Skip to content

Commit

Permalink
get rid of integrations.yaml code
Browse files Browse the repository at this point in the history
  • Loading branch information
olegklimov committed Dec 20, 2024
1 parent 48f2c00 commit 5db2b5f
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 86 deletions.
2 changes: 1 addition & 1 deletion python_binding_and_cmdline/refact/cli_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ async def welcome_message(settings: cli_settings.CmdlineArgs, tip: str):
text = f"""
~/.cache/refact/cli.yaml -- set up this program
~/.cache/refact/bring-your-own-key.yaml -- set up models you want to use
~/.cache/refact/integrations.yaml -- set up github, jira, make, gdb, and other tools, including which actions require confirmation
~/.cache/refact/integrations.d/* -- set up github, jira, make, gdb, and other tools, including which actions require confirmation
~/.cache/refact/privacy.yaml -- which files should never leave your computer
Project: {settings.project_path}
To exit, type 'exit' or Ctrl+D. {tip}.
Expand Down
4 changes: 2 additions & 2 deletions src/global_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ pub struct CommandLine {
#[structopt(long, short="w", default_value="", help="Workspace folder to find all the files. An LSP or HTTP request can override this later.")]
pub workspace_folder: String,

#[structopt(long, help="create manually bring-your-own-key.yaml, integrations.yaml, customization.yaml and privacy.yaml and EXIT")]
#[structopt(long, help="create manually bring-your-own-key.yaml, customization.yaml and privacy.yaml and exit.")]
pub only_create_yaml_configs: bool,
#[structopt(long, help="Print combined customization settings from both system defaults and customization.yaml.")]
pub print_customization: bool,
Expand All @@ -93,7 +93,7 @@ pub struct CommandLine {
#[structopt(long, help="A way to tell this binary it can run more tools without confirmation.")]
pub inside_container: bool,

#[structopt(long, default_value="", help="Specify an alternative integrations.yaml, this also disables the global integrations.d")]
#[structopt(long, default_value="", help="Specify the integrations.yaml, this also disables the global integrations.d")]
pub integrations_yaml: String,
}

Expand Down
4 changes: 2 additions & 2 deletions src/http/routers/v1/links.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ pub async fn handle_v1_links(
// GIT uncommitted
if post.meta.chat_mode == ChatMode::AGENT {
let commits = get_commit_information_from_current_changes(gcx.clone()).await;

let mut project_changes = Vec::new();
for commit in &commits {
project_changes.push(format!(
Expand Down Expand Up @@ -133,7 +133,7 @@ pub async fn handle_v1_links(
}
}

// Failures above
// Failures in integrations
if post.meta.chat_mode == ChatMode::AGENT {
for failed_integr_name in failed_integration_names_after_last_user_message(&post.messages) {
links.push(Link {
Expand Down
2 changes: 1 addition & 1 deletion src/integrations/integr_pdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ async fn start_pdb_session(
timeout_seconds: u64,
) -> Result<String, String> {
if !(command_args.len() >= 3 && command_args[0] == "python" && command_args[1] == "-m" && command_args[2] == "pdb") {
return Err("Usage: python -m pdb ... To use a different Python environment, set `python_path` in `integrations.yaml`.".to_string());
return Err("Usage: python -m pdb ... To use a different Python environment, use a path to python binary.".to_string());
}
command_args.remove(0);

Expand Down
6 changes: 1 addition & 5 deletions src/integrations/setting_up_integrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,10 +269,6 @@ pub fn read_integrations_d(
pub async fn get_integrations_yaml_path(gcx: Arc<ARwLock<GlobalContext>>) -> String {
let gcx_locked = gcx.read().await;
let r = gcx_locked.cmdline.integrations_yaml.clone();
// if r.is_empty() {
// let config_dir = gcx_locked.config_dir.join("integrations.yaml");
// return config_dir.to_string_lossy().to_string();
// }
r
}

Expand Down Expand Up @@ -433,7 +429,7 @@ pub async fn integration_config_get(
pub async fn integration_config_save(
integr_config_path: &String,
integr_values: &serde_json::Value,
) -> Result<(), String> {
) -> Result<(), String> {
let config_path = crate::files_correction::canonical_path(integr_config_path);
let (integr_name, _project_path) = crate::integrations::setting_up_integrations::split_path_into_project_and_integration(&config_path)
.map_err(|e| format!("Failed to split path: {}", e))?;
Expand Down
77 changes: 2 additions & 75 deletions src/tools/tools_description.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use std::path::PathBuf;
use std::collections::HashMap;
use std::sync::Arc;
use indexmap::IndexMap;
Expand Down Expand Up @@ -102,50 +101,19 @@ pub trait Tool: Send + Sync {
}
}

pub async fn read_integrations_yaml(config_dir: &PathBuf) -> Result<serde_yaml::Value, String> {
let yaml_path = config_dir.join("integrations.yaml");

let file = std::fs::File::open(&yaml_path).map_err(
|e| format!("Failed to open {}: {}", yaml_path.display(), e)
)?;

let reader = std::io::BufReader::new(file);
serde_yaml::from_reader(reader).map_err(
|e| {
let location = e.location().map(|loc| format!(" at line {}, column {}", loc.line(), loc.column())).unwrap_or_default();
format!("Failed to parse {}{}: {}", yaml_path.display(), location, e)
}
)
}

pub async fn tools_merged_and_filtered(
gcx: Arc<ARwLock<GlobalContext>>,
_supports_clicks: bool, // XXX
) -> Result<IndexMap<String, Arc<AMutex<Box<dyn Tool + Send>>>>, String> {
let (ast_on, vecdb_on, allow_experimental, config_dir) = {
let (ast_on, vecdb_on, allow_experimental) = {
let gcx_locked = gcx.read().await;
#[cfg(feature="vecdb")]
let vecdb_on = gcx_locked.vec_db.lock().await.is_some();
#[cfg(not(feature="vecdb"))]
let vecdb_on = false;
(gcx_locked.ast_service.is_some(), vecdb_on, gcx_locked.cmdline.experimental, gcx_locked.config_dir.clone())
};

let integrations_value = match read_integrations_yaml(&config_dir).await {
Ok(value) => value,
Err(e) => return Err(format!("Problem in integrations.yaml: {}", e)),
(gcx_locked.ast_service.is_some(), vecdb_on, gcx_locked.cmdline.experimental)
};

if let Some(env_vars) = integrations_value.get("environment_variables") {
if let Some(env_vars_map) = env_vars.as_mapping() {
for (key, value) in env_vars_map {
if let (Some(key_str), Some(value_str)) = (key.as_str(), value.as_str()) {
std::env::set_var(key_str, value_str);
}
}
}
}

let mut tools_all = IndexMap::from([
("definition".to_string(), Arc::new(AMutex::new(Box::new(crate::tools::tool_ast_definition::ToolAstDefinition{}) as Box<dyn Tool + Send>))),
("references".to_string(), Arc::new(AMutex::new(Box::new(crate::tools::tool_ast_reference::ToolAstReference{}) as Box<dyn Tool + Send>))),
Expand All @@ -164,47 +132,6 @@ pub async fn tools_merged_and_filtered(
#[cfg(feature="vecdb")]
tools_all.insert("knowledge".to_string(), Arc::new(AMutex::new(Box::new(crate::tools::tool_knowledge::ToolGetKnowledge{}) as Box<dyn Tool + Send>)));

if allow_experimental {
// The approach here: if it exists, it shouldn't have syntax errors, note the "?"
// if let Some(gh_config) = integrations_value.get("github") {
// tools_all.insert("github".to_string(), Arc::new(AMutex::new(Box::new(ToolGithub::new_from_yaml(gh_config)?) as Box<dyn Tool + Send>)));
// }
// if let Some(gl_config) = integrations_value.get("gitlab") {
// tools_all.insert("gitlab".to_string(), Arc::new(AMutex::new(Box::new(ToolGitlab::new_from_yaml(gl_config)?) as Box<dyn Tool + Send>)));
// }
// if let Some(pdb_config) = integrations_value.get("pdb") {
// tools_all.insert("pdb".to_string(), Arc::new(AMutex::new(Box::new(ToolPdb::new_from_yaml(pdb_config)?) as Box<dyn Tool + Send>)));
// }
// if let Some(chrome_config) = integrations_value.get("chrome") {
// tools_all.insert("chrome".to_string(), Arc::new(AMutex::new(Box::new(ToolChrome::new_from_yaml(chrome_config, supports_clicks)?) as Box<dyn Tool + Send>)));
// }
// if let Some(postgres_config) = integrations_value.get("postgres") {
// tools_all.insert("postgres".to_string(), Arc::new(AMutex::new(Box::new(ToolPostgres::new_from_yaml(postgres_config)?) as Box<dyn Tool + Send>)));
// }
// if let Some(docker_config) = integrations_value.get("docker") {
// tools_all.insert("docker".to_string(), Arc::new(AMutex::new(Box::new(ToolDocker::new_from_yaml(docker_config)?) as Box<dyn Tool + Send>)));
// }
// if let Ok(caps) = crate::global_context::try_load_caps_quickly_if_not_present(gcx.clone(), 0).await {
// let have_thinking_model = {
// let caps_locked = caps.read().unwrap();
// caps_locked.running_models.contains(&"o1-mini".to_string())
// };
// if have_thinking_model {
// tools_all.insert("deep_thinking".to_string(), Arc::new(AMutex::new(Box::new(crate::tools::tool_deep_thinking::ToolDeepThinking{}) as Box<dyn Tool + Send>)));
// }
// }
}

// if let Some(cmdline) = integrations_value.get("cmdline") {
// let cmdline_tools = crate::tools::tool_cmdline::cmdline_tool_from_yaml_value(cmdline, false)?;
// tools_all.extend(cmdline_tools);
// }

// if let Some(cmdline) = integrations_value.get("cmdline_services") {
// let cmdline_tools = crate::tools::tool_cmdline::cmdline_tool_from_yaml_value(cmdline, true)?;
// tools_all.extend(cmdline_tools);
// }

let integrations = crate::integrations::running_integrations::load_integration_tools(
gcx.clone(),
"".to_string(),
Expand Down

0 comments on commit 5db2b5f

Please sign in to comment.