ai 5.0.272 → 5.0.274
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 +30 -0
- package/dist/index.d.mts +26 -3
- package/dist/index.d.ts +26 -3
- package/dist/index.js +225 -58
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +225 -58
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +1 -1
- package/dist/internal/index.mjs +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -817,7 +817,7 @@ function detectMediaType({
|
|
|
817
817
|
var import_provider_utils2 = require("@ai-sdk/provider-utils");
|
|
818
818
|
|
|
819
819
|
// src/version.ts
|
|
820
|
-
var VERSION = true ? "5.0.
|
|
820
|
+
var VERSION = true ? "5.0.274" : "0.0.0-test";
|
|
821
821
|
|
|
822
822
|
// src/util/download/download.ts
|
|
823
823
|
var download = async ({
|
|
@@ -3818,7 +3818,8 @@ function processUIMessageStream({
|
|
|
3818
3818
|
runUpdateMessageJob,
|
|
3819
3819
|
onError,
|
|
3820
3820
|
onToolCall,
|
|
3821
|
-
onData
|
|
3821
|
+
onData,
|
|
3822
|
+
resetStateOnMessageIdChange = false
|
|
3822
3823
|
}) {
|
|
3823
3824
|
return stream.pipeThrough(
|
|
3824
3825
|
new TransformStream({
|
|
@@ -4235,6 +4236,16 @@ function processUIMessageStream({
|
|
|
4235
4236
|
break;
|
|
4236
4237
|
}
|
|
4237
4238
|
case "start": {
|
|
4239
|
+
if (resetStateOnMessageIdChange && chunk.messageId != null && chunk.messageId !== state.message.id) {
|
|
4240
|
+
Object.assign(
|
|
4241
|
+
state,
|
|
4242
|
+
createStreamingUIMessageState({
|
|
4243
|
+
lastMessage: void 0,
|
|
4244
|
+
messageId: chunk.messageId
|
|
4245
|
+
}),
|
|
4246
|
+
{ finishReason: void 0 }
|
|
4247
|
+
);
|
|
4248
|
+
}
|
|
4238
4249
|
if (chunk.messageId != null) {
|
|
4239
4250
|
state.message.id = chunk.messageId;
|
|
4240
4251
|
}
|
|
@@ -6388,6 +6399,20 @@ var DefaultStreamTextResult = class {
|
|
|
6388
6399
|
}
|
|
6389
6400
|
};
|
|
6390
6401
|
|
|
6402
|
+
// src/util/get-own.ts
|
|
6403
|
+
function getOwn(obj, key) {
|
|
6404
|
+
return obj != null && Object.hasOwn(obj, key) ? obj[key] : void 0;
|
|
6405
|
+
}
|
|
6406
|
+
|
|
6407
|
+
// src/ui/unavailable-tool.ts
|
|
6408
|
+
function markToolPartAsUnavailable(part) {
|
|
6409
|
+
part.dynamic = false;
|
|
6410
|
+
return part;
|
|
6411
|
+
}
|
|
6412
|
+
function isToolPartFromUnavailableTool(part) {
|
|
6413
|
+
return part.type === "dynamic-tool" && part.dynamic === false;
|
|
6414
|
+
}
|
|
6415
|
+
|
|
6391
6416
|
// src/ui/convert-to-model-messages.ts
|
|
6392
6417
|
function convertToModelMessages(messages, options) {
|
|
6393
6418
|
const modelMessages = [];
|
|
@@ -6399,6 +6424,25 @@ function convertToModelMessages(messages, options) {
|
|
|
6399
6424
|
)
|
|
6400
6425
|
}));
|
|
6401
6426
|
}
|
|
6427
|
+
function createModelOutput({
|
|
6428
|
+
toolPart,
|
|
6429
|
+
toolName,
|
|
6430
|
+
output,
|
|
6431
|
+
errorMode
|
|
6432
|
+
}) {
|
|
6433
|
+
const tool2 = getOwn(options == null ? void 0 : options.tools, toolName);
|
|
6434
|
+
if (errorMode === "none" && tool2 == null && isToolPartFromUnavailableTool(toolPart)) {
|
|
6435
|
+
return {
|
|
6436
|
+
type: "text",
|
|
6437
|
+
value: "Tool output omitted because the tool is no longer available."
|
|
6438
|
+
};
|
|
6439
|
+
}
|
|
6440
|
+
return createToolModelOutput({
|
|
6441
|
+
output,
|
|
6442
|
+
tool: tool2,
|
|
6443
|
+
errorMode
|
|
6444
|
+
});
|
|
6445
|
+
}
|
|
6402
6446
|
for (const message of messages) {
|
|
6403
6447
|
switch (message.role) {
|
|
6404
6448
|
case "system": {
|
|
@@ -6452,7 +6496,7 @@ function convertToModelMessages(messages, options) {
|
|
|
6452
6496
|
case "assistant": {
|
|
6453
6497
|
if (message.parts != null) {
|
|
6454
6498
|
let processBlock2 = function() {
|
|
6455
|
-
var _a16, _b
|
|
6499
|
+
var _a16, _b;
|
|
6456
6500
|
if (block.length === 0) {
|
|
6457
6501
|
return;
|
|
6458
6502
|
}
|
|
@@ -6504,9 +6548,10 @@ function convertToModelMessages(messages, options) {
|
|
|
6504
6548
|
type: "tool-result",
|
|
6505
6549
|
toolCallId: part.toolCallId,
|
|
6506
6550
|
toolName,
|
|
6507
|
-
output:
|
|
6551
|
+
output: createModelOutput({
|
|
6552
|
+
toolPart: part,
|
|
6553
|
+
toolName,
|
|
6508
6554
|
output: part.state === "output-error" ? part.errorText : part.output,
|
|
6509
|
-
tool: (_b = options == null ? void 0 : options.tools) == null ? void 0 : _b[toolName],
|
|
6510
6555
|
errorMode: part.state === "output-error" ? "json" : "none"
|
|
6511
6556
|
}),
|
|
6512
6557
|
...part.callProviderMetadata != null ? { providerOptions: part.callProviderMetadata } : {}
|
|
@@ -6514,7 +6559,7 @@ function convertToModelMessages(messages, options) {
|
|
|
6514
6559
|
}
|
|
6515
6560
|
}
|
|
6516
6561
|
} else if (isDataUIPart(part)) {
|
|
6517
|
-
const dataPart = (
|
|
6562
|
+
const dataPart = (_b = options == null ? void 0 : options.convertDataPart) == null ? void 0 : _b.call(
|
|
6518
6563
|
options,
|
|
6519
6564
|
part
|
|
6520
6565
|
);
|
|
@@ -6537,7 +6582,6 @@ function convertToModelMessages(messages, options) {
|
|
|
6537
6582
|
modelMessages.push({
|
|
6538
6583
|
role: "tool",
|
|
6539
6584
|
content: toolParts.map((toolPart) => {
|
|
6540
|
-
var _a17;
|
|
6541
6585
|
switch (toolPart.state) {
|
|
6542
6586
|
case "output-error":
|
|
6543
6587
|
case "output-available": {
|
|
@@ -6546,9 +6590,10 @@ function convertToModelMessages(messages, options) {
|
|
|
6546
6590
|
type: "tool-result",
|
|
6547
6591
|
toolCallId: toolPart.toolCallId,
|
|
6548
6592
|
toolName,
|
|
6549
|
-
output:
|
|
6593
|
+
output: createModelOutput({
|
|
6594
|
+
toolPart,
|
|
6595
|
+
toolName,
|
|
6550
6596
|
output: toolPart.state === "output-error" ? toolPart.errorText : toolPart.output,
|
|
6551
|
-
tool: (_a17 = options == null ? void 0 : options.tools) == null ? void 0 : _a17[toolName],
|
|
6552
6597
|
errorMode: toolPart.state === "output-error" ? "text" : "none"
|
|
6553
6598
|
}),
|
|
6554
6599
|
...toolPart.callProviderMetadata != null ? { providerOptions: toolPart.callProviderMetadata } : {}
|
|
@@ -6741,11 +6786,6 @@ var DefaultEmbedResult = class {
|
|
|
6741
6786
|
}
|
|
6742
6787
|
};
|
|
6743
6788
|
|
|
6744
|
-
// src/util/get-own.ts
|
|
6745
|
-
function getOwn(obj, key) {
|
|
6746
|
-
return obj != null && Object.hasOwn(obj, key) ? obj[key] : void 0;
|
|
6747
|
-
}
|
|
6748
|
-
|
|
6749
6789
|
// src/util/set-own.ts
|
|
6750
6790
|
function setOwn(object2, key, value) {
|
|
6751
6791
|
Object.defineProperty(object2, key, {
|
|
@@ -8007,17 +8047,24 @@ var SerialJobExecutor = class {
|
|
|
8007
8047
|
constructor() {
|
|
8008
8048
|
this.queue = [];
|
|
8009
8049
|
this.isProcessing = false;
|
|
8050
|
+
this.idleWaiters = [];
|
|
8010
8051
|
}
|
|
8011
8052
|
async processQueue() {
|
|
8012
8053
|
if (this.isProcessing) {
|
|
8013
8054
|
return;
|
|
8014
8055
|
}
|
|
8015
8056
|
this.isProcessing = true;
|
|
8016
|
-
|
|
8017
|
-
|
|
8018
|
-
|
|
8057
|
+
try {
|
|
8058
|
+
while (this.queue.length > 0) {
|
|
8059
|
+
await this.queue[0]();
|
|
8060
|
+
this.queue.shift();
|
|
8061
|
+
}
|
|
8062
|
+
} finally {
|
|
8063
|
+
this.isProcessing = false;
|
|
8064
|
+
for (const resolve2 of this.idleWaiters.splice(0)) {
|
|
8065
|
+
resolve2();
|
|
8066
|
+
}
|
|
8019
8067
|
}
|
|
8020
|
-
this.isProcessing = false;
|
|
8021
8068
|
}
|
|
8022
8069
|
async run(job) {
|
|
8023
8070
|
return new Promise((resolve2, reject) => {
|
|
@@ -8032,6 +8079,14 @@ var SerialJobExecutor = class {
|
|
|
8032
8079
|
void this.processQueue();
|
|
8033
8080
|
});
|
|
8034
8081
|
}
|
|
8082
|
+
async waitForIdle() {
|
|
8083
|
+
if (!this.isProcessing && this.queue.length === 0) {
|
|
8084
|
+
return;
|
|
8085
|
+
}
|
|
8086
|
+
await new Promise((resolve2) => {
|
|
8087
|
+
this.idleWaiters.push(resolve2);
|
|
8088
|
+
});
|
|
8089
|
+
}
|
|
8035
8090
|
};
|
|
8036
8091
|
|
|
8037
8092
|
// src/util/simulate-readable-stream.ts
|
|
@@ -9778,7 +9833,9 @@ var import_provider_utils31 = require("@ai-sdk/provider-utils");
|
|
|
9778
9833
|
var import_provider_utils30 = require("@ai-sdk/provider-utils");
|
|
9779
9834
|
function appendPathToUrl(url, path) {
|
|
9780
9835
|
const queryOrFragmentStart = url.search(/[?#]/);
|
|
9781
|
-
|
|
9836
|
+
const urlPath = queryOrFragmentStart === -1 ? url : url.slice(0, queryOrFragmentStart);
|
|
9837
|
+
const suffix = queryOrFragmentStart === -1 ? "" : url.slice(queryOrFragmentStart);
|
|
9838
|
+
return `${urlPath.endsWith("/") && path.startsWith("/") ? urlPath.slice(0, -1) : urlPath}${path}${suffix}`;
|
|
9782
9839
|
}
|
|
9783
9840
|
var HttpChatTransport = class {
|
|
9784
9841
|
constructor({
|
|
@@ -9949,6 +10006,8 @@ var AbstractChat = class {
|
|
|
9949
10006
|
this.activeResumeRequest = void 0;
|
|
9950
10007
|
this.resumableStreamState = void 0;
|
|
9951
10008
|
this.jobExecutor = new SerialJobExecutor();
|
|
10009
|
+
this.activeStopCount = 0;
|
|
10010
|
+
this.stopGeneration = 0;
|
|
9952
10011
|
/**
|
|
9953
10012
|
* Appends or replaces a user message to the chat list. This triggers the API call to fetch
|
|
9954
10013
|
* the assistant's response.
|
|
@@ -10039,6 +10098,27 @@ var AbstractChat = class {
|
|
|
10039
10098
|
this.resumeStream = async (options = {}) => {
|
|
10040
10099
|
await this.makeRequest({ trigger: "resume-stream", ...options });
|
|
10041
10100
|
};
|
|
10101
|
+
/**
|
|
10102
|
+
* Resume the stream if the latest response ended with a resumable network
|
|
10103
|
+
* disconnect. If a response is still active, wait for it to settle first so
|
|
10104
|
+
* disconnects reported shortly after the caller's trigger are handled.
|
|
10105
|
+
*
|
|
10106
|
+
* @internal
|
|
10107
|
+
*/
|
|
10108
|
+
this["~resumeStreamIfDisconnected"] = async ({
|
|
10109
|
+
shouldResume = () => true
|
|
10110
|
+
} = {}) => {
|
|
10111
|
+
const activeResponse = this.activeResponse;
|
|
10112
|
+
if (this.resumableStreamState == null && activeResponse != null) {
|
|
10113
|
+
await activeResponse.completionPromise;
|
|
10114
|
+
if (this.resumableStreamState !== activeResponse.state) {
|
|
10115
|
+
return;
|
|
10116
|
+
}
|
|
10117
|
+
}
|
|
10118
|
+
if (this.resumableStreamState != null && shouldResume()) {
|
|
10119
|
+
await this.resumeStream();
|
|
10120
|
+
}
|
|
10121
|
+
};
|
|
10042
10122
|
/**
|
|
10043
10123
|
* Clear the error state and set the status to ready if the chat is in an error state.
|
|
10044
10124
|
*/
|
|
@@ -10055,15 +10135,21 @@ var AbstractChat = class {
|
|
|
10055
10135
|
output,
|
|
10056
10136
|
errorText
|
|
10057
10137
|
}) => this.jobExecutor.run(async () => {
|
|
10058
|
-
var _a16, _b;
|
|
10059
10138
|
const messages = this.state.messages;
|
|
10060
|
-
const
|
|
10061
|
-
|
|
10062
|
-
|
|
10063
|
-
parts: lastMessage.parts.map(
|
|
10064
|
-
(part) => isToolOrDynamicToolUIPart(part) && part.toolCallId === toolCallId ? { ...part, state, output, errorText } : part
|
|
10139
|
+
const messageIndex = messages.findIndex(
|
|
10140
|
+
(message) => message.parts.some(
|
|
10141
|
+
(part) => isToolOrDynamicToolUIPart(part) && part.toolCallId === toolCallId
|
|
10065
10142
|
)
|
|
10066
|
-
|
|
10143
|
+
);
|
|
10144
|
+
if (messageIndex !== -1) {
|
|
10145
|
+
const message = messages[messageIndex];
|
|
10146
|
+
this.state.replaceMessage(messageIndex, {
|
|
10147
|
+
...message,
|
|
10148
|
+
parts: message.parts.map(
|
|
10149
|
+
(part) => isToolOrDynamicToolUIPart(part) && part.toolCallId === toolCallId ? { ...part, state, output, errorText } : part
|
|
10150
|
+
)
|
|
10151
|
+
});
|
|
10152
|
+
}
|
|
10067
10153
|
if (this.activeResponse) {
|
|
10068
10154
|
this.activeResponse.state.message.parts = this.activeResponse.state.message.parts.map(
|
|
10069
10155
|
(part) => isToolOrDynamicToolUIPart(part) && part.toolCallId === toolCallId ? {
|
|
@@ -10074,22 +10160,41 @@ var AbstractChat = class {
|
|
|
10074
10160
|
} : part
|
|
10075
10161
|
);
|
|
10076
10162
|
}
|
|
10077
|
-
if (this.status !== "streaming" && this.status !== "submitted" &&
|
|
10078
|
-
this.
|
|
10079
|
-
|
|
10080
|
-
|
|
10081
|
-
|
|
10163
|
+
if (messageIndex !== -1 && this.status !== "streaming" && this.status !== "submitted" && this.sendAutomaticallyWhen) {
|
|
10164
|
+
const shouldSend = await this.shouldSendAutomatically();
|
|
10165
|
+
if (shouldSend) {
|
|
10166
|
+
void this.runAutomaticRequest(
|
|
10167
|
+
() => this.makeRequest({
|
|
10168
|
+
trigger: "submit-message",
|
|
10169
|
+
messageId: messages[messageIndex].id
|
|
10170
|
+
}),
|
|
10171
|
+
shouldSend
|
|
10172
|
+
);
|
|
10173
|
+
}
|
|
10082
10174
|
}
|
|
10083
10175
|
});
|
|
10084
10176
|
/** @deprecated Use addToolOutput */
|
|
10085
10177
|
this.addToolResult = this.addToolOutput;
|
|
10086
10178
|
/**
|
|
10087
|
-
* Abort the current request
|
|
10179
|
+
* Abort the current request, keep the generated tokens if any, and wait for
|
|
10180
|
+
* the request pipeline to finish.
|
|
10088
10181
|
*/
|
|
10089
10182
|
this.stop = async () => {
|
|
10090
|
-
|
|
10091
|
-
|
|
10092
|
-
|
|
10183
|
+
this.activeStopCount++;
|
|
10184
|
+
this.stopGeneration++;
|
|
10185
|
+
try {
|
|
10186
|
+
const activeResumeRequest = this.activeResumeRequest;
|
|
10187
|
+
const activeResponse = this.activeResponse;
|
|
10188
|
+
activeResumeRequest == null ? void 0 : activeResumeRequest.abortController.abort();
|
|
10189
|
+
activeResponse == null ? void 0 : activeResponse.abortController.abort();
|
|
10190
|
+
await Promise.all([
|
|
10191
|
+
activeResumeRequest == null ? void 0 : activeResumeRequest.completionPromise,
|
|
10192
|
+
activeResponse == null ? void 0 : activeResponse.completionPromise
|
|
10193
|
+
]);
|
|
10194
|
+
await this.jobExecutor.waitForIdle();
|
|
10195
|
+
} finally {
|
|
10196
|
+
this.activeStopCount--;
|
|
10197
|
+
}
|
|
10093
10198
|
};
|
|
10094
10199
|
this.id = id;
|
|
10095
10200
|
this.transport = transport;
|
|
@@ -10135,19 +10240,53 @@ var AbstractChat = class {
|
|
|
10135
10240
|
set messages(messages) {
|
|
10136
10241
|
this.state.messages = messages;
|
|
10137
10242
|
}
|
|
10138
|
-
async
|
|
10243
|
+
async shouldSendAutomatically() {
|
|
10244
|
+
if (!this.sendAutomaticallyWhen)
|
|
10245
|
+
return false;
|
|
10246
|
+
const result = this.sendAutomaticallyWhen({
|
|
10247
|
+
messages: this.state.messages
|
|
10248
|
+
});
|
|
10249
|
+
if (result && typeof result === "object" && "then" in result) {
|
|
10250
|
+
return await result;
|
|
10251
|
+
}
|
|
10252
|
+
return result;
|
|
10253
|
+
}
|
|
10254
|
+
async runAutomaticRequest(request, shouldSend) {
|
|
10255
|
+
const stopGeneration = this.stopGeneration;
|
|
10256
|
+
const startedWhileStopping = this.activeStopCount > 0;
|
|
10257
|
+
if (!(shouldSend != null ? shouldSend : await this.shouldSendAutomatically())) {
|
|
10258
|
+
return;
|
|
10259
|
+
}
|
|
10260
|
+
if (startedWhileStopping || stopGeneration !== this.stopGeneration || this.activeStopCount > 0) {
|
|
10261
|
+
return;
|
|
10262
|
+
}
|
|
10263
|
+
await request();
|
|
10264
|
+
}
|
|
10265
|
+
async makeRequest(options) {
|
|
10266
|
+
const completion = createResolvablePromise();
|
|
10267
|
+
try {
|
|
10268
|
+
await this.makeRequestImpl({
|
|
10269
|
+
...options,
|
|
10270
|
+
completionPromise: completion.promise
|
|
10271
|
+
});
|
|
10272
|
+
} finally {
|
|
10273
|
+
completion.resolve();
|
|
10274
|
+
}
|
|
10275
|
+
}
|
|
10276
|
+
async makeRequestImpl({
|
|
10139
10277
|
trigger,
|
|
10140
10278
|
metadata,
|
|
10141
10279
|
headers,
|
|
10142
10280
|
body,
|
|
10143
|
-
messageId
|
|
10281
|
+
messageId,
|
|
10282
|
+
completionPromise
|
|
10144
10283
|
}) {
|
|
10145
|
-
var _a16, _b
|
|
10284
|
+
var _a16, _b;
|
|
10146
10285
|
if (trigger !== "resume-stream") {
|
|
10147
10286
|
this.resumableStreamState = void 0;
|
|
10148
10287
|
}
|
|
10149
10288
|
const abortController = new AbortController();
|
|
10150
|
-
const activeResumeRequest = trigger === "resume-stream" ? { abortController } : void 0;
|
|
10289
|
+
const activeResumeRequest = trigger === "resume-stream" ? { abortController, completionPromise } : void 0;
|
|
10151
10290
|
if (activeResumeRequest) {
|
|
10152
10291
|
(_a16 = this.activeResumeRequest) == null ? void 0 : _a16.abortController.abort();
|
|
10153
10292
|
this.activeResumeRequest = activeResumeRequest;
|
|
@@ -10160,9 +10299,13 @@ var AbstractChat = class {
|
|
|
10160
10299
|
};
|
|
10161
10300
|
this.setStatus({ status: "submitted", error: void 0 });
|
|
10162
10301
|
const lastMessage = this.lastMessage;
|
|
10302
|
+
const responseMessageIndex = trigger === "submit-message" && messageId != null ? this.state.messages.findIndex((message) => message.id === messageId) : this.state.messages.length - 1;
|
|
10303
|
+
const responseMessage = responseMessageIndex === -1 ? lastMessage : this.state.messages[responseMessageIndex];
|
|
10304
|
+
const originalResponseMessageId = responseMessage == null ? void 0 : responseMessage.id;
|
|
10163
10305
|
const resumableResponseMessage = trigger === "resume-stream" && (lastMessage == null ? void 0 : lastMessage.role) === "assistant" && lastMessage.parts.some(
|
|
10164
10306
|
(part) => isToolOrDynamicToolUIPart(part) && part.state === "input-streaming"
|
|
10165
10307
|
) ? this.state.snapshot(lastMessage) : void 0;
|
|
10308
|
+
const usesEarlierAssistantMessage = responseMessageIndex !== -1 && responseMessageIndex < this.state.messages.length - 1 && (responseMessage == null ? void 0 : responseMessage.role) === "assistant";
|
|
10166
10309
|
let isAbort = false;
|
|
10167
10310
|
let isDisconnect = false;
|
|
10168
10311
|
let isError = false;
|
|
@@ -10170,10 +10313,11 @@ var AbstractChat = class {
|
|
|
10170
10313
|
try {
|
|
10171
10314
|
const response = {
|
|
10172
10315
|
state: trigger === "resume-stream" && this.resumableStreamState != null ? this.resumableStreamState : createStreamingUIMessageState({
|
|
10173
|
-
lastMessage: trigger === "resume-stream" ? resumableResponseMessage : this.state.snapshot(
|
|
10316
|
+
lastMessage: trigger === "resume-stream" ? resumableResponseMessage : this.state.snapshot(responseMessage),
|
|
10174
10317
|
messageId: this.generateId()
|
|
10175
10318
|
}),
|
|
10176
|
-
abortController
|
|
10319
|
+
abortController,
|
|
10320
|
+
completionPromise
|
|
10177
10321
|
};
|
|
10178
10322
|
activeResponse = response;
|
|
10179
10323
|
response.abortController.signal.addEventListener("abort", () => {
|
|
@@ -10227,19 +10371,32 @@ var AbstractChat = class {
|
|
|
10227
10371
|
return job({
|
|
10228
10372
|
state: response.state,
|
|
10229
10373
|
write: ({ updateStatus = true } = {}) => {
|
|
10230
|
-
var _a17;
|
|
10231
10374
|
if (response.abortController.signal.aborted) {
|
|
10232
10375
|
return;
|
|
10233
10376
|
}
|
|
10234
10377
|
if (updateStatus) {
|
|
10235
10378
|
this.setStatus({ status: "streaming" });
|
|
10236
10379
|
}
|
|
10237
|
-
const
|
|
10238
|
-
|
|
10380
|
+
const existingMessageIndex = this.state.messages.findLastIndex(
|
|
10381
|
+
(message) => message.id === response.state.message.id
|
|
10382
|
+
);
|
|
10383
|
+
if (existingMessageIndex !== -1) {
|
|
10239
10384
|
this.state.replaceMessage(
|
|
10240
|
-
|
|
10385
|
+
existingMessageIndex,
|
|
10241
10386
|
response.state.message
|
|
10242
10387
|
);
|
|
10388
|
+
} else if (usesEarlierAssistantMessage) {
|
|
10389
|
+
const originalMessageIndex = this.state.messages.findLastIndex(
|
|
10390
|
+
(message) => message.id === originalResponseMessageId
|
|
10391
|
+
);
|
|
10392
|
+
if (originalMessageIndex !== -1) {
|
|
10393
|
+
this.state.replaceMessage(
|
|
10394
|
+
originalMessageIndex,
|
|
10395
|
+
response.state.message
|
|
10396
|
+
);
|
|
10397
|
+
} else {
|
|
10398
|
+
this.state.pushMessage(response.state.message);
|
|
10399
|
+
}
|
|
10243
10400
|
} else {
|
|
10244
10401
|
this.state.pushMessage(response.state.message);
|
|
10245
10402
|
}
|
|
@@ -10325,14 +10482,19 @@ var AbstractChat = class {
|
|
|
10325
10482
|
clearActiveResumeRequest();
|
|
10326
10483
|
}
|
|
10327
10484
|
}
|
|
10328
|
-
if (
|
|
10329
|
-
await this.
|
|
10330
|
-
|
|
10331
|
-
|
|
10332
|
-
|
|
10333
|
-
|
|
10334
|
-
|
|
10335
|
-
|
|
10485
|
+
if (!isAbort && !isError) {
|
|
10486
|
+
await this.runAutomaticRequest(
|
|
10487
|
+
() => {
|
|
10488
|
+
var _a17;
|
|
10489
|
+
return this.makeRequest({
|
|
10490
|
+
trigger: "submit-message",
|
|
10491
|
+
messageId: (_a17 = this.lastMessage) == null ? void 0 : _a17.id,
|
|
10492
|
+
metadata,
|
|
10493
|
+
headers,
|
|
10494
|
+
body
|
|
10495
|
+
});
|
|
10496
|
+
}
|
|
10497
|
+
);
|
|
10336
10498
|
}
|
|
10337
10499
|
}
|
|
10338
10500
|
};
|
|
@@ -10413,20 +10575,20 @@ function asDynamicToolPart(toolPart) {
|
|
|
10413
10575
|
...toolPart.callProviderMetadata === void 0 ? {} : { callProviderMetadata: toolPart.callProviderMetadata }
|
|
10414
10576
|
};
|
|
10415
10577
|
if (toolPart.state === "output-available") {
|
|
10416
|
-
return {
|
|
10578
|
+
return markToolPartAsUnavailable({
|
|
10417
10579
|
...common,
|
|
10418
10580
|
state: "output-available",
|
|
10419
10581
|
input: toolPart.input,
|
|
10420
10582
|
output: toolPart.output,
|
|
10421
10583
|
...toolPart.preliminary === void 0 ? {} : { preliminary: toolPart.preliminary }
|
|
10422
|
-
};
|
|
10584
|
+
});
|
|
10423
10585
|
}
|
|
10424
|
-
return {
|
|
10586
|
+
return markToolPartAsUnavailable({
|
|
10425
10587
|
...common,
|
|
10426
10588
|
state: "output-error",
|
|
10427
10589
|
input: toolPart.input,
|
|
10428
10590
|
errorText: toolPart.errorText
|
|
10429
|
-
};
|
|
10591
|
+
});
|
|
10430
10592
|
}
|
|
10431
10593
|
var uiMessagesSchema = (0, import_provider_utils33.lazyValidator)(
|
|
10432
10594
|
() => (0, import_provider_utils33.zodSchema)(
|
|
@@ -10482,6 +10644,7 @@ var uiMessagesSchema = (0, import_provider_utils33.lazyValidator)(
|
|
|
10482
10644
|
}),
|
|
10483
10645
|
import_v48.z.object({
|
|
10484
10646
|
type: import_v48.z.literal("dynamic-tool"),
|
|
10647
|
+
dynamic: import_v48.z.literal(false).optional(),
|
|
10485
10648
|
toolName: import_v48.z.string(),
|
|
10486
10649
|
toolCallId: import_v48.z.string(),
|
|
10487
10650
|
state: import_v48.z.literal("input-streaming"),
|
|
@@ -10493,6 +10656,7 @@ var uiMessagesSchema = (0, import_provider_utils33.lazyValidator)(
|
|
|
10493
10656
|
}),
|
|
10494
10657
|
import_v48.z.object({
|
|
10495
10658
|
type: import_v48.z.literal("dynamic-tool"),
|
|
10659
|
+
dynamic: import_v48.z.literal(false).optional(),
|
|
10496
10660
|
toolName: import_v48.z.string(),
|
|
10497
10661
|
toolCallId: import_v48.z.string(),
|
|
10498
10662
|
state: import_v48.z.literal("input-available"),
|
|
@@ -10504,6 +10668,7 @@ var uiMessagesSchema = (0, import_provider_utils33.lazyValidator)(
|
|
|
10504
10668
|
}),
|
|
10505
10669
|
import_v48.z.object({
|
|
10506
10670
|
type: import_v48.z.literal("dynamic-tool"),
|
|
10671
|
+
dynamic: import_v48.z.literal(false).optional(),
|
|
10507
10672
|
toolName: import_v48.z.string(),
|
|
10508
10673
|
toolCallId: import_v48.z.string(),
|
|
10509
10674
|
state: import_v48.z.literal("output-available"),
|
|
@@ -10516,6 +10681,7 @@ var uiMessagesSchema = (0, import_provider_utils33.lazyValidator)(
|
|
|
10516
10681
|
}),
|
|
10517
10682
|
import_v48.z.object({
|
|
10518
10683
|
type: import_v48.z.literal("dynamic-tool"),
|
|
10684
|
+
dynamic: import_v48.z.literal(false).optional(),
|
|
10519
10685
|
toolName: import_v48.z.string(),
|
|
10520
10686
|
toolCallId: import_v48.z.string(),
|
|
10521
10687
|
state: import_v48.z.literal("output-error"),
|
|
@@ -10715,7 +10881,7 @@ async function safeValidateUIMessages({
|
|
|
10715
10881
|
}
|
|
10716
10882
|
const toolPart = part;
|
|
10717
10883
|
const toolName = toolPart.type.slice(5);
|
|
10718
|
-
const tool2 = tools
|
|
10884
|
+
const tool2 = getOwn(tools, toolName);
|
|
10719
10885
|
if (!tool2 && (toolPart.state === "output-available" || toolPart.state === "output-error")) {
|
|
10720
10886
|
message.parts[partIdx] = asDynamicToolPart(toolPart);
|
|
10721
10887
|
continue;
|
|
@@ -10954,6 +11120,7 @@ function readUIMessageStream({
|
|
|
10954
11120
|
consumeStream({
|
|
10955
11121
|
stream: processUIMessageStream({
|
|
10956
11122
|
stream,
|
|
11123
|
+
resetStateOnMessageIdChange: true,
|
|
10957
11124
|
runUpdateMessageJob(job) {
|
|
10958
11125
|
return job({
|
|
10959
11126
|
state,
|