Skip to main content

Class: Deterministic<TInput, TOutput, TSchema>

Defined in: packages/core/src/deterministic.ts:177

Processable Interface

The fundamental interface that all Baleybots primitives and patterns implement. This is what enables universal composability - any Processable can be used anywhere a Baleybot is expected.

Example

// All of these implement Processable:
const bot: Processable = Baleybot.create({ ... });
const chain: Processable = Pipeline.from().chain([...]).build();
const refinement: Processable = loop({ body: bot, condition, maxIterations: 5 });

// With type inference from Zod schema:
const bot = Baleybot.create({
finalResponseSchema: z.object({ sentiment: z.string() })
});

const result = await bot.process('text'); // result is typed as { sentiment: string }

// With input/output type constraints:
const typedBot: Processable<string, { sentiment: string }> = bot;

Type Parameters

TInput

TInput = unknown

The input type of the process method (default: unknown for flexibility)

TOutput

TOutput = unknown

The output type of the process method (or a Zod schema to infer from)

TSchema

TSchema extends ZodSchema | undefined = undefined

Implements

Properties

emitsInvocationEvents

readonly emitsInvocationEvents: boolean

Defined in: packages/core/src/deterministic.ts:185

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?

readonly optional forwardsStepEvents?: boolean

Defined in: packages/core/src/deterministic.ts:186

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

getBotNames()

getBotNames(): string[]

Defined in: packages/core/src/deterministic.ts:458

Get bot names from this processor

Returns

string[]

Array containing this processor's name

Implementation of

Processable.getBotNames


getChildren()

getChildren(): ProcessableChild[]

Defined in: packages/core/src/deterministic.ts:401

A deterministic processor is a leaf — its work is a plain function, not a composition of other processables.

Returns

ProcessableChild[]

Implementation of

Processable.getChildren


getId()

getId(): string

Defined in: packages/core/src/deterministic.ts:382

Get the unique ID of this processor instance

Returns

string

Implementation of

Processable.getId


getName()

getName(): string

Defined in: packages/core/src/deterministic.ts:393

Get the name of this processor — its identity across runs.

Falls back to 'processor' when unnamed. Returning the instance id here was an attempt to make the name unique; a name is a label and getId() is the identity — see Loop.getName().

Returns

string

Implementation of

Processable.getName


getSchema()

getSchema(): TSchema | undefined

Defined in: packages/core/src/deterministic.ts:408

Get the schema if one was provided

Returns

TSchema | undefined


process()

process(input, options?): Promise<InferSchemaOutput<TSchema extends ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>> ? InferOutput<TSchema> : TOutput>>

Defined in: packages/core/src/deterministic.ts:251

Process input and return structured output

You can use BOTH streaming events AND final result together:

  • Streaming events: Provide options.onToken to receive real-time events during execution
  • Final result: Returned when Promise resolves (complete parsed response)

Both work simultaneously - streaming events fire in real-time, then final result is returned.

Parameters

input

TInput

Input data (typed for safety)

options?

ProcessOptions

Optional callbacks for streaming, completion, errors

Returns

Promise<InferSchemaOutput<TSchema extends ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>> ? InferOutput<TSchema> : TOutput>>

Promise resolving to structured output (inferred from TOutput if it's a Zod schema)

Implementation of

Processable.process


stream()

stream(input, options?): AsyncGenerator<BaleybotStreamEvent>

Defined in: packages/core/src/deterministic.ts:352

Stream this processor's output as events.

stream?() has been on Processable all along, but only Baleybot implemented it — which made "stream from any processable" true in the type system and false in practice. 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, "onToken" | "onError" | "onComplete">

Returns

AsyncGenerator<BaleybotStreamEvent>

Implementation of

Processable.stream


subscribeToAll()

subscribeToAll(options?): Subscription

Defined in: packages/core/src/deterministic.ts:418

Subscribe to events from this processor

Deterministic processors don't generate streaming events during execution, but will emit onComplete when process() finishes.

Parameters

options?
omit?

string[]

onComplete?

(botId, botName, output) => void

onError?

(botId, botName, event) => void

onProgressUpdate?

(botId, botName, event) => void

onStreamEvent?

(botId, botName, event) => void

Returns

Subscription

Implementation of

Processable.subscribeToAll


create()

static create<TInput, TOutput, TSchema>(config): CallableDeterministic<TInput, TOutput, TSchema>

Defined in: packages/core/src/deterministic.ts:212

Create a deterministic processor

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()
});

// Both work!
const result1 = await uppercase('hello'); // Direct call
const result2 = await uppercase.process('hello'); // Explicit .process()