Open History to see the last commit
1import type { WorktreeSetupSnapshot } from "@t3tools/contracts";
2import {
3 type EnvironmentId,
4 type MessageId,
5 type OrchestrationV2TurnItem,
6 type RunAttemptId,
7 type ScopedThreadRef,
8 type ServerProviderSkill,
9 type RunId,
10 ThreadId,
11} from "@t3tools/contracts";
12import type { WorkflowOpening } from "@t3tools/client-runtime/state/subagentRuntime";
13import { createContext, type MouseEvent } from "react";
14import { type LegendListRef } from "@legendapp/list/react";
15import type { CodexArtifactTemplate } from "@t3tools/shared/codexArtifactTemplates";
16import { type ChatFileAttachment } from "../../types";
17import { ExpandedImagePreview } from "./ExpandedImagePreview";
18import { type AssistantCitationTarget } from "./AssistantCitationSource";
19import { type MessagesTimelineRow, type WorkGroupScrollAnchor } from "./MessagesTimeline.logic";
20import { type TimestampFormat } from "@t3tools/contracts/settings";
21import { type HandoffTimelineRun } from "./V2LifecycleRow";
22
23export interface TimelineRowSharedState {
24 citationRequest: AssistantCitationTarget | null;
25 listRef: React.RefObject<LegendListRef | null>;
26 timestampFormat: TimestampFormat;
27 routeThreadKey: string;
28 threadRef: ScopedThreadRef | null;
29 markdownCwd: string | undefined;
30 resolvedTheme: "light" | "dark";
31 workspaceRoot: string | undefined;
32 skills: ReadonlyArray<Pick<ServerProviderSkill, "name" | "displayName">>;
33 runs: ReadonlyArray<HandoffTimelineRun>;
34 activeThreadEnvironmentId: EnvironmentId;
35 onRevertToTurnCount: (targetTurnCount: number, messageId: MessageId) => void;
36 onUseArtifactTemplate: (template: CodexArtifactTemplate) => void;
37 onSendAppMessage: ((text: string) => Promise<void>) | undefined;
38 onAppFullscreenChange: (rowId: string, fullscreen: boolean) => void;
39 onRunShellCommand: ((command: string) => void) | undefined;
40 findActive: boolean;
41 onImageExpand: (preview: ExpandedImagePreview) => void;
42 displayThreadKey?: string;
43 onOpenTurnDiff: (runId: RunId, filePath?: string) => void;
44 onOpenThread: (threadId: OrchestrationV2TurnItem["threadId"]) => void;
45 workflowOpening: WorkflowOpening | null;
46 onForkFromRun: (input: {
47 readonly sourceThreadId: ThreadId;
48 readonly runId: RunId;
49 }) => Promise<void>;
50 onRollbackCheckpoint: (input: {
51 readonly checkpointId: string;
52 readonly scopeId: string;
53 }) => void;
54 onToggleTurnFold: (runId: RunId) => void;
55 onToggleAttemptFold: (attemptId: RunAttemptId) => void;
56 onFileOpen: (attachment: ChatFileAttachment) => void;
57 onFileDownload: (attachment: ChatFileAttachment) => void;
58 openPullRequest: (event: MouseEvent<HTMLElement>, url: string) => void;
59 onToggleWorkGroup: (groupId: string, anchorKey: string) => void;
60 onToggleWorkEntry: (anchorKey: string, collapsed: boolean) => void;
61 onCancelWorktreeSetup: (() => void) | null;
62 retryableWorkspacePreparationRunIds: ReadonlySet<RunId>;
63 onRetryWorkspacePreparation: ((runId: RunId) => void) | null;
64 onWorktreeSetupWorkLocally: (() => void) | null;
65 onOpenWorktreeSetupTerminal: ((terminalId: string) => void) | null;
66 workGroupViewState: WorkGroupViewState;
67}
68
69export interface TimelineRowActivityState {
70 isWorking: boolean;
71 isCompacting: boolean;
72 isRevertingCheckpoint: boolean;
73 activeTurnInProgress: boolean;
74 awaitingUser: boolean;
75 isPreparingWorktree: boolean;
76 latestRunId: RunId | null;
77 backgroundWorktreeSetup: WorktreeSetupSnapshot | null;
78}
79
80export const TimelineRowCtx = createContext<TimelineRowSharedState>(null!);
81
82export const TimelineRowActivityCtx = createContext<TimelineRowActivityState>(null!);
83
84export interface WorkGroupViewState {
85 scrollPositions: Map<string, WorkGroupScrollAnchor>;
86 expandedEntries: Set<string>;
87}
88
89export const WorkGroupViewCtx = createContext<{
90 state: WorkGroupViewState;
91 onToggleEntry: (collapsed: boolean) => void;
92} | null>(null);
93
94export type TimelineWorkEntry = Extract<
95 MessagesTimelineRow,
96 { kind: "work" }
97>["groupedEntries"][number];
98
99export type TimelineRow = MessagesTimelineRow;