@anuma/sdk 6.12.0 → 6.13.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.
@@ -11499,6 +11499,20 @@ function clientToolToCompletionsFormat(tool) {
11499
11499
  }
11500
11500
  var TOOL_SEARCH_TOOL_TYPE = "tool_search_tool_regex_20251119";
11501
11501
  var TOOL_SEARCH_TOOL_NAME = "tool_search_tool_regex";
11502
+ function resolveDeferredServerTools(allServerTools, serverToolsFilter, config) {
11503
+ const allowed = serverToolsFilter === void 0 || typeof serverToolsFilter === "function" ? allServerTools : filterServerTools(allServerTools, [...serverToolsFilter]);
11504
+ const excluded = new Set(config.excludeTools ?? []);
11505
+ if (typeof serverToolsFilter === "function") {
11506
+ for (const name of serverToolsFilter.excludeTools ?? []) excluded.add(name);
11507
+ }
11508
+ if (excluded.size === 0) return allowed;
11509
+ return allowed.filter((tool) => !excluded.has(tool.name));
11510
+ }
11511
+ function deferFormattingConfig(serverToolsFilter, config) {
11512
+ if (!config?.enabled) return config;
11513
+ const isExplicitList = serverToolsFilter !== void 0 && typeof serverToolsFilter !== "function";
11514
+ return isExplicitList ? void 0 : config;
11515
+ }
11502
11516
  function byNameAscending(a, b) {
11503
11517
  if (a.name < b.name) return -1;
11504
11518
  if (a.name > b.name) return 1;
@@ -11825,7 +11839,7 @@ function createServerToolsFilter(options = {}) {
11825
11839
  const exclude = new Set(options.excludeTools ?? []);
11826
11840
  const sets = options.toolSets ?? [];
11827
11841
  const matchOpts = options.matchOptions;
11828
- return (embeddings, tools) => {
11842
+ const filter = (embeddings, tools) => {
11829
11843
  const matches = findMatchingTools(embeddings, tools, matchOpts);
11830
11844
  if (matches.length === 0) return [];
11831
11845
  const matchedNames = new Set(matches.map((m) => m.tool.name));
@@ -11843,6 +11857,10 @@ function createServerToolsFilter(options = {}) {
11843
11857
  for (const name of exclude) finalNames.delete(name);
11844
11858
  return [...finalNames];
11845
11859
  };
11860
+ return Object.defineProperty(filter, "excludeTools", {
11861
+ value: Object.freeze([...exclude]),
11862
+ enumerable: false
11863
+ });
11846
11864
  }
11847
11865
  var DEFAULT_EXCLUDED_SERVER_TOOLS = [
11848
11866
  "AnumaVisionMCP-anuma_analyze_image",
@@ -11924,7 +11942,8 @@ async function selectServerToolsForPrompt(options) {
11924
11942
  return [];
11925
11943
  }
11926
11944
  if (allServerTools.length === 0) return [];
11927
- if (deferLoading?.enabled) return allServerTools;
11945
+ if (deferLoading?.enabled)
11946
+ return resolveDeferredServerTools(allServerTools, serverToolsFilter, deferLoading);
11928
11947
  if (typeof serverToolsFilter === "function") {
11929
11948
  if (prompt.length < MIN_CONTENT_LENGTH_FOR_TOOLS) return [];
11930
11949
  let promptEmbedding;
@@ -12351,7 +12370,8 @@ async function previewToolSelection(options) {
12351
12370
  cache: serverToolsConfig?.cache
12352
12371
  });
12353
12372
  const allow = new Set(serverToolsFilter);
12354
- gatedServerNames = allServerTools.filter((t) => allow.has(t.name)).map((t) => t.name);
12373
+ const gated = allServerTools.filter((t) => allow.has(t.name));
12374
+ gatedServerNames = (serverToolsConfig?.deferLoading?.enabled ? resolveDeferredServerTools(gated, serverToolsFilter, serverToolsConfig.deferLoading) : gated).map((t) => t.name);
12355
12375
  } catch {
12356
12376
  }
12357
12377
  }
@@ -12400,7 +12420,11 @@ async function previewToolSelection(options) {
12400
12420
  cache: serverToolsConfig?.cache
12401
12421
  });
12402
12422
  if (serverToolsConfig?.deferLoading?.enabled) {
12403
- serverToolNames = allServerTools.map((t) => t.name);
12423
+ serverToolNames = resolveDeferredServerTools(
12424
+ allServerTools,
12425
+ serverToolsFilter,
12426
+ serverToolsConfig.deferLoading
12427
+ ).map((t) => t.name);
12404
12428
  } else if (typeof serverToolsFilter === "function") {
12405
12429
  serverToolNames = serverToolsFilter(promptEmbedding, allServerTools);
12406
12430
  } else {
@@ -13416,7 +13440,11 @@ function useChatStorage(options) {
13416
13440
  cache: serverToolsConfig?.cache
13417
13441
  });
13418
13442
  if (serverToolsConfig?.deferLoading?.enabled) {
13419
- filteredServerTools2 = allServerTools;
13443
+ filteredServerTools2 = resolveDeferredServerTools(
13444
+ allServerTools,
13445
+ serverToolsFilter,
13446
+ serverToolsConfig.deferLoading
13447
+ );
13420
13448
  } else if (isServerToolsFunction2) {
13421
13449
  if (skipStorageEmbeddings) {
13422
13450
  const toolNames = serverToolsFilter(skipStorageEmbeddings, allServerTools);
@@ -13457,7 +13485,7 @@ function useChatStorage(options) {
13457
13485
  filteredServerTools2,
13458
13486
  filteredClientTools2,
13459
13487
  effectiveApiType2,
13460
- serverToolsConfig?.deferLoading
13488
+ deferFormattingConfig(serverToolsFilter, serverToolsConfig?.deferLoading)
13461
13489
  );
13462
13490
  }
13463
13491
  if (onToolSelection) {
@@ -13816,7 +13844,11 @@ function useChatStorage(options) {
13816
13844
  if (allServerTools) {
13817
13845
  try {
13818
13846
  if (serverToolsConfig?.deferLoading?.enabled && effectiveApiType === "responses") {
13819
- filteredServerTools = allServerTools;
13847
+ filteredServerTools = resolveDeferredServerTools(
13848
+ allServerTools,
13849
+ serverToolsFilter,
13850
+ serverToolsConfig.deferLoading
13851
+ );
13820
13852
  } else if (isServerToolsFunction) {
13821
13853
  if (userMessageEmbeddings) {
13822
13854
  const toolNames = serverToolsFilter(userMessageEmbeddings, allServerTools);
@@ -13896,7 +13928,7 @@ function useChatStorage(options) {
13896
13928
  filteredServerTools,
13897
13929
  filteredClientTools,
13898
13930
  effectiveApiType,
13899
- serverToolsConfig?.deferLoading
13931
+ deferFormattingConfig(serverToolsFilter, serverToolsConfig?.deferLoading)
13900
13932
  );
13901
13933
  }
13902
13934
  if (onToolSelection) {
@@ -32068,6 +32068,15 @@ function filterServerTools(serverTools, includeNames) {
32068
32068
  const includeSet = new Set(includeNames);
32069
32069
  return serverTools.filter((tool) => includeSet.has(tool.name));
32070
32070
  }
32071
+ function resolveDeferredServerTools(allServerTools, serverToolsFilter, config) {
32072
+ const allowed = serverToolsFilter === void 0 || typeof serverToolsFilter === "function" ? allServerTools : filterServerTools(allServerTools, [...serverToolsFilter]);
32073
+ const excluded = new Set(config.excludeTools ?? []);
32074
+ if (typeof serverToolsFilter === "function") {
32075
+ for (const name of serverToolsFilter.excludeTools ?? []) excluded.add(name);
32076
+ }
32077
+ if (excluded.size === 0) return allowed;
32078
+ return allowed.filter((tool) => !excluded.has(tool.name));
32079
+ }
32071
32080
  var DEFAULT_TOOL_MATCH_OPTIONS = {
32072
32081
  limit: 5,
32073
32082
  minSimilarity: 0.3,
@@ -32344,7 +32353,7 @@ function createServerToolsFilter(options = {}) {
32344
32353
  const exclude = new Set(options.excludeTools ?? []);
32345
32354
  const sets = options.toolSets ?? [];
32346
32355
  const matchOpts = options.matchOptions;
32347
- return (embeddings, tools) => {
32356
+ const filter = (embeddings, tools) => {
32348
32357
  const matches = findMatchingTools(embeddings, tools, matchOpts);
32349
32358
  if (matches.length === 0) return [];
32350
32359
  const matchedNames = new Set(matches.map((m) => m.tool.name));
@@ -32362,6 +32371,10 @@ function createServerToolsFilter(options = {}) {
32362
32371
  for (const name of exclude) finalNames.delete(name);
32363
32372
  return [...finalNames];
32364
32373
  };
32374
+ return Object.defineProperty(filter, "excludeTools", {
32375
+ value: Object.freeze([...exclude]),
32376
+ enumerable: false
32377
+ });
32365
32378
  }
32366
32379
  var DEFAULT_EXCLUDED_SERVER_TOOLS = [
32367
32380
  "AnumaVisionMCP-anuma_analyze_image",
@@ -32443,7 +32456,8 @@ async function selectServerToolsForPrompt(options) {
32443
32456
  return [];
32444
32457
  }
32445
32458
  if (allServerTools.length === 0) return [];
32446
- if (deferLoading?.enabled) return allServerTools;
32459
+ if (deferLoading?.enabled)
32460
+ return resolveDeferredServerTools(allServerTools, serverToolsFilter, deferLoading);
32447
32461
  if (typeof serverToolsFilter === "function") {
32448
32462
  if (prompt.length < MIN_CONTENT_LENGTH_FOR_TOOLS) return [];
32449
32463
  let promptEmbedding;
@@ -3013,6 +3013,22 @@ interface DeferLoadingConfig {
3013
3013
  enabled: boolean;
3014
3014
  /** Server-tool names to keep non-deferred (besides the tool-search tool), in priority order. */
3015
3015
  hotToolNames: readonly string[];
3016
+ /**
3017
+ * Server-tool names to drop entirely while defer-loading is on.
3018
+ *
3019
+ * Defer widens the per-turn selection to the whole catalog, which also bypasses the `excludeTools`
3020
+ * baked into a caller's semantic filter. A filter built by {@link createServerToolsFilter} tags itself
3021
+ * with its own exclusions and those are honoured automatically — so most callers need nothing here.
3022
+ *
3023
+ * Set this when the filter's tag can't be seen: a hand-written filter, a filter wrapped in a plain
3024
+ * closure (the wrapper drops the tag), or a static-array `serverToolsFilter`. Anything excluded
3025
+ * UNCONDITIONALLY (a tool the app replaces with its own UI, a capability the model already has
3026
+ * natively) belongs in one of the two places, or defer quietly hands it back to the model.
3027
+ *
3028
+ * This list is UNIONED with the filter's own tag, never a replacement for it — so adding one name
3029
+ * here cannot re-admit the tools the filter already excludes.
3030
+ */
3031
+ excludeTools?: readonly string[];
3016
3032
  }
3017
3033
  /**
3018
3034
  * Result of tool matching with similarity score
@@ -3192,7 +3208,7 @@ interface CreateServerToolsFilterOptions {
3192
3208
  * });
3193
3209
  * ```
3194
3210
  */
3195
- declare function createServerToolsFilter(options?: CreateServerToolsFilterOptions): (embeddings: number[] | number[][], tools: ServerTool[]) => string[];
3211
+ declare function createServerToolsFilter(options?: CreateServerToolsFilterOptions): ServerToolsFilterFunction;
3196
3212
  /**
3197
3213
  * Default exclusions baked into `defaultServerToolsFilter`.
3198
3214
  *
@@ -3258,13 +3274,21 @@ declare const SERVER_TOOL_DEPENDENCY_SETS: ToolSet[];
3258
3274
  * If you need to customize (extra excludes, different limits, opt into
3259
3275
  * tool-set expansion), call `createServerToolsFilter` directly.
3260
3276
  */
3261
- declare const defaultServerToolsFilter: (embeddings: number[] | number[][], tools: ServerTool[]) => string[];
3277
+ declare const defaultServerToolsFilter: ServerToolsFilterFunction;
3262
3278
  /**
3263
3279
  * Type for a server-tools filter — a function that takes prompt embeddings
3264
3280
  * and the full server tool catalog and returns the names of tools to keep.
3265
3281
  * Matches `useChatStorage`'s `serverTools` callback signature.
3266
3282
  */
3267
- type ServerToolsFilterFunction = (embeddings: number[] | number[][], tools: ServerTool[]) => string[];
3283
+ type ServerToolsFilterFunction = ((embeddings: number[] | number[][], tools: ServerTool[]) => string[]) & {
3284
+ /**
3285
+ * The unconditional exclusions this filter applies, exposed by
3286
+ * {@link createServerToolsFilter} so defer-loading can honour them without the caller
3287
+ * repeating the list — see {@link resolveDeferredServerTools}. Absent on a hand-written
3288
+ * filter, or on one wrapped in a plain closure.
3289
+ */
3290
+ readonly excludeTools?: readonly string[];
3291
+ };
3268
3292
  /**
3269
3293
  * Options for `selectServerToolsForPrompt`.
3270
3294
  */
@@ -3292,9 +3316,10 @@ interface SelectServerToolsForPromptOptions {
3292
3316
  */
3293
3317
  cache?: ToolsCacheBackend;
3294
3318
  /**
3295
- * Phase 3 defer-loading. When `enabled`, this helper returns the FULL catalog (skipping semantic/
3296
- * static filtering) to mirror useChatStorage's responses send path, which swaps in the full catalog
3297
- * for mergeTools + tool-search. Omit/disabled → today's filtered selection.
3319
+ * Phase 3 defer-loading. When `enabled`, this helper skips SEMANTIC filtering to mirror
3320
+ * useChatStorage's responses send path, which hands the catalog to mergeTools + tool-search. The
3321
+ * caller's unconditional constraints still apply — an explicit static array, and exclusions (see
3322
+ * {@link resolveDeferredServerTools}). Omit/disabled → today's filtered selection.
3298
3323
  */
3299
3324
  deferLoading?: DeferLoadingConfig;
3300
3325
  }
@@ -3013,6 +3013,22 @@ interface DeferLoadingConfig {
3013
3013
  enabled: boolean;
3014
3014
  /** Server-tool names to keep non-deferred (besides the tool-search tool), in priority order. */
3015
3015
  hotToolNames: readonly string[];
3016
+ /**
3017
+ * Server-tool names to drop entirely while defer-loading is on.
3018
+ *
3019
+ * Defer widens the per-turn selection to the whole catalog, which also bypasses the `excludeTools`
3020
+ * baked into a caller's semantic filter. A filter built by {@link createServerToolsFilter} tags itself
3021
+ * with its own exclusions and those are honoured automatically — so most callers need nothing here.
3022
+ *
3023
+ * Set this when the filter's tag can't be seen: a hand-written filter, a filter wrapped in a plain
3024
+ * closure (the wrapper drops the tag), or a static-array `serverToolsFilter`. Anything excluded
3025
+ * UNCONDITIONALLY (a tool the app replaces with its own UI, a capability the model already has
3026
+ * natively) belongs in one of the two places, or defer quietly hands it back to the model.
3027
+ *
3028
+ * This list is UNIONED with the filter's own tag, never a replacement for it — so adding one name
3029
+ * here cannot re-admit the tools the filter already excludes.
3030
+ */
3031
+ excludeTools?: readonly string[];
3016
3032
  }
3017
3033
  /**
3018
3034
  * Result of tool matching with similarity score
@@ -3192,7 +3208,7 @@ interface CreateServerToolsFilterOptions {
3192
3208
  * });
3193
3209
  * ```
3194
3210
  */
3195
- declare function createServerToolsFilter(options?: CreateServerToolsFilterOptions): (embeddings: number[] | number[][], tools: ServerTool[]) => string[];
3211
+ declare function createServerToolsFilter(options?: CreateServerToolsFilterOptions): ServerToolsFilterFunction;
3196
3212
  /**
3197
3213
  * Default exclusions baked into `defaultServerToolsFilter`.
3198
3214
  *
@@ -3258,13 +3274,21 @@ declare const SERVER_TOOL_DEPENDENCY_SETS: ToolSet[];
3258
3274
  * If you need to customize (extra excludes, different limits, opt into
3259
3275
  * tool-set expansion), call `createServerToolsFilter` directly.
3260
3276
  */
3261
- declare const defaultServerToolsFilter: (embeddings: number[] | number[][], tools: ServerTool[]) => string[];
3277
+ declare const defaultServerToolsFilter: ServerToolsFilterFunction;
3262
3278
  /**
3263
3279
  * Type for a server-tools filter — a function that takes prompt embeddings
3264
3280
  * and the full server tool catalog and returns the names of tools to keep.
3265
3281
  * Matches `useChatStorage`'s `serverTools` callback signature.
3266
3282
  */
3267
- type ServerToolsFilterFunction = (embeddings: number[] | number[][], tools: ServerTool[]) => string[];
3283
+ type ServerToolsFilterFunction = ((embeddings: number[] | number[][], tools: ServerTool[]) => string[]) & {
3284
+ /**
3285
+ * The unconditional exclusions this filter applies, exposed by
3286
+ * {@link createServerToolsFilter} so defer-loading can honour them without the caller
3287
+ * repeating the list — see {@link resolveDeferredServerTools}. Absent on a hand-written
3288
+ * filter, or on one wrapped in a plain closure.
3289
+ */
3290
+ readonly excludeTools?: readonly string[];
3291
+ };
3268
3292
  /**
3269
3293
  * Options for `selectServerToolsForPrompt`.
3270
3294
  */
@@ -3292,9 +3316,10 @@ interface SelectServerToolsForPromptOptions {
3292
3316
  */
3293
3317
  cache?: ToolsCacheBackend;
3294
3318
  /**
3295
- * Phase 3 defer-loading. When `enabled`, this helper returns the FULL catalog (skipping semantic/
3296
- * static filtering) to mirror useChatStorage's responses send path, which swaps in the full catalog
3297
- * for mergeTools + tool-search. Omit/disabled → today's filtered selection.
3319
+ * Phase 3 defer-loading. When `enabled`, this helper skips SEMANTIC filtering to mirror
3320
+ * useChatStorage's responses send path, which hands the catalog to mergeTools + tool-search. The
3321
+ * caller's unconditional constraints still apply — an explicit static array, and exclusions (see
3322
+ * {@link resolveDeferredServerTools}). Omit/disabled → today's filtered selection.
3298
3323
  */
3299
3324
  deferLoading?: DeferLoadingConfig;
3300
3325
  }
@@ -8302,6 +8302,15 @@ function filterServerTools(serverTools, includeNames) {
8302
8302
  const includeSet = new Set(includeNames);
8303
8303
  return serverTools.filter((tool) => includeSet.has(tool.name));
8304
8304
  }
8305
+ function resolveDeferredServerTools(allServerTools, serverToolsFilter, config) {
8306
+ const allowed = serverToolsFilter === void 0 || typeof serverToolsFilter === "function" ? allServerTools : filterServerTools(allServerTools, [...serverToolsFilter]);
8307
+ const excluded = new Set(config.excludeTools ?? []);
8308
+ if (typeof serverToolsFilter === "function") {
8309
+ for (const name of serverToolsFilter.excludeTools ?? []) excluded.add(name);
8310
+ }
8311
+ if (excluded.size === 0) return allowed;
8312
+ return allowed.filter((tool) => !excluded.has(tool.name));
8313
+ }
8305
8314
  var DEFAULT_TOOL_MATCH_OPTIONS = {
8306
8315
  limit: 5,
8307
8316
  minSimilarity: 0.3,
@@ -8578,7 +8587,7 @@ function createServerToolsFilter(options = {}) {
8578
8587
  const exclude = new Set(options.excludeTools ?? []);
8579
8588
  const sets = options.toolSets ?? [];
8580
8589
  const matchOpts = options.matchOptions;
8581
- return (embeddings, tools) => {
8590
+ const filter = (embeddings, tools) => {
8582
8591
  const matches = findMatchingTools(embeddings, tools, matchOpts);
8583
8592
  if (matches.length === 0) return [];
8584
8593
  const matchedNames = new Set(matches.map((m) => m.tool.name));
@@ -8596,6 +8605,10 @@ function createServerToolsFilter(options = {}) {
8596
8605
  for (const name of exclude) finalNames.delete(name);
8597
8606
  return [...finalNames];
8598
8607
  };
8608
+ return Object.defineProperty(filter, "excludeTools", {
8609
+ value: Object.freeze([...exclude]),
8610
+ enumerable: false
8611
+ });
8599
8612
  }
8600
8613
  var DEFAULT_EXCLUDED_SERVER_TOOLS = [
8601
8614
  "AnumaVisionMCP-anuma_analyze_image",
@@ -8677,7 +8690,8 @@ async function selectServerToolsForPrompt(options) {
8677
8690
  return [];
8678
8691
  }
8679
8692
  if (allServerTools.length === 0) return [];
8680
- if (deferLoading?.enabled) return allServerTools;
8693
+ if (deferLoading?.enabled)
8694
+ return resolveDeferredServerTools(allServerTools, serverToolsFilter, deferLoading);
8681
8695
  if (typeof serverToolsFilter === "function") {
8682
8696
  if (prompt.length < MIN_CONTENT_LENGTH_FOR_TOOLS) return [];
8683
8697
  let promptEmbedding;
@@ -86,6 +86,7 @@ __export(index_exports, {
86
86
  computeToolGuidance: () => computeToolGuidance,
87
87
  createServerToolsFilter: () => createServerToolsFilter,
88
88
  defaultServerToolsFilter: () => defaultServerToolsFilter,
89
+ deferFormattingConfig: () => deferFormattingConfig,
89
90
  deriveActiveToolSets: () => deriveActiveToolSets,
90
91
  expandToolSetsAdditive: () => expandToolSetsAdditive,
91
92
  filterAssembledClientTools: () => filterAssembledClientTools,
@@ -105,6 +106,7 @@ __export(index_exports, {
105
106
  mergeTools: () => mergeTools,
106
107
  resolveCouncilPlan: () => resolveCouncilPlan,
107
108
  resolveCouncilServerTools: () => resolveCouncilServerTools,
109
+ resolveDeferredServerTools: () => resolveDeferredServerTools,
108
110
  resolvePlan: () => resolvePlan,
109
111
  resolveServerTools: () => resolveServerTools,
110
112
  resolveToolChoice: () => resolveToolChoice,
@@ -1658,6 +1660,20 @@ function clientToolToCompletionsFormat(tool) {
1658
1660
  }
1659
1661
  var TOOL_SEARCH_TOOL_TYPE = "tool_search_tool_regex_20251119";
1660
1662
  var TOOL_SEARCH_TOOL_NAME = "tool_search_tool_regex";
1663
+ function resolveDeferredServerTools(allServerTools, serverToolsFilter, config) {
1664
+ const allowed = serverToolsFilter === void 0 || typeof serverToolsFilter === "function" ? allServerTools : filterServerTools(allServerTools, [...serverToolsFilter]);
1665
+ const excluded = new Set(config.excludeTools ?? []);
1666
+ if (typeof serverToolsFilter === "function") {
1667
+ for (const name of serverToolsFilter.excludeTools ?? []) excluded.add(name);
1668
+ }
1669
+ if (excluded.size === 0) return allowed;
1670
+ return allowed.filter((tool) => !excluded.has(tool.name));
1671
+ }
1672
+ function deferFormattingConfig(serverToolsFilter, config) {
1673
+ if (!config?.enabled) return config;
1674
+ const isExplicitList = serverToolsFilter !== void 0 && typeof serverToolsFilter !== "function";
1675
+ return isExplicitList ? void 0 : config;
1676
+ }
1661
1677
  function byNameAscending(a, b) {
1662
1678
  if (a.name < b.name) return -1;
1663
1679
  if (a.name > b.name) return 1;
@@ -2013,7 +2029,7 @@ function createServerToolsFilter(options = {}) {
2013
2029
  const exclude = new Set(options.excludeTools ?? []);
2014
2030
  const sets = options.toolSets ?? [];
2015
2031
  const matchOpts = options.matchOptions;
2016
- return (embeddings, tools) => {
2032
+ const filter = (embeddings, tools) => {
2017
2033
  const matches = findMatchingTools(embeddings, tools, matchOpts);
2018
2034
  if (matches.length === 0) return [];
2019
2035
  const matchedNames = new Set(matches.map((m) => m.tool.name));
@@ -2031,6 +2047,10 @@ function createServerToolsFilter(options = {}) {
2031
2047
  for (const name of exclude) finalNames.delete(name);
2032
2048
  return [...finalNames];
2033
2049
  };
2050
+ return Object.defineProperty(filter, "excludeTools", {
2051
+ value: Object.freeze([...exclude]),
2052
+ enumerable: false
2053
+ });
2034
2054
  }
2035
2055
  var DEFAULT_EXCLUDED_SERVER_TOOLS = [
2036
2056
  "AnumaVisionMCP-anuma_analyze_image",
@@ -2112,7 +2132,8 @@ async function selectServerToolsForPrompt(options) {
2112
2132
  return [];
2113
2133
  }
2114
2134
  if (allServerTools.length === 0) return [];
2115
- if (deferLoading?.enabled) return allServerTools;
2135
+ if (deferLoading?.enabled)
2136
+ return resolveDeferredServerTools(allServerTools, serverToolsFilter, deferLoading);
2116
2137
  if (typeof serverToolsFilter === "function") {
2117
2138
  if (prompt.length < MIN_CONTENT_LENGTH_FOR_TOOLS) return [];
2118
2139
  let promptEmbedding;
@@ -2738,6 +2759,7 @@ async function selectCouncilClientTools(input, options) {
2738
2759
  computeToolGuidance,
2739
2760
  createServerToolsFilter,
2740
2761
  defaultServerToolsFilter,
2762
+ deferFormattingConfig,
2741
2763
  deriveActiveToolSets,
2742
2764
  expandToolSetsAdditive,
2743
2765
  filterAssembledClientTools,
@@ -2757,6 +2779,7 @@ async function selectCouncilClientTools(input, options) {
2757
2779
  mergeTools,
2758
2780
  resolveCouncilPlan,
2759
2781
  resolveCouncilServerTools,
2782
+ resolveDeferredServerTools,
2760
2783
  resolvePlan,
2761
2784
  resolveServerTools,
2762
2785
  resolveToolChoice,
@@ -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 };