solagent_rig_gibwork/
lib.rs

1use serde::{Deserialize, Serialize};
2use solagent_core::{
3    rig::{completion::ToolDefinition, tool::Tool},
4    solana_sdk::pubkey::Pubkey,
5    SolanaAgentKit,
6};
7use solagent_parameters::parameters;
8use solagent_plugin_gibwork::{create_gibwork_task, GibworkCreateTaskResponse};
9use std::sync::Arc;
10
11#[derive(Deserialize)]
12pub struct CreateGibworkTaskArgs {
13    title: String,
14    content: String,
15    requirements: String,
16    tags: Vec<String>,
17    token_mint_address: String,
18    token_amount: u64,
19    payer: Option<Pubkey>,
20}
21
22#[derive(Deserialize, Serialize)]
23pub struct CreateGibworkTaskOutput {
24    pub data: GibworkCreateTaskResponse,
25}
26
27#[derive(Debug, thiserror::Error)]
28#[error("CreateGibworkTask error")]
29pub struct CreateGibworkTaskError;
30
31pub struct CreateGibworkTask {
32    agent: Arc<SolanaAgentKit>,
33}
34
35impl CreateGibworkTask {
36    pub fn new(agent: Arc<SolanaAgentKit>) -> Self {
37        CreateGibworkTask { agent }
38    }
39}
40
41impl Tool for CreateGibworkTask {
42    const NAME: &'static str = "create_gibwork_task";
43
44    type Error = CreateGibworkTaskError;
45    type Args = CreateGibworkTaskArgs;
46    type Output = CreateGibworkTaskOutput;
47
48    async fn definition(&self, _prompt: String) -> ToolDefinition {
49        ToolDefinition {
50            name: "create_gibwork_task".to_string(),
51            description: r#"
52            Create a new task on the Gibwork platform with payment in SPL tokens.
53            
54            examples: [
55                [
56                    {
57                        input: {
58                            title: "Build a Solana dApp",
59                            content: "Create a simple Solana dApp with React frontend",
60                            requirements: "Experience with Rust and React",
61                            tags: ["solana", "rust", "react"],
62                            tokenMintAddress: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
63                            tokenAmount: 100,
64                        },
65                        output: {
66                            status: "success",
67                            taskId: "task_123",
68                            signature: "3YKpM1...",
69                            message: "Successfully created task: Build a Solana dApp",
70                        },
71                        explanation: "Create a new task on Gibwork with 100 USDC payment",
72                    },
73                ],
74            ]
75            "#
76            .to_string(),
77            parameters: parameters!(
78                title: String,
79                content: String,
80                requirements: String,
81                tags: Vec<String>,
82                token_mint_address: String,
83                token_amount: u64,
84                payer: Option<Pubkey>,
85            ),
86        }
87    }
88
89    async fn call(&self, args: Self::Args) -> Result<Self::Output, Self::Error> {
90        let data = create_gibwork_task(
91            &self.agent,
92            &args.title,
93            &args.content,
94            &args.requirements,
95            args.tags,
96            &args.token_mint_address,
97            args.token_amount,
98            args.payer,
99        )
100        .await
101        .expect("create_gibwork_task");
102
103        Ok(CreateGibworkTaskOutput { data })
104    }
105}