This commit is contained in:
Dax Raad
2025-05-19 19:29:38 -04:00
parent fa8a46326a
commit 2437ce3f8b
14 changed files with 973 additions and 13 deletions

28
js/src/tool/tool.ts Normal file
View 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();
}
},
}),
};
}