@ai-sdk/openai 2.0.118 → 2.0.122

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.
@@ -33,10 +33,10 @@ var openaiFailedResponseHandler = createJsonErrorResponseHandler({
33
33
 
34
34
  // src/openai-language-model-capabilities.ts
35
35
  function getOpenAILanguageModelCapabilities(modelId) {
36
- var _a, _b, _c, _d, _e;
36
+ var _a2, _b, _c, _d, _e;
37
37
  const oSeriesVersion = getOSeriesVersion(modelId);
38
38
  const gptVersion = getGptVersion(modelId);
39
- const isGptChatModel = (gptVersion == null ? void 0 : gptVersion.minor) == null && ((_b = (_a = gptVersion == null ? void 0 : gptVersion.variant) == null ? void 0 : _a.startsWith("chat")) != null ? _b : false);
39
+ const isGptChatModel = (gptVersion == null ? void 0 : gptVersion.minor) == null && ((_b = (_a2 = gptVersion == null ? void 0 : gptVersion.variant) == null ? void 0 : _a2.startsWith("chat")) != null ? _b : false);
40
40
  const isGptNanoModel = (_d = (_c = gptVersion == null ? void 0 : gptVersion.variant) == null ? void 0 : _c.startsWith("nano")) != null ? _d : false;
41
41
  const supportsFlexProcessing = oSeriesVersion != null && oSeriesVersion >= 3 || gptVersion != null && gptVersion.major >= 5 && !isGptChatModel;
42
42
  const supportsPriorityProcessing = modelId.startsWith("gpt-4") || gptVersion != null && gptVersion.major >= 5 && !isGptNanoModel && !isGptChatModel || oSeriesVersion != null && oSeriesVersion >= 3;
@@ -72,9 +72,14 @@ import {
72
72
  UnsupportedFunctionalityError
73
73
  } from "@ai-sdk/provider";
74
74
  import { convertToBase64 } from "@ai-sdk/provider-utils";
75
+ function serializeToolCallArguments(input) {
76
+ return JSON.stringify(
77
+ typeof input === "object" && input !== null && !Array.isArray(input) ? input : {}
78
+ );
79
+ }
75
80
  function getPromptCacheBreakpoint(providerOptions) {
76
- var _a;
77
- return (_a = providerOptions == null ? void 0 : providerOptions.openai) == null ? void 0 : _a.promptCacheBreakpoint;
81
+ var _a2;
82
+ return (_a2 = providerOptions == null ? void 0 : providerOptions.openai) == null ? void 0 : _a2.promptCacheBreakpoint;
78
83
  }
79
84
  function convertToOpenAIChatMessages({
80
85
  prompt,
@@ -138,7 +143,7 @@ function convertToOpenAIChatMessages({
138
143
  messages.push({
139
144
  role: "user",
140
145
  content: content.map((part, index) => {
141
- var _a, _b, _c;
146
+ var _a2, _b, _c;
142
147
  switch (part.type) {
143
148
  case "text": {
144
149
  const promptCacheBreakpoint = getPromptCacheBreakpoint(
@@ -163,7 +168,7 @@ function convertToOpenAIChatMessages({
163
168
  image_url: {
164
169
  url: part.data instanceof URL ? part.data.toString() : `data:${mediaType};base64,${convertToBase64(part.data)}`,
165
170
  // OpenAI specific extension: image detail
166
- detail: (_b = (_a = part.providerOptions) == null ? void 0 : _a.openai) == null ? void 0 : _b.imageDetail
171
+ detail: (_b = (_a2 = part.providerOptions) == null ? void 0 : _a2.openai) == null ? void 0 : _b.imageDetail
167
172
  },
168
173
  ...promptCacheBreakpoint != null && {
169
174
  prompt_cache_breakpoint: promptCacheBreakpoint
@@ -262,7 +267,7 @@ function convertToOpenAIChatMessages({
262
267
  type: "function",
263
268
  function: {
264
269
  name: part.toolName,
265
- arguments: JSON.stringify(part.input)
270
+ arguments: serializeToolCallArguments(part.input)
266
271
  }
267
272
  });
268
273
  break;
@@ -705,13 +710,13 @@ var OpenAIChatLanguageModel = class {
705
710
  toolChoice,
706
711
  providerOptions
707
712
  }) {
708
- var _a, _b, _c, _d;
713
+ var _a2, _b, _c, _d;
709
714
  const warnings = [];
710
- const openaiOptions = (_a = await parseProviderOptions({
715
+ const openaiOptions = (_a2 = await parseProviderOptions({
711
716
  provider: "openai",
712
717
  providerOptions,
713
718
  schema: openaiChatLanguageModelOptions
714
- })) != null ? _a : {};
719
+ })) != null ? _a2 : {};
715
720
  const structuredOutputs = (_b = openaiOptions.structuredOutputs) != null ? _b : true;
716
721
  const modelCapabilities = getOpenAILanguageModelCapabilities(this.modelId);
717
722
  if (topK != null) {
@@ -885,7 +890,7 @@ var OpenAIChatLanguageModel = class {
885
890
  };
886
891
  }
887
892
  async doGenerate(options) {
888
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
893
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
889
894
  const { args: body, warnings } = await this.getArgs(options);
890
895
  const {
891
896
  responseHeaders,
@@ -911,7 +916,7 @@ var OpenAIChatLanguageModel = class {
911
916
  if (text != null && text.length > 0) {
912
917
  content.push({ type: "text", text });
913
918
  }
914
- for (const toolCall of (_a = choice.message.tool_calls) != null ? _a : []) {
919
+ for (const toolCall of (_a2 = choice.message.tool_calls) != null ? _a2 : []) {
915
920
  content.push({
916
921
  type: "tool-call",
917
922
  toolCallId: (_b = toolCall.id) != null ? _b : generateId(),
@@ -1005,7 +1010,7 @@ var OpenAIChatLanguageModel = class {
1005
1010
  controller.enqueue({ type: "stream-start", warnings });
1006
1011
  },
1007
1012
  transform(chunk, controller) {
1008
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y;
1013
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y;
1009
1014
  if (options.includeRawChunks) {
1010
1015
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
1011
1016
  }
@@ -1031,7 +1036,7 @@ var OpenAIChatLanguageModel = class {
1031
1036
  }
1032
1037
  }
1033
1038
  if (value.usage != null) {
1034
- usage.inputTokens = (_a = value.usage.prompt_tokens) != null ? _a : void 0;
1039
+ usage.inputTokens = (_a2 = value.usage.prompt_tokens) != null ? _a2 : void 0;
1035
1040
  usage.outputTokens = (_b = value.usage.completion_tokens) != null ? _b : void 0;
1036
1041
  usage.totalTokens = (_c = value.usage.total_tokens) != null ? _c : void 0;
1037
1042
  usage.reasoningTokens = (_e = (_d = value.usage.completion_tokens_details) == null ? void 0 : _d.reasoning_tokens) != null ? _e : void 0;
@@ -1506,7 +1511,7 @@ var OpenAICompletionLanguageModel = class {
1506
1511
  };
1507
1512
  }
1508
1513
  async doGenerate(options) {
1509
- var _a, _b, _c;
1514
+ var _a2, _b, _c;
1510
1515
  const { args, warnings } = await this.getArgs(options);
1511
1516
  const {
1512
1517
  responseHeaders,
@@ -1534,7 +1539,7 @@ var OpenAICompletionLanguageModel = class {
1534
1539
  return {
1535
1540
  content: [{ type: "text", text: choice.text }],
1536
1541
  usage: {
1537
- inputTokens: (_a = response.usage) == null ? void 0 : _a.prompt_tokens,
1542
+ inputTokens: (_a2 = response.usage) == null ? void 0 : _a2.prompt_tokens,
1538
1543
  outputTokens: (_b = response.usage) == null ? void 0 : _b.completion_tokens,
1539
1544
  totalTokens: (_c = response.usage) == null ? void 0 : _c.total_tokens
1540
1545
  },
@@ -1655,6 +1660,7 @@ import {
1655
1660
  import {
1656
1661
  combineHeaders as combineHeaders3,
1657
1662
  createJsonResponseHandler as createJsonResponseHandler3,
1663
+ EXPERIMENTAL_EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL,
1658
1664
  parseProviderOptions as parseProviderOptions3,
1659
1665
  postJsonToApi as postJsonToApi3
1660
1666
  } from "@ai-sdk/provider-utils";
@@ -1695,10 +1701,13 @@ var openaiTextEmbeddingResponseSchema = lazyValidator6(
1695
1701
  );
1696
1702
 
1697
1703
  // src/embedding/openai-embedding-model.ts
1704
+ var _a;
1705
+ _a = EXPERIMENTAL_EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL;
1698
1706
  var OpenAIEmbeddingModel = class {
1699
1707
  constructor(modelId, config) {
1700
1708
  this.specificationVersion = "v2";
1701
1709
  this.maxEmbeddingsPerCall = 2048;
1710
+ this[_a] = 3e5;
1702
1711
  this.supportsParallelCalls = true;
1703
1712
  this.modelId = modelId;
1704
1713
  this.config = config;
@@ -1712,7 +1721,7 @@ var OpenAIEmbeddingModel = class {
1712
1721
  abortSignal,
1713
1722
  providerOptions
1714
1723
  }) {
1715
- var _a;
1724
+ var _a2;
1716
1725
  if (values.length > this.maxEmbeddingsPerCall) {
1717
1726
  throw new TooManyEmbeddingValuesForCallError({
1718
1727
  provider: this.provider,
@@ -1721,11 +1730,11 @@ var OpenAIEmbeddingModel = class {
1721
1730
  values
1722
1731
  });
1723
1732
  }
1724
- const openaiOptions = (_a = await parseProviderOptions3({
1733
+ const openaiOptions = (_a2 = await parseProviderOptions3({
1725
1734
  provider: "openai",
1726
1735
  providerOptions,
1727
1736
  schema: openaiEmbeddingProviderOptions
1728
- })) != null ? _a : {};
1737
+ })) != null ? _a2 : {};
1729
1738
  const {
1730
1739
  responseHeaders,
1731
1740
  value: response,
@@ -1817,8 +1826,8 @@ function hasDefaultResponseFormat(modelId) {
1817
1826
  );
1818
1827
  }
1819
1828
  function getMaxImagesPerCall(modelId) {
1820
- var _a;
1821
- return (_a = modelMaxImagesPerCall[modelId]) != null ? _a : modelId.startsWith("gpt-image-") ? 10 : 1;
1829
+ var _a2;
1830
+ return (_a2 = modelMaxImagesPerCall[modelId]) != null ? _a2 : modelId.startsWith("gpt-image-") ? 10 : 1;
1822
1831
  }
1823
1832
  var baseImageModelOptionsObject = z9.object({
1824
1833
  /**
@@ -1893,7 +1902,7 @@ var OpenAIImageModel = class {
1893
1902
  headers,
1894
1903
  abortSignal
1895
1904
  }) {
1896
- var _a, _b, _c, _d;
1905
+ var _a2, _b, _c, _d;
1897
1906
  const warnings = [];
1898
1907
  if (aspectRatio != null) {
1899
1908
  warnings.push({
@@ -1905,7 +1914,7 @@ var OpenAIImageModel = class {
1905
1914
  if (seed != null) {
1906
1915
  warnings.push({ type: "unsupported-setting", setting: "seed" });
1907
1916
  }
1908
- const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
1917
+ const currentDate = (_c = (_b = (_a2 = this.config._internal) == null ? void 0 : _a2.currentDate) == null ? void 0 : _b.call(_a2)) != null ? _c : /* @__PURE__ */ new Date();
1909
1918
  const openaiOptions = (_d = await parseProviderOptions4({
1910
1919
  provider: "openai",
1911
1920
  providerOptions,
@@ -2195,8 +2204,8 @@ var OpenAITranscriptionModel = class {
2195
2204
  };
2196
2205
  }
2197
2206
  async doGenerate(options) {
2198
- var _a, _b, _c, _d, _e, _f, _g, _h;
2199
- const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
2207
+ var _a2, _b, _c, _d, _e, _f, _g, _h;
2208
+ const currentDate = (_c = (_b = (_a2 = this.config._internal) == null ? void 0 : _a2.currentDate) == null ? void 0 : _b.call(_a2)) != null ? _c : /* @__PURE__ */ new Date();
2200
2209
  const { formData, warnings } = await this.getArgs(options);
2201
2210
  const {
2202
2211
  value: response,
@@ -2330,8 +2339,8 @@ var OpenAISpeechModel = class {
2330
2339
  };
2331
2340
  }
2332
2341
  async doGenerate(options) {
2333
- var _a, _b, _c;
2334
- const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
2342
+ var _a2, _b, _c;
2343
+ const currentDate = (_c = (_b = (_a2 = this.config._internal) == null ? void 0 : _a2.currentDate) == null ? void 0 : _b.call(_a2)) != null ? _c : /* @__PURE__ */ new Date();
2335
2344
  const { requestBody, warnings } = await this.getArgs(options);
2336
2345
  const {
2337
2346
  value: audio,
@@ -2422,8 +2431,8 @@ var localShell = createProviderDefinedToolFactoryWithOutputSchema({
2422
2431
 
2423
2432
  // src/responses/convert-to-openai-responses-input.ts
2424
2433
  function getPromptCacheBreakpoint2(providerOptions) {
2425
- var _a;
2426
- return (_a = providerOptions == null ? void 0 : providerOptions.openai) == null ? void 0 : _a.promptCacheBreakpoint;
2434
+ var _a2;
2435
+ return (_a2 = providerOptions == null ? void 0 : providerOptions.openai) == null ? void 0 : _a2.promptCacheBreakpoint;
2427
2436
  }
2428
2437
  function isFileId(data, prefixes) {
2429
2438
  if (!prefixes) return false;
@@ -2436,7 +2445,7 @@ async function convertToOpenAIResponsesInput({
2436
2445
  store,
2437
2446
  hasLocalShellTool = false
2438
2447
  }) {
2439
- var _a, _b, _c, _d, _e, _f;
2448
+ var _a2, _b, _c, _d, _e, _f;
2440
2449
  let input = [];
2441
2450
  const warnings = [];
2442
2451
  for (const { role, content, providerOptions } of prompt) {
@@ -2491,7 +2500,7 @@ async function convertToOpenAIResponsesInput({
2491
2500
  input.push({
2492
2501
  role: "user",
2493
2502
  content: content.map((part, index) => {
2494
- var _a2, _b2, _c2;
2503
+ var _a3, _b2, _c2;
2495
2504
  switch (part.type) {
2496
2505
  case "text": {
2497
2506
  const promptCacheBreakpoint = getPromptCacheBreakpoint2(
@@ -2516,7 +2525,7 @@ async function convertToOpenAIResponsesInput({
2516
2525
  ...part.data instanceof URL ? { image_url: part.data.toString() } : typeof part.data === "string" && isFileId(part.data, fileIdPrefixes) ? { file_id: part.data } : {
2517
2526
  image_url: `data:${mediaType};base64,${convertToBase642(part.data)}`
2518
2527
  },
2519
- detail: (_b2 = (_a2 = part.providerOptions) == null ? void 0 : _a2.openai) == null ? void 0 : _b2.imageDetail,
2528
+ detail: (_b2 = (_a3 = part.providerOptions) == null ? void 0 : _a3.openai) == null ? void 0 : _b2.imageDetail,
2520
2529
  ...promptCacheBreakpoint != null && {
2521
2530
  prompt_cache_breakpoint: promptCacheBreakpoint
2522
2531
  }
@@ -2558,7 +2567,7 @@ async function convertToOpenAIResponsesInput({
2558
2567
  for (const part of content) {
2559
2568
  switch (part.type) {
2560
2569
  case "text": {
2561
- const id = (_b = (_a = part.providerOptions) == null ? void 0 : _a.openai) == null ? void 0 : _b.itemId;
2570
+ const id = (_b = (_a2 = part.providerOptions) == null ? void 0 : _a2.openai) == null ? void 0 : _b.itemId;
2562
2571
  const phase = (_d = (_c = part.providerOptions) == null ? void 0 : _c.openai) == null ? void 0 : _d.phase;
2563
2572
  if (store && id != null) {
2564
2573
  input.push({ type: "item_reference", id });
@@ -3902,7 +3911,7 @@ var OpenAIResponsesLanguageModel = class {
3902
3911
  toolChoice,
3903
3912
  responseFormat
3904
3913
  }) {
3905
- var _a, _b, _c, _d;
3914
+ var _a2, _b, _c, _d;
3906
3915
  const warnings = [];
3907
3916
  const modelCapabilities = getOpenAILanguageModelCapabilities(this.modelId);
3908
3917
  if (topK != null) {
@@ -3942,7 +3951,7 @@ var OpenAIResponsesLanguageModel = class {
3942
3951
  prompt,
3943
3952
  systemMessageMode: modelCapabilities.systemMessageMode,
3944
3953
  fileIdPrefixes: this.config.fileIdPrefixes,
3945
- store: (_a = openaiOptions == null ? void 0 : openaiOptions.store) != null ? _a : true,
3954
+ store: (_a2 = openaiOptions == null ? void 0 : openaiOptions.store) != null ? _a2 : true,
3946
3955
  hasLocalShellTool: hasOpenAITool("openai.local_shell")
3947
3956
  });
3948
3957
  warnings.push(...inputWarnings);
@@ -4120,7 +4129,7 @@ var OpenAIResponsesLanguageModel = class {
4120
4129
  };
4121
4130
  }
4122
4131
  async doGenerate(options) {
4123
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C;
4132
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C;
4124
4133
  const {
4125
4134
  args: body,
4126
4135
  warnings,
@@ -4173,7 +4182,7 @@ var OpenAIResponsesLanguageModel = class {
4173
4182
  providerMetadata: {
4174
4183
  [providerKey]: {
4175
4184
  itemId: part.id,
4176
- reasoningEncryptedContent: (_a = part.encrypted_content) != null ? _a : null
4185
+ reasoningEncryptedContent: (_a2 = part.encrypted_content) != null ? _a2 : null
4177
4186
  }
4178
4187
  }
4179
4188
  });
@@ -4486,7 +4495,7 @@ var OpenAIResponsesLanguageModel = class {
4486
4495
  controller.enqueue({ type: "stream-start", warnings });
4487
4496
  },
4488
4497
  transform(chunk, controller) {
4489
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y;
4498
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y;
4490
4499
  if (options.includeRawChunks) {
4491
4500
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
4492
4501
  }
@@ -4577,7 +4586,7 @@ var OpenAIResponsesLanguageModel = class {
4577
4586
  });
4578
4587
  } else if (value.item.type === "message") {
4579
4588
  ongoingAnnotations.splice(0, ongoingAnnotations.length);
4580
- activeMessagePhase = (_a = value.item.phase) != null ? _a : void 0;
4589
+ activeMessagePhase = (_a2 = value.item.phase) != null ? _a2 : void 0;
4581
4590
  controller.enqueue({
4582
4591
  type: "text-start",
4583
4592
  id: value.item.id,
@@ -4977,14 +4986,14 @@ function isErrorChunk(chunk) {
4977
4986
  return chunk.type === "error";
4978
4987
  }
4979
4988
  function mapWebSearchOutput(action) {
4980
- var _a;
4989
+ var _a2;
4981
4990
  if (action == null) {
4982
4991
  return {};
4983
4992
  }
4984
4993
  switch (action.type) {
4985
4994
  case "search":
4986
4995
  return {
4987
- action: { type: "search", query: (_a = action.query) != null ? _a : void 0 },
4996
+ action: { type: "search", query: (_a2 = action.query) != null ? _a2 : void 0 },
4988
4997
  // include sources when provided by the Responses API (behind include flag)
4989
4998
  ...action.sources != null && { sources: action.sources }
4990
4999
  };
@@ -5001,8 +5010,8 @@ function mapWebSearchOutput(action) {
5001
5010
  }
5002
5011
  }
5003
5012
  function getResponsesUsageMetadata(usage) {
5004
- var _a, _b, _c, _d;
5005
- const cacheWriteTokens = (_a = usage == null ? void 0 : usage.input_tokens_details) == null ? void 0 : _a.cache_write_tokens;
5013
+ var _a2, _b, _c, _d;
5014
+ const cacheWriteTokens = (_a2 = usage == null ? void 0 : usage.input_tokens_details) == null ? void 0 : _a2.cache_write_tokens;
5006
5015
  const orchestrationInputTokens = (_b = usage == null ? void 0 : usage.input_tokens_details) == null ? void 0 : _b.orchestration_input_tokens;
5007
5016
  const orchestrationInputCachedTokens = (_c = usage == null ? void 0 : usage.input_tokens_details) == null ? void 0 : _c.orchestration_input_cached_tokens;
5008
5017
  const orchestrationOutputTokens = (_d = usage == null ? void 0 : usage.output_tokens_details) == null ? void 0 : _d.orchestration_output_tokens;