No JSDoc comment in source yet.
API
@Component()
export class UsageService implements UsageQueries {
@Use() private readonly usage!: UsageStore;
@Use() private readonly errors!: ErrorLog;
@Use() private readonly projectConfig!: ProjectConfigStore;
@Use() private readonly clock!: UsageClock;
async costBySession(projectId: string, sessionIds: readonly string[], fromTs: string, toTs: string): Promise<{ bySession: Map<string, number>; unpriced: boolean }>;
async dailyCostForSessions(projectId: string, sessionIds: readonly string[], fromTs: string, toTs: string): Promise<Array<{ date: string; cost: number }>>;
async query(projectId: string, q: UsageQuery): Promise<UsageResponse>;
queryErrors(projectId: string, q: UsageErrorsQuery): UsageErrorsPage;
clearErrors(projectId: string, q: UsageErrorsClearQuery): number;
modelTotals(projectId: string): UsageModelTotals;
}Dependencies & Wiring
Extracted from class decoratorsMethods (6)
costBySession
async costBySession(projectId: string, sessionIds: readonly string[], fromTs: string, toTs: string): Promise<{ bySession: Map<string, number>; unpriced: boolean }>Period cost per session, for company mode's attribution by the sessions an organization
owns: sums by paired reference priced at the current rates (each half at the tier its own
records ran in). unpriced says some usage ran on a model without pricing, so the numbers
are a lower bound.
stringreadonly string[]stringstringPromise<{ bySession: Map<string, number>; unpriced: boolean }>dailyCostForSessions
async dailyCostForSessions(projectId: string, sessionIds: readonly string[], fromTs: string, toTs: string): Promise<Array<{ date: string; cost: number }>>Daily cost of a set of sessions over a window (the organization finance trend).
stringreadonly string[]stringstringPromise<Array<{ date: string; cost: number }>>query
async query(projectId: string, q: UsageQuery): Promise<UsageResponse>stringUsageQueryPromise<UsageResponse>queryErrors
queryErrors(projectId: string, q: UsageErrorsQuery): UsageErrorsPageOne page of the error detail table, newest first. The dashboard's own response already
carries the first page (errors.recent); this serves the "show me earlier ones" paging,
where refetching the whole aggregate to move one page would be wasteful. rows is the
filtered row count, so the caller knows when it has reached the end; total counts the
records behind those rows, the occurrences the badge reports.
Takes the same filter the dashboard applies — date + agent, and admin-only visibility of unattributed errors — so a page never widens what the summary above it counted.
Paging is by offset into a newest-first table that grows at its head, so errors recorded between two page requests shift every row down and a page can re-show rows already seen. Accepted deliberately: this is a diagnostic table read at a moment in time, not a feed to be walked exhaustively, and keying off the newest row's id would cost a cursor the caller has no other use for.
stringUsageErrorsQueryUsageErrorsPageclearErrors
clearErrors(projectId: string, q: UsageErrorsClearQuery): numberEmpties the error table for the filter the panel is showing, and answers how many rows went.
The filter is the same range (dates, and the trailing window when one is on) and Agent the dashboard and the paged route take, read with the same admin visibility, so a clear removes exactly the set the caller was looking at and never a row outside it: a reader who has narrowed to one Agent and one week does not lose the rest of the year to a button that said "clear", and an admin whose panel showed unattributed rows is not left holding them after clearing it (see ErrorsRepo.deleteFiltered).
stringUsageErrorsClearQuerynumbermodelTotals
modelTotals(projectId: string): UsageModelTotalsLifetime Token totals per Model — one grouped scan of usage_records, no filters. The
models page shows each configured model what it has actually spent, and that figure is not
scoped to a range the way the cost center's is; a model with no records is simply absent,
so the caller renders nothing rather than a zero.
stringUsageModelTotals