Skip to content

armgit / macro

Public Imported from GitHub
0

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

feat(soup): add channels ast literal (#944)

Sean Aye6a9f9fed7ee3
diff --git a/rust/cloud-storage/Cargo.lock b/rust/cloud-storage/Cargo.lock
index a7a1abfefa..71cf23d474 100644
--- a/rust/cloud-storage/Cargo.lock
+++ b/rust/cloud-storage/Cargo.lock
@@ -1837,10 +1837,12 @@ dependencies = [
"chrono",
"doppleganger",
"frecency",
+ "item_filters",
"macro_user_id",
"model-entity",
"model_user",
"models_comms",
+ "models_pagination",
"reqwest",
"rootcause",
"serde",
diff --git a/rust/cloud-storage/comms/Cargo.toml b/rust/cloud-storage/comms/Cargo.toml
index 72678a25be..c8431e1e6c 100644
--- a/rust/cloud-storage/comms/Cargo.toml
+++ b/rust/cloud-storage/comms/Cargo.toml
@@ -14,10 +14,12 @@ axum = { workspace = true, optional = true }
chrono = { workspace = true }
doppleganger = { workspace = true, features = ["chrono", "uuid"] }
frecency = { path = "../frecency", features = ["ports"] }
+item_filters = { path = "../item_filters" }
macro_user_id = { path = "../macro_user_id" }
model-entity = { path = "../model-entity" }
model_user = { path = "../model_user", optional = true, features = ["axum"] }
models_comms = { path = "../models_comms" }
+models_pagination = { path = "../models_pagination" }
reqwest = { workspace = true, optional = true }
rootcause = "0.11"
serde = { workspace = true }
diff --git a/rust/cloud-storage/comms/src/domain/models.rs b/rust/cloud-storage/comms/src/domain/models.rs
index fabc786424..98b85f9987 100644
--- a/rust/cloud-storage/comms/src/domain/models.rs
+++ b/rust/cloud-storage/comms/src/domain/models.rs
@@ -1,5 +1,7 @@
+use item_filters::ast::{LiteralTree, channel::ChannelLiteral};
use macro_user_id::user_id::MacroUserIdStr;
pub use models_comms::*;
+use models_pagination::{Query, SimpleSortMethod};
use serde::Deserialize;
use uuid::Uuid;
@@ -35,3 +37,9 @@ impl UserName {
}
}
}
+
+pub struct GetChannelsRequest {
+ pub macro_id: MacroUserIdStr<'static>,
+ pub limit: Option<u32>,
+ pub query: Query<Uuid, SimpleSortMethod, LiteralTree<ChannelLiteral>>,
+}
diff --git a/rust/cloud-storage/item_filters/src/ast.rs b/rust/cloud-storage/item_filters/src/ast.rs
index 73896ac7fa..2dd0a5390d 100644
--- a/rust/cloud-storage/item_filters/src/ast.rs
+++ b/rust/cloud-storage/item_filters/src/ast.rs
@@ -2,8 +2,9 @@
//! This is used to construct a strictly typed ast for the input filters, allowing consumers to have a logical represenation of the required operations
use crate::{
- ChatFilters, DocumentFilters, EmailFilters, EntityFilters, ProjectFilters,
+ ChannelFilters, ChatFilters, DocumentFilters, EmailFilters, EntityFilters, ProjectFilters,
ast::{
+ channel::ChannelLiteral,
chat::{ChatLiteral, ChatRole},
email::EmailLiteral,
project::ProjectLiteral,
@@ -75,6 +76,9 @@ pub struct EntityFilterAst {
/// the filters that should be applied to the email entity
#[serde(default, rename = "ef")]
pub email_filter: LiteralTree<EmailLiteral>,
+ /// the filters taht should be applied to the channel entity
+ #[serde(default, rename = "chanf")]
+ pub channel_filter: LiteralTree<ChannelLiteral>,
}
impl EntityFilterAst {
@@ -90,6 +94,8 @@ impl EntityFilterAst {
.map(Arc::new),
chat_filter: ChatFilters::expand_ast(entity_filter.chat_filters)?.map(Arc::new),
email_filter: EmailFilters::expand_ast(entity_filter.email_filters)?.map(Arc::new),
+ channel_filter: ChannelFilters::expand_ast(entity_filter.channel_filters)?
+ .map(Arc::new),
}))
}
@@ -101,6 +107,7 @@ impl EntityFilterAst {
project_filter: None,
chat_filter: None,
email_filter: None,
+ channel_filter: None,
}
}
}
@@ -112,10 +119,12 @@ impl IsEmpty for EntityFilterAst {
project_filter,
chat_filter,
email_filter,
+ channel_filter,
} = self;
document_filter.is_none()
&& project_filter.is_none()
&& chat_filter.is_none()
&& email_filter.is_none()
+ && channel_filter.is_none()
}
}
diff --git a/rust/cloud-storage/item_filters/src/ast/channel.rs b/rust/cloud-storage/item_filters/src/ast/channel.rs
index 8b13789179..a59139c7dd 100644
--- a/rust/cloud-storage/item_filters/src/ast/channel.rs
+++ b/rust/cloud-storage/item_filters/src/ast/channel.rs
@@ -1 +1,67 @@
+use filter_ast::{ExpandFrame, Expr, FoldTree, TryExpandNode};
+use macro_user_id::{cowlike::CowLike, user_id::MacroUserIdStr};
+use serde::{Deserialize, Serialize};
+use uuid::Uuid;
+use crate::{ChannelFilters, ast::ExpandErr};
+
+/// the possible literal values in a channel filter ast
+#[derive(Debug, Serialize, Deserialize, Clone)]
+pub enum ChannelLiteral {
+ /// the thread id in which we want to find messages
+ ThreadId(Uuid),
+ /// the message mentions some user x
+ Mention(MacroUserIdStr<'static>),
+ /// the message is in some organization
+ OrganizationId(i64),
+ /// the message is in some channel id
+ ChannelId(Uuid),
+ /// the message comes from some sender x
+ Sender(MacroUserIdStr<'static>),
+}
+
+impl ExpandFrame<ChannelLiteral> for ChannelFilters {
+ type Err = ExpandErr;
+
+ fn expand_ast(
+ filter_request: ChannelFilters,
+ ) -> Result<Option<Expr<ChannelLiteral>>, Self::Err> {
+ let ChannelFilters {
+ thread_ids,
+ mentions,
+ org_id,
+ channel_ids,
+ sender_ids,
+ } = filter_request;
+
+ let thread_ids = thread_ids
+ .iter()
+ .map(|s| Uuid::parse_str(s))
+ .try_expand(|r| r.map(ChannelLiteral::ThreadId), Expr::or)?;
+
+ let mentions = mentions
+ .iter()
+ .map(|s| MacroUserIdStr::parse_from_str(s).map(CowLike::into_owned))
+ .try_expand(|r| r.map(ChannelLiteral::Mention), Expr::or)?;
+
+ let organizations = org_id
+ .into_iter()
+ .expand(ChannelLiteral::OrganizationId, Expr::or);
+
+ let channel_ids = channel_ids
+ .iter()
+ .map(|s| Uuid::parse_str(s))
+ .try_expand(|r| r.map(ChannelLiteral::ChannelId), Expr::or)?;
+
+ let sender_ids = sender_ids
+ .iter()
+ .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),
+ )
+ }
+}