@ai-sdk/openai-compatible 2.0.39 → 2.0.41

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
@@ -14,6 +14,18 @@ import {
14
14
  } from "@ai-sdk/provider-utils";
15
15
  import { z as z3 } from "zod/v4";
16
16
 
17
+ // src/utils/to-camel-case.ts
18
+ function toCamelCase(str) {
19
+ return str.replace(/[_-]([a-z])/g, (g) => g[1].toUpperCase());
20
+ }
21
+ function resolveProviderOptionsKey(rawName, providerOptions) {
22
+ const camelName = toCamelCase(rawName);
23
+ if (camelName !== rawName && (providerOptions == null ? void 0 : providerOptions[camelName]) != null) {
24
+ return camelName;
25
+ }
26
+ return rawName;
27
+ }
28
+
17
29
  // src/openai-compatible-error.ts
18
30
  import { z } from "zod/v4";
19
31
  var openaiCompatibleErrorDataSchema = z.object({
@@ -459,9 +471,14 @@ var OpenAICompatibleChatLanguageModel = class {
459
471
  provider: this.providerOptionsName,
460
472
  providerOptions,
461
473
  schema: openaiCompatibleLanguageModelChatOptions
462
- })) != null ? _b : {}
474
+ })) != null ? _b : {},
475
+ (_c = await parseProviderOptions({
476
+ provider: toCamelCase(this.providerOptionsName),
477
+ providerOptions,
478
+ schema: openaiCompatibleLanguageModelChatOptions
479
+ })) != null ? _c : {}
463
480
  );
464
- const strictJsonSchema = (_c = compatibleOptions == null ? void 0 : compatibleOptions.strictJsonSchema) != null ? _c : true;
481
+ const strictJsonSchema = (_d = compatibleOptions == null ? void 0 : compatibleOptions.strictJsonSchema) != null ? _d : true;
465
482
  if (topK != null) {
466
483
  warnings.push({ type: "unsupported", feature: "topK" });
467
484
  }
@@ -480,7 +497,12 @@ var OpenAICompatibleChatLanguageModel = class {
480
497
  tools,
481
498
  toolChoice
482
499
  });
500
+ const metadataKey = resolveProviderOptionsKey(
501
+ this.providerOptionsName,
502
+ providerOptions
503
+ );
483
504
  return {
505
+ metadataKey,
484
506
  args: {
485
507
  // model id:
486
508
  model: this.modelId,
@@ -497,16 +519,17 @@ var OpenAICompatibleChatLanguageModel = class {
497
519
  json_schema: {
498
520
  schema: responseFormat.schema,
499
521
  strict: strictJsonSchema,
500
- name: (_d = responseFormat.name) != null ? _d : "response",
522
+ name: (_e = responseFormat.name) != null ? _e : "response",
501
523
  description: responseFormat.description
502
524
  }
503
525
  } : { type: "json_object" } : void 0,
504
526
  stop: stopSequences,
505
527
  seed,
506
528
  ...Object.fromEntries(
507
- Object.entries(
508
- (_e = providerOptions == null ? void 0 : providerOptions[this.providerOptionsName]) != null ? _e : {}
509
- ).filter(
529
+ Object.entries({
530
+ ...providerOptions == null ? void 0 : providerOptions[this.providerOptionsName],
531
+ ...providerOptions == null ? void 0 : providerOptions[toCamelCase(this.providerOptionsName)]
532
+ }).filter(
510
533
  ([key]) => !Object.keys(
511
534
  openaiCompatibleLanguageModelChatOptions.shape
512
535
  ).includes(key)
@@ -525,7 +548,7 @@ var OpenAICompatibleChatLanguageModel = class {
525
548
  }
526
549
  async doGenerate(options) {
527
550
  var _a, _b, _c, _d, _e, _f, _g, _h;
528
- const { args, warnings } = await this.getArgs({ ...options });
551
+ const { args, warnings, metadataKey } = await this.getArgs({ ...options });
529
552
  const transformedBody = this.transformRequestBody(args);
530
553
  const body = JSON.stringify(transformedBody);
531
554
  const {
@@ -569,24 +592,24 @@ var OpenAICompatibleChatLanguageModel = class {
569
592
  input: toolCall.function.arguments,
570
593
  ...thoughtSignature ? {
571
594
  providerMetadata: {
572
- [this.providerOptionsName]: { thoughtSignature }
595
+ [metadataKey]: { thoughtSignature }
573
596
  }
574
597
  } : {}
575
598
  });
576
599
  }
577
600
  }
578
601
  const providerMetadata = {
579
- [this.providerOptionsName]: {},
602
+ [metadataKey]: {},
580
603
  ...await ((_f = (_e = this.config.metadataExtractor) == null ? void 0 : _e.extractMetadata) == null ? void 0 : _f.call(_e, {
581
604
  parsedBody: rawResponse
582
605
  }))
583
606
  };
584
607
  const completionTokenDetails = (_g = responseBody.usage) == null ? void 0 : _g.completion_tokens_details;
585
608
  if ((completionTokenDetails == null ? void 0 : completionTokenDetails.accepted_prediction_tokens) != null) {
586
- providerMetadata[this.providerOptionsName].acceptedPredictionTokens = completionTokenDetails == null ? void 0 : completionTokenDetails.accepted_prediction_tokens;
609
+ providerMetadata[metadataKey].acceptedPredictionTokens = completionTokenDetails == null ? void 0 : completionTokenDetails.accepted_prediction_tokens;
587
610
  }
588
611
  if ((completionTokenDetails == null ? void 0 : completionTokenDetails.rejected_prediction_tokens) != null) {
589
- providerMetadata[this.providerOptionsName].rejectedPredictionTokens = completionTokenDetails == null ? void 0 : completionTokenDetails.rejected_prediction_tokens;
612
+ providerMetadata[metadataKey].rejectedPredictionTokens = completionTokenDetails == null ? void 0 : completionTokenDetails.rejected_prediction_tokens;
590
613
  }
591
614
  return {
592
615
  content,
@@ -607,7 +630,7 @@ var OpenAICompatibleChatLanguageModel = class {
607
630
  }
608
631
  async doStream(options) {
609
632
  var _a;
610
- const { args, warnings } = await this.getArgs({ ...options });
633
+ const { args, warnings, metadataKey } = await this.getArgs({ ...options });
611
634
  const body = this.transformRequestBody({
612
635
  ...args,
613
636
  stream: true,
@@ -636,7 +659,7 @@ var OpenAICompatibleChatLanguageModel = class {
636
659
  };
637
660
  let usage = void 0;
638
661
  let isFirstChunk = true;
639
- const providerOptionsName = this.providerOptionsName;
662
+ const providerOptionsName = metadataKey;
640
663
  let isActiveReasoning = false;
641
664
  let isActiveText = false;
642
665
  return {
@@ -1180,13 +1203,20 @@ var OpenAICompatibleCompletionLanguageModel = class {
1180
1203
  tools,
1181
1204
  toolChoice
1182
1205
  }) {
1183
- var _a;
1206
+ var _a, _b;
1184
1207
  const warnings = [];
1185
- const completionOptions = (_a = await parseProviderOptions2({
1186
- provider: this.providerOptionsName,
1187
- providerOptions,
1188
- schema: openaiCompatibleLanguageModelCompletionOptions
1189
- })) != null ? _a : {};
1208
+ const completionOptions = Object.assign(
1209
+ (_a = await parseProviderOptions2({
1210
+ provider: this.providerOptionsName,
1211
+ providerOptions,
1212
+ schema: openaiCompatibleLanguageModelCompletionOptions
1213
+ })) != null ? _a : {},
1214
+ (_b = await parseProviderOptions2({
1215
+ provider: toCamelCase(this.providerOptionsName),
1216
+ providerOptions,
1217
+ schema: openaiCompatibleLanguageModelCompletionOptions
1218
+ })) != null ? _b : {}
1219
+ );
1190
1220
  if (topK != null) {
1191
1221
  warnings.push({ type: "unsupported", feature: "topK" });
1192
1222
  }
@@ -1222,6 +1252,7 @@ var OpenAICompatibleCompletionLanguageModel = class {
1222
1252
  presence_penalty: presencePenalty,
1223
1253
  seed,
1224
1254
  ...providerOptions == null ? void 0 : providerOptions[this.providerOptionsName],
1255
+ ...providerOptions == null ? void 0 : providerOptions[toCamelCase(this.providerOptionsName)],
1225
1256
  // prompt:
1226
1257
  prompt: completionPrompt,
1227
1258
  // stop sequences:
@@ -1671,9 +1702,6 @@ async function fileToBlob(file) {
1671
1702
  const data = file.data instanceof Uint8Array ? file.data : convertBase64ToUint8Array2(file.data);
1672
1703
  return new Blob([data], { type: file.mediaType });
1673
1704
  }
1674
- function toCamelCase(str) {
1675
- return str.replace(/[_-]([a-z])/g, (g) => g[1].toUpperCase());
1676
- }
1677
1705
 
1678
1706
  // src/openai-compatible-provider.ts
1679
1707
  import {
@@ -1682,7 +1710,7 @@ import {
1682
1710
  } from "@ai-sdk/provider-utils";
1683
1711
 
1684
1712
  // src/version.ts
1685
- var VERSION = true ? "2.0.39" : "0.0.0-test";
1713
+ var VERSION = true ? "2.0.41" : "0.0.0-test";
1686
1714
 
1687
1715
  // src/openai-compatible-provider.ts
1688
1716
  function createOpenAICompatible(options) {