llmproxy

package
v0.17.10 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package llmproxy provides an http.RoundTripper that rewrites direct calls to well-known LLM provider endpoints (api.openai.com, api.anthropic.com, etc.) so they instead route through the sprout-foundry platform's /api/proxy/llm/{provider}/* path.

This exists because the WASM build can't ship API keys client-side — the platform holds per-user encrypted keys in its own datastore and attaches them server-side on each proxied request. Native sprout users who want to dogfood the platform routing can install the transport too; it's a no-op when no endpoint is configured.

See roadmap/SP-045-wasm-feature-parity.md §"Tier 2b" for the broader design and roadmap/SP-046-workspace-sync-model.md for the related sync transport.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CORSErrorMessage

func CORSErrorMessage(err error, provider string) string

CORSErrorMessage returns a user-friendly explanation of a CORS error, including guidance on how to resolve it.

func GetCorsProxy

func GetCorsProxy() string

GetCorsProxy returns the currently-configured CORS proxy URL (or "" when unset). Exposed for diagnostic + test paths.

func GetPlatformEndpoint

func GetPlatformEndpoint() string

GetPlatformEndpoint returns the currently-configured platform base URL (or "" when unset). Exposed mostly for diagnostic + test paths.

func Install

func Install()

Install replaces http.DefaultTransport with the llmproxy RoundTripper. Once installed, every http.Client that doesn't override .Transport picks up the URL rewriting (which is exactly what `pkg/agent_api` providers do — see models.go where http.Client{Timeout: ...} is constructed with no Transport).

Idempotent. Safe to call multiple times; only the first replaces the default transport, subsequent calls are no-ops.

func IsCORSError

func IsCORSError(err error) bool

IsCORSError returns true if the error is likely a CORS-related failure. This is heuristic-based since browsers do not provide specific CORS error info.

func SetCorsProxy

func SetCorsProxy(proxyURL string)

SetCorsProxy configures a generic CORS proxy URL prefix. When set, ALL HTTP/HTTPS requests are rewritten to {corsProxy}/{url-encoded original URL} before any other rewriting is attempted. This allows users to route through an arbitrary CORS proxy to bypass browser CORS restrictions. Pass "" to disable CORS proxy rewriting.

Precedence: corsProxy > platformEndpoint > no rewriting.

func SetPlatformEndpoint

func SetPlatformEndpoint(base string)

SetPlatformEndpoint configures the base URL of the sprout-foundry platform. Calls to known LLM providers will be rewritten to `{base}/api/proxy/llm/{provider}{path}`. Pass "" to disable rewriting.

Calling before Install() is harmless — the value is stored and applied once the transport gets installed.

Types

This section is empty.

Jump to

Keyboard shortcuts

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