@shivaedev/agent-codex 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/README.md +47 -1
- package/dist/adapters/Request.d.ts +4 -0
- package/dist/adapters/Request.d.ts.map +1 -0
- package/dist/adapters/Request.js +2 -0
- package/dist/adapters/Request.js.map +1 -0
- package/dist/adapters/UserMessageItem.d.ts +22 -0
- package/dist/adapters/UserMessageItem.d.ts.map +1 -0
- package/dist/adapters/UserMessageItem.js +24 -0
- package/dist/adapters/UserMessageItem.js.map +1 -0
- package/dist/adapters/attributed.d.ts +6 -0
- package/dist/adapters/attributed.d.ts.map +1 -0
- package/dist/adapters/attributed.js +17 -0
- package/dist/adapters/attributed.js.map +1 -0
- package/dist/adapters/codexFailure.d.ts +3 -0
- package/dist/adapters/codexFailure.d.ts.map +1 -0
- package/dist/adapters/codexFailure.js +5 -0
- package/dist/adapters/codexFailure.js.map +1 -0
- package/dist/adapters/connect.d.ts +11 -0
- package/dist/adapters/connect.d.ts.map +1 -0
- package/dist/adapters/connect.js +100 -0
- package/dist/adapters/connect.js.map +1 -0
- package/dist/adapters/delivery.d.ts +18 -0
- package/dist/adapters/delivery.d.ts.map +1 -0
- package/dist/adapters/delivery.js +115 -0
- package/dist/adapters/delivery.js.map +1 -0
- package/dist/adapters/deliveryState.d.ts +31 -0
- package/dist/adapters/deliveryState.d.ts.map +1 -0
- package/dist/adapters/deliveryState.js +29 -0
- package/dist/adapters/deliveryState.js.map +1 -0
- package/dist/adapters/engine.d.ts +10 -0
- package/dist/adapters/engine.d.ts.map +1 -0
- package/dist/adapters/engine.js +80 -0
- package/dist/adapters/engine.js.map +1 -0
- package/dist/adapters/features.d.ts +726 -0
- package/dist/adapters/features.d.ts.map +1 -0
- package/dist/adapters/features.js +46 -0
- package/dist/adapters/features.js.map +1 -0
- package/dist/adapters/handshake.d.ts +5 -0
- package/dist/adapters/handshake.d.ts.map +1 -0
- package/dist/adapters/handshake.js +30 -0
- package/dist/adapters/handshake.js.map +1 -0
- package/dist/adapters/items.d.ts +7 -0
- package/dist/adapters/items.d.ts.map +1 -0
- package/dist/adapters/items.js +105 -0
- package/dist/adapters/items.js.map +1 -0
- package/dist/adapters/mapping.d.ts +9 -0
- package/dist/adapters/mapping.d.ts.map +1 -0
- package/dist/adapters/mapping.js +57 -0
- package/dist/adapters/mapping.js.map +1 -0
- package/dist/adapters/process.d.ts +15 -0
- package/dist/adapters/process.d.ts.map +1 -0
- package/dist/adapters/process.js +55 -0
- package/dist/adapters/process.js.map +1 -0
- package/dist/adapters/protocol.d.ts +178 -0
- package/dist/adapters/protocol.d.ts.map +1 -0
- package/dist/adapters/protocol.js +97 -0
- package/dist/adapters/protocol.js.map +1 -0
- package/dist/adapters/protocolItems.d.ts +89 -0
- package/dist/adapters/protocolItems.d.ts.map +1 -0
- package/dist/adapters/protocolItems.js +100 -0
- package/dist/adapters/protocolItems.js.map +1 -0
- package/dist/adapters/rateLimits.d.ts +7 -0
- package/dist/adapters/rateLimits.d.ts.map +1 -0
- package/dist/adapters/rateLimits.js +40 -0
- package/dist/adapters/rateLimits.js.map +1 -0
- package/dist/adapters/reads.d.ts +324 -0
- package/dist/adapters/reads.d.ts.map +1 -0
- package/dist/adapters/reads.js +83 -0
- package/dist/adapters/reads.js.map +1 -0
- package/dist/adapters/recovery.d.ts +324 -0
- package/dist/adapters/recovery.d.ts.map +1 -0
- package/dist/adapters/recovery.js +39 -0
- package/dist/adapters/recovery.js.map +1 -0
- package/dist/adapters/residualApproval.d.ts +4 -0
- package/dist/adapters/residualApproval.d.ts.map +1 -0
- package/dist/adapters/residualApproval.js +21 -0
- package/dist/adapters/residualApproval.js.map +1 -0
- package/dist/adapters/rpc.d.ts +8 -0
- package/dist/adapters/rpc.d.ts.map +1 -0
- package/dist/adapters/rpc.js +2 -0
- package/dist/adapters/rpc.js.map +1 -0
- package/dist/adapters/rpcProtocol.d.ts +11 -0
- package/dist/adapters/rpcProtocol.d.ts.map +1 -0
- package/dist/adapters/rpcProtocol.js +29 -0
- package/dist/adapters/rpcProtocol.js.map +1 -0
- package/dist/adapters/server.d.ts +30 -0
- package/dist/adapters/server.d.ts.map +1 -0
- package/dist/adapters/server.js +68 -0
- package/dist/adapters/server.js.map +1 -0
- package/dist/adapters/session.d.ts +312 -0
- package/dist/adapters/session.d.ts.map +1 -0
- package/dist/adapters/session.js +45 -0
- package/dist/adapters/session.js.map +1 -0
- package/dist/adapters/subagentItems.d.ts +16 -0
- package/dist/adapters/subagentItems.d.ts.map +1 -0
- package/dist/adapters/subagentItems.js +58 -0
- package/dist/adapters/subagentItems.js.map +1 -0
- package/dist/adapters/tellCliVersionOnce.d.ts +5 -0
- package/dist/adapters/tellCliVersionOnce.d.ts.map +1 -0
- package/dist/adapters/tellCliVersionOnce.js +13 -0
- package/dist/adapters/tellCliVersionOnce.js.map +1 -0
- package/dist/adapters/threadClaims.d.ts +8 -0
- package/dist/adapters/threadClaims.d.ts.map +1 -0
- package/dist/adapters/threadClaims.js +20 -0
- package/dist/adapters/threadClaims.js.map +1 -0
- package/dist/adapters/threadSweep.d.ts +15 -0
- package/dist/adapters/threadSweep.d.ts.map +1 -0
- package/dist/adapters/threadSweep.js +57 -0
- package/dist/adapters/threadSweep.js.map +1 -0
- package/dist/adapters/threadTree.d.ts +8 -0
- package/dist/adapters/threadTree.d.ts.map +1 -0
- package/dist/adapters/threadTree.js +125 -0
- package/dist/adapters/threadTree.js.map +1 -0
- package/dist/adapters/turnRequests.d.ts +13 -0
- package/dist/adapters/turnRequests.d.ts.map +1 -0
- package/dist/adapters/turnRequests.js +27 -0
- package/dist/adapters/turnRequests.js.map +1 -0
- package/dist/adapters/userMessageEvent.d.ts +7 -0
- package/dist/adapters/userMessageEvent.d.ts.map +1 -0
- package/dist/adapters/userMessageEvent.js +19 -0
- package/dist/adapters/userMessageEvent.js.map +1 -0
- package/dist/codex.d.ts +10 -1
- package/dist/codex.d.ts.map +1 -1
- package/dist/codex.js +15 -1
- package/dist/codex.js.map +1 -1
- package/dist/config.d.ts +24 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +4 -0
- package/dist/config.js.map +1 -0
- package/package.json +21 -4
- package/src/adapters/Request.ts +3 -0
- package/src/adapters/UserMessageItem.ts +28 -0
- package/src/adapters/attributed.ts +21 -0
- package/src/adapters/codexFailure.ts +4 -0
- package/src/adapters/connect.ts +129 -0
- package/src/adapters/delivery.ts +137 -0
- package/src/adapters/deliveryState.ts +43 -0
- package/src/adapters/engine.ts +101 -0
- package/src/adapters/features.ts +62 -0
- package/src/adapters/handshake.ts +35 -0
- package/src/adapters/items.ts +133 -0
- package/src/adapters/mapping.ts +66 -0
- package/src/adapters/process.ts +69 -0
- package/src/adapters/protocol.ts +125 -0
- package/src/adapters/protocolItems.ts +113 -0
- package/src/adapters/rateLimits.ts +55 -0
- package/src/adapters/reads.ts +93 -0
- package/src/adapters/recovery.ts +44 -0
- package/src/adapters/residualApproval.ts +23 -0
- package/src/adapters/rpc.ts +8 -0
- package/src/adapters/rpcProtocol.ts +28 -0
- package/src/adapters/server.ts +96 -0
- package/src/adapters/session.ts +71 -0
- package/src/adapters/subagentItems.ts +73 -0
- package/src/adapters/tellCliVersionOnce.ts +20 -0
- package/src/adapters/threadClaims.ts +26 -0
- package/src/adapters/threadSweep.ts +79 -0
- package/src/adapters/threadTree.ts +149 -0
- package/src/adapters/turnRequests.ts +45 -0
- package/src/adapters/userMessageEvent.ts +22 -0
- package/src/codex.ts +15 -1
- package/src/config.ts +17 -0
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import type { ReadFailure } from "@shivaedev/agent/failures.ts";
|
|
3
|
+
import type { Receipt } from "@shivaedev/agent/run.ts";
|
|
4
|
+
import { AppServer } from "#adapters/server.ts";
|
|
5
|
+
export declare function receiptOf(operationId: string, threadId: string, turnId: string): Receipt;
|
|
6
|
+
export declare const recovery: (sessions: Map<string, {
|
|
7
|
+
driver: {
|
|
8
|
+
interrupt: (turnId: string) => Effect.Effect<void, import("@shivaedev/agent/failures.ts").BackendUnavailable | import("@shivaedev/agent/failures.ts").ProtocolFailure | import("@shivaedev/agent/failures.ts").Rejected | import("@shivaedev/agent/failures.ts").UnknownAcceptance, never>;
|
|
9
|
+
queue: (input: import("@shivaedev/agent/run.ts").Input) => Effect.Effect<void, import("@shivaedev/agent/failures.ts").BackendUnavailable | import("@shivaedev/agent/failures.ts").ProtocolFailure | import("@shivaedev/agent/failures.ts").Rejected | import("@shivaedev/agent/failures.ts").UnknownAcceptance, never>;
|
|
10
|
+
recovered: (turnId: string, running: boolean) => Effect.Effect<void, never, never>;
|
|
11
|
+
start: (input: import("@shivaedev/agent/run.ts").ImageInput, operationId: string) => Effect.Effect<string, import("@shivaedev/agent/failures.ts").BackendUnavailable | import("@shivaedev/agent/failures.ts").ProtocolFailure | import("@shivaedev/agent/failures.ts").Rejected | import("@shivaedev/agent/failures.ts").UnknownAcceptance, never>;
|
|
12
|
+
steer: (expected: string, input: import("@shivaedev/agent/run.ts").Input) => Effect.Effect<undefined, import("@shivaedev/agent/failures.ts").BackendUnavailable | import("@shivaedev/agent/failures.ts").ProtocolFailure | import("@shivaedev/agent/failures.ts").Rejected | import("@shivaedev/agent/failures.ts").UnknownAcceptance, never>;
|
|
13
|
+
track: (notification: import("./rpc.ts").RpcNotification) => Effect.Effect<void, never, never>;
|
|
14
|
+
};
|
|
15
|
+
events: import("effect/PubSub").PubSub<{
|
|
16
|
+
readonly origin?: {
|
|
17
|
+
readonly node?: string | undefined;
|
|
18
|
+
readonly parentNode?: string | undefined;
|
|
19
|
+
readonly spawnedBy: string;
|
|
20
|
+
} | undefined;
|
|
21
|
+
readonly raw?: {
|
|
22
|
+
readonly kind: string;
|
|
23
|
+
readonly payload: string;
|
|
24
|
+
readonly source: string;
|
|
25
|
+
} | undefined;
|
|
26
|
+
readonly receipt: {
|
|
27
|
+
readonly backend: string;
|
|
28
|
+
readonly operationId: string;
|
|
29
|
+
readonly reference: {
|
|
30
|
+
readonly value: string;
|
|
31
|
+
readonly version: number;
|
|
32
|
+
};
|
|
33
|
+
readonly session?: {
|
|
34
|
+
readonly value: string;
|
|
35
|
+
readonly version: number;
|
|
36
|
+
} | undefined;
|
|
37
|
+
};
|
|
38
|
+
readonly type: "acknowledged";
|
|
39
|
+
} | {
|
|
40
|
+
readonly origin?: {
|
|
41
|
+
readonly node?: string | undefined;
|
|
42
|
+
readonly parentNode?: string | undefined;
|
|
43
|
+
readonly spawnedBy: string;
|
|
44
|
+
} | undefined;
|
|
45
|
+
readonly raw?: {
|
|
46
|
+
readonly kind: string;
|
|
47
|
+
readonly payload: string;
|
|
48
|
+
readonly source: string;
|
|
49
|
+
} | undefined;
|
|
50
|
+
readonly state: "accepted" | "awaiting-input" | "completed" | "failed" | "interrupted" | "running";
|
|
51
|
+
readonly type: "execution";
|
|
52
|
+
} | {
|
|
53
|
+
readonly origin?: {
|
|
54
|
+
readonly node?: string | undefined;
|
|
55
|
+
readonly parentNode?: string | undefined;
|
|
56
|
+
readonly spawnedBy: string;
|
|
57
|
+
} | undefined;
|
|
58
|
+
readonly raw?: {
|
|
59
|
+
readonly kind: string;
|
|
60
|
+
readonly payload: string;
|
|
61
|
+
readonly source: string;
|
|
62
|
+
} | undefined;
|
|
63
|
+
readonly reference: string;
|
|
64
|
+
readonly type: "session.opened";
|
|
65
|
+
} | {
|
|
66
|
+
readonly origin?: {
|
|
67
|
+
readonly node?: string | undefined;
|
|
68
|
+
readonly parentNode?: string | undefined;
|
|
69
|
+
readonly spawnedBy: string;
|
|
70
|
+
} | undefined;
|
|
71
|
+
readonly raw?: {
|
|
72
|
+
readonly kind: string;
|
|
73
|
+
readonly payload: string;
|
|
74
|
+
readonly source: string;
|
|
75
|
+
} | undefined;
|
|
76
|
+
readonly inputId?: string | undefined;
|
|
77
|
+
readonly parts: readonly ({
|
|
78
|
+
readonly text: string;
|
|
79
|
+
readonly type: "text";
|
|
80
|
+
} | {
|
|
81
|
+
readonly mediaType: string;
|
|
82
|
+
readonly path: string;
|
|
83
|
+
readonly type: "image";
|
|
84
|
+
} | {
|
|
85
|
+
readonly kind: string;
|
|
86
|
+
readonly payload: string;
|
|
87
|
+
readonly type: "native";
|
|
88
|
+
})[];
|
|
89
|
+
readonly role: "agent" | "user";
|
|
90
|
+
readonly type: "message";
|
|
91
|
+
} | {
|
|
92
|
+
readonly origin?: {
|
|
93
|
+
readonly node?: string | undefined;
|
|
94
|
+
readonly parentNode?: string | undefined;
|
|
95
|
+
readonly spawnedBy: string;
|
|
96
|
+
} | undefined;
|
|
97
|
+
readonly raw?: {
|
|
98
|
+
readonly kind: string;
|
|
99
|
+
readonly payload: string;
|
|
100
|
+
readonly source: string;
|
|
101
|
+
} | undefined;
|
|
102
|
+
readonly text: string;
|
|
103
|
+
readonly type: "thinking";
|
|
104
|
+
} | {
|
|
105
|
+
readonly origin?: {
|
|
106
|
+
readonly node?: string | undefined;
|
|
107
|
+
readonly parentNode?: string | undefined;
|
|
108
|
+
readonly spawnedBy: string;
|
|
109
|
+
} | undefined;
|
|
110
|
+
readonly raw?: {
|
|
111
|
+
readonly kind: string;
|
|
112
|
+
readonly payload: string;
|
|
113
|
+
readonly source: string;
|
|
114
|
+
} | undefined;
|
|
115
|
+
readonly input: string;
|
|
116
|
+
readonly name: string;
|
|
117
|
+
readonly providerName?: string | undefined;
|
|
118
|
+
readonly toolId: string;
|
|
119
|
+
readonly type: "tool.started";
|
|
120
|
+
} | {
|
|
121
|
+
readonly origin?: {
|
|
122
|
+
readonly node?: string | undefined;
|
|
123
|
+
readonly parentNode?: string | undefined;
|
|
124
|
+
readonly spawnedBy: string;
|
|
125
|
+
} | undefined;
|
|
126
|
+
readonly raw?: {
|
|
127
|
+
readonly kind: string;
|
|
128
|
+
readonly payload: string;
|
|
129
|
+
readonly source: string;
|
|
130
|
+
} | undefined;
|
|
131
|
+
readonly ok: boolean;
|
|
132
|
+
readonly output: string;
|
|
133
|
+
readonly toolId: string;
|
|
134
|
+
readonly type: "tool.completed";
|
|
135
|
+
} | {
|
|
136
|
+
readonly origin?: {
|
|
137
|
+
readonly node?: string | undefined;
|
|
138
|
+
readonly parentNode?: string | undefined;
|
|
139
|
+
readonly spawnedBy: string;
|
|
140
|
+
} | undefined;
|
|
141
|
+
readonly raw?: {
|
|
142
|
+
readonly kind: string;
|
|
143
|
+
readonly payload: string;
|
|
144
|
+
readonly source: string;
|
|
145
|
+
} | undefined;
|
|
146
|
+
readonly approvalId: string;
|
|
147
|
+
readonly description: string;
|
|
148
|
+
readonly toolId?: string | undefined;
|
|
149
|
+
readonly type: "approval.requested";
|
|
150
|
+
} | {
|
|
151
|
+
readonly origin?: {
|
|
152
|
+
readonly node?: string | undefined;
|
|
153
|
+
readonly parentNode?: string | undefined;
|
|
154
|
+
readonly spawnedBy: string;
|
|
155
|
+
} | undefined;
|
|
156
|
+
readonly raw?: {
|
|
157
|
+
readonly kind: string;
|
|
158
|
+
readonly payload: string;
|
|
159
|
+
readonly source: string;
|
|
160
|
+
} | undefined;
|
|
161
|
+
readonly type: "usage";
|
|
162
|
+
readonly cacheReadTokens?: number | undefined;
|
|
163
|
+
readonly cacheWriteTokens?: number | undefined;
|
|
164
|
+
readonly inputTokens?: number | undefined;
|
|
165
|
+
readonly model?: string | undefined;
|
|
166
|
+
readonly outputTokens?: number | undefined;
|
|
167
|
+
readonly scope: "cumulative" | "delta";
|
|
168
|
+
readonly unit: "run" | "session" | "turn";
|
|
169
|
+
} | {
|
|
170
|
+
readonly origin?: {
|
|
171
|
+
readonly node?: string | undefined;
|
|
172
|
+
readonly parentNode?: string | undefined;
|
|
173
|
+
readonly spawnedBy: string;
|
|
174
|
+
} | undefined;
|
|
175
|
+
readonly raw?: {
|
|
176
|
+
readonly kind: string;
|
|
177
|
+
readonly payload: string;
|
|
178
|
+
readonly source: string;
|
|
179
|
+
} | undefined;
|
|
180
|
+
readonly type: "cost";
|
|
181
|
+
readonly amount: number;
|
|
182
|
+
readonly currency: string;
|
|
183
|
+
readonly model?: string | undefined;
|
|
184
|
+
readonly scope: "cumulative" | "delta";
|
|
185
|
+
readonly source: "estimated" | "provider";
|
|
186
|
+
readonly unit: "run" | "session" | "turn";
|
|
187
|
+
} | {
|
|
188
|
+
readonly origin?: {
|
|
189
|
+
readonly node?: string | undefined;
|
|
190
|
+
readonly parentNode?: string | undefined;
|
|
191
|
+
readonly spawnedBy: string;
|
|
192
|
+
} | undefined;
|
|
193
|
+
readonly raw?: {
|
|
194
|
+
readonly kind: string;
|
|
195
|
+
readonly payload: string;
|
|
196
|
+
readonly source: string;
|
|
197
|
+
} | undefined;
|
|
198
|
+
readonly model: string;
|
|
199
|
+
readonly reason?: string | undefined;
|
|
200
|
+
readonly type: "model.changed";
|
|
201
|
+
} | {
|
|
202
|
+
readonly origin?: {
|
|
203
|
+
readonly node?: string | undefined;
|
|
204
|
+
readonly parentNode?: string | undefined;
|
|
205
|
+
readonly spawnedBy: string;
|
|
206
|
+
} | undefined;
|
|
207
|
+
readonly raw?: {
|
|
208
|
+
readonly kind: string;
|
|
209
|
+
readonly payload: string;
|
|
210
|
+
readonly source: string;
|
|
211
|
+
} | undefined;
|
|
212
|
+
readonly charter?: string | undefined;
|
|
213
|
+
readonly childRef: string;
|
|
214
|
+
readonly label?: string | undefined;
|
|
215
|
+
readonly parentRef?: string | undefined;
|
|
216
|
+
readonly spawnedBy: string;
|
|
217
|
+
readonly type: "child.opened";
|
|
218
|
+
} | {
|
|
219
|
+
readonly origin?: {
|
|
220
|
+
readonly node?: string | undefined;
|
|
221
|
+
readonly parentNode?: string | undefined;
|
|
222
|
+
readonly spawnedBy: string;
|
|
223
|
+
} | undefined;
|
|
224
|
+
readonly raw?: {
|
|
225
|
+
readonly kind: string;
|
|
226
|
+
readonly payload: string;
|
|
227
|
+
readonly source: string;
|
|
228
|
+
} | undefined;
|
|
229
|
+
readonly childRef: string;
|
|
230
|
+
readonly outcome: "completed" | "failed" | "interrupted" | "unknown";
|
|
231
|
+
readonly summary?: string | undefined;
|
|
232
|
+
readonly type: "child.ended";
|
|
233
|
+
} | {
|
|
234
|
+
readonly origin?: {
|
|
235
|
+
readonly node?: string | undefined;
|
|
236
|
+
readonly parentNode?: string | undefined;
|
|
237
|
+
readonly spawnedBy: string;
|
|
238
|
+
} | undefined;
|
|
239
|
+
readonly raw?: {
|
|
240
|
+
readonly kind: string;
|
|
241
|
+
readonly payload: string;
|
|
242
|
+
readonly source: string;
|
|
243
|
+
} | undefined;
|
|
244
|
+
readonly status: "allowed" | "rejected" | "unknown" | "warning";
|
|
245
|
+
readonly type: "rate.limit";
|
|
246
|
+
readonly windows: readonly {
|
|
247
|
+
readonly durationMinutes?: number | undefined;
|
|
248
|
+
readonly model?: string | undefined;
|
|
249
|
+
readonly resetsAt?: number | undefined;
|
|
250
|
+
readonly usedPercent: number;
|
|
251
|
+
}[];
|
|
252
|
+
} | {
|
|
253
|
+
readonly origin?: {
|
|
254
|
+
readonly node?: string | undefined;
|
|
255
|
+
readonly parentNode?: string | undefined;
|
|
256
|
+
readonly spawnedBy: string;
|
|
257
|
+
} | undefined;
|
|
258
|
+
readonly raw?: {
|
|
259
|
+
readonly kind: string;
|
|
260
|
+
readonly payload: string;
|
|
261
|
+
readonly source: string;
|
|
262
|
+
} | undefined;
|
|
263
|
+
readonly tasks: readonly {
|
|
264
|
+
readonly description: string;
|
|
265
|
+
readonly id: string;
|
|
266
|
+
readonly kind: string;
|
|
267
|
+
}[];
|
|
268
|
+
readonly type: "session.background";
|
|
269
|
+
} | {
|
|
270
|
+
readonly origin?: {
|
|
271
|
+
readonly node?: string | undefined;
|
|
272
|
+
readonly parentNode?: string | undefined;
|
|
273
|
+
readonly spawnedBy: string;
|
|
274
|
+
} | undefined;
|
|
275
|
+
readonly raw?: {
|
|
276
|
+
readonly kind: string;
|
|
277
|
+
readonly payload: string;
|
|
278
|
+
readonly source: string;
|
|
279
|
+
} | undefined;
|
|
280
|
+
readonly type: "gap";
|
|
281
|
+
readonly detail: string;
|
|
282
|
+
readonly kind: string;
|
|
283
|
+
} | {
|
|
284
|
+
readonly origin?: {
|
|
285
|
+
readonly node?: string | undefined;
|
|
286
|
+
readonly parentNode?: string | undefined;
|
|
287
|
+
readonly spawnedBy: string;
|
|
288
|
+
} | undefined;
|
|
289
|
+
readonly raw: {
|
|
290
|
+
readonly kind: string;
|
|
291
|
+
readonly payload: string;
|
|
292
|
+
readonly source: string;
|
|
293
|
+
};
|
|
294
|
+
readonly type: "raw";
|
|
295
|
+
}>;
|
|
296
|
+
threadId: string;
|
|
297
|
+
}>) => Effect.Effect<{
|
|
298
|
+
operations: Map<string, string | undefined>;
|
|
299
|
+
reconcile: (operationId: string) => Effect.Effect<{
|
|
300
|
+
readonly receipt: {
|
|
301
|
+
readonly backend: string;
|
|
302
|
+
readonly operationId: string;
|
|
303
|
+
readonly reference: {
|
|
304
|
+
readonly value: string;
|
|
305
|
+
readonly version: number;
|
|
306
|
+
};
|
|
307
|
+
readonly session?: {
|
|
308
|
+
readonly value: string;
|
|
309
|
+
readonly version: number;
|
|
310
|
+
} | undefined;
|
|
311
|
+
};
|
|
312
|
+
readonly type: "accepted";
|
|
313
|
+
} | {
|
|
314
|
+
readonly evidence: string;
|
|
315
|
+
readonly operationId: string;
|
|
316
|
+
readonly type: "not-accepted";
|
|
317
|
+
} | {
|
|
318
|
+
readonly operationId: string;
|
|
319
|
+
readonly reason: string;
|
|
320
|
+
readonly type: "uncertain";
|
|
321
|
+
}, ReadFailure, never>;
|
|
322
|
+
refusals: Map<string, string>;
|
|
323
|
+
}, never, AppServer>;
|
|
324
|
+
//# sourceMappingURL=recovery.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"recovery.d.ts","sourceRoot":"","sources":["../../src/adapters/recovery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAU,MAAM,QAAQ,CAAC;AACxC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,KAAK,EAAE,OAAO,EAAkB,MAAM,yBAAyB,CAAC;AAEvE,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAEhD,wBAAgB,SAAS,CAAC,WAAW,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAExF;AACD,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;6BAiC0B,MAAM;;;;;;;;;;;;;;;;;;;;;;;;oBACnD,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Effect, Schema } from "effect";
|
|
2
|
+
import { Item, turns } from "#adapters/reads.ts";
|
|
3
|
+
import { AppServer } from "#adapters/server.ts";
|
|
4
|
+
export function receiptOf(operationId, threadId, turnId) {
|
|
5
|
+
return { backend: "codex", operationId, reference: { value: turnId, version: 1 }, session: { value: threadId, version: 1 } };
|
|
6
|
+
}
|
|
7
|
+
export const recovery = Effect.fn("Codex.recovery")(function* (sessions) {
|
|
8
|
+
const server = yield* AppServer;
|
|
9
|
+
const operations = new Map();
|
|
10
|
+
const refusals = new Map();
|
|
11
|
+
const reconcile = Effect.fn("Codex.reconcile")(function* (operationId) {
|
|
12
|
+
const refusal = refusals.get(operationId);
|
|
13
|
+
if (refusal !== undefined) {
|
|
14
|
+
return { evidence: refusal, operationId, type: "not-accepted" };
|
|
15
|
+
}
|
|
16
|
+
const threadId = operations.get(operationId);
|
|
17
|
+
if (threadId === undefined) {
|
|
18
|
+
return { operationId, reason: "No local thread association; recover the session reference in the application", type: "uncertain" };
|
|
19
|
+
}
|
|
20
|
+
const matches = (yield* turns(threadId)).filter((turn) => turn.items.some((item) => {
|
|
21
|
+
const decoded = Schema.decodeUnknownOption(Item)(item);
|
|
22
|
+
return decoded._tag === "Some" && decoded.value.type === "userMessage" && decoded.value.clientId === operationId;
|
|
23
|
+
}));
|
|
24
|
+
const found = matches[0];
|
|
25
|
+
if (matches.length !== 1 || found === undefined) {
|
|
26
|
+
return {
|
|
27
|
+
operationId,
|
|
28
|
+
reason: matches.length > 1
|
|
29
|
+
? "Multiple turns match this operation; preserve ownership"
|
|
30
|
+
: "No matching turn is observable; absence does not authorize replay",
|
|
31
|
+
type: "uncertain",
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
yield* sessions.get(threadId)?.driver.recovered(found.id, found.status === "inProgress") ?? Effect.void;
|
|
35
|
+
return { receipt: receiptOf(operationId, threadId, found.id), type: "accepted" };
|
|
36
|
+
});
|
|
37
|
+
return { operations, reconcile: (operationId) => reconcile(operationId).pipe(Effect.provideService(AppServer, server)), refusals };
|
|
38
|
+
});
|
|
39
|
+
//# sourceMappingURL=recovery.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"recovery.js","sourceRoot":"","sources":["../../src/adapters/recovery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAGxC,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAEhD,MAAM,UAAU,SAAS,CAAC,WAAmB,EAAE,QAAgB,EAAE,MAAc;IAC9E,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO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AAE,gBAAgB,GAAG,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAiBlF"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Option } from "effect";
|
|
2
|
+
const DECLINED = "No approval consumer is configured";
|
|
3
|
+
export function residualApproval(request) {
|
|
4
|
+
switch (request.method) {
|
|
5
|
+
case "item/commandExecution/requestApproval":
|
|
6
|
+
case "item/fileChange/requestApproval":
|
|
7
|
+
return Option.some({ decision: "decline" });
|
|
8
|
+
case "item/permissions/requestApproval":
|
|
9
|
+
return Option.some({ permissions: {}, scope: "turn" });
|
|
10
|
+
case "item/tool/requestUserInput":
|
|
11
|
+
return Option.some({ answers: {} });
|
|
12
|
+
case "mcpServer/elicitation/request":
|
|
13
|
+
return Option.some({ "_meta": null, action: "decline", content: null });
|
|
14
|
+
case "execCommandApproval":
|
|
15
|
+
case "applyPatchApproval":
|
|
16
|
+
return Option.some({ decision: { denied: { rejection: DECLINED } } });
|
|
17
|
+
default:
|
|
18
|
+
return Option.none();
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=residualApproval.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"residualApproval.js","sourceRoot":"","sources":["../../src/adapters/residualApproval.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAGhC,MAAM,QAAQ,GAAG,oCAAoC,CAAC;AAEtD,MAAM,UAAU,gBAAgB,CAAC,OAAyB;IACzD,QAAQ,OAAO,CAAC,MAAM,EAAE,CAAC;QACxB,KAAK,uCAAuC,CAAC;QAC7C,KAAK,iCAAiC;YACrC,OAAO,MAAM,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE,SAAS,EAAE,CAAC,CAAC;QAC7C,KAAK,kCAAkC;YACtC,OAAO,MAAM,CAAC,IAAI,CAAC,EAAE,WAAW,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC;QACxD,KAAK,4BAA4B;YAChC,OAAO,MAAM,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,CAAC;QACrC,KAAK,+BAA+B;YACnC,OAAO,MAAM,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;QACzE,KAAK,qBAAqB,CAAC;QAC3B,KAAK,oBAAoB;YACxB,OAAO,MAAM,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE,EAAE,MAAM,EAAE,EAAE,SAAS,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC,CAAC;QACvE;YACC,OAAO,MAAM,CAAC,IAAI,EAAE,CAAC;IACvB,CAAC;AACF,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rpc.d.ts","sourceRoot":"","sources":["../../src/adapters/rpc.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,eAAe;IAC/B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;CACzB;AAED,MAAM,WAAW,gBAAiB,SAAQ,eAAe;IACxD,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAAC;CAC7B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rpc.js","sourceRoot":"","sources":["../../src/adapters/rpc.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
import { ProtocolFailure, Rejected } from "@shivaedev/agent/failures.ts";
|
|
3
|
+
export declare const Envelope: Schema.Struct<{
|
|
4
|
+
readonly error: Schema.optional<Schema.Unknown>;
|
|
5
|
+
readonly id: Schema.optional<Schema.Union<readonly [Schema.Number, Schema.String]>>;
|
|
6
|
+
readonly method: Schema.optional<Schema.String>;
|
|
7
|
+
readonly params: Schema.optional<Schema.Unknown>;
|
|
8
|
+
readonly result: Schema.optional<Schema.Unknown>;
|
|
9
|
+
}>;
|
|
10
|
+
export declare function rejected(value: unknown): ProtocolFailure | Rejected;
|
|
11
|
+
//# sourceMappingURL=rpcProtocol.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rpcProtocol.d.ts","sourceRoot":"","sources":["../../src/adapters/rpcProtocol.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AACzE,eAAO,MAAM,QAAQ;;;;;;EAMnB,CAAC;AAOH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,8BAYtC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
import { ProtocolFailure, Rejected } from "@shivaedev/agent/failures.ts";
|
|
3
|
+
export const Envelope = Schema.Struct({
|
|
4
|
+
error: Schema.optional(Schema.Unknown),
|
|
5
|
+
id: Schema.optional(Schema.Union([Schema.Number, Schema.String])),
|
|
6
|
+
method: Schema.optional(Schema.String),
|
|
7
|
+
params: Schema.optional(Schema.Unknown),
|
|
8
|
+
result: Schema.optional(Schema.Unknown),
|
|
9
|
+
});
|
|
10
|
+
const RpcError = Schema.Struct({
|
|
11
|
+
code: Schema.optional(Schema.Number),
|
|
12
|
+
data: Schema.optional(Schema.Struct({ codexErrorInfo: Schema.optional(Schema.Unknown) })),
|
|
13
|
+
message: Schema.String,
|
|
14
|
+
});
|
|
15
|
+
const Capacity = Schema.Literals(["rateLimitExceeded", "flexUnavailable", "serverOverloaded", "usageLimitExceeded"]);
|
|
16
|
+
export function rejected(value) {
|
|
17
|
+
const error = Schema.decodeUnknownOption(RpcError)(value);
|
|
18
|
+
if (error._tag === "None") {
|
|
19
|
+
return new ProtocolFailure({ backend: "codex", message: "Invalid Codex rejection" });
|
|
20
|
+
}
|
|
21
|
+
const capacity = Schema.decodeUnknownOption(Capacity)(error.value.data?.codexErrorInfo);
|
|
22
|
+
const code = error.value.code === -32_001 ? "session-queue-full" : String(error.value.code ?? "rejected");
|
|
23
|
+
return new Rejected({
|
|
24
|
+
backend: "codex",
|
|
25
|
+
message: error.value.message,
|
|
26
|
+
providerCode: capacity._tag === "Some" ? capacity.value : code,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=rpcProtocol.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rpcProtocol.js","sourceRoot":"","sources":["../../src/adapters/rpcProtocol.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AACzE,MAAM,CAAC,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC;IACrC,KAAK,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC;IACtC,EAAE,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC;IACjE,MAAM,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC;IACtC,MAAM,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC;IACvC,MAAM,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC;CACvC,CAAC,CAAC;AACH,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC;IAC9B,IAAI,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC;IACpC,IAAI,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,cAAc,EAAE,MAAM,CA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apters/process.ts";
|
|
4
|
+
import type { RpcNotification } from "#adapters/rpc.ts";
|
|
5
|
+
import type { CodexConfiguration } from "#config.ts";
|
|
6
|
+
export declare const openServer: (config: CodexConfiguration, spawn?: (() => LineProcess) | undefined) => Effect.Effect<{
|
|
7
|
+
deny: (id: number | string) => void;
|
|
8
|
+
notify: (method: string, params: unknown) => void;
|
|
9
|
+
request: (method: string, params: unknown, operationId?: string) => Effect.Effect<unknown, BackendUnavailable | import("@shivaedev/agent/failures.ts").ProtocolFailure | import("@shivaedev/agent/failures.ts").Rejected | import("@shivaedev/agent/failures.ts").UnknownAcceptance, never>;
|
|
10
|
+
respond: (id: number | string, result: unknown) => void;
|
|
11
|
+
claims: import("#adapters/threadClaims.ts").ThreadClaims;
|
|
12
|
+
exited: Effect.Effect<void, never, never>;
|
|
13
|
+
notifications: PubSub.PubSub<RpcNotification>;
|
|
14
|
+
registrations: Map<string, Scope.Scope>;
|
|
15
|
+
}, BackendUnavailable | import("@shivaedev/agent/failures.ts").ProtocolFailure | import("@shivaedev/agent/failures.ts").Rejected | import("@shivaedev/agent/failures.ts").UnknownAcceptance, Scope.Scope>;
|
|
16
|
+
export type CodexServer = Effect.Success<ReturnType<typeof openServer>>;
|
|
17
|
+
declare const AppServer_base: Context.ServiceClass<AppServer, "@shivaedev/agent-codex/AppServer", {
|
|
18
|
+
deny: (id: number | string) => void;
|
|
19
|
+
notify: (method: string, params: unknown) => void;
|
|
20
|
+
request: (method: string, params: unknown, operationId?: string) => Effect.Effect<unknown, BackendUnavailable | import("@shivaedev/agent/failures.ts").ProtocolFailure | import("@shivaedev/agent/failures.ts").Rejected | import("@shivaedev/agent/failures.ts").UnknownAcceptance, never>;
|
|
21
|
+
respond: (id: number | string, result: unknown) => void;
|
|
22
|
+
claims: import("#adapters/threadClaims.ts").ThreadClaims;
|
|
23
|
+
exited: Effect.Effect<void, never, never>;
|
|
24
|
+
notifications: PubSub.PubSub<RpcNotification>;
|
|
25
|
+
registrations: Map<string, Scope.Scope>;
|
|
26
|
+
}>;
|
|
27
|
+
export declare class AppServer extends AppServer_base {
|
|
28
|
+
}
|
|
29
|
+
export {};
|
|
30
|
+
//# sourceMappingURL=server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/adapters/server.ts"],"names":[],"mappings":"AACA,OAAO,EAAS,OAAO,EAAY,MAAM,EAAuB,MAAM,EAAiB,KAAK,KAAK,EAAE,MAAM,QAAQ,CAAC;AAClH,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAGlE,OAAO,EAAE,KAAK,WAAW,EAAoB,MAAM,sBAAsB,CAAC;AAG1E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAGxD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AACrD,eAAO,MAAM,UAAU,8CAAsF,WAAW;;;;;;;;;yMAgFtH,CAAC;AACH,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,OAAO,UAAU,CAAC,CAAC,CAAC;;;;;;;;;;;AAExE,qBAAa,SAAU,SAAQ,cAA6E;CAAG"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import process from "node:process";
|
|
2
|
+
import { Clock, Context, Deferred, Effect, Exit, Fiber, Option, PubSub, Queue, Schema } from "effect";
|
|
3
|
+
import { BackendUnavailable } from "@shivaedev/agent/failures.ts";
|
|
4
|
+
import { connect } from "#adapters/connect.ts";
|
|
5
|
+
import { handshake } from "#adapters/handshake.ts";
|
|
6
|
+
import { spawnLineProcess } from "#adapters/process.ts";
|
|
7
|
+
import { DynamicToolCallParams } from "#adapters/protocol.ts";
|
|
8
|
+
import { residualApproval } from "#adapters/residualApproval.ts";
|
|
9
|
+
import { tellCliVersionOnce } from "#adapters/tellCliVersionOnce.ts";
|
|
10
|
+
import { openThreadClaims } from "#adapters/threadClaims.ts";
|
|
11
|
+
export const openServer = Effect.fn("Codex.openServer")(function* (config, spawn) {
|
|
12
|
+
const notifications = yield* PubSub.unbounded();
|
|
13
|
+
const requests = yield* Queue.unbounded();
|
|
14
|
+
const exited = yield* Deferred.make();
|
|
15
|
+
const stderr = yield* Queue.unbounded();
|
|
16
|
+
const child = yield* Effect.acquireRelease(Effect.try({
|
|
17
|
+
catch: () => new BackendUnavailable({ backend: "codex", message: "Could not start Codex app-server" }),
|
|
18
|
+
try: () => spawn?.() ?? spawnLineProcess({ args: config.args ?? ["app-server"], command: config.command ?? "codex", cwd: config.cwd ?? process.cwd() }),
|
|
19
|
+
}), (processHandle) => Effect.sync(() => processHandle.kill()));
|
|
20
|
+
const rpc = connect(child, config.requestTimeoutMs ?? 30_000, (n) => {
|
|
21
|
+
PubSub.publishUnsafe(notifications, n);
|
|
22
|
+
}, (id, method, params) => {
|
|
23
|
+
PubSub.publishUnsafe(notifications, { method, params });
|
|
24
|
+
Queue.offerUnsafe(requests, { id, method, params });
|
|
25
|
+
}, () => {
|
|
26
|
+
Deferred.doneUnsafe(exited, Effect.void);
|
|
27
|
+
});
|
|
28
|
+
child.onStderr((text) => {
|
|
29
|
+
Queue.offerUnsafe(stderr, text);
|
|
30
|
+
});
|
|
31
|
+
yield* Effect.forkScoped(Queue.take(stderr).pipe(Effect.flatMap((text) => Effect.logWarning("Codex app-server", { stderr: text })), Effect.forever));
|
|
32
|
+
const claims = openThreadClaims();
|
|
33
|
+
const registrations = new Map();
|
|
34
|
+
const handle = Effect.fn("Codex.handle")(function* (request) {
|
|
35
|
+
if (request.method === "currentTime/read") {
|
|
36
|
+
const millis = yield* Clock.currentTimeMillis;
|
|
37
|
+
yield* Effect.sync(() => rpc.respond(request.id, { currentTimeAt: Math.floor(millis / 1000) }));
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
const declined = residualApproval(request);
|
|
41
|
+
if (declined._tag === "Some") {
|
|
42
|
+
yield* Effect.sync(() => rpc.respond(request.id, declined.value));
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
if (request.method !== "item/tool/call") {
|
|
46
|
+
yield* Effect.sync(() => rpc.deny(request.id));
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
const call = Schema.decodeUnknownOption(DynamicToolCallParams)(request.params);
|
|
50
|
+
const tool = Option.isSome(call) && registrations.has(call.value.threadId)
|
|
51
|
+
? config.tools?.find((candidate) => candidate.name === call.value.tool)
|
|
52
|
+
: undefined;
|
|
53
|
+
const callScope = Option.isSome(call) ? registrations.get(call.value.threadId) : undefined;
|
|
54
|
+
const outcome = tool !== undefined && Option.isSome(call) && callScope !== undefined
|
|
55
|
+
? yield* tool.execute(call.value.arguments, call.value.callId).pipe(Effect.forkIn(callScope), Effect.flatMap(Fiber.await), Effect.map((exit) => (Exit.isSuccess(exit) ? exit.value : { ok: false, text: "The session closed or tool execution failed" })))
|
|
56
|
+
: { ok: false, text: "No registered tool for this thread" };
|
|
57
|
+
yield* Effect.sync(() => rpc.respond(request.id, { contentItems: [{ text: outcome.text, type: "inputText" }], success: outcome.ok }));
|
|
58
|
+
});
|
|
59
|
+
yield* Effect.forkScoped(Queue.take(requests).pipe(Effect.flatMap((request) => Effect.forkScoped(handle(request))), Effect.forever));
|
|
60
|
+
const version = yield* handshake(rpc.request);
|
|
61
|
+
yield* Effect.sync(() => rpc.notify("initialized", {}));
|
|
62
|
+
const tell = yield* tellCliVersionOnce;
|
|
63
|
+
yield* tell(version);
|
|
64
|
+
return { ...rpc, claims, exited: Deferred.await(exited), notifications, registrations };
|
|
65
|
+
});
|
|
66
|
+
export class AppServer extends Context.Service()("@shivaedev/agent-codex/AppServer") {
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/adapters/server.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,cAAc,CAAC;AACnC,OAAO,EAAE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