@ai-sdk/openai 3.0.0-beta.99 → 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -56,8 +56,8 @@ var openaiFailedResponseHandler = (0, import_provider_utils.createJsonErrorRespo
56
56
  function getOpenAILanguageModelCapabilities(modelId) {
57
57
  const supportsFlexProcessing = modelId.startsWith("o3") || modelId.startsWith("o4-mini") || modelId.startsWith("gpt-5") && !modelId.startsWith("gpt-5-chat");
58
58
  const supportsPriorityProcessing = modelId.startsWith("gpt-4") || modelId.startsWith("gpt-5-mini") || modelId.startsWith("gpt-5") && !modelId.startsWith("gpt-5-nano") && !modelId.startsWith("gpt-5-chat") || modelId.startsWith("o3") || modelId.startsWith("o4-mini");
59
- const isReasoningModel = !(modelId.startsWith("gpt-3") || modelId.startsWith("gpt-4") || modelId.startsWith("chatgpt-4o") || modelId.startsWith("gpt-5-chat"));
60
- const supportsNonReasoningParameters = modelId.startsWith("gpt-5.1");
59
+ const isReasoningModel = modelId.startsWith("o1") || modelId.startsWith("o3") || modelId.startsWith("o4-mini") || modelId.startsWith("codex-mini") || modelId.startsWith("computer-use-preview") || modelId.startsWith("gpt-5") && !modelId.startsWith("gpt-5-chat");
60
+ const supportsNonReasoningParameters = modelId.startsWith("gpt-5.1") || modelId.startsWith("gpt-5.2");
61
61
  const systemMessageMode = isReasoningModel ? "developer" : "system";
62
62
  return {
63
63
  supportsFlexProcessing,
@@ -256,6 +256,9 @@ function convertToOpenAIChatMessages({
256
256
  }
257
257
  case "tool": {
258
258
  for (const toolResponse of content) {
259
+ if (toolResponse.type === "tool-approval-response") {
260
+ continue;
261
+ }
259
262
  const output = toolResponse.output;
260
263
  let contentValue;
261
264
  switch (output.type) {
@@ -315,7 +318,7 @@ function mapOpenAIFinishReason(finishReason) {
315
318
  case "tool_calls":
316
319
  return "tool-calls";
317
320
  default:
318
- return "unknown";
321
+ return "other";
319
322
  }
320
323
  }
321
324
 
@@ -556,7 +559,26 @@ var openaiChatLanguageModelOptions = (0, import_provider_utils4.lazySchema)(
556
559
  * username or email address, in order to avoid sending us any identifying
557
560
  * information.
558
561
  */
559
- safetyIdentifier: import_v43.z.string().optional()
562
+ safetyIdentifier: import_v43.z.string().optional(),
563
+ /**
564
+ * Override the system message mode for this model.
565
+ * - 'system': Use the 'system' role for system messages (default for most models)
566
+ * - 'developer': Use the 'developer' role for system messages (used by reasoning models)
567
+ * - 'remove': Remove system messages entirely
568
+ *
569
+ * If not specified, the mode is automatically determined based on the model.
570
+ */
571
+ systemMessageMode: import_v43.z.enum(["system", "developer", "remove"]).optional(),
572
+ /**
573
+ * Force treating this model as a reasoning model.
574
+ *
575
+ * This is useful for "stealth" reasoning models (e.g. via a custom baseURL)
576
+ * where the model ID is not recognized by the SDK's allowlist.
577
+ *
578
+ * When enabled, the SDK applies reasoning-model parameter compatibility rules
579
+ * and defaults `systemMessageMode` to `developer` unless overridden.
580
+ */
581
+ forceReasoning: import_v43.z.boolean().optional()
560
582
  })
561
583
  )
562
584
  );
@@ -651,7 +673,7 @@ var OpenAIChatLanguageModel = class {
651
673
  toolChoice,
652
674
  providerOptions
653
675
  }) {
654
- var _a, _b, _c;
676
+ var _a, _b, _c, _d, _e;
655
677
  const warnings = [];
656
678
  const openaiOptions = (_a = await (0, import_provider_utils5.parseProviderOptions)({
657
679
  provider: "openai",
@@ -659,17 +681,18 @@ var OpenAIChatLanguageModel = class {
659
681
  schema: openaiChatLanguageModelOptions
660
682
  })) != null ? _a : {};
661
683
  const modelCapabilities = getOpenAILanguageModelCapabilities(this.modelId);
684
+ const isReasoningModel = (_b = openaiOptions.forceReasoning) != null ? _b : modelCapabilities.isReasoningModel;
662
685
  if (topK != null) {
663
686
  warnings.push({ type: "unsupported", feature: "topK" });
664
687
  }
665
688
  const { messages, warnings: messageWarnings } = convertToOpenAIChatMessages(
666
689
  {
667
690
  prompt,
668
- systemMessageMode: modelCapabilities.systemMessageMode
691
+ systemMessageMode: (_c = openaiOptions.systemMessageMode) != null ? _c : isReasoningModel ? "developer" : modelCapabilities.systemMessageMode
669
692
  }
670
693
  );
671
694
  warnings.push(...messageWarnings);
672
- const strictJsonSchema = (_b = openaiOptions.strictJsonSchema) != null ? _b : true;
695
+ const strictJsonSchema = (_d = openaiOptions.strictJsonSchema) != null ? _d : true;
673
696
  const baseArgs = {
674
697
  // model id:
675
698
  model: this.modelId,
@@ -690,7 +713,7 @@ var OpenAIChatLanguageModel = class {
690
713
  json_schema: {
691
714
  schema: responseFormat.schema,
692
715
  strict: strictJsonSchema,
693
- name: (_c = responseFormat.name) != null ? _c : "response",
716
+ name: (_e = responseFormat.name) != null ? _e : "response",
694
717
  description: responseFormat.description
695
718
  }
696
719
  } : { type: "json_object" } : void 0,
@@ -711,7 +734,7 @@ var OpenAIChatLanguageModel = class {
711
734
  // messages:
712
735
  messages
713
736
  };
714
- if (modelCapabilities.isReasoningModel) {
737
+ if (isReasoningModel) {
715
738
  if (openaiOptions.reasoningEffort !== "none" || !modelCapabilities.supportsNonReasoningParameters) {
716
739
  if (baseArgs.temperature != null) {
717
740
  baseArgs.temperature = void 0;
@@ -817,7 +840,7 @@ var OpenAIChatLanguageModel = class {
817
840
  };
818
841
  }
819
842
  async doGenerate(options) {
820
- var _a, _b, _c, _d, _e, _f;
843
+ var _a, _b, _c, _d, _e, _f, _g;
821
844
  const { args: body, warnings } = await this.getArgs(options);
822
845
  const {
823
846
  responseHeaders,
@@ -874,7 +897,10 @@ var OpenAIChatLanguageModel = class {
874
897
  }
875
898
  return {
876
899
  content,
877
- finishReason: mapOpenAIFinishReason(choice.finish_reason),
900
+ finishReason: {
901
+ unified: mapOpenAIFinishReason(choice.finish_reason),
902
+ raw: (_g = choice.finish_reason) != null ? _g : void 0
903
+ },
878
904
  usage: convertOpenAIChatUsage(response.usage),
879
905
  request: { body },
880
906
  response: {
@@ -910,7 +936,10 @@ var OpenAIChatLanguageModel = class {
910
936
  fetch: this.config.fetch
911
937
  });
912
938
  const toolCalls = [];
913
- let finishReason = "unknown";
939
+ let finishReason = {
940
+ unified: "other",
941
+ raw: void 0
942
+ };
914
943
  let usage = void 0;
915
944
  let metadataExtracted = false;
916
945
  let isActiveText = false;
@@ -927,13 +956,13 @@ var OpenAIChatLanguageModel = class {
927
956
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
928
957
  }
929
958
  if (!chunk.success) {
930
- finishReason = "error";
959
+ finishReason = { unified: "error", raw: void 0 };
931
960
  controller.enqueue({ type: "error", error: chunk.error });
932
961
  return;
933
962
  }
934
963
  const value = chunk.value;
935
964
  if ("error" in value) {
936
- finishReason = "error";
965
+ finishReason = { unified: "error", raw: void 0 };
937
966
  controller.enqueue({ type: "error", error: value.error });
938
967
  return;
939
968
  }
@@ -958,7 +987,10 @@ var OpenAIChatLanguageModel = class {
958
987
  }
959
988
  const choice = value.choices[0];
960
989
  if ((choice == null ? void 0 : choice.finish_reason) != null) {
961
- finishReason = mapOpenAIFinishReason(choice.finish_reason);
990
+ finishReason = {
991
+ unified: mapOpenAIFinishReason(choice.finish_reason),
992
+ raw: choice.finish_reason
993
+ };
962
994
  }
963
995
  if (((_e = choice == null ? void 0 : choice.logprobs) == null ? void 0 : _e.content) != null) {
964
996
  providerMetadata.openai.logprobs = choice.logprobs.content;
@@ -1238,7 +1270,7 @@ function mapOpenAIFinishReason2(finishReason) {
1238
1270
  case "tool_calls":
1239
1271
  return "tool-calls";
1240
1272
  default:
1241
- return "unknown";
1273
+ return "other";
1242
1274
  }
1243
1275
  }
1244
1276
 
@@ -1436,6 +1468,7 @@ var OpenAICompletionLanguageModel = class {
1436
1468
  };
1437
1469
  }
1438
1470
  async doGenerate(options) {
1471
+ var _a;
1439
1472
  const { args, warnings } = await this.getArgs(options);
1440
1473
  const {
1441
1474
  responseHeaders,
@@ -1463,7 +1496,10 @@ var OpenAICompletionLanguageModel = class {
1463
1496
  return {
1464
1497
  content: [{ type: "text", text: choice.text }],
1465
1498
  usage: convertOpenAICompletionUsage(response.usage),
1466
- finishReason: mapOpenAIFinishReason2(choice.finish_reason),
1499
+ finishReason: {
1500
+ unified: mapOpenAIFinishReason2(choice.finish_reason),
1501
+ raw: (_a = choice.finish_reason) != null ? _a : void 0
1502
+ },
1467
1503
  request: { body: args },
1468
1504
  response: {
1469
1505
  ...getResponseMetadata2(response),
@@ -1497,7 +1533,10 @@ var OpenAICompletionLanguageModel = class {
1497
1533
  abortSignal: options.abortSignal,
1498
1534
  fetch: this.config.fetch
1499
1535
  });
1500
- let finishReason = "unknown";
1536
+ let finishReason = {
1537
+ unified: "other",
1538
+ raw: void 0
1539
+ };
1501
1540
  const providerMetadata = { openai: {} };
1502
1541
  let usage = void 0;
1503
1542
  let isFirstChunk = true;
@@ -1512,13 +1551,13 @@ var OpenAICompletionLanguageModel = class {
1512
1551
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
1513
1552
  }
1514
1553
  if (!chunk.success) {
1515
- finishReason = "error";
1554
+ finishReason = { unified: "error", raw: void 0 };
1516
1555
  controller.enqueue({ type: "error", error: chunk.error });
1517
1556
  return;
1518
1557
  }
1519
1558
  const value = chunk.value;
1520
1559
  if ("error" in value) {
1521
- finishReason = "error";
1560
+ finishReason = { unified: "error", raw: void 0 };
1522
1561
  controller.enqueue({ type: "error", error: value.error });
1523
1562
  return;
1524
1563
  }
@@ -1535,7 +1574,10 @@ var OpenAICompletionLanguageModel = class {
1535
1574
  }
1536
1575
  const choice = value.choices[0];
1537
1576
  if ((choice == null ? void 0 : choice.finish_reason) != null) {
1538
- finishReason = mapOpenAIFinishReason2(choice.finish_reason);
1577
+ finishReason = {
1578
+ unified: mapOpenAIFinishReason2(choice.finish_reason),
1579
+ raw: choice.finish_reason
1580
+ };
1539
1581
  }
1540
1582
  if ((choice == null ? void 0 : choice.logprobs) != null) {
1541
1583
  providerMetadata.openai.logprobs = choice.logprobs;
@@ -1706,11 +1748,13 @@ var modelMaxImagesPerCall = {
1706
1748
  "dall-e-3": 1,
1707
1749
  "dall-e-2": 10,
1708
1750
  "gpt-image-1": 10,
1709
- "gpt-image-1-mini": 10
1751
+ "gpt-image-1-mini": 10,
1752
+ "gpt-image-1.5": 10
1710
1753
  };
1711
1754
  var hasDefaultResponseFormat = /* @__PURE__ */ new Set([
1712
1755
  "gpt-image-1",
1713
- "gpt-image-1-mini"
1756
+ "gpt-image-1-mini",
1757
+ "gpt-image-1.5"
1714
1758
  ]);
1715
1759
 
1716
1760
  // src/image/openai-image-model.ts
@@ -1729,6 +1773,8 @@ var OpenAIImageModel = class {
1729
1773
  }
1730
1774
  async doGenerate({
1731
1775
  prompt,
1776
+ files,
1777
+ mask,
1732
1778
  n,
1733
1779
  size,
1734
1780
  aspectRatio,
@@ -1737,7 +1783,7 @@ var OpenAIImageModel = class {
1737
1783
  headers,
1738
1784
  abortSignal
1739
1785
  }) {
1740
- var _a, _b, _c, _d, _e, _f, _g;
1786
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
1741
1787
  const warnings = [];
1742
1788
  if (aspectRatio != null) {
1743
1789
  warnings.push({
@@ -1750,6 +1796,72 @@ var OpenAIImageModel = class {
1750
1796
  warnings.push({ type: "unsupported", feature: "seed" });
1751
1797
  }
1752
1798
  const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
1799
+ if (files != null) {
1800
+ const { value: response2, responseHeaders: responseHeaders2 } = await (0, import_provider_utils13.postFormDataToApi)({
1801
+ url: this.config.url({
1802
+ path: "/images/edits",
1803
+ modelId: this.modelId
1804
+ }),
1805
+ headers: (0, import_provider_utils13.combineHeaders)(this.config.headers(), headers),
1806
+ formData: (0, import_provider_utils13.convertToFormData)({
1807
+ model: this.modelId,
1808
+ prompt,
1809
+ image: await Promise.all(
1810
+ files.map(
1811
+ (file) => file.type === "file" ? new Blob(
1812
+ [
1813
+ file.data instanceof Uint8Array ? new Blob([file.data], {
1814
+ type: file.mediaType
1815
+ }) : new Blob([(0, import_provider_utils13.convertBase64ToUint8Array)(file.data)], {
1816
+ type: file.mediaType
1817
+ })
1818
+ ],
1819
+ { type: file.mediaType }
1820
+ ) : (0, import_provider_utils13.downloadBlob)(file.url)
1821
+ )
1822
+ ),
1823
+ mask: mask != null ? await fileToBlob(mask) : void 0,
1824
+ n,
1825
+ size,
1826
+ ...(_d = providerOptions.openai) != null ? _d : {}
1827
+ }),
1828
+ failedResponseHandler: openaiFailedResponseHandler,
1829
+ successfulResponseHandler: (0, import_provider_utils13.createJsonResponseHandler)(
1830
+ openaiImageResponseSchema
1831
+ ),
1832
+ abortSignal,
1833
+ fetch: this.config.fetch
1834
+ });
1835
+ return {
1836
+ images: response2.data.map((item) => item.b64_json),
1837
+ warnings,
1838
+ usage: response2.usage != null ? {
1839
+ inputTokens: (_e = response2.usage.input_tokens) != null ? _e : void 0,
1840
+ outputTokens: (_f = response2.usage.output_tokens) != null ? _f : void 0,
1841
+ totalTokens: (_g = response2.usage.total_tokens) != null ? _g : void 0
1842
+ } : void 0,
1843
+ response: {
1844
+ timestamp: currentDate,
1845
+ modelId: this.modelId,
1846
+ headers: responseHeaders2
1847
+ },
1848
+ providerMetadata: {
1849
+ openai: {
1850
+ images: response2.data.map((item) => {
1851
+ var _a2, _b2, _c2, _d2, _e2;
1852
+ return {
1853
+ ...item.revised_prompt ? { revisedPrompt: item.revised_prompt } : {},
1854
+ created: (_a2 = response2.created) != null ? _a2 : void 0,
1855
+ size: (_b2 = response2.size) != null ? _b2 : void 0,
1856
+ quality: (_c2 = response2.quality) != null ? _c2 : void 0,
1857
+ background: (_d2 = response2.background) != null ? _d2 : void 0,
1858
+ outputFormat: (_e2 = response2.output_format) != null ? _e2 : void 0
1859
+ };
1860
+ })
1861
+ }
1862
+ }
1863
+ };
1864
+ }
1753
1865
  const { value: response, responseHeaders } = await (0, import_provider_utils13.postJsonToApi)({
1754
1866
  url: this.config.url({
1755
1867
  path: "/images/generations",
@@ -1761,7 +1873,7 @@ var OpenAIImageModel = class {
1761
1873
  prompt,
1762
1874
  n,
1763
1875
  size,
1764
- ...(_d = providerOptions.openai) != null ? _d : {},
1876
+ ...(_h = providerOptions.openai) != null ? _h : {},
1765
1877
  ...!hasDefaultResponseFormat.has(this.modelId) ? { response_format: "b64_json" } : {}
1766
1878
  },
1767
1879
  failedResponseHandler: openaiFailedResponseHandler,
@@ -1775,9 +1887,9 @@ var OpenAIImageModel = class {
1775
1887
  images: response.data.map((item) => item.b64_json),
1776
1888
  warnings,
1777
1889
  usage: response.usage != null ? {
1778
- inputTokens: (_e = response.usage.input_tokens) != null ? _e : void 0,
1779
- outputTokens: (_f = response.usage.output_tokens) != null ? _f : void 0,
1780
- totalTokens: (_g = response.usage.total_tokens) != null ? _g : void 0
1890
+ inputTokens: (_i = response.usage.input_tokens) != null ? _i : void 0,
1891
+ outputTokens: (_j = response.usage.output_tokens) != null ? _j : void 0,
1892
+ totalTokens: (_k = response.usage.total_tokens) != null ? _k : void 0
1781
1893
  } : void 0,
1782
1894
  response: {
1783
1895
  timestamp: currentDate,
@@ -1802,6 +1914,14 @@ var OpenAIImageModel = class {
1802
1914
  };
1803
1915
  }
1804
1916
  };
1917
+ async function fileToBlob(file) {
1918
+ if (!file) return void 0;
1919
+ if (file.type === "url") {
1920
+ return (0, import_provider_utils13.downloadBlob)(file.url);
1921
+ }
1922
+ const data = file.data instanceof Uint8Array ? file.data : (0, import_provider_utils13.convertBase64ToUint8Array)(file.data);
1923
+ return new Blob([data], { type: file.mediaType });
1924
+ }
1805
1925
 
1806
1926
  // src/tool/apply-patch.ts
1807
1927
  var import_provider_utils14 = require("@ai-sdk/provider-utils");
@@ -2163,16 +2283,14 @@ var mcpArgsSchema = (0, import_provider_utils22.lazySchema)(
2163
2283
  authorization: import_v417.z.string().optional(),
2164
2284
  connectorId: import_v417.z.string().optional(),
2165
2285
  headers: import_v417.z.record(import_v417.z.string(), import_v417.z.string()).optional(),
2166
- // TODO: Integrate this MCP tool approval with our SDK's existing tool approval architecture
2167
- // requireApproval: z
2168
- // .union([
2169
- // z.enum(['always', 'never']),
2170
- // z.object({
2171
- // readOnly: z.boolean().optional(),
2172
- // toolNames: z.array(z.string()).optional(),
2173
- // }),
2174
- // ])
2175
- // .optional(),
2286
+ requireApproval: import_v417.z.union([
2287
+ import_v417.z.enum(["always", "never"]),
2288
+ import_v417.z.object({
2289
+ never: import_v417.z.object({
2290
+ toolNames: import_v417.z.array(import_v417.z.string()).optional()
2291
+ }).optional()
2292
+ })
2293
+ ]).optional(),
2176
2294
  serverDescription: import_v417.z.string().optional(),
2177
2295
  serverUrl: import_v417.z.string().optional()
2178
2296
  }).refine(
@@ -2184,36 +2302,14 @@ var mcpArgsSchema = (0, import_provider_utils22.lazySchema)(
2184
2302
  var mcpInputSchema = (0, import_provider_utils22.lazySchema)(() => (0, import_provider_utils22.zodSchema)(import_v417.z.object({})));
2185
2303
  var mcpOutputSchema = (0, import_provider_utils22.lazySchema)(
2186
2304
  () => (0, import_provider_utils22.zodSchema)(
2187
- import_v417.z.discriminatedUnion("type", [
2188
- import_v417.z.object({
2189
- type: import_v417.z.literal("call"),
2190
- serverLabel: import_v417.z.string(),
2191
- name: import_v417.z.string(),
2192
- arguments: import_v417.z.string(),
2193
- output: import_v417.z.string().nullable().optional(),
2194
- error: import_v417.z.union([import_v417.z.string(), jsonValueSchema]).optional()
2195
- }),
2196
- import_v417.z.object({
2197
- type: import_v417.z.literal("listTools"),
2198
- serverLabel: import_v417.z.string(),
2199
- tools: import_v417.z.array(
2200
- import_v417.z.object({
2201
- name: import_v417.z.string(),
2202
- description: import_v417.z.string().optional(),
2203
- inputSchema: jsonValueSchema,
2204
- annotations: import_v417.z.record(import_v417.z.string(), jsonValueSchema).optional()
2205
- })
2206
- ),
2207
- error: import_v417.z.union([import_v417.z.string(), jsonValueSchema]).optional()
2208
- }),
2209
- import_v417.z.object({
2210
- type: import_v417.z.literal("approvalRequest"),
2211
- serverLabel: import_v417.z.string(),
2212
- name: import_v417.z.string(),
2213
- arguments: import_v417.z.string(),
2214
- approvalRequestId: import_v417.z.string()
2215
- })
2216
- ])
2305
+ import_v417.z.object({
2306
+ type: import_v417.z.literal("call"),
2307
+ serverLabel: import_v417.z.string(),
2308
+ name: import_v417.z.string(),
2309
+ arguments: import_v417.z.string(),
2310
+ output: import_v417.z.string().nullish(),
2311
+ error: import_v417.z.union([import_v417.z.string(), jsonValueSchema]).optional()
2312
+ })
2217
2313
  )
2218
2314
  );
2219
2315
  var mcpToolFactory = (0, import_provider_utils22.createProviderToolFactoryWithOutputSchema)({
@@ -2382,9 +2478,10 @@ async function convertToOpenAIResponsesInput({
2382
2478
  hasShellTool = false,
2383
2479
  hasApplyPatchTool = false
2384
2480
  }) {
2385
- var _a, _b, _c, _d, _e;
2481
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
2386
2482
  const input = [];
2387
2483
  const warnings = [];
2484
+ const processedApprovalIds = /* @__PURE__ */ new Set();
2388
2485
  for (const { role, content } of prompt) {
2389
2486
  switch (role) {
2390
2487
  case "system": {
@@ -2475,10 +2572,13 @@ async function convertToOpenAIResponsesInput({
2475
2572
  break;
2476
2573
  }
2477
2574
  case "tool-call": {
2575
+ const id = (_g = (_d = (_c = part.providerOptions) == null ? void 0 : _c.openai) == null ? void 0 : _d.itemId) != null ? _g : (_f = (_e = part.providerMetadata) == null ? void 0 : _e.openai) == null ? void 0 : _f.itemId;
2478
2576
  if (part.providerExecuted) {
2577
+ if (store && id != null) {
2578
+ input.push({ type: "item_reference", id });
2579
+ }
2479
2580
  break;
2480
2581
  }
2481
- const id = (_d = (_c = part.providerOptions) == null ? void 0 : _c.openai) == null ? void 0 : _d.itemId;
2482
2582
  if (store && id != null) {
2483
2583
  input.push({ type: "item_reference", id });
2484
2584
  break;
@@ -2535,8 +2635,12 @@ async function convertToOpenAIResponsesInput({
2535
2635
  }
2536
2636
  // assistant tool result parts are from provider-executed tools:
2537
2637
  case "tool-result": {
2638
+ if (part.output.type === "execution-denied" || part.output.type === "json" && typeof part.output.value === "object" && part.output.value != null && "type" in part.output.value && part.output.value.type === "execution-denied") {
2639
+ break;
2640
+ }
2538
2641
  if (store) {
2539
- input.push({ type: "item_reference", id: part.toolCallId });
2642
+ const itemId = (_j = (_i = (_h = part.providerMetadata) == null ? void 0 : _h.openai) == null ? void 0 : _i.itemId) != null ? _j : part.toolCallId;
2643
+ input.push({ type: "item_reference", id: itemId });
2540
2644
  } else {
2541
2645
  warnings.push({
2542
2646
  type: "other",
@@ -2605,7 +2709,32 @@ async function convertToOpenAIResponsesInput({
2605
2709
  }
2606
2710
  case "tool": {
2607
2711
  for (const part of content) {
2712
+ if (part.type === "tool-approval-response") {
2713
+ const approvalResponse = part;
2714
+ if (processedApprovalIds.has(approvalResponse.approvalId)) {
2715
+ continue;
2716
+ }
2717
+ processedApprovalIds.add(approvalResponse.approvalId);
2718
+ if (store) {
2719
+ input.push({
2720
+ type: "item_reference",
2721
+ id: approvalResponse.approvalId
2722
+ });
2723
+ }
2724
+ input.push({
2725
+ type: "mcp_approval_response",
2726
+ approval_request_id: approvalResponse.approvalId,
2727
+ approve: approvalResponse.approved
2728
+ });
2729
+ continue;
2730
+ }
2608
2731
  const output = part.output;
2732
+ if (output.type === "execution-denied") {
2733
+ const approvalId = (_l = (_k = output.providerOptions) == null ? void 0 : _k.openai) == null ? void 0 : _l.approvalId;
2734
+ if (approvalId) {
2735
+ continue;
2736
+ }
2737
+ }
2609
2738
  const resolvedToolName = toolNameMapping.toProviderToolName(
2610
2739
  part.toolName
2611
2740
  );
@@ -2619,7 +2748,7 @@ async function convertToOpenAIResponsesInput({
2619
2748
  call_id: part.toolCallId,
2620
2749
  output: parsedOutput.output
2621
2750
  });
2622
- break;
2751
+ continue;
2623
2752
  }
2624
2753
  if (hasShellTool && resolvedToolName === "shell" && output.type === "json") {
2625
2754
  const parsedOutput = await (0, import_provider_utils23.validateTypes)({
@@ -2638,7 +2767,7 @@ async function convertToOpenAIResponsesInput({
2638
2767
  }
2639
2768
  }))
2640
2769
  });
2641
- break;
2770
+ continue;
2642
2771
  }
2643
2772
  if (hasApplyPatchTool && part.toolName === "apply_patch" && output.type === "json") {
2644
2773
  const parsedOutput = await (0, import_provider_utils23.validateTypes)({
@@ -2651,7 +2780,7 @@ async function convertToOpenAIResponsesInput({
2651
2780
  status: parsedOutput.status,
2652
2781
  output: parsedOutput.output
2653
2782
  });
2654
- break;
2783
+ continue;
2655
2784
  }
2656
2785
  let contentValue;
2657
2786
  switch (output.type) {
@@ -2660,7 +2789,7 @@ async function convertToOpenAIResponsesInput({
2660
2789
  contentValue = output.value;
2661
2790
  break;
2662
2791
  case "execution-denied":
2663
- contentValue = (_e = output.reason) != null ? _e : "Tool execution denied.";
2792
+ contentValue = (_m = output.reason) != null ? _m : "Tool execution denied.";
2664
2793
  break;
2665
2794
  case "json":
2666
2795
  case "error-json":
@@ -2732,7 +2861,7 @@ function mapOpenAIResponseFinishReason({
2732
2861
  case "content_filter":
2733
2862
  return "content-filter";
2734
2863
  default:
2735
- return hasFunctionCall ? "tool-calls" : "unknown";
2864
+ return hasFunctionCall ? "tool-calls" : "other";
2736
2865
  }
2737
2866
  }
2738
2867
 
@@ -2835,7 +2964,8 @@ var openaiResponsesChunkSchema = (0, import_provider_utils24.lazySchema)(
2835
2964
  import_v419.z.object({
2836
2965
  type: import_v419.z.literal("mcp_call"),
2837
2966
  id: import_v419.z.string(),
2838
- status: import_v419.z.string()
2967
+ status: import_v419.z.string(),
2968
+ approval_request_id: import_v419.z.string().nullish()
2839
2969
  }),
2840
2970
  import_v419.z.object({
2841
2971
  type: import_v419.z.literal("mcp_list_tools"),
@@ -2992,7 +3122,8 @@ var openaiResponsesChunkSchema = (0, import_provider_utils24.lazySchema)(
2992
3122
  code: import_v419.z.union([import_v419.z.number(), import_v419.z.string()]).optional(),
2993
3123
  message: import_v419.z.string().optional()
2994
3124
  }).loose()
2995
- ]).nullish()
3125
+ ]).nullish(),
3126
+ approval_request_id: import_v419.z.string().nullish()
2996
3127
  }),
2997
3128
  import_v419.z.object({
2998
3129
  type: import_v419.z.literal("mcp_list_tools"),
@@ -3021,7 +3152,7 @@ var openaiResponsesChunkSchema = (0, import_provider_utils24.lazySchema)(
3021
3152
  server_label: import_v419.z.string(),
3022
3153
  name: import_v419.z.string(),
3023
3154
  arguments: import_v419.z.string(),
3024
- approval_request_id: import_v419.z.string()
3155
+ approval_request_id: import_v419.z.string().optional()
3025
3156
  }),
3026
3157
  import_v419.z.object({
3027
3158
  type: import_v419.z.literal("apply_patch_call"),
@@ -3131,6 +3262,19 @@ var openaiResponsesChunkSchema = (0, import_provider_utils24.lazySchema)(
3131
3262
  item_id: import_v419.z.string(),
3132
3263
  summary_index: import_v419.z.number()
3133
3264
  }),
3265
+ import_v419.z.object({
3266
+ type: import_v419.z.literal("response.apply_patch_call_operation_diff.delta"),
3267
+ item_id: import_v419.z.string(),
3268
+ output_index: import_v419.z.number(),
3269
+ delta: import_v419.z.string(),
3270
+ obfuscation: import_v419.z.string().nullish()
3271
+ }),
3272
+ import_v419.z.object({
3273
+ type: import_v419.z.literal("response.apply_patch_call_operation_diff.done"),
3274
+ item_id: import_v419.z.string(),
3275
+ output_index: import_v419.z.number(),
3276
+ diff: import_v419.z.string()
3277
+ }),
3134
3278
  import_v419.z.object({
3135
3279
  type: import_v419.z.literal("error"),
3136
3280
  sequence_number: import_v419.z.number(),
@@ -3331,7 +3475,8 @@ var openaiResponsesResponseSchema = (0, import_provider_utils24.lazySchema)(
3331
3475
  code: import_v419.z.union([import_v419.z.number(), import_v419.z.string()]).optional(),
3332
3476
  message: import_v419.z.string().optional()
3333
3477
  }).loose()
3334
- ]).nullish()
3478
+ ]).nullish(),
3479
+ approval_request_id: import_v419.z.string().nullish()
3335
3480
  }),
3336
3481
  import_v419.z.object({
3337
3482
  type: import_v419.z.literal("mcp_list_tools"),
@@ -3360,7 +3505,7 @@ var openaiResponsesResponseSchema = (0, import_provider_utils24.lazySchema)(
3360
3505
  server_label: import_v419.z.string(),
3361
3506
  name: import_v419.z.string(),
3362
3507
  arguments: import_v419.z.string(),
3363
- approval_request_id: import_v419.z.string()
3508
+ approval_request_id: import_v419.z.string().optional()
3364
3509
  }),
3365
3510
  import_v419.z.object({
3366
3511
  type: import_v419.z.literal("apply_patch_call"),
@@ -3611,7 +3756,26 @@ var openaiResponsesProviderOptionsSchema = (0, import_provider_utils25.lazySchem
3611
3756
  * Defaults to `undefined`.
3612
3757
  * @see https://platform.openai.com/docs/guides/safety-best-practices/end-user-ids
3613
3758
  */
3614
- user: import_v420.z.string().nullish()
3759
+ user: import_v420.z.string().nullish(),
3760
+ /**
3761
+ * Override the system message mode for this model.
3762
+ * - 'system': Use the 'system' role for system messages (default for most models)
3763
+ * - 'developer': Use the 'developer' role for system messages (used by reasoning models)
3764
+ * - 'remove': Remove system messages entirely
3765
+ *
3766
+ * If not specified, the mode is automatically determined based on the model.
3767
+ */
3768
+ systemMessageMode: import_v420.z.enum(["system", "developer", "remove"]).optional(),
3769
+ /**
3770
+ * Force treating this model as a reasoning model.
3771
+ *
3772
+ * This is useful for "stealth" reasoning models (e.g. via a custom baseURL)
3773
+ * where the model ID is not recognized by the SDK's allowlist.
3774
+ *
3775
+ * When enabled, the SDK applies reasoning-model parameter compatibility rules
3776
+ * and defaults `systemMessageMode` to `developer` unless overridden.
3777
+ */
3778
+ forceReasoning: import_v420.z.boolean().optional()
3615
3779
  })
3616
3780
  )
3617
3781
  );
@@ -3742,6 +3906,11 @@ async function prepareResponsesTools({
3742
3906
  value: tool.args,
3743
3907
  schema: mcpArgsSchema
3744
3908
  });
3909
+ const mapApprovalFilter = (filter) => ({
3910
+ tool_names: filter.toolNames
3911
+ });
3912
+ const requireApproval = args.requireApproval;
3913
+ const requireApprovalParam = requireApproval == null ? void 0 : typeof requireApproval === "string" ? requireApproval : requireApproval.never != null ? { never: mapApprovalFilter(requireApproval.never) } : void 0;
3745
3914
  openaiTools2.push({
3746
3915
  type: "mcp",
3747
3916
  server_label: args.serverLabel,
@@ -3752,7 +3921,7 @@ async function prepareResponsesTools({
3752
3921
  authorization: args.authorization,
3753
3922
  connector_id: args.connectorId,
3754
3923
  headers: args.headers,
3755
- require_approval: "never",
3924
+ require_approval: requireApprovalParam != null ? requireApprovalParam : "never",
3756
3925
  server_description: args.serverDescription,
3757
3926
  server_url: args.serverUrl
3758
3927
  });
@@ -3794,6 +3963,21 @@ async function prepareResponsesTools({
3794
3963
  }
3795
3964
 
3796
3965
  // src/responses/openai-responses-language-model.ts
3966
+ function extractApprovalRequestIdToToolCallIdMapping(prompt) {
3967
+ var _a, _b;
3968
+ const mapping = {};
3969
+ for (const message of prompt) {
3970
+ if (message.role !== "assistant") continue;
3971
+ for (const part of message.content) {
3972
+ if (part.type !== "tool-call") continue;
3973
+ const approvalRequestId = (_b = (_a = part.providerOptions) == null ? void 0 : _a.openai) == null ? void 0 : _b.approvalRequestId;
3974
+ if (approvalRequestId != null) {
3975
+ mapping[approvalRequestId] = part.toolCallId;
3976
+ }
3977
+ }
3978
+ }
3979
+ return mapping;
3980
+ }
3797
3981
  var OpenAIResponsesLanguageModel = class {
3798
3982
  constructor(modelId, config) {
3799
3983
  this.specificationVersion = "v3";
@@ -3822,7 +4006,7 @@ var OpenAIResponsesLanguageModel = class {
3822
4006
  toolChoice,
3823
4007
  responseFormat
3824
4008
  }) {
3825
- var _a, _b, _c, _d;
4009
+ var _a, _b, _c, _d, _e, _f;
3826
4010
  const warnings = [];
3827
4011
  const modelCapabilities = getOpenAILanguageModelCapabilities(this.modelId);
3828
4012
  if (topK != null) {
@@ -3845,6 +4029,7 @@ var OpenAIResponsesLanguageModel = class {
3845
4029
  providerOptions,
3846
4030
  schema: openaiResponsesProviderOptionsSchema
3847
4031
  });
4032
+ const isReasoningModel = (_a = openaiOptions == null ? void 0 : openaiOptions.forceReasoning) != null ? _a : modelCapabilities.isReasoningModel;
3848
4033
  if ((openaiOptions == null ? void 0 : openaiOptions.conversation) && (openaiOptions == null ? void 0 : openaiOptions.previousResponseId)) {
3849
4034
  warnings.push({
3850
4035
  type: "unsupported",
@@ -3869,15 +4054,15 @@ var OpenAIResponsesLanguageModel = class {
3869
4054
  const { input, warnings: inputWarnings } = await convertToOpenAIResponsesInput({
3870
4055
  prompt,
3871
4056
  toolNameMapping,
3872
- systemMessageMode: modelCapabilities.systemMessageMode,
4057
+ systemMessageMode: (_b = openaiOptions == null ? void 0 : openaiOptions.systemMessageMode) != null ? _b : isReasoningModel ? "developer" : modelCapabilities.systemMessageMode,
3873
4058
  fileIdPrefixes: this.config.fileIdPrefixes,
3874
- store: (_a = openaiOptions == null ? void 0 : openaiOptions.store) != null ? _a : true,
4059
+ store: (_c = openaiOptions == null ? void 0 : openaiOptions.store) != null ? _c : true,
3875
4060
  hasLocalShellTool: hasOpenAITool("openai.local_shell"),
3876
4061
  hasShellTool: hasOpenAITool("openai.shell"),
3877
4062
  hasApplyPatchTool: hasOpenAITool("openai.apply_patch")
3878
4063
  });
3879
4064
  warnings.push(...inputWarnings);
3880
- const strictJsonSchema = (_b = openaiOptions == null ? void 0 : openaiOptions.strictJsonSchema) != null ? _b : true;
4065
+ const strictJsonSchema = (_d = openaiOptions == null ? void 0 : openaiOptions.strictJsonSchema) != null ? _d : true;
3881
4066
  let include = openaiOptions == null ? void 0 : openaiOptions.include;
3882
4067
  function addInclude(key) {
3883
4068
  if (include == null) {
@@ -3893,9 +4078,9 @@ var OpenAIResponsesLanguageModel = class {
3893
4078
  if (topLogprobs) {
3894
4079
  addInclude("message.output_text.logprobs");
3895
4080
  }
3896
- const webSearchToolName = (_c = tools == null ? void 0 : tools.find(
4081
+ const webSearchToolName = (_e = tools == null ? void 0 : tools.find(
3897
4082
  (tool) => tool.type === "provider" && (tool.id === "openai.web_search" || tool.id === "openai.web_search_preview")
3898
- )) == null ? void 0 : _c.name;
4083
+ )) == null ? void 0 : _e.name;
3899
4084
  if (webSearchToolName) {
3900
4085
  addInclude("web_search_call.action.sources");
3901
4086
  }
@@ -3903,7 +4088,7 @@ var OpenAIResponsesLanguageModel = class {
3903
4088
  addInclude("code_interpreter_call.outputs");
3904
4089
  }
3905
4090
  const store = openaiOptions == null ? void 0 : openaiOptions.store;
3906
- if (store === false && modelCapabilities.isReasoningModel) {
4091
+ if (store === false && isReasoningModel) {
3907
4092
  addInclude("reasoning.encrypted_content");
3908
4093
  }
3909
4094
  const baseArgs = {
@@ -3918,7 +4103,7 @@ var OpenAIResponsesLanguageModel = class {
3918
4103
  format: responseFormat.schema != null ? {
3919
4104
  type: "json_schema",
3920
4105
  strict: strictJsonSchema,
3921
- name: (_d = responseFormat.name) != null ? _d : "response",
4106
+ name: (_f = responseFormat.name) != null ? _f : "response",
3922
4107
  description: responseFormat.description,
3923
4108
  schema: responseFormat.schema
3924
4109
  } : { type: "json_object" }
@@ -3945,7 +4130,7 @@ var OpenAIResponsesLanguageModel = class {
3945
4130
  top_logprobs: topLogprobs,
3946
4131
  truncation: openaiOptions == null ? void 0 : openaiOptions.truncation,
3947
4132
  // model-specific settings:
3948
- ...modelCapabilities.isReasoningModel && ((openaiOptions == null ? void 0 : openaiOptions.reasoningEffort) != null || (openaiOptions == null ? void 0 : openaiOptions.reasoningSummary) != null) && {
4133
+ ...isReasoningModel && ((openaiOptions == null ? void 0 : openaiOptions.reasoningEffort) != null || (openaiOptions == null ? void 0 : openaiOptions.reasoningSummary) != null) && {
3949
4134
  reasoning: {
3950
4135
  ...(openaiOptions == null ? void 0 : openaiOptions.reasoningEffort) != null && {
3951
4136
  effort: openaiOptions.reasoningEffort
@@ -3956,7 +4141,7 @@ var OpenAIResponsesLanguageModel = class {
3956
4141
  }
3957
4142
  }
3958
4143
  };
3959
- if (modelCapabilities.isReasoningModel) {
4144
+ if (isReasoningModel) {
3960
4145
  if (!((openaiOptions == null ? void 0 : openaiOptions.reasoningEffort) === "none" && modelCapabilities.supportsNonReasoningParameters)) {
3961
4146
  if (baseArgs.temperature != null) {
3962
4147
  baseArgs.temperature = void 0;
@@ -4028,7 +4213,7 @@ var OpenAIResponsesLanguageModel = class {
4028
4213
  };
4029
4214
  }
4030
4215
  async doGenerate(options) {
4031
- 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;
4216
+ 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;
4032
4217
  const {
4033
4218
  args: body,
4034
4219
  warnings,
@@ -4040,6 +4225,7 @@ var OpenAIResponsesLanguageModel = class {
4040
4225
  modelId: this.modelId
4041
4226
  });
4042
4227
  const providerKey = this.config.provider.replace(".responses", "");
4228
+ const approvalRequestIdToDummyToolCallIdFromPrompt = extractApprovalRequestIdToToolCallIdMapping(options.prompt);
4043
4229
  const {
4044
4230
  responseHeaders,
4045
4231
  value: response,
@@ -4256,17 +4442,20 @@ var OpenAIResponsesLanguageModel = class {
4256
4442
  break;
4257
4443
  }
4258
4444
  case "mcp_call": {
4445
+ const toolCallId = part.approval_request_id != null ? (_v = approvalRequestIdToDummyToolCallIdFromPrompt[part.approval_request_id]) != null ? _v : part.id : part.id;
4446
+ const toolName = `mcp.${part.name}`;
4259
4447
  content.push({
4260
4448
  type: "tool-call",
4261
- toolCallId: part.id,
4262
- toolName: toolNameMapping.toCustomToolName("mcp"),
4263
- input: JSON.stringify({}),
4264
- providerExecuted: true
4449
+ toolCallId,
4450
+ toolName,
4451
+ input: part.arguments,
4452
+ providerExecuted: true,
4453
+ dynamic: true
4265
4454
  });
4266
4455
  content.push({
4267
4456
  type: "tool-result",
4268
- toolCallId: part.id,
4269
- toolName: toolNameMapping.toCustomToolName("mcp"),
4457
+ toolCallId,
4458
+ toolName,
4270
4459
  result: {
4271
4460
  type: "call",
4272
4461
  serverLabel: part.server_label,
@@ -4274,58 +4463,34 @@ var OpenAIResponsesLanguageModel = class {
4274
4463
  arguments: part.arguments,
4275
4464
  ...part.output != null ? { output: part.output } : {},
4276
4465
  ...part.error != null ? { error: part.error } : {}
4466
+ },
4467
+ providerMetadata: {
4468
+ [providerKey]: {
4469
+ itemId: part.id
4470
+ }
4277
4471
  }
4278
4472
  });
4279
4473
  break;
4280
4474
  }
4281
4475
  case "mcp_list_tools": {
4282
- content.push({
4283
- type: "tool-call",
4284
- toolCallId: part.id,
4285
- toolName: toolNameMapping.toCustomToolName("mcp"),
4286
- input: JSON.stringify({}),
4287
- providerExecuted: true
4288
- });
4289
- content.push({
4290
- type: "tool-result",
4291
- toolCallId: part.id,
4292
- toolName: toolNameMapping.toCustomToolName("mcp"),
4293
- result: {
4294
- type: "listTools",
4295
- serverLabel: part.server_label,
4296
- tools: part.tools.map((t) => {
4297
- var _a2, _b2;
4298
- return {
4299
- name: t.name,
4300
- description: (_a2 = t.description) != null ? _a2 : void 0,
4301
- inputSchema: t.input_schema,
4302
- annotations: (_b2 = t.annotations) != null ? _b2 : void 0
4303
- };
4304
- }),
4305
- ...part.error != null ? { error: part.error } : {}
4306
- }
4307
- });
4308
4476
  break;
4309
4477
  }
4310
4478
  case "mcp_approval_request": {
4479
+ const approvalRequestId = (_w = part.approval_request_id) != null ? _w : part.id;
4480
+ const dummyToolCallId = (_z = (_y = (_x = this.config).generateId) == null ? void 0 : _y.call(_x)) != null ? _z : (0, import_provider_utils27.generateId)();
4481
+ const toolName = `mcp.${part.name}`;
4311
4482
  content.push({
4312
4483
  type: "tool-call",
4313
- toolCallId: part.id,
4314
- toolName: toolNameMapping.toCustomToolName("mcp"),
4315
- input: JSON.stringify({}),
4316
- providerExecuted: true
4484
+ toolCallId: dummyToolCallId,
4485
+ toolName,
4486
+ input: part.arguments,
4487
+ providerExecuted: true,
4488
+ dynamic: true
4317
4489
  });
4318
4490
  content.push({
4319
- type: "tool-result",
4320
- toolCallId: part.id,
4321
- toolName: toolNameMapping.toCustomToolName("mcp"),
4322
- result: {
4323
- type: "approvalRequest",
4324
- serverLabel: part.server_label,
4325
- name: part.name,
4326
- arguments: part.arguments,
4327
- approvalRequestId: part.approval_request_id
4328
- }
4491
+ type: "tool-approval-request",
4492
+ approvalId: approvalRequestId,
4493
+ toolCallId: dummyToolCallId
4329
4494
  });
4330
4495
  break;
4331
4496
  }
@@ -4362,13 +4527,13 @@ var OpenAIResponsesLanguageModel = class {
4362
4527
  toolName: toolNameMapping.toCustomToolName("file_search"),
4363
4528
  result: {
4364
4529
  queries: part.queries,
4365
- results: (_w = (_v = part.results) == null ? void 0 : _v.map((result) => ({
4530
+ results: (_B = (_A = part.results) == null ? void 0 : _A.map((result) => ({
4366
4531
  attributes: result.attributes,
4367
4532
  fileId: result.file_id,
4368
4533
  filename: result.filename,
4369
4534
  score: result.score,
4370
4535
  text: result.text
4371
- }))) != null ? _w : null
4536
+ }))) != null ? _B : null
4372
4537
  }
4373
4538
  });
4374
4539
  break;
@@ -4425,10 +4590,13 @@ var OpenAIResponsesLanguageModel = class {
4425
4590
  const usage = response.usage;
4426
4591
  return {
4427
4592
  content,
4428
- finishReason: mapOpenAIResponseFinishReason({
4429
- finishReason: (_x = response.incomplete_details) == null ? void 0 : _x.reason,
4430
- hasFunctionCall
4431
- }),
4593
+ finishReason: {
4594
+ unified: mapOpenAIResponseFinishReason({
4595
+ finishReason: (_C = response.incomplete_details) == null ? void 0 : _C.reason,
4596
+ hasFunctionCall
4597
+ }),
4598
+ raw: (_E = (_D = response.incomplete_details) == null ? void 0 : _D.reason) != null ? _E : void 0
4599
+ },
4432
4600
  usage: convertOpenAIResponsesUsage(usage),
4433
4601
  request: { body },
4434
4602
  response: {
@@ -4469,7 +4637,12 @@ var OpenAIResponsesLanguageModel = class {
4469
4637
  });
4470
4638
  const self = this;
4471
4639
  const providerKey = this.config.provider.replace(".responses", "");
4472
- let finishReason = "unknown";
4640
+ const approvalRequestIdToDummyToolCallIdFromPrompt = extractApprovalRequestIdToToolCallIdMapping(options.prompt);
4641
+ const approvalRequestIdToDummyToolCallIdFromStream = /* @__PURE__ */ new Map();
4642
+ let finishReason = {
4643
+ unified: "other",
4644
+ raw: void 0
4645
+ };
4473
4646
  let usage = void 0;
4474
4647
  const logprobs = [];
4475
4648
  let responseId = null;
@@ -4485,12 +4658,12 @@ var OpenAIResponsesLanguageModel = class {
4485
4658
  controller.enqueue({ type: "stream-start", warnings });
4486
4659
  },
4487
4660
  transform(chunk, controller) {
4488
- 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;
4661
+ 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;
4489
4662
  if (options.includeRawChunks) {
4490
4663
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
4491
4664
  }
4492
4665
  if (!chunk.success) {
4493
- finishReason = "error";
4666
+ finishReason = { unified: "error", raw: void 0 };
4494
4667
  controller.enqueue({ type: "error", error: chunk.error });
4495
4668
  return;
4496
4669
  }
@@ -4581,32 +4754,41 @@ var OpenAIResponsesLanguageModel = class {
4581
4754
  providerExecuted: true
4582
4755
  });
4583
4756
  } else if (value.item.type === "mcp_call" || value.item.type === "mcp_list_tools" || value.item.type === "mcp_approval_request") {
4584
- controller.enqueue({
4585
- type: "tool-call",
4586
- toolCallId: value.item.id,
4587
- toolName: toolNameMapping.toCustomToolName("mcp"),
4588
- input: "{}",
4589
- providerExecuted: true
4590
- });
4591
4757
  } else if (value.item.type === "apply_patch_call") {
4758
+ const { call_id: callId, operation } = value.item;
4592
4759
  ongoingToolCalls[value.output_index] = {
4593
4760
  toolName: toolNameMapping.toCustomToolName("apply_patch"),
4594
- toolCallId: value.item.call_id
4761
+ toolCallId: callId,
4762
+ applyPatch: {
4763
+ // delete_file doesn't have diff
4764
+ hasDiff: operation.type === "delete_file",
4765
+ endEmitted: operation.type === "delete_file"
4766
+ }
4595
4767
  };
4596
- if (value.item.status === "completed") {
4768
+ controller.enqueue({
4769
+ type: "tool-input-start",
4770
+ id: callId,
4771
+ toolName: toolNameMapping.toCustomToolName("apply_patch")
4772
+ });
4773
+ if (operation.type === "delete_file") {
4774
+ const inputString = JSON.stringify({
4775
+ callId,
4776
+ operation
4777
+ });
4597
4778
  controller.enqueue({
4598
- type: "tool-call",
4599
- toolCallId: value.item.call_id,
4600
- toolName: toolNameMapping.toCustomToolName("apply_patch"),
4601
- input: JSON.stringify({
4602
- callId: value.item.call_id,
4603
- operation: value.item.operation
4604
- }),
4605
- providerMetadata: {
4606
- [providerKey]: {
4607
- itemId: value.item.id
4608
- }
4609
- }
4779
+ type: "tool-input-delta",
4780
+ id: callId,
4781
+ delta: inputString
4782
+ });
4783
+ controller.enqueue({
4784
+ type: "tool-input-end",
4785
+ id: callId
4786
+ });
4787
+ } else {
4788
+ controller.enqueue({
4789
+ type: "tool-input-delta",
4790
+ id: callId,
4791
+ delta: `{"callId":"${escapeJSONDelta(callId)}","operation":{"type":"${escapeJSONDelta(operation.type)}","path":"${escapeJSONDelta(operation.path)}","diff":"`
4610
4792
  });
4611
4793
  }
4612
4794
  } else if (value.item.type === "shell_call") {
@@ -4743,10 +4925,23 @@ var OpenAIResponsesLanguageModel = class {
4743
4925
  });
4744
4926
  } else if (value.item.type === "mcp_call") {
4745
4927
  ongoingToolCalls[value.output_index] = void 0;
4928
+ const approvalRequestId = (_d = value.item.approval_request_id) != null ? _d : void 0;
4929
+ const aliasedToolCallId = approvalRequestId != null ? (_f = (_e = approvalRequestIdToDummyToolCallIdFromStream.get(
4930
+ approvalRequestId
4931
+ )) != null ? _e : approvalRequestIdToDummyToolCallIdFromPrompt[approvalRequestId]) != null ? _f : value.item.id : value.item.id;
4932
+ const toolName = `mcp.${value.item.name}`;
4933
+ controller.enqueue({
4934
+ type: "tool-call",
4935
+ toolCallId: aliasedToolCallId,
4936
+ toolName,
4937
+ input: value.item.arguments,
4938
+ providerExecuted: true,
4939
+ dynamic: true
4940
+ });
4746
4941
  controller.enqueue({
4747
4942
  type: "tool-result",
4748
- toolCallId: value.item.id,
4749
- toolName: toolNameMapping.toCustomToolName("mcp"),
4943
+ toolCallId: aliasedToolCallId,
4944
+ toolName,
4750
4945
  result: {
4751
4946
  type: "call",
4752
4947
  serverLabel: value.item.server_label,
@@ -4754,35 +4949,40 @@ var OpenAIResponsesLanguageModel = class {
4754
4949
  arguments: value.item.arguments,
4755
4950
  ...value.item.output != null ? { output: value.item.output } : {},
4756
4951
  ...value.item.error != null ? { error: value.item.error } : {}
4952
+ },
4953
+ providerMetadata: {
4954
+ [providerKey]: {
4955
+ itemId: value.item.id
4956
+ }
4757
4957
  }
4758
4958
  });
4759
4959
  } else if (value.item.type === "mcp_list_tools") {
4760
4960
  ongoingToolCalls[value.output_index] = void 0;
4761
- controller.enqueue({
4762
- type: "tool-result",
4763
- toolCallId: value.item.id,
4764
- toolName: toolNameMapping.toCustomToolName("mcp"),
4765
- result: {
4766
- type: "listTools",
4767
- serverLabel: value.item.server_label,
4768
- tools: value.item.tools.map((t) => {
4769
- var _a2, _b2;
4770
- return {
4771
- name: t.name,
4772
- description: (_a2 = t.description) != null ? _a2 : void 0,
4773
- inputSchema: t.input_schema,
4774
- annotations: (_b2 = t.annotations) != null ? _b2 : void 0
4775
- };
4776
- }),
4777
- ...value.item.error != null ? { error: value.item.error } : {}
4778
- }
4779
- });
4780
4961
  } else if (value.item.type === "apply_patch_call") {
4781
- ongoingToolCalls[value.output_index] = void 0;
4782
- if (value.item.status === "completed") {
4962
+ const toolCall = ongoingToolCalls[value.output_index];
4963
+ if ((toolCall == null ? void 0 : toolCall.applyPatch) && !toolCall.applyPatch.endEmitted && value.item.operation.type !== "delete_file") {
4964
+ if (!toolCall.applyPatch.hasDiff) {
4965
+ controller.enqueue({
4966
+ type: "tool-input-delta",
4967
+ id: toolCall.toolCallId,
4968
+ delta: escapeJSONDelta(value.item.operation.diff)
4969
+ });
4970
+ }
4971
+ controller.enqueue({
4972
+ type: "tool-input-delta",
4973
+ id: toolCall.toolCallId,
4974
+ delta: '"}}'
4975
+ });
4976
+ controller.enqueue({
4977
+ type: "tool-input-end",
4978
+ id: toolCall.toolCallId
4979
+ });
4980
+ toolCall.applyPatch.endEmitted = true;
4981
+ }
4982
+ if (toolCall && value.item.status === "completed") {
4783
4983
  controller.enqueue({
4784
4984
  type: "tool-call",
4785
- toolCallId: value.item.call_id,
4985
+ toolCallId: toolCall.toolCallId,
4786
4986
  toolName: toolNameMapping.toCustomToolName("apply_patch"),
4787
4987
  input: JSON.stringify({
4788
4988
  callId: value.item.call_id,
@@ -4795,19 +4995,28 @@ var OpenAIResponsesLanguageModel = class {
4795
4995
  }
4796
4996
  });
4797
4997
  }
4998
+ ongoingToolCalls[value.output_index] = void 0;
4798
4999
  } else if (value.item.type === "mcp_approval_request") {
4799
5000
  ongoingToolCalls[value.output_index] = void 0;
5001
+ const dummyToolCallId = (_i = (_h = (_g = self.config).generateId) == null ? void 0 : _h.call(_g)) != null ? _i : (0, import_provider_utils27.generateId)();
5002
+ const approvalRequestId = (_j = value.item.approval_request_id) != null ? _j : value.item.id;
5003
+ approvalRequestIdToDummyToolCallIdFromStream.set(
5004
+ approvalRequestId,
5005
+ dummyToolCallId
5006
+ );
5007
+ const toolName = `mcp.${value.item.name}`;
4800
5008
  controller.enqueue({
4801
- type: "tool-result",
4802
- toolCallId: value.item.id,
4803
- toolName: toolNameMapping.toCustomToolName("mcp"),
4804
- result: {
4805
- type: "approvalRequest",
4806
- serverLabel: value.item.server_label,
4807
- name: value.item.name,
4808
- arguments: value.item.arguments,
4809
- approvalRequestId: value.item.approval_request_id
4810
- }
5009
+ type: "tool-call",
5010
+ toolCallId: dummyToolCallId,
5011
+ toolName,
5012
+ input: value.item.arguments,
5013
+ providerExecuted: true,
5014
+ dynamic: true
5015
+ });
5016
+ controller.enqueue({
5017
+ type: "tool-approval-request",
5018
+ approvalId: approvalRequestId,
5019
+ toolCallId: dummyToolCallId
4811
5020
  });
4812
5021
  } else if (value.item.type === "local_shell_call") {
4813
5022
  ongoingToolCalls[value.output_index] = void 0;
@@ -4858,7 +5067,7 @@ var OpenAIResponsesLanguageModel = class {
4858
5067
  providerMetadata: {
4859
5068
  [providerKey]: {
4860
5069
  itemId: value.item.id,
4861
- reasoningEncryptedContent: (_d = value.item.encrypted_content) != null ? _d : null
5070
+ reasoningEncryptedContent: (_k = value.item.encrypted_content) != null ? _k : null
4862
5071
  }
4863
5072
  }
4864
5073
  });
@@ -4874,6 +5083,38 @@ var OpenAIResponsesLanguageModel = class {
4874
5083
  delta: value.delta
4875
5084
  });
4876
5085
  }
5086
+ } else if (isResponseApplyPatchCallOperationDiffDeltaChunk(value)) {
5087
+ const toolCall = ongoingToolCalls[value.output_index];
5088
+ if (toolCall == null ? void 0 : toolCall.applyPatch) {
5089
+ controller.enqueue({
5090
+ type: "tool-input-delta",
5091
+ id: toolCall.toolCallId,
5092
+ delta: escapeJSONDelta(value.delta)
5093
+ });
5094
+ toolCall.applyPatch.hasDiff = true;
5095
+ }
5096
+ } else if (isResponseApplyPatchCallOperationDiffDoneChunk(value)) {
5097
+ const toolCall = ongoingToolCalls[value.output_index];
5098
+ if ((toolCall == null ? void 0 : toolCall.applyPatch) && !toolCall.applyPatch.endEmitted) {
5099
+ if (!toolCall.applyPatch.hasDiff) {
5100
+ controller.enqueue({
5101
+ type: "tool-input-delta",
5102
+ id: toolCall.toolCallId,
5103
+ delta: escapeJSONDelta(value.diff)
5104
+ });
5105
+ toolCall.applyPatch.hasDiff = true;
5106
+ }
5107
+ controller.enqueue({
5108
+ type: "tool-input-delta",
5109
+ id: toolCall.toolCallId,
5110
+ delta: '"}}'
5111
+ });
5112
+ controller.enqueue({
5113
+ type: "tool-input-end",
5114
+ id: toolCall.toolCallId
5115
+ });
5116
+ toolCall.applyPatch.endEmitted = true;
5117
+ }
4877
5118
  } else if (isResponseImageGenerationCallPartialImageChunk(value)) {
4878
5119
  controller.enqueue({
4879
5120
  type: "tool-result",
@@ -4890,9 +5131,7 @@ var OpenAIResponsesLanguageModel = class {
4890
5131
  controller.enqueue({
4891
5132
  type: "tool-input-delta",
4892
5133
  id: toolCall.toolCallId,
4893
- // The delta is code, which is embedding in a JSON string.
4894
- // To escape it, we use JSON.stringify and slice to remove the outer quotes.
4895
- delta: JSON.stringify(value.delta).slice(1, -1)
5134
+ delta: escapeJSONDelta(value.delta)
4896
5135
  });
4897
5136
  }
4898
5137
  } else if (isResponseCodeInterpreterCallCodeDoneChunk(value)) {
@@ -4932,7 +5171,7 @@ var OpenAIResponsesLanguageModel = class {
4932
5171
  id: value.item_id,
4933
5172
  delta: value.delta
4934
5173
  });
4935
- if (((_f = (_e = options.providerOptions) == null ? void 0 : _e.openai) == null ? void 0 : _f.logprobs) && value.logprobs) {
5174
+ if (((_m = (_l = options.providerOptions) == null ? void 0 : _l.openai) == null ? void 0 : _m.logprobs) && value.logprobs) {
4936
5175
  logprobs.push(value.logprobs);
4937
5176
  }
4938
5177
  } else if (value.type === "response.reasoning_summary_part.added") {
@@ -4959,7 +5198,7 @@ var OpenAIResponsesLanguageModel = class {
4959
5198
  providerMetadata: {
4960
5199
  [providerKey]: {
4961
5200
  itemId: value.item_id,
4962
- reasoningEncryptedContent: (_h = (_g = activeReasoning[value.item_id]) == null ? void 0 : _g.encryptedContent) != null ? _h : null
5201
+ reasoningEncryptedContent: (_o = (_n = activeReasoning[value.item_id]) == null ? void 0 : _n.encryptedContent) != null ? _o : null
4963
5202
  }
4964
5203
  }
4965
5204
  });
@@ -4989,10 +5228,13 @@ var OpenAIResponsesLanguageModel = class {
4989
5228
  activeReasoning[value.item_id].summaryParts[value.summary_index] = "can-conclude";
4990
5229
  }
4991
5230
  } else if (isResponseFinishedChunk(value)) {
4992
- finishReason = mapOpenAIResponseFinishReason({
4993
- finishReason: (_i = value.response.incomplete_details) == null ? void 0 : _i.reason,
4994
- hasFunctionCall
4995
- });
5231
+ finishReason = {
5232
+ unified: mapOpenAIResponseFinishReason({
5233
+ finishReason: (_p = value.response.incomplete_details) == null ? void 0 : _p.reason,
5234
+ hasFunctionCall
5235
+ }),
5236
+ raw: (_r = (_q = value.response.incomplete_details) == null ? void 0 : _q.reason) != null ? _r : void 0
5237
+ };
4996
5238
  usage = value.response.usage;
4997
5239
  if (typeof value.response.service_tier === "string") {
4998
5240
  serviceTier = value.response.service_tier;
@@ -5003,7 +5245,7 @@ var OpenAIResponsesLanguageModel = class {
5003
5245
  controller.enqueue({
5004
5246
  type: "source",
5005
5247
  sourceType: "url",
5006
- id: (_l = (_k = (_j = self.config).generateId) == null ? void 0 : _k.call(_j)) != null ? _l : (0, import_provider_utils27.generateId)(),
5248
+ id: (_u = (_t = (_s = self.config).generateId) == null ? void 0 : _t.call(_s)) != null ? _u : (0, import_provider_utils27.generateId)(),
5007
5249
  url: value.annotation.url,
5008
5250
  title: value.annotation.title
5009
5251
  });
@@ -5011,10 +5253,10 @@ var OpenAIResponsesLanguageModel = class {
5011
5253
  controller.enqueue({
5012
5254
  type: "source",
5013
5255
  sourceType: "document",
5014
- id: (_o = (_n = (_m = self.config).generateId) == null ? void 0 : _n.call(_m)) != null ? _o : (0, import_provider_utils27.generateId)(),
5256
+ id: (_x = (_w = (_v = self.config).generateId) == null ? void 0 : _w.call(_v)) != null ? _x : (0, import_provider_utils27.generateId)(),
5015
5257
  mediaType: "text/plain",
5016
- title: (_q = (_p = value.annotation.quote) != null ? _p : value.annotation.filename) != null ? _q : "Document",
5017
- filename: (_r = value.annotation.filename) != null ? _r : value.annotation.file_id,
5258
+ title: (_z = (_y = value.annotation.quote) != null ? _y : value.annotation.filename) != null ? _z : "Document",
5259
+ filename: (_A = value.annotation.filename) != null ? _A : value.annotation.file_id,
5018
5260
  ...value.annotation.file_id ? {
5019
5261
  providerMetadata: {
5020
5262
  [providerKey]: {
@@ -5027,10 +5269,10 @@ var OpenAIResponsesLanguageModel = class {
5027
5269
  controller.enqueue({
5028
5270
  type: "source",
5029
5271
  sourceType: "document",
5030
- id: (_u = (_t = (_s = self.config).generateId) == null ? void 0 : _t.call(_s)) != null ? _u : (0, import_provider_utils27.generateId)(),
5272
+ id: (_D = (_C = (_B = self.config).generateId) == null ? void 0 : _C.call(_B)) != null ? _D : (0, import_provider_utils27.generateId)(),
5031
5273
  mediaType: "text/plain",
5032
- title: (_w = (_v = value.annotation.filename) != null ? _v : value.annotation.file_id) != null ? _w : "Document",
5033
- filename: (_x = value.annotation.filename) != null ? _x : value.annotation.file_id,
5274
+ title: (_F = (_E = value.annotation.filename) != null ? _E : value.annotation.file_id) != null ? _F : "Document",
5275
+ filename: (_G = value.annotation.filename) != null ? _G : value.annotation.file_id,
5034
5276
  providerMetadata: {
5035
5277
  [providerKey]: {
5036
5278
  fileId: value.annotation.file_id,
@@ -5043,7 +5285,7 @@ var OpenAIResponsesLanguageModel = class {
5043
5285
  controller.enqueue({
5044
5286
  type: "source",
5045
5287
  sourceType: "document",
5046
- id: (_A = (_z = (_y = self.config).generateId) == null ? void 0 : _z.call(_y)) != null ? _A : (0, import_provider_utils27.generateId)(),
5288
+ id: (_J = (_I = (_H = self.config).generateId) == null ? void 0 : _I.call(_H)) != null ? _J : (0, import_provider_utils27.generateId)(),
5047
5289
  mediaType: "application/octet-stream",
5048
5290
  title: value.annotation.file_id,
5049
5291
  filename: value.annotation.file_id,
@@ -5109,6 +5351,12 @@ function isResponseCodeInterpreterCallCodeDeltaChunk(chunk) {
5109
5351
  function isResponseCodeInterpreterCallCodeDoneChunk(chunk) {
5110
5352
  return chunk.type === "response.code_interpreter_call_code.done";
5111
5353
  }
5354
+ function isResponseApplyPatchCallOperationDiffDeltaChunk(chunk) {
5355
+ return chunk.type === "response.apply_patch_call_operation_diff.delta";
5356
+ }
5357
+ function isResponseApplyPatchCallOperationDiffDoneChunk(chunk) {
5358
+ return chunk.type === "response.apply_patch_call_operation_diff.done";
5359
+ }
5112
5360
  function isResponseOutputItemAddedChunk(chunk) {
5113
5361
  return chunk.type === "response.output_item.added";
5114
5362
  }
@@ -5139,6 +5387,9 @@ function mapWebSearchOutput(action) {
5139
5387
  };
5140
5388
  }
5141
5389
  }
5390
+ function escapeJSONDelta(delta) {
5391
+ return JSON.stringify(delta).slice(1, -1);
5392
+ }
5142
5393
 
5143
5394
  // src/speech/openai-speech-model.ts
5144
5395
  var import_provider_utils29 = require("@ai-sdk/provider-utils");
@@ -5493,7 +5744,7 @@ var OpenAITranscriptionModel = class {
5493
5744
  };
5494
5745
 
5495
5746
  // src/version.ts
5496
- var VERSION = true ? "3.0.0-beta.99" : "0.0.0-test";
5747
+ var VERSION = true ? "3.0.1" : "0.0.0-test";
5497
5748
 
5498
5749
  // src/openai-provider.ts
5499
5750
  function createOpenAI(options = {}) {
@@ -5581,6 +5832,8 @@ function createOpenAI(options = {}) {
5581
5832
  provider.responses = createResponsesModel;
5582
5833
  provider.embedding = createEmbeddingModel;
5583
5834
  provider.embeddingModel = createEmbeddingModel;
5835
+ provider.textEmbedding = createEmbeddingModel;
5836
+ provider.textEmbeddingModel = createEmbeddingModel;
5584
5837
  provider.image = createImageModel;
5585
5838
  provider.imageModel = createImageModel;
5586
5839
  provider.transcription = createTranscriptionModel;