Skip to content

Commit cc839c4

Browse files
authored
feat(web): queue messages sent client-side while the agent is working (pingdotgg#11673)
1 parent 2c19283 commit cc839c4

10 files changed

Lines changed: 831 additions & 38 deletions

‎apps/web/src/components/ChatView.tsx‎

Lines changed: 288 additions & 12 deletions
Large diffs are not rendered by default.

‎apps/web/src/components/chat/ChatComposer.tsx‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1166,7 +1166,6 @@ const ComposerFooterPrimaryActions = memo(function ComposerFooterPrimaryActions(
11661166
isEnvironmentUnavailable: boolean;
11671167
hasSendableContent: boolean;
11681168
preserveComposerFocusOnPointerDown?: boolean;
1169-
showSendWhileRunning?: boolean;
11701169
onPreviousPendingQuestion: () => void;
11711170
onInterrupt: () => void;
11721171
onImplementPlanInNewThread: () => void;
@@ -1200,7 +1199,6 @@ const ComposerFooterPrimaryActions = memo(function ComposerFooterPrimaryActions(
12001199
isPreparingWorktree={props.isPreparingWorktree}
12011200
hasSendableContent={props.hasSendableContent}
12021201
preserveComposerFocusOnPointerDown={props.preserveComposerFocusOnPointerDown ?? false}
1203-
showSendWhileRunning={props.showSendWhileRunning ?? false}
12041202
onPreviousPendingQuestion={props.onPreviousPendingQuestion}
12051203
onInterrupt={props.onInterrupt}
12061204
onImplementPlanInNewThread={props.onImplementPlanInNewThread}
@@ -6845,7 +6843,6 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
68456843
isPreparingWorktree={isPreparingWorktree}
68466844
hasSendableContent={composerSendState.hasSendableContent}
68476845
preserveComposerFocusOnPointerDown={isMobileViewport || isComposerResting}
6848-
showSendWhileRunning={isMobileViewport}
68496846
onPreviousPendingQuestion={onPreviousActivePendingUserInputQuestion}
68506847
onInterrupt={handleInterruptPrimaryAction}
68516848
onImplementPlanInNewThread={handleImplementPlanInNewThreadPrimaryAction}

‎apps/web/src/components/chat/ComposerPrimaryActions.test.tsx‎

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ function renderPendingActions(isRunning: boolean) {
4444
);
4545
}
4646

47-
function renderRunningActions(showSendWhileRunning: boolean, hasSendableContent: boolean) {
47+
function renderRunningActions(hasSendableContent: boolean) {
4848
return renderToStaticMarkup(
4949
createElement(ComposerPrimaryActions, {
5050
compact: true,
@@ -58,7 +58,6 @@ function renderRunningActions(showSendWhileRunning: boolean, hasSendableContent:
5858
isEnvironmentUnavailable: false,
5959
isPreparingWorktree: false,
6060
hasSendableContent,
61-
showSendWhileRunning,
6261
onPreviousPendingQuestion: () => {},
6362
onInterrupt: () => {},
6463
onImplementPlanInNewThread: () => {},
@@ -125,25 +124,18 @@ describe("ComposerPrimaryActions", () => {
125124
expect(markup).not.toContain("stage-nightly");
126125
});
127126

128-
it("only renders stop while running when Enter-to-send is available", () => {
129-
const markup = renderRunningActions(false, true);
127+
it("renders a queue action alongside stop while running with a sendable draft", () => {
128+
const markup = renderRunningActions(true);
130129

131130
expect(markup).toContain('aria-label="Stop generation"');
132-
expect(markup).not.toContain('aria-label="Send message"');
133-
});
134-
135-
it("renders send alongside stop while running when Enter-to-send is unavailable", () => {
136-
const markup = renderRunningActions(true, true);
137-
138-
expect(markup).toContain('aria-label="Stop generation"');
139-
expect(markup).toContain('aria-label="Send message"');
131+
expect(markup).toContain('aria-label="Queue message"');
140132
expect(markup).toContain('type="submit"');
141133
});
142134

143135
it("keeps stop as the only action while running with an empty composer", () => {
144-
const markup = renderRunningActions(true, false);
136+
const markup = renderRunningActions(false);
145137

146138
expect(markup).toContain('aria-label="Stop generation"');
147-
expect(markup).not.toContain('aria-label="Send message"');
139+
expect(markup).not.toContain('aria-label="Queue message"');
148140
});
149141
});

‎apps/web/src/components/chat/ComposerPrimaryActions.tsx‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@ interface ComposerPrimaryActionsProps {
2929
isPreparingWorktree: boolean;
3030
hasSendableContent: boolean;
3131
preserveComposerFocusOnPointerDown?: boolean;
32-
/** Enter-to-send is disabled on mobile viewports, where stop would otherwise
33-
* be the only primary action and a running turn could not be steered. */
34-
showSendWhileRunning?: boolean;
3532
onPreviousPendingQuestion: () => void;
3633
onInterrupt: () => void;
3734
onImplementPlanInNewThread: () => void;
@@ -72,7 +69,6 @@ export const ComposerPrimaryActions = memo(function ComposerPrimaryActions({
7269
isPreparingWorktree,
7370
hasSendableContent,
7471
preserveComposerFocusOnPointerDown = false,
75-
showSendWhileRunning = false,
7672
onPreviousPendingQuestion,
7773
onInterrupt,
7874
onImplementPlanInNewThread,
@@ -93,7 +89,7 @@ export const ComposerPrimaryActions = memo(function ComposerPrimaryActions({
9389
"flex cursor-pointer items-center justify-center rounded-full bg-destructive/90 text-white shadow-xs shadow-destructive/24 inset-shadow-[0_1px_--theme(--color-white/16%)] transition-all duration-150 hover:bg-destructive hover:scale-105 active:inset-shadow-[0_1px_--theme(--color-black/8%)] active:shadow-none",
9490
insidePendingAction
9591
? "size-8 sm:size-7"
96-
: showSendWhileRunning && hasSendableContent
92+
: hasSendableContent
9793
? "size-9 sm:size-8"
9894
: "size-8 sm:h-8 sm:w-8",
9995
)}
@@ -247,7 +243,9 @@ export const ComposerPrimaryActions = memo(function ComposerPrimaryActions({
247243
? "Preparing worktree"
248244
: isSendBusy
249245
? "Sending"
250-
: "Send message"
246+
: isRunning
247+
? "Queue message"
248+
: "Send message"
251249
}
252250
>
253251
{stageBackdropVariant ? (
@@ -275,10 +273,12 @@ export const ComposerPrimaryActions = memo(function ComposerPrimaryActions({
275273
return sendButton;
276274
}
277275

276+
// While a turn runs, a sendable draft queues for the next tool boundary, so
277+
// the send button stays next to Stop on every viewport.
278278
return (
279279
<>
280280
{renderStopGenerationButton(false)}
281-
{showSendWhileRunning && hasSendableContent ? sendButton : null}
281+
{hasSendableContent ? sendButton : null}
282282
</>
283283
);
284284
});

‎apps/web/src/components/chat/MessagesTimeline.logic.test.ts‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,6 +1092,40 @@ describe("resolveAssistantMessageCopyState", () => {
10921092
});
10931093

10941094
describe("deriveMessagesTimelineRows", () => {
1095+
it("appends queued messages after the live rows, marking the oldest as next", () => {
1096+
const queuedMessage = (id: string, prompt: string) => ({
1097+
id,
1098+
prompt,
1099+
images: [],
1100+
files: [],
1101+
terminalContexts: [],
1102+
previewAnnotations: [],
1103+
reviewComments: [],
1104+
submissionIntent: "foreground" as const,
1105+
queuedAfterToolActivityId: null,
1106+
createdAt: "2026-01-01T00:00:01Z",
1107+
});
1108+
const rows = deriveMessagesTimelineRows({
1109+
timelineEntries: [],
1110+
isWorking: true,
1111+
activeTurnStartedAt: "2026-01-01T00:00:00Z",
1112+
turnDiffSummaries: [],
1113+
supportsConversationRollback: false,
1114+
queuedMessages: [queuedMessage("q1", "first"), queuedMessage("q2", "second")],
1115+
});
1116+
1117+
expect(rows.map((row) => row.kind)).toEqual([
1118+
"working",
1119+
"thinking",
1120+
"queued-message",
1121+
"queued-message",
1122+
]);
1123+
expect(rows.slice(2)).toMatchObject([
1124+
{ id: "queued-message:q1", isNext: true, queuedMessage: { prompt: "first" } },
1125+
{ id: "queued-message:q2", isNext: false, queuedMessage: { prompt: "second" } },
1126+
]);
1127+
});
1128+
10951129
it("shows the worktree setup card instead of the working placeholder", () => {
10961130
const snapshot: WorktreeSetupSnapshot = {
10971131
threadId: ThreadId.make("thread-setup"),

‎apps/web/src/components/chat/MessagesTimeline.logic.ts‎

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {
2828
type WorkLogEntry,
2929
} from "../../session-logic";
3030
import { type ChatMessage, type ProposedPlan, type TurnDiffSummary } from "../../types";
31+
import type { QueuedComposerMessage } from "../../queuedMessageStore";
3132
import {
3233
type MessageId,
3334
type OrchestrationLatestTurn,
@@ -402,6 +403,14 @@ export type MessagesTimelineRow =
402403
snapshot: WorktreeSetupSnapshot;
403404
/** The agent already started; render only the script row under the turn header. */
404405
embedded: boolean;
406+
}
407+
| {
408+
kind: "queued-message";
409+
id: string;
410+
createdAt: string;
411+
queuedMessage: QueuedComposerMessage;
412+
/** Oldest queued message, the one the next boundary sends. */
413+
isNext: boolean;
405414
};
406415

407416
export interface StableMessagesTimelineRowsState {
@@ -872,6 +881,8 @@ export function deriveMessagesTimelineRows(input: {
872881
liveAgentTaskIds?: ReadonlySet<string> | undefined;
873882
/** Live bootstrap progress. Renders a stage card under the first user message. */
874883
worktreeSetup?: WorktreeSetupSnapshot | null;
884+
/** Messages sent during the running turn, rendered after the live rows. */
885+
queuedMessages?: ReadonlyArray<QueuedComposerMessage>;
875886
}): MessagesTimelineRow[] {
876887
const turnDiffSummaryByAssistantMessageId = new Map<MessageId, TurnDiffSummary>();
877888
for (const summary of input.turnDiffSummaries) {
@@ -1329,8 +1340,17 @@ export function deriveMessagesTimelineRows(input: {
13291340
createdAt: input.activeTurnStartedAt,
13301341
});
13311342
}
1332-
1333-
return attachTrailingToolGroupsToAssistant(nextRows);
1343+
const rows = attachTrailingToolGroupsToAssistant(nextRows);
1344+
input.queuedMessages?.forEach((queuedMessage, index) => {
1345+
rows.push({
1346+
kind: "queued-message",
1347+
id: `queued-message:${queuedMessage.id}`,
1348+
createdAt: queuedMessage.createdAt,
1349+
queuedMessage,
1350+
isNext: index === 0,
1351+
});
1352+
});
1353+
return rows;
13341354
}
13351355

13361356
export const WORKTREE_SETUP_ROW_ID = "worktree-setup-row";
@@ -1468,6 +1488,11 @@ function isRowUnchanged(a: MessagesTimelineRow, b: MessagesTimelineRow): boolean
14681488
case "proposed-plan":
14691489
return a.proposedPlan === (b as typeof a).proposedPlan;
14701490

1491+
case "queued-message": {
1492+
const bq = b as typeof a;
1493+
return a.queuedMessage === bq.queuedMessage && a.isNext === bq.isNext;
1494+
}
1495+
14711496
case "work": {
14721497
const bw = b as typeof a;
14731498
return (

0 commit comments

Comments
 (0)