use crate::{
DriverCallback, DriverCategory, DriverContext, DriverError, DriverResult,
types::{Driver, DriverParameter},
};
use serde_json::{Value, json};
use std::collections::HashMap;
use tracing::{debug, info};
#[derive(Debug)]
pub struct HelloWorldDriver;
#[async_trait::async_trait]
impl Driver for HelloWorldDriver {
fn name(&self) -> &str {
return "helloworld";
}
fn description(&self) -> &str {
return "Greet a user by name";
}
fn usage_hint(&self) -> &str {
return "Use this driver when the user asks to be greeted or when you need to introduce yourself";
}
fn parameters(&self) -> Vec<DriverParameter> {
return vec![DriverParameter {
name: "name".to_string(),
param_type: "string".to_string(),
description: "The name of the person to greet".to_string(),
required: false,
default: Some(Value::String("World".to_string())),
example: Some(Value::String("Alice".to_string())),
enum_values: None,
}];
}
fn example_call(&self) -> DriverResult<Value> {
return Ok(json!({
"action": "helloworld",
"parameters": {
"name": "Alice"
}
}));
}
fn example_output(&self) -> String {
return "Hello, Alice!".to_string();
}
fn category(&self) -> DriverCategory {
return DriverCategory::Basic;
}
async fn execute(
&self,
parameters: &HashMap<String, Value>,
_callback: Option<&dyn DriverCallback>,
_context: Option<&DriverContext>,
) -> DriverResult<String> {
debug!("Executing helloworld driver");
let name = parameters.get("name").and_then(|v| v.as_str()).unwrap_or("World");
let result = format!("Hello, {}!", name);
info!("{}", result);
return Ok(result);
}
fn validate(&self, _parameters: &HashMap<String, Value>) -> DriverResult<()> {
return Ok(());
}
}