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
use agent_session::domain::search::AgentSessionSearchMetadataService;
use axum::extract::FromRef;
use calendar_events::domain::ports::CalendarEventLabelReader;
use entity_access::domain::service::EntityAccessServiceImpl;
use entity_access::outbound::PgAccessRepository;
use macro_authorization::{
MacroAuthJwtValidator, MacroAuthorizationServiceImpl, MacroAuthorizationState,
};
use opensearch_client::OpensearchClient;
use readonly_pool::ReadOnlyPool;
use std::sync::Arc;
/// Concrete entity-access service backing the team receipt extractor. Same
/// type the parent app constructs, so its `Arc` can be passed in directly.
pub type SearchEntityAccessService = EntityAccessServiceImpl<PgAccessRepository>;
/// Concrete authorization service backing search request authentication.
pub type SearchAuthorizationService = MacroAuthorizationServiceImpl<MacroAuthJwtValidator>;
/// Minimal state required by search handlers.
/// This can be extracted from any state that implements `FromRef<SearchHandlerState>`.
#[derive(Clone, FromRef)]
pub struct SearchHandlerState {
/// Read-only database connection for search queries
pub db: ReadOnlyPool,
/// OpenSearch client for full-text search
pub opensearch_client: Arc<OpensearchClient>,
/// Resolves the caller's team membership to mint CRM capability receipts.
pub entity_access_service: Arc<SearchEntityAccessService>,
/// Authorization state used to authenticate search requests.
pub authorization_state: MacroAuthorizationState<SearchAuthorizationService>,
/// Agent-session domain service used after the search layer resolves its
/// authorized session allowlist.
pub agent_session_search_metadata: Arc<dyn AgentSessionSearchMetadataService>,
/// Whether calendar events participate in search. Off in deployed
/// environments until the calendar index has been created and backfilled;
/// gating here covers every caller of the search API at once, the AI
/// search tools included.
pub calendar_search_enabled: bool,
/// Says whose calendar each event hit is on and what the caller is there,
/// by the rule every calendar reader shares.
pub calendar_event_labels: Arc<dyn CalendarEventLabelReader>,
}
impl SearchHandlerState {
/// Assemble the agent-session search use case from read-only adapters.
pub(crate) fn agent_session_search(
&self,
) -> crate::domain::agent_session::AgentSessionSearchService<
crate::outbound::agent_session::AgentSessionSearchMetadataSource,
> {
crate::domain::agent_session::AgentSessionSearchService(
crate::outbound::agent_session::AgentSessionSearchMetadataSource {
db: self.db.clone(),
service: self.agent_session_search_metadata.clone(),
},
)
}
}