diff --git a/libs/shinkai-tools-runner/src/tools/deno_execution_storage.rs b/libs/shinkai-tools-runner/src/tools/deno_execution_storage.rs index a50ef13..9c27095 100644 --- a/libs/shinkai-tools-runner/src/tools/deno_execution_storage.rs +++ b/libs/shinkai-tools-runner/src/tools/deno_execution_storage.rs @@ -3,8 +3,8 @@ use std::{ path::{self, PathBuf}, }; -use super::execution_context::ExecutionContext; use super::path_buf_ext::PathBufExt; +use super::{execution_context::ExecutionContext, file_name_utils::sanitize_for_file_name}; use nanoid::nanoid; #[derive(Default, Clone)] @@ -26,14 +26,20 @@ pub struct DenoExecutionStorage { impl DenoExecutionStorage { pub fn new(context: ExecutionContext) -> Self { let code_id = format!("{}-{}", context.code_id, nanoid!()); - let root = - path::absolute(context.storage.join(context.context_id.clone()).clone()).unwrap(); + let root = path::absolute( + context + .storage + .join(sanitize_for_file_name(context.context_id.clone())) + .clone(), + ) + .unwrap(); let root_code = path::absolute(root.join("code")).unwrap(); let code = path::absolute(root_code.join(code_id.clone())).unwrap(); let logs = path::absolute(root.join("logs")).unwrap(); let log_file = path::absolute(logs.join(format!( "log_{}_{}.log", - context.context_id, context.execution_id, + sanitize_for_file_name(context.context_id.clone()), + sanitize_for_file_name(context.execution_id.clone()) ))) .unwrap(); let deno_cache = path::absolute(root.join("deno-cache")).unwrap(); diff --git a/libs/shinkai-tools-runner/src/tools/file_name_utils.rs b/libs/shinkai-tools-runner/src/tools/file_name_utils.rs new file mode 100644 index 0000000..2475318 --- /dev/null +++ b/libs/shinkai-tools-runner/src/tools/file_name_utils.rs @@ -0,0 +1,4 @@ + +pub fn sanitize_for_file_name(file_name: String) -> String { + file_name.replace(|c: char| !c.is_alphanumeric() && c != '-' && c != '_', "") +} diff --git a/libs/shinkai-tools-runner/src/tools/mod.rs b/libs/shinkai-tools-runner/src/tools/mod.rs index 66ce53a..7c0f20f 100644 --- a/libs/shinkai-tools-runner/src/tools/mod.rs +++ b/libs/shinkai-tools-runner/src/tools/mod.rs @@ -7,4 +7,5 @@ pub mod execution_error; pub mod run_result; pub mod tool; pub mod tool_definition; -mod path_buf_ext; \ No newline at end of file +mod path_buf_ext; +mod file_name_utils;