ai 5.0.248 → 5.0.250
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 +22 -0
- package/dist/index.d.mts +44 -19
- package/dist/index.d.ts +44 -19
- package/dist/index.js +266 -56
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +264 -53
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +4 -3
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +4 -3
- package/dist/internal/index.mjs.map +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.250" : "0.0.0-test";
|
|
731
731
|
|
|
732
732
|
// src/util/download/download.ts
|
|
733
733
|
var download = async ({
|
|
@@ -1744,12 +1744,13 @@ function asArray(value) {
|
|
|
1744
1744
|
|
|
1745
1745
|
// src/util/retry-with-exponential-backoff.ts
|
|
1746
1746
|
import { APICallError as APICallError2 } from "@ai-sdk/provider";
|
|
1747
|
+
import { GatewayError } from "@ai-sdk/gateway";
|
|
1747
1748
|
import { delay, getErrorMessage as getErrorMessage3, isAbortError } from "@ai-sdk/provider-utils";
|
|
1748
1749
|
function getRetryDelayInMs({
|
|
1749
1750
|
error,
|
|
1750
1751
|
exponentialBackoffDelay
|
|
1751
1752
|
}) {
|
|
1752
|
-
const headers = error.responseHeaders;
|
|
1753
|
+
const headers = APICallError2.isInstance(error) ? error.responseHeaders : APICallError2.isInstance(error.cause) ? error.cause.responseHeaders : void 0;
|
|
1753
1754
|
if (!headers)
|
|
1754
1755
|
return exponentialBackoffDelay;
|
|
1755
1756
|
let ms;
|
|
@@ -1810,7 +1811,7 @@ async function _retryWithExponentialBackoff(f, {
|
|
|
1810
1811
|
errors: newErrors
|
|
1811
1812
|
});
|
|
1812
1813
|
}
|
|
1813
|
-
if (error instanceof Error && APICallError2.isInstance(error) && error.isRetryable === true && tryNumber <= maxRetries) {
|
|
1814
|
+
if (error instanceof Error && (APICallError2.isInstance(error) && error.isRetryable === true || GatewayError.isInstance(error) && error.isRetryable === true) && tryNumber <= maxRetries) {
|
|
1814
1815
|
await delay(
|
|
1815
1816
|
getRetryDelayInMs({
|
|
1816
1817
|
error,
|
|
@@ -4072,7 +4073,8 @@ function handleUIMessageStreamFinish({
|
|
|
4072
4073
|
originalMessages = [],
|
|
4073
4074
|
onFinish,
|
|
4074
4075
|
onError,
|
|
4075
|
-
stream
|
|
4076
|
+
stream,
|
|
4077
|
+
getOutcome
|
|
4076
4078
|
}) {
|
|
4077
4079
|
let lastMessage = originalMessages == null ? void 0 : originalMessages[originalMessages.length - 1];
|
|
4078
4080
|
if ((lastMessage == null ? void 0 : lastMessage.role) !== "assistant") {
|
|
@@ -4081,19 +4083,34 @@ function handleUIMessageStreamFinish({
|
|
|
4081
4083
|
messageId = lastMessage.id;
|
|
4082
4084
|
}
|
|
4083
4085
|
let isAborted = false;
|
|
4086
|
+
let hasProcessingFailure = false;
|
|
4087
|
+
let processingError;
|
|
4088
|
+
const recordProcessingFailure = (error) => {
|
|
4089
|
+
hasProcessingFailure = true;
|
|
4090
|
+
processingError = error;
|
|
4091
|
+
};
|
|
4084
4092
|
const idInjectedStream = stream.pipeThrough(
|
|
4085
4093
|
new TransformStream({
|
|
4086
4094
|
transform(chunk, controller) {
|
|
4087
|
-
|
|
4088
|
-
|
|
4089
|
-
if (
|
|
4090
|
-
startChunk
|
|
4095
|
+
try {
|
|
4096
|
+
let outputChunk = chunk;
|
|
4097
|
+
if (chunk.type === "start") {
|
|
4098
|
+
const startChunk = chunk;
|
|
4099
|
+
if (startChunk.messageId == null && messageId != null) {
|
|
4100
|
+
outputChunk = {
|
|
4101
|
+
...startChunk,
|
|
4102
|
+
messageId
|
|
4103
|
+
};
|
|
4104
|
+
}
|
|
4091
4105
|
}
|
|
4106
|
+
if (chunk.type === "abort") {
|
|
4107
|
+
isAborted = true;
|
|
4108
|
+
}
|
|
4109
|
+
controller.enqueue(outputChunk);
|
|
4110
|
+
} catch (error) {
|
|
4111
|
+
recordProcessingFailure(error);
|
|
4112
|
+
throw error;
|
|
4092
4113
|
}
|
|
4093
|
-
if (chunk.type === "abort") {
|
|
4094
|
-
isAborted = true;
|
|
4095
|
-
}
|
|
4096
|
-
controller.enqueue(chunk);
|
|
4097
4114
|
}
|
|
4098
4115
|
})
|
|
4099
4116
|
);
|
|
@@ -4106,19 +4123,28 @@ function handleUIMessageStreamFinish({
|
|
|
4106
4123
|
// will be overridden by the stream
|
|
4107
4124
|
});
|
|
4108
4125
|
const runUpdateMessageJob = async (job) => {
|
|
4109
|
-
|
|
4110
|
-
|
|
4126
|
+
try {
|
|
4127
|
+
await job({ state, write: () => {
|
|
4128
|
+
} });
|
|
4129
|
+
} catch (error) {
|
|
4130
|
+
recordProcessingFailure(error);
|
|
4131
|
+
throw error;
|
|
4132
|
+
}
|
|
4111
4133
|
};
|
|
4112
4134
|
let finishCalled = false;
|
|
4113
4135
|
const callOnFinish = async () => {
|
|
4136
|
+
var _a16;
|
|
4114
4137
|
if (finishCalled || !onFinish) {
|
|
4115
4138
|
return;
|
|
4116
4139
|
}
|
|
4117
4140
|
finishCalled = true;
|
|
4118
4141
|
const isContinuation = state.message.id === (lastMessage == null ? void 0 : lastMessage.id);
|
|
4142
|
+
const declaredOutcome = (_a16 = getOutcome == null ? void 0 : getOutcome()) != null ? _a16 : { status: "unknown" };
|
|
4143
|
+
const outcome = hasProcessingFailure ? { status: "failed", error: processingError } : declaredOutcome.status === "unknown" && isAborted ? { status: "aborted" } : declaredOutcome;
|
|
4119
4144
|
await onFinish({
|
|
4120
|
-
isAborted,
|
|
4145
|
+
isAborted: isAborted || outcome.status === "aborted",
|
|
4121
4146
|
isContinuation,
|
|
4147
|
+
outcome,
|
|
4122
4148
|
responseMessage: state.message,
|
|
4123
4149
|
messages: [
|
|
4124
4150
|
...isContinuation ? originalMessages.slice(0, -1) : originalMessages,
|
|
@@ -5715,6 +5741,17 @@ var DefaultStreamTextResult = class {
|
|
|
5715
5741
|
onError = () => "An error occurred."
|
|
5716
5742
|
// prevent leaking server error details to the client by default
|
|
5717
5743
|
} = {}) {
|
|
5744
|
+
let outcome = { status: "unknown" };
|
|
5745
|
+
let hasFatalFailure = false;
|
|
5746
|
+
const setSourceOutcome = (newOutcome) => {
|
|
5747
|
+
if (!hasFatalFailure && outcome.status !== "completed" && outcome.status !== "aborted" && newOutcome.status !== "unknown" && (outcome.status === "unknown" || newOutcome.status !== "failed")) {
|
|
5748
|
+
outcome = newOutcome;
|
|
5749
|
+
}
|
|
5750
|
+
};
|
|
5751
|
+
const failOutcome = (error) => {
|
|
5752
|
+
hasFatalFailure = true;
|
|
5753
|
+
outcome = { status: "failed", error };
|
|
5754
|
+
};
|
|
5718
5755
|
const responseMessageId = generateMessageId != null ? getResponseUIMessageId({
|
|
5719
5756
|
originalMessages,
|
|
5720
5757
|
responseMessageId: generateMessageId
|
|
@@ -5726,7 +5763,48 @@ var DefaultStreamTextResult = class {
|
|
|
5726
5763
|
const dynamic = ((_b = (_a16 = this.tools) == null ? void 0 : _a16[toolName]) == null ? void 0 : _b.type) === "dynamic";
|
|
5727
5764
|
return dynamic ? true : void 0;
|
|
5728
5765
|
};
|
|
5729
|
-
const
|
|
5766
|
+
const sourceReader = this.fullStream.getReader();
|
|
5767
|
+
let sourceReaderReleased = false;
|
|
5768
|
+
let sourceStreamCancelled = false;
|
|
5769
|
+
const releaseSourceReader = () => {
|
|
5770
|
+
if (!sourceReaderReleased) {
|
|
5771
|
+
sourceReader.releaseLock();
|
|
5772
|
+
sourceReaderReleased = true;
|
|
5773
|
+
}
|
|
5774
|
+
};
|
|
5775
|
+
const sourceStream = new ReadableStream({
|
|
5776
|
+
async pull(controller) {
|
|
5777
|
+
try {
|
|
5778
|
+
const { done, value } = await sourceReader.read();
|
|
5779
|
+
if (done) {
|
|
5780
|
+
releaseSourceReader();
|
|
5781
|
+
if (!sourceStreamCancelled) {
|
|
5782
|
+
controller.close();
|
|
5783
|
+
}
|
|
5784
|
+
} else {
|
|
5785
|
+
controller.enqueue(value);
|
|
5786
|
+
}
|
|
5787
|
+
} catch (error) {
|
|
5788
|
+
releaseSourceReader();
|
|
5789
|
+
if (!sourceStreamCancelled) {
|
|
5790
|
+
failOutcome(error);
|
|
5791
|
+
controller.error(error);
|
|
5792
|
+
}
|
|
5793
|
+
}
|
|
5794
|
+
},
|
|
5795
|
+
async cancel(reason) {
|
|
5796
|
+
sourceStreamCancelled = true;
|
|
5797
|
+
if (sourceReaderReleased) {
|
|
5798
|
+
return;
|
|
5799
|
+
}
|
|
5800
|
+
try {
|
|
5801
|
+
await sourceReader.cancel(reason);
|
|
5802
|
+
} finally {
|
|
5803
|
+
releaseSourceReader();
|
|
5804
|
+
}
|
|
5805
|
+
}
|
|
5806
|
+
});
|
|
5807
|
+
const baseStream = sourceStream.pipeThrough(
|
|
5730
5808
|
new TransformStream({
|
|
5731
5809
|
transform: async (part, controller) => {
|
|
5732
5810
|
const messageMetadataValue = messageMetadata == null ? void 0 : messageMetadata({ part });
|
|
@@ -5940,16 +6018,65 @@ var DefaultStreamTextResult = class {
|
|
|
5940
6018
|
messageMetadata: messageMetadataValue
|
|
5941
6019
|
});
|
|
5942
6020
|
}
|
|
6021
|
+
if (part.type === "finish") {
|
|
6022
|
+
setSourceOutcome({ status: "completed" });
|
|
6023
|
+
} else if (part.type === "abort") {
|
|
6024
|
+
setSourceOutcome({ status: "aborted" });
|
|
6025
|
+
} else if (part.type === "error") {
|
|
6026
|
+
setSourceOutcome({ status: "failed", error: part.error });
|
|
6027
|
+
}
|
|
5943
6028
|
}
|
|
5944
6029
|
})
|
|
5945
6030
|
);
|
|
6031
|
+
const baseStreamReader = baseStream.getReader();
|
|
6032
|
+
let baseStreamReaderReleased = false;
|
|
6033
|
+
let baseStreamCancelled = false;
|
|
6034
|
+
const releaseBaseStreamReader = () => {
|
|
6035
|
+
if (!baseStreamReaderReleased) {
|
|
6036
|
+
baseStreamReader.releaseLock();
|
|
6037
|
+
baseStreamReaderReleased = true;
|
|
6038
|
+
}
|
|
6039
|
+
};
|
|
6040
|
+
const trackedBaseStream = new ReadableStream({
|
|
6041
|
+
async pull(controller) {
|
|
6042
|
+
try {
|
|
6043
|
+
const { done, value } = await baseStreamReader.read();
|
|
6044
|
+
if (done) {
|
|
6045
|
+
releaseBaseStreamReader();
|
|
6046
|
+
if (!baseStreamCancelled) {
|
|
6047
|
+
controller.close();
|
|
6048
|
+
}
|
|
6049
|
+
} else {
|
|
6050
|
+
controller.enqueue(value);
|
|
6051
|
+
}
|
|
6052
|
+
} catch (error) {
|
|
6053
|
+
releaseBaseStreamReader();
|
|
6054
|
+
if (!baseStreamCancelled) {
|
|
6055
|
+
failOutcome(error);
|
|
6056
|
+
controller.error(error);
|
|
6057
|
+
}
|
|
6058
|
+
}
|
|
6059
|
+
},
|
|
6060
|
+
async cancel(reason) {
|
|
6061
|
+
baseStreamCancelled = true;
|
|
6062
|
+
if (baseStreamReaderReleased) {
|
|
6063
|
+
return;
|
|
6064
|
+
}
|
|
6065
|
+
try {
|
|
6066
|
+
await baseStreamReader.cancel(reason);
|
|
6067
|
+
} finally {
|
|
6068
|
+
releaseBaseStreamReader();
|
|
6069
|
+
}
|
|
6070
|
+
}
|
|
6071
|
+
});
|
|
5946
6072
|
return createAsyncIterableStream(
|
|
5947
6073
|
handleUIMessageStreamFinish({
|
|
5948
|
-
stream:
|
|
6074
|
+
stream: trackedBaseStream,
|
|
5949
6075
|
messageId: responseMessageId != null ? responseMessageId : generateMessageId == null ? void 0 : generateMessageId(),
|
|
5950
6076
|
originalMessages,
|
|
5951
6077
|
onFinish,
|
|
5952
|
-
onError
|
|
6078
|
+
onError,
|
|
6079
|
+
getOutcome: () => outcome
|
|
5953
6080
|
})
|
|
5954
6081
|
);
|
|
5955
6082
|
}
|
|
@@ -9955,10 +10082,38 @@ var TextStreamChatTransport = class extends HttpChatTransport {
|
|
|
9955
10082
|
import { TypeValidationError as TypeValidationError4 } from "@ai-sdk/provider";
|
|
9956
10083
|
import {
|
|
9957
10084
|
lazyValidator as lazyValidator2,
|
|
10085
|
+
safeValidateTypes as safeValidateTypes5,
|
|
9958
10086
|
validateTypes as validateTypes2,
|
|
9959
10087
|
zodSchema as zodSchema2
|
|
9960
10088
|
} from "@ai-sdk/provider-utils";
|
|
9961
10089
|
import { z as z8 } from "zod/v4";
|
|
10090
|
+
function isEmptyObject(value) {
|
|
10091
|
+
return value != null && typeof value === "object" && !Array.isArray(value) && Object.keys(value).length === 0;
|
|
10092
|
+
}
|
|
10093
|
+
function asDynamicToolPart(toolPart) {
|
|
10094
|
+
const common = {
|
|
10095
|
+
type: "dynamic-tool",
|
|
10096
|
+
toolName: toolPart.type.slice(5),
|
|
10097
|
+
toolCallId: toolPart.toolCallId,
|
|
10098
|
+
...toolPart.providerExecuted === void 0 ? {} : { providerExecuted: toolPart.providerExecuted },
|
|
10099
|
+
...toolPart.callProviderMetadata === void 0 ? {} : { callProviderMetadata: toolPart.callProviderMetadata }
|
|
10100
|
+
};
|
|
10101
|
+
if (toolPart.state === "output-available") {
|
|
10102
|
+
return {
|
|
10103
|
+
...common,
|
|
10104
|
+
state: "output-available",
|
|
10105
|
+
input: toolPart.input,
|
|
10106
|
+
output: toolPart.output,
|
|
10107
|
+
...toolPart.preliminary === void 0 ? {} : { preliminary: toolPart.preliminary }
|
|
10108
|
+
};
|
|
10109
|
+
}
|
|
10110
|
+
return {
|
|
10111
|
+
...common,
|
|
10112
|
+
state: "output-error",
|
|
10113
|
+
input: toolPart.input,
|
|
10114
|
+
errorText: toolPart.errorText
|
|
10115
|
+
};
|
|
10116
|
+
}
|
|
9962
10117
|
var uiMessagesSchema = lazyValidator2(
|
|
9963
10118
|
() => zodSchema2(
|
|
9964
10119
|
z8.array(
|
|
@@ -10049,7 +10204,8 @@ var uiMessagesSchema = lazyValidator2(
|
|
|
10049
10204
|
toolName: z8.string(),
|
|
10050
10205
|
toolCallId: z8.string(),
|
|
10051
10206
|
state: z8.literal("output-error"),
|
|
10052
|
-
input: z8.unknown(),
|
|
10207
|
+
input: z8.unknown().optional(),
|
|
10208
|
+
rawInput: z8.unknown().optional(),
|
|
10053
10209
|
providerExecuted: z8.boolean().optional(),
|
|
10054
10210
|
output: z8.never().optional(),
|
|
10055
10211
|
errorText: z8.string(),
|
|
@@ -10127,7 +10283,8 @@ var uiMessagesSchema = lazyValidator2(
|
|
|
10127
10283
|
toolCallId: z8.string(),
|
|
10128
10284
|
state: z8.literal("output-error"),
|
|
10129
10285
|
providerExecuted: z8.boolean().optional(),
|
|
10130
|
-
input: z8.unknown(),
|
|
10286
|
+
input: z8.unknown().optional(),
|
|
10287
|
+
rawInput: z8.unknown().optional(),
|
|
10131
10288
|
output: z8.never().optional(),
|
|
10132
10289
|
errorText: z8.string(),
|
|
10133
10290
|
callProviderMetadata: providerMetadataSchema.optional(),
|
|
@@ -10191,6 +10348,17 @@ async function safeValidateUIMessages({
|
|
|
10191
10348
|
value: messages,
|
|
10192
10349
|
schema: uiMessagesSchema
|
|
10193
10350
|
});
|
|
10351
|
+
for (const message of validatedMessages) {
|
|
10352
|
+
for (const part of message.parts) {
|
|
10353
|
+
if (part.type !== "dynamic-tool" && !part.type.startsWith("tool-")) {
|
|
10354
|
+
continue;
|
|
10355
|
+
}
|
|
10356
|
+
const toolPart = part;
|
|
10357
|
+
if (toolPart.state === "output-error" && !("input" in toolPart)) {
|
|
10358
|
+
toolPart.input = void 0;
|
|
10359
|
+
}
|
|
10360
|
+
}
|
|
10361
|
+
}
|
|
10194
10362
|
if (metadataSchema) {
|
|
10195
10363
|
for (const message of validatedMessages) {
|
|
10196
10364
|
await validateTypes2({
|
|
@@ -10225,12 +10393,17 @@ async function safeValidateUIMessages({
|
|
|
10225
10393
|
}
|
|
10226
10394
|
if (tools) {
|
|
10227
10395
|
for (const message of validatedMessages) {
|
|
10228
|
-
const
|
|
10229
|
-
(part
|
|
10230
|
-
|
|
10231
|
-
|
|
10396
|
+
for (const [partIdx, part] of message.parts.entries()) {
|
|
10397
|
+
if (!part.type.startsWith("tool-")) {
|
|
10398
|
+
continue;
|
|
10399
|
+
}
|
|
10400
|
+
const toolPart = part;
|
|
10232
10401
|
const toolName = toolPart.type.slice(5);
|
|
10233
10402
|
const tool2 = tools[toolName];
|
|
10403
|
+
if (!tool2 && (toolPart.state === "output-available" || toolPart.state === "output-error")) {
|
|
10404
|
+
message.parts[partIdx] = asDynamicToolPart(toolPart);
|
|
10405
|
+
continue;
|
|
10406
|
+
}
|
|
10234
10407
|
if (!tool2) {
|
|
10235
10408
|
return {
|
|
10236
10409
|
success: false,
|
|
@@ -10240,7 +10413,30 @@ async function safeValidateUIMessages({
|
|
|
10240
10413
|
})
|
|
10241
10414
|
};
|
|
10242
10415
|
}
|
|
10243
|
-
|
|
10416
|
+
let dynamicToolPart;
|
|
10417
|
+
if (toolPart.state === "output-error") {
|
|
10418
|
+
if (toolPart.input !== void 0) {
|
|
10419
|
+
const result = await safeValidateTypes5({
|
|
10420
|
+
value: toolPart.input,
|
|
10421
|
+
schema: tool2.inputSchema
|
|
10422
|
+
});
|
|
10423
|
+
if (!result.success) {
|
|
10424
|
+
dynamicToolPart = asDynamicToolPart(toolPart);
|
|
10425
|
+
}
|
|
10426
|
+
}
|
|
10427
|
+
} else if (toolPart.state === "output-available") {
|
|
10428
|
+
const result = await safeValidateTypes5({
|
|
10429
|
+
value: toolPart.input,
|
|
10430
|
+
schema: tool2.inputSchema
|
|
10431
|
+
});
|
|
10432
|
+
if (!result.success) {
|
|
10433
|
+
if (isEmptyObject(toolPart.input)) {
|
|
10434
|
+
dynamicToolPart = asDynamicToolPart(toolPart);
|
|
10435
|
+
} else {
|
|
10436
|
+
throw result.error;
|
|
10437
|
+
}
|
|
10438
|
+
}
|
|
10439
|
+
} else if (toolPart.state === "input-available") {
|
|
10244
10440
|
await validateTypes2({
|
|
10245
10441
|
value: toolPart.input,
|
|
10246
10442
|
schema: tool2.inputSchema
|
|
@@ -10252,6 +10448,9 @@ async function safeValidateUIMessages({
|
|
|
10252
10448
|
schema: tool2.outputSchema
|
|
10253
10449
|
});
|
|
10254
10450
|
}
|
|
10451
|
+
if (dynamicToolPart) {
|
|
10452
|
+
message.parts[partIdx] = dynamicToolPart;
|
|
10453
|
+
}
|
|
10255
10454
|
}
|
|
10256
10455
|
}
|
|
10257
10456
|
}
|
|
@@ -10267,18 +10466,8 @@ async function safeValidateUIMessages({
|
|
|
10267
10466
|
};
|
|
10268
10467
|
}
|
|
10269
10468
|
}
|
|
10270
|
-
async function validateUIMessages({
|
|
10271
|
-
|
|
10272
|
-
metadataSchema,
|
|
10273
|
-
dataSchemas,
|
|
10274
|
-
tools
|
|
10275
|
-
}) {
|
|
10276
|
-
const response = await safeValidateUIMessages({
|
|
10277
|
-
messages,
|
|
10278
|
-
metadataSchema,
|
|
10279
|
-
dataSchemas,
|
|
10280
|
-
tools
|
|
10281
|
-
});
|
|
10469
|
+
async function validateUIMessages(options) {
|
|
10470
|
+
const response = await safeValidateUIMessages(options);
|
|
10282
10471
|
if (!response.success)
|
|
10283
10472
|
throw response.error;
|
|
10284
10473
|
return response.data;
|
|
@@ -10298,6 +10487,7 @@ function createUIMessageStream({
|
|
|
10298
10487
|
}) {
|
|
10299
10488
|
let controller;
|
|
10300
10489
|
const ongoingStreamPromises = [];
|
|
10490
|
+
let outcome = { status: "unknown" };
|
|
10301
10491
|
const stream = new ReadableStream({
|
|
10302
10492
|
start(controllerArg) {
|
|
10303
10493
|
controller = controllerArg;
|
|
@@ -10309,6 +10499,35 @@ function createUIMessageStream({
|
|
|
10309
10499
|
} catch (error) {
|
|
10310
10500
|
}
|
|
10311
10501
|
}
|
|
10502
|
+
function setOutcome(newOutcome) {
|
|
10503
|
+
if (outcome.status === "unknown" && newOutcome.status !== "unknown") {
|
|
10504
|
+
outcome = newOutcome;
|
|
10505
|
+
}
|
|
10506
|
+
}
|
|
10507
|
+
function failOutcome(error) {
|
|
10508
|
+
outcome = { status: "failed", error };
|
|
10509
|
+
}
|
|
10510
|
+
function safeError(error) {
|
|
10511
|
+
try {
|
|
10512
|
+
controller.error(error);
|
|
10513
|
+
} catch (e) {
|
|
10514
|
+
}
|
|
10515
|
+
}
|
|
10516
|
+
function handleError(error) {
|
|
10517
|
+
failOutcome(error);
|
|
10518
|
+
let errorText;
|
|
10519
|
+
try {
|
|
10520
|
+
errorText = onError(error);
|
|
10521
|
+
} catch (onErrorError) {
|
|
10522
|
+
failOutcome(onErrorError);
|
|
10523
|
+
safeError(onErrorError);
|
|
10524
|
+
return;
|
|
10525
|
+
}
|
|
10526
|
+
safeEnqueue({
|
|
10527
|
+
type: "error",
|
|
10528
|
+
errorText
|
|
10529
|
+
});
|
|
10530
|
+
}
|
|
10312
10531
|
try {
|
|
10313
10532
|
const result = execute({
|
|
10314
10533
|
writer: {
|
|
@@ -10326,38 +10545,29 @@ function createUIMessageStream({
|
|
|
10326
10545
|
safeEnqueue(value);
|
|
10327
10546
|
}
|
|
10328
10547
|
})().catch((error) => {
|
|
10329
|
-
|
|
10330
|
-
type: "error",
|
|
10331
|
-
errorText: onError(error)
|
|
10332
|
-
});
|
|
10548
|
+
handleError(error);
|
|
10333
10549
|
})
|
|
10334
10550
|
);
|
|
10335
10551
|
},
|
|
10552
|
+
setOutcome,
|
|
10336
10553
|
onError
|
|
10337
10554
|
}
|
|
10338
10555
|
});
|
|
10339
10556
|
if (result) {
|
|
10340
10557
|
ongoingStreamPromises.push(
|
|
10341
10558
|
result.catch((error) => {
|
|
10342
|
-
|
|
10343
|
-
type: "error",
|
|
10344
|
-
errorText: onError(error)
|
|
10345
|
-
});
|
|
10559
|
+
handleError(error);
|
|
10346
10560
|
})
|
|
10347
10561
|
);
|
|
10348
10562
|
}
|
|
10349
10563
|
} catch (error) {
|
|
10350
|
-
|
|
10351
|
-
type: "error",
|
|
10352
|
-
errorText: onError(error)
|
|
10353
|
-
});
|
|
10564
|
+
handleError(error);
|
|
10354
10565
|
}
|
|
10355
|
-
const waitForStreams =
|
|
10566
|
+
const waitForStreams = (async () => {
|
|
10356
10567
|
while (ongoingStreamPromises.length > 0) {
|
|
10357
10568
|
await ongoingStreamPromises.shift();
|
|
10358
10569
|
}
|
|
10359
|
-
|
|
10360
|
-
});
|
|
10570
|
+
})();
|
|
10361
10571
|
waitForStreams.finally(() => {
|
|
10362
10572
|
try {
|
|
10363
10573
|
controller.close();
|
|
@@ -10369,7 +10579,8 @@ function createUIMessageStream({
|
|
|
10369
10579
|
messageId: generateId3(),
|
|
10370
10580
|
originalMessages,
|
|
10371
10581
|
onFinish,
|
|
10372
|
-
onError
|
|
10582
|
+
onError,
|
|
10583
|
+
getOutcome: () => outcome
|
|
10373
10584
|
});
|
|
10374
10585
|
}
|
|
10375
10586
|
|