| package model |
|
|
| import ( |
| "strconv" |
| "strings" |
| "time" |
| ) |
|
|
| |
| const ( |
| LogSourceProxy = "proxy" |
| LogSourceScheduledCheck = "scheduled_check" |
| LogSourceManualTest = "manual_test" |
|
|
| LogSourceDetection = "detection" |
| LogSourceAll = "all" |
| ) |
|
|
| |
| func NormalizeStoredLogSource(raw string) string { |
| switch strings.TrimSpace(raw) { |
| case "", LogSourceProxy: |
| return LogSourceProxy |
| case LogSourceScheduledCheck: |
| return LogSourceScheduledCheck |
| case LogSourceManualTest: |
| return LogSourceManualTest |
| default: |
| return LogSourceProxy |
| } |
| } |
|
|
| |
| |
| type JSONTime struct { |
| time.Time |
| } |
|
|
| |
| func (jt JSONTime) MarshalJSON() ([]byte, error) { |
| if jt.IsZero() { |
| return []byte("0"), nil |
| } |
| return []byte(strconv.FormatInt(jt.Unix(), 10)), nil |
| } |
|
|
| |
| func (jt *JSONTime) UnmarshalJSON(data []byte) error { |
| if string(data) == "null" || string(data) == "0" { |
| jt.Time = time.Time{} |
| return nil |
| } |
| ts, err := strconv.ParseInt(string(data), 10, 64) |
| if err != nil { |
| return err |
| } |
| jt.Time = time.Unix(ts, 0) |
| return nil |
| } |
|
|
| |
| type LogEntry struct { |
| ID int64 `json:"id"` |
| Time JSONTime `json:"time"` |
| Model string `json:"model"` |
| ActualModel string `json:"actual_model,omitempty"` |
| LogSource string `json:"log_source,omitempty"` |
| ChannelID int64 `json:"channel_id"` |
| ChannelName string `json:"channel_name,omitempty"` |
| StatusCode int `json:"status_code"` |
| Message string `json:"message"` |
| Duration float64 `json:"duration"` |
| IsStreaming bool `json:"is_streaming"` |
| FirstByteTime float64 `json:"first_byte_time"` |
| APIKeyUsed string `json:"api_key_used"` |
| APIKeyHash string `json:"api_key_hash,omitempty"` |
| AuthTokenID int64 `json:"auth_token_id"` |
| AuthTokenDescription string `json:"auth_token_description"` |
| ClientIP string `json:"client_ip"` |
| BaseURL string `json:"base_url,omitempty"` |
| ServiceTier string `json:"service_tier,omitempty"` |
|
|
| |
| InputTokens int `json:"input_tokens"` |
| OutputTokens int `json:"output_tokens"` |
| CacheReadInputTokens int `json:"cache_read_input_tokens"` |
| CacheCreationInputTokens int `json:"cache_creation_input_tokens"` |
| Cache5mInputTokens int `json:"cache_5m_input_tokens"` |
| Cache1hInputTokens int `json:"cache_1h_input_tokens"` |
| Cost float64 `json:"cost"` |
| CostMultiplier float64 `json:"cost_multiplier"` |
|
|
| |
| DebugData *DebugLogEntry `json:"-"` |
| } |
|
|
| |
| type LogFilter struct { |
| ChannelID *int64 |
| ChannelName string |
| ChannelNameLike string |
| Model string |
| ModelLike string |
| StatusCode *int |
| ChannelType string |
| AuthTokenID *int64 |
| LogSource string |
| } |
|
|
| |
| |
| type ChannelURLLogStat struct { |
| ChannelID int64 |
| BaseURL string |
| Requests int64 |
| Failures int64 |
| LatencyMs float64 |
| LastSeen time.Time |
| } |
|
|