Skip to main content

Function: decide()

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

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

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 the check that the provider's answers satisfy what the caller declared (a score materialised into a field that only admits integers fails here).