Skip to main content

Class: Deterministic<TInput, TOutput, TSchema>

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

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 loop: Processable = new Loop(bot, config);

// 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

Methods

getBotNames()

getBotNames(): string[]

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

Get bot names from this processor

Returns

string[]

Array containing this processor's name

Implementation of

Processable.getBotNames


getId()

getId(): string

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

Get the unique ID of this processor instance

Returns

string

Implementation of

Processable.getId


getName()

getName(): string

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

Get the name of this processor

Returns

string


getSchema()

getSchema(): TSchema | undefined

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

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:185

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


subscribeToAll()

subscribeToAll(options?): Subscription

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

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:168

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