@zenning/ai 6.0.28 → 6.0.30

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
@@ -898,7 +898,7 @@ import {
898
898
  } from "@zenning/provider-utils";
899
899
 
900
900
  // src/version.ts
901
- var VERSION = true ? "6.0.28" : "0.0.0-test";
901
+ var VERSION = true ? "6.0.30" : "0.0.0-test";
902
902
 
903
903
  // src/util/download/download.ts
904
904
  var download = async ({ url }) => {
@@ -4761,16 +4761,43 @@ function processUIMessageStream({
4761
4761
  break;
4762
4762
  }
4763
4763
  case "text-delta": {
4764
- const textPart = state.activeTextParts[chunk.id];
4764
+ let textPart = state.activeTextParts[chunk.id];
4765
+ if (!textPart) {
4766
+ const existing = state.message.parts.findLast(
4767
+ (p) => p.type === "text" && p.state !== "done"
4768
+ );
4769
+ if (existing) {
4770
+ textPart = existing;
4771
+ } else {
4772
+ textPart = {
4773
+ type: "text",
4774
+ text: "",
4775
+ state: "streaming"
4776
+ };
4777
+ state.message.parts.push(textPart);
4778
+ }
4779
+ state.activeTextParts[chunk.id] = textPart;
4780
+ }
4765
4781
  textPart.text += chunk.delta;
4766
4782
  textPart.providerMetadata = (_a16 = chunk.providerMetadata) != null ? _a16 : textPart.providerMetadata;
4767
4783
  write();
4768
4784
  break;
4769
4785
  }
4770
4786
  case "text-end": {
4771
- const textPart = state.activeTextParts[chunk.id];
4772
- textPart.state = "done";
4773
- textPart.providerMetadata = (_b = chunk.providerMetadata) != null ? _b : textPart.providerMetadata;
4787
+ let textPart = state.activeTextParts[chunk.id];
4788
+ if (!textPart) {
4789
+ const existing = state.message.parts.findLast(
4790
+ (p) => p.type === "text" && p.state !== "done"
4791
+ );
4792
+ if (existing) {
4793
+ textPart = existing;
4794
+ state.activeTextParts[chunk.id] = textPart;
4795
+ }
4796
+ }
4797
+ if (textPart) {
4798
+ textPart.state = "done";
4799
+ textPart.providerMetadata = (_b = chunk.providerMetadata) != null ? _b : textPart.providerMetadata;
4800
+ }
4774
4801
  delete state.activeTextParts[chunk.id];
4775
4802
  write();
4776
4803
  break;
@@ -4788,16 +4815,43 @@ function processUIMessageStream({
4788
4815
  break;
4789
4816
  }
4790
4817
  case "reasoning-delta": {
4791
- const reasoningPart = state.activeReasoningParts[chunk.id];
4818
+ let reasoningPart = state.activeReasoningParts[chunk.id];
4819
+ if (!reasoningPart) {
4820
+ const existing = state.message.parts.findLast(
4821
+ (p) => p.type === "reasoning" && p.state !== "done"
4822
+ );
4823
+ if (existing) {
4824
+ reasoningPart = existing;
4825
+ } else {
4826
+ reasoningPart = {
4827
+ type: "reasoning",
4828
+ text: "",
4829
+ state: "streaming"
4830
+ };
4831
+ state.message.parts.push(reasoningPart);
4832
+ }
4833
+ state.activeReasoningParts[chunk.id] = reasoningPart;
4834
+ }
4792
4835
  reasoningPart.text += chunk.delta;
4793
4836
  reasoningPart.providerMetadata = (_c = chunk.providerMetadata) != null ? _c : reasoningPart.providerMetadata;
4794
4837
  write();
4795
4838
  break;
4796
4839
  }
4797
4840
  case "reasoning-end": {
4798
- const reasoningPart = state.activeReasoningParts[chunk.id];
4799
- reasoningPart.providerMetadata = (_d = chunk.providerMetadata) != null ? _d : reasoningPart.providerMetadata;
4800
- reasoningPart.state = "done";
4841
+ let reasoningPart = state.activeReasoningParts[chunk.id];
4842
+ if (!reasoningPart) {
4843
+ const existing = state.message.parts.findLast(
4844
+ (p) => p.type === "reasoning" && p.state !== "done"
4845
+ );
4846
+ if (existing) {
4847
+ reasoningPart = existing;
4848
+ state.activeReasoningParts[chunk.id] = reasoningPart;
4849
+ }
4850
+ }
4851
+ if (reasoningPart) {
4852
+ reasoningPart.providerMetadata = (_d = chunk.providerMetadata) != null ? _d : reasoningPart.providerMetadata;
4853
+ reasoningPart.state = "done";
4854
+ }
4801
4855
  delete state.activeReasoningParts[chunk.id];
4802
4856
  write();
4803
4857
  break;
@@ -4866,7 +4920,24 @@ function processUIMessageStream({
4866
4920
  break;
4867
4921
  }
4868
4922
  case "tool-input-delta": {
4869
- const partialToolCall = state.partialToolCalls[chunk.toolCallId];
4923
+ let partialToolCall = state.partialToolCalls[chunk.toolCallId];
4924
+ if (!partialToolCall) {
4925
+ const existingPart = state.message.parts.find(
4926
+ (p) => isToolUIPart(p) && p.toolCallId === chunk.toolCallId
4927
+ );
4928
+ if (existingPart) {
4929
+ const isDynamic = existingPart.type === "dynamic-tool";
4930
+ partialToolCall = {
4931
+ text: "",
4932
+ toolName: getToolName(existingPart),
4933
+ index: state.message.parts.filter(isStaticToolUIPart).indexOf(existingPart),
4934
+ dynamic: isDynamic
4935
+ };
4936
+ state.partialToolCalls[chunk.toolCallId] = partialToolCall;
4937
+ } else {
4938
+ break;
4939
+ }
4940
+ }
4870
4941
  partialToolCall.text += chunk.inputTextDelta;
4871
4942
  const { value: partialArgs } = await parsePartialJson(
4872
4943
  partialToolCall.text