@ai-sdk/xai 3.0.12 → 3.0.13

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
@@ -622,6 +622,7 @@ var XaiChatLanguageModel = class {
622
622
  let isFirstChunk = true;
623
623
  const contentBlocks = {};
624
624
  const lastReasoningDeltas = {};
625
+ let activeReasoningBlockId = void 0;
625
626
  const self = this;
626
627
  return {
627
628
  stream: response.pipeThrough(
@@ -672,13 +673,21 @@ var XaiChatLanguageModel = class {
672
673
  const choiceIndex = choice.index;
673
674
  if (delta.content != null && delta.content.length > 0) {
674
675
  const textContent = delta.content;
676
+ if (activeReasoningBlockId != null && !contentBlocks[activeReasoningBlockId].ended) {
677
+ controller.enqueue({
678
+ type: "reasoning-end",
679
+ id: activeReasoningBlockId
680
+ });
681
+ contentBlocks[activeReasoningBlockId].ended = true;
682
+ activeReasoningBlockId = void 0;
683
+ }
675
684
  const lastMessage = body.messages[body.messages.length - 1];
676
685
  if ((lastMessage == null ? void 0 : lastMessage.role) === "assistant" && textContent === lastMessage.content) {
677
686
  return;
678
687
  }
679
688
  const blockId = `text-${value.id || choiceIndex}`;
680
689
  if (contentBlocks[blockId] == null) {
681
- contentBlocks[blockId] = { type: "text" };
690
+ contentBlocks[blockId] = { type: "text", ended: false };
682
691
  controller.enqueue({
683
692
  type: "text-start",
684
693
  id: blockId
@@ -697,7 +706,8 @@ var XaiChatLanguageModel = class {
697
706
  }
698
707
  lastReasoningDeltas[blockId] = delta.reasoning_content;
699
708
  if (contentBlocks[blockId] == null) {
700
- contentBlocks[blockId] = { type: "reasoning" };
709
+ contentBlocks[blockId] = { type: "reasoning", ended: false };
710
+ activeReasoningBlockId = blockId;
701
711
  controller.enqueue({
702
712
  type: "reasoning-start",
703
713
  id: blockId
@@ -710,6 +720,14 @@ var XaiChatLanguageModel = class {
710
720
  });
711
721
  }
712
722
  if (delta.tool_calls != null) {
723
+ if (activeReasoningBlockId != null && !contentBlocks[activeReasoningBlockId].ended) {
724
+ controller.enqueue({
725
+ type: "reasoning-end",
726
+ id: activeReasoningBlockId
727
+ });
728
+ contentBlocks[activeReasoningBlockId].ended = true;
729
+ activeReasoningBlockId = void 0;
730
+ }
713
731
  for (const toolCall of delta.tool_calls) {
714
732
  const toolCallId = toolCall.id;
715
733
  controller.enqueue({
@@ -737,10 +755,12 @@ var XaiChatLanguageModel = class {
737
755
  },
738
756
  flush(controller) {
739
757
  for (const [blockId, block] of Object.entries(contentBlocks)) {
740
- controller.enqueue({
741
- type: block.type === "text" ? "text-end" : "reasoning-end",
742
- id: blockId
743
- });
758
+ if (!block.ended) {
759
+ controller.enqueue({
760
+ type: block.type === "text" ? "text-end" : "reasoning-end",
761
+ id: blockId
762
+ });
763
+ }
744
764
  }
745
765
  controller.enqueue({ type: "finish", finishReason, usage });
746
766
  }
@@ -2115,7 +2135,7 @@ var xaiTools = {
2115
2135
  };
2116
2136
 
2117
2137
  // src/version.ts
2118
- var VERSION = true ? "3.0.12" : "0.0.0-test";
2138
+ var VERSION = true ? "3.0.13" : "0.0.0-test";
2119
2139
 
2120
2140
  // src/xai-provider.ts
2121
2141
  var xaiErrorStructure = {