Skip to content
29 changes: 21 additions & 8 deletions apps/web/src/components/Sidebar.logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { cn } from "../lib/utils";
import { isLatestTurnSettled } from "../session-logic";

export const THREAD_SELECTION_SAFE_SELECTOR = "[data-thread-item], [data-thread-selection-safe]";
export const THREAD_JUMP_HINT_SHOW_DELAY_MS = 100;
export const THREAD_JUMP_HINT_SHOW_DELAY_MS = 75;
export type SidebarNewThreadEnvMode = "local" | "worktree";
type SidebarProject = {
id: string;
Expand All @@ -14,6 +14,7 @@ type SidebarProject = {
updatedAt?: string | undefined;
};
type SidebarThreadSortInput = Pick<Thread, "createdAt" | "updatedAt"> & {
projectId: string;
latestUserMessageAt?: string | null;
messages?: Pick<Thread["messages"][number], "createdAt" | "role">[];
};
Expand Down Expand Up @@ -44,16 +45,28 @@ const THREAD_STATUS_PRIORITY: Record<ThreadStatusPill["label"], number> = {

type ThreadStatusInput = Pick<
SidebarThreadSummary,
| "hasActionableProposedPlan"
| "hasPendingApprovals"
| "hasPendingUserInput"
| "interactionMode"
| "latestTurn"
| "session"
"hasActionableProposedPlan" | "hasPendingApprovals" | "hasPendingUserInput" | "interactionMode"
> & {
latestTurn: ThreadStatusLatestTurnSnapshot | null;
session: ThreadStatusSessionSnapshot | null;
lastVisitedAt?: string | undefined;
};

type LatestTurnSnapshot = NonNullable<SidebarThreadSummary["latestTurn"]>;
type SessionSnapshot = NonNullable<SidebarThreadSummary["session"]>;

export interface ThreadStatusLatestTurnSnapshot {
turnId: LatestTurnSnapshot["turnId"];
startedAt: LatestTurnSnapshot["startedAt"];
completedAt: LatestTurnSnapshot["completedAt"];
}

export interface ThreadStatusSessionSnapshot {
orchestrationStatus: SessionSnapshot["orchestrationStatus"];
activeTurnId?: SessionSnapshot["activeTurnId"];
status: SessionSnapshot["status"];
}

export interface ThreadJumpHintVisibilityController {
sync: (shouldShow: boolean) => void;
dispose: () => void;
Expand Down Expand Up @@ -541,7 +554,7 @@ export function getProjectSortTimestamp(

export function sortProjectsForSidebar<
TProject extends SidebarProject,
TThread extends Pick<Thread, "projectId" | "createdAt" | "updatedAt"> & SidebarThreadSortInput,
TThread extends SidebarThreadSortInput,
>(
projects: readonly TProject[],
threads: readonly TThread[],
Expand Down
Loading
Loading