@@ -21,9 +21,19 @@ function asRecord(value: unknown): Record<string, unknown> {
2121 return value && typeof value === 'object' ? ( value as Record < string , unknown > ) : { }
2222}
2323
24+ function getOperation ( params : Record < string , unknown > | undefined ) : string | undefined {
25+ const args = asRecord ( params ?. args )
26+ return ( args . operation ?? params ?. operation ) as string | undefined
27+ }
28+
29+ const READ_ONLY_TABLE_OPS = new Set ( [ 'get' , 'get_schema' , 'get_row' , 'query_rows' ] )
30+ const READ_ONLY_KB_OPS = new Set ( [ 'get' , 'query' , 'list_tags' , 'get_tag_usage' ] )
31+ const READ_ONLY_KNOWLEDGE_ACTIONS = new Set ( [ 'listed' , 'queried' ] )
32+
2433/**
2534 * Extracts resource descriptors from a tool execution result.
2635 * Returns one or more resources for tools that create/modify workspace entities.
36+ * Read-only operations are excluded to avoid unnecessary cache invalidation.
2737 */
2838export function extractResourcesFromToolResult (
2939 toolName : string ,
@@ -37,6 +47,8 @@ export function extractResourcesFromToolResult(
3747
3848 switch ( toolName ) {
3949 case 'user_table' : {
50+ if ( READ_ONLY_TABLE_OPS . has ( getOperation ( params ) ?? '' ) ) return [ ]
51+
4052 if ( result . tableId ) {
4153 return [
4254 {
@@ -123,6 +135,8 @@ export function extractResourcesFromToolResult(
123135 }
124136
125137 case 'knowledge_base' : {
138+ if ( READ_ONLY_KB_OPS . has ( getOperation ( params ) ?? '' ) ) return [ ]
139+
126140 const kbId =
127141 ( data . id as string ) ??
128142 ( result . knowledgeBaseId as string ) ??
@@ -137,6 +151,9 @@ export function extractResourcesFromToolResult(
137151 }
138152
139153 case 'knowledge' : {
154+ const action = data . action as string | undefined
155+ if ( READ_ONLY_KNOWLEDGE_ACTIONS . has ( action ?? '' ) ) return [ ]
156+
140157 const kbArray = data . knowledge_bases as Array < Record < string , unknown > > | undefined
141158 if ( ! Array . isArray ( kbArray ) ) return [ ]
142159 const resources : ChatResource [ ] = [ ]
0 commit comments