catalog

package
v0.7.2 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: MIT Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package catalog reads the Codex model catalog (GET {base_url}/models, or $CODEX_HOME/models_cache.json read-only) and answers two questions: which models share a compatibility group, and how large a model's usable context window is. Field names follow models_cache.json as fetched by codex 0.162.1.

Index

Constants

View Source
const CacheCheckEvery = 5 * time.Second

CacheCheckEvery is how often a CacheWatch looks at its file at most.

View Source
const CacheFile = "models_cache.json"

CacheFile is Codex's models cache in a Codex home.

View Source
const ToolModeNone = "none"

ToolModeNone is the tool_mode of an entry that has no tool_mode field.

Variables

This section is empty.

Functions

This section is empty.

Types

type CacheWatch added in v0.3.0

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

CacheWatch reloads a models_cache.json into a Store when Codex rewrites it, for a router that sees no /models replies and outlives Codex's model refreshes (the brain).

func NewCacheWatch added in v0.3.0

func NewCacheWatch(path string, store *Store, now func() time.Time) *CacheWatch

NewCacheWatch watches the cache at path for store; a nil now is time.Now.

func (*CacheWatch) Check added in v0.3.0

func (w *CacheWatch) Check() (reloaded bool, err error)

Check looks at the file, at most once per CacheCheckEvery, and when its modification time or size changed loads it into the store. A missing file changes nothing. A file that does not read or parse keeps the last catalog and is tried again once it changes. reloaded reports a new catalog.

type Catalog

type Catalog struct {
	Models map[string]Model
}

Catalog is a parsed /models body.

func LoadCache

func LoadCache(path string) (Catalog, error)

LoadCache reads a models_cache.json. A missing file yields an empty catalog, not an error. The file is never written.

func Parse

func Parse(body []byte) (Catalog, error)

Parse decodes a /models response body.

func (Catalog) Compatible

func (c Catalog) Compatible(a, b string) bool

Compatible reports whether both models are known and share a Group.

func (Catalog) GroupOf

func (c Catalog) GroupOf(slug string) (Group, bool)

GroupOf returns the compatibility group of slug.

func (Catalog) Window

func (c Catalog) Window(slug string) (int, bool)

Window is the usable context in tokens: context_window x percent / 100. A missing model, or a non-positive window or percent, is unknown.

type Group

type Group struct {
	CompHash string `json:"CompHash"`
	Lite     bool   `json:"Lite"`
	ToolMode string `json:"ToolMode"`
}

Group is the compatibility key: a per-step rewrite is safe only between models with an equal Group (research §1.2, spikes 3-5). A Snapshot carries it on the control wire, so its JSON names are spelled out and pinned by internal/control's protocol-v2 fixtures.

type Model

type Model struct {
	Slug             string           `json:"slug"`
	Visibility       string           `json:"visibility"`
	ContextWindow    int              `json:"context_window"`
	MaxContextWindow int              `json:"max_context_window"`
	EffectivePercent int              `json:"effective_context_window_percent"`
	CompHash         string           `json:"comp_hash"`
	ResponsesLite    bool             `json:"use_responses_lite"`
	ToolMode         string           `json:"tool_mode"`
	ReasoningLevels  []ReasoningLevel `json:"supported_reasoning_levels"`
	// DefaultEffort is the effort Codex runs the model at when its settings
	// name none.
	DefaultEffort config.Effort `json:"default_reasoning_level"`
}

Model is one catalog entry. Only the fields the router reads are decoded.

func (*Model) UnmarshalJSON

func (m *Model) UnmarshalJSON(b []byte) error

UnmarshalJSON applies Codex's default for an absent effective_context_window_percent; an explicit 0 stays 0.

type ReasoningLevel

type ReasoningLevel struct {
	Effort config.Effort `json:"effort"`
}

ReasoningLevel is one entry of supported_reasoning_levels.

type Source

type Source interface {
	Current() Catalog
}

Source is what consumers read the current catalog through.

type Store

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

Store holds the current catalog for concurrent readers and writers.

func (*Store) Current

func (s *Store) Current() Catalog

Current returns the latest catalog; the zero Catalog before the first Set.

func (*Store) Set

func (s *Store) Set(c Catalog)

Set replaces the catalog.

Jump to

Keyboard shortcuts

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