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::completion::CompletionHandle;
12use crate::input::Input;
13use crate::input_state::InputState;
14use crate::runtime_state::RuntimeState;
15use crate::traits::{ResetReport, RetireReport, RuntimeDriverError};
16
17/// Runtime mode for a session service instance.
18///
19/// This branch is runtime-backed only. All sessions use v9 runtime.
20#[derive(Debug, Clone, Copy, PartialEq, Eq)]
21pub enum RuntimeMode {
22    /// Full v9 runtime-backed mode.
23    V9Compliant,
24}
25
26/// v9 runtime extensions for SessionService.
27///
28/// Surfaces query this to decide whether to expose v9 runtime methods.
29/// Legacy-mode surfaces MUST NOT advertise v9 capabilities.
30#[cfg_attr(not(target_arch = "wasm32"), async_trait::async_trait)]
31#[cfg_attr(target_arch = "wasm32", async_trait::async_trait(?Send))]
32pub trait SessionServiceRuntimeExt: Send + Sync {
33    /// Get the runtime mode.
34    fn runtime_mode(&self) -> RuntimeMode;
35
36    /// Accept an input for a session.
37    async fn accept_input(
38        &self,
39        session_id: &SessionId,
40        input: Input,
41    ) -> Result<AcceptOutcome, RuntimeDriverError>;
42
43    /// Accept an input and optionally return a completion handle that resolves
44    /// when the admitted work reaches a terminal runtime outcome.
45    async fn accept_input_with_completion(
46        &self,
47        session_id: &SessionId,
48        input: Input,
49    ) -> Result<(AcceptOutcome, Option<CompletionHandle>), RuntimeDriverError>;
50
51    /// Get the runtime state for a session.
52    async fn runtime_state(
53        &self,
54        session_id: &SessionId,
55    ) -> Result<RuntimeState, RuntimeDriverError>;
56
57    /// Retire a session's runtime.
58    async fn retire_runtime(
59        &self,
60        session_id: &SessionId,
61    ) -> Result<RetireReport, RuntimeDriverError>;
62
63    /// Reset a session's runtime.
64    async fn reset_runtime(
65        &self,
66        session_id: &SessionId,
67    ) -> Result<ResetReport, RuntimeDriverError>;
68
69    /// Get the state of a specific input.
70    async fn input_state(
71        &self,
72        session_id: &SessionId,
73        input_id: &InputId,
74    ) -> Result<Option<InputState>, RuntimeDriverError>;
75
76    /// List all active (non-terminal) inputs for a session.
77    async fn list_active_inputs(
78        &self,
79        session_id: &SessionId,
80    ) -> Result<Vec<InputId>, RuntimeDriverError>;
81}
82
83#[cfg(test)]
84mod tests {
85    use super::*;
86
87    // Verify trait is object-safe
88    fn _assert_object_safe(_: &dyn SessionServiceRuntimeExt) {}
89
90    #[test]
91    fn runtime_mode_equality() {
92        assert_eq!(RuntimeMode::V9Compliant, RuntimeMode::V9Compliant);
93    }
94}