ObservabilityModule · library/observability/src/repos/usage.ts:210

UsageRepo

component

No JSDoc comment in source yet.

API

@Component()
export class UsageRepo implements UsageStore {
  @Use() private readonly db!: Db;
  insert(r: UsageRecordInsert): void;
  bucketByModel(projectId: string, f: UsageFilter = {}, tiers: readonly PeakTier[] = []): UsageModelSums[];
  groupsByModel(projectId: string, groupBy: UsageGroupBy, f: UsageFilter = {}, tiers: readonly PeakTier[] = []): UsageGroupModelSums[];
  seriesByModel(projectId: string, granularity: UsageSeriesGranularity, f: UsageFilter = {}, tiers: readonly PeakTier[] = []): UsageSeriesModelSums[];
  toolsByModel(projectId: string, f: UsageFilter = {}, tiers: readonly PeakTier[] = []): UsageToolModelSums[];
  agentSeries(projectId: string, granularity: UsageSeriesGranularity, f: UsageFilter = {}): UsageAgentBucketCount[];
  distinctAgentIds(projectId: string): string[];
  distinctModels(projectId: string): Array<{ provider: string; modelId: string }>;
  deleteByProject(projectId: string): void;
}

Dependencies & Wiring

Extracted from class decorators
implementsinterfaces
@Userequires (1)
db: Db

Methods (9)

insert

insert(r: UsageRecordInsert): void
@paramrUsageRecordInsert
@returnsvoid

bucketByModel

bucketByModel(projectId: string, f: UsageFilter = {}, tiers: readonly PeakTier[] = []): UsageModelSums[]

Sums (broken down by paired reference, and by price tier where one applies): date range + optional agent/model filter.

@paramprojectIdstring
@paramf?UsageFilter
@paramtiers?readonly PeakTier[]
@returnsUsageModelSums[]

groupsByModel

groupsByModel(projectId: string, groupBy: UsageGroupBy, f: UsageFilter = {}, tiers: readonly PeakTier[] = []): UsageGroupModelSums[]

Grouped aggregation (group key x paired reference breakdown): date range + optional agent/model filter.

@paramprojectIdstring
@paramgroupByUsageGroupBy
@paramf?UsageFilter
@paramtiers?readonly PeakTier[]
@returnsUsageGroupModelSums[]

seriesByModel

seriesByModel(projectId: string, granularity: UsageSeriesGranularity, f: UsageFilter = {}, tiers: readonly PeakTier[] = []): UsageSeriesModelSums[]

Time-series sums (bucket key x paired reference breakdown) with per-bucket success-rate counts riding along: powers the cost center's time-series charts (requests / success rate / Token / cost) at the requested precision. The denominator excludes aborted.

@paramprojectIdstring
@paramgranularityUsageSeriesGranularity
@paramf?UsageFilter
@paramtiers?readonly PeakTier[]
@returnsUsageSeriesModelSums[]

toolsByModel

toolsByModel(projectId: string, f: UsageFilter = {}, tiers: readonly PeakTier[] = []): UsageToolModelSums[]

Tool requests' sums (rows with a purpose) by purpose x paired reference, and by price tier where one applies: the Cost Center's list of tool requests.

@paramprojectIdstring
@paramf?UsageFilter
@paramtiers?readonly PeakTier[]
@returnsUsageToolModelSums[]

agentSeries

agentSeries(projectId: string, granularity: UsageSeriesGranularity, f: UsageFilter = {}): UsageAgentBucketCount[]

Per-Agent counts per time bucket (the by-Agent requests chart's series; the denominator excludes aborted).

@paramprojectIdstring
@paramgranularityUsageSeriesGranularity
@paramf?UsageFilter
@returnsUsageAgentBucketCount[]

distinctAgentIds

distinctAgentIds(projectId: string): string[]

Distinct agent_id values seen for this Project (for filter dropdowns); a Session-less request's empty one is no Agent.

@paramprojectIdstring
@returnsstring[]

distinctModels

distinctModels(projectId: string): Array<{ provider: string; modelId: string }>

Distinct Model paired references seen for this Project (for filter dropdowns).

@paramprojectIdstring
@returnsArray<{ provider: string; modelId: string }>

deleteByProject

deleteByProject(projectId: string): void
@paramprojectIdstring
@returnsvoid