reevesagents 2.1.0 → 2.2.1
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/CHANGELOG.md +21 -0
- package/README.md +232 -318
- package/dist/chunk-CJKEBBUI.js +7663 -0
- package/dist/{chunk-UEYJAKAZ.js → chunk-DGLUP7Q7.js} +2 -2
- package/dist/{chunk-PWYG5IM5.js → chunk-HTCENB3Q.js} +2 -2
- package/dist/chunk-PKMTELW4.js +115 -0
- package/dist/chunk-PVYM35RS.js +1697 -0
- package/dist/{chunk-OQJNBACW.js → chunk-QWUBYDUV.js} +2 -2
- package/dist/chunk-XEOWHTRQ.js +1246 -0
- package/dist/{chunk-KROKGL2R.js → chunk-XHP63Y64.js} +879 -2
- package/dist/cli.js +1099 -13
- package/dist/index.d.ts +5 -0
- package/dist/index.js +2 -2
- package/dist/{router-AYNTF24M.js → router-S7KR2CIE.js} +146 -79
- package/dist/{server-TIFQ5JSM.js → server-4OILK2LL.js} +344 -6
- package/dist/{server-BNBSZZIP.js → server-5U4NNV43.js} +305 -14
- package/dist/{tui-launch-7DBX4JYA.js → tui-launch-7WKLVYEH.js} +2 -2
- package/dist/web/app.css +444 -11
- package/dist/web/app.js +672 -21
- package/dist/web/favicon.png +0 -0
- package/dist/web/index.html +75 -0
- package/dist/web/insights-core.js +92 -0
- package/dist/web/plan-controller.js +91 -0
- package/dist/web/plan-error.js +81 -0
- package/dist/web/tick-line.js +78 -0
- package/package.json +10 -8
- package/dist/chunk-DLWYZPW6.js +0 -3222
- package/dist/chunk-YWS3MILO.js +0 -266
|
@@ -1,22 +1,38 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
|
+
flowAttentionText,
|
|
4
|
+
flowBadgeView,
|
|
3
5
|
localeCatalog,
|
|
6
|
+
translate,
|
|
4
7
|
translatePhrase
|
|
5
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-XHP63Y64.js";
|
|
6
9
|
import {
|
|
7
10
|
modelValuesForProvider
|
|
8
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-DGLUP7Q7.js";
|
|
12
|
+
import {
|
|
13
|
+
pauseFlow,
|
|
14
|
+
resumeFlow
|
|
15
|
+
} from "./chunk-PVYM35RS.js";
|
|
9
16
|
import {
|
|
10
17
|
REEVESAGENTS_VERSION,
|
|
18
|
+
flowIncidentAgeMs,
|
|
19
|
+
flowStatusPayload,
|
|
20
|
+
listFlowIncidents,
|
|
11
21
|
listRunApprovals,
|
|
22
|
+
readFlowBadge,
|
|
23
|
+
readTickStatus,
|
|
24
|
+
resolveFlowRunId,
|
|
12
25
|
resolveRunApproval,
|
|
13
26
|
sweepAgentsThrottled,
|
|
14
|
-
sweepOrphanSessionsThrottled
|
|
15
|
-
|
|
27
|
+
sweepOrphanSessionsThrottled,
|
|
28
|
+
systemdTimerState
|
|
29
|
+
} from "./chunk-XEOWHTRQ.js";
|
|
16
30
|
import {
|
|
17
31
|
CONFIG_FIELDS,
|
|
18
32
|
LANGUAGE_OPTIONS,
|
|
33
|
+
NotificationError,
|
|
19
34
|
PROVIDERS,
|
|
35
|
+
appendNotification,
|
|
20
36
|
archiveAndRemoveRun,
|
|
21
37
|
attach,
|
|
22
38
|
attachAll,
|
|
@@ -29,6 +45,7 @@ import {
|
|
|
29
45
|
detach,
|
|
30
46
|
detectAvailable,
|
|
31
47
|
findAgent,
|
|
48
|
+
flowPath,
|
|
32
49
|
hostStatus,
|
|
33
50
|
isLanguageCode,
|
|
34
51
|
killAgent,
|
|
@@ -37,11 +54,19 @@ import {
|
|
|
37
54
|
listRunHistory,
|
|
38
55
|
listRuns,
|
|
39
56
|
loadConfig,
|
|
57
|
+
markNotificationsRead,
|
|
40
58
|
normalizeProvider,
|
|
59
|
+
notificationSummary,
|
|
60
|
+
planExists,
|
|
61
|
+
planItemView,
|
|
62
|
+
planProgress,
|
|
41
63
|
providerColor,
|
|
42
64
|
providerDisplayName,
|
|
43
65
|
providerSupportsAuthMode,
|
|
44
66
|
providerSupportsEffort,
|
|
67
|
+
readFlow,
|
|
68
|
+
readNotifications,
|
|
69
|
+
readPlan,
|
|
45
70
|
readRun,
|
|
46
71
|
runDoctor,
|
|
47
72
|
runHasLiveTmuxTarget,
|
|
@@ -56,7 +81,7 @@ import {
|
|
|
56
81
|
tmuxAvailable,
|
|
57
82
|
tmuxCommand,
|
|
58
83
|
verifyServerLaunch
|
|
59
|
-
} from "./chunk-
|
|
84
|
+
} from "./chunk-CJKEBBUI.js";
|
|
60
85
|
import "./chunk-Q3WWQP2R.js";
|
|
61
86
|
|
|
62
87
|
// src/surfaces/webui/server.ts
|
|
@@ -107,13 +132,50 @@ function monogram(nickname, provider) {
|
|
|
107
132
|
const alnum = base.replace(/[^A-Za-z0-9]/g, "");
|
|
108
133
|
return (alnum.slice(0, 2) || provider.slice(0, 2)).toUpperCase();
|
|
109
134
|
}
|
|
135
|
+
function webFlow(badge, t, options = {}) {
|
|
136
|
+
const pulseMs = options.pulseMs ?? 15 * 60 * 1e3;
|
|
137
|
+
const fresh = pulseMs > 0 && badge.updated_at > 0 && (options.now ?? Date.now()) - badge.updated_at < pulseMs;
|
|
138
|
+
const view = flowBadgeView(t, badge, { fresh });
|
|
139
|
+
const doneKind = badge.status !== "done" ? null : badge.plan_progress !== null && badge.plan_progress.done >= badge.plan_progress.total ? "plan_complete" : badge.close_reason === "stopped by the operator" ? "stopped" : "closed_no_plan";
|
|
140
|
+
return {
|
|
141
|
+
status: badge.status,
|
|
142
|
+
rounds: badge.rounds,
|
|
143
|
+
max_rounds: badge.max_rounds,
|
|
144
|
+
label: view.label,
|
|
145
|
+
attention: badge.attention,
|
|
146
|
+
attention_label: flowAttentionText(t, badge),
|
|
147
|
+
review_overdue: badge.review_overdue,
|
|
148
|
+
tone: view.tone,
|
|
149
|
+
pulse: view.pulse,
|
|
150
|
+
plan: badge.plan_progress,
|
|
151
|
+
done_kind: doneKind,
|
|
152
|
+
detail: view.detail
|
|
153
|
+
};
|
|
154
|
+
}
|
|
110
155
|
function buildWebState(options = {}) {
|
|
156
|
+
const language = options.language ?? loadConfig().global.language;
|
|
157
|
+
const t = (key, values) => translate(language, key, values);
|
|
158
|
+
const now = options.now ?? Date.now();
|
|
111
159
|
const agentIndex = /* @__PURE__ */ new Map();
|
|
112
160
|
const runNameById = /* @__PURE__ */ new Map();
|
|
113
161
|
const runs = listRuns().map((run) => {
|
|
114
162
|
runNameById.set(run.id, run.name);
|
|
115
163
|
const live = options.liveTmuxTarget ? options.liveTmuxTarget(run) : runHasLiveTmuxTarget(run);
|
|
116
164
|
const runStatus = computeRunStatus(run, live);
|
|
165
|
+
const flow = readFlowBadge(run.id, now);
|
|
166
|
+
const incidents = listFlowIncidents(run.id, { open_only: true, now }).map((row) => ({
|
|
167
|
+
id: row.id,
|
|
168
|
+
spec_id: row.spec_id,
|
|
169
|
+
kind: row.kind,
|
|
170
|
+
severity: row.severity,
|
|
171
|
+
owner: row.owner,
|
|
172
|
+
status: row.status,
|
|
173
|
+
first_seen: row.first_seen,
|
|
174
|
+
last_seen: row.last_seen,
|
|
175
|
+
count: row.count,
|
|
176
|
+
note: row.note,
|
|
177
|
+
age_ms: flowIncidentAgeMs(row, now)
|
|
178
|
+
}));
|
|
117
179
|
const terminals = listAgents(run.id).map((agent) => {
|
|
118
180
|
agentIndex.set(agent.id, { nickname: agent.nickname, provider: agent.provider });
|
|
119
181
|
const status = agent.ended_at ? "ended" : agent.task_status;
|
|
@@ -147,7 +209,9 @@ function buildWebState(options = {}) {
|
|
|
147
209
|
working_dir: run.working_dir,
|
|
148
210
|
canStop: run.status === "running" && !run.ended_at,
|
|
149
211
|
canDelete: run.status === "ended" || run.ended_at !== null,
|
|
150
|
-
terminals
|
|
212
|
+
terminals,
|
|
213
|
+
flow: flow ? webFlow(flow, t, { now, pulseMs: options.agent_pulse_ms }) : null,
|
|
214
|
+
incidents
|
|
151
215
|
};
|
|
152
216
|
});
|
|
153
217
|
const history = listRunHistory().map((record) => ({
|
|
@@ -455,12 +519,46 @@ var DEFAULT_WEB_ROOT = join(dirname(fileURLToPath(import.meta.url)), "web");
|
|
|
455
519
|
var STATIC_ROUTES = {
|
|
456
520
|
"/app.css": { file: "app.css", type: "text/css; charset=utf-8" },
|
|
457
521
|
"/app.js": { file: "app.js", type: "text/javascript; charset=utf-8" },
|
|
522
|
+
"/tick-line.js": { file: "tick-line.js", type: "text/javascript; charset=utf-8" },
|
|
523
|
+
"/insights-core.js": { file: "insights-core.js", type: "text/javascript; charset=utf-8" },
|
|
524
|
+
"/plan-controller.js": { file: "plan-controller.js", type: "text/javascript; charset=utf-8" },
|
|
525
|
+
"/plan-error.js": { file: "plan-error.js", type: "text/javascript; charset=utf-8" },
|
|
458
526
|
"/xterm.css": { file: "xterm.css", type: "text/css; charset=utf-8" },
|
|
459
527
|
"/xterm.js": { file: "xterm.js", type: "text/javascript; charset=utf-8" },
|
|
460
528
|
"/addon-fit.js": { file: "addon-fit.js", type: "text/javascript; charset=utf-8" },
|
|
461
529
|
"/brand-duck.json": { file: "brand-duck.json", type: "application/json; charset=utf-8" },
|
|
462
530
|
"/favicon.png": { file: "favicon.png", type: "image/png" }
|
|
463
531
|
};
|
|
532
|
+
var INGEST_WINDOW_MS = 1e4;
|
|
533
|
+
var INGEST_MAX_PER_WINDOW = 60;
|
|
534
|
+
var ingestWindows = /* @__PURE__ */ new Map();
|
|
535
|
+
function ingestAllowed(peer) {
|
|
536
|
+
const key = peer ?? "unknown";
|
|
537
|
+
const now = Date.now();
|
|
538
|
+
const window = ingestWindows.get(key);
|
|
539
|
+
if (!window || now - window.start > INGEST_WINDOW_MS) {
|
|
540
|
+
ingestWindows.set(key, { start: now, count: 1 });
|
|
541
|
+
return true;
|
|
542
|
+
}
|
|
543
|
+
if (window.count >= INGEST_MAX_PER_WINDOW) return false;
|
|
544
|
+
window.count += 1;
|
|
545
|
+
return true;
|
|
546
|
+
}
|
|
547
|
+
function withPulse(summary) {
|
|
548
|
+
return { ...summary, agent_pulse_ms: loadConfig().global.agent_pulse_ms };
|
|
549
|
+
}
|
|
550
|
+
function flowControlRefusal(message) {
|
|
551
|
+
if (/no flow for run|not found/i.test(message) && !/cannot /.test(message)) return { code: "not_found" };
|
|
552
|
+
if (/is already paused/i.test(message)) return { code: "already_paused", state: "paused" };
|
|
553
|
+
const resumeInto = /cannot resume into state (\w+)/.exec(message);
|
|
554
|
+
if (resumeInto) return { code: "not_paused", state: "paused" };
|
|
555
|
+
const transition = /cannot (pause|resume) a flow in state (\w+)/.exec(message);
|
|
556
|
+
if (transition) {
|
|
557
|
+
const [, action, state] = transition;
|
|
558
|
+
return { code: action === "pause" ? "not_pausable" : "not_paused", state };
|
|
559
|
+
}
|
|
560
|
+
return { code: null };
|
|
561
|
+
}
|
|
464
562
|
function errMessage(err) {
|
|
465
563
|
return err instanceof Error ? err.message : String(err);
|
|
466
564
|
}
|
|
@@ -509,6 +607,31 @@ function serveIndex(res, ctx) {
|
|
|
509
607
|
}
|
|
510
608
|
send2(res, 200, buf, "text/html; charset=utf-8");
|
|
511
609
|
}
|
|
610
|
+
var SYSTEMD_PROBE_MS = 6e4;
|
|
611
|
+
var timerProbe = null;
|
|
612
|
+
function timerStateCached(now) {
|
|
613
|
+
if (timerProbe && now - timerProbe.at < SYSTEMD_PROBE_MS) return timerProbe.state;
|
|
614
|
+
const state = systemdTimerState({ now });
|
|
615
|
+
timerProbe = { at: now, state };
|
|
616
|
+
return state;
|
|
617
|
+
}
|
|
618
|
+
function flowTickPayload(now = Date.now()) {
|
|
619
|
+
const status = readTickStatus();
|
|
620
|
+
if (!status) return null;
|
|
621
|
+
const payload = {
|
|
622
|
+
driver: status.driver,
|
|
623
|
+
at: status.at,
|
|
624
|
+
advanced: status.advanced,
|
|
625
|
+
held: status.held,
|
|
626
|
+
skipped: status.skipped
|
|
627
|
+
};
|
|
628
|
+
const timer = timerStateCached(now);
|
|
629
|
+
if (timer) {
|
|
630
|
+
payload.active = timer.active;
|
|
631
|
+
if (timer.next_at !== void 0) payload.next_at = timer.next_at;
|
|
632
|
+
}
|
|
633
|
+
return payload;
|
|
634
|
+
}
|
|
512
635
|
function createSseHub() {
|
|
513
636
|
const clients = /* @__PURE__ */ new Set();
|
|
514
637
|
let timer = null;
|
|
@@ -517,8 +640,14 @@ function createSseHub() {
|
|
|
517
640
|
sweepAgentsThrottled();
|
|
518
641
|
sweepOrphanSessionsThrottled();
|
|
519
642
|
autoCleanupRuns();
|
|
520
|
-
|
|
643
|
+
const state = {
|
|
644
|
+
...buildWebState({ agent_pulse_ms: loadConfig().global.agent_pulse_ms }),
|
|
645
|
+
tick: flowTickPayload(),
|
|
646
|
+
notifications: withPulse(notificationSummary())
|
|
647
|
+
};
|
|
648
|
+
return { state, key: JSON.stringify(state) };
|
|
521
649
|
};
|
|
650
|
+
const frame = (state) => JSON.stringify({ ...state, now: Date.now() });
|
|
522
651
|
const write = (res, payload) => {
|
|
523
652
|
try {
|
|
524
653
|
res.write(`data: ${payload}
|
|
@@ -528,14 +657,15 @@ function createSseHub() {
|
|
|
528
657
|
}
|
|
529
658
|
};
|
|
530
659
|
const tick = () => {
|
|
531
|
-
const
|
|
532
|
-
if (
|
|
533
|
-
last =
|
|
660
|
+
const { state, key } = snapshot();
|
|
661
|
+
if (key === last) return;
|
|
662
|
+
last = key;
|
|
663
|
+
const payload = frame(state);
|
|
534
664
|
for (const res of clients) write(res, payload);
|
|
535
665
|
};
|
|
536
666
|
const start = () => {
|
|
537
667
|
if (timer) return;
|
|
538
|
-
last = snapshot();
|
|
668
|
+
last = snapshot().key;
|
|
539
669
|
timer = setInterval(tick, POLL_MS);
|
|
540
670
|
timer.unref();
|
|
541
671
|
};
|
|
@@ -553,7 +683,7 @@ function createSseHub() {
|
|
|
553
683
|
"connection": "keep-alive",
|
|
554
684
|
"x-content-type-options": "nosniff"
|
|
555
685
|
});
|
|
556
|
-
write(res, snapshot());
|
|
686
|
+
write(res, frame(snapshot().state));
|
|
557
687
|
clients.add(res);
|
|
558
688
|
start();
|
|
559
689
|
res.on("close", () => {
|
|
@@ -731,10 +861,18 @@ function resolveApprovalAction(id, body) {
|
|
|
731
861
|
}
|
|
732
862
|
async function handleRequest(req, res, ctx) {
|
|
733
863
|
if (!isAllowedHostHeader(req.headers.host)) {
|
|
864
|
+
try {
|
|
865
|
+
req.resume();
|
|
866
|
+
} catch {
|
|
867
|
+
}
|
|
734
868
|
send2(res, 403, "forbidden host", "text/plain; charset=utf-8");
|
|
735
869
|
return;
|
|
736
870
|
}
|
|
737
871
|
if (isStateChangingMethod(req.method) && !isAllowedOrigin(req.headers.origin, ctx.port())) {
|
|
872
|
+
try {
|
|
873
|
+
req.resume();
|
|
874
|
+
} catch {
|
|
875
|
+
}
|
|
738
876
|
send2(res, 403, "forbidden origin", "text/plain; charset=utf-8");
|
|
739
877
|
return;
|
|
740
878
|
}
|
|
@@ -754,10 +892,17 @@ async function handleRequest(req, res, ctx) {
|
|
|
754
892
|
sweepOrphanSessionsThrottled();
|
|
755
893
|
autoCleanupRuns();
|
|
756
894
|
sendJson(res, 200, {
|
|
757
|
-
...buildWebState(),
|
|
895
|
+
...buildWebState({ agent_pulse_ms: loadConfig().global.agent_pulse_ms }),
|
|
896
|
+
tick: flowTickPayload(),
|
|
897
|
+
// The server's clock, once: the panel needs it to turn the marks in `tick` into seconds, and a clock inside the
|
|
898
|
+
// stream would make every frame differ — which is the defect this block removes (block 71).
|
|
899
|
+
now: Date.now(),
|
|
758
900
|
providers: listWebProviders(),
|
|
759
901
|
language: webLanguagePayload(),
|
|
760
902
|
web_theme: loadConfig().global.web_theme,
|
|
903
|
+
// One compact summary, so the Logs button can show a badge without loading the journal. The pulse length
|
|
904
|
+
// travels with it: the client cannot read the config, and a summary without it made every card compute 0 ms.
|
|
905
|
+
notifications: withPulse(notificationSummary()),
|
|
761
906
|
version: REEVESAGENTS_VERSION
|
|
762
907
|
});
|
|
763
908
|
return;
|
|
@@ -794,6 +939,150 @@ async function handleRequest(req, res, ctx) {
|
|
|
794
939
|
}
|
|
795
940
|
return;
|
|
796
941
|
}
|
|
942
|
+
if (method === "GET" && path === "/api/plan") {
|
|
943
|
+
const query = /* @__PURE__ */ new Map();
|
|
944
|
+
for (const pair of ((req.url ?? "").split("?")[1] ?? "").split("&")) {
|
|
945
|
+
if (!pair) continue;
|
|
946
|
+
const [rawKey, rawValue = ""] = pair.split("=");
|
|
947
|
+
query.set(decodeURIComponent(rawKey ?? ""), decodeURIComponent(rawValue));
|
|
948
|
+
}
|
|
949
|
+
const runId = query.get("run") ?? "";
|
|
950
|
+
if (!runId) {
|
|
951
|
+
sendJson(res, 400, { error: "run is required" });
|
|
952
|
+
return;
|
|
953
|
+
}
|
|
954
|
+
try {
|
|
955
|
+
const resolved = resolveFlowRunId(runId);
|
|
956
|
+
if (!planExists(resolved)) {
|
|
957
|
+
sendJson(res, 200, { run_id: resolved, plan: null });
|
|
958
|
+
return;
|
|
959
|
+
}
|
|
960
|
+
const plan = readPlan(resolved);
|
|
961
|
+
sendJson(res, 200, {
|
|
962
|
+
run_id: resolved,
|
|
963
|
+
plan: {
|
|
964
|
+
source_path: plan.source_path,
|
|
965
|
+
imported_at: plan.imported_at,
|
|
966
|
+
progress: planProgress(plan),
|
|
967
|
+
items: plan.items.map(planItemView),
|
|
968
|
+
conflicts: plan.conflicts
|
|
969
|
+
}
|
|
970
|
+
});
|
|
971
|
+
} catch (err) {
|
|
972
|
+
sendJson(res, 404, { error: errMessage(err) });
|
|
973
|
+
}
|
|
974
|
+
return;
|
|
975
|
+
}
|
|
976
|
+
if (method === "POST" && (path === "/api/flow/pause" || path === "/api/flow/resume")) {
|
|
977
|
+
const pausing = path === "/api/flow/pause";
|
|
978
|
+
try {
|
|
979
|
+
const body = await readJsonBody(req);
|
|
980
|
+
const requested = typeof body.run_id === "string" ? body.run_id : "";
|
|
981
|
+
if (!requested) {
|
|
982
|
+
sendJson(res, 400, { error: "run_id is required" });
|
|
983
|
+
return;
|
|
984
|
+
}
|
|
985
|
+
let runId;
|
|
986
|
+
try {
|
|
987
|
+
runId = resolveFlowRunId(requested);
|
|
988
|
+
} catch {
|
|
989
|
+
sendJson(res, 404, { error: "not_found" });
|
|
990
|
+
return;
|
|
991
|
+
}
|
|
992
|
+
const before = readFlow(runId);
|
|
993
|
+
if (pausing && before.state === "done") {
|
|
994
|
+
sendJson(res, 409, { error: "not_pausable", state: before.state });
|
|
995
|
+
return;
|
|
996
|
+
}
|
|
997
|
+
if (pausing && before.state === "paused") {
|
|
998
|
+
sendJson(res, 409, { error: "already_paused", state: before.state });
|
|
999
|
+
return;
|
|
1000
|
+
}
|
|
1001
|
+
if (!pausing && before.state !== "paused") {
|
|
1002
|
+
sendJson(res, 409, { error: "not_paused", state: before.state });
|
|
1003
|
+
return;
|
|
1004
|
+
}
|
|
1005
|
+
const result = pausing ? pauseFlow(runId) : resumeFlow(runId);
|
|
1006
|
+
sendJson(res, 200, { run_id: runId, flow: flowStatusPayload(result.state, flowPath(runId)) });
|
|
1007
|
+
} catch (err) {
|
|
1008
|
+
const refusal = flowControlRefusal(errMessage(err));
|
|
1009
|
+
if (refusal.code === "not_found") {
|
|
1010
|
+
sendJson(res, 404, { error: "not_found" });
|
|
1011
|
+
return;
|
|
1012
|
+
}
|
|
1013
|
+
if (refusal.code) {
|
|
1014
|
+
sendJson(res, 409, { error: refusal.code, ...refusal.state ? { state: refusal.state } : {} });
|
|
1015
|
+
return;
|
|
1016
|
+
}
|
|
1017
|
+
sendJson(res, 400, { error: errMessage(err) });
|
|
1018
|
+
}
|
|
1019
|
+
return;
|
|
1020
|
+
}
|
|
1021
|
+
if (method === "GET" && path === "/api/notifications") {
|
|
1022
|
+
const query = /* @__PURE__ */ new Map();
|
|
1023
|
+
for (const pair of ((req.url ?? "").split("?")[1] ?? "").split("&")) {
|
|
1024
|
+
if (!pair) continue;
|
|
1025
|
+
const [rawKey, rawValue = ""] = pair.split("=");
|
|
1026
|
+
query.set(decodeURIComponent(rawKey ?? ""), decodeURIComponent(rawValue));
|
|
1027
|
+
}
|
|
1028
|
+
const limit = Number.parseInt(query.get("limit") ?? "", 10);
|
|
1029
|
+
const since = Number.parseInt(query.get("since") ?? "", 10);
|
|
1030
|
+
try {
|
|
1031
|
+
sendJson(res, 200, readNotifications({
|
|
1032
|
+
limit: Number.isFinite(limit) ? limit : void 0,
|
|
1033
|
+
run: query.get("run") ?? void 0,
|
|
1034
|
+
since: Number.isFinite(since) ? since : void 0,
|
|
1035
|
+
unread: query.get("unread") === "1" || query.get("unread") === "true"
|
|
1036
|
+
}));
|
|
1037
|
+
} catch (err) {
|
|
1038
|
+
sendJson(res, 500, { error: errMessage(err) });
|
|
1039
|
+
}
|
|
1040
|
+
return;
|
|
1041
|
+
}
|
|
1042
|
+
if (method === "POST" && path === "/api/notifications") {
|
|
1043
|
+
const peer = req.socket.remoteAddress ?? "";
|
|
1044
|
+
const loopback = peer === "127.0.0.1" || peer === "::1" || peer === "::ffff:127.0.0.1";
|
|
1045
|
+
if (!loopback) {
|
|
1046
|
+
sendJson(res, 403, { error: "notifications are accepted from loopback only" });
|
|
1047
|
+
return;
|
|
1048
|
+
}
|
|
1049
|
+
if (!req.headers.origin) {
|
|
1050
|
+
sendJson(res, 403, { error: "an Origin header is required" });
|
|
1051
|
+
return;
|
|
1052
|
+
}
|
|
1053
|
+
if (!ingestAllowed(peer)) {
|
|
1054
|
+
try {
|
|
1055
|
+
req.resume();
|
|
1056
|
+
} catch {
|
|
1057
|
+
}
|
|
1058
|
+
sendJson(res, 429, { error: "too many notifications; slow down" });
|
|
1059
|
+
return;
|
|
1060
|
+
}
|
|
1061
|
+
try {
|
|
1062
|
+
const body = await readJsonBody(req);
|
|
1063
|
+
const created = appendNotification({ ...body, source: "external" });
|
|
1064
|
+
sendJson(res, 201, created);
|
|
1065
|
+
} catch (err) {
|
|
1066
|
+
try {
|
|
1067
|
+
req.resume();
|
|
1068
|
+
} catch {
|
|
1069
|
+
}
|
|
1070
|
+
if (err instanceof NotificationError && err.code === "refused") sendJson(res, 400, { error: err.message });
|
|
1071
|
+
else if (err instanceof NotificationError && err.code === "unavailable") sendJson(res, 503, { error: err.message });
|
|
1072
|
+
else sendJson(res, 400, { error: errMessage(err) });
|
|
1073
|
+
}
|
|
1074
|
+
return;
|
|
1075
|
+
}
|
|
1076
|
+
if (method === "POST" && path === "/api/notifications/read") {
|
|
1077
|
+
try {
|
|
1078
|
+
const body = await readJsonBody(req);
|
|
1079
|
+
const seq = typeof body.seq === "number" ? body.seq : void 0;
|
|
1080
|
+
sendJson(res, 200, markNotificationsRead(seq));
|
|
1081
|
+
} catch (err) {
|
|
1082
|
+
sendJson(res, 400, { error: errMessage(err) });
|
|
1083
|
+
}
|
|
1084
|
+
return;
|
|
1085
|
+
}
|
|
797
1086
|
if (method === "GET" && path === "/api/events") {
|
|
798
1087
|
ctx.sse.add(res);
|
|
799
1088
|
return;
|
|
@@ -1025,6 +1314,8 @@ async function startWebServer(options = {}) {
|
|
|
1025
1314
|
};
|
|
1026
1315
|
}
|
|
1027
1316
|
export {
|
|
1317
|
+
flowControlRefusal,
|
|
1318
|
+
flowTickPayload,
|
|
1028
1319
|
startWebServer
|
|
1029
1320
|
};
|
|
1030
|
-
//# sourceMappingURL=server-
|
|
1321
|
+
//# sourceMappingURL=server-5U4NNV43.js.map
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
import {
|
|
3
3
|
closeTuiWebServer,
|
|
4
4
|
startWebFromTui
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-HTCENB3Q.js";
|
|
6
6
|
export {
|
|
7
7
|
closeTuiWebServer,
|
|
8
8
|
startWebFromTui
|
|
9
9
|
};
|
|
10
|
-
//# sourceMappingURL=tui-launch-
|
|
10
|
+
//# sourceMappingURL=tui-launch-7WKLVYEH.js.map
|