( config: ToolDefinitionConfig<TInput, TOutput, TName>, )
| 189 | * ``` |
| 190 | */ |
| 191 | export function toolDefinition< |
| 192 | TInput extends SchemaInput = SchemaInput, |
| 193 | TOutput extends SchemaInput = SchemaInput, |
| 194 | TName extends string = string, |
| 195 | >( |
| 196 | config: ToolDefinitionConfig<TInput, TOutput, TName>, |
| 197 | ): ToolDefinition<TInput, TOutput, TName> { |
| 198 | const definition: ToolDefinition<TInput, TOutput, TName> = { |
| 199 | __toolSide: 'definition', |
| 200 | ...config, |
| 201 | server<TContext = unknown>( |
| 202 | execute: ToolExecuteFunction<TInput, TOutput, TContext>, |
| 203 | ): ServerTool<TInput, TOutput, TName, TContext> { |
| 204 | return { |
| 205 | __toolSide: 'server', |
| 206 | ...config, |
| 207 | execute, |
| 208 | } |
| 209 | }, |
| 210 | |
| 211 | client<TContext = unknown>( |
| 212 | execute?: ToolExecuteFunction<TInput, TOutput, TContext>, |
| 213 | ): ClientTool<TInput, TOutput, TName, TContext> { |
| 214 | return { |
| 215 | __toolSide: 'client', |
| 216 | ...config, |
| 217 | ...(execute !== undefined && { execute }), |
| 218 | } |
| 219 | }, |
| 220 | } |
| 221 | |
| 222 | return definition |
| 223 | } |
no outgoing calls