Documentation
¶
Overview ¶
Package server is the HTTP face of the memcode gateway: bearer-token auth in front of the metered LLM engine (router → Fireworks + the frontier vendor APIs). The wire protocol IS the OpenAI-compat surface (one-wire): POST /v1/chat/completions + GET /v1/models at the natural paths — one completion (or SSE stream) per call, with the memcode extensions riding as ignorable headers/fields (see internal/compat). The agent loop stays client-side; a future server-side loop (cloud workspaces, bots) can layer on without breaking CLI clients.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func LocalTokenAuthenticator ¶ added in v0.9.0
func LocalTokenAuthenticator(token string) gateway.Authenticator
LocalTokenAuthenticator authenticates the single shared self-host bearer as the one local identity. Exported through gateway/serve for compositions.
func New ¶
New builds the handler with no composition options — the self-host default: a local shared-token Authenticator, allow-everything authorization, stdout-only usage, environment provider keys.
func NewWith ¶ added in v0.9.0
func NewWith(cfg Config, ext gateway.Extensions) http.Handler
NewWith builds the HTTP handler from a config plus a composition. Health is unauthenticated (Cloud Run probes); every other route runs behind the Authenticator + Authorizer. A hosted operator supplies cloud implementations here; nothing hosted-specific lives in this package.
Types ¶
type Config ¶
type Config struct {
Port string // PORT (Cloud Run convention), default 8080
// InternalToken (MEMCODE_INTERNAL_TOKEN) gates the /internal/* admin surface
// (cooldown, audit log) — Cloud Scheduler + operators only, NEVER in the CLI.
// The user token must NOT open these: it's distributed to every client, so a
// user could otherwise stop the pool or read lifecycle data. Fails CLOSED:
BackendName string // for the startup log: "hybrid" | "anthropic" | "fireworks"
// SystemPrefix is the server-owned doctrine prepended to every system
// prompt — the first concrete piece of "prompts live server-side". The full
// prompt library migrates here incrementally; this proves the seam.
SystemPrefix string // MEMCODE_SYSTEM_PREFIX (optional)
// SelfHostToken is the shared bearer for the default self-host
// composition (New): every request carrying it runs as one local
// identity. A hosted composition supplies its own Authenticator instead.
SelfHostToken string // MEMCODE_SELFHOST_TOKEN
Provider provider.ModelProvider
}
Config is the service configuration, env-only (keys NEVER in files).
func ConfigFromEnv ¶
ConfigFromEnv builds the service config. Backend selection reuses the same env contract as the engine: MEMCODE_PROVIDER=anthropic|fireworks|hybrid plus ANTHROPIC_API_KEY / MEMCODE_FIREWORKS_URL / _MODEL / _KEY (legacy MEMCODE_VLLM_* names still honored).