@ai-sdk/openai-compatible 2.0.13 → 2.0.14

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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @ai-sdk/openai-compatible
2
2
 
3
+ ## 2.0.14
4
+
5
+ ### Patch Changes
6
+
7
+ - 1612a57: feat(openai-compat): support passing multiple file types
8
+
3
9
  ## 2.0.13
4
10
 
5
11
  ### Patch Changes
package/dist/index.js CHANGED
@@ -98,6 +98,17 @@ function getOpenAIMetadata(message) {
98
98
  var _a, _b;
99
99
  return (_b = (_a = message == null ? void 0 : message.providerOptions) == null ? void 0 : _a.openaiCompatible) != null ? _b : {};
100
100
  }
101
+ function getAudioFormat(mediaType) {
102
+ switch (mediaType) {
103
+ case "audio/wav":
104
+ return "wav";
105
+ case "audio/mp3":
106
+ case "audio/mpeg":
107
+ return "mp3";
108
+ default:
109
+ return null;
110
+ }
111
+ }
101
112
  function convertToOpenAICompatibleChatMessages(prompt) {
102
113
  var _a, _b, _c;
103
114
  const messages = [];
@@ -120,6 +131,7 @@ function convertToOpenAICompatibleChatMessages(prompt) {
120
131
  messages.push({
121
132
  role: "user",
122
133
  content: content.map((part) => {
134
+ var _a2;
123
135
  const partMetadata = getOpenAIMetadata(part);
124
136
  switch (part.type) {
125
137
  case "text": {
@@ -135,11 +147,54 @@ function convertToOpenAICompatibleChatMessages(prompt) {
135
147
  },
136
148
  ...partMetadata
137
149
  };
138
- } else {
139
- throw new import_provider.UnsupportedFunctionalityError({
140
- functionality: `file part media type ${part.mediaType}`
141
- });
142
150
  }
151
+ if (part.mediaType.startsWith("audio/")) {
152
+ if (part.data instanceof URL) {
153
+ throw new import_provider.UnsupportedFunctionalityError({
154
+ functionality: "audio file parts with URLs"
155
+ });
156
+ }
157
+ const format = getAudioFormat(part.mediaType);
158
+ if (format === null) {
159
+ throw new import_provider.UnsupportedFunctionalityError({
160
+ functionality: `audio media type ${part.mediaType}`
161
+ });
162
+ }
163
+ return {
164
+ type: "input_audio",
165
+ input_audio: {
166
+ data: (0, import_provider_utils.convertToBase64)(part.data),
167
+ format
168
+ },
169
+ ...partMetadata
170
+ };
171
+ }
172
+ if (part.mediaType === "application/pdf") {
173
+ if (part.data instanceof URL) {
174
+ throw new import_provider.UnsupportedFunctionalityError({
175
+ functionality: "PDF file parts with URLs"
176
+ });
177
+ }
178
+ return {
179
+ type: "file",
180
+ file: {
181
+ filename: (_a2 = part.filename) != null ? _a2 : "document.pdf",
182
+ file_data: `data:application/pdf;base64,${(0, import_provider_utils.convertToBase64)(part.data)}`
183
+ },
184
+ ...partMetadata
185
+ };
186
+ }
187
+ if (part.mediaType.startsWith("text/")) {
188
+ const textContent = part.data instanceof URL ? part.data.toString() : typeof part.data === "string" ? part.data : new TextDecoder().decode(part.data);
189
+ return {
190
+ type: "text",
191
+ text: textContent,
192
+ ...partMetadata
193
+ };
194
+ }
195
+ throw new import_provider.UnsupportedFunctionalityError({
196
+ functionality: `file part media type ${part.mediaType}`
197
+ });
143
198
  }
144
199
  }
145
200
  }),
@@ -1558,7 +1613,7 @@ async function fileToBlob(file) {
1558
1613
  var import_provider_utils6 = require("@ai-sdk/provider-utils");
1559
1614
 
1560
1615
  // src/version.ts
1561
- var VERSION = true ? "2.0.13" : "0.0.0-test";
1616
+ var VERSION = true ? "2.0.14" : "0.0.0-test";
1562
1617
 
1563
1618
  // src/openai-compatible-provider.ts
1564
1619
  function createOpenAICompatible(options) {