Skip to content

Open-source AI teammates in Slack, Teams, Discord, Telegram and Mattermost. Self-host it, with any agent harness and any model.

Keep onboarding out of switch-buddy's internals, and the buddy out of onboarding's

Simon Flack7b2f0b877c92
diff --git a/console/apps/switch-console-desktop/src/renderer/features/onboarding/onboarding-flow.tsx b/console/apps/switch-console-desktop/src/renderer/features/onboarding/onboarding-flow.tsx
index 92b81bdf3..9e1bfb277 100644
--- a/console/apps/switch-console-desktop/src/renderer/features/onboarding/onboarding-flow.tsx
+++ b/console/apps/switch-console-desktop/src/renderer/features/onboarding/onboarding-flow.tsx
@@ -1,8 +1,7 @@
import { observer } from 'mobx-react-lite';
import { Fragment, useEffect, useState } from 'react';
-import { buddyIntroStore } from '@renderer/features/switch-buddy/buddy-intro-store';
import { BuddyStep } from '@renderer/features/switch-buddy/buddy-step';
-import { openBuddyChat } from '@renderer/features/switch-buddy/open-buddy';
+import { openBuddyAfterOnboarding } from '@renderer/features/switch-buddy/open-buddy';
import {
ExternalServerStep,
LocalSetupStep,
@@ -143,11 +142,7 @@ export const OnboardingFlow = observer(function OnboardingFlow() {
// is still on screen: ending the flow first would draw the app's home
// page for the moment that takes, then jump to the buddy.
await switchServersStore.setActive(serverId);
- if (agent) await openBuddyChat(serverId, agent);
- else {
- buddyIntroStore.skipped();
- navigate('switchBuddy', { serverId });
- }
+ await openBuddyAfterOnboarding(serverId, agent);
onboardingStore.reset();
};
@@ -332,6 +327,9 @@ function currentPage(
serverId={server.id}
workspaceId={workspaceId}
onCreated={(agent) => void finishWithBuddy(server.id, agent)}
+ onSetupOpened={() =>
+ report('onboarding_page', { page: 'provider_setup', path: onboardingStore.via })
+ }
onSkip={() => void finishWithBuddy(server.id, null)}
onNotOffered={() => finish(server.id)}
/>
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.tsx
index e10bd9aae..2e3fb3437 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
@@ -22,12 +22,15 @@ export function BuddyStep({
workspaceId,
onCreated,
onSkip,
+ onSetupOpened,
onNotOffered,
}: {
serverId: string;
workspaceId: string;
onCreated: (agent: { agentId: string; name: string }) => void;
onSkip: () => void;
+ /** The person chose to set up a provider other than those already signed in, for the flow to count. */
+ onSetupOpened: () => void;
onNotOffered: () => void;
}) {
const exit = useWizardExit();
@@ -90,6 +93,7 @@ export function BuddyStep({
workspaceId={workspaceId}
onCreated={onCreated}
onSkip={onSkip}
+ onSetupOpened={onSetupOpened}
/>
);
}
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.tsx
index 23f22a263..9d45c74aa 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
@@ -2,9 +2,7 @@ import { observer } from 'mobx-react-lite';
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 { AgentIcon } from '@renderer/lib/components/agent-icon';
-import { report } from '@renderer/lib/telemetry/report';
import { Button } from '@renderer/lib/ui/button';
import { Spinner } from '@renderer/lib/ui/spinner';
import { OnboardingSurface, useWizardExit } from '@renderer/lib/ui/wizard-frame';
@@ -44,11 +42,14 @@ export const MeetBuddyPage = observer(function MeetBuddyPage({
workspaceId,
onCreated,
onSkip,
+ onSetupOpened,
}: {
serverId: string;
workspaceId: string;
onCreated: (agent: { agentId: string; name: string }) => void;
onSkip: () => void;
+ /** The person opened the other providers' setup, for the page that holds this one to count. */
+ onSetupOpened: () => void;
}) {
const exit = useWizardExit();
const [settingUp, setSettingUp] = useState(false);
@@ -105,7 +106,7 @@ export const MeetBuddyPage = observer(function MeetBuddyPage({
const openSetup = () => {
reportBuddyStep('setup_opened', null);
- report('onboarding_page', { page: 'provider_setup', path: onboardingStore.via });
+ onSetupOpened();
setSettingUp(true);
};
diff --git a/console/apps/switch-console-desktop/src/renderer/features/switch-buddy/open-buddy.test.ts b/console/apps/switch-console-desktop/src/renderer/features/switch-buddy/open-buddy.test.ts
index 4a7f18006..c4a67dea4 100644
--- a/console/apps/switch-console-desktop/src/renderer/features/switch-buddy/open-buddy.test.ts
+++ b/console/apps/switch-console-desktop/src/renderer/features/switch-buddy/open-buddy.test.ts
@@ -7,6 +7,7 @@ const toast = vi.hoisted(() => vi.fn());
const focusComposerWhenOpened = vi.hoisted(() => vi.fn());
const addChat = vi.hoisted(() => vi.fn());
const titled = vi.hoisted(() => vi.fn());
+const skipped = vi.hoisted(() => vi.fn());
vi.mock('@renderer/lib/ipc', () => ({
rpc: { chats: { list: listChats, create: createChat } },
@@ -23,12 +24,13 @@ vi.mock('@renderer/features/chats/stores/chats', () => ({
vi.mock('@renderer/features/switch-servers/switch-servers-store', () => ({
switchServersStore: { statusFor: () => ({ user: { name: 'Max Tam' } }) },
}));
+vi.mock('./buddy-intro-store', () => ({ buddyIntroStore: { skipped } }));
vi.mock('./buddy-welcome-message', () => ({
buddyWelcomeMessage: ({ firstName, agentName }: { firstName: string; agentName: string }) =>
`welcome ${firstName} from ${agentName}`,
}));
-const { BUDDY_CHAT_NAME, openBuddyChat } = await import('./open-buddy');
+const { BUDDY_CHAT_NAME, openBuddyAfterOnboarding, openBuddyChat } = await import('./open-buddy');
const buddy = { agentId: 'a-1', name: 'switch-buddy-max' };
@@ -111,3 +113,25 @@ describe('openBuddyChat', () => {
});
});
});
+
+describe('openBuddyAfterOnboarding', () => {
+ it("ends the first run in the buddy's chat once it exists", async () => {
+ listChats.mockResolvedValue([chat('r-welcome', BUDDY_CHAT_NAME)]);
+
+ await openBuddyAfterOnboarding('srv-1', buddy);
+
+ expect(navigate).toHaveBeenCalledWith(
+ 'managedAgent',
+ expect.objectContaining({ roomId: 'r-welcome' })
+ );
+ expect(skipped).not.toHaveBeenCalled();
+ });
+
+ it('else on its page, keeping its pop-up away for this launch', async () => {
+ await openBuddyAfterOnboarding('srv-1', null);
+
+ expect(navigate).toHaveBeenCalledWith('switchBuddy', { serverId: 'srv-1' });
+ expect(skipped).toHaveBeenCalledTimes(1);
+ expect(listChats).not.toHaveBeenCalled();
+ });
+});
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.ts
index ddfb3658a..7dfbc548c 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
@@ -6,6 +6,7 @@ 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 { buddyIntroStore } from './buddy-intro-store';
import { buddyPerson } from './buddy-person';
import { buddyWelcomeMessage } from './buddy-welcome-message';
@@ -71,3 +72,20 @@ export async function openBuddyChat(
...(roomId ? { roomId } : {}),
});
}
+
+/**
+ * Where the first run ends: the buddy's chat once it exists, else its page,
+ * which waits for an AI provider. Skipping the buddy there also keeps its
+ * pop-up away for the rest of this launch: it was just declined.
+ */
+export async function openBuddyAfterOnboarding(
+ serverId: string,
+ agent: { agentId: string; name: string } | null
+): Promise<void> {
+ if (agent) {
+ await openBuddyChat(serverId, agent);
+ return;
+ }
+ buddyIntroStore.skipped();
+ appState.navigation.navigate('switchBuddy', { serverId });
+}
diff --git a/console/apps/switch-console-desktop/src/renderer/tests/browser/meet-buddy-page.test.tsx b/console/apps/switch-console-desktop/src/renderer/tests/browser/meet-buddy-page.test.tsx
index 667c8ed36..e2e5e9d9d 100644
--- a/console/apps/switch-console-desktop/src/renderer/tests/browser/meet-buddy-page.test.tsx
+++ b/console/apps/switch-console-desktop/src/renderer/tests/browser/meet-buddy-page.test.tsx
@@ -58,6 +58,7 @@ let container: HTMLDivElement | null = null;
let root: Root | null = null;
const onCreated = vi.fn();
const onSkip = vi.fn();
+const onSetupOpened = vi.fn();
const ready = (provider: string): Reported => ({
provider,
@@ -106,6 +107,7 @@ async function render() {
workspaceId="ws-1"
onCreated={(agent) => onCreated(agent)}
onSkip={onSkip}
+ onSetupOpened={onSetupOpened}
/>
)
);
@@ -172,6 +174,19 @@ describe('MeetBuddyPage', () => {
expect(onCreated).toHaveBeenCalledWith({ agentId: 'a-1', name: 'switch-buddy-max-tam' });
});
+ it('tells the page holding it when the person opens the other providers', async () => {
+ state.computer = machine(ready('claude'), signedOut('codex'));
+ await render();
+
+ await act(async () =>
+ [...container!.querySelectorAll('button')]
+ .find((b) => b.textContent === 'Use other AI providers')!
+ .click()
+ );
+
+ expect(onSetupOpened).toHaveBeenCalledTimes(1);
+ });
+
it('offers to open the buddy someone already has', async () => {
state.agents = [{ agentId: 'a-1', name: 'switch-buddy-max' }];
await render();