supercode_interchange/orchestration/
job.rs1use schemars::JsonSchema;
4use serde::{Deserialize, Serialize};
5
6use crate::ontology::Residue;
7
8#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
10#[serde(tag = "kind", rename_all = "snake_case")]
11pub enum Schedule {
12 Once {
14 run_at: String,
16 },
17 Interval {
19 minutes: f64,
21 },
22 Cron {
24 expr: String,
26 #[serde(default = "utc")]
28 tz: String,
29 },
30}
31
32fn utc() -> String {
33 "UTC".to_string()
34}
35
36impl Eq for Schedule {}
37
38impl Schedule {
39 pub fn kind(&self) -> &'static str {
41 match self {
42 Self::Once { .. } => "once",
43 Self::Interval { .. } => "interval",
44 Self::Cron { .. } => "cron",
45 }
46 }
47}
48
49#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
51#[serde(tag = "kind", rename_all = "snake_case")]
52pub enum Target {
53 Origin,
55 Home,
57 Local,
59 Explicit {
61 platform: String,
63 #[serde(default, skip_serializing_if = "Option::is_none")]
65 chat_id: Option<String>,
66 #[serde(default, skip_serializing_if = "Option::is_none")]
68 thread_id: Option<String>,
69 },
70}
71
72impl Target {
73 pub fn render(&self) -> String {
75 match self {
76 Self::Origin => "origin".into(),
77 Self::Home => "home".into(),
78 Self::Local => "local".into(),
79 Self::Explicit {
80 platform,
81 chat_id,
82 thread_id,
83 } => {
84 let mut s = platform.clone();
85 if let Some(c) = chat_id {
86 s.push(':');
87 s.push_str(c);
88 if let Some(t) = thread_id {
89 s.push(':');
90 s.push_str(t);
91 }
92 }
93 s
94 }
95 }
96 }
97}
98
99#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
101pub struct Repeat {
102 #[serde(default)]
104 pub times: Option<u32>,
105 #[serde(default)]
107 pub completed: u32,
108}
109
110#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
112pub struct JobOrigin {
113 pub platform: String,
115 #[serde(default)]
117 pub chat_type: Option<String>,
118 #[serde(default)]
120 pub chat_id: Option<String>,
121 #[serde(default)]
123 pub thread_id: Option<String>,
124}
125
126#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
128pub struct Job {
129 pub id: String,
131 pub schedule: Schedule,
133 #[serde(default)]
135 pub prompt: Option<String>,
136 #[serde(default)]
138 pub workdir: Option<String>,
139 #[serde(default)]
141 pub model: Option<String>,
142 #[serde(default)]
144 pub skills: Vec<String>,
145 #[serde(default)]
147 pub context_from: Option<Vec<String>>,
148 pub deliver: Target,
150 #[serde(default)]
152 pub failure_deliver: Option<Target>,
153 #[serde(default)]
155 pub origin: Option<JobOrigin>,
156 #[serde(default)]
158 pub attach_to_session: Option<bool>,
159 #[serde(default)]
161 pub repeat: Option<Repeat>,
162 #[serde(default = "default_true")]
164 pub enabled: bool,
165 #[serde(default)]
167 pub next_run_at: Option<String>,
168 #[serde(default)]
170 pub last_run_at: Option<String>,
171 #[serde(default)]
173 pub last_status: Option<String>,
174 #[serde(default)]
176 pub created_at: Option<String>,
177 #[serde(default)]
179 pub residue: Residue,
180}
181
182fn default_true() -> bool {
183 true
184}