The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(webapp): keep one gateway's sessions in one sidebar section
Teknium91cb42ee3748
diff --git a/apps/desktop/src/app/chat/sidebar/gateway-group-model.ts b/apps/desktop/src/app/chat/sidebar/gateway-group-model.tsindex f9cdf1fc8e2..02f5df72b6f 100644--- a/apps/desktop/src/app/chat/sidebar/gateway-group-model.ts+++ b/apps/desktop/src/app/chat/sidebar/gateway-group-model.ts@@ -1,3 +1,4 @@+import { LOCAL_CONNECTION_ID } from '@hermes/shared'import { useStore } from '@nanostores/react'import { useMemo } from 'react'@@ -9,6 +10,18 @@ import { $profileColors, normalizeProfileKey } from '@/store/profile'import type { SidebarSessionGroup } from './projects/workspace-groups'+/** A gateway section's name: its registry label, else `localLabel` for the `local` source a+ * registry does not list (the Webapp's one gateway, the host serving it), else the raw id. */+export function gatewayLabel(+ connectionId: string,+ registry: DesktopConnectionsRegistry | null,+ localLabel: string+): string {+ const registered = registry?.connections.find(connection => connection.id === connectionId)?.label++ return registered || (connectionId === LOCAL_CONNECTION_ID ? localLabel : connectionId)+}+/** One group per exact owner `[connectionId, profile]`. Group identity never* depends on a mutable label, URL, or the active gateway. */export function buildGatewaySessionGroups(diff --git a/apps/desktop/src/app/chat/sidebar/gateway-groups-webapp.test.tsx b/apps/desktop/src/app/chat/sidebar/gateway-groups-webapp.test.tsxnew file mode 100644index 00000000000..b5f958ca210--- /dev/null+++ b/apps/desktop/src/app/chat/sidebar/gateway-groups-webapp.test.tsx@@ -0,0 +1,78 @@+// @vitest-environment jsdom+import { act, cleanup, render, screen, within } from '@testing-library/react'+import { MemoryRouter } from 'react-router'+import { afterEach, expect, it } from 'vitest'++import { SidebarProvider } from '@/components/ui/sidebar'+import { $connectionsRegistry } from '@/store/connection-registry-state'+import { setSidebarGrouping } from '@/store/layout'+import { $profiles, $showAllProfiles } from '@/store/profile'+import { $sessions } from '@/store/session'+import { makeSessionInfo } from '@/test/session-info'++import { ChatSidebar } from './index'++const noop = () => {}++const noopAsync = async () => {}++const mount = () =>+ render(+ <MemoryRouter>+ <SidebarProvider>+ <ChatSidebar+ currentView="chat"+ onArchiveSession={noop}+ onBranchSession={noop}+ onDeleteSession={noop}+ onLoadMoreSessions={noop}+ onManageCronJob={noop}+ onNavigate={noop}+ onNewSessionInWorkspace={noop}+ onNewSessionSplit={noop}+ onResumeSession={noop}+ onRetrySessions={noopAsync}+ onTriggerCronJob={async () => {}}+ />+ </SidebarProvider>+ </MemoryRouter>+ )++afterEach(() => {+ cleanup()+ $showAllProfiles.set(false)+ $sessions.set([])+})++// The Webapp publishes no connection registry: its one gateway is the `local` source.+it('names the Webapp gateway section after the host instead of its raw `local` id', () => {+ mount()+ act(() => {+ $connectionsRegistry.set(null)+ $profiles.set([+ { name: 'default', is_default: true },+ { name: 'work', is_default: false }+ ] as typeof $profiles.value)+ $showAllProfiles.set(true)+ setSidebarGrouping('profile')+ $sessions.set(+ [+ ['listed', 'default'],+ ['new-chat', 'default'],+ ['work-chat', 'work']+ ].map(([id, profile]) =>+ makeSessionInfo({ id, connection_id: 'local', profile, title: `${id} title`, last_active: Date.now() / 1000 })+ )+ )+ })++ const sections = document.querySelectorAll('[data-gateway-section]')+ expect(sections).toHaveLength(1)+ const gateway = sections[0] as HTMLElement+ expect(within(gateway).getByText('Hermes host')).toBeTruthy()+ expect(screen.queryByText('local')).toBeNull()+ expect(gateway.querySelectorAll('[data-gateway-group]')).toHaveLength(2)+ expect(within(gateway).getByText('listed title')).toBeTruthy()+ expect(within(gateway).getByText('new-chat title')).toBeTruthy()+ expect(within(gateway).getByText('work-chat title')).toBeTruthy()+})diff --git a/apps/desktop/src/app/chat/sidebar/gateway-groups.tsx b/apps/desktop/src/app/chat/sidebar/gateway-groups.tsxindex fce094a4a76..70df2002a24 100644--- a/apps/desktop/src/app/chat/sidebar/gateway-groups.tsx+++ b/apps/desktop/src/app/chat/sidebar/gateway-groups.tsx@@ -31,6 +31,7 @@ import { $sessionProfilesUsage } from '@/store/session'import { $sidebarSessionRankIds } from '@/store/sidebar-sort'import { SidebarGroupRow, SidebarRowGrab, SidebarRowLink, SidebarRowStack } from './chrome'+import { gatewayLabel } from './gateway-group-model'import {$gatewayGroupAliases,$gatewayGroupCollapsed,@@ -64,6 +65,7 @@ export function GatewayProfileGroups({nested = false,embedded = false}: GatewayProfileGroupsProps) {+ const { t } = useI18n()const registry = useStore($connectionsRegistry)const order = useStore($gatewayGroupOrder)const gatewayProfiles = new Map<string, SidebarSessionGroup[]>()@@ -87,8 +89,7 @@ export function GatewayProfileGroups({sections.push({id,connectionId: group.connectionId,- label:- registry?.connections.find(connection => connection.id === group.connectionId)?.label || group.connectionId,+ label: gatewayLabel(group.connectionId, registry, t.settings.gateway.webappHostTitle),mode: 'profile',path: null,sessions: []diff --git a/apps/desktop/src/lib/browser-desktop-bridge-session-owner.test.ts b/apps/desktop/src/lib/browser-desktop-bridge-session-owner.test.tsnew file mode 100644index 00000000000..58048077097--- /dev/null+++ b/apps/desktop/src/lib/browser-desktop-bridge-session-owner.test.ts@@ -0,0 +1,63 @@+import { afterEach, describe, expect, it, vi } from 'vitest'++import { $connection } from '@/store/session'+import { clearWebappSession, seedWebappSession } from '@/test/webapp-session'++import { installBrowserDesktopBridge } from './browser-desktop-bridge'++type ServedWindow = Window & { __HERMES_DASHBOARD_PROFILE__?: string; hermesDesktop?: Window['hermesDesktop'] }++const win = window as unknown as ServedWindow++const row = (id: string, profile: string) => ({ id, profile, title: id })++function stubGateway() {+ const fetchMock = vi.fn(async (url: URL) => {+ const path = url.pathname++ const body = path.endsWith('/api/profiles/sessions/sidebar')+ ? { recents: { sessions: [row('r1', 'default')] }, cron: { sessions: [] }, messaging: { sessions: [row('m1', 'work')] } }+ : path.endsWith('/api/profiles/sessions')+ ? { sessions: [row('a', 'default'), row('b', 'work')], total: 2 }+ : path.endsWith('/api/sessions/a')+ ? row('a', 'default')+ : {}++ return new Response(JSON.stringify(body), { status: 200 })+ })++ vi.stubGlobal('fetch', fetchMock)+}++afterEach(() => {+ delete win.__HERMES_DASHBOARD_PROFILE__+ clearWebappSession()+ Reflect.deleteProperty(win, 'hermesDesktop')+ document.documentElement.removeAttribute('data-hermes-desktop-host')+ $connection.set(null)+ vi.unstubAllGlobals()+ vi.restoreAllMocks()+})++describe('session rows a Webapp tab lists', () => {+ it('name the serving gateway as their owner, as the tab sockets and new chats do', async () => {+ stubGateway()+ win.__HERMES_DASHBOARD_PROFILE__ = 'default'+ seedWebappSession('served-token')+ expect(installBrowserDesktopBridge()).toBe(true)+ const api = win.hermesDesktop!.api++ const all = await api<{ sessions: { connection_id?: string }[] }>({ path: '/api/profiles/sessions?limit=40' })+ expect(all.sessions.map(session => session.connection_id)).toEqual(['local', 'local'])++ const sidebar = await api<Record<string, { sessions: { connection_id?: string }[] }>>({+ path: '/api/profiles/sessions/sidebar?limit=40'+ })++ expect(sidebar.recents.sessions[0].connection_id).toBe('local')+ expect(sidebar.messaging.sessions[0].connection_id).toBe('local')+ await expect(api({ path: '/api/sessions/a' })).resolves.toMatchObject({ connection_id: 'local' })+ // A write's echo is not a listing: Electron's main process leaves those untouched too.+ await expect(api({ path: '/api/sessions/a', method: 'PATCH', body: {} })).resolves.not.toHaveProperty('connection_id')+ })+})diff --git a/apps/desktop/src/lib/browser-desktop-bridge.ts b/apps/desktop/src/lib/browser-desktop-bridge.tsindex 5aabacaed6c..0e94550a1ee 100644--- a/apps/desktop/src/lib/browser-desktop-bridge.ts+++ b/apps/desktop/src/lib/browser-desktop-bridge.ts@@ -1,4 +1,4 @@-import { externalUrlTarget } from '@hermes/shared'+import { externalUrlTarget, LOCAL_CONNECTION_ID } from '@hermes/shared'import type { HermesApiRequest } from '@/global'import { BROWSER_BRIDGE_STUBS } from '@/lib/browser-bridge-stubs'@@ -20,6 +20,7 @@ import { $connection } from '@/store/session'import { windowProfileOverride } from '@/store/windows'import { resolveGatewayVersion } from '../../electron/gateway-version'+import { tagRegistrySessionResponse } from '../../electron/profile-session-routing'/*** Install a capability-limited Desktop bridge when the real renderer is served@@ -43,6 +44,18 @@ export function installBrowserDesktopBridge(): boolean {const api = <T>(request: HermesApiRequest) => browserApi<T>(bootstrap, request)+ // The renderer's REST door, owning session rows the way Electron's main process does: every row+ // this tab lists comes from the one gateway serving it, the `local` source the tab's sockets and+ // new chats already name. An untagged listed row beside a `local` new chat read as two owners,+ // which split one gateway's sessions into an unowned group and a `local` gateway group.+ const rendererApi = async <T>(request: HermesApiRequest): Promise<T> => {+ const response = await api<T>(request)++ return (request.method || 'GET').toUpperCase() === 'GET'+ ? (tagRegistrySessionResponse(request.path, response, LOCAL_CONNECTION_ID) as T)+ : response+ }+const currentProfile = () => $connection.get()?.profile?.trim() || windowProfileOverride()const objectUrls = new Set<string>()@@ -83,7 +96,7 @@ export function installBrowserDesktopBridge(): boolean {...files,...createBrowserDesktopPluginsBridge({ api, files }),...uploads,- api,+ api: rendererApi,// This renderer is built from the serving checkout, so its version is the// server's, read the way native Desktop reads its runtime's.getVersion: async () => ({