From b6d60cd94615878643f0cdf778d835bf26a309ca Mon Sep 17 00:00:00 2001 From: matevip Date: Thu, 2 Jul 2026 17:35:17 +0800 Subject: [PATCH] fix(chat): drop stale workspace agentId from chat URL on remount (#465) --- mateclaw-ui/src/views/ChatConsole.vue | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/mateclaw-ui/src/views/ChatConsole.vue b/mateclaw-ui/src/views/ChatConsole.vue index da438fc5..6d7bf9b6 100644 --- a/mateclaw-ui/src/views/ChatConsole.vue +++ b/mateclaw-ui/src/views/ChatConsole.vue @@ -1465,8 +1465,24 @@ async function refreshCurrentConversationMessages(conversationId: string) { } async function hydrateStateFromRoute() { - const agentId = route.query.agentId ? String(route.query.agentId) : '' - const conversationId = String(route.query.conversationId || '') + let agentId = route.query.agentId ? String(route.query.agentId) : '' + let conversationId = String(route.query.conversationId || '') + + // The URL can outlive its workspace: switching workspaces remounts this view + // (via the router-view key) but keeps the query string, so agentId / + // conversationId may still point at entities of the previous workspace. An + // agentId missing from the workspace-scoped agent list is such a leftover — + // drop it so the default-select below picks a real employee instead of the + // picker rendering the unresolvable raw id. + if (agentId && agents.value.length > 0 && !agents.value.some(a => String(a.id) === agentId)) { + agentId = '' + // Only follow the paired conversationId when it resolves locally (e.g. a + // Sessions-page jump within this workspace); otherwise it is equally stale + // and would attach the fallback agent to a foreign conversation. + if (!conversations.value.some(conv => conv.conversationId === conversationId)) { + conversationId = '' + } + } if (agentId && agentId !== String(selectedAgentId.value)) { selectedAgentId.value = agentId