Skip to content

Commit 1c9ee65

Browse files
refactor: non-stop silent deduplication
1 parent e982f50 commit 1c9ee65

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

lib/config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff 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

lib/fetch-wrapper/index.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import type { PluginConfig } from "../config"
66
import { handleOpenAIChatAndAnthropic } from "./openai-chat"
77
import { handleGemini } from "./gemini"
88
import { handleOpenAIResponses } from "./openai-responses"
9+
import { detectDuplicates } from "../deduplicator"
910

1011
export 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
}

0 commit comments

Comments
 (0)