Skip to content

Commit a180108

Browse files
committed
Initial CRUD API for workspaces
This adds a simple and unimplemented REST API for workspaces. Workspaces will be the base for all other resources in terms of REST resource mapping, so these go first. These are initially left entirely unimplemented as #600 needs to merge Signed-off-by: Juan Antonio Osorio <[email protected]>
1 parent 1eef816 commit a180108

File tree

6 files changed

+65
-2
lines changed

6 files changed

+65
-2
lines changed

src/codegate/api/__init__.py

Whitespace-only changes.

src/codegate/api/v1.py

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
from fastapi import APIRouter
2+
from fastapi.routing import APIRoute
3+
4+
from codegate.api import v1_models
5+
6+
v1 = APIRouter()
7+
8+
9+
def uniq_name(route: APIRoute):
10+
return f"v1_{route.name}"
11+
12+
13+
@v1.get("/workspaces", tags=["Workspaces"], generate_unique_id_function=uniq_name)
14+
async def list_workspaces() -> v1_models.ListWorkspacesResponse:
15+
"""List all workspaces."""
16+
raise NotImplementedError
17+
18+
@v1.get("/workspaces/active", tags=["Workspaces"], generate_unique_id_function=uniq_name)
19+
async def list_active_workspaces() -> v1_models.ListActiveWorkspacesResponse:
20+
"""List all active workspaces.
21+
22+
In it's current form, this function will only return one workspace. That is,
23+
the globally active workspace."""
24+
raise NotImplementedError
25+
26+
@v1.post("/workspaces", tags=["Workspaces"], generate_unique_id_function=uniq_name, status_code=201)
27+
async def create_workspace(request: v1_models.CreateWorkspaceRequest):
28+
"""Create a new workspace."""
29+
raise NotImplementedError
30+
31+
@v1.get("/workspaces/{workspace_name}", tags=["Workspaces"], generate_unique_id_function=uniq_name)
32+
async def get_workspace(workspace_name: str) -> v1_models.Workspace:
33+
"""Get a workspace by name."""
34+
raise NotImplementedError
35+
36+
@v1.delete("/workspaces/{workspace_name}", tags=["Workspaces"],
37+
generate_unique_id_function=uniq_name, status_code=204)
38+
async def delete_workspace(workspace_name: str):
39+
"""Delete a workspace by name."""
40+
raise NotImplementedError

src/codegate/api/v1_models.py

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from typing import Any
2+
3+
import pydantic
4+
5+
6+
class Workspace(pydantic.BaseModel):
7+
name: str
8+
9+
class ActiveWorkspace(Workspace):
10+
# TODO: use a more specific type for last_updated
11+
last_updated: Any
12+
13+
class ListWorkspacesResponse(pydantic.BaseModel):
14+
workspaces: list[Workspace]
15+
16+
class ListActiveWorkspacesResponse(pydantic.BaseModel):
17+
workspaces: list[ActiveWorkspace]
18+
19+
class CreateWorkspaceRequest(pydantic.BaseModel):
20+
name: str

src/codegate/pipeline/extract_snippets/extract_snippets.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ def extract_snippets(message: str) -> List[CodeSnippet]:
127127
lang_map = {
128128
"typescript": "javascript"
129129
}
130-
lang = lang_map.get(lang, lang)
130+
lang = lang_map.get(lang, lang)
131131
snippets.append(CodeSnippet(filepath=filename, code=content, language=lang))
132132

133133
return snippets

src/codegate/providers/ollama/completion_handler.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import json
21
from typing import AsyncIterator, Optional, Union
32

43
import structlog

src/codegate/server.py

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from starlette.middleware.errors import ServerErrorMiddleware
88

99
from codegate import __description__, __version__
10+
from codegate.api.v1 import v1
1011
from codegate.dashboard.dashboard import dashboard_router
1112
from codegate.pipeline.factory import PipelineFactory
1213
from codegate.providers.anthropic.provider import AnthropicProvider
@@ -97,4 +98,7 @@ async def health_check():
9798
app.include_router(system_router)
9899
app.include_router(dashboard_router)
99100

101+
# CodeGate API
102+
app.include_router(v1, prefix="/api/v1", tags=["CodeGate API"])
103+
100104
return app

0 commit comments

Comments
 (0)