proxy

package
v0.34.0 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2026 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// CodexDesktopPathPrefix is the loopback-only Ollama server route used as
	// Codex's openai_base_url. Codex appends /v1/responses and related paths.
	CodexDesktopPathPrefix = "/api/codex"

	// CodexDesktopModelCatalogFilename is the combined native and Ollama catalog
	// shown by the Codex model picker.
	CodexDesktopModelCatalogFilename = "ollama-launch-models.json"

	// CodexDesktopRoutingCatalogFilename is the Ollama-only routing allow-list,
	// separate from the combined picker catalog.
	CodexDesktopRoutingCatalogFilename = "ollama-launch-codex-routing.json"

	// CodexDesktopManagedAPIKey is a local-only sentinel, never an OpenAI credential.
	// Reject it before forwarding any request to OpenAI.
	CodexDesktopManagedAPIKey = "ollama-local-codex"
)
View Source
const (
	// DefaultClaudeDesktopListenAddr is the loopback address used by the Ollama
	// app and the Claude Desktop profile it manages.
	DefaultClaudeDesktopListenAddr = "127.0.0.1:11435"
)
View Source
const (
	MaxClaudeDesktopModels = 5
)

Variables

This section is empty.

Functions

func ClaudeDesktopMappings

func ClaudeDesktopMappings(models []ClaudeDesktopModel) map[string]string

ClaudeDesktopMappings returns the explicit route-to-model mapping represented by an assigned model catalog.

func DefaultClaudeDesktopMappings

func DefaultClaudeDesktopMappings() map[string]string

DefaultClaudeDesktopMappings returns the safe compatibility fallback used when Ollama.com does not provide an app-specific mapping contract.

func DefaultClaudeDesktopMappingsForModels

func DefaultClaudeDesktopMappingsForModels(available []ClaudeDesktopModel) map[string]string

DefaultClaudeDesktopMappingsForModels resolves the server contract, or the compatibility fallback when it is absent, against the current catalog.

func ProbeClaudeDesktop

func ProbeClaudeDesktop(ctx context.Context, baseURL string) error

ProbeClaudeDesktop verifies that baseURL is served by Ollama's Claude gateway rather than another process using the configured port.

Types

type ClaudeDesktop

type ClaudeDesktop struct {
	// contains filtered or unexported fields
}

ClaudeDesktop is the local gateway that Claude Desktop reaches through its native third-party inference mode. It is deliberately an ordinary HTTP reverse proxy: Claude terminates its own gateway protocol here, so no TLS interception or system trust changes are necessary.

func NewClaudeDesktop

func NewClaudeDesktop(config ClaudeDesktopConfig) (*ClaudeDesktop, error)

NewClaudeDesktop creates a Claude Desktop proxy.

func (*ClaudeDesktop) Addr

func (p *ClaudeDesktop) Addr() string

func (*ClaudeDesktop) Close

func (p *ClaudeDesktop) Close(ctx context.Context) error

func (*ClaudeDesktop) Counts

func (p *ClaudeDesktop) Counts() ClaudeDesktopCounts

func (*ClaudeDesktop) Models

func (p *ClaudeDesktop) Models() []ClaudeDesktopModel

Models returns the model subset currently advertised to Claude Desktop.

func (*ClaudeDesktop) ServeHTTP

func (p *ClaudeDesktop) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*ClaudeDesktop) SetModels

func (p *ClaudeDesktop) SetModels(models []ClaudeDesktopModel) error

SetModels replaces the complete model subset advertised to Claude Desktop.

func (*ClaudeDesktop) Start

func (p *ClaudeDesktop) Start() error

type ClaudeDesktopAccessReason

type ClaudeDesktopAccessReason string
const (
	ClaudeDesktopAccessCloudOff                ClaudeDesktopAccessReason = "cloud_off"
	ClaudeDesktopAccessSignInRequired          ClaudeDesktopAccessReason = "sign_in_required"
	ClaudeDesktopAccessUpgradeRequired         ClaudeDesktopAccessReason = "upgrade_required"
	ClaudeDesktopAccessVerificationUnavailable ClaudeDesktopAccessReason = "verification_unavailable"
	ClaudeDesktopAccessModelNotInstalled       ClaudeDesktopAccessReason = "model_not_installed"
)

type ClaudeDesktopAccessState

type ClaudeDesktopAccessState struct {
	Cloud   ClaudeDesktopCloudStatus
	Account ClaudeDesktopAccountStatus
	Plan    string
}

ClaudeDesktopAccessState is the current account and Cloud state used to evaluate Claude Desktop models. Callers should resolve it again at each user action or proxy request because both settings and account state can change.

type ClaudeDesktopAccountStatus

type ClaudeDesktopAccountStatus string
const (
	ClaudeDesktopAccountUnknown   ClaudeDesktopAccountStatus = "unknown"
	ClaudeDesktopAccountSignedOut ClaudeDesktopAccountStatus = "signed_out"
	ClaudeDesktopAccountSignedIn  ClaudeDesktopAccountStatus = "signed_in"
)

type ClaudeDesktopAvailability

type ClaudeDesktopAvailability string
const (
	ClaudeDesktopAvailabilityUnknown     ClaudeDesktopAvailability = "unknown"
	ClaudeDesktopAvailabilityAvailable   ClaudeDesktopAvailability = "available"
	ClaudeDesktopAvailabilityUnavailable ClaudeDesktopAvailability = "unavailable"
)

type ClaudeDesktopCloudStatus

type ClaudeDesktopCloudStatus string
const (
	ClaudeDesktopCloudUnknown ClaudeDesktopCloudStatus = "unknown"
	ClaudeDesktopCloudOff     ClaudeDesktopCloudStatus = "off"
	ClaudeDesktopCloudOn      ClaudeDesktopCloudStatus = "on"
)

type ClaudeDesktopConfig

type ClaudeDesktopConfig struct {
	ListenAddr         string
	OllamaURL          string
	Model              string
	Models             []ClaudeDesktopModel
	Logger             *slog.Logger
	OnCountsChanged    func(ClaudeDesktopCounts)
	RefreshModels      func(context.Context, []ClaudeDesktopModel) ([]ClaudeDesktopModel, error)
	ResolveAccessState func(context.Context) (ClaudeDesktopAccessState, error)
	ListLocalModels    func(context.Context) ([]string, error)
}

ClaudeDesktopConfig configures a Claude Desktop proxy instance.

type ClaudeDesktopCounts

type ClaudeDesktopCounts struct {
	Routed uint64
}

ClaudeDesktopCounts reports requests routed through the proxy.

type ClaudeDesktopModel

type ClaudeDesktopModel struct {
	Name         string
	Description  string
	DisplayName  string
	RequiredPlan string
	OllamaModel  string
	Cloud        bool
	Recommended  bool
	AccountCloud bool
	// contains filtered or unexported fields
}

ClaudeDesktopModel is one Ollama model adapted for Claude Desktop's model catalog. Name is the canonical recommendation identifier shown to users; OllamaModel is the explicit route sent to the local Ollama server.

func ClaudeDesktopModelsFromCloudInventory

func ClaudeDesktopModelsFromCloudInventory(names []string) []ClaudeDesktopModel

ClaudeDesktopModelsFromCloudInventory converts an account-scoped cloud inventory into selectable Claude routes. Presence in this inventory is the entitlement and Auto-mode eligibility check; these models are not recommendations.

func ClaudeDesktopModelsFromRecommendations

func ClaudeDesktopModelsFromRecommendations(recommendations []api.ModelRecommendation) []ClaudeDesktopModel

ClaudeDesktopModelsFromRecommendations converts the endpoint response into the protocol metadata Claude Desktop expects. Recommendation model names, order, descriptions, limits, and plan requirements remain server-owned.

func DefaultClaudeDesktopModels

func DefaultClaudeDesktopModels() []ClaudeDesktopModel

DefaultClaudeDesktopModels is the built-in offline fallback. Keep this list deliberately small; the Ollama.com app-aware endpoint is the primary source.

func FetchClaudeDesktopModels

func FetchClaudeDesktopModels(client *http.Client, req *http.Request) ([]ClaudeDesktopModel, error)

FetchClaudeDesktopModels fetches the app-aware recommendation contract. Callers own request construction and are responsible for falling back when the request or response fails.

func MapClaudeDesktopModels

func MapClaudeDesktopModels(available []ClaudeDesktopModel, mappings map[string]string) []ClaudeDesktopModel

MapClaudeDesktopModels assigns explicit Claude route IDs to Ollama models. Empty routes are omitted and the same Ollama model may serve multiple routes.

func PreserveClaudeDesktopCloudEntitlements added in v0.33.1

func PreserveClaudeDesktopCloudEntitlements(models, previous []ClaudeDesktopModel) []ClaudeDesktopModel

PreserveClaudeDesktopCloudEntitlements carries verified account facts into an offline catalog without replacing its built-in routes or weakening its last-known plan requirement.

func SelectClaudeDesktopModels

func SelectClaudeDesktopModels(available []ClaudeDesktopModel, selected []string) []ClaudeDesktopModel

SelectClaudeDesktopModels preserves the user's explicit order. Names that are no longer recommended remain usable so a transient endpoint change or outage cannot silently replace a saved user choice. Validated Claude IDs are reusable slots assigned in that order, independent of recommendation order.

func UnverifyClaudeDesktopCloudEntitlements

func UnverifyClaudeDesktopCloudEntitlements(models []ClaudeDesktopModel) []ClaudeDesktopModel

UnverifyClaudeDesktopCloudEntitlements prevents fallback metadata from overriding a catalog that was already refreshed from the server.

func VerifyClaudeDesktopModelsWithCloudInventory

func VerifyClaudeDesktopModelsWithCloudInventory(models, inventory []ClaudeDesktopModel) []ClaudeDesktopModel

VerifyClaudeDesktopModelsWithCloudInventory marks matching catalog models as account-verified without replacing their recommendation metadata.

func WithoutClaudeDesktopRecommendationMappings added in v0.33.1

func WithoutClaudeDesktopRecommendationMappings(models []ClaudeDesktopModel) []ClaudeDesktopModel

WithoutClaudeDesktopRecommendationMappings returns a catalog without server-provided defaults. Callers use this when retaining model metadata across an offline refresh, where the prior mapping contract is stale.

func (ClaudeDesktopModel) GatewayID

func (m ClaudeDesktopModel) GatewayID() string

GatewayID returns the validated Claude-facing ID assigned to this model.

type ClaudeDesktopModelAccess

type ClaudeDesktopModelAccess struct {
	Availability ClaudeDesktopAvailability
	Reason       ClaudeDesktopAccessReason
	RequiredPlan string
}

ClaudeDesktopModelAccess is the policy decision for one model.

func EvaluateClaudeDesktopModelAccess

func EvaluateClaudeDesktopModelAccess(model ClaudeDesktopModel, state ClaudeDesktopAccessState, installed, inventoryKnown bool) ClaudeDesktopModelAccess

EvaluateClaudeDesktopModelAccess applies Claude Desktop's model policy to facts resolved by the app. installed and inventoryKnown only affect local models.

type ClaudeDesktopRoute

type ClaudeDesktopRoute struct {
	ID          string
	DisplayName string
}

ClaudeDesktopRoute is one fixed model ID accepted by Claude Desktop. The gateway advertises the mapped Ollama model as its display name.

func ClaudeDesktopRoutes

func ClaudeDesktopRoutes() []ClaudeDesktopRoute

ClaudeDesktopRoutes returns the fixed routes in Claude's preferred order.

type CodexDesktop added in v0.34.0

type CodexDesktop struct {
	// contains filtered or unexported fields
}

CodexDesktop routes catalog-listed models to Ollama and other requests to their native upstream, using the existing Ollama listener.

func NewCodexDesktop added in v0.34.0

func NewCodexDesktop(config CodexDesktopConfig) (*CodexDesktop, error)

func (*CodexDesktop) ServeHTTP added in v0.34.0

func (h *CodexDesktop) ServeHTTP(w http.ResponseWriter, r *http.Request)

type CodexDesktopConfig added in v0.34.0

type CodexDesktopConfig struct {
	OllamaURL          string
	ChatGPTURL         string
	OpenAIURL          string
	RoutingCatalogPath string
	ActivityLogPath    string
	MaxBodyBytes       int64
	Logger             *slog.Logger
	Transport          http.RoundTripper
}

CodexDesktopConfig describes the upstreams and Ollama-only routing catalog.

Jump to

Keyboard shortcuts

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