ai 5.0.267 → 5.0.268
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.d.mts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +47 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +47 -4
- 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/dist/index.mjs
CHANGED
|
@@ -727,7 +727,7 @@ import {
|
|
|
727
727
|
} from "@ai-sdk/provider-utils";
|
|
728
728
|
|
|
729
729
|
// src/version.ts
|
|
730
|
-
var VERSION = true ? "5.0.
|
|
730
|
+
var VERSION = true ? "5.0.268" : "0.0.0-test";
|
|
731
731
|
|
|
732
732
|
// src/util/download/download.ts
|
|
733
733
|
var download = async ({
|
|
@@ -2935,21 +2935,44 @@ function writeToServerResponse({
|
|
|
2935
2935
|
response.writeHead(statusCode, headers);
|
|
2936
2936
|
}
|
|
2937
2937
|
const reader = stream.getReader();
|
|
2938
|
+
let clientDisconnected = false;
|
|
2939
|
+
let onDisconnect;
|
|
2940
|
+
const handleClose = () => {
|
|
2941
|
+
if (response.writableFinished) {
|
|
2942
|
+
return;
|
|
2943
|
+
}
|
|
2944
|
+
clientDisconnected = true;
|
|
2945
|
+
onDisconnect == null ? void 0 : onDisconnect();
|
|
2946
|
+
reader.cancel(new Error("Client disconnected.")).catch(() => {
|
|
2947
|
+
});
|
|
2948
|
+
};
|
|
2949
|
+
response.once("close", handleClose);
|
|
2950
|
+
if (response.destroyed) {
|
|
2951
|
+
handleClose();
|
|
2952
|
+
}
|
|
2938
2953
|
const read = async () => {
|
|
2939
2954
|
try {
|
|
2940
2955
|
while (true) {
|
|
2941
2956
|
const { done, value } = await reader.read();
|
|
2942
|
-
if (done)
|
|
2957
|
+
if (done || clientDisconnected || response.destroyed)
|
|
2943
2958
|
break;
|
|
2944
2959
|
const canContinue = response.write(value);
|
|
2945
2960
|
if (!canContinue) {
|
|
2946
2961
|
await new Promise((resolve2) => {
|
|
2962
|
+
onDisconnect = resolve2;
|
|
2947
2963
|
response.once("drain", resolve2);
|
|
2948
2964
|
});
|
|
2965
|
+
onDisconnect = void 0;
|
|
2949
2966
|
}
|
|
2950
2967
|
}
|
|
2951
2968
|
} finally {
|
|
2952
|
-
response.
|
|
2969
|
+
response.off("close", handleClose);
|
|
2970
|
+
if (clientDisconnected || response.destroyed) {
|
|
2971
|
+
reader.cancel().catch(() => {
|
|
2972
|
+
});
|
|
2973
|
+
} else {
|
|
2974
|
+
response.end();
|
|
2975
|
+
}
|
|
2953
2976
|
}
|
|
2954
2977
|
};
|
|
2955
2978
|
return read();
|
|
@@ -9737,6 +9760,7 @@ var AbstractChat = class {
|
|
|
9737
9760
|
}) {
|
|
9738
9761
|
this.activeResponse = void 0;
|
|
9739
9762
|
this.activeResumeRequest = void 0;
|
|
9763
|
+
this.resumableStreamState = void 0;
|
|
9740
9764
|
this.jobExecutor = new SerialJobExecutor();
|
|
9741
9765
|
/**
|
|
9742
9766
|
* Appends or replaces a user message to the chat list. This triggers the API call to fetch
|
|
@@ -9932,6 +9956,9 @@ var AbstractChat = class {
|
|
|
9932
9956
|
messageId
|
|
9933
9957
|
}) {
|
|
9934
9958
|
var _a16, _b, _c, _d;
|
|
9959
|
+
if (trigger !== "resume-stream") {
|
|
9960
|
+
this.resumableStreamState = void 0;
|
|
9961
|
+
}
|
|
9935
9962
|
const abortController = new AbortController();
|
|
9936
9963
|
const activeResumeRequest = trigger === "resume-stream" ? { abortController } : void 0;
|
|
9937
9964
|
if (activeResumeRequest) {
|
|
@@ -9952,7 +9979,7 @@ var AbstractChat = class {
|
|
|
9952
9979
|
let activeResponse;
|
|
9953
9980
|
try {
|
|
9954
9981
|
const response = {
|
|
9955
|
-
state: createStreamingUIMessageState({
|
|
9982
|
+
state: trigger === "resume-stream" && this.resumableStreamState != null ? this.resumableStreamState : createStreamingUIMessageState({
|
|
9956
9983
|
lastMessage: trigger === "resume-stream" ? void 0 : this.state.snapshot(lastMessage),
|
|
9957
9984
|
messageId: this.generateId()
|
|
9958
9985
|
}),
|
|
@@ -9977,12 +10004,14 @@ var AbstractChat = class {
|
|
|
9977
10004
|
}));
|
|
9978
10005
|
if (isCurrentRequest()) {
|
|
9979
10006
|
this.setStatus({ status: "ready" });
|
|
10007
|
+
this.resumableStreamState = void 0;
|
|
9980
10008
|
}
|
|
9981
10009
|
return;
|
|
9982
10010
|
}
|
|
9983
10011
|
if (reconnect == null) {
|
|
9984
10012
|
if (isCurrentRequest()) {
|
|
9985
10013
|
this.setStatus({ status: "ready" });
|
|
10014
|
+
this.resumableStreamState = void 0;
|
|
9986
10015
|
}
|
|
9987
10016
|
return;
|
|
9988
10017
|
}
|
|
@@ -10048,17 +10077,26 @@ var AbstractChat = class {
|
|
|
10048
10077
|
if (isAbort) {
|
|
10049
10078
|
if (isCurrentRequest()) {
|
|
10050
10079
|
this.setStatus({ status: "ready" });
|
|
10080
|
+
if (this.resumableStreamState === response.state) {
|
|
10081
|
+
this.resumableStreamState = void 0;
|
|
10082
|
+
}
|
|
10051
10083
|
}
|
|
10052
10084
|
return null;
|
|
10053
10085
|
}
|
|
10054
10086
|
if (isCurrentRequest()) {
|
|
10055
10087
|
this.setStatus({ status: "ready" });
|
|
10088
|
+
if (this.resumableStreamState === response.state) {
|
|
10089
|
+
this.resumableStreamState = void 0;
|
|
10090
|
+
}
|
|
10056
10091
|
}
|
|
10057
10092
|
} catch (err) {
|
|
10058
10093
|
if (isAbort || err.name === "AbortError") {
|
|
10059
10094
|
isAbort = true;
|
|
10060
10095
|
if (isCurrentRequest()) {
|
|
10061
10096
|
this.setStatus({ status: "ready" });
|
|
10097
|
+
if (this.resumableStreamState === (activeResponse == null ? void 0 : activeResponse.state)) {
|
|
10098
|
+
this.resumableStreamState = void 0;
|
|
10099
|
+
}
|
|
10062
10100
|
}
|
|
10063
10101
|
return null;
|
|
10064
10102
|
}
|
|
@@ -10069,6 +10107,11 @@ var AbstractChat = class {
|
|
|
10069
10107
|
if (err instanceof TypeError && (err.message.toLowerCase().includes("fetch") || err.message.toLowerCase().includes("network"))) {
|
|
10070
10108
|
isDisconnect = true;
|
|
10071
10109
|
}
|
|
10110
|
+
if (isDisconnect) {
|
|
10111
|
+
this.resumableStreamState = activeResponse == null ? void 0 : activeResponse.state;
|
|
10112
|
+
} else if (this.resumableStreamState === (activeResponse == null ? void 0 : activeResponse.state)) {
|
|
10113
|
+
this.resumableStreamState = void 0;
|
|
10114
|
+
}
|
|
10072
10115
|
if (this.onError && err instanceof Error) {
|
|
10073
10116
|
this.onError(err);
|
|
10074
10117
|
}
|