Skip to main content

stynx_code_tools/infrastructure/
remote_trigger_tool.rs

1use stynx_code_errors::AppResult;
2use stynx_code_types::{PermissionLevel, Tool};
3use serde_json::{Value, json};
4
5pub struct RemoteTriggerTool;
6
7impl RemoteTriggerTool {
8    pub fn new() -> Self {
9        Self
10    }
11}
12
13#[async_trait::async_trait]
14impl Tool for RemoteTriggerTool {
15    fn name(&self) -> &str {
16        "remote_trigger"
17    }
18
19    fn description(&self) -> &str {
20        "Fire a remote trigger by ID, optionally with a JSON payload."
21    }
22
23    fn input_schema(&self) -> Value {
24        json!({
25            "type": "object",
26            "properties": {
27                "trigger_id": {
28                    "type": "string",
29                    "description": "The ID of the remote trigger to fire"
30                },
31                "payload": {
32                    "description": "Optional JSON payload to send with the trigger"
33                }
34            },
35            "required": ["trigger_id"]
36        })
37    }
38
39    fn permission_level(&self) -> PermissionLevel {
40        PermissionLevel::Dangerous
41    }
42
43    async fn execute(&self, input: Value) -> AppResult<String> {
44        let trigger_id = input
45            .get("trigger_id")
46            .and_then(|v| v.as_str())
47            .ok_or_else(|| stynx_code_errors::AppError::Tool("missing 'trigger_id' field".into()))?;
48
49        let payload = input.get("payload");
50
51        tracing::info!(trigger_id, ?payload, "firing remote trigger (stub)");
52
53        Ok(format!("Trigger '{trigger_id}' acknowledged. (stub)"))
54    }
55}