step 2 complete: all request/response models defined and validated
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -98,8 +98,8 @@ adiuva-api/
|
|||||||
- [x] Write `.env.example`
|
- [x] Write `.env.example`
|
||||||
- **Outcome:** Runnable FastAPI skeleton (returns 404 on all routes).
|
- **Outcome:** Runnable FastAPI skeleton (returns 404 on all routes).
|
||||||
|
|
||||||
### Step 2 — Pydantic schemas (API contracts)
|
### Step 2 — Pydantic schemas (API contracts) ✅
|
||||||
- [ ] Create `app/schemas.py` (mirrors `src/shared/api-types.ts` from Electron repo):
|
- [x] Create `app/schemas.py` (mirrors `src/shared/api-types.ts` from Electron repo):
|
||||||
- `ChatRequest`: `message: str`, `context: ChatContext`, `execution_mode: Literal['direct', 'plan']`
|
- `ChatRequest`: `message: str`, `context: ChatContext`, `execution_mode: Literal['direct', 'plan']`
|
||||||
- `ChatContext`: `user_profile: dict`, `relevant_documents: list[str]`, `recent_tasks: list[dict]`, `conversation_history: list[dict]`
|
- `ChatContext`: `user_profile: dict`, `relevant_documents: list[str]`, `recent_tasks: list[dict]`, `conversation_history: list[dict]`
|
||||||
- `ChatResponse`: `response: str`, `actions: list[PlanAction]`
|
- `ChatResponse`: `response: str`, `actions: list[PlanAction]`
|
||||||
|
|||||||
84
app/schemas.py
Normal file
84
app/schemas.py
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
"""Pydantic schemas — API request/response contracts.
|
||||||
|
|
||||||
|
Mirrors the TypeScript types from the Electron app (src/shared/api-types.ts).
|
||||||
|
"""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from typing import Any, Literal
|
||||||
|
|
||||||
|
from pydantic import BaseModel, Field
|
||||||
|
|
||||||
|
|
||||||
|
# ── Billing ──────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
BillingTier = Literal["free", "pro", "power", "team"]
|
||||||
|
|
||||||
|
|
||||||
|
# ── Auth ─────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
class AuthTokens(BaseModel):
|
||||||
|
access_token: str
|
||||||
|
refresh_token: str
|
||||||
|
expires_at: int
|
||||||
|
|
||||||
|
|
||||||
|
class UserProfile(BaseModel):
|
||||||
|
id: str
|
||||||
|
email: str
|
||||||
|
tier: BillingTier
|
||||||
|
|
||||||
|
|
||||||
|
# ── Chat ─────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
class ChatContext(BaseModel):
|
||||||
|
user_profile: dict[str, Any] = Field(default_factory=dict)
|
||||||
|
relevant_documents: list[str] = Field(default_factory=list)
|
||||||
|
recent_tasks: list[dict[str, Any]] = Field(default_factory=list)
|
||||||
|
conversation_history: list[dict[str, Any]] = Field(default_factory=list)
|
||||||
|
|
||||||
|
|
||||||
|
class PlanAction(BaseModel):
|
||||||
|
type: Literal[
|
||||||
|
"create_record",
|
||||||
|
"update_record",
|
||||||
|
"delete_record",
|
||||||
|
"index_document",
|
||||||
|
"send_notification",
|
||||||
|
]
|
||||||
|
table: str | None = None
|
||||||
|
data: dict[str, Any] | None = None
|
||||||
|
|
||||||
|
|
||||||
|
class ChatRequest(BaseModel):
|
||||||
|
message: str
|
||||||
|
context: ChatContext = Field(default_factory=ChatContext)
|
||||||
|
execution_mode: Literal["direct", "plan"] = "direct"
|
||||||
|
|
||||||
|
|
||||||
|
class ChatResponse(BaseModel):
|
||||||
|
response: str
|
||||||
|
actions: list[PlanAction] = Field(default_factory=list)
|
||||||
|
|
||||||
|
|
||||||
|
# ── Execution Plans ──────────────────────────────────────────────────
|
||||||
|
|
||||||
|
class PlanStep(BaseModel):
|
||||||
|
action: str
|
||||||
|
prompt_template: str | None = None
|
||||||
|
variables: dict[str, Any] | None = None
|
||||||
|
data_from_step: int | None = None
|
||||||
|
|
||||||
|
|
||||||
|
class ExecutionPlan(BaseModel):
|
||||||
|
agent: str
|
||||||
|
steps: list[PlanStep] = Field(default_factory=list)
|
||||||
|
|
||||||
|
|
||||||
|
# ── Backup ───────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
class BackupMetadata(BaseModel):
|
||||||
|
version: int
|
||||||
|
timestamp: int
|
||||||
|
checksum: str
|
||||||
|
chunk_count: int
|
||||||
Reference in New Issue
Block a user