Skip to main content

multicast_codemode/
service.rs

1use async_trait::async_trait;
2use serde_json::Value;
3
4use crate::{CodeModeRunOptions, ExecutionState, SearchOutput, Snippet};
5
6/// Send-safe lifecycle boundary used by transports and native actor handles.
7#[async_trait]
8#[allow(
9    clippy::double_must_use,
10    reason = "async_trait annotates generated futures"
11)]
12pub trait CodeModeService: Send + Sync {
13    /// Installs protected host-defined workflows in the shared composition catalog.
14    async fn install_workflows(
15        &self,
16        _definitions: std::collections::BTreeMap<String, crate::WorkflowDefinition>,
17    ) -> Result<(), String> {
18        if _definitions.is_empty() {
19            Ok(())
20        } else {
21            Err("This host does not support callable workflow definitions".into())
22        }
23    }
24    /// Persists an idle execution without starting effects, so a host can bind it
25    /// to a durable delivery before calling `recover`.
26    async fn prepare(&self, _code: String) -> Result<ExecutionState, String> {
27        Err("This host does not support prepared execution".into())
28    }
29
30    /// Recovers interrupted running work without duplicating an active pass.
31    /// Hosts with independent job workers may return their current snapshot.
32    async fn recover(
33        &self,
34        execution_id: String,
35        _options: CodeModeRunOptions,
36    ) -> Result<ExecutionState, String> {
37        self.execution(execution_id).await
38    }
39    /// Whether this host implements retained asynchronous execution and detached approval.
40    /// Task-capable hosts must implement both `execute_retained` and `approve_detached`.
41    fn supports_retained_execution(&self) -> bool {
42        false
43    }
44
45    /// Commits an approval before returning and drives its continuation independently.
46    async fn approve_detached(
47        &self,
48        _execution_id: String,
49        _seq: u64,
50        _options: CodeModeRunOptions,
51    ) -> Result<ExecutionState, String> {
52        Err("This host does not support detached approval".into())
53    }
54
55    /// Starts work retained for the supplied duration, returning before driving it.
56    async fn execute_retained(
57        &self,
58        _code: String,
59        _retention_ms: u64,
60        _options: CodeModeRunOptions,
61    ) -> Result<ExecutionState, String> {
62        Err("This host does not support retained asynchronous execution".into())
63    }
64
65    /// Searches current connector methods and saved snippets.
66    async fn search(&self, query: String) -> Result<SearchOutput, String>;
67
68    /// Starts an execution and returns its durable running state.
69    async fn execute(
70        &self,
71        code: String,
72        options: CodeModeRunOptions,
73    ) -> Result<ExecutionState, String>;
74
75    /// Returns one bounded execution snapshot by identifier.
76    ///
77    /// Oversized values remain artifact references so transports can return the
78    /// snapshot before retrieving a selected artifact.
79    async fn execution(&self, execution_id: String) -> Result<ExecutionState, String>;
80
81    /// Restarts interrupted running or recovery-paused work with current authority.
82    /// Returns the committed running state before driving its pass independently.
83    /// Paused approvals must be decided through `approve` or `reject`.
84    async fn resume(
85        &self,
86        _execution_id: String,
87        _options: CodeModeRunOptions,
88    ) -> Result<ExecutionState, String> {
89        Err("This host does not support resuming interrupted executions".into())
90    }
91
92    /// Returns one artifact owned by an execution.
93    async fn artifact(&self, execution_id: String, artifact_id: String) -> Result<Value, String>;
94
95    /// Approves a pending action and drives the next replay pass.
96    async fn approve(
97        &self,
98        execution_id: String,
99        seq: u64,
100        options: CodeModeRunOptions,
101    ) -> Result<ExecutionState, String>;
102
103    /// Rejects a pending action.
104    async fn reject(&self, execution_id: String, seq: u64) -> Result<ExecutionState, String>;
105
106    /// Cancels a running or paused execution.
107    async fn cancel(&self, execution_id: String) -> Result<ExecutionState, String>;
108
109    /// Saves a completed execution as a named snippet.
110    async fn save_snippet(
111        &self,
112        _name: String,
113        _description: String,
114        _execution_id: String,
115        _input_schema: Option<Value>,
116    ) -> Result<Snippet, String> {
117        Err("This host does not support saving snippets".into())
118    }
119
120    /// Publishes callable source without invoking tools or requiring a completed execution.
121    async fn publish_snippet(
122        &self,
123        _name: String,
124        _description: String,
125        _code: String,
126        _input_schema: Option<Value>,
127    ) -> Result<Snippet, String> {
128        Err("This host does not support publishing snippets".into())
129    }
130
131    /// Lists saved snippets in stable name order.
132    async fn snippets(&self) -> Result<Vec<Snippet>, String> {
133        Err("This host does not support listing snippets".into())
134    }
135
136    /// Deletes one saved snippet, returning whether it existed.
137    async fn delete_snippet(&self, _name: String) -> Result<bool, String> {
138        Err("This host does not support deleting snippets".into())
139    }
140}