@flame0510/project-aether 1.5.0 → 1.5.2
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/app/agents/ChannelManager.tsx +17 -5
- package/app/agents/PageClient.tsx +13 -3
- package/app/api/agents/download-image/route.ts +8 -0
- package/app/api/update-check/route.ts +26 -15
- package/app/components/VersionBanner.tsx +77 -12
- package/bin/rev4a.js +6 -3
- package/daemon.js +3 -3
- package/docs/ARCHITECTURE.md +25 -3
- package/docs/FRONTEND-ARCHITECTURE.md +3 -2
- package/docs/REV4A.md +17 -0
- package/docs/dev/API-REFERENCE.md +21 -4
- package/docs/rag/REV4A-OVERVIEW.md +7 -1
- package/docs/rag/WHAT-I-CAN-ANSWER.md +2 -1
- package/instrumentation.ts +11 -0
- package/lib/agent-edit-state.ts +25 -66
- package/lib/agent-job-state.ts +145 -0
- package/lib/agent-jobs-maintenance.ts +34 -0
- package/lib/agent-recreate-state.ts +24 -65
- package/lib/agent-restore-state.ts +25 -66
- package/lib/agent-restore.ts +28 -5
- package/lib/agent-update-state.ts +25 -61
- package/lib/channelManager.ts +12 -1
- package/model-pricing.json +258 -22
- package/models.config.json +424 -6
- package/package.json +1 -1
- package/scripts/refresh-model-pricing.mjs +5 -5
|
@@ -52,6 +52,7 @@ export default function ChannelManager({ agentId, displayName, open, onClose }:
|
|
|
52
52
|
|
|
53
53
|
const [pending, setPending] = useState<PendingPairing[]>([]);
|
|
54
54
|
const [approved, setApproved] = useState<ApprovedPairing[]>([]);
|
|
55
|
+
const [pairingError, setPairingError] = useState<string | null>(null);
|
|
55
56
|
const pollRef = useRef<ReturnType<typeof setTimeout> | null>(null);
|
|
56
57
|
const pairingsAbortRef = useRef<AbortController | null>(null);
|
|
57
58
|
const channelsAbortRef = useRef<AbortController | null>(null);
|
|
@@ -85,6 +86,7 @@ export default function ChannelManager({ agentId, displayName, open, onClose }:
|
|
|
85
86
|
const data = await res.json();
|
|
86
87
|
setPending(data.pending ?? []);
|
|
87
88
|
setApproved(data.approved ?? []);
|
|
89
|
+
setPairingError(data.error ?? null);
|
|
88
90
|
}
|
|
89
91
|
} catch (e: any) {
|
|
90
92
|
if (e?.name !== 'AbortError') { /* ignore aborted */ }
|
|
@@ -288,6 +290,7 @@ export default function ChannelManager({ agentId, displayName, open, onClose }:
|
|
|
288
290
|
restarting={restarting}
|
|
289
291
|
pending={pending}
|
|
290
292
|
approved={approved}
|
|
293
|
+
pairingError={pairingError}
|
|
291
294
|
approvingCode={approvingCode}
|
|
292
295
|
revokingId={revokingId}
|
|
293
296
|
onConnect={handleTelegramConnect}
|
|
@@ -305,7 +308,7 @@ export default function ChannelManager({ agentId, displayName, open, onClose }:
|
|
|
305
308
|
|
|
306
309
|
function TelegramTab({
|
|
307
310
|
tg, tgToken, setTgToken, loading, disconnecting, pairingsLoading, restarting,
|
|
308
|
-
pending, approved, approvingCode, revokingId,
|
|
311
|
+
pending, approved, pairingError, approvingCode, revokingId,
|
|
309
312
|
onConnect, onDisconnect, onRestart, onApprove, onRevoke,
|
|
310
313
|
}: {
|
|
311
314
|
tg: TelegramChannel | null;
|
|
@@ -317,6 +320,7 @@ function TelegramTab({
|
|
|
317
320
|
restarting: boolean;
|
|
318
321
|
pending: PendingPairing[];
|
|
319
322
|
approved: ApprovedPairing[];
|
|
323
|
+
pairingError: string | null;
|
|
320
324
|
approvingCode: string | null;
|
|
321
325
|
revokingId: string | null;
|
|
322
326
|
onConnect: () => void;
|
|
@@ -343,6 +347,7 @@ function TelegramTab({
|
|
|
343
347
|
<PairingSection
|
|
344
348
|
pending={pending}
|
|
345
349
|
approved={approved}
|
|
350
|
+
pairingError={pairingError}
|
|
346
351
|
pairingsLoading={pairingsLoading}
|
|
347
352
|
approvingCode={approvingCode}
|
|
348
353
|
revokingId={revokingId}
|
|
@@ -389,11 +394,12 @@ function TelegramTab({
|
|
|
389
394
|
// ── Pairing Section ──────────────────────────
|
|
390
395
|
|
|
391
396
|
function PairingSection({
|
|
392
|
-
pending, approved, pairingsLoading, approvingCode, revokingId,
|
|
397
|
+
pending, approved, pairingError, pairingsLoading, approvingCode, revokingId,
|
|
393
398
|
onApprove, onRevoke,
|
|
394
399
|
}: {
|
|
395
400
|
pending: PendingPairing[];
|
|
396
401
|
approved: ApprovedPairing[];
|
|
402
|
+
pairingError: string | null;
|
|
397
403
|
pairingsLoading: boolean;
|
|
398
404
|
approvingCode: string | null;
|
|
399
405
|
revokingId: string | null;
|
|
@@ -462,9 +468,15 @@ function PairingSection({
|
|
|
462
468
|
)}
|
|
463
469
|
|
|
464
470
|
{approved.length === 0 && (
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
471
|
+
pairingError ? (
|
|
472
|
+
<div style={{ fontSize: 10, color: 'var(--red, #ef4444)' }}>
|
|
473
|
+
{pairingError}
|
|
474
|
+
</div>
|
|
475
|
+
) : (
|
|
476
|
+
<div style={{ fontSize: 10, color: 'var(--text-dim)' }}>
|
|
477
|
+
No approved senders
|
|
478
|
+
</div>
|
|
479
|
+
)
|
|
468
480
|
)}
|
|
469
481
|
</>
|
|
470
482
|
)}
|
|
@@ -343,9 +343,19 @@ export default function AgentsPageClient() {
|
|
|
343
343
|
const res = await fetch('/api/agents/devices-summary');
|
|
344
344
|
if (!res.ok || seq !== dvSummarySeq.current) return;
|
|
345
345
|
const payload = await res.json();
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
setDvSummary(
|
|
346
|
+
// A row whose read failed carries `error: true` and no count: keep the previous
|
|
347
|
+
// value instead of writing zero, which would hide a request that is really waiting.
|
|
348
|
+
setDvSummary((prev) => {
|
|
349
|
+
const next: Record<string, { pending: number }> = {};
|
|
350
|
+
for (const row of payload.agents ?? []) {
|
|
351
|
+
if (row.error === true) {
|
|
352
|
+
if (prev[row.agentId]) next[row.agentId] = prev[row.agentId];
|
|
353
|
+
continue;
|
|
354
|
+
}
|
|
355
|
+
next[row.agentId] = { pending: row.pending ?? 0 };
|
|
356
|
+
}
|
|
357
|
+
return next;
|
|
358
|
+
});
|
|
349
359
|
} catch { /* badges are optional */ }
|
|
350
360
|
}, []);
|
|
351
361
|
|
|
@@ -32,6 +32,14 @@ export async function POST(request: NextRequest): Promise<NextResponse> {
|
|
|
32
32
|
}
|
|
33
33
|
const version = (body?.version as string | undefined) ?? (await defaultDownloadVersion());
|
|
34
34
|
|
|
35
|
+
// Checked again here, next to the start: the first check and this one are separated by
|
|
36
|
+
// awaits, so two requests can pass it together. The loser of the race is refused inside
|
|
37
|
+
// downloadAgentImage, and that rejection would be swallowed by the catch below — the
|
|
38
|
+
// route would answer 202 for a download it never started.
|
|
39
|
+
if (getIsDownloading()) {
|
|
40
|
+
return NextResponse.json({ error: 'A download is already in progress' }, { status: 409 });
|
|
41
|
+
}
|
|
42
|
+
|
|
35
43
|
// Start download in background — fire and forget
|
|
36
44
|
downloadAgentImage({ version }).catch((e: unknown) => {
|
|
37
45
|
console.error(`[download-image] OpenClaw ${version}:`, (e as Error).message);
|
|
@@ -68,45 +68,56 @@ export async function GET(request: Request): Promise<NextResponse> {
|
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
-
return NextResponse.json({ installed, latest, updateAvailable, package: getPackageInfo().name });
|
|
71
|
+
return NextResponse.json({ installed, latest, updateAvailable, package: getPackageInfo().name, log: 'update.log' });
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
/**
|
|
75
75
|
* POST /api/update-check
|
|
76
76
|
*
|
|
77
|
-
* Spawns rev4a update as a detached background process
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
77
|
+
* Spawns `rev4a update` as a detached background process: it installs the latest
|
|
78
|
+
* version, writes `.restart-flag` and lets `rev4a serve` restart the child (`rev4a
|
|
79
|
+
* _run`) with the new binary. Nothing here has to restart anything — the update kills
|
|
80
|
+
* this very process on its way in (`fuser -k <port>/tcp`), so any callback meant to run
|
|
81
|
+
* after it is dead code; the CLI's own flag is the only mechanism that has to work.
|
|
82
|
+
*
|
|
83
|
+
* The child's output goes to `update.log` in the data directory: since the update
|
|
84
|
+
* restarts this process mid-run, that file is the only record of what happened.
|
|
81
85
|
*/
|
|
82
86
|
export async function POST(request: Request): Promise<NextResponse> {
|
|
83
87
|
const denied = await requireAuthJWT(request);
|
|
84
88
|
if (denied) return denied;
|
|
85
89
|
|
|
86
|
-
// Spawn rev4a update in background, then write restart flag directly
|
|
87
|
-
// from this process so rev4a serve detects it and restarts.
|
|
88
90
|
const { spawn } = require('child_process');
|
|
89
91
|
const { join } = require('path');
|
|
90
|
-
const {
|
|
92
|
+
const { openSync, closeSync, appendFileSync } = require('fs');
|
|
91
93
|
|
|
92
94
|
const dataDir = process.env.REV4A_DATA_DIR ||
|
|
93
95
|
join(process.env.HOME || '/root', '.config', 'rev4a', 'data');
|
|
96
|
+
const logPath = join(dataDir, 'update.log');
|
|
97
|
+
|
|
98
|
+
let log: number | null = null;
|
|
99
|
+
try {
|
|
100
|
+
log = openSync(logPath, 'a');
|
|
101
|
+
appendFileSync(logPath, `\n[${new Date().toISOString()}] rev4a update, started from the dashboard\n`);
|
|
102
|
+
} catch {
|
|
103
|
+
// Unwritable log: run the update anyway, we just lose the record.
|
|
104
|
+
}
|
|
94
105
|
|
|
95
106
|
const child = spawn('rev4a', ['update'], {
|
|
96
|
-
stdio: 'ignore',
|
|
107
|
+
stdio: log === null ? 'ignore' : ['ignore', log, log],
|
|
97
108
|
detached: true,
|
|
109
|
+
cwd: dataDir,
|
|
98
110
|
});
|
|
111
|
+
if (log !== null) closeSync(log);
|
|
99
112
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
child.on('exit', () => {
|
|
103
|
-
try { writeFileSync(join(dataDir, '.restart-flag'), ''); } catch {}
|
|
113
|
+
child.on('error', (e: Error) => {
|
|
114
|
+
try { appendFileSync(logPath, `[dashboard] could not start the update: ${e.message}\n`); } catch {}
|
|
104
115
|
});
|
|
105
|
-
|
|
106
116
|
child.unref();
|
|
107
117
|
|
|
108
118
|
return NextResponse.json({
|
|
109
119
|
success: true,
|
|
110
|
-
message: 'Update started.
|
|
120
|
+
message: 'Update started. Rev4a restarts itself once the new version is installed.',
|
|
121
|
+
log: 'update.log',
|
|
111
122
|
});
|
|
112
123
|
}
|
|
@@ -1,14 +1,42 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* "Update available" banner for Rev4a itself.
|
|
5
|
+
*
|
|
6
|
+
* The update is spawned by `POST /api/update-check` and restarts the server, so this
|
|
7
|
+
* component cannot be told the outcome by the response. It records what it asked for,
|
|
8
|
+
* waits for the server to answer again, and on the next mount compares: if the
|
|
9
|
+
* installed version moved it was updated, and if the same update is still offered it
|
|
10
|
+
* did not complete (the log file says why).
|
|
11
|
+
*/
|
|
3
12
|
import { useEffect, useState } from 'react';
|
|
4
13
|
|
|
5
14
|
interface VersionInfo {
|
|
6
15
|
installed: string;
|
|
7
16
|
latest: string | null;
|
|
8
17
|
updateAvailable: boolean;
|
|
18
|
+
log?: string;
|
|
9
19
|
}
|
|
10
20
|
|
|
11
21
|
const DISMISS_KEY = 'rev4a-update-dismissed';
|
|
22
|
+
/** What we asked for and from which version, so the next mount can judge the outcome. */
|
|
23
|
+
const PENDING_KEY = 'rev4a-update-pending';
|
|
24
|
+
|
|
25
|
+
/** How long to poll for the restart before reloading anyway. */
|
|
26
|
+
const WAIT_MS = 120_000;
|
|
27
|
+
|
|
28
|
+
interface Pending { target: string; from: string }
|
|
29
|
+
|
|
30
|
+
function readPending(): Pending | null {
|
|
31
|
+
try {
|
|
32
|
+
const raw = sessionStorage.getItem(PENDING_KEY);
|
|
33
|
+
if (!raw) return null;
|
|
34
|
+
const parsed = JSON.parse(raw) as Pending;
|
|
35
|
+
return parsed && typeof parsed.target === 'string' && typeof parsed.from === 'string' ? parsed : null;
|
|
36
|
+
} catch {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
12
40
|
|
|
13
41
|
export default function VersionBanner() {
|
|
14
42
|
const [info, setInfo] = useState<VersionInfo | null>(null);
|
|
@@ -18,17 +46,37 @@ export default function VersionBanner() {
|
|
|
18
46
|
const [updateOk, setUpdateOk] = useState<string | null>(null);
|
|
19
47
|
|
|
20
48
|
useEffect(() => {
|
|
49
|
+
let active = true;
|
|
21
50
|
fetch('/api/update-check?check=1')
|
|
22
51
|
.then((r) => r.json())
|
|
23
52
|
.then((d: VersionInfo) => {
|
|
53
|
+
if (!active) return;
|
|
54
|
+
const pending = readPending();
|
|
55
|
+
// Back from an update: did the installed version actually move?
|
|
56
|
+
if (pending && d.installed !== pending.from) {
|
|
57
|
+
sessionStorage.removeItem(PENDING_KEY);
|
|
58
|
+
setUpdateOk(`Updated to v${d.installed}`);
|
|
59
|
+
setTimeout(() => { if (active) window.location.reload(); }, 2000);
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
if (pending) {
|
|
63
|
+
sessionStorage.removeItem(PENDING_KEY);
|
|
64
|
+
setInfo(d);
|
|
65
|
+
setDismissed(false);
|
|
66
|
+
setUpdateError(
|
|
67
|
+
`The update to v${pending.target} did not complete: Rev4a is still on v${d.installed}.`
|
|
68
|
+
+ ` See ${d.log ?? 'update.log'} in the Rev4a data directory.`,
|
|
69
|
+
);
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
24
72
|
if (d.updateAvailable) {
|
|
25
73
|
setInfo(d);
|
|
26
74
|
const saved = localStorage.getItem(DISMISS_KEY);
|
|
27
|
-
|
|
28
|
-
else setDismissed(false);
|
|
75
|
+
setDismissed(saved === d.latest);
|
|
29
76
|
}
|
|
30
77
|
})
|
|
31
78
|
.catch(() => {});
|
|
79
|
+
return () => { active = false; };
|
|
32
80
|
}, []);
|
|
33
81
|
|
|
34
82
|
function handleDismiss() {
|
|
@@ -39,6 +87,7 @@ export default function VersionBanner() {
|
|
|
39
87
|
}
|
|
40
88
|
|
|
41
89
|
async function handleUpdate() {
|
|
90
|
+
if (!info) return;
|
|
42
91
|
setUpdating(true);
|
|
43
92
|
setUpdateError(null);
|
|
44
93
|
setUpdateOk(null);
|
|
@@ -49,21 +98,37 @@ export default function VersionBanner() {
|
|
|
49
98
|
headers: { 'Content-Type': 'application/json' },
|
|
50
99
|
});
|
|
51
100
|
const data = await res.json();
|
|
52
|
-
if (data.success) {
|
|
53
|
-
setUpdateOk('Update started. Restarting\u2026');
|
|
54
|
-
localStorage.removeItem(DISMISS_KEY);
|
|
55
|
-
setTimeout(function() { window.location.reload(); }, 5000);
|
|
56
|
-
} else {
|
|
101
|
+
if (!data.success) {
|
|
57
102
|
setUpdateError(data.error || 'Update failed');
|
|
58
103
|
setUpdating(false);
|
|
104
|
+
return;
|
|
59
105
|
}
|
|
106
|
+
sessionStorage.setItem(PENDING_KEY, JSON.stringify({ target: info.latest ?? '', from: info.installed }));
|
|
107
|
+
localStorage.removeItem(DISMISS_KEY);
|
|
108
|
+
setUpdateOk('Update started. Rev4a is restarting…');
|
|
109
|
+
// The server goes down and comes back on the new version: wait for its answer,
|
|
110
|
+
// then reload. A timeout reloads too — the next mount reports the outcome.
|
|
111
|
+
const deadline = Date.now() + WAIT_MS;
|
|
112
|
+
const poll = async () => {
|
|
113
|
+
if (Date.now() > deadline) { window.location.reload(); return; }
|
|
114
|
+
try {
|
|
115
|
+
const r = await fetch('/api/update-check', { cache: 'no-store' });
|
|
116
|
+
const d = (await r.json()) as VersionInfo;
|
|
117
|
+
if (d.installed !== info.installed) { window.location.reload(); return; }
|
|
118
|
+
} catch { /* the server is down for the update: expected */ }
|
|
119
|
+
setTimeout(poll, 3000);
|
|
120
|
+
};
|
|
121
|
+
setTimeout(poll, 3000);
|
|
60
122
|
} catch (err) {
|
|
61
123
|
setUpdateError(err instanceof Error ? err.message : 'Network error');
|
|
62
124
|
setUpdating(false);
|
|
63
125
|
}
|
|
64
126
|
}
|
|
65
127
|
|
|
66
|
-
|
|
128
|
+
// The result states stand on their own (there may be no `info` when the update just
|
|
129
|
+
// succeeded); the "available" state needs the version info and no dismissal.
|
|
130
|
+
const show = Boolean(updateOk) || Boolean(updateError) || Boolean(info?.updateAvailable && !dismissed);
|
|
131
|
+
if (!show) return null;
|
|
67
132
|
|
|
68
133
|
return (
|
|
69
134
|
<div className="update-banner">
|
|
@@ -73,25 +138,25 @@ export default function VersionBanner() {
|
|
|
73
138
|
<span className="update-banner__ok">{updateOk}</span>
|
|
74
139
|
) : updateError ? (
|
|
75
140
|
<span className="update-banner__err">{updateError}</span>
|
|
76
|
-
) : (
|
|
141
|
+
) : info ? (
|
|
77
142
|
<>
|
|
78
143
|
<span className="update-banner__label">Update available</span>
|
|
79
144
|
<span className="update-banner__sep">—</span>
|
|
80
145
|
<span className="update-banner__version">v{info.latest}</span>
|
|
81
146
|
<span className="update-banner__sep">(installed: v{info.installed})</span>
|
|
82
147
|
</>
|
|
83
|
-
)}
|
|
148
|
+
) : null}
|
|
84
149
|
</span>
|
|
85
150
|
|
|
86
151
|
{!updateOk && (
|
|
87
152
|
<div className="update-banner__actions">
|
|
88
153
|
{updateError ? (
|
|
89
154
|
<button className="ui-btn ui-btn--primary ui-btn--sm" onClick={handleUpdate} disabled={updating}>
|
|
90
|
-
{updating ? 'Updating
|
|
155
|
+
{updating ? 'Updating…' : 'Retry'}
|
|
91
156
|
</button>
|
|
92
157
|
) : (
|
|
93
158
|
<button className="ui-btn ui-btn--primary ui-btn--sm" onClick={handleUpdate} disabled={updating}>
|
|
94
|
-
{updating ? 'Updating
|
|
159
|
+
{updating ? 'Updating…' : 'Update now'}
|
|
95
160
|
</button>
|
|
96
161
|
)}
|
|
97
162
|
<button className="ui-btn ui-btn--ghost ui-btn--sm" onClick={handleDismiss}>
|
package/bin/rev4a.js
CHANGED
|
@@ -428,7 +428,9 @@ function seedAgentToken() {
|
|
|
428
428
|
function build() {
|
|
429
429
|
log('BUILD', 'Building Next.js app…');
|
|
430
430
|
try {
|
|
431
|
-
|
|
431
|
+
// Generous on purpose: a build is the slowest step of an install, and killing it
|
|
432
|
+
// because it passed two minutes takes the server down over slowness alone.
|
|
433
|
+
execSync('npx next build', { stdio: 'inherit', cwd: ROOT, timeout: 30 * 60_000 });
|
|
432
434
|
log('BUILD', 'Build complete');
|
|
433
435
|
} catch (err) {
|
|
434
436
|
log('BUILD', `Build failed: ${err.message}`);
|
|
@@ -754,13 +756,14 @@ if (cmd === 'update') {
|
|
|
754
756
|
console.log('Detected git repo — pulling and building…');
|
|
755
757
|
execSync(`cd ${root} && git pull && npm install && npm run build`, {
|
|
756
758
|
stdio: 'inherit',
|
|
757
|
-
|
|
759
|
+
// npm install + a full build: minutes, not two.
|
|
760
|
+
timeout: 30 * 60_000,
|
|
758
761
|
});
|
|
759
762
|
} else {
|
|
760
763
|
console.log('Using npm global install…');
|
|
761
764
|
execSync(`npm install -g ${PKG_NAME}@latest`, {
|
|
762
765
|
stdio: 'inherit',
|
|
763
|
-
timeout:
|
|
766
|
+
timeout: 20 * 60_000,
|
|
764
767
|
});
|
|
765
768
|
// Wipe old build so rev4a serve rebuilds with the new version
|
|
766
769
|
const nextDir = join(ROOT, '.next');
|
package/daemon.js
CHANGED
|
@@ -28,7 +28,7 @@ const MODEL_PRICING = {
|
|
|
28
28
|
'default': { in: 3.00, out: 15.00 },
|
|
29
29
|
};
|
|
30
30
|
|
|
31
|
-
//
|
|
31
|
+
// Direct aliases for models that do not match by substring
|
|
32
32
|
const MODEL_ALIASES = {
|
|
33
33
|
'cheap': 'flash',
|
|
34
34
|
'fast': 'claude-sonnet-4',
|
|
@@ -69,7 +69,7 @@ try {
|
|
|
69
69
|
process.on('uncaughtException', (err) => {
|
|
70
70
|
console.error(`[UNCAUGHT] ${err.message}\n${err.stack}`);
|
|
71
71
|
console.error('Daemon will attempt restart via watchdog cron');
|
|
72
|
-
//
|
|
72
|
+
// Do NOT exit — the watchdog reads this from the healthcheck
|
|
73
73
|
});
|
|
74
74
|
|
|
75
75
|
db.exec(`
|
|
@@ -749,7 +749,7 @@ function pollSessions() {
|
|
|
749
749
|
}
|
|
750
750
|
}
|
|
751
751
|
|
|
752
|
-
// WAL checkpoint
|
|
752
|
+
// FULL WAL checkpoint every 10 polls
|
|
753
753
|
pollCount = (pollCount || 0) + 1;
|
|
754
754
|
if (pollCount % 10 === 0) {
|
|
755
755
|
db.pragma('wal_checkpoint(FULL)');
|
package/docs/ARCHITECTURE.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# Rev4a Architecture — Design & Vision
|
|
2
2
|
|
|
3
3
|
> **Status:** Active — `main` branch
|
|
4
|
-
> **Last updated:** 2026-09-
|
|
4
|
+
> **Last updated:** 2026-09-22
|
|
5
5
|
> **Goal:** Transform Rev4a from a monitoring dashboard into a central orchestrator for a distributed multi-container agency.
|
|
6
6
|
|
|
7
7
|
---
|
|
@@ -207,8 +207,17 @@ The central container, running the Next.js dashboard + orchestration API.
|
|
|
207
207
|
table (`lib/agent-restore-state.ts`): the archive replaces the volume (stop, clear,
|
|
208
208
|
extract, start), up to 30 minutes. Same 202-and-background shape as a recreate, and the
|
|
209
209
|
same guarantees — a reload or a Rev4a restart does not lose the job, a second restore
|
|
210
|
-
is refused, an interrupted one
|
|
211
|
-
|
|
210
|
+
is refused, and an interrupted one is **run again from the same archive** at startup: a
|
|
211
|
+
half-written volume must never be presented as a restore, and the archive was already
|
|
212
|
+
checked before the job started (when it is gone the container is started on whatever the
|
|
213
|
+
volume holds, and the row says so). The extract has no percentage (it is a single
|
|
214
|
+
`tar xzf`); the panel and the agent card show `RESTORING`.
|
|
215
|
+
- **The four job tables share one implementation**: `lib/agent-job-state.ts` builds the
|
|
216
|
+
insert/update/latest/active/`markInterrupted` machinery for `agent_upgrades`,
|
|
217
|
+
`agent_recreates`, `agent_restores` and `agent_edits`; each `lib/agent-*-state.ts` keeps
|
|
218
|
+
only its table's types and function names. They were four near-identical copies that had
|
|
219
|
+
started to drift. At startup `lib/agent-jobs-maintenance.ts` prunes each table to the
|
|
220
|
+
newest 20 rows per agent — the panel reads the latest row only, so the rest is history.
|
|
212
221
|
- **Browser access** to an agent's Control UI goes through `lib/agent-devices.ts`:
|
|
213
222
|
`openclaw devices list | approve | reject | rename | remove` and
|
|
214
223
|
`openclaw dashboard --json`, run inside the container with the async `dockerExec`.
|
|
@@ -279,6 +288,19 @@ the rules for anything you touch, not as a description of the whole tree:
|
|
|
279
288
|
`promisify(exec)` silently ignores an `input` option: the process starts, stdin
|
|
280
289
|
is never written, and the command hangs with no error to point at.
|
|
281
290
|
|
|
291
|
+
- **The process model and self-update.** `rev4a serve` (the systemd unit's process) is a
|
|
292
|
+
supervisor: it spawns `rev4a _run <port>`, which in turn runs Next, the daemon and the
|
|
293
|
+
terminal WebSocket. `rev4a update` installs the new version, then `rev4a restart` writes
|
|
294
|
+
`.restart-flag` in the data directory; `_run` sees it, stops its children, waits for the
|
|
295
|
+
port to come free and exits with code **42**, and the supervisor relaunches `_run` on the
|
|
296
|
+
new code — so the supervisor itself never goes down (the unit's `NRestarts` stays 0).
|
|
297
|
+
The dashboard's **Update now** is only a detached `rev4a update` (`POST
|
|
298
|
+
/api/update-check`): it must not try to restart anything itself, because the update
|
|
299
|
+
stops the very process that spawned it, and the CLI's own flag is the mechanism that
|
|
300
|
+
matters. Its output goes to `update.log` in the data directory, since nothing else can
|
|
301
|
+
report the outcome: the banner records what it asked for, waits for the installed
|
|
302
|
+
version to change and only then reloads (see `VersionBanner`).
|
|
303
|
+
|
|
282
304
|
### 3.2 Agent Container Template (`openclaw-agent-base`)
|
|
283
305
|
|
|
284
306
|
Docker image for every agent container.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Rev4a Frontend Architecture
|
|
2
2
|
|
|
3
|
-
> **Last updated:** 2026-09-
|
|
3
|
+
> **Last updated:** 2026-09-22
|
|
4
4
|
|
|
5
5
|
## Layering
|
|
6
6
|
|
|
@@ -46,8 +46,9 @@ All shared UI primitives live in `app/components/ui/` and are exported from `app
|
|
|
46
46
|
| `BackupSection` | inline in `app/agents/PageClient.tsx` | BACKUP section of the agent detail panel, on the cold backup and the restore. **Backup Now** starts `POST /api/agents/[id]/cold-backup`; while the job runs a banner shows the file and its live percent with **Cancel** (`DELETE /cold-backup`). **Restore** (after a confirm) starts `POST /restore` and a banner shows `Restoring <file>…` (no percent: the extract is a single `tar xzf`, and there is no Cancel). Both sections poll their `GET` every 2 s while running, and on mount pick up a job that is already running — a backup lives in a Docker helper, a restore in `agent_restores`, so reloading the page or navigating away never loses them nor allows a second one (the server answers 409 anyway). Delete per row; all actions disabled while one runs; keyed busy state `{ kind, file }` so only the row in action shows the spinner. On the agent list, an activity Badge (fed by `/api/agents/activity-summary`, polled at 2 s only while something runs, otherwise riding the 15 s list poll) reads `BACKUP nn%`, `RESTORING`, `RECREATING`, `EDITING` or `UPDATING`. |
|
|
47
47
|
| `RecreateSection` | inline in `app/agents/PageClient.tsx` | RECREATE section of the agent detail panel. **Recreate Container** starts `POST /api/agents/[id]/recreate` (202) after a confirm; a banner then shows the phase — *Backing up … nn%* while the cold backup runs, *Recreating container…* while the container is rebuilt and the gateway starts. The section polls `GET /recreate` every 2 s, and on mount picks up a recreate that is already running, so a reload or navigation never loses it; it refetches the agent once the job reports `done`. |
|
|
48
48
|
| `ImageDownloadBanner` | `app/agents/ImageDownloadBanner.tsx` | Agent image banner on the Agents page. Polls `/api/agents/image-status` every 2 s; offers **Download Image** when no supported version is downloaded, **Download <version>** when the registry publishes a newer one, and shows the download in progress and its completion. Downloading changes no agent. |
|
|
49
|
+
| `VersionBanner` | `app/components/VersionBanner.tsx` | "Update available" banner for Rev4a itself, when `GET /api/update-check?check=1` reports a newer published version (dismissable per version, remembered in `localStorage`). **Update now** starts `POST /api/update-check`; because that update restarts the server, the banner cannot be told the outcome by the response: it records what it asked for in `sessionStorage`, polls `/api/update-check` until the installed version moves (two minutes at most) and reloads, then on the next mount either confirms "Updated to vX" or reports that the update did not complete and points at `update.log` (the update's own output). It never reloads blindly onto the same version. |
|
|
49
50
|
| `BrowserAccessSection` / `OpenControlUiButton` | `app/agents/BrowserAccessSection.tsx` | Browser access to one agent's Control UI, in its detail panel: requests waiting for approval (Approve / Reject) and approved browsers (Rename / Revoke), refreshed every 5 s while mounted. A successful approve, reject, rename or revoke updates the list at once, since the refresh behind it runs the OpenClaw CLI and takes seconds; a read started before the mutation is discarded. On agents that require approval, "Invite link" fetches `/api/agents/[id]/invite-link` and shows the link in a read-only field with Copy, which uses the Clipboard API in a secure context and the field's selection over plain HTTP, plus a warning when the link uses localhost. `OpenControlUiButton` opens `/api/agents/[id]/open-control-ui` in a new tab inside the click; that route redirects to a one-time link that pairs the browser with no approval, or to the plain token link when none can be issued. Used on the agent cards and in the panel. |
|
|
50
|
-
| `ChannelManager` / `ChannelSection` | `app/agents/ChannelManager.tsx`, `ChannelSection` inline in `app/agents/PageClient.tsx` | Telegram, in the agent detail panel (`ChannelSection` is the card that opens the modal; the modal title is the agent's display name). Reads `GET /channels`; lists pending pairing requests with **Approve** (`POST /channels/pairing`) and approved senders with **Revoke** after a confirm (`DELETE /channels/pairing?senderId=`). Pending comes from `openclaw pairing list`, approved from OpenClaw's pairing store (`lib/channelManager.ts`). Polls pairings every 5 s while open; one keyed busy state per action. |
|
|
51
|
+
| `ChannelManager` / `ChannelSection` | `app/agents/ChannelManager.tsx`, `ChannelSection` inline in `app/agents/PageClient.tsx` | Telegram, in the agent detail panel (`ChannelSection` is the card that opens the modal; the modal title is the agent's display name). Reads `GET /channels`; lists pending pairing requests with **Approve** (`POST /channels/pairing`) and approved senders with **Revoke** after a confirm (`DELETE /channels/pairing?senderId=`). Pending comes from `openclaw pairing list`, approved from OpenClaw's pairing store (`lib/channelManager.ts`). When that store cannot be read the panel shows the reason instead of "No approved senders" (`PairingState.error`), so an empty list is never a guess. Polls pairings every 5 s while open; one keyed busy state per action. |
|
|
51
52
|
| `EditAgentModal` / `EditBanner` | `app/agents/PageClient.tsx` | Rename/ports editing. The modal has **Display Name** and **Host Port** (same input and validation messages as the create wizard, from `lib/agent-ports.ts`), sends `PATCH /api/agents/[id]` and closes on `202`; `EditBanner` (top of the agent detail) polls `GET /api/agents/[id]` every 2 s while an edit is `rebuilding`, resumes on mount, and refetches the agent once it finishes, so a reload or a navigation shows the running edit instead of allowing a second (the server answers 409). No backup is taken: the volume is untouched. The port range is validated **as it is typed**: the modal fetches `GET /api/agents/ports` when it opens (the same set the create form uses, every container, running or stopped) and excludes the agent's own block, so an occupied range shows the API's message inline and the Save button stays disabled — the create wizard does the same with the same endpoint. |
|
|
52
53
|
| `ModelSection` | `app/agents/ModelSection.tsx` | Primary model and fallbacks for one agent, in its detail panel. Explicit save, no restart. The model is a property of the agent, not of the gateway. Tags models the catalogue marks `deprecated`. |
|
|
53
54
|
| `ModelsProvider` / `useModels` | `app/lib/models-context.tsx` | The client's single model list, from `/api/models`. Whatever changes what is offered calls `refresh()`: the Gateway page after a toggle, a key save or removal, or a sync, and the first-run wizard after saving keys. Everything else only reads, PulseChat included. |
|
package/docs/REV4A.md
CHANGED
|
@@ -201,6 +201,23 @@ If the daemon never answers, `serve` starts anyway, skips the network and image
|
|
|
201
201
|
checks, and says so in the log. The startup sync then reaches no agent, and logs
|
|
202
202
|
that too; run Sync All Agents once Docker is up.
|
|
203
203
|
|
|
204
|
+
### Memory (a host that runs several agents)
|
|
205
|
+
|
|
206
|
+
`rev4a update` installs the new version and the server rebuilds Next before it comes
|
|
207
|
+
back (`rev4a` wipes `.next`, so the build always runs). That build is the memory peak
|
|
208
|
+
of the whole installation: with several agent Gateways resident (roughly 0.5-0.8 GB
|
|
209
|
+
each) a host with no swap can hit the kernel OOM killer during the update — it killed
|
|
210
|
+
`next-server` on a 7.7 GB VPS, which then stayed unreachable until a reboot.
|
|
211
|
+
|
|
212
|
+
Give such a host swap (4-8 GB is enough for the build) and a conservative
|
|
213
|
+
`vm.swappiness`:
|
|
214
|
+
|
|
215
|
+
```bash
|
|
216
|
+
fallocate -l 4G /swapfile && chmod 600 /swapfile && mkswap /swapfile && swapon /swapfile
|
|
217
|
+
echo '/swapfile none swap sw 0 0' >> /etc/fstab
|
|
218
|
+
echo 'vm.swappiness=10' > /etc/sysctl.d/99-rev4a-swap.conf
|
|
219
|
+
```
|
|
220
|
+
|
|
204
221
|
### Systemd environment override
|
|
205
222
|
|
|
206
223
|
File: `/etc/systemd/system/rev4a-next.service` (EnvironmentFile)
|
|
@@ -1339,7 +1339,10 @@ releases used are gone, and reading those returned nothing).
|
|
|
1339
1339
|
|---|---|---|
|
|
1340
1340
|
| `channel` | no | Channel name (default: `telegram`) |
|
|
1341
1341
|
|
|
1342
|
-
**Response:**
|
|
1342
|
+
**Response:** `{ pending: [...], approved: [...], error: null }` — `error` carries why the
|
|
1343
|
+
approved list is empty when that is not simply "none" (the store could not be read); the
|
|
1344
|
+
panel shows it instead of "No approved senders". A missing store is not an error.
|
|
1345
|
+
|
|
1343
1346
|
```json
|
|
1344
1347
|
{
|
|
1345
1348
|
"pending": [
|
|
@@ -2559,14 +2562,28 @@ Installed version against the latest published one.
|
|
|
2559
2562
|
**Query params:** `check=1` queries the registry; without it the answer comes
|
|
2560
2563
|
from local state only.
|
|
2561
2564
|
|
|
2562
|
-
**Response:** `{ "installed": "1.
|
|
2565
|
+
**Response:** `{ "installed": "1.4.2", "latest": "1.5.0", "updateAvailable": true, "package": "@flame0510/project-aether", "log": "update.log" }`
|
|
2566
|
+
|
|
2567
|
+
`log` is the file name, in the Rev4a data directory, where the update's output is
|
|
2568
|
+
written.
|
|
2563
2569
|
|
|
2564
2570
|
### `POST /api/update-check`
|
|
2565
|
-
Run `rev4a update` as a detached background process.
|
|
2566
|
-
|
|
2571
|
+
Run `rev4a update` as a detached background process. Nothing here restarts anything:
|
|
2572
|
+
the update kills this process on its way in (`fuser -k <port>/tcp`) and `rev4a serve`
|
|
2573
|
+
brings the child back on the new binary via its `.restart-flag`, so the connection
|
|
2574
|
+
drops and the page has to wait for the server to answer again.
|
|
2575
|
+
|
|
2576
|
+
The child's output goes to `update.log` in the data directory — the update restarts
|
|
2577
|
+
the process that spawned it, so that file is the only record of what happened.
|
|
2567
2578
|
|
|
2568
2579
|
**Auth:** browser cookie or bearer token
|
|
2569
2580
|
|
|
2581
|
+
**Response:** `{ "success": true, "message": "...", "log": "update.log" }`
|
|
2582
|
+
|
|
2583
|
+
The banner records what it asked for, polls `/api/version` until the installed version
|
|
2584
|
+
moves (or two minutes pass), reloads, and on the next mount either confirms
|
|
2585
|
+
"Updated to vX" or reports that the update did not complete and points at the log.
|
|
2586
|
+
|
|
2570
2587
|
### `GET /api/alerts/smoke`
|
|
2571
2588
|
Send a test alert, to verify the Telegram alerting path end to end.
|
|
2572
2589
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# What is Rev4a?
|
|
2
2
|
|
|
3
|
-
> **Last updated:** 2026-09-
|
|
3
|
+
> **Last updated:** 2026-09-22
|
|
4
4
|
|
|
5
5
|
Rev4a is the control panel for your AI agent infrastructure. It shows you everything your agents are doing, how much they cost, and whether the system is healthy — all in one dashboard.
|
|
6
6
|
|
|
@@ -36,6 +36,12 @@ The agent list also shows a compact TG chip next to each agent name (green = con
|
|
|
36
36
|
|
|
37
37
|
**Browser access:** on agents running OpenClaw 9.x, every new browser has to be approved once before the agent's Control UI connects. The detail panel's "BROWSER ACCESS" section lists browsers waiting for approval, with Approve and Reject, and the browsers already approved, with Rename and Revoke. A yellow "BROWSER WAITING" chip on the agent card says a request is pending. The **Open** button tries a one-time link that lets the browser in without any approval; if the agent cannot issue one (it is stopped, or the link fails) it opens the normal link. To let someone else in, **Invite link** gives a link to send them: their browser appears under waiting for approval, and nothing opens until you approve it. The link contains the token all agents share; changing the agents token cancels every link already sent.
|
|
38
38
|
|
|
39
|
+
Rev4a itself has an **"Update available"** banner: it starts `rev4a update` and the server
|
|
40
|
+
restarts itself, so the dashboard drops briefly. The banner is only shown when a newer
|
|
41
|
+
version is published; it waits for the restart and then confirms the new version, or
|
|
42
|
+
reports that the update did not complete and points at `update.log` in the Rev4a data
|
|
43
|
+
directory, where the update's output is written.
|
|
44
|
+
|
|
39
45
|
The Agents page includes a banner for the **agent base image**, which is kept per
|
|
40
46
|
OpenClaw version. It is hidden when a supported version is downloaded and nothing newer
|
|
41
47
|
is published. When no image is downloaded it offers **Download Image**; when a newer
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# What PULSE Can Answer
|
|
2
2
|
|
|
3
|
-
> **Last updated:** 2026-09-
|
|
3
|
+
> **Last updated:** 2026-09-22
|
|
4
4
|
|
|
5
5
|
PULSE is the in-dashboard AI concierge for Rev4a. This document defines what she can and cannot answer.
|
|
6
6
|
|
|
@@ -102,6 +102,7 @@ PULSE is the in-dashboard AI concierge for Rev4a. This document defines what she
|
|
|
102
102
|
- "Why is the agent base image banner showing?"
|
|
103
103
|
- "How do I fix 'image is outdated'?"
|
|
104
104
|
- "How do agent image updates work?" — The banner on the Agents page runs a `docker pull`. It is a download, not a build: there is no modal, no live log, and no way to abort from the UI.
|
|
105
|
+
- "How do I update Rev4a itself?" — The "Update available" banner starts `rev4a update` in the background (the same command as from a shell). It installs the new version and Rev4a restarts itself, so the dashboard drops for a short while; the banner waits for the new version and then confirms it, or says the update did not complete. The update's output is written to `update.log` in the Rev4a data directory (`~/.config/rev4a/data/update.log`) — the only place that says why an update failed.
|
|
105
106
|
- "Why is my Telegram bot not connecting?"
|
|
106
107
|
- "Why can't I approve a pairing code?"
|
|
107
108
|
- "Why is the TG badge missing from my agent?"
|
package/instrumentation.ts
CHANGED
|
@@ -65,5 +65,16 @@ export async function register() {
|
|
|
65
65
|
} catch {
|
|
66
66
|
console.warn('[rev4a] Could not reconcile cold backups on startup');
|
|
67
67
|
}
|
|
68
|
+
// Retention for the lifecycle job tables: the panel reads the latest row of each
|
|
69
|
+
// agent, so the history is trimmed to the newest rows per agent. Best-effort.
|
|
70
|
+
try {
|
|
71
|
+
const { pruneLifecycleRows } = await import('./lib/agent-jobs-maintenance');
|
|
72
|
+
const removed = pruneLifecycleRows().filter((r) => r.removed > 0);
|
|
73
|
+
if (removed.length) {
|
|
74
|
+
console.log(`[rev4a] Pruned job history: ${removed.map((r) => `${r.table} ${r.removed}`).join(', ')}`);
|
|
75
|
+
}
|
|
76
|
+
} catch {
|
|
77
|
+
console.warn('[rev4a] Could not prune the lifecycle job history');
|
|
78
|
+
}
|
|
68
79
|
}
|
|
69
80
|
}
|