UNPKG

@tanstack/ai

Version:

Type-safe TypeScript AI SDK for streaming chat, tool calling, agents, structured outputs, and multimodal generation.

33 lines (32 loc) • 1.64 kB
import { AnyTool } from '../../../types.js'; /** * Collect the result metadata that one tool call sets. * * `set` merges the top-level keys. A later key replaces an earlier key. * A key set to `undefined` is removed. The reserved `tanstack` key is dropped. * `get` returns `undefined` when no key is left. */ export declare function createResultMetadataCollector(): { set(value: Record<string, unknown>): void; get(): Record<string, unknown> | undefined; }; /** * Check the result metadata of a tool call before it leaves the engine. * * Returns a plain JSON copy of `value` without the reserved `tanstack` key. * When the tool has a Standard Schema `resultMetadataSchema`, returns the * parsed value. A sync or an async schema works. A JSON Schema is not * checked at runtime, the same as `outputSchema`. * * Throws an `Error` when the value cannot become JSON or the schema check * fails. The error has only the tool name, because the model sees it. The * details go to the server log. */ export declare function finalizeResultMetadata(tool: AnyTool, value: Record<string, unknown> | undefined): Promise<import('../../../utilities/merge-metadata.js').MetadataRecord | undefined>; /** * Check the result metadata of a middleware decision (`skip` or * `replaceResult`). Returns a plain JSON copy without the reserved * `tanstack` key. Metadata that cannot become JSON is dropped with a * warning, so the result stays. */ export declare function middlewareResultMetadata(toolName: string, value: Record<string, unknown> | undefined): import('../../../utilities/merge-metadata.js').MetadataRecord | undefined;