All files / src/objects Cost.ts

0% Statements 0/0
0% Branches 0/0
0% Functions 0/0
0% Lines 0/0

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110                                                                                                                                                                                                                           
/**
 * What a resource has cost — `GET /app/stats/cost` (svc-core
 * `services/stats/resource_cost.py`). See `docs/guides/cost-monitoring.md`.
 */
 
/** The resource a ledger row's spend is attributed to (`UsageEnum.Source`). */
export type CostSource =
  | "agent"
  | "model"
  | "skill"
  | "dashboard"
  | "experiment"
  | "generation"
  | "knowledge"
  | "knowledge_repository"
  | "simulation"
  | "swarm";
 
/** `services/stats/periods.py` keys. */
export type CostPeriod =
  | "last_24_hours"
  | "last_7_days"
  | "last_30_days"
  | "this_month"
  | "last_month"
  | "all_time";
 
export interface CostSlice {
  key: string | null;
  label: string;
  invocations: number;
  cost_usd: number | null;
}
 
export interface CostDay {
  /** A calendar date, `YYYY-MM-DD`. */
  date: string;
  invocations: number;
  cost_usd: number | null;
}
 
export interface ResourceCost {
  source_type: CostSource | null;
  source_id: string | null;
  /** `custom` when asked for a `since` / `until` range. */
  period: CostPeriod | "custom";
  period_label: string;
  /** Counts only the caller's own work ("Your spend"), not everyone's in
   *  the workspace ("Workspace spend"). Absent from older responses. */
  mine?: boolean;
  since: string | null;
  until: string;
  invocations: number;
  failed_invocations: number;
  /** null only when there was spend and none of it could be priced. */
  cost_usd: number | null;
  /** Either above 0 makes `cost_usd` a lower bound. */
  unpriced_invocations: number;
  llm_calls: number;
  unpriced_calls: number;
  input_tokens: number;
  output_tokens: number;
  last_invocation_at: string | null;
  by_execution_type: CostSlice[];
  by_source: CostSlice[];
  daily: CostDay[];
}
 
/** What one step of the pipeline cost across a resource's recent turns —
 *  `GET /app/stats/steps` (svc-core `services/stats/step_usage.py`), summed
 *  over models: no row names the route that served it. */
export interface StepUsage {
  /** The graph node that made the calls (`__evaluator__`, a skill node's
   *  id …); null outside a graph. */
  node: string | null;
  /** What it was doing (`retrieval.reranker`, `respond` …); null on calls
   *  from before steps were recorded. */
  step: string | null;
  /** 0 the first pass, 1 the first revision after the quality check, … */
  pass_index: number | null;
  kind: string;
  calls: number;
  failed_calls: number;
  unpriced_calls: number;
  prompt_tokens: number;
  completion_tokens: number;
  cache_read_tokens: number;
  cache_write_tokens: number;
  reasoning_tokens: number;
  cost_usd: number;
  cache_savings_usd: number;
}
 
export interface StepUsageBreakdown {
  source_type: CostSource;
  source_id: string | null;
  period: CostPeriod;
  period_label: string;
  since: string | null;
  until: string;
  /** The newest turns read, of `turns_in_period`. */
  turns_asked: number;
  turns_in_period: number;
  /** How many of them have recorded calls. */
  turns: number;
  /** `unavailable`: the breakdown could not be read — not an empty one. */
  status: "recorded" | "unavailable";
  steps: StepUsage[];
}