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
One rule for whether switch-buddy is offered, and helpers for the buddy and its person
Simon Flack302f8644519b
diff --git a/console/apps/switch-console-desktop/src/renderer/features/deeplinks/open-console-link.ts b/console/apps/switch-console-desktop/src/renderer/features/deeplinks/open-console-link.tsindex 55be638fe..a5043c2ad 100644--- a/console/apps/switch-console-desktop/src/renderer/features/deeplinks/open-console-link.ts+++ b/console/apps/switch-console-desktop/src/renderer/features/deeplinks/open-console-link.ts@@ -2,7 +2,7 @@ import { toast } from 'sonner';import type { AdminSection } from '@renderer/features/admin/admin-sections';import { isAgentSection } from '@renderer/features/managed-agents/agent-sections';import type { SettingsPageTab } from '@renderer/features/settings/components/SettingsPage';-import { isBuddy } from '@renderer/features/switch-buddy/buddy-identity';+import { findBuddy } from '@renderer/features/switch-buddy/buddy-identity';import { switchServersStore } from '@renderer/features/switch-servers/switch-servers-store';import { administersWorkspaceInScope } from '@renderer/features/switch-servers/workspace-admin';import { workspacesStore } from '@renderer/features/workspaces/workspaces-store';@@ -182,7 +182,7 @@ function openAdmin(serverId: string, tab: string | null): void {*/async function openBuddy(serverId: string, tab: string | null): Promise<void> {const agents = await rpc.managedAgents.list(serverId).catch(() => null);- const buddy = agents?.find(isBuddy) ?? null;+ const buddy = findBuddy(agents);if (buddy === null) {appState.navigation.navigate('switchBuddy', { serverId });return;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 9e9180f5c..42e55b467 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@@ -6,6 +6,7 @@ import { useManagedAgents } from '@renderer/features/managed-agents/use-managed-import { BuddyAvatar } from '@renderer/features/switch-buddy/buddy-avatar';import { expectedBuddyName } from '@renderer/features/switch-buddy/buddy-identity';import { useBuddyPending } from '@renderer/features/switch-buddy/buddy-pending';+import { buddyPerson } from '@renderer/features/switch-buddy/buddy-person';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';@@ -89,7 +90,7 @@ export const SidebarMainSection = observer(function SidebarMainSection() {*/const PendingBuddyRow = observer(function PendingBuddyRow({ serverId }: { serverId: string }) {const active = useCurrentViewId() === 'switchBuddy';- const name = expectedBuddyName(switchServersStore.statusFor(serverId)?.user ?? null);+ const name = expectedBuddyName(buddyPerson(serverId));return (<SidebarMenuRowisActive={active}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 865efe9b6..a47e03fc6 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@@ -7,9 +7,6 @@ export const BUDDY_TEMPLATE_ID = 'official:switch-buddy';/** The template's key for the buddy among what it creates. */export const BUDDY_KEY = 'buddy';-/** What the buddy is, whoever's it is: each one is shown by its own name, switch-buddy-<person>. */-export const BUDDY_KIND = 'switch-buddy';-const NAME_PREFIX = 'switch-buddy';/** Agent names are lowercase letters, digits, `.`, `-` and `_`. */@@ -58,6 +55,24 @@ export function isBuddy(return agent.name === NAME_PREFIX || agent.name.startsWith(`${NAME_PREFIX}-`);}+/** The person's buddy among their own agents, if they have one. */+export function findBuddy<T extends Pick<ManagedAgentView, 'name'>>(+ agents: readonly T[] | null | undefined+): T | null {+ return agents?.find(isBuddy) ?? null;+}++/**+ * Whether a server offers switch-buddy: it is made from a template the server+ * serves behind its `switch_buddy` flag, and runs as a managed agent, so+ * agent management must be on too.+ */+export function buddyOffered(+ flags: Pick<FeatureFlags, 'switch_buddy' | 'agent_management'>+): boolean {+ return flags.switch_buddy && flags.agent_management;+}+/*** 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@@ -77,10 +92,9 @@ export function buddyIsPending({return (onboardingBuilt &&serverId !== null &&- flags.switch_buddy &&- flags.agent_management &&+ buddyOffered(flags) &&Array.isArray(agents) &&- !agents.some(isBuddy)+ findBuddy(agents) === null);}diff --git a/console/apps/switch-console-desktop/src/renderer/features/switch-buddy/buddy-intro-dialog.tsx b/console/apps/switch-console-desktop/src/renderer/features/switch-buddy/buddy-intro-dialog.tsxindex 18bfcbb92..010e08225 100644--- a/console/apps/switch-console-desktop/src/renderer/features/switch-buddy/buddy-intro-dialog.tsx+++ b/console/apps/switch-console-desktop/src/renderer/features/switch-buddy/buddy-intro-dialog.tsx@@ -1,18 +1,17 @@import { observer } from 'mobx-react-lite';import { useRef } from 'react';-import { useManagedAgents } from '@renderer/features/managed-agents/use-managed-agents';import { switchServersStore } from '@renderer/features/switch-servers/switch-servers-store';import { workspacesStore } from '@renderer/features/workspaces/workspaces-store';-import { useFeatureFlags } from '@renderer/lib/hooks/useFeatureFlags';import { useCurrentViewId, useNavigate } from '@renderer/lib/layout/navigation-provider';import { Button } from '@renderer/lib/ui/button';import { Dialog, DialogContent } from '@renderer/lib/ui/dialog';import { ONBOARDING_BACKDROP } from '@renderer/lib/ui/wizard-frame';-import { BUILD_FEATURE_FLAGS } from '@shared/core/feature-flags/feature-flags';import { BuddyAvatar } from './buddy-avatar';-import { firstNameOf, isBuddy } from './buddy-identity';+import { firstNameOf } from './buddy-identity';import { BuddyIntroLines } from './buddy-intro-lines';import { buddyIntroStore } from './buddy-intro-store';+import { useBuddyPending } from './buddy-pending';+import { buddyPerson } from './buddy-person';import { reportBuddyStep } from './buddy-telemetry';/**@@ -26,24 +25,19 @@ export const BuddyIntroDialog = observer(function BuddyIntroDialog() {const { navigate } = useNavigate();const meetRef = useRef<HTMLButtonElement>(null);const serverId = switchServersStore.activeServerId;- const flags = useFeatureFlags(serverId);- const agents = useManagedAgents(serverId);+ const pending = useBuddyPending(serverId);const workspaceId = serverId ? workspacesStore.idOnServerInScope(serverId) : null;const onBuddyPage = useCurrentViewId() === 'switchBuddy';- const user = serverId ? (switchServersStore.statusFor(serverId)?.user ?? null) : null;if (- !BUILD_FEATURE_FLAGS.onboarding ||+ !pending ||onBuddyPage ||buddyIntroStore.skippedThisSession ||serverId === null ||workspaceId === null ||- !flags.switch_buddy ||- !flags.agent_management ||- !agents.data ||- agents.data.some(isBuddy) ||buddyIntroStore.isAnswered(workspaceId))return null;+ const person = buddyPerson(serverId);const notNow = () => {buddyIntroStore.answered(workspaceId);@@ -71,7 +65,7 @@ export const BuddyIntroDialog = observer(function BuddyIntroDialog() {</h2><p className="text-sm text-foreground-muted">Your first AI assistant in Switch</p></div>- <BuddyIntroLines firstName={firstNameOf(user?.name)} />+ <BuddyIntroLines firstName={firstNameOf(person.name)} /></div><div className="flex justify-center gap-2 px-8 pt-2 pb-8"><Button variant="ghost" onClick={notNow}>diff --git a/console/apps/switch-console-desktop/src/renderer/features/switch-buddy/buddy-person.ts b/console/apps/switch-console-desktop/src/renderer/features/switch-buddy/buddy-person.tsnew file mode 100644index 000000000..474ac6290--- /dev/null+++ b/console/apps/switch-console-desktop/src/renderer/features/switch-buddy/buddy-person.ts@@ -0,0 +1,10 @@+import { switchServersStore } from '@renderer/features/switch-servers/switch-servers-store';++/** Who a person is to their buddy: what it is named after and greets them by. */+export type BuddyPerson = { name: string | null; email: string | null };++/** The person signed in to the server, as the buddy knows them; nobody while unknown. */+export function buddyPerson(serverId: string): BuddyPerson {+ const user = switchServersStore.statusFor(serverId)?.user ?? null;+ return { name: user?.name ?? null, email: user?.email ?? null };+}diff --git a/console/apps/switch-console-desktop/src/renderer/features/switch-buddy/buddy-step.tsx b/console/apps/switch-console-desktop/src/renderer/features/switch-buddy/buddy-step.tsxindex 41134a403..e10bd9aae 100644--- a/console/apps/switch-console-desktop/src/renderer/features/switch-buddy/buddy-step.tsx+++ b/console/apps/switch-console-desktop/src/renderer/features/switch-buddy/buddy-step.tsx@@ -4,6 +4,7 @@ import { rpc } from '@renderer/lib/ipc';import { Button } from '@renderer/lib/ui/button';import { Spinner } from '@renderer/lib/ui/spinner';import { OnboardingSurface, useWizardExit } from '@renderer/lib/ui/wizard-frame';+import { buddyOffered } from './buddy-identity';import { MeetBuddyPage } from './meet-buddy-page';/**@@ -42,7 +43,7 @@ export function BuddyStep({const { data } = await rpc.featureFlags.get(serverId);// Flags that could not be read are not an answer: off would skip the buddy on a guess.if (data.error !== null) throw new Error(data.error);- if (live) setOffered(data.flags.switch_buddy && data.flags.agent_management);+ if (live) setOffered(buddyOffered(data.flags));} catch (cause) {if (live)setOffered({ error: failureText(cause, 'Could not ask the server what it offers.') });diff --git a/console/apps/switch-console-desktop/src/renderer/features/switch-buddy/create-buddy.ts b/console/apps/switch-console-desktop/src/renderer/features/switch-buddy/create-buddy.tsindex 04c83497f..e9b34cc98 100644--- a/console/apps/switch-console-desktop/src/renderer/features/switch-buddy/create-buddy.ts+++ b/console/apps/switch-console-desktop/src/renderer/features/switch-buddy/create-buddy.ts@@ -1,7 +1,7 @@import { workspacesStore } from '@renderer/features/workspaces/workspaces-store';import { rpc } from '@renderer/lib/ipc';import type { UiEntryPoint } from '@shared/core/telemetry/reporting';-import { BUDDY_TEMPLATE_ID, buddyAgentName, isBuddy } from './buddy-identity';+import { BUDDY_TEMPLATE_ID, buddyAgentName, findBuddy } from './buddy-identity';import { reportBuddyStep } from './buddy-telemetry';/** How many names to try when someone else in the workspace already has the one picked. */@@ -45,7 +45,7 @@ async function createBuddyAgent(input: {entryPoint: UiEntryPoint;}): Promise<{ agentId: string; name: string }> {const existing = (await rpc.managedAgents.list(input.serverId)) ?? [];- const mine = existing.find(isBuddy);+ const mine = findBuddy(existing);if (mine) return { agentId: mine.agentId, name: mine.name };const template = await rpc.workspaces.getTemplateDetail({workspaceId: input.workspaceId,diff --git a/console/apps/switch-console-desktop/src/renderer/features/switch-buddy/meet-buddy-page.tsx b/console/apps/switch-console-desktop/src/renderer/features/switch-buddy/meet-buddy-page.tsxindex c607a35d1..fa48d6a73 100644--- a/console/apps/switch-console-desktop/src/renderer/features/switch-buddy/meet-buddy-page.tsx+++ b/console/apps/switch-console-desktop/src/renderer/features/switch-buddy/meet-buddy-page.tsx@@ -3,7 +3,6 @@ import { motion } from 'motion/react';import { useEffect, useMemo, useRef, useState } from 'react';import { useManagedAgents } from '@renderer/features/managed-agents/use-managed-agents';import { onboardingStore } from '@renderer/features/onboarding/onboarding-store';-import { switchServersStore } from '@renderer/features/switch-servers/switch-servers-store';import { AgentIcon } from '@renderer/lib/components/agent-icon';import { failureText } from '@renderer/lib/errors/describe-failure';import { report } from '@renderer/lib/telemetry/report';@@ -12,7 +11,8 @@ import { Spinner } from '@renderer/lib/ui/spinner';import { OnboardingSurface, useWizardExit } from '@renderer/lib/ui/wizard-frame';import { agentProviders } from '@shared/core/providers/agent-provider-registry';import { BuddyAvatar } from './buddy-avatar';-import { firstNameOf, isBuddy } from './buddy-identity';+import { findBuddy, firstNameOf } from './buddy-identity';+import { buddyPerson } from './buddy-person';import { buddyProviders, startButtons } from './buddy-providers';import { reportBuddyStep } from './buddy-telemetry';import { createBuddy } from './create-buddy';@@ -86,11 +86,11 @@ export const MeetBuddyPage = observer(function MeetBuddyPage({() => (firstDecided ?? []).flatMap((id) => providers.filter((provider) => provider.id === id)),[firstDecided, providers]);- const existing = useManagedAgents(serverId).data?.find(isBuddy) ?? null;+ const existing = findBuddy(useManagedAgents(serverId).data);const [starting, setStarting] = useState<string | null>(null);const [error, setError] = useState<string | null>(null);- const user = switchServersStore.statusFor(serverId)?.user ?? null;- const firstName = firstNameOf(user?.name);+ const person = buddyPerson(serverId);+ const firstName = firstNameOf(person.name);// The opening plays once: back from setting up a provider, it is at rest.const introPlayed = useRef(false);@@ -135,7 +135,7 @@ export const MeetBuddyPage = observer(function MeetBuddyPage({workspaceId,machineId: computer.machine.id,provider: providerId,- person: { name: user?.name ?? null, email: user?.email ?? null },+ person,entryPoint: 'onboarding',}));diff --git a/console/apps/switch-console-desktop/src/renderer/features/switch-buddy/open-buddy.ts b/console/apps/switch-console-desktop/src/renderer/features/switch-buddy/open-buddy.tsindex 06d732e13..ddfb3658a 100644--- a/console/apps/switch-console-desktop/src/renderer/features/switch-buddy/open-buddy.ts+++ b/console/apps/switch-console-desktop/src/renderer/features/switch-buddy/open-buddy.ts@@ -1,12 +1,12 @@import { focusComposerWhenOpened } from '@renderer/features/chats/components/chat-composer';import { chatsStore, chatTitler } from '@renderer/features/chats/stores/chats';-import { switchServersStore } from '@renderer/features/switch-servers/switch-servers-store';import { failureText } from '@renderer/lib/errors/describe-failure';import { toast } from '@renderer/lib/hooks/use-toast';import { rpc } from '@renderer/lib/ipc';import { appState } from '@renderer/lib/stores/app-state';import type { ChatSummary } from '@shared/core/chats/chats';import { firstNameOf } from './buddy-identity';+import { buddyPerson } from './buddy-person';import { buddyWelcomeMessage } from './buddy-welcome-message';/** What the buddy's first chat is called, as on the board; it keeps it. */@@ -28,14 +28,16 @@ async function buddyChat();const existing = direct.find((chat) => chat.name === BUDDY_CHAT_NAME) ?? direct[0];if (existing) return existing;- const user = switchServersStore.statusFor(serverId)?.user ?? null;const chat = await rpc.chats.create({serverId,agentIds: [agentId],name: BUDDY_CHAT_NAME,requestId: crypto.randomUUID(),// Said by the buddy as it joins the chat, in place of its usual line.- greeting: buddyWelcomeMessage({ firstName: firstNameOf(user?.name), agentName: agent.name }),+ greeting: buddyWelcomeMessage({+ firstName: firstNameOf(buddyPerson(serverId).name),+ agentName: agent.name,+ }),});chatsStore.add(serverId, chat);// Named here, so its first message does not rename it.diff --git a/console/apps/switch-console-desktop/src/renderer/features/switch-buddy/provider-setup.tsx b/console/apps/switch-console-desktop/src/renderer/features/switch-buddy/provider-setup.tsxindex 7d609a0f3..d4272e8cd 100644--- a/console/apps/switch-console-desktop/src/renderer/features/switch-buddy/provider-setup.tsx+++ b/console/apps/switch-console-desktop/src/renderer/features/switch-buddy/provider-setup.tsx@@ -2,7 +2,6 @@ import { CircleAlert, ExternalLink } from 'lucide-react';import { observer } from 'mobx-react-lite';import { useCallback, useEffect, useMemo, useState } from 'react';import { LogTail } from '@renderer/features/switch-servers/log-tail';-import { switchServersStore } from '@renderer/features/switch-servers/switch-servers-store';import { AgentIcon } from '@renderer/lib/components/agent-icon';import { failureText } from '@renderer/lib/errors/describe-failure';import { events, rpc } from '@renderer/lib/ipc';@@ -15,6 +14,7 @@ import { agentProviders, requireProvider } from '@shared/core/providers/agent-primport { linksIn } from '@shared/core/providers/provider-login';import type { UiEntryPoint } from '@shared/core/telemetry/reporting';import { providerLoginExitChannel, providerLoginLineChannel } from '@shared/events/appEvents';+import { buddyPerson } from './buddy-person';import { type BuddyProvider, buddyProviders } from './buddy-providers';import { reportBuddyStep } from './buddy-telemetry';import { createBuddy } from './create-buddy';@@ -142,7 +142,6 @@ export const ProviderSetup = observer(function ProviderSetup({reportBuddyStep('start', provider.id);setBusy('create');setError(null);- const user = switchServersStore.statusFor(serverId)?.user ?? null;try {onCreated(await createBuddy({@@ -150,7 +149,7 @@ export const ProviderSetup = observer(function ProviderSetup({workspaceId,machineId: computer.machine.id,provider: provider.id,- person: { name: user?.name ?? null, email: user?.email ?? null },+ person: buddyPerson(serverId),entryPoint,}));diff --git a/console/apps/switch-console-desktop/src/renderer/features/switch-buddy/switch-buddy-view.tsx b/console/apps/switch-console-desktop/src/renderer/features/switch-buddy/switch-buddy-view.tsxindex 25079c782..33a0662b8 100644--- a/console/apps/switch-console-desktop/src/renderer/features/switch-buddy/switch-buddy-view.tsx+++ b/console/apps/switch-console-desktop/src/renderer/features/switch-buddy/switch-buddy-view.tsx@@ -6,14 +6,14 @@ import { AgentProfile } from '@renderer/features/managed-agents/agent-profile';import { agentSections } from '@renderer/features/managed-agents/agent-sections';import { useManagedAgents } from '@renderer/features/managed-agents/use-managed-agents';import { SidebarMenuRow } from '@renderer/features/sidebar/sidebar-primitives';-import { switchServersStore } from '@renderer/features/switch-servers/switch-servers-store';import { workspacesStore } from '@renderer/features/workspaces/workspaces-store';import { Titlebar } from '@renderer/lib/components/titlebar/Titlebar';import { useFeatureFlags } from '@renderer/lib/hooks/useFeatureFlags';import { useParams } from '@renderer/lib/layout/navigation-provider';import { showModal } from '@renderer/lib/modal/modal-provider';import { BUDDY_ICON_URL } from '@shared/core/agents/switch-buddy';-import { expectedBuddyName, firstNameOf, isBuddy } from './buddy-identity';+import { expectedBuddyName, findBuddy, firstNameOf } from './buddy-identity';+import { buddyPerson } from './buddy-person';import { reportBuddyStep } from './buddy-telemetry';import { BuddyWelcome } from './buddy-welcome';import { BUDDY_CHAT_NAME, openBuddyChat } from './open-buddy';@@ -55,9 +55,9 @@ const SwitchBuddyPanel = observer(function SwitchBuddyPanel() {const { params } = useParams('switchBuddy');const { serverId } = params;const managed = useManagedAgents(serverId);- const buddy = managed.data?.find(isBuddy) ?? null;+ const buddy = findBuddy(managed.data);const workspaceId = workspacesStore.idOnServerInScope(serverId);- const user = switchServersStore.statusFor(serverId)?.user ?? null;+ const person = buddyPerson(serverId);const serviceConnections = useFeatureFlags(serverId).service_connections;useEffect(() => {@@ -78,7 +78,7 @@ const SwitchBuddyPanel = observer(function SwitchBuddyPanel() {<div className="flex h-full min-h-0"><div className="flex w-[300px] shrink-0 flex-col overflow-y-auto border-r border-border p-2"><AgentProfile- name={expectedBuddyName(user)}+ name={expectedBuddyName(person)}iconUrl={BUDDY_ICON_URL}serverId={serverId}machine={{@@ -105,7 +105,10 @@ const SwitchBuddyPanel = observer(function SwitchBuddyPanel() {<div className="flex min-w-0 flex-1 flex-col bg-background text-foreground"><div className="min-h-0 flex-1 overflow-auto"><div className="mx-auto w-full max-w-[860px] px-5 py-6">- <BuddyWelcome firstName={firstNameOf(user?.name)} agentName={expectedBuddyName(user)} />+ <BuddyWelcome+ firstName={firstNameOf(person.name)}+ agentName={expectedBuddyName(person)}+ /></div></div><div className="mx-auto w-full max-w-[860px] px-5 pb-5">@@ -115,7 +118,7 @@ const SwitchBuddyPanel = observer(function SwitchBuddyPanel() {disabled={workspaceId === null}className="w-full rounded-full border border-border bg-background px-5 py-3 text-left text-sm text-foreground shadow-sm hover:bg-[var(--sel-soft)] disabled:opacity-60">- Connect an AI provider to chat with {expectedBuddyName(user)}+ Connect an AI provider to chat with {expectedBuddyName(person)}</button>{workspaceId === null && (<p className="mt-2 text-xs text-foreground-muted">