fix(runtime,hands): 4项根因修复 — URL编码/Browser桩/定时解析/LLM超时
Some checks failed
CI / Lint & TypeCheck (push) Has been cancelled
CI / Unit Tests (push) Has been cancelled
CI / Build Frontend (push) Has been cancelled
CI / Rust Check (push) Has been cancelled
CI / Security Scan (push) Has been cancelled
CI / E2E Tests (push) Has been cancelled
Some checks failed
CI / Lint & TypeCheck (push) Has been cancelled
CI / Unit Tests (push) Has been cancelled
CI / Build Frontend (push) Has been cancelled
CI / Rust Check (push) Has been cancelled
CI / Security Scan (push) Has been cancelled
CI / E2E Tests (push) Has been cancelled
1. researcher.rs: url_encode() chars→bytes,修复中文搜索URL编码 (U+533B→%533B 改为 UTF-8 %E5%8C%BB) 2. browser.rs: WebDriver不可用时返回明确错误而非静默成功, 防止LLM误以为操作已完成 3. nl_schedule.rs: 新增相对延迟解析(秒后/分钟后/小时后), 避免fallback到LLM幻觉cron 4. 4个LLM driver: 移除http1_only()防reqwest解码错误, 超时120s→300s适配工具调用链,Anthropic裸Client::new()补全配置
This commit is contained in:
@@ -22,7 +22,12 @@ pub struct AnthropicDriver {
|
||||
impl AnthropicDriver {
|
||||
pub fn new(api_key: SecretString) -> Self {
|
||||
Self {
|
||||
client: Client::new(),
|
||||
client: Client::builder()
|
||||
.user_agent(crate::USER_AGENT)
|
||||
.timeout(std::time::Duration::from_secs(300))
|
||||
.connect_timeout(std::time::Duration::from_secs(30))
|
||||
.build()
|
||||
.unwrap_or_else(|_| Client::new()),
|
||||
api_key,
|
||||
base_url: "https://api.anthropic.com".to_string(),
|
||||
}
|
||||
@@ -30,7 +35,12 @@ impl AnthropicDriver {
|
||||
|
||||
pub fn with_base_url(api_key: SecretString, base_url: String) -> Self {
|
||||
Self {
|
||||
client: Client::new(),
|
||||
client: Client::builder()
|
||||
.user_agent(crate::USER_AGENT)
|
||||
.timeout(std::time::Duration::from_secs(300))
|
||||
.connect_timeout(std::time::Duration::from_secs(30))
|
||||
.build()
|
||||
.unwrap_or_else(|_| Client::new()),
|
||||
api_key,
|
||||
base_url,
|
||||
}
|
||||
|
||||
@@ -30,8 +30,7 @@ impl GeminiDriver {
|
||||
Self {
|
||||
client: Client::builder()
|
||||
.user_agent(crate::USER_AGENT)
|
||||
.http1_only()
|
||||
.timeout(std::time::Duration::from_secs(120))
|
||||
.timeout(std::time::Duration::from_secs(300))
|
||||
.connect_timeout(std::time::Duration::from_secs(30))
|
||||
.build()
|
||||
.unwrap_or_else(|_| Client::new()),
|
||||
@@ -44,8 +43,7 @@ impl GeminiDriver {
|
||||
Self {
|
||||
client: Client::builder()
|
||||
.user_agent(crate::USER_AGENT)
|
||||
.http1_only()
|
||||
.timeout(std::time::Duration::from_secs(120))
|
||||
.timeout(std::time::Duration::from_secs(300))
|
||||
.connect_timeout(std::time::Duration::from_secs(30))
|
||||
.build()
|
||||
.unwrap_or_else(|_| Client::new()),
|
||||
|
||||
@@ -29,7 +29,6 @@ impl LocalDriver {
|
||||
Self {
|
||||
client: Client::builder()
|
||||
.user_agent(crate::USER_AGENT)
|
||||
.http1_only()
|
||||
.timeout(std::time::Duration::from_secs(300)) // 5 min -- local inference can be slow
|
||||
.connect_timeout(std::time::Duration::from_secs(10)) // short connect timeout
|
||||
.build()
|
||||
|
||||
@@ -24,9 +24,8 @@ impl OpenAiDriver {
|
||||
Self {
|
||||
client: Client::builder()
|
||||
.user_agent(crate::USER_AGENT)
|
||||
.http1_only()
|
||||
.timeout(std::time::Duration::from_secs(120)) // 2 minute timeout
|
||||
.connect_timeout(std::time::Duration::from_secs(30)) // 30 second connect timeout
|
||||
.timeout(std::time::Duration::from_secs(300))
|
||||
.connect_timeout(std::time::Duration::from_secs(30))
|
||||
.build()
|
||||
.unwrap_or_else(|_| Client::new()),
|
||||
api_key,
|
||||
@@ -38,9 +37,8 @@ impl OpenAiDriver {
|
||||
Self {
|
||||
client: Client::builder()
|
||||
.user_agent(crate::USER_AGENT)
|
||||
.http1_only()
|
||||
.timeout(std::time::Duration::from_secs(120)) // 2 minute timeout
|
||||
.connect_timeout(std::time::Duration::from_secs(30)) // 30 second connect timeout
|
||||
.timeout(std::time::Duration::from_secs(300))
|
||||
.connect_timeout(std::time::Duration::from_secs(30))
|
||||
.build()
|
||||
.unwrap_or_else(|_| Client::new()),
|
||||
api_key,
|
||||
|
||||
@@ -113,6 +113,11 @@ static RE_INTERVAL: LazyLock<Regex> = LazyLock::new(|| {
|
||||
Regex::new(r"每(\d{1,2})(小时|分钟|分|钟|个小时)").expect("static regex pattern is valid")
|
||||
});
|
||||
|
||||
// try_relative_delay — "X秒后", "X分钟后", "X小时后"
|
||||
static RE_RELATIVE_DELAY: LazyLock<Regex> = LazyLock::new(|| {
|
||||
Regex::new(r"(\d{1,3})\s*(秒|秒钟|分钟|分|小时|个?小时)后").expect("static regex pattern is valid")
|
||||
});
|
||||
|
||||
// try_monthly
|
||||
static RE_MONTHLY: LazyLock<Regex> = LazyLock::new(|| {
|
||||
Regex::new(&format!(
|
||||
@@ -222,6 +227,9 @@ pub fn parse_nl_schedule(input: &str, default_agent_id: &AgentId) -> SchedulePar
|
||||
if let Some(result) = try_one_shot(input, &task_description, default_agent_id) {
|
||||
return result;
|
||||
}
|
||||
if let Some(result) = try_relative_delay(input, &task_description, default_agent_id) {
|
||||
return result;
|
||||
}
|
||||
|
||||
ScheduleParseResult::Unclear
|
||||
}
|
||||
@@ -470,6 +478,34 @@ fn try_one_shot(input: &str, task_desc: &str, agent_id: &AgentId) -> Option<Sche
|
||||
None
|
||||
}
|
||||
|
||||
/// Parse relative delay expressions like "10秒后", "5分钟后", "2小时后".
|
||||
/// Converts to ISO-8601 timestamp from now.
|
||||
fn try_relative_delay(input: &str, task_desc: &str, agent_id: &AgentId) -> Option<ScheduleParseResult> {
|
||||
let caps = RE_RELATIVE_DELAY.captures(input)?;
|
||||
let amount: i64 = caps.get(1)?.as_str().parse().ok()?;
|
||||
if amount <= 0 || amount > 999 {
|
||||
return None;
|
||||
}
|
||||
|
||||
let unit = caps.get(2)?.as_str();
|
||||
let (seconds, desc_unit) = match unit {
|
||||
"秒" | "秒钟" => (amount, "秒"),
|
||||
"分钟" | "分" => (amount * 60, "分钟"),
|
||||
"小时" | "个小时" => (amount * 3600, "小时"),
|
||||
_ => return None,
|
||||
};
|
||||
|
||||
let target = chrono::Utc::now() + chrono::Duration::seconds(seconds);
|
||||
|
||||
Some(ScheduleParseResult::Exact(ParsedSchedule {
|
||||
cron_expression: target.to_rfc3339(),
|
||||
natural_description: format!("{}{}后", amount, desc_unit),
|
||||
confidence: 0.92,
|
||||
task_description: task_desc.to_string(),
|
||||
task_target: TaskTarget::Agent(agent_id.to_string()),
|
||||
}))
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Schedule intent detection
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -478,7 +514,7 @@ fn try_one_shot(input: &str, task_desc: &str, agent_id: &AgentId) -> Option<Sche
|
||||
const SCHEDULE_INTENT_KEYWORDS: &[&str] = &[
|
||||
"提醒我", "提醒", "定时", "每天", "每日", "每周", "每月",
|
||||
"工作日", "每隔", "每", "定期", "到时候", "准时",
|
||||
"闹钟", "闹铃", "日程", "日历",
|
||||
"闹钟", "闹铃", "日程", "日历", "秒后", "分钟后", "小时后",
|
||||
];
|
||||
|
||||
/// Check if user input contains schedule intent.
|
||||
@@ -731,4 +767,40 @@ mod tests {
|
||||
_ => panic!("Expected Exact, got {:?}", result),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_relative_delay_seconds() {
|
||||
let result = parse_nl_schedule("30秒后提醒我", &default_agent());
|
||||
match result {
|
||||
ScheduleParseResult::Exact(s) => {
|
||||
assert!(s.natural_description.contains("30秒"));
|
||||
assert!(s.confidence >= 0.9);
|
||||
}
|
||||
_ => panic!("Expected Exact, got {:?}", result),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_relative_delay_minutes() {
|
||||
let result = parse_nl_schedule("5分钟后提醒我喝水", &default_agent());
|
||||
match result {
|
||||
ScheduleParseResult::Exact(s) => {
|
||||
assert!(s.natural_description.contains("5分钟"));
|
||||
// task_description preserves the original text minus schedule keywords
|
||||
assert!(s.task_description.contains("喝水"));
|
||||
}
|
||||
_ => panic!("Expected Exact, got {:?}", result),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_relative_delay_hours() {
|
||||
let result = parse_nl_schedule("2小时后提醒我开会", &default_agent());
|
||||
match result {
|
||||
ScheduleParseResult::Exact(s) => {
|
||||
assert!(s.natural_description.contains("2小时"));
|
||||
}
|
||||
_ => panic!("Expected Exact, got {:?}", result),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user