From d2332ca83182ea631fcc17d817ec32870488de0e Mon Sep 17 00:00:00 2001 From: Leo310 Date: Tue, 13 Oct 2026 16:53:23 +0200 Subject: [PATCH 1/2] fix(agents): keep a stored context window when the same model is re-picked (#542) buildPersistedChatModel let hydrated catalogue metadata win over the stored contextWindow. hydrateChatModel always fills that field (128000 when the provider reports nothing), so once Ollama was reachable any re-pick of the same model replaced a user-tuned window. Re-picking the stored provider+model now keeps the stored value; a different model still takes the catalogue value. Also adds a Context window field under the chat model in the Agent editor so the value no longer has to be edited by hand in data.json. Co-Authored-By: Claude --- src/components/modal/AgentEditorModal.svelte | 31 ++++++++ src/utils/persistedChatModel.ts | 13 ++- test/utils/persistedChatModel.test.ts | 83 ++++++++++++++++++++ 3 files changed, 123 insertions(+), 4 deletions(-) create mode 100644 test/utils/persistedChatModel.test.ts diff --git a/src/components/modal/AgentEditorModal.svelte b/src/components/modal/AgentEditorModal.svelte index 6878a681..a2838b31 100644 --- a/src/components/modal/AgentEditorModal.svelte +++ b/src/components/modal/AgentEditorModal.svelte @@ -187,6 +187,24 @@ function openModelSelectionModal() { }).open(); } +// The window is filled from provider metadata when a model is picked; this lets the user +// override it (e.g. to match an Ollama num_ctx their hardware can hold). Re-picking the same +// model keeps the override — see buildPersistedChatModel (#542). +function updateChatContextWindow(value: number) { + const chatModel = selectedAgent?.chatModel; + if (!chatModel) return; + const contextWindow = Math.round(value); + if (!Number.isFinite(contextWindow) || contextWindow < 1) { + new Notice("Context window must be a positive number of tokens."); + return; + } + if (contextWindow === chatModel.modelConfig?.contextWindow) return; + pluginData.updateAgent(agentId, { + chatModel: { ...chatModel, modelConfig: { ...chatModel.modelConfig, contextWindow } }, + }); + void applyChanges(); +} + function openSummarizationModelSelectionModal() { const currentSelection = selectedAgent?.summarizationModel ? { @@ -784,6 +802,19 @@ function getServerToolsState(serverId: string): MCPServerToolsState | undefined /> + {#if selectedAgent.chatModel} + + + + {/if} +