@anuma/sdk 6.12.0 → 6.12.1

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.
@@ -272,7 +272,63 @@ interface DeferLoadingConfig {
272
272
  enabled: boolean;
273
273
  /** Server-tool names to keep non-deferred (besides the tool-search tool), in priority order. */
274
274
  hotToolNames: readonly string[];
275
+ /**
276
+ * Server-tool names to drop entirely while defer-loading is on.
277
+ *
278
+ * Defer widens the per-turn selection to the whole catalog, which also bypasses the `excludeTools`
279
+ * baked into a caller's semantic filter. A filter built by {@link createServerToolsFilter} tags itself
280
+ * with its own exclusions and those are honoured automatically — so most callers need nothing here.
281
+ *
282
+ * Set this when the filter's tag can't be seen: a hand-written filter, a filter wrapped in a plain
283
+ * closure (the wrapper drops the tag), or a static-array `serverToolsFilter`. Anything excluded
284
+ * UNCONDITIONALLY (a tool the app replaces with its own UI, a capability the model already has
285
+ * natively) belongs in one of the two places, or defer quietly hands it back to the model.
286
+ *
287
+ * This list is UNIONED with the filter's own tag, never a replacement for it — so adding one name
288
+ * here cannot re-admit the tools the filter already excludes.
289
+ */
290
+ excludeTools?: readonly string[];
275
291
  }
292
+ /**
293
+ * The server-tool set defer-loading should format for one turn.
294
+ *
295
+ * Defer changes how tools are SENT (full definitions + `defer_loading` + a tool-search tool, for a
296
+ * byte-stable cacheable prefix). It must not change WHICH tools the caller allowed, so two things
297
+ * survive that a plain "just use the whole catalog" discards:
298
+ *
299
+ * 1. **an explicit static array** — `serverToolsFilter: ['x']` is a deliberate scoping, and callers
300
+ * commonly pair it with `tool_choice:'required'`. Replacing it with the catalog turns "you must
301
+ * call x" into "you must call something, here is everything". Defer still applies, within the array.
302
+ * 2. **unconditional exclusions** — see {@link DeferLoadingConfig.excludeTools}.
303
+ *
304
+ * A filter FUNCTION is deliberately NOT consulted: it is per-prompt semantic narrowing, and skipping it
305
+ * is the whole point of defer (the model reaches everything else through tool-search). Only the
306
+ * caller's unconditional constraints survive.
307
+ */
308
+ declare function resolveDeferredServerTools(allServerTools: ServerTool[], serverToolsFilter: readonly string[] | ServerToolsFilterFunction | undefined, config: DeferLoadingConfig): ServerTool[];
309
+ /**
310
+ * The defer config {@link mergeTools} should FORMAT this request with — `undefined` when defer
311
+ * formatting must be skipped even though defer-loading is enabled.
312
+ *
313
+ * Scoping the selection to a caller's explicit static array (see {@link resolveDeferredServerTools})
314
+ * is only half the job. `formatServerToolsWithDefer` still marks every non-hot tool `defer_loading`
315
+ * and prepends the tool-search tool, so for a one-tool array whose tool isn't hot — every creation
316
+ * mode: video, music, sfx, image, slides — the search tool becomes the ONLY directly callable entry
317
+ * in the request. Callers pair those arrays with `tool_choice:'required'`, so "you must call the video
318
+ * generator" silently degrades to "you must call tool-search", and a caller scanning tool-call events
319
+ * for the generator's name never sees it.
320
+ *
321
+ * An explicit array is a closed set the caller already narrowed: there is nothing left to discover, so
322
+ * defer has no work to do and its formatting is pure downside. Sending those tools normally is exactly
323
+ * today's (defer-off) behavior for that request.
324
+ *
325
+ * Note this is NOT the same as treating the array as `hotToolNames`: hot tools are non-deferred, but
326
+ * `formatServerToolsWithDefer` prepends the tool-search tool unconditionally, so a `required` turn
327
+ * could still satisfy the constraint by calling it. Skipping the formatting is what actually fixes it.
328
+ *
329
+ * The catalog path (a filter function, or no filter) is untouched — full tool-search + hot + deferred.
330
+ */
331
+ declare function deferFormattingConfig(serverToolsFilter: readonly string[] | ServerToolsFilterFunction | undefined, config: DeferLoadingConfig | undefined): DeferLoadingConfig | undefined;
276
332
  declare function mergeTools(serverTools: ServerTool[], clientTools: Array<LlmapiChatCompletionTool | ToolConfig> | undefined, apiType?: "responses" | "completions", deferConfig?: DeferLoadingConfig): Array<Record<string, unknown>>;
277
333
  /**
278
334
  * Result of tool matching with similarity score
@@ -509,7 +565,7 @@ interface CreateServerToolsFilterOptions {
509
565
  * });
510
566
  * ```
511
567
  */
512
- declare function createServerToolsFilter(options?: CreateServerToolsFilterOptions): (embeddings: number[] | number[][], tools: ServerTool[]) => string[];
568
+ declare function createServerToolsFilter(options?: CreateServerToolsFilterOptions): ServerToolsFilterFunction;
513
569
  /**
514
570
  * Default exclusions baked into `defaultServerToolsFilter`.
515
571
  *
@@ -575,13 +631,21 @@ declare const SERVER_TOOL_DEPENDENCY_SETS: ToolSet[];
575
631
  * If you need to customize (extra excludes, different limits, opt into
576
632
  * tool-set expansion), call `createServerToolsFilter` directly.
577
633
  */
578
- declare const defaultServerToolsFilter: (embeddings: number[] | number[][], tools: ServerTool[]) => string[];
634
+ declare const defaultServerToolsFilter: ServerToolsFilterFunction;
579
635
  /**
580
636
  * Type for a server-tools filter — a function that takes prompt embeddings
581
637
  * and the full server tool catalog and returns the names of tools to keep.
582
638
  * Matches `useChatStorage`'s `serverTools` callback signature.
583
639
  */
584
- type ServerToolsFilterFunction = (embeddings: number[] | number[][], tools: ServerTool[]) => string[];
640
+ type ServerToolsFilterFunction = ((embeddings: number[] | number[][], tools: ServerTool[]) => string[]) & {
641
+ /**
642
+ * The unconditional exclusions this filter applies, exposed by
643
+ * {@link createServerToolsFilter} so defer-loading can honour them without the caller
644
+ * repeating the list — see {@link resolveDeferredServerTools}. Absent on a hand-written
645
+ * filter, or on one wrapped in a plain closure.
646
+ */
647
+ readonly excludeTools?: readonly string[];
648
+ };
585
649
  /**
586
650
  * Options for `selectServerToolsForPrompt`.
587
651
  */
@@ -609,9 +673,10 @@ interface SelectServerToolsForPromptOptions {
609
673
  */
610
674
  cache?: ToolsCacheBackend;
611
675
  /**
612
- * Phase 3 defer-loading. When `enabled`, this helper returns the FULL catalog (skipping semantic/
613
- * static filtering) to mirror useChatStorage's responses send path, which swaps in the full catalog
614
- * for mergeTools + tool-search. Omit/disabled → today's filtered selection.
676
+ * Phase 3 defer-loading. When `enabled`, this helper skips SEMANTIC filtering to mirror
677
+ * useChatStorage's responses send path, which hands the catalog to mergeTools + tool-search. The
678
+ * caller's unconditional constraints still apply — an explicit static array, and exclusions (see
679
+ * {@link resolveDeferredServerTools}). Omit/disabled → today's filtered selection.
615
680
  */
616
681
  deferLoading?: DeferLoadingConfig;
617
682
  }
@@ -1377,4 +1442,4 @@ declare function resolveServerTools(descriptor: ToolIntentDescriptor, catalog: S
1377
1442
  */
1378
1443
  declare function isCoercingIntent(creation: CreationIntent, catalog: ServerToolCatalog): boolean;
1379
1444
 
1380
- 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, deriveActiveToolSets, expandToolSetsAdditive, filterAssembledClientTools, filterServerTools, findMatchingTools, getCachedServerTools, getCatalogEntry, getMaxToolRounds, getServerTools, getThinkingMode, getToolDescription, getToolName, getToolsChecksum, isCoercingIntent, localStorageToolsCache, mergeActiveToolSets, mergeTools, resolveCouncilPlan, resolveCouncilServerTools, resolvePlan, resolveServerTools, resolveToolChoice, scoreTools, selectCouncilClientTools, selectServerSideTools, selectServerToolsForPrompt, shouldRefreshTools, stripCoercedMemoryWrite, toolSetSystemPrompts };
1445
+ 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 };
@@ -1539,6 +1539,20 @@ function clientToolToCompletionsFormat(tool) {
1539
1539
  }
1540
1540
  var TOOL_SEARCH_TOOL_TYPE = "tool_search_tool_regex_20251119";
1541
1541
  var TOOL_SEARCH_TOOL_NAME = "tool_search_tool_regex";
1542
+ function resolveDeferredServerTools(allServerTools, serverToolsFilter, config) {
1543
+ const allowed = serverToolsFilter === void 0 || typeof serverToolsFilter === "function" ? allServerTools : filterServerTools(allServerTools, [...serverToolsFilter]);
1544
+ const excluded = new Set(config.excludeTools ?? []);
1545
+ if (typeof serverToolsFilter === "function") {
1546
+ for (const name of serverToolsFilter.excludeTools ?? []) excluded.add(name);
1547
+ }
1548
+ if (excluded.size === 0) return allowed;
1549
+ return allowed.filter((tool) => !excluded.has(tool.name));
1550
+ }
1551
+ function deferFormattingConfig(serverToolsFilter, config) {
1552
+ if (!config?.enabled) return config;
1553
+ const isExplicitList = serverToolsFilter !== void 0 && typeof serverToolsFilter !== "function";
1554
+ return isExplicitList ? void 0 : config;
1555
+ }
1542
1556
  function byNameAscending(a, b) {
1543
1557
  if (a.name < b.name) return -1;
1544
1558
  if (a.name > b.name) return 1;
@@ -1894,7 +1908,7 @@ function createServerToolsFilter(options = {}) {
1894
1908
  const exclude = new Set(options.excludeTools ?? []);
1895
1909
  const sets = options.toolSets ?? [];
1896
1910
  const matchOpts = options.matchOptions;
1897
- return (embeddings, tools) => {
1911
+ const filter = (embeddings, tools) => {
1898
1912
  const matches = findMatchingTools(embeddings, tools, matchOpts);
1899
1913
  if (matches.length === 0) return [];
1900
1914
  const matchedNames = new Set(matches.map((m) => m.tool.name));
@@ -1912,6 +1926,10 @@ function createServerToolsFilter(options = {}) {
1912
1926
  for (const name of exclude) finalNames.delete(name);
1913
1927
  return [...finalNames];
1914
1928
  };
1929
+ return Object.defineProperty(filter, "excludeTools", {
1930
+ value: Object.freeze([...exclude]),
1931
+ enumerable: false
1932
+ });
1915
1933
  }
1916
1934
  var DEFAULT_EXCLUDED_SERVER_TOOLS = [
1917
1935
  "AnumaVisionMCP-anuma_analyze_image",
@@ -1993,7 +2011,8 @@ async function selectServerToolsForPrompt(options) {
1993
2011
  return [];
1994
2012
  }
1995
2013
  if (allServerTools.length === 0) return [];
1996
- if (deferLoading?.enabled) return allServerTools;
2014
+ if (deferLoading?.enabled)
2015
+ return resolveDeferredServerTools(allServerTools, serverToolsFilter, deferLoading);
1997
2016
  if (typeof serverToolsFilter === "function") {
1998
2017
  if (prompt.length < MIN_CONTENT_LENGTH_FOR_TOOLS) return [];
1999
2018
  let promptEmbedding;
@@ -2618,6 +2637,7 @@ export {
2618
2637
  computeToolGuidance,
2619
2638
  createServerToolsFilter,
2620
2639
  defaultServerToolsFilter,
2640
+ deferFormattingConfig,
2621
2641
  deriveActiveToolSets,
2622
2642
  expandToolSetsAdditive,
2623
2643
  filterAssembledClientTools,
@@ -2637,6 +2657,7 @@ export {
2637
2657
  mergeTools,
2638
2658
  resolveCouncilPlan,
2639
2659
  resolveCouncilServerTools,
2660
+ resolveDeferredServerTools,
2640
2661
  resolvePlan,
2641
2662
  resolveServerTools,
2642
2663
  resolveToolChoice,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anuma/sdk",
3
- "version": "6.12.0",
3
+ "version": "6.12.1",
4
4
  "description": "",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.mjs",