ai-sdk-provider-codex-cli 1.3.1 → 2.0.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/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ProviderV3, LanguageModelV3, UnsupportedFunctionalityError } from '@ai-sdk/provider';
1
+ import { ProviderV4, LanguageModelV4, UnsupportedFunctionalityError } from '@ai-sdk/provider';
2
2
  import { ZodType } from 'zod';
3
3
 
4
4
  /**
@@ -123,12 +123,24 @@ interface JsonRpcNotification {
123
123
  params?: Record<string, unknown>;
124
124
  }
125
125
  type JsonRpcMessage = JsonRpcRequest | JsonRpcResponse | JsonRpcErrorResponse | JsonRpcNotification;
126
+ /**
127
+ * Vendored subset of the codex 0.142.5 `Model` wire type (renamed upstream
128
+ * from `ModelInfo`), plus fields only pre-0.142 servers return.
129
+ */
126
130
  interface ModelInfo {
127
131
  id: string;
128
- name?: string | null;
129
- modelProvider?: string | null;
132
+ /** Underlying model slug (codex >= 0.142). */
133
+ model?: string;
134
+ /** Display name; replaces the pre-0.142 `name` field (codex >= 0.142). */
135
+ displayName?: string;
130
136
  description?: string | null;
137
+ /** Whether the model is hidden from the default picker list (codex >= 0.142). */
138
+ hidden?: boolean;
131
139
  isDefault?: boolean | null;
140
+ /** External contract: only pre-0.142 servers return `name`. */
141
+ name?: string | null;
142
+ /** External contract: only pre-0.142 servers return `modelProvider`. */
143
+ modelProvider?: string | null;
132
144
  [k: string]: unknown;
133
145
  }
134
146
  interface Thread {
@@ -149,8 +161,12 @@ interface ThreadStartParams {
149
161
  developerInstructions?: string | null;
150
162
  personality?: 'none' | 'friendly' | 'pragmatic' | null;
151
163
  ephemeral?: boolean | null;
152
- experimentalRawEvents: boolean;
153
- persistExtendedHistory: boolean;
164
+ experimentalRawEvents?: boolean;
165
+ /**
166
+ * External contract: consumed by pre-0.142 servers only. Codex 0.142.5
167
+ * removed this param and ignores it when sent (verified empirically).
168
+ */
169
+ persistExtendedHistory?: boolean;
154
170
  }
155
171
  interface ThreadStartResponse {
156
172
  thread: Thread;
@@ -174,7 +190,11 @@ interface ThreadResumeParams {
174
190
  baseInstructions?: string | null;
175
191
  developerInstructions?: string | null;
176
192
  personality?: 'none' | 'friendly' | 'pragmatic' | null;
177
- persistExtendedHistory: boolean;
193
+ /**
194
+ * External contract: consumed by pre-0.142 servers only. Codex 0.142.5
195
+ * removed this param and ignores it when sent.
196
+ */
197
+ persistExtendedHistory?: boolean;
178
198
  }
179
199
  type ThreadResumeResponse = ThreadStartResponse;
180
200
  type UserInput = {
@@ -183,11 +203,16 @@ type UserInput = {
183
203
  text_elements: unknown[];
184
204
  } | {
185
205
  type: 'image';
186
- url?: string;
206
+ url: string;
207
+ /** Optional rendering detail hint (codex >= 0.142). */
208
+ detail?: 'auto' | 'low' | 'high' | 'original';
209
+ /** External contract: pre-0.142 servers read `imageUrl`; codex 0.142.5 only reads `url`. */
187
210
  imageUrl?: string;
188
211
  } | {
189
212
  type: 'localImage';
190
213
  path: string;
214
+ /** Optional rendering detail hint (codex >= 0.142). */
215
+ detail?: 'auto' | 'low' | 'high' | 'original';
191
216
  } | {
192
217
  type: 'skill';
193
218
  name: string;
@@ -204,13 +229,18 @@ interface TurnStartParams {
204
229
  approvalPolicy?: unknown;
205
230
  sandboxPolicy?: unknown;
206
231
  model?: string | null;
207
- effort?: 'none' | 'minimal' | 'low' | 'medium' | 'high' | 'xhigh' | null;
232
+ /**
233
+ * Reasoning effort. Open-ended string upstream (`ReasoningEffort = string`
234
+ * in codex 0.142.5); known values include 'none', 'minimal', 'low',
235
+ * 'medium', 'high', 'xhigh', and 'ultra'.
236
+ */
237
+ effort?: string | null;
208
238
  summary?: 'auto' | 'concise' | 'detailed' | 'none' | null;
209
239
  personality?: 'none' | 'friendly' | 'pragmatic' | null;
210
240
  outputSchema?: unknown;
211
241
  collaborationMode?: unknown;
212
242
  }
213
- type CodexErrorInfo = 'contextWindowExceeded' | 'usageLimitExceeded' | 'serverOverloaded' | 'internalServerError' | 'unauthorized' | 'badRequest' | 'threadRollbackFailed' | 'sandboxError' | 'other' | {
243
+ type CodexErrorInfo = 'contextWindowExceeded' | 'usageLimitExceeded' | 'serverOverloaded' | 'cyberPolicy' | 'internalServerError' | 'unauthorized' | 'badRequest' | 'threadRollbackFailed' | 'sandboxError' | 'other' | {
214
244
  httpConnectionFailed: {
215
245
  httpStatusCode: number | null;
216
246
  };
@@ -226,6 +256,10 @@ type CodexErrorInfo = 'contextWindowExceeded' | 'usageLimitExceeded' | 'serverOv
226
256
  responseTooManyFailedAttempts: {
227
257
  httpStatusCode: number | null;
228
258
  };
259
+ } | {
260
+ activeTurnNotSteerable: {
261
+ turnKind: 'review' | 'compact';
262
+ };
229
263
  };
230
264
  interface TurnError {
231
265
  message: string;
@@ -236,6 +270,8 @@ type TurnStatus = 'completed' | 'interrupted' | 'failed' | 'inProgress';
236
270
  type UserMessageItem = {
237
271
  type: 'userMessage';
238
272
  id: string;
273
+ /** Client-supplied message id echoed back by the server (codex >= 0.142). */
274
+ clientId?: string | null;
239
275
  content: UserInput[];
240
276
  };
241
277
  type AgentMessageItem = {
@@ -243,6 +279,8 @@ type AgentMessageItem = {
243
279
  id: string;
244
280
  text: string;
245
281
  phase: string | null;
282
+ /** Memory citation metadata (codex >= 0.142). */
283
+ memoryCitation?: unknown | null;
246
284
  };
247
285
  type PlanItem = {
248
286
  type: 'plan';
@@ -261,6 +299,8 @@ type CommandExecutionItem = {
261
299
  command: string;
262
300
  cwd: string;
263
301
  processId: string | null;
302
+ /** 'agent' | 'userShell' | 'unifiedExecStartup' | 'unifiedExecInteraction' (codex >= 0.142). */
303
+ source?: string;
264
304
  status: string;
265
305
  commandActions: unknown[];
266
306
  aggregatedOutput: string | null;
@@ -280,6 +320,10 @@ type McpToolCallItem = {
280
320
  tool: string;
281
321
  status: string;
282
322
  arguments: unknown;
323
+ /** MCP app context; replaces `mcpAppResourceUri` (codex >= 0.142). */
324
+ appContext?: unknown | null;
325
+ mcpAppResourceUri?: string;
326
+ pluginId?: string | null;
283
327
  result: unknown | null;
284
328
  error: unknown | null;
285
329
  durationMs: number | null;
@@ -292,6 +336,10 @@ type CollabAgentToolCallItem = {
292
336
  senderThreadId: string;
293
337
  receiverThreadIds: string[];
294
338
  prompt: string | null;
339
+ /** Model requested for the spawned agent, when applicable (codex >= 0.142). */
340
+ model?: string | null;
341
+ /** Reasoning effort requested for the spawned agent, when applicable (codex >= 0.142). */
342
+ reasoningEffort?: string | null;
295
343
  agentsStates: Record<string, unknown>;
296
344
  };
297
345
  type WebSearchItem = {
@@ -319,12 +367,58 @@ type ContextCompactionItem = {
319
367
  type: 'contextCompaction';
320
368
  id: string;
321
369
  };
322
- type ThreadItem = UserMessageItem | AgentMessageItem | PlanItem | ReasoningItem | CommandExecutionItem | FileChangeItem | McpToolCallItem | CollabAgentToolCallItem | WebSearchItem | ImageViewItem | EnteredReviewModeItem | ExitedReviewModeItem | ContextCompactionItem;
370
+ /** codex >= 0.142. */
371
+ type HookPromptItem = {
372
+ type: 'hookPrompt';
373
+ id: string;
374
+ fragments: unknown[];
375
+ };
376
+ /** SDK-registered dynamic tool call surfaced as a thread item (codex >= 0.142). */
377
+ type DynamicToolCallItem = {
378
+ type: 'dynamicToolCall';
379
+ id: string;
380
+ namespace: string | null;
381
+ tool: string;
382
+ arguments: unknown;
383
+ status: string;
384
+ contentItems: unknown[] | null;
385
+ success: boolean | null;
386
+ durationMs: number | null;
387
+ };
388
+ /** codex >= 0.142. */
389
+ type SubAgentActivityItem = {
390
+ type: 'subAgentActivity';
391
+ id: string;
392
+ kind: string;
393
+ agentThreadId: string;
394
+ agentPath: string;
395
+ };
396
+ /** codex >= 0.142. */
397
+ type SleepItem = {
398
+ type: 'sleep';
399
+ id: string;
400
+ durationMs: number;
401
+ };
402
+ /** codex >= 0.142. */
403
+ type ImageGenerationItem = {
404
+ type: 'imageGeneration';
405
+ id: string;
406
+ status: string;
407
+ revisedPrompt: string | null;
408
+ result: string;
409
+ savedPath?: string;
410
+ };
411
+ type ThreadItem = UserMessageItem | AgentMessageItem | PlanItem | ReasoningItem | CommandExecutionItem | FileChangeItem | McpToolCallItem | DynamicToolCallItem | CollabAgentToolCallItem | HookPromptItem | SubAgentActivityItem | SleepItem | ImageGenerationItem | WebSearchItem | ImageViewItem | EnteredReviewModeItem | ExitedReviewModeItem | ContextCompactionItem;
323
412
  interface Turn {
324
413
  id: string;
325
414
  items: ThreadItem[];
415
+ /** 'notLoaded' | 'summary' | 'full' (codex >= 0.142). */
416
+ itemsView?: string;
326
417
  status: TurnStatus;
327
418
  error: TurnError | null;
419
+ startedAt?: number | null;
420
+ completedAt?: number | null;
421
+ durationMs?: number | null;
328
422
  }
329
423
  interface TurnStartResponse {
330
424
  turn: Turn;
@@ -349,11 +443,15 @@ interface ItemStartedNotification {
349
443
  item: ThreadItem;
350
444
  threadId: string;
351
445
  turnId: string;
446
+ /** Unix timestamp (ms) when this item lifecycle started (codex >= 0.142). */
447
+ startedAtMs?: number;
352
448
  }
353
449
  interface ItemCompletedNotification {
354
450
  item: ThreadItem;
355
451
  threadId: string;
356
452
  turnId: string;
453
+ /** Unix timestamp (ms) when this item lifecycle completed (codex >= 0.142). */
454
+ completedAtMs?: number;
357
455
  }
358
456
  interface ErrorNotification {
359
457
  error: TurnError;
@@ -366,35 +464,59 @@ interface CommandExecutionRequestApprovalParams {
366
464
  threadId: string;
367
465
  turnId: string;
368
466
  itemId: string;
467
+ /** Unix timestamp (ms) when this approval request started (codex >= 0.142). */
468
+ startedAtMs?: number;
369
469
  approvalId?: string | null;
470
+ /** Environment in which the command will run (codex >= 0.142). */
471
+ environmentId?: string | null;
370
472
  reason?: string | null;
371
473
  networkApprovalContext?: unknown | null;
372
474
  command?: string | null;
373
475
  cwd?: string | null;
374
476
  commandActions?: unknown[] | null;
477
+ /** Additional permissions requested for this command (codex >= 0.142). */
478
+ additionalPermissions?: unknown | null;
375
479
  proposedExecpolicyAmendment?: unknown | null;
480
+ /** Proposed network policy amendments for future requests (codex >= 0.142). */
481
+ proposedNetworkPolicyAmendments?: unknown[] | null;
482
+ /** Ordered decisions the client may present for this prompt (codex >= 0.142). */
483
+ availableDecisions?: unknown[] | null;
376
484
  }
377
485
  interface CommandExecutionRequestApprovalResponse {
378
486
  decision: 'accept' | 'acceptForSession' | 'decline' | 'cancel' | {
379
487
  acceptWithExecpolicyAmendment: {
380
488
  execpolicy_amendment: unknown;
381
489
  };
490
+ } | {
491
+ applyNetworkPolicyAmendment: {
492
+ network_policy_amendment: unknown;
493
+ };
382
494
  };
383
495
  }
384
496
  interface FileChangeRequestApprovalParams {
385
497
  threadId: string;
386
498
  turnId: string;
387
499
  itemId: string;
500
+ /** Unix timestamp (ms) when this approval request started (codex >= 0.142). */
501
+ startedAtMs?: number;
388
502
  reason?: string | null;
389
503
  grantRoot?: string | null;
390
504
  }
391
505
  interface FileChangeRequestApprovalResponse {
392
506
  decision: 'accept' | 'acceptForSession' | 'decline' | 'cancel';
393
507
  }
508
+ /**
509
+ * External contract: `skill/requestApproval` was removed from the codex
510
+ * 0.142.5 server-request surface; only pre-0.142 servers send it.
511
+ */
394
512
  interface SkillRequestApprovalParams {
395
513
  itemId: string;
396
514
  skillName: string;
397
515
  }
516
+ /**
517
+ * External contract: `skill/requestApproval` was removed from the codex
518
+ * 0.142.5 server-request surface; only pre-0.142 servers send it.
519
+ */
398
520
  interface SkillRequestApprovalResponse {
399
521
  decision: 'approve' | 'decline';
400
522
  }
@@ -403,6 +525,8 @@ interface ToolRequestUserInputParams {
403
525
  turnId: string;
404
526
  itemId: string;
405
527
  questions: unknown[];
528
+ /** Auto-resolution deadline in milliseconds, when set (codex >= 0.142). */
529
+ autoResolutionMs?: number | null;
406
530
  }
407
531
  interface ToolRequestUserInputResponse {
408
532
  answers: Record<string, unknown>;
@@ -413,7 +537,10 @@ interface McpServerElicitationRequestParams {
413
537
  /** Nullable: the elicitation may arrive outside of an active turn. */
414
538
  turnId?: string | null;
415
539
  serverName: string;
416
- /** 'form' requests carry message/requestedSchema; 'url' requests carry url/elicitationId. */
540
+ /**
541
+ * 'form' and 'openai/form' (codex >= 0.142) requests carry
542
+ * message/requestedSchema; 'url' requests carry url/elicitationId.
543
+ */
417
544
  mode?: string;
418
545
  message?: string;
419
546
  requestedSchema?: unknown;
@@ -429,11 +556,15 @@ interface McpServerElicitationRequestResponse {
429
556
  action: McpServerElicitationAction;
430
557
  /** Structured user input for accepted elicitations; null for decline/cancel. */
431
558
  content?: Record<string, unknown> | null;
559
+ /** Optional client metadata for form-mode action handling (codex >= 0.142). */
560
+ _meta?: Record<string, unknown> | null;
432
561
  }
433
562
  interface DynamicToolCallParams {
434
563
  threadId: string;
435
564
  turnId: string;
436
565
  callId: string;
566
+ /** Dynamic tool namespace (codex >= 0.142). */
567
+ namespace?: string | null;
437
568
  tool: string;
438
569
  arguments: unknown;
439
570
  }
@@ -442,6 +573,7 @@ interface DynamicToolCallResponse {
442
573
  success: boolean;
443
574
  }
444
575
  interface ChatgptAuthTokensRefreshParams {
576
+ /** Codex 0.142.5 only sends 'unauthorized'; kept open for forward compat. */
445
577
  reason: string;
446
578
  previousAccountId?: string | null;
447
579
  }
@@ -682,10 +814,10 @@ interface CodexAppServerProviderOptions {
682
814
  onSessionCreated?: (session: CodexAppServerSession) => void | Promise<void>;
683
815
  }
684
816
 
685
- interface CodexExecProvider extends ProviderV3 {
686
- (modelId: CodexModelId, settings?: CodexExecSettings): LanguageModelV3;
687
- languageModel(modelId: CodexModelId, settings?: CodexExecSettings): LanguageModelV3;
688
- chat(modelId: CodexModelId, settings?: CodexExecSettings): LanguageModelV3;
817
+ interface CodexExecProvider extends ProviderV4 {
818
+ (modelId: CodexModelId, settings?: CodexExecSettings): LanguageModelV4;
819
+ languageModel(modelId: CodexModelId, settings?: CodexExecSettings): LanguageModelV4;
820
+ chat(modelId: CodexModelId, settings?: CodexExecSettings): LanguageModelV4;
689
821
  embeddingModel(modelId: string): never;
690
822
  imageModel(modelId: string): never;
691
823
  }
@@ -702,10 +834,10 @@ interface CodexAppServerModelListResult {
702
834
  *
703
835
  * Use this via `createCodexAppServer()` or the default `codexAppServer` export.
704
836
  */
705
- interface CodexAppServerProvider extends ProviderV3 {
706
- (modelId: CodexModelId, settings?: CodexAppServerSettings): LanguageModelV3;
707
- languageModel(modelId: CodexModelId, settings?: CodexAppServerSettings): LanguageModelV3;
708
- chat(modelId: CodexModelId, settings?: CodexAppServerSettings): LanguageModelV3;
837
+ interface CodexAppServerProvider extends ProviderV4 {
838
+ (modelId: CodexModelId, settings?: CodexAppServerSettings): LanguageModelV4;
839
+ languageModel(modelId: CodexModelId, settings?: CodexAppServerSettings): LanguageModelV4;
840
+ chat(modelId: CodexModelId, settings?: CodexAppServerSettings): LanguageModelV4;
709
841
  embeddingModel(modelId: string): never;
710
842
  imageModel(modelId: string): never;
711
843
  close(): Promise<void>;
@@ -722,7 +854,7 @@ interface CodexAppServerProvider extends ProviderV3 {
722
854
  * @example
723
855
  * ```ts
724
856
  * const provider = createCodexAppServer({
725
- * defaultSettings: { minCodexVersion: '0.144.0' },
857
+ * defaultSettings: { minCodexVersion: '0.142.5' },
726
858
  * });
727
859
  *
728
860
  * try {
@@ -756,13 +888,10 @@ interface ExecLanguageModelOptions {
756
888
  id: CodexModelId;
757
889
  settings?: CodexExecSettings;
758
890
  }
759
- declare class ExecLanguageModel implements LanguageModelV3 {
760
- readonly specificationVersion: "v3";
891
+ declare class ExecLanguageModel implements LanguageModelV4 {
892
+ readonly specificationVersion: "v4";
761
893
  readonly provider = "codex-cli";
762
- readonly defaultObjectGenerationMode: "json";
763
- readonly supportsImageUrls = false;
764
894
  readonly supportedUrls: {};
765
- readonly supportsStructuredOutputs = true;
766
895
  readonly modelId: string;
767
896
  readonly settings: CodexExecSettings;
768
897
  private logger;
@@ -785,8 +914,8 @@ declare class ExecLanguageModel implements LanguageModelV3 {
785
914
  private emitToolInvocation;
786
915
  private emitToolResult;
787
916
  private handleSpawnError;
788
- doGenerate(options: Parameters<LanguageModelV3['doGenerate']>[0]): Promise<Awaited<ReturnType<LanguageModelV3['doGenerate']>>>;
789
- doStream(options: Parameters<LanguageModelV3['doStream']>[0]): Promise<Awaited<ReturnType<LanguageModelV3['doStream']>>>;
917
+ doGenerate(options: Parameters<LanguageModelV4['doGenerate']>[0]): Promise<Awaited<ReturnType<LanguageModelV4['doGenerate']>>>;
918
+ doStream(options: Parameters<LanguageModelV4['doStream']>[0]): Promise<Awaited<ReturnType<LanguageModelV4['doStream']>>>;
790
919
  }
791
920
 
792
921
  declare class UnsupportedFeatureError extends UnsupportedFunctionalityError {