@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.
Files changed (98) hide show
  1. package/eslint.config.js +23 -0
  2. package/index.html +24 -0
  3. package/package.json +54 -26
  4. package/package.json.bak +89 -0
  5. package/package.json.pub +88 -0
  6. package/src/App.tsx +1173 -0
  7. package/src/components/AuthWidget.tsx +150 -0
  8. package/src/components/AutoField.tsx +206 -0
  9. package/src/components/Backdrop.tsx +93 -0
  10. package/src/components/ChatSidebar.tsx +394 -0
  11. package/src/components/DeleteConfirmDialog.tsx +40 -0
  12. package/src/components/LanguageSwitcher.tsx +186 -0
  13. package/src/components/Markdown.tsx +383 -0
  14. package/src/components/ModelInfoCard.tsx +112 -0
  15. package/src/components/ModelPickerDialog.tsx +470 -0
  16. package/src/components/OAuthLoginModal.tsx +374 -0
  17. package/src/components/OAuthProvidersCard.tsx +287 -0
  18. package/src/components/PlatformsCard.tsx +97 -0
  19. package/src/components/ScheduleBuilder.tsx +273 -0
  20. package/src/components/SidebarFooter.tsx +42 -0
  21. package/src/components/SidebarStatusStrip.tsx +72 -0
  22. package/src/components/SlashPopover.tsx +171 -0
  23. package/src/components/ThemeSwitcher.tsx +243 -0
  24. package/src/components/ToolCall.tsx +228 -0
  25. package/src/components/ToolsetConfigDrawer.tsx +448 -0
  26. package/src/contexts/PageHeaderProvider.tsx +139 -0
  27. package/src/contexts/SystemActions.tsx +120 -0
  28. package/src/contexts/page-header-context.ts +12 -0
  29. package/src/contexts/system-actions-context.ts +18 -0
  30. package/src/contexts/usePageHeader.ts +10 -0
  31. package/src/contexts/useSystemActions.ts +15 -0
  32. package/src/hooks/useModalBehavior.ts +44 -0
  33. package/src/hooks/useSidebarStatus.ts +27 -0
  34. package/src/i18n/af.ts +702 -0
  35. package/src/i18n/context.tsx +123 -0
  36. package/src/i18n/de.ts +701 -0
  37. package/src/i18n/en.ts +708 -0
  38. package/src/i18n/es.ts +701 -0
  39. package/src/i18n/fr.ts +701 -0
  40. package/src/i18n/ga.ts +702 -0
  41. package/src/i18n/hu.ts +702 -0
  42. package/src/i18n/index.ts +2 -0
  43. package/src/i18n/it.ts +701 -0
  44. package/src/i18n/ja.ts +702 -0
  45. package/src/i18n/ko.ts +702 -0
  46. package/src/i18n/pt.ts +702 -0
  47. package/src/i18n/ru.ts +702 -0
  48. package/src/i18n/tr.ts +702 -0
  49. package/src/i18n/types.ts +710 -0
  50. package/src/i18n/uk.ts +702 -0
  51. package/src/i18n/zh-hant.ts +702 -0
  52. package/src/i18n/zh.ts +698 -0
  53. package/src/index.css +274 -0
  54. package/src/lib/api.ts +1585 -0
  55. package/src/lib/dashboard-flags.ts +15 -0
  56. package/src/lib/format.ts +9 -0
  57. package/src/lib/fuzzy.ts +192 -0
  58. package/src/lib/gatewayClient.ts +253 -0
  59. package/src/lib/nested.ts +23 -0
  60. package/src/lib/resolve-page-title.ts +41 -0
  61. package/src/lib/schedule.ts +382 -0
  62. package/src/lib/slashExec.ts +163 -0
  63. package/src/lib/utils.ts +35 -0
  64. package/src/main.tsx +25 -0
  65. package/src/pages/AnalyticsPage.tsx +601 -0
  66. package/src/pages/ChannelsPage.tsx +772 -0
  67. package/src/pages/ChatPage.tsx +889 -0
  68. package/src/pages/ConfigPage.tsx +660 -0
  69. package/src/pages/CronPage.tsx +524 -0
  70. package/src/pages/DocsPage.tsx +69 -0
  71. package/src/pages/EnvPage.tsx +918 -0
  72. package/src/pages/LogsPage.tsx +246 -0
  73. package/src/pages/McpPage.tsx +757 -0
  74. package/src/pages/ModelsPage.tsx +994 -0
  75. package/src/pages/PairingPage.tsx +276 -0
  76. package/src/pages/PluginsPage.tsx +580 -0
  77. package/src/pages/ProfilesPage.tsx +559 -0
  78. package/src/pages/SessionsPage.tsx +936 -0
  79. package/src/pages/SkillsPage.tsx +557 -0
  80. package/src/pages/SystemPage.tsx +1259 -0
  81. package/src/pages/WebhooksPage.tsx +483 -0
  82. package/src/plugins/PluginPage.tsx +64 -0
  83. package/src/plugins/index.ts +6 -0
  84. package/src/plugins/registry.ts +151 -0
  85. package/src/plugins/sdk.d.ts +160 -0
  86. package/src/plugins/slots.ts +199 -0
  87. package/src/plugins/types.ts +37 -0
  88. package/src/plugins/usePlugins.ts +133 -0
  89. package/src/themes/context.tsx +443 -0
  90. package/src/themes/fonts.ts +160 -0
  91. package/src/themes/index.ts +3 -0
  92. package/src/themes/presets.ts +477 -0
  93. package/src/themes/types.ts +187 -0
  94. package/tsconfig.app.json +34 -0
  95. package/tsconfig.json +7 -0
  96. package/tsconfig.node.json +26 -0
  97. package/vite.config.ts +124 -0
  98. package/vite.config.ts.timestamp-1780999102396-af6b77b30ebd8.mjs +105 -0
@@ -0,0 +1,448 @@
1
+ import { useCallback, useEffect, useState } from "react";
2
+ import { createPortal } from "react-dom";
3
+ import { Check, ExternalLink, Loader2, Terminal, X } from "lucide-react";
4
+ import { api } from "@/lib/api";
5
+ import type {
6
+ ToolsetConfig,
7
+ ToolsetInfo,
8
+ ToolsetProvider,
9
+ } from "@/lib/api";
10
+ import { useToast } from "@nastechai/ui/hooks/use-toast";
11
+ import { Button } from "@nastechai/ui/ui/components/button";
12
+ import { Input } from "@nastechai/ui/ui/components/input";
13
+ import { Label } from "@nastechai/ui/ui/components/label";
14
+ import { Badge } from "@nastechai/ui/ui/components/badge";
15
+ import { Switch } from "@nastechai/ui/ui/components/switch";
16
+ import { Spinner } from "@nastechai/ui/ui/components/spinner";
17
+ import { Toast } from "@nastechai/ui/ui/components/toast";
18
+ import { cn, themedBody } from "@/lib/utils";
19
+
20
+ interface Props {
21
+ /** The toolset whose backends are being configured. */
22
+ toolset: ToolsetInfo;
23
+ onClose: () => void;
24
+ /** Called after a toggle/provider/key change so the parent grid refreshes. */
25
+ onChanged: () => void;
26
+ }
27
+
28
+ /**
29
+ * Full configuration surface for a single toolset's backends — the dashboard
30
+ * equivalent of selecting a toolset in the `nastech tools` curses UI: toggle
31
+ * the toolset on/off, pick a provider, enter API keys, and run a provider's
32
+ * post-setup install hook (npm/pip/binary) with a live log tail.
33
+ */
34
+ export function ToolsetConfigDrawer({ toolset, onClose, onChanged }: Props) {
35
+ const { toast, showToast } = useToast();
36
+ const [config, setConfig] = useState<ToolsetConfig | null>(null);
37
+ const [loading, setLoading] = useState(true);
38
+ const [enabled, setEnabled] = useState(toolset.enabled);
39
+ const [toggling, setToggling] = useState(false);
40
+ const [selecting, setSelecting] = useState<string | null>(null);
41
+ const [activeProvider, setActiveProvider] = useState<string | null>(null);
42
+ // Per-env-var draft input values, keyed by env var name.
43
+ const [drafts, setDrafts] = useState<Record<string, string>>({});
44
+ const [savingProvider, setSavingProvider] = useState<string | null>(null);
45
+ const [isSet, setIsSet] = useState<Record<string, boolean>>({});
46
+
47
+ // Post-setup install log tail state.
48
+ const [postSetupRunning, setPostSetupRunning] = useState(false);
49
+ const [postSetupLog, setPostSetupLog] = useState<string[]>([]);
50
+ const [postSetupKey, setPostSetupKey] = useState<string | null>(null);
51
+ // Bumped each time a post-setup is kicked off, to (re)trigger the poll
52
+ // effect below. Mirrors the SkillsPage HubBrowser action-poll pattern so
53
+ // the recursive timer lives inside the effect (lint-clean — no ref
54
+ // mutation, no self-referencing memo).
55
+ const [postSetupTrigger, setPostSetupTrigger] = useState(0);
56
+
57
+ const loadConfig = useCallback(() => {
58
+ // Promise-chain shape (not async/await with a leading synchronous
59
+ // setLoading) so callers in a useEffect don't trip
60
+ // react-hooks/set-state-in-effect — setState only fires inside the
61
+ // async .then/.catch/.finally callbacks.
62
+ return api
63
+ .getToolsetConfig(toolset.name)
64
+ .then((cfg) => {
65
+ setConfig(cfg);
66
+ setActiveProvider(cfg.active_provider);
67
+ const seed: Record<string, boolean> = {};
68
+ for (const p of cfg.providers) {
69
+ for (const e of p.env_vars) seed[e.key] = e.is_set;
70
+ }
71
+ setIsSet(seed);
72
+ })
73
+ .catch(() => showToast("Failed to load toolset config", "error"))
74
+ .finally(() => setLoading(false));
75
+ }, [toolset.name, showToast]);
76
+
77
+ useEffect(() => {
78
+ void loadConfig();
79
+ }, [loadConfig]);
80
+
81
+ // Poll the post-setup action's log until it exits. Driven by
82
+ // postSetupTrigger; the recursive timer + cleanup live entirely inside the
83
+ // effect (matches the SkillsPage HubBrowser pattern — lint-clean).
84
+ useEffect(() => {
85
+ if (postSetupTrigger === 0) return;
86
+ let cancelled = false;
87
+ let timer: ReturnType<typeof setTimeout> | null = null;
88
+ const poll = async () => {
89
+ try {
90
+ const st = await api.getActionStatus("tools-post-setup", 300);
91
+ if (cancelled) return;
92
+ setPostSetupLog(st.lines);
93
+ if (st.running) {
94
+ timer = setTimeout(() => void poll(), 1200);
95
+ } else {
96
+ setPostSetupRunning(false);
97
+ const ok = st.exit_code === 0;
98
+ showToast(
99
+ ok ? "Post-setup complete" : "Post-setup finished with errors",
100
+ ok ? "success" : "error",
101
+ );
102
+ // Refresh — a backend may now report itself configured/available.
103
+ void loadConfig();
104
+ onChanged();
105
+ }
106
+ } catch {
107
+ if (!cancelled) {
108
+ setPostSetupRunning(false);
109
+ showToast("Lost track of the post-setup process", "error");
110
+ }
111
+ }
112
+ };
113
+ // Small delay so the spawned action has a log file to read.
114
+ timer = setTimeout(() => void poll(), 800);
115
+ return () => {
116
+ cancelled = true;
117
+ if (timer) clearTimeout(timer);
118
+ };
119
+ }, [postSetupTrigger, showToast, loadConfig, onChanged]);
120
+
121
+ const handleToggle = async (next: boolean) => {
122
+ setToggling(true);
123
+ try {
124
+ await api.toggleToolset(toolset.name, next);
125
+ setEnabled(next);
126
+ showToast(
127
+ `${toolset.label || toolset.name} ${next ? "enabled" : "disabled"}`,
128
+ "success",
129
+ );
130
+ onChanged();
131
+ } catch {
132
+ showToast("Failed to toggle toolset", "error");
133
+ } finally {
134
+ setToggling(false);
135
+ }
136
+ };
137
+
138
+ const handleSelectProvider = async (provider: ToolsetProvider) => {
139
+ setSelecting(provider.name);
140
+ try {
141
+ await api.selectToolsetProvider(toolset.name, provider.name);
142
+ setActiveProvider(provider.name);
143
+ showToast(`Provider set to ${provider.name}`, "success");
144
+ onChanged();
145
+ } catch (e) {
146
+ showToast(
147
+ e instanceof Error ? e.message : "Failed to select provider",
148
+ "error",
149
+ );
150
+ } finally {
151
+ setSelecting(null);
152
+ }
153
+ };
154
+
155
+ const handleSaveKeys = async (provider: ToolsetProvider) => {
156
+ const env: Record<string, string> = {};
157
+ for (const e of provider.env_vars) {
158
+ const v = drafts[e.key];
159
+ if (v && v.trim()) env[e.key] = v.trim();
160
+ }
161
+ if (Object.keys(env).length === 0) {
162
+ showToast("Enter at least one value to save", "error");
163
+ return;
164
+ }
165
+ setSavingProvider(provider.name);
166
+ try {
167
+ const res = await api.saveToolsetEnv(toolset.name, env);
168
+ setIsSet((prev) => ({ ...prev, ...res.is_set }));
169
+ // Clear saved drafts so the inputs reset to the "saved" placeholder.
170
+ setDrafts((prev) => {
171
+ const next = { ...prev };
172
+ for (const k of res.saved) delete next[k];
173
+ return next;
174
+ });
175
+ showToast(
176
+ res.saved.length
177
+ ? `Saved ${res.saved.length} key${res.saved.length > 1 ? "s" : ""}`
178
+ : "Nothing to save",
179
+ "success",
180
+ );
181
+ onChanged();
182
+ } catch (e) {
183
+ showToast(
184
+ e instanceof Error ? e.message : "Failed to save keys",
185
+ "error",
186
+ );
187
+ } finally {
188
+ setSavingProvider(null);
189
+ }
190
+ };
191
+
192
+ const handleRunPostSetup = async (provider: ToolsetProvider) => {
193
+ if (!provider.post_setup) return;
194
+ setPostSetupRunning(true);
195
+ setPostSetupLog([]);
196
+ setPostSetupKey(provider.post_setup);
197
+ try {
198
+ await api.runToolsetPostSetup(toolset.name, provider.post_setup);
199
+ // Bump the trigger so the poll effect (re)starts tailing the log.
200
+ setPostSetupTrigger((n) => n + 1);
201
+ } catch (e) {
202
+ setPostSetupRunning(false);
203
+ showToast(
204
+ e instanceof Error ? e.message : "Failed to start post-setup",
205
+ "error",
206
+ );
207
+ }
208
+ };
209
+
210
+ const labelText = toolset.label?.trim() || toolset.name;
211
+
212
+ return createPortal(
213
+ <div
214
+ className="fixed inset-0 z-[100] flex items-center justify-center bg-background/85 backdrop-blur-sm p-4"
215
+ onMouseDown={(e) => {
216
+ if (e.target === e.currentTarget) onClose();
217
+ }}
218
+ >
219
+ <div
220
+ className={cn(
221
+ themedBody,
222
+ "relative w-full max-w-2xl max-h-[85vh] border border-border bg-card shadow-2xl flex flex-col",
223
+ )}
224
+ >
225
+ <Button
226
+ ghost
227
+ size="xs"
228
+ className="absolute right-2 top-2 text-muted-foreground hover:text-foreground"
229
+ onClick={onClose}
230
+ aria-label="Close"
231
+ >
232
+ <X />
233
+ </Button>
234
+
235
+ {/* Header — toolset identity + enable toggle */}
236
+ <header className="p-5 pb-3 border-b border-border">
237
+ <div className="flex items-center gap-3 pr-8">
238
+ <span className="font-mondwest text-display text-base tracking-wider">
239
+ {labelText}
240
+ </span>
241
+ <Badge tone={enabled ? "success" : "outline"} className="text-xs">
242
+ {enabled ? "Active" : "Inactive"}
243
+ </Badge>
244
+ </div>
245
+ <p className="text-xs text-muted-foreground mt-1">
246
+ {toolset.description}
247
+ </p>
248
+ <div className="mt-3 flex items-center gap-2">
249
+ <Switch
250
+ checked={enabled}
251
+ onCheckedChange={(v) => void handleToggle(v)}
252
+ disabled={toggling}
253
+ aria-label="Enable toolset"
254
+ />
255
+ <span className="text-xs text-muted-foreground">
256
+ {enabled ? "Enabled for the agent" : "Disabled"}
257
+ </span>
258
+ </div>
259
+ </header>
260
+
261
+ {/* Body — provider matrix */}
262
+ <div className="flex-1 min-h-0 overflow-y-auto p-5 pt-4 space-y-4">
263
+ {loading ? (
264
+ <div className="flex items-center justify-center py-10">
265
+ <Spinner />
266
+ </div>
267
+ ) : !config?.has_category ? (
268
+ <p className="text-sm text-muted-foreground py-6 text-center">
269
+ This toolset has no configurable backends — toggle it on or off
270
+ above. It works with no provider selection or API keys.
271
+ </p>
272
+ ) : config.providers.length === 0 ? (
273
+ <p className="text-sm text-muted-foreground py-6 text-center">
274
+ No providers are available for this toolset in this install.
275
+ </p>
276
+ ) : (
277
+ config.providers.map((provider) => {
278
+ const isActive = provider.name === activeProvider;
279
+ return (
280
+ <div
281
+ key={provider.name}
282
+ className={cn(
283
+ "border border-border p-3",
284
+ isActive && "border-emerald-500/60 bg-emerald-500/5",
285
+ )}
286
+ >
287
+ <div className="flex items-center justify-between gap-2">
288
+ <div className="flex items-center gap-2 min-w-0">
289
+ <span className="font-medium text-sm">
290
+ {provider.name}
291
+ </span>
292
+ {provider.badge && (
293
+ <Badge tone="secondary" className="text-xs">
294
+ {provider.badge}
295
+ </Badge>
296
+ )}
297
+ {provider.requires_nastech_auth && (
298
+ <Badge tone="outline" className="text-xs">
299
+ NasTech Portal
300
+ </Badge>
301
+ )}
302
+ </div>
303
+ {isActive ? (
304
+ <Badge tone="success" className="text-xs shrink-0">
305
+ <Check className="h-3 w-3 mr-0.5" /> Selected
306
+ </Badge>
307
+ ) : (
308
+ <Button
309
+ size="xs"
310
+ outlined
311
+ onClick={() => void handleSelectProvider(provider)}
312
+ disabled={selecting !== null}
313
+ >
314
+ {selecting === provider.name ? (
315
+ <Loader2 className="h-3 w-3 animate-spin" />
316
+ ) : (
317
+ "Select"
318
+ )}
319
+ </Button>
320
+ )}
321
+ </div>
322
+ {provider.tag && (
323
+ <p className="text-xs text-muted-foreground mt-1">
324
+ {provider.tag}
325
+ </p>
326
+ )}
327
+
328
+ {/* API key inputs */}
329
+ {provider.env_vars.length > 0 && (
330
+ <div className="mt-3 space-y-2.5">
331
+ {provider.env_vars.map((ev) => (
332
+ <div key={ev.key} className="space-y-1">
333
+ <div className="flex items-center justify-between gap-2">
334
+ <Label
335
+ htmlFor={`env-${ev.key}`}
336
+ className="text-xs font-mono"
337
+ >
338
+ {ev.key}
339
+ </Label>
340
+ {isSet[ev.key] && (
341
+ <Badge tone="success" className="text-xs">
342
+ Saved
343
+ </Badge>
344
+ )}
345
+ </div>
346
+ <Input
347
+ id={`env-${ev.key}`}
348
+ type="password"
349
+ className="h-8 rounded-none text-xs font-mono"
350
+ placeholder={
351
+ isSet[ev.key]
352
+ ? "•••••••• (saved — leave blank to keep)"
353
+ : ev.prompt || ev.key
354
+ }
355
+ value={drafts[ev.key] ?? ""}
356
+ onChange={(e) =>
357
+ setDrafts((prev) => ({
358
+ ...prev,
359
+ [ev.key]: e.target.value,
360
+ }))
361
+ }
362
+ />
363
+ {ev.url && (
364
+ <a
365
+ href={ev.url}
366
+ target="_blank"
367
+ rel="noreferrer"
368
+ className="inline-flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground"
369
+ >
370
+ <ExternalLink className="h-3 w-3" /> Get a key
371
+ </a>
372
+ )}
373
+ </div>
374
+ ))}
375
+ <Button
376
+ size="xs"
377
+ onClick={() => void handleSaveKeys(provider)}
378
+ disabled={savingProvider !== null}
379
+ >
380
+ {savingProvider === provider.name ? (
381
+ <Loader2 className="h-3 w-3 animate-spin" />
382
+ ) : (
383
+ "Save keys"
384
+ )}
385
+ </Button>
386
+ </div>
387
+ )}
388
+
389
+ {/* Post-setup install hook */}
390
+ {provider.post_setup && (
391
+ <div className="mt-3 border-t border-border pt-3">
392
+ <p className="text-xs text-muted-foreground mb-1.5">
393
+ This backend needs a one-time install
394
+ {" "}
395
+ <span className="font-mono">
396
+ ({provider.post_setup})
397
+ </span>
398
+ . Runs on this host — may take a few minutes.
399
+ </p>
400
+ <Button
401
+ size="xs"
402
+ outlined
403
+ onClick={() => void handleRunPostSetup(provider)}
404
+ disabled={postSetupRunning}
405
+ >
406
+ {postSetupRunning &&
407
+ postSetupKey === provider.post_setup ? (
408
+ <>
409
+ <Loader2 className="h-3 w-3 animate-spin mr-1" />
410
+ Installing…
411
+ </>
412
+ ) : (
413
+ <>
414
+ <Terminal className="h-3 w-3 mr-1" /> Run setup
415
+ </>
416
+ )}
417
+ </Button>
418
+ </div>
419
+ )}
420
+ </div>
421
+ );
422
+ })
423
+ )}
424
+
425
+ {/* Post-setup live log */}
426
+ {(postSetupRunning || postSetupLog.length > 0) && (
427
+ <div className="border border-border">
428
+ <div className="flex items-center gap-2 px-3 py-1.5 border-b border-border bg-muted/30">
429
+ <Terminal className="h-3.5 w-3.5 text-muted-foreground" />
430
+ <span className="text-xs font-mono text-muted-foreground">
431
+ post-setup: {postSetupKey}
432
+ </span>
433
+ {postSetupRunning && (
434
+ <Loader2 className="h-3 w-3 animate-spin ml-auto text-muted-foreground" />
435
+ )}
436
+ </div>
437
+ <pre className="max-h-48 overflow-y-auto p-3 text-xs font-mono whitespace-pre-wrap text-text-secondary">
438
+ {postSetupLog.length ? postSetupLog.join("\n") : "Starting…"}
439
+ </pre>
440
+ </div>
441
+ )}
442
+ </div>
443
+ </div>
444
+ <Toast toast={toast} />
445
+ </div>,
446
+ document.body,
447
+ );
448
+ }
@@ -0,0 +1,139 @@
1
+ import { useLayoutEffect, useMemo, useState, type ReactNode } from "react";
2
+ import { useLocation } from "react-router-dom";
3
+ import { PageHeaderContext } from "./page-header-context";
4
+ import { resolvePageTitle } from "@/lib/resolve-page-title";
5
+ import { cn } from "@/lib/utils";
6
+ import { useI18n } from "@/i18n";
7
+
8
+ export function PageHeaderProvider({
9
+ children,
10
+ pluginTabs,
11
+ }: {
12
+ children: ReactNode;
13
+ pluginTabs: { path: string; label: string }[];
14
+ }) {
15
+ const { pathname } = useLocation();
16
+ const { t } = useI18n();
17
+ const [titleOverride, setTitleOverride] = useState<string | null>(null);
18
+ const [afterTitle, setAfterTitle] = useState<ReactNode>(null);
19
+ const [end, setEnd] = useState<ReactNode>(null);
20
+
21
+ // Clear any per-page title / toolbar slots when the path changes. Child routes
22
+ // re-fill these on mount via usePageHeader.
23
+ /* eslint-disable react-hooks/set-state-in-effect */
24
+ useLayoutEffect(() => {
25
+ setTitleOverride(null);
26
+ setAfterTitle(null);
27
+ setEnd(null);
28
+ }, [pathname]);
29
+ /* eslint-enable react-hooks/set-state-in-effect */
30
+
31
+ const defaultTitle = useMemo(
32
+ () => resolvePageTitle(pathname, t, pluginTabs),
33
+ [pathname, t, pluginTabs],
34
+ );
35
+ const displayTitle = titleOverride ?? defaultTitle;
36
+
37
+ const isChatRoute = pathname === "/chat" || pathname === "/chat/";
38
+ /** Env jump-nav is wide — stack below title on small screens so KEYS stays readable. */
39
+ const isEnvRoute =
40
+ pathname === "/env" || pathname.startsWith("/env/");
41
+
42
+ const value = useMemo(
43
+ () => ({
44
+ setAfterTitle,
45
+ setEnd,
46
+ setTitle: setTitleOverride,
47
+ }),
48
+ [],
49
+ );
50
+
51
+ return (
52
+ <PageHeaderContext.Provider value={value}>
53
+ <div className="flex min-h-0 w-full min-w-0 flex-1 flex-col overflow-hidden">
54
+ <header
55
+ className={cn(
56
+ "z-1 w-full shrink-0",
57
+ "box-border border-b border-current/20",
58
+ "bg-background-base/40 backdrop-blur-sm",
59
+ // Mobile stacks title + toolbar — fixed h-14 clips content; desktop stays one row.
60
+ "min-h-0 overflow-x-hidden overflow-y-visible py-3 sm:h-14 sm:min-h-[3.5rem] sm:overflow-hidden sm:py-0",
61
+ )}
62
+ role="banner"
63
+ >
64
+ <div
65
+ className={cn(
66
+ "flex w-full min-w-0 flex-1 gap-3 px-3 sm:h-full sm:gap-3 sm:px-6",
67
+ isChatRoute
68
+ ? "flex-row items-center"
69
+ : "flex-col justify-center sm:flex-row sm:items-center",
70
+ )}
71
+ >
72
+ <div
73
+ className={cn(
74
+ "flex min-w-0 flex-1 gap-2 sm:gap-3",
75
+ afterTitle && isEnvRoute
76
+ ? "flex-col items-start sm:flex-row sm:items-center"
77
+ : afterTitle
78
+ ? "flex-row flex-wrap items-center"
79
+ : "flex-row items-center",
80
+ )}
81
+ >
82
+ <h1
83
+ className={cn(
84
+ "font-expanded min-w-0 text-sm font-bold tracking-[0.08em] text-midground",
85
+ afterTitle && isEnvRoute
86
+ ? "max-w-full sm:min-w-0 sm:shrink sm:truncate"
87
+ : afterTitle
88
+ ? "shrink truncate"
89
+ : "truncate",
90
+ )}
91
+ style={{ mixBlendMode: "plus-lighter" }}
92
+ >
93
+ {displayTitle}
94
+ </h1>
95
+ {afterTitle ? (
96
+ <div
97
+ className={cn(
98
+ "min-w-0 scrollbar-none",
99
+ isEnvRoute
100
+ ? "w-full overflow-x-auto sm:flex-1 sm:overflow-x-auto"
101
+ : "shrink-0 overflow-visible",
102
+ )}
103
+ >
104
+ {afterTitle}
105
+ </div>
106
+ ) : null}
107
+ </div>
108
+
109
+ {end ? (
110
+ <div
111
+ className={cn(
112
+ "flex min-w-0 sm:max-w-md sm:flex-1",
113
+ isChatRoute
114
+ ? "w-auto shrink-0 justify-end"
115
+ : "w-full justify-start sm:justify-end",
116
+ )}
117
+ >
118
+ {end}
119
+ </div>
120
+ ) : null}
121
+ </div>
122
+ </header>
123
+
124
+ <main
125
+ className={cn(
126
+ "min-h-0 w-full min-w-0 flex-1 flex flex-col",
127
+ // Bottom inset for scrolled pages lives on the route outlet wrapper in
128
+ // `App.tsx` (`w-full min-w-0`) so it pads scrollable content, not flex chrome.
129
+ isChatRoute
130
+ ? "overflow-hidden"
131
+ : "overflow-y-auto overflow-x-hidden [scrollbar-gutter:stable]",
132
+ )}
133
+ >
134
+ {children}
135
+ </main>
136
+ </div>
137
+ </PageHeaderContext.Provider>
138
+ );
139
+ }