Undefined-bot 2.1.0__py3-none-any.whl
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.
- Undefined/__init__.py +3 -0
- Undefined/__main__.py +6 -0
- Undefined/ai.py +1215 -0
- Undefined/config.py +371 -0
- Undefined/end_summary_storage.py +48 -0
- Undefined/faq.py +244 -0
- Undefined/handlers.py +1247 -0
- Undefined/injection_response_agent.py +131 -0
- Undefined/main.py +126 -0
- Undefined/memory.py +120 -0
- Undefined/onebot.py +512 -0
- Undefined/rate_limit.py +130 -0
- Undefined/render.py +123 -0
- Undefined/scheduled_task_storage.py +88 -0
- Undefined/services/__init__.py +1 -0
- Undefined/services/queue_manager.py +206 -0
- Undefined/skills/README.md +53 -0
- Undefined/skills/__init__.py +10 -0
- Undefined/skills/agents/README.md +144 -0
- Undefined/skills/agents/__init__.py +116 -0
- Undefined/skills/agents/entertainment_agent/config.json +17 -0
- Undefined/skills/agents/entertainment_agent/handler.py +220 -0
- Undefined/skills/agents/entertainment_agent/intro.md +25 -0
- Undefined/skills/agents/entertainment_agent/prompt.md +20 -0
- Undefined/skills/agents/entertainment_agent/tools/__init__.py +1 -0
- Undefined/skills/agents/entertainment_agent/tools/ai_draw_one/config.json +34 -0
- Undefined/skills/agents/entertainment_agent/tools/ai_draw_one/handler.py +62 -0
- Undefined/skills/agents/entertainment_agent/tools/ai_study_helper/config.json +22 -0
- Undefined/skills/agents/entertainment_agent/tools/ai_study_helper/handler.py +35 -0
- Undefined/skills/agents/entertainment_agent/tools/get_current_time/config.json +12 -0
- Undefined/skills/agents/entertainment_agent/tools/get_current_time/handler.py +5 -0
- Undefined/skills/agents/entertainment_agent/tools/horoscope/config.json +24 -0
- Undefined/skills/agents/entertainment_agent/tools/horoscope/handler.py +141 -0
- Undefined/skills/agents/entertainment_agent/tools/minecraft_skin/config.json +43 -0
- Undefined/skills/agents/entertainment_agent/tools/minecraft_skin/handler.py +55 -0
- Undefined/skills/agents/entertainment_agent/tools/novel_search/config.json +25 -0
- Undefined/skills/agents/entertainment_agent/tools/novel_search/handler.py +31 -0
- Undefined/skills/agents/entertainment_agent/tools/renjian/config.json +12 -0
- Undefined/skills/agents/entertainment_agent/tools/renjian/handler.py +30 -0
- Undefined/skills/agents/entertainment_agent/tools/wenchang_dijun/config.json +12 -0
- Undefined/skills/agents/entertainment_agent/tools/wenchang_dijun/handler.py +44 -0
- Undefined/skills/agents/file_analysis_agent/__init__.py +1 -0
- Undefined/skills/agents/file_analysis_agent/config.json +21 -0
- Undefined/skills/agents/file_analysis_agent/handler.py +248 -0
- Undefined/skills/agents/file_analysis_agent/intro.md +22 -0
- Undefined/skills/agents/file_analysis_agent/prompt.md +36 -0
- Undefined/skills/agents/file_analysis_agent/tools/__init__.py +1 -0
- Undefined/skills/agents/file_analysis_agent/tools/analyze_code/config.json +17 -0
- Undefined/skills/agents/file_analysis_agent/tools/analyze_code/handler.py +427 -0
- Undefined/skills/agents/file_analysis_agent/tools/analyze_multimodal/config.json +25 -0
- Undefined/skills/agents/file_analysis_agent/tools/analyze_multimodal/handler.py +178 -0
- Undefined/skills/agents/file_analysis_agent/tools/cleanup_temp/config.json +16 -0
- Undefined/skills/agents/file_analysis_agent/tools/cleanup_temp/handler.py +35 -0
- Undefined/skills/agents/file_analysis_agent/tools/detect_file_type/config.json +17 -0
- Undefined/skills/agents/file_analysis_agent/tools/detect_file_type/handler.py +221 -0
- Undefined/skills/agents/file_analysis_agent/tools/download_file/config.json +21 -0
- Undefined/skills/agents/file_analysis_agent/tools/download_file/handler.py +124 -0
- Undefined/skills/agents/file_analysis_agent/tools/extract_archive/config.json +25 -0
- Undefined/skills/agents/file_analysis_agent/tools/extract_archive/handler.py +190 -0
- Undefined/skills/agents/file_analysis_agent/tools/extract_docx/config.json +17 -0
- Undefined/skills/agents/file_analysis_agent/tools/extract_docx/handler.py +78 -0
- Undefined/skills/agents/file_analysis_agent/tools/extract_pdf/config.json +21 -0
- Undefined/skills/agents/file_analysis_agent/tools/extract_pdf/handler.py +67 -0
- Undefined/skills/agents/file_analysis_agent/tools/extract_pptx/config.json +17 -0
- Undefined/skills/agents/file_analysis_agent/tools/extract_pptx/handler.py +73 -0
- Undefined/skills/agents/file_analysis_agent/tools/extract_xlsx/config.json +17 -0
- Undefined/skills/agents/file_analysis_agent/tools/extract_xlsx/handler.py +101 -0
- Undefined/skills/agents/file_analysis_agent/tools/get_current_time/config.json +12 -0
- Undefined/skills/agents/file_analysis_agent/tools/get_current_time/handler.py +5 -0
- Undefined/skills/agents/file_analysis_agent/tools/read_text_file/config.json +21 -0
- Undefined/skills/agents/file_analysis_agent/tools/read_text_file/handler.py +90 -0
- Undefined/skills/agents/info_agent/config.json +17 -0
- Undefined/skills/agents/info_agent/handler.py +220 -0
- Undefined/skills/agents/info_agent/intro.md +22 -0
- Undefined/skills/agents/info_agent/prompt.md +27 -0
- Undefined/skills/agents/info_agent/tools/__init__.py +1 -0
- Undefined/skills/agents/info_agent/tools/baiduhot/config.json +18 -0
- Undefined/skills/agents/info_agent/tools/baiduhot/handler.py +49 -0
- Undefined/skills/agents/info_agent/tools/base64/config.json +22 -0
- Undefined/skills/agents/info_agent/tools/base64/handler.py +44 -0
- Undefined/skills/agents/info_agent/tools/douyinhot/config.json +18 -0
- Undefined/skills/agents/info_agent/tools/douyinhot/handler.py +53 -0
- Undefined/skills/agents/info_agent/tools/get_current_time/config.json +12 -0
- Undefined/skills/agents/info_agent/tools/get_current_time/handler.py +5 -0
- Undefined/skills/agents/info_agent/tools/gold_price/config.json +12 -0
- Undefined/skills/agents/info_agent/tools/gold_price/handler.py +58 -0
- Undefined/skills/agents/info_agent/tools/hash/config.json +22 -0
- Undefined/skills/agents/info_agent/tools/hash/handler.py +43 -0
- Undefined/skills/agents/info_agent/tools/history/config.json +12 -0
- Undefined/skills/agents/info_agent/tools/history/handler.py +37 -0
- Undefined/skills/agents/info_agent/tools/net_check/config.json +17 -0
- Undefined/skills/agents/info_agent/tools/net_check/handler.py +117 -0
- Undefined/skills/agents/info_agent/tools/news_tencent/config.json +17 -0
- Undefined/skills/agents/info_agent/tools/news_tencent/handler.py +38 -0
- Undefined/skills/agents/info_agent/tools/qq_level_query/config.json +29 -0
- Undefined/skills/agents/info_agent/tools/qq_level_query/handler.py +48 -0
- Undefined/skills/agents/info_agent/tools/speed/config.json +17 -0
- Undefined/skills/agents/info_agent/tools/speed/handler.py +37 -0
- Undefined/skills/agents/info_agent/tools/tcping/config.json +21 -0
- Undefined/skills/agents/info_agent/tools/tcping/handler.py +53 -0
- Undefined/skills/agents/info_agent/tools/weather_query/config.json +22 -0
- Undefined/skills/agents/info_agent/tools/weather_query/handler.py +207 -0
- Undefined/skills/agents/info_agent/tools/weibohot/config.json +18 -0
- Undefined/skills/agents/info_agent/tools/weibohot/handler.py +49 -0
- Undefined/skills/agents/info_agent/tools/whois/config.json +17 -0
- Undefined/skills/agents/info_agent/tools/whois/handler.py +63 -0
- Undefined/skills/agents/naga_code_analysis_agent/config.json +17 -0
- Undefined/skills/agents/naga_code_analysis_agent/handler.py +222 -0
- Undefined/skills/agents/naga_code_analysis_agent/intro.md +17 -0
- Undefined/skills/agents/naga_code_analysis_agent/prompt.md +19 -0
- Undefined/skills/agents/naga_code_analysis_agent/tools/__init__.py +1 -0
- Undefined/skills/agents/naga_code_analysis_agent/tools/get_current_time/config.json +12 -0
- Undefined/skills/agents/naga_code_analysis_agent/tools/get_current_time/handler.py +5 -0
- Undefined/skills/agents/naga_code_analysis_agent/tools/glob/config.json +17 -0
- Undefined/skills/agents/naga_code_analysis_agent/tools/glob/handler.py +37 -0
- Undefined/skills/agents/naga_code_analysis_agent/tools/list_directory/config.json +17 -0
- Undefined/skills/agents/naga_code_analysis_agent/tools/list_directory/handler.py +31 -0
- Undefined/skills/agents/naga_code_analysis_agent/tools/read_file/config.json +17 -0
- Undefined/skills/agents/naga_code_analysis_agent/tools/read_file/handler.py +66 -0
- Undefined/skills/agents/naga_code_analysis_agent/tools/read_naga_intro/config.json +12 -0
- Undefined/skills/agents/naga_code_analysis_agent/tools/read_naga_intro/handler.py +327 -0
- Undefined/skills/agents/naga_code_analysis_agent/tools/search_file_content/config.json +25 -0
- Undefined/skills/agents/naga_code_analysis_agent/tools/search_file_content/handler.py +46 -0
- Undefined/skills/agents/scheduler_agent/__init__.py +1 -0
- Undefined/skills/agents/scheduler_agent/config.json +17 -0
- Undefined/skills/agents/scheduler_agent/handler.py +218 -0
- Undefined/skills/agents/scheduler_agent/intro.md +17 -0
- Undefined/skills/agents/scheduler_agent/prompt.md +67 -0
- Undefined/skills/agents/scheduler_agent/tools/__init__.py +1 -0
- Undefined/skills/agents/scheduler_agent/tools/create_schedule_task/config.json +37 -0
- Undefined/skills/agents/scheduler_agent/tools/create_schedule_task/handler.py +68 -0
- Undefined/skills/agents/scheduler_agent/tools/delete_schedule_task/config.json +19 -0
- Undefined/skills/agents/scheduler_agent/tools/delete_schedule_task/handler.py +26 -0
- Undefined/skills/agents/scheduler_agent/tools/get_current_time/config.json +12 -0
- Undefined/skills/agents/scheduler_agent/tools/get_current_time/handler.py +5 -0
- Undefined/skills/agents/scheduler_agent/tools/list_schedule_tasks/config.json +11 -0
- Undefined/skills/agents/scheduler_agent/tools/list_schedule_tasks/handler.py +47 -0
- Undefined/skills/agents/scheduler_agent/tools/update_schedule_task/config.json +39 -0
- Undefined/skills/agents/scheduler_agent/tools/update_schedule_task/handler.py +46 -0
- Undefined/skills/agents/social_agent/config.json +17 -0
- Undefined/skills/agents/social_agent/handler.py +220 -0
- Undefined/skills/agents/social_agent/intro.md +17 -0
- Undefined/skills/agents/social_agent/prompt.md +19 -0
- Undefined/skills/agents/social_agent/tools/__init__.py +1 -0
- Undefined/skills/agents/social_agent/tools/bilibili_search/config.json +21 -0
- Undefined/skills/agents/social_agent/tools/bilibili_search/handler.py +68 -0
- Undefined/skills/agents/social_agent/tools/bilibili_user_info/config.json +17 -0
- Undefined/skills/agents/social_agent/tools/bilibili_user_info/handler.py +68 -0
- Undefined/skills/agents/social_agent/tools/get_current_time/config.json +12 -0
- Undefined/skills/agents/social_agent/tools/get_current_time/handler.py +5 -0
- Undefined/skills/agents/social_agent/tools/music_global_search/config.json +21 -0
- Undefined/skills/agents/social_agent/tools/music_global_search/handler.py +47 -0
- Undefined/skills/agents/social_agent/tools/music_info_get/config.json +22 -0
- Undefined/skills/agents/social_agent/tools/music_info_get/handler.py +35 -0
- Undefined/skills/agents/social_agent/tools/music_lyrics/config.json +22 -0
- Undefined/skills/agents/social_agent/tools/music_lyrics/handler.py +26 -0
- Undefined/skills/agents/social_agent/tools/video_random_recommend/config.json +21 -0
- Undefined/skills/agents/social_agent/tools/video_random_recommend/handler.py +21 -0
- Undefined/skills/agents/web_agent/config.json +17 -0
- Undefined/skills/agents/web_agent/handler.py +221 -0
- Undefined/skills/agents/web_agent/intro.md +14 -0
- Undefined/skills/agents/web_agent/prompt.md +16 -0
- Undefined/skills/agents/web_agent/tools/__init__.py +1 -0
- Undefined/skills/agents/web_agent/tools/crawl_webpage/config.json +21 -0
- Undefined/skills/agents/web_agent/tools/crawl_webpage/handler.py +102 -0
- Undefined/skills/agents/web_agent/tools/get_current_time/config.json +12 -0
- Undefined/skills/agents/web_agent/tools/get_current_time/handler.py +5 -0
- Undefined/skills/agents/web_agent/tools/web_search/config.json +21 -0
- Undefined/skills/agents/web_agent/tools/web_search/handler.py +29 -0
- Undefined/skills/tools/README.md +85 -0
- Undefined/skills/tools/__init__.py +120 -0
- Undefined/skills/tools/debug/config.json +17 -0
- Undefined/skills/tools/debug/handler.py +35 -0
- Undefined/skills/tools/end/config.json +17 -0
- Undefined/skills/tools/end/handler.py +24 -0
- Undefined/skills/tools/get_current_time/config.json +12 -0
- Undefined/skills/tools/get_current_time/handler.py +5 -0
- Undefined/skills/tools/get_forward_msg/config.json +17 -0
- Undefined/skills/tools/get_forward_msg/handler.py +131 -0
- Undefined/skills/tools/get_group_member_info/config.json +38 -0
- Undefined/skills/tools/get_group_member_info/handler.py +142 -0
- Undefined/skills/tools/get_messages_by_time/config.json +30 -0
- Undefined/skills/tools/get_messages_by_time/handler.py +128 -0
- Undefined/skills/tools/get_picture/config.json +45 -0
- Undefined/skills/tools/get_picture/handler.py +191 -0
- Undefined/skills/tools/get_recent_messages/config.json +30 -0
- Undefined/skills/tools/get_recent_messages/handler.py +88 -0
- Undefined/skills/tools/qq_like/config.json +22 -0
- Undefined/skills/tools/qq_like/handler.py +58 -0
- Undefined/skills/tools/render_html/config.json +26 -0
- Undefined/skills/tools/render_html/handler.py +39 -0
- Undefined/skills/tools/render_latex/config.json +26 -0
- Undefined/skills/tools/render_latex/handler.py +78 -0
- Undefined/skills/tools/render_markdown/config.json +26 -0
- Undefined/skills/tools/render_markdown/handler.py +63 -0
- Undefined/skills/tools/save_memory/config.json +17 -0
- Undefined/skills/tools/save_memory/handler.py +17 -0
- Undefined/skills/tools/send_message/config.json +21 -0
- Undefined/skills/tools/send_message/handler.py +60 -0
- Undefined/skills/tools/send_private_message/config.json +21 -0
- Undefined/skills/tools/send_private_message/handler.py +35 -0
- Undefined/utils/__init__.py +0 -0
- Undefined/utils/common.py +186 -0
- Undefined/utils/history.py +284 -0
- Undefined/utils/scheduler.py +286 -0
- Undefined/utils/sender.py +140 -0
- undefined_bot-2.1.0.dist-info/METADATA +259 -0
- undefined_bot-2.1.0.dist-info/RECORD +211 -0
- undefined_bot-2.1.0.dist-info/WHEEL +4 -0
- undefined_bot-2.1.0.dist-info/entry_points.txt +2 -0
- undefined_bot-2.1.0.dist-info/licenses/LICENSE +7 -0
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import subprocess
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
from typing import Any, Dict
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
async def execute(args: Dict[str, Any], context: Dict[str, Any]) -> str:
|
|
7
|
+
pattern = args.get("pattern", "")
|
|
8
|
+
|
|
9
|
+
# 将 base_path 限制在 NagaAgent 子模块中
|
|
10
|
+
base_path = context.get("base_path", Path.cwd() / "code" / "NagaAgent")
|
|
11
|
+
base_path = Path(base_path).resolve()
|
|
12
|
+
|
|
13
|
+
path = str(base_path)
|
|
14
|
+
|
|
15
|
+
cmd = ["find", path, "-type", "f", "-name", pattern]
|
|
16
|
+
|
|
17
|
+
try:
|
|
18
|
+
result = subprocess.run(
|
|
19
|
+
cmd,
|
|
20
|
+
capture_output=True,
|
|
21
|
+
text=True,
|
|
22
|
+
timeout=30,
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
if result.returncode == 0:
|
|
26
|
+
files = result.stdout.strip().split("\n")
|
|
27
|
+
relative_files = [str(Path(f).relative_to(base_path)) for f in files if f]
|
|
28
|
+
if len(relative_files) > 100:
|
|
29
|
+
relative_files = relative_files[:100] + [
|
|
30
|
+
f"... 还有 {len(relative_files) - 100} 个文件"
|
|
31
|
+
]
|
|
32
|
+
return "\n".join(relative_files)
|
|
33
|
+
else:
|
|
34
|
+
return f"未找到匹配的文件: {pattern}"
|
|
35
|
+
|
|
36
|
+
except subprocess.TimeoutExpired:
|
|
37
|
+
return "工具执行超时: glob"
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"type": "function",
|
|
3
|
+
"function": {
|
|
4
|
+
"name": "list_directory",
|
|
5
|
+
"description": "列出目录内容。路径是相对于当前工作目录的。",
|
|
6
|
+
"parameters": {
|
|
7
|
+
"type": "object",
|
|
8
|
+
"properties": {
|
|
9
|
+
"path": {
|
|
10
|
+
"type": "string",
|
|
11
|
+
"description": "目录路径(相对于当前工作目录,默认为根目录)"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"required": []
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
from pathlib import Path
|
|
2
|
+
from typing import Any, Dict
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
async def execute(args: Dict[str, Any], context: Dict[str, Any]) -> str:
|
|
6
|
+
path_str = args.get("path")
|
|
7
|
+
# 将 base_path 限制在 NagaAgent 子模块中
|
|
8
|
+
base_path = context.get("base_path", Path.cwd() / "code" / "NagaAgent")
|
|
9
|
+
base_path = Path(base_path).resolve()
|
|
10
|
+
|
|
11
|
+
if not path_str:
|
|
12
|
+
full_path = base_path
|
|
13
|
+
else:
|
|
14
|
+
# 解析相对于 base_path 的路径
|
|
15
|
+
full_path = (base_path / path_str).resolve()
|
|
16
|
+
|
|
17
|
+
if not str(full_path).startswith(str(base_path)):
|
|
18
|
+
return f"权限不足:只能列出当前工作目录下的内容 ({base_path})"
|
|
19
|
+
|
|
20
|
+
if not full_path.exists():
|
|
21
|
+
return f"目录不存在: {path_str}"
|
|
22
|
+
|
|
23
|
+
items = []
|
|
24
|
+
for item in full_path.iterdir():
|
|
25
|
+
item_type = "📁 " if item.is_dir() else "📄 "
|
|
26
|
+
items.append(f"{item_type}{item.name}")
|
|
27
|
+
|
|
28
|
+
if len(items) > 100:
|
|
29
|
+
items = items[:100] + [f"... 还有 {len(items) - 100} 项"]
|
|
30
|
+
|
|
31
|
+
return "\n".join(items)
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"type": "function",
|
|
3
|
+
"function": {
|
|
4
|
+
"name": "read_file",
|
|
5
|
+
"description": "读取文件内容。路径是相对于当前工作目录的。",
|
|
6
|
+
"parameters": {
|
|
7
|
+
"type": "object",
|
|
8
|
+
"properties": {
|
|
9
|
+
"file_path": {
|
|
10
|
+
"type": "string",
|
|
11
|
+
"description": "文件路径(相对于当前工作目录)"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"required": ["file_path"]
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import chardet
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
from typing import Any, Dict
|
|
4
|
+
import logging
|
|
5
|
+
|
|
6
|
+
logger = logging.getLogger(__name__)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
async def execute(args: Dict[str, Any], context: Dict[str, Any]) -> str:
|
|
10
|
+
# 支持两个参数名以实现兼容性
|
|
11
|
+
file_path = args.get("file_path") or args.get("path", "")
|
|
12
|
+
|
|
13
|
+
if not file_path:
|
|
14
|
+
return "错误:文件路径不能为空"
|
|
15
|
+
|
|
16
|
+
# 将 base_path 限制在 NagaAgent 子模块中
|
|
17
|
+
base_path = context.get("base_path", Path.cwd() / "code" / "NagaAgent")
|
|
18
|
+
base_path = Path(base_path).resolve()
|
|
19
|
+
|
|
20
|
+
# 解析相对于 base_path 的路径
|
|
21
|
+
full_path = (base_path / file_path).resolve()
|
|
22
|
+
|
|
23
|
+
# 安全检查
|
|
24
|
+
if not str(full_path).startswith(str(base_path)):
|
|
25
|
+
return "权限不足:只能读取当前工作目录下的文件"
|
|
26
|
+
|
|
27
|
+
if not full_path.exists():
|
|
28
|
+
return f"文件不存在: {file_path}"
|
|
29
|
+
|
|
30
|
+
if full_path.is_dir():
|
|
31
|
+
return f"错误:{file_path} 是一个目录,不是文件"
|
|
32
|
+
|
|
33
|
+
try:
|
|
34
|
+
with open(full_path, "rb") as binary_file:
|
|
35
|
+
raw_data: bytes = binary_file.read()
|
|
36
|
+
|
|
37
|
+
detected: Any = chardet.detect(raw_data)
|
|
38
|
+
encoding: str | None = detected.get("encoding", "utf-8")
|
|
39
|
+
confidence: float = detected.get("confidence", 0)
|
|
40
|
+
|
|
41
|
+
if encoding is None or confidence < 0.5:
|
|
42
|
+
encoding = "utf-8"
|
|
43
|
+
|
|
44
|
+
file_content: str = ""
|
|
45
|
+
try:
|
|
46
|
+
file_content = raw_data.decode(encoding)
|
|
47
|
+
except UnicodeDecodeError:
|
|
48
|
+
try:
|
|
49
|
+
file_content = raw_data.decode("utf-8")
|
|
50
|
+
except UnicodeDecodeError:
|
|
51
|
+
try:
|
|
52
|
+
file_content = raw_data.decode("utf-16")
|
|
53
|
+
except UnicodeDecodeError:
|
|
54
|
+
file_content = raw_data.decode("latin-1")
|
|
55
|
+
logger.warning(
|
|
56
|
+
f"文件 {file_path} 使用 latin-1 解码,可能包含乱码。"
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
if len(file_content) > 10000:
|
|
60
|
+
file_content = file_content[:10000] + "\n... (内容过长,已截断)"
|
|
61
|
+
|
|
62
|
+
return file_content
|
|
63
|
+
|
|
64
|
+
except Exception as e:
|
|
65
|
+
logger.exception(f"读取文件 {file_path} 时出错")
|
|
66
|
+
return f"读取文件失败: {e}"
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"type": "function",
|
|
3
|
+
"function": {
|
|
4
|
+
"name": "read_naga_intro",
|
|
5
|
+
"description": "读取 NagaAgent 项目的介绍文档,获取项目概述、技术架构、项目结构、构建运行方法等核心信息。当用户询问关于 NagaAgent 项目的任何问题时,应优先使用此工具获取项目上下文,而不是直接阅读代码文件。这样可以节省时间和 token,快速提供准确的项目信息。",
|
|
6
|
+
"parameters": {
|
|
7
|
+
"type": "object",
|
|
8
|
+
"properties": {},
|
|
9
|
+
"required": []
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
from typing import Any, Dict
|
|
2
|
+
|
|
3
|
+
# NagaAgent 项目介绍内容(直接嵌入以保证稳定性)
|
|
4
|
+
NAGA_INTRO_CONTENT = """
|
|
5
|
+
# NagaAgent 项目上下文
|
|
6
|
+
|
|
7
|
+
## 项目概述
|
|
8
|
+
|
|
9
|
+
NagaAgent 是一个功能丰富的智能对话助手系统,采用多服务架构设计,提供智能对话、多Agent协作、知识图谱记忆、语音交互和现代化界面等核心功能。
|
|
10
|
+
|
|
11
|
+
### 核心特性
|
|
12
|
+
|
|
13
|
+
- **智能对话系统**:支持流式对话和工具调用循环
|
|
14
|
+
- **多Agent协作**:基于博弈论的智能任务调度
|
|
15
|
+
- **知识图谱记忆**:GRAG系统支持长期记忆和智能检索(基于Neo4j)
|
|
16
|
+
- **完整语音交互**:实时语音输入输出处理
|
|
17
|
+
- **现代化界面**:PyQt5 GUI + Live2D虚拟形象
|
|
18
|
+
- **系统托盘集成**:后台运行和快捷操作
|
|
19
|
+
|
|
20
|
+
## 技术架构
|
|
21
|
+
|
|
22
|
+
### 系统架构
|
|
23
|
+
|
|
24
|
+
项目采用微服务架构,主要包含以下独立服务:
|
|
25
|
+
|
|
26
|
+
1. **API服务器** (端口8000) - RESTful API接口
|
|
27
|
+
2. **Agent服务器** (端口8001) - 博弈论电脑控制智能体
|
|
28
|
+
3. **MCP服务器** (端口8003) - MCP工具调度服务
|
|
29
|
+
4. **TTS服务器** (端口5048) - 语音合成服务
|
|
30
|
+
|
|
31
|
+
### 技术栈
|
|
32
|
+
|
|
33
|
+
- **Python**: 3.11(推荐)
|
|
34
|
+
- **前端框架**: PyQt5 + Live2D + QSS
|
|
35
|
+
- **后端框架**: FastAPI + Uvicorn + AsyncIO
|
|
36
|
+
- **数据库**: Neo4j(知识图谱)
|
|
37
|
+
- **AI模型**: OpenAI兼容API + 通义千问
|
|
38
|
+
- **协议**: MCP (Model Context Protocol) + WebSocket + MQTT
|
|
39
|
+
|
|
40
|
+
### 依赖管理
|
|
41
|
+
|
|
42
|
+
- **主要依赖**: `nagaagent-core>=1.0.9`(核心依赖已整合)
|
|
43
|
+
- **包管理器**: `uv`(推荐)或 `pip`
|
|
44
|
+
- **配置文件**: `pyproject.toml` + `requirements.txt`
|
|
45
|
+
|
|
46
|
+
## 项目结构
|
|
47
|
+
|
|
48
|
+
```
|
|
49
|
+
NagaAgent/
|
|
50
|
+
├── main.py # 主入口文件
|
|
51
|
+
├── config.json.example # 配置文件模板
|
|
52
|
+
├── setup.py / setup.sh # 安装脚本
|
|
53
|
+
├── start.sh / start.bat # 启动脚本
|
|
54
|
+
├── update.py # 更新脚本
|
|
55
|
+
│
|
|
56
|
+
├── apiserver/ # API服务器模块
|
|
57
|
+
│ ├── api_server.py # FastAPI应用
|
|
58
|
+
│ ├── llm_service.py # LLM服务
|
|
59
|
+
│ ├── message_manager.py # 消息管理器
|
|
60
|
+
│ └── streaming_tool_extractor.py # 流式工具提取器
|
|
61
|
+
│
|
|
62
|
+
├── agentserver/ # Agent服务器模块
|
|
63
|
+
│ ├── agent_server.py # FastAPI应用
|
|
64
|
+
│ ├── agent_manager.py # Agent管理器
|
|
65
|
+
│ ├── task_scheduler.py # 任务调度器
|
|
66
|
+
│ ├── toolkit_manager.py # 工具包管理器
|
|
67
|
+
│ └── agent_computer_control/ # 电脑控制智能体
|
|
68
|
+
│
|
|
69
|
+
├── mcpserver/ # MCP服务器模块
|
|
70
|
+
│ ├── mcp_server.py # FastAPI应用
|
|
71
|
+
│ ├── mcp_manager.py # MCP管理器
|
|
72
|
+
│ ├── mcp_scheduler.py # MCP调度器
|
|
73
|
+
│ ├── mcp_registry.py # MCP注册中心
|
|
74
|
+
│ └── agent_*/ # 各种MCP工具代理
|
|
75
|
+
│
|
|
76
|
+
├── summer_memory/ # GRAG知识图谱记忆系统
|
|
77
|
+
│ ├── memory_manager.py # 记忆管理器
|
|
78
|
+
│ ├── quintuple_extractor.py # 五元组提取器
|
|
79
|
+
│ ├── quintuple_graph.py # 图数据库操作
|
|
80
|
+
│ ├── quintuple_rag_query.py # RAG查询
|
|
81
|
+
│ └── task_manager.py # 任务管理器
|
|
82
|
+
│
|
|
83
|
+
├── game/ # 多智能体博弈系统
|
|
84
|
+
│ ├── naga_game_system.py # 博弈系统核心
|
|
85
|
+
│ ├── core/
|
|
86
|
+
│ │ ├── models/ # 数据模型
|
|
87
|
+
│ │ ├── interaction_graph/ # 交互图生成器
|
|
88
|
+
│ │ └── self_game/ # 自博弈模块
|
|
89
|
+
│ └── examples/ # 使用示例
|
|
90
|
+
│
|
|
91
|
+
├── ui/ # PyQt5界面模块(MVC架构)
|
|
92
|
+
│ ├── pyqt_chat_window.py # 主窗口
|
|
93
|
+
│ ├── components/ # UI组件
|
|
94
|
+
│ ├── controller/ # 控制器
|
|
95
|
+
│ ├── styles/ # 样式表
|
|
96
|
+
│ ├── live2d_local/ # Live2D虚拟形象
|
|
97
|
+
│ └── tray/ # 系统托盘
|
|
98
|
+
│
|
|
99
|
+
├── voice/ # 语音处理模块
|
|
100
|
+
│ ├── tts_wrapper.py # TTS封装
|
|
101
|
+
│ ├── input/ # 语音输入
|
|
102
|
+
│ └── output/ # 语音输出
|
|
103
|
+
│
|
|
104
|
+
├── system/ # 系统配置和工具
|
|
105
|
+
│ ├── config.py # 配置系统(Pydantic)
|
|
106
|
+
│ ├── config_manager.py # 配置管理器
|
|
107
|
+
│ ├── system_checker.py # 系统检测
|
|
108
|
+
│ └── background_analyzer.py # 后台分析器
|
|
109
|
+
│
|
|
110
|
+
├── mqtt_tool/ # 物联网通讯工具
|
|
111
|
+
│ └── device_switch.py # 设备控制
|
|
112
|
+
│
|
|
113
|
+
├── tests/ # 测试用例
|
|
114
|
+
├── logs/ # 日志目录
|
|
115
|
+
└── requirements.txt # Python依赖
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
## 构建和运行
|
|
119
|
+
|
|
120
|
+
### 环境要求
|
|
121
|
+
|
|
122
|
+
- Python 3.11(推荐)
|
|
123
|
+
- 可选:uv工具(加速依赖安装)
|
|
124
|
+
|
|
125
|
+
### 安装依赖
|
|
126
|
+
|
|
127
|
+
**使用setup脚本(推荐)**:
|
|
128
|
+
```bash
|
|
129
|
+
# Linux/macOS
|
|
130
|
+
./setup.sh
|
|
131
|
+
|
|
132
|
+
# Windows
|
|
133
|
+
setup.bat
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
**手动安装**:
|
|
137
|
+
```bash
|
|
138
|
+
# 创建虚拟环境
|
|
139
|
+
python -m venv .venv
|
|
140
|
+
source .venv/bin/activate # Linux/macOS
|
|
141
|
+
# 或
|
|
142
|
+
.\.venv\Scripts\activate # Windows
|
|
143
|
+
|
|
144
|
+
# 安装依赖
|
|
145
|
+
pip install -r requirements.txt
|
|
146
|
+
|
|
147
|
+
# 或使用uv
|
|
148
|
+
uv sync
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
### 配置
|
|
152
|
+
|
|
153
|
+
1. 复制配置文件模板:
|
|
154
|
+
```bash
|
|
155
|
+
cp config.json.example config.json
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
2. 编辑 `config.json`,配置LLM API:
|
|
159
|
+
```json
|
|
160
|
+
{
|
|
161
|
+
"api": {
|
|
162
|
+
"api_key": "你的api_key",
|
|
163
|
+
"base_url": "模型服务商OPENAI API端点",
|
|
164
|
+
"model": "模型名称"
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
3. (可选)启用知识图谱记忆:
|
|
170
|
+
```json
|
|
171
|
+
{
|
|
172
|
+
"grag": {
|
|
173
|
+
"enabled": true,
|
|
174
|
+
"neo4j_uri": "neo4j://127.0.0.1:7687",
|
|
175
|
+
"neo4j_user": "neo4j",
|
|
176
|
+
"neo4j_password": "你安装neo4j时设置的密码"
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
### 启动应用
|
|
182
|
+
|
|
183
|
+
**使用启动脚本**:
|
|
184
|
+
```bash
|
|
185
|
+
# Linux/macOS
|
|
186
|
+
./start.sh
|
|
187
|
+
|
|
188
|
+
# Windows
|
|
189
|
+
start.bat
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
**直接运行**:
|
|
193
|
+
```bash
|
|
194
|
+
# 激活虚拟环境后
|
|
195
|
+
python main.py
|
|
196
|
+
|
|
197
|
+
# 或使用uv
|
|
198
|
+
uv run main.py
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
### 系统检测
|
|
202
|
+
|
|
203
|
+
```bash
|
|
204
|
+
# 完整环境检测
|
|
205
|
+
python main.py --check-env
|
|
206
|
+
|
|
207
|
+
# 快速检测
|
|
208
|
+
python main.py --quick-check
|
|
209
|
+
|
|
210
|
+
# 强制检测(忽略缓存)
|
|
211
|
+
python main.py --check-env --force-check
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
### 更新
|
|
215
|
+
|
|
216
|
+
```bash
|
|
217
|
+
# 使用更新脚本
|
|
218
|
+
./update.sh # Linux/macOS
|
|
219
|
+
update.bat # Windows
|
|
220
|
+
|
|
221
|
+
# 或直接运行
|
|
222
|
+
python update.py
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
## 开发规范
|
|
226
|
+
|
|
227
|
+
### 代码风格
|
|
228
|
+
|
|
229
|
+
- **Python版本**: 3.11+
|
|
230
|
+
- **类型注释**: 使用类型提示(typing模块)
|
|
231
|
+
- **代码格式**: 建议使用black(行长度120字符)
|
|
232
|
+
- **代码检查**: 建议使用ruff
|
|
233
|
+
- **日志级别**: INFO(开发时可设为DEBUG)
|
|
234
|
+
|
|
235
|
+
### 架构设计
|
|
236
|
+
|
|
237
|
+
1. **模块化设计**: 各服务独立运行,支持热插拔
|
|
238
|
+
2. **配置驱动**: 实时配置热更新,无需重启
|
|
239
|
+
3. **异步优先**: 使用AsyncIO进行异步处理
|
|
240
|
+
4. **类型安全**: 使用Pydantic进行数据验证
|
|
241
|
+
|
|
242
|
+
### UI开发规范
|
|
243
|
+
|
|
244
|
+
- **MVC架构**: UI组件符合MVC结构
|
|
245
|
+
- **组件化**: 先创建widget组件和工具,验证后再集成到window
|
|
246
|
+
- **线程安全**: 跨线程调用Qt需使用信号槽机制
|
|
247
|
+
- **样式管理**: 使用QSS统一样式
|
|
248
|
+
|
|
249
|
+
### 配置管理
|
|
250
|
+
|
|
251
|
+
- **配置文件**: `config.json`(支持注释,使用json5解析)
|
|
252
|
+
- **配置类**: `system/config.py` 中的Pydantic模型
|
|
253
|
+
- **热更新**: 支持配置变更监听和通知
|
|
254
|
+
|
|
255
|
+
### 日志规范
|
|
256
|
+
|
|
257
|
+
- **日志目录**: `logs/`
|
|
258
|
+
- **日志级别**: DEBUG, INFO, WARNING, ERROR, CRITICAL
|
|
259
|
+
- **日志格式**: `%(asctime)s - %(name)s - %(levelname)s - %(message)s`
|
|
260
|
+
|
|
261
|
+
### 测试
|
|
262
|
+
|
|
263
|
+
- **测试框架**: pytest
|
|
264
|
+
- **测试目录**: `tests/`
|
|
265
|
+
- **异步测试**: pytest-asyncio
|
|
266
|
+
|
|
267
|
+
## 关键端口
|
|
268
|
+
|
|
269
|
+
- **API服务器**: 8000
|
|
270
|
+
- **Agent服务器**: 8001
|
|
271
|
+
- **MCP服务器**: 8003
|
|
272
|
+
- **TTS服务器**: 5048
|
|
273
|
+
- **ASR服务器**: 5060
|
|
274
|
+
|
|
275
|
+
## 重要注意事项
|
|
276
|
+
|
|
277
|
+
1. **Python版本**: 必须使用Python 3.11,其他版本可能不兼容
|
|
278
|
+
2. **端口占用**: 启动前确保端口8000、8001、8003、5048未被占用
|
|
279
|
+
3. **Neo4j连接**: 如果启用GRAG,确保Neo4j服务正在运行
|
|
280
|
+
4. **编码问题**: 配置文件使用UTF-8编码,支持中文
|
|
281
|
+
5. **虚拟环境**: 建议使用虚拟环境隔离依赖
|
|
282
|
+
6. **系统检测**: 首次启动会自动进行系统环境检测
|
|
283
|
+
|
|
284
|
+
## 故障排除
|
|
285
|
+
|
|
286
|
+
1. **Python版本不兼容**: 确保使用Python 3.11
|
|
287
|
+
2. **端口被占用**: 检查并释放相关端口
|
|
288
|
+
3. **Neo4j连接失败**: 检查Neo4j服务状态和连接配置
|
|
289
|
+
4. **依赖安装失败**: 尝试使用uv代替pip
|
|
290
|
+
5. **UI显示异常**: 检查PyQt5和OpenGL依赖
|
|
291
|
+
|
|
292
|
+
## 扩展开发
|
|
293
|
+
|
|
294
|
+
### 添加新的MCP工具
|
|
295
|
+
|
|
296
|
+
1. 在 `mcpserver/agent_*/` 创建新的MCP代理目录
|
|
297
|
+
2. 实现 `mcp_tools.py` 定义工具接口
|
|
298
|
+
3. 在 `mcpserver/mcp_registry.py` 注册新工具
|
|
299
|
+
|
|
300
|
+
### 添加新的UI组件
|
|
301
|
+
|
|
302
|
+
1. 在 `ui/components/` 创建组件文件
|
|
303
|
+
2. 遵循MVC架构,分离视图和逻辑
|
|
304
|
+
3. 在 `ui/pyqt_chat_window.py` 中集成组件
|
|
305
|
+
|
|
306
|
+
### 扩展博弈系统
|
|
307
|
+
|
|
308
|
+
1. 在 `game/core/` 添加新模块
|
|
309
|
+
2. 使用 `game/core/models/` 中的数据模型
|
|
310
|
+
3. 在 `game/examples/` 添加使用示例
|
|
311
|
+
|
|
312
|
+
## 许可证
|
|
313
|
+
|
|
314
|
+
MIT License - 详见 LICENSE 文件
|
|
315
|
+
|
|
316
|
+
## 贡献指南
|
|
317
|
+
|
|
318
|
+
欢迎创建Issue和Pull Request!
|
|
319
|
+
|
|
320
|
+
- 遵循现有代码风格
|
|
321
|
+
- 添加必要的类型注释
|
|
322
|
+
- 编写清晰的提交信息
|
|
323
|
+
- 更新相关文档
|
|
324
|
+
"""
|
|
325
|
+
|
|
326
|
+
async def execute(args: Dict[str, Any], context: Dict[str, Any]) -> str:
|
|
327
|
+
return f"NagaAgent 项目介绍文档:\n\n{NAGA_INTRO_CONTENT}"
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"type": "function",
|
|
3
|
+
"function": {
|
|
4
|
+
"name": "search_file_content",
|
|
5
|
+
"description": "在文件中搜索内容。支持正则表达式。路径是相对于当前工作目录的。",
|
|
6
|
+
"parameters": {
|
|
7
|
+
"type": "object",
|
|
8
|
+
"properties": {
|
|
9
|
+
"pattern": {
|
|
10
|
+
"type": "string",
|
|
11
|
+
"description": "搜索模式(正则表达式)"
|
|
12
|
+
},
|
|
13
|
+
"path": {
|
|
14
|
+
"type": "string",
|
|
15
|
+
"description": "搜索路径(相对于当前工作目录,默认为根目录)"
|
|
16
|
+
},
|
|
17
|
+
"include": {
|
|
18
|
+
"type": "string",
|
|
19
|
+
"description": "文件过滤模式(如 *.py)"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"required": ["pattern"]
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import subprocess
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
from typing import Any, Dict
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
async def execute(args: Dict[str, Any], context: Dict[str, Any]) -> str:
|
|
7
|
+
pattern = args.get("pattern", "")
|
|
8
|
+
path_str = args.get("path")
|
|
9
|
+
include = args.get("include")
|
|
10
|
+
|
|
11
|
+
# 将 base_path 限制在 NagaAgent 子模块中
|
|
12
|
+
base_path = context.get("base_path", Path.cwd() / "code" / "NagaAgent")
|
|
13
|
+
base_path = Path(base_path).resolve()
|
|
14
|
+
|
|
15
|
+
if not path_str:
|
|
16
|
+
full_path = base_path
|
|
17
|
+
else:
|
|
18
|
+
full_path = (base_path / path_str).resolve()
|
|
19
|
+
|
|
20
|
+
if include is None:
|
|
21
|
+
include = ""
|
|
22
|
+
|
|
23
|
+
if not str(full_path).startswith(str(base_path)):
|
|
24
|
+
return "权限不足:只能在当前工作目录下搜索"
|
|
25
|
+
|
|
26
|
+
cmd = ["grep", "-rn", pattern, str(full_path)]
|
|
27
|
+
if include:
|
|
28
|
+
cmd.extend(["--include", include])
|
|
29
|
+
|
|
30
|
+
try:
|
|
31
|
+
result = subprocess.run(
|
|
32
|
+
cmd,
|
|
33
|
+
capture_output=True,
|
|
34
|
+
text=True,
|
|
35
|
+
timeout=30,
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
if result.returncode == 0:
|
|
39
|
+
output = result.stdout
|
|
40
|
+
lines = output.split("\n")[:50]
|
|
41
|
+
return "\n".join(lines)
|
|
42
|
+
else:
|
|
43
|
+
return f"未找到匹配: {pattern}"
|
|
44
|
+
|
|
45
|
+
except subprocess.TimeoutExpired:
|
|
46
|
+
return "工具执行超时: search_file_content"
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# Scheduler Agent
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"type": "function",
|
|
3
|
+
"function": {
|
|
4
|
+
"name": "scheduler_agent",
|
|
5
|
+
"description": "定时任务管理助手。提供创建、删除、修改、查看定时任务的功能,支持 crontab 语法和执行次数限制。",
|
|
6
|
+
"parameters": {
|
|
7
|
+
"type": "object",
|
|
8
|
+
"properties": {
|
|
9
|
+
"prompt": {
|
|
10
|
+
"type": "string",
|
|
11
|
+
"description": "用户的定时任务管理需求,例如:'创建一个每天早上8点执行的任务'、'删除所有任务'、'查看当前有哪些定时任务'"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"required": ["prompt"]
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|