@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.mjs CHANGED
@@ -43,8 +43,8 @@ var openaiFailedResponseHandler = createJsonErrorResponseHandler({
43
43
  function getOpenAILanguageModelCapabilities(modelId) {
44
44
  const supportsFlexProcessing = modelId.startsWith("o3") || modelId.startsWith("o4-mini") || modelId.startsWith("gpt-5") && !modelId.startsWith("gpt-5-chat");
45
45
  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");
46
- const isReasoningModel = !(modelId.startsWith("gpt-3") || modelId.startsWith("gpt-4") || modelId.startsWith("chatgpt-4o") || modelId.startsWith("gpt-5-chat"));
47
- const supportsNonReasoningParameters = modelId.startsWith("gpt-5.1");
46
+ 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");
47
+ const supportsNonReasoningParameters = modelId.startsWith("gpt-5.1") || modelId.startsWith("gpt-5.2");
48
48
  const systemMessageMode = isReasoningModel ? "developer" : "system";
49
49
  return {
50
50
  supportsFlexProcessing,
@@ -245,6 +245,9 @@ function convertToOpenAIChatMessages({
245
245
  }
246
246
  case "tool": {
247
247
  for (const toolResponse of content) {
248
+ if (toolResponse.type === "tool-approval-response") {
249
+ continue;
250
+ }
248
251
  const output = toolResponse.output;
249
252
  let contentValue;
250
253
  switch (output.type) {
@@ -304,7 +307,7 @@ function mapOpenAIFinishReason(finishReason) {
304
307
  case "tool_calls":
305
308
  return "tool-calls";
306
309
  default:
307
- return "unknown";
310
+ return "other";
308
311
  }
309
312
  }
310
313
 
@@ -545,7 +548,26 @@ var openaiChatLanguageModelOptions = lazySchema2(
545
548
  * username or email address, in order to avoid sending us any identifying
546
549
  * information.
547
550
  */
548
- safetyIdentifier: z3.string().optional()
551
+ safetyIdentifier: z3.string().optional(),
552
+ /**
553
+ * Override the system message mode for this model.
554
+ * - 'system': Use the 'system' role for system messages (default for most models)
555
+ * - 'developer': Use the 'developer' role for system messages (used by reasoning models)
556
+ * - 'remove': Remove system messages entirely
557
+ *
558
+ * If not specified, the mode is automatically determined based on the model.
559
+ */
560
+ systemMessageMode: z3.enum(["system", "developer", "remove"]).optional(),
561
+ /**
562
+ * Force treating this model as a reasoning model.
563
+ *
564
+ * This is useful for "stealth" reasoning models (e.g. via a custom baseURL)
565
+ * where the model ID is not recognized by the SDK's allowlist.
566
+ *
567
+ * When enabled, the SDK applies reasoning-model parameter compatibility rules
568
+ * and defaults `systemMessageMode` to `developer` unless overridden.
569
+ */
570
+ forceReasoning: z3.boolean().optional()
549
571
  })
550
572
  )
551
573
  );
@@ -642,7 +664,7 @@ var OpenAIChatLanguageModel = class {
642
664
  toolChoice,
643
665
  providerOptions
644
666
  }) {
645
- var _a, _b, _c;
667
+ var _a, _b, _c, _d, _e;
646
668
  const warnings = [];
647
669
  const openaiOptions = (_a = await parseProviderOptions({
648
670
  provider: "openai",
@@ -650,17 +672,18 @@ var OpenAIChatLanguageModel = class {
650
672
  schema: openaiChatLanguageModelOptions
651
673
  })) != null ? _a : {};
652
674
  const modelCapabilities = getOpenAILanguageModelCapabilities(this.modelId);
675
+ const isReasoningModel = (_b = openaiOptions.forceReasoning) != null ? _b : modelCapabilities.isReasoningModel;
653
676
  if (topK != null) {
654
677
  warnings.push({ type: "unsupported", feature: "topK" });
655
678
  }
656
679
  const { messages, warnings: messageWarnings } = convertToOpenAIChatMessages(
657
680
  {
658
681
  prompt,
659
- systemMessageMode: modelCapabilities.systemMessageMode
682
+ systemMessageMode: (_c = openaiOptions.systemMessageMode) != null ? _c : isReasoningModel ? "developer" : modelCapabilities.systemMessageMode
660
683
  }
661
684
  );
662
685
  warnings.push(...messageWarnings);
663
- const strictJsonSchema = (_b = openaiOptions.strictJsonSchema) != null ? _b : true;
686
+ const strictJsonSchema = (_d = openaiOptions.strictJsonSchema) != null ? _d : true;
664
687
  const baseArgs = {
665
688
  // model id:
666
689
  model: this.modelId,
@@ -681,7 +704,7 @@ var OpenAIChatLanguageModel = class {
681
704
  json_schema: {
682
705
  schema: responseFormat.schema,
683
706
  strict: strictJsonSchema,
684
- name: (_c = responseFormat.name) != null ? _c : "response",
707
+ name: (_e = responseFormat.name) != null ? _e : "response",
685
708
  description: responseFormat.description
686
709
  }
687
710
  } : { type: "json_object" } : void 0,
@@ -702,7 +725,7 @@ var OpenAIChatLanguageModel = class {
702
725
  // messages:
703
726
  messages
704
727
  };
705
- if (modelCapabilities.isReasoningModel) {
728
+ if (isReasoningModel) {
706
729
  if (openaiOptions.reasoningEffort !== "none" || !modelCapabilities.supportsNonReasoningParameters) {
707
730
  if (baseArgs.temperature != null) {
708
731
  baseArgs.temperature = void 0;
@@ -808,7 +831,7 @@ var OpenAIChatLanguageModel = class {
808
831
  };
809
832
  }
810
833
  async doGenerate(options) {
811
- var _a, _b, _c, _d, _e, _f;
834
+ var _a, _b, _c, _d, _e, _f, _g;
812
835
  const { args: body, warnings } = await this.getArgs(options);
813
836
  const {
814
837
  responseHeaders,
@@ -865,7 +888,10 @@ var OpenAIChatLanguageModel = class {
865
888
  }
866
889
  return {
867
890
  content,
868
- finishReason: mapOpenAIFinishReason(choice.finish_reason),
891
+ finishReason: {
892
+ unified: mapOpenAIFinishReason(choice.finish_reason),
893
+ raw: (_g = choice.finish_reason) != null ? _g : void 0
894
+ },
869
895
  usage: convertOpenAIChatUsage(response.usage),
870
896
  request: { body },
871
897
  response: {
@@ -901,7 +927,10 @@ var OpenAIChatLanguageModel = class {
901
927
  fetch: this.config.fetch
902
928
  });
903
929
  const toolCalls = [];
904
- let finishReason = "unknown";
930
+ let finishReason = {
931
+ unified: "other",
932
+ raw: void 0
933
+ };
905
934
  let usage = void 0;
906
935
  let metadataExtracted = false;
907
936
  let isActiveText = false;
@@ -918,13 +947,13 @@ var OpenAIChatLanguageModel = class {
918
947
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
919
948
  }
920
949
  if (!chunk.success) {
921
- finishReason = "error";
950
+ finishReason = { unified: "error", raw: void 0 };
922
951
  controller.enqueue({ type: "error", error: chunk.error });
923
952
  return;
924
953
  }
925
954
  const value = chunk.value;
926
955
  if ("error" in value) {
927
- finishReason = "error";
956
+ finishReason = { unified: "error", raw: void 0 };
928
957
  controller.enqueue({ type: "error", error: value.error });
929
958
  return;
930
959
  }
@@ -949,7 +978,10 @@ var OpenAIChatLanguageModel = class {
949
978
  }
950
979
  const choice = value.choices[0];
951
980
  if ((choice == null ? void 0 : choice.finish_reason) != null) {
952
- finishReason = mapOpenAIFinishReason(choice.finish_reason);
981
+ finishReason = {
982
+ unified: mapOpenAIFinishReason(choice.finish_reason),
983
+ raw: choice.finish_reason
984
+ };
953
985
  }
954
986
  if (((_e = choice == null ? void 0 : choice.logprobs) == null ? void 0 : _e.content) != null) {
955
987
  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;
@@ -1678,7 +1720,11 @@ var OpenAIEmbeddingModel = class {
1678
1720
  // src/image/openai-image-model.ts
1679
1721
  import {
1680
1722
  combineHeaders as combineHeaders4,
1723
+ convertBase64ToUint8Array,
1724
+ convertToFormData,
1681
1725
  createJsonResponseHandler as createJsonResponseHandler4,
1726
+ downloadBlob,
1727
+ postFormDataToApi,
1682
1728
  postJsonToApi as postJsonToApi4
1683
1729
  } from "@ai-sdk/provider-utils";
1684
1730
 
@@ -1717,11 +1763,13 @@ var modelMaxImagesPerCall = {
1717
1763
  "dall-e-3": 1,
1718
1764
  "dall-e-2": 10,
1719
1765
  "gpt-image-1": 10,
1720
- "gpt-image-1-mini": 10
1766
+ "gpt-image-1-mini": 10,
1767
+ "gpt-image-1.5": 10
1721
1768
  };
1722
1769
  var hasDefaultResponseFormat = /* @__PURE__ */ new Set([
1723
1770
  "gpt-image-1",
1724
- "gpt-image-1-mini"
1771
+ "gpt-image-1-mini",
1772
+ "gpt-image-1.5"
1725
1773
  ]);
1726
1774
 
1727
1775
  // src/image/openai-image-model.ts
@@ -1740,6 +1788,8 @@ var OpenAIImageModel = class {
1740
1788
  }
1741
1789
  async doGenerate({
1742
1790
  prompt,
1791
+ files,
1792
+ mask,
1743
1793
  n,
1744
1794
  size,
1745
1795
  aspectRatio,
@@ -1748,7 +1798,7 @@ var OpenAIImageModel = class {
1748
1798
  headers,
1749
1799
  abortSignal
1750
1800
  }) {
1751
- var _a, _b, _c, _d, _e, _f, _g;
1801
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
1752
1802
  const warnings = [];
1753
1803
  if (aspectRatio != null) {
1754
1804
  warnings.push({
@@ -1761,6 +1811,72 @@ var OpenAIImageModel = class {
1761
1811
  warnings.push({ type: "unsupported", feature: "seed" });
1762
1812
  }
1763
1813
  const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
1814
+ if (files != null) {
1815
+ const { value: response2, responseHeaders: responseHeaders2 } = await postFormDataToApi({
1816
+ url: this.config.url({
1817
+ path: "/images/edits",
1818
+ modelId: this.modelId
1819
+ }),
1820
+ headers: combineHeaders4(this.config.headers(), headers),
1821
+ formData: convertToFormData({
1822
+ model: this.modelId,
1823
+ prompt,
1824
+ image: await Promise.all(
1825
+ files.map(
1826
+ (file) => file.type === "file" ? new Blob(
1827
+ [
1828
+ file.data instanceof Uint8Array ? new Blob([file.data], {
1829
+ type: file.mediaType
1830
+ }) : new Blob([convertBase64ToUint8Array(file.data)], {
1831
+ type: file.mediaType
1832
+ })
1833
+ ],
1834
+ { type: file.mediaType }
1835
+ ) : downloadBlob(file.url)
1836
+ )
1837
+ ),
1838
+ mask: mask != null ? await fileToBlob(mask) : void 0,
1839
+ n,
1840
+ size,
1841
+ ...(_d = providerOptions.openai) != null ? _d : {}
1842
+ }),
1843
+ failedResponseHandler: openaiFailedResponseHandler,
1844
+ successfulResponseHandler: createJsonResponseHandler4(
1845
+ openaiImageResponseSchema
1846
+ ),
1847
+ abortSignal,
1848
+ fetch: this.config.fetch
1849
+ });
1850
+ return {
1851
+ images: response2.data.map((item) => item.b64_json),
1852
+ warnings,
1853
+ usage: response2.usage != null ? {
1854
+ inputTokens: (_e = response2.usage.input_tokens) != null ? _e : void 0,
1855
+ outputTokens: (_f = response2.usage.output_tokens) != null ? _f : void 0,
1856
+ totalTokens: (_g = response2.usage.total_tokens) != null ? _g : void 0
1857
+ } : void 0,
1858
+ response: {
1859
+ timestamp: currentDate,
1860
+ modelId: this.modelId,
1861
+ headers: responseHeaders2
1862
+ },
1863
+ providerMetadata: {
1864
+ openai: {
1865
+ images: response2.data.map((item) => {
1866
+ var _a2, _b2, _c2, _d2, _e2;
1867
+ return {
1868
+ ...item.revised_prompt ? { revisedPrompt: item.revised_prompt } : {},
1869
+ created: (_a2 = response2.created) != null ? _a2 : void 0,
1870
+ size: (_b2 = response2.size) != null ? _b2 : void 0,
1871
+ quality: (_c2 = response2.quality) != null ? _c2 : void 0,
1872
+ background: (_d2 = response2.background) != null ? _d2 : void 0,
1873
+ outputFormat: (_e2 = response2.output_format) != null ? _e2 : void 0
1874
+ };
1875
+ })
1876
+ }
1877
+ }
1878
+ };
1879
+ }
1764
1880
  const { value: response, responseHeaders } = await postJsonToApi4({
1765
1881
  url: this.config.url({
1766
1882
  path: "/images/generations",
@@ -1772,7 +1888,7 @@ var OpenAIImageModel = class {
1772
1888
  prompt,
1773
1889
  n,
1774
1890
  size,
1775
- ...(_d = providerOptions.openai) != null ? _d : {},
1891
+ ...(_h = providerOptions.openai) != null ? _h : {},
1776
1892
  ...!hasDefaultResponseFormat.has(this.modelId) ? { response_format: "b64_json" } : {}
1777
1893
  },
1778
1894
  failedResponseHandler: openaiFailedResponseHandler,
@@ -1786,9 +1902,9 @@ var OpenAIImageModel = class {
1786
1902
  images: response.data.map((item) => item.b64_json),
1787
1903
  warnings,
1788
1904
  usage: response.usage != null ? {
1789
- inputTokens: (_e = response.usage.input_tokens) != null ? _e : void 0,
1790
- outputTokens: (_f = response.usage.output_tokens) != null ? _f : void 0,
1791
- totalTokens: (_g = response.usage.total_tokens) != null ? _g : void 0
1905
+ inputTokens: (_i = response.usage.input_tokens) != null ? _i : void 0,
1906
+ outputTokens: (_j = response.usage.output_tokens) != null ? _j : void 0,
1907
+ totalTokens: (_k = response.usage.total_tokens) != null ? _k : void 0
1792
1908
  } : void 0,
1793
1909
  response: {
1794
1910
  timestamp: currentDate,
@@ -1813,6 +1929,14 @@ var OpenAIImageModel = class {
1813
1929
  };
1814
1930
  }
1815
1931
  };
1932
+ async function fileToBlob(file) {
1933
+ if (!file) return void 0;
1934
+ if (file.type === "url") {
1935
+ return downloadBlob(file.url);
1936
+ }
1937
+ const data = file.data instanceof Uint8Array ? file.data : convertBase64ToUint8Array(file.data);
1938
+ return new Blob([data], { type: file.mediaType });
1939
+ }
1816
1940
 
1817
1941
  // src/tool/apply-patch.ts
1818
1942
  import {
@@ -2210,16 +2334,14 @@ var mcpArgsSchema = lazySchema16(
2210
2334
  authorization: z17.string().optional(),
2211
2335
  connectorId: z17.string().optional(),
2212
2336
  headers: z17.record(z17.string(), z17.string()).optional(),
2213
- // TODO: Integrate this MCP tool approval with our SDK's existing tool approval architecture
2214
- // requireApproval: z
2215
- // .union([
2216
- // z.enum(['always', 'never']),
2217
- // z.object({
2218
- // readOnly: z.boolean().optional(),
2219
- // toolNames: z.array(z.string()).optional(),
2220
- // }),
2221
- // ])
2222
- // .optional(),
2337
+ requireApproval: z17.union([
2338
+ z17.enum(["always", "never"]),
2339
+ z17.object({
2340
+ never: z17.object({
2341
+ toolNames: z17.array(z17.string()).optional()
2342
+ }).optional()
2343
+ })
2344
+ ]).optional(),
2223
2345
  serverDescription: z17.string().optional(),
2224
2346
  serverUrl: z17.string().optional()
2225
2347
  }).refine(
@@ -2231,36 +2353,14 @@ var mcpArgsSchema = lazySchema16(
2231
2353
  var mcpInputSchema = lazySchema16(() => zodSchema16(z17.object({})));
2232
2354
  var mcpOutputSchema = lazySchema16(
2233
2355
  () => zodSchema16(
2234
- z17.discriminatedUnion("type", [
2235
- z17.object({
2236
- type: z17.literal("call"),
2237
- serverLabel: z17.string(),
2238
- name: z17.string(),
2239
- arguments: z17.string(),
2240
- output: z17.string().nullable().optional(),
2241
- error: z17.union([z17.string(), jsonValueSchema]).optional()
2242
- }),
2243
- z17.object({
2244
- type: z17.literal("listTools"),
2245
- serverLabel: z17.string(),
2246
- tools: z17.array(
2247
- z17.object({
2248
- name: z17.string(),
2249
- description: z17.string().optional(),
2250
- inputSchema: jsonValueSchema,
2251
- annotations: z17.record(z17.string(), jsonValueSchema).optional()
2252
- })
2253
- ),
2254
- error: z17.union([z17.string(), jsonValueSchema]).optional()
2255
- }),
2256
- z17.object({
2257
- type: z17.literal("approvalRequest"),
2258
- serverLabel: z17.string(),
2259
- name: z17.string(),
2260
- arguments: z17.string(),
2261
- approvalRequestId: z17.string()
2262
- })
2263
- ])
2356
+ z17.object({
2357
+ type: z17.literal("call"),
2358
+ serverLabel: z17.string(),
2359
+ name: z17.string(),
2360
+ arguments: z17.string(),
2361
+ output: z17.string().nullish(),
2362
+ error: z17.union([z17.string(), jsonValueSchema]).optional()
2363
+ })
2264
2364
  )
2265
2365
  );
2266
2366
  var mcpToolFactory = createProviderToolFactoryWithOutputSchema9({
@@ -2446,9 +2546,10 @@ async function convertToOpenAIResponsesInput({
2446
2546
  hasShellTool = false,
2447
2547
  hasApplyPatchTool = false
2448
2548
  }) {
2449
- var _a, _b, _c, _d, _e;
2549
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
2450
2550
  const input = [];
2451
2551
  const warnings = [];
2552
+ const processedApprovalIds = /* @__PURE__ */ new Set();
2452
2553
  for (const { role, content } of prompt) {
2453
2554
  switch (role) {
2454
2555
  case "system": {
@@ -2539,10 +2640,13 @@ async function convertToOpenAIResponsesInput({
2539
2640
  break;
2540
2641
  }
2541
2642
  case "tool-call": {
2643
+ 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;
2542
2644
  if (part.providerExecuted) {
2645
+ if (store && id != null) {
2646
+ input.push({ type: "item_reference", id });
2647
+ }
2543
2648
  break;
2544
2649
  }
2545
- const id = (_d = (_c = part.providerOptions) == null ? void 0 : _c.openai) == null ? void 0 : _d.itemId;
2546
2650
  if (store && id != null) {
2547
2651
  input.push({ type: "item_reference", id });
2548
2652
  break;
@@ -2599,8 +2703,12 @@ async function convertToOpenAIResponsesInput({
2599
2703
  }
2600
2704
  // assistant tool result parts are from provider-executed tools:
2601
2705
  case "tool-result": {
2706
+ 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") {
2707
+ break;
2708
+ }
2602
2709
  if (store) {
2603
- input.push({ type: "item_reference", id: part.toolCallId });
2710
+ const itemId = (_j = (_i = (_h = part.providerMetadata) == null ? void 0 : _h.openai) == null ? void 0 : _i.itemId) != null ? _j : part.toolCallId;
2711
+ input.push({ type: "item_reference", id: itemId });
2604
2712
  } else {
2605
2713
  warnings.push({
2606
2714
  type: "other",
@@ -2669,7 +2777,32 @@ async function convertToOpenAIResponsesInput({
2669
2777
  }
2670
2778
  case "tool": {
2671
2779
  for (const part of content) {
2780
+ if (part.type === "tool-approval-response") {
2781
+ const approvalResponse = part;
2782
+ if (processedApprovalIds.has(approvalResponse.approvalId)) {
2783
+ continue;
2784
+ }
2785
+ processedApprovalIds.add(approvalResponse.approvalId);
2786
+ if (store) {
2787
+ input.push({
2788
+ type: "item_reference",
2789
+ id: approvalResponse.approvalId
2790
+ });
2791
+ }
2792
+ input.push({
2793
+ type: "mcp_approval_response",
2794
+ approval_request_id: approvalResponse.approvalId,
2795
+ approve: approvalResponse.approved
2796
+ });
2797
+ continue;
2798
+ }
2672
2799
  const output = part.output;
2800
+ if (output.type === "execution-denied") {
2801
+ const approvalId = (_l = (_k = output.providerOptions) == null ? void 0 : _k.openai) == null ? void 0 : _l.approvalId;
2802
+ if (approvalId) {
2803
+ continue;
2804
+ }
2805
+ }
2673
2806
  const resolvedToolName = toolNameMapping.toProviderToolName(
2674
2807
  part.toolName
2675
2808
  );
@@ -2683,7 +2816,7 @@ async function convertToOpenAIResponsesInput({
2683
2816
  call_id: part.toolCallId,
2684
2817
  output: parsedOutput.output
2685
2818
  });
2686
- break;
2819
+ continue;
2687
2820
  }
2688
2821
  if (hasShellTool && resolvedToolName === "shell" && output.type === "json") {
2689
2822
  const parsedOutput = await validateTypes({
@@ -2702,7 +2835,7 @@ async function convertToOpenAIResponsesInput({
2702
2835
  }
2703
2836
  }))
2704
2837
  });
2705
- break;
2838
+ continue;
2706
2839
  }
2707
2840
  if (hasApplyPatchTool && part.toolName === "apply_patch" && output.type === "json") {
2708
2841
  const parsedOutput = await validateTypes({
@@ -2715,7 +2848,7 @@ async function convertToOpenAIResponsesInput({
2715
2848
  status: parsedOutput.status,
2716
2849
  output: parsedOutput.output
2717
2850
  });
2718
- break;
2851
+ continue;
2719
2852
  }
2720
2853
  let contentValue;
2721
2854
  switch (output.type) {
@@ -2724,7 +2857,7 @@ async function convertToOpenAIResponsesInput({
2724
2857
  contentValue = output.value;
2725
2858
  break;
2726
2859
  case "execution-denied":
2727
- contentValue = (_e = output.reason) != null ? _e : "Tool execution denied.";
2860
+ contentValue = (_m = output.reason) != null ? _m : "Tool execution denied.";
2728
2861
  break;
2729
2862
  case "json":
2730
2863
  case "error-json":
@@ -2796,7 +2929,7 @@ function mapOpenAIResponseFinishReason({
2796
2929
  case "content_filter":
2797
2930
  return "content-filter";
2798
2931
  default:
2799
- return hasFunctionCall ? "tool-calls" : "unknown";
2932
+ return hasFunctionCall ? "tool-calls" : "other";
2800
2933
  }
2801
2934
  }
2802
2935
 
@@ -2899,7 +3032,8 @@ var openaiResponsesChunkSchema = lazySchema17(
2899
3032
  z19.object({
2900
3033
  type: z19.literal("mcp_call"),
2901
3034
  id: z19.string(),
2902
- status: z19.string()
3035
+ status: z19.string(),
3036
+ approval_request_id: z19.string().nullish()
2903
3037
  }),
2904
3038
  z19.object({
2905
3039
  type: z19.literal("mcp_list_tools"),
@@ -3056,7 +3190,8 @@ var openaiResponsesChunkSchema = lazySchema17(
3056
3190
  code: z19.union([z19.number(), z19.string()]).optional(),
3057
3191
  message: z19.string().optional()
3058
3192
  }).loose()
3059
- ]).nullish()
3193
+ ]).nullish(),
3194
+ approval_request_id: z19.string().nullish()
3060
3195
  }),
3061
3196
  z19.object({
3062
3197
  type: z19.literal("mcp_list_tools"),
@@ -3085,7 +3220,7 @@ var openaiResponsesChunkSchema = lazySchema17(
3085
3220
  server_label: z19.string(),
3086
3221
  name: z19.string(),
3087
3222
  arguments: z19.string(),
3088
- approval_request_id: z19.string()
3223
+ approval_request_id: z19.string().optional()
3089
3224
  }),
3090
3225
  z19.object({
3091
3226
  type: z19.literal("apply_patch_call"),
@@ -3195,6 +3330,19 @@ var openaiResponsesChunkSchema = lazySchema17(
3195
3330
  item_id: z19.string(),
3196
3331
  summary_index: z19.number()
3197
3332
  }),
3333
+ z19.object({
3334
+ type: z19.literal("response.apply_patch_call_operation_diff.delta"),
3335
+ item_id: z19.string(),
3336
+ output_index: z19.number(),
3337
+ delta: z19.string(),
3338
+ obfuscation: z19.string().nullish()
3339
+ }),
3340
+ z19.object({
3341
+ type: z19.literal("response.apply_patch_call_operation_diff.done"),
3342
+ item_id: z19.string(),
3343
+ output_index: z19.number(),
3344
+ diff: z19.string()
3345
+ }),
3198
3346
  z19.object({
3199
3347
  type: z19.literal("error"),
3200
3348
  sequence_number: z19.number(),
@@ -3395,7 +3543,8 @@ var openaiResponsesResponseSchema = lazySchema17(
3395
3543
  code: z19.union([z19.number(), z19.string()]).optional(),
3396
3544
  message: z19.string().optional()
3397
3545
  }).loose()
3398
- ]).nullish()
3546
+ ]).nullish(),
3547
+ approval_request_id: z19.string().nullish()
3399
3548
  }),
3400
3549
  z19.object({
3401
3550
  type: z19.literal("mcp_list_tools"),
@@ -3424,7 +3573,7 @@ var openaiResponsesResponseSchema = lazySchema17(
3424
3573
  server_label: z19.string(),
3425
3574
  name: z19.string(),
3426
3575
  arguments: z19.string(),
3427
- approval_request_id: z19.string()
3576
+ approval_request_id: z19.string().optional()
3428
3577
  }),
3429
3578
  z19.object({
3430
3579
  type: z19.literal("apply_patch_call"),
@@ -3675,7 +3824,26 @@ var openaiResponsesProviderOptionsSchema = lazySchema18(
3675
3824
  * Defaults to `undefined`.
3676
3825
  * @see https://platform.openai.com/docs/guides/safety-best-practices/end-user-ids
3677
3826
  */
3678
- user: z20.string().nullish()
3827
+ user: z20.string().nullish(),
3828
+ /**
3829
+ * Override the system message mode for this model.
3830
+ * - 'system': Use the 'system' role for system messages (default for most models)
3831
+ * - 'developer': Use the 'developer' role for system messages (used by reasoning models)
3832
+ * - 'remove': Remove system messages entirely
3833
+ *
3834
+ * If not specified, the mode is automatically determined based on the model.
3835
+ */
3836
+ systemMessageMode: z20.enum(["system", "developer", "remove"]).optional(),
3837
+ /**
3838
+ * Force treating this model as a reasoning model.
3839
+ *
3840
+ * This is useful for "stealth" reasoning models (e.g. via a custom baseURL)
3841
+ * where the model ID is not recognized by the SDK's allowlist.
3842
+ *
3843
+ * When enabled, the SDK applies reasoning-model parameter compatibility rules
3844
+ * and defaults `systemMessageMode` to `developer` unless overridden.
3845
+ */
3846
+ forceReasoning: z20.boolean().optional()
3679
3847
  })
3680
3848
  )
3681
3849
  );
@@ -3808,6 +3976,11 @@ async function prepareResponsesTools({
3808
3976
  value: tool.args,
3809
3977
  schema: mcpArgsSchema
3810
3978
  });
3979
+ const mapApprovalFilter = (filter) => ({
3980
+ tool_names: filter.toolNames
3981
+ });
3982
+ const requireApproval = args.requireApproval;
3983
+ const requireApprovalParam = requireApproval == null ? void 0 : typeof requireApproval === "string" ? requireApproval : requireApproval.never != null ? { never: mapApprovalFilter(requireApproval.never) } : void 0;
3811
3984
  openaiTools2.push({
3812
3985
  type: "mcp",
3813
3986
  server_label: args.serverLabel,
@@ -3818,7 +3991,7 @@ async function prepareResponsesTools({
3818
3991
  authorization: args.authorization,
3819
3992
  connector_id: args.connectorId,
3820
3993
  headers: args.headers,
3821
- require_approval: "never",
3994
+ require_approval: requireApprovalParam != null ? requireApprovalParam : "never",
3822
3995
  server_description: args.serverDescription,
3823
3996
  server_url: args.serverUrl
3824
3997
  });
@@ -3860,6 +4033,21 @@ async function prepareResponsesTools({
3860
4033
  }
3861
4034
 
3862
4035
  // src/responses/openai-responses-language-model.ts
4036
+ function extractApprovalRequestIdToToolCallIdMapping(prompt) {
4037
+ var _a, _b;
4038
+ const mapping = {};
4039
+ for (const message of prompt) {
4040
+ if (message.role !== "assistant") continue;
4041
+ for (const part of message.content) {
4042
+ if (part.type !== "tool-call") continue;
4043
+ const approvalRequestId = (_b = (_a = part.providerOptions) == null ? void 0 : _a.openai) == null ? void 0 : _b.approvalRequestId;
4044
+ if (approvalRequestId != null) {
4045
+ mapping[approvalRequestId] = part.toolCallId;
4046
+ }
4047
+ }
4048
+ }
4049
+ return mapping;
4050
+ }
3863
4051
  var OpenAIResponsesLanguageModel = class {
3864
4052
  constructor(modelId, config) {
3865
4053
  this.specificationVersion = "v3";
@@ -3888,7 +4076,7 @@ var OpenAIResponsesLanguageModel = class {
3888
4076
  toolChoice,
3889
4077
  responseFormat
3890
4078
  }) {
3891
- var _a, _b, _c, _d;
4079
+ var _a, _b, _c, _d, _e, _f;
3892
4080
  const warnings = [];
3893
4081
  const modelCapabilities = getOpenAILanguageModelCapabilities(this.modelId);
3894
4082
  if (topK != null) {
@@ -3911,6 +4099,7 @@ var OpenAIResponsesLanguageModel = class {
3911
4099
  providerOptions,
3912
4100
  schema: openaiResponsesProviderOptionsSchema
3913
4101
  });
4102
+ const isReasoningModel = (_a = openaiOptions == null ? void 0 : openaiOptions.forceReasoning) != null ? _a : modelCapabilities.isReasoningModel;
3914
4103
  if ((openaiOptions == null ? void 0 : openaiOptions.conversation) && (openaiOptions == null ? void 0 : openaiOptions.previousResponseId)) {
3915
4104
  warnings.push({
3916
4105
  type: "unsupported",
@@ -3935,15 +4124,15 @@ var OpenAIResponsesLanguageModel = class {
3935
4124
  const { input, warnings: inputWarnings } = await convertToOpenAIResponsesInput({
3936
4125
  prompt,
3937
4126
  toolNameMapping,
3938
- systemMessageMode: modelCapabilities.systemMessageMode,
4127
+ systemMessageMode: (_b = openaiOptions == null ? void 0 : openaiOptions.systemMessageMode) != null ? _b : isReasoningModel ? "developer" : modelCapabilities.systemMessageMode,
3939
4128
  fileIdPrefixes: this.config.fileIdPrefixes,
3940
- store: (_a = openaiOptions == null ? void 0 : openaiOptions.store) != null ? _a : true,
4129
+ store: (_c = openaiOptions == null ? void 0 : openaiOptions.store) != null ? _c : true,
3941
4130
  hasLocalShellTool: hasOpenAITool("openai.local_shell"),
3942
4131
  hasShellTool: hasOpenAITool("openai.shell"),
3943
4132
  hasApplyPatchTool: hasOpenAITool("openai.apply_patch")
3944
4133
  });
3945
4134
  warnings.push(...inputWarnings);
3946
- const strictJsonSchema = (_b = openaiOptions == null ? void 0 : openaiOptions.strictJsonSchema) != null ? _b : true;
4135
+ const strictJsonSchema = (_d = openaiOptions == null ? void 0 : openaiOptions.strictJsonSchema) != null ? _d : true;
3947
4136
  let include = openaiOptions == null ? void 0 : openaiOptions.include;
3948
4137
  function addInclude(key) {
3949
4138
  if (include == null) {
@@ -3959,9 +4148,9 @@ var OpenAIResponsesLanguageModel = class {
3959
4148
  if (topLogprobs) {
3960
4149
  addInclude("message.output_text.logprobs");
3961
4150
  }
3962
- const webSearchToolName = (_c = tools == null ? void 0 : tools.find(
4151
+ const webSearchToolName = (_e = tools == null ? void 0 : tools.find(
3963
4152
  (tool) => tool.type === "provider" && (tool.id === "openai.web_search" || tool.id === "openai.web_search_preview")
3964
- )) == null ? void 0 : _c.name;
4153
+ )) == null ? void 0 : _e.name;
3965
4154
  if (webSearchToolName) {
3966
4155
  addInclude("web_search_call.action.sources");
3967
4156
  }
@@ -3969,7 +4158,7 @@ var OpenAIResponsesLanguageModel = class {
3969
4158
  addInclude("code_interpreter_call.outputs");
3970
4159
  }
3971
4160
  const store = openaiOptions == null ? void 0 : openaiOptions.store;
3972
- if (store === false && modelCapabilities.isReasoningModel) {
4161
+ if (store === false && isReasoningModel) {
3973
4162
  addInclude("reasoning.encrypted_content");
3974
4163
  }
3975
4164
  const baseArgs = {
@@ -3984,7 +4173,7 @@ var OpenAIResponsesLanguageModel = class {
3984
4173
  format: responseFormat.schema != null ? {
3985
4174
  type: "json_schema",
3986
4175
  strict: strictJsonSchema,
3987
- name: (_d = responseFormat.name) != null ? _d : "response",
4176
+ name: (_f = responseFormat.name) != null ? _f : "response",
3988
4177
  description: responseFormat.description,
3989
4178
  schema: responseFormat.schema
3990
4179
  } : { type: "json_object" }
@@ -4011,7 +4200,7 @@ var OpenAIResponsesLanguageModel = class {
4011
4200
  top_logprobs: topLogprobs,
4012
4201
  truncation: openaiOptions == null ? void 0 : openaiOptions.truncation,
4013
4202
  // model-specific settings:
4014
- ...modelCapabilities.isReasoningModel && ((openaiOptions == null ? void 0 : openaiOptions.reasoningEffort) != null || (openaiOptions == null ? void 0 : openaiOptions.reasoningSummary) != null) && {
4203
+ ...isReasoningModel && ((openaiOptions == null ? void 0 : openaiOptions.reasoningEffort) != null || (openaiOptions == null ? void 0 : openaiOptions.reasoningSummary) != null) && {
4015
4204
  reasoning: {
4016
4205
  ...(openaiOptions == null ? void 0 : openaiOptions.reasoningEffort) != null && {
4017
4206
  effort: openaiOptions.reasoningEffort
@@ -4022,7 +4211,7 @@ var OpenAIResponsesLanguageModel = class {
4022
4211
  }
4023
4212
  }
4024
4213
  };
4025
- if (modelCapabilities.isReasoningModel) {
4214
+ if (isReasoningModel) {
4026
4215
  if (!((openaiOptions == null ? void 0 : openaiOptions.reasoningEffort) === "none" && modelCapabilities.supportsNonReasoningParameters)) {
4027
4216
  if (baseArgs.temperature != null) {
4028
4217
  baseArgs.temperature = void 0;
@@ -4094,7 +4283,7 @@ var OpenAIResponsesLanguageModel = class {
4094
4283
  };
4095
4284
  }
4096
4285
  async doGenerate(options) {
4097
- 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;
4286
+ 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;
4098
4287
  const {
4099
4288
  args: body,
4100
4289
  warnings,
@@ -4106,6 +4295,7 @@ var OpenAIResponsesLanguageModel = class {
4106
4295
  modelId: this.modelId
4107
4296
  });
4108
4297
  const providerKey = this.config.provider.replace(".responses", "");
4298
+ const approvalRequestIdToDummyToolCallIdFromPrompt = extractApprovalRequestIdToToolCallIdMapping(options.prompt);
4109
4299
  const {
4110
4300
  responseHeaders,
4111
4301
  value: response,
@@ -4322,17 +4512,20 @@ var OpenAIResponsesLanguageModel = class {
4322
4512
  break;
4323
4513
  }
4324
4514
  case "mcp_call": {
4515
+ const toolCallId = part.approval_request_id != null ? (_v = approvalRequestIdToDummyToolCallIdFromPrompt[part.approval_request_id]) != null ? _v : part.id : part.id;
4516
+ const toolName = `mcp.${part.name}`;
4325
4517
  content.push({
4326
4518
  type: "tool-call",
4327
- toolCallId: part.id,
4328
- toolName: toolNameMapping.toCustomToolName("mcp"),
4329
- input: JSON.stringify({}),
4330
- providerExecuted: true
4519
+ toolCallId,
4520
+ toolName,
4521
+ input: part.arguments,
4522
+ providerExecuted: true,
4523
+ dynamic: true
4331
4524
  });
4332
4525
  content.push({
4333
4526
  type: "tool-result",
4334
- toolCallId: part.id,
4335
- toolName: toolNameMapping.toCustomToolName("mcp"),
4527
+ toolCallId,
4528
+ toolName,
4336
4529
  result: {
4337
4530
  type: "call",
4338
4531
  serverLabel: part.server_label,
@@ -4340,58 +4533,34 @@ var OpenAIResponsesLanguageModel = class {
4340
4533
  arguments: part.arguments,
4341
4534
  ...part.output != null ? { output: part.output } : {},
4342
4535
  ...part.error != null ? { error: part.error } : {}
4536
+ },
4537
+ providerMetadata: {
4538
+ [providerKey]: {
4539
+ itemId: part.id
4540
+ }
4343
4541
  }
4344
4542
  });
4345
4543
  break;
4346
4544
  }
4347
4545
  case "mcp_list_tools": {
4348
- content.push({
4349
- type: "tool-call",
4350
- toolCallId: part.id,
4351
- toolName: toolNameMapping.toCustomToolName("mcp"),
4352
- input: JSON.stringify({}),
4353
- providerExecuted: true
4354
- });
4355
- content.push({
4356
- type: "tool-result",
4357
- toolCallId: part.id,
4358
- toolName: toolNameMapping.toCustomToolName("mcp"),
4359
- result: {
4360
- type: "listTools",
4361
- serverLabel: part.server_label,
4362
- tools: part.tools.map((t) => {
4363
- var _a2, _b2;
4364
- return {
4365
- name: t.name,
4366
- description: (_a2 = t.description) != null ? _a2 : void 0,
4367
- inputSchema: t.input_schema,
4368
- annotations: (_b2 = t.annotations) != null ? _b2 : void 0
4369
- };
4370
- }),
4371
- ...part.error != null ? { error: part.error } : {}
4372
- }
4373
- });
4374
4546
  break;
4375
4547
  }
4376
4548
  case "mcp_approval_request": {
4549
+ const approvalRequestId = (_w = part.approval_request_id) != null ? _w : part.id;
4550
+ const dummyToolCallId = (_z = (_y = (_x = this.config).generateId) == null ? void 0 : _y.call(_x)) != null ? _z : generateId2();
4551
+ const toolName = `mcp.${part.name}`;
4377
4552
  content.push({
4378
4553
  type: "tool-call",
4379
- toolCallId: part.id,
4380
- toolName: toolNameMapping.toCustomToolName("mcp"),
4381
- input: JSON.stringify({}),
4382
- providerExecuted: true
4554
+ toolCallId: dummyToolCallId,
4555
+ toolName,
4556
+ input: part.arguments,
4557
+ providerExecuted: true,
4558
+ dynamic: true
4383
4559
  });
4384
4560
  content.push({
4385
- type: "tool-result",
4386
- toolCallId: part.id,
4387
- toolName: toolNameMapping.toCustomToolName("mcp"),
4388
- result: {
4389
- type: "approvalRequest",
4390
- serverLabel: part.server_label,
4391
- name: part.name,
4392
- arguments: part.arguments,
4393
- approvalRequestId: part.approval_request_id
4394
- }
4561
+ type: "tool-approval-request",
4562
+ approvalId: approvalRequestId,
4563
+ toolCallId: dummyToolCallId
4395
4564
  });
4396
4565
  break;
4397
4566
  }
@@ -4428,13 +4597,13 @@ var OpenAIResponsesLanguageModel = class {
4428
4597
  toolName: toolNameMapping.toCustomToolName("file_search"),
4429
4598
  result: {
4430
4599
  queries: part.queries,
4431
- results: (_w = (_v = part.results) == null ? void 0 : _v.map((result) => ({
4600
+ results: (_B = (_A = part.results) == null ? void 0 : _A.map((result) => ({
4432
4601
  attributes: result.attributes,
4433
4602
  fileId: result.file_id,
4434
4603
  filename: result.filename,
4435
4604
  score: result.score,
4436
4605
  text: result.text
4437
- }))) != null ? _w : null
4606
+ }))) != null ? _B : null
4438
4607
  }
4439
4608
  });
4440
4609
  break;
@@ -4491,10 +4660,13 @@ var OpenAIResponsesLanguageModel = class {
4491
4660
  const usage = response.usage;
4492
4661
  return {
4493
4662
  content,
4494
- finishReason: mapOpenAIResponseFinishReason({
4495
- finishReason: (_x = response.incomplete_details) == null ? void 0 : _x.reason,
4496
- hasFunctionCall
4497
- }),
4663
+ finishReason: {
4664
+ unified: mapOpenAIResponseFinishReason({
4665
+ finishReason: (_C = response.incomplete_details) == null ? void 0 : _C.reason,
4666
+ hasFunctionCall
4667
+ }),
4668
+ raw: (_E = (_D = response.incomplete_details) == null ? void 0 : _D.reason) != null ? _E : void 0
4669
+ },
4498
4670
  usage: convertOpenAIResponsesUsage(usage),
4499
4671
  request: { body },
4500
4672
  response: {
@@ -4535,7 +4707,12 @@ var OpenAIResponsesLanguageModel = class {
4535
4707
  });
4536
4708
  const self = this;
4537
4709
  const providerKey = this.config.provider.replace(".responses", "");
4538
- let finishReason = "unknown";
4710
+ const approvalRequestIdToDummyToolCallIdFromPrompt = extractApprovalRequestIdToToolCallIdMapping(options.prompt);
4711
+ const approvalRequestIdToDummyToolCallIdFromStream = /* @__PURE__ */ new Map();
4712
+ let finishReason = {
4713
+ unified: "other",
4714
+ raw: void 0
4715
+ };
4539
4716
  let usage = void 0;
4540
4717
  const logprobs = [];
4541
4718
  let responseId = null;
@@ -4551,12 +4728,12 @@ var OpenAIResponsesLanguageModel = class {
4551
4728
  controller.enqueue({ type: "stream-start", warnings });
4552
4729
  },
4553
4730
  transform(chunk, controller) {
4554
- 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;
4731
+ 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;
4555
4732
  if (options.includeRawChunks) {
4556
4733
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
4557
4734
  }
4558
4735
  if (!chunk.success) {
4559
- finishReason = "error";
4736
+ finishReason = { unified: "error", raw: void 0 };
4560
4737
  controller.enqueue({ type: "error", error: chunk.error });
4561
4738
  return;
4562
4739
  }
@@ -4647,32 +4824,41 @@ var OpenAIResponsesLanguageModel = class {
4647
4824
  providerExecuted: true
4648
4825
  });
4649
4826
  } else if (value.item.type === "mcp_call" || value.item.type === "mcp_list_tools" || value.item.type === "mcp_approval_request") {
4650
- controller.enqueue({
4651
- type: "tool-call",
4652
- toolCallId: value.item.id,
4653
- toolName: toolNameMapping.toCustomToolName("mcp"),
4654
- input: "{}",
4655
- providerExecuted: true
4656
- });
4657
4827
  } else if (value.item.type === "apply_patch_call") {
4828
+ const { call_id: callId, operation } = value.item;
4658
4829
  ongoingToolCalls[value.output_index] = {
4659
4830
  toolName: toolNameMapping.toCustomToolName("apply_patch"),
4660
- toolCallId: value.item.call_id
4831
+ toolCallId: callId,
4832
+ applyPatch: {
4833
+ // delete_file doesn't have diff
4834
+ hasDiff: operation.type === "delete_file",
4835
+ endEmitted: operation.type === "delete_file"
4836
+ }
4661
4837
  };
4662
- if (value.item.status === "completed") {
4838
+ controller.enqueue({
4839
+ type: "tool-input-start",
4840
+ id: callId,
4841
+ toolName: toolNameMapping.toCustomToolName("apply_patch")
4842
+ });
4843
+ if (operation.type === "delete_file") {
4844
+ const inputString = JSON.stringify({
4845
+ callId,
4846
+ operation
4847
+ });
4663
4848
  controller.enqueue({
4664
- type: "tool-call",
4665
- toolCallId: value.item.call_id,
4666
- toolName: toolNameMapping.toCustomToolName("apply_patch"),
4667
- input: JSON.stringify({
4668
- callId: value.item.call_id,
4669
- operation: value.item.operation
4670
- }),
4671
- providerMetadata: {
4672
- [providerKey]: {
4673
- itemId: value.item.id
4674
- }
4675
- }
4849
+ type: "tool-input-delta",
4850
+ id: callId,
4851
+ delta: inputString
4852
+ });
4853
+ controller.enqueue({
4854
+ type: "tool-input-end",
4855
+ id: callId
4856
+ });
4857
+ } else {
4858
+ controller.enqueue({
4859
+ type: "tool-input-delta",
4860
+ id: callId,
4861
+ delta: `{"callId":"${escapeJSONDelta(callId)}","operation":{"type":"${escapeJSONDelta(operation.type)}","path":"${escapeJSONDelta(operation.path)}","diff":"`
4676
4862
  });
4677
4863
  }
4678
4864
  } else if (value.item.type === "shell_call") {
@@ -4809,10 +4995,23 @@ var OpenAIResponsesLanguageModel = class {
4809
4995
  });
4810
4996
  } else if (value.item.type === "mcp_call") {
4811
4997
  ongoingToolCalls[value.output_index] = void 0;
4998
+ const approvalRequestId = (_d = value.item.approval_request_id) != null ? _d : void 0;
4999
+ const aliasedToolCallId = approvalRequestId != null ? (_f = (_e = approvalRequestIdToDummyToolCallIdFromStream.get(
5000
+ approvalRequestId
5001
+ )) != null ? _e : approvalRequestIdToDummyToolCallIdFromPrompt[approvalRequestId]) != null ? _f : value.item.id : value.item.id;
5002
+ const toolName = `mcp.${value.item.name}`;
5003
+ controller.enqueue({
5004
+ type: "tool-call",
5005
+ toolCallId: aliasedToolCallId,
5006
+ toolName,
5007
+ input: value.item.arguments,
5008
+ providerExecuted: true,
5009
+ dynamic: true
5010
+ });
4812
5011
  controller.enqueue({
4813
5012
  type: "tool-result",
4814
- toolCallId: value.item.id,
4815
- toolName: toolNameMapping.toCustomToolName("mcp"),
5013
+ toolCallId: aliasedToolCallId,
5014
+ toolName,
4816
5015
  result: {
4817
5016
  type: "call",
4818
5017
  serverLabel: value.item.server_label,
@@ -4820,35 +5019,40 @@ var OpenAIResponsesLanguageModel = class {
4820
5019
  arguments: value.item.arguments,
4821
5020
  ...value.item.output != null ? { output: value.item.output } : {},
4822
5021
  ...value.item.error != null ? { error: value.item.error } : {}
5022
+ },
5023
+ providerMetadata: {
5024
+ [providerKey]: {
5025
+ itemId: value.item.id
5026
+ }
4823
5027
  }
4824
5028
  });
4825
5029
  } else if (value.item.type === "mcp_list_tools") {
4826
5030
  ongoingToolCalls[value.output_index] = void 0;
4827
- controller.enqueue({
4828
- type: "tool-result",
4829
- toolCallId: value.item.id,
4830
- toolName: toolNameMapping.toCustomToolName("mcp"),
4831
- result: {
4832
- type: "listTools",
4833
- serverLabel: value.item.server_label,
4834
- tools: value.item.tools.map((t) => {
4835
- var _a2, _b2;
4836
- return {
4837
- name: t.name,
4838
- description: (_a2 = t.description) != null ? _a2 : void 0,
4839
- inputSchema: t.input_schema,
4840
- annotations: (_b2 = t.annotations) != null ? _b2 : void 0
4841
- };
4842
- }),
4843
- ...value.item.error != null ? { error: value.item.error } : {}
4844
- }
4845
- });
4846
5031
  } else if (value.item.type === "apply_patch_call") {
4847
- ongoingToolCalls[value.output_index] = void 0;
4848
- if (value.item.status === "completed") {
5032
+ const toolCall = ongoingToolCalls[value.output_index];
5033
+ if ((toolCall == null ? void 0 : toolCall.applyPatch) && !toolCall.applyPatch.endEmitted && value.item.operation.type !== "delete_file") {
5034
+ if (!toolCall.applyPatch.hasDiff) {
5035
+ controller.enqueue({
5036
+ type: "tool-input-delta",
5037
+ id: toolCall.toolCallId,
5038
+ delta: escapeJSONDelta(value.item.operation.diff)
5039
+ });
5040
+ }
5041
+ controller.enqueue({
5042
+ type: "tool-input-delta",
5043
+ id: toolCall.toolCallId,
5044
+ delta: '"}}'
5045
+ });
5046
+ controller.enqueue({
5047
+ type: "tool-input-end",
5048
+ id: toolCall.toolCallId
5049
+ });
5050
+ toolCall.applyPatch.endEmitted = true;
5051
+ }
5052
+ if (toolCall && value.item.status === "completed") {
4849
5053
  controller.enqueue({
4850
5054
  type: "tool-call",
4851
- toolCallId: value.item.call_id,
5055
+ toolCallId: toolCall.toolCallId,
4852
5056
  toolName: toolNameMapping.toCustomToolName("apply_patch"),
4853
5057
  input: JSON.stringify({
4854
5058
  callId: value.item.call_id,
@@ -4861,19 +5065,28 @@ var OpenAIResponsesLanguageModel = class {
4861
5065
  }
4862
5066
  });
4863
5067
  }
5068
+ ongoingToolCalls[value.output_index] = void 0;
4864
5069
  } else if (value.item.type === "mcp_approval_request") {
4865
5070
  ongoingToolCalls[value.output_index] = void 0;
5071
+ const dummyToolCallId = (_i = (_h = (_g = self.config).generateId) == null ? void 0 : _h.call(_g)) != null ? _i : generateId2();
5072
+ const approvalRequestId = (_j = value.item.approval_request_id) != null ? _j : value.item.id;
5073
+ approvalRequestIdToDummyToolCallIdFromStream.set(
5074
+ approvalRequestId,
5075
+ dummyToolCallId
5076
+ );
5077
+ const toolName = `mcp.${value.item.name}`;
4866
5078
  controller.enqueue({
4867
- type: "tool-result",
4868
- toolCallId: value.item.id,
4869
- toolName: toolNameMapping.toCustomToolName("mcp"),
4870
- result: {
4871
- type: "approvalRequest",
4872
- serverLabel: value.item.server_label,
4873
- name: value.item.name,
4874
- arguments: value.item.arguments,
4875
- approvalRequestId: value.item.approval_request_id
4876
- }
5079
+ type: "tool-call",
5080
+ toolCallId: dummyToolCallId,
5081
+ toolName,
5082
+ input: value.item.arguments,
5083
+ providerExecuted: true,
5084
+ dynamic: true
5085
+ });
5086
+ controller.enqueue({
5087
+ type: "tool-approval-request",
5088
+ approvalId: approvalRequestId,
5089
+ toolCallId: dummyToolCallId
4877
5090
  });
4878
5091
  } else if (value.item.type === "local_shell_call") {
4879
5092
  ongoingToolCalls[value.output_index] = void 0;
@@ -4924,7 +5137,7 @@ var OpenAIResponsesLanguageModel = class {
4924
5137
  providerMetadata: {
4925
5138
  [providerKey]: {
4926
5139
  itemId: value.item.id,
4927
- reasoningEncryptedContent: (_d = value.item.encrypted_content) != null ? _d : null
5140
+ reasoningEncryptedContent: (_k = value.item.encrypted_content) != null ? _k : null
4928
5141
  }
4929
5142
  }
4930
5143
  });
@@ -4940,6 +5153,38 @@ var OpenAIResponsesLanguageModel = class {
4940
5153
  delta: value.delta
4941
5154
  });
4942
5155
  }
5156
+ } else if (isResponseApplyPatchCallOperationDiffDeltaChunk(value)) {
5157
+ const toolCall = ongoingToolCalls[value.output_index];
5158
+ if (toolCall == null ? void 0 : toolCall.applyPatch) {
5159
+ controller.enqueue({
5160
+ type: "tool-input-delta",
5161
+ id: toolCall.toolCallId,
5162
+ delta: escapeJSONDelta(value.delta)
5163
+ });
5164
+ toolCall.applyPatch.hasDiff = true;
5165
+ }
5166
+ } else if (isResponseApplyPatchCallOperationDiffDoneChunk(value)) {
5167
+ const toolCall = ongoingToolCalls[value.output_index];
5168
+ if ((toolCall == null ? void 0 : toolCall.applyPatch) && !toolCall.applyPatch.endEmitted) {
5169
+ if (!toolCall.applyPatch.hasDiff) {
5170
+ controller.enqueue({
5171
+ type: "tool-input-delta",
5172
+ id: toolCall.toolCallId,
5173
+ delta: escapeJSONDelta(value.diff)
5174
+ });
5175
+ toolCall.applyPatch.hasDiff = true;
5176
+ }
5177
+ controller.enqueue({
5178
+ type: "tool-input-delta",
5179
+ id: toolCall.toolCallId,
5180
+ delta: '"}}'
5181
+ });
5182
+ controller.enqueue({
5183
+ type: "tool-input-end",
5184
+ id: toolCall.toolCallId
5185
+ });
5186
+ toolCall.applyPatch.endEmitted = true;
5187
+ }
4943
5188
  } else if (isResponseImageGenerationCallPartialImageChunk(value)) {
4944
5189
  controller.enqueue({
4945
5190
  type: "tool-result",
@@ -4956,9 +5201,7 @@ var OpenAIResponsesLanguageModel = class {
4956
5201
  controller.enqueue({
4957
5202
  type: "tool-input-delta",
4958
5203
  id: toolCall.toolCallId,
4959
- // The delta is code, which is embedding in a JSON string.
4960
- // To escape it, we use JSON.stringify and slice to remove the outer quotes.
4961
- delta: JSON.stringify(value.delta).slice(1, -1)
5204
+ delta: escapeJSONDelta(value.delta)
4962
5205
  });
4963
5206
  }
4964
5207
  } else if (isResponseCodeInterpreterCallCodeDoneChunk(value)) {
@@ -4998,7 +5241,7 @@ var OpenAIResponsesLanguageModel = class {
4998
5241
  id: value.item_id,
4999
5242
  delta: value.delta
5000
5243
  });
5001
- if (((_f = (_e = options.providerOptions) == null ? void 0 : _e.openai) == null ? void 0 : _f.logprobs) && value.logprobs) {
5244
+ if (((_m = (_l = options.providerOptions) == null ? void 0 : _l.openai) == null ? void 0 : _m.logprobs) && value.logprobs) {
5002
5245
  logprobs.push(value.logprobs);
5003
5246
  }
5004
5247
  } else if (value.type === "response.reasoning_summary_part.added") {
@@ -5025,7 +5268,7 @@ var OpenAIResponsesLanguageModel = class {
5025
5268
  providerMetadata: {
5026
5269
  [providerKey]: {
5027
5270
  itemId: value.item_id,
5028
- reasoningEncryptedContent: (_h = (_g = activeReasoning[value.item_id]) == null ? void 0 : _g.encryptedContent) != null ? _h : null
5271
+ reasoningEncryptedContent: (_o = (_n = activeReasoning[value.item_id]) == null ? void 0 : _n.encryptedContent) != null ? _o : null
5029
5272
  }
5030
5273
  }
5031
5274
  });
@@ -5055,10 +5298,13 @@ var OpenAIResponsesLanguageModel = class {
5055
5298
  activeReasoning[value.item_id].summaryParts[value.summary_index] = "can-conclude";
5056
5299
  }
5057
5300
  } else if (isResponseFinishedChunk(value)) {
5058
- finishReason = mapOpenAIResponseFinishReason({
5059
- finishReason: (_i = value.response.incomplete_details) == null ? void 0 : _i.reason,
5060
- hasFunctionCall
5061
- });
5301
+ finishReason = {
5302
+ unified: mapOpenAIResponseFinishReason({
5303
+ finishReason: (_p = value.response.incomplete_details) == null ? void 0 : _p.reason,
5304
+ hasFunctionCall
5305
+ }),
5306
+ raw: (_r = (_q = value.response.incomplete_details) == null ? void 0 : _q.reason) != null ? _r : void 0
5307
+ };
5062
5308
  usage = value.response.usage;
5063
5309
  if (typeof value.response.service_tier === "string") {
5064
5310
  serviceTier = value.response.service_tier;
@@ -5069,7 +5315,7 @@ var OpenAIResponsesLanguageModel = class {
5069
5315
  controller.enqueue({
5070
5316
  type: "source",
5071
5317
  sourceType: "url",
5072
- id: (_l = (_k = (_j = self.config).generateId) == null ? void 0 : _k.call(_j)) != null ? _l : generateId2(),
5318
+ id: (_u = (_t = (_s = self.config).generateId) == null ? void 0 : _t.call(_s)) != null ? _u : generateId2(),
5073
5319
  url: value.annotation.url,
5074
5320
  title: value.annotation.title
5075
5321
  });
@@ -5077,10 +5323,10 @@ var OpenAIResponsesLanguageModel = class {
5077
5323
  controller.enqueue({
5078
5324
  type: "source",
5079
5325
  sourceType: "document",
5080
- id: (_o = (_n = (_m = self.config).generateId) == null ? void 0 : _n.call(_m)) != null ? _o : generateId2(),
5326
+ id: (_x = (_w = (_v = self.config).generateId) == null ? void 0 : _w.call(_v)) != null ? _x : generateId2(),
5081
5327
  mediaType: "text/plain",
5082
- title: (_q = (_p = value.annotation.quote) != null ? _p : value.annotation.filename) != null ? _q : "Document",
5083
- filename: (_r = value.annotation.filename) != null ? _r : value.annotation.file_id,
5328
+ title: (_z = (_y = value.annotation.quote) != null ? _y : value.annotation.filename) != null ? _z : "Document",
5329
+ filename: (_A = value.annotation.filename) != null ? _A : value.annotation.file_id,
5084
5330
  ...value.annotation.file_id ? {
5085
5331
  providerMetadata: {
5086
5332
  [providerKey]: {
@@ -5093,10 +5339,10 @@ var OpenAIResponsesLanguageModel = class {
5093
5339
  controller.enqueue({
5094
5340
  type: "source",
5095
5341
  sourceType: "document",
5096
- id: (_u = (_t = (_s = self.config).generateId) == null ? void 0 : _t.call(_s)) != null ? _u : generateId2(),
5342
+ id: (_D = (_C = (_B = self.config).generateId) == null ? void 0 : _C.call(_B)) != null ? _D : generateId2(),
5097
5343
  mediaType: "text/plain",
5098
- title: (_w = (_v = value.annotation.filename) != null ? _v : value.annotation.file_id) != null ? _w : "Document",
5099
- filename: (_x = value.annotation.filename) != null ? _x : value.annotation.file_id,
5344
+ title: (_F = (_E = value.annotation.filename) != null ? _E : value.annotation.file_id) != null ? _F : "Document",
5345
+ filename: (_G = value.annotation.filename) != null ? _G : value.annotation.file_id,
5100
5346
  providerMetadata: {
5101
5347
  [providerKey]: {
5102
5348
  fileId: value.annotation.file_id,
@@ -5109,7 +5355,7 @@ var OpenAIResponsesLanguageModel = class {
5109
5355
  controller.enqueue({
5110
5356
  type: "source",
5111
5357
  sourceType: "document",
5112
- id: (_A = (_z = (_y = self.config).generateId) == null ? void 0 : _z.call(_y)) != null ? _A : generateId2(),
5358
+ id: (_J = (_I = (_H = self.config).generateId) == null ? void 0 : _I.call(_H)) != null ? _J : generateId2(),
5113
5359
  mediaType: "application/octet-stream",
5114
5360
  title: value.annotation.file_id,
5115
5361
  filename: value.annotation.file_id,
@@ -5175,6 +5421,12 @@ function isResponseCodeInterpreterCallCodeDeltaChunk(chunk) {
5175
5421
  function isResponseCodeInterpreterCallCodeDoneChunk(chunk) {
5176
5422
  return chunk.type === "response.code_interpreter_call_code.done";
5177
5423
  }
5424
+ function isResponseApplyPatchCallOperationDiffDeltaChunk(chunk) {
5425
+ return chunk.type === "response.apply_patch_call_operation_diff.delta";
5426
+ }
5427
+ function isResponseApplyPatchCallOperationDiffDoneChunk(chunk) {
5428
+ return chunk.type === "response.apply_patch_call_operation_diff.done";
5429
+ }
5178
5430
  function isResponseOutputItemAddedChunk(chunk) {
5179
5431
  return chunk.type === "response.output_item.added";
5180
5432
  }
@@ -5205,6 +5457,9 @@ function mapWebSearchOutput(action) {
5205
5457
  };
5206
5458
  }
5207
5459
  }
5460
+ function escapeJSONDelta(delta) {
5461
+ return JSON.stringify(delta).slice(1, -1);
5462
+ }
5208
5463
 
5209
5464
  // src/speech/openai-speech-model.ts
5210
5465
  import {
@@ -5330,11 +5585,11 @@ var OpenAISpeechModel = class {
5330
5585
  // src/transcription/openai-transcription-model.ts
5331
5586
  import {
5332
5587
  combineHeaders as combineHeaders7,
5333
- convertBase64ToUint8Array,
5588
+ convertBase64ToUint8Array as convertBase64ToUint8Array2,
5334
5589
  createJsonResponseHandler as createJsonResponseHandler6,
5335
5590
  mediaTypeToExtension,
5336
5591
  parseProviderOptions as parseProviderOptions7,
5337
- postFormDataToApi
5592
+ postFormDataToApi as postFormDataToApi2
5338
5593
  } from "@ai-sdk/provider-utils";
5339
5594
 
5340
5595
  // src/transcription/openai-transcription-api.ts
@@ -5484,7 +5739,7 @@ var OpenAITranscriptionModel = class {
5484
5739
  schema: openAITranscriptionProviderOptions
5485
5740
  });
5486
5741
  const formData = new FormData();
5487
- const blob = audio instanceof Uint8Array ? new Blob([audio]) : new Blob([convertBase64ToUint8Array(audio)]);
5742
+ const blob = audio instanceof Uint8Array ? new Blob([audio]) : new Blob([convertBase64ToUint8Array2(audio)]);
5488
5743
  formData.append("model", this.modelId);
5489
5744
  const fileExtension = mediaTypeToExtension(mediaType);
5490
5745
  formData.append(
@@ -5531,7 +5786,7 @@ var OpenAITranscriptionModel = class {
5531
5786
  value: response,
5532
5787
  responseHeaders,
5533
5788
  rawValue: rawResponse
5534
- } = await postFormDataToApi({
5789
+ } = await postFormDataToApi2({
5535
5790
  url: this.config.url({
5536
5791
  path: "/audio/transcriptions",
5537
5792
  modelId: this.modelId
@@ -5571,7 +5826,7 @@ var OpenAITranscriptionModel = class {
5571
5826
  };
5572
5827
 
5573
5828
  // src/version.ts
5574
- var VERSION = true ? "3.0.0-beta.99" : "0.0.0-test";
5829
+ var VERSION = true ? "3.0.1" : "0.0.0-test";
5575
5830
 
5576
5831
  // src/openai-provider.ts
5577
5832
  function createOpenAI(options = {}) {
@@ -5659,6 +5914,8 @@ function createOpenAI(options = {}) {
5659
5914
  provider.responses = createResponsesModel;
5660
5915
  provider.embedding = createEmbeddingModel;
5661
5916
  provider.embeddingModel = createEmbeddingModel;
5917
+ provider.textEmbedding = createEmbeddingModel;
5918
+ provider.textEmbeddingModel = createEmbeddingModel;
5662
5919
  provider.image = createImageModel;
5663
5920
  provider.imageModel = createImageModel;
5664
5921
  provider.transcription = createTranscriptionModel;