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
feat(agents): switch agent sessions instantly with a skeleton (#9620)
Eric Hayesff085fc52d48
diff --git a/apps/web/src/features/agents-view/components/AgentSessionSkeleton.tsx b/apps/web/src/features/agents-view/components/AgentSessionSkeleton.tsxnew file mode 100644index 0000000000..a8adb00374--- /dev/null+++ b/apps/web/src/features/agents-view/components/AgentSessionSkeleton.tsx@@ -0,0 +1,33 @@+import { ListSkeleton } from '@app/components/view-shell/ListSkeleton';+import { t } from '@app/lib/i18n';+import { Topbar } from './Topbar';++/** A conversation until its first load resolves, laid out like its pane. */+export function AgentSessionSkeleton() {+ return (+ <>+ <Topbar titleContent={<ListSkeleton.Bar class="h-3 w-40" />} />+ <ListSkeleton.Root+ label={t('common.loadingConversation')}+ class="relative min-h-0 min-w-0 flex-1"+ >+ <div class="pane absolute inset-0 flex flex-col">+ <div class="macro-message-width mx-auto flex min-h-0 w-full flex-1 flex-col gap-3 overflow-hidden px-4 pt-4">+ <ListSkeleton.Bar class="mb-3 h-9 w-2/5 self-end" />+ <ListSkeleton.Bar class="w-4/5" />+ <ListSkeleton.Bar class="w-full" />+ <ListSkeleton.Bar class="mb-3 w-3/5" />+ <ListSkeleton.Bar class="mb-3 h-9 w-1/3 self-end" />+ <ListSkeleton.Bar class="w-11/12" />+ <ListSkeleton.Bar class="w-2/3" />+ </div>+ <div class="dock">+ <div class="composer-anchor">+ <ListSkeleton.Bar class="h-12 w-full" />+ </div>+ </div>+ </div>+ </ListSkeleton.Root>+ </>+ );+}diff --git a/apps/web/src/features/agents-view/views/AgentsView.test.tsx b/apps/web/src/features/agents-view/views/AgentsView.test.tsxnew file mode 100644index 0000000000..97be461a39--- /dev/null+++ b/apps/web/src/features/agents-view/views/AgentsView.test.tsx@@ -0,0 +1,237 @@+import { cleanup, fireEvent, render, screen } from '@solidjs/testing-library';+import {+ createResource,+ createSignal,+ For,+ onMount,+ type ParentProps,+ Suspense,+} from 'solid-js';+import { afterEach, beforeEach, expect, it, vi } from 'vitest';+import type { AgentsRoute } from '../core/route';+import { AgentsView } from './AgentsView';++const state = vi.hoisted(() => ({+ contentId: { current: 'agents' },+ navigate: { current: (_id: string) => {} },+ loads: new Map<string, (name: string) => void>(),+ mounts: [] as string[],+ pass: (props: ParentProps) => props.children,+}));++vi.mock('@app/components/view-shell', () => ({+ ViewShell: { Root: state.pass, Aside: state.pass, Main: state.pass },+}));+vi.mock('@app/features/block-agent/context/pending-session', () => ({+ startPendingSession: () => 'pending',+}));+vi.mock('@app/features/settings/AgentSettings', () => ({+ AgentSettings: () => null,+}));+vi.mock('@app/features/settings/IntegrationsPage', () => ({+ IntegrationsPage: () => null,+}));+vi.mock('@app/features/soup/entity-notifications', () => ({+ withEntityNotifications: (entity: unknown) => entity,+}));+vi.mock('@app/features/tours/ViewTour', () => ({ ViewTour: () => null }));+vi.mock('@app/lib/analytics/posthog', () => ({+ useFeatureFlag: () => () => ({ enabled: false, loading: false }),+}));+vi.mock('@components/app/GlobalAppState', () => ({+ useGlobalBlockOrchestrator: () => ({}),+ useGlobalNotificationSource: () => ({}),+}));+vi.mock('@components/app/mobile/float-regions/float-region-state', () => ({+ FloatRegions: { hostHeight: () => 0 },+}));+vi.mock('@components/app/PreviewPanel', () => ({ PreviewPanel: () => null }));+vi.mock('@components/app/previewTarget', () => ({+ previewBlockTarget: () => ({}),+}));+vi.mock('@components/app/split-layout/layout', () => ({+ useSplitLayout: () => ({+ openWithSplit: (next: { id: string }) => {+ state.navigate.current(next.id);+ return { status: 'replaced' };+ },+ }),+}));+vi.mock('@components/app/split-layout/layoutUtils', () => ({+ useSplitPanelOrThrow: () => ({+ handle: {+ id: 'split',+ content: () => ({ type: 'component', id: state.contentId.current }),+ setDisplayName: () => {},+ },+ }),+}));+vi.mock('@components/app/split-panel', () => ({+ SplitPanel: { Root: state.pass, Body: state.pass },+}));+vi.mock('@core/component/AI/component/message/EmptyChatState', () => ({+ ChatEmptyStateContext: { Provider: state.pass },+}));+vi.mock('@core/component/ComposerGreeting', () => ({+ ComposerGreeting: state.pass,+}));+vi.mock(+ '@core/component/LexicalMarkdown/component/core/StaticMarkdown',+ () => ({+ StaticMarkdownContext: state.pass,+ })+);+vi.mock('@core/component/Toast/Toast', () => ({ toast: { alert: vi.fn() } }));+vi.mock('@core/constant/featureFlags', () => ({ enableAgentUpdates: {} }));+vi.mock('@core/context/user', () => ({ useUserId: () => () => 'user' }));+vi.mock('@core/mobile/isTouchDevice', () => ({ isTouchDevice: () => false }));+vi.mock('@entity', () => ({ ListEntityMetadataQueryProvider: state.pass }));+vi.mock('@notifications/mark-row-seen', () => ({+ markRowNotificationsSeenOnOpen: () => {},+}));+vi.mock('@queries/agent-session/warm', () => ({+ useWarmAgentSessionQuery: () => {},+}));+vi.mock('@queries/soup/items', () => ({+ useSoupAstItemsQuery: () => ({ isPending: true }),+}));+vi.mock('../../routines/routine-navigation', () => ({+ routineContent: () => ({}),+}));+vi.mock('../../routines/routines-page', () => ({ RoutinesPage: () => null }));+vi.mock('../agents-view.css', () => ({}));+vi.mock('../components/AgentSessionPane', () => ({+ // Suspends like the real pane, whose session read waits for the first load.+ AgentSessionPane: (props: { id: string }) => {+ const [title] = createResource(+ () =>+ new Promise<string>((resolve) => {+ state.loads.set(props.id, resolve);+ })+ );+ onMount(() => state.mounts.push(props.id));+ return <div data-testid="pane">{title()}</div>;+ },+}));+vi.mock('../components/AgentsSidebar', () => ({+ AgentsSidebar: (props: {+ activeConversationId?: string;+ onOpenConversation: (conversation: {+ id: string;+ type: 'agent_session';+ }) => void;+ }) => (+ <For each={['a', 'b', 'c']}>+ {(id) => (+ <button+ type="button"+ aria-current={props.activeConversationId === id ? 'true' : undefined}+ onClick={() =>+ props.onOpenConversation({ id, type: 'agent_session' })+ }+ >+ {id}+ </button>+ )}+ </For>+ ),+}));+vi.mock('../components/Topbar', () => ({ Topbar: () => null }));+vi.mock('../context/data-mode', () => ({+ DataModeProvider: state.pass,+ dataModeFor: () => 'chat',+}));+vi.mock('../primitives/composer-draft', () => ({+ createPersistedComposerDraft: () => ({ draft: () => '', setDraft: () => {} }),+}));+vi.mock('../primitives/conversation-list-view', () => ({+ createConversationListView: () => ({+ filters: () => [],+ grouping: () => 'none',+ setSelected: () => {},+ clear: () => {},+ setGrouping: () => {},+ }),+}));+vi.mock('../primitives/workspace-mode', () => ({+ createWorkspaceMode: () => ({ mode: () => 'auto', setMode: () => {} }),+}));+vi.mock('../queries/agent-conversations-query', () => ({+ agentConversationsQuery: () => ({}),+}));+vi.mock('../queries/agent-roster-source', () => ({+ createAgentRosterSource: () => ({+ roster: () => [],+ loading: () => false,+ availabilityLoading: () => false,+ }),+}));+vi.mock('../tour', () => ({ agentsTour: {} }));+vi.mock('./NewChatPage', () => ({ NewChatPage: () => null }));++function agentRoute(id: string): AgentsRoute {+ return { mode: 'chat', conversation: { type: 'agent_session', id } };+}++/** Opens conversation `a`, loaded, with clicks routed the way the split does. */+async function openLoadedConversation() {+ const [route, setRoute] = createSignal(agentRoute('a'));+ state.navigate.current = (id) => {+ state.contentId.current = id;+ setRoute(agentRoute(id.split('~').at(-1) ?? ''));+ };+ render(() => (+ <Suspense>+ <AgentsView route={route()} />+ </Suspense>+ ));+ state.loads.get('a')?.('Session a');+ expect((await screen.findByTestId('pane')).textContent).toBe('Session a');+}++function row(name: string) {+ return screen.getByRole('button', { name });+}++beforeEach(() => {+ state.contentId.current = 'agents';+ state.loads.clear();+ state.mounts.length = 0;+});++afterEach(cleanup);++it('selects the conversation and shows a skeleton before its load resolves', async () => {+ await openLoadedConversation();++ fireEvent.click(row('b'));++ expect(row('b').getAttribute('aria-current')).toBe('true');+ expect(row('a').getAttribute('aria-current')).toBeNull();+ expect(screen.queryByText('Session a')).toBeNull();+ expect(screen.getByRole('status')).toBeTruthy();++ state.loads.get('b')?.('Session b');++ expect((await screen.findByTestId('pane')).textContent).toBe('Session b');+ expect(screen.queryByRole('status')).toBeNull();+});++it('does not wait on a conversation already switched away from', async () => {+ await openLoadedConversation();++ fireEvent.click(row('b'));+ fireEvent.click(row('c'));+ state.loads.get('c')?.('Session c');++ expect((await screen.findByTestId('pane')).textContent).toBe('Session c');+});++it('keeps the open conversation mounted when it is selected again', async () => {+ await openLoadedConversation();++ fireEvent.click(row('a'));++ expect(screen.getByTestId('pane').textContent).toBe('Session a');+ expect(state.mounts).toEqual(['a']);+});diff --git a/apps/web/src/features/agents-view/views/AgentsView.tsx b/apps/web/src/features/agents-view/views/AgentsView.tsxindex 384b2635c0..eac9f1d11d 100644--- a/apps/web/src/features/agents-view/views/AgentsView.tsx+++ b/apps/web/src/features/agents-view/views/AgentsView.tsx@@ -25,6 +25,7 @@ import { markRowNotificationsSeenOnOpen } from '@notifications/mark-row-seen';import { useWarmAgentSessionQuery } from '@queries/agent-session/warm';import { useSoupAstItemsQuery } from '@queries/soup/items';import {+ batch,createEffect,createMemo,createSignal,@@ -34,7 +35,6 @@ import {Show,Suspense,Switch,- useTransition,} from 'solid-js';import { routineContent } from '../../routines/routine-navigation';import { RoutinesPage } from '../../routines/routines-page';@@ -45,6 +45,7 @@ import { enableAgentUpdates } from '@core/constant/featureFlags';import { fireAndForget } from '@core/util/fireAndForget';import type { AgentSessionEntity } from '@entity';import { AgentSessionPane } from '../components/AgentSessionPane';+import { AgentSessionSkeleton } from '../components/AgentSessionSkeleton';import { AgentsSidebar } from '../components/AgentsSidebar';import { Topbar } from '../components/Topbar';import { DataModeProvider, dataModeFor } from '../context/data-mode';@@ -114,18 +115,18 @@ function AgentsWorkspace(props: { route?: AgentsRoute }) {}: undefined);- // A conversation suspends until its first load resolves. Switching inside a- // transition keeps the current one on screen until then, instead of blanking- // the pane to a spinner; the sidebar highlights the target meanwhile.- const [switching, startSwitch] = useTransition();+ // Selecting takes effect at once: the conversation's own Suspense shows a+ // skeleton until its first load resolves. Selecting the conversation already+ // on screen keeps it mounted, since the keyed Show remounts on a new object.const selectConversation = (conversation: AgentConversationTarget) =>- fireAndForget(- startSwitch(() => {- setPage('new');- setSelected({ conversation, activeConversationId: conversation.id });- }),- 'agents-view'- );+ batch(() => {+ setPage('new');+ setSelected((current) =>+ current?.activeConversationId === conversation.id+ ? current+ : { conversation, activeConversationId: conversation.id }+ );+ });// The list and its conversations share one mount (`mountKey` in the routes),// so the selection follows navigation, including Back and Forward.createEffect(@@ -346,7 +347,7 @@ function AgentsWorkspace(props: { route?: AgentsRoute }) {onFilterChange={listView.setSelected}onClearFilters={listView.clear}onGroupingChange={listView.setGrouping}- activePage={selected() || switching() ? undefined : page()}+ activePage={selected() ? undefined : page()}onCreateRoutine={() =>layout.popoverSplit({ type: 'component', id: 'routine-compose' })}@@ -362,11 +363,7 @@ function AgentsWorkspace(props: { route?: AgentsRoute }) {: openPage(next)}modeForConversation={modeForConversation}- activeConversationId={- switching()- ? props.route?.conversation.id- : selected()?.activeConversationId- }+ activeConversationId={selected()?.activeConversationId}search={search()}conversations={partitioned().conversations}archived={partitioned().archived}@@ -421,87 +418,87 @@ function AgentsWorkspace(props: { route?: AgentsRoute }) {class="main touch:pt-[calc(var(--mobile-content-inset-top,var(--safe-top,0px))+0.5rem)] touch:[&>*]:[--mobile-content-inset-top:0px]"classList={{ hidden: isTouchDevice() && mobileList() }}>- {/* Outside the keyed Show, so a conversation switched to in a- transition keeps the previous one shown while it loads. */}- <Suspense fallback={<LoadingComposer />}>- <Show- when={selected()?.conversation}- keyed- fallback={- <>- <Show when={page() !== 'routines'}>- <Topbar- title={pageTitle()}- onBack={- isTouchDevice()- ? () => setMobileList(true)- : undefined- }- />- </Show>- <div class="body">- <Suspense fallback={<LoadingComposer />}>- <Switch>- <Match when={page() === 'routines'}>- <RoutinesPage />- </Match>- <Match when={page() === 'connections'}>- <IntegrationsPage />- </Match>- <Match when={page() === 'agents'}>- <AgentSettings- createKind={creatingKind()}- onCloseCreate={() =>- setCreatingKind(undefined)- }- />- </Match>- </Switch>- <div- class="contents"- classList={{ hidden: page() !== 'new' }}- >- <NewChatPage- showUpdates={- updatesFlag().enabled && page() === 'new'- }- updateSessions={updateSessions()}- onOpenUpdateSession={(id) => {- const session = updateSessions().find(- (item) => item.id === id- );- if (session)- openConversation(- session,- undefined,- modeForConversation(session)- );- }}- mode={workspace.mode()}- onModeChange={workspace.setMode}- active={- !isTouchDevice() ||- (!mobileList() && page() === 'new')+ <Show+ when={selected()?.conversation}+ keyed+ fallback={+ <>+ <Show when={page() !== 'routines'}>+ <Topbar+ title={pageTitle()}+ onBack={+ isTouchDevice()+ ? () => setMobileList(true)+ : undefined+ }+ />+ </Show>+ <div class="body">+ <Suspense fallback={<LoadingComposer />}>+ <Switch>+ <Match when={page() === 'routines'}>+ <RoutinesPage />+ </Match>+ <Match when={page() === 'connections'}>+ <IntegrationsPage />+ </Match>+ <Match when={page() === 'agents'}>+ <AgentSettings+ createKind={creatingKind()}+ onCloseCreate={() =>+ setCreatingKind(undefined)}- registerFocus={(focus) => {- composerFocus = focus;- }}- workspaceId={panel.handle.id}- draft={persistedDraft.draft()}- onDraftChange={persistedDraft.setDraft}- roster={rosterSource.roster()}- rosterLoading={rosterSource.loading()}- availabilityLoading={rosterSource.availabilityLoading()}- onStart={startConversation}- onOpenRoster={openRoster}/>- </div>- </Suspense>- </div>- </>- }- >- {(conversation) => (+ </Match>+ </Switch>+ <div+ class="contents"+ classList={{ hidden: page() !== 'new' }}+ >+ <NewChatPage+ showUpdates={+ updatesFlag().enabled && page() === 'new'+ }+ updateSessions={updateSessions()}+ onOpenUpdateSession={(id) => {+ const session = updateSessions().find(+ (item) => item.id === id+ );+ if (session)+ openConversation(+ session,+ undefined,+ modeForConversation(session)+ );+ }}+ mode={workspace.mode()}+ onModeChange={workspace.setMode}+ active={+ !isTouchDevice() ||+ (!mobileList() && page() === 'new')+ }+ registerFocus={(focus) => {+ composerFocus = focus;+ }}+ workspaceId={panel.handle.id}+ draft={persistedDraft.draft()}+ onDraftChange={persistedDraft.setDraft}+ roster={rosterSource.roster()}+ rosterLoading={rosterSource.loading()}+ availabilityLoading={rosterSource.availabilityLoading()}+ onStart={startConversation}+ onOpenRoster={openRoster}+ />+ </div>+ </Suspense>+ </div>+ </>+ }+ >+ {(conversation) => (+ // Per conversation, so one switched away from can't hold+ // the next in its fallback until its own load settles.+ <Suspense fallback={<AgentSessionSkeleton />}><Switch><Match when={conversation.type === 'agent_session'}><AgentSessionPane@@ -533,9 +530,9 @@ function AgentsWorkspace(props: { route?: AgentsRoute }) {</div></Match></Switch>- )}- </Show>- </Suspense>+ </Suspense>+ )}+ </Show></main><Show when={isTouchDevice() && mobileList()}><divdiff --git a/apps/web/src/lib/i18n/locales/en/common.ts b/apps/web/src/lib/i18n/locales/en/common.tsindex d6620183a9..4fa0c88bce 100644--- a/apps/web/src/lib/i18n/locales/en/common.ts+++ b/apps/web/src/lib/i18n/locales/en/common.ts@@ -23,6 +23,7 @@ export default {close: 'Close',dismiss: 'Dismiss',loading: 'Loading…',+ loadingConversation: 'Loading conversation',delete: 'Delete',rename: 'Rename',more: 'More',diff --git a/docs/agent-guide/ai-chat.md b/docs/agent-guide/ai-chat.mdindex fa5385d3bc..632b1fad15 100644--- a/docs/agent-guide/ai-chat.md+++ b/docs/agent-guide/ai-chat.md@@ -469,8 +469,10 @@ the shimmer.Changing the composer mode does not filter the sidebar.Selecting a row opens its own mode; Shift-click opens it in a new split.Switching conversations keeps the sidebar mounted (no reload or scroll reset)- and the open conversation on screen until the next one has loaded; verify by- tagging the workspace and row nodes and checking they survive the click.+ and moves the selection at once; the pane shows a skeleton until the next+ conversation has loaded. Verify by tagging the workspace and row nodes and+ checking they survive the click. Selecting the open conversation again does+ not remount it.Right-click (or long-press on mobile) opens the same entity menu as Home:Rename, Favorite, Copy link, Share, Archive, Delete, and the other sessionactions. Archived sessions are grouped at the bottom under **Archived**, a