Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 5 additions & 28 deletions web/src/app/(main)/chat/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,36 +56,13 @@ import { useSideQuestions } from "@/hooks/use-side-questions";
import { mergeActivities } from "@/lib/activity-merge";
import { api } from "@/lib/api";
import { shouldSubmitOnKey, useChatSendMode } from "@/lib/chat-send-mode";
import { formatBytes, formatTokens } from "@/lib/format";
import { getLocalStorageValue, removeLocalStorageValue, setLocalStorageValue } from "@/lib/local-storage.client";
import { isBtwCommand } from "@/lib/side-questions";
import type { Activity, Agent, ChatAttachment, Conversation, LLMProfile } from "@/lib/types";
import { cn } from "@/lib/utils";
import { intlLocale, t } from "@/i18n";

// fmtBytes renders a human file size for attachment chips (mirrors transcript.tsx).
function fmtBytes(n: number): string {
if (n >= 1 << 20) return `${(n / (1 << 20)).toFixed(1)} MB`;
if (n >= 1 << 10) return `${(n / (1 << 10)).toFixed(1)} KB`;
return `${n} B`;
}

// fmtTokens renders a compact token count (1234 → 1.2k, 2_000_000 → 2M).
function fmtTokens(n: number): string {
if (n >= 1_000_000) return `${(n / 1_000_000).toFixed(n >= 10_000_000 ? 0 : 1)}M`;
if (n >= 1000) return `${(n / 1000).toFixed(n >= 10000 ? 0 : 1)}k`;
return String(n);
}

// fmtDuration renders an elapsed milliseconds span compactly (90s → 1m30s).
function fmtDuration(ms: number): string {
const s = Math.floor(ms / 1000);
if (s < 60) return `${s}s`;
const m = Math.floor(s / 60);
if (m < 60) return `${m}m${String(s % 60).padStart(2, "0")}s`;
const h = Math.floor(m / 60);
return `${h}h${String(m % 60).padStart(2, "0")}m`;
}

// HISTORY_PAGE is how many steps one history page loads: the latest page on open,
// then one more page each time the user scrolls to the top. Kept modest so a long
// thread stays snappy (only ~a page of rows is in the DOM until you scroll up).
Expand Down Expand Up @@ -202,7 +179,7 @@ function Composer({
>
<PaperclipIcon className="size-3 shrink-0 text-primary" />
<span className="max-w-[160px] truncate">{a.name}</span>
<span className="text-muted-foreground">{fmtBytes(a.size)}</span>
<span className="text-muted-foreground">{formatBytes(a.size)}</span>
{onRemoveAttachment && (
<button
type="button"
Expand Down Expand Up @@ -798,9 +775,9 @@ function ChatView({
{tokenTotal.any && (
<span title={t("input / cache(read) / output tokens")} className="min-w-0 truncate tabular-nums">
{t("input {input} · cache {cache} · output {output}", {
input: fmtTokens(tokenTotal.i),
cache: fmtTokens(tokenTotal.cr),
output: fmtTokens(tokenTotal.o),
input: formatTokens(tokenTotal.i),
cache: formatTokens(tokenTotal.cr),
output: formatTokens(tokenTotal.o),
})}
</span>
)}
Expand Down
23 changes: 9 additions & 14 deletions web/src/app/(main)/dashboard/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import type {
TrafficExchange,
UsageStats,
} from "@/lib/types";
import { formatTokens } from "@/lib/format";
import { cn } from "@/lib/utils";
import { t } from "@/i18n";
import { setVisibleInterval } from "@/lib/polling";
Expand Down Expand Up @@ -66,12 +67,6 @@ function fmtRel(ts?: string | number): string {
return t("{n}d ago", { n: Math.floor(h / 24) });
}

function fmtTokens(n: number): string {
if (n >= 1_000_000) return (n / 1_000_000).toFixed(1) + "M";
if (n >= 1000) return (n / 1000).toFixed(1) + "k";
return String(n);
}

const ASSET_TYPE_LABELS: Record<string, string> = {
root_domain: t("Root domain"),
ip: "IP",
Expand Down Expand Up @@ -590,14 +585,14 @@ export default function DashboardPage() {
<ZapIcon className="size-3" /> {t("Token usage")}
</div>
<div className="text-2xl font-semibold tabular-nums">
{fmtTokens(displayedTokens.input + displayedTokens.output) || "—"}
{formatTokens(displayedTokens.input + displayedTokens.output) || "—"}
</div>
</CardHeader>
<CardContent className="text-[10px] text-muted-foreground">
{t("In {input} (incl. cache {cache}) · Out {output}", {
input: fmtTokens(displayedTokens.input),
cache: fmtTokens(displayedTokens.cacheRead),
output: fmtTokens(displayedTokens.output),
input: formatTokens(displayedTokens.input),
cache: formatTokens(displayedTokens.cacheRead),
output: formatTokens(displayedTokens.output),
})}
</CardContent>
</Card>
Expand Down Expand Up @@ -704,7 +699,7 @@ export default function DashboardPage() {
<div>
<div className="text-[10px] text-muted-foreground">{t("Total (input+output)")}</div>
<div className="mt-0.5 text-3xl font-bold tabular-nums tracking-tight">
{fmtTokens(displayedTokens.input + displayedTokens.output) || "—"}
{formatTokens(displayedTokens.input + displayedTokens.output) || "—"}
</div>
<div className="mt-0.5 text-[10px] text-muted-foreground">
{t("{count} tasks", { count: displayedTokens.taskCount })}
Expand Down Expand Up @@ -741,7 +736,7 @@ export default function DashboardPage() {
<div key={label}>
<div className="mb-1 flex items-center justify-between text-[10px]">
<span className="text-muted-foreground">{label}</span>
<span className={cn("font-mono font-semibold tabular-nums", text)}>{fmtTokens(value)}</span>
<span className={cn("font-mono font-semibold tabular-nums", text)}>{formatTokens(value)}</span>
</div>
<div className="h-1.5 overflow-hidden rounded-full bg-muted">
<div
Expand Down Expand Up @@ -834,7 +829,7 @@ export default function DashboardPage() {
interval="preserveStartEnd"
/>
<YAxis
tickFormatter={(v) => fmtTokens(Number(v))}
tickFormatter={(v) => formatTokens(Number(v))}
tickLine={false}
axisLine={false}
tick={{ fontSize: 10 }}
Expand All @@ -851,7 +846,7 @@ export default function DashboardPage() {
{(dailyTrendConfig as Record<string, { label: string }>)[String(name)]?.label ??
String(name)}
</span>
<span className="font-mono font-semibold tabular-nums">{fmtTokens(Number(value))}</span>
<span className="font-mono font-semibold tabular-nums">{formatTokens(Number(value))}</span>
</div>
)}
/>
Expand Down
13 changes: 4 additions & 9 deletions web/src/app/(main)/function/assets/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
import { api } from "@/lib/api";
import { parseCompanyScopeText } from "@/lib/company-scope";
import { httpHref } from "@/lib/http-href";
import { httpStatusTone } from "@/lib/status";
import type { Asset, Company, CompanyScopeRule } from "@/lib/types";
import { cn } from "@/lib/utils";
import { useActiveCompanyID } from "@/stores/company/company-store";
Expand Down Expand Up @@ -90,14 +91,6 @@ function MethodBadge({ method }: { method: string }) {
);
}

function statusTone(code: number) {
if (code >= 500) return "text-red-500";
if (code >= 400) return "text-amber-500";
if (code >= 300) return "text-blue-500";
if (code >= 200) return "text-emerald-500";
return "text-muted-foreground";
}

const PAGE_SIZES = [25, 50, 100, 200];

const TABS: { key: string; label: string; icon: LucideIcon }[] = [
Expand Down Expand Up @@ -646,7 +639,9 @@ export default function AssetsPage() {
<TableCell className="font-mono text-xs tabular-nums">{a.port || "—"}</TableCell>
<TableCell>
{a.status_code != null ? (
<span className={cn("font-mono text-xs font-semibold tabular-nums", statusTone(a.status_code))}>
<span
className={cn("font-mono text-xs font-semibold tabular-nums", httpStatusTone(a.status_code))}
>
{a.status_code}
</span>
) : (
Expand Down
17 changes: 4 additions & 13 deletions web/src/app/(main)/function/commands/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,10 @@ import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@
import { Sheet, SheetContent, SheetDescription, SheetHeader, SheetTitle } from "@/components/ui/sheet";
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table";
import { api } from "@/lib/api";
import { formatShortDateTime } from "@/lib/format";
import type { CommandRecord, ToolStat } from "@/lib/types";
import { cn } from "@/lib/utils";
import { intlLocale, t } from "@/i18n";

function fmtTime(ts: string) {
return new Date(ts).toLocaleString(intlLocale, {
month: "2-digit",
day: "2-digit",
hour: "2-digit",
minute: "2-digit",
second: "2-digit",
});
}
import { t } from "@/i18n";

// toolInput renders a tool's raw input for display. Bash's {"command":"..."} is
// unwrapped to the bare command; other tools show their pretty-printed JSON args.
Expand Down Expand Up @@ -235,7 +226,7 @@ export default function CommandsPage() {
onClick={() => setSelected(cmd)}
>
<TableCell className="text-xs text-muted-foreground tabular-nums">
{fmtTime(cmd.created_at)}
{formatShortDateTime(cmd.created_at)}
</TableCell>
<TableCell className="text-xs font-mono text-muted-foreground">#{cmd.exploration_id}</TableCell>
<TableCell>
Expand Down Expand Up @@ -340,7 +331,7 @@ export default function CommandsPage() {
<>
<SheetHeader className="border-b px-5 py-4">
<SheetTitle className="pr-8">{t("Tool execution details")}</SheetTitle>
<SheetDescription>{fmtTime(selected.created_at)}</SheetDescription>
<SheetDescription>{formatShortDateTime(selected.created_at)}</SheetDescription>
<div className="flex flex-wrap items-center gap-2 pt-2">
<Badge variant="outline" className="text-xs font-mono">
#{selected.exploration_id}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import { Label } from "@/components/ui/label";
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
import { Spinner } from "@/components/ui/spinner";
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table";
import { formatShortDateTime } from "@/lib/format";
import { statusMeta, type Tone, toneClasses } from "@/lib/status";
import type {
ActiveFindingRetest,
Expand All @@ -46,7 +47,7 @@ import type {
VerificationStatus,
} from "@/lib/types";
import { cn } from "@/lib/utils";
import { intlLocale, t } from "@/i18n";
import { t } from "@/i18n";

export const SEVERITIES: Severity[] = ["critical", "high", "medium", "low"];

Expand Down Expand Up @@ -155,15 +156,6 @@ export function isSameFinding(left: Finding, right: Finding): boolean {
return findingRowKey(left) === findingRowKey(right);
}

export function fmtTime(ts: string) {
return new Date(ts).toLocaleString(intlLocale, {
month: "2-digit",
day: "2-digit",
hour: "2-digit",
minute: "2-digit",
});
}

const COLUMN_COUNT = 10;

interface FindingsTableProps {
Expand Down Expand Up @@ -374,7 +366,9 @@ export function FindingsTable({
<span className="text-muted-foreground">—</span>
)}
</TableCell>
<TableCell className="text-xs text-muted-foreground tabular-nums">{fmtTime(f.ts)}</TableCell>
<TableCell className="text-xs text-muted-foreground tabular-nums">
{formatShortDateTime(f.ts, { seconds: false })}
</TableCell>
<TableCell onClick={(e) => e.stopPropagation()}>
<div className="flex items-center gap-1">
{retest ? (
Expand Down
4 changes: 2 additions & 2 deletions web/src/app/(main)/function/findings/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import { Tabs, TabsList, TabsTrigger } from "@/components/ui/tabs";
import { Textarea } from "@/components/ui/textarea";
import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group";
import { api } from "@/lib/api";
import { formatShortDateTime } from "@/lib/format";
import { getLocalStorageValue, setLocalStorageValue } from "@/lib/local-storage.client";
import { statusMeta } from "@/lib/status";
import type {
Expand All @@ -65,7 +66,6 @@ import {
type FindingReport,
FindingsTable,
findingRowKey,
fmtTime,
isSameFinding,
REPORT_STATE_META,
SEVERITIES,
Expand Down Expand Up @@ -1350,7 +1350,7 @@ export default function FindingsPage() {
);
})}
<span className="text-xs tabular-nums text-muted-foreground">
{fmtTime(group.last_found_at)}
{formatShortDateTime(group.last_found_at, { seconds: false })}
</span>
{group.task_id !== null && (
<Button size="icon-sm" variant="ghost" asChild>
Expand Down
26 changes: 5 additions & 21 deletions web/src/app/(main)/function/llm-records/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,31 +44,17 @@ import {
SelectTrigger,
SelectValue,
} from "@/components/ui/select";
import { formatShortDateTime, formatTokens } from "@/lib/format";
import { cn } from "@/lib/utils";
import { intlLocale, t } from "@/i18n";
import { t } from "@/i18n";
import { api } from "@/lib/api";
import type { LLMRecordItem, LLMRecordDetail, LLMTask } from "@/lib/types";

function fmtTime(ts: string) {
return new Date(ts).toLocaleString(intlLocale, {
month: "2-digit",
day: "2-digit",
hour: "2-digit",
minute: "2-digit",
second: "2-digit",
});
}

function fmtLatency(ms: number) {
if (ms < 1000) return `${ms}ms`;
return `${(ms / 1000).toFixed(1)}s`;
}

function fmtTokens(n: number) {
if (n >= 1000) return `${(n / 1000).toFixed(1)}k`;
return String(n);
}

function tryFormatJSON(s: string): string {
try {
return JSON.stringify(JSON.parse(s), null, 2);
Expand Down Expand Up @@ -424,7 +410,7 @@ export default function LLMRecordsPage() {
onClick={() => setSelected(rec)}
>
<TableCell className="text-xs text-muted-foreground tabular-nums">
{fmtTime(rec.ts)}
{formatShortDateTime(rec.ts)}
</TableCell>
<TableCell className="text-xs font-mono text-muted-foreground">
{rec.task_id ? `#${rec.task_id}` : "-"}
Expand All @@ -447,7 +433,7 @@ export default function LLMRecordsPage() {
</TableCell>
<TableCell>
<span className="text-xs">
{fmtTokens(rec.input_tokens)} / {fmtTokens(rec.output_tokens)}
{formatTokens(rec.input_tokens)} / {formatTokens(rec.output_tokens)}
</span>
</TableCell>
<TableCell>
Expand Down Expand Up @@ -484,9 +470,7 @@ export default function LLMRecordsPage() {
{t("Task #{id}", { id: selected.task_id })}
</Badge>
)}
<span className="text-xs text-muted-foreground">
{fmtTime(selected.ts)}
</span>
<span className="text-xs text-muted-foreground">{formatShortDateTime(selected.ts)}</span>
<span className={cn("text-xs", selected.latency_ms > 30000 && "text-amber-500")}>
{fmtLatency(selected.latency_ms)}
</span>
Expand Down
26 changes: 9 additions & 17 deletions web/src/app/(main)/function/tasks/detail/_tabs/assets-tab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";
import { api } from "@/lib/api";
import { parseCompanyScopeText } from "@/lib/company-scope";
import { formatBytes } from "@/lib/format";
import { httpStatusTone } from "@/lib/status";
import { taskAssetSourceLabel } from "@/lib/task-assets";
import type { Asset, NewAssetType } from "@/lib/types";
import { cn } from "@/lib/utils";
Expand Down Expand Up @@ -104,21 +106,6 @@ function MethodBadge({ method }: { method: string }) {
);
}

function statusTone(code: number) {
if (code >= 500) return "text-red-500";
if (code >= 400) return "text-amber-500";
if (code >= 300) return "text-blue-500";
if (code >= 200) return "text-emerald-500";
return "text-muted-foreground";
}

function fmtBytes(value?: number | null) {
if (!value || !Number.isFinite(value) || value <= 0) return "—";
const units = ["B", "KB", "MB"];
const index = Math.min(Math.floor(Math.log(value) / Math.log(1024)), units.length - 1);
return `${index === 0 ? value : (value / 1024 ** index).toFixed(1)} ${units[index]}`;
}

function Chips({ items, mono }: { items: string[]; mono?: boolean }) {
const clean = items.filter(Boolean);
if (clean.length === 0) return <span className="text-muted-foreground text-xs">—</span>;
Expand Down Expand Up @@ -641,7 +628,10 @@ export function AssetsTab({ taskId }: { taskId: string }) {
<TableCell>
{asset.status_code != null ? (
<span
className={cn("font-mono font-semibold text-xs tabular-nums", statusTone(asset.status_code))}
className={cn(
"font-mono font-semibold text-xs tabular-nums",
httpStatusTone(asset.status_code),
)}
>
{asset.status_code}
</span>
Expand All @@ -650,7 +640,9 @@ export function AssetsTab({ taskId }: { taskId: string }) {
)}
</TableCell>
<TableCell className="max-w-48 truncate text-xs">{asset.page_title || "—"}</TableCell>
<TableCell className="text-xs tabular-nums">{fmtBytes(asset.content_length)}</TableCell>
<TableCell className="text-xs tabular-nums">
{formatBytes(asset.content_length, { empty: "—" })}
</TableCell>
<TableCell>
<Chips items={asset.technologies ?? []} />
</TableCell>
Expand Down
Loading
Loading