chore: generate
This commit is contained in:
@@ -263,68 +263,70 @@ describe("tool.registry", () => {
|
|||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
|
||||||
it.instance("preserves Zod arg descriptions from config-scoped plugin packages", () =>
|
it.instance(
|
||||||
Effect.gen(function* () {
|
"preserves Zod arg descriptions from config-scoped plugin packages",
|
||||||
const test = yield* TestInstance
|
() =>
|
||||||
const opencode = path.join(test.directory, ".opencode")
|
Effect.gen(function* () {
|
||||||
const customTools = path.join(opencode, "tools")
|
const test = yield* TestInstance
|
||||||
const plugin = path.join(opencode, "node_modules", "@opencode-ai", "plugin")
|
const opencode = path.join(test.directory, ".opencode")
|
||||||
yield* Effect.promise(() => fs.mkdir(path.join(plugin, "dist"), { recursive: true }))
|
const customTools = path.join(opencode, "tools")
|
||||||
yield* Effect.promise(() => fs.mkdir(customTools, { recursive: true }))
|
const plugin = path.join(opencode, "node_modules", "@opencode-ai", "plugin")
|
||||||
yield* Effect.promise(() =>
|
yield* Effect.promise(() => fs.mkdir(path.join(plugin, "dist"), { recursive: true }))
|
||||||
fs.cp(path.dirname(fileURLToPath(import.meta.resolve("zod"))), path.join(opencode, "node_modules", "zod"), {
|
yield* Effect.promise(() => fs.mkdir(customTools, { recursive: true }))
|
||||||
dereference: true,
|
yield* Effect.promise(() =>
|
||||||
recursive: true,
|
fs.cp(path.dirname(fileURLToPath(import.meta.resolve("zod"))), path.join(opencode, "node_modules", "zod"), {
|
||||||
}),
|
dereference: true,
|
||||||
)
|
recursive: true,
|
||||||
yield* Effect.promise(() =>
|
}),
|
||||||
Bun.write(
|
)
|
||||||
path.join(plugin, "package.json"),
|
yield* Effect.promise(() =>
|
||||||
JSON.stringify({ name: "@opencode-ai/plugin", type: "module", exports: { ".": "./dist/index.js" } }),
|
Bun.write(
|
||||||
),
|
path.join(plugin, "package.json"),
|
||||||
)
|
JSON.stringify({ name: "@opencode-ai/plugin", type: "module", exports: { ".": "./dist/index.js" } }),
|
||||||
yield* Effect.promise(() =>
|
),
|
||||||
Bun.write(
|
)
|
||||||
path.join(plugin, "dist", "index.js"),
|
yield* Effect.promise(() =>
|
||||||
[
|
Bun.write(
|
||||||
"import { z } from 'zod'",
|
path.join(plugin, "dist", "index.js"),
|
||||||
"export function tool(input) {",
|
[
|
||||||
" return { ...input, jsonSchema: z.toJSONSchema(z.object(input.args), { target: 'draft-7', io: 'input' }) }",
|
"import { z } from 'zod'",
|
||||||
"}",
|
"export function tool(input) {",
|
||||||
"tool.schema = z",
|
" return { ...input, jsonSchema: z.toJSONSchema(z.object(input.args), { target: 'draft-7', io: 'input' }) }",
|
||||||
"",
|
"}",
|
||||||
].join("\n"),
|
"tool.schema = z",
|
||||||
),
|
"",
|
||||||
)
|
].join("\n"),
|
||||||
yield* Effect.promise(() =>
|
),
|
||||||
Bun.write(
|
)
|
||||||
path.join(customTools, "addition.ts"),
|
yield* Effect.promise(() =>
|
||||||
[
|
Bun.write(
|
||||||
'import { tool } from "@opencode-ai/plugin"',
|
path.join(customTools, "addition.ts"),
|
||||||
"export default tool({",
|
[
|
||||||
" description: 'Use this tool to add two numbers and return their sum.',",
|
'import { tool } from "@opencode-ai/plugin"',
|
||||||
" args: {",
|
"export default tool({",
|
||||||
" left: tool.schema.number().describe('The first number to add'),",
|
" description: 'Use this tool to add two numbers and return their sum.',",
|
||||||
" right: tool.schema.number().describe('The second number to add'),",
|
" args: {",
|
||||||
" },",
|
" left: tool.schema.number().describe('The first number to add'),",
|
||||||
" execute: async (args) => `${args.left} + ${args.right} = ${args.left + args.right}`,",
|
" right: tool.schema.number().describe('The second number to add'),",
|
||||||
"})",
|
" },",
|
||||||
"",
|
" execute: async (args) => `${args.left} + ${args.right} = ${args.left + args.right}`,",
|
||||||
].join("\n"),
|
"})",
|
||||||
),
|
"",
|
||||||
)
|
].join("\n"),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
const registry = yield* ToolRegistry.Service
|
const registry = yield* ToolRegistry.Service
|
||||||
const loaded = (yield* registry.all()).find((tool) => tool.id === "addition")
|
const loaded = (yield* registry.all()).find((tool) => tool.id === "addition")
|
||||||
if (!loaded) throw new Error("custom addition tool was not loaded")
|
if (!loaded) throw new Error("custom addition tool was not loaded")
|
||||||
|
|
||||||
expect(ToolJsonSchema.fromTool(loaded)).toMatchObject({
|
expect(ToolJsonSchema.fromTool(loaded)).toMatchObject({
|
||||||
properties: {
|
properties: {
|
||||||
left: { type: "number", description: "The first number to add" },
|
left: { type: "number", description: "The first number to add" },
|
||||||
right: { type: "number", description: "The second number to add" },
|
right: { type: "number", description: "The second number to add" },
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}),
|
}),
|
||||||
20_000,
|
20_000,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user