customprovider

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package customprovider is a small local store of user-registered OpenAI-compatible endpoints — the accounts screen's "+ adicionar provedor customizado" flow, for pointing Kram at a local or LAN server (llama.cpp, LM Studio, Ollama's OpenAI endpoint, vLLM, text-generation-webui — all speak the same chat-completions wire format internal/provider/openai_compat.go already talks) that the fixed internal/providercatalog list has no way to represent.

Same on-disk shape and guarantees as internal/toolsettings/ internal/onboarding: plain JSON under kramhome, 0600, no separate save step, "missing file" is the normal first-run state. The one thing this store deliberately does *not* hold is the API key itself — that's optional here (most local servers have no auth) and, when present, lives in internal/credentials.Store under this entry's own synthesized EnvVar, exactly the way an OAuth-connected account's synthetic env var already works. One place for every secret, not two.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Provider

type Provider struct {
	ID      string `json:"id"`       // stable slug derived from Name, deduped on collision
	Name    string `json:"name"`     // display name, e.g. "Meu Servidor"
	BaseURL string `json:"base_url"` // e.g. "http://192.168.1.50:8080/v1"
	EnvVar  string `json:"env_var"`  // lookup key into credentials.Store for the (optional) API key
	// Model pins the upstream model ID, matching every other catalog
	// provider's DefaultModel. Required, unlike a catalog provider's
	// DefaultModel (which is always populated by Kram itself) — Add
	// rejects an empty value. Genuine passthrough (forwarding whatever
	// the request's own "model" field says) doesn't actually work today:
	// that field is the *combo ID* for any Kram-originated call, never a
	// real upstream model name, so an unpinned custom provider used to
	// silently receive something like "default" as its model — a real
	// bug, not a supported mode. See DECISIONS.md.
	Model string `json:"model"`
	// SupportsTools records whether this server accepts tool/function
	// definitions — a pointer so "never explicitly set" (every entry
	// created before this field existed) is distinguishable from "set to
	// false", matching AttemptInfo.Score's pattern elsewhere in this
	// codebase. Defaults to true (see SupportsToolsOrDefault) since most
	// OpenAI-compatible local servers (llama.cpp, LM Studio, vLLM,
	// Ollama) do support tool calling — this exists so a user whose
	// server genuinely can't has a way to say so, instead of Kram
	// silently sending tool definitions a server can't handle.
	SupportsTools *bool `json:"supports_tools,omitempty"`
}

Provider is one user-registered custom endpoint.

func (Provider) SupportsToolsOrDefault

func (p Provider) SupportsToolsOrDefault() bool

SupportsToolsOrDefault reports p.SupportsTools' value, or true if it was never explicitly set — see that field's doc comment.

type Store

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

Store holds every registered custom provider, in registration order.

func Load

func Load() (*Store, error)

Load reads the custom-providers file, or returns an empty Store if it doesn't exist yet.

func (*Store) Add

func (s *Store) Add(name, baseURL, model string, supportsTools bool) (Provider, error)

Add registers a new custom provider, deriving a stable ID (and the credentials-store EnvVar that goes with it) from name. name, baseURL and model are all required — see Provider.Model's doc comment for why an empty model isn't a supported "passthrough" mode. Persists immediately.

func (*Store) All

func (s *Store) All() []Provider

All returns every registered custom provider, in registration order.

func (*Store) Delete

func (s *Store) Delete(id string) error

Delete removes a custom provider by ID and persists immediately. Not an error if id isn't found — the accounts screen never offers a delete on a row that isn't there.

Jump to

Keyboard shortcuts

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