@ai-sdk/openai 3.0.102 → 3.0.104

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.js CHANGED
@@ -54,10 +54,10 @@ var openaiFailedResponseHandler = (0, import_provider_utils.createJsonErrorRespo
54
54
 
55
55
  // src/openai-language-model-capabilities.ts
56
56
  function getOpenAILanguageModelCapabilities(modelId) {
57
- var _a, _b, _c, _d, _e;
57
+ var _a2, _b, _c, _d, _e;
58
58
  const oSeriesVersion = getOSeriesVersion(modelId);
59
59
  const gptVersion = getGptVersion(modelId);
60
- 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);
60
+ 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);
61
61
  const isGptNanoModel = (_d = (_c = gptVersion == null ? void 0 : gptVersion.variant) == null ? void 0 : _c.startsWith("nano")) != null ? _d : false;
62
62
  const supportsFlexProcessing = oSeriesVersion != null && oSeriesVersion >= 3 || gptVersion != null && gptVersion.major >= 5 && !isGptChatModel;
63
63
  const supportsPriorityProcessing = modelId.startsWith("gpt-4") || gptVersion != null && gptVersion.major >= 5 && !isGptNanoModel && !isGptChatModel || oSeriesVersion != null && oSeriesVersion >= 3;
@@ -137,10 +137,10 @@ function createOpenAIStreamError({
137
137
  requestBodyValues,
138
138
  responseHeaders
139
139
  }) {
140
- var _a;
140
+ var _a2;
141
141
  const streamError = parseStreamError(frame);
142
142
  return new import_provider.APICallError({
143
- message: (_a = streamError == null ? void 0 : streamError.message) != null ? _a : "OpenAI stream failed before any output was generated",
143
+ message: (_a2 = streamError == null ? void 0 : streamError.message) != null ? _a2 : "OpenAI stream failed before any output was generated",
144
144
  url,
145
145
  requestBodyValues,
146
146
  statusCode: streamError == null ? 500 : getStatusCode(streamError),
@@ -150,7 +150,7 @@ function createOpenAIStreamError({
150
150
  });
151
151
  }
152
152
  function parseStreamError(frame) {
153
- var _a;
153
+ var _a2;
154
154
  const value = asRecord(frame);
155
155
  if (value == null) {
156
156
  return void 0;
@@ -165,7 +165,7 @@ function parseStreamError(frame) {
165
165
  frame
166
166
  } : void 0;
167
167
  }
168
- const error = (_a = asRecord(value.error)) != null ? _a : value;
168
+ const error = (_a2 = asRecord(value.error)) != null ? _a2 : value;
169
169
  return typeof error.message === "string" && (asRecord(value.error) != null || typeof error.type === "string" || "code" in error || "param" in error) ? {
170
170
  message: error.message,
171
171
  code: getStringOrNumber(error.code),
@@ -213,7 +213,7 @@ function isHttpErrorStatusCode(value) {
213
213
 
214
214
  // src/chat/convert-openai-chat-usage.ts
215
215
  function convertOpenAIChatUsage(usage) {
216
- var _a, _b, _c, _d, _e, _f, _g, _h;
216
+ var _a2, _b, _c, _d, _e, _f, _g, _h;
217
217
  if (usage == null) {
218
218
  return {
219
219
  inputTokens: {
@@ -230,7 +230,7 @@ function convertOpenAIChatUsage(usage) {
230
230
  raw: void 0
231
231
  };
232
232
  }
233
- const promptTokens = (_a = usage.prompt_tokens) != null ? _a : 0;
233
+ const promptTokens = (_a2 = usage.prompt_tokens) != null ? _a2 : 0;
234
234
  const completionTokens = (_b = usage.completion_tokens) != null ? _b : 0;
235
235
  const cachedTokens = (_d = (_c = usage.prompt_tokens_details) == null ? void 0 : _c.cached_tokens) != null ? _d : 0;
236
236
  const cacheWriteTokens = (_f = (_e = usage.prompt_tokens_details) == null ? void 0 : _e.cache_write_tokens) != null ? _f : void 0;
@@ -255,17 +255,19 @@ function convertOpenAIChatUsage(usage) {
255
255
  var import_provider2 = require("@ai-sdk/provider");
256
256
  var import_provider_utils2 = require("@ai-sdk/provider-utils");
257
257
  function serializeToolCallArguments(input) {
258
- return JSON.stringify(input === void 0 ? {} : input);
258
+ return JSON.stringify(
259
+ typeof input === "object" && input !== null && !Array.isArray(input) ? input : {}
260
+ );
259
261
  }
260
262
  function getPromptCacheBreakpoint(providerOptions) {
261
- var _a;
262
- return (_a = providerOptions == null ? void 0 : providerOptions.openai) == null ? void 0 : _a.promptCacheBreakpoint;
263
+ var _a2;
264
+ return (_a2 = providerOptions == null ? void 0 : providerOptions.openai) == null ? void 0 : _a2.promptCacheBreakpoint;
263
265
  }
264
266
  function convertToOpenAIChatMessages({
265
267
  prompt,
266
268
  systemMessageMode = "system"
267
269
  }) {
268
- var _a, _b;
270
+ var _a2, _b;
269
271
  const messages = [];
270
272
  const warnings = [];
271
273
  for (const { role, content, providerOptions } of prompt) {
@@ -324,7 +326,7 @@ function convertToOpenAIChatMessages({
324
326
  messages.push({
325
327
  role: "user",
326
328
  content: content.map((part, index) => {
327
- var _a2, _b2, _c;
329
+ var _a3, _b2, _c;
328
330
  switch (part.type) {
329
331
  case "text": {
330
332
  const promptCacheBreakpoint = getPromptCacheBreakpoint(
@@ -349,7 +351,7 @@ function convertToOpenAIChatMessages({
349
351
  image_url: {
350
352
  url: part.data instanceof URL ? part.data.toString() : `data:${mediaType};base64,${(0, import_provider_utils2.convertToBase64)(part.data)}`,
351
353
  // OpenAI specific extension: image detail
352
- detail: (_b2 = (_a2 = part.providerOptions) == null ? void 0 : _a2.openai) == null ? void 0 : _b2.imageDetail
354
+ detail: (_b2 = (_a3 = part.providerOptions) == null ? void 0 : _a3.openai) == null ? void 0 : _b2.imageDetail
353
355
  },
354
356
  ...promptCacheBreakpoint != null && {
355
357
  prompt_cache_breakpoint: promptCacheBreakpoint
@@ -468,7 +470,7 @@ function convertToOpenAIChatMessages({
468
470
  continue;
469
471
  }
470
472
  const output = toolResponse.output;
471
- const promptCacheBreakpoint = (_a = output.type === "content" ? output.value.map((part) => getPromptCacheBreakpoint(part.providerOptions)).find((breakpoint) => breakpoint != null) : getPromptCacheBreakpoint(output.providerOptions)) != null ? _a : getPromptCacheBreakpoint(toolResponse.providerOptions);
473
+ const promptCacheBreakpoint = (_a2 = output.type === "content" ? output.value.map((part) => getPromptCacheBreakpoint(part.providerOptions)).find((breakpoint) => breakpoint != null) : getPromptCacheBreakpoint(output.providerOptions)) != null ? _a2 : getPromptCacheBreakpoint(toolResponse.providerOptions);
472
474
  let contentValue;
473
475
  switch (output.type) {
474
476
  case "text":
@@ -902,13 +904,13 @@ var OpenAIChatLanguageModel = class {
902
904
  toolChoice,
903
905
  providerOptions
904
906
  }) {
905
- var _a, _b, _c, _d, _e;
907
+ var _a2, _b, _c, _d, _e;
906
908
  const warnings = [];
907
- const openaiOptions = (_a = await (0, import_provider_utils5.parseProviderOptions)({
909
+ const openaiOptions = (_a2 = await (0, import_provider_utils5.parseProviderOptions)({
908
910
  provider: "openai",
909
911
  providerOptions,
910
912
  schema: openaiLanguageModelChatOptions
911
- })) != null ? _a : {};
913
+ })) != null ? _a2 : {};
912
914
  const modelCapabilities = getOpenAILanguageModelCapabilities(this.modelId);
913
915
  const isReasoningModel = (_b = openaiOptions.forceReasoning) != null ? _b : modelCapabilities.isReasoningModel;
914
916
  if (topK != null) {
@@ -1070,7 +1072,7 @@ var OpenAIChatLanguageModel = class {
1070
1072
  };
1071
1073
  }
1072
1074
  async doGenerate(options) {
1073
- var _a, _b, _c, _d, _e, _f, _g;
1075
+ var _a2, _b, _c, _d, _e, _f, _g;
1074
1076
  const { args: body, warnings } = await this.getArgs(options);
1075
1077
  const {
1076
1078
  responseHeaders,
@@ -1096,7 +1098,7 @@ var OpenAIChatLanguageModel = class {
1096
1098
  if (text != null && text.length > 0) {
1097
1099
  content.push({ type: "text", text });
1098
1100
  }
1099
- for (const toolCall of (_a = choice.message.tool_calls) != null ? _a : []) {
1101
+ for (const toolCall of (_a2 = choice.message.tool_calls) != null ? _a2 : []) {
1100
1102
  content.push({
1101
1103
  type: "tool-call",
1102
1104
  toolCallId: (_b = toolCall.id) != null ? _b : (0, import_provider_utils5.generateId)(),
@@ -1190,7 +1192,7 @@ var OpenAIChatLanguageModel = class {
1190
1192
  controller.enqueue({ type: "stream-start", warnings });
1191
1193
  },
1192
1194
  transform(chunk, controller) {
1193
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
1195
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
1194
1196
  if (options.includeRawChunks) {
1195
1197
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
1196
1198
  }
@@ -1217,7 +1219,7 @@ var OpenAIChatLanguageModel = class {
1217
1219
  }
1218
1220
  if (value.usage != null) {
1219
1221
  usage = value.usage;
1220
- if (((_a = value.usage.completion_tokens_details) == null ? void 0 : _a.accepted_prediction_tokens) != null) {
1222
+ if (((_a2 = value.usage.completion_tokens_details) == null ? void 0 : _a2.accepted_prediction_tokens) != null) {
1221
1223
  providerMetadata.openai.acceptedPredictionTokens = (_b = value.usage.completion_tokens_details) == null ? void 0 : _b.accepted_prediction_tokens;
1222
1224
  }
1223
1225
  if (((_c = value.usage.completion_tokens_details) == null ? void 0 : _c.rejected_prediction_tokens) != null) {
@@ -1324,7 +1326,7 @@ var OpenAIChatLanguageModel = class {
1324
1326
  }
1325
1327
  },
1326
1328
  flush(controller) {
1327
- var _a;
1329
+ var _a2;
1328
1330
  if (isActiveText) {
1329
1331
  controller.enqueue({ type: "text-end", id: "0" });
1330
1332
  }
@@ -1336,7 +1338,7 @@ var OpenAIChatLanguageModel = class {
1336
1338
  });
1337
1339
  controller.enqueue({
1338
1340
  type: "tool-call",
1339
- toolCallId: (_a = toolCall.id) != null ? _a : (0, import_provider_utils5.generateId)(),
1341
+ toolCallId: (_a2 = toolCall.id) != null ? _a2 : (0, import_provider_utils5.generateId)(),
1340
1342
  toolName: toolCall.function.name,
1341
1343
  input: toolCall.function.arguments
1342
1344
  });
@@ -1373,7 +1375,7 @@ var import_provider_utils8 = require("@ai-sdk/provider-utils");
1373
1375
 
1374
1376
  // src/completion/convert-openai-completion-usage.ts
1375
1377
  function convertOpenAICompletionUsage(usage) {
1376
- var _a, _b, _c, _d;
1378
+ var _a2, _b, _c, _d;
1377
1379
  if (usage == null) {
1378
1380
  return {
1379
1381
  inputTokens: {
@@ -1390,7 +1392,7 @@ function convertOpenAICompletionUsage(usage) {
1390
1392
  raw: void 0
1391
1393
  };
1392
1394
  }
1393
- const promptTokens = (_a = usage.prompt_tokens) != null ? _a : 0;
1395
+ const promptTokens = (_a2 = usage.prompt_tokens) != null ? _a2 : 0;
1394
1396
  const completionTokens = (_b = usage.completion_tokens) != null ? _b : 0;
1395
1397
  return {
1396
1398
  inputTokens: {
@@ -1707,7 +1709,7 @@ var OpenAICompletionLanguageModel = class {
1707
1709
  };
1708
1710
  }
1709
1711
  async doGenerate(options) {
1710
- var _a;
1712
+ var _a2;
1711
1713
  const { args, warnings } = await this.getArgs(options);
1712
1714
  const {
1713
1715
  responseHeaders,
@@ -1737,7 +1739,7 @@ var OpenAICompletionLanguageModel = class {
1737
1739
  usage: convertOpenAICompletionUsage(response.usage),
1738
1740
  finishReason: {
1739
1741
  unified: mapOpenAIFinishReason2(choice.finish_reason),
1740
- raw: (_a = choice.finish_reason) != null ? _a : void 0
1742
+ raw: (_a2 = choice.finish_reason) != null ? _a2 : void 0
1741
1743
  },
1742
1744
  request: { body: args },
1743
1745
  response: {
@@ -1898,10 +1900,13 @@ var openaiTextEmbeddingResponseSchema = (0, import_provider_utils10.lazySchema)(
1898
1900
  );
1899
1901
 
1900
1902
  // src/embedding/openai-embedding-model.ts
1903
+ var _a;
1904
+ _a = import_provider_utils11.EXPERIMENTAL_EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL;
1901
1905
  var OpenAIEmbeddingModel = class {
1902
1906
  constructor(modelId, config) {
1903
1907
  this.specificationVersion = "v3";
1904
1908
  this.maxEmbeddingsPerCall = 2048;
1909
+ this[_a] = 3e5;
1905
1910
  this.supportsParallelCalls = true;
1906
1911
  this.modelId = modelId;
1907
1912
  this.config = config;
@@ -1915,7 +1920,7 @@ var OpenAIEmbeddingModel = class {
1915
1920
  abortSignal,
1916
1921
  providerOptions
1917
1922
  }) {
1918
- var _a;
1923
+ var _a2;
1919
1924
  if (values.length > this.maxEmbeddingsPerCall) {
1920
1925
  throw new import_provider6.TooManyEmbeddingValuesForCallError({
1921
1926
  provider: this.provider,
@@ -1924,11 +1929,11 @@ var OpenAIEmbeddingModel = class {
1924
1929
  values
1925
1930
  });
1926
1931
  }
1927
- const openaiOptions = (_a = await (0, import_provider_utils11.parseProviderOptions)({
1932
+ const openaiOptions = (_a2 = await (0, import_provider_utils11.parseProviderOptions)({
1928
1933
  provider: "openai",
1929
1934
  providerOptions,
1930
1935
  schema: openaiEmbeddingModelOptions
1931
- })) != null ? _a : {};
1936
+ })) != null ? _a2 : {};
1932
1937
  const {
1933
1938
  responseHeaders,
1934
1939
  value: response,
@@ -2014,8 +2019,8 @@ function hasDefaultResponseFormat(modelId) {
2014
2019
  );
2015
2020
  }
2016
2021
  function getMaxImagesPerCall(modelId) {
2017
- var _a;
2018
- return (_a = modelMaxImagesPerCall[modelId]) != null ? _a : modelId.startsWith("gpt-image-") ? 10 : 1;
2022
+ var _a2;
2023
+ return (_a2 = modelMaxImagesPerCall[modelId]) != null ? _a2 : modelId.startsWith("gpt-image-") ? 10 : 1;
2019
2024
  }
2020
2025
  var baseImageModelOptionsObject = import_v49.z.object({
2021
2026
  /**
@@ -2102,7 +2107,7 @@ var OpenAIImageModel = class {
2102
2107
  headers,
2103
2108
  abortSignal
2104
2109
  }) {
2105
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
2110
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
2106
2111
  const warnings = [];
2107
2112
  if (aspectRatio != null) {
2108
2113
  warnings.push({
@@ -2114,7 +2119,7 @@ var OpenAIImageModel = class {
2114
2119
  if (seed != null) {
2115
2120
  warnings.push({ type: "unsupported", feature: "seed" });
2116
2121
  }
2117
- const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
2122
+ const currentDate = (_c = (_b = (_a2 = this.config._internal) == null ? void 0 : _a2.currentDate) == null ? void 0 : _b.call(_a2)) != null ? _c : /* @__PURE__ */ new Date();
2118
2123
  if (files != null) {
2119
2124
  const openaiOptions2 = (_d = await (0, import_provider_utils14.parseProviderOptions)({
2120
2125
  provider: "openai",
@@ -2177,10 +2182,10 @@ var OpenAIImageModel = class {
2177
2182
  providerMetadata: {
2178
2183
  openai: {
2179
2184
  images: response2.data.map((item, index) => {
2180
- var _a2, _b2, _c2, _d2, _e2, _f2;
2185
+ var _a3, _b2, _c2, _d2, _e2, _f2;
2181
2186
  return {
2182
2187
  ...item.revised_prompt ? { revisedPrompt: item.revised_prompt } : {},
2183
- created: (_a2 = response2.created) != null ? _a2 : void 0,
2188
+ created: (_a3 = response2.created) != null ? _a3 : void 0,
2184
2189
  size: (_b2 = response2.size) != null ? _b2 : void 0,
2185
2190
  quality: (_c2 = response2.quality) != null ? _c2 : void 0,
2186
2191
  background: (_d2 = response2.background) != null ? _d2 : void 0,
@@ -2244,10 +2249,10 @@ var OpenAIImageModel = class {
2244
2249
  providerMetadata: {
2245
2250
  openai: {
2246
2251
  images: response.data.map((item, index) => {
2247
- var _a2, _b2, _c2, _d2, _e2, _f2;
2252
+ var _a3, _b2, _c2, _d2, _e2, _f2;
2248
2253
  return {
2249
2254
  ...item.revised_prompt ? { revisedPrompt: item.revised_prompt } : {},
2250
- created: (_a2 = response.created) != null ? _a2 : void 0,
2255
+ created: (_a3 = response.created) != null ? _a3 : void 0,
2251
2256
  size: (_b2 = response.size) != null ? _b2 : void 0,
2252
2257
  quality: (_c2 = response.quality) != null ? _c2 : void 0,
2253
2258
  background: (_d2 = response.background) != null ? _d2 : void 0,
@@ -2937,7 +2942,7 @@ var import_provider_utils31 = require("@ai-sdk/provider-utils");
2937
2942
 
2938
2943
  // src/responses/convert-openai-responses-usage.ts
2939
2944
  function convertOpenAIResponsesUsage(usage) {
2940
- var _a, _b, _c, _d, _e, _f;
2945
+ var _a2, _b, _c, _d, _e, _f;
2941
2946
  if (usage == null) {
2942
2947
  return {
2943
2948
  inputTokens: {
@@ -2956,7 +2961,7 @@ function convertOpenAIResponsesUsage(usage) {
2956
2961
  }
2957
2962
  const inputTokens = usage.input_tokens;
2958
2963
  const outputTokens = usage.output_tokens;
2959
- const cachedTokens = (_b = (_a = usage.input_tokens_details) == null ? void 0 : _a.cached_tokens) != null ? _b : 0;
2964
+ const cachedTokens = (_b = (_a2 = usage.input_tokens_details) == null ? void 0 : _a2.cached_tokens) != null ? _b : 0;
2960
2965
  const cacheWriteTokens = (_d = (_c = usage.input_tokens_details) == null ? void 0 : _c.cache_write_tokens) != null ? _d : void 0;
2961
2966
  const reasoningTokens = (_f = (_e = usage.output_tokens_details) == null ? void 0 : _e.reasoning_tokens) != null ? _f : 0;
2962
2967
  return {
@@ -2989,8 +2994,8 @@ function getParallelToolCallMetadata({
2989
2994
  providerOptions,
2990
2995
  providerOptionsName
2991
2996
  }) {
2992
- var _a;
2993
- const metadata = (_a = providerOptions == null ? void 0 : providerOptions[providerOptionsName]) == null ? void 0 : _a.parallelToolCall;
2997
+ var _a2;
2998
+ const metadata = (_a2 = providerOptions == null ? void 0 : providerOptions[providerOptionsName]) == null ? void 0 : _a2.parallelToolCall;
2994
2999
  if (!(0, import_provider7.isJSONObject)(metadata) || typeof metadata.itemId !== "string" || typeof metadata.toolCallId !== "string" || typeof metadata.toolName !== "string" || typeof metadata.input !== "string" || typeof metadata.index !== "number" || !Number.isInteger(metadata.index) || typeof metadata.count !== "number" || !Number.isInteger(metadata.count) || metadata.index < 0 || metadata.count <= metadata.index) {
2995
3000
  return void 0;
2996
3001
  }
@@ -3065,19 +3070,19 @@ async function convertFunctionToolResultOutput({
3065
3070
  providerOptionsName,
3066
3071
  warnings
3067
3072
  }) {
3068
- var _a;
3073
+ var _a2;
3069
3074
  switch (output.type) {
3070
3075
  case "text":
3071
3076
  case "error-text":
3072
3077
  return output.value;
3073
3078
  case "execution-denied":
3074
- return (_a = output.reason) != null ? _a : "Tool call execution denied.";
3079
+ return (_a2 = output.reason) != null ? _a2 : "Tool call execution denied.";
3075
3080
  case "json":
3076
3081
  case "error-json":
3077
3082
  return JSON.stringify(output.value);
3078
3083
  case "content":
3079
3084
  return output.value.map((item) => {
3080
- var _a2, _b, _c, _d, _e;
3085
+ var _a3, _b, _c, _d, _e;
3081
3086
  const promptCacheBreakpoint = getPromptCacheBreakpoint2(
3082
3087
  item.providerOptions,
3083
3088
  providerOptionsName
@@ -3096,7 +3101,7 @@ async function convertFunctionToolResultOutput({
3096
3101
  return {
3097
3102
  type: "input_image",
3098
3103
  image_url: `data:${item.mediaType};base64,${item.data}`,
3099
- detail: (_b = (_a2 = item.providerOptions) == null ? void 0 : _a2[providerOptionsName]) == null ? void 0 : _b.imageDetail,
3104
+ detail: (_b = (_a3 = item.providerOptions) == null ? void 0 : _a3[providerOptionsName]) == null ? void 0 : _b.imageDetail,
3100
3105
  ...promptCacheBreakpoint != null && {
3101
3106
  prompt_cache_breakpoint: promptCacheBreakpoint
3102
3107
  }
@@ -3200,8 +3205,8 @@ function collectCompleteParallelToolResultGroups({
3200
3205
  return completeGroups;
3201
3206
  }
3202
3207
  function getPromptCacheBreakpoint2(providerOptions, providerOptionsName) {
3203
- var _a;
3204
- return (_a = providerOptions == null ? void 0 : providerOptions[providerOptionsName]) == null ? void 0 : _a.promptCacheBreakpoint;
3208
+ var _a2;
3209
+ return (_a2 = providerOptions == null ? void 0 : providerOptions[providerOptionsName]) == null ? void 0 : _a2.promptCacheBreakpoint;
3205
3210
  }
3206
3211
  function isFileId(data, prefixes) {
3207
3212
  if (!prefixes) return false;
@@ -3220,9 +3225,10 @@ async function convertToOpenAIResponsesInput({
3220
3225
  hasLocalShellTool = false,
3221
3226
  hasShellTool = false,
3222
3227
  hasApplyPatchTool = false,
3228
+ toolSearchToolName,
3223
3229
  customProviderToolNames
3224
3230
  }) {
3225
- 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;
3231
+ 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;
3226
3232
  let input = [];
3227
3233
  const warnings = [];
3228
3234
  const processedApprovalIds = /* @__PURE__ */ new Set();
@@ -3290,7 +3296,7 @@ async function convertToOpenAIResponsesInput({
3290
3296
  input.push({
3291
3297
  role: "user",
3292
3298
  content: content.map((part, index) => {
3293
- var _a2, _b2, _c2;
3299
+ var _a3, _b2, _c2;
3294
3300
  switch (part.type) {
3295
3301
  case "text": {
3296
3302
  const promptCacheBreakpoint = getPromptCacheBreakpoint2(
@@ -3317,7 +3323,7 @@ async function convertToOpenAIResponsesInput({
3317
3323
  ...part.data instanceof URL ? { image_url: part.data.toString() } : typeof part.data === "string" && isFileId(part.data, fileIdPrefixes) ? { file_id: part.data } : {
3318
3324
  image_url: `data:${mediaType};base64,${(0, import_provider_utils27.convertToBase64)(part.data)}`
3319
3325
  },
3320
- detail: (_b2 = (_a2 = part.providerOptions) == null ? void 0 : _a2[providerOptionsName]) == null ? void 0 : _b2.imageDetail,
3326
+ detail: (_b2 = (_a3 = part.providerOptions) == null ? void 0 : _a3[providerOptionsName]) == null ? void 0 : _b2.imageDetail,
3321
3327
  ...promptCacheBreakpoint != null && {
3322
3328
  prompt_cache_breakpoint: promptCacheBreakpoint
3323
3329
  }
@@ -3358,7 +3364,7 @@ async function convertToOpenAIResponsesInput({
3358
3364
  for (const part of content) {
3359
3365
  switch (part.type) {
3360
3366
  case "text": {
3361
- const providerOpts = (_a = part.providerOptions) == null ? void 0 : _a[providerOptionsName];
3367
+ const providerOpts = (_a2 = part.providerOptions) == null ? void 0 : _a2[providerOptionsName];
3362
3368
  const id = providerOpts == null ? void 0 : providerOpts.itemId;
3363
3369
  const phase = providerOpts == null ? void 0 : providerOpts.phase;
3364
3370
  if (hasConversation && id != null) {
@@ -3413,7 +3419,7 @@ async function convertToOpenAIResponsesInput({
3413
3419
  const resolvedToolName = toolNameMapping.toProviderToolName(
3414
3420
  part.toolName
3415
3421
  );
3416
- if (resolvedToolName === "tool_search") {
3422
+ if (part.toolName === toolSearchToolName) {
3417
3423
  if (store && id != null) {
3418
3424
  input.push({ type: "item_reference", id });
3419
3425
  break;
@@ -3534,7 +3540,7 @@ async function convertToOpenAIResponsesInput({
3534
3540
  const resolvedResultToolName = toolNameMapping.toProviderToolName(
3535
3541
  part.toolName
3536
3542
  );
3537
- if (resolvedResultToolName === "tool_search") {
3543
+ if (part.toolName === toolSearchToolName) {
3538
3544
  const itemId = (_s = (_r = (_o = (_n = part.providerOptions) == null ? void 0 : _n[providerOptionsName]) == null ? void 0 : _o.itemId) != null ? _r : (_q = (_p = part.providerMetadata) == null ? void 0 : _p[providerOptionsName]) == null ? void 0 : _q.itemId) != null ? _s : part.toolCallId;
3539
3545
  if (store) {
3540
3546
  input.push({ type: "item_reference", id: itemId });
@@ -3732,7 +3738,7 @@ async function convertToOpenAIResponsesInput({
3732
3738
  const resolvedToolName = toolNameMapping.toProviderToolName(
3733
3739
  part.toolName
3734
3740
  );
3735
- if (resolvedToolName === "tool_search" && output.type === "json") {
3741
+ if (part.toolName === toolSearchToolName && output.type === "json") {
3736
3742
  const parsedOutput = await (0, import_provider_utils27.validateTypes)({
3737
3743
  value: output.value,
3738
3744
  schema: toolSearchOutputSchema
@@ -3806,7 +3812,7 @@ async function convertToOpenAIResponsesInput({
3806
3812
  break;
3807
3813
  case "content":
3808
3814
  outputValue = output.value.map((item) => {
3809
- var _a2, _b2, _c2, _d2, _e2;
3815
+ var _a3, _b2, _c2, _d2, _e2;
3810
3816
  const promptCacheBreakpoint = getPromptCacheBreakpoint2(
3811
3817
  item.providerOptions,
3812
3818
  providerOptionsName
@@ -3824,7 +3830,7 @@ async function convertToOpenAIResponsesInput({
3824
3830
  return {
3825
3831
  type: "input_image",
3826
3832
  image_url: `data:${item.mediaType};base64,${item.data}`,
3827
- detail: (_b2 = (_a2 = item.providerOptions) == null ? void 0 : _a2[providerOptionsName]) == null ? void 0 : _b2.imageDetail,
3833
+ detail: (_b2 = (_a3 = item.providerOptions) == null ? void 0 : _a3[providerOptionsName]) == null ? void 0 : _b2.imageDetail,
3828
3834
  ...promptCacheBreakpoint != null && {
3829
3835
  prompt_cache_breakpoint: promptCacheBreakpoint
3830
3836
  }
@@ -5159,7 +5165,7 @@ async function prepareResponsesTools({
5159
5165
  toolNameMapping,
5160
5166
  customProviderToolNames
5161
5167
  }) {
5162
- var _a, _b, _c, _d;
5168
+ var _a2, _b, _c, _d;
5163
5169
  tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
5164
5170
  const toolWarnings = [];
5165
5171
  if (tools == null) {
@@ -5185,7 +5191,7 @@ async function prepareResponsesTools({
5185
5191
  for (const tool of tools) {
5186
5192
  switch (tool.type) {
5187
5193
  case "function": {
5188
- const openaiOptions = (_a = tool.providerOptions) == null ? void 0 : _a.openai;
5194
+ const openaiOptions = (_a2 = tool.providerOptions) == null ? void 0 : _a2.openai;
5189
5195
  const openaiFunctionTool = prepareFunctionTool({
5190
5196
  tool,
5191
5197
  options: openaiOptions
@@ -5602,13 +5608,13 @@ function mapShellSkills(skills) {
5602
5608
 
5603
5609
  // src/responses/openai-responses-language-model.ts
5604
5610
  function extractApprovalRequestIdToToolCallIdMapping(prompt) {
5605
- var _a, _b;
5611
+ var _a2, _b;
5606
5612
  const mapping = {};
5607
5613
  for (const message of prompt) {
5608
5614
  if (message.role !== "assistant") continue;
5609
5615
  for (const part of message.content) {
5610
5616
  if (part.type !== "tool-call") continue;
5611
- const approvalRequestId = (_b = (_a = part.providerOptions) == null ? void 0 : _a.openai) == null ? void 0 : _b.approvalRequestId;
5617
+ const approvalRequestId = (_b = (_a2 = part.providerOptions) == null ? void 0 : _a2.openai) == null ? void 0 : _b.approvalRequestId;
5612
5618
  if (approvalRequestId != null) {
5613
5619
  mapping[approvalRequestId] = part.toolCallId;
5614
5620
  }
@@ -5644,7 +5650,7 @@ var OpenAIResponsesLanguageModel = class {
5644
5650
  toolChoice,
5645
5651
  responseFormat
5646
5652
  }) {
5647
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
5653
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
5648
5654
  const warnings = [];
5649
5655
  const modelCapabilities = getOpenAILanguageModelCapabilities(this.modelId);
5650
5656
  if (topK != null) {
@@ -5675,7 +5681,7 @@ var OpenAIResponsesLanguageModel = class {
5675
5681
  schema: openaiLanguageModelResponsesOptionsSchema
5676
5682
  });
5677
5683
  }
5678
- const isReasoningModel = (_a = openaiOptions == null ? void 0 : openaiOptions.forceReasoning) != null ? _a : modelCapabilities.isReasoningModel;
5684
+ const isReasoningModel = (_a2 = openaiOptions == null ? void 0 : openaiOptions.forceReasoning) != null ? _a2 : modelCapabilities.isReasoningModel;
5679
5685
  if ((openaiOptions == null ? void 0 : openaiOptions.conversation) && (openaiOptions == null ? void 0 : openaiOptions.previousResponseId)) {
5680
5686
  warnings.push({
5681
5687
  type: "unsupported",
@@ -5724,6 +5730,7 @@ var OpenAIResponsesLanguageModel = class {
5724
5730
  hasLocalShellTool: hasOpenAITool("openai.local_shell"),
5725
5731
  hasShellTool: hasOpenAITool("openai.shell"),
5726
5732
  hasApplyPatchTool: hasOpenAITool("openai.apply_patch"),
5733
+ toolSearchToolName: getOpenAIToolName("openai.tool_search"),
5727
5734
  customProviderToolNames: customProviderToolNames.size > 0 ? customProviderToolNames : void 0
5728
5735
  });
5729
5736
  warnings.push(...inputWarnings);
@@ -5736,8 +5743,12 @@ var OpenAIResponsesLanguageModel = class {
5736
5743
  include = [...include, key];
5737
5744
  }
5738
5745
  }
5746
+ function getOpenAIToolName(id) {
5747
+ var _a3;
5748
+ return (_a3 = tools == null ? void 0 : tools.find((tool) => tool.type === "provider" && tool.id === id)) == null ? void 0 : _a3.name;
5749
+ }
5739
5750
  function hasOpenAITool(id) {
5740
- return (tools == null ? void 0 : tools.find((tool) => tool.type === "provider" && tool.id === id)) != null;
5751
+ return getOpenAIToolName(id) != null;
5741
5752
  }
5742
5753
  const topLogprobs = typeof (openaiOptions == null ? void 0 : openaiOptions.logprobs) === "number" ? openaiOptions == null ? void 0 : openaiOptions.logprobs : (openaiOptions == null ? void 0 : openaiOptions.logprobs) === true ? TOP_LOGPROBS_MAX : void 0;
5743
5754
  if (topLogprobs) {
@@ -5897,7 +5908,7 @@ var OpenAIResponsesLanguageModel = class {
5897
5908
  };
5898
5909
  }
5899
5910
  async doGenerate(options) {
5900
- 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, _D, _E;
5911
+ 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, _D, _E;
5901
5912
  const {
5902
5913
  args: body,
5903
5914
  warnings,
@@ -5939,7 +5950,7 @@ var OpenAIResponsesLanguageModel = class {
5939
5950
  }
5940
5951
  const content = [];
5941
5952
  const logprobs = [];
5942
- const functionTools = (_b = (_a = options.tools) == null ? void 0 : _a.filter(
5953
+ const functionTools = (_b = (_a2 = options.tools) == null ? void 0 : _a2.filter(
5943
5954
  (tool) => tool.type === "function"
5944
5955
  )) != null ? _b : [];
5945
5956
  let hasFunctionCall = false;
@@ -6391,7 +6402,7 @@ var OpenAIResponsesLanguageModel = class {
6391
6402
  };
6392
6403
  }
6393
6404
  async doStream(options) {
6394
- var _a, _b;
6405
+ var _a2, _b;
6395
6406
  const {
6396
6407
  args: body,
6397
6408
  warnings,
@@ -6429,7 +6440,7 @@ var OpenAIResponsesLanguageModel = class {
6429
6440
  });
6430
6441
  const self = this;
6431
6442
  const approvalRequestIdToDummyToolCallIdFromPrompt = extractApprovalRequestIdToToolCallIdMapping(options.prompt);
6432
- const functionTools = (_b = (_a = options.tools) == null ? void 0 : _a.filter(
6443
+ const functionTools = (_b = (_a2 = options.tools) == null ? void 0 : _a2.filter(
6433
6444
  (tool) => tool.type === "function"
6434
6445
  )) != null ? _b : [];
6435
6446
  const approvalRequestIdToDummyToolCallIdFromStream = /* @__PURE__ */ new Map();
@@ -6456,7 +6467,7 @@ var OpenAIResponsesLanguageModel = class {
6456
6467
  controller.enqueue({ type: "stream-start", warnings });
6457
6468
  },
6458
6469
  transform(chunk, controller) {
6459
- var _a2, _b2, _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, _D, _E, _F, _G, _H, _I, _J, _K, _L, _M, _N, _O, _P;
6470
+ var _a3, _b2, _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, _D, _E, _F, _G, _H, _I, _J, _K, _L, _M, _N, _O, _P;
6460
6471
  if (options.includeRawChunks) {
6461
6472
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
6462
6473
  }
@@ -6587,7 +6598,7 @@ var OpenAIResponsesLanguageModel = class {
6587
6598
  ongoingToolCalls[value.output_index] = {
6588
6599
  toolName,
6589
6600
  toolCallId,
6590
- toolSearchExecution: (_a2 = value.item.execution) != null ? _a2 : "server"
6601
+ toolSearchExecution: (_a3 = value.item.execution) != null ? _a3 : "server"
6591
6602
  };
6592
6603
  if (isHosted) {
6593
6604
  controller.enqueue({
@@ -6700,14 +6711,14 @@ var OpenAIResponsesLanguageModel = class {
6700
6711
  tools: functionTools
6701
6712
  });
6702
6713
  const enqueueUnexpandedToolCall = () => {
6703
- var _a3;
6714
+ var _a4;
6704
6715
  if (suppressInputStreaming) {
6705
6716
  controller.enqueue({
6706
6717
  type: "tool-input-start",
6707
6718
  id: item.call_id,
6708
6719
  toolName: item.name
6709
6720
  });
6710
- const bufferedInputDeltas = (_a3 = ongoingToolCall == null ? void 0 : ongoingToolCall.bufferedInputDeltas) != null ? _a3 : [];
6721
+ const bufferedInputDeltas = (_a4 = ongoingToolCall == null ? void 0 : ongoingToolCall.bufferedInputDeltas) != null ? _a4 : [];
6711
6722
  if (bufferedInputDeltas.length > 0) {
6712
6723
  for (const delta of bufferedInputDeltas) {
6713
6724
  controller.enqueue({
@@ -7378,7 +7389,7 @@ var OpenAIResponsesLanguageModel = class {
7378
7389
  }
7379
7390
  },
7380
7391
  flush(controller) {
7381
- var _a2;
7392
+ var _a3;
7382
7393
  for (const toolCall of Object.values(ongoingToolCalls)) {
7383
7394
  if (!(toolCall == null ? void 0 : toolCall.suppressInputStreaming)) {
7384
7395
  continue;
@@ -7388,7 +7399,7 @@ var OpenAIResponsesLanguageModel = class {
7388
7399
  id: toolCall.toolCallId,
7389
7400
  toolName: toolCall.toolName
7390
7401
  });
7391
- for (const delta of (_a2 = toolCall.bufferedInputDeltas) != null ? _a2 : []) {
7402
+ for (const delta of (_a3 = toolCall.bufferedInputDeltas) != null ? _a3 : []) {
7392
7403
  controller.enqueue({
7393
7404
  type: "tool-input-delta",
7394
7405
  id: toolCall.toolCallId,
@@ -7493,7 +7504,7 @@ function isResponseOutputChunk(chunk) {
7493
7504
  return !(chunk.type === "response.created" || chunk.type === "response.failed" || chunk.type === "error" || chunk.type === "unknown_chunk");
7494
7505
  }
7495
7506
  function mapWebSearchOutput(action) {
7496
- var _a;
7507
+ var _a2;
7497
7508
  if (action == null) {
7498
7509
  return {};
7499
7510
  }
@@ -7502,7 +7513,7 @@ function mapWebSearchOutput(action) {
7502
7513
  return {
7503
7514
  action: {
7504
7515
  type: "search",
7505
- query: (_a = action.query) != null ? _a : void 0,
7516
+ query: (_a2 = action.query) != null ? _a2 : void 0,
7506
7517
  ...action.queries != null && { queries: action.queries }
7507
7518
  },
7508
7519
  // include sources when provided by the Responses API (behind include flag)
@@ -7605,8 +7616,8 @@ var OpenAISpeechModel = class {
7605
7616
  };
7606
7617
  }
7607
7618
  async doGenerate(options) {
7608
- var _a, _b, _c;
7609
- const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
7619
+ var _a2, _b, _c;
7620
+ const currentDate = (_c = (_b = (_a2 = this.config._internal) == null ? void 0 : _a2.currentDate) == null ? void 0 : _b.call(_a2)) != null ? _c : /* @__PURE__ */ new Date();
7610
7621
  const { requestBody, warnings } = await this.getArgs(options);
7611
7622
  const {
7612
7623
  value: audio,
@@ -7830,8 +7841,8 @@ var OpenAITranscriptionModel = class {
7830
7841
  };
7831
7842
  }
7832
7843
  async doGenerate(options) {
7833
- var _a, _b, _c, _d, _e, _f, _g, _h;
7834
- const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
7844
+ var _a2, _b, _c, _d, _e, _f, _g, _h;
7845
+ const currentDate = (_c = (_b = (_a2 = this.config._internal) == null ? void 0 : _a2.currentDate) == null ? void 0 : _b.call(_a2)) != null ? _c : /* @__PURE__ */ new Date();
7835
7846
  const { formData, warnings } = await this.getArgs(options);
7836
7847
  const {
7837
7848
  value: response,
@@ -7877,17 +7888,17 @@ var OpenAITranscriptionModel = class {
7877
7888
  };
7878
7889
 
7879
7890
  // src/version.ts
7880
- var VERSION = true ? "3.0.102" : "0.0.0-test";
7891
+ var VERSION = true ? "3.0.104" : "0.0.0-test";
7881
7892
 
7882
7893
  // src/openai-provider.ts
7883
7894
  function createOpenAI(options = {}) {
7884
- var _a, _b;
7885
- const baseURL = (_a = (0, import_provider_utils37.withoutTrailingSlash)(
7895
+ var _a2, _b;
7896
+ const baseURL = (_a2 = (0, import_provider_utils37.withoutTrailingSlash)(
7886
7897
  (0, import_provider_utils37.loadOptionalSetting)({
7887
7898
  settingValue: options.baseURL,
7888
7899
  environmentVariableName: "OPENAI_BASE_URL"
7889
7900
  })
7890
- )) != null ? _a : "https://api.openai.com/v1";
7901
+ )) != null ? _a2 : "https://api.openai.com/v1";
7891
7902
  const providerName = (_b = options.name) != null ? _b : "openai";
7892
7903
  const getHeaders = () => (0, import_provider_utils37.withUserAgentSuffix)(
7893
7904
  {