Documentation
¶
Index ¶
- Constants
- func CodexAccountResolverForLogin(key string) openai.CodexAccountResolver
- func CompactionModelID(profile config.ProviderProfile, preference string) string
- func CompactionSummarizerFactory(base config.ProviderProfile, preference string, ...) func(context.Context, string) (zeroruntime.Provider, error)
- func ConfiguredTurnSessions(profile config.ProviderProfile, p zeroruntime.Provider, o Options) (zeroruntime.TurnSessionProvider, bool)
- func DefaultTurnSessions(profile config.ProviderProfile, provider zeroruntime.Provider, options Options) zeroruntime.TurnSessionProvider
- func EscalationSwitchers(profile config.ProviderProfile, provider zeroruntime.Provider, ...) (func(context.Context, string) (zeroruntime.Provider, error), ...)
- func New(profile config.ProviderProfile, options Options) (zeroruntime.Provider, error)
- func NewTurnSessionProvider(profile config.ProviderProfile, options Options) (zeroruntime.TurnSessionProvider, error)
- func OAuthLoginForProfile(profile config.ProviderProfile) (providerio.TokenResolver, string)
- func OptimizedTurnSessions(profile config.ProviderProfile, provider zeroruntime.Provider, options Options) (zeroruntime.TurnSessionProvider, bool)
- type Options
- type RuntimeMetadata
Constants ¶
const CompactionModelEnv = "ZERO_COMPACTION_MODEL"
CompactionModelEnv overrides the compaction summarization model.
Variables ¶
This section is empty.
Functions ¶
func CodexAccountResolverForLogin ¶
func CodexAccountResolverForLogin(key string) openai.CodexAccountResolver
CodexAccountResolverForLogin returns the same per-request account resolver used by the runtime provider. Auxiliary Codex requests use this rather than independently selecting or parsing an OAuth login, which could mismatch the bearer selected by oauthLoginForProfile.
func CompactionModelID ¶
func CompactionModelID(profile config.ProviderProfile, preference string) string
CompactionModelID returns the model that compaction summarization calls should use for the given profile, or "" to use the session's main model. preference is the resolved config value (preferences.compactionModel).
func CompactionSummarizerFactory ¶
func CompactionSummarizerFactory(base config.ProviderProfile, preference string, newProvider func(config.ProviderProfile) (zeroruntime.Provider, error)) func(context.Context, string) (zeroruntime.Provider, error)
CompactionSummarizerFactory returns the lazy constructor the agent loop calls for its dedicated compaction summarizer (agent.Options.Summarizer). The compactor passes the main model in force at that moment — on the first paid compaction and again after a mid-run model switch — so the choice tracks escalations: a run that starts on the cheap model gets no dedicated summarizer, and gains one once it escalates to a pricier main model. Returning (nil, nil) means "summarize on the main provider". The factory itself is nil only when no provider builder exists. Shared by the exec and TUI front ends so the selection rules cannot drift between them.
func ConfiguredTurnSessions ¶
func ConfiguredTurnSessions(profile config.ProviderProfile, p zeroruntime.Provider, o Options) (zeroruntime.TurnSessionProvider, bool)
ConfiguredTurnSessions preserves transport selection and wraps the starting session when RPM is configured. Without either feature, the default is nil.
func DefaultTurnSessions ¶
func DefaultTurnSessions(profile config.ProviderProfile, provider zeroruntime.Provider, options Options) zeroruntime.TurnSessionProvider
DefaultTurnSessions wraps an already-built provider in the DEFAULT (no-op) turn-session adapter with the profile's resolved capability projection. It is the non-optimized sibling of OptimizedTurnSessions for callers that still want capabilities populated — e.g. the mid-run model-switch fallback when the switched model is not eligible for the optimized session. Capability resolution failure degrades to an unknown (zero) projection rather than failing the wrap: the default session has no behavior that depends on capabilities, so a swap must never be blocked by a projection error.
func EscalationSwitchers ¶
func EscalationSwitchers( profile config.ProviderProfile, provider zeroruntime.Provider, newProvider func(config.ProviderProfile) (zeroruntime.Provider, error), onSwitch func(modelID string), sessionOptions ...Options, ) ( func(context.Context, string) (zeroruntime.Provider, error), func(context.Context, string) (zeroruntime.TurnSessionProvider, error), )
EscalationSwitchers builds the two mid-run model switchers a run installs when it has opted into escalation.
ONE IMPLEMENTATION, TWO SURFACES. exec grew this first, and the interactive TUI needs the same behaviour rather than a similar one. The part that is easy to get subtly wrong is not the switch, it is the nil handling around it, and a second copy of that would only ever be exercised on one surface.
THE NIL CONTRACTS ARE THE CONTRACT. The agent loop reassigns the provider only when a switcher returns a non-nil one, so a (nil, nil) return means "no swap" and has to leave everything as it was, including whatever the caller tracks through onSwitch. onSwitch therefore fires only on a real swap, and may be nil. An error is reported to the loop, which records a note and continues on the current model.
The session switcher is installed for an optimized start or configured RPM limits. Default-adapter starts retain that transport after escalation. The same limiter wraps switched sessions so switching cannot reset a cap.
func New ¶
func New(profile config.ProviderProfile, options Options) (zeroruntime.Provider, error)
New creates a runtime provider for a resolved provider profile.
func NewTurnSessionProvider ¶
func NewTurnSessionProvider(profile config.ProviderProfile, options Options) (zeroruntime.TurnSessionProvider, error)
NewTurnSessionProvider builds the default TurnSessionProvider for a resolved profile: it constructs the provider exactly as New does, then wraps it with a ProviderCapabilities projection computed from the same model-registry entry New already resolves. The default session's Stream is the provider's StreamCompletion, so runtime behavior is identical to using New directly.
func OAuthLoginForProfile ¶
func OAuthLoginForProfile(profile config.ProviderProfile) (providerio.TokenResolver, string)
OAuthLoginForProfile resolves the OAuth login used by profile once and returns both its bearer resolver and credential-store key. Keeping the key alongside the resolver lets auxiliary requests derive account-scoped headers from the same login that supplies the bearer.
func OptimizedTurnSessions ¶
func OptimizedTurnSessions(profile config.ProviderProfile, provider zeroruntime.Provider, options Options) (zeroruntime.TurnSessionProvider, bool)
OptimizedTurnSessions returns the gated optimized TurnSessionProvider for an already-built provider, or (nil, false) when the gate is off or the profile is ineligible. Callers leave agent Options.TurnSessionProvider nil on false, so the loop's default wrap keeps today's behavior byte-identical.
Eligibility is deliberately narrow: native ChatGPT Responses uses its concrete Codex provider and defaults on with a kill switch; official OpenAI chat-completions keeps its existing opt-in prewarm session. Compatible gateways and foreign provider values always retain the default adapter.
Types ¶
type Options ¶
type Options struct {
ModelRPM *zeroruntime.ModelRPMLimiter
UserAgent string
HTTPClient *http.Client
ModelRegistry *modelregistry.Registry
// OAuthResolver, when set, lets the provider authenticate model calls with an
// OAuth bearer token (preferred over the API key). nil => API-key auth only.
// Applied to the OpenAI, Anthropic, and Google (Gemini) providers.
OAuthResolver providerio.TokenResolver
// OAuthLoginKey is the credential-store key OAuthResolver bound to (empty when
// there is no OAuth login). It is the SAME selection the bearer resolver made,
// resolved ONCE by the caller so the Codex chatgpt-account-id header reads its
// account from the exact login that issued the bearer token — never a second,
// independent lookup that could pick a different login (a backend-rejected
// mismatch).
OAuthLoginKey string
}
Options configures provider construction.
type RuntimeMetadata ¶
type RuntimeMetadata struct {
ProviderKind config.ProviderKind
APIModel string
}
RuntimeMetadata describes the provider identity and concrete API model used after Zero model aliases and provider-kind defaults are resolved.
func ResolveRuntimeMetadata ¶
func ResolveRuntimeMetadata(profile config.ProviderProfile, options Options) (RuntimeMetadata, error)
ResolveRuntimeMetadata returns the provider kind and API model that New would use for a profile, without constructing a network client.