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
fix(console): keep switch-buddy in the sidebar while it waits on a provider (#926)
Louis Amaudruz92a1dbf93f83
diff --git a/console/apps/switch-console-desktop/src/renderer/features/sidebar/main-section.tsx b/console/apps/switch-console-desktop/src/renderer/features/sidebar/main-section.tsxindex ee8294138..d2d7315d6 100644--- a/console/apps/switch-console-desktop/src/renderer/features/sidebar/main-section.tsx+++ b/console/apps/switch-console-desktop/src/renderer/features/sidebar/main-section.tsx@@ -4,7 +4,8 @@ import { useState } from 'react';import { ManagedAgentList } from '@renderer/features/managed-agents/managed-agent-list';import { useManagedAgents } from '@renderer/features/managed-agents/use-managed-agents';import { BuddyAvatar } from '@renderer/features/switch-buddy/buddy-avatar';-import { expectedBuddyName, isBuddy } from '@renderer/features/switch-buddy/buddy-identity';+import { expectedBuddyName } from '@renderer/features/switch-buddy/buddy-identity';+import { useBuddyPending } from '@renderer/features/switch-buddy/buddy-pending';import { switchServersStore } from '@renderer/features/switch-servers/switch-servers-store';import { useListedRoomsInActiveScope } from '@renderer/features/switch-servers/use-listed-rooms';import { BridgeIcon, hasBridgeIcon } from '@renderer/lib/components/bridge-icon';@@ -43,6 +44,7 @@ export const SidebarMainSection = observer(function SidebarMainSection() {const [tab, setTab] = useState<MainTab>(storedTab);const agents = useManagedAgents(switchServersStore.activeServerId);const flags = useFeatureFlags(switchServersStore.activeServerId);+ const buddyPending = useBuddyPending(switchServersStore.activeServerId);const rooms = useListedRoomsInActiveScope();// No count until the agents are read: a 0 that turns into the real number// a moment later reads as the list changing.@@ -65,13 +67,9 @@ export const SidebarMainSection = observer(function SidebarMainSection() {</div>{tab === 'agents' ? (<>- {BUILD_FEATURE_FLAGS.onboarding &&- flags.switch_buddy &&- switchServersStore.activeServerId !== null &&- agents.data &&- !agents.data.some(isBuddy) && (- <PendingBuddyRow serverId={switchServersStore.activeServerId} />- )}+ {buddyPending && switchServersStore.activeServerId !== null && (+ <PendingBuddyRow serverId={switchServersStore.activeServerId} />+ )}<ManagedAgentList />{agents.data?.length === 0 && !BUILD_FEATURE_FLAGS.onboarding && (<p className="px-[9px] py-2 text-xs text-foreground-muted">No agents yet.</p>diff --git a/console/apps/switch-console-desktop/src/renderer/features/sidebar/sidebar-empty-state.test.ts b/console/apps/switch-console-desktop/src/renderer/features/sidebar/sidebar-empty-state.test.tsindex c4d653dac..fd808129e 100644--- a/console/apps/switch-console-desktop/src/renderer/features/sidebar/sidebar-empty-state.test.ts+++ b/console/apps/switch-console-desktop/src/renderer/features/sidebar/sidebar-empty-state.test.ts@@ -1,5 +1,5 @@import { expect, it } from 'vitest';-import { sidebarEmptyState } from './sidebar-empty-state';+import { showsAgentsAndRooms, sidebarEmptyState } from './sidebar-empty-state';const empty = {grouping: 'agent' as const,@@ -29,3 +29,18 @@ it('says filters matched nothing only in the agent view', () => {expect(sidebarEmptyState(filtered)).toBe('no-filter-match');expect(sidebarEmptyState({ ...filtered, grouping: 'room' })).toBeNull();});++it('keeps Agents / Rooms, and so switch-buddy, beside legacy agents while the buddy waits on a provider', () => {+ expect(+ showsAgentsAndRooms({ managedAgentCount: 0, buddyPending: true, legacyAgentCount: 3 })+ ).toBe(true);+ expect(+ showsAgentsAndRooms({ managedAgentCount: 0, buddyPending: false, legacyAgentCount: 3 })+ ).toBe(false);+ expect(+ showsAgentsAndRooms({ managedAgentCount: 0, buddyPending: false, legacyAgentCount: 0 })+ ).toBe(true);+ expect(+ showsAgentsAndRooms({ managedAgentCount: 1, buddyPending: false, legacyAgentCount: 3 })+ ).toBe(true);+});diff --git a/console/apps/switch-console-desktop/src/renderer/features/sidebar/sidebar-empty-state.ts b/console/apps/switch-console-desktop/src/renderer/features/sidebar/sidebar-empty-state.tsindex 612f50da7..64a6ce048 100644--- a/console/apps/switch-console-desktop/src/renderer/features/sidebar/sidebar-empty-state.ts+++ b/console/apps/switch-console-desktop/src/renderer/features/sidebar/sidebar-empty-state.ts@@ -32,3 +32,17 @@ export function sidebarEmptyState(input: {return 'empty';return null;}++/**+ * Whether the sidebar shows Agents / Rooms under agent management: once+ * anything is managed, while switch-buddy waits on a provider (its row is the+ * way back to its page), or with no agents at all, where there is nothing+ * legacy to show instead.+ */+export function showsAgentsAndRooms(input: {+ managedAgentCount: number;+ buddyPending: boolean;+ legacyAgentCount: number;+}): boolean {+ return input.managedAgentCount > 0 || input.buddyPending || input.legacyAgentCount === 0;+}diff --git a/console/apps/switch-console-desktop/src/renderer/features/sidebar/sidebar-grouped-list.tsx b/console/apps/switch-console-desktop/src/renderer/features/sidebar/sidebar-grouped-list.tsxindex e174a430d..9d9b6cc1c 100644--- a/console/apps/switch-console-desktop/src/renderer/features/sidebar/sidebar-grouped-list.tsx+++ b/console/apps/switch-console-desktop/src/renderer/features/sidebar/sidebar-grouped-list.tsx@@ -5,6 +5,7 @@ import { useEffect, useRef } from 'react';import { ManagedAgentList } from '@renderer/features/managed-agents/managed-agent-list';import { useManagedAgents } from '@renderer/features/managed-agents/use-managed-agents';import { hostReachabilityStore } from '@renderer/features/remote-hosts/host-reachability-store';+import { useBuddyPending } from '@renderer/features/switch-buddy/buddy-pending';import { switchRoomsStore as roomConnectionsStore } from '@renderer/features/switch-rooms/switch-rooms-store';import { isFrozenServer } from '@renderer/features/switch-servers/managed-server-state';import { switchRoomsStore } from '@renderer/features/switch-servers/switch-rooms-store';@@ -20,7 +21,7 @@ import { RoomTree } from './room-tree';import { SessionDiscoveryStatus } from './session-discovery-status';import { SessionsSectionHeader } from './sessions-section-header';import { useScrollSelectionIntoView } from './sidebar-auto-scroll';-import { sidebarEmptyState } from './sidebar-empty-state';+import { showsAgentsAndRooms, sidebarEmptyState } from './sidebar-empty-state';import { agentsInActiveScope, refreshSidebarRoomState } from './sidebar-tree-data';/**@@ -98,6 +99,7 @@ export const SidebarGroupedList = observer(function SidebarGroupedList() {const managedAgents = useManagedAgents(switchServersStore.activeServerId);const activeServerId = switchServersStore.activeServerId;const managementMode = useAgentManagementMode();+ const buddyPending = useBuddyPending(activeServerId);const listedRooms = useListedRoomsInActiveScope();const managedAgentCount = activeServerId && managedAgents.data ? managedAgents.data.length : 0;const emptyState = sidebarEmptyState({@@ -121,10 +123,13 @@ export const SidebarGroupedList = observer(function SidebarGroupedList() {className="flex min-h-0 flex-1 flex-col gap-[2px] overflow-y-auto px-2.5 pt-0 pb-3"><RoomStateDisclosure />- {/* Agents / Rooms once anything is managed, or on an install with no- agents yet, where there is nothing legacy to show. Sessions only- while some agent still runs the old way, and gone once none does. */}- {(managedAgentCount > 0 || legacyCount === 0) && <SidebarMainSection />}+ {/* Sessions only while some agent still runs the old way, and gone+ once none does. */}+ {showsAgentsAndRooms({+ managedAgentCount,+ buddyPending,+ legacyAgentCount: legacyCount,+ }) && <SidebarMainSection />}{legacyCount > 0 && (<><SessionsSectionHeader legacy />diff --git a/console/apps/switch-console-desktop/src/renderer/features/switch-buddy/buddy-identity.test.ts b/console/apps/switch-console-desktop/src/renderer/features/switch-buddy/buddy-identity.test.tsindex f912510af..dba86e4d1 100644--- a/console/apps/switch-console-desktop/src/renderer/features/switch-buddy/buddy-identity.test.ts+++ b/console/apps/switch-console-desktop/src/renderer/features/switch-buddy/buddy-identity.test.ts@@ -1,5 +1,5 @@import { describe, expect, it } from 'vitest';-import { buddyAgentName, isBuddy } from './buddy-identity';+import { buddyAgentName, buddyIsPending, isBuddy } from './buddy-identity';describe('buddyAgentName', () => {it('names the buddy after its person', () => {@@ -29,3 +29,34 @@ describe('isBuddy', () => {expect(isBuddy({ name: 'switch-buddyish' })).toBe(false);});});++describe('buddyIsPending', () => {+ const offered = {+ onboardingBuilt: true,+ serverId: 'srv-1',+ flags: { switch_buddy: true, agent_management: true },+ agents: [],+ };++ it('is pending on a server that offers it, to someone with no buddy', () => {+ expect(buddyIsPending(offered)).toBe(true);+ expect(buddyIsPending({ ...offered, agents: [{ name: 'reviewer' }] })).toBe(true);+ });++ it('is not once the person has a buddy', () => {+ expect(buddyIsPending({ ...offered, agents: [{ name: 'switch-buddy-max' }] })).toBe(false);+ });++ it('is not while their agents are unknown, or where the buddy is not offered', () => {+ expect(buddyIsPending({ ...offered, agents: undefined })).toBe(false);+ expect(buddyIsPending({ ...offered, agents: null })).toBe(false);+ expect(buddyIsPending({ ...offered, serverId: null })).toBe(false);+ expect(buddyIsPending({ ...offered, onboardingBuilt: false })).toBe(false);+ expect(+ buddyIsPending({ ...offered, flags: { switch_buddy: false, agent_management: true } })+ ).toBe(false);+ expect(+ buddyIsPending({ ...offered, flags: { switch_buddy: true, agent_management: false } })+ ).toBe(false);+ });+});diff --git a/console/apps/switch-console-desktop/src/renderer/features/switch-buddy/buddy-identity.ts b/console/apps/switch-console-desktop/src/renderer/features/switch-buddy/buddy-identity.tsindex 7fdebbe26..54843297e 100644--- a/console/apps/switch-console-desktop/src/renderer/features/switch-buddy/buddy-identity.ts+++ b/console/apps/switch-console-desktop/src/renderer/features/switch-buddy/buddy-identity.ts@@ -1,3 +1,4 @@+import type { FeatureFlags } from '@shared/core/feature-flags/feature-flags';import type { ManagedAgentView } from '@shared/core/managed-agents/managed-agents';/** The template every person's buddy is created from, served by the server. */@@ -46,6 +47,32 @@ export function isBuddy(agent: Pick<ManagedAgentView, 'name'>): boolean {return agent.name === NAME_PREFIX || agent.name.startsWith(`${NAME_PREFIX}-`);}+/**+ * Whether the server offers switch-buddy and the person has none yet: it is+ * waiting on an AI provider. Not while their agents are still unknown, so a+ * buddy that exists is never drawn as missing.+ */+export function buddyIsPending({+ onboardingBuilt,+ serverId,+ flags,+ agents,+}: {+ onboardingBuilt: boolean;+ serverId: string | null;+ flags: Pick<FeatureFlags, 'switch_buddy' | 'agent_management'>;+ agents: Pick<ManagedAgentView, 'name'>[] | null | undefined;+}): boolean {+ return (+ onboardingBuilt &&+ serverId !== null &&+ flags.switch_buddy &&+ flags.agent_management &&+ Array.isArray(agents) &&+ !agents.some(isBuddy)+ );+}+/** The first name to greet someone by: the first word of their name. */export function firstNameOf(name: string | null | undefined): string | null {return name?.trim().split(/\s+/)[0] || null;diff --git a/console/apps/switch-console-desktop/src/renderer/features/switch-buddy/buddy-pending.ts b/console/apps/switch-console-desktop/src/renderer/features/switch-buddy/buddy-pending.tsnew file mode 100644index 000000000..c7b5591ea--- /dev/null+++ b/console/apps/switch-console-desktop/src/renderer/features/switch-buddy/buddy-pending.ts@@ -0,0 +1,16 @@+import { useManagedAgents } from '@renderer/features/managed-agents/use-managed-agents';+import { useFeatureFlags } from '@renderer/lib/hooks/useFeatureFlags';+import { BUILD_FEATURE_FLAGS } from '@shared/core/feature-flags/feature-flags';+import { buddyIsPending } from './buddy-identity';++/** @see buddyIsPending, on the server given. */+export function useBuddyPending(serverId: string | null): boolean {+ const flags = useFeatureFlags(serverId);+ const agents = useManagedAgents(serverId);+ return buddyIsPending({+ onboardingBuilt: BUILD_FEATURE_FLAGS.onboarding,+ serverId,+ flags,+ agents: agents.data,+ });+}