fix(review): CLI field names, Pydantic validation, exception chaining
This commit is contained in:
parent
3efdaafb5f
commit
abe2a66436
|
|
@ -1141,15 +1141,15 @@ def kb_list_documents(
|
||||||
table.add_column("Filename")
|
table.add_column("Filename")
|
||||||
table.add_column("Source ID")
|
table.add_column("Source ID")
|
||||||
table.add_column("Department ID")
|
table.add_column("Department ID")
|
||||||
table.add_column("Size")
|
table.add_column("Chunks")
|
||||||
table.add_column("Created")
|
table.add_column("Created")
|
||||||
for d in documents:
|
for d in documents:
|
||||||
table.add_row(
|
table.add_row(
|
||||||
str(d.get("id", "")),
|
str(d.get("document_id", "")),
|
||||||
str(d.get("filename", "")),
|
str(d.get("filename", "")),
|
||||||
str(d.get("source_id", "")),
|
str(d.get("source_id", "")),
|
||||||
str(d.get("department_id", "")),
|
str(d.get("department_id", "")),
|
||||||
str(d.get("size", "")),
|
str(d.get("chunks", "")),
|
||||||
str(d.get("created_at", "")),
|
str(d.get("created_at", "")),
|
||||||
)
|
)
|
||||||
console.print(table)
|
console.print(table)
|
||||||
|
|
|
||||||
|
|
@ -265,14 +265,14 @@ class SkillService:
|
||||||
tool_registry=tool_registry,
|
tool_registry=tool_registry,
|
||||||
)
|
)
|
||||||
loader.load_from_file(file_path)
|
loader.load_from_file(file_path)
|
||||||
except Exception:
|
except Exception as exc:
|
||||||
# Remove the invalid YAML file and re-raise as ValueError
|
# Remove the invalid YAML file and re-raise as ValueError
|
||||||
# so the route layer maps it to 400.
|
# so the route layer maps it to 400.
|
||||||
try:
|
try:
|
||||||
os.remove(file_path)
|
os.remove(file_path)
|
||||||
except OSError:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
raise ValueError("Skill YAML written but registration failed")
|
raise ValueError(f"Skill YAML written but registration failed: {exc}") from exc
|
||||||
|
|
||||||
return {"name": skill_name, "path": file_path}
|
return {"name": skill_name, "path": file_path}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,11 +18,11 @@ from __future__ import annotations
|
||||||
import logging
|
import logging
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Any
|
from typing import Any, Literal
|
||||||
|
|
||||||
from fastapi import APIRouter, Depends, HTTPException, Request
|
from fastapi import APIRouter, Depends, HTTPException, Request
|
||||||
from fastapi.responses import PlainTextResponse
|
from fastapi.responses import PlainTextResponse
|
||||||
from pydantic import BaseModel, ConfigDict
|
from pydantic import BaseModel, ConfigDict, EmailStr, Field
|
||||||
|
|
||||||
from agentkit.server.admin.department_service import get_department_service
|
from agentkit.server.admin.department_service import get_department_service
|
||||||
from agentkit.server.admin.kb_service import get_kb_service
|
from agentkit.server.admin.kb_service import get_kb_service
|
||||||
|
|
@ -348,9 +348,9 @@ class UserCreateRequest(BaseModel):
|
||||||
model_config = ConfigDict(extra="forbid")
|
model_config = ConfigDict(extra="forbid")
|
||||||
|
|
||||||
username: str
|
username: str
|
||||||
email: str
|
email: EmailStr
|
||||||
password: str
|
password: str = Field(min_length=8)
|
||||||
role: str = "member"
|
role: Literal["member", "operator", "admin"] = "member"
|
||||||
department_ids: list[str] | None = None
|
department_ids: list[str] | None = None
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -359,7 +359,7 @@ class UserUpdateRequest(BaseModel):
|
||||||
|
|
||||||
model_config = ConfigDict(extra="forbid")
|
model_config = ConfigDict(extra="forbid")
|
||||||
|
|
||||||
role: str | None = None
|
role: Literal["member", "operator", "admin"] | None = None
|
||||||
is_active: bool | None = None
|
is_active: bool | None = None
|
||||||
is_terminal_authorized: bool | None = None
|
is_terminal_authorized: bool | None = None
|
||||||
is_server_terminal_authorized: bool | None = None
|
is_server_terminal_authorized: bool | None = None
|
||||||
|
|
@ -370,7 +370,7 @@ class ResetPasswordRequest(BaseModel):
|
||||||
|
|
||||||
model_config = ConfigDict(extra="forbid")
|
model_config = ConfigDict(extra="forbid")
|
||||||
|
|
||||||
new_password: str
|
new_password: str = Field(min_length=8)
|
||||||
|
|
||||||
|
|
||||||
@admin_router.post("/users", status_code=201)
|
@admin_router.post("/users", status_code=201)
|
||||||
|
|
@ -982,7 +982,7 @@ async def update_skill(
|
||||||
raise HTTPException(status_code=400, detail=msg) from exc
|
raise HTTPException(status_code=400, detail=msg) from exc
|
||||||
|
|
||||||
|
|
||||||
@admin_router.post("/skills/import")
|
@admin_router.post("/skills/import", status_code=201)
|
||||||
async def import_skill(
|
async def import_skill(
|
||||||
payload: SkillImportRequest,
|
payload: SkillImportRequest,
|
||||||
request: Request,
|
request: Request,
|
||||||
|
|
|
||||||
|
|
@ -250,7 +250,7 @@ class TestSkillEnableDisable:
|
||||||
|
|
||||||
|
|
||||||
class TestSkillImport:
|
class TestSkillImport:
|
||||||
def test_import_valid_yaml_returns_200(
|
def test_import_valid_yaml_returns_201(
|
||||||
self,
|
self,
|
||||||
admin_client: TestClient,
|
admin_client: TestClient,
|
||||||
skills_dir: str,
|
skills_dir: str,
|
||||||
|
|
@ -260,7 +260,7 @@ class TestSkillImport:
|
||||||
"/api/v1/admin/skills/import",
|
"/api/v1/admin/skills/import",
|
||||||
json={"yaml_content": _VALID_SKILL_YAML},
|
json={"yaml_content": _VALID_SKILL_YAML},
|
||||||
)
|
)
|
||||||
assert resp.status_code == 200, resp.text
|
assert resp.status_code == 201, resp.text
|
||||||
body = resp.json()
|
body = resp.json()
|
||||||
assert body["name"] == "admin_test_skill"
|
assert body["name"] == "admin_test_skill"
|
||||||
assert os.path.isfile(body["path"])
|
assert os.path.isfile(body["path"])
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue