| |
| |
| |
| package ports |
|
|
| import ( |
| "context" |
|
|
| "github.com/router-for-me/CLIProxyAPI/v6/internal/config" |
| ) |
|
|
| |
| type ConfigService interface { |
| |
| GetConfig(ctx context.Context) (*config.Config, error) |
|
|
| |
| UpdateConfig(ctx context.Context, cfg *config.Config) error |
|
|
| |
| UpdateField(ctx context.Context, field string, value interface{}) error |
|
|
| |
| UpdateAPIKeys(ctx context.Context, keys []string) error |
|
|
| |
| UpdateGeminiKeys(ctx context.Context, keys []config.GeminiKey) error |
|
|
| |
| UpdateClaudeKeys(ctx context.Context, keys []config.ClaudeKey) error |
|
|
| |
| UpdateCodexKeys(ctx context.Context, keys []config.CodexKey) error |
|
|
| |
| UpdateOpenAICompatibility(ctx context.Context, entries []config.OpenAICompatibility) error |
|
|
| |
| UpdateVertexCompatKeys(ctx context.Context, keys []config.VertexCompatKey) error |
|
|
| |
| UpdateKiroKeys(ctx context.Context, keys []config.KiroKey) error |
|
|
| |
| UpdateOAuthExcludedModels(ctx context.Context, models map[string][]string) error |
|
|
| |
| UpdateOAuthModelAlias(ctx context.Context, aliases map[string][]config.OAuthModelAlias) error |
|
|
| |
| UpdateAmpCode(ctx context.Context, ampCode config.AmpCode) error |
|
|
| |
| UpdateAmpUpstreamURL(ctx context.Context, url string) error |
|
|
| |
| UpdateAmpModelMappings(ctx context.Context, mappings []config.AmpModelMapping) error |
|
|
| |
| UpdateAmpUpstreamAPIKeys(ctx context.Context, keys []config.AmpUpstreamAPIKeyEntry) error |
|
|
| |
| UpdateDebug(ctx context.Context, enabled bool) error |
|
|
| |
| UpdateUsageStatisticsEnabled(ctx context.Context, enabled bool) error |
|
|
| |
| UpdateLoggingToFile(ctx context.Context, enabled bool) error |
|
|
| |
| UpdateLogsMaxTotalSizeMB(ctx context.Context, sizeMB int) error |
|
|
| |
| UpdateRequestLog(ctx context.Context, enabled bool) error |
|
|
| |
| UpdateWebsocketAuth(ctx context.Context, enabled bool) error |
|
|
| |
| UpdateRequestRetry(ctx context.Context, retry int) error |
|
|
| |
| UpdateMaxRetryInterval(ctx context.Context, interval int) error |
|
|
| |
| UpdateForceModelPrefix(ctx context.Context, enabled bool) error |
|
|
| |
| UpdateRoutingStrategy(ctx context.Context, strategy string) error |
|
|
| |
| UpdateProxyURL(ctx context.Context, url string) error |
|
|
| |
| UpdateRemoteManagement(ctx context.Context, allowRemote bool, secretHash string) error |
|
|
| |
| UpdateQuotaExceeded(ctx context.Context, switchProject, switchPreviewModel bool) error |
|
|
| |
| Validate(ctx context.Context) error |
|
|
| |
| ValidateConfig(ctx context.Context, cfg *config.Config) error |
|
|
| |
| GetLatestVersion(ctx context.Context) (string, error) |
| } |
|
|
| |
| type AuthFileService interface { |
| |
| ListAuthFiles(ctx context.Context) ([]*AuthFile, error) |
|
|
| |
| GetAuthFile(ctx context.Context, id string) (*AuthFile, error) |
|
|
| |
| GetAuthFileModels(ctx context.Context, id string) ([]*AuthFileModel, error) |
|
|
| |
| UploadAuthFile(ctx context.Context, filename string, data []byte) (*AuthFile, error) |
|
|
| |
| DownloadAuthFile(ctx context.Context, id string) ([]byte, error) |
|
|
| |
| DeleteAuthFile(ctx context.Context, id string) error |
|
|
| |
| DeleteAllAuthFiles(ctx context.Context) (int, error) |
|
|
| |
| DisableAuthFile(ctx context.Context, id string) error |
|
|
| |
| EnableAuthFile(ctx context.Context, id string) error |
|
|
| |
| RefreshAuthToken(ctx context.Context, id string) error |
| } |
|
|
| |
| type AuthFileModel struct { |
| ID string |
| DisplayName string |
| Type string |
| OwnedBy string |
| } |
|
|
| |
| type LogService interface { |
| |
| GetLogs(ctx context.Context, after int64, limit int) (*LogContent, error) |
|
|
| |
| DeleteLogs(ctx context.Context) (*DeleteLogResult, error) |
|
|
| |
| GetRequestErrorLogs(ctx context.Context) ([]*LogFileInfo, error) |
|
|
| |
| GetRequestLogByID(ctx context.Context, requestID string) ([]byte, error) |
|
|
| |
| DownloadRequestErrorLog(ctx context.Context, filename string) ([]byte, error) |
| } |
|
|
| |
| type UsageService interface { |
| |
| GetUsageStatistics(ctx context.Context) (*UsageStatistics, error) |
|
|
| |
| ExportUsageStatistics(ctx context.Context) (*UsageStatistics, error) |
|
|
| |
| ImportUsageStatistics(ctx context.Context, stats *UsageStatistics) (*ImportResult, error) |
| } |
|
|
| |
| type OAuthService interface { |
| |
| InitiateAuth(ctx context.Context, provider string, options *OAuthOptions) (*OAuthInitResult, error) |
|
|
| |
| CompleteAuth(ctx context.Context, state string, code string) (*AuthFile, error) |
|
|
| |
| GetAuthStatus(ctx context.Context, state string) (*OAuthSessionStatus, error) |
|
|
| |
| CancelAuth(ctx context.Context, state string) error |
| } |
|
|
| |
| type OAuthOptions struct { |
| IsWebUI bool |
| ProjectID string |
| Cookie string |
| } |
|
|
| |
| type OAuthInitResult struct { |
| AuthURL string |
| State string |
| } |
|
|
| |
| type OAuthSessionStatus struct { |
| State string |
| Status string |
| Error string |
| Provider string |
| } |
|
|
| |
| type ManagementService interface { |
| |
| VerifyManagementKey(ctx context.Context, key string, clientIP string) error |
|
|
| |
| IsRemoteAllowed(ctx context.Context, clientIP string) bool |
|
|
| |
| RecordFailedAttempt(ctx context.Context, clientIP string) |
|
|
| |
| IsBlocked(ctx context.Context, clientIP string) (bool, string) |
|
|
| |
| GetVersionInfo(ctx context.Context) (*VersionInfo, error) |
| } |
|
|
| |
| type VersionInfo struct { |
| Version string |
| Commit string |
| BuildDate string |
| } |
|
|
| |
| type APICallService interface { |
| |
| MakeAPICall(ctx context.Context, req *APICallRequest) (*APICallResponse, error) |
|
|
| |
| ResolveToken(ctx context.Context, authIndex string) (string, error) |
| } |
|
|
| |
| type APICallRequest struct { |
| AuthIndex string |
| Method string |
| URL string |
| Headers map[string]string |
| Body string |
| } |
|
|
| |
| type APICallResponse struct { |
| StatusCode int |
| Headers map[string][]string |
| Body string |
| } |
|
|