From aa230050f4edb7bfc8d3e4d59d95c68c36264b41 Mon Sep 17 00:00:00 2001 From: Adam Malczewski Date: Fri, 29 May 2026 14:24:55 +0900 Subject: fix: refresh agent config on send; widen fallback retry detection - Refresh agent config from API before sending a message so edits in AgentBuilder (changed keyId/modelId/agentModels) take effect immediately on existing tabs instead of using stale snapshots - Broaden isRetryable check to also match 'usage limit' and 'exhausted' so fallback keys are actually tried on quota errors --- packages/frontend/src/lib/tabs.svelte.ts | 44 +++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) (limited to 'packages/frontend') diff --git a/packages/frontend/src/lib/tabs.svelte.ts b/packages/frontend/src/lib/tabs.svelte.ts index b2c4480..9b31b3f 100644 --- a/packages/frontend/src/lib/tabs.svelte.ts +++ b/packages/frontend/src/lib/tabs.svelte.ts @@ -1194,6 +1194,41 @@ export function createTabStore() { } } + async function refreshAgentConfig(tabId: string): Promise { + const tab = getTabById(tabId); + if (!tab?.agentSlug || !tab.agentScope) return; + try { + const res = await fetch(`${config.apiBase}/agents`); + if (!res.ok) return; + const data = (await res.json()) as { + agents?: Array<{ + slug: string; + scope: string; + models: Array<{ key_id: string; model_id: string }>; + cwd?: string; + }>; + }; + const agents = data.agents ?? []; + const freshAgent = agents.find((a) => a.slug === tab.agentSlug && a.scope === tab.agentScope); + if (!freshAgent) return; + const firstModel = freshAgent.models[0]; + const patch: Partial = { + agentModels: freshAgent.models, + workingDirectory: freshAgent.cwd || null, + }; + if (firstModel) { + patch.keyId = firstModel.key_id; + patch.modelId = firstModel.model_id; + } else { + patch.keyId = null; + patch.modelId = null; + } + updateTab(tabId, patch); + } catch { + // Silently fall back to stale values + } + } + async function fetchSkillContent(scope: string, name: string): Promise { try { const res = await fetch( @@ -1208,9 +1243,16 @@ export function createTabStore() { } async function sendMessage(text: string): Promise { - const tab = getActiveTab(); + let tab = getActiveTab(); if (!tab) return; + // Refresh agent config to pick up any changes made in AgentBuilder + if (tab.agentSlug && tab.agentScope) { + await refreshAgentConfig(tab.id); + tab = getActiveTab(); + if (!tab) return; + } + // Fetch content for checked skills and build the message to send let messageToSend = text; const checkedKeys = Object.entries(appSettings.skillChecks) -- cgit v1.2.3