import type { HashChain } from "../audit/HashChain.js"; import type { FetchLike } from "../handlers/HandlerRegistration.js"; import type { SecurityEvents } from "../incident/SecurityEvents.js"; import { type UsageSigningKey } from "./UsageReport.js"; import { type UsageLine } from "./UsageTally.js"; /** Where a signed report goes: Decionis, or a directory an operator uploads from. */ export interface UsageDelivery { readonly kind: "url" | "file"; /** `DELIVERED`, or a code saying why not; never throws. */ deliver(period: string, installationId: string, report: string): Promise; } /** * `POST /v1/edge/usage-reports` (`{"report": ""}`) with the * organisation's key. A `USAGE_REPORT_DUPLICATE` conflict means Decionis * already holds this period's report at the same or a later chain position, * so the report is delivered; any other refusal is returned by its code. */ export declare class UrlUsageDelivery implements UsageDelivery { private readonly options; readonly kind = "url"; constructor(options: { readonly baseUrl: string; readonly apiKey: () => string; readonly fetch: FetchLike; }); deliver(_period: string, _installation: string, report: string): Promise; } /** The air-gapped form: `usage--.jws` in a directory, written atomically. */ export declare class FileUsageDelivery implements UsageDelivery { private readonly directory; readonly kind = "file"; constructor(directory: string); deliver(period: string, installationId: string, report: string): Promise; } export interface UsageMeterOptions { readonly orgId: string; readonly chain: HashChain; /** The installation id the operator chose; generated and kept with the tally when null. */ readonly installationId: string | null; /** Where the tally persists (`/edge`); in memory only when null. */ readonly stateDir: string | null; /** How many evidence links between persisted tallies: the chain journal's cadence. */ readonly checkpointLines: number; readonly events: SecurityEvents; /** Reads the usage-report key; without one nothing is reported, and the licence check warns. */ readonly key: (() => UsageSigningKey) | null; readonly delivery: UsageDelivery | null; readonly clock: () => number; } /** * The live count of this installation's edge decisions, and the monthly * reports made from it. The tally is persisted with the evidence chain's * head, at the journal's cadence and on stop, so it resumes exactly where * the chain resumes; a tally whose head is not the chain's restored head * belongs to a chain that is gone, and is dropped with a warning (the * month can be recounted from the collected log with * `agentsafe edge usage-report`). */ export declare class UsageMeter { private readonly options; readonly installationId: string; private readonly tally; private readonly delivered; private readonly since; private readonly unsubscribe; constructor(options: UsageMeterOptions); /** Counts one `EDGE_DECISION` line, as it was linked. */ observe(line: UsageLine): void; /** Governed actions this installation counted in the current month: decisions not delegated. */ governed(): number; /** Whether a usage-report key is configured. */ get reporting(): boolean; /** Completed periods since this installation began whose report has not been delivered. */ undelivered(): readonly string[]; /** * Signs and delivers every undelivered completed period's report, oldest * first. Never throws: a report that cannot be signed or delivered is an * `EDGE_USAGE_REPORT_FAILED` line and is tried again on the next round. */ report(): Promise; /** Stops following the chain and persists the tally once more. */ stop(): void; private path; private restore; private persist; /** The start of the oldest period a report is still made for. */ private windowStart; } //# sourceMappingURL=UsageMeter.d.ts.map