proxyapp

package
v0.7.13 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2026 License: Apache-2.0 Imports: 40 Imported by: 1 module, 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 proxyapp re-exports the handful of internal symbols a host needs to build its own context-guru proxy binary.

WHY THIS EXISTS. cmd/context-guru-proxy is this module's own composition root, and it imports three internal/ packages: buildinfo, logging and modelinfo. (cheapmodel used to be a fourth — see below.) Go forbids importing an internal/ package from another module, so a deployment that needs the standard proxy PLUS its own routes — an enterprise build with SSO, a bespoke activation surface, a private landing page — cannot reuse that root. It has to copy it, and then it owns a 1300-line fork of somebody else's file for ever.

That is what this package removes. It is a FACADE, deliberately: aliases and thin wrappers over the existing internal packages, adding no behaviour and moving no code. Nothing internal is relocated, so all ~70 files that import those packages today are untouched.

ONE EXCEPTION, from the same dispatch.Dispatcher split noted below: AnthropicCheapModel and OpenAICheapModel lost their BaseURL/APIKey/AuthScheme/Client fields in favor of a dispatch.Dispatcher + dispatch.Ref, and proxy.Options.CheapModel changed type from components.Model to *proxy.CheapModelConfig. A host built on this facade that constructed either cheap-model type directly, or passed one to Options.CheapModel, stops compiling. There is no way to re-export the OLD shape here without also re-exporting the credential-holding code this project is removing from the core, so this one break is accepted rather than papered over.

WHY A FACADE RATHER THAN PROMOTING THE PACKAGES. Moving internal/modelinfo (38 importers) out of internal/ would churn ~70 files across the tree and publish its entire surface as API this project then has to keep stable. The composition root uses THIRTEEN of its symbols. Exporting those thirteen is a promise worth making; exporting the whole package by accident is not.

cheapmodel IS promoted, by exception: the dispatch.Dispatcher split (see dispatch/dispatch.go) requires it. Every host now builds its own cheapmodel.Anthropic/OpenAI directly over its own Dispatcher, and a host outside this module (Cortex, say) cannot do that with an internal/ package. Its surface is small and host-agnostic on purpose — wire format only, no transport, no credential — so promoting it is a promise this project can keep.

THE STARTUP ITSELF IS HERE TOO. The facade alone was not enough: a host still had to copy the whole composition root to add its own parts, and then copy every later step by hand. One host missed proxy.PingSavings that way and booked $0 of keep-alive saving. So the root moved here as Main, and cmd/context-guru-proxy calls it with no hooks. A host calls it with its Hooks (hooks.go) and writes only its own parts. It is not a plugin system: the hooks run at fixed points, and proxy.Options remains the contract.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Commit

func Commit() string

Commit is the revision this module was built from.

func ExactWindow

func ExactWindow(r Resolver, ctx context.Context, model string) (tokens int, exact, ok bool)

ExactWindow reports a model's window and whether the answer is exact. See models.ExactWindow.

func Main added in v0.7.3

func Main(hooks Hooks)

Main runs the proxy until a signal or the idle watchdog stops it. It is the whole of cmd/context-guru-proxy's main; hooks adds a host's own parts at fixed points (see Hooks). Like a main, it reads os.Args and the global flag set, and a startup error ends the process.

func SetupLogging

func SetupLogging() string

SetupLogging configures the process logger from the environment (CG_LOG_LEVEL, CG_LOG_FILE) and returns a one-line description of what it did, for the startup log.

It never fails the process: a log file that cannot be opened degrades to stderr with a warning, because refusing to boot over an observability sink would make logging less safe than not having it.

func Version

func Version() string

Build identity, as set by the Makefile's -ldflags. A host that wants its own stamp sets its own variables and ignores these; these are what this module's own build records.

Read as functions rather than re-exported as variables, because a var alias would let a host overwrite the value another part of the process already reported.

Types

type AnthropicCheapModel

type AnthropicCheapModel = cheapmodel.Anthropic

AnthropicCheapModel calls an Anthropic-dialect endpoint.

type App added in v0.7.3

type App struct {
	Config    *config.Config
	Recorder  *dash.Recorder
	Registry  *tenant.Registry
	Tenants   *proxy.TenantSource
	Upstreams map[string]proxy.Upstream
	Windows   Resolver
	Prices    Pricer
	Handler   *proxy.Handler
	Mux       *http.ServeMux
}

App is what the startup has built, for the hooks. A field is nil when the part is off: Recorder without --dashboard, Registry, Tenants and Upstreams outside hosted mode.

type Chain

type Chain = models.Chain

Chain tries several Resolvers in order, first answer wins.

type Defaults added in v0.7.3

type Defaults struct {
	// DashboardContent is the default of --dashboard-content (DASHBOARD_CONTENT).
	DashboardContent bool
}

Defaults are the shared flag defaults a host may change.

type Hooks added in v0.7.3

type Hooks struct {
	// Flags registers the host's own flags. It runs before flag.Parse, on the same flag set.
	Flags func(fs *flag.FlagSet)

	// Defaults changes the default of some shared flags. The flag and its environment variable
	// still win over it.
	Defaults Defaults

	// UIPath moves the dashboard from /dashboard/ to this path (dash.API.SetUIPath). "" keeps
	// /dashboard/. It must be rooted and slash-terminated; Main checks it before anything opens.
	UIPath string

	// BeforeControlDB runs in hosted mode, before the control database at path opens. An error
	// stops the start.
	BeforeControlDB func(path string) error

	// TenantOptions changes the registry options, just before the control database opens.
	TenantOptions func(opts *tenant.Options)

	// Hosted runs in hosted mode, just after the control database opens. app.Registry and
	// app.Upstreams are set; app.Tenants, app.Handler and app.Mux are not yet. An error stops the
	// start.
	Hosted func(app *App) error

	// ProxyOptions changes the proxy options, just before proxy.New.
	ProxyOptions func(opts *proxy.Options, app *App)

	// DashAuth wraps the dashboard authenticator in hosted mode.
	DashAuth func(core dash.Authenticator) dash.Authenticator

	// Mount adds routes to the proxy's mux, after it is built. Every App field is set.
	Mount func(mux *http.ServeMux, app *App)

	// Handler wraps the mux. It runs after Mount. The idle-exit activity stamp, when on, wraps
	// the result, and it still asks the mux which requests count as use: a request that matches
	// no mux route does not count, even when the wrapper answers it.
	Handler func(next http.Handler, app *App) http.Handler
}

Hooks are the points where a host adds its own parts to the standard proxy startup (Main).

WHY THEY EXIST. Go cannot extend a package main, so a deployment that needed the standard proxy plus its own parts (SSO, a key store, its own routes) had to copy cmd/context-guru-proxy and edit the copy. Each later step added to that file then had to be copied by hand, and nothing warned when a copy was missed: one host booked $0 of keep-alive saving because it never called proxy.PingSavings. With the startup here, a new step reaches every host in one change, and a host keeps only its own parts.

Every field is optional. The zero value is exactly the context-guru-proxy binary. A hook runs at one fixed point in the startup, named on its field; Main calls none of them more than once.

type LiteLLM

type LiteLLM = modelslitellm.LiteLLM

LiteLLM resolves against the LiteLLM community price/window map.

func NewLiteLLM

func NewLiteLLM(url string, client *http.Client, ttl time.Duration) *LiteLLM

NewLiteLLM resolves model windows against a LiteLLM gateway, cached for ttl. See litellm.New in models/litellm.

type OpenAICheapModel

type OpenAICheapModel = cheapmodel.OpenAI

OpenAICheapModel calls an OpenAI-dialect endpoint.

type Price

type Price = models.Price

Price is one model's token prices.

type Pricer

type Pricer = models.Pricer

Pricer answers what a model's tokens cost.

type Resolver

type Resolver = models.Resolver

Resolver resolves a model id to its context window.

type Static

type Static = models.Static

Static is the compiled-in table of known models.

func DefaultStatic

func DefaultStatic() Static

DefaultStatic is the compiled-in model table. See models.DefaultStatic.

type Table

type Table = models.Table

Table is a table loaded from a file.

func LoadTable

func LoadTable(path string) (*Table, error)

LoadTable reads a model table from a file. See models.LoadTable.

Directories

Path Synopsis
Package metricspush starts the OpenTelemetry SDK and an OTLP/JSON exporter that send a proxy's metrics to the central collector (R15).
Package metricspush starts the OpenTelemetry SDK and an OTLP/JSON exporter that send a proxy's metrics to the central collector (R15).

Jump to

Keyboard shortcuts

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