Skip to main content

zeph_core/agent/
scheduler_commands.rs

1// SPDX-FileCopyrightText: 2026 Andrei G <bug-ops>
2// SPDX-License-Identifier: MIT OR Apache-2.0
3
4//! [`zeph_commands::SchedulerAccess`] implementation for [`Agent<C>`]: `/scheduler`.
5//!
6//! [`Agent<C>`]: super::Agent
7
8use std::future::Future;
9use std::pin::Pin;
10
11use zeph_commands::{CommandError, SchedulerAccess};
12
13use super::Agent;
14use crate::channel::Channel;
15
16#[cfg(feature = "scheduler")]
17impl<C: Channel> Agent<C> {
18    /// Channel-free version of the scheduler list command for use via
19    /// [`zeph_commands::SchedulerAccess`].
20    pub(super) async fn handle_scheduler_list_as_string(
21        &mut self,
22    ) -> Result<String, super::error::AgentError> {
23        use zeph_tools::executor::ToolCall;
24
25        let call = ToolCall {
26            tool_id: zeph_common::ToolName::new("list_tasks"),
27            params: serde_json::Map::new(),
28            caller_id: None,
29            context: None,
30            tool_call_id: String::new(),
31            skill_name: None,
32        };
33        match self.tool_executor.execute_tool_call_erased(&call).await {
34            Ok(Some(output)) => Ok(output.summary),
35            Ok(None) => {
36                Ok("Scheduler is not enabled or list_tasks tool is unavailable.".to_owned())
37            }
38            Err(e) => Ok(format!("Failed to list scheduled tasks: {e}")),
39        }
40    }
41}
42
43impl<C: Channel + Send + 'static> SchedulerAccess for Agent<C> {
44    // ----- /scheduler -----
45
46    #[cfg(feature = "scheduler")]
47    fn list_scheduled_tasks<'a>(
48        &'a mut self,
49    ) -> Pin<Box<dyn Future<Output = Result<Option<String>, CommandError>> + Send + 'a>> {
50        Box::pin(async move {
51            let result = self
52                .handle_scheduler_list_as_string()
53                .await
54                .map_err(|e| CommandError::new(e.to_string()))?;
55            Ok(Some(result))
56        })
57    }
58
59    #[cfg(not(feature = "scheduler"))]
60    fn list_scheduled_tasks<'a>(
61        &'a mut self,
62    ) -> Pin<Box<dyn Future<Output = Result<Option<String>, CommandError>> + Send + 'a>> {
63        Box::pin(async move { Ok(None) })
64    }
65}