Skip to content

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

switch-buddy's welcome leads with the messaging apps, with their logos (CHOO-3236) (#930)

Louis Amaudruz699c32d08d39
diff --git a/console/apps/switch-console-desktop/src/renderer/features/chats/ui/chat-markdown.tsx b/console/apps/switch-console-desktop/src/renderer/features/chats/ui/chat-markdown.tsx
index 2c2ee3359..cfc5d4280 100644
--- a/console/apps/switch-console-desktop/src/renderer/features/chats/ui/chat-markdown.tsx
+++ b/console/apps/switch-console-desktop/src/renderer/features/chats/ui/chat-markdown.tsx
@@ -1,5 +1,6 @@
import type * as React from 'react';
import {
+ defaultComponents,
defaultRehypePlugins,
defaultUrlTransform,
Streamdown,
@@ -9,10 +10,12 @@ import {
} from 'streamdown';
import type { PluggableList } from 'unified';
import { followConsoleLink } from '@renderer/features/deeplinks/console-link-handler';
+import { BridgeIcon, hasBridgeIcon } from '@renderer/lib/components/bridge-icon';
import { confirmOpenExternalLink } from '@renderer/lib/open-external-link';
import { cn } from '@renderer/utils/utils';
import { CONSOLE_LINK_PREFIX, CONSOLE_LINK_SCHEME } from '@shared/core/deeplinks/console-links';
import { CodeBlock } from './code-block';
+import { PLATFORM_LOGO_PREFIX, platformOfLogoUrl } from './platform-logo';
const HTTP_URL_PATTERN = /^https?:\/\//i;
@@ -30,9 +33,9 @@ const REHYPE_PLUGINS: PluggableList = [
type SanitizeSchema = { protocols?: Record<string, string[]> };
/**
- * The sanitizer, letting links to Console pages keep their `href`: its schema
- * allows web and mail links only, and a `switchdash:` one would arrive
- * stripped, as text marked blocked.
+ * The sanitizer, letting links to Console pages keep their `href`, and
+ * messaging-app logos their `src`: its schema allows web and mail addresses
+ * only, and a `switchdash:` one would arrive stripped, as text marked blocked.
*/
function withConsoleLinks(sanitize: PluggableList[number]): PluggableList[number] {
const [plugin, schema] = sanitize as [unknown, SanitizeSchema];
@@ -43,14 +46,21 @@ function withConsoleLinks(sanitize: PluggableList[number]): PluggableList[number
protocols: {
...schema.protocols,
href: [...(schema.protocols?.href ?? []), CONSOLE_LINK_SCHEME],
+ src: [...(schema.protocols?.src ?? []), CONSOLE_LINK_SCHEME],
},
},
] as PluggableList[number];
}
-/** Links to Console pages pass; everything else gets the usual unsafe-protocol filter. */
+/**
+ * Links to Console pages and messaging-app logos pass; everything else gets
+ * the usual unsafe-protocol filter.
+ */
const urlTransform: UrlTransform = (url, key, node) =>
- url.startsWith(CONSOLE_LINK_PREFIX) ? url : defaultUrlTransform(url, key, node);
+ (key === 'href' && url.startsWith(CONSOLE_LINK_PREFIX)) ||
+ (key === 'src' && url.startsWith(PLATFORM_LOGO_PREFIX))
+ ? url
+ : defaultUrlTransform(url, key, node);
type WithChildren = { children?: React.ReactNode } & ExtraProps;
@@ -92,8 +102,32 @@ function ChatCode({
);
}
+/**
+ * A messaging app where the message names one with its logo: the logo and the
+ * app's name (the image's alt text) in bold, inline and on one line; any other
+ * image as usual.
+ */
+function ChatImage(props: React.ComponentProps<'img'> & ExtraProps) {
+ const platform = platformOfLogoUrl(props.src);
+ if (platform === null) {
+ const DefaultImage = defaultComponents.img;
+ return <DefaultImage {...props} />;
+ }
+ return (
+ <span className="inline-flex items-baseline gap-1 whitespace-nowrap">
+ {hasBridgeIcon(platform) && (
+ <span aria-hidden className="translate-y-[2px]">
+ <BridgeIcon bridgeType={platform} size={14} />
+ </span>
+ )}
+ <strong className="font-semibold">{props.alt}</strong>
+ </span>
+ );
+}
+
const COMPONENTS: Components = {
a: ChatLink,
+ img: ChatImage,
code: ChatCode,
p: ({ children }: WithChildren) => <p className="my-2 leading-relaxed">{children}</p>,
h1: ({ children }: WithChildren) => (
diff --git a/console/apps/switch-console-desktop/src/renderer/features/chats/ui/platform-logo.test.ts b/console/apps/switch-console-desktop/src/renderer/features/chats/ui/platform-logo.test.ts
new file mode 100644
index 000000000..91ce61e5f
--- /dev/null
+++ b/console/apps/switch-console-desktop/src/renderer/features/chats/ui/platform-logo.test.ts
@@ -0,0 +1,21 @@
+import { describe, expect, it } from 'vitest';
+import { platformLogoMarkdown, platformOfLogoUrl } from './platform-logo';
+
+describe('platform logos in chat messages', () => {
+ it('writes a logo the chat reads back', () => {
+ expect(platformLogoMarkdown('slack', 'Slack')).toBe('![Slack](switchdash://logo/slack)');
+ expect(platformOfLogoUrl('switchdash://logo/slack')).toBe('slack');
+ });
+
+ it('leaves every other image alone', () => {
+ expect(platformOfLogoUrl('https://example.com/slack.png')).toBeNull();
+ expect(platformOfLogoUrl('switchdash://open/agents')).toBeNull();
+ expect(platformOfLogoUrl(undefined)).toBeNull();
+ });
+
+ it('refuses an address that is not a platform name', () => {
+ expect(platformOfLogoUrl('switchdash://logo/')).toBeNull();
+ expect(platformOfLogoUrl('switchdash://logo/../etc')).toBeNull();
+ expect(platformOfLogoUrl('switchdash://logo/Slack')).toBeNull();
+ });
+});
diff --git a/console/apps/switch-console-desktop/src/renderer/features/chats/ui/platform-logo.ts b/console/apps/switch-console-desktop/src/renderer/features/chats/ui/platform-logo.ts
new file mode 100644
index 000000000..8aaf64040
--- /dev/null
+++ b/console/apps/switch-console-desktop/src/renderer/features/chats/ui/platform-logo.ts
@@ -0,0 +1,22 @@
+import { CONSOLE_LINK_SCHEME } from '@shared/core/deeplinks/console-links';
+
+/**
+ * A messaging app named with its logo, written into a chat message as an image
+ * whose alt text is the app's name and whose address is this prefix and the
+ * app's `bridge_type`. Console's chat draws the logo and the name inline, where
+ * an emoji would go; no emoji exists for Slack, Teams and the rest. Anywhere
+ * that cannot load the image shows its alt text, the name.
+ */
+export const PLATFORM_LOGO_PREFIX = `${CONSOLE_LINK_SCHEME}://logo/`;
+
+/** The markdown naming `platform` as `name`, with its logo. */
+export function platformLogoMarkdown(platform: string, name: string): string {
+ return `![${name}](${PLATFORM_LOGO_PREFIX}${platform})`;
+}
+
+/** The `bridge_type` an image address draws the logo of, or null when it is any other image. */
+export function platformOfLogoUrl(src: unknown): string | null {
+ if (typeof src !== 'string' || !src.startsWith(PLATFORM_LOGO_PREFIX)) return null;
+ const platform = src.slice(PLATFORM_LOGO_PREFIX.length);
+ return /^[a-z][a-z0-9_-]{0,40}$/.test(platform) ? platform : null;
+}
diff --git a/console/apps/switch-console-desktop/src/renderer/features/switch-buddy/buddy-welcome-message.ts b/console/apps/switch-console-desktop/src/renderer/features/switch-buddy/buddy-welcome-message.ts
index 8c6a52471..603d82e7f 100644
--- a/console/apps/switch-console-desktop/src/renderer/features/switch-buddy/buddy-welcome-message.ts
+++ b/console/apps/switch-console-desktop/src/renderer/features/switch-buddy/buddy-welcome-message.ts
@@ -1,10 +1,25 @@
+import { platformLogoMarkdown } from '@renderer/features/chats/ui/platform-logo';
+
+/** The messaging apps the welcome names, each with its logo. */
+const PLATFORMS: { type: string; name: string }[] = [
+ { type: 'slack', name: 'Slack' },
+ { type: 'teams', name: 'Microsoft Teams' },
+ { type: 'mattermost', name: 'Mattermost' },
+ { type: 'telegram', name: 'Telegram' },
+];
+
+function platformList(): string {
+ const named = PLATFORMS.map(({ type, name }) => platformLogoMarkdown(type, name));
+ return `${named.slice(0, -1).join(', ')} and ${named.at(-1)}`;
+}
+
/**
- * The first message switch-buddy posts in its Welcome chat: who it is, what it
- * can do, and two tips. Written here, posted as the buddy, so it is there the
- * moment the chat opens rather than after the buddy's first session starts.
+ * The first message switch-buddy posts in its Welcome chat: who it is, that
+ * Switch brings agents to the messaging apps a team already uses, and what it
+ * can help with. Written here, posted as the buddy, so it is there the moment
+ * the chat opens rather than after the buddy's first session starts.
*
- * The tips give the buddy's name in words, not as an @mention: posted by the
- * buddy, a mention of itself would be read as addressing it.
+ * The apps' logos are drawn by Console's chat; the Welcome chat is read there.
*/
export function buddyWelcomeMessage({
firstName,
@@ -15,22 +30,15 @@ export function buddyWelcomeMessage({
}): string {
return [
`Hi${firstName ? ` ${firstName}` : ''}, I’m **${agentName}**, your assistant for everything Switch. 👋`,
- 'Switch brings your team to work with your agents, and I’m the first one.',
+ '',
+ `Switch brings your agents to where your team already works: ${platformList()}. Your team talks to agents in the channels they already use, and people and agents work together in shared rooms.`,
'',
'I can help you:',
- '- 🤖 Create agents',
- '- 🏠 Make rooms',
+ '- 🔌 Connect your team’s chat app',
+ '- 🤖 Create agents and bring them into your channels',
+ '- 🏠 Set up rooms where your team and agents work together',
'- 💬 Answer anything about Switch',
- '- 🧑‍💻 Any task, from researching a topic to writing a document',
- '',
- 'Some tips:',
- '',
- '**👫 If you want your team to talk to me**',
- '- In my Agent settings, set “Who can talk to your agent” to “Anyone”.',
- '- Then invite your team members to the channel I’m in.',
'',
- '**➕ If you want to add me to another channel**',
- '- Go to the channel where you want me.',
- `- Type \`/invite-agent\` followed by my name, ${agentName}.`,
+ 'Tell me which app your team uses, and I’ll walk you through connecting it.',
].join('\n');
}
diff --git a/console/apps/switch-console-desktop/src/renderer/tests/browser/chat-platform-logos.test.tsx b/console/apps/switch-console-desktop/src/renderer/tests/browser/chat-platform-logos.test.tsx
new file mode 100644
index 000000000..d805ca028
--- /dev/null
+++ b/console/apps/switch-console-desktop/src/renderer/tests/browser/chat-platform-logos.test.tsx
@@ -0,0 +1,73 @@
+/**
+ * switch-buddy's welcome names the messaging apps with their logos, drawn by
+ * the chat inline in the text beside each name; an app the chat has no logo
+ * for is named without one.
+ */
+import { act } from 'react';
+import { createRoot, type Root } from 'react-dom/client';
+import { afterEach, describe, expect, it, vi } from 'vitest';
+
+vi.hoisted(() => {
+ window.electronAPI ??= {
+ invoke: () => Promise.resolve(undefined),
+ eventOn: () => () => {},
+ eventSend: () => {},
+ } as unknown as typeof window.electronAPI;
+});
+
+import { ChatMarkdown } from '@renderer/features/chats/ui/chat-markdown';
+import { buddyWelcomeMessage } from '@renderer/features/switch-buddy/buddy-welcome-message';
+import '@renderer/index.css';
+
+let container: HTMLDivElement | null = null;
+let root: Root | null = null;
+
+afterEach(async () => {
+ await act(async () => root?.unmount());
+ container?.remove();
+ container = null;
+ root = null;
+});
+
+async function render(markdown: string) {
+ container = document.createElement('div');
+ document.body.appendChild(container);
+ root = createRoot(container);
+ await act(async () => root!.render(<ChatMarkdown>{markdown}</ChatMarkdown>));
+ // Streamdown renders after a tick.
+ await act(async () => new Promise((resolve) => setTimeout(resolve, 50)));
+}
+
+/** Each app named: its name, whether its logo is drawn, and whether it sits in the text. */
+function apps(): string[] {
+ return [...container!.querySelectorAll('strong')]
+ .filter((name) => name.parentElement?.classList.contains('whitespace-nowrap'))
+ .map((name) => {
+ const app = name.parentElement!;
+ const logo = app.querySelector('svg') !== null ? 'logo' : 'no logo';
+ const inline = app.closest('p') !== null ? 'inline' : 'apart';
+ return `${name.textContent?.trim()} (${logo}, ${inline})`;
+ });
+}
+
+describe('messaging-app logos in chat', () => {
+ it('draws each app the welcome names inline, with its logo beside its name', async () => {
+ await render(buddyWelcomeMessage({ firstName: 'Max', agentName: 'switch-buddy-max' }));
+ expect(apps()).toEqual([
+ 'Slack (logo, inline)',
+ 'Microsoft Teams (logo, inline)',
+ 'Mattermost (logo, inline)',
+ 'Telegram (logo, inline)',
+ ]);
+ expect(container!.textContent?.replace(/\s+/g, ' ')).toContain(
+ 'Slack, Microsoft Teams, Mattermost and Telegram'
+ );
+ expect(container!.textContent).not.toContain('switchdash');
+ });
+
+ it('names an app it has no logo for without one', async () => {
+ await render('Try ![Nowhere](switchdash://logo/nowhere) here.');
+ expect(apps()).toEqual(['Nowhere (no logo, inline)']);
+ expect(container!.textContent).not.toContain('switchdash');
+ });
+});
diff --git a/core/switch_core/official_templates/switch-buddy/AGENT.md b/core/switch_core/official_templates/switch-buddy/AGENT.md
index 136eb939d..ff83bdffb 100644
--- a/core/switch_core/official_templates/switch-buddy/AGENT.md
+++ b/core/switch_core/official_templates/switch-buddy/AGENT.md
@@ -38,8 +38,13 @@ reads.
## The first message is already there
Your Welcome chat opens with a message posted in your name when it was created:
-who you are, what you can do, and a couple of tips. You did not write it, but it is
-yours. Do not repeat it. Answer what the person actually says.
+who you are, that Switch brings agents to Slack, Microsoft Teams, Mattermost and
+Telegram, what you can help with, and an invitation to say which app their team
+uses. You did not write it, but it is yours. Do not repeat it. Answer what the
+person actually says: when they name an app, help them connect it.
+
+The app logos in it are images only Switch Console draws. Do not copy them into
+your own messages; name the apps in words.
## Say something before you go quiet