Skip to content

Commit d87c6c3

Browse files
committed
fix(feishu): preserve streaming card content
1 parent c768a9e commit d87c6c3

2 files changed

Lines changed: 11 additions & 25 deletions

File tree

extensions/feishu/src/streaming-card.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ describe("FeishuStreamingSession", () => {
180180

181181
expect(updateBodies).toHaveLength(1);
182182
expect(JSON.parse(updateBodies[0] ?? "{}")).toEqual({
183-
content: " small",
183+
content: "hello small",
184184
sequence: 2,
185185
uuid: "s_card_1_2",
186186
});
@@ -212,13 +212,13 @@ describe("FeishuStreamingSession", () => {
212212

213213
expect(updateBodies).toHaveLength(1);
214214
expect(JSON.parse(updateBodies[0] ?? "{}")).toEqual({
215-
content: "!",
215+
content: "hello!",
216216
sequence: 2,
217217
uuid: "s_card_2_2",
218218
});
219219
});
220220

221-
it("retries unsent suffix content after a failed delta update", async () => {
221+
it("retries cumulative content after a failed streaming update", async () => {
222222
vi.useFakeTimers();
223223
vi.setSystemTime(3_000);
224224
const updateBodies: string[] = [];
@@ -245,18 +245,18 @@ describe("FeishuStreamingSession", () => {
245245

246246
expect(updateBodies).toHaveLength(2);
247247
expect(JSON.parse(updateBodies[0] ?? "{}")).toEqual({
248-
content: " world",
248+
content: "hello world",
249249
sequence: 2,
250250
uuid: "s_card_3_2",
251251
});
252252
expect(JSON.parse(updateBodies[1] ?? "{}")).toEqual({
253-
content: " world!",
253+
content: "hello world!",
254254
sequence: 3,
255255
uuid: "s_card_3_3",
256256
});
257257
});
258258

259-
it("retries unsent suffix content after a non-OK delta update", async () => {
259+
it("retries cumulative content after a non-OK streaming update", async () => {
260260
vi.useFakeTimers();
261261
vi.setSystemTime(3_500);
262262
const updateBodies: string[] = [];
@@ -283,12 +283,12 @@ describe("FeishuStreamingSession", () => {
283283

284284
expect(updateBodies).toHaveLength(2);
285285
expect(JSON.parse(updateBodies[0] ?? "{}")).toEqual({
286-
content: " world",
286+
content: "hello world",
287287
sequence: 2,
288288
uuid: "s_card_5_2",
289289
});
290290
expect(JSON.parse(updateBodies[1] ?? "{}")).toEqual({
291-
content: " world!",
291+
content: "hello world!",
292292
sequence: 3,
293293
uuid: "s_card_5_3",
294294
});

extensions/feishu/src/streaming-card.ts

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -154,16 +154,6 @@ function shouldPushStreamingUpdate(previousText: string, nextText: string): bool
154154
return nextText.length - previousText.length >= STREAMING_SIGNIFICANT_DELTA_CHARS;
155155
}
156156

157-
function resolveStreamingCardAppendContent(previousText: string, nextText: string): string {
158-
if (!nextText || nextText === previousText) {
159-
return "";
160-
}
161-
if (!previousText) {
162-
return nextText;
163-
}
164-
return nextText.startsWith(previousText) ? nextText.slice(previousText.length) : nextText;
165-
}
166-
167157
export function mergeStreamingText(
168158
previousText: string | undefined,
169159
nextText: string | undefined,
@@ -477,13 +467,12 @@ export class FeishuStreamingSession {
477467
if (!mergedText || mergedText === this.state.currentText) {
478468
return;
479469
}
480-
const appendContent = resolveStreamingCardAppendContent(this.state.sentText, mergedText);
481-
if (!appendContent) {
470+
if (mergedText === this.state.sentText) {
482471
return;
483472
}
484473
this.pendingText = null;
485474
this.state.currentText = mergedText;
486-
const sent = await this.updateCardContent(appendContent, (e) =>
475+
const sent = await this.updateCardContent(mergedText, (e) =>
487476
this.log?.(`Update failed: ${String(e)}`),
488477
);
489478
if (sent && this.state) {
@@ -540,10 +529,7 @@ export class FeishuStreamingSession {
540529
// An explicit empty final text clears a transient preview before closeout.
541530
if ((text || finalText !== undefined) && text !== this.state.sentText) {
542531
const sent = text.startsWith(this.state.sentText)
543-
? await this.updateCardContent(
544-
resolveStreamingCardAppendContent(this.state.sentText, text),
545-
(e) => this.log?.(`Final update failed: ${String(e)}`),
546-
)
532+
? await this.updateCardContent(text, (e) => this.log?.(`Final update failed: ${String(e)}`))
547533
: await this.replaceCardContent(text, (e) =>
548534
this.log?.(`Final replace failed: ${String(e)}`),
549535
);

0 commit comments

Comments
 (0)