ai 5.0.0-canary.15 → 5.0.0-canary.16
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 +15 -0
- package/dist/index.d.mts +46 -51
- package/dist/index.d.ts +46 -51
- package/dist/index.js +112 -180
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +111 -178
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +12 -18
- package/dist/internal/index.d.ts +12 -18
- package/dist/internal/index.js +1 -63
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +1 -63
- package/dist/internal/index.mjs.map +1 -1
- package/dist/mcp-stdio/index.d.mts +2 -2
- package/dist/mcp-stdio/index.d.ts +2 -2
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
@@ -29,6 +29,21 @@ function calculateLanguageModelUsage({
|
|
29
29
|
};
|
30
30
|
}
|
31
31
|
|
32
|
+
// core/ui/get-tool-invocations.ts
|
33
|
+
function getToolInvocations(message) {
|
34
|
+
return message.parts.filter(
|
35
|
+
(part) => part.type === "tool-invocation"
|
36
|
+
).map((part) => part.toolInvocation);
|
37
|
+
}
|
38
|
+
|
39
|
+
// core/util/extract-max-tool-invocation-step.ts
|
40
|
+
function extractMaxToolInvocationStep(toolInvocations) {
|
41
|
+
return toolInvocations == null ? void 0 : toolInvocations.reduce((max, toolInvocation) => {
|
42
|
+
var _a17;
|
43
|
+
return Math.max(max, (_a17 = toolInvocation.step) != null ? _a17 : 0);
|
44
|
+
}, 0);
|
45
|
+
}
|
46
|
+
|
32
47
|
// core/util/parse-partial-json.ts
|
33
48
|
import { safeParseJSON } from "@ai-sdk/provider-utils";
|
34
49
|
|
@@ -751,13 +766,9 @@ async function processChatResponse({
|
|
751
766
|
getCurrentDate = () => /* @__PURE__ */ new Date(),
|
752
767
|
lastMessage
|
753
768
|
}) {
|
754
|
-
var _a17
|
769
|
+
var _a17;
|
755
770
|
const replaceLastMessage = (lastMessage == null ? void 0 : lastMessage.role) === "assistant";
|
756
|
-
let step = replaceLastMessage ? 1 +
|
757
|
-
((_b = (_a17 = lastMessage.toolInvocations) == null ? void 0 : _a17.reduce((max, toolInvocation) => {
|
758
|
-
var _a18;
|
759
|
-
return Math.max(max, (_a18 = toolInvocation.step) != null ? _a18 : 0);
|
760
|
-
}, 0)) != null ? _b : 0) : 0;
|
771
|
+
let step = replaceLastMessage ? 1 + ((_a17 = extractMaxToolInvocationStep(getToolInvocations(lastMessage))) != null ? _a17 : 0) : 0;
|
761
772
|
const message = replaceLastMessage ? structuredClone(lastMessage) : {
|
762
773
|
id: generateId3(),
|
763
774
|
createdAt: getCurrentDate(),
|
@@ -830,12 +841,12 @@ async function processChatResponse({
|
|
830
841
|
if (currentReasoningPart == null) {
|
831
842
|
currentReasoningPart = {
|
832
843
|
type: "reasoning",
|
833
|
-
|
844
|
+
text: value.text,
|
834
845
|
providerMetadata: value.providerMetadata
|
835
846
|
};
|
836
847
|
message.parts.push(currentReasoningPart);
|
837
848
|
} else {
|
838
|
-
currentReasoningPart.
|
849
|
+
currentReasoningPart.text += value.text;
|
839
850
|
currentReasoningPart.providerMetadata = value.providerMetadata;
|
840
851
|
}
|
841
852
|
execUpdate();
|
@@ -861,24 +872,20 @@ async function processChatResponse({
|
|
861
872
|
execUpdate();
|
862
873
|
},
|
863
874
|
onToolCallStreamingStartPart(value) {
|
864
|
-
|
865
|
-
message.toolInvocations = [];
|
866
|
-
}
|
875
|
+
const toolInvocations = getToolInvocations(message);
|
867
876
|
partialToolCalls[value.toolCallId] = {
|
868
877
|
text: "",
|
869
878
|
step,
|
870
879
|
toolName: value.toolName,
|
871
|
-
index:
|
880
|
+
index: toolInvocations.length
|
872
881
|
};
|
873
|
-
|
882
|
+
updateToolInvocationPart(value.toolCallId, {
|
874
883
|
state: "partial-call",
|
875
884
|
step,
|
876
885
|
toolCallId: value.toolCallId,
|
877
886
|
toolName: value.toolName,
|
878
887
|
args: void 0
|
879
|
-
};
|
880
|
-
message.toolInvocations.push(invocation);
|
881
|
-
updateToolInvocationPart(value.toolCallId, invocation);
|
888
|
+
});
|
882
889
|
execUpdate();
|
883
890
|
},
|
884
891
|
async onToolCallDeltaPart(value) {
|
@@ -887,68 +894,53 @@ async function processChatResponse({
|
|
887
894
|
const { value: partialArgs } = await parsePartialJson(
|
888
895
|
partialToolCall.text
|
889
896
|
);
|
890
|
-
|
897
|
+
updateToolInvocationPart(value.toolCallId, {
|
891
898
|
state: "partial-call",
|
892
899
|
step: partialToolCall.step,
|
893
900
|
toolCallId: value.toolCallId,
|
894
901
|
toolName: partialToolCall.toolName,
|
895
902
|
args: partialArgs
|
896
|
-
};
|
897
|
-
message.toolInvocations[partialToolCall.index] = invocation;
|
898
|
-
updateToolInvocationPart(value.toolCallId, invocation);
|
903
|
+
});
|
899
904
|
execUpdate();
|
900
905
|
},
|
901
906
|
async onToolCallPart(value) {
|
902
|
-
|
907
|
+
updateToolInvocationPart(value.toolCallId, {
|
903
908
|
state: "call",
|
904
909
|
step,
|
905
910
|
...value
|
906
|
-
};
|
907
|
-
if (partialToolCalls[value.toolCallId] != null) {
|
908
|
-
message.toolInvocations[partialToolCalls[value.toolCallId].index] = invocation;
|
909
|
-
} else {
|
910
|
-
if (message.toolInvocations == null) {
|
911
|
-
message.toolInvocations = [];
|
912
|
-
}
|
913
|
-
message.toolInvocations.push(invocation);
|
914
|
-
}
|
915
|
-
updateToolInvocationPart(value.toolCallId, invocation);
|
911
|
+
});
|
916
912
|
execUpdate();
|
917
913
|
if (onToolCall) {
|
918
914
|
const result = await onToolCall({ toolCall: value });
|
919
915
|
if (result != null) {
|
920
|
-
|
916
|
+
updateToolInvocationPart(value.toolCallId, {
|
921
917
|
state: "result",
|
922
918
|
step,
|
923
919
|
...value,
|
924
920
|
result
|
925
|
-
};
|
926
|
-
message.toolInvocations[message.toolInvocations.length - 1] = invocation2;
|
927
|
-
updateToolInvocationPart(value.toolCallId, invocation2);
|
921
|
+
});
|
928
922
|
execUpdate();
|
929
923
|
}
|
930
924
|
}
|
931
925
|
},
|
932
926
|
onToolResultPart(value) {
|
933
|
-
const toolInvocations = message
|
927
|
+
const toolInvocations = getToolInvocations(message);
|
934
928
|
if (toolInvocations == null) {
|
935
929
|
throw new Error("tool_result must be preceded by a tool_call");
|
936
930
|
}
|
937
931
|
const toolInvocationIndex = toolInvocations.findIndex(
|
938
|
-
(
|
932
|
+
(invocation) => invocation.toolCallId === value.toolCallId
|
939
933
|
);
|
940
934
|
if (toolInvocationIndex === -1) {
|
941
935
|
throw new Error(
|
942
936
|
"tool_result must be preceded by a tool_call with the same toolCallId"
|
943
937
|
);
|
944
938
|
}
|
945
|
-
|
939
|
+
updateToolInvocationPart(value.toolCallId, {
|
946
940
|
...toolInvocations[toolInvocationIndex],
|
947
941
|
state: "result",
|
948
942
|
...value
|
949
|
-
};
|
950
|
-
toolInvocations[toolInvocationIndex] = invocation;
|
951
|
-
updateToolInvocationPart(value.toolCallId, invocation);
|
943
|
+
});
|
952
944
|
execUpdate();
|
953
945
|
},
|
954
946
|
onDataPart(value) {
|
@@ -1244,34 +1236,6 @@ function getTextFromDataUrl(dataUrl) {
|
|
1244
1236
|
}
|
1245
1237
|
}
|
1246
1238
|
|
1247
|
-
// core/util/extract-max-tool-invocation-step.ts
|
1248
|
-
function extractMaxToolInvocationStep(toolInvocations) {
|
1249
|
-
return toolInvocations == null ? void 0 : toolInvocations.reduce((max, toolInvocation) => {
|
1250
|
-
var _a17;
|
1251
|
-
return Math.max(max, (_a17 = toolInvocation.step) != null ? _a17 : 0);
|
1252
|
-
}, 0);
|
1253
|
-
}
|
1254
|
-
|
1255
|
-
// core/util/get-message-parts.ts
|
1256
|
-
function getMessageParts(message) {
|
1257
|
-
var _a17;
|
1258
|
-
return (_a17 = message.parts) != null ? _a17 : [
|
1259
|
-
...message.toolInvocations ? message.toolInvocations.map((toolInvocation) => ({
|
1260
|
-
type: "tool-invocation",
|
1261
|
-
toolInvocation
|
1262
|
-
})) : [],
|
1263
|
-
...message.content ? [{ type: "text", text: message.content }] : []
|
1264
|
-
];
|
1265
|
-
}
|
1266
|
-
|
1267
|
-
// core/util/fill-message-parts.ts
|
1268
|
-
function fillMessageParts(messages) {
|
1269
|
-
return messages.map((message) => ({
|
1270
|
-
...message,
|
1271
|
-
parts: getMessageParts(message)
|
1272
|
-
}));
|
1273
|
-
}
|
1274
|
-
|
1275
1239
|
// core/util/is-deep-equal-data.ts
|
1276
1240
|
function isDeepEqualData(obj1, obj2) {
|
1277
1241
|
if (obj1 === obj2)
|
@@ -1312,7 +1276,7 @@ async function prepareAttachmentsForRequest(attachmentsFromOptions) {
|
|
1312
1276
|
if (!attachmentsFromOptions) {
|
1313
1277
|
return [];
|
1314
1278
|
}
|
1315
|
-
if (attachmentsFromOptions instanceof FileList) {
|
1279
|
+
if (globalThis.FileList && attachmentsFromOptions instanceof globalThis.FileList) {
|
1316
1280
|
return Promise.all(
|
1317
1281
|
Array.from(attachmentsFromOptions).map(async (attachment) => {
|
1318
1282
|
const { name: name17, type } = attachment;
|
@@ -1345,7 +1309,6 @@ function updateToolCallResult({
|
|
1345
1309
|
toolCallId,
|
1346
1310
|
toolResult: result
|
1347
1311
|
}) {
|
1348
|
-
var _a17;
|
1349
1312
|
const lastMessage = messages[messages.length - 1];
|
1350
1313
|
const invocationPart = lastMessage.parts.find(
|
1351
1314
|
(part) => part.type === "tool-invocation" && part.toolInvocation.toolCallId === toolCallId
|
@@ -1353,15 +1316,11 @@ function updateToolCallResult({
|
|
1353
1316
|
if (invocationPart == null) {
|
1354
1317
|
return;
|
1355
1318
|
}
|
1356
|
-
|
1319
|
+
invocationPart.toolInvocation = {
|
1357
1320
|
...invocationPart.toolInvocation,
|
1358
1321
|
state: "result",
|
1359
1322
|
result
|
1360
1323
|
};
|
1361
|
-
invocationPart.toolInvocation = toolResult;
|
1362
|
-
lastMessage.toolInvocations = (_a17 = lastMessage.toolInvocations) == null ? void 0 : _a17.map(
|
1363
|
-
(toolInvocation) => toolInvocation.toolCallId === toolCallId ? toolResult : toolInvocation
|
1364
|
-
);
|
1365
1324
|
}
|
1366
1325
|
|
1367
1326
|
// core/util/should-resubmit-messages.ts
|
@@ -1377,9 +1336,9 @@ function shouldResubmitMessages({
|
|
1377
1336
|
// check if the feature is enabled:
|
1378
1337
|
maxSteps > 1 && // ensure there is a last message:
|
1379
1338
|
lastMessage != null && // ensure we actually have new steps (to prevent infinite loops in case of errors):
|
1380
|
-
(messages.length > originalMessageCount || extractMaxToolInvocationStep(lastMessage
|
1339
|
+
(messages.length > originalMessageCount || extractMaxToolInvocationStep(getToolInvocations(lastMessage)) !== originalMaxToolInvocationStep) && // check that next step is possible:
|
1381
1340
|
isAssistantMessageWithCompletedToolCalls(lastMessage) && // limit the number of automatic steps:
|
1382
|
-
((_a17 = extractMaxToolInvocationStep(lastMessage
|
1341
|
+
((_a17 = extractMaxToolInvocationStep(getToolInvocations(lastMessage))) != null ? _a17 : 0) < maxSteps
|
1383
1342
|
);
|
1384
1343
|
}
|
1385
1344
|
function isAssistantMessageWithCompletedToolCalls(message) {
|
@@ -3190,7 +3149,7 @@ function convertToCoreMessages(messages, options) {
|
|
3190
3149
|
case "reasoning": {
|
3191
3150
|
content2.push({
|
3192
3151
|
type: "reasoning",
|
3193
|
-
text: part.
|
3152
|
+
text: part.text,
|
3194
3153
|
providerOptions: part.providerMetadata
|
3195
3154
|
});
|
3196
3155
|
break;
|
@@ -3280,73 +3239,11 @@ function convertToCoreMessages(messages, options) {
|
|
3280
3239
|
processBlock2();
|
3281
3240
|
break;
|
3282
3241
|
}
|
3283
|
-
const toolInvocations = message.toolInvocations;
|
3284
|
-
if (toolInvocations == null || toolInvocations.length === 0) {
|
3285
|
-
coreMessages.push({ role: "assistant", content });
|
3286
|
-
break;
|
3287
|
-
}
|
3288
|
-
const maxStep = toolInvocations.reduce((max, toolInvocation) => {
|
3289
|
-
var _a18;
|
3290
|
-
return Math.max(max, (_a18 = toolInvocation.step) != null ? _a18 : 0);
|
3291
|
-
}, 0);
|
3292
|
-
for (let i2 = 0; i2 <= maxStep; i2++) {
|
3293
|
-
const stepInvocations = toolInvocations.filter(
|
3294
|
-
(toolInvocation) => {
|
3295
|
-
var _a18;
|
3296
|
-
return ((_a18 = toolInvocation.step) != null ? _a18 : 0) === i2;
|
3297
|
-
}
|
3298
|
-
);
|
3299
|
-
if (stepInvocations.length === 0) {
|
3300
|
-
continue;
|
3301
|
-
}
|
3302
|
-
coreMessages.push({
|
3303
|
-
role: "assistant",
|
3304
|
-
content: [
|
3305
|
-
...isLastMessage && content && i2 === 0 ? [{ type: "text", text: content }] : [],
|
3306
|
-
...stepInvocations.map(
|
3307
|
-
({ toolCallId, toolName, args }) => ({
|
3308
|
-
type: "tool-call",
|
3309
|
-
toolCallId,
|
3310
|
-
toolName,
|
3311
|
-
args
|
3312
|
-
})
|
3313
|
-
)
|
3314
|
-
]
|
3315
|
-
});
|
3316
|
-
coreMessages.push({
|
3317
|
-
role: "tool",
|
3318
|
-
content: stepInvocations.map((toolInvocation) => {
|
3319
|
-
if (!("result" in toolInvocation)) {
|
3320
|
-
throw new MessageConversionError({
|
3321
|
-
originalMessage: message,
|
3322
|
-
message: "ToolInvocation must have a result: " + JSON.stringify(toolInvocation)
|
3323
|
-
});
|
3324
|
-
}
|
3325
|
-
const { toolCallId, toolName, result } = toolInvocation;
|
3326
|
-
const tool2 = tools[toolName];
|
3327
|
-
return (tool2 == null ? void 0 : tool2.experimental_toToolResultContent) != null ? {
|
3328
|
-
type: "tool-result",
|
3329
|
-
toolCallId,
|
3330
|
-
toolName,
|
3331
|
-
result: tool2.experimental_toToolResultContent(result),
|
3332
|
-
experimental_content: tool2.experimental_toToolResultContent(result)
|
3333
|
-
} : {
|
3334
|
-
type: "tool-result",
|
3335
|
-
toolCallId,
|
3336
|
-
toolName,
|
3337
|
-
result
|
3338
|
-
};
|
3339
|
-
})
|
3340
|
-
});
|
3341
|
-
}
|
3342
3242
|
if (content && !isLastMessage) {
|
3343
3243
|
coreMessages.push({ role: "assistant", content });
|
3344
3244
|
}
|
3345
3245
|
break;
|
3346
3246
|
}
|
3347
|
-
case "data": {
|
3348
|
-
break;
|
3349
|
-
}
|
3350
3247
|
default: {
|
3351
3248
|
const _exhaustiveCheck = role;
|
3352
3249
|
throw new MessageConversionError({
|
@@ -3836,10 +3733,36 @@ var enumOutputStrategy = (enumValues) => {
|
|
3836
3733
|
})
|
3837
3734
|
};
|
3838
3735
|
},
|
3839
|
-
validatePartialResult() {
|
3840
|
-
|
3841
|
-
|
3842
|
-
|
3736
|
+
async validatePartialResult({ value, textDelta }) {
|
3737
|
+
if (!isJSONObject(value) || typeof value.result !== "string") {
|
3738
|
+
return {
|
3739
|
+
success: false,
|
3740
|
+
error: new TypeValidationError({
|
3741
|
+
value,
|
3742
|
+
cause: 'value must be an object that contains a string in the "result" property.'
|
3743
|
+
})
|
3744
|
+
};
|
3745
|
+
}
|
3746
|
+
const result = value.result;
|
3747
|
+
const possibleEnumValues = enumValues.filter(
|
3748
|
+
(enumValue) => enumValue.startsWith(result)
|
3749
|
+
);
|
3750
|
+
if (value.result.length === 0 || possibleEnumValues.length === 0) {
|
3751
|
+
return {
|
3752
|
+
success: false,
|
3753
|
+
error: new TypeValidationError({
|
3754
|
+
value,
|
3755
|
+
cause: "value must be a string in the enum"
|
3756
|
+
})
|
3757
|
+
};
|
3758
|
+
}
|
3759
|
+
return {
|
3760
|
+
success: true,
|
3761
|
+
value: {
|
3762
|
+
partial: possibleEnumValues.length > 1 ? result : possibleEnumValues[0],
|
3763
|
+
textDelta
|
3764
|
+
}
|
3765
|
+
};
|
3843
3766
|
},
|
3844
3767
|
createElementStream() {
|
3845
3768
|
throw new UnsupportedFunctionalityError({
|
@@ -4425,6 +4348,7 @@ function streamObject(options) {
|
|
4425
4348
|
} = {},
|
4426
4349
|
...settings
|
4427
4350
|
} = options;
|
4351
|
+
const enumValues = "enum" in options && options.enum ? options.enum : void 0;
|
4428
4352
|
const {
|
4429
4353
|
schema: inputSchema,
|
4430
4354
|
schemaDescription,
|
@@ -4434,9 +4358,14 @@ function streamObject(options) {
|
|
4434
4358
|
output,
|
4435
4359
|
schema: inputSchema,
|
4436
4360
|
schemaName,
|
4437
|
-
schemaDescription
|
4361
|
+
schemaDescription,
|
4362
|
+
enumValues
|
4363
|
+
});
|
4364
|
+
const outputStrategy = getOutputStrategy({
|
4365
|
+
output,
|
4366
|
+
schema: inputSchema,
|
4367
|
+
enumValues
|
4438
4368
|
});
|
4439
|
-
const outputStrategy = getOutputStrategy({ output, schema: inputSchema });
|
4440
4369
|
return new DefaultStreamObjectResult({
|
4441
4370
|
model,
|
4442
4371
|
telemetry,
|
@@ -7864,7 +7793,7 @@ function appendResponseMessages({
|
|
7864
7793
|
responseMessages,
|
7865
7794
|
_internal: { currentDate = () => /* @__PURE__ */ new Date() } = {}
|
7866
7795
|
}) {
|
7867
|
-
var _a17, _b, _c
|
7796
|
+
var _a17, _b, _c;
|
7868
7797
|
const clonedMessages = structuredClone(messages);
|
7869
7798
|
for (const message of responseMessages) {
|
7870
7799
|
const role = message.role;
|
@@ -7872,7 +7801,7 @@ function appendResponseMessages({
|
|
7872
7801
|
const isLastMessageAssistant = lastMessage.role === "assistant";
|
7873
7802
|
switch (role) {
|
7874
7803
|
case "assistant": {
|
7875
|
-
let
|
7804
|
+
let getToolInvocationsForStep2 = function(step) {
|
7876
7805
|
return (typeof message.content === "string" ? [] : message.content.filter((part) => part.type === "tool-call")).map((call) => ({
|
7877
7806
|
state: "call",
|
7878
7807
|
step,
|
@@ -7881,7 +7810,7 @@ function appendResponseMessages({
|
|
7881
7810
|
toolName: call.toolName
|
7882
7811
|
}));
|
7883
7812
|
};
|
7884
|
-
var
|
7813
|
+
var getToolInvocationsForStep = getToolInvocationsForStep2;
|
7885
7814
|
const parts = [{ type: "step-start" }];
|
7886
7815
|
let textContent = "";
|
7887
7816
|
let reasoningTextContent = void 0;
|
@@ -7908,12 +7837,12 @@ function appendResponseMessages({
|
|
7908
7837
|
if (reasoningPart == null) {
|
7909
7838
|
reasoningPart = {
|
7910
7839
|
type: "reasoning",
|
7911
|
-
|
7840
|
+
text: ""
|
7912
7841
|
};
|
7913
7842
|
parts.push(reasoningPart);
|
7914
7843
|
}
|
7915
7844
|
reasoningTextContent = (reasoningTextContent != null ? reasoningTextContent : "") + part.text;
|
7916
|
-
reasoningPart.
|
7845
|
+
reasoningPart.text += part.text;
|
7917
7846
|
reasoningPart.providerMetadata = part.providerOptions;
|
7918
7847
|
break;
|
7919
7848
|
}
|
@@ -7937,16 +7866,13 @@ function appendResponseMessages({
|
|
7937
7866
|
}
|
7938
7867
|
if (isLastMessageAssistant) {
|
7939
7868
|
const maxStep = extractMaxToolInvocationStep(
|
7940
|
-
lastMessage
|
7869
|
+
getToolInvocations(lastMessage)
|
7870
|
+
// TODO remove once Message is removed
|
7941
7871
|
);
|
7942
7872
|
(_b = lastMessage.parts) != null ? _b : lastMessage.parts = [];
|
7943
7873
|
lastMessage.content = textContent;
|
7944
7874
|
lastMessage.parts.push(...parts);
|
7945
|
-
|
7946
|
-
...(_c = lastMessage.toolInvocations) != null ? _c : [],
|
7947
|
-
...getToolInvocations2(maxStep === void 0 ? 0 : maxStep + 1)
|
7948
|
-
];
|
7949
|
-
getToolInvocations2(maxStep === void 0 ? 0 : maxStep + 1).map((call) => ({
|
7875
|
+
getToolInvocationsForStep2(maxStep === void 0 ? 0 : maxStep + 1).map((call) => ({
|
7950
7876
|
type: "tool-invocation",
|
7951
7877
|
toolInvocation: call
|
7952
7878
|
})).forEach((part) => {
|
@@ -7959,10 +7885,9 @@ function appendResponseMessages({
|
|
7959
7885
|
createdAt: currentDate(),
|
7960
7886
|
// generate a createdAt date for the message, will be overridden by the client
|
7961
7887
|
content: textContent,
|
7962
|
-
toolInvocations: getToolInvocations2(0),
|
7963
7888
|
parts: [
|
7964
7889
|
...parts,
|
7965
|
-
...
|
7890
|
+
...getToolInvocationsForStep2(0).map((call) => ({
|
7966
7891
|
type: "tool-invocation",
|
7967
7892
|
toolInvocation: call
|
7968
7893
|
}))
|
@@ -7972,17 +7897,17 @@ function appendResponseMessages({
|
|
7972
7897
|
break;
|
7973
7898
|
}
|
7974
7899
|
case "tool": {
|
7975
|
-
(_d = lastMessage.toolInvocations) != null ? _d : lastMessage.toolInvocations = [];
|
7976
7900
|
if (lastMessage.role !== "assistant") {
|
7977
7901
|
throw new Error(
|
7978
7902
|
`Tool result must follow an assistant message: ${lastMessage.role}`
|
7979
7903
|
);
|
7980
7904
|
}
|
7981
|
-
(
|
7905
|
+
(_c = lastMessage.parts) != null ? _c : lastMessage.parts = [];
|
7982
7906
|
for (const contentPart of message.content) {
|
7983
|
-
const toolCall =
|
7984
|
-
|
7985
|
-
|
7907
|
+
const toolCall = getToolInvocations(
|
7908
|
+
lastMessage
|
7909
|
+
// TODO remove once Message is removed
|
7910
|
+
).find((call) => call.toolCallId === contentPart.toolCallId);
|
7986
7911
|
const toolCallPart = lastMessage.parts.find(
|
7987
7912
|
(part) => part.type === "tool-invocation" && part.toolInvocation.toolCallId === contentPart.toolCallId
|
7988
7913
|
);
|
@@ -8535,6 +8460,24 @@ var MCPClient = class {
|
|
8535
8460
|
await ((_a17 = this.transport) == null ? void 0 : _a17.close());
|
8536
8461
|
this.onClose();
|
8537
8462
|
}
|
8463
|
+
assertCapability(method) {
|
8464
|
+
switch (method) {
|
8465
|
+
case "initialize":
|
8466
|
+
break;
|
8467
|
+
case "tools/list":
|
8468
|
+
case "tools/call":
|
8469
|
+
if (!this.serverCapabilities.tools) {
|
8470
|
+
throw new MCPClientError({
|
8471
|
+
message: `Server does not support tools`
|
8472
|
+
});
|
8473
|
+
}
|
8474
|
+
break;
|
8475
|
+
default:
|
8476
|
+
throw new MCPClientError({
|
8477
|
+
message: `Unsupported method: ${method}`
|
8478
|
+
});
|
8479
|
+
}
|
8480
|
+
}
|
8538
8481
|
async request({
|
8539
8482
|
request,
|
8540
8483
|
resultSchema,
|
@@ -8548,6 +8491,7 @@ var MCPClient = class {
|
|
8548
8491
|
})
|
8549
8492
|
);
|
8550
8493
|
}
|
8494
|
+
this.assertCapability(request.method);
|
8551
8495
|
const signal = options == null ? void 0 : options.signal;
|
8552
8496
|
signal == null ? void 0 : signal.throwIfAborted();
|
8553
8497
|
const messageId = this.requestMessageId++;
|
@@ -8576,7 +8520,7 @@ var MCPClient = class {
|
|
8576
8520
|
resolve(result);
|
8577
8521
|
} catch (error) {
|
8578
8522
|
const parseError = new MCPClientError({
|
8579
|
-
message: "Failed to parse server
|
8523
|
+
message: "Failed to parse server response",
|
8580
8524
|
cause: error
|
8581
8525
|
});
|
8582
8526
|
reject(parseError);
|
@@ -8592,11 +8536,6 @@ var MCPClient = class {
|
|
8592
8536
|
params,
|
8593
8537
|
options
|
8594
8538
|
} = {}) {
|
8595
|
-
if (!this.serverCapabilities.tools) {
|
8596
|
-
throw new MCPClientError({
|
8597
|
-
message: `Server does not support tools`
|
8598
|
-
});
|
8599
|
-
}
|
8600
8539
|
try {
|
8601
8540
|
return this.request({
|
8602
8541
|
request: { method: "tools/list", params },
|
@@ -8612,11 +8551,6 @@ var MCPClient = class {
|
|
8612
8551
|
args,
|
8613
8552
|
options
|
8614
8553
|
}) {
|
8615
|
-
if (!this.serverCapabilities.tools) {
|
8616
|
-
throw new MCPClientError({
|
8617
|
-
message: `Server does not support tools`
|
8618
|
-
});
|
8619
|
-
}
|
8620
8554
|
try {
|
8621
8555
|
return this.request({
|
8622
8556
|
request: { method: "tools/call", params: { name: name17, arguments: args } },
|
@@ -8886,13 +8820,12 @@ export {
|
|
8886
8820
|
transcribe as experimental_transcribe,
|
8887
8821
|
extractMaxToolInvocationStep,
|
8888
8822
|
extractReasoningMiddleware,
|
8889
|
-
fillMessageParts,
|
8890
8823
|
formatDataStreamPart,
|
8891
8824
|
generateId2 as generateId,
|
8892
8825
|
generateObject,
|
8893
8826
|
generateText,
|
8894
|
-
getMessageParts,
|
8895
8827
|
getTextFromDataUrl,
|
8828
|
+
getToolInvocations,
|
8896
8829
|
isAssistantMessageWithCompletedToolCalls,
|
8897
8830
|
isDeepEqualData,
|
8898
8831
|
jsonSchema,
|