@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/expo/index.cjs
CHANGED
|
@@ -5954,6 +5954,12 @@ var ToolTimeoutError = class extends Error {
|
|
|
5954
5954
|
this.name = "ToolTimeoutError";
|
|
5955
5955
|
}
|
|
5956
5956
|
};
|
|
5957
|
+
var ToolCancelledError = class extends Error {
|
|
5958
|
+
constructor() {
|
|
5959
|
+
super("Tool execution cancelled");
|
|
5960
|
+
this.name = "ToolCancelledError";
|
|
5961
|
+
}
|
|
5962
|
+
};
|
|
5957
5963
|
function safeJsonStringify(value) {
|
|
5958
5964
|
try {
|
|
5959
5965
|
return JSON.stringify(value) ?? "null";
|
|
@@ -5961,7 +5967,7 @@ function safeJsonStringify(value) {
|
|
|
5961
5967
|
return String(value);
|
|
5962
5968
|
}
|
|
5963
5969
|
}
|
|
5964
|
-
async function executeToolCall(toolCall, executor, timeoutMs = TOOL_EXECUTOR_TIMEOUT_MS) {
|
|
5970
|
+
async function executeToolCall(toolCall, executor, timeoutMs = TOOL_EXECUTOR_TIMEOUT_MS, signal) {
|
|
5965
5971
|
let args = {};
|
|
5966
5972
|
if (toolCall.arguments) {
|
|
5967
5973
|
const parsed = parseToolArguments(toolCall.arguments);
|
|
@@ -5970,28 +5976,42 @@ async function executeToolCall(toolCall, executor, timeoutMs = TOOL_EXECUTOR_TIM
|
|
|
5970
5976
|
}
|
|
5971
5977
|
args = parsed.args;
|
|
5972
5978
|
}
|
|
5979
|
+
if (signal?.aborted) {
|
|
5980
|
+
return { error: "Tool execution cancelled", errorType: "cancelled" };
|
|
5981
|
+
}
|
|
5982
|
+
let timer;
|
|
5983
|
+
let onAbort;
|
|
5973
5984
|
try {
|
|
5974
|
-
|
|
5975
|
-
|
|
5985
|
+
const racers = [];
|
|
5986
|
+
if (signal) {
|
|
5987
|
+
racers.push(
|
|
5988
|
+
new Promise((_, reject) => {
|
|
5989
|
+
onAbort = () => reject(new ToolCancelledError());
|
|
5990
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
5991
|
+
})
|
|
5992
|
+
);
|
|
5976
5993
|
}
|
|
5977
|
-
|
|
5978
|
-
|
|
5979
|
-
|
|
5980
|
-
executor(args),
|
|
5994
|
+
racers.push(Promise.resolve(signal ? executor(args, signal) : executor(args)));
|
|
5995
|
+
if (isFinite(timeoutMs)) {
|
|
5996
|
+
racers.push(
|
|
5981
5997
|
new Promise((_, reject) => {
|
|
5982
5998
|
timer = setTimeout(() => reject(new ToolTimeoutError()), timeoutMs);
|
|
5983
5999
|
})
|
|
5984
|
-
|
|
5985
|
-
return { result };
|
|
5986
|
-
} finally {
|
|
5987
|
-
clearTimeout(timer);
|
|
6000
|
+
);
|
|
5988
6001
|
}
|
|
6002
|
+
return { result: await Promise.race(racers) };
|
|
5989
6003
|
} catch (e) {
|
|
6004
|
+
if (e instanceof ToolCancelledError) {
|
|
6005
|
+
return { error: "Tool execution cancelled", errorType: "cancelled" };
|
|
6006
|
+
}
|
|
5990
6007
|
const message = e instanceof Error ? e.message : String(e);
|
|
5991
6008
|
return {
|
|
5992
6009
|
error: `Tool execution failed: ${message}`,
|
|
5993
6010
|
errorType: e instanceof ToolTimeoutError ? "timeout" : "execution"
|
|
5994
6011
|
};
|
|
6012
|
+
} finally {
|
|
6013
|
+
clearTimeout(timer);
|
|
6014
|
+
if (onAbort) signal?.removeEventListener("abort", onAbort);
|
|
5995
6015
|
}
|
|
5996
6016
|
}
|
|
5997
6017
|
function toolsToApiFormat(tools, apiType) {
|
|
@@ -8347,11 +8367,12 @@ Executing tool: ${toolInfo}
|
|
|
8347
8367
|
const blockedByFailure = failedDeps.some((d) => failedNames.has(d));
|
|
8348
8368
|
const reason = blockedByFailure ? `failed dependencies: ${failedDeps.join(", ")}` : "a dependency cycle";
|
|
8349
8369
|
const errorMsg = `Tool "${tc.name}" was not executed due to ${reason}`;
|
|
8370
|
+
const skipErrorType = combinedSignal?.aborted ? "cancelled" : "execution";
|
|
8350
8371
|
executionResults.push({
|
|
8351
8372
|
id: tc.id,
|
|
8352
8373
|
name: tc.name,
|
|
8353
8374
|
error: errorMsg,
|
|
8354
|
-
errorType:
|
|
8375
|
+
errorType: skipErrorType
|
|
8355
8376
|
});
|
|
8356
8377
|
await safeAwait(
|
|
8357
8378
|
() => hooks?.afterToolUse?.({
|
|
@@ -8360,7 +8381,7 @@ Executing tool: ${toolInfo}
|
|
|
8360
8381
|
toolCallId: tc.id,
|
|
8361
8382
|
name: tc.name,
|
|
8362
8383
|
error: errorMsg,
|
|
8363
|
-
errorType:
|
|
8384
|
+
errorType: skipErrorType
|
|
8364
8385
|
})
|
|
8365
8386
|
);
|
|
8366
8387
|
}
|
|
@@ -8380,7 +8401,8 @@ Executing tool: ${toolInfo}
|
|
|
8380
8401
|
const { result, error, errorType } = await executeToolCall(
|
|
8381
8402
|
toolCallForExec,
|
|
8382
8403
|
executorConfig.executor,
|
|
8383
|
-
executorConfig.executorTimeout
|
|
8404
|
+
executorConfig.executorTimeout,
|
|
8405
|
+
combinedSignal
|
|
8384
8406
|
);
|
|
8385
8407
|
await safeAwait(
|
|
8386
8408
|
() => hooks?.afterToolUse?.({
|
|
@@ -20971,6 +20993,23 @@ var BUILT_IN_TOOL_SETS = [
|
|
|
20971
20993
|
members: ["dropbox_list_folders", "dropbox_get_file_content", "dropbox_search"],
|
|
20972
20994
|
anchors: ["dropbox_list_folders", "dropbox_search"],
|
|
20973
20995
|
anchorMinSimilarity: 0.53
|
|
20996
|
+
},
|
|
20997
|
+
{
|
|
20998
|
+
// Server tools, so this set does its work through
|
|
20999
|
+
// withActiveToolSetServerTools: once a restaurant tool has run, terse
|
|
21000
|
+
// follow-ups ("okay", "same as before") keep the booking chain. Each tool
|
|
21001
|
+
// still reaches a fresh booking request on its own description.
|
|
21002
|
+
// Anchors are deliberately empty (like the client's Nearby set): the set
|
|
21003
|
+
// is only for stickiness, not a new way to activate on a prompt.
|
|
21004
|
+
// prompt_user_confirm is left out of members: autoFilterClientTools always
|
|
21005
|
+
// sends it, and as a member any unrelated confirmation would pin this set.
|
|
21006
|
+
name: "restaurant-booking",
|
|
21007
|
+
members: [
|
|
21008
|
+
"AnumaPaymentsMCP-anuma_find_restaurant",
|
|
21009
|
+
"AnumaPaymentsMCP-anuma_check_restaurant_availability",
|
|
21010
|
+
"AnumaPaymentsMCP-anuma_book_restaurant"
|
|
21011
|
+
],
|
|
21012
|
+
anchors: []
|
|
20974
21013
|
}
|
|
20975
21014
|
];
|
|
20976
21015
|
function expandToolSetsAdditive(matchedNames, availableNames, scores, toolSets, activeSetNames) {
|
|
@@ -21004,6 +21043,16 @@ function activatedToolSetNames(scores, toolSets = BUILT_IN_TOOL_SETS, activeSetN
|
|
|
21004
21043
|
}
|
|
21005
21044
|
return activated;
|
|
21006
21045
|
}
|
|
21046
|
+
function withActiveToolSetServerTools(selected, allServerTools, serverToolsFilter, activeToolSets = [], extraToolSets = []) {
|
|
21047
|
+
if (activeToolSets.length === 0) return selected;
|
|
21048
|
+
const sticky = new Set(
|
|
21049
|
+
[...BUILT_IN_TOOL_SETS, ...extraToolSets].filter((ts) => activeToolSets.includes(ts.name)).flatMap((ts) => ts.members)
|
|
21050
|
+
);
|
|
21051
|
+
for (const name of serverToolsFilter.excludeTools ?? []) sticky.delete(name);
|
|
21052
|
+
for (const tool of selected) sticky.delete(tool.name);
|
|
21053
|
+
const added = allServerTools.filter((tool) => sticky.has(tool.name));
|
|
21054
|
+
return added.length > 0 ? [...selected, ...added] : selected;
|
|
21055
|
+
}
|
|
21007
21056
|
function toolSetSystemPrompts(selectedToolNames, toolSets = BUILT_IN_TOOL_SETS, activatedSetNames) {
|
|
21008
21057
|
const selected = selectedToolNames instanceof Set ? selectedToolNames : new Set(selectedToolNames);
|
|
21009
21058
|
const prompts = [];
|
|
@@ -22078,15 +22127,25 @@ function useChatStorage(options) {
|
|
|
22078
22127
|
);
|
|
22079
22128
|
} else if (isServerToolsFunction2) {
|
|
22080
22129
|
if (messageContent.length >= MIN_CONTENT_LENGTH_FOR_TOOLS) {
|
|
22081
|
-
|
|
22082
|
-
|
|
22083
|
-
|
|
22084
|
-
|
|
22085
|
-
|
|
22086
|
-
|
|
22087
|
-
|
|
22088
|
-
|
|
22130
|
+
try {
|
|
22131
|
+
skipUserEmbedding = await embedToolText(
|
|
22132
|
+
messageContent,
|
|
22133
|
+
maskForCall2,
|
|
22134
|
+
Boolean(callPiiRedaction2),
|
|
22135
|
+
getTokenRef.current
|
|
22136
|
+
);
|
|
22137
|
+
const toolNames = serverToolsFilter(skipUserEmbedding, allServerTools);
|
|
22138
|
+
filteredServerTools2 = filterServerTools(allServerTools, toolNames);
|
|
22139
|
+
} catch {
|
|
22140
|
+
}
|
|
22089
22141
|
}
|
|
22142
|
+
filteredServerTools2 = withActiveToolSetServerTools(
|
|
22143
|
+
filteredServerTools2,
|
|
22144
|
+
allServerTools,
|
|
22145
|
+
serverToolsFilter,
|
|
22146
|
+
activeToolSetsRef.current,
|
|
22147
|
+
extraToolSets
|
|
22148
|
+
);
|
|
22090
22149
|
} else {
|
|
22091
22150
|
filteredServerTools2 = filterServerTools(allServerTools, serverToolsFilter);
|
|
22092
22151
|
}
|
|
@@ -22375,12 +22434,19 @@ function useChatStorage(options) {
|
|
|
22375
22434
|
const settledEmbedding = await (userMessageEmbeddingPromise ?? embedForToolsSettled(getTokenRef.current));
|
|
22376
22435
|
if ("error" in settledEmbedding) {
|
|
22377
22436
|
serverFilterEmbeddingFailed = true;
|
|
22378
|
-
|
|
22437
|
+
} else {
|
|
22438
|
+
userMessageEmbedding = settledEmbedding.embedding;
|
|
22439
|
+
const toolNames = serverToolsFilter(userMessageEmbedding, allServerTools);
|
|
22440
|
+
filteredServerTools = filterServerTools(allServerTools, toolNames);
|
|
22379
22441
|
}
|
|
22380
|
-
userMessageEmbedding = settledEmbedding.embedding;
|
|
22381
|
-
const toolNames = serverToolsFilter(userMessageEmbedding, allServerTools);
|
|
22382
|
-
filteredServerTools = filterServerTools(allServerTools, toolNames);
|
|
22383
22442
|
}
|
|
22443
|
+
filteredServerTools = withActiveToolSetServerTools(
|
|
22444
|
+
filteredServerTools,
|
|
22445
|
+
allServerTools,
|
|
22446
|
+
serverToolsFilter,
|
|
22447
|
+
activeToolSetsRef.current,
|
|
22448
|
+
extraToolSets
|
|
22449
|
+
);
|
|
22384
22450
|
} else {
|
|
22385
22451
|
filteredServerTools = filterServerTools(allServerTools, serverToolsFilter);
|
|
22386
22452
|
}
|
package/dist/expo/index.d.mts
CHANGED
|
@@ -2177,12 +2177,12 @@ type ToolCallArgumentsDeltaEvent = {
|
|
|
2177
2177
|
argumentsDelta: string;
|
|
2178
2178
|
accumulatedArguments: string;
|
|
2179
2179
|
};
|
|
2180
|
-
type ToolExecutionErrorType = "parse" | "timeout" | "execution";
|
|
2180
|
+
type ToolExecutionErrorType = "parse" | "timeout" | "execution" | "cancelled";
|
|
2181
2181
|
|
|
2182
2182
|
/**
|
|
2183
2183
|
* Tool executor function type
|
|
2184
2184
|
*/
|
|
2185
|
-
type ToolExecutor = (args: Record<string, unknown
|
|
2185
|
+
type ToolExecutor = (args: Record<string, unknown>, signal?: AbortSignal) => Promise<unknown> | unknown;
|
|
2186
2186
|
/**
|
|
2187
2187
|
* Tool configuration with optional executor
|
|
2188
2188
|
*/
|
package/dist/expo/index.d.ts
CHANGED
|
@@ -2177,12 +2177,12 @@ type ToolCallArgumentsDeltaEvent = {
|
|
|
2177
2177
|
argumentsDelta: string;
|
|
2178
2178
|
accumulatedArguments: string;
|
|
2179
2179
|
};
|
|
2180
|
-
type ToolExecutionErrorType = "parse" | "timeout" | "execution";
|
|
2180
|
+
type ToolExecutionErrorType = "parse" | "timeout" | "execution" | "cancelled";
|
|
2181
2181
|
|
|
2182
2182
|
/**
|
|
2183
2183
|
* Tool executor function type
|
|
2184
2184
|
*/
|
|
2185
|
-
type ToolExecutor = (args: Record<string, unknown
|
|
2185
|
+
type ToolExecutor = (args: Record<string, unknown>, signal?: AbortSignal) => Promise<unknown> | unknown;
|
|
2186
2186
|
/**
|
|
2187
2187
|
* Tool configuration with optional executor
|
|
2188
2188
|
*/
|
package/dist/expo/index.mjs
CHANGED
|
@@ -4351,6 +4351,12 @@ var ToolTimeoutError = class extends Error {
|
|
|
4351
4351
|
this.name = "ToolTimeoutError";
|
|
4352
4352
|
}
|
|
4353
4353
|
};
|
|
4354
|
+
var ToolCancelledError = class extends Error {
|
|
4355
|
+
constructor() {
|
|
4356
|
+
super("Tool execution cancelled");
|
|
4357
|
+
this.name = "ToolCancelledError";
|
|
4358
|
+
}
|
|
4359
|
+
};
|
|
4354
4360
|
function safeJsonStringify(value) {
|
|
4355
4361
|
try {
|
|
4356
4362
|
return JSON.stringify(value) ?? "null";
|
|
@@ -4358,7 +4364,7 @@ function safeJsonStringify(value) {
|
|
|
4358
4364
|
return String(value);
|
|
4359
4365
|
}
|
|
4360
4366
|
}
|
|
4361
|
-
async function executeToolCall(toolCall, executor, timeoutMs = TOOL_EXECUTOR_TIMEOUT_MS) {
|
|
4367
|
+
async function executeToolCall(toolCall, executor, timeoutMs = TOOL_EXECUTOR_TIMEOUT_MS, signal) {
|
|
4362
4368
|
let args = {};
|
|
4363
4369
|
if (toolCall.arguments) {
|
|
4364
4370
|
const parsed = parseToolArguments(toolCall.arguments);
|
|
@@ -4367,28 +4373,42 @@ async function executeToolCall(toolCall, executor, timeoutMs = TOOL_EXECUTOR_TIM
|
|
|
4367
4373
|
}
|
|
4368
4374
|
args = parsed.args;
|
|
4369
4375
|
}
|
|
4376
|
+
if (signal?.aborted) {
|
|
4377
|
+
return { error: "Tool execution cancelled", errorType: "cancelled" };
|
|
4378
|
+
}
|
|
4379
|
+
let timer;
|
|
4380
|
+
let onAbort;
|
|
4370
4381
|
try {
|
|
4371
|
-
|
|
4372
|
-
|
|
4382
|
+
const racers = [];
|
|
4383
|
+
if (signal) {
|
|
4384
|
+
racers.push(
|
|
4385
|
+
new Promise((_, reject) => {
|
|
4386
|
+
onAbort = () => reject(new ToolCancelledError());
|
|
4387
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
4388
|
+
})
|
|
4389
|
+
);
|
|
4373
4390
|
}
|
|
4374
|
-
|
|
4375
|
-
|
|
4376
|
-
|
|
4377
|
-
executor(args),
|
|
4391
|
+
racers.push(Promise.resolve(signal ? executor(args, signal) : executor(args)));
|
|
4392
|
+
if (isFinite(timeoutMs)) {
|
|
4393
|
+
racers.push(
|
|
4378
4394
|
new Promise((_, reject) => {
|
|
4379
4395
|
timer = setTimeout(() => reject(new ToolTimeoutError()), timeoutMs);
|
|
4380
4396
|
})
|
|
4381
|
-
|
|
4382
|
-
return { result };
|
|
4383
|
-
} finally {
|
|
4384
|
-
clearTimeout(timer);
|
|
4397
|
+
);
|
|
4385
4398
|
}
|
|
4399
|
+
return { result: await Promise.race(racers) };
|
|
4386
4400
|
} catch (e) {
|
|
4401
|
+
if (e instanceof ToolCancelledError) {
|
|
4402
|
+
return { error: "Tool execution cancelled", errorType: "cancelled" };
|
|
4403
|
+
}
|
|
4387
4404
|
const message = e instanceof Error ? e.message : String(e);
|
|
4388
4405
|
return {
|
|
4389
4406
|
error: `Tool execution failed: ${message}`,
|
|
4390
4407
|
errorType: e instanceof ToolTimeoutError ? "timeout" : "execution"
|
|
4391
4408
|
};
|
|
4409
|
+
} finally {
|
|
4410
|
+
clearTimeout(timer);
|
|
4411
|
+
if (onAbort) signal?.removeEventListener("abort", onAbort);
|
|
4392
4412
|
}
|
|
4393
4413
|
}
|
|
4394
4414
|
function toolsToApiFormat(tools, apiType) {
|
|
@@ -6744,11 +6764,12 @@ Executing tool: ${toolInfo}
|
|
|
6744
6764
|
const blockedByFailure = failedDeps.some((d) => failedNames.has(d));
|
|
6745
6765
|
const reason = blockedByFailure ? `failed dependencies: ${failedDeps.join(", ")}` : "a dependency cycle";
|
|
6746
6766
|
const errorMsg = `Tool "${tc.name}" was not executed due to ${reason}`;
|
|
6767
|
+
const skipErrorType = combinedSignal?.aborted ? "cancelled" : "execution";
|
|
6747
6768
|
executionResults.push({
|
|
6748
6769
|
id: tc.id,
|
|
6749
6770
|
name: tc.name,
|
|
6750
6771
|
error: errorMsg,
|
|
6751
|
-
errorType:
|
|
6772
|
+
errorType: skipErrorType
|
|
6752
6773
|
});
|
|
6753
6774
|
await safeAwait(
|
|
6754
6775
|
() => hooks?.afterToolUse?.({
|
|
@@ -6757,7 +6778,7 @@ Executing tool: ${toolInfo}
|
|
|
6757
6778
|
toolCallId: tc.id,
|
|
6758
6779
|
name: tc.name,
|
|
6759
6780
|
error: errorMsg,
|
|
6760
|
-
errorType:
|
|
6781
|
+
errorType: skipErrorType
|
|
6761
6782
|
})
|
|
6762
6783
|
);
|
|
6763
6784
|
}
|
|
@@ -6777,7 +6798,8 @@ Executing tool: ${toolInfo}
|
|
|
6777
6798
|
const { result, error, errorType } = await executeToolCall(
|
|
6778
6799
|
toolCallForExec,
|
|
6779
6800
|
executorConfig.executor,
|
|
6780
|
-
executorConfig.executorTimeout
|
|
6801
|
+
executorConfig.executorTimeout,
|
|
6802
|
+
combinedSignal
|
|
6781
6803
|
);
|
|
6782
6804
|
await safeAwait(
|
|
6783
6805
|
() => hooks?.afterToolUse?.({
|
|
@@ -19300,6 +19322,23 @@ var BUILT_IN_TOOL_SETS = [
|
|
|
19300
19322
|
members: ["dropbox_list_folders", "dropbox_get_file_content", "dropbox_search"],
|
|
19301
19323
|
anchors: ["dropbox_list_folders", "dropbox_search"],
|
|
19302
19324
|
anchorMinSimilarity: 0.53
|
|
19325
|
+
},
|
|
19326
|
+
{
|
|
19327
|
+
// Server tools, so this set does its work through
|
|
19328
|
+
// withActiveToolSetServerTools: once a restaurant tool has run, terse
|
|
19329
|
+
// follow-ups ("okay", "same as before") keep the booking chain. Each tool
|
|
19330
|
+
// still reaches a fresh booking request on its own description.
|
|
19331
|
+
// Anchors are deliberately empty (like the client's Nearby set): the set
|
|
19332
|
+
// is only for stickiness, not a new way to activate on a prompt.
|
|
19333
|
+
// prompt_user_confirm is left out of members: autoFilterClientTools always
|
|
19334
|
+
// sends it, and as a member any unrelated confirmation would pin this set.
|
|
19335
|
+
name: "restaurant-booking",
|
|
19336
|
+
members: [
|
|
19337
|
+
"AnumaPaymentsMCP-anuma_find_restaurant",
|
|
19338
|
+
"AnumaPaymentsMCP-anuma_check_restaurant_availability",
|
|
19339
|
+
"AnumaPaymentsMCP-anuma_book_restaurant"
|
|
19340
|
+
],
|
|
19341
|
+
anchors: []
|
|
19303
19342
|
}
|
|
19304
19343
|
];
|
|
19305
19344
|
function expandToolSetsAdditive(matchedNames, availableNames, scores, toolSets, activeSetNames) {
|
|
@@ -19333,6 +19372,16 @@ function activatedToolSetNames(scores, toolSets = BUILT_IN_TOOL_SETS, activeSetN
|
|
|
19333
19372
|
}
|
|
19334
19373
|
return activated;
|
|
19335
19374
|
}
|
|
19375
|
+
function withActiveToolSetServerTools(selected, allServerTools, serverToolsFilter, activeToolSets = [], extraToolSets = []) {
|
|
19376
|
+
if (activeToolSets.length === 0) return selected;
|
|
19377
|
+
const sticky = new Set(
|
|
19378
|
+
[...BUILT_IN_TOOL_SETS, ...extraToolSets].filter((ts) => activeToolSets.includes(ts.name)).flatMap((ts) => ts.members)
|
|
19379
|
+
);
|
|
19380
|
+
for (const name of serverToolsFilter.excludeTools ?? []) sticky.delete(name);
|
|
19381
|
+
for (const tool of selected) sticky.delete(tool.name);
|
|
19382
|
+
const added = allServerTools.filter((tool) => sticky.has(tool.name));
|
|
19383
|
+
return added.length > 0 ? [...selected, ...added] : selected;
|
|
19384
|
+
}
|
|
19336
19385
|
function toolSetSystemPrompts(selectedToolNames, toolSets = BUILT_IN_TOOL_SETS, activatedSetNames) {
|
|
19337
19386
|
const selected = selectedToolNames instanceof Set ? selectedToolNames : new Set(selectedToolNames);
|
|
19338
19387
|
const prompts = [];
|
|
@@ -20407,15 +20456,25 @@ function useChatStorage(options) {
|
|
|
20407
20456
|
);
|
|
20408
20457
|
} else if (isServerToolsFunction2) {
|
|
20409
20458
|
if (messageContent.length >= MIN_CONTENT_LENGTH_FOR_TOOLS) {
|
|
20410
|
-
|
|
20411
|
-
|
|
20412
|
-
|
|
20413
|
-
|
|
20414
|
-
|
|
20415
|
-
|
|
20416
|
-
|
|
20417
|
-
|
|
20459
|
+
try {
|
|
20460
|
+
skipUserEmbedding = await embedToolText(
|
|
20461
|
+
messageContent,
|
|
20462
|
+
maskForCall2,
|
|
20463
|
+
Boolean(callPiiRedaction2),
|
|
20464
|
+
getTokenRef.current
|
|
20465
|
+
);
|
|
20466
|
+
const toolNames = serverToolsFilter(skipUserEmbedding, allServerTools);
|
|
20467
|
+
filteredServerTools2 = filterServerTools(allServerTools, toolNames);
|
|
20468
|
+
} catch {
|
|
20469
|
+
}
|
|
20418
20470
|
}
|
|
20471
|
+
filteredServerTools2 = withActiveToolSetServerTools(
|
|
20472
|
+
filteredServerTools2,
|
|
20473
|
+
allServerTools,
|
|
20474
|
+
serverToolsFilter,
|
|
20475
|
+
activeToolSetsRef.current,
|
|
20476
|
+
extraToolSets
|
|
20477
|
+
);
|
|
20419
20478
|
} else {
|
|
20420
20479
|
filteredServerTools2 = filterServerTools(allServerTools, serverToolsFilter);
|
|
20421
20480
|
}
|
|
@@ -20704,12 +20763,19 @@ function useChatStorage(options) {
|
|
|
20704
20763
|
const settledEmbedding = await (userMessageEmbeddingPromise ?? embedForToolsSettled(getTokenRef.current));
|
|
20705
20764
|
if ("error" in settledEmbedding) {
|
|
20706
20765
|
serverFilterEmbeddingFailed = true;
|
|
20707
|
-
|
|
20766
|
+
} else {
|
|
20767
|
+
userMessageEmbedding = settledEmbedding.embedding;
|
|
20768
|
+
const toolNames = serverToolsFilter(userMessageEmbedding, allServerTools);
|
|
20769
|
+
filteredServerTools = filterServerTools(allServerTools, toolNames);
|
|
20708
20770
|
}
|
|
20709
|
-
userMessageEmbedding = settledEmbedding.embedding;
|
|
20710
|
-
const toolNames = serverToolsFilter(userMessageEmbedding, allServerTools);
|
|
20711
|
-
filteredServerTools = filterServerTools(allServerTools, toolNames);
|
|
20712
20771
|
}
|
|
20772
|
+
filteredServerTools = withActiveToolSetServerTools(
|
|
20773
|
+
filteredServerTools,
|
|
20774
|
+
allServerTools,
|
|
20775
|
+
serverToolsFilter,
|
|
20776
|
+
activeToolSetsRef.current,
|
|
20777
|
+
extraToolSets
|
|
20778
|
+
);
|
|
20713
20779
|
} else {
|
|
20714
20780
|
filteredServerTools = filterServerTools(allServerTools, serverToolsFilter);
|
|
20715
20781
|
}
|
package/dist/index.cjs
CHANGED
|
@@ -2258,6 +2258,23 @@ var BUILT_IN_TOOL_SETS = [
|
|
|
2258
2258
|
members: ["dropbox_list_folders", "dropbox_get_file_content", "dropbox_search"],
|
|
2259
2259
|
anchors: ["dropbox_list_folders", "dropbox_search"],
|
|
2260
2260
|
anchorMinSimilarity: 0.53
|
|
2261
|
+
},
|
|
2262
|
+
{
|
|
2263
|
+
// Server tools, so this set does its work through
|
|
2264
|
+
// withActiveToolSetServerTools: once a restaurant tool has run, terse
|
|
2265
|
+
// follow-ups ("okay", "same as before") keep the booking chain. Each tool
|
|
2266
|
+
// still reaches a fresh booking request on its own description.
|
|
2267
|
+
// Anchors are deliberately empty (like the client's Nearby set): the set
|
|
2268
|
+
// is only for stickiness, not a new way to activate on a prompt.
|
|
2269
|
+
// prompt_user_confirm is left out of members: autoFilterClientTools always
|
|
2270
|
+
// sends it, and as a member any unrelated confirmation would pin this set.
|
|
2271
|
+
name: "restaurant-booking",
|
|
2272
|
+
members: [
|
|
2273
|
+
"AnumaPaymentsMCP-anuma_find_restaurant",
|
|
2274
|
+
"AnumaPaymentsMCP-anuma_check_restaurant_availability",
|
|
2275
|
+
"AnumaPaymentsMCP-anuma_book_restaurant"
|
|
2276
|
+
],
|
|
2277
|
+
anchors: []
|
|
2261
2278
|
}
|
|
2262
2279
|
];
|
|
2263
2280
|
function applyToolSets(matchedNames, availableNames, scores, toolSets = BUILT_IN_TOOL_SETS, independentThreshold = 0.65) {
|
package/dist/index.d.mts
CHANGED
|
@@ -7637,7 +7637,7 @@ declare function getImageModel(r: ApiResponse): string | undefined;
|
|
|
7637
7637
|
/**
|
|
7638
7638
|
* Tool executor function type
|
|
7639
7639
|
*/
|
|
7640
|
-
type ToolExecutor = (args: Record<string, unknown
|
|
7640
|
+
type ToolExecutor = (args: Record<string, unknown>, signal?: AbortSignal) => Promise<unknown> | unknown;
|
|
7641
7641
|
/**
|
|
7642
7642
|
* Tool configuration with optional executor
|
|
7643
7643
|
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -7637,7 +7637,7 @@ declare function getImageModel(r: ApiResponse): string | undefined;
|
|
|
7637
7637
|
/**
|
|
7638
7638
|
* Tool executor function type
|
|
7639
7639
|
*/
|
|
7640
|
-
type ToolExecutor = (args: Record<string, unknown
|
|
7640
|
+
type ToolExecutor = (args: Record<string, unknown>, signal?: AbortSignal) => Promise<unknown> | unknown;
|
|
7641
7641
|
/**
|
|
7642
7642
|
* Tool configuration with optional executor
|
|
7643
7643
|
*/
|
package/dist/index.mjs
CHANGED
|
@@ -2052,6 +2052,23 @@ var BUILT_IN_TOOL_SETS = [
|
|
|
2052
2052
|
members: ["dropbox_list_folders", "dropbox_get_file_content", "dropbox_search"],
|
|
2053
2053
|
anchors: ["dropbox_list_folders", "dropbox_search"],
|
|
2054
2054
|
anchorMinSimilarity: 0.53
|
|
2055
|
+
},
|
|
2056
|
+
{
|
|
2057
|
+
// Server tools, so this set does its work through
|
|
2058
|
+
// withActiveToolSetServerTools: once a restaurant tool has run, terse
|
|
2059
|
+
// follow-ups ("okay", "same as before") keep the booking chain. Each tool
|
|
2060
|
+
// still reaches a fresh booking request on its own description.
|
|
2061
|
+
// Anchors are deliberately empty (like the client's Nearby set): the set
|
|
2062
|
+
// is only for stickiness, not a new way to activate on a prompt.
|
|
2063
|
+
// prompt_user_confirm is left out of members: autoFilterClientTools always
|
|
2064
|
+
// sends it, and as a member any unrelated confirmation would pin this set.
|
|
2065
|
+
name: "restaurant-booking",
|
|
2066
|
+
members: [
|
|
2067
|
+
"AnumaPaymentsMCP-anuma_find_restaurant",
|
|
2068
|
+
"AnumaPaymentsMCP-anuma_check_restaurant_availability",
|
|
2069
|
+
"AnumaPaymentsMCP-anuma_book_restaurant"
|
|
2070
|
+
],
|
|
2071
|
+
anchors: []
|
|
2055
2072
|
}
|
|
2056
2073
|
];
|
|
2057
2074
|
function applyToolSets(matchedNames, availableNames, scores, toolSets = BUILT_IN_TOOL_SETS, independentThreshold = 0.65) {
|