优化: run_command 实时流式 + 审批浮窗修复 + 文档探索闭环(fetch_url+obscura引导+model_fetch兼容+prompt策略+厂商预设)

This commit is contained in:
lxy
2026-08-01 17:58:47 +08:00
parent 0e0c6862ba
commit d664bdc309
25 changed files with 1693 additions and 44 deletions
+17 -3
View File
@@ -100,6 +100,7 @@ async fn execute_with_heartbeat(
args: serde_json::Value,
app: &AppHandle,
conv_id: &str,
tool_call_id: &str,
) -> anyhow::Result<serde_json::Value> {
use std::sync::atomic::{AtomicBool, Ordering};
use tokio::time::Duration;
@@ -155,7 +156,20 @@ async fn execute_with_heartbeat(
} else {
60
};
match tokio::time::timeout(Duration::from_secs(outer_secs), tools.execute(name, args)).await {
// run_command 实时流式:经 task-local sink 注入(AppHandle + tool_call_id + conv_id),
// handler 内 execute_streaming 每行 emit AiCommandOutput(治执行中黑盒)。
// 非 run_command 不注入 sink(handler 内 emit_output 静默 noop),零行为变更。
let sink = if name == "run_command" {
Some(crate::commands::ai::command_stream::CommandSink::new(
app.clone(),
tool_call_id.to_string(),
Some(conv_id.to_string()),
))
} else {
None
};
let exec_fut = crate::commands::ai::command_stream::scope(sink, tools.execute(name, args));
match tokio::time::timeout(Duration::from_secs(outer_secs), exec_fut).await {
Ok(result) => result,
Err(_elapsed) => {
tracing::error!(
@@ -460,7 +474,7 @@ pub(crate) async fn process_tool_calls(
let app_clone = app_handle.clone();
let conv_clone = conv_id.to_string();
async move {
let exec_result = execute_with_heartbeat(&tools, &draft.name, args, &app_clone, &conv_clone).await;
let exec_result = execute_with_heartbeat(&tools, &draft.name, args, &app_clone, &conv_clone, &draft.id).await;
match exec_result {
Ok(val) => {
let content = val.to_string();
@@ -573,7 +587,7 @@ pub(crate) async fn process_tool_calls(
let app_clone = app_handle.clone();
let conv_clone = conv_id.to_string();
async move {
let result = execute_with_heartbeat(&tools, &draft.name, args, &app_clone, &conv_clone).await;
let result = execute_with_heartbeat(&tools, &draft.name, args, &app_clone, &conv_clone, &draft.id).await;
match result {
Ok(val) => {
// L3 emit 双写:Low 风险工具执行成功 emit Completed 双路发布。