feat(llamaswap): add llama-swaps (TLS) DSN scheme
CI / Tidy (pull_request) Successful in 9m43s
CI / Build & Test (pull_request) Successful in 10m26s
Adversarial Review (Gadfly) / review (pull_request) Successful in 11m47s

llama-swap was http-only by DSN, pushing TLS-fronted instances onto the openai://
scheme (which loses the management/image methods). Add a "llama-swaps" scheme
that builds an https base URL, alongside "llama-swap" (http, local-first) —
mirroring redis/rediss. Both share one factory; llama-swaps is scheme-only (no
default built-in). The choice stays explicit because a DSN has no reliable
http-vs-https signal.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-27 17:58:59 -04:00
parent b2487a1a37
commit de2b2f0f28
6 changed files with 73 additions and 29 deletions
+21 -11
View File
@@ -20,6 +20,12 @@ const (
ProviderOllamaCloud = "ollama-cloud"
ProviderForeman = "foreman"
ProviderLlamaSwap = "llama-swap"
// ProviderLlamaSwapTLS is the DSN scheme for a TLS-fronted llama-swap
// (https base URL). It is a scheme only, not a default built-in provider
// name. Why a separate scheme rather than auto-detecting: a DSN carries no
// reliable signal for http vs https, so the choice is explicit
// (llama-swap = http local-first, llama-swaps = https), mirroring rediss.
ProviderLlamaSwapTLS = "llama-swaps"
)
// registerBuiltins installs the built-in providers and env-DSN scheme
@@ -70,24 +76,28 @@ func registerBuiltins(r *Registry, httpClient *http.Client) {
// llama-swap: OpenAI-compatible chat + image generation + management
// endpoints over a model-swapping proxy. Chat reuses the openai client
// (provider/llamaswap delegates); the DSN builds an http:// base URL
// because llama-swap is local-first (TLS-fronted instances can use the
// openai:// scheme for chat). The no-DSN built-in errors on use with a
// clear message, mirroring foreman.
// (provider/llamaswap delegates). Two schemes: "llama-swap" builds an
// http:// base URL (local-first default), "llama-swaps" builds https://
// for a TLS-fronted instance (mirrors redis/rediss). The no-DSN built-in
// errors on use with a clear message, mirroring foreman.
llamaSwapOpts := func(extra ...llamaswap.Option) []llamaswap.Option {
if httpClient != nil {
extra = append(extra, llamaswap.WithHTTPClient(httpClient))
}
return extra
}
r.providers[ProviderLlamaSwap] = llamaswap.New(llamaSwapOpts(llamaswap.WithName(ProviderLlamaSwap))...)
r.schemes[ProviderLlamaSwap] = func(name string, dsn DSN) (llm.Provider, error) {
return llamaswap.New(llamaSwapOpts(
llamaswap.WithName(name),
llamaswap.WithBaseURL("http://"+dsn.Host),
llamaswap.WithToken(dsn.Token),
)...), nil
llamaSwapScheme := func(urlScheme string) SchemeFactory {
return func(name string, dsn DSN) (llm.Provider, error) {
return llamaswap.New(llamaSwapOpts(
llamaswap.WithName(name),
llamaswap.WithBaseURL(urlScheme+"://"+dsn.Host),
llamaswap.WithToken(dsn.Token),
)...), nil
}
}
r.providers[ProviderLlamaSwap] = llamaswap.New(llamaSwapOpts(llamaswap.WithName(ProviderLlamaSwap))...)
r.schemes[ProviderLlamaSwap] = llamaSwapScheme("http")
r.schemes[ProviderLlamaSwapTLS] = llamaSwapScheme("https")
// Anthropic and Anthropic-compatible endpoints.
anthropicOpts := func(extra ...anthropic.Option) []anthropic.Option {