All files / src/objects Budget.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 111 112 113 114 115 116 117 118 119 120 121 122 123                                                                                                                                                                                                                                                     
/**
 * Budgets — `GET /app/budgets` (svc-core `app/services/budgets`). A budget is
 * a `cost_cap` rule; this is where each one governing the workspace stands.
 * See `docs/guides/cost-monitoring.md#budgets`.
 */
 
/** Where a budget stands (svc-core `BudgetStatus`), worst first. */
export type BudgetStatus =
  | "reached"
  | "projected_over"
  | "near"
  | "ok"
  | "unavailable";
 
/** A projection of a period's spend at its end — or why there is none. */
export interface BudgetForecast {
  available: boolean;
  unavailable?: "trailing_window" | "not_enough_history" | "unreadable" | null;
  note?: string | null;
  projected_usd?: number | null;
  /** One standard deviation of the trailing days' spend either side. */
  low_usd?: number | null;
  high_usd?: number | null;
  daily_rate_usd?: number | null;
  days_used: number;
  /** When the cap is reached at that rate, if before the period ends. */
  reaches_cap_at?: string | null;
}
 
/** What one member spent — served only to those who govern the workspace. */
export interface BudgetMember {
  user_id: string;
  name: string;
  spent_usd: number;
}
 
export interface Budget {
  rule_id: string;
  rule_name: string;
  action_index: number;
  origin?: "own" | "inherited" | "required" | null;
  home_workspace?: string | null;
  scope_type?: string | null;
  scope_id?: string | null;
  required_for_projects?: boolean;
  /** Above 0, it caps only the work its conditions match. */
  conditions?: number;
  period?: string | null;
  period_label?: string | null;
  window_seconds?: number | null;
  share?: "shared" | "per_member" | null;
  /** Whose spend the figures are. */
  counts?: "workspace" | "yours" | null;
  execution_types?: string[];
  on_reach?: "block" | "warn" | null;
  /** When it alerts those who govern the workspace, in their inbox — keys
   *  of the rule catalogue's `quota_alerts`. Empty: no alerts. */
  alert_at?: string[];
  cap_usd?: number | null;
  spent_usd?: number | null;
  remaining_usd?: number | null;
  used_share?: number | null;
  period_start?: string | null;
  resets_at?: string | null;
  previous_spent_usd?: number | null;
  forecast?: BudgetForecast | null;
  status: BudgetStatus;
  /** Whether the next turn it governs would be refused: used up, or with
   *  less left than a turn usually costs (its room to finish one). */
  blocks?: boolean;
  /** What a turn must find left to start: a typical turn in the workspace. */
  reserve_usd?: number | null;
  members?: BudgetMember[] | null;
  note?: string | null;
}
 
/** CHAIN-R's own monthly cap on the workspace's spend — or, for a project,
 *  its parent's (svc-core `app/services/budgets/allowance.py`). Set by the
 *  deployment; nobody in the workspace can change it. */
export interface PlatformAllowance {
  name: string;
  /** Whose allowance it is. */
  holder: "personal" | "organisation";
  holder_workspace: string;
  cap_usd?: number | null;
  period?: string | null;
  period_label?: string | null;
  spent_usd?: number | null;
  remaining_usd?: number | null;
  used_share?: number | null;
  period_start?: string | null;
  resets_at?: string | null;
  previous_spent_usd?: number | null;
  forecast?: BudgetForecast | null;
  status: BudgetStatus;
  blocks?: boolean;
  reserve_usd?: number | null;
  note?: string | null;
}
 
/** The workspace's calendar month, counted as a budget for it would be. */
export interface SpendOverview {
  period_start: string;
  resets_at?: string | null;
  spent_usd?: number | null;
  last_month_usd?: number | null;
  forecast: BudgetForecast;
}
 
export interface Budgets {
  workspace: string;
  /** The caller governs the workspace: sees each member's spend, and may
   *  add a budget. */
  governs: boolean;
  overview?: SpendOverview | null;
  /** Worst first. */
  budgets: Budget[];
  /** The platform's allowance, when the deployment sets one. */
  allowance?: PlatformAllowance | null;
  /** What a turn here usually costs: what each budget keeps back. */
  typical_turn_usd?: number | null;
}