amp

package
v6.5.1 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2025 License: MIT Imports: 26 Imported by: 0

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

func New(opts ...Option) *AmpModule

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) Name

func (m *AmpModule) Name() string

Name returns the module identifier

func (*AmpModule) OnConfigUpdated

func (m *AmpModule) OnConfigUpdated(cfg *config.Config) error

OnConfigUpdated handles configuration updates. Currently requires restart for URL changes (could be enhanced for dynamic updates).

func (*AmpModule) Register

func (m *AmpModule) Register(ctx modules.Context) error

Register sets up Amp routes if configured. This implements the RouteModuleV2 interface with Context. Routes are registered only once via sync.Once for idempotent behavior.

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

func WithAccessManager(am *sdkaccess.Manager) Option

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

type SecretSource interface {
	Get(ctx context.Context) (string, error)
}

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

func (*StaticSecretSource) Get

Get returns the static API key

Jump to

Keyboard shortcuts

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