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