Never stop coding. Free MIT AI gateway: one endpoint, 375 providers (150+ free), 1,400+ models Kimi, Claude, GPT, Gemini, GLM, DeepSeek, MiniMax. Works with Claude Code, Codex, Cursor, OpenCode, Cline & Copilot. Quota-aware auto-fallback, RTK+Caveman compression saves 15-95% tokens, MCP/A2A, Desktop/PWA. Built by 900+ contributors
TypeScript a2aai-agentsai-gatewayanthropicclaudeclaude-codeclinecodexcopilotcursordeepseekfree-aigeminikimillm-gatewaymcpopenaiopenai-proxyqwentoken-saver
feat(quota-share): extract PoolCard + DimensionBar + AllocationTable + BurnRateChart + ConceptCard + Modals (B/F9)
diegosouzapw160f0693f398
diff --git a/src/app/(dashboard)/dashboard/costs/quota-share/components/AllocationTable.tsx b/src/app/(dashboard)/dashboard/costs/quota-share/components/AllocationTable.tsxnew file mode 100644index 0000000000..14ad070b1c--- /dev/null+++ b/src/app/(dashboard)/dashboard/costs/quota-share/components/AllocationTable.tsx@@ -0,0 +1,125 @@+"use client";++import { useTranslations } from "next-intl";+import type { PoolAllocation } from "@/lib/quota/dimensions";+import type { PoolUsageSnapshot } from "@/lib/quota/types";++interface AllocationTableProps {+ allocations: PoolAllocation[];+ usage: PoolUsageSnapshot | null;+ /** Map from apiKeyId to display name */+ keyLabels: Record<string, string>;+}++const SLICE_PALETTE = [+ "#a78bfa",+ "#60a5fa",+ "#34d399",+ "#fbbf24",+ "#f87171",+ "#22d3ee",+ "#f472b6",+ "#94a3b8",+];++export default function AllocationTable({ allocations, usage, keyLabels }: AllocationTableProps) {+ const t = useTranslations("quotaShare");++ if (allocations.length === 0) {+ return (+ <div className="text-[11px] text-text-muted italic py-3 text-center bg-bg-subtle/40 rounded-md">+ {t("noAllocations")}+ </div>+ );+ }++ // Build per-key consumption lookup from first dimension (primary)+ const primaryDim = usage?.dimensions?.[0];++ return (+ <div className="overflow-x-auto">+ <table className="w-full text-[11px]">+ <thead>+ <tr className="text-[10px] uppercase tracking-wide text-text-muted border-b border-border/40">+ <th className="text-left py-1 pr-2 font-semibold">API Key</th>+ <th className="text-right py-1 pr-2 font-semibold">Weight</th>+ <th className="text-right py-1 pr-2 font-semibold">{t("realConsumedColumn")}</th>+ <th className="text-right py-1 pr-2 font-semibold">{t("deficitColumn")}</th>+ <th className="text-right py-1 font-semibold">Policy</th>+ </tr>+ </thead>+ <tbody>+ {allocations.map((alloc, i) => {+ const color = SLICE_PALETTE[i % SLICE_PALETTE.length];+ const label = keyLabels[alloc.apiKeyId] || alloc.apiKeyId.slice(0, 12) + "…";++ const perKeyData = primaryDim?.perKey?.find((k) => k.apiKeyId === alloc.apiKeyId);+ const consumed = perKeyData?.consumed ?? null;+ const fairShare = perKeyData?.fairShare ?? null;+ const deficit = perKeyData !== undefined ? perKeyData.deficit : null;+ const borrowing = perKeyData?.borrowing ?? false;++ return (+ <tr key={alloc.apiKeyId} className="border-b border-border/20 last:border-0">+ <td className="py-1.5 pr-2">+ <div className="flex items-center gap-1.5 min-w-0">+ <span+ className="inline-block w-2.5 h-2.5 rounded-sm shrink-0"+ style={{ background: color }}+ />+ <span className="font-mono truncate text-text-main">{label}</span>+ {borrowing && (+ <span+ className="text-[9px] px-1 py-0.5 rounded bg-amber-500/15 text-amber-400 font-bold shrink-0"+ title={t("borrowingIndicator")}+ >+ {t("borrowingIndicator")}+ </span>+ )}+ </div>+ </td>+ <td className="py-1.5 pr-2 text-right font-bold tabular-nums" style={{ color }}>+ {alloc.weight}%+ </td>+ <td className="py-1.5 pr-2 text-right tabular-nums text-text-muted">+ {consumed !== null ? consumed.toLocaleString() : "—"}+ </td>+ <td className="py-1.5 pr-2 text-right tabular-nums">+ {deficit !== null ? (+ <span+ className={+ deficit > 0 ? "text-red-400" : deficit < 0 ? "text-emerald-400" : "text-text-muted"+ }+ >+ {deficit > 0 ? "+" : ""}{deficit.toLocaleString()}+ </span>+ ) : (+ <span className="text-text-muted">—</span>+ )}+ {fairShare !== null && (+ <span className="text-[9px] text-text-muted ml-1">+ (fair: {fairShare.toLocaleString()})+ </span>+ )}+ </td>+ <td className="py-1.5 text-right">+ <span+ className={`text-[9px] px-1.5 py-0.5 rounded font-semibold ${+ alloc.policy === "hard"+ ? "bg-red-500/10 text-red-400"+ : alloc.policy === "soft"+ ? "bg-amber-500/10 text-amber-400"+ : "bg-emerald-500/10 text-emerald-400"+ }`}+ >+ {alloc.policy}+ </span>+ </td>+ </tr>+ );+ })}+ </tbody>+ </table>+ </div>+ );+}diff --git a/src/app/(dashboard)/dashboard/costs/quota-share/components/BurnRateChart.tsx b/src/app/(dashboard)/dashboard/costs/quota-share/components/BurnRateChart.tsxnew file mode 100644index 0000000000..a223f4e6a9--- /dev/null+++ b/src/app/(dashboard)/dashboard/costs/quota-share/components/BurnRateChart.tsx@@ -0,0 +1,114 @@+"use client";++import { useState } from "react";+import dynamic from "next/dynamic";+import { useTranslations } from "next-intl";+import type { PoolUsageSnapshot } from "@/lib/quota/types";++// Lazy-load recharts — do NOT import at module level (B28)+const RechartsLineChart = dynamic(+ () => import("recharts").then((m) => ({ default: m.LineChart })),+ { ssr: false }+);+const RechartsLine = dynamic(() => import("recharts").then((m) => ({ default: m.Line })), {+ ssr: false,+});+const RechartsXAxis = dynamic(() => import("recharts").then((m) => ({ default: m.XAxis })), {+ ssr: false,+});+const RechartsYAxis = dynamic(() => import("recharts").then((m) => ({ default: m.YAxis })), {+ ssr: false,+});+const RechartsTooltip = dynamic(() => import("recharts").then((m) => ({ default: m.Tooltip })), {+ ssr: false,+});+const RechartsResponsiveContainer = dynamic(+ () => import("recharts").then((m) => ({ default: m.ResponsiveContainer })),+ { ssr: false }+);++export interface BurnRateChartProps {+ usage: PoolUsageSnapshot | null;+}++export default function BurnRateChart({ usage }: BurnRateChartProps) {+ const t = useTranslations("quotaShare");+ // Capture mount time once — avoids impure Date.now() call on every render+ const [nowMs] = useState(() => Date.now());++ const burnRate = usage?.burnRate;+ const hasData = burnRate && burnRate.tokensPerSecond > 0;++ if (!hasData) {+ return (+ <div className="h-20 flex items-center justify-center rounded-md bg-bg-subtle/30 border border-border/30">+ <p className="text-[11px] text-text-muted italic">{t("burnRateTitle")} — no data yet</p>+ </div>+ );+ }++ const { tokensPerSecond, timeToExhaustionMs } = burnRate;++ // Build a simple 6-point projection line+ const pointCount = 6;+ const intervalMs = timeToExhaustionMs ? timeToExhaustionMs / pointCount : 60_000 * 60;++ const primaryDim = usage?.dimensions?.[0];+ const currentConsumed = primaryDim?.consumedTotal ?? 0;+ const limit = primaryDim?.limit ?? 0;++ const data = Array.from({ length: pointCount + 1 }, (_, i) => {+ const t2 = nowMs + i * intervalMs;+ const projected = Math.min(currentConsumed + tokensPerSecond * ((i * intervalMs) / 1000), limit);+ return {+ time: new Date(t2).toLocaleTimeString(undefined, { hour: "2-digit", minute: "2-digit" }),+ consumed: Math.round(projected),+ };+ });++ const exhaustionLabel = timeToExhaustionMs+ ? `${t("burnRateExhaustsIn")} ${fmtDuration(timeToExhaustionMs)}`+ : null;++ return (+ <div className="space-y-1">+ <div className="flex items-center justify-between text-[10px] text-text-muted">+ <span className="font-semibold uppercase tracking-wide">{t("burnRateTitle")}</span>+ {exhaustionLabel && <span className="text-amber-400 font-semibold">{exhaustionLabel}</span>}+ </div>+ <div className="h-24">+ <RechartsResponsiveContainer width="100%" height="100%">+ <RechartsLineChart data={data}>+ <RechartsXAxis dataKey="time" tick={{ fontSize: 9 }} tickLine={false} axisLine={false} />+ <RechartsYAxis hide />+ <RechartsTooltip+ contentStyle={{+ background: "var(--bg-surface, #1e1e2e)",+ border: "1px solid var(--border)",+ fontSize: 10,+ }}+ />+ <RechartsLine+ type="monotone"+ dataKey="consumed"+ stroke="#a78bfa"+ strokeWidth={2}+ dot={false}+ strokeDasharray="4 2"+ />+ </RechartsLineChart>+ </RechartsResponsiveContainer>+ </div>+ </div>+ );+}++function fmtDuration(ms: number): string {+ const h = Math.floor(ms / 3_600_000);+ const m = Math.floor((ms % 3_600_000) / 60_000);+ if (h >= 24) {+ const d = Math.floor(h / 24);+ return `${d}d ${h % 24}h`;+ }+ return `${h}h ${m}m`;+}diff --git a/src/app/(dashboard)/dashboard/costs/quota-share/components/CreatePoolModal.tsx b/src/app/(dashboard)/dashboard/costs/quota-share/components/CreatePoolModal.tsxnew file mode 100644index 0000000000..d9be376aba--- /dev/null+++ b/src/app/(dashboard)/dashboard/costs/quota-share/components/CreatePoolModal.tsx@@ -0,0 +1,189 @@+"use client";++import { useMemo, useState } from "react";+import { useTranslations } from "next-intl";+import { Button, Modal } from "@/shared/components";+import type { QuotaPool, Policy, QuotaDimension } from "@/lib/quota/dimensions";++interface Connection {+ id: string;+ provider: string;+ name?: string;+ displayName?: string;+ email?: string;+}++interface PlanInfo {+ dimensions: QuotaDimension[];+ source: "auto" | "manual";+}++interface CreatePoolModalProps {+ connections: Connection[];+ plans: Record<string, PlanInfo>;+ existingPools: QuotaPool[];+ onClose: () => void;+ onCreate: (pool: Omit<QuotaPool, "id" | "createdAt">) => Promise<void>;+}++export default function CreatePoolModal({+ connections,+ plans,+ existingPools,+ onClose,+ onCreate,+}: CreatePoolModalProps) {+ const t = useTranslations("quotaShare");+ const [connectionId, setConnectionId] = useState("");+ const [name, setName] = useState("");+ const [defaultPolicy, setDefaultPolicy] = useState<Policy>("hard");+ const [saving, setSaving] = useState(false);+ const [error, setError] = useState<string | null>(null);++ const usedConnectionIds = useMemo(+ () => new Set(existingPools.map((p) => p.connectionId)),+ [existingPools]+ );++ const selectedConn = connections.find((c) => c.id === connectionId);+ const planInfo = connectionId ? plans[connectionId] : undefined;+ const hasPlan = planInfo && planInfo.dimensions.length > 0;++ const connLabel = (c: Connection) =>+ `${c.provider} / ${c.name || c.email || c.displayName || c.id.slice(0, 12)}`;++ const handleCreate = async () => {+ if (!selectedConn) return;+ if (usedConnectionIds.has(connectionId)) {+ setError(t("duplicatePoolError"));+ return;+ }+ const poolName = name.trim() || connLabel(selectedConn);+ setSaving(true);+ setError(null);+ try {+ await onCreate({+ connectionId,+ name: poolName,+ allocations: [],+ });+ onClose();+ } catch (err) {+ setError(err instanceof Error ? err.message : "Failed to create pool");+ } finally {+ setSaving(false);+ }+ };++ return (+ <Modal isOpen onClose={onClose} title={t("newPoolTitle")}>+ <div className="space-y-3">+ {/* Connection selector */}+ <div>+ <label className="text-[11px] uppercase tracking-wide text-text-muted font-semibold block mb-1">+ {t("providerConnection")}+ </label>+ <select+ value={connectionId}+ onChange={(e) => {+ setConnectionId(e.target.value);+ setName("");+ }}+ className="w-full px-3 py-2 rounded border border-border bg-bg-base text-sm"+ >+ <option value="">{t("selectConnection")}</option>+ {connections.map((c) => (+ <option key={c.id} value={c.id} disabled={usedConnectionIds.has(c.id)}>+ {connLabel(c)} {usedConnectionIds.has(c.id) ? t("alreadyUsedSuffix") : ""}+ </option>+ ))}+ </select>+ {connections.length === 0 && (+ <p className="text-[10px] text-amber-400 mt-1">{t("noEligibleConnections")}</p>+ )}+ </div>++ {/* Pool name */}+ {connectionId && (+ <div>+ <label className="text-[11px] uppercase tracking-wide text-text-muted font-semibold block mb-1">+ Pool name+ </label>+ <input+ type="text"+ value={name}+ onChange={(e) => setName(e.target.value)}+ placeholder={selectedConn ? connLabel(selectedConn) : "My quota pool"}+ className="w-full px-3 py-2 rounded border border-border bg-bg-base text-sm"+ />+ </div>+ )}++ {/* Default policy */}+ {connectionId && (+ <div>+ <label className="text-[11px] uppercase tracking-wide text-text-muted font-semibold block mb-1">+ {t("policyLabel")}+ </label>+ <div className="flex gap-1">+ {(["hard", "soft", "burst"] as Policy[]).map((p) => (+ <button+ key={p}+ type="button"+ onClick={() => setDefaultPolicy(p)}+ className={`px-3 py-1.5 rounded-md border text-xs cursor-pointer transition-colors ${+ defaultPolicy === p+ ? "bg-primary/15 border-primary/40 text-primary font-semibold"+ : "border-border text-text-muted hover:text-text-main"+ }`}+ >+ {p === "hard" ? t("policyHard") : p === "soft" ? t("policySoft") : t("policyBurst")}+ </button>+ ))}+ </div>+ </div>+ )}++ {/* Plan info */}+ {connectionId && hasPlan && (+ <div className="rounded-md border border-border/40 bg-bg-subtle/30 p-3 text-[11px] text-text-muted">+ <div className="font-semibold text-text-main mb-1">+ {t("multiDimensionLabel")} ({planInfo.source})+ </div>+ {planInfo.dimensions.map((d, i) => (+ <div key={i}>+ {d.unit} / {d.window}: {d.limit}+ </div>+ ))}+ </div>+ )}++ {/* Cap absolute notice */}+ {connectionId && (+ <div className="text-[10px] text-text-muted">+ <span className="font-semibold">{t("policyCapAbsoluteLabel")}:</span>{" "}+ {t("policyCapAbsolutePlaceholder")}+ </div>+ )}++ {error && (+ <p className="text-[11px] text-red-400 bg-red-500/10 px-3 py-2 rounded">{error}</p>+ )}++ <div className="flex justify-end gap-2 pt-2 border-t border-border/40">+ <Button variant="secondary" size="sm" onClick={onClose} disabled={saving}>+ {t("cancel")}+ </Button>+ <Button+ variant="primary"+ size="sm"+ onClick={handleCreate}+ disabled={!selectedConn || saving}+ >+ {saving ? t("loading") : t("createPool")}+ </Button>+ </div>+ </div>+ </Modal>+ );+}diff --git a/src/app/(dashboard)/dashboard/costs/quota-share/components/DimensionBar.tsx b/src/app/(dashboard)/dashboard/costs/quota-share/components/DimensionBar.tsxnew file mode 100644index 0000000000..8a7071985f--- /dev/null+++ b/src/app/(dashboard)/dashboard/costs/quota-share/components/DimensionBar.tsx@@ -0,0 +1,62 @@+"use client";++import { useState } from "react";+import { useTranslations } from "next-intl";+import type { QuotaDimension } from "@/lib/quota/dimensions";++interface DimensionBarProps {+ dimension: QuotaDimension;+ consumedTotal: number;+ /** ISO string for next reset, or null */+ resetAt?: string | null;+}++function fmtCountdown(ms: number): string {+ if (ms <= 0) return "now";+ const h = Math.floor(ms / 3_600_000);+ const m = Math.floor((ms % 3_600_000) / 60_000);+ if (h >= 24) {+ const d = Math.floor(h / 24);+ return `${d}d ${h % 24}h`;+ }+ return `${h}h ${m}m`;+}++export default function DimensionBar({ dimension, consumedTotal, resetAt }: DimensionBarProps) {+ const t = useTranslations("quotaShare");+ // Capture mount time once — avoids impure Date.now() call on every render+ const [now] = useState(() => Date.now());+ const usedPct =+ dimension.limit > 0 ? Math.min((consumedTotal / dimension.limit) * 100, 100) : 0;++ const barColor =+ usedPct >= 90+ ? "bg-red-500"+ : usedPct >= 70+ ? "bg-amber-400"+ : "bg-primary";++ const resetMs = resetAt ? new Date(resetAt).getTime() - now : null;+ const countdown = resetMs !== null && resetMs > 0 ? fmtCountdown(resetMs) : null;++ return (+ <div className="flex flex-col gap-1 min-w-0">+ <div className="flex items-center justify-between text-[10px] text-text-muted">+ <span className="font-semibold uppercase tracking-wide">+ {dimension.unit} / {dimension.window}+ </span>+ <span className="tabular-nums font-bold" style={{ color: usedPct >= 90 ? "#f87171" : usedPct >= 70 ? "#fbbf24" : undefined }}>+ {Math.round(usedPct)}%+ </span>+ </div>+ <div className="h-1.5 rounded-sm bg-black/6 dark:bg-white/6 overflow-hidden">+ <div className={`h-full rounded-sm transition-all ${barColor}`} style={{ width: `${usedPct}%` }} />+ </div>+ {countdown && (+ <div className="text-[10px] text-text-muted">+ {t("dimensionResetIn")} {countdown}+ </div>+ )}+ </div>+ );+}diff --git a/src/app/(dashboard)/dashboard/costs/quota-share/components/EditAllocationsModal.tsx b/src/app/(dashboard)/dashboard/costs/quota-share/components/EditAllocationsModal.tsxnew file mode 100644index 0000000000..875d1c66d0--- /dev/null+++ b/src/app/(dashboard)/dashboard/costs/quota-share/components/EditAllocationsModal.tsx@@ -0,0 +1,228 @@+"use client";++import { useState } from "react";+import { useTranslations } from "next-intl";+import { Button, Modal } from "@/shared/components";+import type { QuotaPool, PoolAllocation, Policy } from "@/lib/quota/dimensions";++interface ApiKey {+ id: string;+ name?: string;+}++interface EditAllocationsModalProps {+ pool: QuotaPool;+ apiKeys: ApiKey[];+ onClose: () => void;+ onSave: (allocations: PoolAllocation[]) => Promise<void>;+}++function shortId(id: string, max = 12) {+ return id.length > max ? `${id.slice(0, max)}…` : id;+}++const SLICE_PALETTE = [+ "#a78bfa",+ "#60a5fa",+ "#34d399",+ "#fbbf24",+ "#f87171",+ "#22d3ee",+ "#f472b6",+ "#94a3b8",+];++export default function EditAllocationsModal({+ pool,+ apiKeys,+ onClose,+ onSave,+}: EditAllocationsModalProps) {+ const t = useTranslations("quotaShare");+ const [drafts, setDrafts] = useState<PoolAllocation[]>(pool.allocations);+ const [saving, setSaving] = useState(false);+ const [error, setError] = useState<string | null>(null);++ const totalWeight = drafts.reduce(+ (s, a) => s + (Number.isFinite(a.weight) ? a.weight : 0),+ 0+ );++ const availableKeys = apiKeys.filter((k) => !drafts.some((a) => a.apiKeyId === k.id));++ const keyLabel = (id: string) => apiKeys.find((k) => k.id === id)?.name || shortId(id);++ const addKey = (id: string) => {+ setDrafts((prev) => [...prev, { apiKeyId: id, weight: 0, policy: "hard" }]);+ };++ const updateWeight = (id: string, value: number) => {+ setDrafts((prev) =>+ prev.map((a) =>+ a.apiKeyId === id ? { ...a, weight: Math.max(0, Math.min(100, value)) } : a+ )+ );+ };++ const updatePolicy = (id: string, policy: Policy) => {+ setDrafts((prev) => prev.map((a) => (a.apiKeyId === id ? { ...a, policy } : a)));+ };++ const updateCapValue = (id: string, capValue: number | undefined) => {+ setDrafts((prev) => prev.map((a) => (a.apiKeyId === id ? { ...a, capValue } : a)));+ };++ const removeKey = (id: string) => {+ setDrafts((prev) => prev.filter((a) => a.apiKeyId !== id));+ };++ const equalSplit = () => {+ if (drafts.length === 0) return;+ const each = Math.floor(100 / drafts.length);+ const remainder = 100 - each * drafts.length;+ setDrafts((prev) => prev.map((a, i) => ({ ...a, weight: each + (i < remainder ? 1 : 0) })));+ };++ const handleSave = async () => {+ setSaving(true);+ setError(null);+ try {+ await onSave(drafts);+ onClose();+ } catch (err) {+ setError(err instanceof Error ? err.message : "Failed to save");+ } finally {+ setSaving(false);+ }+ };++ return (+ <Modal isOpen onClose={onClose} title={t("editTitle")} size="lg">+ <div className="space-y-3">+ <div className="text-xs text-text-muted">+ {t("pool")}: <strong className="text-text-main">{pool.name}</strong>+ </div>++ {drafts.length === 0 ? (+ <div className="text-[12px] text-text-muted italic py-4 text-center bg-bg-subtle/40 rounded-md">+ {t("noKeysAdded")}+ </div>+ ) : (+ <div className="space-y-2">+ {drafts.map((a, i) => {+ const color = SLICE_PALETTE[i % SLICE_PALETTE.length];+ return (+ <div+ key={a.apiKeyId}+ className="grid items-center gap-2"+ style={{ gridTemplateColumns: "12px minmax(0,1fr) 70px 80px 90px 24px" }}+ >+ <span+ className="inline-block w-3 h-3 rounded-sm"+ style={{ background: color }}+ />+ <span className="text-[12px] font-mono truncate">{keyLabel(a.apiKeyId)}</span>+ <input+ type="number"+ min={0}+ max={100}+ value={a.weight}+ onChange={(e) => updateWeight(a.apiKeyId, Number(e.target.value))}+ className="px-2 py-1 rounded border border-border bg-bg-base text-sm text-right tabular-nums"+ title="Weight %"+ />+ {/* Cap absolute */}+ <input+ type="number"+ min={0}+ value={a.capValue ?? ""}+ onChange={(e) =>+ updateCapValue(a.apiKeyId, e.target.value ? Number(e.target.value) : undefined)+ }+ placeholder={t("policyCapAbsolutePlaceholder")}+ className="px-2 py-1 rounded border border-border bg-bg-base text-xs tabular-nums"+ title={t("policyCapAbsoluteLabel")}+ />+ {/* Policy per key */}+ <select+ value={a.policy}+ onChange={(e) => updatePolicy(a.apiKeyId, e.target.value as Policy)}+ className="px-1 py-1 rounded border border-border bg-bg-base text-xs"+ >+ <option value="hard">{t("policyHard")}</option>+ <option value="soft">{t("policySoft")}</option>+ <option value="burst">{t("policyBurst")}</option>+ </select>+ <button+ type="button"+ onClick={() => removeKey(a.apiKeyId)}+ className="p-0.5 rounded hover:bg-red-500/10 text-text-muted hover:text-red-400 cursor-pointer"+ >+ <span className="material-symbols-outlined text-[16px]">close</span>+ </button>+ </div>+ );+ })}+ </div>+ )}++ <div className="flex items-center justify-between text-[11px] pt-2 border-t border-border/40">+ <span+ className={`font-bold tabular-nums ${+ totalWeight === 100+ ? "text-emerald-400"+ : totalWeight > 100+ ? "text-red-400"+ : "text-amber-400"+ }`}+ >+ {t("totalLabel", { percent: totalWeight })}{" "}+ {totalWeight > 100 && t("totalExceeded")}+ </span>+ <div className="flex items-center gap-2">+ {availableKeys.length > 0 && (+ <select+ value=""+ onChange={(e) => e.target.value && addKey(e.target.value)}+ className="px-2 py-1 rounded border border-border bg-bg-base text-xs"+ >+ <option value="">{t("addKey")}</option>+ {availableKeys.map((k) => (+ <option key={k.id} value={k.id}>+ {k.name || shortId(k.id)}+ </option>+ ))}+ </select>+ )}+ <Button+ variant="secondary"+ size="sm"+ onClick={equalSplit}+ disabled={drafts.length === 0}+ >+ {t("equalSplit")}+ </Button>+ </div>+ </div>++ {error && (+ <p className="text-[11px] text-red-400 bg-red-500/10 px-3 py-2 rounded">{error}</p>+ )}++ <div className="flex justify-end gap-2 pt-2 border-t border-border/40">+ <Button variant="secondary" size="sm" onClick={onClose} disabled={saving}>+ {t("cancel")}+ </Button>+ <Button+ variant="primary"+ size="sm"+ onClick={handleSave}+ disabled={totalWeight > 100 || saving}+ >+ {saving ? t("loading") : t("save")}+ </Button>+ </div>+ </div>+ </Modal>+ );+}diff --git a/src/app/(dashboard)/dashboard/costs/quota-share/components/PoolCard.tsx b/src/app/(dashboard)/dashboard/costs/quota-share/components/PoolCard.tsxnew file mode 100644index 0000000000..bfa2540299--- /dev/null+++ b/src/app/(dashboard)/dashboard/costs/quota-share/components/PoolCard.tsx@@ -0,0 +1,145 @@+"use client";++import { useTranslations } from "next-intl";+import Card from "@/shared/components/Card";+import ProviderIcon from "@/shared/components/ProviderIcon";+import type { QuotaPool } from "@/lib/quota/dimensions";+import type { PoolUsageSnapshot } from "@/lib/quota/types";+import DimensionBar from "./DimensionBar";+import AllocationTable from "./AllocationTable";+import BurnRateChart from "./BurnRateChart";++export interface PoolCardProps {+ pool: QuotaPool;+ usage: PoolUsageSnapshot | null;+ /** Map from apiKeyId to display name */+ keyLabels: Record<string, string>;+ /** Connection display label */+ connectionLabel: string;+ /** Provider identifier */+ provider: string;+ onEdit: () => void;+ onRemove: () => void;+}++function computeStatus(usage: PoolUsageSnapshot | null): "green" | "amber" | "red" {+ if (!usage || usage.dimensions.length === 0) return "green";+ const utilizations = usage.dimensions.map((d) =>+ d.limit > 0 ? (d.consumedTotal / d.limit) * 100 : 0+ );+ const avg = utilizations.reduce((s, u) => s + u, 0) / utilizations.length;+ if (avg > 80) return "red";+ if (avg > 50) return "amber";+ return "green";+}++const STATUS_ICONS = {+ green: { icon: "check_circle", cls: "text-emerald-400" },+ amber: { icon: "warning", cls: "text-amber-400" },+ red: { icon: "error", cls: "text-red-400" },+};++export default function PoolCard({+ pool,+ usage,+ keyLabels,+ connectionLabel,+ provider,+ onEdit,+ onRemove,+}: PoolCardProps) {+ const t = useTranslations("quotaShare");+ const status = computeStatus(usage);+ const { icon: statusIcon, cls: statusCls } = STATUS_ICONS[status];++ // Check for plan dimensions from usage+ const hasDimensions = usage && usage.dimensions.length > 0;++ return (+ <Card padding="md">+ {/* Header */}+ <div className="flex items-start justify-between gap-3 mb-3">+ <div className="flex items-center gap-2 min-w-0">+ <div className="w-7 h-7 rounded-md flex items-center justify-center overflow-hidden shrink-0 bg-bg-subtle">+ <ProviderIcon providerId={provider} size={28} type="color" />+ </div>+ <div className="min-w-0">+ <div className="flex items-center gap-1.5">+ <span className="material-symbols-outlined text-[16px] shrink-0 {statusCls}">+ {statusIcon}+ </span>+ <span className={`text-[14px] shrink-0 ${statusCls}`}>+ <span className="material-symbols-outlined text-[16px]">{statusIcon}</span>+ </span>+ <span className="text-sm font-bold text-text-main truncate">+ {pool.name} · {connectionLabel}+ </span>+ </div>+ <div className="text-[11px] text-text-muted">+ {t("allocationsCount", { count: pool.allocations.length })} · ID: {pool.id.slice(0, 12)}+ </div>+ </div>+ </div>+ <div className="flex items-center gap-1">+ <button+ type="button"+ onClick={onEdit}+ title={t("editAllocations")}+ className="p-1.5 rounded-md hover:bg-bg-subtle text-text-muted hover:text-text-main cursor-pointer"+ >+ <span className="material-symbols-outlined text-[16px]">edit</span>+ </button>+ <button+ type="button"+ onClick={onRemove}+ title={t("removePool")}+ className="p-1.5 rounded-md hover:bg-red-500/10 text-text-muted hover:text-red-400 cursor-pointer"+ >+ <span className="material-symbols-outlined text-[16px]">delete</span>+ </button>+ </div>+ </div>++ {/* Dimensions side-by-side */}+ {hasDimensions ? (+ <div+ className="grid gap-3 mb-3"+ style={{+ gridTemplateColumns: `repeat(${Math.min(usage.dimensions.length, 3)}, 1fr)`,+ }}+ >+ {usage.dimensions.map((dim, i) => (+ <DimensionBar+ key={`${dim.unit}-${dim.window}-${i}`}+ dimension={{ unit: dim.unit, window: dim.window, limit: dim.limit }}+ consumedTotal={dim.consumedTotal}+ />+ ))}+ </div>+ ) : (+ <div className="text-[11px] text-text-muted italic mb-3">+ {t("multiDimensionLabel")} — {t("loading")}+ </div>+ )}++ {/* Allocation table */}+ <div className="mb-3">+ <h4 className="text-[10px] uppercase tracking-wide font-bold text-text-muted mb-1.5">+ Allocations+ </h4>+ <AllocationTable+ allocations={pool.allocations}+ usage={usage}+ keyLabels={keyLabels}+ />+ </div>++ {/* Burn rate chart */}+ {usage && (+ <div className="pt-2 border-t border-border/30">+ <BurnRateChart usage={usage} />+ </div>+ )}+ </Card>+ );+}diff --git a/src/app/(dashboard)/dashboard/costs/quota-share/components/QuotaConceptCard.tsx b/src/app/(dashboard)/dashboard/costs/quota-share/components/QuotaConceptCard.tsxnew file mode 100644index 0000000000..eadae5ca44--- /dev/null+++ b/src/app/(dashboard)/dashboard/costs/quota-share/components/QuotaConceptCard.tsx@@ -0,0 +1,52 @@+"use client";++import { useState } from "react";+import { useTranslations } from "next-intl";+import Card from "@/shared/components/Card";++export default function QuotaConceptCard() {+ const t = useTranslations("quotaShare");+ const [expanded, setExpanded] = useState(false);++ return (+ <Card padding="md">+ <button+ type="button"+ className="w-full flex items-center justify-between gap-2 cursor-pointer"+ onClick={() => setExpanded((p) => !p)}+ aria-expanded={expanded}+ >+ <div className="flex items-center gap-2">+ <span className="material-symbols-outlined text-[20px] text-primary">info</span>+ <span className="text-sm font-semibold text-text-main">{t("conceptTitle")}</span>+ </div>+ <span className="material-symbols-outlined text-[18px] text-text-muted">+ {expanded ? "expand_less" : "expand_more"}+ </span>+ </button>++ {expanded && (+ <div className="mt-3 space-y-2 text-xs text-text-muted leading-relaxed">+ <p>{t("conceptIntro")}</p>+ <div className="grid grid-cols-1 sm:grid-cols-2 gap-2 pt-1">+ <ConceptItem icon="balance" text={t("conceptFairShare")} />+ <ConceptItem icon="trending_up" text={t("conceptBorrowing")} />+ <ConceptItem icon="lock" text={t("conceptGlobalCap")} />+ <ConceptItem icon="schedule" text={t("conceptWindows")} />+ </div>+ </div>+ )}+ </Card>+ );+}++function ConceptItem({ icon, text }: { icon: string; text: string }) {+ return (+ <div className="flex items-start gap-1.5 rounded-md bg-bg-subtle/40 p-2">+ <span className="material-symbols-outlined text-[16px] text-primary shrink-0 mt-0.5">+ {icon}+ </span>+ <span>{text}</span>+ </div>+ );+}