@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.mjs CHANGED
@@ -40,10 +40,10 @@ var openaiFailedResponseHandler = createJsonErrorResponseHandler({
40
40
 
41
41
  // src/openai-language-model-capabilities.ts
42
42
  function getOpenAILanguageModelCapabilities(modelId) {
43
- var _a, _b, _c, _d, _e;
43
+ var _a2, _b, _c, _d, _e;
44
44
  const oSeriesVersion = getOSeriesVersion(modelId);
45
45
  const gptVersion = getGptVersion(modelId);
46
- 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);
46
+ 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);
47
47
  const isGptNanoModel = (_d = (_c = gptVersion == null ? void 0 : gptVersion.variant) == null ? void 0 : _c.startsWith("nano")) != null ? _d : false;
48
48
  const supportsFlexProcessing = oSeriesVersion != null && oSeriesVersion >= 3 || gptVersion != null && gptVersion.major >= 5 && !isGptChatModel;
49
49
  const supportsPriorityProcessing = modelId.startsWith("gpt-4") || gptVersion != null && gptVersion.major >= 5 && !isGptNanoModel && !isGptChatModel || oSeriesVersion != null && oSeriesVersion >= 3;
@@ -123,10 +123,10 @@ function createOpenAIStreamError({
123
123
  requestBodyValues,
124
124
  responseHeaders
125
125
  }) {
126
- var _a;
126
+ var _a2;
127
127
  const streamError = parseStreamError(frame);
128
128
  return new APICallError({
129
- message: (_a = streamError == null ? void 0 : streamError.message) != null ? _a : "OpenAI stream failed before any output was generated",
129
+ message: (_a2 = streamError == null ? void 0 : streamError.message) != null ? _a2 : "OpenAI stream failed before any output was generated",
130
130
  url,
131
131
  requestBodyValues,
132
132
  statusCode: streamError == null ? 500 : getStatusCode(streamError),
@@ -136,7 +136,7 @@ function createOpenAIStreamError({
136
136
  });
137
137
  }
138
138
  function parseStreamError(frame) {
139
- var _a;
139
+ var _a2;
140
140
  const value = asRecord(frame);
141
141
  if (value == null) {
142
142
  return void 0;
@@ -151,7 +151,7 @@ function parseStreamError(frame) {
151
151
  frame
152
152
  } : void 0;
153
153
  }
154
- const error = (_a = asRecord(value.error)) != null ? _a : value;
154
+ const error = (_a2 = asRecord(value.error)) != null ? _a2 : value;
155
155
  return typeof error.message === "string" && (asRecord(value.error) != null || typeof error.type === "string" || "code" in error || "param" in error) ? {
156
156
  message: error.message,
157
157
  code: getStringOrNumber(error.code),
@@ -199,7 +199,7 @@ function isHttpErrorStatusCode(value) {
199
199
 
200
200
  // src/chat/convert-openai-chat-usage.ts
201
201
  function convertOpenAIChatUsage(usage) {
202
- var _a, _b, _c, _d, _e, _f, _g, _h;
202
+ var _a2, _b, _c, _d, _e, _f, _g, _h;
203
203
  if (usage == null) {
204
204
  return {
205
205
  inputTokens: {
@@ -216,7 +216,7 @@ function convertOpenAIChatUsage(usage) {
216
216
  raw: void 0
217
217
  };
218
218
  }
219
- const promptTokens = (_a = usage.prompt_tokens) != null ? _a : 0;
219
+ const promptTokens = (_a2 = usage.prompt_tokens) != null ? _a2 : 0;
220
220
  const completionTokens = (_b = usage.completion_tokens) != null ? _b : 0;
221
221
  const cachedTokens = (_d = (_c = usage.prompt_tokens_details) == null ? void 0 : _c.cached_tokens) != null ? _d : 0;
222
222
  const cacheWriteTokens = (_f = (_e = usage.prompt_tokens_details) == null ? void 0 : _e.cache_write_tokens) != null ? _f : void 0;
@@ -243,17 +243,19 @@ import {
243
243
  } from "@ai-sdk/provider";
244
244
  import { convertToBase64 } from "@ai-sdk/provider-utils";
245
245
  function serializeToolCallArguments(input) {
246
- return JSON.stringify(input === void 0 ? {} : input);
246
+ return JSON.stringify(
247
+ typeof input === "object" && input !== null && !Array.isArray(input) ? input : {}
248
+ );
247
249
  }
248
250
  function getPromptCacheBreakpoint(providerOptions) {
249
- var _a;
250
- return (_a = providerOptions == null ? void 0 : providerOptions.openai) == null ? void 0 : _a.promptCacheBreakpoint;
251
+ var _a2;
252
+ return (_a2 = providerOptions == null ? void 0 : providerOptions.openai) == null ? void 0 : _a2.promptCacheBreakpoint;
251
253
  }
252
254
  function convertToOpenAIChatMessages({
253
255
  prompt,
254
256
  systemMessageMode = "system"
255
257
  }) {
256
- var _a, _b;
258
+ var _a2, _b;
257
259
  const messages = [];
258
260
  const warnings = [];
259
261
  for (const { role, content, providerOptions } of prompt) {
@@ -312,7 +314,7 @@ function convertToOpenAIChatMessages({
312
314
  messages.push({
313
315
  role: "user",
314
316
  content: content.map((part, index) => {
315
- var _a2, _b2, _c;
317
+ var _a3, _b2, _c;
316
318
  switch (part.type) {
317
319
  case "text": {
318
320
  const promptCacheBreakpoint = getPromptCacheBreakpoint(
@@ -337,7 +339,7 @@ function convertToOpenAIChatMessages({
337
339
  image_url: {
338
340
  url: part.data instanceof URL ? part.data.toString() : `data:${mediaType};base64,${convertToBase64(part.data)}`,
339
341
  // OpenAI specific extension: image detail
340
- detail: (_b2 = (_a2 = part.providerOptions) == null ? void 0 : _a2.openai) == null ? void 0 : _b2.imageDetail
342
+ detail: (_b2 = (_a3 = part.providerOptions) == null ? void 0 : _a3.openai) == null ? void 0 : _b2.imageDetail
341
343
  },
342
344
  ...promptCacheBreakpoint != null && {
343
345
  prompt_cache_breakpoint: promptCacheBreakpoint
@@ -456,7 +458,7 @@ function convertToOpenAIChatMessages({
456
458
  continue;
457
459
  }
458
460
  const output = toolResponse.output;
459
- 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);
461
+ 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);
460
462
  let contentValue;
461
463
  switch (output.type) {
462
464
  case "text":
@@ -898,13 +900,13 @@ var OpenAIChatLanguageModel = class {
898
900
  toolChoice,
899
901
  providerOptions
900
902
  }) {
901
- var _a, _b, _c, _d, _e;
903
+ var _a2, _b, _c, _d, _e;
902
904
  const warnings = [];
903
- const openaiOptions = (_a = await parseProviderOptions({
905
+ const openaiOptions = (_a2 = await parseProviderOptions({
904
906
  provider: "openai",
905
907
  providerOptions,
906
908
  schema: openaiLanguageModelChatOptions
907
- })) != null ? _a : {};
909
+ })) != null ? _a2 : {};
908
910
  const modelCapabilities = getOpenAILanguageModelCapabilities(this.modelId);
909
911
  const isReasoningModel = (_b = openaiOptions.forceReasoning) != null ? _b : modelCapabilities.isReasoningModel;
910
912
  if (topK != null) {
@@ -1066,7 +1068,7 @@ var OpenAIChatLanguageModel = class {
1066
1068
  };
1067
1069
  }
1068
1070
  async doGenerate(options) {
1069
- var _a, _b, _c, _d, _e, _f, _g;
1071
+ var _a2, _b, _c, _d, _e, _f, _g;
1070
1072
  const { args: body, warnings } = await this.getArgs(options);
1071
1073
  const {
1072
1074
  responseHeaders,
@@ -1092,7 +1094,7 @@ var OpenAIChatLanguageModel = class {
1092
1094
  if (text != null && text.length > 0) {
1093
1095
  content.push({ type: "text", text });
1094
1096
  }
1095
- for (const toolCall of (_a = choice.message.tool_calls) != null ? _a : []) {
1097
+ for (const toolCall of (_a2 = choice.message.tool_calls) != null ? _a2 : []) {
1096
1098
  content.push({
1097
1099
  type: "tool-call",
1098
1100
  toolCallId: (_b = toolCall.id) != null ? _b : generateId(),
@@ -1186,7 +1188,7 @@ var OpenAIChatLanguageModel = class {
1186
1188
  controller.enqueue({ type: "stream-start", warnings });
1187
1189
  },
1188
1190
  transform(chunk, controller) {
1189
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
1191
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
1190
1192
  if (options.includeRawChunks) {
1191
1193
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
1192
1194
  }
@@ -1213,7 +1215,7 @@ var OpenAIChatLanguageModel = class {
1213
1215
  }
1214
1216
  if (value.usage != null) {
1215
1217
  usage = value.usage;
1216
- if (((_a = value.usage.completion_tokens_details) == null ? void 0 : _a.accepted_prediction_tokens) != null) {
1218
+ if (((_a2 = value.usage.completion_tokens_details) == null ? void 0 : _a2.accepted_prediction_tokens) != null) {
1217
1219
  providerMetadata.openai.acceptedPredictionTokens = (_b = value.usage.completion_tokens_details) == null ? void 0 : _b.accepted_prediction_tokens;
1218
1220
  }
1219
1221
  if (((_c = value.usage.completion_tokens_details) == null ? void 0 : _c.rejected_prediction_tokens) != null) {
@@ -1320,7 +1322,7 @@ var OpenAIChatLanguageModel = class {
1320
1322
  }
1321
1323
  },
1322
1324
  flush(controller) {
1323
- var _a;
1325
+ var _a2;
1324
1326
  if (isActiveText) {
1325
1327
  controller.enqueue({ type: "text-end", id: "0" });
1326
1328
  }
@@ -1332,7 +1334,7 @@ var OpenAIChatLanguageModel = class {
1332
1334
  });
1333
1335
  controller.enqueue({
1334
1336
  type: "tool-call",
1335
- toolCallId: (_a = toolCall.id) != null ? _a : generateId(),
1337
+ toolCallId: (_a2 = toolCall.id) != null ? _a2 : generateId(),
1336
1338
  toolName: toolCall.function.name,
1337
1339
  input: toolCall.function.arguments
1338
1340
  });
@@ -1375,7 +1377,7 @@ import {
1375
1377
 
1376
1378
  // src/completion/convert-openai-completion-usage.ts
1377
1379
  function convertOpenAICompletionUsage(usage) {
1378
- var _a, _b, _c, _d;
1380
+ var _a2, _b, _c, _d;
1379
1381
  if (usage == null) {
1380
1382
  return {
1381
1383
  inputTokens: {
@@ -1392,7 +1394,7 @@ function convertOpenAICompletionUsage(usage) {
1392
1394
  raw: void 0
1393
1395
  };
1394
1396
  }
1395
- const promptTokens = (_a = usage.prompt_tokens) != null ? _a : 0;
1397
+ const promptTokens = (_a2 = usage.prompt_tokens) != null ? _a2 : 0;
1396
1398
  const completionTokens = (_b = usage.completion_tokens) != null ? _b : 0;
1397
1399
  return {
1398
1400
  inputTokens: {
@@ -1718,7 +1720,7 @@ var OpenAICompletionLanguageModel = class {
1718
1720
  };
1719
1721
  }
1720
1722
  async doGenerate(options) {
1721
- var _a;
1723
+ var _a2;
1722
1724
  const { args, warnings } = await this.getArgs(options);
1723
1725
  const {
1724
1726
  responseHeaders,
@@ -1748,7 +1750,7 @@ var OpenAICompletionLanguageModel = class {
1748
1750
  usage: convertOpenAICompletionUsage(response.usage),
1749
1751
  finishReason: {
1750
1752
  unified: mapOpenAIFinishReason2(choice.finish_reason),
1751
- raw: (_a = choice.finish_reason) != null ? _a : void 0
1753
+ raw: (_a2 = choice.finish_reason) != null ? _a2 : void 0
1752
1754
  },
1753
1755
  request: { body: args },
1754
1756
  response: {
@@ -1879,6 +1881,7 @@ import {
1879
1881
  import {
1880
1882
  combineHeaders as combineHeaders3,
1881
1883
  createJsonResponseHandler as createJsonResponseHandler3,
1884
+ EXPERIMENTAL_EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL,
1882
1885
  parseProviderOptions as parseProviderOptions3,
1883
1886
  postJsonToApi as postJsonToApi3
1884
1887
  } from "@ai-sdk/provider-utils";
@@ -1919,10 +1922,13 @@ var openaiTextEmbeddingResponseSchema = lazySchema6(
1919
1922
  );
1920
1923
 
1921
1924
  // src/embedding/openai-embedding-model.ts
1925
+ var _a;
1926
+ _a = EXPERIMENTAL_EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL;
1922
1927
  var OpenAIEmbeddingModel = class {
1923
1928
  constructor(modelId, config) {
1924
1929
  this.specificationVersion = "v3";
1925
1930
  this.maxEmbeddingsPerCall = 2048;
1931
+ this[_a] = 3e5;
1926
1932
  this.supportsParallelCalls = true;
1927
1933
  this.modelId = modelId;
1928
1934
  this.config = config;
@@ -1936,7 +1942,7 @@ var OpenAIEmbeddingModel = class {
1936
1942
  abortSignal,
1937
1943
  providerOptions
1938
1944
  }) {
1939
- var _a;
1945
+ var _a2;
1940
1946
  if (values.length > this.maxEmbeddingsPerCall) {
1941
1947
  throw new TooManyEmbeddingValuesForCallError({
1942
1948
  provider: this.provider,
@@ -1945,11 +1951,11 @@ var OpenAIEmbeddingModel = class {
1945
1951
  values
1946
1952
  });
1947
1953
  }
1948
- const openaiOptions = (_a = await parseProviderOptions3({
1954
+ const openaiOptions = (_a2 = await parseProviderOptions3({
1949
1955
  provider: "openai",
1950
1956
  providerOptions,
1951
1957
  schema: openaiEmbeddingModelOptions
1952
- })) != null ? _a : {};
1958
+ })) != null ? _a2 : {};
1953
1959
  const {
1954
1960
  responseHeaders,
1955
1961
  value: response,
@@ -2047,8 +2053,8 @@ function hasDefaultResponseFormat(modelId) {
2047
2053
  );
2048
2054
  }
2049
2055
  function getMaxImagesPerCall(modelId) {
2050
- var _a;
2051
- return (_a = modelMaxImagesPerCall[modelId]) != null ? _a : modelId.startsWith("gpt-image-") ? 10 : 1;
2056
+ var _a2;
2057
+ return (_a2 = modelMaxImagesPerCall[modelId]) != null ? _a2 : modelId.startsWith("gpt-image-") ? 10 : 1;
2052
2058
  }
2053
2059
  var baseImageModelOptionsObject = z9.object({
2054
2060
  /**
@@ -2135,7 +2141,7 @@ var OpenAIImageModel = class {
2135
2141
  headers,
2136
2142
  abortSignal
2137
2143
  }) {
2138
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
2144
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
2139
2145
  const warnings = [];
2140
2146
  if (aspectRatio != null) {
2141
2147
  warnings.push({
@@ -2147,7 +2153,7 @@ var OpenAIImageModel = class {
2147
2153
  if (seed != null) {
2148
2154
  warnings.push({ type: "unsupported", feature: "seed" });
2149
2155
  }
2150
- const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
2156
+ const currentDate = (_c = (_b = (_a2 = this.config._internal) == null ? void 0 : _a2.currentDate) == null ? void 0 : _b.call(_a2)) != null ? _c : /* @__PURE__ */ new Date();
2151
2157
  if (files != null) {
2152
2158
  const openaiOptions2 = (_d = await parseProviderOptions4({
2153
2159
  provider: "openai",
@@ -2210,10 +2216,10 @@ var OpenAIImageModel = class {
2210
2216
  providerMetadata: {
2211
2217
  openai: {
2212
2218
  images: response2.data.map((item, index) => {
2213
- var _a2, _b2, _c2, _d2, _e2, _f2;
2219
+ var _a3, _b2, _c2, _d2, _e2, _f2;
2214
2220
  return {
2215
2221
  ...item.revised_prompt ? { revisedPrompt: item.revised_prompt } : {},
2216
- created: (_a2 = response2.created) != null ? _a2 : void 0,
2222
+ created: (_a3 = response2.created) != null ? _a3 : void 0,
2217
2223
  size: (_b2 = response2.size) != null ? _b2 : void 0,
2218
2224
  quality: (_c2 = response2.quality) != null ? _c2 : void 0,
2219
2225
  background: (_d2 = response2.background) != null ? _d2 : void 0,
@@ -2277,10 +2283,10 @@ var OpenAIImageModel = class {
2277
2283
  providerMetadata: {
2278
2284
  openai: {
2279
2285
  images: response.data.map((item, index) => {
2280
- var _a2, _b2, _c2, _d2, _e2, _f2;
2286
+ var _a3, _b2, _c2, _d2, _e2, _f2;
2281
2287
  return {
2282
2288
  ...item.revised_prompt ? { revisedPrompt: item.revised_prompt } : {},
2283
- created: (_a2 = response.created) != null ? _a2 : void 0,
2289
+ created: (_a3 = response.created) != null ? _a3 : void 0,
2284
2290
  size: (_b2 = response.size) != null ? _b2 : void 0,
2285
2291
  quality: (_c2 = response.quality) != null ? _c2 : void 0,
2286
2292
  background: (_d2 = response.background) != null ? _d2 : void 0,
@@ -3024,7 +3030,7 @@ import {
3024
3030
 
3025
3031
  // src/responses/convert-openai-responses-usage.ts
3026
3032
  function convertOpenAIResponsesUsage(usage) {
3027
- var _a, _b, _c, _d, _e, _f;
3033
+ var _a2, _b, _c, _d, _e, _f;
3028
3034
  if (usage == null) {
3029
3035
  return {
3030
3036
  inputTokens: {
@@ -3043,7 +3049,7 @@ function convertOpenAIResponsesUsage(usage) {
3043
3049
  }
3044
3050
  const inputTokens = usage.input_tokens;
3045
3051
  const outputTokens = usage.output_tokens;
3046
- const cachedTokens = (_b = (_a = usage.input_tokens_details) == null ? void 0 : _a.cached_tokens) != null ? _b : 0;
3052
+ const cachedTokens = (_b = (_a2 = usage.input_tokens_details) == null ? void 0 : _a2.cached_tokens) != null ? _b : 0;
3047
3053
  const cacheWriteTokens = (_d = (_c = usage.input_tokens_details) == null ? void 0 : _c.cache_write_tokens) != null ? _d : void 0;
3048
3054
  const reasoningTokens = (_f = (_e = usage.output_tokens_details) == null ? void 0 : _e.reasoning_tokens) != null ? _f : 0;
3049
3055
  return {
@@ -3086,8 +3092,8 @@ function getParallelToolCallMetadata({
3086
3092
  providerOptions,
3087
3093
  providerOptionsName
3088
3094
  }) {
3089
- var _a;
3090
- const metadata = (_a = providerOptions == null ? void 0 : providerOptions[providerOptionsName]) == null ? void 0 : _a.parallelToolCall;
3095
+ var _a2;
3096
+ const metadata = (_a2 = providerOptions == null ? void 0 : providerOptions[providerOptionsName]) == null ? void 0 : _a2.parallelToolCall;
3091
3097
  if (!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) {
3092
3098
  return void 0;
3093
3099
  }
@@ -3162,19 +3168,19 @@ async function convertFunctionToolResultOutput({
3162
3168
  providerOptionsName,
3163
3169
  warnings
3164
3170
  }) {
3165
- var _a;
3171
+ var _a2;
3166
3172
  switch (output.type) {
3167
3173
  case "text":
3168
3174
  case "error-text":
3169
3175
  return output.value;
3170
3176
  case "execution-denied":
3171
- return (_a = output.reason) != null ? _a : "Tool call execution denied.";
3177
+ return (_a2 = output.reason) != null ? _a2 : "Tool call execution denied.";
3172
3178
  case "json":
3173
3179
  case "error-json":
3174
3180
  return JSON.stringify(output.value);
3175
3181
  case "content":
3176
3182
  return output.value.map((item) => {
3177
- var _a2, _b, _c, _d, _e;
3183
+ var _a3, _b, _c, _d, _e;
3178
3184
  const promptCacheBreakpoint = getPromptCacheBreakpoint2(
3179
3185
  item.providerOptions,
3180
3186
  providerOptionsName
@@ -3193,7 +3199,7 @@ async function convertFunctionToolResultOutput({
3193
3199
  return {
3194
3200
  type: "input_image",
3195
3201
  image_url: `data:${item.mediaType};base64,${item.data}`,
3196
- detail: (_b = (_a2 = item.providerOptions) == null ? void 0 : _a2[providerOptionsName]) == null ? void 0 : _b.imageDetail,
3202
+ detail: (_b = (_a3 = item.providerOptions) == null ? void 0 : _a3[providerOptionsName]) == null ? void 0 : _b.imageDetail,
3197
3203
  ...promptCacheBreakpoint != null && {
3198
3204
  prompt_cache_breakpoint: promptCacheBreakpoint
3199
3205
  }
@@ -3297,8 +3303,8 @@ function collectCompleteParallelToolResultGroups({
3297
3303
  return completeGroups;
3298
3304
  }
3299
3305
  function getPromptCacheBreakpoint2(providerOptions, providerOptionsName) {
3300
- var _a;
3301
- return (_a = providerOptions == null ? void 0 : providerOptions[providerOptionsName]) == null ? void 0 : _a.promptCacheBreakpoint;
3306
+ var _a2;
3307
+ return (_a2 = providerOptions == null ? void 0 : providerOptions[providerOptionsName]) == null ? void 0 : _a2.promptCacheBreakpoint;
3302
3308
  }
3303
3309
  function isFileId(data, prefixes) {
3304
3310
  if (!prefixes) return false;
@@ -3317,9 +3323,10 @@ async function convertToOpenAIResponsesInput({
3317
3323
  hasLocalShellTool = false,
3318
3324
  hasShellTool = false,
3319
3325
  hasApplyPatchTool = false,
3326
+ toolSearchToolName,
3320
3327
  customProviderToolNames
3321
3328
  }) {
3322
- 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;
3329
+ 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;
3323
3330
  let input = [];
3324
3331
  const warnings = [];
3325
3332
  const processedApprovalIds = /* @__PURE__ */ new Set();
@@ -3387,7 +3394,7 @@ async function convertToOpenAIResponsesInput({
3387
3394
  input.push({
3388
3395
  role: "user",
3389
3396
  content: content.map((part, index) => {
3390
- var _a2, _b2, _c2;
3397
+ var _a3, _b2, _c2;
3391
3398
  switch (part.type) {
3392
3399
  case "text": {
3393
3400
  const promptCacheBreakpoint = getPromptCacheBreakpoint2(
@@ -3414,7 +3421,7 @@ async function convertToOpenAIResponsesInput({
3414
3421
  ...part.data instanceof URL ? { image_url: part.data.toString() } : typeof part.data === "string" && isFileId(part.data, fileIdPrefixes) ? { file_id: part.data } : {
3415
3422
  image_url: `data:${mediaType};base64,${convertToBase642(part.data)}`
3416
3423
  },
3417
- detail: (_b2 = (_a2 = part.providerOptions) == null ? void 0 : _a2[providerOptionsName]) == null ? void 0 : _b2.imageDetail,
3424
+ detail: (_b2 = (_a3 = part.providerOptions) == null ? void 0 : _a3[providerOptionsName]) == null ? void 0 : _b2.imageDetail,
3418
3425
  ...promptCacheBreakpoint != null && {
3419
3426
  prompt_cache_breakpoint: promptCacheBreakpoint
3420
3427
  }
@@ -3455,7 +3462,7 @@ async function convertToOpenAIResponsesInput({
3455
3462
  for (const part of content) {
3456
3463
  switch (part.type) {
3457
3464
  case "text": {
3458
- const providerOpts = (_a = part.providerOptions) == null ? void 0 : _a[providerOptionsName];
3465
+ const providerOpts = (_a2 = part.providerOptions) == null ? void 0 : _a2[providerOptionsName];
3459
3466
  const id = providerOpts == null ? void 0 : providerOpts.itemId;
3460
3467
  const phase = providerOpts == null ? void 0 : providerOpts.phase;
3461
3468
  if (hasConversation && id != null) {
@@ -3510,7 +3517,7 @@ async function convertToOpenAIResponsesInput({
3510
3517
  const resolvedToolName = toolNameMapping.toProviderToolName(
3511
3518
  part.toolName
3512
3519
  );
3513
- if (resolvedToolName === "tool_search") {
3520
+ if (part.toolName === toolSearchToolName) {
3514
3521
  if (store && id != null) {
3515
3522
  input.push({ type: "item_reference", id });
3516
3523
  break;
@@ -3631,7 +3638,7 @@ async function convertToOpenAIResponsesInput({
3631
3638
  const resolvedResultToolName = toolNameMapping.toProviderToolName(
3632
3639
  part.toolName
3633
3640
  );
3634
- if (resolvedResultToolName === "tool_search") {
3641
+ if (part.toolName === toolSearchToolName) {
3635
3642
  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;
3636
3643
  if (store) {
3637
3644
  input.push({ type: "item_reference", id: itemId });
@@ -3829,7 +3836,7 @@ async function convertToOpenAIResponsesInput({
3829
3836
  const resolvedToolName = toolNameMapping.toProviderToolName(
3830
3837
  part.toolName
3831
3838
  );
3832
- if (resolvedToolName === "tool_search" && output.type === "json") {
3839
+ if (part.toolName === toolSearchToolName && output.type === "json") {
3833
3840
  const parsedOutput = await validateTypes({
3834
3841
  value: output.value,
3835
3842
  schema: toolSearchOutputSchema
@@ -3903,7 +3910,7 @@ async function convertToOpenAIResponsesInput({
3903
3910
  break;
3904
3911
  case "content":
3905
3912
  outputValue = output.value.map((item) => {
3906
- var _a2, _b2, _c2, _d2, _e2;
3913
+ var _a3, _b2, _c2, _d2, _e2;
3907
3914
  const promptCacheBreakpoint = getPromptCacheBreakpoint2(
3908
3915
  item.providerOptions,
3909
3916
  providerOptionsName
@@ -3921,7 +3928,7 @@ async function convertToOpenAIResponsesInput({
3921
3928
  return {
3922
3929
  type: "input_image",
3923
3930
  image_url: `data:${item.mediaType};base64,${item.data}`,
3924
- detail: (_b2 = (_a2 = item.providerOptions) == null ? void 0 : _a2[providerOptionsName]) == null ? void 0 : _b2.imageDetail,
3931
+ detail: (_b2 = (_a3 = item.providerOptions) == null ? void 0 : _a3[providerOptionsName]) == null ? void 0 : _b2.imageDetail,
3925
3932
  ...promptCacheBreakpoint != null && {
3926
3933
  prompt_cache_breakpoint: promptCacheBreakpoint
3927
3934
  }
@@ -5264,7 +5271,7 @@ async function prepareResponsesTools({
5264
5271
  toolNameMapping,
5265
5272
  customProviderToolNames
5266
5273
  }) {
5267
- var _a, _b, _c, _d;
5274
+ var _a2, _b, _c, _d;
5268
5275
  tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
5269
5276
  const toolWarnings = [];
5270
5277
  if (tools == null) {
@@ -5290,7 +5297,7 @@ async function prepareResponsesTools({
5290
5297
  for (const tool of tools) {
5291
5298
  switch (tool.type) {
5292
5299
  case "function": {
5293
- const openaiOptions = (_a = tool.providerOptions) == null ? void 0 : _a.openai;
5300
+ const openaiOptions = (_a2 = tool.providerOptions) == null ? void 0 : _a2.openai;
5294
5301
  const openaiFunctionTool = prepareFunctionTool({
5295
5302
  tool,
5296
5303
  options: openaiOptions
@@ -5707,13 +5714,13 @@ function mapShellSkills(skills) {
5707
5714
 
5708
5715
  // src/responses/openai-responses-language-model.ts
5709
5716
  function extractApprovalRequestIdToToolCallIdMapping(prompt) {
5710
- var _a, _b;
5717
+ var _a2, _b;
5711
5718
  const mapping = {};
5712
5719
  for (const message of prompt) {
5713
5720
  if (message.role !== "assistant") continue;
5714
5721
  for (const part of message.content) {
5715
5722
  if (part.type !== "tool-call") continue;
5716
- const approvalRequestId = (_b = (_a = part.providerOptions) == null ? void 0 : _a.openai) == null ? void 0 : _b.approvalRequestId;
5723
+ const approvalRequestId = (_b = (_a2 = part.providerOptions) == null ? void 0 : _a2.openai) == null ? void 0 : _b.approvalRequestId;
5717
5724
  if (approvalRequestId != null) {
5718
5725
  mapping[approvalRequestId] = part.toolCallId;
5719
5726
  }
@@ -5749,7 +5756,7 @@ var OpenAIResponsesLanguageModel = class {
5749
5756
  toolChoice,
5750
5757
  responseFormat
5751
5758
  }) {
5752
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
5759
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
5753
5760
  const warnings = [];
5754
5761
  const modelCapabilities = getOpenAILanguageModelCapabilities(this.modelId);
5755
5762
  if (topK != null) {
@@ -5780,7 +5787,7 @@ var OpenAIResponsesLanguageModel = class {
5780
5787
  schema: openaiLanguageModelResponsesOptionsSchema
5781
5788
  });
5782
5789
  }
5783
- const isReasoningModel = (_a = openaiOptions == null ? void 0 : openaiOptions.forceReasoning) != null ? _a : modelCapabilities.isReasoningModel;
5790
+ const isReasoningModel = (_a2 = openaiOptions == null ? void 0 : openaiOptions.forceReasoning) != null ? _a2 : modelCapabilities.isReasoningModel;
5784
5791
  if ((openaiOptions == null ? void 0 : openaiOptions.conversation) && (openaiOptions == null ? void 0 : openaiOptions.previousResponseId)) {
5785
5792
  warnings.push({
5786
5793
  type: "unsupported",
@@ -5829,6 +5836,7 @@ var OpenAIResponsesLanguageModel = class {
5829
5836
  hasLocalShellTool: hasOpenAITool("openai.local_shell"),
5830
5837
  hasShellTool: hasOpenAITool("openai.shell"),
5831
5838
  hasApplyPatchTool: hasOpenAITool("openai.apply_patch"),
5839
+ toolSearchToolName: getOpenAIToolName("openai.tool_search"),
5832
5840
  customProviderToolNames: customProviderToolNames.size > 0 ? customProviderToolNames : void 0
5833
5841
  });
5834
5842
  warnings.push(...inputWarnings);
@@ -5841,8 +5849,12 @@ var OpenAIResponsesLanguageModel = class {
5841
5849
  include = [...include, key];
5842
5850
  }
5843
5851
  }
5852
+ function getOpenAIToolName(id) {
5853
+ var _a3;
5854
+ return (_a3 = tools == null ? void 0 : tools.find((tool) => tool.type === "provider" && tool.id === id)) == null ? void 0 : _a3.name;
5855
+ }
5844
5856
  function hasOpenAITool(id) {
5845
- return (tools == null ? void 0 : tools.find((tool) => tool.type === "provider" && tool.id === id)) != null;
5857
+ return getOpenAIToolName(id) != null;
5846
5858
  }
5847
5859
  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;
5848
5860
  if (topLogprobs) {
@@ -6002,7 +6014,7 @@ var OpenAIResponsesLanguageModel = class {
6002
6014
  };
6003
6015
  }
6004
6016
  async doGenerate(options) {
6005
- 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;
6017
+ 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;
6006
6018
  const {
6007
6019
  args: body,
6008
6020
  warnings,
@@ -6044,7 +6056,7 @@ var OpenAIResponsesLanguageModel = class {
6044
6056
  }
6045
6057
  const content = [];
6046
6058
  const logprobs = [];
6047
- const functionTools = (_b = (_a = options.tools) == null ? void 0 : _a.filter(
6059
+ const functionTools = (_b = (_a2 = options.tools) == null ? void 0 : _a2.filter(
6048
6060
  (tool) => tool.type === "function"
6049
6061
  )) != null ? _b : [];
6050
6062
  let hasFunctionCall = false;
@@ -6496,7 +6508,7 @@ var OpenAIResponsesLanguageModel = class {
6496
6508
  };
6497
6509
  }
6498
6510
  async doStream(options) {
6499
- var _a, _b;
6511
+ var _a2, _b;
6500
6512
  const {
6501
6513
  args: body,
6502
6514
  warnings,
@@ -6534,7 +6546,7 @@ var OpenAIResponsesLanguageModel = class {
6534
6546
  });
6535
6547
  const self = this;
6536
6548
  const approvalRequestIdToDummyToolCallIdFromPrompt = extractApprovalRequestIdToToolCallIdMapping(options.prompt);
6537
- const functionTools = (_b = (_a = options.tools) == null ? void 0 : _a.filter(
6549
+ const functionTools = (_b = (_a2 = options.tools) == null ? void 0 : _a2.filter(
6538
6550
  (tool) => tool.type === "function"
6539
6551
  )) != null ? _b : [];
6540
6552
  const approvalRequestIdToDummyToolCallIdFromStream = /* @__PURE__ */ new Map();
@@ -6561,7 +6573,7 @@ var OpenAIResponsesLanguageModel = class {
6561
6573
  controller.enqueue({ type: "stream-start", warnings });
6562
6574
  },
6563
6575
  transform(chunk, controller) {
6564
- 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;
6576
+ 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;
6565
6577
  if (options.includeRawChunks) {
6566
6578
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
6567
6579
  }
@@ -6692,7 +6704,7 @@ var OpenAIResponsesLanguageModel = class {
6692
6704
  ongoingToolCalls[value.output_index] = {
6693
6705
  toolName,
6694
6706
  toolCallId,
6695
- toolSearchExecution: (_a2 = value.item.execution) != null ? _a2 : "server"
6707
+ toolSearchExecution: (_a3 = value.item.execution) != null ? _a3 : "server"
6696
6708
  };
6697
6709
  if (isHosted) {
6698
6710
  controller.enqueue({
@@ -6805,14 +6817,14 @@ var OpenAIResponsesLanguageModel = class {
6805
6817
  tools: functionTools
6806
6818
  });
6807
6819
  const enqueueUnexpandedToolCall = () => {
6808
- var _a3;
6820
+ var _a4;
6809
6821
  if (suppressInputStreaming) {
6810
6822
  controller.enqueue({
6811
6823
  type: "tool-input-start",
6812
6824
  id: item.call_id,
6813
6825
  toolName: item.name
6814
6826
  });
6815
- const bufferedInputDeltas = (_a3 = ongoingToolCall == null ? void 0 : ongoingToolCall.bufferedInputDeltas) != null ? _a3 : [];
6827
+ const bufferedInputDeltas = (_a4 = ongoingToolCall == null ? void 0 : ongoingToolCall.bufferedInputDeltas) != null ? _a4 : [];
6816
6828
  if (bufferedInputDeltas.length > 0) {
6817
6829
  for (const delta of bufferedInputDeltas) {
6818
6830
  controller.enqueue({
@@ -7483,7 +7495,7 @@ var OpenAIResponsesLanguageModel = class {
7483
7495
  }
7484
7496
  },
7485
7497
  flush(controller) {
7486
- var _a2;
7498
+ var _a3;
7487
7499
  for (const toolCall of Object.values(ongoingToolCalls)) {
7488
7500
  if (!(toolCall == null ? void 0 : toolCall.suppressInputStreaming)) {
7489
7501
  continue;
@@ -7493,7 +7505,7 @@ var OpenAIResponsesLanguageModel = class {
7493
7505
  id: toolCall.toolCallId,
7494
7506
  toolName: toolCall.toolName
7495
7507
  });
7496
- for (const delta of (_a2 = toolCall.bufferedInputDeltas) != null ? _a2 : []) {
7508
+ for (const delta of (_a3 = toolCall.bufferedInputDeltas) != null ? _a3 : []) {
7497
7509
  controller.enqueue({
7498
7510
  type: "tool-input-delta",
7499
7511
  id: toolCall.toolCallId,
@@ -7598,7 +7610,7 @@ function isResponseOutputChunk(chunk) {
7598
7610
  return !(chunk.type === "response.created" || chunk.type === "response.failed" || chunk.type === "error" || chunk.type === "unknown_chunk");
7599
7611
  }
7600
7612
  function mapWebSearchOutput(action) {
7601
- var _a;
7613
+ var _a2;
7602
7614
  if (action == null) {
7603
7615
  return {};
7604
7616
  }
@@ -7607,7 +7619,7 @@ function mapWebSearchOutput(action) {
7607
7619
  return {
7608
7620
  action: {
7609
7621
  type: "search",
7610
- query: (_a = action.query) != null ? _a : void 0,
7622
+ query: (_a2 = action.query) != null ? _a2 : void 0,
7611
7623
  ...action.queries != null && { queries: action.queries }
7612
7624
  },
7613
7625
  // include sources when provided by the Responses API (behind include flag)
@@ -7718,8 +7730,8 @@ var OpenAISpeechModel = class {
7718
7730
  };
7719
7731
  }
7720
7732
  async doGenerate(options) {
7721
- var _a, _b, _c;
7722
- const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
7733
+ var _a2, _b, _c;
7734
+ const currentDate = (_c = (_b = (_a2 = this.config._internal) == null ? void 0 : _a2.currentDate) == null ? void 0 : _b.call(_a2)) != null ? _c : /* @__PURE__ */ new Date();
7723
7735
  const { requestBody, warnings } = await this.getArgs(options);
7724
7736
  const {
7725
7737
  value: audio,
@@ -7953,8 +7965,8 @@ var OpenAITranscriptionModel = class {
7953
7965
  };
7954
7966
  }
7955
7967
  async doGenerate(options) {
7956
- var _a, _b, _c, _d, _e, _f, _g, _h;
7957
- const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
7968
+ var _a2, _b, _c, _d, _e, _f, _g, _h;
7969
+ const currentDate = (_c = (_b = (_a2 = this.config._internal) == null ? void 0 : _a2.currentDate) == null ? void 0 : _b.call(_a2)) != null ? _c : /* @__PURE__ */ new Date();
7958
7970
  const { formData, warnings } = await this.getArgs(options);
7959
7971
  const {
7960
7972
  value: response,
@@ -8000,17 +8012,17 @@ var OpenAITranscriptionModel = class {
8000
8012
  };
8001
8013
 
8002
8014
  // src/version.ts
8003
- var VERSION = true ? "3.0.102" : "0.0.0-test";
8015
+ var VERSION = true ? "3.0.104" : "0.0.0-test";
8004
8016
 
8005
8017
  // src/openai-provider.ts
8006
8018
  function createOpenAI(options = {}) {
8007
- var _a, _b;
8008
- const baseURL = (_a = withoutTrailingSlash(
8019
+ var _a2, _b;
8020
+ const baseURL = (_a2 = withoutTrailingSlash(
8009
8021
  loadOptionalSetting({
8010
8022
  settingValue: options.baseURL,
8011
8023
  environmentVariableName: "OPENAI_BASE_URL"
8012
8024
  })
8013
- )) != null ? _a : "https://api.openai.com/v1";
8025
+ )) != null ? _a2 : "https://api.openai.com/v1";
8014
8026
  const providerName = (_b = options.name) != null ? _b : "openai";
8015
8027
  const getHeaders = () => withUserAgentSuffix(
8016
8028
  {