ai 5.0.0-beta.22 → 5.0.0-beta.24
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 +19 -0
- package/dist/bin/ai.js +69 -21
- package/dist/bin/ai.js.map +1 -1
- package/dist/bin/ai.min.js +10 -10
- package/dist/index.d.mts +61 -39
- package/dist/index.d.ts +61 -39
- package/dist/index.js +71 -21
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +72 -22
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
@@ -2409,7 +2409,8 @@ import {
|
|
2409
2409
|
getErrorMessage as getErrorMessage5
|
2410
2410
|
} from "@ai-sdk/provider";
|
2411
2411
|
import {
|
2412
|
-
createIdGenerator as createIdGenerator2
|
2412
|
+
createIdGenerator as createIdGenerator2,
|
2413
|
+
isAbortError as isAbortError2
|
2413
2414
|
} from "@ai-sdk/provider-utils";
|
2414
2415
|
|
2415
2416
|
// src/util/prepare-headers.ts
|
@@ -2671,6 +2672,9 @@ var uiMessageChunkSchema = z7.union([
|
|
2671
2672
|
type: z7.literal("finish"),
|
2672
2673
|
messageMetadata: z7.unknown().optional()
|
2673
2674
|
}),
|
2675
|
+
z7.strictObject({
|
2676
|
+
type: z7.literal("abort")
|
2677
|
+
}),
|
2674
2678
|
z7.strictObject({
|
2675
2679
|
type: z7.literal("message-metadata"),
|
2676
2680
|
messageMetadata: z7.unknown()
|
@@ -3055,7 +3059,7 @@ function isToolUIPart(part) {
|
|
3055
3059
|
return part.type.startsWith("tool-");
|
3056
3060
|
}
|
3057
3061
|
function getToolName(part) {
|
3058
|
-
return part.type.split("-")
|
3062
|
+
return part.type.split("-").slice(1).join("-");
|
3059
3063
|
}
|
3060
3064
|
|
3061
3065
|
// src/ui/process-ui-message-stream.ts
|
@@ -3414,6 +3418,7 @@ function handleUIMessageStreamFinish({
|
|
3414
3418
|
} else {
|
3415
3419
|
messageId = lastMessage.id;
|
3416
3420
|
}
|
3421
|
+
let isAborted = false;
|
3417
3422
|
const idInjectedStream = stream.pipeThrough(
|
3418
3423
|
new TransformStream({
|
3419
3424
|
transform(chunk, controller) {
|
@@ -3423,6 +3428,9 @@ function handleUIMessageStreamFinish({
|
|
3423
3428
|
startChunk.messageId = messageId;
|
3424
3429
|
}
|
3425
3430
|
}
|
3431
|
+
if (chunk.type === "abort") {
|
3432
|
+
isAborted = true;
|
3433
|
+
}
|
3426
3434
|
controller.enqueue(chunk);
|
3427
3435
|
}
|
3428
3436
|
})
|
@@ -3448,9 +3456,10 @@ function handleUIMessageStreamFinish({
|
|
3448
3456
|
transform(chunk, controller) {
|
3449
3457
|
controller.enqueue(chunk);
|
3450
3458
|
},
|
3451
|
-
flush() {
|
3459
|
+
async flush() {
|
3452
3460
|
const isContinuation = state.message.id === (lastMessage == null ? void 0 : lastMessage.id);
|
3453
|
-
onFinish({
|
3461
|
+
await onFinish({
|
3462
|
+
isAborted,
|
3454
3463
|
isContinuation,
|
3455
3464
|
responseMessage: state.message,
|
3456
3465
|
messages: [
|
@@ -3544,6 +3553,13 @@ function createStitchableStream() {
|
|
3544
3553
|
let controller = null;
|
3545
3554
|
let isClosed = false;
|
3546
3555
|
let waitForNewStream = createResolvablePromise();
|
3556
|
+
const terminate = () => {
|
3557
|
+
isClosed = true;
|
3558
|
+
waitForNewStream.resolve();
|
3559
|
+
innerStreamReaders.forEach((reader) => reader.cancel());
|
3560
|
+
innerStreamReaders = [];
|
3561
|
+
controller == null ? void 0 : controller.close();
|
3562
|
+
};
|
3547
3563
|
const processPull = async () => {
|
3548
3564
|
if (isClosed && innerStreamReaders.length === 0) {
|
3549
3565
|
controller == null ? void 0 : controller.close();
|
@@ -3569,9 +3585,7 @@ function createStitchableStream() {
|
|
3569
3585
|
} catch (error) {
|
3570
3586
|
controller == null ? void 0 : controller.error(error);
|
3571
3587
|
innerStreamReaders.shift();
|
3572
|
-
|
3573
|
-
controller == null ? void 0 : controller.close();
|
3574
|
-
}
|
3588
|
+
terminate();
|
3575
3589
|
}
|
3576
3590
|
};
|
3577
3591
|
return {
|
@@ -3610,13 +3624,7 @@ function createStitchableStream() {
|
|
3610
3624
|
* Immediately close the outer stream. This will cancel all inner streams
|
3611
3625
|
* and close the outer stream.
|
3612
3626
|
*/
|
3613
|
-
terminate
|
3614
|
-
isClosed = true;
|
3615
|
-
waitForNewStream.resolve();
|
3616
|
-
innerStreamReaders.forEach((reader) => reader.cancel());
|
3617
|
-
innerStreamReaders = [];
|
3618
|
-
controller == null ? void 0 : controller.close();
|
3619
|
-
}
|
3627
|
+
terminate
|
3620
3628
|
};
|
3621
3629
|
}
|
3622
3630
|
|
@@ -3664,6 +3672,30 @@ function now() {
|
|
3664
3672
|
return (_b = (_a16 = globalThis == null ? void 0 : globalThis.performance) == null ? void 0 : _a16.now()) != null ? _b : Date.now();
|
3665
3673
|
}
|
3666
3674
|
|
3675
|
+
// src/util/filter-stream-errors.ts
|
3676
|
+
function filterStreamErrors(readable, onError) {
|
3677
|
+
return new ReadableStream({
|
3678
|
+
async start(controller) {
|
3679
|
+
const reader = readable.getReader();
|
3680
|
+
try {
|
3681
|
+
while (true) {
|
3682
|
+
const { done, value } = await reader.read();
|
3683
|
+
if (done) {
|
3684
|
+
controller.close();
|
3685
|
+
break;
|
3686
|
+
}
|
3687
|
+
controller.enqueue(value);
|
3688
|
+
}
|
3689
|
+
} catch (error) {
|
3690
|
+
await onError({ error, controller });
|
3691
|
+
}
|
3692
|
+
},
|
3693
|
+
cancel(reason) {
|
3694
|
+
return readable.cancel(reason);
|
3695
|
+
}
|
3696
|
+
});
|
3697
|
+
}
|
3698
|
+
|
3667
3699
|
// src/generate-text/run-tools-transformation.ts
|
3668
3700
|
import { generateId } from "@ai-sdk/provider-utils";
|
3669
3701
|
function runToolsTransformation({
|
@@ -3912,6 +3944,7 @@ function streamText({
|
|
3912
3944
|
console.error(error);
|
3913
3945
|
},
|
3914
3946
|
onFinish,
|
3947
|
+
onAbort,
|
3915
3948
|
onStepFinish,
|
3916
3949
|
_internal: {
|
3917
3950
|
now: now2 = now,
|
@@ -3943,6 +3976,7 @@ function streamText({
|
|
3943
3976
|
onChunk,
|
3944
3977
|
onError,
|
3945
3978
|
onFinish,
|
3979
|
+
onAbort,
|
3946
3980
|
onStepFinish,
|
3947
3981
|
now: now2,
|
3948
3982
|
currentDate,
|
@@ -4041,6 +4075,7 @@ var DefaultStreamTextResult = class {
|
|
4041
4075
|
onChunk,
|
4042
4076
|
onError,
|
4043
4077
|
onFinish,
|
4078
|
+
onAbort,
|
4044
4079
|
onStepFinish
|
4045
4080
|
}) {
|
4046
4081
|
this._totalUsage = new DelayedPromise();
|
@@ -4048,7 +4083,6 @@ var DefaultStreamTextResult = class {
|
|
4048
4083
|
this._steps = new DelayedPromise();
|
4049
4084
|
this.output = output;
|
4050
4085
|
this.includeRawChunks = includeRawChunks;
|
4051
|
-
this.generateId = generateId3;
|
4052
4086
|
let stepFinish;
|
4053
4087
|
let recordedContent = [];
|
4054
4088
|
const recordedResponseMessages = [];
|
@@ -4251,6 +4285,15 @@ var DefaultStreamTextResult = class {
|
|
4251
4285
|
this.addStream = stitchableStream.addStream;
|
4252
4286
|
this.closeStream = stitchableStream.close;
|
4253
4287
|
let stream = stitchableStream.stream;
|
4288
|
+
stream = filterStreamErrors(stream, ({ error, controller }) => {
|
4289
|
+
if (isAbortError2(error) && (abortSignal == null ? void 0 : abortSignal.aborted)) {
|
4290
|
+
onAbort == null ? void 0 : onAbort({ steps: recordedSteps });
|
4291
|
+
controller.enqueue({ type: "abort" });
|
4292
|
+
controller.close();
|
4293
|
+
} else {
|
4294
|
+
controller.error(error);
|
4295
|
+
}
|
4296
|
+
});
|
4254
4297
|
stream = stream.pipeThrough(
|
4255
4298
|
new TransformStream({
|
4256
4299
|
start(controller) {
|
@@ -4993,6 +5036,10 @@ var DefaultStreamTextResult = class {
|
|
4993
5036
|
}
|
4994
5037
|
break;
|
4995
5038
|
}
|
5039
|
+
case "abort": {
|
5040
|
+
controller.enqueue(part);
|
5041
|
+
break;
|
5042
|
+
}
|
4996
5043
|
case "tool-input-end": {
|
4997
5044
|
break;
|
4998
5045
|
}
|
@@ -5013,13 +5060,15 @@ var DefaultStreamTextResult = class {
|
|
5013
5060
|
}
|
5014
5061
|
})
|
5015
5062
|
);
|
5016
|
-
return
|
5017
|
-
|
5018
|
-
|
5019
|
-
|
5020
|
-
|
5021
|
-
|
5022
|
-
|
5063
|
+
return createAsyncIterableStream(
|
5064
|
+
handleUIMessageStreamFinish({
|
5065
|
+
stream: baseStream,
|
5066
|
+
messageId: responseMessageId != null ? responseMessageId : generateMessageId == null ? void 0 : generateMessageId(),
|
5067
|
+
originalMessages,
|
5068
|
+
onFinish,
|
5069
|
+
onError
|
5070
|
+
})
|
5071
|
+
);
|
5023
5072
|
}
|
5024
5073
|
pipeUIMessageStreamToResponse(response, {
|
5025
5074
|
originalMessages,
|
@@ -9291,6 +9340,7 @@ export {
|
|
9291
9340
|
asSchema5 as asSchema,
|
9292
9341
|
assistantModelMessageSchema,
|
9293
9342
|
callCompletionApi,
|
9343
|
+
consumeStream,
|
9294
9344
|
convertFileListToFileUIParts,
|
9295
9345
|
convertToCoreMessages,
|
9296
9346
|
convertToModelMessages,
|