Documentation
¶
Index ¶
- Variables
- func CleanupTempFiles() error
- func CloseLogger() error
- func CountMessageTokens(params *MessageCreateParams) (int, error)
- func CountRequestTokens(bodyMap map[string]interface{}) int
- func CountResponseTokens(content string) int
- func CountTokens(text string) (int, error)
- func DirExists(path string) bool
- func EnsureDir(path string) error
- func FileExists(path string) bool
- func GetEncoder() (*tiktoken.Tiktoken, error)
- func GetEnvironmentVariableDocumentation() string
- func GetExecutablePath() (string, error)
- func GetHomeDir() (string, error)
- func GetLogger() *logrus.Logger
- func GetReferenceCountPath() (string, error)
- func GetTempFile(prefix string) (string, error)
- func GetTimestamp() int64
- func InitLogger(config *LogConfig) error
- func InitTokenizer() error
- func LogRequest(method, path string, fields map[string]interface{})
- func LogResponse(statusCode int, duration float64, fields map[string]interface{})
- func LogRouting(model, provider, reason string)
- func LogShutdown(reason string)
- func LogStartup(port int, version string)
- func LogTransformer(name, direction string, success bool, err error)
- func MaskAPIKey(key string) string
- func ResolveConfigPath(path string) (string, error)
- func ResolvePath(path string) (string, error)
- func RotateLogFile(maxSize int64) error
- func ToJSONString(v interface{}) string
- func ValidateBoolean(value string) error
- func ValidateBooleanFlag(value string) error
- func ValidateDirectoryPath(value string) error
- func ValidateEnvironmentVariables() error
- func ValidateFilePath(value string) error
- func ValidateHostAddress(value string) error
- func ValidatePort(value string) error
- func ValidateSpawnDepth(value string) error
- func ValidateURL(value string) error
- func WriteFileAtomic(path string, data []byte, perm os.FileMode) error
- type EnvVar
- type HomeDir
- type LogConfig
- type Message
- type MessageContent
- type MessageCreateParams
- type SystemContent
- type TextContent
- type Tool
- type ToolResultContent
- type ToolUseContent
- type ValidationDetail
- type ValidationReport
Constants ¶
This section is empty.
Variables ¶
var EnvironmentVariables = []EnvVar{ { Name: "CCPROXY_SPAWN_DEPTH", Description: "Tracks the depth of process spawning to prevent infinite loops", Required: false, DefaultValue: "0", ValidateFunc: ValidateSpawnDepth, }, { Name: "CCPROXY_FOREGROUND", Description: "Set to '1' to indicate the process is running in foreground mode", Required: false, DefaultValue: "0", ValidateFunc: ValidateBooleanFlag, }, { Name: "CCPROXY_TEST_MODE", Description: "Set to '1' to enable test mode which disables background spawning", Required: false, DefaultValue: "0", ValidateFunc: ValidateBooleanFlag, }, { Name: "CCPROXY_VERSION", Description: "Override the version string reported by the server", Required: false, DefaultValue: "", ValidateFunc: nil, }, { Name: "CCPROXY_HOST", Description: "Host address to bind the server to", Required: false, DefaultValue: "127.0.0.1", ValidateFunc: ValidateHostAddress, }, { Name: "CCPROXY_PORT", Description: "Port number to bind the server to", Required: false, DefaultValue: "3456", ValidateFunc: ValidatePort, }, { Name: "CCPROXY_LOG", Description: "Enable logging (true/false)", Required: false, DefaultValue: "false", ValidateFunc: ValidateBoolean, }, { Name: "CCPROXY_LOG_FILE", Description: "Path to the log file", Required: false, DefaultValue: "", ValidateFunc: ValidateFilePath, }, { Name: "CCPROXY_API_KEY", Description: "API key for authentication", Required: false, DefaultValue: "", ValidateFunc: nil, }, { Name: "CCPROXY_PROXY_URL", Description: "HTTP/HTTPS proxy URL for outbound connections", Required: false, DefaultValue: "", ValidateFunc: ValidateURL, }, { Name: "CCPROXY_HOME", Description: "Home directory for CCProxy (used in tests)", Required: false, DefaultValue: "", ValidateFunc: ValidateDirectoryPath, }, { Name: "CCPROXY_CONFIG_DIR", Description: "Configuration directory path (used in tests)", Required: false, DefaultValue: "", ValidateFunc: ValidateDirectoryPath, }, { Name: "CCPROXY_DATA_DIR", Description: "Data directory path (used in tests)", Required: false, DefaultValue: "", ValidateFunc: ValidateDirectoryPath, }, { Name: "CCPROXY_LOG_DIR", Description: "Log directory path (used in tests)", Required: false, DefaultValue: "", ValidateFunc: ValidateDirectoryPath, }, { Name: "CCPROXY_PID_FILE", Description: "PID file path (used in tests)", Required: false, DefaultValue: "", ValidateFunc: ValidateFilePath, }, }
EnvironmentVariables defines all CCProxy environment variables
Functions ¶
func CleanupTempFiles ¶
func CleanupTempFiles() error
CleanupTempFiles removes old temporary files from the temp directory
func CountMessageTokens ¶
func CountMessageTokens(params *MessageCreateParams) (int, error)
CountMessageTokens counts tokens in a MessageCreateParams structure
func CountRequestTokens ¶
CountRequestTokens estimates token count for a request This is a simplified implementation - in production you would use tiktoken-go
func CountResponseTokens ¶
CountResponseTokens estimates token count for a response
func CountTokens ¶
CountTokens counts the number of tokens in a string
func GetEncoder ¶
GetEncoder returns the initialized encoder
func GetEnvironmentVariableDocumentation ¶
func GetEnvironmentVariableDocumentation() string
GetEnvironmentVariableDocumentation returns a formatted string documenting all environment variables
func GetExecutablePath ¶
GetExecutablePath returns the path to the current executable
func GetHomeDir ¶
GetHomeDir returns the CCProxy home directory path
func GetReferenceCountPath ¶
GetReferenceCountPath returns the path to the reference count file
func GetTempFile ¶
GetTempFile returns a path for a temporary file in the CCProxy temp directory
func InitTokenizer ¶
func InitTokenizer() error
InitTokenizer initializes the tiktoken encoder with cl100k_base encoding
func LogRequest ¶
LogRequest logs an HTTP request
func LogResponse ¶
LogResponse logs an HTTP response
func LogTransformer ¶
LogTransformer logs transformer operations
func ResolveConfigPath ¶
ResolveConfigPath resolves a configuration file path
func ResolvePath ¶
ResolvePath resolves a path, handling both absolute and relative paths
func ToJSONString ¶
func ToJSONString(v interface{}) string
ToJSONString converts an interface{} to a JSON string
func ValidateBoolean ¶
ValidateBoolean validates boolean environment variables
func ValidateBooleanFlag ¶
ValidateBooleanFlag validates environment variables that should be "0" or "1"
func ValidateDirectoryPath ¶
ValidateDirectoryPath validates directory path (basic validation)
func ValidateEnvironmentVariables ¶
func ValidateEnvironmentVariables() error
ValidateEnvironmentVariables validates all defined environment variables
func ValidateFilePath ¶
ValidateFilePath validates file path (basic validation)
func ValidateHostAddress ¶
ValidateHostAddress validates host address (basic validation)
func ValidateSpawnDepth ¶
ValidateSpawnDepth validates the CCPROXY_SPAWN_DEPTH environment variable
func ValidateURL ¶
ValidateURL validates URL format (basic validation)
Types ¶
type EnvVar ¶
type EnvVar struct {
Name string
Description string
Required bool
DefaultValue string
ValidateFunc func(value string) error
}
EnvVar represents an environment variable with validation rules
type HomeDir ¶
type HomeDir struct {
Root string
ConfigPath string
LogPath string
PIDPath string
PluginsDir string
TempDir string
}
HomeDir represents the CCProxy home directory structure
func InitializeHomeDir ¶
InitializeHomeDir creates and initializes the CCProxy home directory structure
type LogConfig ¶
type LogConfig struct {
Enabled bool
FilePath string
Level string
Format string // "json" or "text"
}
LogConfig represents logging configuration
type Message ¶
type Message struct {
Role string `json:"role"`
Content interface{} `json:"content"` // Can be string or array of content objects
}
Message represents a message in the conversation
type MessageContent ¶
type MessageContent interface{}
MessageContent represents content that can be either string or array
type MessageCreateParams ¶
type MessageCreateParams struct {
Model string `json:"model"`
Messages []Message `json:"messages"`
System interface{} `json:"system,omitempty"` // Can be string or []SystemContent
Tools []Tool `json:"tools,omitempty"`
Stream bool `json:"stream,omitempty"`
}
MessageCreateParams represents the parameters for creating a message
type SystemContent ¶
SystemContent represents system message content
type TextContent ¶
TextContent represents text content in a message
type Tool ¶
type Tool struct {
Name string `json:"name"`
Description string `json:"description,omitempty"`
InputSchema interface{} `json:"input_schema,omitempty"`
}
Tool represents a tool with its schema
type ToolResultContent ¶
type ToolResultContent struct {
Type string `json:"type"`
ToolUse string `json:"tool_use_id"`
Content interface{} `json:"content"`
}
ToolResultContent represents tool result in a message
type ToolUseContent ¶
type ToolUseContent struct {
Type string `json:"type"`
ID string `json:"id"`
Name string `json:"name"`
Input interface{} `json:"input"`
}
ToolUseContent represents tool use in a message
type ValidationDetail ¶
ValidationDetail contains details about a specific environment variable validation
type ValidationReport ¶
type ValidationReport struct {
Valid bool
Errors []string
Details map[string]ValidationDetail
}
ValidationReport represents the result of environment variable validation
func ValidateEnvironmentVariablesWithReport ¶
func ValidateEnvironmentVariablesWithReport() *ValidationReport
ValidateEnvironmentVariablesWithReport validates all environment variables and returns a detailed report