Documentation
¶
Overview ¶
internal/pkg/protocol/sync_routing.go
internal/pkg/protocol/sync_user.go
Index ¶
- type CacheEntityStats
- type FetchEntityRequest
- type FetchEntityResponse
- type ForceFullSyncResponse
- type FullSyncRequest
- type FullSyncResponse
- type GetVersionResponse
- type HeartbeatParams
- type RoutingMember
- type SyncPushParams
- type SyncedRouting
- type SyncedUser
- type UsageLogEntry
- type UsageReport
- type UserRoutingMap
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CacheEntityStats ¶
type CacheEntityStats struct {
Hits int64 `json:"hits"`
Misses int64 `json:"misses"`
Evictions int64 `json:"evictions"`
NegativeHits int64 `json:"negative_hits"`
Size int `json:"size"`
Capacity int `json:"capacity"`
}
CacheEntityStats 是单个实体缓存的运行统计。 LRU 模式实体上报全字段;Full 模式实体仅 Size 有意义、其他字段为 0。
type FetchEntityRequest ¶
FetchEntityRequest 是 sync.fetchEntity 的入参。 Entity 取 events.Entity* 常量;Key 由各实体 handler 解读 (token: API key 字符串;user: id 字符串)。
type FetchEntityResponse ¶
type FetchEntityResponse struct {
Found bool `json:"found"`
Data json.RawMessage `json:"data,omitempty"`
Side json.RawMessage `json:"side,omitempty"`
}
FetchEntityResponse 是 sync.fetchEntity 的响应。 Found=false 表示 master 也未查到;调用方应进入负缓存。 Side 是可选旁路负载(如 token 响应附带的 SyncedUser),由 agent 端 fetcher 解读。
type ForceFullSyncResponse ¶
type FullSyncRequest ¶
type FullSyncResponse ¶
type GetVersionResponse ¶
type GetVersionResponse struct {
Version int64 `json:"version"`
}
type HeartbeatParams ¶
type HeartbeatParams struct {
Uptime int64 `json:"uptime"`
CachedTokens int `json:"cached_tokens"`
CachedChannels int `json:"cached_channels"`
CachedModels int `json:"cached_models"`
CachedGlobalRoutings int `json:"cached_global_routings"`
CachedUserRoutings int `json:"cached_user_routings"`
ActiveConnections int `json:"active_connections"`
Version int64 `json:"version"`
HTTPAddresses json.RawMessage `json:"http_addresses,omitempty"`
Tags string `json:"tags,omitempty"`
ProxyURL string `json:"proxy_url,omitempty"`
ListenPort int `json:"listen_port,omitempty"`
CacheStats map[string]CacheEntityStats `json:"cache_stats,omitempty"`
}
type RoutingMember ¶
type RoutingMember struct {
Ref string `json:"ref"`
Priority int `json:"priority"`
Weight int `json:"weight"`
}
RoutingMember 与 models.RoutingMember 字段一致。protocol 包独立定义避免反向依赖 models 包。
type SyncPushParams ¶
type SyncedRouting ¶
type SyncedRouting struct {
ID uint `json:"id"`
Name string `json:"name"`
Scope string `json:"scope"`
UserID uint `json:"user_id"`
Members []RoutingMember `json:"members"`
Enabled bool `json:"enabled"`
}
SyncedRouting 是 master 推送给 agent 的 ModelRouting 投影。 与 models.ModelRouting 保持字段对等,但脱离 GORM 依赖(agent 端不需要持久化)。
type SyncedUser ¶
SyncedUser 是 master 推送给 agent 的精简 User 投影。 只包含鉴权所需字段,不暴露 Password / Quota / Username。
type UsageLogEntry ¶
type UsageLogEntry struct {
RequestID string `json:"request_id"`
UserID uint `json:"user_id"`
TokenID uint `json:"token_id"`
ChannelID uint `json:"channel_id"`
ModelName string `json:"model_name"`
PromptTokens int `json:"prompt_tokens"`
CompletionTokens int `json:"completion_tokens"`
IsStream bool `json:"is_stream"`
Duration int `json:"duration"`
ClientIP string `json:"client_ip"`
Timestamp int64 `json:"timestamp"`
// Enhanced logging fields
TokenName string `json:"token_name"`
UpstreamModel string `json:"upstream_model"`
FirstResponseMs int `json:"first_response_ms"`
CacheReadTokens int `json:"cache_read_tokens"`
CacheWriteTokens int `json:"cache_write_tokens"`
InboundProtocol string `json:"inbound_protocol"`
OutboundProtocol string `json:"outbound_protocol"`
UseLegacy bool `json:"use_legacy"`
Status int `json:"status"`
ErrorMessage string `json:"error_message,omitempty"`
TraceData string `json:"trace_data,omitempty"`
Other string `json:"other"`
TokenSource string `json:"token_source,omitempty"`
RoutingName string `json:"routing_name,omitempty"`
ErrorStage string `json:"error_stage,omitempty"`
InboundDecodeMs int `json:"inbound_decode_ms,omitempty"`
OutboundEncodeMs int `json:"outbound_encode_ms,omitempty"`
UpstreamDispatchMs int `json:"upstream_dispatch_ms,omitempty"`
UpstreamDecodeMs int `json:"upstream_decode_ms,omitempty"`
ClientEncodeMs int `json:"client_encode_ms,omitempty"`
}
type UsageReport ¶
type UsageReport struct {
AgentID string `json:"agent_id"`
Logs []UsageLogEntry `json:"logs"`
}
type UserRoutingMap ¶
type UserRoutingMap struct {
Routings map[string]*SyncedRouting `json:"routings"`
}
UserRoutingMap 是单个用户的 routing 集合(name → routing), 按用户整体存取,避免每条 user routing 单独缓存。 放在 protocol 包是因为 loaders 与 cache 都需要引用此类型, 而 loaders 包不能反向 import cache。