@acarmisc/backstage-plugin-litellm 0.19.0 → 0.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,54 @@
1
+ import { UserInfo, TeamInfo, VirtualKey } from './types';
2
+ import { Tone } from './components/ui';
3
+ /** One concrete budget limit the signed-in user is subject to. */
4
+ export interface BudgetLimit {
5
+ kind: 'key' | 'user' | 'team';
6
+ /** Display name: key_alias / "Personal budget" / team_alias. */
7
+ label: string;
8
+ /** Secondary identifier: masked key, team_id, etc. */
9
+ sublabel?: string;
10
+ /** Spend cap in USD (> 0 when a cap exists). */
11
+ budget: number;
12
+ /** Spend so far in the current window. */
13
+ spend: number;
14
+ /** Reset window, e.g. "30d". Missing means the budget never resets. */
15
+ budgetDuration?: string;
16
+ /** User-facing warning threshold (soft limit). */
17
+ softLimit?: number;
18
+ /** Share of the cap spent, 0..100+ (unclamped). */
19
+ pct: number;
20
+ }
21
+ /** The budgets that apply to the current user, grouped by enforcement level. */
22
+ export interface BudgetSummary {
23
+ /** Budgeted keys, capped at `maxKeys`, closest to the cap first. */
24
+ keys: BudgetLimit[];
25
+ /** Budgeted keys hidden by the cap. */
26
+ hiddenBudgetedKeys: number;
27
+ /** Every key owned by the user (budgeted or not). */
28
+ totalKeyCount: number;
29
+ /** Personal budget, when one is set (undefined otherwise). */
30
+ user?: BudgetLimit;
31
+ /** Team budgets shared by the user's teams. */
32
+ teams: BudgetLimit[];
33
+ }
34
+ /**
35
+ * Collapses the current user's data into the budget limits that LiteLLM
36
+ * actually enforces for them: key budgets (top `maxKeys`, closest to the cap
37
+ * first), then the personal budget (when set), then each team budget. Team
38
+ * budgets are enforced for every key bound to that team; a key *without* a
39
+ * team falls back to the owner's personal budget.
40
+ */
41
+ export declare function buildBudgetSummary(user: UserInfo | null, teams: TeamInfo[], keys: VirtualKey[], maxKeys?: number): BudgetSummary;
42
+ /**
43
+ * One-line summary of a `BudgetSummary`, for a collapsed/compact header:
44
+ * how many concrete limits the user is subject to, and how close the
45
+ * closest one is to its cap. `closestPct` is null when there are no limits.
46
+ */
47
+ export declare function budgetHeadline(summary: BudgetSummary): {
48
+ count: number;
49
+ closestPct: number | null;
50
+ };
51
+ /** "30d" → "every 30 days"; "1d" → "daily". Returns null when duration is unset. */
52
+ export declare function fmtBudgetDuration(duration?: string): string | null;
53
+ /** status pill tone + meter tone for a budget at `pct`. */
54
+ export declare function budgetTone(pct: number): Tone;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,44 @@
1
+ /**
2
+ * LiteLLM budget-policy widget. Renders the enforcement hierarchy as a
3
+ * numbered flow — key → personal → team → global — and, against each level
4
+ * the signed-in user actually has a limit on, a live meter showing how close
5
+ * they are to the cap. Intended for at-a-glance use on a homepage card next
6
+ * to `LiteLLMHomeWidget`, but works anywhere.
7
+ *
8
+ * The policy text mirrors the LiteLLM proxy behaviour:
9
+ * - every request is checked against stacked limits, in order;
10
+ * - a key bound to a team is capped by the team budgets, not the owner's
11
+ * personal budget;
12
+ * - a limit with a `budget_duration` resets its spend when the window
13
+ * closes; without one it never resets.
14
+ *
15
+ * Two knobs shrink it for use as a secondary column:
16
+ * - `compact` drops the numbered rail and the policy footnote, showing
17
+ * only the limits the user actually has as a tight tagged meter list;
18
+ * - `collapsible` folds the body under a one-line summary header.
19
+ * `action` renders a host-supplied node (e.g. a button) pinned to the card
20
+ * bottom, always visible.
21
+ */
22
+ import React from 'react';
23
+ export interface LiteLLMBudgetWidgetProps {
24
+ /** Optional title override. Defaults to 'Budget Policy'. */
25
+ title?: string;
26
+ /** Max key budgets to show, closest to the cap first. Defaults to 3. */
27
+ maxKeys?: number;
28
+ /**
29
+ * Drop the numbered key→personal→team→global rail and the policy
30
+ * footnote; show only the limits the user actually has. Defaults to false.
31
+ */
32
+ compact?: boolean;
33
+ /** Fold the body under a clickable one-line summary header. Defaults to false. */
34
+ collapsible?: boolean;
35
+ /** Initial expanded state when `collapsible`. Defaults to true. */
36
+ defaultExpanded?: boolean;
37
+ /**
38
+ * Node rendered at the card bottom, below a divider and outside the
39
+ * collapsible region so it stays visible when collapsed — e.g. a
40
+ * "create key" button.
41
+ */
42
+ action?: React.ReactNode;
43
+ }
44
+ export declare const LiteLLMBudgetWidget: React.FC<LiteLLMBudgetWidgetProps>;