@ai-sdk/openai-compatible 2.0.6 → 2.0.8

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
@@ -81,7 +81,7 @@ function getOpenAIMetadata(message) {
81
81
  return (_b = (_a = message == null ? void 0 : message.providerOptions) == null ? void 0 : _a.openaiCompatible) != null ? _b : {};
82
82
  }
83
83
  function convertToOpenAICompatibleChatMessages(prompt) {
84
- var _a;
84
+ var _a, _b, _c;
85
85
  const messages = [];
86
86
  for (const { role, content, ...message } of prompt) {
87
87
  const metadata = getOpenAIMetadata({ ...message });
@@ -140,6 +140,7 @@ function convertToOpenAICompatibleChatMessages(prompt) {
140
140
  break;
141
141
  }
142
142
  case "tool-call": {
143
+ const thoughtSignature = (_b = (_a = part.providerOptions) == null ? void 0 : _a.google) == null ? void 0 : _b.thoughtSignature;
143
144
  toolCalls.push({
144
145
  id: part.toolCallId,
145
146
  type: "function",
@@ -147,7 +148,15 @@ function convertToOpenAICompatibleChatMessages(prompt) {
147
148
  name: part.toolName,
148
149
  arguments: JSON.stringify(part.input)
149
150
  },
150
- ...partMetadata
151
+ ...partMetadata,
152
+ // Include extra_content for Google Gemini thought signatures
153
+ ...thoughtSignature ? {
154
+ extra_content: {
155
+ google: {
156
+ thought_signature: String(thoughtSignature)
157
+ }
158
+ }
159
+ } : {}
151
160
  });
152
161
  break;
153
162
  }
@@ -174,7 +183,7 @@ function convertToOpenAICompatibleChatMessages(prompt) {
174
183
  contentValue = output.value;
175
184
  break;
176
185
  case "execution-denied":
177
- contentValue = (_a = output.reason) != null ? _a : "Tool execution denied.";
186
+ contentValue = (_c = output.reason) != null ? _c : "Tool execution denied.";
178
187
  break;
179
188
  case "content":
180
189
  case "json":
@@ -421,7 +430,7 @@ var OpenAICompatibleChatLanguageModel = class {
421
430
  };
422
431
  }
423
432
  async doGenerate(options) {
424
- var _a, _b, _c, _d, _e, _f;
433
+ var _a, _b, _c, _d, _e, _f, _g, _h;
425
434
  const { args, warnings } = await this.getArgs({ ...options });
426
435
  const body = JSON.stringify(args);
427
436
  const {
@@ -457,21 +466,27 @@ var OpenAICompatibleChatLanguageModel = class {
457
466
  }
458
467
  if (choice.message.tool_calls != null) {
459
468
  for (const toolCall of choice.message.tool_calls) {
469
+ const thoughtSignature = (_c = (_b = toolCall.extra_content) == null ? void 0 : _b.google) == null ? void 0 : _c.thought_signature;
460
470
  content.push({
461
471
  type: "tool-call",
462
- toolCallId: (_b = toolCall.id) != null ? _b : generateId(),
472
+ toolCallId: (_d = toolCall.id) != null ? _d : generateId(),
463
473
  toolName: toolCall.function.name,
464
- input: toolCall.function.arguments
474
+ input: toolCall.function.arguments,
475
+ ...thoughtSignature ? {
476
+ providerMetadata: {
477
+ [this.providerOptionsName]: { thoughtSignature }
478
+ }
479
+ } : {}
465
480
  });
466
481
  }
467
482
  }
468
483
  const providerMetadata = {
469
484
  [this.providerOptionsName]: {},
470
- ...await ((_d = (_c = this.config.metadataExtractor) == null ? void 0 : _c.extractMetadata) == null ? void 0 : _d.call(_c, {
485
+ ...await ((_f = (_e = this.config.metadataExtractor) == null ? void 0 : _e.extractMetadata) == null ? void 0 : _f.call(_e, {
471
486
  parsedBody: rawResponse
472
487
  }))
473
488
  };
474
- const completionTokenDetails = (_e = responseBody.usage) == null ? void 0 : _e.completion_tokens_details;
489
+ const completionTokenDetails = (_g = responseBody.usage) == null ? void 0 : _g.completion_tokens_details;
475
490
  if ((completionTokenDetails == null ? void 0 : completionTokenDetails.accepted_prediction_tokens) != null) {
476
491
  providerMetadata[this.providerOptionsName].acceptedPredictionTokens = completionTokenDetails == null ? void 0 : completionTokenDetails.accepted_prediction_tokens;
477
492
  }
@@ -482,7 +497,7 @@ var OpenAICompatibleChatLanguageModel = class {
482
497
  content,
483
498
  finishReason: {
484
499
  unified: mapOpenAICompatibleFinishReason(choice.finish_reason),
485
- raw: (_f = choice.finish_reason) != null ? _f : void 0
500
+ raw: (_h = choice.finish_reason) != null ? _h : void 0
486
501
  },
487
502
  usage: convertOpenAICompatibleChatUsage(responseBody.usage),
488
503
  providerMetadata,
@@ -536,7 +551,7 @@ var OpenAICompatibleChatLanguageModel = class {
536
551
  controller.enqueue({ type: "stream-start", warnings });
537
552
  },
538
553
  transform(chunk, controller) {
539
- var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
554
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r;
540
555
  if (options.includeRawChunks) {
541
556
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
542
557
  }
@@ -592,6 +607,13 @@ var OpenAICompatibleChatLanguageModel = class {
592
607
  });
593
608
  }
594
609
  if (delta.content) {
610
+ if (isActiveReasoning) {
611
+ controller.enqueue({
612
+ type: "reasoning-end",
613
+ id: "reasoning-0"
614
+ });
615
+ isActiveReasoning = false;
616
+ }
595
617
  if (!isActiveText) {
596
618
  controller.enqueue({ type: "text-start", id: "txt-0" });
597
619
  isActiveText = true;
@@ -603,8 +625,15 @@ var OpenAICompatibleChatLanguageModel = class {
603
625
  });
604
626
  }
605
627
  if (delta.tool_calls != null) {
628
+ if (isActiveReasoning) {
629
+ controller.enqueue({
630
+ type: "reasoning-end",
631
+ id: "reasoning-0"
632
+ });
633
+ isActiveReasoning = false;
634
+ }
606
635
  for (const toolCallDelta of delta.tool_calls) {
607
- const index = toolCallDelta.index;
636
+ const index = (_c = toolCallDelta.index) != null ? _c : toolCalls.length;
608
637
  if (toolCalls[index] == null) {
609
638
  if (toolCallDelta.id == null) {
610
639
  throw new InvalidResponseDataError({
@@ -612,7 +641,7 @@ var OpenAICompatibleChatLanguageModel = class {
612
641
  message: `Expected 'id' to be a string.`
613
642
  });
614
643
  }
615
- if (((_c = toolCallDelta.function) == null ? void 0 : _c.name) == null) {
644
+ if (((_d = toolCallDelta.function) == null ? void 0 : _d.name) == null) {
616
645
  throw new InvalidResponseDataError({
617
646
  data: toolCallDelta,
618
647
  message: `Expected 'function.name' to be a string.`
@@ -628,12 +657,13 @@ var OpenAICompatibleChatLanguageModel = class {
628
657
  type: "function",
629
658
  function: {
630
659
  name: toolCallDelta.function.name,
631
- arguments: (_d = toolCallDelta.function.arguments) != null ? _d : ""
660
+ arguments: (_e = toolCallDelta.function.arguments) != null ? _e : ""
632
661
  },
633
- hasFinished: false
662
+ hasFinished: false,
663
+ thoughtSignature: (_h = (_g = (_f = toolCallDelta.extra_content) == null ? void 0 : _f.google) == null ? void 0 : _g.thought_signature) != null ? _h : void 0
634
664
  };
635
665
  const toolCall2 = toolCalls[index];
636
- if (((_e = toolCall2.function) == null ? void 0 : _e.name) != null && ((_f = toolCall2.function) == null ? void 0 : _f.arguments) != null) {
666
+ if (((_i = toolCall2.function) == null ? void 0 : _i.name) != null && ((_j = toolCall2.function) == null ? void 0 : _j.arguments) != null) {
637
667
  if (toolCall2.function.arguments.length > 0) {
638
668
  controller.enqueue({
639
669
  type: "tool-input-delta",
@@ -648,9 +678,16 @@ var OpenAICompatibleChatLanguageModel = class {
648
678
  });
649
679
  controller.enqueue({
650
680
  type: "tool-call",
651
- toolCallId: (_g = toolCall2.id) != null ? _g : generateId(),
681
+ toolCallId: (_k = toolCall2.id) != null ? _k : generateId(),
652
682
  toolName: toolCall2.function.name,
653
- input: toolCall2.function.arguments
683
+ input: toolCall2.function.arguments,
684
+ ...toolCall2.thoughtSignature ? {
685
+ providerMetadata: {
686
+ [providerOptionsName]: {
687
+ thoughtSignature: toolCall2.thoughtSignature
688
+ }
689
+ }
690
+ } : {}
654
691
  });
655
692
  toolCall2.hasFinished = true;
656
693
  }
@@ -661,24 +698,31 @@ var OpenAICompatibleChatLanguageModel = class {
661
698
  if (toolCall.hasFinished) {
662
699
  continue;
663
700
  }
664
- if (((_h = toolCallDelta.function) == null ? void 0 : _h.arguments) != null) {
665
- toolCall.function.arguments += (_j = (_i = toolCallDelta.function) == null ? void 0 : _i.arguments) != null ? _j : "";
701
+ if (((_l = toolCallDelta.function) == null ? void 0 : _l.arguments) != null) {
702
+ toolCall.function.arguments += (_n = (_m = toolCallDelta.function) == null ? void 0 : _m.arguments) != null ? _n : "";
666
703
  }
667
704
  controller.enqueue({
668
705
  type: "tool-input-delta",
669
706
  id: toolCall.id,
670
- delta: (_k = toolCallDelta.function.arguments) != null ? _k : ""
707
+ delta: (_o = toolCallDelta.function.arguments) != null ? _o : ""
671
708
  });
672
- if (((_l = toolCall.function) == null ? void 0 : _l.name) != null && ((_m = toolCall.function) == null ? void 0 : _m.arguments) != null && isParsableJson(toolCall.function.arguments)) {
709
+ if (((_p = toolCall.function) == null ? void 0 : _p.name) != null && ((_q = toolCall.function) == null ? void 0 : _q.arguments) != null && isParsableJson(toolCall.function.arguments)) {
673
710
  controller.enqueue({
674
711
  type: "tool-input-end",
675
712
  id: toolCall.id
676
713
  });
677
714
  controller.enqueue({
678
715
  type: "tool-call",
679
- toolCallId: (_n = toolCall.id) != null ? _n : generateId(),
716
+ toolCallId: (_r = toolCall.id) != null ? _r : generateId(),
680
717
  toolName: toolCall.function.name,
681
- input: toolCall.function.arguments
718
+ input: toolCall.function.arguments,
719
+ ...toolCall.thoughtSignature ? {
720
+ providerMetadata: {
721
+ [providerOptionsName]: {
722
+ thoughtSignature: toolCall.thoughtSignature
723
+ }
724
+ }
725
+ } : {}
682
726
  });
683
727
  toolCall.hasFinished = true;
684
728
  }
@@ -704,7 +748,14 @@ var OpenAICompatibleChatLanguageModel = class {
704
748
  type: "tool-call",
705
749
  toolCallId: (_a2 = toolCall.id) != null ? _a2 : generateId(),
706
750
  toolName: toolCall.function.name,
707
- input: toolCall.function.arguments
751
+ input: toolCall.function.arguments,
752
+ ...toolCall.thoughtSignature ? {
753
+ providerMetadata: {
754
+ [providerOptionsName]: {
755
+ thoughtSignature: toolCall.thoughtSignature
756
+ }
757
+ }
758
+ } : {}
708
759
  });
709
760
  }
710
761
  const providerMetadata = {
@@ -761,7 +812,13 @@ var OpenAICompatibleChatResponseSchema = z3.looseObject({
761
812
  function: z3.object({
762
813
  name: z3.string(),
763
814
  arguments: z3.string()
764
- })
815
+ }),
816
+ // Support for Google Gemini thought signatures via OpenAI compatibility
817
+ extra_content: z3.object({
818
+ google: z3.object({
819
+ thought_signature: z3.string().nullish()
820
+ }).nullish()
821
+ }).nullish()
765
822
  })
766
823
  ).nullish()
767
824
  }),
@@ -785,12 +842,19 @@ var chunkBaseSchema = z3.looseObject({
785
842
  reasoning: z3.string().nullish(),
786
843
  tool_calls: z3.array(
787
844
  z3.object({
788
- index: z3.number(),
845
+ index: z3.number().nullish(),
846
+ //google does not send index
789
847
  id: z3.string().nullish(),
790
848
  function: z3.object({
791
849
  name: z3.string().nullish(),
792
850
  arguments: z3.string().nullish()
793
- })
851
+ }),
852
+ // Support for Google Gemini thought signatures via OpenAI compatibility
853
+ extra_content: z3.object({
854
+ google: z3.object({
855
+ thought_signature: z3.string().nullish()
856
+ }).nullish()
857
+ }).nullish()
794
858
  })
795
859
  ).nullish()
796
860
  }).nullish(),
@@ -1493,7 +1557,7 @@ import {
1493
1557
  } from "@ai-sdk/provider-utils";
1494
1558
 
1495
1559
  // src/version.ts
1496
- var VERSION = true ? "2.0.6" : "0.0.0-test";
1560
+ var VERSION = true ? "2.0.8" : "0.0.0-test";
1497
1561
 
1498
1562
  // src/openai-compatible-provider.ts
1499
1563
  function createOpenAICompatible(options) {