use std::path::PathBuf;
use std::sync::Arc;
use astrid_core::SessionId;
use astrid_events::EventBus;
use astrid_storage::ScopedKvStore;
use uuid::Uuid;
use astrid_core::session_token::SessionToken;
use crate::capsule::CapsuleId;
use crate::registry::CapsuleRegistry;
pub struct CapsuleContext {
pub workspace_root: PathBuf,
pub global_root: Option<PathBuf>,
pub kv: ScopedKvStore,
pub event_bus: Arc<EventBus>,
pub cli_socket_listener: Option<Arc<tokio::sync::Mutex<tokio::net::UnixListener>>>,
pub capsule_registry: Option<Arc<tokio::sync::RwLock<CapsuleRegistry>>>,
pub session_token: Option<Arc<SessionToken>>,
pub allowance_store: Option<Arc<astrid_approval::AllowanceStore>>,
pub identity_store: Option<Arc<dyn astrid_storage::IdentityStore>>,
}
impl CapsuleContext {
#[must_use]
pub fn new(
workspace_root: PathBuf,
global_root: Option<PathBuf>,
kv: ScopedKvStore,
event_bus: Arc<EventBus>,
cli_socket_listener: Option<Arc<tokio::sync::Mutex<tokio::net::UnixListener>>>,
) -> Self {
Self {
workspace_root,
global_root,
kv,
event_bus,
cli_socket_listener,
capsule_registry: None,
session_token: None,
allowance_store: None,
identity_store: None,
}
}
#[must_use]
pub fn with_session_token(mut self, token: Arc<SessionToken>) -> Self {
self.session_token = Some(token);
self
}
#[must_use]
pub fn with_registry(mut self, registry: Arc<tokio::sync::RwLock<CapsuleRegistry>>) -> Self {
self.capsule_registry = Some(registry);
self
}
#[must_use]
pub fn with_allowance_store(mut self, store: Arc<astrid_approval::AllowanceStore>) -> Self {
self.allowance_store = Some(store);
self
}
#[must_use]
pub fn with_identity_store(mut self, store: Arc<dyn astrid_storage::IdentityStore>) -> Self {
self.identity_store = Some(store);
self
}
}
#[derive(Debug, Clone)]
pub struct CapsuleToolContext {
pub capsule_id: CapsuleId,
pub workspace_root: PathBuf,
pub kv: ScopedKvStore,
pub session_id: Option<SessionId>,
pub user_id: Option<Uuid>,
}
impl CapsuleToolContext {
#[must_use]
pub fn new(capsule_id: CapsuleId, workspace_root: PathBuf, kv: ScopedKvStore) -> Self {
Self {
capsule_id,
workspace_root,
kv,
session_id: None,
user_id: None,
}
}
#[must_use]
pub fn with_session(mut self, session_id: SessionId) -> Self {
self.session_id = Some(session_id);
self
}
#[must_use]
pub fn with_user(mut self, user_id: Uuid) -> Self {
self.user_id = Some(user_id);
self
}
}