2026-02-09 15:49:50 +05:30
|
|
|
"""Schemas for gateway CRUD and template-sync API payloads."""
|
|
|
|
|
|
2026-02-04 23:07:22 +05:30
|
|
|
from __future__ import annotations
|
|
|
|
|
|
2026-02-09 15:49:50 +05:30
|
|
|
from datetime import datetime # noqa: TCH003
|
|
|
|
|
from uuid import UUID # noqa: TCH003
|
2026-02-04 23:07:22 +05:30
|
|
|
|
2026-02-06 16:12:04 +05:30
|
|
|
from pydantic import field_validator
|
2026-02-07 04:24:06 +05:30
|
|
|
from sqlmodel import Field, SQLModel
|
2026-02-04 23:07:22 +05:30
|
|
|
|
|
|
|
|
|
|
|
|
|
class GatewayBase(SQLModel):
|
2026-02-09 15:49:50 +05:30
|
|
|
"""Shared gateway fields used across create/read payloads."""
|
|
|
|
|
|
2026-02-04 23:07:22 +05:30
|
|
|
name: str
|
|
|
|
|
url: str
|
|
|
|
|
main_session_key: str
|
|
|
|
|
workspace_root: str
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class GatewayCreate(GatewayBase):
|
2026-02-09 15:49:50 +05:30
|
|
|
"""Payload for creating a gateway configuration."""
|
|
|
|
|
|
2026-02-04 23:07:22 +05:30
|
|
|
token: str | None = None
|
|
|
|
|
|
2026-02-06 16:12:04 +05:30
|
|
|
@field_validator("token", mode="before")
|
|
|
|
|
@classmethod
|
2026-02-09 15:49:50 +05:30
|
|
|
def normalize_token(cls, value: object) -> str | None | object:
|
|
|
|
|
"""Normalize empty/whitespace tokens to `None`."""
|
2026-02-06 16:12:04 +05:30
|
|
|
if value is None:
|
|
|
|
|
return None
|
|
|
|
|
if isinstance(value, str):
|
|
|
|
|
value = value.strip()
|
|
|
|
|
return value or None
|
|
|
|
|
return value
|
|
|
|
|
|
2026-02-04 23:07:22 +05:30
|
|
|
|
|
|
|
|
class GatewayUpdate(SQLModel):
|
2026-02-09 15:49:50 +05:30
|
|
|
"""Payload for partial gateway updates."""
|
|
|
|
|
|
2026-02-04 23:07:22 +05:30
|
|
|
name: str | None = None
|
|
|
|
|
url: str | None = None
|
|
|
|
|
token: str | None = None
|
|
|
|
|
main_session_key: str | None = None
|
|
|
|
|
workspace_root: str | None = None
|
|
|
|
|
|
2026-02-06 16:12:04 +05:30
|
|
|
@field_validator("token", mode="before")
|
|
|
|
|
@classmethod
|
2026-02-09 15:49:50 +05:30
|
|
|
def normalize_token(cls, value: object) -> str | None | object:
|
|
|
|
|
"""Normalize empty/whitespace tokens to `None`."""
|
2026-02-06 16:12:04 +05:30
|
|
|
if value is None:
|
|
|
|
|
return None
|
|
|
|
|
if isinstance(value, str):
|
|
|
|
|
value = value.strip()
|
|
|
|
|
return value or None
|
|
|
|
|
return value
|
|
|
|
|
|
2026-02-04 23:07:22 +05:30
|
|
|
|
|
|
|
|
class GatewayRead(GatewayBase):
|
2026-02-09 15:49:50 +05:30
|
|
|
"""Gateway payload returned from read endpoints."""
|
|
|
|
|
|
2026-02-04 23:07:22 +05:30
|
|
|
id: UUID
|
2026-02-08 21:16:26 +05:30
|
|
|
organization_id: UUID
|
2026-02-04 23:07:22 +05:30
|
|
|
token: str | None = None
|
|
|
|
|
created_at: datetime
|
|
|
|
|
updated_at: datetime
|
2026-02-07 04:24:06 +05:30
|
|
|
|
|
|
|
|
|
|
|
|
|
class GatewayTemplatesSyncError(SQLModel):
|
2026-02-09 15:49:50 +05:30
|
|
|
"""Per-agent error entry from a gateway template sync operation."""
|
|
|
|
|
|
2026-02-07 04:24:06 +05:30
|
|
|
agent_id: UUID | None = None
|
|
|
|
|
agent_name: str | None = None
|
|
|
|
|
board_id: UUID | None = None
|
|
|
|
|
message: str
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class GatewayTemplatesSyncResult(SQLModel):
|
2026-02-09 15:49:50 +05:30
|
|
|
"""Summary payload returned by gateway template sync endpoints."""
|
|
|
|
|
|
2026-02-07 04:24:06 +05:30
|
|
|
gateway_id: UUID
|
|
|
|
|
include_main: bool
|
|
|
|
|
reset_sessions: bool
|
|
|
|
|
agents_updated: int
|
|
|
|
|
agents_skipped: int
|
|
|
|
|
main_updated: bool
|
|
|
|
|
errors: list[GatewayTemplatesSyncError] = Field(default_factory=list)
|