jarvis-ai-assistant 0.1.207__py3-none-any.whl → 0.1.209__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 (42) hide show
  1. jarvis/__init__.py +1 -1
  2. jarvis/jarvis_agent/__init__.py +63 -103
  3. jarvis/jarvis_agent/edit_file_handler.py +43 -47
  4. jarvis/jarvis_agent/jarvis.py +33 -39
  5. jarvis/jarvis_code_agent/code_agent.py +74 -30
  6. jarvis/jarvis_code_agent/lint.py +6 -6
  7. jarvis/jarvis_code_analysis/code_review.py +164 -175
  8. jarvis/jarvis_data/config_schema.json +0 -25
  9. jarvis/jarvis_git_utils/git_commiter.py +148 -153
  10. jarvis/jarvis_methodology/main.py +70 -81
  11. jarvis/jarvis_platform/base.py +21 -17
  12. jarvis/jarvis_platform/kimi.py +59 -64
  13. jarvis/jarvis_platform/tongyi.py +118 -131
  14. jarvis/jarvis_platform/yuanbao.py +117 -122
  15. jarvis/jarvis_platform_manager/main.py +102 -502
  16. jarvis/jarvis_platform_manager/service.py +432 -0
  17. jarvis/jarvis_smart_shell/main.py +99 -33
  18. jarvis/jarvis_tools/ask_user.py +0 -1
  19. jarvis/jarvis_tools/edit_file.py +64 -55
  20. jarvis/jarvis_tools/file_analyzer.py +17 -28
  21. jarvis/jarvis_tools/read_code.py +80 -81
  22. jarvis/jarvis_utils/builtin_replace_map.py +1 -36
  23. jarvis/jarvis_utils/config.py +13 -48
  24. jarvis/jarvis_utils/embedding.py +6 -51
  25. jarvis/jarvis_utils/git_utils.py +93 -43
  26. jarvis/jarvis_utils/http.py +104 -0
  27. jarvis/jarvis_utils/methodology.py +12 -17
  28. jarvis/jarvis_utils/utils.py +186 -63
  29. {jarvis_ai_assistant-0.1.207.dist-info → jarvis_ai_assistant-0.1.209.dist-info}/METADATA +4 -19
  30. {jarvis_ai_assistant-0.1.207.dist-info → jarvis_ai_assistant-0.1.209.dist-info}/RECORD +34 -40
  31. {jarvis_ai_assistant-0.1.207.dist-info → jarvis_ai_assistant-0.1.209.dist-info}/entry_points.txt +1 -1
  32. jarvis/jarvis_data/huggingface.tar.gz +0 -0
  33. jarvis/jarvis_dev/main.py +0 -1247
  34. jarvis/jarvis_tools/chdir.py +0 -72
  35. jarvis/jarvis_tools/code_plan.py +0 -218
  36. jarvis/jarvis_tools/create_code_agent.py +0 -95
  37. jarvis/jarvis_tools/create_sub_agent.py +0 -82
  38. jarvis/jarvis_tools/file_operation.py +0 -238
  39. jarvis/jarvis_utils/jarvis_history.py +0 -98
  40. {jarvis_ai_assistant-0.1.207.dist-info → jarvis_ai_assistant-0.1.209.dist-info}/WHEEL +0 -0
  41. {jarvis_ai_assistant-0.1.207.dist-info → jarvis_ai_assistant-0.1.209.dist-info}/licenses/LICENSE +0 -0
  42. {jarvis_ai_assistant-0.1.207.dist-info → jarvis_ai_assistant-0.1.209.dist-info}/top_level.txt +0 -0
@@ -7,13 +7,10 @@ import time
7
7
  import urllib.parse
8
8
  from typing import Dict, Generator, List, Tuple
9
9
 
10
- import requests
11
- from PIL import Image
12
- from yaspin import yaspin
13
- from yaspin.api import Yaspin
14
- from yaspin.spinners import Spinners
10
+ from PIL import Image # type: ignore
15
11
 
16
12
  from jarvis.jarvis_platform.base import BasePlatform
13
+ from jarvis.jarvis_utils import http
17
14
  from jarvis.jarvis_utils.output import OutputType, PrettyOutput
18
15
  from jarvis.jarvis_utils.utils import while_success
19
16
 
@@ -40,7 +37,7 @@ class YuanbaoPlatform(BasePlatform):
40
37
  self.conversation_id = "" # 会话ID,用于标识当前对话
41
38
  # 从环境变量中获取必要参数
42
39
  self.cookies = os.getenv("YUANBAO_COOKIES") # 认证cookies
43
- self.agent_id = os.getenv("YUANBAO_AGENT_ID") # 代理ID
40
+ self.agent_id = "naQivTmsDa"
44
41
 
45
42
  if not self.cookies:
46
43
  PrettyOutput.print("YUANBAO_COOKIES 未设置", OutputType.WARNING)
@@ -98,7 +95,8 @@ class YuanbaoPlatform(BasePlatform):
98
95
 
99
96
  try:
100
97
  response = while_success(
101
- lambda: requests.post(url, headers=headers, data=payload, timeout=600), sleep_time=5
98
+ lambda: http.post(url, headers=headers, data=payload),
99
+ sleep_time=5,
102
100
  )
103
101
  response_json = response.json()
104
102
 
@@ -135,115 +133,107 @@ class YuanbaoPlatform(BasePlatform):
135
133
 
136
134
  for file_path in file_list:
137
135
  file_name = os.path.basename(file_path)
138
- with yaspin(Spinners.dots, text=f"上传文件 {file_name}") as spinner:
139
- try:
140
-
141
- # 1. Prepare the file information
142
- spinner.text = f"准备文件信息: {file_name}"
143
- file_size = os.path.getsize(file_path)
144
- file_extension = os.path.splitext(file_path)[1].lower().lstrip(".")
145
-
146
- # Determine file_type using file extension
147
- file_type = "txt" # Default type
148
-
149
- # Image types
150
- if file_extension in ["jpg", "jpeg", "png", "webp", "bmp", "gif"]:
151
- file_type = "image"
152
- # PDF type
153
- elif file_extension == "pdf":
154
- file_type = "pdf"
155
- # Spreadsheet types
156
- elif file_extension in ["xls", "xlsx"]:
157
- file_type = "excel"
158
- # Presentation types
159
- elif file_extension in ["ppt", "pptx"]:
160
- file_type = "ppt"
161
- # Document types
162
- elif file_extension in ["doc", "docx"]:
163
- file_type = "doc"
164
- # Code file types
165
- elif file_extension in [
166
- "bat",
167
- "c",
168
- "cpp",
169
- "cs",
170
- "css",
171
- "go",
172
- "h",
173
- "hpp",
174
- "ini",
175
- "java",
176
- "js",
177
- "json",
178
- "log",
179
- "lua",
180
- "php",
181
- "pl",
182
- "py",
183
- "rb",
184
- "sh",
185
- "sql",
186
- "swift",
187
- "tex",
188
- "toml",
189
- "vue",
190
- "yaml",
191
- "yml",
192
- "rs",
193
- ]:
194
- file_type = "code"
195
-
196
- # 2. Generate upload information
197
- spinner.text = f"获取上传信息: {file_name}"
198
- upload_info = self._generate_upload_info(file_name)
199
- if not upload_info:
200
- spinner.text = f"无法获取文件 {file_name} 的上传信息"
201
- spinner.fail("❌")
202
- return False
203
-
204
- # 3. Upload the file to COS
205
- spinner.text = f"上传文件到云存储: {file_name}"
206
- upload_success = self._upload_file_to_cos(
207
- file_path, upload_info, spinner
208
- )
209
- if not upload_success:
210
- spinner.text = f"上传文件 {file_name} 失败"
211
- spinner.fail("❌")
212
- return False
213
-
214
- # 4. Create file metadata for chat
215
- spinner.text = f"生成文件元数据: {file_name}"
216
- file_metadata = {
217
- "type": file_type,
218
- "docType": file_extension if file_extension else file_type,
219
- "url": upload_info.get("resourceUrl", ""),
220
- "fileName": file_name,
221
- "size": file_size,
222
- "width": 0,
223
- "height": 0,
224
- }
225
-
226
- # Get image dimensions if it's an image file
227
- if file_type == "image":
228
- try:
229
- with Image.open(file_path) as img:
230
- file_metadata["width"] = img.width
231
- file_metadata["height"] = img.height
232
- except Exception as e:
233
- spinner.write(
234
- f"⚠️ 无法获取图片 {file_name} 的尺寸: {str(e)}"
235
- )
236
-
237
- uploaded_files.append(file_metadata)
238
- spinner.text = f"文件 {file_name} 上传成功"
239
- spinner.ok("✅")
240
- time.sleep(3) # 上传成功后等待3秒
241
-
242
- except Exception as e:
243
- spinner.text = f"上传文件 {file_path} 时出错: {str(e)}"
244
- spinner.fail("❌")
136
+ print(f"🔍 上传文件 {file_name}")
137
+ try:
138
+
139
+ # 1. Prepare the file information
140
+ print(f"🔍 准备文件信息: {file_name}")
141
+ file_size = os.path.getsize(file_path)
142
+ file_extension = os.path.splitext(file_path)[1].lower().lstrip(".")
143
+
144
+ # Determine file_type using file extension
145
+ file_type = "txt" # Default type
146
+
147
+ # Image types
148
+ if file_extension in ["jpg", "jpeg", "png", "webp", "bmp", "gif"]:
149
+ file_type = "image"
150
+ # PDF type
151
+ elif file_extension == "pdf":
152
+ file_type = "pdf"
153
+ # Spreadsheet types
154
+ elif file_extension in ["xls", "xlsx"]:
155
+ file_type = "excel"
156
+ # Presentation types
157
+ elif file_extension in ["ppt", "pptx"]:
158
+ file_type = "ppt"
159
+ # Document types
160
+ elif file_extension in ["doc", "docx"]:
161
+ file_type = "doc"
162
+ # Code file types
163
+ elif file_extension in [
164
+ "bat",
165
+ "c",
166
+ "cpp",
167
+ "cs",
168
+ "css",
169
+ "go",
170
+ "h",
171
+ "hpp",
172
+ "ini",
173
+ "java",
174
+ "js",
175
+ "json",
176
+ "log",
177
+ "lua",
178
+ "php",
179
+ "pl",
180
+ "py",
181
+ "rb",
182
+ "sh",
183
+ "sql",
184
+ "swift",
185
+ "tex",
186
+ "toml",
187
+ "vue",
188
+ "yaml",
189
+ "yml",
190
+ "rs",
191
+ ]:
192
+ file_type = "code"
193
+
194
+ # 2. Generate upload information
195
+ print(f"🔍 获取上传信息: {file_name}")
196
+ upload_info = self._generate_upload_info(file_name)
197
+ if not upload_info:
198
+ print(f"无法获取文件 {file_name} 的上传信息")
199
+ return False
200
+
201
+ # 3. Upload the file to COS
202
+ print(f"🔍 上传文件到云存储: {file_name}")
203
+ upload_success = self._upload_file_to_cos(file_path, upload_info)
204
+ if not upload_success:
205
+ print(f"❌ 上传文件 {file_name} 失败")
245
206
  return False
246
207
 
208
+ # 4. Create file metadata for chat
209
+ print(f"🔍 生成文件元数据: {file_name}")
210
+ file_metadata = {
211
+ "type": file_type,
212
+ "docType": file_extension if file_extension else file_type,
213
+ "url": upload_info.get("resourceUrl", ""),
214
+ "fileName": file_name,
215
+ "size": file_size,
216
+ "width": 0,
217
+ "height": 0,
218
+ }
219
+
220
+ # Get image dimensions if it's an image file
221
+ if file_type == "image":
222
+ try:
223
+ with Image.open(file_path) as img:
224
+ file_metadata["width"] = img.width
225
+ file_metadata["height"] = img.height
226
+ except Exception as e:
227
+ print(f"⚠️ 无法获取图片 {file_name} 的尺寸: {str(e)}")
228
+
229
+ uploaded_files.append(file_metadata)
230
+ print(f"✅ 文件 {file_name} 上传成功")
231
+ time.sleep(3) # 上传成功后等待3秒
232
+
233
+ except Exception as e:
234
+ print(f"❌ 上传文件 {file_path} 时出错: {str(e)}")
235
+ return False
236
+
247
237
  self.multimedia = uploaded_files
248
238
  return True
249
239
 
@@ -264,7 +254,8 @@ class YuanbaoPlatform(BasePlatform):
264
254
 
265
255
  try:
266
256
  response = while_success(
267
- lambda: requests.post(url, headers=headers, json=payload, timeout=600), sleep_time=5
257
+ lambda: http.post(url, headers=headers, json=payload),
258
+ sleep_time=5,
268
259
  )
269
260
 
270
261
  if response.status_code != 200:
@@ -283,9 +274,7 @@ class YuanbaoPlatform(BasePlatform):
283
274
  PrettyOutput.print(f"获取上传信息时出错: {str(e)}", OutputType.ERROR)
284
275
  return {}
285
276
 
286
- def _upload_file_to_cos(
287
- self, file_path: str, upload_info: Dict, spinner: Yaspin
288
- ) -> bool:
277
+ def _upload_file_to_cos(self, file_path: str, upload_info: Dict) -> bool:
289
278
  """使用提供的上传信息将文件上传到腾讯COS
290
279
 
291
280
  参数:
@@ -313,7 +302,7 @@ class YuanbaoPlatform(BasePlatform):
313
302
  with open(file_path, "rb") as file:
314
303
  file_content = file.read()
315
304
 
316
- spinner.write(f"ℹ️ 上传文件大小: {len(file_content)}")
305
+ print(f"ℹ️ 上传文件大小: {len(file_content)}")
317
306
 
318
307
  # Prepare headers for PUT request
319
308
  host = f"{upload_info['bucketName']}.{upload_info.get('accelerateDomain', 'cos.accelerate.myqcloud.com')}"
@@ -342,7 +331,7 @@ class YuanbaoPlatform(BasePlatform):
342
331
  )
343
332
 
344
333
  # Upload the file
345
- response = requests.put(url, headers=headers, data=file_content)
334
+ response = http.put(url, headers=headers, data=file_content)
346
335
 
347
336
  if response.status_code not in [200, 204]:
348
337
  PrettyOutput.print(
@@ -481,7 +470,12 @@ class YuanbaoPlatform(BasePlatform):
481
470
  try:
482
471
  # 发送消息请求,获取流式响应
483
472
  response = while_success(
484
- lambda: requests.post(url, headers=headers, json=payload, stream=True, timeout=600),
473
+ lambda: http.post(
474
+ url,
475
+ headers=headers,
476
+ json=payload,
477
+ stream=True,
478
+ ),
485
479
  sleep_time=5,
486
480
  )
487
481
 
@@ -556,7 +550,8 @@ class YuanbaoPlatform(BasePlatform):
556
550
 
557
551
  try:
558
552
  response = while_success(
559
- lambda: requests.post(url, headers=headers, json=payload, timeout=600), sleep_time=5
553
+ lambda: http.post(url, headers=headers, json=payload),
554
+ sleep_time=5,
560
555
  )
561
556
 
562
557
  if response.status_code == 200: