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
Replace AST cursor in soup (#1292)
Sean Ayee2d5de8ac2c8
diff --git a/js/app/CLAUDE.md b/js/app/CLAUDE.mddeleted file mode 120000index 47dc3e3d86..0000000000--- a/js/app/CLAUDE.md+++ /dev/null@@ -1 +0,0 @@-AGENTS.md\ No newline at end of filediff --git a/js/app/CLAUDE.md b/js/app/CLAUDE.mdnew file mode 100644index 0000000000..47dc3e3d86--- /dev/null+++ b/js/app/CLAUDE.md@@ -0,0 +1 @@+AGENTS.md\ No newline at end of filediff --git a/rust/cloud-storage/item_filters/src/lib.rs b/rust/cloud-storage/item_filters/src/lib.rsindex e47ee5ed88..c23b32b999 100644--- a/rust/cloud-storage/item_filters/src/lib.rs+++ b/rust/cloud-storage/item_filters/src/lib.rs@@ -184,7 +184,7 @@ impl IsEmpty for ProjectFilters {}/// a bundle of all of the filters for each entity type-#[derive(Debug, Clone, Default, Deserialize)]+#[derive(Debug, Clone, Default, Deserialize, Serialize)]#[cfg_attr(feature = "schema", derive(utoipa::ToSchema, schemars::JsonSchema))]pub struct EntityFilters {/// the bundled [ProjectFilters]diff --git a/rust/cloud-storage/models_pagination/src/cursor.rs b/rust/cloud-storage/models_pagination/src/cursor.rsindex 16a59fba1c..f4287de39c 100644--- a/rust/cloud-storage/models_pagination/src/cursor.rs+++ b/rust/cloud-storage/models_pagination/src/cursor.rs@@ -46,6 +46,25 @@ pub struct Cursor<Id, C, F> {pub filter: F,}+impl<Id, C, F> Cursor<Id, C, F> {+ /// maps the filter from one type to another+ pub fn map_filter<Fn: FnOnce(F) -> F2, F2>(self, cb: Fn) -> Cursor<Id, C, F2> {+ let Cursor {+ id,+ limit,+ val,+ filter,+ } = self;++ Cursor {+ id,+ limit,+ val,+ filter: cb(filter),+ }+ }+}+/// Type alias for a [Cursor] with a [CursorVal] which is [Sortable]pub type CursorWithVal<Id, V> = Cursor<Id, CursorVal<V>, ()>;@@ -458,6 +477,27 @@ impl<I, T: Sortable, F> Query<I, T, F> {}),}}+ /// maps this filter type into another one via a callback fn.+ /// This is analagous to [Option::map] over just the filter generic type+ pub fn try_map_filter<Cb, F2, E>(self, cb: Cb) -> Result<Query<I, T, F2>, E>+ where+ Cb: FnOnce(F) -> Result<F2, E>,+ {+ match self {+ Query::Sort(a, b) => Ok(Query::Sort(a, cb(b)?)),+ Query::Cursor(Cursor {+ id,+ limit,+ val,+ filter,+ }) => Ok(Query::Cursor(Cursor {+ id,+ limit,+ val,+ filter: cb(filter)?,+ })),+ }+ }/// returns the entity [Uuid] and [Sortable::Value] if they existpub fn vals(&self) -> (Option<&I>, Option<&T::Value>) {diff --git a/rust/cloud-storage/soup/src/domain/models.rs b/rust/cloud-storage/soup/src/domain/models.rsindex 04769a2801..081ae709b4 100644--- a/rust/cloud-storage/soup/src/domain/models.rs+++ b/rust/cloud-storage/soup/src/domain/models.rs@@ -1,7 +1,10 @@use comms::domain::models::GetChannelsRequest;use email::domain::models::{GetEmailsRequest, PreviewView};use frecency::domain::models::{AggregateFrecency, FrecencyQueryErr};-use item_filters::ast::EntityFilterAst;+use item_filters::{+ EntityFilters,+ ast::{EntityFilterAst, ExpandErr},+};use macro_user_id::user_id::MacroUserIdStr;use model_entity::Entity;use models_pagination::{@@ -93,31 +96,112 @@ pub struct AdvancedSortParams<'a> {}#[derive(Debug)]-pub enum SoupQuery {- Simple(Query<Uuid, SimpleSortMethod, Option<EntityFilterAst>>),- Frecency(Query<Uuid, Frecency, Option<EntityFilterAst>>),+pub enum SoupQuery<T> {+ Simple(SimpleQueryInner<T>),+ Frecency(FrecencyQueryInner<T>),}-impl SoupQuery {- pub(crate) fn filter(&self) -> Option<&EntityFilterAst> {+/// the inner private type for [SoupQuery::Simple]+#[derive(Debug)]+pub struct SimpleQueryInner<T>(pub(crate) Query<Uuid, SimpleSortMethod, T>);++/// the inner private type for [SoupQuery::Frecency]+#[derive(Debug)]+pub struct FrecencyQueryInner<T>(pub(crate) Query<Uuid, Frecency, T>);++impl SoupQuery<EntityFilters> {+ /// create a new instance of a [SimpleSortMethod] with [EntityFilters] this is used to+ /// construct the initial page request. To paginate an existing cursor see [Self::new_cursor_simple]+ pub fn new_sort_simple(method: SimpleSortMethod, filters: EntityFilters) -> Self {+ SoupQuery::Simple(SimpleQueryInner(models_pagination::Query::Sort(+ method, filters,+ )))+ }++ /// create a new instance of a [Frecency] with [EntityFilters] this is used to+ /// construct the initial page request. To paginate an existing cursor see [Self::new_cursor_frecency]+ pub fn new_sort_frecency(method: Frecency, filters: EntityFilters) -> Self {+ SoupQuery::Frecency(FrecencyQueryInner(models_pagination::Query::Sort(+ method, filters,+ )))+ }++ /// create a new instance of a [SimpleSortMethod] with an existing cursor on [EntityFilters].+ /// This is used to continue paginating on an existing cursor.+ /// To create a new initial page see [Self::new_sort_simple]+ pub fn new_cursor_simple(+ cursor: CursorWithValAndFilter<Uuid, SimpleSortMethod, EntityFilters>,+ ) -> Self {+ SoupQuery::Simple(SimpleQueryInner(models_pagination::Query::Cursor(cursor)))+ }++ /// create a new instance of a [Frecency] with an existing cursor on [EntityFilters].+ /// This is used to continue paginating on an existing cursor.+ /// To create a new initial page see [Self::new_sort_simple]+ pub fn new_cursor_frecency(+ cursor: CursorWithValAndFilter<Uuid, Frecency, EntityFilters>,+ ) -> Self {+ SoupQuery::Frecency(FrecencyQueryInner(models_pagination::Query::Cursor(cursor)))+ }++ pub fn filter(&self) -> &EntityFilters {match self {- SoupQuery::Simple(query) => query.filter().as_ref(),- SoupQuery::Frecency(query) => query.filter().as_ref(),+ SoupQuery::Simple(SimpleQueryInner(query)) => query.filter(),+ SoupQuery::Frecency(FrecencyQueryInner(query)) => query.filter(),+ }+ }++ pub fn into_ast(self) -> Result<SoupQuery<Option<EntityFilterAst>>, ExpandErr> {+ match self {+ SoupQuery::Simple(SimpleQueryInner(query)) => Ok(SoupQuery::Simple(SimpleQueryInner(+ query.try_map_filter(EntityFilterAst::new_from_filters)?,+ ))),+ SoupQuery::Frecency(FrecencyQueryInner(query)) => Ok(SoupQuery::Frecency(+ FrecencyQueryInner(query.try_map_filter(EntityFilterAst::new_from_filters)?),+ )),}}}#[derive(Debug)]-pub struct SoupRequest {+pub struct SoupRequest<T> {pub soup_type: SoupType,pub limit: u16,- pub cursor: SoupQuery,+ pub cursor: SoupQuery<T>,pub user: MacroUserIdStr<'static>,pub email_preview_view: PreviewView,pub link_id: Option<Uuid>,}-impl SoupRequest {+impl SoupRequest<EntityFilters> {+ /// returns a reference to the filters to pass to the paginator+ /// this is used to prevent passing back the full ast on each server request+ pub(crate) fn filters(&self) -> &EntityFilters {+ self.cursor.filter()+ }++ pub(crate) fn into_ast(self) -> Result<SoupRequest<Option<EntityFilterAst>>, ExpandErr> {+ let SoupRequest {+ soup_type,+ limit,+ cursor,+ user,+ email_preview_view,+ link_id,+ } = self;++ Ok(SoupRequest {+ soup_type,+ limit,+ cursor: cursor.into_ast()?,+ user,+ email_preview_view,+ link_id,+ })+ }+}++impl SoupRequest<Option<EntityFilterAst>> {/// take the parts of the [SoupRequest] that are only relevant to email/// and move them into a [GetEmailsRequest] if it is possible to create onepub(crate) fn build_email_request(&self) -> Option<GetEmailsRequest> {@@ -127,16 +211,16 @@ impl SoupRequest {macro_id: self.user.clone(),limit: Some(self.limit as u32),query: match &self.cursor {- SoupQuery::Simple(Query::Sort(t, f)) => Some(Query::Sort(+ SoupQuery::Simple(SimpleQueryInner(Query::Sort(t, f))) => Some(Query::Sort(*t,f.as_ref().and_then(|f| f.email_filter.clone()),)),- SoupQuery::Simple(Query::Cursor(CursorWithValAndFilter {+ SoupQuery::Simple(SimpleQueryInner(Query::Cursor(CursorWithValAndFilter {id,limit,val,filter,- })) => Some(Query::Cursor(CursorWithValAndFilter {+ }))) => Some(Query::Cursor(CursorWithValAndFilter {id: *id,limit: *limit,val: val.clone(),@@ -153,16 +237,16 @@ impl SoupRequest {macro_id: self.user.clone(),limit: Some(self.limit as u32),query: match &self.cursor {- SoupQuery::Simple(Query::Sort(t, f)) => Some(Query::Sort(+ SoupQuery::Simple(SimpleQueryInner(Query::Sort(t, f))) => Some(Query::Sort(*t,f.as_ref().and_then(|f| f.channel_filter.clone()),)),- SoupQuery::Simple(Query::Cursor(CursorWithValAndFilter {+ SoupQuery::Simple(SimpleQueryInner(Query::Cursor(CursorWithValAndFilter {id,limit,val,filter,- })) => Some(Query::Cursor(CursorWithValAndFilter {+ }))) => Some(Query::Cursor(CursorWithValAndFilter {id: *id,limit: *limit,val: val.clone(),@@ -223,4 +307,6 @@ pub enum SoupErr {EmailErr(#[from] email::domain::models::EmailErr),#[error("A comms error has occured, see logs for more details")]CommsErr,+ #[error(transparent)]+ AstErr(#[from] ExpandErr),}diff --git a/rust/cloud-storage/soup/src/domain/ports.rs b/rust/cloud-storage/soup/src/domain/ports.rsindex 3c80fd8ee3..07b5a855dc 100644--- a/rust/cloud-storage/soup/src/domain/ports.rs+++ b/rust/cloud-storage/soup/src/domain/ports.rs@@ -2,7 +2,7 @@ use crate::domain::models::{AdvancedSortParams, FrecencySoupItem, SimpleSortRequest, SoupErr, SoupRequest,};use either::Either;-use item_filters::ast::EntityFilterAst;+use item_filters::EntityFilters;use models_pagination::{Frecency, PaginatedCursor, SimpleSortMethod};use models_soup::item::SoupItem;@@ -43,13 +43,13 @@ pub trait SoupRepo: Send + Sync + 'static {/// 1. The sort method is [Either] [SimpleSortMethod] or [Frecency]/// 1. The filter type is an [Option] [EntityFilterAst]pub type SoupOutput = Either<- PaginatedCursor<FrecencySoupItem, String, SimpleSortMethod, Option<EntityFilterAst>>,- PaginatedCursor<FrecencySoupItem, String, Frecency, Option<EntityFilterAst>>,+ PaginatedCursor<FrecencySoupItem, String, SimpleSortMethod, EntityFilters>,+ PaginatedCursor<FrecencySoupItem, String, Frecency, EntityFilters>,>;pub trait SoupService: Send + Sync + 'static {fn get_user_soup(&self,- req: SoupRequest,+ req: SoupRequest<EntityFilters>,) -> impl Future<Output = Result<SoupOutput, SoupErr>> + Send;}diff --git a/rust/cloud-storage/soup/src/domain/service.rs b/rust/cloud-storage/soup/src/domain/service.rsindex c6ff1bac63..e6b2463b60 100644--- a/rust/cloud-storage/soup/src/domain/service.rs+++ b/rust/cloud-storage/soup/src/domain/service.rs@@ -1,7 +1,7 @@use crate::domain::{models::{- AdvancedSortParams, FrecencySoupItem, SimpleSortQuery, SimpleSortRequest, SoupErr,- SoupQuery, SoupRequest, SoupType,+ AdvancedSortParams, FrecencyQueryInner, FrecencySoupItem, SimpleQueryInner,+ SimpleSortQuery, SimpleSortRequest, SoupErr, SoupQuery, SoupRequest, SoupType,},ports::{SoupOutput, SoupRepo, SoupService},};@@ -16,7 +16,7 @@ use frecency::domain::{models::{AggregateId, FrecencyPageRequest, JoinFrecency},ports::FrecencyQueryService,};-use item_filters::ast::EntityFilterAst;+use item_filters::{EntityFilters, ast::EntityFilterAst};use macro_user_id::{cowlike::CowLike, user_id::MacroUserIdStr};use model_entity::as_owned::ShallowClone;use models_pagination::{@@ -347,15 +347,16 @@ whereC: ChannelsService,{#[tracing::instrument(err, skip(self))]- async fn get_user_soup(&self, req: SoupRequest) -> Result<SoupOutput, SoupErr> {+ async fn get_user_soup(&self, req: SoupRequest<EntityFilters>) -> Result<SoupOutput, SoupErr> {+ let entity_filter = req.filters().clone();+ let req = req.into_ast()?;let limit = req.limit.clamp(20, 500);- let paginate_filter = req.cursor.filter().cloned();let email_request = req.build_email_request();let comms_request = req.build_comms_request();match req.cursor {- SoupQuery::Simple(cursor) => {+ SoupQuery::Simple(SimpleQueryInner(cursor)) => {let sort_method = *cursor.sort_method();let main_soup_fut = self.handle_simple_request(@@ -379,16 +380,16 @@ where.chain(email_soup?).chain(comms_soup?).paginate_on(limit.into(), sort_method)- .filter_on(paginate_filter)+ .filter_on(entity_filter).sort_desc().into_page(),))}- SoupQuery::Frecency(cursor) => Ok(Either::Right(+ SoupQuery::Frecency(FrecencyQueryInner(cursor)) => Ok(Either::Right(self.handle_advanced_sort(cursor, req.soup_type, req.user, limit).await?.paginate_on(limit.into(), Frecency)- .filter_on(paginate_filter)+ .filter_on(entity_filter).into_page(),)),}diff --git a/rust/cloud-storage/soup/src/domain/service/tests.rs b/rust/cloud-storage/soup/src/domain/service/tests.rsindex 915c2b5d4b..f082982288 100644--- a/rust/cloud-storage/soup/src/domain/service/tests.rs+++ b/rust/cloud-storage/soup/src/domain/service/tests.rs@@ -8,9 +8,11 @@ use frecency::domain::models::{FrecencyPageRequest, FrecencyPageResponse};use frecency::domain::ports::MockFrecencyQueryService;use frecency::domain::services::FrecencyQueryServiceImpl;use frecency::{domain::models::AggregateFrecency, outbound::mock::MockFrecencyStorage};+use item_filters::EntityFilters;use model_entity::EntityType;use models_pagination::{- Cursor, CursorVal, FrecencyValue, PaginatedCursor, SimpleSortMethod, TypeEraseCursor,+ Cursor, CursorVal, CursorWithValAndFilter, FrecencyValue, PaginatedCursor, SimpleSortMethod,+ TypeEraseCursor,};use models_soup::document::{SoupDocument, SoupDocumentSubType};use ordered_float::OrderedFloat;@@ -176,7 +178,10 @@ async fn it_should_not_query_frecency() {link_id: Some(Uuid::new_v4()),soup_type: SoupType::UnExpanded,limit: 0,- cursor: SoupQuery::Simple(Query::Sort(SimpleSortMethod::ViewedUpdated, None)),+ cursor: SoupQuery::new_sort_simple(+ SimpleSortMethod::ViewedUpdated,+ EntityFilters::default(),+ ),user: MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap(),}).await@@ -254,7 +259,7 @@ async fn it_should_query_frecency() {link_id: Some(Uuid::new_v4()),soup_type: SoupType::UnExpanded,limit: u16::MAX,- cursor: SoupQuery::Frecency(Query::Sort(Frecency, None)),+ cursor: SoupQuery::new_sort_frecency(Frecency, EntityFilters::default()),user: MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap(),}).await@@ -332,7 +337,7 @@ async fn it_should_sort_frecency_descending() {link_id: Some(Uuid::new_v4()),soup_type: SoupType::UnExpanded,limit: u16::MAX,- cursor: SoupQuery::Frecency(Query::Sort(Frecency, None)),+ cursor: SoupQuery::new_sort_frecency(Frecency, EntityFilters::default()),user: MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap(),}).await@@ -419,7 +424,7 @@ async fn frecency_should_fallback() {link_id: Some(Uuid::new_v4()),soup_type: SoupType::UnExpanded,limit: 100,- cursor: SoupQuery::Frecency(Query::Sort(Frecency, None)),+ cursor: SoupQuery::new_sort_frecency(Frecency, EntityFilters::default()),user: MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap(),}).await@@ -437,10 +442,11 @@ async fn frecency_should_fallback() {assert!(v.frecency_score.is_none());});// cursor should encode correct info- let typed_cursor = res.next_cursor.unwrap().decode_json().unwrap();+ let typed_cursor: CursorWithValAndFilter<String, Frecency, EntityFilters> =+ res.next_cursor.unwrap().decode_json().unwrap();assert_matches!(typed_cursor,- Cursor { id, limit: 100, val: CursorVal { sort_type: Frecency, last_val: FrecencyValue::UpdatedAt(updated) }, filter: None } => {+ CursorWithValAndFilter { id, limit: 100, val: CursorVal { sort_type: Frecency, last_val: FrecencyValue::UpdatedAt(updated) }, filter: _ } => {let expected_uuid_str = Uuid::from_u128(100).to_string();assert_eq!(id, expected_uuid_str);assert_eq!(updated, <DateTime<Utc>>::default() + Days::new(100));@@ -489,7 +495,7 @@ async fn frecency_should_paginate() {link_id: Some(Uuid::new_v4()),soup_type: SoupType::UnExpanded,limit: 100,- cursor: SoupQuery::Frecency(Query::Sort(Frecency, None)),+ cursor: SoupQuery::new_sort_frecency(Frecency, EntityFilters::default()),user: MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap(),}).await@@ -509,10 +515,11 @@ async fn frecency_should_paginate() {);// cursor should encode correct info- let typed_cursor = res.next_cursor.unwrap().decode_json().unwrap();+ let typed_cursor: CursorWithValAndFilter<String, Frecency, EntityFilters> =+ res.next_cursor.unwrap().decode_json().unwrap();assert_matches!(typed_cursor,- Cursor { id, limit: 100, val: CursorVal { sort_type: Frecency, last_val: FrecencyValue::FrecencyScore(score) }, filter: None} => {+ CursorWithValAndFilter { id, limit: 100, val: CursorVal { sort_type: Frecency, last_val: FrecencyValue::FrecencyScore(score) }, filter: _} => {let expected_uuid_str = Uuid::from_u128(1).to_string();assert_eq!(id, expected_uuid_str);// last item should be the lowest score because we sort desc@@ -561,7 +568,7 @@ async fn frecency_should_resume_cursor() {link_id: Some(Uuid::new_v4()),soup_type: SoupType::UnExpanded,limit: 100,- cursor: SoupQuery::Frecency(Query::Cursor(Cursor {+ cursor: SoupQuery::new_cursor_frecency(CursorWithValAndFilter {id: Uuid::from_u128(5),limit: 100,val: CursorVal {@@ -569,7 +576,7 @@ async fn frecency_should_resume_cursor() {last_val: FrecencyValue::FrecencyScore(5.0),},filter: Default::default(),- })),+ }),user: MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap(),}).await@@ -586,10 +593,11 @@ async fn frecency_should_resume_cursor() {);// cursor should encode correct info- let typed_cursor = res.next_cursor.unwrap().decode_json().unwrap();+ let typed_cursor: CursorWithValAndFilter<String, Frecency, EntityFilters> =+ res.next_cursor.unwrap().decode_json().unwrap();assert_matches!(typed_cursor,- Cursor { id, limit: 100, val: CursorVal { sort_type: Frecency, last_val: FrecencyValue::FrecencyScore(score) }, filter: None} => {+ CursorWithValAndFilter { id, limit: 100, val: CursorVal { sort_type: Frecency, last_val: FrecencyValue::FrecencyScore(score) }, filter: _} => {let expected_uuid_str = Uuid::from_u128(100).to_string(); // "next-100" -> 100assert_eq!(id, expected_uuid_str);// last item should be the lowest score because we sort desc@@ -649,15 +657,15 @@ async fn frecency_fallback_cursor_should_resume() {link_id: Some(Uuid::new_v4()),soup_type: SoupType::UnExpanded,limit: 100,- cursor: SoupQuery::Frecency(Query::Cursor(Cursor {+ cursor: SoupQuery::new_cursor_frecency(CursorWithValAndFilter {id: Uuid::from_u128(100),limit: 100,val: CursorVal {sort_type: Frecency,last_val: FrecencyValue::UpdatedAt(DateTime::default() + Days::new(5)),},- filter: None,- })),+ filter: Default::default(),+ }),user: MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap(),}).await@@ -665,8 +673,9 @@ async fn frecency_fallback_cursor_should_resume() {.unwrap_right();assert!(res.items.iter().all(|v| v.frecency_score.is_none()));- let cursor = res.next_cursor.unwrap().decode_json().unwrap();- assert_matches!(cursor, Cursor { id, limit: 100, val: CursorVal { sort_type: Frecency, last_val: FrecencyValue::UpdatedAt(updated) }, filter: None } => {+ let cursor: CursorWithValAndFilter<String, Frecency, EntityFilters> =+ res.next_cursor.unwrap().decode_json().unwrap();+ assert_matches!(cursor, CursorWithValAndFilter { id, limit: 100, val: CursorVal { sort_type: Frecency, last_val: FrecencyValue::UpdatedAt(updated) }, filter: _ } => {let expected_uuid_str = Uuid::from_u128(100).to_string(); // "next-100" -> 100assert_eq!(id, expected_uuid_str);let expected_date = <DateTime<Utc>>::default() + Days::new(100);@@ -718,20 +727,23 @@ async fn cursor_should_return_simple_sort() {link_id: Some(Uuid::new_v4()),soup_type: SoupType::UnExpanded,limit: 0,- cursor: SoupQuery::Simple(Query::Sort(SimpleSortMethod::ViewedUpdated, None)),+ cursor: SoupQuery::new_sort_simple(+ SimpleSortMethod::ViewedUpdated,+ EntityFilters::default(),+ ),user: MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap(),}).await.unwrap();let simple_cursor = res.unwrap_left();- let cursor_decoded = simple_cursor.next_cursor.unwrap().decode_json().unwrap();- assert_matches!(cursor_decoded, Cursor { id, limit: 20, val: CursorVal { sort_type: SimpleSortMethod::ViewedUpdated, last_val }, filter } => {+ let cursor_decoded: CursorWithValAndFilter<String, SimpleSortMethod, EntityFilters> =+ simple_cursor.next_cursor.unwrap().decode_json().unwrap();+ assert_matches!(cursor_decoded, CursorWithValAndFilter { id, limit: 20, val: CursorVal { sort_type: SimpleSortMethod::ViewedUpdated, last_val }, filter: _ } => {let expected_uuid_str = Uuid::from_u128(19).to_string(); // "my-document-19" -> 19assert_eq!(id, expected_uuid_str);let date: DateTime<Utc> = Default::default();assert_eq!(last_val, date);- assert!(filter.is_none());})}@@ -776,19 +788,19 @@ async fn cursor_should_return_frecency() {link_id: Some(Uuid::new_v4()),soup_type: SoupType::UnExpanded,limit: 100,- cursor: SoupQuery::Frecency(Query::Sort(Frecency, None)),+ cursor: SoupQuery::new_sort_frecency(Frecency, EntityFilters::default()),user: MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap(),}).await.unwrap();let simple_cursor = res.unwrap_right();- let cursor_decoded = simple_cursor.next_cursor.unwrap().decode_json().unwrap();- assert_matches!(cursor_decoded, Cursor { id, limit: 100, val: CursorVal { sort_type: Frecency, last_val: FrecencyValue::FrecencyScore(1.0) }, filter } => {+ let cursor_decoded: CursorWithValAndFilter<String, Frecency, EntityFilters> =+ simple_cursor.next_cursor.unwrap().decode_json().unwrap();+ assert_matches!(cursor_decoded, CursorWithValAndFilter { id, limit: 100, val: CursorVal { sort_type: Frecency, last_val: FrecencyValue::FrecencyScore(1.0) }, filter: _ } => {// frecency sort is descending so the last item is id 1let expected_uuid_str = Uuid::from_u128(1).to_string();assert_eq!(id, expected_uuid_str);- assert!(filter.is_none());})}@@ -832,7 +844,10 @@ async fn it_should_return_is_completed_true_for_completed_tasks() {link_id: Some(Uuid::new_v4()),soup_type: SoupType::UnExpanded,limit: 0,- cursor: SoupQuery::Simple(Query::Sort(SimpleSortMethod::ViewedUpdated, None)),+ cursor: SoupQuery::new_sort_simple(+ SimpleSortMethod::ViewedUpdated,+ EntityFilters::default(),+ ),user: MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap(),}).await@@ -875,7 +890,10 @@ async fn it_should_return_is_completed_false_for_incomplete_tasks() {link_id: Some(Uuid::new_v4()),soup_type: SoupType::UnExpanded,limit: 0,- cursor: SoupQuery::Simple(Query::Sort(SimpleSortMethod::ViewedUpdated, None)),+ cursor: SoupQuery::new_sort_simple(+ SimpleSortMethod::ViewedUpdated,+ EntityFilters::default(),+ ),user: MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap(),}).await@@ -918,7 +936,10 @@ async fn it_should_return_is_completed_none_for_non_tasks() {link_id: Some(Uuid::new_v4()),soup_type: SoupType::UnExpanded,limit: 0,- cursor: SoupQuery::Simple(Query::Sort(SimpleSortMethod::ViewedUpdated, None)),+ cursor: SoupQuery::new_sort_simple(+ SimpleSortMethod::ViewedUpdated,+ EntityFilters::default(),+ ),user: MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap(),}).await@@ -973,7 +994,10 @@ async fn it_should_preserve_is_completed_for_mixed_items() {link_id: Some(Uuid::new_v4()),soup_type: SoupType::UnExpanded,limit: 0,- cursor: SoupQuery::Simple(Query::Sort(SimpleSortMethod::ViewedUpdated, None)),+ cursor: SoupQuery::new_sort_simple(+ SimpleSortMethod::ViewedUpdated,+ EntityFilters::default(),+ ),user: MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap(),}).await@@ -1042,7 +1066,7 @@ async fn it_should_preserve_is_completed_in_by_ids_queries() {link_id: Some(Uuid::new_v4()),soup_type: SoupType::UnExpanded,limit: 3,- cursor: SoupQuery::Frecency(Query::Sort(Frecency, None)),+ cursor: SoupQuery::new_sort_frecency(Frecency, EntityFilters::default()),user: MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap(),}).awaitdiff --git a/rust/cloud-storage/soup/src/inbound/axum_router.rs b/rust/cloud-storage/soup/src/inbound/axum_router.rsindex bc36d49436..354c2cdbdd 100644--- a/rust/cloud-storage/soup/src/inbound/axum_router.rs+++ b/rust/cloud-storage/soup/src/inbound/axum_router.rs@@ -17,10 +17,7 @@ use email::{},inbound::{EmailLinkErr, EmailLinkExtractor, EmailPreviewState},};-use item_filters::{- EntityFilters,- ast::{EntityFilterAst, ExpandErr},-};+use item_filters::{EntityFilters, ast::ExpandErr};use macro_user_id::user_id::MacroUserIdStr;use model_error_response::ErrorResponse;use model_user::axum_extractor::MacroUserExtractor;@@ -122,8 +119,6 @@ where}: PostSoupRequest,cursor: SoupCursor,) -> Result<Json<PaginatedOpaqueCursor<SoupApiItem>>, SoupHandlerErr> {- let filters = EntityFilterAst::new_from_filters(filters)?;-let create_fallback = move || {let params_sort = params.sort_method@@ -131,24 +126,20 @@ where.unwrap_or(SortMethod::Simple(SimpleSortMethod::ViewedAt));match params_sort {SortMethod::Simple(simple_sort_method) => {- SoupQuery::Simple(models_pagination::Query::Sort(simple_sort_method, filters))- }- SortMethod::Advanced(frecency) => {- SoupQuery::Frecency(models_pagination::Query::Sort(frecency, filters))+ SoupQuery::new_sort_simple(simple_sort_method, filters)}+ SortMethod::Advanced(frecency) => SoupQuery::new_sort_frecency(frecency, filters),}};let cursor = match cursor {Either::E1(l) => l.into_option()- .map(models_pagination::Query::Cursor)- .map(SoupQuery::Simple)+ .map(SoupQuery::new_cursor_simple).unwrap_or_else(create_fallback),Either::E2(r) => r.into_option()- .map(models_pagination::Query::Cursor)- .map(SoupQuery::Frecency)+ .map(SoupQuery::new_cursor_frecency).unwrap_or_else(create_fallback),};@@ -210,11 +201,20 @@ impl SoupApiItem {#[derive(Debug, Error)]pub enum SoupHandlerErr {#[error("An internal server error has occurred")]- Internal(#[from] SoupErr),+ Internal(SoupErr),#[error("An internal email server error has occurred")]EmailLinkErr(#[from] EmailLinkErr),#[error("Invalid filter arguments provided")]- ExpandErr(#[from] ExpandErr),+ ExpandErr(ExpandErr),+}++impl From<SoupErr> for SoupHandlerErr {+ fn from(value: SoupErr) -> Self {+ match value {+ SoupErr::AstErr(expand_err) => SoupHandlerErr::ExpandErr(expand_err),+ err => SoupHandlerErr::Internal(err),+ }+ }}impl IntoResponse for SoupHandlerErr {@@ -287,8 +287,8 @@ pub struct PostSoupRequest {}type SoupCursor = axum_extra::either::Either<- CursorExtractor<Uuid, SimpleSortMethod, Option<EntityFilterAst>>,- CursorExtractor<Uuid, Frecency, Option<EntityFilterAst>>,+ CursorExtractor<Uuid, SimpleSortMethod, EntityFilters>,+ CursorExtractor<Uuid, Frecency, EntityFilters>,>;/// Gets the items the user has access todiff --git a/rust/cloud-storage/soup/src/inbound/axum_router/tests.rs b/rust/cloud-storage/soup/src/inbound/axum_router/tests.rsindex 50a135b152..7aaed69e95 100644--- a/rust/cloud-storage/soup/src/inbound/axum_router/tests.rs+++ b/rust/cloud-storage/soup/src/inbound/axum_router/tests.rs@@ -8,7 +8,7 @@ use email::domain::{ports::EmailService,};use http_body_util::BodyExt;-use item_filters::ast::EntityFilterAst;+use item_filters::EntityFilters;use macro_user_id::{email::EmailStr, user_id::MacroUserIdStr};use model_user::UserContext;use models_pagination::{@@ -23,17 +23,17 @@ use uuid::Uuid;use crate::{domain::{- models::{SoupErr, SoupQuery, SoupRequest, SoupType},+ models::{FrecencyQueryInner, SimpleQueryInner, SoupErr, SoupQuery, SoupRequest, SoupType},ports::{SoupOutput, SoupService},},inbound::axum_router::{SoupRouterState, soup_router},};-static CURSOR: &str = "eyJpZCI6ImUzNmM5MTJlLTU2M2MtNDIxZS1iMTAzLWE0YjAwY2ZmMzBlZSIsImxpbWl0IjoxMDAsInZhbCI6eyJzb3J0X3R5cGUiOiJ1cGRhdGVkX2F0IiwibGFzdF92YWwiOiIyMDI1LTExLTA3VDE5OjEyOjU5Ljc4MFoifX0=";+static CURSOR: &str = "eyJpZCI6ImUzNmM5MTJlLTU2M2MtNDIxZS1iMTAzLWE0YjAwY2ZmMzBlZSIsImxpbWl0IjoxMDAsInZhbCI6eyJzb3J0X3R5cGUiOiJ1cGRhdGVkX2F0IiwibGFzdF92YWwiOiIyMDI1LTExLTA3VDE5OjEyOjU5Ljc4MFoifSwiZmlsdGVyIjp7fX0=";#[derive(Clone)]struct MockSoup {- called: Arc<std::sync::Mutex<Vec<SoupRequest>>>,+ called: Arc<std::sync::Mutex<Vec<SoupRequest<EntityFilters>>>>,}impl MockSoup {@@ -47,7 +47,7 @@ impl MockSoup {impl SoupService for MockSoup {async fn get_user_soup(&self,- req: crate::domain::models::SoupRequest,+ req: crate::domain::models::SoupRequest<EntityFilters>,) -> Result<SoupOutput, SoupErr> {let mut guard = self.called.lock().unwrap();guard.push(req);@@ -347,7 +347,10 @@ async fn it_parses_file_assoc_filters() {SoupRequest {soup_type: SoupType::Expanded,limit: _,- cursor: SoupQuery::Simple(Query::Sort(SimpleSortMethod::ViewedAt, Some(_filters))),+ cursor: SoupQuery::Simple(SimpleQueryInner(Query::Sort(+ SimpleSortMethod::ViewedAt,+ _filters+ ))),user: _,email_preview_view: _,link_id: _@@ -417,7 +420,7 @@ async fn cursor_with_assoc_works() {let res = (0..1000).map(|x| Data(x, Uuid::new_v4())).paginate_on(100, Frecency)- .filter_on(arg.cursor.filter().cloned())+ .filter_on(arg.cursor.filter().clone()).into_page();let cursor = res.type_erase().next_cursor.unwrap();@@ -450,10 +453,10 @@ async fn cursor_with_assoc_works() {assert_matches!(req,SoupRequest {- cursor: SoupQuery::Frecency(Query::Cursor(Cursor {- filter: Some(_f),+ cursor: SoupQuery::Frecency(FrecencyQueryInner(Query::Cursor(Cursor {+ filter: _f,..- })),+ }))),..})@@ -521,7 +524,7 @@ async fn cursor_with_all_works() {let res = (0..1000).map(|x| Data(x, Uuid::new_v4())).paginate_on(100, Frecency)- .filter_on(arg.cursor.filter().cloned())+ .filter_on(arg.cursor.filter().clone()).into_page();let cursor = res.type_erase().next_cursor.unwrap();@@ -554,10 +557,10 @@ async fn cursor_with_all_works() {assert_matches!(req,SoupRequest {- cursor: SoupQuery::Frecency(Query::Cursor(Cursor {- filter: Some(_f),+ cursor: SoupQuery::Frecency(FrecencyQueryInner(Query::Cursor(Cursor {+ filter: _f,..- })),+ }))),..})@@ -603,21 +606,20 @@ async fn it_parses_channel_filters() {guard.pop().unwrap()};+ // Check that channel_filters were parsed correctlyassert_matches!(arg,SoupRequest {- cursor: SoupQuery::Simple(Query::Sort(+ cursor: SoupQuery::Simple(SimpleQueryInner(Query::Sort(_,- Some(EntityFilterAst {- document_filter: None,- project_filter: None,- chat_filter: None,- email_filter: None,- channel_filter: Some(_),+ EntityFilters {+ channel_filters,..- }),- )),+ },+ ))),..+ } => {+ assert!(!channel_filters.channel_ids.is_empty());})}diff --git a/rust/cloud-storage/soup/src/inbound/toolset/list_entities.rs b/rust/cloud-storage/soup/src/inbound/toolset/list_entities.rsindex 6acc96fe5a..f82087d76b 100644--- a/rust/cloud-storage/soup/src/inbound/toolset/list_entities.rs+++ b/rust/cloud-storage/soup/src/inbound/toolset/list_entities.rs@@ -7,7 +7,7 @@ use crate::domain::{use ai::tool::{AsyncTool, RequestContext, ServiceContext, ToolCallError, ToolResult};use async_trait::async_trait;use email::domain::models::PreviewView;-use models_pagination::{Query, SimpleSortMethod, TypeEraseCursor};+use models_pagination::{SimpleSortMethod, TypeEraseCursor};use models_soup::item::SoupItem;use schemars::JsonSchema;use serde::{Deserialize, Serialize};@@ -150,7 +150,7 @@ where.get_user_soup(SoupRequest {soup_type: SoupType::Expanded,limit: RESULT_LIMIT,- cursor: SoupQuery::Simple(Query::Sort(sort_method, None)),+ cursor: SoupQuery::new_sort_simple(sort_method, Default::default()),user: (*request_context.user_id).clone(),email_preview_view: PreviewView::default(),link_id: None,