provider

package
v0.6.4 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package provider manages the coding product's persisted provider connection profiles. The llm package remains the only provider runtime; this package selects one profile and projects it into llm.ProviderOverride.

Index

Constants

View Source
const (
	OfficialConnectionID = "official"
)

Variables

View Source
var ErrUtilityModelUnavailable = errors.New("no utility model is configured")

Functions

func IsUtilityModelEligible

func IsUtilityModelEligible(model llm.Model) bool

IsUtilityModelEligible reports whether a catalog model can handle the product's small text requests with thinking disabled.

Types

type CompleteFunc

CompleteFunc is the one-shot LLM boundary used by ConnectionTester.

type Connection

type Connection struct {
	ID          string `json:"id"`
	Name        string `json:"name"`
	BaseURL     string `json:"baseURL,omitempty"`
	ActiveKeyID string `json:"activeKeyId,omitempty"`
	Keys        []Key  `json:"keys,omitempty"`
}

Connection groups one endpoint with multiple named credentials. The official connection has no stored BaseURL; requests use the model catalog.

func FindConnection

func FindConnection(profile Profile, id string) *Connection

type ConnectionTestRequest

type ConnectionTestRequest struct {
	ProviderID    string
	ConnectionID  string
	KeyID         string
	BaseURL       string
	APIKey        string
	ModelID       string
	ThinkingLevel llm.ModelThinkingLevel
}

ConnectionTestRequest describes an exact provider, endpoint, credential and model combination. APIKey and BaseURL may be unsaved values from the settings form. A blank APIKey resolves the saved key identified by ConnectionID/KeyID.

type ConnectionTestResult

type ConnectionTestResult struct {
	Status         ConnectionTestStatus
	ModelID        string
	ModelName      string
	RequestText    string
	ThinkingLevel  llm.ModelThinkingLevel
	ThinkingText   string
	ResponseText   string
	StopReason     llm.StopReason
	InputTokens    int64
	OutputTokens   int64
	Latency        time.Duration
	ProviderStatus int
}

ConnectionTestResult contains no secret or raw provider response. It exposes the fixed probe, model-visible thinking and assistant text separately so the user can verify the exchange shown in settings.

type ConnectionTestStatus

type ConnectionTestStatus string

ConnectionTestStatus is the user-actionable outcome of one provider probe.

const (
	ConnectionTestSuccess              ConnectionTestStatus = "success"
	ConnectionTestAuthenticationFailed ConnectionTestStatus = "authentication_failed"
	ConnectionTestRateLimited          ConnectionTestStatus = "rate_limited"
	ConnectionTestTimeout              ConnectionTestStatus = "timeout"
	ConnectionTestUnreachable          ConnectionTestStatus = "unreachable"
	ConnectionTestNotFound             ConnectionTestStatus = "not_found"
	ConnectionTestProviderError        ConnectionTestStatus = "provider_error"
)

type ConnectionTester

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

ConnectionTester probes draft or persisted connection settings without mutating the provider store or its shared registry overrides.

func NewConnectionTester

func NewConnectionTester(store *Store, complete CompleteFunc) *ConnectionTester

func (*ConnectionTester) Test

type ConnectionUpdate

type ConnectionUpdate struct {
	ID          string
	Name        string
	BaseURL     string
	ActiveKeyID string
	Keys        []KeyUpdate
}

type Key

type Key struct {
	ID     string `json:"id"`
	Name   string `json:"name"`
	APIKey string `json:"apiKey"`
}

Key is one locally stored credential. APIKey is write-only at the HTTP boundary and must never be returned to the browser.

func FindKey

func FindKey(connection Connection, id string) *Key

type KeyUpdate

type KeyUpdate struct {
	ID     string
	Name   string
	APIKey string
}

type ModelReference

type ModelReference struct {
	Provider      string                 `json:"provider"`
	Model         string                 `json:"model"`
	ThinkingLevel llm.ModelThinkingLevel `json:"thinkingLevel,omitempty"`
}

ModelReference is the non-secret identity used in a selection repair.

type ModelRoute

type ModelRoute struct {
	Provider     string `json:"provider"`
	Model        string `json:"model"`
	ConnectionID string `json:"connectionId"`
	KeyID        string `json:"keyId"`
}

ModelRoute is the public, secret-free identity of one resolved request path.

type ModelSelection

type ModelSelection struct {
	Provider      string                 `json:"provider"`
	Model         string                 `json:"model"`
	ThinkingLevel llm.ModelThinkingLevel `json:"thinkingLevel"`
}

ModelSelection is the application-wide model used for new conversations. It is deliberately absent on first launch; choosing a provider connection alone must never silently select a model.

type Profile

type Profile struct {
	ActiveConnectionID string       `json:"activeConnectionId"`
	Connections        []Connection `json:"connections"`
}

Profile is the persisted configuration for one llm provider.

type ResolvedModelRoute

type ResolvedModelRoute struct {
	Route   ModelRoute
	Model   llm.Model
	Options llm.StreamOptions
}

ResolvedModelRoute carries the catalog model and request-scoped connection settings used inside the product. It must never be serialized to the client.

type SelectionRepair

type SelectionRepair struct {
	Target      SelectionRepairTarget `json:"target"`
	Reason      SelectionRepairReason `json:"reason"`
	Previous    ModelReference        `json:"previous"`
	Replacement *ModelReference       `json:"replacement,omitempty"`
}

SelectionRepair records one persisted model selection that was adjusted during startup because its route or thinking level is no longer available. It is kept in memory for the settings UI and is not written to providers.json.

type SelectionRepairReason

type SelectionRepairReason string
const (
	SelectionRepairUnavailable      SelectionRepairReason = "unavailable"
	SelectionRepairUnsupportedLevel SelectionRepairReason = "unsupported_thinking_level"
)

type SelectionRepairTarget

type SelectionRepairTarget string
const (
	SelectionRepairActiveModel  SelectionRepairTarget = "active_model"
	SelectionRepairUtilityModel SelectionRepairTarget = "utility_model"
)

type Store

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

Store persists provider profiles and owns their application to a provider registry. The coding product deliberately disables environment credential lookup, so every usable key comes from this store.

func NewStore

func NewStore(
	dataDir string,
	registry *llm.ProviderRegistry,
) (*Store, error)

func (*Store) ActivateConnection

func (s *Store) ActivateConnection(providerID, connectionID string) (Profile, error)

ActivateConnection selects the endpoint used for subsequent requests.

func (*Store) ActivateKey

func (s *Store) ActivateKey(providerID, connectionID, keyID string) (Profile, error)

ActivateKey selects one saved credential for a connection. An empty key ID leaves the connection without a credential selection.

func (*Store) ActivateModel

func (s *Store) ActivateModel(selection ModelSelection) (ModelSelection, error)

ActivateModel validates and persists the application-wide model selection. A provider must have an effective credential before its model can be used.

func (*Store) ActiveModel

func (s *Store) ActiveModel() (ModelSelection, bool)

ActiveModel returns the explicitly activated model for new conversations. The boolean is false on first launch and after the active provider is reset.

func (*Store) Apply

func (s *Store) Apply()

Apply projects each saved profile into the shared llm provider registry. Providers without a saved profile retain their catalog URL but remain unconfigured; coding never falls back to process environment credentials.

func (*Store) Delete

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

Delete removes one saved profile. If it supplied the application-wide model, that model selection is cleared as part of the same persisted update.

func (*Store) Repairs

func (s *Store) Repairs() []SelectionRepair

Repairs returns startup repairs that should be surfaced to the user. The returned slice is independent from the store and safe for callers to retain.

func (*Store) Replace

func (s *Store) Replace(providerID string, update Update) (Profile, error)

Replace validates and atomically replaces one provider profile.

func (*Store) ResolveUtilityModel

func (s *Store) ResolveUtilityModel() (ResolvedModelRoute, error)

ResolveUtilityModel resolves the pinned route into request-scoped settings. It never mutates the provider-wide override.

func (*Store) Save

func (s *Store) Save(providerID string, update Update) (Profile, error)

Save updates connection names, endpoints, and credentials without changing which connection or credential is currently active. If an active item was removed, the profile falls back to the official connection or inherited credential as appropriate.

func (*Store) SetUtilityModel

func (s *Store) SetUtilityModel(selection UtilityModelSelection) (UtilityModelSelection, error)

SetUtilityModel validates and atomically persists a utility-model selection.

func (*Store) Snapshot

func (s *Store) Snapshot() map[string]Profile

func (*Store) UtilityModel

func (s *Store) UtilityModel() (UtilityModelSelection, bool)

UtilityModel returns the explicitly configured utility-model route.

type Update

type Update struct {
	ActiveConnectionID string
	Connections        []ConnectionUpdate
}

Update describes an application-level profile change. Blank APIKey values preserve existing secrets with the same key ID.

type UtilityModelSelection

type UtilityModelSelection struct {
	Provider     string `json:"provider"`
	Model        string `json:"model"`
	ConnectionID string `json:"connectionId"`
	KeyID        string `json:"keyId"`
}

UtilityModelSelection pins the small model used for lightweight product work such as session titles. It stores stable identities without copying the credential itself.

Jump to

Keyboard shortcuts

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