@acarmisc/backstage-plugin-litellm 0.28.0 → 0.29.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.
Files changed (54) hide show
  1. package/dist/api.d.ts +25 -3
  2. package/dist/budget.d.ts +24 -0
  3. package/dist/components/AuditLog.d.ts +2 -2
  4. package/dist/components/BudgetLimitList.d.ts +7 -7
  5. package/dist/components/DashboardHeader.d.ts +5 -3
  6. package/dist/components/GenerateKeyButton.d.ts +2 -2
  7. package/dist/components/GenerateKeyDialog.d.ts +2 -2
  8. package/dist/components/KeyFormDialog.d.ts +4 -16
  9. package/dist/components/KeySnippets.d.ts +20 -0
  10. package/dist/components/KeysTable.d.ts +5 -2
  11. package/dist/components/LiteLLMBudgetGauges.d.ts +20 -18
  12. package/dist/components/LiteLLMBudgetWidget.d.ts +14 -3
  13. package/dist/components/LiteLLMHomeWidget.d.ts +7 -2
  14. package/dist/components/LiteLLMPage.d.ts +2 -2
  15. package/dist/components/ModelsTable.d.ts +2 -2
  16. package/dist/components/TeamUsage.d.ts +4 -2
  17. package/dist/components/UsageStats.d.ts +4 -2
  18. package/dist/components/keyFormHelpers.d.ts +14 -0
  19. package/dist/components/ui/Gauge.d.ts +24 -0
  20. package/dist/components/ui/Meter.d.ts +13 -0
  21. package/dist/components/ui/charts.d.ts +34 -0
  22. package/dist/components/ui/index.d.ts +6 -0
  23. package/dist/components/ui/pills.d.ts +23 -0
  24. package/dist/components/ui/surfaces.d.ts +65 -0
  25. package/dist/components/ui/tokens.d.ts +52 -0
  26. package/dist/ctas.d.ts +28 -0
  27. package/dist/dates.d.ts +25 -0
  28. package/dist/feedback.d.ts +17 -0
  29. package/dist/format.d.ts +37 -1
  30. package/dist/homeWidgetHelpers.d.ts +40 -0
  31. package/dist/hooks/index.d.ts +3 -0
  32. package/dist/hooks/useCopyToClipboard.d.ts +30 -0
  33. package/dist/hooks/useLiteLLMProfile.d.ts +32 -0
  34. package/dist/index.cjs.js +4927 -2811
  35. package/dist/index.cjs.js.map +4 -4
  36. package/dist/index.esm.js +4963 -2832
  37. package/dist/index.esm.js.map +4 -4
  38. package/dist/keyFilter.d.ts +12 -0
  39. package/dist/keyFormValidation.d.ts +38 -0
  40. package/dist/keyLabels.d.ts +16 -0
  41. package/dist/permissions.d.ts +1 -5
  42. package/dist/plugin.d.ts +6 -5
  43. package/dist/profileCache.d.ts +46 -0
  44. package/dist/routeHelpers.d.ts +6 -0
  45. package/dist/routes.d.ts +1 -0
  46. package/dist/types.d.ts +15 -189
  47. package/dist/unprovisionedCopy.d.ts +7 -0
  48. package/dist/widgetState.d.ts +54 -0
  49. package/package.json +5 -2
  50. package/dist/api.test.d.ts +0 -1
  51. package/dist/budget.test.d.ts +0 -1
  52. package/dist/components/ui.d.ts +0 -206
  53. package/dist/format.test.d.ts +0 -1
  54. package/dist/permissions.test.d.ts +0 -1
@@ -0,0 +1,52 @@
1
+ import type { Theme } from '@mui/material/styles';
2
+ /** `2026-08-16` → `Aug 16`. Falls back to the raw value for anything else. */
3
+ export declare const fmtDateShort: (value: string) => string;
4
+ /** 54253484 → `54.3M`. Keeps axis labels from swallowing the plot area. */
5
+ export declare const fmtCompact: (n: number) => string;
6
+ /** Compact currency for axis ticks — `$24`, `$1.2K`. */
7
+ export declare const fmtUsdCompact: (n: number) => string;
8
+ /** Categorical ramp, ordered so neighbouring series stay distinguishable. */
9
+ export declare const CHART_COLORS: readonly ["#6366F1", "#14B8A6", "#F59E0B", "#EC4899", "#38BDF8", "#84CC16", "#F97316", "#A855F7"];
10
+ /** Fixed colours for series that carry meaning rather than identity. */
11
+ export declare const SERIES: {
12
+ readonly input: "#6366F1";
13
+ readonly output: "#14B8A6";
14
+ readonly success: "#0d9488";
15
+ readonly failure: "#ea580c";
16
+ readonly spend: "#F59E0B";
17
+ readonly budget: "#ea580c";
18
+ };
19
+ /** Stable colour per series name, so a model keeps its colour across charts. */
20
+ export declare function chartColor(name: string): string;
21
+ /** Axis / grid / legend props shared by every chart, derived from the theme. */
22
+ export declare function useChartTheme(): {
23
+ grid: {
24
+ stroke: string;
25
+ strokeDasharray: string;
26
+ vertical: boolean;
27
+ };
28
+ axis: {
29
+ tick: {
30
+ fontSize: number;
31
+ fill: string;
32
+ };
33
+ tickLine: boolean;
34
+ axisLine: {
35
+ stroke: string;
36
+ };
37
+ };
38
+ legend: {
39
+ wrapperStyle: {
40
+ fontSize: number;
41
+ color: string;
42
+ paddingTop: number;
43
+ };
44
+ iconType: "circle";
45
+ iconSize: number;
46
+ };
47
+ cursor: {
48
+ fill: string;
49
+ };
50
+ };
51
+ export type Tone = 'neutral' | 'success' | 'warning' | 'danger' | 'info' | 'accent';
52
+ export declare function toneColor(theme: Theme, tone: Tone): string;
package/dist/ctas.d.ts ADDED
@@ -0,0 +1,28 @@
1
+ /** Preset action-bar buttons. `label` overrides the default copy. */
2
+ export type BudgetCtaKind = 'new-key' | 'module' | 'all-limits';
3
+ export interface BudgetCtaSpec {
4
+ kind: BudgetCtaKind;
5
+ /** Override the default label. */
6
+ label?: string;
7
+ }
8
+ /** Either a bare kind (`'module'`) or a spec object (`{ kind: 'module' }`). */
9
+ export type BudgetCta = BudgetCtaKind | BudgetCtaSpec;
10
+ export declare const DEFAULT_CTAS: BudgetCtaKind[];
11
+ /**
12
+ * Resolves which action-bar buttons to render.
13
+ *
14
+ * - `new-key` is shown when explicitly listed, or automatically (first) when
15
+ * the user has no keys yet — but never while loading or when the profile
16
+ * errored / the user isn't provisioned (a generate flow would fail).
17
+ * - `all-limits` is dropped when there are no limits to expand.
18
+ */
19
+ export declare function resolveCtas(spec: {
20
+ ctas?: BudgetCta[];
21
+ hasKeys: boolean;
22
+ viewState: {
23
+ kind: string;
24
+ };
25
+ limitCount: number;
26
+ }): Array<BudgetCtaSpec & {
27
+ kind: BudgetCtaKind;
28
+ }>;
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Convert a Date to a local calendar day string in YYYY-MM-DD format.
3
+ * Uses local calendar components (getFullYear, getMonth, getDate),
4
+ * not UTC, to avoid timezone shifts at month/year boundaries.
5
+ */
6
+ export declare function toLocalDay(d: Date): string;
7
+ /**
8
+ * Month-to-date range as YYYY-MM-DD strings: the 1st of the current month through today.
9
+ * Uses local calendar, not UTC, to respect the user's timezone.
10
+ */
11
+ export declare function monthToDateRange(now?: Date): {
12
+ startDate: string;
13
+ endDate: string;
14
+ };
15
+ export type DatePreset = 'today' | '24h' | '7d' | '30d';
16
+ /**
17
+ * Build a date range from a preset name. Returns an object with
18
+ * Date objects and pre-formatted YYYY-MM-DD strings for API calls.
19
+ */
20
+ export declare function localDateRange(preset: DatePreset, now?: Date): {
21
+ start: Date;
22
+ end: Date;
23
+ startDate: string;
24
+ endDate: string;
25
+ };
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Feedback message generation for toast notifications.
3
+ * Maps action outcomes to appropriate toast messages and severity levels.
4
+ */
5
+ export type AlertSeverity = 'success' | 'warning' | 'error' | 'info';
6
+ export interface AlertMessage {
7
+ message: string;
8
+ severity: AlertSeverity;
9
+ }
10
+ type ActionKind = 'generateSuccess' | 'generateError' | 'updateSuccess' | 'updateError' | 'blockSuccess' | 'blockError' | 'unblockSuccess' | 'unblockError' | 'resetSpendSuccess' | 'resetSpendError' | 'deleteSuccess' | 'deleteError' | 'deleteAlreadyDeleted' | 'pruneSuccess' | 'prunePartial' | 'pruneError' | 'teamSaveSuccess' | 'teamSaveError' | 'knowledgeBaseSuccess' | 'mcpServerSuccess';
11
+ /**
12
+ * Generate a toast alert message for an action outcome.
13
+ * For inline dialog errors (e.g., key form validation), return null
14
+ * to let the dialog handle it internally.
15
+ */
16
+ export declare function toastFor(kind: ActionKind, errorMsg?: string): AlertMessage | null;
17
+ export {};
package/dist/format.d.ts CHANGED
@@ -1,7 +1,43 @@
1
- export declare const fmtUsd: (n: number) => string;
1
+ /**
2
+ * Format a number as USD currency with 2 decimals. Non-zero values below
3
+ * one cent render as `<$0.01`. Zero, null, undefined, or NaN render as `$0.00`.
4
+ * Negative values keep the leading minus sign.
5
+ */
6
+ export declare const fmtUsd: (n: number | null | undefined) => string;
2
7
  export declare const fmtInt: (n: number) => string;
8
+ /**
9
+ * Format a count for display, showing "–" when the value is null or undefined.
10
+ * Used to indicate that data failed to load, distinct from a zero count.
11
+ */
12
+ export declare const formatCount: (n: number | null | undefined) => string;
3
13
  /**
4
14
  * Estimate how many tokens a USD budget buys at a given per-token price.
5
15
  * Returns null when the price is missing or non-positive.
6
16
  */
7
17
  export declare const estimateTokensFromBudget: (budget: number, pricePerToken?: number) => number | null;
18
+ /**
19
+ * Format TPM and RPM limits for display. When neither limit is set (both null/undefined),
20
+ * returns 'Unlimited'. Otherwise returns formatted values with 'Unlimited' for the missing limit.
21
+ * Uses fmtInt for digit grouping.
22
+ */
23
+ export declare const fmtLimits: (tpm: number | null | undefined, rpm: number | null | undefined) => string;
24
+ export interface ModelInfo {
25
+ model_name: string;
26
+ }
27
+ export interface UsageModelBreakdown {
28
+ total_spend: number;
29
+ prompt_tokens: number;
30
+ completion_tokens: number;
31
+ total_tokens: number;
32
+ api_requests: number;
33
+ successful_requests: number;
34
+ failed_requests: number;
35
+ }
36
+ /**
37
+ * Filter models to only those that have usage data in the given period.
38
+ * Keeps 'all' as a first option and extracts model names from the full list,
39
+ * then filters to only those present in the usage breakdown.
40
+ */
41
+ export declare const modelsWithUsage: (usage: {
42
+ usage_by_model?: Record<string, UsageModelBreakdown>;
43
+ } | null, models: ModelInfo[]) => string[];
@@ -0,0 +1,40 @@
1
+ import type { UsageMetrics } from './types';
2
+ /**
3
+ * Build a human-readable date range caption from two YYYY-MM-DD strings.
4
+ * Example: '2026-09-01', '2026-09-29' → 'Sep 1 – Sep 29'
5
+ */
6
+ export declare function rangeCaption(startDay: string, endDay: string): string;
7
+ /**
8
+ * Build a month-to-date range caption from a Date.
9
+ * Example: new Date('2026-09-29') → 'Sep 1 – 29'
10
+ * Handles same-day (returns date twice) and month/year edge cases.
11
+ */
12
+ export declare function mtdCaption(now?: Date): string;
13
+ /**
14
+ * Build an aria-label summary for a sparkline chart showing daily spend data.
15
+ * Includes total spend, peak value, and the date it occurred.
16
+ * Example: 'Daily spend over 7 days, total $129.90, peak $41.20 on Sep 27'
17
+ */
18
+ export declare function sparklineAriaLabel(points: Array<{
19
+ date: string;
20
+ spend: number;
21
+ }>): string;
22
+ /**
23
+ * Format usage metrics as a single summary line: '$X spent · YM in · ZM out'
24
+ * Handles zero usage and undefined values gracefully.
25
+ */
26
+ export declare function usageSummary(usage: UsageMetrics | null | undefined): string;
27
+ /**
28
+ * Build ARIA attributes for a meter component showing a percentage value.
29
+ * When value > 100%, sets aria-valuetext to include "over cap" warning.
30
+ * Returns an object with role, aria-valuenow, aria-valuemin, aria-valuemax,
31
+ * aria-label, and optionally aria-valuetext.
32
+ */
33
+ export declare function meterAria(pct: number, label?: string): {
34
+ role: string;
35
+ 'aria-valuenow': number;
36
+ 'aria-valuemin': number;
37
+ 'aria-valuemax': number;
38
+ 'aria-label'?: string;
39
+ 'aria-valuetext'?: string;
40
+ };
@@ -0,0 +1,3 @@
1
+ export { useCopyToClipboard } from './useCopyToClipboard';
2
+ export { useLiteLLMProfile, invalidateLiteLLMProfile } from './useLiteLLMProfile';
3
+ export type { LiteLLMProfileResult } from './useLiteLLMProfile';
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Pure helper: determine if the Clipboard API is available.
3
+ */
4
+ export declare function isClipboardApiAvailable(): boolean;
5
+ /**
6
+ * Pure helper: fallback copy via textarea and document.execCommand.
7
+ * Returns true if successful, false otherwise.
8
+ */
9
+ export declare function fallbackCopyToClipboard(text: string): boolean;
10
+ /**
11
+ * Pure helper: create a timer for the copied state.
12
+ * Returns the timer ID so the caller can manage cleanup.
13
+ */
14
+ export declare function startCopiedTimer(onCopiedChange: (copied: boolean) => void, durationMs?: number): ReturnType<typeof setTimeout>;
15
+ /**
16
+ * Hook: copy text to clipboard with visual feedback.
17
+ *
18
+ * @returns {copy, copied, error} - async copy function, copied state, and error if any
19
+ *
20
+ * - `copy(text)`: async function that copies text and returns true if successful
21
+ * - `copied`: true for 2s after successful copy, then resets
22
+ * - `error`: error object if copy failed; shows via alertApi
23
+ *
24
+ * Uses navigator.clipboard.writeText with fallback to textarea + execCommand.
25
+ */
26
+ export declare function useCopyToClipboard(): {
27
+ copy: (text: string) => Promise<boolean>;
28
+ copied: boolean;
29
+ error: Error | null;
30
+ };
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Unified hook for fetching the user's LiteLLM profile: userInfo, teams, keys, models, and config.
3
+ * Results are cached per API instance with a 30s TTL and single-flight deduplication.
4
+ * Callers can invalidate the cache after mutations to ensure fresh data.
5
+ */
6
+ import { LiteLlmApiInterface } from '../api';
7
+ import { UserInfo, TeamInfo, VirtualKey, ModelInfo, LiteLlmConfig } from '../types';
8
+ import { ProfileCache } from '../profileCache';
9
+ export interface LiteLLMProfileResult {
10
+ userInfo: UserInfo | null;
11
+ teams: TeamInfo[];
12
+ keys: VirtualKey[];
13
+ models: ModelInfo[];
14
+ config: LiteLlmConfig | null;
15
+ loading: boolean;
16
+ error: string | null;
17
+ retry: () => void;
18
+ }
19
+ /**
20
+ * Fetch the complete user profile (userInfo, teams, keys, models, config).
21
+ * Results are cached with a 30s TTL and single-flight deduplication per API instance.
22
+ * Call the returned `retry()` after mutations to invalidate the cache.
23
+ */
24
+ export declare function useLiteLLMProfile(cache?: ProfileCache): LiteLLMProfileResult;
25
+ /**
26
+ * Invalidate the profile cache for an API instance after a mutation
27
+ * (e.g., after creating/updating/deleting a key or team).
28
+ *
29
+ * @param api The API instance to invalidate.
30
+ * @param cache The cache instance (defaults to the singleton).
31
+ */
32
+ export declare function invalidateLiteLLMProfile(api: LiteLlmApiInterface, cache?: ProfileCache): void;