ai 6.0.225 → 6.0.226
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/CHANGELOG.md +11 -0
- package/dist/index.js +48 -12
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +48 -12
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +1 -1
- package/dist/internal/index.mjs +1 -1
- package/package.json +3 -3
- package/src/generate-text/run-tools-transformation.ts +40 -10
- package/src/ui/validate-ui-messages.ts +21 -9
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# ai
|
|
2
2
|
|
|
3
|
+
## 6.0.226
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 94219a2: Allow validating assistant UI messages with empty parts so persisted errored responses remain loadable.
|
|
8
|
+
- b1be847: Prevent pending tool executions from enqueueing results after a model stream error closes the result stream.
|
|
9
|
+
- Updated dependencies [06fb54c]
|
|
10
|
+
- Updated dependencies [bc46977]
|
|
11
|
+
- @ai-sdk/provider-utils@4.0.39
|
|
12
|
+
- @ai-sdk/gateway@3.0.150
|
|
13
|
+
|
|
3
14
|
## 6.0.225
|
|
4
15
|
|
|
5
16
|
### Patch Changes
|
package/dist/index.js
CHANGED
|
@@ -1282,7 +1282,7 @@ function detectMediaType({
|
|
|
1282
1282
|
var import_provider_utils3 = require("@ai-sdk/provider-utils");
|
|
1283
1283
|
|
|
1284
1284
|
// src/version.ts
|
|
1285
|
-
var VERSION = true ? "6.0.
|
|
1285
|
+
var VERSION = true ? "6.0.226" : "0.0.0-test";
|
|
1286
1286
|
|
|
1287
1287
|
// src/util/download/download.ts
|
|
1288
1288
|
var download = async ({
|
|
@@ -6611,11 +6611,35 @@ function runToolsTransformation({
|
|
|
6611
6611
|
onToolCallFinish
|
|
6612
6612
|
}) {
|
|
6613
6613
|
let toolResultsStreamController = null;
|
|
6614
|
+
let toolResultsStreamClosed = false;
|
|
6614
6615
|
const toolResultsStream = new ReadableStream({
|
|
6615
6616
|
start(controller) {
|
|
6616
6617
|
toolResultsStreamController = controller;
|
|
6618
|
+
},
|
|
6619
|
+
cancel() {
|
|
6620
|
+
toolResultsStreamClosed = true;
|
|
6617
6621
|
}
|
|
6618
6622
|
});
|
|
6623
|
+
function enqueueToolResult(chunk) {
|
|
6624
|
+
if (toolResultsStreamClosed) {
|
|
6625
|
+
return;
|
|
6626
|
+
}
|
|
6627
|
+
try {
|
|
6628
|
+
toolResultsStreamController.enqueue(chunk);
|
|
6629
|
+
} catch (e) {
|
|
6630
|
+
toolResultsStreamClosed = true;
|
|
6631
|
+
}
|
|
6632
|
+
}
|
|
6633
|
+
function closeToolResultsStream() {
|
|
6634
|
+
if (toolResultsStreamClosed) {
|
|
6635
|
+
return;
|
|
6636
|
+
}
|
|
6637
|
+
toolResultsStreamClosed = true;
|
|
6638
|
+
try {
|
|
6639
|
+
toolResultsStreamController.close();
|
|
6640
|
+
} catch (e) {
|
|
6641
|
+
}
|
|
6642
|
+
}
|
|
6619
6643
|
const outstandingToolResults = /* @__PURE__ */ new Set();
|
|
6620
6644
|
const toolCallsByToolCallId = /* @__PURE__ */ new Map();
|
|
6621
6645
|
let canClose = false;
|
|
@@ -6623,9 +6647,9 @@ function runToolsTransformation({
|
|
|
6623
6647
|
function attemptClose() {
|
|
6624
6648
|
if (canClose && outstandingToolResults.size === 0) {
|
|
6625
6649
|
if (finishChunk != null) {
|
|
6626
|
-
|
|
6650
|
+
enqueueToolResult(finishChunk);
|
|
6627
6651
|
}
|
|
6628
|
-
|
|
6652
|
+
closeToolResultsStream();
|
|
6629
6653
|
}
|
|
6630
6654
|
}
|
|
6631
6655
|
const forwardStream = new TransformStream({
|
|
@@ -6673,7 +6697,7 @@ function runToolsTransformation({
|
|
|
6673
6697
|
case "tool-approval-request": {
|
|
6674
6698
|
const toolCall = toolCallsByToolCallId.get(chunk.toolCallId);
|
|
6675
6699
|
if (toolCall == null) {
|
|
6676
|
-
|
|
6700
|
+
enqueueToolResult({
|
|
6677
6701
|
type: "error",
|
|
6678
6702
|
error: new ToolCallNotFoundForApprovalError({
|
|
6679
6703
|
toolCallId: chunk.toolCallId,
|
|
@@ -6701,7 +6725,7 @@ function runToolsTransformation({
|
|
|
6701
6725
|
toolCallsByToolCallId.set(toolCall.toolCallId, toolCall);
|
|
6702
6726
|
controller.enqueue(toolCall);
|
|
6703
6727
|
if (toolCall.invalid) {
|
|
6704
|
-
|
|
6728
|
+
enqueueToolResult({
|
|
6705
6729
|
type: "tool-error",
|
|
6706
6730
|
toolCallId: toolCall.toolCallId,
|
|
6707
6731
|
toolName: toolCall.toolName,
|
|
@@ -6740,7 +6764,7 @@ function runToolsTransformation({
|
|
|
6740
6764
|
toolName: toolCall.toolName,
|
|
6741
6765
|
input: toolCall.input
|
|
6742
6766
|
});
|
|
6743
|
-
|
|
6767
|
+
enqueueToolResult({
|
|
6744
6768
|
type: "tool-approval-request",
|
|
6745
6769
|
approvalId,
|
|
6746
6770
|
toolCall,
|
|
@@ -6764,12 +6788,12 @@ function runToolsTransformation({
|
|
|
6764
6788
|
onToolCallStart,
|
|
6765
6789
|
onToolCallFinish,
|
|
6766
6790
|
onPreliminaryToolResult: (result) => {
|
|
6767
|
-
|
|
6791
|
+
enqueueToolResult(result);
|
|
6768
6792
|
}
|
|
6769
6793
|
}).then((result) => {
|
|
6770
|
-
|
|
6794
|
+
enqueueToolResult(result);
|
|
6771
6795
|
}).catch((error) => {
|
|
6772
|
-
|
|
6796
|
+
enqueueToolResult({
|
|
6773
6797
|
type: "error",
|
|
6774
6798
|
error
|
|
6775
6799
|
});
|
|
@@ -6779,7 +6803,7 @@ function runToolsTransformation({
|
|
|
6779
6803
|
});
|
|
6780
6804
|
}
|
|
6781
6805
|
} catch (error) {
|
|
6782
|
-
|
|
6806
|
+
enqueueToolResult({ type: "error", error });
|
|
6783
6807
|
}
|
|
6784
6808
|
break;
|
|
6785
6809
|
}
|
|
@@ -6787,7 +6811,7 @@ function runToolsTransformation({
|
|
|
6787
6811
|
const toolName = chunk.toolName;
|
|
6788
6812
|
const toolCall = toolCallsByToolCallId.get(chunk.toolCallId);
|
|
6789
6813
|
if (chunk.isError) {
|
|
6790
|
-
|
|
6814
|
+
enqueueToolResult({
|
|
6791
6815
|
type: "tool-error",
|
|
6792
6816
|
toolCallId: chunk.toolCallId,
|
|
6793
6817
|
toolName,
|
|
@@ -9437,7 +9461,19 @@ var uiMessagesSchema = (0, import_provider_utils24.lazySchema)(
|
|
|
9437
9461
|
})
|
|
9438
9462
|
})
|
|
9439
9463
|
])
|
|
9440
|
-
)
|
|
9464
|
+
)
|
|
9465
|
+
}).superRefine((message, context2) => {
|
|
9466
|
+
if (message.role !== "assistant" && message.parts.length === 0) {
|
|
9467
|
+
context2.addIssue({
|
|
9468
|
+
origin: "array",
|
|
9469
|
+
code: "too_small",
|
|
9470
|
+
minimum: 1,
|
|
9471
|
+
inclusive: true,
|
|
9472
|
+
input: message.parts,
|
|
9473
|
+
path: ["parts"],
|
|
9474
|
+
message: "Message must contain at least one part"
|
|
9475
|
+
});
|
|
9476
|
+
}
|
|
9441
9477
|
})
|
|
9442
9478
|
).nonempty("Messages array must not be empty")
|
|
9443
9479
|
)
|