jarvis-ai-assistant 0.7.8__py3-none-any.whl → 1.0.2__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.
Files changed (279) hide show
  1. jarvis/__init__.py +1 -1
  2. jarvis/jarvis_agent/__init__.py +567 -222
  3. jarvis/jarvis_agent/agent_manager.py +19 -12
  4. jarvis/jarvis_agent/builtin_input_handler.py +79 -11
  5. jarvis/jarvis_agent/config_editor.py +7 -2
  6. jarvis/jarvis_agent/event_bus.py +24 -13
  7. jarvis/jarvis_agent/events.py +19 -1
  8. jarvis/jarvis_agent/file_context_handler.py +67 -64
  9. jarvis/jarvis_agent/file_methodology_manager.py +38 -24
  10. jarvis/jarvis_agent/jarvis.py +186 -114
  11. jarvis/jarvis_agent/language_extractors/__init__.py +8 -1
  12. jarvis/jarvis_agent/language_extractors/c_extractor.py +7 -4
  13. jarvis/jarvis_agent/language_extractors/cpp_extractor.py +9 -4
  14. jarvis/jarvis_agent/language_extractors/go_extractor.py +7 -4
  15. jarvis/jarvis_agent/language_extractors/java_extractor.py +27 -20
  16. jarvis/jarvis_agent/language_extractors/javascript_extractor.py +22 -17
  17. jarvis/jarvis_agent/language_extractors/python_extractor.py +7 -4
  18. jarvis/jarvis_agent/language_extractors/rust_extractor.py +7 -4
  19. jarvis/jarvis_agent/language_extractors/typescript_extractor.py +22 -17
  20. jarvis/jarvis_agent/language_support_info.py +250 -219
  21. jarvis/jarvis_agent/main.py +19 -23
  22. jarvis/jarvis_agent/memory_manager.py +9 -6
  23. jarvis/jarvis_agent/methodology_share_manager.py +21 -15
  24. jarvis/jarvis_agent/output_handler.py +4 -2
  25. jarvis/jarvis_agent/prompt_builder.py +7 -6
  26. jarvis/jarvis_agent/prompt_manager.py +113 -8
  27. jarvis/jarvis_agent/prompts.py +317 -85
  28. jarvis/jarvis_agent/protocols.py +5 -2
  29. jarvis/jarvis_agent/run_loop.py +192 -32
  30. jarvis/jarvis_agent/session_manager.py +7 -3
  31. jarvis/jarvis_agent/share_manager.py +23 -13
  32. jarvis/jarvis_agent/shell_input_handler.py +12 -8
  33. jarvis/jarvis_agent/stdio_redirect.py +25 -26
  34. jarvis/jarvis_agent/task_analyzer.py +29 -23
  35. jarvis/jarvis_agent/task_list.py +869 -0
  36. jarvis/jarvis_agent/task_manager.py +26 -23
  37. jarvis/jarvis_agent/tool_executor.py +6 -5
  38. jarvis/jarvis_agent/tool_share_manager.py +24 -14
  39. jarvis/jarvis_agent/user_interaction.py +3 -3
  40. jarvis/jarvis_agent/utils.py +9 -1
  41. jarvis/jarvis_agent/web_bridge.py +37 -17
  42. jarvis/jarvis_agent/web_output_sink.py +5 -2
  43. jarvis/jarvis_agent/web_server.py +165 -36
  44. jarvis/jarvis_c2rust/__init__.py +1 -1
  45. jarvis/jarvis_c2rust/cli.py +260 -141
  46. jarvis/jarvis_c2rust/collector.py +37 -18
  47. jarvis/jarvis_c2rust/constants.py +60 -0
  48. jarvis/jarvis_c2rust/library_replacer.py +242 -1010
  49. jarvis/jarvis_c2rust/library_replacer_checkpoint.py +133 -0
  50. jarvis/jarvis_c2rust/library_replacer_llm.py +287 -0
  51. jarvis/jarvis_c2rust/library_replacer_loader.py +191 -0
  52. jarvis/jarvis_c2rust/library_replacer_output.py +134 -0
  53. jarvis/jarvis_c2rust/library_replacer_prompts.py +124 -0
  54. jarvis/jarvis_c2rust/library_replacer_utils.py +188 -0
  55. jarvis/jarvis_c2rust/llm_module_agent.py +98 -1044
  56. jarvis/jarvis_c2rust/llm_module_agent_apply.py +170 -0
  57. jarvis/jarvis_c2rust/llm_module_agent_executor.py +288 -0
  58. jarvis/jarvis_c2rust/llm_module_agent_loader.py +170 -0
  59. jarvis/jarvis_c2rust/llm_module_agent_prompts.py +268 -0
  60. jarvis/jarvis_c2rust/llm_module_agent_types.py +57 -0
  61. jarvis/jarvis_c2rust/llm_module_agent_utils.py +150 -0
  62. jarvis/jarvis_c2rust/llm_module_agent_validator.py +119 -0
  63. jarvis/jarvis_c2rust/loaders.py +28 -10
  64. jarvis/jarvis_c2rust/models.py +5 -2
  65. jarvis/jarvis_c2rust/optimizer.py +192 -1974
  66. jarvis/jarvis_c2rust/optimizer_build_fix.py +286 -0
  67. jarvis/jarvis_c2rust/optimizer_clippy.py +766 -0
  68. jarvis/jarvis_c2rust/optimizer_config.py +49 -0
  69. jarvis/jarvis_c2rust/optimizer_docs.py +183 -0
  70. jarvis/jarvis_c2rust/optimizer_options.py +48 -0
  71. jarvis/jarvis_c2rust/optimizer_progress.py +469 -0
  72. jarvis/jarvis_c2rust/optimizer_report.py +52 -0
  73. jarvis/jarvis_c2rust/optimizer_unsafe.py +309 -0
  74. jarvis/jarvis_c2rust/optimizer_utils.py +469 -0
  75. jarvis/jarvis_c2rust/optimizer_visibility.py +185 -0
  76. jarvis/jarvis_c2rust/scanner.py +229 -166
  77. jarvis/jarvis_c2rust/transpiler.py +531 -2732
  78. jarvis/jarvis_c2rust/transpiler_agents.py +503 -0
  79. jarvis/jarvis_c2rust/transpiler_build.py +1294 -0
  80. jarvis/jarvis_c2rust/transpiler_codegen.py +204 -0
  81. jarvis/jarvis_c2rust/transpiler_compile.py +146 -0
  82. jarvis/jarvis_c2rust/transpiler_config.py +178 -0
  83. jarvis/jarvis_c2rust/transpiler_context.py +122 -0
  84. jarvis/jarvis_c2rust/transpiler_executor.py +516 -0
  85. jarvis/jarvis_c2rust/transpiler_generation.py +278 -0
  86. jarvis/jarvis_c2rust/transpiler_git.py +163 -0
  87. jarvis/jarvis_c2rust/transpiler_mod_utils.py +225 -0
  88. jarvis/jarvis_c2rust/transpiler_modules.py +336 -0
  89. jarvis/jarvis_c2rust/transpiler_planning.py +394 -0
  90. jarvis/jarvis_c2rust/transpiler_review.py +1196 -0
  91. jarvis/jarvis_c2rust/transpiler_symbols.py +176 -0
  92. jarvis/jarvis_c2rust/utils.py +269 -79
  93. jarvis/jarvis_code_agent/after_change.py +233 -0
  94. jarvis/jarvis_code_agent/build_validation_config.py +37 -30
  95. jarvis/jarvis_code_agent/builtin_rules.py +68 -0
  96. jarvis/jarvis_code_agent/code_agent.py +976 -1517
  97. jarvis/jarvis_code_agent/code_agent_build.py +227 -0
  98. jarvis/jarvis_code_agent/code_agent_diff.py +246 -0
  99. jarvis/jarvis_code_agent/code_agent_git.py +525 -0
  100. jarvis/jarvis_code_agent/code_agent_impact.py +177 -0
  101. jarvis/jarvis_code_agent/code_agent_lint.py +283 -0
  102. jarvis/jarvis_code_agent/code_agent_llm.py +159 -0
  103. jarvis/jarvis_code_agent/code_agent_postprocess.py +105 -0
  104. jarvis/jarvis_code_agent/code_agent_prompts.py +46 -0
  105. jarvis/jarvis_code_agent/code_agent_rules.py +305 -0
  106. jarvis/jarvis_code_agent/code_analyzer/__init__.py +52 -48
  107. jarvis/jarvis_code_agent/code_analyzer/base_language.py +12 -10
  108. jarvis/jarvis_code_agent/code_analyzer/build_validator/__init__.py +12 -11
  109. jarvis/jarvis_code_agent/code_analyzer/build_validator/base.py +16 -12
  110. jarvis/jarvis_code_agent/code_analyzer/build_validator/cmake.py +26 -17
  111. jarvis/jarvis_code_agent/code_analyzer/build_validator/detector.py +558 -104
  112. jarvis/jarvis_code_agent/code_analyzer/build_validator/fallback.py +27 -16
  113. jarvis/jarvis_code_agent/code_analyzer/build_validator/go.py +22 -18
  114. jarvis/jarvis_code_agent/code_analyzer/build_validator/java_gradle.py +21 -16
  115. jarvis/jarvis_code_agent/code_analyzer/build_validator/java_maven.py +20 -16
  116. jarvis/jarvis_code_agent/code_analyzer/build_validator/makefile.py +27 -16
  117. jarvis/jarvis_code_agent/code_analyzer/build_validator/nodejs.py +47 -23
  118. jarvis/jarvis_code_agent/code_analyzer/build_validator/python.py +71 -37
  119. jarvis/jarvis_code_agent/code_analyzer/build_validator/rust.py +162 -35
  120. jarvis/jarvis_code_agent/code_analyzer/build_validator/validator.py +111 -57
  121. jarvis/jarvis_code_agent/code_analyzer/build_validator.py +18 -12
  122. jarvis/jarvis_code_agent/code_analyzer/context_manager.py +185 -183
  123. jarvis/jarvis_code_agent/code_analyzer/context_recommender.py +2 -1
  124. jarvis/jarvis_code_agent/code_analyzer/dependency_analyzer.py +24 -15
  125. jarvis/jarvis_code_agent/code_analyzer/file_ignore.py +227 -141
  126. jarvis/jarvis_code_agent/code_analyzer/impact_analyzer.py +321 -247
  127. jarvis/jarvis_code_agent/code_analyzer/language_registry.py +37 -29
  128. jarvis/jarvis_code_agent/code_analyzer/language_support.py +21 -13
  129. jarvis/jarvis_code_agent/code_analyzer/languages/__init__.py +15 -9
  130. jarvis/jarvis_code_agent/code_analyzer/languages/c_cpp_language.py +75 -45
  131. jarvis/jarvis_code_agent/code_analyzer/languages/go_language.py +87 -52
  132. jarvis/jarvis_code_agent/code_analyzer/languages/java_language.py +84 -51
  133. jarvis/jarvis_code_agent/code_analyzer/languages/javascript_language.py +94 -64
  134. jarvis/jarvis_code_agent/code_analyzer/languages/python_language.py +109 -71
  135. jarvis/jarvis_code_agent/code_analyzer/languages/rust_language.py +97 -63
  136. jarvis/jarvis_code_agent/code_analyzer/languages/typescript_language.py +103 -69
  137. jarvis/jarvis_code_agent/code_analyzer/llm_context_recommender.py +271 -268
  138. jarvis/jarvis_code_agent/code_analyzer/symbol_extractor.py +76 -64
  139. jarvis/jarvis_code_agent/code_analyzer/tree_sitter_extractor.py +92 -19
  140. jarvis/jarvis_code_agent/diff_visualizer.py +998 -0
  141. jarvis/jarvis_code_agent/lint.py +223 -524
  142. jarvis/jarvis_code_agent/rule_share_manager.py +158 -0
  143. jarvis/jarvis_code_agent/rules/clean_code.md +144 -0
  144. jarvis/jarvis_code_agent/rules/code_review.md +115 -0
  145. jarvis/jarvis_code_agent/rules/documentation.md +165 -0
  146. jarvis/jarvis_code_agent/rules/generate_rules.md +52 -0
  147. jarvis/jarvis_code_agent/rules/performance.md +158 -0
  148. jarvis/jarvis_code_agent/rules/refactoring.md +139 -0
  149. jarvis/jarvis_code_agent/rules/security.md +160 -0
  150. jarvis/jarvis_code_agent/rules/tdd.md +78 -0
  151. jarvis/jarvis_code_agent/test_rules/cpp_test.md +118 -0
  152. jarvis/jarvis_code_agent/test_rules/go_test.md +98 -0
  153. jarvis/jarvis_code_agent/test_rules/java_test.md +99 -0
  154. jarvis/jarvis_code_agent/test_rules/javascript_test.md +113 -0
  155. jarvis/jarvis_code_agent/test_rules/php_test.md +117 -0
  156. jarvis/jarvis_code_agent/test_rules/python_test.md +91 -0
  157. jarvis/jarvis_code_agent/test_rules/ruby_test.md +102 -0
  158. jarvis/jarvis_code_agent/test_rules/rust_test.md +86 -0
  159. jarvis/jarvis_code_agent/utils.py +36 -26
  160. jarvis/jarvis_code_analysis/checklists/loader.py +21 -21
  161. jarvis/jarvis_code_analysis/code_review.py +64 -33
  162. jarvis/jarvis_data/config_schema.json +285 -192
  163. jarvis/jarvis_git_squash/main.py +8 -6
  164. jarvis/jarvis_git_utils/git_commiter.py +53 -76
  165. jarvis/jarvis_mcp/__init__.py +5 -2
  166. jarvis/jarvis_mcp/sse_mcp_client.py +40 -30
  167. jarvis/jarvis_mcp/stdio_mcp_client.py +27 -19
  168. jarvis/jarvis_mcp/streamable_mcp_client.py +35 -26
  169. jarvis/jarvis_memory_organizer/memory_organizer.py +78 -55
  170. jarvis/jarvis_methodology/main.py +48 -39
  171. jarvis/jarvis_multi_agent/__init__.py +56 -23
  172. jarvis/jarvis_multi_agent/main.py +15 -18
  173. jarvis/jarvis_platform/base.py +179 -111
  174. jarvis/jarvis_platform/human.py +27 -16
  175. jarvis/jarvis_platform/kimi.py +52 -45
  176. jarvis/jarvis_platform/openai.py +101 -40
  177. jarvis/jarvis_platform/registry.py +51 -33
  178. jarvis/jarvis_platform/tongyi.py +68 -38
  179. jarvis/jarvis_platform/yuanbao.py +59 -43
  180. jarvis/jarvis_platform_manager/main.py +68 -76
  181. jarvis/jarvis_platform_manager/service.py +24 -14
  182. jarvis/jarvis_rag/README_CONFIG.md +314 -0
  183. jarvis/jarvis_rag/README_DYNAMIC_LOADING.md +311 -0
  184. jarvis/jarvis_rag/README_ONLINE_MODELS.md +230 -0
  185. jarvis/jarvis_rag/__init__.py +57 -4
  186. jarvis/jarvis_rag/cache.py +3 -1
  187. jarvis/jarvis_rag/cli.py +48 -68
  188. jarvis/jarvis_rag/embedding_interface.py +39 -0
  189. jarvis/jarvis_rag/embedding_manager.py +7 -230
  190. jarvis/jarvis_rag/embeddings/__init__.py +41 -0
  191. jarvis/jarvis_rag/embeddings/base.py +114 -0
  192. jarvis/jarvis_rag/embeddings/cohere.py +66 -0
  193. jarvis/jarvis_rag/embeddings/edgefn.py +117 -0
  194. jarvis/jarvis_rag/embeddings/local.py +260 -0
  195. jarvis/jarvis_rag/embeddings/openai.py +62 -0
  196. jarvis/jarvis_rag/embeddings/registry.py +293 -0
  197. jarvis/jarvis_rag/llm_interface.py +8 -6
  198. jarvis/jarvis_rag/query_rewriter.py +8 -9
  199. jarvis/jarvis_rag/rag_pipeline.py +61 -52
  200. jarvis/jarvis_rag/reranker.py +7 -75
  201. jarvis/jarvis_rag/reranker_interface.py +32 -0
  202. jarvis/jarvis_rag/rerankers/__init__.py +41 -0
  203. jarvis/jarvis_rag/rerankers/base.py +109 -0
  204. jarvis/jarvis_rag/rerankers/cohere.py +67 -0
  205. jarvis/jarvis_rag/rerankers/edgefn.py +140 -0
  206. jarvis/jarvis_rag/rerankers/jina.py +79 -0
  207. jarvis/jarvis_rag/rerankers/local.py +89 -0
  208. jarvis/jarvis_rag/rerankers/registry.py +293 -0
  209. jarvis/jarvis_rag/retriever.py +58 -43
  210. jarvis/jarvis_sec/__init__.py +66 -141
  211. jarvis/jarvis_sec/agents.py +21 -17
  212. jarvis/jarvis_sec/analysis.py +80 -33
  213. jarvis/jarvis_sec/checkers/__init__.py +7 -13
  214. jarvis/jarvis_sec/checkers/c_checker.py +356 -164
  215. jarvis/jarvis_sec/checkers/rust_checker.py +47 -29
  216. jarvis/jarvis_sec/cli.py +43 -21
  217. jarvis/jarvis_sec/clustering.py +430 -272
  218. jarvis/jarvis_sec/file_manager.py +99 -55
  219. jarvis/jarvis_sec/parsers.py +9 -6
  220. jarvis/jarvis_sec/prompts.py +4 -3
  221. jarvis/jarvis_sec/report.py +44 -22
  222. jarvis/jarvis_sec/review.py +180 -107
  223. jarvis/jarvis_sec/status.py +50 -41
  224. jarvis/jarvis_sec/types.py +3 -0
  225. jarvis/jarvis_sec/utils.py +160 -83
  226. jarvis/jarvis_sec/verification.py +411 -181
  227. jarvis/jarvis_sec/workflow.py +132 -21
  228. jarvis/jarvis_smart_shell/main.py +28 -41
  229. jarvis/jarvis_stats/cli.py +14 -12
  230. jarvis/jarvis_stats/stats.py +28 -19
  231. jarvis/jarvis_stats/storage.py +14 -8
  232. jarvis/jarvis_stats/visualizer.py +12 -7
  233. jarvis/jarvis_tools/base.py +5 -2
  234. jarvis/jarvis_tools/clear_memory.py +13 -9
  235. jarvis/jarvis_tools/cli/main.py +23 -18
  236. jarvis/jarvis_tools/edit_file.py +572 -873
  237. jarvis/jarvis_tools/execute_script.py +10 -7
  238. jarvis/jarvis_tools/file_analyzer.py +7 -8
  239. jarvis/jarvis_tools/meta_agent.py +287 -0
  240. jarvis/jarvis_tools/methodology.py +5 -3
  241. jarvis/jarvis_tools/read_code.py +305 -1438
  242. jarvis/jarvis_tools/read_symbols.py +50 -17
  243. jarvis/jarvis_tools/read_webpage.py +19 -18
  244. jarvis/jarvis_tools/registry.py +435 -156
  245. jarvis/jarvis_tools/retrieve_memory.py +16 -11
  246. jarvis/jarvis_tools/save_memory.py +8 -6
  247. jarvis/jarvis_tools/search_web.py +31 -31
  248. jarvis/jarvis_tools/sub_agent.py +32 -28
  249. jarvis/jarvis_tools/sub_code_agent.py +44 -60
  250. jarvis/jarvis_tools/task_list_manager.py +1811 -0
  251. jarvis/jarvis_tools/virtual_tty.py +29 -19
  252. jarvis/jarvis_utils/__init__.py +4 -0
  253. jarvis/jarvis_utils/builtin_replace_map.py +2 -1
  254. jarvis/jarvis_utils/clipboard.py +9 -8
  255. jarvis/jarvis_utils/collections.py +331 -0
  256. jarvis/jarvis_utils/config.py +699 -194
  257. jarvis/jarvis_utils/dialogue_recorder.py +294 -0
  258. jarvis/jarvis_utils/embedding.py +6 -3
  259. jarvis/jarvis_utils/file_processors.py +7 -1
  260. jarvis/jarvis_utils/fzf.py +9 -3
  261. jarvis/jarvis_utils/git_utils.py +71 -42
  262. jarvis/jarvis_utils/globals.py +116 -32
  263. jarvis/jarvis_utils/http.py +6 -2
  264. jarvis/jarvis_utils/input.py +318 -83
  265. jarvis/jarvis_utils/jsonnet_compat.py +119 -104
  266. jarvis/jarvis_utils/methodology.py +37 -28
  267. jarvis/jarvis_utils/output.py +201 -44
  268. jarvis/jarvis_utils/utils.py +986 -628
  269. {jarvis_ai_assistant-0.7.8.dist-info → jarvis_ai_assistant-1.0.2.dist-info}/METADATA +49 -33
  270. jarvis_ai_assistant-1.0.2.dist-info/RECORD +304 -0
  271. jarvis/jarvis_code_agent/code_analyzer/structured_code.py +0 -556
  272. jarvis/jarvis_tools/generate_new_tool.py +0 -205
  273. jarvis/jarvis_tools/lsp_client.py +0 -1552
  274. jarvis/jarvis_tools/rewrite_file.py +0 -105
  275. jarvis_ai_assistant-0.7.8.dist-info/RECORD +0 -218
  276. {jarvis_ai_assistant-0.7.8.dist-info → jarvis_ai_assistant-1.0.2.dist-info}/WHEEL +0 -0
  277. {jarvis_ai_assistant-0.7.8.dist-info → jarvis_ai_assistant-1.0.2.dist-info}/entry_points.txt +0 -0
  278. {jarvis_ai_assistant-0.7.8.dist-info → jarvis_ai_assistant-1.0.2.dist-info}/licenses/LICENSE +0 -0
  279. {jarvis_ai_assistant-0.7.8.dist-info → jarvis_ai_assistant-1.0.2.dist-info}/top_level.txt +0 -0
@@ -3,11 +3,19 @@ import json
3
3
  import os
4
4
  import time
5
5
  import uuid
6
- from typing import Any, Dict, Generator, List, Tuple
6
+ from typing import Any
7
+ from typing import Dict
8
+ from typing import Generator
9
+ from typing import List
10
+ from typing import Optional
11
+ from typing import Tuple
12
+ from typing import cast
7
13
 
8
14
  from jarvis.jarvis_platform.base import BasePlatform
9
15
  from jarvis.jarvis_utils import http
10
- from jarvis.jarvis_utils.tag import ot, ct
16
+ from jarvis.jarvis_utils.output import PrettyOutput
17
+ from jarvis.jarvis_utils.tag import ct
18
+ from jarvis.jarvis_utils.tag import ot
11
19
  from jarvis.jarvis_utils.utils import while_success
12
20
 
13
21
 
@@ -17,15 +25,25 @@ class TongyiPlatform(BasePlatform):
17
25
  # Supported image formats
18
26
  IMAGE_EXTENSIONS = {".jpg", ".jpeg", ".png", ".gif", ".webp", ".bmp", ".tiff"}
19
27
 
20
- def __init__(self):
21
- """Initialize Tongyi platform"""
28
+ def __init__(self, llm_config: Optional[Dict[str, Any]] = None):
29
+ """
30
+ Initialize Tongyi platform
31
+
32
+ 参数:
33
+ llm_config: LLM配置字典,包含 tongyi_cookies 等
34
+ """
22
35
  super().__init__()
23
36
  self.session_id = ""
24
- self.cookies = os.getenv("TONGYI_COOKIES", "")
37
+ llm_config = llm_config or {}
38
+
39
+ # 从 llm_config 获取配置,如果没有则从环境变量获取(向后兼容)
40
+ self.cookies = llm_config.get("tongyi_cookies") or os.getenv(
41
+ "TONGYI_COOKIES", ""
42
+ )
25
43
  self.request_id = ""
26
44
  self.msg_id = ""
27
45
  self.model_name = ""
28
- self.uploaded_file_info = []
46
+ self.uploaded_file_info: List[Dict[str, Any]] = []
29
47
  self.system_message = "" # System message for initialization
30
48
  self.first_chat = True # Flag for first chat
31
49
 
@@ -245,7 +263,8 @@ class TongyiPlatform(BasePlatform):
245
263
 
246
264
  try:
247
265
  response = while_success(
248
- lambda: http.post(url, headers=headers, json=payload) )
266
+ lambda: http.post(url, headers=headers, json=payload)
267
+ )
249
268
  if response.status_code != 200:
250
269
  raise Exception(f"HTTP {response.status_code}: {response.text}")
251
270
 
@@ -253,7 +272,7 @@ class TongyiPlatform(BasePlatform):
253
272
  if not result.get("success"):
254
273
  raise Exception(f"Failed to get upload token: {result.get('errorMsg')}")
255
274
 
256
- return result.get("data", {})
275
+ return cast(Dict[str, Any], result.get("data", {}))
257
276
 
258
277
  except Exception as e:
259
278
  raise Exception(f"Failed to get upload token: {str(e)}")
@@ -279,8 +298,8 @@ class TongyiPlatform(BasePlatform):
279
298
  if not os.path.exists(file_path):
280
299
  # 先输出已收集的日志与错误后返回
281
300
  log_lines.append(f"文件不存在: {file_path}")
282
- joined_logs = '\n'.join(log_lines)
283
- print(f"❌ {joined_logs}")
301
+ joined_logs = "\n".join(log_lines)
302
+ PrettyOutput.auto_print(f"❌ {joined_logs}")
284
303
  return False
285
304
 
286
305
  # Get file name and content type
@@ -309,9 +328,11 @@ class TongyiPlatform(BasePlatform):
309
328
  )
310
329
 
311
330
  if response.status_code != 200:
312
- log_lines.append(f"上传失败 {file_name}: HTTP {response.status_code}")
313
- joined_logs = '\n'.join(log_lines)
314
- print(f"❌ {joined_logs}")
331
+ log_lines.append(
332
+ f"上传失败 {file_name}: HTTP {response.status_code}"
333
+ )
334
+ joined_logs = "\n".join(log_lines)
335
+ PrettyOutput.auto_print(f"❌ {joined_logs}")
315
336
  return False
316
337
 
317
338
  # Determine file type based on extension
@@ -343,16 +364,18 @@ class TongyiPlatform(BasePlatform):
343
364
 
344
365
  response = http.post(url, headers=headers, json=payload)
345
366
  if response.status_code != 200:
346
- log_lines.append(f"获取下载链接失败: HTTP {response.status_code}")
347
- joined_logs = '\n'.join(log_lines)
348
- print(f"❌ {joined_logs}")
367
+ log_lines.append(
368
+ f"获取下载链接失败: HTTP {response.status_code}"
369
+ )
370
+ joined_logs = "\n".join(log_lines)
371
+ PrettyOutput.auto_print(f"❌ {joined_logs}")
349
372
  return False
350
373
 
351
374
  result = response.json()
352
375
  if not result.get("success"):
353
376
  log_lines.append(f"获取下载链接失败: {result.get('errorMsg')}")
354
- joined_logs = '\n'.join(log_lines)
355
- print(f"❌ {joined_logs}")
377
+ joined_logs = "\n".join(log_lines)
378
+ PrettyOutput.auto_print(f"❌ {joined_logs}")
356
379
  return False
357
380
 
358
381
  # Add files to chat
@@ -381,30 +404,34 @@ class TongyiPlatform(BasePlatform):
381
404
  add_url, headers=headers, json=add_payload
382
405
  )
383
406
  if add_response.status_code != 200:
384
- log_lines.append(f"添加文件到对话失败: HTTP {add_response.status_code}")
407
+ log_lines.append(
408
+ f"添加文件到对话失败: HTTP {add_response.status_code}"
409
+ )
385
410
  continue
386
411
 
387
412
  add_result = add_response.json()
388
413
  if not add_result.get("success"):
389
- log_lines.append(f"添加文件到对话失败: {add_result.get('errorMsg')}")
414
+ log_lines.append(
415
+ f"添加文件到对话失败: {add_result.get('errorMsg')}"
416
+ )
390
417
  continue
391
418
 
392
419
  file_info.update(add_result.get("data", {}))
393
420
 
394
421
  log_lines.append(f"文件 {file_name} 上传成功")
395
- joined_logs = '\n'.join(log_lines)
396
- print(f"ℹ️ {joined_logs}")
422
+ joined_logs = "\n".join(log_lines)
423
+ PrettyOutput.auto_print(f"ℹ️ {joined_logs}")
397
424
  time.sleep(1) # 短暂暂停以便用户看到成功状态
398
425
 
399
426
  except Exception as e:
400
427
  log_lines.append(f"上传文件 {file_name} 时出错: {str(e)}")
401
- joined_logs = '\n'.join(log_lines)
402
- print(f"❌ {joined_logs}")
428
+ joined_logs = "\n".join(log_lines)
429
+ PrettyOutput.auto_print(f"❌ {joined_logs}")
403
430
  return False
404
431
  return True
405
432
 
406
433
  except Exception as e:
407
- print(f"❌ Error uploading files: {str(e)}")
434
+ PrettyOutput.auto_print(f"❌ Error uploading files: {str(e)}")
408
435
  return False
409
436
 
410
437
  def _get_content_type(self, file_path: str) -> str:
@@ -469,9 +496,12 @@ class TongyiPlatform(BasePlatform):
469
496
 
470
497
  try:
471
498
  response = while_success(
472
- lambda: http.post(url, headers=headers, json=payload) )
499
+ lambda: http.post(url, headers=headers, json=payload)
500
+ )
473
501
  if response.status_code != 200:
474
- print(f"❌ Failed to delete chat: HTTP {response.status_code}")
502
+ PrettyOutput.auto_print(
503
+ f"❌ Failed to delete chat: HTTP {response.status_code}"
504
+ )
475
505
  return False
476
506
  self.request_id = ""
477
507
  self.session_id = ""
@@ -479,13 +509,13 @@ class TongyiPlatform(BasePlatform):
479
509
  self.first_chat = True # Reset first_chat flag
480
510
  return True
481
511
  except Exception as e:
482
- print(f"❌ Error deleting chat: {str(e)}")
512
+ PrettyOutput.auto_print(f"❌ Error deleting chat: {str(e)}")
483
513
  return False
484
514
 
485
515
  def save(self, file_path: str) -> bool:
486
516
  """Save chat session to a file."""
487
517
  if not self.session_id:
488
- print("⚠️ 没有活动的会话可供保存")
518
+ PrettyOutput.auto_print("⚠️ 没有活动的会话可供保存")
489
519
  return False
490
520
 
491
521
  state = {
@@ -502,10 +532,10 @@ class TongyiPlatform(BasePlatform):
502
532
  with open(file_path, "w", encoding="utf-8") as f:
503
533
  json.dump(state, f, ensure_ascii=False, indent=4)
504
534
  self._saved = True
505
- print(f"✅ 会话已成功保存到 {file_path}")
535
+ PrettyOutput.auto_print(f"✅ 会话已成功保存到 {file_path}")
506
536
  return True
507
537
  except Exception as e:
508
- print(f"❌ 保存会话失败: {str(e)}")
538
+ PrettyOutput.auto_print(f"❌ 保存会话失败: {str(e)}")
509
539
  return False
510
540
 
511
541
  def restore(self, file_path: str) -> bool:
@@ -523,13 +553,13 @@ class TongyiPlatform(BasePlatform):
523
553
  self.first_chat = state.get("first_chat", True)
524
554
  self._saved = True
525
555
 
526
- print(f"✅ 从 {file_path} 成功恢复会话")
556
+ PrettyOutput.auto_print(f"✅ 从 {file_path} 成功恢复会话")
527
557
  return True
528
558
  except FileNotFoundError:
529
- print(f"❌ 会话文件未找到: {file_path}")
559
+ PrettyOutput.auto_print(f"❌ 会话文件未找到: {file_path}")
530
560
  return False
531
561
  except Exception as e:
532
- print(f"❌ 恢复会话失败: {str(e)}")
562
+ PrettyOutput.auto_print(f"❌ 恢复会话失败: {str(e)}")
533
563
  return False
534
564
 
535
565
  def set_system_prompt(self, message: str):
@@ -564,20 +594,20 @@ class TongyiPlatform(BasePlatform):
564
594
  @classmethod
565
595
  def get_required_env_keys(cls) -> List[str]:
566
596
  """
567
- 获取通义平台所需的环境变量键列表
597
+ 获取通义平台所需的配置键列表(已弃用:建议使用 llm_config 配置)
568
598
 
569
599
  返回:
570
- List[str]: 环境变量键的列表
600
+ List[str]: 配置键的列表(对应 llm_config 中的 tongyi_cookies)
571
601
  """
572
602
  return ["TONGYI_COOKIES"]
573
603
 
574
604
  @classmethod
575
605
  def get_env_config_guide(cls) -> Dict[str, str]:
576
606
  """
577
- 获取环境变量配置指导
607
+ 获取配置指导(已弃用:建议使用 llm_config 配置)
578
608
 
579
609
  返回:
580
- Dict[str, str]: 环境变量名到配置指导的映射
610
+ Dict[str, str]: 配置键名到配置指导的映射
581
611
  """
582
612
  return {
583
613
  "TONGYI_COOKIES": (
@@ -5,13 +5,21 @@ import json
5
5
  import os
6
6
  import time
7
7
  import urllib.parse
8
- from typing import Dict, Generator, List, Tuple
8
+ from typing import Any
9
+ from typing import Dict
10
+ from typing import Generator
11
+ from typing import List
12
+ from typing import Optional
13
+ from typing import Tuple
14
+ from typing import cast
9
15
 
10
- from PIL import Image # type: ignore
16
+ from PIL import Image
11
17
 
12
18
  from jarvis.jarvis_platform.base import BasePlatform
13
19
  from jarvis.jarvis_utils import http
14
- from jarvis.jarvis_utils.tag import ot, ct
20
+ from jarvis.jarvis_utils.output import PrettyOutput
21
+ from jarvis.jarvis_utils.tag import ct
22
+ from jarvis.jarvis_utils.tag import ot
15
23
  from jarvis.jarvis_utils.utils import while_success
16
24
 
17
25
 
@@ -27,25 +35,30 @@ class YuanbaoPlatform(BasePlatform):
27
35
  ("hunyuan_t1", "Tencent Hunyuan-T1"),
28
36
  ]
29
37
 
30
- def __init__(self):
38
+ def __init__(self, llm_config: Optional[Dict[str, Any]] = None):
31
39
  """
32
40
  初始化Hunyuan模型
41
+
42
+ 参数:
43
+ llm_config: LLM配置字典,包含 yuanbao_cookies 等
33
44
  """
34
45
  super().__init__()
35
46
  self.conversation_id = "" # 会话ID,用于标识当前对话
36
- # 从环境变量中获取必要参数
37
- self.cookies = os.getenv("YUANBAO_COOKIES") # 认证cookies
47
+ llm_config = llm_config or {}
48
+
49
+ # 从 llm_config 获取配置,如果没有则从环境变量获取(向后兼容)
50
+ self.cookies = llm_config.get("yuanbao_cookies") or os.getenv("YUANBAO_COOKIES")
38
51
  self.agent_id = "naQivTmsDa"
39
52
 
40
53
  if not self.cookies:
41
54
  raise ValueError(
42
- "YUANBAO_COOKIES environment variable not set. Please provide your cookies to use the Yuanbao platform."
55
+ "yuanbao_cookies 未设置。请在 llm_config 中配置 yuanbao_cookies 或设置 YUANBAO_COOKIES 环境变量。"
43
56
  )
44
57
 
45
58
  self.system_message = "" # 系统消息,用于初始化对话
46
59
  self.first_chat = True # 标识是否为第一次对话
47
60
  self.model_name = "deep_seek_v3" # 默认模型名称,使用下划线保持一致
48
- self.multimedia = []
61
+ self.multimedia: List[Dict[str, Any]] = []
49
62
 
50
63
  def set_system_prompt(self, message: str):
51
64
  """设置系统消息"""
@@ -58,7 +71,7 @@ class YuanbaoPlatform(BasePlatform):
58
71
  if model_name in model_mapping:
59
72
  self.model_name = model_name
60
73
  else:
61
- print(f"❌ 错误:不支持的模型: {model_name}")
74
+ PrettyOutput.auto_print(f"❌ 错误:不支持的模型: {model_name}")
62
75
 
63
76
  def _get_base_headers(self):
64
77
  """获取API请求的基础头部信息"""
@@ -76,7 +89,6 @@ class YuanbaoPlatform(BasePlatform):
76
89
  "Referer": f"https://yuanbao.tencent.com/chat/{self.agent_id}",
77
90
  "X-Source": "web",
78
91
  "Accept-Encoding": "gzip, deflate, br, zstd",
79
-
80
92
  "Sec-Fetch-Site": "same-origin",
81
93
  "Sec-Fetch-Mode": "cors",
82
94
  "Sec-Fetch-Dest": "empty",
@@ -102,10 +114,10 @@ class YuanbaoPlatform(BasePlatform):
102
114
  self.conversation_id = response_json["id"]
103
115
  return True
104
116
  else:
105
- print(f"❌ 错误:创建会话失败,响应: {response_json}")
117
+ PrettyOutput.auto_print(f"❌ 错误:创建会话失败,响应: {response_json}")
106
118
  return False
107
119
  except Exception as e:
108
- print(f"❌ 错误:创建会话失败:{e}")
120
+ PrettyOutput.auto_print(f"❌ 错误:创建会话失败:{e}")
109
121
  return False
110
122
 
111
123
  def support_upload_files(self) -> bool:
@@ -122,7 +134,7 @@ class YuanbaoPlatform(BasePlatform):
122
134
  用于聊天消息的文件元数据字典列表
123
135
  """
124
136
  if not self.cookies:
125
- print("❌ 未设置YUANBAO_COOKIES,无法上传文件")
137
+ PrettyOutput.auto_print("❌ 未设置yuanbao_cookies,无法上传文件")
126
138
  return False
127
139
 
128
140
  uploaded_files = []
@@ -192,8 +204,8 @@ class YuanbaoPlatform(BasePlatform):
192
204
  upload_info = self._generate_upload_info(file_name)
193
205
  if not upload_info:
194
206
  log_lines.append(f"无法获取文件 {file_name} 的上传信息")
195
- joined_logs = '\n'.join(log_lines)
196
- print(f"❌ {joined_logs}")
207
+ joined_logs = "\n".join(log_lines)
208
+ PrettyOutput.auto_print(f"❌ {joined_logs}")
197
209
  return False
198
210
 
199
211
  # 3. Upload the file to COS
@@ -201,8 +213,8 @@ class YuanbaoPlatform(BasePlatform):
201
213
  upload_success = self._upload_file_to_cos(file_path, upload_info)
202
214
  if not upload_success:
203
215
  log_lines.append(f"上传文件 {file_name} 失败")
204
- joined_logs = '\n'.join(log_lines)
205
- print(f"❌ {joined_logs}")
216
+ joined_logs = "\n".join(log_lines)
217
+ PrettyOutput.auto_print(f"❌ {joined_logs}")
206
218
  return False
207
219
 
208
220
  # 4. Create file metadata for chat
@@ -228,14 +240,14 @@ class YuanbaoPlatform(BasePlatform):
228
240
 
229
241
  uploaded_files.append(file_metadata)
230
242
  log_lines.append(f"文件 {file_name} 上传成功")
231
- joined_logs = '\n'.join(log_lines)
232
- print(f"ℹ️ {joined_logs}")
243
+ joined_logs = "\n".join(log_lines)
244
+ PrettyOutput.auto_print(f"ℹ️ {joined_logs}")
233
245
  time.sleep(3) # 上传成功后等待3秒
234
246
 
235
247
  except Exception as e:
236
248
  log_lines.append(f"上传文件 {file_path} 时出错: {str(e)}")
237
- joined_logs = '\n'.join(log_lines)
238
- print(f"❌ {joined_logs}")
249
+ joined_logs = "\n".join(log_lines)
250
+ PrettyOutput.auto_print(f"❌ {joined_logs}")
239
251
  return False
240
252
 
241
253
  self.multimedia = uploaded_files
@@ -262,16 +274,18 @@ class YuanbaoPlatform(BasePlatform):
262
274
  )
263
275
 
264
276
  if response.status_code != 200:
265
- print(f"❌ 获取上传信息失败,状态码: {response.status_code}")
277
+ PrettyOutput.auto_print(
278
+ f"❌ 获取上传信息失败,状态码: {response.status_code}"
279
+ )
266
280
  if hasattr(response, "text"):
267
- print(f"❌ 响应: {response.text}")
281
+ PrettyOutput.auto_print(f"❌ 响应: {response.text}")
268
282
  return {}
269
283
 
270
284
  upload_info = response.json()
271
- return upload_info
285
+ return cast(Dict[str, Any], upload_info)
272
286
 
273
287
  except Exception as e:
274
- print(f"❌ 获取上传信息时出错: {str(e)}")
288
+ PrettyOutput.auto_print(f"❌ 获取上传信息时出错: {str(e)}")
275
289
  return {}
276
290
 
277
291
  def _upload_file_to_cos(self, file_path: str, upload_info: Dict) -> bool:
@@ -302,7 +316,7 @@ class YuanbaoPlatform(BasePlatform):
302
316
  with open(file_path, "rb") as file:
303
317
  file_content = file.read()
304
318
 
305
- print(f"ℹ️ 上传文件大小: {len(file_content)}")
319
+ PrettyOutput.auto_print(f"ℹ️ 上传文件大小: {len(file_content)}")
306
320
 
307
321
  # Prepare headers for PUT request
308
322
  host = f"{upload_info['bucketName']}.{upload_info.get('accelerateDomain', 'cos.accelerate.myqcloud.com')}"
@@ -334,15 +348,17 @@ class YuanbaoPlatform(BasePlatform):
334
348
  response = http.put(url, headers=headers, data=file_content)
335
349
 
336
350
  if response.status_code not in [200, 204]:
337
- print(f"❌ 文件上传到COS失败,状态码: {response.status_code}")
351
+ PrettyOutput.auto_print(
352
+ f"❌ 文件上传到COS失败,状态码: {response.status_code}"
353
+ )
338
354
  if hasattr(response, "text"):
339
- print(f"❌ 响应: {response.text}")
355
+ PrettyOutput.auto_print(f"❌ 响应: {response.text}")
340
356
  return False
341
357
 
342
358
  return True
343
359
 
344
360
  except Exception as e:
345
- print(f"❌ 上传文件到COS时出错: {str(e)}")
361
+ PrettyOutput.auto_print(f"❌ 上传文件到COS时出错: {str(e)}")
346
362
  return False
347
363
 
348
364
  def _generate_cos_signature(
@@ -404,7 +420,7 @@ class YuanbaoPlatform(BasePlatform):
404
420
  return signature
405
421
 
406
422
  except Exception as e:
407
- print(f"❌ 生成签名时出错: {str(e)}")
423
+ PrettyOutput.auto_print(f"❌ 生成签名时出错: {str(e)}")
408
424
  raise e
409
425
 
410
426
  def chat(self, message: str) -> Generator[str, None, None]:
@@ -550,18 +566,18 @@ class YuanbaoPlatform(BasePlatform):
550
566
  self.first_chat = True
551
567
  return True
552
568
  else:
553
- print(f"⚠️ 删除会话失败: HTTP {response.status_code}")
569
+ PrettyOutput.auto_print(f"⚠️ 删除会话失败: HTTP {response.status_code}")
554
570
  if hasattr(response, "text"):
555
- print(f"⚠️ 响应: {response.text}")
571
+ PrettyOutput.auto_print(f"⚠️ 响应: {response.text}")
556
572
  return False
557
573
  except Exception as e:
558
- print(f"❌ 删除会话时发生错误: {str(e)}")
574
+ PrettyOutput.auto_print(f"❌ 删除会话时发生错误: {str(e)}")
559
575
  return False
560
576
 
561
577
  def save(self, file_path: str) -> bool:
562
578
  """Save chat session to a file."""
563
579
  if not self.conversation_id:
564
- print("⚠️ 没有活动的会话可供保存")
580
+ PrettyOutput.auto_print("⚠️ 没有活动的会话可供保存")
565
581
  return False
566
582
 
567
583
  state = {
@@ -576,10 +592,10 @@ class YuanbaoPlatform(BasePlatform):
576
592
  with open(file_path, "w", encoding="utf-8") as f:
577
593
  json.dump(state, f, ensure_ascii=False, indent=4)
578
594
  self._saved = True
579
- print(f"✅ 会话已成功保存到 {file_path}")
595
+ PrettyOutput.auto_print(f"✅ 会话已成功保存到 {file_path}")
580
596
  return True
581
597
  except Exception as e:
582
- print(f"❌ 保存会话失败: {str(e)}")
598
+ PrettyOutput.auto_print(f"❌ 保存会话失败: {str(e)}")
583
599
  return False
584
600
 
585
601
  def restore(self, file_path: str) -> bool:
@@ -595,13 +611,13 @@ class YuanbaoPlatform(BasePlatform):
595
611
  self.multimedia = state.get("multimedia", [])
596
612
  self._saved = True
597
613
 
598
- print(f"✅ 从 {file_path} 成功恢复会话")
614
+ PrettyOutput.auto_print(f"✅ 从 {file_path} 成功恢复会话")
599
615
  return True
600
616
  except FileNotFoundError:
601
- print(f"❌ 会话文件未找到: {file_path}")
617
+ PrettyOutput.auto_print(f"❌ 会话文件未找到: {file_path}")
602
618
  return False
603
619
  except Exception as e:
604
- print(f"❌ 恢复会话失败: {str(e)}")
620
+ PrettyOutput.auto_print(f"❌ 恢复会话失败: {str(e)}")
605
621
  return False
606
622
 
607
623
  def name(self) -> str:
@@ -620,20 +636,20 @@ class YuanbaoPlatform(BasePlatform):
620
636
  @classmethod
621
637
  def get_required_env_keys(cls) -> List[str]:
622
638
  """
623
- 获取元宝平台所需的环境变量键列表
639
+ 获取元宝平台所需的配置键列表(已弃用:建议使用 llm_config 配置)
624
640
 
625
641
  返回:
626
- List[str]: 环境变量键的列表
642
+ List[str]: 配置键的列表(对应 llm_config 中的 yuanbao_cookies)
627
643
  """
628
644
  return ["YUANBAO_COOKIES"]
629
645
 
630
646
  @classmethod
631
647
  def get_env_config_guide(cls) -> Dict[str, str]:
632
648
  """
633
- 获取环境变量配置指导
649
+ 获取配置指导(已弃用:建议使用 llm_config 配置)
634
650
 
635
651
  返回:
636
- Dict[str, str]: 环境变量名到配置指导的映射
652
+ Dict[str, str]: 配置键名到配置指导的映射
637
653
  """
638
654
  return {
639
655
  "YUANBAO_COOKIES": (