summaryrefslogtreecommitdiffhomepage
path: root/js/src/tool/tool.ts
diff options
context:
space:
mode:
authorDax Raad <[email protected]>2025-05-19 19:29:38 -0400
committerDax Raad <[email protected]>2025-05-26 12:40:17 -0400
commit2437ce3f8b79a7f9d987862b633f3340bfa2c1c4 (patch)
treed46690ea1bf8043871e26b6139f96997b16a6252 /js/src/tool/tool.ts
parentfa8a46326afa2d7fbb592542abf243f248cb5992 (diff)
downloadopencode-2437ce3f8b79a7f9d987862b633f3340bfa2c1c4.tar.gz
opencode-2437ce3f8b79a7f9d987862b633f3340bfa2c1c4.zip
toolz
Diffstat (limited to 'js/src/tool/tool.ts')
-rw-r--r--js/src/tool/tool.ts28
1 files changed, 28 insertions, 0 deletions
diff --git a/js/src/tool/tool.ts b/js/src/tool/tool.ts
new file mode 100644
index 000000000..08ab935b3
--- /dev/null
+++ b/js/src/tool/tool.ts
@@ -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();
+ }
+ },
+ }),
+ };
+}