diff --git a/ui/web/src/lib/session-key.ts b/ui/web/src/lib/session-key.ts index 3cff3927..494e315d 100644 --- a/ui/web/src/lib/session-key.ts +++ b/ui/web/src/lib/session-key.ts @@ -21,11 +21,13 @@ export function buildSessionKey(agentId: string, scope: string): string { /** * Check if a session belongs to the current web user. - * Web sessions have scope format: "ws-{userId}-{timestamp}". + * New format: "ws:direct:{convId}" — API already filters by userId, so all WS sessions are own. + * Legacy format: "ws-{userId}-{timestamp}". * Sessions from other channels (telegram, discord, etc.) are foreign. */ export function isOwnSession(sessionKey: string, userId: string): boolean { if (!userId) return false; const { scope } = parseSessionKey(sessionKey); + if (scope.startsWith("ws:direct:")) return true; return scope.startsWith(`ws-${userId}-`); } diff --git a/ui/web/src/pages/chat/chat-page.tsx b/ui/web/src/pages/chat/chat-page.tsx index 11e5ef13..5d8925a7 100644 --- a/ui/web/src/pages/chat/chat-page.tsx +++ b/ui/web/src/pages/chat/chat-page.tsx @@ -108,11 +108,11 @@ export function ChatPage() { const handleAgentChange = useCallback( (newAgentId: string) => { setAgentId(newAgentId); - const newKey = `agent:${newAgentId}:ws-${userId}-${Date.now().toString(36)}`; + const newKey = `agent:${newAgentId}:ws:direct:${crypto.randomUUID()}`; setSessionKey(newKey); navigate(`/chat/${encodeURIComponent(newKey)}`); }, - [navigate, userId], + [navigate], ); const handleSend = useCallback( @@ -235,7 +235,7 @@ export function ChatPage() { disabled={!connected} /> ) : ( -