mirror of
https://github.com/aljazceru/opencode.git
synced 2026-01-05 08:54:55 +01:00
support custom tools (#2668)
This commit is contained in:
20
packages/plugin/src/tool.ts
Normal file
20
packages/plugin/src/tool.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { z } from "zod/v4"
|
||||
|
||||
export type ToolContext = {
|
||||
sessionID: string
|
||||
messageID: string
|
||||
agent: string
|
||||
abort: AbortSignal
|
||||
}
|
||||
|
||||
export function tool<Args extends z.ZodRawShape>(
|
||||
input: (zod: typeof z) => {
|
||||
description: string
|
||||
args: Args
|
||||
execute: (args: z.infer<z.ZodObject<Args>>, ctx: ToolContext) => Promise<string>
|
||||
},
|
||||
) {
|
||||
return input(z)
|
||||
}
|
||||
|
||||
export type ToolDefinition = ReturnType<typeof tool>
|
||||
Reference in New Issue
Block a user