24 lines
802 B
JavaScript
24 lines
802 B
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.ALL_TOOLS = void 0;
|
|
exports.registerTool = registerTool;
|
|
exports.executeTool = executeTool;
|
|
/** Live registry — grows as domain files are imported. */
|
|
const _registry = new Map();
|
|
/**
|
|
* Mutable array kept in sync with the registry.
|
|
* Used by agents.ts to pick tool subsets by name (backwards-compatible with ALL_TOOLS).
|
|
*/
|
|
exports.ALL_TOOLS = [];
|
|
function registerTool(tool) {
|
|
_registry.set(tool.name, tool);
|
|
exports.ALL_TOOLS.push(tool);
|
|
}
|
|
/** Dispatch a tool call by name — O(1) map lookup, no switch needed. */
|
|
async function executeTool(name, args, ctx) {
|
|
const tool = _registry.get(name);
|
|
if (!tool)
|
|
return { error: `Unknown tool: ${name}` };
|
|
return tool.handler(args, ctx);
|
|
}
|