(
args: &serde_json::Value,
inputs: serde_json::Value,
registry: Arc<ToolRegistry>,
ctx: &ToolContext,
)
| 130 | } |
| 131 | |
| 132 | async fn execute_script_program( |
| 133 | args: &serde_json::Value, |
| 134 | inputs: serde_json::Value, |
| 135 | registry: Arc<ToolRegistry>, |
| 136 | ctx: &ToolContext, |
| 137 | ) -> Result<ToolOutput> { |
| 138 | let language = args |
| 139 | .get("language") |
| 140 | .and_then(|value| value.as_str()) |
| 141 | .unwrap_or("javascript"); |
| 142 | if language != "javascript" { |
| 143 | return Ok(ToolOutput::error(format!( |
| 144 | "Unsupported script language: {language}" |
| 145 | ))); |
| 146 | } |
| 147 | |
| 148 | let source = match load_script_source(args, ctx).await { |
| 149 | Ok(source) => source, |
| 150 | Err(message) => return Ok(ToolOutput::error(message)), |
| 151 | }; |
| 152 | if source.len() > MAX_SCRIPT_SOURCE_BYTES { |
| 153 | return Ok(ToolOutput::error(format!( |
| 154 | "script source is too large: {} bytes exceeds {} bytes", |
| 155 | source.len(), |
| 156 | MAX_SCRIPT_SOURCE_BYTES |
| 157 | ))); |
| 158 | } |
| 159 | if let Err(message) = validate_script_source(&source) { |
| 160 | return Ok(ToolOutput::error(message)); |
| 161 | } |
| 162 | |
| 163 | let allowed_tools = script_allowed_tools(args, ®istry); |
| 164 | let limits = script_limits(args); |
| 165 | match run_quickjs_script( |
| 166 | &source, |
| 167 | inputs, |
| 168 | registry, |
| 169 | ctx.clone(), |
| 170 | allowed_tools, |
| 171 | limits, |
| 172 | ) |
| 173 | .await |
| 174 | { |
| 175 | Ok(output) => Ok(output), |
| 176 | Err(err) => Ok(ToolOutput::error(format!("program script failed: {err}"))), |
| 177 | } |
| 178 | } |
| 179 | |
| 180 | async fn load_script_source( |
| 181 | args: &serde_json::Value, |
no test coverage detected