hippox 0.3.0

The most reliable AI agent.🦛
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
use crate::config::get_config;
use crate::executors::types::{Skill, SkillParameter};
use anyhow::Result;
use once_cell::sync::Lazy;
use redis::Client;
use redis::Commands;
use redis::Connection;
use serde_json::{Value, json};
use std::collections::HashMap;
use std::sync::Arc;
use tokio::sync::Mutex;

struct RedisConnectionPool {
    client: Arc<Mutex<Option<Client>>>,
}

impl RedisConnectionPool {
    fn new() -> Self {
        Self {
            client: Arc::new(Mutex::new(None)),
        }
    }

    async fn get_client(&self) -> Result<Client> {
        let mut client_guard = self.client.lock().await;
        if let Some(client) = client_guard.as_ref() {
            return Ok(client.clone());
        }
        let config = get_config();
        let redis_url = if config.redis_password.is_empty() {
            format!("redis://{}:{}/", config.redis_host, config.redis_port)
        } else {
            format!(
                "redis://:{}@{}:{}/{}",
                config.redis_password, config.redis_host, config.redis_port, config.redis_db
            )
        };
        let client = Client::open(redis_url)?;
        *client_guard = Some(client.clone());
        Ok(client)
    }

    async fn get_connection(&self) -> Result<Connection> {
        let client = self.get_client().await?;
        let conn = client.get_connection()?;
        Ok(conn)
    }
}

static REDIS_POOL: Lazy<RedisConnectionPool> = Lazy::new(|| RedisConnectionPool::new());

/// Redis Set Skill
#[derive(Debug)]
pub struct RedisSetSkill;

#[async_trait::async_trait]
impl Skill for RedisSetSkill {
    fn name(&self) -> &str {
        "redis_set"
    }

    fn description(&self) -> &str {
        "Set a key-value pair in Redis"
    }

    fn usage_hint(&self) -> &str {
        "Use this skill when the user needs to store data in Redis"
    }

    fn parameters(&self) -> Vec<SkillParameter> {
        vec![
            SkillParameter {
                name: "key".to_string(),
                param_type: "string".to_string(),
                description: "Redis key".to_string(),
                required: true,
                default: None,
                example: Some(Value::String("user:100".to_string())),
                enum_values: None,
            },
            SkillParameter {
                name: "value".to_string(),
                param_type: "string".to_string(),
                description: "Value to store".to_string(),
                required: true,
                default: None,
                example: Some(Value::String("John Doe".to_string())),
                enum_values: None,
            },
            SkillParameter {
                name: "ttl".to_string(),
                param_type: "integer".to_string(),
                description: "Time to live in seconds (optional)".to_string(),
                required: false,
                default: None,
                example: Some(Value::Number(3600.into())),
                enum_values: None,
            },
        ]
    }

    fn example_call(&self) -> Value {
        json!({
            "action": "redis_set",
            "parameters": {
                "key": "user:100",
                "value": "John Doe",
                "ttl": 3600
            }
        })
    }

    fn example_output(&self) -> String {
        "Successfully set key 'user:100'".to_string()
    }

    fn category(&self) -> &str {
        "database"
    }

    async fn execute(&self, parameters: &HashMap<String, Value>) -> Result<String> {
        let mut conn = REDIS_POOL.get_connection().await?;
        let key = parameters
            .get("key")
            .and_then(|v| v.as_str())
            .ok_or_else(|| anyhow::anyhow!("Missing required parameter: key"))?;
        let value = parameters
            .get("value")
            .and_then(|v| v.as_str())
            .ok_or_else(|| anyhow::anyhow!("Missing required parameter: value"))?;
        let _: () = conn.set(key, value)?;
        if let Some(ttl) = parameters.get("ttl").and_then(|v| v.as_u64()) {
            let _: () = conn.expire(key, ttl.try_into().unwrap())?;
        }
        Ok(format!("Successfully set key '{}'", key))
    }
}

/// Redis Get Skill
#[derive(Debug)]
pub struct RedisGetSkill;

#[async_trait::async_trait]
impl Skill for RedisGetSkill {
    fn name(&self) -> &str {
        "redis_get"
    }

    fn description(&self) -> &str {
        "Get a value from Redis by key"
    }

    fn usage_hint(&self) -> &str {
        "Use this skill when the user needs to retrieve data from Redis"
    }

    fn parameters(&self) -> Vec<SkillParameter> {
        vec![SkillParameter {
            name: "key".to_string(),
            param_type: "string".to_string(),
            description: "Redis key".to_string(),
            required: true,
            default: None,
            example: Some(Value::String("user:100".to_string())),
            enum_values: None,
        }]
    }

    fn example_call(&self) -> Value {
        json!({
            "action": "redis_get",
            "parameters": {
                "key": "user:100"
            }
        })
    }

    fn example_output(&self) -> String {
        "John Doe".to_string()
    }

    fn category(&self) -> &str {
        "database"
    }

    async fn execute(&self, parameters: &HashMap<String, Value>) -> Result<String> {
        let mut conn = REDIS_POOL.get_connection().await?;
        let key = parameters
            .get("key")
            .and_then(|v| v.as_str())
            .ok_or_else(|| anyhow::anyhow!("Missing required parameter: key"))?;
        let value: Option<String> = conn.get(key)?;
        match value {
            Some(v) => Ok(v),
            None => Ok("null".to_string()),
        }
    }
}

/// Redis Delete Skill
#[derive(Debug)]
pub struct RedisDelSkill;

#[async_trait::async_trait]
impl Skill for RedisDelSkill {
    fn name(&self) -> &str {
        "redis_del"
    }

    fn description(&self) -> &str {
        "Delete a key from Redis"
    }

    fn usage_hint(&self) -> &str {
        "Use this skill when the user needs to delete data from Redis"
    }

    fn parameters(&self) -> Vec<SkillParameter> {
        vec![SkillParameter {
            name: "key".to_string(),
            param_type: "string".to_string(),
            description: "Redis key to delete".to_string(),
            required: true,
            default: None,
            example: Some(Value::String("user:100".to_string())),
            enum_values: None,
        }]
    }

    fn example_call(&self) -> Value {
        json!({
            "action": "redis_del",
            "parameters": {
                "key": "user:100"
            }
        })
    }

    fn example_output(&self) -> String {
        "Successfully deleted key 'user:100'".to_string()
    }

    fn category(&self) -> &str {
        "database"
    }

    async fn execute(&self, parameters: &HashMap<String, Value>) -> Result<String> {
        let mut conn = REDIS_POOL.get_connection().await?;
        let key = parameters
            .get("key")
            .and_then(|v| v.as_str())
            .ok_or_else(|| anyhow::anyhow!("Missing required parameter: key"))?;
        let deleted: i32 = conn.del(key)?;
        if deleted > 0 {
            Ok(format!("Successfully deleted key '{}'", key))
        } else {
            Ok(format!("Key '{}' not found", key))
        }
    }
}

/// Redis Keys Skill
#[derive(Debug)]
pub struct RedisKeysSkill;

#[async_trait::async_trait]
impl Skill for RedisKeysSkill {
    fn name(&self) -> &str {
        "redis_keys"
    }

    fn description(&self) -> &str {
        "Find keys matching a pattern in Redis"
    }

    fn usage_hint(&self) -> &str {
        "Use this skill when the user needs to list keys in Redis"
    }

    fn parameters(&self) -> Vec<SkillParameter> {
        vec![SkillParameter {
            name: "pattern".to_string(),
            param_type: "string".to_string(),
            description: "Key pattern (e.g., user:*)".to_string(),
            required: false,
            default: Some(Value::String("*".to_string())),
            example: Some(Value::String("user:*".to_string())),
            enum_values: None,
        }]
    }

    fn example_call(&self) -> Value {
        json!({
            "action": "redis_keys",
            "parameters": {
                "pattern": "user:*"
            }
        })
    }

    fn example_output(&self) -> String {
        r#"["user:100", "user:101", "user:102"]"#.to_string()
    }

    fn category(&self) -> &str {
        "database"
    }

    async fn execute(&self, parameters: &HashMap<String, Value>) -> Result<String> {
        let mut conn = REDIS_POOL.get_connection().await?;
        let pattern = parameters
            .get("pattern")
            .and_then(|v| v.as_str())
            .unwrap_or("*");
        let keys: Vec<String> = conn.keys(pattern)?;
        Ok(json!(keys).to_string())
    }
}

/// Redis Hash Set Skill
#[derive(Debug)]
pub struct RedisHSetSkill;

#[async_trait::async_trait]
impl Skill for RedisHSetSkill {
    fn name(&self) -> &str {
        "redis_hset"
    }

    fn description(&self) -> &str {
        "Set a field in a Redis hash"
    }

    fn usage_hint(&self) -> &str {
        "Use this skill when the user needs to store structured data in Redis"
    }

    fn parameters(&self) -> Vec<SkillParameter> {
        vec![
            SkillParameter {
                name: "key".to_string(),
                param_type: "string".to_string(),
                description: "Hash key".to_string(),
                required: true,
                default: None,
                example: Some(Value::String("user:100".to_string())),
                enum_values: None,
            },
            SkillParameter {
                name: "field".to_string(),
                param_type: "string".to_string(),
                description: "Field name".to_string(),
                required: true,
                default: None,
                example: Some(Value::String("name".to_string())),
                enum_values: None,
            },
            SkillParameter {
                name: "value".to_string(),
                param_type: "string".to_string(),
                description: "Value to set".to_string(),
                required: true,
                default: None,
                example: Some(Value::String("John Doe".to_string())),
                enum_values: None,
            },
        ]
    }

    fn example_call(&self) -> Value {
        json!({
            "action": "redis_hset",
            "parameters": {
                "key": "user:100",
                "field": "name",
                "value": "John Doe"
            }
        })
    }

    fn example_output(&self) -> String {
        "Successfully set field 'name' in hash 'user:100'".to_string()
    }

    fn category(&self) -> &str {
        "database"
    }

    async fn execute(&self, parameters: &HashMap<String, Value>) -> Result<String> {
        let mut conn = REDIS_POOL.get_connection().await?;
        let key = parameters
            .get("key")
            .and_then(|v| v.as_str())
            .ok_or_else(|| anyhow::anyhow!("Missing required parameter: key"))?;
        let field = parameters
            .get("field")
            .and_then(|v| v.as_str())
            .ok_or_else(|| anyhow::anyhow!("Missing required parameter: field"))?;
        let value = parameters
            .get("value")
            .and_then(|v| v.as_str())
            .ok_or_else(|| anyhow::anyhow!("Missing required parameter: value"))?;
        let _: i32 = conn.hset(key, field, value)?;
        Ok(format!(
            "Successfully set field '{}' in hash '{}'",
            field, key
        ))
    }
}

/// Redis Hash Get Skill
#[derive(Debug)]
pub struct RedisHGetSkill;

#[async_trait::async_trait]
impl Skill for RedisHGetSkill {
    fn name(&self) -> &str {
        "redis_hget"
    }

    fn description(&self) -> &str {
        "Get a field from a Redis hash"
    }

    fn usage_hint(&self) -> &str {
        "Use this skill when the user needs to retrieve structured data from Redis"
    }

    fn parameters(&self) -> Vec<SkillParameter> {
        vec![
            SkillParameter {
                name: "key".to_string(),
                param_type: "string".to_string(),
                description: "Hash key".to_string(),
                required: true,
                default: None,
                example: Some(Value::String("user:100".to_string())),
                enum_values: None,
            },
            SkillParameter {
                name: "field".to_string(),
                param_type: "string".to_string(),
                description: "Field name".to_string(),
                required: true,
                default: None,
                example: Some(Value::String("name".to_string())),
                enum_values: None,
            },
        ]
    }

    fn example_call(&self) -> Value {
        json!({
            "action": "redis_hget",
            "parameters": {
                "key": "user:100",
                "field": "name"
            }
        })
    }

    fn example_output(&self) -> String {
        "John Doe".to_string()
    }

    fn category(&self) -> &str {
        "database"
    }

    async fn execute(&self, parameters: &HashMap<String, Value>) -> Result<String> {
        let mut conn = REDIS_POOL.get_connection().await?;
        let key = parameters
            .get("key")
            .and_then(|v| v.as_str())
            .ok_or_else(|| anyhow::anyhow!("Missing required parameter: key"))?;
        let field = parameters
            .get("field")
            .and_then(|v| v.as_str())
            .ok_or_else(|| anyhow::anyhow!("Missing required parameter: field"))?;
        let value: Option<String> = conn.hget(key, field)?;
        match value {
            Some(v) => Ok(v),
            None => Ok("null".to_string()),
        }
    }
}