Skip to main content

rootcx_types/
lib.rs

1use serde::{Deserialize, Serialize};
2use serde_json::Value as JsonValue;
3
4#[derive(Debug, Clone, Serialize, Deserialize)]
5pub struct OsStatus {
6    pub runtime: RuntimeStatus,
7    pub postgres: PostgresStatus,
8    pub forge: ForgeStatus,
9}
10
11impl OsStatus {
12    pub fn offline() -> Self {
13        Self {
14            runtime: RuntimeStatus { version: String::new(), state: ServiceState::Offline },
15            postgres: PostgresStatus { state: ServiceState::Offline, port: None, data_dir: None },
16            forge: ForgeStatus { state: ServiceState::Offline, port: None },
17        }
18    }
19}
20
21#[derive(Debug, Clone, Serialize, Deserialize)]
22pub struct ForgeStatus {
23    pub state: ServiceState,
24    pub port: Option<u16>,
25}
26
27#[derive(Debug, Clone, Serialize, Deserialize)]
28pub struct RuntimeStatus {
29    pub version: String,
30    pub state: ServiceState,
31}
32
33#[derive(Debug, Clone, Serialize, Deserialize)]
34pub struct PostgresStatus {
35    pub state: ServiceState,
36    pub port: Option<u16>,
37    pub data_dir: Option<String>,
38}
39
40#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
41#[serde(rename_all = "lowercase")]
42pub enum ServiceState {
43    Online,
44    Offline,
45    Starting,
46    Stopping,
47    Error,
48}
49
50#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Serialize, Deserialize)]
51#[serde(rename_all = "lowercase")]
52pub enum AppType {
53    #[default]
54    App,
55    Integration,
56    Agent,
57}
58
59#[derive(Debug, Clone, Serialize, Deserialize)]
60#[serde(rename_all = "camelCase")]
61pub struct ActionDefinition {
62    pub id: String,
63    pub name: String,
64    #[serde(default)]
65    pub description: String,
66    #[serde(default)]
67    pub input_schema: Option<JsonValue>,
68    #[serde(default)]
69    pub output_schema: Option<JsonValue>,
70}
71
72#[derive(Debug, Clone, Serialize, Deserialize)]
73#[serde(rename_all = "camelCase")]
74pub struct AppManifest {
75    pub app_id: String,
76    pub name: String,
77    #[serde(default = "default_version")]
78    pub version: String,
79    #[serde(default)]
80    pub description: String,
81    #[serde(default, rename = "type")]
82    pub app_type: AppType,
83    #[serde(default)]
84    pub permissions: Option<PermissionsContract>,
85    #[serde(default)]
86    pub data_contract: Vec<EntityContract>,
87    #[serde(default, skip_serializing_if = "Vec::is_empty")]
88    pub actions: Vec<ActionDefinition>,
89    #[serde(default, skip_serializing_if = "Option::is_none")]
90    pub config_schema: Option<JsonValue>,
91    #[serde(default, skip_serializing_if = "Option::is_none")]
92    pub user_auth: Option<JsonValue>,
93    #[serde(default, skip_serializing_if = "Vec::is_empty")]
94    pub webhooks: Vec<String>,
95    /// Free-form usage instructions surfaced to AI via list_integrations tool
96    #[serde(default, skip_serializing_if = "Option::is_none")]
97    pub instructions: Option<String>,
98    /// Trigger: auto-invoke this agent on entity events
99    #[serde(default, skip_serializing_if = "Option::is_none")]
100    pub trigger: Option<TriggerConfig>,
101    /// Declarative cron schedules synced on deploy
102    #[serde(default, skip_serializing_if = "Vec::is_empty")]
103    pub crons: Vec<CronDefinition>,
104    #[serde(default, skip_serializing_if = "Option::is_none")]
105    pub icon: Option<String>,
106    /// Public-access surface. Routes listed here bypass Identity. RPCs that
107    /// declare `scope` additionally require a share token whose context
108    /// matches the request body on the listed keys.
109    #[serde(default, skip_serializing_if = "Option::is_none")]
110    pub public: Option<PublicSurface>,
111}
112
113/// Declarative public-access surface for an app.
114///
115/// Anything listed here is reachable without an Authorization header.
116/// Anything **not** listed retains the default JWT-required behavior.
117///
118/// See `core/src/extensions/sharing/` for the runtime enforcement.
119#[derive(Debug, Clone, Default, Serialize, Deserialize)]
120#[serde(rename_all = "camelCase")]
121pub struct PublicSurface {
122    /// Custom RPCs exposed publicly. If `scope` is non-empty, the request
123    /// must carry a share token whose `context` matches the request body on
124    /// every listed key.
125    #[serde(default, skip_serializing_if = "Vec::is_empty")]
126    pub rpcs: Vec<PublicRpc>,
127    /// CRUD collections exposed publicly with the listed actions.
128    /// Allowed actions: "list", "read", "create", "update", "delete".
129    #[serde(default, skip_serializing_if = "Vec::is_empty")]
130    pub collections: Vec<PublicCollection>,
131}
132
133#[derive(Debug, Clone, Serialize, Deserialize)]
134#[serde(rename_all = "camelCase")]
135pub struct PublicRpc {
136    pub name: String,
137    /// Keys to enforce-match between the share token's `context` and the
138    /// request body. Empty `scope` means anonymous access (no share token
139    /// required). Non-empty means a share token IS required and the listed
140    /// keys MUST match exactly.
141    #[serde(default, skip_serializing_if = "Vec::is_empty")]
142    pub scope: Vec<String>,
143}
144
145#[derive(Debug, Clone, Serialize, Deserialize)]
146#[serde(rename_all = "camelCase")]
147pub struct PublicCollection {
148    pub entity: String,
149    /// Subset of CRUD actions exposed: "list", "read", "create", "update", "delete".
150    pub actions: Vec<String>,
151}
152
153#[derive(Debug, Clone, Serialize, Deserialize)]
154#[serde(rename_all = "camelCase")]
155pub struct CronDefinition {
156    pub name: String,
157    pub schedule: String,
158    #[serde(default, skip_serializing_if = "Option::is_none")]
159    pub timezone: Option<String>,
160    #[serde(default, skip_serializing_if = "Option::is_none")]
161    pub method: Option<String>,
162    #[serde(default, skip_serializing_if = "Option::is_none")]
163    pub payload: Option<JsonValue>,
164    #[serde(default = "default_overlap_policy")]
165    pub overlap_policy: String,
166}
167
168fn default_overlap_policy() -> String { "skip".into() }
169
170#[derive(Debug, Clone, Serialize, Deserialize)]
171#[serde(rename_all = "camelCase")]
172pub struct TriggerConfig {
173    pub app_id: String,
174    pub entity: String,
175    pub on: Vec<String>,
176}
177
178fn default_version() -> String {
179    "0.0.1".to_string()
180}
181
182#[derive(Debug, Clone, Serialize, Deserialize)]
183#[serde(rename_all = "camelCase")]
184pub struct EntityContract {
185    pub entity_name: String,
186    pub fields: Vec<FieldContract>,
187    #[serde(default, skip_serializing_if = "Option::is_none")]
188    pub identity_kind: Option<String>,
189    #[serde(default, skip_serializing_if = "Option::is_none")]
190    pub identity_key: Option<String>,
191}
192
193#[derive(Debug, Clone, Serialize, Deserialize)]
194#[serde(rename_all = "camelCase")]
195pub struct FieldContract {
196    pub name: String,
197    #[serde(rename = "type")]
198    pub field_type: String,
199    #[serde(default)]
200    pub required: bool,
201    #[serde(default)]
202    pub default_value: Option<JsonValue>,
203    #[serde(default)]
204    pub enum_values: Option<Vec<String>>,
205    #[serde(default)]
206    pub references: Option<FieldReference>,
207    #[serde(default)]
208    pub is_primary_key: Option<bool>,
209    #[serde(default, skip_serializing_if = "Option::is_none")]
210    pub on_delete: Option<OnDeletePolicy>,
211}
212
213#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
214#[serde(rename_all = "snake_case")]
215pub enum OnDeletePolicy {
216    Cascade,
217    Restrict,
218    SetNull,
219}
220
221#[derive(Debug, Clone, Serialize, Deserialize)]
222pub struct FieldReference {
223    pub entity: String,
224    pub field: String,
225}
226
227#[derive(Debug, Clone, Serialize, Deserialize)]
228#[serde(rename_all = "camelCase")]
229pub struct InstalledApp {
230    pub id: String,
231    pub name: String,
232    pub version: String,
233    pub status: String,
234    #[serde(rename = "type", default)]
235    pub app_type: AppType,
236    pub entities: Vec<String>,
237    #[serde(default)]
238    pub has_frontend: bool,
239    #[serde(default, skip_serializing_if = "Option::is_none")]
240    pub icon: Option<String>,
241}
242
243#[derive(Debug, Clone, Serialize, Deserialize)]
244#[serde(rename_all = "camelCase")]
245pub struct PermissionsContract {
246    #[serde(default)]
247    pub permissions: Vec<PermissionDeclaration>,
248}
249
250#[derive(Debug, Clone, Serialize, Deserialize)]
251pub struct PermissionDeclaration {
252    pub key: String,
253    #[serde(default)]
254    pub description: String,
255}
256
257#[derive(Debug, Clone, Serialize, Deserialize)]
258pub struct SchemaChange {
259    pub entity: String,
260    pub change_type: String,
261    pub column: String,
262    pub detail: Option<String>,
263}
264
265#[derive(Debug, Clone, Serialize, Deserialize)]
266pub struct SchemaVerification {
267    pub compliant: bool,
268    pub changes: Vec<SchemaChange>,
269}
270
271#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
272#[serde(rename_all = "lowercase")]
273pub enum ProviderType {
274    Anthropic,
275    OpenAI,
276    Bedrock,
277}
278
279#[derive(Debug, Clone, Serialize, Deserialize)]
280#[serde(rename_all = "camelCase")]
281pub struct AgentDefinition {
282    pub name: String,
283    #[serde(default)]
284    pub description: Option<String>,
285    #[serde(default)]
286    pub system_prompt: Option<String>,
287    #[serde(default)]
288    pub memory: Option<AgentMemory>,
289    #[serde(default)]
290    pub limits: Option<AgentLimits>,
291    #[serde(default)]
292    pub supervision: Option<SupervisionConfig>,
293}
294
295#[derive(Debug, Clone, Serialize, Deserialize)]
296pub struct AgentMemory {
297    pub enabled: bool,
298}
299
300#[derive(Debug, Clone, Serialize, Deserialize)]
301#[serde(rename_all = "camelCase")]
302pub struct AgentLimits {
303    #[serde(default)]
304    pub max_turns: Option<u32>,
305    #[serde(default)]
306    pub max_context_tokens: Option<u64>,
307    #[serde(default)]
308    pub keep_recent_messages: Option<u32>,
309}
310
311#[derive(Debug, Clone, Serialize, Deserialize)]
312#[serde(rename_all = "camelCase")]
313pub struct SupervisionConfig {
314    pub mode: SupervisionMode,
315    #[serde(default)]
316    pub policies: Vec<SupervisionPolicy>,
317}
318
319#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
320#[serde(rename_all = "lowercase")]
321pub enum SupervisionMode {
322    Autonomous,
323    Supervised,
324    Strict,
325}
326
327#[derive(Debug, Clone, Serialize, Deserialize)]
328#[serde(rename_all = "camelCase")]
329pub struct SupervisionPolicy {
330    pub action: String,
331    #[serde(default)]
332    pub entity: Option<String>,
333    #[serde(default)]
334    pub requires: Option<String>,
335    #[serde(default)]
336    pub rate_limit: Option<RateLimit>,
337}
338
339#[derive(Debug, Clone, Serialize, Deserialize)]
340pub struct RateLimit {
341    pub max: u32,
342    pub window: String,
343}
344
345#[derive(Debug, Clone, Serialize, Deserialize)]
346#[serde(rename_all = "camelCase")]
347pub struct McpServerConfig {
348    pub name: String,
349    pub transport: McpTransport,
350}
351
352#[derive(Debug, Clone, Serialize, Deserialize)]
353#[serde(tag = "type", rename_all = "lowercase")]
354pub enum McpTransport {
355    Stdio { command: String, #[serde(default)] args: Vec<String> },
356    Http { url: String, #[serde(default)] headers: std::collections::HashMap<String, String> },
357    #[deprecated = "use Http"]
358    Sse { url: String, #[serde(default)] headers: std::collections::HashMap<String, String> },
359    Cli { install: String },
360}
361
362#[derive(Debug, Clone, Serialize, Deserialize)]
363#[serde(rename_all = "camelCase")]
364pub struct ToolDescriptor {
365    pub name: String,
366    pub description: String,
367    pub input_schema: serde_json::Value,
368}
369
370#[derive(Debug, Clone, Serialize, Deserialize)]
371#[serde(rename_all = "lowercase")]
372pub enum Role {
373    User,
374    Assistant,
375}
376
377#[derive(Debug, Clone, Serialize, Deserialize)]
378#[serde(tag = "type", rename_all = "snake_case")]
379pub enum ContentBlock {
380    Text { text: String },
381    ToolUse { id: String, name: String, input: serde_json::Value },
382    ToolResult { tool_use_id: String, content: String, #[serde(default)] is_error: bool },
383}
384
385#[derive(Debug, Clone, Serialize, Deserialize)]
386pub struct ChatMessage {
387    pub role: Role,
388    pub content: Vec<ContentBlock>,
389}
390
391#[derive(Debug, Clone, Serialize, Deserialize)]
392pub struct ToolDef {
393    pub name: String,
394    pub description: String,
395    pub input_schema: serde_json::Value,
396}
397