codex

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 2, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TitleFromMessage

func TitleFromMessage(text, fallback string) string

Types

type AppServer

type AppServer struct {
	// contains filtered or unexported fields
}

AppServer manages a `codex app-server` child process and speaks the Codex App Server Protocol (JSON-RPC over stdio) with it.

func NewAppServer

func NewAppServer(ctx context.Context, directory string) (*AppServer, error)

NewAppServer spawns `codex app-server`, initializes the JSON-RPC protocol, and returns a ready AppServer.

func (*AppServer) Done

func (s *AppServer) Done() <-chan struct{}

Done returns a channel that is closed when the read loop exits.

func (*AppServer) InputEvents

func (s *AppServer) InputEvents() <-chan UserInputEvent

InputEvents returns a channel that receives user-input requests from the app-server. Only one caller should read from this channel at a time.

func (*AppServer) Notify

func (s *AppServer) Notify(ctx context.Context, method string, params interface{}) error

Notify sends a JSON-RPC notification (no response expected).

func (*AppServer) ReplyUserInput

func (s *AppServer) ReplyUserInput(id int64, answers interface{}) error

ReplyUserInput sends the user's answer for a deferred item/tool/requestUserInput request back to the app-server.

func (*AppServer) Request

func (s *AppServer) Request(ctx context.Context, method string, params interface{}) (json.RawMessage, error)

Request sends a JSON-RPC request and waits for the matching response.

func (*AppServer) Stderr

func (s *AppServer) Stderr() string

Stderr returns the accumulated stderr output.

func (*AppServer) Stop

func (s *AppServer) Stop()

Stop kills the app-server process and cleans up goroutines.

func (*AppServer) Subscribe

func (s *AppServer) Subscribe(threadID string) <-chan CodexEvent

Subscribe registers a channel to receive CodexEvents for the given threadID.

func (*AppServer) Unsubscribe

func (s *AppServer) Unsubscribe(threadID string)

Unsubscribe removes the listener for threadID and closes its channel.

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client implements Backend by communicating with a persistent `codex app-server` process over JSON-RPC stdio.

func NewClient

func NewClient() *Client

func (*Client) BaseURL

func (c *Client) BaseURL() string

func (*Client) CreateSession

func (c *Client) CreateSession(ctx context.Context, directory string) (*Session, error)

func (*Client) GetSession

func (c *Client) GetSession(ctx context.Context, sessionID string) (*Session, error)

func (*Client) Health

func (c *Client) Health(ctx context.Context) error

func (*Client) ListMessages

func (c *Client) ListMessages(ctx context.Context, sessionID string) ([]MessageResponse, error)

func (*Client) ListProviders

func (c *Client) ListProviders(ctx context.Context) ([]Provider, []string, error)

func (*Client) ListSessions

func (c *Client) ListSessions(ctx context.Context) ([]Session, error)

func (*Client) ReplyQuestion

func (c *Client) ReplyQuestion(ctx context.Context, requestID string, answers [][]string) error

func (*Client) SendMessageEvents

func (c *Client) SendMessageEvents(ctx context.Context, sessionID, text, providerID, modelID, agent string) <-chan StreamEvent

func (*Client) ServerProcess

func (c *Client) ServerProcess() interface {
	Stop()
	Done() <-chan struct{}
}

ServerProcess returns the managed process for lifecycle control.

type CodexEvent

type CodexEvent struct {
	Method   string
	Params   json.RawMessage
	ThreadID string
	TurnID   string
	ItemID   string
	Delta    string
	Message  string
	Status   string
}

CodexEvent is a parsed notification from the Codex app-server.

type MessageInfo

type MessageInfo struct {
	ID   string `json:"id"`
	Role string `json:"role"`
}

type MessageResponse

type MessageResponse struct {
	Info  MessageInfo `json:"info"`
	Parts []Part      `json:"parts"`
}

type Model

type Model struct {
	ID         string `json:"id"`
	ProviderID string `json:"providerID"`
	Name       string `json:"name"`
	Status     string `json:"status"`
}

type ModelRef

type ModelRef struct {
	ID         string `json:"id"`
	ProviderID string `json:"providerID"`
	Variant    string `json:"variant"`
}

type Part

type Part struct {
	Type string `json:"type"`
	Text string `json:"text,omitempty"`
}

type Provider

type Provider struct {
	ID     string           `json:"id"`
	Name   string           `json:"name"`
	Models map[string]Model `json:"models"`
}

type QuestionInfo

type QuestionInfo struct {
	Question string `json:"question"`
	Header   string `json:"header"`
	Custom   *bool  `json:"custom,omitempty"`
}

type QuestionRequest

type QuestionRequest struct {
	ID        string         `json:"id"`
	SessionID string         `json:"sessionID"`
	Questions []QuestionInfo `json:"questions"`
}

type Session

type Session struct {
	ID        string      `json:"id"`
	Title     string      `json:"title"`
	Directory string      `json:"directory"`
	Model     *ModelRef   `json:"model"`
	Time      SessionTime `json:"time"`
}

type SessionTime

type SessionTime struct {
	Created int64 `json:"created"`
	Updated int64 `json:"updated"`
}

type StreamEvent

type StreamEvent struct {
	Text     string
	Question *QuestionRequest
}

type UserInputEvent

type UserInputEvent struct {
	ID     int64
	Params json.RawMessage
}

UserInputEvent is emitted when the app-server asks for user input via item/tool/requestUserInput.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL