ai 5.0.23 → 5.0.25

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
@@ -3771,6 +3771,23 @@ function handleUIMessageStreamFinish({
3771
3771
  await job({ state, write: () => {
3772
3772
  } });
3773
3773
  };
3774
+ let finishCalled = false;
3775
+ const callOnFinish = async () => {
3776
+ if (finishCalled || !onFinish) {
3777
+ return;
3778
+ }
3779
+ finishCalled = true;
3780
+ const isContinuation = state.message.id === (lastMessage == null ? void 0 : lastMessage.id);
3781
+ await onFinish({
3782
+ isAborted,
3783
+ isContinuation,
3784
+ responseMessage: state.message,
3785
+ messages: [
3786
+ ...isContinuation ? originalMessages.slice(0, -1) : originalMessages,
3787
+ state.message
3788
+ ]
3789
+ });
3790
+ };
3774
3791
  return processUIMessageStream({
3775
3792
  stream: idInjectedStream,
3776
3793
  runUpdateMessageJob,
@@ -3780,17 +3797,12 @@ function handleUIMessageStreamFinish({
3780
3797
  transform(chunk, controller) {
3781
3798
  controller.enqueue(chunk);
3782
3799
  },
3800
+ // @ts-expect-error cancel is still new and missing from types https://developer.mozilla.org/en-US/docs/Web/API/TransformStream#browser_compatibility
3801
+ async cancel() {
3802
+ await callOnFinish();
3803
+ },
3783
3804
  async flush() {
3784
- const isContinuation = state.message.id === (lastMessage == null ? void 0 : lastMessage.id);
3785
- await onFinish({
3786
- isAborted,
3787
- isContinuation,
3788
- responseMessage: state.message,
3789
- messages: [
3790
- ...isContinuation ? originalMessages.slice(0, -1) : originalMessages,
3791
- state.message
3792
- ]
3793
- });
3805
+ await callOnFinish();
3794
3806
  }
3795
3807
  })
3796
3808
  );
@@ -9572,12 +9584,7 @@ function convertToModelMessages(messages, options) {
9572
9584
  });
9573
9585
  } else if (part.type === "dynamic-tool") {
9574
9586
  const toolName = part.toolName;
9575
- if (part.state === "input-streaming") {
9576
- throw new MessageConversionError({
9577
- originalMessage: message,
9578
- message: `incomplete tool input is not supported: ${part.toolCallId}`
9579
- });
9580
- } else {
9587
+ if (part.state !== "input-streaming") {
9581
9588
  content.push({
9582
9589
  type: "tool-call",
9583
9590
  toolCallId: part.toolCallId,
@@ -9588,12 +9595,7 @@ function convertToModelMessages(messages, options) {
9588
9595
  }
9589
9596
  } else if (isToolUIPart(part)) {
9590
9597
  const toolName = getToolName(part);
9591
- if (part.state === "input-streaming") {
9592
- throw new MessageConversionError({
9593
- originalMessage: message,
9594
- message: `incomplete tool input is not supported: ${part.toolCallId}`
9595
- });
9596
- } else {
9598
+ if (part.state !== "input-streaming") {
9597
9599
  content.push({
9598
9600
  type: "tool-call",
9599
9601
  toolCallId: part.toolCallId,
@@ -9648,13 +9650,12 @@ function convertToModelMessages(messages, options) {
9648
9650
  };
9649
9651
  }
9650
9652
  default: {
9651
- throw new MessageConversionError({
9652
- originalMessage: message,
9653
- message: `Unsupported tool part state: ${toolPart.state}`
9654
- });
9653
+ return null;
9655
9654
  }
9656
9655
  }
9657
- })
9656
+ }).filter(
9657
+ (output) => output != null
9658
+ )
9658
9659
  });
9659
9660
  }
9660
9661
  block = [];