reevesagents 1.2.0 → 1.3.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/AGENTS.md +183 -0
- package/CHANGELOG.md +61 -0
- package/README.md +292 -171
- package/dist/{chunk-4Q3JF22J.js → chunk-2LC6V55H.js} +2 -2
- package/dist/chunk-4W6MVOPK.js +29 -0
- package/dist/{chunk-MVMGFG4W.js → chunk-65LHCGPC.js} +836 -263
- package/dist/chunk-D24DQQ6V.js +0 -0
- package/dist/chunk-HS6TOISU.js +30 -0
- package/dist/chunk-YMUISYYB.js +5426 -0
- package/dist/chunk-Z2JHNE7V.js +317 -0
- package/dist/cli.d.ts +4 -1
- package/dist/cli.js +442 -49
- package/dist/extras-25AF6TAR.js +0 -0
- package/dist/index.d.ts +13 -37
- package/dist/index.js +13 -19
- package/dist/open-browser-DRSIJQ37.js +0 -0
- package/dist/{router-WCFLHJV7.js → router-TGRU5BFX.js} +1543 -797
- package/dist/{server-Z2YTGWSX.js → server-GYB53IBP.js} +267 -136
- package/dist/server-H2XEJQYT.js +622 -0
- package/dist/{tui-launch-7RGFE5KY.js → tui-launch-45ERRX5M.js} +2 -2
- package/dist/web/app.css +371 -26
- package/dist/web/app.js +717 -51
- package/dist/web/index.html +115 -10
- package/package.json +25 -18
- package/dist/chunk-3IXII4H5.js +0 -129
- package/dist/chunk-DHAW6OY3.js +0 -40
- package/dist/chunk-G6FN75ZW.js +0 -2393
- package/dist/chunk-JY4ZTTRK.js +0 -172
- package/dist/chunk-LUW6GCPO.js +0 -108
|
@@ -1,40 +1,53 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
|
-
localeCatalog
|
|
4
|
-
|
|
3
|
+
localeCatalog,
|
|
4
|
+
translatePhrase
|
|
5
|
+
} from "./chunk-YMUISYYB.js";
|
|
5
6
|
import {
|
|
6
7
|
modelValuesForProvider
|
|
7
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-HS6TOISU.js";
|
|
8
9
|
import {
|
|
10
|
+
REEVESAGENTS_VERSION,
|
|
11
|
+
attach,
|
|
12
|
+
attachAll,
|
|
13
|
+
detach,
|
|
14
|
+
hostStatus,
|
|
15
|
+
listRunApprovals,
|
|
16
|
+
resolveRunApproval
|
|
17
|
+
} from "./chunk-Z2JHNE7V.js";
|
|
18
|
+
import {
|
|
19
|
+
CONFIG_FIELDS,
|
|
9
20
|
LANGUAGE_OPTIONS,
|
|
10
21
|
PROVIDERS,
|
|
11
22
|
archiveAndRemoveRun,
|
|
12
23
|
autoCleanupRuns,
|
|
13
24
|
computeRunStatus,
|
|
14
25
|
deleteAgent,
|
|
26
|
+
deletePreset,
|
|
15
27
|
deleteRunHistory,
|
|
16
28
|
detectAvailable,
|
|
17
29
|
findAgent,
|
|
18
|
-
findAgentAny,
|
|
19
30
|
isLanguageCode,
|
|
20
31
|
killAgent,
|
|
21
32
|
listAgents,
|
|
22
|
-
|
|
33
|
+
listPresets,
|
|
23
34
|
listRunHistory,
|
|
24
35
|
listRuns,
|
|
25
|
-
listRunsAny,
|
|
26
36
|
loadConfig,
|
|
27
37
|
normalizeProvider,
|
|
28
38
|
providerColor,
|
|
29
39
|
providerDisplayName,
|
|
30
40
|
readRun,
|
|
31
|
-
|
|
41
|
+
runDoctor,
|
|
32
42
|
runHasLiveTmuxTarget,
|
|
33
|
-
|
|
43
|
+
savePresetFromRun,
|
|
44
|
+
setConfigValues,
|
|
34
45
|
spawnWorker,
|
|
35
46
|
startRun,
|
|
47
|
+
startRunFromPreset,
|
|
36
48
|
stopRun
|
|
37
|
-
} from "./chunk-
|
|
49
|
+
} from "./chunk-65LHCGPC.js";
|
|
50
|
+
import "./chunk-D24DQQ6V.js";
|
|
38
51
|
|
|
39
52
|
// src/web/server.ts
|
|
40
53
|
import { createServer } from "http";
|
|
@@ -78,32 +91,6 @@ function isAllowedOrigin(originHeader, port) {
|
|
|
78
91
|
return url.port === String(port);
|
|
79
92
|
}
|
|
80
93
|
|
|
81
|
-
// src/web/prebeta-orchestrator.ts
|
|
82
|
-
var ORCHESTRATOR_WEB_PROVIDERS = ["cc", "codex", "opencode", "hermes"];
|
|
83
|
-
function isOrchestratorWebProvider(provider) {
|
|
84
|
-
return ORCHESTRATOR_WEB_PROVIDERS.includes(provider);
|
|
85
|
-
}
|
|
86
|
-
function isRuntime(value) {
|
|
87
|
-
if (!value || typeof value !== "object") return false;
|
|
88
|
-
const maybe = value;
|
|
89
|
-
return typeof maybe.startRun === "function" && typeof maybe.spawnWorker === "function" && typeof maybe.killAgent === "function" && typeof maybe.stopRun === "function";
|
|
90
|
-
}
|
|
91
|
-
async function loadWebOrchestratorRuntime(injected) {
|
|
92
|
-
if (injected) return injected;
|
|
93
|
-
try {
|
|
94
|
-
const specifier = "reevesagents-orchestrator";
|
|
95
|
-
const mod = await import(specifier);
|
|
96
|
-
if (isRuntime(mod)) return mod;
|
|
97
|
-
} catch {
|
|
98
|
-
}
|
|
99
|
-
throw new Error([
|
|
100
|
-
"PRE-BETA orchestrator web mode requires the separate orchestrator package.",
|
|
101
|
-
"Install the all-in pre-beta option, then rerun:",
|
|
102
|
-
" npm install -g reevesagents reevesagents-orchestrator",
|
|
103
|
-
" reevesagents web --prebeta-orchestrator"
|
|
104
|
-
].join("\n"));
|
|
105
|
-
}
|
|
106
|
-
|
|
107
94
|
// src/web/state.ts
|
|
108
95
|
function monogram(nickname, provider) {
|
|
109
96
|
const base = (nickname || provider).trim();
|
|
@@ -111,17 +98,18 @@ function monogram(nickname, provider) {
|
|
|
111
98
|
return (alnum.slice(0, 2) || provider.slice(0, 2)).toUpperCase();
|
|
112
99
|
}
|
|
113
100
|
function buildWebState(options = {}) {
|
|
114
|
-
const
|
|
115
|
-
const
|
|
116
|
-
const runs =
|
|
117
|
-
|
|
101
|
+
const agentIndex = /* @__PURE__ */ new Map();
|
|
102
|
+
const runNameById = /* @__PURE__ */ new Map();
|
|
103
|
+
const runs = listRuns().map((run) => {
|
|
104
|
+
runNameById.set(run.id, run.name);
|
|
118
105
|
const live = options.liveTmuxTarget ? options.liveTmuxTarget(run) : runHasLiveTmuxTarget(run);
|
|
119
106
|
const runStatus = computeRunStatus(run, live);
|
|
120
|
-
const terminals =
|
|
107
|
+
const terminals = listAgents(run.id).map((agent) => {
|
|
108
|
+
agentIndex.set(agent.id, { nickname: agent.nickname, provider: agent.provider });
|
|
121
109
|
const status = agent.ended_at ? "ended" : agent.task_status;
|
|
122
110
|
const hasWindow = !agent.headless && !!agent.tmux_window_id;
|
|
123
111
|
const canAttach = live && hasWindow && status !== "ended";
|
|
124
|
-
const canKill = live && status !== "ended" && hasWindow
|
|
112
|
+
const canKill = live && status !== "ended" && hasWindow;
|
|
125
113
|
const canDelete = status === "ended";
|
|
126
114
|
return {
|
|
127
115
|
id: agent.id,
|
|
@@ -138,12 +126,12 @@ function buildWebState(options = {}) {
|
|
|
138
126
|
canDelete,
|
|
139
127
|
disabledReason: canAttach ? null : status === "ended" ? "agent has ended" : !live ? "run tmux session is unavailable" : "agent has no tmux window",
|
|
140
128
|
monogram: monogram(agent.nickname, agent.provider),
|
|
141
|
-
color: providerColor(agent.provider)
|
|
129
|
+
color: providerColor(agent.provider),
|
|
130
|
+
task: agent.task
|
|
142
131
|
};
|
|
143
132
|
});
|
|
144
133
|
return {
|
|
145
134
|
id: run.id,
|
|
146
|
-
mode,
|
|
147
135
|
name: run.name,
|
|
148
136
|
status: runStatus,
|
|
149
137
|
working_dir: run.working_dir,
|
|
@@ -152,10 +140,9 @@ function buildWebState(options = {}) {
|
|
|
152
140
|
terminals
|
|
153
141
|
};
|
|
154
142
|
});
|
|
155
|
-
const history = listRunHistory(
|
|
143
|
+
const history = listRunHistory().map((record) => ({
|
|
156
144
|
id: record.id,
|
|
157
145
|
name: record.name,
|
|
158
|
-
mode: record.mode,
|
|
159
146
|
status: record.status,
|
|
160
147
|
working_dir: record.working_dir,
|
|
161
148
|
started_at: record.started_at,
|
|
@@ -165,7 +152,24 @@ function buildWebState(options = {}) {
|
|
|
165
152
|
root_provider: record.root_provider,
|
|
166
153
|
root_provider_label: record.root_provider ? providerDisplayName(record.root_provider) : null
|
|
167
154
|
}));
|
|
168
|
-
|
|
155
|
+
const approvals = listRunApprovals(void 0, "pending").map((approval) => {
|
|
156
|
+
const info = agentIndex.get(approval.agent_id);
|
|
157
|
+
return {
|
|
158
|
+
id: approval.id,
|
|
159
|
+
run_id: approval.run_id,
|
|
160
|
+
run_name: runNameById.get(approval.run_id) ?? approval.run_id,
|
|
161
|
+
agent_id: approval.agent_id,
|
|
162
|
+
agent_nickname: info?.nickname ?? approval.agent_id,
|
|
163
|
+
provider: info?.provider ?? null,
|
|
164
|
+
provider_label: info ? providerDisplayName(info.provider) : null,
|
|
165
|
+
color: info ? providerColor(info.provider) : null,
|
|
166
|
+
action: approval.action,
|
|
167
|
+
summary: approval.summary,
|
|
168
|
+
risk: approval.risk,
|
|
169
|
+
requested_at: approval.requested_at
|
|
170
|
+
};
|
|
171
|
+
});
|
|
172
|
+
return { runs, history, approvals };
|
|
169
173
|
}
|
|
170
174
|
function listWebProviders() {
|
|
171
175
|
const available = detectAvailable();
|
|
@@ -173,7 +177,6 @@ function listWebProviders() {
|
|
|
173
177
|
id,
|
|
174
178
|
name: providerDisplayName(id),
|
|
175
179
|
available: available[id],
|
|
176
|
-
orchestrator: isOrchestratorWebProvider(id),
|
|
177
180
|
color: providerColor(id),
|
|
178
181
|
models: [...modelValuesForProvider(id)]
|
|
179
182
|
}));
|
|
@@ -238,7 +241,7 @@ function placeholderPage() {
|
|
|
238
241
|
<body>
|
|
239
242
|
<header>
|
|
240
243
|
<h1>ReevesAgents</h1>
|
|
241
|
-
<span class="tag">web ui
|
|
244
|
+
<span class="tag">web ui \xB7 loopback only</span>
|
|
242
245
|
</header>
|
|
243
246
|
<main id="app"><p class="empty">Loading agents...</p></main>
|
|
244
247
|
<script>
|
|
@@ -283,11 +286,10 @@ import { randomBytes } from "crypto";
|
|
|
283
286
|
import { URL as URL2 } from "url";
|
|
284
287
|
import { WebSocketServer } from "ws";
|
|
285
288
|
import pty from "@lydell/node-pty";
|
|
286
|
-
function resolveTerminalTarget(id
|
|
289
|
+
function resolveTerminalTarget(id) {
|
|
287
290
|
if (!id) throw new Error("missing agent id");
|
|
288
|
-
const agent =
|
|
289
|
-
|
|
290
|
-
else readRun(agent.run_id);
|
|
291
|
+
const agent = findAgent(id);
|
|
292
|
+
readRun(agent.run_id);
|
|
291
293
|
if (agent.ended_at) throw new Error("agent has ended");
|
|
292
294
|
if (agent.headless || !agent.tmux_window_id) throw new Error("agent has no tmux window");
|
|
293
295
|
return { session: agent.tmux_session, windowId: agent.tmux_window_id, nickname: agent.nickname };
|
|
@@ -337,10 +339,10 @@ function disposeBridge(bridge) {
|
|
|
337
339
|
} catch {
|
|
338
340
|
}
|
|
339
341
|
}
|
|
340
|
-
function openBridge(ws, id, bridges
|
|
342
|
+
function openBridge(ws, id, bridges) {
|
|
341
343
|
let target;
|
|
342
344
|
try {
|
|
343
|
-
target = resolveTerminalTarget(id
|
|
345
|
+
target = resolveTerminalTarget(id);
|
|
344
346
|
} catch (err) {
|
|
345
347
|
send(ws, { t: "e", m: err instanceof Error ? err.message : "agent not found" });
|
|
346
348
|
ws.close();
|
|
@@ -399,7 +401,7 @@ function openBridge(ws, id, bridges, options) {
|
|
|
399
401
|
ws.on("close", cleanup);
|
|
400
402
|
ws.on("error", cleanup);
|
|
401
403
|
}
|
|
402
|
-
function attachTerminalBridge(server, getPort
|
|
404
|
+
function attachTerminalBridge(server, getPort) {
|
|
403
405
|
const wss = new WebSocketServer({ noServer: true });
|
|
404
406
|
const bridges = /* @__PURE__ */ new Set();
|
|
405
407
|
server.on("upgrade", (req, socket, head) => {
|
|
@@ -422,7 +424,7 @@ function attachTerminalBridge(server, getPort, options = {}) {
|
|
|
422
424
|
socket.destroy();
|
|
423
425
|
return;
|
|
424
426
|
}
|
|
425
|
-
wss.handleUpgrade(req, socket, head, (ws) => openBridge(ws, id, bridges
|
|
427
|
+
wss.handleUpgrade(req, socket, head, (ws) => openBridge(ws, id, bridges));
|
|
426
428
|
});
|
|
427
429
|
return {
|
|
428
430
|
close: () => new Promise((resolve) => {
|
|
@@ -496,13 +498,13 @@ function serveIndex(res, ctx) {
|
|
|
496
498
|
}
|
|
497
499
|
send2(res, 200, buf, "text/html; charset=utf-8");
|
|
498
500
|
}
|
|
499
|
-
function createSseHub(
|
|
501
|
+
function createSseHub() {
|
|
500
502
|
const clients = /* @__PURE__ */ new Set();
|
|
501
503
|
let timer = null;
|
|
502
504
|
let last = "";
|
|
503
505
|
const snapshot = () => {
|
|
504
|
-
autoCleanupRuns({
|
|
505
|
-
return JSON.stringify(buildWebState(
|
|
506
|
+
autoCleanupRuns({ cleanStale: false });
|
|
507
|
+
return JSON.stringify(buildWebState());
|
|
506
508
|
};
|
|
507
509
|
const write = (res, payload) => {
|
|
508
510
|
try {
|
|
@@ -590,55 +592,38 @@ function normalizePermissionsInput(raw) {
|
|
|
590
592
|
if (raw === "ask" || raw === "skip") return raw;
|
|
591
593
|
throw new Error("unknown permission mode");
|
|
592
594
|
}
|
|
593
|
-
|
|
595
|
+
function parseAuthModeInput(raw) {
|
|
596
|
+
if (raw === void 0 || raw === null || raw === "") return void 0;
|
|
597
|
+
if (raw === "default" || raw === "api-key") return raw;
|
|
598
|
+
throw new Error("unknown auth mode");
|
|
599
|
+
}
|
|
600
|
+
function parseEffortInput(raw) {
|
|
601
|
+
if (raw === void 0 || raw === null || raw === "") return void 0;
|
|
602
|
+
if (raw === "default" || raw === "low" || raw === "medium" || raw === "high" || raw === "xhigh" || raw === "max") return raw;
|
|
603
|
+
throw new Error("unknown effort");
|
|
604
|
+
}
|
|
605
|
+
async function createTerminal(body) {
|
|
594
606
|
const provider = body.provider;
|
|
595
607
|
const normalizedProvider = normalizeProvider(provider);
|
|
596
608
|
if (!normalizedProvider) throw new Error("unknown provider");
|
|
597
609
|
const model = normalizeModel(normalizedProvider, body.model);
|
|
598
610
|
const permissions = normalizePermissionsInput(body.permissions);
|
|
611
|
+
const auth_mode = parseAuthModeInput(body.auth_mode);
|
|
612
|
+
const effort = parseEffortInput(body.effort);
|
|
599
613
|
const nickname = sanitizeNickname(typeof body.nickname === "string" ? body.nickname : "");
|
|
600
614
|
const runName = sanitizeRunName(typeof body.run_name === "string" ? body.run_name : "");
|
|
601
615
|
const prompt = typeof body.prompt === "string" ? body.prompt : "";
|
|
602
616
|
const runId = typeof body.run_id === "string" && body.run_id ? body.run_id : null;
|
|
603
617
|
if (runId) {
|
|
604
|
-
|
|
605
|
-
const
|
|
606
|
-
if (mode2 === "orchestrator") {
|
|
607
|
-
if (!ctx.orchestratorRuntime) throw new Error("PRE-BETA orchestrator web mode is not enabled");
|
|
608
|
-
if (!isOrchestratorWebProvider(normalizedProvider)) throw new Error("provider is not supported in PRE-BETA orchestrator mode");
|
|
609
|
-
const agent2 = ctx.orchestratorRuntime.spawnWorker({
|
|
610
|
-
run_id: runId,
|
|
611
|
-
provider: normalizedProvider,
|
|
612
|
-
nickname: nickname || void 0,
|
|
613
|
-
model,
|
|
614
|
-
permissions,
|
|
615
|
-
task: prompt
|
|
616
|
-
});
|
|
617
|
-
return { id: agent2.id, run_id: agent2.run_id };
|
|
618
|
-
}
|
|
619
|
-
const agent = spawnWorker({ run_id: runId, provider: normalizedProvider, nickname: nickname || void 0, model, permissions, task: prompt });
|
|
618
|
+
readRun(runId);
|
|
619
|
+
const agent = spawnWorker({ run_id: runId, provider: normalizedProvider, nickname: nickname || void 0, model, permissions, auth_mode, effort, task: prompt });
|
|
620
620
|
return { id: agent.id, run_id: agent.run_id };
|
|
621
621
|
}
|
|
622
|
-
const mode = body.mode === "orchestrator" ? "orchestrator" : "spawner";
|
|
623
622
|
const workingDir = typeof body.working_dir === "string" && body.working_dir.trim() ? body.working_dir.trim() : process.cwd();
|
|
624
|
-
if (mode === "orchestrator") {
|
|
625
|
-
if (!ctx.prebetaOrchestrator || !ctx.orchestratorRuntime) throw new Error("PRE-BETA orchestrator web mode is not enabled");
|
|
626
|
-
if (!isOrchestratorWebProvider(normalizedProvider)) throw new Error("provider is not supported in PRE-BETA orchestrator mode");
|
|
627
|
-
const result2 = ctx.orchestratorRuntime.startRun({
|
|
628
|
-
mode: "orchestrator",
|
|
629
|
-
name: runName || nickname || providerDisplayName(normalizedProvider),
|
|
630
|
-
working_dir: workingDir,
|
|
631
|
-
root: { provider: normalizedProvider, nickname: nickname || void 0, model, permissions, task: prompt }
|
|
632
|
-
});
|
|
633
|
-
const root2 = result2.agents[0];
|
|
634
|
-
if (!root2) throw new Error("run created no agent");
|
|
635
|
-
return { id: root2.id, run_id: result2.run.id };
|
|
636
|
-
}
|
|
637
623
|
const result = startRun({
|
|
638
|
-
mode: "spawner",
|
|
639
624
|
name: runName || nickname || providerDisplayName(normalizedProvider),
|
|
640
625
|
working_dir: workingDir,
|
|
641
|
-
root: { provider: normalizedProvider, nickname: nickname || void 0, model, permissions, task: prompt }
|
|
626
|
+
root: { provider: normalizedProvider, nickname: nickname || void 0, model, permissions, auth_mode, effort, task: prompt }
|
|
642
627
|
});
|
|
643
628
|
const root = result.agents[0];
|
|
644
629
|
if (!root) throw new Error("run created no agent");
|
|
@@ -649,45 +634,88 @@ function requireConfirm(body) {
|
|
|
649
634
|
}
|
|
650
635
|
function updateLanguage(body) {
|
|
651
636
|
if (!isLanguageCode(body.language)) throw new Error("unknown language");
|
|
652
|
-
|
|
653
|
-
cfg.global.language = body.language;
|
|
654
|
-
saveConfig(cfg);
|
|
637
|
+
setConfigValues({ language: body.language });
|
|
655
638
|
return webLanguagePayload();
|
|
656
639
|
}
|
|
657
|
-
function
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
640
|
+
function mcpHostsPayload() {
|
|
641
|
+
return { hosts: hostStatus() };
|
|
642
|
+
}
|
|
643
|
+
function attachMcpHostAction(body) {
|
|
644
|
+
const key = typeof body.key === "string" ? body.key : "";
|
|
645
|
+
if (!key) throw new Error("host key is required");
|
|
646
|
+
const result = attach(key);
|
|
647
|
+
return { result, hosts: hostStatus() };
|
|
648
|
+
}
|
|
649
|
+
function detachMcpHostAction(body) {
|
|
650
|
+
const key = typeof body.key === "string" ? body.key : "";
|
|
651
|
+
if (!key) throw new Error("host key is required");
|
|
652
|
+
const result = detach(key);
|
|
653
|
+
return { result, hosts: hostStatus() };
|
|
654
|
+
}
|
|
655
|
+
function attachAllMcpHostsAction() {
|
|
656
|
+
return { results: attachAll(), hosts: hostStatus() };
|
|
657
|
+
}
|
|
658
|
+
function configPayload() {
|
|
659
|
+
const config = loadConfig().global;
|
|
660
|
+
return {
|
|
661
|
+
config,
|
|
662
|
+
fields: CONFIG_FIELDS.filter((field) => field.kind !== "language").map((field) => ({ ...field, label: translatePhrase(config.language, field.label) }))
|
|
663
|
+
};
|
|
664
|
+
}
|
|
665
|
+
function updateConfigAction(body) {
|
|
666
|
+
const patch = {};
|
|
667
|
+
for (const field of CONFIG_FIELDS.filter((field2) => field2.kind !== "language")) {
|
|
668
|
+
if (body[field.key] !== void 0) patch[field.key] = body[field.key];
|
|
663
669
|
}
|
|
664
|
-
if (
|
|
665
|
-
|
|
670
|
+
if (Object.keys(patch).length === 0) throw new Error("no config fields to set");
|
|
671
|
+
return { config: setConfigValues(patch).global };
|
|
672
|
+
}
|
|
673
|
+
function presetsPayload() {
|
|
674
|
+
return { presets: listPresets() };
|
|
675
|
+
}
|
|
676
|
+
function savePresetAction(body) {
|
|
677
|
+
const runId = typeof body.run_id === "string" ? body.run_id : "";
|
|
678
|
+
if (!runId) throw new Error("run_id is required");
|
|
679
|
+
const name = typeof body.name === "string" ? body.name : "";
|
|
680
|
+
const description = typeof body.description === "string" ? body.description : "";
|
|
681
|
+
return { preset: savePresetFromRun(runId, name, description), presets: listPresets() };
|
|
682
|
+
}
|
|
683
|
+
function startPresetAction(name) {
|
|
684
|
+
if (!listPresets().some((preset) => preset.name === name)) throw new Error("preset not found");
|
|
685
|
+
const result = startRunFromPreset(name);
|
|
686
|
+
return { run: result.run, agents: result.agents };
|
|
687
|
+
}
|
|
688
|
+
function deletePresetAction(name) {
|
|
689
|
+
if (!listPresets().some((preset) => preset.name === name)) throw new Error("preset not found");
|
|
690
|
+
deletePreset(name);
|
|
666
691
|
}
|
|
667
|
-
function
|
|
668
|
-
|
|
692
|
+
function killTerminal(id) {
|
|
693
|
+
killAgent(id);
|
|
694
|
+
}
|
|
695
|
+
function deleteTerminal(id) {
|
|
696
|
+
const agent = findAgent(id);
|
|
669
697
|
if (!agent.ended_at) throw new Error("Stop agent before deleting it");
|
|
670
|
-
deleteAgent(id
|
|
698
|
+
deleteAgent(id);
|
|
671
699
|
}
|
|
672
|
-
function stopWebRun(id
|
|
673
|
-
|
|
674
|
-
if (run.mode === "spawner") {
|
|
675
|
-
stopRun(id);
|
|
676
|
-
return;
|
|
677
|
-
}
|
|
678
|
-
if (!ctx.orchestratorRuntime) throw new Error("PRE-BETA orchestrator web mode is not enabled");
|
|
679
|
-
ctx.orchestratorRuntime.stopRun(id);
|
|
700
|
+
function stopWebRun(id) {
|
|
701
|
+
stopRun(id);
|
|
680
702
|
}
|
|
681
|
-
function deleteWebRun(id
|
|
682
|
-
const run =
|
|
703
|
+
function deleteWebRun(id) {
|
|
704
|
+
const run = readRun(id);
|
|
683
705
|
if (run.status !== "ended" && run.ended_at === null) throw new Error("Stop run before deleting it");
|
|
684
706
|
archiveAndRemoveRun(id, "ended");
|
|
685
707
|
}
|
|
686
|
-
function deleteHistoryRecord(id
|
|
687
|
-
const history = listRunHistory(
|
|
708
|
+
function deleteHistoryRecord(id) {
|
|
709
|
+
const history = listRunHistory();
|
|
688
710
|
if (!history.some((record) => record.id === id)) throw new Error("history record not found");
|
|
689
711
|
deleteRunHistory(id);
|
|
690
712
|
}
|
|
713
|
+
function resolveApprovalAction(id, body) {
|
|
714
|
+
const decision = body.decision === "approved" ? "approved" : body.decision === "denied" ? "denied" : null;
|
|
715
|
+
if (!decision) throw new Error("decision must be approved or denied");
|
|
716
|
+
const note = typeof body.note === "string" ? body.note : "";
|
|
717
|
+
return resolveRunApproval(id, decision, note);
|
|
718
|
+
}
|
|
691
719
|
async function handleRequest(req, res, ctx) {
|
|
692
720
|
if (!isAllowedHostHeader(req.headers.host)) {
|
|
693
721
|
send2(res, 403, "forbidden host", "text/plain; charset=utf-8");
|
|
@@ -709,15 +737,47 @@ async function handleRequest(req, res, ctx) {
|
|
|
709
737
|
return;
|
|
710
738
|
}
|
|
711
739
|
if (method === "GET" && path === "/api/state") {
|
|
712
|
-
autoCleanupRuns({
|
|
740
|
+
autoCleanupRuns({ cleanStale: false });
|
|
713
741
|
sendJson(res, 200, {
|
|
714
|
-
...buildWebState(
|
|
742
|
+
...buildWebState(),
|
|
715
743
|
providers: listWebProviders(),
|
|
716
|
-
|
|
717
|
-
|
|
744
|
+
language: webLanguagePayload(),
|
|
745
|
+
version: REEVESAGENTS_VERSION
|
|
718
746
|
});
|
|
719
747
|
return;
|
|
720
748
|
}
|
|
749
|
+
if (method === "GET" && path === "/api/mcp-hosts") {
|
|
750
|
+
try {
|
|
751
|
+
sendJson(res, 200, mcpHostsPayload());
|
|
752
|
+
} catch (err) {
|
|
753
|
+
sendJson(res, 400, { error: errMessage(err) });
|
|
754
|
+
}
|
|
755
|
+
return;
|
|
756
|
+
}
|
|
757
|
+
if (method === "GET" && path === "/api/doctor") {
|
|
758
|
+
try {
|
|
759
|
+
sendJson(res, 200, runDoctor());
|
|
760
|
+
} catch (err) {
|
|
761
|
+
sendJson(res, 400, { error: errMessage(err) });
|
|
762
|
+
}
|
|
763
|
+
return;
|
|
764
|
+
}
|
|
765
|
+
if (method === "GET" && path === "/api/config") {
|
|
766
|
+
try {
|
|
767
|
+
sendJson(res, 200, configPayload());
|
|
768
|
+
} catch (err) {
|
|
769
|
+
sendJson(res, 400, { error: errMessage(err) });
|
|
770
|
+
}
|
|
771
|
+
return;
|
|
772
|
+
}
|
|
773
|
+
if (method === "GET" && path === "/api/presets") {
|
|
774
|
+
try {
|
|
775
|
+
sendJson(res, 200, presetsPayload());
|
|
776
|
+
} catch (err) {
|
|
777
|
+
sendJson(res, 400, { error: errMessage(err) });
|
|
778
|
+
}
|
|
779
|
+
return;
|
|
780
|
+
}
|
|
721
781
|
if (method === "GET" && path === "/api/events") {
|
|
722
782
|
ctx.sse.add(res);
|
|
723
783
|
return;
|
|
@@ -729,7 +789,7 @@ async function handleRequest(req, res, ctx) {
|
|
|
729
789
|
if (method === "POST" && path === "/api/terminals") {
|
|
730
790
|
try {
|
|
731
791
|
const body = await readJsonBody(req);
|
|
732
|
-
sendJson(res, 200, await createTerminal(body
|
|
792
|
+
sendJson(res, 200, await createTerminal(body));
|
|
733
793
|
} catch (err) {
|
|
734
794
|
sendJson(res, 400, { error: errMessage(err) });
|
|
735
795
|
}
|
|
@@ -744,12 +804,77 @@ async function handleRequest(req, res, ctx) {
|
|
|
744
804
|
}
|
|
745
805
|
return;
|
|
746
806
|
}
|
|
807
|
+
if (method === "POST" && path === "/api/mcp-hosts/attach") {
|
|
808
|
+
try {
|
|
809
|
+
const body = await readJsonBody(req);
|
|
810
|
+
sendJson(res, 200, attachMcpHostAction(body));
|
|
811
|
+
} catch (err) {
|
|
812
|
+
sendJson(res, 400, { error: errMessage(err) });
|
|
813
|
+
}
|
|
814
|
+
return;
|
|
815
|
+
}
|
|
816
|
+
if (method === "POST" && path === "/api/mcp-hosts/detach") {
|
|
817
|
+
try {
|
|
818
|
+
const body = await readJsonBody(req);
|
|
819
|
+
sendJson(res, 200, detachMcpHostAction(body));
|
|
820
|
+
} catch (err) {
|
|
821
|
+
sendJson(res, 400, { error: errMessage(err) });
|
|
822
|
+
}
|
|
823
|
+
return;
|
|
824
|
+
}
|
|
825
|
+
if (method === "POST" && path === "/api/mcp-hosts/attach-all") {
|
|
826
|
+
try {
|
|
827
|
+
sendJson(res, 200, attachAllMcpHostsAction());
|
|
828
|
+
} catch (err) {
|
|
829
|
+
sendJson(res, 400, { error: errMessage(err) });
|
|
830
|
+
}
|
|
831
|
+
return;
|
|
832
|
+
}
|
|
833
|
+
if (method === "POST" && path === "/api/config") {
|
|
834
|
+
try {
|
|
835
|
+
const body = await readJsonBody(req);
|
|
836
|
+
sendJson(res, 200, updateConfigAction(body));
|
|
837
|
+
} catch (err) {
|
|
838
|
+
sendJson(res, 400, { error: errMessage(err) });
|
|
839
|
+
}
|
|
840
|
+
return;
|
|
841
|
+
}
|
|
842
|
+
if (method === "POST" && path === "/api/presets/save") {
|
|
843
|
+
try {
|
|
844
|
+
const body = await readJsonBody(req);
|
|
845
|
+
sendJson(res, 200, savePresetAction(body));
|
|
846
|
+
} catch (err) {
|
|
847
|
+
sendJson(res, 400, { error: errMessage(err) });
|
|
848
|
+
}
|
|
849
|
+
return;
|
|
850
|
+
}
|
|
851
|
+
const startPresetMatch = path.match(/^\/api\/presets\/([^/]+)\/start$/);
|
|
852
|
+
if (method === "POST" && startPresetMatch) {
|
|
853
|
+
try {
|
|
854
|
+
sendJson(res, 200, startPresetAction(decodeURIComponent(startPresetMatch[1])));
|
|
855
|
+
} catch (err) {
|
|
856
|
+
sendJson(res, 400, { error: errMessage(err) });
|
|
857
|
+
}
|
|
858
|
+
return;
|
|
859
|
+
}
|
|
860
|
+
const deletePresetMatch = path.match(/^\/api\/presets\/([^/]+)\/delete$/);
|
|
861
|
+
if (method === "POST" && deletePresetMatch) {
|
|
862
|
+
try {
|
|
863
|
+
const body = await readJsonBody(req);
|
|
864
|
+
requireConfirm(body);
|
|
865
|
+
deletePresetAction(decodeURIComponent(deletePresetMatch[1]));
|
|
866
|
+
sendJson(res, 200, { ok: true });
|
|
867
|
+
} catch (err) {
|
|
868
|
+
sendJson(res, 400, { error: errMessage(err) });
|
|
869
|
+
}
|
|
870
|
+
return;
|
|
871
|
+
}
|
|
747
872
|
const killMatch = path.match(/^\/api\/terminals\/([^/]+)\/kill$/);
|
|
748
873
|
if (method === "POST" && killMatch) {
|
|
749
874
|
try {
|
|
750
875
|
const body = await readJsonBody(req);
|
|
751
876
|
requireConfirm(body);
|
|
752
|
-
killTerminal(decodeURIComponent(killMatch[1])
|
|
877
|
+
killTerminal(decodeURIComponent(killMatch[1]));
|
|
753
878
|
sendJson(res, 200, { ok: true });
|
|
754
879
|
} catch (err) {
|
|
755
880
|
sendJson(res, 400, { error: errMessage(err) });
|
|
@@ -761,7 +886,7 @@ async function handleRequest(req, res, ctx) {
|
|
|
761
886
|
try {
|
|
762
887
|
const body = await readJsonBody(req);
|
|
763
888
|
requireConfirm(body);
|
|
764
|
-
deleteTerminal(decodeURIComponent(deleteTerminalMatch[1])
|
|
889
|
+
deleteTerminal(decodeURIComponent(deleteTerminalMatch[1]));
|
|
765
890
|
sendJson(res, 200, { ok: true });
|
|
766
891
|
} catch (err) {
|
|
767
892
|
sendJson(res, 400, { error: errMessage(err) });
|
|
@@ -773,7 +898,7 @@ async function handleRequest(req, res, ctx) {
|
|
|
773
898
|
try {
|
|
774
899
|
const body = await readJsonBody(req);
|
|
775
900
|
requireConfirm(body);
|
|
776
|
-
stopWebRun(decodeURIComponent(stopMatch[1])
|
|
901
|
+
stopWebRun(decodeURIComponent(stopMatch[1]));
|
|
777
902
|
sendJson(res, 200, { ok: true });
|
|
778
903
|
} catch (err) {
|
|
779
904
|
sendJson(res, 400, { error: errMessage(err) });
|
|
@@ -785,7 +910,7 @@ async function handleRequest(req, res, ctx) {
|
|
|
785
910
|
try {
|
|
786
911
|
const body = await readJsonBody(req);
|
|
787
912
|
requireConfirm(body);
|
|
788
|
-
deleteWebRun(decodeURIComponent(deleteRunMatch[1])
|
|
913
|
+
deleteWebRun(decodeURIComponent(deleteRunMatch[1]));
|
|
789
914
|
sendJson(res, 200, { ok: true });
|
|
790
915
|
} catch (err) {
|
|
791
916
|
sendJson(res, 400, { error: errMessage(err) });
|
|
@@ -797,13 +922,23 @@ async function handleRequest(req, res, ctx) {
|
|
|
797
922
|
try {
|
|
798
923
|
const body = await readJsonBody(req);
|
|
799
924
|
requireConfirm(body);
|
|
800
|
-
deleteHistoryRecord(decodeURIComponent(deleteHistoryMatch[1])
|
|
925
|
+
deleteHistoryRecord(decodeURIComponent(deleteHistoryMatch[1]));
|
|
801
926
|
sendJson(res, 200, { ok: true });
|
|
802
927
|
} catch (err) {
|
|
803
928
|
sendJson(res, 400, { error: errMessage(err) });
|
|
804
929
|
}
|
|
805
930
|
return;
|
|
806
931
|
}
|
|
932
|
+
const resolveApprovalMatch = path.match(/^\/api\/approvals\/([^/]+)\/resolve$/);
|
|
933
|
+
if (method === "POST" && resolveApprovalMatch) {
|
|
934
|
+
try {
|
|
935
|
+
const body = await readJsonBody(req);
|
|
936
|
+
sendJson(res, 200, resolveApprovalAction(decodeURIComponent(resolveApprovalMatch[1]), body));
|
|
937
|
+
} catch (err) {
|
|
938
|
+
sendJson(res, 400, { error: errMessage(err) });
|
|
939
|
+
}
|
|
940
|
+
return;
|
|
941
|
+
}
|
|
807
942
|
send2(res, 404, "not found", "text/plain; charset=utf-8");
|
|
808
943
|
}
|
|
809
944
|
function listenWithFallback(server, basePort, range) {
|
|
@@ -831,19 +966,15 @@ async function startWebServer(options = {}) {
|
|
|
831
966
|
const basePort = options.port && Number.isFinite(options.port) ? options.port : DEFAULT_PORT;
|
|
832
967
|
const range = options.range && options.range > 0 ? options.range : DEFAULT_RANGE;
|
|
833
968
|
const webRoot = options.webRoot ?? DEFAULT_WEB_ROOT;
|
|
834
|
-
const prebetaOrchestrator = options.prebetaOrchestrator === true;
|
|
835
|
-
const orchestratorRuntime = prebetaOrchestrator ? await loadWebOrchestratorRuntime(options.orchestratorRuntime) : void 0;
|
|
836
969
|
const cache = /* @__PURE__ */ new Map();
|
|
837
|
-
const sse = createSseHub(
|
|
970
|
+
const sse = createSseHub();
|
|
838
971
|
const sockets = /* @__PURE__ */ new Set();
|
|
839
972
|
let boundPort = basePort;
|
|
840
973
|
const ctx = {
|
|
841
974
|
port: () => boundPort,
|
|
842
975
|
webRoot,
|
|
843
976
|
cache,
|
|
844
|
-
sse
|
|
845
|
-
prebetaOrchestrator,
|
|
846
|
-
orchestratorRuntime
|
|
977
|
+
sse
|
|
847
978
|
};
|
|
848
979
|
const server = createServer((req, res) => {
|
|
849
980
|
handleRequest(req, res, ctx).catch(() => {
|
|
@@ -857,7 +988,7 @@ async function startWebServer(options = {}) {
|
|
|
857
988
|
sockets.add(socket);
|
|
858
989
|
socket.on("close", () => sockets.delete(socket));
|
|
859
990
|
});
|
|
860
|
-
const bridge = attachTerminalBridge(server, () => boundPort
|
|
991
|
+
const bridge = attachTerminalBridge(server, () => boundPort);
|
|
861
992
|
boundPort = await listenWithFallback(server, basePort, range);
|
|
862
993
|
const url = `http://${HOST}:${boundPort}`;
|
|
863
994
|
if (options.open !== false) {
|
|
@@ -880,4 +1011,4 @@ async function startWebServer(options = {}) {
|
|
|
880
1011
|
export {
|
|
881
1012
|
startWebServer
|
|
882
1013
|
};
|
|
883
|
-
//# sourceMappingURL=server-
|
|
1014
|
+
//# sourceMappingURL=server-GYB53IBP.js.map
|