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} /> ) : ( -
+
{t("readOnly")}
diff --git a/ui/web/src/pages/chat/hooks/use-chat-sessions.ts b/ui/web/src/pages/chat/hooks/use-chat-sessions.ts index de7e54a3..8d40fa52 100644 --- a/ui/web/src/pages/chat/hooks/use-chat-sessions.ts +++ b/ui/web/src/pages/chat/hooks/use-chat-sessions.ts @@ -10,7 +10,6 @@ import { useAuthStore } from "@/stores/use-auth-store"; */ export function useChatSessions(agentId: string) { const ws = useWs(); - const userId = useAuthStore((s) => s.userId); const connected = useAuthStore((s) => s.connected); const [sessions, setSessions] = useState([]); const [loading, setLoading] = useState(true); @@ -23,7 +22,7 @@ export function useChatSessions(agentId: string) { try { const res = await ws.call<{ sessions: SessionInfo[] }>( Methods.SESSIONS_LIST, - { agentId }, + { agentId, channel: "ws" }, ); const sorted = (res.sessions ?? []).sort( (a: SessionInfo, b: SessionInfo) => @@ -42,9 +41,9 @@ export function useChatSessions(agentId: string) { }, [loadSessions]); const buildNewSessionKey = useCallback(() => { - const ts = Date.now().toString(36); - return `agent:${agentId}:ws-${userId}-${ts}`; - }, [agentId, userId]); + const convId = crypto.randomUUID(); + return `agent:${agentId}:ws:direct:${convId}`; + }, [agentId]); return { sessions,