From ffc78bfa853aee10e596738f758881226ed10be8 Mon Sep 17 00:00:00 2001 From: Nico Arqueros Date: Sun, 22 Dec 2024 13:12:33 +0530 Subject: [PATCH] bump code runner --- Cargo.lock | 4 +- Cargo.toml | 2 +- .../shinkai-node/src/managers/tool_router.rs | 84 +++++++++---------- 3 files changed, 44 insertions(+), 46 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b01c7004c..a6d53baca 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6847,9 +6847,9 @@ dependencies = [ [[package]] name = "shinkai_tools_runner" -version = "0.9.5" +version = "0.9.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48c57bb4f0f17afa717610da76132fade98dd41b01ef9d46a4323b53c66ab728" +checksum = "ed2fe0b6aa10cd6dcfafd165c2691d494ef14bb1243ed2881ddd2d2dd1b7f787" dependencies = [ "anyhow", "base64-simd", diff --git a/Cargo.toml b/Cargo.toml index d0802962a..13194ccf2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -48,7 +48,7 @@ chrono = "0.4" serde_json = "1.0.117" anyhow = "1.0" blake3 = "1.2.0" -shinkai_tools_runner = "0.9.5" +shinkai_tools_runner = "0.9.6" serde = "1.0.188" base64 = "0.22.0" reqwest = "0.11.27" diff --git a/shinkai-bin/shinkai-node/src/managers/tool_router.rs b/shinkai-bin/shinkai-node/src/managers/tool_router.rs index 5e5a60764..34495f25e 100644 --- a/shinkai-bin/shinkai-node/src/managers/tool_router.rs +++ b/shinkai-bin/shinkai-node/src/managers/tool_router.rs @@ -69,49 +69,7 @@ impl ToolRouter { .map_err(|e| ToolError::DatabaseError(e.to_string()))?; } - // Import tools - async fn import_tools_from_directory(db: Arc) -> Result<(), ToolError> { - let url = env::var("SHINKAI_TOOLS_DIRECTORY_URL") - .map_err(|_| ToolError::MissingConfigError("SHINKAI_TOOLS_DIRECTORY_URL not set".to_string()))?; - - let response = reqwest::get(url) - .await - .map_err(|e| ToolError::RequestError(e))?; - - if response.status() != 200 { - return Err(ToolError::ExecutionError(format!("Import tools request returned a non OK status: {}", response.status()))); - } - - let tools: Vec = response - .json() - .await - .map_err(|e| ToolError::ParseError(format!("Failed to parse tools directory: {}", e)))?; - - for tool in tools { - let tool_url = tool["file"] - .as_str() - .ok_or_else(|| ToolError::ParseError("Missing or invalid file URL in tool definition".to_string()))?; - - let tool_name = tool["name"] - .as_str() - .unwrap_or("unknown"); - - match Node::v2_api_import_tool_internal( - db.clone(), - fetch_node_environment(), - tool_url.to_string(), - ) - .await - { - Ok(_) => println!("Successfully imported tool {}", tool_name), - Err(e) => eprintln!("Failed to import tool {}: {:#?}", tool_name, e), - } - } - - Ok(()) - } - - if let Err(e) = import_tools_from_directory(self.sqlite_manager.clone()).await { + if let Err(e) = Self::import_tools_from_directory(self.sqlite_manager.clone()).await { eprintln!("Error importing tools from directory: {}", e); } @@ -142,6 +100,40 @@ impl ToolRouter { Ok(()) } + async fn import_tools_from_directory(db: Arc) -> Result<(), ToolError> { + let url = env::var("SHINKAI_TOOLS_DIRECTORY_URL") + .map_err(|_| ToolError::MissingConfigError("SHINKAI_TOOLS_DIRECTORY_URL not set".to_string()))?; + + let response = reqwest::get(url).await.map_err(|e| ToolError::RequestError(e))?; + + if response.status() != 200 { + return Err(ToolError::ExecutionError(format!( + "Import tools request returned a non OK status: {}", + response.status() + ))); + } + + let tools: Vec = response + .json() + .await + .map_err(|e| ToolError::ParseError(format!("Failed to parse tools directory: {}", e)))?; + + for tool in tools { + let tool_url = tool["file"] + .as_str() + .ok_or_else(|| ToolError::ParseError("Missing or invalid file URL in tool definition".to_string()))?; + + let tool_name = tool["name"].as_str().unwrap_or("unknown"); + + match Node::v2_api_import_tool_internal(db.clone(), fetch_node_environment(), tool_url.to_string()).await { + Ok(_) => println!("Successfully imported tool {}", tool_name), + Err(e) => eprintln!("Failed to import tool {}: {:#?}", tool_name, e), + } + } + + Ok(()) + } + pub async fn add_static_prompts(&self, _generator: &Box) -> Result<(), ToolError> { // Check if ONLY_TESTING_PROMPTS is set if env::var("ONLY_TESTING_PROMPTS").unwrap_or_default() == "1" @@ -224,9 +216,15 @@ impl ToolRouter { { for (name, definition) in tools { + // Skip tools that start with "demo" if not only_testing_js_tools + if !only_testing_js_tools && name.starts_with("demo") { + continue; + } + // Skip tools that are not in the allowed list if only_testing_js_tools is true if only_testing_js_tools && !allowed_tools.contains(&name.as_str()) { continue; // Skip tools that are not in the allowed list } + println!("Adding JS tool: {}", name); let toolkit = JSToolkit::new(&name, vec![definition.clone()]);