@anthropic-ai/sdk
Version:
The official TypeScript library for the Anthropic API
32 lines • 1.33 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.toolName = toolName;
exports.toolErrorContent = toolErrorContent;
exports.runRunnableTool = runRunnableTool;
const ToolError_1 = require("./ToolError.js");
const sanitize_1 = require("../internal/toolsets/sanitize.js");
/**
* The name the model calls a tool by: `mcp_server_name` for MCP toolsets, `type` for nameless server
* toolsets (browser/computer), `name` for everything else.
*/
function toolName(tool) {
return ('name' in tool ? tool.name
: 'mcp_server_name' in tool ? tool.mcp_server_name
: tool.type);
}
/** Tool-result content for a thrown value: a {@link ToolError}'s own content, otherwise `Error: <message>`. */
function toolErrorContent(e) {
return e instanceof ToolError_1.ToolError ? e.content : (0, sanitize_1.thrownErrorText)(e);
}
/** Parse the input, run the tool, and turn anything thrown into an error result. */
async function runRunnableTool(tool, rawInput, context) {
try {
const input = tool.parse ? tool.parse(rawInput) : rawInput;
const content = await tool.run(input, context);
return { content, isError: false };
}
catch (e) {
return { content: toolErrorContent(e), isError: true };
}
}
//# sourceMappingURL=BetaRunnableTool.js.map