import { z } from 'zod'; import { ExperimentalTool } from '../tool'; import { ValueOf } from '../util/value-of'; /** Typed tool result that is returned by generateText and streamText. It contains the tool call ID, the tool name, the tool arguments, and the tool result. */ export interface ToolResult { /** ID of the tool call. This ID is used to match the tool call with the tool result. */ toolCallId: string; /** Name of the tool that was called. */ toolName: NAME; /** Arguments of the tool call. This is a JSON-serializable object that matches the tool's input schema. */ args: ARGS; /** Result of the tool call. This is the result of the tool's execution. */ result: RESULT; } // limits the tools to those with an execute value type ToToolsWithExecute> = { [K in keyof TOOLS as TOOLS[K] extends { execute: any } ? K : never]: TOOLS[K]; }; // limits the tools to those that have execute !== undefined type ToToolsWithDefinedExecute> = { [K in keyof TOOLS as TOOLS[K]['execute'] extends undefined ? never : K]: TOOLS[K]; }; // transforms the tools into a tool result union type ToToolResultObject> = ValueOf<{ [NAME in keyof TOOLS]: { type: 'tool-result'; toolCallId: string; toolName: NAME & string; args: z.infer; result: Awaited>>; }; }>; export type ToToolResult> = ToToolResultObject>>; export type ToToolResultArray> = Array>;