import { type MachineInfo, type SessionDetail, type DbModelPricing, type GoalStatus } from '../../db/database.js'; import { type BillingDiffSummary } from '../billing-diff.js'; import { type EconomyBrief } from '../brief.js'; import { type ProjectDetail, type RangeStats, type ForecastData, type ModelEfficiency, type ExportType } from '../analytics.js'; import { type ActiveEconomyCloudStorage } from '../cloud-storage.js'; import type { Agent, AgentBreakdown, AccountBreakdown, BudgetStatus, CostCenterBreakdown, CostCenterKind, CostSummary, EconomyRequest, EconomySession, ModelBreakdown, MachineRegistry, Period, ProjectBreakdown, Subscription } from '../../types/index.js'; export type { MachineInfo, SessionDetail, DbModelPricing, GoalStatus } from '../../db/database.js'; export type { BillingDiffSummary } from '../billing-diff.js'; export type { EconomyBrief } from '../brief.js'; export type { ProjectDetail, RangeStats, ForecastData, ModelEfficiency, ExportType } from '../analytics.js'; /** Fleet roll-up: cross-machine summary + per-machine rows + machine registry. */ export interface FleetSummary { summary: CostSummary; machines: MachineInfo[]; registry: MachineRegistry[]; } /** Options accepted by the breakdown reads. `since` (ISO date) wins over period. */ export interface BreakdownQuery { period?: Period; since?: string; machine?: string; } /** Breakdown query for cost centers — same as `BreakdownQuery` plus a kind filter. */ export interface CostCenterQuery extends BreakdownQuery { kind?: CostCenterKind; } /** Create/update input for a budget (the Store assigns id + timestamps). */ export interface BudgetInput { project_path: string | null; agent: Agent | null; cost_center_id?: string | null; period: 'daily' | 'weekly' | 'monthly'; limit_usd: number; alert_at_percent: number; } /** Create/update input for a spending goal. */ export interface GoalInput { period: 'day' | 'week' | 'month' | 'year'; project_path: string | null; agent: Agent | null; limit_usd: number; } /** Create/update input for a model pricing row (model is the key). */ export interface PricingInput { model: string; input_per_1m: number; output_per_1m: number; cache_read_per_1m: number; cache_write_per_1m: number; cache_write_1h_per_1m: number; cache_storage_per_1m_hour: number; } /** Query for the fleet brief. `currentMachineId`/`localSyncAt` only apply to the * local transport (the cloud serve computes freshness from its own dataset). */ export interface BriefQuery { since?: string; machine?: string; currentMachineId?: string; localSyncAt?: Date; } /** Token counts for a pre-flight cost estimate (backs `economy estimate` / * `estimate_cost`). The Store resolves pricing from its own dataset so cloud * users estimate against the SAME pricing table they edit via set/get pricing. */ export interface EstimateInput { model: string; inputTokens: number; outputTokens: number; cacheReadTokens?: number; cacheWriteTokens?: number; cacheWrite1hTokens?: number; cacheStorageTokenHours?: number; } /** Input for a feedback submission (backs `send_feedback`). The Store stamps the * package version and machine id; the caller only supplies user-provided fields. */ export interface FeedbackInput { message: string; email?: string | null; category?: 'bug' | 'feature' | 'general'; } /** Create/update input for a subscription plan. */ export interface SubscriptionInput { id?: string; provider: string; plan: string; agent: Agent | null; monthly_fee_usd: number; included_usage_usd: number; billing_cycle_start: string | null; reset_policy: string; active: number; } /** * The single data interface for economy. Both LocalStore and ApiStore implement * it; callers hold an `EconomyStore` and never know (or branch on) which one. */ export interface EconomyStore { /** Which transport backs this store (for banners/diagnostics only). */ readonly transport: 'local' | 'cloud-http'; summary(period: Period, machine?: string): Promise; sessions(filter: { agent?: Agent; project?: string; account?: string; machine?: string; limit?: number; since?: string; search?: string; }): Promise; topSessions(n: number, agent?: Agent, since?: string): Promise; sessionDetail(id: string): Promise; modelBreakdown(query?: BreakdownQuery): Promise; agentBreakdown(query?: BreakdownQuery): Promise; projectBreakdown(query?: BreakdownQuery): Promise; accountBreakdown(query?: BreakdownQuery): Promise; costCenterBreakdown(query?: CostCenterQuery): Promise; accounts(period: Period): Promise; daily(days: number, machine?: string): Promise>; machines(): Promise; /** Cross-machine fleet roll-up (backs `economy fleet`). */ fleet(period: Period): Promise; billingSummary(period: Period): Promise<{ total_usd: number; by_provider: Record; }>; /** Estimated vs actual (provider) billing delta (backs `economy billing diff`). */ billingDiff(period: Period): Promise; usage(period: Period, agent?: Agent): Promise; savings(period: Period, agent?: Agent): Promise; listBudgets(): Promise; listGoals(): Promise; listPricing(): Promise; listSubscriptions(): Promise; listProjects(): Promise; /** Fleet-wide usage brief (backs `economy brief`). */ brief(query?: BriefQuery): Promise; /** Detailed breakdown for one project by name or path substring. */ projectDetail(nameOrPath: string): Promise; /** Raw rows for a CSV export of sessions or requests over a period. */ exportRows(type: ExportType, period: string): Promise>>; /** Cost/request/token/session totals for an inclusive [from,to] date range. */ rangeStats(from: string, to: string): Promise; /** End-of-month projection from the current burn rate. */ forecast(): Promise; /** Per-model token efficiency (output/input, cache hit%, cost/1k out). */ efficiency(): Promise; /** Requests recorded at or after an ISO timestamp (live cost stream). */ recentRequests(since: string): Promise; /** Pre-flight cost estimate for token counts, priced from this store's dataset. */ estimate(input: EstimateInput): Promise; /** Create a budget; resolves to its id ('' if the transport does not echo one). */ setBudget(input: BudgetInput): Promise; removeBudget(id: string): Promise; setGoal(input: GoalInput): Promise; removeGoal(id: string): Promise; setPricing(input: PricingInput): Promise; removePricing(model: string): Promise; setSubscription(input: SubscriptionInput): Promise; removeSubscription(id: string): Promise; addProject(path: string, name: string): Promise; renameProject(path: string, name: string): Promise; removeProject(path: string): Promise; /** Record user feedback (LocalStore -> local `feedback` table; ApiStore -> * POST /v1/feedback on the shared cloud). */ sendFeedback(input: FeedbackInput): Promise; } export declare class LocalStore implements EconomyStore { readonly transport: "local"; private _db; private db; summary(period: Period, machine?: string): Promise; sessions(filter: { agent?: Agent; project?: string; account?: string; machine?: string; limit?: number; since?: string; search?: string; }): Promise; topSessions(n: number, agent?: Agent, since?: string): Promise; sessionDetail(id: string): Promise; modelBreakdown(query?: BreakdownQuery): Promise; agentBreakdown(query?: BreakdownQuery): Promise; projectBreakdown(query?: BreakdownQuery): Promise; accountBreakdown(query?: BreakdownQuery): Promise; costCenterBreakdown(query?: CostCenterQuery): Promise; accounts(period: Period): Promise; daily(days: number, machine?: string): Promise>; machines(): Promise; fleet(period: Period): Promise; billingSummary(period: Period): Promise<{ total_usd: number; by_provider: Record; }>; billingDiff(period: Period): Promise; usage(period: Period, agent?: Agent): Promise; savings(period: Period, agent?: Agent): Promise; listBudgets(): Promise; listGoals(): Promise; listPricing(): Promise; listSubscriptions(): Promise; listProjects(): Promise; brief(query?: BriefQuery): Promise; projectDetail(nameOrPath: string): Promise; exportRows(type: ExportType, period: string): Promise>>; rangeStats(from: string, to: string): Promise; forecast(): Promise; efficiency(): Promise; recentRequests(since: string): Promise; estimate(input: EstimateInput): Promise; setBudget(input: BudgetInput): Promise; removeBudget(id: string): Promise; setGoal(input: GoalInput): Promise; removeGoal(id: string): Promise; setPricing(input: PricingInput): Promise; removePricing(model: string): Promise; setSubscription(input: SubscriptionInput): Promise; removeSubscription(id: string): Promise; addProject(path: string, name: string): Promise; renameProject(path: string, name: string): Promise; removeProject(path: string): Promise; sendFeedback(input: FeedbackInput): Promise; } export declare class ApiStore implements EconomyStore { private readonly cloud; readonly transport: "cloud-http"; constructor(cloud: ActiveEconomyCloudStorage); summary(period: Period, machine?: string): Promise; sessions(filter: { agent?: Agent; project?: string; account?: string; machine?: string; limit?: number; since?: string; search?: string; }): Promise; topSessions(n: number, agent?: Agent, since?: string): Promise; sessionDetail(id: string): Promise; modelBreakdown(query?: BreakdownQuery): Promise; agentBreakdown(query?: BreakdownQuery): Promise; projectBreakdown(query?: BreakdownQuery): Promise; accountBreakdown(query?: BreakdownQuery): Promise; costCenterBreakdown(query?: CostCenterQuery): Promise; accounts(period: Period): Promise; daily(days: number, machine?: string): Promise>; machines(): Promise; fleet(period: Period): Promise; billingSummary(period: Period): Promise<{ total_usd: number; by_provider: Record; }>; billingDiff(period: Period): Promise; usage(period: Period, agent?: Agent): Promise; savings(period: Period, agent?: Agent): Promise; listBudgets(): Promise; listGoals(): Promise; listPricing(): Promise; listSubscriptions(): Promise; listProjects(): Promise; brief(query?: BriefQuery): Promise; projectDetail(nameOrPath: string): Promise; exportRows(type: ExportType, period: string): Promise>>; rangeStats(from: string, to: string): Promise; forecast(): Promise; efficiency(): Promise; recentRequests(since: string): Promise; estimate(input: EstimateInput): Promise; setBudget(input: BudgetInput): Promise; removeBudget(id: string): Promise; setGoal(input: GoalInput): Promise; removeGoal(id: string): Promise; setPricing(input: PricingInput): Promise; removePricing(model: string): Promise; setSubscription(input: SubscriptionInput): Promise; removeSubscription(id: string): Promise; addProject(path: string, name: string): Promise; renameProject(path: string, name: string): Promise; removeProject(path: string): Promise; sendFeedback(input: FeedbackInput): Promise; } /** * Resolve the active {@link EconomyStore} for the current environment. Returns an * {@link ApiStore} when the @hasna/contracts resolver produces an authenticated * cloud-http client, else a {@link LocalStore} when the explicit local opt-in * applies; a retired `HASNA_ECONOMY_STORAGE_MODE`-family variable is a hard * error, and NO credential + no opt-in FAILS CLOSED. Throws if the API is * configured but misconfigured (so callers can never silently read the wrong * dataset). */ export declare function getStore(env?: NodeJS.ProcessEnv): EconomyStore; /** True when the resolved store is the cloud HTTP transport (skips local sync). */ export declare function isCloudStore(env?: NodeJS.ProcessEnv): boolean; //# sourceMappingURL=index.d.ts.map