mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-02-03 04:50:52 +08:00
Add full Amp CLI support to enable routing AI model requests through the proxy
while maintaining Amp-specific features like thread management, user info, and
telemetry. Includes complete documentation and pull bot configuration.
Features:
- Modular architecture with RouteModule interface for clean integration
- Reverse proxy for Amp management routes (thread/user/meta/ads/telemetry)
- Provider-specific route aliases (/api/provider/{provider}/*)
- Secret management with precedence: config > env > file
- 5-minute secret caching to reduce file I/O
- Automatic gzip decompression for responses
- Proper connection cleanup to prevent leaks
- Localhost-only restriction for management routes (configurable)
- CORS protection for management endpoints
Documentation:
- Complete setup guide (USING_WITH_FACTORY_AND_AMP.md)
- OAuth setup for OpenAI (ChatGPT Plus/Pro) and Anthropic (Claude Pro/Max)
- Factory CLI config examples with all model variants
- Amp CLI/IDE configuration examples
- tmux setup for remote server deployment
- Screenshots and diagrams
Configuration:
- Pull bot disabled for this repo (manual rebase workflow)
- Config fields: AmpUpstreamURL, AmpUpstreamAPIKey, AmpRestrictManagementToLocalhost
- Compatible with upstream DisableCooling and other features
Technical details:
- internal/api/modules/amp/: Complete Amp routing module
- sdk/api/httpx/: HTTP utilities for gzip/transport
- 94.6% test coverage with 34 comprehensive test cases
- Clean integration minimizes merge conflict risk
Security:
- Management routes restricted to localhost by default
- Configurable via amp-restrict-management-to-localhost
- Prevents drive-by browser attacks on user data
This provides a production-ready foundation for Amp CLI integration while
maintaining clean separation from upstream code for easy rebasing.
Amp-Thread-ID: https://ampcode.com/threads/T-9e2befc5-f969-41c6-890c-5b779d58cf18
34 lines
1008 B
Go
34 lines
1008 B
Go
// Package httpx provides HTTP transport utilities for SDK clients,
|
|
// including automatic gzip decompression for misconfigured upstreams.
|
|
package httpx
|
|
|
|
import (
|
|
"bytes"
|
|
"compress/gzip"
|
|
"io"
|
|
)
|
|
|
|
// DecodePossibleGzip inspects the raw response body and transparently
|
|
// decompresses it when the payload is gzip compressed. Some upstream
|
|
// providers return gzip data without a Content-Encoding header, which
|
|
// confuses clients expecting JSON. This helper restores the original
|
|
// JSON bytes while leaving plain responses untouched.
|
|
//
|
|
// This function is preserved for backward compatibility but new code
|
|
// should use GzipFixupTransport instead.
|
|
func DecodePossibleGzip(raw []byte) ([]byte, error) {
|
|
if len(raw) >= 2 && raw[0] == 0x1f && raw[1] == 0x8b {
|
|
reader, err := gzip.NewReader(bytes.NewReader(raw))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
decompressed, err := io.ReadAll(reader)
|
|
_ = reader.Close()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return decompressed, nil
|
|
}
|
|
return raw, nil
|
|
}
|