tool.ts 401 B

12345678910111213141516171819
  1. import { z } from "zod"
  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>(input: {
  9. description: string
  10. args: Args
  11. execute(args: z.infer<z.ZodObject<Args>>, context: ToolContext): Promise<string>
  12. }) {
  13. return input
  14. }
  15. tool.schema = z
  16. export type ToolDefinition = ReturnType<typeof tool>