synthesizer

package
v6.6.29 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2025 License: MIT Imports: 13 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyAuthExcludedModelsMeta

func ApplyAuthExcludedModelsMeta(auth *coreauth.Auth, cfg *config.Config, perKey []string, authKind string)

ApplyAuthExcludedModelsMeta applies excluded models metadata to an auth entry. It computes a hash of excluded models and sets the auth_kind attribute.

func SynthesizeGeminiVirtualAuths

func SynthesizeGeminiVirtualAuths(primary *coreauth.Auth, metadata map[string]any, now time.Time) []*coreauth.Auth

SynthesizeGeminiVirtualAuths creates virtual Auth entries for multi-project Gemini credentials. It disables the primary auth and creates one virtual auth per project.

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, Claude, Codex, 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 and Gemini virtual auth generation.

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 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.

func (*StableIDGenerator) Next

func (g *StableIDGenerator) Next(kind string, parts ...string) (string, string)

Next generates a stable ID based on the kind and parts. Returns the full ID (kind:hash) and the short hash portion.

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
}

SynthesisContext provides the context needed for auth synthesis.

Jump to

Keyboard shortcuts

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