stynx_code_tools/infrastructure/
team_create_tool.rs1use stynx_code_errors::AppResult;
2use stynx_code_types::{PermissionLevel, Tool};
3use serde_json::{Value, json};
4
5pub struct TeamCreateTool;
6
7impl TeamCreateTool {
8 pub fn new() -> Self {
9 Self
10 }
11}
12
13#[async_trait::async_trait]
14impl Tool for TeamCreateTool {
15 fn name(&self) -> &str {
16 "team_create"
17 }
18
19 fn description(&self) -> &str {
20 "Create a new agent team with a name and description. Returns a generated team ID."
21 }
22
23 fn input_schema(&self) -> Value {
24 json!({
25 "type": "object",
26 "properties": {
27 "name": {
28 "type": "string",
29 "description": "Name for the new team"
30 },
31 "description": {
32 "type": "string",
33 "description": "Description of the team's purpose"
34 }
35 },
36 "required": ["name", "description"]
37 })
38 }
39
40 fn permission_level(&self) -> PermissionLevel {
41 PermissionLevel::Dangerous
42 }
43
44 async fn execute(&self, input: Value) -> AppResult<String> {
45 let name = input
46 .get("name")
47 .and_then(|v| v.as_str())
48 .ok_or_else(|| stynx_code_errors::AppError::Tool("missing 'name' field".into()))?;
49
50 let description = input
51 .get("description")
52 .and_then(|v| v.as_str())
53 .ok_or_else(|| stynx_code_errors::AppError::Tool("missing 'description' field".into()))?;
54
55 let team_id = format!("team-{:08x}", rand_id());
56
57 tracing::info!(name, description, team_id, "creating team (stub)");
58
59 Ok(format!("Team created.\n id: {team_id}\n name: {name}\n description: {description}"))
60 }
61}
62
63fn rand_id() -> u32 {
64 use std::collections::hash_map::DefaultHasher;
65 use std::hash::{Hash, Hasher};
66 let mut h = DefaultHasher::new();
67 std::time::SystemTime::now().hash(&mut h);
68 h.finish() as u32
69}