codexsdk

package module
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2026 License: MIT Imports: 19 Imported by: 0

README

codexsdk

Go client and generated protocol types for the Codex app-server JSON-RPC protocol.

The module path is github.com/ronhuafeng/llm-go/codexsdk. Its verified first monorepo release is codexsdk/v0.6.0, continuing the legacy SDK's pre-v1 lineage. The GitHub Release and public Go proxy are the live availability and verification sources. Consumers of github.com/ronhuafeng/codexsdk-go@v0.5.1 should follow the v0.6 migration guide. The migration changes only module and import paths; it adds no forwarding or runtime compatibility layer.

This project is unofficial and experimental. It is not an OpenAI product, is not supported by OpenAI, and may lag or diverge from the Codex CLI/app-server implementation. Use it when you want a small Go SDK that talks to a locally launched Codex app-server over stdio.

Status

  • License: MIT for this repository.
  • Upstream protocol source: OpenAI Codex, Apache-2.0, generated from the app-server schema baseline recorded in internal/protocolschema/appserver/v2/baseline_metadata.json.
  • API stability: pre-1.0. Public APIs are intended to be useful and reviewed, but breaking changes can happen before v1.0.
  • Final legacy release: github.com/ronhuafeng/codexsdk-go@v0.5.1.
  • Runtime requirement: the SDK launches an external codex app-server command. Unit tests and CI do not require a local Codex binary.

The pre-v1 API uses a concrete root client, exported concrete opaque generated facades, consumer-owned narrow interfaces, and manifest-classified stable versus experimental generated compatibility. See Pre-v1 Public API Boundary. For the concrete generated-facade migration, see the v0.4 migration guide. For the unified malformed lifecycle partial-evidence contract, see the v0.5 migration guide.

Packages

  • codexsdk: stdio client, generated typed facades, exact ThreadRunner, exact notification streaming, and generated server-request handling.
  • protocolv2: generated app-server v2 params, responses, notifications, enums, unions, JSON helpers, and method registry.
  • internal/protocolgen: generator internals for the checked-in schema baseline.
  • internal/protocolschema/appserver/v2: reviewed schema baseline, classified manifest, coverage matrix, drift report, and provenance metadata.

Inbound app-server JSON-RPC frames are limited to 16 MiB, including the newline delimiter. Oversized or unterminated frames fail the Root Client with sanitized byte-count and hash diagnostics; outbound messages are not subject to this internal transport limit.

Installation

Install the verified replacement release with:

go get github.com/ronhuafeng/llm-go/codexsdk@v0.6.0

The module targets Go 1.23 or newer.

To run against a real app-server, install Codex CLI separately and make sure codex is on PATH:

codex --version

Quick Start: Typed Client

package main

import (
	"context"
	"log"
	"os"

	"github.com/ronhuafeng/llm-go/codexsdk"
	"github.com/ronhuafeng/llm-go/codexsdk/protocolv2"
)

func main() {
	ctx := context.Background()
	workspace, err := os.Getwd()
	if err != nil {
		log.Fatal(err)
	}

	client, err := codexsdk.New(codexsdk.ClientOptions{
		CWD:     workspace,
		Command: []string{"codex", "app-server", "--listen", "stdio://"},
	})
	if err != nil {
		log.Fatal(err)
	}
	defer client.Close()

	resp, err := client.Models().List(ctx, protocolv2.ModelListParams{})
	if err != nil {
		log.Fatal(err)
	}
	log.Printf("models: %d", len(resp.Data))
}

Quick Start: Exact ThreadRunner

ThreadRunner transparently composes exact generated thread/start and turn/start params. The result retains the exact start response, terminal turn, usage, and every attributable generated notification.

A successfully decoded lifecycle response remains observable as partial evidence even when a required thread or turn identity is missing. In that case, the simple operation returns the decoded facts with ErrMissingThreadID or ErrMissingTurnID; the streaming operation returns a non-nil terminal stream whose Wait, Result, and Err expose the same facts and cause. Identity failure prevents later lifecycle requests or live run registration without closing the Client. See the v0.5 migration guide.

package main

import (
	"context"
	"log"
	"os"

	"github.com/ronhuafeng/llm-go/codexsdk"
	"github.com/ronhuafeng/llm-go/codexsdk/protocolv2"
)

func main() {
	ctx := context.Background()
	workspace, err := os.Getwd()
	if err != nil {
		log.Fatal(err)
	}
	model := os.Getenv("CODEXSDK_EXAMPLE_MODEL")
	if model == "" {
		log.Fatal("set CODEXSDK_EXAMPLE_MODEL")
	}

	root, err := codexsdk.New(codexsdk.ClientOptions{
		CWD:     workspace,
		Command: []string{"codex", "app-server", "--listen", "stdio://"},
	})
	if err != nil {
		log.Fatal(err)
	}
	defer root.Close()

	result, err := root.ThreadRunner().Start(ctx, codexsdk.StartThreadRunRequest{
		Thread: protocolv2.ThreadStartParams{
			Ephemeral: protocolv2.Value(true),
			Model:     protocolv2.Value(model),
		},
		Turn: protocolv2.TurnStartParams{
			Input: []protocolv2.UserInput{
				protocolv2.NewUserInputText(protocolv2.UserInputText{
					Text: "Reply with a short confirmation.",
				}),
			},
		},
	})
	if err != nil {
		log.Fatal(err)
	}
	log.Println(result.Run.FinalResponse)
}

StartStream and ResumeStream expose every exact protocolv2.ServerNotification; Result remains available on failures and contains the latest immutable partial snapshot. More compile-checked examples live in examples_test.go.

Call Stream.Wait when multiple consumers need to observe the same run without coordinating ownership of Next. Any number of waiters can block independently and each receives an immutable result snapshot plus the run's stable terminal error. A waiter's context bounds only that call: cancellation returns the latest partial snapshot with ctx.Err() without canceling the run or changing Stream.Err. Use Stream.Close for explicit shared run cancellation. Next uses a cursor over the same immutable ordered history retained by Result, so Wait does not need to consume notifications and cannot cause per-run backpressure. Next context cancellation retains its shared-run cancellation semantics. The separately configurable global notification-handler queue remains bounded.

For one thread, only one Exact Run may be waiting for turn/start to return its turn identity. An overlapping start fails before sending another turn/start. Once the first turn identity is attached, later turns on the same thread may start without waiting for the earlier live turn to finish.

Configure ServerRequestHandler when the application can provide generated response data. With no handler, the SDK immediately returns a generated fail-closed response for requests that have a safe denial or empty-answer form. Requests requiring application data, including authentication refresh, dynamic tool output, and attestation, return a JSON-RPC error and fail the exact run with ErrExactServerRequest; partial notifications and run evidence remain available in the result.

Callback admission is atomic with client shutdown. Once Close or failure shutdown closes admission, no new server-request or notification handler is started. Normal close cancels exact server-request handler contexts and joins every callback accepted before that boundary before transport teardown; failure shutdown cancels accepted callbacks immediately while preserving the first failure cause and partial run evidence. Handlers must return when their context is canceled and must not call Close reentrantly.

The removed v0.1 lifecycle and copied protocol models have no compatibility aliases. See the migration mapping for exact replacements.

Real App-Server Smoke Test

The real smoke test is opt-in because it launches Codex, uses a configured model, and may create or consume account state.

CODEXSDK_REAL_APP_SERVER_SMOKE=1 \
CODEXSDK_REAL_APP_SERVER_MODEL=gpt-5-mini \
go test . -run TestRealAppServerSmokeStartResumeFork -count=1

Optional command override:

CODEXSDK_REAL_APP_SERVER_COMMAND='codex app-server --listen stdio://' \
CODEXSDK_REAL_APP_SERVER_SMOKE=1 \
CODEXSDK_REAL_APP_SERVER_MODEL=gpt-5-mini \
go test . -run TestRealAppServerSmokeStartResumeFork -count=1

Normal CI does not run this test.

Protocol V2 Schema Strategy

protocolv2 code is generated from a checked-in Codex app-server v2 schema baseline, not by shelling out to Codex during normal builds. The baseline is tracked with:

  • baseline_metadata.json: upstream tag/ref name, target kind, peeled commit, Codex version, generation command, source license, file count, and schema bundle checksum.
  • manifest.json: classified method and exported generated Go surface, request/notification direction, response schema mapping, facade target, explicit generated/deferred facade status, and mechanically derived stable, experimental, or mixed marking. A deferred facade is valid only while a generated method constant or protocol type prerequisite is absent.
  • coverage_matrix.json: reviewed support status for methods, types, and key fields.
  • drift_report.json and matrix_update_skeleton.json: last clean comparison artifacts and the shape of follow-up review work when upstream changes.

Regenerate Go code from the checked-in baseline:

go run ./internal/cmd/protocolv2gen

Check generated code reproducibility without modifying the tree:

go run ./internal/cmd/protocolv2gen -stdout method-registry |
  diff -u protocolv2/method_registry.gen.go -
go run ./internal/cmd/protocolv2gen -stdout protocol-types |
  diff -u protocolv2/protocol_types.gen.go -
tmp="$(mktemp -d)/sdk_surface.gen.go"
python3 scripts/codexsdk_generate_sdk_surface.py --out "$tmp"
gofmt -w "$tmp"
diff -u sdk_surface.gen.go "$tmp"

Maintenance

Use the upstream tracking script to generate review artifacts for a Codex schema update. The script is read-only for the checked-in baseline unless a maintainer copies reviewed files back into the SDK tree.

Check the target policy before generating drift artifacts. Scheduled automation tracks stable rust-vX.Y.Z tags only when the current baseline is already on that stable tag track; manual commits and track switches must be explicit.

python3 scripts/codexsdk_target_policy.py \
  --baseline internal/protocolschema/appserver/v2/baseline_metadata.json \
  --target-ref rust-v0.140.0 \
  --target-kind stable_rust_tag \
  --target-sha <peeled-target-commit> \
  --target-explicit true \
  --mode manual \
  --json
scripts/codexsdk_track_upstream.sh \
  --codex-repo /path/to/openai/codex \
  --commit <peeled-target-commit> \
  --source-ref rust-v0.140.0 \
  --source-ref-kind stable_rust_tag \
  --out /tmp/codexsdk-upstream

Then review the generated reports/SUMMARY.md, schema drift summary, and matrix update skeleton before updating the baseline, manifest, coverage matrix, and generated Go code. Keep handwritten SDK changes limited to reviewed public surface or compatibility fixes. See docs/release.md for the release and schema baseline checklists.

After committing a successful baseline sync, tag the repository commit with an annotated upstream sync tag. These tags intentionally live outside the Go module release namespace.

python3 scripts/codexsdk_sync_tag.py --json
python3 scripts/codexsdk_sync_tag.py --create --push origin --json

Stable upstream Codex tags use upstream-codex-rust-vX.Y.Z. Existing upstream sync tags are never moved; use --next-suffix to create upstream-codex-rust-vX.Y.Z-sync.N for follow-up SDK fixes against the same upstream tag. Manual upstream commits and refs intentionally do not get fallback sync tags.

Compatibility Policy

Before v1.0, minor releases may include breaking changes when the upstream Codex app-server protocol changes or when the SDK corrects an unsafe public API. Patch releases should be backwards compatible except for security or data corruption fixes.

After v1.0, the project should follow SemVer for the public API at the module root and in protocolv2. Generated protocolv2 additions are usually minor changes. Removing or changing generated types, method constants, or facade method signatures is a major change unless the upstream protocol removed the surface and compatibility cannot be preserved safely.

Security

Do not put API keys, account tokens, private workspaces, private schema dumps, or local absolute paths into issues, tests, schema metadata, or generated artifacts. The SDK starts a local app-server process and forwards requests over stdio; callers are responsible for choosing an appropriate Codex command, working directory, approval policy, and server request handler.

See SECURITY.md for vulnerability reporting guidance.

Documentation

Overview

Package codexsdk provides a concrete Client for interacting with a Codex app-server. New returns the only connected form, *Client. The safe, inert zero value closes successfully and returns ErrClientClosed from operations. Generated facade accessors return exported concrete opaque values. Consumers should define narrow interfaces around only the operations they use.

Client owns process transport, client lifecycle, generated protocol facades, exact thread/turn composition, and typed callback delivery. Exact run notifications retain ingestion order across stream attachment: pending notifications are accepted before later live notifications for the same run. A successfully decoded lifecycle response remains observable as exact partial evidence when a required thread or turn identity is missing. ErrMissingThreadID and ErrMissingTurnID fail closed before the next lifecycle stage or live run registration; these malformed responses do not close the Client. Exact run results retain complete immutable notification history independent of observation. Wait observes completion without consuming notifications; Next advances a cursor over the same ordered history. The configurable global notification-handler queue remains bounded, and its overflow closes the client with ErrNotificationBackpressure. Exact run history follows generated-schema identity: turn-scoped facts attach only to the matching turn; thread-scoped facts attach to every run currently active or attaching for that thread and are not retained for a later run; client/global facts never enter per-run evidence. Every validated generated notification is still enqueued for the global handler, in ingestion order, after its justified per-run append completes. A terminal exact notification cannot complete its affected stream until that notification's global handler invocation has returned and any handler failure is published as the client first cause. If shutdown, failure, or bounded backpressure rejects handler work before queue ownership transfers, its dispatch fence is released as discarded without removing already accepted exact-run evidence. Exact server-request failures likewise close callback admission and publish their typed first cause to active runs before the fail-closed protocol response can prompt a terminal notification; transport teardown starts only after that response is written. Client shutdown atomically closes callback admission and joins callbacks accepted before that boundary before releasing transport resources.

It does not provide provider-neutral LLM abstractions, business validation, workflow policy, or application safety profiles.

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	ErrClientClosed             = errors.New("codexsdk: client closed")
	ErrStreamClosed             = errors.New("codexsdk: stream closed")
	ErrTurnFailed               = errors.New("codexsdk: turn failed")
	ErrTurnInterrupted          = errors.New("codexsdk: turn interrupted")
	ErrNotificationBackpressure = errors.New("codexsdk: notification backpressure")
	ErrHandlerFailed            = errors.New("codexsdk: handler failed")
	ErrExactServerRequest       = errors.New("codexsdk: exact server request failed closed")
	ErrMissingThreadID          = errors.New("codexsdk: thread response missing thread id")
	ErrMissingTurnID            = errors.New("codexsdk: turn response missing turn id")
)

Functions

This section is empty.

Types

type Accounts

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

Accounts is an opaque generated facade for exact Codex operations.

func (Accounts) Logout

func (Accounts) RateLimitsRead

func (Accounts) WorkspaceMessagesRead

func (f Accounts) WorkspaceMessagesRead(ctx context.Context) (protocolv2.GetWorkspaceMessagesResponse, error)

type Apps

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

Apps is an opaque generated facade for exact Codex operations.

func (Apps) List

type Client

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

Client owns one Codex app-server process and its transport, callbacks, and exact generated protocol facades. Construct connected clients with New. The zero value is safe but inert.

func New

func New(options ClientOptions) (*Client, error)

func (*Client) Accounts

func (c *Client) Accounts() Accounts

func (*Client) Apps

func (c *Client) Apps() Apps

func (*Client) Close

func (c *Client) Close() error

func (*Client) CollaborationModes

func (c *Client) CollaborationModes() CollaborationModes

func (*Client) Commands

func (c *Client) Commands() Commands

func (*Client) Config

func (c *Client) Config() Config

func (*Client) ConfigRequirements

func (c *Client) ConfigRequirements() ConfigRequirements

func (*Client) Environments

func (c *Client) Environments() Environments

func (*Client) ExperimentalFeatures

func (c *Client) ExperimentalFeatures() ExperimentalFeatures

func (*Client) ExternalAgentConfigs

func (c *Client) ExternalAgentConfigs() ExternalAgentConfigs

func (*Client) FS

func (c *Client) FS() FS

func (*Client) Feedback

func (c *Client) Feedback() Feedback

func (*Client) FuzzyFileSearch

func (c *Client) FuzzyFileSearch() FuzzyFileSearch

func (*Client) Hooks

func (c *Client) Hooks() Hooks

func (*Client) MCPServerStatus

func (c *Client) MCPServerStatus() MCPServerStatus

func (*Client) MCPServers

func (c *Client) MCPServers() MCPServers

func (*Client) Marketplace

func (c *Client) Marketplace() Marketplace

func (*Client) Memory

func (c *Client) Memory() Memory

func (*Client) Mock

func (c *Client) Mock() Mock

func (*Client) ModelProviders

func (c *Client) ModelProviders() ModelProviders

func (*Client) Models

func (c *Client) Models() Models

func (*Client) Plugins

func (c *Client) Plugins() Plugins

func (*Client) Processes

func (c *Client) Processes() Processes

func (*Client) RemoteControl

func (c *Client) RemoteControl() RemoteControl

func (*Client) Reviews

func (c *Client) Reviews() Reviews

func (*Client) Skills

func (c *Client) Skills() Skills

func (*Client) ThreadRunner

func (c *Client) ThreadRunner() ThreadRunner

func (*Client) Threads

func (c *Client) Threads() Threads

func (*Client) Turns

func (c *Client) Turns() Turns

func (*Client) WindowsSandbox

func (c *Client) WindowsSandbox() WindowsSandbox

type ClientOptions

type ClientOptions struct {
	CWD                       string
	Command                   []string
	Initialize                protocolv2.InitializeParams
	ServerRequestHandler      ServerRequestHandler
	ServerNotificationHandler ServerNotificationHandler
	NotificationQueueCapacity int
}

type CollaborationModes

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

CollaborationModes is an opaque generated facade for exact Codex operations.

type Commands

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

Commands is an opaque generated facade for exact Codex operations.

type Config

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

Config is an opaque generated facade for exact Codex operations.

func (Config) MCPServerReload

func (f Config) MCPServerReload(ctx context.Context) (protocolv2.McpServerRefreshResponse, error)

type ConfigRequirements

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

ConfigRequirements is an opaque generated facade for exact Codex operations.

func (ConfigRequirements) Read

type DiagnosticRef

type DiagnosticRef struct {
	Kind      string
	ID        string
	Path      string
	SizeBytes int64
	SHA256    string
}

type Environments

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

Environments is an opaque generated facade for exact Codex operations.

type ExactServerRequestError

type ExactServerRequestError struct {
	Kind   protocolv2.ServerRequestKind
	Reason string
}

func (*ExactServerRequestError) Error

func (e *ExactServerRequestError) Error() string

func (*ExactServerRequestError) Unwrap

func (e *ExactServerRequestError) Unwrap() error

type ExperimentalFeatures

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

ExperimentalFeatures is an opaque generated facade for exact Codex operations.

type ExternalAgentConfigs

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

ExternalAgentConfigs is an opaque generated facade for exact Codex operations.

type FS

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

FS is an opaque generated facade for exact Codex operations.

func (FS) Copy

func (FS) Remove

func (FS) Watch

type Feedback

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

Feedback is an opaque generated facade for exact Codex operations.

type FuzzyFileSearch

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

FuzzyFileSearch is an opaque generated facade for exact Codex operations.

type Hooks

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

Hooks is an opaque generated facade for exact Codex operations.

type InputStats

type InputStats struct {
	ItemsCount      int
	TextBytes       int
	AttachmentCount int
	InputItemsHash  string
}

type MCPServerStatus

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

MCPServerStatus is an opaque generated facade for exact Codex operations.

type MCPServers

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

MCPServers is an opaque generated facade for exact Codex operations.

type Marketplace

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

Marketplace is an opaque generated facade for exact Codex operations.

type Memory

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

Memory is an opaque generated facade for exact Codex operations.

func (Memory) Reset

type Mock

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

Mock is an opaque generated facade for exact Codex operations.

type ModelProviders

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

ModelProviders is an opaque generated facade for exact Codex operations.

type Models

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

Models is an opaque generated facade for exact Codex operations.

type Plugins

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

Plugins is an opaque generated facade for exact Codex operations.

type Processes

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

Processes is an opaque generated facade for exact Codex operations.

type ProtocolError

type ProtocolError struct {
	RequestID protocolv2.RequestId
	Method    string
	Code      int64
	Message   string
	Data      *protocolv2.JSONValue
	Err       error
}

func (*ProtocolError) Error

func (e *ProtocolError) Error() string

func (*ProtocolError) Unwrap

func (e *ProtocolError) Unwrap() error

type RemoteControl

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

RemoteControl is an opaque generated facade for exact Codex operations.

func (RemoteControl) Disable

func (RemoteControl) Enable

func (RemoteControl) StatusRead

type ResumeThreadRunRequest

type ResumeThreadRunRequest struct {
	Thread protocolv2.ThreadResumeParams
	Turn   protocolv2.TurnStartParams
}

type ResumedThreadRun

type ResumedThreadRun struct {
	Resume protocolv2.ThreadResumeResponse
	Run    ThreadRunResult
}

type Reviews

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

Reviews is an opaque generated facade for exact Codex operations.

type ServerNotificationHandler

type ServerNotificationHandler func(context.Context, protocolv2.ServerNotification) error

type ServerRequestResponse

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

type Skills

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

Skills is an opaque generated facade for exact Codex operations.

type StartThreadRunRequest

type StartThreadRunRequest struct {
	Thread protocolv2.ThreadStartParams
	Turn   protocolv2.TurnStartParams
}

type StartedThreadRun

type StartedThreadRun struct {
	Start protocolv2.ThreadStartResponse
	Run   ThreadRunResult
}

type Stream

type Stream[R any] struct {
	// contains filtered or unexported fields
}

func (*Stream[R]) Close

func (s *Stream[R]) Close() error

func (*Stream[R]) Err

func (s *Stream[R]) Err() error

func (*Stream[R]) Next

func (s *Stream[R]) Next(ctx context.Context) bool

func (*Stream[R]) Notification

func (s *Stream[R]) Notification() protocolv2.ServerNotification

func (*Stream[R]) Result

func (s *Stream[R]) Result() (R, bool)

func (*Stream[R]) Wait

func (s *Stream[R]) Wait(ctx context.Context) (R, error)

Wait observes run completion without consuming notifications or owning the run lifecycle. Context cancellation stops only this call and returns the latest immutable partial result; use Close to cancel the shared run.

Example
package main

import (
	"context"
	"os"

	"github.com/ronhuafeng/llm-go/codexsdk"
	"github.com/ronhuafeng/llm-go/codexsdk/protocolv2"
)

func main() {
	ctx := context.Background()
	root, err := codexsdk.New(codexsdk.ClientOptions{
		CWD:     os.TempDir(),
		Command: []string{"codex", "app-server", "--listen", "stdio://"},
	})
	if err != nil {
		panic(err)
	}
	defer root.Close()

	stream, err := root.ThreadRunner().StartStream(ctx, codexsdk.StartThreadRunRequest{
		Turn: protocolv2.TurnStartParams{Input: []protocolv2.UserInput{
			protocolv2.NewUserInputText(protocolv2.UserInputText{Text: "Reply briefly."}),
		}},
	})
	if err != nil {
		panic(err)
	}
	defer stream.Close()

	result, err := stream.Wait(ctx)
	if err != nil {
		// Result retains exact evidence accepted before failure.
		panic(err)
	}
	_ = result.Run.Notifications
}

type ThreadRunResult

type ThreadRunResult struct {
	Turn          protocolv2.Turn
	Usage         *protocolv2.ThreadTokenUsage
	Notifications []protocolv2.ServerNotification
	FinalResponse string
	InputStats    InputStats
	Diagnostics   []DiagnosticRef
}

type ThreadRunner

Example (Start)
package main

import (
	"context"
	"os"

	"github.com/ronhuafeng/llm-go/codexsdk"
	"github.com/ronhuafeng/llm-go/codexsdk/protocolv2"
)

func main() {
	ctx := context.Background()
	root, err := codexsdk.New(codexsdk.ClientOptions{
		CWD:     os.TempDir(),
		Command: []string{"codex", "app-server", "--listen", "stdio://"},
	})
	if err != nil {
		panic(err)
	}
	defer root.Close()

	result, err := root.ThreadRunner().Start(ctx, codexsdk.StartThreadRunRequest{
		Thread: protocolv2.ThreadStartParams{Model: protocolv2.Value("gpt-5")},
		Turn: protocolv2.TurnStartParams{Input: []protocolv2.UserInput{
			protocolv2.NewUserInputText(protocolv2.UserInputText{Text: "Reply briefly."}),
		}},
	})
	if err != nil {
		panic(err)
	}
	_ = result.Run.FinalResponse
	_ = result.Run.Notifications
}

type Threads

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

Threads is an opaque generated facade for exact Codex operations.

type TurnError

type TurnError struct {
	ThreadID string
	Turn     protocolv2.Turn
	Err      error
}

func (*TurnError) Error

func (e *TurnError) Error() string

func (*TurnError) Unwrap

func (e *TurnError) Unwrap() error

type Turns

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

Turns is an opaque generated facade for exact Codex operations.

type WindowsSandbox

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

WindowsSandbox is an opaque generated facade for exact Codex operations.

func (WindowsSandbox) Readiness

Directories

Path Synopsis
internal
Package protocolv2 contains generated and handwritten Codex app-server v2 protocol types.
Package protocolv2 contains generated and handwritten Codex app-server v2 protocol types.

Jump to

Keyboard shortcuts

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