@jrkropp/codex-js 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.
Files changed (40) hide show
  1. package/CHANGELOG.md +5 -0
  2. package/LICENSE +201 -0
  3. package/NOTICE +29 -0
  4. package/README.md +659 -0
  5. package/dist/DynamicToolCallResponse-D2OVpa4p.d.ts +8 -0
  6. package/dist/ToolRequestUserInputResponse-Bxjlpgho.d.ts +17 -0
  7. package/dist/chat-runtime-CMli5dzJ.d.ts +748 -0
  8. package/dist/chunk-FFASNDXU.js +9383 -0
  9. package/dist/chunk-FFASNDXU.js.map +1 -0
  10. package/dist/chunk-FN3SWHRH.js +934 -0
  11. package/dist/chunk-FN3SWHRH.js.map +1 -0
  12. package/dist/chunk-TZBLUZ2X.js +18640 -0
  13. package/dist/chunk-TZBLUZ2X.js.map +1 -0
  14. package/dist/chunk-ZX5OIIJX.js +3 -0
  15. package/dist/chunk-ZX5OIIJX.js.map +1 -0
  16. package/dist/client/index.d.ts +111 -0
  17. package/dist/client/index.js +4 -0
  18. package/dist/client/index.js.map +1 -0
  19. package/dist/index.d.ts +15 -0
  20. package/dist/index.js +6 -0
  21. package/dist/index.js.map +1 -0
  22. package/dist/react/index.d.ts +74 -0
  23. package/dist/react/index.js +5 -0
  24. package/dist/react/index.js.map +1 -0
  25. package/dist/remote-DMPfepa9.d.ts +19 -0
  26. package/dist/server/index.d.ts +1999 -0
  27. package/dist/server/index.js +3 -0
  28. package/dist/server/index.js.map +1 -0
  29. package/dist/session-BO6EZNK7.d.ts +1829 -0
  30. package/dist/shadcn/index.d.ts +68 -0
  31. package/dist/shadcn/index.js +334 -0
  32. package/dist/shadcn/index.js.map +1 -0
  33. package/dist/sidebar-DT2XoitN.d.ts +87 -0
  34. package/dist/store-H2cQxdpe.d.ts +20 -0
  35. package/dist/styles.css +1 -0
  36. package/dist/testing/index.d.ts +91 -0
  37. package/dist/testing/index.js +3 -0
  38. package/dist/testing/index.js.map +1 -0
  39. package/dist/thread_event_store-BIS0qzhi.d.ts +3843 -0
  40. package/package.json +89 -0
@@ -0,0 +1,1999 @@
1
+ import { J as JsonValue, M as McpServerRefreshConfig, B as McpRuntimeEnvironment, F as McpServerStatusListOptions, G as McpServerStatus, H as McpResourceListParams, I as McpResourceListResponse, K as McpResourceTemplateListResponse, O as McpResourceReadParams, P as McpResourceReadResponse, Q as McpServerToolCallParams, V as McpServerToolCallResponse, W as McpToolInfo, X as McpRequestId, Y as McpServerElicitationResponse, Z as McpResourceInfo, _ as McpResourceTemplateInfo, T as ThreadId, C as CreateThreadParams, R as ResumeThreadParams, $ as RolloutItem, b as StoredThreadHistory, d as StoredThread, a0 as ThreadMemoryMode, a1 as ThreadMetadataPatch, l as RequestId, a as ServerRequest, S as ServerNotification, a2 as ServiceTier, a3 as ReasoningEffortConfig, a4 as ReasoningSummaryConfig, a5 as Personality, a6 as AskForApproval, a7 as ApprovalsReviewer, a8 as SandboxPolicy, a9 as PermissionProfile, aa as ActivePermissionProfile, ab as WindowsSandboxLevel, ac as BaseInstructions, w as CollaborationMode, ad as SessionSource, ae as TurnEnvironmentSelection, af as DynamicToolSpec$1, ag as TruncationPolicy, ah as ThreadGoal, ai as ThreadGoalStatus, aj as HookEventName, ak as HookSource, al as HookRunStatus, am as HookOutputEntry, an as HookRunSummary, ao as HookCompletedEvent, r as UserInput, ap as TokenUsage, aq as RequestUserInputResponse, ar as DynamicToolResponse, as as RequestPermissionsResponse, at as RequestPermissionProfile, au as EventMsg, av as Op, aw as Submission, ax as NormalizedRequestUserInputArgs, ay as RequestPermissionsArgs, az as McpServerElicitationRequest, aA as CompactedItem, aB as ResponseItem, aC as RateLimitSnapshot, aD as TokenUsageInfo, aE as TurnContextItem, aF as ModeKind, aG as W3cTraceContext } from '../thread_event_store-BIS0qzhi.js';
2
+ export { aH as ThreadEventPersistenceMode, m as ThreadEventSnapshot, n as ThreadEventStore, aI as ThreadHistoryBuilder, aJ as asThreadId, aK as deniedRequestPermissionsResponse } from '../thread_event_store-BIS0qzhi.js';
3
+ import { c as ClientRequest, h as CollaborationModeListParams, i as CollaborationModeListResponse, I as InitializeParams, d as InitializeResponse, M as McpServerRefreshResponse, j as McpResourceReadParams$1, k as McpResourceReadResponse$1, l as McpServerOauthLoginParams, m as McpServerOauthLoginResponse, L as ListMcpServerStatusParams, n as ListMcpServerStatusResponse, o as McpServerToolCallParams$1, p as McpServerToolCallResponse$1, q as ThreadArchiveParams, t as ThreadArchiveResponse, u as ThreadCompactStartParams, v as ThreadCompactStartResponse, w as ThreadListParams, x as ThreadListResponse, y as ThreadMetadataUpdateParams, z as ThreadMetadataUpdateResponse, B as ThreadSetNameParams, D as ThreadSetNameResponse, E as ThreadReadParams, F as ThreadReadResponse, G as ThreadResumeParams, H as ThreadResumeResponse, f as ThreadStartParams, K as ThreadStartResponse, N as ThreadUnarchiveParams, O as ThreadUnarchiveResponse, P as TurnInterruptParams, Q as TurnInterruptResponse, g as TurnStartParams, S as TurnStartResponse, U as TurnSteerParams, V as TurnSteerResponse, A as AppServerEvent$1, J as JSONRPCErrorError$1, R as Result$1 } from '../session-BO6EZNK7.js';
4
+ export { b as AppServerSession, C as CodexAppServer } from '../session-BO6EZNK7.js';
5
+ export { D as DynamicToolCallResponse } from '../DynamicToolCallResponse-D2OVpa4p.js';
6
+ import { T as ThreadStore } from '../store-H2cQxdpe.js';
7
+ export { InMemoryThreadStore, InMemoryThreadStoreCalls, LocalThreadStore, LocalThreadStoreConfig } from '../testing/index.js';
8
+
9
+ type ClientNotification = {
10
+ "method": "initialized";
11
+ };
12
+
13
+ type WebSearchContextSize = "low" | "medium" | "high";
14
+
15
+ type WebSearchLocation = {
16
+ country: string | null;
17
+ region: string | null;
18
+ city: string | null;
19
+ timezone: string | null;
20
+ };
21
+
22
+ type WebSearchMode$1 = "disabled" | "cached" | "live";
23
+
24
+ type WebSearchToolConfig = {
25
+ context_size: WebSearchContextSize | null;
26
+ allowed_domains: Array<string> | null;
27
+ location: WebSearchLocation | null;
28
+ };
29
+
30
+ type DynamicToolSpec = {
31
+ namespace?: string;
32
+ name: string;
33
+ description: string;
34
+ inputSchema: JsonValue;
35
+ deferLoading?: boolean;
36
+ };
37
+
38
+ type FreeformTool = {
39
+ name: string;
40
+ description: string;
41
+ format: {
42
+ type: string;
43
+ syntax: string;
44
+ definition: string;
45
+ };
46
+ };
47
+ type ResponsesApiTool = {
48
+ name: string;
49
+ description: string;
50
+ strict: boolean;
51
+ defer_loading?: boolean;
52
+ parameters: JsonSchema;
53
+ };
54
+ type ResponsesApiFunctionTool = ResponsesApiTool & {
55
+ type: "function";
56
+ };
57
+ type LoadableToolSpec = ResponsesApiFunctionTool | (ResponsesApiNamespace & {
58
+ type: "namespace";
59
+ });
60
+ type ResponsesApiNamespace = {
61
+ name: string;
62
+ description: string;
63
+ tools: ResponsesApiNamespaceTool[];
64
+ };
65
+ type ResponsesApiNamespaceTool = ResponsesApiFunctionTool;
66
+
67
+ type JsonSchema = unknown;
68
+ type ToolSpec = LoadableToolSpec | {
69
+ type: "tool_search";
70
+ execution: string;
71
+ description: string;
72
+ parameters: JsonSchema;
73
+ } | {
74
+ type: "local_shell";
75
+ } | {
76
+ type: "image_generation";
77
+ output_format: string;
78
+ } | {
79
+ type: "web_search";
80
+ external_web_access?: boolean;
81
+ filters?: unknown;
82
+ user_location?: unknown;
83
+ search_context_size?: unknown;
84
+ search_content_types?: string[];
85
+ } | (FreeformTool & {
86
+ type: "custom";
87
+ });
88
+
89
+ interface McpConnectionManager {
90
+ refresh_mcp_servers_now(config: McpServerRefreshConfig, environment: McpRuntimeEnvironment): Promise<void>;
91
+ list_server_statuses(options?: McpServerStatusListOptions): Promise<McpServerStatus[]>;
92
+ list_resources(params: McpResourceListParams): Promise<McpResourceListResponse>;
93
+ list_resource_templates(params: McpResourceListParams): Promise<McpResourceTemplateListResponse>;
94
+ read_resource(params: McpResourceReadParams): Promise<McpResourceReadResponse>;
95
+ call_tool(params: McpServerToolCallParams): Promise<McpServerToolCallResponse>;
96
+ resolve_tool_info(serverName: string, toolName: string): Promise<McpToolInfo | null>;
97
+ list_tools(): Promise<McpToolInfo[]>;
98
+ resolve_elicitation(serverName: string, id: McpRequestId, response: McpServerElicitationResponse): Promise<void>;
99
+ shutdown(): Promise<void>;
100
+ }
101
+ declare class EmptyMcpConnectionManager implements McpConnectionManager {
102
+ static readonly instance: EmptyMcpConnectionManager;
103
+ refresh_mcp_servers_now(): Promise<void>;
104
+ list_server_statuses(): Promise<McpServerStatus[]>;
105
+ list_resources(params: McpResourceListParams): Promise<McpResourceListResponse>;
106
+ list_resource_templates(params: McpResourceListParams): Promise<McpResourceTemplateListResponse>;
107
+ read_resource(params: McpResourceReadParams): Promise<McpResourceReadResponse>;
108
+ call_tool(params: McpServerToolCallParams): Promise<McpServerToolCallResponse>;
109
+ resolve_tool_info(): Promise<McpToolInfo | null>;
110
+ list_tools(): Promise<McpToolInfo[]>;
111
+ resolve_elicitation(serverName: string): Promise<void>;
112
+ shutdown(): Promise<void>;
113
+ }
114
+ type StaticMcpConnectionManagerOptions = {
115
+ resources?: Record<string, ReadonlyArray<McpResourceInfo>>;
116
+ resource_templates?: Record<string, ReadonlyArray<McpResourceTemplateInfo>>;
117
+ read_resources?: Record<string, McpResourceReadResponse>;
118
+ };
119
+ declare class StaticMcpConnectionManager implements McpConnectionManager {
120
+ private readonly tools;
121
+ private readonly resources;
122
+ private readonly resource_templates;
123
+ private readonly read_resources;
124
+ constructor(tools?: readonly McpToolInfo[], options?: StaticMcpConnectionManagerOptions);
125
+ refresh_mcp_servers_now(): Promise<void>;
126
+ list_server_statuses(options?: McpServerStatusListOptions): Promise<McpServerStatus[]>;
127
+ list_resources(params: McpResourceListParams): Promise<McpResourceListResponse>;
128
+ list_resource_templates(params: McpResourceListParams): Promise<McpResourceTemplateListResponse>;
129
+ read_resource(params: McpResourceReadParams): Promise<McpResourceReadResponse>;
130
+ call_tool(params: McpServerToolCallParams): Promise<McpServerToolCallResponse>;
131
+ resolve_tool_info(serverName: string, toolName: string): Promise<McpToolInfo | null>;
132
+ list_tools(): Promise<McpToolInfo[]>;
133
+ resolve_elicitation(): Promise<void>;
134
+ shutdown(): Promise<void>;
135
+ }
136
+
137
+ declare class LiveThread {
138
+ readonly threadId: ThreadId;
139
+ private readonly threadStore;
140
+ private constructor();
141
+ static create(threadStore: ThreadStore, params: CreateThreadParams): Promise<LiveThread>;
142
+ static resume(threadStore: ThreadStore, params: ResumeThreadParams): Promise<LiveThread>;
143
+ appendItems(items: RolloutItem[]): Promise<void>;
144
+ persist(): Promise<void>;
145
+ flush(): Promise<void>;
146
+ shutdown(): Promise<void>;
147
+ discard(): Promise<void>;
148
+ loadHistory(includeArchived: boolean): Promise<StoredThreadHistory>;
149
+ readThread(includeArchived: boolean, includeHistory: boolean): Promise<StoredThread>;
150
+ updateMemoryMode(mode: ThreadMemoryMode, includeArchived: boolean): Promise<void>;
151
+ updateMetadata(patch: ThreadMetadataPatch, includeArchived: boolean): Promise<StoredThread>;
152
+ localRolloutPath(): Promise<string | null>;
153
+ }
154
+
155
+ declare const AuthMode: {
156
+ readonly ApiKey: "apiKey";
157
+ readonly Chatgpt: "chatgpt";
158
+ };
159
+ type AuthMode = (typeof AuthMode)[keyof typeof AuthMode];
160
+ type PlanType = "free" | "plus" | "pro" | "team" | "enterprise" | "edu" | "unknown";
161
+ type TokenData = {
162
+ access_token: string;
163
+ refresh_token: string;
164
+ id_token: string;
165
+ account_id?: string | null;
166
+ expires_at?: number | null;
167
+ };
168
+ type AuthDotJson = {
169
+ auth_mode?: AuthMode | null;
170
+ openai_api_key?: string | null;
171
+ tokens?: TokenData | null;
172
+ last_refresh?: string | null;
173
+ };
174
+ type CodexAuth = {
175
+ type: typeof AuthMode.ApiKey;
176
+ api_key: string;
177
+ } | {
178
+ type: typeof AuthMode.Chatgpt;
179
+ auth: AuthDotJson;
180
+ account_id?: string | null;
181
+ email?: string | null;
182
+ plan_type?: PlanType | null;
183
+ };
184
+ type ProviderAccount = {
185
+ type: typeof AuthMode.ApiKey;
186
+ } | {
187
+ type: typeof AuthMode.Chatgpt;
188
+ email: string;
189
+ plan_type: PlanType;
190
+ };
191
+ type ProviderAccountState = {
192
+ account: ProviderAccount | null;
193
+ requires_openai_auth: boolean;
194
+ };
195
+
196
+ type ClientRequestSerializationScope = {
197
+ key: string;
198
+ type: "global";
199
+ } | {
200
+ threadId: string;
201
+ type: "thread";
202
+ } | {
203
+ path: string;
204
+ type: "threadPath";
205
+ } | {
206
+ processId: string;
207
+ type: "commandExecProcess";
208
+ } | {
209
+ processHandle: string;
210
+ type: "process";
211
+ } | {
212
+ sessionId: string;
213
+ type: "fuzzyFileSearchSession";
214
+ } | {
215
+ watchId: string;
216
+ type: "fsWatch";
217
+ } | {
218
+ serverName: string;
219
+ type: "mcpOauth";
220
+ };
221
+ declare function clientRequestId(request: ClientRequest): RequestId;
222
+ declare function clientRequestMethod(request: ClientRequest): string;
223
+ declare function clientRequestExperimentalReason(request: ClientRequest | {
224
+ method: string;
225
+ params?: unknown;
226
+ }): string | null;
227
+ declare function clientRequestSerializationScope(request: ClientRequest | {
228
+ method: string;
229
+ params?: unknown;
230
+ }): ClientRequestSerializationScope | null;
231
+
232
+ type JSONRPCErrorError = {
233
+ code: number;
234
+ data?: unknown;
235
+ message: string;
236
+ };
237
+ type Result = unknown;
238
+ type ConnectionId = number;
239
+ type OutgoingResponse = {
240
+ id: RequestId;
241
+ result: Result;
242
+ };
243
+ type OutgoingError = {
244
+ error: JSONRPCErrorError;
245
+ id: RequestId;
246
+ };
247
+ type OutgoingMessage = ServerRequest | ServerNotification | OutgoingResponse | OutgoingError;
248
+ type QueuedOutgoingMessage = {
249
+ message: OutgoingMessage;
250
+ writeComplete?: () => void;
251
+ };
252
+
253
+ type ConnectionOrigin = "stdio" | "inProcess" | "webSocket" | "remoteControl";
254
+ type JSONRPCRequest = {
255
+ id: RequestId;
256
+ method: string;
257
+ params?: unknown;
258
+ };
259
+ type JSONRPCNotification = {
260
+ method: string;
261
+ params?: unknown;
262
+ };
263
+ type JSONRPCResponse = {
264
+ id: RequestId;
265
+ result: Result;
266
+ };
267
+ type JSONRPCError = {
268
+ error: JSONRPCErrorError;
269
+ id: RequestId | null;
270
+ };
271
+ type JSONRPCMessage = JSONRPCRequest | JSONRPCNotification | JSONRPCResponse | JSONRPCError;
272
+ type ParsedServerTransportMessage = {
273
+ request: ClientRequest;
274
+ type: "client_request";
275
+ } | {
276
+ notification: ClientNotification;
277
+ type: "client_notification";
278
+ } | {
279
+ response: JSONRPCResponse;
280
+ type: "response";
281
+ } | {
282
+ error: JSONRPCError;
283
+ type: "error";
284
+ };
285
+ type ParsedClientTransportMessage = {
286
+ request: ServerRequest;
287
+ type: "server_request";
288
+ } | {
289
+ notification: ServerNotification;
290
+ type: "server_notification";
291
+ } | {
292
+ response: JSONRPCResponse;
293
+ type: "response";
294
+ } | {
295
+ error: JSONRPCError;
296
+ type: "error";
297
+ };
298
+ type ParsedTransportPayload<T> = {
299
+ message: T;
300
+ type: "ok";
301
+ } | {
302
+ error: JSONRPCErrorError;
303
+ id: RequestId | null;
304
+ type: "invalid";
305
+ };
306
+ declare function parseServerTransportPayload(payload: string | ArrayBuffer | ArrayBufferView | unknown): ParsedTransportPayload<ParsedServerTransportMessage>;
307
+ declare function parseClientTransportPayload(payload: string | ArrayBuffer | ArrayBufferView | unknown): ParsedTransportPayload<ParsedClientTransportMessage>;
308
+ declare function serializeOutgoingMessage(message: OutgoingMessage): string;
309
+ declare function serializeJsonRpcResponse(id: RequestId, result: Result): string;
310
+ declare function serializeJsonRpcError(id: RequestId | null, error: JSONRPCErrorError): string;
311
+ declare function queuedOutgoingMessage(message: OutgoingMessage, writeComplete?: () => void): QueuedOutgoingMessage;
312
+ declare function jsonRpcParseError(message: string): JSONRPCErrorError;
313
+ declare function jsonRpcInvalidRequestError(message: string): JSONRPCErrorError;
314
+ declare function jsonRpcInternalError(message: string): JSONRPCErrorError;
315
+
316
+ type AppServerEvent = {
317
+ notification: ServerNotification;
318
+ type: "server_notification";
319
+ } | {
320
+ request: ServerRequest;
321
+ type: "server_request";
322
+ } | {
323
+ skipped: number;
324
+ type: "lagged";
325
+ } | {
326
+ message: string;
327
+ type: "disconnected";
328
+ };
329
+ type ConnectionRequestId = {
330
+ connectionId: ConnectionId;
331
+ requestId: RequestId;
332
+ };
333
+ type RequestContext = {
334
+ connectionId: ConnectionId;
335
+ requestId: RequestId;
336
+ };
337
+ type OutgoingServerRequestHandle = {
338
+ request: ServerRequest;
339
+ result: Promise<Result>;
340
+ };
341
+ type OutgoingMessageSenderOptions = {
342
+ send: (message: OutgoingMessage, context: {
343
+ connectionIds?: ConnectionId[];
344
+ context?: unknown;
345
+ threadId?: ThreadId;
346
+ }) => Promise<void> | void;
347
+ };
348
+ declare class OutgoingMessageSender {
349
+ private nextServerRequestId;
350
+ private readonly requestIdToCallback;
351
+ private readonly requestContexts;
352
+ private readonly sendMessage;
353
+ constructor(options: OutgoingMessageSenderOptions);
354
+ threadScoped(threadId: ThreadId): ThreadScopedOutgoingMessageSender;
355
+ threadScopedForConnections(threadId: ThreadId, connectionIds: ConnectionId[]): ThreadScopedOutgoingMessageSender;
356
+ sendServerNotification(notification: ServerNotification, context?: unknown, threadId?: ThreadId, connectionIds?: ConnectionId[]): Promise<void>;
357
+ sendRequest(request: ServerRequest, threadId?: ThreadId | null, context?: unknown, connectionIds?: ConnectionId[]): Promise<Result>;
358
+ sendRequestWithHandle(request: ServerRequest, threadId?: ThreadId | null, context?: unknown, connectionIds?: ConnectionId[]): OutgoingServerRequestHandle;
359
+ registerRequestContext(requestContext: RequestContext): void;
360
+ requestContext(requestId: ConnectionRequestId): RequestContext | null;
361
+ sendResponse(requestId: ConnectionRequestId, result: Result, context?: unknown): Promise<void>;
362
+ sendError(requestId: ConnectionRequestId, error: JSONRPCErrorError, context?: unknown): Promise<void>;
363
+ notifyClientResponse(id: RequestId, result: Result): Promise<void>;
364
+ notifyClientError(id: RequestId, error: JSONRPCErrorError): Promise<void>;
365
+ cancelRequest(id: RequestId): boolean;
366
+ connectionClosed(connectionId: ConnectionId): void;
367
+ cancelRequestsForThread(threadId: ThreadId, error?: JSONRPCErrorError): void;
368
+ pendingRequestsForThread(threadId: ThreadId): ServerRequest[];
369
+ private nextRequestId;
370
+ private takeRequestCallback;
371
+ }
372
+ declare class ThreadScopedOutgoingMessageSender {
373
+ private readonly outgoing;
374
+ private readonly threadId;
375
+ private readonly connectionIds;
376
+ constructor(outgoing: OutgoingMessageSender, threadId: ThreadId, connectionIds?: ConnectionId[]);
377
+ sendRequest(request: ServerRequest, context?: unknown): Promise<Result>;
378
+ sendServerNotification(notification: ServerNotification, context?: unknown): Promise<void>;
379
+ sendResponse(requestId: ConnectionRequestId, result: Result, context?: unknown): Promise<void>;
380
+ sendError(requestId: ConnectionRequestId, error: JSONRPCErrorError, context?: unknown): Promise<void>;
381
+ abortPendingServerRequests(error?: JSONRPCErrorError): void;
382
+ pendingRequests(): ServerRequest[];
383
+ }
384
+
385
+ declare class CodexAppServerRequestError extends Error {
386
+ readonly error: JSONRPCErrorError;
387
+ readonly status: number;
388
+ constructor(error: JSONRPCErrorError, status?: number);
389
+ }
390
+
391
+ declare class ConnectionRpcGateClosedError extends Error {
392
+ constructor();
393
+ }
394
+ declare class ConnectionRpcGate {
395
+ private accepting;
396
+ private inFlight;
397
+ private readonly shutdownWaiters;
398
+ isAccepting(): boolean;
399
+ run<T>(work: () => Promise<T> | T): Promise<T>;
400
+ shutdown(): Promise<void>;
401
+ }
402
+
403
+ type RequestSerializationQueueKey = string;
404
+ declare class RequestSerializationQueues {
405
+ private readonly tails;
406
+ enqueue<T>(key: RequestSerializationQueueKey, work: () => Promise<T> | T): Promise<T>;
407
+ }
408
+
409
+ type CodexAppServerRequestContext = {
410
+ connectionId: ConnectionId;
411
+ outgoing: OutgoingMessageSender;
412
+ requestId: ConnectionRequestId;
413
+ session: CodexAppServerConnectionSessionState;
414
+ };
415
+ type CodexAppServerMethodHandlers<Context = unknown> = {
416
+ collaborationModeList?(params: CollaborationModeListParams, context?: Context): Promise<CollaborationModeListResponse>;
417
+ initialize?(params: InitializeParams, context?: Context, session?: CodexAppServerConnectionSessionState): Promise<InitializeResponse>;
418
+ configMcpServerReload?(params: undefined, context?: Context): Promise<McpServerRefreshResponse>;
419
+ mcpResourceRead?(params: McpResourceReadParams$1, context?: Context, request?: CodexAppServerRequestContext): Promise<McpResourceReadResponse$1 | CodexAppServerDeferredResponse>;
420
+ mcpServerOauthLogin?(params: McpServerOauthLoginParams, context?: Context): Promise<McpServerOauthLoginResponse>;
421
+ mcpServerStatusList?(params: ListMcpServerStatusParams, context?: Context, request?: CodexAppServerRequestContext): Promise<ListMcpServerStatusResponse | CodexAppServerDeferredResponse>;
422
+ mcpServerToolCall?(params: McpServerToolCallParams$1, context?: Context, request?: CodexAppServerRequestContext): Promise<McpServerToolCallResponse$1 | CodexAppServerDeferredResponse>;
423
+ threadArchive?(params: ThreadArchiveParams, context?: Context): Promise<ThreadArchiveResponse>;
424
+ threadCompactStart(params: ThreadCompactStartParams, context?: Context): Promise<ThreadCompactStartResponse>;
425
+ threadList?(params: ThreadListParams, context?: Context): Promise<ThreadListResponse>;
426
+ threadMetadataUpdate?(params: ThreadMetadataUpdateParams, context?: Context): Promise<ThreadMetadataUpdateResponse>;
427
+ threadNameSet?(params: ThreadSetNameParams, context?: Context): Promise<ThreadSetNameResponse>;
428
+ threadRead?(params: ThreadReadParams, context?: Context): Promise<ThreadReadResponse>;
429
+ threadResume(params: ThreadResumeParams, context?: Context): Promise<ThreadResumeResponse>;
430
+ threadStart(params: ThreadStartParams, context?: Context): Promise<ThreadStartResponse>;
431
+ threadUnarchive?(params: ThreadUnarchiveParams, context?: Context): Promise<ThreadUnarchiveResponse>;
432
+ turnInterrupt(params: TurnInterruptParams, context?: Context): Promise<TurnInterruptResponse>;
433
+ turnStart(params: TurnStartParams, context?: Context): Promise<TurnStartResponse>;
434
+ turnSteer(params: TurnSteerParams, context?: Context): Promise<TurnSteerResponse>;
435
+ };
436
+ type InitializedConnectionSessionState = {
437
+ appServerClientName: string;
438
+ clientVersion: string;
439
+ experimentalApiEnabled: boolean;
440
+ optedOutNotificationMethods: ReadonlySet<string>;
441
+ };
442
+ declare class CodexAppServerConnectionSessionState {
443
+ readonly rpcGate: ConnectionRpcGate;
444
+ private initializedState;
445
+ constructor(initializedState?: InitializedConnectionSessionState | null);
446
+ initialized(): boolean;
447
+ initialize(state: InitializedConnectionSessionState): void;
448
+ experimentalApiEnabled(): boolean;
449
+ optedOutNotificationMethods(): ReadonlySet<string>;
450
+ appServerClientName(): string | null;
451
+ clientVersion(): string | null;
452
+ }
453
+ type CodexAppServerMessageProcessorOptions<Context = unknown> = {
454
+ connectionId?: ConnectionId;
455
+ handlers: CodexAppServerMethodHandlers<Context>;
456
+ initializeResponse?: InitializeResponse | (() => InitializeResponse);
457
+ outgoing?: OutgoingMessageSender;
458
+ requestSerializationQueues?: RequestSerializationQueues;
459
+ session?: CodexAppServerConnectionSessionState;
460
+ };
461
+ type CodexAppServerConnectionRequestOutcome = {
462
+ result: unknown;
463
+ type: "response";
464
+ } | {
465
+ type: "deferred";
466
+ } | {
467
+ error: JSONRPCErrorError;
468
+ type: "error";
469
+ };
470
+ type CodexAppServerDeferredResponse = {
471
+ readonly __codexAppServerDeferredResponse: true;
472
+ };
473
+ declare class CodexAppServerMessageProcessor<Context = unknown> {
474
+ readonly connectionId: ConnectionId;
475
+ readonly requestSerializationQueues: RequestSerializationQueues;
476
+ readonly session: CodexAppServerConnectionSessionState;
477
+ private readonly handlers;
478
+ private readonly initializeResponse;
479
+ private readonly outgoing;
480
+ constructor(options: CodexAppServerMessageProcessorOptions<Context>);
481
+ processClientRequest(request: ClientRequest, context?: Context): Promise<unknown>;
482
+ processConnectionRequest(request: ClientRequest, context?: Context): Promise<CodexAppServerConnectionRequestOutcome>;
483
+ shutdown(): Promise<void>;
484
+ connectionClosed(): Promise<void>;
485
+ private initialize;
486
+ private handleInitializedClientRequest;
487
+ private defaultInitializeResponse;
488
+ private connectionRequestId;
489
+ private requestContext;
490
+ }
491
+
492
+ declare class AgentPath {
493
+ private readonly value;
494
+ static readonly ROOT = "/root";
495
+ private constructor();
496
+ static root(): AgentPath;
497
+ static parse(value: string): AgentPath;
498
+ isRoot(): boolean;
499
+ toString(): string;
500
+ }
501
+
502
+ type AgentMetadata = {
503
+ agent_id?: ThreadId | null;
504
+ agent_path?: AgentPath | null;
505
+ agent_nickname?: string | null;
506
+ agent_role?: string | null;
507
+ last_task_message?: string | null;
508
+ };
509
+ type LiveAgent = {
510
+ thread_id: ThreadId;
511
+ metadata: AgentMetadata;
512
+ status: AgentStatus;
513
+ };
514
+ type ListedAgent = {
515
+ agent_name: string;
516
+ agent_status: AgentStatus;
517
+ last_task_message?: string | null;
518
+ };
519
+ declare const AgentStatus: {
520
+ readonly Running: "running";
521
+ readonly Completed: "completed";
522
+ readonly Failed: "failed";
523
+ readonly Closed: "closed";
524
+ readonly Cancelled: "cancelled";
525
+ };
526
+ type AgentStatus = (typeof AgentStatus)[keyof typeof AgentStatus];
527
+ declare class AgentRegistry {
528
+ private readonly agent_tree;
529
+ private readonly used_agent_nicknames;
530
+ private total_count;
531
+ private nickname_reset_count;
532
+ reserve_spawn_slot(max_threads?: number | null): SpawnReservation;
533
+ release_spawned_thread(thread_id: ThreadId): void;
534
+ release_spawn_slot(): void;
535
+ register_root_thread(thread_id: ThreadId): void;
536
+ agent_id_for_path(agent_path: AgentPath): ThreadId | null;
537
+ agent_metadata_for_thread(thread_id: ThreadId): AgentMetadata | null;
538
+ live_agents(): AgentMetadata[];
539
+ update_last_task_message(thread_id: ThreadId, last_task_message: string): void;
540
+ register_spawned_thread(agent_metadata: AgentMetadata): void;
541
+ reserve_agent_nickname(names: readonly string[], preferred?: string | null): string | null;
542
+ reserve_agent_path(agent_path: AgentPath): void;
543
+ private reset_and_select_nickname;
544
+ }
545
+ declare class SpawnReservation {
546
+ private readonly registry;
547
+ private active;
548
+ constructor(registry: AgentRegistry);
549
+ commit(metadata: AgentMetadata): void;
550
+ release(): void;
551
+ }
552
+
553
+ type InterAgentCommunication = {
554
+ author: AgentPath;
555
+ recipient: AgentPath;
556
+ items: unknown[];
557
+ content: string;
558
+ trigger_turn: boolean;
559
+ seq?: number;
560
+ };
561
+ declare class Mailbox {
562
+ private readonly pending;
563
+ private next_seq;
564
+ static new(): {
565
+ mailbox: Mailbox;
566
+ receiver: MailboxReceiver;
567
+ };
568
+ send(communication: Omit<InterAgentCommunication, "seq">): number;
569
+ drain(): InterAgentCommunication[];
570
+ has_pending(): boolean;
571
+ has_pending_trigger_turn(): boolean;
572
+ }
573
+ declare class MailboxReceiver {
574
+ private readonly mailbox;
575
+ constructor(mailbox: Mailbox);
576
+ has_pending(): boolean;
577
+ has_pending_trigger_turn(): boolean;
578
+ drain(): InterAgentCommunication[];
579
+ }
580
+
581
+ declare const SpawnAgentForkMode: {
582
+ readonly FullHistory: "full_history";
583
+ readonly LastNTurns: "last_n_turns";
584
+ };
585
+ type SpawnAgentForkMode = {
586
+ type: typeof SpawnAgentForkMode.FullHistory;
587
+ } | {
588
+ type: typeof SpawnAgentForkMode.LastNTurns;
589
+ turns: number;
590
+ };
591
+ type SpawnAgentOptions = {
592
+ fork_parent_spawn_call_id?: string | null;
593
+ fork_mode?: SpawnAgentForkMode | null;
594
+ environments?: unknown[] | null;
595
+ };
596
+ type AgentControlExecutor = {
597
+ spawn_agent?(input: {
598
+ initial_operation: unknown;
599
+ session_source?: unknown;
600
+ options?: SpawnAgentOptions;
601
+ }): Promise<LiveAgent>;
602
+ send_input?(input: {
603
+ target: ThreadId;
604
+ message?: string | null;
605
+ items?: unknown[] | null;
606
+ interrupt?: boolean;
607
+ }): Promise<unknown>;
608
+ wait_agent?(input: {
609
+ targets: ThreadId[];
610
+ timeout_ms?: number | null;
611
+ }): Promise<unknown>;
612
+ close_agent?(input: {
613
+ target: ThreadId;
614
+ }): Promise<unknown>;
615
+ resume_agent?(input: {
616
+ id: ThreadId;
617
+ }): Promise<unknown>;
618
+ };
619
+ declare class AgentControl {
620
+ private readonly executor;
621
+ readonly registry: AgentRegistry;
622
+ readonly mailbox: Mailbox;
623
+ constructor(executor?: AgentControlExecutor | null);
624
+ static empty(): AgentControl;
625
+ spawn_agent_with_metadata(input: {
626
+ initial_operation: unknown;
627
+ session_source?: unknown;
628
+ options?: SpawnAgentOptions;
629
+ }): Promise<LiveAgent>;
630
+ send_input(input: {
631
+ target: ThreadId;
632
+ message?: string | null;
633
+ items?: unknown[] | null;
634
+ interrupt?: boolean;
635
+ }): Promise<unknown>;
636
+ wait_agent(input: {
637
+ targets: ThreadId[];
638
+ timeout_ms?: number | null;
639
+ }): Promise<unknown>;
640
+ close_agent(input: {
641
+ target: ThreadId;
642
+ }): Promise<unknown>;
643
+ resume_agent(input: {
644
+ id: ThreadId;
645
+ }): Promise<unknown>;
646
+ list_agents(): ListedAgent[];
647
+ send_mail(communication: Omit<InterAgentCommunication, "seq">): number;
648
+ }
649
+
650
+ type WireApi = "responses";
651
+ type ModelProviderAuthInfo = {
652
+ command: string;
653
+ args?: string[] | null;
654
+ env?: Record<string, string> | null;
655
+ };
656
+ type ModelProviderAwsAuthInfo = {
657
+ profile?: string | null;
658
+ region?: string | null;
659
+ };
660
+ type ModelProviderInfo = {
661
+ name: string;
662
+ base_url?: string | null;
663
+ env_key?: string | null;
664
+ env_key_instructions?: string | null;
665
+ experimental_bearer_token?: string | null;
666
+ auth?: ModelProviderAuthInfo | null;
667
+ aws?: ModelProviderAwsAuthInfo | null;
668
+ wire_api?: WireApi;
669
+ query_params?: Record<string, string> | null;
670
+ http_headers?: Record<string, string> | null;
671
+ env_http_headers?: Record<string, string> | null;
672
+ request_max_retries?: number | null;
673
+ stream_max_retries?: number | null;
674
+ stream_idle_timeout_ms?: number | null;
675
+ websocket_connect_timeout_ms?: number | null;
676
+ requires_openai_auth?: boolean;
677
+ supports_websockets?: boolean;
678
+ };
679
+ type ProviderCapabilities = {
680
+ namespace_tools: boolean;
681
+ image_generation: boolean;
682
+ web_search: boolean;
683
+ };
684
+ type ProviderRuntimeConfig = {
685
+ name: string;
686
+ base_url: string;
687
+ responses_url: string;
688
+ query_params: Record<string, string> | null;
689
+ headers: Record<string, string>;
690
+ request_max_retries: number;
691
+ stream_max_retries: number;
692
+ stream_idle_timeout_ms: number;
693
+ websocket_connect_timeout_ms: number;
694
+ supports_websockets: boolean;
695
+ };
696
+ type ModelServiceTier = {
697
+ id: string;
698
+ name: string;
699
+ description: string;
700
+ };
701
+ type ReasoningEffortOption = {
702
+ reasoning_effort: string;
703
+ description: string;
704
+ };
705
+ type ModelInfo = {
706
+ slug: string;
707
+ display_name: string;
708
+ description: string | null;
709
+ default_reasoning_level: string | null;
710
+ supported_reasoning_levels: ReasoningEffortOption[];
711
+ visibility: "list" | "hide" | "none";
712
+ supported_in_api: boolean;
713
+ priority: number;
714
+ upgrade: string | null;
715
+ upgrade_info: null;
716
+ availability_nux: null;
717
+ input_modalities: string[];
718
+ supports_personality: boolean;
719
+ additional_speed_tiers: string[];
720
+ service_tiers: ModelServiceTier[];
721
+ base_instructions: string;
722
+ model_messages?: ModelMessages | null;
723
+ context_window?: number | null;
724
+ max_context_window?: number | null;
725
+ auto_compact_token_limit?: number | null;
726
+ effective_context_window_percent?: number | null;
727
+ };
728
+ type ModelMessages = {
729
+ instructions_template?: string | null;
730
+ instructions_variables?: ModelInstructionsVariables | null;
731
+ };
732
+ type ModelInstructionsVariables = {
733
+ personality?: Record<string, string> | null;
734
+ };
735
+ type ModelPreset = {
736
+ id: string;
737
+ model: string;
738
+ upgrade: string | null;
739
+ upgrade_info: null;
740
+ availability_nux: null;
741
+ display_name: string;
742
+ description: string;
743
+ hidden: boolean;
744
+ supported_reasoning_efforts: ReasoningEffortOption[];
745
+ default_reasoning_effort: string;
746
+ input_modalities: string[];
747
+ supports_personality: boolean;
748
+ additional_speed_tiers: string[];
749
+ service_tiers: ModelServiceTier[];
750
+ is_default: boolean;
751
+ supported_in_api: boolean;
752
+ };
753
+ type ModelListParams = {
754
+ cursor?: string | null;
755
+ limit?: number | null;
756
+ include_hidden?: boolean | null;
757
+ };
758
+ type ModelListResponse = {
759
+ data: ModelPreset[];
760
+ next_cursor: string | null;
761
+ };
762
+ type RefreshStrategy = "online" | "offline" | "online_if_uncached";
763
+ type ModelsManager = {
764
+ list_models(params?: ModelListParams): ModelListResponse;
765
+ raw_model_catalog(refresh_strategy?: RefreshStrategy): {
766
+ models: ModelInfo[];
767
+ };
768
+ get_model_info(model: string): ModelInfo;
769
+ get_default_model(model?: string | null): string;
770
+ default_reasoning_effort(model?: string | null): string;
771
+ };
772
+ type ModelProvider = {
773
+ info(): ModelProviderInfo;
774
+ account_state(): ProviderAccountState;
775
+ capabilities(): ProviderCapabilities;
776
+ runtime_config(auth?: CodexAuth | null): ProviderRuntimeConfig;
777
+ models_manager(): ModelsManager;
778
+ };
779
+
780
+ type ConfigToml = {
781
+ model?: string;
782
+ review_model?: string;
783
+ model_provider?: string;
784
+ service_tier?: ServiceTier | null;
785
+ model_reasoning_effort?: ReasoningEffortConfig | null;
786
+ plan_mode_reasoning_effort?: ReasoningEffortConfig | null;
787
+ model_reasoning_summary?: ReasoningSummaryConfig;
788
+ personality?: Personality | null;
789
+ approval_policy?: AskForApproval;
790
+ approvals_reviewer?: ApprovalsReviewer | null;
791
+ sandbox_policy?: SandboxPolicy | null;
792
+ sandbox_mode?: SandboxPolicy["mode"] | null;
793
+ default_permissions?: string | null;
794
+ permission_profile?: PermissionProfile | null;
795
+ active_permission_profile?: ActivePermissionProfile | null;
796
+ windows_sandbox_level?: WindowsSandboxLevel | null;
797
+ cwd?: string;
798
+ instructions?: string | null;
799
+ model_instructions_file?: string | null;
800
+ model_instructions_file_contents?: string | null;
801
+ base_instructions?: BaseInstructions | string | null;
802
+ developer_instructions?: string | null;
803
+ user_instructions?: string | null;
804
+ collaboration_mode?: CollaborationMode | null;
805
+ session_source?: SessionSource;
806
+ environments?: TurnEnvironmentSelection[];
807
+ dynamic_tools?: DynamicToolSpec$1[];
808
+ final_output_json_schema?: unknown;
809
+ truncation_policy?: TruncationPolicy | null;
810
+ web_search?: WebSearchMode$1 | null;
811
+ tools?: ToolsToml | null;
812
+ features?: FeaturesToml | null;
813
+ profiles?: Record<string, ConfigProfile>;
814
+ profile?: string | null;
815
+ compact_prompt?: string | null;
816
+ include_permissions_instructions?: boolean;
817
+ include_environment_context?: boolean;
818
+ include_apps_instructions?: boolean;
819
+ include_skill_instructions?: boolean;
820
+ };
821
+ type ConfigProfile = Omit<ConfigToml, "profiles" | "profile">;
822
+ type ToolsToml = Omit<DefaultToolsConfigInput, "web_search"> & {
823
+ web_search?: Partial<WebSearchToolConfig> | boolean | null;
824
+ };
825
+ type FeaturesToml = Record<string, unknown>;
826
+ type ResolvedConfig = Required<Pick<ConfigToml, "model" | "model_provider" | "approval_policy" | "cwd" | "session_source">> & Omit<ConfigToml, "model" | "model_provider" | "approval_policy" | "cwd" | "session_source"> & {
827
+ base_instructions: BaseInstructions;
828
+ base_instructions_source: "config" | "model_instructions_file" | "default";
829
+ service_tier: ServiceTier | null;
830
+ reasoning_effort: ReasoningEffortConfig | null;
831
+ reasoning_summary: ReasoningSummaryConfig;
832
+ developer_instructions: string | null;
833
+ user_instructions: string | null;
834
+ personality: Personality | null;
835
+ sandbox_policy: SandboxPolicy;
836
+ permission_profile: PermissionProfile;
837
+ active_permission_profile: ActivePermissionProfile | null;
838
+ windows_sandbox_level: WindowsSandboxLevel | null;
839
+ collaboration_mode: CollaborationMode;
840
+ environments: TurnEnvironmentSelection[];
841
+ dynamic_tools: DynamicToolSpec$1[];
842
+ final_output_json_schema?: unknown;
843
+ truncation_policy: TruncationPolicy | null;
844
+ web_search_mode: WebSearchMode$1;
845
+ tools: ToolsConfig;
846
+ startup_warnings: string[];
847
+ };
848
+
849
+ type ThreadGoalUpdate = {
850
+ status?: ThreadGoalStatus;
851
+ token_budget?: number | null;
852
+ expected_goal_id?: string | null;
853
+ };
854
+ declare const ThreadGoalAccountingMode: {
855
+ readonly ActiveStatusOnly: "active_status_only";
856
+ readonly ActiveOnly: "active_only";
857
+ readonly ActiveOrComplete: "active_or_complete";
858
+ readonly ActiveOrStopped: "active_or_stopped";
859
+ };
860
+ type ThreadGoalAccountingMode = (typeof ThreadGoalAccountingMode)[keyof typeof ThreadGoalAccountingMode];
861
+ type ThreadGoalAccountingOutcome = {
862
+ type: "updated";
863
+ goal: ThreadGoal;
864
+ } | {
865
+ type: "unchanged";
866
+ goal: ThreadGoal | null;
867
+ };
868
+ type ThreadGoalStore = {
869
+ getThreadGoal(threadId: ThreadId): Promise<ThreadGoal | null>;
870
+ replaceThreadGoal(params: {
871
+ thread_id: ThreadId;
872
+ objective: string;
873
+ status: ThreadGoalStatus;
874
+ token_budget?: number | null;
875
+ }): Promise<ThreadGoal>;
876
+ insertThreadGoal(params: {
877
+ thread_id: ThreadId;
878
+ objective: string;
879
+ status: ThreadGoalStatus;
880
+ token_budget?: number | null;
881
+ }): Promise<ThreadGoal>;
882
+ updateThreadGoal(params: {
883
+ thread_id: ThreadId;
884
+ update: ThreadGoalUpdate;
885
+ }): Promise<ThreadGoal>;
886
+ pauseActiveThreadGoal(threadId: ThreadId): Promise<ThreadGoal | null>;
887
+ deleteThreadGoal(threadId: ThreadId): Promise<void>;
888
+ accountThreadGoalUsage(params: {
889
+ thread_id: ThreadId;
890
+ tokens_used_delta?: number;
891
+ time_used_seconds_delta?: number;
892
+ mode?: ThreadGoalAccountingMode;
893
+ }): Promise<ThreadGoalAccountingOutcome>;
894
+ };
895
+ type CreateGoalRequest = {
896
+ objective: string;
897
+ token_budget?: number | null;
898
+ };
899
+
900
+ type ConfiguredHookHandler = {
901
+ event_name: HookEventName;
902
+ matcher?: string | null;
903
+ name?: string | null;
904
+ status_message?: string | null;
905
+ source_path?: string | null;
906
+ source?: HookSource;
907
+ display_order?: number;
908
+ run?: (request: unknown) => Promise<HookHandlerResult> | HookHandlerResult;
909
+ };
910
+ type HookHandlerResult = {
911
+ status?: HookRunStatus;
912
+ entries?: HookOutputEntry[];
913
+ additional_contexts?: string[];
914
+ block_reason?: string | null;
915
+ stop_reason?: string | null;
916
+ feedback_message?: string | null;
917
+ permission_decision?: PermissionRequestDecision | null;
918
+ };
919
+ declare const PermissionRequestDecision: {
920
+ readonly Allow: "allow";
921
+ readonly Deny: "deny";
922
+ };
923
+ type PermissionRequestDecision = {
924
+ type: typeof PermissionRequestDecision.Allow;
925
+ } | {
926
+ type: typeof PermissionRequestDecision.Deny;
927
+ message?: string | null;
928
+ };
929
+
930
+ type SessionStartRequest = {
931
+ session_id: string;
932
+ turn_id: string;
933
+ cwd: string;
934
+ transcript_path?: string | null;
935
+ model: string;
936
+ permission_mode: string;
937
+ source: string;
938
+ };
939
+ type UserPromptSubmitRequest = {
940
+ session_id: string;
941
+ turn_id: string;
942
+ cwd: string;
943
+ transcript_path?: string | null;
944
+ model: string;
945
+ permission_mode: string;
946
+ prompt: string;
947
+ };
948
+ type PreToolUseRequest = {
949
+ session_id: string;
950
+ turn_id: string;
951
+ cwd: string;
952
+ transcript_path?: string | null;
953
+ model: string;
954
+ permission_mode: string;
955
+ tool_name: string;
956
+ matcher_aliases: string[];
957
+ tool_use_id: string;
958
+ tool_input: unknown;
959
+ };
960
+ type PostToolUseRequest = PreToolUseRequest & {
961
+ tool_response: unknown;
962
+ };
963
+ type PermissionRequestRequest = PreToolUseRequest & {
964
+ run_id_suffix: string;
965
+ };
966
+ type CompactHookRequest = {
967
+ session_id: string;
968
+ turn_id: string;
969
+ cwd: string;
970
+ transcript_path?: string | null;
971
+ model: string;
972
+ trigger: "manual" | "auto";
973
+ };
974
+ type PreToolUseOutcome = {
975
+ hook_events: HookCompletedEvent[];
976
+ should_block: boolean;
977
+ block_reason?: string | null;
978
+ additional_contexts: string[];
979
+ };
980
+ type PostToolUseOutcome = {
981
+ hook_events: HookCompletedEvent[];
982
+ should_stop: boolean;
983
+ stop_reason?: string | null;
984
+ feedback_message?: string | null;
985
+ additional_contexts: string[];
986
+ };
987
+ type PermissionRequestOutcome = {
988
+ hook_events: HookCompletedEvent[];
989
+ decision?: PermissionRequestDecision | null;
990
+ };
991
+ declare class Hooks {
992
+ private readonly handlers;
993
+ constructor(handlers?: readonly ConfiguredHookHandler[]);
994
+ static empty(): Hooks;
995
+ static withHandlersForTest(handlers: readonly ConfiguredHookHandler[]): Hooks;
996
+ is_empty(): boolean;
997
+ preview_session_start(request: SessionStartRequest): HookRunSummary[];
998
+ run_session_start(request: SessionStartRequest): Promise<PostToolUseOutcome>;
999
+ preview_user_prompt_submit(): HookRunSummary[];
1000
+ run_user_prompt_submit(request: UserPromptSubmitRequest): Promise<PostToolUseOutcome>;
1001
+ preview_pre_tool_use(request: PreToolUseRequest): HookRunSummary[];
1002
+ run_pre_tool_use(request: PreToolUseRequest): Promise<PreToolUseOutcome>;
1003
+ preview_post_tool_use(request: PostToolUseRequest): HookRunSummary[];
1004
+ run_post_tool_use(request: PostToolUseRequest): Promise<PostToolUseOutcome>;
1005
+ preview_permission_request(request: PermissionRequestRequest): HookRunSummary[];
1006
+ run_permission_request(request: PermissionRequestRequest): Promise<PermissionRequestOutcome>;
1007
+ preview_pre_compact(request: CompactHookRequest): HookRunSummary[];
1008
+ run_pre_compact(request: CompactHookRequest): Promise<PostToolUseOutcome>;
1009
+ preview_post_compact(request: CompactHookRequest): HookRunSummary[];
1010
+ run_post_compact(request: CompactHookRequest): Promise<PostToolUseOutcome>;
1011
+ preview_stop(): HookRunSummary[];
1012
+ run_stop(request: CompactHookRequest): Promise<PostToolUseOutcome>;
1013
+ private preview;
1014
+ private runContextInjecting;
1015
+ private runMatching;
1016
+ }
1017
+
1018
+ declare const TaskKind: {
1019
+ readonly Regular: "Regular";
1020
+ readonly Compact: "Compact";
1021
+ readonly Review: "Review";
1022
+ };
1023
+ type TaskKind = (typeof TaskKind)[keyof typeof TaskKind];
1024
+ type SessionTaskResult = {
1025
+ last_agent_message: string | null;
1026
+ steps?: number;
1027
+ message?: string;
1028
+ };
1029
+ declare class SessionTaskContext {
1030
+ private readonly session;
1031
+ constructor(session: Session);
1032
+ clone_session(): Session;
1033
+ }
1034
+ type SessionTaskRunInput = {
1035
+ session: SessionTaskContext;
1036
+ ctx: TurnContext;
1037
+ input: UserInput[];
1038
+ signal?: AbortSignal;
1039
+ };
1040
+ interface SessionTask {
1041
+ kind(): TaskKind;
1042
+ span_name(): string;
1043
+ records_turn_token_usage_on_span(): boolean;
1044
+ run(input: SessionTaskRunInput): Promise<SessionTaskResult>;
1045
+ abort?(input: {
1046
+ session: SessionTaskContext;
1047
+ ctx: TurnContext;
1048
+ }): Promise<void>;
1049
+ }
1050
+ type RunningTask = {
1051
+ sub_id: string;
1052
+ kind: TaskKind;
1053
+ turn_context: TurnContext;
1054
+ task?: SessionTask;
1055
+ abort_controller?: AbortController;
1056
+ records_turn_token_usage_on_span?: boolean;
1057
+ };
1058
+
1059
+ declare const MailboxDeliveryPhase: {
1060
+ readonly CurrentTurn: "CurrentTurn";
1061
+ readonly NextTurn: "NextTurn";
1062
+ };
1063
+ type MailboxDeliveryPhase = (typeof MailboxDeliveryPhase)[keyof typeof MailboxDeliveryPhase];
1064
+ type PendingUserInput = {
1065
+ resolve(response: RequestUserInputResponse | null): void;
1066
+ };
1067
+ type PendingDynamicTool = {
1068
+ resolve(response: DynamicToolResponse | null): void;
1069
+ };
1070
+ type PendingRequestPermissions = {
1071
+ resolve(response: RequestPermissionsResponse | null): void;
1072
+ };
1073
+ type PendingMcpElicitation = {
1074
+ resolve(response: McpServerElicitationResponse | null): void;
1075
+ };
1076
+ type RemovedTask = {
1077
+ active_turn_is_empty: boolean;
1078
+ task: RunningTask;
1079
+ };
1080
+ declare class TurnState$1 {
1081
+ private readonly pending_user_input;
1082
+ private readonly pending_dynamic_tools;
1083
+ private readonly pending_request_permissions;
1084
+ private readonly pending_mcp_elicitations;
1085
+ private pending_input;
1086
+ private readonly mailbox;
1087
+ private mailbox_delivery_phase;
1088
+ private readonly permission_grants;
1089
+ tool_calls: number;
1090
+ has_memory_citation: boolean;
1091
+ token_usage_at_turn_start: TokenUsage;
1092
+ insertPendingUserInput(key: string, pending: PendingUserInput): PendingUserInput | undefined;
1093
+ removePendingUserInput(key: string): PendingUserInput | undefined;
1094
+ insertPendingDynamicTool(key: string, pending: PendingDynamicTool): PendingDynamicTool | undefined;
1095
+ removePendingDynamicTool(key: string): PendingDynamicTool | undefined;
1096
+ insertPendingRequestPermissions(key: string, pending: PendingRequestPermissions): PendingRequestPermissions | undefined;
1097
+ removePendingRequestPermissions(key: string): PendingRequestPermissions | undefined;
1098
+ insertPendingMcpElicitation(serverName: string, id: McpRequestId, pending: PendingMcpElicitation): PendingMcpElicitation | undefined;
1099
+ removePendingMcpElicitation(serverName: string, id: McpRequestId): PendingMcpElicitation | undefined;
1100
+ recordPermissionGrant(response: RequestPermissionsResponse): void;
1101
+ grantedPermissions(): RequestPermissionProfile[];
1102
+ strictAutoReviewEnabled(): boolean;
1103
+ pushPendingInput(input: UserInput): void;
1104
+ prependPendingInput(input: UserInput[]): void;
1105
+ takePendingInput(): UserInput[];
1106
+ hasPendingInput(): boolean;
1107
+ clearPending(): void;
1108
+ cancelPending(): void;
1109
+ sendMailboxMessage(communication: Omit<InterAgentCommunication, "seq">): number;
1110
+ drainMailbox(): InterAgentCommunication[];
1111
+ hasMailboxPending(): boolean;
1112
+ hasMailboxPendingTriggerTurn(): boolean;
1113
+ acceptMailboxDeliveryForCurrentTurn(): void;
1114
+ acceptsMailboxDeliveryForCurrentTurn(): boolean;
1115
+ setMailboxDeliveryPhase(phase: MailboxDeliveryPhase): void;
1116
+ }
1117
+ declare class ActiveTurn {
1118
+ private readonly tasks;
1119
+ readonly turn_state: TurnState$1;
1120
+ addTask(task: RunningTask): void;
1121
+ removeTask(sub_id: string): RemovedTask | undefined;
1122
+ drainTasks(): RunningTask[];
1123
+ firstTask(): RunningTask | null;
1124
+ hasTask(sub_id: string): boolean;
1125
+ clearPending(): void;
1126
+ cancelPending(): void;
1127
+ get size(): number;
1128
+ }
1129
+
1130
+ type SessionSettingsUpdate = {
1131
+ cwd?: string;
1132
+ approval_policy?: AskForApproval;
1133
+ approvals_reviewer?: ApprovalsReviewer | null;
1134
+ sandbox_policy?: SandboxPolicy;
1135
+ permission_profile?: PermissionProfile | null;
1136
+ active_permission_profile?: ActivePermissionProfile | null;
1137
+ windows_sandbox_level?: WindowsSandboxLevel | null;
1138
+ model?: string;
1139
+ effort?: ReasoningEffortConfig | null;
1140
+ summary?: ReasoningSummaryConfig;
1141
+ service_tier?: ServiceTier | null;
1142
+ collaboration_mode?: CollaborationMode;
1143
+ personality?: Personality | null;
1144
+ environments?: TurnEnvironmentSelection[];
1145
+ persist_environments?: boolean;
1146
+ final_output_json_schema?: unknown;
1147
+ };
1148
+
1149
+ type Event = {
1150
+ id: string;
1151
+ msg: EventMsg;
1152
+ };
1153
+ type SessionConfiguration = {
1154
+ provider: string;
1155
+ model: string;
1156
+ model_info?: ModelInfo | null;
1157
+ collaboration_mode: CollaborationMode;
1158
+ reasoning_effort?: ReasoningEffortConfig | null;
1159
+ reasoning_summary: ReasoningSummaryConfig;
1160
+ service_tier?: ServiceTier | null;
1161
+ base_instructions: BaseInstructions;
1162
+ developer_instructions?: string | null;
1163
+ user_instructions?: string | null;
1164
+ personality?: Personality | null;
1165
+ cwd: string;
1166
+ approval_policy: AskForApproval;
1167
+ approvals_reviewer?: ApprovalsReviewer | null;
1168
+ sandbox_policy: SandboxPolicy;
1169
+ permission_profile: PermissionProfile;
1170
+ active_permission_profile?: ActivePermissionProfile | null;
1171
+ windows_sandbox_level?: WindowsSandboxLevel | null;
1172
+ environments: TurnEnvironmentSelection[];
1173
+ session_source: SessionSource;
1174
+ dynamic_tools: DynamicToolSpec$1[];
1175
+ tools: ToolsConfig;
1176
+ final_output_json_schema?: unknown;
1177
+ truncation_policy?: TruncationPolicy | null;
1178
+ };
1179
+ type SessionParams = {
1180
+ threadId: ThreadId;
1181
+ configuration: SessionConfiguration;
1182
+ liveThread?: LiveThread | null;
1183
+ idGenerator?: () => string;
1184
+ eventSink?: (event: Event) => void;
1185
+ now?: () => number;
1186
+ initialHistory?: RolloutItem[] | null;
1187
+ rolloutPath?: string | null;
1188
+ forkedFromId?: ThreadId | null;
1189
+ threadName?: string | null;
1190
+ threadSource?: string | null;
1191
+ hooks?: Hooks;
1192
+ threadGoalStore?: ThreadGoalStore | null;
1193
+ mcpConnectionManager?: McpConnectionManager | null;
1194
+ agentControl?: AgentControl | null;
1195
+ };
1196
+ declare class Session {
1197
+ readonly threadId: ThreadId;
1198
+ readonly emittedEvents: Event[];
1199
+ private readonly liveThread;
1200
+ private readonly idGenerator;
1201
+ private readonly eventSink?;
1202
+ private readonly now;
1203
+ private configuration;
1204
+ private readonly rolloutPath;
1205
+ private readonly forkedFromId;
1206
+ private readonly threadName;
1207
+ private readonly threadSource;
1208
+ private readonly initialMessages;
1209
+ private readonly hook_runtime;
1210
+ private readonly agent_control;
1211
+ private readonly goal_runtime;
1212
+ private readonly mcp_connection_manager;
1213
+ private readonly state;
1214
+ private sessionConfiguredSent;
1215
+ private sessionStartHooksRan;
1216
+ private readonly idle_pending_input;
1217
+ private readonly session_permission_grants;
1218
+ activeTurn: ActiveTurn | null;
1219
+ constructor(params: SessionParams);
1220
+ private get token_info();
1221
+ private set token_info(value);
1222
+ private get latest_rate_limits();
1223
+ private set latest_rate_limits(value);
1224
+ private get reference_context_item();
1225
+ private set reference_context_item(value);
1226
+ private get previous_turn_settings();
1227
+ private set previous_turn_settings(value);
1228
+ submit(op: Op): Promise<string>;
1229
+ submit_with_id(submission: Submission): Promise<void>;
1230
+ insertPendingUserInput(key: string, pending: PendingUserInput): void;
1231
+ insertPendingDynamicTool(key: string, pending: PendingDynamicTool): void;
1232
+ insertPendingRequestPermissions(key: string, pending: PendingRequestPermissions): void;
1233
+ steer_input(input: UserInput[], expected_turn_id?: string | null): Promise<string>;
1234
+ inject_response_items(input: UserInput[]): Promise<boolean>;
1235
+ prepend_pending_input(input: UserInput[]): Promise<boolean>;
1236
+ get_pending_input(): Promise<UserInput[]>;
1237
+ has_pending_input(): Promise<boolean>;
1238
+ queue_response_items_for_next_turn(items: UserInput[]): Promise<void>;
1239
+ take_queued_response_items_for_next_turn(): Promise<UserInput[]>;
1240
+ collaboration_mode(): CollaborationMode;
1241
+ granted_session_permissions(): RequestPermissionProfile[];
1242
+ hooks(): Hooks;
1243
+ agentControl(): AgentControl;
1244
+ configure_session(initialMessages?: EventMsg[] | null): Promise<void>;
1245
+ strict_auto_review_enabled_for_turn(): boolean;
1246
+ request_user_input(turnContext: TurnContext, callId: string, args: NormalizedRequestUserInputArgs): Promise<RequestUserInputResponse | null>;
1247
+ request_permissions(turnContext: TurnContext, callId: string, args: RequestPermissionsArgs): Promise<RequestPermissionsResponse | null>;
1248
+ refresh_mcp_servers_now(turnContext: TurnContext, config: McpServerRefreshConfig, environment?: McpRuntimeEnvironment): Promise<void>;
1249
+ refresh_mcp_servers_if_requested(turnContext: TurnContext, config?: McpServerRefreshConfig | null): Promise<void>;
1250
+ list_mcp_server_statuses(): Promise<McpServerStatus[]>;
1251
+ list_mcp_tools(): Promise<McpToolInfo[]>;
1252
+ list_resources(params: McpResourceListParams): Promise<McpResourceListResponse>;
1253
+ list_resource_templates(params: McpResourceListParams): Promise<McpResourceTemplateListResponse>;
1254
+ read_resource(_paramsTurnContext: TurnContext | null, params: McpResourceReadParams): Promise<McpResourceReadResponse>;
1255
+ call_tool(turnContext: TurnContext, params: McpServerToolCallParams): Promise<McpServerToolCallResponse>;
1256
+ resolve_mcp_tool_info(toolName: string): Promise<McpToolInfo | null>;
1257
+ request_mcp_server_elicitation(turnContext: TurnContext, serverName: string, id: McpRequestId, request: McpServerElicitationRequest): Promise<McpServerElicitationResponse | null>;
1258
+ request_dynamic_tool(turnContext: TurnContext, callId: string, toolName: string, argumentsValue: unknown): Promise<DynamicToolResponse | null>;
1259
+ startTurn(submission: Submission): Promise<TurnContext>;
1260
+ startCompactTurn(submission: Submission): Promise<TurnContext>;
1261
+ start_task(input: {
1262
+ turnContext: TurnContext;
1263
+ task?: SessionTask;
1264
+ kind?: TaskKind;
1265
+ abortController?: AbortController;
1266
+ }): Promise<RunningTask>;
1267
+ spawn_task(input: {
1268
+ turnContext: TurnContext;
1269
+ task: SessionTask;
1270
+ input: UserInput[];
1271
+ abortController?: AbortController;
1272
+ }): Promise<SessionTaskResult>;
1273
+ recordCompactedItem(item: CompactedItem): Promise<void>;
1274
+ record_into_history(turnContext: TurnContext, items: readonly ResponseItem[]): void;
1275
+ record_conversation_items(turnContext: TurnContext, items: readonly ResponseItem[]): Promise<void>;
1276
+ completeTurn(turnContext: TurnContext, lastAgentMessage?: string | null): Promise<void>;
1277
+ on_task_finished(turnContext: TurnContext, result: SessionTaskResult): Promise<void>;
1278
+ failTurn(turnContext: TurnContext, error: unknown): Promise<void>;
1279
+ abortActiveTurn(reason?: "interrupted"): Promise<void>;
1280
+ abort_all_tasks(reason?: "interrupted"): Promise<void>;
1281
+ markFirstToken(turnContext: TurnContext): void;
1282
+ update_token_usage_info(turnContext: TurnContext, tokenUsage?: TokenUsage | null): Promise<void>;
1283
+ update_rate_limits(turnContext: TurnContext, newRateLimits: RateLimitSnapshot): Promise<void>;
1284
+ token_usage_info(): TokenUsageInfo | null;
1285
+ clone_history(): ContextManager;
1286
+ replace_history(items: ResponseItem[], referenceContextItem?: TurnContextItem | null): void;
1287
+ replace_compacted_history(turnContext: TurnContext, items: ResponseItem[], referenceContextItem?: TurnContextItem | null): Promise<void>;
1288
+ get_total_token_usage_breakdown(): TotalTokenUsageBreakdown;
1289
+ get_total_token_usage(): number;
1290
+ get_thread_goal(): Promise<ThreadGoal | null>;
1291
+ create_thread_goal(turnContext: TurnContext, request: CreateGoalRequest): Promise<ThreadGoal>;
1292
+ update_thread_goal_complete(turnContext: TurnContext): Promise<ThreadGoal>;
1293
+ note_tool_completed(turnContext: TurnContext, toolName: string): Promise<void>;
1294
+ thread_goal_steering_items(): Promise<ResponseItem[]>;
1295
+ latest_rate_limit_snapshot(): RateLimitSnapshot | null;
1296
+ private send_token_count_event;
1297
+ private send_thread_goal_update_if_needed;
1298
+ private send_thread_goal_updated;
1299
+ private userInputOrTurn;
1300
+ private createTurnContext;
1301
+ new_turn_with_sub_id(submissionId: string, updates: SessionSettingsUpdate, trace?: Submission["trace"]): Promise<TurnContext>;
1302
+ new_default_turn_with_sub_id(submissionId: string, trace?: Submission["trace"]): Promise<TurnContext>;
1303
+ turn_context_from_config(config: ResolvedConfig, submissionId: string, trace?: Submission["trace"]): TurnContext;
1304
+ private turnContextFromConfiguration;
1305
+ private overrideTurnContext;
1306
+ private sessionSettingsUpdateFromOp;
1307
+ private notifyUserInputResponse;
1308
+ notify_request_permissions_response(callId: string, response: RequestPermissionsResponse): void;
1309
+ resolve_elicitation(serverName: string, id: McpRequestId, response: McpServerElicitationResponse): Promise<void>;
1310
+ private record_granted_request_permissions;
1311
+ notify_dynamic_tool_response(callId: string, response: DynamicToolResponse): void;
1312
+ private setThreadMemoryMode;
1313
+ private shutdown;
1314
+ private interrupt;
1315
+ private threadRollback;
1316
+ private compactWithoutModel;
1317
+ send_event(turnContext: TurnContext, msg: EventMsg): Promise<void>;
1318
+ recordResponseItem(turnContext: TurnContext, item: ResponseItem): Promise<void>;
1319
+ record_context_updates_and_set_reference_context_item(turnContext: TurnContext): Promise<void>;
1320
+ send_event_raw(event: Event): Promise<void>;
1321
+ private deliver_event_raw;
1322
+ private persist_rollout_items;
1323
+ }
1324
+
1325
+ type WebSearchMode = "disabled" | "cached" | "live";
1326
+ type WebSearchToolType = "text" | "text_and_image";
1327
+ type WebSearchConfig = {
1328
+ filters?: unknown;
1329
+ user_location?: unknown;
1330
+ search_context_size?: unknown;
1331
+ };
1332
+ type ToolsConfig = {
1333
+ namespace_tools: boolean;
1334
+ request_permissions_tool_enabled: boolean;
1335
+ request_user_input_available_modes: readonly ModeKind[];
1336
+ search_tool: boolean;
1337
+ web_search_mode: WebSearchMode | null;
1338
+ web_search_tool_type: WebSearchToolType;
1339
+ web_search_config?: WebSearchConfig | null;
1340
+ image_gen_tool: boolean;
1341
+ exec_command_tool_enabled: boolean;
1342
+ write_stdin_tool_enabled: boolean;
1343
+ apply_patch_tool_enabled: boolean;
1344
+ thread_goal_tools_enabled: boolean;
1345
+ mcp_tools_enabled: boolean;
1346
+ multi_agent_tools_enabled: boolean;
1347
+ };
1348
+ type DefaultToolsConfigInput = {
1349
+ namespace_tools?: boolean;
1350
+ image_generation?: boolean;
1351
+ web_search?: boolean;
1352
+ request_permissions_tool_enabled?: boolean;
1353
+ request_user_input_available_modes?: readonly ModeKind[];
1354
+ search_tool?: boolean;
1355
+ web_search_mode?: WebSearchMode | null;
1356
+ web_search_tool_type?: WebSearchToolType;
1357
+ web_search_config?: WebSearchConfig | null;
1358
+ image_gen_tool?: boolean;
1359
+ exec_command_tool_enabled?: boolean;
1360
+ write_stdin_tool_enabled?: boolean;
1361
+ apply_patch_tool_enabled?: boolean;
1362
+ thread_goal_tools_enabled?: boolean;
1363
+ mcp_tools_enabled?: boolean;
1364
+ multi_agent_tools_enabled?: boolean;
1365
+ };
1366
+
1367
+ type TurnTimingSnapshot = {
1368
+ completed_at: number;
1369
+ duration_ms: number;
1370
+ time_to_first_token_ms: number | null;
1371
+ };
1372
+ declare class TurnTimingState {
1373
+ private started_at_ms;
1374
+ private first_token_at_ms;
1375
+ markTurnStarted(now: number): number;
1376
+ markFirstToken(now: number): void;
1377
+ completedAtAndDuration(now: number): TurnTimingSnapshot;
1378
+ }
1379
+
1380
+ type TurnContextParams = {
1381
+ sub_id: string;
1382
+ trace?: W3cTraceContext;
1383
+ cwd: string;
1384
+ current_date?: string;
1385
+ timezone?: string;
1386
+ approval_policy: AskForApproval;
1387
+ approvals_reviewer?: ApprovalsReviewer | null;
1388
+ sandbox_policy: SandboxPolicy;
1389
+ permission_profile?: PermissionProfile | null;
1390
+ active_permission_profile?: ActivePermissionProfile | null;
1391
+ windows_sandbox_level?: WindowsSandboxLevel | null;
1392
+ model: string;
1393
+ model_info?: ModelInfo | null;
1394
+ personality?: Personality | null;
1395
+ collaboration_mode?: CollaborationMode | null;
1396
+ effort?: ReasoningEffortConfig | null;
1397
+ summary: ReasoningSummaryConfig;
1398
+ service_tier?: ServiceTier | null;
1399
+ session_source: SessionSource;
1400
+ environments: TurnEnvironmentSelection[];
1401
+ base_instructions?: string | null;
1402
+ user_instructions?: string | null;
1403
+ developer_instructions?: string | null;
1404
+ final_output_json_schema?: unknown;
1405
+ truncation_policy?: TruncationPolicy | null;
1406
+ dynamic_tools: DynamicToolSpec$1[];
1407
+ tools: ToolsConfig;
1408
+ };
1409
+ declare class TurnContext {
1410
+ readonly sub_id: string;
1411
+ readonly trace_id?: string;
1412
+ readonly cwd: string;
1413
+ readonly current_date?: string;
1414
+ readonly timezone?: string;
1415
+ readonly approval_policy: AskForApproval;
1416
+ readonly approvals_reviewer?: ApprovalsReviewer | null;
1417
+ readonly sandbox_policy: SandboxPolicy;
1418
+ readonly permission_profile?: PermissionProfile | null;
1419
+ readonly active_permission_profile?: ActivePermissionProfile | null;
1420
+ readonly windows_sandbox_level?: WindowsSandboxLevel | null;
1421
+ readonly model: string;
1422
+ readonly model_info: ModelInfo;
1423
+ readonly personality?: Personality | null;
1424
+ readonly collaboration_mode?: CollaborationMode | null;
1425
+ readonly effort?: ReasoningEffortConfig | null;
1426
+ readonly summary: ReasoningSummaryConfig;
1427
+ readonly service_tier?: ServiceTier | null;
1428
+ readonly session_source: SessionSource;
1429
+ readonly environments: TurnEnvironmentSelection[];
1430
+ readonly base_instructions?: string | null;
1431
+ readonly user_instructions?: string | null;
1432
+ readonly developer_instructions?: string | null;
1433
+ readonly final_output_json_schema?: unknown;
1434
+ readonly truncation_policy?: TruncationPolicy | null;
1435
+ readonly dynamic_tools: DynamicToolSpec$1[];
1436
+ readonly tools: ToolsConfig;
1437
+ readonly turn_timing_state: TurnTimingState;
1438
+ constructor(params: TurnContextParams);
1439
+ toTurnContextItem(): TurnContextItem;
1440
+ effectivePermissionProfile(): PermissionProfile;
1441
+ effectiveSandboxPolicy(): SandboxPolicy;
1442
+ model_context_window(): number | null;
1443
+ auto_compact_token_limit(): number | null;
1444
+ effectiveReasoningEffort(): ReasoningEffortConfig | null;
1445
+ }
1446
+
1447
+ type Prompt = {
1448
+ input: ResponseItem[];
1449
+ tools: ToolSpec[];
1450
+ parallel_tool_calls: boolean;
1451
+ base_instructions: BaseInstructions;
1452
+ };
1453
+ type ResponseEvent = {
1454
+ type: "created";
1455
+ } | {
1456
+ type: "output_text_delta";
1457
+ item_id?: string;
1458
+ delta: string;
1459
+ } | {
1460
+ type: "tool_call_input_delta";
1461
+ item_id: string;
1462
+ call_id?: string | null;
1463
+ delta: string;
1464
+ } | {
1465
+ type: "reasoning_summary_delta";
1466
+ delta: string;
1467
+ summary_index: number;
1468
+ } | {
1469
+ type: "reasoning_content_delta";
1470
+ delta: string;
1471
+ content_index: number;
1472
+ } | {
1473
+ type: "reasoning_summary_part_added";
1474
+ summary_index: number;
1475
+ } | {
1476
+ type: "output_item_added";
1477
+ item: ResponseItem;
1478
+ } | {
1479
+ type: "output_item_done";
1480
+ item: ResponseItem;
1481
+ } | {
1482
+ type: "server_model";
1483
+ model: string;
1484
+ } | {
1485
+ type: "model_verifications";
1486
+ model_verifications: unknown[];
1487
+ } | {
1488
+ type: "server_reasoning_included";
1489
+ reasoning_included: boolean;
1490
+ } | {
1491
+ type: "completed";
1492
+ response_id: string;
1493
+ token_usage?: TokenUsage | null;
1494
+ end_turn?: boolean | null;
1495
+ } | {
1496
+ type: "rate_limits";
1497
+ rate_limits: RateLimitSnapshot;
1498
+ } | {
1499
+ type: "models_etag";
1500
+ etag: string;
1501
+ };
1502
+ type ResponseStream = AsyncIterable<ResponseEvent> & {
1503
+ upstream_request_id?: string | null;
1504
+ };
1505
+ type TurnState = {
1506
+ get(): string | null;
1507
+ set(value: string): void;
1508
+ };
1509
+ type ResponsesApiRequest = {
1510
+ model: string;
1511
+ instructions: string;
1512
+ input: ResponseItem[];
1513
+ tools: unknown[];
1514
+ tool_choice: string;
1515
+ parallel_tool_calls: boolean;
1516
+ reasoning: unknown | null;
1517
+ store: boolean;
1518
+ stream: true;
1519
+ include: string[];
1520
+ service_tier?: string;
1521
+ prompt_cache_key?: string;
1522
+ text?: unknown;
1523
+ client_metadata?: Record<string, string>;
1524
+ };
1525
+ type ResponseCreateWsRequest = Omit<ResponsesApiRequest, "stream"> & {
1526
+ stream: true;
1527
+ previous_response_id?: string;
1528
+ generate?: boolean;
1529
+ };
1530
+ type ResponseProcessedWsRequest = {
1531
+ response_id: string;
1532
+ };
1533
+ type ResponsesWsRequest = ({
1534
+ type: "response.create";
1535
+ } & ResponseCreateWsRequest) | ({
1536
+ type: "response.processed";
1537
+ } & ResponseProcessedWsRequest);
1538
+
1539
+ type Compression = "none" | "zstd";
1540
+ type ResponsesOptions = {
1541
+ signal?: AbortSignal;
1542
+ thread_id?: string | null;
1543
+ session_id?: string | null;
1544
+ session_source?: SessionSource | string | null;
1545
+ extra_headers?: HeadersInit;
1546
+ compression?: Compression;
1547
+ turn_state?: TurnState | null;
1548
+ };
1549
+ type ResponsesClientInput = {
1550
+ api_key: string;
1551
+ runtime: ProviderRuntimeConfig;
1552
+ originator: string;
1553
+ user_agent: string;
1554
+ chatgpt_account_id?: string | null;
1555
+ fedramp?: boolean;
1556
+ fetch?: (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
1557
+ };
1558
+ declare class ResponsesClient {
1559
+ private readonly input;
1560
+ private readonly fetcher;
1561
+ constructor(input: ResponsesClientInput);
1562
+ stream_request(request: ResponsesApiRequest, options?: ResponsesOptions): Promise<ResponseStream>;
1563
+ streamRequest(request: ResponsesApiRequest, options?: ResponsesOptions): Promise<ResponseStream>;
1564
+ }
1565
+
1566
+ type FetchLike$1 = (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
1567
+ type WorkerWebSocket = WebSocket & {
1568
+ accept?: (options?: unknown) => void;
1569
+ binaryType?: BinaryType;
1570
+ };
1571
+ type ResponsesWebsocketClientInput = {
1572
+ api_key: string;
1573
+ runtime: ProviderRuntimeConfig;
1574
+ originator: string;
1575
+ user_agent: string;
1576
+ chatgpt_account_id?: string | null;
1577
+ fedramp?: boolean;
1578
+ fetch?: FetchLike$1;
1579
+ };
1580
+ declare class WsStream {
1581
+ private readonly socket;
1582
+ private readonly queued;
1583
+ private readonly waiters;
1584
+ private closed;
1585
+ constructor(socket: WorkerWebSocket);
1586
+ is_closed(): boolean;
1587
+ send(message: string): void;
1588
+ close(): void;
1589
+ next(timeoutMs?: number | null): Promise<MessageEvent | CloseEvent | ErrorEvent>;
1590
+ private push;
1591
+ }
1592
+ declare class ResponsesWebsocketConnection {
1593
+ private readonly input;
1594
+ private lock;
1595
+ private streamClosed;
1596
+ constructor(input: {
1597
+ stream: WsStream;
1598
+ idle_timeout_ms?: number | null;
1599
+ server_reasoning_included?: boolean;
1600
+ models_etag?: string | null;
1601
+ server_model?: string | null;
1602
+ });
1603
+ is_closed(): Promise<boolean>;
1604
+ send_response_processed(response_id: string): Promise<void>;
1605
+ stream_request(request: ResponsesWsRequest, connection_reused: boolean): Promise<ResponseStream>;
1606
+ close(): void;
1607
+ private initialEvents;
1608
+ private runWebsocketResponseStream;
1609
+ private withExclusiveStream;
1610
+ }
1611
+ declare class ResponsesWebsocketClient {
1612
+ private readonly input;
1613
+ private readonly fetcher;
1614
+ constructor(input: ResponsesWebsocketClientInput);
1615
+ connect(extra_headers?: HeadersInit, default_headers?: HeadersInit, turn_state?: TurnState | null): Promise<ResponsesWebsocketConnection>;
1616
+ }
1617
+
1618
+ type FetchLike = (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
1619
+ type CreateModelClientInput = {
1620
+ apiKey: string;
1621
+ baseUrl?: string;
1622
+ chatgptAccountId?: string | null;
1623
+ fedramp?: boolean;
1624
+ fetch?: FetchLike;
1625
+ provider?: ModelProvider;
1626
+ sessionId: string;
1627
+ threadId: ThreadId | string;
1628
+ installationId: string;
1629
+ includeTimingMetrics?: boolean;
1630
+ betaFeaturesHeader?: string | null;
1631
+ };
1632
+ type ModelClientSessionHandle = {
1633
+ prewarm_websocket(prompt: Prompt, options?: {
1634
+ signal?: AbortSignal;
1635
+ turn?: TurnContext;
1636
+ turn_metadata_header?: string | null;
1637
+ }): Promise<void>;
1638
+ send_response_processed(response_id: string): Promise<void>;
1639
+ stream(prompt: Prompt, options?: {
1640
+ signal?: AbortSignal;
1641
+ turn?: TurnContext;
1642
+ turn_metadata_header?: string | null;
1643
+ }): Promise<ResponseStream>;
1644
+ release(): void;
1645
+ };
1646
+ type ModelClient = {
1647
+ new_session(turn?: TurnContext): ModelClientSessionHandle;
1648
+ responses_websocket_enabled(): boolean;
1649
+ force_http_fallback(): boolean;
1650
+ };
1651
+ declare function createModelClient(input: CreateModelClientInput): ModelClient;
1652
+ type LastResponse = {
1653
+ response_id: string;
1654
+ items_added: ResponseItem[];
1655
+ };
1656
+ type WebsocketSession = {
1657
+ connection: ResponsesWebsocketConnection | null;
1658
+ last_request: ResponsesApiRequest | null;
1659
+ last_response: LastResponse | null;
1660
+ connection_reused: boolean;
1661
+ };
1662
+ declare class CodexModelClient implements ModelClient {
1663
+ private readonly provider;
1664
+ private readonly runtime;
1665
+ private readonly apiKey;
1666
+ private readonly chatgptAccountId;
1667
+ private readonly fedramp;
1668
+ private readonly fetcher?;
1669
+ private readonly sessionId;
1670
+ private readonly threadId;
1671
+ private readonly installationId;
1672
+ private readonly includeTimingMetrics;
1673
+ private readonly betaFeaturesHeader;
1674
+ private disableWebsockets;
1675
+ private windowGeneration;
1676
+ private cachedWebsocketSession;
1677
+ constructor(input: CreateModelClientInput);
1678
+ new_session(turn?: TurnContext): ModelClientSession;
1679
+ responses_websocket_enabled(): boolean;
1680
+ force_http_fallback(): boolean;
1681
+ set_window_generation(windowGeneration: number): void;
1682
+ advance_window_generation(): void;
1683
+ current_window_id(): string;
1684
+ stream_max_retries(): number;
1685
+ websocket_connect_timeout_ms(): number;
1686
+ take_cached_websocket_session(): WebsocketSession;
1687
+ store_cached_websocket_session(websocketSession: WebsocketSession): void;
1688
+ build_responses_request(prompt: Prompt, turn: TurnContext): ResponsesApiRequest;
1689
+ build_responses_options(turn: TurnContext, turnState: TurnState, turnMetadataHeader?: string | null): ResponsesOptions;
1690
+ build_websocket_headers(turn: TurnContext, turnState: TurnState, turnMetadataHeader?: string | null): Headers;
1691
+ build_ws_client_metadata(turn: TurnContext, turnMetadataHeader?: string | null): Record<string, string>;
1692
+ new_responses_client(): ResponsesClient;
1693
+ new_responses_websocket_client(): ResponsesWebsocketClient;
1694
+ private build_responses_headers;
1695
+ }
1696
+ declare class ModelClientSession {
1697
+ private readonly client;
1698
+ private readonly turn?;
1699
+ private websocketSession;
1700
+ private readonly turnState;
1701
+ private released;
1702
+ constructor(client: CodexModelClient, turn?: TurnContext | undefined, websocketSession?: WebsocketSession);
1703
+ prewarm_websocket(prompt: Prompt, options?: {
1704
+ signal?: AbortSignal;
1705
+ turn?: TurnContext;
1706
+ turn_metadata_header?: string | null;
1707
+ }): Promise<void>;
1708
+ send_response_processed(response_id: string): Promise<void>;
1709
+ stream(prompt: Prompt, options?: {
1710
+ signal?: AbortSignal;
1711
+ turn?: TurnContext;
1712
+ turn_metadata_header?: string | null;
1713
+ }): Promise<ResponseStream>;
1714
+ release(): void;
1715
+ private stream_responses_api;
1716
+ private stream_responses_websocket;
1717
+ private websocket_connection;
1718
+ private codex_client;
1719
+ private prepare_websocket_request;
1720
+ private get_incremental_items;
1721
+ private reset_websocket_session;
1722
+ private try_switch_fallback_transport;
1723
+ }
1724
+
1725
+ type TotalTokenUsageBreakdown = {
1726
+ last_api_response_total_tokens: number;
1727
+ all_history_items_model_visible_bytes: number;
1728
+ estimated_tokens_of_items_added_since_last_successful_api_response: number;
1729
+ estimated_bytes_of_items_added_since_last_successful_api_response: number;
1730
+ };
1731
+ declare class ContextManager {
1732
+ private items;
1733
+ private history_version;
1734
+ private token_info_value;
1735
+ private reference_context_item_value;
1736
+ static new(): ContextManager;
1737
+ clone(): ContextManager;
1738
+ token_info(): TokenUsageInfo | null;
1739
+ tokenInfo(): TokenUsageInfo | null;
1740
+ set_token_info(info: TokenUsageInfo | null): void;
1741
+ setTokenInfo(info: TokenUsageInfo | null): void;
1742
+ set_token_usage_full(contextWindow: number): void;
1743
+ setTokenUsageFull(contextWindow: number): void;
1744
+ recordItems(items: Iterable<ResponseItem>, policy?: TruncationPolicy | null): void;
1745
+ record_items(items: Iterable<ResponseItem>, policy?: TruncationPolicy | null): void;
1746
+ replace(items: ResponseItem[]): void;
1747
+ rawItems(): ResponseItem[];
1748
+ raw_items(): ResponseItem[];
1749
+ forPrompt(inputModalities?: readonly string[] | null): ResponseItem[];
1750
+ for_prompt(inputModalities?: readonly string[] | null): ResponseItem[];
1751
+ historyVersion(): number;
1752
+ history_version_value(): number;
1753
+ estimate_token_count_with_base_instructions(baseInstructions: BaseInstructions): number;
1754
+ setReferenceContextItem(item: TurnContextItem | null): void;
1755
+ set_reference_context_item(item: TurnContextItem | null): void;
1756
+ referenceContextItem(): TurnContextItem | null;
1757
+ reference_context_item(): TurnContextItem | null;
1758
+ dropLastNUserTurns(numTurns: number): void;
1759
+ drop_last_n_user_turns(numTurns: number): void;
1760
+ removeFirstItem(): void;
1761
+ remove_first_item(): void;
1762
+ removeLastItem(): boolean;
1763
+ remove_last_item(): boolean;
1764
+ replaceLastTurnImages(placeholder: string): boolean;
1765
+ replace_last_turn_images(placeholder: string): boolean;
1766
+ updateTokenInfo(usage: TokenUsage, modelContextWindow?: number | null): void;
1767
+ update_token_info(usage: TokenUsage, modelContextWindow?: number | null): void;
1768
+ getTotalTokenUsage(serverReasoningIncluded?: boolean): number;
1769
+ get_total_token_usage(serverReasoningIncluded?: boolean): number;
1770
+ getTotalTokenUsageBreakdown(): TotalTokenUsageBreakdown;
1771
+ get_total_token_usage_breakdown(): TotalTokenUsageBreakdown;
1772
+ private getNonLastReasoningItemsTokens;
1773
+ private itemsAfterLastModelGeneratedItem;
1774
+ private trim_pre_turn_context_updates;
1775
+ }
1776
+
1777
+ type RuntimeSession = {
1778
+ abortController: AbortController | null;
1779
+ runPromise: Promise<unknown> | null;
1780
+ session: Session;
1781
+ };
1782
+ type ProcessorEmit<Context> = (threadId: ThreadId, event: AppServerEvent, context?: Context) => Promise<void>;
1783
+ type ProcessorCreateSession<Context> = (threadId: ThreadId, params: ThreadStartParams | ThreadResumeParams | TurnStartParams | ThreadCompactStartParams, context?: Context, submission?: Submission) => Promise<Session>;
1784
+
1785
+ type McpRequestProcessorOptions<Context> = {
1786
+ mcpConnectionManager?: McpConnectionManager | null;
1787
+ mcpServerOauthLogin?: (input: {
1788
+ context?: Context;
1789
+ params: McpServerOauthLoginParams;
1790
+ }) => McpServerOauthLoginResponse | Promise<McpServerOauthLoginResponse>;
1791
+ reloadMcpServers?: (input: {
1792
+ context?: Context;
1793
+ }) => void | Promise<void>;
1794
+ runInBackground?: (promise: Promise<unknown>, context: {
1795
+ context?: Context;
1796
+ }) => void;
1797
+ store: ThreadStore;
1798
+ };
1799
+ declare class McpRequestProcessor<Context> {
1800
+ private readonly options;
1801
+ constructor(options: McpRequestProcessorOptions<Context>);
1802
+ mcpServerRefresh(_params: undefined, context?: Context): Promise<McpServerRefreshResponse>;
1803
+ mcpServerStatusList(params: ListMcpServerStatusParams, context?: Context, request?: CodexAppServerRequestContext): Promise<ListMcpServerStatusResponse | CodexAppServerDeferredResponse>;
1804
+ private mcpServerStatusListResponse;
1805
+ mcpResourceRead(params: McpResourceReadParams$1, context?: Context, request?: CodexAppServerRequestContext): Promise<McpResourceReadResponse$1 | CodexAppServerDeferredResponse>;
1806
+ private mcpResourceReadResponse;
1807
+ mcpServerToolCall(params: McpServerToolCallParams$1, context?: Context, request?: CodexAppServerRequestContext): Promise<McpServerToolCallResponse$1 | CodexAppServerDeferredResponse>;
1808
+ private mcpServerToolCallResponse;
1809
+ mcpServerOauthLogin(params: McpServerOauthLoginParams, context?: Context): Promise<McpServerOauthLoginResponse>;
1810
+ private manager;
1811
+ private runDeferred;
1812
+ private loadThread;
1813
+ }
1814
+
1815
+ type CodexSessionTaskRunnerCreateModelClientInput<Context> = {
1816
+ context?: Context;
1817
+ session: Session;
1818
+ threadId: ThreadId;
1819
+ };
1820
+ type CodexSessionTaskRunnerOptions<Context> = {
1821
+ createModelClient: (input: CodexSessionTaskRunnerCreateModelClientInput<Context>) => ModelClient | Promise<ModelClient>;
1822
+ modelClientCacheKey?: (input: CodexSessionTaskRunnerCreateModelClientInput<Context>) => string | null | undefined;
1823
+ onRuntimeError?: (error: unknown, context: {
1824
+ context?: Context;
1825
+ threadId?: ThreadId;
1826
+ }) => void;
1827
+ runInBackground?: (promise: Promise<unknown>, context: {
1828
+ context?: Context;
1829
+ threadId: ThreadId;
1830
+ }) => void;
1831
+ store: ThreadStore;
1832
+ };
1833
+ declare class CodexSessionTaskRunner<Context> {
1834
+ private readonly options;
1835
+ private readonly modelClients;
1836
+ constructor(options: CodexSessionTaskRunnerOptions<Context>);
1837
+ startRegularTask(input: {
1838
+ context?: Context;
1839
+ items: UserInput[];
1840
+ params: TurnStartParams;
1841
+ runtimeSession: RuntimeSession;
1842
+ submission: Submission;
1843
+ threadId: ThreadId;
1844
+ }): Promise<TurnContext>;
1845
+ startCompactTask(input: {
1846
+ context?: Context;
1847
+ params: ThreadCompactStartParams;
1848
+ runtimeSession: RuntimeSession;
1849
+ submission: Submission;
1850
+ threadId: ThreadId;
1851
+ }): Promise<TurnContext>;
1852
+ private spawnTask;
1853
+ private modelClient;
1854
+ }
1855
+
1856
+ type ThreadRequestProcessorOptions<Context> = {
1857
+ buildCreateThreadParams?: (input: {
1858
+ context?: Context;
1859
+ params: ThreadStartParams;
1860
+ threadId: ThreadId;
1861
+ }) => CreateThreadParams | Promise<CreateThreadParams>;
1862
+ createSession: ProcessorCreateSession<Context>;
1863
+ emit: ProcessorEmit<Context>;
1864
+ resolveDynamicTools?: (input: {
1865
+ context?: Context;
1866
+ params: ThreadStartParams;
1867
+ threadId: ThreadId;
1868
+ }) => DynamicToolSpec$1[] | Promise<DynamicToolSpec$1[]>;
1869
+ sessions: Map<ThreadId, RuntimeSession>;
1870
+ store: ThreadStore;
1871
+ taskRunner: CodexSessionTaskRunner<Context>;
1872
+ };
1873
+ declare class ThreadRequestProcessor<Context> {
1874
+ private readonly options;
1875
+ constructor(options: ThreadRequestProcessorOptions<Context>);
1876
+ threadStart(params: ThreadStartParams, context?: Context): Promise<ThreadStartResponse>;
1877
+ threadResume(params: ThreadResumeParams, context?: Context): Promise<ThreadResumeResponse>;
1878
+ threadCompactStart(params: ThreadCompactStartParams, context?: Context): Promise<ThreadCompactStartResponse>;
1879
+ threadList(params: ThreadListParams): Promise<ThreadListResponse>;
1880
+ threadRead(params: ThreadReadParams): Promise<ThreadReadResponse>;
1881
+ threadNameSet(params: ThreadSetNameParams, context?: Context): Promise<ThreadSetNameResponse>;
1882
+ threadArchive(params: ThreadArchiveParams, context?: Context): Promise<ThreadArchiveResponse>;
1883
+ threadUnarchive(params: ThreadUnarchiveParams, context?: Context): Promise<ThreadUnarchiveResponse>;
1884
+ threadMetadataUpdate(params: ThreadMetadataUpdateParams): Promise<ThreadMetadataUpdateResponse>;
1885
+ private readThreadResponse;
1886
+ private readThreadResponseWithHistory;
1887
+ private createThreadParams;
1888
+ private ensureLiveThread;
1889
+ }
1890
+
1891
+ type TurnRequestProcessorOptions<Context> = {
1892
+ createSession: ProcessorCreateSession<Context>;
1893
+ onRuntimeError?: (error: unknown, context: {
1894
+ context?: Context;
1895
+ threadId?: ThreadId;
1896
+ }) => void;
1897
+ sessions: Map<ThreadId, RuntimeSession>;
1898
+ taskRunner: CodexSessionTaskRunner<Context>;
1899
+ };
1900
+ declare class TurnRequestProcessor<Context> {
1901
+ private readonly options;
1902
+ constructor(options: TurnRequestProcessorOptions<Context>);
1903
+ turnStart(params: TurnStartParams, context?: Context): Promise<TurnStartResponse>;
1904
+ turnSteer(params: TurnSteerParams, context?: Context): Promise<TurnSteerResponse>;
1905
+ turnInterrupt(params: TurnInterruptParams): Promise<TurnInterruptResponse>;
1906
+ private sessionForTurn;
1907
+ }
1908
+
1909
+ type CodexAppServerRuntimeContext = unknown;
1910
+ type CodexAppServerEventSink<Context = CodexAppServerRuntimeContext> = (event: AppServerEvent$1, context: {
1911
+ context?: Context;
1912
+ threadId: ThreadId;
1913
+ }) => Promise<void> | void;
1914
+ type CodexAppServerOutgoingSink<Context = CodexAppServerRuntimeContext> = (message: OutgoingMessage, context: {
1915
+ connectionIds?: ConnectionId[];
1916
+ context?: Context;
1917
+ threadId?: ThreadId;
1918
+ }) => Promise<void> | void;
1919
+ type CodexAppServerRuntimeOptions<Context = CodexAppServerRuntimeContext> = {
1920
+ buildCreateThreadParams?: (input: {
1921
+ context?: Context;
1922
+ params: ThreadStartParams;
1923
+ threadId: ThreadId;
1924
+ }) => CreateThreadParams | Promise<CreateThreadParams>;
1925
+ buildSessionConfiguration?: (input: {
1926
+ context?: Context;
1927
+ params: ThreadStartParams | ThreadResumeParams | TurnStartParams | ThreadCompactStartParams;
1928
+ thread: Awaited<ReturnType<ThreadStore["readThread"]>>;
1929
+ }) => Partial<SessionConfiguration> | Promise<Partial<SessionConfiguration>>;
1930
+ createModelClient: (input: {
1931
+ context?: Context;
1932
+ session: Session;
1933
+ threadId: ThreadId;
1934
+ }) => ModelClient | Promise<ModelClient>;
1935
+ modelClientCacheKey?: (input: {
1936
+ context?: Context;
1937
+ session: Session;
1938
+ threadId: ThreadId;
1939
+ }) => string | null | undefined;
1940
+ mcpConnectionManager?: McpConnectionManager | null;
1941
+ mcpServerOauthLogin?: (input: {
1942
+ context?: Context;
1943
+ params: McpServerOauthLoginParams;
1944
+ }) => McpServerOauthLoginResponse | Promise<McpServerOauthLoginResponse>;
1945
+ reloadMcpServers?: (input: {
1946
+ context?: Context;
1947
+ }) => void | Promise<void>;
1948
+ createSession?: (input: {
1949
+ context?: Context;
1950
+ eventSink: (event: Event) => void;
1951
+ params: ThreadStartParams | ThreadResumeParams | TurnStartParams | ThreadCompactStartParams;
1952
+ submission?: Submission;
1953
+ threadId: ThreadId;
1954
+ }) => Session | Promise<Session>;
1955
+ eventSink?: CodexAppServerEventSink<Context>;
1956
+ onRuntimeError?: (error: unknown, context: {
1957
+ context?: Context;
1958
+ threadId?: ThreadId;
1959
+ }) => void;
1960
+ runInBackground?: (promise: Promise<unknown>, context: {
1961
+ context?: Context;
1962
+ threadId: ThreadId;
1963
+ }) => void;
1964
+ runConnectionBackground?: (promise: Promise<unknown>, context: {
1965
+ context?: Context;
1966
+ }) => void;
1967
+ sendOutgoingMessage?: CodexAppServerEventSink<Context>;
1968
+ sendOutgoingTransportMessage?: CodexAppServerOutgoingSink<Context>;
1969
+ resolveDynamicTools?: (input: {
1970
+ context?: Context;
1971
+ params: ThreadStartParams;
1972
+ threadId: ThreadId;
1973
+ }) => DynamicToolSpec$1[] | Promise<DynamicToolSpec$1[]>;
1974
+ store: ThreadStore;
1975
+ };
1976
+ type CodexAppServerRuntime<Context = CodexAppServerRuntimeContext> = {
1977
+ connectionClosed(connectionId: number): Promise<void>;
1978
+ connectionInitialized(connectionId: number): void;
1979
+ createMessageProcessor(input: {
1980
+ connectionId: ConnectionId;
1981
+ initialize?: (params: InitializeParams, context?: Context, session?: CodexAppServerConnectionSessionState) => Promise<InitializeResponse>;
1982
+ initializeResponse?: InitializeResponse | (() => InitializeResponse);
1983
+ session?: CodexAppServerConnectionSessionState;
1984
+ }): CodexAppServerMessageProcessor<Context>;
1985
+ methodHandlers: CodexAppServerMethodHandlers<Context>;
1986
+ rejectServerRequest(params: {
1987
+ error: JSONRPCErrorError$1;
1988
+ requestId: string | number;
1989
+ threadId: ThreadId | string;
1990
+ }, context?: Context): Promise<void>;
1991
+ resolveServerRequest(params: {
1992
+ requestId: string | number;
1993
+ result: Result$1;
1994
+ threadId: ThreadId | string;
1995
+ }, context?: Context): Promise<void>;
1996
+ };
1997
+ declare function createCodexAppServerRuntime<Context = CodexAppServerRuntimeContext>(options: CodexAppServerRuntimeOptions<Context>): CodexAppServerRuntime<Context>;
1998
+
1999
+ export { type DynamicToolSpec as AppServerDynamicToolSpec, AppServerEvent$1 as AppServerEvent, ClientRequest, CodexAppServerConnectionSessionState, type CodexAppServerEventSink, CodexAppServerMessageProcessor, type CodexAppServerMessageProcessorOptions, type CodexAppServerMethodHandlers, type CodexAppServerOutgoingSink, type CodexAppServerRequestContext, CodexAppServerRequestError, type CodexAppServerRuntime, type CodexAppServerRuntimeContext, type CodexAppServerRuntimeOptions, type ConnectionId, type ConnectionOrigin, ConnectionRpcGate, ConnectionRpcGateClosedError, type CreateModelClientInput, DynamicToolSpec$1 as DynamicToolSpec, EmptyMcpConnectionManager, type Event, EventMsg, type JSONRPCError, JSONRPCErrorError$1 as JSONRPCErrorError, type JSONRPCMessage, LiveThread, McpRequestProcessor, type ModelClient, ModelClientSession, type ModelClientSessionHandle, OutgoingMessageSender, type RequestContext, RequestId, RequestSerializationQueues, type ResponseEvent, type ResponseStream, ResponsesClient, ResponsesWebsocketClient, ResponsesWebsocketConnection, Result$1 as Result, type RuntimeSession, ServerNotification, ServerRequest, StaticMcpConnectionManager, ThreadId, ThreadMemoryMode, ThreadRequestProcessor, ThreadScopedOutgoingMessageSender, ThreadStore, TurnRequestProcessor, TurnStartParams, TurnStartResponse, clientRequestExperimentalReason, clientRequestId, clientRequestMethod, clientRequestSerializationScope, createCodexAppServerRuntime, createModelClient, jsonRpcInternalError, jsonRpcInvalidRequestError, jsonRpcParseError, parseClientTransportPayload, parseServerTransportPayload, queuedOutgoingMessage, serializeJsonRpcError, serializeJsonRpcResponse, serializeOutgoingMessage };