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): Add is_email_attachment document filter (#2006)
Evan Hutnik9d35070d54c6
diff --git a/js/app/packages/app/component/app-sidebar/soup-filter-presets.ts b/js/app/packages/app/component/app-sidebar/soup-filter-presets.tsindex 8f8a128994..c4cf062971 100644--- a/js/app/packages/app/component/app-sidebar/soup-filter-presets.ts+++ b/js/app/packages/app/component/app-sidebar/soup-filter-presets.ts@@ -1,4 +1,7 @@-import { QUERY_FILTERS } from '@app/component/next-soup/filters/query-filters';+import {+ EXCLUDE,+ QUERY_FILTERS,+} from '@app/component/next-soup/filters/query-filters';import type { FilterID } from '@app/component/next-soup/filters/configs';import {applyInboxQueryFilters,@@ -38,20 +41,25 @@ export const VIEW_TAB_PRESETS: Record<ListView, ViewTabConfig> = {tabs: {signal: () => ({queryFilters: {- ...applyInboxQueryFilters({}),+ ...applyInboxQueryFilters({+ document_filters: { is_email_attachment: false },+ }),emailView: 'inbox',},clientFilters: { and: ['signal', 'not-done'] },}),noise: () => ({queryFilters: {- ...applyOtherQueryFilters({}),+ ...applyOtherQueryFilters({+ document_filters: { is_email_attachment: false },+ }),emailView: 'inbox',},clientFilters: { and: ['noise', 'not-done'] },}),all: () => ({queryFilters: {+ document_filters: { is_email_attachment: false },emailView: 'all',},clientFilters: { and: ['explicit-noise'] },@@ -200,6 +208,7 @@ export const VIEW_TAB_PRESETS: Record<ListView, ViewTabConfig> = {...QUERY_FILTERS.file,document_filters: {...QUERY_FILTERS.file.document_filters,+ is_email_attachment: false,owners: [ctx.userId],},project_filters: { owners: [ctx.userId] },@@ -208,9 +217,25 @@ export const VIEW_TAB_PRESETS: Record<ListView, ViewTabConfig> = {};},shared: () => ({- queryFilters: QUERY_FILTERS.file,+ queryFilters: {+ ...QUERY_FILTERS.file,+ document_filters: {+ ...QUERY_FILTERS.file.document_filters,+ is_email_attachment: false,+ },+ },clientFilters: { and: ['file-folder', 'shared-entity'] },}),+ attachments: () => ({+ queryFilters: {+ ...QUERY_FILTERS.file,+ document_filters: {+ is_email_attachment: true,+ },+ project_filters: { project_ids: EXCLUDE },+ },+ clientFilters: { and: ['file-folder'] },+ }),all: () => ({queryFilters: {...QUERY_FILTERS.file,diff --git a/js/app/packages/app/component/next-soup/soup-view/soup-view-tabs.tsx b/js/app/packages/app/component/next-soup/soup-view/soup-view-tabs.tsxindex 40b1608f3d..df905ddda2 100644--- a/js/app/packages/app/component/next-soup/soup-view/soup-view-tabs.tsx+++ b/js/app/packages/app/component/next-soup/soup-view/soup-view-tabs.tsx@@ -314,6 +314,7 @@ const FilesTabs = () => {list={[{ value: 'owned', label: 'Owned' },{ value: 'shared', label: 'Shared' },+ { value: 'attachments', label: 'Attachments' },{ value: 'all', label: 'All' },]}value={activeTab()}diff --git a/js/app/packages/core/constant/servers.ts b/js/app/packages/core/constant/servers.tsindex 584c58c523..8d597238f2 100644--- a/js/app/packages/core/constant/servers.ts+++ b/js/app/packages/core/constant/servers.ts@@ -9,7 +9,7 @@ const serverHostLocal: Servers = {'static-file': 'http://localhost:8100','unfurl-service': 'http://localhost:8095',contacts: 'http://localhost:8083',- 'email-service': 'http://localhost:8094',+ 'email-service': 'http://localhost:8087','image-proxy-service': 'http://localhost:8097',} as const;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 86e5340d1f..063f753b49 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@@ -5,6 +5,7 @@* OpenAPI spec version: 0.1.0*/import type { DocumentFiltersImportance } from './documentFiltersImportance';+import type { DocumentFiltersIsEmailAttachment } from './documentFiltersIsEmailAttachment';import type { NotificationFilters } from './notificationFilters';import type { TaskFilters } from './taskFilters';@@ -18,6 +19,8 @@ export interface DocumentFilters {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 email attachment status. true = only email attachments, false = only non-email attachments, None = both. */+ is_email_attachment?: DocumentFiltersIsEmailAttachment;/** Filter by document notification state. */notification_filters?: NotificationFilters;/** Filter by document owner. Examples: ['macro|[email protected]'], ['macro|[email protected]', 'macro|[email protected]']. Empty to search all owners. */diff --git a/js/app/packages/service-clients/service-search/generated/models/documentFiltersIsEmailAttachment.ts b/js/app/packages/service-clients/service-search/generated/models/documentFiltersIsEmailAttachment.tsnew file mode 100644index 0000000000..8d6d5b1532--- /dev/null+++ b/js/app/packages/service-clients/service-search/generated/models/documentFiltersIsEmailAttachment.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 attachment status. true = only email attachments, false = only non-email attachments, None = both.+ */+export type DocumentFiltersIsEmailAttachment = 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 fc66d471fa..8aad9ac225 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@@ -53,6 +53,7 @@ export * from './chatSearchResponseItemWithMetadataAllOf';export * from './chatSearchResponseItemWithMetadataAllOfMetadata';export * from './documentFilters';export * from './documentFiltersImportance';+export * from './documentFiltersIsEmailAttachment';export * from './documentMetadata';export * from './documentMetadataDeletedAt';export * from './documentMetadataProjectId';diff --git a/js/app/packages/service-clients/service-search/openapi.json b/js/app/packages/service-clients/service-search/openapi.jsonindex 352f0538b5..cbefa936df 100644--- a/js/app/packages/service-clients/service-search/openapi.json+++ b/js/app/packages/service-clients/service-search/openapi.json@@ -647,6 +647,10 @@"type": ["boolean", "null"],"description": "Filter by document importance. None to ignore, true to pass through (no clause), false to short-circuit and return nothing."},+ "is_email_attachment": {+ "type": ["boolean", "null"],+ "description": "Filter by email attachment status. true = only email attachments, false = only non-email attachments, None = both."+ },"notification_filters": {"$ref": "#/components/schemas/NotificationFilters","description": "Filter by document notification state."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 f063ee92e3..8697bc89c9 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@@ -5,6 +5,7 @@* OpenAPI spec version: 0.1.0*/import type { DocumentFiltersImportance } from './documentFiltersImportance';+import type { DocumentFiltersIsEmailAttachment } from './documentFiltersIsEmailAttachment';import type { NotificationFilters } from './notificationFilters';import type { TaskFilters } from './taskFilters';@@ -18,6 +19,8 @@ export interface DocumentFilters {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 email attachment status. true = only email attachments, false = only non-email attachments, None = both. */+ is_email_attachment?: DocumentFiltersIsEmailAttachment;/** Filter by document notification state. */notification_filters?: NotificationFilters;/** Filter by document owner. Examples: ['macro|[email protected]'], ['macro|[email protected]', 'macro|[email protected]']. Empty to search all owners. */diff --git a/js/app/packages/service-clients/service-storage/generated/schemas/documentFiltersIsEmailAttachment.ts b/js/app/packages/service-clients/service-storage/generated/schemas/documentFiltersIsEmailAttachment.tsnew file mode 100644index 0000000000..1b1b262673--- /dev/null+++ b/js/app/packages/service-clients/service-storage/generated/schemas/documentFiltersIsEmailAttachment.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 attachment status. true = only email attachments, false = only non-email attachments, None = both.+ */+export type DocumentFiltersIsEmailAttachment = 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 1c30aad776..f79ac72070 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@@ -182,6 +182,7 @@ export * from './deleteUnthreadedPdfAnchorRequestOneOf';export * from './deleteUnthreadedPdfAnchorRequestOneOfAnchorType';export * from './documentFilters';export * from './documentFiltersImportance';+export * from './documentFiltersIsEmailAttachment';export * from './documentMetadata';export * from './documentMetadataBranchedFromId';export * from './documentMetadataBranchedFromVersionId';diff --git a/js/app/packages/service-clients/service-storage/generated/zod.ts b/js/app/packages/service-clients/service-storage/generated/zod.tsindex 54c7a17799..23737d7576 100644--- a/js/app/packages/service-clients/service-storage/generated/zod.ts+++ b/js/app/packages/service-clients/service-storage/generated/zod.ts@@ -4208,6 +4208,12 @@ export const postItemsSoupBody = zod.describe('Filter by document importance. None to ignore, true to pass through (no clause), false to short-circuit and return nothing.'),+ is_email_attachment: zod+ .boolean()+ .nullish()+ .describe(+ 'Filter by email attachment status. true = only email attachments, false = only non-email attachments, None = both.'+ ),notification_filters: zod.object({done: zoddiff --git a/js/app/packages/service-clients/service-storage/openapi.json b/js/app/packages/service-clients/service-storage/openapi.jsonindex cee4b0c07e..9a530ee3d8 100644--- a/js/app/packages/service-clients/service-storage/openapi.json+++ b/js/app/packages/service-clients/service-storage/openapi.json@@ -6305,6 +6305,10 @@"type": ["boolean", "null"],"description": "Filter by document importance. None to ignore, true to pass through (no clause), false to short-circuit and return nothing."},+ "is_email_attachment": {+ "type": ["boolean", "null"],+ "description": "Filter by email attachment status. true = only email attachments, false = only non-email attachments, None = both."+ },"notification_filters": {"$ref": "#/components/schemas/NotificationFilters","description": "Filter by document notification state."diff --git a/rust/cloud-storage/frecency/src/outbound/postgres/dynamic.rs b/rust/cloud-storage/frecency/src/outbound/postgres/dynamic.rsindex fbe44df3ca..4a1e5f0d7a 100644--- a/rust/cloud-storage/frecency/src/outbound/postgres/dynamic.rs+++ b/rust/cloud-storage/frecency/src/outbound/postgres/dynamic.rs@@ -183,6 +183,14 @@ fn build_document_filter(ast: Option<&Expr<DocumentLiteral>>) -> String {filter_ast::ExprFrame::Literal(DocumentLiteral::SubType(st)) => {format!("dt.sub_type = '{st}'")}+ filter_ast::ExprFrame::Literal(DocumentLiteral::IsEmailAttachment(true)) => {+ r#"EXISTS(SELECT 1 FROM document_email WHERE document_id = fa.entity_id)"#+ .to_string()+ }+ filter_ast::ExprFrame::Literal(DocumentLiteral::IsEmailAttachment(false)) => {+ r#"NOT EXISTS(SELECT 1 FROM document_email WHERE document_id = fa.entity_id)"#+ .to_string()+ }});if formatting.is_empty() {String::new()diff --git a/rust/cloud-storage/item_filters/src/ast/document.rs b/rust/cloud-storage/item_filters/src/ast/document.rsindex 96a990d045..c6be04b464 100644--- a/rust/cloud-storage/item_filters/src/ast/document.rs+++ b/rust/cloud-storage/item_filters/src/ast/document.rs@@ -45,6 +45,9 @@ pub enum DocumentLiteral {/// this node value filters by document sub type#[serde(rename = "dst")]SubType(DocumentSubType),+ /// this node value filters by email attachment status+ #[serde(rename = "iea")]+ IsEmailAttachment(bool),}fn prefix(s: &str) -> IResult<&str, &str> {@@ -149,6 +152,7 @@ impl ExpandFrame<DocumentLiteral> for DocumentFilters {notification_filters,task_filters,sub_types,+ is_email_attachment,} = filter_request;let file_types_node = file_types@@ -185,6 +189,9 @@ impl ExpandFrame<DocumentLiteral> for DocumentFilters {.map(|s| DocumentSubType::from_str(s)).try_expand(|r| r.map(DocumentLiteral::SubType), Expr::or)?;+ let is_email_attachment_node =+ is_email_attachment.map(|v| Expr::Literal(DocumentLiteral::IsEmailAttachment(v)));+let normal_expr = [file_types_node,document_id_nodes,@@ -194,6 +201,7 @@ impl ExpandFrame<DocumentLiteral> for DocumentFilters {notification_done_node,notification_seen_node,sub_types_node,+ is_email_attachment_node,].into_iter().fold_with(Expr::and);diff --git a/rust/cloud-storage/item_filters/src/lib.rs b/rust/cloud-storage/item_filters/src/lib.rsindex fcdbe28187..604b81758f 100644--- a/rust/cloud-storage/item_filters/src/lib.rs+++ b/rust/cloud-storage/item_filters/src/lib.rs@@ -97,6 +97,10 @@ pub struct DocumentFilters {/// Filter by document sub type. Examples: ['task']. Empty to search all sub types.#[serde(default, skip_serializing_if = "Vec::is_empty")]pub sub_types: Vec<String>,++ /// Filter by email attachment status. true = only email attachments, false = only non-email attachments, None = both.+ #[serde(default, skip_serializing_if = "Option::is_none")]+ pub is_email_attachment: Option<bool>,}impl IsEmpty for DocumentFilters {@@ -110,6 +114,7 @@ impl IsEmpty for DocumentFilters {notification_filters,task_filters,sub_types,+ is_email_attachment,} = self;file_types.is_empty()&& document_ids.is_empty()@@ -119,6 +124,7 @@ impl IsEmpty for DocumentFilters {&& notification_filters.is_empty()&& task_filters.is_empty()&& sub_types.is_empty()+ && is_email_attachment.is_none()}}diff --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 487864c3b4..f192d09127 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@@ -139,5 +139,17 @@ VALUES'{"type": "EntityReference", "value": [{"entity_type": "USER", "entity_id": "macro|[email protected]"}]}');+-- Email attachments linked to some documents via document_email+-- doc-in-A and doc-in-B are email attachments; doc-in-C, doc-in-D, standalone, isolated are NOT+INSERT INTO public.email_attachments (id, message_id, filename, mime_type, size_bytes)+VALUES+ ('ea000001-0000-0000-0000-000000000001', 'ea000001-0000-0000-0000-000000000099', 'attachment1.pdf', 'application/pdf', 1024),+ ('ea000001-0000-0000-0000-000000000002', 'ea000001-0000-0000-0000-000000000099', 'attachment2.pdf', 'application/pdf', 2048);++INSERT INTO public.document_email (document_id, email_attachment_id)+VALUES+ ('aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'ea000001-0000-0000-0000-000000000001'),+ ('bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb', 'ea000001-0000-0000-0000-000000000002');+-- Re-enable foreign key constraintsSET session_replication_role = 'origin';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 387d17e95e..bb9ca21e07 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@@ -364,6 +364,14 @@ fn build_document_filter(ast: Option<&Expr<DocumentLiteral>>) -> String {filter_ast::ExprFrame::Literal(DocumentLiteral::SubType(st)) => {format!("dt.sub_type = '{st}'")}+ filter_ast::ExprFrame::Literal(DocumentLiteral::IsEmailAttachment(true)) => {+ r#"EXISTS(SELECT 1 FROM document_email WHERE document_id = d.id)"#+ .to_string()+ }+ filter_ast::ExprFrame::Literal(DocumentLiteral::IsEmailAttachment(false)) => {+ r#"NOT EXISTS(SELECT 1 FROM document_email WHERE document_id = d.id)"#+ .to_string()+ }});if formatting.is_empty() {String::new()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 455ca2a4d0..67904eac53 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@@ -5177,3 +5177,136 @@ async fn test_dyn_filter_by_sub_type_and_file_type(db: PgPool) -> anyhow::ResultOk(())}++// Test filtering documents by is_email_attachment = true (only email attachments)+#[sqlx::test(+ fixtures(+ path = "../../../../../macro_db_client/fixtures",+ scripts("entity_filter_tests")+ ),+ migrator = "MACRO_DB_MIGRATIONS"+)]+async fn test_dyn_filter_is_email_attachment_true(db: PgPool) -> anyhow::Result<()> {+ use item_filters::{DocumentFilters, EntityFilters};++ let user_id = MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap();++ let entity_filters = EntityFilters {+ document_filters: DocumentFilters {+ is_email_attachment: 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 doc_ids: HashSet<Uuid> = items+ .iter()+ .filter_map(|i| match i {+ SoupItem::Document(doc) => Some(doc.id),+ _ => None,+ })+ .collect();++ let expected: HashSet<Uuid> = [+ "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",+ "bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb",+ ]+ .iter()+ .map(|s| Uuid::parse_str(s).unwrap())+ .collect();++ assert_eq!(+ doc_ids, expected,+ "is_email_attachment=true should only return documents linked via document_email"+ );++ // Chats and projects are unaffected by document filters+ let chat_count = items+ .iter()+ .filter(|i| matches!(i, SoupItem::Chat(_)))+ .count();+ let project_count = items+ .iter()+ .filter(|i| matches!(i, SoupItem::Project(_)))+ .count();+ assert!(chat_count > 0, "Should still get chats");+ assert!(project_count > 0, "Should still get projects");++ Ok(())+}++// Test filtering documents by is_email_attachment = false (only non-email attachments)+#[sqlx::test(+ fixtures(+ path = "../../../../../macro_db_client/fixtures",+ scripts("entity_filter_tests")+ ),+ migrator = "MACRO_DB_MIGRATIONS"+)]+async fn test_dyn_filter_is_email_attachment_false(db: PgPool) -> anyhow::Result<()> {+ use item_filters::{DocumentFilters, EntityFilters};++ let user_id = MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap();++ let entity_filters = EntityFilters {+ document_filters: DocumentFilters {+ is_email_attachment: 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 doc_ids: HashSet<Uuid> = items+ .iter()+ .filter_map(|i| match i {+ SoupItem::Document(doc) => Some(doc.id),+ _ => None,+ })+ .collect();++ // doc-in-A and doc-in-B are email attachments, so they should be excluded+ let email_attachment_ids: HashSet<Uuid> = [+ "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",+ "bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb",+ ]+ .iter()+ .map(|s| Uuid::parse_str(s).unwrap())+ .collect();++ assert!(+ doc_ids.is_disjoint(&email_attachment_ids),+ "is_email_attachment=false should exclude documents linked via document_email"+ );+ assert!(+ !doc_ids.is_empty(),+ "Should still return non-email-attachment documents"+ );++ Ok(())+}