Open History to see the last commit
1import { presentThreadShell } from "@t3tools/client-runtime/state/shell";
2import {
3 EnvironmentId,
4 MessageId,
5 RunId,
6 TurnItemId,
7 type OrchestrationV2ProjectedTurnItem,
8 type OrchestrationV2TurnItem,
9 ProjectId,
10 ProviderInstanceId,
11 ThreadId,
12 type OrchestrationV2ThreadProjection,
13} from "@t3tools/contracts";
14import * as DateTime from "effect/DateTime";
15
16import type { ChatMessage, Thread } from "./types";
17
18const DEFAULT_TIMESTAMP = "2026-01-01T00:00:00.000Z";
19
20export type ThreadFixtureOverrides = Partial<Thread> & {
21 readonly messages?: ReadonlyArray<ChatMessage>;
22 readonly proposedPlans?: ReadonlyArray<unknown>;
23};
24
25export function makeThreadProjectionFixture(): OrchestrationV2ThreadProjection {
26 const now = DateTime.makeUnsafe(DEFAULT_TIMESTAMP);
27 const id = ThreadId.make("thread-test");
28 const providerInstanceId = ProviderInstanceId.make("codex");
29 return {
30 thread: {
31 id,
32 projectId: ProjectId.make("project-test"),
33 title: "Thread",
34 providerInstanceId,
35 modelSelection: { instanceId: providerInstanceId, model: "gpt-5.4" },
36 runtimeMode: "full-access",
37 interactionMode: "default",
38 branch: null,
39 worktreePath: null,
40 activeProviderThreadId: null,
41 lineage: { rootThreadId: id, parentThreadId: null, relationshipToParent: null },
42 forkedFrom: null,
43 createdBy: "user",
44 creationSource: "web",
45 createdAt: now,
46 updatedAt: now,
47 archivedAt: null,
48 settledOverride: null,
49 settledAt: null,
50 lastVisitedAt: null,
51 deletedAt: null,
52 },
53 runs: [],
54 attempts: [],
55 nodes: [],
56 subagents: [],
57 providerSessions: [],
58 providerThreads: [],
59 providerTurns: [],
60 runtimeRequests: [],
61 messages: [],
62 plans: [],
63 turnItems: [],
64 checkpointScopes: [],
65 checkpoints: [],
66 contextHandoffs: [],
67 contextTransfers: [],
68 visibleTurnItems: [],
69 updatedAt: now,
70 };
71}
72
73export function makeThreadFixture(overrides: ThreadFixtureOverrides = {}): Thread {
74 const environmentId = overrides.environmentId ?? EnvironmentId.make("environment-test");
75 const id = overrides.id ?? ThreadId.make("thread-test");
76 const projectId = overrides.projectId ?? ProjectId.make("project-test");
77 const providerInstanceId =
78 overrides.providerInstanceId ??
79 overrides.modelSelection?.instanceId ??
80 ProviderInstanceId.make("codex");
81 const modelSelection = overrides.modelSelection ?? {
82 instanceId: providerInstanceId,
83 model: "gpt-5.4",
84 };
85 const createdAt = DateTime.makeUnsafe(DEFAULT_TIMESTAMP);
86 const updatedAt = DateTime.makeUnsafe(DEFAULT_TIMESTAMP);
87 const archivedAt =
88 overrides.archivedAt === null || overrides.archivedAt === undefined
89 ? null
90 : DateTime.makeUnsafe(overrides.archivedAt);
91 const deletedAt =
92 overrides.deletedAt === null || overrides.deletedAt === undefined
93 ? null
94 : DateTime.makeUnsafe(overrides.deletedAt);
95 const shell = presentThreadShell(environmentId, {
96 id,
97 projectId,
98 title: overrides.title ?? "Thread",
99 providerInstanceId,
100 modelSelection,
101 runtimeMode: overrides.runtimeMode ?? "full-access",
102 interactionMode: overrides.interactionMode ?? "default",
103 branch: overrides.branch ?? null,
104 worktreePath: overrides.worktreePath ?? null,
105 activeProviderThreadId: overrides.activeProviderThreadId ?? null,
106 lineage: overrides.lineage ?? {
107 rootThreadId: id,
108 parentThreadId: null,
109 relationshipToParent: null,
110 },
111 forkedFrom: overrides.forkedFrom ?? null,
112 createdBy: "user",
113 creationSource: "web",
114 latestRunId: overrides.latestRun?.runId ?? null,
115 activeRunId: overrides.runtime?.activeRunId ?? null,
116 status: overrides.runtime?.status ?? "idle",
117 pendingRuntimeRequest: null,
118 latestVisibleMessage: null,
119 latestUserMessageAt:
120 overrides.latestUserMessageAt === null || overrides.latestUserMessageAt === undefined
121 ? null
122 : DateTime.makeUnsafe(overrides.latestUserMessageAt),
123 hasActionableProposedPlan: overrides.hasActionableProposedPlan ?? false,
124 itemCount: overrides.itemCount ?? 0,
125 visibleItemCount: overrides.visibleItemCount ?? 0,
126 createdAt,
127 updatedAt,
128 archivedAt,
129 settledOverride: overrides.settledOverride ?? null,
130 settledAt:
131 overrides.settledAt === null || overrides.settledAt === undefined
132 ? null
133 : DateTime.makeUnsafe(overrides.settledAt),
134 deletedAt,
135 });
136
137 return { ...shell, ...overrides };
138}
139
140export function makeStreamingTimelineFixture(text = "") {
141 const threadId = ThreadId.make("streaming-thread");
142 const runId = RunId.make("live-run");
143 const historyRunId = RunId.make("history-run");
144 const time = (second: number) => new Date(Date.UTC(2026, 8, 4, 0, 0, second)).toISOString();
145 const base = (id: string, run: typeof runId, second: number) => ({
146 id: TurnItemId.make(id),
147 threadId,
148 runId: run,
149 nodeId: null,
150 providerThreadId: null,
151 providerTurnId: null,
152 nativeItemRef: null,
153 parentItemId: null,
154 ordinal: second,
155 status: "completed" as const,
156 title: null,
157 startedAt: DateTime.makeUnsafe(time(second)),
158 completedAt: DateTime.makeUnsafe(time(second)),
159 updatedAt: DateTime.makeUnsafe(time(second)),
160 });
161 const items: OrchestrationV2TurnItem[] = [
162 {
163 ...base("history-user-item", historyRunId, 0),
164 type: "user_message",
165 messageId: MessageId.make("history-user"),
166 text: "Inspect",
167 attachments: [],
168 inputIntent: "turn_start",
169 createdBy: "user",
170 creationSource: "web",
171 },
172 {
173 ...base("history-work", historyRunId, 1),
174 type: "command_execution",
175 status: "failed",
176 input: "vp test",
177 output: "Test failed",
178 exitCode: 1,
179 },
180 {
181 ...base("history-assistant-item", historyRunId, 3),
182 type: "assistant_message",
183 messageId: MessageId.make("history-assistant"),
184 text: "Done",
185 streaming: false,
186 updatedAt: DateTime.makeUnsafe(time(4)),
187 },
188 {
189 ...base("live-user-item", runId, 5),
190 type: "user_message",
191 messageId: MessageId.make("live-user"),
192 text: "Continue",
193 attachments: [],
194 inputIntent: "turn_start",
195 createdBy: "user",
196 creationSource: "web",
197 },
198 {
199 ...base("live-work", runId, 6),
200 type: "dynamic_tool",
201 toolName: "read_file",
202 input: { path: "/repo/src/index.ts" },
203 output: "Contents",
204 },
205 {
206 ...base("live-assistant-item", runId, 7),
207 type: "assistant_message",
208 messageId: MessageId.make("live-assistant"),
209 text,
210 streaming: true,
211 status: "running",
212 completedAt: null,
213 },
214 ];
215 const visibleTurnItems: OrchestrationV2ProjectedTurnItem[] = items.map((item, position) => ({
216 position,
217 visibility: "local",
218 sourceThreadId: threadId,
219 sourceItemId: item.id,
220 item,
221 }));
222 return { threadId, runId, historyRunId, visibleTurnItems, time };
223}