codex

package
v3.16.10 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2026 License: Apache-2.0 Imports: 38 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrBridgeUnavailable = errors.New("codex bridge websocket is not connected")
	ErrBridgeClosed      = errors.New("codex bridge websocket closed")
)

Functions

func SessionIDFromContext

func SessionIDFromContext(ctx context.Context) string

SessionIDFromContext returns the session id authenticated for an MCP HTTP request.

Types

type AppServerProxyHandler

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

func NewAppServerProxyHandler

func NewAppServerProxyHandler(processManager proxyProcessManager, tokenManager proxyTokenManager, auth *iam.AuthContext) (*AppServerProxyHandler, error)

func (*AppServerProxyHandler) ServeHTTP

type ChatKitAdapter

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

func NewChatKitAdapter

func NewChatKitAdapter(opts ChatKitAdapterOptions) *ChatKitAdapter

func (*ChatKitAdapter) Handle

func (h *ChatKitAdapter) Handle(w http.ResponseWriter, r *http.Request)

func (*ChatKitAdapter) PrepareSessionToken

func (h *ChatKitAdapter) PrepareSessionToken(ctx context.Context, _ string) (string, error)

PrepareSessionToken returns the long-lived MCP token used by the managed codex app-server.

type ChatKitAdapterOptions

type ChatKitAdapterOptions struct {
	Fallback       http.Handler
	ProcessManager codexProcessManager
	TokenManager   *SessionTokenManager
}

type Client

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

Client is a minimal JSON-RPC 2.0 client over io.Reader/io.Writer. It serializes calls to preserve request/response ordering on plain stdio streams.

func NewClient

func NewClient(reader io.Reader, writer io.Writer) *Client

func (*Client) Call

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

func (*Client) CallUntil

func (c *Client) CallUntil(
	ctx context.Context,
	method string,
	params any,
	result any,
	onNotification func(jsonRPCNotification) error,
	isDone func() bool,
) error

func (*Client) Notify

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

type ExecuteApprovalHTTPHandler

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

func NewExecuteApprovalHTTPHandler

func NewExecuteApprovalHTTPHandler(manager *ExecuteApprovalManager) *ExecuteApprovalHTTPHandler

func (*ExecuteApprovalHTTPHandler) ServeHTTP

type ExecuteApprovalManager

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

func NewExecuteApprovalManager

func NewExecuteApprovalManager(ttl time.Duration) *ExecuteApprovalManager

func (*ExecuteApprovalManager) Approve

func (m *ExecuteApprovalManager) Approve(sessionID string, refIDs []string) error

func (*ExecuteApprovalManager) ListPending

func (m *ExecuteApprovalManager) ListPending(sessionID string) []PendingExecuteApproval

func (*ExecuteApprovalManager) RequireApproval

func (m *ExecuteApprovalManager) RequireApproval(sessionID string, refIDs []string) error

type NotebookMCPBridge

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

func NewNotebookMCPBridge

func NewNotebookMCPBridge(bridge bridgeCaller) *NotebookMCPBridge

func (*NotebookMCPBridge) NewServer

func (b *NotebookMCPBridge) NewServer() *mcpserver.MCPServer

func (*NotebookMCPBridge) SetCallTimeout

func (b *NotebookMCPBridge) SetCallTimeout(timeout time.Duration)

func (*NotebookMCPBridge) SetExecuteApprover

func (b *NotebookMCPBridge) SetExecuteApprover(approver executeApprover)

type PendingExecuteApproval

type PendingExecuteApproval struct {
	SessionID string    `json:"session_id"`
	RefIDs    []string  `json:"ref_ids"`
	CreatedAt time.Time `json:"created_at"`
}

type ProcessManager

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

func NewProcessManager

func NewProcessManager(command string, args []string, env []string) *ProcessManager

func (*ProcessManager) CallRaw

func (p *ProcessManager) CallRaw(
	ctx context.Context,
	method string,
	params any,
	onNotification func(jsonRPCNotification) error,
) (json.RawMessage, error)

func (*ProcessManager) ConfigureSession

func (p *ProcessManager) ConfigureSession(ctx context.Context, cfg SessionConfig) error

func (*ProcessManager) EnsureStarted

func (p *ProcessManager) EnsureStarted(ctx context.Context) error

func (*ProcessManager) InitializeResult

func (p *ProcessManager) InitializeResult() json.RawMessage

func (*ProcessManager) Interrupt

func (p *ProcessManager) Interrupt(ctx context.Context, sessionID, threadID string) error

func (*ProcessManager) MarshalSessionConfig

func (p *ProcessManager) MarshalSessionConfig(cfg SessionConfig) ([]byte, error)

func (*ProcessManager) RunTurn

func (p *ProcessManager) RunTurn(ctx context.Context, req TurnRequest) (*TurnResponse, error)

func (*ProcessManager) StdIO

func (*ProcessManager) Stop

func (p *ProcessManager) Stop(ctx context.Context) error

type SessionConfig

type SessionConfig struct {
	SessionID    string
	MCPServerURL string
	BearerToken  string
}

type SessionTokenManager

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

SessionTokenManager mints and validates MCP bearer tokens for a codex app-server instance. The same token is reused across requests so Codex does not need token refresh or per-thread auth state.

func NewSessionTokenManager

func NewSessionTokenManager(ttl time.Duration) *SessionTokenManager

func (*SessionTokenManager) Issue

func (m *SessionTokenManager) Issue() (string, error)

func (*SessionTokenManager) Validate

func (m *SessionTokenManager) Validate(token string) (string, error)

type StreamableMCPHandler

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

func NewStreamableMCPHandler

func NewStreamableMCPHandler(bridge *ToolBridge, tokens *SessionTokenManager, approvals *ExecuteApprovalManager) (*StreamableMCPHandler, error)

func (*StreamableMCPHandler) ServeHTTP

func (h *StreamableMCPHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type ToolBridge

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

func NewToolBridge

func NewToolBridge(auth *iam.AuthContext) *ToolBridge

func (*ToolBridge) Call

Call dispatches a notebook tool call request over the active websocket and waits for the response.

func (*ToolBridge) HandleWebsocket

func (b *ToolBridge) HandleWebsocket(w http.ResponseWriter, r *http.Request)

HandleWebsocket upgrades and handles the singleton codex bridge websocket.

func (*ToolBridge) Shutdown

func (b *ToolBridge) Shutdown()

Shutdown closes the active websocket connection and fails all pending tool calls.

type TurnEvent

type TurnEvent struct {
	Type       string `json:"type,omitempty"`
	ItemID     string `json:"item_id,omitempty"`
	Text       string `json:"text,omitempty"`
	Icon       string `json:"icon,omitempty"`
	Code       string `json:"code,omitempty"`
	Message    string `json:"message,omitempty"`
	AllowRetry bool   `json:"allow_retry,omitempty"`
}

type TurnRequest

type TurnRequest struct {
	SessionID          string
	ThreadID           string
	PreviousResponseID string
	Input              *chatkit.UserMessageInput
	ToolOutput         *toolsv1.ToolCallOutput
}

type TurnResponse

type TurnResponse struct {
	ThreadID           string      `json:"thread_id,omitempty"`
	PreviousResponseID string      `json:"previous_response_id,omitempty"`
	Events             []TurnEvent `json:"events,omitempty"`
}

Jump to

Keyboard shortcuts

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