@ai-sdk/openai-compatible 2.0.14 → 2.0.16

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,17 @@
1
1
  # @ai-sdk/openai-compatible
2
2
 
3
+ ## 2.0.16
4
+
5
+ ### Patch Changes
6
+
7
+ - 78555ad: fix(openai-compatible): Accept non-OpenAI provider options
8
+
9
+ ## 2.0.15
10
+
11
+ ### Patch Changes
12
+
13
+ - 7116ef3: Use consistent camelCase `openaiCompatible` key for providerOptions. The kebab-case `openai-compatible` key is now deprecated but still supported with a console warning.
14
+
3
15
  ## 2.0.14
4
16
 
5
17
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -209,7 +209,12 @@ declare class OpenAICompatibleImageModel implements ImageModelV3 {
209
209
  readonly specificationVersion = "v3";
210
210
  readonly maxImagesPerCall = 10;
211
211
  get provider(): string;
212
+ /**
213
+ * The provider options key used to extract provider-specific options.
214
+ */
215
+ private get providerOptionsKey();
212
216
  constructor(modelId: OpenAICompatibleImageModelId, config: OpenAICompatibleImageModelConfig);
217
+ private getArgs;
213
218
  doGenerate({ prompt, n, size, aspectRatio, seed, providerOptions, headers, abortSignal, files, mask, }: Parameters<ImageModelV3['doGenerate']>[0]): Promise<Awaited<ReturnType<ImageModelV3['doGenerate']>>>;
214
219
  }
215
220
 
package/dist/index.d.ts CHANGED
@@ -209,7 +209,12 @@ declare class OpenAICompatibleImageModel implements ImageModelV3 {
209
209
  readonly specificationVersion = "v3";
210
210
  readonly maxImagesPerCall = 10;
211
211
  get provider(): string;
212
+ /**
213
+ * The provider options key used to extract provider-specific options.
214
+ */
215
+ private get providerOptionsKey();
212
216
  constructor(modelId: OpenAICompatibleImageModelId, config: OpenAICompatibleImageModelConfig);
217
+ private getArgs;
213
218
  doGenerate({ prompt, n, size, aspectRatio, seed, providerOptions, headers, abortSignal, files, mask, }: Parameters<ImageModelV3['doGenerate']>[0]): Promise<Awaited<ReturnType<ImageModelV3['doGenerate']>>>;
214
219
  }
215
220
 
package/dist/index.js CHANGED
@@ -442,9 +442,21 @@ var OpenAICompatibleChatLanguageModel = class {
442
442
  }) {
443
443
  var _a, _b, _c, _d, _e;
444
444
  const warnings = [];
445
+ const deprecatedOptions = await (0, import_provider_utils2.parseProviderOptions)({
446
+ provider: "openai-compatible",
447
+ providerOptions,
448
+ schema: openaiCompatibleProviderOptions
449
+ });
450
+ if (deprecatedOptions != null) {
451
+ warnings.push({
452
+ type: "other",
453
+ message: `The 'openai-compatible' key in providerOptions is deprecated. Use 'openaiCompatible' instead.`
454
+ });
455
+ }
445
456
  const compatibleOptions = Object.assign(
457
+ deprecatedOptions != null ? deprecatedOptions : {},
446
458
  (_a = await (0, import_provider_utils2.parseProviderOptions)({
447
- provider: "openai-compatible",
459
+ provider: "openaiCompatible",
448
460
  providerOptions,
449
461
  schema: openaiCompatibleProviderOptions
450
462
  })) != null ? _a : {},
@@ -1430,9 +1442,22 @@ var OpenAICompatibleEmbeddingModel = class {
1430
1442
  providerOptions
1431
1443
  }) {
1432
1444
  var _a, _b, _c;
1445
+ const warnings = [];
1446
+ const deprecatedOptions = await (0, import_provider_utils4.parseProviderOptions)({
1447
+ provider: "openai-compatible",
1448
+ providerOptions,
1449
+ schema: openaiCompatibleEmbeddingProviderOptions
1450
+ });
1451
+ if (deprecatedOptions != null) {
1452
+ warnings.push({
1453
+ type: "other",
1454
+ message: `The 'openai-compatible' key in providerOptions is deprecated. Use 'openaiCompatible' instead.`
1455
+ });
1456
+ }
1433
1457
  const compatibleOptions = Object.assign(
1458
+ deprecatedOptions != null ? deprecatedOptions : {},
1434
1459
  (_a = await (0, import_provider_utils4.parseProviderOptions)({
1435
- provider: "openai-compatible",
1460
+ provider: "openaiCompatible",
1436
1461
  providerOptions,
1437
1462
  schema: openaiCompatibleEmbeddingProviderOptions
1438
1463
  })) != null ? _a : {},
@@ -1477,7 +1502,7 @@ var OpenAICompatibleEmbeddingModel = class {
1477
1502
  fetch: this.config.fetch
1478
1503
  });
1479
1504
  return {
1480
- warnings: [],
1505
+ warnings,
1481
1506
  embeddings: response.data.map((item) => item.embedding),
1482
1507
  usage: response.usage ? { tokens: response.usage.prompt_tokens } : void 0,
1483
1508
  providerMetadata: response.providerMetadata,
@@ -1504,6 +1529,19 @@ var OpenAICompatibleImageModel = class {
1504
1529
  get provider() {
1505
1530
  return this.config.provider;
1506
1531
  }
1532
+ /**
1533
+ * The provider options key used to extract provider-specific options.
1534
+ */
1535
+ get providerOptionsKey() {
1536
+ return this.config.provider.split(".")[0].trim();
1537
+ }
1538
+ // TODO: deprecate non-camelCase keys and remove in future major version
1539
+ getArgs(providerOptions) {
1540
+ return {
1541
+ ...providerOptions[this.providerOptionsKey],
1542
+ ...providerOptions[toCamelCase(this.providerOptionsKey)]
1543
+ };
1544
+ }
1507
1545
  async doGenerate({
1508
1546
  prompt,
1509
1547
  n,
@@ -1516,7 +1554,7 @@ var OpenAICompatibleImageModel = class {
1516
1554
  files,
1517
1555
  mask
1518
1556
  }) {
1519
- var _a, _b, _c, _d, _e, _f, _g;
1557
+ var _a, _b, _c, _d, _e;
1520
1558
  const warnings = [];
1521
1559
  if (aspectRatio != null) {
1522
1560
  warnings.push({
@@ -1529,6 +1567,7 @@ var OpenAICompatibleImageModel = class {
1529
1567
  warnings.push({ type: "unsupported", feature: "seed" });
1530
1568
  }
1531
1569
  const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
1570
+ const args = this.getArgs(providerOptions);
1532
1571
  if (files != null && files.length > 0) {
1533
1572
  const { value: response2, responseHeaders: responseHeaders2 } = await (0, import_provider_utils5.postFormDataToApi)({
1534
1573
  url: this.config.url({
@@ -1543,10 +1582,10 @@ var OpenAICompatibleImageModel = class {
1543
1582
  mask: mask != null ? await fileToBlob(mask) : void 0,
1544
1583
  n,
1545
1584
  size,
1546
- ...(_d = providerOptions.openai) != null ? _d : {}
1585
+ ...args
1547
1586
  }),
1548
1587
  failedResponseHandler: (0, import_provider_utils5.createJsonErrorResponseHandler)(
1549
- (_e = this.config.errorStructure) != null ? _e : defaultOpenAICompatibleErrorStructure
1588
+ (_d = this.config.errorStructure) != null ? _d : defaultOpenAICompatibleErrorStructure
1550
1589
  ),
1551
1590
  successfulResponseHandler: (0, import_provider_utils5.createJsonResponseHandler)(
1552
1591
  openaiCompatibleImageResponseSchema
@@ -1575,11 +1614,11 @@ var OpenAICompatibleImageModel = class {
1575
1614
  prompt,
1576
1615
  n,
1577
1616
  size,
1578
- ...(_f = providerOptions.openai) != null ? _f : {},
1617
+ ...args,
1579
1618
  response_format: "b64_json"
1580
1619
  },
1581
1620
  failedResponseHandler: (0, import_provider_utils5.createJsonErrorResponseHandler)(
1582
- (_g = this.config.errorStructure) != null ? _g : defaultOpenAICompatibleErrorStructure
1621
+ (_e = this.config.errorStructure) != null ? _e : defaultOpenAICompatibleErrorStructure
1583
1622
  ),
1584
1623
  successfulResponseHandler: (0, import_provider_utils5.createJsonResponseHandler)(
1585
1624
  openaiCompatibleImageResponseSchema
@@ -1608,12 +1647,15 @@ async function fileToBlob(file) {
1608
1647
  const data = file.data instanceof Uint8Array ? file.data : (0, import_provider_utils5.convertBase64ToUint8Array)(file.data);
1609
1648
  return new Blob([data], { type: file.mediaType });
1610
1649
  }
1650
+ function toCamelCase(str) {
1651
+ return str.replace(/[_-]([a-z])/g, (g) => g[1].toUpperCase());
1652
+ }
1611
1653
 
1612
1654
  // src/openai-compatible-provider.ts
1613
1655
  var import_provider_utils6 = require("@ai-sdk/provider-utils");
1614
1656
 
1615
1657
  // src/version.ts
1616
- var VERSION = true ? "2.0.14" : "0.0.0-test";
1658
+ var VERSION = true ? "2.0.16" : "0.0.0-test";
1617
1659
 
1618
1660
  // src/openai-compatible-provider.ts
1619
1661
  function createOpenAICompatible(options) {