feat: AI 控制台增强——①de_read_clipboard 剪贴板回读工具;②任务可中断(stop_event 循环检查点 + API stop + 前端■停止按钮);③智能滚动(回看历史不被打断,贴底才跟随);④右侧实时画面(MJPEG 流自动跟随操作设备,可手动选择)
This commit is contained in:
+6
-1
@@ -134,13 +134,15 @@ class Agent:
|
||||
|
||||
# ---------- 主循环(流式) ----------
|
||||
async def run_stream(self, prompt: str, serial: str = "",
|
||||
history=None, on_delta=None, on_tool=None):
|
||||
history=None, on_delta=None, on_tool=None,
|
||||
should_stop=None):
|
||||
"""流式执行一轮指令,返回最终完整文本。
|
||||
|
||||
history:上一轮的 [{"role": "user"|"assistant", "content": 文本}] 列表,
|
||||
用于多轮对话保持上下文(截图/工具消息不入历史,控制 token)。
|
||||
on_delta(text, kind):content/reasoning 文本增量(实时推给前端)
|
||||
on_tool(step):工具调用完成(实时显示 MCP 步骤)
|
||||
should_stop:可调用 fn() -> bool,每轮模型调用前检查(用户中断用)
|
||||
"""
|
||||
self.on_delta = on_delta
|
||||
self.on_tool = on_tool
|
||||
@@ -155,6 +157,9 @@ class Agent:
|
||||
self.messages.append({"role": "user", "content": prompt})
|
||||
|
||||
for _step in range(self.s.max_steps):
|
||||
if should_stop and should_stop():
|
||||
_log.info("Agent 被用户中断")
|
||||
return "(已按用户要求停止操作)"
|
||||
content_parts = []
|
||||
tool_acc = {} # index -> {id, name, args}
|
||||
has_tool = False
|
||||
|
||||
Reference in New Issue
Block a user