codex

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package codex implements the Runner-side adapter for `codex app-server`. The adapter deliberately keeps the wire objects as JSON: Codex publishes a versioned schema and may add notification fields without requiring a Runner release. Only the stable identifiers needed by AgentRelay are typed here.

Index

Constants

View Source
const DefaultBinary = "codex"

Variables

This section is empty.

Functions

func Authenticated

func Authenticated(ctx context.Context, binary string) (bool, error)

Authenticated asks Codex CLI whether the local user has completed sign-in. It intentionally relies on the CLI status command instead of reading ~/.codex/auth.json, so AgentRelay never handles OpenAI credentials.

func Version

func Version(ctx context.Context, binary string) (string, error)

Types

type AccountUsageResult

type AccountUsageResult struct {
	Summary AccountUsageSummary `json:"summary"`
}

type AccountUsageSummary

type AccountUsageSummary struct {
	LifetimeTokens        *int64 `json:"lifetimeTokens"`
	PeakDailyTokens       *int64 `json:"peakDailyTokens"`
	CurrentStreakDays     *int64 `json:"currentStreakDays"`
	LongestStreakDays     *int64 `json:"longestStreakDays"`
	LongestRunningTurnSec *int64 `json:"longestRunningTurnSec"`
}

type Client

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

func Start

func Start(ctx context.Context, binary string, handlers Handlers) (*Client, error)

Start launches one long-lived app-server process. Codex owns authentication and model configuration on the Runner host; AgentRelay never receives those credentials.

func (*Client) Call

func (c *Client) Call(ctx context.Context, method string, params any, target any) error

func (*Client) Close

func (c *Client) Close() error

func (*Client) CompactThread

func (c *Client) CompactThread(ctx context.Context, threadID string) error

func (*Client) Done

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

func (*Client) GetAccountUsage

func (c *Client) GetAccountUsage(ctx context.Context) (AccountUsageResult, error)

func (*Client) GetRateLimits

func (c *Client) GetRateLimits(ctx context.Context) (RateLimitsResult, error)

func (*Client) InterruptTurn

func (c *Client) InterruptTurn(ctx context.Context, threadID, turnID string) error

func (*Client) ListModels

func (c *Client) ListModels(ctx context.Context) (ModelListResult, error)

func (*Client) Notify

func (c *Client) Notify(method string, params any) error

func (*Client) Respond

func (c *Client) Respond(id json.RawMessage, result any, responseErr error) error

func (*Client) ResumeThread

func (c *Client) ResumeThread(ctx context.Context, threadID, cwd, model string) error

func (*Client) ResumeThreadState

func (c *Client) ResumeThreadState(ctx context.Context, threadID, cwd, model string) (ThreadResult, error)

func (*Client) ResumeThreadStateWithOptions

func (c *Client) ResumeThreadStateWithOptions(ctx context.Context, threadID, cwd string, options ExecutionOptions) (ThreadResult, error)

func (*Client) ResumeThreadWithOptions

func (c *Client) ResumeThreadWithOptions(ctx context.Context, threadID, cwd string, options ExecutionOptions) error

func (*Client) StartThread

func (c *Client) StartThread(ctx context.Context, cwd, model string) (string, error)

func (*Client) StartThreadWithOptions

func (c *Client) StartThreadWithOptions(ctx context.Context, cwd string, options ExecutionOptions) (string, error)

func (*Client) StartTurn

func (c *Client) StartTurn(ctx context.Context, threadID, message, model string) (string, error)

func (*Client) StartTurnWithInputs

func (c *Client) StartTurnWithInputs(ctx context.Context, threadID string, input []TurnInput, options ExecutionOptions) (string, error)

func (*Client) StartTurnWithOptions

func (c *Client) StartTurnWithOptions(ctx context.Context, threadID, message string, options ExecutionOptions) (string, error)

func (*Client) SteerTurn

func (c *Client) SteerTurn(ctx context.Context, threadID, turnID, message string) error

func (*Client) SteerTurnWithInputs

func (c *Client) SteerTurnWithInputs(ctx context.Context, threadID, turnID string, input []TurnInput) error

type CreditsSnapshot

type CreditsSnapshot struct {
	Balance    *string `json:"balance"`
	HasCredits bool    `json:"hasCredits"`
	Unlimited  bool    `json:"unlimited"`
}

type ExecutionOptions

type ExecutionOptions struct {
	Model             string
	ReasoningEffort   string
	ServiceTier       string
	CollaborationMode string
	PermissionMode    string
}

ExecutionOptions are the user-visible Codex controls advertised by the local App Server. Empty values intentionally defer to the local Codex defaults instead of inventing cloud-side defaults.

type Handlers

type Handlers struct {
	Notification func(Notification)
	Request      func(ServerRequest)
	Stderr       func(string)
	Exit         func(error)
}

type Model

type Model struct {
	ID                        string                  `json:"id"`
	Model                     string                  `json:"model"`
	DisplayName               string                  `json:"displayName"`
	Description               string                  `json:"description"`
	IsDefault                 bool                    `json:"isDefault"`
	Hidden                    bool                    `json:"hidden"`
	DefaultReasoningEffort    string                  `json:"defaultReasoningEffort"`
	SupportedReasoningEfforts []ReasoningEffortOption `json:"supportedReasoningEfforts"`
	DefaultServiceTier        *string                 `json:"defaultServiceTier"`
	ServiceTiers              []ServiceTierOption     `json:"serviceTiers"`
}

type ModelListResult

type ModelListResult struct {
	Data       []Model `json:"data"`
	NextCursor *string `json:"nextCursor"`
}

type Notification

type Notification struct {
	Method string          `json:"method"`
	Params json.RawMessage `json:"params,omitempty"`
}

type RateLimitSnapshot

type RateLimitSnapshot struct {
	LimitID   *string          `json:"limitId"`
	LimitName *string          `json:"limitName"`
	PlanType  *string          `json:"planType"`
	Primary   *RateLimitWindow `json:"primary"`
	Secondary *RateLimitWindow `json:"secondary"`
	Credits   *CreditsSnapshot `json:"credits"`
}

type RateLimitWindow

type RateLimitWindow struct {
	UsedPercent        int    `json:"usedPercent"`
	ResetsAt           *int64 `json:"resetsAt"`
	WindowDurationMins *int64 `json:"windowDurationMins"`
}

type RateLimitsResult

type RateLimitsResult struct {
	RateLimits          RateLimitSnapshot            `json:"rateLimits"`
	RateLimitsByLimitID map[string]RateLimitSnapshot `json:"rateLimitsByLimitId"`
}

type ReasoningEffortOption

type ReasoningEffortOption struct {
	ReasoningEffort string `json:"reasoningEffort"`
	Description     string `json:"description"`
}

type ServerRequest

type ServerRequest struct {
	ID     json.RawMessage `json:"id"`
	Method string          `json:"method"`
	Params json.RawMessage `json:"params,omitempty"`
}

type ServiceTierOption

type ServiceTierOption struct {
	ID          string `json:"id"`
	Name        string `json:"name"`
	Description string `json:"description"`
}

type ThreadResult

type ThreadResult struct {
	Thread struct {
		ID    string `json:"id"`
		Turns []struct {
			ID     string           `json:"id"`
			Status string           `json:"status"`
			Items  []map[string]any `json:"items"`
			Error  map[string]any   `json:"error"`
		} `json:"turns"`
	} `json:"thread"`
}

type TurnInput

type TurnInput map[string]any

TurnInput mirrors the stable input variants accepted by turn/start. Keeping the payload open lets newer Codex versions add optional fields without a Runner release while the constructors below enforce the variants we emit.

func LocalImageInput

func LocalImageInput(path string) TurnInput

func MentionInput

func MentionInput(name, path string) TurnInput

func TextInput

func TextInput(text string) TurnInput

type TurnResult

type TurnResult struct {
	Turn struct {
		ID string `json:"id"`
	} `json:"turn"`
}

Jump to

Keyboard shortcuts

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