Version: 0.9.80.dev.260506
后端: 1. LLM 独立服务与统一计费出口落地:新增 `cmd/llm`、`client/llm` 与 `services/llm/rpc`,补齐 BillingContext、CreditBalanceGuard、价格规则解析、stream usage 归集与 `credit.charge.requested` outbox 发布,active-scheduler / agent / course / memory / gateway fallback 全部改走 llm zrpc,不再各自本地初始化模型。 2. TokenStore 收口为 Credit 权威账本:新增 credit account / ledger / product / order / price-rule / reward-rule 能力与 Redis 快照缓存,扩展 tokenstore rpc/client 支撑余额快照、消耗看板、商品、订单、流水、价格规则和奖励规则,并接入 LLM charge 事件消费完成 Credit 扣费落账。 3. 计费旧链路下线与网关切口切换:`/token-store` 语义整体切到 `/credit-store`,agent chat 移除旧 TokenQuotaGuard,userauth 的 CheckTokenQuota / AdjustTokenUsage 改为废弃,聊天历史落库不再同步旧 token 额度账本,course 图片解析请求补 user_id 进入新计费口径。 前端: 4. 计划广场从 mock 数据切到真实接口:新增 forum api/types,首页支持真实列表、标签、搜索、防抖、点赞、导入和发布计划,详情页补齐帖子详情、评论树、回复和删除评论链路,同时补上“至少一个标签”的前后端约束与默认标签兜底。 5. 商店页切到 Credit 体系并重做展示:顶部改为余额 + Credit/Token 消耗看板,支持 24h/7d/30d/all 周期切换;套餐区展示原价与当前价;历史区改为当前用户 Credit 流水并支持查看更多,整体视觉和交互同步收口。 仓库: 6. 配置与本地启动体系补齐 llm / outbox 编排:`config.example.yaml` 增加 llm rpc 和统一 outbox service 配置,`dev-common.ps1` 把 llm 纳入多服务依赖并自动建 Kafka topic,`docker-compose.yml` 同步初始化 agent/task/memory/active-scheduler/notification/taskclass-forum/llm/token-store 全量 outbox topic。
This commit is contained in:
172
backend/shared/contracts/creditstore/types.go
Normal file
172
backend/shared/contracts/creditstore/types.go
Normal file
@@ -0,0 +1,172 @@
|
||||
package creditstore
|
||||
|
||||
// PageResult 是 Credit 领域的分页结果契约。
|
||||
type PageResult struct {
|
||||
Page int `json:"page"`
|
||||
PageSize int `json:"page_size"`
|
||||
Total int `json:"total"`
|
||||
HasMore bool `json:"has_more"`
|
||||
}
|
||||
|
||||
// CreditBalanceSnapshot 提供给商店页和 LLM 准入 Guard 的余额快照。
|
||||
//
|
||||
// 职责边界:
|
||||
// 1. 只表达 TokenStore 权威账本视角下的 Credit 余额与阻断状态。
|
||||
// 2. snapshot_source 用于说明结果来自 cache 还是 db。
|
||||
// 3. 不承载任何扣费规则细节,避免把价格表语义耦合到余额查询。
|
||||
type CreditBalanceSnapshot struct {
|
||||
UserID uint64 `json:"user_id"`
|
||||
Balance int64 `json:"balance"`
|
||||
TotalRecharged int64 `json:"total_recharged"`
|
||||
TotalRewarded int64 `json:"total_rewarded"`
|
||||
TotalConsumed int64 `json:"total_consumed"`
|
||||
IsBlocked bool `json:"is_blocked"`
|
||||
SnapshotSource string `json:"snapshot_source"`
|
||||
UpdatedAt string `json:"updated_at"`
|
||||
}
|
||||
|
||||
// CreditProductView 是 Credit 商品卡片展示结构。
|
||||
type CreditProductView struct {
|
||||
ProductID uint64 `json:"product_id"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
CreditAmount int64 `json:"credit_amount"`
|
||||
PriceCent int64 `json:"price_cent"`
|
||||
OriginalPriceCent int64 `json:"original_price_cent"`
|
||||
PriceText string `json:"price_text"`
|
||||
Currency string `json:"currency"`
|
||||
Badge string `json:"badge"`
|
||||
Status string `json:"status"`
|
||||
SortOrder int `json:"sort_order"`
|
||||
}
|
||||
|
||||
// CreditOrderView 是 Credit 订单展示结构。
|
||||
type CreditOrderView struct {
|
||||
OrderID uint64 `json:"order_id"`
|
||||
OrderNo string `json:"order_no"`
|
||||
Status string `json:"status"`
|
||||
ProductSnapshot string `json:"product_snapshot"`
|
||||
ProductName string `json:"product_name"`
|
||||
Quantity int `json:"quantity"`
|
||||
CreditAmount int64 `json:"credit_amount"`
|
||||
AmountCent int64 `json:"amount_cent"`
|
||||
PriceText string `json:"price_text"`
|
||||
Currency string `json:"currency"`
|
||||
PaymentMode string `json:"payment_mode"`
|
||||
CreatedAt string `json:"created_at"`
|
||||
PaidAt *string `json:"paid_at"`
|
||||
CreditedAt *string `json:"credited_at"`
|
||||
}
|
||||
|
||||
// CreditTransactionView 是 Credit 流水展示结构。
|
||||
type CreditTransactionView struct {
|
||||
TransactionID uint64 `json:"transaction_id"`
|
||||
EventID string `json:"event_id"`
|
||||
Source string `json:"source"`
|
||||
SourceLabel string `json:"source_label"`
|
||||
Direction string `json:"direction"`
|
||||
Amount int64 `json:"amount"`
|
||||
BalanceAfter int64 `json:"balance_after"`
|
||||
Status string `json:"status"`
|
||||
Description string `json:"description"`
|
||||
MetadataJSON string `json:"metadata_json"`
|
||||
CreatedAt string `json:"created_at"`
|
||||
OrderID *uint64 `json:"order_id"`
|
||||
}
|
||||
|
||||
const (
|
||||
// CreditConsumptionPeriod24h 表示统计最近 24 小时内的消耗。
|
||||
CreditConsumptionPeriod24h = "24h"
|
||||
// CreditConsumptionPeriod7d 表示统计最近 7 天内的消耗。
|
||||
CreditConsumptionPeriod7d = "7d"
|
||||
// CreditConsumptionPeriod30d 表示统计最近 30 天内的消耗。
|
||||
CreditConsumptionPeriod30d = "30d"
|
||||
// CreditConsumptionPeriodAll 表示统计全部历史消耗。
|
||||
CreditConsumptionPeriodAll = "all"
|
||||
)
|
||||
|
||||
// CreditConsumptionDashboardView 是商店页顶部消耗看板的展示结构。
|
||||
type CreditConsumptionDashboardView struct {
|
||||
Period string `json:"period"`
|
||||
CreditConsumed int64 `json:"credit_consumed"`
|
||||
TokenConsumed int64 `json:"token_consumed"`
|
||||
}
|
||||
|
||||
// CreditPriceRuleView 是 Credit 计价规则展示结构。
|
||||
type CreditPriceRuleView struct {
|
||||
RuleID uint64 `json:"rule_id"`
|
||||
Scene string `json:"scene"`
|
||||
ProviderName string `json:"provider_name"`
|
||||
ModelName string `json:"model_name"`
|
||||
InputPriceMicros int64 `json:"input_price_micros"`
|
||||
OutputPriceMicros int64 `json:"output_price_micros"`
|
||||
CachedPriceMicros int64 `json:"cached_price_micros"`
|
||||
ReasoningPriceMicros int64 `json:"reasoning_price_micros"`
|
||||
CreditPerYuan int64 `json:"credit_per_yuan"`
|
||||
Status string `json:"status"`
|
||||
Priority int `json:"priority"`
|
||||
Description string `json:"description"`
|
||||
}
|
||||
|
||||
// CreditRewardRuleView 是 Credit 奖励规则展示结构。
|
||||
type CreditRewardRuleView struct {
|
||||
RuleID uint64 `json:"rule_id"`
|
||||
Source string `json:"source"`
|
||||
Name string `json:"name"`
|
||||
Amount int64 `json:"amount"`
|
||||
Status string `json:"status"`
|
||||
Description string `json:"description"`
|
||||
}
|
||||
|
||||
// CreateCreditOrderRequest 是创建 Credit 订单请求契约。
|
||||
type CreateCreditOrderRequest struct {
|
||||
ActorUserID uint64 `json:"actor_user_id"`
|
||||
ProductID uint64 `json:"product_id"`
|
||||
Quantity int `json:"quantity"`
|
||||
IdempotencyKey string `json:"idempotency_key"`
|
||||
}
|
||||
|
||||
// ListCreditOrdersRequest 是 Credit 订单列表查询契约。
|
||||
type ListCreditOrdersRequest struct {
|
||||
ActorUserID uint64 `json:"actor_user_id"`
|
||||
Page int `json:"page"`
|
||||
PageSize int `json:"page_size"`
|
||||
Status string `json:"status"`
|
||||
}
|
||||
|
||||
// GetCreditConsumptionDashboardRequest 是查询当前用户消耗看板的契约。
|
||||
type GetCreditConsumptionDashboardRequest struct {
|
||||
ActorUserID uint64 `json:"actor_user_id"`
|
||||
Period string `json:"period"`
|
||||
}
|
||||
|
||||
// MockPaidCreditOrderRequest 是 Credit 商店 mock paid 请求契约。
|
||||
type MockPaidCreditOrderRequest struct {
|
||||
ActorUserID uint64 `json:"actor_user_id"`
|
||||
OrderID uint64 `json:"order_id"`
|
||||
MockChannel string `json:"mock_channel"`
|
||||
IdempotencyKey string `json:"idempotency_key"`
|
||||
}
|
||||
|
||||
// ListCreditTransactionsRequest 是当前用户查询自己 Credit 流水的契约。
|
||||
type ListCreditTransactionsRequest struct {
|
||||
ActorUserID uint64 `json:"actor_user_id"`
|
||||
Page int `json:"page"`
|
||||
PageSize int `json:"page_size"`
|
||||
Source string `json:"source"`
|
||||
Direction string `json:"direction"`
|
||||
}
|
||||
|
||||
// ListCreditPriceRulesRequest 是 Credit 价格规则查询契约。
|
||||
type ListCreditPriceRulesRequest struct {
|
||||
Scene string `json:"scene"`
|
||||
ProviderName string `json:"provider_name"`
|
||||
ModelName string `json:"model_name"`
|
||||
Status string `json:"status"`
|
||||
}
|
||||
|
||||
// ListCreditRewardRulesRequest 是 Credit 奖励规则查询契约。
|
||||
type ListCreditRewardRulesRequest struct {
|
||||
Source string `json:"source"`
|
||||
Status string `json:"status"`
|
||||
}
|
||||
Reference in New Issue
Block a user