From a957712590ca04194ff64f7a7f56f1999a703280 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=A8=E7=82=8E?= <635735027@qq.com> Date: Mon, 13 Apr 2026 15:03:49 +0800 Subject: [PATCH] fix: add target_url param for Action::Eval in browser_script_skill_tool MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🤖 Generated with [Qoder][https://qoder.com] --- src/compat/browser_script_skill_tool.rs | 49 +++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 4 deletions(-) diff --git a/src/compat/browser_script_skill_tool.rs b/src/compat/browser_script_skill_tool.rs index 2bdfe0b..caec565 100644 --- a/src/compat/browser_script_skill_tool.rs +++ b/src/compat/browser_script_skill_tool.rs @@ -154,11 +154,26 @@ fn execute_browser_script_impl( browser_tool: &dyn BrowserBackend, args: Value, ) -> anyhow::Result { + eprintln!("[execute_browser_script_impl] 开始执行"); + eprintln!("[execute_browser_script_impl] tool.name: {}", tool.name); + eprintln!("[execute_browser_script_impl] tool.command: {}", tool.command); + eprintln!("[execute_browser_script_impl] skill_root: {:?}", skill_root); + eprintln!("[execute_browser_script_impl] args: {:?}", args); + let script_path = resolve_browser_script_path(skill_root, &tool.command)?; + eprintln!("[execute_browser_script_impl] script_path: {:?}", script_path); + + // 检查脚本文件是否存在 + if !script_path.exists() { + eprintln!("[execute_browser_script_impl] 脚本文件不存在!"); + } else { + eprintln!("[execute_browser_script_impl] 脚本文件存在"); + } let mut args = match args { Value::Object(args) => args, other => { + eprintln!("[execute_browser_script_impl] args 不是 Object: {:?}", other); return Ok(failed_tool_result(format!( "expected object arguments, got {other}" ))) @@ -168,27 +183,34 @@ fn execute_browser_script_impl( let raw_expected_domain = match args.remove("expected_domain") { Some(Value::String(value)) if !value.trim().is_empty() => value, Some(other) => { + eprintln!("[execute_browser_script_impl] expected_domain 格式错误: {:?}", other); return Ok(failed_tool_result(format!( "expected_domain must be a non-empty string, got {other}" ))) } None => { + eprintln!("[execute_browser_script_impl] 缺少 expected_domain"); return Ok(failed_tool_result( "missing required field expected_domain".to_string(), )) } }; + eprintln!("[execute_browser_script_impl] raw_expected_domain: {}", raw_expected_domain); + let expected_domain = match normalize_domain_like(&raw_expected_domain) { Some(value) => value, None => { + eprintln!("[execute_browser_script_impl] expected_domain 解析失败"); return Ok(failed_tool_result(format!( "expected_domain must resolve to a hostname, got {raw_expected_domain:?}" ))) } }; + eprintln!("[execute_browser_script_impl] expected_domain: {}", expected_domain); for required_arg in tool.args.keys() { if !args.contains_key(required_arg) { + eprintln!("[execute_browser_script_impl] 缺少必需参数: {}", required_arg); return Ok(failed_tool_result(format!( "missing required field {required_arg}" ))); @@ -196,8 +218,12 @@ fn execute_browser_script_impl( } let script_body = match fs::read_to_string(&script_path) { - Ok(value) => value, + Ok(value) => { + eprintln!("[execute_browser_script_impl] 脚本读取成功, 长度: {} 字节", value.len()); + value + } Err(err) => { + eprintln!("[execute_browser_script_impl] 脚本读取失败: {}", err); return Ok(failed_tool_result(format!( "failed to read browser script {}: {err}", script_path.display() @@ -206,16 +232,30 @@ fn execute_browser_script_impl( }; let wrapped_script = wrap_browser_script(&script_body, &Value::Object(args.clone())); + eprintln!("[execute_browser_script_impl] 包装后脚本长度: {} 字节", wrapped_script.len()); + eprintln!("[execute_browser_script_impl] 调用 browser_tool.invoke(Action::Eval)..."); + + let target_url = format!("http://{}", expected_domain); let result = match browser_tool.invoke( Action::Eval, - json!({ "script": wrapped_script }), + json!({ + "script": wrapped_script, + "target_url": target_url, + }), &expected_domain, ) { - Ok(result) => result, - Err(err) => return Ok(failed_tool_result(err.to_string())), + Ok(result) => { + eprintln!("[execute_browser_script_impl] invoke 成功, result.success: {}", result.success); + result + } + Err(err) => { + eprintln!("[execute_browser_script_impl] invoke 失败: {}", err); + return Ok(failed_tool_result(err.to_string())) + } }; if !result.success { + eprintln!("[execute_browser_script_impl] result.success=false, data: {:?}", result.data); return Ok(failed_tool_result(format_browser_script_error(&result.data))); } @@ -224,6 +264,7 @@ fn execute_browser_script_impl( .get("text") .cloned() .unwrap_or_else(|| result.data.clone()); + eprintln!("[execute_browser_script_impl] 返回成功, payload 长度: {:?}", payload.to_string().len()); Ok(ToolResult { success: true, output: stringify_tool_payload(&payload)?,