@ai-sdk/openai-compatible 3.0.0-beta.16 → 3.0.0-beta.19

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
@@ -15,6 +15,32 @@ import {
15
15
  } from "@ai-sdk/provider-utils";
16
16
  import { z as z3 } from "zod/v4";
17
17
 
18
+ // src/utils/to-camel-case.ts
19
+ function toCamelCase(str) {
20
+ return str.replace(/[_-]([a-z])/g, (g) => g[1].toUpperCase());
21
+ }
22
+ function resolveProviderOptionsKey(rawName, providerOptions) {
23
+ const camelName = toCamelCase(rawName);
24
+ if (camelName !== rawName && (providerOptions == null ? void 0 : providerOptions[camelName]) != null) {
25
+ return camelName;
26
+ }
27
+ return rawName;
28
+ }
29
+ function warnIfDeprecatedProviderOptionsKey({
30
+ rawName,
31
+ providerOptions,
32
+ warnings
33
+ }) {
34
+ const camelName = toCamelCase(rawName);
35
+ if (camelName !== rawName && (providerOptions == null ? void 0 : providerOptions[rawName]) != null) {
36
+ warnings.push({
37
+ type: "deprecated",
38
+ setting: `providerOptions key '${rawName}'`,
39
+ message: `Use '${camelName}' instead.`
40
+ });
41
+ }
42
+ }
43
+
18
44
  // src/openai-compatible-error.ts
19
45
  import { z } from "zod/v4";
20
46
  var openaiCompatibleErrorDataSchema = z.object({
@@ -452,10 +478,16 @@ var OpenAICompatibleChatLanguageModel = class {
452
478
  });
453
479
  if (deprecatedOptions != null) {
454
480
  warnings.push({
455
- type: "other",
456
- message: `The 'openai-compatible' key in providerOptions is deprecated. Use 'openaiCompatible' instead.`
481
+ type: "deprecated",
482
+ setting: "providerOptions key 'openai-compatible'",
483
+ message: "Use 'openaiCompatible' instead."
457
484
  });
458
485
  }
486
+ warnIfDeprecatedProviderOptionsKey({
487
+ rawName: this.providerOptionsName,
488
+ providerOptions,
489
+ warnings
490
+ });
459
491
  const compatibleOptions = Object.assign(
460
492
  deprecatedOptions != null ? deprecatedOptions : {},
461
493
  (_a = await parseProviderOptions({
@@ -467,9 +499,14 @@ var OpenAICompatibleChatLanguageModel = class {
467
499
  provider: this.providerOptionsName,
468
500
  providerOptions,
469
501
  schema: openaiCompatibleLanguageModelChatOptions
470
- })) != null ? _b : {}
502
+ })) != null ? _b : {},
503
+ (_c = await parseProviderOptions({
504
+ provider: toCamelCase(this.providerOptionsName),
505
+ providerOptions,
506
+ schema: openaiCompatibleLanguageModelChatOptions
507
+ })) != null ? _c : {}
471
508
  );
472
- const strictJsonSchema = (_c = compatibleOptions == null ? void 0 : compatibleOptions.strictJsonSchema) != null ? _c : true;
509
+ const strictJsonSchema = (_d = compatibleOptions == null ? void 0 : compatibleOptions.strictJsonSchema) != null ? _d : true;
473
510
  if (topK != null) {
474
511
  warnings.push({ type: "unsupported", feature: "topK" });
475
512
  }
@@ -488,7 +525,12 @@ var OpenAICompatibleChatLanguageModel = class {
488
525
  tools,
489
526
  toolChoice
490
527
  });
528
+ const metadataKey = resolveProviderOptionsKey(
529
+ this.providerOptionsName,
530
+ providerOptions
531
+ );
491
532
  return {
533
+ metadataKey,
492
534
  args: {
493
535
  // model id:
494
536
  model: this.modelId,
@@ -505,16 +547,17 @@ var OpenAICompatibleChatLanguageModel = class {
505
547
  json_schema: {
506
548
  schema: responseFormat.schema,
507
549
  strict: strictJsonSchema,
508
- name: (_d = responseFormat.name) != null ? _d : "response",
550
+ name: (_e = responseFormat.name) != null ? _e : "response",
509
551
  description: responseFormat.description
510
552
  }
511
553
  } : { type: "json_object" } : void 0,
512
554
  stop: stopSequences,
513
555
  seed,
514
556
  ...Object.fromEntries(
515
- Object.entries(
516
- (_e = providerOptions == null ? void 0 : providerOptions[this.providerOptionsName]) != null ? _e : {}
517
- ).filter(
557
+ Object.entries({
558
+ ...providerOptions == null ? void 0 : providerOptions[this.providerOptionsName],
559
+ ...providerOptions == null ? void 0 : providerOptions[toCamelCase(this.providerOptionsName)]
560
+ }).filter(
518
561
  ([key]) => !Object.keys(
519
562
  openaiCompatibleLanguageModelChatOptions.shape
520
563
  ).includes(key)
@@ -533,7 +576,7 @@ var OpenAICompatibleChatLanguageModel = class {
533
576
  }
534
577
  async doGenerate(options) {
535
578
  var _a, _b, _c, _d, _e, _f, _g, _h;
536
- const { args, warnings } = await this.getArgs({ ...options });
579
+ const { args, warnings, metadataKey } = await this.getArgs({ ...options });
537
580
  const transformedBody = this.transformRequestBody(args);
538
581
  const body = JSON.stringify(transformedBody);
539
582
  const {
@@ -577,24 +620,24 @@ var OpenAICompatibleChatLanguageModel = class {
577
620
  input: toolCall.function.arguments,
578
621
  ...thoughtSignature ? {
579
622
  providerMetadata: {
580
- [this.providerOptionsName]: { thoughtSignature }
623
+ [metadataKey]: { thoughtSignature }
581
624
  }
582
625
  } : {}
583
626
  });
584
627
  }
585
628
  }
586
629
  const providerMetadata = {
587
- [this.providerOptionsName]: {},
630
+ [metadataKey]: {},
588
631
  ...await ((_f = (_e = this.config.metadataExtractor) == null ? void 0 : _e.extractMetadata) == null ? void 0 : _f.call(_e, {
589
632
  parsedBody: rawResponse
590
633
  }))
591
634
  };
592
635
  const completionTokenDetails = (_g = responseBody.usage) == null ? void 0 : _g.completion_tokens_details;
593
636
  if ((completionTokenDetails == null ? void 0 : completionTokenDetails.accepted_prediction_tokens) != null) {
594
- providerMetadata[this.providerOptionsName].acceptedPredictionTokens = completionTokenDetails == null ? void 0 : completionTokenDetails.accepted_prediction_tokens;
637
+ providerMetadata[metadataKey].acceptedPredictionTokens = completionTokenDetails == null ? void 0 : completionTokenDetails.accepted_prediction_tokens;
595
638
  }
596
639
  if ((completionTokenDetails == null ? void 0 : completionTokenDetails.rejected_prediction_tokens) != null) {
597
- providerMetadata[this.providerOptionsName].rejectedPredictionTokens = completionTokenDetails == null ? void 0 : completionTokenDetails.rejected_prediction_tokens;
640
+ providerMetadata[metadataKey].rejectedPredictionTokens = completionTokenDetails == null ? void 0 : completionTokenDetails.rejected_prediction_tokens;
598
641
  }
599
642
  return {
600
643
  content,
@@ -615,7 +658,9 @@ var OpenAICompatibleChatLanguageModel = class {
615
658
  }
616
659
  async doStream(options) {
617
660
  var _a;
618
- const { args, warnings } = await this.getArgs({ ...options });
661
+ const { args, warnings, metadataKey } = await this.getArgs({
662
+ ...options
663
+ });
619
664
  const body = this.transformRequestBody({
620
665
  ...args,
621
666
  stream: true,
@@ -644,7 +689,7 @@ var OpenAICompatibleChatLanguageModel = class {
644
689
  };
645
690
  let usage = void 0;
646
691
  let isFirstChunk = true;
647
- const providerOptionsName = this.providerOptionsName;
692
+ const providerOptionsName = metadataKey;
648
693
  let isActiveReasoning = false;
649
694
  let isActiveText = false;
650
695
  return {
@@ -1188,13 +1233,25 @@ var OpenAICompatibleCompletionLanguageModel = class {
1188
1233
  tools,
1189
1234
  toolChoice
1190
1235
  }) {
1191
- var _a;
1236
+ var _a, _b;
1192
1237
  const warnings = [];
1193
- const completionOptions = (_a = await parseProviderOptions2({
1194
- provider: this.providerOptionsName,
1238
+ warnIfDeprecatedProviderOptionsKey({
1239
+ rawName: this.providerOptionsName,
1195
1240
  providerOptions,
1196
- schema: openaiCompatibleLanguageModelCompletionOptions
1197
- })) != null ? _a : {};
1241
+ warnings
1242
+ });
1243
+ const completionOptions = Object.assign(
1244
+ (_a = await parseProviderOptions2({
1245
+ provider: this.providerOptionsName,
1246
+ providerOptions,
1247
+ schema: openaiCompatibleLanguageModelCompletionOptions
1248
+ })) != null ? _a : {},
1249
+ (_b = await parseProviderOptions2({
1250
+ provider: toCamelCase(this.providerOptionsName),
1251
+ providerOptions,
1252
+ schema: openaiCompatibleLanguageModelCompletionOptions
1253
+ })) != null ? _b : {}
1254
+ );
1198
1255
  if (topK != null) {
1199
1256
  warnings.push({ type: "unsupported", feature: "topK" });
1200
1257
  }
@@ -1230,6 +1287,7 @@ var OpenAICompatibleCompletionLanguageModel = class {
1230
1287
  presence_penalty: presencePenalty,
1231
1288
  seed,
1232
1289
  ...providerOptions == null ? void 0 : providerOptions[this.providerOptionsName],
1290
+ ...providerOptions == null ? void 0 : providerOptions[toCamelCase(this.providerOptionsName)],
1233
1291
  // prompt:
1234
1292
  prompt: completionPrompt,
1235
1293
  // stop sequences:
@@ -1473,10 +1531,16 @@ var OpenAICompatibleEmbeddingModel = class {
1473
1531
  });
1474
1532
  if (deprecatedOptions != null) {
1475
1533
  warnings.push({
1476
- type: "other",
1477
- message: `The 'openai-compatible' key in providerOptions is deprecated. Use 'openaiCompatible' instead.`
1534
+ type: "deprecated",
1535
+ setting: "providerOptions key 'openai-compatible'",
1536
+ message: "Use 'openaiCompatible' instead."
1478
1537
  });
1479
1538
  }
1539
+ warnIfDeprecatedProviderOptionsKey({
1540
+ rawName: this.providerOptionsName,
1541
+ providerOptions,
1542
+ warnings
1543
+ });
1480
1544
  const compatibleOptions = Object.assign(
1481
1545
  deprecatedOptions != null ? deprecatedOptions : {},
1482
1546
  (_a = await parseProviderOptions3({
@@ -1567,8 +1631,12 @@ var OpenAICompatibleImageModel = class {
1567
1631
  get providerOptionsKey() {
1568
1632
  return this.config.provider.split(".")[0].trim();
1569
1633
  }
1570
- // TODO: deprecate non-camelCase keys and remove in future major version
1571
- getArgs(providerOptions) {
1634
+ getArgs(providerOptions, warnings) {
1635
+ warnIfDeprecatedProviderOptionsKey({
1636
+ rawName: this.providerOptionsKey,
1637
+ providerOptions,
1638
+ warnings
1639
+ });
1572
1640
  return {
1573
1641
  ...providerOptions[this.providerOptionsKey],
1574
1642
  ...providerOptions[toCamelCase(this.providerOptionsKey)]
@@ -1599,7 +1667,7 @@ var OpenAICompatibleImageModel = class {
1599
1667
  warnings.push({ type: "unsupported", feature: "seed" });
1600
1668
  }
1601
1669
  const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
1602
- const args = this.getArgs(providerOptions);
1670
+ const args = this.getArgs(providerOptions, warnings);
1603
1671
  if (files != null && files.length > 0) {
1604
1672
  const { value: response2, responseHeaders: responseHeaders2 } = await postFormDataToApi({
1605
1673
  url: this.config.url({
@@ -1679,9 +1747,6 @@ async function fileToBlob(file) {
1679
1747
  const data = file.data instanceof Uint8Array ? file.data : convertBase64ToUint8Array2(file.data);
1680
1748
  return new Blob([data], { type: file.mediaType });
1681
1749
  }
1682
- function toCamelCase(str) {
1683
- return str.replace(/[_-]([a-z])/g, (g) => g[1].toUpperCase());
1684
- }
1685
1750
 
1686
1751
  // src/openai-compatible-provider.ts
1687
1752
  import {
@@ -1690,7 +1755,7 @@ import {
1690
1755
  } from "@ai-sdk/provider-utils";
1691
1756
 
1692
1757
  // src/version.ts
1693
- var VERSION = true ? "3.0.0-beta.16" : "0.0.0-test";
1758
+ var VERSION = true ? "3.0.0-beta.19" : "0.0.0-test";
1694
1759
 
1695
1760
  // src/openai-compatible-provider.ts
1696
1761
  function createOpenAICompatible(options) {