Documentation
¶
Overview ¶
Package synthesizer provides auth synthesis strategies for the watcher package. It implements the Strategy pattern to support multiple auth sources: - ConfigSynthesizer: generates Auth entries from config API keys - FileSynthesizer: generates Auth entries from OAuth JSON files
Index ¶
- func ApplyAuthExcludedModelsMeta(auth *coreauth.Auth, perKey []string, authKind string)
- func ExtractExcludedModelsFromMetadata(metadata map[string]any) ([]string, error)
- func GeminiConfigSource(auth *coreauth.Auth) string
- func LegacyGeminiConfigSource(auth *coreauth.Auth) string
- func SyncOAuthExcludedModelsAttributes(auth *coreauth.Auth) error
- func SynthesizeAuthFile(ctx *SynthesisContext, fullPath string, data []byte) ([]*coreauth.Auth, error)
- type AuthSynthesizer
- type ConfigSynthesizer
- type FileSynthesizer
- type PluginAuthParser
- type PluginMultiAuthParser
- type StableIDGenerator
- type SynthesisContext
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ApplyAuthExcludedModelsMeta ¶
ApplyAuthExcludedModelsMeta stores the credential's own excluded models on an auth entry. It computes a hash of excluded models and sets the auth_kind attribute. Global oauth-excluded-models are intentionally not merged here: they are resolved at model registration time, and a non-empty credential list overrides them.
func ExtractExcludedModelsFromMetadata ¶ added in v1.1.1
ExtractExcludedModelsFromMetadata reads per-account excluded models from the OAuth JSON metadata. Supports both "excluded_models" and "excluded-models" keys. The value must be a string array; a single string is also accepted for older hand-written files and is split on commas, because model IDs never contain commas. Any other type, or a non-string array element, is an error.
func GeminiConfigSource ¶ added in v1.0.70
GeminiConfigSource derives the current source from a stored Gemini credential identity.
func LegacyGeminiConfigSource ¶ added in v1.0.70
LegacyGeminiConfigSource returns the source used before Gemini routing fields became part of credential identity.
func SyncOAuthExcludedModelsAttributes ¶ added in v1.1.2
SyncOAuthExcludedModelsAttributes rebuilds the excluded_models attributes of an OAuth auth from its metadata, dropping stale values first because ApplyAuthExcludedModelsMeta never clears them. Invalid metadata returns an error and leaves the attributes untouched.
func SynthesizeAuthFile ¶
func SynthesizeAuthFile(ctx *SynthesisContext, fullPath string, data []byte) ([]*coreauth.Auth, error)
SynthesizeAuthFile generates Auth entries for one auth JSON file payload. It shares exactly the same mapping behavior as FileSynthesizer.Synthesize. Unsupported payloads yield no auths and a nil error; a recognized credential with an invalid excluded_models field yields an error naming the file.
Types ¶
type AuthSynthesizer ¶
type AuthSynthesizer interface {
// Synthesize generates Auth entries from the given context.
// Returns a slice of Auth pointers and any error encountered.
Synthesize(ctx *SynthesisContext) ([]*coreauth.Auth, error)
}
AuthSynthesizer defines the interface for generating Auth entries from various sources.
type ConfigSynthesizer ¶
type ConfigSynthesizer struct{}
ConfigSynthesizer generates Auth entries from configuration API keys. It handles Gemini, Interactions, Claude, Codex, xAI, Meta, OpenAI-compat, and Vertex-compat providers.
func NewConfigSynthesizer ¶
func NewConfigSynthesizer() *ConfigSynthesizer
NewConfigSynthesizer creates a new ConfigSynthesizer instance.
func (*ConfigSynthesizer) Synthesize ¶
func (s *ConfigSynthesizer) Synthesize(ctx *SynthesisContext) ([]*coreauth.Auth, error)
Synthesize generates Auth entries from config API keys.
type FileSynthesizer ¶
type FileSynthesizer struct{}
FileSynthesizer generates Auth entries from OAuth JSON files. It handles file-based authentication.
func NewFileSynthesizer ¶
func NewFileSynthesizer() *FileSynthesizer
NewFileSynthesizer creates a new FileSynthesizer instance.
func (*FileSynthesizer) Synthesize ¶
func (s *FileSynthesizer) Synthesize(ctx *SynthesisContext) ([]*coreauth.Auth, error)
Synthesize generates Auth entries from auth files in the auth directory.
type PluginAuthParser ¶ added in v1.0.39
type PluginAuthParser interface {
ParseAuth(context.Context, pluginapi.AuthParseRequest) (*coreauth.Auth, bool, error)
}
PluginAuthParser lets provider plugins parse auth file payloads.
type PluginMultiAuthParser ¶ added in v1.0.39
type PluginMultiAuthParser interface {
ParseAuths(context.Context, pluginapi.AuthParseRequest) ([]*coreauth.Auth, bool, error)
}
PluginMultiAuthParser expands one auth file payload into multiple plugin auth records.
type StableIDGenerator ¶
type StableIDGenerator struct {
// contains filtered or unexported fields
}
StableIDGenerator generates stable, deterministic IDs for auth entries. It uses SHA256 hashing with collision handling via counters. It is not safe for concurrent use.
func NewStableIDGenerator ¶
func NewStableIDGenerator() *StableIDGenerator
NewStableIDGenerator creates a new StableIDGenerator instance.
type SynthesisContext ¶
type SynthesisContext struct {
// Config is the current configuration
Config *config.Config
// AuthDir is the directory containing auth files
AuthDir string
// Now is the current time for timestamps
Now time.Time
// IDGenerator generates stable IDs for auth entries
IDGenerator *StableIDGenerator
// ClusterMode enables cluster UUID normalization for synthesized auth entries.
ClusterMode bool
// UUIDForAuth returns the cluster UUID for an auth entry.
UUIDForAuth func(auth *coreauth.Auth) string
// PluginAuthParser parses provider-specific plugin auth files.
PluginAuthParser PluginAuthParser
}
SynthesisContext provides the context needed for auth synthesis.