Spaces:
Build error
Build error
Sync from GitHub via hub-sync
Browse files
dashboard/src/playground/Header.test.tsx
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// @vitest-environment jsdom
|
| 2 |
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
| 3 |
+
import { cleanup, fireEvent, render, screen } from '@testing-library/react';
|
| 4 |
+
import { Header, modelLabel, openableModels } from './Header';
|
| 5 |
+
import { useStore } from './store';
|
| 6 |
+
import type { ModelSummary, SessionSummary } from './types';
|
| 7 |
+
|
| 8 |
+
const qwen: ModelSummary = {
|
| 9 |
+
model_id: 'qwen3_5_0_8b_abliterated', backend: 'qwen', domain: 'text', status: 'completed', params: 752_393_024,
|
| 10 |
+
calibrated: false, has_canary: false, created_at_unix: 0, updated_at_unix: 0, parent_model_id: null,
|
| 11 |
+
};
|
| 12 |
+
const core: ModelSummary = { ...qwen, model_id: 'lm_wikitext_l4', backend: 'plastic', params: 6_845_984, calibrated: true, has_canary: true, chat_tuned: false };
|
| 13 |
+
const physics: ModelSummary = { ...core, model_id: 'phys', domain: 'physics' };
|
| 14 |
+
const child: ModelSummary = { ...qwen, model_id: 'sleep_1', parent_model_id: 'qwen3_5_0_8b_abliterated' };
|
| 15 |
+
|
| 16 |
+
function session(id: string, model: string, domain: 'text' | 'physics' = 'text'): SessionSummary {
|
| 17 |
+
return { session_id: id, model_id: model, domain, parent_session_id: null, created_at_unix: 0, updated_at_unix: 0, pos: 0, n_transactions: 0,
|
| 18 |
+
commits: 0, rollbacks: 0, scales: 0, projects: 0, readonly: 0, read_only: false, read_only_reason: null } as unknown as SessionSummary;
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
const initial = useStore.getState();
|
| 22 |
+
let selected: (string | null)[];
|
| 23 |
+
|
| 24 |
+
beforeEach(() => {
|
| 25 |
+
selected = [];
|
| 26 |
+
useStore.setState({ ...initial, health: { ok: true, artifacts_root: '', device: 'cpu', n_models: 1, n_sessions: 1, public: true,
|
| 27 |
+
capabilities: { create_session: false, fork: false, reset: true, delete: false, resume: true, calibrate: false, sleep: false } },
|
| 28 |
+
selectSession: async (id: string | null) => { selected.push(id); useStore.setState({ currentSessionId: id }); } }, true);
|
| 29 |
+
});
|
| 30 |
+
afterEach(() => { cleanup(); useStore.setState(initial, true); vi.restoreAllMocks(); });
|
| 31 |
+
|
| 32 |
+
describe('header model and session pickers', () => {
|
| 33 |
+
it('shows a single model and session as plain text, not a one-option menu', () => {
|
| 34 |
+
useStore.setState({ models: [qwen], sessions: [session('demo_text', qwen.model_id)], currentSessionId: 'demo_text' });
|
| 35 |
+
render(<Header />);
|
| 36 |
+
expect(screen.queryByRole('combobox')).toBeNull();
|
| 37 |
+
expect(screen.getByText('qwen3_5_0_8b_abliterated · Gated DeltaNet (Qwen3.5) · 752M')).toBeTruthy();
|
| 38 |
+
});
|
| 39 |
+
|
| 40 |
+
it('offers every openable model and opens the chosen model’s session', () => {
|
| 41 |
+
useStore.setState({ models: [qwen, core, physics], sessions: [session('demo_text', qwen.model_id), session('demo_core', core.model_id), session('demo_physics', 'phys', 'physics')], currentSessionId: 'demo_text' });
|
| 42 |
+
render(<Header />);
|
| 43 |
+
const picker = screen.getByRole('combobox', { name: 'Model' }) as HTMLSelectElement;
|
| 44 |
+
expect([...picker.options].map((o) => o.textContent)).toEqual(['qwen3_5_0_8b_abliterated · Gated DeltaNet (Qwen3.5) · 752M', 'lm_wikitext_l4 · Plastic delta memory · 6.8M']);
|
| 45 |
+
fireEvent.change(picker, { target: { value: 'lm_wikitext_l4' } });
|
| 46 |
+
expect(selected).toEqual(['demo_core']);
|
| 47 |
+
expect(screen.queryByRole('combobox', { name: 'Session' })).toBeNull(); // one session per model
|
| 48 |
+
});
|
| 49 |
+
|
| 50 |
+
it('adds a session menu only when the chosen model has several sessions', () => {
|
| 51 |
+
useStore.setState({ models: [qwen], sessions: [session('a', qwen.model_id), session('b', qwen.model_id)], currentSessionId: 'a' });
|
| 52 |
+
render(<Header />);
|
| 53 |
+
expect(screen.queryByRole('combobox', { name: 'Model' })).toBeNull();
|
| 54 |
+
const s = screen.getByRole('combobox', { name: 'Session' }) as HTMLSelectElement;
|
| 55 |
+
fireEvent.change(s, { target: { value: 'b' } });
|
| 56 |
+
expect(selected).toEqual(['b']);
|
| 57 |
+
});
|
| 58 |
+
|
| 59 |
+
it('lists only models the server returned that have a text session, and names sleep children', () => {
|
| 60 |
+
const list = openableModels([qwen, core, child], [session('demo_text', qwen.model_id), session('demo_sleep_1', 'sleep_1')]);
|
| 61 |
+
expect(list.map((m) => m.model_id)).toEqual(['qwen3_5_0_8b_abliterated', 'sleep_1']);
|
| 62 |
+
expect(modelLabel(child)).toBe('sleep_1 · Gated DeltaNet (Qwen3.5) · 752M · sleep child of qwen3_5_0_8b_abliterated');
|
| 63 |
+
});
|
| 64 |
+
});
|
dashboard/src/playground/Header.tsx
CHANGED
|
@@ -1,7 +1,49 @@
|
|
| 1 |
import { backendLabel, modeLabel } from './format';
|
| 2 |
import { TABS, TAB_LABELS, useStore } from './store';
|
|
|
|
| 3 |
import { Select, StateChip } from './ui';
|
| 4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
export function Header() {
|
| 6 |
const health = useStore((s) => s.health);
|
| 7 |
const sessions = useStore((s) => s.sessions);
|
|
@@ -14,9 +56,18 @@ export function Header() {
|
|
| 14 |
const setTab = useStore((s) => s.setTab);
|
| 15 |
|
| 16 |
const text = sessions.filter((s) => s.domain === 'text');
|
| 17 |
-
const
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
const connected = health !== null && !stale;
|
| 19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
return (
|
| 21 |
<header className="border-b border-edge bg-surface-raised">
|
| 22 |
<div className="mx-auto flex max-w-[1500px] flex-wrap items-center gap-x-5 gap-y-3 px-4 py-3">
|
|
@@ -41,27 +92,33 @@ export function Header() {
|
|
| 41 |
</button>
|
| 42 |
))}
|
| 43 |
</nav>
|
| 44 |
-
<div className="ml-auto flex flex-wrap items-center gap-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
{detail ? (
|
| 46 |
<>
|
| 47 |
-
<StateChip>{backendLabel(detail.summary.backend ?? model?.backend)}</StateChip>
|
| 48 |
<StateChip tone={modeLabel(detail.meta.harness) === 'guarded' ? 'warn' : 'default'}>{modeLabel(detail.meta.harness)}</StateChip>
|
| 49 |
{model && model.chat_tuned === false ? <StateChip tone="warn">base model, not chat-tuned</StateChip> : null}
|
| 50 |
</>
|
| 51 |
) : null}
|
| 52 |
-
<label className="flex items-center gap-2 text-label font-semibold uppercase tracking-wide text-ink-muted">
|
| 53 |
-
Session
|
| 54 |
-
<span className="w-52">
|
| 55 |
-
<Select aria-label="Session" value={current ?? ''} onChange={(e) => void selectSession(e.target.value || null)} disabled={text.length === 0}>
|
| 56 |
-
{text.length === 0 ? <option value="">no text session</option> : null}
|
| 57 |
-
{text.map((s) => (
|
| 58 |
-
<option key={s.session_id} value={s.session_id}>
|
| 59 |
-
{s.session_id}
|
| 60 |
-
</option>
|
| 61 |
-
))}
|
| 62 |
-
</Select>
|
| 63 |
-
</span>
|
| 64 |
-
</label>
|
| 65 |
</div>
|
| 66 |
</div>
|
| 67 |
</header>
|
|
|
|
| 1 |
import { backendLabel, modeLabel } from './format';
|
| 2 |
import { TABS, TAB_LABELS, useStore } from './store';
|
| 3 |
+
import type { ModelSummary, SessionSummary } from './types';
|
| 4 |
import { Select, StateChip } from './ui';
|
| 5 |
|
| 6 |
+
function shortParams(n: number | undefined): string {
|
| 7 |
+
if (typeof n !== 'number' || !Number.isFinite(n) || n <= 0) return '';
|
| 8 |
+
return n >= 1e9 ? `${(n / 1e9).toFixed(1)}B` : n >= 1e6 ? `${(n / 1e6).toFixed(n >= 1e8 ? 0 : 1)}M` : `${Math.round(n / 1e3)}K`;
|
| 9 |
+
}
|
| 10 |
+
|
| 11 |
+
/** A model as a visitor should read it: its id, the learner, its size, and whether sleep produced it. */
|
| 12 |
+
export function modelLabel(m: ModelSummary): string {
|
| 13 |
+
const size = shortParams(m.params);
|
| 14 |
+
return [m.model_id, backendLabel(m.backend), size, m.parent_model_id ? `sleep child of ${m.parent_model_id}` : null].filter(Boolean).join(' · ');
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
/** Models a visitor can open: the server's catalog, text only, with at least one session to open it in. */
|
| 18 |
+
export function openableModels(models: ModelSummary[], sessions: SessionSummary[]): ModelSummary[] {
|
| 19 |
+
return models.filter((m) => m.domain === 'text' && sessions.some((s) => s.domain === 'text' && s.model_id === m.model_id));
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
function Picker({ label, value, options, onChange }: { label: string; value: string; options: { value: string; text: string; title?: string }[]; onChange: (v: string) => void }) {
|
| 23 |
+
const current = options.find((o) => o.value === value);
|
| 24 |
+
return (
|
| 25 |
+
<div className="flex items-center gap-2">
|
| 26 |
+
<span className="text-label font-semibold uppercase tracking-wide text-ink-muted">{label}</span>
|
| 27 |
+
{options.length > 1 ? (
|
| 28 |
+
<span className="inline-block min-w-[15rem] max-w-[34rem]">
|
| 29 |
+
<Select aria-label={label} value={value} onChange={(e) => onChange(e.target.value)}>
|
| 30 |
+
{options.map((o) => (
|
| 31 |
+
<option key={o.value} value={o.value} title={o.title}>
|
| 32 |
+
{o.text}
|
| 33 |
+
</option>
|
| 34 |
+
))}
|
| 35 |
+
</Select>
|
| 36 |
+
</span>
|
| 37 |
+
) : (
|
| 38 |
+
// one choice is a fact, not a menu
|
| 39 |
+
<span className="font-mono text-sm text-ink-primary" title={current?.title}>
|
| 40 |
+
{current?.text ?? 'none'}
|
| 41 |
+
</span>
|
| 42 |
+
)}
|
| 43 |
+
</div>
|
| 44 |
+
);
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
export function Header() {
|
| 48 |
const health = useStore((s) => s.health);
|
| 49 |
const sessions = useStore((s) => s.sessions);
|
|
|
|
| 56 |
const setTab = useStore((s) => s.setTab);
|
| 57 |
|
| 58 |
const text = sessions.filter((s) => s.domain === 'text');
|
| 59 |
+
const openable = openableModels(models, sessions);
|
| 60 |
+
const currentSession = text.find((s) => s.session_id === current);
|
| 61 |
+
const modelId = currentSession?.model_id ?? detail?.meta.model_id ?? '';
|
| 62 |
+
const model = models.find((m) => m.model_id === modelId);
|
| 63 |
+
const modelSessions = text.filter((s) => s.model_id === modelId);
|
| 64 |
const connected = health !== null && !stale;
|
| 65 |
|
| 66 |
+
const chooseModel = (id: string) => {
|
| 67 |
+
const first = text.find((s) => s.model_id === id);
|
| 68 |
+
if (first) void selectSession(first.session_id);
|
| 69 |
+
};
|
| 70 |
+
|
| 71 |
return (
|
| 72 |
<header className="border-b border-edge bg-surface-raised">
|
| 73 |
<div className="mx-auto flex max-w-[1500px] flex-wrap items-center gap-x-5 gap-y-3 px-4 py-3">
|
|
|
|
| 92 |
</button>
|
| 93 |
))}
|
| 94 |
</nav>
|
| 95 |
+
<div className="ml-auto flex flex-wrap items-center gap-x-4 gap-y-2">
|
| 96 |
+
{text.length === 0 ? (
|
| 97 |
+
<span className="text-sm text-ink-secondary">no text session</span>
|
| 98 |
+
) : (
|
| 99 |
+
<>
|
| 100 |
+
<Picker
|
| 101 |
+
label="Model"
|
| 102 |
+
value={modelId}
|
| 103 |
+
options={openable.map((m) => ({ value: m.model_id, text: modelLabel(m), title: m.model_id }))}
|
| 104 |
+
onChange={chooseModel}
|
| 105 |
+
/>
|
| 106 |
+
{modelSessions.length > 1 ? (
|
| 107 |
+
<Picker
|
| 108 |
+
label="Session"
|
| 109 |
+
value={current ?? ''}
|
| 110 |
+
options={modelSessions.map((s) => ({ value: s.session_id, text: s.session_id }))}
|
| 111 |
+
onChange={(v) => void selectSession(v || null)}
|
| 112 |
+
/>
|
| 113 |
+
) : null}
|
| 114 |
+
</>
|
| 115 |
+
)}
|
| 116 |
{detail ? (
|
| 117 |
<>
|
|
|
|
| 118 |
<StateChip tone={modeLabel(detail.meta.harness) === 'guarded' ? 'warn' : 'default'}>{modeLabel(detail.meta.harness)}</StateChip>
|
| 119 |
{model && model.chat_tuned === false ? <StateChip tone="warn">base model, not chat-tuned</StateChip> : null}
|
| 120 |
</>
|
| 121 |
) : null}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 122 |
</div>
|
| 123 |
</div>
|
| 124 |
</header>
|