Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
fix(getting-started): reopen existing example chats (#6810)
Peter Chinman58d035a4d2ad
diff --git a/apps/web/src/features/getting-started/getting-started-chat.test.ts b/apps/web/src/features/getting-started/getting-started-chat.test.tsnew file mode 100644index 0000000000..edaa3fb6a6--- /dev/null+++ b/apps/web/src/features/getting-started/getting-started-chat.test.ts@@ -0,0 +1,93 @@+import { beforeEach, describe, expect, it, vi } from 'vitest';+import { createGettingStartedChatOpener } from './getting-started-chat';+import { createGettingStartedState } from './getting-started-state';++describe('getting started chats', () => {+ beforeEach(() => localStorage.clear());++ const setup = (userId = 'user-1') => {+ const state = createGettingStartedState(userId);+ const startChat = vi+ .fn<(prompt: string) => Promise<string | undefined>>()+ .mockResolvedValue('chat-1');+ const openChat = vi.fn();+ const activate = createGettingStartedChatOpener({+ state,+ startChat,+ openChat,+ });+ return { state, startChat, openChat, activate };+ };++ it('reopens the saved chat after remounting without resending the prompt', async () => {+ const first = setup();+ await first.activate('example-weekly-brief', 'Build my weekly brief');+ first.state.markCompleted('example-weekly-brief');+ first.state.toggleSection('basics');++ const reopened = setup();+ expect(+ await reopened.activate('example-weekly-brief', 'Updated prompt')+ ).toBe(true);+ expect(reopened.startChat).not.toHaveBeenCalled();+ expect(reopened.openChat).toHaveBeenCalledWith('chat-1');+ expect(first.startChat).toHaveBeenCalledExactlyOnceWith(+ 'Build my weekly brief'+ );+ });++ it('keeps chats separate for each button and account', async () => {+ const first = setup();+ first.startChat+ .mockResolvedValueOnce('chat-1')+ .mockResolvedValueOnce('chat-2');+ await first.activate('example-weekly-brief', 'Brief');+ await first.activate('example-pull-tasks', 'Tasks');+ await first.activate('example-weekly-brief', 'Brief');+ await first.activate('example-pull-tasks', 'Tasks');+ expect(first.startChat).toHaveBeenCalledTimes(2);+ expect(first.openChat.mock.calls).toEqual([+ ['chat-1'],+ ['chat-2'],+ ['chat-1'],+ ['chat-2'],+ ]);++ const other = setup('user-2');+ await other.activate('example-weekly-brief', 'Brief');+ expect(other.startChat).toHaveBeenCalledOnce();+ });++ it('ignores repeated clicks while creating the chat', async () => {+ const { startChat, openChat, activate } = setup();+ let finish!: (chatId: string) => void;+ startChat.mockReturnValueOnce(+ new Promise((resolve) => {+ finish = resolve;+ })+ );+ const first = activate('example-weekly-brief', 'Brief');+ expect(await activate('example-weekly-brief', 'Brief')).toBe(false);+ finish('chat-1');+ expect(await first).toBe(true);+ expect(await activate('example-weekly-brief', 'Brief')).toBe(true);+ expect(startChat).toHaveBeenCalledOnce();+ expect(openChat.mock.calls).toEqual([['chat-1'], ['chat-1']]);+ });++ it('allows retrying failed creation', async () => {+ const { state, startChat, activate } = setup();+ startChat.mockResolvedValueOnce(undefined);+ expect(await activate('example-weekly-brief', 'Brief')).toBe(false);+ expect(state.chatIdForAction('example-weekly-brief')).toBeUndefined();+ expect(await activate('example-weekly-brief', 'Brief')).toBe(true);+ expect(startChat).toHaveBeenCalledTimes(2);+ });++ it('clears the pending guard if creation throws', async () => {+ const { startChat, activate } = setup();+ startChat.mockRejectedValueOnce(new Error('Network failure'));+ expect(await activate('example-weekly-brief', 'Brief')).toBe(false);+ expect(await activate('example-weekly-brief', 'Brief')).toBe(true);+ });+});diff --git a/apps/web/src/features/getting-started/getting-started-chat.ts b/apps/web/src/features/getting-started/getting-started-chat.tsnew file mode 100644index 0000000000..73f6c14434--- /dev/null+++ b/apps/web/src/features/getting-started/getting-started-chat.ts@@ -0,0 +1,36 @@+import type { GettingStartedState } from './getting-started-state';++/** Reopen each example's chat without sending its starter prompt again. */+export function createGettingStartedChatOpener(options: {+ state: Pick<GettingStartedState, 'chatIdForAction' | 'rememberChat'>;+ startChat: (prompt: string) => Promise<string | undefined>;+ openChat: (chatId: string) => void;+}) {+ const pending = new Set<string>();++ return async (actionId: string, prompt: string): Promise<boolean> => {+ if (pending.has(actionId)) return false;++ const existingChatId = options.state.chatIdForAction(actionId);+ if (existingChatId) {+ options.openChat(existingChatId);+ return true;+ }++ pending.add(actionId);+ try {+ let chatId: string | undefined;+ try {+ chatId = await options.startChat(prompt);+ } catch {+ return false;+ }+ if (!chatId) return false;+ options.state.rememberChat(actionId, chatId);+ options.openChat(chatId);+ return true;+ } finally {+ pending.delete(actionId);+ }+ };+}diff --git a/apps/web/src/features/getting-started/getting-started-state.test.ts b/apps/web/src/features/getting-started/getting-started-state.test.tsindex e6bbe6207e..da3ecf35e2 100644--- a/apps/web/src/features/getting-started/getting-started-state.test.ts+++ b/apps/web/src/features/getting-started/getting-started-state.test.ts@@ -8,6 +8,7 @@ describe('createGettingStartedState', () => {load: vi.fn().mockReturnValue({completedActionIds: ['set-name'],collapsedSectionIds: ['basics'],+ chatIdsByAction: {},}),save: vi.fn(),};@@ -20,12 +21,14 @@ describe('createGettingStartedState', () => {expect(store.save).toHaveBeenLastCalledWith('user-1', {completedActionIds: ['set-name', 'connect-email'],collapsedSectionIds: ['basics'],+ chatIdsByAction: {},});state.toggleSection('basics');expect(store.save).toHaveBeenLastCalledWith('user-1', {completedActionIds: ['set-name', 'connect-email'],collapsedSectionIds: [],+ chatIdsByAction: {},});});});diff --git a/apps/web/src/features/getting-started/getting-started-state.ts b/apps/web/src/features/getting-started/getting-started-state.tsindex f7f55f993a..e19d4d3f23 100644--- a/apps/web/src/features/getting-started/getting-started-state.ts+++ b/apps/web/src/features/getting-started/getting-started-state.ts@@ -25,11 +25,15 @@ export function createGettingStartedState(const [collapsed, setCollapsed] = createSignal<ReadonlySet<string>>(new Set(snapshot?.collapsedSectionIds));+ const [chatIds, setChatIds] = createSignal<ReadonlyMap<string, string>>(+ new Map(Object.entries(snapshot?.chatIdsByAction ?? {}))+ );const persist = () => {store.save(userId, {completedActionIds: [...completed()],collapsedSectionIds: [...collapsed()],+ chatIdsByAction: Object.fromEntries(chatIds()),});};@@ -50,6 +54,11 @@ export function createGettingStartedState(};return {+ chatIdForAction: (actionId: string) => chatIds().get(actionId),+ rememberChat: (actionId: string, chatId: string) => {+ setChatIds((previous) => new Map(previous).set(actionId, chatId));+ persist();+ },isPersistedComplete: (actionId: string) => completed().has(actionId),markCompleted,isCollapsed: (sectionId: string) => collapsed().has(sectionId),diff --git a/apps/web/src/features/getting-started/getting-started-store.test.ts b/apps/web/src/features/getting-started/getting-started-store.test.tsindex 56535f7854..7154b69c9c 100644--- a/apps/web/src/features/getting-started/getting-started-store.test.ts+++ b/apps/web/src/features/getting-started/getting-started-store.test.ts@@ -10,6 +10,7 @@ describe('parseGettingStartedSnapshot', () => {).toEqual({completedActionIds: ['set-name'],collapsedSectionIds: ['basics'],+ chatIdsByAction: {},});});@@ -17,6 +18,7 @@ describe('parseGettingStartedSnapshot', () => {expect(parseGettingStartedSnapshot('{}')).toEqual({completedActionIds: [],collapsedSectionIds: [],+ chatIdsByAction: {},});});@@ -28,6 +30,7 @@ describe('parseGettingStartedSnapshot', () => {).toEqual({completedActionIds: ['set-name'],collapsedSectionIds: [],+ chatIdsByAction: {},});});@@ -37,6 +40,7 @@ describe('parseGettingStartedSnapshot', () => {).toEqual({completedActionIds: ['renamed-action'],collapsedSectionIds: [],+ chatIdsByAction: {},});});@@ -49,4 +53,29 @@ describe('parseGettingStartedSnapshot', () => {it('returns null for malformed JSON', () => {expect(parseGettingStartedSnapshot('{')).toBeNull();});++ it('keeps valid chat mappings and drops invalid chat ids', () => {+ expect(+ parseGettingStartedSnapshot(+ JSON.stringify({+ chatIdsByAction: {+ brief: 'chat-1',+ tasks: 12,+ inbox: null,+ empty: '',+ },+ })+ )?.chatIdsByAction+ ).toEqual({ brief: 'chat-1' });+ });++ it.each([null, [], 'chat-1', 12])(+ 'ignores malformed chat mappings: %j',+ (value) => {+ expect(+ parseGettingStartedSnapshot(JSON.stringify({ chatIdsByAction: value }))+ ?.chatIdsByAction+ ).toEqual({});+ }+ );});diff --git a/apps/web/src/features/getting-started/getting-started-store.ts b/apps/web/src/features/getting-started/getting-started-store.tsindex 3fd2c66b4d..f2bbe65ee2 100644--- a/apps/web/src/features/getting-started/getting-started-store.ts+++ b/apps/web/src/features/getting-started/getting-started-store.ts@@ -5,6 +5,7 @@ export type GettingStartedSnapshot = {/** Actions completed by clicking or by an observed event (not derived state). */completedActionIds: string[];collapsedSectionIds: string[];+ chatIdsByAction: Record<string, string>;};/** Persistence seam for user-scoped Getting Started progress. */@@ -20,6 +21,16 @@ function stringArray(value: unknown): string[] {return value.filter((item): item is string => typeof item === 'string');}+function chatIdsByAction(value: unknown): Record<string, string> {+ if (typeof value !== 'object' || value === null || Array.isArray(value))+ return {};+ return Object.fromEntries(+ Object.entries(value).filter(+ ([, chatId]) => typeof chatId === 'string' && chatId.length > 0+ )+ );+}+/*** Unknown ids are kept: they're inert at render time, and dropping them would* erase progress across config renames or a client running older config.@@ -36,6 +47,7 @@ export function parseGettingStartedSnapshot(return {completedActionIds: stringArray(record.completedActionIds),collapsedSectionIds: stringArray(record.collapsedSectionIds),+ chatIdsByAction: chatIdsByAction(record.chatIdsByAction),};} catch {return null;diff --git a/apps/web/src/features/getting-started/getting-started.tsx b/apps/web/src/features/getting-started/getting-started.tsxindex 8af07d67df..cc7141652e 100644--- a/apps/web/src/features/getting-started/getting-started.tsx+++ b/apps/web/src/features/getting-started/getting-started.tsx@@ -36,6 +36,7 @@ import {} from '@theme/signals/themeSignals';import { createEffect, createSignal, For, on, onMount, Show } from 'solid-js';import { AGENT_EXAMPLES } from './agent-examples';+import { createGettingStartedChatOpener } from './getting-started-chat';import { ActionRow, SectionHeader } from './getting-started-rows';import {GettingStartedProvider,@@ -105,14 +106,14 @@ function GettingStartedContent() {openContent({ type: 'component', id: 'settings' });};- const openChatPrompt = async (prompt: string): Promise<boolean> => {+ const startChat = async (prompt: string): Promise<string | undefined> => {const result = await createChat({ name: deriveChatName(prompt) },{ source: 'getting-started' });if ('error' in result || !result.chatId) {toast.failure('Unable to start chat');- return false;+ return undefined;}// The chat block consumes this on mount and sends immediately. The model// must be one this plan may use: a pending send bypasses ChatInput, whose@@ -124,10 +125,15 @@ function GettingStartedContent() {attachments: [],model: defaultModelForPlan(hasPaidAccess()),});- openContent({ type: 'chat', id: result.chatId });- return true;+ return result.chatId;};+ const openChatPrompt = createGettingStartedChatOpener({+ state,+ startChat,+ openChat: (id) => openContent({ type: 'chat', id }),+ });+/*** The deterministic id of the how-to guide seeded at signup. Undefined* while the query is in flight; gated on isSuccess so a render-time read@@ -223,7 +229,7 @@ function GettingStartedContent() {icon: example.icon,title: example.title,description: example.description,- onActivate: () => openChatPrompt(example.prompt),+ onActivate: () => openChatPrompt(example.id, example.prompt),})),},];diff --git a/docs/AGENT_GUIDE/surfaces.md b/docs/AGENT_GUIDE/surfaces.mdindex 14b0aa57b2..5460cb94bd 100644--- a/docs/AGENT_GUIDE/surfaces.md+++ b/docs/AGENT_GUIDE/surfaces.md@@ -774,6 +774,15 @@ week and with no visible scrollbar. Under ~672px the four stats read as a two-covalue, and chips shorten. Rows stay on one line at every width. On touch devices the list restsbelow the floating page title and above the bottom toolbar.+## Getting Started — `/app/component/getting-started`++The buttons under **Put Macro's agent to work** create a chat and send their+example prompt on first use. Later clicks reopen that button's saved chat without+sending the prompt again, including after leaving the page or refreshing. Each+button has its own chat, saved per account in this browser's local storage.+Repeated clicks while the same button is creating its chat are ignored; a failed+creation can be retried.+## Home — `/app/component/home`Greeting, getting-started checklist, example prompt buttons (`Draft a document`,