mirror of
https://github.com/aljazceru/opencode.git
synced 2025-12-23 10:44:21 +01:00
rework custom tools
This commit is contained in:
@@ -5,15 +5,15 @@ export const ExamplePlugin: Plugin = async (ctx) => {
|
||||
return {
|
||||
permission: {},
|
||||
tool: {
|
||||
mytool: tool((zod) => ({
|
||||
mytool: tool({
|
||||
description: "This is a custom tool tool",
|
||||
args: {
|
||||
foo: zod.string(),
|
||||
foo: tool.schema.string().describe("foo"),
|
||||
},
|
||||
async execute(args, ctx) {
|
||||
async execute(args) {
|
||||
return `Hello ${args.foo}!`
|
||||
},
|
||||
})),
|
||||
}),
|
||||
},
|
||||
async "chat.params"(_input, output) {
|
||||
output.topP = 1
|
||||
|
||||
@@ -7,14 +7,13 @@ export type ToolContext = {
|
||||
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 function tool<Args extends z.ZodRawShape>(input: {
|
||||
description: string
|
||||
args: Args
|
||||
execute(args: z.infer<z.ZodObject<Args>>, context: ToolContext): Promise<string>
|
||||
}) {
|
||||
return input
|
||||
}
|
||||
tool.schema = z
|
||||
|
||||
export type ToolDefinition = ReturnType<typeof tool>
|
||||
|
||||
Reference in New Issue
Block a user