elizaos_plugin_cron/
lib.rs1#![allow(missing_docs)]
2
3use async_trait::async_trait;
4use serde_json::Value;
5
6mod schedule;
7mod service;
8mod storage;
9mod types;
10
11pub mod actions;
12pub mod providers;
13
14pub use schedule::{
15 compute_next_run, format_schedule, parse_natural_language_schedule, parse_schedule,
16 validate_cron_expression,
17};
18pub use service::CronService;
19pub use storage::CronStorage;
20pub use types::{
21 CronConfig, JobDefinition, JobState, JobUpdate, PayloadType, ScheduleType,
22 DEFAULT_MAX_JOBS, DEFAULT_TIMEOUT_MS,
23};
24
25pub use actions::get_cron_actions;
26pub use providers::{get_cron_providers, CronContextProvider};
27
28pub const PLUGIN_NAME: &str = "cron";
29pub const PLUGIN_DESCRIPTION: &str = "Scheduled job management with cron expressions, intervals, and one-time runs";
30pub const PLUGIN_VERSION: &str = env!("CARGO_PKG_VERSION");
31
32#[derive(Debug, Clone)]
33pub struct ActionExample {
34 pub user_message: String,
35 pub agent_response: String,
36}
37
38#[derive(Debug, Clone)]
39pub struct ActionResult {
40 pub success: bool,
41 pub text: String,
42 pub data: Option<Value>,
43 pub error: Option<String>,
44}
45
46#[derive(Debug, Clone)]
47pub struct ProviderResult {
48 pub values: Value,
49 pub text: String,
50 pub data: Value,
51}
52
53#[async_trait]
54pub trait Action: Send + Sync {
55 fn name(&self) -> &str;
56 fn similes(&self) -> Vec<&str>;
57 fn description(&self) -> &str;
58 async fn validate(&self, message: &Value, state: &Value) -> bool;
59 async fn handler(
60 &self,
61 message: &Value,
62 state: &Value,
63 service: Option<&mut CronService>,
64 ) -> ActionResult;
65 fn examples(&self) -> Vec<ActionExample>;
66}
67
68#[async_trait]
69pub trait Provider: Send + Sync {
70 fn name(&self) -> &str;
71 fn description(&self) -> &str;
72 fn position(&self) -> i32;
73 async fn get(
74 &self,
75 message: &Value,
76 state: &Value,
77 service: Option<&CronService>,
78 ) -> ProviderResult;
79}
80
81pub mod prelude {
82 pub use crate::actions::get_cron_actions;
83 pub use crate::providers::{get_cron_providers, CronContextProvider};
84 pub use crate::schedule::{
85 compute_next_run, format_schedule, parse_natural_language_schedule, parse_schedule,
86 validate_cron_expression,
87 };
88 pub use crate::service::CronService;
89 pub use crate::storage::CronStorage;
90 pub use crate::types::{
91 CronConfig, JobDefinition, JobState, JobUpdate, PayloadType, ScheduleType,
92 };
93 pub use crate::{Action, ActionExample, ActionResult, Provider, ProviderResult};
94 pub use crate::{PLUGIN_DESCRIPTION, PLUGIN_NAME, PLUGIN_VERSION};
95}