feat: 十轮网关优化 - 安全加固/可观测性/性能/可靠性
CI / lint (push) Has been cancelled
CI / test (push) Has been cancelled
CI / build (push) Has been cancelled
CI / security-scan (push) Has been cancelled

- SSE Keepalive Ping (15s心跳防止代理断连)
- Timing HTTP 头 (X-Timing-Queue/Inference/Total-Ms)
- Adapter Request-ID 传播到后端
- Session 清理日志回调
- Server 安全加固 (ReadHeaderTimeout/MaxHeaderBytes 防 slowloris)
- Usage Tracker 数据保留清理 (retentionDays + 定期清理)
- Config Reload 后 Adapter Registry 更新 (RegisterIfAbsent + RWMutex)
- Rate Limiter 空闲 Bucket 清理 (30分钟过期)
- Shutdown Drain 超时可配置 (ShutdownDrainSeconds)
- Config 模型字段校验增强 (provider/endpoint/actual_model)
- Auth 过期 Key 自动清理 (5分钟扫描)
- Admin API Rate Limiting
- Adapter Health Check 独立超时 (每个 adapter 3s)
- TCP 连接阶段超时 (DialContext 5s + KeepAlive 30s)
- 幂等键缓存、审计日志、Gzip 中间件、CORS Expose Headers
- Backpressure 响应头、熔断器 Prometheus 指标
- 连接池优化、Trace-ID 全链路传播
This commit is contained in:
selfrelease
2026-08-03 15:43:11 +08:00
parent e7e98271d4
commit da9c8334d8
27 changed files with 3002 additions and 309 deletions
+18 -4
View File
@@ -7,8 +7,9 @@ import (
// Assembler assembles context messages for a chat request.
type Assembler struct {
estimator *TokenEstimator
cfg *config.ContextConfig
estimator *TokenEstimator
cfg *config.ContextConfig
summarizer *Summarizer
}
// NewAssembler creates a new context assembler.
@@ -19,6 +20,11 @@ func NewAssembler(cfg *config.ContextConfig) *Assembler {
}
}
// SetSummarizer 注入摘要器,启用后 trimSummaryAndRecent 策略将生成真实 LLM 摘要。
func (a *Assembler) SetSummarizer(s *Summarizer) {
a.summarizer = s
}
// AssembleResult contains the assembled messages and metadata.
type AssembleResult struct {
Messages []api.Message
@@ -143,13 +149,21 @@ func (a *Assembler) trimSummaryAndRecent(messages []api.Message, budget int) tri
recentTokens += msgTokens
}
// Add summary placeholder if we trimmed anything
// Add summary if we trimmed anything
result := make([]api.Message, 0, len(systemMsgs)+1+len(recentMsgs))
result = append(result, systemMsgs...)
if len(recentMsgs) < len(rest) {
// 被裁剪的老消息
trimmedMsgs := rest[:len(rest)-len(recentMsgs)]
var summaryText string
if a.summarizer != nil {
summaryText = a.summarizer.Summarize(trimmedMsgs)
} else {
summaryText = "[Earlier conversation history has been summarized and omitted.]"
}
result = append(result, api.Message{
Role: "system",
Content: "[Earlier conversation history has been summarized and omitted.]",
Content: summaryText,
})
}
result = append(result, recentMsgs...)