Documentation
¶
Overview ¶
Package config provides configuration management for the OpenRouter CLI.
Index ¶
Constants ¶
const ( // DefaultModel is the default model to use when not configured. DefaultModel = "moonshotai/kimi-k2.5" // DefaultImageModel is the default model for image generation. DefaultImageModel = "google/gemini-2.5-flash-image" // DefaultStreamTimeout is the default timeout for streaming requests. DefaultStreamTimeout = 5 * time.Minute // StreamChunkTimeout is the timeout for waiting for a single chunk. // If no data is received within this time, the stream is considered hung. StreamChunkTimeout = 30 * time.Second // DefaultTerminalWidth is the default terminal width when auto-detection fails. DefaultTerminalWidth = 80 // EscDoublePressTimeout is the timeout for double-press ESC actions. EscDoublePressTimeout = 2 * time.Second // PreviewTruncateLength is the max length for session preview text. PreviewTruncateLength = 50 // StreamChannelBuffer is the buffer size for stream chunk channels. StreamChannelBuffer = 100 )
Default configuration values.
Variables ¶
var ErrSessionNotFound = errors.New("session not found")
ErrSessionNotFound is returned when a session cannot be found.
var GetConfigDir = func() (string, error) { configDir, err := os.UserConfigDir() if err != nil { return "", fmt.Errorf("failed to get user config directory: %w", err) } return filepath.Join(configDir, "openrouter"), nil }
GetConfigDir returns the platform-specific config directory for openrouter. This is a variable to allow mocking in tests.
var GetSessionDir = func() (string, error) { configDir, err := GetConfigDir() if err != nil { return "", err } return filepath.Join(configDir, "sessions"), nil }
GetSessionDir returns the directory where sessions are stored. This is a variable to allow mocking in tests.
Functions ¶
func GetConfigPath ¶
GetConfigPath returns the full path to the config file.
func PromptForAPIKey ¶
PromptForAPIKey interactively prompts the user for their API key.
Types ¶
type AppConfig ¶
type AppConfig struct {
// APIKey is the OpenRouter API key.
APIKey string
// DefaultModel is the default model to use.
DefaultModel string
// StreamTimeout is the timeout for streaming requests.
StreamTimeout time.Duration
// TerminalWidth is the terminal width (0 = auto-detect).
TerminalWidth int
}
AppConfig holds all runtime configuration.
func NewAppConfig ¶
func NewAppConfig() *AppConfig
NewAppConfig creates a new AppConfig with default values.
type Config ¶
type Config struct {
APIKey string `json:"api_key"`
DefaultModel string `json:"default_model,omitempty"`
DefaultImageModel string `json:"default_image_model,omitempty"`
}
Config holds the application configuration that is persisted to disk.
type Session ¶
type Session struct {
ID string `json:"id"`
Model string `json:"model,omitempty"` // Model used for this session
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
History []string `json:"history"` // User input history for arrow key navigation
Messages []SessionMessage `json:"messages"` // Full conversation for resume
}
Session represents a CLI session with its history.
func GetLatestSession ¶
GetLatestSession returns the most recently updated session.
func LoadSession ¶
LoadSession loads an existing session by ID.
func NewSession ¶
func NewSession() *Session
NewSession creates a new session with a generated UUID.
func (*Session) AppendHistory ¶
AppendHistory adds an entry to the history and saves.
func (*Session) AppendMessage ¶
AppendMessage adds a message to the conversation and saves.
type SessionMessage ¶
SessionMessage represents a message in the conversation.
type SessionSummary ¶
type SessionSummary struct {
ID string
Model string
CreatedAt time.Time
UpdatedAt time.Time
MessageCount int
Preview string // First user message, truncated to ~50 chars
}
SessionSummary represents a session for list display.
func ListSessions ¶
func ListSessions() ([]SessionSummary, error)
ListSessions returns summaries of all sessions sorted by UpdatedAt descending.