diff --git a/extensions/index.ts b/extensions/index.ts index 12971d0..f452ed5 100644 --- a/extensions/index.ts +++ b/extensions/index.ts @@ -428,14 +428,51 @@ async function webSearchGemini(query: string, signal?: AbortSignal): Promise Math.ceil(s.length / 4); @@ -450,6 +487,7 @@ async function buildContextBlock( ctx: any, prompt: string, signal?: AbortSignal, + mode?: string, ): Promise { if (getConfig("contextInject") === "off") return ""; const budget = Number(getConfig("contextTokens") ?? 1500) || 1500; @@ -491,9 +529,15 @@ async function buildContextBlock( } // --- (Strada A) --- - if (needsWebSearch(prompt)) { - const web = await webSearchGemini(prompt.slice(0, 300), signal); - if (web) parts.push({ label: "web", xml: "web_context", body: web }); + if (needsWebSearch(prompt, mode)) { + // anti-ridondanza: non ricercare lo stesso topic entro 60s + const topic = prompt.trim().toLowerCase().slice(0, 60); + const now = Date.now(); + if (topic !== lastSearch.topic || now - lastSearch.time > 60_000) { + lastSearch = { topic, time: now }; + const web = await webSearchGemini(prompt.slice(0, 300), signal); + if (web) parts.push({ label: "web", xml: "web_context", body: web }); + } } // Token cap: budget totale ~1500. Assegna in modo proporzionale. @@ -1126,7 +1170,7 @@ export default function agyExtension(pi: ExtensionAPI) { const wantInject = p.injectContext ?? true; const prevWs = getConfig("webSearch"); if (typeof p.webSearch === "boolean") setConfig("webSearch", p.webSearch ? "on" : "off"); - const contextBlock = wantInject ? await buildContextBlock(ctx, p.prompt, signal) : ""; + const contextBlock = wantInject ? await buildContextBlock(ctx, p.prompt, signal, p.mode) : ""; if (typeof p.webSearch === "boolean" && prevWs) setConfig("webSearch", prevWs); const res = await executeAgy({ prompt: p.prompt,