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
28 lines
710 B
TypeScript
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)
|
|
}
|