ai 5.0.269 → 5.0.271
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 +25 -0
- package/dist/index.d.mts +27 -5
- package/dist/index.d.ts +27 -5
- package/dist/index.js +178 -29
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +178 -29
- 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.271" : "0.0.0-test";
|
|
731
731
|
|
|
732
732
|
// src/util/download/download.ts
|
|
733
733
|
var download = async ({
|
|
@@ -2999,6 +2999,75 @@ function pipeTextStreamToResponse({
|
|
|
2999
2999
|
});
|
|
3000
3000
|
}
|
|
3001
3001
|
|
|
3002
|
+
// src/ui-message-stream/create-sse-stream-with-keep-alive.ts
|
|
3003
|
+
var STREAM_OPEN_COMMENT = ": stream-open\n\n";
|
|
3004
|
+
var KEEP_ALIVE_COMMENT = ": keep-alive\n\n";
|
|
3005
|
+
function createSseStreamWithKeepAlive({
|
|
3006
|
+
stream,
|
|
3007
|
+
keepAliveMs
|
|
3008
|
+
}) {
|
|
3009
|
+
if (keepAliveMs == null) {
|
|
3010
|
+
return stream;
|
|
3011
|
+
}
|
|
3012
|
+
if (!Number.isFinite(keepAliveMs) || keepAliveMs <= 0 || keepAliveMs > 2147483647) {
|
|
3013
|
+
throw new Error(
|
|
3014
|
+
"keepAliveMs must be a positive finite timer duration no greater than 2147483647"
|
|
3015
|
+
);
|
|
3016
|
+
}
|
|
3017
|
+
const reader = stream.getReader();
|
|
3018
|
+
let keepAliveTimeout;
|
|
3019
|
+
let isCancelled = false;
|
|
3020
|
+
const clearKeepAliveTimeout = () => {
|
|
3021
|
+
clearTimeout(keepAliveTimeout);
|
|
3022
|
+
keepAliveTimeout = void 0;
|
|
3023
|
+
};
|
|
3024
|
+
const scheduleKeepAlive = (controller) => {
|
|
3025
|
+
clearKeepAliveTimeout();
|
|
3026
|
+
keepAliveTimeout = setTimeout(() => {
|
|
3027
|
+
if (isCancelled) {
|
|
3028
|
+
return;
|
|
3029
|
+
}
|
|
3030
|
+
if (controller.desiredSize != null && controller.desiredSize > 0) {
|
|
3031
|
+
controller.enqueue(KEEP_ALIVE_COMMENT);
|
|
3032
|
+
}
|
|
3033
|
+
scheduleKeepAlive(controller);
|
|
3034
|
+
}, keepAliveMs);
|
|
3035
|
+
};
|
|
3036
|
+
return new ReadableStream({
|
|
3037
|
+
start(controller) {
|
|
3038
|
+
controller.enqueue(STREAM_OPEN_COMMENT);
|
|
3039
|
+
scheduleKeepAlive(controller);
|
|
3040
|
+
},
|
|
3041
|
+
pull(controller) {
|
|
3042
|
+
return reader.read().then(
|
|
3043
|
+
(result) => {
|
|
3044
|
+
clearKeepAliveTimeout();
|
|
3045
|
+
if (isCancelled) {
|
|
3046
|
+
return;
|
|
3047
|
+
}
|
|
3048
|
+
if (result.done) {
|
|
3049
|
+
controller.close();
|
|
3050
|
+
} else {
|
|
3051
|
+
controller.enqueue(result.value);
|
|
3052
|
+
scheduleKeepAlive(controller);
|
|
3053
|
+
}
|
|
3054
|
+
},
|
|
3055
|
+
(error) => {
|
|
3056
|
+
clearKeepAliveTimeout();
|
|
3057
|
+
if (!isCancelled) {
|
|
3058
|
+
throw error;
|
|
3059
|
+
}
|
|
3060
|
+
}
|
|
3061
|
+
);
|
|
3062
|
+
},
|
|
3063
|
+
async cancel(reason) {
|
|
3064
|
+
isCancelled = true;
|
|
3065
|
+
clearKeepAliveTimeout();
|
|
3066
|
+
await reader.cancel(reason);
|
|
3067
|
+
}
|
|
3068
|
+
});
|
|
3069
|
+
}
|
|
3070
|
+
|
|
3002
3071
|
// src/ui-message-stream/json-to-sse-transform-stream.ts
|
|
3003
3072
|
var JsonToSseTransformStream = class extends TransformStream {
|
|
3004
3073
|
constructor() {
|
|
@@ -3031,9 +3100,13 @@ function createUIMessageStreamResponse({
|
|
|
3031
3100
|
statusText,
|
|
3032
3101
|
headers,
|
|
3033
3102
|
stream,
|
|
3103
|
+
keepAliveMs,
|
|
3034
3104
|
consumeSseStream
|
|
3035
3105
|
}) {
|
|
3036
|
-
let sseStream =
|
|
3106
|
+
let sseStream = createSseStreamWithKeepAlive({
|
|
3107
|
+
stream: stream.pipeThrough(new JsonToSseTransformStream()),
|
|
3108
|
+
keepAliveMs
|
|
3109
|
+
});
|
|
3037
3110
|
if (consumeSseStream) {
|
|
3038
3111
|
const [stream1, stream2] = sseStream.tee();
|
|
3039
3112
|
sseStream = stream1;
|
|
@@ -3631,16 +3704,41 @@ function createStreamingUIMessageState({
|
|
|
3631
3704
|
lastMessage,
|
|
3632
3705
|
messageId
|
|
3633
3706
|
}) {
|
|
3707
|
+
var _a16;
|
|
3708
|
+
const message = (lastMessage == null ? void 0 : lastMessage.role) === "assistant" ? lastMessage : {
|
|
3709
|
+
id: messageId,
|
|
3710
|
+
metadata: void 0,
|
|
3711
|
+
role: "assistant",
|
|
3712
|
+
parts: []
|
|
3713
|
+
};
|
|
3714
|
+
const partialToolCalls = createIdMap();
|
|
3715
|
+
const lastStepStartIndex = message.parts.findLastIndex(
|
|
3716
|
+
(part) => part.type === "step-start"
|
|
3717
|
+
);
|
|
3718
|
+
let staticToolIndex = 0;
|
|
3719
|
+
for (const part of message.parts.slice(lastStepStartIndex + 1)) {
|
|
3720
|
+
if (!isToolOrDynamicToolUIPart(part)) {
|
|
3721
|
+
continue;
|
|
3722
|
+
}
|
|
3723
|
+
const index = staticToolIndex;
|
|
3724
|
+
if (isToolUIPart(part)) {
|
|
3725
|
+
staticToolIndex++;
|
|
3726
|
+
}
|
|
3727
|
+
if (part.state !== "input-streaming") {
|
|
3728
|
+
continue;
|
|
3729
|
+
}
|
|
3730
|
+
partialToolCalls[part.toolCallId] = {
|
|
3731
|
+
text: (_a16 = part.rawInput) != null ? _a16 : "",
|
|
3732
|
+
index,
|
|
3733
|
+
toolName: isDynamicToolUIPart(part) ? part.toolName : getToolName(part),
|
|
3734
|
+
dynamic: isDynamicToolUIPart(part)
|
|
3735
|
+
};
|
|
3736
|
+
}
|
|
3634
3737
|
return {
|
|
3635
|
-
message
|
|
3636
|
-
id: messageId,
|
|
3637
|
-
metadata: void 0,
|
|
3638
|
-
role: "assistant",
|
|
3639
|
-
parts: []
|
|
3640
|
-
},
|
|
3738
|
+
message,
|
|
3641
3739
|
activeTextParts: createIdMap(),
|
|
3642
3740
|
activeReasoningParts: createIdMap(),
|
|
3643
|
-
partialToolCalls
|
|
3741
|
+
partialToolCalls
|
|
3644
3742
|
};
|
|
3645
3743
|
}
|
|
3646
3744
|
function processUIMessageStream({
|
|
@@ -3748,7 +3846,7 @@ function processUIMessageStream({
|
|
|
3748
3846
|
}
|
|
3749
3847
|
}
|
|
3750
3848
|
function updateDynamicToolPart(options, existingPart) {
|
|
3751
|
-
var _a17
|
|
3849
|
+
var _a17;
|
|
3752
3850
|
const part = existingPart != null ? existingPart : getCurrentStepParts().find(
|
|
3753
3851
|
(part2) => part2.type === "dynamic-tool" && part2.toolCallId === options.toolCallId
|
|
3754
3852
|
);
|
|
@@ -3760,9 +3858,9 @@ function processUIMessageStream({
|
|
|
3760
3858
|
anyPart.input = anyOptions.input;
|
|
3761
3859
|
anyPart.output = anyOptions.output;
|
|
3762
3860
|
anyPart.errorText = anyOptions.errorText;
|
|
3763
|
-
anyPart.rawInput =
|
|
3861
|
+
anyPart.rawInput = anyOptions.rawInput;
|
|
3764
3862
|
anyPart.preliminary = anyOptions.preliminary;
|
|
3765
|
-
anyPart.providerExecuted = (
|
|
3863
|
+
anyPart.providerExecuted = (_a17 = anyOptions.providerExecuted) != null ? _a17 : part.providerExecuted;
|
|
3766
3864
|
if (anyOptions.providerMetadata != null && part.state === "input-available") {
|
|
3767
3865
|
part.callProviderMetadata = anyOptions.providerMetadata;
|
|
3768
3866
|
}
|
|
@@ -3920,14 +4018,16 @@ function processUIMessageStream({
|
|
|
3920
4018
|
toolCallId: chunk.toolCallId,
|
|
3921
4019
|
toolName: partialToolCall.toolName,
|
|
3922
4020
|
state: "input-streaming",
|
|
3923
|
-
input: partialArgs
|
|
4021
|
+
input: partialArgs,
|
|
4022
|
+
rawInput: partialToolCall.text
|
|
3924
4023
|
});
|
|
3925
4024
|
} else {
|
|
3926
4025
|
updateToolPart({
|
|
3927
4026
|
toolCallId: chunk.toolCallId,
|
|
3928
4027
|
toolName: partialToolCall.toolName,
|
|
3929
4028
|
state: "input-streaming",
|
|
3930
|
-
input: partialArgs
|
|
4029
|
+
input: partialArgs,
|
|
4030
|
+
rawInput: partialToolCall.text
|
|
3931
4031
|
});
|
|
3932
4032
|
}
|
|
3933
4033
|
write();
|
|
@@ -4241,9 +4341,13 @@ function pipeUIMessageStreamToResponse({
|
|
|
4241
4341
|
statusText,
|
|
4242
4342
|
headers,
|
|
4243
4343
|
stream,
|
|
4344
|
+
keepAliveMs,
|
|
4244
4345
|
consumeSseStream
|
|
4245
4346
|
}) {
|
|
4246
|
-
let sseStream =
|
|
4347
|
+
let sseStream = createSseStreamWithKeepAlive({
|
|
4348
|
+
stream: stream.pipeThrough(new JsonToSseTransformStream()),
|
|
4349
|
+
keepAliveMs
|
|
4350
|
+
});
|
|
4247
4351
|
if (consumeSseStream) {
|
|
4248
4352
|
const [stream1, stream2] = sseStream.tee();
|
|
4249
4353
|
sseStream = stream1;
|
|
@@ -6573,6 +6677,21 @@ var DefaultEmbedResult = class {
|
|
|
6573
6677
|
}
|
|
6574
6678
|
};
|
|
6575
6679
|
|
|
6680
|
+
// src/util/get-own.ts
|
|
6681
|
+
function getOwn(obj, key) {
|
|
6682
|
+
return obj != null && Object.hasOwn(obj, key) ? obj[key] : void 0;
|
|
6683
|
+
}
|
|
6684
|
+
|
|
6685
|
+
// src/util/set-own.ts
|
|
6686
|
+
function setOwn(object2, key, value) {
|
|
6687
|
+
Object.defineProperty(object2, key, {
|
|
6688
|
+
value,
|
|
6689
|
+
enumerable: true,
|
|
6690
|
+
configurable: true,
|
|
6691
|
+
writable: true
|
|
6692
|
+
});
|
|
6693
|
+
}
|
|
6694
|
+
|
|
6576
6695
|
// src/embed/embed-many.ts
|
|
6577
6696
|
import {
|
|
6578
6697
|
withUserAgentSuffix as withUserAgentSuffix4
|
|
@@ -6800,10 +6919,10 @@ async function embedMany({
|
|
|
6800
6919
|
for (const [providerName, metadata] of Object.entries(
|
|
6801
6920
|
result.providerMetadata
|
|
6802
6921
|
)) {
|
|
6803
|
-
providerMetadata
|
|
6804
|
-
...providerMetadata
|
|
6922
|
+
setOwn(providerMetadata, providerName, {
|
|
6923
|
+
...getOwn(providerMetadata, providerName),
|
|
6805
6924
|
...metadata
|
|
6806
|
-
};
|
|
6925
|
+
});
|
|
6807
6926
|
}
|
|
6808
6927
|
}
|
|
6809
6928
|
}
|
|
@@ -6983,10 +7102,13 @@ async function generateImage({
|
|
|
6983
7102
|
delete providerMetadata[providerName].images;
|
|
6984
7103
|
}
|
|
6985
7104
|
} else {
|
|
6986
|
-
(_b = providerMetadata
|
|
6987
|
-
|
|
7105
|
+
const currentEntry = (_b = getOwn(providerMetadata, providerName)) != null ? _b : {
|
|
7106
|
+
images: []
|
|
7107
|
+
};
|
|
7108
|
+
currentEntry.images.push(
|
|
6988
7109
|
...result.providerMetadata[providerName].images
|
|
6989
7110
|
);
|
|
7111
|
+
setOwn(providerMetadata, providerName, currentEntry);
|
|
6990
7112
|
}
|
|
6991
7113
|
}
|
|
6992
7114
|
}
|
|
@@ -9263,7 +9385,7 @@ var DefaultProviderRegistry = class {
|
|
|
9263
9385
|
separator,
|
|
9264
9386
|
languageModelMiddleware
|
|
9265
9387
|
}) {
|
|
9266
|
-
this.providers =
|
|
9388
|
+
this.providers = /* @__PURE__ */ Object.create(null);
|
|
9267
9389
|
this.separator = separator;
|
|
9268
9390
|
this.languageModelMiddleware = languageModelMiddleware;
|
|
9269
9391
|
}
|
|
@@ -9629,6 +9751,10 @@ import {
|
|
|
9629
9751
|
normalizeHeaders,
|
|
9630
9752
|
resolve
|
|
9631
9753
|
} from "@ai-sdk/provider-utils";
|
|
9754
|
+
function appendPathToUrl(url, path) {
|
|
9755
|
+
const queryOrFragmentStart = url.search(/[?#]/);
|
|
9756
|
+
return queryOrFragmentStart === -1 ? `${url}${path}` : `${url.slice(0, queryOrFragmentStart)}${path}${url.slice(queryOrFragmentStart)}`;
|
|
9757
|
+
}
|
|
9632
9758
|
var HttpChatTransport = class {
|
|
9633
9759
|
constructor({
|
|
9634
9760
|
api = "/api/chat",
|
|
@@ -9703,7 +9829,7 @@ var HttpChatTransport = class {
|
|
|
9703
9829
|
return this.processResponseStream(response.body);
|
|
9704
9830
|
}
|
|
9705
9831
|
async reconnectToStream(options) {
|
|
9706
|
-
var _a16, _b, _c, _d
|
|
9832
|
+
var _a16, _b, _c, _d;
|
|
9707
9833
|
const resolvedBody = await resolve(this.body);
|
|
9708
9834
|
const resolvedHeaders = await resolve(this.headers);
|
|
9709
9835
|
const resolvedCredentials = await resolve(this.credentials);
|
|
@@ -9719,10 +9845,23 @@ var HttpChatTransport = class {
|
|
|
9719
9845
|
credentials: resolvedCredentials,
|
|
9720
9846
|
requestMetadata: options.metadata
|
|
9721
9847
|
}));
|
|
9722
|
-
|
|
9848
|
+
let api = preparedRequest == null ? void 0 : preparedRequest.api;
|
|
9849
|
+
if (api == null) {
|
|
9850
|
+
if (options.chatId === "." || options.chatId === "..") {
|
|
9851
|
+
throw new InvalidArgumentError({
|
|
9852
|
+
parameter: "chatId",
|
|
9853
|
+
value: options.chatId,
|
|
9854
|
+
message: 'Chat IDs must not be "." or ".." when using the default reconnect URL.'
|
|
9855
|
+
});
|
|
9856
|
+
}
|
|
9857
|
+
api = appendPathToUrl(
|
|
9858
|
+
this.api,
|
|
9859
|
+
`/${encodeURIComponent(options.chatId)}/stream`
|
|
9860
|
+
);
|
|
9861
|
+
}
|
|
9723
9862
|
const headers = (preparedRequest == null ? void 0 : preparedRequest.headers) !== void 0 ? normalizeHeaders(preparedRequest.headers) : baseHeaders;
|
|
9724
|
-
const credentials = (
|
|
9725
|
-
const fetch2 = (
|
|
9863
|
+
const credentials = (_b = preparedRequest == null ? void 0 : preparedRequest.credentials) != null ? _b : resolvedCredentials;
|
|
9864
|
+
const fetch2 = (_c = this.fetch) != null ? _c : globalThis.fetch;
|
|
9726
9865
|
const response = await fetch2(api, {
|
|
9727
9866
|
method: "GET",
|
|
9728
9867
|
headers,
|
|
@@ -9734,7 +9873,7 @@ var HttpChatTransport = class {
|
|
|
9734
9873
|
}
|
|
9735
9874
|
if (!response.ok) {
|
|
9736
9875
|
throw new Error(
|
|
9737
|
-
(
|
|
9876
|
+
(_d = await response.text()) != null ? _d : "Failed to fetch the chat response."
|
|
9738
9877
|
);
|
|
9739
9878
|
}
|
|
9740
9879
|
if (!response.body) {
|
|
@@ -9996,6 +10135,9 @@ var AbstractChat = class {
|
|
|
9996
10135
|
};
|
|
9997
10136
|
this.setStatus({ status: "submitted", error: void 0 });
|
|
9998
10137
|
const lastMessage = this.lastMessage;
|
|
10138
|
+
const resumableResponseMessage = trigger === "resume-stream" && (lastMessage == null ? void 0 : lastMessage.role) === "assistant" && lastMessage.parts.some(
|
|
10139
|
+
(part) => isToolOrDynamicToolUIPart(part) && part.state === "input-streaming"
|
|
10140
|
+
) ? this.state.snapshot(lastMessage) : void 0;
|
|
9999
10141
|
let isAbort = false;
|
|
10000
10142
|
let isDisconnect = false;
|
|
10001
10143
|
let isError = false;
|
|
@@ -10003,7 +10145,7 @@ var AbstractChat = class {
|
|
|
10003
10145
|
try {
|
|
10004
10146
|
const response = {
|
|
10005
10147
|
state: trigger === "resume-stream" && this.resumableStreamState != null ? this.resumableStreamState : createStreamingUIMessageState({
|
|
10006
|
-
lastMessage: trigger === "resume-stream" ?
|
|
10148
|
+
lastMessage: trigger === "resume-stream" ? resumableResponseMessage : this.state.snapshot(lastMessage),
|
|
10007
10149
|
messageId: this.generateId()
|
|
10008
10150
|
}),
|
|
10009
10151
|
abortController
|
|
@@ -10184,8 +10326,13 @@ function lastAssistantMessageIsCompleteWithToolCalls({
|
|
|
10184
10326
|
const lastStepStartIndex = message.parts.reduce((lastIndex, part, index) => {
|
|
10185
10327
|
return part.type === "step-start" ? index : lastIndex;
|
|
10186
10328
|
}, -1);
|
|
10187
|
-
const
|
|
10188
|
-
|
|
10329
|
+
const lastStepParts = message.parts.slice(lastStepStartIndex + 1);
|
|
10330
|
+
const lastStepToolInvocations = lastStepParts.filter(isToolOrDynamicToolUIPart).filter((part) => !part.providerExecuted);
|
|
10331
|
+
const lastToolInvocationIndex = lastStepParts.reduce(
|
|
10332
|
+
(lastIndex, part, index) => isToolOrDynamicToolUIPart(part) && !part.providerExecuted ? index : lastIndex,
|
|
10333
|
+
-1
|
|
10334
|
+
);
|
|
10335
|
+
return lastStepToolInvocations.length > 0 && !lastStepParts.slice(lastToolInvocationIndex + 1).some((part) => part.type === "text" && part.state !== "done") && lastStepToolInvocations.every(
|
|
10189
10336
|
(part) => part.state === "output-available" || part.state === "output-error"
|
|
10190
10337
|
);
|
|
10191
10338
|
}
|
|
@@ -10319,6 +10466,7 @@ var uiMessagesSchema = lazyValidator2(
|
|
|
10319
10466
|
toolCallId: z8.string(),
|
|
10320
10467
|
state: z8.literal("input-streaming"),
|
|
10321
10468
|
input: z8.unknown().optional(),
|
|
10469
|
+
rawInput: z8.string().optional(),
|
|
10322
10470
|
providerExecuted: z8.boolean().optional(),
|
|
10323
10471
|
output: z8.never().optional(),
|
|
10324
10472
|
errorText: z8.never().optional()
|
|
@@ -10364,6 +10512,7 @@ var uiMessagesSchema = lazyValidator2(
|
|
|
10364
10512
|
state: z8.literal("input-streaming"),
|
|
10365
10513
|
providerExecuted: z8.boolean().optional(),
|
|
10366
10514
|
input: z8.unknown().optional(),
|
|
10515
|
+
rawInput: z8.string().optional(),
|
|
10367
10516
|
output: z8.never().optional(),
|
|
10368
10517
|
errorText: z8.never().optional(),
|
|
10369
10518
|
approval: z8.never().optional()
|