ad38beeb9e
CI / docker (push) Successful in 11m2s
引入用户端对话/生图与管理端 Provider 配置,统一 invoke 编排、Gateway、请求日志与模型管理;前端按设计规范拆分布局,Go module 更名为 github.com/rose_cat707/Atlas;生图长任务进度改为 SSE 推送;重写 README;移除 Dockerfile syntax 指令以修复 CI 构建超时。 Co-authored-by: Cursor <cursoragent@cursor.com>
85 lines
1.8 KiB
Go
85 lines
1.8 KiB
Go
package reqlog
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
"time"
|
|
|
|
"github.com/rose_cat707/Atlas/internal/store"
|
|
)
|
|
|
|
type Logger struct {
|
|
store *store.Store
|
|
}
|
|
|
|
func New(st *store.Store) *Logger {
|
|
return &Logger{store: st}
|
|
}
|
|
|
|
type Entry struct {
|
|
SessionID string
|
|
Method string
|
|
Path string
|
|
Protocol string
|
|
ProviderID *int64
|
|
Model string
|
|
StatusCode int
|
|
LatencyMS int
|
|
Error string
|
|
RequestSummary string
|
|
ResponseSummary string
|
|
}
|
|
|
|
func (l *Logger) Log(ctx context.Context, e Entry) {
|
|
if l == nil || l.store == nil {
|
|
return
|
|
}
|
|
entry := e
|
|
l.store.WriteQueue.Enqueue(func(ctx context.Context, st *store.Store) error {
|
|
_, err := st.InsertRequestLog(ctx, &store.RequestLog{
|
|
SessionID: entry.SessionID,
|
|
Method: entry.Method,
|
|
Path: entry.Path,
|
|
Protocol: entry.Protocol,
|
|
ProviderID: entry.ProviderID,
|
|
Model: entry.Model,
|
|
StatusCode: entry.StatusCode,
|
|
LatencyMS: entry.LatencyMS,
|
|
Error: entry.Error,
|
|
RequestSummary: entry.RequestSummary,
|
|
ResponseSummary: entry.ResponseSummary,
|
|
})
|
|
return err
|
|
})
|
|
}
|
|
|
|
func Summarize(body []byte, max int) string {
|
|
s := strings.TrimSpace(string(body))
|
|
if len(s) <= max {
|
|
return s
|
|
}
|
|
return s[:max] + "..."
|
|
}
|
|
|
|
func SummarizeSSE(raw string, max int) string {
|
|
var b strings.Builder
|
|
for _, line := range strings.Split(raw, "\n") {
|
|
if strings.HasPrefix(line, "data: ") && !strings.Contains(line, "[DONE]") {
|
|
b.WriteString(strings.TrimPrefix(line, "data: "))
|
|
b.WriteByte(' ')
|
|
}
|
|
}
|
|
return Summarize([]byte(strings.TrimSpace(b.String())), max)
|
|
}
|
|
|
|
func Since(start time.Time) int {
|
|
return int(time.Since(start).Milliseconds())
|
|
}
|
|
|
|
func ProviderIDPtr(id int64) *int64 {
|
|
if id <= 0 {
|
|
return nil
|
|
}
|
|
return &id
|
|
}
|