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): available-endpoints card + per-key model preview
diegosouzapwdf7b1e83c202
diff --git a/src/app/(dashboard)/dashboard/costs/quota-share/QuotaSharePageClient.tsx b/src/app/(dashboard)/dashboard/costs/quota-share/QuotaSharePageClient.tsxindex 9c28789aff..42f78f897a 100644--- a/src/app/(dashboard)/dashboard/costs/quota-share/QuotaSharePageClient.tsx+++ b/src/app/(dashboard)/dashboard/costs/quota-share/QuotaSharePageClient.tsx@@ -13,6 +13,7 @@ import { usePoolUsage } from "./hooks/usePoolUsage";import { useLocalStoragePoolMigration } from "./hooks/useLocalStoragePoolMigration";import { usePoolsUsageAggregate } from "./hooks/usePoolsUsageAggregate";import QuotaConceptCard from "./components/QuotaConceptCard";+import QuotaEndpointsCard from "./components/QuotaEndpointsCard";import PoolCard from "./components/PoolCard";import PoolWizard from "./components/PoolWizard";@@ -427,6 +428,14 @@ export default function QuotaSharePageClient() {{/* Concept card */}<QuotaConceptCard />+ {/* Endpoints card */}+ <QuotaEndpointsCard+ groups={groups}+ pools={pools}+ connections={connections}+ apiKeys={apiKeys}+ />+{/* Stats */}<div className="grid grid-cols-2 lg:grid-cols-4 gap-3"><StatCard label={t("kpiActivePools")} value={String(stats.activePools)} />diff --git a/src/app/(dashboard)/dashboard/costs/quota-share/components/QuotaEndpointsCard.tsx b/src/app/(dashboard)/dashboard/costs/quota-share/components/QuotaEndpointsCard.tsxnew file mode 100644index 0000000000..197a1fb239--- /dev/null+++ b/src/app/(dashboard)/dashboard/costs/quota-share/components/QuotaEndpointsCard.tsx@@ -0,0 +1,289 @@+"use client";++import { useState, useMemo } from "react";+import { useTranslations } from "next-intl";+import useEmailPrivacyStore from "@/store/emailPrivacyStore";+import { maskEmailLikeValue } from "@/shared/utils/maskEmail";+import Card from "@/shared/components/Card";+import { quotaModelName, quotaGroupSlug } from "@/lib/quota/quotaModelNaming";++// ─────────────────────────────────────────────────────────────────────────────+// Local types (mirrors QuotaSharePageClient)+// ─────────────────────────────────────────────────────────────────────────────++interface QuotaGroup {+ id: string;+ name: string;+ createdAt: string;+}++interface QuotaPool {+ id: string;+ connectionId: string;+ connectionIds?: string[];+ groupId?: string;+ [key: string]: unknown;+}++interface Connection {+ id: string;+ provider: string;+ name?: string;+ displayName?: string;+ email?: string;+}++interface ApiKey {+ id: string;+ name?: string;+}++// ─────────────────────────────────────────────────────────────────────────────+// Representative model list per provider (same constant as PoolWizard)+// ─────────────────────────────────────────────────────────────────────────────++const PREVIEW_MODELS_BY_PROVIDER: Record<string, string[]> = {+ openai: ["gpt-4o", "gpt-4o-mini", "o3", "gpt-4-turbo"],+ anthropic: ["claude-opus-4-5", "claude-sonnet-4-5", "claude-haiku-3-5"],+ gemini: ["gemini-2.5-pro", "gemini-2.5-flash", "gemini-2.0-flash"],+ cx: ["gpt-5.4-mini", "gpt-5.4", "o3"],+ codex: ["codex-mini-latest", "codex-latest"],+ glm: ["glm-4", "glm-4v", "glm-z1-airx"],+ minimax: ["minimax-m1", "minimax-text-01"],+ kimi: ["moonshot-v1-8k", "moonshot-v1-32k"],+ default: ["model-a", "model-b", "model-c"],+};++const MAX_MODELS_SHOWN = 3;++function getPreviewModels(provider: string): string[] {+ return PREVIEW_MODELS_BY_PROVIDER[provider] ?? PREVIEW_MODELS_BY_PROVIDER["default"];+}++// ─────────────────────────────────────────────────────────────────────────────+// Props+// ─────────────────────────────────────────────────────────────────────────────++interface QuotaEndpointsCardProps {+ groups: QuotaGroup[];+ pools: QuotaPool[];+ connections: Connection[];+ apiKeys: ApiKey[];+}++// ─────────────────────────────────────────────────────────────────────────────+// Component+// ─────────────────────────────────────────────────────────────────────────────++export default function QuotaEndpointsCard({+ groups,+ pools,+ connections,+ apiKeys,+}: QuotaEndpointsCardProps) {+ const t = useTranslations("quotaShare");+ const emailsVisible = useEmailPrivacyStore((s) => s.emailsVisible);++ const [selectedKeyId, setSelectedKeyId] = useState<string>("");+ const [previewModels, setPreviewModels] = useState<string[] | null>(null);+ const [loadingPreview, setLoadingPreview] = useState(false);++ // ── Derive default model list from groups + pools + connections ──────────────+ // For each group, collect all pools that belong to it, then for each pool's+ // providers (from connectionIds), generate qtSd/<groupSlug>/<provider>/<model>+ // using the same PREVIEW_MODELS_BY_PROVIDER map that PoolWizard uses.+ //+ // This is a REPRESENTATIVE list — the full list is served by /v1/models.++ const defaultByGroup = useMemo<+ Array<{+ group: QuotaGroup;+ entries: Array<{ provider: string; models: string[] }>;+ }>+ >(() => {+ return groups.map((group) => {+ const groupPools = pools.filter(+ (p) => ((p as { groupId?: string }).groupId ?? "group-demo") === group.id+ );++ // Collect unique providers for this group+ const providerSet = new Set<string>();+ for (const pool of groupPools) {+ const cids = pool.connectionIds ?? [pool.connectionId];+ for (const cid of cids) {+ const conn = connections.find((c) => c.id === cid);+ if (conn) providerSet.add(conn.provider);+ }+ }++ const entries = Array.from(providerSet).map((provider) => {+ const previewModelIds = getPreviewModels(provider);+ const models = previewModelIds+ .slice(0, MAX_MODELS_SHOWN)+ .map((m) => quotaModelName(group.name, provider, m));+ return { provider, models };+ });++ return { group, entries };+ });+ }, [groups, pools, connections]);++ // ── Key name with optional email masking ─────────────────────────────────────++ const keyLabel = (key: ApiKey) => {+ const raw = key.name || key.id.slice(0, 12) + "…";+ return emailsVisible ? raw : maskEmailLikeValue(raw);+ };++ // ── Key selector handler ─────────────────────────────────────────────────────++ const handleKeyChange = async (keyId: string) => {+ setSelectedKeyId(keyId);+ if (!keyId) {+ setPreviewModels(null);+ return;+ }+ setLoadingPreview(true);+ try {+ const res = await fetch(`/api/quota/keys/${keyId}/models`);+ if (res.ok) {+ const body = (await res.json()) as { models: string[] };+ setPreviewModels(Array.isArray(body.models) ? body.models : []);+ } else {+ setPreviewModels([]);+ }+ } catch {+ setPreviewModels([]);+ } finally {+ setLoadingPreview(false);+ }+ };++ // ── Compute the combined default model count across all groups ────────────────++ const hasAnyDefaultModels = defaultByGroup.some((g) =>+ g.entries.some((e) => e.models.length > 0)+ );++ // ── Render ───────────────────────────────────────────────────────────────────++ const hasData = groups.length > 0 && pools.length > 0;++ return (+ <Card padding="sm">+ {/* Header row */}+ <div className="flex items-start justify-between gap-3 flex-wrap">+ <div className="flex items-start gap-2">+ <span className="material-symbols-outlined text-[18px] text-primary shrink-0 mt-0.5">+ api+ </span>+ <div>+ <span className="text-sm font-semibold text-text-main">{t("endpointsTitle")}</span>+ <p className="text-xs text-text-muted mt-0.5 max-w-lg">{t("endpointsHint")}</p>+ </div>+ </div>++ {/* Key preview selector */}+ {apiKeys.length > 0 && (+ <div className="flex items-center gap-2 shrink-0">+ <label className="text-xs text-text-muted whitespace-nowrap">+ {t("previewForKey")}+ </label>+ <select+ value={selectedKeyId}+ onChange={(e) => void handleKeyChange(e.target.value)}+ className="px-2 py-1 rounded border border-border bg-bg-base text-xs text-text-main min-w-[140px]"+ >+ <option value="">{t("previewKeyNone")}</option>+ {apiKeys.map((k) => (+ <option key={k.id} value={k.id}>+ {keyLabel(k)}+ </option>+ ))}+ </select>+ </div>+ )}+ </div>++ {/* Base URL line */}+ <div className="mt-3 flex items-center gap-2 rounded-md bg-bg-subtle/50 border border-border/40 px-3 py-2">+ <span className="text-[10px] uppercase tracking-wide text-text-muted font-semibold shrink-0">+ {t("endpointsBaseUrl")}+ </span>+ <code className="text-xs text-primary font-mono">POST /v1/chat/completions</code>+ <span className="text-xs text-text-muted mx-1">·</span>+ <code className="text-xs text-text-muted font-mono">+ model: "qtSd/<group>/<provider>/<model>"+ </code>+ </div>++ {/* Model listing */}+ <div className="mt-3">+ {loadingPreview ? (+ <div className="text-xs text-text-muted animate-pulse py-2">{t("loading")}</div>+ ) : previewModels !== null ? (+ // Per-key preview from the API+ <div>+ {previewModels.length === 0 ? (+ <p className="text-xs text-text-muted italic">{t("noAllocations")}</p>+ ) : (+ <ul className="space-y-0.5">+ {previewModels.map((m) => (+ <li key={m}>+ <code className="text-[11px] font-mono text-text-main bg-bg-subtle/40 rounded px-1.5 py-0.5 inline-block">+ {m}+ </code>+ </li>+ ))}+ </ul>+ )}+ </div>+ ) : hasData && hasAnyDefaultModels ? (+ // Default view: grouped by group → provider → model ids+ <div className="space-y-3">+ {defaultByGroup.map(({ group, entries }) => {+ if (entries.length === 0) return null;+ return (+ <div key={group.id}>+ <div className="flex items-center gap-1.5 mb-1">+ <span className="material-symbols-outlined text-[13px] text-text-muted">+ folder+ </span>+ <span className="text-[11px] font-semibold text-text-muted uppercase tracking-wide">+ {quotaGroupSlug(group.name)}+ </span>+ </div>+ <div className="space-y-1 pl-4">+ {entries.map(({ provider, models }) => (+ <div key={provider} className="space-y-0.5">+ <span className="text-[10px] text-text-muted font-medium">{provider}</span>+ <ul className="space-y-0.5">+ {models.map((m) => (+ <li key={m}>+ <code className="text-[11px] font-mono text-text-main bg-bg-subtle/40 rounded px-1.5 py-0.5 inline-block">+ {m}+ </code>+ </li>+ ))}+ </ul>+ </div>+ ))}+ </div>+ </div>+ );+ })}+ </div>+ ) : (+ // No pools yet — show the format placeholder+ <div className="text-xs text-text-muted italic">+ <code className="font-mono text-[11px]">+ qtSd/<groupSlug>/<provider>/<model>+ </code>+ {" — "}+ {t("emptyDescription")}+ </div>+ )}+ </div>+ </Card>+ );+}diff --git a/src/i18n/messages/en.json b/src/i18n/messages/en.jsonindex b20d38a617..ab0e06c3c6 100644--- a/src/i18n/messages/en.json+++ b/src/i18n/messages/en.json@@ -7913,7 +7913,12 @@"groupAllocationNote": "Allocations apply to all pools in this group via the shared quota layer.","groupNamePrompt": "Enter group name","wizardGroupLabel": "Group",- "allGroups": "All groups"+ "allGroups": "All groups",+ "endpointsTitle": "Available endpoints",+ "endpointsHint": "Call these virtual models with any allocated key — routing + quota are handled per group.",+ "previewForKey": "Preview for key",+ "previewKeyNone": "(all endpoints)",+ "endpointsBaseUrl": "Base URL"},"plugins": {"title": "Plugins",diff --git a/src/i18n/messages/pt-BR.json b/src/i18n/messages/pt-BR.jsonindex ed94723077..afcb621a25 100644--- a/src/i18n/messages/pt-BR.json+++ b/src/i18n/messages/pt-BR.json@@ -5418,7 +5418,12 @@"groupAllocationNote": "As alocações se aplicam a todos os pools deste grupo através da camada de cota compartilhada.","groupNamePrompt": "Digite o nome do grupo","wizardGroupLabel": "Grupo",- "allGroups": "Todos os grupos"+ "allGroups": "Todos os grupos",+ "endpointsTitle": "Endpoints disponíveis",+ "endpointsHint": "Chame estes modelos virtuais com qualquer chave alocada — roteamento + cota são tratados por grupo.",+ "previewForKey": "Pré-visualizar p/ chave",+ "previewKeyNone": "(todos os endpoints)",+ "endpointsBaseUrl": "URL base"},"requestLogger": {"recording": "Recording",diff --git a/tests/unit/quota-endpoints-card.test.ts b/tests/unit/quota-endpoints-card.test.tsnew file mode 100644index 0000000000..713565634f--- /dev/null+++ b/tests/unit/quota-endpoints-card.test.ts@@ -0,0 +1,163 @@+/**+ * tests/unit/quota-endpoints-card.test.ts+ *+ * Task 7 — source-scan assertions for QuotaEndpointsCard component:+ * - renders /v1/chat/completions base URL+ * - references quotaModelName or builds qtSd/ ids+ * - has a <select> with a previewKeyNone option+ * - fetches /api/quota/keys/{id}/models when a key is selected+ * - QuotaSharePageClient imports + renders <QuotaEndpointsCard+ * - i18n parity for the 5 new keys+ *+ * Pattern mirrors tests/unit/quota-groups-ui.test.ts (source-scan, Node native runner).+ */++import test from "node:test";+import assert from "node:assert/strict";+import { readFileSync } from "node:fs";+import { join, dirname } from "node:path";+import { fileURLToPath } from "node:url";++const ROOT = join(dirname(fileURLToPath(import.meta.url)), "..", "..");++const CARD_PATH = join(+ ROOT,+ "src/app/(dashboard)/dashboard/costs/quota-share/components/QuotaEndpointsCard.tsx"+);++const PAGE_CLIENT_PATH = join(+ ROOT,+ "src/app/(dashboard)/dashboard/costs/quota-share/QuotaSharePageClient.tsx"+);++const EN_PATH = join(ROOT, "src/i18n/messages/en.json");+const PT_PATH = join(ROOT, "src/i18n/messages/pt-BR.json");++const cardSrc = readFileSync(CARD_PATH, "utf8");+const pageSrc = readFileSync(PAGE_CLIENT_PATH, "utf8");++// ── QuotaEndpointsCard: base URL ───────────────────────────────────────────────++test("QuotaEndpointsCard: renders /v1/chat/completions base URL", () => {+ assert.ok(+ cardSrc.includes("/v1/chat/completions"),+ "QuotaEndpointsCard must render the /v1/chat/completions endpoint"+ );+});++// ── QuotaEndpointsCard: builds qtSd/ model ids ────────────────────────────────++test("QuotaEndpointsCard: references quotaModelName or qtSd/ prefix", () => {+ const refsModelName = cardSrc.includes("quotaModelName");+ const refsQtSd = cardSrc.includes("qtSd/") || cardSrc.includes("qtSd");+ assert.ok(+ refsModelName || refsQtSd,+ "QuotaEndpointsCard must reference quotaModelName or the qtSd/ model prefix"+ );+});++// ── QuotaEndpointsCard: key selector ──────────────────────────────────────────++test("QuotaEndpointsCard: has a <select> for API key preview", () => {+ assert.ok(+ cardSrc.includes("<select"),+ "QuotaEndpointsCard must render a <select> for API key selection"+ );+});++test("QuotaEndpointsCard: has a previewKeyNone leading option", () => {+ assert.ok(+ cardSrc.includes('previewKeyNone') || cardSrc.includes("previewKeyNone"),+ "QuotaEndpointsCard must use the t('previewKeyNone') i18n key for the empty/all option"+ );+});++test("QuotaEndpointsCard: has a leading option with value=\"\" for no-key selection", () => {+ // The leading option must have value="" so that on reset it reverts to all-endpoints view+ assert.ok(+ cardSrc.includes('value=""') || cardSrc.includes("value=''"),+ "QuotaEndpointsCard must have a leading <option value=\"\"> for (all endpoints)"+ );+});++// ── QuotaEndpointsCard: per-key fetch ─────────────────────────────────────────++test("QuotaEndpointsCard: fetches /api/quota/keys/ + /models for key preview", () => {+ assert.ok(+ cardSrc.includes("/api/quota/keys/"),+ "QuotaEndpointsCard must fetch /api/quota/keys/..."+ );+ assert.ok(+ cardSrc.includes("/models"),+ "QuotaEndpointsCard must include /models in the fetch URL"+ );+});++// ── QuotaSharePageClient: imports + renders QuotaEndpointsCard ─────────────────++test("QuotaSharePageClient: imports QuotaEndpointsCard", () => {+ assert.ok(+ pageSrc.includes("QuotaEndpointsCard"),+ "QuotaSharePageClient must import QuotaEndpointsCard"+ );+});++test("QuotaSharePageClient: renders <QuotaEndpointsCard", () => {+ assert.ok(+ pageSrc.includes("<QuotaEndpointsCard"),+ "QuotaSharePageClient must render <QuotaEndpointsCard ..."+ );+});++test("QuotaSharePageClient: passes groups, pools, connections, apiKeys to QuotaEndpointsCard", () => {+ const cardIdx = pageSrc.indexOf("<QuotaEndpointsCard");+ assert.ok(cardIdx >= 0, "<QuotaEndpointsCard must exist in the source");+ // Find the closing tag (allow JSX self-close or regular close)+ const closeIdx = pageSrc.indexOf("/>", cardIdx);+ const block = pageSrc.slice(cardIdx, closeIdx + 2);+ assert.ok(block.includes("groups="), "QuotaEndpointsCard must receive groups prop");+ assert.ok(block.includes("pools="), "QuotaEndpointsCard must receive pools prop");+ assert.ok(block.includes("connections="), "QuotaEndpointsCard must receive connections prop");+ assert.ok(block.includes("apiKeys="), "QuotaEndpointsCard must receive apiKeys prop");+});++// ── i18n parity ───────────────────────────────────────────────────────────────++const ENDPOINTS_KEYS = [+ "endpointsTitle",+ "endpointsHint",+ "previewForKey",+ "previewKeyNone",+ "endpointsBaseUrl",+] as const;++test("i18n: all 5 endpoint keys present in en.json quotaShare namespace", () => {+ const en = JSON.parse(readFileSync(EN_PATH, "utf8")) as Record<string, Record<string, string>>;+ for (const k of ENDPOINTS_KEYS) {+ assert.equal(+ typeof en["quotaShare"]?.[k],+ "string",+ `en.json missing quotaShare.${k}`+ );+ }+});++test("i18n: all 5 endpoint keys present in pt-BR.json quotaShare namespace", () => {+ const pt = JSON.parse(readFileSync(PT_PATH, "utf8")) as Record<string, Record<string, string>>;+ for (const k of ENDPOINTS_KEYS) {+ assert.equal(+ typeof pt["quotaShare"]?.[k],+ "string",+ `pt-BR.json missing quotaShare.${k}`+ );+ }+});++test("i18n: full parity — en and pt-BR both have all 5 endpoint keys", () => {+ const en = JSON.parse(readFileSync(EN_PATH, "utf8")) as Record<string, Record<string, string>>;+ const pt = JSON.parse(readFileSync(PT_PATH, "utf8")) as Record<string, Record<string, string>>;+ for (const k of ENDPOINTS_KEYS) {+ assert.ok(k in (en["quotaShare"] ?? {}), `en.json missing quotaShare.${k}`);+ assert.ok(k in (pt["quotaShare"] ?? {}), `pt-BR.json missing quotaShare.${k}`);+ }+});