Help us shape the future of Go! Take the 2026 Go Developer Survey

activity

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2026 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ActivityDelta

type ActivityDelta struct {
	NovelsCreated     int64 `gorm:"column:novels_created;not null;default:0"`
	ChaptersCreated   int64 `gorm:"column:chapters_created;not null;default:0"`
	CharactersCreated int64 `gorm:"column:characters_created;not null;default:0"`
	LocationsCreated  int64 `gorm:"column:locations_created;not null;default:0"`
	CreativeSeconds   int64 `gorm:"column:creative_seconds;not null;default:0"`
	ConversationTurns int64 `gorm:"column:conversation_turns;not null;default:0"`
	ToolCalls         int64 `gorm:"column:tool_calls;not null;default:0"`
}

ActivityDelta 是一次操作对全局每日统计的非负增量。

type DailyActivity

type DailyActivity struct {
	Date          string `gorm:"column:date;primaryKey;size:10"`
	ActivityDelta `gorm:"embedded"`
}

DailyActivity 按记录时的本地日期累计,不与小说或会话建立级联关系。

func (DailyActivity) TableName

func (DailyActivity) TableName() string

type DailyLLMUsage

type DailyLLMUsage struct {
	Date       string `gorm:"column:date;primaryKey;size:10"`
	Provider   string `gorm:"column:provider;primaryKey"`
	Model      string `gorm:"column:model;primaryKey"`
	Purpose    string `gorm:"column:purpose;primaryKey"`
	UsageCount int64  `gorm:"column:usage_count;not null;default:0"`
	TokenUsage `gorm:"embedded"`
}

DailyLLMUsage 按日期、服务商、模型和用途累计已取得的用量。

func (DailyLLMUsage) TableName

func (DailyLLMUsage) TableName() string

type Store

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

Store 负责每日统计的尽力记录;写入失败只告警,不向业务调用方返回错误。

func NewStore

func NewStore(db *gorm.DB, logger *slog.Logger) *Store

func (*Store) AddActivity

func (s *Store) AddActivity(ctx context.Context, delta ActivityDelta)

AddActivity 将非负增量原子累加到当天;全零增量不创建空行。 调用位置应在业务事务外,统计失败无需补偿或重试。

func (*Store) AddLLMUsage

func (s *Store) AddLLMUsage(ctx context.Context, provider, model, purpose string, usage TokenUsage)

AddLLMUsage 累计一次已取得的最终 usage,包括服务商明确返回全零的用量。 调用方跳过缺失 usage 的请求,并负责从原始响应中提取单次用量。

func (*Store) InitTracking

func (s *Store) InitTracking(ctx context.Context)

InitTracking 在表就绪后、加载运行时 AppSettings 前调用,保留已有统计起点。 起点写入 app_config;先初始化再加载设置,避免后续 SaveSettings 写回旧快照。

type TokenUsage

type TokenUsage struct {
	InputTokens     int64 `gorm:"column:input_tokens;not null;default:0"`
	OutputTokens    int64 `gorm:"column:output_tokens;not null;default:0"`
	TotalTokens     int64 `gorm:"column:total_tokens;not null;default:0"`
	CacheHitTokens  int64 `gorm:"column:cache_hit_tokens;not null;default:0"`
	CacheMissTokens int64 `gorm:"column:cache_miss_tokens;not null;default:0"`
	ReasoningTokens int64 `gorm:"column:reasoning_tokens;not null;default:0"`
}

TokenUsage 是调用方已取得的单次用量;缺失字段不贡献增量。 TotalTokens 由调用方按服务商口径确定,缓存和推理明细不再加进总量。

Jump to

Keyboard shortcuts

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