@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,313 @@
1
+ 'use client';
2
+
3
+ import { useEffect, useRef, useState, useMemo } from 'react';
4
+
5
+ const RECONNECT_DELAY = 2000;
6
+
7
+ // ── ANSI Color Map ──────────────────────────────────────────────
8
+ const ANSI_FG: Record<number, string> = {
9
+ 30: '#1d1d1d', 31: '#e06c75', 32: '#98c379', 33: '#d19a66',
10
+ 34: '#61afef', 35: '#c678dd', 36: '#56b6c2', 37: '#abb2bf',
11
+ 90: '#5c6370', 91: '#e06c75', 92: '#98c379', 93: '#d19a66',
12
+ 94: '#61afef', 95: '#c678dd', 96: '#56b6c2', 97: '#ffffff',
13
+ };
14
+ const ANSI_BG: Record<number, string> = {
15
+ 40: '#1d1d1d', 41: '#e06c75', 42: '#98c379', 43: '#d19a66',
16
+ 44: '#61afef', 45: '#c678dd', 46: '#56b6c2', 47: '#abb2bf',
17
+ 100: '#5c6370', 101: '#e06c75', 102: '#98c379', 103: '#d19a66',
18
+ 104: '#61afef', 105: '#c678dd', 106: '#56b6c2', 107: '#ffffff',
19
+ };
20
+
21
+ type AnsiStyle = { fg?: string; bg?: string; bold?: boolean; dim?: boolean; italic?: boolean; underline?: boolean };
22
+ type Segment = { text: string; style: AnsiStyle };
23
+
24
+ // ── ANSI Parser ─────────────────────────────────────────────────
25
+ // Parses text with ANSI escape sequences into {text, style} segments.
26
+ // Handles: SGR (Select Graphic Rendition) — colors, bold, dim, italic, underline, reset.
27
+ // Strips: bracketed paste, OSC, non-SGR sequences, bell, CR.
28
+ function parseAnsi(text: string): Segment[] {
29
+ const segments: Segment[] = [];
30
+ const current: AnsiStyle = {};
31
+ let i = 0;
32
+
33
+ while (i < text.length) {
34
+ // Check for ESC
35
+ if (text[i] === '\x1b' && i + 1 < text.length) {
36
+ if (text[i + 1] === '[') {
37
+ // CSI sequence: \x1b[ ... <final byte>
38
+ const start = i + 2;
39
+ const end = text.indexOf('m', start); // SGR ends with 'm'
40
+ if (end !== -1) {
41
+ const params = text.slice(start, end).split(';');
42
+ for (const p of params) {
43
+ const code = parseInt(p, 10);
44
+ if (isNaN(code)) continue;
45
+ if (code === 0) {
46
+ // Reset all
47
+ Object.keys(current).forEach(k => delete (current as any)[k]);
48
+ } else if (code === 1) current.bold = true;
49
+ else if (code === 2) current.dim = true;
50
+ else if (code === 3) current.italic = true;
51
+ else if (code === 4) current.underline = true;
52
+ else if (code === 22) { current.bold = false; current.dim = false; }
53
+ else if (code === 23) current.italic = false;
54
+ else if (code === 24) current.underline = false;
55
+ else if (code >= 30 && code <= 37) { current.fg = ANSI_FG[code]; }
56
+ else if (code >= 90 && code <= 97) { current.fg = ANSI_FG[code]; }
57
+ else if (code === 39) delete current.fg;
58
+ else if (code >= 40 && code <= 47) { current.bg = ANSI_BG[code]; }
59
+ else if (code >= 100 && code <= 107) { current.bg = ANSI_BG[code]; }
60
+ else if (code === 49) delete current.bg;
61
+ }
62
+ i = end + 1;
63
+ continue;
64
+ }
65
+ // CSI not ending with 'm' — strip whole sequence
66
+ const endByte = text.slice(i + 2).search(/[@-~]/);
67
+ if (endByte !== -1) {
68
+ i += 2 + endByte + 1;
69
+ continue;
70
+ }
71
+ } else if (text[i + 1] === ']') {
72
+ // OSC sequence: strip until ST (\x1b\\ or \x07)
73
+ const st = text.indexOf('\x1b\\', i);
74
+ const bell = text.indexOf('\x07', i);
75
+ const endPos = st !== -1 ? st + 2 : (bell !== -1 ? bell + 1 : -1);
76
+ if (endPos !== -1) { i = endPos; continue; }
77
+ } else {
78
+ // Any other ESC sequence: strip 2 chars
79
+ i += 2;
80
+ continue;
81
+ }
82
+ }
83
+
84
+ // Bell
85
+ if (text[i] === '\x07') { i++; continue; }
86
+ // CR
87
+ if (text[i] === '\r') { i++; continue; }
88
+
89
+ // Collect visible characters until next ESC or EOL
90
+ let j = i;
91
+ while (j < text.length && text[j] !== '\x1b' && text[j] !== '\x07' && text[j] !== '\r') {
92
+ j++;
93
+ }
94
+ if (j > i) {
95
+ segments.push({ text: text.slice(i, j), style: { ...current } });
96
+ }
97
+ i = j;
98
+ }
99
+
100
+ return segments;
101
+ }
102
+
103
+ // ── Segment to inline style ─────────────────────────────────────
104
+ function segmentStyle(s: AnsiStyle): React.CSSProperties {
105
+ const style: React.CSSProperties = {};
106
+ if (s.fg) style.color = s.fg;
107
+ if (s.bg) style.backgroundColor = s.bg;
108
+ if (s.bold) style.fontWeight = 700;
109
+ if (s.dim) style.opacity = 0.6;
110
+ if (s.italic) style.fontStyle = 'italic';
111
+ if (s.underline) style.textDecoration = 'underline';
112
+ return style;
113
+ }
114
+
115
+ // ── Render text as segments (cached via useMemo) ────────────────
116
+ function RenderAnsi({ text }: { text: string }) {
117
+ const segments = useMemo(() => parseAnsi(text), [text]);
118
+ return (
119
+ <>
120
+ {segments.map((seg, i) => (
121
+ <span key={i} style={segmentStyle(seg.style)}>{seg.text}</span>
122
+ ))}
123
+ </>
124
+ );
125
+ }
126
+
127
+ // ── Terminal Client Component ───────────────────────────────────
128
+ export default function TerminalClient({ containerId }: { containerId: string }) {
129
+ const outputRef = useRef<HTMLDivElement>(null);
130
+ const inputRef = useRef<HTMLTextAreaElement>(null);
131
+ const wsRef = useRef<WebSocket | null>(null);
132
+ const cmdHistoryRef = useRef<string[]>([]);
133
+ const histIdxRef = useRef(-1);
134
+ const cmdBufferRef = useRef('');
135
+ const pendingCmdRef = useRef('');
136
+ const [status, setStatus] = useState('Connecting...');
137
+ const [buffer, setBuffer] = useState(''); // raw PTY output (kept for segment rendering)
138
+ const [currentInput, setCurrentInput] = useState('');
139
+
140
+ function appendOutput(raw: string) {
141
+ if (!raw) return;
142
+ pendingCmdRef.current = '';
143
+ setBuffer(prev => {
144
+ const next = prev + raw;
145
+ return next.length > 200000 ? next.slice(-200000) : next;
146
+ });
147
+ }
148
+
149
+ useEffect(() => {
150
+ if (outputRef.current) {
151
+ outputRef.current.scrollTop = outputRef.current.scrollHeight;
152
+ }
153
+ }, [buffer]);
154
+
155
+ function sendCommand(cmd: string) {
156
+ if (!cmd.trim() && !cmd) return;
157
+ cmdHistoryRef.current.push(cmd);
158
+ histIdxRef.current = cmdHistoryRef.current.length;
159
+ cmdBufferRef.current = '';
160
+ pendingCmdRef.current = cmd;
161
+ if (wsRef.current?.readyState === WebSocket.OPEN) {
162
+ wsRef.current.send(cmd + '\n');
163
+ }
164
+ }
165
+
166
+ function handleKeyDown(e: React.KeyboardEvent<HTMLTextAreaElement>) {
167
+ const val = e.currentTarget.value;
168
+ if (e.key === 'Enter' && !e.shiftKey) {
169
+ e.preventDefault();
170
+ setCurrentInput('');
171
+ sendCommand(val);
172
+ } else if (e.key === 'ArrowUp') { e.preventDefault();
173
+ if (!cmdHistoryRef.current.length) return;
174
+ if (histIdxRef.current === cmdHistoryRef.current.length) cmdBufferRef.current = val;
175
+ histIdxRef.current = Math.max(0, histIdxRef.current - 1);
176
+ setCurrentInput(cmdHistoryRef.current[histIdxRef.current]);
177
+ } else if (e.key === 'ArrowDown') { e.preventDefault();
178
+ if (histIdxRef.current >= cmdHistoryRef.current.length - 1) {
179
+ histIdxRef.current = cmdHistoryRef.current.length;
180
+ setCurrentInput(cmdBufferRef.current);
181
+ } else { histIdxRef.current++; setCurrentInput(cmdHistoryRef.current[histIdxRef.current]); }
182
+ } else if (e.key === 'Tab') { e.preventDefault();
183
+ if (wsRef.current?.readyState === WebSocket.OPEN) wsRef.current.send('\t');
184
+ } else if (e.key === 'c' && e.ctrlKey) { e.preventDefault();
185
+ setCurrentInput('');
186
+ if (wsRef.current?.readyState === WebSocket.OPEN) wsRef.current.send('\x03');
187
+ } else if (e.key === 'l' && e.ctrlKey) { e.preventDefault();
188
+ setBuffer(''); setCurrentInput('');
189
+ } else if (e.key === 'd' && e.ctrlKey) { e.preventDefault();
190
+ if (wsRef.current?.readyState === WebSocket.OPEN) wsRef.current.send('\x04');
191
+ } else if (e.key === 'u' && e.ctrlKey) { e.preventDefault(); setCurrentInput(''); }
192
+ }
193
+
194
+ function handlePaste(e: React.ClipboardEvent) {
195
+ const pasted = e.clipboardData.getData('text');
196
+ if (pasted.includes('\n')) {
197
+ e.preventDefault();
198
+ for (const line of pasted.trim().split('\n')) if (line.trim()) sendCommand(line.trim());
199
+ }
200
+ }
201
+
202
+ useEffect(() => {
203
+ let mounted = true;
204
+ let reconnectTimer: ReturnType<typeof setTimeout> | null = null;
205
+
206
+ function connect() {
207
+ if (!mounted) return;
208
+ setStatus('Connecting...');
209
+ const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
210
+ const ws = new WebSocket(
211
+ `${protocol}//${window.location.host}/api/terminal-ws?id=${encodeURIComponent(containerId)}`
212
+ );
213
+ ws.onopen = () => {
214
+ if (!mounted) { ws.close(); return; }
215
+ setStatus('Connected'); inputRef.current?.focus();
216
+ appendOutput(`[Connected] ${containerId}\n`);
217
+ };
218
+ ws.onmessage = (event) => {
219
+ if (!mounted) return;
220
+ const text = typeof event.data === 'string' ? event.data : new TextDecoder().decode(new Uint8Array(event.data));
221
+ appendOutput(text);
222
+ };
223
+ ws.onclose = () => {
224
+ if (!mounted) return;
225
+ setStatus('Disconnected');
226
+ appendOutput('\n[Disconnected]\n');
227
+ reconnectTimer = setTimeout(() => { if (mounted) connect(); }, RECONNECT_DELAY);
228
+ };
229
+ wsRef.current = ws;
230
+ }
231
+ connect();
232
+ setTimeout(() => inputRef.current?.focus(), 300);
233
+ return () => {
234
+ mounted = false;
235
+ if (reconnectTimer) clearTimeout(reconnectTimer);
236
+ if (wsRef.current) { wsRef.current.close(); wsRef.current = null; }
237
+ };
238
+ }, [containerId]);
239
+
240
+ function handleOutputClick() { inputRef.current?.focus(); }
241
+
242
+ const lines = useMemo(() => buffer.split('\n'), [buffer]);
243
+ const lastLine = lines[lines.length - 1] || '';
244
+ const showInput = pendingCmdRef.current ? pendingCmdRef.current : currentInput;
245
+
246
+ return (
247
+ <div style={{
248
+ position: 'fixed', top: 0, left: 0,
249
+ width: '100vw', height: '100dvh',
250
+ background: '#0a0a0b', display: 'flex', flexDirection: 'column',
251
+ zIndex: 9999,
252
+ fontFamily: 'Menlo, Monaco, "Courier New", monospace',
253
+ fontSize: 13, lineHeight: 1.5, color: '#e0e0e0',
254
+ }}>
255
+ {/* Top bar */}
256
+ <div style={{
257
+ height: 44, minHeight: 44, background: '#141416',
258
+ borderBottom: '1px solid #222',
259
+ display: 'flex', alignItems: 'center', justifyContent: 'space-between',
260
+ padding: '0 16px', color: '#888', fontSize: 12, flexShrink: 0,
261
+ }}>
262
+ <div style={{ display: 'flex', alignItems: 'center', gap: 12 }}>
263
+ <span style={{ color: '#925BFC', letterSpacing: '4px', fontSize: 14, fontFamily: 'Instrument Serif, serif' }}>TERMINAL</span>
264
+ <span style={{ color: status === 'Connected' ? '#22c55e' : '#ef4444' }}>●</span>
265
+ <span style={{ color: '#ccc' }}>{containerId}</span>
266
+ <span style={{ color: '#555', fontSize: 11 }}>{status}</span>
267
+ </div>
268
+ <a href="/containers" style={{
269
+ color: '#888', textDecoration: 'none', border: '1px solid #333',
270
+ borderRadius: 4, padding: '3px 10px', fontSize: 11, cursor: 'pointer',
271
+ }}>CLOSE</a>
272
+ </div>
273
+
274
+ {/* Scrollable output area */}
275
+ <div ref={outputRef} onClick={handleOutputClick} style={{
276
+ flex: 1, overflow: 'auto', padding: '8px 12px 0',
277
+ whiteSpace: 'pre-wrap', wordBreak: 'break-all',
278
+ cursor: 'text', userSelect: 'text', WebkitUserSelect: 'text',
279
+ }}>
280
+ {lines.length > 1 && (
281
+ <div>
282
+ {lines.slice(0, -1).map((line, i) => (
283
+ <div key={i} style={{ minHeight: '1.5em', whiteSpace: 'pre-wrap', wordBreak: 'break-all' }}>
284
+ <RenderAnsi text={line} />
285
+ </div>
286
+ ))}
287
+ </div>
288
+ )}
289
+ {/* Last line + cursor inline */}
290
+ <div style={{ display: 'flex', minHeight: '1.5em' }}>
291
+ <span style={{ whiteSpace: 'pre-wrap', wordBreak: 'break-all' }}>
292
+ <RenderAnsi text={lastLine} />
293
+ {showInput}
294
+ <span style={{
295
+ display: 'inline-block', width: 8, height: '1.1em',
296
+ background: '#e0e0e0',
297
+ animation: 'blink 1s step-end infinite',
298
+ verticalAlign: 'text-bottom', marginLeft: 1,
299
+ }} />
300
+ </span>
301
+ </div>
302
+ </div>
303
+
304
+ {/* Hidden textarea */}
305
+ <textarea ref={inputRef} value={currentInput}
306
+ onChange={e => setCurrentInput(e.target.value)}
307
+ onKeyDown={handleKeyDown} onPaste={handlePaste}
308
+ autoComplete="off" autoCorrect="off" autoCapitalize="off" spellCheck={false}
309
+ style={{ position: 'fixed', top: '-9999px', left: '-9999px', width: 1, height: 1, opacity: 0 }}
310
+ />
311
+ </div>
312
+ );
313
+ }
@@ -0,0 +1,6 @@
1
+ import TerminalClient from './TerminalClient';
2
+
3
+ export default async function TerminalPage({ params }: { params: Promise<{ id: string }> }) {
4
+ const { id } = await params;
5
+ return <TerminalClient containerId={id} />;
6
+ }