@ai-sdk/openai-compatible 2.0.6 → 2.0.7

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
  }
@@ -604,7 +619,7 @@ var OpenAICompatibleChatLanguageModel = class {
604
619
  }
605
620
  if (delta.tool_calls != null) {
606
621
  for (const toolCallDelta of delta.tool_calls) {
607
- const index = toolCallDelta.index;
622
+ const index = (_c = toolCallDelta.index) != null ? _c : toolCalls.length;
608
623
  if (toolCalls[index] == null) {
609
624
  if (toolCallDelta.id == null) {
610
625
  throw new InvalidResponseDataError({
@@ -612,7 +627,7 @@ var OpenAICompatibleChatLanguageModel = class {
612
627
  message: `Expected 'id' to be a string.`
613
628
  });
614
629
  }
615
- if (((_c = toolCallDelta.function) == null ? void 0 : _c.name) == null) {
630
+ if (((_d = toolCallDelta.function) == null ? void 0 : _d.name) == null) {
616
631
  throw new InvalidResponseDataError({
617
632
  data: toolCallDelta,
618
633
  message: `Expected 'function.name' to be a string.`
@@ -628,12 +643,13 @@ var OpenAICompatibleChatLanguageModel = class {
628
643
  type: "function",
629
644
  function: {
630
645
  name: toolCallDelta.function.name,
631
- arguments: (_d = toolCallDelta.function.arguments) != null ? _d : ""
646
+ arguments: (_e = toolCallDelta.function.arguments) != null ? _e : ""
632
647
  },
633
- hasFinished: false
648
+ hasFinished: false,
649
+ thoughtSignature: (_h = (_g = (_f = toolCallDelta.extra_content) == null ? void 0 : _f.google) == null ? void 0 : _g.thought_signature) != null ? _h : void 0
634
650
  };
635
651
  const toolCall2 = toolCalls[index];
636
- if (((_e = toolCall2.function) == null ? void 0 : _e.name) != null && ((_f = toolCall2.function) == null ? void 0 : _f.arguments) != null) {
652
+ if (((_i = toolCall2.function) == null ? void 0 : _i.name) != null && ((_j = toolCall2.function) == null ? void 0 : _j.arguments) != null) {
637
653
  if (toolCall2.function.arguments.length > 0) {
638
654
  controller.enqueue({
639
655
  type: "tool-input-delta",
@@ -648,9 +664,16 @@ var OpenAICompatibleChatLanguageModel = class {
648
664
  });
649
665
  controller.enqueue({
650
666
  type: "tool-call",
651
- toolCallId: (_g = toolCall2.id) != null ? _g : generateId(),
667
+ toolCallId: (_k = toolCall2.id) != null ? _k : generateId(),
652
668
  toolName: toolCall2.function.name,
653
- input: toolCall2.function.arguments
669
+ input: toolCall2.function.arguments,
670
+ ...toolCall2.thoughtSignature ? {
671
+ providerMetadata: {
672
+ [providerOptionsName]: {
673
+ thoughtSignature: toolCall2.thoughtSignature
674
+ }
675
+ }
676
+ } : {}
654
677
  });
655
678
  toolCall2.hasFinished = true;
656
679
  }
@@ -661,24 +684,31 @@ var OpenAICompatibleChatLanguageModel = class {
661
684
  if (toolCall.hasFinished) {
662
685
  continue;
663
686
  }
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 : "";
687
+ if (((_l = toolCallDelta.function) == null ? void 0 : _l.arguments) != null) {
688
+ toolCall.function.arguments += (_n = (_m = toolCallDelta.function) == null ? void 0 : _m.arguments) != null ? _n : "";
666
689
  }
667
690
  controller.enqueue({
668
691
  type: "tool-input-delta",
669
692
  id: toolCall.id,
670
- delta: (_k = toolCallDelta.function.arguments) != null ? _k : ""
693
+ delta: (_o = toolCallDelta.function.arguments) != null ? _o : ""
671
694
  });
672
- if (((_l = toolCall.function) == null ? void 0 : _l.name) != null && ((_m = toolCall.function) == null ? void 0 : _m.arguments) != null && isParsableJson(toolCall.function.arguments)) {
695
+ if (((_p = toolCall.function) == null ? void 0 : _p.name) != null && ((_q = toolCall.function) == null ? void 0 : _q.arguments) != null && isParsableJson(toolCall.function.arguments)) {
673
696
  controller.enqueue({
674
697
  type: "tool-input-end",
675
698
  id: toolCall.id
676
699
  });
677
700
  controller.enqueue({
678
701
  type: "tool-call",
679
- toolCallId: (_n = toolCall.id) != null ? _n : generateId(),
702
+ toolCallId: (_r = toolCall.id) != null ? _r : generateId(),
680
703
  toolName: toolCall.function.name,
681
- input: toolCall.function.arguments
704
+ input: toolCall.function.arguments,
705
+ ...toolCall.thoughtSignature ? {
706
+ providerMetadata: {
707
+ [providerOptionsName]: {
708
+ thoughtSignature: toolCall.thoughtSignature
709
+ }
710
+ }
711
+ } : {}
682
712
  });
683
713
  toolCall.hasFinished = true;
684
714
  }
@@ -704,7 +734,14 @@ var OpenAICompatibleChatLanguageModel = class {
704
734
  type: "tool-call",
705
735
  toolCallId: (_a2 = toolCall.id) != null ? _a2 : generateId(),
706
736
  toolName: toolCall.function.name,
707
- input: toolCall.function.arguments
737
+ input: toolCall.function.arguments,
738
+ ...toolCall.thoughtSignature ? {
739
+ providerMetadata: {
740
+ [providerOptionsName]: {
741
+ thoughtSignature: toolCall.thoughtSignature
742
+ }
743
+ }
744
+ } : {}
708
745
  });
709
746
  }
710
747
  const providerMetadata = {
@@ -761,7 +798,13 @@ var OpenAICompatibleChatResponseSchema = z3.looseObject({
761
798
  function: z3.object({
762
799
  name: z3.string(),
763
800
  arguments: z3.string()
764
- })
801
+ }),
802
+ // Support for Google Gemini thought signatures via OpenAI compatibility
803
+ extra_content: z3.object({
804
+ google: z3.object({
805
+ thought_signature: z3.string().nullish()
806
+ }).nullish()
807
+ }).nullish()
765
808
  })
766
809
  ).nullish()
767
810
  }),
@@ -785,12 +828,19 @@ var chunkBaseSchema = z3.looseObject({
785
828
  reasoning: z3.string().nullish(),
786
829
  tool_calls: z3.array(
787
830
  z3.object({
788
- index: z3.number(),
831
+ index: z3.number().nullish(),
832
+ //google does not send index
789
833
  id: z3.string().nullish(),
790
834
  function: z3.object({
791
835
  name: z3.string().nullish(),
792
836
  arguments: z3.string().nullish()
793
- })
837
+ }),
838
+ // Support for Google Gemini thought signatures via OpenAI compatibility
839
+ extra_content: z3.object({
840
+ google: z3.object({
841
+ thought_signature: z3.string().nullish()
842
+ }).nullish()
843
+ }).nullish()
794
844
  })
795
845
  ).nullish()
796
846
  }).nullish(),
@@ -1493,7 +1543,7 @@ import {
1493
1543
  } from "@ai-sdk/provider-utils";
1494
1544
 
1495
1545
  // src/version.ts
1496
- var VERSION = true ? "2.0.6" : "0.0.0-test";
1546
+ var VERSION = true ? "2.0.7" : "0.0.0-test";
1497
1547
 
1498
1548
  // src/openai-compatible-provider.ts
1499
1549
  function createOpenAICompatible(options) {