import type { FlexibleSchema } from './schema'; import type { Context } from './types/context'; import { tool, type ProviderExecutedTool, type Tool } from './types/tool'; /** * A provider-executed tool is a tool for which the provider executes the tool. */ export type ProviderExecutedToolFactory< INPUT, OUTPUT, ARGS extends object, CONTEXT extends Context = {}, > = ( options: ARGS & { onInputStart?: Tool['onInputStart']; onInputDelta?: Tool['onInputDelta']; onInputAvailable?: Tool['onInputAvailable']; }, ) => ProviderExecutedTool; export function createProviderExecutedToolFactory< INPUT, OUTPUT, ARGS extends object, CONTEXT extends Context = {}, >({ id, inputSchema, outputSchema, supportsDeferredResults, }: { id: `${string}.${string}`; inputSchema: FlexibleSchema; outputSchema: FlexibleSchema; /** * Whether this provider-executed tool supports deferred results. * * When true, the tool result may not be returned in the same turn as the * tool call (e.g., when using programmatic tool calling where a server tool * triggers a client-executed tool, and the server tool's result is deferred * until the client tool is resolved). * * @default false */ supportsDeferredResults?: boolean; }): ProviderExecutedToolFactory { return ({ onInputStart, onInputDelta, onInputAvailable, ...args }: ARGS & { onInputStart?: Tool['onInputStart']; onInputDelta?: Tool['onInputDelta']; onInputAvailable?: Tool['onInputAvailable']; }): ProviderExecutedTool => tool({ type: 'provider', isProviderExecuted: true, id, args, inputSchema, outputSchema, onInputStart, onInputDelta, onInputAvailable, supportsDeferredResults, }) as ProviderExecutedTool; }