tool.ts 423 B

1234567891011121314151617181920
  1. import { z } from "zod/v4"
  2. export type ToolContext = {
  3. sessionID: string
  4. messageID: string
  5. agent: string
  6. abort: AbortSignal
  7. }
  8. export function tool<Args extends z.ZodRawShape>(
  9. input: (zod: typeof z) => {
  10. description: string
  11. args: Args
  12. execute: (args: z.infer<z.ZodObject<Args>>, ctx: ToolContext) => Promise<string>
  13. },
  14. ) {
  15. return input(z)
  16. }
  17. export type ToolDefinition = ReturnType<typeof tool>