#[cfg(not(target_arch = "wasm32"))]
pub mod admission;
pub mod errors;
#[cfg(not(target_arch = "wasm32"))]
pub mod live_orchestration;
#[cfg(all(feature = "session-store", not(target_arch = "wasm32")))]
pub mod llm_reconfigure;
#[cfg(not(target_arch = "wasm32"))]
pub mod recovery;
#[cfg(not(target_arch = "wasm32"))]
pub mod runtime_state;
#[cfg(all(feature = "session-store", not(target_arch = "wasm32")))]
pub mod staged_promotion;
pub use errors::LiveOpenPrecheckError;
#[cfg(not(target_arch = "wasm32"))]
pub use runtime_state::{SessionInfo, SessionState};
#[cfg(all(feature = "session-store", not(target_arch = "wasm32")))]
mod inner {
use std::path::PathBuf;
use std::sync::{Arc, RwLock as StdRwLock};
use meerkat_client::LlmClient;
use meerkat_core::ConfigRuntime;
use meerkat_core::connection::RealmId;
use meerkat_runtime::MeerkatMachine;
use crate::service_factory::FactoryAgentBuilder;
use crate::session_runtime::admission::StagedCapacityAdmissions;
use crate::session_runtime::runtime_state::SkillIdentityRegistryState;
use crate::{PersistentSessionService, StagedSessionRegistry};
pub struct MeerkatSessionRuntime {
pub service: Arc<PersistentSessionService<FactoryAgentBuilder>>,
pub staged_sessions: Arc<StagedSessionRegistry>,
pub staged_capacity_admissions: StagedCapacityAdmissions,
pub runtime_adapter: Arc<MeerkatMachine>,
#[cfg(feature = "live")]
pub live_adapter_host: Arc<StdRwLock<Option<Arc<meerkat_live::LiveAdapterHost>>>>,
pub config_runtime: Arc<StdRwLock<Option<Arc<ConfigRuntime>>>>,
pub default_llm_client: Arc<StdRwLock<Option<Arc<dyn LlmClient>>>>,
pub realm_id: Arc<StdRwLock<Option<RealmId>>>,
pub instance_id: Arc<StdRwLock<Option<String>>>,
pub backend: Arc<StdRwLock<Option<String>>>,
pub skill_identity_registry: Arc<StdRwLock<SkillIdentityRegistryState>>,
pub skill_identity_context_root: Arc<StdRwLock<Option<PathBuf>>>,
pub skill_identity_user_root: Arc<StdRwLock<Option<PathBuf>>>,
}
impl MeerkatSessionRuntime {
pub fn config_runtime(&self) -> Option<Arc<ConfigRuntime>> {
self.config_runtime
.read()
.unwrap_or_else(std::sync::PoisonError::into_inner)
.clone()
}
pub fn set_config_runtime(&self, runtime: Arc<ConfigRuntime>) {
*self
.config_runtime
.write()
.unwrap_or_else(std::sync::PoisonError::into_inner) = Some(runtime);
}
pub fn realm_id(&self) -> Option<RealmId> {
self.realm_id
.read()
.unwrap_or_else(std::sync::PoisonError::into_inner)
.clone()
}
pub fn instance_id(&self) -> Option<String> {
self.instance_id
.read()
.unwrap_or_else(std::sync::PoisonError::into_inner)
.clone()
}
pub fn backend(&self) -> Option<String> {
self.backend
.read()
.unwrap_or_else(std::sync::PoisonError::into_inner)
.clone()
}
pub fn set_realm_context(
&self,
realm_id: Option<RealmId>,
instance_id: Option<String>,
backend: Option<String>,
) {
*self
.realm_id
.write()
.unwrap_or_else(std::sync::PoisonError::into_inner) = realm_id;
*self
.instance_id
.write()
.unwrap_or_else(std::sync::PoisonError::into_inner) = instance_id;
*self
.backend
.write()
.unwrap_or_else(std::sync::PoisonError::into_inner) = backend;
}
pub fn set_default_llm_client(&self, client: Option<Arc<dyn LlmClient>>) {
*self
.default_llm_client
.write()
.unwrap_or_else(std::sync::PoisonError::into_inner) = client;
}
pub fn default_llm_client(&self) -> Option<Arc<dyn LlmClient>> {
self.default_llm_client
.read()
.unwrap_or_else(std::sync::PoisonError::into_inner)
.clone()
}
#[cfg(feature = "live")]
pub fn set_live_adapter_host(&self, host: Arc<meerkat_live::LiveAdapterHost>) {
if let Ok(mut slot) = self.live_adapter_host.write() {
*slot = Some(host);
}
}
#[cfg(feature = "live")]
pub fn live_adapter_host(&self) -> Option<Arc<meerkat_live::LiveAdapterHost>> {
self.live_adapter_host
.read()
.ok()
.and_then(|guard| guard.clone())
}
pub fn skill_identity_registry(&self) -> meerkat_core::skills::SourceIdentityRegistry {
self.skill_identity_registry
.read()
.map(|state| state.registry.clone())
.unwrap_or_default()
}
pub fn set_skill_identity_registry(
&self,
registry: meerkat_core::skills::SourceIdentityRegistry,
) {
if let Ok(mut slot) = self.skill_identity_registry.write() {
slot.registry = registry;
}
}
pub fn set_skill_identity_registry_for_generation(
&self,
generation: u64,
registry: meerkat_core::skills::SourceIdentityRegistry,
) {
if let Ok(mut slot) = self.skill_identity_registry.write()
&& generation >= slot.generation
{
slot.generation = generation;
slot.registry = registry;
}
}
}
}
#[cfg(all(feature = "session-store", not(target_arch = "wasm32")))]
pub use inner::MeerkatSessionRuntime;
#[cfg(all(feature = "session-store", not(target_arch = "wasm32")))]
pub use builder::SessionRuntimeBuilder;
#[cfg(all(feature = "session-store", not(target_arch = "wasm32")))]
mod builder {
use std::collections::HashMap;
use std::path::PathBuf;
use std::sync::{Arc, Mutex as StdMutex, RwLock as StdRwLock};
use meerkat_client::LlmClient;
use meerkat_core::ConfigRuntime;
use meerkat_core::connection::RealmId;
use meerkat_core::skills::SourceIdentityRegistry;
use meerkat_runtime::MeerkatMachine;
use crate::service_factory::FactoryAgentBuilder;
use crate::session_runtime::admission::StagedCapacityAdmissions;
use crate::session_runtime::inner::MeerkatSessionRuntime;
use crate::session_runtime::runtime_state::SkillIdentityRegistryState;
use crate::{PersistentSessionService, StagedSessionRegistry};
pub struct SessionRuntimeBuilder {
service: Arc<PersistentSessionService<FactoryAgentBuilder>>,
staged_sessions: Arc<StagedSessionRegistry>,
staged_capacity_admissions: StagedCapacityAdmissions,
runtime_adapter: Arc<MeerkatMachine>,
#[cfg(feature = "live")]
live_adapter_host: Arc<StdRwLock<Option<Arc<meerkat_live::LiveAdapterHost>>>>,
config_runtime: Arc<StdRwLock<Option<Arc<ConfigRuntime>>>>,
default_llm_client: Arc<StdRwLock<Option<Arc<dyn LlmClient>>>>,
realm_id: Arc<StdRwLock<Option<RealmId>>>,
instance_id: Arc<StdRwLock<Option<String>>>,
backend: Arc<StdRwLock<Option<String>>>,
skill_identity_registry: Arc<StdRwLock<SkillIdentityRegistryState>>,
skill_identity_context_root: Arc<StdRwLock<Option<PathBuf>>>,
skill_identity_user_root: Arc<StdRwLock<Option<PathBuf>>>,
}
impl SessionRuntimeBuilder {
pub fn new(
service: Arc<PersistentSessionService<FactoryAgentBuilder>>,
staged_sessions: Arc<StagedSessionRegistry>,
runtime_adapter: Arc<MeerkatMachine>,
) -> Self {
Self {
service,
staged_sessions,
staged_capacity_admissions: Arc::new(StdMutex::new(HashMap::new())),
runtime_adapter,
#[cfg(feature = "live")]
live_adapter_host: Arc::new(StdRwLock::new(None)),
config_runtime: Arc::new(StdRwLock::new(None)),
default_llm_client: Arc::new(StdRwLock::new(None)),
realm_id: Arc::new(StdRwLock::new(None)),
instance_id: Arc::new(StdRwLock::new(None)),
backend: Arc::new(StdRwLock::new(None)),
skill_identity_registry: Arc::new(StdRwLock::new(
SkillIdentityRegistryState::default(),
)),
skill_identity_context_root: Arc::new(StdRwLock::new(None)),
skill_identity_user_root: Arc::new(StdRwLock::new(None)),
}
}
#[must_use]
pub fn with_staged_capacity_admissions(
mut self,
admissions: StagedCapacityAdmissions,
) -> Self {
self.staged_capacity_admissions = admissions;
self
}
#[cfg(feature = "live")]
#[must_use]
pub fn with_live_adapter_host_slot(
mut self,
slot: Arc<StdRwLock<Option<Arc<meerkat_live::LiveAdapterHost>>>>,
) -> Self {
self.live_adapter_host = slot;
self
}
#[cfg(feature = "live")]
#[must_use]
pub fn with_live_adapter_host(self, host: Arc<meerkat_live::LiveAdapterHost>) -> Self {
if let Ok(mut slot) = self.live_adapter_host.write() {
*slot = Some(host);
}
self
}
#[must_use]
pub fn with_config_runtime_slot(
mut self,
slot: Arc<StdRwLock<Option<Arc<ConfigRuntime>>>>,
) -> Self {
self.config_runtime = slot;
self
}
#[must_use]
pub fn with_config_runtime(self, runtime: Arc<ConfigRuntime>) -> Self {
if let Ok(mut slot) = self.config_runtime.write() {
*slot = Some(runtime);
}
self
}
#[must_use]
pub fn with_default_llm_client_slot(
mut self,
slot: Arc<StdRwLock<Option<Arc<dyn LlmClient>>>>,
) -> Self {
self.default_llm_client = slot;
self
}
#[must_use]
pub fn with_default_llm_client(self, client: Arc<dyn LlmClient>) -> Self {
if let Ok(mut slot) = self.default_llm_client.write() {
*slot = Some(client);
}
self
}
#[must_use]
pub fn with_realm_id(self, realm_id: RealmId) -> Self {
if let Ok(mut slot) = self.realm_id.write() {
*slot = Some(realm_id);
}
self
}
#[must_use]
pub fn with_instance_id(self, instance_id: String) -> Self {
if let Ok(mut slot) = self.instance_id.write() {
*slot = Some(instance_id);
}
self
}
#[must_use]
pub fn with_backend(self, backend: String) -> Self {
if let Ok(mut slot) = self.backend.write() {
*slot = Some(backend);
}
self
}
#[must_use]
pub fn with_realm_id_slot(mut self, slot: Arc<StdRwLock<Option<RealmId>>>) -> Self {
self.realm_id = slot;
self
}
#[must_use]
pub fn with_instance_id_slot(mut self, slot: Arc<StdRwLock<Option<String>>>) -> Self {
self.instance_id = slot;
self
}
#[must_use]
pub fn with_backend_slot(mut self, slot: Arc<StdRwLock<Option<String>>>) -> Self {
self.backend = slot;
self
}
#[must_use]
pub fn with_skill_identity_registry(self, registry: SourceIdentityRegistry) -> Self {
if let Ok(mut slot) = self.skill_identity_registry.write() {
slot.registry = registry;
}
self
}
#[must_use]
pub fn with_skill_identity_registry_slot(
mut self,
slot: Arc<StdRwLock<SkillIdentityRegistryState>>,
) -> Self {
self.skill_identity_registry = slot;
self
}
#[must_use]
pub fn with_skill_identity_context_root_slot(
mut self,
slot: Arc<StdRwLock<Option<PathBuf>>>,
) -> Self {
self.skill_identity_context_root = slot;
self
}
#[must_use]
pub fn with_skill_identity_context_root(self, path: PathBuf) -> Self {
if let Ok(mut slot) = self.skill_identity_context_root.write() {
*slot = Some(path);
}
self
}
#[must_use]
pub fn with_skill_identity_user_root_slot(
mut self,
slot: Arc<StdRwLock<Option<PathBuf>>>,
) -> Self {
self.skill_identity_user_root = slot;
self
}
#[must_use]
pub fn with_skill_identity_user_root(self, path: PathBuf) -> Self {
if let Ok(mut slot) = self.skill_identity_user_root.write() {
*slot = Some(path);
}
self
}
#[must_use]
pub fn build(self) -> MeerkatSessionRuntime {
MeerkatSessionRuntime {
service: self.service,
staged_sessions: self.staged_sessions,
staged_capacity_admissions: self.staged_capacity_admissions,
runtime_adapter: self.runtime_adapter,
#[cfg(feature = "live")]
live_adapter_host: self.live_adapter_host,
config_runtime: self.config_runtime,
default_llm_client: self.default_llm_client,
realm_id: self.realm_id,
instance_id: self.instance_id,
backend: self.backend,
skill_identity_registry: self.skill_identity_registry,
skill_identity_context_root: self.skill_identity_context_root,
skill_identity_user_root: self.skill_identity_user_root,
}
}
}
}