103 lines
2.8 KiB
TypeScript
103 lines
2.8 KiB
TypeScript
import type { StatusTone } from "../../components/StatusPill";
|
|
import type { OrchestrationLatestTurn, OrchestrationSession } from "@t3tools/contracts";
|
|
import { EnvironmentThreadShell } from "@t3tools/client-runtime/state/shell";
|
|
|
|
export type ThreadStatusKind =
|
|
| "pending-approval"
|
|
| "awaiting-input"
|
|
| "working"
|
|
| "connecting"
|
|
| "error"
|
|
| "plan-ready";
|
|
|
|
export interface ThreadStatusPresentation extends StatusTone {
|
|
readonly kind: ThreadStatusKind;
|
|
/** Whether the indicator represents in-flight activity. */
|
|
readonly pulse: boolean;
|
|
}
|
|
|
|
function isLatestTurnSettled(
|
|
latestTurn: OrchestrationLatestTurn | null,
|
|
session: OrchestrationSession | null,
|
|
): boolean {
|
|
if (!latestTurn?.startedAt) return false;
|
|
if (!latestTurn.completedAt) return false;
|
|
if (!session) return true;
|
|
return session.status !== "running";
|
|
}
|
|
|
|
/**
|
|
* Resolves the user-facing status of a thread, in priority order. Returns
|
|
* `null` for quiescent threads so rows stay free of "Idle"-style noise.
|
|
* Mirrors `resolveThreadStatusPill` in apps/web/src/components/Sidebar.logic.ts.
|
|
*/
|
|
export function resolveThreadStatus(
|
|
thread: EnvironmentThreadShell,
|
|
): ThreadStatusPresentation | null {
|
|
if (thread.hasPendingApprovals) {
|
|
return {
|
|
kind: "pending-approval",
|
|
label: "Needs Approval",
|
|
pillClassName: "bg-warning",
|
|
textClassName: "text-warning-foreground",
|
|
pulse: false,
|
|
};
|
|
}
|
|
|
|
if (thread.hasPendingUserInput) {
|
|
return {
|
|
kind: "awaiting-input",
|
|
label: "Awaiting Input",
|
|
pillClassName: "bg-adaptive-indigo-500-a12-a16",
|
|
textClassName: "text-adaptive-indigo-600-300",
|
|
pulse: false,
|
|
};
|
|
}
|
|
|
|
if (thread.session?.status === "running") {
|
|
return {
|
|
kind: "working",
|
|
label: "Working",
|
|
pillClassName: "bg-adaptive-sky-500-a12-a16",
|
|
textClassName: "text-adaptive-sky-600-400",
|
|
pulse: true,
|
|
};
|
|
}
|
|
|
|
if (thread.session?.status === "starting") {
|
|
return {
|
|
kind: "connecting",
|
|
label: "Connecting",
|
|
pillClassName: "bg-adaptive-sky-500-a12-a16",
|
|
textClassName: "text-adaptive-sky-600-400",
|
|
pulse: true,
|
|
};
|
|
}
|
|
|
|
if (thread.session?.status === "error" || thread.latestTurn?.state === "error") {
|
|
return {
|
|
kind: "error",
|
|
label: "Error",
|
|
pillClassName: "bg-danger",
|
|
textClassName: "text-danger-foreground",
|
|
pulse: false,
|
|
};
|
|
}
|
|
|
|
const hasPlanReadyPrompt =
|
|
thread.interactionMode === "plan" &&
|
|
isLatestTurnSettled(thread.latestTurn, thread.session) &&
|
|
thread.hasActionableProposedPlan;
|
|
if (hasPlanReadyPrompt) {
|
|
return {
|
|
kind: "plan-ready",
|
|
label: "Plan Ready",
|
|
pillClassName: "bg-adaptive-violet-500-a12-a16",
|
|
textClassName: "text-adaptive-violet-600-400",
|
|
pulse: false,
|
|
};
|
|
}
|
|
|
|
return null;
|
|
}
|