@ai-sdk/openai-compatible 3.0.0-beta.33 → 3.0.0-beta.35

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.
Files changed (27) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/dist/index.d.ts +1 -1
  3. package/dist/index.js +77 -59
  4. package/dist/index.js.map +1 -1
  5. package/dist/internal/index.js +73 -55
  6. package/dist/internal/index.js.map +1 -1
  7. package/package.json +4 -4
  8. package/src/chat/convert-openai-compatible-chat-usage.ts +1 -1
  9. package/src/chat/convert-to-openai-compatible-chat-messages.ts +92 -78
  10. package/src/chat/map-openai-compatible-finish-reason.ts +1 -1
  11. package/src/chat/openai-compatible-api-types.ts +1 -1
  12. package/src/chat/openai-compatible-chat-language-model.ts +9 -9
  13. package/src/chat/openai-compatible-metadata-extractor.ts +1 -1
  14. package/src/chat/openai-compatible-prepare-tools.ts +2 -3
  15. package/src/completion/convert-openai-compatible-completion-usage.ts +1 -1
  16. package/src/completion/convert-to-openai-compatible-completion-prompt.ts +1 -2
  17. package/src/completion/map-openai-compatible-finish-reason.ts +1 -1
  18. package/src/completion/openai-compatible-completion-language-model.ts +7 -8
  19. package/src/embedding/openai-compatible-embedding-model.ts +6 -6
  20. package/src/image/openai-compatible-image-model.ts +4 -4
  21. package/src/index.ts +3 -3
  22. package/src/openai-compatible-error.ts +1 -2
  23. package/src/openai-compatible-provider.ts +5 -5
  24. package/src/utils/to-camel-case.ts +1 -1
  25. /package/src/chat/{openai-compatible-chat-options.ts → openai-compatible-chat-language-model-options.ts} +0 -0
  26. /package/src/completion/{openai-compatible-completion-options.ts → openai-compatible-completion-language-model-options.ts} +0 -0
  27. /package/src/embedding/{openai-compatible-embedding-options.ts → openai-compatible-embedding-model-options.ts} +0 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,30 @@
1
1
  # @ai-sdk/openai-compatible
2
2
 
3
+ ## 3.0.0-beta.35
4
+
5
+ ### Major Changes
6
+
7
+ - 04e9009: chore: make provider implementations code patterns more consistent, including renaming certain exported symbols
8
+
9
+ For all externally exported symbols that were renamed, the old names continue to work via deprecated aliases.
10
+
11
+ ### Patch Changes
12
+
13
+ - Updated dependencies [08d2129]
14
+ - @ai-sdk/provider-utils@5.0.0-beta.30
15
+
16
+ ## 3.0.0-beta.34
17
+
18
+ ### Patch Changes
19
+
20
+ - 9bd6512: feat(provider): change file part data property to be tagged with a type and remove the image part type
21
+ - 258c093: chore: ensure consistent import handling and avoid import duplicates or cycles
22
+ - Updated dependencies [9bd6512]
23
+ - Updated dependencies [258c093]
24
+ - Updated dependencies [b6783da]
25
+ - @ai-sdk/provider-utils@5.0.0-beta.29
26
+ - @ai-sdk/provider@4.0.0-beta.14
27
+
3
28
  ## 3.0.0-beta.33
4
29
 
5
30
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -251,7 +251,7 @@ declare class OpenAICompatibleImageModel implements ImageModelV4 {
251
251
  doGenerate({ prompt, n, size, aspectRatio, seed, providerOptions, headers, abortSignal, files, mask, }: Parameters<ImageModelV4['doGenerate']>[0]): Promise<Awaited<ReturnType<ImageModelV4['doGenerate']>>>;
252
252
  }
253
253
 
254
- interface OpenAICompatibleProvider<CHAT_MODEL_IDS extends string = string, COMPLETION_MODEL_IDS extends string = string, EMBEDDING_MODEL_IDS extends string = string, IMAGE_MODEL_IDS extends string = string> extends Omit<ProviderV4, 'imageModel'> {
254
+ interface OpenAICompatibleProvider<CHAT_MODEL_IDS extends string = string, COMPLETION_MODEL_IDS extends string = string, EMBEDDING_MODEL_IDS extends string = string, IMAGE_MODEL_IDS extends string = string> extends ProviderV4 {
255
255
  (modelId: CHAT_MODEL_IDS): LanguageModelV4;
256
256
  languageModel(modelId: CHAT_MODEL_IDS, config?: Partial<OpenAICompatibleChatConfig>): LanguageModelV4;
257
257
  chatModel(modelId: CHAT_MODEL_IDS): LanguageModelV4;
package/dist/index.js CHANGED
@@ -105,7 +105,8 @@ import {
105
105
  import {
106
106
  convertBase64ToUint8Array,
107
107
  convertToBase64,
108
- isProviderReference
108
+ getTopLevelMediaType,
109
+ resolveFullMediaType
109
110
  } from "@ai-sdk/provider-utils";
110
111
  function getOpenAIMetadata(message) {
111
112
  var _a, _b;
@@ -151,70 +152,87 @@ function convertToOpenAICompatibleChatMessages(prompt) {
151
152
  return { type: "text", text: part.text, ...partMetadata };
152
153
  }
153
154
  case "file": {
154
- if (isProviderReference(part.data)) {
155
- throw new UnsupportedFunctionalityError({
156
- functionality: "file parts with provider references"
157
- });
158
- }
159
- if (part.mediaType.startsWith("image/")) {
160
- const mediaType = part.mediaType === "image/*" ? "image/jpeg" : part.mediaType;
161
- return {
162
- type: "image_url",
163
- image_url: {
164
- url: part.data instanceof URL ? part.data.toString() : `data:${mediaType};base64,${convertToBase64(part.data)}`
165
- },
166
- ...partMetadata
167
- };
168
- }
169
- if (part.mediaType.startsWith("audio/")) {
170
- if (part.data instanceof URL) {
155
+ switch (part.data.type) {
156
+ case "reference": {
171
157
  throw new UnsupportedFunctionalityError({
172
- functionality: "audio file parts with URLs"
158
+ functionality: "file parts with provider references"
173
159
  });
174
160
  }
175
- const format = getAudioFormat(part.mediaType);
176
- if (format === null) {
161
+ case "text": {
177
162
  throw new UnsupportedFunctionalityError({
178
- functionality: `audio media type ${part.mediaType}`
163
+ functionality: "text file parts"
179
164
  });
180
165
  }
181
- return {
182
- type: "input_audio",
183
- input_audio: {
184
- data: convertToBase64(part.data),
185
- format
186
- },
187
- ...partMetadata
188
- };
189
- }
190
- if (part.mediaType === "application/pdf") {
191
- if (part.data instanceof URL) {
166
+ case "url":
167
+ case "data": {
168
+ const topLevel = getTopLevelMediaType(part.mediaType);
169
+ if (topLevel === "image") {
170
+ return {
171
+ type: "image_url",
172
+ image_url: {
173
+ url: part.data.type === "url" ? part.data.url.toString() : `data:${resolveFullMediaType({ part })};base64,${convertToBase64(part.data.data)}`
174
+ },
175
+ ...partMetadata
176
+ };
177
+ }
178
+ if (topLevel === "audio") {
179
+ if (part.data.type === "url") {
180
+ throw new UnsupportedFunctionalityError({
181
+ functionality: "audio file parts with URLs"
182
+ });
183
+ }
184
+ const fullMediaType = resolveFullMediaType({ part });
185
+ const format = getAudioFormat(fullMediaType);
186
+ if (format === null) {
187
+ throw new UnsupportedFunctionalityError({
188
+ functionality: `audio media type ${fullMediaType}`
189
+ });
190
+ }
191
+ return {
192
+ type: "input_audio",
193
+ input_audio: {
194
+ data: convertToBase64(part.data.data),
195
+ format
196
+ },
197
+ ...partMetadata
198
+ };
199
+ }
200
+ if (topLevel === "application") {
201
+ if (part.data.type === "url") {
202
+ throw new UnsupportedFunctionalityError({
203
+ functionality: "PDF file parts with URLs"
204
+ });
205
+ }
206
+ const fullMediaType = resolveFullMediaType({ part });
207
+ if (fullMediaType !== "application/pdf") {
208
+ throw new UnsupportedFunctionalityError({
209
+ functionality: `file part media type ${fullMediaType}`
210
+ });
211
+ }
212
+ return {
213
+ type: "file",
214
+ file: {
215
+ filename: (_a2 = part.filename) != null ? _a2 : "document.pdf",
216
+ file_data: `data:application/pdf;base64,${convertToBase64(part.data.data)}`
217
+ },
218
+ ...partMetadata
219
+ };
220
+ }
221
+ if (topLevel === "text") {
222
+ const textContent = part.data.type === "url" ? part.data.url.toString() : typeof part.data.data === "string" ? new TextDecoder().decode(
223
+ convertBase64ToUint8Array(part.data.data)
224
+ ) : new TextDecoder().decode(part.data.data);
225
+ return {
226
+ type: "text",
227
+ text: textContent,
228
+ ...partMetadata
229
+ };
230
+ }
192
231
  throw new UnsupportedFunctionalityError({
193
- functionality: "PDF file parts with URLs"
232
+ functionality: `file part media type ${part.mediaType}`
194
233
  });
195
234
  }
196
- return {
197
- type: "file",
198
- file: {
199
- filename: (_a2 = part.filename) != null ? _a2 : "document.pdf",
200
- file_data: `data:application/pdf;base64,${convertToBase64(part.data)}`
201
- },
202
- ...partMetadata
203
- };
204
235
  }
205
- if (part.mediaType.startsWith("text/")) {
206
- const textContent = part.data instanceof URL ? part.data.toString() : typeof part.data === "string" ? new TextDecoder().decode(
207
- convertBase64ToUint8Array(part.data)
208
- ) : new TextDecoder().decode(part.data);
209
- return {
210
- type: "text",
211
- text: textContent,
212
- ...partMetadata
213
- };
214
- }
215
- throw new UnsupportedFunctionalityError({
216
- functionality: `file part media type ${part.mediaType}`
217
- });
218
236
  }
219
237
  }
220
238
  }),
@@ -339,7 +357,7 @@ function mapOpenAICompatibleFinishReason(finishReason) {
339
357
  }
340
358
  }
341
359
 
342
- // src/chat/openai-compatible-chat-options.ts
360
+ // src/chat/openai-compatible-chat-language-model-options.ts
343
361
  import { z as z2 } from "zod/v4";
344
362
  var openaiCompatibleLanguageModelChatOptions = z2.object({
345
363
  /**
@@ -1137,7 +1155,7 @@ function mapOpenAICompatibleFinishReason2(finishReason) {
1137
1155
  }
1138
1156
  }
1139
1157
 
1140
- // src/completion/openai-compatible-completion-options.ts
1158
+ // src/completion/openai-compatible-completion-language-model-options.ts
1141
1159
  import { z as z4 } from "zod/v4";
1142
1160
  var openaiCompatibleLanguageModelCompletionOptions = z4.object({
1143
1161
  /**
@@ -1465,7 +1483,7 @@ import {
1465
1483
  } from "@ai-sdk/provider-utils";
1466
1484
  import { z as z7 } from "zod/v4";
1467
1485
 
1468
- // src/embedding/openai-compatible-embedding-options.ts
1486
+ // src/embedding/openai-compatible-embedding-model-options.ts
1469
1487
  import { z as z6 } from "zod/v4";
1470
1488
  var openaiCompatibleEmbeddingModelOptions = z6.object({
1471
1489
  /**
@@ -1761,7 +1779,7 @@ import {
1761
1779
  } from "@ai-sdk/provider-utils";
1762
1780
 
1763
1781
  // src/version.ts
1764
- var VERSION = true ? "3.0.0-beta.33" : "0.0.0-test";
1782
+ var VERSION = true ? "3.0.0-beta.35" : "0.0.0-test";
1765
1783
 
1766
1784
  // src/openai-compatible-provider.ts
1767
1785
  function createOpenAICompatible(options) {