Documentation
¶
Overview ¶
Package picompat provides compatibility for importing configurations from pi.
Package picompat provides compatibility for importing configurations from pi.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CheckExists ¶
func CheckExists() bool
CheckExists checks if pi config directory and auth.json exist.
func ComputeSourceHash ¶
ComputeSourceHash computes a truncated SHA-256 hash of the source files.
func DefaultPiDir ¶
func DefaultPiDir() string
DefaultPiDir returns the default pi config directory.
Types ¶
type AuthCredentials ¶
AuthCredentials maps provider names to their credentials.
func LoadAuth ¶
func LoadAuth(piDir string) (AuthCredentials, error)
LoadAuth reads the pi auth.json file.
type AuthEntry ¶
type AuthEntry struct {
// OAuth fields
AuthType string `json:"type,omitempty"`
AccessToken string `json:"access,omitempty"` // pi oauth
RefreshToken string `json:"refresh,omitempty"` // pi oauth
// API-key fields — pi uses "key"; some versions use "api_key"
Key string `json:"key,omitempty"`
APIKey string `json:"api_key,omitempty"`
Expires int64 `json:"expires,omitempty"` // epoch milliseconds
}
AuthEntry represents a single credential entry in auth.json. Pi uses several field-name conventions across versions:
- OAuth entries use "access" (token) and "refresh"
- API-key entries use "key" (preferred) or "api_key"
- The "type" field is "oauth" or "api_key"
func (AuthEntry) ResolvedKey ¶
ResolvedKey returns the usable credential: the OAuth access token for oauth entries, or the API key for api_key entries. Returns "" if nothing is set.
func (*AuthEntry) TokenExpiryStatus ¶
TokenExpiryStatus returns the expiry status of a credential. Returns hours remaining if not expired, negative if expired, and a warning message.
type ModelDefinition ¶
type ModelDefinition struct {
ID string `json:"id,omitempty"`
Provider string `json:"provider,omitempty"`
Name string `json:"name,omitempty"`
}
ModelDefinition represents a model entry in models.json.
type ModelsConfig ¶
type ModelsConfig struct {
Providers []ProviderDefinition `json:"providers,omitempty"`
Models []ModelDefinition `json:"models,omitempty"`
}
ModelsConfig represents the pi models.json file.
func LoadModels ¶
func LoadModels(piDir string) (*ModelsConfig, error)
LoadModels reads the pi models.json file.
func (*ModelsConfig) GetProviderByName ¶
func (m *ModelsConfig) GetProviderByName(name string) *ProviderDefinition
GetProviderByName finds a provider definition by name.
func (*ModelsConfig) UnmarshalJSON ¶
func (m *ModelsConfig) UnmarshalJSON(data []byte) error
type ProviderDefinition ¶
type ProviderDefinition struct {
Name string `json:"name,omitempty"`
Provider string `json:"provider,omitempty"`
BaseURL string `json:"baseUrl,omitempty"`
APIKey string `json:"api_key,omitempty"`
API string `json:"api,omitempty"` // e.g., "openai-completions", "anthropic"
Models []string `json:"models,omitempty"`
Title string `json:"title,omitempty"`
Description string `json:"description,omitempty"`
Extra map[string]interface{} `json:"extra,omitempty"`
}
ProviderDefinition represents a provider in models.json.
func (*ProviderDefinition) UnmarshalJSON ¶
func (p *ProviderDefinition) UnmarshalJSON(data []byte) error
type ProviderMapping ¶
type ProviderMapping struct {
AgentName string // name in agent config
Type string // agent type, e.g. "anthropic", "openai", "openrouter"
BaseURL string // default URL if not specified in pi
}
ProviderMapping maps pi provider names to agent configurations.
type Settings ¶
type Settings struct {
DefaultProvider string `json:"defaultProvider,omitempty"`
DefaultModel string `json:"defaultModel,omitempty"`
MaxIterations int `json:"max_iterations,omitempty"`
}
Settings represents the pi settings.json file.
func LoadSettings ¶
LoadSettings reads the pi settings.json file.
type TranslationResult ¶
type TranslationResult struct {
Providers map[string]agentConfig.ProviderConfig
Default string
Warnings Warnings
}
TranslationResult contains the result of translating pi config to agent config.
func Translate ¶
func Translate(piDir string) (*TranslationResult, error)
Translate merges pi auth, models, and settings into agent provider configs. It implements the two-source merge algorithm from SD-007.