mirror of
https://github.com/anomalyco/opencode.git
synced 2026-04-29 13:09:46 +00:00
support custom tools (#2668)
This commit is contained in:
parent
e9d902d844
commit
3b6c0ec0b3
12 changed files with 140 additions and 488 deletions
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>
|
||||
Loading…
Add table
Add a link
Reference in a new issue