Skip to main content

lenso_contracts/
runtime.rs

1//! Pure-data runtime declarations for module manifests.
2//!
3//! These declarations describe runtime behavior a module can provide without
4//! carrying executable handlers. Loading sources decide how to bind them later.
5
6use serde::{Deserialize, Serialize};
7use serde_json::Value;
8use utoipa::ToSchema;
9
10#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, ToSchema)]
11pub struct RuntimeSurface {
12    #[serde(default)]
13    pub functions: Vec<RuntimeFunctionDeclaration>,
14    #[serde(default)]
15    pub schedules: Vec<ScheduledFunctionDeclaration>,
16}
17
18#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, ToSchema)]
19pub struct RuntimeFunctionDeclaration {
20    /// Stable function name used by `runtime.function_runs`.
21    pub name: String,
22    /// Version for the declared function contract.
23    pub version: u16,
24    /// Queue name the host should use when registering the function.
25    pub queue: String,
26    /// Optional schema identifier for the function input payload.
27    #[serde(default, skip_serializing_if = "Option::is_none")]
28    pub input_schema: Option<String>,
29    /// Optional retry policy requested by the module. The host still owns
30    /// enforcement and may clamp values when behavior registration is added.
31    #[serde(default, skip_serializing_if = "Option::is_none")]
32    pub retry_policy: Option<RuntimeRetryPolicyDeclaration>,
33}
34
35#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, ToSchema)]
36pub struct RuntimeRetryPolicyDeclaration {
37    pub max_attempts: u32,
38    pub initial_delay_ms: u64,
39}
40
41#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, ToSchema)]
42pub struct ScheduledFunctionDeclaration {
43    /// Stable schedule name scoped to the owning module.
44    pub name: String,
45    /// Runtime function enqueued when this schedule is due.
46    pub function_name: String,
47    /// Standard 5-field cron expression in UTC.
48    pub cron: String,
49    #[serde(default)]
50    pub input: Value,
51}