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(soup): Importance filter (#1316)
Evan Hutnikcde8120cfa77
diff --git a/js/app/bun.lock b/js/app/bun.lockindex 24a2677495..abe551c154 100644--- a/js/app/bun.lock+++ b/js/app/bun.lock@@ -1,6 +1,5 @@{"lockfileVersion": 1,- "configVersion": 0,"workspaces": {"": {"name": "@coparse/monorepo",diff --git a/js/app/packages/service-clients/service-search/generated/models/channelFilters.ts b/js/app/packages/service-clients/service-search/generated/models/channelFilters.tsindex 274c77ae32..3edebc554d 100644--- a/js/app/packages/service-clients/service-search/generated/models/channelFilters.ts+++ b/js/app/packages/service-clients/service-search/generated/models/channelFilters.ts@@ -4,6 +4,7 @@* search_service* OpenAPI spec version: 0.1.0*/+import type { ChannelFiltersImportance } from './channelFiltersImportance';import type { ChannelFiltersOrgId } from './channelFiltersOrgId';/**@@ -12,6 +13,8 @@ import type { ChannelFiltersOrgId } from './channelFiltersOrgId';export interface ChannelFilters {/** Channel IDs to search within. Examples: ['general']. Empty to search all accessible channels. */channel_ids?: string[];+ /** Filter by channel importance. None to ignore, true to pass through (no clause), false to short-circuit and return nothing. */+ importance?: ChannelFiltersImportance;/** Channel user mentions to search for. Examples: ['@username']. Empty if not filtering by mentions. */mentions?: string[];/** Channel organization ID to search within. Empty to ignore organization filtering. */diff --git a/js/app/packages/service-clients/service-search/generated/models/channelFiltersImportance.ts b/js/app/packages/service-clients/service-search/generated/models/channelFiltersImportance.tsnew file mode 100644index 0000000000..8b72a2c1d0--- /dev/null+++ b/js/app/packages/service-clients/service-search/generated/models/channelFiltersImportance.ts@@ -0,0 +1,11 @@+/**+ * Generated by orval v7.13.0 🍺+ * Do not edit manually.+ * search_service+ * OpenAPI spec version: 0.1.0+ */++/**+ * Filter by channel importance. None to ignore, true to pass through (no clause), false to short-circuit and return nothing.+ */+export type ChannelFiltersImportance = boolean | null;diff --git a/js/app/packages/service-clients/service-search/generated/models/chatFilters.ts b/js/app/packages/service-clients/service-search/generated/models/chatFilters.tsindex d06230baff..38f463936d 100644--- a/js/app/packages/service-clients/service-search/generated/models/chatFilters.ts+++ b/js/app/packages/service-clients/service-search/generated/models/chatFilters.ts@@ -4,6 +4,7 @@* search_service* OpenAPI spec version: 0.1.0*/+import type { ChatFiltersImportance } from './chatFiltersImportance';/*** The chat filters used to filter down what chats you search over.@@ -11,6 +12,8 @@export interface ChatFilters {/** Chat ids to search over. Examples: ['chat1'], ['chat1', 'chat2']. When provided, chat search will only match results on these chats. Empty to search all accessible chats. */chat_ids?: string[];+ /** Filter by chat importance. None to ignore, true to pass through (no clause), false to short-circuit and return nothing. */+ importance?: ChatFiltersImportance;/** Filter by chat owner. Examples: ['macro|[email protected]'], ['macro|[email protected]', 'macro|[email protected]']. Empty to search all owners. */owners?: string[];/** A list of project ids to search within. Examples: ['project1']. Empty to ignore project filtering. */diff --git a/js/app/packages/service-clients/service-search/generated/models/chatFiltersImportance.ts b/js/app/packages/service-clients/service-search/generated/models/chatFiltersImportance.tsnew file mode 100644index 0000000000..a26730b758--- /dev/null+++ b/js/app/packages/service-clients/service-search/generated/models/chatFiltersImportance.ts@@ -0,0 +1,11 @@+/**+ * Generated by orval v7.13.0 🍺+ * Do not edit manually.+ * search_service+ * OpenAPI spec version: 0.1.0+ */++/**+ * Filter by chat importance. None to ignore, true to pass through (no clause), false to short-circuit and return nothing.+ */+export type ChatFiltersImportance = boolean | null;diff --git a/js/app/packages/service-clients/service-search/generated/models/documentFilters.ts b/js/app/packages/service-clients/service-search/generated/models/documentFilters.tsindex 266b81f788..0312a5bed8 100644--- a/js/app/packages/service-clients/service-search/generated/models/documentFilters.ts+++ b/js/app/packages/service-clients/service-search/generated/models/documentFilters.ts@@ -4,6 +4,7 @@* search_service* OpenAPI spec version: 0.1.0*/+import type { DocumentFiltersImportance } from './documentFiltersImportance';/*** The document filters used to filter down what documents you search over.@@ -13,6 +14,8 @@ export interface DocumentFilters {document_ids?: string[];/** Document file types to search. Examples: ['pdf'], ['md', 'txt']. Empty to search all file types. */file_types?: string[];+ /** Filter by document importance. None to ignore, true to pass through (no clause), false to short-circuit and return nothing. */+ importance?: DocumentFiltersImportance;/** Filter by document owner. Examples: ['macro|[email protected]'], ['macro|[email protected]', 'macro|[email protected]']. Empty to search all owners. */owners?: string[];/** A list of project ids to search within. Examples: ['project1'].diff --git a/js/app/packages/service-clients/service-search/generated/models/documentFiltersImportance.ts b/js/app/packages/service-clients/service-search/generated/models/documentFiltersImportance.tsnew file mode 100644index 0000000000..52797c304b--- /dev/null+++ b/js/app/packages/service-clients/service-search/generated/models/documentFiltersImportance.ts@@ -0,0 +1,11 @@+/**+ * Generated by orval v7.13.0 🍺+ * Do not edit manually.+ * search_service+ * OpenAPI spec version: 0.1.0+ */++/**+ * Filter by document importance. None to ignore, true to pass through (no clause), false to short-circuit and return nothing.+ */+export type DocumentFiltersImportance = boolean | null;diff --git a/js/app/packages/service-clients/service-search/generated/models/emailFilters.ts b/js/app/packages/service-clients/service-search/generated/models/emailFilters.tsindex 6d59444820..920be897ef 100644--- a/js/app/packages/service-clients/service-search/generated/models/emailFilters.ts+++ b/js/app/packages/service-clients/service-search/generated/models/emailFilters.ts@@ -4,6 +4,7 @@* search_service* OpenAPI spec version: 0.1.0*/+import type { EmailFiltersImportance } from './emailFiltersImportance';/*** The email filters used to filter down what emails you search over.@@ -13,6 +14,8 @@ export interface EmailFilters {bcc?: string[];/** Email CC addresses to filter by. Examples: ['[email protected]']. Empty if not filtering by CC. */cc?: string[];+ /** Filter by email importance. None to ignore, true to pass through (no clause), false to short-circuit and return nothing. */+ importance?: EmailFiltersImportance;/** Email Recipient addresses to filter by. Examples: ['[email protected]']. Empty if not filtering by Recipient. */recipients?: string[];/** Email sender addresses to filter by. Examples: ['[email protected]']. Empty to search all senders. */diff --git a/js/app/packages/service-clients/service-search/generated/models/emailFiltersImportance.ts b/js/app/packages/service-clients/service-search/generated/models/emailFiltersImportance.tsnew file mode 100644index 0000000000..3b2fc32a6d--- /dev/null+++ b/js/app/packages/service-clients/service-search/generated/models/emailFiltersImportance.ts@@ -0,0 +1,11 @@+/**+ * Generated by orval v7.13.0 🍺+ * Do not edit manually.+ * search_service+ * OpenAPI spec version: 0.1.0+ */++/**+ * Filter by email importance. None to ignore, true to pass through (no clause), false to short-circuit and return nothing.+ */+export type EmailFiltersImportance = boolean | null;diff --git a/js/app/packages/service-clients/service-search/generated/models/index.ts b/js/app/packages/service-clients/service-search/generated/models/index.tsindex ccae976bcb..dbb3861f98 100644--- a/js/app/packages/service-clients/service-search/generated/models/index.ts+++ b/js/app/packages/service-clients/service-search/generated/models/index.ts@@ -6,6 +6,7 @@*/export * from './channelFilters';+export * from './channelFiltersImportance';export * from './channelFiltersOrgId';export * from './channelMetadata';export * from './channelMetadataInteractedAt';@@ -30,6 +31,7 @@ export * from './channelSearchResultSenderId';export * from './channelSearchResultThreadId';export * from './channelSearchResultUpdatedAt';export * from './chatFilters';+export * from './chatFiltersImportance';export * from './chatMessageSearchResult';export * from './chatMessageSearchResultChatMessageId';export * from './chatMessageSearchResultRole';@@ -50,6 +52,7 @@ export * from './chatSearchResponseItemWithMetadata';export * from './chatSearchResponseItemWithMetadataAllOf';export * from './chatSearchResponseItemWithMetadataAllOfMetadata';export * from './documentFilters';+export * from './documentFiltersImportance';export * from './documentMetadata';export * from './documentMetadataDeletedAt';export * from './documentMetadataProjectId';@@ -73,6 +76,7 @@ export * from './documentSearchResultRawContent';export * from './documentSearchResultScore';export * from './documentSubType';export * from './emailFilters';+export * from './emailFiltersImportance';export * from './emailSearchRequest';export * from './emailSearchRequestAllOf';export * from './emailSearchRequestAllOfTwo';@@ -96,6 +100,7 @@ export * from './errorResponse';export * from './fileType';export * from './matchType';export * from './projectFilters';+export * from './projectFiltersImportance';export * from './projectMetadata';export * from './projectMetadataDeletedAt';export * from './projectMetadataParentProjectId';diff --git a/js/app/packages/service-clients/service-search/generated/models/projectFilters.ts b/js/app/packages/service-clients/service-search/generated/models/projectFilters.tsindex 7a35ffb768..4dbb57fe07 100644--- a/js/app/packages/service-clients/service-search/generated/models/projectFilters.ts+++ b/js/app/packages/service-clients/service-search/generated/models/projectFilters.ts@@ -4,11 +4,14 @@* search_service* OpenAPI spec version: 0.1.0*/+import type { ProjectFiltersImportance } from './projectFiltersImportance';/*** The project filters used to filter down what projects you search over.*/export interface ProjectFilters {+ /** Filter by project importance. None to ignore, true to pass through (no clause), false to short-circuit and return nothing. */+ importance?: ProjectFiltersImportance;/** Filter by project owner. Examples: ['macro|[email protected]'], ['macro|[email protected]', 'macro|[email protected]']. Empty to search all owners. */owners?: string[];/** Project IDs to search within. Examples: ['project1']. Empty to search all accessible projects. */diff --git a/js/app/packages/service-clients/service-search/generated/models/projectFiltersImportance.ts b/js/app/packages/service-clients/service-search/generated/models/projectFiltersImportance.tsnew file mode 100644index 0000000000..d787d1f907--- /dev/null+++ b/js/app/packages/service-clients/service-search/generated/models/projectFiltersImportance.ts@@ -0,0 +1,11 @@+/**+ * Generated by orval v7.13.0 🍺+ * Do not edit manually.+ * search_service+ * OpenAPI spec version: 0.1.0+ */++/**+ * Filter by project importance. None to ignore, true to pass through (no clause), false to short-circuit and return nothing.+ */+export type ProjectFiltersImportance = boolean | null;diff --git a/js/app/packages/service-clients/service-search/openapi.json b/js/app/packages/service-clients/service-search/openapi.jsonindex cf894dc1d0..42bf0667db 100644--- a/js/app/packages/service-clients/service-search/openapi.json+++ b/js/app/packages/service-clients/service-search/openapi.json@@ -184,6 +184,10 @@},"description": "Channel IDs to search within. Examples: ['general']. Empty to search all accessible channels."},+ "importance": {+ "type": ["boolean", "null"],+ "description": "Filter by channel importance. None to ignore, true to pass through (no clause), false to short-circuit and return nothing."+ },"mentions": {"type": "array","items": {@@ -409,6 +413,10 @@},"description": "Chat ids to search over. Examples: ['chat1'], ['chat1', 'chat2']. When provided, chat search will only match results on these chats. Empty to search all accessible chats."},+ "importance": {+ "type": ["boolean", "null"],+ "description": "Filter by chat importance. None to ignore, true to pass through (no clause), false to short-circuit and return nothing."+ },"owners": {"type": "array","items": {@@ -628,6 +636,10 @@},"description": "Document file types to search. Examples: ['pdf'], ['md', 'txt']. Empty to search all file types."},+ "importance": {+ "type": ["boolean", "null"],+ "description": "Filter by document importance. None to ignore, true to pass through (no clause), false to short-circuit and return nothing."+ },"owners": {"type": "array","items": {@@ -859,6 +871,10 @@},"description": "Email CC addresses to filter by. Examples: ['[email protected]']. Empty if not filtering by CC."},+ "importance": {+ "type": ["boolean", "null"],+ "description": "Filter by email importance. None to ignore, true to pass through (no clause), false to short-circuit and return nothing."+ },"recipients": {"type": "array","items": {@@ -1149,6 +1165,10 @@"type": "object","description": "The project filters used to filter down what projects you search over.","properties": {+ "importance": {+ "type": ["boolean", "null"],+ "description": "Filter by project importance. None to ignore, true to pass through (no clause), false to short-circuit and return nothing."+ },"owners": {"type": "array","items": {diff --git a/js/app/packages/service-clients/service-storage/generated/schemas/channelFilters.ts b/js/app/packages/service-clients/service-storage/generated/schemas/channelFilters.tsindex 0514b638ee..7ce749b6a7 100644--- a/js/app/packages/service-clients/service-storage/generated/schemas/channelFilters.ts+++ b/js/app/packages/service-clients/service-storage/generated/schemas/channelFilters.ts@@ -4,6 +4,7 @@* document_storage_service* OpenAPI spec version: 0.1.0*/+import type { ChannelFiltersImportance } from './channelFiltersImportance';import type { ChannelFiltersOrgId } from './channelFiltersOrgId';/**@@ -12,6 +13,8 @@ import type { ChannelFiltersOrgId } from './channelFiltersOrgId';export interface ChannelFilters {/** Channel IDs to search within. Examples: ['general']. Empty to search all accessible channels. */channel_ids?: string[];+ /** Filter by channel importance. None to ignore, true to pass through (no clause), false to short-circuit and return nothing. */+ importance?: ChannelFiltersImportance;/** Channel user mentions to search for. Examples: ['@username']. Empty if not filtering by mentions. */mentions?: string[];/** Channel organization ID to search within. Empty to ignore organization filtering. */diff --git a/js/app/packages/service-clients/service-storage/generated/schemas/channelFiltersImportance.ts b/js/app/packages/service-clients/service-storage/generated/schemas/channelFiltersImportance.tsnew file mode 100644index 0000000000..df0a48b237--- /dev/null+++ b/js/app/packages/service-clients/service-storage/generated/schemas/channelFiltersImportance.ts@@ -0,0 +1,11 @@+/**+ * Generated by orval v7.13.0 🍺+ * Do not edit manually.+ * document_storage_service+ * OpenAPI spec version: 0.1.0+ */++/**+ * Filter by channel importance. None to ignore, true to pass through (no clause), false to short-circuit and return nothing.+ */+export type ChannelFiltersImportance = boolean | null;diff --git a/js/app/packages/service-clients/service-storage/generated/schemas/chatFilters.ts b/js/app/packages/service-clients/service-storage/generated/schemas/chatFilters.tsindex a14605cf13..14dae282b6 100644--- a/js/app/packages/service-clients/service-storage/generated/schemas/chatFilters.ts+++ b/js/app/packages/service-clients/service-storage/generated/schemas/chatFilters.ts@@ -4,6 +4,7 @@* document_storage_service* OpenAPI spec version: 0.1.0*/+import type { ChatFiltersImportance } from './chatFiltersImportance';/*** The chat filters used to filter down what chats you search over.@@ -11,6 +12,8 @@export interface ChatFilters {/** Chat ids to search over. Examples: ['chat1'], ['chat1', 'chat2']. When provided, chat search will only match results on these chats. Empty to search all accessible chats. */chat_ids?: string[];+ /** Filter by chat importance. None to ignore, true to pass through (no clause), false to short-circuit and return nothing. */+ importance?: ChatFiltersImportance;/** Filter by chat owner. Examples: ['macro|[email protected]'], ['macro|[email protected]', 'macro|[email protected]']. Empty to search all owners. */owners?: string[];/** A list of project ids to search within. Examples: ['project1']. Empty to ignore project filtering. */diff --git a/js/app/packages/service-clients/service-storage/generated/schemas/chatFiltersImportance.ts b/js/app/packages/service-clients/service-storage/generated/schemas/chatFiltersImportance.tsnew file mode 100644index 0000000000..4f5ef152e9--- /dev/null+++ b/js/app/packages/service-clients/service-storage/generated/schemas/chatFiltersImportance.ts@@ -0,0 +1,11 @@+/**+ * Generated by orval v7.13.0 🍺+ * Do not edit manually.+ * document_storage_service+ * OpenAPI spec version: 0.1.0+ */++/**+ * Filter by chat importance. None to ignore, true to pass through (no clause), false to short-circuit and return nothing.+ */+export type ChatFiltersImportance = boolean | null;diff --git a/js/app/packages/service-clients/service-storage/generated/schemas/documentFilters.ts b/js/app/packages/service-clients/service-storage/generated/schemas/documentFilters.tsindex e0596668fe..0055f74a47 100644--- a/js/app/packages/service-clients/service-storage/generated/schemas/documentFilters.ts+++ b/js/app/packages/service-clients/service-storage/generated/schemas/documentFilters.ts@@ -4,6 +4,7 @@* document_storage_service* OpenAPI spec version: 0.1.0*/+import type { DocumentFiltersImportance } from './documentFiltersImportance';/*** The document filters used to filter down what documents you search over.@@ -13,6 +14,8 @@ export interface DocumentFilters {document_ids?: string[];/** Document file types to search. Examples: ['pdf'], ['md', 'txt']. Empty to search all file types. */file_types?: string[];+ /** Filter by document importance. None to ignore, true to pass through (no clause), false to short-circuit and return nothing. */+ importance?: DocumentFiltersImportance;/** Filter by document owner. Examples: ['macro|[email protected]'], ['macro|[email protected]', 'macro|[email protected]']. Empty to search all owners. */owners?: string[];/** A list of project ids to search within. Examples: ['project1'].diff --git a/js/app/packages/service-clients/service-storage/generated/schemas/documentFiltersImportance.ts b/js/app/packages/service-clients/service-storage/generated/schemas/documentFiltersImportance.tsnew file mode 100644index 0000000000..d7bb700d46--- /dev/null+++ b/js/app/packages/service-clients/service-storage/generated/schemas/documentFiltersImportance.ts@@ -0,0 +1,11 @@+/**+ * Generated by orval v7.13.0 🍺+ * Do not edit manually.+ * document_storage_service+ * OpenAPI spec version: 0.1.0+ */++/**+ * Filter by document importance. None to ignore, true to pass through (no clause), false to short-circuit and return nothing.+ */+export type DocumentFiltersImportance = boolean | null;diff --git a/js/app/packages/service-clients/service-storage/generated/schemas/emailFilters.ts b/js/app/packages/service-clients/service-storage/generated/schemas/emailFilters.tsindex 7a17efd6e0..33f09dd75e 100644--- a/js/app/packages/service-clients/service-storage/generated/schemas/emailFilters.ts+++ b/js/app/packages/service-clients/service-storage/generated/schemas/emailFilters.ts@@ -4,6 +4,7 @@* document_storage_service* OpenAPI spec version: 0.1.0*/+import type { EmailFiltersImportance } from './emailFiltersImportance';/*** The email filters used to filter down what emails you search over.@@ -13,6 +14,8 @@ export interface EmailFilters {bcc?: string[];/** Email CC addresses to filter by. Examples: ['[email protected]']. Empty if not filtering by CC. */cc?: string[];+ /** Filter by email importance. None to ignore, true to pass through (no clause), false to short-circuit and return nothing. */+ importance?: EmailFiltersImportance;/** Email Recipient addresses to filter by. Examples: ['[email protected]']. Empty if not filtering by Recipient. */recipients?: string[];/** Email sender addresses to filter by. Examples: ['[email protected]']. Empty to search all senders. */diff --git a/js/app/packages/service-clients/service-storage/generated/schemas/emailFiltersImportance.ts b/js/app/packages/service-clients/service-storage/generated/schemas/emailFiltersImportance.tsnew file mode 100644index 0000000000..7e3f74df99--- /dev/null+++ b/js/app/packages/service-clients/service-storage/generated/schemas/emailFiltersImportance.ts@@ -0,0 +1,11 @@+/**+ * Generated by orval v7.13.0 🍺+ * Do not edit manually.+ * document_storage_service+ * OpenAPI spec version: 0.1.0+ */++/**+ * Filter by email importance. None to ignore, true to pass through (no clause), false to short-circuit and return nothing.+ */+export type EmailFiltersImportance = boolean | null;diff --git a/js/app/packages/service-clients/service-storage/generated/schemas/index.ts b/js/app/packages/service-clients/service-storage/generated/schemas/index.tsindex 43b8f1d236..36d47edaf2 100644--- a/js/app/packages/service-clients/service-storage/generated/schemas/index.ts+++ b/js/app/packages/service-clients/service-storage/generated/schemas/index.ts@@ -55,6 +55,7 @@ export * from './basicDocumentType';export * from './bomPart';export * from './channel';export * from './channelFilters';+export * from './channelFiltersImportance';export * from './channelFiltersOrgId';export * from './channelMessage';export * from './channelMessageDeletedAt';@@ -69,6 +70,7 @@ export * from './channelWithParticipants';export * from './chat';export * from './chatDeletedAt';export * from './chatFilters';+export * from './chatFiltersImportance';export * from './chatModel';export * from './chatProjectId';export * from './chatTokenCount';@@ -154,6 +156,7 @@ export * from './deleteUnthreadedPdfAnchorRequest';export * from './deleteUnthreadedPdfAnchorRequestOneOf';export * from './deleteUnthreadedPdfAnchorRequestOneOfAnchorType';export * from './documentFilters';+export * from './documentFiltersImportance';export * from './documentMetadata';export * from './documentMetadataBranchedFromId';export * from './documentMetadataBranchedFromVersionId';@@ -230,6 +233,7 @@ export * from './editPdfPlaceableCommentAnchorRequestWidthPct';export * from './editPdfPlaceableCommentAnchorRequestXPct';export * from './editPdfPlaceableCommentAnchorRequestYPct';export * from './emailFilters';+export * from './emailFiltersImportance';export * from './emptyResponse';export * from './entityFilters';export * from './entityReference';@@ -368,6 +372,7 @@ export * from './projectDeletedAt';export * from './projectDeleteResponseData';export * from './projectDocumentStatus';export * from './projectFilters';+export * from './projectFiltersImportance';export * from './projectParentId';export * from './projectPreview';export * from './projectPreviewData';diff --git a/js/app/packages/service-clients/service-storage/generated/schemas/projectFilters.ts b/js/app/packages/service-clients/service-storage/generated/schemas/projectFilters.tsindex fb887ddbb4..373c05d08f 100644--- a/js/app/packages/service-clients/service-storage/generated/schemas/projectFilters.ts+++ b/js/app/packages/service-clients/service-storage/generated/schemas/projectFilters.ts@@ -4,11 +4,14 @@* document_storage_service* OpenAPI spec version: 0.1.0*/+import type { ProjectFiltersImportance } from './projectFiltersImportance';/*** The project filters used to filter down what projects you search over.*/export interface ProjectFilters {+ /** Filter by project importance. None to ignore, true to pass through (no clause), false to short-circuit and return nothing. */+ importance?: ProjectFiltersImportance;/** Filter by project owner. Examples: ['macro|[email protected]'], ['macro|[email protected]', 'macro|[email protected]']. Empty to search all owners. */owners?: string[];/** Project IDs to search within. Examples: ['project1']. Empty to search all accessible projects. */diff --git a/js/app/packages/service-clients/service-storage/generated/schemas/projectFiltersImportance.ts b/js/app/packages/service-clients/service-storage/generated/schemas/projectFiltersImportance.tsnew file mode 100644index 0000000000..4442f9ccc6--- /dev/null+++ b/js/app/packages/service-clients/service-storage/generated/schemas/projectFiltersImportance.ts@@ -0,0 +1,11 @@+/**+ * Generated by orval v7.13.0 🍺+ * Do not edit manually.+ * document_storage_service+ * OpenAPI spec version: 0.1.0+ */++/**+ * Filter by project importance. None to ignore, true to pass through (no clause), false to short-circuit and return nothing.+ */+export type ProjectFiltersImportance = boolean | null;diff --git a/js/app/packages/service-clients/service-storage/generated/zod.ts b/js/app/packages/service-clients/service-storage/generated/zod.tsindex 54b741e025..51cba70cf5 100644--- a/js/app/packages/service-clients/service-storage/generated/zod.ts+++ b/js/app/packages/service-clients/service-storage/generated/zod.ts@@ -3538,6 +3538,12 @@ export const postItemsSoupBody = zod.describe("Channel IDs to search within. Examples: ['general']. Empty to search all accessible channels."),+ importance: zod+ .boolean()+ .nullish()+ .describe(+ 'Filter by channel importance. None to ignore, true to pass through (no clause), false to short-circuit and return nothing.'+ ),mentions: zod.array(zod.string()).optional()@@ -3575,6 +3581,12 @@ export const postItemsSoupBody = zod.describe("Chat ids to search over. Examples: ['chat1'], ['chat1', 'chat2']. When provided, chat search will only match results on these chats. Empty to search all accessible chats."),+ importance: zod+ .boolean()+ .nullish()+ .describe(+ 'Filter by chat importance. None to ignore, true to pass through (no clause), false to short-circuit and return nothing.'+ ),owners: zod.array(zod.string()).optional()@@ -3612,6 +3624,12 @@ export const postItemsSoupBody = zod.describe("Document file types to search. Examples: ['pdf'], ['md', 'txt']. Empty to search all file types."),+ importance: zod+ .boolean()+ .nullish()+ .describe(+ 'Filter by document importance. None to ignore, true to pass through (no clause), false to short-circuit and return nothing.'+ ),owners: zod.array(zod.string()).optional()@@ -3643,6 +3661,12 @@ export const postItemsSoupBody = zod.describe("Email CC addresses to filter by. Examples: ['[email protected]']. Empty if not filtering by CC."),+ importance: zod+ .boolean()+ .nullish()+ .describe(+ 'Filter by email importance. None to ignore, true to pass through (no clause), false to short-circuit and return nothing.'+ ),recipients: zod.array(zod.string()).optional()@@ -3662,6 +3686,12 @@ export const postItemsSoupBody = zod),project_filters: zod.object({+ importance: zod+ .boolean()+ .nullish()+ .describe(+ 'Filter by project importance. None to ignore, true to pass through (no clause), false to short-circuit and return nothing.'+ ),owners: zod.array(zod.string()).optional()diff --git a/js/app/packages/service-clients/service-storage/openapi.json b/js/app/packages/service-clients/service-storage/openapi.jsonindex 4f86b4c37e..82f49d29bd 100644--- a/js/app/packages/service-clients/service-storage/openapi.json+++ b/js/app/packages/service-clients/service-storage/openapi.json@@ -4641,6 +4641,10 @@},"description": "Channel IDs to search within. Examples: ['general']. Empty to search all accessible channels."},+ "importance": {+ "type": ["boolean", "null"],+ "description": "Filter by channel importance. None to ignore, true to pass through (no clause), false to short-circuit and return nothing."+ },"mentions": {"type": "array","items": {@@ -4840,6 +4844,10 @@},"description": "Chat ids to search over. Examples: ['chat1'], ['chat1', 'chat2']. When provided, chat search will only match results on these chats. Empty to search all accessible chats."},+ "importance": {+ "type": ["boolean", "null"],+ "description": "Filter by chat importance. None to ignore, true to pass through (no clause), false to short-circuit and return nothing."+ },"owners": {"type": "array","items": {@@ -5445,6 +5453,10 @@},"description": "Document file types to search. Examples: ['pdf'], ['md', 'txt']. Empty to search all file types."},+ "importance": {+ "type": ["boolean", "null"],+ "description": "Filter by document importance. None to ignore, true to pass through (no clause), false to short-circuit and return nothing."+ },"owners": {"type": "array","items": {@@ -6023,6 +6035,10 @@},"description": "Email CC addresses to filter by. Examples: ['[email protected]']. Empty if not filtering by CC."},+ "importance": {+ "type": ["boolean", "null"],+ "description": "Filter by email importance. None to ignore, true to pass through (no clause), false to short-circuit and return nothing."+ },"recipients": {"type": "array","items": {@@ -7570,6 +7586,10 @@"type": "object","description": "The project filters used to filter down what projects you search over.","properties": {+ "importance": {+ "type": ["boolean", "null"],+ "description": "Filter by project importance. None to ignore, true to pass through (no clause), false to short-circuit and return nothing."+ },"owners": {"type": "array","items": {diff --git a/rust/cloud-storage/comms/src/outbound/postgres/comms_repo/dynamic.rs b/rust/cloud-storage/comms/src/outbound/postgres/comms_repo/dynamic.rsindex 11c80390f0..c4d633abfb 100644--- a/rust/cloud-storage/comms/src/outbound/postgres/comms_repo/dynamic.rs+++ b/rust/cloud-storage/comms/src/outbound/postgres/comms_repo/dynamic.rs@@ -97,6 +97,9 @@ fn build_channel_filter(ast: Option<&Expr<ChannelLiteral>>) -> String {filter_ast::ExprFrame::Literal(ChannelLiteral::ThreadId(_)) => String::new(),filter_ast::ExprFrame::Literal(ChannelLiteral::Mention(_)) => String::new(),filter_ast::ExprFrame::Literal(ChannelLiteral::Sender(_)) => String::new(),+ filter_ast::ExprFrame::Literal(ChannelLiteral::Importance(true)) => String::new(),+ // all channels are important, so if importance is false, exclude them+ filter_ast::ExprFrame::Literal(ChannelLiteral::Importance(false)) => "1=0".to_string(),});if formatting.is_empty() {String::new()diff --git a/rust/cloud-storage/comms/src/outbound/postgres/comms_repo/dynamic/tests.rs b/rust/cloud-storage/comms/src/outbound/postgres/comms_repo/dynamic/tests.rsindex 662bf5375e..dbd5ba5f18 100644--- a/rust/cloud-storage/comms/src/outbound/postgres/comms_repo/dynamic/tests.rs+++ b/rust/cloud-storage/comms/src/outbound/postgres/comms_repo/dynamic/tests.rs@@ -166,6 +166,72 @@ async fn test_get_user_channels_dynamic_mixed_supported_and_unsupported_filters();}+// Test filtering channels by importance+// importance=true is a no-op (returns all channels)+// importance=false short-circuits to match nothing (1=0)+#[sqlx::test(+ migrator = "MACRO_DB_MIGRATIONS",+ fixtures(path = "../../../fixtures", scripts("channels"))+)]+async fn test_get_user_channels_dynamic_filter_by_importance(pool: Pool<sqlx::Postgres>) {+ use filter_ast::ExpandFrame;+ use item_filters::ChannelFilters;++ let user_id = MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap();++ // importance=true: no-op, should return all channels+ {+ let channel_filters = ChannelFilters {+ importance: Some(true),+ ..Default::default()+ };++ let filter_ast = ChannelFilters::expand_ast(channel_filters)+ .unwrap()+ .map(std::sync::Arc::new);++ let params = GetChannelsRequest {+ macro_id: user_id.clone(),+ limit: Some(20),+ query: Query::Sort(SimpleSortMethod::UpdatedAt, filter_ast),+ }+ .into_params();++ let channels = get_user_channels_dynamic(&pool, ¶ms).await.unwrap();+ assert_eq!(+ channels.len(),+ 4,+ "importance=true should return all 4 channels"+ );+ }++ // importance=false: 1=0, should return no channels+ {+ let channel_filters = ChannelFilters {+ importance: Some(false),+ ..Default::default()+ };++ let filter_ast = ChannelFilters::expand_ast(channel_filters)+ .unwrap()+ .map(std::sync::Arc::new);++ let params = GetChannelsRequest {+ macro_id: user_id.into_owned(),+ limit: Some(20),+ query: Query::Sort(SimpleSortMethod::UpdatedAt, filter_ast),+ }+ .into_params();++ let channels = get_user_channels_dynamic(&pool, ¶ms).await.unwrap();+ assert_eq!(+ channels.len(),+ 0,+ "importance=false should return no channels"+ );+ }+}+#[sqlx::test(migrator = "MACRO_DB_MIGRATIONS",fixtures(path = "../../../fixtures", scripts("channels"))diff --git a/rust/cloud-storage/email/fixtures/email_dynamic_query.sql b/rust/cloud-storage/email/fixtures/email_dynamic_query.sqlindex 302edb0dc3..9ec08a1170 100644--- a/rust/cloud-storage/email/fixtures/email_dynamic_query.sql+++ b/rust/cloud-storage/email/fixtures/email_dynamic_query.sql@@ -23,7 +23,11 @@ VALUES('10000004-0000-0000-0000-000000000004', 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'STARRED', 'STARRED', 'Show', 'LabelShow', 'System', NOW()),('10000005-0000-0000-0000-000000000005', 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'DRAFT', 'DRAFT', 'Show', 'LabelShow', 'System', NOW()),('10000006-0000-0000-0000-000000000006', 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'TRASH', 'TRASH', 'Hide', 'LabelHide', 'System', NOW()),- ('10000007-0000-0000-0000-000000000007', 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'Label_Work', 'Work', 'Show', 'LabelShow', 'User', NOW());+ ('10000007-0000-0000-0000-000000000007', 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'Label_Work', 'Work', 'Show', 'LabelShow', 'User', NOW()),+ -- Category labels for importance testing+ ('10000008-0000-0000-0000-000000000008', 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'CATEGORY_PERSONAL', 'CATEGORY_PERSONAL', 'Show', 'LabelShow', 'System', NOW()),+ ('10000009-0000-0000-0000-000000000009', 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'CATEGORY_UPDATES', 'CATEGORY_UPDATES', 'Show', 'LabelShow', 'System', NOW()),+ ('10000010-0000-0000-0000-000000000010', 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'CATEGORY_PROMOTIONS', 'CATEGORY_PROMOTIONS', 'Show', 'LabelShow', 'System', NOW());-- Insert test threadsINSERT INTO email_threads (@@ -159,4 +163,12 @@ VALUES('30000006-0000-0000-0000-000000000006', '10000007-0000-0000-0000-000000000007'),-- Message 7: INBOX- ('30000007-0000-0000-0000-000000000007', '10000001-0000-0000-0000-000000000001');+ ('30000007-0000-0000-0000-000000000007', '10000001-0000-0000-0000-000000000001'),++ -- Importance labels:+ -- Message 1 (thread 1): CATEGORY_PERSONAL (priority label → important)+ ('30000001-0000-0000-0000-000000000001', '10000008-0000-0000-0000-000000000008'),+ -- Message 6 (thread 6): CATEGORY_UPDATES (depriority label, no priority → NOT important)+ ('30000006-0000-0000-0000-000000000006', '10000009-0000-0000-0000-000000000009'),+ -- Message 7 (thread 7): CATEGORY_PROMOTIONS (depriority label, no priority → NOT important)+ ('30000007-0000-0000-0000-000000000007', '10000010-0000-0000-0000-000000000010');diff --git a/rust/cloud-storage/email/src/outbound/email_pg_repo/dynamic.rs b/rust/cloud-storage/email/src/outbound/email_pg_repo/dynamic.rsindex b663332f15..a840f0deca 100644--- a/rust/cloud-storage/email/src/outbound/email_pg_repo/dynamic.rs+++ b/rust/cloud-storage/email/src/outbound/email_pg_repo/dynamic.rs@@ -109,6 +109,42 @@ fn build_email_filter(ast: &Expr<EmailLiteral>) -> String {escape_like_pattern(&s)),},+ filter_ast::ExprFrame::Literal(EmailLiteral::Importance(true)) => {+ // Signal: has a priority label OR does not have a depriority label+ r#"(+ EXISTS (+ SELECT 1 FROM email_message_labels ml+ JOIN email_labels l ON ml.label_id = l.id+ WHERE ml.message_id = m.id+ AND l.name IN ('CATEGORY_PERSONAL', 'SENT')+ )+ OR NOT EXISTS (+ SELECT 1 FROM email_message_labels ml+ JOIN email_labels l ON ml.label_id = l.id+ WHERE ml.message_id = m.id+ AND l.name IN ('CATEGORY_UPDATES', 'CATEGORY_PROMOTIONS', 'CATEGORY_SOCIAL', 'CATEGORY_FORUMS')+ )+ )"#+ .to_string()+ }+ filter_ast::ExprFrame::Literal(EmailLiteral::Importance(false)) => {+ // Opposite of Importance(true)+ r#"(+ NOT EXISTS (+ SELECT 1 FROM email_message_labels ml+ JOIN email_labels l ON ml.label_id = l.id+ WHERE ml.message_id = m.id+ AND l.name IN ('CATEGORY_PERSONAL', 'SENT')+ )+ AND EXISTS (+ SELECT 1 FROM email_message_labels ml+ JOIN email_labels l ON ml.label_id = l.id+ WHERE ml.message_id = m.id+ AND l.name IN ('CATEGORY_UPDATES', 'CATEGORY_PROMOTIONS', 'CATEGORY_SOCIAL', 'CATEGORY_FORUMS')+ )+ )"#+ .to_string()+ }});if formatting.is_empty() {diff --git a/rust/cloud-storage/email/src/outbound/email_pg_repo/test.rs b/rust/cloud-storage/email/src/outbound/email_pg_repo/test.rsindex 14ccb6895d..19be571656 100644--- a/rust/cloud-storage/email/src/outbound/email_pg_repo/test.rs+++ b/rust/cloud-storage/email/src/outbound/email_pg_repo/test.rs@@ -624,6 +624,105 @@ async fn test_dynamic_query_pagination(pool: Pool<Postgres>) -> anyhow::Result<(Ok(())}+// Test filtering emails by importance+// The fixture has:+// Thread 1 (msg 1): INBOX + CATEGORY_PERSONAL → important (has priority label)+// Thread 2 (msg 2): SENT → important (has priority label)+// Thread 3 (msg 3): DRAFT → important (no depriority label)+// Thread 4 (msg 4): STARRED + INBOX → important (no depriority label)+// Thread 5 (msg 5): IMPORTANT + INBOX → important (no depriority label)+// Thread 6 (msg 6): Work + CATEGORY_UPDATES → NOT important (depriority, no priority)+// Thread 7 (msg 7): INBOX + CATEGORY_PROMOTIONS → NOT important (depriority, no priority)+#[sqlx::test(+ migrator = "MACRO_DB_MIGRATIONS",+ fixtures(path = "../../../fixtures", scripts("email_dynamic_query"))+)]+async fn test_dynamic_query_with_importance_filter(pool: Pool<Postgres>) -> anyhow::Result<()> {+ let link_id = Uuid::parse_str("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa")?;+ let view = PreviewView::StandardLabel(PreviewViewStandardLabel::All);+ let limit = 50;++ // importance=true: threads with priority labels OR without depriority labels+ {+ let filter = Arc::new(Expr::Literal(EmailLiteral::Importance(true)));+ let query = Query::new(None, SimpleSortMethod::UpdatedAt, filter);++ let results =+ dynamic::dynamic_email_thread_cursor(&pool, &link_id, limit, &view, query).await?;++ // Threads 1 (CATEGORY_PERSONAL), 2 (SENT), 3 (no depriority), 4 (no depriority), 5 (no depriority)+ assert_eq!(+ results.len(),+ 5,+ "importance=true should return 5 important threads"+ );++ let result_ids: std::collections::HashSet<String> =+ results.iter().map(|r| r.id.to_string()).collect();++ assert!(+ result_ids.contains("20000001-0000-0000-0000-000000000001"),+ "Should include thread 1 (CATEGORY_PERSONAL)"+ );+ assert!(+ result_ids.contains("20000002-0000-0000-0000-000000000002"),+ "Should include thread 2 (SENT)"+ );+ assert!(+ result_ids.contains("20000003-0000-0000-0000-000000000003"),+ "Should include thread 3 (no depriority)"+ );+ assert!(+ result_ids.contains("20000004-0000-0000-0000-000000000004"),+ "Should include thread 4 (no depriority)"+ );+ assert!(+ result_ids.contains("20000005-0000-0000-0000-000000000005"),+ "Should include thread 5 (no depriority)"+ );++ // Threads 6 and 7 should be excluded (depriority labels, no priority)+ assert!(+ !result_ids.contains("20000006-0000-0000-0000-000000000006"),+ "Should exclude thread 6 (CATEGORY_UPDATES)"+ );+ assert!(+ !result_ids.contains("20000007-0000-0000-0000-000000000007"),+ "Should exclude thread 7 (CATEGORY_PROMOTIONS)"+ );+ }++ // importance=false: threads with depriority labels AND without priority labels+ {+ let filter = Arc::new(Expr::Literal(EmailLiteral::Importance(false)));+ let query = Query::new(None, SimpleSortMethod::UpdatedAt, filter);++ let results =+ dynamic::dynamic_email_thread_cursor(&pool, &link_id, limit, &view, query).await?;++ // Threads 6 (CATEGORY_UPDATES) and 7 (CATEGORY_PROMOTIONS)+ assert_eq!(+ results.len(),+ 2,+ "importance=false should return 2 unimportant threads"+ );++ let result_ids: std::collections::HashSet<String> =+ results.iter().map(|r| r.id.to_string()).collect();++ assert!(+ result_ids.contains("20000006-0000-0000-0000-000000000006"),+ "Should include thread 6 (CATEGORY_UPDATES)"+ );+ assert!(+ result_ids.contains("20000007-0000-0000-0000-000000000007"),+ "Should include thread 7 (CATEGORY_PROMOTIONS)"+ );+ }++ Ok(())+}+#[sqlx::test(migrator = "MACRO_DB_MIGRATIONS",fixtures(path = "../../../fixtures", scripts("email_thread_metadata"))diff --git a/rust/cloud-storage/frecency/src/outbound/postgres/dynamic.rs b/rust/cloud-storage/frecency/src/outbound/postgres/dynamic.rsindex 523c7fb1b9..62ef4cf5cb 100644--- a/rust/cloud-storage/frecency/src/outbound/postgres/dynamic.rs+++ b/rust/cloud-storage/frecency/src/outbound/postgres/dynamic.rs@@ -77,6 +77,26 @@ fn build_document_filter(ast: Option<&Expr<DocumentLiteral>>) -> String {filter_ast::ExprFrame::Literal(DocumentLiteral::Owner(o)) => {format!(r#"entity_id IN (SELECT id FROM "Document" WHERE owner = '{o}' AND "deletedAt" IS NULL)"#)}+ filter_ast::ExprFrame::Literal(DocumentLiteral::Importance(true)) => {+ // "Important" documents: non-tasks OR tasks where user is an assignee+ r#"(+ dt.sub_type IS NULL+ OR dt.sub_type != 'task'+ OR ep_assignees.values->'value' @> jsonb_build_array(jsonb_build_object('entity_id', $1))+ )"#+ .to_string()+ }+ // filter_ast::ExprFrame::Literal(DocumentLiteral::Importance(false)) => String::new()+ filter_ast::ExprFrame::Literal(DocumentLiteral::Importance(false)) => {+ // "Unimportant" documents: tasks where user is NOT an assignee+ r#"(+ dt.sub_type = 'task'+ -- special null handling for jsonb column+ AND (ep_assignees.values = 'null'+ OR NOT ep_assignees.values->'value' @> jsonb_build_array(jsonb_build_object('entity_id', $1)))+ )"#+ .to_string()+ }});if formatting.is_empty() {String::new()@@ -121,6 +141,9 @@ fn build_chat_filter(ast: Option<&Expr<ChatLiteral>>) -> String {filter_ast::ExprFrame::Literal(ChatLiteral::Owner(o)) => {format!(r#"entity_id IN (SELECT id FROM "Chat" WHERE "userId" = '{o}' AND "deletedAt" IS NULL)"#)}+ // all chats are important, so if importance is false, exclude them+ filter_ast::ExprFrame::Literal(ChatLiteral::Importance(true)) => String::new(),+ filter_ast::ExprFrame::Literal(ChatLiteral::Importance(false)) => "1=0".to_string(),});if formatting.is_empty() {String::new()@@ -143,6 +166,9 @@ fn build_project_filter(ast: Option<&Expr<ProjectLiteral>>) -> String {filter_ast::ExprFrame::Literal(ProjectLiteral::Owner(o)) => {format!(r#"entity_id IN (SELECT id FROM "Project" WHERE "userId" = '{o}' AND "deletedAt" IS NULL)"#)}+ filter_ast::ExprFrame::Literal(ProjectLiteral::Importance(true)) => String::new(),+ // all projects are important, so if importance is false, exclude them+ filter_ast::ExprFrame::Literal(ProjectLiteral::Importance(false)) => "1=0".to_string(),});if formatting.is_empty() {String::new()diff --git a/rust/cloud-storage/item_filters/src/ast/channel.rs b/rust/cloud-storage/item_filters/src/ast/channel.rsindex a59139c7dd..6f7b7b4530 100644--- a/rust/cloud-storage/item_filters/src/ast/channel.rs+++ b/rust/cloud-storage/item_filters/src/ast/channel.rs@@ -18,6 +18,8 @@ pub enum ChannelLiteral {ChannelId(Uuid),/// the message comes from some sender xSender(MacroUserIdStr<'static>),+ /// this node value filters by channel importance. false short-circuits to match nothing.+ Importance(bool),}impl ExpandFrame<ChannelLiteral> for ChannelFilters {@@ -32,6 +34,7 @@ impl ExpandFrame<ChannelLiteral> for ChannelFilters {org_id,channel_ids,sender_ids,+ importance,} = filter_request;let thread_ids = thread_ids@@ -58,10 +61,17 @@ impl ExpandFrame<ChannelLiteral> for ChannelFilters {.map(|s| MacroUserIdStr::parse_from_str(s).map(CowLike::into_owned)).try_expand(|r| r.map(ChannelLiteral::Sender), Expr::or)?;- Ok(- [thread_ids, mentions, organizations, channel_ids, sender_ids]- .into_iter()- .fold_with(Expr::and),- )+ let importance_node = importance.map(|imp| Expr::Literal(ChannelLiteral::Importance(imp)));++ Ok([+ thread_ids,+ mentions,+ organizations,+ channel_ids,+ sender_ids,+ importance_node,+ ]+ .into_iter()+ .fold_with(Expr::and))}}diff --git a/rust/cloud-storage/item_filters/src/ast/chat.rs b/rust/cloud-storage/item_filters/src/ast/chat.rsindex fb1dd03d9f..890dcb30a2 100644--- a/rust/cloud-storage/item_filters/src/ast/chat.rs+++ b/rust/cloud-storage/item_filters/src/ast/chat.rs@@ -19,6 +19,8 @@ pub enum ChatLiteral {ChatId(Uuid),/// the chat is owned by [MacroUserIdStr]Owner(MacroUserIdStr<'static>),+ /// this node value filters by chat importance. false short-circuits to match nothing.+ Importance(bool),}/// the possible roles for a chat@@ -55,6 +57,7 @@ impl ExpandFrame<ChatLiteral> for ChatFilters {chat_ids,project_ids,owners,+ importance,} = filter_request;let project_ids = project_ids@@ -77,7 +80,9 @@ impl ExpandFrame<ChatLiteral> for ChatFilters {.map(|s| MacroUserIdStr::parse_from_str(s).map(CowLike::into_owned)).try_expand(|r| r.map(ChatLiteral::Owner), Expr::or)?;- Ok([project_ids, chat_ids, role, owners]+ let importance_node = importance.map(|imp| Expr::Literal(ChatLiteral::Importance(imp)));++ Ok([project_ids, chat_ids, role, owners, importance_node].into_iter().fold_with(Expr::and))}diff --git a/rust/cloud-storage/item_filters/src/ast/document.rs b/rust/cloud-storage/item_filters/src/ast/document.rsindex b262202170..c1fe7ae8e9 100644--- a/rust/cloud-storage/item_filters/src/ast/document.rs+++ b/rust/cloud-storage/item_filters/src/ast/document.rs@@ -29,6 +29,9 @@ pub enum DocumentLiteral {/// this node value filters by document owner#[serde(rename = "o")]Owner(MacroUserIdStr<'static>),+ /// this node value filters by document importance. false short-circuits to match nothing.+ #[serde(rename = "imp")]+ Importance(bool),}fn prefix(s: &str) -> IResult<&str, &str> {@@ -120,6 +123,7 @@ impl ExpandFrame<DocumentLiteral> for DocumentFilters {document_ids,project_ids,owners,+ importance,} = filter_request;let file_types_node = file_types@@ -142,8 +146,16 @@ impl ExpandFrame<DocumentLiteral> for DocumentFilters {.map(|s| MacroUserIdStr::parse_from_str(s).map(CowLike::into_owned)).try_expand(|r| r.map(DocumentLiteral::Owner), Expr::or)?;- Ok([file_types_node, document_id_nodes, project_ids, owners]- .into_iter()- .fold_with(Expr::and))+ let importance_node = importance.map(|imp| Expr::Literal(DocumentLiteral::Importance(imp)));++ Ok([+ file_types_node,+ document_id_nodes,+ project_ids,+ owners,+ importance_node,+ ]+ .into_iter()+ .fold_with(Expr::and))}}diff --git a/rust/cloud-storage/item_filters/src/ast/email.rs b/rust/cloud-storage/item_filters/src/ast/email.rsindex 7ef9446bdb..94275ae631 100644--- a/rust/cloud-storage/item_filters/src/ast/email.rs+++ b/rust/cloud-storage/item_filters/src/ast/email.rs@@ -24,6 +24,8 @@ pub enum EmailLiteral {Bcc(Email),/// The recipient field of the emailRecipient(Email),+ /// This node value filters by email importance. false short-circuits to match nothing.+ Importance(bool),}impl ExpandFrame<EmailLiteral> for EmailFilters {@@ -34,6 +36,7 @@ impl ExpandFrame<EmailLiteral> for EmailFilters {cc,bcc,recipients,+ importance,} = input;fn map_email(s: String) -> Email {@@ -60,8 +63,16 @@ impl ExpandFrame<EmailLiteral> for EmailFilters {.map(map_email).expand(EmailLiteral::Recipient, Expr::or);- Ok([sender_nodes, cc_nodes, bcc_nodes, recipient_nodes]- .into_iter()- .fold_with(Expr::and))+ let importance_node = importance.map(|imp| Expr::Literal(EmailLiteral::Importance(imp)));++ Ok([+ sender_nodes,+ cc_nodes,+ bcc_nodes,+ recipient_nodes,+ importance_node,+ ]+ .into_iter()+ .fold_with(Expr::and))}}diff --git a/rust/cloud-storage/item_filters/src/ast/project.rs b/rust/cloud-storage/item_filters/src/ast/project.rsindex 7707c2cfe4..56fd675219 100644--- a/rust/cloud-storage/item_filters/src/ast/project.rs+++ b/rust/cloud-storage/item_filters/src/ast/project.rs@@ -12,6 +12,8 @@ pub enum ProjectLiteral {ProjectId(Uuid),/// the owner of the projectOwner(MacroUserIdStr<'static>),+ /// this node value filters by project importance. false short-circuits to match nothing.+ Importance(bool),}impl ExpandFrame<ProjectLiteral> for ProjectFilters {@@ -21,6 +23,7 @@ impl ExpandFrame<ProjectLiteral> for ProjectFilters {let ProjectFilters {project_ids,owners,+ importance,} = input;let project_ids = project_ids@@ -33,6 +36,10 @@ impl ExpandFrame<ProjectLiteral> for ProjectFilters {.map(|s| MacroUserIdStr::parse_from_str(s).map(CowLike::into_owned)).try_expand(|r| r.map(ProjectLiteral::Owner), Expr::or)?;- Ok([project_ids, owners].into_iter().fold_with(Expr::and))+ let importance_node = importance.map(|imp| Expr::Literal(ProjectLiteral::Importance(imp)));++ Ok([project_ids, owners, importance_node]+ .into_iter()+ .fold_with(Expr::and))}}diff --git a/rust/cloud-storage/item_filters/src/ast/tests.rs b/rust/cloud-storage/item_filters/src/ast/tests.rsindex 6fe59365c2..77e914ab24 100644--- a/rust/cloud-storage/item_filters/src/ast/tests.rs+++ b/rust/cloud-storage/item_filters/src/ast/tests.rs@@ -29,6 +29,7 @@ fn it_expands_filters() {document_ids: vec![document_id.to_string()],project_ids: vec![project_id.to_string()],owners: vec!["macro|[email protected]".to_string()],+ importance: Some(true),},..Default::default()};@@ -50,36 +51,45 @@ fn it_expands_filters() {{"&": [{- "|": [+ "&": [{- "l": {- "ft": "pdf",- }+ "|": [+ {+ "l": {+ "ft": "pdf",+ }+ },+ {+ "l": {+ "ft": "txt"+ }+ }+ ]},{"l": {- "ft": "txt"+ "id": document_id}}]},{"l": {- "id": document_id+ "pid": project_id}}]},{"l": {- "pid": project_id+ "o": "macro|[email protected]"}}]},{"l": {- "o": "macro|[email protected]"+ "imp": true}}]@@ -97,6 +107,7 @@ fn it_expands_file_associations() {document_ids: vec![],project_ids: vec![],owners: vec![],+ importance: Some(true),},..Default::default()};@@ -166,6 +177,7 @@ fn it_expands_other_association() {document_ids: vec![],project_ids: vec![],owners: vec![],+ importance: Some(true),},..Default::default()};diff --git a/rust/cloud-storage/item_filters/src/lib.rs b/rust/cloud-storage/item_filters/src/lib.rsindex c23b32b999..20ac547a44 100644--- a/rust/cloud-storage/item_filters/src/lib.rs+++ b/rust/cloud-storage/item_filters/src/lib.rs@@ -42,6 +42,10 @@ pub struct DocumentFilters {/// Filter by document owner. Examples: ['macro|[email protected]'], ['macro|[email protected]', 'macro|[email protected]']. Empty to search all owners.#[serde(default, skip_serializing_if = "Vec::is_empty")]pub owners: Vec<String>,++ /// Filter by document importance. None to ignore, true to pass through (no clause), false to short-circuit and return nothing.+ #[serde(default, skip_serializing_if = "Option::is_none")]+ pub importance: Option<bool>,}impl IsEmpty for DocumentFilters {@@ -51,11 +55,13 @@ impl IsEmpty for DocumentFilters {document_ids,project_ids,owners,+ importance,} = self;file_types.is_empty()&& document_ids.is_empty()&& project_ids.is_empty()&& owners.is_empty()+ && importance.is_none()}}@@ -78,6 +84,10 @@ pub struct ChatFilters {/// Filter by chat owner. Examples: ['macro|[email protected]'], ['macro|[email protected]', 'macro|[email protected]']. Empty to search all owners.#[serde(default, skip_serializing_if = "Vec::is_empty")]pub owners: Vec<String>,++ /// Filter by chat importance. None to ignore, true to pass through (no clause), false to short-circuit and return nothing.+ #[serde(default, skip_serializing_if = "Option::is_none")]+ pub importance: Option<bool>,}impl IsEmpty for ChatFilters {@@ -87,8 +97,13 @@ impl IsEmpty for ChatFilters {chat_ids,project_ids,owners,+ importance,} = self;- role.is_empty() && chat_ids.is_empty() && project_ids.is_empty() && owners.is_empty()+ role.is_empty()+ && chat_ids.is_empty()+ && project_ids.is_empty()+ && owners.is_empty()+ && importance.is_none()}}@@ -108,6 +123,10 @@ pub struct EmailFilters {/// Email Recipient addresses to filter by. Examples: ['[email protected]']. Empty if not filtering by Recipient.#[serde(default, skip_serializing_if = "Vec::is_empty")]pub recipients: Vec<String>,++ /// Filter by email importance. None to ignore, true to pass through (no clause), false to short-circuit and return nothing.+ #[serde(default, skip_serializing_if = "Option::is_none")]+ pub importance: Option<bool>,}impl IsEmpty for EmailFilters {@@ -117,8 +136,13 @@ impl IsEmpty for EmailFilters {cc,bcc,recipients,+ importance,} = self;- senders.is_empty() && cc.is_empty() && bcc.is_empty() && recipients.is_empty()+ senders.is_empty()+ && cc.is_empty()+ && bcc.is_empty()+ && recipients.is_empty()+ && importance.is_none()}}@@ -141,6 +165,10 @@ pub struct ChannelFilters {/// Sender IDs to search within. Examples: ['user1']. Empty to search all accessible senders.#[serde(default, skip_serializing_if = "Vec::is_empty")]pub sender_ids: Vec<String>,++ /// Filter by channel importance. None to ignore, true to pass through (no clause), false to short-circuit and return nothing.+ #[serde(default, skip_serializing_if = "Option::is_none")]+ pub importance: Option<bool>,}impl IsEmpty for ChannelFilters {@@ -151,12 +179,14 @@ impl IsEmpty for ChannelFilters {org_id,channel_ids,sender_ids,+ importance,} = self;thread_ids.is_empty()&& mentions.is_empty()&& org_id.is_none()&& channel_ids.is_empty()&& sender_ids.is_empty()+ && importance.is_none()}}@@ -171,6 +201,10 @@ pub struct ProjectFilters {/// Filter by project owner. Examples: ['macro|[email protected]'], ['macro|[email protected]', 'macro|[email protected]']. Empty to search all owners.#[serde(default, skip_serializing_if = "Vec::is_empty")]pub owners: Vec<String>,++ /// Filter by project importance. None to ignore, true to pass through (no clause), false to short-circuit and return nothing.+ #[serde(default, skip_serializing_if = "Option::is_none")]+ pub importance: Option<bool>,}impl IsEmpty for ProjectFilters {@@ -178,8 +212,9 @@ impl IsEmpty for ProjectFilters {let ProjectFilters {project_ids,owners,+ importance,} = self;- project_ids.is_empty() && owners.is_empty()+ project_ids.is_empty() && owners.is_empty() && importance.is_none()}}diff --git a/rust/cloud-storage/justfile b/rust/cloud-storage/justfileindex 5750d3acc4..2649261d89 100644--- a/rust/cloud-storage/justfile+++ b/rust/cloud-storage/justfile@@ -79,6 +79,8 @@ setup_test_envs:echo "DATABASE_URL={{ MACRODB }}" >> ./name_search/.envecho "DATABASE_URL={{ MACRODB }}" >> ./email_contact_search/.envecho "DATABASE_URL={{ MACRODB }}" >> ./email_scheduled_handler/.env+ echo "DATABASE_URL={{ MACRODB }}" >> ./saved_views/.env+ echo "DATABASE_URL={{ MACRODB }}" >> ./comms_service/.envsetup_macrodb:just macro_db_client/create_dbdiff --git a/rust/cloud-storage/macro_db_client/fixtures/entity_filter_tests.sql b/rust/cloud-storage/macro_db_client/fixtures/entity_filter_tests.sqlindex 8dc1af926b..9501e079a3 100644--- a/rust/cloud-storage/macro_db_client/fixtures/entity_filter_tests.sql+++ b/rust/cloud-storage/macro_db_client/fixtures/entity_filter_tests.sql@@ -97,5 +97,45 @@ VALUES('macro|[email protected]', 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'document', '2024-01-01 00:00:00', '2024-01-08 10:00:00'),('macro|[email protected]', 'a1a1a1a1-a1a1-a1a1-a1a1-a1a1a1a1a1a1', 'chat', '2024-01-01 00:00:00', '2024-01-07 10:00:00');+---------------------------------------------------+-- DOCUMENT SUB TYPES & ASSIGNEES (for importance testing)+---------------------------------------------------++-- Make some documents tasks+INSERT INTO public.document_sub_type ("document_id", "sub_type")+VALUES+ ('aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'task'), -- doc-in-A is a task+ ('bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb', 'task'), -- doc-in-B is a task+ ('cccccccc-cccc-cccc-cccc-cccccccccccc', 'task'); -- doc-in-C is a task+-- doc-in-D and standalone doc are NOT tasks++-- Assignee properties for tasks+INSERT INTO entity_properties (id, entity_id, entity_type, property_definition_id, values)+VALUES+ -- doc-in-A: assigned to user-1 (important to user-1)+ (+ 'a0000001-0000-0000-0000-000000000001',+ 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa',+ 'TASK',+ '00000001-0000-0000-0000-000000000001',+ '{"type": "EntityReference", "value": [{"entity_type": "USER", "entity_id": "macro|[email protected]"}]}'+ ),+ -- doc-in-B: assigned to a different user (NOT important to user-1)+ (+ 'a0000001-0000-0000-0000-000000000002',+ 'bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb',+ 'TASK',+ '00000001-0000-0000-0000-000000000001',+ '{"type": "EntityReference", "value": [{"entity_type": "USER", "entity_id": "macro|[email protected]"}]}'+ ),+ -- doc-in-C: assigned to user-1 (important to user-1)+ (+ 'a0000001-0000-0000-0000-000000000003',+ 'cccccccc-cccc-cccc-cccc-cccccccccccc',+ 'TASK',+ '00000001-0000-0000-0000-000000000001',+ '{"type": "EntityReference", "value": [{"entity_type": "USER", "entity_id": "macro|[email protected]"}]}'+ );+-- Re-enable foreign key constraintsSET session_replication_role = 'origin';diff --git a/rust/cloud-storage/models_search/src/chat/test.rs b/rust/cloud-storage/models_search/src/chat/test.rsindex 6b09c2291f..e5aaaca15d 100644--- a/rust/cloud-storage/models_search/src/chat/test.rs+++ b/rust/cloud-storage/models_search/src/chat/test.rs@@ -12,6 +12,7 @@ fn test_chat_search_request_json_serialization() {chat_ids: vec![],project_ids: vec![],owners: vec![],+ importance: None,}),search_on: SearchOn::Content,collapse: None,@@ -85,6 +86,7 @@ fn test_chat_search_request_round_trip() {chat_ids: vec![],project_ids: vec![],owners: vec![],+ importance: None,}),search_on: SearchOn::Content,collapse: None,diff --git a/rust/cloud-storage/models_search/src/document/test.rs b/rust/cloud-storage/models_search/src/document/test.rsindex 73e5082fc6..085d847110 100644--- a/rust/cloud-storage/models_search/src/document/test.rs+++ b/rust/cloud-storage/models_search/src/document/test.rs@@ -12,6 +12,7 @@ fn test_document_search_request_json_serialization() {document_ids: vec![],project_ids: vec![],owners: vec![],+ importance: None,}),search_on: SearchOn::Content,collapse: None,@@ -85,6 +86,7 @@ fn test_document_search_request_round_trip() {document_ids: vec![],project_ids: vec![],owners: vec![],+ importance: None,}),search_on: SearchOn::Content,collapse: None,diff --git a/rust/cloud-storage/models_search/src/email/test.rs b/rust/cloud-storage/models_search/src/email/test.rsindex 10f36b4747..7722ba8508 100644--- a/rust/cloud-storage/models_search/src/email/test.rs+++ b/rust/cloud-storage/models_search/src/email/test.rs@@ -12,6 +12,7 @@ fn test_email_search_request_json_serialization() {cc: vec!["[email protected]".to_string()],bcc: vec!["[email protected]".to_string()],recipients: vec![],+ importance: None,}),search_on: SearchOn::Content,collapse: None,@@ -96,6 +97,7 @@ fn test_email_search_request_round_trip() {cc: vec![],bcc: vec!["[email protected]".to_string()],recipients: vec![],+ importance: None,}),search_on: SearchOn::Content,collapse: None,diff --git a/rust/cloud-storage/soup/src/outbound/pg_soup_repo/expanded/dynamic.rs b/rust/cloud-storage/soup/src/outbound/pg_soup_repo/expanded/dynamic.rsindex 2140bd9fab..2f784d3b89 100644--- a/rust/cloud-storage/soup/src/outbound/pg_soup_repo/expanded/dynamic.rs+++ b/rust/cloud-storage/soup/src/outbound/pg_soup_repo/expanded/dynamic.rs@@ -108,6 +108,11 @@ static DOCUMENT_CLAUSE: &str = r#"AND ep_status.entity_id = d.idAND ep_status.entity_type = 'TASK'AND ep_status.property_definition_id = $7+ LEFT JOIN entity_properties ep_assignees+ ON dt.sub_type = 'task'+ AND ep_assignees.entity_id = d.id+ AND ep_assignees.entity_type = 'TASK'+ AND ep_assignees.property_definition_id = $8INNER JOIN UserAccessibleItems uai ON uai.item_id = d.id AND uai.item_type = 'document'-- This MUST be a LEFT JOIN to support all three sort methodsLEFT JOIN "UserHistory" uh ON uh."itemId" = d.id AND uh."itemType" = 'document' AND uh."userId" = $1@@ -239,6 +244,26 @@ fn build_document_filter(ast: Option<&Expr<DocumentLiteral>>) -> String {format!(r#"d."projectId" = '{p}'"#)}filter_ast::ExprFrame::Literal(DocumentLiteral::Owner(o)) => format!("d.owner = '{o}'"),+ filter_ast::ExprFrame::Literal(DocumentLiteral::Importance(true)) => {+ // "Important" documents: non-tasks OR tasks where user is an assignee+ r#"(+ dt.sub_type IS NULL+ OR dt.sub_type != 'task'+ OR ep_assignees.values->'value' @> jsonb_build_array(jsonb_build_object('entity_id', $1))+ )"#+ .to_string()+ }+ // filter_ast::ExprFrame::Literal(DocumentLiteral::Importance(false)) => String::new()+ filter_ast::ExprFrame::Literal(DocumentLiteral::Importance(false)) => {+ // "Unimportant" documents: tasks where user is NOT an assignee+ r#"(+ dt.sub_type = 'task'+ -- special null handling for jsonb column+ AND (ep_assignees.values = 'null'+ OR NOT ep_assignees.values->'value' @> jsonb_build_array(jsonb_build_object('entity_id', $1)))+ )"#+ .to_string()+ }});if formatting.is_empty() {String::new()@@ -262,6 +287,9 @@ fn build_chat_filter(ast: Option<&Expr<ChatLiteral>>) -> String {filter_ast::ExprFrame::Literal(ChatLiteral::Role(_r)) => String::new(),filter_ast::ExprFrame::Literal(ChatLiteral::ChatId(i)) => format!("c.id = '{i}'"),filter_ast::ExprFrame::Literal(ChatLiteral::Owner(o)) => format!("c.owner = '{o}'"),+ filter_ast::ExprFrame::Literal(ChatLiteral::Importance(true)) => String::new(),+ // all chats are important, so if importance is false, exclude them+ filter_ast::ExprFrame::Literal(ChatLiteral::Importance(false)) => "1=0".to_string(),});if formatting.is_empty() {String::new()@@ -282,6 +310,9 @@ fn build_project_filter(ast: Option<&Expr<ProjectLiteral>>) -> String {format!(r#"p."parentId" = '{p}'"#)}filter_ast::ExprFrame::Literal(ProjectLiteral::Owner(o)) => format!("p.owner = '{o}'"),+ filter_ast::ExprFrame::Literal(ProjectLiteral::Importance(true)) => String::new(),+ // all projects are important, so if importance is false, exclude them+ filter_ast::ExprFrame::Literal(ProjectLiteral::Importance(false)) => "1=0".to_string(),});if formatting.is_empty() {String::new()@@ -525,6 +556,7 @@ pub(crate) async fn expanded_dynamic_cursor_soup(let (cursor_id, cursor_timestamp) = cursor.vals();let cursor_id_str = cursor_id.as_ref().map(|u| u.to_string());let status_property_id = SystemPropertyKey::STATUS_UUID;+ let assignees_property_id = SystemPropertyKey::ASSIGNEES_UUID;let completed_option_id = StatusOption::COMPLETED_UUID.to_string();let mut items = build_query(cursor.filter(), exclude_frecency)@@ -536,6 +568,7 @@ pub(crate) async fn expanded_dynamic_cursor_soup(.bind(cursor_id_str).bind(completed_option_id).bind(status_property_id)+ .bind(assignees_property_id).try_map(|row| SoupRow::from_row(&row)?.into_soup_item()).fetch_all(db).await?;diff --git a/rust/cloud-storage/soup/src/outbound/pg_soup_repo/expanded/tests.rs b/rust/cloud-storage/soup/src/outbound/pg_soup_repo/expanded/tests.rsindex 4bec972343..e4dcd00c48 100644--- a/rust/cloud-storage/soup/src/outbound/pg_soup_repo/expanded/tests.rs+++ b/rust/cloud-storage/soup/src/outbound/pg_soup_repo/expanded/tests.rs@@ -2104,6 +2104,343 @@ async fn test_dynamic_query_with_ast_and_frecency_exclusion(Ok(())}+// Test filtering documents by importance+// The fixture has:+// doc-in-A: task, assigned to user-1 (important)+// doc-in-B: task, assigned to other-user (NOT important)+// doc-in-C: task, assigned to user-1 (important)+// doc-in-D: not a task (important - non-tasks are always important)+// standalone doc: not a task (important)+#[sqlx::test(+ fixtures(+ path = "../../../../../macro_db_client/fixtures",+ scripts("entity_filter_tests")+ ),+ migrator = "MACRO_DB_MIGRATIONS"+)]+async fn test_filter_documents_by_importance(db: PgPool) -> anyhow::Result<()> {+ use item_filters::{DocumentFilters, EntityFilters};++ let user_id = MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap();++ // importance=true: non-tasks + tasks assigned to user+ {+ let entity_filters = EntityFilters {+ document_filters: DocumentFilters {+ importance: Some(true),+ ..Default::default()+ },+ ..Default::default()+ };++ let filters = EntityFilterAst::new_from_filters(entity_filters)?.unwrap();++ let items = expanded_dynamic_cursor_soup(+ &db,+ ExpandedDynamicCursorArgs {+ user_id: user_id.copied(),+ limit: 20,+ cursor: Query::Sort(SimpleSortMethod::CreatedAt, filters),+ exclude_frecency: false,+ },+ )+ .await?;++ let mut doc_ids: HashSet<Uuid> = HashSet::new();+ let mut chat_count = 0;+ let mut project_count = 0;++ for item in &items {+ match item {+ SoupItem::Document(doc) => {+ doc_ids.insert(doc.id);+ }+ SoupItem::Chat(_) => chat_count += 1,+ SoupItem::Project(_) => project_count += 1,+ _ => unimplemented!("encountered unexpected entity"),+ }+ }++ let expected_ids: HashSet<Uuid> = [+ "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa", // doc-in-A (task, assigned to user)+ "cccccccc-cccc-cccc-cccc-cccccccccccc", // doc-in-C (task, assigned to user)+ "dddddddd-dddd-dddd-dddd-dddddddddddd", // doc-in-D (not a task)+ "eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee", // standalone doc (not a task)+ ]+ .iter()+ .map(|&s| Uuid::parse_str(s).unwrap())+ .collect();++ assert_eq!(+ doc_ids, expected_ids,+ "Should get the correct important documents"+ );+ assert_eq!(chat_count, 4, "Should get all chats");+ assert_eq!(project_count, 4, "Should get all projects");+ }++ // importance=false: only tasks NOT assigned to user+ {+ let entity_filters = EntityFilters {+ document_filters: DocumentFilters {+ importance: Some(false),+ ..Default::default()+ },+ ..Default::default()+ };++ let filters = EntityFilterAst::new_from_filters(entity_filters)?.unwrap();++ let items = expanded_dynamic_cursor_soup(+ &db,+ ExpandedDynamicCursorArgs {+ user_id: user_id.copied(),+ limit: 20,+ cursor: Query::Sort(SimpleSortMethod::CreatedAt, filters),+ exclude_frecency: false,+ },+ )+ .await?;++ let mut doc_ids: HashSet<Uuid> = HashSet::new();+ let mut chat_count = 0;+ let mut project_count = 0;++ for item in &items {+ match item {+ SoupItem::Document(doc) => {+ doc_ids.insert(doc.id);+ }+ SoupItem::Chat(_) => chat_count += 1,+ SoupItem::Project(_) => project_count += 1,+ _ => unimplemented!("encountered unexpected entity"),+ }+ }++ let expected_ids: HashSet<Uuid> = [+ "bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb", // doc-in-B (task, assigned to other user)+ ]+ .iter()+ .map(|&s| Uuid::parse_str(s).unwrap())+ .collect();++ assert_eq!(+ doc_ids, expected_ids,+ "Should get the correct unimportant documents"+ );+ assert_eq!(chat_count, 4, "Should get all chats");+ assert_eq!(project_count, 4, "Should get all projects");+ }++ Ok(())+}++// Test filtering chats by importance+// importance=true is a no-op (returns all chats)+// importance=false short-circuits to match nothing (1=0)+#[sqlx::test(+ fixtures(+ path = "../../../../../macro_db_client/fixtures",+ scripts("entity_filter_tests")+ ),+ migrator = "MACRO_DB_MIGRATIONS"+)]+async fn test_filter_chats_by_importance(db: PgPool) -> anyhow::Result<()> {+ use item_filters::{ChatFilters, EntityFilters};++ let user_id = MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap();++ // importance=true: no-op, should return all chats+ {+ let entity_filters = EntityFilters {+ chat_filters: ChatFilters {+ importance: Some(true),+ ..Default::default()+ },+ ..Default::default()+ };++ let filters = EntityFilterAst::new_from_filters(entity_filters)?.unwrap();++ let items = expanded_dynamic_cursor_soup(+ &db,+ ExpandedDynamicCursorArgs {+ user_id: user_id.copied(),+ limit: 20,+ cursor: Query::Sort(SimpleSortMethod::CreatedAt, filters),+ exclude_frecency: false,+ },+ )+ .await?;++ let mut doc_count = 0;+ let mut chat_count = 0;+ let mut project_count = 0;++ for item in &items {+ match item {+ SoupItem::Document(_) => doc_count += 1,+ SoupItem::Chat(_) => chat_count += 1,+ SoupItem::Project(_) => project_count += 1,+ _ => unimplemented!("encountered unexpected entity"),+ }+ }++ assert_eq!(chat_count, 4, "importance=true should return all chats");+ assert_eq!(doc_count, 5, "Should get all documents");+ assert_eq!(project_count, 4, "Should get all projects");+ }++ // importance=false: 1=0, should return no chats+ {+ let entity_filters = EntityFilters {+ chat_filters: ChatFilters {+ importance: Some(false),+ ..Default::default()+ },+ ..Default::default()+ };++ let filters = EntityFilterAst::new_from_filters(entity_filters)?.unwrap();++ let items = expanded_dynamic_cursor_soup(+ &db,+ ExpandedDynamicCursorArgs {+ user_id: user_id.copied(),+ limit: 20,+ cursor: Query::Sort(SimpleSortMethod::CreatedAt, filters),+ exclude_frecency: false,+ },+ )+ .await?;++ let mut doc_count = 0;+ let mut chat_count = 0;+ let mut project_count = 0;++ for item in &items {+ match item {+ SoupItem::Document(_) => doc_count += 1,+ SoupItem::Chat(_) => chat_count += 1,+ SoupItem::Project(_) => project_count += 1,+ _ => unimplemented!("encountered unexpected entity"),+ }+ }++ assert_eq!(chat_count, 0, "importance=false should return no chats");+ assert_eq!(doc_count, 5, "Should get all documents");+ assert_eq!(project_count, 4, "Should get all projects");+ }++ Ok(())+}++// Test filtering projects by importance+// importance=true is a no-op (returns all projects)+// importance=false short-circuits to match nothing (1=0)+#[sqlx::test(+ fixtures(+ path = "../../../../../macro_db_client/fixtures",+ scripts("entity_filter_tests")+ ),+ migrator = "MACRO_DB_MIGRATIONS"+)]+async fn test_filter_projects_by_importance(db: PgPool) -> anyhow::Result<()> {+ use item_filters::{EntityFilters, ProjectFilters};++ let user_id = MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap();++ // importance=true: no-op, should return all projects+ {+ let entity_filters = EntityFilters {+ project_filters: ProjectFilters {+ importance: Some(true),+ ..Default::default()+ },+ ..Default::default()+ };++ let filters = EntityFilterAst::new_from_filters(entity_filters)?.unwrap();++ let items = expanded_dynamic_cursor_soup(+ &db,+ ExpandedDynamicCursorArgs {+ user_id: user_id.copied(),+ limit: 20,+ cursor: Query::Sort(SimpleSortMethod::CreatedAt, filters),+ exclude_frecency: false,+ },+ )+ .await?;++ let mut doc_count = 0;+ let mut chat_count = 0;+ let mut project_count = 0;++ for item in &items {+ match item {+ SoupItem::Document(_) => doc_count += 1,+ SoupItem::Chat(_) => chat_count += 1,+ SoupItem::Project(_) => project_count += 1,+ _ => unimplemented!("encountered unexpected entity"),+ }+ }++ assert_eq!(+ project_count, 4,+ "importance=true should return all projects"+ );+ assert_eq!(doc_count, 5, "Should get all documents");+ assert_eq!(chat_count, 4, "Should get all chats");+ }++ // importance=false: 1=0, should return no projects+ {+ let entity_filters = EntityFilters {+ project_filters: ProjectFilters {+ importance: Some(false),+ ..Default::default()+ },+ ..Default::default()+ };++ let filters = EntityFilterAst::new_from_filters(entity_filters)?.unwrap();++ let items = expanded_dynamic_cursor_soup(+ &db,+ ExpandedDynamicCursorArgs {+ user_id: user_id.copied(),+ limit: 20,+ cursor: Query::Sort(SimpleSortMethod::CreatedAt, filters),+ exclude_frecency: false,+ },+ )+ .await?;++ let mut doc_count = 0;+ let mut chat_count = 0;+ let mut project_count = 0;++ for item in &items {+ match item {+ SoupItem::Document(_) => doc_count += 1,+ SoupItem::Chat(_) => chat_count += 1,+ SoupItem::Project(_) => project_count += 1,+ _ => unimplemented!("encountered unexpected entity"),+ }+ }++ assert_eq!(+ project_count, 0,+ "importance=false should return no projects"+ );+ assert_eq!(doc_count, 5, "Should get all documents");+ assert_eq!(chat_count, 4, "Should get all chats");+ }++ Ok(())+}+/// Test that system properties are populated on SoupItems (Documents and Projects)#[sqlx::test(migrator = "MACRO_DB_MIGRATIONS",