auto-coder-web 0.1.24__py3-none-any.whl → 0.1.26__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 (30) hide show
  1. auto_coder_web/auto_coder_runner_wrapper.py +7 -0
  2. auto_coder_web/common_router/__init__.py +0 -0
  3. auto_coder_web/common_router/auto_coder_conf_router.py +39 -0
  4. auto_coder_web/common_router/chat_list_router.py +75 -0
  5. auto_coder_web/common_router/completions_router.py +53 -0
  6. auto_coder_web/common_router/file_group_router.py +192 -0
  7. auto_coder_web/common_router/file_router.py +79 -0
  8. auto_coder_web/proxy.py +22 -477
  9. auto_coder_web/routers/chat_router.py +330 -0
  10. auto_coder_web/routers/coding_router.py +330 -0
  11. auto_coder_web/routers/config_router.py +199 -0
  12. auto_coder_web/routers/todo_router.py +463 -20
  13. auto_coder_web/version.py +1 -1
  14. auto_coder_web/web/asset-manifest.json +6 -6
  15. auto_coder_web/web/index.html +1 -1
  16. auto_coder_web/web/static/css/main.b9764291.css +6 -0
  17. auto_coder_web/web/static/css/main.b9764291.css.map +1 -0
  18. auto_coder_web/web/static/js/main.a707a18c.js +3 -0
  19. auto_coder_web/web/static/js/{main.470202a1.js.LICENSE.txt → main.a707a18c.js.LICENSE.txt} +43 -1
  20. auto_coder_web/web/static/js/{main.470202a1.js.map → main.a707a18c.js.map} +1 -1
  21. {auto_coder_web-0.1.24.dist-info → auto_coder_web-0.1.26.dist-info}/METADATA +1 -1
  22. {auto_coder_web-0.1.24.dist-info → auto_coder_web-0.1.26.dist-info}/RECORD +27 -16
  23. {auto_coder_web-0.1.24.dist-info → auto_coder_web-0.1.26.dist-info}/top_level.txt +1 -0
  24. expert_routers/__init__.py +3 -0
  25. expert_routers/history_router.py +333 -0
  26. auto_coder_web/web/static/css/main.770925e5.css +0 -6
  27. auto_coder_web/web/static/css/main.770925e5.css.map +0 -1
  28. auto_coder_web/web/static/js/main.470202a1.js +0 -3
  29. {auto_coder_web-0.1.24.dist-info → auto_coder_web-0.1.26.dist-info}/WHEEL +0 -0
  30. {auto_coder_web-0.1.24.dist-info → auto_coder_web-0.1.26.dist-info}/entry_points.txt +0 -0
@@ -46,6 +46,13 @@ class AutoCoderRunnerWrapper:
46
46
 
47
47
  def configure_wrapper(self,conf: str, skip_print=False ):
48
48
  return configure(conf, skip_print)
49
+
50
+
51
+ def coding_wapper(self,query):
52
+ return coding(query)
53
+
54
+ def chat_wrapper(self,query):
55
+ return chat(query)
49
56
 
50
57
 
51
58
 
File without changes
@@ -0,0 +1,39 @@
1
+ from fastapi import APIRouter, Request, HTTPException, Depends
2
+ from autocoder.auto_coder_runner import get_memory, configure
3
+
4
+ router = APIRouter()
5
+
6
+
7
+ @router.get("/api/conf")
8
+ async def get_conf():
9
+ """获取配置信息"""
10
+ memory = get_memory()
11
+ return {"conf": memory["conf"]}
12
+
13
+
14
+ @router.post("/api/conf")
15
+ async def config(
16
+ request: Request,
17
+ ):
18
+ """更新配置信息"""
19
+ data = await request.json()
20
+ try:
21
+ for key, value in data.items():
22
+ configure(f"{key}:{str(value)}")
23
+ return {"status": "success"}
24
+ except Exception as e:
25
+ raise HTTPException(status_code=400, detail=str(e))
26
+
27
+
28
+ @router.delete("/api/conf/{key}")
29
+ async def delete_config(
30
+ key: str
31
+ ):
32
+ """删除配置项"""
33
+ try:
34
+ configure(f"/drop {key}")
35
+ return {"status": "success"}
36
+ except ValueError as e:
37
+ raise HTTPException(status_code=404, detail=str(e))
38
+ except Exception as e:
39
+ raise HTTPException(status_code=400, detail=str(e))
@@ -0,0 +1,75 @@
1
+ import os
2
+ import json
3
+ from fastapi import APIRouter, HTTPException
4
+ import aiofiles
5
+ from auto_coder_web.types import ChatList
6
+
7
+ router = APIRouter()
8
+
9
+ @router.post("/api/chat-lists/save")
10
+ async def save_chat_list(chat_list: ChatList):
11
+ try:
12
+ chat_lists_dir = os.path.join(
13
+ ".auto-coder", "auto-coder.web", "chat-lists")
14
+ os.makedirs(chat_lists_dir, exist_ok=True)
15
+
16
+ file_path = os.path.join(
17
+ chat_lists_dir, f"{chat_list.name}.json")
18
+ async with aiofiles.open(file_path, 'w') as f:
19
+ await f.write(json.dumps({"messages": chat_list.messages}, indent=2))
20
+ return {"status": "success", "message": f"Chat list {chat_list.name} saved successfully"}
21
+ except Exception as e:
22
+ raise HTTPException(status_code=500, detail=str(e))
23
+
24
+ @router.get("/api/chat-lists")
25
+ async def get_chat_lists():
26
+ try:
27
+ chat_lists_dir = os.path.join(
28
+ ".auto-coder", "auto-coder.web", "chat-lists")
29
+ os.makedirs(chat_lists_dir, exist_ok=True)
30
+
31
+ # Get files with their modification times
32
+ chat_lists = []
33
+ for file in os.listdir(chat_lists_dir):
34
+ if file.endswith('.json'):
35
+ file_path = os.path.join(chat_lists_dir, file)
36
+ mod_time = os.path.getmtime(file_path)
37
+ # Store tuple of (name, mod_time)
38
+ chat_lists.append((file[:-5], mod_time))
39
+
40
+ # Sort by modification time (newest first)
41
+ chat_lists.sort(key=lambda x: x[1], reverse=True)
42
+
43
+ # Return only the chat list names
44
+ return {"chat_lists": [name for name, _ in chat_lists]}
45
+ except Exception as e:
46
+ raise HTTPException(status_code=500, detail=str(e))
47
+
48
+ @router.get("/api/chat-lists/{name}")
49
+ async def get_chat_list(name: str):
50
+ try:
51
+ file_path = os.path.join(
52
+ ".auto-coder", "auto-coder.web", "chat-lists", f"{name}.json")
53
+ if not os.path.exists(file_path):
54
+ raise HTTPException(
55
+ status_code=404, detail=f"Chat list {name} not found")
56
+
57
+ async with aiofiles.open(file_path, 'r') as f:
58
+ content = await f.read()
59
+ return json.loads(content)
60
+ except Exception as e:
61
+ raise HTTPException(status_code=500, detail=str(e))
62
+
63
+ @router.delete("/api/chat-lists/{name}")
64
+ async def delete_chat_list(name: str):
65
+ try:
66
+ file_path = os.path.join(
67
+ ".auto-coder", "auto-coder.web", "chat-lists", f"{name}.json")
68
+ if not os.path.exists(file_path):
69
+ raise HTTPException(
70
+ status_code=404, detail=f"Chat list {name} not found")
71
+
72
+ os.remove(file_path)
73
+ return {"status": "success", "message": f"Chat list {name} deleted successfully"}
74
+ except Exception as e:
75
+ raise HTTPException(status_code=500, detail=str(e))
@@ -0,0 +1,53 @@
1
+ import os
2
+ from fastapi import APIRouter, Query, Request, Depends
3
+ from auto_coder_web.types import CompletionItem, CompletionResponse
4
+
5
+ router = APIRouter()
6
+
7
+ async def get_auto_coder_runner(request: Request):
8
+ """获取AutoCoderRunner实例作为依赖"""
9
+ return request.app.state.auto_coder_runner
10
+
11
+ @router.get("/api/completions/files")
12
+ async def get_file_completions(
13
+ name: str = Query(...),
14
+ auto_coder_runner = Depends(get_auto_coder_runner)
15
+ ):
16
+ """获取文件名补全"""
17
+ matches = auto_coder_runner.find_files_in_project([name])
18
+ completions = []
19
+ project_root = auto_coder_runner.project_path
20
+ for file_name in matches:
21
+ path_parts = file_name.split(os.sep)
22
+ # 只显示最后三层路径,让显示更简洁
23
+ display_name = os.sep.join(
24
+ path_parts[-3:]) if len(path_parts) > 3 else file_name
25
+ relative_path = os.path.relpath(file_name, project_root)
26
+
27
+ completions.append(CompletionItem(
28
+ name=relative_path, # 给补全项一个唯一标识
29
+ path=relative_path, # 实际用于替换的路径
30
+ display=display_name, # 显示的简短路径
31
+ location=relative_path # 完整的相对路径信息
32
+ ))
33
+ return CompletionResponse(completions=completions)
34
+
35
+ @router.get("/api/completions/symbols")
36
+ async def get_symbol_completions(
37
+ name: str = Query(...),
38
+ auto_coder_runner = Depends(get_auto_coder_runner)
39
+ ):
40
+ """获取符号补全"""
41
+ symbols = auto_coder_runner.get_symbol_list()
42
+ matches = []
43
+
44
+ for symbol in symbols:
45
+ if name.lower() in symbol.symbol_name.lower():
46
+ relative_path = os.path.relpath(
47
+ symbol.file_name, auto_coder_runner.project_path)
48
+ matches.append(CompletionItem(
49
+ name=symbol.symbol_name,
50
+ path=f"{symbol.symbol_name} ({relative_path}/{symbol.symbol_type.value})",
51
+ display=f"{symbol.symbol_name}(location: {relative_path})"
52
+ ))
53
+ return CompletionResponse(completions=matches)
@@ -0,0 +1,192 @@
1
+ from typing import List
2
+ import asyncio
3
+ from fastapi import APIRouter, Request, HTTPException, Depends
4
+ from autocoder.agent.auto_filegroup import AutoFileGroup
5
+ from autocoder.utils import operate_config_api
6
+ from autocoder.auto_coder_runner import get_memory,save_memory, load_memory
7
+ import json
8
+ import os
9
+
10
+ router = APIRouter()
11
+
12
+
13
+ async def get_project_path(request: Request):
14
+ """获取项目路径作为依赖"""
15
+ return request.app.state.project_path
16
+
17
+
18
+ def _create_file_group(group_name: str, description: str):
19
+ memory = get_memory()
20
+ if group_name in memory["current_files"]["groups"]:
21
+ return None
22
+
23
+ memory["current_files"]["groups"][group_name] = []
24
+
25
+ if "groups_info" not in memory["current_files"]:
26
+ memory["current_files"]["groups_info"] = {}
27
+
28
+ memory["current_files"]["groups_info"][group_name] = {
29
+ "query_prefix": description
30
+ }
31
+ save_memory()
32
+
33
+
34
+ def _add_files_to_group(project_path: str, name: str, files: List[str]):
35
+ memory = get_memory()
36
+ for file in files:
37
+ memory["current_files"]["groups"][name].append(
38
+ os.path.join(project_path, file))
39
+ save_memory()
40
+
41
+
42
+ def _remove_file_from_group(project_path: str, name: str, files: List[str]):
43
+ memory = get_memory()
44
+ for file in files:
45
+ memory["current_files"]["groups"][name].remove(
46
+ os.path.join(project_path, file))
47
+ save_memory()
48
+
49
+
50
+ def _update_group_description(name: str, description: str):
51
+ memory = get_memory()
52
+ memory["current_files"]["groups_info"][name]["query_prefix"] = description
53
+ save_memory()
54
+
55
+
56
+ def _get_groups(project_path: str):
57
+ memory = get_memory()
58
+ v = [
59
+ {
60
+ "name": group_name,
61
+ "files": memory["current_files"]["groups"][group_name],
62
+ "description": memory["current_files"]["groups_info"][group_name]["query_prefix"]
63
+ } for group_name in memory["current_files"]["groups"]
64
+ ]
65
+ return v
66
+
67
+ def _switch_groups(group_names: List[str]):
68
+ memory = get_memory()
69
+ new_files = []
70
+ for group_name in group_names:
71
+ files = memory["current_files"]["groups"][group_name]
72
+ new_files.extend(files)
73
+ memory["current_files"]["files"] = new_files
74
+ memory["current_files"]["current_groups"] = group_names
75
+ save_memory()
76
+
77
+
78
+ def _delete_file_group(project_path: str, group_name: str):
79
+ memory = get_memory()
80
+ if group_name not in memory["current_files"]["groups"]:
81
+ return None
82
+ del memory["current_files"]["groups"][group_name]
83
+ if group_name in memory["current_files"]["groups_info"]:
84
+ del memory["current_files"]["groups_info"][group_name]
85
+ save_memory()
86
+
87
+
88
+ @router.post("/api/file-groups")
89
+ async def create_file_group(
90
+ request: Request
91
+ ):
92
+ data = await request.json()
93
+ group_name = data.get("name")
94
+ description = data.get("description", "")
95
+ await asyncio.to_thread(_create_file_group, group_name, description)
96
+ return {"status": "success", "message": f"Created group: {group_name}"}
97
+
98
+
99
+ @router.post("/api/file-groups/auto")
100
+ async def auto_create_groups(
101
+ request: Request,
102
+ project_path: str = Depends(get_project_path)
103
+ ):
104
+ try:
105
+ memory = get_memory()
106
+ data = await request.json()
107
+ file_size_limit = data.get("file_size_limit", 100)
108
+ skip_diff = data.get("skip_diff", False)
109
+ group_num_limit = data.get("group_num_limit", 10)
110
+
111
+ # Create AutoFileGroup instance
112
+ auto_grouper = AutoFileGroup(
113
+ operate_config_api.get_llm(memory),
114
+ project_path,
115
+ skip_diff=skip_diff,
116
+ file_size_limit=file_size_limit,
117
+ group_num_limit=group_num_limit
118
+ )
119
+
120
+ # Get groups
121
+ groups = auto_grouper.group_files()
122
+
123
+ # Create groups using file_group_manager
124
+ for group in groups:
125
+ await asyncio.to_thread(_create_file_group,
126
+ name=group.name,
127
+ description=group.description
128
+ )
129
+ # Add files to the group
130
+ await asyncio.to_thread(_add_files_to_group,
131
+ group.name,
132
+ group.urls
133
+ )
134
+
135
+ return {"status": "success", "message": f"Created {len(groups)} groups"}
136
+ except Exception as e:
137
+ raise HTTPException(status_code=500, detail=str(e))
138
+
139
+
140
+ @router.post("/api/file-groups/switch")
141
+ async def switch_file_groups(
142
+ request: Request
143
+ ):
144
+ data = await request.json()
145
+ group_names = data.get("group_names", [])
146
+ await asyncio.to_thread(_switch_groups, group_names)
147
+ return {"status": "success", "message": f"Switched to groups: {group_names}"}
148
+
149
+
150
+ @router.delete("/api/file-groups/{name}")
151
+ async def delete_file_group(
152
+ name: str,
153
+ project_path: str = Depends(get_project_path)
154
+ ):
155
+ await asyncio.to_thread(_delete_file_group, project_path, name)
156
+ return {"status": "success", "message": f"Deleted group: {name}"}
157
+
158
+
159
+ @router.post("/api/file-groups/{name}/files")
160
+ async def add_files_to_group(
161
+ name: str,
162
+ request: Request,
163
+ project_path: str = Depends(get_project_path)
164
+ ):
165
+ data = await request.json()
166
+ files = data.get("files", [])
167
+ description = data.get("description")
168
+ if description is not None:
169
+ await asyncio.to_thread(_update_group_description, name, description)
170
+ else:
171
+ await asyncio.to_thread(_add_files_to_group, project_path, name, files)
172
+ return {"status": "success", "message": f"Added files to group: {name}"}
173
+
174
+
175
+ @router.delete("/api/file-groups/{name}/files")
176
+ async def remove_files_from_group(
177
+ name: str,
178
+ request: Request,
179
+ project_path: str = Depends(get_project_path)
180
+ ):
181
+ data = await request.json()
182
+ files = data.get("files", [])
183
+ await asyncio.to_thread(_remove_file_from_group, project_path, name, files)
184
+ return {"status": "success", "message": f"Removed files from group: {name}"}
185
+
186
+
187
+ @router.get("/api/file-groups")
188
+ async def get_file_groups(
189
+ project_path: str = Depends(get_project_path)
190
+ ):
191
+ groups = await asyncio.to_thread(_get_groups, project_path)
192
+ return {"groups": groups}
@@ -0,0 +1,79 @@
1
+ import os
2
+ import shutil
3
+ from fastapi import APIRouter, Request, HTTPException, Depends
4
+ from auto_coder_web.file_manager import get_directory_tree, read_file_content
5
+
6
+ router = APIRouter()
7
+
8
+ async def get_project_path(request: Request) -> str:
9
+ """获取项目路径作为依赖"""
10
+ return request.app.state.project_path
11
+
12
+ async def get_auto_coder_runner(request: Request):
13
+ """获取AutoCoderRunner实例作为依赖"""
14
+ return request.app.state.auto_coder_runner
15
+
16
+ @router.delete("/api/files/{path:path}")
17
+ async def delete_file(
18
+ path: str,
19
+ project_path: str = Depends(get_project_path)
20
+ ):
21
+ try:
22
+ full_path = os.path.join(project_path, path)
23
+ if os.path.exists(full_path):
24
+ if os.path.isdir(full_path):
25
+ shutil.rmtree(full_path)
26
+ else:
27
+ os.remove(full_path)
28
+ return {"message": f"Successfully deleted {path}"}
29
+ else:
30
+ raise HTTPException(
31
+ status_code=404, detail="File not found")
32
+ except Exception as e:
33
+ raise HTTPException(status_code=500, detail=str(e))
34
+
35
+ @router.get("/api/files")
36
+ async def get_files(
37
+ project_path: str = Depends(get_project_path)
38
+ ):
39
+ tree = get_directory_tree(project_path)
40
+ # print(tree)
41
+ return {"tree": tree}
42
+
43
+ @router.put("/api/file/{path:path}")
44
+ async def update_file(
45
+ path: str,
46
+ request: Request,
47
+ project_path: str = Depends(get_project_path)
48
+ ):
49
+ try:
50
+ data = await request.json()
51
+ content = data.get("content")
52
+ if content is None:
53
+ raise HTTPException(
54
+ status_code=400, detail="Content is required")
55
+
56
+ full_path = os.path.join(project_path, path)
57
+
58
+ # Ensure the directory exists
59
+ os.makedirs(os.path.dirname(full_path), exist_ok=True)
60
+
61
+ # Write the file content
62
+ with open(full_path, 'w', encoding='utf-8') as f:
63
+ f.write(content)
64
+
65
+ return {"message": f"Successfully updated {path}"}
66
+ except Exception as e:
67
+ raise HTTPException(status_code=500, detail=str(e))
68
+
69
+ @router.get("/api/file/{path:path}")
70
+ async def get_file_content(
71
+ path: str,
72
+ project_path: str = Depends(get_project_path)
73
+ ):
74
+ content = read_file_content(project_path, path)
75
+ if content is None:
76
+ raise HTTPException(
77
+ status_code=404, detail="File not found or cannot be read")
78
+
79
+ return {"content": content}