|
| 1 | +diff --git a/dist/index.mjs b/dist/index.mjs |
| 2 | +index 764cbf5325502a9836710b1c218e03d2356cd192..219f7886a71ebe7e469718e39abb72d30e1de4b9 100644 |
| 3 | +--- a/dist/index.mjs |
| 4 | ++++ b/dist/index.mjs |
| 5 | +@@ -728,16 +728,7 @@ function getMappedStream(response, salvageContext) { |
| 6 | + }); |
| 7 | + } |
| 8 | + } |
| 9 | +- if (Array.isArray(chunk.tool_calls)) { |
| 10 | +- if (reasoningId) { |
| 11 | +- controller.enqueue({ |
| 12 | +- type: "reasoning-end", |
| 13 | +- id: reasoningId |
| 14 | +- }); |
| 15 | +- reasoningId = null; |
| 16 | +- } |
| 17 | +- emitToolCallDeltas(chunk.tool_calls, controller); |
| 18 | +- } |
| 19 | ++ let toolCallsEmitted = false; |
| 20 | + if (choices?.[0]?.delta) { |
| 21 | + const delta = choices[0].delta; |
| 22 | + const reasoningDelta = delta.reasoning_content ?? delta.reasoning; |
| 23 | +@@ -788,8 +779,19 @@ function getMappedStream(response, salvageContext) { |
| 24 | + reasoningId = null; |
| 25 | + } |
| 26 | + emitToolCallDeltas(deltaToolCalls, controller); |
| 27 | ++ toolCallsEmitted = true; |
| 28 | + } |
| 29 | + } |
| 30 | ++ if (!toolCallsEmitted && Array.isArray(chunk.tool_calls)) { |
| 31 | ++ if (reasoningId) { |
| 32 | ++ controller.enqueue({ |
| 33 | ++ type: "reasoning-end", |
| 34 | ++ id: reasoningId |
| 35 | ++ }); |
| 36 | ++ reasoningId = null; |
| 37 | ++ } |
| 38 | ++ emitToolCallDeltas(chunk.tool_calls, controller); |
| 39 | ++ } |
| 40 | + }, |
| 41 | + flush(controller) { |
| 42 | + for (const [idx] of activeToolCalls) { |
| 43 | +diff --git a/src/streaming.ts b/src/streaming.ts |
| 44 | +index 114d54f70ad03f9acb7f57886bc03961c2938cd5..7c116056e71f1410d7a7fcbb4579449c991dab2d 100644 |
| 45 | +--- a/src/streaming.ts |
| 46 | ++++ b/src/streaming.ts |
| 47 | +@@ -189,16 +189,7 @@ export function getMappedStream( |
| 48 | + } |
| 49 | + } |
| 50 | + |
| 51 | +- // --- Native format: top-level `tool_calls` --- |
| 52 | +- if (Array.isArray(chunk.tool_calls)) { |
| 53 | +- // Close active reasoning block before tool calls start |
| 54 | +- if (reasoningId) { |
| 55 | +- controller.enqueue({ type: "reasoning-end", id: reasoningId }); |
| 56 | +- reasoningId = null; |
| 57 | +- } |
| 58 | +- emitToolCallDeltas(chunk.tool_calls as Record<string, unknown>[], controller); |
| 59 | +- } |
| 60 | +- |
| 61 | ++ let toolCallsEmitted = false; |
| 62 | + // --- OpenAI format: choices[0].delta --- |
| 63 | + if (choices?.[0]?.delta) { |
| 64 | + const delta = choices[0].delta; |
| 65 | +@@ -253,8 +244,19 @@ export function getMappedStream( |
| 66 | + reasoningId = null; |
| 67 | + } |
| 68 | + emitToolCallDeltas(deltaToolCalls, controller); |
| 69 | ++ toolCallsEmitted = true; |
| 70 | + } |
| 71 | + } |
| 72 | ++ |
| 73 | ++ // --- Native format: top-level `tool_calls` --- |
| 74 | ++ if (!toolCallsEmitted && Array.isArray(chunk.tool_calls)) { |
| 75 | ++ // Close active reasoning block before tool calls start |
| 76 | ++ if (reasoningId) { |
| 77 | ++ controller.enqueue({ type: "reasoning-end", id: reasoningId }); |
| 78 | ++ reasoningId = null; |
| 79 | ++ } |
| 80 | ++ emitToolCallDeltas(chunk.tool_calls as Record<string, unknown>[], controller); |
| 81 | ++ } |
| 82 | + }, |
| 83 | + |
| 84 | + flush(controller) { |
0 commit comments