ai 6.0.225 → 6.0.227
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 +17 -0
- package/dist/index.js +73 -31
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +73 -31
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +1 -1
- package/dist/internal/index.mjs +1 -1
- package/docs/03-ai-sdk-core/37-speech.mdx +1 -0
- package/package.json +3 -3
- package/src/generate-text/run-tools-transformation.ts +40 -10
- package/src/ui/chat.ts +24 -17
- package/src/ui/validate-ui-messages.ts +21 -9
package/dist/index.mjs
CHANGED
|
@@ -1171,7 +1171,7 @@ import {
|
|
|
1171
1171
|
} from "@ai-sdk/provider-utils";
|
|
1172
1172
|
|
|
1173
1173
|
// src/version.ts
|
|
1174
|
-
var VERSION = true ? "6.0.
|
|
1174
|
+
var VERSION = true ? "6.0.227" : "0.0.0-test";
|
|
1175
1175
|
|
|
1176
1176
|
// src/util/download/download.ts
|
|
1177
1177
|
var download = async ({
|
|
@@ -6539,11 +6539,35 @@ function runToolsTransformation({
|
|
|
6539
6539
|
onToolCallFinish
|
|
6540
6540
|
}) {
|
|
6541
6541
|
let toolResultsStreamController = null;
|
|
6542
|
+
let toolResultsStreamClosed = false;
|
|
6542
6543
|
const toolResultsStream = new ReadableStream({
|
|
6543
6544
|
start(controller) {
|
|
6544
6545
|
toolResultsStreamController = controller;
|
|
6546
|
+
},
|
|
6547
|
+
cancel() {
|
|
6548
|
+
toolResultsStreamClosed = true;
|
|
6545
6549
|
}
|
|
6546
6550
|
});
|
|
6551
|
+
function enqueueToolResult(chunk) {
|
|
6552
|
+
if (toolResultsStreamClosed) {
|
|
6553
|
+
return;
|
|
6554
|
+
}
|
|
6555
|
+
try {
|
|
6556
|
+
toolResultsStreamController.enqueue(chunk);
|
|
6557
|
+
} catch (e) {
|
|
6558
|
+
toolResultsStreamClosed = true;
|
|
6559
|
+
}
|
|
6560
|
+
}
|
|
6561
|
+
function closeToolResultsStream() {
|
|
6562
|
+
if (toolResultsStreamClosed) {
|
|
6563
|
+
return;
|
|
6564
|
+
}
|
|
6565
|
+
toolResultsStreamClosed = true;
|
|
6566
|
+
try {
|
|
6567
|
+
toolResultsStreamController.close();
|
|
6568
|
+
} catch (e) {
|
|
6569
|
+
}
|
|
6570
|
+
}
|
|
6547
6571
|
const outstandingToolResults = /* @__PURE__ */ new Set();
|
|
6548
6572
|
const toolCallsByToolCallId = /* @__PURE__ */ new Map();
|
|
6549
6573
|
let canClose = false;
|
|
@@ -6551,9 +6575,9 @@ function runToolsTransformation({
|
|
|
6551
6575
|
function attemptClose() {
|
|
6552
6576
|
if (canClose && outstandingToolResults.size === 0) {
|
|
6553
6577
|
if (finishChunk != null) {
|
|
6554
|
-
|
|
6578
|
+
enqueueToolResult(finishChunk);
|
|
6555
6579
|
}
|
|
6556
|
-
|
|
6580
|
+
closeToolResultsStream();
|
|
6557
6581
|
}
|
|
6558
6582
|
}
|
|
6559
6583
|
const forwardStream = new TransformStream({
|
|
@@ -6601,7 +6625,7 @@ function runToolsTransformation({
|
|
|
6601
6625
|
case "tool-approval-request": {
|
|
6602
6626
|
const toolCall = toolCallsByToolCallId.get(chunk.toolCallId);
|
|
6603
6627
|
if (toolCall == null) {
|
|
6604
|
-
|
|
6628
|
+
enqueueToolResult({
|
|
6605
6629
|
type: "error",
|
|
6606
6630
|
error: new ToolCallNotFoundForApprovalError({
|
|
6607
6631
|
toolCallId: chunk.toolCallId,
|
|
@@ -6629,7 +6653,7 @@ function runToolsTransformation({
|
|
|
6629
6653
|
toolCallsByToolCallId.set(toolCall.toolCallId, toolCall);
|
|
6630
6654
|
controller.enqueue(toolCall);
|
|
6631
6655
|
if (toolCall.invalid) {
|
|
6632
|
-
|
|
6656
|
+
enqueueToolResult({
|
|
6633
6657
|
type: "tool-error",
|
|
6634
6658
|
toolCallId: toolCall.toolCallId,
|
|
6635
6659
|
toolName: toolCall.toolName,
|
|
@@ -6668,7 +6692,7 @@ function runToolsTransformation({
|
|
|
6668
6692
|
toolName: toolCall.toolName,
|
|
6669
6693
|
input: toolCall.input
|
|
6670
6694
|
});
|
|
6671
|
-
|
|
6695
|
+
enqueueToolResult({
|
|
6672
6696
|
type: "tool-approval-request",
|
|
6673
6697
|
approvalId,
|
|
6674
6698
|
toolCall,
|
|
@@ -6692,12 +6716,12 @@ function runToolsTransformation({
|
|
|
6692
6716
|
onToolCallStart,
|
|
6693
6717
|
onToolCallFinish,
|
|
6694
6718
|
onPreliminaryToolResult: (result) => {
|
|
6695
|
-
|
|
6719
|
+
enqueueToolResult(result);
|
|
6696
6720
|
}
|
|
6697
6721
|
}).then((result) => {
|
|
6698
|
-
|
|
6722
|
+
enqueueToolResult(result);
|
|
6699
6723
|
}).catch((error) => {
|
|
6700
|
-
|
|
6724
|
+
enqueueToolResult({
|
|
6701
6725
|
type: "error",
|
|
6702
6726
|
error
|
|
6703
6727
|
});
|
|
@@ -6707,7 +6731,7 @@ function runToolsTransformation({
|
|
|
6707
6731
|
});
|
|
6708
6732
|
}
|
|
6709
6733
|
} catch (error) {
|
|
6710
|
-
|
|
6734
|
+
enqueueToolResult({ type: "error", error });
|
|
6711
6735
|
}
|
|
6712
6736
|
break;
|
|
6713
6737
|
}
|
|
@@ -6715,7 +6739,7 @@ function runToolsTransformation({
|
|
|
6715
6739
|
const toolName = chunk.toolName;
|
|
6716
6740
|
const toolCall = toolCallsByToolCallId.get(chunk.toolCallId);
|
|
6717
6741
|
if (chunk.isError) {
|
|
6718
|
-
|
|
6742
|
+
enqueueToolResult({
|
|
6719
6743
|
type: "tool-error",
|
|
6720
6744
|
toolCallId: chunk.toolCallId,
|
|
6721
6745
|
toolName,
|
|
@@ -9375,7 +9399,19 @@ var uiMessagesSchema = lazySchema2(
|
|
|
9375
9399
|
})
|
|
9376
9400
|
})
|
|
9377
9401
|
])
|
|
9378
|
-
)
|
|
9402
|
+
)
|
|
9403
|
+
}).superRefine((message, context2) => {
|
|
9404
|
+
if (message.role !== "assistant" && message.parts.length === 0) {
|
|
9405
|
+
context2.addIssue({
|
|
9406
|
+
origin: "array",
|
|
9407
|
+
code: "too_small",
|
|
9408
|
+
minimum: 1,
|
|
9409
|
+
inclusive: true,
|
|
9410
|
+
input: message.parts,
|
|
9411
|
+
path: ["parts"],
|
|
9412
|
+
message: "Message must contain at least one part"
|
|
9413
|
+
});
|
|
9414
|
+
}
|
|
9379
9415
|
})
|
|
9380
9416
|
).nonempty("Messages array must not be empty")
|
|
9381
9417
|
)
|
|
@@ -13782,7 +13818,7 @@ var AbstractChat = class {
|
|
|
13782
13818
|
body,
|
|
13783
13819
|
messageId
|
|
13784
13820
|
}) {
|
|
13785
|
-
var _a22, _b
|
|
13821
|
+
var _a22, _b;
|
|
13786
13822
|
let resumeStream;
|
|
13787
13823
|
if (trigger === "resume-stream") {
|
|
13788
13824
|
try {
|
|
@@ -13809,18 +13845,20 @@ var AbstractChat = class {
|
|
|
13809
13845
|
let isAbort = false;
|
|
13810
13846
|
let isDisconnect = false;
|
|
13811
13847
|
let isError = false;
|
|
13848
|
+
let activeResponse;
|
|
13812
13849
|
try {
|
|
13813
|
-
const
|
|
13850
|
+
const response = {
|
|
13814
13851
|
state: createStreamingUIMessageState({
|
|
13815
13852
|
lastMessage: this.state.snapshot(lastMessage),
|
|
13816
13853
|
messageId: this.generateId()
|
|
13817
13854
|
}),
|
|
13818
13855
|
abortController: new AbortController()
|
|
13819
13856
|
};
|
|
13820
|
-
activeResponse
|
|
13857
|
+
activeResponse = response;
|
|
13858
|
+
response.abortController.signal.addEventListener("abort", () => {
|
|
13821
13859
|
isAbort = true;
|
|
13822
13860
|
});
|
|
13823
|
-
this.activeResponse =
|
|
13861
|
+
this.activeResponse = response;
|
|
13824
13862
|
let stream;
|
|
13825
13863
|
if (trigger === "resume-stream") {
|
|
13826
13864
|
stream = resumeStream;
|
|
@@ -13828,7 +13866,7 @@ var AbstractChat = class {
|
|
|
13828
13866
|
stream = await this.transport.sendMessages({
|
|
13829
13867
|
chatId: this.id,
|
|
13830
13868
|
messages: this.state.messages,
|
|
13831
|
-
abortSignal:
|
|
13869
|
+
abortSignal: response.abortController.signal,
|
|
13832
13870
|
metadata,
|
|
13833
13871
|
headers,
|
|
13834
13872
|
body,
|
|
@@ -13840,18 +13878,18 @@ var AbstractChat = class {
|
|
|
13840
13878
|
// serialize the job execution to avoid race conditions:
|
|
13841
13879
|
this.jobExecutor.run(
|
|
13842
13880
|
() => job({
|
|
13843
|
-
state:
|
|
13881
|
+
state: response.state,
|
|
13844
13882
|
write: () => {
|
|
13845
13883
|
var _a23;
|
|
13846
13884
|
this.setStatus({ status: "streaming" });
|
|
13847
|
-
const replaceLastMessage =
|
|
13885
|
+
const replaceLastMessage = response.state.message.id === ((_a23 = this.lastMessage) == null ? void 0 : _a23.id);
|
|
13848
13886
|
if (replaceLastMessage) {
|
|
13849
13887
|
this.state.replaceMessage(
|
|
13850
13888
|
this.state.messages.length - 1,
|
|
13851
|
-
|
|
13889
|
+
response.state.message
|
|
13852
13890
|
);
|
|
13853
13891
|
} else {
|
|
13854
|
-
this.state.pushMessage(
|
|
13892
|
+
this.state.pushMessage(response.state.message);
|
|
13855
13893
|
}
|
|
13856
13894
|
}
|
|
13857
13895
|
})
|
|
@@ -13890,23 +13928,27 @@ var AbstractChat = class {
|
|
|
13890
13928
|
this.setStatus({ status: "error", error: err });
|
|
13891
13929
|
} finally {
|
|
13892
13930
|
try {
|
|
13893
|
-
(
|
|
13894
|
-
|
|
13895
|
-
|
|
13896
|
-
|
|
13897
|
-
|
|
13898
|
-
|
|
13899
|
-
|
|
13900
|
-
|
|
13931
|
+
if (activeResponse) {
|
|
13932
|
+
(_a22 = this.onFinish) == null ? void 0 : _a22.call(this, {
|
|
13933
|
+
message: activeResponse.state.message,
|
|
13934
|
+
messages: this.state.messages,
|
|
13935
|
+
isAbort,
|
|
13936
|
+
isDisconnect,
|
|
13937
|
+
isError,
|
|
13938
|
+
finishReason: activeResponse.state.finishReason
|
|
13939
|
+
});
|
|
13940
|
+
}
|
|
13901
13941
|
} catch (err) {
|
|
13902
13942
|
console.error(err);
|
|
13903
13943
|
}
|
|
13904
|
-
this.activeResponse
|
|
13944
|
+
if (this.activeResponse === activeResponse) {
|
|
13945
|
+
this.activeResponse = void 0;
|
|
13946
|
+
}
|
|
13905
13947
|
}
|
|
13906
13948
|
if (!isError && await this.shouldSendAutomatically()) {
|
|
13907
13949
|
await this.makeRequest({
|
|
13908
13950
|
trigger: "submit-message",
|
|
13909
|
-
messageId: (
|
|
13951
|
+
messageId: (_b = this.lastMessage) == null ? void 0 : _b.id,
|
|
13910
13952
|
metadata,
|
|
13911
13953
|
headers,
|
|
13912
13954
|
body
|