fix: use get_work_path() instead of get_stack_path()+data/system for work dir, add etag check for PROMPT.md downloads
All checks were successful
BotServer CI/CD / build (push) Successful in 3m37s
All checks were successful
BotServer CI/CD / build (push) Successful in 3m37s
This commit is contained in:
parent
a4a3837c4c
commit
f4c99030aa
3 changed files with 49 additions and 41 deletions
|
|
@ -144,15 +144,11 @@ fn associate_tool_with_session(
|
||||||
use crate::core::shared::models::schema::session_tool_associations;
|
use crate::core::shared::models::schema::session_tool_associations;
|
||||||
|
|
||||||
// Check if tool's .mcp.json file exists in work directory
|
// Check if tool's .mcp.json file exists in work directory
|
||||||
// Use relative path from botserver binary current directory
|
let work_root = crate::core::shared::utils::get_work_path();
|
||||||
let gb_dir =
|
|
||||||
std::path::PathBuf::from(crate::core::shared::utils::get_stack_path()).join("data/system");
|
|
||||||
|
|
||||||
// Get bot name to construct the path
|
// Get bot name to construct the path
|
||||||
let bot_name = get_bot_name_from_id(state, &user.bot_id)?;
|
let bot_name = get_bot_name_from_id(state, &user.bot_id)?;
|
||||||
let work_path = Path::new(&gb_dir)
|
let work_path = Path::new(&work_root).join(format!("{}.gbai/{}.gbdialog", bot_name, bot_name));
|
||||||
.join("work")
|
|
||||||
.join(format!("{}.gbai/{}.gbdialog", bot_name, bot_name));
|
|
||||||
let mcp_path = work_path.join(format!("{}.mcp.json", tool_name));
|
let mcp_path = work_path.join(format!("{}.mcp.json", tool_name));
|
||||||
|
|
||||||
trace!("Checking for tool .mcp.json at: {:?}", mcp_path);
|
trace!("Checking for tool .mcp.json at: {:?}", mcp_path);
|
||||||
|
|
|
||||||
|
|
@ -35,19 +35,16 @@ pub fn get_session_tools(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build path to work/{bot_name}.gbai/{bot_name}.gbdialog directory
|
// Build path to work/{bot_name}.gbai/{bot_name}.gbdialog directory
|
||||||
// Use relative path from botserver binary location
|
let work_root = std::path::PathBuf::from(crate::core::shared::utils::get_work_path());
|
||||||
let gb_dir =
|
|
||||||
std::path::PathBuf::from(crate::core::shared::utils::get_stack_path()).join("data/system");
|
|
||||||
|
|
||||||
// Ensure work directory exists (create if not)
|
// Ensure work directory exists (create if not)
|
||||||
let work_base = gb_dir.join("work");
|
if !work_root.exists() {
|
||||||
if !work_base.exists() {
|
std::fs::create_dir_all(&work_root)
|
||||||
std::fs::create_dir_all(&work_base)
|
.map_err(|e| format!("Failed to create work directory {:?}: {}", work_root, e))?;
|
||||||
.map_err(|e| format!("Failed to create work directory {:?}: {}", work_base, e))?;
|
info!("Created work directory at: {:?}", work_root);
|
||||||
info!("Created work directory at: {:?}", work_base);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let work_path = work_base.join(format!("{}.gbai/{}.gbdialog", bot_name, bot_name));
|
let work_path = work_root.join(format!("{}.gbai/{}.gbdialog", bot_name, bot_name));
|
||||||
|
|
||||||
info!(
|
info!(
|
||||||
"Loading {} tools for session {} from {:?}",
|
"Loading {} tools for session {} from {:?}",
|
||||||
|
|
|
||||||
|
|
@ -600,7 +600,17 @@ impl DriveMonitor {
|
||||||
}
|
}
|
||||||
|
|
||||||
if is_prompt_file {
|
if is_prompt_file {
|
||||||
// Download prompt file to work directory
|
// Check etag to avoid re-downloading unchanged prompt files
|
||||||
|
let etag = obj.e_tag().unwrap_or_default().to_string();
|
||||||
|
let prompt_state_key = format!("__prompt__{}", path);
|
||||||
|
let should_download = {
|
||||||
|
let states = self.file_states.read().await;
|
||||||
|
match states.get(&prompt_state_key) {
|
||||||
|
Some(prev) => prev.etag != etag,
|
||||||
|
None => true,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
if should_download {
|
||||||
match client.get_object().bucket(&self.bucket_name).key(&path).send().await {
|
match client.get_object().bucket(&self.bucket_name).key(&path).send().await {
|
||||||
Ok(response) => {
|
Ok(response) => {
|
||||||
let bytes = response.body.collect().await?.into_bytes();
|
let bytes = response.body.collect().await?.into_bytes();
|
||||||
|
|
@ -630,6 +640,11 @@ impl DriveMonitor {
|
||||||
log::error!("Failed to download prompt file {}: {}", path, e);
|
log::error!("Failed to download prompt file {}: {}", path, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
let mut states = self.file_states.write().await;
|
||||||
|
states.insert(prompt_state_key, FileState { etag, indexed: false });
|
||||||
|
} else {
|
||||||
|
trace!("Prompt file {} unchanged (etag match), skipping download", path);
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue