diff --git a/packages/react/CHANGELOG.md b/packages/react/CHANGELOG.md index 777ee2b34..aefb6fce5 100644 --- a/packages/react/CHANGELOG.md +++ b/packages/react/CHANGELOG.md @@ -1,5 +1,11 @@ # @assistant-ui/react +## 0.7.14 + +### Patch Changes + +- fix: assistantDecoderStream should end current tool call on flush + ## 0.7.12 ### Patch Changes diff --git a/packages/react/package.json b/packages/react/package.json index e4e47ca37..e1c44974b 100644 --- a/packages/react/package.json +++ b/packages/react/package.json @@ -29,7 +29,7 @@ "conversational-ui", "conversational-ai" ], - "version": "0.7.12", + "version": "0.7.14", "license": "MIT", "exports": { ".": { diff --git a/packages/react/src/runtimes/edge/streams/assistantDecoderStream.ts b/packages/react/src/runtimes/edge/streams/assistantDecoderStream.ts index 2d6a32b19..b8cd7c133 100644 --- a/packages/react/src/runtimes/edge/streams/assistantDecoderStream.ts +++ b/packages/react/src/runtimes/edge/streams/assistantDecoderStream.ts @@ -11,24 +11,30 @@ export function assistantDecoderStream() { | { id: string; name: string; argsText: string } | undefined; + const endCurrentToolCall = ( + controller: TransformStreamDefaultController, + ) => { + if (!currentToolCall) return; + controller.enqueue({ + type: "tool-call", + toolCallType: "function", + toolCallId: currentToolCall.id, + toolName: currentToolCall.name, + args: currentToolCall.argsText, + }); + currentToolCall = undefined; + }; + return new TransformStream< StreamPart, ToolResultStreamPart >({ transform({ type, value }, controller) { if ( - currentToolCall && type !== AssistantStreamChunkType.ToolCallDelta && type !== AssistantStreamChunkType.Error ) { - controller.enqueue({ - type: "tool-call", - toolCallType: "function", - toolCallId: currentToolCall.id, - toolName: currentToolCall.name, - args: currentToolCall.argsText, - }); - currentToolCall = undefined; + endCurrentToolCall(controller); } switch (type) { @@ -135,5 +141,8 @@ export function assistantDecoderStream() { } } }, + flush(controller) { + endCurrentToolCall(controller); + }, }); }