Skip to content
Merged
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
24 changes: 24 additions & 0 deletions apps/web/src/components/ChatView.logic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
buildExpiredTerminalContextToastCopy,
mergeDirectPreviewAnnotation,
planComposerTurn,
deriveTimelineWorking,
snapshotComposerSend,
withMessageContext,
deriveAvailableRevertTurnCounts,
Expand Down Expand Up @@ -45,6 +46,7 @@ import { appAtomRegistry } from "../rpc/atomRegistry";
import { environmentThreadDetails } from "../state/threads";

import type { Thread } from "../types";
import { derivePhase } from "../session-logic";
import { makeThreadFixture, makeThreadProjectionFixture } from "../test-fixtures";
import {
getAntigravitySendBlockReason,
Expand Down Expand Up @@ -1129,6 +1131,28 @@ describe("snapshotComposerSend", () => {
});
});

describe("deriveTimelineWorking", () => {
it.each(["preparing", "starting", "queued"] as const)(
"restores activity from a persisted %s session without a local send",
(status) => {
const state = {
phase: derivePhase({ ...readySession, status }),
isSendBusy: false,
isCompacting: false,
runlessWorkStartedAt: null,
};
expect(deriveTimelineWorking(state)).toBe(true);
expect(deriveTimelineWorking({ ...state, phase: "ready" })).toBe(false);
expect(
deriveTimelineWorking({
...state,
phase: derivePhase({ ...readySession, status: "failed" }),
}),
).toBe(false);
},
);
});

describe("planComposerTurn", () => {
const base = {
messageText: "hello",
Expand Down
16 changes: 16 additions & 0 deletions apps/web/src/components/ChatView.logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1294,6 +1294,22 @@ export function snapshotComposerSend(contents: ComposerSendContents) {

export type ComposerSendSnapshot = ReturnType<typeof snapshotComposerSend>;

/** Derived from the persisted run phase, so a starting run still reads as work after a reload. */
export function deriveTimelineWorking(input: {
readonly phase: SessionPhase;
readonly isSendBusy: boolean;
readonly isCompacting: boolean;
readonly runlessWorkStartedAt: string | null;
}): boolean {
return (
input.phase === "connecting" ||
input.phase === "running" ||
input.isSendBusy ||
input.isCompacting ||
input.runlessWorkStartedAt !== null
);
}

/** How a composer send dispatches: where it runs and whether it waits behind other work. */
export function planComposerTurn(input: {
readonly messageText: string;
Expand Down
9 changes: 7 additions & 2 deletions apps/web/src/components/ChatView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ import {
import {
buildLocalDraftThread,
deriveCommittedServerUserMessageIds,
deriveTimelineWorking,
dismissBranchMismatchForSession,
shouldRenderPreviewMiniPlayer,
deriveLockedProvider,
Expand Down Expand Up @@ -1495,8 +1496,12 @@ export default function ChatView(props: ChatViewProps) {
run: serverProjection?.runs.find((run) => run.id === activeRuntime?.activeRunId),
messages: serverProjection?.messages,
});
const isWorking =
phase === "running" || isSendBusy || isCompacting || runlessWorkStartedAt !== null;
const isWorking = deriveTimelineWorking({
phase,
isSendBusy,
isCompacting,
runlessWorkStartedAt,
});
const activeContextWindow = deriveLatestContextWindowSnapshot(
serverVisibleTurnItems ?? [],
activeThreadLiveTokenUsage,
Expand Down
Loading