Skip to content

Commit 22f2639

Browse files
fix(app-shell): a reopened AI chat answer draws one step line, not one per stored step (#39288)
Part of #39283 (the console half; the server half is objectstack-ai/cloud#5412) Clause-②: no Metadata-protocol: none ## 维护者速读 - 用户能看到什么变化:在控制台 AI 对话里重新打开一段对话时,一轮回答的工具步骤合成一行(如「2 步 · 查找相关记录 · 汇总相关数据 ×18」),与刚生成时一致,不再每条存储记录各画一行。 - 为什么做:替 AI 问答的用户解决「重新打开后几十行步骤把答案挤到下面」的问题;但要在云端生效,云端的会话接口还需按约定给每条消息带上所属轮次。 - 出错会怎样:最坏情况是重新打开的对话步骤行合并得不对,只影响显示,不改任何数据,回退本改动即恢复原样。 - 要你做什么:无。 ## What changes `toUIMessages` (`ui/packages/app-shell/src/hooks/useChatConversation.ts`) now folds consecutive stored assistant rows of one `turnId` into ONE assistant UI message, the shape the live stream gives: - each row's parts in order: the tool parts of every step, then the body; the merged message carries the FIRST row's id and the turn's `turnId`; - `tool` rows between the steps merge their results onto the call parts by reference, as before, so every call keeps its output and state; - a row that called no tool is the answer that ends the run: a later row of the same turn (a resumed turn's continuation after 「继续查」) starts a second message, which is what a reload showed before; - the store's `(called …)` step placeholder is no text of the answer: it is left out of a folded message, except that an answer with no other text keeps the first one (the chat draws it as its quiet activity note); the match is exact, recomputed from the row's own tool calls (`storedStepPlaceholder`); - a row with no `turnId` (absent or null) folds into nothing and is mapped exactly as before. So on reload the step line, the answer and 「计算方式」 each render once, and the line shows no elapsed time (none is persisted). `ChatbotEnhanced.tsx` is untouched (in flight under #39264). Files to read first, by risk: 1. `ui/packages/app-shell/src/hooks/useChatConversation.ts`: the fold branch in `toUIMessages` and `foldIntoAnswer` (the run boundary and the placeholder handling). 2. `ui/packages/app-shell/src/hooks/useChatConversation.test.ts`: the describe "one stored turn is one answer". 3. `ui/packages/app-shell/src/console/ai/__tests__/AiChatPage.reloadStepLine-39283.test.tsx`: the render pin and its control. ## Tests - Unit (`useChatConversation.test.ts`, new describe): the card's turn (1 `query_records` round, 1 round of 5 parallel `aggregate_data`, 13 single ones, then the answer) maps to ONE assistant message; its 19 tool parts are in call order, each with its result; they fold by name to 2 steps, `aggregate_data` ×18; the body is the answer alone, after the tools. Also: a resumed turn stays two messages (the turn end on the second); nothing folds across turns or for rows with no `turnId`; a stopped turn keeps one placeholder; a step's own words stay in order. - Render (`AiChatPage.reloadStepLine-39283.test.tsx`): server rows through `toUIMessages`, `hydratedMessagesToChatMessages` and the real `ChatbotEnhanced` in the shipped zh pack draw ONE `tool-phase-line`, headline exactly 「2 步」 (no time), steps exactly 「查找相关记录 · 汇总相关数据 ×18」, the answer once, no step group. CONTROL: the same rows without `turnId` draw 15 lines. <details><summary>Local runs (head 7bbeccf)</summary> - `pnpm --dir ui exec vitest run packages/app-shell/src/hooks/ packages/app-shell/src/console/ai/`: Test Files 149 passed, Tests 1279 passed. - `pnpm --filter @object-ui/app-shell run type-check`: exit 0 (both programs; `--listFiles` of `tsconfig.test.json` lists both new test files). - Ablation (`scripts/ablation-replace.mjs`, fold branch guarded off): the 4 new unit cases and the render case went red (5 failed, 14 passed, the control stayed green); restore verified, blob equals HEAD and `git diff HEAD` empty. - `dispatch-gates --commands`: 38 derived families, each run with exit 0, `--ran` reconciliation "38 run, 0 NOT-MEASURED (a DERIVED zero)"; plus `pnpm check:changeset-fixed` and `pnpm check:new-line-citations` exit 0. </details> ## Acceptance notes - **Reach depends on the producer.** The objectstack-ai/cloud conversation service (`ObjectQLConversationService.toMessage` / `toMessages`, read at cloud `19dbb42`) returns each message as role and content only, plus `turnEnd` on a turn's end row: no `turnId` and no `id`, although `AiConversationMessageSchema.turnId` and `AIConversationMessage.turnId` declare it. Messages without `turnId` are mapped as before, so in cloud the reopened conversation keeps one line per row until the service returns `turnId`; the fold reads the declared field and adds no positional fallback in the consumer. Reported to the seat for a cloud card. - **Run boundary.** The card's default ("up to and including the first row with body text") is implemented as "up to and including the first row that called no tool": a step row may carry the model's own words before its calls, which the live stream keeps inside the one answer, so it does not end the run. A resumed turn's partial answer is a tool-less row, so a resume still shows as two answers, as before. - **Live shape compared.** The live stream holds one assistant message: one text part with the whole turn's text and the tool parts in call order (cloud's stream encoder opens one step and one text part). The folded message holds the same tool parts and the same joined text, with the body after the tools. - **Message id.** The folded message carries its first row's id. Readers of a hydrated id (React keys, the step-group key, the question map, the resume target `noMessageSendTarget`) need only a unique id per message; rating and saving read `turnId`, and Continue reads the `data-turn-end` part, which stays on the message. - **Share view.** `aiMessageRowsToServerMessages` (the public share transcript) carries no `turn_id`, so a shared transcript keeps one line per row; not changed here. ## Verification Two minutes: `pnpm --dir ui exec vitest run packages/app-shell/src/console/ai/__tests__/AiChatPage.reloadStepLine-39283.test.tsx` shows 2 passed: the folded line reads 「2 步」 「查找相关记录 · 汇总相关数据 ×18」, and the control draws 15 lines. --- _Generated by [Claude Code](https://claude.ai/code/session_012dn2AcfwnfHMghyeNLFvob)_ <!-- signed: repo:objectstack@os-bob · os-bob · session_012dn2AcfwnfHMghyeNLFvob --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 1a66d75 commit 22f2639

4 files changed

Lines changed: 317 additions & 6 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
'@object-ui/app-shell': patch
3+
---
4+
5+
fix(app-shell): a reopened AI chat answer draws one step line, not one per stored step
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
The conversation store keeps each step of an answer as its own assistant row, stamped with the turn's `turnId`. Reopening a conversation used to turn every row into its own message, so an answer that took fifteen tool rounds drew fifteen 「1 步」 lines where the live answer drew one folded line. When the conversation routes return each message's `turnId` (`AiConversationMessageSchema.turnId`), a reloaded conversation now folds consecutive assistant rows of one turn into one answer, the shape the live stream gives: the tool steps in call order, then the body. Its step line, its answer and its 「计算方式」 each render once, and the line shows no elapsed time, because none is stored.
11+
12+
A resumed turn (「继续查」) still shows its continuation as a second answer under the first. Messages returned with no `turnId` are drawn as before, one message per row.
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* objectstack#39283 — a reopened answer draws ONE step line, as the live one
5+
* did, not one per stored row.
6+
*
7+
* The conversation store writes one assistant row per step of an answer, each
8+
* stamped with the turn's `turnId`, and a `tool` row with each step's results.
9+
* The server history below is that shape, run through the real reload path:
10+
* `toUIMessages` → `hydratedMessagesToChatMessages` → `ChatbotEnhanced`, in
11+
* the shipped zh pack. The live line folds the turn's tools by name and shows
12+
* an elapsed time only while it measured one; a reloaded line has none.
13+
*
14+
* CONTROL: the same rows stored with no `turnId` keep one line per row, so the
15+
* pin reads the fold, not a renderer that folds everything.
16+
*/
17+
import '@testing-library/jest-dom/vitest';
18+
import * as React from 'react';
19+
import { afterEach, describe, expect, it } from 'vitest';
20+
import { cleanup, render, screen } from '@testing-library/react';
21+
import { I18nProvider } from '@object-ui/i18n';
22+
import { ChatbotEnhanced } from '@object-ui/plugin-chatbot';
23+
import { hydratedMessagesToChatMessages } from '../aiChatHydration';
24+
import { toUIMessages } from '../../../hooks/useChatConversation';
25+
26+
afterEach(cleanup);
27+
28+
const QUESTION = '各阶段的商机分布如何?';
29+
const ANSWER = '商机分布在 4 个阶段。';
30+
31+
/** One query_records round, one round of five parallel aggregate_data, then thirteen single ones. */
32+
const ROUNDS = [
33+
['query_records'],
34+
Array.from({ length: 5 }, () => 'aggregate_data'),
35+
...Array.from({ length: 13 }, () => ['aggregate_data']),
36+
];
37+
38+
function storedHistory(turnId: string | undefined) {
39+
const stamp = turnId === undefined ? {} : { turnId };
40+
const rows: Array<{ id: string; role: string; content: unknown; turnId?: string }> = [
41+
{ id: 'u1', role: 'user', content: QUESTION, ...stamp },
42+
];
43+
ROUNDS.forEach((tools, r) => {
44+
const calls = tools.map((toolName, c) => ({ type: 'tool-call', toolCallId: `c${r}-${c}`, toolName, input: {} }));
45+
rows.push({
46+
id: `a${r}`,
47+
role: 'assistant',
48+
content: [{ type: 'text', text: `(called ${tools.join(', ')})` }, ...calls],
49+
...stamp,
50+
});
51+
rows.push({
52+
id: `t${r}`,
53+
role: 'tool',
54+
content: calls.map((call) => ({
55+
type: 'tool-result',
56+
toolCallId: call.toolCallId,
57+
toolName: call.toolName,
58+
output: { type: 'json', value: { ok: true } },
59+
})),
60+
...stamp,
61+
});
62+
});
63+
rows.push({ id: 'answer', role: 'assistant', content: ANSWER, ...stamp });
64+
return rows;
65+
}
66+
67+
function renderReloaded(turnId: string | undefined) {
68+
const messages = hydratedMessagesToChatMessages(toUIMessages(storedHistory(turnId)));
69+
return render(
70+
<I18nProvider config={{ defaultLanguage: 'zh', detectBrowserLanguage: false }}>
71+
<ChatbotEnhanced messages={messages} />
72+
</I18nProvider>,
73+
);
74+
}
75+
76+
describe('a reopened multi-round answer draws one step line (objectstack#39283)', () => {
77+
it('folds the turn\'s 15 stored step rows into one line: 2 步 · 查找相关记录 · 汇总相关数据 ×18', () => {
78+
renderReloaded('turn-1');
79+
const lines = screen.getAllByTestId('tool-phase-line');
80+
expect(lines).toHaveLength(1);
81+
// No elapsed time: none is persisted, so a reloaded line shows only its count.
82+
expect(screen.getByTestId('tool-phase-headline')).toHaveTextContent(/^2 步$/);
83+
expect(screen.getByTestId('tool-phase-steps')).toHaveTextContent(/^查找相关记录 · 汇总相关数据 ×18$/);
84+
// One answer: the body once, and no group of separate step messages.
85+
expect(screen.getAllByText(ANSWER)).toHaveLength(1);
86+
expect(screen.queryByTestId('assistant-step-group')).toBeNull();
87+
});
88+
89+
it('CONTROL: the same rows stored with no turnId keep one line per row', () => {
90+
renderReloaded(undefined);
91+
expect(screen.getAllByTestId('tool-phase-line')).toHaveLength(ROUNDS.length);
92+
});
93+
});

‎ui/packages/app-shell/src/hooks/useChatConversation.test.ts‎

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
*/
1414
import { describe, it, expect } from 'vitest';
1515
import { aiMessageRowsToServerMessages, toUIMessages } from './useChatConversation';
16+
import type { HydratedUIMessage } from './useChatConversation';
1617

1718
describe('toUIMessages — merging tool-results onto the call (refresh survival)', () => {
1819
const draftEnvelope = {
@@ -338,3 +339,133 @@ describe('toUIMessages — the turn the server stamped (objectstack#31865)', ()
338339
expect('turnId' in out[3]).toBe(false);
339340
});
340341
});
342+
343+
/**
344+
* objectstack#39283 — the store writes one assistant row per step of an
345+
* answer, each stamped with the turn's `turnId`, plus a `tool` row with each
346+
* step's results. The rows below are that shape, as the conversation routes
347+
* return it: a step row's `content` is the store's `(called …)` placeholder
348+
* text and its tool calls; the answer row is text only.
349+
*/
350+
interface StoredRow {
351+
id: string;
352+
role: string;
353+
content: unknown;
354+
turnId?: string;
355+
turnEnd?: unknown;
356+
}
357+
358+
function storedTurn(turnId: string | undefined, rounds: string[][], answer: string | undefined, tag = 's') {
359+
const stamp = turnId === undefined ? {} : { turnId };
360+
const rows: StoredRow[] = [];
361+
rounds.forEach((tools, r) => {
362+
const calls = tools.map((toolName, c) => ({
363+
type: 'tool-call',
364+
toolCallId: `${tag}${r}-${c}`,
365+
toolName,
366+
input: { round: r },
367+
}));
368+
rows.push({
369+
id: `${tag}-a${r}`,
370+
role: 'assistant',
371+
content: [{ type: 'text', text: `(called ${tools.join(', ')})` }, ...calls],
372+
...stamp,
373+
});
374+
rows.push({
375+
id: `${tag}-t${r}`,
376+
role: 'tool',
377+
content: calls.map((call) => ({
378+
type: 'tool-result',
379+
toolCallId: call.toolCallId,
380+
toolName: call.toolName,
381+
output: { type: 'json', value: { round: r, id: call.toolCallId } },
382+
})),
383+
...stamp,
384+
});
385+
});
386+
if (answer !== undefined) rows.push({ id: `${tag}-answer`, role: 'assistant', content: answer, ...stamp });
387+
return rows;
388+
}
389+
390+
/** The card's turn: one `query_records` round, one round of five parallel `aggregate_data`, then thirteen single ones. */
391+
const FIFTEEN_ROUNDS = [
392+
['query_records'],
393+
Array.from({ length: 5 }, () => 'aggregate_data'),
394+
...Array.from({ length: 13 }, () => ['aggregate_data']),
395+
];
396+
397+
const toolParts = (message: HydratedUIMessage) =>
398+
message.parts.filter((part) => part.type.startsWith('tool-'));
399+
const textParts = (message: HydratedUIMessage) =>
400+
message.parts.filter((part) => part.type === 'text').map((part) => part.text);
401+
402+
describe('toUIMessages — one stored turn is one answer (objectstack#39283)', () => {
403+
it('folds 15 step rows of one turn and their answer into ONE assistant message whose tools fold to 2 steps', () => {
404+
const out = toUIMessages([
405+
{ id: 'u1', role: 'user', content: 'How are the deals spread?', turnId: 'turn-1' },
406+
...storedTurn('turn-1', FIFTEEN_ROUNDS, 'Deals are spread across 4 stages.'),
407+
]);
408+
expect(out.map((m) => [m.role, m.id, m.turnId])).toEqual([
409+
['user', 'u1', 'turn-1'],
410+
// The first stored row's id: the answer starts where its turn's rows start.
411+
['assistant', 's-a0', 'turn-1'],
412+
]);
413+
const answer = out[1];
414+
const tools = toolParts(answer);
415+
// Every call of the turn, in call order, each with the result its `tool` row carried.
416+
expect(tools).toHaveLength(19);
417+
expect(tools.map((part) => part.toolCallId)).toEqual(
418+
FIFTEEN_ROUNDS.flatMap((round, r) => round.map((_, c) => `s${r}-${c}`)),
419+
);
420+
for (const part of tools) {
421+
expect(part.state).toBe('output-available');
422+
expect(part.output).toEqual({ type: 'json', value: expect.objectContaining({ id: part.toolCallId }) });
423+
}
424+
// The step line folds by tool name: 2 steps, the repeated one ×18.
425+
const byName = new Map<string, number>();
426+
for (const part of tools) byName.set(String(part.toolName), (byName.get(String(part.toolName)) ?? 0) + 1);
427+
expect([...byName]).toEqual([
428+
['query_records', 1],
429+
['aggregate_data', 18],
430+
]);
431+
// The body is the answer alone, after the tools: no store placeholder rides along.
432+
expect(textParts(answer)).toEqual(['Deals are spread across 4 stages.']);
433+
expect(answer.parts[answer.parts.length - 1]).toEqual({ type: 'text', text: 'Deals are spread across 4 stages.' });
434+
});
435+
436+
it('keeps a resumed turn\'s continuation a second message: the answer row ends the first', () => {
437+
const turnEnd = { reason: 'answered', wrapUp: false, resumable: false, resumesLeft: 1, turnId: 'turn-1' };
438+
const first = storedTurn('turn-1', [['query_records'], ['aggregate_data']], 'Partial: two of four stages read.', 'p');
439+
const rest = storedTurn('turn-1', [['aggregate_data'], ['aggregate_data']], 'All four stages read.', 'r');
440+
rest[rest.length - 1].turnEnd = turnEnd;
441+
const out = toUIMessages([{ id: 'u1', role: 'user', content: 'q', turnId: 'turn-1' }, ...first, ...rest]);
442+
expect(out.map((m) => m.id)).toEqual(['u1', 'p-a0', 'r-a0']);
443+
expect(textParts(out[1])).toEqual(['Partial: two of four stages read.']);
444+
expect(toolParts(out[2]).map((part) => part.toolCallId)).toEqual(['r0-0', 'r1-0']);
445+
expect(out[2].parts.at(-1)).toMatchObject({ type: 'data-turn-end', data: turnEnd });
446+
});
447+
448+
it('folds nothing across turns, and nothing for rows stored with no turnId', () => {
449+
const out = toUIMessages([
450+
...storedTurn('turn-1', [['query_records']], undefined, 'x'),
451+
...storedTurn('turn-2', [['aggregate_data']], 'Two.', 'y'),
452+
...storedTurn(undefined, [['query_records'], ['aggregate_data']], 'Three.', 'z'),
453+
]);
454+
expect(out.map((m) => m.id)).toEqual(['x-a0', 'y-a0', 'z-a0', 'z-a1', 'z-answer']);
455+
// A row that folded into nothing is byte-for-byte what it was: its placeholder stays.
456+
expect(textParts(out[2])).toEqual(['(called query_records)']);
457+
});
458+
459+
it('a turn that stopped before its answer keeps ONE placeholder, and a step\'s own words stay in order', () => {
460+
const stopped = toUIMessages(storedTurn('turn-1', [['query_records'], ['aggregate_data', 'aggregate_data']], undefined));
461+
expect(stopped).toHaveLength(1);
462+
expect(textParts(stopped[0])).toEqual(['(called query_records)']);
463+
expect(toolParts(stopped[0])).toHaveLength(3);
464+
465+
const rows = storedTurn('turn-1', [['query_records'], ['aggregate_data']], 'Done.');
466+
rows[2].content = [{ type: 'text', text: 'Now the totals. ' }, ...(rows[2].content as unknown[]).slice(1)];
467+
const narrated = toUIMessages(rows);
468+
expect(narrated).toHaveLength(1);
469+
expect(textParts(narrated[0])).toEqual(['Now the totals. ', 'Done.']);
470+
});
471+
});

‎ui/packages/app-shell/src/hooks/useChatConversation.ts‎

Lines changed: 81 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -631,12 +631,51 @@ function mergeToolResultsInto(
631631
}
632632
}
633633

634+
/**
635+
* The `content` the conversation store writes for an assistant step that
636+
* called tools and said nothing (`content` is required there): `(called
637+
* <tool names>)`, or `(tool call)` when no call names a tool. Read off the
638+
* row's OWN call parts, so only the exact text the store wrote for this row
639+
* matches, never a model's words. `undefined` for a row that called no tool.
640+
*/
641+
function storedStepPlaceholder(parts: readonly HydratedUIMessagePart[]): string | undefined {
642+
const calls = parts.filter((part) => typeof part.toolCallId === 'string' && part.type.startsWith('tool-'));
643+
if (calls.length === 0) return undefined;
644+
const names = calls
645+
.map((part) => (typeof part.toolName === 'string' ? part.toolName : ''))
646+
.filter((name) => name.length > 0)
647+
.join(', ');
648+
return names ? `(called ${names})` : '(tool call)';
649+
}
650+
651+
/**
652+
* objectstack#39283 — the answer a stored assistant row folds into: the
653+
* message its turn's earlier rows made, while that answer is still open.
654+
*/
655+
interface OpenAnswer {
656+
message: HydratedUIMessage;
657+
turnId: string;
658+
/** The first folded row's placeholder, kept only while the answer has no other text. */
659+
placeholder?: HydratedUIMessagePart;
660+
}
661+
634662
export function toUIMessages(rows: ServerMessage[] | undefined): HydratedUIMessage[] {
635663
if (!rows) return [];
636664
const out: HydratedUIMessage[] = [];
637665
// Index assistant tool-call parts by id so a later `tool`-role result row can
638666
// merge its output onto the matching call (see mergeToolResultsInto).
639667
const toolPartByCallId = new Map<string, HydratedUIMessagePart>();
668+
// objectstack#39283 — the conversation store writes one assistant row per
669+
// step of an answer (each round of tool calls, then the answer itself), all
670+
// stamped with the turn's `turnId`; the live stream gives that answer as ONE
671+
// assistant message, and a reloaded answer has the same shape. So
672+
// consecutive assistant rows of one turn fold into one message: each row's
673+
// parts in order (the tool parts, then the body), carrying the first row's
674+
// id. `tool` rows between them merge their results by reference and do not
675+
// break the run. A row that called no tool is the answer that ends the run:
676+
// a later row of the same turn (a resumed turn's continuation) starts a new
677+
// message. A row with no `turnId` folds into nothing.
678+
let open: OpenAnswer | undefined;
640679
rows.forEach((row, idx) => {
641680
const role = row.role as HydratedUIMessage['role'] | 'tool';
642681
if (role === 'tool') {
@@ -670,16 +709,52 @@ export function toUIMessages(rows: ServerMessage[] | undefined): HydratedUIMessa
670709
if (role === 'assistant' && row.turnEnd && typeof row.turnEnd === 'object') {
671710
parts.push(...storedAnswerParts('', { turnEnd: row.turnEnd }));
672711
}
673-
out.push({
674-
id: row.id ?? `msg-${idx}`,
675-
role,
676-
parts,
677-
...(row.turnId !== undefined ? { turnId: row.turnId } : {}),
678-
});
712+
const turnId = typeof row.turnId === 'string' && row.turnId.length > 0 ? row.turnId : undefined;
713+
const placeholder = role === 'assistant' ? storedStepPlaceholder(parts) : undefined;
714+
if (role === 'assistant' && open && turnId === open.turnId) {
715+
foldIntoAnswer(open, parts, placeholder);
716+
} else {
717+
const message: HydratedUIMessage = {
718+
id: row.id ?? `msg-${idx}`,
719+
role,
720+
parts,
721+
...(row.turnId !== undefined ? { turnId: row.turnId } : {}),
722+
};
723+
out.push(message);
724+
open = role === 'assistant' && turnId ? { message, turnId } : undefined;
725+
if (open && placeholder) {
726+
const text = parts.find((part) => part.type === 'text' && part.text === placeholder);
727+
if (text && parts.every((part) => part.type !== 'text' || part === text)) open.placeholder = text;
728+
}
729+
}
730+
// A row that called no tool is its answer's end: the next row starts a new message.
731+
if (open && placeholder === undefined) open = undefined;
679732
});
680733
return out;
681734
}
682735

736+
/**
737+
* objectstack#39283 — fold one more stored row of a turn into its open answer.
738+
* The store's step placeholder is no text of the answer (the live stream has
739+
* none), so it is left out, and the first folded one is dropped once the
740+
* answer holds any other text; an answer that holds no text but placeholders
741+
* keeps the first, which the chat draws as its quiet activity note.
742+
*/
743+
function foldIntoAnswer(
744+
open: OpenAnswer,
745+
parts: HydratedUIMessagePart[],
746+
placeholder: string | undefined,
747+
): void {
748+
const kept = parts.filter(
749+
(part) => !(placeholder !== undefined && part.type === 'text' && part.text === placeholder),
750+
);
751+
if (open.placeholder && kept.some((part) => part.type === 'text')) {
752+
open.message.parts = open.message.parts.filter((part) => part !== open.placeholder);
753+
open.placeholder = undefined;
754+
}
755+
open.message.parts.push(...kept);
756+
}
757+
683758
/**
684759
* A FLAT `ai_messages` row as returned by the public share endpoint
685760
* (`GET /api/v1/share-links/:token/messages`), which streams the raw object

0 commit comments

Comments
 (0)