import { tool, type ProviderDefinedTool, type Tool } from './types/tool'; import type { FlexibleSchema } from './schema'; import type { Context } from './types/context'; import type { ToolExecuteFunction } from './types/tool-execute-function'; /** * A provider-defined tool is a tool for which the provider defines the input * and output schemas, but does not execute the tool. */ export type ProviderDefinedToolFactory< INPUT, ARGS extends object, CONTEXT extends Context = {}, > = ( options: ARGS & { execute?: ToolExecuteFunction; needsApproval?: Tool['needsApproval']; toModelOutput?: Tool['toModelOutput']; onInputStart?: Tool['onInputStart']; onInputDelta?: Tool['onInputDelta']; onInputAvailable?: Tool['onInputAvailable']; }, ) => ProviderDefinedTool; export function createProviderDefinedToolFactory< INPUT, ARGS extends object, CONTEXT extends Context = {}, >({ id, inputSchema, }: { id: `${string}.${string}`; inputSchema: FlexibleSchema; }): ProviderDefinedToolFactory { return ({ execute, outputSchema, needsApproval, toModelOutput, onInputStart, onInputDelta, onInputAvailable, ...args }: ARGS & { execute?: ToolExecuteFunction; outputSchema?: FlexibleSchema; needsApproval?: Tool['needsApproval']; toModelOutput?: Tool['toModelOutput']; onInputStart?: Tool['onInputStart']; onInputDelta?: Tool['onInputDelta']; onInputAvailable?: Tool['onInputAvailable']; }): ProviderDefinedTool => tool({ type: 'provider', isProviderExecuted: false, id, args, inputSchema, outputSchema, execute, needsApproval, toModelOutput, onInputStart, onInputDelta, onInputAvailable, }) as ProviderDefinedTool; } export type ProviderDefinedToolFactoryWithOutputSchema< INPUT, OUTPUT, ARGS extends object, CONTEXT extends Context = {}, > = ( options: ARGS & { execute?: ToolExecuteFunction; needsApproval?: Tool['needsApproval']; toModelOutput?: Tool['toModelOutput']; onInputStart?: Tool['onInputStart']; onInputDelta?: Tool['onInputDelta']; onInputAvailable?: Tool['onInputAvailable']; }, ) => ProviderDefinedTool; export function createProviderDefinedToolFactoryWithOutputSchema< INPUT, OUTPUT, ARGS extends object, CONTEXT extends Context = {}, >({ id, inputSchema, outputSchema, }: { id: `${string}.${string}`; inputSchema: FlexibleSchema; outputSchema: FlexibleSchema; }): ProviderDefinedToolFactoryWithOutputSchema { return ({ execute, needsApproval, toModelOutput, onInputStart, onInputDelta, onInputAvailable, ...args }: ARGS & { execute?: ToolExecuteFunction; needsApproval?: Tool['needsApproval']; toModelOutput?: Tool['toModelOutput']; onInputStart?: Tool['onInputStart']; onInputDelta?: Tool['onInputDelta']; onInputAvailable?: Tool['onInputAvailable']; }): ProviderDefinedTool => tool({ type: 'provider', isProviderExecuted: false, id, args, inputSchema, outputSchema, execute, needsApproval, toModelOutput, onInputStart, onInputDelta, onInputAvailable, }) as ProviderDefinedTool; }