Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fix-finish-step-event-name.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"chat": patch
---

Fix `fromFullStream()` step separator detection for AI SDK v5+: rename `step-finish` event check to `finish-step`
24 changes: 12 additions & 12 deletions packages/chat/src/from-full-stream.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,28 +30,28 @@ describe("fromFullStream", () => {
it("injects separator between steps", async () => {
const stream = events([
{ type: "text-delta", textDelta: "hello." },
{ type: "step-finish" },
{ type: "finish-step" },
{ type: "text-delta", textDelta: "how are you?" },
]);
expect(await collect(fromFullStream(stream))).toBe(
"hello.\n\nhow are you?"
);
});

it("does not add trailing separator after final step-finish", async () => {
it("does not add trailing separator after final finish-step", async () => {
const stream = events([
{ type: "text-delta", textDelta: "done." },
{ type: "step-finish" },
{ type: "finish-step" },
]);
expect(await collect(fromFullStream(stream))).toBe("done.");
});

it("handles multiple steps", async () => {
const stream = events([
{ type: "text-delta", textDelta: "step 1" },
{ type: "step-finish" },
{ type: "finish-step" },
{ type: "text-delta", textDelta: "step 2" },
{ type: "step-finish" },
{ type: "finish-step" },
{ type: "text-delta", textDelta: "step 3" },
]);
expect(await collect(fromFullStream(stream))).toBe(
Expand All @@ -64,26 +64,26 @@ describe("fromFullStream", () => {
{ type: "text-delta", textDelta: "before" },
{ type: "tool-call", toolName: "search", args: {} },
{ type: "tool-result", toolName: "search", result: "data" },
{ type: "step-finish" },
{ type: "finish-step" },
{ type: "tool-call-streaming-start", toolName: "lookup" },
{ type: "text-delta", textDelta: " after" },
]);
expect(await collect(fromFullStream(stream))).toBe("before\n\n after");
});

it("handles consecutive step-finish events", async () => {
it("handles consecutive finish-step events", async () => {
const stream = events([
{ type: "text-delta", textDelta: "a" },
{ type: "step-finish" },
{ type: "step-finish" },
{ type: "finish-step" },
{ type: "finish-step" },
{ type: "text-delta", textDelta: "b" },
]);
expect(await collect(fromFullStream(stream))).toBe("a\n\nb");
});

it("does not inject separator when step-finish comes before any text", async () => {
it("does not inject separator when finish-step comes before any text", async () => {
const stream = events([
{ type: "step-finish" },
{ type: "finish-step" },
{ type: "text-delta", textDelta: "first text" },
]);
expect(await collect(fromFullStream(stream))).toBe("first text");
Expand Down Expand Up @@ -124,7 +124,7 @@ describe("fromFullStream", () => {
it("injects separator between steps with text property", async () => {
const stream = events([
{ type: "text-delta", id: "0", text: "step 1." },
{ type: "step-finish" },
{ type: "finish-step" },
{ type: "text-delta", id: "0", text: "step 2." },
]);
expect(await collect(fromFullStream(stream))).toBe("step 1.\n\nstep 2.");
Expand Down
2 changes: 1 addition & 1 deletion packages/chat/src/from-full-stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export async function* fromFullStream(
needsSeparator = false;
hasEmittedText = true;
yield textContent;
} else if (typed.type === "step-finish") {
} else if (typed.type === "finish-step") {
needsSeparator = true;
}
}
Expand Down
Loading