feat(server): meter AI point usage across tenant AI features
Adds an ai_point_usage_logs ledger and a reserve/refund/complete pipeline that charges AI points for article selection optimize, template analyze /title/outline, and KOL prompt generate/optimize. Pending reservations are reconciled when the kol-assist worker and template-assist tasks finish or fail, so points refund automatically on errors. Workspace now exposes the AI quota status and a paginated usage ledger. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -22,6 +22,7 @@ func NewWorkspaceHandler(a *bootstrap.App) *WorkspaceHandler {
|
||||
a.Cache,
|
||||
),
|
||||
repository.NewQuotaRepository(a.DB),
|
||||
repository.NewAIPointUsageRepository(a.DB),
|
||||
).WithCache(a.Cache),
|
||||
}
|
||||
}
|
||||
@@ -53,6 +54,30 @@ func (h *WorkspaceHandler) QuotaSummary(c *gin.Context) {
|
||||
response.Success(c, data)
|
||||
}
|
||||
|
||||
func (h *WorkspaceHandler) AIPointUsageLogs(c *gin.Context) {
|
||||
page := parseIntQuery(c.Query("page"), 1)
|
||||
pageSize := parseIntQuery(c.Query("page_size"), 20)
|
||||
if c.Query("page") == "" && c.Query("page_size") == "" && c.Query("limit") != "" {
|
||||
limit := parseIntQuery(c.Query("limit"), 20)
|
||||
offset := parseIntQuery(c.Query("offset"), 0)
|
||||
if limit > 0 {
|
||||
pageSize = limit
|
||||
page = offset/limit + 1
|
||||
}
|
||||
}
|
||||
|
||||
data, err := h.svc.AIPointUsageLogs(
|
||||
c.Request.Context(),
|
||||
page,
|
||||
pageSize,
|
||||
)
|
||||
if err != nil {
|
||||
response.Error(c, err)
|
||||
return
|
||||
}
|
||||
response.Success(c, data)
|
||||
}
|
||||
|
||||
func (h *WorkspaceHandler) TemplateCards(c *gin.Context) {
|
||||
data, err := h.svc.TemplateCards(c.Request.Context())
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user