{"modulePath":"github.com/Mag1cFall/AIStudio2API","version":"v0.3.16","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package requestdb\n\nPackage requestdb 在本地 SQLite 中保存请求用量、小时与本地日汇总及可选的 gzip 压缩截断正文\n\n## Types\n\n```go\ntype AccountUsageEntry struct {\n\tAccount  string\n\tModel    string\n\tChannel  string\n\tLastUsed time.Time\n}\n```\nAccountUsageEntry 表示单个账户在指定模型与通道上的最近使用时刻\n\n```go\ntype AccountUsageSeed struct {\n\tEntries          []AccountUsageEntry\n\tQuotaDayStart    time.Time\n\tQuotaDayRequests map[string]int64\n}\n```\nAccountUsageSeed 保存启动时从请求账本读回的账户最近使用记录与当前配额日请求数\n\n```go\ntype Logger func(level, message string, attrs ...any)\n```\nLogger 输出账本写入失败与丢弃记录的运行日志，attrs 依次为字段的英文标识与取值\n\n```go\ntype Row struct {\n\tID                     string\n\tTime                   time.Time\n\tProtocol               string\n\tPath                   string\n\tModel                  string\n\tAccount                string\n\tChannel                string\n\tAPIKey                 string\n\tStatus                 int\n\tState                  string\n\tDuration               time.Duration\n\tFirstEvent             time.Duration\n\tQueue                  time.Duration\n\tProof                  api.ProofTiming\n\tInputTokens            int64\n\tCachedTokens           int64\n\tReasoningTokens        int64\n\tReplyTokens            int64\n\tTotalTokens            int64\n\tToolCalls              int\n\tReplyTool              bool\n\tReplyToolCalls         int\n\tReplyToolContinuations int\n\tError                  string\n\tAttempts               []api.RequestAttempt\n}\n```\nRow 是一次完成请求的用量记录\n\n```go\ntype Store struct {\n\t// contains filtered or unexported fields\n}\n```\nStore 串行批量写入请求账本与汇总，并提供聚合与明细查询\n\n```go\nfunc Open(path string, log Logger) (*Store, error)\n```\nOpen 打开或创建账本数据库并启动写入协程\n\n```go\nfunc (store *Store) AccountUsageSeed(ctx context.Context, quotaDayStart time.Time) (AccountUsageSeed, error)\n```\nAccountUsageSeed 返回各账户按模型与通道聚合的最近使用时刻，以及自 quotaDayStart 起至今的请求数\n\n```go\nfunc (store *Store) BodyCapture() bool\n```\nBodyCapture 返回是否保存请求与响应正文\n\n```go\nfunc (store *Store) Close() error\n```\nClose 写完已排队的记录后关闭数据库\n\n```go\nfunc (store *Store) ExportRecords(ctx context.Context, query api.UsageRecordQuery, output io.Writer) error\n```\nExportRecords 以带 BOM 的 UTF-8 CSV 按完成时间倒序写出范围内全部符合条件的请求记录\n\n```go\nfunc (store *Store) Record(row Row)\n```\nRecord 排队写入一条用量记录，不等待落盘\n\n```go\nfunc (store *Store) Records(ctx context.Context, query api.UsageRecordQuery) (api.UsageRecordPage, error)\n```\nRecords 按完成时间倒序返回一页请求记录\n\n```go\nfunc (store *Store) RequestBody(ctx context.Context, id string) (api.RequestBody, error)\n```\nRequestBody 返回请求保存的截断正文\n\n```go\nfunc (store *Store) SaveBody(body api.RequestBody)\n```\nSaveBody 排队写入一条截断正文，不等待落盘\n\n```go\nfunc (store *Store) SetBodyCapture(enabled bool)\n```\nSetBodyCapture 设置是否保存请求与响应正文\n\n```go\nfunc (store *Store) Usage(ctx context.Context, query api.UsageQuery) (api.UsageReport, error)\n```\nUsage 返回时间范围内的汇总、上一周期、估算费用、逐桶趋势、堆叠序列、分项与筛选候选\n\n```go\nfunc (store *Store) UsagePairs(ctx context.Context, query api.UsageQuery) ([]api.UsagePair, error)\n```\nUsagePairs 返回时间范围内符合筛选的账户与模型组合汇总，按请求数降序、账户与模型升序排列\n\n","path":"github.com/Mag1cFall/AIStudio2API/internal/requestdb","name":"requestdb","synopsis":"Package requestdb 在本地 SQLite 中保存请求用量、小时与本地日汇总及可选的 gzip 压缩截断正文","isRedistributable":true}
