use crate::{actions::delete_webhook, parameters_json_schema, SolanaAgentKit};
use rig::{
completion::ToolDefinition,
tool::{Tool, ToolEmbedding},
};
use serde::{Deserialize, Serialize};
use serde_json::json;
use std::sync::Arc;
#[derive(Deserialize)]
pub struct DeleteWebHookArgs {
webhook_id: String,
}
#[derive(Deserialize, Serialize)]
pub struct DeleteWebHookOutput {
pub data: serde_json::Value,
}
#[derive(Debug, thiserror::Error)]
#[error("DeleteWebHook error")]
pub struct DeleteWebHookError;
pub struct DeleteWebHook {
agent: Arc<SolanaAgentKit>,
}
impl DeleteWebHook {
pub fn new(agent: Arc<SolanaAgentKit>) -> Self {
DeleteWebHook { agent }
}
}
impl Tool for DeleteWebHook {
const NAME: &'static str = "delete_webhook";
type Error = DeleteWebHookError;
type Args = DeleteWebHookArgs;
type Output = DeleteWebHookOutput;
async fn definition(&self, _prompt: String) -> ToolDefinition {
ToolDefinition {
name: "delete_webhook".to_string(),
description: r#"
Deletes a Helius webhook by its unique ID
input: {
webhook_id: "webhook_123",
},
"#
.to_string(),
parameters: parameters_json_schema!(
webhook_id: String,
),
}
}
async fn call(&self, args: Self::Args) -> Result<Self::Output, Self::Error> {
let data = delete_webhook(&self.agent, &args.webhook_id).await.expect("delete_webhook");
Ok(DeleteWebHookOutput { data })
}
}
#[derive(Debug, thiserror::Error)]
#[error("Init error")]
pub struct InitError;
impl ToolEmbedding for DeleteWebHook {
type InitError = InitError;
type Context = ();
type State = Arc<SolanaAgentKit>;
fn init(_state: Self::State, _context: Self::Context) -> Result<Self, Self::InitError> {
Ok(DeleteWebHook { agent: _state })
}
fn embedding_docs(&self) -> Vec<String> {
vec!["Deletes a Helius webhook by its unique ID".into()]
}
fn context(&self) -> Self::Context {}
}