@ai-sdk/xai 2.0.49 → 2.0.50

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
@@ -618,6 +618,7 @@ var XaiChatLanguageModel = class {
618
618
  let isFirstChunk = true;
619
619
  const contentBlocks = {};
620
620
  const lastReasoningDeltas = {};
621
+ let activeReasoningBlockId = void 0;
621
622
  const self = this;
622
623
  return {
623
624
  stream: response.pipeThrough(
@@ -670,13 +671,21 @@ var XaiChatLanguageModel = class {
670
671
  const choiceIndex = choice.index;
671
672
  if (delta.content != null && delta.content.length > 0) {
672
673
  const textContent = delta.content;
674
+ if (activeReasoningBlockId != null && !contentBlocks[activeReasoningBlockId].ended) {
675
+ controller.enqueue({
676
+ type: "reasoning-end",
677
+ id: activeReasoningBlockId
678
+ });
679
+ contentBlocks[activeReasoningBlockId].ended = true;
680
+ activeReasoningBlockId = void 0;
681
+ }
673
682
  const lastMessage = body.messages[body.messages.length - 1];
674
683
  if ((lastMessage == null ? void 0 : lastMessage.role) === "assistant" && textContent === lastMessage.content) {
675
684
  return;
676
685
  }
677
686
  const blockId = `text-${value.id || choiceIndex}`;
678
687
  if (contentBlocks[blockId] == null) {
679
- contentBlocks[blockId] = { type: "text" };
688
+ contentBlocks[blockId] = { type: "text", ended: false };
680
689
  controller.enqueue({
681
690
  type: "text-start",
682
691
  id: blockId
@@ -695,7 +704,8 @@ var XaiChatLanguageModel = class {
695
704
  }
696
705
  lastReasoningDeltas[blockId] = delta.reasoning_content;
697
706
  if (contentBlocks[blockId] == null) {
698
- contentBlocks[blockId] = { type: "reasoning" };
707
+ contentBlocks[blockId] = { type: "reasoning", ended: false };
708
+ activeReasoningBlockId = blockId;
699
709
  controller.enqueue({
700
710
  type: "reasoning-start",
701
711
  id: blockId
@@ -708,6 +718,14 @@ var XaiChatLanguageModel = class {
708
718
  });
709
719
  }
710
720
  if (delta.tool_calls != null) {
721
+ if (activeReasoningBlockId != null && !contentBlocks[activeReasoningBlockId].ended) {
722
+ controller.enqueue({
723
+ type: "reasoning-end",
724
+ id: activeReasoningBlockId
725
+ });
726
+ contentBlocks[activeReasoningBlockId].ended = true;
727
+ activeReasoningBlockId = void 0;
728
+ }
711
729
  for (const toolCall of delta.tool_calls) {
712
730
  const toolCallId = toolCall.id;
713
731
  controller.enqueue({
@@ -735,10 +753,12 @@ var XaiChatLanguageModel = class {
735
753
  },
736
754
  flush(controller) {
737
755
  for (const [blockId, block] of Object.entries(contentBlocks)) {
738
- controller.enqueue({
739
- type: block.type === "text" ? "text-end" : "reasoning-end",
740
- id: blockId
741
- });
756
+ if (!block.ended) {
757
+ controller.enqueue({
758
+ type: block.type === "text" ? "text-end" : "reasoning-end",
759
+ id: blockId
760
+ });
761
+ }
742
762
  }
743
763
  controller.enqueue({ type: "finish", finishReason, usage });
744
764
  }
@@ -2093,7 +2113,7 @@ var xaiTools = {
2093
2113
  };
2094
2114
 
2095
2115
  // src/version.ts
2096
- var VERSION = true ? "2.0.49" : "0.0.0-test";
2116
+ var VERSION = true ? "2.0.50" : "0.0.0-test";
2097
2117
 
2098
2118
  // src/xai-provider.ts
2099
2119
  var xaiErrorStructure = {