fix: restore Claude tool call ID normalization from upstream
The normalizeMessages function in transform.ts was missing a block that normalizes tool call IDs for Claude models. This block exists in the upstream OpenCode repo but was inadvertently removed in our fork. The normalization replaces any characters that are not alphanumeric, underscore, or hyphen with underscores in toolCallId fields. This prevents Claude from rejecting messages with tool call IDs containing invalid characters.
This commit is contained in:
@@ -72,6 +72,23 @@ export namespace ProviderTransform {
|
||||
.filter((msg): msg is ModelMessage => msg !== undefined && msg.content !== "")
|
||||
}
|
||||
|
||||
if (model.api.id.includes("claude")) {
|
||||
return msgs.map((msg) => {
|
||||
if ((msg.role === "assistant" || msg.role === "tool") && Array.isArray(msg.content)) {
|
||||
msg.content = msg.content.map((part) => {
|
||||
if ((part.type === "tool-call" || part.type === "tool-result") && "toolCallId" in part) {
|
||||
return {
|
||||
...part,
|
||||
toolCallId: part.toolCallId.replace(/[^a-zA-Z0-9_-]/g, "_"),
|
||||
}
|
||||
}
|
||||
return part
|
||||
})
|
||||
}
|
||||
return msg
|
||||
})
|
||||
}
|
||||
|
||||
if (
|
||||
model.providerID === "mistral" ||
|
||||
model.api.id.toLowerCase().includes("mistral") ||
|
||||
|
||||
Reference in New Issue
Block a user