Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin' into feature/oauth
Browse files Browse the repository at this point in the history
  • Loading branch information
acedward committed Dec 18, 2024
2 parents d445939 + 2276be9 commit be38863
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 22 deletions.
28 changes: 14 additions & 14 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ members = [
resolver = "2"

[workspace.package]
version = "0.9.2"
version = "0.9.3"
edition = "2021"
authors = ["Nico Arqueros <[email protected]>"]

Expand Down Expand Up @@ -57,4 +57,4 @@ uuid = { version = "1.6.1" }
rand = "=0.8.5"
chrono-tz = "0.5"
hex = "=0.4.3"
env_logger = "0.11.5"
env_logger = "0.11.5"
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ impl Node {
let mut perm_file_path = PathBuf::from(storage_path.clone());
perm_file_path.push(".tools_storage");
perm_file_path.push("tools");
perm_file_path.push(shinkai_tool.tool_router_key());
perm_file_path.push(shinkai_tool.tool_router_key_path());
if let Err(err) = std::fs::create_dir_all(&perm_file_path) {
let api_error = APIError {
code: StatusCode::INTERNAL_SERVER_ERROR.as_u16(),
Expand Down Expand Up @@ -1543,7 +1543,7 @@ impl Node {
let assets = PathBuf::from(&node_env.node_storage_path.unwrap_or_default())
.join(".tools_storage")
.join("tools")
.join(tool.tool_router_key());
.join(tool.tool_router_key_path());
if assets.exists() {
for entry in std::fs::read_dir(assets).unwrap() {
let entry = entry.unwrap();
Expand Down Expand Up @@ -1726,7 +1726,7 @@ impl Node {
let mut file_path = PathBuf::from(&node_env.node_storage_path.clone().unwrap_or_default())
.join(".tools_storage")
.join("tools")
.join(tool.tool_router_key());
.join(tool.tool_router_key_path());
if !file_path.exists() {
let s = std::fs::create_dir_all(&file_path);
if s.is_err() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::time::{SystemTime, UNIX_EPOCH};
use std::{env, thread};

use super::parameters::Parameters;
use super::shinkai_tool::ShinkaiTool;
use super::tool_config::{OAuth, ToolConfig};
use super::tool_output_arg::ToolOutputArg;
use super::tool_playground::{SqlQuery, SqlTable};
Expand Down Expand Up @@ -81,7 +82,7 @@ impl DenoTool {
let path = PathBuf::from(&node_storage_path)
.join(".tools_storage")
.join("tools")
.join(tool_router_key);
.join(ShinkaiTool::convert_to_path(&tool_router_key));
self.assets
.clone()
.unwrap_or(vec![])
Expand Down
12 changes: 10 additions & 2 deletions shinkai-libs/shinkai-tools-primitives/src/tools/python_tools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use tokio::runtime::Runtime;
use super::deno_tools::ToolResult;
use super::parameters::Parameters;
use super::shared_execution::update_result_with_modified_files;
use super::shinkai_tool::ShinkaiTool;
use super::tool_config::{OAuth, ToolConfig};
use super::tool_output_arg::ToolOutputArg;
use super::tool_playground::{SqlQuery, SqlTable};
Expand Down Expand Up @@ -80,7 +81,7 @@ impl PythonTool {
let path = PathBuf::from(&node_storage_path)
.join(".tools_storage")
.join("tools")
.join(tool_router_key);
.join(ShinkaiTool::convert_to_path(&tool_router_key));
self.assets
.clone()
.unwrap_or(vec![])
Expand Down Expand Up @@ -261,7 +262,14 @@ impl PythonTool {
if result.is_err() {
return result;
}
update_result_with_modified_files(result.unwrap(), start_time, &home_path, &logs_path, &node_name, &app_id)
update_result_with_modified_files(
result.unwrap(),
start_time,
&home_path,
&logs_path,
&node_name,
&app_id,
)
})
})
.unwrap()
Expand Down
20 changes: 20 additions & 0 deletions shinkai-libs/shinkai-tools-primitives/src/tools/shinkai_tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,26 @@ impl ShinkaiTool {
}
}

// Return a folder-safe version of the tool_router_key
pub fn tool_router_key_path(&self) -> String {
let path = self.tool_router_key();
Self::convert_to_path(&path)
}

pub fn convert_to_path(tool_router_key: &str) -> String {
tool_router_key
.chars()
.map(|c| {
if c.is_ascii_alphanumeric() || c == '-' || c == '_' {
c
} else {
'_'
}
})
.collect::<String>()
.to_lowercase()
}

/// The key that this tool will be stored under in the tool router
pub fn tool_router_key(&self) -> String {
match self {
Expand Down

0 comments on commit be38863

Please sign in to comment.