Agent Zero AI framework
Refresh context indicator after clearing chat
Alessandro9f0db8ad046d
diff --git a/plugins/_context_window/AGENTS.md b/plugins/_context_window/AGENTS.mdindex 7748c7463..fea48f33c 100644--- a/plugins/_context_window/AGENTS.md+++ b/plugins/_context_window/AGENTS.md@@ -41,8 +41,9 @@restores the accepted response after the accounting tail is drained.- Responses API turns keep their native result and callback behavior unchanged.- Older chats without a stored breakdown show the explanatory empty state.-- The indicator refreshes once per new Agent 0 generation and again when the- run completes; streamed updates to the same generation do not refetch it.+- The indicator refreshes once per new Agent 0 generation, when the run+ completes, and when the active chat log GUID changes (including Clear Chat);+ streamed updates to the same generation do not refetch it.- `_model_config` supplies the effective model limit and the`model-context-strip-end` WebUI slot; it does not own this feature's state.- The `contextWindowUsage` Interface setting defaults to visible on mobile anddiff --git a/plugins/_context_window/extensions/webui/apply_snapshot_before/refresh-context-window.js b/plugins/_context_window/extensions/webui/apply_snapshot_before/refresh-context-window.jsindex 5a21adbd5..51a17cdd5 100644--- a/plugins/_context_window/extensions/webui/apply_snapshot_before/refresh-context-window.js+++ b/plugins/_context_window/extensions/webui/apply_snapshot_before/refresh-context-window.js@@ -3,6 +3,7 @@ import { store as contextWindowStore } from "/plugins/_context_window/webui/contconst OVERRIDE_REVISION_KEY = "_model_config_override_revision";let lastContextId = "";let lastRevision = null;+let lastLogGuid = "";let lastGenerationKey = "";function latestGenerationKey(logs) {@@ -21,6 +22,7 @@ export default async function refreshContextWindow(ctx) {if (!contextId) {lastContextId = "";lastRevision = null;+ lastLogGuid = "";lastGenerationKey = "";return;}@@ -28,15 +30,18 @@ export default async function refreshContextWindow(ctx) {const contexts = Array.isArray(snapshot?.contexts) ? snapshot.contexts : [];const active = contexts.find(item => item?.id === contextId) || null;const revision = active?.[OVERRIDE_REVISION_KEY] || null;+ const logGuid = String(snapshot?.log_guid || "");const generationKey = latestGenerationKey(snapshot?.logs);if (contextId === lastContextId&& revision === lastRevision+ && logGuid === lastLogGuid&& (!generationKey || generationKey === lastGenerationKey)) return;lastContextId = contextId;lastRevision = revision;+ lastLogGuid = logGuid;if (generationKey) lastGenerationKey = generationKey;await contextWindowStore.refresh(contextId);}diff --git a/plugins/_context_window/tests/test_context_window.py b/plugins/_context_window/tests/test_context_window.pyindex b97bba481..04ae433b3 100644--- a/plugins/_context_window/tests/test_context_window.py+++ b/plugins/_context_window/tests/test_context_window.py@@ -194,6 +194,8 @@ def test_webui_and_accounting_are_plugin_owned():assert "rpartition(" not in helperassert 'item?.type !== "agent"' in refresh_hookassert "Number(item.agentno || 0) !== 0" in refresh_hook+ assert 'const logGuid = String(snapshot?.log_guid || "")' in refresh_hook+ assert "logGuid === lastLogGuid" in refresh_hookassert "generationKey === lastGenerationKey" in refresh_hook