@janole/ai-sdk-provider-codex-asp 0.1.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/LICENSE +21 -0
- package/README.md +164 -0
- package/dist/index.cjs +1559 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +672 -0
- package/dist/index.d.ts +672 -0
- package/dist/index.js +1535 -0
- package/dist/index.js.map +1 -0
- package/package.json +76 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,672 @@
|
|
|
1
|
+
import { LanguageModelV3, LanguageModelV3CallOptions, LanguageModelV3GenerateResult, LanguageModelV3StreamResult, LanguageModelV3StreamPart, LanguageModelV3Prompt, ProviderV3 } from '@ai-sdk/provider';
|
|
2
|
+
|
|
3
|
+
/** Base error type for this provider package. */
|
|
4
|
+
declare class CodexProviderError extends Error {
|
|
5
|
+
constructor(message: string, options?: {
|
|
6
|
+
cause?: unknown;
|
|
7
|
+
});
|
|
8
|
+
}
|
|
9
|
+
/** Error used for methods intentionally left as stubs in early PRs. */
|
|
10
|
+
declare class CodexNotImplementedError extends CodexProviderError {
|
|
11
|
+
constructor(method: string);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
type AskForApproval = "untrusted" | "on-failure" | "on-request" | "never";
|
|
15
|
+
|
|
16
|
+
type ExecPolicyAmendment = Array<string>;
|
|
17
|
+
|
|
18
|
+
type CommandExecutionApprovalDecision = "accept" | "acceptForSession" | {
|
|
19
|
+
"acceptWithExecpolicyAmendment": {
|
|
20
|
+
execpolicy_amendment: ExecPolicyAmendment;
|
|
21
|
+
};
|
|
22
|
+
} | "decline" | "cancel";
|
|
23
|
+
|
|
24
|
+
type CommandAction = {
|
|
25
|
+
"type": "read";
|
|
26
|
+
command: string;
|
|
27
|
+
name: string;
|
|
28
|
+
path: string;
|
|
29
|
+
} | {
|
|
30
|
+
"type": "listFiles";
|
|
31
|
+
command: string;
|
|
32
|
+
path: string | null;
|
|
33
|
+
} | {
|
|
34
|
+
"type": "search";
|
|
35
|
+
command: string;
|
|
36
|
+
query: string | null;
|
|
37
|
+
path: string | null;
|
|
38
|
+
} | {
|
|
39
|
+
"type": "unknown";
|
|
40
|
+
command: string;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
type CommandExecutionRequestApprovalParams = {
|
|
44
|
+
threadId: string;
|
|
45
|
+
turnId: string;
|
|
46
|
+
itemId: string;
|
|
47
|
+
/**
|
|
48
|
+
* Unique identifier for this specific approval callback.
|
|
49
|
+
*
|
|
50
|
+
* For regular shell/unified_exec approvals, this is null.
|
|
51
|
+
*
|
|
52
|
+
* For zsh-exec-bridge subcommand approvals, multiple callbacks can belong to
|
|
53
|
+
* one parent `itemId`, so `approvalId` is a distinct opaque callback id
|
|
54
|
+
* (a UUID) used to disambiguate routing.
|
|
55
|
+
*/
|
|
56
|
+
approvalId?: string | null;
|
|
57
|
+
/**
|
|
58
|
+
* Optional explanatory reason (e.g. request for network access).
|
|
59
|
+
*/
|
|
60
|
+
reason?: string | null;
|
|
61
|
+
/**
|
|
62
|
+
* The command to be executed.
|
|
63
|
+
*/
|
|
64
|
+
command?: string | null;
|
|
65
|
+
/**
|
|
66
|
+
* The command's working directory.
|
|
67
|
+
*/
|
|
68
|
+
cwd?: string | null;
|
|
69
|
+
/**
|
|
70
|
+
* Best-effort parsed command actions for friendly display.
|
|
71
|
+
*/
|
|
72
|
+
commandActions?: Array<CommandAction> | null;
|
|
73
|
+
/**
|
|
74
|
+
* Optional proposed execpolicy amendment to allow similar commands without prompting.
|
|
75
|
+
*/
|
|
76
|
+
proposedExecpolicyAmendment?: ExecPolicyAmendment | null;
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
type CommandExecutionRequestApprovalResponse = {
|
|
80
|
+
decision: CommandExecutionApprovalDecision;
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
type FileChangeApprovalDecision = "accept" | "acceptForSession" | "decline" | "cancel";
|
|
84
|
+
|
|
85
|
+
type FileChangeRequestApprovalParams = {
|
|
86
|
+
threadId: string;
|
|
87
|
+
turnId: string;
|
|
88
|
+
itemId: string;
|
|
89
|
+
/**
|
|
90
|
+
* Optional explanatory reason (e.g. request for extra write access).
|
|
91
|
+
*/
|
|
92
|
+
reason?: string | null;
|
|
93
|
+
/**
|
|
94
|
+
* [UNSTABLE] When set, the agent is asking the user to allow writes under this root
|
|
95
|
+
* for the remainder of the session (unclear if this is honored today).
|
|
96
|
+
*/
|
|
97
|
+
grantRoot?: string | null;
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
type FileChangeRequestApprovalResponse = {
|
|
101
|
+
decision: FileChangeApprovalDecision;
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
type SandboxMode = "read-only" | "workspace-write" | "danger-full-access";
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Hand-maintained subset of the Codex app-server protocol types.
|
|
108
|
+
*
|
|
109
|
+
* Only includes types this provider actively uses. When adding new types,
|
|
110
|
+
* check the full generated set first:
|
|
111
|
+
*
|
|
112
|
+
* npm run codex:generate-types
|
|
113
|
+
*
|
|
114
|
+
* The generated types land in src/protocol/app-server-protocol/ (gitignored)
|
|
115
|
+
* and serve as the authoritative reference. V2 types (camelCase) are in the v2/ subdirectory.
|
|
116
|
+
*/
|
|
117
|
+
|
|
118
|
+
interface JsonRpcMessageBase {
|
|
119
|
+
id?: number | string;
|
|
120
|
+
method?: string;
|
|
121
|
+
params?: unknown;
|
|
122
|
+
result?: unknown;
|
|
123
|
+
error?: {
|
|
124
|
+
code: number;
|
|
125
|
+
message: string;
|
|
126
|
+
data?: unknown;
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
interface CodexInitializeParams {
|
|
130
|
+
clientInfo: {
|
|
131
|
+
name: string;
|
|
132
|
+
version: string;
|
|
133
|
+
title?: string;
|
|
134
|
+
};
|
|
135
|
+
capabilities?: {
|
|
136
|
+
experimentalApi?: boolean;
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
interface CodexInitializeResult {
|
|
140
|
+
serverInfo?: {
|
|
141
|
+
name: string;
|
|
142
|
+
version: string;
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
interface CodexInitializedNotification {
|
|
146
|
+
method: "initialized";
|
|
147
|
+
params?: Record<string, never>;
|
|
148
|
+
}
|
|
149
|
+
interface CodexDynamicToolDefinition {
|
|
150
|
+
name: string;
|
|
151
|
+
description?: string;
|
|
152
|
+
inputSchema: Record<string, unknown>;
|
|
153
|
+
}
|
|
154
|
+
interface CodexThreadStartParams {
|
|
155
|
+
model?: string;
|
|
156
|
+
cwd?: string;
|
|
157
|
+
approvalPolicy?: AskForApproval;
|
|
158
|
+
sandbox?: SandboxMode;
|
|
159
|
+
dynamicTools?: CodexDynamicToolDefinition[];
|
|
160
|
+
developerInstructions?: string;
|
|
161
|
+
}
|
|
162
|
+
interface CodexThreadStartResult {
|
|
163
|
+
threadId: string;
|
|
164
|
+
tools?: CodexDynamicToolDefinition[];
|
|
165
|
+
}
|
|
166
|
+
interface CodexThreadResumeParams {
|
|
167
|
+
threadId: string;
|
|
168
|
+
persistExtendedHistory: boolean;
|
|
169
|
+
developerInstructions?: string;
|
|
170
|
+
}
|
|
171
|
+
interface CodexThreadResumeResult {
|
|
172
|
+
thread?: {
|
|
173
|
+
id?: string;
|
|
174
|
+
};
|
|
175
|
+
threadId?: string;
|
|
176
|
+
}
|
|
177
|
+
interface CodexTurnInputText {
|
|
178
|
+
type: "text";
|
|
179
|
+
text: string;
|
|
180
|
+
text_elements: Array<{
|
|
181
|
+
start: number;
|
|
182
|
+
end: number;
|
|
183
|
+
type: "mention" | "skill";
|
|
184
|
+
}>;
|
|
185
|
+
}
|
|
186
|
+
interface CodexTurnInputImage {
|
|
187
|
+
type: "image";
|
|
188
|
+
url: string;
|
|
189
|
+
}
|
|
190
|
+
interface CodexTurnInputLocalImage {
|
|
191
|
+
type: "localImage";
|
|
192
|
+
path: string;
|
|
193
|
+
}
|
|
194
|
+
interface CodexTurnInputSkill {
|
|
195
|
+
type: "skill";
|
|
196
|
+
name: string;
|
|
197
|
+
path: string;
|
|
198
|
+
}
|
|
199
|
+
interface CodexTurnInputMention {
|
|
200
|
+
type: "mention";
|
|
201
|
+
name: string;
|
|
202
|
+
path: string;
|
|
203
|
+
}
|
|
204
|
+
type CodexTurnInputItem = CodexTurnInputText | CodexTurnInputImage | CodexTurnInputLocalImage | CodexTurnInputSkill | CodexTurnInputMention;
|
|
205
|
+
interface CodexTurnStartParams {
|
|
206
|
+
threadId: string;
|
|
207
|
+
input: CodexTurnInputItem[];
|
|
208
|
+
}
|
|
209
|
+
interface CodexTurnStartResult {
|
|
210
|
+
turnId: string;
|
|
211
|
+
}
|
|
212
|
+
interface CodexTurnStartedNotification {
|
|
213
|
+
method: "turn/started";
|
|
214
|
+
params: {
|
|
215
|
+
threadId: string;
|
|
216
|
+
turnId: string;
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
interface CodexTurnCompletedNotification {
|
|
220
|
+
method: "turn/completed";
|
|
221
|
+
params: {
|
|
222
|
+
threadId: string;
|
|
223
|
+
turnId: string;
|
|
224
|
+
status: "completed" | "interrupted" | "failed";
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
interface CodexItemStartedNotification {
|
|
228
|
+
method: "item/started";
|
|
229
|
+
params: {
|
|
230
|
+
threadId: string;
|
|
231
|
+
turnId: string;
|
|
232
|
+
itemId: string;
|
|
233
|
+
itemType: string;
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
interface CodexItemCompletedNotification {
|
|
237
|
+
method: "item/completed";
|
|
238
|
+
params: {
|
|
239
|
+
threadId: string;
|
|
240
|
+
turnId: string;
|
|
241
|
+
itemId: string;
|
|
242
|
+
itemType: string;
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
interface CodexAgentMessageDeltaNotification {
|
|
246
|
+
method: "item/agentMessage/delta";
|
|
247
|
+
params: {
|
|
248
|
+
threadId: string;
|
|
249
|
+
turnId: string;
|
|
250
|
+
itemId: string;
|
|
251
|
+
delta: string;
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
interface CodexToolCallStartedNotification {
|
|
255
|
+
method: "item/tool/callStarted";
|
|
256
|
+
params: {
|
|
257
|
+
callId: string;
|
|
258
|
+
tool: string;
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
interface CodexToolCallDeltaNotification {
|
|
262
|
+
method: "item/tool/callDelta";
|
|
263
|
+
params: {
|
|
264
|
+
callId: string;
|
|
265
|
+
delta: string;
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
interface CodexToolCallFinishedNotification {
|
|
269
|
+
method: "item/tool/callFinished";
|
|
270
|
+
params: {
|
|
271
|
+
callId: string;
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
interface CodexToolCallRequestParams {
|
|
275
|
+
threadId?: string;
|
|
276
|
+
turnId?: string;
|
|
277
|
+
callId?: string;
|
|
278
|
+
tool?: string;
|
|
279
|
+
toolName?: string;
|
|
280
|
+
arguments?: unknown;
|
|
281
|
+
input?: unknown;
|
|
282
|
+
}
|
|
283
|
+
type CodexToolResultContentItem = {
|
|
284
|
+
type: "inputText";
|
|
285
|
+
text: string;
|
|
286
|
+
} | {
|
|
287
|
+
type: "inputImage";
|
|
288
|
+
imageUrl: string;
|
|
289
|
+
};
|
|
290
|
+
interface CodexToolCallResult {
|
|
291
|
+
success: boolean;
|
|
292
|
+
contentItems: CodexToolResultContentItem[];
|
|
293
|
+
}
|
|
294
|
+
type CodexNotification = CodexInitializedNotification | CodexTurnStartedNotification | CodexTurnCompletedNotification | CodexItemStartedNotification | CodexItemCompletedNotification | CodexAgentMessageDeltaNotification | CodexToolCallStartedNotification | CodexToolCallDeltaNotification | CodexToolCallFinishedNotification;
|
|
295
|
+
|
|
296
|
+
type JsonRpcId = string | number;
|
|
297
|
+
interface JsonRpcRequest {
|
|
298
|
+
id: JsonRpcId;
|
|
299
|
+
method: string;
|
|
300
|
+
params?: unknown;
|
|
301
|
+
}
|
|
302
|
+
interface JsonRpcNotification {
|
|
303
|
+
method: string;
|
|
304
|
+
params?: unknown;
|
|
305
|
+
}
|
|
306
|
+
interface JsonRpcSuccessResponse {
|
|
307
|
+
id: JsonRpcId;
|
|
308
|
+
result: unknown;
|
|
309
|
+
}
|
|
310
|
+
interface JsonRpcErrorResponse {
|
|
311
|
+
id: JsonRpcId;
|
|
312
|
+
error: {
|
|
313
|
+
code: number;
|
|
314
|
+
message: string;
|
|
315
|
+
data?: unknown;
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
type JsonRpcResponse = JsonRpcSuccessResponse | JsonRpcErrorResponse;
|
|
319
|
+
type JsonRpcMessage = JsonRpcRequest | JsonRpcNotification | JsonRpcSuccessResponse | JsonRpcErrorResponse;
|
|
320
|
+
type CodexTransportEventMap = {
|
|
321
|
+
message: (message: JsonRpcMessage) => void;
|
|
322
|
+
error: (error: unknown) => void;
|
|
323
|
+
close: (code: number | null, signal: NodeJS.Signals | null) => void;
|
|
324
|
+
};
|
|
325
|
+
interface CodexTransport {
|
|
326
|
+
connect(): Promise<void>;
|
|
327
|
+
disconnect(): Promise<void>;
|
|
328
|
+
sendMessage(message: JsonRpcMessage): Promise<void>;
|
|
329
|
+
sendNotification(method: string, params?: unknown): Promise<void>;
|
|
330
|
+
on<K extends keyof CodexTransportEventMap>(event: K, listener: CodexTransportEventMap[K]): () => void;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
declare class JsonRpcError extends CodexProviderError {
|
|
334
|
+
readonly code: number;
|
|
335
|
+
readonly data?: unknown;
|
|
336
|
+
constructor(error: {
|
|
337
|
+
code: number;
|
|
338
|
+
message: string;
|
|
339
|
+
data?: unknown;
|
|
340
|
+
});
|
|
341
|
+
}
|
|
342
|
+
interface AppServerClientSettings {
|
|
343
|
+
requestTimeoutMs?: number;
|
|
344
|
+
}
|
|
345
|
+
type NotificationHandler = (params: unknown) => void | Promise<void>;
|
|
346
|
+
type AnyNotificationHandler = (method: string, params: unknown) => void | Promise<void>;
|
|
347
|
+
type RequestHandler = (params: unknown, request: JsonRpcRequest) => unknown;
|
|
348
|
+
type ToolCallRequestHandler = (params: CodexToolCallRequestParams, request: JsonRpcRequest) => CodexToolCallResult | Promise<CodexToolCallResult>;
|
|
349
|
+
declare class AppServerClient {
|
|
350
|
+
private readonly transport;
|
|
351
|
+
private readonly requestTimeoutMs;
|
|
352
|
+
private nextId;
|
|
353
|
+
private readonly pendingRequests;
|
|
354
|
+
private readonly notificationHandlers;
|
|
355
|
+
private readonly anyNotificationHandlers;
|
|
356
|
+
private readonly requestHandlers;
|
|
357
|
+
private removeMessageListener;
|
|
358
|
+
private removeErrorListener;
|
|
359
|
+
constructor(transport: CodexTransport, settings?: AppServerClientSettings);
|
|
360
|
+
connect(): Promise<void>;
|
|
361
|
+
disconnect(): Promise<void>;
|
|
362
|
+
request<TResult>(method: string, params?: unknown, timeoutMs?: number): Promise<TResult>;
|
|
363
|
+
notification(method: string, params?: unknown): Promise<void>;
|
|
364
|
+
onNotification(method: string, handler: NotificationHandler): () => void;
|
|
365
|
+
onAnyNotification(handler: AnyNotificationHandler): () => void;
|
|
366
|
+
onRequest(method: string, handler: RequestHandler): () => void;
|
|
367
|
+
onToolCallRequest(handler: ToolCallRequestHandler): () => void;
|
|
368
|
+
private handleMessage;
|
|
369
|
+
private handleResponse;
|
|
370
|
+
private handleNotification;
|
|
371
|
+
private handleInboundRequest;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
interface CodexCommandApprovalRequest {
|
|
375
|
+
threadId: string;
|
|
376
|
+
turnId: string;
|
|
377
|
+
itemId: string;
|
|
378
|
+
approvalId?: string | null;
|
|
379
|
+
reason?: string | null;
|
|
380
|
+
command?: string | null;
|
|
381
|
+
cwd?: string | null;
|
|
382
|
+
}
|
|
383
|
+
interface CodexFileChangeApprovalRequest {
|
|
384
|
+
threadId: string;
|
|
385
|
+
turnId: string;
|
|
386
|
+
itemId: string;
|
|
387
|
+
reason?: string | null;
|
|
388
|
+
grantRoot?: string | null;
|
|
389
|
+
}
|
|
390
|
+
type CommandApprovalHandler = (request: CodexCommandApprovalRequest) => CommandExecutionApprovalDecision | Promise<CommandExecutionApprovalDecision>;
|
|
391
|
+
type FileChangeApprovalHandler = (request: CodexFileChangeApprovalRequest) => FileChangeApprovalDecision | Promise<FileChangeApprovalDecision>;
|
|
392
|
+
interface ApprovalsDispatcherSettings {
|
|
393
|
+
onCommandApproval?: CommandApprovalHandler;
|
|
394
|
+
onFileChangeApproval?: FileChangeApprovalHandler;
|
|
395
|
+
}
|
|
396
|
+
declare class ApprovalsDispatcher {
|
|
397
|
+
private readonly onCommandApproval;
|
|
398
|
+
private readonly onFileChangeApproval;
|
|
399
|
+
constructor(settings?: ApprovalsDispatcherSettings);
|
|
400
|
+
attach(client: AppServerClient): () => void;
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
interface CodexWorkerSettings {
|
|
404
|
+
transportFactory: () => CodexTransport;
|
|
405
|
+
idleTimeoutMs: number;
|
|
406
|
+
}
|
|
407
|
+
interface PendingToolCall {
|
|
408
|
+
requestId: JsonRpcId;
|
|
409
|
+
callId: string;
|
|
410
|
+
toolName: string;
|
|
411
|
+
args: unknown;
|
|
412
|
+
threadId: string;
|
|
413
|
+
}
|
|
414
|
+
declare class CodexWorker {
|
|
415
|
+
state: "idle" | "busy" | "disconnected";
|
|
416
|
+
initialized: boolean;
|
|
417
|
+
initializeResult: unknown;
|
|
418
|
+
pendingToolCall: PendingToolCall | null;
|
|
419
|
+
private inner;
|
|
420
|
+
private readonly settings;
|
|
421
|
+
private idleTimer;
|
|
422
|
+
private sessionListeners;
|
|
423
|
+
constructor(settings: CodexWorkerSettings);
|
|
424
|
+
ensureConnected(): Promise<void>;
|
|
425
|
+
acquire(): void;
|
|
426
|
+
release(): void;
|
|
427
|
+
markInitialized(result: unknown): void;
|
|
428
|
+
onSession<K extends keyof CodexTransportEventMap>(event: K, listener: CodexTransportEventMap[K]): () => void;
|
|
429
|
+
clearSessionListeners(): void;
|
|
430
|
+
sendMessage(message: JsonRpcMessage): Promise<void>;
|
|
431
|
+
sendNotification(method: string, params?: unknown): Promise<void>;
|
|
432
|
+
shutdown(): Promise<void>;
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
interface CodexWorkerPoolSettings {
|
|
436
|
+
poolSize?: number;
|
|
437
|
+
transportFactory: () => CodexTransport;
|
|
438
|
+
idleTimeoutMs?: number;
|
|
439
|
+
}
|
|
440
|
+
declare class CodexWorkerPool {
|
|
441
|
+
private readonly workers;
|
|
442
|
+
private shutdownCalled;
|
|
443
|
+
constructor(settings: CodexWorkerPoolSettings);
|
|
444
|
+
acquire(): CodexWorker;
|
|
445
|
+
release(worker: CodexWorker): void;
|
|
446
|
+
shutdown(): Promise<void>;
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
interface PersistentTransportSettings {
|
|
450
|
+
pool: CodexWorkerPool;
|
|
451
|
+
}
|
|
452
|
+
declare class PersistentTransport implements CodexTransport {
|
|
453
|
+
private readonly pool;
|
|
454
|
+
private worker;
|
|
455
|
+
private pendingInitializeId;
|
|
456
|
+
private initializeIntercepted;
|
|
457
|
+
private readonly messageListeners;
|
|
458
|
+
private readonly errorListeners;
|
|
459
|
+
private readonly closeListeners;
|
|
460
|
+
constructor(settings: PersistentTransportSettings);
|
|
461
|
+
connect(): Promise<void>;
|
|
462
|
+
disconnect(): Promise<void>;
|
|
463
|
+
sendMessage(message: JsonRpcMessage): Promise<void>;
|
|
464
|
+
sendNotification(method: string, params?: unknown): Promise<void>;
|
|
465
|
+
on<K extends keyof CodexTransportEventMap>(event: K, listener: CodexTransportEventMap[K]): () => void;
|
|
466
|
+
getPendingToolCall(): PendingToolCall | null;
|
|
467
|
+
respondToToolCall(result: CodexToolCallResult): Promise<void>;
|
|
468
|
+
parkToolCall(pending: PendingToolCall): void;
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
interface StdioTransportSettings {
|
|
472
|
+
command?: string;
|
|
473
|
+
args?: string[];
|
|
474
|
+
cwd?: string;
|
|
475
|
+
env?: NodeJS.ProcessEnv;
|
|
476
|
+
}
|
|
477
|
+
declare class StdioTransport implements CodexTransport {
|
|
478
|
+
private readonly settings;
|
|
479
|
+
private process;
|
|
480
|
+
private readonly listeners;
|
|
481
|
+
private stdoutBuffer;
|
|
482
|
+
constructor(settings?: StdioTransportSettings);
|
|
483
|
+
connect(): Promise<void>;
|
|
484
|
+
disconnect(): Promise<void>;
|
|
485
|
+
sendMessage(message: JsonRpcMessage): Promise<void>;
|
|
486
|
+
sendNotification(method: string, params?: unknown): Promise<void>;
|
|
487
|
+
on<K extends keyof CodexTransportEventMap>(event: K, listener: CodexTransportEventMap[K]): () => void;
|
|
488
|
+
private handleStdoutChunk;
|
|
489
|
+
private emit;
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
interface WebSocketTransportSettings {
|
|
493
|
+
url?: string;
|
|
494
|
+
headers?: Record<string, string>;
|
|
495
|
+
}
|
|
496
|
+
declare class WebSocketTransport implements CodexTransport {
|
|
497
|
+
private readonly settings;
|
|
498
|
+
private socket;
|
|
499
|
+
private readonly listeners;
|
|
500
|
+
constructor(settings?: WebSocketTransportSettings);
|
|
501
|
+
connect(): Promise<void>;
|
|
502
|
+
disconnect(): Promise<void>;
|
|
503
|
+
sendMessage(message: JsonRpcMessage): Promise<void>;
|
|
504
|
+
sendNotification(method: string, params?: unknown): Promise<void>;
|
|
505
|
+
on<K extends keyof CodexTransportEventMap>(event: K, listener: CodexTransportEventMap[K]): () => void;
|
|
506
|
+
private handleIncomingMessage;
|
|
507
|
+
private emit;
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
interface DynamicToolExecutionContext {
|
|
511
|
+
threadId?: string;
|
|
512
|
+
turnId?: string;
|
|
513
|
+
callId?: string;
|
|
514
|
+
toolName: string;
|
|
515
|
+
}
|
|
516
|
+
type DynamicToolHandler = (args: unknown, context: DynamicToolExecutionContext) => Promise<CodexToolCallResult>;
|
|
517
|
+
/** Full tool definition: schema advertised to Codex + local execution handler. */
|
|
518
|
+
interface DynamicToolDefinition {
|
|
519
|
+
description: string;
|
|
520
|
+
inputSchema: Record<string, unknown>;
|
|
521
|
+
execute: DynamicToolHandler;
|
|
522
|
+
}
|
|
523
|
+
interface DynamicToolsDispatcherSettings {
|
|
524
|
+
/** Tools with full schema advertised to Codex. Handlers are registered automatically. */
|
|
525
|
+
tools?: Record<string, DynamicToolDefinition>;
|
|
526
|
+
/** Legacy handler-only registration (no schema). Tools are not advertised to Codex. */
|
|
527
|
+
handlers?: Record<string, DynamicToolHandler>;
|
|
528
|
+
timeoutMs?: number;
|
|
529
|
+
}
|
|
530
|
+
declare class DynamicToolsDispatcher {
|
|
531
|
+
private readonly handlers;
|
|
532
|
+
private readonly timeoutMs;
|
|
533
|
+
constructor(settings?: DynamicToolsDispatcherSettings);
|
|
534
|
+
register(name: string, handler: DynamicToolHandler): void;
|
|
535
|
+
attach(client: AppServerClient): () => void;
|
|
536
|
+
dispatch(params: CodexToolCallRequestParams): Promise<CodexToolCallResult>;
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
interface CodexLanguageModelSettings {
|
|
540
|
+
}
|
|
541
|
+
interface CodexThreadDefaults {
|
|
542
|
+
cwd?: string;
|
|
543
|
+
approvalPolicy?: AskForApproval;
|
|
544
|
+
sandbox?: SandboxMode;
|
|
545
|
+
}
|
|
546
|
+
interface CodexModelConfig {
|
|
547
|
+
provider: string;
|
|
548
|
+
providerSettings: {
|
|
549
|
+
defaultModel?: string;
|
|
550
|
+
clientInfo?: {
|
|
551
|
+
name: string;
|
|
552
|
+
version: string;
|
|
553
|
+
title?: string;
|
|
554
|
+
};
|
|
555
|
+
experimentalApi?: boolean;
|
|
556
|
+
transport?: {
|
|
557
|
+
type?: "stdio" | "websocket";
|
|
558
|
+
stdio?: StdioTransportSettings;
|
|
559
|
+
websocket?: WebSocketTransportSettings;
|
|
560
|
+
};
|
|
561
|
+
defaultThreadSettings?: CodexThreadDefaults;
|
|
562
|
+
transportFactory?: () => CodexTransport;
|
|
563
|
+
tools?: Record<string, DynamicToolDefinition>;
|
|
564
|
+
toolHandlers?: Record<string, DynamicToolHandler>;
|
|
565
|
+
toolTimeoutMs?: number;
|
|
566
|
+
approvals?: {
|
|
567
|
+
onCommandApproval?: CommandApprovalHandler;
|
|
568
|
+
onFileChangeApproval?: FileChangeApprovalHandler;
|
|
569
|
+
};
|
|
570
|
+
};
|
|
571
|
+
}
|
|
572
|
+
declare class CodexLanguageModel implements LanguageModelV3 {
|
|
573
|
+
readonly specificationVersion: "v3";
|
|
574
|
+
readonly provider: string;
|
|
575
|
+
readonly modelId: string;
|
|
576
|
+
readonly supportedUrls: Record<string, RegExp[]>;
|
|
577
|
+
private readonly settings;
|
|
578
|
+
private readonly config;
|
|
579
|
+
constructor(modelId: string, settings: CodexLanguageModelSettings, config: CodexModelConfig);
|
|
580
|
+
doGenerate(options: LanguageModelV3CallOptions): Promise<LanguageModelV3GenerateResult>;
|
|
581
|
+
private registerCrossCallToolHandler;
|
|
582
|
+
doStream(options: LanguageModelV3CallOptions): Promise<LanguageModelV3StreamResult>;
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
/** Package name from package.json. */
|
|
586
|
+
declare const PACKAGE_NAME: string;
|
|
587
|
+
/** Package version from package.json. */
|
|
588
|
+
declare const PACKAGE_VERSION: string;
|
|
589
|
+
|
|
590
|
+
interface CodexEventMapperInput {
|
|
591
|
+
method: string;
|
|
592
|
+
params?: unknown;
|
|
593
|
+
}
|
|
594
|
+
declare class CodexEventMapper {
|
|
595
|
+
private streamStarted;
|
|
596
|
+
private readonly openTextParts;
|
|
597
|
+
private threadId;
|
|
598
|
+
setThreadId(threadId: string): void;
|
|
599
|
+
map(event: CodexEventMapperInput): LanguageModelV3StreamPart[];
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
/**
|
|
603
|
+
* Extracts system messages from the prompt and concatenates them into a single
|
|
604
|
+
* string suitable for `developerInstructions` on `thread/start` or
|
|
605
|
+
* `thread/resume`. Returns `undefined` when no system content is present.
|
|
606
|
+
*/
|
|
607
|
+
declare function mapSystemPrompt(prompt: LanguageModelV3Prompt): string | undefined;
|
|
608
|
+
/**
|
|
609
|
+
* Maps the prompt to the `input` array for a `turn/start` request.
|
|
610
|
+
*
|
|
611
|
+
* System messages are **not** included here — they are routed to
|
|
612
|
+
* `developerInstructions` via {@link mapSystemPrompt} instead.
|
|
613
|
+
*
|
|
614
|
+
* @param isResume - When true the thread already holds the full history on
|
|
615
|
+
* disk, so only the last user message is extracted and sent. When false
|
|
616
|
+
* (fresh thread) all user text is folded into a single item.
|
|
617
|
+
*/
|
|
618
|
+
declare function mapPromptToTurnInput(prompt: LanguageModelV3Prompt, isResume?: boolean): CodexTurnInputItem[];
|
|
619
|
+
|
|
620
|
+
declare const CODEX_PROVIDER_ID = "codex-app-server";
|
|
621
|
+
declare function codexProviderMetadata(threadId: string | undefined): {
|
|
622
|
+
"codex-app-server": {
|
|
623
|
+
threadId: string;
|
|
624
|
+
};
|
|
625
|
+
} | undefined;
|
|
626
|
+
declare function withProviderMetadata<T extends LanguageModelV3StreamPart>(part: T, threadId: string | undefined): T;
|
|
627
|
+
|
|
628
|
+
interface CodexProviderSettings {
|
|
629
|
+
defaultModel?: string;
|
|
630
|
+
clientInfo?: {
|
|
631
|
+
name: string;
|
|
632
|
+
version: string;
|
|
633
|
+
title?: string;
|
|
634
|
+
};
|
|
635
|
+
experimentalApi?: boolean;
|
|
636
|
+
transport?: {
|
|
637
|
+
type?: "stdio" | "websocket";
|
|
638
|
+
stdio?: StdioTransportSettings;
|
|
639
|
+
websocket?: WebSocketTransportSettings;
|
|
640
|
+
};
|
|
641
|
+
defaultThreadSettings?: CodexThreadDefaults;
|
|
642
|
+
transportFactory?: () => CodexTransport;
|
|
643
|
+
/** Tools with schema (description + inputSchema) advertised to Codex + local handlers. */
|
|
644
|
+
tools?: Record<string, DynamicToolDefinition>;
|
|
645
|
+
/** Legacy: handler-only tools, not advertised to Codex. Use `tools` for full schema support. */
|
|
646
|
+
toolHandlers?: Record<string, DynamicToolHandler>;
|
|
647
|
+
toolTimeoutMs?: number;
|
|
648
|
+
approvals?: {
|
|
649
|
+
onCommandApproval?: CommandApprovalHandler;
|
|
650
|
+
onFileChangeApproval?: FileChangeApprovalHandler;
|
|
651
|
+
};
|
|
652
|
+
persistent?: {
|
|
653
|
+
poolSize?: number;
|
|
654
|
+
idleTimeoutMs?: number;
|
|
655
|
+
scope?: "provider" | "global";
|
|
656
|
+
key?: string;
|
|
657
|
+
};
|
|
658
|
+
}
|
|
659
|
+
interface CodexProvider extends ProviderV3 {
|
|
660
|
+
(modelId: string, settings?: CodexLanguageModelSettings): CodexLanguageModel;
|
|
661
|
+
chat(modelId: string, settings?: CodexLanguageModelSettings): CodexLanguageModel;
|
|
662
|
+
readonly settings: Readonly<CodexProviderSettings>;
|
|
663
|
+
shutdown(): Promise<void>;
|
|
664
|
+
}
|
|
665
|
+
declare function createCodexAppServer(settings?: CodexProviderSettings): CodexProvider;
|
|
666
|
+
declare const codexAppServer: CodexProvider;
|
|
667
|
+
/**
|
|
668
|
+
* Backward-compatible alias kept during migration from scaffold naming.
|
|
669
|
+
*/
|
|
670
|
+
declare const createCodexProvider: typeof createCodexAppServer;
|
|
671
|
+
|
|
672
|
+
export { AppServerClient, type AppServerClientSettings, ApprovalsDispatcher, type ApprovalsDispatcherSettings, type AskForApproval, CODEX_PROVIDER_ID, type CodexAgentMessageDeltaNotification, type CodexCommandApprovalRequest, type CodexDynamicToolDefinition, CodexEventMapper, type CodexEventMapperInput, type CodexFileChangeApprovalRequest, type CodexInitializeParams, type CodexInitializeResult, type CodexInitializedNotification, type CodexItemCompletedNotification, type CodexItemStartedNotification, CodexLanguageModel, type CodexLanguageModelSettings, type CodexModelConfig, CodexNotImplementedError, type CodexNotification, type CodexProvider, CodexProviderError, type CodexProviderSettings, type CodexThreadDefaults, type CodexThreadResumeParams, type CodexThreadResumeResult, type CodexThreadStartParams, type CodexThreadStartResult, type CodexToolCallDeltaNotification, type CodexToolCallFinishedNotification, type CodexToolCallRequestParams, type CodexToolCallResult, type CodexToolCallStartedNotification, type CodexToolResultContentItem, type CodexTransport, type CodexTransportEventMap, type CodexTurnCompletedNotification, type CodexTurnInputImage, type CodexTurnInputItem, type CodexTurnInputLocalImage, type CodexTurnInputMention, type CodexTurnInputSkill, type CodexTurnInputText, type CodexTurnStartParams, type CodexTurnStartResult, type CodexTurnStartedNotification, CodexWorker, CodexWorkerPool, type CodexWorkerPoolSettings, type CodexWorkerSettings, type CommandApprovalHandler, type CommandExecutionApprovalDecision, type CommandExecutionRequestApprovalParams, type CommandExecutionRequestApprovalResponse, type DynamicToolDefinition, type DynamicToolExecutionContext, type DynamicToolHandler, DynamicToolsDispatcher, type DynamicToolsDispatcherSettings, type FileChangeApprovalDecision, type FileChangeApprovalHandler, type FileChangeRequestApprovalParams, type FileChangeRequestApprovalResponse, JsonRpcError, type JsonRpcErrorResponse, type JsonRpcId, type JsonRpcMessage, type JsonRpcMessageBase, type JsonRpcNotification, type JsonRpcRequest, type JsonRpcResponse, type JsonRpcSuccessResponse, PACKAGE_NAME, PACKAGE_VERSION, type PendingToolCall, PersistentTransport, type PersistentTransportSettings, type SandboxMode, StdioTransport, type StdioTransportSettings, WebSocketTransport, type WebSocketTransportSettings, codexAppServer, codexProviderMetadata, createCodexAppServer, createCodexProvider, mapPromptToTurnInput, mapSystemPrompt, withProviderMetadata };
|