(
args: &serde_json::Value,
ctx: &ToolContext,
)
| 178 | } |
| 179 | |
| 180 | async fn load_script_source( |
| 181 | args: &serde_json::Value, |
| 182 | ctx: &ToolContext, |
| 183 | ) -> std::result::Result<String, String> { |
| 184 | if let Some(source) = args.get("source").and_then(|value| value.as_str()) { |
| 185 | return Ok(source.to_string()); |
| 186 | } |
| 187 | |
| 188 | let Some(path) = args.get("path").and_then(|value| value.as_str()) else { |
| 189 | return Err("program script requires either source or path".to_string()); |
| 190 | }; |
| 191 | if !(path.ends_with(".js") || path.ends_with(".mjs")) { |
| 192 | return Err("program script path must point to a .js or .mjs file".to_string()); |
| 193 | } |
| 194 | |
| 195 | let workspace_path = ctx |
| 196 | .resolve_workspace_path(path) |
| 197 | .map_err(|err| format!("failed to resolve script path: {err}"))?; |
| 198 | ctx.workspace_services |
| 199 | .fs() |
| 200 | .read_text(&workspace_path) |
| 201 | .await |
| 202 | .map_err(|err| format!("failed to read script path '{}': {err}", path)) |
| 203 | } |
| 204 | |
| 205 | fn script_allowed_tools(args: &serde_json::Value, registry: &ToolRegistry) -> HashSet<String> { |
| 206 | let mut allowed = args |
no test coverage detected