/** * dsh-balance host half. * * Owns the API credential, polls `/user/balance`, accumulates this machine's own * token consumption, and serves the resulting snapshot to the browser half over * two exact routes. The client never sees the credential and never reaches the * network; it only reads the projection. * * The displayed balance is **not** the platform figure. A reading is an anchor: the * platform settles minutes late, so the number shown is `reading - locally observed * spend since the reading's usage cutoff`, which keeps moving while the platform * catches up. See `estimator.ts` for the algebra, and `ledger.ts` for why only * balance *decreases* are ever summed (that is what makes a top-up harmless). * * @module dsh-balance */ import Schema from '@deepseek-ai/schemastery'; import type { Context } from '@deepseek-ai/cordis'; import { type HolidayFormat } from './holidays.js'; import { type TokenWeights } from './pricing.js'; import { type Currency } from './protocol.js'; /** Plugin name; also the Loader row id and the client bundle registration id. */ export declare const name = "dsh-balance"; /** * Required services. * * `connection` is the browser trust surface, and it is required rather than * optional on purpose. It is mounted by `@deepseek-ai/dsh-web-app` — the same * bundle, at the same level, as `webserver`, and the only bundle that provides one * (`packages/bundle/web-app/cordis.patch.yml`) — so there is no harness composition * with a web server and no browser connection seam. Declaring it means the route * fence can never silently fail open: without the service this plugin does not load * at all, rather than serving account data unfenced. */ export declare const inject: string[]; /** Plugin configuration, mirrored field-for-field by {@link Config}. */ export interface Config { /** Credential reference holding the DeepSeek API key. */ apiKeyEnv: string; /** Balance endpoint origin. */ apiOrigin: string; /** Balance endpoint path. */ balancePath: string; /** How often the platform is polled. */ refreshIntervalMs: number; /** Per-request timeout. */ requestTimeoutMs: number; /** How far the platform's figure lags actual usage. */ settlementLagMs: number; /** Window the instantaneous rate is measured over. */ rateWindowMs: number; /** Window the correction factor is learnt over. */ calibrationWindowMs: number; /** How many recent candidates the correction median is taken over. */ correctionSamples: number; /** How many agreeing probe samples are needed before advising a calendar change. */ probeSamples: number; /** How long readings and token buckets are kept. */ retentionMs: number; /** How long without a reading before the snapshot is marked stale. */ staleAfterMs: number; /** Clamp for the reported time-to-empty. */ etaCapMs: number; /** Rates below this are reported as idle. */ minBurnPerHour: number; /** Attribution threshold between usage and platform adjustments. */ minPredictedSpend: number; /** Wallet preference. */ preferredCurrency: 'auto' | Currency; /** Currency the price table is denominated in. */ priceCurrency: Currency; /** Peak rates per route. */ priceTable: Record; /** Off-peak multiplier. */ offPeakFactor: number; /** ISO weekdays carrying peak windows. */ peakDays: number[]; /** Peak windows as `"HH:mm-HH:mm"`. */ peakWindows: string[]; /** Zone the peak windows are expressed in. */ priceTimeZone: string; /** Statutory holidays, `YYYY-MM-DD`. */ holidays: string[]; /** Make-up workdays, `YYYY-MM-DD`. */ makeupWorkdays: string[]; /** Whether a make-up workday prices its windows at peak rates. */ treatMakeupWorkdaysAsPeak: boolean; /** Whether the optional remote calendar source is enabled. */ holidaySourceEnabled: boolean; /** Remote calendar URL template containing `{year}`. */ holidaySourceUrl: string; /** Remote payload shape. */ holidaySourceFormat: HolidayFormat; /** Normal remote refresh interval. */ holidayRefreshIntervalMs: number; /** Retry interval while the current year is unpublished. */ holidayMissingYearRetryMs: number; /** Remote calendar request timeout. */ holidayTimeoutMs: number; /** Relative cost shape for routes the price table does not describe. */ weights: TokenWeights; /** Whether time-to-empty integrates across upcoming pricing periods. */ etaIntegratesSchedule: boolean; /** Time-to-empty below this warns. */ etaWarnMs: number; /** Time-to-empty below this is critical. */ etaCriticalMs: number; /** Browser poll interval served to the client. */ clientPollIntervalMs: number; /** Whether history is persisted. */ persist: boolean; /** Override for the persistence directory. */ historyRoot: string; /** Whether loopback `http` origins are accepted (local development). */ allowLoopbackHttp: boolean; } /** Schema mirrors {@link Config}; defaults live here so the settings surface carries them. */ export declare const Config: Schema; /** * Mount the plugin. * @param ctx - Cordis context. * @param config - validated configuration. */ export declare function apply(ctx: Context, config: Config): void;