Added locations of backend and frontend implementations of the APIs

This commit is contained in:
Zvonimir Sabljic
2024-12-27 13:13:45 +03:00
parent 344a6c19b4
commit 732b2119ac
3 changed files with 44 additions and 5 deletions

View File

@@ -39,6 +39,7 @@ class SaveFileOptions(BaseModel):
class SaveFileStep(BaseModel):
type: Literal[StepType.SAVE_FILE] = StepType.SAVE_FILE
save_file: SaveFileOptions
related_api_endpoints: list[str] = Field(description="API endpoints that are implemented in this file", default=[])
class CommandStep(BaseModel):
@@ -216,6 +217,7 @@ class Developer(RelevantFilesMixin, BaseAgent):
await self.send_message("Thinking about how to implement this task ...")
await self.ui.start_breakdown_stream()
related_api_endpoints = current_task.get("related_api_endpoints", [])
llm = self.get_llm(TASK_BREAKDOWN_AGENT_NAME, stream_output=True)
convo = AgentConvo(self).template(
"breakdown",
@@ -223,7 +225,7 @@ class Developer(RelevantFilesMixin, BaseAgent):
iteration=None,
current_task_index=current_task_index,
docs=self.current_state.docs,
related_api_endpoints=current_task.get("related_api_endpoints", []),
related_api_endpoints=related_api_endpoints,
)
response: str = await llm(convo)

View File

@@ -82,10 +82,21 @@ class Orchestrator(BaseAgent, GitMixin):
should_update_knowledge_base = any(
"src/pages/" in single_agent.step.get("save_file", {}).get("path", "")
or "src/api/" in single_agent.step.get("save_file", {}).get("path", "")
or len(single_agent.step.get("related_api_endpoints")) > 0
for single_agent in agent
)
if should_update_knowledge_base:
files_with_implemented_apis = [
{
"path": single_agent.step.get("save_file", {}).get("path", None),
"related_api_endpoints": single_agent.step.get("related_api_endpoints"),
"line": 0, # TODO implement getting the line number here
}
for single_agent in agent
if len(single_agent.step.get("related_api_endpoints")) > 0
]
await self.state_manager.update_apis(files_with_implemented_apis)
await self.state_manager.update_implemented_pages_and_apis()
else:

View File

@@ -686,25 +686,51 @@ class StateManager:
endpoint = lines[i + 1].split("Endpoint:")[1]
request = lines[i + 2].split("Request:")[1]
response = lines[i + 3].split("Response:")[1]
backend = (
next(
(
api
for api in self.current_state.knowledge_base.get("apis", [])
if api["endpoint"] == endpoint.strip()
),
{},
)
.get("locations", {})
.get("backend", None)
)
apis.append(
{
"description": description.strip(),
"endpoint": endpoint.strip(),
"request": request.strip(),
"response": response.strip(),
"file": file.path,
"line": i - 1,
"status": "mocked",
"locations": {
"frontend": {
"path": file.path,
"line": i - 1,
},
"backend": backend,
},
"status": "implemented" if backend is not None else "mocked",
}
)
return apis
async def update_apis(self):
async def update_apis(self, files_with_implemented_apis: list[dict] = []):
"""
Update the list of APIs.
"""
apis = self.get_apis()
for file in files_with_implemented_apis:
for endpoint in file["related_api_endpoints"]:
api = next((api for api in apis if (endpoint in api["endpoint"])), None)
if api is not None:
api["status"] = "implemented"
api["locations"]["backend"] = {
"path": file["path"],
"line": file["line"],
}
self.next_state.knowledge_base["apis"] = apis
self.next_state.flag_knowledge_base_as_modified()
await self.ui.knowledge_base_update(self.next_state.knowledge_base)