Documentation
¶
Overview ¶
Package broker is a thin REST→ws codex v2 JSON-RPC adapter inside CXG. It owns no business logic: it converts a single /api/turns REST call into a turn lifecycle on a loopback ws to a codex app-server subprocess, returning the resulting codex Turn object verbatim.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Conn ¶
type Conn struct {
// contains filtered or unexported fields
}
Conn is one loopback ws to a codex app-server subprocess. Safe for concurrent Turn() / StartThread() calls — internally serializes writes and demuxes responses + turn/completed notifications.
func Dial ¶
Dial opens a fresh ws, performs the codex initialize / initialized handshake, and starts the reader goroutine. Caller must Close().
func (*Conn) StartThread ¶
StartThread issues thread/start with empty params and returns the new thread id. Other ThreadStartResponse fields are discarded — CXG only owns the loopback, agentserver tracks per-conversation state.
func (*Conn) Turn ¶
func (c *Conn) Turn(ctx context.Context, threadID string, callerParams json.RawMessage, timeout time.Duration) (json.RawMessage, error)
Turn sends turn/start and blocks until the matching turn/completed notification arrives or timeout elapses. Returns the raw codex Turn JSON for verbatim REST passthrough.
type Pool ¶
type Pool struct {
// contains filtered or unexported fields
}
Pool caches one *Conn per workspace id. Connections whose ws has been silent (no frames in either direction) for longer than idleTTL are reaped and closed. Safe for concurrent use.
Idleness is measured from Conn.lastActiveAt, which the conn itself updates on every successful ws read/write. This means a long-running Turn that keeps streaming item/completed frames stays alive past idleTTL — the reaper only kills conns that are actually silent.
func NewPool ¶
func NewPool(resolver WSURLResolver, idleTTL time.Duration) *Pool
NewPool starts a background reaper goroutine. Caller must Close().
type TimeoutError ¶
type TimeoutError struct {
ThreadID, TurnID string
}
TimeoutError is returned when timeoutMs elapses without turn/completed.
func (*TimeoutError) Error ¶
func (e *TimeoutError) Error() string
type TurnRPCError ¶
type TurnRPCError struct {
Code int
Message string
Data json.RawMessage
}
TurnRPCError is returned by Turn when codex returns a JSON-RPC error in response to turn/start (rare; usually means malformed request).
func (*TurnRPCError) Error ¶
func (e *TurnRPCError) Error() string