Skip to content

Commit c46ddcb

Browse files
committed
bug fixes & testing
1 parent 2184910 commit c46ddcb

File tree

7 files changed

+237
-63
lines changed

7 files changed

+237
-63
lines changed

api/openapi.json

+46-52
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@
148148
}
149149
}
150150
},
151-
"/api/v1/provider-endpoints/{provider_id}/models": {
151+
"/api/v1/provider-endpoints/{provider_name}/models": {
152152
"get": {
153153
"tags": [
154154
"CodeGate API",
@@ -159,13 +159,12 @@
159159
"operationId": "v1_list_models_by_provider",
160160
"parameters": [
161161
{
162-
"name": "provider_id",
162+
"name": "provider_name",
163163
"in": "path",
164164
"required": true,
165165
"schema": {
166166
"type": "string",
167-
"format": "uuid",
168-
"title": "Provider Id"
167+
"title": "Provider Name"
169168
}
170169
}
171170
],
@@ -240,14 +239,14 @@
240239
}
241240
}
242241
},
243-
"delete": {
242+
"put": {
244243
"tags": [
245244
"CodeGate API",
246245
"Providers"
247246
],
248-
"summary": "Delete Provider Endpoint",
249-
"description": "Delete a provider endpoint by id.",
250-
"operationId": "v1_delete_provider_endpoint",
247+
"summary": "Update Provider Endpoint",
248+
"description": "Update a provider endpoint by name.",
249+
"operationId": "v1_update_provider_endpoint",
251250
"parameters": [
252251
{
253252
"name": "provider_name",
@@ -259,12 +258,24 @@
259258
}
260259
}
261260
],
261+
"requestBody": {
262+
"required": true,
263+
"content": {
264+
"application/json": {
265+
"schema": {
266+
"$ref": "#/components/schemas/ProviderEndpoint"
267+
}
268+
}
269+
}
270+
},
262271
"responses": {
263272
"200": {
264273
"description": "Successful Response",
265274
"content": {
266275
"application/json": {
267-
"schema": {}
276+
"schema": {
277+
"$ref": "#/components/schemas/ProviderEndpoint"
278+
}
268279
}
269280
}
270281
},
@@ -279,42 +290,34 @@
279290
}
280291
}
281292
}
282-
}
283-
},
284-
"/api/v1/provider-endpoints/{provider_id}/auth-material": {
285-
"put": {
293+
},
294+
"delete": {
286295
"tags": [
287296
"CodeGate API",
288297
"Providers"
289298
],
290-
"summary": "Configure Auth Material",
291-
"description": "Configure auth material for a provider.",
292-
"operationId": "v1_configure_auth_material",
299+
"summary": "Delete Provider Endpoint",
300+
"description": "Delete a provider endpoint by name.",
301+
"operationId": "v1_delete_provider_endpoint",
293302
"parameters": [
294303
{
295-
"name": "provider_id",
304+
"name": "provider_name",
296305
"in": "path",
297306
"required": true,
298307
"schema": {
299308
"type": "string",
300-
"format": "uuid",
301-
"title": "Provider Id"
309+
"title": "Provider Name"
302310
}
303311
}
304312
],
305-
"requestBody": {
306-
"required": true,
307-
"content": {
308-
"application/json": {
309-
"schema": {
310-
"$ref": "#/components/schemas/ConfigureAuthMaterial"
313+
"responses": {
314+
"200": {
315+
"description": "Successful Response",
316+
"content": {
317+
"application/json": {
318+
"schema": {}
311319
}
312320
}
313-
}
314-
},
315-
"responses": {
316-
"204": {
317-
"description": "Successful Response"
318321
},
319322
"422": {
320323
"description": "Validation Error",
@@ -329,24 +332,23 @@
329332
}
330333
}
331334
},
332-
"/api/v1/provider-endpoints/{provider_id}": {
335+
"/api/v1/provider-endpoints/{provider_name}/auth-material": {
333336
"put": {
334337
"tags": [
335338
"CodeGate API",
336339
"Providers"
337340
],
338-
"summary": "Update Provider Endpoint",
339-
"description": "Update a provider endpoint by ID.",
340-
"operationId": "v1_update_provider_endpoint",
341+
"summary": "Configure Auth Material",
342+
"description": "Configure auth material for a provider.",
343+
"operationId": "v1_configure_auth_material",
341344
"parameters": [
342345
{
343-
"name": "provider_id",
346+
"name": "provider_name",
344347
"in": "path",
345348
"required": true,
346349
"schema": {
347350
"type": "string",
348-
"format": "uuid",
349-
"title": "Provider Id"
351+
"title": "Provider Name"
350352
}
351353
}
352354
],
@@ -355,21 +357,14 @@
355357
"content": {
356358
"application/json": {
357359
"schema": {
358-
"$ref": "#/components/schemas/ProviderEndpoint"
360+
"$ref": "#/components/schemas/ConfigureAuthMaterial"
359361
}
360362
}
361363
}
362364
},
363365
"responses": {
364-
"200": {
365-
"description": "Successful Response",
366-
"content": {
367-
"application/json": {
368-
"schema": {
369-
"$ref": "#/components/schemas/ProviderEndpoint"
370-
}
371-
}
372-
}
366+
"204": {
367+
"description": "Successful Response"
373368
},
374369
"422": {
375370
"description": "Validation Error",
@@ -391,24 +386,23 @@
391386
"Workspaces"
392387
],
393388
"summary": "List Workspaces",
394-
"description": "List all workspaces.\n\nArgs:\n provider_id (Optional[UUID]): Filter workspaces by provider ID. If provided,\n will return workspaces where models from the specified provider (e.g., OpenAI,\n Anthropic) have been used in workspace muxing rules. Note that you must\n refer to a provider by ID, not by name.\n\nReturns:\n ListWorkspacesResponse: A response object containing the list of workspaces.",
389+
"description": "List all workspaces.\n\nArgs:\n provider_name (Optional[str]): Filter workspaces by provider name. If provided,\n will return workspaces where models from the specified provider (e.g., OpenAI,\n Anthropic) have been used in workspace muxing rules.\n\nReturns:\n ListWorkspacesResponse: A response object containing the list of workspaces.",
395390
"operationId": "v1_list_workspaces",
396391
"parameters": [
397392
{
398-
"name": "provider_id",
393+
"name": "provider_name",
399394
"in": "query",
400395
"required": false,
401396
"schema": {
402397
"anyOf": [
403398
{
404-
"type": "string",
405-
"format": "uuid"
399+
"type": "string"
406400
},
407401
{
408402
"type": "null"
409403
}
410404
],
411-
"title": "Provider Id"
405+
"title": "Provider Name"
412406
}
413407
}
414408
],

migrations/versions/2025_03_05_2126-e4c05d7591a8_add_installation_table.py

-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
from typing import Sequence, Union
1010

1111
from alembic import op
12-
import sqlalchemy as sa
13-
1412

1513
# revision identifiers, used by Alembic.
1614
revision: str = "e4c05d7591a8"

src/codegate/api/v1.py

+12-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,14 @@ async def _add_provider_id_to_mux_rule(
5151
f'Provider "{mux_rule.provider_name}" of type "{mux_rule.provider_type}" not found' # noqa: E501
5252
)
5353

54-
return mux_models.MuxRuleWithProviderId(**mux_rule.model_dump(), provider_id=provider.id)
54+
return mux_models.MuxRuleWithProviderId(
55+
matcher=mux_rule.matcher,
56+
matcher_type=mux_rule.matcher_type,
57+
model=mux_rule.model,
58+
provider_type=provider.provider_type,
59+
provider_id=provider.id,
60+
provider_name=provider.name,
61+
)
5562

5663

5764
class FilterByNameParams(BaseModel):
@@ -272,6 +279,8 @@ async def list_workspaces(
272279
wslist = await wscrud.get_workspaces()
273280
resp = v1_models.ListWorkspacesResponse.from_db_workspaces_with_sessioninfo(wslist)
274281
return resp
282+
except provendcrud.ProviderNotFoundError:
283+
return v1_models.ListWorkspacesResponse(workspaces=[])
275284
except Exception as e:
276285
raise HTTPException(status_code=500, detail=str(e))
277286

@@ -332,7 +341,8 @@ async def create_workspace(
332341
)
333342
except crud.WorkspaceCrudError as e:
334343
raise HTTPException(status_code=400, detail=str(e))
335-
except Exception:
344+
except Exception as e:
345+
logger.debug(f"Error creating workspace: {e}")
336346
raise HTTPException(status_code=500, detail="Internal server error")
337347

338348
return v1_models.FullWorkspace(

src/codegate/cli.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
from codegate.config import Config, ConfigurationError
1717
from codegate.db.connection import (
1818
init_db_sync,
19-
init_session_if_not_exists,
2019
init_instance,
20+
init_session_if_not_exists,
2121
)
2222
from codegate.pipeline.factory import PipelineFactory
2323
from codegate.pipeline.sensitive_data.manager import SensitiveDataManager

src/codegate/db/connection.py

+32-3
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,16 @@ async def soft_delete_workspace(self, workspace: WorkspaceRow) -> Optional[Works
414414
return deleted_workspace
415415

416416
async def hard_delete_workspace(self, workspace: WorkspaceRow) -> Optional[WorkspaceRow]:
417+
# First delete associated muxes
418+
sql_delete_muxes = text(
419+
"""
420+
DELETE FROM muxes
421+
WHERE workspace_id = :id
422+
"""
423+
)
424+
await self._execute_with_no_return(sql_delete_muxes, {"id": workspace.id})
425+
426+
# Then delete the workspace
417427
sql = text(
418428
"""
419429
DELETE FROM workspaces
@@ -472,15 +482,34 @@ async def delete_provider_endpoint(
472482
self,
473483
provider: ProviderEndpoint,
474484
) -> Optional[ProviderEndpoint]:
475-
sql = text(
485+
# Delete from provider_models
486+
sql_delete_provider_models = text(
487+
"""
488+
DELETE FROM provider_models
489+
WHERE provider_endpoint_id = :id
490+
"""
491+
)
492+
await self._execute_with_no_return(sql_delete_provider_models, {"id": provider.id})
493+
494+
# Delete from muxes
495+
sql_delete_muxes = text(
496+
"""
497+
DELETE FROM muxes
498+
WHERE provider_endpoint_id = :id
499+
"""
500+
)
501+
await self._execute_with_no_return(sql_delete_muxes, {"id": provider.id})
502+
503+
# Delete from provider_endpoints
504+
sql_delete_provider_endpoints = text(
476505
"""
477506
DELETE FROM provider_endpoints
478507
WHERE id = :id
479508
RETURNING *
480509
"""
481510
)
482511
deleted_provider = await self._execute_update_pydantic_model(
483-
provider, sql, should_raise=True
512+
provider, sql_delete_provider_endpoints, should_raise=True
484513
)
485514
return deleted_provider
486515

@@ -621,7 +650,7 @@ async def init_instance(self) -> None:
621650
await self._execute_with_no_return(sql, instance.model_dump())
622651
except IntegrityError as e:
623652
logger.debug(f"Exception type: {type(e)}")
624-
raise AlreadyExistsError(f"Instance already initialized.")
653+
raise AlreadyExistsError("Instance already initialized.")
625654

626655

627656
class DbReader(DbCodeGate):

src/codegate/workspaces/crud.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -341,9 +341,9 @@ async def set_muxes(
341341
# Add the new muxes
342342
priority = 0
343343

344-
muxes_with_routes: List[
345-
Tuple[mux_models.MuxRuleWithProviderId, rulematcher.ModelRoute]
346-
] = []
344+
muxes_with_routes: List[Tuple[mux_models.MuxRuleWithProviderId, rulematcher.ModelRoute]] = (
345+
[]
346+
)
347347

348348
# Verify all models are valid
349349
for mux in muxes:

0 commit comments

Comments
 (0)