myagent-ai 1.12.5 → 1.13.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/agents/main_agent.py +5 -1
- package/core/context_builder.py +15 -4
- package/core/deps_checker.py +5 -4
- package/memory/manager.py +11 -11
- package/package.json +1 -1
- package/skills/browser_skill.py +24 -768
- package/skills/chromedev_mcp.py +931 -0
- package/web/ui/chat/chat.css +0 -1
- package/web/ui/chat/chat_main.js +21 -21
- package/web/ui/chat/flow_engine.js +93 -27
package/agents/main_agent.py
CHANGED
|
@@ -454,7 +454,11 @@ class MainAgent(BaseAgent):
|
|
|
454
454
|
)
|
|
455
455
|
if db_history:
|
|
456
456
|
conversation_history = [
|
|
457
|
-
Message(
|
|
457
|
+
Message(
|
|
458
|
+
role=entry.role,
|
|
459
|
+
content=entry.content,
|
|
460
|
+
metadata={"time": (entry.created_at[:19] if entry.created_at else "")}
|
|
461
|
+
)
|
|
458
462
|
for entry in db_history
|
|
459
463
|
]
|
|
460
464
|
logger.info(f"[{task_id}] 从 DB 加载了 {len(conversation_history)} 条历史对话")
|
package/core/context_builder.py
CHANGED
|
@@ -415,7 +415,12 @@ class ContextBuilder:
|
|
|
415
415
|
if not content.strip():
|
|
416
416
|
continue
|
|
417
417
|
label = role_labels.get(role, role)
|
|
418
|
-
|
|
418
|
+
# 从 metadata 中提取时间(DB加载时已附带)
|
|
419
|
+
msg_time = ""
|
|
420
|
+
msg_meta = getattr(msg, "metadata", None)
|
|
421
|
+
if isinstance(msg_meta, dict):
|
|
422
|
+
msg_time = msg_meta.get("time", "")
|
|
423
|
+
filtered_msgs.append((label, content.strip(), msg_time))
|
|
419
424
|
|
|
420
425
|
if not filtered_msgs:
|
|
421
426
|
return "<resentdialog>\n(无对话历史)\n</resentdialog>"
|
|
@@ -439,8 +444,12 @@ class ContextBuilder:
|
|
|
439
444
|
formatted_lines.append(prefix_text)
|
|
440
445
|
formatted_lines.append("") # 空行分隔
|
|
441
446
|
|
|
442
|
-
for label, content in recent_msgs:
|
|
443
|
-
|
|
447
|
+
for label, content, msg_time in recent_msgs:
|
|
448
|
+
# 临时合并时间信息到内容中给 LLM 参考
|
|
449
|
+
if msg_time:
|
|
450
|
+
formatted_lines.append(f"[{label}] [{msg_time}] {_xml_escape(content)}")
|
|
451
|
+
else:
|
|
452
|
+
formatted_lines.append(f"[{label}] {_xml_escape(content)}")
|
|
444
453
|
|
|
445
454
|
dialog_text = "\n".join(formatted_lines)
|
|
446
455
|
|
|
@@ -482,7 +491,9 @@ class ContextBuilder:
|
|
|
482
491
|
return ""
|
|
483
492
|
|
|
484
493
|
summary_parts: List[str] = ["[历史对话摘要]"]
|
|
485
|
-
for
|
|
494
|
+
for item in old_msgs:
|
|
495
|
+
label = item[0]
|
|
496
|
+
content = item[1]
|
|
486
497
|
# 提取第一行或前100字符作为要点
|
|
487
498
|
first_line = content.split("\n")[0].strip()
|
|
488
499
|
if len(first_line) > 100:
|
package/core/deps_checker.py
CHANGED
|
@@ -16,7 +16,8 @@ core/deps_checker.py - 自动依赖检测与安装
|
|
|
16
16
|
系统技能: psutil
|
|
17
17
|
托盘功能: pystray, PIL
|
|
18
18
|
语音合成: edge_tts
|
|
19
|
-
浏览器自动化:
|
|
19
|
+
浏览器自动化: chrome-devtools-mcp (Node.js, Chrome DevTools Protocol)
|
|
20
|
+
(备用) playwright (+ chromium 浏览器二进制)
|
|
20
21
|
桌面GUI自动化: mss, pynput, pygetwindow
|
|
21
22
|
"""
|
|
22
23
|
from __future__ import annotations
|
|
@@ -75,9 +76,9 @@ DEPENDENCIES: List[DepInfo] = [
|
|
|
75
76
|
# ── 语音合成 ──
|
|
76
77
|
DepInfo("edge_tts", "edge-tts", "6.1.0", "tts", "all"),
|
|
77
78
|
|
|
78
|
-
# ── 浏览器自动化 (Playwright) ──
|
|
79
|
+
# ── 浏览器自动化 (ChromeDev MCP + Playwright 备用) ──
|
|
79
80
|
DepInfo("playwright", "playwright", "1.41.0", "browser", "all",
|
|
80
|
-
note="
|
|
81
|
+
note="备用方案。推荐使用 chrome-devtools-mcp (需 Node.js >= 20.19)"),
|
|
81
82
|
|
|
82
83
|
# ── 桌面 GUI 自动化 ──
|
|
83
84
|
DepInfo("mss", "mss", "9.0.0", "gui", "all",
|
|
@@ -413,7 +414,7 @@ def ensure_skill_deps(skill_category: str) -> bool:
|
|
|
413
414
|
|
|
414
415
|
Args:
|
|
415
416
|
skill_category: 技能分类名称
|
|
416
|
-
"browser" - 浏览器自动化 (playwright)
|
|
417
|
+
"browser" - 浏览器自动化 (chrome-devtools-mcp / playwright)
|
|
417
418
|
"gui" - 桌面GUI自动化 (mss, pynput, pygetwindow)
|
|
418
419
|
"search" - 搜索技能
|
|
419
420
|
"tts" - 语音合成
|
package/memory/manager.py
CHANGED
|
@@ -278,17 +278,13 @@ class MemoryManager:
|
|
|
278
278
|
# ==========================================================================
|
|
279
279
|
|
|
280
280
|
def add_session(self, session_id, role="", content="", key="", importance=0.5, metadata=None) -> str:
|
|
281
|
-
"""
|
|
281
|
+
"""添加会话记忆。内容不包含时间前缀,时间仅存于 created_at 和 metadata。"""
|
|
282
282
|
from datetime import datetime as _dt
|
|
283
283
|
_now_str = _dt.now().strftime("%Y-%m-%d %H:%M:%S")
|
|
284
|
-
#
|
|
285
|
-
if role and content and not content.startswith("["):
|
|
286
|
-
timestamped_content = f"[{_now_str}] {content}"
|
|
287
|
-
else:
|
|
288
|
-
timestamped_content = truncate_str(content, 50000)
|
|
284
|
+
# 直接存储原始内容,不再注入时间前缀
|
|
289
285
|
entry = MemoryEntry(
|
|
290
286
|
session_id=session_id, category="session", role=role,
|
|
291
|
-
content=
|
|
287
|
+
content=truncate_str(content, 50000), key=key,
|
|
292
288
|
importance=importance, metadata={"timestamp": _now_str, **(metadata or {})},
|
|
293
289
|
)
|
|
294
290
|
return self._insert(entry)
|
|
@@ -366,7 +362,7 @@ class MemoryManager:
|
|
|
366
362
|
session_id: str,
|
|
367
363
|
limit: int = 50,
|
|
368
364
|
) -> str:
|
|
369
|
-
"""获取对话历史文本(供 LLM 使用)"""
|
|
365
|
+
"""获取对话历史文本(供 LLM 使用),临时合并时间信息"""
|
|
370
366
|
entries = self.get_conversation(session_id, limit)
|
|
371
367
|
lines = []
|
|
372
368
|
for e in entries:
|
|
@@ -379,7 +375,12 @@ class MemoryManager:
|
|
|
379
375
|
label = "系统"
|
|
380
376
|
elif e.role == "tool":
|
|
381
377
|
label = "工具"
|
|
382
|
-
|
|
378
|
+
# 从 created_at 提取时间,临时合并到内容中给 LLM
|
|
379
|
+
time_str = e.created_at[:19] if e.created_at and len(e.created_at) >= 19 else ""
|
|
380
|
+
if time_str:
|
|
381
|
+
lines.append(f"[{label}] [{time_str}] {e.content}")
|
|
382
|
+
else:
|
|
383
|
+
lines.append(f"[{label}] {e.content}")
|
|
383
384
|
return "\n".join(lines)
|
|
384
385
|
|
|
385
386
|
def clear_conversation(self, session_id) -> int:
|
|
@@ -469,11 +470,10 @@ class MemoryManager:
|
|
|
469
470
|
"""添加全局记忆(跨会话可检索)"""
|
|
470
471
|
from datetime import datetime
|
|
471
472
|
now_str = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
|
472
|
-
timestamped_content = f"[{now_str}] {truncate_str(content, 50000)}"
|
|
473
473
|
ts_summary = summary or truncate_str(content, 200)
|
|
474
474
|
entry = MemoryEntry(
|
|
475
475
|
session_id=session_id, category="global", key=key,
|
|
476
|
-
content=
|
|
476
|
+
content=truncate_str(content, 50000), summary=f"[{now_str}] {ts_summary}",
|
|
477
477
|
importance=importance, metadata={"timestamp": now_str, **(metadata or {})},
|
|
478
478
|
)
|
|
479
479
|
return self._insert(entry)
|