Documentation
¶
Overview ¶
Package codexsock is a client for a local Codex App Server. It connects over the server's Unix domain socket, speaks JSON-RPC over WebSocket, and offers thread discovery, naming, queued messages and mid-turn steering.
Use Dial to open a Client, then call its methods. A Client supports concurrent calls and never reconnects or replays a request: after the connection drops, Dial again. Queued sends report one of three outcomes (see QueueStatus), and a caller must treat an unknown outcome as possibly delivered. The App Server API is experimental and can change between Codex releases.
Index ¶
- Variables
- func ValidThreadID(id string) bool
- func Version() string
- type Client
- func (c *Client) Close() error
- func (c *Client) FindThread(ctx context.Context, idOrName string) (Thread, error)
- func (c *Client) ListThreads(ctx context.Context, opt ListOptions) ([]Thread, error)
- func (c *Client) Probe(ctx context.Context) error
- func (c *Client) Queue(ctx context.Context, id string, msg Message, opt QueueOptions) (QueueResult, error)
- func (c *Client) ReadThread(ctx context.Context, id string) (Thread, error)
- func (c *Client) Rename(ctx context.Context, id, name string) error
- func (c *Client) Resume(ctx context.Context, id string) error
- func (c *Client) Steer(ctx context.Context, id, turnID, text string) (string, error)
- type Config
- type ListOptions
- type Message
- type QueueOptions
- type QueueResult
- type QueueStatus
- type RPCError
- type Thread
- type ThreadStatus
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNotFound is returned (wrapped) by FindThread when no thread matches. ErrNotFound = errors.New("thread not found") // ErrAmbiguous is returned (wrapped) by FindThread when more than one // thread has the requested exact name. ErrAmbiguous = errors.New("ambiguous thread name") )
var ErrClosed = errors.New("codexsock: client closed")
ErrClosed is returned by calls made after Close, and by calls still pending when Close runs.
Functions ¶
func ValidThreadID ¶
ValidThreadID reports whether id has the canonical 8-4-4-4-12 hexadecimal UUID form used for Codex thread IDs.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is an initialized connection to an App Server. Create it with Dial. Calls can run concurrently. After the connection closes, use Dial again; the client never replays requests.
All calls share one connection. If the context of a call expires while its request is being written, the WebSocket library closes the whole connection, which fails every concurrent call. A call whose context expires while it waits for the write lock is reported as sent (so Queue reports an unknown outcome), which is pessimistic but safe.
func Dial ¶
Dial connects to the App Server named by cfg, performs the initialize handshake and returns a ready Client. The caller must Close it. Dial fails if the socket is unreachable, the WebSocket upgrade is refused or the server rejects initialization.
func (*Client) Close ¶
Close closes the connection, fails pending calls with ErrClosed and waits for the reader goroutine to stop. It is safe to call more than once.
func (*Client) FindThread ¶
FindThread resolves a thread by ID or exact name. An ID match wins over a name match. A name lookup lists saved and loaded threads, which takes several calls, so bound the whole operation with ctx. It supports at most 10,000 threads per listing and fails with an error beyond that; use the thread ID instead. It returns ErrNotFound when nothing matches and ErrAmbiguous when several threads share the name.
func (*Client) ListThreads ¶
ListThreads returns saved threads, or loaded threads when opt.LoadedOnly is set. It pages through the server's results with one call per page, so bound the whole operation with ctx. A listing of more than 10,000 threads fails with an error rather than returning a partial result.
func (*Client) Probe ¶
Probe makes one inexpensive read-only call to check that the server responds.
func (*Client) Queue ¶
func (c *Client) Queue(ctx context.Context, id string, msg Message, opt QueueOptions) (QueueResult, error)
Queue adds one text message to the queue of the thread with the given ID. The result is always populated, including on error. An unknown status means the message may have been accepted, so a caller should keep the correlation ID and avoid blind retries.
func (*Client) ReadThread ¶
ReadThread returns the metadata of the thread with the given ID, without its turns. It rejects an invalid thread ID before contacting the server.
func (*Client) Rename ¶
Rename sets the name of the thread with the given ID. It rejects an invalid thread ID and an empty name before contacting the server.
type Config ¶
type Config struct {
// Address is the App Server endpoint. It must be "unix://PATH" for an
// explicit socket. An empty string or "unix://" selects the default
// socket under $CODEX_HOME, or ~/.codex when CODEX_HOME is unset. Other
// schemes are rejected.
Address string
// Timeout is a per-call limit, not an operation limit. It bounds the
// connection handshake and each individual RPC call, so an operation that
// makes several calls (such as FindThread) can take longer in total. Bound
// a whole operation with the deadline of the context passed to it. A zero
// or negative value means 5 seconds.
Timeout time.Duration
}
Config configures Dial.
type ListOptions ¶
type ListOptions struct {
// LoadedOnly lists only threads currently loaded in the server's memory
// instead of the saved-thread listing.
LoadedOnly bool
}
ListOptions selects which threads ListThreads returns.
type Message ¶
type Message struct {
// Text is the message body. It must contain a non-blank character.
Text string
// ClientMessageID is an optional caller-chosen correlation ID. Queue
// generates one when it is empty.
ClientMessageID string
}
Message is the text to deliver with Queue.
type QueueOptions ¶
type QueueOptions struct {
// Resume sends a separate thread resume request after the server has
// accepted the message. A failed resume does not change the queue status;
// it is reported in QueueResult.ResumeError.
Resume bool
}
QueueOptions adjusts Queue.
type QueueResult ¶
type QueueResult struct {
// Status is the outcome. See the QueueStatus constants.
Status QueueStatus `json:"status"`
// ClientMessageID is the correlation ID sent with the message.
ClientMessageID string `json:"clientMessageId,omitempty"`
// SubmissionID is the server's ID for the queued submission when Status
// is QueueAccepted.
SubmissionID string `json:"submissionId,omitempty"`
// ResumeError describes a failed resume request after an accepted queue.
ResumeError string `json:"resumeError,omitempty"`
}
QueueResult is the structured outcome of Queue.
type QueueStatus ¶
type QueueStatus string
QueueStatus is the outcome of Queue.
const ( // QueueAccepted ("queued") means the server accepted the submission and // returned a matching submission ID. It does not mean the thread has // started or finished processing the message. QueueAccepted QueueStatus = "queued" // QueueUnknown ("unknown") means the request may have reached the server, // for example after a timeout, a disconnect or an unusable reply, so the // message may or may not be queued. Check the thread before sending // again; do not retry blindly. QueueUnknown QueueStatus = "unknown" // QueueFailed ("failed") means the message was definitely not queued: // invalid input, a cancelled context before anything was written, or a // request the server rejected as invalid. QueueFailed QueueStatus = "failed" )
type RPCError ¶
RPCError is a JSON-RPC error object returned by the App Server. Use errors.As to inspect Code.
type Thread ¶
type Thread struct {
ID string `json:"id"`
Name string `json:"name,omitempty"`
CWD string `json:"cwd,omitempty"`
CreatedAt int64 `json:"createdAt,omitempty"`
UpdatedAt int64 `json:"updatedAt,omitempty"`
Status ThreadStatus `json:"status"`
}
Thread describes one Codex thread as reported by the App Server.
type ThreadStatus ¶
type ThreadStatus struct {
Type string `json:"type,omitempty"`
ActiveFlags []string `json:"activeFlags,omitempty"`
}
ThreadStatus is the runtime status of a thread. Type is a server-defined value such as "notLoaded", "idle" or "active"; ActiveFlags qualify an active thread.
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
codex-send
command
|
|
|
internal
|
|
|
fakeserver
Package fakeserver is a test helper that serves a minimal Codex App Server over a Unix socket.
|
Package fakeserver is a test helper that serves a minimal Codex App Server over a Unix socket. |