Sign in

    tun-poc-proto

    Download zip
    Version
    0.1.3
    License
    Apache-2.0
    Last updated
    5 months ago
    Downloads
    194

    #tun-poc-proto

    Shared wire protocol types for tun-poc. Imported by the browser client, the relay, and the server agent so all three stay in sync.

    Covers:

    • Relay ↔ client and relay ↔ server messages (session lifecycle, terminal I/O, resize, reconnection).
    • REST API payloads (auth, user status, server list).
    • Codex JSON-RPC envelopes and filesystem event types.
    • Newtype IDs (ServerId, UserId, GroupId) and typed serde for each message variant.

    See docs/protocol.md for the message flow.

    AddMemberRequest

    pub(all) struct AddMemberRequest {
    login : String
    }

    CodexActiveFlag

    pub(all) enum CodexActiveFlag {
    WaitingOnApproval
    WaitingOnUserInput
    } derive(Eq,
    Debug
    )

    CodexActivityStatus

    pub(all) enum CodexActivityStatus {
    NotLoaded
    Idle
    Active(Array[CodexActiveFlag])
    SystemError
    } derive(Eq,
    Debug
    )

    CodexApproval

    pub(all) enum CodexApproval {
    Command(String)
    FileChange(String)
    }

    CodexApprovalDecision

    pub(all) enum CodexApprovalDecision {
    Accept
    Decline
    }

    CodexClientInfo

    pub(all) struct CodexClientInfo {
    name : String
    title : String
    version : String
    }

    CodexIncoming

    pub(all) enum CodexIncoming {
    ThreadResult(CodexThreadResult)
    ThreadListResult(Array[CodexThreadResult])
    ThreadReadResult(CodexThreadResult, Array[CodexReadTurn])
    OtherResponse(Json)
    TurnStarted(CodexTurnId)
    TurnCompleted(CodexTurnId, CodexStatus)
    ItemStarted(CodexTurnId, CodexItemId, CodexItemKind, String, String)
    ItemCompleted(CodexTurnId, CodexItemId, CodexStatus)
    Delta(CodexTurnId, CodexItemId, String, CodexItemKind)
    ThreadStatusChanged(CodexThreadId, CodexActivityStatus)
    Approval(CodexRequestId, CodexThreadId, CodexTurnId, CodexItemId, CodexApproval)
    }

    CodexItemId

    pub(all) struct CodexItemId(String) derive(Eq,
    Debug
    )

    CodexItemKind

    pub(all) enum CodexItemKind {
    AgentMessage
    UserMessage
    CommandExecution
    FileChange
    Reasoning
    } derive(Eq,
    Debug
    )

    CodexOutgoing

    pub(all) enum CodexOutgoing {
    Initialize(Int, CodexClientInfo)
    ThreadStart(Int, String)
    ThreadList(Int, String)
    ThreadRead(Int, CodexThreadId, Bool)
    ThreadResume(Int, CodexThreadId)
    TurnStart(Int, CodexThreadId, String)
    TurnInterrupt(Int, CodexThreadId, CodexTurnId)
    Initialized
    Approval(CodexRequestId, CodexApprovalDecision)
    }

    CodexReadItem

    pub(all) struct CodexReadItem {
    id : CodexItemId
    kind : CodexItemKind
    text : String
    command : String
    output : String
    }

    CodexReadTurn

    pub(all) struct CodexReadTurn {
    id : CodexTurnId
    items : Array[CodexReadItem]
    status : CodexStatus
    }

    CodexRequestId

    pub(all) struct CodexRequestId(Json)

    CodexStatus

    pub(all) enum CodexStatus {
    InProgress
    Completed
    Failed
    } derive(Eq,
    Debug
    )

    CodexThreadResult

    pub(all) struct CodexThreadResult {
    id : CodexThreadId
    preview : String
    status : CodexThreadStatus
    activity : CodexActivityStatus
    } derive(Eq,
    Debug
    )

    CodexThreadStatus

    pub(all) enum CodexThreadStatus {
    Open
    Archived
    Closed
    } derive(Eq,
    Debug
    )

    CodexTurnId

    pub(all) struct CodexTurnId(String) derive(Eq,
    Debug
    )

    CreateGroupRequest

    pub(all) struct CreateGroupRequest {
    name : String
    }

    CreateMachineRequest

    pub(all) struct CreateMachineRequest {
    name : String
    }

    CreateMachineResponse

    pub(all) struct CreateMachineResponse {
    token : String
    machine_id : Int
    }

    CreatedGroupResponse

    pub(all) struct CreatedGroupResponse {
    id : Int
    }

    DeviceApproveRequest

    pub(all) struct DeviceApproveRequest {
    code : String
    }

    Request body of POST /device/approve. Sent by the SPA when the user clicks Approve on the pairing page.

    DeviceAuthorizationRequest

    pub(all) struct DeviceAuthorizationRequest {
    hostname : String
    }

    DeviceAuthorizationResponse

    pub(all) struct DeviceAuthorizationResponse {
    device_code : String
    user_code : String
    verification_uri : String
    verification_uri_complete : String?
    expires_in : Int
    interval : Int
    }

    DeviceDenyRequest

    pub(all) struct DeviceDenyRequest {
    code : String
    }

    Request body of POST /device/deny. Sent by the SPA when the user clicks Deny on the pairing page.

    DevicePendingResponse

    pub(all) struct DevicePendingResponse {
    hostname : String
    }

    Response body of GET /device/pending?code=<user_code>. Returned to the SPA approval page so it can render the hostname the agent reported.

    DeviceTokenError

    pub(all) enum DeviceTokenError {
    AuthorizationPending
    SlowDown
    ExpiredToken
    AccessDenied
    InvalidRequest
    UnsupportedGrantType
    Unknown(String)
    }

    RFC 8628 §3.5 token-endpoint error codes, plus Unknown(String) as a forward-compatibility hatch for codes added by a future relay against an older server. Wire format is a bare JSON string (see DeviceTokenResponse::Error).

    DeviceTokenRequest

    pub(all) struct DeviceTokenRequest {
    grant_type : String
    device_code : String
    }

    DeviceTokenResponse

    pub(all) enum DeviceTokenResponse {
    Success(String, String)
    Error(DeviceTokenError)
    }

    RFC 8628 §3.5 token-endpoint response. Discriminated on the wire by which field is present: access_token → Success, error → Error.

    ErrorCode

    pub(all) enum ErrorCode {
    TaskNotFound
    TaskOffline
    InternalError
    ProtoVersionTooOld(Int)
    } derive(Eq,
    Debug
    )

    ErrorCode::to_wire

    fn ErrorCode::to_wire(self : ErrorCode) -> String

    FileStat

    pub(all) struct FileStat {
    file_type : Int
    size : Int64
    mtime : Int64
    ctime : Int64
    } derive(
    Debug
    )

    impl ToJson for FileStat

    FileStat::to_log_string

    fn FileStat::to_log_string(self : FileStat) -> String

    FsMessage

    pub(all) enum FsMessage {
    Stat(String, String, String)
    StatResult(String, String, FileStat)
    Readdir(String, String, String)
    ReaddirResult(String, String, Array[(String, Int)])
    ReadFile(String, String, String)
    ReadFileResult(String, String, String)
    WriteFile(String, String, String, String, Bool, Bool)
    Mkdir(String, String, String)
    FsDelete(String, String, String, Bool)
    FsRename(String, String, String, String, Bool)
    FsOk(String, String)
    FsError(String, String, String, String)
    } derive(
    Debug
    )

    impl ToJson for FsMessage

    FsMessage::client_id

    fn FsMessage::client_id(self : FsMessage) -> String

    FsMessage::to_log_string

    fn FsMessage::to_log_string(self : FsMessage) -> String

    GrantAccessRequest

    pub(all) struct GrantAccessRequest {
    group_id : Int
    }

    GroupInfo

    pub(all) struct GroupInfo {
    id : Int
    name : String
    owner_id : Int64
    }

    GroupMember

    pub(all) struct GroupMember {
    github_id : Int64
    login : String
    avatar_url : String
    }

    MachineAccessGroup

    pub(all) struct MachineAccessGroup {
    group_id : Int
    name : String
    }

    Message

    pub(all) enum Message {
    Sys(SysMessage)
    Fs(FsMessage)
    Term(TermMessage)
    Codex(String, String)
    } derive(
    Debug
    )

    impl ToJson for Message

    Message::client_id

    fn Message::client_id(self : Message) -> String

    Message::to_log_string

    fn Message::to_log_string(self : Message) -> String

    RegisterRejectReason

    pub(all) enum RegisterRejectReason {
    UuidAlreadyClaimedThisSession
    InvalidUuid
    ProtoVersionTooOld(Int)
    } derive(Eq,
    Debug
    )

    RegisterRejectReason::to_wire

    fn RegisterRejectReason::to_wire(self : RegisterRejectReason) -> String

    SysMessage

    pub(all) enum SysMessage {
    Register(
    UUID
    , String, String, Int)
    Registered(
    UUID
    )
    RegisterRejected(RegisterRejectReason)
    TaskExited(Int)
    Connect(
    UUID
    , Int64?, Int)
    Connected
    TaskOnline
    NewClient(String, Int64?)
    ClientDisconnected(String)
    Error(ErrorCode)
    AuthError(String)
    }

    impl Debug for SysMessage

    SysMessage::client_id

    fn SysMessage::client_id(self : SysMessage) -> String

    SysMessage::to_log_string

    fn SysMessage::to_log_string(self : SysMessage) -> String

    TaskEntry

    pub(all) struct TaskEntry {
    task_uuid :
    UUID

    machine_id : Int
    hostname : String
    cwd : String
    owner : String
    online : Bool
    last_seen_at : Int64
    }

    Flat row for the GET /api/tasks listing. One row per running task instance (keyed by task_uuid), joined with its parent machine's display info. machine_id groups tasks that belong to the same long-lived machine; task_uuid is the identity used everywhere else on the wire.
    impl ToJson for TaskEntry

    TermMessage

    pub(all) enum TermMessage {
    Data(String, Int64, Int64?, Bool?, String)
    Exited(String, Int64)
    } derive(
    Debug
    )

    TermMessage::client_id

    fn TermMessage::client_id(self : TermMessage) -> String

    TermMessage::to_log_string

    fn TermMessage::to_log_string(self : TermMessage) -> String

    TransferGroupRequest

    pub(all) struct TransferGroupRequest {
    new_owner_id : Int64
    }

    UserInfo

    pub(all) struct UserInfo {
    github_id : Int64
    login : String
    avatar_url : String
    status : UserStatus
    is_admin : Bool
    }

    UserStatus

    pub(all) enum UserStatus {
    Pending
    Approved
    Rejected
    } derive(Eq,
    Debug
    )

    UserStatus::from_string

    fn UserStatus::from_string(s : String) -> UserStatus

    UserStatus::to_string

    fn UserStatus::to_string(self : UserStatus) -> String

    ProtoMinVersion

    let ProtoMinVersion : Int

    Lowest proto_version the relay accepts on Register/Connect. Bump to match ProtoVersion when dropping support for a prior version.

    ProtoVersion

    let ProtoVersion : Int

    Wire protocol version this build speaks. Bumped on every breaking change to Register/Connect or the sys-channel handshake. Both fields default to 0 so peers built before versioning was introduced decode as version 0 — fully backwards compatible.