Documentation
¶
Overview ¶
Package amp implements the Amp CLI routing module, providing OAuth-based integration with Amp CLI for ChatGPT and Anthropic subscriptions.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AmpModule ¶
type AmpModule struct {
// contains filtered or unexported fields
}
AmpModule implements the RouteModuleV2 interface for Amp CLI integration. It provides:
- Reverse proxy to Amp control plane for OAuth/management
- Provider-specific route aliases (/api/provider/{provider}/...)
- Automatic gzip decompression for misconfigured upstreams
func New ¶
New creates a new Amp routing module with the given options. This is the preferred constructor using the Option pattern.
Example:
ampModule := amp.New(
amp.WithAccessManager(accessManager),
amp.WithAuthMiddleware(authMiddleware),
amp.WithSecretSource(customSecret),
)
func NewLegacy ¶
func NewLegacy(accessManager *sdkaccess.Manager, authMiddleware gin.HandlerFunc) *AmpModule
NewLegacy creates a new Amp routing module using the legacy constructor signature. This is provided for backwards compatibility.
DEPRECATED: Use New with options instead.
func (*AmpModule) OnConfigUpdated ¶
OnConfigUpdated handles configuration updates. Currently requires restart for URL changes (could be enhanced for dynamic updates).
type FallbackHandler ¶
type FallbackHandler struct {
// contains filtered or unexported fields
}
FallbackHandler wraps a standard handler with fallback logic to ampcode.com when the model's provider is not available in CLIProxyAPI
func NewFallbackHandler ¶
func NewFallbackHandler(getProxy func() *httputil.ReverseProxy) *FallbackHandler
NewFallbackHandler creates a new fallback handler wrapper The getProxy function allows lazy evaluation of the proxy (useful when proxy is created after routes)
func (*FallbackHandler) WrapHandler ¶
func (fh *FallbackHandler) WrapHandler(handler gin.HandlerFunc) gin.HandlerFunc
WrapHandler wraps a gin.HandlerFunc with fallback logic If the model's provider is not configured in CLIProxyAPI, it forwards to ampcode.com
type MultiSourceSecret ¶
type MultiSourceSecret struct {
// contains filtered or unexported fields
}
MultiSourceSecret implements precedence-based secret lookup: 1. Explicit config value (highest priority) 2. Environment variable AMP_API_KEY 3. File-based secret (lowest priority)
func NewMultiSourceSecret ¶
func NewMultiSourceSecret(explicitKey string, cacheTTL time.Duration) *MultiSourceSecret
NewMultiSourceSecret creates a secret source with precedence and caching
func NewMultiSourceSecretWithPath ¶
func NewMultiSourceSecretWithPath(explicitKey string, filePath string, cacheTTL time.Duration) *MultiSourceSecret
NewMultiSourceSecretWithPath creates a secret source with a custom file path (for testing)
func (*MultiSourceSecret) Get ¶
func (s *MultiSourceSecret) Get(ctx context.Context) (string, error)
Get retrieves the Amp API key using precedence: config > env > file Results are cached for cacheTTL duration to avoid excessive file reads
func (*MultiSourceSecret) InvalidateCache ¶
func (s *MultiSourceSecret) InvalidateCache()
InvalidateCache clears the cached secret, forcing a fresh read on next Get
type Option ¶
type Option func(*AmpModule)
Option configures the AmpModule.
func WithAccessManager ¶
WithAccessManager sets the access manager for the module.
func WithAuthMiddleware ¶
func WithAuthMiddleware(middleware gin.HandlerFunc) Option
WithAuthMiddleware sets the authentication middleware for provider routes.
func WithSecretSource ¶
func WithSecretSource(source SecretSource) Option
WithSecretSource sets a custom secret source for the module.
type SecretSource ¶
SecretSource provides Amp API keys with configurable precedence and caching
type StaticSecretSource ¶
type StaticSecretSource struct {
// contains filtered or unexported fields
}
StaticSecretSource returns a fixed API key (for testing)
func NewStaticSecretSource ¶
func NewStaticSecretSource(key string) *StaticSecretSource
NewStaticSecretSource creates a secret source with a fixed key