ForcePilot/backend/package/yuxi/gateway/protocol/frames.py
Kris fee71576a2 feat(gateway): add core gateway protocol implementation
新建了完整的网关协议模块,包含版本协商、基础类型定义、信道请求模型、错误码规范、通信帧结构以及握手流程,实现了完整的客户端-服务端通信协议基础框架
2026-05-12 00:54:15 +08:00

37 lines
753 B
Python

from __future__ import annotations
from typing import TYPE_CHECKING, Any, Literal
from pydantic import BaseModel, Field
if TYPE_CHECKING:
from yuxi.gateway.protocol.errors import ErrorDetail
class RequestFrame(BaseModel):
type: Literal["req"] = "req"
id: str
method: str
params: dict[str, Any] = Field(default_factory=dict)
class ResponseFrame(BaseModel):
type: Literal["res"] = "res"
id: str
ok: bool
payload: Any = None
error: ErrorDetail | None = None
class EventFrame(BaseModel):
type: Literal["event"] = "event"
event: str
payload: Any = None
seq: int = 0
state_version: int = 0
from yuxi.gateway.protocol.errors import ErrorDetail # noqa: E402
ResponseFrame.model_rebuild()