use crate::{
actions::{get_webhook, HeliusWebhookIdResponse},
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 GetWebHookArgs {
webhook_id: String,
}
#[derive(Deserialize, Serialize)]
pub struct GetWebHookOutput {
pub data: HeliusWebhookIdResponse,
}
#[derive(Debug, thiserror::Error)]
#[error("GetWebHook error")]
pub struct GetWebHookError;
pub struct GetWebHook {
agent: Arc<SolanaAgentKit>,
}
impl GetWebHook {
pub fn new(agent: Arc<SolanaAgentKit>) -> Self {
GetWebHook { agent }
}
}
impl Tool for GetWebHook {
const NAME: &'static str = "get_webhook";
type Error = GetWebHookError;
type Args = GetWebHookArgs;
type Output = GetWebHookOutput;
async fn definition(&self, _prompt: String) -> ToolDefinition {
ToolDefinition {
name: "get_webhook".to_string(),
description: r#"
Retrieves details of 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 = get_webhook(&self.agent, &args.webhook_id).await.expect("get_webhook");
Ok(GetWebHookOutput { data })
}
}
#[derive(Debug, thiserror::Error)]
#[error("Init error")]
pub struct InitError;
impl ToolEmbedding for GetWebHook {
type InitError = InitError;
type Context = ();
type State = Arc<SolanaAgentKit>;
fn init(_state: Self::State, _context: Self::Context) -> Result<Self, Self::InitError> {
Ok(GetWebHook { agent: _state })
}
fn embedding_docs(&self) -> Vec<String> {
vec!["Retrieves details of a Helius webhook by its unique ID".into()]
}
fn context(&self) -> Self::Context {}
}