@agentdocumentformat/cli 0.7.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/LICENSE +21 -0
- package/README.md +45 -0
- package/dist/adf.mjs +162 -0
- package/dist/chunks/APEv2Parser-2CNNHMXV.mjs +22 -0
- package/dist/chunks/AiffParser-7BR4RL6G.mjs +162 -0
- package/dist/chunks/App-L5L37JI5.mjs +16747 -0
- package/dist/chunks/AsfParser-VVRSLFOM.mjs +538 -0
- package/dist/chunks/DsdiffParser-CMD4AX7A.mjs +156 -0
- package/dist/chunks/DsfParser-UOGZDS2M.mjs +94 -0
- package/dist/chunks/FlacParser-HB3T3CD4.mjs +23 -0
- package/dist/chunks/MP4Parser-66HBRUSX.mjs +973 -0
- package/dist/chunks/MatroskaParser-J3HUIMEW.mjs +579 -0
- package/dist/chunks/MpegParser-YW6LIUEW.mjs +442 -0
- package/dist/chunks/MusepackParser-PAUSXP7D.mjs +252 -0
- package/dist/chunks/OggParser-NUBV3GWC.mjs +359 -0
- package/dist/chunks/WavPackParser-WQAGT7TC.mjs +171 -0
- package/dist/chunks/WaveParser-EWLQVDX4.mjs +238 -0
- package/dist/chunks/adf-schema-JRU2BTOG.mjs +62 -0
- package/dist/chunks/build-QF5W473T.mjs +60 -0
- package/dist/chunks/chatgpt-subscription-BQGWYZXE.mjs +23 -0
- package/dist/chunks/chunk-2DIECGFL.mjs +6 -0
- package/dist/chunks/chunk-2NAP2ZF7.mjs +60 -0
- package/dist/chunks/chunk-3AT7IIP7.mjs +25696 -0
- package/dist/chunks/chunk-3GNIDM53.mjs +35 -0
- package/dist/chunks/chunk-3M4ZPOA3.mjs +1477 -0
- package/dist/chunks/chunk-4MQPTCXY.mjs +510 -0
- package/dist/chunks/chunk-5PO5PKRV.mjs +366 -0
- package/dist/chunks/chunk-5QU5VY7N.mjs +52 -0
- package/dist/chunks/chunk-5W7KES6P.mjs +436 -0
- package/dist/chunks/chunk-62NE4LG4.mjs +61 -0
- package/dist/chunks/chunk-64OKE4X3.mjs +45 -0
- package/dist/chunks/chunk-6GJ4QHRI.mjs +1278 -0
- package/dist/chunks/chunk-6VQEXLE2.mjs +144 -0
- package/dist/chunks/chunk-6XUV6EK6.mjs +41 -0
- package/dist/chunks/chunk-776TSXEP.mjs +43 -0
- package/dist/chunks/chunk-7CV2SA3H.mjs +285 -0
- package/dist/chunks/chunk-7MTRVW2U.mjs +3103 -0
- package/dist/chunks/chunk-7N2R2VCG.mjs +1434 -0
- package/dist/chunks/chunk-7T2YMTWL.mjs +374 -0
- package/dist/chunks/chunk-7XYNI52E.mjs +149 -0
- package/dist/chunks/chunk-APHX6HSV.mjs +7731 -0
- package/dist/chunks/chunk-APRU6PHC.mjs +40 -0
- package/dist/chunks/chunk-AUYKRQPJ.mjs +499 -0
- package/dist/chunks/chunk-DXWDD5XJ.mjs +136 -0
- package/dist/chunks/chunk-EWL5FG4I.mjs +39 -0
- package/dist/chunks/chunk-EYX2YLJW.mjs +117 -0
- package/dist/chunks/chunk-F5ELW46V.mjs +27 -0
- package/dist/chunks/chunk-G426FACA.mjs +49 -0
- package/dist/chunks/chunk-GEKSJHIV.mjs +2472 -0
- package/dist/chunks/chunk-HBUENVQL.mjs +570 -0
- package/dist/chunks/chunk-HPVFJYXR.mjs +112 -0
- package/dist/chunks/chunk-HWLWPXQ7.mjs +721 -0
- package/dist/chunks/chunk-I2HJYHFT.mjs +665 -0
- package/dist/chunks/chunk-I3UYSITV.mjs +68 -0
- package/dist/chunks/chunk-IC4JDZCI.mjs +3864 -0
- package/dist/chunks/chunk-IHDDCZBS.mjs +112 -0
- package/dist/chunks/chunk-IIGMZHQQ.mjs +10416 -0
- package/dist/chunks/chunk-KWFOS5WC.mjs +41 -0
- package/dist/chunks/chunk-LAZIXV2F.mjs +5290 -0
- package/dist/chunks/chunk-LFMB4PAA.mjs +10814 -0
- package/dist/chunks/chunk-M2RX3S2T.mjs +49 -0
- package/dist/chunks/chunk-M3WPIJYM.mjs +65 -0
- package/dist/chunks/chunk-NBTUWMGP.mjs +263 -0
- package/dist/chunks/chunk-NGK6PVSF.mjs +2676 -0
- package/dist/chunks/chunk-NZ7JTHEO.mjs +85 -0
- package/dist/chunks/chunk-OQN33RGQ.mjs +52 -0
- package/dist/chunks/chunk-RIX34QHC.mjs +2935 -0
- package/dist/chunks/chunk-SGUTYISF.mjs +16 -0
- package/dist/chunks/chunk-SLJ5L7PY.mjs +1473 -0
- package/dist/chunks/chunk-SLUKGXKH.mjs +68 -0
- package/dist/chunks/chunk-TMT32MXT.mjs +419 -0
- package/dist/chunks/chunk-UYY5M2PB.mjs +151 -0
- package/dist/chunks/chunk-VAUOM3IN.mjs +298 -0
- package/dist/chunks/chunk-VMHTYDH4.mjs +172 -0
- package/dist/chunks/chunk-VZS54AA5.mjs +200 -0
- package/dist/chunks/chunk-WFQUVXML.mjs +295 -0
- package/dist/chunks/chunk-X34PDRUH.mjs +809 -0
- package/dist/chunks/chunk-XNPZBLYL.mjs +33 -0
- package/dist/chunks/chunk-XX7OSWTO.mjs +157 -0
- package/dist/chunks/chunk-XYTWGHFS.mjs +600 -0
- package/dist/chunks/chunk-XYV3VCIX.mjs +336 -0
- package/dist/chunks/chunk-Y5ZLKFLE.mjs +1469 -0
- package/dist/chunks/chunk-ZJKXHM4Q.mjs +230 -0
- package/dist/chunks/cli-TCMBNZF6.mjs +1030 -0
- package/dist/chunks/commands-DTEKM4ZL.mjs +20 -0
- package/dist/chunks/daemon-ZC3FZ2P4.mjs +112449 -0
- package/dist/chunks/daemon-control-WDX7PMTC.mjs +300 -0
- package/dist/chunks/daemon-token-WRSULP7G.mjs +23 -0
- package/dist/chunks/devtools-H7CI2ZVG.mjs +85 -0
- package/dist/chunks/discord-IWDQJA7A.mjs +70588 -0
- package/dist/chunks/dist-C57KYFS2.mjs +4952 -0
- package/dist/chunks/dist-I3XBAGDL.mjs +11 -0
- package/dist/chunks/email-V4Q4VJON.mjs +58679 -0
- package/dist/chunks/environment-NX277MQG.mjs +15 -0
- package/dist/chunks/grok-subscription-4PYX7TBF.mjs +19 -0
- package/dist/chunks/layout-EPJQNFAI.mjs +22 -0
- package/dist/chunks/lib-N7FCZWKH.mjs +4038 -0
- package/dist/chunks/open-OTQDGDH5.mjs +36 -0
- package/dist/chunks/parser-JVY2PWSM.mjs +19 -0
- package/dist/chunks/pipeline-executor-BHBSJX2K.mjs +19 -0
- package/dist/chunks/react-IUIDQ5LX.mjs +11 -0
- package/dist/chunks/screen-54BUTYCW.mjs +27 -0
- package/dist/chunks/slack-3L5QTDZX.mjs +8113 -0
- package/dist/chunks/store-WR7TZJZS.mjs +32 -0
- package/dist/chunks/telegram-5ISVFBV3.mjs +14918 -0
- package/dist/chunks/terminal-O5WO7C5U.mjs +48 -0
- package/dist/chunks/theme-NORU4J74.mjs +20 -0
- package/dist/chunks/themes-F2FKU7CP.mjs +23 -0
- package/dist/chunks/token-6G3HCMNX.mjs +54 -0
- package/dist/chunks/token-util-UXYSDQIW.mjs +12 -0
- package/dist/chunks/tui-ODVYUIMT.mjs +197 -0
- package/dist/chunks/welcome-XHXFV7SH.mjs +32 -0
- package/dist/chunks/whatsapp-XSAMNGPJ.mjs +85412 -0
- package/dist/chunks/xterm-headless-YF53XWXE.mjs +3353 -0
- package/package.json +53 -0
- package/resources/wasm/coreutils.LICENSE +18 -0
- package/resources/wasm/coreutils.wasm +0 -0
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
import { createRequire as __adfCreateRequire } from 'node:module';
|
|
2
|
+
import { fileURLToPath as __adfFileURLToPath } from 'node:url';
|
|
3
|
+
import { dirname as __adfDirname } from 'node:path';
|
|
4
|
+
const require = __adfCreateRequire(import.meta.url);
|
|
5
|
+
const __filename = __adfFileURLToPath(import.meta.url);
|
|
6
|
+
const __dirname = __adfDirname(__filename);
|
|
7
|
+
import {
|
|
8
|
+
DEFAULT_DAEMON_URL,
|
|
9
|
+
resolveDaemonToken
|
|
10
|
+
} from "./chunk-G426FACA.mjs";
|
|
11
|
+
import {
|
|
12
|
+
defaultUserDataPath
|
|
13
|
+
} from "./chunk-IHDDCZBS.mjs";
|
|
14
|
+
import "./chunk-M2RX3S2T.mjs";
|
|
15
|
+
|
|
16
|
+
// src/main/cli/daemon-control.ts
|
|
17
|
+
import { spawn, execFileSync } from "node:child_process";
|
|
18
|
+
import { closeSync, existsSync, mkdirSync, openSync, readFileSync, statSync, readSync } from "node:fs";
|
|
19
|
+
import { homedir } from "node:os";
|
|
20
|
+
import { dirname, join, resolve } from "node:path";
|
|
21
|
+
import { fileURLToPath } from "node:url";
|
|
22
|
+
var DEFAULT_DAEMON_PORT = 7385, DEFAULT_MESH_PORT = 7295, START_TIMEOUT_MS = 9e4, STOP_TIMEOUT_MS = 3e4;
|
|
23
|
+
function daemonTarget(url) {
|
|
24
|
+
let host = "127.0.0.1", port = DEFAULT_DAEMON_PORT;
|
|
25
|
+
try {
|
|
26
|
+
let parsed = new URL(url);
|
|
27
|
+
host = parsed.hostname.replace(/^\[|\]$/g, ""), port = parsed.port ? Number(parsed.port) : parsed.protocol === "https:" ? 443 : 80;
|
|
28
|
+
} catch {
|
|
29
|
+
}
|
|
30
|
+
return { url: url.replace(/\/+$/, ""), host, port, loopback: isLoopbackHost(host) };
|
|
31
|
+
}
|
|
32
|
+
function isLoopbackHost(host) {
|
|
33
|
+
return host === "localhost" || host === "::1" || /^127\./.test(host);
|
|
34
|
+
}
|
|
35
|
+
function daemonPaths(port, env = process.env) {
|
|
36
|
+
let settingsFile = env.ADF_DAEMON_SETTINGS ?? join(defaultUserDataPath({ quiet: !0 }), "adf-settings.json"), dataDir = dirname(settingsFile), suffix = port === DEFAULT_DAEMON_PORT ? "" : `-${port}`;
|
|
37
|
+
return {
|
|
38
|
+
dataDir,
|
|
39
|
+
settingsFile,
|
|
40
|
+
pidFile: env.ADF_DAEMON_PIDFILE ?? join(dataDir, `adf-daemon${suffix}.pid`),
|
|
41
|
+
logFile: join(dataDir, "logs", `adf-daemon${suffix}.log`),
|
|
42
|
+
custom: !!(env.ADF_DAEMON_SETTINGS || env.ADF_USER_DATA_DIR)
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
async function isHealthy(url, fetchImpl = fetch, timeoutMs = 1500) {
|
|
46
|
+
try {
|
|
47
|
+
return (await fetchImpl(`${url}/health`, { signal: AbortSignal.timeout(timeoutMs) })).ok;
|
|
48
|
+
} catch {
|
|
49
|
+
return !1;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
function readPidFile(file) {
|
|
53
|
+
try {
|
|
54
|
+
let raw = readFileSync(file, "utf-8").trim();
|
|
55
|
+
if (raw.startsWith("{")) {
|
|
56
|
+
let parsed = JSON.parse(raw);
|
|
57
|
+
return typeof parsed.pid == "number" ? { pid: parsed.pid, startedAt: typeof parsed.startedAt == "number" ? parsed.startedAt : void 0 } : null;
|
|
58
|
+
}
|
|
59
|
+
let pid = Number.parseInt(raw, 10);
|
|
60
|
+
return Number.isFinite(pid) && pid > 0 ? { pid } : null;
|
|
61
|
+
} catch {
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
function processAlive(pid) {
|
|
66
|
+
try {
|
|
67
|
+
return process.kill(pid, 0), !0;
|
|
68
|
+
} catch (err) {
|
|
69
|
+
return err?.code === "EPERM";
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
function readJson(file) {
|
|
73
|
+
try {
|
|
74
|
+
return JSON.parse(readFileSync(file, "utf-8"));
|
|
75
|
+
} catch {
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
async function studioConflict(paths, env = process.env, fetchImpl = fetch) {
|
|
80
|
+
let settings = readJson(paths.settingsFile) ?? {}, meshPort = Number(env.MESH_PORT) || (typeof settings.meshPort == "number" ? settings.meshPort : DEFAULT_MESH_PORT), runtimeId = typeof settings.runtimeId == "string" ? settings.runtimeId : null;
|
|
81
|
+
if (runtimeId)
|
|
82
|
+
try {
|
|
83
|
+
let res = await fetchImpl(`http://127.0.0.1:${meshPort}/ping`, { signal: AbortSignal.timeout(800) });
|
|
84
|
+
if ((res.ok ? await res.json() : null)?.runtime_id === runtimeId)
|
|
85
|
+
return `Another ADF runtime on the same settings is already running (its mesh answers on 127.0.0.1:${meshPort}), most likely ADF Studio.`;
|
|
86
|
+
} catch {
|
|
87
|
+
}
|
|
88
|
+
return !paths.custom && studioProcessRunning() ? "ADF Studio is running." : null;
|
|
89
|
+
}
|
|
90
|
+
function studioProcessRunning() {
|
|
91
|
+
try {
|
|
92
|
+
if (process.platform === "win32") {
|
|
93
|
+
let out = execFileSync("tasklist", ["/FI", "IMAGENAME eq ADF Studio.exe", "/NH", "/FO", "CSV"], { encoding: "utf-8", windowsHide: !0, timeout: 4e3, stdio: ["ignore", "pipe", "ignore"] });
|
|
94
|
+
return /"ADF Studio\.exe"/i.test(out);
|
|
95
|
+
}
|
|
96
|
+
return process.platform === "darwin" ? (execFileSync("pgrep", ["-x", "ADF Studio"], { stdio: "ignore", timeout: 4e3 }), !0) : (execFileSync("pgrep", ["-f", "adf-studio"], { stdio: "ignore", timeout: 4e3 }), !0);
|
|
97
|
+
} catch {
|
|
98
|
+
return !1;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
var STUDIO_ADVICE = [
|
|
102
|
+
"Studio and the daemon would run the same agents from the same files at once.",
|
|
103
|
+
"Quit ADF Studio, then run adf again. Or keep using Studio.",
|
|
104
|
+
"(Different data on purpose? Point the daemon elsewhere with ADF_DAEMON_SETTINGS, or override with: adf daemon start --force)"
|
|
105
|
+
].join(`
|
|
106
|
+
`);
|
|
107
|
+
function daemonLaunch() {
|
|
108
|
+
let here = fileURLToPath(import.meta.url), source = /\.tsx?$/.test(here);
|
|
109
|
+
if (source) {
|
|
110
|
+
let root = resolve(dirname(here), "..", "..", "..");
|
|
111
|
+
return { command: process.execPath, args: [...process.execArgv, join(root, "src", "main", "cli", "bin.ts"), "daemon"], cwd: root, source, root };
|
|
112
|
+
}
|
|
113
|
+
let entry = process.argv[1];
|
|
114
|
+
return { command: process.execPath, args: [...process.execArgv, entry, "daemon"], cwd: homedir(), source };
|
|
115
|
+
}
|
|
116
|
+
var DaemonStartError = class extends Error {
|
|
117
|
+
constructor(message, advice) {
|
|
118
|
+
super(message);
|
|
119
|
+
this.advice = advice;
|
|
120
|
+
}
|
|
121
|
+
advice;
|
|
122
|
+
};
|
|
123
|
+
async function startDaemon(target, options = {}) {
|
|
124
|
+
let env = options.env ?? process.env, fetchImpl = options.fetch ?? fetch, log = options.log ?? ((text) => process.stderr.write(text));
|
|
125
|
+
if (!target.loopback) throw new DaemonStartError(`${target.url} is not on this machine; start the daemon there.`);
|
|
126
|
+
let paths = daemonPaths(target.port, env);
|
|
127
|
+
if (!options.force) {
|
|
128
|
+
let conflict = await studioConflict(paths, env, fetchImpl);
|
|
129
|
+
if (conflict) throw new DaemonStartError(conflict, STUDIO_ADVICE);
|
|
130
|
+
}
|
|
131
|
+
let existing = readPidFile(paths.pidFile);
|
|
132
|
+
if (existing && processAlive(existing.pid) && !await isHealthy(target.url, fetchImpl))
|
|
133
|
+
return log(`Waiting for the ADF daemon starting as pid ${existing.pid}\u2026
|
|
134
|
+
`), await waitHealthy(target.url, fetchImpl, START_TIMEOUT_MS, () => processAlive(existing.pid)), { pid: existing.pid, paths, ms: 0 };
|
|
135
|
+
mkdirSync(dirname(paths.logFile), { recursive: !0 });
|
|
136
|
+
let launch = daemonLaunch(), tty = process.stderr.isTTY, started = Date.now();
|
|
137
|
+
if (log(`Starting the ADF daemon on ${target.host}:${target.port}\u2026${tty ? "" : `
|
|
138
|
+
`}`), launch.source && launch.root) {
|
|
139
|
+
let script = join(launch.root, "scripts", "rebuild-for-node.mjs");
|
|
140
|
+
if (existsSync(script)) {
|
|
141
|
+
let fd = openSync(paths.logFile, "a");
|
|
142
|
+
try {
|
|
143
|
+
execFileSync(process.execPath, [script], { cwd: launch.root, stdio: ["ignore", fd, fd], windowsHide: !0, timeout: 18e4 });
|
|
144
|
+
} catch {
|
|
145
|
+
throw closeSync(fd), new DaemonStartError("Could not prepare better-sqlite3 for this Node.js.", `Run: node scripts/rebuild-for-node.mjs (details in ${paths.logFile})`);
|
|
146
|
+
}
|
|
147
|
+
closeSync(fd);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
let out = openSync(paths.logFile, "a"), childEnv = { ...env };
|
|
151
|
+
childEnv.ADF_NODE_ENV_DEFAULTED === "1" && (delete childEnv.NODE_ENV, delete childEnv.ADF_NODE_ENV_DEFAULTED);
|
|
152
|
+
let child = spawn(launch.command, launch.args, {
|
|
153
|
+
cwd: launch.cwd,
|
|
154
|
+
detached: !0,
|
|
155
|
+
windowsHide: !0,
|
|
156
|
+
stdio: ["ignore", out, out],
|
|
157
|
+
env: {
|
|
158
|
+
...childEnv,
|
|
159
|
+
ADF_DAEMON_PORT: String(target.port),
|
|
160
|
+
ADF_DAEMON_HOST: target.host === "localhost" ? "127.0.0.1" : target.host,
|
|
161
|
+
ADF_DAEMON_PIDFILE: paths.pidFile,
|
|
162
|
+
ADF_DAEMON_SETTINGS: paths.settingsFile
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
closeSync(out);
|
|
166
|
+
let exited = null;
|
|
167
|
+
child.once("exit", (code) => {
|
|
168
|
+
exited = code ?? -1;
|
|
169
|
+
}), child.unref();
|
|
170
|
+
let pid = child.pid ?? -1, tick = tty ? setInterval(() => log("."), 1e3) : null;
|
|
171
|
+
try {
|
|
172
|
+
if (!await waitHealthy(target.url, fetchImpl, START_TIMEOUT_MS, () => exited === null)) {
|
|
173
|
+
let tail = tailLines(paths.logFile, 15);
|
|
174
|
+
throw new DaemonStartError(
|
|
175
|
+
exited !== null ? `The daemon exited during startup (code ${exited}).` : `The daemon did not answer ${target.url}/health within ${START_TIMEOUT_MS / 1e3}s.`,
|
|
176
|
+
`Log: ${paths.logFile}${tail ? `
|
|
177
|
+
${tail}` : ""}`
|
|
178
|
+
);
|
|
179
|
+
}
|
|
180
|
+
} finally {
|
|
181
|
+
tick && clearInterval(tick), tty && log(`
|
|
182
|
+
`);
|
|
183
|
+
}
|
|
184
|
+
let ms = Date.now() - started;
|
|
185
|
+
return log(`ADF daemon running in the background (pid ${pid}, ${(ms / 1e3).toFixed(1)}s) \xB7 log ${paths.logFile}
|
|
186
|
+
`), { pid, paths, ms };
|
|
187
|
+
}
|
|
188
|
+
async function waitHealthy(url, fetchImpl, timeoutMs, alive) {
|
|
189
|
+
let deadline = Date.now() + timeoutMs;
|
|
190
|
+
for (; Date.now() < deadline; ) {
|
|
191
|
+
if (await isHealthy(url, fetchImpl, 1e3)) return !0;
|
|
192
|
+
if (!alive()) return !1;
|
|
193
|
+
await new Promise((r) => setTimeout(r, 250));
|
|
194
|
+
}
|
|
195
|
+
return !1;
|
|
196
|
+
}
|
|
197
|
+
async function ensureDaemon(url, options = {}) {
|
|
198
|
+
let env = options.env ?? process.env, fetchImpl = options.fetch ?? fetch, target = daemonTarget(url);
|
|
199
|
+
return await isHealthy(target.url, fetchImpl) || !target.loopback || options.disabled || env.ADF_NO_AUTOSTART === "1" ? null : await startDaemon(target, options);
|
|
200
|
+
}
|
|
201
|
+
async function stopDaemon(target, options = {}) {
|
|
202
|
+
let env = options.env ?? process.env, fetchImpl = options.fetch ?? fetch, paths = daemonPaths(target.port, env), record = readPidFile(paths.pidFile), token = resolveDaemonToken(void 0, env, target.url);
|
|
203
|
+
if (!await isHealthy(target.url, fetchImpl))
|
|
204
|
+
return record && processAlive(record.pid) ? { stopped: !1, message: `No daemon answers ${target.url}, but pid ${record.pid} from ${paths.pidFile} is alive. It may be starting or stuck; see adf daemon logs.` } : { stopped: !0, message: `No daemon running at ${target.url}.` };
|
|
205
|
+
let accepted = !1;
|
|
206
|
+
try {
|
|
207
|
+
let res = await fetchImpl(`${target.url}/daemon/shutdown`, { method: "POST", headers: token ? { Authorization: `Bearer ${token}` } : {}, signal: AbortSignal.timeout(5e3) });
|
|
208
|
+
if (accepted = res.ok, !res.ok && res.status !== 404)
|
|
209
|
+
return { stopped: !1, message: `The daemon refused to stop: ${(await res.json().catch(() => null))?.error ?? `HTTP ${res.status}`}` };
|
|
210
|
+
} catch {
|
|
211
|
+
}
|
|
212
|
+
if (!accepted) {
|
|
213
|
+
if (record && process.platform !== "win32" && processAlive(record.pid))
|
|
214
|
+
try {
|
|
215
|
+
process.kill(record.pid, "SIGTERM"), accepted = !0;
|
|
216
|
+
} catch {
|
|
217
|
+
}
|
|
218
|
+
if (!accepted)
|
|
219
|
+
return { stopped: !1, message: "This daemon has no stop endpoint (older build). Stop it with Ctrl+C in its terminal, or update it." };
|
|
220
|
+
}
|
|
221
|
+
let deadline = Date.now() + (options.timeoutMs ?? STOP_TIMEOUT_MS);
|
|
222
|
+
for (; Date.now() < deadline; ) {
|
|
223
|
+
let up = await isHealthy(target.url, fetchImpl, 800), alive = record ? processAlive(record.pid) : !1;
|
|
224
|
+
if (!up && !alive) return { stopped: !0, message: "ADF daemon stopped." };
|
|
225
|
+
await new Promise((r) => setTimeout(r, 300));
|
|
226
|
+
}
|
|
227
|
+
return { stopped: !1, message: `The daemon is still shutting down after ${(options.timeoutMs ?? STOP_TIMEOUT_MS) / 1e3}s (unloading agents, stopping containers). Check adf daemon logs.` };
|
|
228
|
+
}
|
|
229
|
+
async function daemonStatus(target, options = {}) {
|
|
230
|
+
let env = options.env ?? process.env, fetchImpl = options.fetch ?? fetch, paths = daemonPaths(target.port, env), running = await isHealthy(target.url, fetchImpl), record = readPidFile(paths.pidFile), lines = [`url ${target.url}`, `status ${running ? "running" : "not running"}`];
|
|
231
|
+
if (running)
|
|
232
|
+
try {
|
|
233
|
+
let token = resolveDaemonToken(void 0, env, target.url), body = await (await fetchImpl(`${target.url}/runtime`, { headers: token ? { Authorization: `Bearer ${token}` } : {}, signal: AbortSignal.timeout(3e3) })).json();
|
|
234
|
+
body.daemon?.pid && lines.push(`pid ${body.daemon.pid}`), typeof body.daemon?.uptime == "number" && lines.push(`uptime ${formatUptime(body.daemon.uptime)}`), body.daemon?.version && lines.push(`version ${body.daemon.version}`), Array.isArray(body.agents) && lines.push(`agents ${body.agents.length} loaded`);
|
|
235
|
+
} catch {
|
|
236
|
+
}
|
|
237
|
+
else record && processAlive(record.pid) && lines.push(`pid ${record.pid} (alive, not answering: starting or stuck)`);
|
|
238
|
+
return target.loopback && (lines.push(`data ${paths.dataDir}`), lines.push(`log ${paths.logFile}${existsSync(paths.logFile) ? "" : " (none yet)"}`)), { running, lines };
|
|
239
|
+
}
|
|
240
|
+
function formatUptime(seconds) {
|
|
241
|
+
let s = Math.floor(seconds), h = Math.floor(s / 3600), m = Math.floor(s % 3600 / 60);
|
|
242
|
+
return h > 0 ? `${h}h ${m}m` : m > 0 ? `${m}m ${s % 60}s` : `${s}s`;
|
|
243
|
+
}
|
|
244
|
+
function tailLines(file, count) {
|
|
245
|
+
try {
|
|
246
|
+
let size = statSync(file).size, len = Math.min(size, 64 * 1024), fd = openSync(file, "r"), buf = Buffer.alloc(len);
|
|
247
|
+
return readSync(fd, buf, 0, len, size - len), closeSync(fd), buf.toString("utf-8").split(/\r?\n/).filter(Boolean).slice(-count).join(`
|
|
248
|
+
`);
|
|
249
|
+
} catch {
|
|
250
|
+
return "";
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
async function followLog(file, options) {
|
|
254
|
+
let tail = tailLines(file, options.lines);
|
|
255
|
+
if (tail && options.write(`${tail}
|
|
256
|
+
`), !options.follow) return;
|
|
257
|
+
let offset = existsSync(file) ? statSync(file).size : 0;
|
|
258
|
+
for (; !options.signal?.aborted; ) {
|
|
259
|
+
await new Promise((r) => setTimeout(r, 500));
|
|
260
|
+
let size = 0;
|
|
261
|
+
try {
|
|
262
|
+
size = statSync(file).size;
|
|
263
|
+
} catch {
|
|
264
|
+
continue;
|
|
265
|
+
}
|
|
266
|
+
if (size < offset && (offset = 0), size === offset) continue;
|
|
267
|
+
let fd = openSync(file, "r"), buf = Buffer.alloc(size - offset);
|
|
268
|
+
readSync(fd, buf, 0, buf.length, offset), closeSync(fd), offset = size, options.write(buf.toString("utf-8"));
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
function daemonUrlFrom(args, env = process.env) {
|
|
272
|
+
let url, port, rest = [];
|
|
273
|
+
for (let i = 0; i < args.length; i++) {
|
|
274
|
+
let arg = args[i];
|
|
275
|
+
arg === "--url" || arg === "-u" ? url = args[++i] : arg.startsWith("--url=") ? url = arg.slice(6) : arg === "--port" || arg === "-p" ? port = args[++i] : arg.startsWith("--port=") ? port = arg.slice(7) : rest.push(arg);
|
|
276
|
+
}
|
|
277
|
+
if (url) return { url: url.replace(/\/+$/, ""), rest };
|
|
278
|
+
let p = port ?? env.ADF_DAEMON_PORT;
|
|
279
|
+
return p ? { url: `http://127.0.0.1:${p}`, rest } : { url: (env.ADF_DAEMON_URL ?? DEFAULT_DAEMON_URL).replace(/\/+$/, ""), rest };
|
|
280
|
+
}
|
|
281
|
+
export {
|
|
282
|
+
DEFAULT_DAEMON_PORT,
|
|
283
|
+
DaemonStartError,
|
|
284
|
+
STUDIO_ADVICE,
|
|
285
|
+
daemonLaunch,
|
|
286
|
+
daemonPaths,
|
|
287
|
+
daemonStatus,
|
|
288
|
+
daemonTarget,
|
|
289
|
+
daemonUrlFrom,
|
|
290
|
+
ensureDaemon,
|
|
291
|
+
followLog,
|
|
292
|
+
isHealthy,
|
|
293
|
+
isLoopbackHost,
|
|
294
|
+
processAlive,
|
|
295
|
+
readPidFile,
|
|
296
|
+
startDaemon,
|
|
297
|
+
stopDaemon,
|
|
298
|
+
studioConflict,
|
|
299
|
+
tailLines
|
|
300
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { createRequire as __adfCreateRequire } from 'node:module';
|
|
2
|
+
import { fileURLToPath as __adfFileURLToPath } from 'node:url';
|
|
3
|
+
import { dirname as __adfDirname } from 'node:path';
|
|
4
|
+
const require = __adfCreateRequire(import.meta.url);
|
|
5
|
+
const __filename = __adfFileURLToPath(import.meta.url);
|
|
6
|
+
const __dirname = __adfDirname(__filename);
|
|
7
|
+
import {
|
|
8
|
+
DAEMON_TOKEN_FILENAME,
|
|
9
|
+
daemonSettingsDir,
|
|
10
|
+
daemonTokenPath,
|
|
11
|
+
ensureDaemonToken,
|
|
12
|
+
readDaemonToken,
|
|
13
|
+
tokensEqual
|
|
14
|
+
} from "./chunk-IHDDCZBS.mjs";
|
|
15
|
+
import "./chunk-M2RX3S2T.mjs";
|
|
16
|
+
export {
|
|
17
|
+
DAEMON_TOKEN_FILENAME,
|
|
18
|
+
daemonSettingsDir,
|
|
19
|
+
daemonTokenPath,
|
|
20
|
+
ensureDaemonToken,
|
|
21
|
+
readDaemonToken,
|
|
22
|
+
tokensEqual
|
|
23
|
+
};
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { createRequire as __adfCreateRequire } from 'node:module';
|
|
2
|
+
import { fileURLToPath as __adfFileURLToPath } from 'node:url';
|
|
3
|
+
import { dirname as __adfDirname } from 'node:path';
|
|
4
|
+
const require = __adfCreateRequire(import.meta.url);
|
|
5
|
+
const __filename = __adfFileURLToPath(import.meta.url);
|
|
6
|
+
const __dirname = __adfDirname(__filename);
|
|
7
|
+
import {
|
|
8
|
+
wrapper_default
|
|
9
|
+
} from "./chunk-F5ELW46V.mjs";
|
|
10
|
+
import "./chunk-NGK6PVSF.mjs";
|
|
11
|
+
import "./chunk-M2RX3S2T.mjs";
|
|
12
|
+
|
|
13
|
+
// node_modules/ink/build/devtools-window-polyfill.js
|
|
14
|
+
var customGlobal = globalThis;
|
|
15
|
+
customGlobal.WebSocket ||= wrapper_default;
|
|
16
|
+
customGlobal.window ||= globalThis;
|
|
17
|
+
customGlobal.self ||= globalThis;
|
|
18
|
+
customGlobal.window.__REACT_DEVTOOLS_COMPONENT_FILTERS__ = [
|
|
19
|
+
{
|
|
20
|
+
// ComponentFilterElementType
|
|
21
|
+
type: 1,
|
|
22
|
+
// ElementTypeHostComponent
|
|
23
|
+
value: 7,
|
|
24
|
+
isEnabled: !0
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
// ComponentFilterDisplayName
|
|
28
|
+
type: 2,
|
|
29
|
+
value: "InternalApp",
|
|
30
|
+
isEnabled: !0,
|
|
31
|
+
isValid: !0
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
// ComponentFilterDisplayName
|
|
35
|
+
type: 2,
|
|
36
|
+
value: "InternalAppContext",
|
|
37
|
+
isEnabled: !0,
|
|
38
|
+
isValid: !0
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
// ComponentFilterDisplayName
|
|
42
|
+
type: 2,
|
|
43
|
+
value: "InternalStdoutContext",
|
|
44
|
+
isEnabled: !0,
|
|
45
|
+
isValid: !0
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
// ComponentFilterDisplayName
|
|
49
|
+
type: 2,
|
|
50
|
+
value: "InternalStderrContext",
|
|
51
|
+
isEnabled: !0,
|
|
52
|
+
isValid: !0
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
// ComponentFilterDisplayName
|
|
56
|
+
type: 2,
|
|
57
|
+
value: "InternalStdinContext",
|
|
58
|
+
isEnabled: !0,
|
|
59
|
+
isValid: !0
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
// ComponentFilterDisplayName
|
|
63
|
+
type: 2,
|
|
64
|
+
value: "InternalFocusContext",
|
|
65
|
+
isEnabled: !0,
|
|
66
|
+
isValid: !0
|
|
67
|
+
}
|
|
68
|
+
];
|
|
69
|
+
|
|
70
|
+
// node_modules/ink/build/devtools.js
|
|
71
|
+
import devtools from "react-devtools-core";
|
|
72
|
+
var isDevToolsReachable = async () => new Promise((resolve) => {
|
|
73
|
+
let socket = new wrapper_default("ws://localhost:8097"), timeout = setTimeout(() => {
|
|
74
|
+
socket.terminate(), resolve(!1);
|
|
75
|
+
}, 2e3);
|
|
76
|
+
timeout.unref(), socket.on("open", () => {
|
|
77
|
+
clearTimeout(timeout), socket.terminate(), resolve(!0);
|
|
78
|
+
}), socket.on("error", () => {
|
|
79
|
+
clearTimeout(timeout), socket.terminate(), resolve(!1);
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
await isDevToolsReachable() ? (devtools.initialize(), devtools.connectToDevTools()) : console.warn(`DEV is set to true, but the React DevTools server is not running. Start it with:
|
|
83
|
+
|
|
84
|
+
$ npx react-devtools
|
|
85
|
+
`);
|