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: support email label search (#1659)
gbirman7cb45ce7ab2d
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 21460d3f34..1921a990ea 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@@ -17,8 +17,14 @@ export interface EmailFilters {cc?: string[];/** Email thread IDs to filter by. Examples: ['thread-uuid-1']. Empty to search all threads. */email_thread_ids?: string[];+ /** Exclude emails that have any of these labels. Supports both Gmail system labels (e.g. "CATEGORY_PROMOTIONS") and user-created labels. Empty to not exclude any labels.+Note: SPAM and TRASH emails are not indexed in OpenSearch, so they are already excluded by default. */+ exclude_labels?: string[];/** Filter by email importance. None to ignore, true to pass through (no clause), false to short-circuit and return nothing. */importance?: EmailFiltersImportance;+ /** Only include emails that have at least one of these labels. Supports both Gmail system labels (e.g. "INBOX", "CATEGORY_PROMOTIONS") and user-created labels (e.g. "github"). Empty to not filter by included labels.+Note: SPAM and TRASH emails are not indexed in OpenSearch, so they will never appear in results regardless of this filter. */+ include_labels?: string[];/** Filter by email notification state. */notification_filters?: NotificationFilters;/** Email Recipient addresses to filter by. Examples: ['[email protected]']. Empty if not filtering by Recipient. */diff --git a/js/app/packages/service-clients/service-search/openapi.json b/js/app/packages/service-clients/service-search/openapi.jsonindex c0fdbe2b41..7e1b0bb99e 100644--- a/js/app/packages/service-clients/service-search/openapi.json+++ b/js/app/packages/service-clients/service-search/openapi.json@@ -901,10 +901,24 @@},"description": "Email thread IDs to filter by. Examples: ['thread-uuid-1']. Empty to search all threads."},+ "exclude_labels": {+ "type": "array",+ "items": {+ "type": "string"+ },+ "description": "Exclude emails that have any of these labels. Supports both Gmail system labels (e.g. \"CATEGORY_PROMOTIONS\") and user-created labels. Empty to not exclude any labels.\nNote: SPAM and TRASH emails are not indexed in OpenSearch, so they are already excluded by default."+ },"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."},+ "include_labels": {+ "type": "array",+ "items": {+ "type": "string"+ },+ "description": "Only include emails that have at least one of these labels. Supports both Gmail system labels (e.g. \"INBOX\", \"CATEGORY_PROMOTIONS\") and user-created labels (e.g. \"github\"). Empty to not filter by included labels.\nNote: SPAM and TRASH emails are not indexed in OpenSearch, so they will never appear in results regardless of this filter."+ },"notification_filters": {"$ref": "#/components/schemas/NotificationFilters","description": "Filter by email notification state."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 e5c85ad382..44d8390f36 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@@ -17,8 +17,14 @@ export interface EmailFilters {cc?: string[];/** Email thread IDs to filter by. Examples: ['thread-uuid-1']. Empty to search all threads. */email_thread_ids?: string[];+ /** Exclude emails that have any of these labels. Supports both Gmail system labels (e.g. "CATEGORY_PROMOTIONS") and user-created labels. Empty to not exclude any labels.+Note: SPAM and TRASH emails are not indexed in OpenSearch, so they are already excluded by default. */+ exclude_labels?: string[];/** Filter by email importance. None to ignore, true to pass through (no clause), false to short-circuit and return nothing. */importance?: EmailFiltersImportance;+ /** Only include emails that have at least one of these labels. Supports both Gmail system labels (e.g. "INBOX", "CATEGORY_PROMOTIONS") and user-created labels (e.g. "github"). Empty to not filter by included labels.+Note: SPAM and TRASH emails are not indexed in OpenSearch, so they will never appear in results regardless of this filter. */+ include_labels?: string[];/** Filter by email notification state. */notification_filters?: NotificationFilters;/** Email Recipient addresses to filter by. Examples: ['[email protected]']. Empty if not filtering by Recipient. */diff --git a/js/app/packages/service-clients/service-storage/generated/zod.ts b/js/app/packages/service-clients/service-storage/generated/zod.tsindex fb564a3ae6..f4f7b3c8c8 100644--- a/js/app/packages/service-clients/service-storage/generated/zod.ts+++ b/js/app/packages/service-clients/service-storage/generated/zod.ts@@ -4138,12 +4138,24 @@ export const postItemsSoupBody = zod.describe("Email thread IDs to filter by. Examples: ['thread-uuid-1']. Empty to search all threads."),+ exclude_labels: zod+ .array(zod.string())+ .optional()+ .describe(+ 'Exclude emails that have any of these labels. Supports both Gmail system labels (e.g. \"CATEGORY_PROMOTIONS\") and user-created labels. Empty to not exclude any labels.\nNote: SPAM and TRASH emails are not indexed in OpenSearch, so they are already excluded by default.'+ ),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.'),+ include_labels: zod+ .array(zod.string())+ .optional()+ .describe(+ 'Only include emails that have at least one of these labels. Supports both Gmail system labels (e.g. \"INBOX\", \"CATEGORY_PROMOTIONS\") and user-created labels (e.g. \"github\"). Empty to not filter by included labels.\nNote: SPAM and TRASH emails are not indexed in OpenSearch, so they will never appear in results regardless of this filter.'+ ),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 4015bfd177..2363377923 100644--- a/js/app/packages/service-clients/service-storage/openapi.json+++ b/js/app/packages/service-clients/service-storage/openapi.json@@ -6701,10 +6701,24 @@},"description": "Email thread IDs to filter by. Examples: ['thread-uuid-1']. Empty to search all threads."},+ "exclude_labels": {+ "type": "array",+ "items": {+ "type": "string"+ },+ "description": "Exclude emails that have any of these labels. Supports both Gmail system labels (e.g. \"CATEGORY_PROMOTIONS\") and user-created labels. Empty to not exclude any labels.\nNote: SPAM and TRASH emails are not indexed in OpenSearch, so they are already excluded by default."+ },"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."},+ "include_labels": {+ "type": "array",+ "items": {+ "type": "string"+ },+ "description": "Only include emails that have at least one of these labels. Supports both Gmail system labels (e.g. \"INBOX\", \"CATEGORY_PROMOTIONS\") and user-created labels (e.g. \"github\"). Empty to not filter by included labels.\nNote: SPAM and TRASH emails are not indexed in OpenSearch, so they will never appear in results regardless of this filter."+ },"notification_filters": {"$ref": "#/components/schemas/NotificationFilters","description": "Filter by email notification state."diff --git a/rust/cloud-storage/item_filters/src/ast/email.rs b/rust/cloud-storage/item_filters/src/ast/email.rsindex d40cdd8c14..a986dcaf17 100644--- a/rust/cloud-storage/item_filters/src/ast/email.rs+++ b/rust/cloud-storage/item_filters/src/ast/email.rs@@ -46,6 +46,8 @@ impl ExpandFrame<EmailLiteral> for EmailFilters {email_thread_ids,importance,notification_filters,+ include_labels: _,+ exclude_labels: _,} = input;fn map_email(s: String) -> Email {diff --git a/rust/cloud-storage/item_filters/src/lib.rs b/rust/cloud-storage/item_filters/src/lib.rsindex 7b66e52449..445b05ee81 100644--- a/rust/cloud-storage/item_filters/src/lib.rs+++ b/rust/cloud-storage/item_filters/src/lib.rs@@ -192,6 +192,16 @@ pub struct EmailFilters {/// Filter by email notification state.#[serde(default, skip_serializing_if = "NotificationFilters::is_empty")]pub notification_filters: NotificationFilters,++ /// Only include emails that have at least one of these labels. Supports both Gmail system labels (e.g. "INBOX", "CATEGORY_PROMOTIONS") and user-created labels (e.g. "github"). Empty to not filter by included labels.+ /// Note: SPAM and TRASH emails are not indexed in OpenSearch, so they will never appear in results regardless of this filter.+ #[serde(default, skip_serializing_if = "Vec::is_empty")]+ pub include_labels: Vec<String>,++ /// Exclude emails that have any of these labels. Supports both Gmail system labels (e.g. "CATEGORY_PROMOTIONS") and user-created labels. Empty to not exclude any labels.+ /// Note: SPAM and TRASH emails are not indexed in OpenSearch, so they are already excluded by default.+ #[serde(default, skip_serializing_if = "Vec::is_empty")]+ pub exclude_labels: Vec<String>,}impl IsEmpty for EmailFilters {@@ -204,6 +214,8 @@ impl IsEmpty for EmailFilters {email_thread_ids,importance,notification_filters,+ include_labels,+ exclude_labels,} = self;senders.is_empty()&& cc.is_empty()@@ -212,6 +224,8 @@ impl IsEmpty for EmailFilters {&& email_thread_ids.is_empty()&& importance.is_none()&& notification_filters.is_empty()+ && include_labels.is_empty()+ && exclude_labels.is_empty()}}diff --git a/rust/cloud-storage/opensearch_client/src/search/emails.rs b/rust/cloud-storage/opensearch_client/src/search/emails.rsindex 90098cb31a..a9b121060e 100644--- a/rust/cloud-storage/opensearch_client/src/search/emails.rs+++ b/rust/cloud-storage/opensearch_client/src/search/emails.rs@@ -36,6 +36,10 @@ pub(crate) struct EmailQueryBuilder {bcc: Vec<String>,/// The recipients of the email messagerecipients: Vec<String>,+ /// Labels to include (emails must have at least one)+ include_labels: Vec<String>,+ /// Labels to exclude (emails must not have any)+ exclude_labels: Vec<String>,}impl EmailQueryBuilder {@@ -47,6 +51,8 @@ impl EmailQueryBuilder {cc: Vec::new(),bcc: Vec::new(),recipients: Vec::new(),+ include_labels: Vec::new(),+ exclude_labels: Vec::new(),}}@@ -88,6 +94,16 @@ impl EmailQueryBuilder {self}+ pub fn include_labels(mut self, include_labels: Vec<String>) -> Self {+ self.include_labels = include_labels;+ self+ }++ pub fn exclude_labels(mut self, exclude_labels: Vec<String>) -> Self {+ self.exclude_labels = exclude_labels;+ self+ }+pub fn build_bool_query<'a>(&'a self) -> Result<BoolQueryBuilder<'a>> {let mut content_bool_query = self.inner.build_content_bool_query()?;@@ -115,11 +131,18 @@ impl EmailQueryBuilder {}if !self.recipients.is_empty() {- // Create new query for recipientslet recipients_query =should_wildcard_field_query_builder("recipients", &self.recipients);content_bool_query.filter(recipients_query);}++ if !self.include_labels.is_empty() {+ content_bool_query.filter(QueryType::terms("labels", self.include_labels.clone()));+ }++ for label in &self.exclude_labels {+ content_bool_query.must_not(QueryType::term("labels", label.clone()));+ }// END CUSTOM ATTRIBUTES SECTIONOk(content_bool_query)@@ -181,6 +204,8 @@ pub struct EmailSearchArgs {pub cc: Vec<String>,pub bcc: Vec<String>,pub recipients: Vec<String>,+ pub include_labels: Vec<String>,+ pub exclude_labels: Vec<String>,pub page: u32,pub page_size: u32,pub match_type: String,@@ -204,6 +229,8 @@ impl From<EmailSearchArgs> for EmailQueryBuilder {.bcc(args.bcc).search_on(args.search_on).recipients(args.recipients)+ .include_labels(args.include_labels)+ .exclude_labels(args.exclude_labels).collapse(args.collapse).ids_only(args.ids_only).disable_recency(args.disable_recency)diff --git a/rust/cloud-storage/opensearch_client/src/search/unified.rs b/rust/cloud-storage/opensearch_client/src/search/unified.rsindex 922ed01634..585c5cffa6 100644--- a/rust/cloud-storage/opensearch_client/src/search/unified.rs+++ b/rust/cloud-storage/opensearch_client/src/search/unified.rs@@ -87,6 +87,8 @@ impl From<UnifiedSearchArgs> for EmailSearchArgs {cc: args.email_search_args.cc,bcc: args.email_search_args.bcc,recipients: args.email_search_args.recipients,+ include_labels: args.email_search_args.include_labels,+ exclude_labels: args.email_search_args.exclude_labels,}}}@@ -150,6 +152,8 @@ pub struct UnifiedEmailSearchArgs {pub cc: Vec<String>,pub bcc: Vec<String>,pub recipients: Vec<String>,+ pub include_labels: Vec<String>,+ pub exclude_labels: Vec<String>,}#[derive(Debug, Default, Clone)]diff --git a/rust/cloud-storage/opensearch_client/src/search/unified/test.rs b/rust/cloud-storage/opensearch_client/src/search/unified/test.rsindex 6b65cce767..93eb54b33c 100644--- a/rust/cloud-storage/opensearch_client/src/search/unified/test.rs+++ b/rust/cloud-storage/opensearch_client/src/search/unified/test.rs@@ -446,6 +446,7 @@ fn test_build_unified_search_request_content() -> anyhow::Result<()> {cc: vec!["id1".to_string(), "id2".to_string()],bcc: vec!["id1".to_string(), "id2".to_string()],recipients: vec!["id1".to_string(), "id2".to_string()],+ ..Default::default()},channel_message_search_args: UnifiedChannelMessageSearchArgs {channel_ids: vec!["id1".to_string(), "id2".to_string()],@@ -815,6 +816,7 @@ fn test_build_unified_search_request_content() -> anyhow::Result<()> {cc: vec!["id1".to_string(), "id2".to_string()],bcc: vec!["id1".to_string(), "id2".to_string()],recipients: vec!["id1".to_string(), "id2".to_string()],+ ..Default::default()},channel_message_search_args: UnifiedChannelMessageSearchArgs {channel_ids: vec!["id1".to_string(), "id2".to_string()],diff --git a/rust/cloud-storage/search_service/src/api/search/simple/filter.rs b/rust/cloud-storage/search_service/src/api/search/simple/filter.rsindex d2d5d5d3ce..ca051a43b5 100644--- a/rust/cloud-storage/search_service/src/api/search/simple/filter.rs+++ b/rust/cloud-storage/search_service/src/api/search/simple/filter.rs@@ -153,6 +153,8 @@ impl FilterVariantToSearchArgs for item_filters::EmailFilters {cc: self.cc.clone(),bcc: self.bcc.clone(),recipients: self.recipients.clone(),+ include_labels: self.include_labels.clone(),+ exclude_labels: self.exclude_labels.clone(),})}}diff --git a/rust/cloud-storage/search_service/src/api/search/simple/simple_unified.rs b/rust/cloud-storage/search_service/src/api/search/simple/simple_unified.rsindex 319cdd9a8f..3f212088cc 100644--- a/rust/cloud-storage/search_service/src/api/search/simple/simple_unified.rs+++ b/rust/cloud-storage/search_service/src/api/search/simple/simple_unified.rs@@ -403,8 +403,6 @@ pub(in crate::api::search) async fn perform_unified_search(let (project_hits, project_next_cursor) = project_results?;let (content_hits, content_next_cursor) = content_results?;- println!("{:?} {:?}", content_next_cursor, content_hits.len());-// Track original counts before combininglet doc_name_count = doc_hits.len();let chat_name_count = chat_hits.len();