// Package ports defines service interfaces (input ports) for the domain layer. // These interfaces define the operations that can be performed on the domain // and are implemented by domain services. package ports import ( "context" "github.com/router-for-me/CLIProxyAPI/v6/internal/config" ) // ConfigService defines operations for configuration management type ConfigService interface { // GetConfig retrieves the current configuration GetConfig(ctx context.Context) (*config.Config, error) // UpdateConfig updates the entire configuration UpdateConfig(ctx context.Context, cfg *config.Config) error // UpdateField updates a single configuration field UpdateField(ctx context.Context, field string, value interface{}) error // UpdateAPIKeys updates the API keys list UpdateAPIKeys(ctx context.Context, keys []string) error // UpdateGeminiKeys updates the Gemini keys list UpdateGeminiKeys(ctx context.Context, keys []config.GeminiKey) error // UpdateClaudeKeys updates the Claude keys list UpdateClaudeKeys(ctx context.Context, keys []config.ClaudeKey) error // UpdateCodexKeys updates the Codex keys list UpdateCodexKeys(ctx context.Context, keys []config.CodexKey) error // UpdateOpenAICompatibility updates the OpenAI compatibility entries UpdateOpenAICompatibility(ctx context.Context, entries []config.OpenAICompatibility) error // UpdateVertexCompatKeys updates the Vertex compatibility keys UpdateVertexCompatKeys(ctx context.Context, keys []config.VertexCompatKey) error // UpdateKiroKeys updates the Kiro keys list UpdateKiroKeys(ctx context.Context, keys []config.KiroKey) error // UpdateOAuthExcludedModels updates OAuth excluded models UpdateOAuthExcludedModels(ctx context.Context, models map[string][]string) error // UpdateOAuthModelAlias updates OAuth model aliases UpdateOAuthModelAlias(ctx context.Context, aliases map[string][]config.OAuthModelAlias) error // UpdateAmpCode updates the AmpCode configuration UpdateAmpCode(ctx context.Context, ampCode config.AmpCode) error // UpdateAmpUpstreamURL updates the Amp upstream URL UpdateAmpUpstreamURL(ctx context.Context, url string) error // UpdateAmpModelMappings updates Amp model mappings UpdateAmpModelMappings(ctx context.Context, mappings []config.AmpModelMapping) error // UpdateAmpUpstreamAPIKeys updates Amp upstream API keys UpdateAmpUpstreamAPIKeys(ctx context.Context, keys []config.AmpUpstreamAPIKeyEntry) error // UpdateDebug updates the debug setting UpdateDebug(ctx context.Context, enabled bool) error // UpdateUsageStatisticsEnabled updates the usage statistics enabled setting UpdateUsageStatisticsEnabled(ctx context.Context, enabled bool) error // UpdateLoggingToFile updates the logging to file setting UpdateLoggingToFile(ctx context.Context, enabled bool) error // UpdateLogsMaxTotalSizeMB updates the max log size UpdateLogsMaxTotalSizeMB(ctx context.Context, sizeMB int) error // UpdateRequestLog updates the request log setting UpdateRequestLog(ctx context.Context, enabled bool) error // UpdateWebsocketAuth updates the websocket auth setting UpdateWebsocketAuth(ctx context.Context, enabled bool) error // UpdateRequestRetry updates the request retry count UpdateRequestRetry(ctx context.Context, retry int) error // UpdateMaxRetryInterval updates the max retry interval UpdateMaxRetryInterval(ctx context.Context, interval int) error // UpdateForceModelPrefix updates the force model prefix setting UpdateForceModelPrefix(ctx context.Context, enabled bool) error // UpdateRoutingStrategy updates the routing strategy UpdateRoutingStrategy(ctx context.Context, strategy string) error // UpdateProxyURL updates the proxy URL UpdateProxyURL(ctx context.Context, url string) error // UpdateRemoteManagement updates the remote management settings UpdateRemoteManagement(ctx context.Context, allowRemote bool, secretHash string) error // UpdateQuotaExceeded updates the quota exceeded settings UpdateQuotaExceeded(ctx context.Context, switchProject, switchPreviewModel bool) error // Validate validates the current configuration Validate(ctx context.Context) error // ValidateConfig validates a specific configuration ValidateConfig(ctx context.Context, cfg *config.Config) error // GetLatestVersion retrieves the latest version from GitHub GetLatestVersion(ctx context.Context) (string, error) } // AuthFileService defines operations for authentication file management type AuthFileService interface { // ListAuthFiles retrieves all authentication files ListAuthFiles(ctx context.Context) ([]*AuthFile, error) // GetAuthFile retrieves a single authentication file by ID GetAuthFile(ctx context.Context, id string) (*AuthFile, error) // GetAuthFileModels retrieves models supported by an auth file GetAuthFileModels(ctx context.Context, id string) ([]*AuthFileModel, error) // UploadAuthFile uploads a new authentication file UploadAuthFile(ctx context.Context, filename string, data []byte) (*AuthFile, error) // DownloadAuthFile retrieves the raw content of an auth file DownloadAuthFile(ctx context.Context, id string) ([]byte, error) // DeleteAuthFile deletes an authentication file DeleteAuthFile(ctx context.Context, id string) error // DeleteAllAuthFiles deletes all authentication files DeleteAllAuthFiles(ctx context.Context) (int, error) // DisableAuthFile disables an authentication file DisableAuthFile(ctx context.Context, id string) error // EnableAuthFile enables an authentication file EnableAuthFile(ctx context.Context, id string) error // RefreshAuthToken refreshes the token for an auth file RefreshAuthToken(ctx context.Context, id string) error } // AuthFileModel represents a model supported by an auth file type AuthFileModel struct { ID string DisplayName string Type string OwnedBy string } // LogService defines operations for log management type LogService interface { // GetLogs retrieves log entries with optional filtering GetLogs(ctx context.Context, after int64, limit int) (*LogContent, error) // DeleteLogs removes all log files DeleteLogs(ctx context.Context) (*DeleteLogResult, error) // GetRequestErrorLogs retrieves error request log files GetRequestErrorLogs(ctx context.Context) ([]*LogFileInfo, error) // GetRequestLogByID retrieves a specific request log by ID GetRequestLogByID(ctx context.Context, requestID string) ([]byte, error) // DownloadRequestErrorLog downloads a specific error log file DownloadRequestErrorLog(ctx context.Context, filename string) ([]byte, error) } // UsageService defines operations for usage statistics type UsageService interface { // GetUsageStatistics retrieves current usage statistics GetUsageStatistics(ctx context.Context) (*UsageStatistics, error) // ExportUsageStatistics exports statistics for backup ExportUsageStatistics(ctx context.Context) (*UsageStatistics, error) // ImportUsageStatistics imports statistics from backup ImportUsageStatistics(ctx context.Context, stats *UsageStatistics) (*ImportResult, error) } // OAuthService defines operations for OAuth authentication type OAuthService interface { // InitiateAuth initiates OAuth authentication for a provider InitiateAuth(ctx context.Context, provider string, options *OAuthOptions) (*OAuthInitResult, error) // CompleteAuth completes OAuth authentication with a code CompleteAuth(ctx context.Context, state string, code string) (*AuthFile, error) // GetAuthStatus retrieves the status of an OAuth session GetAuthStatus(ctx context.Context, state string) (*OAuthSessionStatus, error) // CancelAuth cancels an ongoing OAuth session CancelAuth(ctx context.Context, state string) error } // OAuthOptions contains options for OAuth initiation type OAuthOptions struct { IsWebUI bool ProjectID string Cookie string } // OAuthInitResult contains the result of OAuth initiation type OAuthInitResult struct { AuthURL string State string } // OAuthSessionStatus represents the status of an OAuth session type OAuthSessionStatus struct { State string Status string // "pending", "complete", "error" Error string Provider string } // ManagementService defines operations for management functionality type ManagementService interface { // VerifyManagementKey verifies a management key VerifyManagementKey(ctx context.Context, key string, clientIP string) error // IsRemoteAllowed checks if remote management is allowed for a client IsRemoteAllowed(ctx context.Context, clientIP string) bool // RecordFailedAttempt records a failed authentication attempt RecordFailedAttempt(ctx context.Context, clientIP string) // IsBlocked checks if a client IP is blocked IsBlocked(ctx context.Context, clientIP string) (bool, string) // GetVersionInfo retrieves version information GetVersionInfo(ctx context.Context) (*VersionInfo, error) } // VersionInfo contains version information type VersionInfo struct { Version string Commit string BuildDate string } // APICallService defines operations for API calls type APICallService interface { // MakeAPICall makes a generic HTTP API call MakeAPICall(ctx context.Context, req *APICallRequest) (*APICallResponse, error) // ResolveToken resolves a token for an auth index ResolveToken(ctx context.Context, authIndex string) (string, error) } // APICallRequest contains parameters for an API call type APICallRequest struct { AuthIndex string Method string URL string Headers map[string]string Body string } // APICallResponse contains the response from an API call type APICallResponse struct { StatusCode int Headers map[string][]string Body string }