@flame0510/project-aether 1.1.9

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 (290) hide show
  1. package/README.md +150 -0
  2. package/agent-templates/README.md +37 -0
  3. package/agent-templates/argus/AGENTS.md +52 -0
  4. package/agent-templates/argus/IDENTITY.md +7 -0
  5. package/agent-templates/argus/MEMORY.md +9 -0
  6. package/agent-templates/argus/SOUL.md +24 -0
  7. package/agent-templates/argus/TOOLS.md +8 -0
  8. package/agent-templates/atlas/AGENTS.md +47 -0
  9. package/agent-templates/atlas/HEARTBEAT.md +10 -0
  10. package/agent-templates/atlas/IDENTITY.md +6 -0
  11. package/agent-templates/atlas/MEMORY.md +9 -0
  12. package/agent-templates/atlas/SOUL.md +21 -0
  13. package/agent-templates/atlas/TOOLS.md +4 -0
  14. package/agent-templates/base-image/.trigger +0 -0
  15. package/agent-templates/base-image/Dockerfile +90 -0
  16. package/agent-templates/base-image/entrypoint.sh +37 -0
  17. package/agent-templates/custom/AGENTS.md +29 -0
  18. package/agent-templates/custom/BOOTSTRAP.md +56 -0
  19. package/agent-templates/custom/MEMORY.md +8 -0
  20. package/agent-templates/prometheus/AGENTS.md +37 -0
  21. package/agent-templates/prometheus/IDENTITY.md +6 -0
  22. package/agent-templates/prometheus/MEMORY.md +9 -0
  23. package/agent-templates/prometheus/SOUL.md +21 -0
  24. package/agent-templates/prometheus/TOOLS.md +4 -0
  25. package/app/agents/ChannelManager.tsx +465 -0
  26. package/app/agents/ImageDownloadBanner.tsx +159 -0
  27. package/app/agents/PageClient.tsx +1285 -0
  28. package/app/agents/create/PageClient.tsx +437 -0
  29. package/app/agents/create/page.tsx +126 -0
  30. package/app/agents/loading.tsx +14 -0
  31. package/app/agents/page.tsx +5 -0
  32. package/app/api/agents/[id]/backup/route.ts +169 -0
  33. package/app/api/agents/[id]/channels/pairing/route.ts +69 -0
  34. package/app/api/agents/[id]/channels/route.ts +14 -0
  35. package/app/api/agents/[id]/channels/telegram/route.ts +50 -0
  36. package/app/api/agents/[id]/lifecycle/route.ts +94 -0
  37. package/app/api/agents/[id]/recreate/route.ts +199 -0
  38. package/app/api/agents/[id]/restart/route.ts +33 -0
  39. package/app/api/agents/[id]/restore/route.ts +81 -0
  40. package/app/api/agents/[id]/route.ts +280 -0
  41. package/app/api/agents/channels-summary/route.ts +39 -0
  42. package/app/api/agents/config-json/route.ts +58 -0
  43. package/app/api/agents/create/route.ts +488 -0
  44. package/app/api/agents/download-image/route.ts +32 -0
  45. package/app/api/agents/image-status/route.ts +126 -0
  46. package/app/api/agents/route.ts +213 -0
  47. package/app/api/agents/token/route.ts +94 -0
  48. package/app/api/agents-active/route.ts +190 -0
  49. package/app/api/agents-config/route.ts +629 -0
  50. package/app/api/alerts/smoke/route.ts +26 -0
  51. package/app/api/aliases/add/route.ts +28 -0
  52. package/app/api/aliases/remove/route.ts +27 -0
  53. package/app/api/assistant/route.ts +204 -0
  54. package/app/api/auth/check/route.ts +38 -0
  55. package/app/api/auth/login/route.ts +85 -0
  56. package/app/api/auth/logout/route.ts +7 -0
  57. package/app/api/auth/status/route.ts +33 -0
  58. package/app/api/config/env/route.ts +132 -0
  59. package/app/api/config/restart/route.ts +26 -0
  60. package/app/api/containers/route.ts +75 -0
  61. package/app/api/cost-override/route.ts +46 -0
  62. package/app/api/costs/route.ts +84 -0
  63. package/app/api/credentials/[id]/reveal/route.ts +21 -0
  64. package/app/api/credentials/[id]/route.ts +52 -0
  65. package/app/api/credentials/[id]/sync/route.ts +58 -0
  66. package/app/api/credentials/detect/route.ts +246 -0
  67. package/app/api/credentials/route.ts +33 -0
  68. package/app/api/crons/[id]/route.ts +69 -0
  69. package/app/api/crons/route.ts +12 -0
  70. package/app/api/crons/runs/route.ts +31 -0
  71. package/app/api/debug/route.ts +11 -0
  72. package/app/api/envcheck/route.ts +18 -0
  73. package/app/api/events/route.ts +24 -0
  74. package/app/api/gateway/agent/route.ts +154 -0
  75. package/app/api/gateway/provider/balance/route.ts +38 -0
  76. package/app/api/gateway/provider/keys.ts +38 -0
  77. package/app/api/gateway/provider/oauth/route.ts +304 -0
  78. package/app/api/gateway/provider/route.ts +209 -0
  79. package/app/api/gateway/route.ts +223 -0
  80. package/app/api/gateway/sync.ts +189 -0
  81. package/app/api/lineage/route.ts +54 -0
  82. package/app/api/memory-context/route.ts +15 -0
  83. package/app/api/metrics/route.ts +35 -0
  84. package/app/api/models/route.ts +77 -0
  85. package/app/api/plugins/route.js +37 -0
  86. package/app/api/provider/upstream.ts +142 -0
  87. package/app/api/provider/v1/chat/completions/route.ts +146 -0
  88. package/app/api/provider/v1/models/route.ts +167 -0
  89. package/app/api/provider-usage/route.ts +629 -0
  90. package/app/api/session/route.ts +39 -0
  91. package/app/api/sessions/[id]/route.ts +38 -0
  92. package/app/api/sessions/route.ts +23 -0
  93. package/app/api/setup/agent-image/route.ts +102 -0
  94. package/app/api/setup/password/route.ts +111 -0
  95. package/app/api/setup/restart/route.ts +76 -0
  96. package/app/api/skills/delete/route.js +105 -0
  97. package/app/api/skills/promote/route.js +129 -0
  98. package/app/api/skills/route.js +203 -0
  99. package/app/api/skills/save/route.js +142 -0
  100. package/app/api/stats/route.ts +34 -0
  101. package/app/api/stats-since/route.ts +20 -0
  102. package/app/api/stream/route.ts +70 -0
  103. package/app/api/system-health/route.ts +233 -0
  104. package/app/api/tool-calls/route.ts +24 -0
  105. package/app/api/tools-config/route.ts +163 -0
  106. package/app/api/update-check/route.ts +127 -0
  107. package/app/api/version/route.ts +25 -0
  108. package/app/api/wizard/complete/route.ts +32 -0
  109. package/app/api/wizard/reset/route.ts +28 -0
  110. package/app/api/wizard/status/route.ts +28 -0
  111. package/app/api/workspace/route.ts +392 -0
  112. package/app/api/workspace/stream/route.ts +136 -0
  113. package/app/components/AppShell.tsx +33 -0
  114. package/app/components/AuthGuard.tsx +91 -0
  115. package/app/components/CostBreakdown.tsx +37 -0
  116. package/app/components/DashboardHeader.tsx +73 -0
  117. package/app/components/DashboardLayout.tsx +76 -0
  118. package/app/components/DashboardToolbar.tsx +61 -0
  119. package/app/components/FloatingActions.tsx +33 -0
  120. package/app/components/Icons.tsx +78 -0
  121. package/app/components/LineageGraphPage.tsx +142 -0
  122. package/app/components/LiveFeed.tsx +48 -0
  123. package/app/components/MobileBottomNav.tsx +84 -0
  124. package/app/components/ModelPickerModal.tsx +94 -0
  125. package/app/components/PasswordInput.tsx +86 -0
  126. package/app/components/PulseChat.tsx +362 -0
  127. package/app/components/Rev4aLoader.tsx +48 -0
  128. package/app/components/SessionDrawer.tsx +263 -0
  129. package/app/components/SessionTopology.tsx +289 -0
  130. package/app/components/Sidebar.tsx +294 -0
  131. package/app/components/Skeleton.tsx +133 -0
  132. package/app/components/SystemCockpit.tsx +169 -0
  133. package/app/components/VersionBanner.tsx +105 -0
  134. package/app/components/WizardButton.tsx +30 -0
  135. package/app/components/ui/Badge.tsx +30 -0
  136. package/app/components/ui/Button.tsx +59 -0
  137. package/app/components/ui/ConfirmModal.tsx +46 -0
  138. package/app/components/ui/FilterBar.tsx +33 -0
  139. package/app/components/ui/Input.tsx +25 -0
  140. package/app/components/ui/ItemList.tsx +83 -0
  141. package/app/components/ui/LoadingSpinner.tsx +30 -0
  142. package/app/components/ui/Metric.tsx +22 -0
  143. package/app/components/ui/Modal.tsx +42 -0
  144. package/app/components/ui/Page.tsx +18 -0
  145. package/app/components/ui/Pill.tsx +6 -0
  146. package/app/components/ui/PropertyList.tsx +24 -0
  147. package/app/components/ui/Select.tsx +26 -0
  148. package/app/components/ui/StatusCard.tsx +32 -0
  149. package/app/components/ui/Surface.tsx +14 -0
  150. package/app/components/ui/Tabs.tsx +55 -0
  151. package/app/components/ui/TemplateOption.tsx +59 -0
  152. package/app/components/ui/Toast.tsx +44 -0
  153. package/app/components/ui/index.ts +19 -0
  154. package/app/components/ui/tokens.ts +18 -0
  155. package/app/config/PageClient.tsx +293 -0
  156. package/app/config/loading.tsx +10 -0
  157. package/app/config/page.tsx +7 -0
  158. package/app/containers/ContainersClient.tsx +129 -0
  159. package/app/containers/loading.tsx +21 -0
  160. package/app/containers/page.tsx +5 -0
  161. package/app/containers/terminal/[id]/TerminalClient.tsx +313 -0
  162. package/app/containers/terminal/[id]/page.tsx +6 -0
  163. package/app/credentials/PageClient.tsx +598 -0
  164. package/app/credentials/loading.tsx +10 -0
  165. package/app/credentials/page.tsx +7 -0
  166. package/app/crons/PageClient.tsx +538 -0
  167. package/app/crons/loading.tsx +10 -0
  168. package/app/crons/page.tsx +5 -0
  169. package/app/design-system.ts +57 -0
  170. package/app/gateway/PageClient.tsx +1048 -0
  171. package/app/gateway/loading.tsx +24 -0
  172. package/app/gateway/page.tsx +5 -0
  173. package/app/globals.css +1474 -0
  174. package/app/layout.tsx +45 -0
  175. package/app/lib/models-context.tsx +41 -0
  176. package/app/lineage/loading.tsx +10 -0
  177. package/app/lineage/page.tsx +13 -0
  178. package/app/loading.tsx +16 -0
  179. package/app/login/page.tsx +160 -0
  180. package/app/memory/MemoryContextPageClient.tsx +196 -0
  181. package/app/memory/loading.tsx +10 -0
  182. package/app/memory/page.tsx +8 -0
  183. package/app/page.tsx +31 -0
  184. package/app/plugins/PageClient.tsx +296 -0
  185. package/app/plugins/loading.tsx +10 -0
  186. package/app/plugins/page.tsx +5 -0
  187. package/app/setup/PageClient.tsx +227 -0
  188. package/app/setup/loading.tsx +21 -0
  189. package/app/setup/page.tsx +7 -0
  190. package/app/skills/PageClient.tsx +499 -0
  191. package/app/skills/loading.tsx +10 -0
  192. package/app/skills/page.tsx +5 -0
  193. package/app/tools/ToolsPageClient.tsx +308 -0
  194. package/app/tools/loading.tsx +10 -0
  195. package/app/tools/page.tsx +62 -0
  196. package/app/tools/tools-catalog.ts +141 -0
  197. package/app/wizard/PageClient.tsx +485 -0
  198. package/app/wizard/icons.tsx +89 -0
  199. package/app/wizard/loading.tsx +24 -0
  200. package/app/wizard/page.tsx +7 -0
  201. package/app/wizard/storage.ts +33 -0
  202. package/app/wizard/useWizard.ts +101 -0
  203. package/app/workspace/WorkspaceClient.tsx +633 -0
  204. package/app/workspace/loading.tsx +36 -0
  205. package/app/workspace/page.tsx +8 -0
  206. package/bin/docker-entrypoint.sh +21 -0
  207. package/bin/postinstall.js +20 -0
  208. package/bin/rev4a.js +696 -0
  209. package/daemon.js +783 -0
  210. package/docs/ARCHITECTURE.md +557 -0
  211. package/docs/CONTAINER-TERMINAL.md +280 -0
  212. package/docs/DESIGN-SYSTEM.md +99 -0
  213. package/docs/FRONTEND-ARCHITECTURE.md +119 -0
  214. package/docs/REV4A.md +504 -0
  215. package/docs/dev/API-REFERENCE.md +1835 -0
  216. package/docs/dev/DATABASE.md +224 -0
  217. package/docs/dev/GATEWAY.md +300 -0
  218. package/docs/dev/PROVIDERS.md +229 -0
  219. package/docs/dev/SESSION-MAINTENANCE-PLAN.md +607 -0
  220. package/docs/dev/WORKSPACE.md +199 -0
  221. package/docs/rag/DATA-FRESHNESS.md +109 -0
  222. package/docs/rag/GLOSSARY.md +125 -0
  223. package/docs/rag/REV4A-OVERVIEW.md +135 -0
  224. package/docs/rag/WHAT-I-CAN-ANSWER.md +124 -0
  225. package/lib/agent-setup.ts +130 -0
  226. package/lib/alerts.ts +115 -0
  227. package/lib/apiFetch.ts +7 -0
  228. package/lib/auth.ts +28 -0
  229. package/lib/billing.ts +100 -0
  230. package/lib/buildAgentImage.ts +346 -0
  231. package/lib/channelManager.ts +386 -0
  232. package/lib/container.ts +60 -0
  233. package/lib/credentials/db.ts +86 -0
  234. package/lib/credentials/delivery.ts +448 -0
  235. package/lib/credentials/detect.ts +149 -0
  236. package/lib/credentials/hash.ts +9 -0
  237. package/lib/credentials/providers.ts +110 -0
  238. package/lib/credentials/vault.ts +195 -0
  239. package/lib/db-bootstrap.d.ts +3 -0
  240. package/lib/db-bootstrap.mjs +144 -0
  241. package/lib/db.ts +25 -0
  242. package/lib/docker-utils.ts +60 -0
  243. package/lib/hooks/useDashboard.ts +264 -0
  244. package/lib/hooks/useRev4aTimezone.ts +28 -0
  245. package/lib/hooks/useScreenshot.ts +30 -0
  246. package/lib/memory-context.ts +385 -0
  247. package/lib/model-catalogue.ts +131 -0
  248. package/lib/model-pricing.ts +63 -0
  249. package/lib/openclaw-cron.ts +350 -0
  250. package/lib/patterns/ApiAdapter.ts +73 -0
  251. package/lib/patterns/ApiClient.ts +65 -0
  252. package/lib/patterns/EventBus.ts +113 -0
  253. package/lib/patterns/FilterStrategy.ts +79 -0
  254. package/lib/patterns/SessionFactory.ts +117 -0
  255. package/lib/patterns/sessionPresentation.ts +117 -0
  256. package/lib/provider-balance.ts +163 -0
  257. package/lib/requireAuth.tsx +38 -0
  258. package/lib/rev4a-auth.d.ts +3 -0
  259. package/lib/rev4a-auth.js +36 -0
  260. package/lib/rev4a-paths.ts +145 -0
  261. package/lib/timezone.ts +46 -0
  262. package/lib/types/index.ts +96 -0
  263. package/lib/utils/format.ts +82 -0
  264. package/lineage.js +56 -0
  265. package/model-pricing.json +482 -0
  266. package/models.config.json +844 -0
  267. package/next-env.d.ts +6 -0
  268. package/next.config.mjs +7 -0
  269. package/package.json +82 -0
  270. package/public/apple-touch-icon.png +0 -0
  271. package/public/favicon-64.png +0 -0
  272. package/public/favicon.svg +58 -0
  273. package/public/icon-192-maskable.png +0 -0
  274. package/public/icon-192.png +0 -0
  275. package/public/icon-512-maskable.png +0 -0
  276. package/public/icon-512.png +0 -0
  277. package/public/manifest.json +38 -0
  278. package/public/rev4a-logo.png +0 -0
  279. package/public/rev4a-logo.svg +58 -0
  280. package/rev4a-rules/AGENTS.md +37 -0
  281. package/scripts/add-auth.cjs +185 -0
  282. package/scripts/backup.sh +66 -0
  283. package/scripts/check-providers.mjs +143 -0
  284. package/scripts/docker/traefik/docker-compose.yml +32 -0
  285. package/scripts/docker/traefik/dynamic/.gitkeep +18 -0
  286. package/scripts/docker/traefik/traefik.yml +37 -0
  287. package/scripts/remove-auth-profile.js +56 -0
  288. package/scripts/restore.sh +82 -0
  289. package/terminal-ws-server.js +139 -0
  290. package/tsconfig.json +42 -0
@@ -0,0 +1,94 @@
1
+ 'use client';
2
+
3
+ import { useState } from 'react';
4
+ import { useModels } from '../lib/models-context';
5
+
6
+ interface ProviderEntry {
7
+ provider: string;
8
+ emoji: string;
9
+ models: { id: string; label: string }[];
10
+ }
11
+
12
+ interface ModelPickerModalProps {
13
+ open: boolean;
14
+ value?: string;
15
+ title?: string;
16
+ onClose: () => void;
17
+ onSelect: (model: string) => void;
18
+ }
19
+
20
+ const FALLBACK_PROVIDERS: ProviderEntry[] = [
21
+ { provider: 'Default', emoji: '🔧', models: [{ id: '', label: 'Default' }] },
22
+ ];
23
+
24
+ export default function ModelPickerModal({ open, value = '', title = 'Select model', onClose, onSelect }: ModelPickerModalProps) {
25
+ const { providers: contextProviders, loaded } = useModels();
26
+ const [expanded, setExpanded] = useState<Record<number, boolean>>({ 0: true });
27
+ const providers = loaded && contextProviders.length ? contextProviders : FALLBACK_PROVIDERS;
28
+
29
+ if (!open) return null;
30
+
31
+ const current = value ? value.split('/').slice(1).join('/') || value : 'Default';
32
+
33
+ return (
34
+ <div className="model-picker" onClick={onClose}>
35
+ <div className="model-picker__panel" onClick={(e) => e.stopPropagation()}>
36
+ <div className="model-picker__header">
37
+ <div>
38
+ <div className="model-picker__title">{title}</div>
39
+ <div className="model-picker__current">Attuale: {current}</div>
40
+ </div>
41
+ <button className="model-picker__close" onClick={onClose} aria-label="Close">×</button>
42
+ </div>
43
+ <div className="model-picker__body">
44
+ {providers.map((provider, pIdx) => (
45
+ <div key={`${provider.provider}-${pIdx}`} className="model-picker__provider">
46
+ <button
47
+ className={`model-picker__provider-header${expanded[pIdx] ? ' model-picker__provider-header--expanded' : ''}`}
48
+ onClick={() => setExpanded((prev) => ({ ...prev, [pIdx]: !prev[pIdx] }))}
49
+ >
50
+ <span className="model-picker__chevron">{expanded[pIdx] ? '▾' : '▸'}</span>
51
+ <span className="model-picker__emoji">{provider.emoji}</span>
52
+ <span className="model-picker__provider-name">{provider.provider}</span>
53
+ <span className="model-picker__count">{provider.models.length}</span>
54
+ </button>
55
+ {expanded[pIdx] && (
56
+ <div className="model-picker__models">
57
+ {provider.models.map((m) => (
58
+ <button
59
+ key={m.id || '__default__'}
60
+ className={`model-picker__model${(value || '') === m.id ? ' model-picker__model--active' : ''}`}
61
+ onClick={() => onSelect(m.id)}
62
+ >
63
+ {m.label}
64
+ </button>
65
+ ))}
66
+ </div>
67
+ )}
68
+ </div>
69
+ ))}
70
+ </div>
71
+ </div>
72
+ <style jsx>{`
73
+ .model-picker { position: fixed; inset: 0; z-index: 1000; background: rgba(0,0,0,.55); display: flex; align-items: center; justify-content: center; padding: 16px; }
74
+ .model-picker__panel { width: min(520px, 100%); max-height: min(720px, 88dvh); background: var(--bg2); border: 1px solid var(--border); border-radius: 12px; box-shadow: 0 20px 80px rgba(0,0,0,.45); overflow: hidden; display: flex; flex-direction: column; }
75
+ .model-picker__header { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 14px 16px; border-bottom: 1px solid var(--border); }
76
+ .model-picker__title { color: var(--text); font-size: 14px; font-weight: 600; }
77
+ .model-picker__current { color: var(--text-dim); font-size: 10px; margin-top: 3px; }
78
+ .model-picker__close { background: none; border: 1px solid var(--border); color: var(--text-dim); border-radius: 0; width: 30px; height: 30px; cursor: pointer; font-size: 18px; line-height: 1; }
79
+ .model-picker__body { overflow: auto; padding: 8px; }
80
+ .model-picker__provider-header { width: 100%; display: flex; align-items: center; gap: 8px; padding: 9px 10px; border: 0; border-radius: 0; background: none; color: var(--text-dim); cursor: pointer; font: inherit; font-size: 12px; }
81
+ .model-picker__provider-header:hover, .model-picker__provider-header--expanded { background: var(--bg3); color: var(--text); }
82
+ .model-picker__chevron { width: 14px; }
83
+ .model-picker__emoji { width: 18px; text-align: center; }
84
+ .model-picker__provider-name { flex: 1; text-align: left; font-weight: 600; }
85
+ .model-picker__count { font-size: 10px; color: var(--text-dim); background: var(--bg); border-radius: 0; padding: 1px 6px; }
86
+ .model-picker__models { display: grid; gap: 2px; padding: 2px 0 6px 40px; }
87
+ .model-picker__model { text-align: left; border: 0; border-radius: 0; background: none; color: var(--text); cursor: pointer; padding: 7px 9px; font: inherit; font-size: 11px; }
88
+ .model-picker__model:hover { background: var(--bg3); }
89
+ .model-picker__model--active { background: rgba(146,91,252,.14); color: var(--violet); }
90
+ @media (max-width: 600px) { .model-picker { align-items: flex-end; padding: 0; } .model-picker__panel { border-radius: 0; max-height: 82dvh; } }
91
+ `}</style>
92
+ </div>
93
+ );
94
+ }
@@ -0,0 +1,86 @@
1
+ 'use client';
2
+
3
+ import { useState } from 'react';
4
+ import { Input } from './ui';
5
+ import { EyeIcon, EyeOffIcon } from './Icons';
6
+
7
+ function generateKey(): string {
8
+ const arr = new Uint8Array(24);
9
+ crypto.getRandomValues(arr);
10
+ return Array.from(arr, (b) => b.toString(16).padStart(2, '0')).join('');
11
+ }
12
+
13
+ interface PasswordInputProps {
14
+ value: string;
15
+ onChange: (value: string) => void;
16
+ placeholder?: string;
17
+ disabled?: boolean;
18
+ style?: React.CSSProperties;
19
+ showGenerate?: boolean;
20
+ }
21
+
22
+ export default function PasswordInput({
23
+ value,
24
+ onChange,
25
+ placeholder = '',
26
+ disabled = false,
27
+ style,
28
+ showGenerate = false,
29
+ }: PasswordInputProps) {
30
+ const [visible, setVisible] = useState(false);
31
+
32
+ const hasRightButton = showGenerate;
33
+ const paddingRight = hasRightButton ? 150 : 44;
34
+
35
+ return (
36
+ <div style={{ position: 'relative', ...style }}>
37
+ <Input
38
+ type={visible ? 'text' : 'password'}
39
+ placeholder={placeholder}
40
+ value={value}
41
+ onChange={(e) => onChange(e.target.value)}
42
+ disabled={disabled}
43
+ style={{ paddingRight }}
44
+ />
45
+ <div
46
+ style={{
47
+ position: 'absolute',
48
+ right: 4,
49
+ top: '50%',
50
+ transform: 'translateY(-50%)',
51
+ display: 'flex',
52
+ alignItems: 'center',
53
+ gap: 4,
54
+ }}
55
+ >
56
+ {showGenerate && (
57
+ <button
58
+ onClick={() => {
59
+ onChange(generateKey());
60
+ setVisible(true);
61
+ }}
62
+ disabled={disabled}
63
+ type="button"
64
+ tabIndex={-1}
65
+ className="ui-btn ui-btn--ghost ui-btn--sm"
66
+ title="Generate secure key"
67
+ style={{ marginRight: 2 }}
68
+ >
69
+ Generate
70
+ </button>
71
+ )}
72
+ <button
73
+ onClick={() => setVisible((v) => !v)}
74
+ disabled={disabled}
75
+ type="button"
76
+ tabIndex={-1}
77
+ className="ui-btn ui-btn--ghost ui-btn--sm"
78
+ title={visible ? 'Hide' : 'Show'}
79
+ style={{ minWidth: 32, justifyContent: 'center' }}
80
+ >
81
+ {visible ? <EyeOffIcon size={16} /> : <EyeIcon size={16} />}
82
+ </button>
83
+ </div>
84
+ </div>
85
+ );
86
+ }
@@ -0,0 +1,362 @@
1
+ 'use client';
2
+
3
+ import { useState, useRef, useEffect, useCallback } from 'react';
4
+ import { usePathname } from 'next/navigation';
5
+ import Link from 'next/link';
6
+
7
+ const STORAGE_KEY = 'rev4a_pulse_chat';
8
+ const MODEL_STORAGE_KEY = 'rev4a-pulse-model';
9
+
10
+ interface ModelOption {
11
+ id: string;
12
+ label: string;
13
+ }
14
+
15
+ interface ModelGroup {
16
+ provider: string;
17
+ emoji: string;
18
+ models: ModelOption[];
19
+ }
20
+
21
+ interface Message {
22
+ role: 'user' | 'assistant';
23
+ content: string;
24
+ }
25
+
26
+ function loadMessages(): Message[] {
27
+ try {
28
+ const raw = localStorage.getItem(STORAGE_KEY);
29
+ if (!raw) return [];
30
+ const parsed = JSON.parse(raw);
31
+ return Array.isArray(parsed) ? parsed : [];
32
+ } catch {
33
+ return [];
34
+ }
35
+ }
36
+
37
+ function saveMessages(messages: Message[]) {
38
+ try {
39
+ localStorage.setItem(STORAGE_KEY, JSON.stringify(messages));
40
+ } catch {
41
+ // storage full or unavailable — silently ignore
42
+ }
43
+ }
44
+
45
+ function renderContent(text: string) {
46
+ const parts = text.split(/(\[([^\]]+)\]\(([^)]+)\))/g);
47
+ const result: React.ReactNode[] = [];
48
+ let i = 0;
49
+ while (i < parts.length) {
50
+ const part = parts[i];
51
+ if (part?.startsWith('[') && parts[i + 2]) {
52
+ const label = parts[i + 1];
53
+ const href = parts[i + 2];
54
+ const isInternal = href?.startsWith('/');
55
+ result.push(
56
+ isInternal ? (
57
+ <Link key={i} href={href!} style={{ color: 'var(--violet)', textDecoration: 'underline' }}>
58
+ {label}
59
+ </Link>
60
+ ) : (
61
+ <a key={i} href={href} target="_blank" rel="noopener noreferrer" style={{ color: 'var(--violet)', textDecoration: 'underline' }}>
62
+ {label}
63
+ </a>
64
+ ),
65
+ );
66
+ i += 3;
67
+ } else {
68
+ if (part) result.push(<span key={i}>{part}</span>);
69
+ i += 1;
70
+ }
71
+ }
72
+ return result;
73
+ }
74
+
75
+ export default function PulseChat() {
76
+ const pathname = usePathname();
77
+ const [open, setOpen] = useState(false);
78
+ const [messages, setMessages] = useState<Message[]>(loadMessages);
79
+ const [input, setInput] = useState('');
80
+ const [streaming, setStreaming] = useState(false);
81
+ const [selectedModel, setSelectedModel] = useState<string>('');
82
+ const [modelGroups, setModelGroups] = useState<ModelGroup[]>([]);
83
+ const [modelsLoading, setModelsLoading] = useState(true);
84
+ const bottomRef = useRef<HTMLDivElement>(null);
85
+ const inputRef = useRef<HTMLTextAreaElement>(null);
86
+ const abortRef = useRef<AbortController | null>(null);
87
+
88
+ // Fetch available models from backend on mount
89
+ useEffect(() => {
90
+ let cancelled = false;
91
+
92
+ async function fetchModels() {
93
+ try {
94
+ const res = await fetch('/api/models');
95
+ if (!res.ok) throw new Error(`HTTP ${res.status}`);
96
+ const data: ModelGroup[] = await res.json();
97
+ if (cancelled) return;
98
+
99
+ setModelGroups(data);
100
+
101
+ const allIds = data.flatMap((g) => g.models.map((m) => m.id));
102
+
103
+ // Restore saved model if valid, otherwise pick first
104
+ try {
105
+ const saved = localStorage.getItem(MODEL_STORAGE_KEY);
106
+ if (saved && allIds.includes(saved)) {
107
+ setSelectedModel(saved);
108
+ } else if (allIds.length > 0) {
109
+ setSelectedModel(allIds[0]);
110
+ }
111
+ } catch {
112
+ if (allIds.length > 0) setSelectedModel(allIds[0]);
113
+ }
114
+ } catch {
115
+ // API unavailable — leave selectedModel empty, select stays disabled
116
+ } finally {
117
+ if (!cancelled) setModelsLoading(false);
118
+ }
119
+ }
120
+
121
+ fetchModels();
122
+ return () => { cancelled = true; };
123
+ }, []);
124
+
125
+ // Save model preference on change
126
+ useEffect(() => {
127
+ try {
128
+ localStorage.setItem(MODEL_STORAGE_KEY, selectedModel);
129
+ } catch {
130
+ // ignore
131
+ }
132
+ }, [selectedModel]);
133
+
134
+ useEffect(() => {
135
+ saveMessages(messages);
136
+ }, [messages]);
137
+
138
+ useEffect(() => {
139
+ if (open) {
140
+ bottomRef.current?.scrollIntoView({ behavior: 'smooth' });
141
+ inputRef.current?.focus();
142
+ }
143
+ }, [open, messages]);
144
+
145
+ const newSession = useCallback(() => {
146
+ setMessages([]);
147
+ localStorage.removeItem(STORAGE_KEY);
148
+ inputRef.current?.focus();
149
+ }, []);
150
+
151
+ const send = useCallback(async () => {
152
+ const text = input.trim();
153
+ if (!text || streaming) return;
154
+
155
+ const userMsg: Message = { role: 'user', content: text };
156
+ const history = [...messages, userMsg];
157
+ setMessages(history);
158
+ setInput('');
159
+ setStreaming(true);
160
+
161
+ const assistantMsg: Message = { role: 'assistant', content: '' };
162
+ setMessages([...history, assistantMsg]);
163
+
164
+ abortRef.current = new AbortController();
165
+
166
+ try {
167
+ const res = await fetch('/api/assistant', {
168
+ method: 'POST',
169
+ headers: { 'Content-Type': 'application/json' },
170
+ body: JSON.stringify({
171
+ message: text,
172
+ page: pathname,
173
+ model: selectedModel,
174
+ history: messages.slice(-8).map((m) => ({ role: m.role, content: m.content })),
175
+ }),
176
+ signal: abortRef.current.signal,
177
+ });
178
+
179
+ if (!res.ok) {
180
+ const err = await res.text();
181
+ setMessages((prev) => [
182
+ ...prev.slice(0, -1),
183
+ { role: 'assistant', content: `Error: ${err}` },
184
+ ]);
185
+ return;
186
+ }
187
+
188
+ const reader = res.body?.getReader();
189
+ const decoder = new TextDecoder();
190
+ let accumulated = '';
191
+
192
+ if (!reader) return;
193
+
194
+ while (true) {
195
+ const { done, value } = await reader.read();
196
+ if (done) break;
197
+
198
+ const chunk = decoder.decode(value, { stream: true });
199
+ const lines = chunk.split('\n');
200
+
201
+ for (const line of lines) {
202
+ if (!line.startsWith('data:')) continue;
203
+ const data = line.slice(5).trim();
204
+ if (data === '[DONE]') continue;
205
+ try {
206
+ const json = JSON.parse(data);
207
+ const delta = json?.choices?.[0]?.delta?.content ?? '';
208
+ if (delta) {
209
+ accumulated += delta;
210
+ setMessages((prev) => [
211
+ ...prev.slice(0, -1),
212
+ { role: 'assistant', content: accumulated },
213
+ ]);
214
+ }
215
+ } catch {
216
+ // non-JSON SSE line, skip
217
+ }
218
+ }
219
+ }
220
+ } catch (err: unknown) {
221
+ if ((err as Error)?.name !== 'AbortError') {
222
+ setMessages((prev) => [
223
+ ...prev.slice(0, -1),
224
+ { role: 'assistant', content: 'Connection error. Try again.' },
225
+ ]);
226
+ }
227
+ } finally {
228
+ setStreaming(false);
229
+ abortRef.current = null;
230
+ }
231
+ }, [input, messages, pathname, streaming]);
232
+
233
+ const onKeyDown = (e: React.KeyboardEvent<HTMLTextAreaElement>) => {
234
+ if (e.key === 'Enter' && !e.shiftKey) {
235
+ e.preventDefault();
236
+ send();
237
+ }
238
+ };
239
+
240
+ return (
241
+ <>
242
+ {/* Floating trigger button */}
243
+ <button
244
+ className="ochat__trigger"
245
+ aria-label="Pulse — Rev4a Assistant"
246
+ onClick={() => setOpen((v) => !v)}
247
+ title="Pulse — Rev4a Assistant"
248
+ >
249
+ <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round">
250
+ <path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z" />
251
+ </svg>
252
+ </button>
253
+
254
+ {/* Chat panel */}
255
+ {open && (
256
+ <div className="ochat__panel">
257
+ <div className="ochat__header">
258
+ <span className="ochat__header-title">
259
+ <svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="var(--violet)" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round" style={{ marginRight: 6 }}>
260
+ <ellipse cx="12" cy="12" rx="10" ry="6" />
261
+ <circle cx="12" cy="12" r="3" fill="var(--violet)" stroke="none" />
262
+ </svg>
263
+ PULSE
264
+ </span>
265
+ <select
266
+ value={selectedModel}
267
+ onChange={(e) => setSelectedModel(e.target.value)}
268
+ disabled={modelsLoading || modelGroups.length === 0}
269
+ style={{
270
+ border: '1px solid var(--border)',
271
+ background: 'var(--bg)',
272
+ color: 'var(--text)',
273
+ fontFamily: 'var(--font-mono-stack)',
274
+ fontSize: 11,
275
+ borderRadius: 0,
276
+ padding: '1px 4px',
277
+ cursor: modelsLoading ? 'wait' : 'pointer',
278
+ outline: 'none',
279
+ opacity: modelsLoading ? 0.5 : 1,
280
+ }}
281
+ aria-label="Select model"
282
+ >
283
+ {modelsLoading ? (
284
+ <option value="">…</option>
285
+ ) : (
286
+ modelGroups.map((group) => (
287
+ <optgroup key={group.provider} label={`${group.emoji} ${group.provider}`}>
288
+ {group.models.map((m) => (
289
+ <option key={m.id} value={m.id}>
290
+ {group.emoji} {m.label}
291
+ </option>
292
+ ))}
293
+ </optgroup>
294
+ ))
295
+ )}
296
+ </select>
297
+ <div style={{ display: 'flex', gap: 4, alignItems: 'center' }}>
298
+ {messages.length > 0 && (
299
+ <button
300
+ className="ochat__clear"
301
+ onClick={newSession}
302
+ title="New session"
303
+ aria-label="New session"
304
+ >
305
+ <svg width="11" height="11" viewBox="0 0 16 16" fill="none">
306
+ <path d="M2 8h12M8 2v12" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" />
307
+ </svg>
308
+ </button>
309
+ )}
310
+ <button className="ochat__close" onClick={() => setOpen(false)} aria-label="Close">
311
+ <svg width="12" height="12" viewBox="0 0 12 12" fill="none">
312
+ <path d="M2 2l8 8M10 2l-8 8" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" />
313
+ </svg>
314
+ </button>
315
+ </div>
316
+ </div>
317
+
318
+ <div className="ochat__messages">
319
+ {messages.length === 0 && (
320
+ <p className="ochat__empty">
321
+ Hello! I'm <strong>Pulse</strong>, the oracle of Rev4a. Ask me about the dashboard, data, or the page you're looking at.
322
+ </p>
323
+ )}
324
+ {messages.map((m, i) => (
325
+ <div key={i} className={`ochat__msg ochat__msg--${m.role}`}>
326
+ {m.role === 'assistant' ? renderContent(m.content) : m.content}
327
+ {m.role === 'assistant' && streaming && i === messages.length - 1 && (
328
+ <span className="ochat__cursor" />
329
+ )}
330
+ </div>
331
+ ))}
332
+ <div ref={bottomRef} />
333
+ </div>
334
+
335
+ <div className="ochat__footer">
336
+ <textarea
337
+ ref={inputRef}
338
+ className="ochat__input"
339
+ value={input}
340
+ onChange={(e) => setInput(e.target.value)}
341
+ onKeyDown={onKeyDown}
342
+ placeholder="Ask Pulse…"
343
+ rows={1}
344
+ disabled={streaming}
345
+ />
346
+ <button
347
+ className="ochat__send"
348
+ onClick={send}
349
+ disabled={!input.trim() || streaming}
350
+ aria-label="Send"
351
+ >
352
+ <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
353
+ <line x1="22" y1="2" x2="11" y2="13" />
354
+ <polygon points="22 2 15 22 11 13 2 9 22 2" />
355
+ </svg>
356
+ </button>
357
+ </div>
358
+ </div>
359
+ )}
360
+ </>
361
+ );
362
+ }
@@ -0,0 +1,48 @@
1
+ type Rev4aLoaderProps = {
2
+ label?: string;
3
+ fullHeight?: boolean;
4
+ compact?: boolean;
5
+ };
6
+
7
+ export default function Rev4aLoader({ label = 'LOADING', fullHeight = false, compact = false }: Rev4aLoaderProps) {
8
+ const logoSize = compact ? 42 : 64;
9
+ return (
10
+ <div
11
+ style={{
12
+ flex: 1,
13
+ minHeight: fullHeight ? '100dvh' : compact ? 120 : 220,
14
+ display: 'flex',
15
+ alignItems: 'center',
16
+ justifyContent: 'center',
17
+ padding: compact ? 12 : 20,
18
+ }}
19
+ >
20
+ <div style={{ display: 'flex', flexDirection: 'column', alignItems: 'center', gap: compact ? 10 : 14 }}>
21
+ <img
22
+ src="/rev4a-logo.svg"
23
+ alt="Rev4a loading"
24
+ width={logoSize}
25
+ height={logoSize}
26
+ style={{
27
+ objectFit: 'contain',
28
+ display: 'block',
29
+ animation: 'rev4a-loader-pulse 1.35s ease-in-out infinite',
30
+ filter: 'drop-shadow(0 0 16px rgba(146,91,252,0.22))',
31
+ }}
32
+ />
33
+ <div style={{ fontFamily: 'var(--font-serif-stack, serif)', fontSize: compact ? 16 : 22, letterSpacing: compact ? 3 : 4, color: 'var(--violet)' }}>
34
+ REV4A
35
+ </div>
36
+ <div style={{ fontSize: compact ? 10 : 11, letterSpacing: '0.12em', color: 'var(--text-dim)' }}>
37
+ {label}
38
+ </div>
39
+ </div>
40
+ <style>{`
41
+ @keyframes rev4a-loader-pulse {
42
+ 0%, 100% { transform: scale(0.96); opacity: 0.72; }
43
+ 50% { transform: scale(1); opacity: 1; }
44
+ }
45
+ `}</style>
46
+ </div>
47
+ );
48
+ }