@ai-sdk/openai 4.0.0-beta.20 → 4.0.0-beta.21

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.
@@ -91,7 +91,11 @@ function convertOpenAIChatUsage(usage) {
91
91
  import {
92
92
  UnsupportedFunctionalityError
93
93
  } from "@ai-sdk/provider";
94
- import { convertToBase64 } from "@ai-sdk/provider-utils";
94
+ import {
95
+ convertToBase64,
96
+ isProviderReference,
97
+ resolveProviderReference
98
+ } from "@ai-sdk/provider-utils";
95
99
  function convertToOpenAIChatMessages({
96
100
  prompt,
97
101
  systemMessageMode = "system"
@@ -141,13 +145,23 @@ function convertToOpenAIChatMessages({
141
145
  return { type: "text", text: part.text };
142
146
  }
143
147
  case "file": {
148
+ if (isProviderReference(part.data)) {
149
+ return {
150
+ type: "file",
151
+ file: {
152
+ file_id: resolveProviderReference({
153
+ reference: part.data,
154
+ provider: "openai"
155
+ })
156
+ }
157
+ };
158
+ }
144
159
  if (part.mediaType.startsWith("image/")) {
145
160
  const mediaType = part.mediaType === "image/*" ? "image/jpeg" : part.mediaType;
146
161
  return {
147
162
  type: "image_url",
148
163
  image_url: {
149
164
  url: part.data instanceof URL ? part.data.toString() : `data:${mediaType};base64,${convertToBase64(part.data)}`,
150
- // OpenAI specific extension: image detail
151
165
  detail: (_b = (_a2 = part.providerOptions) == null ? void 0 : _a2.openai) == null ? void 0 : _b.imageDetail
152
166
  }
153
167
  };
@@ -191,7 +205,7 @@ function convertToOpenAIChatMessages({
191
205
  }
192
206
  return {
193
207
  type: "file",
194
- file: typeof part.data === "string" && part.data.startsWith("file-") ? { file_id: part.data } : {
208
+ file: {
195
209
  filename: (_c = part.filename) != null ? _c : `part-${index}.pdf`,
196
210
  file_data: `data:application/pdf;base64,${convertToBase64(part.data)}`
197
211
  }
@@ -2392,8 +2406,10 @@ import {
2392
2406
  import {
2393
2407
  convertToBase64 as convertToBase642,
2394
2408
  isNonNullable,
2409
+ isProviderReference as isProviderReference2,
2395
2410
  parseJSON,
2396
2411
  parseProviderOptions as parseProviderOptions6,
2412
+ resolveProviderReference as resolveProviderReference2,
2397
2413
  validateTypes
2398
2414
  } from "@ai-sdk/provider-utils";
2399
2415
  import { z as z16 } from "zod/v4";
@@ -2666,12 +2682,29 @@ async function convertToOpenAIResponsesInput({
2666
2682
  input.push({
2667
2683
  role: "user",
2668
2684
  content: content.map((part, index) => {
2669
- var _a2, _b2, _c2;
2685
+ var _a2, _b2, _c2, _d2, _e2;
2670
2686
  switch (part.type) {
2671
2687
  case "text": {
2672
2688
  return { type: "input_text", text: part.text };
2673
2689
  }
2674
2690
  case "file": {
2691
+ if (isProviderReference2(part.data)) {
2692
+ const fileId = resolveProviderReference2({
2693
+ reference: part.data,
2694
+ provider: providerOptionsName
2695
+ });
2696
+ if (part.mediaType.startsWith("image/")) {
2697
+ return {
2698
+ type: "input_image",
2699
+ file_id: fileId,
2700
+ detail: (_b2 = (_a2 = part.providerOptions) == null ? void 0 : _a2[providerOptionsName]) == null ? void 0 : _b2.imageDetail
2701
+ };
2702
+ }
2703
+ return {
2704
+ type: "input_file",
2705
+ file_id: fileId
2706
+ };
2707
+ }
2675
2708
  if (part.mediaType.startsWith("image/")) {
2676
2709
  const mediaType = part.mediaType === "image/*" ? "image/jpeg" : part.mediaType;
2677
2710
  return {
@@ -2679,7 +2712,7 @@ async function convertToOpenAIResponsesInput({
2679
2712
  ...part.data instanceof URL ? { image_url: part.data.toString() } : typeof part.data === "string" && isFileId(part.data, fileIdPrefixes) ? { file_id: part.data } : {
2680
2713
  image_url: `data:${mediaType};base64,${convertToBase642(part.data)}`
2681
2714
  },
2682
- detail: (_b2 = (_a2 = part.providerOptions) == null ? void 0 : _a2[providerOptionsName]) == null ? void 0 : _b2.imageDetail
2715
+ detail: (_d2 = (_c2 = part.providerOptions) == null ? void 0 : _c2[providerOptionsName]) == null ? void 0 : _d2.imageDetail
2683
2716
  };
2684
2717
  } else if (part.mediaType === "application/pdf") {
2685
2718
  if (part.data instanceof URL) {
@@ -2691,7 +2724,7 @@ async function convertToOpenAIResponsesInput({
2691
2724
  return {
2692
2725
  type: "input_file",
2693
2726
  ...typeof part.data === "string" && isFileId(part.data, fileIdPrefixes) ? { file_id: part.data } : {
2694
- filename: (_c2 = part.filename) != null ? _c2 : `part-${index}.pdf`,
2727
+ filename: (_e2 = part.filename) != null ? _e2 : `part-${index}.pdf`,
2695
2728
  file_data: `data:application/pdf;base64,${convertToBase642(part.data)}`
2696
2729
  }
2697
2730
  };