@tanstack/ai
Version:
Type-safe TypeScript AI SDK for streaming chat, tool calling, agents, structured outputs, and multimodal generation.
34 lines (33 loc) • 1.82 kB
TypeScript
import { StandardSchemaV1 } from '@standard-schema/spec';
import { JSONSchema, SchemaInput } from '../../../types.js';
/** A JSON Schema object: typed, or as JSON gives it. */
type AnySchema = JSONSchema | Record<string, unknown>;
/**
* Check `value` against the JSON Schema `schema` with `@cfworker/json-schema`,
* as a tool input is checked, with no repair. Every keyword that the
* validator knows is checked. `format` is an annotation only. The result has
* the Standard Schema shape: `{ value }` when it fits, else `{ issues }`.
*
* @example
* ```ts
* const result = validateJsonSchema({ type: 'string', pattern: '^a' }, 'b')
* if (result.issues) console.log(result.issues.map((issue) => issue.message))
* ```
*/
export declare function validateJsonSchema(schema: AnySchema | boolean, value: unknown): StandardSchemaV1.Result<unknown>;
/**
* How a failed tool input is repaired. `undefined`: the built-in repair.
* `false`: no repair. A function: called instead of the built-in repair. It
* returns the input to check again, or `undefined` to keep the error.
*/
export type ToolInputRepair = false | ((input: unknown, error: Error) => unknown | Promise<unknown>);
/**
* The final check of a tool input, just before the tool runs or the client
* gets the call. A Standard Schema runs here (an async validator too), and
* its output is the input, so transforms apply once. A JSON Schema (an MCP
* tool, a plain JSON Schema tool) is checked with `@cfworker/json-schema`.
* A failed input is repaired as `repair` says, then checked again. The error
* of the first check goes back to the model as the tool result.
*/
export declare function validateToolInput(schema: SchemaInput | boolean | undefined, received: unknown, toolName: string, repair?: ToolInputRepair): Promise<unknown>;
export {};