Skip to content
Source
Sign inSign up

McpToolAccess.testkit.ts

102 lines2.9 KB

1import {
2 type OrchestrationV2ThreadProjection,
3 type OrchestrationV2ThreadShell,
4 ProjectId,
5 type ProviderInteractionMode,
6 ProviderInstanceId,
7 RunId,
8 type RuntimeMode,
9 type ThreadId,
10} from "@t3tools/contracts";
11import * as DateTime from "effect/DateTime";
12import * as Effect from "effect/Effect";
13import * as Layer from "effect/Layer";
14​
15import * as ThreadManagement from "../orchestration-v2/ThreadManagementService.ts";
16​
17const EPOCH = DateTime.makeUnsafe("2026-01-01T00:00:00.000Z");
18​
19export const liveThreadShell = (
20 id: ThreadId,
21 modes: {
22 readonly runtimeMode?: RuntimeMode;
23 readonly interactionMode?: ProviderInteractionMode;
24 readonly activeRunId?: RunId | null;
25 } = {},
26): OrchestrationV2ThreadShell => {
27 const providerInstanceId = ProviderInstanceId.make("codex");
28 return {
29 id,
30 projectId: ProjectId.make("project:mcp-test"),
31 title: id,
32 providerInstanceId,
33 modelSelection: { instanceId: providerInstanceId, model: "gpt-5" },
34 runtimeMode: modes.runtimeMode ?? "full-access",
35 interactionMode: modes.interactionMode ?? "default",
36 branch: null,
37 worktreePath: null,
38 createdBy: "user",
39 creationSource: "web",
40 activeProviderThreadId: null,
41 lineage: { rootThreadId: id, parentThreadId: null, relationshipToParent: null },
42 forkedFrom: null,
43 latestRunId: null,
44 activeRunId: modes.activeRunId === undefined ? RunId.make("run:mcp-test") : modes.activeRunId,
45 status: "running",
46 pendingRuntimeRequest: null,
47 latestVisibleMessage: null,
48 latestUserMessageAt: null,
49 hasActionableProposedPlan: false,
50 itemCount: 0,
51 visibleItemCount: 0,
52 createdAt: EPOCH,
53 updatedAt: EPOCH,
54 archivedAt: null,
55 settledOverride: null,
56 settledAt: null,
57 lastVisitedAt: null,
58 deletedAt: null,
59 };
60};
61​
62export const liveThreadsLayer = Layer.mock(ThreadManagement.ThreadManagementService)({
63 getThreadShell: (threadId) => Effect.succeed(liveThreadShell(threadId)),
64});
65​
66export const idleThreadProjection = (
67 shell: OrchestrationV2ThreadShell,
68): OrchestrationV2ThreadProjection => {
69 const {
70 status: _status,
71 activeRunId: _activeRunId,
72 latestRunId: _latestRunId,
73 pendingRuntimeRequest: _pendingRuntimeRequest,
74 latestVisibleMessage: _latestVisibleMessage,
75 latestUserMessageAt: _latestUserMessageAt,
76 hasActionableProposedPlan: _hasActionableProposedPlan,
77 itemCount: _itemCount,
78 visibleItemCount: _visibleItemCount,
79 lastVisitedAt,
80 ...thread
81 } = shell;
82 return {
83 thread: { ...thread, lastVisitedAt: lastVisitedAt ?? null },
84 runs: [],
85 attempts: [],
86 nodes: [],
87 subagents: [],
88 providerSessions: [],
89 providerThreads: [],
90 providerTurns: [],
91 runtimeRequests: [],
92 messages: [],
93 plans: [],
94 turnItems: [],
95 checkpointScopes: [],
96 checkpoints: [],
97 contextHandoffs: [],
98 contextTransfers: [],
99 visibleTurnItems: [],
100 updatedAt: shell.updatedAt,
101 };
102};