Variable: Output
constOutput:object
Defined in: packages/core/src/utils/output.ts:76
Output helper namespace
Provides convenient methods for defining output schemas.
These are recommended over using outputSchema directly
as they're more expressive and provide better type inference.
Type Declaration
array()
array<
T>(config):OutputConfig<T[]>
Define an array output schema
Use this when your bot should return an array of items. The schema should be for a single item; it will be wrapped in an array.
Type Parameters
T
T
Parameters
config
Configuration with item schema
schema
ZodType<T>
Returns
OutputConfig<T[]>
OutputConfig for array output
Example
import { Output } from '@baleybots/core';
import { z } from 'zod';
const itemSchema = z.object({
title: z.string(),
url: z.string().url(),
});
const bot = new Baleybot({
name: 'link-extractor',
goal: 'Extract links from text',
output: Output.array({ schema: itemSchema }),
});
const result = await bot.process('...');
// result is typed as { title: string, url: string }[]
choice()
choice<
T>(choices):OutputConfig<T>
Define a choice output schema
Use this when your bot should return one of a set of choices. This is simpler than defining an enum schema manually.
Type Parameters
T
T extends string
Parameters
choices
readonly T[]
Array of valid choices
Returns
OutputConfig<T>
OutputConfig for choice output
Example
import { Output } from '@baleybots/core';
const bot = new Baleybot({
name: 'classifier',
goal: 'Classify the sentiment',
output: Output.choice(['positive', 'negative', 'neutral']),
});
const result = await bot.process('I love this!');
// result is typed as 'positive' | 'negative' | 'neutral'
object()
object<
T>(config):OutputConfig<T>
Define an object output schema
Use this when your bot should return a structured object.
Type Parameters
T
T
Parameters
config
Configuration with schema
schema
ZodType<T>
Returns
OutputConfig<T>
OutputConfig for object output
Example
import { Output } from '@baleybots/core';
import { z } from 'zod';
const bot = new Baleybot({
name: 'summarizer',
goal: 'Summarize text',
output: Output.object({
schema: z.object({
summary: z.string(),
keyPoints: z.array(z.string()),
wordCount: z.number(),
}),
}),
});
const result = await bot.process('...');
// result is typed as { summary: string, keyPoints: string[], wordCount: number }