- Nueva interfaz Discoverer con Refresh() por backend - Kilo: full auto (isFree + metadata completa del upstream) - OpenCode: heurística -free para descubrir nuevos free - Kimchi: agrega todos los IDs no-curados del upstream - discoveryLoop cada 10 min en el Proxy - Backends stateful (mutex + catálogo dinámico) - CREDENCIALES.md y KIMCHI_ANALISIS.md documentan el setup
43 lines
1.8 KiB
Go
43 lines
1.8 KiB
Go
package proxy
|
|
|
|
// Backend represents one upstream free-model provider (opencode zen, kilo, mimo, ...).
|
|
//
|
|
// Each backend knows its own model catalogue, how to resolve a requested model
|
|
// name to the upstream ID, and the URL + headers required to forward a chat
|
|
// completion request to it. The Proxy holds an ordered list of backends and
|
|
// routes each request to the first one that recognises the model.
|
|
type Backend interface {
|
|
// Name is a short stable identifier ("opencode", "kilo").
|
|
Name() string
|
|
|
|
// Models returns the free models this backend exposes, for /v1/models listing.
|
|
// Implementations may return a dynamic (discovered) catalogue; before the
|
|
// first successful Refresh() they fall back to the curated list.
|
|
Models() []ModelInfo
|
|
|
|
// Resolve maps a client-requested model name to the upstream model ID.
|
|
// Returns ok=false when this backend does not recognise the model, so the
|
|
// router can try the next backend (or fall back to pass-through).
|
|
Resolve(model string) (resolved string, ok bool)
|
|
|
|
// ChatURL is the full upstream chat completions URL.
|
|
ChatURL() string
|
|
|
|
// Headers returns the headers required to authenticate/identify the
|
|
// request to the upstream (auth, client-id, request/session tracking, etc.).
|
|
Headers(requestID, sessionID string) map[string]string
|
|
}
|
|
|
|
// Discoverer is an optional capability a Backend may implement to
|
|
// auto-discover its model catalogue from the upstream /models endpoint.
|
|
//
|
|
// The Proxy runs a discovery loop that calls Refresh() periodically. Each
|
|
// implementation owns its parsing and free-model filtering logic, and merges
|
|
// discovered models with its curated base layer (curated metadata always wins
|
|
// for known IDs).
|
|
type Discoverer interface {
|
|
// Refresh fetches the upstream model list and updates the backend's
|
|
// dynamic catalogue. Safe to call concurrently with Models()/Resolve().
|
|
Refresh() error
|
|
}
|