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.
59 lines
1.2 KiB
Go
59 lines
1.2 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.31.1
|
|
// source: usage.sql
|
|
|
|
package postgresdb
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
)
|
|
|
|
const insertModelUsage = `-- name: InsertModelUsage :exec
|
|
INSERT INTO model_usage (
|
|
org_id, source, task_id, attempt, workflow, step, alias, provider, model,
|
|
input_tokens, output_tokens, cached_tokens, at
|
|
) VALUES (
|
|
COALESCE((SELECT t.org_id FROM tasks t WHERE t.id = $1 AND $1 <> 0), $2::text),
|
|
$3, $1, $4, $5, $6, $7,
|
|
$8, $9, $10, $11, $12, $13
|
|
)
|
|
`
|
|
|
|
type InsertModelUsageParams struct {
|
|
TaskID int64
|
|
OrgID string
|
|
Source string
|
|
Attempt int64
|
|
Workflow string
|
|
Step string
|
|
Alias string
|
|
Provider string
|
|
Model string
|
|
InputTokens int64
|
|
OutputTokens int64
|
|
CachedTokens int64
|
|
At time.Time
|
|
}
|
|
|
|
// A task's usage belongs to the task's org, whatever the caller says.
|
|
func (q *Queries) InsertModelUsage(ctx context.Context, arg InsertModelUsageParams) error {
|
|
_, err := q.db.Exec(ctx, insertModelUsage,
|
|
arg.TaskID,
|
|
arg.OrgID,
|
|
arg.Source,
|
|
arg.Attempt,
|
|
arg.Workflow,
|
|
arg.Step,
|
|
arg.Alias,
|
|
arg.Provider,
|
|
arg.Model,
|
|
arg.InputTokens,
|
|
arg.OutputTokens,
|
|
arg.CachedTokens,
|
|
arg.At,
|
|
)
|
|
return err
|
|
}
|