modelctx

package
v1.1.30 Latest Latest
Warning

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

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

Documentation

Overview

Package modelctx provides persistent storage for named Docker Model Runner contexts, allowing users to switch between different Model Runner backends without setting environment variables each time.

Index

Constants

View Source
const DefaultContextName = "default"

DefaultContextName is the reserved name for the auto-detected context. It is never written to disk; a missing or empty "current" value implies it.

Variables

This section is empty.

Functions

func ValidateName

func ValidateName(name string) error

ValidateName returns an error if name is reserved or does not match the allowed pattern.

Types

type ContextConfig

type ContextConfig struct {
	// Host is the Model Runner API base URL (e.g. "http://192.168.1.100:12434").
	Host string `json:"host"`
	// TLS holds optional TLS settings.
	TLS TLSConfig `json:"tls,omitempty"`
	// Description is an optional human-readable note.
	Description string `json:"description,omitempty"`
	// CreatedAt records when the context was created.
	CreatedAt time.Time `json:"createdAt"`
}

ContextConfig is the configuration for a named Model Runner context.

type Store

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

Store manages named Model Runner contexts stored in a single JSON file.

func New

func New(dockerConfigDir string) (*Store, error)

New returns a Store that persists contexts in <dockerConfigDir>/model/contexts.json. It creates the parent directory if it does not exist.

func (*Store) Active

func (s *Store) Active() (string, error)

Active returns the name of the currently active context, or DefaultContextName if none has been set.

func (*Store) Create

func (s *Store) Create(name string, cfg ContextConfig) error

Create writes a new named context. It returns an error if the name is reserved, fails validation, or already exists.

func (*Store) Get

func (s *Store) Get(name string) (ContextConfig, error)

Get returns the configuration for the named context.

func (*Store) List

func (s *Store) List() (map[string]ContextConfig, error)

List returns all named contexts. The synthetic "default" context is not included.

func (*Store) Remove

func (s *Store) Remove(name string) error

Remove deletes the named context. It returns an error if name is DefaultContextName or if the context is currently active.

func (*Store) SetActive

func (s *Store) SetActive(name string) error

SetActive makes the named context active. Pass DefaultContextName to revert to auto-detection. The named context must already exist unless name is DefaultContextName.

type TLSConfig

type TLSConfig struct {
	// Enabled indicates whether TLS is used for this context.
	Enabled bool `json:"enabled"`
	// SkipVerify disables TLS server certificate verification.
	SkipVerify bool `json:"skipVerify,omitempty"`
	// CACert is the absolute path to a custom CA certificate PEM file.
	CACert string `json:"caCert,omitempty"`
}

TLSConfig holds optional TLS settings for a named context.

Jump to

Keyboard shortcuts

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