lark-remote 0.1.5 → 0.1.6
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 +17 -0
- package/README.en.md +0 -4
- package/README.md +0 -4
- package/dist/bridge/approval-coordinator.d.ts +108 -0
- package/dist/bridge/approval-coordinator.js +258 -0
- package/dist/bridge/index.d.ts +62 -0
- package/dist/bridge/index.js +402 -21
- package/dist/bridge/queue-manager.d.ts +9 -0
- package/dist/bridge/queue-manager.js +19 -11
- package/dist/card/approval-render.d.ts +16 -0
- package/dist/card/approval-render.js +247 -0
- package/dist/card/card-shared.d.ts +14 -0
- package/dist/card/card-shared.js +28 -0
- package/dist/card/run-renderer.js +77 -6
- package/dist/card/run-state.d.ts +25 -3
- package/dist/card/run-state.js +203 -2
- package/dist/config/dir.js +1 -1
- package/dist/config/index.d.ts +42 -0
- package/dist/config/index.js +23 -1
- package/dist/connector/index.d.ts +5 -0
- package/dist/connector/index.js +12 -0
- package/dist/index.js +44 -22
- package/dist/router/config/codex.d.ts +1 -1
- package/dist/router/config/codex.js +49 -0
- package/dist/router/config/common/render.js +4 -0
- package/dist/router/config/types.d.ts +1 -1
- package/dist/router/index.d.ts +27 -2
- package/dist/router/index.js +109 -28
- package/dist/router/utils.d.ts +2 -0
- package/dist/router/utils.js +5 -2
- package/dist/runner/codex/app-server/client.d.ts +82 -0
- package/dist/runner/codex/app-server/client.js +234 -0
- package/dist/runner/codex/app-server/connection-manager.d.ts +56 -0
- package/dist/runner/codex/app-server/connection-manager.js +170 -0
- package/dist/runner/codex/app-server/protocol-types.d.ts +527 -0
- package/dist/runner/codex/app-server/protocol-types.js +67 -0
- package/dist/runner/codex/app-server/runner.d.ts +121 -0
- package/dist/runner/codex/app-server/runner.js +554 -0
- package/dist/runner/codex/app-server/translator.d.ts +109 -0
- package/dist/runner/codex/app-server/translator.js +734 -0
- package/dist/runner/codex/app-server/transport.d.ts +49 -0
- package/dist/runner/codex/app-server/transport.js +231 -0
- package/dist/runner/codex/factory.d.ts +29 -0
- package/dist/runner/codex/factory.js +39 -0
- package/dist/runner/codex/index.d.ts +2 -0
- package/dist/runner/codex/index.js +2 -0
- package/dist/runner/codex/runner.d.ts +3 -0
- package/dist/runner/codex/runner.js +5 -0
- package/dist/runner/common/usage.d.ts +2 -0
- package/dist/runner/common/usage.js +2 -0
- package/dist/runner/index.d.ts +2 -2
- package/dist/runner/index.js +1 -1
- package/dist/runner/types.d.ts +123 -2
- package/dist/session/codex/rollout-reader.js +43 -0
- package/package.json +1 -1
|
@@ -0,0 +1,527 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Codex App Server JSON-RPC Protocol Types
|
|
3
|
+
*
|
|
4
|
+
* Aligned with the real `codex app-server` protocol (v2, generated via
|
|
5
|
+
* `codex app-server generate-json-schema --experimental`). Method names and
|
|
6
|
+
* field names use the wire format exactly: camelCase paths for methods
|
|
7
|
+
* (`item/agentMessage/delta`) and snake_case only where the server requires it
|
|
8
|
+
* (e.g. permission profile fields).
|
|
9
|
+
*/
|
|
10
|
+
export interface JsonRpcRequest {
|
|
11
|
+
jsonrpc: '2.0';
|
|
12
|
+
id: number | string;
|
|
13
|
+
method: string;
|
|
14
|
+
params?: unknown;
|
|
15
|
+
}
|
|
16
|
+
export interface JsonRpcNotification {
|
|
17
|
+
jsonrpc: '2.0';
|
|
18
|
+
method: string;
|
|
19
|
+
params?: unknown;
|
|
20
|
+
}
|
|
21
|
+
export interface JsonRpcSuccessResponse {
|
|
22
|
+
jsonrpc: '2.0';
|
|
23
|
+
id: number | string;
|
|
24
|
+
result: unknown;
|
|
25
|
+
}
|
|
26
|
+
export interface JsonRpcErrorResponse {
|
|
27
|
+
jsonrpc: '2.0';
|
|
28
|
+
id: number | string | null;
|
|
29
|
+
error: {
|
|
30
|
+
code: number;
|
|
31
|
+
message: string;
|
|
32
|
+
data?: unknown;
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
export type ServerMessage = JsonRpcRequest | JsonRpcNotification | JsonRpcSuccessResponse | JsonRpcErrorResponse;
|
|
36
|
+
/** Standard JSON-RPC error codes. */
|
|
37
|
+
export declare const RpcErrorCode: {
|
|
38
|
+
readonly PARSE_ERROR: -32700;
|
|
39
|
+
readonly INVALID_REQUEST: -32600;
|
|
40
|
+
readonly METHOD_NOT_FOUND: -32601;
|
|
41
|
+
readonly INVALID_PARAMS: -32602;
|
|
42
|
+
readonly INTERNAL_ERROR: -32603;
|
|
43
|
+
/** Timeout error (custom, not standard JSON-RPC). */
|
|
44
|
+
readonly TIMEOUT_ERROR: -32000;
|
|
45
|
+
/** Connection lost / transport error (custom). */
|
|
46
|
+
readonly CONNECTION_LOST: -32001;
|
|
47
|
+
};
|
|
48
|
+
export interface ClientInfo {
|
|
49
|
+
name: string;
|
|
50
|
+
version: string;
|
|
51
|
+
}
|
|
52
|
+
export interface InitializeParams {
|
|
53
|
+
clientInfo: ClientInfo;
|
|
54
|
+
capabilities?: Record<string, unknown>;
|
|
55
|
+
}
|
|
56
|
+
export interface InitializeResult {
|
|
57
|
+
serverInfo?: {
|
|
58
|
+
name?: string;
|
|
59
|
+
version?: string;
|
|
60
|
+
};
|
|
61
|
+
protocolVersion?: string;
|
|
62
|
+
capabilities?: Record<string, unknown>;
|
|
63
|
+
}
|
|
64
|
+
export type SandboxMode = 'read-only' | 'workspace-write' | 'danger-full-access';
|
|
65
|
+
/** Response-side sandbox policy object (the request side uses `SandboxMode`
|
|
66
|
+
* strings; the response reports the active policy as a structured object). */
|
|
67
|
+
export interface SandboxPolicy {
|
|
68
|
+
type: 'dangerFullAccess' | 'readOnly' | 'externalSandbox' | 'workspaceWrite';
|
|
69
|
+
networkAccess?: boolean;
|
|
70
|
+
writableRoots?: string[];
|
|
71
|
+
[key: string]: unknown;
|
|
72
|
+
}
|
|
73
|
+
export type AskForApproval = 'untrusted' | 'on-request' | 'never' | {
|
|
74
|
+
granular: {
|
|
75
|
+
mcp_elicitations: boolean;
|
|
76
|
+
rules: boolean;
|
|
77
|
+
sandbox_approval: boolean;
|
|
78
|
+
request_permissions?: boolean;
|
|
79
|
+
skill_approval?: boolean;
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
export interface ThreadStartParams {
|
|
83
|
+
cwd?: string | null;
|
|
84
|
+
model?: string | null;
|
|
85
|
+
modelProvider?: string | null;
|
|
86
|
+
approvalPolicy?: AskForApproval;
|
|
87
|
+
sandbox?: SandboxMode;
|
|
88
|
+
permissions?: string | null;
|
|
89
|
+
config?: Record<string, unknown> | null;
|
|
90
|
+
}
|
|
91
|
+
export interface ThreadStartResponse {
|
|
92
|
+
thread: Thread;
|
|
93
|
+
cwd: string;
|
|
94
|
+
model: string;
|
|
95
|
+
modelProvider: string;
|
|
96
|
+
approvalPolicy: AskForApproval;
|
|
97
|
+
sandbox?: SandboxPolicy | null;
|
|
98
|
+
}
|
|
99
|
+
/** Real wire shape: ThreadStatus is a discriminated object, not a string. */
|
|
100
|
+
export type ThreadStatus = {
|
|
101
|
+
type: 'notLoaded';
|
|
102
|
+
} | {
|
|
103
|
+
type: 'idle';
|
|
104
|
+
} | {
|
|
105
|
+
type: 'systemError';
|
|
106
|
+
} | {
|
|
107
|
+
type: 'active';
|
|
108
|
+
activeFlags: unknown[];
|
|
109
|
+
};
|
|
110
|
+
export interface ThreadResumeParams {
|
|
111
|
+
threadId: string;
|
|
112
|
+
cwd?: string | null;
|
|
113
|
+
model?: string | null;
|
|
114
|
+
modelProvider?: string | null;
|
|
115
|
+
approvalPolicy?: AskForApproval;
|
|
116
|
+
sandbox?: SandboxMode;
|
|
117
|
+
}
|
|
118
|
+
export interface ThreadResumeResponse {
|
|
119
|
+
thread: Thread;
|
|
120
|
+
cwd: string;
|
|
121
|
+
model: string;
|
|
122
|
+
modelProvider: string;
|
|
123
|
+
}
|
|
124
|
+
export interface ThreadCompactStartParams {
|
|
125
|
+
threadId: string;
|
|
126
|
+
}
|
|
127
|
+
export interface Thread {
|
|
128
|
+
id: string;
|
|
129
|
+
sessionId: string;
|
|
130
|
+
status: ThreadStatus;
|
|
131
|
+
cwd: string;
|
|
132
|
+
preview: string;
|
|
133
|
+
turns: Turn[];
|
|
134
|
+
createdAt: number;
|
|
135
|
+
updatedAt: number;
|
|
136
|
+
modelProvider: string;
|
|
137
|
+
cliVersion: string;
|
|
138
|
+
ephemeral: boolean;
|
|
139
|
+
name?: string | null;
|
|
140
|
+
forkedFromId?: string | null;
|
|
141
|
+
parentThreadId?: string | null;
|
|
142
|
+
}
|
|
143
|
+
export interface UserInput {
|
|
144
|
+
type: 'text';
|
|
145
|
+
text: string;
|
|
146
|
+
text_elements?: unknown[];
|
|
147
|
+
}
|
|
148
|
+
export interface TurnStartParams {
|
|
149
|
+
threadId: string;
|
|
150
|
+
input: UserInput[];
|
|
151
|
+
model?: string | null;
|
|
152
|
+
effort?: string | null;
|
|
153
|
+
cwd?: string | null;
|
|
154
|
+
approvalPolicy?: AskForApproval;
|
|
155
|
+
sandboxPolicy?: SandboxMode;
|
|
156
|
+
}
|
|
157
|
+
export interface TurnStartResponse {
|
|
158
|
+
turn: Turn;
|
|
159
|
+
}
|
|
160
|
+
export interface TurnInterruptParams {
|
|
161
|
+
threadId: string;
|
|
162
|
+
turnId: string;
|
|
163
|
+
}
|
|
164
|
+
export type TurnStatus = 'inProgress' | 'completed' | 'failed' | 'interrupted';
|
|
165
|
+
export interface TurnError {
|
|
166
|
+
message: string;
|
|
167
|
+
additionalDetails?: string | null;
|
|
168
|
+
codexErrorInfo?: unknown;
|
|
169
|
+
}
|
|
170
|
+
export interface Turn {
|
|
171
|
+
id: string;
|
|
172
|
+
items: ThreadItem[];
|
|
173
|
+
status: TurnStatus;
|
|
174
|
+
error?: TurnError | null;
|
|
175
|
+
startedAt?: number | null;
|
|
176
|
+
completedAt?: number | null;
|
|
177
|
+
durationMs?: number | null;
|
|
178
|
+
}
|
|
179
|
+
export interface AgentMessageItem {
|
|
180
|
+
type: 'agentMessage';
|
|
181
|
+
id: string;
|
|
182
|
+
text: string;
|
|
183
|
+
phase?: string | null;
|
|
184
|
+
}
|
|
185
|
+
export interface ReasoningItem {
|
|
186
|
+
type: 'reasoning';
|
|
187
|
+
id: string;
|
|
188
|
+
content?: string[];
|
|
189
|
+
summary?: string[];
|
|
190
|
+
}
|
|
191
|
+
export interface CommandExecutionItem {
|
|
192
|
+
type: 'commandExecution';
|
|
193
|
+
id: string;
|
|
194
|
+
command: string;
|
|
195
|
+
cwd?: string | null;
|
|
196
|
+
aggregatedOutput?: string | null;
|
|
197
|
+
status?: string | null;
|
|
198
|
+
}
|
|
199
|
+
export interface PlanItem {
|
|
200
|
+
type: 'plan';
|
|
201
|
+
id: string;
|
|
202
|
+
text: string;
|
|
203
|
+
}
|
|
204
|
+
export interface FileChangeItem {
|
|
205
|
+
type: 'fileChange';
|
|
206
|
+
id: string;
|
|
207
|
+
changes: FileUpdateChange[];
|
|
208
|
+
status: string;
|
|
209
|
+
}
|
|
210
|
+
export interface FileUpdateChangeKind {
|
|
211
|
+
type: 'add' | 'delete' | 'update';
|
|
212
|
+
/** Present only on `update` kind — the move destination, if any. */
|
|
213
|
+
move_path?: string | null;
|
|
214
|
+
}
|
|
215
|
+
export interface FileUpdateChange {
|
|
216
|
+
path: string;
|
|
217
|
+
kind: FileUpdateChangeKind;
|
|
218
|
+
diff: string;
|
|
219
|
+
}
|
|
220
|
+
export interface ObservationItem {
|
|
221
|
+
type: 'observation';
|
|
222
|
+
id: string;
|
|
223
|
+
content: string;
|
|
224
|
+
timestamp: number;
|
|
225
|
+
}
|
|
226
|
+
export interface DiffItem {
|
|
227
|
+
type: 'diff';
|
|
228
|
+
id: string;
|
|
229
|
+
diff: string;
|
|
230
|
+
timestamp: number;
|
|
231
|
+
}
|
|
232
|
+
export type ThreadItem = AgentMessageItem | ReasoningItem | CommandExecutionItem | PlanItem | FileChangeItem | ObservationItem | DiffItem | {
|
|
233
|
+
type: 'userMessage';
|
|
234
|
+
id: string;
|
|
235
|
+
content: unknown[];
|
|
236
|
+
} | {
|
|
237
|
+
type: 'contextCompaction';
|
|
238
|
+
id: string;
|
|
239
|
+
[key: string]: unknown;
|
|
240
|
+
} | {
|
|
241
|
+
type: string;
|
|
242
|
+
id: string;
|
|
243
|
+
[key: string]: unknown;
|
|
244
|
+
};
|
|
245
|
+
export interface PlanStep {
|
|
246
|
+
id?: string;
|
|
247
|
+
title: string;
|
|
248
|
+
subtitle?: string;
|
|
249
|
+
status?: 'pending' | 'in_progress' | 'completed' | 'error';
|
|
250
|
+
}
|
|
251
|
+
export declare const NotificationMethod: {
|
|
252
|
+
readonly TURN_STARTED: "turn/started";
|
|
253
|
+
readonly TURN_COMPLETED: "turn/completed";
|
|
254
|
+
readonly TURN_DIFF_UPDATED: "turn/diff/updated";
|
|
255
|
+
readonly TURN_PLAN_UPDATED: "turn/plan/updated";
|
|
256
|
+
readonly ITEM_STARTED: "item/started";
|
|
257
|
+
readonly ITEM_COMPLETED: "item/completed";
|
|
258
|
+
readonly AGENT_MESSAGE_DELTA: "item/agentMessage/delta";
|
|
259
|
+
readonly REASONING_SUMMARY_TEXT_DELTA: "item/reasoning/summaryTextDelta";
|
|
260
|
+
readonly REASONING_SUMMARY_PART_ADDED: "item/reasoning/summaryPartAdded";
|
|
261
|
+
readonly REASONING_TEXT_DELTA: "item/reasoning/textDelta";
|
|
262
|
+
readonly COMMAND_EXECUTION_OUTPUT_DELTA: "item/commandExecution/outputDelta";
|
|
263
|
+
readonly FILE_CHANGE_OUTPUT_DELTA: "item/fileChange/outputDelta";
|
|
264
|
+
readonly PLAN_DELTA: "item/plan/delta";
|
|
265
|
+
readonly TOKEN_USAGE_UPDATED: "thread/tokenUsage/updated";
|
|
266
|
+
readonly SERVER_REQUEST_RESOLVED: "serverRequest/resolved";
|
|
267
|
+
readonly ERROR: "error";
|
|
268
|
+
readonly WARNING: "warning";
|
|
269
|
+
readonly THREAD_STARTED: "thread/started";
|
|
270
|
+
readonly THREAD_STATUS_CHANGED: "thread/status/changed";
|
|
271
|
+
readonly THREAD_COMPACTED: "thread/compacted";
|
|
272
|
+
readonly MODEL_REROUTED: "model/rerouted";
|
|
273
|
+
};
|
|
274
|
+
export interface TurnStartedNotification {
|
|
275
|
+
method: 'turn/started';
|
|
276
|
+
params: {
|
|
277
|
+
threadId: string;
|
|
278
|
+
turn: Turn;
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
export interface TurnCompletedNotification {
|
|
282
|
+
method: 'turn/completed';
|
|
283
|
+
params: {
|
|
284
|
+
threadId: string;
|
|
285
|
+
turn: Turn;
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
export interface ItemStartedNotification {
|
|
289
|
+
method: 'item/started';
|
|
290
|
+
params: {
|
|
291
|
+
threadId: string;
|
|
292
|
+
turnId: string;
|
|
293
|
+
item: ThreadItem;
|
|
294
|
+
startedAtMs: number;
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
export interface ItemCompletedNotification {
|
|
298
|
+
method: 'item/completed';
|
|
299
|
+
params: {
|
|
300
|
+
threadId: string;
|
|
301
|
+
turnId: string;
|
|
302
|
+
item: ThreadItem;
|
|
303
|
+
completedAtMs: number;
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
export interface AgentMessageDeltaNotification {
|
|
307
|
+
method: 'item/agentMessage/delta';
|
|
308
|
+
params: {
|
|
309
|
+
threadId: string;
|
|
310
|
+
turnId: string;
|
|
311
|
+
itemId: string;
|
|
312
|
+
delta: string;
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
export interface ReasoningSummaryTextDeltaNotification {
|
|
316
|
+
method: 'item/reasoning/summaryTextDelta';
|
|
317
|
+
params: {
|
|
318
|
+
threadId: string;
|
|
319
|
+
turnId: string;
|
|
320
|
+
itemId: string;
|
|
321
|
+
delta: string;
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
export interface ReasoningSummaryPartAddedNotification {
|
|
325
|
+
method: 'item/reasoning/summaryPartAdded';
|
|
326
|
+
params: {
|
|
327
|
+
threadId: string;
|
|
328
|
+
turnId: string;
|
|
329
|
+
itemId: string;
|
|
330
|
+
summaryIndex: number;
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
export interface ReasoningTextDeltaNotification {
|
|
334
|
+
method: 'item/reasoning/textDelta';
|
|
335
|
+
params: {
|
|
336
|
+
threadId: string;
|
|
337
|
+
turnId: string;
|
|
338
|
+
itemId: string;
|
|
339
|
+
delta: string;
|
|
340
|
+
contentIndex: number;
|
|
341
|
+
};
|
|
342
|
+
}
|
|
343
|
+
export interface CommandExecutionOutputDeltaNotification {
|
|
344
|
+
method: 'item/commandExecution/outputDelta';
|
|
345
|
+
params: {
|
|
346
|
+
threadId: string;
|
|
347
|
+
turnId: string;
|
|
348
|
+
itemId: string;
|
|
349
|
+
delta: string;
|
|
350
|
+
};
|
|
351
|
+
}
|
|
352
|
+
export interface PlanDeltaNotification {
|
|
353
|
+
method: 'item/plan/delta';
|
|
354
|
+
params: {
|
|
355
|
+
threadId: string;
|
|
356
|
+
turnId: string;
|
|
357
|
+
itemId: string;
|
|
358
|
+
/** EXPERIMENTAL — plain-text plan delta; do not assume concatenation
|
|
359
|
+
* matches the completed plan item content. */
|
|
360
|
+
delta: string;
|
|
361
|
+
};
|
|
362
|
+
}
|
|
363
|
+
export interface FileChangeOutputDeltaNotification {
|
|
364
|
+
method: 'item/fileChange/outputDelta';
|
|
365
|
+
params: {
|
|
366
|
+
threadId: string;
|
|
367
|
+
turnId: string;
|
|
368
|
+
itemId: string;
|
|
369
|
+
delta: string;
|
|
370
|
+
};
|
|
371
|
+
}
|
|
372
|
+
export interface TokenUsageBreakdown {
|
|
373
|
+
inputTokens: number;
|
|
374
|
+
outputTokens: number;
|
|
375
|
+
cachedInputTokens?: number;
|
|
376
|
+
totalTokens?: number;
|
|
377
|
+
cacheReadTokens?: number;
|
|
378
|
+
cacheCreationTokens?: number;
|
|
379
|
+
}
|
|
380
|
+
export interface ThreadTokenUsage {
|
|
381
|
+
last: TokenUsageBreakdown;
|
|
382
|
+
total: TokenUsageBreakdown;
|
|
383
|
+
/** 当前模型 context window 上限(v2 schema 中与 last/total 平级;
|
|
384
|
+
* app-server 模式下唯一携带该信息的通道,CLI token_count 无此字段)。 */
|
|
385
|
+
modelContextWindow?: number;
|
|
386
|
+
}
|
|
387
|
+
export interface ThreadTokenUsageUpdatedNotification {
|
|
388
|
+
method: 'thread/tokenUsage/updated';
|
|
389
|
+
params: {
|
|
390
|
+
threadId: string;
|
|
391
|
+
turnId: string;
|
|
392
|
+
tokenUsage: ThreadTokenUsage;
|
|
393
|
+
};
|
|
394
|
+
}
|
|
395
|
+
export interface ServerRequestResolvedNotification {
|
|
396
|
+
method: 'serverRequest/resolved';
|
|
397
|
+
params: {
|
|
398
|
+
threadId: string;
|
|
399
|
+
requestId: number | string;
|
|
400
|
+
};
|
|
401
|
+
}
|
|
402
|
+
export interface ErrorNotification {
|
|
403
|
+
method: 'error';
|
|
404
|
+
params: {
|
|
405
|
+
error: TurnError;
|
|
406
|
+
threadId: string;
|
|
407
|
+
turnId: string;
|
|
408
|
+
willRetry: boolean;
|
|
409
|
+
};
|
|
410
|
+
}
|
|
411
|
+
export interface WarningNotification {
|
|
412
|
+
method: 'warning';
|
|
413
|
+
params: {
|
|
414
|
+
threadId?: string;
|
|
415
|
+
turnId?: string;
|
|
416
|
+
code: string;
|
|
417
|
+
message: string;
|
|
418
|
+
timestamp?: string;
|
|
419
|
+
};
|
|
420
|
+
}
|
|
421
|
+
export interface ThreadStatusChangedNotification {
|
|
422
|
+
method: 'thread/status/changed';
|
|
423
|
+
params: {
|
|
424
|
+
threadId: string;
|
|
425
|
+
status: string;
|
|
426
|
+
timestamp?: string;
|
|
427
|
+
};
|
|
428
|
+
}
|
|
429
|
+
export interface ModelReroutedNotification {
|
|
430
|
+
method: 'model/rerouted';
|
|
431
|
+
params: {
|
|
432
|
+
threadId: string;
|
|
433
|
+
turnId?: string;
|
|
434
|
+
model: string;
|
|
435
|
+
reason?: string;
|
|
436
|
+
timestamp?: string;
|
|
437
|
+
};
|
|
438
|
+
}
|
|
439
|
+
export declare const ServerRequestMethod: {
|
|
440
|
+
readonly COMMAND_EXECUTION_APPROVAL: "item/commandExecution/requestApproval";
|
|
441
|
+
readonly FILE_CHANGE_APPROVAL: "item/fileChange/requestApproval";
|
|
442
|
+
readonly PERMISSIONS_APPROVAL: "item/permissions/requestApproval";
|
|
443
|
+
};
|
|
444
|
+
export interface NetworkApprovalContext {
|
|
445
|
+
host: string;
|
|
446
|
+
protocol: string;
|
|
447
|
+
port?: number | null;
|
|
448
|
+
}
|
|
449
|
+
export interface CommandExecutionRequestApprovalParams {
|
|
450
|
+
threadId: string;
|
|
451
|
+
turnId: string;
|
|
452
|
+
itemId: string;
|
|
453
|
+
startedAtMs: number;
|
|
454
|
+
command?: string | null;
|
|
455
|
+
cwd?: string | null;
|
|
456
|
+
reason?: string | null;
|
|
457
|
+
availableDecisions?: CommandExecutionApprovalDecision[] | null;
|
|
458
|
+
networkApprovalContext?: NetworkApprovalContext | null;
|
|
459
|
+
approvalId?: string | null;
|
|
460
|
+
}
|
|
461
|
+
export interface NetworkPolicyAmendment {
|
|
462
|
+
host: string;
|
|
463
|
+
action: 'allow' | 'deny';
|
|
464
|
+
}
|
|
465
|
+
/** Real wire shape: plain-string decisions plus structured decisions. */
|
|
466
|
+
export type CommandExecutionApprovalDecision = 'accept' | 'acceptForSession' | 'decline' | 'cancel' | {
|
|
467
|
+
acceptWithExecpolicyAmendment: {
|
|
468
|
+
execpolicy_amendment: string[];
|
|
469
|
+
};
|
|
470
|
+
} | {
|
|
471
|
+
applyNetworkPolicyAmendment: {
|
|
472
|
+
network_policy_amendment: NetworkPolicyAmendment;
|
|
473
|
+
};
|
|
474
|
+
};
|
|
475
|
+
export interface CommandExecutionRequestApprovalResponse {
|
|
476
|
+
decision: CommandExecutionApprovalDecision;
|
|
477
|
+
}
|
|
478
|
+
export interface FileChangeRequestApprovalParams {
|
|
479
|
+
threadId: string;
|
|
480
|
+
turnId: string;
|
|
481
|
+
itemId: string;
|
|
482
|
+
startedAtMs: number;
|
|
483
|
+
grantRoot?: string | null;
|
|
484
|
+
reason?: string | null;
|
|
485
|
+
}
|
|
486
|
+
export type FileChangeApprovalDecision = 'accept' | 'acceptForSession' | 'decline' | 'cancel';
|
|
487
|
+
export interface FileChangeRequestApprovalResponse {
|
|
488
|
+
decision: FileChangeApprovalDecision;
|
|
489
|
+
}
|
|
490
|
+
export type FileSystemAccessMode = 'read' | 'write' | 'deny';
|
|
491
|
+
export interface FileSystemSandboxEntry {
|
|
492
|
+
path: string;
|
|
493
|
+
access: FileSystemAccessMode;
|
|
494
|
+
}
|
|
495
|
+
/** Real wire shape: `read`/`write` are legacy string arrays; `entries` is the
|
|
496
|
+
* current structured form (`[{ path, access }]`). */
|
|
497
|
+
export interface AdditionalFileSystemPermissions {
|
|
498
|
+
entries?: FileSystemSandboxEntry[] | null;
|
|
499
|
+
read?: string[] | null;
|
|
500
|
+
write?: string[] | null;
|
|
501
|
+
}
|
|
502
|
+
export interface AdditionalNetworkPermissions {
|
|
503
|
+
enabled?: boolean | null;
|
|
504
|
+
}
|
|
505
|
+
export interface RequestPermissionProfile {
|
|
506
|
+
fileSystem?: AdditionalFileSystemPermissions | null;
|
|
507
|
+
network?: AdditionalNetworkPermissions | null;
|
|
508
|
+
}
|
|
509
|
+
export interface GrantedPermissionProfile {
|
|
510
|
+
fileSystem?: AdditionalFileSystemPermissions | null;
|
|
511
|
+
network?: AdditionalNetworkPermissions | null;
|
|
512
|
+
}
|
|
513
|
+
export interface PermissionsRequestApprovalParams {
|
|
514
|
+
threadId: string;
|
|
515
|
+
turnId: string;
|
|
516
|
+
itemId: string;
|
|
517
|
+
startedAtMs: number;
|
|
518
|
+
cwd: string;
|
|
519
|
+
permissions: RequestPermissionProfile;
|
|
520
|
+
reason?: string | null;
|
|
521
|
+
}
|
|
522
|
+
export interface PermissionsRequestApprovalResponse {
|
|
523
|
+
permissions: GrantedPermissionProfile;
|
|
524
|
+
scope?: 'turn' | 'session';
|
|
525
|
+
}
|
|
526
|
+
/** Unsupported / ignored server request methods. */
|
|
527
|
+
export declare const UNSUPPORTED_SERVER_REQUEST_METHODS: Set<string>;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Codex App Server JSON-RPC Protocol Types
|
|
3
|
+
*
|
|
4
|
+
* Aligned with the real `codex app-server` protocol (v2, generated via
|
|
5
|
+
* `codex app-server generate-json-schema --experimental`). Method names and
|
|
6
|
+
* field names use the wire format exactly: camelCase paths for methods
|
|
7
|
+
* (`item/agentMessage/delta`) and snake_case only where the server requires it
|
|
8
|
+
* (e.g. permission profile fields).
|
|
9
|
+
*/
|
|
10
|
+
/** Standard JSON-RPC error codes. */
|
|
11
|
+
export const RpcErrorCode = {
|
|
12
|
+
PARSE_ERROR: -32700,
|
|
13
|
+
INVALID_REQUEST: -32600,
|
|
14
|
+
METHOD_NOT_FOUND: -32601,
|
|
15
|
+
INVALID_PARAMS: -32602,
|
|
16
|
+
INTERNAL_ERROR: -32603,
|
|
17
|
+
/** Timeout error (custom, not standard JSON-RPC). */
|
|
18
|
+
TIMEOUT_ERROR: -32000,
|
|
19
|
+
/** Connection lost / transport error (custom). */
|
|
20
|
+
CONNECTION_LOST: -32001,
|
|
21
|
+
};
|
|
22
|
+
// =============================================================================
|
|
23
|
+
// Notifications (server → client)
|
|
24
|
+
// =============================================================================
|
|
25
|
+
export const NotificationMethod = {
|
|
26
|
+
TURN_STARTED: 'turn/started',
|
|
27
|
+
TURN_COMPLETED: 'turn/completed',
|
|
28
|
+
TURN_DIFF_UPDATED: 'turn/diff/updated',
|
|
29
|
+
TURN_PLAN_UPDATED: 'turn/plan/updated',
|
|
30
|
+
ITEM_STARTED: 'item/started',
|
|
31
|
+
ITEM_COMPLETED: 'item/completed',
|
|
32
|
+
AGENT_MESSAGE_DELTA: 'item/agentMessage/delta',
|
|
33
|
+
REASONING_SUMMARY_TEXT_DELTA: 'item/reasoning/summaryTextDelta',
|
|
34
|
+
REASONING_SUMMARY_PART_ADDED: 'item/reasoning/summaryPartAdded',
|
|
35
|
+
REASONING_TEXT_DELTA: 'item/reasoning/textDelta',
|
|
36
|
+
COMMAND_EXECUTION_OUTPUT_DELTA: 'item/commandExecution/outputDelta',
|
|
37
|
+
FILE_CHANGE_OUTPUT_DELTA: 'item/fileChange/outputDelta',
|
|
38
|
+
PLAN_DELTA: 'item/plan/delta',
|
|
39
|
+
TOKEN_USAGE_UPDATED: 'thread/tokenUsage/updated',
|
|
40
|
+
SERVER_REQUEST_RESOLVED: 'serverRequest/resolved',
|
|
41
|
+
ERROR: 'error',
|
|
42
|
+
WARNING: 'warning',
|
|
43
|
+
THREAD_STARTED: 'thread/started',
|
|
44
|
+
THREAD_STATUS_CHANGED: 'thread/status/changed',
|
|
45
|
+
THREAD_COMPACTED: 'thread/compacted',
|
|
46
|
+
MODEL_REROUTED: 'model/rerouted',
|
|
47
|
+
};
|
|
48
|
+
// =============================================================================
|
|
49
|
+
// Server Requests (approval)
|
|
50
|
+
// =============================================================================
|
|
51
|
+
export const ServerRequestMethod = {
|
|
52
|
+
COMMAND_EXECUTION_APPROVAL: 'item/commandExecution/requestApproval',
|
|
53
|
+
FILE_CHANGE_APPROVAL: 'item/fileChange/requestApproval',
|
|
54
|
+
PERMISSIONS_APPROVAL: 'item/permissions/requestApproval',
|
|
55
|
+
};
|
|
56
|
+
/** Unsupported / ignored server request methods. */
|
|
57
|
+
export const UNSUPPORTED_SERVER_REQUEST_METHODS = new Set([
|
|
58
|
+
'item/tool/requestUserInput',
|
|
59
|
+
'mcpServer/elicitation/request',
|
|
60
|
+
'item/tool/call',
|
|
61
|
+
'account/chatgptAuthTokens/refresh',
|
|
62
|
+
'attestation/generate',
|
|
63
|
+
'currentTime/read',
|
|
64
|
+
'applyPatchApproval',
|
|
65
|
+
'execCommandApproval',
|
|
66
|
+
]);
|
|
67
|
+
//# sourceMappingURL=protocol-types.js.map
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CodexAppServerRunner: workspace-lifetime runner using the Codex App Server
|
|
3
|
+
* protocol (`codex app-server`, JSON-RPC over stdio).
|
|
4
|
+
*
|
|
5
|
+
* Flow per run: acquire persistent connection → thread/start or thread/resume
|
|
6
|
+
* → turn/start → consume notifications (agent message deltas, approval server
|
|
7
|
+
* requests, …) until turn/completed → synthesize ResultEvent.
|
|
8
|
+
*/
|
|
9
|
+
import type { AgentKind, AgentSessionReader, AgentEvent, AgentRunner, AgentStatusInfo, SpawnOptions } from '../../types.js';
|
|
10
|
+
import { type AskForApproval, type SandboxMode } from './protocol-types.js';
|
|
11
|
+
export interface CodexAppServerRunnerOptions {
|
|
12
|
+
kind: AgentKind;
|
|
13
|
+
sessionReader: AgentSessionReader;
|
|
14
|
+
/** Path to the codex binary. Defaults to `codex`. */
|
|
15
|
+
binary?: string;
|
|
16
|
+
/** Environment variables. */
|
|
17
|
+
env?: Record<string, string | undefined>;
|
|
18
|
+
/** Args to spawn the app server with. Defaults to `['app-server', '--stdio']`. */
|
|
19
|
+
appServerArgs?: string[];
|
|
20
|
+
/** Request timeout in milliseconds. */
|
|
21
|
+
requestTimeoutMs?: number;
|
|
22
|
+
/** Idle TTL for connection manager. */
|
|
23
|
+
idleTtlMs?: number;
|
|
24
|
+
/** How long to wait for turn output before failing. Defaults to 10 min. */
|
|
25
|
+
turnTimeoutMs?: number;
|
|
26
|
+
model?: string;
|
|
27
|
+
modelProvider?: string;
|
|
28
|
+
reasoningEffort?: string;
|
|
29
|
+
/** Configured sandbox mode (Codex 官方 SandboxMode 标准值). */
|
|
30
|
+
sandbox?: SandboxMode;
|
|
31
|
+
/** Configured approval policy (Codex 官方 AskForApproval 标准值). */
|
|
32
|
+
approvalPolicy?: AskForApproval;
|
|
33
|
+
}
|
|
34
|
+
export declare class CodexAppServerRunner implements AgentRunner {
|
|
35
|
+
readonly kind: AgentKind;
|
|
36
|
+
readonly sessionReader: AgentSessionReader;
|
|
37
|
+
readonly lifetime: "workspace";
|
|
38
|
+
private connectionManager;
|
|
39
|
+
private currentClient;
|
|
40
|
+
private currentTranslator;
|
|
41
|
+
private currentThreadId;
|
|
42
|
+
private currentTurnId;
|
|
43
|
+
private lastEventAt;
|
|
44
|
+
private _isRunning;
|
|
45
|
+
private model?;
|
|
46
|
+
private modelProvider?;
|
|
47
|
+
private reasoningEffort?;
|
|
48
|
+
private sandboxConfig?;
|
|
49
|
+
private approvalPolicyConfig?;
|
|
50
|
+
private readonly turnTimeoutMs;
|
|
51
|
+
/** Pending approval requests: requestId (JSON-RPC id) → kind + view. */
|
|
52
|
+
private pendingApprovals;
|
|
53
|
+
/** Notification queue consumed by the active run generator. */
|
|
54
|
+
private notificationQueue;
|
|
55
|
+
private waitResolve;
|
|
56
|
+
private forceFinish;
|
|
57
|
+
/** stop() 在 turn/start 响应前到达时置位,turn/start 完成后补发 interrupt。 */
|
|
58
|
+
private stopRequested;
|
|
59
|
+
constructor(opts: CodexAppServerRunnerOptions);
|
|
60
|
+
get isRunning(): boolean;
|
|
61
|
+
/**
|
|
62
|
+
* Run a message in the current thread.
|
|
63
|
+
*
|
|
64
|
+
* 进程容错:若 app-server 子进程被外部误杀或自身异常退出(连接丢失),
|
|
65
|
+
* 自动重拉进程并重试一次 setup(thread/start 或按 sessionId thread/resume
|
|
66
|
+
* 继续处理),保证消费用户消息时进程挂了也能恢复。
|
|
67
|
+
*/
|
|
68
|
+
run(message: string, opts: SpawnOptions): AsyncGenerator<AgentEvent>;
|
|
69
|
+
/**
|
|
70
|
+
* Acquire the connection and set up the turn: thread/start(新会话)或
|
|
71
|
+
* thread/resume(按 sessionId 恢复既有线程)→ turn/start。
|
|
72
|
+
*/
|
|
73
|
+
private setupTurn;
|
|
74
|
+
/**
|
|
75
|
+
* Run a compact operation on the current thread.
|
|
76
|
+
*/
|
|
77
|
+
runCompact(_message: string, opts: SpawnOptions): AsyncGenerator<AgentEvent>;
|
|
78
|
+
/**
|
|
79
|
+
* Stop the current turn by interrupting it.
|
|
80
|
+
*/
|
|
81
|
+
stop(_opts?: {
|
|
82
|
+
immediate?: boolean;
|
|
83
|
+
}): Promise<void>;
|
|
84
|
+
/**
|
|
85
|
+
* Respond to an approval server request. `response` is the bridge
|
|
86
|
+
* ApprovalAction (`{ action: 'accept' | 'accept_for_session' | 'decline' | 'cancel' }`).
|
|
87
|
+
*/
|
|
88
|
+
respondApproval(requestId: number | string, response: unknown): Promise<void>;
|
|
89
|
+
/**
|
|
90
|
+
* Dispose the runner: release the connection.
|
|
91
|
+
*/
|
|
92
|
+
dispose(): Promise<void>;
|
|
93
|
+
getUsageAuthority(): 'live';
|
|
94
|
+
killOrphan(): void;
|
|
95
|
+
registerExitHandlers(): void;
|
|
96
|
+
unregisterExitHandlers(): void;
|
|
97
|
+
getStatusInfo(): AgentStatusInfo;
|
|
98
|
+
private buildThreadParams;
|
|
99
|
+
private buildTurnParams;
|
|
100
|
+
/**
|
|
101
|
+
* Consume the notification queue until a result event arrives or the turn
|
|
102
|
+
* times out / is interrupted.
|
|
103
|
+
*/
|
|
104
|
+
private consumeTurn;
|
|
105
|
+
/**
|
|
106
|
+
* Compute the current idle deadline. 0 disables the idle timeout; otherwise
|
|
107
|
+
* the deadline is based on the last received event, not the turn start time.
|
|
108
|
+
*/
|
|
109
|
+
private nextTurnIdleDeadline;
|
|
110
|
+
private interruptCurrentTurn;
|
|
111
|
+
private waitForEvents;
|
|
112
|
+
private handleNotification;
|
|
113
|
+
private handleServerRequest;
|
|
114
|
+
private pushEvents;
|
|
115
|
+
private wakeWaiters;
|
|
116
|
+
private failTurn;
|
|
117
|
+
private resetRunState;
|
|
118
|
+
private buildGrantedPermissions;
|
|
119
|
+
/** 拒绝权限审批:空 fileSystem + 关闭网络(真实 GrantedPermissionProfile)。 */
|
|
120
|
+
private denyAllPermissions;
|
|
121
|
+
}
|