@anuma/sdk 6.27.8 → 6.28.0
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/dist/expo/index.cjs +92 -26
- package/dist/expo/index.d.mts +2 -2
- package/dist/expo/index.d.ts +2 -2
- package/dist/expo/index.mjs +92 -26
- package/dist/index.cjs +17 -0
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.mjs +17 -0
- package/dist/react/index.cjs +117 -23
- package/dist/react/index.d.mts +36 -3
- package/dist/react/index.d.ts +36 -3
- package/dist/react/index.mjs +116 -23
- package/dist/server/index.cjs +76 -18
- package/dist/server/index.d.mts +17 -3
- package/dist/server/index.d.ts +17 -3
- package/dist/server/index.mjs +76 -18
- package/dist/telemetry/index.d.mts +1 -1
- package/dist/telemetry/index.d.ts +1 -1
- package/dist/tools/index.cjs +5 -1
- package/dist/tools/index.d.mts +4 -2
- package/dist/tools/index.d.ts +4 -2
- package/dist/tools/index.mjs +5 -1
- package/dist/tools/selection/index.cjs +44 -6
- package/dist/tools/selection/index.d.mts +35 -2
- package/dist/tools/selection/index.d.ts +35 -2
- package/dist/tools/selection/index.mjs +42 -5
- package/package.json +1 -1
package/dist/react/index.mjs
CHANGED
|
@@ -4480,6 +4480,12 @@ var ToolTimeoutError = class extends Error {
|
|
|
4480
4480
|
this.name = "ToolTimeoutError";
|
|
4481
4481
|
}
|
|
4482
4482
|
};
|
|
4483
|
+
var ToolCancelledError = class extends Error {
|
|
4484
|
+
constructor() {
|
|
4485
|
+
super("Tool execution cancelled");
|
|
4486
|
+
this.name = "ToolCancelledError";
|
|
4487
|
+
}
|
|
4488
|
+
};
|
|
4483
4489
|
function safeJsonStringify(value) {
|
|
4484
4490
|
try {
|
|
4485
4491
|
return JSON.stringify(value) ?? "null";
|
|
@@ -4487,7 +4493,7 @@ function safeJsonStringify(value) {
|
|
|
4487
4493
|
return String(value);
|
|
4488
4494
|
}
|
|
4489
4495
|
}
|
|
4490
|
-
async function executeToolCall(toolCall, executor, timeoutMs = TOOL_EXECUTOR_TIMEOUT_MS) {
|
|
4496
|
+
async function executeToolCall(toolCall, executor, timeoutMs = TOOL_EXECUTOR_TIMEOUT_MS, signal) {
|
|
4491
4497
|
let args = {};
|
|
4492
4498
|
if (toolCall.arguments) {
|
|
4493
4499
|
const parsed = parseToolArguments(toolCall.arguments);
|
|
@@ -4496,28 +4502,42 @@ async function executeToolCall(toolCall, executor, timeoutMs = TOOL_EXECUTOR_TIM
|
|
|
4496
4502
|
}
|
|
4497
4503
|
args = parsed.args;
|
|
4498
4504
|
}
|
|
4505
|
+
if (signal?.aborted) {
|
|
4506
|
+
return { error: "Tool execution cancelled", errorType: "cancelled" };
|
|
4507
|
+
}
|
|
4508
|
+
let timer;
|
|
4509
|
+
let onAbort;
|
|
4499
4510
|
try {
|
|
4500
|
-
|
|
4501
|
-
|
|
4511
|
+
const racers = [];
|
|
4512
|
+
if (signal) {
|
|
4513
|
+
racers.push(
|
|
4514
|
+
new Promise((_, reject) => {
|
|
4515
|
+
onAbort = () => reject(new ToolCancelledError());
|
|
4516
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
4517
|
+
})
|
|
4518
|
+
);
|
|
4502
4519
|
}
|
|
4503
|
-
|
|
4504
|
-
|
|
4505
|
-
|
|
4506
|
-
executor(args),
|
|
4520
|
+
racers.push(Promise.resolve(signal ? executor(args, signal) : executor(args)));
|
|
4521
|
+
if (isFinite(timeoutMs)) {
|
|
4522
|
+
racers.push(
|
|
4507
4523
|
new Promise((_, reject) => {
|
|
4508
4524
|
timer = setTimeout(() => reject(new ToolTimeoutError()), timeoutMs);
|
|
4509
4525
|
})
|
|
4510
|
-
|
|
4511
|
-
return { result };
|
|
4512
|
-
} finally {
|
|
4513
|
-
clearTimeout(timer);
|
|
4526
|
+
);
|
|
4514
4527
|
}
|
|
4528
|
+
return { result: await Promise.race(racers) };
|
|
4515
4529
|
} catch (e) {
|
|
4530
|
+
if (e instanceof ToolCancelledError) {
|
|
4531
|
+
return { error: "Tool execution cancelled", errorType: "cancelled" };
|
|
4532
|
+
}
|
|
4516
4533
|
const message = e instanceof Error ? e.message : String(e);
|
|
4517
4534
|
return {
|
|
4518
4535
|
error: `Tool execution failed: ${message}`,
|
|
4519
4536
|
errorType: e instanceof ToolTimeoutError ? "timeout" : "execution"
|
|
4520
4537
|
};
|
|
4538
|
+
} finally {
|
|
4539
|
+
clearTimeout(timer);
|
|
4540
|
+
if (onAbort) signal?.removeEventListener("abort", onAbort);
|
|
4521
4541
|
}
|
|
4522
4542
|
}
|
|
4523
4543
|
function toolsToApiFormat(tools, apiType) {
|
|
@@ -6873,11 +6893,12 @@ Executing tool: ${toolInfo}
|
|
|
6873
6893
|
const blockedByFailure = failedDeps.some((d) => failedNames.has(d));
|
|
6874
6894
|
const reason = blockedByFailure ? `failed dependencies: ${failedDeps.join(", ")}` : "a dependency cycle";
|
|
6875
6895
|
const errorMsg = `Tool "${tc.name}" was not executed due to ${reason}`;
|
|
6896
|
+
const skipErrorType = combinedSignal?.aborted ? "cancelled" : "execution";
|
|
6876
6897
|
executionResults.push({
|
|
6877
6898
|
id: tc.id,
|
|
6878
6899
|
name: tc.name,
|
|
6879
6900
|
error: errorMsg,
|
|
6880
|
-
errorType:
|
|
6901
|
+
errorType: skipErrorType
|
|
6881
6902
|
});
|
|
6882
6903
|
await safeAwait(
|
|
6883
6904
|
() => hooks?.afterToolUse?.({
|
|
@@ -6886,7 +6907,7 @@ Executing tool: ${toolInfo}
|
|
|
6886
6907
|
toolCallId: tc.id,
|
|
6887
6908
|
name: tc.name,
|
|
6888
6909
|
error: errorMsg,
|
|
6889
|
-
errorType:
|
|
6910
|
+
errorType: skipErrorType
|
|
6890
6911
|
})
|
|
6891
6912
|
);
|
|
6892
6913
|
}
|
|
@@ -6906,7 +6927,8 @@ Executing tool: ${toolInfo}
|
|
|
6906
6927
|
const { result, error, errorType } = await executeToolCall(
|
|
6907
6928
|
toolCallForExec,
|
|
6908
6929
|
executorConfig.executor,
|
|
6909
|
-
executorConfig.executorTimeout
|
|
6930
|
+
executorConfig.executorTimeout,
|
|
6931
|
+
combinedSignal
|
|
6910
6932
|
);
|
|
6911
6933
|
await safeAwait(
|
|
6912
6934
|
() => hooks?.afterToolUse?.({
|
|
@@ -21389,6 +21411,23 @@ var BUILT_IN_TOOL_SETS = [
|
|
|
21389
21411
|
members: ["dropbox_list_folders", "dropbox_get_file_content", "dropbox_search"],
|
|
21390
21412
|
anchors: ["dropbox_list_folders", "dropbox_search"],
|
|
21391
21413
|
anchorMinSimilarity: 0.53
|
|
21414
|
+
},
|
|
21415
|
+
{
|
|
21416
|
+
// Server tools, so this set does its work through
|
|
21417
|
+
// withActiveToolSetServerTools: once a restaurant tool has run, terse
|
|
21418
|
+
// follow-ups ("okay", "same as before") keep the booking chain. Each tool
|
|
21419
|
+
// still reaches a fresh booking request on its own description.
|
|
21420
|
+
// Anchors are deliberately empty (like the client's Nearby set): the set
|
|
21421
|
+
// is only for stickiness, not a new way to activate on a prompt.
|
|
21422
|
+
// prompt_user_confirm is left out of members: autoFilterClientTools always
|
|
21423
|
+
// sends it, and as a member any unrelated confirmation would pin this set.
|
|
21424
|
+
name: "restaurant-booking",
|
|
21425
|
+
members: [
|
|
21426
|
+
"AnumaPaymentsMCP-anuma_find_restaurant",
|
|
21427
|
+
"AnumaPaymentsMCP-anuma_check_restaurant_availability",
|
|
21428
|
+
"AnumaPaymentsMCP-anuma_book_restaurant"
|
|
21429
|
+
],
|
|
21430
|
+
anchors: []
|
|
21392
21431
|
}
|
|
21393
21432
|
];
|
|
21394
21433
|
function expandToolSetsAdditive(matchedNames, availableNames, scores, toolSets, activeSetNames) {
|
|
@@ -21422,6 +21461,16 @@ function activatedToolSetNames(scores, toolSets = BUILT_IN_TOOL_SETS, activeSetN
|
|
|
21422
21461
|
}
|
|
21423
21462
|
return activated;
|
|
21424
21463
|
}
|
|
21464
|
+
function withActiveToolSetServerTools(selected, allServerTools, serverToolsFilter, activeToolSets = [], extraToolSets = []) {
|
|
21465
|
+
if (activeToolSets.length === 0) return selected;
|
|
21466
|
+
const sticky = new Set(
|
|
21467
|
+
[...BUILT_IN_TOOL_SETS, ...extraToolSets].filter((ts) => activeToolSets.includes(ts.name)).flatMap((ts) => ts.members)
|
|
21468
|
+
);
|
|
21469
|
+
for (const name of serverToolsFilter.excludeTools ?? []) sticky.delete(name);
|
|
21470
|
+
for (const tool of selected) sticky.delete(tool.name);
|
|
21471
|
+
const added = allServerTools.filter((tool) => sticky.has(tool.name));
|
|
21472
|
+
return added.length > 0 ? [...selected, ...added] : selected;
|
|
21473
|
+
}
|
|
21425
21474
|
function toolSetSystemPrompts(selectedToolNames, toolSets = BUILT_IN_TOOL_SETS, activatedSetNames) {
|
|
21426
21475
|
const selected = selectedToolNames instanceof Set ? selectedToolNames : new Set(selectedToolNames);
|
|
21427
21476
|
const prompts = [];
|
|
@@ -21535,7 +21584,9 @@ async function selectServerToolsForPrompt(options) {
|
|
|
21535
21584
|
embeddingModel,
|
|
21536
21585
|
cacheExpirationMs,
|
|
21537
21586
|
cache,
|
|
21538
|
-
deferLoading
|
|
21587
|
+
deferLoading,
|
|
21588
|
+
activeToolSets,
|
|
21589
|
+
extraToolSets
|
|
21539
21590
|
} = options;
|
|
21540
21591
|
if (serverToolsFilter === void 0) return [];
|
|
21541
21592
|
if (Array.isArray(serverToolsFilter) && serverToolsFilter.length === 0) return [];
|
|
@@ -21549,7 +21600,14 @@ async function selectServerToolsForPrompt(options) {
|
|
|
21549
21600
|
if (deferLoading?.enabled)
|
|
21550
21601
|
return resolveDeferredServerTools(allServerTools, serverToolsFilter, deferLoading);
|
|
21551
21602
|
if (typeof serverToolsFilter === "function") {
|
|
21552
|
-
|
|
21603
|
+
const withSticky = (selected) => withActiveToolSetServerTools(
|
|
21604
|
+
selected,
|
|
21605
|
+
allServerTools,
|
|
21606
|
+
serverToolsFilter,
|
|
21607
|
+
activeToolSets,
|
|
21608
|
+
extraToolSets
|
|
21609
|
+
);
|
|
21610
|
+
if (prompt.length < MIN_CONTENT_LENGTH_FOR_TOOLS) return withSticky([]);
|
|
21553
21611
|
let promptEmbedding;
|
|
21554
21612
|
try {
|
|
21555
21613
|
promptEmbedding = await generateEmbedding(prompt, {
|
|
@@ -21558,10 +21616,10 @@ async function selectServerToolsForPrompt(options) {
|
|
|
21558
21616
|
model: embeddingModel
|
|
21559
21617
|
});
|
|
21560
21618
|
} catch {
|
|
21561
|
-
return [];
|
|
21619
|
+
return withSticky([]);
|
|
21562
21620
|
}
|
|
21563
21621
|
const names = serverToolsFilter(promptEmbedding, allServerTools);
|
|
21564
|
-
return filterServerTools(allServerTools, names);
|
|
21622
|
+
return withSticky(filterServerTools(allServerTools, names));
|
|
21565
21623
|
}
|
|
21566
21624
|
return filterServerTools(allServerTools, serverToolsFilter);
|
|
21567
21625
|
}
|
|
@@ -21964,7 +22022,8 @@ async function previewToolSelection(options) {
|
|
|
21964
22022
|
activeToolSets ?? []
|
|
21965
22023
|
);
|
|
21966
22024
|
let gatedServerNames = [];
|
|
21967
|
-
|
|
22025
|
+
const stickyOnly = typeof serverToolsFilter === "function" && !!activeToolSets?.length && !serverToolsConfig?.deferLoading?.enabled;
|
|
22026
|
+
if (Array.isArray(serverToolsFilter) && serverToolsFilter.length > 0 || stickyOnly) {
|
|
21968
22027
|
try {
|
|
21969
22028
|
const allServerTools = await getServerTools({
|
|
21970
22029
|
baseUrl,
|
|
@@ -21973,9 +22032,19 @@ async function previewToolSelection(options) {
|
|
|
21973
22032
|
apiKey,
|
|
21974
22033
|
cache: serverToolsConfig?.cache
|
|
21975
22034
|
});
|
|
21976
|
-
|
|
21977
|
-
|
|
21978
|
-
|
|
22035
|
+
if (typeof serverToolsFilter === "function") {
|
|
22036
|
+
gatedServerNames = withActiveToolSetServerTools(
|
|
22037
|
+
[],
|
|
22038
|
+
allServerTools,
|
|
22039
|
+
serverToolsFilter,
|
|
22040
|
+
activeToolSets,
|
|
22041
|
+
extraToolSets
|
|
22042
|
+
).map((t) => t.name);
|
|
22043
|
+
} else {
|
|
22044
|
+
const allow = new Set(serverToolsFilter);
|
|
22045
|
+
const gated = allServerTools.filter((t) => allow.has(t.name));
|
|
22046
|
+
gatedServerNames = (serverToolsConfig?.deferLoading?.enabled ? resolveDeferredServerTools(gated, serverToolsFilter, serverToolsConfig.deferLoading) : gated).map((t) => t.name);
|
|
22047
|
+
}
|
|
21979
22048
|
} catch {
|
|
21980
22049
|
}
|
|
21981
22050
|
}
|
|
@@ -22030,7 +22099,16 @@ async function previewToolSelection(options) {
|
|
|
22030
22099
|
serverToolsConfig.deferLoading
|
|
22031
22100
|
).map((t) => t.name);
|
|
22032
22101
|
} else if (typeof serverToolsFilter === "function") {
|
|
22033
|
-
|
|
22102
|
+
const sticky = withActiveToolSetServerTools(
|
|
22103
|
+
[],
|
|
22104
|
+
allServerTools,
|
|
22105
|
+
serverToolsFilter,
|
|
22106
|
+
activeToolSets,
|
|
22107
|
+
extraToolSets
|
|
22108
|
+
).map((t) => t.name);
|
|
22109
|
+
serverToolNames = [
|
|
22110
|
+
.../* @__PURE__ */ new Set([...serverToolsFilter(promptEmbedding, allServerTools), ...sticky])
|
|
22111
|
+
];
|
|
22034
22112
|
} else {
|
|
22035
22113
|
const allow = new Set(serverToolsFilter);
|
|
22036
22114
|
serverToolNames = allServerTools.filter((t) => allow.has(t.name)).map((t) => t.name);
|
|
@@ -23078,6 +23156,13 @@ function useChatStorage(options) {
|
|
|
23078
23156
|
const toolNames = serverToolsFilter(skipStorageEmbeddings, allServerTools);
|
|
23079
23157
|
filteredServerTools2 = filterServerTools(allServerTools, toolNames);
|
|
23080
23158
|
}
|
|
23159
|
+
filteredServerTools2 = withActiveToolSetServerTools(
|
|
23160
|
+
filteredServerTools2,
|
|
23161
|
+
allServerTools,
|
|
23162
|
+
serverToolsFilter,
|
|
23163
|
+
activeToolSetsRef.current,
|
|
23164
|
+
extraToolSets
|
|
23165
|
+
);
|
|
23081
23166
|
} else {
|
|
23082
23167
|
filteredServerTools2 = filterServerTools(allServerTools, serverToolsFilter);
|
|
23083
23168
|
}
|
|
@@ -23525,6 +23610,13 @@ function useChatStorage(options) {
|
|
|
23525
23610
|
const toolNames = serverToolsFilter(userMessageEmbeddings, allServerTools);
|
|
23526
23611
|
filteredServerTools = filterServerTools(allServerTools, toolNames);
|
|
23527
23612
|
}
|
|
23613
|
+
filteredServerTools = withActiveToolSetServerTools(
|
|
23614
|
+
filteredServerTools,
|
|
23615
|
+
allServerTools,
|
|
23616
|
+
serverToolsFilter,
|
|
23617
|
+
activeToolSetsRef.current,
|
|
23618
|
+
extraToolSets
|
|
23619
|
+
);
|
|
23528
23620
|
} else {
|
|
23529
23621
|
filteredServerTools = filterServerTools(allServerTools, serverToolsFilter);
|
|
23530
23622
|
}
|
|
@@ -35256,6 +35348,7 @@ export {
|
|
|
35256
35348
|
verifyMemoriesForPublish,
|
|
35257
35349
|
walk,
|
|
35258
35350
|
webPlatformStorage,
|
|
35351
|
+
withActiveToolSetServerTools,
|
|
35259
35352
|
withInternalFlowMarker,
|
|
35260
35353
|
writeEncryptedFile
|
|
35261
35354
|
};
|
package/dist/server/index.cjs
CHANGED
|
@@ -33283,6 +33283,23 @@ var BUILT_IN_TOOL_SETS = [
|
|
|
33283
33283
|
members: ["dropbox_list_folders", "dropbox_get_file_content", "dropbox_search"],
|
|
33284
33284
|
anchors: ["dropbox_list_folders", "dropbox_search"],
|
|
33285
33285
|
anchorMinSimilarity: 0.53
|
|
33286
|
+
},
|
|
33287
|
+
{
|
|
33288
|
+
// Server tools, so this set does its work through
|
|
33289
|
+
// withActiveToolSetServerTools: once a restaurant tool has run, terse
|
|
33290
|
+
// follow-ups ("okay", "same as before") keep the booking chain. Each tool
|
|
33291
|
+
// still reaches a fresh booking request on its own description.
|
|
33292
|
+
// Anchors are deliberately empty (like the client's Nearby set): the set
|
|
33293
|
+
// is only for stickiness, not a new way to activate on a prompt.
|
|
33294
|
+
// prompt_user_confirm is left out of members: autoFilterClientTools always
|
|
33295
|
+
// sends it, and as a member any unrelated confirmation would pin this set.
|
|
33296
|
+
name: "restaurant-booking",
|
|
33297
|
+
members: [
|
|
33298
|
+
"AnumaPaymentsMCP-anuma_find_restaurant",
|
|
33299
|
+
"AnumaPaymentsMCP-anuma_check_restaurant_availability",
|
|
33300
|
+
"AnumaPaymentsMCP-anuma_book_restaurant"
|
|
33301
|
+
],
|
|
33302
|
+
anchors: []
|
|
33286
33303
|
}
|
|
33287
33304
|
];
|
|
33288
33305
|
function expandToolSetsAdditive(matchedNames, availableNames, scores, toolSets, activeSetNames) {
|
|
@@ -33316,6 +33333,16 @@ function activatedToolSetNames(scores, toolSets = BUILT_IN_TOOL_SETS, activeSetN
|
|
|
33316
33333
|
}
|
|
33317
33334
|
return activated;
|
|
33318
33335
|
}
|
|
33336
|
+
function withActiveToolSetServerTools(selected, allServerTools, serverToolsFilter, activeToolSets = [], extraToolSets = []) {
|
|
33337
|
+
if (activeToolSets.length === 0) return selected;
|
|
33338
|
+
const sticky = new Set(
|
|
33339
|
+
[...BUILT_IN_TOOL_SETS, ...extraToolSets].filter((ts) => activeToolSets.includes(ts.name)).flatMap((ts) => ts.members)
|
|
33340
|
+
);
|
|
33341
|
+
for (const name of serverToolsFilter.excludeTools ?? []) sticky.delete(name);
|
|
33342
|
+
for (const tool of selected) sticky.delete(tool.name);
|
|
33343
|
+
const added = allServerTools.filter((tool) => sticky.has(tool.name));
|
|
33344
|
+
return added.length > 0 ? [...selected, ...added] : selected;
|
|
33345
|
+
}
|
|
33319
33346
|
function toolSetSystemPrompts(selectedToolNames, toolSets = BUILT_IN_TOOL_SETS, activatedSetNames) {
|
|
33320
33347
|
const selected = selectedToolNames instanceof Set ? selectedToolNames : new Set(selectedToolNames);
|
|
33321
33348
|
const prompts = [];
|
|
@@ -33429,7 +33456,9 @@ async function selectServerToolsForPrompt(options) {
|
|
|
33429
33456
|
embeddingModel,
|
|
33430
33457
|
cacheExpirationMs,
|
|
33431
33458
|
cache,
|
|
33432
|
-
deferLoading
|
|
33459
|
+
deferLoading,
|
|
33460
|
+
activeToolSets,
|
|
33461
|
+
extraToolSets
|
|
33433
33462
|
} = options;
|
|
33434
33463
|
if (serverToolsFilter === void 0) return [];
|
|
33435
33464
|
if (Array.isArray(serverToolsFilter) && serverToolsFilter.length === 0) return [];
|
|
@@ -33443,7 +33472,14 @@ async function selectServerToolsForPrompt(options) {
|
|
|
33443
33472
|
if (deferLoading?.enabled)
|
|
33444
33473
|
return resolveDeferredServerTools(allServerTools, serverToolsFilter, deferLoading);
|
|
33445
33474
|
if (typeof serverToolsFilter === "function") {
|
|
33446
|
-
|
|
33475
|
+
const withSticky = (selected) => withActiveToolSetServerTools(
|
|
33476
|
+
selected,
|
|
33477
|
+
allServerTools,
|
|
33478
|
+
serverToolsFilter,
|
|
33479
|
+
activeToolSets,
|
|
33480
|
+
extraToolSets
|
|
33481
|
+
);
|
|
33482
|
+
if (prompt.length < MIN_CONTENT_LENGTH_FOR_TOOLS) return withSticky([]);
|
|
33447
33483
|
let promptEmbedding;
|
|
33448
33484
|
try {
|
|
33449
33485
|
promptEmbedding = await generateEmbedding(prompt, {
|
|
@@ -33452,10 +33488,10 @@ async function selectServerToolsForPrompt(options) {
|
|
|
33452
33488
|
model: embeddingModel
|
|
33453
33489
|
});
|
|
33454
33490
|
} catch {
|
|
33455
|
-
return [];
|
|
33491
|
+
return withSticky([]);
|
|
33456
33492
|
}
|
|
33457
33493
|
const names = serverToolsFilter(promptEmbedding, allServerTools);
|
|
33458
|
-
return filterServerTools(allServerTools, names);
|
|
33494
|
+
return withSticky(filterServerTools(allServerTools, names));
|
|
33459
33495
|
}
|
|
33460
33496
|
return filterServerTools(allServerTools, serverToolsFilter);
|
|
33461
33497
|
}
|
|
@@ -35383,6 +35419,12 @@ var ToolTimeoutError = class extends Error {
|
|
|
35383
35419
|
this.name = "ToolTimeoutError";
|
|
35384
35420
|
}
|
|
35385
35421
|
};
|
|
35422
|
+
var ToolCancelledError = class extends Error {
|
|
35423
|
+
constructor() {
|
|
35424
|
+
super("Tool execution cancelled");
|
|
35425
|
+
this.name = "ToolCancelledError";
|
|
35426
|
+
}
|
|
35427
|
+
};
|
|
35386
35428
|
function safeJsonStringify(value) {
|
|
35387
35429
|
try {
|
|
35388
35430
|
return JSON.stringify(value) ?? "null";
|
|
@@ -35390,7 +35432,7 @@ function safeJsonStringify(value) {
|
|
|
35390
35432
|
return String(value);
|
|
35391
35433
|
}
|
|
35392
35434
|
}
|
|
35393
|
-
async function executeToolCall(toolCall, executor, timeoutMs = TOOL_EXECUTOR_TIMEOUT_MS) {
|
|
35435
|
+
async function executeToolCall(toolCall, executor, timeoutMs = TOOL_EXECUTOR_TIMEOUT_MS, signal) {
|
|
35394
35436
|
let args = {};
|
|
35395
35437
|
if (toolCall.arguments) {
|
|
35396
35438
|
const parsed = parseToolArguments(toolCall.arguments);
|
|
@@ -35399,28 +35441,42 @@ async function executeToolCall(toolCall, executor, timeoutMs = TOOL_EXECUTOR_TIM
|
|
|
35399
35441
|
}
|
|
35400
35442
|
args = parsed.args;
|
|
35401
35443
|
}
|
|
35444
|
+
if (signal?.aborted) {
|
|
35445
|
+
return { error: "Tool execution cancelled", errorType: "cancelled" };
|
|
35446
|
+
}
|
|
35447
|
+
let timer;
|
|
35448
|
+
let onAbort;
|
|
35402
35449
|
try {
|
|
35403
|
-
|
|
35404
|
-
|
|
35450
|
+
const racers = [];
|
|
35451
|
+
if (signal) {
|
|
35452
|
+
racers.push(
|
|
35453
|
+
new Promise((_, reject) => {
|
|
35454
|
+
onAbort = () => reject(new ToolCancelledError());
|
|
35455
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
35456
|
+
})
|
|
35457
|
+
);
|
|
35405
35458
|
}
|
|
35406
|
-
|
|
35407
|
-
|
|
35408
|
-
|
|
35409
|
-
executor(args),
|
|
35459
|
+
racers.push(Promise.resolve(signal ? executor(args, signal) : executor(args)));
|
|
35460
|
+
if (isFinite(timeoutMs)) {
|
|
35461
|
+
racers.push(
|
|
35410
35462
|
new Promise((_, reject) => {
|
|
35411
35463
|
timer = setTimeout(() => reject(new ToolTimeoutError()), timeoutMs);
|
|
35412
35464
|
})
|
|
35413
|
-
|
|
35414
|
-
return { result };
|
|
35415
|
-
} finally {
|
|
35416
|
-
clearTimeout(timer);
|
|
35465
|
+
);
|
|
35417
35466
|
}
|
|
35467
|
+
return { result: await Promise.race(racers) };
|
|
35418
35468
|
} catch (e) {
|
|
35469
|
+
if (e instanceof ToolCancelledError) {
|
|
35470
|
+
return { error: "Tool execution cancelled", errorType: "cancelled" };
|
|
35471
|
+
}
|
|
35419
35472
|
const message = e instanceof Error ? e.message : String(e);
|
|
35420
35473
|
return {
|
|
35421
35474
|
error: `Tool execution failed: ${message}`,
|
|
35422
35475
|
errorType: e instanceof ToolTimeoutError ? "timeout" : "execution"
|
|
35423
35476
|
};
|
|
35477
|
+
} finally {
|
|
35478
|
+
clearTimeout(timer);
|
|
35479
|
+
if (onAbort) signal?.removeEventListener("abort", onAbort);
|
|
35424
35480
|
}
|
|
35425
35481
|
}
|
|
35426
35482
|
function toolsToApiFormat(tools, apiType) {
|
|
@@ -37776,11 +37832,12 @@ Executing tool: ${toolInfo}
|
|
|
37776
37832
|
const blockedByFailure = failedDeps.some((d) => failedNames.has(d));
|
|
37777
37833
|
const reason = blockedByFailure ? `failed dependencies: ${failedDeps.join(", ")}` : "a dependency cycle";
|
|
37778
37834
|
const errorMsg = `Tool "${tc.name}" was not executed due to ${reason}`;
|
|
37835
|
+
const skipErrorType = combinedSignal?.aborted ? "cancelled" : "execution";
|
|
37779
37836
|
executionResults.push({
|
|
37780
37837
|
id: tc.id,
|
|
37781
37838
|
name: tc.name,
|
|
37782
37839
|
error: errorMsg,
|
|
37783
|
-
errorType:
|
|
37840
|
+
errorType: skipErrorType
|
|
37784
37841
|
});
|
|
37785
37842
|
await safeAwait(
|
|
37786
37843
|
() => hooks?.afterToolUse?.({
|
|
@@ -37789,7 +37846,7 @@ Executing tool: ${toolInfo}
|
|
|
37789
37846
|
toolCallId: tc.id,
|
|
37790
37847
|
name: tc.name,
|
|
37791
37848
|
error: errorMsg,
|
|
37792
|
-
errorType:
|
|
37849
|
+
errorType: skipErrorType
|
|
37793
37850
|
})
|
|
37794
37851
|
);
|
|
37795
37852
|
}
|
|
@@ -37809,7 +37866,8 @@ Executing tool: ${toolInfo}
|
|
|
37809
37866
|
const { result, error, errorType } = await executeToolCall(
|
|
37810
37867
|
toolCallForExec,
|
|
37811
37868
|
executorConfig.executor,
|
|
37812
|
-
executorConfig.executorTimeout
|
|
37869
|
+
executorConfig.executorTimeout,
|
|
37870
|
+
combinedSignal
|
|
37813
37871
|
);
|
|
37814
37872
|
await safeAwait(
|
|
37815
37873
|
() => hooks?.afterToolUse?.({
|
package/dist/server/index.d.mts
CHANGED
|
@@ -2093,7 +2093,7 @@ type ToolUseEndEvent = {
|
|
|
2093
2093
|
name: string;
|
|
2094
2094
|
result?: unknown;
|
|
2095
2095
|
error?: string;
|
|
2096
|
-
errorType?: "parse" | "timeout" | "execution";
|
|
2096
|
+
errorType?: "parse" | "timeout" | "execution" | "cancelled";
|
|
2097
2097
|
};
|
|
2098
2098
|
type RunStartEvent = {
|
|
2099
2099
|
runId: string;
|
|
@@ -2219,7 +2219,7 @@ type ToolCallArgumentsDeltaEvent = {
|
|
|
2219
2219
|
argumentsDelta: string;
|
|
2220
2220
|
accumulatedArguments: string;
|
|
2221
2221
|
};
|
|
2222
|
-
type ToolExecutionErrorType = "parse" | "timeout" | "execution";
|
|
2222
|
+
type ToolExecutionErrorType = "parse" | "timeout" | "execution" | "cancelled";
|
|
2223
2223
|
|
|
2224
2224
|
/** A tool result from an auto-executed tool. */
|
|
2225
2225
|
type AutoExecutedToolResult = {
|
|
@@ -2679,7 +2679,7 @@ declare function runToolLoop(options: RunToolLoopOptions): Promise<RunToolLoopRe
|
|
|
2679
2679
|
/**
|
|
2680
2680
|
* Tool executor function type
|
|
2681
2681
|
*/
|
|
2682
|
-
type ToolExecutor = (args: Record<string, unknown
|
|
2682
|
+
type ToolExecutor = (args: Record<string, unknown>, signal?: AbortSignal) => Promise<unknown> | unknown;
|
|
2683
2683
|
/**
|
|
2684
2684
|
* Tool configuration with optional executor
|
|
2685
2685
|
*/
|
|
@@ -3393,6 +3393,20 @@ interface SelectServerToolsForPromptOptions {
|
|
|
3393
3393
|
* {@link resolveDeferredServerTools}). Omit/disabled → today's filtered selection.
|
|
3394
3394
|
*/
|
|
3395
3395
|
deferLoading?: DeferLoadingConfig;
|
|
3396
|
+
/**
|
|
3397
|
+
* Tool-set names that are sticky for this conversation — the same list you
|
|
3398
|
+
* pass to `useChatStorage`'s `activeToolSets`, e.g. from
|
|
3399
|
+
* `deriveActiveToolSets`. With a filter function, the server-tool members of
|
|
3400
|
+
* these sets are selected whatever the prompt scored, even on a prompt too
|
|
3401
|
+
* short to embed. Omit for selection from the prompt alone.
|
|
3402
|
+
*/
|
|
3403
|
+
activeToolSets?: string[];
|
|
3404
|
+
/**
|
|
3405
|
+
* The caller's sets beyond {@link BUILT_IN_TOOL_SETS} — the same list you pass
|
|
3406
|
+
* to `useChatStorage`'s `extraToolSets` — so a custom set named in
|
|
3407
|
+
* `activeToolSets` stays sticky here too.
|
|
3408
|
+
*/
|
|
3409
|
+
extraToolSets?: ToolSet[];
|
|
3396
3410
|
}
|
|
3397
3411
|
/**
|
|
3398
3412
|
* Select server-side tools for a prompt using the same path
|
package/dist/server/index.d.ts
CHANGED
|
@@ -2093,7 +2093,7 @@ type ToolUseEndEvent = {
|
|
|
2093
2093
|
name: string;
|
|
2094
2094
|
result?: unknown;
|
|
2095
2095
|
error?: string;
|
|
2096
|
-
errorType?: "parse" | "timeout" | "execution";
|
|
2096
|
+
errorType?: "parse" | "timeout" | "execution" | "cancelled";
|
|
2097
2097
|
};
|
|
2098
2098
|
type RunStartEvent = {
|
|
2099
2099
|
runId: string;
|
|
@@ -2219,7 +2219,7 @@ type ToolCallArgumentsDeltaEvent = {
|
|
|
2219
2219
|
argumentsDelta: string;
|
|
2220
2220
|
accumulatedArguments: string;
|
|
2221
2221
|
};
|
|
2222
|
-
type ToolExecutionErrorType = "parse" | "timeout" | "execution";
|
|
2222
|
+
type ToolExecutionErrorType = "parse" | "timeout" | "execution" | "cancelled";
|
|
2223
2223
|
|
|
2224
2224
|
/** A tool result from an auto-executed tool. */
|
|
2225
2225
|
type AutoExecutedToolResult = {
|
|
@@ -2679,7 +2679,7 @@ declare function runToolLoop(options: RunToolLoopOptions): Promise<RunToolLoopRe
|
|
|
2679
2679
|
/**
|
|
2680
2680
|
* Tool executor function type
|
|
2681
2681
|
*/
|
|
2682
|
-
type ToolExecutor = (args: Record<string, unknown
|
|
2682
|
+
type ToolExecutor = (args: Record<string, unknown>, signal?: AbortSignal) => Promise<unknown> | unknown;
|
|
2683
2683
|
/**
|
|
2684
2684
|
* Tool configuration with optional executor
|
|
2685
2685
|
*/
|
|
@@ -3393,6 +3393,20 @@ interface SelectServerToolsForPromptOptions {
|
|
|
3393
3393
|
* {@link resolveDeferredServerTools}). Omit/disabled → today's filtered selection.
|
|
3394
3394
|
*/
|
|
3395
3395
|
deferLoading?: DeferLoadingConfig;
|
|
3396
|
+
/**
|
|
3397
|
+
* Tool-set names that are sticky for this conversation — the same list you
|
|
3398
|
+
* pass to `useChatStorage`'s `activeToolSets`, e.g. from
|
|
3399
|
+
* `deriveActiveToolSets`. With a filter function, the server-tool members of
|
|
3400
|
+
* these sets are selected whatever the prompt scored, even on a prompt too
|
|
3401
|
+
* short to embed. Omit for selection from the prompt alone.
|
|
3402
|
+
*/
|
|
3403
|
+
activeToolSets?: string[];
|
|
3404
|
+
/**
|
|
3405
|
+
* The caller's sets beyond {@link BUILT_IN_TOOL_SETS} — the same list you pass
|
|
3406
|
+
* to `useChatStorage`'s `extraToolSets` — so a custom set named in
|
|
3407
|
+
* `activeToolSets` stays sticky here too.
|
|
3408
|
+
*/
|
|
3409
|
+
extraToolSets?: ToolSet[];
|
|
3396
3410
|
}
|
|
3397
3411
|
/**
|
|
3398
3412
|
* Select server-side tools for a prompt using the same path
|