@depup/ai-sdk__openai 3.0.41-depup.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 (74) hide show
  1. package/CHANGELOG.md +3101 -0
  2. package/LICENSE +13 -0
  3. package/README.md +25 -0
  4. package/changes.json +5 -0
  5. package/dist/index.d.mts +1107 -0
  6. package/dist/index.d.ts +1107 -0
  7. package/dist/index.js +6408 -0
  8. package/dist/index.js.map +1 -0
  9. package/dist/index.mjs +6493 -0
  10. package/dist/index.mjs.map +1 -0
  11. package/dist/internal/index.d.mts +1137 -0
  12. package/dist/internal/index.d.ts +1137 -0
  13. package/dist/internal/index.js +6256 -0
  14. package/dist/internal/index.js.map +1 -0
  15. package/dist/internal/index.mjs +6306 -0
  16. package/dist/internal/index.mjs.map +1 -0
  17. package/docs/03-openai.mdx +2396 -0
  18. package/internal.d.ts +1 -0
  19. package/package.json +96 -0
  20. package/src/chat/convert-openai-chat-usage.ts +57 -0
  21. package/src/chat/convert-to-openai-chat-messages.ts +225 -0
  22. package/src/chat/get-response-metadata.ts +15 -0
  23. package/src/chat/map-openai-finish-reason.ts +19 -0
  24. package/src/chat/openai-chat-api.ts +198 -0
  25. package/src/chat/openai-chat-language-model.ts +703 -0
  26. package/src/chat/openai-chat-options.ts +192 -0
  27. package/src/chat/openai-chat-prepare-tools.ts +84 -0
  28. package/src/chat/openai-chat-prompt.ts +70 -0
  29. package/src/completion/convert-openai-completion-usage.ts +46 -0
  30. package/src/completion/convert-to-openai-completion-prompt.ts +93 -0
  31. package/src/completion/get-response-metadata.ts +15 -0
  32. package/src/completion/map-openai-finish-reason.ts +19 -0
  33. package/src/completion/openai-completion-api.ts +81 -0
  34. package/src/completion/openai-completion-language-model.ts +336 -0
  35. package/src/completion/openai-completion-options.ts +61 -0
  36. package/src/embedding/openai-embedding-api.ts +13 -0
  37. package/src/embedding/openai-embedding-model.ts +95 -0
  38. package/src/embedding/openai-embedding-options.ts +30 -0
  39. package/src/image/openai-image-api.ts +35 -0
  40. package/src/image/openai-image-model.ts +349 -0
  41. package/src/image/openai-image-options.ts +31 -0
  42. package/src/index.ts +23 -0
  43. package/src/internal/index.ts +19 -0
  44. package/src/openai-config.ts +18 -0
  45. package/src/openai-error.ts +22 -0
  46. package/src/openai-language-model-capabilities.ts +52 -0
  47. package/src/openai-provider.ts +270 -0
  48. package/src/openai-tools.ts +126 -0
  49. package/src/responses/convert-openai-responses-usage.ts +53 -0
  50. package/src/responses/convert-to-openai-responses-input.ts +735 -0
  51. package/src/responses/map-openai-responses-finish-reason.ts +22 -0
  52. package/src/responses/openai-responses-api.ts +1260 -0
  53. package/src/responses/openai-responses-language-model.ts +2098 -0
  54. package/src/responses/openai-responses-options.ts +299 -0
  55. package/src/responses/openai-responses-prepare-tools.ts +408 -0
  56. package/src/responses/openai-responses-provider-metadata.ts +62 -0
  57. package/src/speech/openai-speech-api.ts +38 -0
  58. package/src/speech/openai-speech-model.ts +137 -0
  59. package/src/speech/openai-speech-options.ts +26 -0
  60. package/src/tool/apply-patch.ts +141 -0
  61. package/src/tool/code-interpreter.ts +104 -0
  62. package/src/tool/custom.ts +64 -0
  63. package/src/tool/file-search.ts +145 -0
  64. package/src/tool/image-generation.ts +126 -0
  65. package/src/tool/local-shell.ts +72 -0
  66. package/src/tool/mcp.ts +125 -0
  67. package/src/tool/shell.ts +203 -0
  68. package/src/tool/web-search-preview.ts +141 -0
  69. package/src/tool/web-search.ts +181 -0
  70. package/src/transcription/openai-transcription-api.ts +37 -0
  71. package/src/transcription/openai-transcription-model.ts +232 -0
  72. package/src/transcription/openai-transcription-options.ts +53 -0
  73. package/src/transcription/transcription-test.mp3 +0 -0
  74. package/src/version.ts +6 -0
@@ -0,0 +1,1260 @@
1
+ import { JSONSchema7 } from '@ai-sdk/provider';
2
+ import { InferSchema, lazySchema, zodSchema } from '@ai-sdk/provider-utils';
3
+ import { z } from 'zod/v4';
4
+
5
+ export type OpenAIResponsesInput = Array<OpenAIResponsesInputItem>;
6
+
7
+ export type OpenAIResponsesInputItem =
8
+ | OpenAIResponsesSystemMessage
9
+ | OpenAIResponsesUserMessage
10
+ | OpenAIResponsesAssistantMessage
11
+ | OpenAIResponsesFunctionCall
12
+ | OpenAIResponsesFunctionCallOutput
13
+ | OpenAIResponsesCustomToolCall
14
+ | OpenAIResponsesCustomToolCallOutput
15
+ | OpenAIResponsesMcpApprovalResponse
16
+ | OpenAIResponsesComputerCall
17
+ | OpenAIResponsesLocalShellCall
18
+ | OpenAIResponsesLocalShellCallOutput
19
+ | OpenAIResponsesShellCall
20
+ | OpenAIResponsesShellCallOutput
21
+ | OpenAIResponsesApplyPatchCall
22
+ | OpenAIResponsesApplyPatchCallOutput
23
+ | OpenAIResponsesReasoning
24
+ | OpenAIResponsesItemReference;
25
+
26
+ export type OpenAIResponsesIncludeValue =
27
+ | 'web_search_call.action.sources'
28
+ | 'code_interpreter_call.outputs'
29
+ | 'computer_call_output.output.image_url'
30
+ | 'file_search_call.results'
31
+ | 'message.input_image.image_url'
32
+ | 'message.output_text.logprobs'
33
+ | 'reasoning.encrypted_content';
34
+
35
+ export type OpenAIResponsesIncludeOptions =
36
+ | Array<OpenAIResponsesIncludeValue>
37
+ | undefined
38
+ | null;
39
+
40
+ export type OpenAIResponsesApplyPatchOperationDiffDeltaChunk = {
41
+ type: 'response.apply_patch_call_operation_diff.delta';
42
+ item_id: string;
43
+ output_index: number;
44
+ delta: string;
45
+ obfuscation?: string | null;
46
+ };
47
+
48
+ export type OpenAIResponsesApplyPatchOperationDiffDoneChunk = {
49
+ type: 'response.apply_patch_call_operation_diff.done';
50
+ item_id: string;
51
+ output_index: number;
52
+ diff: string;
53
+ };
54
+
55
+ export type OpenAIResponsesSystemMessage = {
56
+ role: 'system' | 'developer';
57
+ content: string;
58
+ };
59
+
60
+ export type OpenAIResponsesUserMessage = {
61
+ role: 'user';
62
+ content: Array<
63
+ | { type: 'input_text'; text: string }
64
+ | { type: 'input_image'; image_url: string }
65
+ | { type: 'input_image'; file_id: string }
66
+ | { type: 'input_file'; file_url: string }
67
+ | { type: 'input_file'; filename: string; file_data: string }
68
+ | { type: 'input_file'; file_id: string }
69
+ >;
70
+ };
71
+
72
+ export type OpenAIResponsesAssistantMessage = {
73
+ role: 'assistant';
74
+ content: Array<{ type: 'output_text'; text: string }>;
75
+ id?: string;
76
+ phase?: 'commentary' | 'final_answer' | null;
77
+ };
78
+
79
+ export type OpenAIResponsesFunctionCall = {
80
+ type: 'function_call';
81
+ call_id: string;
82
+ name: string;
83
+ arguments: string;
84
+ id?: string;
85
+ };
86
+
87
+ export type OpenAIResponsesFunctionCallOutput = {
88
+ type: 'function_call_output';
89
+ call_id: string;
90
+ output:
91
+ | string
92
+ | Array<
93
+ | { type: 'input_text'; text: string }
94
+ | { type: 'input_image'; image_url: string }
95
+ | { type: 'input_file'; filename: string; file_data: string }
96
+ >;
97
+ };
98
+
99
+ export type OpenAIResponsesCustomToolCall = {
100
+ type: 'custom_tool_call';
101
+ id?: string;
102
+ call_id: string;
103
+ name: string;
104
+ input: string;
105
+ };
106
+
107
+ export type OpenAIResponsesCustomToolCallOutput = {
108
+ type: 'custom_tool_call_output';
109
+ call_id: string;
110
+ output: OpenAIResponsesFunctionCallOutput['output'];
111
+ };
112
+
113
+ export type OpenAIResponsesMcpApprovalResponse = {
114
+ type: 'mcp_approval_response';
115
+ approval_request_id: string;
116
+ approve: boolean;
117
+ };
118
+
119
+ export type OpenAIResponsesComputerCall = {
120
+ type: 'computer_call';
121
+ id: string;
122
+ status?: string;
123
+ };
124
+
125
+ export type OpenAIResponsesLocalShellCall = {
126
+ type: 'local_shell_call';
127
+ id: string;
128
+ call_id: string;
129
+ action: {
130
+ type: 'exec';
131
+ command: string[];
132
+ timeout_ms?: number;
133
+ user?: string;
134
+ working_directory?: string;
135
+ env?: Record<string, string>;
136
+ };
137
+ };
138
+
139
+ export type OpenAIResponsesLocalShellCallOutput = {
140
+ type: 'local_shell_call_output';
141
+ call_id: string;
142
+ output: string;
143
+ };
144
+
145
+ /**
146
+ * Official OpenAI API Specifications: https://platform.openai.com/docs/api-reference/responses/object#responses-object-output-shell_tool_call
147
+ */
148
+ export type OpenAIResponsesShellCall = {
149
+ type: 'shell_call';
150
+ id: string;
151
+ call_id: string;
152
+ status: 'in_progress' | 'completed' | 'incomplete';
153
+ action: {
154
+ commands: string[];
155
+ timeout_ms?: number;
156
+ max_output_length?: number;
157
+ };
158
+ };
159
+
160
+ export type OpenAIResponsesShellCallOutput = {
161
+ type: 'shell_call_output';
162
+ id?: string;
163
+ call_id: string;
164
+ status?: 'in_progress' | 'completed' | 'incomplete';
165
+ max_output_length?: number | null;
166
+ output: Array<{
167
+ stdout: string;
168
+ stderr: string;
169
+ outcome: { type: 'timeout' } | { type: 'exit'; exit_code: number };
170
+ }>;
171
+ };
172
+
173
+ export type OpenAIResponsesApplyPatchCall = {
174
+ type: 'apply_patch_call';
175
+ id?: string;
176
+ call_id: string;
177
+ status: 'in_progress' | 'completed';
178
+ operation:
179
+ | {
180
+ type: 'create_file';
181
+ path: string;
182
+ diff: string;
183
+ }
184
+ | {
185
+ type: 'delete_file';
186
+ path: string;
187
+ }
188
+ | {
189
+ type: 'update_file';
190
+ path: string;
191
+ diff: string;
192
+ };
193
+ };
194
+
195
+ export type OpenAIResponsesApplyPatchCallOutput = {
196
+ type: 'apply_patch_call_output';
197
+ call_id: string;
198
+ status: 'completed' | 'failed';
199
+ output?: string;
200
+ };
201
+
202
+ export type OpenAIResponsesItemReference = {
203
+ type: 'item_reference';
204
+ id: string;
205
+ };
206
+
207
+ /**
208
+ * A filter used to compare a specified attribute key to a given value using a defined comparison operation.
209
+ */
210
+ export type OpenAIResponsesFileSearchToolComparisonFilter = {
211
+ /**
212
+ * The key to compare against the value.
213
+ */
214
+ key: string;
215
+
216
+ /**
217
+ * Specifies the comparison operator: eq, ne, gt, gte, lt, lte, in, nin.
218
+ */
219
+ type: 'eq' | 'ne' | 'gt' | 'gte' | 'lt' | 'lte' | 'in' | 'nin';
220
+
221
+ /**
222
+ * The value to compare against the attribute key; supports string, number, boolean, or array of string types.
223
+ */
224
+ value: string | number | boolean | string[];
225
+ };
226
+
227
+ /**
228
+ * Combine multiple filters using and or or.
229
+ */
230
+ export type OpenAIResponsesFileSearchToolCompoundFilter = {
231
+ /**
232
+ * Type of operation: and or or.
233
+ */
234
+ type: 'and' | 'or';
235
+
236
+ /**
237
+ * Array of filters to combine. Items can be ComparisonFilter or CompoundFilter.
238
+ */
239
+ filters: Array<
240
+ | OpenAIResponsesFileSearchToolComparisonFilter
241
+ | OpenAIResponsesFileSearchToolCompoundFilter
242
+ >;
243
+ };
244
+
245
+ export type OpenAIResponsesTool =
246
+ | {
247
+ type: 'function';
248
+ name: string;
249
+ description: string | undefined;
250
+ parameters: JSONSchema7;
251
+ strict?: boolean;
252
+ }
253
+ | {
254
+ type: 'apply_patch';
255
+ }
256
+ | {
257
+ type: 'web_search';
258
+ external_web_access: boolean | undefined;
259
+ filters: { allowed_domains: string[] | undefined } | undefined;
260
+ search_context_size: 'low' | 'medium' | 'high' | undefined;
261
+ user_location:
262
+ | {
263
+ type: 'approximate';
264
+ city?: string;
265
+ country?: string;
266
+ region?: string;
267
+ timezone?: string;
268
+ }
269
+ | undefined;
270
+ }
271
+ | {
272
+ type: 'web_search_preview';
273
+ search_context_size: 'low' | 'medium' | 'high' | undefined;
274
+ user_location:
275
+ | {
276
+ type: 'approximate';
277
+ city?: string;
278
+ country?: string;
279
+ region?: string;
280
+ timezone?: string;
281
+ }
282
+ | undefined;
283
+ }
284
+ | {
285
+ type: 'code_interpreter';
286
+ container: string | { type: 'auto'; file_ids: string[] | undefined };
287
+ }
288
+ | {
289
+ type: 'file_search';
290
+ vector_store_ids: string[];
291
+ max_num_results: number | undefined;
292
+ ranking_options:
293
+ | { ranker?: string; score_threshold?: number }
294
+ | undefined;
295
+ filters:
296
+ | OpenAIResponsesFileSearchToolComparisonFilter
297
+ | OpenAIResponsesFileSearchToolCompoundFilter
298
+ | undefined;
299
+ }
300
+ | {
301
+ type: 'image_generation';
302
+ background: 'auto' | 'opaque' | 'transparent' | undefined;
303
+ input_fidelity: 'low' | 'high' | undefined;
304
+ input_image_mask:
305
+ | {
306
+ file_id: string | undefined;
307
+ image_url: string | undefined;
308
+ }
309
+ | undefined;
310
+ model: string | undefined;
311
+ moderation: 'auto' | undefined;
312
+ output_compression: number | undefined;
313
+ output_format: 'png' | 'jpeg' | 'webp' | undefined;
314
+ partial_images: number | undefined;
315
+ quality: 'auto' | 'low' | 'medium' | 'high' | undefined;
316
+ size: 'auto' | '1024x1024' | '1024x1536' | '1536x1024' | undefined;
317
+ }
318
+
319
+ /**
320
+ * Official OpenAI API Specifications: https://platform.openai.com/docs/api-reference/responses/create#responses_create-tools-mcp_tool
321
+ */
322
+ | {
323
+ type: 'mcp';
324
+ server_label: string;
325
+ allowed_tools:
326
+ | string[]
327
+ | {
328
+ read_only?: boolean;
329
+ tool_names?: string[];
330
+ }
331
+ | undefined;
332
+ authorization: string | undefined;
333
+ connector_id: string | undefined;
334
+ headers: Record<string, string> | undefined;
335
+ require_approval:
336
+ | 'always'
337
+ | 'never'
338
+ | {
339
+ never?: { tool_names?: string[] };
340
+ }
341
+ | undefined;
342
+ server_description: string | undefined;
343
+ server_url: string | undefined;
344
+ }
345
+ | {
346
+ type: 'custom';
347
+ name: string;
348
+ description?: string;
349
+ format?:
350
+ | {
351
+ type: 'grammar';
352
+ syntax: 'regex' | 'lark';
353
+ definition: string;
354
+ }
355
+ | {
356
+ type: 'text';
357
+ };
358
+ }
359
+ | {
360
+ type: 'local_shell';
361
+ }
362
+ | {
363
+ type: 'shell';
364
+ environment?:
365
+ | {
366
+ type: 'container_auto';
367
+ file_ids?: string[];
368
+ memory_limit?: '1g' | '4g' | '16g' | '64g';
369
+ network_policy?:
370
+ | { type: 'disabled' }
371
+ | {
372
+ type: 'allowlist';
373
+ allowed_domains: string[];
374
+ domain_secrets?: Array<{
375
+ domain: string;
376
+ name: string;
377
+ value: string;
378
+ }>;
379
+ };
380
+ skills?: Array<
381
+ | {
382
+ type: 'skill_reference';
383
+ skill_id: string;
384
+ version?: string;
385
+ }
386
+ | {
387
+ type: 'inline';
388
+ name: string;
389
+ description: string;
390
+ source: {
391
+ type: 'base64';
392
+ media_type: 'application/zip';
393
+ data: string;
394
+ };
395
+ }
396
+ >;
397
+ }
398
+ | {
399
+ type: 'container_reference';
400
+ container_id: string;
401
+ }
402
+ | {
403
+ type: 'local';
404
+ skills?: Array<{
405
+ name: string;
406
+ description: string;
407
+ path: string;
408
+ }>;
409
+ };
410
+ };
411
+
412
+ export type OpenAIResponsesReasoning = {
413
+ type: 'reasoning';
414
+ id?: string;
415
+ encrypted_content?: string | null;
416
+ summary: Array<{
417
+ type: 'summary_text';
418
+ text: string;
419
+ }>;
420
+ };
421
+
422
+ export const openaiResponsesChunkSchema = lazySchema(() =>
423
+ zodSchema(
424
+ z.union([
425
+ z.object({
426
+ type: z.literal('response.output_text.delta'),
427
+ item_id: z.string(),
428
+ delta: z.string(),
429
+ logprobs: z
430
+ .array(
431
+ z.object({
432
+ token: z.string(),
433
+ logprob: z.number(),
434
+ top_logprobs: z.array(
435
+ z.object({
436
+ token: z.string(),
437
+ logprob: z.number(),
438
+ }),
439
+ ),
440
+ }),
441
+ )
442
+ .nullish(),
443
+ }),
444
+ z.object({
445
+ type: z.enum(['response.completed', 'response.incomplete']),
446
+ response: z.object({
447
+ incomplete_details: z.object({ reason: z.string() }).nullish(),
448
+ usage: z.object({
449
+ input_tokens: z.number(),
450
+ input_tokens_details: z
451
+ .object({ cached_tokens: z.number().nullish() })
452
+ .nullish(),
453
+ output_tokens: z.number(),
454
+ output_tokens_details: z
455
+ .object({ reasoning_tokens: z.number().nullish() })
456
+ .nullish(),
457
+ }),
458
+ service_tier: z.string().nullish(),
459
+ }),
460
+ }),
461
+ z.object({
462
+ type: z.literal('response.created'),
463
+ response: z.object({
464
+ id: z.string(),
465
+ created_at: z.number(),
466
+ model: z.string(),
467
+ service_tier: z.string().nullish(),
468
+ }),
469
+ }),
470
+ z.object({
471
+ type: z.literal('response.output_item.added'),
472
+ output_index: z.number(),
473
+ item: z.discriminatedUnion('type', [
474
+ z.object({
475
+ type: z.literal('message'),
476
+ id: z.string(),
477
+ phase: z.enum(['commentary', 'final_answer']).nullish(),
478
+ }),
479
+ z.object({
480
+ type: z.literal('reasoning'),
481
+ id: z.string(),
482
+ encrypted_content: z.string().nullish(),
483
+ }),
484
+ z.object({
485
+ type: z.literal('function_call'),
486
+ id: z.string(),
487
+ call_id: z.string(),
488
+ name: z.string(),
489
+ arguments: z.string(),
490
+ }),
491
+ z.object({
492
+ type: z.literal('web_search_call'),
493
+ id: z.string(),
494
+ status: z.string(),
495
+ }),
496
+ z.object({
497
+ type: z.literal('computer_call'),
498
+ id: z.string(),
499
+ status: z.string(),
500
+ }),
501
+ z.object({
502
+ type: z.literal('file_search_call'),
503
+ id: z.string(),
504
+ }),
505
+ z.object({
506
+ type: z.literal('image_generation_call'),
507
+ id: z.string(),
508
+ }),
509
+ z.object({
510
+ type: z.literal('code_interpreter_call'),
511
+ id: z.string(),
512
+ container_id: z.string(),
513
+ code: z.string().nullable(),
514
+ outputs: z
515
+ .array(
516
+ z.discriminatedUnion('type', [
517
+ z.object({ type: z.literal('logs'), logs: z.string() }),
518
+ z.object({ type: z.literal('image'), url: z.string() }),
519
+ ]),
520
+ )
521
+ .nullable(),
522
+ status: z.string(),
523
+ }),
524
+ z.object({
525
+ type: z.literal('mcp_call'),
526
+ id: z.string(),
527
+ status: z.string(),
528
+ approval_request_id: z.string().nullish(),
529
+ }),
530
+ z.object({
531
+ type: z.literal('mcp_list_tools'),
532
+ id: z.string(),
533
+ }),
534
+ z.object({
535
+ type: z.literal('mcp_approval_request'),
536
+ id: z.string(),
537
+ }),
538
+ z.object({
539
+ type: z.literal('apply_patch_call'),
540
+ id: z.string(),
541
+ call_id: z.string(),
542
+ status: z.enum(['in_progress', 'completed']),
543
+ operation: z.discriminatedUnion('type', [
544
+ z.object({
545
+ type: z.literal('create_file'),
546
+ path: z.string(),
547
+ diff: z.string(),
548
+ }),
549
+ z.object({
550
+ type: z.literal('delete_file'),
551
+ path: z.string(),
552
+ }),
553
+ z.object({
554
+ type: z.literal('update_file'),
555
+ path: z.string(),
556
+ diff: z.string(),
557
+ }),
558
+ ]),
559
+ }),
560
+ z.object({
561
+ type: z.literal('custom_tool_call'),
562
+ id: z.string(),
563
+ call_id: z.string(),
564
+ name: z.string(),
565
+ input: z.string(),
566
+ }),
567
+ z.object({
568
+ type: z.literal('shell_call'),
569
+ id: z.string(),
570
+ call_id: z.string(),
571
+ status: z.enum(['in_progress', 'completed', 'incomplete']),
572
+ action: z.object({
573
+ commands: z.array(z.string()),
574
+ }),
575
+ }),
576
+ z.object({
577
+ type: z.literal('shell_call_output'),
578
+ id: z.string(),
579
+ call_id: z.string(),
580
+ status: z.enum(['in_progress', 'completed', 'incomplete']),
581
+ output: z.array(
582
+ z.object({
583
+ stdout: z.string(),
584
+ stderr: z.string(),
585
+ outcome: z.discriminatedUnion('type', [
586
+ z.object({ type: z.literal('timeout') }),
587
+ z.object({
588
+ type: z.literal('exit'),
589
+ exit_code: z.number(),
590
+ }),
591
+ ]),
592
+ }),
593
+ ),
594
+ }),
595
+ ]),
596
+ }),
597
+ z.object({
598
+ type: z.literal('response.output_item.done'),
599
+ output_index: z.number(),
600
+ item: z.discriminatedUnion('type', [
601
+ z.object({
602
+ type: z.literal('message'),
603
+ id: z.string(),
604
+ phase: z.enum(['commentary', 'final_answer']).nullish(),
605
+ }),
606
+ z.object({
607
+ type: z.literal('reasoning'),
608
+ id: z.string(),
609
+ encrypted_content: z.string().nullish(),
610
+ }),
611
+ z.object({
612
+ type: z.literal('function_call'),
613
+ id: z.string(),
614
+ call_id: z.string(),
615
+ name: z.string(),
616
+ arguments: z.string(),
617
+ status: z.literal('completed'),
618
+ }),
619
+ z.object({
620
+ type: z.literal('custom_tool_call'),
621
+ id: z.string(),
622
+ call_id: z.string(),
623
+ name: z.string(),
624
+ input: z.string(),
625
+ status: z.literal('completed'),
626
+ }),
627
+ z.object({
628
+ type: z.literal('code_interpreter_call'),
629
+ id: z.string(),
630
+ code: z.string().nullable(),
631
+ container_id: z.string(),
632
+ outputs: z
633
+ .array(
634
+ z.discriminatedUnion('type', [
635
+ z.object({ type: z.literal('logs'), logs: z.string() }),
636
+ z.object({ type: z.literal('image'), url: z.string() }),
637
+ ]),
638
+ )
639
+ .nullable(),
640
+ }),
641
+ z.object({
642
+ type: z.literal('image_generation_call'),
643
+ id: z.string(),
644
+ result: z.string(),
645
+ }),
646
+ z.object({
647
+ type: z.literal('web_search_call'),
648
+ id: z.string(),
649
+ status: z.string(),
650
+ action: z
651
+ .discriminatedUnion('type', [
652
+ z.object({
653
+ type: z.literal('search'),
654
+ query: z.string().nullish(),
655
+ sources: z
656
+ .array(
657
+ z.discriminatedUnion('type', [
658
+ z.object({ type: z.literal('url'), url: z.string() }),
659
+ z.object({ type: z.literal('api'), name: z.string() }),
660
+ ]),
661
+ )
662
+ .nullish(),
663
+ }),
664
+ z.object({
665
+ type: z.literal('open_page'),
666
+ url: z.string().nullish(),
667
+ }),
668
+ z.object({
669
+ type: z.literal('find_in_page'),
670
+ url: z.string().nullish(),
671
+ pattern: z.string().nullish(),
672
+ }),
673
+ ])
674
+ .nullish(),
675
+ }),
676
+ z.object({
677
+ type: z.literal('file_search_call'),
678
+ id: z.string(),
679
+ queries: z.array(z.string()),
680
+ results: z
681
+ .array(
682
+ z.object({
683
+ attributes: z.record(
684
+ z.string(),
685
+ z.union([z.string(), z.number(), z.boolean()]),
686
+ ),
687
+ file_id: z.string(),
688
+ filename: z.string(),
689
+ score: z.number(),
690
+ text: z.string(),
691
+ }),
692
+ )
693
+ .nullish(),
694
+ }),
695
+ z.object({
696
+ type: z.literal('local_shell_call'),
697
+ id: z.string(),
698
+ call_id: z.string(),
699
+ action: z.object({
700
+ type: z.literal('exec'),
701
+ command: z.array(z.string()),
702
+ timeout_ms: z.number().optional(),
703
+ user: z.string().optional(),
704
+ working_directory: z.string().optional(),
705
+ env: z.record(z.string(), z.string()).optional(),
706
+ }),
707
+ }),
708
+ z.object({
709
+ type: z.literal('computer_call'),
710
+ id: z.string(),
711
+ status: z.literal('completed'),
712
+ }),
713
+ z.object({
714
+ type: z.literal('mcp_call'),
715
+ id: z.string(),
716
+ status: z.string(),
717
+ arguments: z.string(),
718
+ name: z.string(),
719
+ server_label: z.string(),
720
+ output: z.string().nullish(),
721
+ error: z
722
+ .union([
723
+ z.string(),
724
+ z
725
+ .object({
726
+ type: z.string().optional(),
727
+ code: z.union([z.number(), z.string()]).optional(),
728
+ message: z.string().optional(),
729
+ })
730
+ .loose(),
731
+ ])
732
+ .nullish(),
733
+ approval_request_id: z.string().nullish(),
734
+ }),
735
+ z.object({
736
+ type: z.literal('mcp_list_tools'),
737
+ id: z.string(),
738
+ server_label: z.string(),
739
+ tools: z.array(
740
+ z.object({
741
+ name: z.string(),
742
+ description: z.string().optional(),
743
+ input_schema: z.any(),
744
+ annotations: z.record(z.string(), z.unknown()).optional(),
745
+ }),
746
+ ),
747
+ error: z
748
+ .union([
749
+ z.string(),
750
+ z
751
+ .object({
752
+ type: z.string().optional(),
753
+ code: z.union([z.number(), z.string()]).optional(),
754
+ message: z.string().optional(),
755
+ })
756
+ .loose(),
757
+ ])
758
+ .optional(),
759
+ }),
760
+ z.object({
761
+ type: z.literal('mcp_approval_request'),
762
+ id: z.string(),
763
+ server_label: z.string(),
764
+ name: z.string(),
765
+ arguments: z.string(),
766
+ approval_request_id: z.string().optional(),
767
+ }),
768
+ z.object({
769
+ type: z.literal('apply_patch_call'),
770
+ id: z.string(),
771
+ call_id: z.string(),
772
+ status: z.enum(['in_progress', 'completed']),
773
+ operation: z.discriminatedUnion('type', [
774
+ z.object({
775
+ type: z.literal('create_file'),
776
+ path: z.string(),
777
+ diff: z.string(),
778
+ }),
779
+ z.object({
780
+ type: z.literal('delete_file'),
781
+ path: z.string(),
782
+ }),
783
+ z.object({
784
+ type: z.literal('update_file'),
785
+ path: z.string(),
786
+ diff: z.string(),
787
+ }),
788
+ ]),
789
+ }),
790
+ z.object({
791
+ type: z.literal('shell_call'),
792
+ id: z.string(),
793
+ call_id: z.string(),
794
+ status: z.enum(['in_progress', 'completed', 'incomplete']),
795
+ action: z.object({
796
+ commands: z.array(z.string()),
797
+ }),
798
+ }),
799
+ z.object({
800
+ type: z.literal('shell_call_output'),
801
+ id: z.string(),
802
+ call_id: z.string(),
803
+ status: z.enum(['in_progress', 'completed', 'incomplete']),
804
+ output: z.array(
805
+ z.object({
806
+ stdout: z.string(),
807
+ stderr: z.string(),
808
+ outcome: z.discriminatedUnion('type', [
809
+ z.object({ type: z.literal('timeout') }),
810
+ z.object({
811
+ type: z.literal('exit'),
812
+ exit_code: z.number(),
813
+ }),
814
+ ]),
815
+ }),
816
+ ),
817
+ }),
818
+ ]),
819
+ }),
820
+ z.object({
821
+ type: z.literal('response.function_call_arguments.delta'),
822
+ item_id: z.string(),
823
+ output_index: z.number(),
824
+ delta: z.string(),
825
+ }),
826
+ z.object({
827
+ type: z.literal('response.custom_tool_call_input.delta'),
828
+ item_id: z.string(),
829
+ output_index: z.number(),
830
+ delta: z.string(),
831
+ }),
832
+ z.object({
833
+ type: z.literal('response.image_generation_call.partial_image'),
834
+ item_id: z.string(),
835
+ output_index: z.number(),
836
+ partial_image_b64: z.string(),
837
+ }),
838
+ z.object({
839
+ type: z.literal('response.code_interpreter_call_code.delta'),
840
+ item_id: z.string(),
841
+ output_index: z.number(),
842
+ delta: z.string(),
843
+ }),
844
+ z.object({
845
+ type: z.literal('response.code_interpreter_call_code.done'),
846
+ item_id: z.string(),
847
+ output_index: z.number(),
848
+ code: z.string(),
849
+ }),
850
+ z.object({
851
+ type: z.literal('response.output_text.annotation.added'),
852
+ annotation: z.discriminatedUnion('type', [
853
+ z.object({
854
+ type: z.literal('url_citation'),
855
+ start_index: z.number(),
856
+ end_index: z.number(),
857
+ url: z.string(),
858
+ title: z.string(),
859
+ }),
860
+ z.object({
861
+ type: z.literal('file_citation'),
862
+ file_id: z.string(),
863
+ filename: z.string(),
864
+ index: z.number(),
865
+ }),
866
+ z.object({
867
+ type: z.literal('container_file_citation'),
868
+ container_id: z.string(),
869
+ file_id: z.string(),
870
+ filename: z.string(),
871
+ start_index: z.number(),
872
+ end_index: z.number(),
873
+ }),
874
+ z.object({
875
+ type: z.literal('file_path'),
876
+ file_id: z.string(),
877
+ index: z.number(),
878
+ }),
879
+ ]),
880
+ }),
881
+ z.object({
882
+ type: z.literal('response.reasoning_summary_part.added'),
883
+ item_id: z.string(),
884
+ summary_index: z.number(),
885
+ }),
886
+ z.object({
887
+ type: z.literal('response.reasoning_summary_text.delta'),
888
+ item_id: z.string(),
889
+ summary_index: z.number(),
890
+ delta: z.string(),
891
+ }),
892
+ z.object({
893
+ type: z.literal('response.reasoning_summary_part.done'),
894
+ item_id: z.string(),
895
+ summary_index: z.number(),
896
+ }),
897
+ z.object({
898
+ type: z.literal('response.apply_patch_call_operation_diff.delta'),
899
+ item_id: z.string(),
900
+ output_index: z.number(),
901
+ delta: z.string(),
902
+ obfuscation: z.string().nullish(),
903
+ }),
904
+ z.object({
905
+ type: z.literal('response.apply_patch_call_operation_diff.done'),
906
+ item_id: z.string(),
907
+ output_index: z.number(),
908
+ diff: z.string(),
909
+ }),
910
+ z.object({
911
+ type: z.literal('error'),
912
+ sequence_number: z.number(),
913
+ error: z.object({
914
+ type: z.string(),
915
+ code: z.string(),
916
+ message: z.string(),
917
+ param: z.string().nullish(),
918
+ }),
919
+ }),
920
+ z
921
+ .object({ type: z.string() })
922
+ .loose()
923
+ .transform(value => ({
924
+ type: 'unknown_chunk' as const,
925
+ message: value.type,
926
+ })), // fallback for unknown chunks
927
+ ]),
928
+ ),
929
+ );
930
+
931
+ export type OpenAIResponsesChunk = InferSchema<
932
+ typeof openaiResponsesChunkSchema
933
+ >;
934
+
935
+ export type OpenAIResponsesLogprobs = NonNullable<
936
+ (OpenAIResponsesChunk & {
937
+ type: 'response.output_text.delta';
938
+ })['logprobs']
939
+ > | null;
940
+
941
+ export type OpenAIResponsesWebSearchAction = NonNullable<
942
+ ((OpenAIResponsesChunk & {
943
+ type: 'response.output_item.done';
944
+ })['item'] & {
945
+ type: 'web_search_call';
946
+ })['action']
947
+ >;
948
+
949
+ export const openaiResponsesResponseSchema = lazySchema(() =>
950
+ zodSchema(
951
+ z.object({
952
+ id: z.string().optional(),
953
+ created_at: z.number().optional(),
954
+ error: z
955
+ .object({
956
+ message: z.string(),
957
+ type: z.string(),
958
+ param: z.string().nullish(),
959
+ code: z.string(),
960
+ })
961
+ .nullish(),
962
+ model: z.string().optional(),
963
+ output: z
964
+ .array(
965
+ z.discriminatedUnion('type', [
966
+ z.object({
967
+ type: z.literal('message'),
968
+ role: z.literal('assistant'),
969
+ id: z.string(),
970
+ phase: z.enum(['commentary', 'final_answer']).nullish(),
971
+ content: z.array(
972
+ z.object({
973
+ type: z.literal('output_text'),
974
+ text: z.string(),
975
+ logprobs: z
976
+ .array(
977
+ z.object({
978
+ token: z.string(),
979
+ logprob: z.number(),
980
+ top_logprobs: z.array(
981
+ z.object({
982
+ token: z.string(),
983
+ logprob: z.number(),
984
+ }),
985
+ ),
986
+ }),
987
+ )
988
+ .nullish(),
989
+ annotations: z.array(
990
+ z.discriminatedUnion('type', [
991
+ z.object({
992
+ type: z.literal('url_citation'),
993
+ start_index: z.number(),
994
+ end_index: z.number(),
995
+ url: z.string(),
996
+ title: z.string(),
997
+ }),
998
+ z.object({
999
+ type: z.literal('file_citation'),
1000
+ file_id: z.string(),
1001
+ filename: z.string(),
1002
+ index: z.number(),
1003
+ }),
1004
+ z.object({
1005
+ type: z.literal('container_file_citation'),
1006
+ container_id: z.string(),
1007
+ file_id: z.string(),
1008
+ filename: z.string(),
1009
+ start_index: z.number(),
1010
+ end_index: z.number(),
1011
+ }),
1012
+ z.object({
1013
+ type: z.literal('file_path'),
1014
+ file_id: z.string(),
1015
+ index: z.number(),
1016
+ }),
1017
+ ]),
1018
+ ),
1019
+ }),
1020
+ ),
1021
+ }),
1022
+ z.object({
1023
+ type: z.literal('web_search_call'),
1024
+ id: z.string(),
1025
+ status: z.string(),
1026
+ action: z
1027
+ .discriminatedUnion('type', [
1028
+ z.object({
1029
+ type: z.literal('search'),
1030
+ query: z.string().nullish(),
1031
+ sources: z
1032
+ .array(
1033
+ z.discriminatedUnion('type', [
1034
+ z.object({ type: z.literal('url'), url: z.string() }),
1035
+ z.object({
1036
+ type: z.literal('api'),
1037
+ name: z.string(),
1038
+ }),
1039
+ ]),
1040
+ )
1041
+ .nullish(),
1042
+ }),
1043
+ z.object({
1044
+ type: z.literal('open_page'),
1045
+ url: z.string().nullish(),
1046
+ }),
1047
+ z.object({
1048
+ type: z.literal('find_in_page'),
1049
+ url: z.string().nullish(),
1050
+ pattern: z.string().nullish(),
1051
+ }),
1052
+ ])
1053
+ .nullish(),
1054
+ }),
1055
+ z.object({
1056
+ type: z.literal('file_search_call'),
1057
+ id: z.string(),
1058
+ queries: z.array(z.string()),
1059
+ results: z
1060
+ .array(
1061
+ z.object({
1062
+ attributes: z.record(
1063
+ z.string(),
1064
+ z.union([z.string(), z.number(), z.boolean()]),
1065
+ ),
1066
+ file_id: z.string(),
1067
+ filename: z.string(),
1068
+ score: z.number(),
1069
+ text: z.string(),
1070
+ }),
1071
+ )
1072
+ .nullish(),
1073
+ }),
1074
+ z.object({
1075
+ type: z.literal('code_interpreter_call'),
1076
+ id: z.string(),
1077
+ code: z.string().nullable(),
1078
+ container_id: z.string(),
1079
+ outputs: z
1080
+ .array(
1081
+ z.discriminatedUnion('type', [
1082
+ z.object({ type: z.literal('logs'), logs: z.string() }),
1083
+ z.object({ type: z.literal('image'), url: z.string() }),
1084
+ ]),
1085
+ )
1086
+ .nullable(),
1087
+ }),
1088
+ z.object({
1089
+ type: z.literal('image_generation_call'),
1090
+ id: z.string(),
1091
+ result: z.string(),
1092
+ }),
1093
+ z.object({
1094
+ type: z.literal('local_shell_call'),
1095
+ id: z.string(),
1096
+ call_id: z.string(),
1097
+ action: z.object({
1098
+ type: z.literal('exec'),
1099
+ command: z.array(z.string()),
1100
+ timeout_ms: z.number().optional(),
1101
+ user: z.string().optional(),
1102
+ working_directory: z.string().optional(),
1103
+ env: z.record(z.string(), z.string()).optional(),
1104
+ }),
1105
+ }),
1106
+ z.object({
1107
+ type: z.literal('function_call'),
1108
+ call_id: z.string(),
1109
+ name: z.string(),
1110
+ arguments: z.string(),
1111
+ id: z.string(),
1112
+ }),
1113
+ z.object({
1114
+ type: z.literal('custom_tool_call'),
1115
+ call_id: z.string(),
1116
+ name: z.string(),
1117
+ input: z.string(),
1118
+ id: z.string(),
1119
+ }),
1120
+ z.object({
1121
+ type: z.literal('computer_call'),
1122
+ id: z.string(),
1123
+ status: z.string().optional(),
1124
+ }),
1125
+ z.object({
1126
+ type: z.literal('reasoning'),
1127
+ id: z.string(),
1128
+ encrypted_content: z.string().nullish(),
1129
+ summary: z.array(
1130
+ z.object({
1131
+ type: z.literal('summary_text'),
1132
+ text: z.string(),
1133
+ }),
1134
+ ),
1135
+ }),
1136
+ z.object({
1137
+ type: z.literal('mcp_call'),
1138
+ id: z.string(),
1139
+ status: z.string(),
1140
+ arguments: z.string(),
1141
+ name: z.string(),
1142
+ server_label: z.string(),
1143
+ output: z.string().nullish(),
1144
+ error: z
1145
+ .union([
1146
+ z.string(),
1147
+ z
1148
+ .object({
1149
+ type: z.string().optional(),
1150
+ code: z.union([z.number(), z.string()]).optional(),
1151
+ message: z.string().optional(),
1152
+ })
1153
+ .loose(),
1154
+ ])
1155
+ .nullish(),
1156
+ approval_request_id: z.string().nullish(),
1157
+ }),
1158
+ z.object({
1159
+ type: z.literal('mcp_list_tools'),
1160
+ id: z.string(),
1161
+ server_label: z.string(),
1162
+ tools: z.array(
1163
+ z.object({
1164
+ name: z.string(),
1165
+ description: z.string().optional(),
1166
+ input_schema: z.any(),
1167
+ annotations: z.record(z.string(), z.unknown()).optional(),
1168
+ }),
1169
+ ),
1170
+ error: z
1171
+ .union([
1172
+ z.string(),
1173
+ z
1174
+ .object({
1175
+ type: z.string().optional(),
1176
+ code: z.union([z.number(), z.string()]).optional(),
1177
+ message: z.string().optional(),
1178
+ })
1179
+ .loose(),
1180
+ ])
1181
+ .optional(),
1182
+ }),
1183
+ z.object({
1184
+ type: z.literal('mcp_approval_request'),
1185
+ id: z.string(),
1186
+ server_label: z.string(),
1187
+ name: z.string(),
1188
+ arguments: z.string(),
1189
+ approval_request_id: z.string().optional(),
1190
+ }),
1191
+ z.object({
1192
+ type: z.literal('apply_patch_call'),
1193
+ id: z.string(),
1194
+ call_id: z.string(),
1195
+ status: z.enum(['in_progress', 'completed']),
1196
+ operation: z.discriminatedUnion('type', [
1197
+ z.object({
1198
+ type: z.literal('create_file'),
1199
+ path: z.string(),
1200
+ diff: z.string(),
1201
+ }),
1202
+ z.object({
1203
+ type: z.literal('delete_file'),
1204
+ path: z.string(),
1205
+ }),
1206
+ z.object({
1207
+ type: z.literal('update_file'),
1208
+ path: z.string(),
1209
+ diff: z.string(),
1210
+ }),
1211
+ ]),
1212
+ }),
1213
+ z.object({
1214
+ type: z.literal('shell_call'),
1215
+ id: z.string(),
1216
+ call_id: z.string(),
1217
+ status: z.enum(['in_progress', 'completed', 'incomplete']),
1218
+ action: z.object({
1219
+ commands: z.array(z.string()),
1220
+ }),
1221
+ }),
1222
+ z.object({
1223
+ type: z.literal('shell_call_output'),
1224
+ id: z.string(),
1225
+ call_id: z.string(),
1226
+ status: z.enum(['in_progress', 'completed', 'incomplete']),
1227
+ output: z.array(
1228
+ z.object({
1229
+ stdout: z.string(),
1230
+ stderr: z.string(),
1231
+ outcome: z.discriminatedUnion('type', [
1232
+ z.object({ type: z.literal('timeout') }),
1233
+ z.object({
1234
+ type: z.literal('exit'),
1235
+ exit_code: z.number(),
1236
+ }),
1237
+ ]),
1238
+ }),
1239
+ ),
1240
+ }),
1241
+ ]),
1242
+ )
1243
+ .optional(),
1244
+ service_tier: z.string().nullish(),
1245
+ incomplete_details: z.object({ reason: z.string() }).nullish(),
1246
+ usage: z
1247
+ .object({
1248
+ input_tokens: z.number(),
1249
+ input_tokens_details: z
1250
+ .object({ cached_tokens: z.number().nullish() })
1251
+ .nullish(),
1252
+ output_tokens: z.number(),
1253
+ output_tokens_details: z
1254
+ .object({ reasoning_tokens: z.number().nullish() })
1255
+ .nullish(),
1256
+ })
1257
+ .optional(),
1258
+ }),
1259
+ ),
1260
+ );