Skip to content

Commit 2bca144

Browse files
committed
Fix Apply on Invalid 'messages[68].tool_calls[0].id': string too long. Expected a string with maximum length 40, but got a string with length 46 instead. anomalyco#12653
The issue is specific for arch linux environment, and I add this method to allow 40 up character for the message. If the call is triggered, it allows to pass through.
1 parent 85d0ed5 commit 2bca144

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

‎packages/opencode/src/provider/transform.ts‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,27 @@ export namespace ProviderTransform {
130130
return result
131131
}
132132

133+
// OpenAI and GitHub Copilot (OpenAI-compatible) allow max 40 chars for tool_calls[].id
134+
const openAiLikeNpm = ["@ai-sdk/openai", "@ai-sdk/github-copilot", "@ai-sdk/openai-compatible"]
135+
if (openAiLikeNpm.includes(model.api.npm ?? "")) {
136+
const MAX_TOOL_CALL_ID_LENGTH = 40
137+
msgs = msgs.map((msg) => {
138+
if ((msg.role === "assistant" || msg.role === "tool") && Array.isArray(msg.content)) {
139+
return {
140+
...msg,
141+
content: msg.content.map((part: any) => {
142+
if ((part.type === "tool-call" || part.type === "tool-result") && part.toolCallId) {
143+
const id = part.toolCallId.replace(/[^a-zA-Z0-9_-]/g, "_")
144+
return { ...part, toolCallId: id.length > MAX_TOOL_CALL_ID_LENGTH ? id.slice(0, MAX_TOOL_CALL_ID_LENGTH) : id }
145+
}
146+
return part
147+
}),
148+
}
149+
}
150+
return msg
151+
})
152+
}
153+
133154
if (typeof model.capabilities.interleaved === "object" && model.capabilities.interleaved.field) {
134155
const field = model.capabilities.interleaved.field
135156
return msgs.map((msg) => {

0 commit comments

Comments
 (0)