mirror of
https://github.com/aljazceru/opencode.git
synced 2026-01-04 16:34:55 +01:00
toolz
This commit is contained in:
28
js/src/tool/tool.ts
Normal file
28
js/src/tool/tool.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { type Tool, tool as AITool } from "ai";
|
||||
import { Log } from "../util/log";
|
||||
|
||||
const log = Log.create({ service: "tool" });
|
||||
|
||||
export function tool<Params, Result>(
|
||||
tool: Tool<Params, Result> & {
|
||||
name: string;
|
||||
},
|
||||
) {
|
||||
return {
|
||||
[tool.name]: AITool({
|
||||
...tool,
|
||||
execute: async (params, opts) => {
|
||||
log.info("invoking", {
|
||||
id: opts.toolCallId,
|
||||
name: tool.name,
|
||||
...params,
|
||||
});
|
||||
try {
|
||||
return tool.execute!(params, opts);
|
||||
} catch (e: any) {
|
||||
return "An error occurred: " + e.toString();
|
||||
}
|
||||
},
|
||||
}),
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user