rivet-actor-runtime-socket-protocol 2.3.5

Versioned protocol for the experimental Actor Runtime Socket
# MARK: Handshake

# The schema version rides in the vbare embedded-version prefix of every
# frame, so ClientHello carries no version or authentication fields.
type ClientHello void

type HelloOk struct {
	# Largest frame payload the server accepts and will send.
	maxFrameBytes: u32
}

type HelloRejectUnsupportedVersion void

type ServerHello union {
	HelloOk |
	HelloRejectUnsupportedVersion
}

# MARK: SQL values

type SqlNull void
type SqlInteger i64
type SqlReal f64
type SqlText str
type SqlBlob data

type SqlValue union {
	SqlNull |
	SqlInteger |
	SqlReal |
	SqlText |
	SqlBlob
}

type SqlRow list<SqlValue>

# MARK: SQLite API — requests

# Multi-statement script, one job, no params, no result rows.
type SqliteExec struct {
	script: str
}

# Single statement, positional params, returns rows and change counts.
type SqliteQuery struct {
	sql: str
	params: list<SqlValue>
}

# Starts an explicit transaction owned by leaseKey. The optional timeout is
# milliseconds and defaults to the runtime's 60-second safety deadline.
type SqliteBegin struct {
	leaseKey: str
	timeoutMs: optional<u64>
}

type SqliteCommit struct {
	leaseKey: str
}

type SqliteRollback struct {
	leaseKey: str
}

type RequestPayload union {
	SqliteExec |
	SqliteQuery |
	SqliteBegin |
	SqliteCommit |
	SqliteRollback
}

type Request struct {
	requestId: u32
	# For Exec and Query, selects a transaction started on this connection.
	leaseKey: optional<str>
	payload: RequestPayload
}

type ClientFrame union {
	Request
}

# MARK: SQLite API — responses

type SqliteExecOk void
type SqliteBeginOk void
type SqliteCommitOk void
type SqliteRollbackOk void

type SqliteQueryOk struct {
	columns: list<str>
	rows: list<SqlRow>
	changes: i64
	lastInsertRowId: optional<i64>
}

# MARK: Errors

type SqlError struct {
	code: i32
	statementIndex: u32
	message: str
}

type EndpointClosed void

type QueueFull struct {
	limit: str
	capacity: u32
}

# The key was missing, unknown, owned by another connection, or already
# committed/rolled back. The request was not executed.
type InvalidLeaseKey struct {
	message: str
}

# The key's deadline fired (or its connection closed) and its transaction was
# rolled back. The request was not executed.
type LeaseExpired struct {
	timeoutMs: u64
	message: str
}

# The statement executed, but its serialized response exceeded maxFrameBytes.
type ResponseTooLarge void

type ResponsePayload union {
	SqliteExecOk |
	SqliteQueryOk |
	SqliteBeginOk |
	SqliteCommitOk |
	SqliteRollbackOk |
	SqlError |
	EndpointClosed |
	QueueFull |
	InvalidLeaseKey |
	LeaseExpired |
	ResponseTooLarge
}

type Response struct {
	requestId: u32
	payload: ResponsePayload
}

# MARK: Connection-level errors

type FrameTooLarge void
type MalformedFrame void

type GoAwayReason union {
	FrameTooLarge |
	MalformedFrame
}

type GoAway struct {
	reason: GoAwayReason
}

type ServerFrame union {
	Response |
	GoAway
}