Skip to content

usage

Usage: what was used, what it cost, and what to charge for it, as a ledger.

On this page 7
TypeScript
import { usage } from "copilotz/plugins/billing";

What it keeps

It keeps 3 collections.

CollectionKept asFields
usagerecords, appended and never changedmeter, subject, catalog, quantities, tags, cost, price, costs, prices, saved, rated, unpriced, adjusts, kind, at
usageCloseddocumentsrecords, groups, shape, at
usageRollupdocumentsday, meter, subject, catalog, tags, kind, unpriced, quantities, cost, price, costs, prices, saved, rated, n

Its named queries read for callers, as the rules let them:

QueryWho outside runs it
usage.listthe app's code
usage.totalspeople, agents for a person, keys and routines

What it lets callers do

Of its 7 Actions, people and agents may call 3; contacts and someone signed out may call none.

ActionPersonAgentContactAnyoneKeyWhat it does
usage.activityyesyesnonoyesWhat was done, newest first (agents' turns, computers' sessions, apps' days), with what each was charged: everyone's for the org's owners and admins, your own for others.
usage.orgyesyesnonoyesUsage totals across the whole org, for its owners and admins; your own for others.
usage.quoteyesyesnonoyesWhat a use would be charged now (its price), without recording it.

An agent works for a person, and calls what both may. A key calls only what its scope names.

Only the app's own code calls usage.close, usage.quotes, usage.record and usage.rerate: its plugins, its schedules and the system.

Where it shows

It has no Views of its own: its front ends show it, usage-terminal and usage-web.

  • What it adds to resources: modelUse (ledger).

What it needs

You set it in resources.usage: 2 settings are required.

SettingTypeRequiredWhat it is
usage.rollupsRollupsyesHow whole days are rolled up, so totals over many days read each day's groups rather than its records.
usage.categoriesCategoriesyesWhat each category holds (see shared/categories.ts).
usage.priceListstringnoWhoever keeps an org's plan: the Action naming its price list among resources.priceLists (none: resources.price).
usage.spentstringnoThe Action told what each use was charged ({ price }), before it's recorded, so what's left is known without reading the ledger.

It also reads cost, price, priceLists and usageNames, resource kinds the app and other plugins fill.

What it requires

It builds on no other plugin.

It ships with copilotz@1.0.0-rc.34.

What it does on its own

Some of its work starts without a caller: an event, or the time.

  • usage.close calls usage.close, cron 10 0 * (UTC).

Listing

It keeps every listing rule.