diff --git a/src/components/modal/AgentEditorModal.svelte b/src/components/modal/AgentEditorModal.svelte index 6878a681..4c158330 100644 --- a/src/components/modal/AgentEditorModal.svelte +++ b/src/components/modal/AgentEditorModal.svelte @@ -187,6 +187,29 @@ 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). +// Bumped on a rejected edit to remount the field, which otherwise keeps showing the invalid +// value it bound locally. +let contextWindowFieldKey = $state(0); + +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."); + contextWindowFieldKey++; + 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 +807,21 @@ function getServerToolsState(serverId: string): MCPServerToolsState | undefined /> + {#if selectedAgent.chatModel} + + {#key contextWindowFieldKey} + + {/key} + + {/if} +