@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.
@@ -31547,6 +31547,23 @@ var BUILT_IN_TOOL_SETS = [
31547
31547
  members: ["dropbox_list_folders", "dropbox_get_file_content", "dropbox_search"],
31548
31548
  anchors: ["dropbox_list_folders", "dropbox_search"],
31549
31549
  anchorMinSimilarity: 0.53
31550
+ },
31551
+ {
31552
+ // Server tools, so this set does its work through
31553
+ // withActiveToolSetServerTools: once a restaurant tool has run, terse
31554
+ // follow-ups ("okay", "same as before") keep the booking chain. Each tool
31555
+ // still reaches a fresh booking request on its own description.
31556
+ // Anchors are deliberately empty (like the client's Nearby set): the set
31557
+ // is only for stickiness, not a new way to activate on a prompt.
31558
+ // prompt_user_confirm is left out of members: autoFilterClientTools always
31559
+ // sends it, and as a member any unrelated confirmation would pin this set.
31560
+ name: "restaurant-booking",
31561
+ members: [
31562
+ "AnumaPaymentsMCP-anuma_find_restaurant",
31563
+ "AnumaPaymentsMCP-anuma_check_restaurant_availability",
31564
+ "AnumaPaymentsMCP-anuma_book_restaurant"
31565
+ ],
31566
+ anchors: []
31550
31567
  }
31551
31568
  ];
31552
31569
  function expandToolSetsAdditive(matchedNames, availableNames, scores, toolSets, activeSetNames) {
@@ -31580,6 +31597,16 @@ function activatedToolSetNames(scores, toolSets = BUILT_IN_TOOL_SETS, activeSetN
31580
31597
  }
31581
31598
  return activated;
31582
31599
  }
31600
+ function withActiveToolSetServerTools(selected, allServerTools, serverToolsFilter, activeToolSets = [], extraToolSets = []) {
31601
+ if (activeToolSets.length === 0) return selected;
31602
+ const sticky = new Set(
31603
+ [...BUILT_IN_TOOL_SETS, ...extraToolSets].filter((ts) => activeToolSets.includes(ts.name)).flatMap((ts) => ts.members)
31604
+ );
31605
+ for (const name of serverToolsFilter.excludeTools ?? []) sticky.delete(name);
31606
+ for (const tool of selected) sticky.delete(tool.name);
31607
+ const added = allServerTools.filter((tool) => sticky.has(tool.name));
31608
+ return added.length > 0 ? [...selected, ...added] : selected;
31609
+ }
31583
31610
  function toolSetSystemPrompts(selectedToolNames, toolSets = BUILT_IN_TOOL_SETS, activatedSetNames) {
31584
31611
  const selected = selectedToolNames instanceof Set ? selectedToolNames : new Set(selectedToolNames);
31585
31612
  const prompts = [];
@@ -31693,7 +31720,9 @@ async function selectServerToolsForPrompt(options) {
31693
31720
  embeddingModel,
31694
31721
  cacheExpirationMs,
31695
31722
  cache,
31696
- deferLoading
31723
+ deferLoading,
31724
+ activeToolSets,
31725
+ extraToolSets
31697
31726
  } = options;
31698
31727
  if (serverToolsFilter === void 0) return [];
31699
31728
  if (Array.isArray(serverToolsFilter) && serverToolsFilter.length === 0) return [];
@@ -31707,7 +31736,14 @@ async function selectServerToolsForPrompt(options) {
31707
31736
  if (deferLoading?.enabled)
31708
31737
  return resolveDeferredServerTools(allServerTools, serverToolsFilter, deferLoading);
31709
31738
  if (typeof serverToolsFilter === "function") {
31710
- if (prompt.length < MIN_CONTENT_LENGTH_FOR_TOOLS) return [];
31739
+ const withSticky = (selected) => withActiveToolSetServerTools(
31740
+ selected,
31741
+ allServerTools,
31742
+ serverToolsFilter,
31743
+ activeToolSets,
31744
+ extraToolSets
31745
+ );
31746
+ if (prompt.length < MIN_CONTENT_LENGTH_FOR_TOOLS) return withSticky([]);
31711
31747
  let promptEmbedding;
31712
31748
  try {
31713
31749
  promptEmbedding = await generateEmbedding(prompt, {
@@ -31716,10 +31752,10 @@ async function selectServerToolsForPrompt(options) {
31716
31752
  model: embeddingModel
31717
31753
  });
31718
31754
  } catch {
31719
- return [];
31755
+ return withSticky([]);
31720
31756
  }
31721
31757
  const names = serverToolsFilter(promptEmbedding, allServerTools);
31722
- return filterServerTools(allServerTools, names);
31758
+ return withSticky(filterServerTools(allServerTools, names));
31723
31759
  }
31724
31760
  return filterServerTools(allServerTools, serverToolsFilter);
31725
31761
  }
@@ -33629,6 +33665,12 @@ var ToolTimeoutError = class extends Error {
33629
33665
  this.name = "ToolTimeoutError";
33630
33666
  }
33631
33667
  };
33668
+ var ToolCancelledError = class extends Error {
33669
+ constructor() {
33670
+ super("Tool execution cancelled");
33671
+ this.name = "ToolCancelledError";
33672
+ }
33673
+ };
33632
33674
  function safeJsonStringify(value) {
33633
33675
  try {
33634
33676
  return JSON.stringify(value) ?? "null";
@@ -33636,7 +33678,7 @@ function safeJsonStringify(value) {
33636
33678
  return String(value);
33637
33679
  }
33638
33680
  }
33639
- async function executeToolCall(toolCall, executor, timeoutMs = TOOL_EXECUTOR_TIMEOUT_MS) {
33681
+ async function executeToolCall(toolCall, executor, timeoutMs = TOOL_EXECUTOR_TIMEOUT_MS, signal) {
33640
33682
  let args = {};
33641
33683
  if (toolCall.arguments) {
33642
33684
  const parsed = parseToolArguments(toolCall.arguments);
@@ -33645,28 +33687,42 @@ async function executeToolCall(toolCall, executor, timeoutMs = TOOL_EXECUTOR_TIM
33645
33687
  }
33646
33688
  args = parsed.args;
33647
33689
  }
33690
+ if (signal?.aborted) {
33691
+ return { error: "Tool execution cancelled", errorType: "cancelled" };
33692
+ }
33693
+ let timer;
33694
+ let onAbort;
33648
33695
  try {
33649
- if (!isFinite(timeoutMs)) {
33650
- return { result: await executor(args) };
33696
+ const racers = [];
33697
+ if (signal) {
33698
+ racers.push(
33699
+ new Promise((_, reject) => {
33700
+ onAbort = () => reject(new ToolCancelledError());
33701
+ signal.addEventListener("abort", onAbort, { once: true });
33702
+ })
33703
+ );
33651
33704
  }
33652
- let timer;
33653
- try {
33654
- const result = await Promise.race([
33655
- executor(args),
33705
+ racers.push(Promise.resolve(signal ? executor(args, signal) : executor(args)));
33706
+ if (isFinite(timeoutMs)) {
33707
+ racers.push(
33656
33708
  new Promise((_, reject) => {
33657
33709
  timer = setTimeout(() => reject(new ToolTimeoutError()), timeoutMs);
33658
33710
  })
33659
- ]);
33660
- return { result };
33661
- } finally {
33662
- clearTimeout(timer);
33711
+ );
33663
33712
  }
33713
+ return { result: await Promise.race(racers) };
33664
33714
  } catch (e) {
33715
+ if (e instanceof ToolCancelledError) {
33716
+ return { error: "Tool execution cancelled", errorType: "cancelled" };
33717
+ }
33665
33718
  const message = e instanceof Error ? e.message : String(e);
33666
33719
  return {
33667
33720
  error: `Tool execution failed: ${message}`,
33668
33721
  errorType: e instanceof ToolTimeoutError ? "timeout" : "execution"
33669
33722
  };
33723
+ } finally {
33724
+ clearTimeout(timer);
33725
+ if (onAbort) signal?.removeEventListener("abort", onAbort);
33670
33726
  }
33671
33727
  }
33672
33728
  function toolsToApiFormat(tools, apiType) {
@@ -36022,11 +36078,12 @@ Executing tool: ${toolInfo}
36022
36078
  const blockedByFailure = failedDeps.some((d) => failedNames.has(d));
36023
36079
  const reason = blockedByFailure ? `failed dependencies: ${failedDeps.join(", ")}` : "a dependency cycle";
36024
36080
  const errorMsg = `Tool "${tc.name}" was not executed due to ${reason}`;
36081
+ const skipErrorType = combinedSignal?.aborted ? "cancelled" : "execution";
36025
36082
  executionResults.push({
36026
36083
  id: tc.id,
36027
36084
  name: tc.name,
36028
36085
  error: errorMsg,
36029
- errorType: "execution"
36086
+ errorType: skipErrorType
36030
36087
  });
36031
36088
  await safeAwait(
36032
36089
  () => hooks?.afterToolUse?.({
@@ -36035,7 +36092,7 @@ Executing tool: ${toolInfo}
36035
36092
  toolCallId: tc.id,
36036
36093
  name: tc.name,
36037
36094
  error: errorMsg,
36038
- errorType: "execution"
36095
+ errorType: skipErrorType
36039
36096
  })
36040
36097
  );
36041
36098
  }
@@ -36055,7 +36112,8 @@ Executing tool: ${toolInfo}
36055
36112
  const { result, error, errorType } = await executeToolCall(
36056
36113
  toolCallForExec,
36057
36114
  executorConfig.executor,
36058
- executorConfig.executorTimeout
36115
+ executorConfig.executorTimeout,
36116
+ combinedSignal
36059
36117
  );
36060
36118
  await safeAwait(
36061
36119
  () => hooks?.afterToolUse?.({
@@ -147,7 +147,7 @@ type ToolUseEndEvent = {
147
147
  name: string;
148
148
  result?: unknown;
149
149
  error?: string;
150
- errorType?: "parse" | "timeout" | "execution";
150
+ errorType?: "parse" | "timeout" | "execution" | "cancelled";
151
151
  };
152
152
  type RunStartEvent = {
153
153
  runId: string;
@@ -147,7 +147,7 @@ type ToolUseEndEvent = {
147
147
  name: string;
148
148
  result?: unknown;
149
149
  error?: string;
150
- errorType?: "parse" | "timeout" | "execution";
150
+ errorType?: "parse" | "timeout" | "execution" | "cancelled";
151
151
  };
152
152
  type RunStartEvent = {
153
153
  runId: string;
@@ -515,7 +515,7 @@ function createInteractiveTool(options, config) {
515
515
  description: config.description,
516
516
  arguments: config.parameters
517
517
  },
518
- executor: async (args) => {
518
+ executor: async (args, signal) => {
519
519
  if (config.validate && !config.validate(args)) {
520
520
  return { cancelled: true };
521
521
  }
@@ -525,6 +525,8 @@ function createInteractiveTool(options, config) {
525
525
  }
526
526
  const interactionId = generateInteractionId(config.interactionType);
527
527
  const interactionData = config.mapArgs ? config.mapArgs(args) : args;
528
+ const onAbort = () => context.cancelInteraction?.(interactionId);
529
+ signal?.addEventListener("abort", onAbort, { once: true });
528
530
  try {
529
531
  const result = await context.createInteraction(interactionId, config.interactionType, {
530
532
  ...interactionData,
@@ -536,6 +538,8 @@ function createInteractiveTool(options, config) {
536
538
  return result;
537
539
  } catch {
538
540
  return { cancelled: true };
541
+ } finally {
542
+ signal?.removeEventListener("abort", onAbort);
539
543
  }
540
544
  },
541
545
  // Interactive tools wait for user input and should not be subject
@@ -2,7 +2,7 @@ type LlmapiChatCompletionTool = {
2
2
  [key: string]: unknown;
3
3
  };
4
4
 
5
- type ToolExecutionErrorType = "parse" | "timeout" | "execution";
5
+ type ToolExecutionErrorType = "parse" | "timeout" | "execution" | "cancelled";
6
6
  type ToolExecutionResult = {
7
7
  result?: unknown;
8
8
  error?: string;
@@ -13,7 +13,7 @@ type ToolExecutionResult = {
13
13
  /**
14
14
  * Tool executor function type
15
15
  */
16
- type ToolExecutor = (args: Record<string, unknown>) => Promise<unknown> | unknown;
16
+ type ToolExecutor = (args: Record<string, unknown>, signal?: AbortSignal) => Promise<unknown> | unknown;
17
17
  /**
18
18
  * Tool configuration with optional executor
19
19
  */
@@ -140,6 +140,8 @@ declare function createChatTools(getAccessToken: () => string | null, requestCal
140
140
  */
141
141
  type UIInteractionContext = {
142
142
  createInteraction: (id: string, type: string, data: unknown) => Promise<unknown>;
143
+ /** Rejects and removes a pending interaction. Optional for older contexts. */
144
+ cancelInteraction?: (id: string) => void;
143
145
  createDisplayInteraction: (id: string, displayType: string, data: unknown, result: unknown, toolVersion?: number, replacesInteractionId?: string) => void;
144
146
  };
145
147
  /**
@@ -2,7 +2,7 @@ type LlmapiChatCompletionTool = {
2
2
  [key: string]: unknown;
3
3
  };
4
4
 
5
- type ToolExecutionErrorType = "parse" | "timeout" | "execution";
5
+ type ToolExecutionErrorType = "parse" | "timeout" | "execution" | "cancelled";
6
6
  type ToolExecutionResult = {
7
7
  result?: unknown;
8
8
  error?: string;
@@ -13,7 +13,7 @@ type ToolExecutionResult = {
13
13
  /**
14
14
  * Tool executor function type
15
15
  */
16
- type ToolExecutor = (args: Record<string, unknown>) => Promise<unknown> | unknown;
16
+ type ToolExecutor = (args: Record<string, unknown>, signal?: AbortSignal) => Promise<unknown> | unknown;
17
17
  /**
18
18
  * Tool configuration with optional executor
19
19
  */
@@ -140,6 +140,8 @@ declare function createChatTools(getAccessToken: () => string | null, requestCal
140
140
  */
141
141
  type UIInteractionContext = {
142
142
  createInteraction: (id: string, type: string, data: unknown) => Promise<unknown>;
143
+ /** Rejects and removes a pending interaction. Optional for older contexts. */
144
+ cancelInteraction?: (id: string) => void;
143
145
  createDisplayInteraction: (id: string, displayType: string, data: unknown, result: unknown, toolVersion?: number, replacesInteractionId?: string) => void;
144
146
  };
145
147
  /**
@@ -359,7 +359,7 @@ function createInteractiveTool(options, config) {
359
359
  description: config.description,
360
360
  arguments: config.parameters
361
361
  },
362
- executor: async (args) => {
362
+ executor: async (args, signal) => {
363
363
  if (config.validate && !config.validate(args)) {
364
364
  return { cancelled: true };
365
365
  }
@@ -369,6 +369,8 @@ function createInteractiveTool(options, config) {
369
369
  }
370
370
  const interactionId = generateInteractionId(config.interactionType);
371
371
  const interactionData = config.mapArgs ? config.mapArgs(args) : args;
372
+ const onAbort = () => context.cancelInteraction?.(interactionId);
373
+ signal?.addEventListener("abort", onAbort, { once: true });
372
374
  try {
373
375
  const result = await context.createInteraction(interactionId, config.interactionType, {
374
376
  ...interactionData,
@@ -380,6 +382,8 @@ function createInteractiveTool(options, config) {
380
382
  return result;
381
383
  } catch {
382
384
  return { cancelled: true };
385
+ } finally {
386
+ signal?.removeEventListener("abort", onAbort);
383
387
  }
384
388
  },
385
389
  // Interactive tools wait for user input and should not be subject
@@ -116,7 +116,8 @@ __export(index_exports, {
116
116
  selectServerToolsForPrompt: () => selectServerToolsForPrompt,
117
117
  shouldRefreshTools: () => shouldRefreshTools,
118
118
  stripCoercedMemoryWrite: () => stripCoercedMemoryWrite,
119
- toolSetSystemPrompts: () => toolSetSystemPrompts
119
+ toolSetSystemPrompts: () => toolSetSystemPrompts,
120
+ withActiveToolSetServerTools: () => withActiveToolSetServerTools
120
121
  });
121
122
  module.exports = __toCommonJS(index_exports);
122
123
 
@@ -1993,6 +1994,23 @@ var BUILT_IN_TOOL_SETS = [
1993
1994
  members: ["dropbox_list_folders", "dropbox_get_file_content", "dropbox_search"],
1994
1995
  anchors: ["dropbox_list_folders", "dropbox_search"],
1995
1996
  anchorMinSimilarity: 0.53
1997
+ },
1998
+ {
1999
+ // Server tools, so this set does its work through
2000
+ // withActiveToolSetServerTools: once a restaurant tool has run, terse
2001
+ // follow-ups ("okay", "same as before") keep the booking chain. Each tool
2002
+ // still reaches a fresh booking request on its own description.
2003
+ // Anchors are deliberately empty (like the client's Nearby set): the set
2004
+ // is only for stickiness, not a new way to activate on a prompt.
2005
+ // prompt_user_confirm is left out of members: autoFilterClientTools always
2006
+ // sends it, and as a member any unrelated confirmation would pin this set.
2007
+ name: "restaurant-booking",
2008
+ members: [
2009
+ "AnumaPaymentsMCP-anuma_find_restaurant",
2010
+ "AnumaPaymentsMCP-anuma_check_restaurant_availability",
2011
+ "AnumaPaymentsMCP-anuma_book_restaurant"
2012
+ ],
2013
+ anchors: []
1996
2014
  }
1997
2015
  ];
1998
2016
  function applyToolSets(matchedNames, availableNames, scores, toolSets = BUILT_IN_TOOL_SETS, independentThreshold = 0.65) {
@@ -2055,6 +2073,16 @@ function activatedToolSetNames(scores, toolSets = BUILT_IN_TOOL_SETS, activeSetN
2055
2073
  }
2056
2074
  return activated;
2057
2075
  }
2076
+ function withActiveToolSetServerTools(selected, allServerTools, serverToolsFilter, activeToolSets = [], extraToolSets = []) {
2077
+ if (activeToolSets.length === 0) return selected;
2078
+ const sticky = new Set(
2079
+ [...BUILT_IN_TOOL_SETS, ...extraToolSets].filter((ts) => activeToolSets.includes(ts.name)).flatMap((ts) => ts.members)
2080
+ );
2081
+ for (const name of serverToolsFilter.excludeTools ?? []) sticky.delete(name);
2082
+ for (const tool of selected) sticky.delete(tool.name);
2083
+ const added = allServerTools.filter((tool) => sticky.has(tool.name));
2084
+ return added.length > 0 ? [...selected, ...added] : selected;
2085
+ }
2058
2086
  function toolSetSystemPrompts(selectedToolNames, toolSets = BUILT_IN_TOOL_SETS, activatedSetNames) {
2059
2087
  const selected = selectedToolNames instanceof Set ? selectedToolNames : new Set(selectedToolNames);
2060
2088
  const prompts = [];
@@ -2168,7 +2196,9 @@ async function selectServerToolsForPrompt(options) {
2168
2196
  embeddingModel,
2169
2197
  cacheExpirationMs,
2170
2198
  cache,
2171
- deferLoading
2199
+ deferLoading,
2200
+ activeToolSets,
2201
+ extraToolSets
2172
2202
  } = options;
2173
2203
  if (serverToolsFilter === void 0) return [];
2174
2204
  if (Array.isArray(serverToolsFilter) && serverToolsFilter.length === 0) return [];
@@ -2182,7 +2212,14 @@ async function selectServerToolsForPrompt(options) {
2182
2212
  if (deferLoading?.enabled)
2183
2213
  return resolveDeferredServerTools(allServerTools, serverToolsFilter, deferLoading);
2184
2214
  if (typeof serverToolsFilter === "function") {
2185
- if (prompt.length < MIN_CONTENT_LENGTH_FOR_TOOLS) return [];
2215
+ const withSticky = (selected) => withActiveToolSetServerTools(
2216
+ selected,
2217
+ allServerTools,
2218
+ serverToolsFilter,
2219
+ activeToolSets,
2220
+ extraToolSets
2221
+ );
2222
+ if (prompt.length < MIN_CONTENT_LENGTH_FOR_TOOLS) return withSticky([]);
2186
2223
  let promptEmbedding;
2187
2224
  try {
2188
2225
  promptEmbedding = await generateEmbedding(prompt, {
@@ -2191,10 +2228,10 @@ async function selectServerToolsForPrompt(options) {
2191
2228
  model: embeddingModel
2192
2229
  });
2193
2230
  } catch {
2194
- return [];
2231
+ return withSticky([]);
2195
2232
  }
2196
2233
  const names = serverToolsFilter(promptEmbedding, allServerTools);
2197
- return filterServerTools(allServerTools, names);
2234
+ return withSticky(filterServerTools(allServerTools, names));
2198
2235
  }
2199
2236
  return filterServerTools(allServerTools, serverToolsFilter);
2200
2237
  }
@@ -2836,5 +2873,6 @@ async function selectCouncilClientTools(input, options) {
2836
2873
  selectServerToolsForPrompt,
2837
2874
  shouldRefreshTools,
2838
2875
  stripCoercedMemoryWrite,
2839
- toolSetSystemPrompts
2876
+ toolSetSystemPrompts,
2877
+ withActiveToolSetServerTools
2840
2878
  });
@@ -5,7 +5,7 @@ type LlmapiChatCompletionTool = {
5
5
  /**
6
6
  * Tool executor function type
7
7
  */
8
- type ToolExecutor = (args: Record<string, unknown>) => Promise<unknown> | unknown;
8
+ type ToolExecutor = (args: Record<string, unknown>, signal?: AbortSignal) => Promise<unknown> | unknown;
9
9
  /**
10
10
  * Tool configuration with optional executor
11
11
  */
@@ -505,6 +505,25 @@ declare function expandToolSetsAdditive(matchedNames: Set<string>, availableName
505
505
  * @param activeSetNames - Set names forced active regardless of score.
506
506
  */
507
507
  declare function activatedToolSetNames(scores: ReadonlyMap<string, number>, toolSets?: ToolSet[], activeSetNames?: ReadonlySet<string>): Set<string>;
508
+ /**
509
+ * Add the server-tool members of every set named in `activeToolSets` to a
510
+ * semantic server-tool selection.
511
+ *
512
+ * A semantic filter ranks only the latest prompt, so a terse follow-up inside a
513
+ * flow ("okay", "retry") drops the flow's server tools. This is the server-side
514
+ * half of what `autoFilterClientTools` does for client tools: an active set's
515
+ * members that are in the catalog are kept whatever the prompt scored, even
516
+ * below the short-prompt gate, where `selected` is empty. Exclusions tagged on
517
+ * the filter still win.
518
+ *
519
+ * @param selected - What the semantic filter picked (`[]` when it did not run).
520
+ * @param allServerTools - The full server-tool catalog.
521
+ * @param serverToolsFilter - The filter function, read only for its `excludeTools` tag.
522
+ * @param activeToolSets - Set names that are sticky for this conversation.
523
+ * @param extraToolSets - The caller's sets beyond {@link BUILT_IN_TOOL_SETS}.
524
+ * @returns `selected`, followed by any active-set members it was missing.
525
+ */
526
+ declare function withActiveToolSetServerTools(selected: ServerTool[], allServerTools: ServerTool[], serverToolsFilter: ServerToolsFilterFunction, activeToolSets?: readonly string[], extraToolSets?: readonly ToolSet[]): ServerTool[];
508
527
  /**
509
528
  * Collect the `systemPrompt` of every tool set that activated for a request,
510
529
  * for the caller to APPEND to its base system prompt.
@@ -679,6 +698,20 @@ interface SelectServerToolsForPromptOptions {
679
698
  * {@link resolveDeferredServerTools}). Omit/disabled → today's filtered selection.
680
699
  */
681
700
  deferLoading?: DeferLoadingConfig;
701
+ /**
702
+ * Tool-set names that are sticky for this conversation — the same list you
703
+ * pass to `useChatStorage`'s `activeToolSets`, e.g. from
704
+ * `deriveActiveToolSets`. With a filter function, the server-tool members of
705
+ * these sets are selected whatever the prompt scored, even on a prompt too
706
+ * short to embed. Omit for selection from the prompt alone.
707
+ */
708
+ activeToolSets?: string[];
709
+ /**
710
+ * The caller's sets beyond {@link BUILT_IN_TOOL_SETS} — the same list you pass
711
+ * to `useChatStorage`'s `extraToolSets` — so a custom set named in
712
+ * `activeToolSets` stays sticky here too.
713
+ */
714
+ extraToolSets?: ToolSet[];
682
715
  }
683
716
  /**
684
717
  * Select server-side tools for a prompt using the same path
@@ -1443,4 +1476,4 @@ declare function resolveServerTools(descriptor: ToolIntentDescriptor, catalog: S
1443
1476
  */
1444
1477
  declare function isCoercingIntent(creation: CreationIntent, catalog: ServerToolCatalog): boolean;
1445
1478
 
1446
- export { type AssembledToolsFilterFn, BUILT_IN_TOOL_SETS, CLIENT_TOOLS_MIN_SIMILARITY, CLIENT_TOOLS_RELEVANCE_RATIO, CREATION_INTENT_CLIENT_FACTORIES, CREATION_INTENT_CLIENT_FILTER, CREATION_INTENT_TOOL_SET, type CachedServerTools, type ClientFactoryBuilder, type ClientFactoryKey, type ClientToolsFilterMode, type ConnectorGuidance, type ConnectorGuidanceInput, type CouncilClientSelectionOptions, type CouncilClientToolsInput, type CreateServerToolsFilterOptions, type CreationIntent, DEFAULT_CACHE_EXPIRATION_MS, DEFAULT_EXCLUDED_SERVER_TOOLS, DEFAULT_SERVER_TOOLS_MATCH_OPTIONS, type DeferLoadingConfig, FULL_GENERATIVE_CLIENT_FACTORIES, MAX_CLIENT_TOOLS_AFTER_FILTER, MEMORY_SAVE_TOOL_NAME, MIN_CONTENT_LENGTH_FOR_TOOLS, type ParsedServerToolsResponse, type PostFilterKey, type ResolvePlanContext, SERVER_TOOL_DEPENDENCY_SETS, type SelectServerSideToolsOptions, type SelectServerToolsForPromptOptions, type SelectionLogger, type ServerTool, type ServerToolCatalog, type ServerToolCatalogEntry, type ServerToolsFilter, type ServerToolsFilterContext, type ServerToolsFilterFunction, type ServerToolsOptions, type ServerToolsResponse, TOOL_CATALOG, type ThinkingModeHint, type ToolActivationEvent, type ToolChoice, type ToolConfig, type ToolExecutor, type ToolIntentDescriptor, type ToolLane, type ToolMatchOptions, type ToolMatchResult, type ToolPlanSpec, type ToolSelectionAdapters, type ToolSet, type ToolsCacheBackend, activatedToolSetNames, applyToolSets, assembleClientTools, autoFilterClientTools, buildConnectorGuidance, buildDeniedToolsRider, clearServerToolsCache, composeCouncilClientTools, computeToolGuidance, createServerToolsFilter, defaultServerToolsFilter, deferFormattingConfig, deriveActiveToolSets, expandToolSetsAdditive, filterAssembledClientTools, filterServerTools, findMatchingTools, getCachedServerTools, getCatalogEntry, getMaxToolRounds, getServerTools, getThinkingMode, getToolDescription, getToolName, getToolsChecksum, isCoercingIntent, localStorageToolsCache, mergeActiveToolSets, mergeTools, resolveCouncilPlan, resolveCouncilServerTools, resolveDeferredServerTools, resolvePlan, resolveServerTools, resolveToolChoice, scoreTools, selectCouncilClientTools, selectServerSideTools, selectServerToolsForPrompt, shouldRefreshTools, stripCoercedMemoryWrite, toolSetSystemPrompts };
1479
+ export { type AssembledToolsFilterFn, BUILT_IN_TOOL_SETS, CLIENT_TOOLS_MIN_SIMILARITY, CLIENT_TOOLS_RELEVANCE_RATIO, CREATION_INTENT_CLIENT_FACTORIES, CREATION_INTENT_CLIENT_FILTER, CREATION_INTENT_TOOL_SET, type CachedServerTools, type ClientFactoryBuilder, type ClientFactoryKey, type ClientToolsFilterMode, type ConnectorGuidance, type ConnectorGuidanceInput, type CouncilClientSelectionOptions, type CouncilClientToolsInput, type CreateServerToolsFilterOptions, type CreationIntent, DEFAULT_CACHE_EXPIRATION_MS, DEFAULT_EXCLUDED_SERVER_TOOLS, DEFAULT_SERVER_TOOLS_MATCH_OPTIONS, type DeferLoadingConfig, FULL_GENERATIVE_CLIENT_FACTORIES, MAX_CLIENT_TOOLS_AFTER_FILTER, MEMORY_SAVE_TOOL_NAME, MIN_CONTENT_LENGTH_FOR_TOOLS, type ParsedServerToolsResponse, type PostFilterKey, type ResolvePlanContext, SERVER_TOOL_DEPENDENCY_SETS, type SelectServerSideToolsOptions, type SelectServerToolsForPromptOptions, type SelectionLogger, type ServerTool, type ServerToolCatalog, type ServerToolCatalogEntry, type ServerToolsFilter, type ServerToolsFilterContext, type ServerToolsFilterFunction, type ServerToolsOptions, type ServerToolsResponse, TOOL_CATALOG, type ThinkingModeHint, type ToolActivationEvent, type ToolChoice, type ToolConfig, type ToolExecutor, type ToolIntentDescriptor, type ToolLane, type ToolMatchOptions, type ToolMatchResult, type ToolPlanSpec, type ToolSelectionAdapters, type ToolSet, type ToolsCacheBackend, activatedToolSetNames, applyToolSets, assembleClientTools, autoFilterClientTools, buildConnectorGuidance, buildDeniedToolsRider, clearServerToolsCache, composeCouncilClientTools, computeToolGuidance, createServerToolsFilter, defaultServerToolsFilter, deferFormattingConfig, deriveActiveToolSets, expandToolSetsAdditive, filterAssembledClientTools, filterServerTools, findMatchingTools, getCachedServerTools, getCatalogEntry, getMaxToolRounds, getServerTools, getThinkingMode, getToolDescription, getToolName, getToolsChecksum, isCoercingIntent, localStorageToolsCache, mergeActiveToolSets, mergeTools, resolveCouncilPlan, resolveCouncilServerTools, resolveDeferredServerTools, resolvePlan, resolveServerTools, resolveToolChoice, scoreTools, selectCouncilClientTools, selectServerSideTools, selectServerToolsForPrompt, shouldRefreshTools, stripCoercedMemoryWrite, toolSetSystemPrompts, withActiveToolSetServerTools };
@@ -5,7 +5,7 @@ type LlmapiChatCompletionTool = {
5
5
  /**
6
6
  * Tool executor function type
7
7
  */
8
- type ToolExecutor = (args: Record<string, unknown>) => Promise<unknown> | unknown;
8
+ type ToolExecutor = (args: Record<string, unknown>, signal?: AbortSignal) => Promise<unknown> | unknown;
9
9
  /**
10
10
  * Tool configuration with optional executor
11
11
  */
@@ -505,6 +505,25 @@ declare function expandToolSetsAdditive(matchedNames: Set<string>, availableName
505
505
  * @param activeSetNames - Set names forced active regardless of score.
506
506
  */
507
507
  declare function activatedToolSetNames(scores: ReadonlyMap<string, number>, toolSets?: ToolSet[], activeSetNames?: ReadonlySet<string>): Set<string>;
508
+ /**
509
+ * Add the server-tool members of every set named in `activeToolSets` to a
510
+ * semantic server-tool selection.
511
+ *
512
+ * A semantic filter ranks only the latest prompt, so a terse follow-up inside a
513
+ * flow ("okay", "retry") drops the flow's server tools. This is the server-side
514
+ * half of what `autoFilterClientTools` does for client tools: an active set's
515
+ * members that are in the catalog are kept whatever the prompt scored, even
516
+ * below the short-prompt gate, where `selected` is empty. Exclusions tagged on
517
+ * the filter still win.
518
+ *
519
+ * @param selected - What the semantic filter picked (`[]` when it did not run).
520
+ * @param allServerTools - The full server-tool catalog.
521
+ * @param serverToolsFilter - The filter function, read only for its `excludeTools` tag.
522
+ * @param activeToolSets - Set names that are sticky for this conversation.
523
+ * @param extraToolSets - The caller's sets beyond {@link BUILT_IN_TOOL_SETS}.
524
+ * @returns `selected`, followed by any active-set members it was missing.
525
+ */
526
+ declare function withActiveToolSetServerTools(selected: ServerTool[], allServerTools: ServerTool[], serverToolsFilter: ServerToolsFilterFunction, activeToolSets?: readonly string[], extraToolSets?: readonly ToolSet[]): ServerTool[];
508
527
  /**
509
528
  * Collect the `systemPrompt` of every tool set that activated for a request,
510
529
  * for the caller to APPEND to its base system prompt.
@@ -679,6 +698,20 @@ interface SelectServerToolsForPromptOptions {
679
698
  * {@link resolveDeferredServerTools}). Omit/disabled → today's filtered selection.
680
699
  */
681
700
  deferLoading?: DeferLoadingConfig;
701
+ /**
702
+ * Tool-set names that are sticky for this conversation — the same list you
703
+ * pass to `useChatStorage`'s `activeToolSets`, e.g. from
704
+ * `deriveActiveToolSets`. With a filter function, the server-tool members of
705
+ * these sets are selected whatever the prompt scored, even on a prompt too
706
+ * short to embed. Omit for selection from the prompt alone.
707
+ */
708
+ activeToolSets?: string[];
709
+ /**
710
+ * The caller's sets beyond {@link BUILT_IN_TOOL_SETS} — the same list you pass
711
+ * to `useChatStorage`'s `extraToolSets` — so a custom set named in
712
+ * `activeToolSets` stays sticky here too.
713
+ */
714
+ extraToolSets?: ToolSet[];
682
715
  }
683
716
  /**
684
717
  * Select server-side tools for a prompt using the same path
@@ -1443,4 +1476,4 @@ declare function resolveServerTools(descriptor: ToolIntentDescriptor, catalog: S
1443
1476
  */
1444
1477
  declare function isCoercingIntent(creation: CreationIntent, catalog: ServerToolCatalog): boolean;
1445
1478
 
1446
- export { type AssembledToolsFilterFn, BUILT_IN_TOOL_SETS, CLIENT_TOOLS_MIN_SIMILARITY, CLIENT_TOOLS_RELEVANCE_RATIO, CREATION_INTENT_CLIENT_FACTORIES, CREATION_INTENT_CLIENT_FILTER, CREATION_INTENT_TOOL_SET, type CachedServerTools, type ClientFactoryBuilder, type ClientFactoryKey, type ClientToolsFilterMode, type ConnectorGuidance, type ConnectorGuidanceInput, type CouncilClientSelectionOptions, type CouncilClientToolsInput, type CreateServerToolsFilterOptions, type CreationIntent, DEFAULT_CACHE_EXPIRATION_MS, DEFAULT_EXCLUDED_SERVER_TOOLS, DEFAULT_SERVER_TOOLS_MATCH_OPTIONS, type DeferLoadingConfig, FULL_GENERATIVE_CLIENT_FACTORIES, MAX_CLIENT_TOOLS_AFTER_FILTER, MEMORY_SAVE_TOOL_NAME, MIN_CONTENT_LENGTH_FOR_TOOLS, type ParsedServerToolsResponse, type PostFilterKey, type ResolvePlanContext, SERVER_TOOL_DEPENDENCY_SETS, type SelectServerSideToolsOptions, type SelectServerToolsForPromptOptions, type SelectionLogger, type ServerTool, type ServerToolCatalog, type ServerToolCatalogEntry, type ServerToolsFilter, type ServerToolsFilterContext, type ServerToolsFilterFunction, type ServerToolsOptions, type ServerToolsResponse, TOOL_CATALOG, type ThinkingModeHint, type ToolActivationEvent, type ToolChoice, type ToolConfig, type ToolExecutor, type ToolIntentDescriptor, type ToolLane, type ToolMatchOptions, type ToolMatchResult, type ToolPlanSpec, type ToolSelectionAdapters, type ToolSet, type ToolsCacheBackend, activatedToolSetNames, applyToolSets, assembleClientTools, autoFilterClientTools, buildConnectorGuidance, buildDeniedToolsRider, clearServerToolsCache, composeCouncilClientTools, computeToolGuidance, createServerToolsFilter, defaultServerToolsFilter, deferFormattingConfig, deriveActiveToolSets, expandToolSetsAdditive, filterAssembledClientTools, filterServerTools, findMatchingTools, getCachedServerTools, getCatalogEntry, getMaxToolRounds, getServerTools, getThinkingMode, getToolDescription, getToolName, getToolsChecksum, isCoercingIntent, localStorageToolsCache, mergeActiveToolSets, mergeTools, resolveCouncilPlan, resolveCouncilServerTools, resolveDeferredServerTools, resolvePlan, resolveServerTools, resolveToolChoice, scoreTools, selectCouncilClientTools, selectServerSideTools, selectServerToolsForPrompt, shouldRefreshTools, stripCoercedMemoryWrite, toolSetSystemPrompts };
1479
+ export { type AssembledToolsFilterFn, BUILT_IN_TOOL_SETS, CLIENT_TOOLS_MIN_SIMILARITY, CLIENT_TOOLS_RELEVANCE_RATIO, CREATION_INTENT_CLIENT_FACTORIES, CREATION_INTENT_CLIENT_FILTER, CREATION_INTENT_TOOL_SET, type CachedServerTools, type ClientFactoryBuilder, type ClientFactoryKey, type ClientToolsFilterMode, type ConnectorGuidance, type ConnectorGuidanceInput, type CouncilClientSelectionOptions, type CouncilClientToolsInput, type CreateServerToolsFilterOptions, type CreationIntent, DEFAULT_CACHE_EXPIRATION_MS, DEFAULT_EXCLUDED_SERVER_TOOLS, DEFAULT_SERVER_TOOLS_MATCH_OPTIONS, type DeferLoadingConfig, FULL_GENERATIVE_CLIENT_FACTORIES, MAX_CLIENT_TOOLS_AFTER_FILTER, MEMORY_SAVE_TOOL_NAME, MIN_CONTENT_LENGTH_FOR_TOOLS, type ParsedServerToolsResponse, type PostFilterKey, type ResolvePlanContext, SERVER_TOOL_DEPENDENCY_SETS, type SelectServerSideToolsOptions, type SelectServerToolsForPromptOptions, type SelectionLogger, type ServerTool, type ServerToolCatalog, type ServerToolCatalogEntry, type ServerToolsFilter, type ServerToolsFilterContext, type ServerToolsFilterFunction, type ServerToolsOptions, type ServerToolsResponse, TOOL_CATALOG, type ThinkingModeHint, type ToolActivationEvent, type ToolChoice, type ToolConfig, type ToolExecutor, type ToolIntentDescriptor, type ToolLane, type ToolMatchOptions, type ToolMatchResult, type ToolPlanSpec, type ToolSelectionAdapters, type ToolSet, type ToolsCacheBackend, activatedToolSetNames, applyToolSets, assembleClientTools, autoFilterClientTools, buildConnectorGuidance, buildDeniedToolsRider, clearServerToolsCache, composeCouncilClientTools, computeToolGuidance, createServerToolsFilter, defaultServerToolsFilter, deferFormattingConfig, deriveActiveToolSets, expandToolSetsAdditive, filterAssembledClientTools, filterServerTools, findMatchingTools, getCachedServerTools, getCatalogEntry, getMaxToolRounds, getServerTools, getThinkingMode, getToolDescription, getToolName, getToolsChecksum, isCoercingIntent, localStorageToolsCache, mergeActiveToolSets, mergeTools, resolveCouncilPlan, resolveCouncilServerTools, resolveDeferredServerTools, resolvePlan, resolveServerTools, resolveToolChoice, scoreTools, selectCouncilClientTools, selectServerSideTools, selectServerToolsForPrompt, shouldRefreshTools, stripCoercedMemoryWrite, toolSetSystemPrompts, withActiveToolSetServerTools };
@@ -1872,6 +1872,23 @@ var BUILT_IN_TOOL_SETS = [
1872
1872
  members: ["dropbox_list_folders", "dropbox_get_file_content", "dropbox_search"],
1873
1873
  anchors: ["dropbox_list_folders", "dropbox_search"],
1874
1874
  anchorMinSimilarity: 0.53
1875
+ },
1876
+ {
1877
+ // Server tools, so this set does its work through
1878
+ // withActiveToolSetServerTools: once a restaurant tool has run, terse
1879
+ // follow-ups ("okay", "same as before") keep the booking chain. Each tool
1880
+ // still reaches a fresh booking request on its own description.
1881
+ // Anchors are deliberately empty (like the client's Nearby set): the set
1882
+ // is only for stickiness, not a new way to activate on a prompt.
1883
+ // prompt_user_confirm is left out of members: autoFilterClientTools always
1884
+ // sends it, and as a member any unrelated confirmation would pin this set.
1885
+ name: "restaurant-booking",
1886
+ members: [
1887
+ "AnumaPaymentsMCP-anuma_find_restaurant",
1888
+ "AnumaPaymentsMCP-anuma_check_restaurant_availability",
1889
+ "AnumaPaymentsMCP-anuma_book_restaurant"
1890
+ ],
1891
+ anchors: []
1875
1892
  }
1876
1893
  ];
1877
1894
  function applyToolSets(matchedNames, availableNames, scores, toolSets = BUILT_IN_TOOL_SETS, independentThreshold = 0.65) {
@@ -1934,6 +1951,16 @@ function activatedToolSetNames(scores, toolSets = BUILT_IN_TOOL_SETS, activeSetN
1934
1951
  }
1935
1952
  return activated;
1936
1953
  }
1954
+ function withActiveToolSetServerTools(selected, allServerTools, serverToolsFilter, activeToolSets = [], extraToolSets = []) {
1955
+ if (activeToolSets.length === 0) return selected;
1956
+ const sticky = new Set(
1957
+ [...BUILT_IN_TOOL_SETS, ...extraToolSets].filter((ts) => activeToolSets.includes(ts.name)).flatMap((ts) => ts.members)
1958
+ );
1959
+ for (const name of serverToolsFilter.excludeTools ?? []) sticky.delete(name);
1960
+ for (const tool of selected) sticky.delete(tool.name);
1961
+ const added = allServerTools.filter((tool) => sticky.has(tool.name));
1962
+ return added.length > 0 ? [...selected, ...added] : selected;
1963
+ }
1937
1964
  function toolSetSystemPrompts(selectedToolNames, toolSets = BUILT_IN_TOOL_SETS, activatedSetNames) {
1938
1965
  const selected = selectedToolNames instanceof Set ? selectedToolNames : new Set(selectedToolNames);
1939
1966
  const prompts = [];
@@ -2047,7 +2074,9 @@ async function selectServerToolsForPrompt(options) {
2047
2074
  embeddingModel,
2048
2075
  cacheExpirationMs,
2049
2076
  cache,
2050
- deferLoading
2077
+ deferLoading,
2078
+ activeToolSets,
2079
+ extraToolSets
2051
2080
  } = options;
2052
2081
  if (serverToolsFilter === void 0) return [];
2053
2082
  if (Array.isArray(serverToolsFilter) && serverToolsFilter.length === 0) return [];
@@ -2061,7 +2090,14 @@ async function selectServerToolsForPrompt(options) {
2061
2090
  if (deferLoading?.enabled)
2062
2091
  return resolveDeferredServerTools(allServerTools, serverToolsFilter, deferLoading);
2063
2092
  if (typeof serverToolsFilter === "function") {
2064
- if (prompt.length < MIN_CONTENT_LENGTH_FOR_TOOLS) return [];
2093
+ const withSticky = (selected) => withActiveToolSetServerTools(
2094
+ selected,
2095
+ allServerTools,
2096
+ serverToolsFilter,
2097
+ activeToolSets,
2098
+ extraToolSets
2099
+ );
2100
+ if (prompt.length < MIN_CONTENT_LENGTH_FOR_TOOLS) return withSticky([]);
2065
2101
  let promptEmbedding;
2066
2102
  try {
2067
2103
  promptEmbedding = await generateEmbedding(prompt, {
@@ -2070,10 +2106,10 @@ async function selectServerToolsForPrompt(options) {
2070
2106
  model: embeddingModel
2071
2107
  });
2072
2108
  } catch {
2073
- return [];
2109
+ return withSticky([]);
2074
2110
  }
2075
2111
  const names = serverToolsFilter(promptEmbedding, allServerTools);
2076
- return filterServerTools(allServerTools, names);
2112
+ return withSticky(filterServerTools(allServerTools, names));
2077
2113
  }
2078
2114
  return filterServerTools(allServerTools, serverToolsFilter);
2079
2115
  }
@@ -2714,5 +2750,6 @@ export {
2714
2750
  selectServerToolsForPrompt,
2715
2751
  shouldRefreshTools,
2716
2752
  stripCoercedMemoryWrite,
2717
- toolSetSystemPrompts
2753
+ toolSetSystemPrompts,
2754
+ withActiveToolSetServerTools
2718
2755
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anuma/sdk",
3
- "version": "6.27.8",
3
+ "version": "6.28.0",
4
4
  "description": "",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.mjs",