Three hand-rolled compact-number formatters and two mirrored copies of the
reasoning-effort value set collapse into apps/shared/src/format.ts and
apps/shared/src/reasoning-effort.ts, exported from the package root and as
the subpaths `@hermes/shared/format` / `@hermes/shared/reasoning-effort`
(the TUI compiles with lib ES2023 and imports subpaths only). Surfaces keep
their own label maps and UI helpers. No re-export shims remain.
Convention for compactNumber (desktop's implementation, moved verbatim):
lowercase 'k', uppercase 'M', promotion-guarded thresholds (>= 999.5 -> k,
>= 999_950 -> M) so rounding can never print "1000k", trailing ".0"
stripped, non-finite / <= 0 -> "0".
Sites (path::symbol -> canonical):
apps/desktop/src/lib/format.ts::compactNumber -> apps/shared/src/format.ts::compactNumber (moved; file deleted)
web/src/lib/format.ts::formatTokenCount -> deleted
ui-tui/src/lib/text.ts::fmtK -> deleted (text.ts's own callers use compactNumber)
apps/desktop/src/app/agents/index.tsx -> @hermes/shared
apps/desktop/src/app/chat/sidebar/chrome.tsx -> @hermes/shared
apps/desktop/src/app/chat/sidebar/session-row.tsx -> @hermes/shared
apps/desktop/src/app/command-center/index.tsx -> @hermes/shared
apps/desktop/src/app/shell/context-usage-panel.tsx -> @hermes/shared
apps/desktop/src/app/shell/titlebar-controls.tsx -> @hermes/shared
apps/desktop/src/app/skills/index.tsx -> @hermes/shared
apps/desktop/src/app/skills/mcp-tab.tsx -> @hermes/shared
apps/desktop/src/components/ui/tab-dropdown.tsx -> @hermes/shared
apps/desktop/src/lib/statusbar.tsx -> @hermes/shared
apps/desktop/src/sdk/index.ts::compactNumber -> re-exported from @hermes/shared (plugin SDK surface unchanged)
apps/desktop/src/plugins/kanban/{board,drawer}.tsx -> unchanged (import via @hermes/plugin-sdk)
web/src/components/ModelInfoCard.tsx::formatTokenCount -> @hermes/shared::compactNumber
web/src/pages/ModelsPage.tsx::formatTokenCount -> @hermes/shared::compactNumber
ui-tui/src/components/appChrome.tsx::fmtK -> @hermes/shared/format::compactNumber
ui-tui/src/components/thinking.tsx::fmtK -> @hermes/shared/format::compactNumber
ui-tui/src/app/slash/commands/session.ts::fmtK -> @hermes/shared/format::compactNumber
ui-tui/src/__tests__/text.test.ts::fmtK suite -> apps/shared/src/format.test.ts (table incl. promotion guard)
apps/desktop/src/lib/reasoning-effort.ts::REASONING_EFFORTS/REASONING_EFFORT_VALUES/
DEFAULT_REASONING_EFFORT/ReasoningEffort/isReasoningEffort -> apps/shared/src/reasoning-effort.ts
(SHORT_LABELS, reasoningEffortLabel, isThinkingEnabled, resolveReasoningEffort stay local)
apps/desktop/src/app/settings/constants.ts -> @hermes/shared
apps/desktop/src/app/settings/model-settings.tsx -> @hermes/shared
apps/desktop/src/app/shell/model-catalog-menu.tsx -> @hermes/shared (+ local reasoningEffortLabel)
apps/desktop/src/app/shell/model-edit-submenu.tsx -> @hermes/shared (+ local UI helpers)
apps/desktop/src/app/shell/model-menu-panel.tsx -> @hermes/shared
apps/desktop/src/lib/model-status-label.ts -> @hermes/shared (+ local reasoningEffortLabel)
apps/desktop/src/sdk/index.ts -> value set re-exported from @hermes/shared; label helper stays from '@/lib/reasoning-effort'
apps/desktop/src/lib/reasoning-effort.test.ts -> value-set + isReasoningEffort cases moved to apps/shared/src/reasoning-effort.test.ts
web/src/lib/reasoning-effort.ts::EFFORT_OPTIONS -> labels mapped over shared REASONING_EFFORT_VALUES (same order: none, then 7 levels)
web/src/lib/reasoning-effort.ts::VALID_EFFORTS -> Set(REASONING_EFFORT_VALUES); normalizeEffort falls back to DEFAULT_REASONING_EFFORT
Semantics kept: web `none` is selectable; desktop `none` resolves to ''
(thinking off); desktop isReasoningEffort still trims + lowercases.
Behavior change:
- web: token counts on the Models page and ModelInfoCard now print a
lowercase 'k' and are promotion-guarded: 128_000 "128K" -> "128k",
999_999 "1000.0K" -> "1M", 1_500 "1.5K" -> "1.5k". 'M' is unchanged.
- TUI: fmtK used Intl compact notation; compactNumber differs only in
suffix case and the guard: 1_000_000 "1m" -> "1M", and billions no
longer get a 'b' suffix (1_000_000_000 "1b" -> "1000M"). Sub-million
values are identical ("999", "1k", "1.5k"). Non-positive values now
print "0" instead of "-1k".
- desktop: none (its formatter moved verbatim).
Tests: apps/shared/src/format.test.ts::"compactNumber" (table incl.
999_999 -> "1M", 999_949 -> "999.9k"; fails when the promotion guard is
removed) and apps/shared/src/reasoning-effort.test.ts::"reasoning-effort"
(no duplicate values, `none` is the only non-level, default is a member;
fails on a duplicated level or a `none`-accepting isReasoningEffort).
113 lines
4.1 KiB
TypeScript
113 lines
4.1 KiB
TypeScript
import { useEffect, useRef, useState } from "react";
|
|
import { Brain, Eye, Gauge, Lightbulb, Wrench } from "lucide-react";
|
|
import { Spinner } from "@nous-research/ui/ui/components/spinner";
|
|
import { api } from "@/lib/api";
|
|
import type { ModelInfoResponse } from "@/lib/api";
|
|
import { compactNumber } from "@hermes/shared";
|
|
|
|
interface ModelInfoCardProps {
|
|
/** Current model string from config state — used to detect changes */
|
|
currentModel: string;
|
|
/** Bumped after config saves to trigger re-fetch */
|
|
refreshKey?: number;
|
|
}
|
|
|
|
export function ModelInfoCard({
|
|
currentModel,
|
|
refreshKey = 0,
|
|
}: ModelInfoCardProps) {
|
|
const [info, setInfo] = useState<ModelInfoResponse | null>(null);
|
|
const [loading, setLoading] = useState(false);
|
|
const lastFetchKeyRef = useRef("");
|
|
|
|
useEffect(() => {
|
|
if (!currentModel) return;
|
|
// Re-fetch when model changes OR when refreshKey bumps (after save)
|
|
const fetchKey = `${currentModel}:${refreshKey}`;
|
|
if (fetchKey === lastFetchKeyRef.current) return;
|
|
lastFetchKeyRef.current = fetchKey;
|
|
setLoading(true);
|
|
api
|
|
.getModelInfo()
|
|
.then(setInfo)
|
|
.catch(() => setInfo(null))
|
|
.finally(() => setLoading(false));
|
|
}, [currentModel, refreshKey]);
|
|
|
|
if (loading) {
|
|
return (
|
|
<div className="flex items-center gap-2 py-2 text-xs text-muted-foreground">
|
|
<Spinner className="text-xs" />
|
|
Loading model info…
|
|
</div>
|
|
);
|
|
}
|
|
|
|
if (!info || !info.model || info.effective_context_length <= 0) return null;
|
|
|
|
const caps = info.capabilities;
|
|
const hasCaps = caps && Object.keys(caps).length > 0;
|
|
|
|
return (
|
|
<div className="border border-border/60 bg-muted/30 px-3 py-2.5 space-y-2">
|
|
<div className="flex items-center gap-4 text-xs">
|
|
<div className="flex items-center gap-1.5 text-muted-foreground">
|
|
<Gauge className="h-3.5 w-3.5" />
|
|
<span className="font-medium">Context Window</span>
|
|
</div>
|
|
<div className="flex items-center gap-2">
|
|
<span className="font-mono font-semibold text-foreground">
|
|
{compactNumber(info.effective_context_length)}
|
|
</span>
|
|
{info.config_context_length > 0 ? (
|
|
<span className="text-amber-500 text-xs">
|
|
(override — auto: {compactNumber(info.auto_context_length)})
|
|
</span>
|
|
) : (
|
|
<span className="text-text-tertiary text-xs">
|
|
auto-detected
|
|
</span>
|
|
)}
|
|
</div>
|
|
</div>
|
|
|
|
{hasCaps && caps.max_output_tokens && caps.max_output_tokens > 0 && (
|
|
<div className="flex items-center gap-4 text-xs">
|
|
<div className="flex items-center gap-1.5 text-muted-foreground">
|
|
<Lightbulb className="h-3.5 w-3.5" />
|
|
<span className="font-medium">Max Output</span>
|
|
</div>
|
|
<span className="font-mono font-semibold text-foreground">
|
|
{compactNumber(caps.max_output_tokens)}
|
|
</span>
|
|
</div>
|
|
)}
|
|
|
|
{hasCaps && (
|
|
<div className="flex flex-wrap items-center gap-1.5 pt-0.5">
|
|
{caps.supports_tools && (
|
|
<span className="inline-flex items-center gap-1 bg-success/10 px-2 py-0.5 text-xs font-medium text-success">
|
|
<Wrench className="h-2.5 w-2.5" /> Tools
|
|
</span>
|
|
)}
|
|
{caps.supports_vision && (
|
|
<span className="inline-flex items-center gap-1 bg-blue-500/10 px-2 py-0.5 text-xs font-medium text-blue-600 dark:text-blue-400">
|
|
<Eye className="h-2.5 w-2.5" /> Vision
|
|
</span>
|
|
)}
|
|
{caps.supports_reasoning && (
|
|
<span className="inline-flex items-center gap-1 bg-purple-500/10 px-2 py-0.5 text-xs font-medium text-purple-600 dark:text-purple-400">
|
|
<Brain className="h-2.5 w-2.5" /> Reasoning
|
|
</span>
|
|
)}
|
|
{caps.model_family && (
|
|
<span className="inline-flex items-center gap-1 bg-muted px-2 py-0.5 text-xs font-medium text-text-secondary">
|
|
{caps.model_family}
|
|
</span>
|
|
)}
|
|
</div>
|
|
)}
|
|
</div>
|
|
);
|
|
}
|