Show working status for new threads
This commit is contained in:
2 files changed
+81
-1
No files matched your search
@@ -170,6 +170,7 @@ describe("hasUnseenCompletion", () => {
|
||||
hasPendingUserInput: false,
|
||||
interactionMode: "default",
|
||||
latestTurn: makeLatestTurn(),
|
||||
latestUserMessageAt: null,
|
||||
lastVisitedAt: "2026-03-09T10:04:00.000Z",
|
||||
session: null,
|
||||
}),
|
||||
@@ -184,6 +185,7 @@ describe("hasUnseenCompletion", () => {
|
||||
hasPendingUserInput: false,
|
||||
interactionMode: "default",
|
||||
latestTurn: makeLatestTurn(),
|
||||
latestUserMessageAt: null,
|
||||
lastVisitedAt: undefined,
|
||||
session: null,
|
||||
}),
|
||||
@@ -737,6 +739,7 @@ describe("resolveThreadStatusPill", () => {
|
||||
hasPendingUserInput: false,
|
||||
interactionMode: "plan" as const,
|
||||
latestTurn: null,
|
||||
latestUserMessageAt: null,
|
||||
lastVisitedAt: undefined,
|
||||
session: {
|
||||
threadId: ThreadId.make("thread-1"),
|
||||
@@ -781,6 +784,56 @@ describe("resolveThreadStatusPill", () => {
|
||||
).toMatchObject({ label: "Working", pulse: true });
|
||||
});
|
||||
|
||||
it("shows working while a new thread turn is waiting for its first session update", () => {
|
||||
expect(
|
||||
resolveThreadStatusPill({
|
||||
thread: {
|
||||
...baseThread,
|
||||
latestUserMessageAt: "2026-03-09T10:00:01.000Z",
|
||||
session: null,
|
||||
},
|
||||
}),
|
||||
).toMatchObject({ label: "Working", pulse: true });
|
||||
});
|
||||
|
||||
it("keeps showing working through a ready session before the turn starts", () => {
|
||||
expect(
|
||||
resolveThreadStatusPill({
|
||||
thread: {
|
||||
...baseThread,
|
||||
latestUserMessageAt: "2026-03-09T10:00:01.000Z",
|
||||
session: {
|
||||
...baseThread.session,
|
||||
status: "ready",
|
||||
activeTurnId: null,
|
||||
updatedAt: "2026-03-09T10:00:02.000Z",
|
||||
},
|
||||
},
|
||||
}),
|
||||
).toMatchObject({ label: "Working", pulse: true });
|
||||
});
|
||||
|
||||
it("does not show stale pending work after the turn acknowledges the message", () => {
|
||||
expect(
|
||||
resolveThreadStatusPill({
|
||||
thread: {
|
||||
...baseThread,
|
||||
latestUserMessageAt: "2026-03-09T10:00:01.000Z",
|
||||
latestTurn: {
|
||||
...makeLatestTurn(),
|
||||
requestedAt: "2026-03-09T10:00:02.000Z",
|
||||
},
|
||||
session: {
|
||||
...baseThread.session,
|
||||
status: "ready",
|
||||
activeTurnId: null,
|
||||
updatedAt: "2026-03-09T10:05:00.000Z",
|
||||
},
|
||||
},
|
||||
}),
|
||||
).toBeNull();
|
||||
});
|
||||
|
||||
it("shows plan ready when a settled plan turn has a proposed plan ready for follow-up", () => {
|
||||
expect(
|
||||
resolveThreadStatusPill({
|
||||
|
||||
@@ -115,6 +115,7 @@ type ThreadStatusInput = Pick<
|
||||
| "hasPendingUserInput"
|
||||
| "interactionMode"
|
||||
| "latestTurn"
|
||||
| "latestUserMessageAt"
|
||||
| "session"
|
||||
> & {
|
||||
lastVisitedAt?: string | undefined;
|
||||
@@ -223,6 +224,32 @@ export function hasUnseenCompletion(thread: ThreadStatusInput): boolean {
|
||||
return completedAt > lastVisitedAt;
|
||||
}
|
||||
|
||||
function hasPendingTurnStart(thread: ThreadStatusInput): boolean {
|
||||
if (!thread.latestUserMessageAt) return false;
|
||||
const latestUserMessageAt = Date.parse(thread.latestUserMessageAt);
|
||||
if (Number.isNaN(latestUserMessageAt)) return false;
|
||||
|
||||
const latestTurnRequestedAt = thread.latestTurn
|
||||
? Date.parse(thread.latestTurn.requestedAt)
|
||||
: Number.NaN;
|
||||
if (!Number.isNaN(latestTurnRequestedAt) && latestTurnRequestedAt >= latestUserMessageAt) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Session bootstrap may pass through starting/ready before the provider
|
||||
// creates the turn; only terminal states can acknowledge a failed start.
|
||||
const session = thread.session;
|
||||
if (
|
||||
!session ||
|
||||
(session.status !== "error" && session.status !== "interrupted" && session.status !== "stopped")
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const sessionUpdatedAt = Date.parse(session.updatedAt);
|
||||
return Number.isNaN(sessionUpdatedAt) || sessionUpdatedAt < latestUserMessageAt;
|
||||
}
|
||||
|
||||
export function shouldClearThreadSelectionOnMouseDown(target: HTMLElement | null): boolean {
|
||||
if (target === null) return true;
|
||||
return !target.closest(THREAD_SELECTION_SAFE_SELECTOR);
|
||||
@@ -505,7 +532,7 @@ export function resolveThreadStatusPill(input: {
|
||||
};
|
||||
}
|
||||
|
||||
if (thread.session?.status === "running") {
|
||||
if (thread.session?.status === "running" || hasPendingTurnStart(thread)) {
|
||||
return {
|
||||
label: "Working",
|
||||
colorClass: "text-sky-600 dark:text-sky-300/80",
|
||||
|
||||
Reference in new issue
Block a user