Skip to content

Commit c8b87c6

Browse files
roomoteedelauna
authored andcommitted
fix: sanitize mimo streaming tool call ids
1 parent 6038a94 commit c8b87c6

2 files changed

Lines changed: 12 additions & 3 deletions

File tree

src/api/providers/__tests__/mimo.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -855,8 +855,8 @@ describe("MimoHandler", () => {
855855

856856
const toolChunks = chunks.filter((c) => c.type === "tool_call_partial")
857857
expect(toolChunks.length).toBeGreaterThan(0)
858-
expect(toolChunks[0].id).toBeDefined()
859-
expect(typeof toolChunks[0].id).toBe("string")
858+
expect(toolChunks[0].id).toBe(sanitizeOpenAiCallId("call_with-special.chars@123"))
859+
expect(toolChunks[0].id).not.toMatch(/[^a-zA-Z0-9_-]/)
860860
})
861861

862862
it("should convert system prompt to system message for MiMo", async () => {

src/api/providers/mimo.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,15 @@ export class MimoHandler extends OpenAiHandler {
110110
for await (const chunk of stream) {
111111
const delta = chunk.choices?.[0]?.delta ?? {}
112112
const finishReason = chunk.choices?.[0]?.finish_reason
113+
const sanitizedDelta = delta.tool_calls
114+
? {
115+
...delta,
116+
tool_calls: delta.tool_calls.map((toolCall) => ({
117+
...toolCall,
118+
id: toolCall.id ? sanitizeOpenAiCallId(toolCall.id) : toolCall.id,
119+
})),
120+
}
121+
: delta
113122

114123
if (delta.content) {
115124
yield {
@@ -125,7 +134,7 @@ export class MimoHandler extends OpenAiHandler {
125134
}
126135
}
127136

128-
yield* this.processToolCalls(delta, finishReason, activeToolCallIds)
137+
yield* this.processToolCalls(sanitizedDelta, finishReason, activeToolCallIds)
129138

130139
if (chunk.usage) {
131140
lastUsage = chunk.usage

0 commit comments

Comments
 (0)