feat(statestore): record a usage row for every model call

Task agent runs and MCP sampling record against their task (billed to the
task's org); gateway chat turns, titles, sampling and curators record
against the system org. Rows carry source, workflow, step, alias,
provider/model and tokens for later chargeback.
This commit is contained in:
sam committed 2026-10-10 18:32:43 +11:00
1 parent 12b9a57404
commit e4ea2eaabc
31 files changed
+1068 -322

No files matched your search

+17
View File
@@ -0,0 +1,17 @@
package postgres
import (
"context"
"github.com/samcharles93/archie-core/internal/domain/usage"
"github.com/samcharles93/archie-core/internal/infrastructure/postgres/postgresdb"
)
// RecordUsage appends one model call's usage record.
func (s *Store) RecordUsage(ctx context.Context, r usage.Record) error {
return postgresdb.New(s.pool).InsertModelUsage(ctx, postgresdb.InsertModelUsageParams{
TaskID: r.TaskID, OrgID: r.Org, Source: string(r.Source), Attempt: int64(r.Attempt),
Workflow: r.Workflow, Step: r.Step, Alias: r.Alias, Provider: r.Provider, Model: r.Model,
InputTokens: r.InputTokens, OutputTokens: r.OutputTokens, CachedTokens: r.CachedTokens, At: r.At,
})
}