Clear windows and fix build failure (#5452)

Co-authored-by: Douwe Osinga <douwe@squareup.com>
This commit is contained in:
Douwe Osinga
2025-10-30 12:54:05 -04:00
committed by GitHub
parent cb2303107d
commit 1fb72dc805
+29 -28
View File
@@ -479,40 +479,41 @@ async fn agent_add_extension(
State(state): State<Arc<AppState>>, State(state): State<Arc<AppState>>,
Json(request): Json<AddExtensionRequest>, Json(request): Json<AddExtensionRequest>,
) -> Result<StatusCode, ErrorResponse> { ) -> Result<StatusCode, ErrorResponse> {
// If this is a Stdio extension that uses npx, check for Node.js installation if cfg!(target_os = "windows") {
#[cfg(target_os = "windows")] if let ExtensionConfig::Stdio { cmd, .. } = &request.config {
if let ExtensionConfig::Stdio { cmd, .. } = &request.config { if cmd.ends_with("npx.cmd") || cmd.ends_with("npx") {
if cmd.ends_with("npx.cmd") || cmd.ends_with("npx") { let node_exists = std::path::Path::new(r"C:\Program Files\nodejs\node.exe")
let node_exists = std::path::Path::new(r"C:\Program Files\nodejs\node.exe").exists() .exists()
|| std::path::Path::new(r"C:\Program Files (x86)\nodejs\node.exe").exists(); || std::path::Path::new(r"C:\Program Files (x86)\nodejs\node.exe").exists();
if !node_exists { if !node_exists {
let cmd_path = std::path::Path::new(&cmd); let cmd_path = std::path::Path::new(&cmd);
let script_dir = cmd_path.parent().ok_or(StatusCode::INTERNAL_SERVER_ERROR)?; let script_dir = cmd_path
let install_script = script_dir.join("install-node.cmd"); .parent()
.ok_or_else(|| ErrorResponse::internal("Invalid command path"))?;
let install_script = script_dir.join("install-node.cmd");
if install_script.exists() { if install_script.exists() {
eprintln!("Installing Node.js..."); eprintln!("Installing Node.js...");
let output = std::process::Command::new(&install_script) let output = std::process::Command::new(&install_script)
.arg("https://nodejs.org/dist/v23.10.0/node-v23.10.0-x64.msi") .arg("https://nodejs.org/dist/v23.10.0/node-v23.10.0-x64.msi")
.output() .output()
.map_err(|e| { .map_err(|_e| {
eprintln!("Failed to run Node.js installer: {}", e); ErrorResponse::internal("Failed to run Node.js installer")
StatusCode::INTERNAL_SERVER_ERROR })?;
})?;
if !output.status.success() { if !output.status.success() {
return Err(ErrorResponse::internal(format!(
"Failed to install Node.js: {}",
String::from_utf8_lossy(&output.stderr)
)));
}
} else {
return Err(ErrorResponse::internal(format!( return Err(ErrorResponse::internal(format!(
"Failed to install Node.js: {}", "Node.js not detected and no installer script not found at: {}",
String::from_utf8_lossy(&output.stderr) install_script.display()
))); )));
} }
eprintln!("Node.js installation completed");
} else {
return Err(ErrorResponse::internal(format!(
"Node.js not detected and no installer script not found at: {}",
install_script.display()
)));
} }
} }
} }