|
5 | 5 | * schema codecs, and stream lifecycle are delegated to Effect RPC. |
6 | 6 | */ |
7 | 7 |
|
8 | | -import { TheseusRpc } from "@theseus.run/core/Rpc"; |
9 | | -import { Effect, Exit, Layer, Scope, Stream } from "effect"; |
| 8 | +import { |
| 9 | + type DispatchEventEntrySchema, |
| 10 | + type DispatchEventSchema, |
| 11 | + type DispatchSessionSchema, |
| 12 | + type MissionSessionSchema, |
| 13 | + type ResearchPocEventSchema, |
| 14 | + type RuntimeDispatchEventSchema, |
| 15 | + TheseusRpc, |
| 16 | + type WorkTreeNodeSessionSchema, |
| 17 | +} from "@theseus.run/core/Rpc"; |
| 18 | +import { Effect, Exit, Layer, type Schema, Scope, Stream } from "effect"; |
10 | 19 | import { RpcClient, RpcSerialization } from "effect/unstable/rpc"; |
11 | 20 | import * as Socket from "effect/unstable/socket/Socket"; |
12 | 21 |
|
13 | 22 | // --------------------------------------------------------------------------- |
14 | 23 | // Types |
15 | 24 | // --------------------------------------------------------------------------- |
16 | 25 |
|
17 | | -/** Serialized dispatch event matching DispatchEventSchema */ |
18 | | -export interface CortexSignal { |
19 | | - readonly id: string; |
20 | | - readonly nodeId: string; |
21 | | - readonly slot: |
22 | | - | "harness" |
23 | | - | "workspace" |
24 | | - | "mission" |
25 | | - | "work-node" |
26 | | - | "observations" |
27 | | - | "history" |
28 | | - | "recall"; |
29 | | - readonly authority: "system" | "developer" | "user" | "assistant" | "tool"; |
30 | | - readonly priority: number; |
31 | | - readonly text: string; |
32 | | -} |
33 | | - |
34 | | -export interface DispatchEvent { |
35 | | - readonly _tag: string; |
36 | | - readonly name?: string; |
37 | | - readonly iteration?: number; |
38 | | - readonly signals?: ReadonlyArray<CortexSignal>; |
39 | | - readonly historyMessageCount?: number; |
40 | | - readonly cortexMessageCount?: number; |
41 | | - readonly promptMessageCount?: number; |
42 | | - readonly tool?: string; |
43 | | - readonly content?: string; |
44 | | - readonly structured?: unknown; |
45 | | - readonly args?: unknown; |
46 | | - readonly error?: unknown; |
47 | | - readonly isError?: boolean; |
48 | | - readonly satellite?: string; |
49 | | - readonly phase?: string; |
50 | | - readonly action?: string; |
51 | | - readonly injection?: string; |
52 | | - readonly detail?: string | null; |
53 | | - readonly reason?: string; |
54 | | - readonly result?: { |
55 | | - readonly dispatchId: string; |
56 | | - readonly name: string; |
57 | | - readonly content: string; |
58 | | - readonly usage: { readonly inputTokens: number; readonly outputTokens: number }; |
59 | | - }; |
60 | | -} |
61 | | - |
62 | | -export interface DispatchEventEntry { |
63 | | - readonly dispatchId: string; |
64 | | - readonly timestamp: number; |
65 | | - readonly event: DispatchEvent; |
66 | | -} |
67 | | - |
68 | | -export interface MissionSession { |
69 | | - readonly missionId: string; |
70 | | - readonly capsuleId: string; |
71 | | - readonly goal: string; |
72 | | - readonly criteria: ReadonlyArray<string>; |
73 | | - readonly state: "pending" | "running" | "done" | "failed"; |
74 | | -} |
75 | | - |
76 | | -export interface DispatchSession { |
77 | | - readonly workNodeId: string; |
78 | | - readonly parentWorkNodeId?: string | null; |
79 | | - readonly kind: "dispatch"; |
80 | | - readonly relation: WorkNodeRelation; |
81 | | - readonly label: string; |
82 | | - readonly control: WorkNodeControlDescriptor; |
83 | | - readonly dispatchId: string; |
84 | | - readonly missionId: string; |
85 | | - readonly capsuleId: string; |
86 | | - readonly name: string; |
87 | | - readonly modelRequest?: ModelRequest | null; |
88 | | - readonly iteration: number; |
89 | | - readonly state: WorkNodeState; |
90 | | - readonly usage: { readonly inputTokens: number; readonly outputTokens: number }; |
91 | | -} |
92 | | - |
93 | | -export interface WorkNodeSession { |
94 | | - readonly workNodeId: string; |
95 | | - readonly missionId: string; |
96 | | - readonly capsuleId: string; |
97 | | - readonly parentWorkNodeId?: string | null; |
98 | | - readonly kind: "dispatch" | "task" | "external"; |
99 | | - readonly relation: WorkNodeRelation; |
100 | | - readonly label: string; |
101 | | - readonly state: WorkNodeState; |
102 | | - readonly control: WorkNodeControlDescriptor; |
103 | | - readonly startedAt?: number | null; |
104 | | - readonly completedAt?: number | null; |
105 | | -} |
106 | | - |
107 | | -export type WorkNodeRelation = "root" | "delegated" | "continued" | "branched"; |
108 | | -export type WorkNodeState = |
109 | | - | "pending" |
110 | | - | "running" |
111 | | - | "paused" |
112 | | - | "blocked" |
113 | | - | "done" |
114 | | - | "failed" |
115 | | - | "aborted"; |
116 | | -export type WorkControlCapability = |
117 | | - | { readonly _tag: "Supported" } |
118 | | - | { readonly _tag: "Unsupported"; readonly reason: string }; |
119 | | -export interface WorkNodeControlDescriptor { |
120 | | - readonly interrupt: WorkControlCapability; |
121 | | - readonly injectGuidance: WorkControlCapability; |
122 | | - readonly pause: WorkControlCapability; |
123 | | - readonly resume: WorkControlCapability; |
124 | | - readonly stop: WorkControlCapability; |
125 | | - readonly requestStatus: WorkControlCapability; |
126 | | -} |
127 | | -export type ModelRequest = |
128 | | - | { |
129 | | - readonly provider: "openai"; |
130 | | - readonly model: string; |
131 | | - readonly maxOutputTokens?: number | null; |
132 | | - readonly reasoningEffort?: "low" | "medium" | "high" | "xhigh" | null; |
133 | | - readonly textVerbosity?: "low" | "medium" | "high" | null; |
134 | | - } |
135 | | - | { |
136 | | - readonly provider: "copilot"; |
137 | | - readonly model: string; |
138 | | - readonly maxTokens?: number | null; |
139 | | - }; |
140 | | - |
141 | | -export type RuntimeDispatchEvent = |
142 | | - | { |
143 | | - readonly _tag: "WorkNodeStarted"; |
144 | | - readonly node: WorkNodeSession; |
145 | | - } |
146 | | - | { |
147 | | - readonly _tag: "DispatchSessionStarted"; |
148 | | - readonly session: DispatchSession; |
149 | | - } |
150 | | - | { |
151 | | - readonly _tag: "DispatchEvent"; |
152 | | - readonly workNodeId: string; |
153 | | - readonly dispatchId: string; |
154 | | - readonly missionId: string; |
155 | | - readonly capsuleId: string; |
156 | | - readonly event: DispatchEvent; |
157 | | - } |
158 | | - | { |
159 | | - readonly _tag: "WorkNodeStateChanged"; |
160 | | - readonly workNodeId: string; |
161 | | - readonly missionId: string; |
162 | | - readonly state: WorkNodeState; |
163 | | - readonly reason?: string | null; |
164 | | - } |
165 | | - | { |
166 | | - readonly _tag: "RuntimeProcessFailed"; |
167 | | - readonly workNodeId: string; |
168 | | - readonly missionId: string; |
169 | | - readonly process: string; |
170 | | - readonly reason: string; |
171 | | - }; |
172 | | - |
173 | | -export type ResearchPocEvent = |
174 | | - | { |
175 | | - readonly _tag: "MissionCreated"; |
176 | | - readonly mission: MissionSession; |
177 | | - } |
178 | | - | RuntimeDispatchEvent; |
| 26 | +export type DispatchEvent = Schema.Schema.Type<typeof DispatchEventSchema>; |
| 27 | +export type DispatchEventEntry = Schema.Schema.Type<typeof DispatchEventEntrySchema>; |
| 28 | +export type MissionSession = Schema.Schema.Type<typeof MissionSessionSchema>; |
| 29 | +export type DispatchSession = Schema.Schema.Type<typeof DispatchSessionSchema>; |
| 30 | +export type WorkNodeSession = Schema.Schema.Type<typeof WorkTreeNodeSessionSchema>; |
| 31 | +export type WorkNodeRelation = WorkNodeSession["relation"]; |
| 32 | +export type WorkNodeState = WorkNodeSession["state"]; |
| 33 | +export type WorkControlCapability = WorkNodeSession["control"]["pause"]; |
| 34 | +export type WorkNodeControlDescriptor = WorkNodeSession["control"]; |
| 35 | +export type ModelRequest = NonNullable<DispatchSession["modelRequest"]>; |
| 36 | +export type RuntimeDispatchEvent = Schema.Schema.Type<typeof RuntimeDispatchEventSchema>; |
| 37 | +export type ResearchPocEvent = Schema.Schema.Type<typeof ResearchPocEventSchema>; |
179 | 38 |
|
180 | 39 | export type ConnectionState = "connecting" | "connected" | "disconnected"; |
181 | 40 | export type ConnectionListener = (state: ConnectionState) => void; |
|
0 commit comments