use std::sync::Arc;
use std::time::Duration;
use async_trait::async_trait;
use chrono::{DateTime, Utc};
use nexo_llm::ToolDef;
use serde_json::Value;
use tokio_util::sync::CancellationToken;
use crate::error::PollerError;
use crate::host::{PollerHost, TickAck};
use crate::PollerRunner;
#[async_trait]
pub trait Poller: Send + Sync + 'static {
fn kind(&self) -> &'static str;
fn description(&self) -> &'static str {
""
}
fn validate(&self, _config: &Value) -> Result<(), PollerError> {
Ok(())
}
async fn tick(&self, ctx: &PollContext) -> Result<TickAck, PollerError>;
fn custom_tools(&self) -> Vec<CustomToolSpec> {
Vec::new()
}
}
pub struct CustomToolSpec {
pub def: ToolDef,
pub handler: Arc<dyn CustomToolHandler>,
}
#[async_trait]
pub trait CustomToolHandler: Send + Sync + 'static {
async fn call(&self, runner: Arc<PollerRunner>, args: Value) -> anyhow::Result<Value>;
}
pub struct PollContext {
pub job_id: String,
pub agent_id: String,
pub kind: &'static str,
pub config: Value,
pub cursor: Option<Vec<u8>>,
pub now: DateTime<Utc>,
pub interval_hint: Duration,
pub cancel: CancellationToken,
pub host: Arc<dyn PollerHost>,
}
#[cfg(test)]
mod tests {
use super::*;
fn assert_send_sync<T: Send + Sync>() {}
#[test]
fn poll_context_is_send_sync() {
assert_send_sync::<PollContext>();
}
}