ai 6.0.288 → 6.0.290
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 +35 -0
- package/dist/index.d.mts +13 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +377 -281
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +314 -213
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +20 -5
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +20 -5
- package/dist/internal/index.mjs.map +1 -1
- package/docs/03-ai-sdk-core/16-mcp-tools.mdx +57 -0
- package/docs/03-ai-sdk-core/40-middleware.mdx +92 -7
- package/docs/04-ai-sdk-ui/03-chatbot-tool-usage.mdx +7 -0
- package/package.json +5 -4
- package/src/embed/embed-many.ts +19 -3
- package/src/generate-speech/generated-audio-file.ts +0 -8
- package/src/generate-text/generated-file.ts +0 -4
- package/src/generate-text/parse-tool-call.ts +30 -23
- package/src/generate-text/run-tools-transformation.ts +37 -3
- package/src/generate-text/stream-text.ts +9 -28
- package/src/generate-text/to-response-messages.ts +7 -0
- package/src/generate-text/tool-call.ts +26 -0
- package/src/generate-text/validate-tool-approvals.ts +20 -2
- package/src/middleware/extract-reasoning-middleware.ts +1 -1
- package/src/middleware/wrap-embedding-model.ts +12 -2
- package/src/model/get-embedding-model-provider-options-transformer.ts +17 -0
- package/src/prompt/content-part.ts +2 -0
- package/src/prompt/convert-to-language-model-prompt.ts +7 -2
- package/src/prompt/data-content.ts +11 -2
- package/src/ui/chat.ts +108 -17
- package/src/ui/convert-to-model-messages.ts +8 -0
- package/src/ui/http-chat-transport.ts +1 -1
- package/src/ui/last-assistant-message-is-complete-with-approval-responses.ts +1 -1
- package/src/ui/last-assistant-message-is-complete-with-tool-calls.ts +2 -1
- package/src/ui/process-ui-message-stream.ts +6 -0
- package/src/ui/ui-messages.ts +10 -0
- package/src/ui/validate-ui-messages.ts +79 -114
- package/src/ui-message-stream/ui-message-chunks.ts +2 -0
- package/src/util/write-to-server-response.ts +0 -2
package/dist/index.mjs
CHANGED
|
@@ -1224,7 +1224,7 @@ import {
|
|
|
1224
1224
|
} from "@ai-sdk/provider-utils";
|
|
1225
1225
|
|
|
1226
1226
|
// src/version.ts
|
|
1227
|
-
var VERSION = true ? "6.0.
|
|
1227
|
+
var VERSION = true ? "6.0.290" : "0.0.0-test";
|
|
1228
1228
|
|
|
1229
1229
|
// src/util/download/download.ts
|
|
1230
1230
|
var download = async ({
|
|
@@ -1352,6 +1352,7 @@ var dataContentSchema = z.union([
|
|
|
1352
1352
|
)
|
|
1353
1353
|
]);
|
|
1354
1354
|
function convertToLanguageModelV3DataContent(content) {
|
|
1355
|
+
let originalUrl;
|
|
1355
1356
|
if (content instanceof Uint8Array) {
|
|
1356
1357
|
return { data: content, mediaType: void 0 };
|
|
1357
1358
|
}
|
|
@@ -1360,7 +1361,9 @@ function convertToLanguageModelV3DataContent(content) {
|
|
|
1360
1361
|
}
|
|
1361
1362
|
if (typeof content === "string") {
|
|
1362
1363
|
try {
|
|
1363
|
-
|
|
1364
|
+
const url = new URL(content);
|
|
1365
|
+
originalUrl = url.toString() !== content ? content : void 0;
|
|
1366
|
+
content = url;
|
|
1364
1367
|
} catch (error) {
|
|
1365
1368
|
}
|
|
1366
1369
|
}
|
|
@@ -1376,7 +1379,11 @@ function convertToLanguageModelV3DataContent(content) {
|
|
|
1376
1379
|
}
|
|
1377
1380
|
return { data: base64Content, mediaType: dataUrlMediaType };
|
|
1378
1381
|
}
|
|
1379
|
-
return {
|
|
1382
|
+
return {
|
|
1383
|
+
data: content,
|
|
1384
|
+
mediaType: void 0,
|
|
1385
|
+
...originalUrl != null ? { originalUrl } : {}
|
|
1386
|
+
};
|
|
1380
1387
|
}
|
|
1381
1388
|
function convertDataContentToBase64String(content) {
|
|
1382
1389
|
if (typeof content === "string") {
|
|
@@ -1741,7 +1748,11 @@ function convertPartToLanguageModelPart(part, downloadedAssets) {
|
|
|
1741
1748
|
default:
|
|
1742
1749
|
throw new Error(`Unsupported part type: ${type}`);
|
|
1743
1750
|
}
|
|
1744
|
-
const {
|
|
1751
|
+
const {
|
|
1752
|
+
data: convertedData,
|
|
1753
|
+
mediaType: convertedMediaType,
|
|
1754
|
+
originalUrl
|
|
1755
|
+
} = convertToLanguageModelV3DataContent(originalData);
|
|
1745
1756
|
let mediaType = convertedMediaType != null ? convertedMediaType : part.mediaType;
|
|
1746
1757
|
let data = convertedData;
|
|
1747
1758
|
if (data instanceof URL) {
|
|
@@ -1762,6 +1773,7 @@ function convertPartToLanguageModelPart(part, downloadedAssets) {
|
|
|
1762
1773
|
// any image
|
|
1763
1774
|
filename: void 0,
|
|
1764
1775
|
data,
|
|
1776
|
+
...data instanceof URL && originalUrl != null ? { originalUrl } : {},
|
|
1765
1777
|
providerOptions: part.providerOptions
|
|
1766
1778
|
};
|
|
1767
1779
|
}
|
|
@@ -1774,6 +1786,7 @@ function convertPartToLanguageModelPart(part, downloadedAssets) {
|
|
|
1774
1786
|
mediaType,
|
|
1775
1787
|
filename: part.filename,
|
|
1776
1788
|
data,
|
|
1789
|
+
...data instanceof URL && originalUrl != null ? { originalUrl } : {},
|
|
1777
1790
|
providerOptions: part.providerOptions
|
|
1778
1791
|
};
|
|
1779
1792
|
}
|
|
@@ -2168,7 +2181,9 @@ var toolResultPartSchema = z4.object({
|
|
|
2168
2181
|
var toolApprovalRequestSchema = z4.object({
|
|
2169
2182
|
type: z4.literal("tool-approval-request"),
|
|
2170
2183
|
approvalId: z4.string(),
|
|
2171
|
-
toolCallId: z4.string()
|
|
2184
|
+
toolCallId: z4.string(),
|
|
2185
|
+
signature: z4.string().optional(),
|
|
2186
|
+
inputSchemaInput: z4.unknown().optional()
|
|
2172
2187
|
});
|
|
2173
2188
|
var toolApprovalResponseSchema = z4.object({
|
|
2174
2189
|
type: z4.literal("tool-approval-response"),
|
|
@@ -3134,8 +3149,8 @@ var DefaultGeneratedFile = class {
|
|
|
3134
3149
|
}
|
|
3135
3150
|
};
|
|
3136
3151
|
var DefaultGeneratedFileWithType = class extends DefaultGeneratedFile {
|
|
3137
|
-
constructor(
|
|
3138
|
-
super(
|
|
3152
|
+
constructor() {
|
|
3153
|
+
super(...arguments);
|
|
3139
3154
|
this.type = "file";
|
|
3140
3155
|
}
|
|
3141
3156
|
};
|
|
@@ -3263,6 +3278,43 @@ import {
|
|
|
3263
3278
|
asSchema as asSchema2,
|
|
3264
3279
|
safeValidateTypes as safeValidateTypes2
|
|
3265
3280
|
} from "@ai-sdk/provider-utils";
|
|
3281
|
+
|
|
3282
|
+
// src/util/is-deep-equal-data.ts
|
|
3283
|
+
function isDeepEqualData(obj1, obj2) {
|
|
3284
|
+
if (obj1 === obj2)
|
|
3285
|
+
return true;
|
|
3286
|
+
if (obj1 == null || obj2 == null)
|
|
3287
|
+
return false;
|
|
3288
|
+
if (typeof obj1 !== "object" && typeof obj2 !== "object")
|
|
3289
|
+
return obj1 === obj2;
|
|
3290
|
+
if (obj1.constructor !== obj2.constructor)
|
|
3291
|
+
return false;
|
|
3292
|
+
if (obj1 instanceof Date && obj2 instanceof Date) {
|
|
3293
|
+
return obj1.getTime() === obj2.getTime();
|
|
3294
|
+
}
|
|
3295
|
+
if (Array.isArray(obj1)) {
|
|
3296
|
+
if (obj1.length !== obj2.length)
|
|
3297
|
+
return false;
|
|
3298
|
+
for (let i = 0; i < obj1.length; i++) {
|
|
3299
|
+
if (!isDeepEqualData(obj1[i], obj2[i]))
|
|
3300
|
+
return false;
|
|
3301
|
+
}
|
|
3302
|
+
return true;
|
|
3303
|
+
}
|
|
3304
|
+
const keys1 = Object.keys(obj1);
|
|
3305
|
+
const keys2 = Object.keys(obj2);
|
|
3306
|
+
if (keys1.length !== keys2.length)
|
|
3307
|
+
return false;
|
|
3308
|
+
for (const key of keys1) {
|
|
3309
|
+
if (!keys2.includes(key))
|
|
3310
|
+
return false;
|
|
3311
|
+
if (!isDeepEqualData(obj1[key], obj2[key]))
|
|
3312
|
+
return false;
|
|
3313
|
+
}
|
|
3314
|
+
return true;
|
|
3315
|
+
}
|
|
3316
|
+
|
|
3317
|
+
// src/generate-text/validate-tool-approvals.ts
|
|
3266
3318
|
async function validateApprovedToolApprovals({
|
|
3267
3319
|
approvedToolApprovals,
|
|
3268
3320
|
tools,
|
|
@@ -3302,17 +3354,29 @@ async function validateApprovedToolApprovals({
|
|
|
3302
3354
|
}
|
|
3303
3355
|
}
|
|
3304
3356
|
if (tool2 != null && typeof tool2.execute === "function" && tool2.inputSchema != null) {
|
|
3357
|
+
const hasInputSchemaInput = Object.prototype.hasOwnProperty.call(
|
|
3358
|
+
approvalRequest,
|
|
3359
|
+
"inputSchemaInput"
|
|
3360
|
+
);
|
|
3305
3361
|
const validation = await safeValidateTypes2({
|
|
3306
|
-
value: toolCall.input,
|
|
3362
|
+
value: hasInputSchemaInput ? approvalRequest.inputSchemaInput : toolCall.input,
|
|
3307
3363
|
schema: asSchema2(tool2.inputSchema)
|
|
3308
3364
|
});
|
|
3365
|
+
let validationError;
|
|
3309
3366
|
if (!validation.success) {
|
|
3367
|
+
validationError = validation.error;
|
|
3368
|
+
} else if (!isDeepEqualData(validation.value, toolCall.input)) {
|
|
3369
|
+
validationError = new Error(
|
|
3370
|
+
"Approved tool input does not match the validated schema output."
|
|
3371
|
+
);
|
|
3372
|
+
}
|
|
3373
|
+
if (validationError != null) {
|
|
3310
3374
|
invalid.push({
|
|
3311
3375
|
...approval,
|
|
3312
3376
|
error: new InvalidToolInputError({
|
|
3313
3377
|
toolName: toolCall.toolName,
|
|
3314
3378
|
toolInput: JSON.stringify(toolCall.input),
|
|
3315
|
-
cause:
|
|
3379
|
+
cause: validationError
|
|
3316
3380
|
})
|
|
3317
3381
|
});
|
|
3318
3382
|
continue;
|
|
@@ -4039,6 +4103,22 @@ import {
|
|
|
4039
4103
|
safeParseJSON as safeParseJSON3,
|
|
4040
4104
|
safeValidateTypes as safeValidateTypes4
|
|
4041
4105
|
} from "@ai-sdk/provider-utils";
|
|
4106
|
+
|
|
4107
|
+
// src/generate-text/tool-call.ts
|
|
4108
|
+
var inputSchemaInputSymbol = Symbol("ai-sdk-tool-call-input-schema-input");
|
|
4109
|
+
function setToolCallInputSchemaInput(toolCall, inputSchemaInput) {
|
|
4110
|
+
Object.defineProperty(toolCall, inputSchemaInputSymbol, {
|
|
4111
|
+
value: inputSchemaInput
|
|
4112
|
+
});
|
|
4113
|
+
return toolCall;
|
|
4114
|
+
}
|
|
4115
|
+
function getToolCallInputSchemaInput(toolCall) {
|
|
4116
|
+
return inputSchemaInputSymbol in toolCall ? {
|
|
4117
|
+
value: toolCall[inputSchemaInputSymbol]
|
|
4118
|
+
} : void 0;
|
|
4119
|
+
}
|
|
4120
|
+
|
|
4121
|
+
// src/generate-text/parse-tool-call.ts
|
|
4042
4122
|
async function parseToolCall({
|
|
4043
4123
|
toolCall,
|
|
4044
4124
|
tools,
|
|
@@ -4145,26 +4225,29 @@ async function doParseToolCall({
|
|
|
4145
4225
|
cause: parseResult.error
|
|
4146
4226
|
});
|
|
4147
4227
|
}
|
|
4148
|
-
return
|
|
4149
|
-
type
|
|
4150
|
-
|
|
4151
|
-
|
|
4152
|
-
|
|
4153
|
-
|
|
4154
|
-
|
|
4155
|
-
|
|
4156
|
-
|
|
4157
|
-
|
|
4158
|
-
|
|
4159
|
-
|
|
4160
|
-
|
|
4161
|
-
|
|
4162
|
-
|
|
4163
|
-
|
|
4164
|
-
|
|
4165
|
-
|
|
4166
|
-
|
|
4167
|
-
|
|
4228
|
+
return setToolCallInputSchemaInput(
|
|
4229
|
+
tool2.type === "dynamic" ? {
|
|
4230
|
+
type: "tool-call",
|
|
4231
|
+
toolCallId: toolCall.toolCallId,
|
|
4232
|
+
toolName: toolCall.toolName,
|
|
4233
|
+
input: parseResult.value,
|
|
4234
|
+
providerExecuted: toolCall.providerExecuted,
|
|
4235
|
+
providerMetadata: toolCall.providerMetadata,
|
|
4236
|
+
...tool2.metadata != null ? { toolMetadata: tool2.metadata } : {},
|
|
4237
|
+
dynamic: true,
|
|
4238
|
+
title: tool2.title
|
|
4239
|
+
} : {
|
|
4240
|
+
type: "tool-call",
|
|
4241
|
+
toolCallId: toolCall.toolCallId,
|
|
4242
|
+
toolName,
|
|
4243
|
+
input: parseResult.value,
|
|
4244
|
+
providerExecuted: toolCall.providerExecuted,
|
|
4245
|
+
providerMetadata: toolCall.providerMetadata,
|
|
4246
|
+
...tool2.metadata != null ? { toolMetadata: tool2.metadata } : {},
|
|
4247
|
+
title: tool2.title
|
|
4248
|
+
},
|
|
4249
|
+
parseResult.rawValue
|
|
4250
|
+
);
|
|
4168
4251
|
}
|
|
4169
4252
|
|
|
4170
4253
|
// src/generate-text/prepare-step-call-settings.ts
|
|
@@ -4370,11 +4453,13 @@ async function toResponseMessages({
|
|
|
4370
4453
|
break;
|
|
4371
4454
|
}
|
|
4372
4455
|
case "tool-approval-request":
|
|
4456
|
+
const inputSchemaInput = getToolCallInputSchemaInput(part.toolCall);
|
|
4373
4457
|
content.push({
|
|
4374
4458
|
type: "tool-approval-request",
|
|
4375
4459
|
approvalId: part.approvalId,
|
|
4376
4460
|
toolCallId: part.toolCall.toolCallId,
|
|
4377
|
-
...part.signature != null ? { signature: part.signature } : {}
|
|
4461
|
+
...part.signature != null ? { signature: part.signature } : {},
|
|
4462
|
+
...inputSchemaInput != null && !isDeepEqualData(inputSchemaInput.value, part.toolCall.input) ? { inputSchemaInput: inputSchemaInput.value } : {}
|
|
4378
4463
|
});
|
|
4379
4464
|
break;
|
|
4380
4465
|
}
|
|
@@ -5502,8 +5587,6 @@ function writeToServerResponse({
|
|
|
5502
5587
|
});
|
|
5503
5588
|
}
|
|
5504
5589
|
}
|
|
5505
|
-
} catch (error) {
|
|
5506
|
-
throw error;
|
|
5507
5590
|
} finally {
|
|
5508
5591
|
response.end();
|
|
5509
5592
|
}
|
|
@@ -5667,6 +5750,7 @@ var uiMessageChunkSchema = lazySchema(
|
|
|
5667
5750
|
approvalId: z7.string(),
|
|
5668
5751
|
toolCallId: z7.string(),
|
|
5669
5752
|
approvalDescriptor: z7.unknown().optional(),
|
|
5753
|
+
inputSchemaInput: z7.unknown().optional(),
|
|
5670
5754
|
signature: z7.string().optional()
|
|
5671
5755
|
}),
|
|
5672
5756
|
z7.looseObject({
|
|
@@ -6247,6 +6331,10 @@ function processUIMessageStream({
|
|
|
6247
6331
|
toolInvocation.approval = {
|
|
6248
6332
|
id: chunk.approvalId,
|
|
6249
6333
|
...chunk.approvalDescriptor != null ? { descriptor: chunk.approvalDescriptor } : {},
|
|
6334
|
+
...Object.prototype.hasOwnProperty.call(
|
|
6335
|
+
chunk,
|
|
6336
|
+
"inputSchemaInput"
|
|
6337
|
+
) ? { inputSchemaInput: chunk.inputSchemaInput } : {},
|
|
6250
6338
|
...chunk.signature != null ? { signature: chunk.signature } : {}
|
|
6251
6339
|
};
|
|
6252
6340
|
write();
|
|
@@ -6892,8 +6980,10 @@ function runToolsTransformation({
|
|
|
6892
6980
|
attemptClose();
|
|
6893
6981
|
});
|
|
6894
6982
|
}
|
|
6983
|
+
const activeToolCallToolNames = /* @__PURE__ */ new Map();
|
|
6895
6984
|
const forwardStream = new TransformStream({
|
|
6896
6985
|
async transform(chunk, controller) {
|
|
6986
|
+
var _a23, _b, _c, _d;
|
|
6897
6987
|
const chunkType = chunk.type;
|
|
6898
6988
|
switch (chunkType) {
|
|
6899
6989
|
case "stream-start":
|
|
@@ -6903,9 +6993,6 @@ function runToolsTransformation({
|
|
|
6903
6993
|
case "reasoning-start":
|
|
6904
6994
|
case "reasoning-delta":
|
|
6905
6995
|
case "reasoning-end":
|
|
6906
|
-
case "tool-input-start":
|
|
6907
|
-
case "tool-input-delta":
|
|
6908
|
-
case "tool-input-end":
|
|
6909
6996
|
case "source":
|
|
6910
6997
|
case "response-metadata":
|
|
6911
6998
|
case "error":
|
|
@@ -6913,6 +7000,36 @@ function runToolsTransformation({
|
|
|
6913
7000
|
controller.enqueue(chunk);
|
|
6914
7001
|
break;
|
|
6915
7002
|
}
|
|
7003
|
+
case "tool-input-start": {
|
|
7004
|
+
activeToolCallToolNames.set(chunk.id, chunk.toolName);
|
|
7005
|
+
await ((_b = (_a23 = tools == null ? void 0 : tools[chunk.toolName]) == null ? void 0 : _a23.onInputStart) == null ? void 0 : _b.call(_a23, {
|
|
7006
|
+
toolCallId: chunk.id,
|
|
7007
|
+
messages,
|
|
7008
|
+
abortSignal,
|
|
7009
|
+
experimental_context
|
|
7010
|
+
}));
|
|
7011
|
+
controller.enqueue(chunk);
|
|
7012
|
+
break;
|
|
7013
|
+
}
|
|
7014
|
+
case "tool-input-delta": {
|
|
7015
|
+
const toolName = activeToolCallToolNames.get(chunk.id);
|
|
7016
|
+
if (toolName != null) {
|
|
7017
|
+
await ((_d = (_c = tools == null ? void 0 : tools[toolName]) == null ? void 0 : _c.onInputDelta) == null ? void 0 : _d.call(_c, {
|
|
7018
|
+
inputTextDelta: chunk.delta,
|
|
7019
|
+
toolCallId: chunk.id,
|
|
7020
|
+
messages,
|
|
7021
|
+
abortSignal,
|
|
7022
|
+
experimental_context
|
|
7023
|
+
}));
|
|
7024
|
+
}
|
|
7025
|
+
controller.enqueue(chunk);
|
|
7026
|
+
break;
|
|
7027
|
+
}
|
|
7028
|
+
case "tool-input-end": {
|
|
7029
|
+
activeToolCallToolNames.delete(chunk.id);
|
|
7030
|
+
controller.enqueue(chunk);
|
|
7031
|
+
break;
|
|
7032
|
+
}
|
|
6916
7033
|
case "file": {
|
|
6917
7034
|
controller.enqueue({
|
|
6918
7035
|
type: "file",
|
|
@@ -8134,7 +8251,6 @@ var DefaultStreamTextResult = class {
|
|
|
8134
8251
|
const stepToolCalls = [];
|
|
8135
8252
|
const stepToolOutputs = [];
|
|
8136
8253
|
let warnings;
|
|
8137
|
-
const activeToolCallToolNames = {};
|
|
8138
8254
|
let stepFinishReason = "other";
|
|
8139
8255
|
let stepRawFinishReason = void 0;
|
|
8140
8256
|
let hasReceivedTerminalChunk = false;
|
|
@@ -8281,16 +8397,7 @@ var DefaultStreamTextResult = class {
|
|
|
8281
8397
|
break;
|
|
8282
8398
|
}
|
|
8283
8399
|
case "tool-input-start": {
|
|
8284
|
-
activeToolCallToolNames[chunk.id] = chunk.toolName;
|
|
8285
8400
|
const tool2 = stepToolSet == null ? void 0 : stepToolSet[chunk.toolName];
|
|
8286
|
-
if ((tool2 == null ? void 0 : tool2.onInputStart) != null) {
|
|
8287
|
-
await tool2.onInputStart({
|
|
8288
|
-
toolCallId: chunk.id,
|
|
8289
|
-
messages: stepInputMessages,
|
|
8290
|
-
abortSignal,
|
|
8291
|
-
experimental_context
|
|
8292
|
-
});
|
|
8293
|
-
}
|
|
8294
8401
|
controller.enqueue({
|
|
8295
8402
|
...chunk,
|
|
8296
8403
|
dynamic: (_i2 = chunk.dynamic) != null ? _i2 : (tool2 == null ? void 0 : tool2.type) === "dynamic",
|
|
@@ -8299,22 +8406,10 @@ var DefaultStreamTextResult = class {
|
|
|
8299
8406
|
break;
|
|
8300
8407
|
}
|
|
8301
8408
|
case "tool-input-end": {
|
|
8302
|
-
delete activeToolCallToolNames[chunk.id];
|
|
8303
8409
|
controller.enqueue(chunk);
|
|
8304
8410
|
break;
|
|
8305
8411
|
}
|
|
8306
8412
|
case "tool-input-delta": {
|
|
8307
|
-
const toolName = activeToolCallToolNames[chunk.id];
|
|
8308
|
-
const tool2 = stepToolSet == null ? void 0 : stepToolSet[toolName];
|
|
8309
|
-
if ((tool2 == null ? void 0 : tool2.onInputDelta) != null) {
|
|
8310
|
-
await tool2.onInputDelta({
|
|
8311
|
-
inputTextDelta: chunk.delta,
|
|
8312
|
-
toolCallId: chunk.id,
|
|
8313
|
-
messages: stepInputMessages,
|
|
8314
|
-
abortSignal,
|
|
8315
|
-
experimental_context
|
|
8316
|
-
});
|
|
8317
|
-
}
|
|
8318
8413
|
controller.enqueue(chunk);
|
|
8319
8414
|
break;
|
|
8320
8415
|
}
|
|
@@ -8921,10 +9016,14 @@ var DefaultStreamTextResult = class {
|
|
|
8921
9016
|
break;
|
|
8922
9017
|
}
|
|
8923
9018
|
case "tool-approval-request": {
|
|
9019
|
+
const inputSchemaInput = getToolCallInputSchemaInput(
|
|
9020
|
+
part.toolCall
|
|
9021
|
+
);
|
|
8924
9022
|
controller.enqueue({
|
|
8925
9023
|
type: "tool-approval-request",
|
|
8926
9024
|
approvalId: part.approvalId,
|
|
8927
9025
|
toolCallId: part.toolCall.toolCallId,
|
|
9026
|
+
...inputSchemaInput != null && !isDeepEqualData(inputSchemaInput.value, part.toolCall.input) ? { inputSchemaInput: inputSchemaInput.value } : {},
|
|
8928
9027
|
...part.signature != null ? { signature: part.signature } : {}
|
|
8929
9028
|
});
|
|
8930
9029
|
break;
|
|
@@ -9519,6 +9618,12 @@ async function convertToModelMessages(messages, options) {
|
|
|
9519
9618
|
type: "tool-approval-request",
|
|
9520
9619
|
approvalId: part.approval.id,
|
|
9521
9620
|
toolCallId: part.toolCallId,
|
|
9621
|
+
...Object.prototype.hasOwnProperty.call(
|
|
9622
|
+
part.approval,
|
|
9623
|
+
"inputSchemaInput"
|
|
9624
|
+
) ? {
|
|
9625
|
+
inputSchemaInput: part.approval.inputSchemaInput
|
|
9626
|
+
} : {},
|
|
9522
9627
|
...part.approval.signature != null ? { signature: part.approval.signature } : {}
|
|
9523
9628
|
});
|
|
9524
9629
|
}
|
|
@@ -9674,8 +9779,29 @@ function asDynamicToolPart(toolPart) {
|
|
|
9674
9779
|
toolName: type.slice(5)
|
|
9675
9780
|
};
|
|
9676
9781
|
}
|
|
9677
|
-
|
|
9678
|
-
()
|
|
9782
|
+
function getToolPartInputSchemaInput(toolPart) {
|
|
9783
|
+
return toolPart.approval != null && Object.prototype.hasOwnProperty.call(toolPart.approval, "inputSchemaInput") ? { value: toolPart.approval.inputSchemaInput } : void 0;
|
|
9784
|
+
}
|
|
9785
|
+
var uiMessagesSchema = lazySchema2(() => {
|
|
9786
|
+
const approvalRequestedSchema = z8.object({
|
|
9787
|
+
id: z8.string(),
|
|
9788
|
+
approved: z8.never().optional(),
|
|
9789
|
+
descriptor: z8.unknown().optional(),
|
|
9790
|
+
reason: z8.never().optional(),
|
|
9791
|
+
signature: z8.string().optional(),
|
|
9792
|
+
inputSchemaInput: z8.unknown().optional()
|
|
9793
|
+
});
|
|
9794
|
+
const approvalRespondedSchema = approvalRequestedSchema.extend({
|
|
9795
|
+
approved: z8.boolean(),
|
|
9796
|
+
reason: z8.string().optional()
|
|
9797
|
+
});
|
|
9798
|
+
const approvalGrantedSchema = approvalRespondedSchema.extend({
|
|
9799
|
+
approved: z8.literal(true)
|
|
9800
|
+
});
|
|
9801
|
+
const approvalDeniedSchema = approvalRespondedSchema.extend({
|
|
9802
|
+
approved: z8.literal(false)
|
|
9803
|
+
});
|
|
9804
|
+
return zodSchema2(
|
|
9679
9805
|
z8.array(
|
|
9680
9806
|
z8.object({
|
|
9681
9807
|
id: z8.string(),
|
|
@@ -9763,13 +9889,7 @@ var uiMessagesSchema = lazySchema2(
|
|
|
9763
9889
|
output: z8.never().optional(),
|
|
9764
9890
|
errorText: z8.never().optional(),
|
|
9765
9891
|
callProviderMetadata: providerMetadataSchema.optional(),
|
|
9766
|
-
approval:
|
|
9767
|
-
id: z8.string(),
|
|
9768
|
-
approved: z8.never().optional(),
|
|
9769
|
-
descriptor: z8.unknown().optional(),
|
|
9770
|
-
reason: z8.never().optional(),
|
|
9771
|
-
signature: z8.string().optional()
|
|
9772
|
-
})
|
|
9892
|
+
approval: approvalRequestedSchema
|
|
9773
9893
|
}),
|
|
9774
9894
|
z8.object({
|
|
9775
9895
|
type: z8.literal("dynamic-tool"),
|
|
@@ -9782,13 +9902,7 @@ var uiMessagesSchema = lazySchema2(
|
|
|
9782
9902
|
output: z8.never().optional(),
|
|
9783
9903
|
errorText: z8.never().optional(),
|
|
9784
9904
|
callProviderMetadata: providerMetadataSchema.optional(),
|
|
9785
|
-
approval:
|
|
9786
|
-
id: z8.string(),
|
|
9787
|
-
approved: z8.boolean(),
|
|
9788
|
-
descriptor: z8.unknown().optional(),
|
|
9789
|
-
reason: z8.string().optional(),
|
|
9790
|
-
signature: z8.string().optional()
|
|
9791
|
-
})
|
|
9905
|
+
approval: approvalRespondedSchema
|
|
9792
9906
|
}),
|
|
9793
9907
|
z8.object({
|
|
9794
9908
|
type: z8.literal("dynamic-tool"),
|
|
@@ -9803,13 +9917,7 @@ var uiMessagesSchema = lazySchema2(
|
|
|
9803
9917
|
callProviderMetadata: providerMetadataSchema.optional(),
|
|
9804
9918
|
resultProviderMetadata: providerMetadataSchema.optional(),
|
|
9805
9919
|
preliminary: z8.boolean().optional(),
|
|
9806
|
-
approval:
|
|
9807
|
-
id: z8.string(),
|
|
9808
|
-
approved: z8.literal(true),
|
|
9809
|
-
descriptor: z8.unknown().optional(),
|
|
9810
|
-
reason: z8.string().optional(),
|
|
9811
|
-
signature: z8.string().optional()
|
|
9812
|
-
}).optional()
|
|
9920
|
+
approval: approvalGrantedSchema.optional()
|
|
9813
9921
|
}),
|
|
9814
9922
|
z8.object({
|
|
9815
9923
|
type: z8.literal("dynamic-tool"),
|
|
@@ -9824,13 +9932,7 @@ var uiMessagesSchema = lazySchema2(
|
|
|
9824
9932
|
errorText: z8.string(),
|
|
9825
9933
|
callProviderMetadata: providerMetadataSchema.optional(),
|
|
9826
9934
|
resultProviderMetadata: providerMetadataSchema.optional(),
|
|
9827
|
-
approval:
|
|
9828
|
-
id: z8.string(),
|
|
9829
|
-
approved: z8.literal(true),
|
|
9830
|
-
descriptor: z8.unknown().optional(),
|
|
9831
|
-
reason: z8.string().optional(),
|
|
9832
|
-
signature: z8.string().optional()
|
|
9833
|
-
}).optional()
|
|
9935
|
+
approval: approvalGrantedSchema.optional()
|
|
9834
9936
|
}),
|
|
9835
9937
|
z8.object({
|
|
9836
9938
|
type: z8.literal("dynamic-tool"),
|
|
@@ -9843,13 +9945,7 @@ var uiMessagesSchema = lazySchema2(
|
|
|
9843
9945
|
output: z8.never().optional(),
|
|
9844
9946
|
errorText: z8.never().optional(),
|
|
9845
9947
|
callProviderMetadata: providerMetadataSchema.optional(),
|
|
9846
|
-
approval:
|
|
9847
|
-
id: z8.string(),
|
|
9848
|
-
approved: z8.literal(false),
|
|
9849
|
-
descriptor: z8.unknown().optional(),
|
|
9850
|
-
reason: z8.string().optional(),
|
|
9851
|
-
signature: z8.string().optional()
|
|
9852
|
-
})
|
|
9948
|
+
approval: approvalDeniedSchema
|
|
9853
9949
|
}),
|
|
9854
9950
|
z8.object({
|
|
9855
9951
|
type: z8.string().startsWith("tool-"),
|
|
@@ -9885,13 +9981,7 @@ var uiMessagesSchema = lazySchema2(
|
|
|
9885
9981
|
output: z8.never().optional(),
|
|
9886
9982
|
errorText: z8.never().optional(),
|
|
9887
9983
|
callProviderMetadata: providerMetadataSchema.optional(),
|
|
9888
|
-
approval:
|
|
9889
|
-
id: z8.string(),
|
|
9890
|
-
approved: z8.never().optional(),
|
|
9891
|
-
descriptor: z8.unknown().optional(),
|
|
9892
|
-
reason: z8.never().optional(),
|
|
9893
|
-
signature: z8.string().optional()
|
|
9894
|
-
})
|
|
9984
|
+
approval: approvalRequestedSchema
|
|
9895
9985
|
}),
|
|
9896
9986
|
z8.object({
|
|
9897
9987
|
type: z8.string().startsWith("tool-"),
|
|
@@ -9903,13 +9993,7 @@ var uiMessagesSchema = lazySchema2(
|
|
|
9903
9993
|
output: z8.never().optional(),
|
|
9904
9994
|
errorText: z8.never().optional(),
|
|
9905
9995
|
callProviderMetadata: providerMetadataSchema.optional(),
|
|
9906
|
-
approval:
|
|
9907
|
-
id: z8.string(),
|
|
9908
|
-
approved: z8.boolean(),
|
|
9909
|
-
descriptor: z8.unknown().optional(),
|
|
9910
|
-
reason: z8.string().optional(),
|
|
9911
|
-
signature: z8.string().optional()
|
|
9912
|
-
})
|
|
9996
|
+
approval: approvalRespondedSchema
|
|
9913
9997
|
}),
|
|
9914
9998
|
z8.object({
|
|
9915
9999
|
type: z8.string().startsWith("tool-"),
|
|
@@ -9923,13 +10007,7 @@ var uiMessagesSchema = lazySchema2(
|
|
|
9923
10007
|
callProviderMetadata: providerMetadataSchema.optional(),
|
|
9924
10008
|
resultProviderMetadata: providerMetadataSchema.optional(),
|
|
9925
10009
|
preliminary: z8.boolean().optional(),
|
|
9926
|
-
approval:
|
|
9927
|
-
id: z8.string(),
|
|
9928
|
-
approved: z8.literal(true),
|
|
9929
|
-
descriptor: z8.unknown().optional(),
|
|
9930
|
-
reason: z8.string().optional(),
|
|
9931
|
-
signature: z8.string().optional()
|
|
9932
|
-
}).optional()
|
|
10010
|
+
approval: approvalGrantedSchema.optional()
|
|
9933
10011
|
}),
|
|
9934
10012
|
z8.object({
|
|
9935
10013
|
type: z8.string().startsWith("tool-"),
|
|
@@ -9943,13 +10021,7 @@ var uiMessagesSchema = lazySchema2(
|
|
|
9943
10021
|
errorText: z8.string(),
|
|
9944
10022
|
callProviderMetadata: providerMetadataSchema.optional(),
|
|
9945
10023
|
resultProviderMetadata: providerMetadataSchema.optional(),
|
|
9946
|
-
approval:
|
|
9947
|
-
id: z8.string(),
|
|
9948
|
-
approved: z8.literal(true),
|
|
9949
|
-
descriptor: z8.unknown().optional(),
|
|
9950
|
-
reason: z8.string().optional(),
|
|
9951
|
-
signature: z8.string().optional()
|
|
9952
|
-
}).optional()
|
|
10024
|
+
approval: approvalGrantedSchema.optional()
|
|
9953
10025
|
}),
|
|
9954
10026
|
z8.object({
|
|
9955
10027
|
type: z8.string().startsWith("tool-"),
|
|
@@ -9961,13 +10033,7 @@ var uiMessagesSchema = lazySchema2(
|
|
|
9961
10033
|
output: z8.never().optional(),
|
|
9962
10034
|
errorText: z8.never().optional(),
|
|
9963
10035
|
callProviderMetadata: providerMetadataSchema.optional(),
|
|
9964
|
-
approval:
|
|
9965
|
-
id: z8.string(),
|
|
9966
|
-
approved: z8.literal(false),
|
|
9967
|
-
descriptor: z8.unknown().optional(),
|
|
9968
|
-
reason: z8.string().optional(),
|
|
9969
|
-
signature: z8.string().optional()
|
|
9970
|
-
})
|
|
10036
|
+
approval: approvalDeniedSchema
|
|
9971
10037
|
})
|
|
9972
10038
|
])
|
|
9973
10039
|
)
|
|
@@ -9985,8 +10051,8 @@ var uiMessagesSchema = lazySchema2(
|
|
|
9985
10051
|
}
|
|
9986
10052
|
})
|
|
9987
10053
|
).nonempty("Messages array must not be empty")
|
|
9988
|
-
)
|
|
9989
|
-
);
|
|
10054
|
+
);
|
|
10055
|
+
});
|
|
9990
10056
|
async function safeValidateUIMessagesInternal({
|
|
9991
10057
|
messages,
|
|
9992
10058
|
metadataSchema,
|
|
@@ -10012,7 +10078,7 @@ async function safeValidateUIMessagesInternal({
|
|
|
10012
10078
|
});
|
|
10013
10079
|
if (metadataSchema) {
|
|
10014
10080
|
for (const [msgIdx, message] of validatedMessages.entries()) {
|
|
10015
|
-
await validateTypes3({
|
|
10081
|
+
message.metadata = await validateTypes3({
|
|
10016
10082
|
value: message.metadata,
|
|
10017
10083
|
schema: metadataSchema,
|
|
10018
10084
|
context: {
|
|
@@ -10044,7 +10110,7 @@ async function safeValidateUIMessagesInternal({
|
|
|
10044
10110
|
})
|
|
10045
10111
|
};
|
|
10046
10112
|
}
|
|
10047
|
-
await validateTypes3({
|
|
10113
|
+
dataPart.data = await validateTypes3({
|
|
10048
10114
|
value: dataPart.data,
|
|
10049
10115
|
schema: dataSchema,
|
|
10050
10116
|
context: {
|
|
@@ -10086,35 +10152,34 @@ async function safeValidateUIMessagesInternal({
|
|
|
10086
10152
|
entityName: toolName,
|
|
10087
10153
|
entityId: toolPart.toolCallId
|
|
10088
10154
|
};
|
|
10155
|
+
const inputSchemaInput = getToolPartInputSchemaInput(toolPart);
|
|
10156
|
+
const inputToValidate = inputSchemaInput == null ? toolPart.input : inputSchemaInput.value;
|
|
10089
10157
|
let convertToDynamic = false;
|
|
10090
|
-
if (toolPart.state
|
|
10091
|
-
if (toolPart.input !== void 0) {
|
|
10092
|
-
const result = await safeValidateTypes5({
|
|
10093
|
-
value: toolPart.input,
|
|
10094
|
-
schema: tool2.inputSchema,
|
|
10095
|
-
context: inputValidationContext
|
|
10096
|
-
});
|
|
10097
|
-
convertToDynamic = !result.success;
|
|
10098
|
-
}
|
|
10099
|
-
} else if (toolPart.state === "output-available") {
|
|
10158
|
+
if (toolPart.state !== "input-streaming" && (toolPart.state !== "output-error" || inputSchemaInput != null || toolPart.input !== void 0)) {
|
|
10100
10159
|
const result = await safeValidateTypes5({
|
|
10101
|
-
value:
|
|
10160
|
+
value: inputToValidate,
|
|
10102
10161
|
schema: tool2.inputSchema,
|
|
10103
10162
|
context: inputValidationContext
|
|
10104
10163
|
});
|
|
10164
|
+
let inputError;
|
|
10105
10165
|
if (!result.success) {
|
|
10106
|
-
|
|
10166
|
+
inputError = result.error;
|
|
10167
|
+
} else if (inputSchemaInput != null) {
|
|
10168
|
+
if (!isDeepEqualData(result.value, toolPart.input)) {
|
|
10169
|
+
inputError = new TypeValidationError3({
|
|
10170
|
+
value: toolPart.input,
|
|
10171
|
+
cause: "Tool input does not match the output reconstructed from inputSchemaInput.",
|
|
10172
|
+
context: inputValidationContext
|
|
10173
|
+
});
|
|
10174
|
+
}
|
|
10175
|
+
}
|
|
10176
|
+
if (inputError != null) {
|
|
10177
|
+
if (toolPart.state === "output-error" || toolPart.state === "output-available" && isEmptyObject(toolPart.input)) {
|
|
10107
10178
|
convertToDynamic = true;
|
|
10108
10179
|
} else {
|
|
10109
|
-
throw
|
|
10180
|
+
throw inputError;
|
|
10110
10181
|
}
|
|
10111
10182
|
}
|
|
10112
|
-
} else if (toolPart.state === "input-available" || toolPart.state === "approval-requested" || toolPart.state === "approval-responded" || toolPart.state === "output-denied") {
|
|
10113
|
-
await validateTypes3({
|
|
10114
|
-
value: toolPart.input,
|
|
10115
|
-
schema: tool2.inputSchema,
|
|
10116
|
-
context: inputValidationContext
|
|
10117
|
-
});
|
|
10118
10183
|
}
|
|
10119
10184
|
if (toolPart.state === "output-available" && tool2.outputSchema) {
|
|
10120
10185
|
await validateTypes3({
|
|
@@ -10383,6 +10448,14 @@ function getEmbeddingModelMaxInputBytesPerCall(model) {
|
|
|
10383
10448
|
return model[EXPERIMENTAL_EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL];
|
|
10384
10449
|
}
|
|
10385
10450
|
|
|
10451
|
+
// src/model/get-embedding-model-provider-options-transformer.ts
|
|
10452
|
+
import {
|
|
10453
|
+
EXPERIMENTAL_EMBEDDING_MODEL_PROVIDER_OPTIONS_TRANSFORMER
|
|
10454
|
+
} from "@ai-sdk/provider-utils";
|
|
10455
|
+
function getEmbeddingModelProviderOptionsTransformer(model) {
|
|
10456
|
+
return model[EXPERIMENTAL_EMBEDDING_MODEL_PROVIDER_OPTIONS_TRANSFORMER];
|
|
10457
|
+
}
|
|
10458
|
+
|
|
10386
10459
|
// src/util/split-array.ts
|
|
10387
10460
|
function splitArray(array2, chunkSize) {
|
|
10388
10461
|
if (chunkSize <= 0) {
|
|
@@ -10437,7 +10510,6 @@ async function embedMany({
|
|
|
10437
10510
|
}),
|
|
10438
10511
|
tracer,
|
|
10439
10512
|
fn: async (span) => {
|
|
10440
|
-
var _a23;
|
|
10441
10513
|
const [
|
|
10442
10514
|
maxEmbeddingsPerCall,
|
|
10443
10515
|
maxInputBytesPerCall,
|
|
@@ -10469,7 +10541,7 @@ async function embedMany({
|
|
|
10469
10541
|
}),
|
|
10470
10542
|
tracer,
|
|
10471
10543
|
fn: async (doEmbedSpan) => {
|
|
10472
|
-
var
|
|
10544
|
+
var _a23, _b;
|
|
10473
10545
|
const modelResponse = await model.doEmbed({
|
|
10474
10546
|
values,
|
|
10475
10547
|
abortSignal,
|
|
@@ -10477,7 +10549,7 @@ async function embedMany({
|
|
|
10477
10549
|
providerOptions
|
|
10478
10550
|
});
|
|
10479
10551
|
const embeddings3 = modelResponse.embeddings;
|
|
10480
|
-
const usage2 = (
|
|
10552
|
+
const usage2 = (_a23 = modelResponse.usage) != null ? _a23 : { tokens: NaN };
|
|
10481
10553
|
doEmbedSpan.setAttributes(
|
|
10482
10554
|
await selectTelemetryAttributes({
|
|
10483
10555
|
telemetry,
|
|
@@ -10531,6 +10603,7 @@ async function embedMany({
|
|
|
10531
10603
|
maxEmbeddingsPerCall: hasEmbeddingLimit ? maxEmbeddingsPerCall : Infinity,
|
|
10532
10604
|
maxInputBytesPerCall: hasInputByteLimit ? maxInputBytesPerCall : Infinity
|
|
10533
10605
|
});
|
|
10606
|
+
const providerOptionsTransformer = getEmbeddingModelProviderOptionsTransformer(model);
|
|
10534
10607
|
const embeddings = [];
|
|
10535
10608
|
const warnings = [];
|
|
10536
10609
|
const responses = [];
|
|
@@ -10540,9 +10613,18 @@ async function embedMany({
|
|
|
10540
10613
|
valueChunks,
|
|
10541
10614
|
supportsParallelCalls ? maxParallelCalls : 1
|
|
10542
10615
|
);
|
|
10616
|
+
let nextChunkStartIndex = 0;
|
|
10543
10617
|
for (const parallelChunk of parallelChunks) {
|
|
10544
10618
|
const results = await Promise.all(
|
|
10545
|
-
parallelChunk.map((chunk) => {
|
|
10619
|
+
parallelChunk.map(async (chunk) => {
|
|
10620
|
+
const startIndex = nextChunkStartIndex;
|
|
10621
|
+
nextChunkStartIndex += chunk.length;
|
|
10622
|
+
const chunkProviderOptions = providerOptionsTransformer ? await providerOptionsTransformer({
|
|
10623
|
+
providerOptions,
|
|
10624
|
+
values,
|
|
10625
|
+
startIndex,
|
|
10626
|
+
endIndex: startIndex + chunk.length
|
|
10627
|
+
}) : providerOptions;
|
|
10546
10628
|
return retry(() => {
|
|
10547
10629
|
return recordSpan({
|
|
10548
10630
|
name: "ai.embedMany.doEmbed",
|
|
@@ -10562,15 +10644,15 @@ async function embedMany({
|
|
|
10562
10644
|
}),
|
|
10563
10645
|
tracer,
|
|
10564
10646
|
fn: async (doEmbedSpan) => {
|
|
10565
|
-
var
|
|
10647
|
+
var _a23, _b;
|
|
10566
10648
|
const modelResponse = await model.doEmbed({
|
|
10567
10649
|
values: chunk,
|
|
10568
10650
|
abortSignal,
|
|
10569
10651
|
headers: headersWithUserAgent,
|
|
10570
|
-
providerOptions
|
|
10652
|
+
providerOptions: chunkProviderOptions
|
|
10571
10653
|
});
|
|
10572
10654
|
const embeddings2 = modelResponse.embeddings;
|
|
10573
|
-
const usage = (
|
|
10655
|
+
const usage = (_a23 = modelResponse.usage) != null ? _a23 : { tokens: NaN };
|
|
10574
10656
|
doEmbedSpan.setAttributes(
|
|
10575
10657
|
await selectTelemetryAttributes({
|
|
10576
10658
|
telemetry,
|
|
@@ -10609,7 +10691,7 @@ async function embedMany({
|
|
|
10609
10691
|
result.providerMetadata
|
|
10610
10692
|
)) {
|
|
10611
10693
|
providerMetadata[providerName] = {
|
|
10612
|
-
...
|
|
10694
|
+
...providerMetadata[providerName],
|
|
10613
10695
|
...metadata
|
|
10614
10696
|
};
|
|
10615
10697
|
}
|
|
@@ -11674,41 +11756,6 @@ function getTextFromDataUrl(dataUrl) {
|
|
|
11674
11756
|
}
|
|
11675
11757
|
}
|
|
11676
11758
|
|
|
11677
|
-
// src/util/is-deep-equal-data.ts
|
|
11678
|
-
function isDeepEqualData(obj1, obj2) {
|
|
11679
|
-
if (obj1 === obj2)
|
|
11680
|
-
return true;
|
|
11681
|
-
if (obj1 == null || obj2 == null)
|
|
11682
|
-
return false;
|
|
11683
|
-
if (typeof obj1 !== "object" && typeof obj2 !== "object")
|
|
11684
|
-
return obj1 === obj2;
|
|
11685
|
-
if (obj1.constructor !== obj2.constructor)
|
|
11686
|
-
return false;
|
|
11687
|
-
if (obj1 instanceof Date && obj2 instanceof Date) {
|
|
11688
|
-
return obj1.getTime() === obj2.getTime();
|
|
11689
|
-
}
|
|
11690
|
-
if (Array.isArray(obj1)) {
|
|
11691
|
-
if (obj1.length !== obj2.length)
|
|
11692
|
-
return false;
|
|
11693
|
-
for (let i = 0; i < obj1.length; i++) {
|
|
11694
|
-
if (!isDeepEqualData(obj1[i], obj2[i]))
|
|
11695
|
-
return false;
|
|
11696
|
-
}
|
|
11697
|
-
return true;
|
|
11698
|
-
}
|
|
11699
|
-
const keys1 = Object.keys(obj1);
|
|
11700
|
-
const keys2 = Object.keys(obj2);
|
|
11701
|
-
if (keys1.length !== keys2.length)
|
|
11702
|
-
return false;
|
|
11703
|
-
for (const key of keys1) {
|
|
11704
|
-
if (!keys2.includes(key))
|
|
11705
|
-
return false;
|
|
11706
|
-
if (!isDeepEqualData(obj1[key], obj2[key]))
|
|
11707
|
-
return false;
|
|
11708
|
-
}
|
|
11709
|
-
return true;
|
|
11710
|
-
}
|
|
11711
|
-
|
|
11712
11759
|
// src/util/serial-job-executor.ts
|
|
11713
11760
|
var SerialJobExecutor = class {
|
|
11714
11761
|
constructor() {
|
|
@@ -13413,7 +13460,10 @@ var doWrap = ({
|
|
|
13413
13460
|
};
|
|
13414
13461
|
|
|
13415
13462
|
// src/middleware/wrap-embedding-model.ts
|
|
13416
|
-
import {
|
|
13463
|
+
import {
|
|
13464
|
+
EXPERIMENTAL_EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL as EXPERIMENTAL_EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL2,
|
|
13465
|
+
EXPERIMENTAL_EMBEDDING_MODEL_PROVIDER_OPTIONS_TRANSFORMER as EXPERIMENTAL_EMBEDDING_MODEL_PROVIDER_OPTIONS_TRANSFORMER2
|
|
13466
|
+
} from "@ai-sdk/provider-utils";
|
|
13417
13467
|
var wrapEmbeddingModel = ({
|
|
13418
13468
|
model,
|
|
13419
13469
|
middleware: middlewareArg,
|
|
@@ -13449,6 +13499,7 @@ var doWrap2 = ({
|
|
|
13449
13499
|
modelId: (_b = modelId != null ? modelId : overrideModelId == null ? void 0 : overrideModelId({ model })) != null ? _b : model.modelId,
|
|
13450
13500
|
maxEmbeddingsPerCall: (_c = overrideMaxEmbeddingsPerCall == null ? void 0 : overrideMaxEmbeddingsPerCall({ model })) != null ? _c : model.maxEmbeddingsPerCall,
|
|
13451
13501
|
[EXPERIMENTAL_EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL2]: getEmbeddingModelMaxInputBytesPerCall(model),
|
|
13502
|
+
[EXPERIMENTAL_EMBEDDING_MODEL_PROVIDER_OPTIONS_TRANSFORMER2]: getEmbeddingModelProviderOptionsTransformer(model),
|
|
13452
13503
|
supportsParallelCalls: (_d = overrideSupportsParallelCalls == null ? void 0 : overrideSupportsParallelCalls({ model })) != null ? _d : model.supportsParallelCalls,
|
|
13453
13504
|
async doEmbed(params) {
|
|
13454
13505
|
const transformedParams = await doTransform({ params });
|
|
@@ -14267,7 +14318,7 @@ var HttpChatTransport = class {
|
|
|
14267
14318
|
const response = await fetch2(api, {
|
|
14268
14319
|
method: "POST",
|
|
14269
14320
|
headers: {
|
|
14270
|
-
"
|
|
14321
|
+
"content-type": "application/json",
|
|
14271
14322
|
...headers
|
|
14272
14323
|
},
|
|
14273
14324
|
body: JSON.stringify(body),
|
|
@@ -14375,9 +14426,24 @@ var AbstractChat = class {
|
|
|
14375
14426
|
this.sendMessage = async (message, options) => {
|
|
14376
14427
|
var _a23, _b, _c, _d;
|
|
14377
14428
|
if (message == null) {
|
|
14378
|
-
|
|
14379
|
-
|
|
14380
|
-
messageId
|
|
14429
|
+
let messageId = this.pendingApprovalMessageId;
|
|
14430
|
+
if (messageId == null) {
|
|
14431
|
+
messageId = (_a23 = this.lastMessage) == null ? void 0 : _a23.id;
|
|
14432
|
+
for (let i = this.state.messages.length - 1; i >= 0; i--) {
|
|
14433
|
+
const candidate = this.state.messages[i];
|
|
14434
|
+
if (candidate.role === "assistant" && candidate.parts.some(
|
|
14435
|
+
(part) => isToolUIPart(part) && part.state === "approval-responded"
|
|
14436
|
+
)) {
|
|
14437
|
+
messageId = candidate.id;
|
|
14438
|
+
break;
|
|
14439
|
+
}
|
|
14440
|
+
}
|
|
14441
|
+
}
|
|
14442
|
+
const consumesPendingApproval = messageId != null && messageId === this.pendingApprovalMessageId;
|
|
14443
|
+
const pendingApprovalMessageIndex = consumesPendingApproval ? this.state.messages.findIndex((message2) => message2.id === messageId) : -1;
|
|
14444
|
+
await this.makeRequestForToolApproval({
|
|
14445
|
+
messageId,
|
|
14446
|
+
messageIndex: pendingApprovalMessageIndex,
|
|
14381
14447
|
...options
|
|
14382
14448
|
});
|
|
14383
14449
|
return;
|
|
@@ -14472,16 +14538,24 @@ var AbstractChat = class {
|
|
|
14472
14538
|
options
|
|
14473
14539
|
}) => this.jobExecutor.run(async () => {
|
|
14474
14540
|
const messages = this.state.messages;
|
|
14475
|
-
const lastMessage = messages[messages.length - 1];
|
|
14476
14541
|
const updatePart = (part) => isToolUIPart(part) && part.state === "approval-requested" && part.approval.id === id ? {
|
|
14477
14542
|
...part,
|
|
14478
14543
|
state: "approval-responded",
|
|
14479
14544
|
approval: { ...part.approval, id, approved, reason }
|
|
14480
14545
|
} : part;
|
|
14481
|
-
|
|
14482
|
-
|
|
14483
|
-
|
|
14484
|
-
|
|
14546
|
+
const messageIndex = messages.findIndex(
|
|
14547
|
+
(message) => message.parts.some(
|
|
14548
|
+
(part) => isToolUIPart(part) && part.state === "approval-requested" && part.approval.id === id
|
|
14549
|
+
)
|
|
14550
|
+
);
|
|
14551
|
+
if (messageIndex !== -1) {
|
|
14552
|
+
const message = messages[messageIndex];
|
|
14553
|
+
this.state.replaceMessage(messageIndex, {
|
|
14554
|
+
...message,
|
|
14555
|
+
parts: message.parts.map(updatePart)
|
|
14556
|
+
});
|
|
14557
|
+
this.pendingApprovalMessageId = message.id;
|
|
14558
|
+
}
|
|
14485
14559
|
if (this.activeResponse) {
|
|
14486
14560
|
this.activeResponse.state.message.parts = this.activeResponse.state.message.parts.map(updatePart);
|
|
14487
14561
|
}
|
|
@@ -14489,9 +14563,10 @@ var AbstractChat = class {
|
|
|
14489
14563
|
this.shouldSendAutomatically().then((shouldSend) => {
|
|
14490
14564
|
var _a23;
|
|
14491
14565
|
if (shouldSend) {
|
|
14492
|
-
this.
|
|
14493
|
-
|
|
14494
|
-
messageId
|
|
14566
|
+
const messageId = messageIndex === -1 ? (_a23 = this.lastMessage) == null ? void 0 : _a23.id : messages[messageIndex].id;
|
|
14567
|
+
this.makeRequestForToolApproval({
|
|
14568
|
+
messageId,
|
|
14569
|
+
messageIndex,
|
|
14495
14570
|
...options
|
|
14496
14571
|
});
|
|
14497
14572
|
}
|
|
@@ -14593,6 +14668,25 @@ var AbstractChat = class {
|
|
|
14593
14668
|
}
|
|
14594
14669
|
return result;
|
|
14595
14670
|
}
|
|
14671
|
+
async makeRequestForToolApproval({
|
|
14672
|
+
messageId,
|
|
14673
|
+
messageIndex,
|
|
14674
|
+
...options
|
|
14675
|
+
}) {
|
|
14676
|
+
var _a23, _b;
|
|
14677
|
+
const consumesPendingApproval = messageId != null && messageId === this.pendingApprovalMessageId;
|
|
14678
|
+
if (consumesPendingApproval) {
|
|
14679
|
+
this.pendingApprovalMessageId = void 0;
|
|
14680
|
+
}
|
|
14681
|
+
await this.makeRequest({
|
|
14682
|
+
trigger: "submit-message",
|
|
14683
|
+
messageId,
|
|
14684
|
+
...options
|
|
14685
|
+
});
|
|
14686
|
+
if (consumesPendingApproval && this.status === "error" && this.pendingApprovalMessageId == null) {
|
|
14687
|
+
this.pendingApprovalMessageId = (_b = (_a23 = this.state.messages[messageIndex]) == null ? void 0 : _a23.id) != null ? _b : messageId;
|
|
14688
|
+
}
|
|
14689
|
+
}
|
|
14596
14690
|
async makeRequest({
|
|
14597
14691
|
trigger,
|
|
14598
14692
|
metadata,
|
|
@@ -14659,6 +14753,9 @@ var AbstractChat = class {
|
|
|
14659
14753
|
}
|
|
14660
14754
|
this.setStatus({ status: "submitted", error: void 0 });
|
|
14661
14755
|
const lastMessage = this.lastMessage;
|
|
14756
|
+
const responseMessageIndex = trigger === "submit-message" && messageId != null ? this.state.messages.findIndex((message) => message.id === messageId) : this.state.messages.length - 1;
|
|
14757
|
+
const responseMessage = responseMessageIndex === -1 ? lastMessage : this.state.messages[responseMessageIndex];
|
|
14758
|
+
const usesEarlierAssistantMessage = responseMessageIndex !== -1 && responseMessageIndex < this.state.messages.length - 1 && (responseMessage == null ? void 0 : responseMessage.role) === "assistant";
|
|
14662
14759
|
let isAbort = false;
|
|
14663
14760
|
let isDisconnect = false;
|
|
14664
14761
|
let isError = false;
|
|
@@ -14666,7 +14763,7 @@ var AbstractChat = class {
|
|
|
14666
14763
|
try {
|
|
14667
14764
|
const response = {
|
|
14668
14765
|
state: createStreamingUIMessageState({
|
|
14669
|
-
lastMessage: trigger === "resume-stream" || trigger === "regenerate-message" ? void 0 : this.state.snapshot(
|
|
14766
|
+
lastMessage: trigger === "resume-stream" || trigger === "regenerate-message" ? void 0 : this.state.snapshot(responseMessage),
|
|
14670
14767
|
messageId: this.generateId()
|
|
14671
14768
|
}),
|
|
14672
14769
|
abortController
|
|
@@ -14707,8 +14804,12 @@ var AbstractChat = class {
|
|
|
14707
14804
|
if (updateStatus) {
|
|
14708
14805
|
this.setStatus({ status: "streaming" });
|
|
14709
14806
|
}
|
|
14710
|
-
|
|
14711
|
-
|
|
14807
|
+
if (usesEarlierAssistantMessage) {
|
|
14808
|
+
this.state.replaceMessage(
|
|
14809
|
+
responseMessageIndex,
|
|
14810
|
+
response.state.message
|
|
14811
|
+
);
|
|
14812
|
+
} else if (response.state.message.id === ((_a24 = this.lastMessage) == null ? void 0 : _a24.id)) {
|
|
14712
14813
|
this.state.replaceMessage(
|
|
14713
14814
|
this.state.messages.length - 1,
|
|
14714
14815
|
response.state.message
|
|
@@ -14855,7 +14956,7 @@ function lastAssistantMessageIsCompleteWithApprovalResponses({
|
|
|
14855
14956
|
// has at least one tool approval response
|
|
14856
14957
|
lastStepToolInvocations.filter((part) => part.state === "approval-responded").length > 0 && // all tool approvals must have a response
|
|
14857
14958
|
lastStepToolInvocations.every(
|
|
14858
|
-
(part) => part.state === "output-available" || part.state === "output-error" || part.state === "output-denied" || part.state === "approval-responded"
|
|
14959
|
+
(part) => part.state === "output-available" && part.preliminary !== true || part.state === "output-error" || part.state === "output-denied" || part.state === "approval-responded"
|
|
14859
14960
|
)
|
|
14860
14961
|
);
|
|
14861
14962
|
}
|
|
@@ -14876,7 +14977,7 @@ function lastAssistantMessageIsCompleteWithToolCalls({
|
|
|
14876
14977
|
}, -1);
|
|
14877
14978
|
const lastStepToolInvocations = message.parts.slice(lastStepStartIndex + 1).filter(isToolUIPart).filter((part) => !part.providerExecuted);
|
|
14878
14979
|
return lastStepToolInvocations.length > 0 && lastStepToolInvocations.every(
|
|
14879
|
-
(part) => part.state === "output-available" || part.state === "output-error"
|
|
14980
|
+
(part) => part.state === "output-available" && part.preliminary !== true || part.state === "output-error"
|
|
14880
14981
|
);
|
|
14881
14982
|
}
|
|
14882
14983
|
|