Skip to content

Commit

Permalink
Merge pull request #846 from dcSpark/feature/rust-node
Browse files Browse the repository at this point in the history
Added runner/os/tool-set fields to tools
  • Loading branch information
nicarq authored Feb 5, 2025
2 parents b995c8c + 4521b90 commit e473dcd
Show file tree
Hide file tree
Showing 19 changed files with 1,005 additions and 165 deletions.
4 changes: 4 additions & 0 deletions shinkai-bin/shinkai-node/src/network/handle_commands_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2384,6 +2384,8 @@ impl Node {
app_id,
llm_provider,
mounts,
runner,
operating_system,
res,
} => {
let db_clone = Arc::clone(&self.db);
Expand All @@ -2403,6 +2405,8 @@ impl Node {
llm_provider,
node_name,
mounts,
runner,
operating_system,
res,
)
.await;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,43 +1,61 @@
use crate::{
llm_provider::job_manager::JobManager, managers::IdentityManager, network::{node_error::NodeError, node_shareable_logic::download_zip_file, Node}, tools::{
tool_definitions::definition_generation::{generate_tool_definitions, get_all_deno_tools}, tool_execution::execution_coordinator::{execute_code, execute_tool_cmd}, tool_generation::v2_create_and_send_job_message, tool_prompts::{generate_code_prompt, tool_metadata_implementation_prompt}
}, utils::environment::NodeEnvironment
llm_provider::job_manager::JobManager,
managers::IdentityManager,
network::{node_error::NodeError, node_shareable_logic::download_zip_file, Node},
tools::{
tool_definitions::definition_generation::{generate_tool_definitions, get_all_deno_tools},
tool_execution::execution_coordinator::{execute_code, execute_tool_cmd},
tool_generation::v2_create_and_send_job_message,
tool_prompts::{generate_code_prompt, tool_metadata_implementation_prompt},
},
utils::environment::NodeEnvironment,
};

use async_channel::Sender;
use chrono::Utc;
use ed25519_dalek::{ed25519::signature::SignerMut, SigningKey};
use reqwest::StatusCode;
use serde_json::{json, Map, Value};

use shinkai_http_api::node_api_router::{APIError, SendResponseBodyData};
use shinkai_message_primitives::{
schemas::{
inbox_name::InboxName, indexable_version::IndexableVersion, job::JobLike, job_config::JobConfig, shinkai_name::ShinkaiSubidentityType, tool_router_key::ToolRouterKey
}, shinkai_message::shinkai_message_schemas::{CallbackAction, JobCreationInfo, MessageSchemaType}, shinkai_utils::{shinkai_message_builder::ShinkaiMessageBuilder, signatures::clone_signature_secret_key}
inbox_name::InboxName, indexable_version::IndexableVersion, job::JobLike, job_config::JobConfig,
shinkai_name::ShinkaiSubidentityType, tool_router_key::ToolRouterKey,
},
shinkai_message::shinkai_message_schemas::{CallbackAction, JobCreationInfo, MessageSchemaType},
shinkai_utils::{shinkai_message_builder::ShinkaiMessageBuilder, signatures::clone_signature_secret_key},
};
use shinkai_message_primitives::{
schemas::{
shinkai_name::ShinkaiName, shinkai_tools::{CodeLanguage, DynamicToolType}
}, shinkai_message::shinkai_message_schemas::JobMessage
shinkai_name::ShinkaiName,
shinkai_tools::{CodeLanguage, DynamicToolType},
},
shinkai_message::shinkai_message_schemas::JobMessage,
};
use shinkai_sqlite::{errors::SqliteManagerError, SqliteManager};
use shinkai_tools_primitives::tools::tool_types::{OperatingSystem, RunnerType};
use shinkai_tools_primitives::tools::{
deno_tools::DenoTool, error::ToolError, python_tools::PythonTool, shinkai_tool::{ShinkaiTool, ShinkaiToolWithAssets}, tool_config::{OAuth, ToolConfig}, tool_output_arg::ToolOutputArg, tool_playground::ToolPlayground
deno_tools::DenoTool,
error::ToolError,
python_tools::PythonTool,
shinkai_tool::{ShinkaiTool, ShinkaiToolWithAssets},
tool_config::{OAuth, ToolConfig},
tool_output_arg::ToolOutputArg,
tool_playground::ToolPlayground,
};

use std::path::PathBuf;
use std::{
collections::HashMap, env, fs::File, io::{Read, Write}, sync::Arc, time::Instant
collections::HashMap,
env,
fs::File,
io::{Read, Write},
sync::Arc,
time::Instant,
};
use tokio::fs;
use tokio::{process::Command, sync::Mutex};
use zip::{write::FileOptions, ZipWriter};

use x25519_dalek::PublicKey as EncryptionPublicKey;
use x25519_dalek::StaticSecret as EncryptionStaticKey;

use chrono::Utc;

use std::path::PathBuf;
use tokio::fs;
use zip::{write::FileOptions, ZipWriter};

impl Node {
/// Searches for Shinkai tools using both vector and full-text search (FTS)
Expand Down Expand Up @@ -505,6 +523,9 @@ impl Node {
sql_queries: Some(payload.metadata.sql_queries),
file_inbox: None,
assets: payload.assets.clone(),
runner: payload.metadata.runner,
operating_system: payload.metadata.operating_system,
tool_set: payload.metadata.tool_set,
};
ShinkaiTool::Deno(tool, false)
}
Expand All @@ -529,6 +550,9 @@ impl Node {
sql_queries: Some(payload.metadata.sql_queries),
file_inbox: None,
assets: payload.assets.clone(),
runner: payload.metadata.runner,
operating_system: payload.metadata.operating_system,
tool_set: payload.metadata.tool_set,
};
ShinkaiTool::Python(tool, false)
}
Expand Down Expand Up @@ -882,6 +906,8 @@ impl Node {
llm_provider: String,
node_name: ShinkaiName,
mounts: Option<Vec<String>>,
runner: Option<RunnerType>,
operating_system: Option<Vec<OperatingSystem>>,
res: Sender<Result<Value, APIError>>,
) -> Result<(), NodeError> {
if Self::validate_bearer_token(&bearer, db.clone(), &res).await.is_err() {
Expand Down Expand Up @@ -909,6 +935,8 @@ impl Node {
bearer,
node_name,
mounts,
runner,
operating_system,
)
.await;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,35 +1,32 @@
use crate::llm_provider::job_manager::JobManager;
use crate::managers::IdentityManager;
use crate::tools::tool_definitions::definition_generation::generate_tool_definitions;
use crate::tools::tool_execution::execution_custom::try_to_execute_rust_tool;
use crate::tools::tool_execution::execution_deno_dynamic::{check_deno_tool, execute_deno_tool};
use crate::tools::tool_execution::execution_header_generator::{check_tool, generate_execution_environment};
use crate::tools::tool_execution::execution_python_dynamic::execute_python_tool;
use crate::utils::environment::fetch_node_environment;

use base64::{engine::general_purpose::URL_SAFE_NO_PAD, Engine};
use chrono::Utc;
use ed25519_dalek::SigningKey;
use regex::Regex;
use reqwest::Client;
use serde_json::json;
use serde_json::{Map, Value};
use sha2::{Digest, Sha256};
use shinkai_message_primitives::schemas::shinkai_name::ShinkaiName;
use shinkai_message_primitives::schemas::shinkai_tools::CodeLanguage;
use shinkai_message_primitives::schemas::shinkai_tools::DynamicToolType;
use shinkai_message_primitives::schemas::tool_router_key::ToolRouterKey;
use shinkai_sqlite::oauth_manager::OAuthToken;
use shinkai_sqlite::SqliteManager;
use shinkai_tools_primitives::tools::error::ToolError;

use shinkai_tools_primitives::tools::shinkai_tool::ShinkaiTool;
use shinkai_tools_primitives::tools::tool_config::{OAuth, ToolConfig};
use tokio::sync::Mutex;

use crate::managers::IdentityManager;
use ed25519_dalek::SigningKey;

use base64::{engine::general_purpose::URL_SAFE_NO_PAD, Engine};
use chrono::Utc;
use regex::Regex;
use reqwest::Client;
use sha2::{Digest, Sha256};
use shinkai_tools_primitives::tools::tool_types::{OperatingSystem, RunnerType};
use std::collections::HashMap;
use std::sync::Arc;
use tokio::sync::Mutex;
use x25519_dalek::PublicKey as EncryptionPublicKey;
use x25519_dalek::StaticSecret as EncryptionStaticKey;

Expand Down Expand Up @@ -418,6 +415,8 @@ pub async fn execute_code(
bearer: String,
node_name: ShinkaiName,
mounts: Option<Vec<String>>,
runner: Option<RunnerType>,
operating_system: Option<Vec<OperatingSystem>>,
) -> Result<Value, ToolError> {
eprintln!("[execute_code] tool_type: {}", tool_type);
// Route based on the prefix
Expand All @@ -439,6 +438,8 @@ pub async fn execute_code(
support_files,
code,
mounts,
runner,
operating_system,
)
.await
}
Expand All @@ -459,6 +460,8 @@ pub async fn execute_code(
support_files,
code,
mounts,
runner,
operating_system,
)
.await
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ use std::path::PathBuf;

use serde_json::{Map, Value};
use shinkai_message_primitives::schemas::shinkai_name::ShinkaiName;
use shinkai_tools_primitives::tools::deno_tools::{DenoTool, ToolResult};
use shinkai_tools_primitives::tools::deno_tools::DenoTool;
use shinkai_tools_primitives::tools::error::ToolError;
use shinkai_tools_primitives::tools::parameters::Parameters;
use shinkai_tools_primitives::tools::tool_config::{OAuth, ToolConfig};
use shinkai_tools_primitives::tools::tool_output_arg::ToolOutputArg;
use shinkai_tools_primitives::tools::tool_types::{OperatingSystem, RunnerType, ToolResult};

use super::execution_header_generator::{check_tool, generate_execution_environment};
use crate::utils::environment::fetch_node_environment;
Expand All @@ -27,6 +28,8 @@ pub async fn execute_deno_tool(
support_files: HashMap<String, String>,
code: String,
mounts: Option<Vec<String>>,
runner: Option<RunnerType>,
operating_system: Option<Vec<OperatingSystem>>,
) -> Result<Value, ToolError> {
// Create a minimal DenoTool instance
let tool = DenoTool {
Expand All @@ -49,6 +52,13 @@ pub async fn execute_deno_tool(
sql_queries: None,
file_inbox: None,
assets: None,
runner: runner.unwrap_or_default(),
operating_system: operating_system.unwrap_or(vec![
OperatingSystem::Linux,
OperatingSystem::MacOS,
OperatingSystem::Windows,
]),
tool_set: None,
};

let env = generate_execution_environment(
Expand Down Expand Up @@ -98,21 +108,24 @@ pub async fn execute_deno_tool(
}
}

match tool.run_on_demand(
env,
node_env.api_listen_address.ip().to_string(),
node_env.api_listen_address.port(),
support_files,
parameters,
extra_config,
node_storage_path,
app_id.clone(),
tool_id.clone(),
node_name,
false,
assets_files,
mounts,
).await {
match tool
.run_on_demand(
env,
node_env.api_listen_address.ip().to_string(),
node_env.api_listen_address.port(),
support_files,
parameters,
extra_config,
node_storage_path,
app_id.clone(),
tool_id.clone(),
node_name,
false,
assets_files,
mounts,
)
.await
{
Ok(run_result) => Ok(run_result.data),
Err(e) => Err(e),
}
Expand Down Expand Up @@ -145,6 +158,9 @@ pub async fn check_deno_tool(
sql_queries: None,
file_inbox: None,
assets: None,
runner: RunnerType::Any,
operating_system: vec![OperatingSystem::Linux, OperatingSystem::MacOS, OperatingSystem::Windows],
tool_set: None,
};

let node_env = fetch_node_environment();
Expand All @@ -160,5 +176,6 @@ pub async fn check_deno_tool(
node_storage_path,
app_id.clone(),
tool_id.clone(),
).await
)
.await
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ use serde_json::{Map, Value};
use shinkai_message_primitives::schemas::shinkai_name::ShinkaiName;
use shinkai_sqlite::SqliteManager;
use shinkai_tools_primitives::tools::{
deno_tools::ToolResult,
error::ToolError,
parameters::Parameters,
python_tools::PythonTool,
tool_config::{OAuth, ToolConfig},
tool_output_arg::ToolOutputArg,
tool_types::{OperatingSystem, RunnerType, ToolResult},
};
use std::sync::Arc;

Expand All @@ -28,6 +28,8 @@ pub async fn execute_python_tool(
support_files: HashMap<String, String>,
code: String,
mounts: Option<Vec<String>>,
runner: Option<RunnerType>,
operating_system: Option<Vec<OperatingSystem>>,
) -> Result<Value, ToolError> {
// Create a minimal DenoTool instance
let tool = PythonTool {
Expand All @@ -50,6 +52,13 @@ pub async fn execute_python_tool(
file_inbox: None,
oauth: oauth.clone(),
assets: None,
runner: runner.unwrap_or_default(),
operating_system: operating_system.unwrap_or(vec![
OperatingSystem::Linux,
OperatingSystem::MacOS,
OperatingSystem::Windows,
]),
tool_set: None,
};

let env = generate_execution_environment(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,8 @@ mod tests {
use super::*;

use shinkai_embedding::model_type::{EmbeddingModelType, OllamaTextEmbeddingsInference};
use shinkai_tools_primitives::tools::deno_tools::ToolResult;
use shinkai_tools_primitives::tools::tool_config::BasicConfig;
use shinkai_tools_primitives::tools::tool_types::{OperatingSystem, RunnerType, ToolResult};
use shinkai_tools_primitives::tools::{deno_tools::DenoTool, shinkai_tool::ShinkaiTool};
use std::path::PathBuf;
use std::sync::Arc;
Expand Down Expand Up @@ -339,7 +339,6 @@ mod tests {
fn create_deno_tool() -> ShinkaiTool {
let mut initial_tool = ShinkaiTool::Deno(
DenoTool {

name: "Test Tool".to_string(),
homepage: Some("http://127.0.0.1/index.html".to_string()),
author: "Test Author".to_string(),
Expand Down Expand Up @@ -374,6 +373,9 @@ mod tests {
sql_queries: None,
file_inbox: None,
assets: None,
runner: RunnerType::Any,
operating_system: vec![OperatingSystem::Windows],
tool_set: None,
},
true,
);
Expand Down
Loading

0 comments on commit e473dcd

Please sign in to comment.