localconfig

package
v0.1.14 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package localconfig owns Sol's single-user configuration and credentials. It has no provider transport or project-directory discovery.

Index

Constants

View Source
const APIKeyMode = "api-key"
View Source
const Version = 2

Version is the current on-disk configuration schema version.

Variables

This section is empty.

Functions

func DefaultPath

func DefaultPath() (string, error)

DefaultPath resolves only the OS user config directory, never the project.

func ValidID

func ValidID(id string) bool

ValidID checks provider and authentication-method identifiers.

Types

type APIKeyCredential

type APIKeyCredential struct {
	Key string `json:"key"`
}

APIKeyCredential holds one explicitly configured provider key.

type CommitStore

type CommitStore interface {
	Store
	UpdateWithCommit(context.Context, func(*Config) (context.Context, error)) (Config, error)
}

CommitStore supports transactions which accept an irreversible remote effect. Lock acquisition and the callback use the caller's context. The callback may supply a fresh bounded context for committing an accepted effect independently of caller cancellation. Ordinary configuration changes use Store.Update.

type Config

type Config struct {
	Providers    map[string]ProviderAuth `json:"providers"`
	DefaultModel *ModelSelection         `json:"default_model,omitempty"`
}

Config is the complete local configuration snapshot. Providers is initialized even when the file is absent. Credentials are not safe for display.

func (Config) Validate

func (c Config) Validate() error

Validate checks typed records without exposing credential contents in errors.

type FileStore

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

FileStore persists the complete record using private atomic writes and a stable advisory lock. Load and Update coordinate across independent processes.

func NewFileStore

func NewFileStore(path string) (*FileStore, error)

NewFileStore requires an explicit absolute path in a Sol-owned directory. The containing directory is made private. Construction does not access files.

func (*FileStore) Load

func (s *FileStore) Load(ctx context.Context) (Config, error)

func (*FileStore) Update

func (s *FileStore) Update(ctx context.Context, change func(*Config) error) (Config, error)

func (*FileStore) UpdateWithCommit

func (s *FileStore) UpdateWithCommit(ctx context.Context, change func(*Config) (context.Context, error)) (Config, error)

UpdateWithCommit requires a bounded commit context from a successful callback. Returning an error leaves the file unchanged. The caller owns context cleanup.

type ModelSelection

type ModelSelection struct {
	Model string `json:"model"`
	Auth  string `json:"auth"`
}

ModelSelection persists the model and deliberate authentication method together. Auth is api-key or a named OAuth method belonging to the selected provider.

func (ModelSelection) Validate

func (m ModelSelection) Validate() error

type OAuthCredential

type OAuthCredential struct {
	AccessToken  string    `json:"access_token"`
	RefreshToken string    `json:"refresh_token"`
	ExpiresAt    time.Time `json:"expires_at"`
	AccountID    string    `json:"account_id,omitempty"`
}

OAuthCredential holds refreshable tokens and optional account-routing metadata.

type ProviderAuth

type ProviderAuth struct {
	APIKey *APIKeyCredential          `json:"api_key,omitempty"`
	OAuth  map[string]OAuthCredential `json:"oauth,omitempty"`
}

ProviderAuth keeps API-key and named OAuth methods independently configurable.

type Store

type Store interface {
	Load(context.Context) (Config, error)
	Update(context.Context, func(*Config) error) (Config, error)
}

Store serializes read-modify-write across its users, including token refresh. Update callbacks must not reenter the store. A failed callback is not persisted.

Jump to

Keyboard shortcuts

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