@@ -29,56 +29,9 @@ type ToolSearchRunPlan = {
2929 replayAllowedToolNames : Set < string > ;
3030 liveAllowedToolNames : Set < string > ;
3131 capabilityToolNames : Set < string > ;
32- autoAddedControlNames ?: Set < string > ;
3332 emptyAllowlistCallableNames : string [ ] ;
3433} ;
3534
36- /**
37- * Builds the callable-name list used to decide whether an allowlist is empty.
38- * Auto-added tool-search controls are excluded so they do not make an otherwise
39- * empty user/tool allowlist look populated.
40- */
41- export function buildCallableToolNamesForEmptyAllowlistCheck ( params : {
42- effectiveToolNames : string [ ] ;
43- autoAddedToolSearchControlNames ?: Set < string > ;
44- toolSearchCatalogToolCount : number ;
45- } ) : string [ ] {
46- return [
47- ...params . effectiveToolNames . filter (
48- ( toolName ) => ! params . autoAddedToolSearchControlNames ?. has ( toolName ) ,
49- ) ,
50- ...Array . from (
51- { length : params . toolSearchCatalogToolCount } ,
52- ( _ , index ) => `tool-search:${ index } ` ,
53- ) ,
54- ] ;
55- }
56-
57- /**
58- * Identifies tool-search control names that were added by policy rather than
59- * explicitly allowed by the user. Explicit controls stay visible to empty
60- * allowlist checks because the user selected them.
61- */
62- export function buildAutoAddedToolSearchControlNamesForAllowlistCheck ( params : {
63- toolSearchControlsEnabled : boolean ;
64- explicitAllowlistSources : Array < { entries : string [ ] } > ;
65- controlNames ?: readonly string [ ] ;
66- } ) : Set < string > | undefined {
67- if ( ! params . toolSearchControlsEnabled ) {
68- return undefined ;
69- }
70- const explicitlyAllowed = new Set (
71- params . explicitAllowlistSources . flatMap ( ( source ) =>
72- source . entries . map ( ( entry ) => normalizeToolName ( entry ) ) ,
73- ) ,
74- ) ;
75- return new Set (
76- ( params . controlNames ?? TOOL_SEARCH_CONTROL_ALLOWLIST_NAMES ) . filter (
77- ( controlName ) => ! explicitlyAllowed . has ( normalizeToolName ( controlName ) ) ,
78- ) ,
79- ) ;
80- }
81-
8235function collectExplicitlyAllowedClientToolNames ( params : {
8336 clientTools ?: CollectAllowedToolNamesParams [ "clientTools" ] ;
8437 explicitAllowlistSources : Array < { entries : string [ ] } > ;
@@ -153,11 +106,17 @@ export function buildToolSearchRunPlan(params: {
153106 liveAllowedToolNames . add ( visibleName ) ;
154107 }
155108 }
156- const autoAddedControlNames = buildAutoAddedToolSearchControlNamesForAllowlistCheck ( {
157- toolSearchControlsEnabled : params . controlsEnabled ,
158- explicitAllowlistSources : params . explicitAllowlistSources ,
159- controlNames : params . controlNames ,
160- } ) ;
109+ const explicitControlAllowlistNames = new Set (
110+ params . explicitAllowlistSources . flatMap ( ( source ) =>
111+ source . entries . map ( ( entry ) => normalizeToolName ( entry ) ) ,
112+ ) ,
113+ ) ;
114+ const autoAddedControlNames = new Set (
115+ ( params . controlsEnabled
116+ ? ( params . controlNames ?? TOOL_SEARCH_CONTROL_ALLOWLIST_NAMES )
117+ : [ ]
118+ ) . filter ( ( controlName ) => ! explicitControlAllowlistNames . has ( normalizeToolName ( controlName ) ) ) ,
119+ ) ;
161120 const explicitlyAllowedClientToolNames = collectExplicitlyAllowedClientToolNames ( {
162121 clientTools : params . clientTools ,
163122 explicitAllowlistSources : params . explicitAllowlistSources ,
@@ -175,13 +134,11 @@ export function buildToolSearchRunPlan(params: {
175134 replayAllowedToolNames,
176135 liveAllowedToolNames,
177136 capabilityToolNames,
178- autoAddedControlNames,
179137 emptyAllowlistCallableNames : [
180- ...buildCallableToolNamesForEmptyAllowlistCheck ( {
181- effectiveToolNames : [ ...emptyAllowlistVisibleToolNames ] ,
182- autoAddedToolSearchControlNames : autoAddedControlNames ,
183- toolSearchCatalogToolCount : params . catalogToolCount ,
184- } ) ,
138+ ...[ ...emptyAllowlistVisibleToolNames ] . filter (
139+ ( toolName ) => ! autoAddedControlNames . has ( toolName ) ,
140+ ) ,
141+ ...Array . from ( { length : params . catalogToolCount } , ( _ , index ) => `tool-search:${ index } ` ) ,
185142 ...explicitClientCallableNames ,
186143 ] ,
187144 } ;
0 commit comments