여러 줄 주석이 설명보다 경위(예전·실측·지적)를 적고 있어 읽는 사람이 결론을 찾기 어려웠다. - ts·tsx·js·mjs·css·py 478개: 여러 줄 주석은 첫 문장 한 줄로, 과거형·날짜 문장은 삭제 - 주석 위치는 TypeScript 파서·파이썬 tokenize/ast 로 찾는다 — 문자열 안의 # · /* 는 건드리지 않는다 - eslint·ts·noqa·type: ignore 같은 지시 주석은 그대로 둔다 파이썬 275개 정리 전후 AST 동일, TS 298개 주석 뺀 토큰 동일(빈 JSX 주석 10곳만 차이). site·frontend·admin tsc, site vitest 105 passed Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
62 lines
1.7 KiB
Python
62 lines
1.7 KiB
Python
"""사장님 에이전트 대화 — 빌더 화면의 입구."""
|
|
|
|
from uuid import UUID
|
|
|
|
from fastapi import APIRouter, Depends, HTTPException, Response
|
|
from pydantic import BaseModel, Field
|
|
|
|
from common.models.gmodel import UserInfo
|
|
from router.v1.validator.dependencies import IsValidAccessToken
|
|
from services.agent import runtime
|
|
from services.agent.runtime import AgentError
|
|
|
|
router = APIRouter(prefix="/v1/agent", tags=["Agent"])
|
|
|
|
_STATUS = {
|
|
"PLACE_NOT_FOUND": 404,
|
|
"AGENT_NOT_CONFIGURED": 409,
|
|
"AGENT_UNKNOWN_TOOL": 409,
|
|
"AGENT_EMPTY_MESSAGE": 400,
|
|
"AGENT_MESSAGE_TOO_LONG": 400,
|
|
"AGENT_CALL_FAILED": 502,
|
|
}
|
|
|
|
|
|
class Confirm(BaseModel):
|
|
"""직전 답의 확인 버튼이 그대로 돌려보내는 값."""
|
|
|
|
tool: str = Field(min_length=1, max_length=40)
|
|
args: dict = {}
|
|
|
|
|
|
class Req_Chat(BaseModel):
|
|
message: str = Field(default="", max_length=runtime.MAX_MESSAGE)
|
|
confirm: Confirm | None = None
|
|
|
|
|
|
@router.get("/status")
|
|
async def status(response: Response, user: UserInfo = Depends(IsValidAccessToken)):
|
|
"""대화창을 열 수 있는지."""
|
|
response.headers["Cache-Control"] = "no-store"
|
|
return {"enabled": runtime.is_configured()}
|
|
|
|
|
|
@router.post("/chat/{place_id}")
|
|
async def chat(
|
|
place_id: UUID,
|
|
req: Req_Chat,
|
|
response: Response,
|
|
user: UserInfo = Depends(IsValidAccessToken),
|
|
):
|
|
response.headers["Cache-Control"] = "no-store"
|
|
response.headers["Referrer-Policy"] = "no-referrer"
|
|
try:
|
|
return await runtime.chat(
|
|
user,
|
|
str(place_id),
|
|
req.message,
|
|
confirm=req.confirm.model_dump() if req.confirm else None,
|
|
)
|
|
except AgentError as ex:
|
|
raise HTTPException(_STATUS.get(str(ex), 409), str(ex)) from ex
|