fix(kiro): preserve underscores in tool names and restore sanitized names in responses
Do not collapse consecutive underscores in uniqueName so mcp__server__tool is sent intact to Kiro, attach reverse map on request translation, and restore client tool names in responses.
This commit is contained in:
@@ -48,7 +48,6 @@ function uniqueName(rawName, index, usedNames) {
|
||||
const cleaned = String(rawName || "")
|
||||
.trim()
|
||||
.replace(TOOL_NAME_PATTERN, "_")
|
||||
.replace(/_+/g, "_")
|
||||
.replace(/^_+|_+$/g, "");
|
||||
const base = trimCodePoints(cleaned || `tool_${index + 1}`, KIRO_TOOL_NAME_MAX_LENGTH);
|
||||
let candidate = base;
|
||||
|
||||
@@ -48,9 +48,9 @@ function convertFinishReason(reason) {
|
||||
*/
|
||||
// Kiro only accepts sanitized tool names; the request translator leaves the
|
||||
// reverse map on the stream state so calls come back under the client's names.
|
||||
function restoreToolName(state, name) {
|
||||
function restoreToolName(stateOrData, name) {
|
||||
const raw = name || "";
|
||||
const map = state?.toolNameMap;
|
||||
const map = stateOrData?.toolNameMap || stateOrData?._toolNameMap;
|
||||
return map && typeof map.get === "function" && map.has(raw) ? map.get(raw) : raw;
|
||||
}
|
||||
|
||||
@@ -254,7 +254,7 @@ export function kiroToClaudeNonStreaming(data) {
|
||||
content.push({
|
||||
type: "tool_use",
|
||||
id: tc.id || `toolu_${Date.now()}`,
|
||||
name: restoreToolName(state, tc.function?.name),
|
||||
name: restoreToolName(data, tc.function?.name),
|
||||
input,
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user