Performs structured on-device decision making (boolean questions, multiple-choice questions, and scalar scoring) over text or key-value contexts.
Signature:
export declare class DecisionMaker extends TaskRunner
Extends: TaskRunner
Properties
| Property | Type | Description |
|---|---|---|
| contextUsage | DecisionContextUsage | null | Token usage details from the most recent evaluation. |
| contextWindow | number | Total token capacity of the underlying model context window. |
Methods
| Method | Modifiers | Description |
|---|---|---|
| classify(context, options) | Convenience method to classify a context into one of the provided option labels. | |
| close() | Releases all native WASM resources held by this DecisionMaker instance. | |
| createFromModelBuffer(wasmFileset, modelAssetBuffer) | static |
Initializes the Wasm runtime and creates a new DecisionMaker based on the provided model asset buffer. |
| createFromModelPath(wasmFileset, modelAssetPath) | static |
Initializes the Wasm runtime and creates a new DecisionMaker based on the path to the model asset. |
| createFromOptions(wasmFileset, options) | static |
Initializes the Wasm runtime and creates a new DecisionMaker from the provided options. |
| evaluate(context, questions) | Evaluates a heterogeneous list of questions (BooleanQuestion, ChoiceQuestion, ScoreQuestion) against a single shared context KV-cache prefix. |
|
| evaluateBatch(items) | Evaluates multiple contexts and their associated questions in a batch. | |
| evaluateBoolean(context, question, threshold) | Evaluates a yes/no boolean question against the given context. | |
| evaluateBooleanBatch(contexts, question, threshold) | Evaluates the same boolean question across a batch of contexts. | |
| evaluateChoice(context, question, options, scoringMode) | Evaluates a multiple-choice question with candidate options against the given context. | |
| evaluateChoiceBatch(contexts, question, options, scoringMode) | Evaluates the same multiple-choice question across a batch of contexts. | |
| evaluateScore(context, question, scaleMin, scaleMax) | Evaluates a scalar rating question over an integer scale [scaleMin, scaleMax]. |
|
| evaluateScoreBatch(contexts, question, scaleMin, scaleMax) | Evaluates the same scalar rating question across a batch of contexts. | |
| measureContextUsage(context, questions) | Computes the token count of the given context and questions without running model inference. | |
| prewarm() | Pre-warms the underlying inference engine to minimize first-call latency. | |
| setOptions(options) | Sets new options for the DecisionMaker instance. | |
| setSchema(schema) | Sets or updates the JSON schema / field descriptions used to format structured key-value contexts. |
DecisionMaker.contextUsage
Token usage details from the most recent evaluation.
Signature:
get contextUsage(): { contextTokens: number; maxQuestionTokens: number; totalTokens: number; contextWindow: number; } | null;
DecisionMaker.contextWindow
Total token capacity of the underlying model context window.
Signature:
get contextWindow(): number;
DecisionMaker.classify()
Convenience method to classify a context into one of the provided option labels.
Signature:
classify(context: DecisionContext, options: string[]): Promise<ChoiceResult>;
Parameters
| Parameter | Type | Description |
|---|---|---|
| context | DecisionContext | The input text or structured key-value record. |
| options | string[] | Candidate category labels. |
Returns:
Promise<ChoiceResult>
DecisionMaker.close()
Releases all native WASM resources held by this DecisionMaker instance.
Signature:
close(): void;
Returns:
void
DecisionMaker.createFromModelBuffer()
Initializes the Wasm runtime and creates a new DecisionMaker based on the provided model asset buffer.
Signature:
static createFromModelBuffer(wasmFileset: WasmFileset, modelAssetBuffer: Uint8Array | ReadableStreamDefaultReader): Promise<DecisionMaker>;
Parameters
| Parameter | Type | Description |
|---|---|---|
| wasmFileset | WasmFileset | A configuration object that provides the location of the Wasm binary and its loader. |
| modelAssetBuffer | Uint8Array | ReadableStreamDefaultReader | A binary representation of the model or a stream reader. |
Returns:
Promise<DecisionMaker>
DecisionMaker.createFromModelPath()
Initializes the Wasm runtime and creates a new DecisionMaker based on the path to the model asset.
Signature:
static createFromModelPath(wasmFileset: WasmFileset, modelAssetPath: TrustedResourceUrl | string): Promise<DecisionMaker>;
Parameters
| Parameter | Type | Description |
|---|---|---|
| wasmFileset | WasmFileset | A configuration object that provides the location of the Wasm binary and its loader. |
| modelAssetPath | TrustedResourceUrl | string | The path to the model asset. |
Returns:
Promise<DecisionMaker>
DecisionMaker.createFromOptions()
Initializes the Wasm runtime and creates a new DecisionMaker from the provided options.
Signature:
static createFromOptions(wasmFileset: WasmFileset, options: DecisionMakerOptions): Promise<DecisionMaker>;
Parameters
| Parameter | Type | Description |
|---|---|---|
| wasmFileset | WasmFileset | A configuration object that provides the location of the Wasm binary and its loader. |
| options | DecisionMakerOptions | Configuration options for the DecisionMaker. |
Returns:
Promise<DecisionMaker>
DecisionMaker.evaluate()
Evaluates a heterogeneous list of questions (BooleanQuestion, ChoiceQuestion, ScoreQuestion) against a single shared context KV-cache prefix.
Signature:
evaluate(context: DecisionContext, questions: Array<BooleanQuestion | ChoiceQuestion | ScoreQuestion>): Promise<Array<BooleanResult | ChoiceResult | ScoreResult>>;
Parameters
| Parameter | Type | Description |
|---|---|---|
| context | DecisionContext | The input text or structured key-value context. |
| questions | Array<BooleanQuestion | ChoiceQuestion | ScoreQuestion> | Questions to evaluate against the context. |
Returns:
Promise<Array<BooleanResult | ChoiceResult | ScoreResult>>
DecisionMaker.evaluateBatch()
Evaluates multiple contexts and their associated questions in a batch.
Signature:
evaluateBatch(items: Array<{ context: DecisionContext; questions: Array<BooleanQuestion | ChoiceQuestion | ScoreQuestion> }>): Promise<Array<Array<BooleanResult | ChoiceResult | ScoreResult>>>;
Parameters
| Parameter | Type | Description |
|---|---|---|
| items | Array<{ context: DecisionContext; questions: Array<BooleanQuestion | ChoiceQuestion | ScoreQuestion> }> | Batch items pairing each context with its questions. |
Returns:
Promise<Array<Array<BooleanResult | ChoiceResult | ScoreResult>>>
DecisionMaker.evaluateBoolean()
Evaluates a yes/no boolean question against the given context.
Signature:
evaluateBoolean(context: DecisionContext, question: string | BooleanQuestion, threshold?: number): Promise<BooleanResult>;
Parameters
| Parameter | Type | Description |
|---|---|---|
| context | DecisionContext | The input text or structured context. |
| question | string | BooleanQuestion | The boolean question string or BooleanQuestion object. |
| threshold | number | Optional probability threshold in [0.0, 1.0] above which answer is true (defaults to 0.5). |
Returns:
Promise<BooleanResult>
DecisionMaker.evaluateBooleanBatch()
Evaluates the same boolean question across a batch of contexts.
Signature:
evaluateBooleanBatch(contexts: DecisionContext[], question: string | BooleanQuestion, threshold?: number): Promise<BooleanResult[]>;
Parameters
| Parameter | Type | Description |
|---|---|---|
| contexts | DecisionContext[] | Array of input contexts. |
| question | string | BooleanQuestion | The boolean question to evaluate. |
| threshold | number | Optional decision threshold in [0.0, 1.0]. |
Returns:
Promise<BooleanResult[]>
DecisionMaker.evaluateChoice()
Evaluates a multiple-choice question with candidate options against the given context.
Signature:
evaluateChoice(context: DecisionContext, question: string | ChoiceQuestion, options?: string[], scoringMode?: ScoringMode): Promise<ChoiceResult>;
Parameters
| Parameter | Type | Description |
|---|---|---|
| context | DecisionContext | The input text or structured context. |
| question | string | ChoiceQuestion | The multiple-choice question string or ChoiceQuestion object. |
| options | string[] | Candidate option strings (required when question is a string). |
| scoringMode | ScoringMode | Optional scoring mode override. |
Returns:
Promise<ChoiceResult>
DecisionMaker.evaluateChoiceBatch()
Evaluates the same multiple-choice question across a batch of contexts.
Signature:
evaluateChoiceBatch(contexts: DecisionContext[], question: string | ChoiceQuestion, options?: string[], scoringMode?: ScoringMode): Promise<ChoiceResult[]>;
Parameters
| Parameter | Type | Description |
|---|---|---|
| contexts | DecisionContext[] | Array of input contexts. |
| question | string | ChoiceQuestion | The multiple-choice question. |
| options | string[] | Candidate option strings (when question is a string). |
| scoringMode | ScoringMode | Optional scoring mode override. |
Returns:
Promise<ChoiceResult[]>
DecisionMaker.evaluateScore()
Evaluates a scalar rating question over an integer scale [scaleMin, scaleMax].
Signature:
evaluateScore(context: DecisionContext, question: string | ScoreQuestion, scaleMin?: number, scaleMax?: number): Promise<ScoreResult>;
Parameters
| Parameter | Type | Description |
|---|---|---|
| context | DecisionContext | The input text or structured context. |
| question | string | ScoreQuestion | The scoring question string or ScoreQuestion object. |
| scaleMin | number | Minimum integer score on the rating scale (defaults to 1). |
| scaleMax | number | Maximum integer score on the rating scale (defaults to 5). |
Returns:
Promise<ScoreResult>
DecisionMaker.evaluateScoreBatch()
Evaluates the same scalar rating question across a batch of contexts.
Signature:
evaluateScoreBatch(contexts: DecisionContext[], question: string | ScoreQuestion, scaleMin?: number, scaleMax?: number): Promise<ScoreResult[]>;
Parameters
| Parameter | Type | Description |
|---|---|---|
| contexts | DecisionContext[] | Array of input contexts. |
| question | string | ScoreQuestion | The scoring question. |
| scaleMin | number | Minimum integer score (defaults to 1). |
| scaleMax | number | Maximum integer score (defaults to 5). |
Returns:
Promise<ScoreResult[]>
DecisionMaker.measureContextUsage()
Computes the token count of the given context and questions without running model inference.
Signature:
measureContextUsage(context: DecisionContext, questions?: Array<BooleanQuestion | ChoiceQuestion | ScoreQuestion>): Promise<{ contextTokens: number; maxQuestionTokens: number; totalTokens: number; contextWindow: number; }>;
Parameters
| Parameter | Type | Description |
|---|---|---|
| context | DecisionContext | The input context to measure. |
| questions | Array<BooleanQuestion | ChoiceQuestion | ScoreQuestion> | Optional questions to include in the token count. |
Returns:
Promise<{ contextTokens: number; maxQuestionTokens: number; totalTokens: number; contextWindow: number; }>
DecisionMaker.prewarm()
Pre-warms the underlying inference engine to minimize first-call latency.
Signature:
prewarm(): Promise<void>;
Returns:
Promise<void>
DecisionMaker.setOptions()
Sets new options for the DecisionMaker instance.
Signature:
setOptions(options: DecisionMakerOptions): Promise<void>;
Parameters
| Parameter | Type | Description |
|---|---|---|
| options | DecisionMakerOptions | New options to apply. |
Returns:
Promise<void>
DecisionMaker.setSchema()
Sets or updates the JSON schema / field descriptions used to format structured key-value contexts.
Signature:
setSchema(schema: Record<string, string> | string): Promise<void>;
Parameters
| Parameter | Type | Description |
|---|---|---|
| schema | Record<string, string> | string | Mapping of field names to human-readable descriptions, or a serialized JSON schema string. |
Returns:
Promise<void>