hypeframe 0.8.1 → 0.9.0
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/README.md +2 -1
- package/dist/index.js +846 -377
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -243,6 +243,7 @@ var id = {
|
|
|
243
243
|
"agentLog.refused": "ditolak",
|
|
244
244
|
"agentLog.option": "{agent}: {what} diganti ke {value}",
|
|
245
245
|
"agentLog.stopped": "✦ {agent} berhenti (kode {code}). Obrolan baru menyalakannya lagi.",
|
|
246
|
+
"agentLog.account": "✦ Akun {agent} berganti: dimuat ulang, obrolan berikutnya memakai akun baru.",
|
|
246
247
|
"engine.agentsReady": "Asisten AI siap: {list}",
|
|
247
248
|
"engine.agentsNone": "Belum ada asisten AI. Pasang dari menu hypeframe > Asisten AI.",
|
|
248
249
|
"engine.statusHint": "Tekan Enter kapan saja untuk melihat status.",
|
|
@@ -292,7 +293,29 @@ Tekan Esc untuk melewati satu langkah. Panduan ini bisa dibuka lagi dari Bantuan
|
|
|
292
293
|
"agent.needLogin": "perlu masuk akun",
|
|
293
294
|
"agent.notInstalled": "belum dipasang",
|
|
294
295
|
"agent.add": "Pasang dan masuk akun",
|
|
295
|
-
"agent.login": "
|
|
296
|
+
"agent.login": "Ganti akun (keluar, lalu masuk dengan akun lain)",
|
|
297
|
+
"agent.logout": "Keluar akun",
|
|
298
|
+
"agent.ownApi": "Pakai URL API sendiri (alamat + kunci API)",
|
|
299
|
+
"agent.ownApiChange": "Ganti API sendiri ({host})",
|
|
300
|
+
"agent.ownApiOff": "Berhenti memakai API sendiri",
|
|
301
|
+
"agent.ownApiOffDone": "OpenCode kembali memakai penyedia bawaannya.",
|
|
302
|
+
"agent.ownApiTag": "API sendiri ({host})",
|
|
303
|
+
"agent.apiUrl": "Alamat API (kompatibel OpenAI, biasanya berakhiran /v1)",
|
|
304
|
+
"agent.apiUrlBad": "Alamat harus diawali http:// atau https://",
|
|
305
|
+
"agent.apiKey": "Kunci API (kosongkan kalau servernya tidak memakai kunci)",
|
|
306
|
+
"agent.apiModelsLoading": "Mengambil daftar model dari alamat itu...",
|
|
307
|
+
"agent.apiModelsFound": "{n} model ditemukan",
|
|
308
|
+
"agent.apiModelsNone": "Daftar model tidak bisa diambil, ketik nama modelnya",
|
|
309
|
+
"agent.apiModel": "Model utama (model lain di daftar tetap bisa dipilih di HypeFrame Web)",
|
|
310
|
+
"agent.apiModelType": "Nama model persis seperti di penyedianya (mis. gpt-4o-mini)",
|
|
311
|
+
"agent.apiSaved": "OpenCode memakai {host}, model {model}. Kunci disimpan di perangkat ini saja.",
|
|
312
|
+
"agent.apiNotReady": "OpenCode belum bisa membuka obrolan dengan API ini. Periksa alamat, kunci, dan nama modelnya, lalu coba lagi.",
|
|
313
|
+
"agent.logoutAsk": "Keluar dari akun {name} di perangkat ini?",
|
|
314
|
+
"agent.loggingOut": "Keluar dari akun {name}...",
|
|
315
|
+
"agent.loggedOut": "{name} sudah keluar akun. Pilih Masuk akun untuk memakai akun lain.",
|
|
316
|
+
"agent.keyRemoved": "Kunci {name} yang disimpan HypeFrame sudah dihapus.",
|
|
317
|
+
"agent.logoutUnsupported": "{name} tidak menyediakan keluar akun dari luar aplikasinya. Pilih Ganti akun: masuk dengan akun lain menggantikan akun lama.",
|
|
318
|
+
"agent.logoutRestart": "Mesin sedang menyala: matikan lalu nyalakan lagi supaya {name} berhenti memakai akun lama.",
|
|
296
319
|
"agent.remove": "Hapus dari perangkat ini",
|
|
297
320
|
"agent.back": "Kembali",
|
|
298
321
|
"agent.installing": "Memasang {name} dari daftar resmi ACP...",
|
|
@@ -491,6 +514,7 @@ var en = {
|
|
|
491
514
|
"agentLog.refused": "refused",
|
|
492
515
|
"agentLog.option": "{agent}: {what} changed to {value}",
|
|
493
516
|
"agentLog.stopped": "✦ {agent} stopped (code {code}). A new chat starts it again.",
|
|
517
|
+
"agentLog.account": "✦ {agent} account changed: reloaded, the next chat uses the new account.",
|
|
494
518
|
"engine.agentsReady": "AI assistants ready: {list}",
|
|
495
519
|
"engine.agentsNone": "No AI assistant yet. Add one from the hypeframe menu > AI assistant.",
|
|
496
520
|
"engine.statusHint": "Press Enter at any time to see the status.",
|
|
@@ -540,7 +564,29 @@ Press Esc to skip a step. You can open this guide again from Help & maintenance.
|
|
|
540
564
|
"agent.needLogin": "needs login",
|
|
541
565
|
"agent.notInstalled": "not installed",
|
|
542
566
|
"agent.add": "Install and log in",
|
|
543
|
-
"agent.login": "
|
|
567
|
+
"agent.login": "Switch account (sign out, then sign in with another account)",
|
|
568
|
+
"agent.logout": "Sign out",
|
|
569
|
+
"agent.ownApi": "Use your own API URL (address + API key)",
|
|
570
|
+
"agent.ownApiChange": "Change own API ({host})",
|
|
571
|
+
"agent.ownApiOff": "Stop using own API",
|
|
572
|
+
"agent.ownApiOffDone": "OpenCode is back on its own providers.",
|
|
573
|
+
"agent.ownApiTag": "own API ({host})",
|
|
574
|
+
"agent.apiUrl": "API address (OpenAI-compatible, usually ending in /v1)",
|
|
575
|
+
"agent.apiUrlBad": "The address must start with http:// or https://",
|
|
576
|
+
"agent.apiKey": "API key (leave empty if the server needs none)",
|
|
577
|
+
"agent.apiModelsLoading": "Getting the model list from that address...",
|
|
578
|
+
"agent.apiModelsFound": "{n} models found",
|
|
579
|
+
"agent.apiModelsNone": "Could not get the model list, type the model name",
|
|
580
|
+
"agent.apiModel": "Main model (the other models in the list stay pickable in HypeFrame Web)",
|
|
581
|
+
"agent.apiModelType": "Model name exactly as the provider calls it (e.g. gpt-4o-mini)",
|
|
582
|
+
"agent.apiSaved": "OpenCode uses {host}, model {model}. The key is kept on this device only.",
|
|
583
|
+
"agent.apiNotReady": "OpenCode cannot open a chat with this API yet. Check the address, key and model name, then try again.",
|
|
584
|
+
"agent.logoutAsk": "Sign out of {name} on this device?",
|
|
585
|
+
"agent.loggingOut": "Signing out of {name}...",
|
|
586
|
+
"agent.loggedOut": "{name} is signed out. Pick Log in to use another account.",
|
|
587
|
+
"agent.keyRemoved": "The {name} key saved by HypeFrame was removed.",
|
|
588
|
+
"agent.logoutUnsupported": "{name} offers no sign-out from outside its own app. Pick Switch account: signing in with another account replaces the old one.",
|
|
589
|
+
"agent.logoutRestart": "The engine is running: stop it and start it again so {name} stops using the old account.",
|
|
544
590
|
"agent.remove": "Remove from this device",
|
|
545
591
|
"agent.back": "Back",
|
|
546
592
|
"agent.installing": "Installing {name} from the official ACP registry...",
|
|
@@ -753,7 +799,7 @@ import readline3 from "node:readline";
|
|
|
753
799
|
|
|
754
800
|
// ../protocol/src/index.ts
|
|
755
801
|
var PROTOCOL_VERSION = 1;
|
|
756
|
-
var ALLOWED_KINDS = ["status", "kunci", "agen.mulai", "agen.kirim", "agen.izin", "agen.batal", "agen.opsi", "agen.riwayat", "render.relai"];
|
|
802
|
+
var ALLOWED_KINDS = ["status", "kunci", "agen.mulai", "agen.kirim", "agen.izin", "agen.batal", "agen.opsi", "agen.riwayat", "agen.akun", "render.relai"];
|
|
757
803
|
var CloseCode = {
|
|
758
804
|
BadHello: 4001,
|
|
759
805
|
Replaced: 4002,
|
|
@@ -776,12 +822,12 @@ var EngineError = {
|
|
|
776
822
|
|
|
777
823
|
// src/agent/service.ts
|
|
778
824
|
import crypto3 from "node:crypto";
|
|
779
|
-
import
|
|
780
|
-
import
|
|
825
|
+
import fs11 from "node:fs";
|
|
826
|
+
import path8 from "node:path";
|
|
781
827
|
// package.json
|
|
782
828
|
var package_default = {
|
|
783
829
|
name: "hypeframe",
|
|
784
|
-
version: "0.
|
|
830
|
+
version: "0.9.0",
|
|
785
831
|
description: "Local engine for HypeFrame Web: code clips, video renders and AI agents run on your own machine; the web is just the view.",
|
|
786
832
|
keywords: [
|
|
787
833
|
"hypeframe",
|
|
@@ -995,6 +1041,7 @@ function writeHelpers() {
|
|
|
995
1041
|
const open = `#!/bin/sh
|
|
996
1042
|
# HypeFrame: open a link in the phone's browser (the engine watches this file)
|
|
997
1043
|
[ -n "$1" ] || exit 0
|
|
1044
|
+
[ -n "$HF_TANPA_BUKA" ] && exit 0
|
|
998
1045
|
printf '%s\\n' "$1" >> "${openFile()}"
|
|
999
1046
|
`;
|
|
1000
1047
|
fs7.writeFileSync(path4.join(bin, "xdg-open"), open, { mode: 493 });
|
|
@@ -1065,10 +1112,8 @@ function watchOpenRequests(open, everyMs = 1000) {
|
|
|
1065
1112
|
return () => clearInterval(timer);
|
|
1066
1113
|
}
|
|
1067
1114
|
|
|
1068
|
-
// src/agent/
|
|
1069
|
-
import
|
|
1070
|
-
import fs8 from "node:fs";
|
|
1071
|
-
import path5 from "node:path";
|
|
1115
|
+
// src/agent/login.ts
|
|
1116
|
+
import { spawn as spawn2 } from "node:child_process";
|
|
1072
1117
|
|
|
1073
1118
|
// src/agent/acp.ts
|
|
1074
1119
|
import { spawn } from "node:child_process";
|
|
@@ -1083,12 +1128,17 @@ class RpcError extends Error {
|
|
|
1083
1128
|
this.data = data;
|
|
1084
1129
|
}
|
|
1085
1130
|
}
|
|
1086
|
-
function agentSpawn(agent, env = {}, extraArgs = []) {
|
|
1131
|
+
function agentSpawn(agent, env = {}, extraArgs = [], opts = {}) {
|
|
1132
|
+
const all = [...agent.launch.args, ...extraArgs];
|
|
1133
|
+
const inTerminal = (cmd) => `stty cols 400 rows 50 2>/dev/null; exec ${[cmd, ...all].map(shQuote).join(" ")}`;
|
|
1087
1134
|
if (agent.launch.linux) {
|
|
1088
|
-
const [cmd, args] = linuxCommand(agent.launch.cmd,
|
|
1135
|
+
const [cmd, args] = opts.pty ? linuxCommand("/usr/bin/script", ["-qfec", inTerminal(agent.launch.cmd), "/dev/null"], { ...agent.launch.env, ...env }) : linuxCommand(agent.launch.cmd, all, { ...agent.launch.env, ...env });
|
|
1089
1136
|
return [cmd, args, { ...process.env }];
|
|
1090
1137
|
}
|
|
1091
|
-
|
|
1138
|
+
const childEnv = { ...process.env, ...agent.launch.env, ...env };
|
|
1139
|
+
if (opts.pty && process.platform === "linux" && onPath("script"))
|
|
1140
|
+
return ["script", ["-qfec", inTerminal(agent.launch.cmd), "/dev/null"], childEnv];
|
|
1141
|
+
return [agent.launch.cmd, all, childEnv];
|
|
1092
1142
|
}
|
|
1093
1143
|
|
|
1094
1144
|
class AcpProcess extends EventEmitter {
|
|
@@ -1206,7 +1256,375 @@ class AcpProcess extends EventEmitter {
|
|
|
1206
1256
|
}
|
|
1207
1257
|
}
|
|
1208
1258
|
|
|
1259
|
+
// src/agent/store.ts
|
|
1260
|
+
import fs8 from "node:fs";
|
|
1261
|
+
import path5 from "node:path";
|
|
1262
|
+
function setReady(id, ready) {
|
|
1263
|
+
const a = readInstalled().find((x) => x.id === id);
|
|
1264
|
+
if (a)
|
|
1265
|
+
writeInstalled({ ...a, ready });
|
|
1266
|
+
}
|
|
1267
|
+
var AGENT_ID = /^[a-z0-9][a-z0-9-]{0,39}$/;
|
|
1268
|
+
var folder = (id) => {
|
|
1269
|
+
if (typeof id !== "string" || !AGENT_ID.test(id))
|
|
1270
|
+
throw new Error(`Invalid agent id: ${JSON.stringify(String(id)).slice(0, 60)}`);
|
|
1271
|
+
return path5.join(agentDir(), id);
|
|
1272
|
+
};
|
|
1273
|
+
function readInstalled() {
|
|
1274
|
+
const out = [];
|
|
1275
|
+
for (const id of fs8.readdirSync(agentDir())) {
|
|
1276
|
+
if (!AGENT_ID.test(id))
|
|
1277
|
+
continue;
|
|
1278
|
+
try {
|
|
1279
|
+
const a = JSON.parse(fs8.readFileSync(path5.join(folder(id), "agent.json"), "utf8"));
|
|
1280
|
+
if (a.id === id && a.launch?.cmd)
|
|
1281
|
+
out.push(a);
|
|
1282
|
+
} catch {}
|
|
1283
|
+
}
|
|
1284
|
+
return out;
|
|
1285
|
+
}
|
|
1286
|
+
function writeInstalled(a) {
|
|
1287
|
+
fs8.mkdirSync(folder(a.id), { recursive: true });
|
|
1288
|
+
const f = path5.join(folder(a.id), "agent.json");
|
|
1289
|
+
fs8.writeFileSync(`${f}.tmp`, JSON.stringify(a, null, 2));
|
|
1290
|
+
fs8.renameSync(`${f}.tmp`, f);
|
|
1291
|
+
}
|
|
1292
|
+
function removeAgent(id) {
|
|
1293
|
+
fs8.rmSync(folder(id), { recursive: true, force: true });
|
|
1294
|
+
}
|
|
1295
|
+
function agentEnv(id) {
|
|
1296
|
+
try {
|
|
1297
|
+
return JSON.parse(fs8.readFileSync(path5.join(folder(id), "env.json"), "utf8"));
|
|
1298
|
+
} catch {
|
|
1299
|
+
return {};
|
|
1300
|
+
}
|
|
1301
|
+
}
|
|
1302
|
+
var SECRET_NAME = /KEY|TOKEN|SECRET|PASSWORD/i;
|
|
1303
|
+
function forgetAgentSecrets(id) {
|
|
1304
|
+
const gone = Object.keys(agentEnv(id)).filter((k) => SECRET_NAME.test(k));
|
|
1305
|
+
removeAgentEnv(id, gone);
|
|
1306
|
+
return gone;
|
|
1307
|
+
}
|
|
1308
|
+
function removeAgentEnv(id, names) {
|
|
1309
|
+
const env = agentEnv(id);
|
|
1310
|
+
if (!names.some((k) => (k in env)))
|
|
1311
|
+
return;
|
|
1312
|
+
for (const k of names)
|
|
1313
|
+
delete env[k];
|
|
1314
|
+
const f = path5.join(folder(id), "env.json");
|
|
1315
|
+
fs8.writeFileSync(`${f}.tmp`, JSON.stringify(env), { mode: 384 });
|
|
1316
|
+
fs8.renameSync(`${f}.tmp`, f);
|
|
1317
|
+
}
|
|
1318
|
+
function saveAgentEnv(id, env) {
|
|
1319
|
+
fs8.mkdirSync(folder(id), { recursive: true });
|
|
1320
|
+
const f = path5.join(folder(id), "env.json");
|
|
1321
|
+
fs8.writeFileSync(`${f}.tmp`, JSON.stringify({ ...agentEnv(id), ...env }), { mode: 384 });
|
|
1322
|
+
fs8.renameSync(`${f}.tmp`, f);
|
|
1323
|
+
}
|
|
1324
|
+
|
|
1325
|
+
// src/agent/login.ts
|
|
1326
|
+
var SIGN_IN = /https?:\/\/[^\s"'<>]{8,2000}/g;
|
|
1327
|
+
var looksLikeSignIn = (u) => /oauth|auth|login|signin|sign-in|device|accounts\./i.test(u);
|
|
1328
|
+
function linkScanner(found) {
|
|
1329
|
+
const seen = new Set;
|
|
1330
|
+
let rest = "";
|
|
1331
|
+
return (text) => {
|
|
1332
|
+
rest += text;
|
|
1333
|
+
const end = rest.lastIndexOf(`
|
|
1334
|
+
`);
|
|
1335
|
+
if (end < 0)
|
|
1336
|
+
return void (rest = rest.slice(-4096));
|
|
1337
|
+
const lines = rest.slice(0, end);
|
|
1338
|
+
rest = rest.slice(end + 1);
|
|
1339
|
+
for (const u of lines.match(SIGN_IN) ?? [])
|
|
1340
|
+
if (looksLikeSignIn(u) && !seen.has(u))
|
|
1341
|
+
seen.add(u), found(u);
|
|
1342
|
+
};
|
|
1343
|
+
}
|
|
1344
|
+
function runAttached(cmd, args, env) {
|
|
1345
|
+
return new Promise((done) => {
|
|
1346
|
+
const child = spawn2(cmd, args, { stdio: "inherit", env });
|
|
1347
|
+
child.on("error", () => done(-1));
|
|
1348
|
+
child.on("exit", (code) => done(code));
|
|
1349
|
+
});
|
|
1350
|
+
}
|
|
1351
|
+
async function keyFromShell(name, io) {
|
|
1352
|
+
const value = process.env[name];
|
|
1353
|
+
if (!value)
|
|
1354
|
+
return null;
|
|
1355
|
+
if (io.confirm)
|
|
1356
|
+
return await io.confirm(t("agent.keyFromShellAsk", { name })) ? value : null;
|
|
1357
|
+
io.say(t("agent.keyFromShell", { name }));
|
|
1358
|
+
return value;
|
|
1359
|
+
}
|
|
1360
|
+
async function checkReady(id) {
|
|
1361
|
+
const a = readInstalled().find((x) => x.id === id);
|
|
1362
|
+
if (!a)
|
|
1363
|
+
return false;
|
|
1364
|
+
const proc = new AcpProcess;
|
|
1365
|
+
try {
|
|
1366
|
+
await proc.start(a, projectDir("_cek"), agentEnv(id));
|
|
1367
|
+
await proc.request("session/new", { cwd: projectDir("_cek"), mcpServers: [] }, 90000);
|
|
1368
|
+
setReady(id, true);
|
|
1369
|
+
return true;
|
|
1370
|
+
} catch {
|
|
1371
|
+
setReady(id, false);
|
|
1372
|
+
return false;
|
|
1373
|
+
} finally {
|
|
1374
|
+
await proc.stop();
|
|
1375
|
+
}
|
|
1376
|
+
}
|
|
1377
|
+
var isKey = (m) => m.type === "env_var" || !!m.varName;
|
|
1378
|
+
function pick(methods) {
|
|
1379
|
+
return methods.find((m) => m.type === "terminal") ?? methods.find((m) => (!m.type || m.type === "agent") && !isKey(m)) ?? methods.find(isKey);
|
|
1380
|
+
}
|
|
1381
|
+
async function logoutAgent(id) {
|
|
1382
|
+
const a = readInstalled().find((x) => x.id === id);
|
|
1383
|
+
if (!a)
|
|
1384
|
+
throw new Error(`Agent ${id} is not installed`);
|
|
1385
|
+
let signedOut = false;
|
|
1386
|
+
const proc = new AcpProcess;
|
|
1387
|
+
try {
|
|
1388
|
+
const init = await proc.start(a, projectDir("_cek"), agentEnv(id));
|
|
1389
|
+
if (init.agentCapabilities?.auth?.logout)
|
|
1390
|
+
signedOut = await proc.request("logout", {}, 60000).then(() => true, () => false) || false;
|
|
1391
|
+
} finally {
|
|
1392
|
+
await proc.stop();
|
|
1393
|
+
}
|
|
1394
|
+
const keys = forgetAgentSecrets(id).length > 0;
|
|
1395
|
+
if (!signedOut && !keys)
|
|
1396
|
+
return "unsupported";
|
|
1397
|
+
setReady(id, false);
|
|
1398
|
+
return signedOut ? "signed-out" : "key-removed";
|
|
1399
|
+
}
|
|
1400
|
+
async function loginAgent(id, io) {
|
|
1401
|
+
const a = readInstalled().find((x) => x.id === id);
|
|
1402
|
+
if (!a)
|
|
1403
|
+
throw new Error(`Agent ${id} is not installed`);
|
|
1404
|
+
const proc = new AcpProcess;
|
|
1405
|
+
let method;
|
|
1406
|
+
if (io.link)
|
|
1407
|
+
proc.on("stderr", linkScanner(io.link));
|
|
1408
|
+
try {
|
|
1409
|
+
const init = await proc.start(a, projectDir("_cek"), agentEnv(id));
|
|
1410
|
+
method = pick(init.authMethods ?? []);
|
|
1411
|
+
if (method && (!method.type || method.type === "agent") && !isKey(method))
|
|
1412
|
+
await proc.request("authenticate", { methodId: method.id }, 10 * 60000);
|
|
1413
|
+
} finally {
|
|
1414
|
+
await proc.stop();
|
|
1415
|
+
}
|
|
1416
|
+
if (method?.type === "terminal") {
|
|
1417
|
+
io.say(method.name || method.description || id);
|
|
1418
|
+
const [cmd, args, env] = agentSpawn(a, { ...agentEnv(id), ...method.env ?? {} }, method.args ?? []);
|
|
1419
|
+
if (await runAttached(cmd, args, env) !== 0)
|
|
1420
|
+
return setReady(id, false), false;
|
|
1421
|
+
} else if (method && isKey(method)) {
|
|
1422
|
+
const name = method.varName || method.id;
|
|
1423
|
+
const value = await keyFromShell(name, io) || await io.ask(name);
|
|
1424
|
+
if (!value)
|
|
1425
|
+
return false;
|
|
1426
|
+
saveAgentEnv(id, { [name]: value.trim() });
|
|
1427
|
+
}
|
|
1428
|
+
return checkReady(id);
|
|
1429
|
+
}
|
|
1430
|
+
var ANSI = /\x1b\[[0-9;?<>=]*[A-Za-z]|\x1b\][^\x07]*\x07|\r/g;
|
|
1431
|
+
var CODE_PROMPT = /paste the authorization code|authorization code|enter the code/i;
|
|
1432
|
+
var remote = new Map;
|
|
1433
|
+
|
|
1434
|
+
class RemoteLogin {
|
|
1435
|
+
id;
|
|
1436
|
+
state = { tahap: "mulai" };
|
|
1437
|
+
child;
|
|
1438
|
+
proc;
|
|
1439
|
+
text = "";
|
|
1440
|
+
ended = false;
|
|
1441
|
+
timer;
|
|
1442
|
+
constructor(id) {
|
|
1443
|
+
this.id = id;
|
|
1444
|
+
}
|
|
1445
|
+
async start() {
|
|
1446
|
+
const a = readInstalled().find((x) => x.id === this.id);
|
|
1447
|
+
if (!a)
|
|
1448
|
+
return this.fail("Agen belum dipasang di mesin ini.");
|
|
1449
|
+
if (a.launch.linux)
|
|
1450
|
+
writeHelpers();
|
|
1451
|
+
const env = { ...agentEnv(this.id), HF_TANPA_BUKA: "1" };
|
|
1452
|
+
this.timer = setTimeout(() => this.cancel("Waktu masuk habis (10 menit). Coba lagi."), 10 * 60000);
|
|
1453
|
+
this.timer.unref?.();
|
|
1454
|
+
const scan = linkScanner((u) => this.link(u));
|
|
1455
|
+
const proc = this.proc = new AcpProcess;
|
|
1456
|
+
proc.on("stderr", scan);
|
|
1457
|
+
let method;
|
|
1458
|
+
try {
|
|
1459
|
+
const init = await proc.start(a, projectDir("_cek"), env);
|
|
1460
|
+
method = pick(init.authMethods ?? []);
|
|
1461
|
+
if (method && (!method.type || method.type === "agent") && !isKey(method)) {
|
|
1462
|
+
this.state = { ...this.state, cara: "browser" };
|
|
1463
|
+
await proc.request("authenticate", { methodId: method.id }, 10 * 60000);
|
|
1464
|
+
await proc.stop();
|
|
1465
|
+
return this.finish();
|
|
1466
|
+
}
|
|
1467
|
+
} catch (e) {
|
|
1468
|
+
await proc.stop();
|
|
1469
|
+
return this.fail(e instanceof Error ? e.message : String(e));
|
|
1470
|
+
}
|
|
1471
|
+
await proc.stop();
|
|
1472
|
+
if (method?.type !== "terminal")
|
|
1473
|
+
return this.fail("Agen ini masuk dengan kunci API, bukan akun. Atur kuncinya di perangkat yang menjalankan mesin.");
|
|
1474
|
+
this.state = { ...this.state, cara: "kode" };
|
|
1475
|
+
const [cmd, args, childEnv] = agentSpawn(a, { ...env, ...method.env ?? {} }, method.args ?? [], { pty: true });
|
|
1476
|
+
const child = this.child = spawn2(cmd, args, { env: childEnv, stdio: ["pipe", "pipe", "pipe"], windowsHide: true });
|
|
1477
|
+
const feed = (d) => {
|
|
1478
|
+
const t = String(d).replace(ANSI, "");
|
|
1479
|
+
this.text = (this.text + t).slice(-8000);
|
|
1480
|
+
scan(t);
|
|
1481
|
+
if (CODE_PROMPT.test(this.text) && (this.state.tahap === "tautan" || this.state.tahap === "mulai") && this.state.tautan)
|
|
1482
|
+
this.state = { ...this.state, tahap: "kode" };
|
|
1483
|
+
};
|
|
1484
|
+
child.stdout?.on("data", feed);
|
|
1485
|
+
child.stderr?.on("data", feed);
|
|
1486
|
+
child.stdin?.on("error", () => {
|
|
1487
|
+
return;
|
|
1488
|
+
});
|
|
1489
|
+
child.on("error", (e) => this.fail(e.message));
|
|
1490
|
+
child.on("exit", (code) => code === 0 ? void this.finish() : this.fail(lastLines(this.text) || `Masuk berhenti (kode ${code}).`));
|
|
1491
|
+
}
|
|
1492
|
+
link(u) {
|
|
1493
|
+
if (this.ended || this.state.tautan)
|
|
1494
|
+
return;
|
|
1495
|
+
this.state = { ...this.state, tautan: u, tahap: CODE_PROMPT.test(this.text) && this.state.cara === "kode" ? "kode" : "tautan" };
|
|
1496
|
+
}
|
|
1497
|
+
sendCode(code) {
|
|
1498
|
+
const k = code.trim().slice(0, 2000);
|
|
1499
|
+
if (!k || !this.child || this.state.tahap !== "kode")
|
|
1500
|
+
throw new Error("Belum ada yang menunggu kode. Mulai masuk lagi.");
|
|
1501
|
+
this.child.stdin?.write(`${k}\r`);
|
|
1502
|
+
this.state = { ...this.state, tahap: "cek" };
|
|
1503
|
+
}
|
|
1504
|
+
async finish() {
|
|
1505
|
+
if (this.ended)
|
|
1506
|
+
return;
|
|
1507
|
+
this.state = { ...this.state, tahap: "cek" };
|
|
1508
|
+
const ok = await checkReady(this.id);
|
|
1509
|
+
this.end(ok ? { tahap: "selesai" } : { tahap: "gagal", pesan: "Masuk selesai, tapi agen belum bisa membuka obrolan. Coba lagi." });
|
|
1510
|
+
}
|
|
1511
|
+
fail(pesan) {
|
|
1512
|
+
if (this.ended)
|
|
1513
|
+
return;
|
|
1514
|
+
setReady(this.id, false);
|
|
1515
|
+
this.end({ ...this.state, tahap: "gagal", pesan: pesan.slice(0, 400) });
|
|
1516
|
+
}
|
|
1517
|
+
cancel(pesan = "Masuk dibatalkan.") {
|
|
1518
|
+
this.child?.kill();
|
|
1519
|
+
this.proc?.stop();
|
|
1520
|
+
this.fail(pesan);
|
|
1521
|
+
}
|
|
1522
|
+
end(s) {
|
|
1523
|
+
this.ended = true;
|
|
1524
|
+
clearTimeout(this.timer);
|
|
1525
|
+
this.state = s;
|
|
1526
|
+
}
|
|
1527
|
+
get done() {
|
|
1528
|
+
return this.ended;
|
|
1529
|
+
}
|
|
1530
|
+
}
|
|
1531
|
+
function lastLines(t) {
|
|
1532
|
+
return t.split(`
|
|
1533
|
+
`).map((l) => l.trim()).filter((l) => l && !/^https?:\/\//.test(l)).slice(-2).join(" ").slice(0, 300);
|
|
1534
|
+
}
|
|
1535
|
+
function startRemoteLogin(id) {
|
|
1536
|
+
const old = remote.get(id);
|
|
1537
|
+
if (old && !old.done)
|
|
1538
|
+
return old.state;
|
|
1539
|
+
const r = new RemoteLogin(id);
|
|
1540
|
+
remote.set(id, r);
|
|
1541
|
+
r.start();
|
|
1542
|
+
return r.state;
|
|
1543
|
+
}
|
|
1544
|
+
var remoteLoginState = (id) => remote.get(id)?.state ?? null;
|
|
1545
|
+
function sendRemoteCode(id, code) {
|
|
1546
|
+
const r = remote.get(id);
|
|
1547
|
+
if (!r)
|
|
1548
|
+
throw new Error("Belum ada yang menunggu kode. Mulai masuk lagi.");
|
|
1549
|
+
r.sendCode(code);
|
|
1550
|
+
return r.state;
|
|
1551
|
+
}
|
|
1552
|
+
function cancelRemoteLogin(id) {
|
|
1553
|
+
const r = remote.get(id);
|
|
1554
|
+
if (r && !r.done)
|
|
1555
|
+
r.cancel();
|
|
1556
|
+
}
|
|
1557
|
+
|
|
1558
|
+
// src/agent/opencode.ts
|
|
1559
|
+
import fs9 from "node:fs";
|
|
1560
|
+
import path6 from "node:path";
|
|
1561
|
+
var OPENCODE = "opencode";
|
|
1562
|
+
var OPENCODE_KEY = "HF_OPENCODE_KEY";
|
|
1563
|
+
var PROVIDER = "hypeframe";
|
|
1564
|
+
var configFile = () => path6.join(dataDir(), "opencode.json");
|
|
1565
|
+
var cleanUrl = (u) => u.trim().replace(/\/+$/, "");
|
|
1566
|
+
function saveOpencodeApi(api) {
|
|
1567
|
+
const url = cleanUrl(api.url);
|
|
1568
|
+
if (!/^https?:\/\/[^\s/]+/i.test(url))
|
|
1569
|
+
throw new Error("The API address must start with http:// or https://");
|
|
1570
|
+
const models = [...new Set(api.models.map((m) => m.trim()).filter(Boolean))].slice(0, 50);
|
|
1571
|
+
if (!models.length)
|
|
1572
|
+
throw new Error("Pick at least one model");
|
|
1573
|
+
const key = api.key.trim();
|
|
1574
|
+
const config = {
|
|
1575
|
+
$schema: "https://opencode.ai/config.json",
|
|
1576
|
+
provider: {
|
|
1577
|
+
[PROVIDER]: {
|
|
1578
|
+
npm: "@ai-sdk/openai-compatible",
|
|
1579
|
+
name: (api.name || new URL(url).hostname).slice(0, 60),
|
|
1580
|
+
options: { baseURL: url, ...key ? { apiKey: `{env:${OPENCODE_KEY}}` } : {} },
|
|
1581
|
+
models: Object.fromEntries(models.map((m) => [m, { name: m }]))
|
|
1582
|
+
}
|
|
1583
|
+
},
|
|
1584
|
+
model: `${PROVIDER}/${models[0]}`
|
|
1585
|
+
};
|
|
1586
|
+
const f = configFile();
|
|
1587
|
+
fs9.writeFileSync(`${f}.tmp`, `${JSON.stringify(config, null, 2)}
|
|
1588
|
+
`, { mode: 384 });
|
|
1589
|
+
fs9.renameSync(`${f}.tmp`, f);
|
|
1590
|
+
if (key)
|
|
1591
|
+
saveAgentEnv(OPENCODE, { [OPENCODE_KEY]: key, OPENCODE_CONFIG: f });
|
|
1592
|
+
else
|
|
1593
|
+
removeAgentEnv(OPENCODE, [OPENCODE_KEY]), saveAgentEnv(OPENCODE, { OPENCODE_CONFIG: f });
|
|
1594
|
+
return f;
|
|
1595
|
+
}
|
|
1596
|
+
function opencodeApi() {
|
|
1597
|
+
try {
|
|
1598
|
+
const c = JSON.parse(fs9.readFileSync(configFile(), "utf8"));
|
|
1599
|
+
const p = c?.provider?.[PROVIDER];
|
|
1600
|
+
if (!p?.options?.baseURL)
|
|
1601
|
+
return null;
|
|
1602
|
+
return { url: String(p.options.baseURL), name: String(p.name ?? ""), model: String(c.model ?? "").replace(`${PROVIDER}/`, "") };
|
|
1603
|
+
} catch {
|
|
1604
|
+
return null;
|
|
1605
|
+
}
|
|
1606
|
+
}
|
|
1607
|
+
function removeOpencodeApi() {
|
|
1608
|
+
fs9.rmSync(configFile(), { force: true });
|
|
1609
|
+
removeAgentEnv(OPENCODE, [OPENCODE_KEY, "OPENCODE_CONFIG"]);
|
|
1610
|
+
}
|
|
1611
|
+
async function fetchApiModels(url, key, timeoutMs = 1e4) {
|
|
1612
|
+
try {
|
|
1613
|
+
const r = await fetch(`${cleanUrl(url)}/models`, { headers: key.trim() ? { authorization: `Bearer ${key.trim()}` } : {}, signal: AbortSignal.timeout(timeoutMs) });
|
|
1614
|
+
if (!r.ok)
|
|
1615
|
+
return [];
|
|
1616
|
+
const j = await r.json();
|
|
1617
|
+
const ids = (Array.isArray(j?.data) ? j.data : []).map((m) => typeof m?.id === "string" ? m.id : "").filter((x) => x && x.length < 200);
|
|
1618
|
+
return [...new Set(ids)].sort();
|
|
1619
|
+
} catch {
|
|
1620
|
+
return [];
|
|
1621
|
+
}
|
|
1622
|
+
}
|
|
1623
|
+
|
|
1209
1624
|
// src/agent/session.ts
|
|
1625
|
+
import crypto2 from "node:crypto";
|
|
1626
|
+
import fs10 from "node:fs";
|
|
1627
|
+
import path7 from "node:path";
|
|
1210
1628
|
var UNSAFE_MODE = /bypass|dont.?ask|accept.?edits|yolo|full.?access|danger/i;
|
|
1211
1629
|
var SAFE_MODES = ["default", "ask"];
|
|
1212
1630
|
var MAX_READ = 10 * 1024 * 1024;
|
|
@@ -1229,7 +1647,7 @@ function splitId(id) {
|
|
|
1229
1647
|
}
|
|
1230
1648
|
var lexists = (p) => {
|
|
1231
1649
|
try {
|
|
1232
|
-
|
|
1650
|
+
fs10.lstatSync(p);
|
|
1233
1651
|
return true;
|
|
1234
1652
|
} catch {
|
|
1235
1653
|
return false;
|
|
@@ -1238,16 +1656,16 @@ var lexists = (p) => {
|
|
|
1238
1656
|
function insideFolder(folder, p) {
|
|
1239
1657
|
if (typeof p !== "string" || !p)
|
|
1240
1658
|
return false;
|
|
1241
|
-
const abs =
|
|
1242
|
-
const rel =
|
|
1243
|
-
if (rel.startsWith("..") ||
|
|
1659
|
+
const abs = path7.resolve(folder, p);
|
|
1660
|
+
const rel = path7.relative(folder, abs);
|
|
1661
|
+
if (rel.startsWith("..") || path7.isAbsolute(rel))
|
|
1244
1662
|
return false;
|
|
1245
1663
|
let probe = abs;
|
|
1246
|
-
while (!lexists(probe) &&
|
|
1247
|
-
probe =
|
|
1664
|
+
while (!lexists(probe) && path7.dirname(probe) !== probe)
|
|
1665
|
+
probe = path7.dirname(probe);
|
|
1248
1666
|
try {
|
|
1249
|
-
const r =
|
|
1250
|
-
return !(r.startsWith("..") ||
|
|
1667
|
+
const r = path7.relative(fs10.realpathSync(folder), fs10.realpathSync(probe));
|
|
1668
|
+
return !(r.startsWith("..") || path7.isAbsolute(r));
|
|
1251
1669
|
} catch {
|
|
1252
1670
|
return false;
|
|
1253
1671
|
}
|
|
@@ -1285,8 +1703,14 @@ class AgentSessions {
|
|
|
1285
1703
|
const proc = new AcpProcess;
|
|
1286
1704
|
proc.onRequest = (m, p) => this.fromAgent(agentId, m, p);
|
|
1287
1705
|
proc.onNotification = (m, p) => {
|
|
1288
|
-
if (m
|
|
1289
|
-
|
|
1706
|
+
if (m !== "session/update")
|
|
1707
|
+
return;
|
|
1708
|
+
const key = `${agentId}/${String(p?.sessionId ?? "")}`;
|
|
1709
|
+
const u = p?.update;
|
|
1710
|
+
const s = this.sessions.get(key);
|
|
1711
|
+
if (s && /^config_options?_update$/.test(String(u?.sessionUpdate ?? "")) && Array.isArray(u?.configOptions))
|
|
1712
|
+
s.opsi = { ...s.opsi, configOptions: safeConfig(u.configOptions) };
|
|
1713
|
+
this.queue(key, u);
|
|
1290
1714
|
};
|
|
1291
1715
|
proc.on("exit", (code) => {
|
|
1292
1716
|
if (this.procs.get(agentId)?.proc === proc)
|
|
@@ -1298,8 +1722,8 @@ class AgentSessions {
|
|
|
1298
1722
|
}
|
|
1299
1723
|
this.o.onExit(agentId, code);
|
|
1300
1724
|
});
|
|
1301
|
-
const cwd =
|
|
1302
|
-
|
|
1725
|
+
const cwd = path7.join(agentDir(), agentId, "kerja");
|
|
1726
|
+
fs10.mkdirSync(cwd, { recursive: true });
|
|
1303
1727
|
const p = proc.start(agent, cwd, this.o.env?.(agentId) ?? {}, this.o.startTimeoutMs ?? 180000).then((init) => {
|
|
1304
1728
|
const entry = { proc, init };
|
|
1305
1729
|
this.procs.set(agentId, entry);
|
|
@@ -1311,7 +1735,7 @@ class AgentSessions {
|
|
|
1311
1735
|
this.starting.set(agentId, p);
|
|
1312
1736
|
return p;
|
|
1313
1737
|
}
|
|
1314
|
-
async open({ agentId, projectId, resumeId }) {
|
|
1738
|
+
async open({ agentId, projectId, resumeId, onRoute }) {
|
|
1315
1739
|
const { proc, init } = await this.process(agentId);
|
|
1316
1740
|
const [resumeAgent, resumeOwn] = resumeId ? splitId(resumeId) : ["", ""];
|
|
1317
1741
|
const resume = resumeOwn && (!resumeAgent || resumeAgent === agentId) ? resumeOwn : "";
|
|
@@ -1320,8 +1744,9 @@ class AgentSessions {
|
|
|
1320
1744
|
if (live)
|
|
1321
1745
|
return { sessionId: key(resume), init, raw: {}, dimuat: "hidup", routeId: live.routeId, opsi: live.opsi ?? {} };
|
|
1322
1746
|
const cwd = projectDir(projectId);
|
|
1323
|
-
|
|
1747
|
+
fs10.writeFileSync(path7.join(cwd, "AGENTS.md"), AGENTS_MD);
|
|
1324
1748
|
const routeId = crypto2.randomBytes(9).toString("base64url");
|
|
1749
|
+
onRoute?.(routeId);
|
|
1325
1750
|
const params = { cwd, mcpServers: this.o.mcpServers(cwd, projectId, routeId, this.o.agent(agentId)) };
|
|
1326
1751
|
const limit = this.o.sessionTimeoutMs ?? 90000;
|
|
1327
1752
|
let raw;
|
|
@@ -1387,9 +1812,17 @@ class AgentSessions {
|
|
|
1387
1812
|
const e = this.procs.get(s.agentId);
|
|
1388
1813
|
if (!e)
|
|
1389
1814
|
throw new Error("Agent stopped");
|
|
1390
|
-
|
|
1815
|
+
let id = String(o.id ?? "").slice(0, 100);
|
|
1391
1816
|
const value = String(o.nilai ?? "").slice(0, 200);
|
|
1392
|
-
const
|
|
1817
|
+
const current = s.opsi?.configOptions ?? [];
|
|
1818
|
+
let config = current.find((c) => c.id === id);
|
|
1819
|
+
if (!config && current.length && o.jenis !== "model" && o.jenis !== "mode") {
|
|
1820
|
+
const hint = String(o.nama ?? "").trim().toLowerCase();
|
|
1821
|
+
config = hint ? current.find((c) => String(c.name ?? "").trim().toLowerCase() === hint || String(c.category ?? "").toLowerCase() === hint) : undefined;
|
|
1822
|
+
if (!config)
|
|
1823
|
+
throw new Error("This choice is no longer offered by the agent. Start a new chat to see its current choices.");
|
|
1824
|
+
id = String(config.id);
|
|
1825
|
+
}
|
|
1393
1826
|
const modeLike = o.jenis === "mode" || o.jenis !== "model" && (isModeOption(config) || /mode/i.test(id));
|
|
1394
1827
|
if (modeLike && UNSAFE_MODE.test(value))
|
|
1395
1828
|
throw new Error("A mode that skips asking is not allowed in HypeFrame");
|
|
@@ -1433,6 +1866,13 @@ class AgentSessions {
|
|
|
1433
1866
|
async stopAll() {
|
|
1434
1867
|
await Promise.all([...this.procs.values()].map(({ proc }) => proc.stop()));
|
|
1435
1868
|
}
|
|
1869
|
+
async stopAgent(agentId) {
|
|
1870
|
+
const e = this.procs.get(agentId);
|
|
1871
|
+
if (!e)
|
|
1872
|
+
return false;
|
|
1873
|
+
await e.proc.stop();
|
|
1874
|
+
return true;
|
|
1875
|
+
}
|
|
1436
1876
|
queue(sessionId, update) {
|
|
1437
1877
|
const s = this.sessions.get(sessionId);
|
|
1438
1878
|
if (!s || update === undefined)
|
|
@@ -1473,12 +1913,12 @@ class AgentSessions {
|
|
|
1473
1913
|
if (method === "fs/read_text_file") {
|
|
1474
1914
|
if (!insideFolder(s.cwd, p.path))
|
|
1475
1915
|
throw new RpcError(-32602, OUTSIDE);
|
|
1476
|
-
const st =
|
|
1916
|
+
const st = fs10.statSync(path7.resolve(s.cwd, p.path), { throwIfNoEntry: false });
|
|
1477
1917
|
if (!st?.isFile())
|
|
1478
1918
|
throw new RpcError(-32602, "Not a regular file");
|
|
1479
1919
|
if (st.size > MAX_READ)
|
|
1480
1920
|
throw new RpcError(-32602, "File too large (over 10 MB)");
|
|
1481
|
-
let content =
|
|
1921
|
+
let content = fs10.readFileSync(path7.resolve(s.cwd, p.path), "utf8");
|
|
1482
1922
|
if (p.line || p.limit) {
|
|
1483
1923
|
const lines = content.split(`
|
|
1484
1924
|
`);
|
|
@@ -1491,66 +1931,23 @@ class AgentSessions {
|
|
|
1491
1931
|
if (method === "fs/write_text_file") {
|
|
1492
1932
|
if (!insideFolder(s.cwd, p.path))
|
|
1493
1933
|
throw new RpcError(-32602, OUTSIDE);
|
|
1494
|
-
const f =
|
|
1495
|
-
|
|
1496
|
-
|
|
1934
|
+
const f = path7.resolve(s.cwd, p.path);
|
|
1935
|
+
fs10.mkdirSync(path7.dirname(f), { recursive: true });
|
|
1936
|
+
fs10.writeFileSync(f, String(p.content ?? ""));
|
|
1497
1937
|
return null;
|
|
1498
1938
|
}
|
|
1499
1939
|
throw new RpcError(-32601, `Method not found: ${method}`);
|
|
1500
1940
|
}
|
|
1501
1941
|
}
|
|
1502
1942
|
|
|
1503
|
-
// src/agent/
|
|
1504
|
-
|
|
1505
|
-
import path6 from "node:path";
|
|
1506
|
-
function setReady(id, ready) {
|
|
1507
|
-
const a = readInstalled().find((x) => x.id === id);
|
|
1508
|
-
if (a)
|
|
1509
|
-
writeInstalled({ ...a, ready });
|
|
1510
|
-
}
|
|
1511
|
-
var AGENT_ID = /^[a-z0-9][a-z0-9-]{0,39}$/;
|
|
1512
|
-
var folder = (id) => {
|
|
1513
|
-
if (typeof id !== "string" || !AGENT_ID.test(id))
|
|
1514
|
-
throw new Error(`Invalid agent id: ${JSON.stringify(String(id)).slice(0, 60)}`);
|
|
1515
|
-
return path6.join(agentDir(), id);
|
|
1516
|
-
};
|
|
1517
|
-
function readInstalled() {
|
|
1518
|
-
const out = [];
|
|
1519
|
-
for (const id of fs9.readdirSync(agentDir())) {
|
|
1520
|
-
if (!AGENT_ID.test(id))
|
|
1521
|
-
continue;
|
|
1522
|
-
try {
|
|
1523
|
-
const a = JSON.parse(fs9.readFileSync(path6.join(folder(id), "agent.json"), "utf8"));
|
|
1524
|
-
if (a.id === id && a.launch?.cmd)
|
|
1525
|
-
out.push(a);
|
|
1526
|
-
} catch {}
|
|
1527
|
-
}
|
|
1528
|
-
return out;
|
|
1529
|
-
}
|
|
1530
|
-
function writeInstalled(a) {
|
|
1531
|
-
fs9.mkdirSync(folder(a.id), { recursive: true });
|
|
1532
|
-
const f = path6.join(folder(a.id), "agent.json");
|
|
1533
|
-
fs9.writeFileSync(`${f}.tmp`, JSON.stringify(a, null, 2));
|
|
1534
|
-
fs9.renameSync(`${f}.tmp`, f);
|
|
1535
|
-
}
|
|
1536
|
-
function removeAgent(id) {
|
|
1537
|
-
fs9.rmSync(folder(id), { recursive: true, force: true });
|
|
1538
|
-
}
|
|
1539
|
-
function agentEnv(id) {
|
|
1943
|
+
// src/agent/service.ts
|
|
1944
|
+
var hostOf = (u) => {
|
|
1540
1945
|
try {
|
|
1541
|
-
return
|
|
1946
|
+
return new URL(u).host;
|
|
1542
1947
|
} catch {
|
|
1543
|
-
return
|
|
1948
|
+
return u.slice(0, 60);
|
|
1544
1949
|
}
|
|
1545
|
-
}
|
|
1546
|
-
function saveAgentEnv(id, env) {
|
|
1547
|
-
fs9.mkdirSync(folder(id), { recursive: true });
|
|
1548
|
-
const f = path6.join(folder(id), "env.json");
|
|
1549
|
-
fs9.writeFileSync(`${f}.tmp`, JSON.stringify({ ...agentEnv(id), ...env }), { mode: 384 });
|
|
1550
|
-
fs9.renameSync(`${f}.tmp`, f);
|
|
1551
|
-
}
|
|
1552
|
-
|
|
1553
|
-
// src/agent/service.ts
|
|
1950
|
+
};
|
|
1554
1951
|
var MAX_NEWS = 180 * 1024;
|
|
1555
1952
|
var MAX_TOOL_ARGS = 200 * 1024;
|
|
1556
1953
|
var MAX_TEXT = 48 * 1024;
|
|
@@ -1664,28 +2061,28 @@ function mcpServerFor(agent, url, key, bridge) {
|
|
|
1664
2061
|
return { name: "hypeframe", command: bridge.command, args: bridge.args, env: [...bridge.env, ...env] };
|
|
1665
2062
|
}
|
|
1666
2063
|
function historyFile(projectId, sessionId) {
|
|
1667
|
-
return
|
|
2064
|
+
return path8.join(projectDir(projectId), "riwayat", `${crypto3.createHash("sha256").update(sessionId).digest("hex").slice(0, 32)}.jsonl`);
|
|
1668
2065
|
}
|
|
1669
2066
|
function record(file, updates) {
|
|
1670
2067
|
if (!updates.length)
|
|
1671
2068
|
return;
|
|
1672
2069
|
try {
|
|
1673
|
-
|
|
1674
|
-
|
|
2070
|
+
fs11.mkdirSync(path8.dirname(file), { recursive: true });
|
|
2071
|
+
fs11.appendFileSync(file, `${updates.map((u) => JSON.stringify(u)).join(`
|
|
1675
2072
|
`)}
|
|
1676
2073
|
`);
|
|
1677
|
-
if (
|
|
1678
|
-
const text =
|
|
2074
|
+
if (fs11.statSync(file).size > MAX_HISTORY) {
|
|
2075
|
+
const text = fs11.readFileSync(file, "utf8");
|
|
1679
2076
|
const from = text.indexOf(`
|
|
1680
2077
|
`, text.length - MAX_HISTORY / 2);
|
|
1681
|
-
|
|
2078
|
+
fs11.writeFileSync(file, from >= 0 ? text.slice(from + 1) : "");
|
|
1682
2079
|
}
|
|
1683
2080
|
} catch {}
|
|
1684
2081
|
}
|
|
1685
2082
|
function readHistory(file) {
|
|
1686
2083
|
let text = "";
|
|
1687
2084
|
try {
|
|
1688
|
-
text =
|
|
2085
|
+
text = fs11.readFileSync(file, "utf8");
|
|
1689
2086
|
} catch {
|
|
1690
2087
|
return { update: [], potong: false };
|
|
1691
2088
|
}
|
|
@@ -1740,6 +2137,13 @@ function createAgentService(o) {
|
|
|
1740
2137
|
sendUpdates(sessionId);
|
|
1741
2138
|
o.conn.news("agen", { sessionId, ...body });
|
|
1742
2139
|
};
|
|
2140
|
+
const accountRestart = new Set;
|
|
2141
|
+
const restartForAccount = (agentId) => {
|
|
2142
|
+
if (!sessions.running().includes(agentId))
|
|
2143
|
+
return Promise.resolve(false);
|
|
2144
|
+
accountRestart.add(agentId);
|
|
2145
|
+
return sessions.stopAgent(agentId);
|
|
2146
|
+
};
|
|
1743
2147
|
const sessions = new AgentSessions({
|
|
1744
2148
|
agent: (id) => readInstalled().find((a) => a.id === id),
|
|
1745
2149
|
env: (id) => agentEnv(id),
|
|
@@ -1764,7 +2168,12 @@ function createAgentService(o) {
|
|
|
1764
2168
|
setTimeout(() => permissions.has(id) && done(null), 5 * 60000).unref();
|
|
1765
2169
|
control(sessionId, { izin: { id, judul: String(req.toolCall.title ?? ""), jenis: String(req.toolCall.kind ?? ""), perintah: commandText(req), wajibTanya: info.mustAsk, opsi: req.options } });
|
|
1766
2170
|
}),
|
|
1767
|
-
onExit: (agentId, code) =>
|
|
2171
|
+
onExit: (agentId, code) => {
|
|
2172
|
+
const akun = accountRestart.delete(agentId);
|
|
2173
|
+
o.conn.news("agen", { agentId, berhenti: code, ...akun ? { akun: true } : {} });
|
|
2174
|
+
if (!akun)
|
|
2175
|
+
emit({ type: "stopped", agent: nameOf(agentId), code });
|
|
2176
|
+
},
|
|
1768
2177
|
flushMs: o.flushMs ?? 100
|
|
1769
2178
|
});
|
|
1770
2179
|
const text = (c, k) => typeof c[k] === "string" ? c[k] : "";
|
|
@@ -1782,16 +2191,29 @@ function createAgentService(o) {
|
|
|
1782
2191
|
const t0 = Date.now();
|
|
1783
2192
|
if (fresh)
|
|
1784
2193
|
emit({ type: "starting", agent: a.name });
|
|
1785
|
-
const
|
|
2194
|
+
const alat = Array.isArray(c.alat) ? c.alat : undefined;
|
|
2195
|
+
let early = "";
|
|
2196
|
+
const register = (id) => {
|
|
2197
|
+
early = id;
|
|
2198
|
+
routes.set(id, { dari: c.dari, tab, alat: alat ?? [], projectId, agentId });
|
|
2199
|
+
};
|
|
2200
|
+
let opened;
|
|
2201
|
+
try {
|
|
2202
|
+
opened = await sessions.open({ agentId, projectId, resumeId: text(c, "resume") || undefined, onRoute: register });
|
|
2203
|
+
} catch (e) {
|
|
2204
|
+
if (early)
|
|
2205
|
+
routes.delete(early);
|
|
2206
|
+
throw e;
|
|
2207
|
+
}
|
|
2208
|
+
const { sessionId, dimuat, routeId, opsi } = opened;
|
|
1786
2209
|
if (fresh)
|
|
1787
2210
|
emit({ type: "ready", agent: a.name, ms: Date.now() - t0 });
|
|
1788
2211
|
if (dimuat !== "hidup")
|
|
1789
2212
|
emit({ type: "chat", agent: a.name, resumed: dimuat === "load" });
|
|
1790
|
-
const alat = Array.isArray(c.alat) ? c.alat : undefined;
|
|
1791
2213
|
const r = routes.get(routeId);
|
|
1792
2214
|
if (!r)
|
|
1793
2215
|
routes.set(routeId, { dari: c.dari, tab, alat: alat ?? [], projectId, agentId });
|
|
1794
|
-
else {
|
|
2216
|
+
else if (routeId !== early) {
|
|
1795
2217
|
if (tab && r.tab === tab)
|
|
1796
2218
|
r.dari = c.dari;
|
|
1797
2219
|
if (alat)
|
|
@@ -1838,10 +2260,47 @@ function createAgentService(o) {
|
|
|
1838
2260
|
const macam = text(c, "macam");
|
|
1839
2261
|
if (!["model", "mode", "opsi"].includes(macam))
|
|
1840
2262
|
throw new Error("Pilihan tidak dikenal.");
|
|
1841
|
-
const r = await sessions.setOption(text(c, "sessionId"), { jenis: macam, id: text(c, "id"), nilai: text(c, "nilai") });
|
|
2263
|
+
const r = await sessions.setOption(text(c, "sessionId"), { jenis: macam, id: text(c, "id"), nilai: text(c, "nilai"), nama: text(c, "nama") });
|
|
1842
2264
|
emit({ type: "option", agent: nameOf(sessions.agentOf(text(c, "sessionId"))), what: macam === "opsi" ? text(c, "id") : macam, value: text(c, "nilai") });
|
|
1843
2265
|
return r;
|
|
1844
2266
|
},
|
|
2267
|
+
"agen.akun": async (c) => {
|
|
2268
|
+
const agentId = text(c, "agentId");
|
|
2269
|
+
const aksi = text(c, "aksi");
|
|
2270
|
+
if (aksi === "api-model")
|
|
2271
|
+
return { model: await fetchApiModels(text(c, "url"), text(c, "kunci")) };
|
|
2272
|
+
if (!readInstalled().some((x) => x.id === agentId))
|
|
2273
|
+
throw new Error("Agen belum dipasang di mesin ini.");
|
|
2274
|
+
switch (aksi) {
|
|
2275
|
+
case "keluar": {
|
|
2276
|
+
const hasil = await logoutAgent(agentId);
|
|
2277
|
+
await restartForAccount(agentId);
|
|
2278
|
+
return { hasil };
|
|
2279
|
+
}
|
|
2280
|
+
case "masuk":
|
|
2281
|
+
return { ...startRemoteLogin(agentId) };
|
|
2282
|
+
case "status":
|
|
2283
|
+
return { ...remoteLoginState(agentId) ?? { tahap: "tidak-ada" } };
|
|
2284
|
+
case "kode":
|
|
2285
|
+
return { ...sendRemoteCode(agentId, text(c, "kode")) };
|
|
2286
|
+
case "batal":
|
|
2287
|
+
return cancelRemoteLogin(agentId), {};
|
|
2288
|
+
case "api-simpan": {
|
|
2289
|
+
if (agentId !== OPENCODE)
|
|
2290
|
+
throw new Error("API sendiri hanya untuk OpenCode.");
|
|
2291
|
+
const models = Array.isArray(c.model) ? c.model.filter((m) => typeof m === "string") : [];
|
|
2292
|
+
saveOpencodeApi({ url: text(c, "url"), key: text(c, "kunci"), models, name: text(c, "nama") || undefined });
|
|
2293
|
+
await restartForAccount(OPENCODE);
|
|
2294
|
+
return { siap: await checkReady(OPENCODE) };
|
|
2295
|
+
}
|
|
2296
|
+
case "api-hapus":
|
|
2297
|
+
removeOpencodeApi();
|
|
2298
|
+
await restartForAccount(OPENCODE);
|
|
2299
|
+
return {};
|
|
2300
|
+
default:
|
|
2301
|
+
throw new Error("Pilihan tidak dikenal.");
|
|
2302
|
+
}
|
|
2303
|
+
},
|
|
1845
2304
|
"agen.riwayat": async (c) => {
|
|
1846
2305
|
try {
|
|
1847
2306
|
return readHistory(historyFile(text(c, "projectId"), text(c, "sessionId")));
|
|
@@ -1856,17 +2315,17 @@ function createAgentService(o) {
|
|
|
1856
2315
|
const folder = projectDir(projectId);
|
|
1857
2316
|
if (!p || !insideFolder(folder, p))
|
|
1858
2317
|
return fail(`Only files inside the HypeFrame project folder (${folder}) can be added.`);
|
|
1859
|
-
const file =
|
|
1860
|
-
const st =
|
|
2318
|
+
const file = path8.resolve(folder, p);
|
|
2319
|
+
const st = fs11.statSync(file, { throwIfNoEntry: false });
|
|
1861
2320
|
if (!st?.isFile())
|
|
1862
2321
|
return fail(`${p} is not a file in the project folder.`);
|
|
1863
|
-
const nama =
|
|
1864
|
-
const mime = MEDIA[
|
|
2322
|
+
const nama = path8.basename(file).slice(0, 120);
|
|
2323
|
+
const mime = MEDIA[path8.extname(file).slice(1).toLowerCase()];
|
|
1865
2324
|
if (!mime)
|
|
1866
2325
|
return fail(`${nama}: only images, audio, video, fonts and Lottie/JSON files can be added to a HypeFrame project.`);
|
|
1867
2326
|
if (st.size > MAX_FILE2)
|
|
1868
2327
|
return fail(`${nama} is ${(st.size / 1048576).toFixed(1)} MB; files up to 4 MB can be sent to HypeFrame Web. Make it smaller (lower resolution or bitrate) and try again.`);
|
|
1869
|
-
const data =
|
|
2328
|
+
const data = fs11.readFileSync(file).toString("base64");
|
|
1870
2329
|
const n = Math.max(1, Math.ceil(data.length / PIECE));
|
|
1871
2330
|
const id = crypto3.randomBytes(8).toString("hex");
|
|
1872
2331
|
let last = {};
|
|
@@ -1939,24 +2398,46 @@ function createAgentService(o) {
|
|
|
1939
2398
|
}
|
|
1940
2399
|
}
|
|
1941
2400
|
function capabilities() {
|
|
1942
|
-
|
|
2401
|
+
const api = opencodeApi();
|
|
2402
|
+
return readInstalled().filter((a) => isSupported(a.id) || process.env.HYPEFRAME_ACP_REGISTRY).slice(0, 8).map((a) => ({ id: a.id, nama: a.name, siap: a.ready === true, ...a.id === OPENCODE && api ? { api: hostOf(api.url) } : {} }));
|
|
2403
|
+
}
|
|
2404
|
+
const stamps = new Map;
|
|
2405
|
+
const stampOf = (id) => [path8.join(agentDir(), id, "agent.json"), path8.join(agentDir(), id, "env.json"), ...id === OPENCODE ? [path8.join(dataDir(), "opencode.json")] : []].map((f) => fs11.statSync(f, { throwIfNoEntry: false })?.mtimeMs ?? 0).join(":");
|
|
2406
|
+
function checkAccounts() {
|
|
2407
|
+
const running = sessions.running();
|
|
2408
|
+
const restarted = [];
|
|
2409
|
+
for (const id of running) {
|
|
2410
|
+
const now = stampOf(id);
|
|
2411
|
+
const before = stamps.get(id);
|
|
2412
|
+
stamps.set(id, now);
|
|
2413
|
+
if (before !== undefined && before !== now) {
|
|
2414
|
+
restartForAccount(id);
|
|
2415
|
+
stamps.delete(id);
|
|
2416
|
+
restarted.push(nameOf(id));
|
|
2417
|
+
emit({ type: "account", agent: nameOf(id) });
|
|
2418
|
+
}
|
|
2419
|
+
}
|
|
2420
|
+
for (const id of [...stamps.keys()])
|
|
2421
|
+
if (!running.includes(id))
|
|
2422
|
+
stamps.delete(id);
|
|
2423
|
+
return restarted;
|
|
1943
2424
|
}
|
|
1944
2425
|
function activity() {
|
|
1945
2426
|
return { chats: sessions.count(), working: sessions.working(), agents: sessions.running().map((id) => nameOf(id)) };
|
|
1946
2427
|
}
|
|
1947
|
-
return { work, route, capabilities, activity, key, stop: () => (stopping = true, clearInterval(ticker), sessions.stopAll()) };
|
|
2428
|
+
return { work, route, capabilities, checkAccounts, activity, key, stop: () => (stopping = true, clearInterval(ticker), sessions.stopAll()) };
|
|
1948
2429
|
}
|
|
1949
2430
|
|
|
1950
2431
|
// src/agent/mcp-bridge.ts
|
|
1951
|
-
import
|
|
1952
|
-
import
|
|
2432
|
+
import fs13 from "node:fs";
|
|
2433
|
+
import path10 from "node:path";
|
|
1953
2434
|
import readline2 from "node:readline";
|
|
1954
2435
|
|
|
1955
2436
|
// src/util/runtime.ts
|
|
1956
|
-
import
|
|
1957
|
-
import
|
|
2437
|
+
import fs12 from "node:fs";
|
|
2438
|
+
import path9 from "node:path";
|
|
1958
2439
|
function isStandalone() {
|
|
1959
|
-
return
|
|
2440
|
+
return path9.basename(process.execPath).toLowerCase().startsWith("hypeframe");
|
|
1960
2441
|
}
|
|
1961
2442
|
function runtimeLabel() {
|
|
1962
2443
|
const bun = process.versions.bun;
|
|
@@ -1966,7 +2447,7 @@ function launchCommand() {
|
|
|
1966
2447
|
if (isStandalone())
|
|
1967
2448
|
return [process.execPath];
|
|
1968
2449
|
try {
|
|
1969
|
-
const script =
|
|
2450
|
+
const script = fs12.realpathSync(process.argv[1] || "");
|
|
1970
2451
|
return /[\\/]_npx[\\/]/.test(script) ? null : [process.execPath, script];
|
|
1971
2452
|
} catch {
|
|
1972
2453
|
return null;
|
|
@@ -2002,13 +2483,13 @@ rl.on('line', (line) => {
|
|
|
2002
2483
|
rl.on('close', () => Promise.all(busy).then(() => process.exit(0)));
|
|
2003
2484
|
`;
|
|
2004
2485
|
function bridgeLaunch() {
|
|
2005
|
-
const file =
|
|
2486
|
+
const file = path10.join(agentDir(), "mcp-bridge.mjs");
|
|
2006
2487
|
let now = "";
|
|
2007
2488
|
try {
|
|
2008
|
-
now =
|
|
2489
|
+
now = fs13.readFileSync(file, "utf8");
|
|
2009
2490
|
} catch {}
|
|
2010
2491
|
if (now !== BRIDGE_SOURCE)
|
|
2011
|
-
|
|
2492
|
+
fs13.writeFileSync(file, BRIDGE_SOURCE);
|
|
2012
2493
|
return { command: process.execPath, args: [file], env: isStandalone() ? [{ name: "BUN_BE_BUN", value: "1" }] : [] };
|
|
2013
2494
|
}
|
|
2014
2495
|
async function runMcpBridge() {
|
|
@@ -2054,7 +2535,7 @@ async function runMcpBridge() {
|
|
|
2054
2535
|
}
|
|
2055
2536
|
|
|
2056
2537
|
// src/config/lock.ts
|
|
2057
|
-
import
|
|
2538
|
+
import fs14 from "node:fs";
|
|
2058
2539
|
class AlreadyRunning extends Error {
|
|
2059
2540
|
code = "SUDAH_JALAN";
|
|
2060
2541
|
}
|
|
@@ -2068,7 +2549,7 @@ var alive = (pid) => {
|
|
|
2068
2549
|
};
|
|
2069
2550
|
function runningPid() {
|
|
2070
2551
|
try {
|
|
2071
|
-
const pid = Number(
|
|
2552
|
+
const pid = Number(fs14.readFileSync(lockFile(), "utf8"));
|
|
2072
2553
|
return Number.isInteger(pid) && pid > 0 && pid !== process.pid && alive(pid) ? pid : null;
|
|
2073
2554
|
} catch {
|
|
2074
2555
|
return null;
|
|
@@ -2078,13 +2559,13 @@ function singleInstance() {
|
|
|
2078
2559
|
const f = lockFile();
|
|
2079
2560
|
for (let attempt = 0;attempt < 2; attempt++) {
|
|
2080
2561
|
try {
|
|
2081
|
-
const fd =
|
|
2082
|
-
|
|
2083
|
-
|
|
2562
|
+
const fd = fs14.openSync(f, "wx");
|
|
2563
|
+
fs14.writeSync(fd, String(process.pid));
|
|
2564
|
+
fs14.closeSync(fd);
|
|
2084
2565
|
const release = () => {
|
|
2085
2566
|
try {
|
|
2086
|
-
if (
|
|
2087
|
-
|
|
2567
|
+
if (fs14.readFileSync(f, "utf8") === String(process.pid))
|
|
2568
|
+
fs14.rmSync(f, { force: true });
|
|
2088
2569
|
} catch {}
|
|
2089
2570
|
process.off("exit", release);
|
|
2090
2571
|
};
|
|
@@ -2093,10 +2574,10 @@ function singleInstance() {
|
|
|
2093
2574
|
} catch (e) {
|
|
2094
2575
|
if (e.code !== "EEXIST")
|
|
2095
2576
|
throw e;
|
|
2096
|
-
const pid = Number(
|
|
2577
|
+
const pid = Number(fs14.readFileSync(f, "utf8"));
|
|
2097
2578
|
if (Number.isInteger(pid) && pid > 0 && alive(pid))
|
|
2098
2579
|
throw new AlreadyRunning("engine already running");
|
|
2099
|
-
|
|
2580
|
+
fs14.rmSync(f, { force: true });
|
|
2100
2581
|
}
|
|
2101
2582
|
}
|
|
2102
2583
|
throw new AlreadyRunning("engine already running");
|
|
@@ -2332,44 +2813,55 @@ async function pair(o) {
|
|
|
2332
2813
|
}
|
|
2333
2814
|
|
|
2334
2815
|
// src/render/chrome.ts
|
|
2335
|
-
import
|
|
2816
|
+
import fs15 from "node:fs";
|
|
2336
2817
|
import http from "node:http";
|
|
2337
|
-
import
|
|
2818
|
+
import path11 from "node:path";
|
|
2338
2819
|
import { Browser, detectBrowserPlatform, getInstalledBrowsers, install, resolveBuildId } from "@puppeteer/browsers";
|
|
2339
2820
|
import puppeteer from "puppeteer-core";
|
|
2340
2821
|
var ANDROID_ARGS = ["--no-sandbox", "--disable-dev-shm-usage"];
|
|
2341
|
-
var ANDROID_FALLBACKS = [
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
|
|
2822
|
+
var ANDROID_FALLBACKS = [
|
|
2823
|
+
{ args: [], pipe: false },
|
|
2824
|
+
{ args: [], pipe: true },
|
|
2825
|
+
{ args: ["--enable-features=NetworkServiceInProcess2"], pipe: true },
|
|
2826
|
+
{ args: ["--single-process", "--no-zygote"], pipe: true },
|
|
2827
|
+
{ args: ["--enable-features=NetworkServiceInProcess2"], pipe: false },
|
|
2828
|
+
{ args: ["--single-process", "--no-zygote"], pipe: false }
|
|
2829
|
+
];
|
|
2830
|
+
var flagsFile = () => path11.join(dataDir(), "chrome-flags.json");
|
|
2831
|
+
var sameCara = (a, b) => a.pipe === b.pipe && a.args.length === b.args.length && a.args.every((x, i) => x === b.args[i]);
|
|
2832
|
+
function savedCara() {
|
|
2345
2833
|
try {
|
|
2346
|
-
const
|
|
2347
|
-
|
|
2834
|
+
const j = JSON.parse(fs15.readFileSync(flagsFile(), "utf8"));
|
|
2835
|
+
const c = { args: Array.isArray(j.args) ? j.args.map(String) : [], pipe: j.pipe === true };
|
|
2836
|
+
return ANDROID_FALLBACKS.some((f) => sameCara(f, c)) ? c : { args: [], pipe: false };
|
|
2348
2837
|
} catch {
|
|
2349
|
-
return [];
|
|
2838
|
+
return { args: [], pipe: false };
|
|
2350
2839
|
}
|
|
2351
2840
|
}
|
|
2352
|
-
function
|
|
2841
|
+
function saveCara(c) {
|
|
2353
2842
|
try {
|
|
2354
|
-
if (
|
|
2355
|
-
|
|
2843
|
+
if (c.args.length || c.pipe)
|
|
2844
|
+
fs15.writeFileSync(flagsFile(), JSON.stringify(c));
|
|
2356
2845
|
else
|
|
2357
|
-
|
|
2846
|
+
fs15.rmSync(flagsFile(), { force: true });
|
|
2358
2847
|
} catch {}
|
|
2359
2848
|
}
|
|
2360
2849
|
function chromePlatformArgs(android = isAndroid()) {
|
|
2361
|
-
return android ? [...ANDROID_ARGS, ...
|
|
2850
|
+
return android ? [...ANDROID_ARGS, ...savedCara().args] : [];
|
|
2851
|
+
}
|
|
2852
|
+
function chromePipe(android = isAndroid()) {
|
|
2853
|
+
return android && savedCara().pipe;
|
|
2362
2854
|
}
|
|
2363
2855
|
async function probeChrome(attempt, android = isAndroid()) {
|
|
2364
2856
|
if (!android)
|
|
2365
|
-
return attempt([]);
|
|
2366
|
-
const saved =
|
|
2857
|
+
return attempt({ args: [], pipe: false });
|
|
2858
|
+
const saved = savedCara();
|
|
2367
2859
|
let first;
|
|
2368
|
-
for (const
|
|
2860
|
+
for (const cara of [saved, ...ANDROID_FALLBACKS.filter((f) => !sameCara(f, saved))]) {
|
|
2369
2861
|
try {
|
|
2370
|
-
const r = await attempt([...
|
|
2371
|
-
if (!
|
|
2372
|
-
|
|
2862
|
+
const r = await attempt({ args: [...cara.args], pipe: cara.pipe });
|
|
2863
|
+
if (!sameCara(cara, saved))
|
|
2864
|
+
saveCara(cara);
|
|
2373
2865
|
return r;
|
|
2374
2866
|
} catch (e) {
|
|
2375
2867
|
first ??= e;
|
|
@@ -2384,7 +2876,7 @@ function chromeLogHint(log) {
|
|
|
2384
2876
|
function candidates() {
|
|
2385
2877
|
const e = process.env;
|
|
2386
2878
|
if (process.platform === "win32") {
|
|
2387
|
-
return [e.PROGRAMFILES, e["PROGRAMFILES(X86)"], e.LOCALAPPDATA].filter((d) => !!d).flatMap((d) => [
|
|
2879
|
+
return [e.PROGRAMFILES, e["PROGRAMFILES(X86)"], e.LOCALAPPDATA].filter((d) => !!d).flatMap((d) => [path11.join(d, "Google", "Chrome", "Application", "chrome.exe"), path11.join(d, "Microsoft", "Edge", "Application", "msedge.exe")]);
|
|
2388
2880
|
}
|
|
2389
2881
|
if (process.platform === "darwin") {
|
|
2390
2882
|
return ["/Applications/Google Chrome.app/Contents/MacOS/Google Chrome", "/Applications/Chromium.app/Contents/MacOS/Chromium", "/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge"];
|
|
@@ -2394,15 +2886,15 @@ function candidates() {
|
|
|
2394
2886
|
function findChrome(android = isAndroid()) {
|
|
2395
2887
|
const forced = process.env.HYPEFRAME_CHROME;
|
|
2396
2888
|
if (forced)
|
|
2397
|
-
return
|
|
2889
|
+
return fs15.existsSync(forced) ? forced : null;
|
|
2398
2890
|
if (android && linuxChromiumReady())
|
|
2399
2891
|
return chromiumWrapper();
|
|
2400
|
-
return candidates().find((p) =>
|
|
2892
|
+
return candidates().find((p) => fs15.existsSync(p)) || null;
|
|
2401
2893
|
}
|
|
2402
2894
|
async function cachedChrome(cacheDir) {
|
|
2403
2895
|
try {
|
|
2404
|
-
const all = await getInstalledBrowsers({ cacheDir:
|
|
2405
|
-
return all.find((b) => b.browser === Browser.CHROME &&
|
|
2896
|
+
const all = await getInstalledBrowsers({ cacheDir: path11.join(cacheDir, "chrome") });
|
|
2897
|
+
return all.find((b) => b.browser === Browser.CHROME && fs15.existsSync(b.executablePath))?.executablePath ?? null;
|
|
2406
2898
|
} catch {
|
|
2407
2899
|
return null;
|
|
2408
2900
|
}
|
|
@@ -2421,7 +2913,7 @@ async function prepareChrome(cacheDir, progress = () => {
|
|
|
2421
2913
|
const platform = detectBrowserPlatform();
|
|
2422
2914
|
if (!platform)
|
|
2423
2915
|
throw new Error("Sistem ini belum didukung untuk render (Chrome tidak tersedia).");
|
|
2424
|
-
const dir =
|
|
2916
|
+
const dir = path11.join(cacheDir, "chrome");
|
|
2425
2917
|
const buildId = await resolveBuildId(Browser.CHROME, platform, "stable");
|
|
2426
2918
|
progress(0, `Chrome ${buildId}`);
|
|
2427
2919
|
const r = await install({
|
|
@@ -2450,14 +2942,14 @@ var TRY_ENCODER = `async (c) => {
|
|
|
2450
2942
|
});
|
|
2451
2943
|
}`;
|
|
2452
2944
|
async function checkChrome(chrome, { gpu = false, android = isAndroid() } = {}) {
|
|
2453
|
-
return probeChrome(async (
|
|
2945
|
+
return probeChrome(async (cara) => ({ ...await checkOnce(chrome, gpu, android ? [...ANDROID_ARGS, ...cara.args] : [], cara.pipe), extra: [...cara.args, ...cara.pipe ? ["pipe"] : []] }), android);
|
|
2454
2946
|
}
|
|
2455
|
-
async function checkOnce(chrome, gpu, platformArgs) {
|
|
2947
|
+
async function checkOnce(chrome, gpu, platformArgs, pipe = false) {
|
|
2456
2948
|
const srv = http.createServer((_q, r) => (r.writeHead(200, { "content-type": "text/html" }), r.end("<!doctype html><title>check</title>")));
|
|
2457
2949
|
await new Promise((ok) => srv.listen(0, "127.0.0.1", ok));
|
|
2458
2950
|
let b;
|
|
2459
2951
|
try {
|
|
2460
|
-
b = await puppeteer.launch({ executablePath: chrome, headless: true, protocolTimeout: 60000, args: ["--no-first-run", "--disable-extensions", ...gpu ? [] : softwareGpuArgs, ...platformArgs] });
|
|
2952
|
+
b = await puppeteer.launch({ executablePath: chrome, headless: true, pipe, protocolTimeout: 60000, args: ["--no-first-run", "--disable-extensions", ...gpu ? [] : softwareGpuArgs, ...platformArgs] });
|
|
2461
2953
|
} catch (e) {
|
|
2462
2954
|
srv.close();
|
|
2463
2955
|
throw e;
|
|
@@ -2486,9 +2978,9 @@ async function checkOnce(chrome, gpu, platformArgs) {
|
|
|
2486
2978
|
|
|
2487
2979
|
// src/render/ffmpeg.ts
|
|
2488
2980
|
import crypto5 from "node:crypto";
|
|
2489
|
-
import
|
|
2981
|
+
import fs16 from "node:fs";
|
|
2490
2982
|
import fsp from "node:fs/promises";
|
|
2491
|
-
import
|
|
2983
|
+
import path12 from "node:path";
|
|
2492
2984
|
import { pipeline } from "node:stream/promises";
|
|
2493
2985
|
import { Readable } from "node:stream";
|
|
2494
2986
|
import zlib from "node:zlib";
|
|
@@ -2502,22 +2994,22 @@ var FFMPEG_PINNED = {
|
|
|
2502
2994
|
"darwin-arm64": { sha256: "6be74d6f449889c2e87a75873894f8520cad56c08ac76f2a628d85b0519daaca", size: 19253088 }
|
|
2503
2995
|
};
|
|
2504
2996
|
var exe = process.platform === "win32" ? "ffmpeg.exe" : "ffmpeg";
|
|
2505
|
-
var cached2 = (cacheDir) =>
|
|
2997
|
+
var cached2 = (cacheDir) => path12.join(cacheDir, "ffmpeg", FFMPEG_RELEASE, exe);
|
|
2506
2998
|
var thisPlatform = () => `${process.platform}-${process.arch}`;
|
|
2507
2999
|
async function findFfmpeg(cacheDir, key = thisPlatform()) {
|
|
2508
3000
|
const forced = process.env.HYPEFRAME_FFMPEG;
|
|
2509
3001
|
if (forced)
|
|
2510
|
-
return
|
|
3002
|
+
return fs16.existsSync(forced) ? forced : null;
|
|
2511
3003
|
if (!FFMPEG_PINNED[key])
|
|
2512
3004
|
return onPath("ffmpeg");
|
|
2513
3005
|
try {
|
|
2514
3006
|
const mod = await import("ffmpeg-static");
|
|
2515
3007
|
const p = typeof mod.default === "string" ? mod.default : null;
|
|
2516
|
-
if (p &&
|
|
3008
|
+
if (p && fs16.existsSync(p))
|
|
2517
3009
|
return p;
|
|
2518
3010
|
} catch {}
|
|
2519
3011
|
const c = cached2(cacheDir);
|
|
2520
|
-
return
|
|
3012
|
+
return fs16.existsSync(c) ? c : null;
|
|
2521
3013
|
}
|
|
2522
3014
|
async function downloadVerified(url, sha256, dest, progress = () => {
|
|
2523
3015
|
return;
|
|
@@ -2526,7 +3018,7 @@ async function downloadVerified(url, sha256, dest, progress = () => {
|
|
|
2526
3018
|
if (!r.ok || !r.body)
|
|
2527
3019
|
throw new Error(`download ${r.status}`);
|
|
2528
3020
|
const total = Number(r.headers.get("content-length")) || 0;
|
|
2529
|
-
await fsp.mkdir(
|
|
3021
|
+
await fsp.mkdir(path12.dirname(dest), { recursive: true });
|
|
2530
3022
|
const tmp = `${dest}.download`;
|
|
2531
3023
|
const hash = crypto5.createHash("sha256");
|
|
2532
3024
|
let got = 0;
|
|
@@ -2538,13 +3030,13 @@ async function downloadVerified(url, sha256, dest, progress = () => {
|
|
|
2538
3030
|
if (pct - last >= 10)
|
|
2539
3031
|
last = pct, progress(pct);
|
|
2540
3032
|
});
|
|
2541
|
-
await pipeline(body,
|
|
3033
|
+
await pipeline(body, fs16.createWriteStream(tmp));
|
|
2542
3034
|
if (hash.digest("hex") !== sha256) {
|
|
2543
3035
|
await fsp.rm(tmp, { force: true });
|
|
2544
3036
|
throw new Error("ffmpeg: sidik unduhan tidak cocok, berkas ditolak.");
|
|
2545
3037
|
}
|
|
2546
3038
|
if (gunzip) {
|
|
2547
|
-
await pipeline(
|
|
3039
|
+
await pipeline(fs16.createReadStream(tmp), zlib.createGunzip(), fs16.createWriteStream(`${tmp}.raw`));
|
|
2548
3040
|
await fsp.rm(tmp, { force: true });
|
|
2549
3041
|
await fsp.rename(`${tmp}.raw`, dest);
|
|
2550
3042
|
} else
|
|
@@ -2567,16 +3059,16 @@ async function prepareFfmpeg(cacheDir, progress = () => {
|
|
|
2567
3059
|
}
|
|
2568
3060
|
|
|
2569
3061
|
// src/render/job.ts
|
|
2570
|
-
import { spawn as
|
|
3062
|
+
import { spawn as spawn3 } from "node:child_process";
|
|
2571
3063
|
import crypto6 from "node:crypto";
|
|
2572
|
-
import
|
|
3064
|
+
import fs17 from "node:fs";
|
|
2573
3065
|
import fsp2 from "node:fs/promises";
|
|
2574
|
-
import
|
|
3066
|
+
import path13 from "node:path";
|
|
2575
3067
|
import puppeteer2 from "puppeteer-core";
|
|
2576
3068
|
var LIMIT_SECONDS = 1800;
|
|
2577
3069
|
function run(cmd, args, limitSeconds = 600) {
|
|
2578
3070
|
return new Promise((ok, fail) => {
|
|
2579
|
-
const p =
|
|
3071
|
+
const p = spawn3(cmd, args, { stdio: ["ignore", "ignore", "pipe"] });
|
|
2580
3072
|
let err = "";
|
|
2581
3073
|
p.stderr.on("data", (d) => err = (err + d).slice(-2000));
|
|
2582
3074
|
const timer = setTimeout(() => p.kill("SIGKILL"), limitSeconds * 1000);
|
|
@@ -2588,7 +3080,7 @@ function run(cmd, args, limitSeconds = 600) {
|
|
|
2588
3080
|
function saveBody(req, to, max) {
|
|
2589
3081
|
return new Promise((ok, fail) => {
|
|
2590
3082
|
let n = 0;
|
|
2591
|
-
const out =
|
|
3083
|
+
const out = fs17.createWriteStream(to);
|
|
2592
3084
|
req.on("data", (d) => {
|
|
2593
3085
|
n += d.length;
|
|
2594
3086
|
if (n > max)
|
|
@@ -2630,12 +3122,13 @@ function createJobRunner(o) {
|
|
|
2630
3122
|
let browser;
|
|
2631
3123
|
try {
|
|
2632
3124
|
progress(0, "Menyiapkan");
|
|
2633
|
-
const profile =
|
|
2634
|
-
await fsp2.mkdir(
|
|
2635
|
-
await fsp2.writeFile(
|
|
3125
|
+
const profile = path13.join(task.dir, "profil");
|
|
3126
|
+
await fsp2.mkdir(path13.join(profile, "Default"), { recursive: true });
|
|
3127
|
+
await fsp2.writeFile(path13.join(profile, "Default", "Preferences"), JSON.stringify({ webkit: { webprefs: { fonts: { standard: { Zyyy: "Roboto" }, sansserif: { Zyyy: "Roboto" }, serif: { Zyyy: "Noto Serif" } } } } }));
|
|
2636
3128
|
browser = await puppeteer2.launch({
|
|
2637
3129
|
executablePath: chrome,
|
|
2638
3130
|
headless: true,
|
|
3131
|
+
pipe: chromePipe(),
|
|
2639
3132
|
userDataDir: profile,
|
|
2640
3133
|
args: [
|
|
2641
3134
|
"--no-first-run",
|
|
@@ -2663,9 +3156,9 @@ function createJobRunner(o) {
|
|
|
2663
3156
|
if (result.error)
|
|
2664
3157
|
throw new Error(result.error);
|
|
2665
3158
|
progress(99, clip ? "Menyelesaikan klip" : "Menyelesaikan video");
|
|
2666
|
-
const raw =
|
|
3159
|
+
const raw = path13.join(task.dir, "mentah.mp4");
|
|
2667
3160
|
const webm = clip && task.transparent;
|
|
2668
|
-
const file =
|
|
3161
|
+
const file = path13.join(task.dir, webm ? "hasil.webm" : "hasil.mp4");
|
|
2669
3162
|
if (clip)
|
|
2670
3163
|
await fsp2.rename(raw, file);
|
|
2671
3164
|
else
|
|
@@ -2692,11 +3185,11 @@ function createJobRunner(o) {
|
|
|
2692
3185
|
return res.writeHead(403), res.end(), true;
|
|
2693
3186
|
const pkg = r.task.packageDir;
|
|
2694
3187
|
if (m[2] === "proyek.json" || m[2] === "klip.json" || m[3]) {
|
|
2695
|
-
const f = m[3] ?
|
|
2696
|
-
if (!
|
|
3188
|
+
const f = m[3] ? path13.join(pkg, "aset", m[3]) : path13.join(pkg, m[2]);
|
|
3189
|
+
if (!fs17.existsSync(f))
|
|
2697
3190
|
return res.writeHead(404), res.end(), true;
|
|
2698
3191
|
res.writeHead(200, { "content-type": m[3] ? "application/octet-stream" : "application/json", "content-length": (await fsp2.stat(f)).size });
|
|
2699
|
-
|
|
3192
|
+
fs17.createReadStream(f).pipe(res);
|
|
2700
3193
|
return true;
|
|
2701
3194
|
}
|
|
2702
3195
|
if (m[2] === "kemajuan") {
|
|
@@ -2713,7 +3206,7 @@ function createJobRunner(o) {
|
|
|
2713
3206
|
r.finish({ error: String(b.pesan || "Render gagal.").slice(0, 300) });
|
|
2714
3207
|
return res.writeHead(204), res.end(), true;
|
|
2715
3208
|
}
|
|
2716
|
-
await saveBody(req,
|
|
3209
|
+
await saveBody(req, path13.join(r.task.dir, "mentah.mp4"), 8 * 1073741824);
|
|
2717
3210
|
r.finish({ audio: String(req.headers["x-kodek-audio"] || "") });
|
|
2718
3211
|
res.writeHead(204);
|
|
2719
3212
|
res.end();
|
|
@@ -2723,9 +3216,9 @@ function createJobRunner(o) {
|
|
|
2723
3216
|
}
|
|
2724
3217
|
|
|
2725
3218
|
// src/render/page.ts
|
|
2726
|
-
import
|
|
3219
|
+
import fs18 from "node:fs";
|
|
2727
3220
|
import fsp3 from "node:fs/promises";
|
|
2728
|
-
import
|
|
3221
|
+
import path14 from "node:path";
|
|
2729
3222
|
var TYPES = {
|
|
2730
3223
|
".html": "text/html; charset=utf-8",
|
|
2731
3224
|
".js": "text/javascript",
|
|
@@ -2746,13 +3239,13 @@ var SAFE_PATH = /^[\w@.+-]+(?:\/[\w@.+-]+)*$/;
|
|
|
2746
3239
|
var VERSION_ID = /^[0-9a-f]{12}$/;
|
|
2747
3240
|
function createPage({ web, cacheDir }) {
|
|
2748
3241
|
const base = `${String(web || "").replace(/\/+$/, "")}/render/`;
|
|
2749
|
-
const root =
|
|
3242
|
+
const root = path14.join(cacheDir, "halaman");
|
|
2750
3243
|
let version = null;
|
|
2751
|
-
const versionDir = () =>
|
|
3244
|
+
const versionDir = () => path14.join(root, version);
|
|
2752
3245
|
const pending = new Map;
|
|
2753
3246
|
async function download(rel) {
|
|
2754
|
-
const target =
|
|
2755
|
-
if (
|
|
3247
|
+
const target = path14.join(versionDir(), rel);
|
|
3248
|
+
if (fs18.existsSync(target))
|
|
2756
3249
|
return target;
|
|
2757
3250
|
if (!pending.has(rel)) {
|
|
2758
3251
|
pending.set(rel, (async () => {
|
|
@@ -2760,7 +3253,7 @@ function createPage({ web, cacheDir }) {
|
|
|
2760
3253
|
if (!r.ok)
|
|
2761
3254
|
throw Object.assign(new Error(`halaman ${rel}: ${r.status}`), { status: r.status });
|
|
2762
3255
|
const body = Buffer.from(await r.arrayBuffer());
|
|
2763
|
-
await fsp3.mkdir(
|
|
3256
|
+
await fsp3.mkdir(path14.dirname(target), { recursive: true });
|
|
2764
3257
|
await fsp3.writeFile(`${target}.tmp`, body);
|
|
2765
3258
|
await fsp3.rename(`${target}.tmp`, target);
|
|
2766
3259
|
return target;
|
|
@@ -2784,10 +3277,10 @@ function createPage({ web, cacheDir }) {
|
|
|
2784
3277
|
await download(f);
|
|
2785
3278
|
if (old !== version) {
|
|
2786
3279
|
const all = (await fsp3.readdir(root).catch(() => [])).filter((d) => VERSION_ID.test(d));
|
|
2787
|
-
const dated = await Promise.all(all.map(async (d) => ({ d, t: (await fsp3.stat(
|
|
3280
|
+
const dated = await Promise.all(all.map(async (d) => ({ d, t: (await fsp3.stat(path14.join(root, d))).mtimeMs })));
|
|
2788
3281
|
for (const { d } of dated.sort((a, b) => b.t - a.t).slice(2))
|
|
2789
3282
|
if (d !== version)
|
|
2790
|
-
await fsp3.rm(
|
|
3283
|
+
await fsp3.rm(path14.join(root, d), { recursive: true, force: true });
|
|
2791
3284
|
}
|
|
2792
3285
|
return { version };
|
|
2793
3286
|
}
|
|
@@ -2804,8 +3297,8 @@ function createPage({ web, cacheDir }) {
|
|
|
2804
3297
|
return res.writeHead(404), res.end(), true;
|
|
2805
3298
|
try {
|
|
2806
3299
|
const f = await download(rel);
|
|
2807
|
-
res.writeHead(200, { "content-type": TYPES[
|
|
2808
|
-
|
|
3300
|
+
res.writeHead(200, { "content-type": TYPES[path14.extname(f)] || "application/octet-stream", "cache-control": "no-store" });
|
|
3301
|
+
fs18.createReadStream(f).pipe(res);
|
|
2809
3302
|
} catch (e) {
|
|
2810
3303
|
res.writeHead(e.status === 404 ? 404 : 502);
|
|
2811
3304
|
res.end();
|
|
@@ -2940,10 +3433,10 @@ async function runRelayJob(j, o) {
|
|
|
2940
3433
|
|
|
2941
3434
|
// src/render/service.ts
|
|
2942
3435
|
import crypto8 from "node:crypto";
|
|
2943
|
-
import
|
|
3436
|
+
import fs19 from "node:fs";
|
|
2944
3437
|
import fsp4 from "node:fs/promises";
|
|
2945
3438
|
import http2 from "node:http";
|
|
2946
|
-
import
|
|
3439
|
+
import path15 from "node:path";
|
|
2947
3440
|
import yauzl from "yauzl";
|
|
2948
3441
|
var ACTIVE = new Set(["unggah", "antre", "jalan"]);
|
|
2949
3442
|
var safeEqual = (a, b) => a.length === b.length && crypto8.timingSafeEqual(Buffer.from(a), Buffer.from(b));
|
|
@@ -2970,14 +3463,14 @@ function extractZip(f, to) {
|
|
|
2970
3463
|
zip.on("entry", (en) => {
|
|
2971
3464
|
if (en.fileName.endsWith("/"))
|
|
2972
3465
|
return zip.readEntry();
|
|
2973
|
-
const target =
|
|
2974
|
-
if (!target.startsWith(to +
|
|
3466
|
+
const target = path15.join(to, en.fileName);
|
|
3467
|
+
if (!target.startsWith(to + path15.sep))
|
|
2975
3468
|
return fail(new Error(EngineError.BadPackage));
|
|
2976
|
-
|
|
3469
|
+
fs19.mkdirSync(path15.dirname(target), { recursive: true });
|
|
2977
3470
|
zip.openReadStream(en, (e2, s) => {
|
|
2978
3471
|
if (e2 || !s)
|
|
2979
3472
|
return fail(e2 ?? new Error("zip"));
|
|
2980
|
-
const out =
|
|
3473
|
+
const out = fs19.createWriteStream(target);
|
|
2981
3474
|
s.pipe(out);
|
|
2982
3475
|
out.on("finish", () => zip.readEntry());
|
|
2983
3476
|
out.on("error", fail);
|
|
@@ -2992,13 +3485,13 @@ function extractZip(f, to) {
|
|
|
2992
3485
|
function saveBody2(req, to, max) {
|
|
2993
3486
|
return new Promise((ok, fail) => {
|
|
2994
3487
|
let n = 0;
|
|
2995
|
-
const out =
|
|
3488
|
+
const out = fs19.createWriteStream(to);
|
|
2996
3489
|
req.on("data", (d) => {
|
|
2997
3490
|
n += d.length;
|
|
2998
3491
|
if (n > max) {
|
|
2999
3492
|
req.destroy();
|
|
3000
3493
|
out.destroy();
|
|
3001
|
-
|
|
3494
|
+
fs19.rm(to, { force: true }, () => fail(new Error("terlalu besar")));
|
|
3002
3495
|
}
|
|
3003
3496
|
});
|
|
3004
3497
|
req.pipe(out);
|
|
@@ -3027,7 +3520,7 @@ async function createRenderService(o) {
|
|
|
3027
3520
|
} } = o;
|
|
3028
3521
|
const origins = new Set([].concat(o.origin || []));
|
|
3029
3522
|
const sign = (kind, body) => crypto8.createHmac("sha256", key).update(`${kind}.${body}`).digest("base64url");
|
|
3030
|
-
const dir = (job) =>
|
|
3523
|
+
const dir = (job) => path15.join(folder, job);
|
|
3031
3524
|
await fsp4.mkdir(folder, { recursive: true });
|
|
3032
3525
|
function readTicket(req) {
|
|
3033
3526
|
const tk = String(req.headers.authorization || "").replace(/^Bearer\s+/i, "");
|
|
@@ -3049,7 +3542,7 @@ async function createRenderService(o) {
|
|
|
3049
3542
|
const jobs = new Map;
|
|
3050
3543
|
const queue = [];
|
|
3051
3544
|
let current = null;
|
|
3052
|
-
const persist = (t) => fsp4.writeFile(
|
|
3545
|
+
const persist = (t) => fsp4.writeFile(path15.join(dir(t.job), "status.json"), JSON.stringify(t)).catch(() => {
|
|
3053
3546
|
return;
|
|
3054
3547
|
});
|
|
3055
3548
|
const update = (t, patch) => (Object.assign(t, patch, { diperbarui: Date.now() }), void persist(t));
|
|
@@ -3068,19 +3561,19 @@ async function createRenderService(o) {
|
|
|
3068
3561
|
});
|
|
3069
3562
|
async function clearFiles(t, all = false) {
|
|
3070
3563
|
for (const n of all ? ["."] : ["paket", "paket.zip", "profil", "mentah.mp4", "mentah.webm"])
|
|
3071
|
-
await fsp4.rm(
|
|
3564
|
+
await fsp4.rm(path15.join(dir(t.job), n), { recursive: true, force: true }).catch(() => {
|
|
3072
3565
|
return;
|
|
3073
3566
|
});
|
|
3074
3567
|
if (!all) {
|
|
3075
3568
|
for (const f of await fsp4.readdir(dir(t.job)).catch(() => []))
|
|
3076
3569
|
if (/^p\d+$/.test(f))
|
|
3077
|
-
await fsp4.rm(
|
|
3570
|
+
await fsp4.rm(path15.join(dir(t.job), f), { force: true });
|
|
3078
3571
|
}
|
|
3079
3572
|
}
|
|
3080
3573
|
async function openPackage(t) {
|
|
3081
3574
|
const d = dir(t.job);
|
|
3082
3575
|
const main = t.tiket.jenis === "klip" ? "klip.json" : "proyek.json";
|
|
3083
|
-
const entries = await listZip(
|
|
3576
|
+
const entries = await listZip(path15.join(d, "paket.zip"));
|
|
3084
3577
|
const names = entries.map((x) => x.name).filter((n) => !n.endsWith("/"));
|
|
3085
3578
|
if (names.some((n) => n.startsWith("/") || n.includes("..") || n.includes("\\") || n !== main && !/^aset\/[\w-]+$/.test(n)))
|
|
3086
3579
|
throw new Error(EngineError.BadPackage);
|
|
@@ -3088,10 +3581,10 @@ async function createRenderService(o) {
|
|
|
3088
3581
|
throw new Error(`Paket tidak berisi ${main}.`);
|
|
3089
3582
|
if (entries.reduce((a, x) => a + x.size, 0) > maxUnzippedMb * 1048576)
|
|
3090
3583
|
throw new Error("Isi paket terlalu besar.");
|
|
3091
|
-
await extractZip(
|
|
3092
|
-
await fsp4.rm(
|
|
3093
|
-
const j = JSON.parse(await fsp4.readFile(
|
|
3094
|
-
const has = (id) => /^[\w-]+$/.test(id) &&
|
|
3584
|
+
await extractZip(path15.join(d, "paket.zip"), path15.join(d, "paket"));
|
|
3585
|
+
await fsp4.rm(path15.join(d, "paket.zip"), { force: true });
|
|
3586
|
+
const j = JSON.parse(await fsp4.readFile(path15.join(d, "paket", main), "utf8"));
|
|
3587
|
+
const has = (id) => /^[\w-]+$/.test(id) && fs19.existsSync(path15.join(d, "paket", "aset", id));
|
|
3095
3588
|
if (main === "klip.json") {
|
|
3096
3589
|
const k = j.klip || {};
|
|
3097
3590
|
const seconds = Number(k.durationInFrames) / Number(k.fps);
|
|
@@ -3139,7 +3632,7 @@ async function createRenderService(o) {
|
|
|
3139
3632
|
job: t.job,
|
|
3140
3633
|
kind: t.tiket.jenis,
|
|
3141
3634
|
dir: dir(t.job),
|
|
3142
|
-
packageDir:
|
|
3635
|
+
packageDir: path15.join(dir(t.job), "paket"),
|
|
3143
3636
|
transparent: !!t.transparan,
|
|
3144
3637
|
persen: t.persen,
|
|
3145
3638
|
width: t.tiket.w,
|
|
@@ -3159,7 +3652,7 @@ async function createRenderService(o) {
|
|
|
3159
3652
|
const size = (await fsp4.stat(h.file)).size;
|
|
3160
3653
|
if (size < 200)
|
|
3161
3654
|
throw new Error(EngineError.EmptyResult);
|
|
3162
|
-
update(t, { status: "selesai", persen: 100, tahap: "", selesaiPada: Date.now(), hasilUkuran: size, hasilBerkas:
|
|
3655
|
+
update(t, { status: "selesai", persen: 100, tahap: "", selesaiPada: Date.now(), hasilUkuran: size, hasilBerkas: path15.basename(h.file), hasilJenis: h.type });
|
|
3163
3656
|
onJob("done", t);
|
|
3164
3657
|
} catch (e) {
|
|
3165
3658
|
if (t.status !== "batal") {
|
|
@@ -3197,10 +3690,10 @@ async function createRenderService(o) {
|
|
|
3197
3690
|
if (a > z)
|
|
3198
3691
|
return res.writeHead(416, { ...h, "content-range": `bytes */${st.size}` }), res.end();
|
|
3199
3692
|
res.writeHead(206, { ...h, "content-length": z - a + 1, "content-range": `bytes ${a}-${z}/${st.size}` });
|
|
3200
|
-
return void
|
|
3693
|
+
return void fs19.createReadStream(f, { start: a, end: z }).pipe(res);
|
|
3201
3694
|
}
|
|
3202
3695
|
res.writeHead(200, { ...h, "content-length": st.size });
|
|
3203
|
-
|
|
3696
|
+
fs19.createReadStream(f).pipe(res);
|
|
3204
3697
|
}
|
|
3205
3698
|
const ROUTE = /^\/tugas(?:\/(r_[a-f0-9]{16})(\/potongan\/(\d{1,4})|\/mulai|\/hasil)?)?$/;
|
|
3206
3699
|
const server = http2.createServer(async (req, res) => {
|
|
@@ -3239,8 +3732,8 @@ async function createRenderService(o) {
|
|
|
3239
3732
|
if (t.status !== "unggah")
|
|
3240
3733
|
return json(req, res, 409, { galat: "Unggahan sudah ditutup." });
|
|
3241
3734
|
const n = Number(m[3]);
|
|
3242
|
-
const f =
|
|
3243
|
-
const before =
|
|
3735
|
+
const f = path15.join(dir(job), `p${n}`);
|
|
3736
|
+
const before = fs19.existsSync(f) ? (await fsp4.stat(f)).size : 0;
|
|
3244
3737
|
const room = Number(ticket.maksMb) * 1048576 - (t.terunggah - before);
|
|
3245
3738
|
const size = await saveBody2(req, f, Math.min(partMb * 1048576 + 1024, room));
|
|
3246
3739
|
const expected = String(req.headers["x-sha256"] || "").toLowerCase();
|
|
@@ -3262,13 +3755,13 @@ async function createRenderService(o) {
|
|
|
3262
3755
|
const count = Number(b.jumlah);
|
|
3263
3756
|
if (!(count > 0 && count < 1e4))
|
|
3264
3757
|
return json(req, res, 400, { galat: "Jumlah potongan tidak valid." });
|
|
3265
|
-
const zip =
|
|
3266
|
-
const out =
|
|
3758
|
+
const zip = path15.join(dir(job), "paket.zip");
|
|
3759
|
+
const out = fs19.createWriteStream(zip);
|
|
3267
3760
|
const hash = crypto8.createHash("sha256");
|
|
3268
3761
|
let total = 0;
|
|
3269
3762
|
for (let i = 0;i < count; i++) {
|
|
3270
|
-
const f =
|
|
3271
|
-
if (!
|
|
3763
|
+
const f = path15.join(dir(job), `p${i}`);
|
|
3764
|
+
if (!fs19.existsSync(f))
|
|
3272
3765
|
return out.destroy(), json(req, res, 400, { galat: `Potongan ${i + 1} belum terunggah.` });
|
|
3273
3766
|
const part = await fsp4.readFile(f);
|
|
3274
3767
|
hash.update(part);
|
|
@@ -3298,8 +3791,8 @@ async function createRenderService(o) {
|
|
|
3298
3791
|
return json(req, res, 200, summary(t));
|
|
3299
3792
|
}
|
|
3300
3793
|
if (m[2] === "/hasil" && (req.method === "GET" || req.method === "HEAD")) {
|
|
3301
|
-
const f = t.hasilBerkas ?
|
|
3302
|
-
if (t.status !== "selesai" || !f || !
|
|
3794
|
+
const f = t.hasilBerkas ? path15.join(dir(job), t.hasilBerkas) : "";
|
|
3795
|
+
if (t.status !== "selesai" || !f || !fs19.existsSync(f))
|
|
3303
3796
|
return json(req, res, 409, { galat: "Video belum jadi." });
|
|
3304
3797
|
const webm = t.hasilJenis === "video/webm";
|
|
3305
3798
|
return sendFile(req, res, f, webm ? "video/webm" : "video/mp4", `hypeframe-${job}.${webm ? "webm" : "mp4"}`);
|
|
@@ -3330,7 +3823,7 @@ async function createRenderService(o) {
|
|
|
3330
3823
|
if (!JOB_ID.test(job))
|
|
3331
3824
|
continue;
|
|
3332
3825
|
try {
|
|
3333
|
-
const t = JSON.parse(await fsp4.readFile(
|
|
3826
|
+
const t = JSON.parse(await fsp4.readFile(path15.join(dir(job), "status.json"), "utf8"));
|
|
3334
3827
|
if (t.status === "jalan" || t.status === "antre")
|
|
3335
3828
|
update(t, { status: "gagal", galat: EngineError.Restarted });
|
|
3336
3829
|
jobs.set(job, t);
|
|
@@ -3411,7 +3904,7 @@ function table(rows, indent = " ") {
|
|
|
3411
3904
|
}
|
|
3412
3905
|
|
|
3413
3906
|
// src/util/open.ts
|
|
3414
|
-
import { spawn as
|
|
3907
|
+
import { spawn as spawn4 } from "node:child_process";
|
|
3415
3908
|
var PAIRING_LINK = new RegExp(`^https?://[A-Za-z0-9.-]+(:\\d+)?/sambung\\?kode=${PAIRING_CODE.source.slice(1, -1)}$`);
|
|
3416
3909
|
var WEB_ORIGIN = /^https?:\/\/[A-Za-z0-9.-]+(:\d+)?\/?$/;
|
|
3417
3910
|
function openCommand(target, platform, url) {
|
|
@@ -3425,7 +3918,7 @@ function openCommand(target, platform, url) {
|
|
|
3425
3918
|
}
|
|
3426
3919
|
function launch(target, url) {
|
|
3427
3920
|
const [cmd, args] = openCommand(target, isAndroid() ? "android" : process.platform, url);
|
|
3428
|
-
const p =
|
|
3921
|
+
const p = spawn4(cmd, args, { stdio: "ignore", detached: true });
|
|
3429
3922
|
p.on("error", () => {
|
|
3430
3923
|
return;
|
|
3431
3924
|
});
|
|
@@ -3479,6 +3972,8 @@ function logAgentEvent(e) {
|
|
|
3479
3972
|
return log.detail(t("agentLog.option", { agent: e.agent, what: e.what, value: e.value }));
|
|
3480
3973
|
case "stopped":
|
|
3481
3974
|
return log.warn(t("agentLog.stopped", { agent: a, code: String(e.code) }));
|
|
3975
|
+
case "account":
|
|
3976
|
+
return log.info(t("agentLog.account", { agent: a }));
|
|
3482
3977
|
}
|
|
3483
3978
|
}
|
|
3484
3979
|
async function pairDevice(s, noBrowser = false) {
|
|
@@ -3604,13 +4099,14 @@ async function start(args, { fromMenu = false } = {}) {
|
|
|
3604
4099
|
const engineConn = new Connection({ gateway: s.gateway, token: account.token, info: { versi: VERSION, os: osName(), nama: s.name, kemampuan: capabilities, portLokal: service.port }, handler });
|
|
3605
4100
|
conn = engineConn;
|
|
3606
4101
|
setInterval(() => {
|
|
4102
|
+
agents.checkAccounts();
|
|
3607
4103
|
const now = agents.capabilities();
|
|
3608
4104
|
if (JSON.stringify(now) === JSON.stringify(capabilities.agen))
|
|
3609
4105
|
return;
|
|
3610
4106
|
capabilities.agen = now;
|
|
3611
4107
|
conn?.setInfo({ kemampuan: capabilities });
|
|
3612
4108
|
conn?.news("status", { kemampuan: capabilities });
|
|
3613
|
-
},
|
|
4109
|
+
}, 5000).unref();
|
|
3614
4110
|
let connectedBefore = false;
|
|
3615
4111
|
let renderNote = "";
|
|
3616
4112
|
engineConn.on("connected", () => {
|
|
@@ -3727,23 +4223,23 @@ function logout() {
|
|
|
3727
4223
|
|
|
3728
4224
|
// src/cli/commands/autostart.ts
|
|
3729
4225
|
import { spawnSync as spawnSync3 } from "node:child_process";
|
|
3730
|
-
import
|
|
4226
|
+
import fs20 from "node:fs";
|
|
3731
4227
|
import os3 from "node:os";
|
|
3732
|
-
import
|
|
4228
|
+
import path16 from "node:path";
|
|
3733
4229
|
function entryFile() {
|
|
3734
4230
|
const home = os3.homedir();
|
|
3735
4231
|
if (process.platform === "win32")
|
|
3736
|
-
return
|
|
4232
|
+
return path16.join(process.env.APPDATA || path16.join(home, "AppData", "Roaming"), "Microsoft", "Windows", "Start Menu", "Programs", "Startup", "HypeFrame.cmd");
|
|
3737
4233
|
if (process.platform === "darwin")
|
|
3738
|
-
return
|
|
4234
|
+
return path16.join(home, "Library", "LaunchAgents", "com.hypeframe.engine.plist");
|
|
3739
4235
|
if (hasSystemd())
|
|
3740
|
-
return
|
|
3741
|
-
return
|
|
4236
|
+
return path16.join(home, ".config", "systemd", "user", "hypeframe.service");
|
|
4237
|
+
return path16.join(home, ".config", "autostart", "hypeframe.desktop");
|
|
3742
4238
|
}
|
|
3743
4239
|
function hasSystemd() {
|
|
3744
4240
|
return process.platform === "linux" && spawnSync3("systemctl", ["--user", "--version"], { stdio: "ignore" }).status === 0;
|
|
3745
4241
|
}
|
|
3746
|
-
var autostartEnabled = () =>
|
|
4242
|
+
var autostartEnabled = () => fs20.existsSync(entryFile());
|
|
3747
4243
|
var xml = (s) => s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
3748
4244
|
function autostart(mode) {
|
|
3749
4245
|
const file = entryFile();
|
|
@@ -3755,7 +4251,7 @@ function autostart(mode) {
|
|
|
3755
4251
|
if (mode === "off") {
|
|
3756
4252
|
if (process.platform === "linux" && file.endsWith(".service"))
|
|
3757
4253
|
spawnSync3("systemctl", ["--user", "disable", "hypeframe.service"], { stdio: "ignore" });
|
|
3758
|
-
|
|
4254
|
+
fs20.rmSync(file, { force: true });
|
|
3759
4255
|
log.ok(t("autostart.off"));
|
|
3760
4256
|
return;
|
|
3761
4257
|
}
|
|
@@ -3770,14 +4266,14 @@ function autostart(mode) {
|
|
|
3770
4266
|
return;
|
|
3771
4267
|
}
|
|
3772
4268
|
const quoted = cmd.map((c) => `"${c}"`).join(" ");
|
|
3773
|
-
|
|
4269
|
+
fs20.mkdirSync(path16.dirname(file), { recursive: true });
|
|
3774
4270
|
if (process.platform === "win32") {
|
|
3775
|
-
|
|
4271
|
+
fs20.writeFileSync(file, `@echo off\r
|
|
3776
4272
|
start "HypeFrame" /min ${quoted} start --no-browser\r
|
|
3777
4273
|
`);
|
|
3778
4274
|
} else if (process.platform === "darwin") {
|
|
3779
|
-
const out =
|
|
3780
|
-
|
|
4275
|
+
const out = path16.join(logDir(), "autostart.log");
|
|
4276
|
+
fs20.writeFileSync(file, `<?xml version="1.0" encoding="UTF-8"?>
|
|
3781
4277
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
3782
4278
|
<plist version="1.0"><dict>
|
|
3783
4279
|
<key>Label</key><string>com.hypeframe.engine</string>
|
|
@@ -3788,7 +4284,7 @@ start "HypeFrame" /min ${quoted} start --no-browser\r
|
|
|
3788
4284
|
</dict></plist>
|
|
3789
4285
|
`);
|
|
3790
4286
|
} else if (file.endsWith(".service")) {
|
|
3791
|
-
|
|
4287
|
+
fs20.writeFileSync(file, `[Unit]
|
|
3792
4288
|
Description=HypeFrame engine
|
|
3793
4289
|
After=network-online.target
|
|
3794
4290
|
|
|
@@ -3803,7 +4299,7 @@ WantedBy=default.target
|
|
|
3803
4299
|
spawnSync3("systemctl", ["--user", "daemon-reload"], { stdio: "ignore" });
|
|
3804
4300
|
spawnSync3("systemctl", ["--user", "enable", "hypeframe.service"], { stdio: "ignore" });
|
|
3805
4301
|
} else {
|
|
3806
|
-
|
|
4302
|
+
fs20.writeFileSync(file, `[Desktop Entry]
|
|
3807
4303
|
Type=Application
|
|
3808
4304
|
Name=HypeFrame engine
|
|
3809
4305
|
Exec=${quoted} start --no-browser
|
|
@@ -3868,6 +4364,7 @@ async function bench(args) {
|
|
|
3868
4364
|
const b = await puppeteer3.launch({
|
|
3869
4365
|
executablePath: chrome,
|
|
3870
4366
|
headless: true,
|
|
4367
|
+
pipe: chromePipe(),
|
|
3871
4368
|
protocolTimeout: 300000,
|
|
3872
4369
|
args: ["--no-first-run", "--disable-extensions", ...s.gpu ? [] : softwareGpuArgs, ...chromePlatformArgs()]
|
|
3873
4370
|
});
|
|
@@ -3905,9 +4402,9 @@ async function bench(args) {
|
|
|
3905
4402
|
import * as p from "@clack/prompts";
|
|
3906
4403
|
|
|
3907
4404
|
// src/agent/install.ts
|
|
3908
|
-
import
|
|
4405
|
+
import fs21 from "node:fs";
|
|
3909
4406
|
import fsp5 from "node:fs/promises";
|
|
3910
|
-
import
|
|
4407
|
+
import path17 from "node:path";
|
|
3911
4408
|
import yauzl2 from "yauzl";
|
|
3912
4409
|
function unzip(file, to) {
|
|
3913
4410
|
return new Promise((ok, fail) => {
|
|
@@ -3915,16 +4412,16 @@ function unzip(file, to) {
|
|
|
3915
4412
|
if (e || !zip)
|
|
3916
4413
|
return fail(e ?? new Error("zip"));
|
|
3917
4414
|
zip.on("entry", (en) => {
|
|
3918
|
-
const target =
|
|
3919
|
-
if (!target.startsWith(to +
|
|
4415
|
+
const target = path17.join(to, en.fileName);
|
|
4416
|
+
if (!target.startsWith(to + path17.sep))
|
|
3920
4417
|
return fail(new Error("archive path outside the agent folder"));
|
|
3921
4418
|
if (en.fileName.endsWith("/"))
|
|
3922
|
-
return
|
|
3923
|
-
|
|
4419
|
+
return fs21.mkdirSync(target, { recursive: true }), zip.readEntry();
|
|
4420
|
+
fs21.mkdirSync(path17.dirname(target), { recursive: true });
|
|
3924
4421
|
zip.openReadStream(en, (e2, s) => {
|
|
3925
4422
|
if (e2 || !s)
|
|
3926
4423
|
return fail(e2 ?? new Error("zip"));
|
|
3927
|
-
const out =
|
|
4424
|
+
const out = fs21.createWriteStream(target);
|
|
3928
4425
|
s.pipe(out);
|
|
3929
4426
|
out.on("finish", () => zip.readEntry());
|
|
3930
4427
|
out.on("error", fail);
|
|
@@ -3939,7 +4436,7 @@ function unzip(file, to) {
|
|
|
3939
4436
|
async function untarGz(file, to) {
|
|
3940
4437
|
const { gunzipSync } = await import("node:zlib");
|
|
3941
4438
|
const data = gunzipSync(await fsp5.readFile(file));
|
|
3942
|
-
const root =
|
|
4439
|
+
const root = path17.resolve(to);
|
|
3943
4440
|
const str = (b) => b.toString("utf8").replace(/\0[\s\S]*$/, "");
|
|
3944
4441
|
const octal = (b) => Number.parseInt(str(b).trim() || "0", 8) || 0;
|
|
3945
4442
|
let off = 0;
|
|
@@ -3970,8 +4467,8 @@ async function untarGz(file, to) {
|
|
|
3970
4467
|
name = name.replace(/^\.\//, "");
|
|
3971
4468
|
if (!name)
|
|
3972
4469
|
continue;
|
|
3973
|
-
const target =
|
|
3974
|
-
if (target !== root && !target.startsWith(root +
|
|
4470
|
+
const target = path17.resolve(root, name);
|
|
4471
|
+
if (target !== root && !target.startsWith(root + path17.sep))
|
|
3975
4472
|
throw new Error("archive path outside the agent folder");
|
|
3976
4473
|
if (type === "5") {
|
|
3977
4474
|
await fsp5.mkdir(target, { recursive: true });
|
|
@@ -3979,22 +4476,22 @@ async function untarGz(file, to) {
|
|
|
3979
4476
|
}
|
|
3980
4477
|
if (type !== "0" && type !== "7")
|
|
3981
4478
|
continue;
|
|
3982
|
-
await fsp5.mkdir(
|
|
4479
|
+
await fsp5.mkdir(path17.dirname(target), { recursive: true });
|
|
3983
4480
|
await fsp5.writeFile(target, body, { mode: octal(h.subarray(100, 108)) & 73 ? 493 : 420 });
|
|
3984
4481
|
}
|
|
3985
4482
|
}
|
|
3986
4483
|
function npxRunner(pkg, extra = []) {
|
|
3987
4484
|
if (isStandalone())
|
|
3988
4485
|
return { cmd: process.execPath, args: ["x", pkg, ...extra], env: { BUN_BE_BUN: "1" } };
|
|
3989
|
-
const npxCli =
|
|
3990
|
-
if (!
|
|
4486
|
+
const npxCli = path17.join(path17.dirname(process.execPath), process.platform === "win32" ? "" : "..", process.platform === "win32" ? "node_modules" : "lib/node_modules", "npm", "bin", "npx-cli.js");
|
|
4487
|
+
if (!fs21.existsSync(npxCli))
|
|
3991
4488
|
throw new Error("npx was not found next to Node.js");
|
|
3992
4489
|
return { cmd: process.execPath, args: [npxCli, "-y", pkg, ...extra], env: {} };
|
|
3993
4490
|
}
|
|
3994
4491
|
function ownCopy(a) {
|
|
3995
4492
|
const bin = a.distribution.binary?.[platformKey()];
|
|
3996
4493
|
if (bin) {
|
|
3997
|
-
const cmd = onPath(
|
|
4494
|
+
const cmd = onPath(path17.basename(bin.cmd).replace(/\.exe$/i, ""));
|
|
3998
4495
|
return cmd ? { cmd, args: bin.args ?? [], env: bin.env ?? {} } : null;
|
|
3999
4496
|
}
|
|
4000
4497
|
const npx = a.distribution.npx;
|
|
@@ -4008,35 +4505,35 @@ function ownCopy(a) {
|
|
|
4008
4505
|
async function unpackBinary(id, version, bin, progress) {
|
|
4009
4506
|
if (!/^[0-9a-f]{64}$/i.test(bin.sha256 || ""))
|
|
4010
4507
|
throw new Error(`Agent ${id}: the registry gives no sha256; not installed`);
|
|
4011
|
-
const dir =
|
|
4508
|
+
const dir = path17.join(agentDir(), id, version);
|
|
4012
4509
|
const tmp = `${dir}.tmp`;
|
|
4013
4510
|
await fsp5.rm(tmp, { recursive: true, force: true });
|
|
4014
4511
|
await fsp5.mkdir(tmp, { recursive: true });
|
|
4015
4512
|
try {
|
|
4016
|
-
const name =
|
|
4513
|
+
const name = path17.basename(new URL(bin.archive).pathname);
|
|
4017
4514
|
const cmdRel = bin.cmd.replace(/^\.\//, "");
|
|
4018
4515
|
if (/\.zip$/i.test(name)) {
|
|
4019
|
-
const file =
|
|
4516
|
+
const file = path17.join(tmp, ".download.zip");
|
|
4020
4517
|
await downloadVerified(bin.archive, bin.sha256.toLowerCase(), file, progress);
|
|
4021
4518
|
await unzip(file, tmp);
|
|
4022
4519
|
await fsp5.rm(file, { force: true });
|
|
4023
4520
|
} else if (/\.(tar\.gz|tgz)$/i.test(name)) {
|
|
4024
|
-
const file =
|
|
4521
|
+
const file = path17.join(tmp, ".download.tar.gz");
|
|
4025
4522
|
await downloadVerified(bin.archive, bin.sha256.toLowerCase(), file, progress);
|
|
4026
4523
|
await untarGz(file, tmp);
|
|
4027
4524
|
await fsp5.rm(file, { force: true });
|
|
4028
4525
|
} else if (/\.gz$/i.test(name)) {
|
|
4029
|
-
await downloadVerified(bin.archive, bin.sha256.toLowerCase(),
|
|
4526
|
+
await downloadVerified(bin.archive, bin.sha256.toLowerCase(), path17.join(tmp, cmdRel), progress, true);
|
|
4030
4527
|
} else
|
|
4031
4528
|
throw new Error(`Agent ${id}: unsupported archive ${name}`);
|
|
4032
|
-
const cmd =
|
|
4033
|
-
if (!
|
|
4529
|
+
const cmd = path17.join(tmp, cmdRel);
|
|
4530
|
+
if (!fs21.existsSync(cmd))
|
|
4034
4531
|
throw new Error(`Agent ${id}: ${bin.cmd} is not in the download`);
|
|
4035
4532
|
if (process.platform !== "win32")
|
|
4036
4533
|
await fsp5.chmod(cmd, 493);
|
|
4037
4534
|
await fsp5.rm(dir, { recursive: true, force: true });
|
|
4038
4535
|
await fsp5.rename(tmp, dir);
|
|
4039
|
-
return { cmd:
|
|
4536
|
+
return { cmd: path17.join(dir, cmdRel), args: bin.args ?? [], env: bin.env ?? {} };
|
|
4040
4537
|
} catch (e) {
|
|
4041
4538
|
await fsp5.rm(tmp, { recursive: true, force: true });
|
|
4042
4539
|
throw e;
|
|
@@ -4056,9 +4553,9 @@ async function codexAcpBuild(arch) {
|
|
|
4056
4553
|
return { url, sha256: sha256.toLowerCase(), version: String(j.tag_name ?? "latest").replace(/^v/, "") };
|
|
4057
4554
|
}
|
|
4058
4555
|
var findFile = (dir, name) => {
|
|
4059
|
-
for (const n of
|
|
4060
|
-
const f =
|
|
4061
|
-
const st =
|
|
4556
|
+
for (const n of fs21.readdirSync(dir)) {
|
|
4557
|
+
const f = path17.join(dir, n);
|
|
4558
|
+
const st = fs21.lstatSync(f);
|
|
4062
4559
|
if (st.isFile() && n === name)
|
|
4063
4560
|
return f;
|
|
4064
4561
|
if (st.isDirectory()) {
|
|
@@ -4078,23 +4575,23 @@ async function installInLinux(a, id, progress, steps, arch) {
|
|
|
4078
4575
|
}
|
|
4079
4576
|
if (id === "codex-acp") {
|
|
4080
4577
|
const b = await codexAcpBuild(arch);
|
|
4081
|
-
const dir =
|
|
4578
|
+
const dir = path17.join(agentDir(), id, b.version);
|
|
4082
4579
|
const tmp = `${dir}.tmp`;
|
|
4083
4580
|
await fsp5.rm(tmp, { recursive: true, force: true });
|
|
4084
4581
|
await fsp5.mkdir(tmp, { recursive: true });
|
|
4085
4582
|
try {
|
|
4086
|
-
const file =
|
|
4583
|
+
const file = path17.join(tmp, ".download.tar.gz");
|
|
4087
4584
|
await downloadVerified(b.url, b.sha256, file, progress);
|
|
4088
4585
|
await untarGz(file, tmp);
|
|
4089
4586
|
await fsp5.rm(file, { force: true });
|
|
4090
4587
|
const found = findFile(tmp, "codex-acp");
|
|
4091
4588
|
if (!found)
|
|
4092
4589
|
throw new Error("codex-acp: the program is not in the download");
|
|
4093
|
-
const rel =
|
|
4590
|
+
const rel = path17.relative(tmp, found);
|
|
4094
4591
|
await fsp5.chmod(found, 493);
|
|
4095
4592
|
await fsp5.rm(dir, { recursive: true, force: true });
|
|
4096
4593
|
await fsp5.rename(tmp, dir);
|
|
4097
|
-
return { launch: { cmd:
|
|
4594
|
+
return { launch: { cmd: path17.join(dir, rel), args: [], env: {}, linux: true }, version: b.version };
|
|
4098
4595
|
} catch (e) {
|
|
4099
4596
|
await fsp5.rm(tmp, { recursive: true, force: true });
|
|
4100
4597
|
throw e;
|
|
@@ -4141,94 +4638,6 @@ async function installAgent(id, progress = () => {
|
|
|
4141
4638
|
return installed;
|
|
4142
4639
|
}
|
|
4143
4640
|
|
|
4144
|
-
// src/agent/login.ts
|
|
4145
|
-
import { spawn as spawn4 } from "node:child_process";
|
|
4146
|
-
var SIGN_IN = /https?:\/\/[^\s"'<>]{8,2000}/g;
|
|
4147
|
-
var looksLikeSignIn = (u) => /oauth|auth|login|signin|sign-in|device|accounts\./i.test(u);
|
|
4148
|
-
function linkScanner(found) {
|
|
4149
|
-
const seen = new Set;
|
|
4150
|
-
let rest = "";
|
|
4151
|
-
return (text) => {
|
|
4152
|
-
rest += text;
|
|
4153
|
-
const end = rest.lastIndexOf(`
|
|
4154
|
-
`);
|
|
4155
|
-
if (end < 0)
|
|
4156
|
-
return void (rest = rest.slice(-4096));
|
|
4157
|
-
const lines = rest.slice(0, end);
|
|
4158
|
-
rest = rest.slice(end + 1);
|
|
4159
|
-
for (const u of lines.match(SIGN_IN) ?? [])
|
|
4160
|
-
if (looksLikeSignIn(u) && !seen.has(u))
|
|
4161
|
-
seen.add(u), found(u);
|
|
4162
|
-
};
|
|
4163
|
-
}
|
|
4164
|
-
function runAttached(cmd, args, env) {
|
|
4165
|
-
return new Promise((done) => {
|
|
4166
|
-
const child = spawn4(cmd, args, { stdio: "inherit", env });
|
|
4167
|
-
child.on("error", () => done(-1));
|
|
4168
|
-
child.on("exit", (code) => done(code));
|
|
4169
|
-
});
|
|
4170
|
-
}
|
|
4171
|
-
async function keyFromShell(name, io) {
|
|
4172
|
-
const value = process.env[name];
|
|
4173
|
-
if (!value)
|
|
4174
|
-
return null;
|
|
4175
|
-
if (io.confirm)
|
|
4176
|
-
return await io.confirm(t("agent.keyFromShellAsk", { name })) ? value : null;
|
|
4177
|
-
io.say(t("agent.keyFromShell", { name }));
|
|
4178
|
-
return value;
|
|
4179
|
-
}
|
|
4180
|
-
async function checkReady(id) {
|
|
4181
|
-
const a = readInstalled().find((x) => x.id === id);
|
|
4182
|
-
if (!a)
|
|
4183
|
-
return false;
|
|
4184
|
-
const proc = new AcpProcess;
|
|
4185
|
-
try {
|
|
4186
|
-
await proc.start(a, projectDir("_cek"), agentEnv(id));
|
|
4187
|
-
await proc.request("session/new", { cwd: projectDir("_cek"), mcpServers: [] }, 90000);
|
|
4188
|
-
setReady(id, true);
|
|
4189
|
-
return true;
|
|
4190
|
-
} catch {
|
|
4191
|
-
setReady(id, false);
|
|
4192
|
-
return false;
|
|
4193
|
-
} finally {
|
|
4194
|
-
await proc.stop();
|
|
4195
|
-
}
|
|
4196
|
-
}
|
|
4197
|
-
var isKey = (m) => m.type === "env_var" || !!m.varName;
|
|
4198
|
-
function pick(methods) {
|
|
4199
|
-
return methods.find((m) => m.type === "terminal") ?? methods.find((m) => (!m.type || m.type === "agent") && !isKey(m)) ?? methods.find(isKey);
|
|
4200
|
-
}
|
|
4201
|
-
async function loginAgent(id, io) {
|
|
4202
|
-
const a = readInstalled().find((x) => x.id === id);
|
|
4203
|
-
if (!a)
|
|
4204
|
-
throw new Error(`Agent ${id} is not installed`);
|
|
4205
|
-
const proc = new AcpProcess;
|
|
4206
|
-
let method;
|
|
4207
|
-
if (io.link)
|
|
4208
|
-
proc.on("stderr", linkScanner(io.link));
|
|
4209
|
-
try {
|
|
4210
|
-
const init = await proc.start(a, projectDir("_cek"), agentEnv(id));
|
|
4211
|
-
method = pick(init.authMethods ?? []);
|
|
4212
|
-
if (method && (!method.type || method.type === "agent") && !isKey(method))
|
|
4213
|
-
await proc.request("authenticate", { methodId: method.id }, 10 * 60000);
|
|
4214
|
-
} finally {
|
|
4215
|
-
await proc.stop();
|
|
4216
|
-
}
|
|
4217
|
-
if (method?.type === "terminal") {
|
|
4218
|
-
io.say(method.name || method.description || id);
|
|
4219
|
-
const [cmd, args, env] = agentSpawn(a, { ...agentEnv(id), ...method.env ?? {} }, method.args ?? []);
|
|
4220
|
-
if (await runAttached(cmd, args, env) !== 0)
|
|
4221
|
-
return setReady(id, false), false;
|
|
4222
|
-
} else if (method && isKey(method)) {
|
|
4223
|
-
const name = method.varName || method.id;
|
|
4224
|
-
const value = await keyFromShell(name, io) || await io.ask(name);
|
|
4225
|
-
if (!value)
|
|
4226
|
-
return false;
|
|
4227
|
-
saveAgentEnv(id, { [name]: value.trim() });
|
|
4228
|
-
}
|
|
4229
|
-
return checkReady(id);
|
|
4230
|
-
}
|
|
4231
|
-
|
|
4232
4641
|
// src/cli/commands/agent.ts
|
|
4233
4642
|
var NAMES = { "antigravity-acp": "Antigravity", "codex-acp": "Codex", opencode: "OpenCode" };
|
|
4234
4643
|
var agentName = (id) => NAMES[id] ?? readInstalled().find((a) => a.id === id)?.name ?? id;
|
|
@@ -4243,7 +4652,39 @@ var stateText = (s) => s === "ready" ? color.ok(t("agent.ready")) : s === "login
|
|
|
4243
4652
|
function agentHint(id, s) {
|
|
4244
4653
|
const mark = s === "ready" ? "✔" : s === "login" ? "▲" : "○";
|
|
4245
4654
|
const state = t(s === "ready" ? "agent.ready" : s === "login" ? "agent.needLogin" : "agent.notInstalled");
|
|
4246
|
-
|
|
4655
|
+
const api = id === OPENCODE && s !== "none" ? opencodeApi() : null;
|
|
4656
|
+
const account = api ? t("agent.ownApiTag", { host: hostOf2(api.url) }) : ACCOUNT[id] ? t(ACCOUNT[id]) : "";
|
|
4657
|
+
return `${mark} ${state}${account ? ` · ${account}` : ""}`;
|
|
4658
|
+
}
|
|
4659
|
+
var hostOf2 = (u) => {
|
|
4660
|
+
try {
|
|
4661
|
+
return new URL(u).host;
|
|
4662
|
+
} catch {
|
|
4663
|
+
return u;
|
|
4664
|
+
}
|
|
4665
|
+
};
|
|
4666
|
+
async function ownApi() {
|
|
4667
|
+
const now = opencodeApi();
|
|
4668
|
+
const url = await p.text({ message: t("agent.apiUrl"), placeholder: "https://api.contoh.com/v1", initialValue: now?.url ?? "", validate: (v) => /^https?:\/\/\S+$/i.test(String(v ?? "").trim()) ? undefined : t("agent.apiUrlBad") });
|
|
4669
|
+
if (p.isCancel(url))
|
|
4670
|
+
return;
|
|
4671
|
+
const key = await p.password({ message: t("agent.apiKey") });
|
|
4672
|
+
if (p.isCancel(key))
|
|
4673
|
+
return;
|
|
4674
|
+
const s = p.spinner();
|
|
4675
|
+
s.start(t("agent.apiModelsLoading"));
|
|
4676
|
+
const list = await fetchApiModels(String(url), String(key ?? ""));
|
|
4677
|
+
s.stop(list.length ? t("agent.apiModelsFound", { n: list.length }) : t("agent.apiModelsNone"));
|
|
4678
|
+
const model = list.length ? await p.select({ message: t("agent.apiModel"), options: list.slice(0, 300).map((m) => ({ value: m, label: m })), initialValue: now && list.includes(now.model) ? now.model : list[0], maxItems: 12 }) : await p.text({ message: t("agent.apiModelType"), placeholder: "gpt-4o-mini", initialValue: now?.model ?? "", validate: (v) => String(v ?? "").trim() ? undefined : "—" });
|
|
4679
|
+
if (p.isCancel(model))
|
|
4680
|
+
return;
|
|
4681
|
+
const main = String(model).trim();
|
|
4682
|
+
saveOpencodeApi({ url: String(url), key: String(key ?? ""), models: [main, ...list.filter((m) => m !== main).slice(0, 40)] });
|
|
4683
|
+
log.ok(t("agent.apiSaved", { host: hostOf2(String(url).trim()), model: main }));
|
|
4684
|
+
if (await checkReady(OPENCODE))
|
|
4685
|
+
log.detail(t(runningPid() ? "agent.nextRunning" : "agent.nextStart", { name: agentName(OPENCODE) }));
|
|
4686
|
+
else
|
|
4687
|
+
log.warn(t("agent.apiNotReady"));
|
|
4247
4688
|
}
|
|
4248
4689
|
var io = {
|
|
4249
4690
|
ask: async (label) => {
|
|
@@ -4318,13 +4759,24 @@ async function loginOne(id) {
|
|
|
4318
4759
|
log.warn(t("agent.loginFailed", { name: agentName(id) }));
|
|
4319
4760
|
return ok;
|
|
4320
4761
|
}
|
|
4762
|
+
async function logoutOne(id) {
|
|
4763
|
+
const name = agentName(id);
|
|
4764
|
+
log.info(t("agent.loggingOut", { name }));
|
|
4765
|
+
const r = await logoutAgent(id);
|
|
4766
|
+
if (r === "unsupported")
|
|
4767
|
+
return log.warn(t("agent.logoutUnsupported", { name })), false;
|
|
4768
|
+
log.ok(t(r === "signed-out" ? "agent.loggedOut" : "agent.keyRemoved", { name }));
|
|
4769
|
+
if (runningPid())
|
|
4770
|
+
log.detail(t("agent.logoutRestart", { name }));
|
|
4771
|
+
return true;
|
|
4772
|
+
}
|
|
4321
4773
|
async function agentCommand(args) {
|
|
4322
4774
|
const [sub, raw] = args.rest;
|
|
4323
4775
|
const id = raw ? resolveAgentId(raw) : raw;
|
|
4324
4776
|
if (!sub || sub === "list")
|
|
4325
4777
|
return listAgents();
|
|
4326
4778
|
if (!id)
|
|
4327
|
-
return log.error("hypeframe agent add|login|remove <id>");
|
|
4779
|
+
return log.error("hypeframe agent add|login|logout|remove <id>");
|
|
4328
4780
|
if (sub === "add")
|
|
4329
4781
|
return void await addAgent(id, args.flags.download === true);
|
|
4330
4782
|
if (sub === "login") {
|
|
@@ -4332,11 +4784,16 @@ async function agentCommand(args) {
|
|
|
4332
4784
|
return log.error(t("agent.notInstalledYet", { name: agentName(id) }));
|
|
4333
4785
|
return void await loginOne(id);
|
|
4334
4786
|
}
|
|
4787
|
+
if (sub === "logout") {
|
|
4788
|
+
if (agentState(id) === "none")
|
|
4789
|
+
return log.error(t("agent.notInstalledYet", { name: agentName(id) }));
|
|
4790
|
+
return void await logoutOne(id);
|
|
4791
|
+
}
|
|
4335
4792
|
if (sub === "remove") {
|
|
4336
4793
|
removeAgent(id);
|
|
4337
4794
|
return log.ok(t("agent.removed", { name: agentName(id) }));
|
|
4338
4795
|
}
|
|
4339
|
-
log.error("hypeframe agent list|add|login|remove codex|antigravity|opencode");
|
|
4796
|
+
log.error("hypeframe agent list|add|login|logout|remove codex|antigravity|opencode");
|
|
4340
4797
|
}
|
|
4341
4798
|
async function agentMenu() {
|
|
4342
4799
|
for (;; ) {
|
|
@@ -4352,7 +4809,8 @@ async function agentMenu() {
|
|
|
4352
4809
|
options: [
|
|
4353
4810
|
...state === "none" ? [{ value: "add", label: t("agent.add") }] : [],
|
|
4354
4811
|
...state === "login" ? [{ value: "login", label: t("agent.loginNow") }] : [],
|
|
4355
|
-
...state === "ready" ? [{ value: "
|
|
4812
|
+
...state === "ready" ? [{ value: "switch", label: t("agent.login") }, { value: "logout", label: t("agent.logout") }] : [],
|
|
4813
|
+
...choice === OPENCODE && state !== "none" ? [{ value: "api", label: opencodeApi() ? t("agent.ownApiChange", { host: hostOf2(opencodeApi().url) }) : t("agent.ownApi") }, ...opencodeApi() ? [{ value: "api-off", label: t("agent.ownApiOff") }] : []] : [],
|
|
4356
4814
|
...state !== "none" ? [{ value: "remove", label: t("agent.remove") }] : [],
|
|
4357
4815
|
{ value: "", label: color.muted(t("agent.back")) }
|
|
4358
4816
|
]
|
|
@@ -4364,6 +4822,17 @@ async function agentMenu() {
|
|
|
4364
4822
|
await addAgent(choice);
|
|
4365
4823
|
if (action === "login")
|
|
4366
4824
|
await loginOne(choice);
|
|
4825
|
+
if (action === "switch")
|
|
4826
|
+
await logoutAgent(choice).catch(() => "unsupported"), await loginOne(choice);
|
|
4827
|
+
if (action === "api")
|
|
4828
|
+
await ownApi();
|
|
4829
|
+
if (action === "api-off")
|
|
4830
|
+
removeOpencodeApi(), log.ok(t("agent.ownApiOffDone"));
|
|
4831
|
+
if (action === "logout") {
|
|
4832
|
+
const sure = await p.confirm({ message: t("agent.logoutAsk", { name: agentName(choice) }), initialValue: false });
|
|
4833
|
+
if (sure === true)
|
|
4834
|
+
await logoutOne(choice);
|
|
4835
|
+
}
|
|
4367
4836
|
if (action === "remove") {
|
|
4368
4837
|
const sure = await p.confirm({ message: t("agent.removeAsk", { name: agentName(choice) }), initialValue: false });
|
|
4369
4838
|
if (sure === true)
|
|
@@ -4443,8 +4912,8 @@ async function config(args) {
|
|
|
4443
4912
|
|
|
4444
4913
|
// src/cli/commands/doctor.ts
|
|
4445
4914
|
import { spawnSync as spawnSync4 } from "node:child_process";
|
|
4446
|
-
import
|
|
4447
|
-
import
|
|
4915
|
+
import fs22 from "node:fs";
|
|
4916
|
+
import path18 from "node:path";
|
|
4448
4917
|
var mark = { ok: color.ok(icon.ok), warn: color.warn(icon.warn), error: color.error(icon.error) };
|
|
4449
4918
|
async function reach(url) {
|
|
4450
4919
|
const t0 = Date.now();
|
|
@@ -4473,10 +4942,10 @@ async function doctor(args) {
|
|
|
4473
4942
|
show({ label: "Node.js", result: maj > 20 || maj === 20 && min >= 3 ? "ok" : "error", detail: `${process.versions.node}${maj < 20 || maj === 20 && min < 3 ? ` ${t("doctor.nodeOld")}` : ""}` });
|
|
4474
4943
|
}
|
|
4475
4944
|
try {
|
|
4476
|
-
const probe =
|
|
4477
|
-
|
|
4478
|
-
|
|
4479
|
-
const st =
|
|
4945
|
+
const probe = path18.join(dataDir(), `.probe-${process.pid}`);
|
|
4946
|
+
fs22.writeFileSync(probe, "x");
|
|
4947
|
+
fs22.rmSync(probe);
|
|
4948
|
+
const st = fs22.statfsSync(dataDir());
|
|
4480
4949
|
const free = st.bavail * st.bsize;
|
|
4481
4950
|
show({ label: t("doctor.disk"), result: free > 2 * 1024 ** 3 ? "ok" : "warn", detail: `${dataDir()} ${color.muted(icon.dot)} ${t("doctor.free", { size: bytes2(free) })}` });
|
|
4482
4951
|
} catch (e) {
|
|
@@ -4523,21 +4992,21 @@ async function doctor(args) {
|
|
|
4523
4992
|
}
|
|
4524
4993
|
|
|
4525
4994
|
// src/cli/commands/history.ts
|
|
4526
|
-
import
|
|
4527
|
-
import
|
|
4995
|
+
import fs23 from "node:fs";
|
|
4996
|
+
import path19 from "node:path";
|
|
4528
4997
|
function readHistory2(hours = 24) {
|
|
4529
4998
|
const root = renderDir();
|
|
4530
4999
|
const since = Date.now() - hours * 3600000;
|
|
4531
5000
|
const out = [];
|
|
4532
|
-
for (const name of
|
|
5001
|
+
for (const name of fs23.readdirSync(root)) {
|
|
4533
5002
|
if (!JOB_ID.test(name))
|
|
4534
5003
|
continue;
|
|
4535
5004
|
try {
|
|
4536
|
-
const j = JSON.parse(
|
|
5005
|
+
const j = JSON.parse(fs23.readFileSync(path19.join(root, name, "status.json"), "utf8"));
|
|
4537
5006
|
if ((j.diperbarui || j.dibuat) < since)
|
|
4538
5007
|
continue;
|
|
4539
|
-
const f = j.hasilBerkas ?
|
|
4540
|
-
out.push({ job: j, file: f &&
|
|
5008
|
+
const f = j.hasilBerkas ? path19.join(root, name, j.hasilBerkas) : null;
|
|
5009
|
+
out.push({ job: j, file: f && fs23.existsSync(f) ? f : null });
|
|
4541
5010
|
} catch {}
|
|
4542
5011
|
}
|
|
4543
5012
|
return out.sort((a, b) => (b.job.diperbarui || 0) - (a.job.diperbarui || 0));
|
|
@@ -4564,30 +5033,30 @@ function history() {
|
|
|
4564
5033
|
|
|
4565
5034
|
// src/cli/commands/maintenance.ts
|
|
4566
5035
|
import { spawnSync as spawnSync5 } from "node:child_process";
|
|
4567
|
-
import
|
|
5036
|
+
import fs24 from "node:fs";
|
|
4568
5037
|
import os4 from "node:os";
|
|
4569
|
-
import
|
|
5038
|
+
import path20 from "node:path";
|
|
4570
5039
|
async function clean() {
|
|
4571
5040
|
if (runningPid()) {
|
|
4572
5041
|
log.warn(t("clean.running"));
|
|
4573
5042
|
return;
|
|
4574
5043
|
}
|
|
4575
|
-
const targets = [
|
|
4576
|
-
for (const job of
|
|
5044
|
+
const targets = [path20.join(cacheDir(), "chrome"), path20.join(cacheDir(), "halaman"), path20.join(logDir(), "hypeframe.log.1")];
|
|
5045
|
+
for (const job of fs24.readdirSync(renderDir())) {
|
|
4577
5046
|
if (!JOB_ID.test(job))
|
|
4578
5047
|
continue;
|
|
4579
5048
|
try {
|
|
4580
|
-
const s = JSON.parse(
|
|
5049
|
+
const s = JSON.parse(fs24.readFileSync(path20.join(renderDir(), job, "status.json"), "utf8")).status;
|
|
4581
5050
|
if (s === "gagal" || s === "batal" || s === "unggah")
|
|
4582
|
-
targets.push(
|
|
5051
|
+
targets.push(path20.join(renderDir(), job));
|
|
4583
5052
|
} catch {
|
|
4584
|
-
targets.push(
|
|
5053
|
+
targets.push(path20.join(renderDir(), job));
|
|
4585
5054
|
}
|
|
4586
5055
|
}
|
|
4587
5056
|
let freed = 0;
|
|
4588
5057
|
for (const p of targets) {
|
|
4589
5058
|
freed += await sizeOf(p);
|
|
4590
|
-
|
|
5059
|
+
fs24.rmSync(p, { recursive: true, force: true });
|
|
4591
5060
|
}
|
|
4592
5061
|
log.ok(t("clean.done", { size: bytes2(freed) }));
|
|
4593
5062
|
}
|
|
@@ -4596,7 +5065,7 @@ function report() {
|
|
|
4596
5065
|
const a = readAccount();
|
|
4597
5066
|
let recent = "";
|
|
4598
5067
|
try {
|
|
4599
|
-
recent =
|
|
5068
|
+
recent = fs24.readFileSync(path20.join(logDir(), "hypeframe.log"), "utf8").split(`
|
|
4600
5069
|
`).slice(-400).join(`
|
|
4601
5070
|
`);
|
|
4602
5071
|
} catch {
|
|
@@ -4617,8 +5086,8 @@ function report() {
|
|
|
4617
5086
|
recent
|
|
4618
5087
|
];
|
|
4619
5088
|
const stamp = new Date().toISOString().slice(0, 19).replace(/[-:T]/g, "");
|
|
4620
|
-
const file =
|
|
4621
|
-
|
|
5089
|
+
const file = path20.join(dataDir(), `laporan-${stamp}.txt`);
|
|
5090
|
+
fs24.writeFileSync(file, mask(lines.join(`
|
|
4622
5091
|
`)), { mode: 384 });
|
|
4623
5092
|
log.ok(t("report.done", { file }));
|
|
4624
5093
|
log.detail(t("report.hint"));
|
|
@@ -4654,13 +5123,13 @@ function openWeb(args) {
|
|
|
4654
5123
|
}
|
|
4655
5124
|
|
|
4656
5125
|
// src/cli/commands/status.ts
|
|
4657
|
-
import
|
|
4658
|
-
import
|
|
5126
|
+
import fs25 from "node:fs";
|
|
5127
|
+
import path21 from "node:path";
|
|
4659
5128
|
function statusRows(args) {
|
|
4660
5129
|
const s = resolveSettings(args?.flags);
|
|
4661
5130
|
const a = readAccount();
|
|
4662
5131
|
const pid = runningPid();
|
|
4663
|
-
const chrome = findChrome() ||
|
|
5132
|
+
const chrome = findChrome() || fs25.existsSync(path21.join(cacheDir(), "chrome"));
|
|
4664
5133
|
const recent = readHistory2();
|
|
4665
5134
|
const k = (key) => color.muted(t(key));
|
|
4666
5135
|
return [
|
|
@@ -4882,7 +5351,7 @@ function help() {
|
|
|
4882
5351
|
["open", t("help.open")],
|
|
4883
5352
|
["doctor", t("help.doctor")],
|
|
4884
5353
|
["bench", t("help.bench")],
|
|
4885
|
-
["agent list|add|login|remove", t("help.agent")],
|
|
5354
|
+
["agent list|add|login|logout|remove", t("help.agent")],
|
|
4886
5355
|
["chromium", t("help.chromium")],
|
|
4887
5356
|
["history", t("help.history")],
|
|
4888
5357
|
["autostart on|off", t("help.autostart")],
|