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 ¶
- func Commit() string
- func ExactWindow(r Resolver, ctx context.Context, model string) (tokens int, exact, ok bool)
- func Main(hooks Hooks)
- func SetupLogging() string
- func Version() string
- type AnthropicCheapModel
- type App
- type Chain
- type Defaults
- type Hooks
- type LiteLLM
- type OpenAICheapModel
- type Price
- type Pricer
- type Resolver
- type Static
- type Table
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExactWindow ¶
ExactWindow reports a model's window and whether the answer is exact rather than inferred. The distinction matters: a fraction-of-window trigger computed from a guessed window is a guess.
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 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 ¶
LiteLLM resolves against the LiteLLM community price/window map (internal/modelinfo/litellm: the one network call in this family, kept out of modelinfo itself so that package stays I/O-free).
type OpenAICheapModel ¶
type OpenAICheapModel = cheapmodel.OpenAI
OpenAICheapModel calls an OpenAI-dialect endpoint.
Source Files
¶
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). |