2026-02-04 23:07:22 +05:30
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
|
|
from datetime import datetime
|
2026-02-06 16:12:04 +05:30
|
|
|
from typing import Any
|
2026-02-04 23:07:22 +05:30
|
|
|
from uuid import UUID
|
|
|
|
|
|
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):
|
|
|
|
|
name: str
|
|
|
|
|
url: str
|
|
|
|
|
main_session_key: str
|
|
|
|
|
workspace_root: str
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class GatewayCreate(GatewayBase):
|
|
|
|
|
token: str | None = None
|
|
|
|
|
|
2026-02-06 16:12:04 +05:30
|
|
|
@field_validator("token", mode="before")
|
|
|
|
|
@classmethod
|
|
|
|
|
def normalize_token(cls, value: Any) -> Any:
|
|
|
|
|
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):
|
|
|
|
|
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
|
|
|
|
|
def normalize_token(cls, value: Any) -> Any:
|
|
|
|
|
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):
|
|
|
|
|
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):
|
|
|
|
|
agent_id: UUID | None = None
|
|
|
|
|
agent_name: str | None = None
|
|
|
|
|
board_id: UUID | None = None
|
|
|
|
|
message: str
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class GatewayTemplatesSyncResult(SQLModel):
|
|
|
|
|
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)
|