Skip to main content

meerkat_runtime/
service_ext.rs

1//! SessionServiceRuntimeExt — v9 runtime extension for SessionService.
2//!
3//! This trait extends the existing SessionService with runtime-specific
4//! operations. It lives in meerkat-runtime (NOT in core) to maintain
5//! the separation: core owns SessionService, runtime owns runtime extensions.
6
7use meerkat_core::lifecycle::InputId;
8use meerkat_core::types::SessionId;
9
10use crate::accept::AcceptOutcome;
11use crate::input::Input;
12use crate::input_state::InputState;
13use crate::runtime_state::RuntimeState;
14use crate::traits::{ResetReport, RetireReport, RuntimeDriverError};
15
16/// Runtime mode for a session service instance.
17///
18/// This branch is runtime-backed only. All sessions use v9 runtime.
19#[derive(Debug, Clone, Copy, PartialEq, Eq)]
20pub enum RuntimeMode {
21    /// Full v9 runtime-backed mode.
22    V9Compliant,
23}
24
25/// v9 runtime extensions for SessionService.
26///
27/// Surfaces query this to decide whether to expose v9 runtime methods.
28/// Legacy-mode surfaces MUST NOT advertise v9 capabilities.
29#[cfg_attr(not(target_arch = "wasm32"), async_trait::async_trait)]
30#[cfg_attr(target_arch = "wasm32", async_trait::async_trait(?Send))]
31pub trait SessionServiceRuntimeExt: Send + Sync {
32    /// Get the runtime mode.
33    fn runtime_mode(&self) -> RuntimeMode;
34
35    /// Accept an input for a session.
36    async fn accept_input(
37        &self,
38        session_id: &SessionId,
39        input: Input,
40    ) -> Result<AcceptOutcome, RuntimeDriverError>;
41
42    /// Get the runtime state for a session.
43    async fn runtime_state(
44        &self,
45        session_id: &SessionId,
46    ) -> Result<RuntimeState, RuntimeDriverError>;
47
48    /// Retire a session's runtime.
49    async fn retire_runtime(
50        &self,
51        session_id: &SessionId,
52    ) -> Result<RetireReport, RuntimeDriverError>;
53
54    /// Reset a session's runtime.
55    async fn reset_runtime(
56        &self,
57        session_id: &SessionId,
58    ) -> Result<ResetReport, RuntimeDriverError>;
59
60    /// Get the state of a specific input.
61    async fn input_state(
62        &self,
63        session_id: &SessionId,
64        input_id: &InputId,
65    ) -> Result<Option<InputState>, RuntimeDriverError>;
66
67    /// List all active (non-terminal) inputs for a session.
68    async fn list_active_inputs(
69        &self,
70        session_id: &SessionId,
71    ) -> Result<Vec<InputId>, RuntimeDriverError>;
72}
73
74#[cfg(test)]
75mod tests {
76    use super::*;
77
78    // Verify trait is object-safe
79    fn _assert_object_safe(_: &dyn SessionServiceRuntimeExt) {}
80
81    #[test]
82    fn runtime_mode_equality() {
83        assert_eq!(RuntimeMode::V9Compliant, RuntimeMode::V9Compliant);
84    }
85}