@ai-sdk/openai 3.0.101 → 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.
@@ -32,10 +32,10 @@ var openaiFailedResponseHandler = createJsonErrorResponseHandler({
32
32
 
33
33
  // src/openai-language-model-capabilities.ts
34
34
  function getOpenAILanguageModelCapabilities(modelId) {
35
- var _a, _b, _c, _d, _e;
35
+ var _a2, _b, _c, _d, _e;
36
36
  const oSeriesVersion = getOSeriesVersion(modelId);
37
37
  const gptVersion = getGptVersion(modelId);
38
- 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);
38
+ 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);
39
39
  const isGptNanoModel = (_d = (_c = gptVersion == null ? void 0 : gptVersion.variant) == null ? void 0 : _c.startsWith("nano")) != null ? _d : false;
40
40
  const supportsFlexProcessing = oSeriesVersion != null && oSeriesVersion >= 3 || gptVersion != null && gptVersion.major >= 5 && !isGptChatModel;
41
41
  const supportsPriorityProcessing = modelId.startsWith("gpt-4") || gptVersion != null && gptVersion.major >= 5 && !isGptNanoModel && !isGptChatModel || oSeriesVersion != null && oSeriesVersion >= 3;
@@ -115,10 +115,10 @@ function createOpenAIStreamError({
115
115
  requestBodyValues,
116
116
  responseHeaders
117
117
  }) {
118
- var _a;
118
+ var _a2;
119
119
  const streamError = parseStreamError(frame);
120
120
  return new APICallError({
121
- message: (_a = streamError == null ? void 0 : streamError.message) != null ? _a : "OpenAI stream failed before any output was generated",
121
+ message: (_a2 = streamError == null ? void 0 : streamError.message) != null ? _a2 : "OpenAI stream failed before any output was generated",
122
122
  url,
123
123
  requestBodyValues,
124
124
  statusCode: streamError == null ? 500 : getStatusCode(streamError),
@@ -128,7 +128,7 @@ function createOpenAIStreamError({
128
128
  });
129
129
  }
130
130
  function parseStreamError(frame) {
131
- var _a;
131
+ var _a2;
132
132
  const value = asRecord(frame);
133
133
  if (value == null) {
134
134
  return void 0;
@@ -143,7 +143,7 @@ function parseStreamError(frame) {
143
143
  frame
144
144
  } : void 0;
145
145
  }
146
- const error = (_a = asRecord(value.error)) != null ? _a : value;
146
+ const error = (_a2 = asRecord(value.error)) != null ? _a2 : value;
147
147
  return typeof error.message === "string" && (asRecord(value.error) != null || typeof error.type === "string" || "code" in error || "param" in error) ? {
148
148
  message: error.message,
149
149
  code: getStringOrNumber(error.code),
@@ -191,7 +191,7 @@ function isHttpErrorStatusCode(value) {
191
191
 
192
192
  // src/chat/convert-openai-chat-usage.ts
193
193
  function convertOpenAIChatUsage(usage) {
194
- var _a, _b, _c, _d, _e, _f, _g, _h;
194
+ var _a2, _b, _c, _d, _e, _f, _g, _h;
195
195
  if (usage == null) {
196
196
  return {
197
197
  inputTokens: {
@@ -208,7 +208,7 @@ function convertOpenAIChatUsage(usage) {
208
208
  raw: void 0
209
209
  };
210
210
  }
211
- const promptTokens = (_a = usage.prompt_tokens) != null ? _a : 0;
211
+ const promptTokens = (_a2 = usage.prompt_tokens) != null ? _a2 : 0;
212
212
  const completionTokens = (_b = usage.completion_tokens) != null ? _b : 0;
213
213
  const cachedTokens = (_d = (_c = usage.prompt_tokens_details) == null ? void 0 : _c.cached_tokens) != null ? _d : 0;
214
214
  const cacheWriteTokens = (_f = (_e = usage.prompt_tokens_details) == null ? void 0 : _e.cache_write_tokens) != null ? _f : void 0;
@@ -235,17 +235,19 @@ import {
235
235
  } from "@ai-sdk/provider";
236
236
  import { convertToBase64 } from "@ai-sdk/provider-utils";
237
237
  function serializeToolCallArguments(input) {
238
- return JSON.stringify(input === void 0 ? {} : input);
238
+ return JSON.stringify(
239
+ typeof input === "object" && input !== null && !Array.isArray(input) ? input : {}
240
+ );
239
241
  }
240
242
  function getPromptCacheBreakpoint(providerOptions) {
241
- var _a;
242
- return (_a = providerOptions == null ? void 0 : providerOptions.openai) == null ? void 0 : _a.promptCacheBreakpoint;
243
+ var _a2;
244
+ return (_a2 = providerOptions == null ? void 0 : providerOptions.openai) == null ? void 0 : _a2.promptCacheBreakpoint;
243
245
  }
244
246
  function convertToOpenAIChatMessages({
245
247
  prompt,
246
248
  systemMessageMode = "system"
247
249
  }) {
248
- var _a, _b;
250
+ var _a2, _b;
249
251
  const messages = [];
250
252
  const warnings = [];
251
253
  for (const { role, content, providerOptions } of prompt) {
@@ -304,7 +306,7 @@ function convertToOpenAIChatMessages({
304
306
  messages.push({
305
307
  role: "user",
306
308
  content: content.map((part, index) => {
307
- var _a2, _b2, _c;
309
+ var _a3, _b2, _c;
308
310
  switch (part.type) {
309
311
  case "text": {
310
312
  const promptCacheBreakpoint = getPromptCacheBreakpoint(
@@ -329,7 +331,7 @@ function convertToOpenAIChatMessages({
329
331
  image_url: {
330
332
  url: part.data instanceof URL ? part.data.toString() : `data:${mediaType};base64,${convertToBase64(part.data)}`,
331
333
  // OpenAI specific extension: image detail
332
- detail: (_b2 = (_a2 = part.providerOptions) == null ? void 0 : _a2.openai) == null ? void 0 : _b2.imageDetail
334
+ detail: (_b2 = (_a3 = part.providerOptions) == null ? void 0 : _a3.openai) == null ? void 0 : _b2.imageDetail
333
335
  },
334
336
  ...promptCacheBreakpoint != null && {
335
337
  prompt_cache_breakpoint: promptCacheBreakpoint
@@ -448,7 +450,7 @@ function convertToOpenAIChatMessages({
448
450
  continue;
449
451
  }
450
452
  const output = toolResponse.output;
451
- 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);
453
+ 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);
452
454
  let contentValue;
453
455
  switch (output.type) {
454
456
  case "text":
@@ -890,13 +892,13 @@ var OpenAIChatLanguageModel = class {
890
892
  toolChoice,
891
893
  providerOptions
892
894
  }) {
893
- var _a, _b, _c, _d, _e;
895
+ var _a2, _b, _c, _d, _e;
894
896
  const warnings = [];
895
- const openaiOptions = (_a = await parseProviderOptions({
897
+ const openaiOptions = (_a2 = await parseProviderOptions({
896
898
  provider: "openai",
897
899
  providerOptions,
898
900
  schema: openaiLanguageModelChatOptions
899
- })) != null ? _a : {};
901
+ })) != null ? _a2 : {};
900
902
  const modelCapabilities = getOpenAILanguageModelCapabilities(this.modelId);
901
903
  const isReasoningModel = (_b = openaiOptions.forceReasoning) != null ? _b : modelCapabilities.isReasoningModel;
902
904
  if (topK != null) {
@@ -1058,7 +1060,7 @@ var OpenAIChatLanguageModel = class {
1058
1060
  };
1059
1061
  }
1060
1062
  async doGenerate(options) {
1061
- var _a, _b, _c, _d, _e, _f, _g;
1063
+ var _a2, _b, _c, _d, _e, _f, _g;
1062
1064
  const { args: body, warnings } = await this.getArgs(options);
1063
1065
  const {
1064
1066
  responseHeaders,
@@ -1084,7 +1086,7 @@ var OpenAIChatLanguageModel = class {
1084
1086
  if (text != null && text.length > 0) {
1085
1087
  content.push({ type: "text", text });
1086
1088
  }
1087
- for (const toolCall of (_a = choice.message.tool_calls) != null ? _a : []) {
1089
+ for (const toolCall of (_a2 = choice.message.tool_calls) != null ? _a2 : []) {
1088
1090
  content.push({
1089
1091
  type: "tool-call",
1090
1092
  toolCallId: (_b = toolCall.id) != null ? _b : generateId(),
@@ -1178,7 +1180,7 @@ var OpenAIChatLanguageModel = class {
1178
1180
  controller.enqueue({ type: "stream-start", warnings });
1179
1181
  },
1180
1182
  transform(chunk, controller) {
1181
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
1183
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
1182
1184
  if (options.includeRawChunks) {
1183
1185
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
1184
1186
  }
@@ -1205,7 +1207,7 @@ var OpenAIChatLanguageModel = class {
1205
1207
  }
1206
1208
  if (value.usage != null) {
1207
1209
  usage = value.usage;
1208
- if (((_a = value.usage.completion_tokens_details) == null ? void 0 : _a.accepted_prediction_tokens) != null) {
1210
+ if (((_a2 = value.usage.completion_tokens_details) == null ? void 0 : _a2.accepted_prediction_tokens) != null) {
1209
1211
  providerMetadata.openai.acceptedPredictionTokens = (_b = value.usage.completion_tokens_details) == null ? void 0 : _b.accepted_prediction_tokens;
1210
1212
  }
1211
1213
  if (((_c = value.usage.completion_tokens_details) == null ? void 0 : _c.rejected_prediction_tokens) != null) {
@@ -1312,7 +1314,7 @@ var OpenAIChatLanguageModel = class {
1312
1314
  }
1313
1315
  },
1314
1316
  flush(controller) {
1315
- var _a;
1317
+ var _a2;
1316
1318
  if (isActiveText) {
1317
1319
  controller.enqueue({ type: "text-end", id: "0" });
1318
1320
  }
@@ -1324,7 +1326,7 @@ var OpenAIChatLanguageModel = class {
1324
1326
  });
1325
1327
  controller.enqueue({
1326
1328
  type: "tool-call",
1327
- toolCallId: (_a = toolCall.id) != null ? _a : generateId(),
1329
+ toolCallId: (_a2 = toolCall.id) != null ? _a2 : generateId(),
1328
1330
  toolName: toolCall.function.name,
1329
1331
  input: toolCall.function.arguments
1330
1332
  });
@@ -1367,7 +1369,7 @@ import {
1367
1369
 
1368
1370
  // src/completion/convert-openai-completion-usage.ts
1369
1371
  function convertOpenAICompletionUsage(usage) {
1370
- var _a, _b, _c, _d;
1372
+ var _a2, _b, _c, _d;
1371
1373
  if (usage == null) {
1372
1374
  return {
1373
1375
  inputTokens: {
@@ -1384,7 +1386,7 @@ function convertOpenAICompletionUsage(usage) {
1384
1386
  raw: void 0
1385
1387
  };
1386
1388
  }
1387
- const promptTokens = (_a = usage.prompt_tokens) != null ? _a : 0;
1389
+ const promptTokens = (_a2 = usage.prompt_tokens) != null ? _a2 : 0;
1388
1390
  const completionTokens = (_b = usage.completion_tokens) != null ? _b : 0;
1389
1391
  return {
1390
1392
  inputTokens: {
@@ -1710,7 +1712,7 @@ var OpenAICompletionLanguageModel = class {
1710
1712
  };
1711
1713
  }
1712
1714
  async doGenerate(options) {
1713
- var _a;
1715
+ var _a2;
1714
1716
  const { args, warnings } = await this.getArgs(options);
1715
1717
  const {
1716
1718
  responseHeaders,
@@ -1740,7 +1742,7 @@ var OpenAICompletionLanguageModel = class {
1740
1742
  usage: convertOpenAICompletionUsage(response.usage),
1741
1743
  finishReason: {
1742
1744
  unified: mapOpenAIFinishReason2(choice.finish_reason),
1743
- raw: (_a = choice.finish_reason) != null ? _a : void 0
1745
+ raw: (_a2 = choice.finish_reason) != null ? _a2 : void 0
1744
1746
  },
1745
1747
  request: { body: args },
1746
1748
  response: {
@@ -1871,6 +1873,7 @@ import {
1871
1873
  import {
1872
1874
  combineHeaders as combineHeaders3,
1873
1875
  createJsonResponseHandler as createJsonResponseHandler3,
1876
+ EXPERIMENTAL_EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL,
1874
1877
  parseProviderOptions as parseProviderOptions3,
1875
1878
  postJsonToApi as postJsonToApi3
1876
1879
  } from "@ai-sdk/provider-utils";
@@ -1911,10 +1914,13 @@ var openaiTextEmbeddingResponseSchema = lazySchema6(
1911
1914
  );
1912
1915
 
1913
1916
  // src/embedding/openai-embedding-model.ts
1917
+ var _a;
1918
+ _a = EXPERIMENTAL_EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL;
1914
1919
  var OpenAIEmbeddingModel = class {
1915
1920
  constructor(modelId, config) {
1916
1921
  this.specificationVersion = "v3";
1917
1922
  this.maxEmbeddingsPerCall = 2048;
1923
+ this[_a] = 3e5;
1918
1924
  this.supportsParallelCalls = true;
1919
1925
  this.modelId = modelId;
1920
1926
  this.config = config;
@@ -1928,7 +1934,7 @@ var OpenAIEmbeddingModel = class {
1928
1934
  abortSignal,
1929
1935
  providerOptions
1930
1936
  }) {
1931
- var _a;
1937
+ var _a2;
1932
1938
  if (values.length > this.maxEmbeddingsPerCall) {
1933
1939
  throw new TooManyEmbeddingValuesForCallError({
1934
1940
  provider: this.provider,
@@ -1937,11 +1943,11 @@ var OpenAIEmbeddingModel = class {
1937
1943
  values
1938
1944
  });
1939
1945
  }
1940
- const openaiOptions = (_a = await parseProviderOptions3({
1946
+ const openaiOptions = (_a2 = await parseProviderOptions3({
1941
1947
  provider: "openai",
1942
1948
  providerOptions,
1943
1949
  schema: openaiEmbeddingModelOptions
1944
- })) != null ? _a : {};
1950
+ })) != null ? _a2 : {};
1945
1951
  const {
1946
1952
  responseHeaders,
1947
1953
  value: response,
@@ -2039,8 +2045,8 @@ function hasDefaultResponseFormat(modelId) {
2039
2045
  );
2040
2046
  }
2041
2047
  function getMaxImagesPerCall(modelId) {
2042
- var _a;
2043
- return (_a = modelMaxImagesPerCall[modelId]) != null ? _a : modelId.startsWith("gpt-image-") ? 10 : 1;
2048
+ var _a2;
2049
+ return (_a2 = modelMaxImagesPerCall[modelId]) != null ? _a2 : modelId.startsWith("gpt-image-") ? 10 : 1;
2044
2050
  }
2045
2051
  var baseImageModelOptionsObject = z9.object({
2046
2052
  /**
@@ -2127,7 +2133,7 @@ var OpenAIImageModel = class {
2127
2133
  headers,
2128
2134
  abortSignal
2129
2135
  }) {
2130
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
2136
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
2131
2137
  const warnings = [];
2132
2138
  if (aspectRatio != null) {
2133
2139
  warnings.push({
@@ -2139,7 +2145,7 @@ var OpenAIImageModel = class {
2139
2145
  if (seed != null) {
2140
2146
  warnings.push({ type: "unsupported", feature: "seed" });
2141
2147
  }
2142
- const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
2148
+ const currentDate = (_c = (_b = (_a2 = this.config._internal) == null ? void 0 : _a2.currentDate) == null ? void 0 : _b.call(_a2)) != null ? _c : /* @__PURE__ */ new Date();
2143
2149
  if (files != null) {
2144
2150
  const openaiOptions2 = (_d = await parseProviderOptions4({
2145
2151
  provider: "openai",
@@ -2202,10 +2208,10 @@ var OpenAIImageModel = class {
2202
2208
  providerMetadata: {
2203
2209
  openai: {
2204
2210
  images: response2.data.map((item, index) => {
2205
- var _a2, _b2, _c2, _d2, _e2, _f2;
2211
+ var _a3, _b2, _c2, _d2, _e2, _f2;
2206
2212
  return {
2207
2213
  ...item.revised_prompt ? { revisedPrompt: item.revised_prompt } : {},
2208
- created: (_a2 = response2.created) != null ? _a2 : void 0,
2214
+ created: (_a3 = response2.created) != null ? _a3 : void 0,
2209
2215
  size: (_b2 = response2.size) != null ? _b2 : void 0,
2210
2216
  quality: (_c2 = response2.quality) != null ? _c2 : void 0,
2211
2217
  background: (_d2 = response2.background) != null ? _d2 : void 0,
@@ -2269,10 +2275,10 @@ var OpenAIImageModel = class {
2269
2275
  providerMetadata: {
2270
2276
  openai: {
2271
2277
  images: response.data.map((item, index) => {
2272
- var _a2, _b2, _c2, _d2, _e2, _f2;
2278
+ var _a3, _b2, _c2, _d2, _e2, _f2;
2273
2279
  return {
2274
2280
  ...item.revised_prompt ? { revisedPrompt: item.revised_prompt } : {},
2275
- created: (_a2 = response.created) != null ? _a2 : void 0,
2281
+ created: (_a3 = response.created) != null ? _a3 : void 0,
2276
2282
  size: (_b2 = response.size) != null ? _b2 : void 0,
2277
2283
  quality: (_c2 = response.quality) != null ? _c2 : void 0,
2278
2284
  background: (_d2 = response.background) != null ? _d2 : void 0,
@@ -2515,8 +2521,8 @@ var OpenAITranscriptionModel = class {
2515
2521
  };
2516
2522
  }
2517
2523
  async doGenerate(options) {
2518
- var _a, _b, _c, _d, _e, _f, _g, _h;
2519
- const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
2524
+ var _a2, _b, _c, _d, _e, _f, _g, _h;
2525
+ const currentDate = (_c = (_b = (_a2 = this.config._internal) == null ? void 0 : _a2.currentDate) == null ? void 0 : _b.call(_a2)) != null ? _c : /* @__PURE__ */ new Date();
2520
2526
  const { formData, warnings } = await this.getArgs(options);
2521
2527
  const {
2522
2528
  value: response,
@@ -2650,8 +2656,8 @@ var OpenAISpeechModel = class {
2650
2656
  };
2651
2657
  }
2652
2658
  async doGenerate(options) {
2653
- var _a, _b, _c;
2654
- const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
2659
+ var _a2, _b, _c;
2660
+ const currentDate = (_c = (_b = (_a2 = this.config._internal) == null ? void 0 : _a2.currentDate) == null ? void 0 : _b.call(_a2)) != null ? _c : /* @__PURE__ */ new Date();
2655
2661
  const { requestBody, warnings } = await this.getArgs(options);
2656
2662
  const {
2657
2663
  value: audio,
@@ -2701,7 +2707,7 @@ import {
2701
2707
 
2702
2708
  // src/responses/convert-openai-responses-usage.ts
2703
2709
  function convertOpenAIResponsesUsage(usage) {
2704
- var _a, _b, _c, _d, _e, _f;
2710
+ var _a2, _b, _c, _d, _e, _f;
2705
2711
  if (usage == null) {
2706
2712
  return {
2707
2713
  inputTokens: {
@@ -2720,7 +2726,7 @@ function convertOpenAIResponsesUsage(usage) {
2720
2726
  }
2721
2727
  const inputTokens = usage.input_tokens;
2722
2728
  const outputTokens = usage.output_tokens;
2723
- const cachedTokens = (_b = (_a = usage.input_tokens_details) == null ? void 0 : _a.cached_tokens) != null ? _b : 0;
2729
+ const cachedTokens = (_b = (_a2 = usage.input_tokens_details) == null ? void 0 : _a2.cached_tokens) != null ? _b : 0;
2724
2730
  const cacheWriteTokens = (_d = (_c = usage.input_tokens_details) == null ? void 0 : _c.cache_write_tokens) != null ? _d : void 0;
2725
2731
  const reasoningTokens = (_f = (_e = usage.output_tokens_details) == null ? void 0 : _e.reasoning_tokens) != null ? _f : 0;
2726
2732
  return {
@@ -2977,8 +2983,8 @@ function getParallelToolCallMetadata({
2977
2983
  providerOptions,
2978
2984
  providerOptionsName
2979
2985
  }) {
2980
- var _a;
2981
- const metadata = (_a = providerOptions == null ? void 0 : providerOptions[providerOptionsName]) == null ? void 0 : _a.parallelToolCall;
2986
+ var _a2;
2987
+ const metadata = (_a2 = providerOptions == null ? void 0 : providerOptions[providerOptionsName]) == null ? void 0 : _a2.parallelToolCall;
2982
2988
  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) {
2983
2989
  return void 0;
2984
2990
  }
@@ -3053,19 +3059,19 @@ async function convertFunctionToolResultOutput({
3053
3059
  providerOptionsName,
3054
3060
  warnings
3055
3061
  }) {
3056
- var _a;
3062
+ var _a2;
3057
3063
  switch (output.type) {
3058
3064
  case "text":
3059
3065
  case "error-text":
3060
3066
  return output.value;
3061
3067
  case "execution-denied":
3062
- return (_a = output.reason) != null ? _a : "Tool call execution denied.";
3068
+ return (_a2 = output.reason) != null ? _a2 : "Tool call execution denied.";
3063
3069
  case "json":
3064
3070
  case "error-json":
3065
3071
  return JSON.stringify(output.value);
3066
3072
  case "content":
3067
3073
  return output.value.map((item) => {
3068
- var _a2, _b, _c, _d, _e;
3074
+ var _a3, _b, _c, _d, _e;
3069
3075
  const promptCacheBreakpoint = getPromptCacheBreakpoint2(
3070
3076
  item.providerOptions,
3071
3077
  providerOptionsName
@@ -3084,7 +3090,7 @@ async function convertFunctionToolResultOutput({
3084
3090
  return {
3085
3091
  type: "input_image",
3086
3092
  image_url: `data:${item.mediaType};base64,${item.data}`,
3087
- detail: (_b = (_a2 = item.providerOptions) == null ? void 0 : _a2[providerOptionsName]) == null ? void 0 : _b.imageDetail,
3093
+ detail: (_b = (_a3 = item.providerOptions) == null ? void 0 : _a3[providerOptionsName]) == null ? void 0 : _b.imageDetail,
3088
3094
  ...promptCacheBreakpoint != null && {
3089
3095
  prompt_cache_breakpoint: promptCacheBreakpoint
3090
3096
  }
@@ -3188,8 +3194,8 @@ function collectCompleteParallelToolResultGroups({
3188
3194
  return completeGroups;
3189
3195
  }
3190
3196
  function getPromptCacheBreakpoint2(providerOptions, providerOptionsName) {
3191
- var _a;
3192
- return (_a = providerOptions == null ? void 0 : providerOptions[providerOptionsName]) == null ? void 0 : _a.promptCacheBreakpoint;
3197
+ var _a2;
3198
+ return (_a2 = providerOptions == null ? void 0 : providerOptions[providerOptionsName]) == null ? void 0 : _a2.promptCacheBreakpoint;
3193
3199
  }
3194
3200
  function isFileId(data, prefixes) {
3195
3201
  if (!prefixes) return false;
@@ -3208,9 +3214,10 @@ async function convertToOpenAIResponsesInput({
3208
3214
  hasLocalShellTool = false,
3209
3215
  hasShellTool = false,
3210
3216
  hasApplyPatchTool = false,
3217
+ toolSearchToolName,
3211
3218
  customProviderToolNames
3212
3219
  }) {
3213
- 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;
3220
+ 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;
3214
3221
  let input = [];
3215
3222
  const warnings = [];
3216
3223
  const processedApprovalIds = /* @__PURE__ */ new Set();
@@ -3278,7 +3285,7 @@ async function convertToOpenAIResponsesInput({
3278
3285
  input.push({
3279
3286
  role: "user",
3280
3287
  content: content.map((part, index) => {
3281
- var _a2, _b2, _c2;
3288
+ var _a3, _b2, _c2;
3282
3289
  switch (part.type) {
3283
3290
  case "text": {
3284
3291
  const promptCacheBreakpoint = getPromptCacheBreakpoint2(
@@ -3305,7 +3312,7 @@ async function convertToOpenAIResponsesInput({
3305
3312
  ...part.data instanceof URL ? { image_url: part.data.toString() } : typeof part.data === "string" && isFileId(part.data, fileIdPrefixes) ? { file_id: part.data } : {
3306
3313
  image_url: `data:${mediaType};base64,${convertToBase642(part.data)}`
3307
3314
  },
3308
- detail: (_b2 = (_a2 = part.providerOptions) == null ? void 0 : _a2[providerOptionsName]) == null ? void 0 : _b2.imageDetail,
3315
+ detail: (_b2 = (_a3 = part.providerOptions) == null ? void 0 : _a3[providerOptionsName]) == null ? void 0 : _b2.imageDetail,
3309
3316
  ...promptCacheBreakpoint != null && {
3310
3317
  prompt_cache_breakpoint: promptCacheBreakpoint
3311
3318
  }
@@ -3346,7 +3353,7 @@ async function convertToOpenAIResponsesInput({
3346
3353
  for (const part of content) {
3347
3354
  switch (part.type) {
3348
3355
  case "text": {
3349
- const providerOpts = (_a = part.providerOptions) == null ? void 0 : _a[providerOptionsName];
3356
+ const providerOpts = (_a2 = part.providerOptions) == null ? void 0 : _a2[providerOptionsName];
3350
3357
  const id = providerOpts == null ? void 0 : providerOpts.itemId;
3351
3358
  const phase = providerOpts == null ? void 0 : providerOpts.phase;
3352
3359
  if (hasConversation && id != null) {
@@ -3401,7 +3408,7 @@ async function convertToOpenAIResponsesInput({
3401
3408
  const resolvedToolName = toolNameMapping.toProviderToolName(
3402
3409
  part.toolName
3403
3410
  );
3404
- if (resolvedToolName === "tool_search") {
3411
+ if (part.toolName === toolSearchToolName) {
3405
3412
  if (store && id != null) {
3406
3413
  input.push({ type: "item_reference", id });
3407
3414
  break;
@@ -3522,7 +3529,7 @@ async function convertToOpenAIResponsesInput({
3522
3529
  const resolvedResultToolName = toolNameMapping.toProviderToolName(
3523
3530
  part.toolName
3524
3531
  );
3525
- if (resolvedResultToolName === "tool_search") {
3532
+ if (part.toolName === toolSearchToolName) {
3526
3533
  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;
3527
3534
  if (store) {
3528
3535
  input.push({ type: "item_reference", id: itemId });
@@ -3720,7 +3727,7 @@ async function convertToOpenAIResponsesInput({
3720
3727
  const resolvedToolName = toolNameMapping.toProviderToolName(
3721
3728
  part.toolName
3722
3729
  );
3723
- if (resolvedToolName === "tool_search" && output.type === "json") {
3730
+ if (part.toolName === toolSearchToolName && output.type === "json") {
3724
3731
  const parsedOutput = await validateTypes({
3725
3732
  value: output.value,
3726
3733
  schema: toolSearchOutputSchema
@@ -3794,7 +3801,7 @@ async function convertToOpenAIResponsesInput({
3794
3801
  break;
3795
3802
  case "content":
3796
3803
  outputValue = output.value.map((item) => {
3797
- var _a2, _b2, _c2, _d2, _e2;
3804
+ var _a3, _b2, _c2, _d2, _e2;
3798
3805
  const promptCacheBreakpoint = getPromptCacheBreakpoint2(
3799
3806
  item.providerOptions,
3800
3807
  providerOptionsName
@@ -3812,7 +3819,7 @@ async function convertToOpenAIResponsesInput({
3812
3819
  return {
3813
3820
  type: "input_image",
3814
3821
  image_url: `data:${item.mediaType};base64,${item.data}`,
3815
- detail: (_b2 = (_a2 = item.providerOptions) == null ? void 0 : _a2[providerOptionsName]) == null ? void 0 : _b2.imageDetail,
3822
+ detail: (_b2 = (_a3 = item.providerOptions) == null ? void 0 : _a3[providerOptionsName]) == null ? void 0 : _b2.imageDetail,
3816
3823
  ...promptCacheBreakpoint != null && {
3817
3824
  prompt_cache_breakpoint: promptCacheBreakpoint
3818
3825
  }
@@ -3933,6 +3940,22 @@ var jsonValueSchema = z18.lazy(
3933
3940
  z18.record(z18.string(), jsonValueSchema.optional())
3934
3941
  ])
3935
3942
  );
3943
+ function isRecord(value) {
3944
+ return value != null && typeof value === "object" && !Array.isArray(value);
3945
+ }
3946
+ var openaiResponsesLocalShellCallSchema = z18.object({
3947
+ type: z18.literal("local_shell_call"),
3948
+ id: z18.string(),
3949
+ call_id: z18.string(),
3950
+ action: z18.object({
3951
+ type: z18.literal("exec"),
3952
+ command: z18.array(z18.string()),
3953
+ timeout_ms: z18.number().optional(),
3954
+ user: z18.string().optional(),
3955
+ working_directory: z18.string().optional(),
3956
+ env: z18.record(z18.string(), z18.string()).optional()
3957
+ })
3958
+ });
3936
3959
  var openaiResponsesNestedErrorChunkSchema = z18.object({
3937
3960
  type: z18.literal("error"),
3938
3961
  sequence_number: z18.number(),
@@ -3950,6 +3973,60 @@ var openaiResponsesErrorChunkSchema = z18.object({
3950
3973
  message: z18.string(),
3951
3974
  param: z18.string().nullish()
3952
3975
  });
3976
+ var openaiResponsesModeledChunkTypes = /* @__PURE__ */ new Set([
3977
+ "error",
3978
+ "response.apply_patch_call_operation_diff.delta",
3979
+ "response.apply_patch_call_operation_diff.done",
3980
+ "response.code_interpreter_call_code.delta",
3981
+ "response.code_interpreter_call_code.done",
3982
+ "response.completed",
3983
+ "response.created",
3984
+ "response.custom_tool_call_input.delta",
3985
+ "response.failed",
3986
+ "response.function_call_arguments.delta",
3987
+ "response.function_call_arguments.done",
3988
+ "response.image_generation_call.partial_image",
3989
+ "response.incomplete",
3990
+ "response.output_item.added",
3991
+ "response.output_item.done",
3992
+ "response.output_text.annotation.added",
3993
+ "response.output_text.delta",
3994
+ "response.reasoning_summary_part.added",
3995
+ "response.reasoning_summary_part.done",
3996
+ "response.reasoning_summary_text.delta"
3997
+ ]);
3998
+ var openaiResponsesModeledOutputItemTypes = /* @__PURE__ */ new Set([
3999
+ "apply_patch_call",
4000
+ "code_interpreter_call",
4001
+ "computer_call",
4002
+ "custom_tool_call",
4003
+ "file_search_call",
4004
+ "function_call",
4005
+ "image_generation_call",
4006
+ "local_shell_call",
4007
+ "mcp_approval_request",
4008
+ "mcp_call",
4009
+ "mcp_list_tools",
4010
+ "message",
4011
+ "reasoning",
4012
+ "shell_call",
4013
+ "shell_call_output",
4014
+ "tool_search_call",
4015
+ "tool_search_output",
4016
+ "web_search_call"
4017
+ ]);
4018
+ function isModeledOpenAIResponsesChunk(value) {
4019
+ if (typeof value.type !== "string" || !openaiResponsesModeledChunkTypes.has(value.type)) {
4020
+ return false;
4021
+ }
4022
+ if (value.type !== "response.output_item.added" && value.type !== "response.output_item.done") {
4023
+ return true;
4024
+ }
4025
+ if (!isRecord(value.item) || typeof value.item.type !== "string") {
4026
+ return true;
4027
+ }
4028
+ return openaiResponsesModeledOutputItemTypes.has(value.item.type);
4029
+ }
3953
4030
  var openaiResponsesChunkSchema = lazySchema16(
3954
4031
  () => zodSchema16(
3955
4032
  z18.union([
@@ -4068,6 +4145,7 @@ var openaiResponsesChunkSchema = lazySchema16(
4068
4145
  type: z18.literal("file_search_call"),
4069
4146
  id: z18.string()
4070
4147
  }),
4148
+ openaiResponsesLocalShellCallSchema,
4071
4149
  z18.object({
4072
4150
  type: z18.literal("image_generation_call"),
4073
4151
  id: z18.string()
@@ -4266,19 +4344,7 @@ var openaiResponsesChunkSchema = lazySchema16(
4266
4344
  })
4267
4345
  ).nullish()
4268
4346
  }),
4269
- z18.object({
4270
- type: z18.literal("local_shell_call"),
4271
- id: z18.string(),
4272
- call_id: z18.string(),
4273
- action: z18.object({
4274
- type: z18.literal("exec"),
4275
- command: z18.array(z18.string()),
4276
- timeout_ms: z18.number().optional(),
4277
- user: z18.string().optional(),
4278
- working_directory: z18.string().optional(),
4279
- env: z18.record(z18.string(), z18.string()).optional()
4280
- })
4281
- }),
4347
+ openaiResponsesLocalShellCallSchema,
4282
4348
  z18.object({
4283
4349
  type: z18.literal("computer_call"),
4284
4350
  id: z18.string(),
@@ -4405,6 +4471,14 @@ var openaiResponsesChunkSchema = lazySchema16(
4405
4471
  output_index: z18.number(),
4406
4472
  delta: z18.string()
4407
4473
  }),
4474
+ z18.object({
4475
+ // `name` is documented as required but omitted from live API events:
4476
+ // https://github.com/openai/openai-openapi/issues/545
4477
+ type: z18.literal("response.function_call_arguments.done"),
4478
+ item_id: z18.string(),
4479
+ output_index: z18.number(),
4480
+ arguments: z18.string()
4481
+ }),
4408
4482
  z18.object({
4409
4483
  type: z18.literal("response.custom_tool_call_input.delta"),
4410
4484
  item_id: z18.string(),
@@ -4491,7 +4565,9 @@ var openaiResponsesChunkSchema = lazySchema16(
4491
4565
  }),
4492
4566
  openaiResponsesNestedErrorChunkSchema,
4493
4567
  openaiResponsesErrorChunkSchema,
4494
- z18.object({ type: z18.string() }).loose().transform((value) => ({
4568
+ z18.object({ type: z18.string() }).loose().refine((value) => !isModeledOpenAIResponsesChunk(value), {
4569
+ message: "Known response chunk failed schema validation"
4570
+ }).transform((value) => ({
4495
4571
  type: "unknown_chunk",
4496
4572
  message: value.type
4497
4573
  }))
@@ -4631,19 +4707,7 @@ var openaiResponsesResponseSchema = lazySchema16(
4631
4707
  id: z18.string(),
4632
4708
  result: z18.string()
4633
4709
  }),
4634
- z18.object({
4635
- type: z18.literal("local_shell_call"),
4636
- id: z18.string(),
4637
- call_id: z18.string(),
4638
- action: z18.object({
4639
- type: z18.literal("exec"),
4640
- command: z18.array(z18.string()),
4641
- timeout_ms: z18.number().optional(),
4642
- user: z18.string().optional(),
4643
- working_directory: z18.string().optional(),
4644
- env: z18.record(z18.string(), z18.string()).optional()
4645
- })
4646
- }),
4710
+ openaiResponsesLocalShellCallSchema,
4647
4711
  z18.object({
4648
4712
  type: z18.literal("function_call"),
4649
4713
  call_id: z18.string(),
@@ -5450,7 +5514,7 @@ async function prepareResponsesTools({
5450
5514
  toolNameMapping,
5451
5515
  customProviderToolNames
5452
5516
  }) {
5453
- var _a, _b, _c, _d;
5517
+ var _a2, _b, _c, _d;
5454
5518
  tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
5455
5519
  const toolWarnings = [];
5456
5520
  if (tools == null) {
@@ -5476,7 +5540,7 @@ async function prepareResponsesTools({
5476
5540
  for (const tool of tools) {
5477
5541
  switch (tool.type) {
5478
5542
  case "function": {
5479
- const openaiOptions = (_a = tool.providerOptions) == null ? void 0 : _a.openai;
5543
+ const openaiOptions = (_a2 = tool.providerOptions) == null ? void 0 : _a2.openai;
5480
5544
  const openaiFunctionTool = prepareFunctionTool({
5481
5545
  tool,
5482
5546
  options: openaiOptions
@@ -5893,13 +5957,13 @@ function mapShellSkills(skills) {
5893
5957
 
5894
5958
  // src/responses/openai-responses-language-model.ts
5895
5959
  function extractApprovalRequestIdToToolCallIdMapping(prompt) {
5896
- var _a, _b;
5960
+ var _a2, _b;
5897
5961
  const mapping = {};
5898
5962
  for (const message of prompt) {
5899
5963
  if (message.role !== "assistant") continue;
5900
5964
  for (const part of message.content) {
5901
5965
  if (part.type !== "tool-call") continue;
5902
- const approvalRequestId = (_b = (_a = part.providerOptions) == null ? void 0 : _a.openai) == null ? void 0 : _b.approvalRequestId;
5966
+ const approvalRequestId = (_b = (_a2 = part.providerOptions) == null ? void 0 : _a2.openai) == null ? void 0 : _b.approvalRequestId;
5903
5967
  if (approvalRequestId != null) {
5904
5968
  mapping[approvalRequestId] = part.toolCallId;
5905
5969
  }
@@ -5935,7 +5999,7 @@ var OpenAIResponsesLanguageModel = class {
5935
5999
  toolChoice,
5936
6000
  responseFormat
5937
6001
  }) {
5938
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
6002
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
5939
6003
  const warnings = [];
5940
6004
  const modelCapabilities = getOpenAILanguageModelCapabilities(this.modelId);
5941
6005
  if (topK != null) {
@@ -5966,7 +6030,7 @@ var OpenAIResponsesLanguageModel = class {
5966
6030
  schema: openaiLanguageModelResponsesOptionsSchema
5967
6031
  });
5968
6032
  }
5969
- const isReasoningModel = (_a = openaiOptions == null ? void 0 : openaiOptions.forceReasoning) != null ? _a : modelCapabilities.isReasoningModel;
6033
+ const isReasoningModel = (_a2 = openaiOptions == null ? void 0 : openaiOptions.forceReasoning) != null ? _a2 : modelCapabilities.isReasoningModel;
5970
6034
  if ((openaiOptions == null ? void 0 : openaiOptions.conversation) && (openaiOptions == null ? void 0 : openaiOptions.previousResponseId)) {
5971
6035
  warnings.push({
5972
6036
  type: "unsupported",
@@ -6015,6 +6079,7 @@ var OpenAIResponsesLanguageModel = class {
6015
6079
  hasLocalShellTool: hasOpenAITool("openai.local_shell"),
6016
6080
  hasShellTool: hasOpenAITool("openai.shell"),
6017
6081
  hasApplyPatchTool: hasOpenAITool("openai.apply_patch"),
6082
+ toolSearchToolName: getOpenAIToolName("openai.tool_search"),
6018
6083
  customProviderToolNames: customProviderToolNames.size > 0 ? customProviderToolNames : void 0
6019
6084
  });
6020
6085
  warnings.push(...inputWarnings);
@@ -6027,8 +6092,12 @@ var OpenAIResponsesLanguageModel = class {
6027
6092
  include = [...include, key];
6028
6093
  }
6029
6094
  }
6095
+ function getOpenAIToolName(id) {
6096
+ var _a3;
6097
+ return (_a3 = tools == null ? void 0 : tools.find((tool) => tool.type === "provider" && tool.id === id)) == null ? void 0 : _a3.name;
6098
+ }
6030
6099
  function hasOpenAITool(id) {
6031
- return (tools == null ? void 0 : tools.find((tool) => tool.type === "provider" && tool.id === id)) != null;
6100
+ return getOpenAIToolName(id) != null;
6032
6101
  }
6033
6102
  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;
6034
6103
  if (topLogprobs) {
@@ -6188,7 +6257,7 @@ var OpenAIResponsesLanguageModel = class {
6188
6257
  };
6189
6258
  }
6190
6259
  async doGenerate(options) {
6191
- 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;
6260
+ 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;
6192
6261
  const {
6193
6262
  args: body,
6194
6263
  warnings,
@@ -6230,7 +6299,7 @@ var OpenAIResponsesLanguageModel = class {
6230
6299
  }
6231
6300
  const content = [];
6232
6301
  const logprobs = [];
6233
- const functionTools = (_b = (_a = options.tools) == null ? void 0 : _a.filter(
6302
+ const functionTools = (_b = (_a2 = options.tools) == null ? void 0 : _a2.filter(
6234
6303
  (tool) => tool.type === "function"
6235
6304
  )) != null ? _b : [];
6236
6305
  let hasFunctionCall = false;
@@ -6682,7 +6751,7 @@ var OpenAIResponsesLanguageModel = class {
6682
6751
  };
6683
6752
  }
6684
6753
  async doStream(options) {
6685
- var _a, _b;
6754
+ var _a2, _b;
6686
6755
  const {
6687
6756
  args: body,
6688
6757
  warnings,
@@ -6720,7 +6789,7 @@ var OpenAIResponsesLanguageModel = class {
6720
6789
  });
6721
6790
  const self = this;
6722
6791
  const approvalRequestIdToDummyToolCallIdFromPrompt = extractApprovalRequestIdToToolCallIdMapping(options.prompt);
6723
- const functionTools = (_b = (_a = options.tools) == null ? void 0 : _a.filter(
6792
+ const functionTools = (_b = (_a2 = options.tools) == null ? void 0 : _a2.filter(
6724
6793
  (tool) => tool.type === "function"
6725
6794
  )) != null ? _b : [];
6726
6795
  const approvalRequestIdToDummyToolCallIdFromStream = /* @__PURE__ */ new Map();
@@ -6747,7 +6816,7 @@ var OpenAIResponsesLanguageModel = class {
6747
6816
  controller.enqueue({ type: "stream-start", warnings });
6748
6817
  },
6749
6818
  transform(chunk, controller) {
6750
- 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;
6819
+ 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;
6751
6820
  if (options.includeRawChunks) {
6752
6821
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
6753
6822
  }
@@ -6759,6 +6828,7 @@ var OpenAIResponsesLanguageModel = class {
6759
6828
  requestBodyValues: body,
6760
6829
  responseHeaders
6761
6830
  }) : chunk.error;
6831
+ encounteredStreamError = true;
6762
6832
  finishReason = { unified: "error", raw: void 0 };
6763
6833
  controller.enqueue({ type: "error", error });
6764
6834
  return;
@@ -6877,7 +6947,7 @@ var OpenAIResponsesLanguageModel = class {
6877
6947
  ongoingToolCalls[value.output_index] = {
6878
6948
  toolName,
6879
6949
  toolCallId,
6880
- toolSearchExecution: (_a2 = value.item.execution) != null ? _a2 : "server"
6950
+ toolSearchExecution: (_a3 = value.item.execution) != null ? _a3 : "server"
6881
6951
  };
6882
6952
  if (isHosted) {
6883
6953
  controller.enqueue({
@@ -6990,14 +7060,14 @@ var OpenAIResponsesLanguageModel = class {
6990
7060
  tools: functionTools
6991
7061
  });
6992
7062
  const enqueueUnexpandedToolCall = () => {
6993
- var _a3;
7063
+ var _a4;
6994
7064
  if (suppressInputStreaming) {
6995
7065
  controller.enqueue({
6996
7066
  type: "tool-input-start",
6997
7067
  id: item.call_id,
6998
7068
  toolName: item.name
6999
7069
  });
7000
- const bufferedInputDeltas = (_a3 = ongoingToolCall == null ? void 0 : ongoingToolCall.bufferedInputDeltas) != null ? _a3 : [];
7070
+ const bufferedInputDeltas = (_a4 = ongoingToolCall == null ? void 0 : ongoingToolCall.bufferedInputDeltas) != null ? _a4 : [];
7001
7071
  if (bufferedInputDeltas.length > 0) {
7002
7072
  for (const delta of bufferedInputDeltas) {
7003
7073
  controller.enqueue({
@@ -7558,13 +7628,15 @@ var OpenAIResponsesLanguageModel = class {
7558
7628
  activeReasoning[value.item_id].summaryParts[value.summary_index] = "can-conclude";
7559
7629
  }
7560
7630
  } else if (isResponseFinishedChunk(value)) {
7561
- finishReason = {
7562
- unified: mapOpenAIResponseFinishReason({
7563
- finishReason: (_x = value.response.incomplete_details) == null ? void 0 : _x.reason,
7564
- hasFunctionCall
7565
- }),
7566
- raw: (_z = (_y = value.response.incomplete_details) == null ? void 0 : _y.reason) != null ? _z : void 0
7567
- };
7631
+ if (!encounteredStreamError) {
7632
+ finishReason = {
7633
+ unified: mapOpenAIResponseFinishReason({
7634
+ finishReason: (_x = value.response.incomplete_details) == null ? void 0 : _x.reason,
7635
+ hasFunctionCall
7636
+ }),
7637
+ raw: (_z = (_y = value.response.incomplete_details) == null ? void 0 : _y.reason) != null ? _z : void 0
7638
+ };
7639
+ }
7568
7640
  usage = value.response.usage;
7569
7641
  if (typeof value.response.service_tier === "string") {
7570
7642
  serviceTier = value.response.service_tier;
@@ -7666,7 +7738,7 @@ var OpenAIResponsesLanguageModel = class {
7666
7738
  }
7667
7739
  },
7668
7740
  flush(controller) {
7669
- var _a2;
7741
+ var _a3;
7670
7742
  for (const toolCall of Object.values(ongoingToolCalls)) {
7671
7743
  if (!(toolCall == null ? void 0 : toolCall.suppressInputStreaming)) {
7672
7744
  continue;
@@ -7676,7 +7748,7 @@ var OpenAIResponsesLanguageModel = class {
7676
7748
  id: toolCall.toolCallId,
7677
7749
  toolName: toolCall.toolName
7678
7750
  });
7679
- for (const delta of (_a2 = toolCall.bufferedInputDeltas) != null ? _a2 : []) {
7751
+ for (const delta of (_a3 = toolCall.bufferedInputDeltas) != null ? _a3 : []) {
7680
7752
  controller.enqueue({
7681
7753
  type: "tool-input-delta",
7682
7754
  id: toolCall.toolCallId,
@@ -7781,7 +7853,7 @@ function isResponseOutputChunk(chunk) {
7781
7853
  return !(chunk.type === "response.created" || chunk.type === "response.failed" || chunk.type === "error" || chunk.type === "unknown_chunk");
7782
7854
  }
7783
7855
  function mapWebSearchOutput(action) {
7784
- var _a;
7856
+ var _a2;
7785
7857
  if (action == null) {
7786
7858
  return {};
7787
7859
  }
@@ -7790,7 +7862,7 @@ function mapWebSearchOutput(action) {
7790
7862
  return {
7791
7863
  action: {
7792
7864
  type: "search",
7793
- query: (_a = action.query) != null ? _a : void 0,
7865
+ query: (_a2 = action.query) != null ? _a2 : void 0,
7794
7866
  ...action.queries != null && { queries: action.queries }
7795
7867
  },
7796
7868
  // include sources when provided by the Responses API (behind include flag)