@ai-sdk/openai-compatible 1.0.55 → 1.0.57

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,20 @@
1
1
  # @ai-sdk/openai-compatible
2
2
 
3
+ ## 1.0.57
4
+
5
+ ### Patch Changes
6
+
7
+ - 14810cb: fix(provider-utils): preserve streamed tool calls with unreliable IDs and indices
8
+ - Updated dependencies [14810cb]
9
+ - @ai-sdk/provider-utils@3.0.40
10
+
11
+ ## 1.0.56
12
+
13
+ ### Patch Changes
14
+
15
+ - Updated dependencies [bf29419]
16
+ - @ai-sdk/provider-utils@3.0.39
17
+
3
18
  ## 1.0.55
4
19
 
5
20
  ### Patch Changes
package/dist/index.js CHANGED
@@ -503,7 +503,7 @@ var OpenAICompatibleChatLanguageModel = class {
503
503
  abortSignal: options.abortSignal,
504
504
  fetch: this.config.fetch
505
505
  });
506
- const toolCalls = [];
506
+ let toolCallTracker;
507
507
  let finishReason = "unknown";
508
508
  const usage = {
509
509
  completionTokens: void 0,
@@ -539,11 +539,14 @@ var OpenAICompatibleChatLanguageModel = class {
539
539
  stream: response.pipeThrough(
540
540
  new TransformStream({
541
541
  start(controller) {
542
+ toolCallTracker = new import_provider_utils2.StreamingToolCallTracker(controller, {
543
+ generateId: import_provider_utils2.generateId
544
+ });
542
545
  controller.enqueue({ type: "stream-start", warnings });
543
546
  },
544
547
  // TODO we lost type safety on Chunk, most likely due to the error schema. MUST FIX
545
548
  transform(chunk, controller) {
546
- var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
549
+ var _a2, _b;
547
550
  if (options.includeRawChunks) {
548
551
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
549
552
  }
@@ -617,109 +620,21 @@ var OpenAICompatibleChatLanguageModel = class {
617
620
  fallbackIndex,
618
621
  toolCallDelta
619
622
  ] of delta.tool_calls.entries()) {
620
- const index = (_b = toolCallDelta.index) != null ? _b : fallbackIndex;
621
- if (toolCalls[index] == null) {
622
- if (toolCallDelta.id == null) {
623
- throw new import_provider3.InvalidResponseDataError({
624
- data: toolCallDelta,
625
- message: `Expected 'id' to be a string.`
626
- });
627
- }
628
- if (((_c = toolCallDelta.function) == null ? void 0 : _c.name) == null) {
629
- throw new import_provider3.InvalidResponseDataError({
630
- data: toolCallDelta,
631
- message: `Expected 'function.name' to be a string.`
632
- });
633
- }
634
- controller.enqueue({
635
- type: "tool-input-start",
636
- id: toolCallDelta.id,
637
- toolName: toolCallDelta.function.name
638
- });
639
- toolCalls[index] = {
640
- id: toolCallDelta.id,
641
- type: "function",
642
- function: {
643
- name: toolCallDelta.function.name,
644
- arguments: (_d = toolCallDelta.function.arguments) != null ? _d : ""
645
- },
646
- hasFinished: false
647
- };
648
- const toolCall2 = toolCalls[index];
649
- if (((_e = toolCall2.function) == null ? void 0 : _e.name) != null && ((_f = toolCall2.function) == null ? void 0 : _f.arguments) != null) {
650
- if (toolCall2.function.arguments.length > 0) {
651
- controller.enqueue({
652
- type: "tool-input-delta",
653
- id: toolCall2.id,
654
- delta: toolCall2.function.arguments
655
- });
656
- }
657
- if ((0, import_provider_utils2.isParsableJson)(toolCall2.function.arguments)) {
658
- controller.enqueue({
659
- type: "tool-input-end",
660
- id: toolCall2.id
661
- });
662
- controller.enqueue({
663
- type: "tool-call",
664
- toolCallId: (_g = toolCall2.id) != null ? _g : (0, import_provider_utils2.generateId)(),
665
- toolName: toolCall2.function.name,
666
- input: toolCall2.function.arguments
667
- });
668
- toolCall2.hasFinished = true;
669
- }
670
- }
671
- continue;
672
- }
673
- const toolCall = toolCalls[index];
674
- if (toolCall.hasFinished) {
675
- continue;
676
- }
677
- if (((_h = toolCallDelta.function) == null ? void 0 : _h.arguments) != null) {
678
- toolCall.function.arguments += (_j = (_i = toolCallDelta.function) == null ? void 0 : _i.arguments) != null ? _j : "";
679
- }
680
- controller.enqueue({
681
- type: "tool-input-delta",
682
- id: toolCall.id,
683
- delta: (_k = toolCallDelta.function.arguments) != null ? _k : ""
623
+ toolCallTracker.processDelta({
624
+ ...toolCallDelta,
625
+ index: (_b = toolCallDelta.index) != null ? _b : fallbackIndex
684
626
  });
685
- if (((_l = toolCall.function) == null ? void 0 : _l.name) != null && ((_m = toolCall.function) == null ? void 0 : _m.arguments) != null && (0, import_provider_utils2.isParsableJson)(toolCall.function.arguments)) {
686
- controller.enqueue({
687
- type: "tool-input-end",
688
- id: toolCall.id
689
- });
690
- controller.enqueue({
691
- type: "tool-call",
692
- toolCallId: (_n = toolCall.id) != null ? _n : (0, import_provider_utils2.generateId)(),
693
- toolName: toolCall.function.name,
694
- input: toolCall.function.arguments
695
- });
696
- toolCall.hasFinished = true;
697
- }
698
627
  }
699
628
  }
700
629
  },
701
630
  flush(controller) {
702
- var _a2;
703
631
  if (isActiveReasoning) {
704
632
  controller.enqueue({ type: "reasoning-end", id: "reasoning-0" });
705
633
  }
706
634
  if (isActiveText) {
707
635
  controller.enqueue({ type: "text-end", id: "txt-0" });
708
636
  }
709
- for (const toolCall of toolCalls.filter(
710
- (toolCall2) => !toolCall2.hasFinished
711
- )) {
712
- controller.enqueue({
713
- type: "tool-input-end",
714
- id: toolCall.id
715
- });
716
- controller.enqueue({
717
- type: "tool-call",
718
- toolCallId: (_a2 = toolCall.id) != null ? _a2 : (0, import_provider_utils2.generateId)(),
719
- toolName: toolCall.function.name,
720
- input: toolCall.function.arguments
721
- });
722
- }
637
+ toolCallTracker.flush();
723
638
  const providerMetadata = {
724
639
  [providerOptionsName]: {},
725
640
  ...metadataExtractor == null ? void 0 : metadataExtractor.buildMetadata()
@@ -1417,7 +1332,7 @@ var openaiCompatibleImageResponseSchema = import_v48.z.object({
1417
1332
  var import_provider_utils6 = require("@ai-sdk/provider-utils");
1418
1333
 
1419
1334
  // src/version.ts
1420
- var VERSION = true ? "1.0.55" : "0.0.0-test";
1335
+ var VERSION = true ? "1.0.57" : "0.0.0-test";
1421
1336
 
1422
1337
  // src/openai-compatible-provider.ts
1423
1338
  function createOpenAICompatible(options) {