auto-coder-web 0.1.98__py3-none-any.whl → 0.1.100__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/file_manager.py +1 -1
- auto_coder_web/proxy.py +2 -1
- auto_coder_web/routers/file_command_router.py +315 -0
- auto_coder_web/version.py +1 -1
- auto_coder_web/web/assets/main-DgQa03WG.css +32 -0
- auto_coder_web/web/assets/main.js +349 -349
- auto_coder_web/web/index.html +1 -1
- {auto_coder_web-0.1.98.dist-info → auto_coder_web-0.1.100.dist-info}/METADATA +2 -2
- {auto_coder_web-0.1.98.dist-info → auto_coder_web-0.1.100.dist-info}/RECORD +12 -11
- auto_coder_web/web/assets/main-BJLO9M6L.css +0 -32
- {auto_coder_web-0.1.98.dist-info → auto_coder_web-0.1.100.dist-info}/WHEEL +0 -0
- {auto_coder_web-0.1.98.dist-info → auto_coder_web-0.1.100.dist-info}/entry_points.txt +0 -0
- {auto_coder_web-0.1.98.dist-info → auto_coder_web-0.1.100.dist-info}/top_level.txt +0 -0
auto_coder_web/file_manager.py
CHANGED
@@ -147,7 +147,7 @@ async def get_directory_tree_async(root_path: str, path: str = None, lazy: bool
|
|
147
147
|
|
148
148
|
def should_ignore(name: str) -> bool:
|
149
149
|
"""Check if a file or directory should be ignored"""
|
150
|
-
allowed_hidden_files = {'.autocoderrules', '.gitignore', '.autocoderignore'}
|
150
|
+
allowed_hidden_files = {'.autocoderrules', '.gitignore', '.autocoderignore',".autocodercommands"}
|
151
151
|
# Ignore hidden files/directories (starting with '.'), unless explicitly allowed
|
152
152
|
## and name != ".auto-coder": # Original comment kept for context if needed
|
153
153
|
if name.startswith('.') and name not in allowed_hidden_files:
|
auto_coder_web/proxy.py
CHANGED
@@ -19,7 +19,7 @@ import sys
|
|
19
19
|
from auto_coder_web.terminal import terminal_manager
|
20
20
|
from autocoder.common import AutoCoderArgs
|
21
21
|
from auto_coder_web.auto_coder_runner_wrapper import AutoCoderRunnerWrapper
|
22
|
-
from auto_coder_web.routers import todo_router, settings_router, auto_router, commit_router, chat_router, coding_router, index_router, config_router, upload_router, rag_router, editable_preview_router, mcp_router, direct_chat_router, rules_router, chat_panels_router, code_editor_tabs_router
|
22
|
+
from auto_coder_web.routers import todo_router, settings_router, auto_router, commit_router, chat_router, coding_router, index_router, config_router, upload_router, rag_router, editable_preview_router, mcp_router, direct_chat_router, rules_router, chat_panels_router, code_editor_tabs_router, file_command_router
|
23
23
|
from auto_coder_web.expert_routers import history_router
|
24
24
|
from auto_coder_web.common_router import completions_router, file_router, auto_coder_conf_router, chat_list_router, file_group_router, model_router, compiler_router
|
25
25
|
from auto_coder_web.common_router import active_context_router
|
@@ -112,6 +112,7 @@ class ProxyServer:
|
|
112
112
|
self.app.include_router(rules_router.router)
|
113
113
|
self.app.include_router(chat_panels_router.router)
|
114
114
|
self.app.include_router(code_editor_tabs_router.router)
|
115
|
+
self.app.include_router(file_command_router.router)
|
115
116
|
|
116
117
|
@self.app.on_event("shutdown")
|
117
118
|
async def shutdown_event():
|
@@ -0,0 +1,315 @@
|
|
1
|
+
"""
|
2
|
+
Document Router for managing and analyzing document files.
|
3
|
+
|
4
|
+
This router provides endpoints for listing documents and reading document variables
|
5
|
+
using the CommandFileManager from the auto-coder project.
|
6
|
+
"""
|
7
|
+
|
8
|
+
import os
|
9
|
+
import json
|
10
|
+
import aiofiles
|
11
|
+
from fastapi import APIRouter, HTTPException, Request, Depends
|
12
|
+
from pydantic import BaseModel
|
13
|
+
from pathlib import Path
|
14
|
+
from typing import List, Dict, Optional, Set, Any
|
15
|
+
from jinja2 import Template, Environment, meta
|
16
|
+
|
17
|
+
# Import the CommandFileManager from the auto-coder project
|
18
|
+
from autocoder.common.command_file_manager import CommandManager, JinjaVariable
|
19
|
+
|
20
|
+
router = APIRouter()
|
21
|
+
|
22
|
+
async def get_project_path(request: Request) -> str:
|
23
|
+
"""Get the project path from the FastAPI request context."""
|
24
|
+
return request.app.state.project_path
|
25
|
+
|
26
|
+
async def get_documents_path(project_path: str) -> Path:
|
27
|
+
"""Get the documents directory path."""
|
28
|
+
# Default to .autocodercommands directory in the project
|
29
|
+
return Path(project_path) / ".autocodercommands"
|
30
|
+
|
31
|
+
class DocumentFile(BaseModel):
|
32
|
+
"""Model for document file information."""
|
33
|
+
file_name: str
|
34
|
+
file_path: str
|
35
|
+
|
36
|
+
class DocumentVariable(BaseModel):
|
37
|
+
"""Model for document variable information."""
|
38
|
+
name: str
|
39
|
+
default_value: Optional[str] = None
|
40
|
+
description: Optional[str] = None
|
41
|
+
|
42
|
+
class DocumentAnalysis(BaseModel):
|
43
|
+
"""Model for document analysis information."""
|
44
|
+
file_name: str
|
45
|
+
file_path: str
|
46
|
+
variables: List[DocumentVariable]
|
47
|
+
|
48
|
+
class ListDocumentsResponse(BaseModel):
|
49
|
+
"""Response model for listing documents."""
|
50
|
+
success: bool
|
51
|
+
documents: Optional[List[DocumentFile]] = None
|
52
|
+
errors: Optional[List[str]] = None
|
53
|
+
|
54
|
+
class ReadDocumentResponse(BaseModel):
|
55
|
+
"""Response model for reading a document."""
|
56
|
+
success: bool
|
57
|
+
document: Optional[DocumentFile] = None
|
58
|
+
content: Optional[str] = None
|
59
|
+
errors: Optional[List[str]] = None
|
60
|
+
|
61
|
+
class AnalyzeDocumentResponse(BaseModel):
|
62
|
+
"""Response model for analyzing a document."""
|
63
|
+
success: bool
|
64
|
+
analysis: Optional[DocumentAnalysis] = None
|
65
|
+
errors: Optional[List[str]] = None
|
66
|
+
|
67
|
+
class AllVariablesResponse(BaseModel):
|
68
|
+
"""Response model for getting all variables."""
|
69
|
+
success: bool
|
70
|
+
variables: Optional[Dict[str, List[str]]] = None
|
71
|
+
errors: Optional[List[str]] = None
|
72
|
+
|
73
|
+
class RenderTemplateRequest(BaseModel):
|
74
|
+
"""Request model for rendering a template."""
|
75
|
+
file_name: str
|
76
|
+
variables: Dict[str, str]
|
77
|
+
|
78
|
+
class RenderTemplateResponse(BaseModel):
|
79
|
+
"""Response model for rendering a template."""
|
80
|
+
success: bool
|
81
|
+
rendered_content: Optional[str] = None
|
82
|
+
errors: Optional[List[str]] = None
|
83
|
+
|
84
|
+
@router.get("/api/file_commands", response_model=ListDocumentsResponse)
|
85
|
+
async def list_documents(request: Request, recursive: bool = False):
|
86
|
+
"""
|
87
|
+
List all document files in the documents directory.
|
88
|
+
|
89
|
+
Args:
|
90
|
+
recursive: Whether to search recursively.
|
91
|
+
|
92
|
+
Returns:
|
93
|
+
A ListDocumentsResponse object.
|
94
|
+
"""
|
95
|
+
try:
|
96
|
+
project_path = await get_project_path(request)
|
97
|
+
documents_path = await get_documents_path(project_path)
|
98
|
+
|
99
|
+
# Initialize the CommandManager
|
100
|
+
manager = CommandManager(str(documents_path))
|
101
|
+
|
102
|
+
# List command files
|
103
|
+
result = manager.list_command_files(recursive=recursive)
|
104
|
+
|
105
|
+
if not result.success:
|
106
|
+
return ListDocumentsResponse(
|
107
|
+
success=False,
|
108
|
+
errors=result.errors
|
109
|
+
)
|
110
|
+
|
111
|
+
# Convert to DocumentFile objects
|
112
|
+
documents = []
|
113
|
+
for file_path in result.command_files:
|
114
|
+
file_name = os.path.basename(file_path)
|
115
|
+
documents.append(DocumentFile(
|
116
|
+
file_name=file_name,
|
117
|
+
file_path=file_path
|
118
|
+
))
|
119
|
+
|
120
|
+
return ListDocumentsResponse(
|
121
|
+
success=True,
|
122
|
+
documents=documents
|
123
|
+
)
|
124
|
+
except Exception as e:
|
125
|
+
return ListDocumentsResponse(
|
126
|
+
success=False,
|
127
|
+
errors=[f"Error listing documents: {str(e)}"]
|
128
|
+
)
|
129
|
+
|
130
|
+
@router.get("/api/file_commands/{file_name}", response_model=ReadDocumentResponse)
|
131
|
+
async def read_document(file_name: str, request: Request):
|
132
|
+
"""
|
133
|
+
Read a document file.
|
134
|
+
|
135
|
+
Args:
|
136
|
+
file_name: The name of the file to read.
|
137
|
+
|
138
|
+
Returns:
|
139
|
+
A ReadDocumentResponse object.
|
140
|
+
"""
|
141
|
+
try:
|
142
|
+
project_path = await get_project_path(request)
|
143
|
+
documents_path = await get_documents_path(project_path)
|
144
|
+
|
145
|
+
# Initialize the CommandManager
|
146
|
+
manager = CommandManager(str(documents_path))
|
147
|
+
|
148
|
+
# Read command file
|
149
|
+
command_file = manager.read_command_file(file_name)
|
150
|
+
|
151
|
+
if not command_file:
|
152
|
+
return ReadDocumentResponse(
|
153
|
+
success=False,
|
154
|
+
errors=[f"Document '{file_name}' not found."]
|
155
|
+
)
|
156
|
+
|
157
|
+
return ReadDocumentResponse(
|
158
|
+
success=True,
|
159
|
+
document=DocumentFile(
|
160
|
+
file_name=command_file.file_name,
|
161
|
+
file_path=command_file.file_path
|
162
|
+
),
|
163
|
+
content=command_file.content
|
164
|
+
)
|
165
|
+
except Exception as e:
|
166
|
+
return ReadDocumentResponse(
|
167
|
+
success=False,
|
168
|
+
errors=[f"Error reading document: {str(e)}"]
|
169
|
+
)
|
170
|
+
|
171
|
+
@router.get("/api/file_commands/{file_name}/variables", response_model=AnalyzeDocumentResponse)
|
172
|
+
async def analyze_document(file_name: str, request: Request):
|
173
|
+
"""
|
174
|
+
Analyze a document file to extract variables.
|
175
|
+
|
176
|
+
Args:
|
177
|
+
file_name: The name of the file to analyze.
|
178
|
+
|
179
|
+
Returns:
|
180
|
+
An AnalyzeDocumentResponse object.
|
181
|
+
"""
|
182
|
+
try:
|
183
|
+
project_path = await get_project_path(request)
|
184
|
+
documents_path = await get_documents_path(project_path)
|
185
|
+
|
186
|
+
# Initialize the CommandManager
|
187
|
+
manager = CommandManager(str(documents_path))
|
188
|
+
|
189
|
+
# Analyze command file
|
190
|
+
analysis = manager.analyze_command_file(file_name)
|
191
|
+
|
192
|
+
if not analysis:
|
193
|
+
return AnalyzeDocumentResponse(
|
194
|
+
success=False,
|
195
|
+
errors=[f"Document '{file_name}' not found or could not be analyzed."]
|
196
|
+
)
|
197
|
+
|
198
|
+
# Convert to DocumentVariable objects
|
199
|
+
variables = []
|
200
|
+
for var in analysis.variables:
|
201
|
+
variables.append(DocumentVariable(
|
202
|
+
name=var.name,
|
203
|
+
default_value=var.default_value,
|
204
|
+
description=var.description
|
205
|
+
))
|
206
|
+
|
207
|
+
return AnalyzeDocumentResponse(
|
208
|
+
success=True,
|
209
|
+
analysis=DocumentAnalysis(
|
210
|
+
file_name=analysis.file_name,
|
211
|
+
file_path=analysis.file_path,
|
212
|
+
variables=variables
|
213
|
+
)
|
214
|
+
)
|
215
|
+
except Exception as e:
|
216
|
+
return AnalyzeDocumentResponse(
|
217
|
+
success=False,
|
218
|
+
errors=[f"Error analyzing document: {str(e)}"]
|
219
|
+
)
|
220
|
+
|
221
|
+
@router.get("/api/file_commands/variables/all", response_model=AllVariablesResponse)
|
222
|
+
async def get_all_variables(request: Request, recursive: bool = False):
|
223
|
+
"""
|
224
|
+
Get all variables from all document files.
|
225
|
+
|
226
|
+
Args:
|
227
|
+
recursive: Whether to search recursively.
|
228
|
+
|
229
|
+
Returns:
|
230
|
+
An AllVariablesResponse object.
|
231
|
+
"""
|
232
|
+
try:
|
233
|
+
project_path = await get_project_path(request)
|
234
|
+
documents_path = await get_documents_path(project_path)
|
235
|
+
|
236
|
+
# Initialize the CommandManager
|
237
|
+
manager = CommandManager(str(documents_path))
|
238
|
+
|
239
|
+
# Get all variables
|
240
|
+
variables = manager.get_all_variables(recursive=recursive)
|
241
|
+
|
242
|
+
return AllVariablesResponse(
|
243
|
+
success=True,
|
244
|
+
variables=variables
|
245
|
+
)
|
246
|
+
except Exception as e:
|
247
|
+
return AllVariablesResponse(
|
248
|
+
success=False,
|
249
|
+
errors=[f"Error getting all variables: {str(e)}"]
|
250
|
+
)
|
251
|
+
|
252
|
+
@router.get("/api/file_commands/path")
|
253
|
+
async def get_documents_directory(request: Request):
|
254
|
+
"""
|
255
|
+
Get the documents directory path.
|
256
|
+
|
257
|
+
Returns:
|
258
|
+
The documents directory path.
|
259
|
+
"""
|
260
|
+
try:
|
261
|
+
project_path = await get_project_path(request)
|
262
|
+
documents_path = await get_documents_path(project_path)
|
263
|
+
|
264
|
+
return {
|
265
|
+
"success": True,
|
266
|
+
"path": str(documents_path)
|
267
|
+
}
|
268
|
+
except Exception as e:
|
269
|
+
return {
|
270
|
+
"success": False,
|
271
|
+
"errors": [f"Error getting documents directory: {str(e)}"]
|
272
|
+
}
|
273
|
+
|
274
|
+
@router.post("/api/file_commands/render", response_model=RenderTemplateResponse)
|
275
|
+
async def render_template(request: RenderTemplateRequest, req: Request):
|
276
|
+
"""
|
277
|
+
Render a template with the provided variables.
|
278
|
+
|
279
|
+
Args:
|
280
|
+
request: The request containing the file name and variables.
|
281
|
+
|
282
|
+
Returns:
|
283
|
+
A RenderTemplateResponse object containing the rendered content.
|
284
|
+
"""
|
285
|
+
try:
|
286
|
+
project_path = await get_project_path(req)
|
287
|
+
documents_path = await get_documents_path(project_path)
|
288
|
+
|
289
|
+
# Initialize the CommandManager
|
290
|
+
manager = CommandManager(str(documents_path))
|
291
|
+
|
292
|
+
# Read command file
|
293
|
+
command_file = manager.read_command_file(request.file_name)
|
294
|
+
|
295
|
+
if not command_file:
|
296
|
+
return RenderTemplateResponse(
|
297
|
+
success=False,
|
298
|
+
errors=[f"Document '{request.file_name}' not found."]
|
299
|
+
)
|
300
|
+
|
301
|
+
# Create Jinja2 template
|
302
|
+
template = Template(command_file.content)
|
303
|
+
|
304
|
+
# Render template with provided variables
|
305
|
+
rendered_content = template.render(**request.variables)
|
306
|
+
|
307
|
+
return RenderTemplateResponse(
|
308
|
+
success=True,
|
309
|
+
rendered_content=rendered_content
|
310
|
+
)
|
311
|
+
except Exception as e:
|
312
|
+
return RenderTemplateResponse(
|
313
|
+
success=False,
|
314
|
+
errors=[f"Error rendering template: {str(e)}"]
|
315
|
+
)
|
auto_coder_web/version.py
CHANGED
@@ -1 +1 @@
|
|
1
|
-
__version__ = "0.1.
|
1
|
+
__version__ = "0.1.100"
|