requestdb

package
v0.2.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 7, 2026 License: MIT Imports: 23 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package requestdb 在本地 SQLite 中保存请求用量、小时与本地日汇总及可选的截断正文

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Logger

type Logger func(level string, message string)

Logger 输出账本写入失败与丢弃记录的运行日志

type Row

type Row struct {
	ID              string
	Time            time.Time
	Protocol        string
	Path            string
	Model           string
	Account         string
	Channel         string
	Status          int
	State           string
	Duration        time.Duration
	FirstEvent      time.Duration
	Queue           time.Duration
	InputTokens     int64
	ReasoningTokens int64
	ReplyTokens     int64
	TotalTokens     int64
	ToolCalls       int
	Error           string
	Attempts        []api.RequestAttempt
}

Row 是一次完成请求的用量记录

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store 串行批量写入请求账本与汇总,并提供聚合与明细查询

func Open

func Open(path string, log Logger) (*Store, error)

Open 打开或创建账本数据库并启动写入协程

func (*Store) BodyCapture

func (store *Store) BodyCapture() bool

BodyCapture 返回是否保存请求与响应正文

func (*Store) Close

func (store *Store) Close() error

Close 写完已排队的记录后关闭数据库

func (*Store) ExportRecords

func (store *Store) ExportRecords(ctx context.Context, query api.UsageRecordQuery, output io.Writer) error

ExportRecords 以带 BOM 的 UTF-8 CSV 按完成时间倒序写出范围内全部符合条件的请求记录

func (*Store) Record

func (store *Store) Record(row Row)

Record 排队写入一条用量记录,不等待落盘

func (*Store) Records

func (store *Store) Records(ctx context.Context, query api.UsageRecordQuery) (api.UsageRecordPage, error)

Records 按完成时间倒序返回一页请求记录

func (*Store) RequestBody

func (store *Store) RequestBody(ctx context.Context, id string) (api.RequestBody, error)

RequestBody 返回请求保存的截断正文

func (*Store) SaveBody

func (store *Store) SaveBody(body api.RequestBody)

SaveBody 排队写入一条截断正文,不等待落盘

func (*Store) SetBodyCapture

func (store *Store) SetBodyCapture(enabled bool)

SetBodyCapture 设置是否保存请求与响应正文

func (*Store) Usage

func (store *Store) Usage(ctx context.Context, query api.UsageQuery) (api.UsageReport, error)

Usage 返回时间范围内的汇总、上一周期、逐桶趋势、堆叠序列、分项与筛选候选

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL