词元广场TOKPUB.COM - 欢迎您,支持一个 Key 调用近 600+ 海内外模型,限时特价模型低至 1 折,欢迎上岸!

read、write、bash)并行工作。.opencode/tool/ 目录~/.config/opencode/tool/ 目录tool() 辅助函数创建工具,提供类型安全和验证:// .opencode/tool/database.ts
import { tool } from "@opencode-ai/plugin"
export default tool({
description: "Query the project database",
args: {
query: tool.schema.string().describe("SQL query to execute"),
},
async execute(args) {
// 数据库逻辑
return `Executed query: ${args.query}`
},
})database 工具。<文件名>_<导出名>:// .opencode/tool/math.ts
import { tool } from "@opencode-ai/plugin"
export const add = tool({
description: "Add two numbers",
args: {
a: tool.schema.number().describe("First number"),
b: tool.schema.number().describe("Second number"),
},
async execute(args) {
return args.a + args.b
},
})
export const multiply = tool({
description: "Multiply two numbers",
args: {
a: tool.schema.number().describe("First number"),
b: tool.schema.number().describe("Second number"),
},
async execute(args) {
return args.a * args.b
},
})math_add 和 math_multiply。bash 工具:import { tool } from "@opencode-ai/plugin"
export default tool({
description: "受限的 bash 封装",
args: {
command: tool.schema.string().describe("要执行的命令"),
},
async execute(args) {
// 拦 截危险命令
const blocked = ["rm -rf", "sudo", "mkfs"]
for (const cmd of blocked) {
if (args.command.includes(cmd)) {
return `⛔ 已拦截危险命令: ${args.command}`
}
}
// 执行其他命令...
return `执行: ${args.command}`
},
})