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
fix(ai): fix ai email (#2397)
Eric Hayes60235acd17d0
diff --git a/infra/stacks/document-cognition-service/index.ts b/infra/stacks/document-cognition-service/index.tsindex 99d713c688..1e6b4e24cd 100644--- a/infra/stacks/document-cognition-service/index.ts+++ b/infra/stacks/document-cognition-service/index.ts@@ -131,6 +131,10 @@ const cloudStorageServiceStack = new pulumi.StackReference(});+const emailServiceStack = new pulumi.StackReference('email-service-stack', {+ name: `macro-inc/email-service/${stack}`,+});+const linksharingStack = new pulumi.StackReference('linksharing-stack', {name: `macro-inc/link-sharing/${stack}`,});@@ -159,6 +163,14 @@ const docxUploadBucketArn: pulumi.Output<string> = cloudStorageServiceStack.getOutput('docxUploadBucketArn').apply((arn) => arn as string);+const emailScheduledQueueArn: pulumi.Output<string> = emailServiceStack+ .getOutput('scheduledQueueArn')+ .apply((arn) => arn as string);++const emailScheduledQueueName: pulumi.Output<string> = emailServiceStack+ .getOutput('scheduledQueueName')+ .apply((name) => name as string);+export const documentStorageServiceUrl: pulumi.Output<string> =cloudStorageServiceStack.getOutput('cloudStorageServiceUrl')@@ -238,6 +250,7 @@ const documentCognitionService = new DocumentCognitionService(queueArns: [documentTextExtractorQueueArn,deleteChatQueueArn,+ emailScheduledQueueArn,searchEventQueueArn,notificationIngressQueueArn,],@@ -283,6 +296,10 @@ const documentCognitionService = new DocumentCognitionService(name: 'CHAT_DELETE_QUEUE',value: pulumi.interpolate`${deleteChatQueueName}`,},+ {+ name: 'EMAIL_SCHEDULED_QUEUE',+ value: pulumi.interpolate`${emailScheduledQueueName}`,+ },{name: 'DOCUMENT_STORAGE_BUCKET',value: pulumi.interpolate`${documentStorageBucketId}`,diff --git a/infra/stacks/mcp-server/index.ts b/infra/stacks/mcp-server/index.tsindex adf63995df..078db6d901 100644--- a/infra/stacks/mcp-server/index.ts+++ b/infra/stacks/mcp-server/index.ts@@ -99,6 +99,10 @@ const cloudStorageServiceStack = new pulumi.StackReference(});+const emailServiceStack = new pulumi.StackReference('email-service-stack', {+ name: `macro-inc/email-service/${stack}`,+});+export const documentStorageServiceUrl: pulumi.Output<string> =cloudStorageServiceStack.getOutput('cloudStorageServiceUrl')@@ -112,6 +116,14 @@ const docxUploadBucketArn: pulumi.Output<string> = cloudStorageServiceStack.getOutput('docxUploadBucketArn').apply((arn) => arn as string);+const emailScheduledQueueArn: pulumi.Output<string> = emailServiceStack+ .getOutput('scheduledQueueArn')+ .apply((arn) => arn as string);++const emailScheduledQueueName: pulumi.Output<string> = emailServiceStack+ .getOutput('scheduledQueueName')+ .apply((name) => name as string);+const linksharingStack = new pulumi.StackReference('linksharing-stack', {name: `macro-inc/link-sharing/${stack}`,});@@ -151,6 +163,7 @@ const mcpServer = new McpServer(`mcp-server-${stack}`, {cloudfrontPrivateKeySecretArn,MACRO_API_TOKENS.macroApiTokenPublicKeyArn,],+ queueArns: [emailScheduledQueueArn],bucketArns: [documentStorageBucketArn, docxUploadBucketArn],serviceContainerPort: 8080,healthCheckPath: '/health',@@ -213,6 +226,10 @@ const mcpServer = new McpServer(`mcp-server-${stack}`, {stack === 'prod' ? '' : `-${stack}`}.macro.com`,},+ {+ name: 'EMAIL_SCHEDULED_QUEUE',+ value: pulumi.interpolate`${emailScheduledQueueName}`,+ },{name: 'STATIC_FILE_SERVICE_URL',value: `https://static-file-service${diff --git a/infra/stacks/mcp-server/mcp-server.ts b/infra/stacks/mcp-server/mcp-server.tsindex 43fc0b55fe..f5fbd82498 100644--- a/infra/stacks/mcp-server/mcp-server.ts+++ b/infra/stacks/mcp-server/mcp-server.ts@@ -36,6 +36,7 @@ type CreateMcpServerArgs = {healthCheckPath: string;tags: { [key: string]: string };secretKeyArns: (pulumi.Output<string> | string)[];+ queueArns: (pulumi.Output<string> | string)[];bucketArns: (pulumi.Output<string> | string)[];};@@ -64,6 +65,7 @@ export class McpServer extends pulumi.ComponentResource {containerEnvVars,cloudStorageClusterName,secretKeyArns,+ queueArns,bucketArns,tags,}: CreateMcpServerArgs,@@ -166,6 +168,29 @@ export class McpServer extends pulumi.ComponentResource {{ parent: this });+ const sqsPolicy = new aws.iam.Policy(+ `${BASE_NAME}-sqs-policy`,+ {+ name: `${BASE_NAME}-sqs-policy-${stack}`,+ policy: {+ Version: '2012-10-17',+ Statement: [+ {+ Action: [+ 'sqs:SendMessage',+ 'sqs:DeleteMessage',+ 'sqs:GetQueueAttributes',+ ],+ Resource: queueArns,+ Effect: 'Allow',+ },+ ],+ },+ tags: this.tags,+ },+ { parent: this }+ );+this.role = new aws.iam.Role(`${BASE_NAME}-role`,{@@ -183,7 +208,11 @@ export class McpServer extends pulumi.ComponentResource {},],},- managedPolicyArns: [secretsManagerPolicy.arn, s3Policy.arn],+ managedPolicyArns: [+ secretsManagerPolicy.arn,+ s3Policy.arn,+ sqsPolicy.arn,+ ],tags: this.tags,},{ parent: this }diff --git a/rust/cloud-storage/Cargo.lock b/rust/cloud-storage/Cargo.lockindex e45699bdf9..d337e4ec25 100644--- a/rust/cloud-storage/Cargo.lock+++ b/rust/cloud-storage/Cargo.lock@@ -125,6 +125,7 @@ dependencies = ["serde_json","soup","sqlx",+ "sqs_client","strum","tokio","tracing",@@ -6263,6 +6264,7 @@ dependencies = ["ai_tools","ai_toolset","anyhow",+ "aws-sdk-sqs","axum","chrono","comms",@@ -6289,6 +6291,7 @@ dependencies = ["serde_json","soup","sqlx",+ "sqs_client","static_file_service_client","sync_service_client","thiserror 2.0.17",diff --git a/rust/cloud-storage/ai_tools/Cargo.toml b/rust/cloud-storage/ai_tools/Cargo.tomlindex 4ce487dd63..ad3721b399 100644--- a/rust/cloud-storage/ai_tools/Cargo.toml+++ b/rust/cloud-storage/ai_tools/Cargo.toml@@ -49,6 +49,7 @@ serde.workspace = trueserde_json.workspace = trueproperties = { path = "../properties", features = ["ai_tools"] }soup = { path = "../soup", features = ["ai_tools", "outbound"] }+sqs_client = { path = "../sqs_client", default-features = false, features = ["email", "gmail"] }sqlx.workspace = truestrum.workspace = truetokio.workspace = truediff --git a/rust/cloud-storage/ai_tools/src/tool_context.rs b/rust/cloud-storage/ai_tools/src/tool_context.rsindex 2938772cd3..f565d707e0 100644--- a/rust/cloud-storage/ai_tools/src/tool_context.rs+++ b/rust/cloud-storage/ai_tools/src/tool_context.rs@@ -39,6 +39,9 @@ pub type ToolFrecencyService = FrecencyQueryServiceImpl<FrecencyPgStorage>;pub type ToolEmailService =EmailServiceImpl<EmailPgRepo, ToolFrecencyService, email::domain::ports::NoOpEnqueuer>;+/// Type alias for the send-capable email service implementation used by user tools.+pub type ToolUserEmailService = EmailServiceImpl<EmailPgRepo, ToolFrecencyService, sqs_client::SQS>;+/// Type alias for the comms/channels service implementationpub type ToolCommsService = ChannelServiceImpl<PgCommsRepo, PgUserRepo, FrecencyPgStorage>;@@ -130,7 +133,7 @@ pub type ToolPropertiesService = properties::PropertiesServiceImpl<pub type ToolPropertiesToolContext = PropertiesToolContext<ToolPropertiesService>;/// Type alias for the email tool context-pub type ToolEmailToolContext = EmailToolContext<ToolEmailService>;+pub type ToolEmailToolContext = EmailToolContext<ToolUserEmailService>;/// The full service context containing all API clients./// Individual tools should extract only the clients they need via `FromRef`.diff --git a/rust/cloud-storage/document_cognition_service/Cargo.toml b/rust/cloud-storage/document_cognition_service/Cargo.tomlindex 6f0d472d33..7ea789fe1b 100644--- a/rust/cloud-storage/document_cognition_service/Cargo.toml+++ b/rust/cloud-storage/document_cognition_service/Cargo.toml@@ -118,6 +118,8 @@ sqlx = { workspace = true }sqs_client = { path = "../sqs_client", default-features = false, features = ["chat","document_text_extractor",+ "email",+ "gmail","search",] }stream = { path = "../stream" }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.rsindex 2ba920d473..87463f9b51 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@@ -135,7 +135,7 @@ pub async fn test_api_context(pool: sqlx::Pool<sqlx::Postgres>) -> std::sync::Ar.behavior_version(aws_sdk_sqs::config::BehaviorVersion::latest()).build();let aws_sqs_client = aws_sdk_sqs::Client::from_conf(sqs_config.clone());- let sqs_client = SQS::new(aws_sqs_client);+ let sqs_client = SQS::new(aws_sqs_client).email_scheduled_queue("test-email-scheduled-queue");let document_storage_client = Arc::new(DocumentStorageServiceClient::new("dummy_auth_key".into(),@@ -268,7 +268,7 @@ pub async fn test_api_context(pool: sqlx::Pool<sqlx::Postgres>) -> std::sync::Arfrecency::domain::services::FrecencyQueryServiceImpl::new(frecency::outbound::postgres::FrecencyPgStorage::new(pool.clone()),),- email::domain::ports::NoOpEnqueuer,+ sqs_client.clone(),0,)),Arc::new(email::domain::ports::NoOpGmailTokenProvider),diff --git a/rust/cloud-storage/document_cognition_service/src/bin/mcp_server.rs b/rust/cloud-storage/document_cognition_service/src/bin/mcp_server.rsindex 42600a3a16..d7b9828438 100644--- a/rust/cloud-storage/document_cognition_service/src/bin/mcp_server.rs+++ b/rust/cloud-storage/document_cognition_service/src/bin/mcp_server.rs@@ -47,6 +47,7 @@ use sync_service_client::SyncServiceClient;env_var!(struct McpEnvVars {DatabaseUrl,+ EmailScheduledQueue,DocumentStorageServiceUrl,SyncServiceUrl,SyncServiceAuthKey,@@ -102,6 +103,9 @@ async fn main() -> anyhow::Result<()> {let macro_env = macro_env::Environment::new_or_prod();let aws_config = macro_aws_config::get_macro_aws_config().await;+ let queue_aws_client = aws_sdk_sqs::Client::new(&aws_config);+ let sqs_client = sqs_client::SQS::new(queue_aws_client)+ .email_scheduled_queue(env_vars.email_scheduled_queue.as_ref());let secretsmanager_client = secretsmanager_client::SecretsManager::new(aws_sdk_secretsmanager::Client::new(&aws_config),@@ -240,7 +244,7 @@ async fn main() -> anyhow::Result<()> {Arc::new(EmailServiceImpl::new(EmailPgRepo::new(db.clone()),FrecencyQueryServiceImpl::new(FrecencyPgStorage::new(db.clone())),- email::domain::ports::NoOpEnqueuer,+ sqs_client.clone(),0,)),Arc::new(email::domain::ports::NoOpGmailTokenProvider),diff --git a/rust/cloud-storage/document_cognition_service/src/config.rs b/rust/cloud-storage/document_cognition_service/src/config.rsindex bbe541e90f..8136f205e4 100644--- a/rust/cloud-storage/document_cognition_service/src/config.rs+++ b/rust/cloud-storage/document_cognition_service/src/config.rs@@ -26,6 +26,8 @@ pub struct Config {pub document_text_extractor_queue: String,/// The sqs queue to send chat delete jobspub chat_delete_queue: String,+ /// The sqs queue to enqueue outbound email sends+ pub email_scheduled_queue: String,/// The sqs queue to send notifications topub notification_queue: String,pub search_event_queue: String,@@ -59,6 +61,7 @@ env_var!(pub DocumentStorageBucket,pub DocumentTextExtractorQueue,pub ChatDeleteQueue,+ pub EmailScheduledQueue,pub NotificationQueue,pub DocumentStorageServiceUrl,pub SearchEventQueue,@@ -105,6 +108,7 @@ impl Config {document_storage_bucket,document_text_extractor_queue,chat_delete_queue,+ email_scheduled_queue,notification_queue,document_storage_service_url,search_event_queue,@@ -131,6 +135,7 @@ impl Config {document_storage_service_url: document_storage_service_url.to_string(),document_text_extractor_queue: document_text_extractor_queue.to_string(),chat_delete_queue: chat_delete_queue.to_string(),+ email_scheduled_queue: email_scheduled_queue.to_string(),notification_queue: notification_queue.to_string(),search_event_queue: search_event_queue.to_string(),sync_service_auth_key: sync_service_auth_key.to_string(),@@ -163,6 +168,7 @@ impl Config {document_storage_service_url: Default::default(),document_text_extractor_queue: Default::default(),chat_delete_queue: Default::default(),+ email_scheduled_queue: Default::default(),notification_queue: Default::default(),search_event_queue: Default::default(),sync_service_url: Default::default(),diff --git a/rust/cloud-storage/document_cognition_service/src/main.rs b/rust/cloud-storage/document_cognition_service/src/main.rsindex 98e21f33f4..a8a5a78e8f 100644--- a/rust/cloud-storage/document_cognition_service/src/main.rs+++ b/rust/cloud-storage/document_cognition_service/src/main.rs@@ -79,6 +79,7 @@ async fn main() -> anyhow::Result<()> {let sqs_client = sqs_client::SQS::new(queue_aws_client).document_text_extractor_queue(&config.document_text_extractor_queue).chat_delete_queue(&config.chat_delete_queue)+ .email_scheduled_queue(&config.email_scheduled_queue).search_event_queue(&config.search_event_queue);let secretsmanager_client = secretsmanager_client::SecretsManager::new(@@ -280,7 +281,7 @@ async fn main() -> anyhow::Result<()> {Arc::new(EmailServiceImpl::new(EmailPgRepo::new(db.clone()),FrecencyQueryServiceImpl::new(FrecencyPgStorage::new(db.clone())),- email::domain::ports::NoOpEnqueuer,+ sqs_client.clone(),0,)),Arc::new(email::domain::ports::NoOpGmailTokenProvider),diff --git a/rust/cloud-storage/memory/Cargo.toml b/rust/cloud-storage/memory/Cargo.tomlindex 484a16b80d..3a3c597df0 100644--- a/rust/cloud-storage/memory/Cargo.toml+++ b/rust/cloud-storage/memory/Cargo.toml@@ -20,6 +20,7 @@ sqlx = { workspace = true }tokio = { workspace = true }anyhow = { workspace = true }axum = { workspace = true }+aws-sdk-sqs = { workspace = true }model_user = { path = "../model_user", features = ["axum"] }tracing = { workspace = true }utoipa = { workspace = true }@@ -43,6 +44,7 @@ readonly_pool = { path = "../readonly_pool" }soup = { path = "../soup", features = ["all"] }properties = { path = "../properties" }macro_aws_config = { path = "../macro_aws_config" }+sqs_client = { path = "../sqs_client", default-features = false, features = ["email", "gmail"] }macro_db_migrator = { path = "../macro_db_migrator" }diff --git a/rust/cloud-storage/memory/src/context.rs b/rust/cloud-storage/memory/src/context.rsindex ec0da8aafb..2253de4ae1 100644--- a/rust/cloud-storage/memory/src/context.rs+++ b/rust/cloud-storage/memory/src/context.rs@@ -33,6 +33,7 @@ use sync_service_client::SyncServiceClient;/// `SEARCH_SERVICE_URL`, `EMAIL_SERVICE_URL`, `SYNC_SERVICE_URL`,/// `DOCUMENT_COGNITION_SERVICE_URL`, `STATIC_FILE_SERVICE_URL`,/// `DOCUMENT_STORAGE_BUCKET`, `DOCX_DOCUMENT_UPLOAD_BUCKET`,+/// `EMAIL_SCHEDULED_QUEUE`,/// `DOCUMENT_STORAGE_SERVICE_CLOUDFRONT_DISTRIBUTION_URL`,/// `DOCUMENT_STORAGE_SERVICE_CLOUDFRONT_SIGNER_PUBLIC_KEY_ID`,/// `DOCUMENT_STORAGE_SERVICE_CLOUDFRONT_SIGNER_PRIVATE_KEY_SECRET_NAME`@@ -49,10 +50,14 @@ pub async fn build_tool_service_context(pool: sqlx::PgPool) -> anyhow::Result<Tostd::env::var("LEXICAL_SERVICE_URL").unwrap_or_else(|_| "http://localhost:8096".into());let doc_bucket = std::env::var("DOCUMENT_STORAGE_BUCKET")?;let docx_bucket = std::env::var("DOCX_DOCUMENT_UPLOAD_BUCKET")?;+ let email_scheduled_queue = std::env::var("EMAIL_SCHEDULED_QUEUE")?;let cf_dist_url = std::env::var("DOCUMENT_STORAGE_SERVICE_CLOUDFRONT_DISTRIBUTION_URL")?;let cf_key_id = std::env::var("DOCUMENT_STORAGE_SERVICE_CLOUDFRONT_SIGNER_PUBLIC_KEY_ID")?;let cf_private_key =std::env::var("DOCUMENT_STORAGE_SERVICE_CLOUDFRONT_SIGNER_PRIVATE_KEY_SECRET_NAME")?;+ let aws_config = macro_aws_config::get_macro_aws_config().await;+ let sqs_client = sqs_client::SQS::new(aws_sdk_sqs::Client::new(&aws_config))+ .email_scheduled_queue(&email_scheduled_queue);// Service clientslet dss_client = Arc::new(DocumentStorageServiceClient::new(@@ -151,7 +156,7 @@ pub async fn build_tool_service_context(pool: sqlx::PgPool) -> anyhow::Result<ToArc::new(EmailServiceImpl::new(EmailPgRepo::new(pool.clone()),FrecencyQueryServiceImpl::new(FrecencyPgStorage::new(pool.clone())),- email::domain::ports::NoOpEnqueuer,+ sqs_client,0,)),Arc::new(email::domain::ports::NoOpGmailTokenProvider),