Skip to main content

Interface: Processable<TInput, TOutput>

Defined in: packages/core/src/types.ts:100

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)

Methods

getBotNames()

getBotNames(): string[]

Defined in: packages/core/src/types.ts:247

Get all bot names in this processable (including nested processables)

Returns

string[]

Array of bot names that can emit events

Example

const pipeline = pipeline()
.step(chatBot)
.parallel({ sentiment: sentimentBot, tone: toneBot })
.build();

const botNames = pipeline.getBotNames();
// ['assistant', 'sentiment', 'tone']

getId()

getId(): string

Defined in: packages/core/src/types.ts:166

Get the unique ID of this processable instance

Each processable has a unique ID that persists for its lifetime. IDs are useful for:

  • Filtering specific instances in subscriptions
  • Tracking performance metrics per instance
  • Debugging nested compositions

Returns

string

Unique ID 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'

process()

process(input, options?): Promise<InferSchemaOutput<TOutput>>

Defined in: packages/core/src/types.ts:132

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

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

Example

// Stream events in real-time AND get final result
const result = await bot.process(input, {
onToken: {
onTextDelta(botName, event) {
process.stdout.write(event.content); // Real-time streaming
},
onToolExecutionStart(botName, event) {
console.log(`Tool starting: ${event.toolName}`); // Real-time tool status
}
}
});

// Also get final result when Promise resolves
console.log('Complete response:', result); // Final parsed response

stream()?

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

Defined in: packages/core/src/types.ts:140

Stream events as an async iterator

Alternative to callback-based streaming via onToken/onComplete/onError. Uses for await pattern for cleaner consumption.

Parameters

input

TInput

options?

Omit<ProcessOptions, "onToken" | "onComplete" | "onError">

Returns

AsyncGenerator<BaleybotStreamEvent>


subscribeToAll()

subscribeToAll(options?): Subscription

Defined in: packages/core/src/types.ts:223

Subscribe to categorized events from this processable and all nested processables

Provides fine-grained control over event handling with categorized callbacks:

  • onStreamEvent: Real-time content streaming (text_delta, structured_output_delta, tool_call_arguments_delta)
  • onProgressUpdate: Status updates (tool_execution_start, tool_call_stream_start, tool_call_stream_complete, reasoning)
  • onComplete: Emitted when each bot finishes processing with final output
  • onError: Error events (error, tool_validation_error)

Callbacks now receive both bot ID and name for precise identification:

  • botId: Unique instance identifier (e.g., 'baleybot-1-a3f891')
  • botName: Semantic name (e.g., 'analyzer', 'router', 'processor')

Parameters

options?

Optional categorized callbacks and bot filter

omit?

string[]

onComplete?

(botId, botName, output) => void

onError?

(botId, botName, event) => void

onProgressUpdate?

(botId, botName, event) => void

onStreamEvent?

(botId, botName, event) => void

Returns

Subscription

Subscription object with unsubscribe method

Examples

const subscription = pipeline.subscribeToAll({
onStreamEvent(botId, botName, event) {
// Real-time streaming content
if (event.type === 'text_delta') {
console.log(`[${botId}] ${botName}:`, event.content);
}
},
onProgressUpdate(botId, botName, event) {
// Status updates
if (event.type === 'tool_execution_start') {
console.log(`${botName} (${botId}) executing ${event.toolName}`);
}
},
onComplete(botId, botName, output) {
// Bot finished processing
console.log(`${botName} completed:`, output);
},
onError(botId, botName, event) {
// Errors
console.error(`${botName} error:`, event);
}
});

await pipeline.process('input');
subscription.unsubscribe();
const subscription = pipeline.subscribeToAll({
onStreamEvent(botId, botName, event) {
console.log(`${botName}:`, event);
},
omit: ['chat-step', 'processor-42-8a3f91'] // Filter by name or ID
});