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(inbox): allow marking agent-session (AI) notifications done (#6676)
Wolf Mermelstein9df21847a7a8
diff --git a/apps/web/src/features/next-soup/actions/make-mark-done-action.test.ts b/apps/web/src/features/next-soup/actions/make-mark-done-action.test.tsindex 843ba8048d..c9af4ab134 100644--- a/apps/web/src/features/next-soup/actions/make-mark-done-action.test.ts+++ b/apps/web/src/features/next-soup/actions/make-mark-done-action.test.ts@@ -148,6 +148,48 @@ describe('makeMarkDoneAction', () => {mocks.toNotificationEntityRef.mockReset();});+ it('allows mark done on agent-session rows', () => {+ const { action, dispose } = createAction();++ expect(+ action.canExecute({+ type: 'agent_session',+ id: 'session-1',+ } as EntityData)+ ).toBe(true);+ expect(+ action.canExecute({ type: 'channel_message', id: 'msg-1' } as EntityData)+ ).toBe(false);+ dispose();+ });++ it('uses the agent-session entity target while GraphQL Soup is enabled', async () => {+ mocks.graphqlSoupEnabled.mockReturnValue(true);+ mocks.resolveMarkEntitiesDoneVariables.mockReturnValue({+ emailIds: [],+ notificationIds: ['agent-notification'],+ reminderIds: [],+ });+ mocks.toNotificationEntityRef.mockReturnValue({+ type: 'agent_session',+ id: 'session-1',+ });+ const session = { type: 'agent_session', id: 'session-1' } as EntityData;+ const { action, dispose } = createAction();++ await action.execute([session]);++ expect(mocks.toNotificationEntityRef).toHaveBeenCalledWith(session);+ expect(mocks.mutateAsync).toHaveBeenCalledWith(+ expect.objectContaining({+ exactNotificationIds: { current: [] },+ notificationEntities: [{ type: 'agent_session', id: 'session-1' }],+ optimisticNotificationIds: ['agent-notification'],+ })+ );+ dispose();+ });+it('moves list focus without opening the next entity', async () => {const { soup } = createSoup();const { action, dispose } = createAction();diff --git a/apps/web/src/features/next-soup/actions/make-mark-done-action.ts b/apps/web/src/features/next-soup/actions/make-mark-done-action.tsindex c181195385..47fe57a45f 100644--- a/apps/web/src/features/next-soup/actions/make-mark-done-action.ts+++ b/apps/web/src/features/next-soup/actions/make-mark-done-action.ts@@ -227,6 +227,10 @@ export const makeMarkDoneAction = (options: MakeMarkDoneOptions) => {entity.type === 'email' ||entity.type === 'channel' ||entity.type === 'chat' ||+ // Agent-session rows exist in the inbox only through their settled /+ // waiting-for-input / mentioned notifications, so done resolves to+ // those notification ids like every other notification-backed type.+ entity.type === 'agent_session' ||entity.type === 'document' ||entity.type === 'project' ||entity.type === 'foreign' ||diff --git a/apps/web/src/lib/queries/notification/entity-mutations.ts b/apps/web/src/lib/queries/notification/entity-mutations.tsindex 53c6ee7e0d..d5773335b2 100644--- a/apps/web/src/lib/queries/notification/entity-mutations.ts+++ b/apps/web/src/lib/queries/notification/entity-mutations.ts@@ -12,6 +12,7 @@ import {} from '@service-storage/graphql-soup';type SimpleNotificationEntityType =+ | 'agent_session'| 'calendar_event'| 'call'| 'channel'@@ -49,6 +50,7 @@ export function toNotificationEntityRef(entity: FrontendNotificationEntity): NotificationEntityRef | undefined {switch (entity.type) {+ case 'agent_session':case 'calendar_event':case 'call':case 'channel':@@ -79,6 +81,7 @@ export type NotificationEntityUpdateOperation = Exclude<>;const ENTITY_TYPE_TO_GRAPHQL = {+ agent_session: 'AGENT_SESSION',calendar_event: 'CALENDAR_EVENT',call: 'CALL',channel: 'CHANNEL',diff --git a/apps/web/src/lib/queries/notification/tests/entity-mutations.test.ts b/apps/web/src/lib/queries/notification/tests/entity-mutations.test.tsindex 641700dd31..6257eb980f 100644--- a/apps/web/src/lib/queries/notification/tests/entity-mutations.test.ts+++ b/apps/web/src/lib/queries/notification/tests/entity-mutations.test.ts@@ -19,7 +19,32 @@ vi.mock('@service-storage/graphql-soup', () => ({mapGraphqlNotification: vi.fn((notification) => notification),}));-import { updateNotificationsForEntities } from '../entity-mutations';+import {+ toNotificationEntityInput,+ toNotificationEntityRef,+ updateNotificationsForEntities,+} from '../entity-mutations';++describe('toNotificationEntityRef', () => {+ it('targets agent sessions so their notifications can be marked done', () => {+ const ref = toNotificationEntityRef({+ type: 'agent_session',+ id: 'session-1',+ });++ expect(ref).toEqual({ type: 'agent_session', id: 'session-1' });+ expect(toNotificationEntityInput(ref!)).toEqual({+ entityType: 'AGENT_SESSION',+ entityId: 'session-1',+ });+ });++ it('has no target for entity types the notification service does not file under', () => {+ expect(+ toNotificationEntityRef({ type: 'automation', id: 'automation-1' })+ ).toBeUndefined();+ });+});describe('updateNotificationsForEntities', () => {beforeEach(() => {diff --git a/apps/web/src/lib/queries/notification/tests/user-notifications.test.tsx b/apps/web/src/lib/queries/notification/tests/user-notifications.test.tsxindex 9f83b0a349..4b00ebb454 100644--- a/apps/web/src/lib/queries/notification/tests/user-notifications.test.tsx+++ b/apps/web/src/lib/queries/notification/tests/user-notifications.test.tsx@@ -1056,6 +1056,43 @@ describe('optimisticInsertNotification', () => {expect(mockRefetchSoupEntity).not.toHaveBeenCalled();});+ it('restores an agent-session row on an agent notification', () => {+ // An agent-session row marked done left the inbox; the next settled /+ // waiting-for-input notification has to bring it back like any other+ // notification-backed entity.+ mockHasSoupEntity.mockReturnValue(true);+ seedQueryCache([createMockNotificationPage([])]);++ const agentNotification = createMockNotification({+ entity_type: 'agent_session',+ entity_id: 'session-1',+ created_at: '2024-01-01T00:00:00.000Z',+ notification_event_type: 'agent_session_settled',+ notification_metadata: {+ tag: 'agent_session_settled',+ content: {+ sessionName: 'Fix mark done',+ excerpt: 'Done.',+ },+ },+ } as unknown as Partial<UnifiedNotification>);++ optimisticInsertNotification(agentNotification);++ expect(mockOptimisticUpdateSoupItemUpdatedAt).toHaveBeenCalledWith(+ 'session-1',+ 'agentSession',+ '2024-01-01T00:00:00.000Z'+ );+ expect(vi.mocked(bumpSoupEntityNotifiedAt)).toHaveBeenCalledWith(+ 'session-1',+ '2024-01-01T00:00:00.000Z'+ );+ expect(+ vi.mocked(restoreSoupEntityToDoneFilteredQueries)+ ).toHaveBeenCalledWith('session-1', 'unseen');+ });+it('should skip soup update for unsupported entity types', () => {seedQueryCache([createMockNotificationPage([])]);diff --git a/apps/web/src/lib/queries/notification/user-notifications.ts b/apps/web/src/lib/queries/notification/user-notifications.tsindex 6f66fa93c2..9208acab08 100644--- a/apps/web/src/lib/queries/notification/user-notifications.ts+++ b/apps/web/src/lib/queries/notification/user-notifications.ts@@ -928,6 +928,7 @@ function notificationEntityTypeToSoupTag(.with('foreign_entity', () => 'foreignEntity' as const).with('reminder', () => 'reminder' as const).with('calendar_event', () => 'calendarEvent' as const)+ .with('agent_session', () => 'agentSession' as const).with(P.union('user',@@ -938,7 +939,6 @@ function notificationEntityTypeToSoupTag('crm_company','crm_contact','skill',- 'agent_session','scheduled_action','initiative'),