Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

fix(soup): calendar events not filtered out (#5505)

dev-rb107a86aecbd0
diff --git a/apps/web/src/features/companies/Company/use-company-emails-query.ts b/apps/web/src/features/companies/Company/use-company-emails-query.ts
index 7dcd36665b..3c728c911a 100644
--- a/apps/web/src/features/companies/Company/use-company-emails-query.ts
+++ b/apps/web/src/features/companies/Company/use-company-emails-query.ts
@@ -30,6 +30,7 @@ export function useCompanyEmailsQuery(
return useSoupAstItemsQuery(
() => {
const base = {
+ calf: { l: { id: NIL_UUID } },
df: { l: { id: NIL_UUID } },
chanf: { l: { ChannelId: NIL_UUID } },
cthf: { l: { ThreadId: NIL_UUID } },
diff --git a/apps/web/src/features/contacts/Contact/use-contact-emails-query.ts b/apps/web/src/features/contacts/Contact/use-contact-emails-query.ts
index 0741b4b0a5..d71216ce9e 100644
--- a/apps/web/src/features/contacts/Contact/use-contact-emails-query.ts
+++ b/apps/web/src/features/contacts/Contact/use-contact-emails-query.ts
@@ -31,6 +31,7 @@ export function useContactEmailsQuery(
() => {
const addr = email();
const base = {
+ calf: { l: { id: NIL_UUID } },
df: { l: { id: NIL_UUID } },
chanf: { l: { ChannelId: NIL_UUID } },
cthf: { l: { ThreadId: NIL_UUID } },
diff --git a/apps/web/src/features/next-soup/debug/DocumentWherePlayground.tsx b/apps/web/src/features/next-soup/debug/DocumentWherePlayground.tsx
index 1689a22d0f..8a866adca7 100644
--- a/apps/web/src/features/next-soup/debug/DocumentWherePlayground.tsx
+++ b/apps/web/src/features/next-soup/debug/DocumentWherePlayground.tsx
@@ -203,6 +203,7 @@ const EXAMPLES: {
const SIMPLE_SOUP_NON_DOCUMENT_FILTERS: Pick<
PostSoupRequest,
+ | 'calendar_event_filters'
| 'call_filters'
| 'channel_filters'
| 'channel_thread_filters'
@@ -212,6 +213,7 @@ const SIMPLE_SOUP_NON_DOCUMENT_FILTERS: Pick<
| 'foreign_entity_filters'
| 'project_filters'
> = {
+ calendar_event_filters: { calendar_event_ids: [NIL_UUID] },
call_filters: { call_ids: [NIL_UUID] },
channel_filters: { channel_ids: [NIL_UUID] },
channel_thread_filters: { thread_ids: [NIL_UUID] },
@@ -223,6 +225,7 @@ const SIMPLE_SOUP_NON_DOCUMENT_FILTERS: Pick<
};
const AST_SOUP_DOCUMENT_ONLY_FILTERS: Query['include'] = {
+ calendarEventId: [NIL_UUID],
callId: [NIL_UUID],
channelId: [NIL_UUID],
channelThreadId: [NIL_UUID],
diff --git a/apps/web/src/features/next-soup/filters/filter-store/compile.test.ts b/apps/web/src/features/next-soup/filters/filter-store/compile.test.ts
index 9b7f67037c..54020cb03d 100644
--- a/apps/web/src/features/next-soup/filters/filter-store/compile.test.ts
+++ b/apps/web/src/features/next-soup/filters/filter-store/compile.test.ts
@@ -12,6 +12,7 @@ describe('defineQueryFilters', () => {
expect(query.include?.threadId).toBeUndefined();
// ...while other entity targets are still excluded.
expect(query.include?.documentId).toEqual([NIL_UUID]);
+ expect(query.include?.calendarEventId).toEqual([NIL_UUID]);
expect(query.include?.chatId).toEqual([NIL_UUID]);
});
@@ -20,10 +21,36 @@ describe('defineQueryFilters', () => {
expect(query.include?.threadId).toEqual([NIL_UUID]);
expect(query.include?.documentId).toEqual([NIL_UUID]);
+ expect(query.include?.calendarEventId).toEqual([NIL_UUID]);
+ });
+
+ it('treats calendar event ids as referencing the calendar target', () => {
+ const query = defineQueryFilters({
+ exclude: { calendarEventId: [NIL_UUID] },
+ });
+
+ expect(query.include?.calendarEventId).toBeUndefined();
+ expect(query.include?.documentId).toEqual([NIL_UUID]);
});
});
describe('compileToAst', () => {
+ it('NIL-excludes calendar events from query states that predate the target', () => {
+ const ast = compileToAst(
+ queryStateFrom({ include: { threadId: ['thread-1'] } })
+ );
+
+ expect(ast.calf).toEqual({ l: { id: NIL_UUID } });
+ });
+
+ it('compiles calendar event ids to the calendar AST target', () => {
+ const ast = compileToAst(
+ queryStateFrom({ include: { calendarEventId: ['event-1'] } })
+ );
+
+ expect(ast.calf).toEqual({ l: { id: 'event-1' } });
+ });
+
it('keeps existing flat include and exclude document filters unchanged', () => {
const state: QueryState = {
include: {
diff --git a/apps/web/src/features/next-soup/filters/filter-store/compile.ts b/apps/web/src/features/next-soup/filters/filter-store/compile.ts
index 44864776cb..407c8119fc 100644
--- a/apps/web/src/features/next-soup/filters/filter-store/compile.ts
+++ b/apps/web/src/features/next-soup/filters/filter-store/compile.ts
@@ -20,6 +20,7 @@ type BackendAst =
type QueryTarget =
| 'df'
+ | 'calf'
| 'ef'
| 'chanf'
| 'cthf'
@@ -88,6 +89,7 @@ const FIELD_CONFIG: Record<
documentSeen: { target: 'df', field: 'ns' },
documentDone: { target: 'df', field: 'nd' },
isEmailAttachment: { target: 'df', field: 'iea' },
+ calendarEventId: { target: 'calf', field: 'id' },
threadId: { target: 'ef', field: 'ThreadId' },
emailLinkId: { target: 'ef', field: 'Owner' },
emailSeen: { target: 'ef', field: 'NotificationSeen' },
@@ -186,6 +188,7 @@ export const queryStateFrom = (query: Query): QueryState => ({
const emptyTargetAstLists = (): Record<QueryTarget, BackendAst[]> => ({
df: [],
+ calf: [],
ef: [],
chanf: [],
cthf: [],
@@ -405,7 +408,17 @@ export function compileToAst(state: QueryState): TargetAstMap {
}
}
- // Unless explicitly includes/excluded, channel threads are excluded by default
+ // Calendar events are not rendered by Soup yet. Persisted query states from
+ // before the calendar target existed do not carry its NIL id filter, so keep
+ // them scoped unless a calendar filter is explicitly present.
+ if (
+ !('calendarEventId' in state.include) &&
+ !('calendarEventId' in state.exclude)
+ ) {
+ result.calf ??= AST.literal('id', NIL_UUID);
+ }
+
+ // Unless explicitly included/excluded, channel threads are excluded by default
if (
!('channelThreadId' in state.include) &&
!('channelThreadId' in state.exclude)
@@ -422,6 +435,7 @@ export function compileToAst(state: QueryState): TargetAstMap {
const ID_FIELD_NAMES: Partial<Record<QueryTarget, FieldName>> = {
df: 'documentId',
+ calf: 'calendarEventId',
ef: 'threadId',
chanf: 'channelId',
cthf: 'channelThreadId',
diff --git a/apps/web/src/features/next-soup/filters/filter-store/types.ts b/apps/web/src/features/next-soup/filters/filter-store/types.ts
index 1cfbd45e5d..081e3d29e1 100644
--- a/apps/web/src/features/next-soup/filters/filter-store/types.ts
+++ b/apps/web/src/features/next-soup/filters/filter-store/types.ts
@@ -32,6 +32,7 @@ export type ArrayFieldFilters = {
subType?: string[];
projectId?: string[];
documentOwnerId?: string[];
+ calendarEventId?: string[];
threadId?: string[];
emailLinkId?: string[];
emailProjectId?: string[];
diff --git a/apps/web/src/features/next-soup/filters/query-filters.test.ts b/apps/web/src/features/next-soup/filters/query-filters.test.ts
index ac6884e2be..b2fcb86e40 100644
--- a/apps/web/src/features/next-soup/filters/query-filters.test.ts
+++ b/apps/web/src/features/next-soup/filters/query-filters.test.ts
@@ -2,6 +2,8 @@ import type { SoupApiItem } from '@service-storage/generated/schemas';
import { describe, expect, it } from 'vitest';
import type { Query } from './filter-store/types';
import {
+ filterSoupItemByRequestBody,
+ QUERY_FILTERS_BASE,
soupItemMatchesProjectMembership,
soupItemMatchesQuery,
} from './query-filters';
@@ -23,6 +25,9 @@ const taskItem = (id: string): SoupApiItem =>
const emailItem = (id: string): SoupApiItem =>
({ tag: 'emailThread', data: { id } }) as unknown as SoupApiItem;
+const calendarEventItem = (id: string): SoupApiItem =>
+ ({ tag: 'calendarEvent', data: { id } }) as unknown as SoupApiItem;
+
const chatItem = (id: string, overrides: object = {}): SoupApiItem =>
({ tag: 'chat', data: { id, ...overrides } }) as unknown as SoupApiItem;
@@ -38,6 +43,9 @@ describe('soupItemMatchesQuery', () => {
expect(soupItemMatchesQuery(emailItem('thread-1'), query)).toBe(true);
// A freshly created task/doc must NOT leak into an email-scoped list.
expect(soupItemMatchesQuery(documentItem('doc-1'), query)).toBe(false);
+ expect(soupItemMatchesQuery(calendarEventItem('event-1'), query)).toBe(
+ false
+ );
expect(soupItemMatchesQuery(chatItem('chat-1'), query)).toBe(false);
});
@@ -137,6 +145,19 @@ describe('soupItemMatchesQuery', () => {
});
});
+describe('filterSoupItemByRequestBody', () => {
+ it('excludes calendar events from typed queries using the base filters', () => {
+ expect(QUERY_FILTERS_BASE.calendar_event_filters).toEqual({
+ calendar_event_ids: ['00000000-0000-0000-0000-000000000000'],
+ });
+ expect(
+ filterSoupItemByRequestBody(calendarEventItem('event-1'), {
+ ...QUERY_FILTERS_BASE,
+ })
+ ).toBe(false);
+ });
+});
+
describe('soupItemMatchesProjectMembership', () => {
const PROJECT = 'proj-1';
diff --git a/apps/web/src/features/next-soup/filters/query-filters.ts b/apps/web/src/features/next-soup/filters/query-filters.ts
index ab36098083..c131311994 100644
--- a/apps/web/src/features/next-soup/filters/query-filters.ts
+++ b/apps/web/src/features/next-soup/filters/query-filters.ts
@@ -15,6 +15,7 @@ const EXCLUDE: string[] = [NIL_UUID];
// Base filter that excludes all entity types by default
export const QUERY_FILTERS_BASE: SoupItemsQueryFilters = {
+ calendar_event_filters: { calendar_event_ids: EXCLUDE },
call_filters: { call_ids: EXCLUDE },
channel_filters: { channel_ids: EXCLUDE },
channel_thread_filters: { thread_ids: EXCLUDE },
diff --git a/apps/web/src/features/next-soup/sidebar/soup-filter-presets.test.ts b/apps/web/src/features/next-soup/sidebar/soup-filter-presets.test.ts
index fe157794f8..7b42ecc426 100644
--- a/apps/web/src/features/next-soup/sidebar/soup-filter-presets.test.ts
+++ b/apps/web/src/features/next-soup/sidebar/soup-filter-presets.test.ts
@@ -17,3 +17,19 @@ describe('mail view presets', () => {
}
});
});
+
+describe('calendar event scoping', () => {
+ it('excludes calendar events from views that do not render them', () => {
+ const nilId = '00000000-0000-0000-0000-000000000000';
+
+ expect(
+ getViewPreset('mail', 'important')?.filters.include?.calendarEventId
+ ).toEqual([nilId]);
+ expect(
+ getViewPreset('inbox', 'all')?.filters.include?.calendarEventId
+ ).toEqual([nilId]);
+ expect(
+ getViewPreset('search', 'all')?.filters.include?.calendarEventId
+ ).toEqual([nilId]);
+ });
+});
diff --git a/apps/web/src/features/next-soup/sidebar/soup-filter-presets.ts b/apps/web/src/features/next-soup/sidebar/soup-filter-presets.ts
index 27acc2320c..9799730d67 100644
--- a/apps/web/src/features/next-soup/sidebar/soup-filter-presets.ts
+++ b/apps/web/src/features/next-soup/sidebar/soup-filter-presets.ts
@@ -137,8 +137,10 @@ export const VIEW_TAB_PRESETS: Record<ListView, ViewTabConfig> = {
}),
all: () => ({
filters: {
- // crm companies aren't surfaced outside the Companies view.
+ // Calendar events are not rendered by Soup, and CRM companies are
+ // not surfaced outside the Companies view.
include: {
+ calendarEventId: [NIL_UUID],
crmCompanyId: [NIL_UUID],
...(ENABLE_SUPPORTED_SOUP_FOREIGN_ENTITIES_OVERRIDE
? { foreignEntitySource: ['github_pull_request'] }
@@ -488,13 +490,14 @@ export const VIEW_TAB_PRESETS: Record<ListView, ViewTabConfig> = {
all: () => ({
// Temporary: search has no full-text index over foreign entities yet,
// so always exclude them (matching no record id) until search supports
- // them. CRM rows and non-displayable channel-thread rows are
+ // them. Calendar, CRM, and non-displayable channel-thread rows are
// NIL-excluded the same way. `search-supported` mirrors these
// exclusions client-side so entities that enter the soup cache outside
// this query (e.g. websocket-driven inserts) don't surface in the
// search feed.
filters: {
include: {
+ calendarEventId: [NIL_UUID],
foreignEntityRecordId: [NIL_UUID],
crmCompanyId: [NIL_UUID],
channelThreadId: [NIL_UUID],
diff --git a/apps/web/src/features/next-soup/soup-view/create-search-state.ts b/apps/web/src/features/next-soup/soup-view/create-search-state.ts
index 95d8852139..386cc327b1 100644
--- a/apps/web/src/features/next-soup/soup-view/create-search-state.ts
+++ b/apps/web/src/features/next-soup/soup-view/create-search-state.ts
@@ -67,6 +67,18 @@ function filterDataToQueryFilters(data: QueryState): EntityFilters {
const filters: EntityFilters = {};
const { include } = data;
+ // Calendar events are not displayed in Soup search. Older restored query
+ // states predate calendarEventId, so treat a missing field as match-nothing;
+ // an explicit include/exclude remains authoritative.
+ const calendarEventIds =
+ include.calendarEventId ??
+ (data.exclude.calendarEventId === undefined ? [NIL_UUID] : undefined);
+ if (calendarEventIds?.length) {
+ filters.calendar_event_filters = {
+ calendar_event_ids: calendarEventIds,
+ };
+ }
+
// Document filters
if (
include.documentId?.length ||
diff --git a/apps/web/src/lib/queries/soup/backfill.ts b/apps/web/src/lib/queries/soup/backfill.ts
index aaa53d177b..8c7bbde812 100644
--- a/apps/web/src/lib/queries/soup/backfill.ts
+++ b/apps/web/src/lib/queries/soup/backfill.ts
@@ -15,7 +15,7 @@ import {
// Bump when a default backfill input changes so persisted opaque cursors
// cannot retain the previous server-side filters.
-const BACKFILL_VERSION = 3;
+const BACKFILL_VERSION = 4;
const PAGE_LIMIT = 250;
// The email-content DataLoader rejects operations with more than 20 threads.
const EMAIL_CONTENT_PAGE_LIMIT = 20;
@@ -42,6 +42,7 @@ export const CORE_SOUP_BACKFILL_LANE: SoupBackfillParams = {
sortMethod: 'VIEWED_UPDATED',
emailView: 'ALL',
filters: {
+ calendarEventFilter: { literal: { id: EXCLUDED_ENTITY_ID } },
emailFilter: { tree: { literal: { threadId: EXCLUDED_ENTITY_ID } } },
channelThreadFilter: { literal: { threadId: EXCLUDED_ENTITY_ID } },
callFilter: { literal: { callId: EXCLUDED_ENTITY_ID } },
@@ -63,6 +64,7 @@ export const EMAIL_SOUP_BACKFILL_LANE: SoupBackfillParams = {
sortMethod: 'VIEWED_UPDATED',
emailView: 'ALL',
filters: {
+ calendarEventFilter: { literal: { id: EXCLUDED_ENTITY_ID } },
documentFilter: { literal: { id: EXCLUDED_ENTITY_ID } },
projectFilter: { literal: { projectIdSelf: EXCLUDED_ENTITY_ID } },
chatFilter: { literal: { chatId: EXCLUDED_ENTITY_ID } },
@@ -84,6 +86,7 @@ export const AUXILIARY_SOUP_BACKFILL_LANE: SoupBackfillParams = {
sortMethod: 'VIEWED_UPDATED',
emailView: 'ALL',
filters: {
+ calendarEventFilter: { literal: { id: EXCLUDED_ENTITY_ID } },
documentFilter: { literal: { id: EXCLUDED_ENTITY_ID } },
projectFilter: { literal: { projectIdSelf: EXCLUDED_ENTITY_ID } },
chatFilter: { literal: { chatId: EXCLUDED_ENTITY_ID } },
diff --git a/apps/web/src/lib/queries/soup/graphql/ast.test.ts b/apps/web/src/lib/queries/soup/graphql/ast.test.ts
index 7fb5b456ee..d92a337f6a 100644
--- a/apps/web/src/lib/queries/soup/graphql/ast.test.ts
+++ b/apps/web/src/lib/queries/soup/graphql/ast.test.ts
@@ -205,6 +205,30 @@ describe('makeGraphqlSoupInput', () => {
});
});
+ it('maps calendar event id filters', () => {
+ const input = makeGraphqlSoupInput({
+ params: { limit: 100, sort_method: 'updated_at' },
+ body: { calf: { l: { id: 'event-1' } } } as never,
+ });
+
+ expect(input).toMatchObject({
+ initial: {
+ filters: {
+ calendarEventFilter: { literal: { id: 'event-1' } },
+ },
+ },
+ });
+ });
+
+ it('throws for unsupported calendar literals so callers can fall back', () => {
+ expect(() =>
+ makeGraphqlSoupInput({
+ params: { limit: 100, sort_method: 'updated_at' },
+ body: { calf: { l: { s: 'confirmed' } } } as never,
+ })
+ ).toThrow('Unsupported GraphQL Soup AST');
+ });
+
it('throws for REST-only file association literals so callers can fall back', () => {
expect(() =>
makeInput({
@@ -215,7 +239,6 @@ describe('makeGraphqlSoupInput', () => {
it('throws for REST-only top-level filters instead of silently widening the query', () => {
for (const body of [
- { calf: { l: { id: 'event-1' } } },
{ eca: ['[email protected]'] },
{ ecd: ['example.com'] },
]) {
diff --git a/apps/web/src/lib/queries/soup/graphql/ast.ts b/apps/web/src/lib/queries/soup/graphql/ast.ts
index 60558d84c8..2b0613bed9 100644
--- a/apps/web/src/lib/queries/soup/graphql/ast.ts
+++ b/apps/web/src/lib/queries/soup/graphql/ast.ts
@@ -1,4 +1,5 @@
import type {
+ GraphqlCalendarEventLiteral as GraphqlCalendarEventLiteralInput,
GraphqlCallLiteral as GraphqlCallLiteralInput,
GraphqlCallStatus,
GraphqlChannelLiteral as GraphqlChannelLiteralInput,
@@ -47,6 +48,7 @@ type RestAst =
| { l: unknown };
type TargetAstKey =
+ | 'calf'
| 'df'
| 'pf'
| 'cf'
@@ -59,8 +61,7 @@ type TargetAstKey =
| 'propf';
type AstBody = Partial<Record<TargetAstKey, RestAst>> & {
- /** Calendar, CRM-address, and CRM-domain filters are REST-only today. */
- calf?: unknown;
+ /** CRM-address and CRM-domain filters are REST-only today. */
eca?: string[];
ecd?: string[];
emailView?: 'inbox' | 'drafts' | 'sent' | 'all';
@@ -198,6 +199,18 @@ function mapEmailValue(value: unknown): GraphqlEmailValueInput {
unsupported('expected partial/complete/domain email value');
}
+function mapCalendarEventLiteral(
+ literal: unknown
+): GraphqlCalendarEventLiteralInput {
+ const [field, value] = singleLiteralField(literal);
+ switch (field) {
+ case 'id':
+ return { id: mapString(value, 'id') };
+ default:
+ unsupported(`calendar event literal ${field}`);
+ }
+}
+
function mapDocumentLiteral(literal: unknown): GraphqlDocumentLiteralInput {
const [field, value] = singleLiteralField(literal);
switch (field) {
@@ -499,9 +512,6 @@ function mapEmailView(
}
function assertGraphqlCompatibleBody(body: AstBody): void {
- if (body.calf !== undefined) {
- unsupported('calendar filters are not supported by GraphQL Soup yet');
- }
if (body.eca !== undefined) {
unsupported(
'CRM-scoped email address filters are not supported by GraphQL Soup yet'
@@ -518,6 +528,12 @@ function makeGraphqlFilters(body: AstBody): GraphqlEntityFilterAstInput {
assertGraphqlCompatibleBody(body);
const filters: GraphqlEntityFilterAstInput = {};
+ if (body.calf) {
+ filters.calendarEventFilter = compileExpr(
+ body.calf,
+ mapCalendarEventLiteral
+ );
+ }
if (body.df)
filters.documentFilter = compileExpr(body.df, mapDocumentLiteral);
if (body.pf) filters.projectFilter = compileExpr(body.pf, mapProjectLiteral);