Class: Deterministic<TInput, TOutput, TSchema>
Defined in: packages/core/src/deterministic.ts:142
A plain function as a Processable: no model call, composable with Baleybots in pipelines, loops, etc.
Examples
Simple string transformation
const uppercase = Deterministic.create({
name: 'uppercase',
processFn: (input: string) => input.toUpperCase()
});
const result = await uppercase.process('hello'); // 'HELLO'
With Zod schema validation
const formatter = Deterministic.create({
name: 'formatter',
processFn: (input: { name: string, age: number }) => ({
formatted: `${input.name} is ${input.age} years old`,
timestamp: new Date().toISOString()
}),
schema: z.object({
formatted: z.string(),
timestamp: z.string()
})
});
const result = await formatter.process({ name: 'Alice', age: 30 });
// result is typed as { formatted: string, timestamp: string }
Async processing
const fetchUser = Deterministic.create({
name: 'fetchUser',
processFn: async (userId: string) => {
const response = await fetch(`/api/users/${userId}`);
return response.json();
}
});
In a chain with AI bots
const chain = pipeline(
step((text: string) => text.trim().toLowerCase(), 'preprocess'),
Baleybot.create({
name: 'sentiment',
goal: 'Analyze the sentiment',
output: Output.object({ schema: z.object({ sentiment: z.string() }) }),
}),
step((result: { sentiment: string }) => ({
...result,
processedAt: new Date().toISOString(),
}), 'postprocess'),
);
Type Parameters
TInput
TInput = unknown
TOutput
TOutput = unknown
TSchema
TSchema extends ZodSchema | undefined = undefined
Implements
Processable<TInput,TSchemaextendsZodSchema?InferOutput<TSchema> :TOutput>
Properties
emitsInvocationEvents
readonlyemitsInvocationEvents:boolean
Defined in: packages/core/src/deterministic.ts:150
All events from one process() call reach its own options.onToken callback. Enables isolated step events when the same instance runs concurrently. Subscription-only implementations must not overlap observed invocations.
Implementation of
Processable.emitsInvocationEvents
forwardsStepEvents?
readonlyoptionalforwardsStepEvents?:boolean
Defined in: packages/core/src/deterministic.ts:151
True when this processable forwards its children's stream events to
ProcessOptions.hooks.onStepEvent itself.
A composite that intercepts a child's stream — today only graph() —
declares this so an enclosing composite knows not to also capture and
replay the same events off subscribeToAll. Without the declaration,
nesting two interceptors delivers every leaf event once per level: the
inner fires it live with precise attribution, the outer replays its
buffered copy at step end. Declared rather than sniffed (no
instanceof, no structural probe), per ASK-DONT-SNIFF.
Absent means false: the composite passes hooks through (or fires only boundaries) and its enclosing graph captures leaf streams on its behalf.
Implementation of
Processable.forwardsStepEvents
Methods
describe()
describe():
ProcessableStructure
Defined in: packages/core/src/deterministic.ts:292
A function's body is code the identity cannot see, so the step is opaque
and its version is what decides resume. Without one, a deploy that
changes the function still resumes; strict durability refuses to start.
Returns
Implementation of
getId()
getId():
string
Defined in: packages/core/src/deterministic.ts:278
This instance's id, unique within the process for its lifetime and different after a restart.
Returns
string
Example
const bot1 = Baleybot.create({ name: 'analyzer' });
const bot2 = Baleybot.create({ name: 'analyzer' });
bot1.getId(); // 'baleybot-1-a3f891'
bot2.getId(); // 'baleybot-2-b4c2d3'
// Same semantic name, different IDs
bot1.getName(); // 'analyzer'
bot2.getName(); // 'analyzer'
Implementation of
getName()
getName():
string
Defined in: packages/core/src/deterministic.ts:283
Falls back to 'processor' when unnamed.
Returns
string
Implementation of
getSchema()
getSchema():
TSchema|undefined
Defined in: packages/core/src/deterministic.ts:302
Returns
TSchema | undefined
process()
process(
input,options?):Promise<InferSchemaOutput<TSchemaextendsZodType<unknown,unknown,$ZodTypeInternals<unknown,unknown>> ?InferOutput<TSchema> :TOutput>>
Defined in: packages/core/src/deterministic.ts:211
Run once and resolve to the final output. Events stream to
options.onToken while it runs; see ProcessOptions.onToken.
Parameters
input
TInput
options?
Returns
Promise<InferSchemaOutput<TSchema extends ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>> ? InferOutput<TSchema> : TOutput>>
Implementation of
stream()
stream(
input,options?):AsyncGenerator<BaleybotStreamEvent>
Defined in: packages/core/src/deterministic.ts:255
Stream this processor's output as events.
A transform has exactly one thing to report, so it reports one result
event; a generator processFn reports one per
yield, which is what makes streaming a deterministic step worth doing.
Note the asymmetry with process(): the events here are raw yields.
transformOutput and schema validation apply to the final value and are
observed through process(), not through this stream.
Parameters
input
TInput
options?
Omit<ProcessOptions, "onError" | "onToken" | "onComplete">
Returns
AsyncGenerator<BaleybotStreamEvent>
Implementation of
subscribeToAll()
subscribeToAll(
options?):Subscription
Defined in: packages/core/src/deterministic.ts:307
A step's subscribers hear its completion or failure; it emits no stream events.
Parameters
options?
Returns
Implementation of
create()
staticcreate<TInput,TOutput,TSchema>(config):CallableDeterministic<TInput,TOutput,TSchema>
Defined in: packages/core/src/deterministic.ts:179
Returns a callable function that also has .process(), .getName(), etc.
Type Parameters
TInput
TInput = unknown
TOutput
TOutput = unknown
TSchema
TSchema extends ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>> | undefined = undefined
Parameters
config
DeterministicConfig<TInput, TOutput, TSchema>
Returns
CallableDeterministic<TInput, TOutput, TSchema>
Example
const uppercase = Deterministic.create({
processFn: (s: string) => s.toUpperCase()
});
const result1 = await uppercase('hello');
const result2 = await uppercase.process('hello');