Open-source AI teammates in Slack, Teams, Discord, Telegram and Mattermost. Self-host it, with any agent harness and any model.
Python agent-orchestrationaiai-agentschatopsdiscordlangchainmcpmicrosoft-teamsmulti-agentopen-sourceopenaiself-hostedslack
refactor(switchdash): extract navigating to another server's scope (CHOO-1423)
Christian McDermottebee14d2df6e
diff --git a/dash/apps/switchdash-desktop/src/renderer/features/locations/stores/agents-store.ts b/dash/apps/switchdash-desktop/src/renderer/features/locations/stores/agents-store.tsindex 6e1ea478a..96968c0cd 100644--- a/dash/apps/switchdash-desktop/src/renderer/features/locations/stores/agents-store.ts+++ b/dash/apps/switchdash-desktop/src/renderer/features/locations/stores/agents-store.ts@@ -53,6 +53,17 @@ export class AgentsStore {});}+ /** One agent by id, across every location — the palette resolves an agent's+ * provider from a search hit this way, so it can show the same provider mark+ * the sidebar does. */+ agentById(agentId: string): Agent | null {+ for (const agents of this.byLocation.values()) {+ const found = agents.find((a) => a.id === agentId);+ if (found) return found;+ }+ return null;+ }+/** The Switch server a location's agents belong to, or null if unlinked. */serverIdForLocation(locationId: string): string | null {const agents = this.byLocation.get(locationId);diff --git a/dash/apps/switchdash-desktop/src/renderer/features/switch-rooms/session-deeplink-listener.tsx b/dash/apps/switchdash-desktop/src/renderer/features/switch-rooms/session-deeplink-listener.tsxindex 040fccc4b..f0488babd 100644--- a/dash/apps/switchdash-desktop/src/renderer/features/switch-rooms/session-deeplink-listener.tsx+++ b/dash/apps/switchdash-desktop/src/renderer/features/switch-rooms/session-deeplink-listener.tsx@@ -3,8 +3,8 @@ import { toast } from 'sonner';import { agentsStore } from '@renderer/features/locations/stores/agents-store';import { getLocationManagerStore } from '@renderer/features/locations/stores/location-selectors';import { getSessionManagerStore } from '@renderer/features/sessions/stores/session-selectors';-import { switchServersStore } from '@renderer/features/switch-servers/switch-servers-store';import { events } from '@renderer/lib/ipc';+import { scopeToLocationServer } from '@renderer/lib/layout/scope-to-server';import { appState, sidebarStore } from '@renderer/lib/stores/app-state';import { sessionDeeplinkChannel } from '@shared/core/switch-rooms/switchRoomEvents';import { pickDeeplinkTarget } from './session-deeplink-resolve';@@ -78,9 +78,6 @@ export function SessionDeeplinkListener(): null {});return;}- // Scope the sidebar to the session's server first; otherwise its location- // is filtered out of the server-scoped tree and the reveal has nothing- // to expand.console.info('[deeplink] navigating to session', {linkSessionId: sessionId,matchedSessionId: match.sessionId,@@ -88,9 +85,10 @@ export function SessionDeeplinkListener(): null {locationId: match.locationId,roomId,});- if (!agentsStore.loaded) await agentsStore.load();- const serverId = agentsStore.serverIdForLocation(match.locationId);- if (serverId) await switchServersStore.setActive(serverId);+ // Scope the sidebar to the session's server first; otherwise its location+ // is filtered out of the server-scoped tree and the reveal has nothing+ // to expand.+ await scopeToLocationServer(match.locationId);sidebarStore.revealSessionInRoom(match.locationId, roomId);sidebarStore.requestScrollToSession(match.sessionId);appState.navigation.navigate('session', match);diff --git a/dash/apps/switchdash-desktop/src/renderer/lib/layout/scope-to-server.ts b/dash/apps/switchdash-desktop/src/renderer/lib/layout/scope-to-server.tsnew file mode 100644index 000000000..7161b8a2b--- /dev/null+++ b/dash/apps/switchdash-desktop/src/renderer/lib/layout/scope-to-server.ts@@ -0,0 +1,32 @@+import { agentsStore } from '@renderer/features/locations/stores/agents-store';+import { switchRoomsStore } from '@renderer/features/switch-servers/switch-rooms-store';+import { switchServersStore } from '@renderer/features/switch-servers/switch-servers-store';++/**+ * Make a target's Switch server the active one before navigating to it.+ *+ * The active server scopes the whole sidebar — `sidebarStore.isLocationInActiveScope`+ * and `switchRoomsStore.listedRoomsInActiveScope` both filter on it. Navigating+ * to something on another server without this opens the view but leaves the+ * sidebar showing a tree the target is not in, so the row you just opened is+ * nowhere to be seen.+ *+ * A no-op when the target is already on the active server, when its server+ * cannot be resolved (an unlinked location), or when no server is active.+ */+async function activateServer(serverId: string | null): Promise<void> {+ if (!serverId) return;+ if (switchServersStore.activeServerId === serverId) return;+ await switchServersStore.setActive(serverId);+}++/** Scope to the server owning `locationId` — for agents and sessions. */+export async function scopeToLocationServer(locationId: string): Promise<void> {+ if (!agentsStore.loaded) await agentsStore.load();+ await activateServer(agentsStore.serverIdForLocation(locationId));+}++/** Scope to the server owning `roomId`. */+export async function scopeToRoomServer(roomId: string): Promise<void> {+ await activateServer(switchRoomsStore.roomServerId(roomId));+}