mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-11-18 07:58:27 +00:00
refactor(dashboard): lote 6 — loggers, flow-routing, logs/activity/audit/costs/quota/limits/models/context/compression/translator on the CI UI Kit (KEA-7886) (#17882)
refactor(dashboard): lote 6 — loggers, flow-routing, logs/activity/audit/costs/quota/limits/models/context/compression/translator on the CI UI Kit (KEA-7886)
This commit is contained in:
@@ -2,6 +2,12 @@
|
||||
|
||||
import { useState, useEffect, useCallback } from "react";
|
||||
import { useTranslations } from "next-intl";
|
||||
import { Alert } from "@omniroute/ui-kit/alert";
|
||||
import { PageHeader } from "@omniroute/ui-kit/page-header";
|
||||
import Button from "@/shared/components/Button";
|
||||
import Card from "@/shared/components/Card";
|
||||
import Icon from "@/shared/components/Icon";
|
||||
import { Skeleton } from "@/shared/components/Loading";
|
||||
import type { AuditLogEntry } from "@/lib/compliance/index";
|
||||
import ActivityFeed from "./components/ActivityFeed";
|
||||
import EventTypeFilter, { type EventCategory, matchesCategory } from "./components/EventTypeFilter";
|
||||
@@ -58,69 +64,50 @@ export default function ActivityFeedClient() {
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
{/* Header */}
|
||||
<div className="flex items-start justify-between gap-4 flex-wrap">
|
||||
<div>
|
||||
<h1 className="text-xl font-bold text-[var(--color-text-main)]">{t("title")}</h1>
|
||||
<p className="text-sm text-[var(--color-text-muted)] mt-1">{t("description")}</p>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => fetchEntries()}
|
||||
disabled={loading}
|
||||
className="px-4 py-2 rounded-lg text-sm font-medium bg-[var(--color-surface)] border border-[var(--color-border)] text-[var(--color-text-main)] hover:bg-[var(--color-bg-alt)] transition-colors disabled:opacity-50"
|
||||
aria-label={t("refreshAria")}
|
||||
>
|
||||
{loading ? (
|
||||
<span className="flex items-center gap-2">
|
||||
<span
|
||||
className="material-symbols-outlined text-[16px] animate-spin"
|
||||
aria-hidden="true"
|
||||
>
|
||||
progress_activity
|
||||
</span>
|
||||
{t("loading")}
|
||||
</span>
|
||||
) : (
|
||||
<span className="flex items-center gap-2">
|
||||
<span className="material-symbols-outlined text-[16px]" aria-hidden="true">
|
||||
refresh
|
||||
</span>
|
||||
{t("refresh")}
|
||||
</span>
|
||||
)}
|
||||
</button>
|
||||
</div>
|
||||
<PageHeader
|
||||
compact
|
||||
title={t("title")}
|
||||
description={t("description")}
|
||||
actions={
|
||||
<Button
|
||||
variant="outline"
|
||||
icon="refresh"
|
||||
loading={loading}
|
||||
onClick={() => fetchEntries()}
|
||||
aria-label={t("refreshAria")}
|
||||
>
|
||||
{loading ? t("loading") : t("refresh")}
|
||||
</Button>
|
||||
}
|
||||
/>
|
||||
|
||||
{/* Filter */}
|
||||
<EventTypeFilter value={category} onChange={setCategory} />
|
||||
|
||||
{/* Error */}
|
||||
{error && (
|
||||
<div
|
||||
className="p-4 rounded-lg bg-red-500/10 border border-red-500/30 text-red-400 text-sm"
|
||||
role="alert"
|
||||
>
|
||||
{error}
|
||||
</div>
|
||||
<Alert
|
||||
variant="critical"
|
||||
icon={<Icon name="error" size={16} />}
|
||||
dismissLabel={t("dismissError")}
|
||||
onDismiss={() => setError(null)}
|
||||
description={error}
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* Feed */}
|
||||
<div className="rounded-xl border border-[var(--color-border)] overflow-hidden bg-[var(--color-surface)]">
|
||||
<Card padding="none" className="overflow-hidden">
|
||||
{loading ? (
|
||||
<div className="flex items-center justify-center py-20 text-[var(--color-text-muted)]">
|
||||
<span
|
||||
className="material-symbols-outlined text-[32px] animate-spin mr-3"
|
||||
aria-hidden="true"
|
||||
>
|
||||
progress_activity
|
||||
</span>
|
||||
<span className="text-sm">{t("loadingActivity")}</span>
|
||||
<div className="flex flex-col gap-3 p-4" aria-busy="true">
|
||||
<span className="ci-sr-only">{t("loadingActivity")}</span>
|
||||
{Array.from({ length: 5 }, (_, i) => (
|
||||
<Skeleton key={i} className="h-10 w-full" />
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
<ActivityFeed entries={filtered} referenceNowMs={referenceNowMs} />
|
||||
)}
|
||||
</div>
|
||||
</Card>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
"use client";
|
||||
|
||||
import { useTranslations } from "next-intl";
|
||||
import EmptyState from "@/shared/components/EmptyState";
|
||||
import { groupByDay } from "@/lib/audit/timeline";
|
||||
import type { AuditLogEntry } from "@/lib/compliance/index";
|
||||
import DayHeader from "./DayHeader";
|
||||
@@ -16,18 +17,13 @@ export default function ActivityFeed({ entries, referenceNowMs }: ActivityFeedPr
|
||||
|
||||
if (!entries.length) {
|
||||
return (
|
||||
<div
|
||||
className="flex flex-col items-center justify-center py-20 text-center"
|
||||
role="status"
|
||||
aria-live="polite"
|
||||
>
|
||||
<span className="material-symbols-outlined text-[48px] text-[var(--color-text-muted)] mb-4" aria-hidden="true">
|
||||
timeline
|
||||
</span>
|
||||
<h3 className="text-base font-semibold text-[var(--color-text-main)] mb-1">
|
||||
{t("emptyTitle")}
|
||||
</h3>
|
||||
<p className="text-sm text-[var(--color-text-muted)] max-w-sm">{t("emptyDescription")}</p>
|
||||
<div role="status" aria-live="polite" data-testid="activity-empty-state">
|
||||
<EmptyState
|
||||
icon="timeline"
|
||||
title={t("emptyTitle")}
|
||||
description={t("emptyDescription")}
|
||||
className="border-0"
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -35,11 +31,11 @@ export default function ActivityFeed({ entries, referenceNowMs }: ActivityFeedPr
|
||||
const groups = groupByDay(entries, referenceNowMs);
|
||||
|
||||
return (
|
||||
<div className="divide-y divide-[var(--color-border)]">
|
||||
<div className="divide-y divide-border" data-testid="activity-feed">
|
||||
{groups.map((group) => (
|
||||
<section key={group.dayKey} aria-label={group.label}>
|
||||
<DayHeader label={group.label} dayKey={group.dayKey} />
|
||||
<ul className="divide-y divide-[var(--color-border)]">
|
||||
<ul className="divide-y divide-border">
|
||||
{group.entries.map((entry, idx) => (
|
||||
<ActivityItem
|
||||
key={typeof entry.id === "number" ? entry.id : `${group.dayKey}-${idx}`}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
"use client";
|
||||
|
||||
import { useTranslations, useLocale } from "next-intl";
|
||||
import Icon from "@/shared/components/Icon";
|
||||
import { getActivityIcon } from "@/lib/audit/activityIcons";
|
||||
import { relativeTime } from "@/lib/audit/timeline";
|
||||
import type { AuditLogEntry } from "@/lib/compliance/index";
|
||||
@@ -33,24 +34,17 @@ export default function ActivityItem({ entry, referenceNowMs }: ActivityItemProp
|
||||
}
|
||||
|
||||
return (
|
||||
<li className="flex items-start gap-3 px-4 py-3 hover:bg-[var(--color-bg-alt)] transition-colors">
|
||||
<span
|
||||
className="material-symbols-outlined flex-shrink-0 mt-0.5 text-[20px] text-[var(--color-accent)]"
|
||||
aria-hidden="true"
|
||||
>
|
||||
{icon}
|
||||
</span>
|
||||
<li className="flex items-start gap-3 px-4 py-3 hover:bg-bg-subtle transition-colors">
|
||||
<Icon name={icon} size={20} className="flex-shrink-0 mt-0.5 text-primary" />
|
||||
<div className="flex-1 min-w-0">
|
||||
<p className="text-sm text-[var(--color-text-main)] truncate" title={phrase}>
|
||||
<p className="text-sm text-text-main truncate" title={phrase}>
|
||||
{phrase}
|
||||
</p>
|
||||
{target && (
|
||||
<p className="text-xs text-[var(--color-text-muted)] truncate mt-0.5">{target}</p>
|
||||
)}
|
||||
{target && <p className="text-xs text-text-muted truncate mt-0.5">{target}</p>}
|
||||
</div>
|
||||
<time
|
||||
dateTime={timestamp}
|
||||
className="flex-shrink-0 text-xs text-[var(--color-text-muted)] whitespace-nowrap mt-0.5"
|
||||
className="flex-shrink-0 text-xs text-text-muted whitespace-nowrap mt-0.5"
|
||||
title={timestamp}
|
||||
>
|
||||
{timeAgo}
|
||||
|
||||
@@ -11,24 +11,20 @@ export default function DayHeader({ label, dayKey }: DayHeaderProps) {
|
||||
const t = useTranslations("activity");
|
||||
|
||||
const displayLabel =
|
||||
label === "today"
|
||||
? t("todayHeader")
|
||||
: label === "yesterday"
|
||||
? t("yesterdayHeader")
|
||||
: label;
|
||||
label === "today" ? t("todayHeader") : label === "yesterday" ? t("yesterdayHeader") : label;
|
||||
|
||||
return (
|
||||
<div
|
||||
className="sticky top-0 z-10 flex items-center gap-3 py-2 px-4 bg-[var(--color-bg)] border-b border-[var(--color-border)]"
|
||||
className="sticky top-0 z-10 flex items-center gap-3 py-2 px-4 bg-surface-2 border-b border-border"
|
||||
aria-label={displayLabel}
|
||||
>
|
||||
<span className="text-xs font-semibold uppercase tracking-widest text-[var(--color-text-muted)]">
|
||||
<span className="text-xs font-semibold uppercase tracking-widest text-text-muted">
|
||||
{displayLabel}
|
||||
</span>
|
||||
{label !== "today" && label !== "yesterday" && (
|
||||
<span className="text-xs text-[var(--color-text-muted)] opacity-60">{dayKey}</span>
|
||||
<span className="text-xs text-text-muted opacity-60">{dayKey}</span>
|
||||
)}
|
||||
<div className="flex-1 h-px bg-[var(--color-border)]" />
|
||||
<div className="flex-1 h-px bg-border" />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
"use client";
|
||||
|
||||
import { useTranslations } from "next-intl";
|
||||
import FilterPills from "@/shared/components/FilterPills";
|
||||
|
||||
export type EventCategory =
|
||||
"all" | "providers" | "combos" | "apikeys" | "settings" | "quota" | "auth" | "system";
|
||||
@@ -53,23 +54,11 @@ export default function EventTypeFilter({ value, onChange }: EventTypeFilterProp
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="flex flex-wrap gap-2" role="group" aria-label={t("filterAria")}>
|
||||
{CATEGORIES.map((cat) => (
|
||||
<button
|
||||
key={cat}
|
||||
type="button"
|
||||
onClick={() => onChange(cat)}
|
||||
aria-pressed={value === cat}
|
||||
className={[
|
||||
"px-3 py-1 rounded-full text-xs font-medium border transition-colors",
|
||||
value === cat
|
||||
? "bg-[var(--color-accent)] text-white border-[var(--color-accent)]"
|
||||
: "bg-[var(--color-surface)] text-[var(--color-text-muted)] border-[var(--color-border)] hover:bg-[var(--color-bg-alt)]",
|
||||
].join(" ")}
|
||||
>
|
||||
{t(labelKey[cat])}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
<FilterPills
|
||||
aria-label={t("filterAria")}
|
||||
options={CATEGORIES.map((cat) => ({ value: cat, label: t(labelKey[cat]) }))}
|
||||
value={value}
|
||||
onChange={(next) => onChange(next as EventCategory)}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,18 @@
|
||||
|
||||
import { useCallback, useEffect, useState } from "react";
|
||||
import { useTranslations } from "next-intl";
|
||||
import { Card } from "@/shared/components";
|
||||
import { DataTableFooter, DataTableShell } from "@omniroute/ui-kit/data-table-shell";
|
||||
import { PageHeader } from "@omniroute/ui-kit/page-header";
|
||||
import {
|
||||
Table,
|
||||
TableBody,
|
||||
TableCell,
|
||||
TableHead,
|
||||
TableHeader,
|
||||
TableRow,
|
||||
} from "@omniroute/ui-kit/table";
|
||||
import { TableLoadingState } from "@omniroute/ui-kit/table-loading";
|
||||
import { Badge, Button, EmptyState, Input, Select } from "@/shared/components";
|
||||
import type { A2ATask, TaskState } from "@/lib/a2a/taskManager";
|
||||
|
||||
type TaskListResponse = {
|
||||
@@ -14,12 +25,12 @@ type TaskListResponse = {
|
||||
|
||||
const A2A_PAGE_SIZE = 25;
|
||||
|
||||
const STATE_STYLES: Record<TaskState, string> = {
|
||||
submitted: "border-amber-500/30 bg-amber-500/10 text-amber-600",
|
||||
working: "border-blue-500/30 bg-blue-500/10 text-blue-600",
|
||||
completed: "border-emerald-500/30 bg-emerald-500/10 text-emerald-600",
|
||||
failed: "border-red-500/30 bg-red-500/10 text-red-600",
|
||||
cancelled: "border-border bg-sidebar/40 text-text-muted",
|
||||
const STATE_TONES: Record<TaskState, "warning" | "info" | "success" | "error" | "default"> = {
|
||||
submitted: "warning",
|
||||
working: "info",
|
||||
completed: "success",
|
||||
failed: "error",
|
||||
cancelled: "default",
|
||||
};
|
||||
|
||||
function taskDuration(task: A2ATask): string {
|
||||
@@ -71,57 +82,46 @@ export default function A2aAuditTab() {
|
||||
|
||||
return (
|
||||
<div className="space-y-5">
|
||||
<Card className="p-5">
|
||||
<div className="flex flex-col gap-4 lg:flex-row lg:items-start lg:justify-between">
|
||||
<div>
|
||||
<h2 className="text-xl font-semibold text-text-main">{t("a2aAudit")}</h2>
|
||||
<p className="mt-1 text-sm text-text-muted">{t("a2aAuditDesc")}</p>
|
||||
<p className="mt-2 text-xs text-text-muted">
|
||||
{t("a2aShowingTasks", { count: data.tasks.length, total: data.total })}
|
||||
</p>
|
||||
</div>
|
||||
<button
|
||||
<PageHeader
|
||||
compact
|
||||
title={t("a2aAudit")}
|
||||
description={t("a2aAuditDesc")}
|
||||
actions={
|
||||
<Button
|
||||
variant="outline"
|
||||
icon="refresh"
|
||||
loading={loading}
|
||||
onClick={() => void fetchTasks()}
|
||||
disabled={loading}
|
||||
className="inline-flex items-center gap-2 rounded-lg border border-border px-3 py-2 text-sm font-medium text-text-main transition-colors hover:bg-sidebar disabled:opacity-40"
|
||||
>
|
||||
<span
|
||||
className={`material-symbols-outlined text-[16px] ${loading ? "animate-spin" : ""}`}
|
||||
>
|
||||
refresh
|
||||
</span>
|
||||
{t("refresh")}
|
||||
</button>
|
||||
</div>
|
||||
</Card>
|
||||
</Button>
|
||||
}
|
||||
/>
|
||||
|
||||
<Card className="p-4">
|
||||
<div className="grid gap-3 md:grid-cols-3">
|
||||
<label className="space-y-1">
|
||||
<span className="text-xs font-medium uppercase tracking-wider text-text-muted">
|
||||
{t("a2aSkill")}
|
||||
</span>
|
||||
<input
|
||||
<DataTableShell
|
||||
filterAlignment="end"
|
||||
resultCount={data.total}
|
||||
resultLabel={() => t("a2aShowingTasks", { count: data.tasks.length, total: data.total })}
|
||||
filters={
|
||||
<>
|
||||
<Input
|
||||
label={t("a2aSkill")}
|
||||
value={skillFilter}
|
||||
onChange={(e) => {
|
||||
setOffset(0);
|
||||
setSkillFilter(e.target.value);
|
||||
}}
|
||||
placeholder={t("a2aSkillPlaceholder")}
|
||||
className="w-full rounded-lg border border-border bg-surface px-3 py-2 text-sm text-text-main focus:outline-none focus:ring-2 focus:ring-primary/40"
|
||||
className="w-full sm:w-56"
|
||||
/>
|
||||
</label>
|
||||
<label className="space-y-1">
|
||||
<span className="text-xs font-medium uppercase tracking-wider text-text-muted">
|
||||
{t("a2aState")}
|
||||
</span>
|
||||
<select
|
||||
<Select
|
||||
label={t("a2aState")}
|
||||
value={stateFilter}
|
||||
onChange={(e) => {
|
||||
setOffset(0);
|
||||
setStateFilter(e.target.value as TaskState | "all");
|
||||
}}
|
||||
className="w-full rounded-lg border border-border bg-surface px-3 py-2 text-sm text-text-main focus:outline-none focus:ring-2 focus:ring-primary/40"
|
||||
className="w-full sm:w-44"
|
||||
>
|
||||
<option value="all">{t("a2aAllStates")}</option>
|
||||
<option value="submitted">{t("a2aStateSubmitted")}</option>
|
||||
@@ -129,91 +129,85 @@ export default function A2aAuditTab() {
|
||||
<option value="completed">{t("a2aStateCompleted")}</option>
|
||||
<option value="failed">{t("a2aStateFailed")}</option>
|
||||
<option value="cancelled">{t("a2aStateCancelled")}</option>
|
||||
</select>
|
||||
</label>
|
||||
<div className="flex items-end">
|
||||
<button
|
||||
</Select>
|
||||
<Button
|
||||
variant="ghost"
|
||||
onClick={() => {
|
||||
setSkillFilter("");
|
||||
setStateFilter("all");
|
||||
setOffset(0);
|
||||
}}
|
||||
className="w-full rounded-lg border border-border px-3 py-2 text-sm font-medium text-text-main transition-colors hover:bg-sidebar"
|
||||
>
|
||||
{t("clearFilters")}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</Card>
|
||||
|
||||
<Card className="overflow-hidden">
|
||||
</Button>
|
||||
</>
|
||||
}
|
||||
pagination={
|
||||
<DataTableFooter
|
||||
pagination={
|
||||
<div className="flex items-center gap-2">
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => setOffset((c) => Math.max(0, c - A2A_PAGE_SIZE))}
|
||||
disabled={offset === 0 || loading}
|
||||
>
|
||||
{t("previous")}
|
||||
</Button>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => setOffset((c) => c + A2A_PAGE_SIZE)}
|
||||
disabled={offset + A2A_PAGE_SIZE >= data.total || loading}
|
||||
>
|
||||
{t("next")}
|
||||
</Button>
|
||||
</div>
|
||||
}
|
||||
/>
|
||||
}
|
||||
>
|
||||
{loading ? (
|
||||
<div className="p-8 text-center text-sm text-text-muted">{t("a2aLoadingTasks")}</div>
|
||||
<TableLoadingState label={t("a2aLoadingTasks")} />
|
||||
) : data.tasks.length === 0 ? (
|
||||
<div className="p-10 text-center">
|
||||
<span className="material-symbols-outlined text-[40px] text-text-muted">
|
||||
device_hub
|
||||
</span>
|
||||
<p className="mt-3 text-sm text-text-muted">{t("a2aNoTasks")}</p>
|
||||
</div>
|
||||
<EmptyState icon="device_hub" title={t("a2aNoTasks")} />
|
||||
) : (
|
||||
<div className="overflow-x-auto">
|
||||
<table className="w-full min-w-[760px] text-left text-sm">
|
||||
<thead className="border-b border-border bg-sidebar/40 text-xs uppercase tracking-wider text-text-muted">
|
||||
<tr>
|
||||
<th className="px-4 py-3 font-medium">{t("timestamp")}</th>
|
||||
<th className="px-4 py-3 font-medium">{t("a2aTaskId")}</th>
|
||||
<th className="px-4 py-3 font-medium">{t("a2aSkill")}</th>
|
||||
<th className="px-4 py-3 font-medium">{t("a2aState")}</th>
|
||||
<th className="px-4 py-3 font-medium">{t("duration")}</th>
|
||||
<th className="px-4 py-3 font-medium">{t("a2aEvents")}</th>
|
||||
<th className="px-4 py-3 font-medium">{t("a2aArtifacts")}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody className="divide-y divide-border">
|
||||
{data.tasks.map((task) => (
|
||||
<tr key={task.id} className="transition-colors hover:bg-sidebar/30">
|
||||
<td className="whitespace-nowrap px-4 py-3 font-mono text-xs text-text-muted">
|
||||
{new Date(task.createdAt).toLocaleString()}
|
||||
</td>
|
||||
<td className="px-4 py-3 font-mono text-xs text-text-muted">
|
||||
{task.id.slice(0, 8)}…
|
||||
</td>
|
||||
<td className="px-4 py-3 font-mono text-xs text-text-main">{task.skill}</td>
|
||||
<td className="px-4 py-3">
|
||||
<span
|
||||
className={`rounded-full border px-2 py-1 text-xs font-medium ${STATE_STYLES[task.state]}`}
|
||||
>
|
||||
{t(`a2aState${task.state.charAt(0).toUpperCase()}${task.state.slice(1)}`)}
|
||||
</span>
|
||||
</td>
|
||||
<td className="px-4 py-3 text-text-muted">{taskDuration(task)}</td>
|
||||
<td className="px-4 py-3 text-text-muted">{task.events.length}</td>
|
||||
<td className="px-4 py-3 text-text-muted">{task.artifacts.length}</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<Table scrollbarLabel={t("a2aAudit")} className="min-w-[760px] text-left">
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead>{t("timestamp")}</TableHead>
|
||||
<TableHead>{t("a2aTaskId")}</TableHead>
|
||||
<TableHead>{t("a2aSkill")}</TableHead>
|
||||
<TableHead>{t("a2aState")}</TableHead>
|
||||
<TableHead>{t("duration")}</TableHead>
|
||||
<TableHead>{t("a2aEvents")}</TableHead>
|
||||
<TableHead>{t("a2aArtifacts")}</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{data.tasks.map((task) => (
|
||||
<TableRow key={task.id}>
|
||||
<TableCell className="font-mono text-xs text-text-muted">
|
||||
{new Date(task.createdAt).toLocaleString()}
|
||||
</TableCell>
|
||||
<TableCell className="font-mono text-xs text-text-muted">
|
||||
{task.id.slice(0, 8)}…
|
||||
</TableCell>
|
||||
<TableCell className="font-mono text-xs text-text-main">{task.skill}</TableCell>
|
||||
<TableCell>
|
||||
<Badge size="sm" variant={STATE_TONES[task.state]}>
|
||||
{t(`a2aState${task.state.charAt(0).toUpperCase()}${task.state.slice(1)}`)}
|
||||
</Badge>
|
||||
</TableCell>
|
||||
<TableCell className="text-text-muted">{taskDuration(task)}</TableCell>
|
||||
<TableCell className="text-text-muted">{task.events.length}</TableCell>
|
||||
<TableCell className="text-text-muted">{task.artifacts.length}</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
</TableBody>
|
||||
</Table>
|
||||
)}
|
||||
</Card>
|
||||
|
||||
<div className="flex items-center justify-end gap-2">
|
||||
<button
|
||||
onClick={() => setOffset((c) => Math.max(0, c - A2A_PAGE_SIZE))}
|
||||
disabled={offset === 0 || loading}
|
||||
className="rounded-lg border border-border px-3 py-2 text-sm font-medium text-text-main transition-colors hover:bg-sidebar disabled:opacity-40"
|
||||
>
|
||||
{t("previous")}
|
||||
</button>
|
||||
<button
|
||||
onClick={() => setOffset((c) => c + A2A_PAGE_SIZE)}
|
||||
disabled={offset + A2A_PAGE_SIZE >= data.total || loading}
|
||||
className="rounded-lg border border-border px-3 py-2 text-sm font-medium text-text-main transition-colors hover:bg-sidebar disabled:opacity-40"
|
||||
>
|
||||
{t("next")}
|
||||
</button>
|
||||
</div>
|
||||
</DataTableShell>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,28 @@
|
||||
|
||||
import { useCallback, useEffect, useMemo, useState } from "react";
|
||||
import { useTranslations } from "next-intl";
|
||||
import { Card } from "@/shared/components";
|
||||
import { Alert } from "@omniroute/ui-kit/alert";
|
||||
import { DataTableFooter, DataTableShell } from "@omniroute/ui-kit/data-table-shell";
|
||||
import { PageHeader } from "@omniroute/ui-kit/page-header";
|
||||
import {
|
||||
Sheet,
|
||||
SheetBody,
|
||||
SheetContent,
|
||||
SheetDescription,
|
||||
SheetHeader,
|
||||
SheetTitle,
|
||||
} from "@omniroute/ui-kit/sheet";
|
||||
import {
|
||||
Table,
|
||||
TableBody,
|
||||
TableCell,
|
||||
TableHead,
|
||||
TableHeader,
|
||||
TableRow,
|
||||
} from "@omniroute/ui-kit/table";
|
||||
import { TableLoadingState } from "@omniroute/ui-kit/table-loading";
|
||||
import { Badge, Button, EmptyState, Input, Select } from "@/shared/components";
|
||||
import Icon from "@/shared/components/Icon";
|
||||
|
||||
type AuditEntry = {
|
||||
id: number;
|
||||
@@ -152,265 +173,248 @@ export default function ComplianceTab() {
|
||||
URL.revokeObjectURL(url);
|
||||
};
|
||||
|
||||
const severityClass = (value: Severity) => {
|
||||
if (value === "critical") return "border-red-500/30 bg-red-500/10 text-red-600";
|
||||
if (value === "warning") return "border-amber-500/30 bg-amber-500/10 text-amber-600";
|
||||
return "border-blue-500/30 bg-blue-500/10 text-blue-600";
|
||||
const severityTone = (value: Severity) => {
|
||||
if (value === "critical") return "error" as const;
|
||||
if (value === "warning") return "warning" as const;
|
||||
return "info" as const;
|
||||
};
|
||||
|
||||
const pageButtons = (
|
||||
<div className="flex items-center gap-2">
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => setOffset((current) => Math.max(0, current - PAGE_SIZE))}
|
||||
disabled={offset === 0 || loading}
|
||||
>
|
||||
{t("previous")}
|
||||
</Button>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => setOffset((current) => current + PAGE_SIZE)}
|
||||
disabled={!canGoNext || loading}
|
||||
>
|
||||
{t("next")}
|
||||
</Button>
|
||||
</div>
|
||||
);
|
||||
|
||||
return (
|
||||
<div className="space-y-5">
|
||||
<Card className="p-5">
|
||||
<div className="flex flex-col gap-4 lg:flex-row lg:items-start lg:justify-between">
|
||||
<div>
|
||||
<h2 className="text-xl font-semibold text-text-main">{t("title")}</h2>
|
||||
<p className="mt-1 text-sm text-text-muted">{t("description")}</p>
|
||||
<p className="mt-2 text-xs text-text-muted">
|
||||
{t("showing", { count: visibleEntries.length, total: totalCount })}
|
||||
</p>
|
||||
</div>
|
||||
<PageHeader
|
||||
compact
|
||||
title={t("title")}
|
||||
description={t("description")}
|
||||
actions={
|
||||
<div className="flex flex-wrap gap-2">
|
||||
<button
|
||||
<Button
|
||||
variant="outline"
|
||||
icon="refresh"
|
||||
loading={loading}
|
||||
onClick={() => void fetchEntries()}
|
||||
disabled={loading}
|
||||
className="inline-flex items-center gap-2 rounded-lg border border-border px-3 py-2 text-sm font-medium text-text-main transition-colors hover:bg-sidebar disabled:opacity-40"
|
||||
>
|
||||
<span
|
||||
className={`material-symbols-outlined text-[16px] ${loading ? "animate-spin" : ""}`}
|
||||
>
|
||||
refresh
|
||||
</span>
|
||||
{t("refresh")}
|
||||
</button>
|
||||
<button
|
||||
</Button>
|
||||
<Button
|
||||
variant="outline"
|
||||
icon="download"
|
||||
onClick={exportVisibleEntries}
|
||||
disabled={visibleEntries.length === 0}
|
||||
className="inline-flex items-center gap-2 rounded-lg bg-primary px-3 py-2 text-sm font-medium text-accent-foreground transition-colors hover:bg-primary/90 disabled:opacity-40"
|
||||
>
|
||||
<span className="material-symbols-outlined text-[16px]">download</span>
|
||||
{t("export")}
|
||||
</button>
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</Card>
|
||||
}
|
||||
/>
|
||||
|
||||
<Card className="p-4">
|
||||
<div className="grid gap-3 md:grid-cols-2 xl:grid-cols-6">
|
||||
<label className="space-y-1">
|
||||
<span className="text-xs font-medium uppercase tracking-wider text-text-muted">
|
||||
{t("eventType")}
|
||||
</span>
|
||||
<input
|
||||
list="compliance-event-types"
|
||||
value={eventType}
|
||||
onChange={(event) => {
|
||||
setOffset(0);
|
||||
setEventType(event.target.value);
|
||||
}}
|
||||
placeholder={t("eventTypePlaceholder")}
|
||||
className="w-full rounded-lg border border-border bg-surface px-3 py-2 text-sm text-text-main focus:outline-none focus:ring-2 focus:ring-primary/40"
|
||||
/>
|
||||
<datalist id="compliance-event-types">
|
||||
{eventTypes.map((type) => (
|
||||
<option key={type} value={type} />
|
||||
))}
|
||||
</datalist>
|
||||
</label>
|
||||
<label className="space-y-1">
|
||||
<span className="text-xs font-medium uppercase tracking-wider text-text-muted">
|
||||
{t("actor")}
|
||||
</span>
|
||||
<input
|
||||
list="compliance-actors"
|
||||
value={actor}
|
||||
onChange={(event) => {
|
||||
setOffset(0);
|
||||
setActor(event.target.value);
|
||||
}}
|
||||
placeholder={t("actorPlaceholder")}
|
||||
className="w-full rounded-lg border border-border bg-surface px-3 py-2 text-sm text-text-main focus:outline-none focus:ring-2 focus:ring-primary/40"
|
||||
/>
|
||||
<datalist id="compliance-actors">
|
||||
{actors.map((a) => (
|
||||
<option key={a} value={a} />
|
||||
))}
|
||||
</datalist>
|
||||
</label>
|
||||
<label className="space-y-1">
|
||||
<span className="text-xs font-medium uppercase tracking-wider text-text-muted">
|
||||
{t("severity")}
|
||||
</span>
|
||||
<select
|
||||
{error && (
|
||||
<Alert
|
||||
variant="critical"
|
||||
icon={<Icon name="error" size={16} />}
|
||||
dismissLabel={t("dismissError")}
|
||||
onDismiss={() => setError(null)}
|
||||
description={error}
|
||||
/>
|
||||
)}
|
||||
|
||||
<DataTableShell
|
||||
filterAlignment="end"
|
||||
resultCount={totalCount}
|
||||
resultLabel={() => t("showing", { count: visibleEntries.length, total: totalCount })}
|
||||
filters={
|
||||
<>
|
||||
<div>
|
||||
<Input
|
||||
label={t("eventType")}
|
||||
list="compliance-event-types"
|
||||
value={eventType}
|
||||
onChange={(event) => {
|
||||
setOffset(0);
|
||||
setEventType(event.target.value);
|
||||
}}
|
||||
placeholder={t("eventTypePlaceholder")}
|
||||
className="w-full sm:w-48"
|
||||
/>
|
||||
<datalist id="compliance-event-types">
|
||||
{eventTypes.map((type) => (
|
||||
<option key={type} value={type} />
|
||||
))}
|
||||
</datalist>
|
||||
</div>
|
||||
<div>
|
||||
<Input
|
||||
label={t("actor")}
|
||||
list="compliance-actors"
|
||||
value={actor}
|
||||
onChange={(event) => {
|
||||
setOffset(0);
|
||||
setActor(event.target.value);
|
||||
}}
|
||||
placeholder={t("actorPlaceholder")}
|
||||
className="w-full sm:w-44"
|
||||
/>
|
||||
<datalist id="compliance-actors">
|
||||
{actors.map((a) => (
|
||||
<option key={a} value={a} />
|
||||
))}
|
||||
</datalist>
|
||||
</div>
|
||||
<Select
|
||||
label={t("severity")}
|
||||
value={severity}
|
||||
onChange={(event) => {
|
||||
setOffset(0);
|
||||
setSeverity(event.target.value as "all" | Severity);
|
||||
}}
|
||||
className="w-full rounded-lg border border-border bg-surface px-3 py-2 text-sm text-text-main focus:outline-none focus:ring-2 focus:ring-primary/40"
|
||||
className="w-full sm:w-40"
|
||||
>
|
||||
<option value="all">{t("allSeverities")}</option>
|
||||
<option value="info">{t("info")}</option>
|
||||
<option value="warning">{t("warning")}</option>
|
||||
<option value="critical">{t("critical")}</option>
|
||||
</select>
|
||||
</label>
|
||||
<label className="space-y-1">
|
||||
<span className="text-xs font-medium uppercase tracking-wider text-text-muted">
|
||||
{t("from")}
|
||||
</span>
|
||||
<input
|
||||
</Select>
|
||||
<Input
|
||||
type="datetime-local"
|
||||
label={t("from")}
|
||||
value={from}
|
||||
onChange={(event) => {
|
||||
setOffset(0);
|
||||
setFrom(event.target.value);
|
||||
}}
|
||||
className="w-full rounded-lg border border-border bg-surface px-3 py-2 text-sm text-text-main focus:outline-none focus:ring-2 focus:ring-primary/40"
|
||||
className="w-full sm:w-52"
|
||||
/>
|
||||
</label>
|
||||
<label className="space-y-1">
|
||||
<span className="text-xs font-medium uppercase tracking-wider text-text-muted">
|
||||
{t("to")}
|
||||
</span>
|
||||
<input
|
||||
<Input
|
||||
type="datetime-local"
|
||||
label={t("to")}
|
||||
value={to}
|
||||
onChange={(event) => {
|
||||
setOffset(0);
|
||||
setTo(event.target.value);
|
||||
}}
|
||||
className="w-full rounded-lg border border-border bg-surface px-3 py-2 text-sm text-text-main focus:outline-none focus:ring-2 focus:ring-primary/40"
|
||||
className="w-full sm:w-52"
|
||||
/>
|
||||
</label>
|
||||
<div className="flex items-end">
|
||||
<button
|
||||
onClick={resetFilters}
|
||||
className="w-full rounded-lg border border-border px-3 py-2 text-sm font-medium text-text-main transition-colors hover:bg-sidebar"
|
||||
>
|
||||
<Button variant="ghost" onClick={resetFilters}>
|
||||
{t("clearFilters")}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</Card>
|
||||
|
||||
{error && (
|
||||
<div className="rounded-lg border border-red-500/30 bg-red-500/10 px-4 py-3 text-sm text-red-600">
|
||||
{error}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<Card className="overflow-hidden">
|
||||
</Button>
|
||||
</>
|
||||
}
|
||||
pagination={<DataTableFooter pagination={pageButtons} />}
|
||||
>
|
||||
{loading ? (
|
||||
<div className="p-8 text-center text-sm text-text-muted">{t("loading")}</div>
|
||||
<TableLoadingState label={t("loading")} />
|
||||
) : visibleEntries.length === 0 ? (
|
||||
<div className="p-10 text-center">
|
||||
<span className="material-symbols-outlined text-[40px] text-text-muted">policy</span>
|
||||
<p className="mt-3 text-sm text-text-muted">{t("noEvents")}</p>
|
||||
</div>
|
||||
<EmptyState icon="policy" title={t("noEvents")} />
|
||||
) : (
|
||||
<div className="overflow-x-auto">
|
||||
<table className="w-full min-w-[1040px] text-left text-sm">
|
||||
<thead className="border-b border-border bg-sidebar/40 text-xs uppercase tracking-wider text-text-muted">
|
||||
<tr>
|
||||
<th className="px-4 py-3 font-medium">{t("timestamp")}</th>
|
||||
<th className="px-4 py-3 font-medium">{t("eventType")}</th>
|
||||
<th className="px-4 py-3 font-medium">{t("severity")}</th>
|
||||
<th className="px-4 py-3 font-medium">{t("sourceIp")}</th>
|
||||
<th className="px-4 py-3 font-medium">{t("userOrKey")}</th>
|
||||
<th className="px-4 py-3 font-medium">{t("action")}</th>
|
||||
<th className="px-4 py-3 font-medium">{t("result")}</th>
|
||||
<th className="px-4 py-3 text-right font-medium">{t("details")}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody className="divide-y divide-border">
|
||||
{visibleEntries.map((entry) => {
|
||||
const entrySeverity = getSeverity(entry);
|
||||
return (
|
||||
<tr key={entry.id} className="transition-colors hover:bg-sidebar/30">
|
||||
<td className="whitespace-nowrap px-4 py-3 font-mono text-xs text-text-muted">
|
||||
{formatLocalDate(entry.timestamp)}
|
||||
</td>
|
||||
<td className="px-4 py-3">
|
||||
<span className="rounded-md border border-border bg-surface px-2 py-1 font-mono text-xs text-text-main">
|
||||
{t.has(`eventTypes.${entry.action}`)
|
||||
? t(`eventTypes.${entry.action}`)
|
||||
: entry.action}
|
||||
</span>
|
||||
</td>
|
||||
<td className="px-4 py-3">
|
||||
<span
|
||||
className={`inline-flex rounded-full border px-2 py-1 text-xs font-medium ${severityClass(entrySeverity)}`}
|
||||
>
|
||||
{t(entrySeverity)}
|
||||
</span>
|
||||
</td>
|
||||
<td className="whitespace-nowrap px-4 py-3 font-mono text-xs text-text-muted">
|
||||
{entry.ip_address || entry.ip || t("notAvailable")}
|
||||
</td>
|
||||
<td className="px-4 py-3 text-text-main">{entry.actor || t("system")}</td>
|
||||
<td className="max-w-[220px] truncate px-4 py-3 text-text-muted">
|
||||
{entry.target || entry.resourceType || t("notAvailable")}
|
||||
</td>
|
||||
<td className="px-4 py-3 text-text-muted">
|
||||
{entry.status || t("notAvailable")}
|
||||
</td>
|
||||
<td className="px-4 py-3 text-right">
|
||||
<button
|
||||
onClick={() => setSelectedEntry(entry)}
|
||||
className="rounded-lg border border-border px-3 py-1.5 text-xs font-medium text-text-main transition-colors hover:bg-sidebar"
|
||||
>
|
||||
{t("viewDetails")}
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
);
|
||||
})}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<Table scrollbarLabel={t("title")} className="min-w-[1040px] text-left">
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead>{t("timestamp")}</TableHead>
|
||||
<TableHead>{t("eventType")}</TableHead>
|
||||
<TableHead>{t("severity")}</TableHead>
|
||||
<TableHead>{t("sourceIp")}</TableHead>
|
||||
<TableHead>{t("userOrKey")}</TableHead>
|
||||
<TableHead>{t("action")}</TableHead>
|
||||
<TableHead>{t("result")}</TableHead>
|
||||
<TableHead className="text-right">{t("details")}</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{visibleEntries.map((entry) => {
|
||||
const entrySeverity = getSeverity(entry);
|
||||
return (
|
||||
<TableRow key={entry.id}>
|
||||
<TableCell className="font-mono text-xs text-text-muted">
|
||||
{formatLocalDate(entry.timestamp)}
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<Badge size="sm" className="font-mono">
|
||||
{t.has(`eventTypes.${entry.action}`)
|
||||
? t(`eventTypes.${entry.action}`)
|
||||
: entry.action}
|
||||
</Badge>
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<Badge size="sm" variant={severityTone(entrySeverity)}>
|
||||
{t(entrySeverity)}
|
||||
</Badge>
|
||||
</TableCell>
|
||||
<TableCell className="font-mono text-xs text-text-muted">
|
||||
{entry.ip_address || entry.ip || t("notAvailable")}
|
||||
</TableCell>
|
||||
<TableCell className="text-text-main">{entry.actor || t("system")}</TableCell>
|
||||
<TableCell className="max-w-[220px] truncate text-text-muted">
|
||||
{entry.target || entry.resourceType || t("notAvailable")}
|
||||
</TableCell>
|
||||
<TableCell className="text-text-muted">
|
||||
{entry.status || t("notAvailable")}
|
||||
</TableCell>
|
||||
<TableCell className="text-right">
|
||||
<Button variant="outline" size="sm" onClick={() => setSelectedEntry(entry)}>
|
||||
{t("viewDetails")}
|
||||
</Button>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
);
|
||||
})}
|
||||
</TableBody>
|
||||
</Table>
|
||||
)}
|
||||
</Card>
|
||||
</DataTableShell>
|
||||
|
||||
<div className="flex items-center justify-end gap-2">
|
||||
<button
|
||||
onClick={() => setOffset((current) => Math.max(0, current - PAGE_SIZE))}
|
||||
disabled={offset === 0 || loading}
|
||||
className="rounded-lg border border-border px-3 py-2 text-sm font-medium text-text-main transition-colors hover:bg-sidebar disabled:opacity-40"
|
||||
>
|
||||
{t("previous")}
|
||||
</button>
|
||||
<button
|
||||
onClick={() => setOffset((current) => current + PAGE_SIZE)}
|
||||
disabled={!canGoNext || loading}
|
||||
className="rounded-lg border border-border px-3 py-2 text-sm font-medium text-text-main transition-colors hover:bg-sidebar disabled:opacity-40"
|
||||
>
|
||||
{t("next")}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{selectedEntry && (
|
||||
<div className="fixed inset-0 z-50 flex items-center justify-center p-4">
|
||||
<button
|
||||
aria-label={t("closeDetails")}
|
||||
className="absolute inset-0 bg-black/30 backdrop-blur-sm"
|
||||
onClick={() => setSelectedEntry(null)}
|
||||
/>
|
||||
<div className="relative w-full max-w-3xl rounded-xl border border-border bg-surface shadow-2xl">
|
||||
<div className="flex items-center justify-between border-b border-border p-4">
|
||||
<h3 className="text-lg font-semibold text-text-main">{t("details")}</h3>
|
||||
<button
|
||||
onClick={() => setSelectedEntry(null)}
|
||||
className="rounded-lg p-2 text-text-muted hover:bg-sidebar hover:text-text-main"
|
||||
>
|
||||
<span className="material-symbols-outlined text-[20px]">close</span>
|
||||
</button>
|
||||
<Sheet
|
||||
open={selectedEntry !== null}
|
||||
onOpenChange={(open) => {
|
||||
if (!open) setSelectedEntry(null);
|
||||
}}
|
||||
>
|
||||
{/* showClose={false}: the kit close button hard-codes an English label. */}
|
||||
<SheetContent side="right" showClose={false} className="w-full sm:max-w-2xl">
|
||||
<SheetHeader className="flex flex-row items-center justify-between gap-3">
|
||||
<div className="min-w-0">
|
||||
<SheetTitle>{t("details")}</SheetTitle>
|
||||
<SheetDescription>
|
||||
{selectedEntry
|
||||
? `${selectedEntry.action} · ${formatLocalDate(selectedEntry.timestamp)}`
|
||||
: ""}
|
||||
</SheetDescription>
|
||||
</div>
|
||||
<pre className="max-h-[70vh] overflow-auto p-4 text-xs text-text-main">
|
||||
{formatJson(selectedEntry)}
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon-sm"
|
||||
aria-label={t("closeDetails")}
|
||||
onClick={() => setSelectedEntry(null)}
|
||||
>
|
||||
<Icon name="close" size={18} />
|
||||
</Button>
|
||||
</SheetHeader>
|
||||
<SheetBody>
|
||||
<pre className="overflow-auto whitespace-pre-wrap break-words rounded-lg border border-border bg-bg-subtle p-4 font-mono text-xs text-text-main">
|
||||
{selectedEntry ? formatJson(selectedEntry) : ""}
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</SheetBody>
|
||||
</SheetContent>
|
||||
</Sheet>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,19 @@
|
||||
|
||||
import { useCallback, useEffect, useState } from "react";
|
||||
import { useTranslations } from "next-intl";
|
||||
import { Card } from "@/shared/components";
|
||||
import { DataTableFooter, DataTableShell } from "@omniroute/ui-kit/data-table-shell";
|
||||
import { PageHeader } from "@omniroute/ui-kit/page-header";
|
||||
import {
|
||||
Table,
|
||||
TableBody,
|
||||
TableCell,
|
||||
TableHead,
|
||||
TableHeader,
|
||||
TableRow,
|
||||
} from "@omniroute/ui-kit/table";
|
||||
import { TableLoadingState } from "@omniroute/ui-kit/table-loading";
|
||||
import { Badge, Button, Card, EmptyState, Input, Select } from "@/shared/components";
|
||||
import Icon from "@/shared/components/Icon";
|
||||
|
||||
type McpAuditEntry = {
|
||||
id: number;
|
||||
@@ -95,32 +107,24 @@ export default function McpAuditTab() {
|
||||
|
||||
return (
|
||||
<div className="space-y-5">
|
||||
<Card className="p-5">
|
||||
<div className="flex flex-col gap-4 lg:flex-row lg:items-start lg:justify-between">
|
||||
<div>
|
||||
<h2 className="text-xl font-semibold text-text-main">{t("mcpAudit")}</h2>
|
||||
<p className="mt-1 text-sm text-text-muted">{t("mcpAuditDesc")}</p>
|
||||
<p className="mt-2 text-xs text-text-muted">
|
||||
{t("showing", { count: data.entries.length, total: data.total })}
|
||||
</p>
|
||||
</div>
|
||||
<button
|
||||
<PageHeader
|
||||
compact
|
||||
title={t("mcpAudit")}
|
||||
description={t("mcpAuditDesc")}
|
||||
actions={
|
||||
<Button
|
||||
variant="outline"
|
||||
icon="refresh"
|
||||
loading={loading}
|
||||
onClick={() => {
|
||||
void fetchAudit();
|
||||
void fetchStats();
|
||||
}}
|
||||
disabled={loading}
|
||||
className="inline-flex items-center gap-2 rounded-lg border border-border px-3 py-2 text-sm font-medium text-text-main transition-colors hover:bg-sidebar disabled:opacity-40"
|
||||
>
|
||||
<span
|
||||
className={`material-symbols-outlined text-[16px] ${loading ? "animate-spin" : ""}`}
|
||||
>
|
||||
refresh
|
||||
</span>
|
||||
{t("refresh")}
|
||||
</button>
|
||||
</div>
|
||||
</Card>
|
||||
</Button>
|
||||
}
|
||||
/>
|
||||
|
||||
{stats && (
|
||||
<div className="grid grid-cols-2 gap-3 md:grid-cols-4">
|
||||
@@ -147,21 +151,19 @@ export default function McpAuditTab() {
|
||||
icon: "star",
|
||||
},
|
||||
].map((item) => (
|
||||
<Card key={item.label} className="px-4 py-3">
|
||||
<div className="flex items-center gap-2 mb-1">
|
||||
<span
|
||||
className="material-symbols-outlined text-[14px]"
|
||||
style={{ color: "var(--color-text-muted)" }}
|
||||
>
|
||||
{item.icon}
|
||||
</span>
|
||||
<span className="text-xs text-text-muted uppercase tracking-wider">
|
||||
<Card key={item.label} padding="none" className="px-4 py-3">
|
||||
<div className="mb-1 flex items-center gap-2">
|
||||
<Icon name={item.icon} size={14} className="text-text-muted" />
|
||||
<span className="text-xs uppercase tracking-wider text-text-muted">
|
||||
{item.label}
|
||||
</span>
|
||||
</div>
|
||||
<p
|
||||
className="text-lg font-semibold truncate"
|
||||
style={{ color: item.highlight ? "rgb(34,197,94)" : "var(--color-text)" }}
|
||||
className={
|
||||
item.highlight
|
||||
? "truncate text-lg font-semibold text-success"
|
||||
: "truncate text-lg font-semibold text-text-main"
|
||||
}
|
||||
>
|
||||
{item.value}
|
||||
</p>
|
||||
@@ -170,124 +172,115 @@ export default function McpAuditTab() {
|
||||
</div>
|
||||
)}
|
||||
|
||||
<Card className="p-4">
|
||||
<div className="grid gap-3 md:grid-cols-3">
|
||||
<label className="space-y-1">
|
||||
<span className="text-xs font-medium uppercase tracking-wider text-text-muted">
|
||||
{t("tool")}
|
||||
</span>
|
||||
<input
|
||||
<DataTableShell
|
||||
filterAlignment="end"
|
||||
resultCount={data.total}
|
||||
resultLabel={() => t("showing", { count: data.entries.length, total: data.total })}
|
||||
filters={
|
||||
<>
|
||||
<Input
|
||||
label={t("tool")}
|
||||
value={toolFilter}
|
||||
onChange={(event) => {
|
||||
setOffset(0);
|
||||
setToolFilter(event.target.value);
|
||||
}}
|
||||
placeholder={t("toolPlaceholder")}
|
||||
className="w-full rounded-lg border border-border bg-surface px-3 py-2 text-sm text-text-main focus:outline-none focus:ring-2 focus:ring-primary/40"
|
||||
className="w-full sm:w-56"
|
||||
/>
|
||||
</label>
|
||||
<label className="space-y-1">
|
||||
<span className="text-xs font-medium uppercase tracking-wider text-text-muted">
|
||||
{t("result")}
|
||||
</span>
|
||||
<select
|
||||
<Select
|
||||
label={t("result")}
|
||||
value={successFilter}
|
||||
onChange={(event) => {
|
||||
setOffset(0);
|
||||
setSuccessFilter(event.target.value as "all" | "true" | "false");
|
||||
}}
|
||||
className="w-full rounded-lg border border-border bg-surface px-3 py-2 text-sm text-text-main focus:outline-none focus:ring-2 focus:ring-primary/40"
|
||||
className="w-full sm:w-44"
|
||||
>
|
||||
<option value="all">{t("allResults")}</option>
|
||||
<option value="true">{t("success")}</option>
|
||||
<option value="false">{t("failure")}</option>
|
||||
</select>
|
||||
</label>
|
||||
<div className="flex items-end">
|
||||
<button
|
||||
</Select>
|
||||
<Button
|
||||
variant="ghost"
|
||||
onClick={() => {
|
||||
setToolFilter("");
|
||||
setSuccessFilter("all");
|
||||
setOffset(0);
|
||||
}}
|
||||
className="w-full rounded-lg border border-border px-3 py-2 text-sm font-medium text-text-main transition-colors hover:bg-sidebar"
|
||||
>
|
||||
{t("clearFilters")}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</Card>
|
||||
|
||||
<Card className="overflow-hidden">
|
||||
</Button>
|
||||
</>
|
||||
}
|
||||
pagination={
|
||||
<DataTableFooter
|
||||
pagination={
|
||||
<div className="flex items-center gap-2">
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => setOffset((current) => Math.max(0, current - MCP_PAGE_SIZE))}
|
||||
disabled={offset === 0 || loading}
|
||||
>
|
||||
{t("previous")}
|
||||
</Button>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => setOffset((current) => current + MCP_PAGE_SIZE)}
|
||||
disabled={offset + MCP_PAGE_SIZE >= data.total || loading}
|
||||
>
|
||||
{t("next")}
|
||||
</Button>
|
||||
</div>
|
||||
}
|
||||
/>
|
||||
}
|
||||
>
|
||||
{loading ? (
|
||||
<div className="p-8 text-center text-sm text-text-muted">{t("loading")}</div>
|
||||
<TableLoadingState label={t("loading")} />
|
||||
) : data.entries.length === 0 ? (
|
||||
<div className="p-10 text-center">
|
||||
<span className="material-symbols-outlined text-[40px] text-text-muted">terminal</span>
|
||||
<p className="mt-3 text-sm text-text-muted">{t("noMcpEvents")}</p>
|
||||
</div>
|
||||
<EmptyState icon="terminal" title={t("noMcpEvents")} />
|
||||
) : (
|
||||
<div className="overflow-x-auto">
|
||||
<table className="w-full min-w-[860px] text-left text-sm">
|
||||
<thead className="border-b border-border bg-sidebar/40 text-xs uppercase tracking-wider text-text-muted">
|
||||
<tr>
|
||||
<th className="px-4 py-3 font-medium">{t("timestamp")}</th>
|
||||
<th className="px-4 py-3 font-medium">{t("tool")}</th>
|
||||
<th className="px-4 py-3 font-medium">{t("duration")}</th>
|
||||
<th className="px-4 py-3 font-medium">{t("result")}</th>
|
||||
<th className="px-4 py-3 font-medium">{t("apiKey")}</th>
|
||||
<th className="px-4 py-3 font-medium">{t("output")}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody className="divide-y divide-border">
|
||||
{data.entries.map((entry) => (
|
||||
<tr key={entry.id} className="transition-colors hover:bg-sidebar/30">
|
||||
<td className="whitespace-nowrap px-4 py-3 font-mono text-xs text-text-muted">
|
||||
{new Date(entry.createdAt).toLocaleString()}
|
||||
</td>
|
||||
<td className="px-4 py-3 font-mono text-xs text-text-main">{entry.toolName}</td>
|
||||
<td className="px-4 py-3 text-text-muted">{entry.durationMs}ms</td>
|
||||
<td className="px-4 py-3">
|
||||
<span
|
||||
className={`rounded-full border px-2 py-1 text-xs font-medium ${
|
||||
entry.success
|
||||
? "border-emerald-500/30 bg-emerald-500/10 text-emerald-600"
|
||||
: "border-red-500/30 bg-red-500/10 text-red-600"
|
||||
}`}
|
||||
>
|
||||
{entry.success ? t("success") : entry.errorCode || t("failure")}
|
||||
</span>
|
||||
</td>
|
||||
<td className="px-4 py-3 font-mono text-xs text-text-muted">
|
||||
{entry.apiKeyId || t("notAvailable")}
|
||||
</td>
|
||||
<td className="max-w-[280px] truncate px-4 py-3 text-xs text-text-muted">
|
||||
{entry.outputSummary || t("notAvailable")}
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<Table scrollbarLabel={t("mcpAudit")} className="min-w-[860px] text-left">
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead>{t("timestamp")}</TableHead>
|
||||
<TableHead>{t("tool")}</TableHead>
|
||||
<TableHead>{t("duration")}</TableHead>
|
||||
<TableHead>{t("result")}</TableHead>
|
||||
<TableHead>{t("apiKey")}</TableHead>
|
||||
<TableHead>{t("output")}</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{data.entries.map((entry) => (
|
||||
<TableRow key={entry.id}>
|
||||
<TableCell className="font-mono text-xs text-text-muted">
|
||||
{new Date(entry.createdAt).toLocaleString()}
|
||||
</TableCell>
|
||||
<TableCell className="font-mono text-xs text-text-main">
|
||||
{entry.toolName}
|
||||
</TableCell>
|
||||
<TableCell className="text-text-muted">{entry.durationMs}ms</TableCell>
|
||||
<TableCell>
|
||||
<Badge size="sm" variant={entry.success ? "success" : "error"}>
|
||||
{entry.success ? t("success") : entry.errorCode || t("failure")}
|
||||
</Badge>
|
||||
</TableCell>
|
||||
<TableCell className="font-mono text-xs text-text-muted">
|
||||
{entry.apiKeyId || t("notAvailable")}
|
||||
</TableCell>
|
||||
<TableCell className="max-w-[280px] truncate text-xs text-text-muted">
|
||||
{entry.outputSummary || t("notAvailable")}
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
</TableBody>
|
||||
</Table>
|
||||
)}
|
||||
</Card>
|
||||
|
||||
<div className="flex items-center justify-end gap-2">
|
||||
<button
|
||||
onClick={() => setOffset((current) => Math.max(0, current - MCP_PAGE_SIZE))}
|
||||
disabled={offset === 0 || loading}
|
||||
className="rounded-lg border border-border px-3 py-2 text-sm font-medium text-text-main transition-colors hover:bg-sidebar disabled:opacity-40"
|
||||
>
|
||||
{t("previous")}
|
||||
</button>
|
||||
<button
|
||||
onClick={() => setOffset((current) => current + MCP_PAGE_SIZE)}
|
||||
disabled={offset + MCP_PAGE_SIZE >= data.total || loading}
|
||||
className="rounded-lg border border-border px-3 py-2 text-sm font-medium text-text-main transition-colors hover:bg-sidebar disabled:opacity-40"
|
||||
>
|
||||
{t("next")}
|
||||
</button>
|
||||
</div>
|
||||
</DataTableShell>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
"use client";
|
||||
|
||||
import Icon from "@/shared/components/Icon";
|
||||
|
||||
// ExclusionsPanel (#8034) — per-model/endpoint compression exclusion filter.
|
||||
//
|
||||
// Lets the operator name model ids / `provider/model` patterns that must never be
|
||||
@@ -79,13 +81,8 @@ export default function ExclusionsPanel() {
|
||||
>
|
||||
<div className="flex flex-col gap-3">
|
||||
{loadError !== null && (
|
||||
<p
|
||||
role="alert"
|
||||
className="flex items-center gap-1 text-xs font-medium text-red-600 dark:text-red-400"
|
||||
>
|
||||
<span className="material-symbols-outlined text-[14px]" aria-hidden="true">
|
||||
error
|
||||
</span>
|
||||
<p role="alert" className="flex items-center gap-1 text-xs font-medium text-error">
|
||||
<Icon name="error" size={14} />
|
||||
{t("failedLoadWithStatus", { status: loadError || t("unknownError") })}
|
||||
</p>
|
||||
)}
|
||||
@@ -95,6 +92,7 @@ export default function ExclusionsPanel() {
|
||||
disabled={locked}
|
||||
placeholder={t("compressionExclusionsPlaceholder")}
|
||||
onChange={(e) => setRaw(e.target.value)}
|
||||
aria-label={t("compressionExclusionsTitle")}
|
||||
data-testid="compression-exclusions-textarea"
|
||||
/>
|
||||
<div className="flex items-center justify-between gap-3">
|
||||
@@ -106,17 +104,12 @@ export default function ExclusionsPanel() {
|
||||
: t("compressionExclusionsCount", { count: patterns.length }))}
|
||||
</span>
|
||||
<div className="flex items-center gap-2">
|
||||
<span role="status" className="text-xs text-emerald-600 dark:text-emerald-400">
|
||||
<span role="status" className="text-xs text-success">
|
||||
{status === "saved" && t("compressionExclusionsSaved")}
|
||||
</span>
|
||||
{status === "error" && (
|
||||
<span
|
||||
role="alert"
|
||||
className="flex items-center gap-1 text-xs font-medium text-red-600 dark:text-red-400"
|
||||
>
|
||||
<span className="material-symbols-outlined text-[14px]" aria-hidden="true">
|
||||
error
|
||||
</span>
|
||||
<span role="alert" className="flex items-center gap-1 text-xs font-medium text-error">
|
||||
<Icon name="error" size={14} />
|
||||
{t("saveFailed")}
|
||||
</span>
|
||||
)}
|
||||
|
||||
@@ -1,6 +1,16 @@
|
||||
"use client";
|
||||
import { useState } from "react";
|
||||
import { useTranslations } from "next-intl";
|
||||
import {
|
||||
Table,
|
||||
TableBody,
|
||||
TableCell,
|
||||
TableHead,
|
||||
TableHeader,
|
||||
TableRow,
|
||||
} from "@omniroute/ui-kit/table";
|
||||
import Button from "@/shared/components/Button";
|
||||
import Input from "@/shared/components/Input";
|
||||
|
||||
interface Row {
|
||||
engine: string;
|
||||
@@ -85,46 +95,46 @@ function VerifyControls({
|
||||
const t = useTranslations("compressionStudio");
|
||||
return (
|
||||
<>
|
||||
<label className="text-[10px]">
|
||||
{t("provider")}
|
||||
<input
|
||||
className="ml-1 w-24 rounded border px-1 text-xs"
|
||||
value={provider}
|
||||
onChange={(e) => onProvider(e.target.value)}
|
||||
/>
|
||||
</label>
|
||||
<label className="text-[10px]">
|
||||
{t("judgeModel")}
|
||||
<input
|
||||
data-testid="verify-model"
|
||||
className="ml-1 w-32 rounded border px-1 text-xs"
|
||||
value={judgeModel}
|
||||
onChange={(e) => onJudgeModel(e.target.value)}
|
||||
placeholder={t("judgeModelPlaceholder")}
|
||||
/>
|
||||
</label>
|
||||
<label className="text-[10px]">
|
||||
{t("maxCostUsd")}
|
||||
<input
|
||||
type="number"
|
||||
step="0.01"
|
||||
min="0"
|
||||
className="ml-1 w-16 rounded border px-1 text-xs"
|
||||
value={capUsd}
|
||||
onChange={(e) => onCapUsd(Number(e.target.value))}
|
||||
/>
|
||||
</label>
|
||||
<button
|
||||
<Input
|
||||
label={t("provider")}
|
||||
className="w-28"
|
||||
inputClassName="h-8 min-h-8 text-xs"
|
||||
value={provider}
|
||||
onChange={(e) => onProvider(e.target.value)}
|
||||
/>
|
||||
<Input
|
||||
label={t("judgeModel")}
|
||||
data-testid="verify-model"
|
||||
className="w-40"
|
||||
inputClassName="h-8 min-h-8 text-xs"
|
||||
value={judgeModel}
|
||||
onChange={(e) => onJudgeModel(e.target.value)}
|
||||
placeholder={t("judgeModelPlaceholder")}
|
||||
/>
|
||||
<Input
|
||||
type="number"
|
||||
label={t("maxCostUsd")}
|
||||
step="0.01"
|
||||
min="0"
|
||||
className="w-24"
|
||||
inputClassName="h-8 min-h-8 text-xs"
|
||||
value={capUsd}
|
||||
onChange={(e) => onCapUsd(Number(e.target.value))}
|
||||
/>
|
||||
<Button
|
||||
variant="secondary"
|
||||
size="sm"
|
||||
icon="balance"
|
||||
data-testid="verify-all"
|
||||
onClick={onVerify}
|
||||
loading={verifying}
|
||||
disabled={verifying || !judgeModel}
|
||||
title={!judgeModel ? t("enterJudgeModel") : undefined}
|
||||
className="rounded bg-purple-500/30 px-3 py-1 text-sm disabled:opacity-40"
|
||||
>
|
||||
{verifying ? t("verifying") : `⚖ ${t("verifyAll")}`}
|
||||
</button>
|
||||
{verifying ? t("verifying") : t("verifyAll")}
|
||||
</Button>
|
||||
{spent !== null && (
|
||||
<span className="text-[10px] opacity-70">
|
||||
<span className="text-[10px] text-text-muted">
|
||||
{t("spent", { spent: spent.toFixed(3), cap: capUsd.toFixed(2) })}
|
||||
{capped ? ` · ${t("capReached")}` : ""}
|
||||
</span>
|
||||
@@ -142,33 +152,33 @@ function ComparisonTable({
|
||||
}) {
|
||||
const t = useTranslations("compressionStudio");
|
||||
return (
|
||||
<table className="w-full text-xs">
|
||||
<thead>
|
||||
<tr className="text-left opacity-60">
|
||||
<th>{t("engine")}</th>
|
||||
<th>{t("savings")}</th>
|
||||
<th>{t("retention")}</th>
|
||||
<th>{t("outputTokensShort")}</th>
|
||||
<th>{t("fidelity")}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<Table scrollbarLabel={t("compareTab")} className="min-w-0 text-xs">
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead>{t("engine")}</TableHead>
|
||||
<TableHead>{t("savings")}</TableHead>
|
||||
<TableHead>{t("retention")}</TableHead>
|
||||
<TableHead>{t("outputTokensShort")}</TableHead>
|
||||
<TableHead>{t("fidelity")}</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{rows.map((row) => {
|
||||
const verdict = verdicts[row.engine];
|
||||
return (
|
||||
<tr key={row.engine} data-testid="compare-row" className="border-b">
|
||||
<td className="font-semibold">{row.engine}</td>
|
||||
<td>−{row.meanSavingsPercent.toFixed(0)}%</td>
|
||||
<td>{Math.round(row.meanRetention * 100)}%</td>
|
||||
<td>{row.totalCompressedTokens}</td>
|
||||
<td data-testid="verify-verdict">
|
||||
<TableRow key={row.engine} data-testid="compare-row">
|
||||
<TableCell className="font-semibold">{row.engine}</TableCell>
|
||||
<TableCell>−{row.meanSavingsPercent.toFixed(0)}%</TableCell>
|
||||
<TableCell>{Math.round(row.meanRetention * 100)}%</TableCell>
|
||||
<TableCell>{row.totalCompressedTokens}</TableCell>
|
||||
<TableCell data-testid="verify-verdict">
|
||||
{verdict ? (verdict.skippedCapped ? "—(cap)" : (verdict.verdict ?? "?")) : ""}
|
||||
</td>
|
||||
</tr>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
);
|
||||
})}
|
||||
</tbody>
|
||||
</table>
|
||||
</TableBody>
|
||||
</Table>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -219,14 +229,16 @@ export function CompareView({ text }: CompareViewProps) {
|
||||
return (
|
||||
<div className="flex flex-col gap-3">
|
||||
<div className="flex flex-wrap items-end gap-2">
|
||||
<button
|
||||
<Button
|
||||
variant="primary"
|
||||
size="sm"
|
||||
data-testid="compare-load"
|
||||
onClick={load}
|
||||
loading={loading}
|
||||
disabled={loading}
|
||||
className="rounded bg-blue-500/30 px-3 py-1 text-sm"
|
||||
>
|
||||
{loading ? t("running") : t("loadAb")}
|
||||
</button>
|
||||
</Button>
|
||||
{rows.length > 0 && (
|
||||
<VerifyControls
|
||||
provider={provider}
|
||||
|
||||
@@ -20,13 +20,13 @@ export function CompressionAnnotation({ stats }: CompressionAnnotationProps) {
|
||||
|
||||
return (
|
||||
<div className="flex items-center gap-2 flex-wrap" data-testid="compression-annotation">
|
||||
<span className="text-xs font-mono text-muted">
|
||||
<span className="text-xs font-mono text-text-muted">
|
||||
{stats.originalTokens}→{stats.compressedTokens}
|
||||
</span>
|
||||
{sorted.map(([name, n]) => (
|
||||
<span
|
||||
key={name}
|
||||
className="px-1.5 py-0.5 rounded text-[10px] bg-purple-500/10 text-purple-400 border border-purple-500/20"
|
||||
className="px-1.5 py-0.5 rounded text-[10px] bg-chart-3/10 text-chart-3 border border-chart-3/20"
|
||||
>
|
||||
{name}×{n}
|
||||
</span>
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
import { useMemo, useState } from "react";
|
||||
import { useTranslations } from "next-intl";
|
||||
import type { NodeTypes } from "@xyflow/react";
|
||||
import Button from "@/shared/components/Button";
|
||||
import Icon from "@/shared/components/Icon";
|
||||
import { FlowCanvas } from "@/shared/components/flow/FlowCanvas";
|
||||
import { EngineNode } from "./nodes/EngineNode";
|
||||
import { IoNode } from "./nodes/IoNode";
|
||||
@@ -45,17 +47,15 @@ function SpeedButton({
|
||||
onClick: () => void;
|
||||
}) {
|
||||
return (
|
||||
<button
|
||||
<Button
|
||||
variant={active ? "secondary" : "ghost"}
|
||||
size="sm"
|
||||
onClick={onClick}
|
||||
className="px-2 py-0.5 rounded text-[11px] border transition-colors"
|
||||
style={{
|
||||
borderColor: active ? "var(--color-primary)" : "var(--color-border)",
|
||||
color: active ? "var(--color-primary)" : "var(--color-text-muted)",
|
||||
background: active ? "var(--color-primary-subtle)" : "transparent",
|
||||
}}
|
||||
aria-pressed={active}
|
||||
className={`h-6 min-h-6 px-2 text-[11px] ${active ? "text-primary" : "text-text-muted"}`}
|
||||
>
|
||||
{s}×
|
||||
</button>
|
||||
</Button>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -73,19 +73,16 @@ function ViewButton({
|
||||
onClick: () => void;
|
||||
}) {
|
||||
return (
|
||||
<button
|
||||
<Button
|
||||
variant={active ? "secondary" : "ghost"}
|
||||
size="sm"
|
||||
onClick={onClick}
|
||||
data-testid={testId}
|
||||
aria-pressed={active}
|
||||
className="px-2 py-0.5 rounded text-[11px] border transition-colors"
|
||||
style={{
|
||||
borderColor: active ? "var(--color-primary)" : "var(--color-border)",
|
||||
color: active ? "var(--color-primary)" : "var(--color-text-muted)",
|
||||
background: active ? "var(--color-primary-subtle)" : "transparent",
|
||||
}}
|
||||
className={`h-6 min-h-6 px-2 text-[11px] ${active ? "text-primary" : "text-text-muted"}`}
|
||||
>
|
||||
{label}
|
||||
</button>
|
||||
</Button>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -95,7 +92,7 @@ function EmptyState() {
|
||||
const t = useTranslations("compressionStudio");
|
||||
return (
|
||||
<div
|
||||
className="flex flex-col items-center justify-center h-full gap-3 text-muted"
|
||||
className="flex flex-col items-center justify-center h-full gap-3 text-text-muted"
|
||||
data-testid="compression-cockpit-empty"
|
||||
>
|
||||
<span className="text-3xl opacity-40">⌁</span>
|
||||
@@ -176,13 +173,17 @@ export function CompressionCockpit({ run: runProp }: CompressionCockpitProps) {
|
||||
<div className="flex flex-col h-full gap-2" data-testid="compression-cockpit">
|
||||
{/* ── Header ─────────────────────────────────────────────────────── */}
|
||||
<div className="flex items-center gap-3 px-3 py-2 rounded-lg border border-border bg-bg/60 shrink-0">
|
||||
<span className="text-xs font-semibold text-muted uppercase tracking-wide">{run.mode}</span>
|
||||
<span className="text-xs font-semibold text-text-muted uppercase tracking-wide">
|
||||
{run.mode}
|
||||
</span>
|
||||
{run.comboId && (
|
||||
<span className="text-xs text-muted px-1.5 py-0.5 rounded bg-border/40 font-mono">
|
||||
<span className="text-xs text-text-muted px-1.5 py-0.5 rounded bg-border/40 font-mono">
|
||||
{run.comboId}
|
||||
</span>
|
||||
)}
|
||||
<span className="text-xs text-muted font-mono opacity-70 truncate">{run.requestId}</span>
|
||||
<span className="text-xs text-text-muted font-mono opacity-70 truncate">
|
||||
{run.requestId}
|
||||
</span>
|
||||
<CompressionAnnotation
|
||||
stats={{
|
||||
originalTokens: run.originalTokens,
|
||||
@@ -210,14 +211,14 @@ export function CompressionCockpit({ run: runProp }: CompressionCockpitProps) {
|
||||
onClick={() => setView("waterfall")}
|
||||
/>
|
||||
</div>
|
||||
<span className="text-[11px] text-muted">
|
||||
<span className="text-[11px] text-text-muted">
|
||||
{fmt(run.originalTokens)} → {fmt(run.compressedTokens)} {t("tokenShort")}
|
||||
</span>
|
||||
<span className="text-xs font-bold" style={{ color: "var(--orch-status-success)" }}>
|
||||
−{run.savingsPercent.toFixed(1)}%
|
||||
</span>
|
||||
{isComplete && view === "canvas" && (
|
||||
<span className="text-[10px] px-1.5 py-0.5 rounded border border-border text-muted">
|
||||
<span className="text-[10px] px-1.5 py-0.5 rounded border border-border text-text-muted">
|
||||
{t("replayDone")}
|
||||
</span>
|
||||
)}
|
||||
@@ -244,27 +245,32 @@ export function CompressionCockpit({ run: runProp }: CompressionCockpitProps) {
|
||||
{/* ── Replay controls (canvas only — the waterfall is static) ──────── */}
|
||||
{view === "canvas" && (
|
||||
<div className="flex items-center gap-2 px-3 py-1.5 rounded-lg border border-border bg-bg/60 shrink-0">
|
||||
<button
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
icon={isPlaying ? "pause" : "play_arrow"}
|
||||
onClick={isPlaying ? pause : play}
|
||||
className="flex items-center gap-1.5 px-2.5 py-1 rounded border border-border text-xs hover:bg-border/30 transition-colors"
|
||||
className="h-7 min-h-7 px-2.5 text-xs"
|
||||
aria-label={isPlaying ? t("pauseReplay") : t("playReplay")}
|
||||
>
|
||||
{isPlaying ? `⏸ ${t("pause")}` : `▷ ${t("replay")}`}
|
||||
</button>
|
||||
<button
|
||||
{isPlaying ? t("pause") : t("replay")}
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon-sm"
|
||||
onClick={reset}
|
||||
className="px-2 py-1 rounded border border-border text-xs text-muted hover:bg-border/30 transition-colors"
|
||||
className="text-text-muted"
|
||||
aria-label={t("resetReplay")}
|
||||
>
|
||||
⟳
|
||||
</button>
|
||||
<Icon name="replay" size={16} />
|
||||
</Button>
|
||||
<div className="flex items-center gap-1 ml-2">
|
||||
{SPEEDS.map((s) => (
|
||||
<SpeedButton key={s} s={s} active={speed === s} onClick={() => setSpeed(s)} />
|
||||
))}
|
||||
</div>
|
||||
{displayRun && currentFrame && (
|
||||
<span className="ml-auto text-[11px] text-muted">
|
||||
<span className="ml-auto text-[11px] text-text-muted">
|
||||
{t("stepProgress", {
|
||||
current: displayRun?.steps.length ?? 0,
|
||||
total: run.steps.length,
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
"use client";
|
||||
import { useTranslations } from "next-intl";
|
||||
import Badge from "@/shared/components/Badge";
|
||||
import Button from "@/shared/components/Button";
|
||||
import type { DiffSegment } from "./compressionFlowModel";
|
||||
export interface DiffPaneProps {
|
||||
segments: DiffSegment[];
|
||||
@@ -7,23 +9,26 @@ export interface DiffPaneProps {
|
||||
}
|
||||
const SEG_CLASS: Record<DiffSegment["type"], string> = {
|
||||
same: "opacity-90",
|
||||
removed: "bg-red-500/20 line-through",
|
||||
added: "bg-green-500/20",
|
||||
removed: "bg-error/20 line-through",
|
||||
added: "bg-success/20",
|
||||
};
|
||||
export function DiffPane({ segments, preservedBlocks }: DiffPaneProps) {
|
||||
const t = useTranslations("compressionStudio");
|
||||
return (
|
||||
<div data-testid="diff-pane" className="font-mono text-xs leading-relaxed">
|
||||
<div className="mb-2 flex gap-2 text-[10px]">
|
||||
<span className="rounded bg-blue-500/20 px-2 py-0.5">{t("inlineView")}</span>
|
||||
<button
|
||||
type="button"
|
||||
<Badge size="sm" variant="info">
|
||||
{t("inlineView")}
|
||||
</Badge>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
disabled
|
||||
title={t("splitComingSoon")}
|
||||
className="rounded px-2 py-0.5 opacity-40"
|
||||
className="h-6 min-h-6 px-2 text-[10px]"
|
||||
>
|
||||
{t("splitComingSoon")}
|
||||
</button>
|
||||
</Button>
|
||||
</div>
|
||||
<div className="whitespace-pre-wrap">
|
||||
{segments.map((seg, i) => (
|
||||
@@ -35,9 +40,9 @@ export function DiffPane({ segments, preservedBlocks }: DiffPaneProps) {
|
||||
{preservedBlocks.length > 0 && (
|
||||
<div className="mt-3 flex flex-wrap gap-1" data-testid="diff-preserved">
|
||||
{preservedBlocks.map((b, i) => (
|
||||
<span key={i} className="rounded border border-purple-500/50 px-1 text-[10px]">
|
||||
<Badge key={i} size="sm" className="border-chart-3/50 text-[10px]">
|
||||
{b.kind}: {b.preview.slice(0, 40)}
|
||||
</span>
|
||||
</Badge>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
|
||||
@@ -1,5 +1,13 @@
|
||||
"use client";
|
||||
import { useTranslations } from "next-intl";
|
||||
import {
|
||||
Table,
|
||||
TableBody,
|
||||
TableCell,
|
||||
TableHead,
|
||||
TableHeader,
|
||||
TableRow,
|
||||
} from "@omniroute/ui-kit/table";
|
||||
import type { EncoderComparison } from "./compressionFlowModel";
|
||||
|
||||
const fmt = (n: number) => n.toLocaleString("en-US");
|
||||
@@ -18,42 +26,42 @@ export function EncoderComparisonTable({ comparison }: { comparison: EncoderComp
|
||||
].sort((a, b) => (a.size?.tokens ?? Infinity) - (b.size?.tokens ?? Infinity));
|
||||
|
||||
return (
|
||||
<section data-testid="encoder-comparison" className="rounded border p-2 text-xs">
|
||||
<section data-testid="encoder-comparison" className="rounded border border-border p-2 text-xs">
|
||||
<header className="mb-1 font-semibold">
|
||||
{t("encoderComparison", { count: comparison.arraysCompared })}{" "}
|
||||
<span data-testid="encoder-winner" className="font-mono">
|
||||
{t("encoderWinner", { winner: comparison.winner })}
|
||||
</span>
|
||||
</header>
|
||||
<table className="w-full font-mono">
|
||||
<thead>
|
||||
<tr className="text-left text-muted-foreground">
|
||||
<th>{t("encoder")}</th>
|
||||
<th>{t("bytes")}</th>
|
||||
<th>{t("tokensCl100k")}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<Table persistentScrollbars={false} className="min-w-0 font-mono text-xs">
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead className="h-8">{t("encoder")}</TableHead>
|
||||
<TableHead className="h-8">{t("bytes")}</TableHead>
|
||||
<TableHead className="h-8">{t("tokensCl100k")}</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{rows.map((r) => (
|
||||
<tr key={r.key} className={r.key === comparison.winner ? "font-bold" : ""}>
|
||||
<td>
|
||||
<TableRow key={r.key} className={r.key === comparison.winner ? "font-bold" : ""}>
|
||||
<TableCell className="h-8">
|
||||
{r.label}
|
||||
{r.key === comparison.winner ? " ✓" : ""}
|
||||
</td>
|
||||
</TableCell>
|
||||
{r.size ? (
|
||||
<>
|
||||
<td>{fmt(r.size.bytes)}</td>
|
||||
<td>{fmt(r.size.tokens)}</td>
|
||||
<TableCell className="h-8">{fmt(r.size.bytes)}</TableCell>
|
||||
<TableCell className="h-8">{fmt(r.size.tokens)}</TableCell>
|
||||
</>
|
||||
) : (
|
||||
<td colSpan={2} data-testid="encoder-toon-na">
|
||||
<TableCell colSpan={2} className="h-8" data-testid="encoder-toon-na">
|
||||
n/a
|
||||
</td>
|
||||
</TableCell>
|
||||
)}
|
||||
</tr>
|
||||
</TableRow>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</TableBody>
|
||||
</Table>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
"use client";
|
||||
import { useState } from "react";
|
||||
import { useTranslations } from "next-intl";
|
||||
import Button from "@/shared/components/Button";
|
||||
import { usePreviewCompression, type Lane, type PreviewBatch } from "@/hooks/usePreviewCompression";
|
||||
import { WaterfallInspector } from "./WaterfallInspector";
|
||||
import { DiffPane } from "./DiffPane";
|
||||
@@ -31,15 +32,17 @@ function LaneList({ lanes, onSelect }: { lanes: Lane[]; onSelect: (e: string) =>
|
||||
return (
|
||||
<>
|
||||
{lanes.map((l) => (
|
||||
<button
|
||||
<Button
|
||||
key={l.engine}
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
data-testid="play-lane"
|
||||
onClick={() => onSelect(l.engine)}
|
||||
className="flex w-full items-center justify-between border-b py-1 text-left font-mono text-xs"
|
||||
className="h-auto min-h-8 w-full justify-between rounded-none border-b border-border px-1 py-1 text-left font-mono text-xs"
|
||||
>
|
||||
<span>{l.engine}</span>
|
||||
<span>{laneStatus(l, t)}</span>
|
||||
</button>
|
||||
</Button>
|
||||
))}
|
||||
</>
|
||||
);
|
||||
@@ -110,7 +113,7 @@ export function PlayView({ text, onText, laneEngines = LANE_ENGINES }: PlayViewP
|
||||
</section>
|
||||
)}
|
||||
{batch && !batch.combined && batch.combinedError && (
|
||||
<section data-testid="play-combined-error" className="text-xs text-red-600">
|
||||
<section data-testid="play-combined-error" className="text-xs text-error">
|
||||
{t("combinedError", { reason: batch.combinedError })}
|
||||
</section>
|
||||
)}
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
"use client";
|
||||
import type { ReactNode } from "react";
|
||||
import { useTranslations } from "next-intl";
|
||||
import { CheckboxGroup } from "@omniroute/ui-kit/checkbox";
|
||||
import Button from "@/shared/components/Button";
|
||||
import Checkbox from "@/shared/components/Checkbox";
|
||||
import Textarea from "@/shared/components/Textarea";
|
||||
export const LANE_ENGINES = [
|
||||
"session-dedup",
|
||||
"ccr",
|
||||
@@ -41,21 +45,24 @@ function EngineOptions({
|
||||
const t = useTranslations("compressionStudio");
|
||||
return (
|
||||
<div>
|
||||
<div className="text-[10px] uppercase opacity-60">{t("activeCombined")}</div>
|
||||
{LANE_ENGINES.map((engine) => (
|
||||
<label key={engine} className="flex items-center gap-2 text-sm">
|
||||
<input
|
||||
type="checkbox"
|
||||
<CheckboxGroup label={t("activeCombined")} className="gap-1">
|
||||
{LANE_ENGINES.map((engine) => (
|
||||
<Checkbox
|
||||
key={engine}
|
||||
label={engine}
|
||||
checked={active.includes(engine)}
|
||||
onChange={() => onToggleActive(engine)}
|
||||
/>
|
||||
{engine}
|
||||
</label>
|
||||
))}
|
||||
<label className="flex items-center gap-2 text-sm opacity-50">
|
||||
<input type="checkbox" disabled /> llmlingua{" "}
|
||||
<span className="text-[10px]">({t("requiresOnnx")})</span>
|
||||
</label>
|
||||
))}
|
||||
<Checkbox
|
||||
disabled
|
||||
label={
|
||||
<>
|
||||
llmlingua <span className="text-[10px]">({t("requiresOnnx")})</span>
|
||||
</>
|
||||
}
|
||||
/>
|
||||
</CheckboxGroup>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -65,7 +72,7 @@ function ToggleOption({
|
||||
checked,
|
||||
onChange,
|
||||
children,
|
||||
className = "flex items-center gap-2 text-sm",
|
||||
className = "text-sm",
|
||||
}: {
|
||||
testId: string;
|
||||
checked: boolean;
|
||||
@@ -74,10 +81,13 @@ function ToggleOption({
|
||||
className?: string;
|
||||
}) {
|
||||
return (
|
||||
<label className={className}>
|
||||
<input type="checkbox" data-testid={testId} checked={checked} onChange={onChange} />
|
||||
{children}
|
||||
</label>
|
||||
<Checkbox
|
||||
className={className}
|
||||
data-testid={testId}
|
||||
checked={checked}
|
||||
onChange={onChange}
|
||||
label={children}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -102,9 +112,10 @@ export function PlaygroundInput({
|
||||
const t = useTranslations("compressionStudio");
|
||||
return (
|
||||
<div className="flex flex-col gap-3">
|
||||
<textarea
|
||||
<Textarea
|
||||
data-testid="play-input"
|
||||
className="min-h-[160px] w-full rounded border p-2 font-mono text-xs"
|
||||
aria-label={t("inputPlaceholder")}
|
||||
className="min-h-[160px] w-full font-mono text-xs"
|
||||
value={text}
|
||||
onChange={(e) => onText(e.target.value)}
|
||||
placeholder={t("inputPlaceholder")}
|
||||
@@ -123,7 +134,7 @@ export function PlaygroundInput({
|
||||
testId="quantum-toggle"
|
||||
checked={quantumLock}
|
||||
onChange={onToggleQuantum}
|
||||
className="flex items-center gap-1 text-xs"
|
||||
className="text-xs"
|
||||
>
|
||||
{t("quantumLock")}
|
||||
</ToggleOption>
|
||||
@@ -131,18 +142,20 @@ export function PlaygroundInput({
|
||||
testId="heatmap-toggle"
|
||||
checked={Boolean(heatmap)}
|
||||
onChange={onToggleHeatmap}
|
||||
className="flex items-center gap-1 text-xs"
|
||||
className="text-xs"
|
||||
>
|
||||
{t("saliencyHeatmap")} {heatmap ? `(${heatmap})` : ""}
|
||||
</ToggleOption>
|
||||
<button
|
||||
<Button
|
||||
data-testid="play-run"
|
||||
className="rounded bg-blue-500/30 py-2 font-semibold"
|
||||
icon="play_arrow"
|
||||
fullWidth
|
||||
onClick={onRun}
|
||||
loading={loading}
|
||||
disabled={loading}
|
||||
>
|
||||
{loading ? t("running") : `▶ ${t("run")}`}
|
||||
</button>
|
||||
{loading ? t("running") : t("run")}
|
||||
</Button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ export function QuantumLockBadge({ stats }: QuantumLockBadgeProps) {
|
||||
.map(([cat, n]) => `${cat} ×${n}`)
|
||||
.join(", ");
|
||||
return (
|
||||
<span data-testid="quantum-badge" className="text-xs font-mono text-emerald-600">
|
||||
<span data-testid="quantum-badge" className="text-xs font-mono text-success">
|
||||
🔒 {stats.fragments} volatile fragment(s) stabilized{detail ? ` (${detail})` : ""}
|
||||
</span>
|
||||
);
|
||||
|
||||
@@ -1,14 +1,18 @@
|
||||
import React from "react";
|
||||
import type { RiskGateStats } from "./compressionFlowModel.ts";
|
||||
|
||||
export function RiskGateBadge({ stats }: { stats: RiskGateStats | null | undefined }): React.ReactElement | null {
|
||||
export function RiskGateBadge({
|
||||
stats,
|
||||
}: {
|
||||
stats: RiskGateStats | null | undefined;
|
||||
}): React.ReactElement | null {
|
||||
if (!stats || stats.spansProtected <= 0) return null;
|
||||
const cats = Object.entries(stats.categories)
|
||||
.filter(([, n]) => (n ?? 0) > 0)
|
||||
.map(([k, n]) => `${k} ×${n}`)
|
||||
.join(", ");
|
||||
return (
|
||||
<div data-testid="risk-gate-badge" className="text-sm text-amber-700">
|
||||
<div data-testid="risk-gate-badge" className="text-sm text-warning">
|
||||
🛡️ {stats.spansProtected} risky span(s) protected{cats ? ` (${cats})` : ""}
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -44,7 +44,7 @@ function StepRow({ step, maxTokens }: { step: CompressionEngineStep; maxTokens:
|
||||
{step.engine}
|
||||
</span>
|
||||
{skipped && (
|
||||
<span className="ml-1.5 text-[10px] text-muted bg-muted/10 px-1 rounded">
|
||||
<span className="ml-1.5 text-[10px] text-text-muted bg-bg-subtle px-1 rounded">
|
||||
{t("skipped")}
|
||||
</span>
|
||||
)}
|
||||
@@ -55,7 +55,7 @@ function StepRow({ step, maxTokens }: { step: CompressionEngineStep; maxTokens:
|
||||
{/* in bar */}
|
||||
<div className="relative h-2 rounded-full bg-border/30 overflow-hidden">
|
||||
<div
|
||||
className="absolute inset-y-0 left-0 rounded-full bg-muted/40"
|
||||
className="absolute inset-y-0 left-0 rounded-full bg-border/40"
|
||||
style={{ width: `${barWidthIn.toFixed(1)}%` }}
|
||||
/>
|
||||
</div>
|
||||
@@ -72,7 +72,7 @@ function StepRow({ step, maxTokens }: { step: CompressionEngineStep; maxTokens:
|
||||
|
||||
{/* Token counts */}
|
||||
<div className="w-36 shrink-0 text-right">
|
||||
<div className="text-[10px] text-muted">
|
||||
<div className="text-[10px] text-text-muted">
|
||||
{fmt(step.originalTokens)} → {fmt(step.compressedTokens)}
|
||||
</div>
|
||||
{!skipped && (
|
||||
@@ -85,7 +85,7 @@ function StepRow({ step, maxTokens }: { step: CompressionEngineStep; maxTokens:
|
||||
</div>
|
||||
)}
|
||||
{step.durationMs != null && (
|
||||
<div className="text-[9px] text-muted">{step.durationMs.toFixed(1)}ms</div>
|
||||
<div className="text-[9px] text-text-muted">{step.durationMs.toFixed(1)}ms</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
@@ -117,11 +117,11 @@ export function WaterfallInspector({ run, className = "" }: WaterfallInspectorPr
|
||||
return (
|
||||
<div className={`flex flex-col ${className}`} data-testid="waterfall-inspector">
|
||||
{/* Header — INPUT */}
|
||||
<div className="flex items-center gap-3 py-2 border-b border-border font-semibold text-xs text-muted">
|
||||
<div className="flex items-center gap-3 py-2 border-b border-border font-semibold text-xs text-text-muted">
|
||||
<span className="w-28 shrink-0 text-primary">⌁ {t("input")}</span>
|
||||
<div className="flex-1">
|
||||
<div className="h-2 rounded-full bg-muted/30 overflow-hidden">
|
||||
<div className="h-full w-full rounded-full bg-muted/50" />
|
||||
<div className="h-2 rounded-full bg-border/30 overflow-hidden">
|
||||
<div className="h-full w-full rounded-full bg-border/50" />
|
||||
</div>
|
||||
</div>
|
||||
<span className="w-36 shrink-0 text-right">
|
||||
@@ -136,17 +136,17 @@ export function WaterfallInspector({ run, className = "" }: WaterfallInspectorPr
|
||||
|
||||
{/* Footer — OUTPUT */}
|
||||
<div className="flex items-center gap-3 py-2 border-t border-border mt-1">
|
||||
<span className="w-28 shrink-0 text-xs font-semibold text-green-500">✦ {t("output")}</span>
|
||||
<span className="w-28 shrink-0 text-xs font-semibold text-success">✦ {t("output")}</span>
|
||||
<div className="flex-1">
|
||||
<div className="h-2 rounded-full bg-border/30 overflow-hidden">
|
||||
<div
|
||||
className="h-full rounded-full bg-green-500"
|
||||
className="h-full rounded-full bg-success"
|
||||
style={{ width: pctWidth(run.originalTokens, run.compressedTokens) }}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div className="w-36 shrink-0 text-right">
|
||||
<div className="text-xs font-semibold text-green-500">
|
||||
<div className="text-xs font-semibold text-success">
|
||||
{t("tokenCount", { count: run.compressedTokens })}
|
||||
</div>
|
||||
<div
|
||||
@@ -160,11 +160,11 @@ export function WaterfallInspector({ run, className = "" }: WaterfallInspectorPr
|
||||
</div>
|
||||
|
||||
{/* Summary bar */}
|
||||
<div className="flex items-center gap-3 px-3 py-2 rounded-lg bg-border/10 mt-2 text-[11px] text-muted">
|
||||
<div className="flex items-center gap-3 px-3 py-2 rounded-lg bg-border/10 mt-2 text-[11px] text-text-muted">
|
||||
<span>
|
||||
{fmt(run.originalTokens)} → {fmt(run.compressedTokens)} {t("tokenShort")}
|
||||
</span>
|
||||
<span className="text-green-500 font-bold">−{run.savingsPercent.toFixed(1)}%</span>
|
||||
<span className="text-success font-bold">−{run.savingsPercent.toFixed(1)}%</span>
|
||||
{run.comboId && <span className="font-mono opacity-70">{run.comboId}</span>}
|
||||
<span className="ml-auto opacity-60">{run.mode}</span>
|
||||
</div>
|
||||
|
||||
@@ -118,13 +118,15 @@ export function EngineNode({ data }: NodeProps) {
|
||||
<span className="text-xs font-semibold truncate flex-1" title={engine as string}>
|
||||
{engine as string}
|
||||
</span>
|
||||
{skipped && <span className="text-[10px] text-muted px-1 rounded bg-muted/10">skip</span>}
|
||||
{skipped && (
|
||||
<span className="text-[10px] text-text-muted px-1 rounded bg-bg-subtle">skip</span>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Body — token bar */}
|
||||
{!skipped && (
|
||||
<div className="px-2.5 py-1.5">
|
||||
<div className="flex justify-between text-[10px] text-muted mb-0.5">
|
||||
<div className="flex justify-between text-[10px] text-text-muted mb-0.5">
|
||||
<span>{tokIn.toLocaleString()}</span>
|
||||
<span>→</span>
|
||||
<span>{tokOut.toLocaleString()}</span>
|
||||
@@ -150,14 +152,14 @@ export function EngineNode({ data }: NodeProps) {
|
||||
)}
|
||||
{techniques.length > 0 && (
|
||||
<span
|
||||
className="text-[9px] text-muted truncate"
|
||||
className="text-[9px] text-text-muted truncate"
|
||||
title={(techniquesUsed as string[]).join(", ")}
|
||||
>
|
||||
{techniques.join(", ")}
|
||||
</span>
|
||||
)}
|
||||
{durationMs != null && (
|
||||
<span className="text-[9px] text-muted">{(durationMs as number).toFixed(1)}ms</span>
|
||||
<span className="text-[9px] text-text-muted">{(durationMs as number).toFixed(1)}ms</span>
|
||||
)}
|
||||
{/* Layer pills */}
|
||||
{layers.length > 0 && (
|
||||
|
||||
@@ -50,7 +50,7 @@ export function IoNode({ data }: NodeProps) {
|
||||
<div className="text-base font-bold" style={{ color }}>
|
||||
{(tokens as number).toLocaleString()}
|
||||
</div>
|
||||
<div className="text-[10px] text-muted">tokens</div>
|
||||
<div className="text-[10px] text-text-muted">tokens</div>
|
||||
|
||||
{!isInput && savingsPercent != null && (
|
||||
<div
|
||||
|
||||
@@ -1,29 +1,38 @@
|
||||
"use client";
|
||||
import { useState } from "react";
|
||||
import { useTranslations } from "next-intl";
|
||||
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@omniroute/ui-kit/tabs";
|
||||
import { PlayView } from "./PlayView";
|
||||
import { CompareView } from "./CompareView";
|
||||
|
||||
export default function CompressionStudioPage() {
|
||||
const t = useTranslations("compressionStudio");
|
||||
const [tab, setTab] = useState<"play" | "compare">("play");
|
||||
const [text, setText] = useState("");
|
||||
return (
|
||||
<div className="flex h-[calc(100dvh-6rem)] min-h-[480px] flex-col p-4">
|
||||
<div className="mb-3 flex gap-2">
|
||||
<button data-testid="tab-play" aria-pressed={tab === "play"} onClick={() => setTab("play")}>
|
||||
{t("playTab")}
|
||||
</button>
|
||||
<button
|
||||
data-testid="tab-compare"
|
||||
aria-pressed={tab === "compare"}
|
||||
onClick={() => setTab("compare")}
|
||||
>
|
||||
{t("compareTab")}
|
||||
</button>
|
||||
</div>
|
||||
<div className="min-h-0 flex-1">
|
||||
{tab === "play" ? <PlayView text={text} onText={setText} /> : <CompareView text={text} />}
|
||||
</div>
|
||||
{/* Kit underline Tabs (WAI-ARIA tablist); the selected view mounts in its panel. */}
|
||||
<Tabs
|
||||
variant="underline"
|
||||
value={tab}
|
||||
onValueChange={(next) => setTab(next as "play" | "compare")}
|
||||
className="flex min-h-0 flex-1 flex-col"
|
||||
>
|
||||
<TabsList aria-label={t("studioViews")} className="mb-3">
|
||||
<TabsTrigger value="play" data-testid="tab-play">
|
||||
{t("playTab")}
|
||||
</TabsTrigger>
|
||||
<TabsTrigger value="compare" data-testid="tab-compare">
|
||||
{t("compareTab")}
|
||||
</TabsTrigger>
|
||||
</TabsList>
|
||||
<TabsContent value="play" className="min-h-0 flex-1">
|
||||
<PlayView text={text} onText={setText} />
|
||||
</TabsContent>
|
||||
<TabsContent value="compare" className="min-h-0 flex-1">
|
||||
<CompareView text={text} />
|
||||
</TabsContent>
|
||||
</Tabs>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
import { useEffect, useState } from "react";
|
||||
import { useLocale, useTranslations } from "next-intl";
|
||||
import Badge from "@/shared/components/Badge";
|
||||
import Card from "@/shared/components/Card";
|
||||
|
||||
interface Summary {
|
||||
totalRuns: number;
|
||||
@@ -38,10 +40,7 @@ export default function CompressionStylesTile() {
|
||||
const styles = Object.entries(summary.appliedStyleCounts);
|
||||
|
||||
return (
|
||||
<div
|
||||
data-testid="compression-styles-tile"
|
||||
className="rounded-lg border border-border/40 bg-surface p-4"
|
||||
>
|
||||
<Card padding="sm" data-testid="compression-styles-tile">
|
||||
<p className="text-sm font-medium text-text-main">{t("compressionStylesTileTitle")}</p>
|
||||
<p className="mt-1 text-2xl font-semibold text-text-main">
|
||||
{summary.totalTokensSaved.toLocaleString(locale, { useGrouping: false })}
|
||||
@@ -57,12 +56,12 @@ export default function CompressionStylesTile() {
|
||||
<span className="text-xs text-text-muted">{t("compressionStylesTileEmpty")}</span>
|
||||
) : (
|
||||
styles.map(([id, count]) => (
|
||||
<span key={id} className="rounded bg-border/30 px-2 py-0.5 text-xs text-text-main">
|
||||
<Badge key={id} size="sm">
|
||||
{id} · {count}
|
||||
</span>
|
||||
</Badge>
|
||||
))
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,13 @@
|
||||
|
||||
import { useEffect, useMemo, useState } from "react";
|
||||
import { useTranslations } from "next-intl";
|
||||
import { Alert } from "@omniroute/ui-kit/alert";
|
||||
import { PageHeader, SectionHeader } from "@omniroute/ui-kit/page-header";
|
||||
import { SegmentedControl } from "@/shared/components";
|
||||
import Card from "@/shared/components/Card";
|
||||
import Checkbox from "@/shared/components/Checkbox";
|
||||
import Select from "@/shared/components/Select";
|
||||
import Icon from "@/shared/components/Icon";
|
||||
import CompressionSettingsTab from "@/app/(dashboard)/dashboard/settings/components/CompressionSettingsTab";
|
||||
import { outputStyleLanguages } from "../../../../../../open-sse/services/compression/outputStyles/catalog.ts";
|
||||
import {
|
||||
@@ -169,16 +175,18 @@ export default function CavemanContextPageClient() {
|
||||
|
||||
return (
|
||||
<div className="mx-auto flex max-w-6xl flex-col gap-6">
|
||||
<header className="flex flex-col gap-2">
|
||||
<div className="flex items-center justify-between gap-3">
|
||||
<div className="flex items-center gap-3">
|
||||
<span className="material-symbols-outlined text-[30px] text-primary">compress</span>
|
||||
<div>
|
||||
<h1 className="text-2xl font-bold text-text-main">{t("title")}</h1>
|
||||
<p className="text-sm text-text-muted">{t("description")}</p>
|
||||
</div>
|
||||
</div>
|
||||
<PageHeader
|
||||
compact
|
||||
title={
|
||||
<span className="flex items-center gap-3">
|
||||
<Icon name="compress" size={30} className="text-primary" />
|
||||
{t("title")}
|
||||
</span>
|
||||
}
|
||||
description={t("description")}
|
||||
actions={
|
||||
<SegmentedControl
|
||||
aria-label={t("viewMode")}
|
||||
value={viewMode}
|
||||
onChange={(v) => setViewMode(v as "simple" | "advanced")}
|
||||
options={[
|
||||
@@ -186,85 +194,72 @@ export default function CavemanContextPageClient() {
|
||||
{ value: "advanced", label: t("advancedMode") || "Advanced" },
|
||||
]}
|
||||
/>
|
||||
</div>
|
||||
</header>
|
||||
}
|
||||
/>
|
||||
|
||||
<section className="grid grid-cols-1 gap-3 sm:grid-cols-4">
|
||||
{statCards.map(([label, value]) => (
|
||||
<div key={label} className="rounded-lg border border-border bg-surface p-4">
|
||||
<Card key={label} padding="sm">
|
||||
<p className="text-xs uppercase text-text-muted">{label}</p>
|
||||
<p className="mt-1 text-xl font-semibold text-text-main">{value}</p>
|
||||
</div>
|
||||
</Card>
|
||||
))}
|
||||
</section>
|
||||
|
||||
<section className="rounded-lg border border-border bg-surface p-4">
|
||||
<div className="flex flex-col gap-1">
|
||||
<h2 className="text-sm font-semibold text-text-main">{t("languagePacks")}</h2>
|
||||
<p className="text-xs text-text-muted">{t("languagePacksDesc")}</p>
|
||||
</div>
|
||||
<div className="mt-4 flex flex-wrap gap-4 text-sm text-text-main">
|
||||
<label className="flex items-center gap-2">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={languageConfig.enabled}
|
||||
disabled={saving}
|
||||
onChange={(event) => updateLanguageConfig({ enabled: event.target.checked })}
|
||||
/>
|
||||
{t("enabled")}
|
||||
</label>
|
||||
<label className="flex items-center gap-2">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={languageConfig.autoDetect}
|
||||
disabled={saving}
|
||||
onChange={(event) => updateLanguageConfig({ autoDetect: event.target.checked })}
|
||||
/>
|
||||
{t("autoDetect")}
|
||||
</label>
|
||||
<select
|
||||
<Card padding="sm">
|
||||
<SectionHeader title={t("languagePacks")} description={t("languagePacksDesc")} />
|
||||
<div className="mt-4 flex flex-wrap items-center gap-4 text-sm text-text-main">
|
||||
<Checkbox
|
||||
label={t("enabled")}
|
||||
checked={languageConfig.enabled}
|
||||
disabled={saving}
|
||||
onChange={(event) => updateLanguageConfig({ enabled: event.target.checked })}
|
||||
/>
|
||||
<Checkbox
|
||||
label={t("autoDetect")}
|
||||
checked={languageConfig.autoDetect}
|
||||
disabled={saving}
|
||||
onChange={(event) => updateLanguageConfig({ autoDetect: event.target.checked })}
|
||||
/>
|
||||
<Select
|
||||
aria-label={t("defaultLanguage")}
|
||||
value={languageConfig.defaultLanguage}
|
||||
disabled={saving || languageConfig.autoDetect}
|
||||
onChange={(event) => updateLanguageConfig({ defaultLanguage: event.target.value })}
|
||||
className="rounded-lg border border-border bg-bg px-3 py-2 text-sm"
|
||||
>
|
||||
{languageOptions.map((lang) => (
|
||||
<option key={lang} value={lang}>
|
||||
{lang}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</Select>
|
||||
</div>
|
||||
<div className="mt-4 grid grid-cols-1 gap-3 sm:grid-cols-2 lg:grid-cols-3">
|
||||
{languagePacks.map((pack) => (
|
||||
<label
|
||||
<Checkbox
|
||||
key={pack.language}
|
||||
className="flex items-center justify-between rounded-lg border border-border bg-bg p-3 text-sm text-text-main"
|
||||
>
|
||||
<span>
|
||||
{pack.language} - {t("rulesCount", { count: pack.ruleCount })}
|
||||
</span>
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={languageConfig.enabledPacks.includes(pack.language)}
|
||||
disabled={saving || pack.language === "en"}
|
||||
onChange={(event) => togglePack(pack.language, event.target.checked)}
|
||||
/>
|
||||
</label>
|
||||
className="justify-between rounded-lg border border-border bg-bg p-3 text-sm text-text-main"
|
||||
label={`${pack.language} - ${t("rulesCount", { count: pack.ruleCount })}`}
|
||||
checked={languageConfig.enabledPacks.includes(pack.language)}
|
||||
disabled={saving || pack.language === "en"}
|
||||
onChange={(event) => togglePack(pack.language, event.target.checked)}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
</section>
|
||||
</Card>
|
||||
|
||||
{!masterEnabled && (
|
||||
<div className="rounded-lg border border-amber-500/30 bg-amber-500/10 px-4 py-3 text-sm text-amber-700 dark:text-amber-300 flex items-start gap-2">
|
||||
<span className="material-symbols-outlined text-[18px]">info</span>
|
||||
<p>{t("masterDisabledWarning")}</p>
|
||||
</div>
|
||||
<Alert
|
||||
variant="warning"
|
||||
icon={<Icon name="info" size={18} />}
|
||||
className="[&>.ci-alert__dismiss]:hidden"
|
||||
description={t("masterDisabledWarning")}
|
||||
/>
|
||||
)}
|
||||
|
||||
<section className="grid grid-cols-1 gap-4 lg:grid-cols-2">
|
||||
<div className="rounded-lg border border-border bg-surface p-4">
|
||||
<h2 className="text-sm font-semibold text-text-main">{t("analyticsTitle")}</h2>
|
||||
<Card padding="sm">
|
||||
<SectionHeader title={t("analyticsTitle")} />
|
||||
<div className="mt-3 space-y-2 text-sm text-text-main">
|
||||
{modeBreakdown.length === 0 ? (
|
||||
<p className="text-text-muted">{t("noAnalytics")}</p>
|
||||
@@ -279,23 +274,19 @@ export default function CavemanContextPageClient() {
|
||||
))
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</Card>
|
||||
|
||||
<div className="rounded-lg border border-border bg-surface p-4">
|
||||
<h2 className="text-sm font-semibold text-text-main">{t("outputModeTitle")}</h2>
|
||||
<p className="mt-1 text-xs text-text-muted">{t("outputModeDesc")}</p>
|
||||
<Card padding="sm">
|
||||
<SectionHeader title={t("outputModeTitle")} description={t("outputModeDesc")} />
|
||||
{/* On/off + intensity for caveman output mode live in the panel
|
||||
(/dashboard/context/settings). This page keeps the detailed knobs only. */}
|
||||
<div className="mt-3 flex flex-wrap gap-4 text-sm text-text-main">
|
||||
<label className="flex items-center gap-2">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={outputMode.autoClarity}
|
||||
disabled={saving}
|
||||
onChange={(event) => updateOutputMode({ autoClarity: event.target.checked })}
|
||||
/>
|
||||
{t("autoClarity")}
|
||||
</label>
|
||||
<Checkbox
|
||||
label={t("autoClarity")}
|
||||
checked={outputMode.autoClarity}
|
||||
disabled={saving}
|
||||
onChange={(event) => updateOutputMode({ autoClarity: event.target.checked })}
|
||||
/>
|
||||
</div>
|
||||
<pre className="mt-3 overflow-auto rounded-lg border border-border bg-bg p-3 text-xs text-text-main">
|
||||
{previewPrompt}
|
||||
@@ -303,7 +294,7 @@ export default function CavemanContextPageClient() {
|
||||
<p className="mt-3 text-xs text-text-muted">
|
||||
{t("bypassConditions")}: {t("bypassConditionsList")}
|
||||
</p>
|
||||
</div>
|
||||
</Card>
|
||||
</section>
|
||||
|
||||
{viewMode === "advanced" && <CompressionSettingsTab />}
|
||||
|
||||
@@ -8,6 +8,14 @@ import { useTranslations } from "next-intl";
|
||||
import { STACKED_PIPELINE_ENGINE_INTENSITIES } from "@/shared/validation/compressionConfigSchemas";
|
||||
import { CompressionPipelineEditor } from "@/shared/components/compression/CompressionPipelineEditor";
|
||||
import { ComboCompressionModeSelect } from "@/shared/components/compression/ComboCompressionModeSelect";
|
||||
import { Alert } from "@omniroute/ui-kit/alert";
|
||||
import { SectionHeader } from "@omniroute/ui-kit/page-header";
|
||||
import Badge from "@/shared/components/Badge";
|
||||
import Button from "@/shared/components/Button";
|
||||
import Card from "@/shared/components/Card";
|
||||
import Checkbox from "@/shared/components/Checkbox";
|
||||
import Input from "@/shared/components/Input";
|
||||
import Select from "@/shared/components/Select";
|
||||
import CompressionHub from "./CompressionHub";
|
||||
|
||||
type PipelineStep = { engine: string; intensity?: string };
|
||||
@@ -204,57 +212,56 @@ function NamedCombosManager() {
|
||||
|
||||
if (loadFailed) {
|
||||
return (
|
||||
<div className="flex items-center justify-between gap-4 rounded-lg border border-border bg-surface p-4">
|
||||
<p role="alert" className="text-sm text-red-600 dark:text-red-400">
|
||||
<Card padding="sm" className="flex items-center justify-between gap-4">
|
||||
<p role="alert" className="text-sm text-error">
|
||||
{tSettings("compressionTitle")}: {tCommon("failedToLoad")}
|
||||
</p>
|
||||
<button
|
||||
type="button"
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => setLoadAttempt((attempt) => attempt + 1)}
|
||||
className="shrink-0 rounded-lg border border-border px-3 py-1.5 text-xs text-text-main hover:bg-bg"
|
||||
className="shrink-0"
|
||||
>
|
||||
{tSettings("retry")}
|
||||
</button>
|
||||
</div>
|
||||
</Button>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-4">
|
||||
<div>
|
||||
<h2 className="text-lg font-semibold text-text-main">{t("namedCombos")}</h2>
|
||||
<p className="text-sm text-text-muted">{t("namedCombosDescription")}</p>
|
||||
</div>
|
||||
<SectionHeader title={t("namedCombos")} description={t("namedCombosDescription")} />
|
||||
|
||||
{/* #12063: the master "Prompt Compression" switch (Settings page) is a hard kill that
|
||||
runs BEFORE an active profile is even considered (strategySelector.ts resolveBasePlan).
|
||||
Surface that dependency here so a selected profile is never silently inert. */}
|
||||
{!compressionEnabled && activeComboId && (
|
||||
<div
|
||||
<Alert
|
||||
variant="warning"
|
||||
role="alert"
|
||||
data-testid="compression-master-switch-warning"
|
||||
className="rounded-lg border border-amber-500/40 bg-amber-500/10 p-3 text-sm text-amber-600 dark:text-amber-400"
|
||||
className="[&>.ci-alert__dismiss]:hidden"
|
||||
>
|
||||
{t("activeProfileMasterSwitchOffWarning")}{" "}
|
||||
<Link href="/dashboard/context/settings" className="font-medium underline">
|
||||
{t("activeProfileMasterSwitchOffCta")}
|
||||
</Link>
|
||||
</div>
|
||||
</Alert>
|
||||
)}
|
||||
|
||||
<section className="rounded-lg border border-border bg-surface p-4">
|
||||
<Card padding="sm">
|
||||
<div className="grid grid-cols-1 gap-3 md:grid-cols-2">
|
||||
<input
|
||||
<Input
|
||||
label={t("name")}
|
||||
value={name}
|
||||
onChange={(event) => setName(event.target.value)}
|
||||
placeholder={t("comboNamePlaceholder")}
|
||||
className="rounded-lg border border-border bg-bg px-3 py-2 text-sm text-text-main"
|
||||
/>
|
||||
<input
|
||||
<Input
|
||||
label={t("descriptionField")}
|
||||
value={description}
|
||||
onChange={(event) => setDescription(event.target.value)}
|
||||
placeholder={t("descriptionPlaceholder")}
|
||||
className="rounded-lg border border-border bg-bg px-3 py-2 text-sm text-text-main"
|
||||
/>
|
||||
</div>
|
||||
|
||||
@@ -271,39 +278,32 @@ function NamedCombosManager() {
|
||||
<h3 className="mb-2 text-sm font-semibold text-text-main">{t("languagePacks")}</h3>
|
||||
<div className="space-y-2 text-sm text-text-main">
|
||||
{languagePacks.map((pack) => (
|
||||
<label key={pack.language} className="flex items-center justify-between gap-2">
|
||||
<span>
|
||||
{pack.language} ({pack.ruleCount})
|
||||
</span>
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={selectedPacks.includes(pack.language)}
|
||||
disabled={pack.language === "en"}
|
||||
onChange={(event) => togglePack(pack.language, event.target.checked)}
|
||||
/>
|
||||
</label>
|
||||
<Checkbox
|
||||
key={pack.language}
|
||||
label={`${pack.language} (${pack.ruleCount})`}
|
||||
checked={selectedPacks.includes(pack.language)}
|
||||
disabled={pack.language === "en"}
|
||||
onChange={(event) => togglePack(pack.language, event.target.checked)}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
<div className="space-y-2 text-sm text-text-main">
|
||||
<h3 className="text-sm font-semibold text-text-main">{t("outputMode")}</h3>
|
||||
<label className="flex items-center gap-2">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={outputMode}
|
||||
onChange={(event) => setOutputMode(event.target.checked)}
|
||||
/>
|
||||
{t("enabled")}
|
||||
</label>
|
||||
<select
|
||||
<Checkbox
|
||||
label={t("enabled")}
|
||||
checked={outputMode}
|
||||
onChange={(event) => setOutputMode(event.target.checked)}
|
||||
/>
|
||||
<Select
|
||||
aria-label={t("intensity")}
|
||||
value={outputModeIntensity}
|
||||
onChange={(event) => setOutputModeIntensity(event.target.value)}
|
||||
className="w-full rounded-lg border border-border bg-bg px-3 py-2 text-sm"
|
||||
>
|
||||
<option value="lite">{t("intensityLite")}</option>
|
||||
<option value="full">{t("intensityFull")}</option>
|
||||
<option value="ultra">{t("intensityUltra")}</option>
|
||||
</select>
|
||||
</Select>
|
||||
</div>
|
||||
<div>
|
||||
<h3 className="mb-2 text-sm font-semibold text-text-main">{t("assignToRouting")}</h3>
|
||||
@@ -316,19 +316,17 @@ function NamedCombosManager() {
|
||||
if (!id) return null;
|
||||
return (
|
||||
<div key={id} className="flex items-center justify-between gap-2">
|
||||
<label className="flex min-w-0 flex-1 items-center justify-between gap-2">
|
||||
<span className="truncate">{combo.name ?? id}</span>
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={assignmentIds.includes(id)}
|
||||
onChange={(event) => toggleAssignment(id, event.target.checked)}
|
||||
/>
|
||||
</label>
|
||||
<Checkbox
|
||||
className="min-w-0 flex-1"
|
||||
label={<span className="truncate">{combo.name ?? id}</span>}
|
||||
checked={assignmentIds.includes(id)}
|
||||
onChange={(event) => toggleAssignment(id, event.target.checked)}
|
||||
/>
|
||||
<ComboCompressionModeSelect
|
||||
combo={{ id, config: combo.config }}
|
||||
disabled={!compressionEnabled}
|
||||
title="Compression override"
|
||||
className="w-24 shrink-0 rounded-lg border border-border bg-bg px-2 py-1 text-xs text-text-main disabled:opacity-50"
|
||||
title={t("compressionOverride")}
|
||||
className="ci-select-native--sm w-24 shrink-0 text-xs"
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
@@ -339,78 +337,65 @@ function NamedCombosManager() {
|
||||
</div>
|
||||
|
||||
{error && (
|
||||
<p className="mt-4 text-sm text-danger" role="alert">
|
||||
<p className="mt-4 text-sm text-error" role="alert">
|
||||
{error}
|
||||
</p>
|
||||
)}
|
||||
|
||||
<div className="mt-4 flex flex-wrap gap-2">
|
||||
<button
|
||||
onClick={saveCombo}
|
||||
disabled={saving}
|
||||
className="rounded-lg bg-primary px-4 py-2 text-sm font-medium text-accent-foreground"
|
||||
>
|
||||
<Button onClick={saveCombo} loading={saving} disabled={saving}>
|
||||
{editingId ? t("save") : t("createCombo")}
|
||||
</button>
|
||||
</Button>
|
||||
{editingId && (
|
||||
<button
|
||||
onClick={resetForm}
|
||||
className="rounded-lg border border-border px-4 py-2 text-sm text-text-main"
|
||||
>
|
||||
<Button variant="ghost" onClick={resetForm}>
|
||||
{t("cancel")}
|
||||
</button>
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</section>
|
||||
</Card>
|
||||
|
||||
<section className="grid grid-cols-1 gap-4 lg:grid-cols-2">
|
||||
{combos.map((combo) => (
|
||||
<div key={combo.id} className="rounded-lg border border-border bg-surface p-4">
|
||||
<Card key={combo.id} padding="sm">
|
||||
<div className="flex items-start justify-between gap-3">
|
||||
<div className="min-w-0">
|
||||
<h3 className="truncate text-base font-semibold text-text-main">{combo.name}</h3>
|
||||
<p className="mt-1 text-sm text-text-muted">{combo.description}</p>
|
||||
</div>
|
||||
{combo.id === activeComboId && (
|
||||
<span
|
||||
data-testid={`active-badge-${combo.id}`}
|
||||
className="rounded-full bg-green-500/10 px-2 py-1 text-xs font-medium text-green-500"
|
||||
>
|
||||
● {t("active")}
|
||||
</span>
|
||||
<Badge data-testid={`active-badge-${combo.id}`} variant="success" dot>
|
||||
{t("active")}
|
||||
</Badge>
|
||||
)}
|
||||
</div>
|
||||
<div className="mt-4 flex flex-wrap gap-2">
|
||||
{combo.pipeline.map((step, index) => (
|
||||
<span
|
||||
key={`${combo.id}-${index}`}
|
||||
className="rounded-lg border border-border bg-bg px-2 py-1 font-mono text-xs text-text-muted"
|
||||
>
|
||||
<Badge key={`${combo.id}-${index}`} size="sm" className="font-mono">
|
||||
{index + 1}. {step.engine}
|
||||
{step.intensity ? `:${step.intensity}` : ""}
|
||||
</span>
|
||||
</Badge>
|
||||
))}
|
||||
</div>
|
||||
<p className="mt-3 text-xs text-text-muted">
|
||||
{t("languagePacksList", { packs: combo.languagePacks.join(", ") })}
|
||||
</p>
|
||||
<div className="mt-4 flex flex-wrap gap-2">
|
||||
<button
|
||||
onClick={() => editCombo(combo)}
|
||||
className="rounded-lg border border-border px-3 py-1.5 text-xs text-text-main"
|
||||
>
|
||||
<Button variant="outline" size="sm" icon="edit" onClick={() => editCombo(combo)}>
|
||||
{t("editCombo")}
|
||||
</button>
|
||||
</Button>
|
||||
{!combo.isDefault && (
|
||||
<button
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
icon="delete"
|
||||
onClick={() => deleteCombo(combo)}
|
||||
className="rounded-lg border border-danger/40 px-3 py-1.5 text-xs text-danger"
|
||||
className="border-error/40 text-error hover:bg-error/10"
|
||||
>
|
||||
{t("deleteCombo")}
|
||||
</button>
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</Card>
|
||||
))}
|
||||
</section>
|
||||
</div>
|
||||
|
||||
@@ -9,6 +9,13 @@
|
||||
|
||||
import { useCallback, useEffect, useRef, useState } from "react";
|
||||
import { useTranslations } from "next-intl";
|
||||
import { Alert } from "@omniroute/ui-kit/alert";
|
||||
import Button from "@/shared/components/Button";
|
||||
import Card from "@/shared/components/Card";
|
||||
import Icon from "@/shared/components/Icon";
|
||||
import { Skeleton } from "@/shared/components/Loading";
|
||||
import Select from "@/shared/components/Select";
|
||||
import Toggle from "@/shared/components/Toggle";
|
||||
|
||||
// ── Types ─────────────────────────────────────────────────────────────────────
|
||||
|
||||
@@ -57,35 +64,6 @@ function confirmLeave(event: BeforeUnloadEvent) {
|
||||
|
||||
// ── Sub-components ──────────────────────────────────────────────────────────────
|
||||
|
||||
function Toggle({
|
||||
checked,
|
||||
onChange,
|
||||
ariaLabel,
|
||||
}: {
|
||||
checked: boolean;
|
||||
onChange: () => void;
|
||||
ariaLabel: string;
|
||||
}) {
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
role="switch"
|
||||
aria-checked={checked}
|
||||
aria-label={ariaLabel}
|
||||
onClick={onChange}
|
||||
className={`relative w-10 h-5 rounded-full transition-colors ${
|
||||
checked ? "bg-green-500" : "bg-border"
|
||||
}`}
|
||||
>
|
||||
<span
|
||||
className={`absolute top-0.5 w-4 h-4 rounded-full bg-white transition-transform ${
|
||||
checked ? "left-5" : "left-0.5"
|
||||
}`}
|
||||
/>
|
||||
</button>
|
||||
);
|
||||
}
|
||||
|
||||
// ── Main component ──────────────────────────────────────────────────────────────
|
||||
|
||||
export default function CompressionHub() {
|
||||
@@ -207,31 +185,33 @@ export default function CompressionHub() {
|
||||
// ── Derived state ─────────────────────────────────────────────────────────────
|
||||
if (loading) {
|
||||
return (
|
||||
<div className="flex items-center justify-center p-10 text-sm text-text-muted">
|
||||
{t("loading")}
|
||||
<div className="flex flex-col gap-3 p-4" aria-busy="true">
|
||||
<span className="ci-sr-only">{t("loading")}</span>
|
||||
<Skeleton className="h-32 w-full" />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (loadFailed) {
|
||||
return (
|
||||
<section className="flex flex-col gap-5 rounded-xl border border-primary/30 bg-surface p-5">
|
||||
<Card padding="sm" className="flex flex-col gap-5 border-primary/30">
|
||||
<div className="flex items-center justify-between gap-4">
|
||||
<p role="alert" className="text-sm text-red-600 dark:text-red-400">
|
||||
<p role="alert" className="text-sm text-error">
|
||||
{tSettings("compressionTitle")}: {tCommon("failedToLoad")}
|
||||
</p>
|
||||
<button
|
||||
type="button"
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => {
|
||||
setLoading(true);
|
||||
setLoadAttempt((attempt) => attempt + 1);
|
||||
}}
|
||||
className="shrink-0 rounded-lg border border-border px-3 py-1.5 text-xs text-text-main hover:bg-bg"
|
||||
className="shrink-0"
|
||||
>
|
||||
{tSettings("retry")}
|
||||
</button>
|
||||
</Button>
|
||||
</div>
|
||||
</section>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -241,29 +221,31 @@ export default function CompressionHub() {
|
||||
: "";
|
||||
|
||||
return (
|
||||
<section className="flex flex-col gap-5 rounded-xl border border-primary/30 bg-surface p-5">
|
||||
<Card padding="sm" className="flex flex-col gap-5 border-primary/30">
|
||||
{/* ── Header ── */}
|
||||
<div className="flex items-start justify-between gap-3">
|
||||
<div className="flex items-center gap-3">
|
||||
<span className="material-symbols-outlined text-[26px] text-primary" aria-hidden="true">
|
||||
hub
|
||||
</span>
|
||||
<Icon name="hub" size={26} className="text-primary" />
|
||||
<div>
|
||||
<h1 className="text-xl font-bold text-text-main">{t("hubTitle")}</h1>
|
||||
<p className="text-sm text-text-muted">{t("hubDescription")}</p>
|
||||
</div>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => setExplainerOpen((v) => !v)}
|
||||
className="shrink-0 rounded-lg border border-border px-3 py-1.5 text-xs text-text-main hover:bg-bg"
|
||||
aria-expanded={explainerOpen}
|
||||
className="shrink-0"
|
||||
>
|
||||
{explainerOpen ? t("hideExplanation") : t("howItWorks")}
|
||||
</button>
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{error && (
|
||||
<p className="rounded border border-danger/40 px-3 py-2 text-xs text-danger">{error}</p>
|
||||
<p role="alert" className="rounded border border-error/40 px-3 py-2 text-xs text-error">
|
||||
{error}
|
||||
</p>
|
||||
)}
|
||||
|
||||
{/* ── Explainer ── */}
|
||||
@@ -301,18 +283,13 @@ export default function CompressionHub() {
|
||||
|
||||
{/* ── Active profile ── */}
|
||||
<div className="flex flex-col gap-3 rounded-lg border border-border bg-bg p-4">
|
||||
<div className="flex flex-col gap-1">
|
||||
<label htmlFor="active-profile" className="text-sm font-semibold text-text-main">
|
||||
{t("activeProfile")}
|
||||
</label>
|
||||
<p className="text-xs text-text-muted">{t("activeProfileDescription")}</p>
|
||||
</div>
|
||||
<select
|
||||
<Select
|
||||
id="active-profile"
|
||||
label={t("activeProfile")}
|
||||
hint={t("activeProfileDescription")}
|
||||
data-testid="active-profile-select"
|
||||
value={settings?.activeComboId ?? ""}
|
||||
onChange={(e) => saveSettings({ activeComboId: e.target.value || null })}
|
||||
className="rounded-lg border border-border bg-surface px-3 py-2 text-sm text-text-main"
|
||||
>
|
||||
<option value="">{t("defaultFromPanel")}</option>
|
||||
{combos.map((c) => (
|
||||
@@ -320,7 +297,7 @@ export default function CompressionHub() {
|
||||
{c.name}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</Select>
|
||||
<div
|
||||
data-testid="active-profile-preview"
|
||||
className="rounded-lg border border-dashed border-border px-3 py-2 text-xs text-text-muted"
|
||||
@@ -357,11 +334,13 @@ export default function CompressionHub() {
|
||||
ariaLabel={t("contextEditingAria")}
|
||||
/>
|
||||
</div>
|
||||
<div className="flex items-start gap-2 rounded-lg border border-amber-500/40 bg-amber-500/5 px-3 py-2 text-xs text-amber-500">
|
||||
<span className="material-symbols-outlined text-[16px]">info</span>
|
||||
<span>{t("contextEditingNote")}</span>
|
||||
</div>
|
||||
<Alert
|
||||
variant="warning"
|
||||
icon={<Icon name="info" size={16} />}
|
||||
className="[&>.ci-alert__dismiss]:hidden"
|
||||
description={t("contextEditingNote")}
|
||||
/>
|
||||
</div>
|
||||
</section>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -14,6 +14,9 @@ import { useTranslations } from "next-intl";
|
||||
import Card from "@/shared/components/Card";
|
||||
import Toggle from "@/shared/components/Toggle";
|
||||
import Button from "@/shared/components/Button";
|
||||
import Badge from "@/shared/components/Badge";
|
||||
import Select from "@/shared/components/Select";
|
||||
import { PageHeader as KitPageHeader } from "@omniroute/ui-kit/page-header";
|
||||
import { SAMPLE_BEFORE_TEXT, SAMPLE_PAGE_PNG_DATA_URI, SAMPLE_METRICS } from "./sampleData";
|
||||
|
||||
interface CompressionConfigLite {
|
||||
@@ -62,15 +65,16 @@ const ECONOMICS = [
|
||||
function PageHeader() {
|
||||
const t = useTranslations("omniglyph");
|
||||
return (
|
||||
<div className="flex flex-col gap-2">
|
||||
<div className="flex items-center gap-3">
|
||||
<h1 className="text-2xl font-semibold">{t("title")}</h1>
|
||||
<span className="rounded-full border border-amber-500/40 bg-amber-500/10 px-2 py-0.5 text-xs font-medium text-amber-600 dark:text-amber-400">
|
||||
{t("preview")}
|
||||
<KitPageHeader
|
||||
compact
|
||||
title={
|
||||
<span className="flex items-center gap-3">
|
||||
{t("title")}
|
||||
<Badge variant="warning">{t("preview")}</Badge>
|
||||
</span>
|
||||
</div>
|
||||
<p className="max-w-2xl text-sm text-text-muted">{t("description")}</p>
|
||||
</div>
|
||||
}
|
||||
description={t("description")}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -97,7 +101,7 @@ function BeforeAfterCard() {
|
||||
<Card className="p-6">
|
||||
<div className="mb-1 flex items-baseline justify-between">
|
||||
<h2 className="text-lg font-semibold">{t("beforeAfterTitle")}</h2>
|
||||
<span className="text-sm font-medium text-emerald-600 dark:text-emerald-400">
|
||||
<span className="text-sm font-medium text-success">
|
||||
{t("blockSavings", { percent: SAMPLE_METRICS.savingsPct })}
|
||||
</span>
|
||||
</div>
|
||||
@@ -109,7 +113,7 @@ function BeforeAfterCard() {
|
||||
<span className="text-xs font-medium uppercase tracking-wide text-text-muted">
|
||||
{t("textTokens", { tokens: SAMPLE_METRICS.textTokens })}
|
||||
</span>
|
||||
<pre className="max-h-60 overflow-auto rounded border border-black/10 bg-black/5 p-3 text-[11px] leading-relaxed dark:border-white/10 dark:bg-white/5">
|
||||
<pre className="max-h-60 overflow-auto rounded border border-border bg-bg-subtle p-3 text-[11px] leading-relaxed">
|
||||
{SAMPLE_BEFORE_TEXT}
|
||||
</pre>
|
||||
</div>
|
||||
@@ -117,7 +121,8 @@ function BeforeAfterCard() {
|
||||
<span className="text-xs font-medium uppercase tracking-wide text-text-muted">
|
||||
{t("renderedTokens", { tokens: SAMPLE_METRICS.imageTokens })}
|
||||
</span>
|
||||
<div className="overflow-auto rounded border border-black/10 bg-white p-3 dark:border-white/10">
|
||||
{/* White paper behind the rendered page image (its own background), in both themes. */}
|
||||
<div className="overflow-auto rounded border border-border bg-white p-3">
|
||||
{/* eslint-disable-next-line @next/next/no-img-element -- data URI, no loader needed */}
|
||||
<img
|
||||
src={SAMPLE_PAGE_PNG_DATA_URI}
|
||||
@@ -149,15 +154,13 @@ function GatesCard() {
|
||||
<ol className="flex flex-col gap-3">
|
||||
{GATES.map((g, i) => (
|
||||
<li key={g.id} className="flex gap-3">
|
||||
<span className="mt-0.5 flex h-6 w-6 shrink-0 items-center justify-center rounded-full bg-black/5 text-xs font-semibold tabular-nums dark:bg-white/10">
|
||||
<span className="mt-0.5 flex h-6 w-6 shrink-0 items-center justify-center rounded-full bg-bg-subtle text-xs font-semibold tabular-nums">
|
||||
{i + 1}
|
||||
</span>
|
||||
<div className="flex flex-col">
|
||||
<span className="text-sm font-medium">
|
||||
{t(`gates.${g.id}.label`)} —{" "}
|
||||
<span className="text-emerald-600 dark:text-emerald-400">
|
||||
{t(`gates.${g.id}.pass`)}
|
||||
</span>
|
||||
<span className="text-success">{t(`gates.${g.id}.pass`)}</span>
|
||||
</span>
|
||||
<span className="text-xs text-text-muted">{t(`gates.${g.id}.why`)}</span>
|
||||
</div>
|
||||
@@ -180,8 +183,8 @@ function ProfileCard(props: {
|
||||
<div className="flex flex-col gap-3">
|
||||
<h2 className="text-lg font-semibold">{t("profileTitle")}</h2>
|
||||
<p className="max-w-xl text-sm text-text-muted">{t("profileDescription")}</p>
|
||||
<select
|
||||
className="w-full max-w-sm rounded-md border border-border bg-surface px-3 py-2 text-sm"
|
||||
<Select
|
||||
className="w-full max-w-sm"
|
||||
value={props.profile}
|
||||
disabled={props.disabled}
|
||||
aria-label={t("profileAria")}
|
||||
@@ -193,7 +196,7 @@ function ProfileCard(props: {
|
||||
{t(`profiles.${p.key}.label`)}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</Select>
|
||||
<span className="max-w-xl text-xs text-text-muted">
|
||||
{t(`profiles.${selected.key}.description`)}
|
||||
</span>
|
||||
@@ -249,7 +252,7 @@ function LoadErrorCard(props: { onRetry: () => void }) {
|
||||
return (
|
||||
<Card className="p-6">
|
||||
<div className="flex items-center justify-between gap-4">
|
||||
<p role="alert" className="text-sm text-red-600 dark:text-red-400">
|
||||
<p role="alert" className="text-sm text-error">
|
||||
{t("compressionTitle")}: {tCommon("failedToLoad")}
|
||||
</p>
|
||||
<Button size="sm" variant="secondary" onClick={props.onRetry}>
|
||||
|
||||
@@ -2,7 +2,16 @@
|
||||
|
||||
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
||||
import { useTranslations } from "next-intl";
|
||||
import { SegmentedControl, Collapsible } from "@/shared/components";
|
||||
import { Alert } from "@omniroute/ui-kit/alert";
|
||||
import { PageHeader, SectionHeader } from "@omniroute/ui-kit/page-header";
|
||||
import { Collapsible, SegmentedControl } from "@/shared/components";
|
||||
import Button from "@/shared/components/Button";
|
||||
import Card from "@/shared/components/Card";
|
||||
import Checkbox from "@/shared/components/Checkbox";
|
||||
import Input from "@/shared/components/Input";
|
||||
import Select from "@/shared/components/Select";
|
||||
import Textarea from "@/shared/components/Textarea";
|
||||
import Icon from "@/shared/components/Icon";
|
||||
import { useNotificationStore } from "@/store/notificationStore";
|
||||
import { rtkConfigSchema } from "@/shared/validation/compressionConfigSchemas";
|
||||
import RtkLearnDiscoverCard from "./RtkLearnDiscoverCard";
|
||||
@@ -172,24 +181,21 @@ function NumberSetting({
|
||||
return () => onDraftChange(false);
|
||||
}, [open, onDraftChange]);
|
||||
return (
|
||||
<label className="flex flex-col gap-1 text-sm text-text-main">
|
||||
{label}
|
||||
<input
|
||||
type="number"
|
||||
min={min}
|
||||
max={max}
|
||||
value={draft ?? value}
|
||||
onChange={(event) => {
|
||||
draftRef.current = event.target.value;
|
||||
setDraft(event.target.value);
|
||||
}}
|
||||
onBlur={commit}
|
||||
onKeyDown={(event) => {
|
||||
if (event.key === "Enter") commit();
|
||||
}}
|
||||
className="rounded border border-border bg-bg px-2 py-1 text-sm"
|
||||
/>
|
||||
</label>
|
||||
<Input
|
||||
label={label}
|
||||
type="number"
|
||||
min={min}
|
||||
max={max}
|
||||
value={draft ?? value}
|
||||
onChange={(event) => {
|
||||
draftRef.current = event.target.value;
|
||||
setDraft(event.target.value);
|
||||
}}
|
||||
onBlur={commit}
|
||||
onKeyDown={(event) => {
|
||||
if (event.key === "Enter") commit();
|
||||
}}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -406,34 +412,37 @@ export default function RtkContextPageClient() {
|
||||
if (loadFailed) {
|
||||
return (
|
||||
<div className="mx-auto flex max-w-6xl flex-col gap-6">
|
||||
<div className="flex items-center justify-between gap-4 rounded-lg border border-border bg-surface p-4">
|
||||
<p role="alert" className="text-sm text-red-600 dark:text-red-400">
|
||||
<Card padding="sm" className="flex items-center justify-between gap-4">
|
||||
<p role="alert" className="text-sm text-error">
|
||||
{tSettings("compressionTitle")}: {tCommon("failedToLoad")}
|
||||
</p>
|
||||
<button
|
||||
type="button"
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => setLoadAttempt((attempt) => attempt + 1)}
|
||||
className="shrink-0 rounded-lg border border-border px-3 py-1.5 text-xs text-text-main hover:bg-bg"
|
||||
className="shrink-0"
|
||||
>
|
||||
{tSettings("retry")}
|
||||
</button>
|
||||
</div>
|
||||
</Button>
|
||||
</Card>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="mx-auto flex max-w-6xl flex-col gap-6">
|
||||
<header className="flex flex-col gap-2">
|
||||
<div className="flex items-center justify-between gap-3">
|
||||
<div className="flex items-center gap-3">
|
||||
<span className="material-symbols-outlined text-[30px] text-primary">filter_alt</span>
|
||||
<div>
|
||||
<h1 className="text-2xl font-bold text-text-main">{t("title")}</h1>
|
||||
<p className="text-sm text-text-muted">{t("description")}</p>
|
||||
</div>
|
||||
</div>
|
||||
<PageHeader
|
||||
compact
|
||||
title={
|
||||
<span className="flex items-center gap-3">
|
||||
<Icon name="filter_alt" size={30} className="text-primary" />
|
||||
{t("title")}
|
||||
</span>
|
||||
}
|
||||
description={t("description")}
|
||||
actions={
|
||||
<SegmentedControl
|
||||
aria-label={t("viewMode")}
|
||||
value={viewMode}
|
||||
onChange={(v) => setViewMode(v as "simple" | "advanced")}
|
||||
options={[
|
||||
@@ -441,49 +450,41 @@ export default function RtkContextPageClient() {
|
||||
{ value: "advanced", label: t("advancedMode") || "Advanced" },
|
||||
]}
|
||||
/>
|
||||
</div>
|
||||
</header>
|
||||
}
|
||||
/>
|
||||
|
||||
<section className="grid grid-cols-1 gap-3 sm:grid-cols-2 xl:grid-cols-4">
|
||||
{statCards.map(([label, value]) => (
|
||||
<div key={label} className="rounded-lg border border-border bg-surface p-4">
|
||||
<Card key={label} padding="sm">
|
||||
<p className="text-xs uppercase text-text-muted">{label}</p>
|
||||
<p className="mt-1 text-xl font-semibold text-text-main">{value}</p>
|
||||
</div>
|
||||
</Card>
|
||||
))}
|
||||
</section>
|
||||
|
||||
{masterEnabled === false && (
|
||||
<div className="rounded-lg border border-amber-500/30 bg-amber-500/10 px-4 py-3 text-sm text-amber-700 dark:text-amber-300 flex items-start gap-2">
|
||||
<span className="material-symbols-outlined text-[18px]">info</span>
|
||||
<p>{t("masterSwitchOffAlert")}</p>
|
||||
</div>
|
||||
<Alert
|
||||
variant="warning"
|
||||
icon={<Icon name="info" size={18} />}
|
||||
className="[&>.ci-alert__dismiss]:hidden"
|
||||
description={t("masterSwitchOffAlert")}
|
||||
/>
|
||||
)}
|
||||
|
||||
{loadError !== null && (
|
||||
<p
|
||||
role="alert"
|
||||
className="flex items-center gap-1 text-xs font-medium text-red-600 dark:text-red-400"
|
||||
>
|
||||
<span className="material-symbols-outlined text-[14px]" aria-hidden="true">
|
||||
error
|
||||
</span>
|
||||
<p role="alert" className="flex items-center gap-1 text-xs font-medium text-error">
|
||||
<Icon name="error" size={14} />
|
||||
{tSettings("failedLoadWithStatus", { status: loadError || tSettings("unknownError") })}
|
||||
</p>
|
||||
)}
|
||||
|
||||
{config && (
|
||||
<section className="rounded-lg border border-border bg-surface p-4">
|
||||
<Card padding="sm">
|
||||
{/* On/off + intensity now live in the panel (/dashboard/context/settings). This
|
||||
page edits RTK's detailed configuration only. */}
|
||||
{saveFailed && (
|
||||
<p
|
||||
role="alert"
|
||||
className="mb-3 flex items-center gap-1 text-xs font-medium text-red-500"
|
||||
>
|
||||
<span className="material-symbols-outlined text-[14px]" aria-hidden="true">
|
||||
error
|
||||
</span>
|
||||
<p role="alert" className="mb-3 flex items-center gap-1 text-xs font-medium text-error">
|
||||
<Icon name="error" size={14} />
|
||||
{tSettings("saveFailed")}
|
||||
</p>
|
||||
)}
|
||||
@@ -514,60 +515,56 @@ export default function RtkContextPageClient() {
|
||||
["customFiltersEnabled", t("customFilters")],
|
||||
["trustProjectFilters", t("trustProjectFilters")],
|
||||
].map(([key, label]) => (
|
||||
<label key={key} className="flex items-center gap-2">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={Boolean(config[key as keyof RtkConfig])}
|
||||
onChange={(event) =>
|
||||
saveConfig({ [key]: event.target.checked } as Partial<RtkConfig>)
|
||||
}
|
||||
/>
|
||||
{label}
|
||||
</label>
|
||||
<Checkbox
|
||||
key={key}
|
||||
label={label}
|
||||
checked={Boolean(config[key as keyof RtkConfig])}
|
||||
onChange={(event) =>
|
||||
saveConfig({ [key]: event.target.checked } as Partial<RtkConfig>)
|
||||
}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
<div className="mt-4 max-w-sm text-sm text-text-main">
|
||||
<label className="flex flex-col gap-1">
|
||||
{t("rawOutputRetention")}
|
||||
<select
|
||||
value={config.rawOutputRetention}
|
||||
onChange={(event) =>
|
||||
saveConfig({
|
||||
rawOutputRetention: event.target.value as RtkConfig["rawOutputRetention"],
|
||||
})
|
||||
}
|
||||
className="rounded border border-border bg-bg px-2 py-1 text-sm"
|
||||
>
|
||||
<option value="never">{t("rawOutputNever")}</option>
|
||||
<option value="failures">{t("rawOutputFailures")}</option>
|
||||
<option value="always">{t("rawOutputAlways")}</option>
|
||||
</select>
|
||||
</label>
|
||||
<Select
|
||||
label={t("rawOutputRetention")}
|
||||
value={config.rawOutputRetention}
|
||||
onChange={(event) =>
|
||||
saveConfig({
|
||||
rawOutputRetention: event.target.value as RtkConfig["rawOutputRetention"],
|
||||
})
|
||||
}
|
||||
>
|
||||
<option value="never">{t("rawOutputNever")}</option>
|
||||
<option value="failures">{t("rawOutputFailures")}</option>
|
||||
<option value="always">{t("rawOutputAlways")}</option>
|
||||
</Select>
|
||||
</div>
|
||||
</section>
|
||||
</Card>
|
||||
)}
|
||||
|
||||
{viewMode === "advanced" && (
|
||||
<section className="grid grid-cols-1 gap-4 xl:grid-cols-[1fr_1fr]">
|
||||
<div className="rounded-lg border border-border bg-surface p-4">
|
||||
<div className="mb-3 flex items-center justify-between">
|
||||
<h2 className="text-sm font-semibold text-text-main">{t("filterTesting")}</h2>
|
||||
<button
|
||||
onClick={runPreview}
|
||||
className="rounded-lg bg-primary px-3 py-2 text-sm font-medium text-accent-foreground"
|
||||
>
|
||||
{t("run")}
|
||||
</button>
|
||||
</div>
|
||||
<textarea
|
||||
<Card padding="sm">
|
||||
<SectionHeader
|
||||
className="mb-3"
|
||||
title={t("filterTesting")}
|
||||
actions={
|
||||
<Button size="sm" icon="play_arrow" onClick={runPreview}>
|
||||
{t("run")}
|
||||
</Button>
|
||||
}
|
||||
/>
|
||||
<Textarea
|
||||
value={sample}
|
||||
onChange={(event) => setSample(event.target.value)}
|
||||
placeholder={t("pasteOutput")}
|
||||
className="h-72 w-full rounded-lg border border-border bg-bg p-3 font-mono text-xs text-text-main"
|
||||
aria-label={t("filterTesting")}
|
||||
className="h-72 w-full font-mono text-xs"
|
||||
/>
|
||||
</div>
|
||||
<div className="rounded-lg border border-border bg-surface p-4">
|
||||
<h2 className="mb-3 text-sm font-semibold text-text-main">{t("result")}</h2>
|
||||
</Card>
|
||||
<Card padding="sm">
|
||||
<SectionHeader className="mb-3" title={t("result")} />
|
||||
{preview?.detection && (
|
||||
<p className="mb-2 text-xs text-text-muted">
|
||||
{t("detected")}: {preview.detection.type} (
|
||||
@@ -577,7 +574,7 @@ export default function RtkContextPageClient() {
|
||||
<pre className="h-72 overflow-auto rounded-lg border border-border bg-bg p-3 text-xs text-text-main">
|
||||
{preview ? JSON.stringify(preview, null, 2) : t("previewEmpty")}
|
||||
</pre>
|
||||
</div>
|
||||
</Card>
|
||||
</section>
|
||||
)}
|
||||
|
||||
@@ -609,8 +606,8 @@ export default function RtkContextPageClient() {
|
||||
<p className="text-xs font-medium text-text-main">{filter.name}</p>
|
||||
<p className="mt-0.5 text-[11px] text-text-muted">{filter.description}</p>
|
||||
</div>
|
||||
<input
|
||||
type="checkbox"
|
||||
<Checkbox
|
||||
aria-label={filter.name}
|
||||
checked={enabled}
|
||||
disabled={!config}
|
||||
onChange={(event) => toggleFilter(filter.id, event.target.checked)}
|
||||
|
||||
@@ -2,6 +2,10 @@
|
||||
|
||||
import { useState } from "react";
|
||||
import { useTranslations } from "next-intl";
|
||||
import { SectionHeader } from "@omniroute/ui-kit/page-header";
|
||||
import Button from "@/shared/components/Button";
|
||||
import Card from "@/shared/components/Card";
|
||||
import Input from "@/shared/components/Input";
|
||||
|
||||
interface NoiseCandidate {
|
||||
pattern: string;
|
||||
@@ -78,15 +82,11 @@ export default function RtkLearnDiscoverCard() {
|
||||
}
|
||||
|
||||
return (
|
||||
<section
|
||||
className="rounded-lg border border-border bg-surface p-4"
|
||||
data-testid="rtk-learn-discover"
|
||||
>
|
||||
<h2 className="text-sm font-semibold text-text-main">{t("learnDiscoverTitle")}</h2>
|
||||
<p className="mt-1 text-xs text-text-muted">{t("learnDiscoverDesc")}</p>
|
||||
<Card padding="sm" data-testid="rtk-learn-discover">
|
||||
<SectionHeader title={t("learnDiscoverTitle")} description={t("learnDiscoverDesc")} />
|
||||
|
||||
{error && (
|
||||
<p className="mt-3 text-xs text-red-600 dark:text-red-400" data-testid="rtk-ld-error">
|
||||
<p className="mt-3 text-xs text-error" role="alert" data-testid="rtk-ld-error">
|
||||
{error}
|
||||
</p>
|
||||
)}
|
||||
@@ -95,15 +95,16 @@ export default function RtkLearnDiscoverCard() {
|
||||
{/* ── Discover ─────────────────────────────────────────────── */}
|
||||
<div>
|
||||
<h3 className="text-xs font-medium text-text-main">{t("discoverHeading")}</h3>
|
||||
<button
|
||||
type="button"
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={runDiscover}
|
||||
disabled={discovering}
|
||||
data-testid="rtk-discover-button"
|
||||
className="mt-2 rounded border border-border px-2.5 py-1 text-xs font-medium text-text-main hover:bg-surface-hover disabled:opacity-50"
|
||||
className="mt-2"
|
||||
>
|
||||
{discovering ? t("discoverScanning") : t("discoverButton")}
|
||||
</button>
|
||||
</Button>
|
||||
|
||||
{candidates !== null && (
|
||||
<div className="mt-3" data-testid="rtk-discover-results">
|
||||
@@ -135,23 +136,25 @@ export default function RtkLearnDiscoverCard() {
|
||||
<div>
|
||||
<h3 className="text-xs font-medium text-text-main">{t("learnHeading")}</h3>
|
||||
<div className="mt-2 flex gap-2">
|
||||
<input
|
||||
<Input
|
||||
type="text"
|
||||
value={command}
|
||||
onChange={(event) => setCommand(event.target.value)}
|
||||
placeholder={t("learnCommandPlaceholder")}
|
||||
aria-label={t("learnHeading")}
|
||||
data-testid="rtk-learn-command"
|
||||
className="min-w-0 flex-1 rounded border border-border bg-surface px-2 py-1 text-xs text-text-main"
|
||||
className="min-w-0 flex-1"
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={runLearn}
|
||||
disabled={learning || !command.trim()}
|
||||
data-testid="rtk-learn-button"
|
||||
className="shrink-0 rounded border border-border px-2.5 py-1 text-xs font-medium text-text-main hover:bg-surface-hover disabled:opacity-50"
|
||||
className="shrink-0"
|
||||
>
|
||||
{t("learnButton")}
|
||||
</button>
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{suggested === null ? (
|
||||
@@ -161,13 +164,13 @@ export default function RtkLearnDiscoverCard() {
|
||||
<p className="text-[11px] text-text-muted">
|
||||
{t("learnSamplesUsed", { count: learnCount })}
|
||||
</p>
|
||||
<pre className="mt-2 max-h-48 overflow-auto rounded bg-surface-hover p-2 text-[10px] text-text-main">
|
||||
<pre className="mt-2 max-h-48 overflow-auto rounded bg-bg-subtle p-2 text-[10px] text-text-main">
|
||||
{JSON.stringify(suggested, null, 2)}
|
||||
</pre>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,11 @@
|
||||
|
||||
import { useState } from "react";
|
||||
import { useTranslations } from "next-intl";
|
||||
import { SectionHeader } from "@omniroute/ui-kit/page-header";
|
||||
import Button from "@/shared/components/Button";
|
||||
import Card from "@/shared/components/Card";
|
||||
import Checkbox from "@/shared/components/Checkbox";
|
||||
import Textarea from "@/shared/components/Textarea";
|
||||
|
||||
const RTK_TOML_MAX_BYTES = 1024 * 1024;
|
||||
|
||||
@@ -67,51 +72,49 @@ function RtkTomlEditor({
|
||||
<div className="mt-3 flex flex-col gap-3">
|
||||
<label className="text-xs font-medium text-text-main">
|
||||
{t("tomlChooseFile")}
|
||||
{/* Native file picker: the kit has no file input; tokens style its button. */}
|
||||
<input
|
||||
type="file"
|
||||
accept=".toml,text/plain,application/toml"
|
||||
onChange={(event) => onFileChange(event.target.files?.[0])}
|
||||
data-testid="rtk-toml-file"
|
||||
className="mt-1 block w-full text-xs text-text-muted file:mr-3 file:rounded file:border file:border-border file:bg-bg file:px-2.5 file:py-1 file:text-xs file:text-text-main"
|
||||
className="mt-1 block w-full text-xs text-text-muted file:mr-3 file:rounded-control file:border file:border-border file:bg-bg-subtle file:px-2.5 file:py-1 file:text-xs file:text-text-main"
|
||||
/>
|
||||
</label>
|
||||
<textarea
|
||||
<Textarea
|
||||
value={content}
|
||||
onChange={(event) => onContentChange(event.target.value)}
|
||||
placeholder={t("tomlImportPlaceholder")}
|
||||
aria-label={t("tomlImportTitle")}
|
||||
data-testid="rtk-toml-content"
|
||||
className="h-56 w-full rounded-lg border border-border bg-bg p-3 font-mono text-xs text-text-main"
|
||||
className="h-56 w-full font-mono text-xs"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="mt-3 flex flex-wrap items-center gap-3">
|
||||
<button
|
||||
type="button"
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => onProcess("validate")}
|
||||
disabled={processing !== null || !content.trim()}
|
||||
data-testid="rtk-toml-validate"
|
||||
className="rounded border border-border px-3 py-1.5 text-xs font-medium text-text-main hover:bg-surface-hover disabled:opacity-50"
|
||||
>
|
||||
{processing === "validate" ? t("tomlValidating") : t("tomlValidate")}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
</Button>
|
||||
<Button
|
||||
size="sm"
|
||||
onClick={() => onProcess("install")}
|
||||
disabled={processing !== null || !content.trim()}
|
||||
data-testid="rtk-toml-install"
|
||||
className="rounded bg-primary px-3 py-1.5 text-xs font-medium text-accent-foreground disabled:opacity-50"
|
||||
>
|
||||
{processing === "install" ? t("tomlInstalling") : t("tomlInstall")}
|
||||
</button>
|
||||
<label className="flex items-center gap-2 text-xs text-text-main">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={overwrite}
|
||||
onChange={(event) => onOverwriteChange(event.target.checked)}
|
||||
data-testid="rtk-toml-overwrite"
|
||||
/>
|
||||
{t("tomlConfirmOverwrite")}
|
||||
</label>
|
||||
</Button>
|
||||
<Checkbox
|
||||
label={t("tomlConfirmOverwrite")}
|
||||
checked={overwrite}
|
||||
onChange={(event) => onOverwriteChange(event.target.checked)}
|
||||
data-testid="rtk-toml-overwrite"
|
||||
/>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
@@ -151,13 +154,7 @@ function RtkTomlResult({ result }: { result: ImportResult }) {
|
||||
<ul className="mt-2 space-y-1 text-[11px] text-text-main">
|
||||
{result.outcomes.map((outcome) => (
|
||||
<li key={`${outcome.filterId}:${outcome.testName}`}>
|
||||
<span
|
||||
className={
|
||||
outcome.passed
|
||||
? "text-emerald-700 dark:text-emerald-300"
|
||||
: "text-red-600 dark:text-red-400"
|
||||
}
|
||||
>
|
||||
<span className={outcome.passed ? "text-success" : "text-error"}>
|
||||
{outcome.passed ? t("tomlTestPassed") : t("tomlTestFailed")}
|
||||
</span>{" "}
|
||||
· <code>{outcome.filterId}</code> · {outcome.testName}
|
||||
@@ -166,7 +163,7 @@ function RtkTomlResult({ result }: { result: ImportResult }) {
|
||||
</ul>
|
||||
)}
|
||||
{result.warnings.length > 0 && (
|
||||
<ul className="mt-2 space-y-1 text-[11px] text-amber-700 dark:text-amber-300">
|
||||
<ul className="mt-2 space-y-1 text-[11px] text-warning">
|
||||
{result.warnings.map((warning) => (
|
||||
<li key={warning}>{warning}</li>
|
||||
))}
|
||||
@@ -224,12 +221,8 @@ export default function RtkTomlImportCard({ onInstalled }: RtkTomlImportCardProp
|
||||
}
|
||||
|
||||
return (
|
||||
<section
|
||||
className="rounded-lg border border-border bg-surface p-4"
|
||||
data-testid="rtk-toml-import"
|
||||
>
|
||||
<h2 className="text-sm font-semibold text-text-main">{t("tomlImportTitle")}</h2>
|
||||
<p className="mt-1 text-xs text-text-muted">{t("tomlImportDesc")}</p>
|
||||
<Card padding="sm" data-testid="rtk-toml-import">
|
||||
<SectionHeader title={t("tomlImportTitle")} description={t("tomlImportDesc")} />
|
||||
<RtkTomlEditor
|
||||
content={content}
|
||||
processing={processing}
|
||||
@@ -244,12 +237,12 @@ export default function RtkTomlImportCard({ onInstalled }: RtkTomlImportCardProp
|
||||
/>
|
||||
|
||||
{error && (
|
||||
<p className="mt-3 text-xs text-red-600 dark:text-red-400" data-testid="rtk-toml-error">
|
||||
<p className="mt-3 text-xs text-error" role="alert" data-testid="rtk-toml-error">
|
||||
{error}
|
||||
</p>
|
||||
)}
|
||||
|
||||
{result && <RtkTomlResult result={result} />}
|
||||
</section>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -16,6 +16,10 @@ import { useTranslations, useLocale } from "next-intl";
|
||||
// vitest/jsdom component test. Direct imports resolve identically under Next.js.
|
||||
import Button from "@/shared/components/Button";
|
||||
import Card from "@/shared/components/Card";
|
||||
import Icon from "@/shared/components/Icon";
|
||||
import Input from "@/shared/components/Input";
|
||||
import { Skeleton } from "@/shared/components/Loading";
|
||||
import Select from "@/shared/components/Select";
|
||||
import Toggle from "@/shared/components/Toggle";
|
||||
import {
|
||||
ENGINE_IDS,
|
||||
@@ -185,9 +189,11 @@ function LiveZoneToggle({
|
||||
function AutoTriggerInput({
|
||||
value,
|
||||
onCommit,
|
||||
ariaLabel,
|
||||
}: {
|
||||
value: number;
|
||||
onCommit: (tokens: number) => void;
|
||||
ariaLabel: string;
|
||||
}) {
|
||||
// The edit not saved yet, or null while the field shows the current value.
|
||||
const [draft, setDraft] = useState<string | null>(null);
|
||||
@@ -202,8 +208,10 @@ function AutoTriggerInput({
|
||||
if (tokens !== value) onCommit(tokens);
|
||||
};
|
||||
return (
|
||||
<input
|
||||
<Input
|
||||
type="number"
|
||||
aria-label={ariaLabel}
|
||||
inputClassName="h-8 min-h-8 w-24"
|
||||
min={AUTO_TRIGGER_MIN}
|
||||
max={AUTO_TRIGGER_MAX}
|
||||
value={draft ?? String(value)}
|
||||
@@ -216,7 +224,6 @@ function AutoTriggerInput({
|
||||
}
|
||||
if (e.key === "Enter") commit(e.currentTarget.value);
|
||||
}}
|
||||
className="w-24 rounded border border-border bg-surface px-2 py-1 text-sm text-text-main"
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -235,48 +242,44 @@ function AdaptiveContextBudgetDial({
|
||||
// the panel has no selected-model context here; 200k is Claude-class default.
|
||||
const target = getAdaptiveTargetSummary(contextBudget, 200000);
|
||||
return (
|
||||
<div className="mb-4 space-y-2 rounded-md border border-border/60 bg-bg-subtle px-3 py-2">
|
||||
<label className="flex items-center justify-between gap-3">
|
||||
<span className="text-sm font-medium text-text-main">{t("compressionAdaptiveMode")}</span>
|
||||
<select
|
||||
data-testid="context-budget-mode-select"
|
||||
value={contextBudget.mode ?? "off"}
|
||||
<div className="mb-4 space-y-2 rounded-md border border-border bg-bg-subtle px-3 py-2">
|
||||
<Select
|
||||
compact
|
||||
label={t("compressionAdaptiveMode")}
|
||||
selectClassName="w-44"
|
||||
data-testid="context-budget-mode-select"
|
||||
value={contextBudget.mode ?? "off"}
|
||||
onChange={(e) => {
|
||||
const mode = e.target.value;
|
||||
if (CONTEXT_BUDGET_MODES.has(mode as ContextBudgetConfig["mode"])) {
|
||||
onChange({ mode: mode as ContextBudgetConfig["mode"] });
|
||||
}
|
||||
}}
|
||||
disabled={saving}
|
||||
>
|
||||
<option value="off">{t("compressionAdaptiveModeOff")}</option>
|
||||
<option value="floor">{t("compressionAdaptiveModeFloor")}</option>
|
||||
<option value="replace-autotrigger">{t("compressionAdaptiveModeReplace")}</option>
|
||||
</Select>
|
||||
{(contextBudget.mode ?? "off") !== "off" && (
|
||||
<Select
|
||||
compact
|
||||
label={t("compressionAdaptivePolicy")}
|
||||
selectClassName="w-44"
|
||||
data-testid="context-budget-policy-select"
|
||||
value={contextBudget.policy ?? "reserve-output"}
|
||||
onChange={(e) => {
|
||||
const mode = e.target.value;
|
||||
if (CONTEXT_BUDGET_MODES.has(mode as ContextBudgetConfig["mode"])) {
|
||||
onChange({ mode: mode as ContextBudgetConfig["mode"] });
|
||||
const policy = e.target.value;
|
||||
if (CONTEXT_BUDGET_POLICIES.has(policy as ContextBudgetConfig["policy"])) {
|
||||
onChange({ policy: policy as ContextBudgetConfig["policy"] });
|
||||
}
|
||||
}}
|
||||
disabled={saving}
|
||||
className="w-44 rounded border border-border bg-surface px-2 py-1 text-sm text-text-main"
|
||||
>
|
||||
<option value="off">{t("compressionAdaptiveModeOff")}</option>
|
||||
<option value="floor">{t("compressionAdaptiveModeFloor")}</option>
|
||||
<option value="replace-autotrigger">{t("compressionAdaptiveModeReplace")}</option>
|
||||
</select>
|
||||
</label>
|
||||
{(contextBudget.mode ?? "off") !== "off" && (
|
||||
<label className="flex items-center justify-between gap-3">
|
||||
<span className="text-sm font-medium text-text-main">
|
||||
{t("compressionAdaptivePolicy")}
|
||||
</span>
|
||||
<select
|
||||
data-testid="context-budget-policy-select"
|
||||
value={contextBudget.policy ?? "reserve-output"}
|
||||
onChange={(e) => {
|
||||
const policy = e.target.value;
|
||||
if (CONTEXT_BUDGET_POLICIES.has(policy as ContextBudgetConfig["policy"])) {
|
||||
onChange({ policy: policy as ContextBudgetConfig["policy"] });
|
||||
}
|
||||
}}
|
||||
disabled={saving}
|
||||
className="w-44 rounded border border-border bg-surface px-2 py-1 text-sm text-text-main"
|
||||
>
|
||||
<option value="reserve-output">{t("compressionAdaptivePolicyReserve")}</option>
|
||||
<option value="percentage">{t("compressionAdaptivePolicyPercentage")}</option>
|
||||
<option value="absolute">{t("compressionAdaptivePolicyAbsolute")}</option>
|
||||
</select>
|
||||
</label>
|
||||
<option value="reserve-output">{t("compressionAdaptivePolicyReserve")}</option>
|
||||
<option value="percentage">{t("compressionAdaptivePolicyPercentage")}</option>
|
||||
<option value="absolute">{t("compressionAdaptivePolicyAbsolute")}</option>
|
||||
</Select>
|
||||
)}
|
||||
<div data-testid="adaptive-target-preview" className="text-xs text-text-muted">
|
||||
{target.enabled
|
||||
@@ -538,8 +541,9 @@ export default function CompressionPanel() {
|
||||
const derivedText = derivedPreviewText(derived, t);
|
||||
if (loading) {
|
||||
return (
|
||||
<Card className="p-6">
|
||||
<p className="text-sm text-text-muted">{t("loading")}</p>
|
||||
<Card className="p-6" aria-busy="true">
|
||||
<span className="ci-sr-only">{t("loading")}</span>
|
||||
<Skeleton className="h-24 w-full" />
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
@@ -548,7 +552,7 @@ export default function CompressionPanel() {
|
||||
return (
|
||||
<Card className="p-6">
|
||||
<div className="flex items-center justify-between gap-4">
|
||||
<p role="alert" className="text-sm text-red-600 dark:text-red-400">
|
||||
<p role="alert" className="text-sm text-error">
|
||||
{t("compressionTitle")}: {tCommon("failedToLoad")}
|
||||
</p>
|
||||
<Button
|
||||
@@ -571,10 +575,8 @@ export default function CompressionPanel() {
|
||||
{/* Master */}
|
||||
<div className="mb-5 flex items-start justify-between gap-4">
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="rounded-lg bg-blue-500/10 p-2 text-blue-500">
|
||||
<span className="material-symbols-outlined text-[20px]" aria-hidden="true">
|
||||
compress
|
||||
</span>
|
||||
<div className="rounded-lg bg-info/10 p-2 text-info">
|
||||
<Icon name="compress" size={20} />
|
||||
</div>
|
||||
<div>
|
||||
<h3 className="text-lg font-semibold">{t("compressionTitle")}</h3>
|
||||
@@ -587,22 +589,19 @@ export default function CompressionPanel() {
|
||||
className="mt-0.5 inline-flex items-center gap-1 text-xs text-primary hover:underline"
|
||||
>
|
||||
{t("compressionGuidanceFullGuideLink")}
|
||||
<span className="material-symbols-outlined text-[12px]" aria-hidden="true">
|
||||
open_in_new
|
||||
</span>
|
||||
<Icon name="open_in_new" size={12} />
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex items-center gap-3">
|
||||
{status === "saved" && (
|
||||
<span className="flex items-center gap-1 text-xs font-medium text-emerald-500">
|
||||
<span className="material-symbols-outlined text-[14px]">check_circle</span>{" "}
|
||||
{t("saved")}
|
||||
<span className="flex items-center gap-1 text-xs font-medium text-success">
|
||||
<Icon name="check_circle" size={14} /> {t("saved")}
|
||||
</span>
|
||||
)}
|
||||
{status === "error" && (
|
||||
<span className="flex items-center gap-1 text-xs font-medium text-red-500">
|
||||
<span className="material-symbols-outlined text-[14px]">error</span> {t("saveFailed")}
|
||||
<span className="flex items-center gap-1 text-xs font-medium text-error">
|
||||
<Icon name="error" size={14} /> {t("saveFailed")}
|
||||
</span>
|
||||
)}
|
||||
<Toggle
|
||||
@@ -618,7 +617,7 @@ export default function CompressionPanel() {
|
||||
{/* Derived pipeline preview */}
|
||||
<div
|
||||
data-testid="derived-pipeline-preview"
|
||||
className="mb-4 rounded-md border border-border/60 bg-bg-subtle px-3 py-2 text-xs text-text-muted"
|
||||
className="mb-4 rounded-md border border-border bg-bg-subtle px-3 py-2 text-xs text-text-muted"
|
||||
>
|
||||
<span className="font-medium text-text-main">{t("compressionEffectivePipeline")}</span>{" "}
|
||||
{derivedText}
|
||||
@@ -670,18 +669,19 @@ export default function CompressionPanel() {
|
||||
</div>
|
||||
<div className="flex shrink-0 items-center gap-2">
|
||||
{levels && (
|
||||
<select
|
||||
<Select
|
||||
aria-label={engineLabel}
|
||||
value={level}
|
||||
onChange={(e) => setEngine(id, { level: e.target.value })}
|
||||
disabled={!config.enabled || !engine.enabled || saving}
|
||||
className="w-28 rounded border border-border bg-surface px-2 py-1 text-xs text-text-main"
|
||||
selectClassName="ci-select-native--sm w-28 text-xs"
|
||||
>
|
||||
{levels.map((lvl) => (
|
||||
<option key={lvl} value={lvl}>
|
||||
{t(`compressionLevel.${lvl}`)}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</Select>
|
||||
)}
|
||||
<span data-testid={`engine-toggle-${id}`}>
|
||||
<Toggle
|
||||
@@ -699,7 +699,7 @@ export default function CompressionPanel() {
|
||||
</div>
|
||||
|
||||
{/* Output Styles — response-output instruction injection (Phase 4A, catalog-driven) */}
|
||||
<div className="mt-2 flex flex-col gap-3 border-t border-border/30 py-3">
|
||||
<div className="mt-2 flex flex-col gap-3 border-t border-border py-3">
|
||||
<div className="min-w-0 flex-1">
|
||||
<p className="text-sm font-medium text-text-main">
|
||||
{t("compressionSettingsOutputStyles")}
|
||||
@@ -727,21 +727,22 @@ export default function CompressionPanel() {
|
||||
{meta.description && <p className="text-xs text-text-muted">{styleDescription}</p>}
|
||||
</div>
|
||||
<div className="flex shrink-0 items-center gap-2">
|
||||
<select
|
||||
<Select
|
||||
aria-label={styleLabel}
|
||||
selectClassName="ci-select-native--sm w-28 text-xs"
|
||||
data-testid={`output-style-level-${id}`}
|
||||
value={sel?.level ?? "full"}
|
||||
onChange={(e) =>
|
||||
setOutputStyle(id, { level: e.target.value as CavemanIntensity })
|
||||
}
|
||||
disabled={!sel || saving}
|
||||
className="w-28 rounded border border-border bg-surface px-2 py-1 text-xs text-text-main"
|
||||
>
|
||||
{CAVEMAN_OUTPUT_LEVELS.map((lvl) => (
|
||||
<option key={lvl} value={lvl}>
|
||||
{t(`compressionLevel.${lvl}`)}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</Select>
|
||||
<span data-testid={`output-style-toggle-${id}`}>
|
||||
<Toggle
|
||||
size="sm"
|
||||
@@ -759,20 +760,19 @@ export default function CompressionPanel() {
|
||||
|
||||
{/* Ultra SLM tier — Phase 4 (B): pick the `ultra`-mode engine (heuristic Tier-A
|
||||
or the opt-in LLMLingua-2 SLM Tier-B) + best-effort pre-warm. */}
|
||||
<div className="mt-2 flex flex-col gap-3 border-t border-border/30 py-3">
|
||||
<label className="flex items-center justify-between">
|
||||
<span className="text-sm font-medium text-text-main">{t("compressionUltraEngine")}</span>
|
||||
<select
|
||||
data-testid="ultra-engine-select"
|
||||
value={config.ultraEngine ?? "heuristic"}
|
||||
onChange={(e) => save({ ultraEngine: e.target.value === "slm" ? "slm" : "heuristic" })}
|
||||
disabled={saving}
|
||||
className="w-44 rounded border border-border bg-surface px-2 py-1 text-sm text-text-main"
|
||||
>
|
||||
<option value="heuristic">{t("compressionUltraEngineHeuristic")}</option>
|
||||
<option value="slm">{t("compressionUltraEngineSlm")}</option>
|
||||
</select>
|
||||
</label>
|
||||
<div className="mt-2 flex flex-col gap-3 border-t border-border py-3">
|
||||
<Select
|
||||
compact
|
||||
label={t("compressionUltraEngine")}
|
||||
selectClassName="w-44"
|
||||
data-testid="ultra-engine-select"
|
||||
value={config.ultraEngine ?? "heuristic"}
|
||||
onChange={(e) => save({ ultraEngine: e.target.value === "slm" ? "slm" : "heuristic" })}
|
||||
disabled={saving}
|
||||
>
|
||||
<option value="heuristic">{t("compressionUltraEngineHeuristic")}</option>
|
||||
<option value="slm">{t("compressionUltraEngineSlm")}</option>
|
||||
</Select>
|
||||
|
||||
{config.ultraEngine === "slm" && (
|
||||
<>
|
||||
@@ -794,7 +794,7 @@ export default function CompressionPanel() {
|
||||
</div>
|
||||
|
||||
{/* mcpAccessibility — writes its own endpoint / separate store */}
|
||||
<div className="flex flex-col gap-2 border-t border-border/30 py-3 sm:flex-row sm:items-center sm:justify-between">
|
||||
<div className="flex flex-col gap-2 border-t border-border py-3 sm:flex-row sm:items-center sm:justify-between">
|
||||
<div className="min-w-0 flex-1">
|
||||
<p className="text-sm font-medium text-text-main">{t("mcpAccessibilityTitle")}</p>
|
||||
<p className="mt-0.5 text-xs text-text-muted">{t("mcpAccessibilityDescription")}</p>
|
||||
@@ -810,40 +810,40 @@ export default function CompressionPanel() {
|
||||
</div>
|
||||
|
||||
{/* General */}
|
||||
<div className="space-y-3 border-t border-border/30 pt-4">
|
||||
<div className="space-y-3 border-t border-border pt-4">
|
||||
<h4 className="text-sm font-medium text-text-main">{t("compressionGeneral")}</h4>
|
||||
<label className="flex items-center justify-between">
|
||||
<div className="flex items-center justify-between gap-3">
|
||||
<span className="text-sm text-text-muted">{t("compressionAutoTrigger")}</span>
|
||||
<div className="flex items-center gap-2">
|
||||
<AutoTriggerInput
|
||||
ariaLabel={t("compressionAutoTrigger")}
|
||||
value={config.autoTriggerTokens}
|
||||
onCommit={(autoTriggerTokens) => save({ autoTriggerTokens })}
|
||||
/>
|
||||
<span className="text-xs text-text-muted">{t("tokens")}</span>
|
||||
</div>
|
||||
</label>
|
||||
<label className="flex items-center justify-between">
|
||||
<span className="text-sm text-text-muted">{t("compressionPreserveSystem")}</span>
|
||||
<select
|
||||
value={
|
||||
config.preserveSystemPromptMode ??
|
||||
(config.preserveSystemPrompt === false ? "whenNoCache" : "always")
|
||||
}
|
||||
onChange={(e) =>
|
||||
save({
|
||||
preserveSystemPromptMode: e.target.value as "always" | "whenNoCache" | "never",
|
||||
})
|
||||
}
|
||||
disabled={saving}
|
||||
aria-label={t("compressionPreserveSystem")}
|
||||
data-testid="preserve-system-mode-select"
|
||||
className="w-36 rounded border border-border bg-surface px-2 py-1 text-sm text-text-main"
|
||||
>
|
||||
<option value="always">{t("compressionPreserveSystemAlways")}</option>
|
||||
<option value="whenNoCache">{t("compressionPreserveSystemWhenNoCache")}</option>
|
||||
<option value="never">{t("compressionPreserveSystemNever")}</option>
|
||||
</select>
|
||||
</label>
|
||||
</div>
|
||||
<Select
|
||||
compact
|
||||
label={t("compressionPreserveSystem")}
|
||||
selectClassName="w-36"
|
||||
value={
|
||||
config.preserveSystemPromptMode ??
|
||||
(config.preserveSystemPrompt === false ? "whenNoCache" : "always")
|
||||
}
|
||||
onChange={(e) =>
|
||||
save({
|
||||
preserveSystemPromptMode: e.target.value as "always" | "whenNoCache" | "never",
|
||||
})
|
||||
}
|
||||
disabled={saving}
|
||||
aria-label={t("compressionPreserveSystem")}
|
||||
data-testid="preserve-system-mode-select"
|
||||
>
|
||||
<option value="always">{t("compressionPreserveSystemAlways")}</option>
|
||||
<option value="whenNoCache">{t("compressionPreserveSystemWhenNoCache")}</option>
|
||||
<option value="never">{t("compressionPreserveSystemNever")}</option>
|
||||
</Select>
|
||||
<LiveZoneToggle
|
||||
enabled={config.liveZone?.enabled === true}
|
||||
saving={saving}
|
||||
|
||||
@@ -11,7 +11,12 @@
|
||||
// button, badge, "cache impact" label) is translated.
|
||||
|
||||
import { useTranslations } from "next-intl";
|
||||
import type { CacheImpact, EngineGuidance } from "../../../../../../open-sse/services/compression/engineCatalog.ts";
|
||||
import Badge from "@/shared/components/Badge";
|
||||
import Button from "@/shared/components/Button";
|
||||
import type {
|
||||
CacheImpact,
|
||||
EngineGuidance,
|
||||
} from "../../../../../../open-sse/services/compression/engineCatalog.ts";
|
||||
|
||||
const CACHE_IMPACT_LABEL: Record<CacheImpact, string> = {
|
||||
none: "None",
|
||||
@@ -38,27 +43,30 @@ export default function EngineGuidanceDetail({
|
||||
<div className="mt-1 flex flex-col gap-1">
|
||||
<div className="flex items-center gap-2">
|
||||
{!guidance.lossy && (
|
||||
<span
|
||||
<Badge
|
||||
size="sm"
|
||||
variant="success"
|
||||
data-testid={`engine-safe-default-${id}`}
|
||||
className="rounded border border-emerald-500/30 bg-emerald-500/10 px-1.5 py-0.5 text-[10px] font-medium uppercase tracking-wider text-emerald-500"
|
||||
className="text-[10px] uppercase tracking-wider"
|
||||
>
|
||||
{t("compressionGuidanceSafeDefault")}
|
||||
</span>
|
||||
</Badge>
|
||||
)}
|
||||
<button
|
||||
type="button"
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
data-testid={`engine-guidance-toggle-${id}`}
|
||||
onClick={onToggle}
|
||||
aria-expanded={expanded}
|
||||
className="text-[10px] uppercase tracking-wider text-primary hover:underline"
|
||||
className="h-6 min-h-6 px-1.5 text-[10px] uppercase tracking-wider text-primary"
|
||||
>
|
||||
{expanded ? t("compressionGuidanceHide") : t("compressionGuidanceShow")}
|
||||
</button>
|
||||
</Button>
|
||||
</div>
|
||||
{expanded && (
|
||||
<div
|
||||
data-testid={`engine-guidance-detail-${id}`}
|
||||
className="rounded border border-border/50 bg-bg-subtle p-2 text-xs text-text-muted"
|
||||
className="rounded border border-border bg-bg-subtle p-2 text-xs text-text-muted"
|
||||
>
|
||||
<p>{guidance.tradeoffs}</p>
|
||||
<p className="mt-1">
|
||||
|
||||
@@ -4,7 +4,21 @@ import { useEffect, useMemo, useState } from "react";
|
||||
import { useSearchParams } from "next/navigation";
|
||||
import { useLocale, useTranslations } from "next-intl";
|
||||
import { useProviderNodeMap, resolveProviderName } from "@/lib/display/useProviderNodeMap";
|
||||
import { SortableTableHead } from "@omniroute/ui-kit/data-table-shell";
|
||||
import { PageHeader } from "@omniroute/ui-kit/page-header";
|
||||
import {
|
||||
Table,
|
||||
TableBody,
|
||||
TableCell,
|
||||
TableHead,
|
||||
TableHeader,
|
||||
TableRow,
|
||||
} from "@omniroute/ui-kit/table";
|
||||
import { Card, EmptyState, SegmentedControl, CardSkeleton } from "@/shared/components";
|
||||
import Badge from "@/shared/components/Badge";
|
||||
import Button from "@/shared/components/Button";
|
||||
import Input from "@/shared/components/Input";
|
||||
import Icon from "@/shared/components/Icon";
|
||||
import {
|
||||
getServiceTierDisplayLabel,
|
||||
type TranslationFn as CostTranslationFn,
|
||||
@@ -509,37 +523,38 @@ export default function CostOverviewTab() {
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-6">
|
||||
<Card className="p-6">
|
||||
<div className="flex flex-col gap-4 lg:flex-row lg:items-end lg:justify-between">
|
||||
<div>
|
||||
<h2 className="text-xl font-bold text-text-main">{t("overviewTitle")}</h2>
|
||||
<p className="text-sm text-text-muted mt-1">{t("overviewDescription")}</p>
|
||||
</div>
|
||||
<PageHeader
|
||||
compact
|
||||
title={t("overviewTitle")}
|
||||
description={t("overviewDescription")}
|
||||
actions={
|
||||
<div className="flex flex-wrap items-center gap-3">
|
||||
{summary.streak > 0 && (
|
||||
<div className="flex items-center gap-1.5 px-3 py-1.5 rounded-full bg-amber-500/10 border border-amber-500/20">
|
||||
<span className="material-symbols-outlined text-amber-400 text-sm">
|
||||
local_fire_department
|
||||
</span>
|
||||
<span className="text-sm font-semibold text-amber-400">{summary.streak}</span>
|
||||
<span className="text-xs text-amber-400/70">{t("dayStreak")}</span>
|
||||
</div>
|
||||
<Badge variant="warning" icon={<Icon name="local_fire_department" size={14} />}>
|
||||
<span className="font-semibold">{summary.streak}</span>
|
||||
<span className="opacity-80">{t("dayStreak")}</span>
|
||||
</Badge>
|
||||
)}
|
||||
{analytics && summary.totalCost > 0 && (
|
||||
<div className="flex items-center gap-1">
|
||||
<button
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
icon="download"
|
||||
onClick={() => {
|
||||
const csv = generateCSV(analytics, locale);
|
||||
const dateStr = new Date().toISOString().slice(0, 10);
|
||||
downloadFile(csv, `omniroute-costs-${range}-${dateStr}.csv`, "text/csv");
|
||||
}}
|
||||
className="flex items-center gap-1 px-2.5 py-1.5 text-xs text-text-muted hover:text-text-main hover:bg-surface/50 rounded-lg border border-border/30 transition-colors"
|
||||
title={t("exportCSV")}
|
||||
aria-label={t("exportCSV")}
|
||||
>
|
||||
<span className="material-symbols-outlined text-sm">download</span>
|
||||
CSV
|
||||
</button>
|
||||
<button
|
||||
</Button>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
icon="download"
|
||||
onClick={() => {
|
||||
const json = generateJSON(analytics);
|
||||
const dateStr = new Date().toISOString().slice(0, 10);
|
||||
@@ -549,12 +564,11 @@ export default function CostOverviewTab() {
|
||||
"application/json"
|
||||
);
|
||||
}}
|
||||
className="flex items-center gap-1 px-2.5 py-1.5 text-xs text-text-muted hover:text-text-main hover:bg-surface/50 rounded-lg border border-border/30 transition-colors"
|
||||
title={t("exportJSON")}
|
||||
aria-label={t("exportJSON")}
|
||||
>
|
||||
<span className="material-symbols-outlined text-sm">download</span>
|
||||
JSON
|
||||
</button>
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
<SegmentedControl
|
||||
@@ -566,40 +580,40 @@ export default function CostOverviewTab() {
|
||||
onChange={(value) => setRange(value as CostRange)}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</Card>
|
||||
}
|
||||
/>
|
||||
|
||||
<div className="grid grid-cols-2 lg:grid-cols-4 gap-3">
|
||||
<MetricCard
|
||||
label={t("spendToday")}
|
||||
value={formatCurrencyCost(locale, presetCosts["1d"] || 0)}
|
||||
loading={summaryLoading}
|
||||
color="text-emerald-400"
|
||||
color="text-chart-4"
|
||||
/>
|
||||
<MetricCard
|
||||
label={t("spend7d")}
|
||||
value={formatCurrencyCost(locale, presetCosts["7d"] || 0)}
|
||||
loading={summaryLoading}
|
||||
color="text-sky-400"
|
||||
color="text-chart-2"
|
||||
/>
|
||||
<MetricCard
|
||||
label={t("spend30d")}
|
||||
value={formatCurrencyCost(locale, presetCosts["30d"] || 0)}
|
||||
loading={summaryLoading}
|
||||
color="text-violet-400"
|
||||
color="text-chart-3"
|
||||
/>
|
||||
<MetricCard
|
||||
label={t("selectedWindow")}
|
||||
value={formatCurrencyCost(locale, summary.totalCost || 0)}
|
||||
subValue={selectedRangeLabel}
|
||||
color="text-amber-400"
|
||||
color="text-chart-5"
|
||||
/>
|
||||
</div>
|
||||
|
||||
{includesFlatRateEstimates && (
|
||||
<div className="flex items-start gap-2 rounded-lg border border-amber-500/20 bg-amber-500/5 px-4 py-3">
|
||||
<span className="material-symbols-outlined text-amber-400 text-base leading-5">info</span>
|
||||
<p className="text-xs text-amber-300/90">{t("flatRateEstimateNotice")}</p>
|
||||
<div className="flex items-start gap-2 rounded-lg border border-warning/20 bg-warning-bg px-4 py-3">
|
||||
<Icon name="info" size={16} className="mt-0.5 text-warning" />
|
||||
<p className="text-xs text-warning">{t("flatRateEstimateNotice")}</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
@@ -691,7 +705,7 @@ export default function CostOverviewTab() {
|
||||
{t("routingEfficiency")}
|
||||
</h3>
|
||||
<div className="grid grid-cols-2 xl:grid-cols-3 gap-4">
|
||||
<div className="rounded-lg border border-border/20 bg-surface/20 px-4 py-3">
|
||||
<div className="rounded-lg border border-border bg-bg-subtle px-4 py-3">
|
||||
<p className="text-xs uppercase tracking-wide text-text-muted font-semibold">
|
||||
{t("fallbackCount")}
|
||||
</p>
|
||||
@@ -704,7 +718,7 @@ export default function CostOverviewTab() {
|
||||
})}
|
||||
</p>
|
||||
</div>
|
||||
<div className="rounded-lg border border-border/20 bg-surface/20 px-4 py-3">
|
||||
<div className="rounded-lg border border-border bg-bg-subtle px-4 py-3">
|
||||
<p className="text-xs uppercase tracking-wide text-text-muted font-semibold">
|
||||
{t("fallbackRate")}
|
||||
</p>
|
||||
@@ -712,30 +726,28 @@ export default function CostOverviewTab() {
|
||||
<p
|
||||
className={`text-lg font-semibold ${
|
||||
(summary.fallbackRatePct || 0) > 10
|
||||
? "text-red-400"
|
||||
? "text-error"
|
||||
: (summary.fallbackRatePct || 0) > 5
|
||||
? "text-amber-400"
|
||||
: "text-emerald-400"
|
||||
? "text-warning"
|
||||
: "text-success"
|
||||
}`}
|
||||
>
|
||||
{(summary.fallbackRatePct || 0).toFixed(1)}%
|
||||
</p>
|
||||
<span
|
||||
className="material-symbols-outlined text-sm"
|
||||
style={{
|
||||
color:
|
||||
(summary.fallbackRatePct || 0) > 10
|
||||
? "#f87171"
|
||||
: (summary.fallbackRatePct || 0) > 5
|
||||
? "#fbbf24"
|
||||
: "#34d399",
|
||||
}}
|
||||
>
|
||||
{(summary.fallbackRatePct || 0) > 5 ? "warning" : "check_circle"}
|
||||
</span>
|
||||
<Icon
|
||||
name={(summary.fallbackRatePct || 0) > 5 ? "warning" : "check_circle"}
|
||||
size={16}
|
||||
className={
|
||||
(summary.fallbackRatePct || 0) > 10
|
||||
? "text-error"
|
||||
: (summary.fallbackRatePct || 0) > 5
|
||||
? "text-warning"
|
||||
: "text-success"
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div className="rounded-lg border border-border/20 bg-surface/20 px-4 py-3">
|
||||
<div className="rounded-lg border border-border bg-bg-subtle px-4 py-3">
|
||||
<p className="text-xs uppercase tracking-wide text-text-muted font-semibold">
|
||||
{t("modelCoverage")}
|
||||
</p>
|
||||
@@ -752,13 +764,13 @@ export default function CostOverviewTab() {
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
<Card className="p-5">
|
||||
<div className="flex items-center gap-2 mb-3">
|
||||
<span className="material-symbols-outlined text-sky-400 text-lg">trending_up</span>
|
||||
<Icon name="trending_up" size={18} className="text-info" />
|
||||
<h3 className="text-sm font-semibold text-text-muted uppercase tracking-wide">
|
||||
{t("monthlyForecast")}
|
||||
</h3>
|
||||
</div>
|
||||
<div className="flex items-end gap-3">
|
||||
<p className="text-3xl font-bold text-sky-400">
|
||||
<p className="text-3xl font-bold text-info">
|
||||
{currencyFormatter.format(projectedMonthEnd)}
|
||||
</p>
|
||||
<p className="text-xs text-text-muted pb-1">
|
||||
@@ -772,15 +784,13 @@ export default function CostOverviewTab() {
|
||||
<span>{t("daysRemaining", { days: daysRemainingInMonth })}</span>
|
||||
</div>
|
||||
{includesFlatRateEstimates && (
|
||||
<p className="mt-2 text-xs text-amber-300/90">{t("flatRateEstimateForecast")}</p>
|
||||
<p className="mt-2 text-xs text-warning">{t("flatRateEstimateForecast")}</p>
|
||||
)}
|
||||
</Card>
|
||||
|
||||
<Card className="p-5">
|
||||
<div className="flex items-center gap-2 mb-3">
|
||||
<span className="material-symbols-outlined text-violet-400 text-lg">
|
||||
compare_arrows
|
||||
</span>
|
||||
<Icon name="compare_arrows" size={18} className="text-chart-3" />
|
||||
<h3 className="text-sm font-semibold text-text-muted uppercase tracking-wide">
|
||||
{t("periodComparison")}
|
||||
</h3>
|
||||
@@ -789,30 +799,32 @@ export default function CostOverviewTab() {
|
||||
<p
|
||||
className={`text-3xl font-bold ${
|
||||
costChangePct > 0
|
||||
? "text-red-400"
|
||||
? "text-error"
|
||||
: costChangePct < 0
|
||||
? "text-emerald-400"
|
||||
? "text-success"
|
||||
: "text-text-main"
|
||||
}`}
|
||||
>
|
||||
{costChangePct > 0 ? "+" : ""}
|
||||
{costChangePct.toFixed(1)}%
|
||||
</p>
|
||||
<span
|
||||
className={`material-symbols-outlined text-lg pb-1 ${
|
||||
<Icon
|
||||
name={
|
||||
costChangePct > 0
|
||||
? "text-red-400"
|
||||
? "arrow_upward"
|
||||
: costChangePct < 0
|
||||
? "text-emerald-400"
|
||||
? "arrow_downward"
|
||||
: "remove"
|
||||
}
|
||||
size={18}
|
||||
className={`mb-1 ${
|
||||
costChangePct > 0
|
||||
? "text-error"
|
||||
: costChangePct < 0
|
||||
? "text-success"
|
||||
: "text-text-muted"
|
||||
}`}
|
||||
>
|
||||
{costChangePct > 0
|
||||
? "arrow_upward"
|
||||
: costChangePct < 0
|
||||
? "arrow_downward"
|
||||
: "remove"}
|
||||
</span>
|
||||
/>
|
||||
</div>
|
||||
<div className="mt-3 grid grid-cols-2 gap-3 text-xs">
|
||||
<div className="text-text-muted">
|
||||
@@ -1005,11 +1017,6 @@ function CostExplorerCard({
|
||||
[t]
|
||||
);
|
||||
|
||||
function renderSortIcon(columnKey: CostExplorerSortKey) {
|
||||
if (sortKey !== columnKey) return "unfold_more";
|
||||
return sortDirection === "asc" ? "arrow_upward" : "arrow_downward";
|
||||
}
|
||||
|
||||
function formatCost(value: number): string {
|
||||
if (!hasCostData && value <= 0) return t("legacyOrFree");
|
||||
return formatCurrencyCost(locale, value);
|
||||
@@ -1030,9 +1037,7 @@ function CostExplorerCard({
|
||||
<div className="flex flex-col gap-4 lg:flex-row lg:items-start lg:justify-between mb-5">
|
||||
<div>
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="material-symbols-outlined text-emerald-400 text-xl">
|
||||
travel_explore
|
||||
</span>
|
||||
<Icon name="travel_explore" size={20} className="text-success" />
|
||||
<h3 className="text-lg font-bold text-text-main">{t("costExplorerTitle")}</h3>
|
||||
</div>
|
||||
<p className="text-sm text-text-muted mt-1">{t("costExplorerDescription")}</p>
|
||||
@@ -1043,23 +1048,19 @@ function CostExplorerCard({
|
||||
value={groupBy}
|
||||
onChange={(value) => onGroupByChange(value as CostExplorerGroupBy)}
|
||||
/>
|
||||
<label className="relative block min-w-55">
|
||||
<span className="material-symbols-outlined pointer-events-none absolute left-3 top-1/2 -translate-y-1/2 text-sm text-text-muted">
|
||||
search
|
||||
</span>
|
||||
<input
|
||||
value={searchQuery}
|
||||
onChange={(event) => onSearchChange(event.target.value)}
|
||||
placeholder={t("filterRows")}
|
||||
className="w-full rounded-lg border border-border/40 bg-surface/40 py-2 pl-9 pr-3 text-sm text-text-main placeholder:text-text-muted focus:border-primary focus:outline-none"
|
||||
aria-label={t("filterCostExplorerRows")}
|
||||
/>
|
||||
</label>
|
||||
<Input
|
||||
icon="search"
|
||||
value={searchQuery}
|
||||
onChange={(event) => onSearchChange(event.target.value)}
|
||||
placeholder={t("filterRows")}
|
||||
aria-label={t("filterCostExplorerRows")}
|
||||
className="min-w-55"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{rows.length === 0 ? (
|
||||
<div className="rounded-xl border border-border/30 bg-surface/20 p-6">
|
||||
<div className="rounded-xl border border-border bg-bg-subtle p-6">
|
||||
<EmptyState
|
||||
icon="manage_search"
|
||||
title={t("noMatchingCostRows")}
|
||||
@@ -1068,78 +1069,67 @@ function CostExplorerCard({
|
||||
</div>
|
||||
) : (
|
||||
<>
|
||||
<div className="overflow-x-auto">
|
||||
<table className="w-full min-w-205 text-sm">
|
||||
<thead>
|
||||
<tr className="border-b border-border/30 text-[11px] uppercase text-text-muted">
|
||||
{columns.map((column) => (
|
||||
<th
|
||||
key={column.key}
|
||||
className={`pb-2 font-semibold ${
|
||||
column.align === "right" ? "text-right" : "text-left"
|
||||
}`}
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => onSort(column.key)}
|
||||
className={`inline-flex items-center gap-1 hover:text-text-main ${
|
||||
column.align === "right" ? "justify-end" : "justify-start"
|
||||
}`}
|
||||
>
|
||||
<span>{column.label}</span>
|
||||
<span className="material-symbols-outlined text-sm">
|
||||
{renderSortIcon(column.key)}
|
||||
</span>
|
||||
</button>
|
||||
</th>
|
||||
))}
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody className="divide-y divide-border/20">
|
||||
{rows.map((row) => (
|
||||
<tr key={row.id} className="hover:bg-surface/20">
|
||||
<td className="py-3 pr-4">
|
||||
<div className="flex flex-col">
|
||||
<span className="font-medium text-text-main">{row.name}</span>
|
||||
{row.detail ? (
|
||||
<span className="text-xs text-text-muted truncate max-w-[320px]">
|
||||
{row.detail}
|
||||
</span>
|
||||
) : null}
|
||||
</div>
|
||||
</td>
|
||||
<td className="py-3 text-right font-mono text-text-muted">
|
||||
{formatCost(row.cost)}
|
||||
</td>
|
||||
<td className="py-3 text-right font-mono text-text-muted">
|
||||
{numberFormatter.format(row.requests)}
|
||||
</td>
|
||||
<td className="py-3 text-right font-mono text-text-muted">
|
||||
{compactFormatter.format(row.totalTokens)}
|
||||
</td>
|
||||
<td className="py-3 text-right font-mono text-text-muted">
|
||||
{row.avgCostPerRequest > 0
|
||||
? currencyFormatter.format(row.avgCostPerRequest)
|
||||
: "—"}
|
||||
</td>
|
||||
<td className="py-3 text-right">
|
||||
<div className="flex items-center justify-end gap-2">
|
||||
<div className="h-1.5 w-16 overflow-hidden rounded-full bg-surface/60">
|
||||
<div
|
||||
className="h-full rounded-full bg-emerald-400"
|
||||
style={{ width: `${Math.min(Math.max(row.sharePct, 0), 100)}%` }}
|
||||
/>
|
||||
</div>
|
||||
<span className="w-12 font-mono text-text-muted">
|
||||
{row.sharePct.toFixed(1)}%
|
||||
</span>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<Table scrollbarLabel={t("costExplorerTitle")} className="min-w-205">
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
{columns.map((column) => (
|
||||
<SortableTableHead
|
||||
key={column.key}
|
||||
align={column.align}
|
||||
direction={sortKey === column.key ? sortDirection : undefined}
|
||||
defaultDirection={column.key === "name" ? "asc" : "desc"}
|
||||
// handleExplorerSort owns the flip rule; the kit renders the control.
|
||||
onDirectionChange={() => onSort(column.key)}
|
||||
>
|
||||
{column.label}
|
||||
</SortableTableHead>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{rows.map((row) => (
|
||||
<TableRow key={row.id}>
|
||||
<TableCell className="pr-4">
|
||||
<div className="flex flex-col">
|
||||
<span className="font-medium text-text-main">{row.name}</span>
|
||||
{row.detail ? (
|
||||
<span className="max-w-[320px] truncate text-xs text-text-muted">
|
||||
{row.detail}
|
||||
</span>
|
||||
) : null}
|
||||
</div>
|
||||
</TableCell>
|
||||
<TableCell className="text-right font-mono text-text-muted">
|
||||
{formatCost(row.cost)}
|
||||
</TableCell>
|
||||
<TableCell className="text-right font-mono text-text-muted">
|
||||
{numberFormatter.format(row.requests)}
|
||||
</TableCell>
|
||||
<TableCell className="text-right font-mono text-text-muted">
|
||||
{compactFormatter.format(row.totalTokens)}
|
||||
</TableCell>
|
||||
<TableCell className="text-right font-mono text-text-muted">
|
||||
{row.avgCostPerRequest > 0
|
||||
? currencyFormatter.format(row.avgCostPerRequest)
|
||||
: "—"}
|
||||
</TableCell>
|
||||
<TableCell className="text-right">
|
||||
<div className="flex items-center justify-end gap-2">
|
||||
<div className="h-1.5 w-16 overflow-hidden rounded-full bg-border/60">
|
||||
<div
|
||||
className="h-full rounded-full bg-success"
|
||||
style={{ width: `${Math.min(Math.max(row.sharePct, 0), 100)}%` }}
|
||||
/>
|
||||
</div>
|
||||
<span className="w-12 font-mono text-text-muted">
|
||||
{row.sharePct.toFixed(1)}%
|
||||
</span>
|
||||
</div>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
</TableBody>
|
||||
</Table>
|
||||
<p className="mt-3 text-xs text-text-muted">{formatRowCount()}</p>
|
||||
</>
|
||||
)}
|
||||
@@ -1149,7 +1139,7 @@ function CostExplorerCard({
|
||||
|
||||
function CompactMetric({ label, value }: { label: string; value: string }) {
|
||||
return (
|
||||
<div className="rounded-lg border border-border/20 bg-surface/20 px-4 py-3">
|
||||
<div className="rounded-lg border border-border bg-bg-subtle px-4 py-3">
|
||||
<p className="text-xs uppercase tracking-wide text-text-muted font-semibold">{label}</p>
|
||||
<p className="text-lg font-semibold text-text-main mt-1">{value}</p>
|
||||
</div>
|
||||
@@ -1184,12 +1174,12 @@ function ActivityHeatmap({
|
||||
|
||||
const maxValue = Math.max(...days.map((day) => day.value), 1);
|
||||
const getIntensity = (value: number): string => {
|
||||
if (value === 0) return "bg-surface/30";
|
||||
if (value === 0) return "bg-border/50";
|
||||
const ratio = value / maxValue;
|
||||
if (ratio < 0.25) return "bg-emerald-900/50";
|
||||
if (ratio < 0.5) return "bg-emerald-700/60";
|
||||
if (ratio < 0.75) return "bg-emerald-500/70";
|
||||
return "bg-emerald-400";
|
||||
if (ratio < 0.25) return "bg-success/25";
|
||||
if (ratio < 0.5) return "bg-success/45";
|
||||
if (ratio < 0.75) return "bg-success/70";
|
||||
return "bg-success";
|
||||
};
|
||||
|
||||
const weeks: Array<Array<{ date: string; value: number }>> = [];
|
||||
@@ -1224,11 +1214,11 @@ function ActivityHeatmap({
|
||||
<div className="flex items-center gap-2 mt-3 text-[10px] text-text-muted">
|
||||
<span>{lessLabel}</span>
|
||||
<div className="flex gap-0.5">
|
||||
<div className="w-2.5 h-2.5 rounded-xs bg-surface/30" />
|
||||
<div className="w-2.5 h-2.5 rounded-xs bg-emerald-900/50" />
|
||||
<div className="w-2.5 h-2.5 rounded-xs bg-emerald-700/60" />
|
||||
<div className="w-2.5 h-2.5 rounded-xs bg-emerald-500/70" />
|
||||
<div className="w-2.5 h-2.5 rounded-xs bg-emerald-400" />
|
||||
<div className="w-2.5 h-2.5 rounded-xs bg-border/50" />
|
||||
<div className="w-2.5 h-2.5 rounded-xs bg-success/25" />
|
||||
<div className="w-2.5 h-2.5 rounded-xs bg-success/45" />
|
||||
<div className="w-2.5 h-2.5 rounded-xs bg-success/70" />
|
||||
<div className="w-2.5 h-2.5 rounded-xs bg-success" />
|
||||
</div>
|
||||
<span>{moreLabel}</span>
|
||||
</div>
|
||||
@@ -1277,42 +1267,38 @@ function CostBreakdownTable({
|
||||
<h3 className="text-sm font-semibold text-text-muted uppercase tracking-wide mb-4">
|
||||
{title}
|
||||
</h3>
|
||||
<div className="overflow-x-auto">
|
||||
<table className="w-full text-sm">
|
||||
<thead>
|
||||
<tr className="text-[11px] text-text-muted uppercase border-b border-border/30">
|
||||
{columns.map((column) => (
|
||||
<th
|
||||
key={column.key}
|
||||
className={`pb-2 font-semibold ${
|
||||
column.align === "right" ? "text-right" : "text-left"
|
||||
}`}
|
||||
>
|
||||
{column.label}
|
||||
</th>
|
||||
))}
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody className="divide-y divide-border/20">
|
||||
{rows.map((row) => (
|
||||
<tr key={String(row[columns[0].key])} className="hover:bg-surface/20">
|
||||
{columns.map((column) => (
|
||||
<td
|
||||
key={column.key}
|
||||
className={`py-2 ${
|
||||
column.align === "right"
|
||||
? "text-right font-mono text-text-muted"
|
||||
: "text-left text-text-main truncate max-w-50"
|
||||
}`}
|
||||
>
|
||||
{formatValue(row[column.key], column.format)}
|
||||
</td>
|
||||
))}
|
||||
</tr>
|
||||
<Table scrollbarLabel={title}>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
{columns.map((column) => (
|
||||
<TableHead
|
||||
key={column.key}
|
||||
className={column.align === "right" ? "text-right" : "text-left"}
|
||||
>
|
||||
{column.label}
|
||||
</TableHead>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{rows.map((row) => (
|
||||
<TableRow key={String(row[columns[0].key])}>
|
||||
{columns.map((column) => (
|
||||
<TableCell
|
||||
key={column.key}
|
||||
className={
|
||||
column.align === "right"
|
||||
? "text-right font-mono text-text-muted"
|
||||
: "max-w-50 truncate text-left text-text-main"
|
||||
}
|
||||
>
|
||||
{formatValue(row[column.key], column.format)}
|
||||
</TableCell>
|
||||
))}
|
||||
</TableRow>
|
||||
))}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
|
||||
import { useMemo, useState } from "react";
|
||||
import { useTranslations } from "next-intl";
|
||||
import { Card } from "@/shared/components";
|
||||
import { Button, Card, Input, Toggle } from "@/shared/components";
|
||||
import Icon from "@/shared/components/Icon";
|
||||
|
||||
export interface ApiKeyUsageLimitPayload {
|
||||
key: {
|
||||
@@ -63,7 +64,7 @@ function formatResetHint(resetAtIso: string | null, t: ReturnType<typeof useTran
|
||||
|
||||
function UsageQuotaMetric({ label, value }: { label: string; value: string }) {
|
||||
return (
|
||||
<div className="rounded-lg border border-border/20 bg-surface/20 px-4 py-3">
|
||||
<div className="rounded-lg border border-border bg-bg-subtle px-4 py-3">
|
||||
<p className="text-xs uppercase tracking-wide text-text-muted font-semibold">{label}</p>
|
||||
<p className="text-lg font-semibold text-text-main mt-1">{value}</p>
|
||||
</div>
|
||||
@@ -127,35 +128,27 @@ export function ApiKeyUsageLimitCard({
|
||||
};
|
||||
|
||||
return (
|
||||
<Card className="p-5 border-emerald-500/20">
|
||||
<Card className="p-5 border-success/20">
|
||||
<div className="flex flex-col gap-4 lg:flex-row lg:items-start lg:justify-between">
|
||||
<div className="min-w-0">
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="material-symbols-outlined text-emerald-400 text-lg">paid</span>
|
||||
<Icon name="paid" size={18} className="text-success" />
|
||||
<h3 className="text-sm font-semibold text-text-main">{t("apiKeyUsdQuota")}</h3>
|
||||
{payload?.key.name && (
|
||||
<span className="truncate rounded bg-surface px-2 py-0.5 text-xs text-text-muted">
|
||||
<span className="truncate rounded bg-bg-subtle px-2 py-0.5 text-xs text-text-muted">
|
||||
{payload.key.name}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
<p className="mt-1 text-xs text-text-muted">{t("apiKeyUsdQuotaDescription")}</p>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
role="switch"
|
||||
aria-checked={enabled}
|
||||
<Toggle
|
||||
checked={enabled}
|
||||
onChange={(next) => setEnabled(next)}
|
||||
disabled={loading || !payload}
|
||||
onClick={() => setEnabled((prev) => !prev)}
|
||||
className={`inline-flex shrink-0 items-center justify-center gap-1.5 rounded-md border px-3 py-2 text-xs font-semibold transition-colors ${
|
||||
enabled
|
||||
? "border-emerald-500/30 bg-emerald-500/15 text-emerald-700 dark:text-emerald-300"
|
||||
: "border-border bg-black/5 text-text-muted dark:bg-white/5"
|
||||
} ${loading || !payload ? "opacity-50" : ""}`}
|
||||
>
|
||||
<span className="material-symbols-outlined text-[14px]">paid</span>
|
||||
{enabled ? t("enabled") : t("disabled")}
|
||||
</button>
|
||||
label={enabled ? t("enabled") : t("disabled")}
|
||||
className="shrink-0"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="mt-4 grid gap-3 md:grid-cols-2 xl:grid-cols-4">
|
||||
@@ -167,52 +160,46 @@ export function ApiKeyUsageLimitCard({
|
||||
label={t("weeklySpend")}
|
||||
value={loading || !status ? "..." : formatter.format(status.weeklySpentUsd)}
|
||||
/>
|
||||
<div className="rounded-lg border border-border/20 bg-surface/20 px-4 py-3">
|
||||
<label className="text-xs uppercase tracking-wide text-text-muted font-semibold">
|
||||
{t("dailyQuota")}
|
||||
</label>
|
||||
<input
|
||||
<div className="rounded-lg border border-border bg-bg-subtle px-4 py-3">
|
||||
<Input
|
||||
type="number"
|
||||
min={0}
|
||||
step="0.01"
|
||||
label={t("dailyQuota")}
|
||||
value={dailyLimit}
|
||||
onChange={(event) => setDailyLimit(event.target.value)}
|
||||
className="mt-2 w-full rounded-md border border-border bg-background px-2 py-1.5 text-sm text-text-main"
|
||||
placeholder="0.00"
|
||||
/>
|
||||
</div>
|
||||
<div className="rounded-lg border border-border/20 bg-surface/20 px-4 py-3">
|
||||
<label className="text-xs uppercase tracking-wide text-text-muted font-semibold">
|
||||
{t("weeklyQuota")}
|
||||
</label>
|
||||
<input
|
||||
<div className="rounded-lg border border-border bg-bg-subtle px-4 py-3">
|
||||
<Input
|
||||
type="number"
|
||||
min={0}
|
||||
step="0.01"
|
||||
label={t("weeklyQuota")}
|
||||
value={weeklyLimit}
|
||||
onChange={(event) => setWeeklyLimit(event.target.value)}
|
||||
className="mt-2 w-full rounded-md border border-border bg-background px-2 py-1.5 text-sm text-text-main"
|
||||
placeholder="0.00"
|
||||
hint={formatResetHint(status?.weeklyResetAtIso ?? null, t)}
|
||||
/>
|
||||
<p className="mt-1 text-[10px] text-text-muted">
|
||||
{formatResetHint(status?.weeklyResetAtIso ?? null, t)}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{error && <p className="mt-3 text-xs text-red-500">{error}</p>}
|
||||
{error && (
|
||||
<p className="mt-3 text-xs text-error" role="alert">
|
||||
{error}
|
||||
</p>
|
||||
)}
|
||||
<div className="mt-4 flex justify-end">
|
||||
<button
|
||||
type="button"
|
||||
<Button
|
||||
size="sm"
|
||||
icon="save"
|
||||
onClick={handleSave}
|
||||
loading={saving}
|
||||
disabled={saving || loading || !payload}
|
||||
className="inline-flex items-center gap-1.5 rounded-md bg-primary px-3 py-2 text-xs font-semibold text-accent-foreground transition-colors hover:bg-primary/90 disabled:opacity-50"
|
||||
>
|
||||
<span className="material-symbols-outlined text-[14px]">
|
||||
{saving ? "hourglass_empty" : "save"}
|
||||
</span>
|
||||
{saving ? t("saving") : t("saveQuota")}
|
||||
</button>
|
||||
</Button>
|
||||
</div>
|
||||
</Card>
|
||||
);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
"use client";
|
||||
|
||||
import { Card } from "@/shared/components";
|
||||
import { CHART_SERIES, getSeriesColor } from "@/shared/components/analytics/chartColors";
|
||||
import {
|
||||
ResponsiveContainer,
|
||||
PieChart,
|
||||
@@ -16,17 +17,6 @@ import {
|
||||
Bar,
|
||||
} from "recharts";
|
||||
|
||||
const CHART_COLORS = [
|
||||
"#10b981",
|
||||
"#06b6d4",
|
||||
"#f59e0b",
|
||||
"#8b5cf6",
|
||||
"#ef4444",
|
||||
"#14b8a6",
|
||||
"#6366f1",
|
||||
"#ec4899",
|
||||
];
|
||||
|
||||
function createCurrencyFormatter(locale: string) {
|
||||
return new Intl.NumberFormat(locale, {
|
||||
style: "currency",
|
||||
@@ -61,7 +51,7 @@ export function ProviderSpendCard({
|
||||
const chartRows = rows.slice(0, 6).map((row, index) => ({
|
||||
name: row.provider,
|
||||
value: row.cost,
|
||||
fill: CHART_COLORS[index % CHART_COLORS.length],
|
||||
fill: getSeriesColor(index),
|
||||
}));
|
||||
|
||||
return (
|
||||
@@ -142,16 +132,16 @@ export function CostTrendCard({
|
||||
<div className="h-55">
|
||||
<ResponsiveContainer width="100%" height="100%">
|
||||
<LineChart data={chartRows} margin={{ top: 5, right: 12, left: 0, bottom: 0 }}>
|
||||
<CartesianGrid stroke="rgba(255,255,255,0.06)" vertical={false} />
|
||||
<CartesianGrid stroke="var(--ci-color-border-subtle)" vertical={false} />
|
||||
<XAxis
|
||||
dataKey="date"
|
||||
tick={{ fontSize: 10, fill: "var(--text-muted)" }}
|
||||
tick={{ fontSize: 10, fill: "var(--color-text-muted)" }}
|
||||
axisLine={false}
|
||||
tickLine={false}
|
||||
interval={Math.max(Math.floor(chartRows.length / 8), 0)}
|
||||
/>
|
||||
<YAxis
|
||||
tick={{ fontSize: 10, fill: "var(--text-muted)" }}
|
||||
tick={{ fontSize: 10, fill: "var(--color-text-muted)" }}
|
||||
axisLine={false}
|
||||
tickLine={false}
|
||||
tickFormatter={(value) => currencyFormatter.format(value).replace(".00", "")}
|
||||
@@ -170,7 +160,7 @@ export function CostTrendCard({
|
||||
<Line
|
||||
type="monotone"
|
||||
dataKey="cost"
|
||||
stroke="#10b981"
|
||||
stroke={CHART_SERIES.cost}
|
||||
strokeWidth={2.5}
|
||||
dot={false}
|
||||
activeDot={{ r: 4 }}
|
||||
@@ -208,12 +198,12 @@ export function WeeklyPatternCard({
|
||||
<BarChart data={chartData} margin={{ top: 5, right: 5, left: 0, bottom: 0 }}>
|
||||
<XAxis
|
||||
dataKey="day"
|
||||
tick={{ fontSize: 11, fill: "var(--text-muted)" }}
|
||||
tick={{ fontSize: 11, fill: "var(--color-text-muted)" }}
|
||||
axisLine={false}
|
||||
tickLine={false}
|
||||
/>
|
||||
<YAxis
|
||||
tick={{ fontSize: 10, fill: "var(--text-muted)" }}
|
||||
tick={{ fontSize: 10, fill: "var(--color-text-muted)" }}
|
||||
axisLine={false}
|
||||
tickLine={false}
|
||||
tickFormatter={(value) =>
|
||||
@@ -235,7 +225,7 @@ export function WeeklyPatternCard({
|
||||
boxShadow: "var(--shadow-soft)",
|
||||
}}
|
||||
/>
|
||||
<Bar dataKey="tokens" fill="#8b5cf6" radius={[4, 4, 0, 0]} />
|
||||
<Bar dataKey="tokens" fill="var(--color-chart-3)" radius={[4, 4, 0, 0]} />
|
||||
</BarChart>
|
||||
</ResponsiveContainer>
|
||||
</div>
|
||||
|
||||
@@ -40,7 +40,7 @@ export function TopListCard({
|
||||
{rows.slice(0, 6).map((row) => (
|
||||
<div
|
||||
key={String(row[nameKey])}
|
||||
className="flex items-center justify-between gap-3 rounded-lg border border-border/20 bg-surface/20 px-4 py-3"
|
||||
className="flex items-center justify-between gap-3 rounded-lg border border-border bg-bg-subtle px-4 py-3"
|
||||
>
|
||||
<span className="text-sm text-text-main truncate">{String(row[nameKey])}</span>
|
||||
<div className="flex items-center gap-3 shrink-0">
|
||||
|
||||
@@ -2,7 +2,14 @@
|
||||
|
||||
import { useCallback, useEffect, useMemo, useState } from "react";
|
||||
import { useTranslations } from "next-intl";
|
||||
import { Alert } from "@omniroute/ui-kit/alert";
|
||||
import { PageHeader } from "@omniroute/ui-kit/page-header";
|
||||
import { Button } from "@/shared/components";
|
||||
import EmptyState from "@/shared/components/EmptyState";
|
||||
import Input from "@/shared/components/Input";
|
||||
import { Skeleton } from "@/shared/components/Loading";
|
||||
import Select from "@/shared/components/Select";
|
||||
import Icon from "@/shared/components/Icon";
|
||||
import useEmailPrivacyStore from "@/store/emailPrivacyStore";
|
||||
import { maskEmailLikeValue } from "@/shared/utils/maskEmail";
|
||||
import type { QuotaPool } from "@/lib/quota/dimensions";
|
||||
@@ -65,14 +72,14 @@ function StatCard({
|
||||
}) {
|
||||
const color =
|
||||
tone === "amber"
|
||||
? "text-amber-400"
|
||||
? "text-warning"
|
||||
: tone === "red"
|
||||
? "text-red-400"
|
||||
? "text-error"
|
||||
: tone === "green"
|
||||
? "text-emerald-400"
|
||||
? "text-success"
|
||||
: "text-text-main";
|
||||
return (
|
||||
<div className="rounded-lg border border-border/40 bg-bg-subtle/30 px-4 py-3">
|
||||
<div className="rounded-lg border border-border bg-bg-subtle px-4 py-3">
|
||||
<div className="text-[10px] uppercase tracking-wide text-text-muted font-semibold">
|
||||
{label}
|
||||
</div>
|
||||
@@ -413,69 +420,64 @@ export default function QuotaSharePageClient() {
|
||||
<div className="flex flex-col gap-4">
|
||||
{/* Falha ao remover: dispensável, mas nunca silenciosa. */}
|
||||
{removeError && (
|
||||
<div
|
||||
role="alert"
|
||||
className="flex items-start gap-2 rounded-lg border border-red-500/40 bg-red-500/10 px-3 py-2 text-[12px] text-red-700 dark:text-red-200"
|
||||
>
|
||||
<span className="material-symbols-outlined text-[16px] text-red-500 shrink-0">error</span>
|
||||
<span className="flex-1">{removeError}</span>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setRemoveError(null)}
|
||||
aria-label={t("dismiss")}
|
||||
className="shrink-0 text-red-500 hover:text-red-400 cursor-pointer"
|
||||
>
|
||||
<span className="material-symbols-outlined text-[16px]">close</span>
|
||||
</button>
|
||||
</div>
|
||||
<Alert
|
||||
variant="critical"
|
||||
icon={<Icon name="error" size={16} />}
|
||||
dismissLabel={t("dismiss")}
|
||||
onDismiss={() => setRemoveError(null)}
|
||||
description={removeError}
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* Header */}
|
||||
<div className="flex items-start justify-between flex-wrap gap-3">
|
||||
<div>
|
||||
<h1 className="text-xl font-bold text-text-main flex items-center gap-2">
|
||||
<span className="material-symbols-outlined text-[24px] text-primary">pie_chart</span>
|
||||
<PageHeader
|
||||
compact
|
||||
title={
|
||||
<span className="flex items-center gap-2">
|
||||
<Icon name="pie_chart" size={24} className="text-primary" />
|
||||
{t("title")}
|
||||
</h1>
|
||||
<p className="text-sm text-text-muted mt-0.5">{t("description")}</p>
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<Button variant="primary" size="sm" onClick={() => setCreateOpen(true)}>
|
||||
<span className="material-symbols-outlined text-[14px] mr-1">add</span>
|
||||
</span>
|
||||
}
|
||||
description={t("description")}
|
||||
actions={
|
||||
<Button variant="primary" size="sm" icon="add" onClick={() => setCreateOpen(true)}>
|
||||
{t("newPool")}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
/>
|
||||
|
||||
{/* Beta banner — scoped to this page only */}
|
||||
<div className="flex items-center gap-2 rounded-lg border border-amber-500/40 bg-amber-500/10 px-3 py-2 text-[12px] text-amber-700 dark:text-amber-200">
|
||||
<span className="material-symbols-outlined text-[16px] text-amber-500 shrink-0">
|
||||
science
|
||||
</span>
|
||||
<span className="flex-1">
|
||||
<span className="font-semibold">{t("betaTitle")}</span> — {t("betaText")}
|
||||
</span>
|
||||
<a
|
||||
href="https://github.com/diegosouzapw/OmniRoute/issues/new?labels=quota-share,beta&title=%5Bquota-share%5D%20"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className="shrink-0 inline-flex items-center gap-1 font-medium text-amber-600 dark:text-amber-300 hover:underline"
|
||||
>
|
||||
<span className="material-symbols-outlined text-[14px]">bug_report</span>
|
||||
{t("betaReportLink")}
|
||||
</a>
|
||||
</div>
|
||||
{/* Beta banner — scoped to this page only (always shown: no dismiss) */}
|
||||
<Alert
|
||||
variant="warning"
|
||||
icon={<Icon name="science" size={16} />}
|
||||
className="[&>.ci-alert__dismiss]:hidden"
|
||||
description={
|
||||
<span>
|
||||
<span className="font-semibold">{t("betaTitle")}</span> — {t("betaText")}
|
||||
</span>
|
||||
}
|
||||
actions={
|
||||
<a
|
||||
href="https://github.com/diegosouzapw/OmniRoute/issues/new?labels=quota-share,beta&title=%5Bquota-share%5D%20"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className="inline-flex items-center gap-1 font-medium underline-offset-2 hover:underline"
|
||||
>
|
||||
<Icon name="bug_report" size={14} />
|
||||
{t("betaReportLink")}
|
||||
</a>
|
||||
}
|
||||
/>
|
||||
|
||||
{/* Group bar */}
|
||||
<div className="flex items-center gap-2 flex-wrap rounded-lg border border-border/40 bg-bg-subtle/20 px-3 py-2">
|
||||
<span className="text-[11px] uppercase tracking-wide text-text-muted font-semibold shrink-0">
|
||||
{t("groupLabel")}
|
||||
</span>
|
||||
<select
|
||||
<div className="flex flex-wrap items-center gap-2 rounded-lg border border-border bg-bg-subtle px-3 py-2">
|
||||
<Select
|
||||
compact
|
||||
label={t("groupLabel")}
|
||||
value={selectedGroupId}
|
||||
onChange={(e) => setSelectedGroupId(e.target.value)}
|
||||
title={t("groupSelectHint")}
|
||||
className="px-2 py-1 rounded border border-border bg-bg-base text-sm text-text-main min-w-[120px]"
|
||||
selectClassName="min-w-[120px]"
|
||||
>
|
||||
<option value="all">{t("allGroups")}</option>
|
||||
{groups.map((g) => (
|
||||
@@ -483,11 +485,12 @@ export default function QuotaSharePageClient() {
|
||||
{g.name}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</Select>
|
||||
{showNewGroupInput ? (
|
||||
<div className="flex items-center gap-1">
|
||||
<input
|
||||
<Input
|
||||
type="text"
|
||||
aria-label={t("groupNamePrompt")}
|
||||
value={newGroupInput}
|
||||
onChange={(e) => setNewGroupInput(e.target.value)}
|
||||
onKeyDown={(e) => {
|
||||
@@ -499,57 +502,53 @@ export default function QuotaSharePageClient() {
|
||||
}}
|
||||
placeholder={t("groupNamePrompt")}
|
||||
autoFocus
|
||||
className="px-2 py-1 rounded border border-border bg-bg-base text-sm w-36"
|
||||
inputClassName="h-8 min-h-8 w-36"
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
<Button
|
||||
variant="secondary"
|
||||
size="sm"
|
||||
onClick={() => void handleCreateGroup()}
|
||||
disabled={!newGroupInput.trim()}
|
||||
className="text-xs px-2 py-1 rounded bg-primary/15 text-primary hover:bg-primary/25 transition-colors disabled:opacity-40"
|
||||
>
|
||||
{t("newGroup")}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={() => {
|
||||
setShowNewGroupInput(false);
|
||||
setNewGroupInput("");
|
||||
}}
|
||||
className="text-xs px-2 py-1 rounded border border-border text-text-muted hover:text-text-main transition-colors"
|
||||
>
|
||||
{t("cancel")}
|
||||
</button>
|
||||
</Button>
|
||||
</div>
|
||||
) : (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setShowNewGroupInput(true)}
|
||||
className="flex items-center gap-1 text-xs text-text-muted hover:text-text-main transition-colors"
|
||||
>
|
||||
<span className="material-symbols-outlined text-[14px]">add</span>
|
||||
<Button variant="ghost" size="sm" icon="add" onClick={() => setShowNewGroupInput(true)}>
|
||||
{t("newGroup")}
|
||||
</button>
|
||||
</Button>
|
||||
)}
|
||||
{selectedGroupId !== "all" && (
|
||||
<button
|
||||
type="button"
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
icon="edit"
|
||||
onClick={() => void handleRenameGroup()}
|
||||
disabled={renaming}
|
||||
className="flex items-center gap-1 text-xs text-text-muted hover:text-text-main transition-colors ml-1 disabled:opacity-40"
|
||||
>
|
||||
<span className="material-symbols-outlined text-[14px]">edit</span>
|
||||
{t("renameGroup")}
|
||||
</button>
|
||||
</Button>
|
||||
)}
|
||||
{selectedGroupId !== "all" && selectedGroupId !== "group-demo" && (
|
||||
<button
|
||||
type="button"
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
icon="delete"
|
||||
onClick={() => void handleDeleteGroup()}
|
||||
className="flex items-center gap-1 text-xs text-text-muted hover:text-red-400 transition-colors"
|
||||
className="hover:text-error"
|
||||
>
|
||||
<span className="material-symbols-outlined text-[14px]">delete</span>
|
||||
{t("deleteGroup")}
|
||||
</button>
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
|
||||
@@ -582,19 +581,18 @@ export default function QuotaSharePageClient() {
|
||||
|
||||
{/* Pool list */}
|
||||
{loading ? (
|
||||
<div className="text-text-muted text-sm py-10 text-center animate-pulse">
|
||||
{t("loading")}
|
||||
<div className="flex flex-col gap-3" aria-busy="true">
|
||||
<span className="ci-sr-only">{t("loading")}</span>
|
||||
<Skeleton className="h-40 w-full" />
|
||||
</div>
|
||||
) : pools.length === 0 ? (
|
||||
<div className="rounded-xl border border-border bg-surface py-16 text-center">
|
||||
<span className="material-symbols-outlined text-[64px] opacity-15">pie_chart</span>
|
||||
<h3 className="mt-3 text-base font-semibold text-text-main">{t("emptyTitle")}</h3>
|
||||
<p className="mt-1 text-sm text-text-muted max-w-md mx-auto">{t("emptyDescription")}</p>
|
||||
<Button variant="primary" size="sm" className="mt-4" onClick={() => setCreateOpen(true)}>
|
||||
<span className="material-symbols-outlined text-[14px] mr-1">add</span>
|
||||
{t("newPool")}
|
||||
</Button>
|
||||
</div>
|
||||
<EmptyState
|
||||
icon="pie_chart"
|
||||
title={t("emptyTitle")}
|
||||
description={t("emptyDescription")}
|
||||
actionLabel={t("newPool")}
|
||||
onAction={() => setCreateOpen(true)}
|
||||
/>
|
||||
) : (
|
||||
<>
|
||||
{groupsToRender.length === 0 ? (
|
||||
@@ -604,9 +602,9 @@ export default function QuotaSharePageClient() {
|
||||
variant="primary"
|
||||
size="sm"
|
||||
className="mt-3"
|
||||
icon="add"
|
||||
onClick={() => setCreateOpen(true)}
|
||||
>
|
||||
<span className="material-symbols-outlined text-[14px] mr-1">add</span>
|
||||
{t("newPool")}
|
||||
</Button>
|
||||
</div>
|
||||
@@ -619,9 +617,7 @@ export default function QuotaSharePageClient() {
|
||||
<div key={g.id} className="flex flex-col gap-3">
|
||||
{/* Per-group heading */}
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="material-symbols-outlined text-[16px] text-text-muted">
|
||||
folder
|
||||
</span>
|
||||
<Icon name="folder" size={16} className="text-text-muted" />
|
||||
<span className="text-sm font-semibold text-text-main">{g.name}</span>
|
||||
<span className="text-[11px] text-text-muted">({groupPools.length})</span>
|
||||
</div>
|
||||
@@ -632,9 +628,9 @@ export default function QuotaSharePageClient() {
|
||||
variant="primary"
|
||||
size="sm"
|
||||
className="mt-3"
|
||||
icon="add"
|
||||
onClick={() => setCreateOpen(true)}
|
||||
>
|
||||
<span className="material-symbols-outlined text-[14px] mr-1">add</span>
|
||||
{t("newPool")}
|
||||
</Button>
|
||||
</div>
|
||||
@@ -669,13 +665,11 @@ export default function QuotaSharePageClient() {
|
||||
{selectedGroupId === "all" && orphanPools.length > 0 && (
|
||||
<div className="flex flex-col gap-3">
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="material-symbols-outlined text-[16px] text-amber-400">
|
||||
folder_off
|
||||
</span>
|
||||
<Icon name="folder_off" size={16} className="text-warning" />
|
||||
<span className="text-sm font-semibold text-text-main">{t("ungroupedTitle")}</span>
|
||||
<span className="text-[11px] text-text-muted">({orphanPools.length})</span>
|
||||
</div>
|
||||
<p className="text-[11px] text-amber-400/80">{t("ungroupedHint")}</p>
|
||||
<p className="text-[11px] text-warning">{t("ungroupedHint")}</p>
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-3">
|
||||
{orphanPools.map((pool) => (
|
||||
<PoolCardWithUsage
|
||||
|
||||
@@ -59,10 +59,8 @@ function summarizeQuotas(provider: string, raw: unknown): QuotaSummary | null {
|
||||
}
|
||||
|
||||
function PctDot({ pct }: { pct: number }) {
|
||||
const color =
|
||||
pct <= 20 ? "bg-red-500" : pct <= 50 ? "bg-yellow-500" : "bg-emerald-500";
|
||||
const textColor =
|
||||
pct <= 20 ? "text-red-500" : pct <= 50 ? "text-yellow-500" : "text-emerald-500";
|
||||
const color = pct <= 20 ? "bg-error" : pct <= 50 ? "bg-warning" : "bg-success";
|
||||
const textColor = pct <= 20 ? "text-error" : pct <= 50 ? "text-warning" : "text-success";
|
||||
return (
|
||||
<span className={`inline-flex items-center gap-1 tabular-nums text-[11px] ${textColor}`}>
|
||||
<span className={`w-1.5 h-1.5 rounded-full shrink-0 ${color}`} aria-hidden />
|
||||
@@ -109,20 +107,15 @@ export default function AccountQuotaRow({
|
||||
}, []);
|
||||
|
||||
// Resolve the effective connection list to display
|
||||
const ids: string[] = Array.isArray(connectionIds) && connectionIds.length > 0
|
||||
? connectionIds
|
||||
: [];
|
||||
const ids: string[] =
|
||||
Array.isArray(connectionIds) && connectionIds.length > 0 ? connectionIds : [];
|
||||
|
||||
// Resolve provider for each connection (providers[i] matches connectionIds[i])
|
||||
const providerFor = (index: number): string =>
|
||||
Array.isArray(providers) && providers[index] != null
|
||||
? (providers[index] as string)
|
||||
: provider;
|
||||
Array.isArray(providers) && providers[index] != null ? (providers[index] as string) : provider;
|
||||
|
||||
const renderFallback = () => (
|
||||
<span className="text-[11px] text-text-muted tabular-nums">
|
||||
{t("accountQuotaNone")}
|
||||
</span>
|
||||
<span className="text-[11px] text-text-muted tabular-nums">{t("accountQuotaNone")}</span>
|
||||
);
|
||||
|
||||
if (error || caches === null) {
|
||||
@@ -165,15 +158,16 @@ export default function AccountQuotaRow({
|
||||
<span className="shrink-0">
|
||||
<ProviderIcon providerId={prov} size={14} />
|
||||
</span>
|
||||
<span className="text-text-muted truncate max-w-[90px]" title={emailsVisible ? connId : maskEmailLikeValue(connId)}>
|
||||
<span
|
||||
className="text-text-muted truncate max-w-[90px]"
|
||||
title={emailsVisible ? connId : maskEmailLikeValue(connId)}
|
||||
>
|
||||
{emailsVisible ? `${connId.slice(0, 8)}…` : maskEmailLikeValue(connId)}
|
||||
</span>
|
||||
{summary ? (
|
||||
<>
|
||||
<PctDot pct={summary.pct} />
|
||||
{reset ? (
|
||||
<span className="text-text-muted">· {reset}</span>
|
||||
) : null}
|
||||
{reset ? <span className="text-text-muted">· {reset}</span> : null}
|
||||
</>
|
||||
) : (
|
||||
<span className="text-text-muted">{t("accountQuotaNone")}</span>
|
||||
|
||||
@@ -3,6 +3,16 @@
|
||||
import { useTranslations } from "next-intl";
|
||||
import type { PoolAllocation } from "@/lib/quota/dimensions";
|
||||
import type { PoolUsageSnapshot } from "@/lib/quota/types";
|
||||
import {
|
||||
Table,
|
||||
TableBody,
|
||||
TableCell,
|
||||
TableHead,
|
||||
TableHeader,
|
||||
TableRow,
|
||||
} from "@omniroute/ui-kit/table";
|
||||
import Badge from "@/shared/components/Badge";
|
||||
import { getSeriesColor } from "@/shared/components/analytics/chartColors";
|
||||
|
||||
interface AllocationTableProps {
|
||||
allocations: PoolAllocation[];
|
||||
@@ -11,23 +21,12 @@ interface AllocationTableProps {
|
||||
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">
|
||||
<div className="rounded-md bg-bg-subtle py-3 text-center text-[11px] italic text-text-muted">
|
||||
{t("noAllocations")}
|
||||
</div>
|
||||
);
|
||||
@@ -37,94 +36,96 @@ export default function AllocationTable({ allocations, usage, keyLabels }: Alloc
|
||||
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">{t("apiKeyColumn")}</th>
|
||||
<th className="text-right py-1 pr-2 font-semibold">{t("weightColumn")}</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">{t("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) + "…";
|
||||
<Table scrollbarLabel={t("apiKeyColumn")} className="min-w-0 text-[11px]">
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead className="h-8 px-2">{t("apiKeyColumn")}</TableHead>
|
||||
<TableHead className="h-8 px-2 text-right">{t("weightColumn")}</TableHead>
|
||||
<TableHead className="h-8 px-2 text-right">{t("realConsumedColumn")}</TableHead>
|
||||
<TableHead className="h-8 px-2 text-right">{t("deficitColumn")}</TableHead>
|
||||
<TableHead className="h-8 px-2 text-right">{t("policy")}</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{allocations.map((alloc, i) => {
|
||||
// Same categorical series as StackedAllocationBar (kit chart tokens).
|
||||
const color = getSeriesColor(i);
|
||||
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;
|
||||
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">
|
||||
({t("fairShareShort")}: {fairShare.toLocaleString()})
|
||||
</span>
|
||||
)}
|
||||
</td>
|
||||
<td className="py-1.5 text-right">
|
||||
return (
|
||||
<TableRow key={alloc.apiKeyId}>
|
||||
<TableCell className="h-auto px-2 py-1.5">
|
||||
<div className="flex items-center gap-1.5 min-w-0">
|
||||
<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"
|
||||
}`}
|
||||
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 && (
|
||||
<Badge
|
||||
size="sm"
|
||||
variant="warning"
|
||||
className="shrink-0 text-[9px] font-bold"
|
||||
title={t("borrowingIndicator")}
|
||||
>
|
||||
{t("borrowingIndicator")}
|
||||
</Badge>
|
||||
)}
|
||||
</div>
|
||||
</TableCell>
|
||||
<TableCell
|
||||
className="h-auto px-2 py-1.5 text-right font-bold tabular-nums"
|
||||
style={{ color }}
|
||||
>
|
||||
{alloc.weight}%
|
||||
</TableCell>
|
||||
<TableCell className="h-auto px-2 py-1.5 text-right tabular-nums text-text-muted">
|
||||
{consumed !== null ? consumed.toLocaleString() : "—"}
|
||||
</TableCell>
|
||||
<TableCell className="h-auto px-2 py-1.5 text-right tabular-nums">
|
||||
{deficit !== null ? (
|
||||
<span
|
||||
className={
|
||||
deficit > 0 ? "text-error" : deficit < 0 ? "text-success" : "text-text-muted"
|
||||
}
|
||||
>
|
||||
{t(`policy${alloc.policy[0].toUpperCase()}${alloc.policy.slice(1)}`)}
|
||||
{deficit > 0 ? "+" : ""}
|
||||
{deficit.toLocaleString()}
|
||||
</span>
|
||||
</td>
|
||||
</tr>
|
||||
);
|
||||
})}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
) : (
|
||||
<span className="text-text-muted">—</span>
|
||||
)}
|
||||
{fairShare !== null && (
|
||||
<span className="text-[9px] text-text-muted ml-1">
|
||||
({t("fairShareShort")}: {fairShare.toLocaleString()})
|
||||
</span>
|
||||
)}
|
||||
</TableCell>
|
||||
<TableCell className="h-auto px-2 py-1.5 text-right">
|
||||
<Badge
|
||||
size="sm"
|
||||
variant={
|
||||
alloc.policy === "hard"
|
||||
? "error"
|
||||
: alloc.policy === "soft"
|
||||
? "warning"
|
||||
: "success"
|
||||
}
|
||||
className="text-[9px] font-semibold"
|
||||
>
|
||||
{t(`policy${alloc.policy[0].toUpperCase()}${alloc.policy.slice(1)}`)}
|
||||
</Badge>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
);
|
||||
})}
|
||||
</TableBody>
|
||||
</Table>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ export default function BurnRateChartInner({ usage }: BurnRateChartInnerProps) {
|
||||
<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>}
|
||||
{exhaustionLabel && <span className="text-warning font-semibold">{exhaustionLabel}</span>}
|
||||
</div>
|
||||
<div className="h-24">
|
||||
<ResponsiveContainer width="100%" height="100%">
|
||||
@@ -65,15 +65,15 @@ export default function BurnRateChartInner({ usage }: BurnRateChartInnerProps) {
|
||||
<YAxis hide />
|
||||
<Tooltip
|
||||
contentStyle={{
|
||||
background: "var(--bg-surface, #1e1e2e)",
|
||||
border: "1px solid var(--border)",
|
||||
background: "var(--color-surface)",
|
||||
border: "1px solid var(--color-border)",
|
||||
fontSize: 10,
|
||||
}}
|
||||
/>
|
||||
<Line
|
||||
type="monotone"
|
||||
dataKey="consumed"
|
||||
stroke="#a78bfa"
|
||||
stroke="var(--color-chart-3)"
|
||||
strokeWidth={2}
|
||||
dot={false}
|
||||
strokeDasharray="4 2"
|
||||
|
||||
@@ -26,15 +26,9 @@ export default function DimensionBar({ dimension, consumedTotal, resetAt }: Dime
|
||||
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 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 barColor = usedPct >= 90 ? "bg-error" : usedPct >= 70 ? "bg-warning" : "bg-primary";
|
||||
|
||||
const resetMs = resetAt ? new Date(resetAt).getTime() - now : null;
|
||||
const countdown = resetMs !== null && resetMs > 0 ? fmtCountdown(resetMs) : null;
|
||||
@@ -45,12 +39,19 @@ export default function DimensionBar({ dimension, consumedTotal, resetAt }: Dime
|
||||
<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 }}>
|
||||
<span
|
||||
className={`tabular-nums font-bold ${
|
||||
usedPct >= 90 ? "text-error" : usedPct >= 70 ? "text-warning" : ""
|
||||
}`}
|
||||
>
|
||||
{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 className="h-1.5 overflow-hidden rounded-sm bg-border/60" aria-hidden="true">
|
||||
<div
|
||||
className={`h-full rounded-sm transition-all ${barColor}`}
|
||||
style={{ width: `${usedPct}%` }}
|
||||
/>
|
||||
</div>
|
||||
{countdown && (
|
||||
<div className="text-[10px] text-text-muted">
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
"use client";
|
||||
|
||||
import { useTranslations } from "next-intl";
|
||||
import Button from "@/shared/components/Button";
|
||||
import Card from "@/shared/components/Card";
|
||||
import Icon from "@/shared/components/Icon";
|
||||
import ProviderIcon from "@/shared/components/ProviderIcon";
|
||||
import useEmailPrivacyStore from "@/store/emailPrivacyStore";
|
||||
import { maskEmailLikeValue } from "@/shared/utils/maskEmail";
|
||||
@@ -43,9 +45,9 @@ function computeStatus(usage: PoolUsageSnapshot | null): "green" | "amber" | "re
|
||||
}
|
||||
|
||||
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" },
|
||||
green: { icon: "check_circle", cls: "text-success" },
|
||||
amber: { icon: "warning", cls: "text-warning" },
|
||||
red: { icon: "error", cls: "text-error" },
|
||||
};
|
||||
|
||||
export default function PoolCard({
|
||||
@@ -101,9 +103,7 @@ export default function PoolCard({
|
||||
)}
|
||||
<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>
|
||||
<Icon name={statusIcon} size={16} className={statusCls} />
|
||||
<span className="text-sm font-bold text-text-main truncate">
|
||||
{displayName} · {displayConnectionLabel}
|
||||
</span>
|
||||
@@ -115,22 +115,26 @@ export default function PoolCard({
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex items-center gap-1">
|
||||
<button
|
||||
type="button"
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon-sm"
|
||||
onClick={onEdit}
|
||||
title={t("editAllocations")}
|
||||
className="p-1.5 rounded-md hover:bg-bg-subtle text-text-muted hover:text-text-main cursor-pointer"
|
||||
aria-label={t("editAllocations")}
|
||||
className="text-text-muted"
|
||||
>
|
||||
<span className="material-symbols-outlined text-[16px]">edit</span>
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
<Icon name="edit" size={16} />
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon-sm"
|
||||
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"
|
||||
aria-label={t("removePool")}
|
||||
className="text-text-muted hover:bg-error/10 hover:text-error"
|
||||
>
|
||||
<span className="material-symbols-outlined text-[16px]">delete</span>
|
||||
</button>
|
||||
<Icon name="delete" size={16} />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -162,7 +166,7 @@ export default function PoolCard({
|
||||
{/* Allocation table */}
|
||||
<div className="mb-3">
|
||||
<h4 className="text-[10px] uppercase tracking-wide font-bold text-text-muted mb-1.5">
|
||||
Allocations
|
||||
{t("allocationsHeading")}
|
||||
</h4>
|
||||
<AllocationTable allocations={pool.allocations} usage={usage} keyLabels={keyLabels} />
|
||||
</div>
|
||||
@@ -172,7 +176,7 @@ export default function PoolCard({
|
||||
|
||||
{/* Burn rate chart */}
|
||||
{usage && (
|
||||
<div className="pt-2 border-t border-border/30">
|
||||
<div className="pt-2 border-t border-border">
|
||||
<BurnRateChart usage={usage} />
|
||||
</div>
|
||||
)}
|
||||
|
||||
@@ -2,6 +2,11 @@
|
||||
|
||||
import { useCallback, useEffect, useState } from "react";
|
||||
import { useTranslations, useLocale } from "next-intl";
|
||||
import Button from "@/shared/components/Button";
|
||||
import Checkbox from "@/shared/components/Checkbox";
|
||||
import Icon from "@/shared/components/Icon";
|
||||
import Input from "@/shared/components/Input";
|
||||
import Select from "@/shared/components/Select";
|
||||
import type { QuotaSchedule, ReserveRule } from "@/lib/quota/schedules";
|
||||
|
||||
export interface PoolSchedulesCardProps {
|
||||
@@ -191,26 +196,29 @@ export default function PoolSchedulesCard({ poolId }: PoolSchedulesCardProps) {
|
||||
}
|
||||
}, [rows, poolId, t]);
|
||||
|
||||
const inputCls =
|
||||
"bg-bg-subtle border border-border/50 rounded px-1.5 py-0.5 text-[11px] text-text-main";
|
||||
// Dense inline editor rows: kit controls at a compact height.
|
||||
const inputCls = "h-7 min-h-7 px-1.5 text-[11px]";
|
||||
const selectCls = "ci-select-native--sm h-7 min-h-7 text-[11px]";
|
||||
|
||||
return (
|
||||
<div className="mt-2 pt-2 border-t border-border/30">
|
||||
<button
|
||||
type="button"
|
||||
<div className="mt-2 pt-2 border-t border-border">
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={() => setOpen((prev) => !prev)}
|
||||
className="flex items-center gap-1 text-[10px] uppercase tracking-wide font-bold text-text-muted hover:text-text-main w-full text-left cursor-pointer"
|
||||
aria-expanded={open}
|
||||
className="h-7 min-h-7 w-full justify-start gap-1 px-1 text-[10px] font-bold uppercase tracking-wide text-text-muted"
|
||||
>
|
||||
<span
|
||||
className={`material-symbols-outlined text-[13px] transition-transform ${open ? "rotate-90" : ""}`}
|
||||
>
|
||||
chevron_right
|
||||
</span>
|
||||
<Icon
|
||||
name="chevron_right"
|
||||
size={13}
|
||||
className={`transition-transform ${open ? "rotate-90" : ""}`}
|
||||
/>
|
||||
{t("schedulesTitle")}
|
||||
{rows.length > 0 && (
|
||||
<span className="ml-1 text-text-muted/60 normal-case font-normal">({rows.length})</span>
|
||||
)}
|
||||
</button>
|
||||
</Button>
|
||||
|
||||
{open && (
|
||||
<div className="mt-1.5 flex flex-col gap-2">
|
||||
@@ -225,53 +233,51 @@ export default function PoolSchedulesCard({ poolId }: PoolSchedulesCardProps) {
|
||||
{rows.map((row, index) => (
|
||||
<div
|
||||
key={row.id}
|
||||
className={`rounded-md border border-border/40 p-2 flex flex-col gap-1.5 ${
|
||||
className={`rounded-md border border-border p-2 flex flex-col gap-1.5 ${
|
||||
row.enabled ? "" : "opacity-50"
|
||||
}`}
|
||||
>
|
||||
{/* Row 1 — when */}
|
||||
<div className="flex flex-wrap items-center gap-1.5">
|
||||
<input
|
||||
type="checkbox"
|
||||
<Checkbox
|
||||
checked={row.enabled}
|
||||
onChange={(e) => patchRow(index, { enabled: e.target.checked })}
|
||||
aria-label={t("schedulesEnabled")}
|
||||
className="cursor-pointer"
|
||||
/>
|
||||
|
||||
<select
|
||||
<Select
|
||||
value={row.mode}
|
||||
onChange={(e) =>
|
||||
patchRow(index, { mode: e.target.value as DraftSchedule["mode"] })
|
||||
}
|
||||
aria-label={t("schedulesMode")}
|
||||
className={`${inputCls} cursor-pointer`}
|
||||
selectClassName={selectCls}
|
||||
>
|
||||
<option value="allow">{t("schedulesModeAllow")}</option>
|
||||
<option value="block">{t("schedulesModeBlock")}</option>
|
||||
</select>
|
||||
</Select>
|
||||
|
||||
<div className="flex items-center gap-0.5">
|
||||
{initials.map((initial, day) => (
|
||||
<button
|
||||
<Button
|
||||
key={day}
|
||||
type="button"
|
||||
variant={row.days.includes(day) ? "secondary" : "ghost"}
|
||||
size="icon-sm"
|
||||
onClick={() => toggleDay(index, day)}
|
||||
aria-pressed={row.days.includes(day)}
|
||||
title={initial}
|
||||
className={`w-5 h-5 rounded text-[10px] font-bold cursor-pointer ${
|
||||
row.days.includes(day)
|
||||
? "bg-accent/20 text-accent"
|
||||
: "bg-bg-subtle text-text-muted"
|
||||
className={`size-6 min-h-6 text-[10px] font-bold ${
|
||||
row.days.includes(day) ? "text-primary" : "text-text-muted"
|
||||
}`}
|
||||
>
|
||||
{initial}
|
||||
</button>
|
||||
</Button>
|
||||
))}
|
||||
</div>
|
||||
|
||||
<input
|
||||
<Input
|
||||
type="time"
|
||||
inputClassName={inputCls}
|
||||
value={minutesToTime(row.startMinute)}
|
||||
onChange={(e) =>
|
||||
patchRow(index, {
|
||||
@@ -279,54 +285,57 @@ export default function PoolSchedulesCard({ poolId }: PoolSchedulesCardProps) {
|
||||
})
|
||||
}
|
||||
aria-label={t("schedulesFrom")}
|
||||
className={inputCls}
|
||||
/>
|
||||
<span className="text-[11px] text-text-muted">→</span>
|
||||
<input
|
||||
<Input
|
||||
type="time"
|
||||
inputClassName={inputCls}
|
||||
value={minutesToTime(row.endMinute)}
|
||||
onChange={(e) =>
|
||||
patchRow(index, { endMinute: timeToMinutes(e.target.value, row.endMinute) })
|
||||
}
|
||||
aria-label={t("schedulesTo")}
|
||||
className={inputCls}
|
||||
/>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon-sm"
|
||||
onClick={() => {
|
||||
setRows((prev) => prev.filter((_, i) => i !== index));
|
||||
setMessage(null);
|
||||
}}
|
||||
title={t("schedulesRemove")}
|
||||
className="ml-auto p-1 rounded hover:bg-red-500/10 text-text-muted hover:text-red-400 cursor-pointer"
|
||||
aria-label={t("schedulesRemove")}
|
||||
className="ml-auto text-text-muted hover:bg-error/10 hover:text-error"
|
||||
>
|
||||
<span className="material-symbols-outlined text-[14px]">delete</span>
|
||||
</button>
|
||||
<Icon name="delete" size={14} />
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{/* Row 2a — how much must be left, one floor per metered window */}
|
||||
{row.mode === "allow" && (
|
||||
<div className="flex flex-col gap-1">
|
||||
<div className="flex flex-wrap items-center gap-1.5">
|
||||
<label
|
||||
<span
|
||||
className="text-[11px] text-text-muted"
|
||||
title={t("schedulesReserveHint")}
|
||||
>
|
||||
{t("schedulesReserve")}
|
||||
</label>
|
||||
</span>
|
||||
{row.reserves.length === 0 && (
|
||||
<span className="text-[11px] text-text-muted/60 italic">
|
||||
{t("schedulesReserveNone")}
|
||||
</span>
|
||||
)}
|
||||
<button
|
||||
type="button"
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
icon="add"
|
||||
onClick={() => addReserve(index)}
|
||||
className="text-[11px] px-1.5 py-0.5 rounded bg-bg-subtle hover:bg-bg-subtle/70 text-text-main cursor-pointer"
|
||||
className="h-7 min-h-7 px-2 text-[11px]"
|
||||
>
|
||||
+ {t("schedulesReserveAdd")}
|
||||
</button>
|
||||
{t("schedulesReserveAdd")}
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{row.reserves.map((rule, ruleIndex) => (
|
||||
@@ -334,7 +343,8 @@ export default function PoolSchedulesCard({ poolId }: PoolSchedulesCardProps) {
|
||||
key={`${rule.window}-${ruleIndex}`}
|
||||
className="flex flex-wrap items-center gap-1.5 pl-3"
|
||||
>
|
||||
<select
|
||||
<Select
|
||||
selectClassName={selectCls}
|
||||
value={rule.window}
|
||||
onChange={(e) =>
|
||||
patchReserve(index, ruleIndex, {
|
||||
@@ -343,15 +353,14 @@ export default function PoolSchedulesCard({ poolId }: PoolSchedulesCardProps) {
|
||||
})
|
||||
}
|
||||
aria-label={t("schedulesReserveWindow")}
|
||||
className={`${inputCls} cursor-pointer`}
|
||||
>
|
||||
{RESERVE_WINDOWS.map((w) => (
|
||||
<option key={w} value={w}>
|
||||
{w === "any" ? t("schedulesReserveWindowAny") : w}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
<input
|
||||
</Select>
|
||||
<Input
|
||||
type="number"
|
||||
min={0}
|
||||
max={100}
|
||||
@@ -364,17 +373,19 @@ export default function PoolSchedulesCard({ poolId }: PoolSchedulesCardProps) {
|
||||
})
|
||||
}
|
||||
aria-label={t("schedulesReserve")}
|
||||
className={`${inputCls} w-16`}
|
||||
inputClassName={`${inputCls} w-16`}
|
||||
/>
|
||||
<span className="text-[11px] text-text-muted">%</span>
|
||||
<button
|
||||
type="button"
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon-sm"
|
||||
onClick={() => patchReserve(index, ruleIndex, null)}
|
||||
title={t("schedulesReserveRemove")}
|
||||
className="p-0.5 rounded hover:bg-red-500/10 text-text-muted hover:text-red-400 cursor-pointer"
|
||||
aria-label={t("schedulesReserveRemove")}
|
||||
className="size-6 min-h-6 text-text-muted hover:bg-error/10 hover:text-error"
|
||||
>
|
||||
<span className="material-symbols-outlined text-[13px]">close</span>
|
||||
</button>
|
||||
<Icon name="close" size={13} />
|
||||
</Button>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
@@ -383,14 +394,15 @@ export default function PoolSchedulesCard({ poolId }: PoolSchedulesCardProps) {
|
||||
{/* Row 2b — how much OmniRoute itself may spend */}
|
||||
{row.mode === "allow" && (
|
||||
<div className="flex flex-wrap items-center gap-1.5">
|
||||
<label
|
||||
<span
|
||||
className="text-[11px] text-text-muted"
|
||||
title={t("schedulesBudgetHint")}
|
||||
>
|
||||
{t("schedulesBudget")}
|
||||
</label>
|
||||
<input
|
||||
</span>
|
||||
<Input
|
||||
type="number"
|
||||
aria-label={t("schedulesBudget")}
|
||||
min={0}
|
||||
value={row.budgetValue ?? ""}
|
||||
placeholder="—"
|
||||
@@ -403,9 +415,10 @@ export default function PoolSchedulesCard({ poolId }: PoolSchedulesCardProps) {
|
||||
e.target.value === "" ? undefined : (row.budgetUnit ?? "tokens"),
|
||||
})
|
||||
}
|
||||
className={`${inputCls} w-24`}
|
||||
inputClassName={`${inputCls} w-24`}
|
||||
/>
|
||||
<select
|
||||
<Select
|
||||
selectClassName={selectCls}
|
||||
value={row.budgetUnit ?? ""}
|
||||
disabled={row.budgetValue === undefined}
|
||||
onChange={(e) =>
|
||||
@@ -415,7 +428,6 @@ export default function PoolSchedulesCard({ poolId }: PoolSchedulesCardProps) {
|
||||
})
|
||||
}
|
||||
aria-label={t("schedulesBudgetUnit")}
|
||||
className={`${inputCls} cursor-pointer disabled:opacity-40`}
|
||||
>
|
||||
<option value="">—</option>
|
||||
{BUDGET_UNITS.map((unit) => (
|
||||
@@ -423,8 +435,9 @@ export default function PoolSchedulesCard({ poolId }: PoolSchedulesCardProps) {
|
||||
{unit}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
<select
|
||||
</Select>
|
||||
<Select
|
||||
selectClassName={selectCls}
|
||||
value={row.budgetWindow}
|
||||
disabled={row.budgetValue === undefined}
|
||||
onChange={(e) =>
|
||||
@@ -433,37 +446,38 @@ export default function PoolSchedulesCard({ poolId }: PoolSchedulesCardProps) {
|
||||
})
|
||||
}
|
||||
aria-label={t("schedulesBudgetWindow")}
|
||||
className={`${inputCls} cursor-pointer disabled:opacity-40`}
|
||||
>
|
||||
{BUDGET_WINDOWS.map((w) => (
|
||||
<option key={w} value={w}>
|
||||
{w}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</Select>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Row 3 — zone and precedence */}
|
||||
<div className="flex flex-wrap items-center gap-1.5">
|
||||
<label className="text-[11px] text-text-muted">{t("schedulesTimezone")}</label>
|
||||
<input
|
||||
<span className="text-[11px] text-text-muted">{t("schedulesTimezone")}</span>
|
||||
<Input
|
||||
type="text"
|
||||
aria-label={t("schedulesTimezone")}
|
||||
value={row.timezone ?? ""}
|
||||
placeholder="Europe/Rome"
|
||||
onChange={(e) => patchRow(index, { timezone: e.target.value.trim() || null })}
|
||||
className={`${inputCls} w-40`}
|
||||
inputClassName={`${inputCls} w-40`}
|
||||
/>
|
||||
<label className="text-[11px] text-text-muted ml-1">
|
||||
<span className="ml-1 text-[11px] text-text-muted">
|
||||
{t("schedulesPriority")}
|
||||
</label>
|
||||
<input
|
||||
</span>
|
||||
<Input
|
||||
type="number"
|
||||
aria-label={t("schedulesPriority")}
|
||||
min={0}
|
||||
max={1000}
|
||||
value={row.priority}
|
||||
onChange={(e) => patchRow(index, { priority: Number(e.target.value) || 0 })}
|
||||
className={`${inputCls} w-14`}
|
||||
inputClassName={`${inputCls} w-14`}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
@@ -472,27 +486,24 @@ export default function PoolSchedulesCard({ poolId }: PoolSchedulesCardProps) {
|
||||
)}
|
||||
|
||||
<div className="flex items-center gap-2">
|
||||
<button
|
||||
type="button"
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
icon="add"
|
||||
onClick={() => {
|
||||
setRows((prev) => [...prev, newDraft()]);
|
||||
setMessage(null);
|
||||
}}
|
||||
className="text-[11px] px-2 py-1 rounded bg-bg-subtle hover:bg-bg-subtle/70 text-text-main cursor-pointer"
|
||||
>
|
||||
+ {t("schedulesAdd")}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={save}
|
||||
disabled={saving || !loaded}
|
||||
className="text-[11px] px-2 py-1 rounded bg-accent/20 text-accent hover:bg-accent/30 disabled:opacity-40 cursor-pointer"
|
||||
>
|
||||
{t("schedulesAdd")}
|
||||
</Button>
|
||||
<Button size="sm" onClick={save} loading={saving} disabled={saving || !loaded}>
|
||||
{saving ? t("loading") : t("save")}
|
||||
</button>
|
||||
</Button>
|
||||
{message && (
|
||||
<span
|
||||
className={`text-[11px] ${message.kind === "ok" ? "text-emerald-400" : "text-red-400"}`}
|
||||
role="status"
|
||||
className={`text-[11px] ${message.kind === "ok" ? "text-success" : "text-error"}`}
|
||||
>
|
||||
{message.text}
|
||||
</span>
|
||||
|
||||
@@ -20,6 +20,13 @@
|
||||
import { useMemo, useState, type Dispatch, type SetStateAction } from "react";
|
||||
import { useTranslations } from "next-intl";
|
||||
import { Button, Modal } from "@/shared/components";
|
||||
import Badge from "@/shared/components/Badge";
|
||||
import Checkbox from "@/shared/components/Checkbox";
|
||||
import Input from "@/shared/components/Input";
|
||||
import SegmentedControl from "@/shared/components/SegmentedControl";
|
||||
import Select from "@/shared/components/Select";
|
||||
import { getSeriesColor } from "@/shared/components/analytics/chartColors";
|
||||
import Icon from "@/shared/components/Icon";
|
||||
import useEmailPrivacyStore from "@/store/emailPrivacyStore";
|
||||
import { maskEmailLikeValue } from "@/shared/utils/maskEmail";
|
||||
import { getKnownPlan } from "@/lib/quota/planRegistry";
|
||||
@@ -86,17 +93,6 @@ export interface PoolWizardProps {
|
||||
const UNIT_OPTIONS: QuotaUnit[] = ["percent", "requests", "tokens", "usd"];
|
||||
const WINDOW_OPTIONS: QuotaWindow[] = ["5h", "hourly", "daily", "weekly", "monthly"];
|
||||
|
||||
const SLICE_PALETTE = [
|
||||
"#a78bfa",
|
||||
"#60a5fa",
|
||||
"#34d399",
|
||||
"#fbbf24",
|
||||
"#f87171",
|
||||
"#22d3ee",
|
||||
"#f472b6",
|
||||
"#94a3b8",
|
||||
];
|
||||
|
||||
/** A few representative model names to show in the preview. */
|
||||
const PREVIEW_MODELS_BY_PROVIDER: Record<string, string[]> = {
|
||||
openai: ["gpt-4o", "gpt-4o-mini", "o3", "gpt-4-turbo"],
|
||||
@@ -127,20 +123,31 @@ function Stepper({ currentStep }: { currentStep: 1 | 2 | 3 }) {
|
||||
{ num: 3, label: t("wizardStep3Label") },
|
||||
];
|
||||
|
||||
// Built from kit tokens, not the kit Wizard: its step/back/skip/save copy is hard-coded
|
||||
// English and it always renders a Skip action (see the lote 6 pendências).
|
||||
return (
|
||||
<div className="flex items-center gap-0 px-4 py-3 border-b border-border bg-bg-alt shrink-0">
|
||||
<ol
|
||||
aria-label={t("wizardTitle")}
|
||||
className="flex shrink-0 flex-wrap items-center gap-y-2 border-b border-border bg-bg-subtle px-4 py-3"
|
||||
>
|
||||
{steps.map((step, idx) => (
|
||||
<div key={step.num} className="flex items-center">
|
||||
<li
|
||||
key={step.num}
|
||||
className="flex items-center"
|
||||
aria-current={currentStep === step.num ? "step" : undefined}
|
||||
>
|
||||
{idx > 0 && (
|
||||
<div
|
||||
className={`h-px w-8 mx-2 transition-colors ${
|
||||
aria-hidden="true"
|
||||
className={`mx-2 h-px w-8 transition-colors ${
|
||||
currentStep > step.num ? "bg-primary" : "bg-border"
|
||||
}`}
|
||||
/>
|
||||
)}
|
||||
<div className="flex items-center gap-1.5">
|
||||
<span
|
||||
className={`flex items-center justify-center w-5 h-5 rounded-full text-[11px] font-semibold transition-colors ${
|
||||
aria-hidden="true"
|
||||
className={`flex size-5 items-center justify-center rounded-full text-[11px] font-semibold transition-colors ${
|
||||
currentStep === step.num
|
||||
? "bg-primary text-accent-foreground"
|
||||
: currentStep > step.num
|
||||
@@ -148,11 +155,7 @@ function Stepper({ currentStep }: { currentStep: 1 | 2 | 3 }) {
|
||||
: "bg-border text-text-muted"
|
||||
}`}
|
||||
>
|
||||
{currentStep > step.num ? (
|
||||
<span className="material-symbols-outlined text-[12px]">check</span>
|
||||
) : (
|
||||
step.num
|
||||
)}
|
||||
{currentStep > step.num ? <Icon name="check" size={12} /> : step.num}
|
||||
</span>
|
||||
<span
|
||||
className={`text-xs font-medium transition-colors ${
|
||||
@@ -162,9 +165,9 @@ function Stepper({ currentStep }: { currentStep: 1 | 2 | 3 }) {
|
||||
{step.label}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
))}
|
||||
</div>
|
||||
</ol>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -186,7 +189,7 @@ function pickWizardDimensions(
|
||||
}
|
||||
|
||||
// Pure predicate hoisted out of the component to keep its cognitive budget flat
|
||||
// (check:cognitive-complexity new-code mode): snap the group <select> to a real,
|
||||
// (check:cognitive-complexity new-code mode): snap the group Select to a real,
|
||||
// selectable option in create mode once groups load.
|
||||
function poolWizardNeedsGroupSnap(
|
||||
open: boolean,
|
||||
@@ -399,7 +402,7 @@ export default function PoolWizard({
|
||||
setSaving,
|
||||
setGroupId,
|
||||
});
|
||||
// Keep the group <select> on a real, selectable option (create mode) — self-
|
||||
// Keep the group Select on a real, selectable option (create mode) — self-
|
||||
// extinguishing state adjustment during render (react-hooks/set-state-in-effect).
|
||||
if (poolWizardNeedsGroupSnap(open, Boolean(editPool), groups, groupId)) {
|
||||
setGroupId(groups[0].id);
|
||||
@@ -644,88 +647,87 @@ export default function PoolWizard({
|
||||
|
||||
{/* Connection multi-select (checkboxes) */}
|
||||
<div>
|
||||
<label className="text-[11px] uppercase tracking-wide text-text-muted font-semibold block mb-1">
|
||||
<span
|
||||
id="pool-wizard-connections-label"
|
||||
className="mb-1 block text-[11px] font-semibold uppercase tracking-wide text-text-muted"
|
||||
>
|
||||
{t("wizardConnectionsLabel")}
|
||||
</label>
|
||||
</span>
|
||||
{lockedProvider && (
|
||||
<p className="text-[10px] text-amber-400 mb-1.5">
|
||||
<p className="text-[10px] text-warning mb-1.5">
|
||||
{t("wizardSingleProviderNote")} ({lockedProvider})
|
||||
</p>
|
||||
)}
|
||||
<div className="space-y-1.5 rounded border border-border bg-bg-base px-3 py-2 max-h-48 overflow-y-auto">
|
||||
<div
|
||||
role="group"
|
||||
aria-labelledby="pool-wizard-connections-label"
|
||||
className="max-h-48 space-y-1.5 overflow-y-auto rounded border border-border bg-bg px-3 py-2"
|
||||
>
|
||||
{availableConnections.map((c) => {
|
||||
const checked = connectionIds.includes(c.id);
|
||||
const isPrimary = connectionIds[0] === c.id;
|
||||
return (
|
||||
<label
|
||||
<Checkbox
|
||||
key={c.id}
|
||||
className="flex items-center gap-2 cursor-pointer select-none py-0.5"
|
||||
>
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={checked}
|
||||
onChange={() => {
|
||||
setConnectionIds((prev) => {
|
||||
if (prev.includes(c.id)) {
|
||||
const next = prev.filter((id) => id !== c.id);
|
||||
if (next.length === 0) setPoolName("");
|
||||
return next;
|
||||
} else {
|
||||
return [...prev, c.id];
|
||||
}
|
||||
});
|
||||
}}
|
||||
className="accent-primary w-3.5 h-3.5 shrink-0"
|
||||
/>
|
||||
<span className="text-sm truncate">{connLabel(c)}</span>
|
||||
{isPrimary && (
|
||||
<span className="text-[10px] font-semibold text-primary bg-primary/10 px-1.5 py-0.5 rounded shrink-0">
|
||||
{t("wizardPrimaryBadge")}
|
||||
checked={checked}
|
||||
onChange={() => {
|
||||
setConnectionIds((prev) => {
|
||||
if (prev.includes(c.id)) {
|
||||
const next = prev.filter((id) => id !== c.id);
|
||||
if (next.length === 0) setPoolName("");
|
||||
return next;
|
||||
} else {
|
||||
return [...prev, c.id];
|
||||
}
|
||||
});
|
||||
}}
|
||||
label={
|
||||
<span className="flex min-w-0 items-center gap-2">
|
||||
<span className="truncate text-sm">{connLabel(c)}</span>
|
||||
{isPrimary && (
|
||||
<Badge size="sm" variant="primary" className="shrink-0">
|
||||
{t("wizardPrimaryBadge")}
|
||||
</Badge>
|
||||
)}
|
||||
</span>
|
||||
)}
|
||||
</label>
|
||||
}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
{connections
|
||||
.filter((c) => existingPoolConnectionIds.has(c.id))
|
||||
.map((c) => (
|
||||
<label
|
||||
<Checkbox
|
||||
key={c.id}
|
||||
className="flex items-center gap-2 cursor-not-allowed select-none py-0.5 opacity-40"
|
||||
>
|
||||
<input
|
||||
type="checkbox"
|
||||
disabled
|
||||
checked={false}
|
||||
readOnly
|
||||
className="w-3.5 h-3.5 shrink-0"
|
||||
/>
|
||||
<span className="text-sm truncate">
|
||||
{connLabel(c)} {t("alreadyUsedSuffix")}
|
||||
{connectionPoolName[c.id] ? ` — ${connectionPoolName[c.id]}` : ""}
|
||||
</span>
|
||||
</label>
|
||||
disabled
|
||||
checked={false}
|
||||
readOnly
|
||||
className="opacity-60"
|
||||
label={
|
||||
<span className="truncate text-sm">
|
||||
{connLabel(c)} {t("alreadyUsedSuffix")}
|
||||
{connectionPoolName[c.id] ? ` — ${connectionPoolName[c.id]}` : ""}
|
||||
</span>
|
||||
}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
{connections.length === 0 && (
|
||||
<p className="text-[10px] text-amber-400 mt-1">{t("noEligibleConnections")}</p>
|
||||
<p className="text-[10px] text-warning mt-1">{t("noEligibleConnections")}</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Pool name */}
|
||||
{connectionIds.length > 0 && (
|
||||
<div>
|
||||
<label className="text-[11px] uppercase tracking-wide text-text-muted font-semibold block mb-1">
|
||||
{t("wizardPoolNameLabel")}
|
||||
</label>
|
||||
<input
|
||||
<Input
|
||||
type="text"
|
||||
label={t("wizardPoolNameLabel")}
|
||||
value={poolName}
|
||||
onChange={(e) => setPoolName(e.target.value)}
|
||||
placeholder={
|
||||
selectedConn ? selectedConn.provider : t("wizardPoolNamePlaceholder")
|
||||
}
|
||||
className="w-full px-3 py-2 rounded border border-border bg-bg-base text-sm"
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
@@ -733,61 +735,52 @@ export default function PoolWizard({
|
||||
{/* Group picker */}
|
||||
{connectionIds.length > 0 && groups.length > 0 && (
|
||||
<div>
|
||||
<label className="text-[11px] uppercase tracking-wide text-text-muted font-semibold block mb-1">
|
||||
{t("wizardGroupLabel")}
|
||||
</label>
|
||||
<select
|
||||
<Select
|
||||
label={t("wizardGroupLabel")}
|
||||
value={groupId}
|
||||
onChange={(e) => setGroupId(e.target.value)}
|
||||
className="w-full px-3 py-2 rounded border border-border bg-bg-base text-sm"
|
||||
>
|
||||
{groups.map((g) => (
|
||||
<option key={g.id} value={g.id}>
|
||||
{g.name}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</Select>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Default policy */}
|
||||
{connectionIds.length > 0 && (
|
||||
<div>
|
||||
<label className="text-[11px] uppercase tracking-wide text-text-muted font-semibold block mb-1">
|
||||
<span className="mb-1 block text-[11px] font-semibold uppercase tracking-wide text-text-muted">
|
||||
{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"
|
||||
</span>
|
||||
<SegmentedControl
|
||||
aria-label={t("policyLabel")}
|
||||
size="sm"
|
||||
value={defaultPolicy}
|
||||
onChange={(value) => setDefaultPolicy(value as Policy)}
|
||||
options={(["hard", "soft", "burst"] as Policy[]).map((p) => ({
|
||||
value: p,
|
||||
label:
|
||||
p === "hard"
|
||||
? t("policyHard")
|
||||
: p === "soft"
|
||||
? t("policySoft")
|
||||
: t("policyBurst")}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
: t("policyBurst"),
|
||||
}))}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="flex justify-end pt-2">
|
||||
<button
|
||||
<Button
|
||||
onClick={() => setStep(2)}
|
||||
disabled={connectionIds.length === 0}
|
||||
className="flex items-center gap-1.5 text-sm px-4 py-2 rounded-lg bg-primary text-accent-foreground hover:bg-primary/90 transition-colors disabled:opacity-40 disabled:cursor-not-allowed"
|
||||
iconRight="arrow_forward"
|
||||
>
|
||||
{t("wizardNext")}
|
||||
<span className="material-symbols-outlined text-[16px]">arrow_forward</span>
|
||||
</button>
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
@@ -803,19 +796,14 @@ export default function PoolWizard({
|
||||
</div>
|
||||
|
||||
{/* Dimensions editor (ported from ProviderPlanConfigClient) */}
|
||||
<div className="rounded-lg border border-border/40 bg-bg-subtle/10 p-3">
|
||||
<div className="rounded-lg border border-border bg-bg-subtle p-3">
|
||||
<div className="flex items-center justify-between mb-2">
|
||||
<span className="text-[11px] uppercase tracking-wide font-bold text-text-muted">
|
||||
{tPlans("dimensionLabel")}
|
||||
</span>
|
||||
<button
|
||||
type="button"
|
||||
onClick={addDimension}
|
||||
className="text-[11px] text-primary hover:underline cursor-pointer flex items-center gap-1"
|
||||
>
|
||||
<span className="material-symbols-outlined text-[14px]">add</span>
|
||||
<Button variant="ghost" size="sm" icon="add" onClick={addDimension}>
|
||||
{tPlans("addDimension")}
|
||||
</button>
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{editDimensions.length === 0 && (
|
||||
@@ -831,76 +819,73 @@ export default function PoolWizard({
|
||||
className="grid items-center gap-2"
|
||||
style={{ gridTemplateColumns: "1fr 1fr 90px 24px" }}
|
||||
>
|
||||
<select
|
||||
<Select
|
||||
aria-label={tPlans("dimensionLabel")}
|
||||
value={dim.unit}
|
||||
onChange={(e) => updateDimension(i, { unit: e.target.value as QuotaUnit })}
|
||||
className="px-2 py-1.5 rounded border border-border bg-bg-base text-xs"
|
||||
selectClassName="ci-select-native--sm text-xs"
|
||||
>
|
||||
{UNIT_OPTIONS.map((u) => (
|
||||
<option key={u} value={u}>
|
||||
{tPlans(`unitOptions.${u}`)}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
<select
|
||||
</Select>
|
||||
<Select
|
||||
aria-label={tPlans(`windowOptions.${dim.window}`)}
|
||||
value={dim.window}
|
||||
onChange={(e) =>
|
||||
updateDimension(i, { window: e.target.value as QuotaWindow })
|
||||
}
|
||||
className="px-2 py-1.5 rounded border border-border bg-bg-base text-xs"
|
||||
selectClassName="ci-select-native--sm text-xs"
|
||||
>
|
||||
{WINDOW_OPTIONS.map((w) => (
|
||||
<option key={w} value={w}>
|
||||
{tPlans(`windowOptions.${w}`)}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
<input
|
||||
</Select>
|
||||
<Input
|
||||
type="number"
|
||||
min={0}
|
||||
aria-label={tPlans("limitLabel")}
|
||||
value={dim.limit}
|
||||
onChange={(e) => updateDimension(i, { limit: Number(e.target.value) })}
|
||||
placeholder={tPlans("limitLabel")}
|
||||
className="px-2 py-1.5 rounded border border-border bg-bg-base text-xs tabular-nums text-right"
|
||||
inputClassName="h-8 min-h-8 text-right text-xs tabular-nums"
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon-sm"
|
||||
onClick={() => removeDimension(i)}
|
||||
className="p-0.5 rounded hover:bg-red-500/10 text-text-muted hover:text-red-400 cursor-pointer"
|
||||
aria-label={t("wizardRemoveDimension")}
|
||||
className="size-6 min-h-6 text-text-muted hover:bg-error/10 hover:text-error"
|
||||
>
|
||||
<span className="material-symbols-outlined text-[16px]">close</span>
|
||||
</button>
|
||||
<Icon name="close" size={16} />
|
||||
</Button>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{dimensionsEdited && (
|
||||
<p className="text-[10px] text-amber-400">{t("wizardDimensionsEditedNotice")}</p>
|
||||
<p className="text-[10px] text-warning">{t("wizardDimensionsEditedNotice")}</p>
|
||||
)}
|
||||
|
||||
{/* Helper note when pool has multiple connections */}
|
||||
{connectionIds.length > 1 && (
|
||||
<p className="text-[10px] text-text-muted bg-bg-subtle/40 px-3 py-2 rounded border border-border/40">
|
||||
<p className="rounded border border-border bg-bg-subtle px-3 py-2 text-[10px] text-text-muted">
|
||||
{t("wizardAdditionalConnectionsNote")}
|
||||
</p>
|
||||
)}
|
||||
|
||||
<div className="flex items-center justify-between pt-2">
|
||||
<button
|
||||
onClick={() => setStep(1)}
|
||||
className="flex items-center gap-1.5 text-sm px-4 py-2 rounded-lg border border-border text-text-muted hover:text-text-main hover:bg-black/5 dark:hover:bg-white/5 transition-colors"
|
||||
>
|
||||
<span className="material-symbols-outlined text-[16px]">arrow_back</span>
|
||||
<Button variant="outline" icon="arrow_back" onClick={() => setStep(1)}>
|
||||
{t("wizardBack")}
|
||||
</button>
|
||||
<button
|
||||
onClick={() => setStep(3)}
|
||||
className="flex items-center gap-1.5 text-sm px-4 py-2 rounded-lg bg-primary text-accent-foreground hover:bg-primary/90 transition-colors"
|
||||
>
|
||||
</Button>
|
||||
<Button iconRight="arrow_forward" onClick={() => setStep(3)}>
|
||||
{t("wizardNext")}
|
||||
<span className="material-symbols-outlined text-[16px]">arrow_forward</span>
|
||||
</button>
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
@@ -917,13 +902,13 @@ export default function PoolWizard({
|
||||
|
||||
{/* Allocation rows (ported from EditAllocationsModal) */}
|
||||
{allocations.length === 0 ? (
|
||||
<div className="text-[12px] text-text-muted italic py-4 text-center bg-bg-subtle/40 rounded-md">
|
||||
<div className="rounded-md bg-bg-subtle py-4 text-center text-[12px] italic text-text-muted">
|
||||
{t("noKeysAdded")}
|
||||
</div>
|
||||
) : (
|
||||
<div className="space-y-2">
|
||||
{allocations.map((a, i) => {
|
||||
const color = SLICE_PALETTE[i % SLICE_PALETTE.length];
|
||||
const color = getSeriesColor(i);
|
||||
return (
|
||||
<div
|
||||
key={a.apiKeyId}
|
||||
@@ -935,16 +920,17 @@ export default function PoolWizard({
|
||||
style={{ background: color }}
|
||||
/>
|
||||
<span className="text-[12px] font-mono truncate">{keyLabel(a.apiKeyId)}</span>
|
||||
<input
|
||||
<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"
|
||||
inputClassName="h-8 min-h-8 px-2 text-right tabular-nums"
|
||||
title={t("weightPercent")}
|
||||
aria-label={t("weightPercent")}
|
||||
/>
|
||||
<input
|
||||
<Input
|
||||
type="number"
|
||||
min={0}
|
||||
value={a.capValue ?? ""}
|
||||
@@ -955,27 +941,31 @@ export default function PoolWizard({
|
||||
)
|
||||
}
|
||||
placeholder={t("policyCapAbsolutePlaceholder")}
|
||||
className="px-2 py-1 rounded border border-border bg-bg-base text-xs tabular-nums"
|
||||
inputClassName="h-8 min-h-8 px-2 text-xs tabular-nums"
|
||||
title={t("policyCapAbsoluteLabel")}
|
||||
aria-label={t("policyCapAbsoluteLabel")}
|
||||
/>
|
||||
<select
|
||||
<Select
|
||||
aria-label={t("policyLabel")}
|
||||
value={a.policy}
|
||||
onChange={(e) =>
|
||||
updateAllocationPolicy(a.apiKeyId, e.target.value as Policy)
|
||||
}
|
||||
className="px-1 py-1 rounded border border-border bg-bg-base text-xs"
|
||||
selectClassName="ci-select-native--sm text-xs"
|
||||
>
|
||||
<option value="hard">{t("policyHard")}</option>
|
||||
<option value="soft">{t("policySoft")}</option>
|
||||
<option value="burst">{t("policyBurst")}</option>
|
||||
</select>
|
||||
<button
|
||||
type="button"
|
||||
</Select>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon-sm"
|
||||
onClick={() => removeAllocation(a.apiKeyId)}
|
||||
className="p-0.5 rounded hover:bg-red-500/10 text-text-muted hover:text-red-400 cursor-pointer"
|
||||
aria-label={t("wizardRemoveKey")}
|
||||
className="size-6 min-h-6 text-text-muted hover:bg-error/10 hover:text-error"
|
||||
>
|
||||
<span className="material-symbols-outlined text-[16px]">close</span>
|
||||
</button>
|
||||
<Icon name="close" size={16} />
|
||||
</Button>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
@@ -983,14 +973,14 @@ export default function PoolWizard({
|
||||
)}
|
||||
|
||||
{/* Add key + equal split controls */}
|
||||
<div className="flex items-center justify-between text-[11px] pt-1 border-t border-border/40">
|
||||
<div className="flex flex-wrap items-center justify-between gap-2 border-t border-border pt-1 text-[11px]">
|
||||
<span
|
||||
className={`font-bold tabular-nums ${
|
||||
totalWeight === 100
|
||||
? "text-emerald-400"
|
||||
? "text-success"
|
||||
: totalWeight > 100
|
||||
? "text-red-400"
|
||||
: "text-amber-400"
|
||||
? "text-error"
|
||||
: "text-warning"
|
||||
}`}
|
||||
>
|
||||
{t("totalLabel", { percent: totalWeight })}{" "}
|
||||
@@ -998,10 +988,11 @@ export default function PoolWizard({
|
||||
</span>
|
||||
<div className="flex items-center gap-2">
|
||||
{availableKeys.length > 0 && (
|
||||
<select
|
||||
<Select
|
||||
aria-label={t("addKey")}
|
||||
value=""
|
||||
onChange={(e) => e.target.value && addKey(e.target.value)}
|
||||
className="px-2 py-1 rounded border border-border bg-bg-base text-xs"
|
||||
selectClassName="ci-select-native--sm text-xs"
|
||||
>
|
||||
<option value="">{t("addKey")}</option>
|
||||
{availableKeys.map((k) => (
|
||||
@@ -1009,7 +1000,7 @@ export default function PoolWizard({
|
||||
{k.name || k.id.slice(0, 12) + "…"}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</Select>
|
||||
)}
|
||||
<Button
|
||||
variant="secondary"
|
||||
@@ -1023,24 +1014,26 @@ export default function PoolWizard({
|
||||
</div>
|
||||
|
||||
{/* Exclusive checkbox */}
|
||||
<label className="flex items-start gap-2 cursor-pointer select-none pt-1 border-t border-border/40">
|
||||
<input
|
||||
type="checkbox"
|
||||
<div className="border-t border-border pt-2">
|
||||
<Checkbox
|
||||
checked={exclusive}
|
||||
onChange={(e) => setExclusive(e.target.checked)}
|
||||
className="mt-0.5 accent-primary w-4 h-4"
|
||||
label={
|
||||
<span className="flex flex-col">
|
||||
<span className="text-sm font-semibold text-text-main">
|
||||
{t("wizardExclusiveLabel")}
|
||||
</span>
|
||||
<span className="mt-0.5 text-[11px] text-text-muted">
|
||||
{t("wizardExclusiveHint")}
|
||||
</span>
|
||||
</span>
|
||||
}
|
||||
/>
|
||||
<div>
|
||||
<span className="text-sm font-semibold text-text-main">
|
||||
{t("wizardExclusiveLabel")}
|
||||
</span>
|
||||
<p className="text-[11px] text-text-muted mt-0.5">{t("wizardExclusiveHint")}</p>
|
||||
</div>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
{/* quotaModelName preview — grouped by provider */}
|
||||
{previewByProvider.length > 0 && (
|
||||
<div className="rounded-md border border-border/40 bg-bg-subtle/30 p-3 text-[11px]">
|
||||
<div className="rounded-md border border-border bg-bg-subtle p-3 text-[11px]">
|
||||
<div className="font-semibold text-text-muted uppercase tracking-wide mb-1.5 text-[10px]">
|
||||
{t("wizardPreviewLabel")}
|
||||
</div>
|
||||
@@ -1074,22 +1067,24 @@ export default function PoolWizard({
|
||||
)}
|
||||
|
||||
{error && (
|
||||
<p className="text-[11px] text-red-400 bg-red-500/10 px-3 py-2 rounded">{error}</p>
|
||||
<p role="alert" className="rounded bg-error/10 px-3 py-2 text-[11px] text-error">
|
||||
{error}
|
||||
</p>
|
||||
)}
|
||||
|
||||
<div className="flex items-center justify-between pt-2 border-t border-border/40">
|
||||
<button
|
||||
<div className="flex items-center justify-between border-t border-border pt-2">
|
||||
<Button
|
||||
variant="outline"
|
||||
icon="arrow_back"
|
||||
onClick={() => setStep(2)}
|
||||
disabled={saving}
|
||||
className="flex items-center gap-1.5 text-sm px-4 py-2 rounded-lg border border-border text-text-muted hover:text-text-main hover:bg-black/5 dark:hover:bg-white/5 transition-colors disabled:opacity-40"
|
||||
>
|
||||
<span className="material-symbols-outlined text-[16px]">arrow_back</span>
|
||||
{t("wizardBack")}
|
||||
</button>
|
||||
</Button>
|
||||
<Button
|
||||
variant="primary"
|
||||
size="sm"
|
||||
onClick={() => void handleFinish()}
|
||||
loading={saving}
|
||||
disabled={totalWeight > 100 || saving}
|
||||
>
|
||||
{saving ? t("loading") : editPool ? t("saveChanges") : t("wizardCreatePool")}
|
||||
|
||||
@@ -1,34 +1,19 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { useTranslations } from "next-intl";
|
||||
import Card from "@/shared/components/Card";
|
||||
import Collapsible from "@/shared/components/Collapsible";
|
||||
import Icon from "@/shared/components/Icon";
|
||||
|
||||
export default function QuotaConceptCard() {
|
||||
const t = useTranslations("quotaShare");
|
||||
const [expanded, setExpanded] = useState(false);
|
||||
|
||||
// Kit Accordion (Collapsible adapter): collapsed by default, as before.
|
||||
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">
|
||||
<div data-testid="quota-concept-card">
|
||||
<Collapsible title={t("conceptTitle")} icon="info">
|
||||
<div className="space-y-2 text-xs leading-relaxed text-text-muted">
|
||||
<p>{t("conceptIntro")}</p>
|
||||
<div className="grid grid-cols-1 sm:grid-cols-2 gap-2 pt-1">
|
||||
<div className="grid grid-cols-1 gap-2 pt-1 sm:grid-cols-2">
|
||||
<ConceptItem icon="balance" text={t("conceptFairShare")} />
|
||||
<ConceptItem icon="trending_up" text={t("conceptBorrowing")} />
|
||||
<ConceptItem icon="lock" text={t("conceptGlobalCap")} />
|
||||
@@ -45,17 +30,15 @@ export default function QuotaConceptCard() {
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</Card>
|
||||
</Collapsible>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
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>
|
||||
<div className="flex items-start gap-1.5 rounded-md bg-bg-subtle p-2">
|
||||
<Icon name={icon} size={16} className="text-primary mt-0.5" />
|
||||
<span>{text}</span>
|
||||
</div>
|
||||
);
|
||||
@@ -63,10 +46,8 @@ function ConceptItem({ icon, text }: { icon: string; text: string }) {
|
||||
|
||||
function ConceptItemWithDesc({ icon, title, desc }: { icon: string; title: string; desc: 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>
|
||||
<div className="flex items-start gap-1.5 rounded-md bg-bg-subtle p-2">
|
||||
<Icon name={icon} size={16} className="text-primary mt-0.5" />
|
||||
<div className="flex flex-col gap-0.5">
|
||||
<span className="font-semibold text-text-main">{title}</span>
|
||||
<span className="text-text-muted">{desc}</span>
|
||||
|
||||
@@ -4,7 +4,10 @@ import { useState, useMemo, useEffect } from "react";
|
||||
import { useTranslations } from "next-intl";
|
||||
import useEmailPrivacyStore from "@/store/emailPrivacyStore";
|
||||
import { maskEmailLikeValue } from "@/shared/utils/maskEmail";
|
||||
import Button from "@/shared/components/Button";
|
||||
import Card from "@/shared/components/Card";
|
||||
import Icon from "@/shared/components/Icon";
|
||||
import Select from "@/shared/components/Select";
|
||||
import {
|
||||
quotaModelName,
|
||||
quotaGroupSlug,
|
||||
@@ -206,9 +209,10 @@ export default function QuotaEndpointsCard({
|
||||
}, [groups, pools, connections]);
|
||||
|
||||
// Real qtSd combos grouped by group → provider (preferred over placeholders).
|
||||
const realByGroup = useMemo<
|
||||
Array<{ group: QuotaGroup; entries: Array<{ provider: string; models: string[] }> }> | null
|
||||
>(() => {
|
||||
const realByGroup = useMemo<Array<{
|
||||
group: QuotaGroup;
|
||||
entries: Array<{ provider: string; models: string[] }>;
|
||||
}> | null>(() => {
|
||||
if (!realCombos || realCombos.length === 0) return null;
|
||||
const byGroupSlug = new Map<string, Map<string, string[]>>();
|
||||
for (const name of realCombos) {
|
||||
@@ -269,9 +273,7 @@ export default function QuotaEndpointsCard({
|
||||
|
||||
// ── Compute the combined default model count across all groups ────────────────
|
||||
|
||||
const hasAnyDefaultModels = viewByGroup.some((g) =>
|
||||
g.entries.some((e) => e.models.length > 0)
|
||||
);
|
||||
const hasAnyDefaultModels = viewByGroup.some((g) => g.entries.some((e) => e.models.length > 0));
|
||||
|
||||
// ── Render ───────────────────────────────────────────────────────────────────
|
||||
|
||||
@@ -282,9 +284,7 @@ export default function QuotaEndpointsCard({
|
||||
{/* 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>
|
||||
<Icon name="api" size={18} className="text-primary mt-0.5" />
|
||||
<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>
|
||||
@@ -295,13 +295,12 @@ export default function QuotaEndpointsCard({
|
||||
<div className="flex items-center gap-2 shrink-0">
|
||||
{apiKeys.length > 0 && (
|
||||
<>
|
||||
<label className="text-xs text-text-muted whitespace-nowrap">
|
||||
{t("previewForKey")}
|
||||
</label>
|
||||
<select
|
||||
<Select
|
||||
compact
|
||||
label={t("previewForKey")}
|
||||
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]"
|
||||
selectClassName="min-w-[140px]"
|
||||
>
|
||||
<option value="">{t("previewKeyNone")}</option>
|
||||
{apiKeys.map((k) => (
|
||||
@@ -309,145 +308,145 @@ export default function QuotaEndpointsCard({
|
||||
{keyLabel(k)}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</Select>
|
||||
</>
|
||||
)}
|
||||
<button
|
||||
type="button"
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon-sm"
|
||||
onClick={() => setCollapsed((c) => !c)}
|
||||
title={collapsed ? t("endpointsExpand") : t("endpointsCollapse")}
|
||||
aria-label={collapsed ? t("endpointsExpand") : t("endpointsCollapse")}
|
||||
className="p-1 rounded hover:bg-black/5 dark:hover:bg-white/5 text-text-muted hover:text-text-main transition-colors cursor-pointer"
|
||||
aria-expanded={!collapsed}
|
||||
className="text-text-muted"
|
||||
>
|
||||
<span className="material-symbols-outlined text-[18px]">
|
||||
{collapsed ? "expand_more" : "expand_less"}
|
||||
</span>
|
||||
</button>
|
||||
<Icon name={collapsed ? "expand_more" : "expand_less"} size={18} />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{!collapsed && (
|
||||
<>
|
||||
{/* Base URL line(s) */}
|
||||
<div className="mt-3 rounded-md bg-bg-subtle/50 border border-border/40 px-3 py-2 space-y-1">
|
||||
<div className="flex items-center gap-2 flex-wrap">
|
||||
<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>
|
||||
{hasAnthropic && (
|
||||
<div className="flex items-center gap-2 flex-wrap">
|
||||
<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/messages</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>
|
||||
<span className="text-[10px] text-text-muted">({t("endpointsAnthropicNote")})</span>
|
||||
</div>
|
||||
)}
|
||||
{hasResponses && (
|
||||
<div className="flex items-center gap-2 flex-wrap">
|
||||
<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/responses</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>
|
||||
<span className="text-[10px] text-text-muted">({t("endpointsResponsesNote")})</span>
|
||||
</div>
|
||||
)}
|
||||
{hasCodex && (
|
||||
<div className="flex items-center gap-2 flex-wrap">
|
||||
<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">WS /v1/responses</code>
|
||||
<span className="text-xs text-text-muted mx-1">·</span>
|
||||
<code className="text-xs text-text-muted font-mono">
|
||||
model: "qtSd/<group>/codex/<model>"
|
||||
</code>
|
||||
<span className="text-[10px] text-text-muted">({t("endpointsWsNote")})</span>
|
||||
</div>
|
||||
)}
|
||||
</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>
|
||||
{/* Base URL line(s) */}
|
||||
<div className="mt-3 rounded-md bg-bg-subtle border border-border px-3 py-2 space-y-1">
|
||||
<div className="flex items-center gap-2 flex-wrap">
|
||||
<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>
|
||||
{hasAnthropic && (
|
||||
<div className="flex items-center gap-2 flex-wrap">
|
||||
<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/messages</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>
|
||||
<span className="text-[10px] text-text-muted">({t("endpointsAnthropicNote")})</span>
|
||||
</div>
|
||||
)}
|
||||
{hasResponses && (
|
||||
<div className="flex items-center gap-2 flex-wrap">
|
||||
<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/responses</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>
|
||||
<span className="text-[10px] text-text-muted">({t("endpointsResponsesNote")})</span>
|
||||
</div>
|
||||
)}
|
||||
{hasCodex && (
|
||||
<div className="flex items-center gap-2 flex-wrap">
|
||||
<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">WS /v1/responses</code>
|
||||
<span className="text-xs text-text-muted mx-1">·</span>
|
||||
<code className="text-xs text-text-muted font-mono">
|
||||
model: "qtSd/<group>/codex/<model>"
|
||||
</code>
|
||||
<span className="text-[10px] text-text-muted">({t("endpointsWsNote")})</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
) : hasData && hasAnyDefaultModels ? (
|
||||
// Default view: grouped by group → provider → real qtSd model ids
|
||||
<div className="space-y-3">
|
||||
{viewByGroup.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>
|
||||
|
||||
{/* 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>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</ul>
|
||||
)}
|
||||
</div>
|
||||
) : hasData && hasAnyDefaultModels ? (
|
||||
// Default view: grouped by group → provider → real qtSd model ids
|
||||
<div className="space-y-3">
|
||||
{viewByGroup.map(({ group, entries }) => {
|
||||
if (entries.length === 0) return null;
|
||||
return (
|
||||
<div key={group.id}>
|
||||
<div className="flex items-center gap-1.5 mb-1">
|
||||
<Icon name="folder" size={13} className="text-text-muted" />
|
||||
<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>
|
||||
) : (
|
||||
// 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>
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
import { useTranslations } from "next-intl";
|
||||
import type { PoolAllocation } from "@/lib/quota/dimensions";
|
||||
import type { PoolUsageSnapshot } from "@/lib/quota/types";
|
||||
import { getSeriesColor } from "@/shared/components/analytics/chartColors";
|
||||
|
||||
export interface StackedAllocationBarProps {
|
||||
allocations: PoolAllocation[];
|
||||
@@ -13,17 +14,6 @@ export interface StackedAllocationBarProps {
|
||||
dimensionIndex?: number;
|
||||
}
|
||||
|
||||
const PALETTE = [
|
||||
"#a78bfa",
|
||||
"#60a5fa",
|
||||
"#34d399",
|
||||
"#fbbf24",
|
||||
"#f87171",
|
||||
"#22d3ee",
|
||||
"#f472b6",
|
||||
"#94a3b8",
|
||||
];
|
||||
|
||||
export default function StackedAllocationBar({
|
||||
allocations,
|
||||
usage,
|
||||
@@ -56,7 +46,7 @@ export default function StackedAllocationBar({
|
||||
{/* Stacked bar */}
|
||||
<div className="flex h-3 rounded overflow-hidden w-full mb-2">
|
||||
{allocations.map((alloc, i) => {
|
||||
const color = PALETTE[i % PALETTE.length];
|
||||
const color = getSeriesColor(i);
|
||||
const keyUsage = perKeyMap[alloc.apiKeyId];
|
||||
let consumedPercent: number | null = null;
|
||||
if (keyUsage && keyUsage.fairShare > 0) {
|
||||
@@ -81,7 +71,7 @@ export default function StackedAllocationBar({
|
||||
{/* Labels */}
|
||||
<div className="flex flex-wrap gap-x-3 gap-y-1">
|
||||
{allocations.map((alloc, i) => {
|
||||
const color = PALETTE[i % PALETTE.length];
|
||||
const color = getSeriesColor(i);
|
||||
const keyUsage = perKeyMap[alloc.apiKeyId];
|
||||
let consumedPercent: number | null = null;
|
||||
if (keyUsage && keyUsage.fairShare > 0) {
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
import { useState, useEffect } from "react";
|
||||
import { useTranslations } from "next-intl";
|
||||
import Button from "@/shared/components/Button";
|
||||
import Icon from "@/shared/components/Icon";
|
||||
import type { ConsumptionEvent } from "@/lib/db/quotaConsumption";
|
||||
|
||||
export interface UsageLogCardProps {
|
||||
@@ -46,7 +48,7 @@ export default function UsageLogCard({ poolId, keyLabels }: UsageLogCardProps) {
|
||||
.then((data) => {
|
||||
if (!alive) return;
|
||||
const raw: unknown = data?.events;
|
||||
setEvents(Array.isArray(raw) ? (raw as ConsumptionEvent[]) : [] ?? []);
|
||||
setEvents(Array.isArray(raw) ? (raw as ConsumptionEvent[]) : ([] ?? []));
|
||||
setLoaded(true);
|
||||
})
|
||||
.catch(() => {
|
||||
@@ -64,19 +66,21 @@ export default function UsageLogCard({ poolId, keyLabels }: UsageLogCardProps) {
|
||||
keyLabels?.[apiKeyId] ?? apiKeyId.slice(0, 10) + "…";
|
||||
|
||||
return (
|
||||
<div className="mt-2 pt-2 border-t border-border/30">
|
||||
<button
|
||||
type="button"
|
||||
<div className="mt-2 pt-2 border-t border-border">
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={() => setOpen((prev) => !prev)}
|
||||
className="flex items-center gap-1 text-[10px] uppercase tracking-wide font-bold text-text-muted hover:text-text-main w-full text-left cursor-pointer"
|
||||
aria-expanded={open}
|
||||
className="h-7 min-h-7 w-full justify-start gap-1 px-1 text-[10px] font-bold uppercase tracking-wide text-text-muted"
|
||||
>
|
||||
<span
|
||||
className={`material-symbols-outlined text-[13px] transition-transform ${open ? "rotate-90" : ""}`}
|
||||
>
|
||||
chevron_right
|
||||
</span>
|
||||
<Icon
|
||||
name="chevron_right"
|
||||
size={13}
|
||||
className={`transition-transform ${open ? "rotate-90" : ""}`}
|
||||
/>
|
||||
{t("logTitle")}
|
||||
</button>
|
||||
</Button>
|
||||
|
||||
{open && (
|
||||
<div className="mt-1.5">
|
||||
|
||||
@@ -34,14 +34,9 @@ interface PoolCreate {
|
||||
export function adaptLsPoolToApiSchema(lsPool: LsPool): PoolCreate {
|
||||
const connectionId = lsPool.connectionId || "";
|
||||
const name =
|
||||
lsPool.accountLabel ||
|
||||
lsPool.provider ||
|
||||
lsPool.connectionId?.slice(0, 12) ||
|
||||
"Migrated pool";
|
||||
lsPool.accountLabel || lsPool.provider || lsPool.connectionId?.slice(0, 12) || "Migrated pool";
|
||||
const policy: Policy =
|
||||
lsPool.policy === "soft" || lsPool.policy === "burst"
|
||||
? (lsPool.policy as Policy)
|
||||
: "hard";
|
||||
lsPool.policy === "soft" || lsPool.policy === "burst" ? (lsPool.policy as Policy) : "hard";
|
||||
|
||||
const allocations: PoolAllocation[] = (lsPool.allocations || [])
|
||||
.filter((a) => a.apiKeyId)
|
||||
|
||||
@@ -32,10 +32,14 @@ export function usePoolsUsageAggregate(pools: QuotaPool[]): PoolsUsageAggregate
|
||||
const fetchAll = async () => {
|
||||
try {
|
||||
const snapshots = await Promise.all(
|
||||
ids.map((id) => fetch(`/api/quota/pools/${id}/usage`).then((r) => (r.ok ? r.json() : null)))
|
||||
ids.map((id) =>
|
||||
fetch(`/api/quota/pools/${id}/usage`).then((r) => (r.ok ? r.json() : null))
|
||||
)
|
||||
);
|
||||
if (!mounted) return;
|
||||
const valid = snapshots.filter((s): s is { usage: PoolUsageSnapshot } => s !== null && !!s.usage);
|
||||
const valid = snapshots.filter(
|
||||
(s): s is { usage: PoolUsageSnapshot } => s !== null && !!s.usage
|
||||
);
|
||||
let totalUtil = 0;
|
||||
let utilCount = 0;
|
||||
let borrowing = 0;
|
||||
@@ -58,7 +62,11 @@ export function usePoolsUsageAggregate(pools: QuotaPool[]): PoolsUsageAggregate
|
||||
});
|
||||
} catch (err) {
|
||||
if (mounted) {
|
||||
setState((s) => ({ ...s, loading: false, error: err instanceof Error ? err.message : "fetch failed" }));
|
||||
setState((s) => ({
|
||||
...s,
|
||||
loading: false,
|
||||
error: err instanceof Error ? err.message : "fetch failed",
|
||||
}));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
"use client";
|
||||
|
||||
import { useState, useEffect } from "react";
|
||||
import { Card } from "@/shared/components";
|
||||
import { Badge, Card, Skeleton } from "@/shared/components";
|
||||
import Icon from "@/shared/components/Icon";
|
||||
import { useTranslations } from "next-intl";
|
||||
|
||||
interface CompressionStats {
|
||||
@@ -40,8 +41,9 @@ export default function CompressionLogTab() {
|
||||
|
||||
if (loading) {
|
||||
return (
|
||||
<Card className="p-6">
|
||||
<p className="text-sm text-text-muted">{t("loading")}</p>
|
||||
<Card className="p-6" aria-busy="true">
|
||||
<span className="ci-sr-only">{t("loading")}</span>
|
||||
<Skeleton className="h-16 w-full" />
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
@@ -50,7 +52,7 @@ export default function CompressionLogTab() {
|
||||
return (
|
||||
<Card className="p-6">
|
||||
<div className="flex items-center gap-3 mb-4">
|
||||
<span className="material-symbols-outlined text-blue-500 text-[20px]">compress</span>
|
||||
<Icon name="compress" size={20} className="text-info" />
|
||||
<h3 className="text-lg font-semibold">{t("compressionLogTitle")}</h3>
|
||||
</div>
|
||||
<p className="text-sm text-text-muted">{t("compressionLogEmpty")}</p>
|
||||
@@ -61,7 +63,7 @@ export default function CompressionLogTab() {
|
||||
return (
|
||||
<Card className="p-6">
|
||||
<div className="flex items-center gap-3 mb-5">
|
||||
<span className="material-symbols-outlined text-blue-500 text-[20px]">compress</span>
|
||||
<Icon name="compress" size={20} className="text-info" />
|
||||
<h3 className="text-lg font-semibold">{t("compressionLogTitle")}</h3>
|
||||
</div>
|
||||
|
||||
@@ -73,16 +75,16 @@ export default function CompressionLogTab() {
|
||||
return (
|
||||
<div
|
||||
key={entry.id}
|
||||
className="p-3 rounded-lg border border-border/50 bg-surface/30 space-y-2"
|
||||
className="space-y-2 rounded-lg border border-border bg-bg-subtle p-3"
|
||||
>
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="flex items-center gap-2 text-sm">
|
||||
<span className="font-mono text-text-main">
|
||||
{entry.provider}/{entry.model}
|
||||
</span>
|
||||
<span className="px-1.5 py-0.5 rounded text-[10px] font-medium bg-blue-500/10 text-blue-400 border border-blue-500/20">
|
||||
<Badge size="sm" variant="info">
|
||||
{stats.mode}
|
||||
</span>
|
||||
</Badge>
|
||||
</div>
|
||||
<div className="flex items-center gap-3 text-xs text-text-muted">
|
||||
<span>
|
||||
@@ -91,9 +93,9 @@ export default function CompressionLogTab() {
|
||||
<span
|
||||
className={`font-medium ${
|
||||
stats.savingsPercent >= 25
|
||||
? "text-emerald-400"
|
||||
? "text-success"
|
||||
: stats.savingsPercent >= 10
|
||||
? "text-yellow-400"
|
||||
? "text-warning"
|
||||
: "text-text-muted"
|
||||
}`}
|
||||
>
|
||||
@@ -106,12 +108,9 @@ export default function CompressionLogTab() {
|
||||
{stats.techniquesUsed.length > 0 && (
|
||||
<div className="flex flex-wrap gap-1">
|
||||
{stats.techniquesUsed.map((technique) => (
|
||||
<span
|
||||
key={technique}
|
||||
className="px-1.5 py-0.5 rounded text-[10px] bg-surface text-text-muted border border-border/30"
|
||||
>
|
||||
<Badge key={technique} size="sm">
|
||||
{technique}
|
||||
</span>
|
||||
</Badge>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
@@ -119,12 +118,13 @@ export default function CompressionLogTab() {
|
||||
{stats.rulesApplied && stats.rulesApplied.length > 0 && (
|
||||
<div className="flex flex-wrap gap-1">
|
||||
{stats.rulesApplied.map((rule) => (
|
||||
<span
|
||||
<Badge
|
||||
key={rule}
|
||||
className="px-1.5 py-0.5 rounded text-[10px] bg-purple-500/10 text-purple-400 border border-purple-500/20"
|
||||
size="sm"
|
||||
className="border-chart-3/20 bg-chart-3/10 text-chart-3"
|
||||
>
|
||||
{rule.replace(/_/g, " ")}
|
||||
</span>
|
||||
</Badge>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
|
||||
@@ -1,7 +1,15 @@
|
||||
"use client";
|
||||
|
||||
import { useTranslations } from "next-intl";
|
||||
import { PageHeader } from "@omniroute/ui-kit/page-header";
|
||||
import ConsoleLogViewer from "@/shared/components/ConsoleLogViewer";
|
||||
|
||||
export default function LogsConsolePage() {
|
||||
return <ConsoleLogViewer />;
|
||||
const t = useTranslations("logs");
|
||||
return (
|
||||
<div className="flex flex-col gap-6">
|
||||
<PageHeader compact title={t("console")} />
|
||||
<ConsoleLogViewer />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,9 +1,21 @@
|
||||
"use client";
|
||||
|
||||
import { useState, useRef, useEffect, Suspense } from "react";
|
||||
import { useState, useRef, Suspense } from "react";
|
||||
import { useSearchParams } from "next/navigation";
|
||||
import { ConfirmModal, RequestLoggerV2 } from "@/shared/components";
|
||||
import { useTranslations } from "next-intl";
|
||||
import { Alert } from "@omniroute/ui-kit/alert";
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuLabel,
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuTrigger,
|
||||
} from "@omniroute/ui-kit/dropdown-menu";
|
||||
import { PageHeader } from "@omniroute/ui-kit/page-header";
|
||||
import Button from "@/shared/components/Button";
|
||||
import Icon from "@/shared/components/Icon";
|
||||
import {
|
||||
buildLogExportUrl,
|
||||
readLogExportTruncation,
|
||||
@@ -49,20 +61,9 @@ function LogsPageContent() {
|
||||
const [cleaningHistory, setCleaningHistory] = useState(false);
|
||||
const [cleanHistoryStatus, setCleanHistoryStatus] = useState<string | null>(null);
|
||||
const [requestLogKey, setRequestLogKey] = useState(0);
|
||||
const dropdownRef = useRef<HTMLDivElement>(null);
|
||||
const requestLoggerRef = useRef<any>(null);
|
||||
const t = useTranslations("logs") as LogsTranslator;
|
||||
|
||||
useEffect(() => {
|
||||
function handleClickOutside(e: MouseEvent) {
|
||||
if (dropdownRef.current && !dropdownRef.current.contains(e.target as Node)) {
|
||||
setShowExport(false);
|
||||
}
|
||||
}
|
||||
document.addEventListener("mousedown", handleClickOutside);
|
||||
return () => document.removeEventListener("mousedown", handleClickOutside);
|
||||
}, []);
|
||||
|
||||
async function handleExport(hours: number) {
|
||||
setExporting(true);
|
||||
setShowExport(false);
|
||||
@@ -143,108 +144,67 @@ function LogsPageContent() {
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-6">
|
||||
<div className="flex-shrink-0 flex items-center justify-between gap-4 flex-wrap">
|
||||
<h2 className="text-lg font-semibold text-text-main">{t("requestLogs")}</h2>
|
||||
|
||||
<div className="flex items-center gap-2">
|
||||
<button
|
||||
id="clean-log-history-btn"
|
||||
onClick={() => setShowCleanHistory(true)}
|
||||
disabled={cleaningHistory}
|
||||
className="flex items-center gap-2 px-4 py-2 text-sm font-medium rounded-lg
|
||||
border border-red-500/30 bg-red-500/10 text-red-700 hover:bg-red-500/15
|
||||
hover:border-red-500/50 dark:text-red-300 dark:hover:bg-red-500/20 transition-all duration-200
|
||||
disabled:opacity-50 disabled:cursor-not-allowed"
|
||||
>
|
||||
<svg
|
||||
width="16"
|
||||
height="16"
|
||||
viewBox="0 0 16 16"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="1.5"
|
||||
<PageHeader
|
||||
compact
|
||||
title={t("requestLogs")}
|
||||
actions={
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<Button
|
||||
id="clean-log-history-btn"
|
||||
variant="outline"
|
||||
icon="delete_sweep"
|
||||
onClick={() => setShowCleanHistory(true)}
|
||||
disabled={cleaningHistory}
|
||||
className="border-error/30 text-error hover:bg-error/10"
|
||||
>
|
||||
<path
|
||||
d="M6 2h4m-5 2h6m-7 0h8m-1 0-.5 9a1 1 0 0 1-1 1h-3a1 1 0 0 1-1-1L5 4m2 3v4m2-4v4"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
/>
|
||||
</svg>
|
||||
{logsText(t, "cleanHistoryButton", "Clean history")}
|
||||
</button>
|
||||
{logsText(t, "cleanHistoryButton", "Clean history")}
|
||||
</Button>
|
||||
|
||||
<div className="relative" ref={dropdownRef}>
|
||||
<button
|
||||
id="export-logs-btn"
|
||||
onClick={() => setShowExport(!showExport)}
|
||||
disabled={exporting}
|
||||
className="flex items-center gap-2 px-4 py-2 text-sm font-medium rounded-lg
|
||||
bg-[var(--card-bg,#1e1e2e)] border border-[var(--border,#333)]
|
||||
text-[var(--text-secondary,#aaa)] hover:text-[var(--text-primary,#fff)]
|
||||
hover:border-[var(--accent,#7c3aed)] transition-all duration-200
|
||||
disabled:opacity-50 disabled:cursor-not-allowed"
|
||||
>
|
||||
<svg
|
||||
width="16"
|
||||
height="16"
|
||||
viewBox="0 0 16 16"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="1.5"
|
||||
>
|
||||
<path
|
||||
d="M8 2v8m0 0l-3-3m3 3l3-3M3 12h10"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
/>
|
||||
</svg>
|
||||
{exporting ? t("exporting") : t("export")}
|
||||
</button>
|
||||
|
||||
{showExport && (
|
||||
<div
|
||||
className="absolute right-0 top-full mt-1 z-50 min-w-[140px] rounded-lg
|
||||
bg-[var(--card-bg,#1e1e2e)] border border-[var(--border,#333)]
|
||||
shadow-xl overflow-hidden animate-in fade-in"
|
||||
>
|
||||
<div className="px-3 py-2 text-xs text-[var(--text-muted,#666)] border-b border-[var(--border,#333)] font-medium">
|
||||
{t("timeRange")}
|
||||
</div>
|
||||
{/* Kit DropdownMenu (Radix): outside click, Escape and focus return are its own. */}
|
||||
<DropdownMenu open={showExport} onOpenChange={setShowExport}>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button id="export-logs-btn" variant="outline" icon="download" disabled={exporting}>
|
||||
{exporting ? t("exporting") : t("export")}
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end" className="min-w-[160px]">
|
||||
<DropdownMenuLabel>{t("timeRange")}</DropdownMenuLabel>
|
||||
<DropdownMenuSeparator />
|
||||
{TIME_RANGES.map((range) => (
|
||||
<button
|
||||
<DropdownMenuItem
|
||||
key={range.hours}
|
||||
id={`export-${range.hours}h-btn`}
|
||||
onClick={() => handleExport(range.hours)}
|
||||
className="w-full px-3 py-2 text-sm text-left hover:bg-[var(--hover-bg,#2a2a3e)]
|
||||
text-[var(--text-secondary,#aaa)] hover:text-[var(--text-primary,#fff)]
|
||||
transition-colors flex items-center justify-between"
|
||||
onSelect={() => handleExport(range.hours)}
|
||||
shortcut={range.hours === 24 ? t("defaultRange") : undefined}
|
||||
>
|
||||
<span>{t("lastNHours", { hours: range.label })}</span>
|
||||
<span className="text-xs text-[var(--text-muted,#666)]">
|
||||
{range.hours === 24 ? t("defaultRange") : ""}
|
||||
</span>
|
||||
</button>
|
||||
{t("lastNHours", { hours: range.label })}
|
||||
</DropdownMenuItem>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
/>
|
||||
|
||||
{exportStatus && (
|
||||
<div
|
||||
<Alert
|
||||
id="export-logs-status"
|
||||
role="status"
|
||||
className="flex-shrink-0 rounded-lg border border-amber-500/30 bg-amber-500/10 px-4 py-3 text-sm text-amber-700 dark:text-amber-300"
|
||||
>
|
||||
{exportStatus}
|
||||
</div>
|
||||
variant="warning"
|
||||
icon={<Icon name="warning" size={16} />}
|
||||
dismissLabel={t("close")}
|
||||
onDismiss={() => setExportStatus(null)}
|
||||
description={exportStatus}
|
||||
/>
|
||||
)}
|
||||
|
||||
{cleanHistoryStatus && (
|
||||
<div className="flex-shrink-0 rounded-lg border border-[var(--border,#333)] bg-[var(--card-bg,#1e1e2e)] px-4 py-3 text-sm text-[var(--text-secondary,#aaa)]">
|
||||
{cleanHistoryStatus}
|
||||
</div>
|
||||
<Alert
|
||||
variant="default"
|
||||
icon={<Icon name="info" size={16} />}
|
||||
dismissLabel={t("close")}
|
||||
onDismiss={() => setCleanHistoryStatus(null)}
|
||||
description={cleanHistoryStatus}
|
||||
/>
|
||||
)}
|
||||
|
||||
<div className="min-h-0">
|
||||
@@ -275,11 +235,12 @@ function LogsPageContent() {
|
||||
}
|
||||
|
||||
export default function LogsPage() {
|
||||
const t = useTranslations("logs");
|
||||
return (
|
||||
<Suspense
|
||||
fallback={
|
||||
<div className="flex items-center justify-center py-12 text-text-muted text-sm">
|
||||
Loading logs...
|
||||
{t("loading")}
|
||||
</div>
|
||||
}
|
||||
>
|
||||
|
||||
@@ -1,7 +1,15 @@
|
||||
"use client";
|
||||
|
||||
import { useTranslations } from "next-intl";
|
||||
import { PageHeader } from "@omniroute/ui-kit/page-header";
|
||||
import ProxyLogger from "@/shared/components/ProxyLogger";
|
||||
|
||||
export default function LogsProxyPage() {
|
||||
return <ProxyLogger />;
|
||||
const t = useTranslations("logs");
|
||||
return (
|
||||
<div className="flex flex-col gap-6">
|
||||
<PageHeader compact title={t("proxyLogs")} />
|
||||
<ProxyLogger />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
import { Suspense } from "react";
|
||||
import { useSearchParams } from "next/navigation";
|
||||
import { useTranslations } from "next-intl";
|
||||
import RequestTimeline from "@/shared/components/RequestTimeline";
|
||||
|
||||
function LogsTimelinePageContent() {
|
||||
@@ -16,11 +17,12 @@ function LogsTimelinePageContent() {
|
||||
}
|
||||
|
||||
export default function LogsTimelinePage() {
|
||||
const t = useTranslations("logs");
|
||||
return (
|
||||
<Suspense
|
||||
fallback={
|
||||
<div className="flex items-center justify-center py-12 text-text-muted text-sm">
|
||||
Loading timeline...
|
||||
{t("loading")}
|
||||
</div>
|
||||
}
|
||||
>
|
||||
|
||||
@@ -21,7 +21,7 @@ function CatalogBulkProgress({ running, progress }: { running: boolean; progress
|
||||
if (running) {
|
||||
return (
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="h-2 w-32 overflow-hidden rounded-full bg-black/10 dark:bg-white/10 sm:w-48">
|
||||
<div className="h-2 w-32 overflow-hidden rounded-full bg-border sm:w-48">
|
||||
<div
|
||||
className="h-full bg-primary transition-all duration-300"
|
||||
style={{ width: `${percent}%` }}
|
||||
@@ -70,7 +70,7 @@ export default function CatalogBulkActionBar({
|
||||
const t = useTranslations("modelCatalog");
|
||||
|
||||
return (
|
||||
<div className="flex flex-wrap items-center justify-between gap-3 border-b border-border bg-black/[0.01] px-4 py-2.5 dark:bg-white/[0.01]">
|
||||
<div className="flex flex-wrap items-center justify-between gap-3 border-b border-border bg-bg-subtle px-4 py-2.5">
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<Button
|
||||
variant="secondary"
|
||||
|
||||
@@ -2,15 +2,11 @@
|
||||
|
||||
import type { ReactNode } from "react";
|
||||
import { useTranslations } from "next-intl";
|
||||
import { Button, Input } from "@/shared/components";
|
||||
import { Button, Input, Select } from "@/shared/components";
|
||||
import { parseNonNegativeInt } from "./catalogUrlState";
|
||||
|
||||
// Shared building blocks of the model and combo filter panels; the markup matches what each
|
||||
// panel rendered inline, so both keep the same DOM, labels and classes.
|
||||
|
||||
const FIELD_LABEL_CLASS = "flex flex-col gap-1 text-xs font-medium text-text-main";
|
||||
const FIELD_CONTROL_CLASS =
|
||||
"h-9 w-full rounded-control border border-black/10 bg-white px-2.5 text-xs text-text-main focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary dark:border-white/10 dark:bg-white/5";
|
||||
// Shared building blocks of the model and combo filter panels (kit Field + Input/Select
|
||||
// adapters: the label is a <label htmlFor> above the control).
|
||||
|
||||
function humanize(value: string): string {
|
||||
return value
|
||||
@@ -78,16 +74,9 @@ export function FilterSelect({
|
||||
children: ReactNode;
|
||||
}) {
|
||||
return (
|
||||
<label className={FIELD_LABEL_CLASS}>
|
||||
{label}
|
||||
<select
|
||||
value={value}
|
||||
onChange={(e) => onChange(e.target.value)}
|
||||
className={FIELD_CONTROL_CLASS}
|
||||
>
|
||||
{children}
|
||||
</select>
|
||||
</label>
|
||||
<Select label={label} value={value} onChange={(e) => onChange(e.target.value)}>
|
||||
{children}
|
||||
</Select>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -136,17 +125,14 @@ export function FilterNumberInput({
|
||||
onChange: (value: number | undefined) => void;
|
||||
}) {
|
||||
return (
|
||||
<label className={FIELD_LABEL_CLASS}>
|
||||
{label}
|
||||
<input
|
||||
type="number"
|
||||
min={min}
|
||||
step={step}
|
||||
placeholder={placeholder}
|
||||
value={value ?? ""}
|
||||
onChange={(e) => onChange(parseNonNegativeInt(e.target.value))}
|
||||
className={FIELD_CONTROL_CLASS}
|
||||
/>
|
||||
</label>
|
||||
<Input
|
||||
type="number"
|
||||
label={label}
|
||||
min={min}
|
||||
step={step}
|
||||
placeholder={placeholder}
|
||||
value={value ?? ""}
|
||||
onChange={(e) => onChange(parseNonNegativeInt(e.target.value))}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2,23 +2,19 @@
|
||||
|
||||
import type { ReactNode } from "react";
|
||||
import { useTranslations } from "next-intl";
|
||||
import { Button } from "@/shared/components";
|
||||
import { DataTableFooter } from "@omniroute/ui-kit/data-table-shell";
|
||||
import { TableCell, TableHead } from "@omniroute/ui-kit/table";
|
||||
import { Button, Checkbox } from "@/shared/components";
|
||||
|
||||
// Cells and footer shared by the model and combo catalog tables; the markup matches what each
|
||||
// table rendered inline, so both keep the same DOM, labels and classes.
|
||||
|
||||
const CHECKBOX_CLASS =
|
||||
"rounded border-black/20 text-primary focus:ring-primary dark:border-white/20";
|
||||
// Cells and footer shared by the model and combo catalog tables (kit Table cells, Checkbox
|
||||
// adapter, kit DataTableFooter).
|
||||
|
||||
/** A column heading without sorting. */
|
||||
export function PlainHeading({ children }: { children: ReactNode }) {
|
||||
return (
|
||||
<th
|
||||
scope="col"
|
||||
className="px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-text-muted"
|
||||
>
|
||||
<TableHead scope="col" className="px-4">
|
||||
{children}
|
||||
</th>
|
||||
</TableHead>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -26,12 +22,9 @@ export function PlainHeading({ children }: { children: ReactNode }) {
|
||||
export function ActionsHeading() {
|
||||
const t = useTranslations("modelCatalog");
|
||||
return (
|
||||
<th
|
||||
scope="col"
|
||||
className="px-4 py-3 text-right text-xs font-semibold uppercase tracking-wide text-text-muted"
|
||||
>
|
||||
<TableHead scope="col" className="px-4 text-right">
|
||||
{t("actions")}
|
||||
</th>
|
||||
</TableHead>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -48,18 +41,16 @@ export function SelectAllHeaderCell({
|
||||
label: string;
|
||||
}) {
|
||||
return (
|
||||
<th scope="col" className="w-10 px-4 py-3">
|
||||
<input
|
||||
type="checkbox"
|
||||
<TableHead scope="col" className="w-10 px-4">
|
||||
{/* The adapter forwards `indeterminate` as the kit prop (not a ref callback: the kit
|
||||
effect would overwrite a ref-set value). */}
|
||||
<Checkbox
|
||||
checked={checked}
|
||||
ref={(el) => {
|
||||
if (el) el.indeterminate = indeterminate;
|
||||
}}
|
||||
indeterminate={indeterminate}
|
||||
onChange={onToggle}
|
||||
aria-label={label}
|
||||
className={CHECKBOX_CLASS}
|
||||
/>
|
||||
</th>
|
||||
</TableHead>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -73,15 +64,9 @@ export function SelectRowCell({
|
||||
label: string;
|
||||
}) {
|
||||
return (
|
||||
<td className="w-10 px-4 py-3">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={checked}
|
||||
onChange={onToggle}
|
||||
aria-label={label}
|
||||
className={CHECKBOX_CLASS}
|
||||
/>
|
||||
</td>
|
||||
<TableCell className="w-10 px-4">
|
||||
<Checkbox checked={checked} onChange={onToggle} aria-label={label} />
|
||||
</TableCell>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -101,19 +86,24 @@ export function CatalogTableFooter({
|
||||
}) {
|
||||
const t = useTranslations("modelCatalog");
|
||||
return (
|
||||
<footer className="flex flex-col gap-3 border-t border-border px-4 py-3 sm:flex-row sm:items-center sm:justify-between">
|
||||
<p className="text-sm text-text-muted" aria-live="polite">
|
||||
{children}
|
||||
</p>
|
||||
<div className="flex items-center gap-3">
|
||||
<span className="text-sm text-text-muted">{t("page", { page, pageCount })}</span>
|
||||
<Button variant="secondary" size="sm" disabled={page === 1} onClick={onPrevious}>
|
||||
{t("previous")}
|
||||
</Button>
|
||||
<Button variant="secondary" size="sm" disabled={page >= pageCount} onClick={onNext}>
|
||||
{t("next")}
|
||||
</Button>
|
||||
</div>
|
||||
</footer>
|
||||
<DataTableFooter
|
||||
className="border-t border-border px-4 py-3"
|
||||
metadata={
|
||||
<p className="text-sm text-text-muted" aria-live="polite">
|
||||
{children}
|
||||
</p>
|
||||
}
|
||||
pagination={
|
||||
<div className="flex items-center gap-3">
|
||||
<span className="text-sm text-text-muted">{t("page", { page, pageCount })}</span>
|
||||
<Button variant="outline" size="sm" disabled={page === 1} onClick={onPrevious}>
|
||||
{t("previous")}
|
||||
</Button>
|
||||
<Button variant="outline" size="sm" disabled={page >= pageCount} onClick={onNext}>
|
||||
{t("next")}
|
||||
</Button>
|
||||
</div>
|
||||
}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"use client";
|
||||
|
||||
import { useRef, type KeyboardEvent } from "react";
|
||||
import { Tabs, TabsList, TabsTrigger } from "@omniroute/ui-kit/tabs";
|
||||
import type { CatalogTab } from "./catalogUrlState";
|
||||
|
||||
const TAB_ORDER: CatalogTab[] = ["models", "combos"];
|
||||
@@ -13,7 +13,11 @@ export function catalogPanelId(tab: CatalogTab): string {
|
||||
return `panel-${tab}`;
|
||||
}
|
||||
|
||||
/** WAI-ARIA tabs: roving tabindex, Arrow/Home/End move selection and focus together. */
|
||||
/**
|
||||
* Kit underline Tabs (WAI-ARIA tablist; the kit owns roving tabindex and Arrow/Home/End).
|
||||
* The tab/panel ids stay the page's own (`tab-*` / `panel-*`) because the panels are
|
||||
* rendered by the page, outside this component.
|
||||
*/
|
||||
export default function CatalogTabs({
|
||||
activeTab,
|
||||
onSelect,
|
||||
@@ -25,60 +29,25 @@ export default function CatalogTabs({
|
||||
labels: Record<CatalogTab, string>;
|
||||
ariaLabel: string;
|
||||
}) {
|
||||
const tabRefs = useRef<Partial<Record<CatalogTab, HTMLButtonElement | null>>>({});
|
||||
|
||||
const handleKeyDown = (event: KeyboardEvent<HTMLButtonElement>, index: number) => {
|
||||
let next: number;
|
||||
switch (event.key) {
|
||||
case "ArrowRight":
|
||||
next = (index + 1) % TAB_ORDER.length;
|
||||
break;
|
||||
case "ArrowLeft":
|
||||
next = (index - 1 + TAB_ORDER.length) % TAB_ORDER.length;
|
||||
break;
|
||||
case "Home":
|
||||
next = 0;
|
||||
break;
|
||||
case "End":
|
||||
next = TAB_ORDER.length - 1;
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
event.preventDefault();
|
||||
const tab = TAB_ORDER[next];
|
||||
onSelect(tab);
|
||||
tabRefs.current[tab]?.focus();
|
||||
};
|
||||
|
||||
return (
|
||||
<div role="tablist" aria-label={ariaLabel} className="mt-2 flex border-b border-border">
|
||||
{TAB_ORDER.map((tab, index) => {
|
||||
const selected = tab === activeTab;
|
||||
return (
|
||||
<button
|
||||
<Tabs
|
||||
variant="underline"
|
||||
value={activeTab}
|
||||
onValueChange={(next) => onSelect(next as CatalogTab)}
|
||||
className="mt-2"
|
||||
>
|
||||
<TabsList aria-label={ariaLabel}>
|
||||
{TAB_ORDER.map((tab) => (
|
||||
<TabsTrigger
|
||||
key={tab}
|
||||
ref={(element) => {
|
||||
tabRefs.current[tab] = element;
|
||||
}}
|
||||
type="button"
|
||||
role="tab"
|
||||
value={tab}
|
||||
id={catalogTabId(tab)}
|
||||
aria-selected={selected}
|
||||
aria-controls={selected ? catalogPanelId(tab) : undefined}
|
||||
tabIndex={selected ? 0 : -1}
|
||||
onClick={() => onSelect(tab)}
|
||||
onKeyDown={(event) => handleKeyDown(event, index)}
|
||||
className={`border-b-2 px-4 py-2.5 text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary ${
|
||||
selected
|
||||
? "border-primary text-primary"
|
||||
: "border-transparent text-text-muted hover:text-text-main"
|
||||
}`}
|
||||
aria-controls={tab === activeTab ? catalogPanelId(tab) : undefined}
|
||||
>
|
||||
{labels[tab]}
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</TabsTrigger>
|
||||
))}
|
||||
</TabsList>
|
||||
</Tabs>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,15 @@
|
||||
"use client";
|
||||
|
||||
import { useTranslations } from "next-intl";
|
||||
import { SortableTableHead } from "@omniroute/ui-kit/data-table-shell";
|
||||
import {
|
||||
Table,
|
||||
TableBody,
|
||||
TableCaption,
|
||||
TableCell,
|
||||
TableHeader,
|
||||
TableRow,
|
||||
} from "@omniroute/ui-kit/table";
|
||||
import { Badge, Button } from "@/shared/components";
|
||||
import CatalogTestBadge from "./CatalogTestBadge";
|
||||
import {
|
||||
@@ -39,25 +48,17 @@ function SortableHeading({
|
||||
onSort: (field: ComboSortField) => void;
|
||||
}) {
|
||||
const active = field === activeField;
|
||||
// The page's onSort owns the flip rule (same field flips, a new field starts "asc").
|
||||
return (
|
||||
<th
|
||||
<SortableTableHead
|
||||
scope="col"
|
||||
aria-sort={active ? (direction === "asc" ? "ascending" : "descending") : "none"}
|
||||
className="whitespace-nowrap px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-text-muted"
|
||||
className="px-4"
|
||||
direction={active ? direction : undefined}
|
||||
defaultDirection="asc"
|
||||
onDirectionChange={() => onSort(field)}
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => onSort(field)}
|
||||
className="inline-flex min-h-8 items-center gap-1 rounded-sm text-left hover:text-text-main focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"
|
||||
>
|
||||
{label}
|
||||
{active && (
|
||||
<span className="material-symbols-outlined text-base text-primary" aria-hidden="true">
|
||||
{direction === "asc" ? "arrow_upward" : "arrow_downward"}
|
||||
</span>
|
||||
)}
|
||||
</button>
|
||||
</th>
|
||||
{label}
|
||||
</SortableTableHead>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -78,8 +79,8 @@ function ComboCatalogTableHead({
|
||||
}) {
|
||||
const t = useTranslations("modelCatalog");
|
||||
return (
|
||||
<thead className="border-b border-border bg-black/[0.02] dark:bg-white/[0.02]">
|
||||
<tr>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<SelectAllHeaderCell
|
||||
checked={allOnPageSelected}
|
||||
indeterminate={someOnPageSelected}
|
||||
@@ -116,8 +117,8 @@ function ComboCatalogTableHead({
|
||||
/>
|
||||
<PlainHeading>{t("healthTest")}</PlainHeading>
|
||||
<ActionsHeading />
|
||||
</tr>
|
||||
</thead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -125,7 +126,7 @@ function ComboCatalogTableHead({
|
||||
function ComboMembersCell({ combo }: { combo: ComboCatalogRow }) {
|
||||
const t = useTranslations("modelCatalog");
|
||||
return (
|
||||
<td className="px-4 py-3">
|
||||
<TableCell className="h-auto whitespace-normal px-4 py-3 align-top">
|
||||
<span className="font-medium tabular-nums text-text-main">
|
||||
{combo.memberCount}{" "}
|
||||
{combo.memberCount === 1 ? t("modelCountSingle") : t("modelCountPlural")}
|
||||
@@ -135,7 +136,7 @@ function ComboMembersCell({ combo }: { combo: ComboCatalogRow }) {
|
||||
{combo.models.slice(0, 3).map((m, idx) => (
|
||||
<span
|
||||
key={idx}
|
||||
className="inline-block max-w-[150px] truncate rounded bg-black/5 px-1.5 py-0.5 font-mono text-[10px] text-text-muted dark:bg-white/5"
|
||||
className="inline-block max-w-[150px] truncate rounded bg-bg-subtle px-1.5 py-0.5 font-mono text-[10px] text-text-muted"
|
||||
title={m.model}
|
||||
>
|
||||
{m.label ||
|
||||
@@ -151,7 +152,7 @@ function ComboMembersCell({ combo }: { combo: ComboCatalogRow }) {
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</td>
|
||||
</TableCell>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -178,17 +179,13 @@ function ComboCatalogTableRow({
|
||||
const result = testResults[testKey];
|
||||
|
||||
return (
|
||||
<tr
|
||||
className={`align-top transition-colors hover:bg-black/[0.02] dark:hover:bg-white/[0.02] ${
|
||||
isSelected ? "bg-primary/[0.03]" : ""
|
||||
}`}
|
||||
>
|
||||
<TableRow data-state={isSelected ? "selected" : undefined} className="align-top">
|
||||
<SelectRowCell
|
||||
checked={isSelected}
|
||||
onToggle={() => onToggleSelect(combo.id)}
|
||||
label={t("selectCombo", { name: combo.name })}
|
||||
/>
|
||||
<td className="max-w-sm px-4 py-3">
|
||||
<TableCell className="h-auto max-w-sm whitespace-normal px-4 py-3 align-top">
|
||||
<div className="font-medium text-text-main">{combo.displayName}</div>
|
||||
{combo.displayName !== combo.name && (
|
||||
<span className="font-mono text-xs text-text-muted">{combo.name}</span>
|
||||
@@ -196,22 +193,22 @@ function ComboCatalogTableRow({
|
||||
{combo.description && (
|
||||
<p className="mt-1 line-clamp-2 text-xs text-text-muted">{combo.description}</p>
|
||||
)}
|
||||
</td>
|
||||
<td className="whitespace-nowrap px-4 py-3">
|
||||
</TableCell>
|
||||
<TableCell className="h-auto px-4 py-3 align-top">
|
||||
<Badge size="sm" variant="default">
|
||||
{humanize(combo.strategy)}
|
||||
</Badge>
|
||||
</td>
|
||||
</TableCell>
|
||||
<ComboMembersCell combo={combo} />
|
||||
<td className="whitespace-nowrap px-4 py-3">
|
||||
<TableCell className="h-auto px-4 py-3 align-top">
|
||||
<Badge size="sm" variant={combo.status === "active" ? "success" : "default"}>
|
||||
{combo.status === "active" ? t("active") : t("paused")}
|
||||
</Badge>
|
||||
</td>
|
||||
<td className="whitespace-nowrap px-4 py-3">
|
||||
</TableCell>
|
||||
<TableCell className="h-auto px-4 py-3 align-top">
|
||||
<CatalogTestBadge result={result} loading={isTesting} />
|
||||
</td>
|
||||
<td className="whitespace-nowrap px-4 py-3 text-right">
|
||||
</TableCell>
|
||||
<TableCell className="h-auto px-4 py-3 text-right align-top">
|
||||
<Button
|
||||
variant="secondary"
|
||||
size="sm"
|
||||
@@ -221,8 +218,8 @@ function ComboCatalogTableRow({
|
||||
>
|
||||
{t("test")}
|
||||
</Button>
|
||||
</td>
|
||||
</tr>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -275,14 +272,13 @@ export default function ComboCatalogTable({
|
||||
|
||||
return (
|
||||
<>
|
||||
<div
|
||||
className="overflow-x-auto"
|
||||
role="region"
|
||||
aria-label={t("combosTableRegion")}
|
||||
tabIndex={0}
|
||||
>
|
||||
<table className="min-w-[900px] w-full border-collapse text-sm">
|
||||
<caption className="sr-only">{t("combosTableCaption")}</caption>
|
||||
<div role="region" aria-label={t("combosTableRegion")}>
|
||||
<Table
|
||||
scrollbarLabel={t("combosTableRegion")}
|
||||
containerClassName="rounded-none border-0"
|
||||
className="min-w-[900px]"
|
||||
>
|
||||
<TableCaption className="sr-only">{t("combosTableCaption")}</TableCaption>
|
||||
<ComboCatalogTableHead
|
||||
sortField={sortField}
|
||||
sortDirection={sortDirection}
|
||||
@@ -291,7 +287,7 @@ export default function ComboCatalogTable({
|
||||
someOnPageSelected={someOnPageSelected}
|
||||
onToggleSelectAll={onToggleSelectAll}
|
||||
/>
|
||||
<tbody className="divide-y divide-border">
|
||||
<TableBody>
|
||||
{rows.map((combo) => (
|
||||
<ComboCatalogTableRow
|
||||
key={combo.id}
|
||||
@@ -304,8 +300,8 @@ export default function ComboCatalogTable({
|
||||
bulkRunning={bulkRunning}
|
||||
/>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</TableBody>
|
||||
</Table>
|
||||
</div>
|
||||
|
||||
<CatalogTableFooter page={page} pageCount={pageCount} onPrevious={onPrevious} onNext={onNext}>
|
||||
|
||||
@@ -1,6 +1,17 @@
|
||||
"use client";
|
||||
|
||||
import { useTranslations } from "next-intl";
|
||||
import { SortableTableHead } from "@omniroute/ui-kit/data-table-shell";
|
||||
import { ModelIdentity } from "@omniroute/ui-kit/model-identity";
|
||||
import {
|
||||
Table,
|
||||
TableBody,
|
||||
TableCaption,
|
||||
TableCell,
|
||||
TableHeader,
|
||||
TableRow,
|
||||
} from "@omniroute/ui-kit/table";
|
||||
import ProviderIcon from "@/shared/components/ProviderIcon";
|
||||
import { Badge, Button } from "@/shared/components";
|
||||
import CatalogTestBadge from "./CatalogTestBadge";
|
||||
import {
|
||||
@@ -62,25 +73,17 @@ function SortableHeading({
|
||||
onSort: (field: CatalogSortField) => void;
|
||||
}) {
|
||||
const active = field === activeField;
|
||||
// The page's onSort owns the flip rule (same field flips, a new field starts "asc").
|
||||
return (
|
||||
<th
|
||||
<SortableTableHead
|
||||
scope="col"
|
||||
aria-sort={active ? (direction === "asc" ? "ascending" : "descending") : "none"}
|
||||
className="whitespace-nowrap px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-text-muted"
|
||||
className="px-4"
|
||||
direction={active ? direction : undefined}
|
||||
defaultDirection="asc"
|
||||
onDirectionChange={() => onSort(field)}
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => onSort(field)}
|
||||
className="inline-flex min-h-8 items-center gap-1 rounded-sm text-left hover:text-text-main focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"
|
||||
>
|
||||
{label}
|
||||
{active && (
|
||||
<span className="material-symbols-outlined text-base text-primary" aria-hidden="true">
|
||||
{direction === "asc" ? "arrow_upward" : "arrow_downward"}
|
||||
</span>
|
||||
)}
|
||||
</button>
|
||||
</th>
|
||||
{label}
|
||||
</SortableTableHead>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -119,8 +122,8 @@ function ModelCatalogTableHead({
|
||||
}) {
|
||||
const t = useTranslations("modelCatalog");
|
||||
return (
|
||||
<thead className="border-b border-border bg-black/[0.02] dark:bg-white/[0.02]">
|
||||
<tr>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
{onToggleSelectAll && (
|
||||
<SelectAllHeaderCell
|
||||
checked={allOnPageSelected}
|
||||
@@ -168,8 +171,8 @@ function ModelCatalogTableHead({
|
||||
<PlainHeading>{labels.flags || t("flags")}</PlainHeading>
|
||||
<PlainHeading>{t("healthTest")}</PlainHeading>
|
||||
{showActions && <ActionsHeading />}
|
||||
</tr>
|
||||
</thead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -182,9 +185,13 @@ function ModelProviderCell({
|
||||
}) {
|
||||
const t = useTranslations("modelCatalog");
|
||||
return (
|
||||
<td className="px-4 py-3">
|
||||
<TableCell className="h-auto px-4 py-3 align-top">
|
||||
<div className="flex items-center gap-1.5">
|
||||
<span className="font-medium text-text-main">{model.provider}</span>
|
||||
<ModelIdentity
|
||||
name={model.provider}
|
||||
provider={model.provider}
|
||||
logo={<ProviderIcon providerId={model.providerId} size={18} type="color" />}
|
||||
/>
|
||||
{providerHealth && providerHealth !== "healthy" && (
|
||||
<Badge size="sm" variant={providerHealth === "degraded" ? "warning" : "error"} dot>
|
||||
{providerHealth === "degraded" ? t("degraded") : t("down")}
|
||||
@@ -192,18 +199,18 @@ function ModelProviderCell({
|
||||
)}
|
||||
</div>
|
||||
<span className="mt-0.5 block font-mono text-xs text-text-muted">{model.providerId}</span>
|
||||
</td>
|
||||
</TableCell>
|
||||
);
|
||||
}
|
||||
|
||||
function ModelTypeCell({ model }: { model: CatalogModelRow }) {
|
||||
return (
|
||||
<td className="px-4 py-3 text-text-main">
|
||||
<TableCell className="h-auto px-4 py-3 align-top text-text-main">
|
||||
{humanize(model.type)}
|
||||
{model.subtype && (
|
||||
<span className="mt-0.5 block text-xs text-text-muted">{humanize(model.subtype)}</span>
|
||||
)}
|
||||
</td>
|
||||
</TableCell>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -212,7 +219,7 @@ function ModelCapabilitiesCell({ capabilities }: { capabilities: string[] }) {
|
||||
const t = useTranslations("modelCatalog");
|
||||
const additionalCapabilities = capabilities.slice(3);
|
||||
return (
|
||||
<td className="max-w-xs px-4 py-3">
|
||||
<TableCell className="h-auto max-w-xs whitespace-normal px-4 py-3 align-top">
|
||||
{capabilities.length > 0 ? (
|
||||
<div className="flex flex-wrap gap-1.5">
|
||||
{capabilities.slice(0, 3).map((capability) => (
|
||||
@@ -239,14 +246,14 @@ function ModelCapabilitiesCell({ capabilities }: { capabilities: string[] }) {
|
||||
—
|
||||
</span>
|
||||
)}
|
||||
</td>
|
||||
</TableCell>
|
||||
);
|
||||
}
|
||||
|
||||
function ModelFlagsCell({ model, labels }: { model: CatalogModelRow; labels: ModelCatalogLabels }) {
|
||||
const t = useTranslations("modelCatalog");
|
||||
return (
|
||||
<td className="px-4 py-3">
|
||||
<TableCell className="h-auto px-4 py-3 align-top">
|
||||
<div className="flex flex-wrap gap-1.5">
|
||||
{model.custom === true && (
|
||||
<Badge size="sm" variant="info">
|
||||
@@ -264,7 +271,7 @@ function ModelFlagsCell({ model, labels }: { model: CatalogModelRow; labels: Mod
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
</td>
|
||||
</TableCell>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -302,11 +309,7 @@ function ModelCatalogTableRow({
|
||||
output: common("output"),
|
||||
});
|
||||
return (
|
||||
<tr
|
||||
className={`align-top transition-colors hover:bg-black/[0.02] dark:hover:bg-white/[0.02] ${
|
||||
isSelected ? "bg-primary/[0.03]" : ""
|
||||
}`}
|
||||
>
|
||||
<TableRow data-state={isSelected ? "selected" : undefined} className="align-top">
|
||||
{onToggleSelect && (
|
||||
<SelectRowCell
|
||||
checked={isSelected}
|
||||
@@ -315,24 +318,24 @@ function ModelCatalogTableRow({
|
||||
/>
|
||||
)}
|
||||
<ModelProviderCell model={model} providerHealth={providerHealthMap[model.providerId]} />
|
||||
<td className="max-w-sm px-4 py-3">
|
||||
<TableCell className="h-auto max-w-sm whitespace-normal px-4 py-3 align-top">
|
||||
<span className="block break-words font-medium text-text-main">{model.name}</span>
|
||||
<span className="mt-0.5 block break-all font-mono text-xs text-text-muted">{model.id}</span>
|
||||
</td>
|
||||
</TableCell>
|
||||
<ModelTypeCell model={model} />
|
||||
<ModelCapabilitiesCell capabilities={capabilities} />
|
||||
<td className="whitespace-nowrap px-4 py-3 tabular-nums text-text-main">
|
||||
<TableCell className="h-auto px-4 py-3 align-top tabular-nums text-text-main">
|
||||
{formatOptionalCount(model.context_length)}
|
||||
</td>
|
||||
<td className="whitespace-nowrap px-4 py-3 tabular-nums text-text-main">
|
||||
</TableCell>
|
||||
<TableCell className="h-auto px-4 py-3 align-top tabular-nums text-text-main">
|
||||
{formatOptionalCount(model.max_output_tokens)}
|
||||
</td>
|
||||
</TableCell>
|
||||
<ModelFlagsCell model={model} labels={labels} />
|
||||
<td className="whitespace-nowrap px-4 py-3">
|
||||
<TableCell className="h-auto px-4 py-3 align-top">
|
||||
<CatalogTestBadge result={result} loading={isTesting} />
|
||||
</td>
|
||||
</TableCell>
|
||||
{onTestModel && (
|
||||
<td className="whitespace-nowrap px-4 py-3 text-right">
|
||||
<TableCell className="h-auto px-4 py-3 text-right align-top">
|
||||
<Button
|
||||
variant="secondary"
|
||||
size="sm"
|
||||
@@ -342,9 +345,9 @@ function ModelCatalogTableRow({
|
||||
>
|
||||
{t("test")}
|
||||
</Button>
|
||||
</td>
|
||||
</TableCell>
|
||||
)}
|
||||
</tr>
|
||||
</TableRow>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -406,9 +409,13 @@ export default function ModelCatalogTable({
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="overflow-x-auto" role="region" aria-label={t("tableRegion")} tabIndex={0}>
|
||||
<table className="min-w-[1100px] w-full border-collapse text-sm">
|
||||
<caption className="sr-only">{t("tableCaption")}</caption>
|
||||
<div role="region" aria-label={t("tableRegion")}>
|
||||
<Table
|
||||
scrollbarLabel={t("tableRegion")}
|
||||
containerClassName="rounded-none border-0"
|
||||
className="min-w-[1100px]"
|
||||
>
|
||||
<TableCaption className="sr-only">{t("tableCaption")}</TableCaption>
|
||||
<ModelCatalogTableHead
|
||||
labels={labels}
|
||||
sortField={sortField}
|
||||
@@ -419,7 +426,7 @@ export default function ModelCatalogTable({
|
||||
onToggleSelectAll={onToggleSelectAll}
|
||||
showActions={Boolean(onTestModel)}
|
||||
/>
|
||||
<tbody className="divide-y divide-border">
|
||||
<TableBody>
|
||||
{rows.map((model) => (
|
||||
<ModelCatalogTableRow
|
||||
key={`${model.providerId}:${model.id}`}
|
||||
@@ -434,8 +441,8 @@ export default function ModelCatalogTable({
|
||||
bulkRunning={bulkRunning}
|
||||
/>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</TableBody>
|
||||
</Table>
|
||||
</div>
|
||||
|
||||
<CatalogTableFooter page={page} pageCount={pageCount} onPrevious={onPrevious} onNext={onNext}>
|
||||
@@ -445,7 +452,7 @@ export default function ModelCatalogTable({
|
||||
total: formatCount(totalCount),
|
||||
})}
|
||||
{loading && <span className="ml-2">{t("refreshing")}</span>}
|
||||
{error && <span className="ml-2 text-red-500">{t("refreshFailed")}</span>}
|
||||
{error && <span className="ml-2 text-error">{t("refreshFailed")}</span>}
|
||||
</CatalogTableFooter>
|
||||
</>
|
||||
);
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
||||
import { useTranslations } from "next-intl";
|
||||
|
||||
import { Button, Card, ConfirmModal } from "@/shared/components";
|
||||
import { PageHeader } from "@omniroute/ui-kit/page-header";
|
||||
import { Button, Card, ConfirmModal, EmptyState, Skeleton } from "@/shared/components";
|
||||
import CatalogBulkActionBar from "./CatalogBulkActionBar";
|
||||
import {
|
||||
BULK_CONFIRM_COMBO_THRESHOLD,
|
||||
@@ -614,21 +615,22 @@ function CatalogHeader({ context }: { context: CatalogPageContext }) {
|
||||
context;
|
||||
return (
|
||||
<>
|
||||
<header className="flex flex-col gap-2">
|
||||
<div className="flex flex-wrap items-start justify-between gap-3">
|
||||
<div>
|
||||
<h1 className="text-2xl font-semibold text-text-main">{t("title")}</h1>
|
||||
<p className="mt-1 max-w-3xl text-sm text-text-muted">{t("subtitle")}</p>
|
||||
</div>
|
||||
<Button
|
||||
variant="secondary"
|
||||
icon="refresh"
|
||||
loading={modelsLoading || combosLoading}
|
||||
onClick={refreshAll}
|
||||
>
|
||||
{t("refresh")}
|
||||
</Button>
|
||||
</div>
|
||||
<div className="flex flex-col gap-2">
|
||||
<PageHeader
|
||||
compact
|
||||
title={t("title")}
|
||||
description={t("subtitle")}
|
||||
actions={
|
||||
<Button
|
||||
variant="secondary"
|
||||
icon="refresh"
|
||||
loading={modelsLoading || combosLoading}
|
||||
onClick={refreshAll}
|
||||
>
|
||||
{t("refresh")}
|
||||
</Button>
|
||||
}
|
||||
/>
|
||||
|
||||
<CatalogTabs
|
||||
activeTab={activeTab}
|
||||
@@ -639,7 +641,7 @@ function CatalogHeader({ context }: { context: CatalogPageContext }) {
|
||||
combos: `${t("combosTab")} (${combos.length})`,
|
||||
}}
|
||||
/>
|
||||
</header>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -733,12 +735,12 @@ function CatalogModelsContent({ context }: { context: CatalogPageContext }) {
|
||||
return (
|
||||
<>
|
||||
{modelsLoading && models.length === 0 ? (
|
||||
<div
|
||||
role="status"
|
||||
aria-live="polite"
|
||||
className="flex min-h-64 items-center justify-center p-8 text-sm text-text-muted"
|
||||
>
|
||||
{t("loading")}
|
||||
<div role="status" aria-live="polite" className="flex min-h-64 flex-col gap-2 p-4">
|
||||
{/* Skeleton rows (CSS only): the kit TableLoadingState brand loader animates on timers. */}
|
||||
<span className="ci-sr-only">{t("loading")}</span>
|
||||
{Array.from({ length: 6 }, (_, i) => (
|
||||
<Skeleton key={i} className="h-9 w-full" />
|
||||
))}
|
||||
</div>
|
||||
) : modelsError && models.length === 0 ? (
|
||||
<div
|
||||
@@ -752,19 +754,13 @@ function CatalogModelsContent({ context }: { context: CatalogPageContext }) {
|
||||
</Button>
|
||||
</div>
|
||||
) : visibleModels.length === 0 ? (
|
||||
<div className="flex min-h-64 flex-col items-center justify-center gap-2 p-8 text-center">
|
||||
<span className="material-symbols-outlined text-3xl text-text-muted" aria-hidden="true">
|
||||
search_off
|
||||
</span>
|
||||
<p className="font-medium text-text-main">
|
||||
{models.length === 0 ? t("noModelsAvailable") : t("noModelsMatch")}
|
||||
</p>
|
||||
{models.length > 0 && (
|
||||
<Button variant="ghost" size="sm" onClick={clearModelFilters}>
|
||||
{t("clearFilters")}
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
<EmptyState
|
||||
className="min-h-64"
|
||||
icon="search_off"
|
||||
title={models.length === 0 ? t("noModelsAvailable") : t("noModelsMatch")}
|
||||
actionLabel={models.length > 0 ? t("clearFilters") : ""}
|
||||
onAction={models.length > 0 ? clearModelFilters : null}
|
||||
/>
|
||||
) : (
|
||||
<CatalogModelsResults context={context} />
|
||||
)}
|
||||
@@ -921,12 +917,12 @@ function CatalogCombosContent({ context }: { context: CatalogPageContext }) {
|
||||
return (
|
||||
<>
|
||||
{combosLoading && combos.length === 0 ? (
|
||||
<div
|
||||
role="status"
|
||||
aria-live="polite"
|
||||
className="flex min-h-64 items-center justify-center p-8 text-sm text-text-muted"
|
||||
>
|
||||
{t("loading")}
|
||||
<div role="status" aria-live="polite" className="flex min-h-64 flex-col gap-2 p-4">
|
||||
{/* Skeleton rows (CSS only): the kit TableLoadingState brand loader animates on timers. */}
|
||||
<span className="ci-sr-only">{t("loading")}</span>
|
||||
{Array.from({ length: 6 }, (_, i) => (
|
||||
<Skeleton key={i} className="h-9 w-full" />
|
||||
))}
|
||||
</div>
|
||||
) : combosError && combos.length === 0 ? (
|
||||
<div
|
||||
@@ -940,19 +936,13 @@ function CatalogCombosContent({ context }: { context: CatalogPageContext }) {
|
||||
</Button>
|
||||
</div>
|
||||
) : visibleCombos.length === 0 ? (
|
||||
<div className="flex min-h-64 flex-col items-center justify-center gap-2 p-8 text-center">
|
||||
<span className="material-symbols-outlined text-3xl text-text-muted" aria-hidden="true">
|
||||
search_off
|
||||
</span>
|
||||
<p className="font-medium text-text-main">
|
||||
{combos.length === 0 ? t("noCombosAvailable") : t("noCombosMatch")}
|
||||
</p>
|
||||
{combos.length > 0 && (
|
||||
<Button variant="ghost" size="sm" onClick={clearComboFilters}>
|
||||
{t("clearFilters")}
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
<EmptyState
|
||||
className="min-h-64"
|
||||
icon="search_off"
|
||||
title={combos.length === 0 ? t("noCombosAvailable") : t("noCombosMatch")}
|
||||
actionLabel={combos.length > 0 ? t("clearFilters") : ""}
|
||||
onAction={combos.length > 0 ? clearComboFilters : null}
|
||||
/>
|
||||
) : (
|
||||
<CatalogCombosResults context={context} />
|
||||
)}
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
"use client";
|
||||
|
||||
import Icon from "@/shared/components/Icon";
|
||||
|
||||
import { Suspense, useCallback, useMemo, useState } from "react";
|
||||
import { useTranslations } from "next-intl";
|
||||
import { Badge, Card, SegmentedControl } from "@/shared/components";
|
||||
// Imported from its module (not the barrel) so the page's barrel stubs in tests stay as they were.
|
||||
import KitButton from "@/shared/components/Button";
|
||||
import TranslatorConceptCard from "./components/TranslatorConceptCard";
|
||||
import TranslateTab from "./components/TranslateTab";
|
||||
import MonitorTab from "./components/MonitorTab";
|
||||
@@ -198,24 +202,26 @@ function AutoFeaturesCard() {
|
||||
|
||||
return (
|
||||
<Card className="border-primary/10 bg-primary/5">
|
||||
<button
|
||||
type="button"
|
||||
<KitButton
|
||||
variant="ghost"
|
||||
onClick={() => setShowFeatures((prev) => !prev)}
|
||||
aria-expanded={showFeatures}
|
||||
aria-controls="auto-features-grid"
|
||||
className="flex w-full items-center justify-between p-4 text-left"
|
||||
className="h-auto w-full justify-between p-4 text-left"
|
||||
>
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="material-symbols-outlined text-[20px] text-primary">auto_fix_high</span>
|
||||
<Icon name="auto_fix_high" size={20} className="text-primary" />
|
||||
<h3 className="text-sm font-semibold text-text-main">{t("autoFeaturesTitle")}</h3>
|
||||
<Badge variant="primary" size="sm">
|
||||
{t("autoFeaturesCount")}
|
||||
</Badge>
|
||||
</div>
|
||||
<span className="material-symbols-outlined text-[18px] text-text-muted">
|
||||
{showFeatures ? "expand_less" : "expand_more"}
|
||||
</span>
|
||||
</button>
|
||||
<Icon
|
||||
name={showFeatures ? "expand_less" : "expand_more"}
|
||||
size={18}
|
||||
className="text-text-muted"
|
||||
/>
|
||||
</KitButton>
|
||||
|
||||
{showFeatures && (
|
||||
<div
|
||||
@@ -288,45 +294,22 @@ function FeatureChip({
|
||||
description: string;
|
||||
color: "purple" | "blue" | "amber" | "emerald" | "cyan" | "orange" | "pink" | "indigo";
|
||||
}) {
|
||||
// Categorical chip accents on the kit chart/status tokens (theme-aware).
|
||||
const colorMap = {
|
||||
purple: {
|
||||
shell: "border-purple-500/20 bg-purple-500/5",
|
||||
icon: "text-purple-500",
|
||||
},
|
||||
blue: {
|
||||
shell: "border-blue-500/20 bg-blue-500/5",
|
||||
icon: "text-blue-500",
|
||||
},
|
||||
amber: {
|
||||
shell: "border-amber-500/20 bg-amber-500/5",
|
||||
icon: "text-amber-500",
|
||||
},
|
||||
emerald: {
|
||||
shell: "border-emerald-500/20 bg-emerald-500/5",
|
||||
icon: "text-emerald-500",
|
||||
},
|
||||
cyan: {
|
||||
shell: "border-cyan-500/20 bg-cyan-500/5",
|
||||
icon: "text-cyan-500",
|
||||
},
|
||||
orange: {
|
||||
shell: "border-orange-500/20 bg-orange-500/5",
|
||||
icon: "text-orange-500",
|
||||
},
|
||||
pink: {
|
||||
shell: "border-pink-500/20 bg-pink-500/5",
|
||||
icon: "text-pink-500",
|
||||
},
|
||||
indigo: {
|
||||
shell: "border-indigo-500/20 bg-indigo-500/5",
|
||||
icon: "text-indigo-500",
|
||||
},
|
||||
purple: { shell: "border-chart-3/20 bg-chart-3/5", icon: "text-chart-3" },
|
||||
blue: { shell: "border-chart-2/20 bg-chart-2/5", icon: "text-chart-2" },
|
||||
amber: { shell: "border-warning/20 bg-warning/5", icon: "text-warning" },
|
||||
emerald: { shell: "border-chart-4/20 bg-chart-4/5", icon: "text-chart-4" },
|
||||
cyan: { shell: "border-info/20 bg-info/5", icon: "text-info" },
|
||||
orange: { shell: "border-chart-5/20 bg-chart-5/5", icon: "text-chart-5" },
|
||||
pink: { shell: "border-chart-5/20 bg-chart-5/5", icon: "text-chart-5" },
|
||||
indigo: { shell: "border-chart-3/20 bg-chart-3/5", icon: "text-chart-3" },
|
||||
}[color];
|
||||
|
||||
return (
|
||||
<div className={`rounded-lg border p-3 ${colorMap.shell}`} data-testid="feature-chip">
|
||||
<div className="mb-1 flex items-center gap-2">
|
||||
<span className={`material-symbols-outlined text-[16px] ${colorMap.icon}`}>{icon}</span>
|
||||
<Icon name={icon} size={16} className={colorMap.icon} />
|
||||
<p className="text-xs font-semibold text-text-main">{title}</p>
|
||||
</div>
|
||||
<p className="text-[10px] leading-relaxed text-text-muted">{description}</p>
|
||||
|
||||
@@ -1,8 +1,20 @@
|
||||
"use client";
|
||||
|
||||
import Icon from "@/shared/components/Icon";
|
||||
|
||||
import { useTranslations } from "next-intl";
|
||||
import { useState, useEffect, useRef, useCallback } from "react";
|
||||
import { Card, Badge, EmptyState } from "@/shared/components";
|
||||
import {
|
||||
Table,
|
||||
TableBody,
|
||||
TableCell,
|
||||
TableHead,
|
||||
TableHeader,
|
||||
TableRow,
|
||||
} from "@omniroute/ui-kit/table";
|
||||
// Direct module import keeps the tests' barrel stubs (Card/Badge/EmptyState) unchanged.
|
||||
import Button from "@/shared/components/Button";
|
||||
import { FORMAT_META } from "../exampleTemplates";
|
||||
|
||||
interface MonitorTabProps {
|
||||
@@ -35,13 +47,14 @@ interface StatCardProps {
|
||||
color: "blue" | "green" | "red" | "purple" | "amber" | "cyan";
|
||||
}
|
||||
|
||||
// Stat accents on kit status/chart tokens (theme-aware).
|
||||
const COLOR_MAP: Record<StatCardProps["color"], { shell: string; icon: string }> = {
|
||||
blue: { shell: "bg-blue-500/10", icon: "text-blue-500" },
|
||||
green: { shell: "bg-green-500/10", icon: "text-green-500" },
|
||||
red: { shell: "bg-red-500/10", icon: "text-red-500" },
|
||||
purple: { shell: "bg-purple-500/10", icon: "text-purple-500" },
|
||||
amber: { shell: "bg-amber-500/10", icon: "text-amber-500" },
|
||||
cyan: { shell: "bg-cyan-500/10", icon: "text-cyan-500" },
|
||||
blue: { shell: "bg-info/10", icon: "text-info" },
|
||||
green: { shell: "bg-success/10", icon: "text-success" },
|
||||
red: { shell: "bg-error/10", icon: "text-error" },
|
||||
purple: { shell: "bg-chart-3/10", icon: "text-chart-3" },
|
||||
amber: { shell: "bg-warning/10", icon: "text-warning" },
|
||||
cyan: { shell: "bg-chart-2/10", icon: "text-chart-2" },
|
||||
};
|
||||
|
||||
function StatCard({ icon, label, value, color }: StatCardProps) {
|
||||
@@ -51,12 +64,7 @@ function StatCard({ icon, label, value, color }: StatCardProps) {
|
||||
<Card>
|
||||
<div className="p-4 flex items-center gap-3">
|
||||
<div className={`flex items-center justify-center w-10 h-10 rounded-lg ${resolved.shell}`}>
|
||||
<span
|
||||
className={`material-symbols-outlined text-[22px] ${resolved.icon}`}
|
||||
aria-hidden="true"
|
||||
>
|
||||
{icon}
|
||||
</span>
|
||||
<Icon name={icon} size={22} className={resolved.icon} />
|
||||
</div>
|
||||
<div>
|
||||
<p className="text-lg font-bold text-text-main">{value}</p>
|
||||
@@ -149,12 +157,7 @@ export default function MonitorTab({ onGoToTranslate }: MonitorTabProps) {
|
||||
className="flex items-start gap-3 px-4 py-3 rounded-lg bg-primary/5 border border-primary/10 text-sm text-text-muted"
|
||||
data-testid="monitor-origin-hint"
|
||||
>
|
||||
<span
|
||||
className="material-symbols-outlined text-primary text-[20px] mt-0.5 shrink-0"
|
||||
aria-hidden="true"
|
||||
>
|
||||
info
|
||||
</span>
|
||||
<Icon name="info" size={20} className="text-primary mt-0.5" />
|
||||
<p>
|
||||
{translateOrFallback(
|
||||
"monitorOriginHint",
|
||||
@@ -194,8 +197,8 @@ export default function MonitorTab({ onGoToTranslate }: MonitorTabProps) {
|
||||
</div>
|
||||
|
||||
{/* Memory note */}
|
||||
<div className="flex items-center gap-2 rounded-lg border border-amber-500/10 bg-amber-500/5 px-3 py-2 text-xs text-amber-600 dark:text-amber-400">
|
||||
<span className="material-symbols-outlined text-[14px]">memory</span>
|
||||
<div className="flex items-center gap-2 rounded-lg border border-warning/20 bg-warning-bg px-3 py-2 text-xs text-warning">
|
||||
<Icon name="memory" size={14} />
|
||||
<p>
|
||||
{t("liveMonitorMemoryNote")}{" "}
|
||||
<span className="text-text-muted">{t("liveMonitorMemoryCapNote")}</span>
|
||||
@@ -206,16 +209,15 @@ export default function MonitorTab({ onGoToTranslate }: MonitorTabProps) {
|
||||
<Card>
|
||||
<div className="p-3 flex items-center justify-between">
|
||||
<div className="flex items-center gap-2">
|
||||
<span
|
||||
className={`material-symbols-outlined text-[18px] ${autoRefresh ? "text-green-500 animate-pulse" : "text-text-muted"}`}
|
||||
aria-hidden="true"
|
||||
>
|
||||
{autoRefresh ? "radio_button_checked" : "radio_button_unchecked"}
|
||||
</span>
|
||||
<button
|
||||
type="button"
|
||||
<Icon
|
||||
name={autoRefresh ? "radio_button_checked" : "radio_button_unchecked"}
|
||||
size={18}
|
||||
className={autoRefresh ? "animate-pulse text-success" : "text-text-muted"}
|
||||
/>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={() => setAutoRefresh((prev) => !prev)}
|
||||
className="text-sm text-text-main hover:text-primary transition-colors"
|
||||
aria-label={
|
||||
autoRefresh
|
||||
? translateOrFallback("pauseAutoRefresh", "Pause auto-refresh")
|
||||
@@ -226,7 +228,7 @@ export default function MonitorTab({ onGoToTranslate }: MonitorTabProps) {
|
||||
{autoRefresh
|
||||
? translateOrFallback("liveAutoRefreshing", "Atualizando ao vivo")
|
||||
: translateOrFallback("paused", "Pausado")}
|
||||
</button>
|
||||
</Button>
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
{/* Live/Paused badge */}
|
||||
@@ -235,17 +237,9 @@ export default function MonitorTab({ onGoToTranslate }: MonitorTabProps) {
|
||||
? translateOrFallback("live", "Live")
|
||||
: translateOrFallback("paused", "Paused")}
|
||||
</Badge>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => void fetchHistory()}
|
||||
className="flex items-center gap-1 text-xs text-text-muted hover:text-primary transition-colors"
|
||||
aria-label={tc("refresh")}
|
||||
>
|
||||
<span className="material-symbols-outlined text-[16px]" aria-hidden="true">
|
||||
refresh
|
||||
</span>
|
||||
<Button variant="ghost" size="sm" icon="refresh" onClick={() => void fetchHistory()}>
|
||||
{tc("refresh")}
|
||||
</button>
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</Card>
|
||||
@@ -257,9 +251,7 @@ export default function MonitorTab({ onGoToTranslate }: MonitorTabProps) {
|
||||
|
||||
{loading ? (
|
||||
<div className="flex items-center justify-center py-12 text-text-muted">
|
||||
<span className="material-symbols-outlined animate-spin mr-2" aria-hidden="true">
|
||||
progress_activity
|
||||
</span>
|
||||
<Icon name="progress_activity" className="animate-spin mr-2" />
|
||||
{tc("loading")}
|
||||
</div>
|
||||
) : events.length === 0 ? (
|
||||
@@ -277,20 +269,20 @@ export default function MonitorTab({ onGoToTranslate }: MonitorTabProps) {
|
||||
/>
|
||||
</div>
|
||||
) : (
|
||||
<div className="overflow-x-auto" data-testid="monitor-events-table">
|
||||
<table className="w-full text-sm">
|
||||
<thead>
|
||||
<tr className="text-left text-xs text-text-muted border-b border-border">
|
||||
<th className="pb-2 pr-4">{t("time")}</th>
|
||||
<th className="pb-2 pr-4">{translateOrFallback("routeDetails", "Route")}</th>
|
||||
<th className="pb-2 pr-4">{t("source")}</th>
|
||||
<th className="pb-2 pr-4">{t("target")}</th>
|
||||
<th className="pb-2 pr-4">{t("model")}</th>
|
||||
<th className="pb-2 pr-4">{t("status")}</th>
|
||||
<th className="pb-2 text-right">{t("latency")}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<div data-testid="monitor-events-table">
|
||||
<Table scrollbarLabel={t("recentTranslations")} className="text-sm">
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead>{t("time")}</TableHead>
|
||||
<TableHead>{translateOrFallback("routeDetails", "Route")}</TableHead>
|
||||
<TableHead>{t("source")}</TableHead>
|
||||
<TableHead>{t("target")}</TableHead>
|
||||
<TableHead>{t("model")}</TableHead>
|
||||
<TableHead>{t("status")}</TableHead>
|
||||
<TableHead className="text-right">{t("latency")}</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{events.map((event, i) => {
|
||||
const srcMeta = FORMAT_META[event.sourceFormat as keyof typeof FORMAT_META] ?? {
|
||||
label: event.sourceFormat ?? "?",
|
||||
@@ -302,17 +294,13 @@ export default function MonitorTab({ onGoToTranslate }: MonitorTabProps) {
|
||||
};
|
||||
|
||||
return (
|
||||
<tr
|
||||
key={event.id ?? i}
|
||||
className="border-b border-border/50 hover:bg-bg-subtle/50 transition-colors"
|
||||
data-testid="monitor-event-row"
|
||||
>
|
||||
<td className="py-2 pr-4 text-xs text-text-muted whitespace-nowrap">
|
||||
<TableRow key={event.id ?? i} data-testid="monitor-event-row">
|
||||
<TableCell className="text-xs text-text-muted whitespace-nowrap">
|
||||
{event.timestamp
|
||||
? new Date(event.timestamp).toLocaleTimeString()
|
||||
: notAvailable}
|
||||
</td>
|
||||
<td className="py-2 pr-4 min-w-[220px]">
|
||||
</TableCell>
|
||||
<TableCell className="min-w-[220px]">
|
||||
<div className="flex flex-col gap-1">
|
||||
<div className="flex flex-wrap items-center gap-1.5">
|
||||
<Badge variant="default" size="sm">
|
||||
@@ -337,21 +325,21 @@ export default function MonitorTab({ onGoToTranslate }: MonitorTabProps) {
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
<td className="py-2 pr-4">
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<Badge variant="default" size="sm">
|
||||
{srcMeta.label}
|
||||
</Badge>
|
||||
</td>
|
||||
<td className="py-2 pr-4">
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<Badge variant="primary" size="sm">
|
||||
{tgtMeta.label}
|
||||
</Badge>
|
||||
</td>
|
||||
<td className="py-2 pr-4 text-xs font-mono text-text-muted break-all">
|
||||
</TableCell>
|
||||
<TableCell className="text-xs font-mono text-text-muted break-all">
|
||||
{event.model ?? notAvailable}
|
||||
</td>
|
||||
<td className="py-2 pr-4">
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
{event.status === "success" ? (
|
||||
<Badge variant="success" size="sm" dot>
|
||||
{t("ok")}
|
||||
@@ -361,15 +349,15 @@ export default function MonitorTab({ onGoToTranslate }: MonitorTabProps) {
|
||||
{event.statusCode ?? t("errorShort")}
|
||||
</Badge>
|
||||
)}
|
||||
</td>
|
||||
<td className="py-2 text-right text-xs text-text-muted">
|
||||
</TableCell>
|
||||
<TableCell className="text-right text-xs text-text-muted">
|
||||
{event.latency ? formatLatency(event.latency) : notAvailable}
|
||||
</td>
|
||||
</tr>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
);
|
||||
})}
|
||||
</tbody>
|
||||
</table>
|
||||
</TableBody>
|
||||
</Table>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
"use client";
|
||||
|
||||
import Icon from "@/shared/components/Icon";
|
||||
|
||||
import { useCallback } from "react";
|
||||
import { useTranslations } from "next-intl";
|
||||
import { Badge, Button, Card } from "@/shared/components";
|
||||
@@ -69,26 +71,18 @@ export default function ResultNarrated({
|
||||
<Card className="flex flex-col gap-4 p-4">
|
||||
{/* Header */}
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="material-symbols-outlined text-[20px] text-primary" aria-hidden="true">
|
||||
translate
|
||||
</span>
|
||||
<Icon name="translate" size={20} className="text-primary" />
|
||||
<h3 className="text-sm font-semibold text-text-main">
|
||||
{tr("simpleResultPanelTitle", "Translation + Response")}
|
||||
</h3>
|
||||
</div>
|
||||
|
||||
{/* Status area — aria-live for screen-reader announcements (D20) */}
|
||||
<div
|
||||
aria-live="polite"
|
||||
aria-atomic="true"
|
||||
className="flex flex-1 flex-col gap-3"
|
||||
>
|
||||
<div aria-live="polite" aria-atomic="true" className="flex flex-1 flex-col gap-3">
|
||||
{/* idle */}
|
||||
{result.status === "idle" && (
|
||||
<div className="flex flex-col items-center justify-center gap-2 py-8 text-center">
|
||||
<span className="material-symbols-outlined text-[40px] text-text-muted/40" aria-hidden="true">
|
||||
info
|
||||
</span>
|
||||
<Icon name="info" size={40} className="text-text-muted/40" />
|
||||
<p className="text-sm text-text-muted">
|
||||
{tr("simpleStartWithExamplePlaceholder", "Select a ready-made example")}
|
||||
</p>
|
||||
@@ -98,9 +92,7 @@ export default function ResultNarrated({
|
||||
{/* translating or sending */}
|
||||
{isSpinning && (
|
||||
<div className="flex items-center gap-3 py-6">
|
||||
<span className="material-symbols-outlined animate-spin text-[24px] text-primary" aria-hidden="true">
|
||||
progress_activity
|
||||
</span>
|
||||
<Icon name="progress_activity" size={24} className="animate-spin text-primary" />
|
||||
<span className="text-sm text-text-muted">
|
||||
{result.status === "translating"
|
||||
? tr("narratedTranslating", "Translating to {target}...", {
|
||||
@@ -135,7 +127,7 @@ export default function ResultNarrated({
|
||||
|
||||
{/* Response preview */}
|
||||
{result.responsePreview && (
|
||||
<div className="rounded-md border border-black/10 bg-black/5 p-3 dark:border-white/10 dark:bg-white/5">
|
||||
<div className="rounded-md border border-border bg-bg-subtle p-3">
|
||||
<pre className="overflow-x-auto whitespace-pre-wrap break-words font-mono text-xs text-text-main">
|
||||
{result.responsePreview.slice(0, 500)}
|
||||
</pre>
|
||||
@@ -172,9 +164,7 @@ export default function ResultNarrated({
|
||||
{result.status === "error" && (
|
||||
<div className="flex flex-col gap-2">
|
||||
<Badge variant="error">
|
||||
<span className="material-symbols-outlined text-[14px]" aria-hidden="true">
|
||||
error
|
||||
</span>
|
||||
<Icon name="error" size={14} />
|
||||
Error
|
||||
</Badge>
|
||||
<p className="text-sm text-text-main">
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
"use client";
|
||||
|
||||
import Icon from "@/shared/components/Icon";
|
||||
|
||||
import { useCallback } from "react";
|
||||
import { useTranslations } from "next-intl";
|
||||
import { Button, Select, SegmentedControl } from "@/shared/components";
|
||||
import { InfoTooltip } from "@/shared/components";
|
||||
import Textarea from "@/shared/components/Textarea";
|
||||
import { FORMAT_OPTIONS, FORMAT_META, getExampleTemplates } from "../exampleTemplates";
|
||||
import type { FormatId, TranslateMode } from "../types";
|
||||
|
||||
@@ -110,7 +113,10 @@ export default function SimpleControls({
|
||||
|
||||
const exampleSelectOptions = [
|
||||
...examples.map((ex) => ({ value: ex.id, label: ex.name })),
|
||||
{ value: "__custom__", label: tr("simpleStartWithCustomOption", "Paste your request (advanced)") },
|
||||
{
|
||||
value: "__custom__",
|
||||
label: tr("simpleStartWithCustomOption", "Paste your request (advanced)"),
|
||||
},
|
||||
];
|
||||
|
||||
const sourceOptions = FORMAT_OPTIONS;
|
||||
@@ -124,7 +130,12 @@ export default function SimpleControls({
|
||||
<span className="text-sm font-medium text-text-main">
|
||||
{tr("simpleAppUsesLabel", "My app uses")}
|
||||
</span>
|
||||
<InfoTooltip text={tr("simpleAppUsesHint", "The API format your app speaks (e.g. Anthropic SDK = claude).")} />
|
||||
<InfoTooltip
|
||||
text={tr(
|
||||
"simpleAppUsesHint",
|
||||
"The API format your app speaks (e.g. Anthropic SDK = claude)."
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
<Select
|
||||
aria-label={tr("simpleAppUsesLabel", "My app uses")}
|
||||
@@ -135,9 +146,7 @@ export default function SimpleControls({
|
||||
</div>
|
||||
|
||||
<div className="hidden items-center pt-8 sm:flex">
|
||||
<span className="material-symbols-outlined text-[20px] text-text-muted" aria-hidden="true">
|
||||
arrow_forward
|
||||
</span>
|
||||
<Icon name="arrow_forward" size={20} className="text-text-muted" />
|
||||
</div>
|
||||
|
||||
<div className="flex min-w-0 flex-1 flex-col gap-1">
|
||||
@@ -145,11 +154,18 @@ export default function SimpleControls({
|
||||
<span className="text-sm font-medium text-text-main">
|
||||
{tr("simpleSendToLabel", "Send to")}
|
||||
</span>
|
||||
<InfoTooltip text={tr("simpleSendToHint", "Where to actually send the request (a provider connected in OmniRoute).")} />
|
||||
<InfoTooltip
|
||||
text={tr(
|
||||
"simpleSendToHint",
|
||||
"Where to actually send the request (a provider connected in OmniRoute)."
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
<Select
|
||||
aria-label={tr("simpleSendToLabel", "Send to")}
|
||||
options={providerOptions.length > 0 ? providerOptions : [{ value: provider, label: provider }]}
|
||||
options={
|
||||
providerOptions.length > 0 ? providerOptions : [{ value: provider, label: provider }]
|
||||
}
|
||||
value={provider}
|
||||
onChange={handleProviderChange}
|
||||
disabled={loading}
|
||||
@@ -173,9 +189,7 @@ export default function SimpleControls({
|
||||
|
||||
{/* Row 3: mode segmented control */}
|
||||
<div className="flex flex-col gap-1">
|
||||
<span className="text-sm font-medium text-text-main">
|
||||
{tr("simpleModeLabel", "Mode")}
|
||||
</span>
|
||||
<span className="text-sm font-medium text-text-main">{tr("simpleModeLabel", "Mode")}</span>
|
||||
<SegmentedControl
|
||||
options={modeOptions}
|
||||
value={mode}
|
||||
@@ -189,13 +203,13 @@ export default function SimpleControls({
|
||||
<span className="text-sm font-medium text-text-main">
|
||||
{tr("simpleInputPanelTitle", "Input")}
|
||||
</span>
|
||||
<textarea
|
||||
<Textarea
|
||||
aria-label={tr("simpleInputPanelTitle", "Input")}
|
||||
rows={6}
|
||||
value={inputText}
|
||||
onChange={(e) => onInputChange(e.target.value)}
|
||||
placeholder={tr("simpleInputPanelHint", "Free-text message or ready-made example")}
|
||||
className="w-full resize-y rounded-lg border border-black/10 bg-white px-3 py-2 font-mono text-sm text-text-main placeholder:text-text-muted focus:outline-none focus:ring-2 focus:ring-primary/40 dark:border-white/10 dark:bg-white/5"
|
||||
className="w-full resize-y font-mono text-sm"
|
||||
/>
|
||||
</div>
|
||||
|
||||
@@ -213,15 +227,14 @@ export default function SimpleControls({
|
||||
: tr("simpleModeSend", "Send and see response")}
|
||||
</Button>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
<Button
|
||||
variant="ghost"
|
||||
icon="tune"
|
||||
onClick={onOpenAdvanced}
|
||||
aria-label={tr("simpleAdvancedToggle", "Advanced")}
|
||||
className="inline-flex items-center gap-1 rounded-md px-3 py-1.5 text-sm text-text-muted transition-colors hover:bg-black/5 hover:text-text-main dark:hover:bg-white/5"
|
||||
>
|
||||
<span className="material-symbols-outlined text-[16px]" aria-hidden="true">tune</span>
|
||||
{tr("simpleAdvancedToggle", "Advanced")}
|
||||
</button>
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
import { useCallback, type ReactNode } from "react";
|
||||
import { useTranslations } from "next-intl";
|
||||
import Icon from "@/shared/components/Icon";
|
||||
import Tooltip from "@/shared/components/Tooltip";
|
||||
|
||||
interface FlowNodeProps {
|
||||
@@ -12,23 +13,16 @@ interface FlowNodeProps {
|
||||
tooltipContent?: string;
|
||||
}
|
||||
|
||||
// Categorical node accents on the kit chart tokens (theme-aware, both modes).
|
||||
const COLOR_MAP: Record<FlowNodeProps["color"], { border: string; bg: string; text: string }> = {
|
||||
primary: { border: "border-primary/30", bg: "bg-primary/5", text: "text-primary" },
|
||||
orange: { border: "border-orange-500/30", bg: "bg-orange-500/5", text: "text-orange-500" },
|
||||
blue: { border: "border-blue-500/30", bg: "bg-blue-500/5", text: "text-blue-500" },
|
||||
emerald: {
|
||||
border: "border-emerald-500/30",
|
||||
bg: "bg-emerald-500/5",
|
||||
text: "text-emerald-500",
|
||||
},
|
||||
amber: { border: "border-amber-500/30", bg: "bg-amber-500/5", text: "text-amber-500" },
|
||||
purple: {
|
||||
border: "border-purple-500/30",
|
||||
bg: "bg-purple-500/5",
|
||||
text: "text-purple-500",
|
||||
},
|
||||
cyan: { border: "border-cyan-500/30", bg: "bg-cyan-500/5", text: "text-cyan-500" },
|
||||
pink: { border: "border-pink-500/30", bg: "bg-pink-500/5", text: "text-pink-500" },
|
||||
orange: { border: "border-chart-5/30", bg: "bg-chart-5/5", text: "text-chart-5" },
|
||||
blue: { border: "border-chart-2/30", bg: "bg-chart-2/5", text: "text-chart-2" },
|
||||
emerald: { border: "border-chart-4/30", bg: "bg-chart-4/5", text: "text-chart-4" },
|
||||
amber: { border: "border-warning/30", bg: "bg-warning/5", text: "text-warning" },
|
||||
purple: { border: "border-chart-3/30", bg: "bg-chart-3/5", text: "text-chart-3" },
|
||||
cyan: { border: "border-info/30", bg: "bg-info/5", text: "text-info" },
|
||||
pink: { border: "border-chart-5/30", bg: "bg-chart-5/5", text: "text-chart-5" },
|
||||
};
|
||||
|
||||
function FlowNode({ icon, color, title, example, tooltipContent }: FlowNodeProps) {
|
||||
@@ -37,9 +31,7 @@ function FlowNode({ icon, color, title, example, tooltipContent }: FlowNodeProps
|
||||
<div
|
||||
className={`flex flex-col items-center gap-1 rounded-lg border ${c.border} ${c.bg} px-3 py-2 text-center min-w-0`}
|
||||
>
|
||||
<span className={`material-symbols-outlined text-[20px] ${c.text}`} aria-hidden="true">
|
||||
{icon}
|
||||
</span>
|
||||
<Icon name={icon} size={20} className={c.text} />
|
||||
<p className="text-[11px] font-semibold text-text-main leading-tight">{title}</p>
|
||||
<p className="text-[10px] text-text-muted leading-tight">{example}</p>
|
||||
</div>
|
||||
@@ -57,12 +49,7 @@ function FlowNode({ icon, color, title, example, tooltipContent }: FlowNodeProps
|
||||
function FlowArrow({ label }: { label?: string }) {
|
||||
return (
|
||||
<div className="flex flex-col items-center justify-center text-text-muted">
|
||||
<span
|
||||
className="material-symbols-outlined text-[20px] rotate-90 sm:rotate-0"
|
||||
aria-hidden="true"
|
||||
>
|
||||
arrow_forward
|
||||
</span>
|
||||
<Icon name="arrow_forward" size={20} className="rotate-90 sm:rotate-0" />
|
||||
{label && <span className="text-[9px] uppercase tracking-wide mt-0.5">{label}</span>}
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
"use client";
|
||||
|
||||
import Button from "@/shared/components/Button";
|
||||
import Icon from "@/shared/components/Icon";
|
||||
|
||||
import { useCallback, useState } from "react";
|
||||
import { useTranslations } from "next-intl";
|
||||
import { Card } from "@/shared/components";
|
||||
@@ -25,12 +28,7 @@ export default function TranslatorConceptCard() {
|
||||
<Card className="border-primary/10 bg-primary/5">
|
||||
<div className="p-4 space-y-3">
|
||||
<div className="flex items-start gap-3">
|
||||
<span
|
||||
className="material-symbols-outlined text-primary text-[22px] mt-0.5 shrink-0"
|
||||
aria-hidden="true"
|
||||
>
|
||||
info
|
||||
</span>
|
||||
<Icon name="info" size={22} className="text-primary mt-0.5" />
|
||||
<div className="flex-1 min-w-0">
|
||||
<h2 className="text-sm font-semibold text-text-main mb-1">
|
||||
{tr(
|
||||
@@ -49,18 +47,17 @@ export default function TranslatorConceptCard() {
|
||||
|
||||
<TranslateFlowDiagram />
|
||||
|
||||
<button
|
||||
type="button"
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={() => setOpen((v) => !v)}
|
||||
aria-expanded={open}
|
||||
aria-controls="translator-concept-how-it-works"
|
||||
className="flex items-center gap-2 text-xs font-medium text-primary hover:text-primary/80 transition-colors w-full justify-start py-1 rounded"
|
||||
className="w-full justify-start text-xs font-medium text-primary"
|
||||
>
|
||||
<span>{tr("conceptHowItWorksToggle", "How it works")}</span>
|
||||
<span className="material-symbols-outlined text-[16px]" aria-hidden="true">
|
||||
{open ? "expand_less" : "expand_more"}
|
||||
</span>
|
||||
</button>
|
||||
<Icon name={open ? "expand_less" : "expand_more"} size={16} />
|
||||
</Button>
|
||||
|
||||
{open && (
|
||||
<div
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
"use client";
|
||||
|
||||
import Icon from "@/shared/components/Icon";
|
||||
|
||||
import { type ReactNode } from "react";
|
||||
import { useTranslations } from "next-intl";
|
||||
import { Card } from "@/shared/components";
|
||||
@@ -21,10 +23,7 @@ export interface AdvancedSectionProps {
|
||||
* forceOpenSlug is forwarded as data-slug on the wrapper div so each
|
||||
* accordion child can read it via props passed down by F9's TranslateTab.
|
||||
*/
|
||||
export default function AdvancedSection({
|
||||
forceOpenSlug,
|
||||
children,
|
||||
}: AdvancedSectionProps) {
|
||||
export default function AdvancedSection({ forceOpenSlug, children }: AdvancedSectionProps) {
|
||||
const t = useTranslations("translator");
|
||||
|
||||
/** Safe i18n with inline fallback — pattern from TranslatorPageClient. */
|
||||
@@ -40,16 +39,11 @@ export default function AdvancedSection({
|
||||
};
|
||||
|
||||
return (
|
||||
<Card id="translator-advanced-section" className="border-amber-500/10 bg-amber-500/[0.02]">
|
||||
<Card id="translator-advanced-section" className="border-warning/20 bg-warning/[0.02]">
|
||||
<div className="p-4 space-y-3">
|
||||
{/* Header */}
|
||||
<div className="flex items-start gap-3">
|
||||
<span
|
||||
className="material-symbols-outlined text-amber-500 text-[20px] mt-0.5 shrink-0"
|
||||
aria-hidden="true"
|
||||
>
|
||||
tune
|
||||
</span>
|
||||
<Icon name="tune" size={20} className="text-warning mt-0.5" />
|
||||
<div className="min-w-0">
|
||||
<h3 className="text-sm font-semibold text-text-main">
|
||||
{tr("advancedSectionTitle", "Advanced")}
|
||||
@@ -57,7 +51,7 @@ export default function AdvancedSection({
|
||||
<p className="text-xs text-text-muted">
|
||||
{tr(
|
||||
"advancedSectionSubtitle",
|
||||
"Raw JSON, pipeline e ferramentas técnicas. Tudo aqui é igual às tabs antigas — apenas reorganizado.",
|
||||
"Raw JSON, pipeline e ferramentas técnicas. Tudo aqui é igual às tabs antigas — apenas reorganizado."
|
||||
)}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
"use client";
|
||||
|
||||
// Header toggle imports the Button module directly so tests can keep stubbing the barrel.
|
||||
import HeaderButton from "@/shared/components/Button";
|
||||
import Icon from "@/shared/components/Icon";
|
||||
|
||||
import { useState, useEffect, useCallback, useRef } from "react";
|
||||
import { useTranslations } from "next-intl";
|
||||
import { Button, Select } from "@/shared/components";
|
||||
@@ -106,10 +110,8 @@ function CompressionPreviewContent({ inputContent = "" }: { inputContent?: strin
|
||||
<div className="space-y-4">
|
||||
{/* Empty state */}
|
||||
{!hasInput && (
|
||||
<div className="flex items-center gap-2 px-3 py-2 rounded-md bg-black/5 dark:bg-white/5 text-sm text-text-muted">
|
||||
<span className="material-symbols-outlined text-[16px]" aria-hidden="true">
|
||||
info
|
||||
</span>
|
||||
<div className="flex items-center gap-2 px-3 py-2 rounded-md bg-bg-subtle text-sm text-text-muted">
|
||||
<Icon name="info" size={16} />
|
||||
<span>{t("compressionEmptyHint")}</span>
|
||||
</div>
|
||||
)}
|
||||
@@ -139,7 +141,7 @@ function CompressionPreviewContent({ inputContent = "" }: { inputContent?: strin
|
||||
|
||||
{/* Error */}
|
||||
{compressionError && (
|
||||
<div className="text-sm text-red-500" role="alert">
|
||||
<div className="text-sm text-error" role="alert">
|
||||
{compressionError}
|
||||
</div>
|
||||
)}
|
||||
@@ -151,24 +153,22 @@ function CompressionPreviewContent({ inputContent = "" }: { inputContent?: strin
|
||||
className="grid grid-cols-2 md:grid-cols-4 gap-3"
|
||||
data-testid="compression-result-grid"
|
||||
>
|
||||
<div className="card p-3 text-center bg-black/5 dark:bg-white/5 rounded-lg border border-border">
|
||||
<div className="card p-3 text-center bg-bg-subtle rounded-lg border border-border">
|
||||
<div className="text-xs text-text-muted">{t("compressionOriginal")}</div>
|
||||
<div className="text-lg font-bold">{compressionResult.originalTokens}</div>
|
||||
<div className="text-xs text-text-muted">{t("tokens")}</div>
|
||||
</div>
|
||||
<div className="card p-3 text-center bg-black/5 dark:bg-white/5 rounded-lg border border-border">
|
||||
<div className="card p-3 text-center bg-bg-subtle rounded-lg border border-border">
|
||||
<div className="text-xs text-text-muted">{t("compressionCompressed")}</div>
|
||||
<div className="text-lg font-bold">{compressionResult.compressedTokens}</div>
|
||||
<div className="text-xs text-text-muted">{t("tokens")}</div>
|
||||
</div>
|
||||
<div className="card p-3 text-center bg-black/5 dark:bg-white/5 rounded-lg border border-border">
|
||||
<div className="card p-3 text-center bg-bg-subtle rounded-lg border border-border">
|
||||
<div className="text-xs text-text-muted">{t("compressionSaved")}</div>
|
||||
<div className="text-lg font-bold text-green-500">
|
||||
{compressionResult.tokensSaved}
|
||||
</div>
|
||||
<div className="text-lg font-bold text-success">{compressionResult.tokensSaved}</div>
|
||||
<div className="text-xs text-text-muted">{compressionResult.savingsPct}%</div>
|
||||
</div>
|
||||
<div className="card p-3 text-center bg-black/5 dark:bg-white/5 rounded-lg border border-border">
|
||||
<div className="card p-3 text-center bg-bg-subtle rounded-lg border border-border">
|
||||
<div className="text-xs text-text-muted">{t("compressionDuration")}</div>
|
||||
<div className="text-lg font-bold">{compressionResult.durationMs}</div>
|
||||
<div className="text-xs text-text-muted">ms</div>
|
||||
@@ -247,40 +247,34 @@ export default function CompressionPreviewAccordion({
|
||||
|
||||
return (
|
||||
<div
|
||||
className="rounded-lg border border-black/5 dark:border-white/5 bg-surface w-full"
|
||||
className="rounded-lg border border-border bg-surface w-full"
|
||||
data-testid="compression-accordion"
|
||||
>
|
||||
{/* Header row — matches Collapsible visual style */}
|
||||
<div
|
||||
className={cn(
|
||||
"flex items-center gap-3 p-4 hover:bg-black/[0.02] dark:hover:bg-white/[0.02] transition-colors",
|
||||
open && "border-b border-black/5 dark:border-white/5"
|
||||
"flex items-center gap-3 p-4 transition-colors hover:bg-bg-subtle",
|
||||
open && "border-b border-border"
|
||||
)}
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
<HeaderButton
|
||||
variant="ghost"
|
||||
onClick={handleToggle}
|
||||
aria-expanded={open}
|
||||
aria-controls="compression-preview-content"
|
||||
className="flex items-center gap-3 flex-1 min-w-0 text-left -m-1 p-1 rounded"
|
||||
className="-m-1 h-auto min-w-0 flex-1 justify-start gap-3 p-1 text-left"
|
||||
>
|
||||
<span
|
||||
className="material-symbols-outlined text-text-muted text-[20px] shrink-0"
|
||||
aria-hidden="true"
|
||||
>
|
||||
{open ? "expand_more" : "chevron_right"}
|
||||
</span>
|
||||
<span
|
||||
className="material-symbols-outlined text-text-muted text-[18px] shrink-0"
|
||||
aria-hidden="true"
|
||||
>
|
||||
compress
|
||||
</span>
|
||||
<Icon
|
||||
name={open ? "expand_more" : "chevron_right"}
|
||||
size={20}
|
||||
className="text-text-muted"
|
||||
/>
|
||||
<Icon name="compress" size={18} className="text-text-muted" />
|
||||
<div className="flex-1 min-w-0">
|
||||
<div className="text-sm font-medium text-text-main truncate">{title}</div>
|
||||
<div className="text-xs text-text-muted truncate">{subtitle}</div>
|
||||
</div>
|
||||
</button>
|
||||
</HeaderButton>
|
||||
</div>
|
||||
|
||||
{/* Content — D7 lazy-render */}
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
"use client";
|
||||
|
||||
import Icon from "@/shared/components/Icon";
|
||||
|
||||
import { useState, useEffect, useCallback } from "react";
|
||||
import { useTranslations } from "next-intl";
|
||||
import { Card, Badge } from "@/shared/components";
|
||||
import Collapsible from "@/shared/components/Collapsible";
|
||||
// Direct module import: tests stub the barrel (Card/Badge) only.
|
||||
import StepButton from "@/shared/components/Button";
|
||||
import { FORMAT_META } from "../../exampleTemplates";
|
||||
import type { AdvancedAccordionProps, FormatId } from "../../types";
|
||||
|
||||
@@ -90,9 +94,9 @@ function statusNumberClass(status: PipelineStep["status"]): string {
|
||||
case "active":
|
||||
return "bg-primary/10 text-primary";
|
||||
case "done":
|
||||
return "bg-emerald-500/10 text-emerald-500";
|
||||
return "bg-success/10 text-success";
|
||||
case "error":
|
||||
return "bg-red-500/10 text-red-500";
|
||||
return "bg-error/10 text-error";
|
||||
default:
|
||||
return "bg-bg-subtle text-text-muted";
|
||||
}
|
||||
@@ -172,7 +176,7 @@ export default function PipelineView({
|
||||
subtitle={tr("advancedPipelineSubtitle", "Visualize cada passo da tradução (hub-and-spoke).")}
|
||||
icon="route"
|
||||
defaultOpen={defaultOpen || forceOpen}
|
||||
className="border-black/5 dark:border-white/5"
|
||||
className="border-border"
|
||||
>
|
||||
{/* D7 lazy-render container */}
|
||||
<div
|
||||
@@ -190,9 +194,7 @@ export default function PipelineView({
|
||||
{/* Demo badge when showing placeholder data */}
|
||||
{!pipelineSteps && (
|
||||
<div className="flex items-center gap-2 text-xs text-text-muted px-1">
|
||||
<span className="material-symbols-outlined text-[14px]" aria-hidden="true">
|
||||
info
|
||||
</span>
|
||||
<Icon name="info" size={14} />
|
||||
<span>
|
||||
{tr(
|
||||
"pipelineVisualizationHint",
|
||||
@@ -228,7 +230,7 @@ export default function PipelineView({
|
||||
<Card
|
||||
className={
|
||||
step.status === "error"
|
||||
? "border-red-500/30"
|
||||
? "border-error/30"
|
||||
: isExpanded
|
||||
? "border-primary/30"
|
||||
: step.status === "pending"
|
||||
@@ -236,10 +238,10 @@ export default function PipelineView({
|
||||
: ""
|
||||
}
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
<StepButton
|
||||
variant="ghost"
|
||||
onClick={() => setExpandedStepId(isExpanded ? null : step.id)}
|
||||
className="w-full p-3 flex items-center gap-3 text-left"
|
||||
className="h-auto w-full justify-start gap-3 p-3 text-left"
|
||||
aria-expanded={isExpanded}
|
||||
aria-controls={`pipeline-step-content-${step.id}`}
|
||||
>
|
||||
@@ -275,13 +277,12 @@ export default function PipelineView({
|
||||
</div>
|
||||
|
||||
{/* Expand chevron */}
|
||||
<span
|
||||
className="material-symbols-outlined text-[18px] text-text-muted shrink-0"
|
||||
aria-hidden="true"
|
||||
>
|
||||
{isExpanded ? "expand_less" : "expand_more"}
|
||||
</span>
|
||||
</button>
|
||||
<Icon
|
||||
name={isExpanded ? "expand_less" : "expand_more"}
|
||||
size={18}
|
||||
className="text-text-muted"
|
||||
/>
|
||||
</StepButton>
|
||||
|
||||
{/* Expanded content — pre-formatted JSON/SSE */}
|
||||
{isExpanded && (
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
"use client";
|
||||
|
||||
// Direct module import: tests stub the barrel Button with a reduced prop set.
|
||||
import IconButton from "@/shared/components/Button";
|
||||
import Icon from "@/shared/components/Icon";
|
||||
import { cn } from "@/shared/utils/cn";
|
||||
|
||||
import { useState, useCallback, useEffect, useMemo } from "react";
|
||||
import { useTranslations } from "next-intl";
|
||||
import { Card, Button, Select, Badge } from "@/shared/components";
|
||||
@@ -24,6 +29,18 @@ export interface RawJsonPanelProps extends Omit<AdvancedAccordionProps, "slug">
|
||||
* Collapsible opens. Once opened, `hasOpened` stays true so editors remain
|
||||
* mounted through subsequent open/close cycles (preserving editor state).
|
||||
*/
|
||||
// FORMAT_META colour names → theme-aware kit tokens (the old `text-${color}-500`
|
||||
// template string was never generated by Tailwind).
|
||||
const FORMAT_ACCENT_CLASS: Record<string, string> = {
|
||||
amber: "text-warning",
|
||||
blue: "text-chart-2",
|
||||
cyan: "text-info",
|
||||
emerald: "text-chart-4",
|
||||
orange: "text-chart-5",
|
||||
pink: "text-chart-5",
|
||||
purple: "text-chart-3",
|
||||
};
|
||||
|
||||
export default function RawJsonPanel({
|
||||
forceOpen = false,
|
||||
onOpenChange,
|
||||
@@ -246,7 +263,7 @@ export default function RawJsonPanel({
|
||||
)}
|
||||
icon="code"
|
||||
defaultOpen={defaultOpen || forceOpen}
|
||||
className="border-black/5 dark:border-white/5"
|
||||
className="border-border"
|
||||
>
|
||||
{/* Internal open-state control — Collapsible owns its own open state,
|
||||
but we mirror it here for the lazy-render guard and onOpenChange. */}
|
||||
@@ -269,13 +286,8 @@ export default function RawJsonPanel({
|
||||
<>
|
||||
{/* Error banner */}
|
||||
{errorMessage && (
|
||||
<div className="flex items-start gap-2 px-3 py-2 rounded-lg bg-red-500/10 border border-red-500/20 text-sm text-red-500">
|
||||
<span
|
||||
className="material-symbols-outlined text-[16px] mt-0.5 shrink-0"
|
||||
aria-hidden="true"
|
||||
>
|
||||
error
|
||||
</span>
|
||||
<div className="flex items-start gap-2 px-3 py-2 rounded-lg bg-error/10 border border-error/20 text-sm text-error">
|
||||
<Icon name="error" size={16} className="mt-0.5" />
|
||||
<span>{errorMessage}</span>
|
||||
</div>
|
||||
)}
|
||||
@@ -285,17 +297,19 @@ export default function RawJsonPanel({
|
||||
<div className="p-4 flex flex-col sm:flex-row items-center gap-4">
|
||||
{/* Source Format */}
|
||||
<div className="flex-1 w-full">
|
||||
<label className="block text-xs font-medium text-text-muted mb-1.5 uppercase tracking-wider">
|
||||
{tr("source", "Source")}
|
||||
</label>
|
||||
<div className="flex items-center gap-2">
|
||||
<span
|
||||
className={`material-symbols-outlined text-[20px] text-${srcMeta.color}-500`}
|
||||
aria-hidden="true"
|
||||
>
|
||||
{srcMeta.icon}
|
||||
</span>
|
||||
{/* The label lives on the Select (associated with the kit trigger); the format
|
||||
icon and the auto badge sit beside the control, aligned to its baseline. */}
|
||||
<div className="flex items-end gap-2">
|
||||
<Icon
|
||||
name={srcMeta.icon}
|
||||
size={20}
|
||||
className={cn(
|
||||
"mb-2 shrink-0",
|
||||
FORMAT_ACCENT_CLASS[srcMeta.color] ?? "text-text-muted"
|
||||
)}
|
||||
/>
|
||||
<Select
|
||||
label={tr("source", "Source")}
|
||||
value={sourceFormat}
|
||||
onChange={(e: React.ChangeEvent<HTMLSelectElement>) => {
|
||||
setSourceFormat(e.target.value);
|
||||
@@ -305,7 +319,7 @@ export default function RawJsonPanel({
|
||||
className="flex-1"
|
||||
/>
|
||||
{detectedFormat && (
|
||||
<Badge variant="primary" size="sm" icon="auto_awesome">
|
||||
<Badge variant="primary" size="sm" icon="auto_awesome" className="mb-2">
|
||||
{tr("auto", "auto")}
|
||||
</Badge>
|
||||
)}
|
||||
@@ -313,31 +327,30 @@ export default function RawJsonPanel({
|
||||
</div>
|
||||
|
||||
{/* Swap Button */}
|
||||
<button
|
||||
type="button"
|
||||
<IconButton
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
onClick={handleSwapFormats}
|
||||
className="p-2 rounded-full hover:bg-primary/10 text-text-muted hover:text-primary transition-all mt-4 sm:mt-5"
|
||||
className="mt-4 rounded-full sm:mt-5"
|
||||
title={tr("swapFormats", "Swap formats")}
|
||||
aria-label={tr("swapFormats", "Swap formats")}
|
||||
>
|
||||
<span className="material-symbols-outlined text-[24px]" aria-hidden="true">
|
||||
swap_horiz
|
||||
</span>
|
||||
</button>
|
||||
<Icon name="swap_horiz" size={24} />
|
||||
</IconButton>
|
||||
|
||||
{/* Target Format */}
|
||||
<div className="flex-1 w-full">
|
||||
<label className="block text-xs font-medium text-text-muted mb-1.5 uppercase tracking-wider">
|
||||
{tr("target", "Target")}
|
||||
</label>
|
||||
<div className="flex items-center gap-2">
|
||||
<span
|
||||
className={`material-symbols-outlined text-[20px] text-${tgtMeta.color}-500`}
|
||||
aria-hidden="true"
|
||||
>
|
||||
{tgtMeta.icon}
|
||||
</span>
|
||||
<div className="flex items-end gap-2">
|
||||
<Icon
|
||||
name={tgtMeta.icon}
|
||||
size={20}
|
||||
className={cn(
|
||||
"mb-2 shrink-0",
|
||||
FORMAT_ACCENT_CLASS[tgtMeta.color] ?? "text-text-muted"
|
||||
)}
|
||||
/>
|
||||
<Select
|
||||
label={tr("target", "Target")}
|
||||
value={targetFormat}
|
||||
onChange={(e: React.ChangeEvent<HTMLSelectElement>) =>
|
||||
setTargetFormat(e.target.value)
|
||||
@@ -366,9 +379,7 @@ export default function RawJsonPanel({
|
||||
{/* Translation path indicator */}
|
||||
{translationPath && (
|
||||
<div className="flex items-center gap-2 text-xs text-text-muted">
|
||||
<span className="material-symbols-outlined text-[14px]" aria-hidden="true">
|
||||
route
|
||||
</span>
|
||||
<Icon name="route" size={14} />
|
||||
{translationPath === "hub-and-spoke" ? (
|
||||
<span>
|
||||
{(() => {
|
||||
@@ -410,12 +421,7 @@ export default function RawJsonPanel({
|
||||
<div className="p-4 space-y-3">
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="flex items-center gap-2">
|
||||
<span
|
||||
className="material-symbols-outlined text-[18px] text-text-muted"
|
||||
aria-hidden="true"
|
||||
>
|
||||
input
|
||||
</span>
|
||||
<Icon name="input" size={18} className="text-text-muted" />
|
||||
<h3 className="text-sm font-semibold text-text-main">
|
||||
{tr("input", "Input")}
|
||||
</h3>
|
||||
@@ -425,28 +431,26 @@ export default function RawJsonPanel({
|
||||
</Badge>
|
||||
)}
|
||||
{detecting && (
|
||||
<span
|
||||
className="material-symbols-outlined text-[14px] text-text-muted animate-spin"
|
||||
aria-hidden="true"
|
||||
>
|
||||
progress_activity
|
||||
</span>
|
||||
<Icon
|
||||
name="progress_activity"
|
||||
size={14}
|
||||
className="text-text-muted animate-spin"
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
<div className="flex items-center gap-1">
|
||||
<button
|
||||
type="button"
|
||||
<IconButton
|
||||
variant="ghost"
|
||||
size="icon-sm"
|
||||
onClick={() => handleCopy(inputContent)}
|
||||
className="p-1.5 rounded hover:bg-black/5 dark:hover:bg-white/5 text-text-muted hover:text-text-main transition-colors"
|
||||
title={tc("copy" as Parameters<typeof tc>[0])}
|
||||
aria-label={tr("input", "Input") + " — copy"}
|
||||
>
|
||||
<span className="material-symbols-outlined text-[16px]" aria-hidden="true">
|
||||
content_copy
|
||||
</span>
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
<Icon name="content_copy" size={16} />
|
||||
</IconButton>
|
||||
<IconButton
|
||||
variant="ghost"
|
||||
size="icon-sm"
|
||||
onClick={() => {
|
||||
setInputContent("");
|
||||
setOutputContent("");
|
||||
@@ -454,14 +458,11 @@ export default function RawJsonPanel({
|
||||
setActiveTemplate(null);
|
||||
setErrorMessage(null);
|
||||
}}
|
||||
className="p-1.5 rounded hover:bg-black/5 dark:hover:bg-white/5 text-text-muted hover:text-text-main transition-colors"
|
||||
title={tr("clear", "Clear")}
|
||||
aria-label={tr("clear", "Clear") + " input"}
|
||||
>
|
||||
<span className="material-symbols-outlined text-[16px]" aria-hidden="true">
|
||||
delete
|
||||
</span>
|
||||
</button>
|
||||
<Icon name="delete" size={16} />
|
||||
</IconButton>
|
||||
</div>
|
||||
</div>
|
||||
<div className="border border-border rounded-lg overflow-hidden">
|
||||
@@ -491,12 +492,7 @@ export default function RawJsonPanel({
|
||||
<div className="p-4 space-y-3">
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="flex items-center gap-2">
|
||||
<span
|
||||
className="material-symbols-outlined text-[18px] text-amber-500"
|
||||
aria-hidden="true"
|
||||
>
|
||||
hub
|
||||
</span>
|
||||
<Icon name="hub" size={18} className="text-warning" />
|
||||
<h3 className="text-sm font-semibold text-text-main">
|
||||
{tr("openaiIntermediatePanel", "OpenAI Intermediate")}
|
||||
</h3>
|
||||
@@ -504,17 +500,15 @@ export default function RawJsonPanel({
|
||||
Hub
|
||||
</Badge>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
<IconButton
|
||||
variant="ghost"
|
||||
size="icon-sm"
|
||||
onClick={() => handleCopy(intermediateContent)}
|
||||
className="p-1.5 rounded hover:bg-black/5 dark:hover:bg-white/5 text-text-muted hover:text-text-main transition-colors"
|
||||
title={tc("copy" as Parameters<typeof tc>[0])}
|
||||
aria-label={tr("copyIntermediateJson", "Copy intermediate JSON")}
|
||||
>
|
||||
<span className="material-symbols-outlined text-[16px]" aria-hidden="true">
|
||||
content_copy
|
||||
</span>
|
||||
</button>
|
||||
<Icon name="content_copy" size={16} />
|
||||
</IconButton>
|
||||
</div>
|
||||
<div className="border border-border rounded-lg overflow-hidden">
|
||||
<Editor
|
||||
@@ -542,12 +536,7 @@ export default function RawJsonPanel({
|
||||
<div className="p-4 space-y-3">
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="flex items-center gap-2">
|
||||
<span
|
||||
className="material-symbols-outlined text-[18px] text-text-muted"
|
||||
aria-hidden="true"
|
||||
>
|
||||
output
|
||||
</span>
|
||||
<Icon name="output" size={18} className="text-text-muted" />
|
||||
<h3 className="text-sm font-semibold text-text-main">
|
||||
{tr("output", "Output")}
|
||||
</h3>
|
||||
@@ -557,17 +546,15 @@ export default function RawJsonPanel({
|
||||
</Badge>
|
||||
)}
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
<IconButton
|
||||
variant="ghost"
|
||||
size="icon-sm"
|
||||
onClick={() => handleCopy(outputContent)}
|
||||
className="p-1.5 rounded hover:bg-black/5 dark:hover:bg-white/5 text-text-muted hover:text-text-main transition-colors"
|
||||
title={tc("copy" as Parameters<typeof tc>[0])}
|
||||
aria-label={tr("copyOutputJson", "Copy output JSON")}
|
||||
>
|
||||
<span className="material-symbols-outlined text-[16px]" aria-hidden="true">
|
||||
content_copy
|
||||
</span>
|
||||
</button>
|
||||
<Icon name="content_copy" size={16} />
|
||||
</IconButton>
|
||||
</div>
|
||||
<div className="border border-border rounded-lg overflow-hidden">
|
||||
<Editor
|
||||
@@ -594,12 +581,7 @@ export default function RawJsonPanel({
|
||||
<Card>
|
||||
<div className="p-4 space-y-3">
|
||||
<div className="flex items-center gap-2">
|
||||
<span
|
||||
className="material-symbols-outlined text-[18px] text-primary"
|
||||
aria-hidden="true"
|
||||
>
|
||||
library_books
|
||||
</span>
|
||||
<Icon name="library_books" size={18} className="text-primary" />
|
||||
<h3 className="text-sm font-semibold text-text-main">
|
||||
{tr("exampleTemplates", "Example Templates")}
|
||||
</h3>
|
||||
@@ -609,12 +591,13 @@ export default function RawJsonPanel({
|
||||
</div>
|
||||
<div className="grid grid-cols-2 sm:grid-cols-3 md:grid-cols-6 gap-2">
|
||||
{templates.map((template) => (
|
||||
<button
|
||||
<IconButton
|
||||
key={template.id}
|
||||
type="button"
|
||||
variant="ghost"
|
||||
onClick={() => loadTemplate(template)}
|
||||
aria-pressed={activeTemplate === template.id}
|
||||
className={`
|
||||
group flex flex-col items-center gap-1.5 p-3 rounded-lg border transition-all text-center
|
||||
group h-auto flex-col items-center gap-1.5 p-3 rounded-lg border transition-all text-center
|
||||
${
|
||||
activeTemplate === template.id
|
||||
? "border-primary bg-primary/5 text-primary"
|
||||
@@ -622,25 +605,22 @@ export default function RawJsonPanel({
|
||||
}
|
||||
`}
|
||||
>
|
||||
<span
|
||||
className={`material-symbols-outlined text-[22px] ${
|
||||
<Icon
|
||||
name={template.icon}
|
||||
size={22}
|
||||
className={`${
|
||||
activeTemplate === template.id
|
||||
? "text-primary"
|
||||
: "text-text-muted group-hover:text-primary"
|
||||
} transition-colors`}
|
||||
aria-hidden="true"
|
||||
>
|
||||
{template.icon}
|
||||
</span>
|
||||
/>
|
||||
<span className="text-xs font-medium leading-tight">{template.name}</span>
|
||||
</button>
|
||||
</IconButton>
|
||||
))}
|
||||
</div>
|
||||
{activeTemplate && (
|
||||
<div className="flex items-center gap-2 text-xs text-text-muted">
|
||||
<span className="material-symbols-outlined text-[14px]" aria-hidden="true">
|
||||
info
|
||||
</span>
|
||||
<Icon name="info" size={14} />
|
||||
{tr("templateLoadHint", "Template loaded for format: {format}").replace(
|
||||
"{format}",
|
||||
FORMAT_META[sourceFormat]?.label ?? sourceFormat
|
||||
|
||||
@@ -1,11 +1,24 @@
|
||||
"use client";
|
||||
|
||||
// Header toggle imports the Button module directly so tests can keep stubbing the barrel.
|
||||
import HeaderButton from "@/shared/components/Button";
|
||||
import Icon from "@/shared/components/Icon";
|
||||
|
||||
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
||||
import { useTranslations } from "next-intl";
|
||||
|
||||
import { Button, Card } from "@/shared/components";
|
||||
import { copyToClipboard } from "@/shared/utils/clipboard";
|
||||
import { cn } from "@/shared/utils/cn";
|
||||
import {
|
||||
Table,
|
||||
TableBody,
|
||||
TableCell,
|
||||
TableHead,
|
||||
TableHeader,
|
||||
TableRow,
|
||||
} from "@omniroute/ui-kit/table";
|
||||
import Textarea from "@/shared/components/Textarea";
|
||||
|
||||
// ─── Sample payloads ──────────────────────────────────────────────────────────
|
||||
|
||||
@@ -229,37 +242,31 @@ export default function StreamTransformerAccordion({
|
||||
|
||||
// ── Render ────────────────────────────────────────────────────────────────
|
||||
return (
|
||||
<div className="rounded-lg border border-black/5 dark:border-white/5 bg-surface">
|
||||
<div className="rounded-lg border border-border bg-surface">
|
||||
{/* ── Collapsible header — mirrors Collapsible.tsx visual style ──── */}
|
||||
<div
|
||||
className={cn(
|
||||
"flex items-center gap-3 p-4 hover:bg-black/[0.02] dark:hover:bg-white/[0.02] transition-colors",
|
||||
open && "border-b border-black/5 dark:border-white/5"
|
||||
"flex items-center gap-3 p-4 transition-colors hover:bg-bg-subtle",
|
||||
open && "border-b border-border"
|
||||
)}
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
<HeaderButton
|
||||
variant="ghost"
|
||||
onClick={handleToggle}
|
||||
aria-expanded={open}
|
||||
className="flex items-center gap-3 flex-1 min-w-0 text-left -m-1 p-1 rounded"
|
||||
className="-m-1 h-auto min-w-0 flex-1 justify-start gap-3 p-1 text-left"
|
||||
>
|
||||
<span
|
||||
className="material-symbols-outlined text-text-muted text-[20px] shrink-0"
|
||||
aria-hidden="true"
|
||||
>
|
||||
{open ? "expand_more" : "chevron_right"}
|
||||
</span>
|
||||
<span
|
||||
className="material-symbols-outlined text-text-muted text-[18px] shrink-0"
|
||||
aria-hidden="true"
|
||||
>
|
||||
swap_horiz
|
||||
</span>
|
||||
<Icon
|
||||
name={open ? "expand_more" : "chevron_right"}
|
||||
size={20}
|
||||
className="text-text-muted"
|
||||
/>
|
||||
<Icon name="swap_horiz" size={18} className="text-text-muted" />
|
||||
<div className="flex-1 min-w-0">
|
||||
<div className="text-sm font-medium text-text-main truncate">{title}</div>
|
||||
<div className="text-xs text-text-muted truncate">{subtitle}</div>
|
||||
</div>
|
||||
</button>
|
||||
</HeaderButton>
|
||||
</div>
|
||||
|
||||
{/* ── Content: lazy-render guard (D7) ────────────────────────────── */}
|
||||
@@ -268,12 +275,7 @@ export default function StreamTransformerAccordion({
|
||||
<div className="space-y-5 min-w-0">
|
||||
{/* Info banner */}
|
||||
<div className="flex items-start gap-3 px-4 py-3 rounded-lg bg-primary/5 border border-primary/10 text-sm text-text-muted">
|
||||
<span
|
||||
className="material-symbols-outlined text-primary text-[20px] mt-0.5 shrink-0"
|
||||
aria-hidden="true"
|
||||
>
|
||||
swap_horiz
|
||||
</span>
|
||||
<Icon name="swap_horiz" size={20} className="text-primary mt-0.5" />
|
||||
<div>
|
||||
<p className="font-medium text-text-main mb-0.5">
|
||||
{translateOrFallback("streamTransformerTitle", "Responses Stream Transformer")}
|
||||
@@ -326,7 +328,7 @@ export default function StreamTransformerAccordion({
|
||||
<div
|
||||
role="alert"
|
||||
data-testid="error-display"
|
||||
className="rounded-lg border border-red-500/30 bg-red-500/10 px-3 py-2 text-sm text-red-600 dark:text-red-400"
|
||||
className="rounded-lg border border-error/30 bg-error/10 px-3 py-2 text-sm text-error"
|
||||
>
|
||||
{error}
|
||||
</div>
|
||||
@@ -346,16 +348,14 @@ export default function StreamTransformerAccordion({
|
||||
onClick={() => handleCopy(rawSse, "input")}
|
||||
aria-label={translateOrFallback("copyInput", "Copy input")}
|
||||
>
|
||||
<span className="material-symbols-outlined text-[14px]" aria-hidden="true">
|
||||
{copiedField === "input" ? "check" : "content_copy"}
|
||||
</span>
|
||||
<Icon name={copiedField === "input" ? "check" : "content_copy"} size={14} />
|
||||
</Button>
|
||||
</div>
|
||||
<textarea
|
||||
<Textarea
|
||||
value={rawSse}
|
||||
onChange={(e) => setRawSse(e.target.value)}
|
||||
data-testid="raw-sse-input"
|
||||
className="min-h-[360px] w-full rounded-lg border border-border bg-bg-secondary px-3 py-3 text-xs font-mono text-text-main focus:outline-none focus:ring-1 focus:ring-primary/50"
|
||||
className="min-h-[360px] w-full font-mono text-xs"
|
||||
spellCheck={false}
|
||||
aria-label={translateOrFallback(
|
||||
"rawChatSseInput",
|
||||
@@ -380,14 +380,15 @@ export default function StreamTransformerAccordion({
|
||||
disabled={!transformedSse}
|
||||
aria-label={translateOrFallback("copyOutput", "Copy output")}
|
||||
>
|
||||
<span className="material-symbols-outlined text-[14px]" aria-hidden="true">
|
||||
{copiedField === "output" ? "check" : "content_copy"}
|
||||
</span>
|
||||
<Icon
|
||||
name={copiedField === "output" ? "check" : "content_copy"}
|
||||
size={14}
|
||||
/>
|
||||
</Button>
|
||||
</div>
|
||||
<pre
|
||||
data-testid="transformed-output"
|
||||
className="min-h-[360px] overflow-auto rounded-lg border border-border bg-bg-secondary px-3 py-3 text-xs font-mono whitespace-pre-wrap break-all"
|
||||
className="min-h-[360px] overflow-auto rounded-lg border border-border bg-bg-subtle px-3 py-3 text-xs font-mono whitespace-pre-wrap break-all"
|
||||
>
|
||||
{transformedSse || translateOrFallback("noResultsYet", "No results yet")}
|
||||
</pre>
|
||||
@@ -431,35 +432,31 @@ export default function StreamTransformerAccordion({
|
||||
)}
|
||||
</p>
|
||||
) : (
|
||||
<div className="overflow-x-auto">
|
||||
<table className="w-full text-sm">
|
||||
<thead>
|
||||
<tr className="text-left text-xs text-text-muted border-b border-border">
|
||||
<th className="pb-2 pr-4">#</th>
|
||||
<th className="pb-2 pr-4">
|
||||
{translateOrFallback("eventType", "Event type")}
|
||||
</th>
|
||||
<th className="pb-2">{translateOrFallback("eventPreview", "Preview")}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{transformedFrames.map((frame, index) => (
|
||||
<tr
|
||||
key={`${frame.event}_${index}`}
|
||||
className="border-b border-border/50 align-top"
|
||||
>
|
||||
<td className="py-2 pr-4 text-xs text-text-muted">{index + 1}</td>
|
||||
<td className="py-2 pr-4 font-mono text-xs text-primary">
|
||||
{frame.event}
|
||||
</td>
|
||||
<td className="py-2 text-xs text-text-muted break-all">
|
||||
{frame.preview}
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<Table
|
||||
scrollbarLabel={translateOrFallback("eventType", "Event type")}
|
||||
className="text-sm"
|
||||
>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead>#</TableHead>
|
||||
<TableHead>{translateOrFallback("eventType", "Event type")}</TableHead>
|
||||
<TableHead>{translateOrFallback("eventPreview", "Preview")}</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{transformedFrames.map((frame, index) => (
|
||||
<TableRow key={`${frame.event}_${index}`} className="align-top">
|
||||
<TableCell className="text-xs text-text-muted">{index + 1}</TableCell>
|
||||
<TableCell className="font-mono text-xs text-primary">
|
||||
{frame.event}
|
||||
</TableCell>
|
||||
<TableCell className="break-all text-xs text-text-muted">
|
||||
{frame.preview}
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
</TableBody>
|
||||
</Table>
|
||||
)}
|
||||
</div>
|
||||
</Card>
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
"use client";
|
||||
|
||||
import Icon from "@/shared/components/Icon";
|
||||
|
||||
import { useState, useEffect, useMemo } from "react";
|
||||
import { useTranslations } from "next-intl";
|
||||
import Collapsible from "@/shared/components/Collapsible";
|
||||
import { Card, Button, Select, Badge } from "@/shared/components";
|
||||
import Input from "@/shared/components/Input";
|
||||
import { getExampleTemplates, FORMAT_META, FORMAT_OPTIONS } from "../../exampleTemplates";
|
||||
import { useProviderOptions } from "../../hooks/useProviderOptions";
|
||||
import { useAvailableModels } from "../../hooks/useAvailableModels";
|
||||
@@ -216,9 +219,7 @@ function TestBenchContent() {
|
||||
<div className="space-y-5 min-w-0">
|
||||
{/* Info Banner */}
|
||||
<div className="flex items-start gap-3 px-4 py-3 rounded-lg bg-primary/5 border border-primary/10 text-sm text-text-muted">
|
||||
<span className="material-symbols-outlined text-primary text-[20px] mt-0.5 shrink-0">
|
||||
info
|
||||
</span>
|
||||
<Icon name="info" size={20} className="text-primary mt-0.5" />
|
||||
<div>
|
||||
<p className="font-medium text-text-main mb-0.5">{t("compatibilityTester")}</p>
|
||||
<p>{t("testBenchDescription")}</p>
|
||||
@@ -230,10 +231,8 @@ function TestBenchContent() {
|
||||
<div className="p-4 flex flex-col gap-4">
|
||||
<div className="flex flex-col sm:flex-row items-end gap-4 min-w-0">
|
||||
<div className="flex-1 w-full">
|
||||
<label className="block text-xs font-medium text-text-muted mb-1.5 uppercase tracking-wider">
|
||||
{t("source")}
|
||||
</label>
|
||||
<Select
|
||||
label={t("source")}
|
||||
value={sourceFormat}
|
||||
onChange={(e) => {
|
||||
setSourceFormat(e.target.value);
|
||||
@@ -243,15 +242,11 @@ function TestBenchContent() {
|
||||
/>
|
||||
</div>
|
||||
<div className="flex items-center justify-center px-2">
|
||||
<span className="material-symbols-outlined text-[22px] text-text-muted">
|
||||
arrow_forward
|
||||
</span>
|
||||
<Icon name="arrow_forward" size={22} className="text-text-muted" />
|
||||
</div>
|
||||
<div className="flex-1 w-full">
|
||||
<label className="block text-xs font-medium text-text-muted mb-1.5 uppercase tracking-wider">
|
||||
{t("targetProvider")}
|
||||
</label>
|
||||
<Select
|
||||
label={t("targetProvider")}
|
||||
value={provider}
|
||||
onChange={(e) => {
|
||||
setProvider(e.target.value);
|
||||
@@ -271,17 +266,14 @@ function TestBenchContent() {
|
||||
</Button>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-xs font-medium text-text-muted mb-1.5 uppercase tracking-wider">
|
||||
{t("model")}
|
||||
</label>
|
||||
<div className="relative">
|
||||
<input
|
||||
<Input
|
||||
type="text"
|
||||
label={t("model")}
|
||||
value={model}
|
||||
onChange={(e) => setModel(e.target.value)}
|
||||
list="testbench-acc-model-suggestions"
|
||||
placeholder={t("modelPlaceholder")}
|
||||
className="w-full bg-bg-subtle border border-border rounded-lg px-3 py-2 text-sm text-text-main placeholder:text-text-muted focus:outline-none focus:border-primary transition-colors"
|
||||
/>
|
||||
<datalist id="testbench-acc-model-suggestions">
|
||||
{availableModels.map((m) => (
|
||||
@@ -311,17 +303,17 @@ function TestBenchContent() {
|
||||
</div>
|
||||
<div className="flex items-center gap-3 text-xs text-text-muted">
|
||||
<span className="flex items-center gap-1">
|
||||
<span className="size-2 rounded-full bg-green-500" /> {passCount} {t("passed")}
|
||||
<span className="size-2 rounded-full bg-success" /> {passCount} {t("passed")}
|
||||
</span>
|
||||
<span className="flex items-center gap-1">
|
||||
<span className="size-2 rounded-full bg-red-500" /> {failCount} {t("failed")}
|
||||
<span className="size-2 rounded-full bg-error" /> {failCount} {t("failed")}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
{/* Progress bar */}
|
||||
<div className="w-full h-2 bg-bg-subtle rounded-full overflow-hidden">
|
||||
<div
|
||||
className="h-full bg-gradient-to-r from-green-500 to-emerald-400 rounded-full transition-all duration-500"
|
||||
className="h-full bg-gradient-to-r from-success to-success rounded-full transition-all duration-500"
|
||||
style={{ width: `${compatibility}%` }}
|
||||
/>
|
||||
</div>
|
||||
@@ -340,9 +332,9 @@ function TestBenchContent() {
|
||||
key={scenario.id}
|
||||
className={`transition-all ${
|
||||
result?.status === "pass"
|
||||
? "border-green-500/30"
|
||||
? "border-success/30"
|
||||
: result?.status === "error"
|
||||
? "border-red-500/30"
|
||||
? "border-error/30"
|
||||
: ""
|
||||
}`}
|
||||
>
|
||||
@@ -352,21 +344,24 @@ function TestBenchContent() {
|
||||
<div
|
||||
className={`flex items-center justify-center w-9 h-9 rounded-lg ${
|
||||
result?.status === "pass"
|
||||
? "bg-green-500/10 text-green-500"
|
||||
? "bg-success/10 text-success"
|
||||
: result?.status === "error"
|
||||
? "bg-red-500/10 text-red-500"
|
||||
? "bg-error/10 text-error"
|
||||
: "bg-bg-subtle text-text-muted"
|
||||
}`}
|
||||
>
|
||||
<span className="material-symbols-outlined text-[20px]">
|
||||
{isRunning
|
||||
? "progress_activity"
|
||||
: result?.status === "pass"
|
||||
? "check_circle"
|
||||
: result?.status === "error"
|
||||
? "error"
|
||||
: scenario.icon}
|
||||
</span>
|
||||
<Icon
|
||||
name={
|
||||
isRunning
|
||||
? "progress_activity"
|
||||
: result?.status === "pass"
|
||||
? "check_circle"
|
||||
: result?.status === "error"
|
||||
? "error"
|
||||
: scenario.icon
|
||||
}
|
||||
size={20}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<p className="text-sm font-medium text-text-main">
|
||||
@@ -385,8 +380,8 @@ function TestBenchContent() {
|
||||
<div
|
||||
className={`rounded-lg p-2 text-xs ${
|
||||
result.status === "pass"
|
||||
? "bg-green-500/5 text-green-600 dark:text-green-400"
|
||||
: "bg-red-500/5 text-red-600 dark:text-red-400"
|
||||
? "bg-success/5 text-success"
|
||||
: "bg-error/5 text-error"
|
||||
}`}
|
||||
>
|
||||
{result.status === "pass" ? (
|
||||
|
||||
@@ -1608,7 +1608,8 @@
|
||||
"mcpMetricCalls24h": "Calls (24h)",
|
||||
"mcpMetricSuccessRate": "Success rate",
|
||||
"mcpMetricAvgDuration": "Avg duration",
|
||||
"mcpMetricTopTool": "Top tool"
|
||||
"mcpMetricTopTool": "Top tool",
|
||||
"dismissError": "Dismiss error"
|
||||
},
|
||||
"themesPage": {
|
||||
"title": "Themes",
|
||||
@@ -9059,7 +9060,8 @@
|
||||
"tomlTestPassed": "Passed",
|
||||
"tomlTestFailed": "Failed",
|
||||
"tomlImportError": "Could not process the RTK TOML file.",
|
||||
"tomlFileReadError": "Could not read the selected TOML file."
|
||||
"tomlFileReadError": "Could not read the selected TOML file.",
|
||||
"viewMode": "View mode"
|
||||
},
|
||||
"compressionEngineConfig": {
|
||||
"loading": "Loading…",
|
||||
@@ -9281,7 +9283,8 @@
|
||||
"languagePacksList": "Language packs: {packs}",
|
||||
"dragToReorder": "Drag to reorder step",
|
||||
"engine": "Engine",
|
||||
"intensity": "Intensity"
|
||||
"intensity": "Intensity",
|
||||
"compressionOverride": "Compression override"
|
||||
},
|
||||
"compressionStudio": {
|
||||
"noRun": "No compression run available.",
|
||||
@@ -9341,7 +9344,8 @@
|
||||
"encoderWinner": "winner: {winner}",
|
||||
"encoder": "encoder",
|
||||
"bytes": "bytes",
|
||||
"tokensCl100k": "tokens (cl100k)"
|
||||
"tokensCl100k": "tokens (cl100k)",
|
||||
"studioViews": "Studio views"
|
||||
},
|
||||
"omniglyph": {
|
||||
"preview": "Preview",
|
||||
@@ -9547,7 +9551,9 @@
|
||||
"tooltipMinLength": "Messages shorter than this are not compressed. Lower = more compression.",
|
||||
"tooltipMinSavings": "Only compress if it saves at least this many tokens.",
|
||||
"ultraSettings": "Ultra Settings",
|
||||
"ultraSettingsDesc": "SLM-powered semantic compression"
|
||||
"ultraSettingsDesc": "SLM-powered semantic compression",
|
||||
"defaultLanguage": "Default language",
|
||||
"viewMode": "View mode"
|
||||
},
|
||||
"translator": {
|
||||
"title": "Translator",
|
||||
@@ -12096,8 +12102,18 @@
|
||||
"resilienceRotations": "{count} account rotations",
|
||||
"resilienceRetried": "Retried empty turn",
|
||||
"resilienceContinued": "Resumed mid-stream",
|
||||
"resilienceRecovered": "Recovered by a resilience action"
|
||||
}
|
||||
"resilienceRecovered": "Recovered by a resilience action",
|
||||
"conversationContext": "Conversation Context",
|
||||
"goToBottom": "Go to bottom",
|
||||
"liveRefreshOn": "Live refresh: on",
|
||||
"liveRefreshOff": "Live refresh: off",
|
||||
"liveRefresh": "Live refresh",
|
||||
"continuesFromParent": "continues from parent",
|
||||
"continuesFrom": "Continues from {id}",
|
||||
"viewConversation": "view conversation",
|
||||
"openConversation": "Open conversation {id}"
|
||||
},
|
||||
"tableLabel": "Request logs"
|
||||
},
|
||||
"proxyLogger": {
|
||||
"filterAll": "All",
|
||||
@@ -12142,7 +12158,9 @@
|
||||
"colServedBy": "Served by",
|
||||
"filterTraffic": "Traffic",
|
||||
"filterTests": "Tests",
|
||||
"filterSource": "Source"
|
||||
"filterSource": "Source",
|
||||
"tableLabel": "Proxy logs",
|
||||
"sortLogs": "Sort logs"
|
||||
},
|
||||
"endpointOptions": {
|
||||
"speech": "Speech",
|
||||
@@ -12395,7 +12413,10 @@
|
||||
"ungroupedTitle": "Ungrouped",
|
||||
"ungroupedHint": "These pools are not assigned to a known group. Edit a pool to move it into a real group.",
|
||||
"removeFailed": "Could not remove this pool.",
|
||||
"dismiss": "Dismiss"
|
||||
"dismiss": "Dismiss",
|
||||
"allocationsHeading": "Allocations",
|
||||
"wizardRemoveDimension": "Remove dimension",
|
||||
"wizardRemoveKey": "Remove key"
|
||||
},
|
||||
"plugins": {
|
||||
"title": "Plugins",
|
||||
@@ -12553,7 +12574,8 @@
|
||||
"settingsUpdateFailed": "Settings update failed",
|
||||
"serviceRevealApiKey": "{actor} revealed API key for {target}",
|
||||
"genericEvent": "{actor} {target}"
|
||||
}
|
||||
},
|
||||
"dismissError": "Dismiss error"
|
||||
},
|
||||
"agentBridge": {
|
||||
"title": "AgentBridge",
|
||||
@@ -14888,7 +14910,20 @@
|
||||
"mcp": "MCP",
|
||||
"mcpTool": "MCP tool",
|
||||
"scope": "Scope",
|
||||
"apiKey": "API key"
|
||||
"apiKey": "API key",
|
||||
"visibleCount": "{visible} visible / {total} total",
|
||||
"modeLabel": "View mode",
|
||||
"jumpToNow": "Jump to current time, NOW line resets to position {position}%",
|
||||
"laneReuse": "Lane reuse",
|
||||
"laneReuseLabel": "Lane reuse window (minutes)",
|
||||
"laneReuseHint": "Requests sharing a conversation id stay on the same timeline row as long as the gap between them is under this many minutes.",
|
||||
"laneReuseUnit": "min",
|
||||
"autoRefresh": "Auto-refresh",
|
||||
"autoRefreshLabel": "Auto-refresh interval (seconds)",
|
||||
"autoRefreshHint": "How often the timeline re-fetches the request list from the server.",
|
||||
"autoRefreshUnit": "s",
|
||||
"zoomOut": "Zoom out",
|
||||
"zoomIn": "Zoom in"
|
||||
},
|
||||
"metadata": {
|
||||
"compressionTitle": "Compression",
|
||||
|
||||
@@ -1608,7 +1608,8 @@
|
||||
"mcpMetricCalls24h": "Chamadas (24h)",
|
||||
"mcpMetricSuccessRate": "Taxa de sucesso",
|
||||
"mcpMetricAvgDuration": "Duração média",
|
||||
"mcpMetricTopTool": "Ferramenta principal"
|
||||
"mcpMetricTopTool": "Ferramenta principal",
|
||||
"dismissError": "Dispensar erro"
|
||||
},
|
||||
"themesPage": {
|
||||
"title": "Temas",
|
||||
@@ -9059,7 +9060,8 @@
|
||||
"tomlTestPassed": "Aprovado",
|
||||
"tomlTestFailed": "Reprovado",
|
||||
"tomlImportError": "Não foi possível processar o arquivo TOML do RTK.",
|
||||
"tomlFileReadError": "Não foi possível ler o arquivo TOML selecionado."
|
||||
"tomlFileReadError": "Não foi possível ler o arquivo TOML selecionado.",
|
||||
"viewMode": "Modo de visualização"
|
||||
},
|
||||
"compressionEngineConfig": {
|
||||
"loading": "Carregando…",
|
||||
@@ -9281,7 +9283,8 @@
|
||||
"languagePacksList": "Pacotes de idioma: {packs}",
|
||||
"dragToReorder": "Arraste para reordenar a etapa",
|
||||
"engine": "Mecanismo",
|
||||
"intensity": "Intensidade"
|
||||
"intensity": "Intensidade",
|
||||
"compressionOverride": "Substituição de compressão"
|
||||
},
|
||||
"compressionStudio": {
|
||||
"noRun": "Nenhuma execução de compressão disponível.",
|
||||
@@ -9341,7 +9344,8 @@
|
||||
"encoderWinner": "vencedor: {winner}",
|
||||
"encoder": "codificador",
|
||||
"bytes": "bytes",
|
||||
"tokensCl100k": "tokens (cl100k)"
|
||||
"tokensCl100k": "tokens (cl100k)",
|
||||
"studioViews": "Visões do estúdio"
|
||||
},
|
||||
"omniglyph": {
|
||||
"preview": "Visualização",
|
||||
@@ -9547,7 +9551,9 @@
|
||||
"tooltipMinLength": "Mensagens menores que isso não são compactadas. Menor = mais compressão.",
|
||||
"tooltipMinSavings": "Compacte apenas se salvar pelo menos esse número de tokens.",
|
||||
"ultraSettings": "Configurações Ultra",
|
||||
"ultraSettingsDesc": "Compressão semântica alimentada por SLM"
|
||||
"ultraSettingsDesc": "Compressão semântica alimentada por SLM",
|
||||
"defaultLanguage": "Idioma padrão",
|
||||
"viewMode": "Modo de visualização"
|
||||
},
|
||||
"translator": {
|
||||
"title": "Tradutor",
|
||||
@@ -12096,8 +12102,18 @@
|
||||
"resilienceRotations": "{count} rotações de conta",
|
||||
"resilienceRetried": "Turno vazio repetido",
|
||||
"resilienceContinued": "Retomado no meio do fluxo",
|
||||
"resilienceRecovered": "Recuperado por uma ação de resiliência"
|
||||
}
|
||||
"resilienceRecovered": "Recuperado por uma ação de resiliência",
|
||||
"conversationContext": "Contexto da conversa",
|
||||
"goToBottom": "Ir para o fim",
|
||||
"liveRefreshOn": "Atualização ao vivo: ligada",
|
||||
"liveRefreshOff": "Atualização ao vivo: desligada",
|
||||
"liveRefresh": "Atualização ao vivo",
|
||||
"continuesFromParent": "continua da requisição pai",
|
||||
"continuesFrom": "Continua de {id}",
|
||||
"viewConversation": "ver conversa",
|
||||
"openConversation": "Abrir conversa {id}"
|
||||
},
|
||||
"tableLabel": "Logs de requisições"
|
||||
},
|
||||
"proxyLogger": {
|
||||
"filterAll": "Todos",
|
||||
@@ -12142,7 +12158,9 @@
|
||||
"colServedBy": "Atendido por",
|
||||
"filterTraffic": "Tráfego",
|
||||
"filterTests": "Testes",
|
||||
"filterSource": "Fonte"
|
||||
"filterSource": "Fonte",
|
||||
"tableLabel": "Logs de proxy",
|
||||
"sortLogs": "Ordenar logs"
|
||||
},
|
||||
"endpointOptions": {
|
||||
"speech": "Fala",
|
||||
@@ -12395,7 +12413,10 @@
|
||||
"ungroupedTitle": "Sem grupo",
|
||||
"ungroupedHint": "Estes pools não estão atribuídos a um grupo conhecido. Edite um pool para movê-lo para um grupo real.",
|
||||
"removeFailed": "Não foi possível remover este pool.",
|
||||
"dismiss": "Dispensar"
|
||||
"dismiss": "Dispensar",
|
||||
"allocationsHeading": "Alocações",
|
||||
"wizardRemoveDimension": "Remover dimensão",
|
||||
"wizardRemoveKey": "Remover chave"
|
||||
},
|
||||
"plugins": {
|
||||
"title": "Plugins",
|
||||
@@ -12553,7 +12574,8 @@
|
||||
"settingsUpdateFailed": "Falha ao atualizar configurações",
|
||||
"serviceRevealApiKey": "{actor} visualizou API key de {target}",
|
||||
"genericEvent": "{actor} {target}"
|
||||
}
|
||||
},
|
||||
"dismissError": "Dispensar erro"
|
||||
},
|
||||
"agentBridge": {
|
||||
"title": "AgentBridge",
|
||||
@@ -14888,7 +14910,20 @@
|
||||
"mcp": "MCP",
|
||||
"mcpTool": "MCP tool",
|
||||
"scope": "Scope",
|
||||
"apiKey": "API key"
|
||||
"apiKey": "API key",
|
||||
"visibleCount": "{visible} visíveis / {total} no total",
|
||||
"modeLabel": "Modo de visualização",
|
||||
"jumpToNow": "Ir para o horário atual; a linha AGORA volta para a posição {position}%",
|
||||
"laneReuse": "Reúso de faixa",
|
||||
"laneReuseLabel": "Janela de reúso de faixa (minutos)",
|
||||
"laneReuseHint": "Requisições com o mesmo id de conversa ficam na mesma linha da timeline enquanto o intervalo entre elas for menor que estes minutos.",
|
||||
"laneReuseUnit": "min",
|
||||
"autoRefresh": "Atualização automática",
|
||||
"autoRefreshLabel": "Intervalo de atualização automática (segundos)",
|
||||
"autoRefreshHint": "Com que frequência a timeline busca de novo a lista de requisições no servidor.",
|
||||
"autoRefreshUnit": "s",
|
||||
"zoomOut": "Diminuir zoom",
|
||||
"zoomIn": "Aumentar zoom"
|
||||
},
|
||||
"metadata": {
|
||||
"compressionTitle": "Compressão",
|
||||
|
||||
@@ -1608,7 +1608,8 @@
|
||||
"mcpMetricCalls24h": "Lượt gọi (24 giờ)",
|
||||
"mcpMetricSuccessRate": "Tỷ lệ thành công",
|
||||
"mcpMetricAvgDuration": "Thời lượng trung bình",
|
||||
"mcpMetricTopTool": "tool hàng đầu"
|
||||
"mcpMetricTopTool": "tool hàng đầu",
|
||||
"dismissError": "Bỏ qua lỗi"
|
||||
},
|
||||
"themesPage": {
|
||||
"title": "Chủ đề",
|
||||
@@ -9059,7 +9060,8 @@
|
||||
"tomlTestPassed": "Đạt",
|
||||
"tomlTestFailed": "Không đạt",
|
||||
"tomlImportError": "Không thể xử lý tệp RTK TOML.",
|
||||
"tomlFileReadError": "Không thể đọc tệp TOML đã chọn."
|
||||
"tomlFileReadError": "Không thể đọc tệp TOML đã chọn.",
|
||||
"viewMode": "Chế độ xem"
|
||||
},
|
||||
"compressionEngineConfig": {
|
||||
"loading": "Đang tải…",
|
||||
@@ -9281,7 +9283,8 @@
|
||||
"languagePacksList": "Gói ngôn ngữ: {packs}",
|
||||
"dragToReorder": "Kéo để sắp xếp lại bước",
|
||||
"engine": "Bộ máy",
|
||||
"intensity": "Cường độ"
|
||||
"intensity": "Cường độ",
|
||||
"compressionOverride": "Ghi đè nén"
|
||||
},
|
||||
"compressionStudio": {
|
||||
"noRun": "Chưa có lượt nén nào.",
|
||||
@@ -9341,7 +9344,8 @@
|
||||
"encoderWinner": "tốt nhất: {winner}",
|
||||
"encoder": "bộ mã hóa",
|
||||
"bytes": "byte",
|
||||
"tokensCl100k": "token (cl100k)"
|
||||
"tokensCl100k": "token (cl100k)",
|
||||
"studioViews": "Các chế độ xem của studio"
|
||||
},
|
||||
"omniglyph": {
|
||||
"preview": "Xem trước",
|
||||
@@ -9547,7 +9551,9 @@
|
||||
"tooltipMinLength": "Tin nhắn ngắn hơn mức này sẽ không được nén. Thấp hơn = nén nhiều hơn.",
|
||||
"tooltipMinSavings": "Chỉ nén nếu tiết kiệm được ít nhất ngần này token.",
|
||||
"ultraSettings": "Cài đặt tối đa",
|
||||
"ultraSettingsDesc": "Nén ngữ nghĩa sử dụng SLM"
|
||||
"ultraSettingsDesc": "Nén ngữ nghĩa sử dụng SLM",
|
||||
"defaultLanguage": "Ngôn ngữ mặc định",
|
||||
"viewMode": "Chế độ xem"
|
||||
},
|
||||
"translator": {
|
||||
"title": "Trình dịch",
|
||||
@@ -12096,8 +12102,18 @@
|
||||
"resilienceRotations": "{count} lần chuyển tài khoản",
|
||||
"resilienceRetried": "Đã thử lại lượt trống",
|
||||
"resilienceContinued": "Đã tiếp tục giữa luồng",
|
||||
"resilienceRecovered": "Đã khôi phục bằng hành động phục hồi"
|
||||
}
|
||||
"resilienceRecovered": "Đã khôi phục bằng hành động phục hồi",
|
||||
"conversationContext": "Ngữ cảnh hội thoại",
|
||||
"goToBottom": "Xuống cuối",
|
||||
"liveRefreshOn": "Làm mới trực tiếp: bật",
|
||||
"liveRefreshOff": "Làm mới trực tiếp: tắt",
|
||||
"liveRefresh": "Làm mới trực tiếp",
|
||||
"continuesFromParent": "tiếp nối từ yêu cầu cha",
|
||||
"continuesFrom": "Tiếp nối từ {id}",
|
||||
"viewConversation": "xem hội thoại",
|
||||
"openConversation": "Mở hội thoại {id}"
|
||||
},
|
||||
"tableLabel": "Nhật ký yêu cầu"
|
||||
},
|
||||
"proxyLogger": {
|
||||
"filterAll": "Tất cả",
|
||||
@@ -12142,7 +12158,9 @@
|
||||
"colServedBy": "Được phục vụ bởi",
|
||||
"filterTraffic": "Lưu lượng",
|
||||
"filterTests": "Bài kiểm tra",
|
||||
"filterSource": "Nguồn"
|
||||
"filterSource": "Nguồn",
|
||||
"tableLabel": "Nhật ký proxy",
|
||||
"sortLogs": "Sắp xếp nhật ký"
|
||||
},
|
||||
"endpointOptions": {
|
||||
"speech": "Giọng nói",
|
||||
@@ -12395,7 +12413,10 @@
|
||||
"ungroupedTitle": "Chưa phân nhóm",
|
||||
"ungroupedHint": "Các pool này chưa được gán cho một nhóm mà hệ thống nhận diện. Hãy chỉnh sửa một pool để chuyển pool đó vào một nhóm hợp lệ.",
|
||||
"removeFailed": "Không thể xóa nhóm này.",
|
||||
"dismiss": "Đóng"
|
||||
"dismiss": "Đóng",
|
||||
"allocationsHeading": "Phân bổ",
|
||||
"wizardRemoveDimension": "Xóa chiều hạn mức",
|
||||
"wizardRemoveKey": "Xóa khóa"
|
||||
},
|
||||
"plugins": {
|
||||
"title": "Plugin",
|
||||
@@ -12553,7 +12574,8 @@
|
||||
"settingsUpdateFailed": "Cập nhật cài đặt thất bại",
|
||||
"serviceRevealApiKey": "{actor} đã hiển thị khóa API của {target}",
|
||||
"genericEvent": "{actor} {target}"
|
||||
}
|
||||
},
|
||||
"dismissError": "Bỏ qua lỗi"
|
||||
},
|
||||
"agentBridge": {
|
||||
"title": "AgentBridge",
|
||||
@@ -14888,7 +14910,20 @@
|
||||
"mcp": "MCP",
|
||||
"mcpTool": "Công cụ MCP",
|
||||
"scope": "Phạm vi",
|
||||
"apiKey": "Khóa API"
|
||||
"apiKey": "Khóa API",
|
||||
"visibleCount": "{visible} hiển thị / {total} tổng",
|
||||
"modeLabel": "Chế độ xem",
|
||||
"jumpToNow": "Về thời điểm hiện tại, vạch HIỆN TẠI trở về vị trí {position}%",
|
||||
"laneReuse": "Tái dùng làn",
|
||||
"laneReuseLabel": "Khoảng tái dùng làn (phút)",
|
||||
"laneReuseHint": "Các yêu cầu cùng mã hội thoại ở lại cùng một hàng trên dòng thời gian khi khoảng cách giữa chúng nhỏ hơn số phút này.",
|
||||
"laneReuseUnit": "phút",
|
||||
"autoRefresh": "Tự động làm mới",
|
||||
"autoRefreshLabel": "Chu kỳ tự động làm mới (giây)",
|
||||
"autoRefreshHint": "Tần suất dòng thời gian tải lại danh sách yêu cầu từ máy chủ.",
|
||||
"autoRefreshUnit": "giây",
|
||||
"zoomOut": "Thu nhỏ",
|
||||
"zoomIn": "Phóng to"
|
||||
},
|
||||
"metadata": {
|
||||
"compressionTitle": "Nén",
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
"use client";
|
||||
|
||||
import { useTranslations } from "next-intl";
|
||||
import Badge from "./Badge";
|
||||
|
||||
type UsageProvenance = "reported" | "estimated" | "absent" | null | undefined;
|
||||
|
||||
@@ -38,13 +39,15 @@ export function CallContentProvenanceBadges({
|
||||
</div>
|
||||
<div className="flex flex-wrap gap-1">
|
||||
{keys.map((key) => (
|
||||
<span
|
||||
<Badge
|
||||
key={key}
|
||||
data-testid={`content-provenance-${key}`}
|
||||
className="inline-block px-2.5 py-1 rounded text-[10px] font-bold border bg-amber-500/15 text-amber-700 dark:text-amber-300 border-amber-500/30"
|
||||
variant="warning"
|
||||
size="sm"
|
||||
className="font-bold"
|
||||
>
|
||||
{t(key)}
|
||||
</span>
|
||||
</Badge>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
"use client";
|
||||
|
||||
import { useLocale, useTranslations } from "next-intl";
|
||||
import { Alert } from "@omniroute/ui-kit/alert";
|
||||
import { cn } from "@/shared/utils/cn";
|
||||
import Button from "./Button";
|
||||
import Icon from "./Icon";
|
||||
import Input from "./Input";
|
||||
import Select from "./Select";
|
||||
|
||||
/**
|
||||
* Console Log Viewer — Real-time application log viewer.
|
||||
@@ -25,22 +31,24 @@ interface LogEntry {
|
||||
[key: string]: unknown;
|
||||
}
|
||||
|
||||
// The terminal pane stays dark in both themes (DESIGN_SYSTEM: intentional terminal hex), so the
|
||||
// level colours are the GitHub-dark terminal palette, not theme tokens.
|
||||
const LEVEL_COLORS: Record<string, string> = {
|
||||
debug: "text-gray-400",
|
||||
trace: "text-gray-500",
|
||||
info: "text-cyan-400",
|
||||
warn: "text-yellow-400",
|
||||
error: "text-red-400",
|
||||
fatal: "text-fuchsia-400",
|
||||
debug: "text-[#8b949e]",
|
||||
trace: "text-[#6e7681]",
|
||||
info: "text-[#39c5cf]",
|
||||
warn: "text-[#e3b341]",
|
||||
error: "text-[#ff7b72]",
|
||||
fatal: "text-[#f778ba]",
|
||||
};
|
||||
|
||||
const LEVEL_BG: Record<string, string> = {
|
||||
debug: "bg-gray-500/10 border-gray-500/20",
|
||||
trace: "bg-gray-500/10 border-gray-500/20",
|
||||
info: "bg-cyan-500/10 border-cyan-500/20",
|
||||
warn: "bg-yellow-500/10 border-yellow-500/20",
|
||||
error: "bg-red-500/10 border-red-500/20",
|
||||
fatal: "bg-fuchsia-500/10 border-fuchsia-500/20",
|
||||
debug: "bg-[#8b949e]/10 border-[#8b949e]/20",
|
||||
trace: "bg-[#8b949e]/10 border-[#8b949e]/20",
|
||||
info: "bg-[#39c5cf]/10 border-[#39c5cf]/20",
|
||||
warn: "bg-[#e3b341]/10 border-[#e3b341]/20",
|
||||
error: "bg-[#ff7b72]/10 border-[#ff7b72]/20",
|
||||
fatal: "bg-[#f778ba]/10 border-[#f778ba]/20",
|
||||
};
|
||||
|
||||
const POLL_INTERVAL = 5000; // 5 seconds
|
||||
@@ -170,72 +178,71 @@ export default function ConsoleLogViewer() {
|
||||
return (
|
||||
<div className="flex flex-col gap-4">
|
||||
{/* Toolbar */}
|
||||
<div className="flex flex-wrap items-center gap-3 p-4 rounded-xl bg-[var(--color-surface)] border border-[var(--color-border)]">
|
||||
<div className="flex flex-wrap items-end gap-3 rounded-xl border border-border bg-surface p-4">
|
||||
{/* Level filter */}
|
||||
<select
|
||||
<Select
|
||||
value={levelFilter}
|
||||
onChange={(e) => setLevelFilter(e.target.value)}
|
||||
aria-label={tv("filterByLevel")}
|
||||
className="px-3 py-2 rounded-lg text-sm bg-[var(--color-bg)] border border-[var(--color-border)] text-[var(--color-text-main)] focus:outline-2 focus:outline-[var(--color-accent)]"
|
||||
>
|
||||
<option value="all">{t("allLevels")}</option>
|
||||
<option value="debug">Debug+</option>
|
||||
<option value="info">Info+</option>
|
||||
<option value="warn">Warn+</option>
|
||||
<option value="error">Error+</option>
|
||||
</select>
|
||||
</Select>
|
||||
|
||||
{/* Search */}
|
||||
<input
|
||||
<Input
|
||||
type="text"
|
||||
icon="search"
|
||||
placeholder={tv("searchPlaceholder")}
|
||||
value={searchText}
|
||||
onChange={(e) => setSearchText(e.target.value)}
|
||||
aria-label={tv("searchAria")}
|
||||
className="flex-1 min-w-[200px] px-3 py-2 rounded-lg text-sm bg-[var(--color-bg)] border border-[var(--color-border)] text-[var(--color-text-main)] placeholder:text-[var(--color-text-muted)] focus:outline-2 focus:outline-[var(--color-accent)]"
|
||||
className="min-w-[200px] flex-1"
|
||||
/>
|
||||
|
||||
{/* Auto-scroll toggle */}
|
||||
<button
|
||||
<Button
|
||||
variant="outline"
|
||||
aria-pressed={autoScroll}
|
||||
onClick={() => {
|
||||
// Switching auto-scroll back on is an explicit "take me to the newest line".
|
||||
if (!autoScroll) followTailRef.current = true;
|
||||
setAutoScroll(!autoScroll);
|
||||
}}
|
||||
title={autoScroll ? tv("disableAutoScroll") : tv("enableAutoScroll")}
|
||||
className={`px-3 py-2 rounded-lg text-sm font-medium border transition-colors ${
|
||||
autoScroll
|
||||
? "bg-cyan-500/15 text-cyan-400 border-cyan-500/30"
|
||||
: "bg-[var(--color-bg)] text-[var(--color-text-muted)] border-[var(--color-border)]"
|
||||
}`}
|
||||
className={cn(autoScroll && "border-info/30 bg-info/15 text-info")}
|
||||
>
|
||||
<span className="material-symbols-outlined text-[16px] align-middle mr-1">
|
||||
{autoScroll ? "vertical_align_bottom" : "lock"}
|
||||
</span>
|
||||
<Icon name={autoScroll ? "vertical_align_bottom" : "lock"} size={16} />
|
||||
{tv("autoScroll")}
|
||||
</button>
|
||||
</Button>
|
||||
|
||||
{/* Refresh */}
|
||||
<button
|
||||
<Button
|
||||
variant="outline"
|
||||
size="icon"
|
||||
onClick={fetchLogs}
|
||||
disabled={loading}
|
||||
aria-label={tc("refresh")}
|
||||
className="px-3 py-2 rounded-lg text-sm font-medium bg-[var(--color-bg)] border border-[var(--color-border)] text-[var(--color-text-main)] hover:bg-[var(--color-bg-alt)] disabled:opacity-50 transition-colors"
|
||||
title={tc("refresh")}
|
||||
>
|
||||
<span className="material-symbols-outlined text-[16px] align-middle" aria-hidden="true">
|
||||
refresh
|
||||
</span>
|
||||
</button>
|
||||
<Icon name="refresh" size={16} />
|
||||
</Button>
|
||||
|
||||
{/* Status */}
|
||||
<div className="flex items-center gap-2 ml-auto text-xs text-[var(--color-text-muted)]">
|
||||
<span className="inline-block w-2 h-2 rounded-full bg-green-500 animate-pulse" />
|
||||
<div className="ml-auto flex items-center gap-2 self-center text-xs text-text-muted">
|
||||
<span
|
||||
aria-hidden="true"
|
||||
className="inline-block size-2 animate-pulse rounded-full bg-success"
|
||||
/>
|
||||
<span>{tv("entryCount", { count: filteredLogs.length })}</span>
|
||||
<span className="text-[var(--color-text-muted)]/50">•</span>
|
||||
<span className="text-text-muted/50">•</span>
|
||||
<span>{tv("lastHour")}</span>
|
||||
{lastUpdated && (
|
||||
<>
|
||||
<span className="text-[var(--color-text-muted)]/50">•</span>
|
||||
<span className="text-text-muted/50">•</span>
|
||||
<span>{tv("updatedAt", { time: lastUpdated.toLocaleTimeString(locale) })}</span>
|
||||
</>
|
||||
)}
|
||||
@@ -244,14 +251,18 @@ export default function ConsoleLogViewer() {
|
||||
|
||||
{/* Error */}
|
||||
{error && (
|
||||
<div
|
||||
className="p-4 rounded-lg bg-red-500/10 border border-red-500/30 text-red-400 text-sm"
|
||||
role="alert"
|
||||
>
|
||||
<span className="material-symbols-outlined text-[16px] align-middle mr-2">error</span>
|
||||
{error}
|
||||
<span className="text-xs ml-2 opacity-70">— {tv("fileLoggingRequired")}</span>
|
||||
</div>
|
||||
<Alert
|
||||
variant="critical"
|
||||
icon={<Icon name="error" size={16} />}
|
||||
dismissLabel={tc("dismissNotification")}
|
||||
onDismiss={() => setError(null)}
|
||||
description={
|
||||
<>
|
||||
{error}
|
||||
<span className="ml-2 text-xs opacity-70">— {tv("fileLoggingRequired")}</span>
|
||||
</>
|
||||
}
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* Console output */}
|
||||
@@ -260,7 +271,7 @@ export default function ConsoleLogViewer() {
|
||||
onScroll={() => {
|
||||
followTailRef.current = isPinnedToBottom(scrollRef.current);
|
||||
}}
|
||||
className="rounded-xl border border-[var(--color-border)] bg-[#0d1117] overflow-auto font-mono text-xs leading-relaxed"
|
||||
className="rounded-xl border border-border bg-[#0d1117] overflow-auto font-mono text-xs leading-relaxed"
|
||||
style={{ maxHeight: "calc(100vh - 340px)", minHeight: "400px" }}
|
||||
role="log"
|
||||
aria-label={tv("consoleAria")}
|
||||
@@ -280,9 +291,7 @@ export default function ConsoleLogViewer() {
|
||||
<div className="p-3 space-y-px">
|
||||
{filteredLogs.length === 0 && !loading ? (
|
||||
<div className="text-[#8b949e] text-center py-12">
|
||||
<span className="material-symbols-outlined text-[40px] block mb-2 opacity-30">
|
||||
terminal
|
||||
</span>
|
||||
<Icon name="terminal" size={40} className="block mb-2 opacity-30" />
|
||||
<p>{t("noLogEntries")}</p>
|
||||
<p className="text-[10px] mt-1 opacity-60">{tv("emptyFileLoggingHint")}</p>
|
||||
</div>
|
||||
@@ -299,7 +308,7 @@ export default function ConsoleLogViewer() {
|
||||
<div
|
||||
key={idx}
|
||||
className={`group flex items-start gap-2 px-2 py-1 rounded hover:bg-white/5 transition-colors ${
|
||||
level === "error" || level === "fatal" ? "bg-red-500/5" : ""
|
||||
level === "error" || level === "fatal" ? "bg-[#ff7b72]/5" : ""
|
||||
}`}
|
||||
>
|
||||
{/* Timestamp */}
|
||||
@@ -315,7 +324,7 @@ export default function ConsoleLogViewer() {
|
||||
</span>
|
||||
|
||||
{/* Component */}
|
||||
{comp && <span className="text-purple-400/80 shrink-0">[{comp}]</span>}
|
||||
{comp && <span className="text-[#d2a8ff]/80 shrink-0">[{comp}]</span>}
|
||||
|
||||
{/* Message */}
|
||||
<span className="text-[#c9d1d9] flex-1 break-all">
|
||||
@@ -327,16 +336,16 @@ export default function ConsoleLogViewer() {
|
||||
</span>
|
||||
|
||||
{/* Copy button */}
|
||||
<button
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon-sm"
|
||||
onClick={() => handleCopy(entry, idx)}
|
||||
title={tv("copyLogEntry")}
|
||||
aria-label={tv("copyLogEntry")}
|
||||
className="opacity-0 group-hover:opacity-100 focus-visible:opacity-100 transition-opacity shrink-0 text-[#8b949e] hover:text-white"
|
||||
className="size-6 min-h-6 shrink-0 text-[#8b949e] opacity-0 transition-opacity hover:bg-white/10 hover:text-white group-hover:opacity-100 focus-visible:opacity-100"
|
||||
>
|
||||
<span className="material-symbols-outlined text-[14px]" aria-hidden="true">
|
||||
{copiedIdx === idx ? "check" : "content_copy"}
|
||||
</span>
|
||||
</button>
|
||||
<Icon name={copiedIdx === idx ? "check" : "content_copy"} size={14} />
|
||||
</Button>
|
||||
{copiedIdx === idx && (
|
||||
<span className="sr-only" role="status" aria-live="polite">
|
||||
{tc("copied")}
|
||||
@@ -349,9 +358,7 @@ export default function ConsoleLogViewer() {
|
||||
|
||||
{loading && filteredLogs.length === 0 && (
|
||||
<div className="text-[#8b949e] text-center py-12">
|
||||
<span className="material-symbols-outlined text-[24px] animate-spin block mb-2">
|
||||
progress_activity
|
||||
</span>
|
||||
<Icon name="progress_activity" size={24} className="animate-spin block mb-2" />
|
||||
{t("loadingLogs")}
|
||||
</div>
|
||||
)}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
"use client";
|
||||
|
||||
import { useTranslations } from "next-intl";
|
||||
import Button from "./Button";
|
||||
import Icon from "./Icon";
|
||||
import useJsonTreeExpandStore, { useJsonTreeExpandLevel } from "@/store/jsonTreeExpandStore";
|
||||
|
||||
interface JsonTreeExpandControlsProps {
|
||||
@@ -17,53 +19,54 @@ export function JsonTreeExpandControls({ sectionId }: JsonTreeExpandControlsProp
|
||||
const level = useJsonTreeExpandLevel(sectionId);
|
||||
const { collapseAll, collapseOneLevel, expandOneLevel, expandAll } = useJsonTreeExpandStore();
|
||||
|
||||
const buttonClass =
|
||||
"p-1 rounded hover:bg-bg-subtle text-text-muted hover:text-text-primary transition-colors";
|
||||
|
||||
return (
|
||||
<div className="flex items-center gap-0.5">
|
||||
<button
|
||||
type="button"
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon-sm"
|
||||
onClick={() => collapseAll(sectionId)}
|
||||
title={t("collapseAllLevels")}
|
||||
aria-label={t("collapseAllLevels")}
|
||||
className={buttonClass}
|
||||
className="size-6 min-h-6 text-text-muted"
|
||||
>
|
||||
<span className="material-symbols-outlined text-[16px]">collapse_all</span>
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
<Icon name="collapse_all" size={16} />
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon-sm"
|
||||
onClick={() => collapseOneLevel(sectionId)}
|
||||
title={t("collapseOneLevel")}
|
||||
aria-label={t("collapseOneLevel")}
|
||||
className={buttonClass}
|
||||
className="size-6 min-h-6 text-text-muted"
|
||||
>
|
||||
<span className="material-symbols-outlined text-[16px]">remove</span>
|
||||
</button>
|
||||
<Icon name="remove" size={16} />
|
||||
</Button>
|
||||
<span
|
||||
className="min-w-[1.5em] text-center text-[11px] font-mono text-text-muted tabular-nums"
|
||||
title={t("currentExpandLevel")}
|
||||
>
|
||||
{level}
|
||||
</span>
|
||||
<button
|
||||
type="button"
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon-sm"
|
||||
onClick={() => expandOneLevel(sectionId)}
|
||||
title={t("expandOneLevel")}
|
||||
aria-label={t("expandOneLevel")}
|
||||
className={buttonClass}
|
||||
className="size-6 min-h-6 text-text-muted"
|
||||
>
|
||||
<span className="material-symbols-outlined text-[16px]">add</span>
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
<Icon name="add" size={16} />
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon-sm"
|
||||
onClick={() => expandAll(sectionId)}
|
||||
title={t("expandAllLevels")}
|
||||
aria-label={t("expandAllLevels")}
|
||||
className={buttonClass}
|
||||
className="size-6 min-h-6 text-text-muted"
|
||||
>
|
||||
<span className="material-symbols-outlined text-[16px]">expand_all</span>
|
||||
</button>
|
||||
<Icon name="expand_all" size={16} />
|
||||
</Button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,16 @@
|
||||
|
||||
import { useState, useEffect } from "react";
|
||||
import { useTranslations } from "next-intl";
|
||||
import { cn } from "@/shared/utils/cn";
|
||||
import Badge from "./Badge";
|
||||
import Button from "./Button";
|
||||
import Card from "./Card";
|
||||
import EmptyState from "./EmptyState";
|
||||
import Icon from "./Icon";
|
||||
import Input from "./Input";
|
||||
import { Skeleton } from "./Loading";
|
||||
import Select from "./Select";
|
||||
import Toggle from "./Toggle";
|
||||
import { matchesOnlyPaidModels } from "@/shared/utils/freeModels";
|
||||
|
||||
export interface ModelMapping {
|
||||
@@ -165,183 +174,152 @@ export default function ModelRoutingSection({ combos: externalCombos }: { combos
|
||||
const patternIsPaidOnly = hidePaidModels && matchesOnlyPaidModels(pattern);
|
||||
|
||||
return (
|
||||
<Card>
|
||||
<div className="flex items-center justify-between gap-4">
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="p-2 rounded-lg bg-primary/10 text-primary">
|
||||
<span className="material-symbols-outlined text-[20px]" aria-hidden="true">
|
||||
route
|
||||
</span>
|
||||
</div>
|
||||
<div>
|
||||
<h3 className="text-lg font-semibold">{t("modelRoutingTitle")}</h3>
|
||||
<p className="text-sm text-text-muted">{t("modelRoutingDesc")}</p>
|
||||
</div>
|
||||
</div>
|
||||
{!adding && (
|
||||
<button
|
||||
onClick={() => setAdding(true)}
|
||||
className="flex items-center gap-1 px-2.5 py-1 text-xs font-medium rounded-lg
|
||||
bg-primary/10 text-primary hover:bg-primary/20 transition-colors"
|
||||
>
|
||||
<span className="material-symbols-outlined text-[14px]">add</span>
|
||||
<Card
|
||||
title={t("modelRoutingTitle")}
|
||||
subtitle={t("modelRoutingDesc")}
|
||||
icon="route"
|
||||
action={
|
||||
!adding && (
|
||||
<Button variant="secondary" size="sm" icon="add" onClick={() => setAdding(true)}>
|
||||
{t("addRule")}
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
|
||||
</Button>
|
||||
)
|
||||
}
|
||||
>
|
||||
{/* Inline form */}
|
||||
{adding && (
|
||||
<div className="mt-3 p-3 rounded-lg border border-primary/20 bg-primary/[0.03] dark:bg-primary/[0.06]">
|
||||
<div className="grid grid-cols-1 sm:grid-cols-2 gap-2">
|
||||
<div className="mt-3 rounded-lg border border-primary/20 bg-primary/[0.04] p-3">
|
||||
<div className="grid grid-cols-1 gap-3 sm:grid-cols-2">
|
||||
<div>
|
||||
<label className="text-[10px] font-medium text-text-muted uppercase tracking-wider">
|
||||
{t("pattern")}
|
||||
</label>
|
||||
<input
|
||||
<Input
|
||||
label={t("pattern")}
|
||||
value={pattern}
|
||||
onChange={(e) => setPattern(e.target.value)}
|
||||
placeholder="claude-sonnet*"
|
||||
className="w-full mt-0.5 px-2.5 py-1.5 text-xs rounded-lg border border-black/10 dark:border-white/10
|
||||
bg-white dark:bg-black/20 focus:outline-none focus:ring-1 focus:ring-primary"
|
||||
hint={t("patternHint")}
|
||||
/>
|
||||
<p className="text-[9px] text-text-muted mt-0.5">{t("patternHint")}</p>
|
||||
{patternIsPaidOnly && (
|
||||
<p className="text-[9px] text-amber-500 mt-0.5">
|
||||
<p className="mt-1 text-xs text-warning" role="status">
|
||||
{t("paidModelPatternWarning") ||
|
||||
"This pattern only matches paid models — enable paid models or adjust the pattern."}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
<div>
|
||||
<label className="text-[10px] font-medium text-text-muted uppercase tracking-wider">
|
||||
{t("routeToCombo")}
|
||||
</label>
|
||||
<select
|
||||
value={comboId}
|
||||
onChange={(e) => setComboId(e.target.value)}
|
||||
className="w-full mt-0.5 px-2.5 py-1.5 text-xs rounded-lg border border-black/10 dark:border-white/10
|
||||
bg-white dark:bg-black/20 focus:outline-none focus:ring-1 focus:ring-primary"
|
||||
>
|
||||
<option value="">{t("selectCombo")}</option>
|
||||
{combos.map((c) => (
|
||||
<option key={c.id} value={c.id}>
|
||||
{c.name}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
<label className="text-[10px] font-medium text-text-muted uppercase tracking-wider">
|
||||
{t("priority")}
|
||||
</label>
|
||||
<input
|
||||
type="number"
|
||||
value={priority}
|
||||
onChange={(e) => setPriority(Number(e.target.value))}
|
||||
className="w-full mt-0.5 px-2.5 py-1.5 text-xs rounded-lg border border-black/10 dark:border-white/10
|
||||
bg-white dark:bg-black/20 focus:outline-none focus:ring-1 focus:ring-primary"
|
||||
/>
|
||||
<p className="text-[9px] text-text-muted mt-0.5">{t("priorityHint")}</p>
|
||||
</div>
|
||||
<div>
|
||||
<label className="text-[10px] font-medium text-text-muted uppercase tracking-wider">
|
||||
{t("description")}
|
||||
</label>
|
||||
<input
|
||||
value={description}
|
||||
onChange={(e) => setDescription(e.target.value)}
|
||||
placeholder={t("modelRoutingDescriptionPlaceholder")}
|
||||
className="w-full mt-0.5 px-2.5 py-1.5 text-xs rounded-lg border border-black/10 dark:border-white/10
|
||||
bg-white dark:bg-black/20 focus:outline-none focus:ring-1 focus:ring-primary"
|
||||
/>
|
||||
</div>
|
||||
<Select
|
||||
label={t("routeToCombo")}
|
||||
value={comboId}
|
||||
onChange={(e) => setComboId(e.target.value)}
|
||||
>
|
||||
<option value="">{t("selectCombo")}</option>
|
||||
{combos.map((c) => (
|
||||
<option key={c.id} value={c.id}>
|
||||
{c.name}
|
||||
</option>
|
||||
))}
|
||||
</Select>
|
||||
<Input
|
||||
type="number"
|
||||
label={t("priority")}
|
||||
value={priority}
|
||||
onChange={(e) => setPriority(Number(e.target.value))}
|
||||
hint={t("priorityHint")}
|
||||
/>
|
||||
<Input
|
||||
label={t("description")}
|
||||
value={description}
|
||||
onChange={(e) => setDescription(e.target.value)}
|
||||
placeholder={t("modelRoutingDescriptionPlaceholder")}
|
||||
/>
|
||||
</div>
|
||||
<div className="flex items-center gap-2 mt-2.5">
|
||||
<button
|
||||
<div className="mt-3 flex items-center gap-2">
|
||||
<Button
|
||||
size="sm"
|
||||
onClick={handleSave}
|
||||
disabled={!pattern.trim() || !comboId || patternIsPaidOnly}
|
||||
className="px-3 py-1 text-xs font-medium rounded-lg bg-primary text-accent-foreground
|
||||
hover:bg-primary/90 disabled:opacity-40 transition-colors"
|
||||
>
|
||||
{editingId ? t("update") : t("save")}
|
||||
</button>
|
||||
<button
|
||||
onClick={resetForm}
|
||||
className="px-3 py-1 text-xs font-medium rounded-lg
|
||||
bg-black/5 dark:bg-white/5 hover:bg-black/10 dark:hover:bg-white/10 transition-colors"
|
||||
>
|
||||
</Button>
|
||||
<Button variant="ghost" size="sm" onClick={resetForm}>
|
||||
{t("cancel")}
|
||||
</button>
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Mappings list */}
|
||||
{loading ? (
|
||||
<div className="mt-3 text-xs text-text-muted">{t("loading")}</div>
|
||||
) : mappings.length === 0 ? (
|
||||
<div className="mt-3 text-center py-4">
|
||||
<p className="text-xs text-text-muted">{t("noRoutingRules")}</p>
|
||||
<p className="text-[10px] text-text-muted mt-1">{t("routingRuleHint")}</p>
|
||||
<div className="mt-3 flex flex-col gap-1.5" aria-busy="true">
|
||||
<span className="ci-sr-only">{t("loading")}</span>
|
||||
<Skeleton className="h-10 w-full" />
|
||||
<Skeleton className="h-10 w-full" />
|
||||
</div>
|
||||
) : mappings.length === 0 ? (
|
||||
<EmptyState
|
||||
className="mt-3"
|
||||
icon="route"
|
||||
title={t("noRoutingRules")}
|
||||
description={t("routingRuleHint")}
|
||||
/>
|
||||
) : (
|
||||
<div className="mt-3 flex flex-col gap-1.5">
|
||||
{mappings.map((m) => (
|
||||
<div
|
||||
key={m.id}
|
||||
className={`flex items-center justify-between px-3 py-2 rounded-lg border transition-colors
|
||||
${
|
||||
m.enabled
|
||||
? "border-black/10 dark:border-white/10 bg-white/70 dark:bg-white/[0.02]"
|
||||
: "border-black/5 dark:border-white/5 bg-black/[0.02] dark:bg-white/[0.01] opacity-50"
|
||||
}`}
|
||||
className={cn(
|
||||
"flex items-center justify-between rounded-lg border px-3 py-2 transition-colors",
|
||||
m.enabled ? "border-border bg-surface" : "border-border/60 bg-bg-subtle opacity-50"
|
||||
)}
|
||||
>
|
||||
<div className="flex items-center gap-3 min-w-0">
|
||||
<code className="text-xs px-1.5 py-0.5 rounded bg-amber-500/10 text-amber-700 dark:text-amber-300 font-mono shrink-0">
|
||||
<div className="flex min-w-0 items-center gap-3">
|
||||
<code className="shrink-0 rounded bg-warning/10 px-1.5 py-0.5 font-mono text-xs text-warning">
|
||||
{m.pattern}
|
||||
</code>
|
||||
<span className="text-text-muted text-[10px]">→</span>
|
||||
<span className="text-xs font-medium text-primary truncate">
|
||||
<span className="text-[10px] text-text-muted" aria-hidden="true">
|
||||
→
|
||||
</span>
|
||||
<span className="truncate text-xs font-medium text-primary">
|
||||
{m.comboName || m.comboId.slice(0, 8)}
|
||||
</span>
|
||||
{m.description && (
|
||||
<span className="text-[10px] text-text-muted truncate hidden sm:inline">
|
||||
<span className="hidden truncate text-[10px] text-text-muted sm:inline">
|
||||
{m.description}
|
||||
</span>
|
||||
)}
|
||||
<span className="text-[9px] px-1 py-0.5 rounded bg-black/5 dark:bg-white/5 text-text-muted shrink-0">
|
||||
<Badge size="sm" className="shrink-0">
|
||||
P{m.priority}
|
||||
</span>
|
||||
</Badge>
|
||||
</div>
|
||||
<div className="flex items-center gap-1 shrink-0">
|
||||
<button
|
||||
onClick={() => handleToggle(m)}
|
||||
className="p-1 rounded hover:bg-black/5 dark:hover:bg-white/5 transition-colors"
|
||||
<div className="flex shrink-0 items-center gap-1">
|
||||
{/* A switch with a static name ("Enabled") — the on/off state is its checked
|
||||
state, not part of the label (an action label + aria-pressed read as
|
||||
"Disable, pressed"). */}
|
||||
<Toggle
|
||||
size="sm"
|
||||
checked={m.enabled}
|
||||
onChange={() => handleToggle(m)}
|
||||
ariaLabel={t("enabled")}
|
||||
title={m.enabled ? t("disable") : t("enable")}
|
||||
>
|
||||
<span
|
||||
className={`material-symbols-outlined text-[14px] ${m.enabled ? "text-emerald-500" : "text-text-muted"}`}
|
||||
>
|
||||
{m.enabled ? "toggle_on" : "toggle_off"}
|
||||
</span>
|
||||
</button>
|
||||
<button
|
||||
className="mx-1"
|
||||
/>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon-sm"
|
||||
onClick={() => handleEdit(m)}
|
||||
className="p-1 rounded hover:bg-black/5 dark:hover:bg-white/5 transition-colors"
|
||||
title={tCommon("edit")}
|
||||
aria-label={tCommon("edit")}
|
||||
>
|
||||
<span className="material-symbols-outlined text-[14px] text-text-muted">
|
||||
edit
|
||||
</span>
|
||||
</button>
|
||||
<button
|
||||
<Icon name="edit" size={14} className="text-text-muted" />
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon-sm"
|
||||
onClick={() => handleDelete(m.id)}
|
||||
className="p-1 rounded hover:bg-red-500/10 transition-colors"
|
||||
title={tCommon("delete")}
|
||||
aria-label={tCommon("delete")}
|
||||
className="hover:bg-error/10"
|
||||
>
|
||||
<span className="material-symbols-outlined text-[14px] text-red-500">delete</span>
|
||||
</button>
|
||||
<Icon name="delete" size={14} className="text-error" />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
|
||||
@@ -1,19 +1,15 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect } from "react";
|
||||
import { useTranslations } from "next-intl";
|
||||
import {
|
||||
TYPE_COLORS,
|
||||
LEVEL_COLORS,
|
||||
PROVIDER_COLORS,
|
||||
getProxyStatusStyle as getStatusStyle,
|
||||
} from "@/shared/constants/colors";
|
||||
import { TYPE_COLORS, LEVEL_COLORS, PROVIDER_COLORS } from "@/shared/constants/colors";
|
||||
import {
|
||||
formatDuration as formatLatency,
|
||||
maskAccount,
|
||||
maskSegment,
|
||||
} from "@/shared/utils/formatting";
|
||||
import useEmailPrivacyStore from "@/store/emailPrivacyStore";
|
||||
import Badge from "./Badge";
|
||||
import Modal, { TALL_MODAL_PROPS } from "./Modal";
|
||||
|
||||
/**
|
||||
* Proxy log detail modal — shows full proxy event metadata, error info, and config.
|
||||
@@ -125,12 +121,9 @@ function TlsBadge({ log, t }) {
|
||||
{t("tlsFingerprint")}
|
||||
</div>
|
||||
{log.tlsFingerprint ? (
|
||||
<span
|
||||
className="inline-flex items-center gap-1 px-2.5 py-1 rounded text-[10px] font-bold uppercase"
|
||||
style={{ backgroundColor: "rgba(6, 182, 212, 0.15)", color: "#22d3ee" }}
|
||||
>
|
||||
<span style={{ fontSize: "12px" }}>🔒</span> Chrome 124
|
||||
</span>
|
||||
<Badge variant="info" className="text-[10px] font-bold uppercase">
|
||||
<span aria-hidden="true">🔒</span> Chrome 124
|
||||
</Badge>
|
||||
) : (
|
||||
<div className="text-sm text-text-muted">{t("directNative")}</div>
|
||||
)}
|
||||
@@ -155,7 +148,7 @@ function ObservedMetadataGrid({ log, t, emailsVisible }) {
|
||||
<div className="text-[10px] text-text-muted uppercase tracking-wider mb-1">
|
||||
{t("clientIp")}
|
||||
</div>
|
||||
<div className="text-sm font-medium font-mono text-emerald-400">{log.clientIp || "—"}</div>
|
||||
<div className="text-sm font-medium font-mono text-success">{log.clientIp || "—"}</div>
|
||||
</div>
|
||||
<div>
|
||||
<div className="text-[10px] text-text-muted uppercase tracking-wider mb-1">
|
||||
@@ -174,7 +167,7 @@ function ObservedMetadataGrid({ log, t, emailsVisible }) {
|
||||
{formatAttemptTiming(log.firstChunkMs)}
|
||||
</ObservedField>
|
||||
<ObservedField label={t("egressIp")}>
|
||||
<span className="text-emerald-400">{maskSegment(log.egressIp) || "—"}</span>
|
||||
<span className="text-success">{maskSegment(log.egressIp) || "—"}</span>
|
||||
</ObservedField>
|
||||
<ObservedLinkField
|
||||
label={t("correlationId")}
|
||||
@@ -210,79 +203,62 @@ function formatDateValue(iso) {
|
||||
}
|
||||
}
|
||||
|
||||
// Proxy status string → kit Badge tone.
|
||||
function proxyStatusTone(status: unknown) {
|
||||
if (status === "success") return "success" as const;
|
||||
if (status === "error") return "error" as const;
|
||||
if (status === "timeout") return "warning" as const;
|
||||
return "default" as const;
|
||||
}
|
||||
|
||||
export default function ProxyLogDetail({ log, onClose }) {
|
||||
const t = useTranslations("proxyLog");
|
||||
const { emailsVisible } = useEmailPrivacyStore();
|
||||
useEffect(() => {
|
||||
const handler = (e) => {
|
||||
if (e.key === "Escape") onClose();
|
||||
};
|
||||
window.addEventListener("keydown", handler);
|
||||
return () => window.removeEventListener("keydown", handler);
|
||||
}, [onClose]);
|
||||
|
||||
const statusStyle = getStatusStyle(log.status);
|
||||
|
||||
// The Modal adapter (kit Dialog) owns Escape, the overlay click, the focus trap and the
|
||||
// focus return.
|
||||
return (
|
||||
<div
|
||||
className="fixed inset-0 z-50 flex items-start justify-center pt-[5vh]"
|
||||
onClick={onClose}
|
||||
role="dialog"
|
||||
aria-modal="true"
|
||||
aria-label={t("detailAriaLabel")}
|
||||
<Modal
|
||||
isOpen
|
||||
onClose={onClose}
|
||||
maxWidth="700px"
|
||||
size="full"
|
||||
{...TALL_MODAL_PROPS}
|
||||
title={
|
||||
<span className="flex items-center gap-3">
|
||||
<Badge variant={proxyStatusTone(log.status)} className="font-bold uppercase">
|
||||
{log.status}
|
||||
</Badge>
|
||||
<span>{t("event")}</span>
|
||||
</span>
|
||||
}
|
||||
>
|
||||
<div className="absolute inset-0 bg-black/60 backdrop-blur-sm" />
|
||||
<div
|
||||
className="relative bg-bg-primary border border-border rounded-xl w-full max-w-[700px] max-h-[90vh] overflow-y-auto shadow-2xl"
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
>
|
||||
{/* Header */}
|
||||
<div className="sticky top-0 z-10 flex items-center justify-between px-6 py-4 border-b border-border bg-bg-primary/95 backdrop-blur-sm rounded-t-xl">
|
||||
<div className="flex items-center gap-3">
|
||||
<span
|
||||
className="inline-block px-2.5 py-1 rounded text-xs font-bold uppercase"
|
||||
style={{ backgroundColor: statusStyle.bg, color: statusStyle.text }}
|
||||
>
|
||||
{log.status}
|
||||
</span>
|
||||
<span className="font-bold text-lg">{t("event")}</span>
|
||||
<div className="flex flex-col gap-6">
|
||||
{/* Metadata Grid */}
|
||||
<ObservedMetadataGrid log={log} t={t} emailsVisible={emailsVisible} />
|
||||
|
||||
{/* Error */}
|
||||
{log.error && (
|
||||
<div className="rounded-xl border border-error/30 bg-error/10 p-4">
|
||||
<div className="mb-1 text-[10px] font-bold uppercase tracking-wider text-error">
|
||||
{t("error")}
|
||||
</div>
|
||||
<div className="font-mono text-sm text-error">{log.error}</div>
|
||||
</div>
|
||||
<button
|
||||
onClick={onClose}
|
||||
className="p-1.5 rounded-lg hover:bg-bg-subtle text-text-muted hover:text-text-primary transition-colors"
|
||||
aria-label={t("close")}
|
||||
>
|
||||
<span className="material-symbols-outlined">close</span>
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="p-6 flex flex-col gap-6">
|
||||
{/* Metadata Grid */}
|
||||
<ObservedMetadataGrid log={log} t={t} emailsVisible={emailsVisible} />
|
||||
|
||||
{/* Error */}
|
||||
{log.error && (
|
||||
<div className="p-4 rounded-xl bg-red-500/10 border border-red-500/30">
|
||||
<div className="text-[10px] text-red-400 uppercase tracking-wider mb-1 font-bold">
|
||||
{t("error")}
|
||||
</div>
|
||||
<div className="text-sm text-red-300 font-mono">{log.error}</div>
|
||||
{/* Proxy Config Details */}
|
||||
{log.proxy && (
|
||||
<div className="rounded-xl border border-border bg-bg-subtle p-4">
|
||||
<div className="mb-2 text-[10px] font-bold uppercase tracking-wider text-text-muted">
|
||||
{t("configuration")}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Proxy Config Details */}
|
||||
{log.proxy && (
|
||||
<div className="p-4 rounded-xl bg-bg-subtle border border-border">
|
||||
<div className="text-[10px] text-text-muted uppercase tracking-wider mb-2 font-bold">
|
||||
{t("configuration")}
|
||||
</div>
|
||||
<pre className="text-xs font-mono text-text-primary bg-black/20 rounded-lg p-3 overflow-x-auto">
|
||||
{JSON.stringify(log.proxy, null, 2)}
|
||||
</pre>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<pre className="overflow-x-auto rounded-lg bg-surface-2 p-3 font-mono text-xs text-text-primary">
|
||||
{JSON.stringify(log.proxy, null, 2)}
|
||||
</pre>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,15 +1,28 @@
|
||||
"use client";
|
||||
|
||||
import Icon from "@/shared/components/Icon";
|
||||
|
||||
import { useState, useEffect, useCallback, useMemo, useRef } from "react";
|
||||
import { useTranslations } from "next-intl";
|
||||
import Card from "./Card";
|
||||
import ProxyLogDetail from "./ProxyLogDetail";
|
||||
import {
|
||||
TYPE_COLORS,
|
||||
LEVEL_COLORS,
|
||||
PROVIDER_COLORS,
|
||||
getProxyStatusStyle as getStatusStyle,
|
||||
} from "@/shared/constants/colors";
|
||||
Table,
|
||||
TableBody,
|
||||
TableCell,
|
||||
TableHead,
|
||||
TableHeader,
|
||||
TableRow,
|
||||
} from "@omniroute/ui-kit/table";
|
||||
import { DataTableShell } from "@omniroute/ui-kit/data-table-shell";
|
||||
import { TableLoadingState } from "@omniroute/ui-kit/table-loading";
|
||||
import { cn } from "@/shared/utils/cn";
|
||||
import Badge from "./Badge";
|
||||
import Button from "./Button";
|
||||
import ColumnToggle from "./ColumnToggle";
|
||||
import EmptyState from "./EmptyState";
|
||||
import Input from "./Input";
|
||||
import Select from "./Select";
|
||||
import ProxyLogDetail from "./ProxyLogDetail";
|
||||
import { TYPE_COLORS, LEVEL_COLORS, PROVIDER_COLORS } from "@/shared/constants/colors";
|
||||
import {
|
||||
formatTime,
|
||||
formatDuration as formatLatency,
|
||||
@@ -19,14 +32,6 @@ import {
|
||||
} from "@/shared/utils/formatting";
|
||||
import useEmailPrivacyStore from "@/store/emailPrivacyStore";
|
||||
import { getProviderDisplayLabel } from "@/shared/utils/providerDisplayLabel";
|
||||
import {
|
||||
LOG_TABLE_CLASS,
|
||||
LOG_TABLE_HEAD_CLASS,
|
||||
LOG_TABLE_HEADER_BG_STYLE,
|
||||
LOG_TABLE_HEADER_CELL_CLASS,
|
||||
LOG_TABLE_HEADER_CELL_RIGHT_CLASS,
|
||||
LOG_TABLE_ROW_CLASS,
|
||||
} from "./logTableStyles";
|
||||
|
||||
const PROXY_COLUMN_KEYS = [
|
||||
"status",
|
||||
@@ -57,10 +62,19 @@ function isProviderTestLog(log) {
|
||||
return typeof log.targetUrl === "string" && log.targetUrl.endsWith("/connection-test");
|
||||
}
|
||||
|
||||
// Proxy status string → kit Badge tone.
|
||||
function proxyStatusTone(status: unknown) {
|
||||
if (status === "success") return "success" as const;
|
||||
if (status === "error") return "error" as const;
|
||||
if (status === "timeout") return "warning" as const;
|
||||
return "default" as const;
|
||||
}
|
||||
|
||||
const DEFAULT_VISIBLE = Object.fromEntries(PROXY_COLUMN_KEYS.map((key) => [key, true]));
|
||||
|
||||
export default function ProxyLogger() {
|
||||
const t = useTranslations("proxyLogger");
|
||||
const tCommon = useTranslations("common");
|
||||
const { emailsVisible } = useEmailPrivacyStore();
|
||||
const [logs, setLogs] = useState([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
@@ -235,449 +249,455 @@ export default function ProxyLogger() {
|
||||
return (
|
||||
<div className="flex flex-col gap-4">
|
||||
{/* Header Bar */}
|
||||
<div className="flex flex-wrap items-center gap-3">
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
{/* Recording Toggle */}
|
||||
<button
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
aria-pressed={recording}
|
||||
onClick={() => setRecording(!recording)}
|
||||
className={`flex items-center gap-2 px-3 py-1.5 rounded-full text-sm font-medium border transition-colors ${
|
||||
recording
|
||||
? "bg-red-500/10 border-red-500/30 text-red-400"
|
||||
: "bg-bg-subtle border-border text-text-muted"
|
||||
}`}
|
||||
className={cn(
|
||||
"rounded-full",
|
||||
recording ? "border-error/30 bg-error/10 text-error" : "text-text-muted"
|
||||
)}
|
||||
>
|
||||
<span
|
||||
className={`w-2 h-2 rounded-full ${recording ? "bg-red-500 animate-pulse" : "bg-text-muted"}`}
|
||||
aria-hidden="true"
|
||||
className={cn(
|
||||
"size-2 rounded-full",
|
||||
recording ? "bg-error animate-pulse" : "bg-text-muted"
|
||||
)}
|
||||
/>
|
||||
{recording ? t("recording") : t("paused")}
|
||||
</button>
|
||||
|
||||
{/* Search */}
|
||||
<div className="flex-1 min-w-[200px] relative">
|
||||
<span className="material-symbols-outlined absolute left-3 top-1/2 -translate-y-1/2 text-text-muted text-[18px]">
|
||||
search
|
||||
</span>
|
||||
<input
|
||||
type="text"
|
||||
placeholder={t("searchPlaceholder")}
|
||||
value={search}
|
||||
onChange={(e) => setSearch(e.target.value)}
|
||||
className="w-full pl-10 pr-4 py-2 rounded-lg bg-bg-subtle border border-border text-sm text-text-primary placeholder:text-text-muted focus:outline-none focus:border-primary"
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Type Dropdown */}
|
||||
<select
|
||||
value={selectedType}
|
||||
onChange={(e) => setSelectedType(e.target.value)}
|
||||
className="px-3 py-2 rounded-lg bg-bg-subtle border border-border text-sm text-text-primary focus:outline-none focus:border-primary appearance-none cursor-pointer min-w-[120px]"
|
||||
>
|
||||
<option value="">{t("allTypes")}</option>
|
||||
{uniqueTypes.map((t) => (
|
||||
<option key={t} value={t}>
|
||||
{(TYPE_COLORS[t]?.label || t).toUpperCase()}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
|
||||
{/* Level Dropdown */}
|
||||
<select
|
||||
value={selectedLevel}
|
||||
onChange={(e) => setSelectedLevel(e.target.value)}
|
||||
className="px-3 py-2 rounded-lg bg-bg-subtle border border-border text-sm text-text-primary focus:outline-none focus:border-primary appearance-none cursor-pointer min-w-[120px]"
|
||||
>
|
||||
<option value="">{t("allLevels")}</option>
|
||||
{uniqueLevels.map((l) => (
|
||||
<option key={l} value={l}>
|
||||
{LEVEL_COLORS[l]?.label || l}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
|
||||
{/* Provider Dropdown */}
|
||||
<select
|
||||
value={selectedProvider}
|
||||
onChange={(e) => setSelectedProvider(e.target.value)}
|
||||
className="px-3 py-2 rounded-lg bg-bg-subtle border border-border text-sm text-text-primary focus:outline-none focus:border-primary appearance-none cursor-pointer min-w-[140px]"
|
||||
>
|
||||
<option value="">{t("allProviders")}</option>
|
||||
{uniqueProviders.map((p) => {
|
||||
const pc = PROVIDER_COLORS[p];
|
||||
return (
|
||||
<option key={p} value={p}>
|
||||
{pc?.label || p.toUpperCase()}
|
||||
</option>
|
||||
);
|
||||
})}
|
||||
</select>
|
||||
</Button>
|
||||
|
||||
{/* Stats */}
|
||||
<div className="flex items-center gap-2 text-xs text-text-muted">
|
||||
<span className="px-2 py-1 rounded bg-bg-subtle border border-border font-mono">
|
||||
<div className="flex flex-wrap items-center gap-1.5 font-mono">
|
||||
<Badge size="sm">
|
||||
{totalCount} {t("total")}
|
||||
</span>
|
||||
<span className="px-2 py-1 rounded bg-emerald-500/10 text-emerald-400 font-mono">
|
||||
</Badge>
|
||||
<Badge size="sm" variant="success">
|
||||
{okCount} {t("ok")}
|
||||
</span>
|
||||
</Badge>
|
||||
{errorCount > 0 && (
|
||||
<span className="px-2 py-1 rounded bg-red-500/10 text-red-400 font-mono">
|
||||
<Badge size="sm" variant="error">
|
||||
{errorCount} {t("err")}
|
||||
</span>
|
||||
</Badge>
|
||||
)}
|
||||
{timeoutCount > 0 && (
|
||||
<span className="px-2 py-1 rounded bg-amber-500/10 text-amber-400 font-mono">
|
||||
<Badge size="sm" variant="warning">
|
||||
{timeoutCount} {t("timeoutShort")}
|
||||
</span>
|
||||
</Badge>
|
||||
)}
|
||||
{directCount > 0 && (
|
||||
<span className="px-2 py-1 rounded bg-gray-500/10 text-gray-400 font-mono">
|
||||
<Badge size="sm">
|
||||
{directCount} {t("direct")}
|
||||
</span>
|
||||
</Badge>
|
||||
)}
|
||||
{tlsCount > 0 && (
|
||||
<span className="px-2 py-1 rounded bg-cyan-500/10 text-cyan-400 font-mono">
|
||||
<Badge size="sm" variant="info">
|
||||
🔒 {tlsCount} TLS
|
||||
</span>
|
||||
</Badge>
|
||||
)}
|
||||
{testsCount > 0 && (
|
||||
<span className="px-2 py-1 rounded bg-violet-500/10 text-violet-400 font-mono">
|
||||
<Badge size="sm" className="border-chart-3/30 bg-chart-3/10 text-chart-3">
|
||||
{testsCount} {t("filterTests")}
|
||||
</span>
|
||||
</Badge>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Sort */}
|
||||
<select
|
||||
value={sortBy}
|
||||
onChange={(e) => setSortBy(e.target.value)}
|
||||
className="px-3 py-2 rounded-lg bg-bg-subtle border border-border text-sm text-text-primary focus:outline-none focus:border-primary appearance-none cursor-pointer min-w-[140px]"
|
||||
>
|
||||
<option value="newest">{t("newest")}</option>
|
||||
<option value="oldest">{t("oldest")}</option>
|
||||
<option value="latency_desc">{t("latencyDesc")}</option>
|
||||
<option value="latency_asc">{t("latencyAsc")}</option>
|
||||
</select>
|
||||
|
||||
{/* Refresh */}
|
||||
<button
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="ms-auto"
|
||||
onClick={() => fetchLogs(false)}
|
||||
className="p-2 rounded-lg hover:bg-bg-subtle text-text-muted hover:text-text-primary transition-colors"
|
||||
title={t("refresh")}
|
||||
aria-label={t("refresh")}
|
||||
>
|
||||
<span className="material-symbols-outlined text-[18px]">refresh</span>
|
||||
</button>
|
||||
<Icon name="refresh" size={18} />
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{/* Quick Filters */}
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
{statusFilters.map((f) => (
|
||||
<button
|
||||
key={f.key}
|
||||
onClick={() => setActiveFilter(activeFilter === f.key ? "all" : f.key)}
|
||||
className={`flex items-center gap-1.5 px-3 py-1 rounded-full text-xs font-medium border transition-all ${
|
||||
activeFilter === f.key
|
||||
? f.key === "error"
|
||||
? "bg-red-500/20 text-red-400 border-red-500/40"
|
||||
: f.key === "ok"
|
||||
? "bg-emerald-500/20 text-emerald-400 border-emerald-500/40"
|
||||
: f.key === "timeout"
|
||||
? "bg-amber-500/20 text-amber-400 border-amber-500/40"
|
||||
: "bg-primary text-accent-foreground border-primary"
|
||||
: "bg-bg-subtle border-border text-text-muted hover:border-text-muted"
|
||||
}`}
|
||||
>
|
||||
{f.icon && <span className="material-symbols-outlined text-[14px]">{f.icon}</span>}
|
||||
{f.label}
|
||||
</button>
|
||||
))}
|
||||
<DataTableShell
|
||||
filterAlignment="end"
|
||||
filters={
|
||||
<>
|
||||
{/* Search */}
|
||||
<Input
|
||||
type="text"
|
||||
icon="search"
|
||||
placeholder={t("searchPlaceholder")}
|
||||
aria-label={t("searchPlaceholder")}
|
||||
value={search}
|
||||
onChange={(e) => setSearch(e.target.value)}
|
||||
className="w-full sm:w-72"
|
||||
/>
|
||||
|
||||
{uniqueProviders.length > 0 && <span className="w-px h-5 bg-border mx-1" />}
|
||||
|
||||
<span className="text-[10px] text-text-muted uppercase tracking-wider mr-1">
|
||||
{t("filterSource")}
|
||||
</span>
|
||||
{sourceFilters.map((f) => (
|
||||
<button
|
||||
key={`source-${f.key}`}
|
||||
onClick={() => setSourceFilter(sourceFilter === f.key ? "all" : f.key)}
|
||||
className={`flex items-center gap-1.5 px-3 py-1 rounded-full text-xs font-medium border transition-all ${
|
||||
sourceFilter === f.key
|
||||
? "bg-primary text-accent-foreground border-primary"
|
||||
: "bg-bg-subtle border-border text-text-muted hover:border-text-muted"
|
||||
}`}
|
||||
>
|
||||
{f.label}
|
||||
</button>
|
||||
))}
|
||||
|
||||
{uniqueProviders.length > 0 && <span className="w-px h-5 bg-border mx-1" />}
|
||||
|
||||
{uniqueProviders.map((p) => {
|
||||
const pc = PROVIDER_COLORS[p] || { bg: "#374151", text: "#fff", label: p.toUpperCase() };
|
||||
const isActive = selectedProvider === p;
|
||||
return (
|
||||
<button
|
||||
key={p}
|
||||
onClick={() => setSelectedProvider(isActive ? "" : p)}
|
||||
className={`px-3 py-1 rounded-full text-xs font-bold uppercase border transition-all ${
|
||||
isActive
|
||||
? "border-white/40 ring-1 ring-white/20"
|
||||
: "border-transparent opacity-70 hover:opacity-100"
|
||||
}`}
|
||||
style={{
|
||||
backgroundColor: isActive ? pc.bg : `${pc.bg}33`,
|
||||
color: isActive ? pc.text : pc.bg,
|
||||
}}
|
||||
{/* Type Dropdown */}
|
||||
<Select
|
||||
className="w-auto"
|
||||
value={selectedType}
|
||||
onChange={(e) => setSelectedType(e.target.value)}
|
||||
aria-label={t("colType")}
|
||||
selectClassName="min-w-[120px]"
|
||||
>
|
||||
{pc.label}
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
<option value="">{t("allTypes")}</option>
|
||||
{uniqueTypes.map((type) => (
|
||||
<option key={type} value={type}>
|
||||
{(TYPE_COLORS[type]?.label || type).toUpperCase()}
|
||||
</option>
|
||||
))}
|
||||
</Select>
|
||||
|
||||
{/* Column Visibility Toggles */}
|
||||
<div className="flex flex-wrap items-center gap-1.5">
|
||||
<span className="text-[10px] text-text-muted uppercase tracking-wider mr-1">
|
||||
{t("columns")}
|
||||
</span>
|
||||
{columns.map((col) => (
|
||||
<button
|
||||
key={col.key}
|
||||
onClick={() => toggleColumn(col.key)}
|
||||
className={`px-2 py-0.5 rounded text-[10px] font-medium border transition-all ${
|
||||
visibleColumns[col.key]
|
||||
? "bg-primary/15 text-primary border-primary/30"
|
||||
: "bg-bg-subtle text-text-muted border-border opacity-50 hover:opacity-80"
|
||||
}`}
|
||||
>
|
||||
{col.label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
{/* Level Dropdown */}
|
||||
<Select
|
||||
className="w-auto"
|
||||
value={selectedLevel}
|
||||
onChange={(e) => setSelectedLevel(e.target.value)}
|
||||
aria-label={t("colLevel")}
|
||||
selectClassName="min-w-[120px]"
|
||||
>
|
||||
<option value="">{t("allLevels")}</option>
|
||||
{uniqueLevels.map((l) => (
|
||||
<option key={l} value={l}>
|
||||
{LEVEL_COLORS[l]?.label || l}
|
||||
</option>
|
||||
))}
|
||||
</Select>
|
||||
|
||||
{/* Table */}
|
||||
<Card className="overflow-hidden bg-surface">
|
||||
<div className="p-0 overflow-x-auto max-h-[calc(100vh-320px)] overflow-y-auto">
|
||||
{loading && logs.length === 0 ? (
|
||||
<div className="p-8 text-center text-text-muted">{t("loadingProxyLogs")}</div>
|
||||
) : logs.length === 0 ? (
|
||||
<div className="p-8 text-center text-text-muted">
|
||||
<span className="material-symbols-outlined text-[48px] mb-2 block opacity-40">
|
||||
vpn_lock
|
||||
</span>
|
||||
{t("noProxyLogs")}
|
||||
</div>
|
||||
) : sortedLogs.length === 0 ? (
|
||||
<div className="p-8 text-center text-text-muted">{t("noMatchingLogs")}</div>
|
||||
) : (
|
||||
<table className={LOG_TABLE_CLASS}>
|
||||
<thead className={LOG_TABLE_HEAD_CLASS} style={LOG_TABLE_HEADER_BG_STYLE}>
|
||||
<tr className={LOG_TABLE_ROW_CLASS} style={LOG_TABLE_HEADER_BG_STYLE}>
|
||||
{visibleColumns.status && (
|
||||
<th className={LOG_TABLE_HEADER_CELL_CLASS}>{t("colStatus")}</th>
|
||||
)}
|
||||
{visibleColumns.proxy && (
|
||||
<th className={LOG_TABLE_HEADER_CELL_CLASS}>{t("colProxy")}</th>
|
||||
)}
|
||||
{visibleColumns.tls && (
|
||||
<th className={LOG_TABLE_HEADER_CELL_CLASS}>{t("colTls")}</th>
|
||||
)}
|
||||
{visibleColumns.type && (
|
||||
<th className={LOG_TABLE_HEADER_CELL_CLASS}>{t("colType")}</th>
|
||||
)}
|
||||
{visibleColumns.level && (
|
||||
<th className={LOG_TABLE_HEADER_CELL_CLASS}>{t("colLevel")}</th>
|
||||
)}
|
||||
{visibleColumns.provider && (
|
||||
<th className={LOG_TABLE_HEADER_CELL_CLASS}>{t("colProvider")}</th>
|
||||
)}
|
||||
{visibleColumns.upstream && (
|
||||
<th className={LOG_TABLE_HEADER_CELL_RIGHT_CLASS}>{t("colUpstream")}</th>
|
||||
)}
|
||||
{visibleColumns.egress && (
|
||||
<th className={LOG_TABLE_HEADER_CELL_CLASS}>{t("colEgress")}</th>
|
||||
)}
|
||||
{visibleColumns.correlation && (
|
||||
<th className={LOG_TABLE_HEADER_CELL_CLASS}>{t("colCorrelation")}</th>
|
||||
)}
|
||||
{visibleColumns.servedBy && (
|
||||
<th className={LOG_TABLE_HEADER_CELL_CLASS}>{t("colServedBy")}</th>
|
||||
)}
|
||||
{visibleColumns.target && (
|
||||
<th className={LOG_TABLE_HEADER_CELL_CLASS}>{t("colTarget")}</th>
|
||||
)}
|
||||
{visibleColumns.latency && (
|
||||
<th className={LOG_TABLE_HEADER_CELL_RIGHT_CLASS}>{t("colLatency")}</th>
|
||||
)}
|
||||
{visibleColumns.ip && (
|
||||
<th className={LOG_TABLE_HEADER_CELL_CLASS}>{t("colClientIp")}</th>
|
||||
)}
|
||||
{visibleColumns.time && (
|
||||
<th className={LOG_TABLE_HEADER_CELL_RIGHT_CLASS}>{t("colTime")}</th>
|
||||
)}
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody className="divide-y divide-border/30">
|
||||
{sortedLogs.map((log) => {
|
||||
const statusStyle = getStatusStyle(log.status);
|
||||
const typeColor = TYPE_COLORS[log.proxy?.type] || {
|
||||
bg: "#6B7280",
|
||||
text: "#fff",
|
||||
label: log.proxy?.type || "-",
|
||||
};
|
||||
const levelColor = LEVEL_COLORS[log.level] || LEVEL_COLORS.direct;
|
||||
const resolvedProviderLabel =
|
||||
getProviderDisplayLabel(log.provider, providerNodes) ||
|
||||
(log.provider || "-").toUpperCase();
|
||||
const providerColor = PROVIDER_COLORS[log.provider] || {
|
||||
bg: "#374151",
|
||||
text: "#fff",
|
||||
label: resolvedProviderLabel,
|
||||
};
|
||||
const isError = log.status === "error" || log.status === "timeout";
|
||||
{/* Provider Dropdown */}
|
||||
<Select
|
||||
className="w-auto"
|
||||
value={selectedProvider}
|
||||
onChange={(e) => setSelectedProvider(e.target.value)}
|
||||
aria-label={t("colProvider")}
|
||||
selectClassName="min-w-[140px]"
|
||||
>
|
||||
<option value="">{t("allProviders")}</option>
|
||||
{uniqueProviders.map((p) => {
|
||||
const pc = PROVIDER_COLORS[p];
|
||||
return (
|
||||
<option key={p} value={p}>
|
||||
{pc?.label || p.toUpperCase()}
|
||||
</option>
|
||||
);
|
||||
})}
|
||||
</Select>
|
||||
|
||||
return (
|
||||
<tr
|
||||
key={log.id}
|
||||
onClick={() => setSelectedLog(selectedLog?.id === log.id ? null : log)}
|
||||
className={`cursor-pointer hover:bg-sky-500/10 dark:hover:bg-sky-400/10 transition-colors ${isError ? "bg-red-500/5" : ""}`}
|
||||
>
|
||||
{visibleColumns.status && (
|
||||
<td className="px-3 py-2">
|
||||
<span
|
||||
className="inline-block px-2 py-0.5 rounded text-[10px] font-bold min-w-[50px] text-center uppercase"
|
||||
style={{ backgroundColor: statusStyle.bg, color: statusStyle.text }}
|
||||
>
|
||||
{log.status}
|
||||
</span>
|
||||
</td>
|
||||
)}
|
||||
{visibleColumns.proxy && (
|
||||
<td className="px-3 py-2 font-mono text-[11px] text-primary">
|
||||
{log.proxy
|
||||
? log.proxy.name || `${log.proxy.host}:${log.proxy.port}`
|
||||
: "—"}
|
||||
</td>
|
||||
)}
|
||||
{visibleColumns.tls && (
|
||||
<td className="px-3 py-2">
|
||||
{log.tlsFingerprint ? (
|
||||
<span
|
||||
className="inline-flex items-center gap-1 px-2 py-0.5 rounded text-[9px] font-bold uppercase"
|
||||
style={{
|
||||
backgroundColor: "rgba(6, 182, 212, 0.15)",
|
||||
color: "#22d3ee",
|
||||
}}
|
||||
title={t("tlsFingerprint")}
|
||||
>
|
||||
<span style={{ fontSize: "10px" }}>🔒</span> TLS
|
||||
</span>
|
||||
) : (
|
||||
<span className="text-text-muted text-[10px]">—</span>
|
||||
)}
|
||||
</td>
|
||||
)}
|
||||
{visibleColumns.type && (
|
||||
<td className="px-3 py-2">
|
||||
<span
|
||||
className="inline-block px-2 py-0.5 rounded text-[9px] font-bold uppercase"
|
||||
style={{ backgroundColor: typeColor.bg, color: typeColor.text }}
|
||||
>
|
||||
{typeColor.label}
|
||||
</span>
|
||||
</td>
|
||||
)}
|
||||
{visibleColumns.level && (
|
||||
<td className="px-3 py-2">
|
||||
<span
|
||||
className="inline-block px-2 py-0.5 rounded text-[9px] font-bold uppercase"
|
||||
style={{ backgroundColor: levelColor.bg, color: levelColor.text }}
|
||||
>
|
||||
{levelColor.label}
|
||||
</span>
|
||||
</td>
|
||||
)}
|
||||
{visibleColumns.provider && (
|
||||
<td className="px-3 py-2">
|
||||
{log.provider ? (
|
||||
<span
|
||||
className="inline-block px-2 py-0.5 rounded text-[9px] font-bold uppercase"
|
||||
style={{
|
||||
backgroundColor: providerColor.bg,
|
||||
color: providerColor.text,
|
||||
}}
|
||||
>
|
||||
{providerColor.label}
|
||||
</span>
|
||||
) : (
|
||||
<span className="text-text-muted text-[10px]">—</span>
|
||||
)}
|
||||
</td>
|
||||
)}
|
||||
{visibleColumns.upstream && (
|
||||
<td className="px-3 py-2 text-right text-text-muted font-mono">
|
||||
{typeof log.upstreamStatus === "number"
|
||||
? String(log.upstreamStatus)
|
||||
: "—"}
|
||||
</td>
|
||||
)}
|
||||
{visibleColumns.egress && (
|
||||
<td className="px-3 py-2 font-mono text-[11px] text-emerald-400">
|
||||
{maskSegment(log.egressIp) || "—"}
|
||||
</td>
|
||||
)}
|
||||
{visibleColumns.correlation && (
|
||||
<td className="px-3 py-2 font-mono text-[11px]">
|
||||
{log.correlationId ? (
|
||||
<a
|
||||
href={`/dashboard/logs?correlationId=${encodeURIComponent(log.correlationId)}`}
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
title={log.correlationId}
|
||||
className="text-primary hover:underline"
|
||||
>
|
||||
{log.correlationId.slice(0, 12)}…
|
||||
</a>
|
||||
) : (
|
||||
<span className="text-text-muted text-[10px]">—</span>
|
||||
)}
|
||||
</td>
|
||||
)}
|
||||
{visibleColumns.servedBy && (
|
||||
<td className="px-3 py-2 font-mono text-[11px] text-text-muted">
|
||||
{maskAccount(log.rotationAccount ?? log.account, emailsVisible) || "—"}
|
||||
</td>
|
||||
)}
|
||||
{visibleColumns.target && (
|
||||
<td
|
||||
className="px-3 py-2 text-text-muted truncate max-w-[200px] font-mono text-[10px]"
|
||||
title={log.targetUrl}
|
||||
>
|
||||
{truncateUrl(log.targetUrl)}
|
||||
</td>
|
||||
)}
|
||||
{visibleColumns.latency && (
|
||||
<td className="px-3 py-2 text-right text-text-muted font-mono">
|
||||
{formatLatency(log.latencyMs)}
|
||||
</td>
|
||||
)}
|
||||
{visibleColumns.ip && (
|
||||
<td className="px-3 py-2 font-mono text-[11px] text-emerald-400">
|
||||
{log.clientIp || "—"}
|
||||
</td>
|
||||
)}
|
||||
{visibleColumns.time && (
|
||||
<td className="px-3 py-2 text-right text-text-muted">
|
||||
{formatTime(log.timestamp)}
|
||||
</td>
|
||||
)}
|
||||
</tr>
|
||||
);
|
||||
})}
|
||||
</tbody>
|
||||
</table>
|
||||
{/* Sort */}
|
||||
<Select
|
||||
className="w-auto"
|
||||
value={sortBy}
|
||||
onChange={(e) => setSortBy(e.target.value)}
|
||||
aria-label={t("sortLogs")}
|
||||
selectClassName="min-w-[140px]"
|
||||
>
|
||||
<option value="newest">{t("newest")}</option>
|
||||
<option value="oldest">{t("oldest")}</option>
|
||||
<option value="latency_desc">{t("latencyDesc")}</option>
|
||||
<option value="latency_asc">{t("latencyAsc")}</option>
|
||||
</Select>
|
||||
|
||||
{/* Column visibility — kit DropdownMenu checkbox items via the adapter. */}
|
||||
<ColumnToggle columns={columns} visible={visibleColumns} onToggle={toggleColumn} />
|
||||
</>
|
||||
}
|
||||
>
|
||||
{/* Quick Filters */}
|
||||
<div
|
||||
role="group"
|
||||
aria-label={tCommon("filters")}
|
||||
className="flex flex-wrap items-center gap-2 border-b border-border px-3 py-2.5"
|
||||
>
|
||||
{statusFilters.map((f) => (
|
||||
<Button
|
||||
key={f.key}
|
||||
variant="outline"
|
||||
size="sm"
|
||||
aria-pressed={activeFilter === f.key}
|
||||
onClick={() => setActiveFilter(activeFilter === f.key ? "all" : f.key)}
|
||||
className={cn(
|
||||
"h-7 min-h-7 rounded-full px-3 text-xs",
|
||||
activeFilter === f.key
|
||||
? f.key === "error"
|
||||
? "bg-error/20 text-error border-error/40"
|
||||
: f.key === "ok"
|
||||
? "bg-success/20 text-success border-success/40"
|
||||
: f.key === "timeout"
|
||||
? "bg-warning/20 text-warning border-warning/40"
|
||||
: "bg-primary text-accent-foreground border-primary"
|
||||
: "text-text-muted"
|
||||
)}
|
||||
>
|
||||
{f.icon && <Icon name={f.icon} size={14} />}
|
||||
{f.label}
|
||||
</Button>
|
||||
))}
|
||||
|
||||
{uniqueProviders.length > 0 && (
|
||||
<span aria-hidden="true" className="mx-1 h-5 w-px bg-border" />
|
||||
)}
|
||||
</div>
|
||||
</Card>
|
||||
|
||||
<span className="mr-1 text-[10px] uppercase tracking-wider text-text-muted">
|
||||
{t("filterSource")}
|
||||
</span>
|
||||
{sourceFilters.map((f) => (
|
||||
<Button
|
||||
key={`source-${f.key}`}
|
||||
variant="outline"
|
||||
size="sm"
|
||||
aria-pressed={sourceFilter === f.key}
|
||||
onClick={() => setSourceFilter(sourceFilter === f.key ? "all" : f.key)}
|
||||
className={cn(
|
||||
"h-7 min-h-7 rounded-full px-3 text-xs",
|
||||
sourceFilter === f.key
|
||||
? "bg-primary text-accent-foreground border-primary"
|
||||
: "text-text-muted"
|
||||
)}
|
||||
>
|
||||
{f.label}
|
||||
</Button>
|
||||
))}
|
||||
|
||||
{uniqueProviders.length > 0 && (
|
||||
<span aria-hidden="true" className="mx-1 h-5 w-px bg-border" />
|
||||
)}
|
||||
|
||||
{uniqueProviders.map((p) => {
|
||||
// Provider identity colours (brand palette in constants/colors), not status tones.
|
||||
const pc = PROVIDER_COLORS[p] || {
|
||||
bg: "#374151",
|
||||
text: "#fff",
|
||||
label: p.toUpperCase(),
|
||||
};
|
||||
const isActive = selectedProvider === p;
|
||||
return (
|
||||
<Button
|
||||
key={p}
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
aria-pressed={isActive}
|
||||
onClick={() => setSelectedProvider(isActive ? "" : p)}
|
||||
className={cn(
|
||||
"h-7 min-h-7 rounded-full border px-3 text-xs font-bold uppercase",
|
||||
isActive
|
||||
? "border-border-strong ring-1 ring-border-strong"
|
||||
: "border-transparent opacity-70 hover:opacity-100"
|
||||
)}
|
||||
style={{
|
||||
backgroundColor: isActive ? pc.bg : `${pc.bg}33`,
|
||||
color: isActive ? pc.text : pc.bg,
|
||||
}}
|
||||
>
|
||||
{pc.label}
|
||||
</Button>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
|
||||
{/* Table */}
|
||||
{loading && logs.length === 0 ? (
|
||||
<TableLoadingState label={t("loadingProxyLogs")} />
|
||||
) : logs.length === 0 ? (
|
||||
<EmptyState icon="vpn_lock" title={t("noProxyLogs")} />
|
||||
) : sortedLogs.length === 0 ? (
|
||||
<EmptyState icon="search_off" title={t("noMatchingLogs")} />
|
||||
) : (
|
||||
<Table
|
||||
scrollbarLabel={t("tableLabel")}
|
||||
// Opaque bg-surface viewport (#4233); it scrolls both axes under a sticky header.
|
||||
containerClassName="max-h-[calc(100vh-320px)] overflow-auto rounded-none border-0 bg-surface"
|
||||
className="text-left text-xs"
|
||||
>
|
||||
<TableHeader className="sticky top-0 z-10">
|
||||
<TableRow>
|
||||
{visibleColumns.status && <TableHead className="px-3">{t("colStatus")}</TableHead>}
|
||||
{visibleColumns.proxy && <TableHead className="px-3">{t("colProxy")}</TableHead>}
|
||||
{visibleColumns.tls && <TableHead className="px-3">{t("colTls")}</TableHead>}
|
||||
{visibleColumns.type && <TableHead className="px-3">{t("colType")}</TableHead>}
|
||||
{visibleColumns.level && <TableHead className="px-3">{t("colLevel")}</TableHead>}
|
||||
{visibleColumns.provider && (
|
||||
<TableHead className="px-3">{t("colProvider")}</TableHead>
|
||||
)}
|
||||
{visibleColumns.upstream && (
|
||||
<TableHead className="ci-table__head--numeric px-3">{t("colUpstream")}</TableHead>
|
||||
)}
|
||||
{visibleColumns.egress && <TableHead className="px-3">{t("colEgress")}</TableHead>}
|
||||
{visibleColumns.correlation && (
|
||||
<TableHead className="px-3">{t("colCorrelation")}</TableHead>
|
||||
)}
|
||||
{visibleColumns.servedBy && (
|
||||
<TableHead className="px-3">{t("colServedBy")}</TableHead>
|
||||
)}
|
||||
{visibleColumns.target && <TableHead className="px-3">{t("colTarget")}</TableHead>}
|
||||
{visibleColumns.latency && (
|
||||
<TableHead className="ci-table__head--numeric px-3">{t("colLatency")}</TableHead>
|
||||
)}
|
||||
{visibleColumns.ip && <TableHead className="px-3">{t("colClientIp")}</TableHead>}
|
||||
{visibleColumns.time && (
|
||||
<TableHead className="ci-table__head--numeric px-3">{t("colTime")}</TableHead>
|
||||
)}
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{sortedLogs.map((log) => {
|
||||
// Proxy type / level keep their categorical palettes (constants/colors).
|
||||
const typeColor = TYPE_COLORS[log.proxy?.type] || {
|
||||
bg: "#6B7280",
|
||||
text: "#fff",
|
||||
label: log.proxy?.type || "-",
|
||||
};
|
||||
const levelColor = LEVEL_COLORS[log.level] || LEVEL_COLORS.direct;
|
||||
const resolvedProviderLabel =
|
||||
getProviderDisplayLabel(log.provider, providerNodes) ||
|
||||
(log.provider || "-").toUpperCase();
|
||||
const providerColor = PROVIDER_COLORS[log.provider] || {
|
||||
bg: "#374151",
|
||||
text: "#fff",
|
||||
label: resolvedProviderLabel,
|
||||
};
|
||||
const isError = log.status === "error" || log.status === "timeout";
|
||||
|
||||
return (
|
||||
<TableRow
|
||||
key={log.id}
|
||||
onClick={() => setSelectedLog(selectedLog?.id === log.id ? null : log)}
|
||||
className={cn(
|
||||
"cursor-pointer hover:bg-info/10 transition-colors",
|
||||
isError && "bg-error/5"
|
||||
)}
|
||||
>
|
||||
{visibleColumns.status && (
|
||||
<TableCell className="px-3 py-2">
|
||||
<Badge
|
||||
size="sm"
|
||||
variant={proxyStatusTone(log.status)}
|
||||
className="min-w-[50px] justify-center font-bold uppercase"
|
||||
>
|
||||
{log.status}
|
||||
</Badge>
|
||||
</TableCell>
|
||||
)}
|
||||
{visibleColumns.proxy && (
|
||||
<TableCell className="px-3 py-2 font-mono text-[11px] text-primary">
|
||||
{log.proxy ? log.proxy.name || `${log.proxy.host}:${log.proxy.port}` : "—"}
|
||||
</TableCell>
|
||||
)}
|
||||
{visibleColumns.tls && (
|
||||
<TableCell className="px-3 py-2">
|
||||
{log.tlsFingerprint ? (
|
||||
<Badge
|
||||
size="sm"
|
||||
variant="info"
|
||||
className="text-[9px] font-bold uppercase"
|
||||
title={t("tlsFingerprint")}
|
||||
>
|
||||
<span aria-hidden="true">🔒</span> TLS
|
||||
</Badge>
|
||||
) : (
|
||||
<span className="text-[10px] text-text-muted">—</span>
|
||||
)}
|
||||
</TableCell>
|
||||
)}
|
||||
{visibleColumns.type && (
|
||||
<TableCell className="px-3 py-2">
|
||||
<span
|
||||
className="inline-block rounded px-2 py-0.5 text-[9px] font-bold uppercase"
|
||||
style={{ backgroundColor: typeColor.bg, color: typeColor.text }}
|
||||
>
|
||||
{typeColor.label}
|
||||
</span>
|
||||
</TableCell>
|
||||
)}
|
||||
{visibleColumns.level && (
|
||||
<TableCell className="px-3 py-2">
|
||||
<span
|
||||
className="inline-block rounded px-2 py-0.5 text-[9px] font-bold uppercase"
|
||||
style={{ backgroundColor: levelColor.bg, color: levelColor.text }}
|
||||
>
|
||||
{levelColor.label}
|
||||
</span>
|
||||
</TableCell>
|
||||
)}
|
||||
{visibleColumns.provider && (
|
||||
<TableCell className="px-3 py-2">
|
||||
{log.provider ? (
|
||||
<span
|
||||
className="inline-block rounded px-2 py-0.5 text-[9px] font-bold uppercase"
|
||||
style={{
|
||||
backgroundColor: providerColor.bg,
|
||||
color: providerColor.text,
|
||||
}}
|
||||
>
|
||||
{providerColor.label}
|
||||
</span>
|
||||
) : (
|
||||
<span className="text-[10px] text-text-muted">—</span>
|
||||
)}
|
||||
</TableCell>
|
||||
)}
|
||||
{visibleColumns.upstream && (
|
||||
<TableCell className="px-3 py-2 text-right font-mono text-text-muted">
|
||||
{typeof log.upstreamStatus === "number" ? String(log.upstreamStatus) : "—"}
|
||||
</TableCell>
|
||||
)}
|
||||
{visibleColumns.egress && (
|
||||
<TableCell className="px-3 py-2 font-mono text-[11px] text-success">
|
||||
{maskSegment(log.egressIp) || "—"}
|
||||
</TableCell>
|
||||
)}
|
||||
{visibleColumns.correlation && (
|
||||
<TableCell className="px-3 py-2 font-mono text-[11px]">
|
||||
{log.correlationId ? (
|
||||
<a
|
||||
href={`/dashboard/logs?correlationId=${encodeURIComponent(log.correlationId)}`}
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
title={log.correlationId}
|
||||
className="text-primary hover:underline"
|
||||
>
|
||||
{log.correlationId.slice(0, 12)}…
|
||||
</a>
|
||||
) : (
|
||||
<span className="text-[10px] text-text-muted">—</span>
|
||||
)}
|
||||
</TableCell>
|
||||
)}
|
||||
{visibleColumns.servedBy && (
|
||||
<TableCell className="px-3 py-2 font-mono text-[11px] text-text-muted">
|
||||
{maskAccount(log.rotationAccount ?? log.account, emailsVisible) || "—"}
|
||||
</TableCell>
|
||||
)}
|
||||
{visibleColumns.target && (
|
||||
<TableCell
|
||||
className="max-w-[200px] truncate px-3 py-2 font-mono text-[10px] text-text-muted"
|
||||
title={log.targetUrl}
|
||||
>
|
||||
{truncateUrl(log.targetUrl)}
|
||||
</TableCell>
|
||||
)}
|
||||
{visibleColumns.latency && (
|
||||
<TableCell className="px-3 py-2 text-right font-mono text-text-muted">
|
||||
{formatLatency(log.latencyMs)}
|
||||
</TableCell>
|
||||
)}
|
||||
{visibleColumns.ip && (
|
||||
<TableCell className="px-3 py-2 font-mono text-[11px] text-success">
|
||||
{log.clientIp || "—"}
|
||||
</TableCell>
|
||||
)}
|
||||
{visibleColumns.time && (
|
||||
<TableCell className="px-3 py-2 text-right text-text-muted">
|
||||
{formatTime(log.timestamp)}
|
||||
</TableCell>
|
||||
)}
|
||||
</TableRow>
|
||||
);
|
||||
})}
|
||||
</TableBody>
|
||||
</Table>
|
||||
)}
|
||||
</DataTableShell>
|
||||
{/* Detail Panel */}
|
||||
{selectedLog && <ProxyLogDetail log={selectedLog} onClose={() => setSelectedLog(null)} />}
|
||||
</div>
|
||||
|
||||
@@ -499,7 +499,7 @@ export default function ReasoningRoutingRules({
|
||||
</p>
|
||||
)}
|
||||
{(loadFailed || keyMissing) && (
|
||||
<p className="mt-4 text-sm text-red-500" role="alert">
|
||||
<p className="mt-4 text-sm text-error" role="alert">
|
||||
{keyMissing ? e("missingKey") : t("loadError")}
|
||||
</p>
|
||||
)}
|
||||
@@ -760,7 +760,7 @@ export default function ReasoningRoutingRules({
|
||||
/>
|
||||
)}
|
||||
{catalogError && sourceKind === "model" && (
|
||||
<p className="text-sm text-amber-600">{e("catalogError")}</p>
|
||||
<p className="text-sm text-warning">{e("catalogError")}</p>
|
||||
)}
|
||||
<p className="rounded-lg bg-primary/5 p-3 text-sm leading-relaxed text-text-muted">
|
||||
{e("matchStageHint")}
|
||||
@@ -852,7 +852,7 @@ export default function ReasoningRoutingRules({
|
||||
)}
|
||||
<p className="text-sm text-text-muted">{e("effortHint." + form.effortMode)}</p>
|
||||
{capabilityWarning && (
|
||||
<p role="status" className="text-sm text-amber-600 dark:text-amber-400">
|
||||
<p role="status" className="text-sm text-warning">
|
||||
{capabilityWarning}
|
||||
</p>
|
||||
)}
|
||||
@@ -939,11 +939,7 @@ export default function ReasoningRoutingRules({
|
||||
<Button type="button" variant="ghost" onClick={() => confirmDiscard(reset)}>
|
||||
{t("cancel")}
|
||||
</Button>
|
||||
{dirty && (
|
||||
<span className="text-xs text-amber-600 dark:text-amber-400">
|
||||
{e("unsaved")}
|
||||
</span>
|
||||
)}
|
||||
{dirty && <span className="text-xs text-warning">{e("unsaved")}</span>}
|
||||
</div>
|
||||
</fieldset>
|
||||
</form>
|
||||
@@ -999,9 +995,7 @@ export default function ReasoningRoutingRules({
|
||||
]}
|
||||
/>
|
||||
</div>
|
||||
{dirty && (
|
||||
<p className="mt-4 text-sm text-amber-600 dark:text-amber-400">{e("saveBeforeCheck")}</p>
|
||||
)}
|
||||
{dirty && <p className="mt-4 text-sm text-warning">{e("saveBeforeCheck")}</p>}
|
||||
<Button
|
||||
className="mt-4"
|
||||
variant="secondary"
|
||||
@@ -1031,7 +1025,7 @@ export default function ReasoningRoutingRules({
|
||||
<p className="text-sm text-text-muted">{e("notMatchedHint")}</p>
|
||||
)}
|
||||
{[...simulationErrors, ...(decision?.warnings || [])].map((warning, index) => (
|
||||
<p key={index} className="text-sm text-amber-600">
|
||||
<p key={index} className="text-sm text-warning">
|
||||
{String(warning)}
|
||||
</p>
|
||||
))}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
"use client";
|
||||
|
||||
import { cn } from "@/shared/utils/cn";
|
||||
import Button from "./Button";
|
||||
import Icon from "./Icon";
|
||||
|
||||
interface ReorderControlProps {
|
||||
onMoveUp?: () => void;
|
||||
@@ -22,37 +24,31 @@ export default function ReorderControl({
|
||||
downLabel = "Move down",
|
||||
className,
|
||||
}: ReorderControlProps) {
|
||||
const btn = (disabled: boolean) =>
|
||||
cn(
|
||||
"flex size-5 items-center justify-center rounded",
|
||||
disabled
|
||||
? "cursor-not-allowed text-text-muted/30"
|
||||
: "text-text-muted hover:bg-sidebar hover:text-primary"
|
||||
);
|
||||
// Compact (20px) kit ghost icon buttons: the kit's min-height is reset so the pair stays
|
||||
// the height of one list row.
|
||||
const btn = "size-5 min-h-5 min-w-5 rounded text-text-muted hover:text-primary";
|
||||
return (
|
||||
<div className={cn("flex shrink-0 flex-col", className)}>
|
||||
<button
|
||||
type="button"
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon-sm"
|
||||
onClick={onMoveUp}
|
||||
disabled={isFirst}
|
||||
aria-label={upLabel}
|
||||
className={btn(isFirst)}
|
||||
className={btn}
|
||||
>
|
||||
<span className="material-symbols-outlined text-[18px] leading-none">
|
||||
keyboard_arrow_up
|
||||
</span>
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
<Icon name="keyboard_arrow_up" size={18} />
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon-sm"
|
||||
onClick={onMoveDown}
|
||||
disabled={isLast}
|
||||
aria-label={downLabel}
|
||||
className={btn(isLast)}
|
||||
className={btn}
|
||||
>
|
||||
<span className="material-symbols-outlined text-[18px] leading-none">
|
||||
keyboard_arrow_down
|
||||
</span>
|
||||
</button>
|
||||
<Icon name="keyboard_arrow_down" size={18} />
|
||||
</Button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -13,6 +13,9 @@ import {
|
||||
} from "@/shared/hooks/useTimestampTitles";
|
||||
import { JsonTreeExpandControls } from "@/shared/components/JsonTreeExpandControls";
|
||||
import { useJsonTreeExpandLevel } from "@/store/jsonTreeExpandStore";
|
||||
import { cn } from "@/shared/utils/cn";
|
||||
import Button from "./Button";
|
||||
import Icon from "./Icon";
|
||||
import {
|
||||
isPipelineSizeLimitMarker,
|
||||
isSizeLimitOmissionMarker,
|
||||
@@ -111,43 +114,44 @@ export function PayloadSection({
|
||||
{title}
|
||||
</h3>
|
||||
{collapsible && (
|
||||
<button
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon-sm"
|
||||
onClick={() => setOpen((v) => !v)}
|
||||
className="p-1 rounded hover:bg-bg-subtle text-text-muted hover:text-text-primary transition-colors"
|
||||
className="size-6 min-h-6 text-text-muted"
|
||||
aria-expanded={open}
|
||||
aria-label={open ? t("collapse", { title }) : t("expand", { title })}
|
||||
>
|
||||
<span className="material-symbols-outlined text-[16px]">
|
||||
{open ? "expand_less" : "expand_more"}
|
||||
</span>
|
||||
</button>
|
||||
<Icon name={open ? "expand_less" : "expand_more"} size={16} />
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
{!notice && (
|
||||
<button
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={handleCopy}
|
||||
className="flex items-center gap-1 px-2 py-1 text-xs text-text-muted hover:text-text-primary transition-colors"
|
||||
className="h-7 min-h-7 px-2 text-xs text-text-muted"
|
||||
aria-label={t("copyTitle", { title })}
|
||||
>
|
||||
<span className="material-symbols-outlined text-[14px]">
|
||||
{copied ? "check" : "content_copy"}
|
||||
</span>
|
||||
<Icon name={copied ? "check" : "content_copy"} size={14} />
|
||||
{copied ? t("copied") : t("copy")}
|
||||
</button>
|
||||
</Button>
|
||||
)}
|
||||
{parsedJson !== null && <JsonTreeExpandControls sectionId={resolvedSectionId} />}
|
||||
</div>
|
||||
</div>
|
||||
{open && notice && (
|
||||
<div className="p-4 rounded-xl border border-amber-500/40 bg-amber-500/10 text-xs text-amber-700 dark:text-amber-300 flex items-start gap-2">
|
||||
<span className="material-symbols-outlined text-[16px] shrink-0">warning</span>
|
||||
<div className="flex items-start gap-2 rounded-xl border border-warning/40 bg-warning/10 p-4 text-xs text-warning">
|
||||
<Icon name="warning" size={16} />
|
||||
<span>{t("payloadSizeLimitOmitted")}</span>
|
||||
</div>
|
||||
)}
|
||||
{open && !notice && parsedJson !== null && (
|
||||
<div
|
||||
ref={treeContainerRef}
|
||||
className="rounded-xl bg-black/5 dark:bg-black/30 border border-border max-h-150 overflow-auto p-4 text-xs font-mono"
|
||||
className="max-h-150 overflow-auto rounded-xl border border-border bg-surface-2 p-4 font-mono text-xs"
|
||||
>
|
||||
<JsonView
|
||||
src={parsedJson}
|
||||
@@ -159,7 +163,7 @@ export function PayloadSection({
|
||||
</div>
|
||||
)}
|
||||
{open && !notice && parsedJson === null && (
|
||||
<pre className="p-4 rounded-xl bg-black/5 dark:bg-black/30 border border-border overflow-x-auto text-xs font-mono text-text-main max-h-150 overflow-y-auto leading-relaxed whitespace-pre-wrap break-words">
|
||||
<pre className="max-h-150 overflow-x-auto overflow-y-auto whitespace-pre-wrap break-words rounded-xl border border-border bg-surface-2 p-4 font-mono text-xs leading-relaxed text-text-main">
|
||||
{json}
|
||||
</pre>
|
||||
)}
|
||||
@@ -196,6 +200,7 @@ function asInterceptedResponseBody(responseBody: unknown): InterceptedRequest {
|
||||
}
|
||||
|
||||
export function ConversationContextSection({ log, detail }) {
|
||||
const t = useTranslations("requestLogger.detail");
|
||||
const [open, setOpen] = useState(true);
|
||||
const [liveDetail, setLiveDetail] = useState(detail);
|
||||
const [liveRefresh, setLiveRefresh] = useState(() => {
|
||||
@@ -301,17 +306,22 @@ export function ConversationContextSection({ log, detail }) {
|
||||
<div className="flex items-center justify-between gap-3 mb-2">
|
||||
<div className="flex items-center gap-3">
|
||||
<h3 className="text-[11px] text-text-muted uppercase tracking-wider font-bold">
|
||||
Conversation Context
|
||||
{t("conversationContext")}
|
||||
</h3>
|
||||
<button
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon-sm"
|
||||
onClick={() => setOpen((v) => !v)}
|
||||
className="p-1 rounded hover:bg-bg-subtle text-text-muted hover:text-text-primary transition-colors"
|
||||
aria-label={open ? "Collapse Conversation Context" : "Expand Conversation Context"}
|
||||
className="size-6 min-h-6 text-text-muted"
|
||||
aria-expanded={open}
|
||||
aria-label={
|
||||
open
|
||||
? t("collapse", { title: t("conversationContext") })
|
||||
: t("expand", { title: t("conversationContext") })
|
||||
}
|
||||
>
|
||||
<span className="material-symbols-outlined text-[16px]">
|
||||
{open ? "expand_less" : "expand_more"}
|
||||
</span>
|
||||
</button>
|
||||
<Icon name={open ? "expand_less" : "expand_more"} size={16} />
|
||||
</Button>
|
||||
{liveDetail?.parentLogId && (
|
||||
// Full navigation, not client-side routing: the logs page only reads
|
||||
// ?id from a fresh mount (useState(() => searchParams.get("id")) in
|
||||
@@ -320,10 +330,10 @@ export function ConversationContextSection({ log, detail }) {
|
||||
<a
|
||||
href={`/dashboard/logs?id=${encodeURIComponent(liveDetail.parentLogId)}`}
|
||||
className="flex items-center gap-1 text-[11px] text-text-muted hover:text-primary transition-colors"
|
||||
title={`Continues from ${liveDetail.parentLogId}`}
|
||||
title={t("continuesFrom", { id: liveDetail.parentLogId })}
|
||||
>
|
||||
<span className="material-symbols-outlined text-[14px]">reply</span>
|
||||
continues from parent
|
||||
<Icon name="reply" size={14} />
|
||||
{t("continuesFromParent")}
|
||||
</a>
|
||||
)}
|
||||
{liveDetail?.sessionTag && (
|
||||
@@ -335,42 +345,47 @@ export function ConversationContextSection({ log, detail }) {
|
||||
<a
|
||||
href={`/dashboard/conversations?tree=${encodeURIComponent(liveDetail.sessionTag)}`}
|
||||
className="flex items-center gap-1 text-[11px] text-text-muted hover:text-primary transition-colors"
|
||||
title={`Open conversation ${liveDetail.sessionTag}`}
|
||||
title={t("openConversation", { id: liveDetail.sessionTag })}
|
||||
>
|
||||
<span className="material-symbols-outlined text-[14px]">forum</span>
|
||||
view conversation
|
||||
<Icon name="forum" size={14} />
|
||||
{t("viewConversation")}
|
||||
</a>
|
||||
)}
|
||||
</div>
|
||||
{open && (
|
||||
<div className="flex items-center gap-1">
|
||||
{liveDetail?.active && (
|
||||
<button
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon-sm"
|
||||
onClick={toggleLiveRefresh}
|
||||
title={liveRefresh ? "Live refresh: on" : "Live refresh: off"}
|
||||
className={`p-1 rounded hover:bg-bg-subtle text-text-muted hover:text-text-primary transition-colors ${liveRefresh ? "text-primary" : ""}`}
|
||||
title={liveRefresh ? t("liveRefreshOn") : t("liveRefreshOff")}
|
||||
// Static name + aria-pressed carries the on/off state ("Live refresh, pressed");
|
||||
// the stateful wording stays in the tooltip.
|
||||
aria-label={t("liveRefresh")}
|
||||
className={cn("size-7 min-h-7", liveRefresh ? "text-primary" : "text-text-muted")}
|
||||
aria-pressed={liveRefresh}
|
||||
>
|
||||
<span className="material-symbols-outlined text-[18px]">
|
||||
{liveRefresh ? "sync" : "sync_disabled"}
|
||||
</span>
|
||||
</button>
|
||||
<Icon name={liveRefresh ? "sync" : "sync_disabled"} size={18} />
|
||||
</Button>
|
||||
)}
|
||||
<button
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon-sm"
|
||||
onClick={scrollToBottom}
|
||||
title="Go to bottom"
|
||||
className="p-1 rounded hover:bg-bg-subtle text-text-muted hover:text-text-primary transition-colors"
|
||||
aria-label="Go to bottom"
|
||||
title={t("goToBottom")}
|
||||
className="size-7 min-h-7 text-text-muted"
|
||||
aria-label={t("goToBottom")}
|
||||
>
|
||||
<span className="material-symbols-outlined text-[18px]">vertical_align_bottom</span>
|
||||
</button>
|
||||
<Icon name="vertical_align_bottom" size={18} />
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
{open && (
|
||||
<div
|
||||
ref={turnsBoxRef}
|
||||
className="rounded-xl bg-black/5 dark:bg-black/30 border border-border max-h-150 overflow-y-auto p-3 space-y-2"
|
||||
className="max-h-150 space-y-2 overflow-y-auto rounded-xl border border-border bg-surface-2 p-3"
|
||||
>
|
||||
{allTurns.map((turn, i) => (
|
||||
<ChatBubble key={i} turn={turn} />
|
||||
|
||||
@@ -3,11 +3,7 @@
|
||||
import { useState, useEffect, useMemo, useRef } from "react";
|
||||
import { useLocale, useTranslations } from "next-intl";
|
||||
import { JsonView } from "@/shared/components/jsonView";
|
||||
import {
|
||||
PROVIDER_COLORS,
|
||||
getHttpStatusStyle as getStatusStyle,
|
||||
getProtocolColor,
|
||||
} from "@/shared/constants/colors";
|
||||
import { PROVIDER_COLORS, getProtocolColor } from "@/shared/constants/colors";
|
||||
import { formatDuration, formatApiKeyLabel, maskAccount } from "@/shared/utils/formatting";
|
||||
import { formatErrorForDisplay, formatReasoningStat } from "@/shared/utils/formatting";
|
||||
import { useTheme } from "@/shared/hooks/useTheme";
|
||||
@@ -25,6 +21,19 @@ import {
|
||||
isBodySizeLimitOmission,
|
||||
} from "@/shared/components/RequestLoggerDetail.sections";
|
||||
import { getResilienceBadges } from "@/shared/components/requestLoggerResilience";
|
||||
import { cn } from "@/shared/utils/cn";
|
||||
import Badge from "./Badge";
|
||||
import Button from "./Button";
|
||||
import Icon from "./Icon";
|
||||
|
||||
// HTTP status → kit Badge tone (2xx success, 4xx warning, 5xx error).
|
||||
function httpStatusTone(status: number) {
|
||||
if (status >= 200 && status < 300) return "success" as const;
|
||||
if (status >= 400 && status < 500) return "warning" as const;
|
||||
if (status >= 500) return "error" as const;
|
||||
if (status === 0) return "info" as const;
|
||||
return "default" as const;
|
||||
}
|
||||
|
||||
// ─── Copy-all composition ────────────────────────────────────────────────────
|
||||
// Compose every visible payload section + stream chunk into a single block so
|
||||
@@ -244,44 +253,50 @@ function StreamSection({ title, sectionId, json, onCopy }) {
|
||||
<h3 className="text-[11px] text-text-muted uppercase tracking-wider font-bold">
|
||||
{title}
|
||||
</h3>
|
||||
<button
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon-sm"
|
||||
onClick={() => setOpen((v) => !v)}
|
||||
className="p-1 rounded hover:bg-bg-subtle text-text-muted hover:text-text-primary transition-colors"
|
||||
className="size-6 min-h-6 text-text-muted"
|
||||
aria-expanded={open}
|
||||
aria-label={open ? t("collapse", { title }) : t("expand", { title })}
|
||||
>
|
||||
<span className="material-symbols-outlined text-[16px]">
|
||||
{open ? "expand_less" : "expand_more"}
|
||||
</span>
|
||||
</button>
|
||||
<Icon name={open ? "expand_less" : "expand_more"} size={16} />
|
||||
</Button>
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<button
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon-sm"
|
||||
onClick={toggleRaw}
|
||||
title={showRaw ? t("rawViewOn") : t("rawViewOff")}
|
||||
aria-label={showRaw ? t("rawViewOn") : t("rawViewOff")}
|
||||
className={`p-1 rounded hover:bg-bg-subtle text-text-muted hover:text-text-primary transition-colors ${showRaw ? "text-primary" : ""}`}
|
||||
className={cn("size-7 min-h-7", showRaw ? "text-primary" : "text-text-muted")}
|
||||
aria-pressed={showRaw}
|
||||
>
|
||||
<span className="material-symbols-outlined text-[18px]">code</span>
|
||||
</button>
|
||||
<button
|
||||
<Icon name="code" size={18} />
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon-sm"
|
||||
onClick={toggleAutoscroll}
|
||||
title={autoscroll ? t("autoscrollOn") : t("autoscrollOff")}
|
||||
className={`p-1 rounded hover:bg-bg-subtle text-text-muted hover:text-text-primary transition-colors ${autoscroll ? "text-primary" : ""}`}
|
||||
aria-label={autoscroll ? t("autoscrollOn") : t("autoscrollOff")}
|
||||
className={cn("size-7 min-h-7", autoscroll ? "text-primary" : "text-text-muted")}
|
||||
aria-pressed={autoscroll}
|
||||
>
|
||||
<span className="material-symbols-outlined text-[18px]">vertical_align_bottom</span>
|
||||
</button>
|
||||
<button
|
||||
<Icon name="vertical_align_bottom" size={18} />
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={handleCopy}
|
||||
className="flex items-center gap-1 px-2 py-1 text-xs text-text-muted hover:text-text-primary transition-colors"
|
||||
className="h-7 min-h-7 px-2 text-xs text-text-muted"
|
||||
aria-label={t("copyTitle", { title })}
|
||||
>
|
||||
<span className="material-symbols-outlined text-[14px]">
|
||||
{copied ? "check" : "content_copy"}
|
||||
</span>
|
||||
<Icon name={copied ? "check" : "content_copy"} size={14} />
|
||||
{copied ? t("copied") : t("copy")}
|
||||
</button>
|
||||
</Button>
|
||||
{!showRaw && segments.some((s) => s.type === "json") && (
|
||||
<JsonTreeExpandControls sectionId={resolvedSectionId} />
|
||||
)}
|
||||
@@ -290,7 +305,7 @@ function StreamSection({ title, sectionId, json, onCopy }) {
|
||||
{open && (
|
||||
<div
|
||||
ref={ref}
|
||||
className="p-4 rounded-xl bg-black/5 dark:bg-black/30 border border-border overflow-x-auto text-xs font-mono text-text-main max-h-150 overflow-y-auto leading-relaxed"
|
||||
className="max-h-150 overflow-x-auto overflow-y-auto rounded-xl border border-border bg-surface-2 p-4 font-mono text-xs leading-relaxed text-text-main"
|
||||
>
|
||||
{showRaw ? (
|
||||
<pre className="whitespace-pre-wrap break-words">{json}</pre>
|
||||
@@ -390,7 +405,6 @@ export default function RequestLoggerDetail({
|
||||
e.preventDefault();
|
||||
};
|
||||
|
||||
const statusStyle = getStatusStyle(log.status);
|
||||
const protocolKey = log.sourceFormat || log.provider;
|
||||
const protocol = getProtocolColor(protocolKey, log.provider);
|
||||
const providerColor = PROVIDER_COLORS[log.provider] || {
|
||||
@@ -549,8 +563,8 @@ export default function RequestLoggerDetail({
|
||||
const cacheSourceLabel = cacheSource === "semantic" ? t("semanticCache") : t("upstreamCache");
|
||||
const cacheSourceClassName =
|
||||
cacheSource === "semantic"
|
||||
? "bg-emerald-500/20 text-emerald-700 dark:text-emerald-300 border-emerald-500/30"
|
||||
: "bg-sky-500/20 text-sky-700 dark:text-sky-300 border-sky-500/30";
|
||||
? "bg-success/20 text-success border-success/30"
|
||||
: "bg-info/20 text-info border-info/30";
|
||||
// resilience badges (flag alone decides, whatever the status).
|
||||
const resilienceBadges = getResilienceBadges(
|
||||
log.resilienceActions || detail?.resilienceActions || null,
|
||||
@@ -567,7 +581,7 @@ export default function RequestLoggerDetail({
|
||||
aria-modal="true"
|
||||
aria-label={t("ariaLabel")}
|
||||
>
|
||||
<div className="absolute inset-0 bg-black/60 backdrop-blur-sm" />
|
||||
<div className="absolute inset-0 bg-[var(--ci-color-overlay)] backdrop-blur-sm" />
|
||||
<div
|
||||
ref={modalScrollRef}
|
||||
className="relative w-full max-w-225 max-h-[90vh] overflow-x-hidden overflow-y-auto rounded-xl border border-border bg-bg-primary shadow-2xl"
|
||||
@@ -579,20 +593,17 @@ export default function RequestLoggerDetail({
|
||||
<div className="flex flex-col">
|
||||
<div className="flex items-center gap-2">
|
||||
{log.active ? (
|
||||
<span className="inline-flex items-center gap-1.5 px-2.5 py-1 rounded text-xs font-bold bg-amber-500/20 text-amber-600 dark:text-amber-400 border border-amber-500/30">
|
||||
<span className="inline-flex items-center gap-1.5 px-2.5 py-1 rounded text-xs font-bold bg-warning/20 text-warning border border-warning/30">
|
||||
<span className="inline-block h-3 w-3 rounded-full border-2 border-current border-t-transparent animate-spin" />
|
||||
</span>
|
||||
) : log.status === 0 ? (
|
||||
<span className="inline-block px-2.5 py-1 rounded text-xs font-bold bg-emerald-500/20 text-emerald-700 dark:text-emerald-300 border border-emerald-500/30">
|
||||
<span className="inline-block px-2.5 py-1 rounded text-xs font-bold bg-success/20 text-success border border-success/30">
|
||||
{t("completed")}
|
||||
</span>
|
||||
) : (
|
||||
<span
|
||||
className="inline-block px-2.5 py-1 rounded text-xs font-bold"
|
||||
style={{ backgroundColor: statusStyle.bg, color: statusStyle.text }}
|
||||
>
|
||||
<Badge variant={httpStatusTone(log.status)} className="font-bold">
|
||||
{log.status}
|
||||
</span>
|
||||
</Badge>
|
||||
)}
|
||||
{hasStatusDiscrepancy && (
|
||||
<span className="text-[10px] font-bold px-2 py-0.5 rounded bg-bg-subtle border border-border text-text-muted">
|
||||
@@ -602,7 +613,7 @@ export default function RequestLoggerDetail({
|
||||
{log.method && <span className="font-bold text-lg">{log.method}</span>}
|
||||
</div>
|
||||
{hasStatusDiscrepancy && (
|
||||
<span className="text-[10px] text-amber-600 dark:text-amber-400 font-medium mt-0.5">
|
||||
<span className="text-[10px] text-warning font-medium mt-0.5">
|
||||
{t("statusDiscrepancy", { status: log.status, provider: providerStatus })}
|
||||
</span>
|
||||
)}
|
||||
@@ -623,50 +634,56 @@ export default function RequestLoggerDetail({
|
||||
)}
|
||||
</div>
|
||||
<div className="flex items-center gap-1 shrink-0">
|
||||
<button
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={handleCopyAll}
|
||||
className="flex items-center gap-1.5 px-2.5 py-1.5 rounded-lg hover:bg-bg-subtle text-text-muted hover:text-text-primary transition-colors"
|
||||
className="text-text-muted"
|
||||
aria-label={t("copyAll")}
|
||||
title={t("copyAll")}
|
||||
>
|
||||
<span className="material-symbols-outlined text-[16px]">
|
||||
{copiedAll ? "check" : "content_copy"}
|
||||
</span>
|
||||
<Icon name={copiedAll ? "check" : "content_copy"} size={16} />
|
||||
<span className="text-xs font-medium">
|
||||
{copiedAll ? t("copiedAll") : t("copyAll")}
|
||||
</span>
|
||||
</button>
|
||||
</Button>
|
||||
{/* Only rendered when a caller actually wires up navigation (RequestLoggerV2's
|
||||
list view) — a caller with no ordered-list context to navigate through
|
||||
(conversations page, RequestTimeline) passes neither, so there's nothing
|
||||
to show instead of a permanently-disabled dead button. */}
|
||||
{(onPrevious || onNext) && (
|
||||
<>
|
||||
<button
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon-sm"
|
||||
onClick={onPrevious}
|
||||
disabled={!onPrevious}
|
||||
className="p-1.5 rounded-lg hover:bg-bg-subtle text-text-muted hover:text-text-primary transition-colors disabled:opacity-30 disabled:pointer-events-none"
|
||||
className="text-text-muted"
|
||||
aria-label={t("previousRequest")}
|
||||
>
|
||||
<span className="material-symbols-outlined text-[18px]">chevron_left</span>
|
||||
</button>
|
||||
<button
|
||||
<Icon name="chevron_left" size={18} />
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon-sm"
|
||||
onClick={onNext}
|
||||
disabled={!onNext}
|
||||
className="p-1.5 rounded-lg hover:bg-bg-subtle text-text-muted hover:text-text-primary transition-colors disabled:opacity-30 disabled:pointer-events-none"
|
||||
className="text-text-muted"
|
||||
aria-label={t("nextRequest")}
|
||||
>
|
||||
<span className="material-symbols-outlined text-[18px]">chevron_right</span>
|
||||
</button>
|
||||
<Icon name="chevron_right" size={18} />
|
||||
</Button>
|
||||
</>
|
||||
)}
|
||||
<button
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon-sm"
|
||||
onClick={onClose}
|
||||
className="p-1.5 rounded-lg hover:bg-bg-subtle text-text-muted hover:text-text-primary transition-colors"
|
||||
className="text-text-muted"
|
||||
aria-label={t("close")}
|
||||
>
|
||||
<span className="material-symbols-outlined">close</span>
|
||||
</button>
|
||||
<Icon name="close" />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -775,10 +792,10 @@ export default function RequestLoggerDetail({
|
||||
<span className="px-2 py-0.5 rounded bg-primary/20 text-primary text-xs font-bold">
|
||||
{t("totalIn", { value: formatTokenValue(tokenStats.totalIn) })}
|
||||
</span>
|
||||
<span className="px-2 py-0.5 rounded bg-sky-500/20 text-sky-700 dark:text-sky-400 text-xs font-bold">
|
||||
<span className="px-2 py-0.5 rounded bg-info/20 text-info text-xs font-bold">
|
||||
{t("cacheRead", { value: formatTokenValue(tokenStats.cacheRead) })}
|
||||
</span>
|
||||
<span className="px-2 py-0.5 rounded bg-amber-500/20 text-amber-700 dark:text-amber-400 text-xs font-bold">
|
||||
<span className="px-2 py-0.5 rounded bg-warning/20 text-warning text-xs font-bold">
|
||||
{t("cacheWrite", { value: formatTokenValue(tokenStats.cacheWrite) })}
|
||||
</span>
|
||||
{tokenStats.compressed != null &&
|
||||
@@ -791,7 +808,7 @@ export default function RequestLoggerDetail({
|
||||
? Math.max(0, Math.min(100, Math.round((saved / fromTokens) * 100)))
|
||||
: 100;
|
||||
return (
|
||||
<span className="px-2 py-0.5 rounded bg-purple-500/20 text-purple-700 dark:text-purple-300 text-xs font-bold">
|
||||
<span className="px-2 py-0.5 rounded bg-chart-3/20 text-chart-3 text-xs font-bold">
|
||||
{t("compressed", {
|
||||
from: fromTokens.toLocaleString(),
|
||||
to: Math.max(0, tokenStats.totalIn).toLocaleString(),
|
||||
@@ -810,10 +827,10 @@ export default function RequestLoggerDetail({
|
||||
className="flex flex-wrap items-center gap-1.5"
|
||||
data-testid="token-group-output"
|
||||
>
|
||||
<span className="px-2 py-0.5 rounded bg-emerald-500/20 text-emerald-700 dark:text-emerald-400 text-xs font-bold">
|
||||
<span className="px-2 py-0.5 rounded bg-success/20 text-success text-xs font-bold">
|
||||
{t("totalOut", { value: formatTokenValue(tokenStats.totalOut) })}
|
||||
</span>
|
||||
<span className="px-2 py-0.5 rounded bg-violet-500/20 text-violet-700 dark:text-violet-400 text-xs font-bold">
|
||||
<span className="px-2 py-0.5 rounded bg-chart-3/20 text-chart-3 text-xs font-bold">
|
||||
{t("reasoning", { value: formatReasoningStat(tokenStats, t) })}
|
||||
</span>
|
||||
</div>
|
||||
@@ -832,7 +849,7 @@ export default function RequestLoggerDetail({
|
||||
className={`text-sm font-medium font-mono ${
|
||||
(detail?.requestedModel || log.requestedModel) &&
|
||||
(detail?.requestedModel || log.requestedModel) !== log.model
|
||||
? "text-amber-600 dark:text-amber-400"
|
||||
? "text-warning"
|
||||
: "text-text-muted"
|
||||
}`}
|
||||
>
|
||||
@@ -885,10 +902,8 @@ export default function RequestLoggerDetail({
|
||||
<div className="text-[10px] text-text-muted uppercase tracking-wider mb-1">
|
||||
{t("modelPinning")}
|
||||
</div>
|
||||
<span className="inline-flex items-center gap-1 px-2.5 py-1 rounded text-[10px] font-bold bg-violet-500/15 text-violet-600 dark:text-violet-400 border border-violet-500/25">
|
||||
<svg className="w-3 h-3" viewBox="0 0 16 16" fill="currentColor">
|
||||
<path d="M4.5 2A1.5 1.5 0 003 3.5v1.9l-1.4 2.8A.5.5 0 002 9h4v4.5a.5.5 0 00.5.5h3a.5.5 0 00.5-.5V9h4a.5.5 0 00.44-.73L13 5.4V3.5A1.5 1.5 0 0011.5 2h-7z" />
|
||||
</svg>
|
||||
<span className="inline-flex items-center gap-1 px-2.5 py-1 rounded text-[10px] font-bold bg-chart-3/15 text-chart-3 border border-chart-3/25">
|
||||
<Icon name="push_pin" size={12} />
|
||||
{t("activeModelPinning")}
|
||||
</span>
|
||||
</div>
|
||||
@@ -900,7 +915,7 @@ export default function RequestLoggerDetail({
|
||||
<div className="text-sm font-medium">{accountLabel}</div>
|
||||
{codexAccountRotation && (
|
||||
<div
|
||||
className="mt-1 text-[10px] text-amber-600 dark:text-amber-400 font-mono"
|
||||
className="mt-1 text-[10px] text-warning font-mono"
|
||||
title={`${codexAccountRotation.initialConnectionId} -> ${codexAccountRotation.finalConnectionId}`}
|
||||
>
|
||||
{t("rotated", {
|
||||
@@ -935,7 +950,7 @@ export default function RequestLoggerDetail({
|
||||
{t("combo")}
|
||||
</div>
|
||||
{detail?.comboName || log.comboName ? (
|
||||
<span className="inline-block px-2.5 py-1 rounded-full text-[10px] font-bold bg-violet-500/20 text-violet-700 dark:text-violet-300 border border-violet-500/30">
|
||||
<span className="inline-block px-2.5 py-1 rounded-full text-[10px] font-bold bg-chart-3/20 text-chart-3 border border-chart-3/30">
|
||||
{detail?.comboName || log.comboName}
|
||||
</span>
|
||||
) : (
|
||||
@@ -944,7 +959,7 @@ export default function RequestLoggerDetail({
|
||||
</div>
|
||||
<div>
|
||||
<div className="text-[10px] text-text-muted uppercase tracking-wider mb-1">
|
||||
Conversation
|
||||
{tColumns("conversation")}
|
||||
</div>
|
||||
{detail?.sessionTag || log.sessionTag ? (
|
||||
<div
|
||||
@@ -963,93 +978,49 @@ export default function RequestLoggerDetail({
|
||||
|
||||
{/* Error Message */}
|
||||
{(detail?.error || log.error) && (
|
||||
<div className="p-4 rounded-xl bg-red-500/10 border border-red-500/30">
|
||||
<div className="p-4 rounded-xl bg-error/10 border border-error/30">
|
||||
<div className="flex items-center justify-between mb-1">
|
||||
<div className="text-[10px] text-red-600 dark:text-red-400 uppercase tracking-wider font-bold">
|
||||
<div className="text-[10px] text-error uppercase tracking-wider font-bold">
|
||||
{t("error")}
|
||||
</div>
|
||||
{isCombo503 && !cleared && (
|
||||
<button
|
||||
<Button
|
||||
variant="warning"
|
||||
size="sm"
|
||||
onClick={handleUnblockAll}
|
||||
disabled={unblockAllBusy}
|
||||
className="flex items-center gap-1 px-2.5 py-1 text-[10px] font-medium rounded-lg
|
||||
bg-amber-500/10 border border-amber-500/30 text-amber-600
|
||||
hover:bg-amber-500/15 hover:border-amber-500/50
|
||||
dark:text-amber-400 transition-all duration-200
|
||||
disabled:opacity-50 disabled:cursor-not-allowed"
|
||||
className="h-7 min-h-7 px-2.5 text-[10px]"
|
||||
>
|
||||
<svg
|
||||
width="12"
|
||||
height="12"
|
||||
viewBox="0 0 16 16"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="1.5"
|
||||
>
|
||||
<rect x="3" y="6" width="10" height="8" rx="1" />
|
||||
<path d="M5 6V4a3 3 0 0 1 3-3h0a3 3 0 0 1 3 3v1" />
|
||||
<circle cx="8" cy="10" r="1" fill="currentColor" stroke="none" />
|
||||
</svg>
|
||||
<Icon name="lock_open" size={12} />
|
||||
{unblockAllBusy ? "..." : t("unblockAll")}
|
||||
</button>
|
||||
</Button>
|
||||
)}
|
||||
{isCombo503 && cleared && (
|
||||
<span className="flex items-center gap-1 px-2.5 py-1 text-[10px] font-medium rounded-lg bg-green-500/10 border border-green-500/30 text-green-600 dark:text-green-400">
|
||||
<svg
|
||||
width="10"
|
||||
height="10"
|
||||
viewBox="0 0 16 16"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="2"
|
||||
>
|
||||
<polyline points="4 8 7 11 12 4" />
|
||||
</svg>
|
||||
<span className="flex items-center gap-1 px-2.5 py-1 text-[10px] font-medium rounded-lg bg-success/10 border border-success/30 text-success">
|
||||
<Icon name="check" size={10} />
|
||||
{t("cleared")}
|
||||
</span>
|
||||
)}
|
||||
{isModelCooldown && !cleared && (
|
||||
<button
|
||||
<Button
|
||||
variant="warning"
|
||||
size="sm"
|
||||
onClick={handleUnblockModel}
|
||||
disabled={unblocking}
|
||||
className="flex items-center gap-1 px-2.5 py-1 text-[10px] font-medium rounded-lg
|
||||
bg-amber-500/10 border border-amber-500/30 text-amber-600
|
||||
hover:bg-amber-500/15 hover:border-amber-500/50
|
||||
dark:text-amber-400 transition-all duration-200
|
||||
disabled:opacity-50 disabled:cursor-not-allowed"
|
||||
className="h-7 min-h-7 px-2.5 text-[10px]"
|
||||
>
|
||||
<svg
|
||||
width="12"
|
||||
height="12"
|
||||
viewBox="0 0 16 16"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="1.5"
|
||||
>
|
||||
<rect x="3" y="6" width="10" height="8" rx="1" />
|
||||
<path d="M5 6V4a3 3 0 0 1 3-3h0a3 3 0 0 1 3 3v1" />
|
||||
<circle cx="8" cy="10" r="1" fill="currentColor" stroke="none" />
|
||||
</svg>
|
||||
<Icon name="lock_open" size={12} />
|
||||
{unblocking ? "..." : t("unblock")}
|
||||
</button>
|
||||
</Button>
|
||||
)}
|
||||
{isModelCooldown && cleared && (
|
||||
<span className="flex items-center gap-1 px-2.5 py-1 text-[10px] font-medium rounded-lg bg-green-500/10 border border-green-500/30 text-green-600 dark:text-green-400">
|
||||
<svg
|
||||
width="10"
|
||||
height="10"
|
||||
viewBox="0 0 16 16"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="2"
|
||||
>
|
||||
<polyline points="4 8 7 11 12 4" />
|
||||
</svg>
|
||||
<span className="flex items-center gap-1 px-2.5 py-1 text-[10px] font-medium rounded-lg bg-success/10 border border-success/30 text-success">
|
||||
<Icon name="check" size={10} />
|
||||
{t("cleared")}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
<div className="text-sm text-red-600 dark:text-red-300 font-mono whitespace-pre-wrap break-words">
|
||||
<div className="text-sm text-error font-mono whitespace-pre-wrap break-words">
|
||||
{formatErrorForDisplay(detail?.error || log.error)}
|
||||
</div>
|
||||
</div>
|
||||
@@ -1069,30 +1040,28 @@ export default function RequestLoggerDetail({
|
||||
return aStart - bStart;
|
||||
})
|
||||
.map((r) => {
|
||||
const rStatusStyle = r.active ? null : getStatusStyle(r.status);
|
||||
const isCurrent = r.id === log.id;
|
||||
const startTime = new Date(new Date(r.timestamp).getTime() - (r.duration || 0));
|
||||
return (
|
||||
<button
|
||||
<Button
|
||||
key={r.id}
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={() => !isCurrent && onSelectRelated?.(r)}
|
||||
disabled={isCurrent}
|
||||
className={`flex items-center gap-2 px-2 py-1.5 rounded text-left text-xs transition-colors ${
|
||||
isCurrent
|
||||
? "bg-primary/10 border border-primary/30 cursor-default"
|
||||
: "hover:bg-bg-hover cursor-pointer"
|
||||
}`}
|
||||
aria-current={isCurrent ? "true" : undefined}
|
||||
className={cn(
|
||||
"h-auto w-full justify-start gap-2 px-2 py-1.5 text-left text-xs font-normal",
|
||||
isCurrent && "border border-primary/30 bg-primary/10 disabled:opacity-100"
|
||||
)}
|
||||
>
|
||||
<span
|
||||
className="inline-block px-1.5 py-0.5 rounded text-[9px] font-bold min-w-[28px] text-center"
|
||||
style={
|
||||
rStatusStyle
|
||||
? { backgroundColor: rStatusStyle.bg, color: rStatusStyle.text }
|
||||
: { backgroundColor: "#374151", color: "#fff" }
|
||||
}
|
||||
<Badge
|
||||
size="sm"
|
||||
variant={r.active ? "default" : httpStatusTone(r.status)}
|
||||
className="min-w-[28px] justify-center text-[9px] font-bold"
|
||||
>
|
||||
{r.status || "..."}
|
||||
</span>
|
||||
</Badge>
|
||||
<span className="font-mono text-text-muted">{r.id}</span>
|
||||
<span className="text-text-muted">{r.model}</span>
|
||||
<span className="text-text-muted text-[10px]">
|
||||
@@ -1106,7 +1075,7 @@ export default function RequestLoggerDetail({
|
||||
{t("current")}
|
||||
</span>
|
||||
)}
|
||||
</button>
|
||||
</Button>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
@@ -1114,11 +1083,11 @@ export default function RequestLoggerDetail({
|
||||
)}
|
||||
|
||||
{detailIssue && (
|
||||
<div className="p-4 rounded-xl bg-amber-500/10 border border-amber-500/30">
|
||||
<div className="text-[10px] text-amber-700 dark:text-amber-400 uppercase tracking-wider mb-1 font-bold">
|
||||
<div className="p-4 rounded-xl bg-warning/10 border border-warning/30">
|
||||
<div className="text-[10px] text-warning uppercase tracking-wider mb-1 font-bold">
|
||||
{t("detailStatus")}
|
||||
</div>
|
||||
<div className="text-sm text-amber-700 dark:text-amber-200">{detailIssue}</div>
|
||||
<div className="text-sm text-warning">{detailIssue}</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
@@ -1224,9 +1193,7 @@ export default function RequestLoggerDetail({
|
||||
|
||||
{payloadSections.length === 0 && !requestJson && !responseJson && !loading && (
|
||||
<div className="p-6 text-center text-text-muted">
|
||||
<span className="material-symbols-outlined text-[32px] mb-2 block opacity-40">
|
||||
info
|
||||
</span>
|
||||
<Icon name="info" size={32} className="mb-2 block opacity-40" />
|
||||
<p className="text-sm">{t("noPayload")}</p>
|
||||
<p className="text-xs mt-1">{t("detailedPayloadInfo")}</p>
|
||||
</div>
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -7,6 +7,10 @@ import { copyToClipboard } from "@/shared/utils/clipboard";
|
||||
import { formatApiKeyLabel } from "@/shared/utils/formatting";
|
||||
import { MCP_TOOL_SCOPES } from "@/shared/constants/mcpScopes";
|
||||
import RequestLoggerDetail from "@/shared/components/RequestLoggerDetail";
|
||||
import Badge from "@/shared/components/Badge";
|
||||
import Button from "@/shared/components/Button";
|
||||
import Input from "@/shared/components/Input";
|
||||
import Select from "@/shared/components/Select";
|
||||
import useEmailPrivacyStore from "@/store/emailPrivacyStore";
|
||||
import {
|
||||
type TimelineLog,
|
||||
@@ -36,6 +40,7 @@ import {
|
||||
nextTimelineLogs,
|
||||
getTimelineBarColor,
|
||||
MCP_BAR_COLOR,
|
||||
TIMELINE_BAR_COLORS,
|
||||
} from "@/shared/components/RequestTimeline.utils";
|
||||
|
||||
export type { TimelineLog } from "@/shared/components/RequestTimeline.utils";
|
||||
@@ -567,40 +572,42 @@ export default function RequestTimeline({
|
||||
<div className="flex items-center gap-3">
|
||||
<h2 className="text-sm font-semibold text-text-main">{t("title")}</h2>
|
||||
<span className="text-[10px] text-text-muted font-mono">
|
||||
{visibleLogs.length} visible / {logs.length} total
|
||||
{t("visibleCount", { visible: visibleLogs.length, total: logs.length })}
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
{/* Mode selector */}
|
||||
<div className="flex items-center rounded-lg border border-border overflow-hidden">
|
||||
<div role="group" aria-label={t("modeLabel")} className="flex items-center gap-0.5">
|
||||
{(["follow", "live", "pan"] as ViewMode[]).map((m) => (
|
||||
<button
|
||||
<Button
|
||||
key={m}
|
||||
data-testid={`timeline-mode-${m}`}
|
||||
variant={mode === m ? "primary" : "ghost"}
|
||||
size="sm"
|
||||
aria-pressed={mode === m}
|
||||
onClick={() => handleModeChange(m)}
|
||||
title={t(`modes.${MODE_META[m].descriptionKey}`)}
|
||||
className={`px-2.5 py-1 text-[11px] font-medium transition-colors ${
|
||||
mode === m
|
||||
? "bg-primary text-accent-foreground"
|
||||
: "bg-bg-subtle text-text-muted hover:text-text-main"
|
||||
}`}
|
||||
className="h-7 min-h-7 px-2.5 text-[11px]"
|
||||
>
|
||||
{t(`modes.${MODE_META[m].labelKey}`)}
|
||||
</button>
|
||||
</Button>
|
||||
))}
|
||||
</div>
|
||||
<button
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={handleReset}
|
||||
title={`Jump to current time, NOW line resets to position ${Math.round(nowLineX)}%`}
|
||||
className="px-2 py-1 text-[11px] text-text-muted hover:text-text-main bg-bg-subtle rounded-md border border-border transition-colors"
|
||||
title={t("jumpToNow", { position: Math.round(nowLineX) })}
|
||||
className="h-7 min-h-7 px-2 text-[11px]"
|
||||
>
|
||||
{t("reset")}
|
||||
</button>
|
||||
<select
|
||||
</Button>
|
||||
<Select
|
||||
value={selectedApiKey}
|
||||
onChange={(e) => setSelectedApiKey(e.target.value)}
|
||||
aria-label={t("apiKey")}
|
||||
className="px-2 py-1 text-[11px] text-text-muted bg-bg-subtle rounded-md border border-border"
|
||||
compact
|
||||
className="w-auto"
|
||||
data-testid="timeline-api-key-filter"
|
||||
>
|
||||
<option value="">{t("allApiKeys")}</option>
|
||||
@@ -612,18 +619,19 @@ export default function RequestTimeline({
|
||||
</option>
|
||||
);
|
||||
})}
|
||||
</select>
|
||||
</Select>
|
||||
{/* Conversation lane-reuse window: how long a lane stays reserved
|
||||
for its conversation before falling back to normal packing. */}
|
||||
<label
|
||||
className="flex items-center gap-1 px-2 py-1 text-[11px] text-text-muted bg-bg-subtle rounded-md border border-border"
|
||||
title="Requests sharing a conversation id stay on the same timeline row as long as the gap between them is under this many minutes."
|
||||
<div
|
||||
className="flex items-center gap-1 whitespace-nowrap text-[11px] text-text-muted"
|
||||
title={t("laneReuseHint")}
|
||||
>
|
||||
<span>Lane reuse</span>
|
||||
<input
|
||||
<span aria-hidden="true">{t("laneReuse")}</span>
|
||||
<Input
|
||||
type="number"
|
||||
min={1}
|
||||
step={1}
|
||||
aria-label={t("laneReuseLabel")}
|
||||
value={conversationLaneReuseMinutes}
|
||||
onChange={(e) => {
|
||||
const next = Math.max(1, Number(e.target.value) || 1);
|
||||
@@ -632,20 +640,22 @@ export default function RequestTimeline({
|
||||
localStorage.setItem(CONVERSATION_LANE_REUSE_STORAGE_KEY, String(next));
|
||||
} catch {}
|
||||
}}
|
||||
className="w-10 bg-transparent text-center font-mono focus:outline-none"
|
||||
className="w-auto min-w-0 shrink-0"
|
||||
inputClassName="h-7 min-h-7 w-12 px-1 text-center font-mono text-[11px]"
|
||||
/>
|
||||
<span>min</span>
|
||||
</label>
|
||||
<span aria-hidden="true">{t("laneReuseUnit")}</span>
|
||||
</div>
|
||||
{/* How often the timeline re-polls /api/usage/call-logs for new rows. */}
|
||||
<label
|
||||
className="flex items-center gap-1 px-2 py-1 text-[11px] text-text-muted bg-bg-subtle rounded-md border border-border"
|
||||
title="How often the timeline re-fetches the request list from the server."
|
||||
<div
|
||||
className="flex items-center gap-1 whitespace-nowrap text-[11px] text-text-muted"
|
||||
title={t("autoRefreshHint")}
|
||||
>
|
||||
<span>Auto-refresh</span>
|
||||
<input
|
||||
<span aria-hidden="true">{t("autoRefresh")}</span>
|
||||
<Input
|
||||
type="number"
|
||||
min={1}
|
||||
step={1}
|
||||
aria-label={t("autoRefreshLabel")}
|
||||
value={listPollSeconds}
|
||||
onChange={(e) => {
|
||||
const next = Math.max(1, Number(e.target.value) || 1);
|
||||
@@ -654,27 +664,34 @@ export default function RequestTimeline({
|
||||
localStorage.setItem(TIMELINE_LIST_POLL_STORAGE_KEY, String(next));
|
||||
} catch {}
|
||||
}}
|
||||
className="w-10 bg-transparent text-center font-mono focus:outline-none"
|
||||
className="w-auto min-w-0 shrink-0"
|
||||
inputClassName="h-7 min-h-7 w-12 px-1 text-center font-mono text-[11px]"
|
||||
/>
|
||||
<span>s</span>
|
||||
</label>
|
||||
<span aria-hidden="true">{t("autoRefreshUnit")}</span>
|
||||
</div>
|
||||
{/* Zoom */}
|
||||
<div className="flex items-center gap-1 rounded-lg border border-border overflow-hidden">
|
||||
<button
|
||||
<div className="flex items-center gap-0.5">
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon-sm"
|
||||
onClick={() => setZoom((z) => Math.max(0.001, z * 0.5))}
|
||||
className="px-2 py-1 text-[11px] text-text-muted hover:text-text-main bg-bg-subtle transition-colors"
|
||||
aria-label={t("zoomOut")}
|
||||
title={t("zoomOut")}
|
||||
>
|
||||
-
|
||||
</button>
|
||||
<span className="px-1 text-[10px] text-text-muted font-mono min-w-[36px] text-center">
|
||||
<span aria-hidden="true">-</span>
|
||||
</Button>
|
||||
<span className="min-w-[36px] px-1 text-center font-mono text-[10px] text-text-muted">
|
||||
{zoom >= 1 ? `${zoom}x` : `${zoom * 100}%`}
|
||||
</span>
|
||||
<button
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon-sm"
|
||||
onClick={() => setZoom((z) => Math.min(8, z * 2))}
|
||||
className="px-2 py-1 text-[11px] text-text-muted hover:text-text-main bg-bg-subtle transition-colors"
|
||||
aria-label={t("zoomIn")}
|
||||
title={t("zoomIn")}
|
||||
>
|
||||
+
|
||||
</button>
|
||||
<span aria-hidden="true">+</span>
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -747,7 +764,9 @@ export default function RequestTimeline({
|
||||
onMouseLeave={handleBarLeave}
|
||||
>
|
||||
<div className="w-full h-full flex items-center px-1.5 overflow-hidden">
|
||||
<span className="text-[11px] font-mono text-white/90 truncate whitespace-nowrap">
|
||||
{/* text-bg inverts with the theme: light ink on the deep light-mode fills, dark ink
|
||||
on the pastel dark-mode fills (white on the pastels is ~1.5:1). */}
|
||||
<span className="text-[11px] font-mono text-bg truncate whitespace-nowrap">
|
||||
{truncateModel(log.model)}
|
||||
</span>
|
||||
</div>
|
||||
@@ -805,8 +824,8 @@ export default function RequestTimeline({
|
||||
bottom: 0,
|
||||
}}
|
||||
>
|
||||
<div className="w-px h-full bg-red-500 shadow-[0_0_8px_rgba(239,68,68,0.6)] -translate-x-1/2" />
|
||||
<div className="absolute top-[2px] -translate-x-1/2 bg-red-500 text-white text-[8px] font-mono px-1.5 py-0.5 rounded-b-sm font-bold tracking-wider">
|
||||
<div className="w-px h-full bg-error shadow-[0_0_8px_var(--color-error)] -translate-x-1/2" />
|
||||
<div className="absolute top-[2px] -translate-x-1/2 bg-error text-bg text-[8px] font-mono px-1.5 py-0.5 rounded-b-sm font-bold tracking-wider">
|
||||
NOW
|
||||
</div>
|
||||
</div>
|
||||
@@ -821,10 +840,10 @@ export default function RequestTimeline({
|
||||
width: axisTick.kind === "day" ? 2 : 1,
|
||||
backgroundColor:
|
||||
axisTick.kind === "day"
|
||||
? "rgba(99,102,241,0.5)"
|
||||
? "color-mix(in srgb, var(--color-chart-3) 50%, transparent)"
|
||||
: axisTick.kind === "hour"
|
||||
? "rgba(148,163,184,0.45)"
|
||||
: "rgba(148,163,184,0.15)",
|
||||
? "color-mix(in srgb, var(--color-text-muted) 45%, transparent)"
|
||||
: "color-mix(in srgb, var(--color-text-muted) 15%, transparent)",
|
||||
zIndex: 1,
|
||||
}}
|
||||
/>
|
||||
@@ -851,9 +870,9 @@ export default function RequestTimeline({
|
||||
: hoveredLog.model || t("unknownModel")}
|
||||
</span>
|
||||
{hoveredLog.active && (
|
||||
<span className="text-[9px] px-1.5 py-0.5 rounded-full bg-indigo-500/20 text-indigo-400 font-medium">
|
||||
<Badge size="sm" className="border-chart-3/30 bg-chart-3/20 text-[9px] text-chart-3">
|
||||
{t("active")}
|
||||
</span>
|
||||
</Badge>
|
||||
)}
|
||||
</div>
|
||||
<div className="space-y-0.5 text-[10px] text-text-muted font-mono">
|
||||
@@ -923,7 +942,7 @@ export default function RequestTimeline({
|
||||
</>
|
||||
)}
|
||||
{hoveredLog.error && (
|
||||
<div className="mt-1 text-red-400 text-[9px] break-all">{hoveredLog.error}</div>
|
||||
<div className="mt-1 text-error text-[9px] break-all">{hoveredLog.error}</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
@@ -932,23 +951,38 @@ export default function RequestTimeline({
|
||||
{/* Legend */}
|
||||
<div className="flex items-center gap-3 px-4 py-1.5 border-t border-border text-[9px] shrink-0">
|
||||
<div className="flex items-center gap-1">
|
||||
<div className="w-2.5 h-2.5 rounded-sm" style={{ backgroundColor: "#059669" }} />
|
||||
<div
|
||||
className="w-2.5 h-2.5 rounded-sm"
|
||||
style={{ backgroundColor: TIMELINE_BAR_COLORS.success }}
|
||||
/>
|
||||
<span className="text-text-muted">2xx</span>
|
||||
</div>
|
||||
<div className="flex items-center gap-1">
|
||||
<div className="w-2.5 h-2.5 rounded-sm" style={{ backgroundColor: "#D97706" }} />
|
||||
<div
|
||||
className="w-2.5 h-2.5 rounded-sm"
|
||||
style={{ backgroundColor: TIMELINE_BAR_COLORS.warning }}
|
||||
/>
|
||||
<span className="text-text-muted">4xx</span>
|
||||
</div>
|
||||
<div className="flex items-center gap-1">
|
||||
<div className="w-2.5 h-2.5 rounded-sm" style={{ backgroundColor: "#DC2626" }} />
|
||||
<div
|
||||
className="w-2.5 h-2.5 rounded-sm"
|
||||
style={{ backgroundColor: TIMELINE_BAR_COLORS.error }}
|
||||
/>
|
||||
<span className="text-text-muted">5xx</span>
|
||||
</div>
|
||||
<div className="flex items-center gap-1">
|
||||
<div className="w-2.5 h-2.5 rounded-sm" style={{ backgroundColor: "#6366F1" }} />
|
||||
<div
|
||||
className="w-2.5 h-2.5 rounded-sm"
|
||||
style={{ backgroundColor: TIMELINE_BAR_COLORS.active }}
|
||||
/>
|
||||
<span className="text-text-muted">{t("active")}</span>
|
||||
</div>
|
||||
<div className="flex items-center gap-1">
|
||||
<div className="w-2.5 h-2.5 rounded-sm" style={{ backgroundColor: "#6B7280" }} />
|
||||
<div
|
||||
className="w-2.5 h-2.5 rounded-sm"
|
||||
style={{ backgroundColor: TIMELINE_BAR_COLORS.other }}
|
||||
/>
|
||||
<span className="text-text-muted">{t("other")}</span>
|
||||
</div>
|
||||
<div className="flex items-center gap-1">
|
||||
@@ -956,11 +990,11 @@ export default function RequestTimeline({
|
||||
<span className="text-text-muted">{t("mcp")}</span>
|
||||
</div>
|
||||
<div className="ml-4 flex items-center gap-1.5 text-text-muted">
|
||||
<div className="w-3 border-t border-dashed border-slate-400/40" />
|
||||
<div className="w-3 border-t border-dashed border-text-muted/40" />
|
||||
<span>{t("tenMinutes")}</span>
|
||||
<div className="w-3 border-t border-slate-400/60 ml-2" />
|
||||
<div className="w-3 border-t border-text-muted/60 ml-2" />
|
||||
<span>{t("hour")}</span>
|
||||
<div className="w-3 border-t-2 border-accent/40 ml-2" />
|
||||
<div className="w-3 border-t-2 border-chart-3/50 ml-2" />
|
||||
<span>{t("day")}</span>
|
||||
</div>
|
||||
<div
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import { getHttpStatusStyle } from "@/shared/constants/colors";
|
||||
|
||||
export type TimelineRowKind = "llm" | "mcp";
|
||||
|
||||
export interface TimelineLog {
|
||||
@@ -81,13 +79,34 @@ export function formatTimeAxis(ms: number): string {
|
||||
return `${h}:${m}:${s}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Timeline bar fills, as kit theme tokens (KEA-7886): status tones for 2xx/4xx/5xx, the
|
||||
* categorical chart palette for "active" and MCP rows. CSS values, so both themes resolve.
|
||||
*/
|
||||
export const TIMELINE_BAR_COLORS = {
|
||||
success: "var(--color-success)",
|
||||
warning: "var(--color-warning)",
|
||||
error: "var(--color-error)",
|
||||
active: "var(--color-chart-3)",
|
||||
other: "var(--color-text-muted)",
|
||||
} as const;
|
||||
|
||||
export function getStatusColor(status: number, active: boolean | undefined): string {
|
||||
if (active) return "#6366F1";
|
||||
return getHttpStatusStyle(status).bg;
|
||||
if (active) return TIMELINE_BAR_COLORS.active;
|
||||
if (status >= 200 && status < 300) return TIMELINE_BAR_COLORS.success;
|
||||
if (status >= 400 && status < 500) return TIMELINE_BAR_COLORS.warning;
|
||||
if (status >= 500) return TIMELINE_BAR_COLORS.error;
|
||||
// status 0 = pending (same tone as an active bar, as before).
|
||||
if (status === 0) return TIMELINE_BAR_COLORS.active;
|
||||
return TIMELINE_BAR_COLORS.other;
|
||||
}
|
||||
|
||||
/** Teal, distinct from the 2xx green used for LLM bars. */
|
||||
export const MCP_BAR_COLOR = "#0F766E";
|
||||
/**
|
||||
* Categorical chart blue for MCP rows. Not chart-4: the kit's chart-4 is the success green in
|
||||
* both themes, which made MCP bars identical to 2xx LLM bars. chart-2 is unused by the other
|
||||
* timeline categories.
|
||||
*/
|
||||
export const MCP_BAR_COLOR = "var(--color-chart-2)";
|
||||
|
||||
export function getTimelineBarColor(log: TimelineLog): string {
|
||||
if (log.kind === "mcp" && (log.status || 0) < 400) return MCP_BAR_COLOR;
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
import { useState } from "react";
|
||||
import { useTranslations } from "next-intl";
|
||||
import Select from "../Select";
|
||||
|
||||
export interface ComboCompressionModeSelectCombo {
|
||||
id: string;
|
||||
@@ -93,22 +94,23 @@ export function ComboCompressionModeSelect({
|
||||
};
|
||||
|
||||
return (
|
||||
<select
|
||||
// Kit-styled native select (adapter `Select` with <option> children). A caller's
|
||||
// `className` still lands on the control itself, as with the legacy native select.
|
||||
<Select
|
||||
compact
|
||||
value={compressionOverride}
|
||||
onChange={(e) => handleChange(e.target.value)}
|
||||
disabled={disabled || isSaving}
|
||||
className={
|
||||
className ||
|
||||
"text-xs py-1 px-2 rounded border border-black/10 dark:border-white/10 bg-surface text-text-main focus:border-primary focus:outline-none transition-colors disabled:opacity-50"
|
||||
}
|
||||
selectClassName={className}
|
||||
title={title}
|
||||
aria-label={title || t("compressionSettings")}
|
||||
>
|
||||
{OPTIONS.map((option) => (
|
||||
<option key={option.value} value={option.value} className="bg-surface text-text-main">
|
||||
<option key={option.value} value={option.value}>
|
||||
{t(`modeOptions.${option.key}`)}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</Select>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -33,6 +33,9 @@ import {
|
||||
type EngineIntensities,
|
||||
type PipelineStep,
|
||||
} from "./compressionPipelineModel";
|
||||
import Button from "../Button";
|
||||
import Icon from "../Icon";
|
||||
import Select from "../Select";
|
||||
|
||||
export type { PipelineStep } from "./compressionPipelineModel";
|
||||
|
||||
@@ -42,9 +45,6 @@ type Props = {
|
||||
engineIntensities: EngineIntensities;
|
||||
};
|
||||
|
||||
const SELECT_CLASS =
|
||||
"rounded-lg border border-border bg-bg px-3 py-2 text-sm text-text-main w-full";
|
||||
|
||||
function SortableRow(props: {
|
||||
id: string;
|
||||
index: number;
|
||||
@@ -71,49 +71,48 @@ function SortableRow(props: {
|
||||
data-testid={`pipeline-row-${props.index}`}
|
||||
className="grid grid-cols-[auto_1fr_1fr_auto] items-center gap-2"
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
{/* dnd-kit drag handle: its listeners/attributes ride on the kit Button. */}
|
||||
<Button
|
||||
variant="outline"
|
||||
size="icon"
|
||||
aria-label={t("dragToReorder")}
|
||||
data-testid={`pipeline-drag-${props.index}`}
|
||||
className="cursor-grab rounded-lg border border-border px-2 py-2 text-sm text-text-muted"
|
||||
className="cursor-grab text-text-muted"
|
||||
{...attributes}
|
||||
{...listeners}
|
||||
>
|
||||
⠿
|
||||
</button>
|
||||
<select
|
||||
<Icon name="drag_indicator" size={16} />
|
||||
</Button>
|
||||
<Select
|
||||
aria-label={t("engine")}
|
||||
value={props.step.engine}
|
||||
onChange={(event) => props.onPatch({ engine: event.target.value })}
|
||||
className={SELECT_CLASS}
|
||||
>
|
||||
{props.engines.map((engine) => (
|
||||
<option key={engine} value={engine}>
|
||||
{engine}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
<select
|
||||
</Select>
|
||||
<Select
|
||||
aria-label={t("intensity")}
|
||||
value={props.step.intensity ?? ""}
|
||||
onChange={(event) => props.onPatch({ intensity: event.target.value })}
|
||||
className={SELECT_CLASS}
|
||||
>
|
||||
{allowedIntensities(props.step.engine, props.engineIntensities).map((intensity) => (
|
||||
<option key={intensity} value={intensity}>
|
||||
{intensity}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
<button
|
||||
type="button"
|
||||
</Select>
|
||||
<Button
|
||||
variant="outline"
|
||||
onClick={props.onRemove}
|
||||
disabled={!props.canRemove}
|
||||
data-testid={`pipeline-remove-${props.index}`}
|
||||
className="rounded-lg border border-border px-3 py-2 text-sm text-text-main disabled:opacity-50"
|
||||
>
|
||||
{t("removeStep")}
|
||||
</button>
|
||||
</Button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -144,14 +143,15 @@ export function CompressionPipelineEditor({ steps, onChange, engineIntensities }
|
||||
<div className="space-y-3" data-testid="compression-pipeline-editor">
|
||||
<div className="flex items-center justify-between">
|
||||
<h3 className="text-sm font-semibold text-text-main">{t("pipeline")}</h3>
|
||||
<button
|
||||
type="button"
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
icon="add"
|
||||
data-testid="pipeline-add-step"
|
||||
onClick={() => onChange(addLayer(steps, { engine: firstEngine }, engineIntensities))}
|
||||
className="rounded-lg border border-border px-3 py-1.5 text-xs text-text-main"
|
||||
>
|
||||
{t("addStep")}
|
||||
</button>
|
||||
</Button>
|
||||
</div>
|
||||
<DndContext
|
||||
id={dndContextId}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
"use client";
|
||||
import type { EngineConfigField } from "@omniroute/open-sse/services/compression/engines/types";
|
||||
import { Checkbox as KitCheckbox, CheckboxGroup } from "@omniroute/ui-kit/checkbox";
|
||||
import Input from "../Input";
|
||||
import Select from "../Select";
|
||||
|
||||
export interface EngineConfigFormProps {
|
||||
schema: EngineConfigField[];
|
||||
@@ -10,78 +13,96 @@ export interface EngineConfigFormProps {
|
||||
|
||||
export function EngineConfigForm({ schema, value, onChange: set }: EngineConfigFormProps) {
|
||||
return (
|
||||
<div className="flex flex-col gap-3">
|
||||
<div className="flex flex-col gap-4">
|
||||
{schema.map((f) => {
|
||||
const v = value[f.key] ?? f.defaultValue;
|
||||
return (
|
||||
<label key={f.key} className="flex flex-col gap-1 text-sm">
|
||||
<span className="font-medium">{f.label}</span>
|
||||
{f.description && <span className="text-xs text-text-muted">{f.description}</span>}
|
||||
{f.type === "boolean" && (
|
||||
<input type="checkbox" checked={!!v} onChange={(e) => set(f.key, e.target.checked)} />
|
||||
)}
|
||||
{f.type === "number" && (
|
||||
<input
|
||||
type="number"
|
||||
// NaN (an emptied field, "not set") renders as an empty input, never as 0;
|
||||
// overflow (Infinity) also renders empty and surfaces through the save error.
|
||||
value={typeof v === "number" && Number.isFinite(v) ? v : ""}
|
||||
placeholder={f.defaultValue != null ? String(f.defaultValue) : ""}
|
||||
min={f.min}
|
||||
max={f.max}
|
||||
// Fractional settings (e.g. CCR retrievalRampFactor 1.5) must not fail
|
||||
// the browser's step validation, whose default step is 1.
|
||||
step="any"
|
||||
onChange={(e) => {
|
||||
// A browser reports badInput with an empty value for unparseable entries
|
||||
// ("1e", "1,5" in a comma-decimal locale): keep the last valid value rather
|
||||
// than mapping the entry to the unset sentinel.
|
||||
if (e.target.value === "" && e.target.validity.badInput) return;
|
||||
set(f.key, e.target.value === "" ? Number.NaN : Number(e.target.value));
|
||||
}}
|
||||
className="border border-border rounded px-2 py-1"
|
||||
/>
|
||||
)}
|
||||
{f.type === "string" && (
|
||||
<input
|
||||
type="text"
|
||||
value={(v as string) ?? ""}
|
||||
onChange={(e) => set(f.key, e.target.value)}
|
||||
className="border border-border rounded px-2 py-1"
|
||||
/>
|
||||
)}
|
||||
{f.type === "select" && (
|
||||
<select
|
||||
value={v as string}
|
||||
onChange={(e) => set(f.key, e.target.value)}
|
||||
className="border border-border rounded px-2 py-1"
|
||||
>
|
||||
{(f.options ?? []).map((o) => (
|
||||
<option key={o.value} value={o.value}>
|
||||
{o.label}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
)}
|
||||
{f.type === "multiselect" &&
|
||||
(f.options ?? []).map((o) => (
|
||||
<label key={o.value} className="flex items-center gap-2 text-xs">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={Array.isArray(v) && (v as string[]).includes(o.value)}
|
||||
onChange={(e) => {
|
||||
const arr = Array.isArray(v) ? [...(v as string[])] : [];
|
||||
set(
|
||||
f.key,
|
||||
e.target.checked ? [...arr, o.value] : arr.filter((x) => x !== o.value)
|
||||
);
|
||||
}}
|
||||
/>
|
||||
{o.label}
|
||||
</label>
|
||||
if (f.type === "boolean") {
|
||||
return (
|
||||
<KitCheckbox
|
||||
key={f.key}
|
||||
label={f.label}
|
||||
description={f.description || undefined}
|
||||
checked={!!v}
|
||||
onChange={(e) => set(f.key, e.target.checked)}
|
||||
/>
|
||||
);
|
||||
}
|
||||
if (f.type === "multiselect") {
|
||||
return (
|
||||
<CheckboxGroup key={f.key} label={f.label} description={f.description || undefined}>
|
||||
{(f.options ?? []).map((o) => (
|
||||
<KitCheckbox
|
||||
key={o.value}
|
||||
label={o.label}
|
||||
checked={Array.isArray(v) && (v as string[]).includes(o.value)}
|
||||
onChange={(e) => {
|
||||
const arr = Array.isArray(v) ? [...(v as string[])] : [];
|
||||
set(
|
||||
f.key,
|
||||
e.target.checked ? [...arr, o.value] : arr.filter((x) => x !== o.value)
|
||||
);
|
||||
}}
|
||||
/>
|
||||
))}
|
||||
</label>
|
||||
);
|
||||
</CheckboxGroup>
|
||||
);
|
||||
}
|
||||
if (f.type === "number") {
|
||||
return (
|
||||
<Input
|
||||
key={f.key}
|
||||
type="number"
|
||||
label={f.label}
|
||||
hint={f.description || undefined}
|
||||
// NaN (an emptied field, "not set") renders as an empty input, never as 0;
|
||||
// overflow (Infinity) also renders empty and surfaces through the save error.
|
||||
value={typeof v === "number" && Number.isFinite(v) ? v : ""}
|
||||
placeholder={f.defaultValue != null ? String(f.defaultValue) : ""}
|
||||
min={f.min}
|
||||
max={f.max}
|
||||
// Fractional settings (e.g. CCR retrievalRampFactor 1.5) must not fail
|
||||
// the browser's step validation, whose default step is 1.
|
||||
step="any"
|
||||
onChange={(e) => {
|
||||
// A browser reports badInput with an empty value for unparseable entries
|
||||
// ("1e", "1,5" in a comma-decimal locale): keep the last valid value rather
|
||||
// than mapping the entry to the unset sentinel.
|
||||
if (e.target.value === "" && e.target.validity.badInput) return;
|
||||
set(f.key, e.target.value === "" ? Number.NaN : Number(e.target.value));
|
||||
}}
|
||||
/>
|
||||
);
|
||||
}
|
||||
if (f.type === "string") {
|
||||
return (
|
||||
<Input
|
||||
key={f.key}
|
||||
type="text"
|
||||
label={f.label}
|
||||
hint={f.description || undefined}
|
||||
value={(v as string) ?? ""}
|
||||
onChange={(e) => set(f.key, e.target.value)}
|
||||
/>
|
||||
);
|
||||
}
|
||||
if (f.type === "select") {
|
||||
return (
|
||||
<Select
|
||||
key={f.key}
|
||||
label={f.label}
|
||||
hint={f.description || undefined}
|
||||
value={v as string}
|
||||
onChange={(e) => set(f.key, e.target.value)}
|
||||
>
|
||||
{(f.options ?? []).map((o) => (
|
||||
<option key={o.value} value={o.value}>
|
||||
{o.label}
|
||||
</option>
|
||||
))}
|
||||
</Select>
|
||||
);
|
||||
}
|
||||
return null;
|
||||
})}
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -4,6 +4,12 @@ import { useEffect, useState } from "react";
|
||||
import { useLocale, useTranslations } from "next-intl";
|
||||
import type { EngineConfigField } from "@omniroute/open-sse/services/compression/engines/types";
|
||||
import { EngineConfigForm } from "@/shared/components/compression/EngineConfigForm";
|
||||
import { Alert } from "@omniroute/ui-kit/alert";
|
||||
import { PageHeader, SectionHeader } from "@omniroute/ui-kit/page-header";
|
||||
import Button from "@/shared/components/Button";
|
||||
import Card from "@/shared/components/Card";
|
||||
import Icon from "@/shared/components/Icon";
|
||||
import Textarea from "@/shared/components/Textarea";
|
||||
import {
|
||||
buildEngineDetailUpdate,
|
||||
forgetSentEdits,
|
||||
@@ -86,10 +92,10 @@ const ENGINE_ICON_ALIASES: Record<string, string> = {
|
||||
|
||||
function StatCard({ label, value }: { label: string; value: string }) {
|
||||
return (
|
||||
<div className="flex flex-col gap-0.5 rounded-lg border border-border bg-surface p-3">
|
||||
<Card padding="sm" className="flex flex-col gap-0.5">
|
||||
<span className="text-xs text-text-muted">{label}</span>
|
||||
<span className="text-lg font-semibold text-text">{value}</span>
|
||||
</div>
|
||||
<span className="text-lg font-semibold text-text-main">{value}</span>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -109,11 +115,11 @@ function renderDiffSegment(
|
||||
"";
|
||||
|
||||
return (
|
||||
<div key={`${label}-${index}`} className="rounded border border-border bg-background p-2">
|
||||
<span className="mr-2 rounded bg-muted px-1.5 py-0.5 text-[10px] font-semibold uppercase tracking-wide text-text-muted">
|
||||
<div key={`${label}-${index}`} className="rounded border border-border bg-bg p-2">
|
||||
<span className="mr-2 rounded bg-bg-subtle px-1.5 py-0.5 text-[10px] font-semibold uppercase tracking-wide text-text-muted">
|
||||
{translateLabel(label)}
|
||||
</span>
|
||||
<span className="whitespace-pre-wrap break-words text-text">{text}</span>
|
||||
<span className="whitespace-pre-wrap break-words text-text-main">{text}</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -359,41 +365,52 @@ export function EngineConfigPage({ engineId }: { engineId: string }) {
|
||||
return (
|
||||
<div className="flex flex-col gap-6 p-6 max-w-3xl">
|
||||
{/* ── Header ── */}
|
||||
<div className="flex flex-col gap-1">
|
||||
<div className="flex items-center gap-2">
|
||||
{engine.icon && (
|
||||
<span
|
||||
className="material-symbols-outlined text-[28px] leading-none text-text-muted"
|
||||
aria-hidden="true"
|
||||
>
|
||||
{ENGINE_ICON_ALIASES[engine.icon] || engine.icon}
|
||||
</span>
|
||||
)}
|
||||
<h1 className="text-2xl font-bold text-text">{engineName}</h1>
|
||||
</div>
|
||||
{subtitle && <p className="text-sm text-text-muted">{subtitle}</p>}
|
||||
</div>
|
||||
<PageHeader
|
||||
compact
|
||||
title={
|
||||
<span className="flex items-center gap-2">
|
||||
{engine.icon && (
|
||||
<Icon
|
||||
name={ENGINE_ICON_ALIASES[engine.icon] || engine.icon}
|
||||
size={28}
|
||||
className="text-text-muted"
|
||||
/>
|
||||
)}
|
||||
{engineName}
|
||||
</span>
|
||||
}
|
||||
description={subtitle || undefined}
|
||||
/>
|
||||
|
||||
{loadError && (
|
||||
<p className="text-xs text-destructive border border-destructive/30 rounded px-3 py-2">
|
||||
{loadError}
|
||||
</p>
|
||||
<Alert
|
||||
variant="critical"
|
||||
icon={<Icon name="error" size={16} />}
|
||||
description={loadError}
|
||||
// Cleared only by a successful reload; the kit Alert has no non-dismissible mode.
|
||||
className="[&>.ci-alert__dismiss]:hidden"
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* ── Panel pointer (on/off + level live there now) ── */}
|
||||
<div className="flex flex-col gap-1 rounded-lg border border-border bg-surface p-4">
|
||||
<p className="text-xs text-text-muted" data-testid="panel-pointer-notice">
|
||||
{t("panelPointerPrefix")}{" "}
|
||||
<a href="/dashboard/context/settings" className="underline hover:text-text">
|
||||
{t("compressionSettings")}
|
||||
</a>
|
||||
{t("panelPointerSuffix")}
|
||||
</p>
|
||||
</div>
|
||||
<Alert
|
||||
variant="info"
|
||||
icon={<Icon name="info" size={16} />}
|
||||
className="[&>.ci-alert__dismiss]:hidden"
|
||||
description={
|
||||
<span data-testid="panel-pointer-notice">
|
||||
{t("panelPointerPrefix")}{" "}
|
||||
<a href="/dashboard/context/settings" className="underline hover:text-text-main">
|
||||
{t("compressionSettings")}
|
||||
</a>
|
||||
{t("panelPointerSuffix")}
|
||||
</span>
|
||||
}
|
||||
/>
|
||||
|
||||
{/* ── Config form ── */}
|
||||
<div className="flex flex-col gap-3 rounded-lg border border-border bg-surface p-4">
|
||||
<h2 className="text-sm font-semibold text-text">{t("configuration")}</h2>
|
||||
<Card padding="sm" className="flex flex-col gap-3">
|
||||
<SectionHeader title={t("configuration")} />
|
||||
{visibleConfigSchema.length > 0 ? (
|
||||
<EngineConfigForm
|
||||
schema={visibleConfigSchema}
|
||||
@@ -405,51 +422,51 @@ export function EngineConfigPage({ engineId }: { engineId: string }) {
|
||||
)}
|
||||
<div className="flex items-center gap-3 pt-1">
|
||||
{persistable ? (
|
||||
<button
|
||||
onClick={handleSave}
|
||||
disabled={saving || Boolean(loadError)}
|
||||
className="px-4 py-1.5 rounded bg-primary text-primary-foreground text-sm font-medium disabled:opacity-50"
|
||||
>
|
||||
<Button size="sm" onClick={handleSave} disabled={saving || Boolean(loadError)}>
|
||||
{saving ? t("saving") : t("save")}
|
||||
</button>
|
||||
</Button>
|
||||
) : (
|
||||
<p className="text-xs text-text-muted" data-testid="no-detail-store-notice">
|
||||
{t("globalSettingsOnly")}
|
||||
</p>
|
||||
)}
|
||||
{saveError && <p className="text-xs text-destructive">{saveError}</p>}
|
||||
{saveError && (
|
||||
<p className="text-xs text-error" role="alert">
|
||||
{saveError}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</Card>
|
||||
|
||||
{/* ── Live preview ── */}
|
||||
<div className="flex flex-col gap-3 rounded-lg border border-border bg-surface p-4">
|
||||
<h2 className="text-sm font-semibold text-text">{t("preview")}</h2>
|
||||
<textarea
|
||||
className="border border-border rounded px-3 py-2 text-sm text-text bg-background resize-y min-h-[80px]"
|
||||
<Card padding="sm" className="flex flex-col gap-3">
|
||||
<SectionHeader title={t("preview")} />
|
||||
<Textarea
|
||||
className="min-h-[80px] resize-y"
|
||||
value={previewText}
|
||||
onChange={(e) => setPreviewText(e.target.value)}
|
||||
aria-label={t("previewInput")}
|
||||
/>
|
||||
<div className="flex items-center gap-3">
|
||||
<button
|
||||
onClick={handlePreview}
|
||||
disabled={previewLoading}
|
||||
className="px-4 py-1.5 rounded bg-primary text-primary-foreground text-sm font-medium disabled:opacity-50"
|
||||
>
|
||||
<Button variant="secondary" size="sm" onClick={handlePreview} disabled={previewLoading}>
|
||||
{previewLoading ? t("processing") : t("preview")}
|
||||
</button>
|
||||
</Button>
|
||||
</div>
|
||||
{previewError && <p className="text-xs text-destructive">{previewError}</p>}
|
||||
{previewError && (
|
||||
<p className="text-xs text-error" role="alert">
|
||||
{previewError}
|
||||
</p>
|
||||
)}
|
||||
{preview && (
|
||||
<div className="flex flex-col gap-3 pt-1 text-sm">
|
||||
<div className="flex flex-wrap gap-4">
|
||||
<span className="text-text-muted">
|
||||
{t("originalTokens")}:{" "}
|
||||
<strong className="text-text">{preview.originalTokens}</strong>
|
||||
<strong className="text-text-main">{preview.originalTokens}</strong>
|
||||
</span>
|
||||
<span className="text-text-muted">
|
||||
{t("compressedTokens")}:{" "}
|
||||
<strong className="text-text">{preview.compressedTokens}</strong>
|
||||
<strong className="text-text-main">{preview.compressedTokens}</strong>
|
||||
</span>
|
||||
<span className="text-text-muted">
|
||||
{t("savings")}:{" "}
|
||||
@@ -461,7 +478,7 @@ export function EngineConfigPage({ engineId }: { engineId: string }) {
|
||||
<h3 className="text-xs font-semibold uppercase tracking-wide text-text-muted">
|
||||
{t("original")}
|
||||
</h3>
|
||||
<pre className="max-h-72 overflow-auto rounded border border-border bg-background p-3 whitespace-pre-wrap break-words text-text">
|
||||
<pre className="max-h-72 overflow-auto whitespace-pre-wrap break-words rounded border border-border bg-bg p-3 text-text-main">
|
||||
{preview.original ?? ""}
|
||||
</pre>
|
||||
</div>
|
||||
@@ -469,7 +486,7 @@ export function EngineConfigPage({ engineId }: { engineId: string }) {
|
||||
<h3 className="text-xs font-semibold uppercase tracking-wide text-text-muted">
|
||||
{t("compressed")}
|
||||
</h3>
|
||||
<pre className="max-h-72 overflow-auto rounded border border-border bg-background p-3 whitespace-pre-wrap break-words text-text">
|
||||
<pre className="max-h-72 overflow-auto whitespace-pre-wrap break-words rounded border border-border bg-bg p-3 text-text-main">
|
||||
{preview.compressed ?? ""}
|
||||
</pre>
|
||||
</div>
|
||||
@@ -491,11 +508,11 @@ export function EngineConfigPage({ engineId }: { engineId: string }) {
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</Card>
|
||||
|
||||
{/* ── Analytics strip ── */}
|
||||
<div className="flex flex-col gap-3 rounded-lg border border-border bg-surface p-4">
|
||||
<h2 className="text-sm font-semibold text-text">{t("last7Days")}</h2>
|
||||
<Card padding="sm" className="flex flex-col gap-3">
|
||||
<SectionHeader title={t("last7Days")} />
|
||||
{analytics && analytics.runs === 0 ? (
|
||||
<p className="text-sm text-text-muted">{t("noDataYet")}</p>
|
||||
) : analytics ? (
|
||||
@@ -513,7 +530,7 @@ export function EngineConfigPage({ engineId }: { engineId: string }) {
|
||||
) : (
|
||||
<p className="text-sm text-text-muted">{t("noDataYet")}</p>
|
||||
)}
|
||||
</div>
|
||||
</Card>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
export const LOG_TABLE_CLASS = "w-full text-left border-collapse text-xs";
|
||||
export const LOG_TABLE_HEAD_CLASS = "sticky top-0 z-10";
|
||||
export const LOG_TABLE_ROW_CLASS = "border-b border-border";
|
||||
export const LOG_TABLE_HEADER_CELL_CLASS =
|
||||
"px-3 py-2.5 font-semibold text-text-muted uppercase tracking-wider text-[10px]";
|
||||
export const LOG_TABLE_HEADER_CELL_RIGHT_CLASS = `${LOG_TABLE_HEADER_CELL_CLASS} text-right`;
|
||||
export const LOG_TABLE_HEADER_BG_STYLE = { backgroundColor: "var(--color-bg, #fff)" } as const;
|
||||
@@ -2,11 +2,14 @@
|
||||
|
||||
import Link from "next/link";
|
||||
import { useTranslations } from "next-intl";
|
||||
import { buttonVariants } from "@omniroute/ui-kit/button";
|
||||
import Card from "@/shared/components/Card";
|
||||
import Icon from "@/shared/components/Icon";
|
||||
|
||||
export default function RoutingEntryLink({ apiKeyId }: { apiKeyId?: string }) {
|
||||
const t = useTranslations("reasoningRouting.editor");
|
||||
return (
|
||||
<div className="flex flex-wrap items-center justify-between gap-4 rounded-xl border border-border bg-surface p-4">
|
||||
<Card padding="sm" className="flex flex-wrap items-center justify-between gap-4">
|
||||
<div className="min-w-0 flex-1">
|
||||
<p className="font-medium text-text-main">{t("pageTitle")}</p>
|
||||
<p className="mt-1 text-sm text-text-muted">{t("entryHint")}</p>
|
||||
@@ -17,13 +20,11 @@ export default function RoutingEntryLink({ apiKeyId }: { apiKeyId?: string }) {
|
||||
? "/dashboard/api-manager/routing?apiKeyId=" + encodeURIComponent(apiKeyId)
|
||||
: "/dashboard/api-manager/routing"
|
||||
}
|
||||
className="inline-flex shrink-0 items-center gap-2 rounded-lg border border-border px-4 py-2 text-sm font-medium text-primary hover:bg-primary/10 focus-visible:outline-2 focus-visible:outline-primary"
|
||||
className={buttonVariants({ variant: "outline", className: "shrink-0" })}
|
||||
>
|
||||
<span className="material-symbols-outlined text-lg" aria-hidden="true">
|
||||
route
|
||||
</span>
|
||||
<Icon name="route" size={18} />
|
||||
{t("configure")}
|
||||
</Link>
|
||||
</div>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -47,6 +47,7 @@ import {
|
||||
ChevronLeft,
|
||||
ChevronRight,
|
||||
ChevronUp,
|
||||
ChevronsDownUp,
|
||||
ChevronsUpDown,
|
||||
Circle,
|
||||
CircleAlert,
|
||||
@@ -112,6 +113,7 @@ import {
|
||||
Grid2x2,
|
||||
Hammer,
|
||||
HardDriveDownload,
|
||||
Hash,
|
||||
Heart,
|
||||
HeartPulse,
|
||||
Hexagon,
|
||||
@@ -119,6 +121,7 @@ import {
|
||||
Hourglass,
|
||||
House,
|
||||
Image,
|
||||
ImageUpscale,
|
||||
Inbox,
|
||||
Info,
|
||||
Key,
|
||||
@@ -127,11 +130,14 @@ import {
|
||||
Languages,
|
||||
Layers,
|
||||
LayoutGrid,
|
||||
LibraryBig,
|
||||
LifeBuoy,
|
||||
Lightbulb,
|
||||
Link,
|
||||
List,
|
||||
ListChecks,
|
||||
ListChevronsDownUp,
|
||||
ListChevronsUpDown,
|
||||
ListFilter,
|
||||
ListOrdered,
|
||||
ListX,
|
||||
@@ -187,6 +193,7 @@ import {
|
||||
RectangleEllipsis,
|
||||
RefreshCw,
|
||||
RefreshCwOff,
|
||||
Reply,
|
||||
Rocket,
|
||||
RotateCcw,
|
||||
Route,
|
||||
@@ -237,6 +244,7 @@ import {
|
||||
Volume2,
|
||||
Wallet,
|
||||
Wand2,
|
||||
Waves,
|
||||
Waypoints,
|
||||
Webhook,
|
||||
Wifi,
|
||||
@@ -259,7 +267,6 @@ import {
|
||||
SquareFunction,
|
||||
SquarePen,
|
||||
Type,
|
||||
Waves,
|
||||
} from "lucide-react";
|
||||
// Combos editor + routing strategies (KEA-7886, lote 4).
|
||||
import {
|
||||
@@ -433,6 +440,7 @@ export const ICON_MAP: Record<string, LucideIcon | null> = {
|
||||
psychology: Brain,
|
||||
radar: Radar,
|
||||
request_quote: Receipt,
|
||||
robot: Bot,
|
||||
route: Route,
|
||||
route_off: RouteOff,
|
||||
savings: Coins,
|
||||
@@ -504,7 +512,7 @@ export const ICON_MAP: Record<string, LucideIcon | null> = {
|
||||
cloud_queue: Cloud,
|
||||
cloud_sync: CloudSync,
|
||||
code_blocks: SquareCode,
|
||||
collapse_all: null,
|
||||
collapse_all: ListChevronsDownUp,
|
||||
compare: Columns2,
|
||||
compare_arrows: ArrowLeftRight,
|
||||
computer: Monitor,
|
||||
@@ -537,7 +545,7 @@ export const ICON_MAP: Record<string, LucideIcon | null> = {
|
||||
event_available: CalendarCheck,
|
||||
event_busy: CalendarX,
|
||||
event_repeat: CalendarSync,
|
||||
expand_all: null,
|
||||
expand_all: ListChevronsUpDown,
|
||||
explore: Compass,
|
||||
face: null,
|
||||
fact_check: ClipboardCheck,
|
||||
@@ -581,7 +589,7 @@ export const ICON_MAP: Record<string, LucideIcon | null> = {
|
||||
keyboard_arrow_up: ChevronUp,
|
||||
keyboard_capslock: null,
|
||||
label: Tag,
|
||||
library_books: null,
|
||||
library_books: LibraryBig,
|
||||
linear_scale: GitCommitHorizontal,
|
||||
link_off: Unlink,
|
||||
list: List,
|
||||
@@ -621,7 +629,7 @@ export const ICON_MAP: Record<string, LucideIcon | null> = {
|
||||
pending_actions: ClipboardClock,
|
||||
percent: Percent,
|
||||
pets: null,
|
||||
photo_size_select_large: null,
|
||||
photo_size_select_large: ImageUpscale,
|
||||
pin: RectangleEllipsis,
|
||||
play_circle: CirclePlay,
|
||||
playlist_add: ListPlus,
|
||||
@@ -635,9 +643,9 @@ export const ICON_MAP: Record<string, LucideIcon | null> = {
|
||||
receipt_long: ReceiptText,
|
||||
record_voice_over: Speech,
|
||||
redeem: Gift,
|
||||
remove: null,
|
||||
remove: Minus,
|
||||
replay: RotateCcw,
|
||||
reply: null,
|
||||
reply: Reply,
|
||||
report: OctagonAlert,
|
||||
restore: RotateCcw,
|
||||
rocket_launch: Rocket,
|
||||
@@ -672,11 +680,11 @@ export const ICON_MAP: Record<string, LucideIcon | null> = {
|
||||
swords: Swords,
|
||||
sync: RefreshCw,
|
||||
sync_alt: ArrowLeftRight,
|
||||
sync_disabled: null,
|
||||
sync_disabled: RefreshCwOff,
|
||||
sync_problem: RefreshCwOff,
|
||||
system_update_alt: MonitorDown,
|
||||
table_chart: null,
|
||||
tag: null,
|
||||
tag: Hash,
|
||||
task_alt: CircleCheckBig,
|
||||
text_fields: Type,
|
||||
text_snippet: FileText,
|
||||
@@ -691,7 +699,7 @@ export const ICON_MAP: Record<string, LucideIcon | null> = {
|
||||
trending_flat: MoveRight,
|
||||
trending_up: TrendingUp,
|
||||
troubleshoot: Stethoscope,
|
||||
unfold_less: null,
|
||||
unfold_less: ChevronsDownUp,
|
||||
unfold_more: ChevronsUpDown,
|
||||
upload_file: FileUp,
|
||||
verified: BadgeCheck,
|
||||
|
||||
@@ -46,7 +46,8 @@ test.describe("Compression Studio (Tela A)", () => {
|
||||
const compareTab = page.locator('[data-testid="tab-compare"]');
|
||||
await expect(compareTab).toBeVisible({ timeout: 30_000 });
|
||||
await compareTab.click();
|
||||
await expect(compareTab).toHaveAttribute("aria-pressed", "true");
|
||||
// KEA-7886: the studio views are kit Tabs (role="tab"), so the selection is aria-selected.
|
||||
await expect(compareTab).toHaveAttribute("aria-selected", "true");
|
||||
// Compare view mounted → its load control is present.
|
||||
await expect(page.locator('[data-testid="compare-load"]').first()).toBeVisible({
|
||||
timeout: 30_000,
|
||||
|
||||
@@ -1,7 +1,17 @@
|
||||
// @vitest-environment jsdom
|
||||
import React, { act } from "react";
|
||||
import { createRoot, type Root } from "react-dom/client";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi, beforeAll } from "vitest";
|
||||
|
||||
// The kit Table (KEA-7886) mounts a persistent horizontal scrollbar that measures the table
|
||||
// with ResizeObserver, which jsdom does not implement.
|
||||
beforeAll(() => {
|
||||
globalThis.ResizeObserver ??= class {
|
||||
observe() {}
|
||||
unobserve() {}
|
||||
disconnect() {}
|
||||
} as unknown as typeof ResizeObserver;
|
||||
});
|
||||
|
||||
import enMessages from "@/i18n/messages/en.json";
|
||||
|
||||
|
||||
@@ -2,7 +2,17 @@
|
||||
import React, { act } from "react";
|
||||
import { createRoot, type Root } from "react-dom/client";
|
||||
import { renderToString } from "react-dom/server";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi, beforeAll } from "vitest";
|
||||
|
||||
// The kit Table (KEA-7886) mounts a persistent horizontal scrollbar that measures the table
|
||||
// with ResizeObserver, which jsdom does not implement.
|
||||
beforeAll(() => {
|
||||
globalThis.ResizeObserver ??= class {
|
||||
observe() {}
|
||||
unobserve() {}
|
||||
disconnect() {}
|
||||
} as unknown as typeof ResizeObserver;
|
||||
});
|
||||
|
||||
import enMessages from "@/i18n/messages/en.json";
|
||||
|
||||
@@ -265,10 +275,13 @@ describe("Models and Combos Catalog Page UI", () => {
|
||||
}
|
||||
|
||||
function inputByLabel(text: string): HTMLInputElement {
|
||||
// KEA-7886: kit fields — the <label htmlFor> sits above the control, not around it.
|
||||
const label = [...container.querySelectorAll("label")].find((element) =>
|
||||
element.textContent?.trim().startsWith(text)
|
||||
);
|
||||
const input = label?.querySelector("input") ?? null;
|
||||
const input =
|
||||
label?.querySelector("input") ??
|
||||
(label?.htmlFor ? (document.getElementById(label.htmlFor) as HTMLInputElement | null) : null);
|
||||
expect(input).not.toBeNull();
|
||||
return input as HTMLInputElement;
|
||||
}
|
||||
@@ -762,7 +775,11 @@ describe("Models and Combos Catalog Page UI", () => {
|
||||
const label = [...container.querySelectorAll("label")].find((element) =>
|
||||
element.textContent?.trim().startsWith(text)
|
||||
);
|
||||
const select = label?.querySelector("select") ?? null;
|
||||
const select =
|
||||
label?.querySelector("select") ??
|
||||
(label?.htmlFor
|
||||
? (document.getElementById(label.htmlFor) as HTMLSelectElement | null)
|
||||
: null);
|
||||
expect(select).not.toBeNull();
|
||||
return select as HTMLSelectElement;
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user