File tree Expand file tree Collapse file tree 2 files changed +18
-2
lines changed
Expand file tree Collapse file tree 2 files changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -36,8 +36,8 @@ const defaultConfig: PluginConfig = {
3636 pruning_summary : 'detailed' ,
3737 nudge_freq : 10 ,
3838 strategies : {
39- onIdle : [ 'deduplication' , ' ai-analysis'] ,
40- onTool : [ 'deduplication' , ' ai-analysis']
39+ onIdle : [ 'ai-analysis' ] ,
40+ onTool : [ 'ai-analysis' ]
4141 }
4242}
4343
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ import type { PluginConfig } from "../config"
66import { handleOpenAIChatAndAnthropic } from "./openai-chat"
77import { handleGemini } from "./gemini"
88import { handleOpenAIResponses } from "./openai-responses"
9+ import { detectDuplicates } from "../deduplicator"
910
1011export type { FetchHandlerContext , FetchHandlerResult , SynthPrompts } from "./types"
1112
@@ -78,6 +79,21 @@ export function installFetchWrapper(
7879 }
7980 }
8081
82+ // Run deduplication after handlers have populated toolParameters cache
83+ const sessionId = state . lastSeenSessionId
84+ if ( sessionId && state . toolParameters . size > 0 ) {
85+ const toolIds = Array . from ( state . toolParameters . keys ( ) )
86+ const alreadyPruned = state . prunedIds . get ( sessionId ) ?? [ ]
87+ const alreadyPrunedLower = new Set ( alreadyPruned . map ( id => id . toLowerCase ( ) ) )
88+ const unpruned = toolIds . filter ( id => ! alreadyPrunedLower . has ( id . toLowerCase ( ) ) )
89+ if ( unpruned . length > 0 ) {
90+ const { duplicateIds } = detectDuplicates ( state . toolParameters , unpruned , config . protectedTools )
91+ if ( duplicateIds . length > 0 ) {
92+ state . prunedIds . set ( sessionId , [ ...new Set ( [ ...alreadyPruned , ...duplicateIds ] ) ] )
93+ }
94+ }
95+ }
96+
8197 if ( modified ) {
8298 init . body = JSON . stringify ( body )
8399 }
You can’t perform that action at this time.
0 commit comments