@ai-sdk/xai 3.0.12 → 3.0.14

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
  }
@@ -1615,11 +1635,12 @@ var XaiResponsesLanguageModel = class {
1615
1635
  topP,
1616
1636
  stopSequences,
1617
1637
  seed,
1638
+ responseFormat,
1618
1639
  providerOptions,
1619
1640
  tools,
1620
1641
  toolChoice
1621
1642
  }) {
1622
- var _a, _b, _c, _d;
1643
+ var _a, _b, _c, _d, _e;
1623
1644
  const warnings = [];
1624
1645
  const options = (_a = await parseProviderOptions2({
1625
1646
  provider: "xai",
@@ -1659,6 +1680,17 @@ var XaiResponsesLanguageModel = class {
1659
1680
  temperature,
1660
1681
  top_p: topP,
1661
1682
  seed,
1683
+ ...(responseFormat == null ? void 0 : responseFormat.type) === "json" && {
1684
+ text: {
1685
+ format: responseFormat.schema != null ? {
1686
+ type: "json_schema",
1687
+ strict: true,
1688
+ name: (_e = responseFormat.name) != null ? _e : "response",
1689
+ description: responseFormat.description,
1690
+ schema: responseFormat.schema
1691
+ } : { type: "json_object" }
1692
+ }
1693
+ },
1662
1694
  ...options.reasoningEffort != null && {
1663
1695
  reasoning: { effort: options.reasoningEffort }
1664
1696
  },
@@ -2115,7 +2147,7 @@ var xaiTools = {
2115
2147
  };
2116
2148
 
2117
2149
  // src/version.ts
2118
- var VERSION = true ? "3.0.12" : "0.0.0-test";
2150
+ var VERSION = true ? "3.0.14" : "0.0.0-test";
2119
2151
 
2120
2152
  // src/xai-provider.ts
2121
2153
  var xaiErrorStructure = {