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.

fix(ai): task properties (#3617)

Will Hutchinson80664701301e
diff --git a/rust/cloud-storage/Cargo.lock b/rust/cloud-storage/Cargo.lock
index b566888f96..ef267c6289 100644
--- a/rust/cloud-storage/Cargo.lock
+++ b/rust/cloud-storage/Cargo.lock
@@ -151,6 +151,7 @@ dependencies = [
"sqs_client",
"strum",
"sync_service_client",
+ "system_properties",
"teams",
"tokio",
"tracing",
diff --git a/rust/cloud-storage/ai_tools/Cargo.toml b/rust/cloud-storage/ai_tools/Cargo.toml
index b0b9aa030a..297eaa612d 100644
--- a/rust/cloud-storage/ai_tools/Cargo.toml
+++ b/rust/cloud-storage/ai_tools/Cargo.toml
@@ -65,6 +65,7 @@ teams = { path = "../teams", default-features = false, features = ["ai_tools", "
sqlx.workspace = true
strum.workspace = true
sync_service_client = { path = "../sync_service_client" }
+system_properties = { path = "../system_properties" }
tokio.workspace = true
tracing.workspace = true
utoipa.workspace = true
diff --git a/rust/cloud-storage/ai_tools/src/build_context.rs b/rust/cloud-storage/ai_tools/src/build_context.rs
index 2ff116a2e8..1f96b5b966 100644
--- a/rust/cloud-storage/ai_tools/src/build_context.rs
+++ b/rust/cloud-storage/ai_tools/src/build_context.rs
@@ -5,8 +5,8 @@
//! instead of duplicating the wiring logic.
use crate::tool_context::{
- NoOpCallRtcClient, NoOpConnectionService, NoOpNotificationIngress, NoOpNotificationService,
- NoOpSnsEndpointManager, NoOpTaskProperties, ToolNotificationQueue, ToolServiceContext,
+ NoOpCallRtcClient, NoOpConnectionService, NoOpNotificationIngress, NoOpSnsEndpointManager,
+ ToolNotificationQueue, ToolServiceContext,
};
use anthropic::toolset::AnthropicToolContext;
use anyhow::Context;
@@ -194,12 +194,21 @@ pub async fn build_tool_service_context_from_env(
presigned_url_expiry_seconds: 3600,
browser_cache_expiry_seconds: 86400,
};
+ let entity_access_service = Arc::new(EntityAccessServiceImpl::new(PgAccessRepository::new(
+ pool.clone(),
+ )));
+ let properties_service =
+ crate::tool_context::build_properties_service(pool.clone(), entity_access_service.clone());
+ let task_properties_service = crate::tool_context::build_task_properties_adapter(
+ pool.clone(),
+ properties_service.clone(),
+ );
let document_service = documents::domain::service::DocumentServiceImpl {
repo: document_repo,
cloudfront_config,
sync_service_client: sync_client.as_ref().clone(),
upload_url_service: s3_upload_adapter,
- task_properties_service: NoOpTaskProperties,
+ task_properties_service,
connection_service: NoOpConnectionService,
entity_access_management_service:
entity_access_management::domain::service::EntityAccessManagementServiceImpl::new(
@@ -207,9 +216,6 @@ pub async fn build_tool_service_context_from_env(
),
};
- let entity_access_service = Arc::new(EntityAccessServiceImpl::new(PgAccessRepository::new(
- pool.clone(),
- )));
let document_tool_context = DocumentToolContext::new(
document_service,
(*entity_access_service).clone(),
@@ -217,16 +223,8 @@ pub async fn build_tool_service_context_from_env(
sync_client.as_ref().clone(),
);
- let properties_service = properties::PropertiesServiceImpl::new(
- properties::PropertiesPgRepo::new(pool.clone()),
- Some(properties::PermissionServiceImpl::new(
- pool.clone(),
- entity_access_service.clone(),
- )),
- Some(NoOpNotificationService),
- );
let properties_tool_context =
- properties::inbound::toolset::PropertiesToolContext::new(properties_service);
+ crate::tool_context::build_properties_tool_context(properties_service);
let email_tool_context = email::inbound::toolset::EmailToolContext::new(
Arc::new(EmailServiceImpl::new(
diff --git a/rust/cloud-storage/ai_tools/src/lib.rs b/rust/cloud-storage/ai_tools/src/lib.rs
index da1b931818..438c960272 100644
--- a/rust/cloud-storage/ai_tools/src/lib.rs
+++ b/rust/cloud-storage/ai_tools/src/lib.rs
@@ -34,13 +34,15 @@ pub use tool_context::no_op_schedule_context;
pub use tool_context::{
NoOpCallRtcClient, NoOpConnectionService, NoOpNotificationIngress, NoOpNotificationService,
NoOpScheduleContext, NoOpSnsEndpointManager, NoOpTaskProperties, RequestContext,
- ToolCallRecordQueryService, ToolCallService, ToolCallToolContext, ToolChannelMessagesService,
- ToolChannelToolContext, ToolChatService, ToolChatToolContext, ToolCommsService,
- ToolDocumentService, ToolDocumentToolContext, ToolEmailService, ToolEmailToolContext,
- ToolEntityAccessManagementService, ToolEntityAccessService, ToolFrecencyService,
- ToolNotificationQueue, ToolNotificationService, ToolNotificationToolContext,
- ToolPropertiesService, ToolPropertiesToolContext, ToolServiceContext, ToolSoupService,
- ToolTeamService, ToolTeamToolContext, ToolUserEmailService, build_channel_tool_context,
+ TaskPropertiesAdapter, ToolCallRecordQueryService, ToolCallService, ToolCallToolContext,
+ ToolChannelMessagesService, ToolChannelToolContext, ToolChatService, ToolChatToolContext,
+ ToolCommsService, ToolDocumentService, ToolDocumentToolContext, ToolEmailService,
+ ToolEmailToolContext, ToolEntityAccessManagementService, ToolEntityAccessService,
+ ToolFrecencyService, ToolNotificationQueue, ToolNotificationService,
+ ToolNotificationToolContext, ToolPropertiesService, ToolPropertiesToolContext,
+ ToolServiceContext, ToolSoupService, ToolSystemPropertiesService, ToolTeamService,
+ ToolTeamToolContext, ToolUserEmailService, build_channel_tool_context,
+ build_properties_service, build_properties_tool_context, build_task_properties_adapter,
build_team_tool_context,
};
pub type AiToolSet = AsyncToolCollection<ToolServiceContext>;
diff --git a/rust/cloud-storage/ai_tools/src/tool_context.rs b/rust/cloud-storage/ai_tools/src/tool_context.rs
index 3ed7961766..a545406128 100644
--- a/rust/cloud-storage/ai_tools/src/tool_context.rs
+++ b/rust/cloud-storage/ai_tools/src/tool_context.rs
@@ -22,6 +22,10 @@ use notification::inbound::ai_tool::NotificationToolContext;
use properties::inbound::toolset::PropertiesToolContext;
use soup::{domain::service::SoupImpl, inbound::toolset::SoupToolContext};
use std::sync::Arc;
+use system_properties::{
+ PgSystemPropertiesRepository, StatusOption, SystemPropertiesService as _,
+ SystemPropertiesServiceImpl,
+};
use teams::{inbound::toolset::TeamToolContext, outbound::team_repo::TeamRepositoryImpl};
pub use ai_toolset::RequestContext;
@@ -94,7 +98,7 @@ pub fn build_team_tool_context(pool: sqlx::PgPool) -> ToolTeamToolContext {
)
}
-/// No-op task properties service (not needed for AI tools)
+/// No-op task properties service for tests and contexts that do not create tasks.
#[derive(Clone)]
pub struct NoOpTaskProperties;
@@ -123,6 +127,66 @@ impl TaskPropertiesPort for NoOpTaskProperties {
}
}
+/// Adapter implementing [`TaskPropertiesPort`] with the real properties services.
+#[derive(Clone)]
+pub struct TaskPropertiesAdapter {
+ /// System properties service used to attach/copy task property rows.
+ pub system_properties: Arc<ToolSystemPropertiesService>,
+ /// Properties service used to assign concrete task property values.
+ pub properties: Arc<ToolPropertiesService>,
+}
+
+impl TaskPropertiesPort for TaskPropertiesAdapter {
+ async fn attach_task_properties(&self, entity_ids: Vec<String>) -> anyhow::Result<()> {
+ self.system_properties
+ .attach_task_properties(entity_ids)
+ .await
+ .map_err(Into::into)
+ }
+
+ async fn update_task_status(&self, task_id: &str, status: &str) -> anyhow::Result<()> {
+ let status_option = StatusOption::try_from(status).map_err(|e| anyhow::anyhow!(e))?;
+
+ self.system_properties
+ .update_task_status(task_id, status_option)
+ .await?;
+
+ Ok(())
+ }
+
+ async fn set_entity_property(
+ &self,
+ user_id: &str,
+ entity_id: &str,
+ property_definition_id: uuid::Uuid,
+ value: Option<models_properties::api::requests::SetPropertyValue>,
+ ) -> anyhow::Result<()> {
+ use properties::PropertiesService as _;
+
+ self.properties
+ .set_entity_property(
+ user_id,
+ entity_id,
+ models_properties::EntityType::Task,
+ property_definition_id,
+ value,
+ )
+ .await
+ .map_err(Into::into)
+ }
+
+ async fn copy_task_properties(
+ &self,
+ from_task_id: &str,
+ to_task_id: &str,
+ ) -> anyhow::Result<()> {
+ self.system_properties
+ .copy_task_properties(from_task_id, to_task_id)
+ .await
+ .map_err(Into::into)
+ }
+}
+
/// No-op connection service
#[derive(Clone)]
pub struct NoOpConnectionService;
@@ -350,7 +414,7 @@ pub type ToolEntityAccessManagementService =
pub type ToolDocumentService = documents::domain::service::DocumentServiceImpl<
documents::outbound::pg_document_repo::PgDocumentRepo,
documents::outbound::s3_upload_url::S3UploadUrlAdapter,
- NoOpTaskProperties,
+ TaskPropertiesAdapter,
NoOpConnectionService,
ToolEntityAccessManagementService,
>;
@@ -392,6 +456,9 @@ impl properties::NotificationService for NoOpNotificationService {
}
}
+/// Type alias for the system properties service implementation used by AI tools.
+pub type ToolSystemPropertiesService = SystemPropertiesServiceImpl<PgSystemPropertiesRepository>;
+
/// Type alias for the properties service implementation used by AI tools
pub type ToolPropertiesService = properties::PropertiesServiceImpl<
properties::PropertiesPgRepo,
@@ -402,6 +469,43 @@ pub type ToolPropertiesService = properties::PropertiesServiceImpl<
/// Type alias for the properties tool context
pub type ToolPropertiesToolContext = PropertiesToolContext<ToolPropertiesService>;
+/// Build the properties service shared by the properties tools and task adapter.
+pub fn build_properties_service(
+ pool: sqlx::PgPool,
+ entity_access_service: Arc<ToolEntityAccessService>,
+) -> Arc<ToolPropertiesService> {
+ Arc::new(properties::PropertiesServiceImpl::new(
+ properties::PropertiesPgRepo::new(pool.clone()),
+ Some(properties::PermissionServiceImpl::new(
+ pool,
+ entity_access_service,
+ )),
+ Some(NoOpNotificationService),
+ ))
+}
+
+/// Build the real task properties adapter used by document creation tools.
+pub fn build_task_properties_adapter(
+ pool: sqlx::PgPool,
+ properties: Arc<ToolPropertiesService>,
+) -> TaskPropertiesAdapter {
+ TaskPropertiesAdapter {
+ system_properties: Arc::new(SystemPropertiesServiceImpl::new(
+ PgSystemPropertiesRepository::new(pool),
+ )),
+ properties,
+ }
+}
+
+/// Build a properties tool context from a shared properties service.
+pub fn build_properties_tool_context(
+ properties: Arc<ToolPropertiesService>,
+) -> ToolPropertiesToolContext {
+ PropertiesToolContext {
+ service: properties,
+ }
+}
+
/// Type alias for the email tool context
pub type ToolEmailToolContext = EmailToolContext<ToolUserEmailService>;
diff --git a/rust/cloud-storage/document_cognition_service/src/api/context/test.rs b/rust/cloud-storage/document_cognition_service/src/api/context/test.rs
index 92d6838061..d40cbcdef6 100644
--- a/rust/cloud-storage/document_cognition_service/src/api/context/test.rs
+++ b/rust/cloud-storage/document_cognition_service/src/api/context/test.rs
@@ -229,22 +229,26 @@ pub async fn test_api_context(pool: sqlx::Pool<sqlx::Postgres>) -> std::sync::Ar
presigned_url_expiry_seconds: 3600,
browser_cache_expiry_seconds: 86400,
};
+ let entity_access_service = Arc::new(
+ entity_access::domain::service::EntityAccessServiceImpl::new(
+ entity_access::outbound::PgAccessRepository::new(pool.clone()),
+ ),
+ );
+ let properties_service =
+ ai_tools::build_properties_service(pool.clone(), entity_access_service.clone());
+ let task_properties_service =
+ ai_tools::build_task_properties_adapter(pool.clone(), properties_service.clone());
let document_service = documents::domain::service::DocumentServiceImpl::new(
document_repo,
cloudfront_config,
sync_service_client.as_ref().clone(),
s3_upload_adapter,
- ai_tools::NoOpTaskProperties,
+ task_properties_service,
ai_tools::NoOpConnectionService,
entity_access_management::domain::service::EntityAccessManagementServiceImpl::new(
entity_access_management::outbound::PgRepository::new(pool.clone()),
),
);
- let entity_access_service = Arc::new(
- entity_access::domain::service::EntityAccessServiceImpl::new(
- entity_access::outbound::PgAccessRepository::new(pool.clone()),
- ),
- );
let test_lexical_client = LexicalClient::new("test".into(), "http://nofileshere".into());
let document_tool_context = documents::inbound::toolset::DocumentToolContext::new(
document_service,
@@ -256,16 +260,7 @@ pub async fn test_api_context(pool: sqlx::Pool<sqlx::Postgres>) -> std::sync::Ar
let search_service_client = Arc::new(search_service_client);
// Build properties tool context
- let properties_service = properties::PropertiesServiceImpl::new(
- properties::PropertiesPgRepo::new(pool.clone()),
- Some(properties::PermissionServiceImpl::new(
- pool.clone(),
- entity_access_service.clone(),
- )),
- Some(ai_tools::NoOpNotificationService),
- );
- let properties_tool_context =
- properties::inbound::toolset::PropertiesToolContext::new(properties_service);
+ let properties_tool_context = ai_tools::build_properties_tool_context(properties_service);
let email_tool_context = email::inbound::toolset::EmailToolContext::new(
Arc::new(email::domain::service::EmailServiceImpl::new(
diff --git a/rust/cloud-storage/document_cognition_service/src/main.rs b/rust/cloud-storage/document_cognition_service/src/main.rs
index 53e7c019f0..e585485f2a 100644
--- a/rust/cloud-storage/document_cognition_service/src/main.rs
+++ b/rust/cloud-storage/document_cognition_service/src/main.rs
@@ -1,9 +1,6 @@
#![recursion_limit = "256"]
use crate::api::context::ApiContext;
-use ai_tools::{
- NoOpCallRtcClient, NoOpConnectionService, NoOpNotificationIngress, NoOpNotificationService,
- NoOpTaskProperties,
-};
+use ai_tools::{NoOpCallRtcClient, NoOpConnectionService, NoOpNotificationIngress};
use anyhow::Context;
use call::domain::service::{CallRecordQueryServiceImpl, CallServiceImpl};
use call::inbound::toolset::CallToolContext;
@@ -252,12 +249,16 @@ async fn main() -> anyhow::Result<()> {
presigned_url_expiry_seconds: 3600,
browser_cache_expiry_seconds: 86400,
};
+ let properties_service =
+ ai_tools::build_properties_service(db.clone(), entity_access_service.clone());
+ let task_properties_service =
+ ai_tools::build_task_properties_adapter(db.clone(), properties_service.clone());
let document_service = DocumentServiceImpl::new(
document_repo,
cloudfront_config,
sync_service_client.clone(),
s3_upload_adapter,
- NoOpTaskProperties,
+ task_properties_service,
NoOpConnectionService,
entity_access_management::domain::service::EntityAccessManagementServiceImpl::new(
entity_access_management::outbound::PgRepository::new(db.clone()),
@@ -308,16 +309,7 @@ async fn main() -> anyhow::Result<()> {
let search_service_client = Arc::new(search_service_client);
- let properties_service = properties::PropertiesServiceImpl::new(
- properties::PropertiesPgRepo::new(db.clone()),
- Some(properties::PermissionServiceImpl::new(
- db.clone(),
- entity_access_service.clone(),
- )),
- Some(NoOpNotificationService),
- );
- let properties_tool_context =
- properties::inbound::toolset::PropertiesToolContext::new(properties_service);
+ let properties_tool_context = ai_tools::build_properties_tool_context(properties_service);
tracing::info!("initialized properties tool context");
diff --git a/rust/cloud-storage/mcp_service/src/context.rs b/rust/cloud-storage/mcp_service/src/context.rs
index ca675ad6df..de8a260b11 100644
--- a/rust/cloud-storage/mcp_service/src/context.rs
+++ b/rust/cloud-storage/mcp_service/src/context.rs
@@ -1,9 +1,8 @@
use std::sync::Arc;
use ai_tools::{
- NoOpCallRtcClient, NoOpConnectionService, NoOpNotificationIngress, NoOpNotificationService,
- NoOpScheduleContext, NoOpSnsEndpointManager, NoOpTaskProperties, ToolNotificationQueue,
- ToolServiceContext,
+ NoOpCallRtcClient, NoOpConnectionService, NoOpNotificationIngress, NoOpScheduleContext,
+ NoOpSnsEndpointManager, ToolNotificationQueue, ToolServiceContext,
};
use anyhow::Context;
use comms::domain::service::ChannelServiceImpl;
@@ -218,39 +217,34 @@ async fn build_tool_context(
};
let sync_service_client =
SyncServiceClient::new(sync_service_auth_key.clone(), sync_service_url.clone());
+ let entity_access_service = Arc::new(EntityAccessServiceImpl::new(PgAccessRepository::new(
+ db.clone(),
+ )));
+ let properties_service =
+ ai_tools::build_properties_service(db.clone(), entity_access_service.clone());
+ let task_properties_service =
+ ai_tools::build_task_properties_adapter(db.clone(), properties_service.clone());
let document_service = documents::domain::service::DocumentServiceImpl {
repo: document_repo,
cloudfront_config,
sync_service_client: sync_service_client.clone(),
upload_url_service: s3_upload_adapter,
- task_properties_service: NoOpTaskProperties,
+ task_properties_service,
connection_service: NoOpConnectionService,
entity_access_management_service:
entity_access_management::domain::service::EntityAccessManagementServiceImpl::new(
entity_access_management::outbound::PgRepository::new(db.clone()),
),
};
- let entity_access_service = EntityAccessServiceImpl::new(PgAccessRepository::new(db.clone()));
let lexical_client_for_tools = (*lexical_client).clone();
let document_tool_context = DocumentToolContext::new(
document_service,
- entity_access_service,
+ (*entity_access_service).clone(),
lexical_client_for_tools,
sync_service_client.clone(),
);
- let properties_service = properties::PropertiesServiceImpl::new(
- properties::PropertiesPgRepo::new(db.clone()),
- Some(properties::PermissionServiceImpl::new(
- db.clone(),
- Arc::new(EntityAccessServiceImpl::new(PgAccessRepository::new(
- db.clone(),
- ))),
- )),
- Some(NoOpNotificationService),
- );
- let properties_tool_context =
- properties::inbound::toolset::PropertiesToolContext::new(properties_service);
+ let properties_tool_context = ai_tools::build_properties_tool_context(properties_service);
let email_tool_context = email::inbound::toolset::EmailToolContext::new(
Arc::new(EmailServiceImpl::new(
diff --git a/rust/cloud-storage/memory/src/context.rs b/rust/cloud-storage/memory/src/context.rs
index 1a7e218e5f..18297272ab 100644
--- a/rust/cloud-storage/memory/src/context.rs
+++ b/rust/cloud-storage/memory/src/context.rs
@@ -1,7 +1,5 @@
use ai_tools::{
- NoOpCallRtcClient, NoOpConnectionService, NoOpNotificationIngress, NoOpNotificationService,
- NoOpScheduleContext, NoOpSnsEndpointManager, NoOpTaskProperties, ToolNotificationQueue,
- ToolServiceContext,
+ NoOpConnectionService, NoOpSnsEndpointManager, ToolNotificationQueue, ToolServiceContext,
};
use comms::domain::service::ChannelServiceImpl;
use comms::outbound::postgres::comms_repo::PgCommsRepo;
@@ -114,19 +112,24 @@ pub async fn build_tool_service_context(
presigned_url_expiry_seconds: 3600,
browser_cache_expiry_seconds: 86400,
};
+ let entity_access_service = Arc::new(EntityAccessServiceImpl::new(PgAccessRepository::new(
+ pool.clone(),
+ )));
+ let properties_service =
+ ai_tools::build_properties_service(pool.clone(), entity_access_service.clone());
+ let task_properties_service =
+ ai_tools::build_task_properties_adapter(pool.clone(), properties_service.clone());
let document_service = documents::domain::service::DocumentServiceImpl::new(
document_repo,
cloudfront_config,
sync_client.as_ref().clone(),
s3_upload_adapter,
- NoOpTaskProperties,
+ task_properties_service,
NoOpConnectionService,
entity_access_management::domain::service::EntityAccessManagementServiceImpl::new(
entity_access_management::outbound::PgRepository::new(pool.clone()),
),
);
- let entity_access_service = EntityAccessServiceImpl::new(PgAccessRepository::new(pool.clone()));
- let entity_access_service = Arc::new(entity_access_service);
let document_tool_context = DocumentToolContext::new(
document_service,
(*entity_access_service).clone(),
@@ -135,16 +138,7 @@ pub async fn build_tool_service_context(
);
// Properties tool context
- let properties_service = properties::PropertiesServiceImpl::new(
- properties::PropertiesPgRepo::new(pool.clone()),
- Some(properties::PermissionServiceImpl::new(
- pool.clone(),
- entity_access_service.clone(),
- )),
- Some(NoOpNotificationService),
- );
- let properties_tool_context =
- properties::inbound::toolset::PropertiesToolContext::new(properties_service);
+ let properties_tool_context = ai_tools::build_properties_tool_context(properties_service);
// Email tool context
let email_tool_context = email::inbound::toolset::EmailToolContext::new(