@ai-sdk/openai 4.0.47 → 4.0.49

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.
@@ -34,10 +34,10 @@ var openaiFailedResponseHandler = createJsonErrorResponseHandler({
34
34
 
35
35
  // src/openai-language-model-capabilities.ts
36
36
  function getOpenAILanguageModelCapabilities(modelId) {
37
- var _a, _b, _c, _d, _e;
37
+ var _a2, _b, _c, _d, _e;
38
38
  const oSeriesVersion = getOSeriesVersion(modelId);
39
39
  const gptVersion = getGptVersion(modelId);
40
- 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);
40
+ 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);
41
41
  const isGptNanoModel = (_d = (_c = gptVersion == null ? void 0 : gptVersion.variant) == null ? void 0 : _c.startsWith("nano")) != null ? _d : false;
42
42
  const supportsFlexProcessing = oSeriesVersion != null && oSeriesVersion >= 3 || gptVersion != null && gptVersion.major >= 5 && !isGptChatModel;
43
43
  const supportsPriorityProcessing = modelId.startsWith("gpt-4") || gptVersion != null && gptVersion.major >= 5 && !isGptNanoModel && !isGptChatModel || oSeriesVersion != null && oSeriesVersion >= 3;
@@ -70,6 +70,25 @@ function getGptVersion(modelId) {
70
70
 
71
71
  // src/openai-stream-error.ts
72
72
  import { APICallError } from "@ai-sdk/provider";
73
+ import {
74
+ createProviderStreamError
75
+ } from "@ai-sdk/provider-utils";
76
+ function createOpenAIProviderStreamError(frame) {
77
+ var _a2, _b;
78
+ const streamError = parseStreamError(frame);
79
+ if (streamError == null) {
80
+ return void 0;
81
+ }
82
+ const statusCode = getStatusCode(streamError);
83
+ return createProviderStreamError({
84
+ message: streamError.message,
85
+ type: (_a2 = streamError.type) != null ? _a2 : void 0,
86
+ code: (_b = streamError.code) != null ? _b : void 0,
87
+ statusCode,
88
+ isRetryable: isRetryableStreamError(streamError, statusCode),
89
+ data: frame
90
+ });
91
+ }
73
92
  async function throwIfOpenAIStreamErrorBeforeOutput({
74
93
  stream,
75
94
  getError,
@@ -166,20 +185,21 @@ function createOpenAIStreamError({
166
185
  requestBodyValues,
167
186
  responseHeaders
168
187
  }) {
169
- var _a;
170
- const streamError = parseStreamError(frame);
188
+ var _a2, _b;
189
+ const streamError = createOpenAIProviderStreamError(frame);
171
190
  return new APICallError({
172
- message: (_a = streamError == null ? void 0 : streamError.message) != null ? _a : "OpenAI stream failed before any output was generated",
191
+ message: (_a2 = streamError == null ? void 0 : streamError.message) != null ? _a2 : "OpenAI stream failed before any output was generated",
173
192
  url,
174
193
  requestBodyValues,
175
- statusCode: streamError == null ? 500 : getStatusCode(streamError),
194
+ statusCode: (_b = streamError == null ? void 0 : streamError.statusCode) != null ? _b : 500,
176
195
  responseHeaders,
177
196
  responseBody: JSON.stringify(frame),
178
- data: frame
197
+ data: frame,
198
+ isRetryable: streamError == null ? void 0 : streamError.isRetryable
179
199
  });
180
200
  }
181
201
  function parseStreamError(frame) {
182
- var _a;
202
+ var _a2;
183
203
  const value = asRecord(frame);
184
204
  if (value == null) {
185
205
  return void 0;
@@ -190,27 +210,20 @@ function parseStreamError(frame) {
190
210
  return typeof (responseError == null ? void 0 : responseError.message) === "string" ? {
191
211
  message: responseError.message,
192
212
  code: getStringOrNumber(responseError.code),
193
- type: "response.failed",
194
- frame
213
+ type: "response.failed"
195
214
  } : void 0;
196
215
  }
197
- const error = (_a = asRecord(value.error)) != null ? _a : value;
216
+ const error = (_a2 = asRecord(value.error)) != null ? _a2 : value;
198
217
  return typeof error.message === "string" && (asRecord(value.error) != null || typeof error.type === "string" || "code" in error || "param" in error) ? {
199
218
  message: error.message,
200
219
  code: getStringOrNumber(error.code),
201
- type: typeof error.type === "string" ? error.type : void 0,
202
- frame
220
+ type: typeof error.type === "string" ? error.type : void 0
203
221
  } : void 0;
204
222
  }
205
223
  function getStatusCode(error) {
206
- if (typeof error.code === "number" && isHttpErrorStatusCode(error.code)) {
207
- return error.code;
208
- }
209
- if (typeof error.code === "string" && /^\d{3}$/.test(error.code)) {
210
- const numericCode = Number(error.code);
211
- if (isHttpErrorStatusCode(numericCode)) {
212
- return numericCode;
213
- }
224
+ const explicitStatusCode = getHttpStatusCode(error.code);
225
+ if (explicitStatusCode != null) {
226
+ return explicitStatusCode;
214
227
  }
215
228
  const discriminator = [error.code, error.type].filter((value) => typeof value === "string" || typeof value === "number").join(" ").toLowerCase();
216
229
  if (["insufficient_quota", "rate_limit"].some(
@@ -239,15 +252,28 @@ function getStringOrNumber(value) {
239
252
  function isHttpErrorStatusCode(value) {
240
253
  return Number.isInteger(value) && value >= 400 && value <= 599;
241
254
  }
255
+ function getHttpStatusCode(value) {
256
+ const statusCode = typeof value === "string" && /^\d{3}$/.test(value) ? Number(value) : value;
257
+ return typeof statusCode === "number" && isHttpErrorStatusCode(statusCode) ? statusCode : void 0;
258
+ }
259
+ function isRetryableStatusCode(statusCode) {
260
+ return statusCode === 408 || statusCode === 409 || statusCode === 429 || statusCode >= 500;
261
+ }
262
+ function isRetryableStreamError(error, statusCode) {
263
+ if (error.code === "insufficient_quota" || error.type === "insufficient_quota") {
264
+ return false;
265
+ }
266
+ return isRetryableStatusCode(statusCode);
267
+ }
242
268
 
243
269
  // src/chat/convert-openai-chat-usage.ts
244
270
  import { createNullLanguageModelUsage } from "@ai-sdk/provider-utils";
245
271
  function convertOpenAIChatUsage(usage) {
246
- var _a, _b, _c, _d, _e, _f, _g, _h;
272
+ var _a2, _b, _c, _d, _e, _f, _g, _h;
247
273
  if (usage == null) {
248
274
  return createNullLanguageModelUsage();
249
275
  }
250
- const promptTokens = (_a = usage.prompt_tokens) != null ? _a : 0;
276
+ const promptTokens = (_a2 = usage.prompt_tokens) != null ? _a2 : 0;
251
277
  const completionTokens = (_b = usage.completion_tokens) != null ? _b : 0;
252
278
  const cachedTokens = (_d = (_c = usage.prompt_tokens_details) == null ? void 0 : _c.cached_tokens) != null ? _d : 0;
253
279
  const cacheWriteTokens = (_f = (_e = usage.prompt_tokens_details) == null ? void 0 : _e.cache_write_tokens) != null ? _f : void 0;
@@ -279,17 +305,19 @@ import {
279
305
  resolveProviderReference
280
306
  } from "@ai-sdk/provider-utils";
281
307
  function serializeToolCallArguments(input) {
282
- return JSON.stringify(input === void 0 ? {} : input);
308
+ return JSON.stringify(
309
+ typeof input === "object" && input !== null && !Array.isArray(input) ? input : {}
310
+ );
283
311
  }
284
312
  function getPromptCacheBreakpoint(providerOptions) {
285
- var _a;
286
- return (_a = providerOptions == null ? void 0 : providerOptions.openai) == null ? void 0 : _a.promptCacheBreakpoint;
313
+ var _a2;
314
+ return (_a2 = providerOptions == null ? void 0 : providerOptions.openai) == null ? void 0 : _a2.promptCacheBreakpoint;
287
315
  }
288
316
  function convertToOpenAIChatMessages({
289
317
  prompt,
290
318
  systemMessageMode = "system"
291
319
  }) {
292
- var _a, _b;
320
+ var _a2, _b;
293
321
  const messages = [];
294
322
  const warnings = [];
295
323
  for (const { role, content, providerOptions } of prompt) {
@@ -348,7 +376,7 @@ function convertToOpenAIChatMessages({
348
376
  messages.push({
349
377
  role: "user",
350
378
  content: content.map((part, index) => {
351
- var _a2, _b2, _c;
379
+ var _a3, _b2, _c;
352
380
  switch (part.type) {
353
381
  case "text": {
354
382
  const promptCacheBreakpoint = getPromptCacheBreakpoint(
@@ -394,7 +422,7 @@ function convertToOpenAIChatMessages({
394
422
  type: "image_url",
395
423
  image_url: {
396
424
  url: part.data.type === "url" ? part.data.url.toString() : `data:${resolveFullMediaType({ part })};base64,${convertToBase64(part.data.data)}`,
397
- detail: (_b2 = (_a2 = part.providerOptions) == null ? void 0 : _a2.openai) == null ? void 0 : _b2.imageDetail
425
+ detail: (_b2 = (_a3 = part.providerOptions) == null ? void 0 : _a3.openai) == null ? void 0 : _b2.imageDetail
398
426
  },
399
427
  ...promptCacheBreakpoint != null && {
400
428
  prompt_cache_breakpoint: promptCacheBreakpoint
@@ -519,7 +547,7 @@ function convertToOpenAIChatMessages({
519
547
  continue;
520
548
  }
521
549
  const output = toolResponse.output;
522
- 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);
550
+ 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);
523
551
  let contentValue;
524
552
  switch (output.type) {
525
553
  case "text":
@@ -974,13 +1002,13 @@ var OpenAIChatLanguageModel = class _OpenAIChatLanguageModel {
974
1002
  reasoning,
975
1003
  providerOptions
976
1004
  }) {
977
- var _a, _b, _c, _d, _e, _f;
1005
+ var _a2, _b, _c, _d, _e, _f;
978
1006
  const warnings = [];
979
- const openaiOptions = (_a = await parseProviderOptions({
1007
+ const openaiOptions = (_a2 = await parseProviderOptions({
980
1008
  provider: "openai",
981
1009
  providerOptions,
982
1010
  schema: openaiLanguageModelChatOptions
983
- })) != null ? _a : {};
1011
+ })) != null ? _a2 : {};
984
1012
  const modelCapabilities = getOpenAILanguageModelCapabilities(this.modelId);
985
1013
  const resolvedReasoningEffort = (_b = openaiOptions.reasoningEffort) != null ? _b : isCustomReasoning(reasoning) ? reasoning : void 0;
986
1014
  const isReasoningModel = (_c = openaiOptions.forceReasoning) != null ? _c : modelCapabilities.isReasoningModel;
@@ -1143,7 +1171,7 @@ var OpenAIChatLanguageModel = class _OpenAIChatLanguageModel {
1143
1171
  };
1144
1172
  }
1145
1173
  async doGenerate(options) {
1146
- var _a, _b, _c, _d, _e, _f, _g;
1174
+ var _a2, _b, _c, _d, _e, _f, _g;
1147
1175
  const { args: body, warnings } = await this.getArgs(options);
1148
1176
  const {
1149
1177
  responseHeaders,
@@ -1154,7 +1182,7 @@ var OpenAIChatLanguageModel = class _OpenAIChatLanguageModel {
1154
1182
  path: "/chat/completions",
1155
1183
  modelId: this.modelId
1156
1184
  }),
1157
- headers: combineHeaders((_b = (_a = this.config).headers) == null ? void 0 : _b.call(_a), options.headers),
1185
+ headers: combineHeaders((_b = (_a2 = this.config).headers) == null ? void 0 : _b.call(_a2), options.headers),
1158
1186
  body,
1159
1187
  failedResponseHandler: openaiFailedResponseHandler,
1160
1188
  successfulResponseHandler: createJsonResponseHandler(
@@ -1215,7 +1243,7 @@ var OpenAIChatLanguageModel = class _OpenAIChatLanguageModel {
1215
1243
  };
1216
1244
  }
1217
1245
  async doStream(options) {
1218
- var _a, _b;
1246
+ var _a2, _b;
1219
1247
  const { args, warnings } = await this.getArgs(options);
1220
1248
  const body = {
1221
1249
  ...args,
@@ -1230,7 +1258,7 @@ var OpenAIChatLanguageModel = class _OpenAIChatLanguageModel {
1230
1258
  });
1231
1259
  const { responseHeaders, value: response } = await postJsonToApi({
1232
1260
  url,
1233
- headers: combineHeaders((_b = (_a = this.config).headers) == null ? void 0 : _b.call(_a), options.headers),
1261
+ headers: combineHeaders((_b = (_a2 = this.config).headers) == null ? void 0 : _b.call(_a2), options.headers),
1234
1262
  body,
1235
1263
  failedResponseHandler: openaiFailedResponseHandler,
1236
1264
  successfulResponseHandler: createEventSourceResponseHandler(
@@ -1267,7 +1295,7 @@ var OpenAIChatLanguageModel = class _OpenAIChatLanguageModel {
1267
1295
  controller.enqueue({ type: "stream-start", warnings });
1268
1296
  },
1269
1297
  transform(chunk, controller) {
1270
- var _a2, _b2, _c, _d, _e;
1298
+ var _a3, _b2, _c, _d, _e, _f;
1271
1299
  if (options.includeRawChunks) {
1272
1300
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
1273
1301
  }
@@ -1279,7 +1307,10 @@ var OpenAIChatLanguageModel = class _OpenAIChatLanguageModel {
1279
1307
  const value = chunk.value;
1280
1308
  if ("error" in value) {
1281
1309
  finishReason = { unified: "error", raw: void 0 };
1282
- controller.enqueue({ type: "error", error: value.error });
1310
+ controller.enqueue({
1311
+ type: "error",
1312
+ error: (_a3 = createOpenAIProviderStreamError(value.error)) != null ? _a3 : value.error
1313
+ });
1283
1314
  return;
1284
1315
  }
1285
1316
  if (!metadataExtracted) {
@@ -1294,11 +1325,11 @@ var OpenAIChatLanguageModel = class _OpenAIChatLanguageModel {
1294
1325
  }
1295
1326
  if (value.usage != null) {
1296
1327
  usage = value.usage;
1297
- if (((_a2 = value.usage.completion_tokens_details) == null ? void 0 : _a2.accepted_prediction_tokens) != null) {
1298
- providerMetadata.openai.acceptedPredictionTokens = (_b2 = value.usage.completion_tokens_details) == null ? void 0 : _b2.accepted_prediction_tokens;
1328
+ if (((_b2 = value.usage.completion_tokens_details) == null ? void 0 : _b2.accepted_prediction_tokens) != null) {
1329
+ providerMetadata.openai.acceptedPredictionTokens = (_c = value.usage.completion_tokens_details) == null ? void 0 : _c.accepted_prediction_tokens;
1299
1330
  }
1300
- if (((_c = value.usage.completion_tokens_details) == null ? void 0 : _c.rejected_prediction_tokens) != null) {
1301
- providerMetadata.openai.rejectedPredictionTokens = (_d = value.usage.completion_tokens_details) == null ? void 0 : _d.rejected_prediction_tokens;
1331
+ if (((_d = value.usage.completion_tokens_details) == null ? void 0 : _d.rejected_prediction_tokens) != null) {
1332
+ providerMetadata.openai.rejectedPredictionTokens = (_e = value.usage.completion_tokens_details) == null ? void 0 : _e.rejected_prediction_tokens;
1302
1333
  }
1303
1334
  }
1304
1335
  const choice = value.choices[0];
@@ -1308,7 +1339,7 @@ var OpenAIChatLanguageModel = class _OpenAIChatLanguageModel {
1308
1339
  raw: choice.finish_reason
1309
1340
  };
1310
1341
  }
1311
- if (((_e = choice == null ? void 0 : choice.logprobs) == null ? void 0 : _e.content) != null) {
1342
+ if (((_f = choice == null ? void 0 : choice.logprobs) == null ? void 0 : _f.content) != null) {
1312
1343
  providerMetadata.openai.logprobs = choice.logprobs.content;
1313
1344
  }
1314
1345
  if ((choice == null ? void 0 : choice.delta) == null) {
@@ -1388,11 +1419,11 @@ import {
1388
1419
  // src/completion/convert-openai-completion-usage.ts
1389
1420
  import { createNullLanguageModelUsage as createNullLanguageModelUsage2 } from "@ai-sdk/provider-utils";
1390
1421
  function convertOpenAICompletionUsage(usage) {
1391
- var _a, _b, _c, _d;
1422
+ var _a2, _b, _c, _d;
1392
1423
  if (usage == null) {
1393
1424
  return createNullLanguageModelUsage2();
1394
1425
  }
1395
- const promptTokens = (_a = usage.prompt_tokens) != null ? _a : 0;
1426
+ const promptTokens = (_a2 = usage.prompt_tokens) != null ? _a2 : 0;
1396
1427
  const completionTokens = (_b = usage.completion_tokens) != null ? _b : 0;
1397
1428
  return {
1398
1429
  inputTokens: {
@@ -1717,7 +1748,7 @@ var OpenAICompletionLanguageModel = class _OpenAICompletionLanguageModel {
1717
1748
  };
1718
1749
  }
1719
1750
  async doGenerate(options) {
1720
- var _a, _b, _c;
1751
+ var _a2, _b, _c;
1721
1752
  const { args, warnings } = await this.getArgs(options);
1722
1753
  const {
1723
1754
  responseHeaders,
@@ -1728,7 +1759,7 @@ var OpenAICompletionLanguageModel = class _OpenAICompletionLanguageModel {
1728
1759
  path: "/completions",
1729
1760
  modelId: this.modelId
1730
1761
  }),
1731
- headers: combineHeaders2((_b = (_a = this.config).headers) == null ? void 0 : _b.call(_a), options.headers),
1762
+ headers: combineHeaders2((_b = (_a2 = this.config).headers) == null ? void 0 : _b.call(_a2), options.headers),
1732
1763
  body: args,
1733
1764
  failedResponseHandler: openaiFailedResponseHandler,
1734
1765
  successfulResponseHandler: createJsonResponseHandler2(
@@ -1760,7 +1791,7 @@ var OpenAICompletionLanguageModel = class _OpenAICompletionLanguageModel {
1760
1791
  };
1761
1792
  }
1762
1793
  async doStream(options) {
1763
- var _a, _b;
1794
+ var _a2, _b;
1764
1795
  const { args, warnings } = await this.getArgs(options);
1765
1796
  const body = {
1766
1797
  ...args,
@@ -1775,7 +1806,7 @@ var OpenAICompletionLanguageModel = class _OpenAICompletionLanguageModel {
1775
1806
  });
1776
1807
  const { responseHeaders, value: response } = await postJsonToApi2({
1777
1808
  url,
1778
- headers: combineHeaders2((_b = (_a = this.config).headers) == null ? void 0 : _b.call(_a), options.headers),
1809
+ headers: combineHeaders2((_b = (_a2 = this.config).headers) == null ? void 0 : _b.call(_a2), options.headers),
1779
1810
  body,
1780
1811
  failedResponseHandler: openaiFailedResponseHandler,
1781
1812
  successfulResponseHandler: createEventSourceResponseHandler2(
@@ -1806,6 +1837,7 @@ var OpenAICompletionLanguageModel = class _OpenAICompletionLanguageModel {
1806
1837
  controller.enqueue({ type: "stream-start", warnings });
1807
1838
  },
1808
1839
  transform(chunk, controller) {
1840
+ var _a3;
1809
1841
  if (options.includeRawChunks) {
1810
1842
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
1811
1843
  }
@@ -1817,7 +1849,10 @@ var OpenAICompletionLanguageModel = class _OpenAICompletionLanguageModel {
1817
1849
  const value = chunk.value;
1818
1850
  if ("error" in value) {
1819
1851
  finishReason = { unified: "error", raw: void 0 };
1820
- controller.enqueue({ type: "error", error: value.error });
1852
+ controller.enqueue({
1853
+ type: "error",
1854
+ error: (_a3 = createOpenAIProviderStreamError(value.error)) != null ? _a3 : value.error
1855
+ });
1821
1856
  return;
1822
1857
  }
1823
1858
  if (isFirstChunk) {
@@ -1879,6 +1914,7 @@ import {
1879
1914
  import {
1880
1915
  combineHeaders as combineHeaders3,
1881
1916
  createJsonResponseHandler as createJsonResponseHandler3,
1917
+ EXPERIMENTAL_EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL,
1882
1918
  parseProviderOptions as parseProviderOptions3,
1883
1919
  postJsonToApi as postJsonToApi3,
1884
1920
  serializeModelOptions as serializeModelOptions3,
@@ -1922,15 +1958,17 @@ var openaiTextEmbeddingResponseSchema = lazySchema6(
1922
1958
  );
1923
1959
 
1924
1960
  // src/embedding/openai-embedding-model.ts
1961
+ var _a;
1925
1962
  var OpenAIEmbeddingModel = class _OpenAIEmbeddingModel {
1926
1963
  constructor(modelId, config) {
1927
1964
  this.specificationVersion = "v4";
1928
1965
  this.maxEmbeddingsPerCall = 2048;
1966
+ this[_a] = 3e5;
1929
1967
  this.supportsParallelCalls = true;
1930
1968
  this.modelId = modelId;
1931
1969
  this.config = config;
1932
1970
  }
1933
- static [WORKFLOW_SERIALIZE3](model) {
1971
+ static [(_a = EXPERIMENTAL_EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL, WORKFLOW_SERIALIZE3)](model) {
1934
1972
  return serializeModelOptions3({
1935
1973
  modelId: model.modelId,
1936
1974
  config: model.config
@@ -1948,7 +1986,7 @@ var OpenAIEmbeddingModel = class _OpenAIEmbeddingModel {
1948
1986
  abortSignal,
1949
1987
  providerOptions
1950
1988
  }) {
1951
- var _a, _b, _c;
1989
+ var _a2, _b, _c;
1952
1990
  if (values.length > this.maxEmbeddingsPerCall) {
1953
1991
  throw new TooManyEmbeddingValuesForCallError({
1954
1992
  provider: this.provider,
@@ -1957,11 +1995,11 @@ var OpenAIEmbeddingModel = class _OpenAIEmbeddingModel {
1957
1995
  values
1958
1996
  });
1959
1997
  }
1960
- const openaiOptions = (_a = await parseProviderOptions3({
1998
+ const openaiOptions = (_a2 = await parseProviderOptions3({
1961
1999
  provider: "openai",
1962
2000
  providerOptions,
1963
2001
  schema: openaiEmbeddingModelOptions
1964
- })) != null ? _a : {};
2002
+ })) != null ? _a2 : {};
1965
2003
  const {
1966
2004
  responseHeaders,
1967
2005
  value: response,
@@ -2062,8 +2100,8 @@ function hasDefaultResponseFormat(modelId) {
2062
2100
  );
2063
2101
  }
2064
2102
  function getMaxImagesPerCall(modelId) {
2065
- var _a;
2066
- return (_a = modelMaxImagesPerCall[modelId]) != null ? _a : modelId.startsWith("gpt-image-") ? 10 : 1;
2103
+ var _a2;
2104
+ return (_a2 = modelMaxImagesPerCall[modelId]) != null ? _a2 : modelId.startsWith("gpt-image-") ? 10 : 1;
2067
2105
  }
2068
2106
  var baseImageModelOptionsObject = z9.object({
2069
2107
  /**
@@ -2159,7 +2197,7 @@ var OpenAIImageModel = class _OpenAIImageModel {
2159
2197
  headers,
2160
2198
  abortSignal
2161
2199
  }) {
2162
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
2200
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
2163
2201
  const warnings = [];
2164
2202
  if (aspectRatio != null) {
2165
2203
  warnings.push({
@@ -2171,7 +2209,7 @@ var OpenAIImageModel = class _OpenAIImageModel {
2171
2209
  if (seed != null) {
2172
2210
  warnings.push({ type: "unsupported", feature: "seed" });
2173
2211
  }
2174
- const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
2212
+ const currentDate = (_c = (_b = (_a2 = this.config._internal) == null ? void 0 : _a2.currentDate) == null ? void 0 : _b.call(_a2)) != null ? _c : /* @__PURE__ */ new Date();
2175
2213
  if (files != null) {
2176
2214
  const openaiOptions2 = (_d = await parseProviderOptions4({
2177
2215
  provider: "openai",
@@ -2234,10 +2272,10 @@ var OpenAIImageModel = class _OpenAIImageModel {
2234
2272
  providerMetadata: {
2235
2273
  openai: {
2236
2274
  images: response2.data.map((item, index) => {
2237
- var _a2, _b2, _c2, _d2, _e2, _f2;
2275
+ var _a3, _b2, _c2, _d2, _e2, _f2;
2238
2276
  return {
2239
2277
  ...item.revised_prompt ? { revisedPrompt: item.revised_prompt } : {},
2240
- created: (_a2 = response2.created) != null ? _a2 : void 0,
2278
+ created: (_a3 = response2.created) != null ? _a3 : void 0,
2241
2279
  size: (_b2 = response2.size) != null ? _b2 : void 0,
2242
2280
  quality: (_c2 = response2.quality) != null ? _c2 : void 0,
2243
2281
  background: (_d2 = response2.background) != null ? _d2 : void 0,
@@ -2301,10 +2339,10 @@ var OpenAIImageModel = class _OpenAIImageModel {
2301
2339
  providerMetadata: {
2302
2340
  openai: {
2303
2341
  images: response.data.map((item, index) => {
2304
- var _a2, _b2, _c2, _d2, _e2, _f2;
2342
+ var _a3, _b2, _c2, _d2, _e2, _f2;
2305
2343
  return {
2306
2344
  ...item.revised_prompt ? { revisedPrompt: item.revised_prompt } : {},
2307
- created: (_a2 = response.created) != null ? _a2 : void 0,
2345
+ created: (_a3 = response.created) != null ? _a3 : void 0,
2308
2346
  size: (_b2 = response.size) != null ? _b2 : void 0,
2309
2347
  quality: (_c2 = response.quality) != null ? _c2 : void 0,
2310
2348
  background: (_d2 = response.background) != null ? _d2 : void 0,
@@ -2589,13 +2627,13 @@ var OpenAITranscriptionModel = class _OpenAITranscriptionModel {
2589
2627
  };
2590
2628
  }
2591
2629
  async doGenerate(options) {
2592
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
2630
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j;
2593
2631
  if (isRealtimeTranscriptionModelId(this.modelId)) {
2594
2632
  throw new UnsupportedFunctionalityError4({
2595
2633
  functionality: `non-streaming transcription with ${this.modelId}`
2596
2634
  });
2597
2635
  }
2598
- const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
2636
+ const currentDate = (_c = (_b = (_a2 = this.config._internal) == null ? void 0 : _a2.currentDate) == null ? void 0 : _b.call(_a2)) != null ? _c : /* @__PURE__ */ new Date();
2599
2637
  const { formData, warnings } = await this.getArgs(options);
2600
2638
  const {
2601
2639
  value: response,
@@ -2639,13 +2677,13 @@ var OpenAITranscriptionModel = class _OpenAITranscriptionModel {
2639
2677
  };
2640
2678
  }
2641
2679
  async doStream(options) {
2642
- var _a, _b, _c, _d, _e, _f, _g;
2680
+ var _a2, _b, _c, _d, _e, _f, _g;
2643
2681
  if (!isRealtimeTranscriptionModelId(this.modelId)) {
2644
2682
  throw new UnsupportedFunctionalityError4({
2645
2683
  functionality: `streaming transcription with ${this.modelId}`
2646
2684
  });
2647
2685
  }
2648
- const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
2686
+ const currentDate = (_c = (_b = (_a2 = this.config._internal) == null ? void 0 : _a2.currentDate) == null ? void 0 : _b.call(_a2)) != null ? _c : /* @__PURE__ */ new Date();
2649
2687
  const openAIOptions = await parseProviderOptions5({
2650
2688
  provider: "openai",
2651
2689
  providerOptions: options.providerOptions,
@@ -2784,7 +2822,7 @@ function createOpenAIRealtimeTranscriptionStream({
2784
2822
  void sendAudio(socket).catch(finishWithError);
2785
2823
  },
2786
2824
  onMessageText: async (text) => {
2787
- var _a, _b, _c, _d;
2825
+ var _a2, _b, _c, _d;
2788
2826
  const parsed = await safeParseJSON({ text });
2789
2827
  if (!parsed.success) return;
2790
2828
  const raw = parsed.value;
@@ -2796,7 +2834,7 @@ function createOpenAIRealtimeTranscriptionStream({
2796
2834
  controller.enqueue({
2797
2835
  type: "transcript-delta",
2798
2836
  id: raw.item_id,
2799
- delta: (_a = raw.delta) != null ? _a : ""
2837
+ delta: (_a2 = raw.delta) != null ? _a2 : ""
2800
2838
  });
2801
2839
  break;
2802
2840
  }
@@ -2835,7 +2873,7 @@ function buildOpenAIRealtimeTranscriptionSession({
2835
2873
  inputAudioFormat,
2836
2874
  providerOptions
2837
2875
  }) {
2838
- var _a, _b;
2876
+ var _a2, _b;
2839
2877
  return {
2840
2878
  type: "session.update",
2841
2879
  session: {
@@ -2849,7 +2887,7 @@ function buildOpenAIRealtimeTranscriptionSession({
2849
2887
  transcription: {
2850
2888
  model: modelId,
2851
2889
  ...(providerOptions == null ? void 0 : providerOptions.language) != null ? { language: providerOptions.language } : {},
2852
- ...((_a = providerOptions == null ? void 0 : providerOptions.streaming) == null ? void 0 : _a.delay) != null ? { delay: providerOptions.streaming.delay } : {}
2890
+ ...((_a2 = providerOptions == null ? void 0 : providerOptions.streaming) == null ? void 0 : _a2.delay) != null ? { delay: providerOptions.streaming.delay } : {}
2853
2891
  },
2854
2892
  turn_detection: null
2855
2893
  }
@@ -2859,14 +2897,14 @@ function buildOpenAIRealtimeTranscriptionSession({
2859
2897
  };
2860
2898
  }
2861
2899
  function getOpenAIRealtimeConnection(headers) {
2862
- var _a;
2900
+ var _a2;
2863
2901
  let authorization;
2864
2902
  for (const [key, value] of Object.entries(headers)) {
2865
2903
  if (key.toLowerCase() === "authorization" && value != null) {
2866
2904
  authorization = value;
2867
2905
  }
2868
2906
  }
2869
- const token = (_a = authorization == null ? void 0 : authorization.match(/^bearer\s+(.+)$/i)) == null ? void 0 : _a[1];
2907
+ const token = (_a2 = authorization == null ? void 0 : authorization.match(/^bearer\s+(.+)$/i)) == null ? void 0 : _a2[1];
2870
2908
  if (token == null) {
2871
2909
  return { protocols: ["realtime"], headers };
2872
2910
  }
@@ -2981,8 +3019,8 @@ var OpenAISpeechModel = class _OpenAISpeechModel {
2981
3019
  };
2982
3020
  }
2983
3021
  async doGenerate(options) {
2984
- var _a, _b, _c, _d, _e;
2985
- const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
3022
+ var _a2, _b, _c, _d, _e;
3023
+ const currentDate = (_c = (_b = (_a2 = this.config._internal) == null ? void 0 : _a2.currentDate) == null ? void 0 : _b.call(_a2)) != null ? _c : /* @__PURE__ */ new Date();
2986
3024
  const { requestBody, warnings } = await this.getArgs(options);
2987
3025
  const {
2988
3026
  value: audio,
@@ -3037,13 +3075,13 @@ import {
3037
3075
  // src/responses/convert-openai-responses-usage.ts
3038
3076
  import { createNullLanguageModelUsage as createNullLanguageModelUsage3 } from "@ai-sdk/provider-utils";
3039
3077
  function convertOpenAIResponsesUsage(usage) {
3040
- var _a, _b, _c, _d, _e, _f;
3078
+ var _a2, _b, _c, _d, _e, _f;
3041
3079
  if (usage == null) {
3042
3080
  return createNullLanguageModelUsage3();
3043
3081
  }
3044
3082
  const inputTokens = usage.input_tokens;
3045
3083
  const outputTokens = usage.output_tokens;
3046
- const cachedTokens = (_b = (_a = usage.input_tokens_details) == null ? void 0 : _a.cached_tokens) != null ? _b : 0;
3084
+ const cachedTokens = (_b = (_a2 = usage.input_tokens_details) == null ? void 0 : _a2.cached_tokens) != null ? _b : 0;
3047
3085
  const cacheWriteTokens = (_d = (_c = usage.input_tokens_details) == null ? void 0 : _c.cache_write_tokens) != null ? _d : void 0;
3048
3086
  const reasoningTokens = (_f = (_e = usage.output_tokens_details) == null ? void 0 : _e.reasoning_tokens) != null ? _f : 0;
3049
3087
  return {
@@ -3421,7 +3459,7 @@ var programmaticToolCallingFactory = createProviderExecutedToolFactory({
3421
3459
  var programmaticToolCalling = () => experimental_toolCaller(programmaticToolCallingFactory({}), {
3422
3460
  type: "provider",
3423
3461
  prepareProviderOptions: (providerOptions) => {
3424
- var _a;
3462
+ var _a2;
3425
3463
  const openaiOptions = providerOptions == null ? void 0 : providerOptions.openai;
3426
3464
  return {
3427
3465
  ...providerOptions,
@@ -3429,7 +3467,7 @@ var programmaticToolCalling = () => experimental_toolCaller(programmaticToolCall
3429
3467
  ...openaiOptions,
3430
3468
  allowedCallers: [
3431
3469
  .../* @__PURE__ */ new Set([
3432
- ...(_a = openaiOptions == null ? void 0 : openaiOptions.allowedCallers) != null ? _a : [],
3470
+ ...(_a2 = openaiOptions == null ? void 0 : openaiOptions.allowedCallers) != null ? _a2 : [],
3433
3471
  "programmatic"
3434
3472
  ])
3435
3473
  ]
@@ -3449,8 +3487,8 @@ function getParallelToolCallMetadata({
3449
3487
  providerOptions,
3450
3488
  providerOptionsName
3451
3489
  }) {
3452
- var _a;
3453
- const metadata = (_a = providerOptions == null ? void 0 : providerOptions[providerOptionsName]) == null ? void 0 : _a.parallelToolCall;
3490
+ var _a2;
3491
+ const metadata = (_a2 = providerOptions == null ? void 0 : providerOptions[providerOptionsName]) == null ? void 0 : _a2.parallelToolCall;
3454
3492
  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) {
3455
3493
  return void 0;
3456
3494
  }
@@ -3530,14 +3568,14 @@ async function convertFunctionToolResultOutput({
3530
3568
  providerOptionsName,
3531
3569
  warnings
3532
3570
  }) {
3533
- var _a;
3571
+ var _a2;
3534
3572
  const hasOutputSchema = outputSchemaToolNames == null ? void 0 : outputSchemaToolNames.has(toolName);
3535
3573
  switch (output.type) {
3536
3574
  case "text":
3537
3575
  case "error-text":
3538
3576
  return hasOutputSchema ? JSON.stringify(output.value) : output.value;
3539
3577
  case "execution-denied": {
3540
- const reason = (_a = output.reason) != null ? _a : "Tool call execution denied.";
3578
+ const reason = (_a2 = output.reason) != null ? _a2 : "Tool call execution denied.";
3541
3579
  return hasOutputSchema ? JSON.stringify(reason) : reason;
3542
3580
  }
3543
3581
  case "json":
@@ -3545,7 +3583,7 @@ async function convertFunctionToolResultOutput({
3545
3583
  return JSON.stringify(output.value);
3546
3584
  case "content":
3547
3585
  return output.value.map((item) => {
3548
- var _a2, _b, _c;
3586
+ var _a3, _b, _c;
3549
3587
  const promptCacheBreakpoint = getPromptCacheBreakpoint2(
3550
3588
  item.providerOptions,
3551
3589
  providerOptionsName
@@ -3562,7 +3600,7 @@ async function convertFunctionToolResultOutput({
3562
3600
  }
3563
3601
  case "file": {
3564
3602
  const topLevel = getTopLevelMediaType2(item.mediaType);
3565
- const imageDetail = (_b = (_a2 = item.providerOptions) == null ? void 0 : _a2[providerOptionsName]) == null ? void 0 : _b.imageDetail;
3603
+ const imageDetail = (_b = (_a3 = item.providerOptions) == null ? void 0 : _a3[providerOptionsName]) == null ? void 0 : _b.imageDetail;
3566
3604
  if (item.data.type === "data") {
3567
3605
  const fullMediaType = resolveFullMediaType2({ part: item });
3568
3606
  if (topLevel === "image") {
@@ -3678,8 +3716,8 @@ function collectCompleteParallelToolResultGroups({
3678
3716
  return completeGroups;
3679
3717
  }
3680
3718
  function getPromptCacheBreakpoint2(providerOptions, providerOptionsName) {
3681
- var _a;
3682
- return (_a = providerOptions == null ? void 0 : providerOptions[providerOptionsName]) == null ? void 0 : _a.promptCacheBreakpoint;
3719
+ var _a2;
3720
+ return (_a2 = providerOptions == null ? void 0 : providerOptions[providerOptionsName]) == null ? void 0 : _a2.promptCacheBreakpoint;
3683
3721
  }
3684
3722
  function isFileId(data, prefixes) {
3685
3723
  if (!prefixes) return false;
@@ -3702,7 +3740,7 @@ async function convertToOpenAIResponsesInput({
3702
3740
  customProviderToolNames,
3703
3741
  outputSchemaToolNames
3704
3742
  }) {
3705
- 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, _F, _G, _H, _I, _J, _K;
3743
+ 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, _F, _G, _H, _I, _J, _K;
3706
3744
  let input = [];
3707
3745
  const warnings = [];
3708
3746
  const processedApprovalIds = /* @__PURE__ */ new Set();
@@ -3770,7 +3808,7 @@ async function convertToOpenAIResponsesInput({
3770
3808
  input.push({
3771
3809
  role: "user",
3772
3810
  content: content.map((part, index) => {
3773
- var _a2, _b2, _c2, _d2, _e2;
3811
+ var _a3, _b2, _c2, _d2, _e2;
3774
3812
  switch (part.type) {
3775
3813
  case "text": {
3776
3814
  const promptCacheBreakpoint = getPromptCacheBreakpoint2(
@@ -3800,7 +3838,7 @@ async function convertToOpenAIResponsesInput({
3800
3838
  return {
3801
3839
  type: "input_image",
3802
3840
  file_id: fileId,
3803
- detail: (_b2 = (_a2 = part.providerOptions) == null ? void 0 : _a2[providerOptionsName]) == null ? void 0 : _b2.imageDetail,
3841
+ detail: (_b2 = (_a3 = part.providerOptions) == null ? void 0 : _a3[providerOptionsName]) == null ? void 0 : _b2.imageDetail,
3804
3842
  ...promptCacheBreakpoint != null && {
3805
3843
  prompt_cache_breakpoint: promptCacheBreakpoint
3806
3844
  }
@@ -3873,7 +3911,7 @@ async function convertToOpenAIResponsesInput({
3873
3911
  for (const part of content) {
3874
3912
  switch (part.type) {
3875
3913
  case "text": {
3876
- const providerOptions2 = (_a = part.providerOptions) == null ? void 0 : _a[providerOptionsName];
3914
+ const providerOptions2 = (_a2 = part.providerOptions) == null ? void 0 : _a2[providerOptionsName];
3877
3915
  const id = providerOptions2 == null ? void 0 : providerOptions2.itemId;
3878
3916
  const phase = providerOptions2 == null ? void 0 : providerOptions2.phase;
3879
3917
  if (hasConversation && id != null) {
@@ -4455,7 +4493,7 @@ async function convertToOpenAIResponsesInput({
4455
4493
  break;
4456
4494
  case "content":
4457
4495
  outputValue = output.value.map((item) => {
4458
- var _a2, _b2, _c2;
4496
+ var _a3, _b2, _c2;
4459
4497
  const promptCacheBreakpoint = getPromptCacheBreakpoint2(
4460
4498
  item.providerOptions,
4461
4499
  providerOptionsName
@@ -4471,7 +4509,7 @@ async function convertToOpenAIResponsesInput({
4471
4509
  };
4472
4510
  case "file": {
4473
4511
  const topLevel = getTopLevelMediaType2(item.mediaType);
4474
- const imageDetail = (_b2 = (_a2 = item.providerOptions) == null ? void 0 : _a2[providerOptionsName]) == null ? void 0 : _b2.imageDetail;
4512
+ const imageDetail = (_b2 = (_a3 = item.providerOptions) == null ? void 0 : _a3[providerOptionsName]) == null ? void 0 : _b2.imageDetail;
4475
4513
  if (item.data.type === "data") {
4476
4514
  const fullMediaType = resolveFullMediaType2({
4477
4515
  part: item
@@ -4602,6 +4640,7 @@ function mapOpenAIResponseFinishReason({
4602
4640
 
4603
4641
  // src/responses/openai-responses-api.ts
4604
4642
  import {
4643
+ isRecord,
4605
4644
  lazySchema as lazySchema18,
4606
4645
  zodSchema as zodSchema18
4607
4646
  } from "@ai-sdk/provider-utils";
@@ -4699,6 +4738,19 @@ var openaiResponsesProgramOutputSchema = z20.object({
4699
4738
  result: z20.string(),
4700
4739
  status: z20.enum(["completed", "incomplete"])
4701
4740
  });
4741
+ var openaiResponsesLocalShellCallSchema = z20.object({
4742
+ type: z20.literal("local_shell_call"),
4743
+ id: z20.string(),
4744
+ call_id: z20.string(),
4745
+ action: z20.object({
4746
+ type: z20.literal("exec"),
4747
+ command: z20.array(z20.string()),
4748
+ timeout_ms: z20.number().optional(),
4749
+ user: z20.string().optional(),
4750
+ working_directory: z20.string().optional(),
4751
+ env: z20.record(z20.string(), z20.string()).optional()
4752
+ })
4753
+ });
4702
4754
  var openaiResponsesNestedErrorChunkSchema = z20.object({
4703
4755
  type: z20.literal("error"),
4704
4756
  sequence_number: z20.number(),
@@ -4716,6 +4768,64 @@ var openaiResponsesErrorChunkSchema = z20.object({
4716
4768
  message: z20.string(),
4717
4769
  param: z20.string().nullish()
4718
4770
  });
4771
+ var openaiResponsesModeledChunkTypes = /* @__PURE__ */ new Set([
4772
+ "error",
4773
+ "response.apply_patch_call_operation_diff.delta",
4774
+ "response.apply_patch_call_operation_diff.done",
4775
+ "response.code_interpreter_call_code.delta",
4776
+ "response.code_interpreter_call_code.done",
4777
+ "response.completed",
4778
+ "response.created",
4779
+ "response.custom_tool_call_input.delta",
4780
+ "response.failed",
4781
+ "response.function_call_arguments.delta",
4782
+ "response.function_call_arguments.done",
4783
+ "response.image_generation_call.partial_image",
4784
+ "response.in_progress",
4785
+ "response.incomplete",
4786
+ "response.output_item.added",
4787
+ "response.output_item.done",
4788
+ "response.output_text.annotation.added",
4789
+ "response.output_text.delta",
4790
+ "response.reasoning_summary_part.added",
4791
+ "response.reasoning_summary_part.done",
4792
+ "response.reasoning_summary_text.delta"
4793
+ ]);
4794
+ var openaiResponsesModeledOutputItemTypes = /* @__PURE__ */ new Set([
4795
+ "apply_patch_call",
4796
+ "code_interpreter_call",
4797
+ "compaction",
4798
+ "computer_call",
4799
+ "custom_tool_call",
4800
+ "file_search_call",
4801
+ "function_call",
4802
+ "image_generation_call",
4803
+ "local_shell_call",
4804
+ "mcp_approval_request",
4805
+ "mcp_call",
4806
+ "mcp_list_tools",
4807
+ "message",
4808
+ "program",
4809
+ "program_output",
4810
+ "reasoning",
4811
+ "shell_call",
4812
+ "shell_call_output",
4813
+ "tool_search_call",
4814
+ "tool_search_output",
4815
+ "web_search_call"
4816
+ ]);
4817
+ function isModeledOpenAIResponsesChunk(value) {
4818
+ if (typeof value.type !== "string" || !openaiResponsesModeledChunkTypes.has(value.type)) {
4819
+ return false;
4820
+ }
4821
+ if (value.type !== "response.output_item.added" && value.type !== "response.output_item.done") {
4822
+ return true;
4823
+ }
4824
+ if (!isRecord(value.item) || typeof value.item.type !== "string") {
4825
+ return true;
4826
+ }
4827
+ return openaiResponsesModeledOutputItemTypes.has(value.item.type);
4828
+ }
4719
4829
  var openaiResponsesChunkSchema = lazySchema18(
4720
4830
  () => zodSchema18(
4721
4831
  z20.union([
@@ -4843,6 +4953,7 @@ var openaiResponsesChunkSchema = lazySchema18(
4843
4953
  type: z20.literal("file_search_call"),
4844
4954
  id: z20.string()
4845
4955
  }),
4956
+ openaiResponsesLocalShellCallSchema,
4846
4957
  z20.object({
4847
4958
  type: z20.literal("image_generation_call"),
4848
4959
  id: z20.string()
@@ -5049,19 +5160,7 @@ var openaiResponsesChunkSchema = lazySchema18(
5049
5160
  })
5050
5161
  ).nullish()
5051
5162
  }),
5052
- z20.object({
5053
- type: z20.literal("local_shell_call"),
5054
- id: z20.string(),
5055
- call_id: z20.string(),
5056
- action: z20.object({
5057
- type: z20.literal("exec"),
5058
- command: z20.array(z20.string()),
5059
- timeout_ms: z20.number().optional(),
5060
- user: z20.string().optional(),
5061
- working_directory: z20.string().optional(),
5062
- env: z20.record(z20.string(), z20.string()).optional()
5063
- })
5064
- }),
5163
+ openaiResponsesLocalShellCallSchema,
5065
5164
  openaiResponsesComputerCallSchema,
5066
5165
  z20.object({
5067
5166
  type: z20.literal("mcp_call"),
@@ -5189,6 +5288,14 @@ var openaiResponsesChunkSchema = lazySchema18(
5189
5288
  output_index: z20.number(),
5190
5289
  delta: z20.string()
5191
5290
  }),
5291
+ z20.object({
5292
+ // `name` is documented as required but omitted from live API events:
5293
+ // https://github.com/openai/openai-openapi/issues/545
5294
+ type: z20.literal("response.function_call_arguments.done"),
5295
+ item_id: z20.string(),
5296
+ output_index: z20.number(),
5297
+ arguments: z20.string()
5298
+ }),
5192
5299
  z20.object({
5193
5300
  type: z20.literal("response.custom_tool_call_input.delta"),
5194
5301
  item_id: z20.string(),
@@ -5278,7 +5385,9 @@ var openaiResponsesChunkSchema = lazySchema18(
5278
5385
  }),
5279
5386
  openaiResponsesNestedErrorChunkSchema,
5280
5387
  openaiResponsesErrorChunkSchema,
5281
- z20.object({ type: z20.string() }).loose().transform((value) => ({
5388
+ z20.object({ type: z20.string() }).loose().refine((value) => !isModeledOpenAIResponsesChunk(value), {
5389
+ message: "Known response chunk failed schema validation"
5390
+ }).transform((value) => ({
5282
5391
  type: "unknown_chunk",
5283
5392
  message: value.type
5284
5393
  }))
@@ -5418,19 +5527,7 @@ var openaiResponsesResponseSchema = lazySchema18(
5418
5527
  id: z20.string(),
5419
5528
  result: z20.string()
5420
5529
  }),
5421
- z20.object({
5422
- type: z20.literal("local_shell_call"),
5423
- id: z20.string(),
5424
- call_id: z20.string(),
5425
- action: z20.object({
5426
- type: z20.literal("exec"),
5427
- command: z20.array(z20.string()),
5428
- timeout_ms: z20.number().optional(),
5429
- user: z20.string().optional(),
5430
- working_directory: z20.string().optional(),
5431
- env: z20.record(z20.string(), z20.string()).optional()
5432
- })
5433
- }),
5530
+ openaiResponsesLocalShellCallSchema,
5434
5531
  z20.object({
5435
5532
  type: z20.literal("function_call"),
5436
5533
  call_id: z20.string(),
@@ -6258,7 +6355,7 @@ async function prepareResponsesTools({
6258
6355
  customProviderToolNames,
6259
6356
  outputSchemaToolNames
6260
6357
  }) {
6261
- var _a, _b, _c, _d;
6358
+ var _a2, _b, _c, _d;
6262
6359
  tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
6263
6360
  const toolWarnings = [];
6264
6361
  if (tools == null) {
@@ -6284,7 +6381,7 @@ async function prepareResponsesTools({
6284
6381
  for (const tool of tools) {
6285
6382
  switch (tool.type) {
6286
6383
  case "function": {
6287
- const openaiOptions = (_a = tool.providerOptions) == null ? void 0 : _a.openai;
6384
+ const openaiOptions = (_a2 = tool.providerOptions) == null ? void 0 : _a2.openai;
6288
6385
  if ((openaiOptions == null ? void 0 : openaiOptions.outputSchema) != null) {
6289
6386
  outputSchemaToolNames == null ? void 0 : outputSchemaToolNames.add(tool.name);
6290
6387
  }
@@ -6702,11 +6799,11 @@ function mapShellEnvironment(environment) {
6702
6799
  function mapShellSkills(skills) {
6703
6800
  return skills == null ? void 0 : skills.map(
6704
6801
  (skill) => {
6705
- var _a, _b;
6802
+ var _a2, _b;
6706
6803
  return skill.type === "skillReference" ? {
6707
6804
  type: "skill_reference",
6708
6805
  skill_id: resolveProviderReference3({
6709
- reference: (_a = skill.providerReference) != null ? _a : {},
6806
+ reference: (_a2 = skill.providerReference) != null ? _a2 : {},
6710
6807
  provider: "openai"
6711
6808
  }),
6712
6809
  version: (_b = skill.version) != null ? _b : "latest"
@@ -6726,13 +6823,13 @@ function mapShellSkills(skills) {
6726
6823
 
6727
6824
  // src/responses/openai-responses-language-model.ts
6728
6825
  function extractApprovalRequestIdToToolCallIdMapping(prompt) {
6729
- var _a, _b;
6826
+ var _a2, _b;
6730
6827
  const mapping = {};
6731
6828
  for (const message of prompt) {
6732
6829
  if (message.role !== "assistant") continue;
6733
6830
  for (const part of message.content) {
6734
6831
  if (part.type !== "tool-call") continue;
6735
- const approvalRequestId = (_b = (_a = part.providerOptions) == null ? void 0 : _a.openai) == null ? void 0 : _b.approvalRequestId;
6832
+ const approvalRequestId = (_b = (_a2 = part.providerOptions) == null ? void 0 : _a2.openai) == null ? void 0 : _b.approvalRequestId;
6736
6833
  if (approvalRequestId != null) {
6737
6834
  mapping[approvalRequestId] = part.toolCallId;
6738
6835
  }
@@ -6795,16 +6892,16 @@ function mapComputerCallInput({
6795
6892
  pending_safety_checks,
6796
6893
  status
6797
6894
  }) {
6798
- var _a;
6895
+ var _a2;
6799
6896
  return {
6800
6897
  actions: (actions != null ? actions : action != null ? [action] : []).map(
6801
6898
  mapComputerAction
6802
6899
  ),
6803
- pendingSafetyChecks: (_a = pending_safety_checks == null ? void 0 : pending_safety_checks.map((safetyCheck) => ({
6900
+ pendingSafetyChecks: (_a2 = pending_safety_checks == null ? void 0 : pending_safety_checks.map((safetyCheck) => ({
6804
6901
  id: safetyCheck.id,
6805
6902
  ...safetyCheck.code != null && { code: safetyCheck.code },
6806
6903
  ...safetyCheck.message != null && { message: safetyCheck.message }
6807
- }))) != null ? _a : [],
6904
+ }))) != null ? _a2 : [],
6808
6905
  status
6809
6906
  };
6810
6907
  }
@@ -6846,7 +6943,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
6846
6943
  toolChoice,
6847
6944
  responseFormat
6848
6945
  }) {
6849
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
6946
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
6850
6947
  const warnings = [];
6851
6948
  const modelCapabilities = getOpenAILanguageModelCapabilities(this.modelId);
6852
6949
  if (topK != null) {
@@ -6877,7 +6974,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
6877
6974
  schema: openaiLanguageModelResponsesOptionsSchema
6878
6975
  });
6879
6976
  }
6880
- const resolvedReasoningEffort = (_a = openaiOptions == null ? void 0 : openaiOptions.reasoningEffort) != null ? _a : isCustomReasoning2(reasoning) ? reasoning : void 0;
6977
+ const resolvedReasoningEffort = (_a2 = openaiOptions == null ? void 0 : openaiOptions.reasoningEffort) != null ? _a2 : isCustomReasoning2(reasoning) ? reasoning : void 0;
6881
6978
  const resolvedReasoningSummary = (openaiOptions == null ? void 0 : openaiOptions.reasoningSummary) !== void 0 ? openaiOptions.reasoningSummary : resolvedReasoningEffort != null && resolvedReasoningEffort !== "none" ? "detailed" : void 0;
6882
6979
  const isReasoningModel = (_b = openaiOptions == null ? void 0 : openaiOptions.forceReasoning) != null ? _b : modelCapabilities.isReasoningModel;
6883
6980
  if ((openaiOptions == null ? void 0 : openaiOptions.conversation) && (openaiOptions == null ? void 0 : openaiOptions.previousResponseId)) {
@@ -7116,7 +7213,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7116
7213
  };
7117
7214
  }
7118
7215
  async doGenerate(options) {
7119
- 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, _F, _G, _H;
7216
+ 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, _F, _G, _H;
7120
7217
  const {
7121
7218
  args: body,
7122
7219
  warnings,
@@ -7136,7 +7233,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7136
7233
  rawValue: rawResponse
7137
7234
  } = await postJsonToApi6({
7138
7235
  url,
7139
- headers: combineHeaders7((_b = (_a = this.config).headers) == null ? void 0 : _b.call(_a), options.headers),
7236
+ headers: combineHeaders7((_b = (_a2 = this.config).headers) == null ? void 0 : _b.call(_a2), options.headers),
7140
7237
  body,
7141
7238
  failedResponseHandler: openaiFailedResponseHandler,
7142
7239
  successfulResponseHandler: createJsonResponseHandler6(
@@ -7697,7 +7794,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7697
7794
  };
7698
7795
  }
7699
7796
  async doStream(options) {
7700
- var _a, _b, _c, _d;
7797
+ var _a2, _b, _c, _d;
7701
7798
  const {
7702
7799
  args: body,
7703
7800
  warnings,
@@ -7713,7 +7810,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7713
7810
  });
7714
7811
  const { responseHeaders, value: response } = await postJsonToApi6({
7715
7812
  url,
7716
- headers: combineHeaders7((_b = (_a = this.config).headers) == null ? void 0 : _b.call(_a), options.headers),
7813
+ headers: combineHeaders7((_b = (_a2 = this.config).headers) == null ? void 0 : _b.call(_a2), options.headers),
7717
7814
  body: {
7718
7815
  ...body,
7719
7816
  stream: true
@@ -7757,8 +7854,8 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7757
7854
  itemId,
7758
7855
  outputIndex
7759
7856
  }) => {
7760
- var _a2;
7761
- return outputIndex == null ? itemId : (_a2 = activeOutputItemIds[outputIndex]) != null ? _a2 : itemId;
7857
+ var _a3;
7858
+ return outputIndex == null ? itemId : (_a3 = activeOutputItemIds[outputIndex]) != null ? _a3 : itemId;
7762
7859
  };
7763
7860
  let serviceTier;
7764
7861
  let reasoningContext;
@@ -7771,7 +7868,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7771
7868
  controller.enqueue({ type: "stream-start", warnings });
7772
7869
  },
7773
7870
  transform(chunk, controller) {
7774
- var _a2, _b2, _c2, _d2, _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;
7871
+ var _a3, _b2, _c2, _d2, _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, _Q, _R;
7775
7872
  if (options.includeRawChunks) {
7776
7873
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
7777
7874
  }
@@ -7783,6 +7880,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7783
7880
  requestBodyValues: body,
7784
7881
  responseHeaders
7785
7882
  }) : chunk.error;
7883
+ encounteredStreamError = true;
7786
7884
  finishReason = { unified: "error", raw: void 0 };
7787
7885
  controller.enqueue({ type: "error", error });
7788
7886
  return;
@@ -7849,7 +7947,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7849
7947
  providerExecuted: true
7850
7948
  });
7851
7949
  } else if (value.item.type === "computer_call") {
7852
- const toolCallId = (_a2 = value.item.call_id) != null ? _a2 : value.item.id;
7950
+ const toolCallId = (_a3 = value.item.call_id) != null ? _a3 : value.item.id;
7853
7951
  ongoingToolCalls[value.output_index] = {
7854
7952
  toolName: toolNameMapping.toCustomToolName("computer"),
7855
7953
  toolCallId
@@ -8021,14 +8119,14 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8021
8119
  tools: functionTools
8022
8120
  });
8023
8121
  const enqueueUnexpandedToolCall = () => {
8024
- var _a3;
8122
+ var _a4;
8025
8123
  if (suppressInputStreaming) {
8026
8124
  controller.enqueue({
8027
8125
  type: "tool-input-start",
8028
8126
  id: item.call_id,
8029
8127
  toolName: item.name
8030
8128
  });
8031
- const bufferedInputDeltas = (_a3 = ongoingToolCall == null ? void 0 : ongoingToolCall.bufferedInputDeltas) != null ? _a3 : [];
8129
+ const bufferedInputDeltas = (_a4 = ongoingToolCall == null ? void 0 : ongoingToolCall.bufferedInputDeltas) != null ? _a4 : [];
8032
8130
  if (bufferedInputDeltas.length > 0) {
8033
8131
  for (const delta of bufferedInputDeltas) {
8034
8132
  controller.enqueue({
@@ -8696,13 +8794,15 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8696
8794
  }
8697
8795
  }
8698
8796
  } else if (isResponseFinishedChunk(value)) {
8699
- finishReason = {
8700
- unified: mapOpenAIResponseFinishReason({
8701
- finishReason: (_x = value.response.incomplete_details) == null ? void 0 : _x.reason,
8702
- hasFunctionCall
8703
- }),
8704
- raw: (_z = (_y = value.response.incomplete_details) == null ? void 0 : _y.reason) != null ? _z : void 0
8705
- };
8797
+ if (!encounteredStreamError) {
8798
+ finishReason = {
8799
+ unified: mapOpenAIResponseFinishReason({
8800
+ finishReason: (_x = value.response.incomplete_details) == null ? void 0 : _x.reason,
8801
+ hasFunctionCall
8802
+ }),
8803
+ raw: (_z = (_y = value.response.incomplete_details) == null ? void 0 : _y.reason) != null ? _z : void 0
8804
+ };
8805
+ }
8706
8806
  usage = value.response.usage;
8707
8807
  if (typeof value.response.service_tier === "string") {
8708
8808
  serviceTier = value.response.service_tier;
@@ -8725,17 +8825,18 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8725
8825
  }
8726
8826
  if (!encounteredStreamError && value.response.error != null) {
8727
8827
  encounteredStreamError = true;
8828
+ const error = {
8829
+ type: "response.failed",
8830
+ sequence_number: value.sequence_number,
8831
+ response: {
8832
+ error: value.response.error,
8833
+ incomplete_details: value.response.incomplete_details,
8834
+ service_tier: value.response.service_tier
8835
+ }
8836
+ };
8728
8837
  controller.enqueue({
8729
8838
  type: "error",
8730
- error: {
8731
- type: "response.failed",
8732
- sequence_number: value.sequence_number,
8733
- response: {
8734
- error: value.response.error,
8735
- incomplete_details: value.response.incomplete_details,
8736
- service_tier: value.response.service_tier
8737
- }
8738
- }
8839
+ error: (_E = createOpenAIProviderStreamError(error)) != null ? _E : error
8739
8840
  });
8740
8841
  }
8741
8842
  } else if (isResponseAnnotationAddedChunk(value)) {
@@ -8744,7 +8845,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8744
8845
  controller.enqueue({
8745
8846
  type: "source",
8746
8847
  sourceType: "url",
8747
- id: (_G = (_F = (_E = self.config).generateId) == null ? void 0 : _F.call(_E)) != null ? _G : generateId2(),
8848
+ id: (_H = (_G = (_F = self.config).generateId) == null ? void 0 : _G.call(_F)) != null ? _H : generateId2(),
8748
8849
  url: value.annotation.url,
8749
8850
  title: value.annotation.title
8750
8851
  });
@@ -8752,7 +8853,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8752
8853
  controller.enqueue({
8753
8854
  type: "source",
8754
8855
  sourceType: "document",
8755
- id: (_J = (_I = (_H = self.config).generateId) == null ? void 0 : _I.call(_H)) != null ? _J : generateId2(),
8856
+ id: (_K = (_J = (_I = self.config).generateId) == null ? void 0 : _J.call(_I)) != null ? _K : generateId2(),
8756
8857
  mediaType: "text/plain",
8757
8858
  title: value.annotation.filename,
8758
8859
  filename: value.annotation.filename,
@@ -8768,7 +8869,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8768
8869
  controller.enqueue({
8769
8870
  type: "source",
8770
8871
  sourceType: "document",
8771
- id: (_M = (_L = (_K = self.config).generateId) == null ? void 0 : _L.call(_K)) != null ? _M : generateId2(),
8872
+ id: (_N = (_M = (_L = self.config).generateId) == null ? void 0 : _M.call(_L)) != null ? _N : generateId2(),
8772
8873
  mediaType: "text/plain",
8773
8874
  title: value.annotation.filename,
8774
8875
  filename: value.annotation.filename,
@@ -8784,7 +8885,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8784
8885
  controller.enqueue({
8785
8886
  type: "source",
8786
8887
  sourceType: "document",
8787
- id: (_P = (_O = (_N = self.config).generateId) == null ? void 0 : _O.call(_N)) != null ? _P : generateId2(),
8888
+ id: (_Q = (_P = (_O = self.config).generateId) == null ? void 0 : _P.call(_O)) != null ? _Q : generateId2(),
8788
8889
  mediaType: "application/octet-stream",
8789
8890
  title: value.annotation.file_id,
8790
8891
  filename: value.annotation.file_id,
@@ -8800,11 +8901,14 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8800
8901
  } else if (isErrorChunk(value)) {
8801
8902
  encounteredStreamError = true;
8802
8903
  finishReason = { unified: "error", raw: "error" };
8803
- controller.enqueue({ type: "error", error: value });
8904
+ controller.enqueue({
8905
+ type: "error",
8906
+ error: (_R = createOpenAIProviderStreamError(value)) != null ? _R : value
8907
+ });
8804
8908
  }
8805
8909
  },
8806
8910
  flush(controller) {
8807
- var _a2;
8911
+ var _a3;
8808
8912
  for (const toolCall of Object.values(ongoingToolCalls)) {
8809
8913
  if (!(toolCall == null ? void 0 : toolCall.suppressInputStreaming)) {
8810
8914
  continue;
@@ -8814,7 +8918,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8814
8918
  id: toolCall.toolCallId,
8815
8919
  toolName: toolCall.toolName
8816
8920
  });
8817
- for (const delta of (_a2 = toolCall.bufferedInputDeltas) != null ? _a2 : []) {
8921
+ for (const delta of (_a3 = toolCall.bufferedInputDeltas) != null ? _a3 : []) {
8818
8922
  controller.enqueue({
8819
8923
  type: "tool-input-delta",
8820
8924
  id: toolCall.toolCallId,
@@ -8922,7 +9026,7 @@ function isResponseOutputChunk(chunk) {
8922
9026
  return !(chunk.type === "response.created" || chunk.type === "response.in_progress" || chunk.type === "response.failed" || chunk.type === "error" || chunk.type === "unknown_chunk");
8923
9027
  }
8924
9028
  function mapWebSearchOutput(action) {
8925
- var _a;
9029
+ var _a2;
8926
9030
  if (action == null) {
8927
9031
  return {};
8928
9032
  }
@@ -8931,7 +9035,7 @@ function mapWebSearchOutput(action) {
8931
9035
  return {
8932
9036
  action: {
8933
9037
  type: "search",
8934
- query: (_a = action.query) != null ? _a : void 0,
9038
+ query: (_a2 = action.query) != null ? _a2 : void 0,
8935
9039
  ...action.queries != null && { queries: action.queries }
8936
9040
  },
8937
9041
  // include sources when provided by the Responses API (behind include flag)