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(documents): add in default task properties to ai created tasks (#2884)

Will Hutchinson47b5fe932313
diff --git a/rust/cloud-storage/documents/src/domain/models.rs b/rust/cloud-storage/documents/src/domain/models.rs
index a6dd2e00cf..af69072849 100644
--- a/rust/cloud-storage/documents/src/domain/models.rs
+++ b/rust/cloud-storage/documents/src/domain/models.rs
@@ -10,6 +10,16 @@ use serde_json::Value;
/// SHA256 hash of an empty string — used for empty markdown documents (tasks).
pub const EMPTY_SHA256: &str = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855";
+/// Assignee property id
+pub const ASSIGNEES_PROPERTY_ID: &str = "00000001-0000-0000-0000-000000000001";
+
+/// Status property id
+pub const STATUS_PROPERTY_ID: &str = "00000001-0000-0000-0000-000000000002";
+
+/// Not started status option
+pub const NOT_STARTED_STATUS_OPTION_ID: uuid::Uuid =
+ uuid::uuid!("00000001-0000-0000-0002-000000000001");
+
/// Errors that can occur during document operations.
#[derive(Debug, thiserror::Error)]
pub enum DocumentError {
diff --git a/rust/cloud-storage/documents/src/domain/ports.rs b/rust/cloud-storage/documents/src/domain/ports.rs
index a3ac8e3737..e9d735554b 100644
--- a/rust/cloud-storage/documents/src/domain/ports.rs
+++ b/rust/cloud-storage/documents/src/domain/ports.rs
@@ -319,4 +319,12 @@ pub trait DocumentService: Send + Sync + 'static {
plain_user_id: String,
request: CreateTaskRequest,
) -> impl Future<Output = Result<CreateTaskResponse, DocumentError>> + Send;
+
+ /// Assigns the task properties to a document
+ fn handle_task_properties(
+ &self,
+ user_id: MacroUserIdStr<'static>,
+ document_id: &str,
+ request: &CreateTaskRequest,
+ ) -> impl Future<Output = Result<(), DocumentError>> + Send;
}
diff --git a/rust/cloud-storage/documents/src/domain/service.rs b/rust/cloud-storage/documents/src/domain/service.rs
index bdd34bf65e..288c559ce1 100644
--- a/rust/cloud-storage/documents/src/domain/service.rs
+++ b/rust/cloud-storage/documents/src/domain/service.rs
@@ -5,6 +5,8 @@ mod tests;
use entity_access_management::domain::ports::EntityAccessManagementService;
use model_entity::EntityType;
+use models_properties::EntityReference;
+use models_properties::api::SetPropertyValue;
use std::borrow::Cow;
use std::str::FromStr;
use std::time::{SystemTime, UNIX_EPOCH};
@@ -31,6 +33,10 @@ use s3_key::{
};
use tracing;
+use crate::domain::models::{
+ ASSIGNEES_PROPERTY_ID, NOT_STARTED_STATUS_OPTION_ID, PropertyInput, STATUS_PROPERTY_ID,
+};
+
use super::models::{
CloudFrontConfig, CommentThread, CopyDocumentRepoArgs, CreateDocumentRepoArgs,
CreateTaskRequest, CreateTaskResponse, DocumentError, EMPTY_SHA256, EditDocumentRepoArgs,
@@ -991,8 +997,8 @@ impl<
CreateDocumentRepoArgs {
id: None,
sha: EMPTY_SHA256.to_string(),
- document_name: request.task_name,
- user_id,
+ document_name: request.task_name.clone(),
+ user_id: user_id.clone(),
file_type: Some(FileType::Md),
project_id: request.project_id,
email_attachment_id: None,
@@ -1010,42 +1016,85 @@ impl<
.document_id
.clone();
+ let _ = self
+ .handle_task_properties(user_id, &document_id, &request)
+ .await
+ .inspect_err(|e| {
+ tracing::error!(
+ error=?e,
+ document_id=?document_id,
+ "failed to assign task properties",
+ );
+ });
+
+ Ok(CreateTaskResponse { document_id })
+ }
+
+ /// Assigns the task properties to a document
+ #[tracing::instrument(skip(self, request), err)]
+ async fn handle_task_properties(
+ &self,
+ user_id: MacroUserIdStr<'static>,
+ document_id: &str,
+ request: &CreateTaskRequest,
+ ) -> Result<(), DocumentError> {
if request.share_with_team {
let _ = self
.repo
- .share_with_team(&plain_user_id, &document_id)
+ .share_with_team(user_id.as_ref(), document_id)
.await
.inspect_err(|e| {
tracing::error!(error=?e, "failed to share task with team");
});
}
- if let Some(properties) = request.property_values {
- for property_input in properties {
- let Ok(property_uuid) = uuid::Uuid::parse_str(&property_input.property_id) else {
- tracing::warn!(property_id=?property_input.property_id, "invalid property_id UUID, skipping");
- continue;
- };
+ // Use provided properties or assign default ones for task
+ let properties = if let Some(properties) = request.property_values.as_ref() {
+ properties
+ } else {
+ &vec![
+ PropertyInput {
+ property_id: ASSIGNEES_PROPERTY_ID.to_string(),
+ value: SetPropertyValue::MultiEntityReference {
+ references: vec![EntityReference {
+ entity_id: user_id.as_ref().to_string(),
+ entity_type: models_properties::EntityType::User,
+ specific_message_id: None,
+ }],
+ },
+ },
+ PropertyInput {
+ property_id: STATUS_PROPERTY_ID.to_string(),
+ value: SetPropertyValue::SelectOption {
+ option_id: NOT_STARTED_STATUS_OPTION_ID,
+ },
+ },
+ ]
+ };
- let _ = self
- .task_properties_service
- .set_entity_property(
- &plain_user_id,
- &document_id,
- property_uuid,
- Some(property_input.value.clone()),
- )
- .await
- .inspect_err(|e| {
- tracing::warn!(
- property_id=?property_uuid,
+ for property_input in properties {
+ let Ok(property_uuid) = uuid::Uuid::parse_str(&property_input.property_id) else {
+ tracing::warn!(property_id=?property_input.property_id, "invalid property_id UUID, skipping");
+ continue;
+ };
+
+ let _ = self
+ .task_properties_service
+ .set_entity_property(
+ user_id.as_ref(),
+ document_id,
+ property_uuid,
+ Some(property_input.value.clone()),
+ )
+ .await
+ .inspect_err(|e| {
+ tracing::warn!(
error=?e,
- "failed to set property on task, continuing"
- );
- });
- }
+ property_uuid=?property_uuid,
+ "unable to set entity property")
+ });
}
- Ok(CreateTaskResponse { document_id })
+ Ok(())
}
}
diff --git a/rust/cloud-storage/documents/src/inbound/toolset/create_document.rs b/rust/cloud-storage/documents/src/inbound/toolset/create_document.rs
index 3523ad5fec..0e80168de3 100644
--- a/rust/cloud-storage/documents/src/inbound/toolset/create_document.rs
+++ b/rust/cloud-storage/documents/src/inbound/toolset/create_document.rs
@@ -2,6 +2,7 @@
use std::str::FromStr;
+use crate::domain::models::CreateTaskRequest;
use crate::domain::{models::CreateDocumentRepoArgs, ports::DocumentService};
use ai::tool::{AsyncTool, RequestContext, ServiceContext, ToolCallError, ToolResult};
use anyhow::Context;
@@ -84,7 +85,7 @@ where
id: None,
sha: hashes.0,
document_name: self.document_name.clone(),
- user_id,
+ user_id: user_id.clone(),
file_type: Some(parsed_file_type),
project_id: None,
email_attachment_id: None,
@@ -101,6 +102,33 @@ where
})?;
tracing::trace!("created document");
+ // if the document is a task we need to assign the default properties for the task like status and assignee
+ if self.is_task {
+ let document_id = &document_response
+ .document_response
+ .document_metadata
+ .document_id;
+
+ tracing::trace!("assigning task properties");
+ service_context
+ .service
+ .handle_task_properties(
+ user_id.clone(),
+ document_id,
+ &CreateTaskRequest {
+ task_name: self.document_name.clone(), // doesn't actually matter
+ project_id: None,
+ property_values: None, // uses default properties
+ share_with_team: true,
+ },
+ )
+ .await
+ .map_err(|e| ToolCallError {
+ description: "unable to assign task properties".to_string(),
+ internal_error: e.into(),
+ })?;
+ }
+
let document_response = document_response.document_response;
let document_metadata = document_response.document_metadata;
diff --git a/rust/cloud-storage/github/src/domain/service/sync/test.rs b/rust/cloud-storage/github/src/domain/service/sync/test.rs
index 0a923c00a8..dd982a96d8 100644
--- a/rust/cloud-storage/github/src/domain/service/sync/test.rs
+++ b/rust/cloud-storage/github/src/domain/service/sync/test.rs
@@ -209,6 +209,15 @@ impl DocumentService for StubDocumentService {
) -> Result<Vec<documents::domain::models::CommentThread>, DocumentError> {
unimplemented!()
}
+
+ async fn handle_task_properties(
+ &self,
+ _user_id: MacroUserIdStr<'static>,
+ _document_id: &str,
+ _request: &documents::domain::models::CreateTaskRequest,
+ ) -> Result<(), DocumentError> {
+ unimplemented!()
+ }
}
/// Stateful stub repo that tracks task IDs per github key.