config

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2026 License: BSD-3-Clause Imports: 5 Imported by: 0

Documentation

Overview

Package config 提供 LLM 供应商配置相关类型。

Package config provides a generic dual-file JSON configuration manager. It uses two files: config.json (for machine-synced settings) and local_settings.json (for machine-local settings). Application-specific types should be added via GetSetting/SetSetting or by wrapping this manager in the application layer.

Index

Constants

View Source
const (
	ProviderOpenAI    = "openai"
	ProviderAnthropic = "anthropic"
	ProviderGemini    = "gemini"
)

ProviderType 常量。

Variables

This section is empty.

Functions

func CollectAllKeys

func CollectAllKeys(nodes []ToolTreeNode) []string

CollectAllKeys recursively collects all keys from a tool tree.

func CollectDescendantKeys

func CollectDescendantKeys(nodes []ToolTreeNode, key string) []string

CollectDescendantKeys collects all descendant keys (including the node itself) for a given key in the tree. Returns nil if not found.

func FindNodeAncestors

func FindNodeAncestors(nodes []ToolTreeNode, key string) []string

FindNodeAncestors finds the path from root to a node by key. Returns nil if not found.

Types

type ConfigManager

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

ConfigManager manages two JSON config files:

  • config.json: cross-machine settings (e.g., LLM providers)
  • local_settings.json: machine-local settings (e.g., paths, preferences)

func NewConfigManager

func NewConfigManager(appDataDir string) *ConfigManager

NewConfigManager creates a ConfigManager for the given app data directory.

func (*ConfigManager) AddLLMProvider

func (cm *ConfigManager) AddLLMProvider(p map[string]any) (string, error)

AddLLMProvider adds an LLM provider config and returns its generated ID.

func (*ConfigManager) DeleteLLMProvider

func (cm *ConfigManager) DeleteLLMProvider(id string) error

DeleteLLMProvider removes an LLM provider by ID.

func (*ConfigManager) GetCachedModels

func (cm *ConfigManager) GetCachedModels(providerID string) []any

GetCachedModels returns cached models for a provider.

func (*ConfigManager) GetConfig

func (cm *ConfigManager) GetConfig() map[string]any

GetConfig returns a snapshot of the entire config.json as a map.

func (*ConfigManager) GetDefaultLLMID

func (cm *ConfigManager) GetDefaultLLMID() string

GetDefaultLLMID returns the default LLM provider ID.

func (*ConfigManager) GetLLMProviders

func (cm *ConfigManager) GetLLMProviders() []map[string]any

GetLLMProviders returns all LLM providers as a slice.

func (*ConfigManager) GetLocalAny

func (cm *ConfigManager) GetLocalAny(key string) any

GetLocalAny returns a value from local_settings.json by key.

func (*ConfigManager) GetLocalString

func (cm *ConfigManager) GetLocalString(key string) string

GetLocalString returns a string from local_settings.json.

func (*ConfigManager) GetSelectedModels

func (cm *ConfigManager) GetSelectedModels(providerID string) []any

GetSelectedModels returns selected model IDs for a provider.

func (*ConfigManager) GetSetting

func (cm *ConfigManager) GetSetting(name string) map[string]any

GetSetting returns the raw content of a config file as a flat map. name: "config" → config.json, "local_settings" → local_settings.json.

func (*ConfigManager) Load

func (cm *ConfigManager) Load() error

Load reads both config files from disk. If config.json doesn't exist, it creates one with defaults and saves it.

func (*ConfigManager) Save

func (cm *ConfigManager) Save() error

Save persists the config.json to disk.

func (*ConfigManager) SetCachedModels

func (cm *ConfigManager) SetCachedModels(providerID string, models []any) error

SetCachedModels caches model list for a provider.

func (*ConfigManager) SetDefaultLLM

func (cm *ConfigManager) SetDefaultLLM(id string) error

SetDefaultLLM sets the default LLM provider ID.

func (*ConfigManager) SetLocalAny

func (cm *ConfigManager) SetLocalAny(key string, value any) error

SetLocalAny sets a value in local_settings.json and saves.

func (*ConfigManager) SetLocalString

func (cm *ConfigManager) SetLocalString(key, value string) error

SetLocalString sets a string in local_settings.json and saves.

func (*ConfigManager) SetSelectedModels

func (cm *ConfigManager) SetSelectedModels(providerID string, models []any) error

SetSelectedModels saves selected model IDs for a provider.

func (*ConfigManager) SetSetting

func (cm *ConfigManager) SetSetting(name string, data map[string]any) error

SetSetting merges data into the specified config file and saves it. name: "config" → config.json, "local_settings" → local_settings.json. Merges top-level keys only; nested maps are replaced, not deep-merged.

func (*ConfigManager) UpdateLLMProvider

func (cm *ConfigManager) UpdateLLMProvider(id string, p map[string]any) error

UpdateLLMProvider updates an existing LLM provider by ID.

type LLMProviderConfig

type LLMProviderConfig struct {
	ID           string   `json:"id"`
	Name         string   `json:"name"`
	ProviderType string   `json:"provider_type"` // openai, anthropic, gemini
	BaseURL      string   `json:"base_url"`
	APIKey       string   `json:"-"` // 不序列化,由 credential 管理
	Models       []string `json:"models"`
	Enabled      bool     `json:"enabled"`
	WorkspaceID  string   `json:"workspace_id,omitempty"`
}

LLMProviderConfig LLM 供应商配置。

type ToolTreeNode

type ToolTreeNode struct {
	Key      string         `json:"key"`                // Node key for enabled-state storage
	Label    string         `json:"label"`              // Display label
	Children []ToolTreeNode `json:"children,omitempty"` // Child nodes
}

ToolTreeNode represents a node in the tool configuration tree. Application-specific tool trees should be defined in the application layer using this type and the Helper functions below.

Jump to

Keyboard shortcuts

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