auto-coder-web 0.1.38__py3-none-any.whl → 0.1.40__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.
- auto_coder_web/auto_coder_runner_wrapper.py +6 -1
- auto_coder_web/common_router/model_router.py +157 -1
- auto_coder_web/init_project.py +26 -0
- auto_coder_web/proxy.py +40 -70
- auto_coder_web/version.py +1 -1
- auto_coder_web/web/asset-manifest.json +6 -6
- auto_coder_web/web/index.html +1 -1
- auto_coder_web/web/static/css/{main.0ef9afe0.css → main.d58ae48e.css} +3 -3
- auto_coder_web/web/static/css/main.d58ae48e.css.map +1 -0
- auto_coder_web/web/static/js/{main.2922014a.js → main.8d7d4613.js} +3 -3
- auto_coder_web/web/static/js/{main.2922014a.js.LICENSE.txt → main.8d7d4613.js.LICENSE.txt} +4 -0
- auto_coder_web/web/static/js/{main.2922014a.js.map → main.8d7d4613.js.map} +1 -1
- {auto_coder_web-0.1.38.dist-info → auto_coder_web-0.1.40.dist-info}/METADATA +1 -1
- {auto_coder_web-0.1.38.dist-info → auto_coder_web-0.1.40.dist-info}/RECORD +17 -16
- auto_coder_web/web/static/css/main.0ef9afe0.css.map +0 -1
- {auto_coder_web-0.1.38.dist-info → auto_coder_web-0.1.40.dist-info}/WHEEL +0 -0
- {auto_coder_web-0.1.38.dist-info → auto_coder_web-0.1.40.dist-info}/entry_points.txt +0 -0
- {auto_coder_web-0.1.38.dist-info → auto_coder_web-0.1.40.dist-info}/top_level.txt +0 -0
@@ -33,13 +33,18 @@ from autocoder.auto_coder_runner import (
|
|
33
33
|
completer,
|
34
34
|
summon,
|
35
35
|
get_memory,
|
36
|
+
get_all_extensions
|
36
37
|
)
|
37
38
|
|
38
39
|
class AutoCoderRunnerWrapper:
|
39
40
|
def __init__(self, project_path: str, product_mode: str = "lite"):
|
41
|
+
self.project_path = project_path
|
42
|
+
self.product_mode = product_mode
|
40
43
|
load_memory()
|
41
44
|
load_tokenizer()
|
42
|
-
|
45
|
+
|
46
|
+
def get_all_extensions_wrapper(self):
|
47
|
+
return get_all_extensions(self.project_path)
|
43
48
|
|
44
49
|
def auto_command_wrapper(self, command: str, params: Dict[str, Any]) -> Dict[str, str]:
|
45
50
|
return auto_command(command,params)
|
@@ -1,10 +1,22 @@
|
|
1
|
-
from fastapi import APIRouter, HTTPException
|
1
|
+
from fastapi import APIRouter, HTTPException, Request
|
2
2
|
from typing import List, Dict, Optional
|
3
|
+
import json
|
4
|
+
import os
|
3
5
|
from pydantic import BaseModel
|
4
6
|
from autocoder import models as model_utils
|
5
7
|
|
6
8
|
router = APIRouter()
|
7
9
|
|
10
|
+
async def get_project_path(request: Request):
|
11
|
+
"""获取项目路径作为依赖"""
|
12
|
+
return request.app.state.project_path
|
13
|
+
|
14
|
+
# Path for providers JSON file
|
15
|
+
PROVIDERS_FILE = os.path.expanduser("~/.auto-coder/keys/models_providers.json")
|
16
|
+
|
17
|
+
# Ensure directory exists
|
18
|
+
os.makedirs(os.path.dirname(PROVIDERS_FILE), exist_ok=True)
|
19
|
+
|
8
20
|
class Model(BaseModel):
|
9
21
|
name: str
|
10
22
|
description: str = ""
|
@@ -154,3 +166,147 @@ async def update_model_speed(model_name: str, speed: float):
|
|
154
166
|
raise HTTPException(status_code=404, detail="Model not found")
|
155
167
|
except Exception as e:
|
156
168
|
raise HTTPException(status_code=500, detail=str(e))
|
169
|
+
|
170
|
+
# Provider management endpoints
|
171
|
+
class ModelInfo(BaseModel):
|
172
|
+
id: str
|
173
|
+
name: str
|
174
|
+
input_price: float
|
175
|
+
output_price: float
|
176
|
+
is_reasoning: bool
|
177
|
+
|
178
|
+
class ProviderConfig(BaseModel):
|
179
|
+
name: str
|
180
|
+
base_url: str
|
181
|
+
models: List[ModelInfo]
|
182
|
+
|
183
|
+
def load_providers() -> List[Dict]:
|
184
|
+
"""Load providers from JSON file"""
|
185
|
+
# Default providers if file doesn't exist
|
186
|
+
default_providers = [
|
187
|
+
{
|
188
|
+
"name": "volcanoEngine",
|
189
|
+
"base_url": "https://ark.cn-beijing.volces.com/api/v3",
|
190
|
+
"models": [
|
191
|
+
{
|
192
|
+
"id": "deepseek-v3-241226",
|
193
|
+
"name": "Deepseek V3",
|
194
|
+
"input_price": 1.0,
|
195
|
+
"output_price": 4.0,
|
196
|
+
"is_reasoning": False
|
197
|
+
},
|
198
|
+
{
|
199
|
+
"id": "deepseek-r1-250120",
|
200
|
+
"name": "Deepseek R1",
|
201
|
+
"input_price": 2.0,
|
202
|
+
"output_price": 8.0,
|
203
|
+
"is_reasoning": True
|
204
|
+
}
|
205
|
+
]
|
206
|
+
},
|
207
|
+
{
|
208
|
+
"name": "openrouter",
|
209
|
+
"base_url": "https://openrouter.ai/api/v1",
|
210
|
+
"models": [
|
211
|
+
{
|
212
|
+
"id": "anthropic/claude-3.7-sonnet:thinking",
|
213
|
+
"name": "Claude 3.7 Sonnet Thinking",
|
214
|
+
"input_price": 22.0,
|
215
|
+
"output_price": 111.0,
|
216
|
+
"is_reasoning": True
|
217
|
+
},
|
218
|
+
{
|
219
|
+
"id": "anthropic/claude-3.7-sonnet",
|
220
|
+
"name": "Claude 3.7 Sonnet",
|
221
|
+
"input_price": 22.0,
|
222
|
+
"output_price": 111.0,
|
223
|
+
"is_reasoning": False
|
224
|
+
}
|
225
|
+
]
|
226
|
+
}
|
227
|
+
]
|
228
|
+
|
229
|
+
if not os.path.exists(PROVIDERS_FILE):
|
230
|
+
return default_providers
|
231
|
+
try:
|
232
|
+
with open(PROVIDERS_FILE, 'r',encoding='utf-8') as f:
|
233
|
+
# 根据名字去重,优先保留文件中的提供商配置
|
234
|
+
loaded_providers = json.load(f)
|
235
|
+
providers_map = {provider["name"]: provider for provider in loaded_providers}
|
236
|
+
|
237
|
+
# 只添加名字不重复的默认提供商
|
238
|
+
for default_provider in default_providers:
|
239
|
+
if default_provider["name"] not in providers_map:
|
240
|
+
providers_map[default_provider["name"]] = default_provider
|
241
|
+
|
242
|
+
return list(providers_map.values())
|
243
|
+
except Exception as e:
|
244
|
+
print(f"Error loading providers: {e}")
|
245
|
+
return default_providers
|
246
|
+
|
247
|
+
def save_providers(providers: List[Dict]) -> None:
|
248
|
+
"""Save providers to JSON file"""
|
249
|
+
with open(PROVIDERS_FILE, 'w',encoding='utf-8') as f:
|
250
|
+
# 根据名字去重,然后再统一保存
|
251
|
+
json.dump(providers, f, indent=2,ensure_ascii=False)
|
252
|
+
|
253
|
+
@router.get("/api/providers", response_model=List[ProviderConfig])
|
254
|
+
async def get_providers():
|
255
|
+
"""Get all available providers"""
|
256
|
+
try:
|
257
|
+
providers = load_providers()
|
258
|
+
return providers
|
259
|
+
except Exception as e:
|
260
|
+
raise HTTPException(status_code=500, detail=str(e))
|
261
|
+
|
262
|
+
@router.post("/api/providers", response_model=ProviderConfig)
|
263
|
+
async def add_provider(provider: ProviderConfig):
|
264
|
+
"""Add a new provider"""
|
265
|
+
try:
|
266
|
+
providers = load_providers()
|
267
|
+
|
268
|
+
# Check if provider with same name already exists
|
269
|
+
if any(p["name"] == provider.name for p in providers):
|
270
|
+
raise HTTPException(status_code=400, detail="Provider with this name already exists")
|
271
|
+
|
272
|
+
providers.append(provider.model_dump())
|
273
|
+
save_providers(providers)
|
274
|
+
return provider
|
275
|
+
except Exception as e:
|
276
|
+
raise HTTPException(status_code=500, detail=str(e))
|
277
|
+
|
278
|
+
@router.put("/api/providers/{provider_name}", response_model=ProviderConfig)
|
279
|
+
async def update_provider(provider_name: str, provider: ProviderConfig):
|
280
|
+
"""Update an existing provider"""
|
281
|
+
try:
|
282
|
+
providers = load_providers()
|
283
|
+
updated = False
|
284
|
+
|
285
|
+
for p in providers:
|
286
|
+
if p["name"] == provider_name:
|
287
|
+
p.update(provider.model_dump())
|
288
|
+
updated = True
|
289
|
+
break
|
290
|
+
|
291
|
+
if not updated:
|
292
|
+
raise HTTPException(status_code=404, detail="Provider not found")
|
293
|
+
|
294
|
+
save_providers(providers)
|
295
|
+
return provider
|
296
|
+
except Exception as e:
|
297
|
+
raise HTTPException(status_code=500, detail=str(e))
|
298
|
+
|
299
|
+
@router.delete("/api/providers/{provider_name}")
|
300
|
+
async def delete_provider(provider_name: str):
|
301
|
+
"""Delete a provider by name"""
|
302
|
+
try:
|
303
|
+
providers = load_providers()
|
304
|
+
providers_list = [p for p in providers if p["name"] != provider_name]
|
305
|
+
|
306
|
+
if len(providers) == len(providers_list):
|
307
|
+
raise HTTPException(status_code=404, detail="Provider not found")
|
308
|
+
|
309
|
+
save_providers(providers_list)
|
310
|
+
return {"message": f"Provider {provider_name} deleted successfully"}
|
311
|
+
except Exception as e:
|
312
|
+
raise HTTPException(status_code=500, detail=str(e))
|
@@ -0,0 +1,26 @@
|
|
1
|
+
import os
|
2
|
+
from autocoder.common import git_utils
|
3
|
+
def init_project(project_path: str):
|
4
|
+
os.makedirs(os.path.join(project_path, "actions"), exist_ok=True)
|
5
|
+
os.makedirs(os.path.join(project_path,
|
6
|
+
".auto-coder"), exist_ok=True)
|
7
|
+
|
8
|
+
from autocoder.common.command_templates import create_actions
|
9
|
+
|
10
|
+
source_dir = os.path.abspath(project_path)
|
11
|
+
create_actions(
|
12
|
+
source_dir=source_dir,
|
13
|
+
params={"project_type": "python",
|
14
|
+
"source_dir": source_dir},
|
15
|
+
)
|
16
|
+
git_utils.init(os.path.abspath(project_path))
|
17
|
+
|
18
|
+
with open(os.path.join(source_dir, ".gitignore"), "a") as f:
|
19
|
+
f.write("\n.auto-coder/")
|
20
|
+
f.write("\n/actions/")
|
21
|
+
f.write("\n/output.txt")
|
22
|
+
|
23
|
+
print(
|
24
|
+
f"""Successfully initialized auto-coder project in {os.path.abspath(project_path)}."""
|
25
|
+
)
|
26
|
+
return
|
auto_coder_web/proxy.py
CHANGED
@@ -31,26 +31,31 @@ from loguru import logger
|
|
31
31
|
from auto_coder_web.lang import get_message
|
32
32
|
|
33
33
|
class ProxyServer:
|
34
|
-
def __init__(self, project_path: str, quick: bool = False, product_mode: str = "pro"):
|
34
|
+
def __init__(self, project_path: str, quick: bool = False, product_mode: str = "pro"):
|
35
35
|
self.app = FastAPI()
|
36
|
-
self.setup_middleware()
|
36
|
+
self.setup_middleware()
|
37
37
|
|
38
38
|
self.setup_static_files()
|
39
39
|
self.project_path = project_path
|
40
|
-
|
40
|
+
self.product_mode = product_mode
|
41
|
+
self.auto_coder_runner = None
|
41
42
|
# Check if project is initialized
|
42
43
|
self.is_initialized = self.check_project_initialization()
|
43
|
-
if not self.is_initialized:
|
44
|
+
if not self.is_initialized and product_mode == "pro":
|
44
45
|
logger.warning(get_message("project_not_initialized"))
|
45
46
|
logger.warning(get_message("run_auto_coder_chat"))
|
46
|
-
sys.exit(1)
|
47
|
-
|
48
|
-
self.auto_coder_runner = AutoCoderRunnerWrapper(project_path, product_mode=product_mode)
|
49
|
-
|
47
|
+
sys.exit(1)
|
50
48
|
|
49
|
+
if self.is_initialized:
|
50
|
+
self._initialize()
|
51
|
+
|
51
52
|
self.setup_routes()
|
53
|
+
|
54
|
+
def _initialize(self):
|
55
|
+
self.auto_coder_runner = AutoCoderRunnerWrapper(self.project_path, product_mode=self.product_mode)
|
52
56
|
self.client = httpx.AsyncClient()
|
53
57
|
|
58
|
+
|
54
59
|
def setup_middleware(self):
|
55
60
|
self.app.add_middleware(
|
56
61
|
CORSMiddleware,
|
@@ -127,10 +132,7 @@ class ProxyServer:
|
|
127
132
|
|
128
133
|
@self.app.get("/api/project-path")
|
129
134
|
async def get_project_path():
|
130
|
-
return {"project_path": self.project_path}
|
131
|
-
|
132
|
-
def get_project_runner(project_path: str) -> AutoCoderRunner:
|
133
|
-
return self.projects[project_path]
|
135
|
+
return {"project_path": self.project_path}
|
134
136
|
|
135
137
|
@self.app.get("/api/os")
|
136
138
|
async def get_os():
|
@@ -162,65 +164,33 @@ class ProxyServer:
|
|
162
164
|
"default": field.default
|
163
165
|
})
|
164
166
|
return {"keys": keys}
|
167
|
+
|
168
|
+
|
169
|
+
@self.app.post("/api/initialization-project")
|
170
|
+
async def initialization_project():
|
171
|
+
"""Get the project initialization status"""
|
172
|
+
from auto_coder_web.init_project import init_project
|
173
|
+
init_project(self.project_path)
|
174
|
+
base_persist_dir = os.path.join(self.project_path,".auto-coder", "plugins", "chat-auto-coder")
|
175
|
+
os.makedirs(base_persist_dir, exist_ok=True)
|
176
|
+
self.is_initialized = True
|
177
|
+
self._initialize()
|
178
|
+
return {"success": True}
|
179
|
+
|
180
|
+
@self.app.get("/api/guess/project_type")
|
181
|
+
async def get_project_type():
|
182
|
+
v = self.auto_coder_runner.get_all_extensions_wrapper()
|
183
|
+
return {
|
184
|
+
"project_type":v
|
185
|
+
}
|
186
|
+
|
187
|
+
@self.app.put("/api/congigure/project_type")
|
188
|
+
async def configure_project_type(project_type:str):
|
189
|
+
self.auto_coder_runner.configure_wrapper(f"project_type:{project_type}")
|
190
|
+
return {
|
191
|
+
"succcess": True
|
192
|
+
}
|
165
193
|
|
166
|
-
@self.app.post("/api/revert")
|
167
|
-
async def revert():
|
168
|
-
try:
|
169
|
-
result = self.auto_coder_runner.revert()
|
170
|
-
return result
|
171
|
-
except Exception as e:
|
172
|
-
raise HTTPException(status_code=500, detail=str(e))
|
173
|
-
|
174
|
-
@self.app.get("/api/active-files")
|
175
|
-
async def get_active_files():
|
176
|
-
"""获取当前活动文件列表"""
|
177
|
-
active_files = self.auto_coder_runner.get_active_files()
|
178
|
-
return active_files
|
179
|
-
|
180
|
-
@self.app.post("/api/commit")
|
181
|
-
async def commit():
|
182
|
-
try:
|
183
|
-
result = self.auto_coder_runner.commit()
|
184
|
-
return result
|
185
|
-
except Exception as e:
|
186
|
-
raise HTTPException(status_code=500, detail=str(e))
|
187
|
-
|
188
|
-
@self.app.get("/api/last-yaml")
|
189
|
-
async def get_last_yaml():
|
190
|
-
"""Get information about the last YAML file"""
|
191
|
-
return JSONResponse(content=self.auto_coder_runner.get_last_yaml_info())
|
192
|
-
|
193
|
-
@self.app.get("/api/history/file-content/{file_number}", response_model=FileContentResponse)
|
194
|
-
async def get_file_content(file_number: int):
|
195
|
-
"""获取指定编号文件的完整内容"""
|
196
|
-
auto_coder_dir = "actions"
|
197
|
-
file_name = f"{file_number}_chat_action.yml"
|
198
|
-
file_path = ""
|
199
|
-
|
200
|
-
# 搜索文件
|
201
|
-
for root, _, files in os.walk(auto_coder_dir):
|
202
|
-
if file_name in files:
|
203
|
-
file_path = os.path.join(root, file_name)
|
204
|
-
break
|
205
|
-
|
206
|
-
if not file_path:
|
207
|
-
return FileContentResponse(
|
208
|
-
success=False,
|
209
|
-
message=f"找不到文件: {file_name}"
|
210
|
-
)
|
211
|
-
|
212
|
-
try:
|
213
|
-
with open(file_path, 'r', encoding='utf-8') as f:
|
214
|
-
content = f.read()
|
215
|
-
return FileContentResponse(
|
216
|
-
success=True,
|
217
|
-
content=content
|
218
|
-
)
|
219
|
-
except Exception as e:
|
220
|
-
return FileContentResponse(
|
221
|
-
success=False,
|
222
|
-
message=f"读取文件出错: {str(e)}"
|
223
|
-
)
|
224
194
|
|
225
195
|
@self.app.get("/api/initialization-status")
|
226
196
|
async def get_initialization_status():
|
auto_coder_web/version.py
CHANGED
@@ -1 +1 @@
|
|
1
|
-
__version__ = "0.1.
|
1
|
+
__version__ = "0.1.40"
|
@@ -1,15 +1,15 @@
|
|
1
1
|
{
|
2
2
|
"files": {
|
3
|
-
"main.css": "/static/css/main.
|
4
|
-
"main.js": "/static/js/main.
|
3
|
+
"main.css": "/static/css/main.d58ae48e.css",
|
4
|
+
"main.js": "/static/js/main.8d7d4613.js",
|
5
5
|
"static/js/453.d855a71b.chunk.js": "/static/js/453.d855a71b.chunk.js",
|
6
6
|
"index.html": "/index.html",
|
7
|
-
"main.
|
8
|
-
"main.
|
7
|
+
"main.d58ae48e.css.map": "/static/css/main.d58ae48e.css.map",
|
8
|
+
"main.8d7d4613.js.map": "/static/js/main.8d7d4613.js.map",
|
9
9
|
"453.d855a71b.chunk.js.map": "/static/js/453.d855a71b.chunk.js.map"
|
10
10
|
},
|
11
11
|
"entrypoints": [
|
12
|
-
"static/css/main.
|
13
|
-
"static/js/main.
|
12
|
+
"static/css/main.d58ae48e.css",
|
13
|
+
"static/js/main.8d7d4613.js"
|
14
14
|
]
|
15
15
|
}
|
auto_coder_web/web/index.html
CHANGED
@@ -1 +1 @@
|
|
1
|
-
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="/favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="Web site created using create-react-app"/><link rel="apple-touch-icon" href="/logo192.png"/><link rel="manifest" href="/manifest.json"/><title>React App</title><script defer="defer" src="/static/js/main.
|
1
|
+
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="/favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="Web site created using create-react-app"/><link rel="apple-touch-icon" href="/logo192.png"/><link rel="manifest" href="/manifest.json"/><title>React App</title><script defer="defer" src="/static/js/main.8d7d4613.js"></script><link href="/static/css/main.d58ae48e.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>
|