@nastechai/agent 0.16.0 → 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/eslint.config.js +23 -0
- package/index.html +24 -0
- package/package.json +54 -26
- package/package.json.bak +89 -0
- package/package.json.pub +88 -0
- package/src/App.tsx +1173 -0
- package/src/components/AuthWidget.tsx +150 -0
- package/src/components/AutoField.tsx +206 -0
- package/src/components/Backdrop.tsx +93 -0
- package/src/components/ChatSidebar.tsx +394 -0
- package/src/components/DeleteConfirmDialog.tsx +40 -0
- package/src/components/LanguageSwitcher.tsx +186 -0
- package/src/components/Markdown.tsx +383 -0
- package/src/components/ModelInfoCard.tsx +112 -0
- package/src/components/ModelPickerDialog.tsx +470 -0
- package/src/components/OAuthLoginModal.tsx +374 -0
- package/src/components/OAuthProvidersCard.tsx +287 -0
- package/src/components/PlatformsCard.tsx +97 -0
- package/src/components/ScheduleBuilder.tsx +273 -0
- package/src/components/SidebarFooter.tsx +42 -0
- package/src/components/SidebarStatusStrip.tsx +72 -0
- package/src/components/SlashPopover.tsx +171 -0
- package/src/components/ThemeSwitcher.tsx +243 -0
- package/src/components/ToolCall.tsx +228 -0
- package/src/components/ToolsetConfigDrawer.tsx +448 -0
- package/src/contexts/PageHeaderProvider.tsx +139 -0
- package/src/contexts/SystemActions.tsx +120 -0
- package/src/contexts/page-header-context.ts +12 -0
- package/src/contexts/system-actions-context.ts +18 -0
- package/src/contexts/usePageHeader.ts +10 -0
- package/src/contexts/useSystemActions.ts +15 -0
- package/src/hooks/useModalBehavior.ts +44 -0
- package/src/hooks/useSidebarStatus.ts +27 -0
- package/src/i18n/af.ts +702 -0
- package/src/i18n/context.tsx +123 -0
- package/src/i18n/de.ts +701 -0
- package/src/i18n/en.ts +708 -0
- package/src/i18n/es.ts +701 -0
- package/src/i18n/fr.ts +701 -0
- package/src/i18n/ga.ts +702 -0
- package/src/i18n/hu.ts +702 -0
- package/src/i18n/index.ts +2 -0
- package/src/i18n/it.ts +701 -0
- package/src/i18n/ja.ts +702 -0
- package/src/i18n/ko.ts +702 -0
- package/src/i18n/pt.ts +702 -0
- package/src/i18n/ru.ts +702 -0
- package/src/i18n/tr.ts +702 -0
- package/src/i18n/types.ts +710 -0
- package/src/i18n/uk.ts +702 -0
- package/src/i18n/zh-hant.ts +702 -0
- package/src/i18n/zh.ts +698 -0
- package/src/index.css +274 -0
- package/src/lib/api.ts +1585 -0
- package/src/lib/dashboard-flags.ts +15 -0
- package/src/lib/format.ts +9 -0
- package/src/lib/fuzzy.ts +192 -0
- package/src/lib/gatewayClient.ts +253 -0
- package/src/lib/nested.ts +23 -0
- package/src/lib/resolve-page-title.ts +41 -0
- package/src/lib/schedule.ts +382 -0
- package/src/lib/slashExec.ts +163 -0
- package/src/lib/utils.ts +35 -0
- package/src/main.tsx +25 -0
- package/src/pages/AnalyticsPage.tsx +601 -0
- package/src/pages/ChannelsPage.tsx +772 -0
- package/src/pages/ChatPage.tsx +889 -0
- package/src/pages/ConfigPage.tsx +660 -0
- package/src/pages/CronPage.tsx +524 -0
- package/src/pages/DocsPage.tsx +69 -0
- package/src/pages/EnvPage.tsx +918 -0
- package/src/pages/LogsPage.tsx +246 -0
- package/src/pages/McpPage.tsx +757 -0
- package/src/pages/ModelsPage.tsx +994 -0
- package/src/pages/PairingPage.tsx +276 -0
- package/src/pages/PluginsPage.tsx +580 -0
- package/src/pages/ProfilesPage.tsx +559 -0
- package/src/pages/SessionsPage.tsx +936 -0
- package/src/pages/SkillsPage.tsx +557 -0
- package/src/pages/SystemPage.tsx +1259 -0
- package/src/pages/WebhooksPage.tsx +483 -0
- package/src/plugins/PluginPage.tsx +64 -0
- package/src/plugins/index.ts +6 -0
- package/src/plugins/registry.ts +151 -0
- package/src/plugins/sdk.d.ts +160 -0
- package/src/plugins/slots.ts +199 -0
- package/src/plugins/types.ts +37 -0
- package/src/plugins/usePlugins.ts +133 -0
- package/src/themes/context.tsx +443 -0
- package/src/themes/fonts.ts +160 -0
- package/src/themes/index.ts +3 -0
- package/src/themes/presets.ts +477 -0
- package/src/themes/types.ts +187 -0
- package/tsconfig.app.json +34 -0
- package/tsconfig.json +7 -0
- package/tsconfig.node.json +26 -0
- package/vite.config.ts +124 -0
- package/vite.config.ts.timestamp-1780999102396-af6b77b30ebd8.mjs +105 -0
package/src/App.tsx
ADDED
|
@@ -0,0 +1,1173 @@
|
|
|
1
|
+
import {
|
|
2
|
+
useCallback,
|
|
3
|
+
useEffect,
|
|
4
|
+
useMemo,
|
|
5
|
+
useRef,
|
|
6
|
+
useState,
|
|
7
|
+
type ComponentType,
|
|
8
|
+
type ReactNode,
|
|
9
|
+
} from "react";
|
|
10
|
+
import { createPortal } from "react-dom";
|
|
11
|
+
import {
|
|
12
|
+
Routes,
|
|
13
|
+
Route,
|
|
14
|
+
NavLink,
|
|
15
|
+
Navigate,
|
|
16
|
+
useLocation,
|
|
17
|
+
useNavigate,
|
|
18
|
+
} from "react-router-dom";
|
|
19
|
+
import {
|
|
20
|
+
Activity,
|
|
21
|
+
BarChart3,
|
|
22
|
+
BookOpen,
|
|
23
|
+
Clock,
|
|
24
|
+
Code,
|
|
25
|
+
Cpu,
|
|
26
|
+
Database,
|
|
27
|
+
Download,
|
|
28
|
+
Eye,
|
|
29
|
+
FileText,
|
|
30
|
+
Globe,
|
|
31
|
+
Heart,
|
|
32
|
+
KeyRound,
|
|
33
|
+
Menu,
|
|
34
|
+
MessageSquare,
|
|
35
|
+
Package,
|
|
36
|
+
PanelLeftClose,
|
|
37
|
+
PanelLeftOpen,
|
|
38
|
+
Puzzle,
|
|
39
|
+
RotateCw,
|
|
40
|
+
Settings,
|
|
41
|
+
Shield,
|
|
42
|
+
Sparkles,
|
|
43
|
+
Star,
|
|
44
|
+
Terminal,
|
|
45
|
+
Users,
|
|
46
|
+
Wrench,
|
|
47
|
+
X,
|
|
48
|
+
Zap,
|
|
49
|
+
} from "lucide-react";
|
|
50
|
+
import { Button } from "@nastechai/ui/ui/components/button";
|
|
51
|
+
import { SelectionSwitcher } from "@nastechai/ui/ui/components/selection-switcher";
|
|
52
|
+
import { Spinner } from "@nastechai/ui/ui/components/spinner";
|
|
53
|
+
import { cn } from "@/lib/utils";
|
|
54
|
+
import { Backdrop } from "@/components/Backdrop";
|
|
55
|
+
import { SidebarFooter } from "@/components/SidebarFooter";
|
|
56
|
+
import { SidebarStatusStrip, gatewayLine } from "@/components/SidebarStatusStrip";
|
|
57
|
+
import { useBelowBreakpoint } from "@nastechai/ui/hooks/use-below-breakpoint";
|
|
58
|
+
import { useSidebarStatus } from "@/hooks/useSidebarStatus";
|
|
59
|
+
import { AuthWidget } from "@/components/AuthWidget";
|
|
60
|
+
import { PageHeaderProvider } from "@/contexts/PageHeaderProvider";
|
|
61
|
+
import { useSystemActions } from "@/contexts/useSystemActions";
|
|
62
|
+
import type { SystemAction } from "@/contexts/system-actions-context";
|
|
63
|
+
import ConfigPage from "@/pages/ConfigPage";
|
|
64
|
+
import DocsPage from "@/pages/DocsPage";
|
|
65
|
+
import EnvPage from "@/pages/EnvPage";
|
|
66
|
+
import SessionsPage from "@/pages/SessionsPage";
|
|
67
|
+
import LogsPage from "@/pages/LogsPage";
|
|
68
|
+
import AnalyticsPage from "@/pages/AnalyticsPage";
|
|
69
|
+
import ModelsPage from "@/pages/ModelsPage";
|
|
70
|
+
import CronPage from "@/pages/CronPage";
|
|
71
|
+
import ProfilesPage from "@/pages/ProfilesPage";
|
|
72
|
+
import SkillsPage from "@/pages/SkillsPage";
|
|
73
|
+
import PluginsPage from "@/pages/PluginsPage";
|
|
74
|
+
import ChatPage from "@/pages/ChatPage";
|
|
75
|
+
import { LanguageSwitcher } from "@/components/LanguageSwitcher";
|
|
76
|
+
import { ThemeSwitcher } from "@/components/ThemeSwitcher";
|
|
77
|
+
import { useI18n } from "@/i18n";
|
|
78
|
+
import type { Translations } from "@/i18n/types";
|
|
79
|
+
import { PluginPage, PluginSlot, usePlugins } from "@/plugins";
|
|
80
|
+
import type { PluginManifest } from "@/plugins";
|
|
81
|
+
import { useTheme } from "@/themes";
|
|
82
|
+
import { isDashboardEmbeddedChatEnabled } from "@/lib/dashboard-flags";
|
|
83
|
+
import { api } from "@/lib/api";
|
|
84
|
+
import type { StatusResponse } from "@/lib/api";
|
|
85
|
+
|
|
86
|
+
function RootRedirect() {
|
|
87
|
+
return <Navigate to="/sessions" replace />;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function UnknownRouteFallback({ pluginsLoading }: { pluginsLoading: boolean }) {
|
|
91
|
+
if (pluginsLoading) {
|
|
92
|
+
// Render nothing during the plugin-load window — a spinner here would just flash.
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
return <Navigate to="/sessions" replace />;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const CHAT_NAV_ITEM: NavItem = {
|
|
99
|
+
path: "/chat",
|
|
100
|
+
labelKey: "chat",
|
|
101
|
+
label: "Chat",
|
|
102
|
+
icon: Terminal,
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Built-in routes except /chat. Chat is rendered persistently (outside
|
|
107
|
+
* <Routes>) when embedded — see the persistent chat host block rendered
|
|
108
|
+
* inline near the bottom of this file — so the PTY child, WebSocket,
|
|
109
|
+
* and xterm instance survive when the user visits another tab and comes
|
|
110
|
+
* back. A `display:none` toggle hides the terminal without unmounting.
|
|
111
|
+
* Routing still owns the URL so /chat deep-links, browser back/forward,
|
|
112
|
+
* and nav highlight keep working.
|
|
113
|
+
*/
|
|
114
|
+
const BUILTIN_ROUTES_CORE: Record<string, ComponentType> = {
|
|
115
|
+
"/": RootRedirect,
|
|
116
|
+
"/sessions": SessionsPage,
|
|
117
|
+
"/analytics": AnalyticsPage,
|
|
118
|
+
"/models": ModelsPage,
|
|
119
|
+
"/logs": LogsPage,
|
|
120
|
+
"/cron": CronPage,
|
|
121
|
+
"/skills": SkillsPage,
|
|
122
|
+
"/plugins": PluginsPage,
|
|
123
|
+
"/profiles": ProfilesPage,
|
|
124
|
+
"/config": ConfigPage,
|
|
125
|
+
"/env": EnvPage,
|
|
126
|
+
"/docs": DocsPage,
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
// Route placeholder for /chat. The persistent ChatPage host (rendered
|
|
130
|
+
// outside <Routes> when embedded chat is on) paints on top; this empty
|
|
131
|
+
// element just claims the path so the `*` catch-all redirect doesn't
|
|
132
|
+
// fire when the user navigates to /chat.
|
|
133
|
+
function ChatRouteSink() {
|
|
134
|
+
return null;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const BUILTIN_NAV_REST: NavItem[] = [
|
|
138
|
+
{
|
|
139
|
+
path: "/sessions",
|
|
140
|
+
labelKey: "sessions",
|
|
141
|
+
label: "Sessions",
|
|
142
|
+
icon: MessageSquare,
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
path: "/analytics",
|
|
146
|
+
labelKey: "analytics",
|
|
147
|
+
label: "Analytics",
|
|
148
|
+
icon: BarChart3,
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
path: "/models",
|
|
152
|
+
labelKey: "models",
|
|
153
|
+
label: "Models",
|
|
154
|
+
icon: Cpu,
|
|
155
|
+
},
|
|
156
|
+
{ path: "/logs", labelKey: "logs", label: "Logs", icon: FileText },
|
|
157
|
+
{ path: "/cron", labelKey: "cron", label: "Cron", icon: Clock },
|
|
158
|
+
{ path: "/skills", labelKey: "skills", label: "Skills", icon: Package },
|
|
159
|
+
{ path: "/plugins", labelKey: "plugins", label: "Plugins", icon: Puzzle },
|
|
160
|
+
{ path: "/profiles", labelKey: "profiles", label: "Profiles", icon: Users },
|
|
161
|
+
{ path: "/config", labelKey: "config", label: "Config", icon: Settings },
|
|
162
|
+
{ path: "/env", labelKey: "keys", label: "Keys", icon: KeyRound },
|
|
163
|
+
{
|
|
164
|
+
path: "/docs",
|
|
165
|
+
labelKey: "documentation",
|
|
166
|
+
label: "Documentation",
|
|
167
|
+
icon: BookOpen,
|
|
168
|
+
},
|
|
169
|
+
];
|
|
170
|
+
|
|
171
|
+
const ICON_MAP: Record<string, ComponentType<{ className?: string }>> = {
|
|
172
|
+
Activity,
|
|
173
|
+
BarChart3,
|
|
174
|
+
Clock,
|
|
175
|
+
Cpu,
|
|
176
|
+
FileText,
|
|
177
|
+
KeyRound,
|
|
178
|
+
MessageSquare,
|
|
179
|
+
Package,
|
|
180
|
+
Settings,
|
|
181
|
+
Puzzle,
|
|
182
|
+
Sparkles,
|
|
183
|
+
Terminal,
|
|
184
|
+
Globe,
|
|
185
|
+
Database,
|
|
186
|
+
Shield,
|
|
187
|
+
Users,
|
|
188
|
+
Wrench,
|
|
189
|
+
Zap,
|
|
190
|
+
Heart,
|
|
191
|
+
Star,
|
|
192
|
+
Code,
|
|
193
|
+
Eye,
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
function resolveIcon(name: string): ComponentType<{ className?: string }> {
|
|
197
|
+
return ICON_MAP[name] ?? Puzzle;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
function buildNavItems(
|
|
201
|
+
builtIn: NavItem[],
|
|
202
|
+
manifests: PluginManifest[],
|
|
203
|
+
): NavItem[] {
|
|
204
|
+
const items = [...builtIn];
|
|
205
|
+
|
|
206
|
+
for (const manifest of manifests) {
|
|
207
|
+
if (manifest.tab.override) continue;
|
|
208
|
+
if (manifest.tab.hidden) continue;
|
|
209
|
+
|
|
210
|
+
const pluginItem: NavItem = {
|
|
211
|
+
path: manifest.tab.path,
|
|
212
|
+
label: manifest.label,
|
|
213
|
+
icon: resolveIcon(manifest.icon),
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
const pos = manifest.tab.position ?? "end";
|
|
217
|
+
if (pos === "end") {
|
|
218
|
+
items.push(pluginItem);
|
|
219
|
+
} else if (pos.startsWith("after:")) {
|
|
220
|
+
const target = "/" + pos.slice(6);
|
|
221
|
+
const idx = items.findIndex((i) => i.path === target);
|
|
222
|
+
items.splice(idx >= 0 ? idx + 1 : items.length, 0, pluginItem);
|
|
223
|
+
} else if (pos.startsWith("before:")) {
|
|
224
|
+
const target = "/" + pos.slice(7);
|
|
225
|
+
const idx = items.findIndex((i) => i.path === target);
|
|
226
|
+
items.splice(idx >= 0 ? idx : items.length, 0, pluginItem);
|
|
227
|
+
} else {
|
|
228
|
+
items.push(pluginItem);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
return items;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/** Split merged nav into built-in sidebar entries vs plugin tabs, preserving plugin order hints. */
|
|
236
|
+
function partitionSidebarNav(
|
|
237
|
+
builtIn: NavItem[],
|
|
238
|
+
manifests: PluginManifest[],
|
|
239
|
+
): { coreItems: NavItem[]; pluginItems: NavItem[] } {
|
|
240
|
+
const merged = buildNavItems(builtIn, manifests);
|
|
241
|
+
const builtinPaths = new Set(builtIn.map((i) => i.path));
|
|
242
|
+
const coreItems: NavItem[] = [];
|
|
243
|
+
const pluginItems: NavItem[] = [];
|
|
244
|
+
for (const item of merged) {
|
|
245
|
+
if (builtinPaths.has(item.path)) coreItems.push(item);
|
|
246
|
+
else pluginItems.push(item);
|
|
247
|
+
}
|
|
248
|
+
return { coreItems, pluginItems };
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
function buildRoutes(
|
|
252
|
+
builtinRoutes: Record<string, ComponentType>,
|
|
253
|
+
manifests: PluginManifest[],
|
|
254
|
+
): Array<{
|
|
255
|
+
key: string;
|
|
256
|
+
path: string;
|
|
257
|
+
element: ReactNode;
|
|
258
|
+
}> {
|
|
259
|
+
const byOverride = new Map<string, PluginManifest>();
|
|
260
|
+
const addons: PluginManifest[] = [];
|
|
261
|
+
|
|
262
|
+
for (const m of manifests) {
|
|
263
|
+
if (m.tab.override) {
|
|
264
|
+
byOverride.set(m.tab.override, m);
|
|
265
|
+
} else {
|
|
266
|
+
addons.push(m);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
const routes: Array<{
|
|
271
|
+
key: string;
|
|
272
|
+
path: string;
|
|
273
|
+
element: ReactNode;
|
|
274
|
+
}> = [];
|
|
275
|
+
|
|
276
|
+
for (const [path, Component] of Object.entries(builtinRoutes)) {
|
|
277
|
+
const om = byOverride.get(path);
|
|
278
|
+
if (om) {
|
|
279
|
+
routes.push({
|
|
280
|
+
key: `override:${om.name}`,
|
|
281
|
+
path,
|
|
282
|
+
element: <PluginPage name={om.name} />,
|
|
283
|
+
});
|
|
284
|
+
} else {
|
|
285
|
+
routes.push({ key: `builtin:${path}`, path, element: <Component /> });
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
for (const m of addons) {
|
|
290
|
+
if (m.tab.hidden) continue;
|
|
291
|
+
if (m.tab.path === "/plugins") continue;
|
|
292
|
+
if (builtinRoutes[m.tab.path]) continue;
|
|
293
|
+
routes.push({
|
|
294
|
+
key: `plugin:${m.name}`,
|
|
295
|
+
path: m.tab.path,
|
|
296
|
+
element: <PluginPage name={m.name} />,
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
for (const m of manifests) {
|
|
301
|
+
if (!m.tab.hidden) continue;
|
|
302
|
+
if (m.tab.path === "/plugins") continue;
|
|
303
|
+
if (builtinRoutes[m.tab.path] || m.tab.override) continue;
|
|
304
|
+
routes.push({
|
|
305
|
+
key: `plugin:hidden:${m.name}`,
|
|
306
|
+
path: m.tab.path,
|
|
307
|
+
element: <PluginPage name={m.name} />,
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
return routes;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
const SIDEBAR_COLLAPSED_KEY = "nastech-sidebar-collapsed";
|
|
315
|
+
|
|
316
|
+
export default function App() {
|
|
317
|
+
const { t } = useI18n();
|
|
318
|
+
const { pathname } = useLocation();
|
|
319
|
+
const { manifests, loading: pluginsLoading } = usePlugins();
|
|
320
|
+
const { theme } = useTheme();
|
|
321
|
+
const [mobileOpen, setMobileOpen] = useState(false);
|
|
322
|
+
const closeMobile = useCallback(() => setMobileOpen(false), []);
|
|
323
|
+
|
|
324
|
+
const [collapsed, setCollapsed] = useState(() => {
|
|
325
|
+
try {
|
|
326
|
+
return localStorage.getItem(SIDEBAR_COLLAPSED_KEY) === "true";
|
|
327
|
+
} catch {
|
|
328
|
+
return false;
|
|
329
|
+
}
|
|
330
|
+
});
|
|
331
|
+
const toggleCollapsed = useCallback(() => {
|
|
332
|
+
setCollapsed((prev) => {
|
|
333
|
+
const next = !prev;
|
|
334
|
+
try {
|
|
335
|
+
localStorage.setItem(SIDEBAR_COLLAPSED_KEY, String(next));
|
|
336
|
+
} catch { /* localStorage may be unavailable in private browsing */ }
|
|
337
|
+
return next;
|
|
338
|
+
});
|
|
339
|
+
}, []);
|
|
340
|
+
const isMobile = useBelowBreakpoint(1024);
|
|
341
|
+
const isDesktopCollapsed = collapsed && !isMobile;
|
|
342
|
+
const tooltipWarmRef = useRef(0);
|
|
343
|
+
const sidebarStatus = useSidebarStatus();
|
|
344
|
+
const isDocsRoute = pathname === "/docs" || pathname === "/docs/";
|
|
345
|
+
const normalizedPath = pathname.replace(/\/$/, "") || "/";
|
|
346
|
+
const isChatRoute = normalizedPath === "/chat";
|
|
347
|
+
const embeddedChat = isDashboardEmbeddedChatEnabled();
|
|
348
|
+
|
|
349
|
+
// `dashboard.show_token_analytics` gates the Analytics nav item. The
|
|
350
|
+
// page itself remains reachable by URL (it renders an explanation when
|
|
351
|
+
// the flag is off — see AnalyticsPage), but hiding the nav entry avoids
|
|
352
|
+
// surfacing misleading token/cost numbers in the sidebar. Default off.
|
|
353
|
+
const [showTokenAnalytics, setShowTokenAnalytics] = useState(false);
|
|
354
|
+
useEffect(() => {
|
|
355
|
+
api
|
|
356
|
+
.getConfig()
|
|
357
|
+
.then((cfg) => {
|
|
358
|
+
const dash = (cfg?.dashboard ?? {}) as {
|
|
359
|
+
show_token_analytics?: unknown;
|
|
360
|
+
};
|
|
361
|
+
setShowTokenAnalytics(dash.show_token_analytics === true);
|
|
362
|
+
})
|
|
363
|
+
.catch(() => setShowTokenAnalytics(false));
|
|
364
|
+
}, []);
|
|
365
|
+
|
|
366
|
+
// A plugin can replace the built-in /chat page via `tab.override: "/chat"`
|
|
367
|
+
// in its manifest. When one does, `buildRoutes` already swaps the route
|
|
368
|
+
// element for <PluginPage /> — but we also have to suppress the
|
|
369
|
+
// persistent ChatPage host below, or the plugin's page and the built-in
|
|
370
|
+
// terminal would paint on top of each other. The override is niche
|
|
371
|
+
// (nothing ships overriding /chat today) but it's an advertised
|
|
372
|
+
// extension point, so preserve the pre-persistence contract: when a
|
|
373
|
+
// plugin owns /chat, the built-in chat UI is entirely absent.
|
|
374
|
+
//
|
|
375
|
+
// Waiting on `pluginsLoading` is load-bearing: manifests arrive
|
|
376
|
+
// asynchronously from /api/dashboard/plugins, so on initial render
|
|
377
|
+
// `chatOverriddenByPlugin` is always false. Without the loading
|
|
378
|
+
// gate, the persistent host would mount, spawn a PTY, and THEN get
|
|
379
|
+
// yanked out from under the user when the plugin's manifest resolves
|
|
380
|
+
// — killing the session mid-paint. Delaying host mount by the
|
|
381
|
+
// plugin-load window (typically <50ms, worst case 2s safety timeout)
|
|
382
|
+
// is the cheaper trade-off.
|
|
383
|
+
const chatOverriddenByPlugin = useMemo(
|
|
384
|
+
() => manifests.some((m) => m.tab.override === "/chat"),
|
|
385
|
+
[manifests],
|
|
386
|
+
);
|
|
387
|
+
|
|
388
|
+
const builtinRoutes = useMemo(
|
|
389
|
+
() => ({
|
|
390
|
+
...BUILTIN_ROUTES_CORE,
|
|
391
|
+
...(embeddedChat ? { "/chat": ChatRouteSink } : {}),
|
|
392
|
+
}),
|
|
393
|
+
[embeddedChat],
|
|
394
|
+
);
|
|
395
|
+
|
|
396
|
+
const builtinNav = useMemo(() => {
|
|
397
|
+
const base = embeddedChat
|
|
398
|
+
? [CHAT_NAV_ITEM, ...BUILTIN_NAV_REST]
|
|
399
|
+
: BUILTIN_NAV_REST;
|
|
400
|
+
return showTokenAnalytics
|
|
401
|
+
? base
|
|
402
|
+
: base.filter((n) => n.path !== "/analytics");
|
|
403
|
+
}, [embeddedChat, showTokenAnalytics]);
|
|
404
|
+
|
|
405
|
+
const sidebarNav = useMemo(
|
|
406
|
+
() => partitionSidebarNav(builtinNav, manifests),
|
|
407
|
+
[builtinNav, manifests],
|
|
408
|
+
);
|
|
409
|
+
const routes = useMemo(
|
|
410
|
+
() => buildRoutes(builtinRoutes, manifests),
|
|
411
|
+
[builtinRoutes, manifests],
|
|
412
|
+
);
|
|
413
|
+
const pluginTabMeta = useMemo(
|
|
414
|
+
() =>
|
|
415
|
+
manifests
|
|
416
|
+
.filter((m) => !m.tab.hidden)
|
|
417
|
+
.map((m) => ({
|
|
418
|
+
path: m.tab.override ?? m.tab.path,
|
|
419
|
+
label: m.label,
|
|
420
|
+
})),
|
|
421
|
+
[manifests],
|
|
422
|
+
);
|
|
423
|
+
|
|
424
|
+
const layoutVariant = theme.layoutVariant ?? "standard";
|
|
425
|
+
|
|
426
|
+
useEffect(() => {
|
|
427
|
+
if (!mobileOpen) return;
|
|
428
|
+
const onKey = (e: KeyboardEvent) => {
|
|
429
|
+
if (e.key === "Escape") setMobileOpen(false);
|
|
430
|
+
};
|
|
431
|
+
document.addEventListener("keydown", onKey);
|
|
432
|
+
const prevOverflow = document.body.style.overflow;
|
|
433
|
+
document.body.style.overflow = "hidden";
|
|
434
|
+
return () => {
|
|
435
|
+
document.removeEventListener("keydown", onKey);
|
|
436
|
+
document.body.style.overflow = prevOverflow;
|
|
437
|
+
};
|
|
438
|
+
}, [mobileOpen]);
|
|
439
|
+
|
|
440
|
+
useEffect(() => {
|
|
441
|
+
const mql = window.matchMedia("(min-width: 1024px)");
|
|
442
|
+
const onChange = (e: MediaQueryListEvent) => {
|
|
443
|
+
if (e.matches) setMobileOpen(false);
|
|
444
|
+
};
|
|
445
|
+
mql.addEventListener("change", onChange);
|
|
446
|
+
return () => mql.removeEventListener("change", onChange);
|
|
447
|
+
}, []);
|
|
448
|
+
|
|
449
|
+
return (
|
|
450
|
+
<div
|
|
451
|
+
data-layout-variant={layoutVariant}
|
|
452
|
+
className="flex h-dvh max-h-dvh min-h-0 flex-col overflow-hidden bg-black text-text-primary antialiased"
|
|
453
|
+
>
|
|
454
|
+
<SelectionSwitcher />
|
|
455
|
+
<Backdrop />
|
|
456
|
+
<PluginSlot name="backdrop" />
|
|
457
|
+
|
|
458
|
+
<header
|
|
459
|
+
className={cn(
|
|
460
|
+
"lg:hidden fixed top-0 left-0 right-0 z-40 min-h-14",
|
|
461
|
+
"flex items-center gap-2 px-4 py-2",
|
|
462
|
+
"border-b border-current/20",
|
|
463
|
+
"bg-background-base/90 backdrop-blur-sm",
|
|
464
|
+
)}
|
|
465
|
+
style={{
|
|
466
|
+
background: "var(--component-header-background)",
|
|
467
|
+
borderImage: "var(--component-header-border-image)",
|
|
468
|
+
clipPath: "var(--component-header-clip-path)",
|
|
469
|
+
}}
|
|
470
|
+
>
|
|
471
|
+
<Button
|
|
472
|
+
ghost
|
|
473
|
+
size="icon"
|
|
474
|
+
onClick={() => setMobileOpen(true)}
|
|
475
|
+
aria-label={t.app.openNavigation}
|
|
476
|
+
aria-expanded={mobileOpen}
|
|
477
|
+
aria-controls="app-sidebar"
|
|
478
|
+
className="text-text-secondary hover:text-midground"
|
|
479
|
+
>
|
|
480
|
+
<Menu />
|
|
481
|
+
</Button>
|
|
482
|
+
|
|
483
|
+
<img
|
|
484
|
+
src="/banner.png"
|
|
485
|
+
alt="NasTech"
|
|
486
|
+
className="h-8 w-auto object-contain"
|
|
487
|
+
/>
|
|
488
|
+
</header>
|
|
489
|
+
|
|
490
|
+
{mobileOpen && (
|
|
491
|
+
<Button
|
|
492
|
+
ghost
|
|
493
|
+
aria-label={t.app.closeNavigation}
|
|
494
|
+
onClick={closeMobile}
|
|
495
|
+
className={cn(
|
|
496
|
+
"lg:hidden fixed inset-0 z-40 p-0 block",
|
|
497
|
+
"bg-black/60 backdrop-blur-sm",
|
|
498
|
+
)}
|
|
499
|
+
/>
|
|
500
|
+
)}
|
|
501
|
+
|
|
502
|
+
<PluginSlot name="header-banner" />
|
|
503
|
+
|
|
504
|
+
<div className="flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden pt-14 lg:pt-0">
|
|
505
|
+
<div className="flex min-h-0 min-w-0 flex-1">
|
|
506
|
+
<aside
|
|
507
|
+
id="app-sidebar"
|
|
508
|
+
aria-label={t.app.navigation}
|
|
509
|
+
className={cn(
|
|
510
|
+
"fixed top-0 left-0 z-50 flex h-dvh max-h-dvh w-64 min-h-0 flex-col",
|
|
511
|
+
"border-r border-current/20",
|
|
512
|
+
"bg-background-base/95 backdrop-blur-sm",
|
|
513
|
+
"transition-[transform] duration-200 ease-out",
|
|
514
|
+
mobileOpen ? "translate-x-0" : "-translate-x-full",
|
|
515
|
+
"lg:sticky lg:top-0 lg:translate-x-0 lg:shrink-0 lg:overflow-hidden",
|
|
516
|
+
"lg:transition-[width] lg:duration-[600ms] lg:ease-[cubic-bezier(0.33,1.35,0.62,1)]",
|
|
517
|
+
collapsed && "lg:w-14",
|
|
518
|
+
)}
|
|
519
|
+
style={{
|
|
520
|
+
background: "var(--component-sidebar-background)",
|
|
521
|
+
clipPath: "var(--component-sidebar-clip-path)",
|
|
522
|
+
borderImage: "var(--component-sidebar-border-image)",
|
|
523
|
+
}}
|
|
524
|
+
>
|
|
525
|
+
<div
|
|
526
|
+
className={cn(
|
|
527
|
+
"flex h-14 shrink-0 items-center gap-2",
|
|
528
|
+
"border-b border-current/20",
|
|
529
|
+
collapsed ? "lg:justify-center lg:px-0" : "px-4 justify-between",
|
|
530
|
+
)}
|
|
531
|
+
>
|
|
532
|
+
<div
|
|
533
|
+
className={cn(
|
|
534
|
+
"flex items-center gap-2",
|
|
535
|
+
collapsed && "lg:hidden",
|
|
536
|
+
)}
|
|
537
|
+
>
|
|
538
|
+
<PluginSlot name="header-left" />
|
|
539
|
+
|
|
540
|
+
<img
|
|
541
|
+
src="/banner.png"
|
|
542
|
+
alt="NasTech"
|
|
543
|
+
className={cn(
|
|
544
|
+
"object-contain",
|
|
545
|
+
collapsed ? "h-8 w-8" : "h-10 w-auto max-w-[140px]",
|
|
546
|
+
)}
|
|
547
|
+
/>
|
|
548
|
+
</div>
|
|
549
|
+
|
|
550
|
+
<Button
|
|
551
|
+
ghost
|
|
552
|
+
size="icon"
|
|
553
|
+
onClick={closeMobile}
|
|
554
|
+
aria-label={t.app.closeNavigation}
|
|
555
|
+
className="lg:hidden text-text-secondary hover:text-midground"
|
|
556
|
+
>
|
|
557
|
+
<X />
|
|
558
|
+
</Button>
|
|
559
|
+
|
|
560
|
+
<Button
|
|
561
|
+
ghost
|
|
562
|
+
size="icon"
|
|
563
|
+
onClick={toggleCollapsed}
|
|
564
|
+
aria-label={
|
|
565
|
+
collapsed ? t.common.expand : t.common.collapse
|
|
566
|
+
}
|
|
567
|
+
className="hidden lg:flex text-text-secondary hover:text-midground"
|
|
568
|
+
>
|
|
569
|
+
{collapsed ? (
|
|
570
|
+
<PanelLeftOpen className="h-4 w-4" />
|
|
571
|
+
) : (
|
|
572
|
+
<PanelLeftClose className="h-4 w-4" />
|
|
573
|
+
)}
|
|
574
|
+
</Button>
|
|
575
|
+
</div>
|
|
576
|
+
|
|
577
|
+
<nav
|
|
578
|
+
className="min-h-0 w-full flex-1 overflow-y-auto overflow-x-hidden border-t border-current/10 py-2"
|
|
579
|
+
aria-label={t.app.navigation}
|
|
580
|
+
>
|
|
581
|
+
<ul className="flex flex-col">
|
|
582
|
+
{sidebarNav.coreItems.map((item) => (
|
|
583
|
+
<SidebarNavLink
|
|
584
|
+
closeMobile={closeMobile}
|
|
585
|
+
collapsed={isDesktopCollapsed}
|
|
586
|
+
item={item}
|
|
587
|
+
key={item.path}
|
|
588
|
+
t={t}
|
|
589
|
+
tooltipWarmRef={tooltipWarmRef}
|
|
590
|
+
/>
|
|
591
|
+
))}
|
|
592
|
+
</ul>
|
|
593
|
+
|
|
594
|
+
{sidebarNav.pluginItems.length > 0 && (
|
|
595
|
+
<div
|
|
596
|
+
aria-labelledby="nastech-sidebar-plugin-nav-heading"
|
|
597
|
+
className="flex flex-col border-t border-current/10 pb-2"
|
|
598
|
+
role="group"
|
|
599
|
+
>
|
|
600
|
+
<span
|
|
601
|
+
className={cn(
|
|
602
|
+
"px-5 pt-2.5 pb-1",
|
|
603
|
+
"font-mondwest text-display text-xs tracking-[0.12em] text-text-tertiary",
|
|
604
|
+
isDesktopCollapsed && "lg:hidden",
|
|
605
|
+
)}
|
|
606
|
+
id="nastech-sidebar-plugin-nav-heading"
|
|
607
|
+
>
|
|
608
|
+
{t.app.pluginNavSection}
|
|
609
|
+
</span>
|
|
610
|
+
|
|
611
|
+
<ul className="flex flex-col">
|
|
612
|
+
{sidebarNav.pluginItems.map((item) => (
|
|
613
|
+
<SidebarNavLink
|
|
614
|
+
closeMobile={closeMobile}
|
|
615
|
+
collapsed={isDesktopCollapsed}
|
|
616
|
+
item={item}
|
|
617
|
+
key={item.path}
|
|
618
|
+
t={t}
|
|
619
|
+
tooltipWarmRef={tooltipWarmRef}
|
|
620
|
+
/>
|
|
621
|
+
))}
|
|
622
|
+
</ul>
|
|
623
|
+
</div>
|
|
624
|
+
)}
|
|
625
|
+
</nav>
|
|
626
|
+
|
|
627
|
+
<SidebarSystemActions
|
|
628
|
+
collapsed={isDesktopCollapsed}
|
|
629
|
+
onNavigate={closeMobile}
|
|
630
|
+
status={sidebarStatus}
|
|
631
|
+
tooltipWarmRef={tooltipWarmRef}
|
|
632
|
+
/>
|
|
633
|
+
|
|
634
|
+
<div
|
|
635
|
+
className={cn(
|
|
636
|
+
"flex shrink-0 items-center gap-2",
|
|
637
|
+
"px-3 py-2",
|
|
638
|
+
"border-t border-current/20",
|
|
639
|
+
isDesktopCollapsed
|
|
640
|
+
? "lg:flex-col lg:items-start lg:gap-3 lg:py-3"
|
|
641
|
+
: "justify-between",
|
|
642
|
+
)}
|
|
643
|
+
>
|
|
644
|
+
<div
|
|
645
|
+
className={cn(
|
|
646
|
+
"flex min-w-0 items-center gap-2",
|
|
647
|
+
isDesktopCollapsed && "lg:flex-col lg:items-start",
|
|
648
|
+
)}
|
|
649
|
+
>
|
|
650
|
+
<PluginSlot name="header-right" />
|
|
651
|
+
|
|
652
|
+
<SidebarIconWithTooltip
|
|
653
|
+
collapsed={isDesktopCollapsed}
|
|
654
|
+
label={t.theme?.switchTheme ?? "Switch theme"}
|
|
655
|
+
tooltipWarmRef={tooltipWarmRef}
|
|
656
|
+
>
|
|
657
|
+
<ThemeSwitcher collapsed={isDesktopCollapsed} dropUp />
|
|
658
|
+
</SidebarIconWithTooltip>
|
|
659
|
+
|
|
660
|
+
<SidebarIconWithTooltip
|
|
661
|
+
collapsed={isDesktopCollapsed}
|
|
662
|
+
label={t.language.switchTo}
|
|
663
|
+
tooltipWarmRef={tooltipWarmRef}
|
|
664
|
+
>
|
|
665
|
+
<LanguageSwitcher collapsed={isDesktopCollapsed} dropUp />
|
|
666
|
+
</SidebarIconWithTooltip>
|
|
667
|
+
</div>
|
|
668
|
+
</div>
|
|
669
|
+
|
|
670
|
+
<div
|
|
671
|
+
className={cn(
|
|
672
|
+
"flex shrink-0 flex-col",
|
|
673
|
+
isDesktopCollapsed && "lg:hidden",
|
|
674
|
+
)}
|
|
675
|
+
>
|
|
676
|
+
<AuthWidget />
|
|
677
|
+
<SidebarFooter status={sidebarStatus} />
|
|
678
|
+
</div>
|
|
679
|
+
</aside>
|
|
680
|
+
|
|
681
|
+
<PageHeaderProvider pluginTabs={pluginTabMeta}>
|
|
682
|
+
<div
|
|
683
|
+
className={cn(
|
|
684
|
+
"relative z-2 flex min-w-0 min-h-0 flex-1 flex-col",
|
|
685
|
+
"px-3 sm:px-6",
|
|
686
|
+
isChatRoute
|
|
687
|
+
? "pb-0 pt-1 sm:pt-2 lg:pt-4"
|
|
688
|
+
: "pt-2 sm:pt-4 lg:pt-6",
|
|
689
|
+
isDocsRoute && "min-h-0 flex-1",
|
|
690
|
+
)}
|
|
691
|
+
>
|
|
692
|
+
<PluginSlot name="pre-main" />
|
|
693
|
+
<div
|
|
694
|
+
className={cn(
|
|
695
|
+
"w-full min-w-0",
|
|
696
|
+
!isChatRoute &&
|
|
697
|
+
"pb-[calc(2rem+env(safe-area-inset-bottom,0px))] lg:pb-8",
|
|
698
|
+
(isDocsRoute || isChatRoute) &&
|
|
699
|
+
"min-h-0 flex flex-1 flex-col",
|
|
700
|
+
)}
|
|
701
|
+
>
|
|
702
|
+
<Routes>
|
|
703
|
+
{routes.map(({ key, path, element }) => (
|
|
704
|
+
<Route key={key} path={path} element={element} />
|
|
705
|
+
))}
|
|
706
|
+
<Route
|
|
707
|
+
path="*"
|
|
708
|
+
element={
|
|
709
|
+
<UnknownRouteFallback pluginsLoading={pluginsLoading} />
|
|
710
|
+
}
|
|
711
|
+
/>
|
|
712
|
+
</Routes>
|
|
713
|
+
|
|
714
|
+
{embeddedChat &&
|
|
715
|
+
!chatOverriddenByPlugin &&
|
|
716
|
+
(pluginsLoading ? (
|
|
717
|
+
isChatRoute ? (
|
|
718
|
+
<div
|
|
719
|
+
className="flex min-h-0 min-w-0 flex-1 items-center justify-center"
|
|
720
|
+
aria-busy="true"
|
|
721
|
+
aria-live="polite"
|
|
722
|
+
>
|
|
723
|
+
<div className="flex items-center gap-2 text-sm text-muted-foreground">
|
|
724
|
+
<Spinner />
|
|
725
|
+
<span>Loading chat…</span>
|
|
726
|
+
</div>
|
|
727
|
+
</div>
|
|
728
|
+
) : null
|
|
729
|
+
) : (
|
|
730
|
+
<div
|
|
731
|
+
data-chat-active={isChatRoute ? "true" : "false"}
|
|
732
|
+
className={cn(
|
|
733
|
+
"min-h-0 min-w-0",
|
|
734
|
+
isChatRoute ? "flex flex-1 flex-col" : "hidden",
|
|
735
|
+
)}
|
|
736
|
+
aria-hidden={!isChatRoute}
|
|
737
|
+
>
|
|
738
|
+
<ChatPage isActive={isChatRoute} />
|
|
739
|
+
</div>
|
|
740
|
+
))}
|
|
741
|
+
</div>
|
|
742
|
+
<PluginSlot name="post-main" />
|
|
743
|
+
</div>
|
|
744
|
+
</PageHeaderProvider>
|
|
745
|
+
</div>
|
|
746
|
+
</div>
|
|
747
|
+
|
|
748
|
+
<PluginSlot name="overlay" />
|
|
749
|
+
</div>
|
|
750
|
+
);
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
function SidebarNavLink({
|
|
754
|
+
closeMobile,
|
|
755
|
+
collapsed,
|
|
756
|
+
item,
|
|
757
|
+
tooltipWarmRef,
|
|
758
|
+
t,
|
|
759
|
+
}: SidebarNavLinkProps) {
|
|
760
|
+
const { path, label, labelKey, icon: Icon } = item;
|
|
761
|
+
const liRef = useRef<HTMLLIElement>(null);
|
|
762
|
+
const [hovered, setHovered] = useState(false);
|
|
763
|
+
|
|
764
|
+
const navLabel = labelKey
|
|
765
|
+
? ((t.app.nav as Record<string, string>)[labelKey] ?? label)
|
|
766
|
+
: label;
|
|
767
|
+
|
|
768
|
+
return (
|
|
769
|
+
<li
|
|
770
|
+
ref={liRef}
|
|
771
|
+
onMouseEnter={collapsed ? () => setHovered(true) : undefined}
|
|
772
|
+
onMouseLeave={collapsed ? () => setHovered(false) : undefined}
|
|
773
|
+
>
|
|
774
|
+
<NavLink
|
|
775
|
+
to={path}
|
|
776
|
+
end={path === "/sessions"}
|
|
777
|
+
onClick={closeMobile}
|
|
778
|
+
aria-label={collapsed ? navLabel : undefined}
|
|
779
|
+
onFocus={collapsed ? () => setHovered(true) : undefined}
|
|
780
|
+
onBlur={collapsed ? () => setHovered(false) : undefined}
|
|
781
|
+
className={({ isActive }) =>
|
|
782
|
+
cn(
|
|
783
|
+
"group/nav relative flex items-center gap-3",
|
|
784
|
+
"px-5 py-2.5",
|
|
785
|
+
"font-mondwest text-display uppercase text-sm tracking-[0.12em]",
|
|
786
|
+
"whitespace-nowrap transition-colors cursor-pointer",
|
|
787
|
+
"focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-midground",
|
|
788
|
+
isActive
|
|
789
|
+
? "text-midground"
|
|
790
|
+
: "text-text-secondary hover:text-midground",
|
|
791
|
+
)
|
|
792
|
+
}
|
|
793
|
+
style={{
|
|
794
|
+
clipPath: "var(--component-tab-clip-path)",
|
|
795
|
+
}}
|
|
796
|
+
>
|
|
797
|
+
{({ isActive }) => (
|
|
798
|
+
<>
|
|
799
|
+
<Icon className="h-3.5 w-3.5 shrink-0" />
|
|
800
|
+
|
|
801
|
+
<span
|
|
802
|
+
className={cn(
|
|
803
|
+
"truncate transition-opacity duration-300",
|
|
804
|
+
collapsed ? "lg:opacity-0" : "lg:opacity-100",
|
|
805
|
+
)}
|
|
806
|
+
>
|
|
807
|
+
{navLabel}
|
|
808
|
+
</span>
|
|
809
|
+
|
|
810
|
+
<span
|
|
811
|
+
aria-hidden
|
|
812
|
+
className="absolute inset-y-0.5 left-1.5 right-1.5 bg-midground opacity-0 pointer-events-none transition-opacity duration-200 group-hover/nav:opacity-5"
|
|
813
|
+
/>
|
|
814
|
+
|
|
815
|
+
{isActive && (
|
|
816
|
+
<span
|
|
817
|
+
aria-hidden
|
|
818
|
+
className="absolute left-0 top-0 bottom-0 w-px bg-midground"
|
|
819
|
+
style={{ mixBlendMode: "plus-lighter" }}
|
|
820
|
+
/>
|
|
821
|
+
)}
|
|
822
|
+
</>
|
|
823
|
+
)}
|
|
824
|
+
</NavLink>
|
|
825
|
+
|
|
826
|
+
{collapsed && hovered && liRef.current && (
|
|
827
|
+
<SidebarTooltip anchor={liRef.current} label={navLabel} warmRef={tooltipWarmRef} />
|
|
828
|
+
)}
|
|
829
|
+
</li>
|
|
830
|
+
);
|
|
831
|
+
}
|
|
832
|
+
|
|
833
|
+
function SidebarSystemActions({
|
|
834
|
+
collapsed,
|
|
835
|
+
onNavigate,
|
|
836
|
+
status,
|
|
837
|
+
tooltipWarmRef,
|
|
838
|
+
}: SidebarSystemActionsProps) {
|
|
839
|
+
const { t } = useI18n();
|
|
840
|
+
const navigate = useNavigate();
|
|
841
|
+
const { activeAction, isBusy, isRunning, pendingAction, runAction } =
|
|
842
|
+
useSystemActions();
|
|
843
|
+
|
|
844
|
+
const items: SystemActionItem[] = [
|
|
845
|
+
{
|
|
846
|
+
action: "restart",
|
|
847
|
+
icon: RotateCw,
|
|
848
|
+
label: t.status.restartGateway,
|
|
849
|
+
runningLabel: t.status.restartingGateway,
|
|
850
|
+
spin: true,
|
|
851
|
+
},
|
|
852
|
+
{
|
|
853
|
+
action: "update",
|
|
854
|
+
icon: Download,
|
|
855
|
+
label: t.status.updateNasTech,
|
|
856
|
+
runningLabel: t.status.updatingNasTech,
|
|
857
|
+
spin: false,
|
|
858
|
+
},
|
|
859
|
+
];
|
|
860
|
+
|
|
861
|
+
const handleClick = (action: SystemAction) => {
|
|
862
|
+
if (isBusy) return;
|
|
863
|
+
void runAction(action);
|
|
864
|
+
navigate("/sessions");
|
|
865
|
+
onNavigate();
|
|
866
|
+
};
|
|
867
|
+
|
|
868
|
+
return (
|
|
869
|
+
<div
|
|
870
|
+
className={cn(
|
|
871
|
+
"shrink-0 flex flex-col",
|
|
872
|
+
"border-t border-current/10",
|
|
873
|
+
"py-1",
|
|
874
|
+
)}
|
|
875
|
+
>
|
|
876
|
+
<span
|
|
877
|
+
className={cn(
|
|
878
|
+
"px-5 pt-0.5 pb-0.5",
|
|
879
|
+
"font-mondwest text-display text-xs tracking-[0.12em] text-text-tertiary",
|
|
880
|
+
collapsed && "lg:hidden",
|
|
881
|
+
)}
|
|
882
|
+
>
|
|
883
|
+
{t.app.system}
|
|
884
|
+
</span>
|
|
885
|
+
|
|
886
|
+
<div className={cn(collapsed && "lg:hidden")}>
|
|
887
|
+
<SidebarStatusStrip status={status} />
|
|
888
|
+
</div>
|
|
889
|
+
|
|
890
|
+
<GatewayDot collapsed={collapsed} status={status} tooltipWarmRef={tooltipWarmRef} />
|
|
891
|
+
|
|
892
|
+
<ul className="flex flex-col">
|
|
893
|
+
{items.map((item) => (
|
|
894
|
+
<SystemActionButton
|
|
895
|
+
key={item.action}
|
|
896
|
+
collapsed={collapsed}
|
|
897
|
+
disabled={isBusy && !(pendingAction === item.action || (activeAction === item.action && isRunning))}
|
|
898
|
+
tooltipWarmRef={tooltipWarmRef}
|
|
899
|
+
isPending={pendingAction === item.action}
|
|
900
|
+
isRunning={activeAction === item.action && isRunning && pendingAction !== item.action}
|
|
901
|
+
item={item}
|
|
902
|
+
onClick={() => handleClick(item.action)}
|
|
903
|
+
/>
|
|
904
|
+
))}
|
|
905
|
+
</ul>
|
|
906
|
+
</div>
|
|
907
|
+
);
|
|
908
|
+
}
|
|
909
|
+
|
|
910
|
+
function SystemActionButton({
|
|
911
|
+
collapsed,
|
|
912
|
+
disabled,
|
|
913
|
+
isPending,
|
|
914
|
+
isRunning: isActionRunning,
|
|
915
|
+
item,
|
|
916
|
+
onClick,
|
|
917
|
+
tooltipWarmRef,
|
|
918
|
+
}: SystemActionButtonProps) {
|
|
919
|
+
const { icon: Icon, label, runningLabel, spin } = item;
|
|
920
|
+
const liRef = useRef<HTMLLIElement>(null);
|
|
921
|
+
const [hovered, setHovered] = useState(false);
|
|
922
|
+
const busy = isPending || isActionRunning;
|
|
923
|
+
const displayLabel = isActionRunning ? runningLabel : label;
|
|
924
|
+
|
|
925
|
+
return (
|
|
926
|
+
<li
|
|
927
|
+
ref={liRef}
|
|
928
|
+
onMouseEnter={collapsed ? () => setHovered(true) : undefined}
|
|
929
|
+
onMouseLeave={collapsed ? () => setHovered(false) : undefined}
|
|
930
|
+
>
|
|
931
|
+
<button
|
|
932
|
+
onClick={onClick}
|
|
933
|
+
disabled={disabled}
|
|
934
|
+
aria-busy={busy}
|
|
935
|
+
aria-label={collapsed ? displayLabel : undefined}
|
|
936
|
+
onFocus={collapsed ? () => setHovered(true) : undefined}
|
|
937
|
+
onBlur={collapsed ? () => setHovered(false) : undefined}
|
|
938
|
+
type="button"
|
|
939
|
+
className={cn(
|
|
940
|
+
"group/action relative flex w-full items-center gap-3",
|
|
941
|
+
"px-5 py-2.5",
|
|
942
|
+
"font-mondwest text-display text-xs tracking-[0.1em]",
|
|
943
|
+
"whitespace-nowrap transition-colors cursor-pointer",
|
|
944
|
+
"focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-midground",
|
|
945
|
+
busy
|
|
946
|
+
? "text-midground"
|
|
947
|
+
: "text-text-secondary hover:text-midground",
|
|
948
|
+
"disabled:text-text-disabled disabled:cursor-not-allowed",
|
|
949
|
+
)}
|
|
950
|
+
>
|
|
951
|
+
{isPending ? (
|
|
952
|
+
<Spinner className="shrink-0 text-[0.875rem]" />
|
|
953
|
+
) : isActionRunning && spin ? (
|
|
954
|
+
<Spinner className="shrink-0 text-[0.875rem]" />
|
|
955
|
+
) : (
|
|
956
|
+
<Icon
|
|
957
|
+
className={cn(
|
|
958
|
+
"h-3.5 w-3.5 shrink-0",
|
|
959
|
+
isActionRunning && !spin && "animate-pulse",
|
|
960
|
+
)}
|
|
961
|
+
/>
|
|
962
|
+
)}
|
|
963
|
+
|
|
964
|
+
<span className={cn(
|
|
965
|
+
"truncate transition-opacity duration-300",
|
|
966
|
+
collapsed ? "lg:opacity-0" : "lg:opacity-100",
|
|
967
|
+
)}>
|
|
968
|
+
{displayLabel}
|
|
969
|
+
</span>
|
|
970
|
+
|
|
971
|
+
<span
|
|
972
|
+
aria-hidden
|
|
973
|
+
className="absolute inset-y-0.5 left-1.5 right-1.5 bg-midground opacity-0 pointer-events-none transition-opacity duration-200 group-hover/action:opacity-5"
|
|
974
|
+
/>
|
|
975
|
+
|
|
976
|
+
{busy && (
|
|
977
|
+
<span
|
|
978
|
+
aria-hidden
|
|
979
|
+
className="absolute left-0 top-0 bottom-0 w-px bg-midground"
|
|
980
|
+
style={{ mixBlendMode: "plus-lighter" }}
|
|
981
|
+
/>
|
|
982
|
+
)}
|
|
983
|
+
</button>
|
|
984
|
+
|
|
985
|
+
{collapsed && hovered && liRef.current && (
|
|
986
|
+
<SidebarTooltip anchor={liRef.current} label={displayLabel} warmRef={tooltipWarmRef} />
|
|
987
|
+
)}
|
|
988
|
+
</li>
|
|
989
|
+
);
|
|
990
|
+
}
|
|
991
|
+
|
|
992
|
+
function SidebarIconWithTooltip({
|
|
993
|
+
children,
|
|
994
|
+
collapsed,
|
|
995
|
+
label,
|
|
996
|
+
tooltipWarmRef,
|
|
997
|
+
}: SidebarIconWithTooltipProps) {
|
|
998
|
+
const ref = useRef<HTMLDivElement>(null);
|
|
999
|
+
const [hovered, setHovered] = useState(false);
|
|
1000
|
+
|
|
1001
|
+
return (
|
|
1002
|
+
<div
|
|
1003
|
+
ref={ref}
|
|
1004
|
+
className={cn(
|
|
1005
|
+
"relative w-fit",
|
|
1006
|
+
collapsed && "group/icon",
|
|
1007
|
+
)}
|
|
1008
|
+
onMouseEnter={collapsed ? () => setHovered(true) : undefined}
|
|
1009
|
+
onMouseLeave={collapsed ? () => setHovered(false) : undefined}
|
|
1010
|
+
>
|
|
1011
|
+
{children}
|
|
1012
|
+
|
|
1013
|
+
{collapsed && (
|
|
1014
|
+
<span
|
|
1015
|
+
aria-hidden
|
|
1016
|
+
className="absolute inset-y-0 inset-x-[-0.375rem] bg-midground opacity-0 pointer-events-none transition-opacity duration-200 group-hover/icon:opacity-5 hidden lg:block"
|
|
1017
|
+
/>
|
|
1018
|
+
)}
|
|
1019
|
+
|
|
1020
|
+
{collapsed && hovered && ref.current && (
|
|
1021
|
+
<SidebarTooltip anchor={ref.current} label={label} warmRef={tooltipWarmRef} />
|
|
1022
|
+
)}
|
|
1023
|
+
</div>
|
|
1024
|
+
);
|
|
1025
|
+
}
|
|
1026
|
+
|
|
1027
|
+
function GatewayDot({ collapsed, status, tooltipWarmRef }: GatewayDotProps) {
|
|
1028
|
+
const { t } = useI18n();
|
|
1029
|
+
const ref = useRef<HTMLDivElement>(null);
|
|
1030
|
+
const [hovered, setHovered] = useState(false);
|
|
1031
|
+
|
|
1032
|
+
const toneToColor: Record<string, string> = {
|
|
1033
|
+
"text-success": "bg-success",
|
|
1034
|
+
"text-warning": "bg-warning",
|
|
1035
|
+
"text-destructive": "bg-destructive",
|
|
1036
|
+
"text-muted-foreground": "bg-muted-foreground",
|
|
1037
|
+
};
|
|
1038
|
+
|
|
1039
|
+
let color: string;
|
|
1040
|
+
let label: string;
|
|
1041
|
+
|
|
1042
|
+
if (!status) {
|
|
1043
|
+
color = "bg-midground/20";
|
|
1044
|
+
label = t.status.gateway;
|
|
1045
|
+
} else {
|
|
1046
|
+
const gw = gatewayLine(status, t);
|
|
1047
|
+
color = toneToColor[gw.tone] ?? "bg-muted-foreground";
|
|
1048
|
+
label = `${t.status.gateway} ${gw.label}`;
|
|
1049
|
+
}
|
|
1050
|
+
|
|
1051
|
+
return (
|
|
1052
|
+
<div
|
|
1053
|
+
ref={ref}
|
|
1054
|
+
className={cn(
|
|
1055
|
+
"hidden lg:flex py-3 pl-[1.625rem] transition-opacity duration-300",
|
|
1056
|
+
collapsed ? "lg:opacity-100" : "lg:opacity-0 lg:h-0 lg:py-0 lg:overflow-hidden",
|
|
1057
|
+
)}
|
|
1058
|
+
role="status"
|
|
1059
|
+
aria-label={label}
|
|
1060
|
+
tabIndex={collapsed ? 0 : -1}
|
|
1061
|
+
onMouseEnter={collapsed ? () => setHovered(true) : undefined}
|
|
1062
|
+
onMouseLeave={collapsed ? () => setHovered(false) : undefined}
|
|
1063
|
+
onFocus={collapsed ? () => setHovered(true) : undefined}
|
|
1064
|
+
onBlur={collapsed ? () => setHovered(false) : undefined}
|
|
1065
|
+
>
|
|
1066
|
+
<span
|
|
1067
|
+
aria-hidden
|
|
1068
|
+
className={cn("h-1.5 w-1.5 rounded-full", color)}
|
|
1069
|
+
/>
|
|
1070
|
+
|
|
1071
|
+
{hovered && ref.current && (
|
|
1072
|
+
<SidebarTooltip anchor={ref.current} label={label} warmRef={tooltipWarmRef} />
|
|
1073
|
+
)}
|
|
1074
|
+
</div>
|
|
1075
|
+
);
|
|
1076
|
+
}
|
|
1077
|
+
|
|
1078
|
+
function SidebarTooltip({ anchor, label, warmRef }: SidebarTooltipProps) {
|
|
1079
|
+
const rect = anchor.getBoundingClientRect();
|
|
1080
|
+
const sidebar = document.getElementById("app-sidebar");
|
|
1081
|
+
const sidebarRight = sidebar?.getBoundingClientRect().right ?? rect.right;
|
|
1082
|
+
|
|
1083
|
+
const isWarm = warmRef ? Date.now() - warmRef.current < 300 : false;
|
|
1084
|
+
|
|
1085
|
+
useEffect(() => {
|
|
1086
|
+
if (warmRef) warmRef.current = Date.now();
|
|
1087
|
+
return () => {
|
|
1088
|
+
if (warmRef) warmRef.current = Date.now();
|
|
1089
|
+
};
|
|
1090
|
+
}, [warmRef]);
|
|
1091
|
+
|
|
1092
|
+
return createPortal(
|
|
1093
|
+
<span
|
|
1094
|
+
className={cn(
|
|
1095
|
+
"fixed z-[100] pointer-events-none",
|
|
1096
|
+
"px-2 py-1",
|
|
1097
|
+
"bg-background-base/95 border border-current/20 backdrop-blur-sm shadow-lg",
|
|
1098
|
+
"font-mondwest text-display text-xs tracking-[0.1em] text-midground uppercase",
|
|
1099
|
+
)}
|
|
1100
|
+
style={{
|
|
1101
|
+
top: rect.top + rect.height / 2,
|
|
1102
|
+
left: sidebarRight + 8,
|
|
1103
|
+
transform: "translateY(-50%)",
|
|
1104
|
+
opacity: isWarm ? 1 : undefined,
|
|
1105
|
+
animation: isWarm ? "none" : "sidebar-tooltip-in 120ms ease-out",
|
|
1106
|
+
}}
|
|
1107
|
+
>
|
|
1108
|
+
{label}
|
|
1109
|
+
</span>,
|
|
1110
|
+
document.body,
|
|
1111
|
+
);
|
|
1112
|
+
}
|
|
1113
|
+
|
|
1114
|
+
type TooltipWarmRef = React.RefObject<number>;
|
|
1115
|
+
|
|
1116
|
+
interface GatewayDotProps {
|
|
1117
|
+
collapsed: boolean;
|
|
1118
|
+
status: StatusResponse | null;
|
|
1119
|
+
tooltipWarmRef: TooltipWarmRef;
|
|
1120
|
+
}
|
|
1121
|
+
|
|
1122
|
+
interface NavItem {
|
|
1123
|
+
icon: ComponentType<{ className?: string }>;
|
|
1124
|
+
label: string;
|
|
1125
|
+
labelKey?: string;
|
|
1126
|
+
path: string;
|
|
1127
|
+
}
|
|
1128
|
+
|
|
1129
|
+
interface SidebarIconWithTooltipProps {
|
|
1130
|
+
children: ReactNode;
|
|
1131
|
+
collapsed: boolean;
|
|
1132
|
+
label: string;
|
|
1133
|
+
tooltipWarmRef: TooltipWarmRef;
|
|
1134
|
+
}
|
|
1135
|
+
|
|
1136
|
+
interface SidebarNavLinkProps {
|
|
1137
|
+
closeMobile: () => void;
|
|
1138
|
+
collapsed: boolean;
|
|
1139
|
+
item: NavItem;
|
|
1140
|
+
t: Translations;
|
|
1141
|
+
tooltipWarmRef: TooltipWarmRef;
|
|
1142
|
+
}
|
|
1143
|
+
|
|
1144
|
+
interface SidebarSystemActionsProps {
|
|
1145
|
+
collapsed: boolean;
|
|
1146
|
+
onNavigate: () => void;
|
|
1147
|
+
status: StatusResponse | null;
|
|
1148
|
+
tooltipWarmRef: TooltipWarmRef;
|
|
1149
|
+
}
|
|
1150
|
+
|
|
1151
|
+
interface SidebarTooltipProps {
|
|
1152
|
+
anchor: HTMLElement;
|
|
1153
|
+
label: string;
|
|
1154
|
+
warmRef?: TooltipWarmRef;
|
|
1155
|
+
}
|
|
1156
|
+
|
|
1157
|
+
interface SystemActionButtonProps {
|
|
1158
|
+
collapsed: boolean;
|
|
1159
|
+
disabled: boolean;
|
|
1160
|
+
isPending: boolean;
|
|
1161
|
+
isRunning: boolean;
|
|
1162
|
+
item: SystemActionItem;
|
|
1163
|
+
onClick: () => void;
|
|
1164
|
+
tooltipWarmRef: TooltipWarmRef;
|
|
1165
|
+
}
|
|
1166
|
+
|
|
1167
|
+
interface SystemActionItem {
|
|
1168
|
+
action: SystemAction;
|
|
1169
|
+
icon: ComponentType<{ className?: string }>;
|
|
1170
|
+
label: string;
|
|
1171
|
+
runningLabel: string;
|
|
1172
|
+
spin: boolean;
|
|
1173
|
+
}
|