diff --git a/app/components/agent/AgentSwitcher.vue b/app/components/agent/AgentSwitcher.vue index 3695e4f..ece1051 100644 --- a/app/components/agent/AgentSwitcher.vue +++ b/app/components/agent/AgentSwitcher.vue @@ -36,9 +36,6 @@ async function loadAgents() { } function toggle() { - if (!open.value && agents.value.length === 0) { - loadAgents(); - } open.value = !open.value; } @@ -56,6 +53,7 @@ function handleClickOutside(e: MouseEvent) { } onMounted(() => { + loadAgents(); document.addEventListener("click", handleClickOutside); }); diff --git a/app/composables/useAgentSessions.ts b/app/composables/useAgentSessions.ts index 596bcd0..16c0f20 100644 --- a/app/composables/useAgentSessions.ts +++ b/app/composables/useAgentSessions.ts @@ -28,6 +28,16 @@ export function useAgentSessions(agentSlug: string) { sessions.value.find((s) => s.id === currentSessionId.value) ?? null, ); + function syncSessionToUrl(id: string | null) { + if (import.meta.server) return; + const route = useRoute(); + const router = useRouter(); + const current = route.query.session; + const target = id ?? undefined; + if (current === target) return; + router.replace({ query: { ...route.query, session: target } }); + } + async function fetchSessions() { loading.value = true; try { @@ -62,17 +72,20 @@ export function useAgentSessions(agentSlug: string) { async function selectSession(id: string) { currentSessionId.value = id; + syncSessionToUrl(id); } async function newSession(): Promise { const latest = sessions.value[0]; if (latest && latest.lastActiveAt === latest.createdAt) { currentSessionId.value = latest.id; + syncSessionToUrl(latest.id); return latest; } const session = await createSession(); if (session) { currentSessionId.value = session.id; + syncSessionToUrl(session.id); } return session; } @@ -96,12 +109,15 @@ export function useAgentSessions(agentSlug: string) { if (currentSessionId.value === id) { if (sessions.value.length > 0) { currentSessionId.value = sessions.value[0]?.id ?? null; + syncSessionToUrl(currentSessionId.value); } else { const session = await createSession(); if (session) { currentSessionId.value = session.id; + syncSessionToUrl(session.id); } else { currentSessionId.value = null; + syncSessionToUrl(null); } } } @@ -162,10 +178,16 @@ export function useAgentSessions(agentSlug: string) { if (initialized.value) return; await auth.refresh(); await fetchSessions(); - if (sessions.value.length === 0) { + const route = useRoute(); + const urlSessionId = route.query.session; + const urlSessionStr = typeof urlSessionId === "string" ? urlSessionId : null; + if (urlSessionStr && sessions.value.some((s) => s.id === urlSessionStr)) { + currentSessionId.value = urlSessionStr; + } else if (sessions.value.length === 0) { await newSession(); } else { currentSessionId.value = sessions.value[0]?.id ?? null; + syncSessionToUrl(currentSessionId.value); } initialized.value = true; } diff --git a/packages/drizzle-pkg/db.sqlite b/packages/drizzle-pkg/db.sqlite index 3bea3ff..17ebbed 100644 Binary files a/packages/drizzle-pkg/db.sqlite and b/packages/drizzle-pkg/db.sqlite differ