Skip to main content

Function: decide()

decide<T>(schema, options?): CallableDeterministic<unknown, T, undefined>

Defined in: packages/core/src/core/decide.ts:71

Build a processor that answers schema with the configured decision provider.

Model selection and reducibility are checked on process(), not at construction: a missing decision model is a configuration error; an irreducible schema throws NotADecisionError.

Type Parameters

T

T

Parameters

schema

ZodType<T>

options?

DecideOptions = {}

Returns

CallableDeterministic<unknown, T, undefined>

Example

import { decide, setDefaults } from '@baleybots/core';
import { decision } from '@baleybots/core';
import '@baleybots/core/providers/typesafe';

setDefaults({ decisions: { model: { id: 'jev', provider: 'typesafe', config } } });

const triage = decide(z.object({
category: decision.choice(['billing', 'technical']),
refund: z.boolean().describe('Do they want a refund?'),
}));

await triage('I was charged twice.'); // { category: 'billing', refund: true }

The result is parsed with the schema it came from. That is not belt and braces — it is the check that the provider's answers actually satisfy what the caller declared, and it is what would have caught a score being materialised into a field that only admits integers.