@ai-sdk/openai 4.0.0-beta.4 → 4.0.0-beta.41

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 (66) hide show
  1. package/CHANGELOG.md +399 -22
  2. package/README.md +2 -0
  3. package/dist/index.d.ts +166 -49
  4. package/dist/index.js +2454 -1627
  5. package/dist/index.js.map +1 -1
  6. package/dist/internal/index.d.ts +176 -53
  7. package/dist/internal/index.js +2220 -1648
  8. package/dist/internal/index.js.map +1 -1
  9. package/docs/03-openai.mdx +292 -22
  10. package/package.json +13 -14
  11. package/src/chat/convert-openai-chat-usage.ts +2 -2
  12. package/src/chat/convert-to-openai-chat-messages.ts +99 -71
  13. package/src/chat/map-openai-finish-reason.ts +2 -2
  14. package/src/chat/openai-chat-api.ts +6 -2
  15. package/src/chat/openai-chat-language-model.ts +68 -164
  16. package/src/chat/openai-chat-options.ts +10 -1
  17. package/src/chat/openai-chat-prepare-tools.ts +7 -7
  18. package/src/completion/convert-openai-completion-usage.ts +2 -2
  19. package/src/completion/convert-to-openai-completion-prompt.ts +2 -3
  20. package/src/completion/map-openai-finish-reason.ts +2 -2
  21. package/src/completion/openai-completion-api.ts +5 -2
  22. package/src/completion/openai-completion-language-model.ts +46 -30
  23. package/src/completion/openai-completion-options.ts +5 -1
  24. package/src/embedding/openai-embedding-model.ts +25 -8
  25. package/src/embedding/openai-embedding-options.ts +5 -1
  26. package/src/files/openai-files-api.ts +17 -0
  27. package/src/files/openai-files-options.ts +22 -0
  28. package/src/files/openai-files.ts +100 -0
  29. package/src/image/openai-image-model.ts +31 -15
  30. package/src/image/openai-image-options.ts +3 -0
  31. package/src/index.ts +2 -0
  32. package/src/openai-config.ts +7 -7
  33. package/src/openai-language-model-capabilities.ts +3 -2
  34. package/src/openai-provider.ts +63 -30
  35. package/src/openai-tools.ts +12 -1
  36. package/src/responses/convert-openai-responses-usage.ts +2 -2
  37. package/src/responses/convert-to-openai-responses-input.ts +244 -77
  38. package/src/responses/map-openai-responses-finish-reason.ts +2 -2
  39. package/src/responses/openai-responses-api.ts +141 -3
  40. package/src/responses/openai-responses-language-model.ts +274 -61
  41. package/src/responses/openai-responses-options.ts +29 -3
  42. package/src/responses/openai-responses-prepare-tools.ts +48 -15
  43. package/src/responses/openai-responses-provider-metadata.ts +12 -2
  44. package/src/skills/openai-skills-api.ts +31 -0
  45. package/src/skills/openai-skills.ts +83 -0
  46. package/src/speech/openai-speech-model.ts +28 -12
  47. package/src/speech/openai-speech-options.ts +5 -1
  48. package/src/tool/apply-patch.ts +33 -32
  49. package/src/tool/code-interpreter.ts +40 -41
  50. package/src/tool/custom.ts +2 -8
  51. package/src/tool/file-search.ts +3 -3
  52. package/src/tool/image-generation.ts +2 -2
  53. package/src/tool/local-shell.ts +2 -2
  54. package/src/tool/mcp.ts +3 -3
  55. package/src/tool/shell.ts +9 -4
  56. package/src/tool/tool-search.ts +98 -0
  57. package/src/tool/web-search-preview.ts +2 -2
  58. package/src/tool/web-search.ts +2 -2
  59. package/src/transcription/openai-transcription-model.ts +30 -14
  60. package/src/transcription/openai-transcription-options.ts +5 -1
  61. package/dist/index.d.mts +0 -1107
  62. package/dist/index.mjs +0 -6508
  63. package/dist/index.mjs.map +0 -1
  64. package/dist/internal/index.d.mts +0 -1137
  65. package/dist/internal/index.mjs +0 -6321
  66. package/dist/internal/index.mjs.map +0 -1
@@ -1,7 +1,22 @@
1
- import { JSONSchema7 } from '@ai-sdk/provider';
2
- import { InferSchema, lazySchema, zodSchema } from '@ai-sdk/provider-utils';
1
+ import type { JSONObject, JSONSchema7, JSONValue } from '@ai-sdk/provider';
2
+ import {
3
+ lazySchema,
4
+ zodSchema,
5
+ type InferSchema,
6
+ } from '@ai-sdk/provider-utils';
3
7
  import { z } from 'zod/v4';
4
8
 
9
+ const jsonValueSchema: z.ZodType<JSONValue> = z.lazy(() =>
10
+ z.union([
11
+ z.string(),
12
+ z.number(),
13
+ z.boolean(),
14
+ z.null(),
15
+ z.array(jsonValueSchema),
16
+ z.record(z.string(), jsonValueSchema.optional()),
17
+ ]),
18
+ );
19
+
5
20
  export type OpenAIResponsesInput = Array<OpenAIResponsesInputItem>;
6
21
 
7
22
  export type OpenAIResponsesInputItem =
@@ -20,8 +35,11 @@ export type OpenAIResponsesInputItem =
20
35
  | OpenAIResponsesShellCallOutput
21
36
  | OpenAIResponsesApplyPatchCall
22
37
  | OpenAIResponsesApplyPatchCallOutput
38
+ | OpenAIResponsesToolSearchCall
39
+ | OpenAIResponsesToolSearchOutput
23
40
  | OpenAIResponsesReasoning
24
- | OpenAIResponsesItemReference;
41
+ | OpenAIResponsesItemReference
42
+ | OpenAIResponsesCompactionItem;
25
43
 
26
44
  export type OpenAIResponsesIncludeValue =
27
45
  | 'web_search_call.action.sources'
@@ -93,6 +111,7 @@ export type OpenAIResponsesFunctionCallOutput = {
93
111
  | { type: 'input_text'; text: string }
94
112
  | { type: 'input_image'; image_url: string }
95
113
  | { type: 'input_file'; filename: string; file_data: string }
114
+ | { type: 'input_file'; file_url: string }
96
115
  >;
97
116
  };
98
117
 
@@ -199,11 +218,35 @@ export type OpenAIResponsesApplyPatchCallOutput = {
199
218
  output?: string;
200
219
  };
201
220
 
221
+ export type OpenAIResponsesToolSearchCall = {
222
+ type: 'tool_search_call';
223
+ id: string;
224
+ execution: 'server' | 'client';
225
+ call_id: string | null;
226
+ status: 'in_progress' | 'completed' | 'incomplete';
227
+ arguments: unknown;
228
+ };
229
+
230
+ export type OpenAIResponsesToolSearchOutput = {
231
+ type: 'tool_search_output';
232
+ id?: string;
233
+ execution: 'server' | 'client';
234
+ call_id: string | null;
235
+ status: 'in_progress' | 'completed' | 'incomplete';
236
+ tools: Array<JSONObject>;
237
+ };
238
+
202
239
  export type OpenAIResponsesItemReference = {
203
240
  type: 'item_reference';
204
241
  id: string;
205
242
  };
206
243
 
244
+ export type OpenAIResponsesCompactionItem = {
245
+ type: 'compaction';
246
+ id: string;
247
+ encrypted_content: string;
248
+ };
249
+
207
250
  /**
208
251
  * A filter used to compare a specified attribute key to a given value using a defined comparison operation.
209
252
  */
@@ -249,6 +292,7 @@ export type OpenAIResponsesTool =
249
292
  description: string | undefined;
250
293
  parameters: JSONSchema7;
251
294
  strict?: boolean;
295
+ defer_loading?: boolean;
252
296
  }
253
297
  | {
254
298
  type: 'apply_patch';
@@ -407,6 +451,12 @@ export type OpenAIResponsesTool =
407
451
  path: string;
408
452
  }>;
409
453
  };
454
+ }
455
+ | {
456
+ type: 'tool_search';
457
+ execution?: 'server' | 'client';
458
+ description?: string;
459
+ parameters?: Record<string, unknown>;
410
460
  };
411
461
 
412
462
  export type OpenAIResponsesReasoning = {
@@ -458,6 +508,31 @@ export const openaiResponsesChunkSchema = lazySchema(() =>
458
508
  service_tier: z.string().nullish(),
459
509
  }),
460
510
  }),
511
+ z.object({
512
+ type: z.literal('response.failed'),
513
+ response: z.object({
514
+ error: z
515
+ .object({
516
+ code: z.string().nullish(),
517
+ message: z.string(),
518
+ })
519
+ .nullish(),
520
+ incomplete_details: z.object({ reason: z.string() }).nullish(),
521
+ usage: z
522
+ .object({
523
+ input_tokens: z.number(),
524
+ input_tokens_details: z
525
+ .object({ cached_tokens: z.number().nullish() })
526
+ .nullish(),
527
+ output_tokens: z.number(),
528
+ output_tokens_details: z
529
+ .object({ reasoning_tokens: z.number().nullish() })
530
+ .nullish(),
531
+ })
532
+ .nullish(),
533
+ service_tier: z.string().nullish(),
534
+ }),
535
+ }),
461
536
  z.object({
462
537
  type: z.literal('response.created'),
463
538
  response: z.object({
@@ -573,6 +648,11 @@ export const openaiResponsesChunkSchema = lazySchema(() =>
573
648
  commands: z.array(z.string()),
574
649
  }),
575
650
  }),
651
+ z.object({
652
+ type: z.literal('compaction'),
653
+ id: z.string(),
654
+ encrypted_content: z.string().nullish(),
655
+ }),
576
656
  z.object({
577
657
  type: z.literal('shell_call_output'),
578
658
  id: z.string(),
@@ -592,6 +672,22 @@ export const openaiResponsesChunkSchema = lazySchema(() =>
592
672
  }),
593
673
  ),
594
674
  }),
675
+ z.object({
676
+ type: z.literal('tool_search_call'),
677
+ id: z.string(),
678
+ execution: z.enum(['server', 'client']),
679
+ call_id: z.string().nullable(),
680
+ status: z.enum(['in_progress', 'completed', 'incomplete']),
681
+ arguments: z.unknown(),
682
+ }),
683
+ z.object({
684
+ type: z.literal('tool_search_output'),
685
+ id: z.string(),
686
+ execution: z.enum(['server', 'client']),
687
+ call_id: z.string().nullable(),
688
+ status: z.enum(['in_progress', 'completed', 'incomplete']),
689
+ tools: z.array(z.record(z.string(), jsonValueSchema.optional())),
690
+ }),
595
691
  ]),
596
692
  }),
597
693
  z.object({
@@ -796,6 +892,11 @@ export const openaiResponsesChunkSchema = lazySchema(() =>
796
892
  commands: z.array(z.string()),
797
893
  }),
798
894
  }),
895
+ z.object({
896
+ type: z.literal('compaction'),
897
+ id: z.string(),
898
+ encrypted_content: z.string(),
899
+ }),
799
900
  z.object({
800
901
  type: z.literal('shell_call_output'),
801
902
  id: z.string(),
@@ -815,6 +916,22 @@ export const openaiResponsesChunkSchema = lazySchema(() =>
815
916
  }),
816
917
  ),
817
918
  }),
919
+ z.object({
920
+ type: z.literal('tool_search_call'),
921
+ id: z.string(),
922
+ execution: z.enum(['server', 'client']),
923
+ call_id: z.string().nullable(),
924
+ status: z.enum(['in_progress', 'completed', 'incomplete']),
925
+ arguments: z.unknown(),
926
+ }),
927
+ z.object({
928
+ type: z.literal('tool_search_output'),
929
+ id: z.string(),
930
+ execution: z.enum(['server', 'client']),
931
+ call_id: z.string().nullable(),
932
+ status: z.enum(['in_progress', 'completed', 'incomplete']),
933
+ tools: z.array(z.record(z.string(), jsonValueSchema.optional())),
934
+ }),
818
935
  ]),
819
936
  }),
820
937
  z.object({
@@ -1219,6 +1336,11 @@ export const openaiResponsesResponseSchema = lazySchema(() =>
1219
1336
  commands: z.array(z.string()),
1220
1337
  }),
1221
1338
  }),
1339
+ z.object({
1340
+ type: z.literal('compaction'),
1341
+ id: z.string(),
1342
+ encrypted_content: z.string(),
1343
+ }),
1222
1344
  z.object({
1223
1345
  type: z.literal('shell_call_output'),
1224
1346
  id: z.string(),
@@ -1238,6 +1360,22 @@ export const openaiResponsesResponseSchema = lazySchema(() =>
1238
1360
  }),
1239
1361
  ),
1240
1362
  }),
1363
+ z.object({
1364
+ type: z.literal('tool_search_call'),
1365
+ id: z.string(),
1366
+ execution: z.enum(['server', 'client']),
1367
+ call_id: z.string().nullable(),
1368
+ status: z.enum(['in_progress', 'completed', 'incomplete']),
1369
+ arguments: z.unknown(),
1370
+ }),
1371
+ z.object({
1372
+ type: z.literal('tool_search_output'),
1373
+ id: z.string(),
1374
+ execution: z.enum(['server', 'client']),
1375
+ call_id: z.string().nullable(),
1376
+ status: z.enum(['in_progress', 'completed', 'incomplete']),
1377
+ tools: z.array(z.record(z.string(), jsonValueSchema.optional())),
1378
+ }),
1241
1379
  ]),
1242
1380
  )
1243
1381
  .optional(),