opencode: add custom tools support
Adds support for custom tools - user-defined functions that the LLM can call during conversations. Custom tools work alongside opencode's built-in tools and are configured through the new `tools` option. The configuration follows the same pattern as other opencode settings like `agents` and `commands`, supporting: - Inline TypeScript content - Individual file paths - Bulk directory imports
This commit is contained in:
parent
081234b704
commit
b1b1c68033
11 changed files with 213 additions and 0 deletions
42
tests/modules/programs/opencode/tools-inline.nix
Normal file
42
tests/modules/programs/opencode/tools-inline.nix
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
{
|
||||
programs.opencode = {
|
||||
enable = true;
|
||||
tools = {
|
||||
database-query = ''
|
||||
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}`
|
||||
},
|
||||
})
|
||||
'';
|
||||
api-client = ''
|
||||
import { tool } from "@opencode-ai/plugin"
|
||||
|
||||
export default tool({
|
||||
description: "Make API requests to external services",
|
||||
args: {
|
||||
endpoint: tool.schema.string().describe("API endpoint to call"),
|
||||
method: tool.schema.string().describe("HTTP method"),
|
||||
},
|
||||
async execute(args) {
|
||||
return `Called ''${args.method} ''${args.endpoint}`
|
||||
},
|
||||
})
|
||||
'';
|
||||
};
|
||||
};
|
||||
nmt.script = ''
|
||||
assertFileExists home-files/.config/opencode/tool/database-query.ts
|
||||
assertFileExists home-files/.config/opencode/tool/api-client.ts
|
||||
assertFileContent home-files/.config/opencode/tool/database-query.ts \
|
||||
${./database-query-tool.ts}
|
||||
assertFileContent home-files/.config/opencode/tool/api-client.ts \
|
||||
${./api-client-tool.ts}
|
||||
'';
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue