Files
oh-my-openagent/src/shared/tool-name.ts
YeonGyu-Kim eb5cc873ea fix: trim whitespace from tool names to prevent invalid tool calls
Some models (e.g. kimi-k2.5) return tool names with leading spaces
like ' delegate_task', causing tool matching to fail.

Add .trim() in transformToolName() and defensive trim in claude-code-hooks.

Fixes #1568
2026-02-07 13:12:47 +09:00

28 lines
710 B
TypeScript

const SPECIAL_TOOL_MAPPINGS: Record<string, string> = {
webfetch: "WebFetch",
websearch: "WebSearch",
todoread: "TodoRead",
todowrite: "TodoWrite",
}
function toPascalCase(str: string): string {
return str
.split(/[-_\s]+/)
.map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase())
.join("")
}
export function transformToolName(toolName: string): string {
const trimmed = toolName.trim()
const lower = trimmed.toLowerCase()
if (lower in SPECIAL_TOOL_MAPPINGS) {
return SPECIAL_TOOL_MAPPINGS[lower]
}
if (trimmed.includes("-") || trimmed.includes("_")) {
return toPascalCase(trimmed)
}
return trimmed.charAt(0).toUpperCase() + trimmed.slice(1)
}