85 lines
2.6 KiB
Python
85 lines
2.6 KiB
Python
"""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
|