Skip to content

Commit 7acb95c

Browse files
authored
refactor(ui): consolidate chat rendering ownership (#133508)
1 parent 207f7d2 commit 7acb95c

16 files changed

Lines changed: 197 additions & 497 deletions

‎docs/web/webchat.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Status: the macOS/iOS SwiftUI chat UI talks directly to the Gateway WebSocket. N
2424

2525
- The UI connects to the Gateway WebSocket and uses the `chat.history`, `chat.send`, `chat.inject`, and `chat.message.get` RPC methods.
2626
- `chat.history` is bounded for stability: Gateway may truncate long text fields, omit heavy metadata, and replace oversized entries with `[chat.history omitted: message too large]`. History pages skip hidden and tool-only transcript entries while filling the requested visible-message window from the existing indexed transcript. API clients can send a per-request `maxChars` to override the default limit for one call.
27-
- When a visible assistant message was truncated in `chat.history`, **Show more** fetches the full display-normalized entry inline through `chat.message.get`, without increasing the default history payload. **Show less** restores the truncated preview and reuses the fetched content on the next expansion. `chat.message.get` uses the same transcript branch and display rules as `chat.history`, but targets one entry by `messageId` and returns an honest unavailable reason when the full content can no longer be returned.
27+
- When a visible assistant message was truncated in `chat.history`, the Control UI automatically fetches the full display-normalized entry through `chat.message.get`, without increasing the default history payload. The preview remains visible while it loads; recovered content replaces it inline. `chat.message.get` uses the same transcript branch and display rules as `chat.history`, but targets one entry by `messageId` and returns an honest unavailable reason when the full content can no longer be returned.
2828
- `chat.history` follows the active transcript branch for append-only session files, so abandoned rewrite branches and superseded prompt copies are not rendered in WebChat.
2929
- Compaction entries render as a "Compacted history" divider explaining that the compacted transcript is preserved as a checkpoint, with an action to open session checkpoints (branch or restore, when permissions allow).
3030
- Control UI remembers the backing Gateway `sessionId` returned by `chat.history` and includes it on follow-up `chat.send` calls, so reconnects and page refreshes continue the same stored conversation unless the user starts or resets a session.

‎ui/src/pages/chat/attachment-payload-store.ts‎

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,6 @@ export function getChatAttachmentPreviewUrl(attachment: ChatAttachment): string
5757
return attachment.previewUrl ?? storedPreview ?? getChatAttachmentDataUrl(attachment);
5858
}
5959

60-
function cloneChatAttachmentMetadata(attachment: ChatAttachment): ChatAttachment {
61-
const { dataUrl: _dataUrl, ...metadata } = attachment;
62-
return metadata;
63-
}
64-
65-
export function cloneChatAttachmentsMetadata(
66-
attachments: readonly ChatAttachment[],
67-
): ChatAttachment[] {
68-
return attachments.map(cloneChatAttachmentMetadata);
69-
}
70-
7160
/** Gives another mounted composer payload ownership independent of the source. */
7261
export function cloneChatAttachmentsForIndependentOwner(
7362
attachments: readonly ChatAttachment[],

‎ui/src/pages/chat/chat-commands.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,6 @@ export async function dispatchChatSlashCommand(
466466
host,
467467
`/${name} ${args}`.trim(),
468468
host.chatRunId,
469-
undefined,
470469
resolveCurrentUserIdentity(host.hello, host.client?.instanceId) ?? undefined,
471470
);
472471
}

‎ui/src/pages/chat/chat-queue.ts‎

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@ import { captureChatOutboxAdmission } from "../../lib/chat/outbox-store.ts";
55
import type { SenderIdentity } from "../../lib/chat/sender-label.ts";
66
import { scopedAgentIdForSession, type SessionScopeHost } from "../../lib/sessions/index.ts";
77
import { generateUUID } from "../../lib/uuid.ts";
8-
import {
9-
releaseChatAttachmentPayloads,
10-
cloneChatAttachmentsMetadata,
11-
} from "./attachment-payload-store.ts";
8+
import { releaseChatAttachmentPayloads } from "./attachment-payload-store.ts";
129
import { chatOutboxOwner } from "./chat-outbox-owner.ts";
1310
import {
1411
admitStoredChatComposerQueueItem,
@@ -98,21 +95,18 @@ export function subscribeChatOutboxProjection(host: ChatQueueScopedSessionHost):
9895
export function enqueueChatMessage(
9996
host: ChatQueueScopedSessionHost,
10097
text: string,
101-
attachments?: ChatAttachment[],
10298
refreshSessions?: boolean,
10399
localCommand?: { args: string; name: string },
104100
sender?: SenderIdentity,
105101
): ChatQueueItem | null {
106102
const trimmed = text.trim();
107-
const hasAttachments = Boolean(attachments && attachments.length > 0);
108-
if (!trimmed && !hasAttachments) {
103+
if (!trimmed) {
109104
return null;
110105
}
111106
const item: ChatQueueItem = {
112107
id: generateUUID(),
113108
text: trimmed,
114109
createdAt: Date.now(),
115-
attachments: hasAttachments ? cloneChatAttachmentsMetadata(attachments ?? []) : undefined,
116110
refreshSessions,
117111
localCommandArgs: localCommand?.args,
118112
localCommandName: localCommand?.name,
@@ -128,12 +122,10 @@ export function enqueuePendingRunMessage(
128122
host: ChatQueueScopedSessionHost,
129123
text: string,
130124
pendingRunId: string,
131-
attachments?: ChatAttachment[],
132125
sender?: SenderIdentity,
133126
) {
134127
const trimmed = text.trim();
135-
const hasAttachments = Boolean(attachments && attachments.length > 0);
136-
if (!trimmed && !hasAttachments) {
128+
if (!trimmed) {
137129
return;
138130
}
139131
// Local commands join an existing run without a wire chat.send, so this
@@ -142,7 +134,6 @@ export function enqueuePendingRunMessage(
142134
id: generateUUID(),
143135
text: trimmed,
144136
createdAt: Date.now(),
145-
attachments: hasAttachments ? cloneChatAttachmentsMetadata(attachments ?? []) : undefined,
146137
pendingRunId,
147138
...(sender ? { sender } : {}),
148139
};

‎ui/src/pages/chat/chat-send-actions.ts‎

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
resumeStoredChatOutboxes as resumeStoredChatOutboxesDrain,
1515
scheduleStoredChatOutboxDrain,
1616
} from "./chat-outbox-drain.ts";
17+
import { chatOutboxOwner } from "./chat-outbox-owner.ts";
1718
import {
1819
admitQueuedMessageForSession,
1920
isVolatileQueuedMessage,
@@ -36,7 +37,7 @@ import {
3637
resolveDisplayedLeafEntryId,
3738
} from "./chat-send-request.ts";
3839
import { OFFLINE_QUEUE_STORAGE_ERROR } from "./chat-send-support.ts";
39-
import { listStoredChatOutboxes, storedChatOutboxScopeKey } from "./composer-persistence.ts";
40+
import { storedChatOutboxScopeKey } from "./composer-persistence.ts";
4041
import { formatConnectError } from "./connect-error.ts";
4142
import {
4243
activeQueuedMessageEdit,
@@ -101,10 +102,6 @@ export async function sendChatMessageWithGeneratedRunId(
101102
}
102103
}
103104

104-
function findStoredOutbox(host: ChatHost, id: string) {
105-
return listStoredChatOutboxes(host).find(({ queue }) => queue.some((item) => item.id === id));
106-
}
107-
108105
const resetRetryState = (
109106
entry: ChatQueueItem,
110107
sendState: ChatQueueItem["sendState"],
@@ -246,7 +243,7 @@ export async function retryQueuedChatMessage(host: ChatHost, id: string) {
246243
) {
247244
return;
248245
}
249-
let outbox = findStoredOutbox(host, item.id);
246+
let outbox = chatOutboxOwner(host).durable(host, item.id);
250247
if (!outbox) {
251248
const wasVolatile = isVolatileQueuedMessage(host, item.id);
252249
if (!admitQueuedMessageForSession(host, item.sessionKey ?? host.sessionKey, item)) {
@@ -281,7 +278,7 @@ export async function retryQueuedChatMessage(host: ChatHost, id: string) {
281278
setChatError(host, OFFLINE_QUEUE_STORAGE_ERROR);
282279
return;
283280
}
284-
outbox = findStoredOutbox(host, retry.id);
281+
outbox = chatOutboxOwner(host).durable(host, retry.id);
285282
if (!outbox) {
286283
setChatError(host, OFFLINE_QUEUE_STORAGE_ERROR);
287284
return;

‎ui/src/pages/chat/chat-send-submit.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,6 @@ export async function handleSendChat(
402402
const queued = enqueueChatMessage(
403403
host,
404404
message,
405-
undefined,
406405
isChatResetCommand(message),
407406
{
408407
args: parsed.args,

0 commit comments

Comments
 (0)