elizaos_plugin_code/
lib.rs1#![allow(missing_docs)]
2
3use async_trait::async_trait;
4use serde_json::Value;
5
6mod error;
7mod path_utils;
8mod service;
9mod types;
10
11pub mod actions;
12pub mod providers;
13
14pub use error::Result;
15pub use path_utils::{
16 extract_base_command, is_forbidden_command, is_safe_command, validate_path,
17 DEFAULT_FORBIDDEN_COMMANDS,
18};
19pub use service::CoderService;
20pub use types::{CodeConfig, CommandHistoryEntry, CommandResult, FileOperation, FileOperationType};
21
22pub use actions::get_code_actions;
23pub use providers::get_code_providers;
24pub use providers::CoderStatusProvider;
25
26pub const PLUGIN_NAME: &str = "code";
27pub const PLUGIN_DESCRIPTION: &str = "Filesystem + shell + git tools within a restricted directory";
28pub const PLUGIN_VERSION: &str = env!("CARGO_PKG_VERSION");
29
30#[derive(Debug, Clone)]
31pub struct ActionExample {
32 pub user_message: String,
33 pub agent_response: String,
34}
35
36#[derive(Debug, Clone)]
37pub struct ActionResult {
38 pub success: bool,
39 pub text: String,
40 pub data: Option<Value>,
41 pub error: Option<String>,
42}
43
44#[derive(Debug, Clone)]
45pub struct ProviderResult {
46 pub values: Value,
47 pub text: String,
48 pub data: Value,
49}
50
51#[async_trait]
52pub trait Action: Send + Sync {
53 fn name(&self) -> &str;
54 fn similes(&self) -> Vec<&str>;
55 fn description(&self) -> &str;
56 async fn validate(&self, message: &Value, state: &Value) -> bool;
57 async fn handler(
58 &self,
59 message: &Value,
60 state: &Value,
61 service: Option<&mut CoderService>,
62 ) -> ActionResult;
63 fn examples(&self) -> Vec<ActionExample>;
64}
65
66#[async_trait]
67pub trait Provider: Send + Sync {
68 fn name(&self) -> &str;
69 fn description(&self) -> &str;
70 fn position(&self) -> i32;
71 async fn get(
72 &self,
73 message: &Value,
74 state: &Value,
75 service: Option<&CoderService>,
76 ) -> ProviderResult;
77}
78
79pub mod prelude {
80 pub use crate::actions::get_code_actions;
81 pub use crate::providers::{get_code_providers, CoderStatusProvider};
82 pub use crate::service::CoderService;
83 pub use crate::types::{
84 CodeConfig, CommandHistoryEntry, CommandResult, FileOperation, FileOperationType,
85 };
86 pub use crate::{Action, ActionExample, ActionResult, Provider, ProviderResult};
87 pub use crate::{Result, PLUGIN_DESCRIPTION, PLUGIN_NAME, PLUGIN_VERSION};
88}