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(calendar): point agent calendar tools at calendar_service (#6747)

gbirman83069ac20069
diff --git a/crates/ai_tools/src/build_context.rs b/crates/ai_tools/src/build_context.rs
index c816565a83..8a30f55d18 100644
--- a/crates/ai_tools/src/build_context.rs
+++ b/crates/ai_tools/src/build_context.rs
@@ -34,8 +34,8 @@ use lexical_client::LexicalClient;
use macro_env::Environment;
use macro_env_var::{env_var, maybe_env_var};
use macro_service_urls::{
- AiEditingWorkerUrl, ConnectionGatewayUrl, DocumentStorageServiceUrl, EmailServiceUrl,
- LexicalServiceUrl, SyncServiceUrl,
+ AiEditingWorkerUrl, CalendarServiceUrl, ConnectionGatewayUrl, DocumentStorageServiceUrl,
+ EmailServiceUrl, LexicalServiceUrl, SyncServiceUrl,
};
use notification::domain::service::{NotificationReaderService, PlatformArnConfig};
use notification::outbound::queue::SqsQueue;
@@ -113,6 +113,7 @@ pub async fn build_tool_service_context_from_env(
let document_storage_service_url = DocumentStorageServiceUrl::new()?.to_string();
let sync_service_url = SyncServiceUrl::new()?.to_string();
let email_service_url = EmailServiceUrl::new()?.to_string();
+ let calendar_service_url = CalendarServiceUrl::new()?.to_string();
let lexical_service_url = LexicalServiceUrl::new()?.to_string();
let ai_editing_worker_url = AiEditingWorkerUrl::new()?.to_string();
let connection_gateway_url = ConnectionGatewayUrl::new()?.to_string();
@@ -349,7 +350,7 @@ pub async fn build_tool_service_context_from_env(
let calendar_tool_context = crate::tool_context::build_calendar_tool_context(
pool.clone(),
- email_service_url,
+ calendar_service_url,
env.internal_api_key.to_string(),
);
diff --git a/crates/ai_tools/src/tool_context.rs b/crates/ai_tools/src/tool_context.rs
index 33c4878a5a..059929c2ed 100644
--- a/crates/ai_tools/src/tool_context.rs
+++ b/crates/ai_tools/src/tool_context.rs
@@ -337,29 +337,29 @@ pub type ToolCalendarReadService = calendar_events::domain::service::CalendarSer
>;
/// Type alias for the calendar mutation client used by AI tools. Mutations
-/// call the email service — the calendar write authority holding the Google
+/// call the calendar service — the calendar write authority holding the Google
/// client, token minting, and request gate — with internal auth on behalf
/// of the requesting user, so tool-driven edits behave identically to
/// UI-driven ones.
pub type ToolCalendarMutationService =
- calendar_events::outbound::email_service_mutations::EmailServiceCalendarMutations;
+ calendar_events::outbound::calendar_service_mutations::CalendarServiceMutations;
/// Type alias for the calendar AI tool context.
pub type ToolCalendarToolContext =
CalendarToolContext<ToolCalendarMutationService, ToolCalendarReadService>;
/// Build the calendar AI tool context: reads query the local occurrence
-/// projections from `pool`; mutations call the email service at
-/// `email_service_url` with the shared internal API key.
+/// projections from `pool`; mutations call the calendar service at
+/// `calendar_service_url` with the shared internal API key.
pub fn build_calendar_tool_context(
pool: sqlx::PgPool,
- email_service_url: String,
+ calendar_service_url: String,
internal_api_key: String,
) -> ToolCalendarToolContext {
CalendarToolContext::new(
Arc::new(
- calendar_events::outbound::email_service_mutations::EmailServiceCalendarMutations::new(
- email_service_url,
+ calendar_events::outbound::calendar_service_mutations::CalendarServiceMutations::new(
+ calendar_service_url,
internal_api_key,
),
),
diff --git a/crates/calendar_events/src/outbound/email_service_mutations.rs b/crates/calendar_events/src/outbound/calendar_service_mutations.rs
similarity index 84%
rename from crates/calendar_events/src/outbound/email_service_mutations.rs
rename to crates/calendar_events/src/outbound/calendar_service_mutations.rs
index f022fb11e9..ce186c53ed 100644
--- a/crates/calendar_events/src/outbound/email_service_mutations.rs
+++ b/crates/calendar_events/src/outbound/calendar_service_mutations.rs
@@ -1,11 +1,16 @@
-//! Email-service HTTP adapter for the calendar mutation port.
+//! Calendar-service HTTP adapter for the calendar mutation port.
//!
-//! The email service is the calendar write authority: it holds the Google
+//! The calendar service is the calendar write authority: it holds the Google
//! provider client, token minting, and the per-inbox request gate. Hosts
//! that expose calendar mutations without those dependencies (the AI tool
//! hosts) implement [`CalendarMutationService`] through this client, so
//! every mutation flows through the same routes, validation, and error
//! mapping as user-initiated ones.
+//!
+//! The base URL points at the calendar service's `/calendar` gateway prefix,
+//! so the request paths here are exactly the routes
+//! [`crate::inbound::mutation_router::calendar_mutation_router`] serves
+//! (`/calendars`, `/events`, `/events/{id}`, `/events/{id}/rsvp`).
#[cfg(all(test, feature = "inbound"))]
mod test;
@@ -30,16 +35,16 @@ const INTERNAL_API_KEY_HEADER: &str = "x-internal-auth-key";
/// Header carrying the acting Macro user for internal authorization.
const INTERNAL_MACRO_USER_ID_HEADER: &str = "x-internal-macro-user-id";
-/// Calendar mutation client calling the email service with internal
+/// Calendar mutation client calling the calendar service with internal
/// authorization on behalf of the requesting user.
-pub struct EmailServiceCalendarMutations {
+pub struct CalendarServiceMutations {
base_url: String,
internal_api_key: String,
http: reqwest::Client,
}
-impl EmailServiceCalendarMutations {
- /// Construct the client for the email service at `base_url`.
+impl CalendarServiceMutations {
+ /// Construct the client for the calendar service at `base_url`.
pub fn new(base_url: String, internal_api_key: String) -> Self {
Self {
base_url: base_url.trim_end_matches('/').to_string(),
@@ -117,7 +122,7 @@ fn error_from_response(status: StatusCode, body: Option<String>) -> CalendarMuta
return fallback_error(
status,
format!(
- "the email service calendar API returned status {status} with no mutation \
+ "the calendar service API returned status {status} with no mutation \
error body"
),
);
@@ -265,7 +270,7 @@ fn rsvp_body(
}
}
-impl CalendarMutationService for EmailServiceCalendarMutations {
+impl CalendarMutationService for CalendarServiceMutations {
#[tracing::instrument(skip(self, requester_id, draft), err)]
async fn create_event(
&self,
@@ -275,7 +280,7 @@ impl CalendarMutationService for EmailServiceCalendarMutations {
draft: CalendarEventDraft,
) -> Result<CalendarEvent, CalendarMutationError> {
self.event_from(
- self.request(reqwest::Method::POST, "/calendar/events", requester_id)
+ self.request(reqwest::Method::POST, "/events", requester_id)
.json(&create_body(email_link_id, calendar_id, &draft)),
)
.await
@@ -286,7 +291,7 @@ impl CalendarMutationService for EmailServiceCalendarMutations {
&self,
requester_id: &str,
) -> Result<Vec<VisibleCalendar>, CalendarMutationError> {
- self.send(self.request(reqwest::Method::GET, "/calendar/calendars", requester_id))
+ self.send(self.request(reqwest::Method::GET, "/calendars", requester_id))
.await?
.json::<ListCalendarsWire>()
.await
@@ -310,7 +315,7 @@ impl CalendarMutationService for EmailServiceCalendarMutations {
self.event_from(
self.request(
reqwest::Method::PATCH,
- &format!("/calendar/events/{event_id}"),
+ &format!("/events/{event_id}"),
requester_id,
)
.json(&update_body(calendar_id, &patch, &scope)),
@@ -329,7 +334,7 @@ impl CalendarMutationService for EmailServiceCalendarMutations {
self.send(
self.request(
reqwest::Method::DELETE,
- &format!("/calendar/events/{event_id}"),
+ &format!("/events/{event_id}"),
requester_id,
)
.query(&delete_query(calendar_id, &scope)),
@@ -350,7 +355,7 @@ impl CalendarMutationService for EmailServiceCalendarMutations {
self.event_from(
self.request(
reqwest::Method::PUT,
- &format!("/calendar/events/{event_id}/rsvp"),
+ &format!("/events/{event_id}/rsvp"),
requester_id,
)
.json(&rsvp_body(calendar_id, response, &scope)),
@@ -358,18 +363,25 @@ impl CalendarMutationService for EmailServiceCalendarMutations {
.await
}
- #[tracing::instrument(skip(self, requester_id), err)]
+ /// Not reachable over this transport. Disconnecting a calendar is part of
+ /// an inbox's link lifecycle, served by the email service at
+ /// `DELETE /email/links/{link_id}/calendar` (see
+ /// `email_service::api::email::links::calendar`) — a route the calendar
+ /// service does not mount, and one that stays on the email service after
+ /// the calendar cutover. The AI-tool hosts that construct this client
+ /// never disconnect calendars (the toolset exposes no such tool), so this
+ /// arm exists only to satisfy [`CalendarMutationService`]; issuing the
+ /// request against the calendar service base would 404. It returns a
+ /// domain error instead of firing a request that cannot succeed.
async fn disconnect_calendar(
&self,
- requester_id: &str,
- email_link_id: Uuid,
+ _requester_id: &str,
+ _email_link_id: Uuid,
) -> Result<(), CalendarMutationError> {
- self.send(self.request(
- reqwest::Method::DELETE,
- &format!("/email/links/{email_link_id}/calendar"),
- requester_id,
+ Err(CalendarMutationError::InvalidInput(
+ "disconnecting a calendar is not available through the calendar-service mutation \
+ client; it is served by the email service's inbox link lifecycle"
+ .to_string(),
))
- .await
- .map(|_| ())
}
}
diff --git a/crates/calendar_events/src/outbound/email_service_mutations/test.rs b/crates/calendar_events/src/outbound/calendar_service_mutations/test.rs
similarity index 100%
rename from crates/calendar_events/src/outbound/email_service_mutations/test.rs
rename to crates/calendar_events/src/outbound/calendar_service_mutations/test.rs
diff --git a/crates/calendar_events/src/outbound/mod.rs b/crates/calendar_events/src/outbound/mod.rs
index 2874f96d3d..ef119604a0 100644
--- a/crates/calendar_events/src/outbound/mod.rs
+++ b/crates/calendar_events/src/outbound/mod.rs
@@ -1,8 +1,8 @@
//! Outbound calendar adapters.
-/// Email-service HTTP adapter for the mutation port.
+/// Calendar-service HTTP adapter for the mutation port.
#[cfg(feature = "mutation-client")]
-pub mod email_service_mutations;
+pub mod calendar_service_mutations;
/// Google Calendar API adapter.
#[cfg(feature = "google")]
pub mod google;
diff --git a/crates/macro_service_urls/src/lib.rs b/crates/macro_service_urls/src/lib.rs
index 2f1fa04129..ebc1f3a2ea 100644
--- a/crates/macro_service_urls/src/lib.rs
+++ b/crates/macro_service_urls/src/lib.rs
@@ -593,6 +593,14 @@ service_url! {
dev: "https://dev-gateway.macro.com/email",
prod: "https://gateway.macro.com/email",
},
+ /// Calendar service API URL. The calendar write authority once
+ /// `calendar_service` owns provider mutations; its API is mounted at
+ /// the root and under the `/calendar` gateway prefix.
+ pub CalendarServiceUrl {
+ local: "http://localhost:8088",
+ dev: "https://dev-gateway.macro.com/calendar",
+ prod: "https://gateway.macro.com/calendar",
+ },
/// Image proxy service API URL.
pub ImageProxyServiceUrl {
local: "http://localhost:8097",
diff --git a/crates/macro_service_urls/src/test.rs b/crates/macro_service_urls/src/test.rs
index 35cf15862c..15da7a1dbb 100644
--- a/crates/macro_service_urls/src/test.rs
+++ b/crates/macro_service_urls/src/test.rs
@@ -509,6 +509,10 @@ fn exported_service_urls_match_local_values() {
service_urls.email_service_url.as_ref(),
"http://localhost:8087"
);
+ assert_eq!(
+ service_urls.calendar_service_url.as_ref(),
+ "http://localhost:8088"
+ );
assert_eq!(
service_urls.image_proxy_service_url.as_ref(),
"http://localhost:8097",
@@ -591,6 +595,10 @@ fn exported_service_urls_match_dev_values() {
service_urls.email_service_url.as_ref(),
"https://dev-gateway.macro.com/email",
);
+ assert_eq!(
+ service_urls.calendar_service_url.as_ref(),
+ "https://dev-gateway.macro.com/calendar",
+ );
assert_eq!(
service_urls.image_proxy_service_url.as_ref(),
"https://dev-gateway.macro.com/image-proxy",
@@ -670,6 +678,10 @@ fn exported_service_urls_match_prod_values() {
service_urls.email_service_url.as_ref(),
"https://gateway.macro.com/email",
);
+ assert_eq!(
+ service_urls.calendar_service_url.as_ref(),
+ "https://gateway.macro.com/calendar",
+ );
assert_eq!(
service_urls.image_proxy_service_url.as_ref(),
"https://gateway.macro.com/image-proxy",