hypeframe 0.5.1 → 0.6.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 +6 -2
- package/dist/index.js +545 -295
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -220,6 +220,13 @@ var id = {
|
|
|
220
220
|
"agent.webHint": "Mengobrol dengan agen dilakukan di HypeFrame Web, halaman Asisten, selama mesin menyala.",
|
|
221
221
|
"agent.toolNoTab": "Agen memanggil alat HypeFrame, tapi tab HypeFrame Web tidak terbuka. Buka HypeFrame Web lalu kirim pesannya lagi.",
|
|
222
222
|
"agent.toolNoAnswer": "Agen memanggil alat HypeFrame, tapi HypeFrame Web tidak menjawab. Pastikan tabnya terbuka.",
|
|
223
|
+
"agent.unpacking": "100% · membuka paket (di HP bisa sampai beberapa menit)...",
|
|
224
|
+
"linux.preparing": "Agen di HP berjalan di Linux mini (Ubuntu lewat proot). Menyiapkannya sekali saja, unduhan sekitar 100 MB...",
|
|
225
|
+
"linux.pkg": "Memasang proot-distro...",
|
|
226
|
+
"linux.distro": "Mengunduh Ubuntu...",
|
|
227
|
+
"linux.apt": "Menyiapkan Ubuntu (sertifikat dan curl)...",
|
|
228
|
+
"linux.ready": "Linux mini siap.",
|
|
229
|
+
"linux.openUrl": "Buka di browser HP: {url}",
|
|
223
230
|
"agent.keyFromShellAsk": "Pakai {name} yang sudah ada di terminal ini?",
|
|
224
231
|
"agent.keyFromShell": "Memakai {name} dari terminal ini (disimpan untuk agen ini saja).",
|
|
225
232
|
"agent.own": "{name} sudah terpasang di komputer ini ({path}); yang itu dipakai, tidak diunduh lagi.",
|
|
@@ -387,6 +394,13 @@ var en = {
|
|
|
387
394
|
"agent.webHint": "Chatting with agents happens in HypeFrame Web, on the Assistant page, while the engine runs.",
|
|
388
395
|
"agent.toolNoTab": "An agent called a HypeFrame tool, but no HypeFrame Web tab is open. Open HypeFrame Web and send the message again.",
|
|
389
396
|
"agent.toolNoAnswer": "An agent called a HypeFrame tool, but HypeFrame Web did not answer. Make sure its tab is open.",
|
|
397
|
+
"agent.unpacking": "100% · unpacking (this can take a few minutes on a phone)...",
|
|
398
|
+
"linux.preparing": "Agents on a phone run in a Linux mini (Ubuntu under proot). Setting it up once, about 100 MB to download...",
|
|
399
|
+
"linux.pkg": "Installing proot-distro...",
|
|
400
|
+
"linux.distro": "Downloading Ubuntu...",
|
|
401
|
+
"linux.apt": "Preparing Ubuntu (certificates and curl)...",
|
|
402
|
+
"linux.ready": "Linux mini ready.",
|
|
403
|
+
"linux.openUrl": "Open in the phone browser: {url}",
|
|
390
404
|
"agent.keyFromShellAsk": "Use the {name} already set in this terminal?",
|
|
391
405
|
"agent.keyFromShell": "Using {name} from this terminal (saved for this agent only).",
|
|
392
406
|
"agent.own": "{name} is already installed on this computer ({path}); that copy is used, nothing is downloaded.",
|
|
@@ -563,7 +577,7 @@ var log = {
|
|
|
563
577
|
};
|
|
564
578
|
|
|
565
579
|
// src/cli/commands/start.ts
|
|
566
|
-
import
|
|
580
|
+
import crypto8 from "node:crypto";
|
|
567
581
|
|
|
568
582
|
// ../protocol/src/index.ts
|
|
569
583
|
var PROTOCOL_VERSION = 1;
|
|
@@ -589,13 +603,13 @@ var EngineError = {
|
|
|
589
603
|
};
|
|
590
604
|
|
|
591
605
|
// src/agent/service.ts
|
|
592
|
-
import
|
|
593
|
-
import
|
|
594
|
-
import
|
|
606
|
+
import crypto3 from "node:crypto";
|
|
607
|
+
import fs10 from "node:fs";
|
|
608
|
+
import path7 from "node:path";
|
|
595
609
|
// package.json
|
|
596
610
|
var package_default = {
|
|
597
611
|
name: "hypeframe",
|
|
598
|
-
version: "0.
|
|
612
|
+
version: "0.6.0",
|
|
599
613
|
description: "Local engine for HypeFrame Web: code clips, video renders and AI agents run on your own machine; the web is just the view.",
|
|
600
614
|
keywords: [
|
|
601
615
|
"hypeframe",
|
|
@@ -693,10 +707,168 @@ async function fetchRegistry() {
|
|
|
693
707
|
return (Array.isArray(j.agents) ? j.agents : []).filter(valid).map((a) => local ? a : { ...a, distribution: { ...a.distribution, local: undefined } });
|
|
694
708
|
}
|
|
695
709
|
|
|
696
|
-
// src/agent/
|
|
710
|
+
// src/agent/linux.ts
|
|
711
|
+
import { spawnSync as spawnSync2 } from "node:child_process";
|
|
697
712
|
import crypto from "node:crypto";
|
|
713
|
+
import fs7 from "node:fs";
|
|
714
|
+
import path4 from "node:path";
|
|
715
|
+
|
|
716
|
+
// src/util/which.ts
|
|
698
717
|
import fs6 from "node:fs";
|
|
699
718
|
import path3 from "node:path";
|
|
719
|
+
function isAndroid() {
|
|
720
|
+
return process.platform === "android" || !!process.env.TERMUX_VERSION || (process.env.PREFIX ?? "").includes("/com.termux/");
|
|
721
|
+
}
|
|
722
|
+
function onPath(name) {
|
|
723
|
+
if (!/^[\w.@+-]{1,80}$/.test(name))
|
|
724
|
+
return null;
|
|
725
|
+
const file = process.platform === "win32" ? /\.exe$/i.test(name) ? name : `${name}.exe` : name;
|
|
726
|
+
for (const dir of (process.env.PATH || "").split(path3.delimiter).filter(Boolean)) {
|
|
727
|
+
const f = path3.join(dir, file);
|
|
728
|
+
try {
|
|
729
|
+
const st = fs6.statSync(f);
|
|
730
|
+
if (st.isFile() && (process.platform === "win32" || st.mode & 73))
|
|
731
|
+
return f;
|
|
732
|
+
} catch {}
|
|
733
|
+
}
|
|
734
|
+
return null;
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
// src/agent/linux.ts
|
|
738
|
+
var DISTRO = "ubuntu";
|
|
739
|
+
var prefix = () => process.env.PREFIX || "/data/data/com.termux/files/usr";
|
|
740
|
+
function linuxDir() {
|
|
741
|
+
const d = path4.join(dataDir(), "linux");
|
|
742
|
+
fs7.mkdirSync(path4.join(d, "bin"), { recursive: true });
|
|
743
|
+
return d;
|
|
744
|
+
}
|
|
745
|
+
var rootfs = () => path4.join(prefix(), "var", "lib", "proot-distro", "installed-rootfs", DISTRO);
|
|
746
|
+
var readyFile = () => path4.join(linuxDir(), "siap");
|
|
747
|
+
var openFile = () => path4.join(linuxDir(), "buka-url");
|
|
748
|
+
var bridgeScript = () => path4.join(linuxDir(), "bin", "hf-mcp-bridge");
|
|
749
|
+
function linuxReady() {
|
|
750
|
+
return !!onPath("proot-distro") && fs7.existsSync(path4.join(rootfs(), "usr", "bin", "env")) && fs7.existsSync(readyFile());
|
|
751
|
+
}
|
|
752
|
+
var shQuote = (s) => `'${String(s).replace(/'/g, `'\\''`)}'`;
|
|
753
|
+
var VAR = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
754
|
+
function linuxCommand(cmd, args, env = {}) {
|
|
755
|
+
const hf = dataDir();
|
|
756
|
+
const bin = path4.join(linuxDir(), "bin");
|
|
757
|
+
const vars = {
|
|
758
|
+
HOME: "/root",
|
|
759
|
+
LANG: "C.UTF-8",
|
|
760
|
+
DISPLAY: ":0",
|
|
761
|
+
BROWSER: path4.join(bin, "xdg-open"),
|
|
762
|
+
PATH: `${bin}:/root/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin`,
|
|
763
|
+
...env
|
|
764
|
+
};
|
|
765
|
+
const script = [
|
|
766
|
+
"#!/bin/bash",
|
|
767
|
+
"# HypeFrame: one command in the Linux mini (written by the engine)",
|
|
768
|
+
...Object.entries(vars).filter(([k]) => VAR.test(k)).map(([k, v]) => `export ${k}=${shQuote(v)}`),
|
|
769
|
+
`exec ${[cmd, ...args].map(shQuote).join(" ")}`,
|
|
770
|
+
""
|
|
771
|
+
].join(`
|
|
772
|
+
`);
|
|
773
|
+
const dir = path4.join(linuxDir(), "jalan");
|
|
774
|
+
fs7.mkdirSync(dir, { recursive: true, mode: 448 });
|
|
775
|
+
const file = path4.join(dir, `${crypto.createHash("sha256").update(script).digest("hex").slice(0, 24)}.sh`);
|
|
776
|
+
if (!fs7.existsSync(file))
|
|
777
|
+
fs7.writeFileSync(file, script, { mode: 384 });
|
|
778
|
+
return ["proot-distro", ["login", DISTRO, "--shared-tmp", "--bind", `${hf}:${hf}`, "--", "/bin/bash", file]];
|
|
779
|
+
}
|
|
780
|
+
var BRIDGE_SH = `#!/bin/bash
|
|
781
|
+
# HypeFrame tools for an agent in the Linux mini: stdio MCP <-> the engine on 127.0.0.1 (HF_MCP_URL, HF_MCP_KUNCI)
|
|
782
|
+
while IFS= read -r line || [ -n "$line" ]; do
|
|
783
|
+
[ -z "$line" ] && continue
|
|
784
|
+
out=$(printf '%s' "$line" | curl -sS --max-time 600 -X POST -H "authorization: Bearer $HF_MCP_KUNCI" -H 'content-type: application/json' --data-binary @- "$HF_MCP_URL" 2>/dev/null)
|
|
785
|
+
if [ $? -ne 0 ]; then
|
|
786
|
+
id=$(printf '%s' "$line" | sed -nE 's/.*"id"[[:space:]]*:[[:space:]]*("[^"]*"|[0-9]+).*/\\1/p')
|
|
787
|
+
[ -n "$id" ] && printf '{"jsonrpc":"2.0","id":%s,"error":{"code":-32000,"message":"The HypeFrame engine is not running on this phone."}}\\n' "$id"
|
|
788
|
+
continue
|
|
789
|
+
fi
|
|
790
|
+
[ -n "$out" ] && printf '%s\\n' "$out"
|
|
791
|
+
done
|
|
792
|
+
`;
|
|
793
|
+
function writeHelpers() {
|
|
794
|
+
const bin = path4.join(linuxDir(), "bin");
|
|
795
|
+
const open = `#!/bin/sh
|
|
796
|
+
# HypeFrame: open a link in the phone's browser (the engine watches this file)
|
|
797
|
+
[ -n "$1" ] || exit 0
|
|
798
|
+
printf '%s\\n' "$1" >> "${openFile()}"
|
|
799
|
+
`;
|
|
800
|
+
fs7.writeFileSync(path4.join(bin, "xdg-open"), open, { mode: 493 });
|
|
801
|
+
for (const n of ["x-www-browser", "www-browser", "sensible-browser"])
|
|
802
|
+
fs7.writeFileSync(path4.join(bin, n), open, { mode: 493 });
|
|
803
|
+
fs7.writeFileSync(bridgeScript(), BRIDGE_SH, { mode: 493 });
|
|
804
|
+
}
|
|
805
|
+
function prepareLinux(say = () => {
|
|
806
|
+
return;
|
|
807
|
+
}) {
|
|
808
|
+
const run = (cmd, args) => spawnSync2(cmd, args, { stdio: ["ignore", "inherit", "inherit"], env: { ...process.env, DEBIAN_FRONTEND: "noninteractive" } }).status === 0;
|
|
809
|
+
writeHelpers();
|
|
810
|
+
if (linuxReady())
|
|
811
|
+
return;
|
|
812
|
+
say("linux.preparing");
|
|
813
|
+
if (!onPath("proot-distro")) {
|
|
814
|
+
say("linux.pkg");
|
|
815
|
+
if (!run("pkg", ["install", "-y", "proot-distro"]))
|
|
816
|
+
throw new Error("pkg install proot-distro");
|
|
817
|
+
}
|
|
818
|
+
if (!fs7.existsSync(path4.join(rootfs(), "usr", "bin", "env"))) {
|
|
819
|
+
say("linux.distro");
|
|
820
|
+
if (!run("proot-distro", ["install", DISTRO]))
|
|
821
|
+
throw new Error(`proot-distro install ${DISTRO}`);
|
|
822
|
+
}
|
|
823
|
+
say("linux.apt");
|
|
824
|
+
const [cmd, args] = linuxCommand("/bin/sh", ["-c", "apt-get update -q && DEBIAN_FRONTEND=noninteractive apt-get install -y -q ca-certificates curl"]);
|
|
825
|
+
if (!run(cmd, args))
|
|
826
|
+
throw new Error("apt-get install ca-certificates curl");
|
|
827
|
+
fs7.writeFileSync(readyFile(), `${DISTRO}
|
|
828
|
+
`);
|
|
829
|
+
say("linux.ready");
|
|
830
|
+
}
|
|
831
|
+
function runInLinux(script) {
|
|
832
|
+
const [cmd, args] = linuxCommand("/bin/bash", ["-c", script]);
|
|
833
|
+
return spawnSync2(cmd, args, { stdio: ["ignore", "inherit", "inherit"] }).status === 0;
|
|
834
|
+
}
|
|
835
|
+
function watchOpenRequests(open, everyMs = 1000) {
|
|
836
|
+
const f = openFile();
|
|
837
|
+
try {
|
|
838
|
+
fs7.writeFileSync(f, "");
|
|
839
|
+
} catch {}
|
|
840
|
+
let seen = 0;
|
|
841
|
+
const tick = () => {
|
|
842
|
+
let text = "";
|
|
843
|
+
try {
|
|
844
|
+
text = fs7.readFileSync(f, "utf8");
|
|
845
|
+
} catch {
|
|
846
|
+
return;
|
|
847
|
+
}
|
|
848
|
+
if (text.length < seen)
|
|
849
|
+
seen = 0;
|
|
850
|
+
const fresh = text.slice(seen);
|
|
851
|
+
const end = fresh.lastIndexOf(`
|
|
852
|
+
`);
|
|
853
|
+
if (end < 0)
|
|
854
|
+
return;
|
|
855
|
+
seen += end + 1;
|
|
856
|
+
for (const line of fresh.slice(0, end).split(`
|
|
857
|
+
`)) {
|
|
858
|
+
const url = line.trim();
|
|
859
|
+
if (/^https?:\/\/[^\s]{1,2000}$/.test(url))
|
|
860
|
+
open(url);
|
|
861
|
+
}
|
|
862
|
+
};
|
|
863
|
+
const timer = setInterval(tick, everyMs);
|
|
864
|
+
timer.unref?.();
|
|
865
|
+
return () => clearInterval(timer);
|
|
866
|
+
}
|
|
867
|
+
|
|
868
|
+
// src/agent/session.ts
|
|
869
|
+
import crypto2 from "node:crypto";
|
|
870
|
+
import fs8 from "node:fs";
|
|
871
|
+
import path5 from "node:path";
|
|
700
872
|
|
|
701
873
|
// src/agent/acp.ts
|
|
702
874
|
import { spawn } from "node:child_process";
|
|
@@ -711,6 +883,13 @@ class RpcError extends Error {
|
|
|
711
883
|
this.data = data;
|
|
712
884
|
}
|
|
713
885
|
}
|
|
886
|
+
function agentSpawn(agent, env = {}, extraArgs = []) {
|
|
887
|
+
if (agent.launch.linux) {
|
|
888
|
+
const [cmd, args] = linuxCommand(agent.launch.cmd, [...agent.launch.args, ...extraArgs], { ...agent.launch.env, ...env });
|
|
889
|
+
return [cmd, args, { ...process.env }];
|
|
890
|
+
}
|
|
891
|
+
return [agent.launch.cmd, [...agent.launch.args, ...extraArgs], { ...process.env, ...agent.launch.env, ...env }];
|
|
892
|
+
}
|
|
714
893
|
|
|
715
894
|
class AcpProcess extends EventEmitter {
|
|
716
895
|
child;
|
|
@@ -730,7 +909,8 @@ class AcpProcess extends EventEmitter {
|
|
|
730
909
|
return this.stderrTail;
|
|
731
910
|
}
|
|
732
911
|
async start(agent, cwd, env = {}, timeoutMs = 180000) {
|
|
733
|
-
const
|
|
912
|
+
const [cmd, args, childEnv] = agentSpawn(agent, env);
|
|
913
|
+
const child = spawn(cmd, args, { cwd, env: childEnv, stdio: ["pipe", "pipe", "pipe"], windowsHide: true });
|
|
734
914
|
this.child = child;
|
|
735
915
|
child.stderr?.on("data", (d) => this.stderrTail = (this.stderrTail + d).slice(-4096));
|
|
736
916
|
child.stdin?.on("error", () => {
|
|
@@ -846,7 +1026,7 @@ function splitId(id) {
|
|
|
846
1026
|
}
|
|
847
1027
|
var lexists = (p) => {
|
|
848
1028
|
try {
|
|
849
|
-
|
|
1029
|
+
fs8.lstatSync(p);
|
|
850
1030
|
return true;
|
|
851
1031
|
} catch {
|
|
852
1032
|
return false;
|
|
@@ -855,16 +1035,16 @@ var lexists = (p) => {
|
|
|
855
1035
|
function insideFolder(folder, p) {
|
|
856
1036
|
if (typeof p !== "string" || !p)
|
|
857
1037
|
return false;
|
|
858
|
-
const abs =
|
|
859
|
-
const rel =
|
|
860
|
-
if (rel.startsWith("..") ||
|
|
1038
|
+
const abs = path5.resolve(folder, p);
|
|
1039
|
+
const rel = path5.relative(folder, abs);
|
|
1040
|
+
if (rel.startsWith("..") || path5.isAbsolute(rel))
|
|
861
1041
|
return false;
|
|
862
1042
|
let probe = abs;
|
|
863
|
-
while (!lexists(probe) &&
|
|
864
|
-
probe =
|
|
1043
|
+
while (!lexists(probe) && path5.dirname(probe) !== probe)
|
|
1044
|
+
probe = path5.dirname(probe);
|
|
865
1045
|
try {
|
|
866
|
-
const r =
|
|
867
|
-
return !(r.startsWith("..") ||
|
|
1046
|
+
const r = path5.relative(fs8.realpathSync(folder), fs8.realpathSync(probe));
|
|
1047
|
+
return !(r.startsWith("..") || path5.isAbsolute(r));
|
|
868
1048
|
} catch {
|
|
869
1049
|
return false;
|
|
870
1050
|
}
|
|
@@ -909,8 +1089,8 @@ class AgentSessions {
|
|
|
909
1089
|
}
|
|
910
1090
|
this.o.onExit(agentId, code);
|
|
911
1091
|
});
|
|
912
|
-
const cwd =
|
|
913
|
-
|
|
1092
|
+
const cwd = path5.join(agentDir(), agentId, "kerja");
|
|
1093
|
+
fs8.mkdirSync(cwd, { recursive: true });
|
|
914
1094
|
const p = proc.start(agent, cwd, this.o.env?.(agentId) ?? {}, this.o.startTimeoutMs ?? 180000).then((init) => {
|
|
915
1095
|
const entry = { proc, init };
|
|
916
1096
|
this.procs.set(agentId, entry);
|
|
@@ -931,9 +1111,9 @@ class AgentSessions {
|
|
|
931
1111
|
if (live)
|
|
932
1112
|
return { sessionId: key(resume), init, raw: {}, dimuat: "hidup", routeId: live.routeId, opsi: live.opsi ?? {} };
|
|
933
1113
|
const cwd = projectDir(projectId);
|
|
934
|
-
|
|
935
|
-
const routeId =
|
|
936
|
-
const params = { cwd, mcpServers: this.o.mcpServers(cwd, projectId, routeId) };
|
|
1114
|
+
fs8.writeFileSync(path5.join(cwd, "AGENTS.md"), AGENTS_MD);
|
|
1115
|
+
const routeId = crypto2.randomBytes(9).toString("base64url");
|
|
1116
|
+
const params = { cwd, mcpServers: this.o.mcpServers(cwd, projectId, routeId, this.o.agent(agentId)) };
|
|
937
1117
|
const limit = this.o.sessionTimeoutMs ?? 90000;
|
|
938
1118
|
let raw;
|
|
939
1119
|
let dimuat = "baru";
|
|
@@ -1084,12 +1264,12 @@ class AgentSessions {
|
|
|
1084
1264
|
if (method === "fs/read_text_file") {
|
|
1085
1265
|
if (!insideFolder(s.cwd, p.path))
|
|
1086
1266
|
throw new RpcError(-32602, OUTSIDE);
|
|
1087
|
-
const st =
|
|
1267
|
+
const st = fs8.statSync(path5.resolve(s.cwd, p.path), { throwIfNoEntry: false });
|
|
1088
1268
|
if (!st?.isFile())
|
|
1089
1269
|
throw new RpcError(-32602, "Not a regular file");
|
|
1090
1270
|
if (st.size > MAX_READ)
|
|
1091
1271
|
throw new RpcError(-32602, "File too large (over 10 MB)");
|
|
1092
|
-
let content =
|
|
1272
|
+
let content = fs8.readFileSync(path5.resolve(s.cwd, p.path), "utf8");
|
|
1093
1273
|
if (p.line || p.limit) {
|
|
1094
1274
|
const lines = content.split(`
|
|
1095
1275
|
`);
|
|
@@ -1102,9 +1282,9 @@ class AgentSessions {
|
|
|
1102
1282
|
if (method === "fs/write_text_file") {
|
|
1103
1283
|
if (!insideFolder(s.cwd, p.path))
|
|
1104
1284
|
throw new RpcError(-32602, OUTSIDE);
|
|
1105
|
-
const f =
|
|
1106
|
-
|
|
1107
|
-
|
|
1285
|
+
const f = path5.resolve(s.cwd, p.path);
|
|
1286
|
+
fs8.mkdirSync(path5.dirname(f), { recursive: true });
|
|
1287
|
+
fs8.writeFileSync(f, String(p.content ?? ""));
|
|
1108
1288
|
return null;
|
|
1109
1289
|
}
|
|
1110
1290
|
throw new RpcError(-32601, `Method not found: ${method}`);
|
|
@@ -1112,8 +1292,8 @@ class AgentSessions {
|
|
|
1112
1292
|
}
|
|
1113
1293
|
|
|
1114
1294
|
// src/agent/store.ts
|
|
1115
|
-
import
|
|
1116
|
-
import
|
|
1295
|
+
import fs9 from "node:fs";
|
|
1296
|
+
import path6 from "node:path";
|
|
1117
1297
|
function setReady(id, ready) {
|
|
1118
1298
|
const a = readInstalled().find((x) => x.id === id);
|
|
1119
1299
|
if (a)
|
|
@@ -1123,15 +1303,15 @@ var AGENT_ID = /^[a-z0-9][a-z0-9-]{0,39}$/;
|
|
|
1123
1303
|
var folder = (id) => {
|
|
1124
1304
|
if (typeof id !== "string" || !AGENT_ID.test(id))
|
|
1125
1305
|
throw new Error(`Invalid agent id: ${JSON.stringify(String(id)).slice(0, 60)}`);
|
|
1126
|
-
return
|
|
1306
|
+
return path6.join(agentDir(), id);
|
|
1127
1307
|
};
|
|
1128
1308
|
function readInstalled() {
|
|
1129
1309
|
const out = [];
|
|
1130
|
-
for (const id of
|
|
1310
|
+
for (const id of fs9.readdirSync(agentDir())) {
|
|
1131
1311
|
if (!AGENT_ID.test(id))
|
|
1132
1312
|
continue;
|
|
1133
1313
|
try {
|
|
1134
|
-
const a = JSON.parse(
|
|
1314
|
+
const a = JSON.parse(fs9.readFileSync(path6.join(folder(id), "agent.json"), "utf8"));
|
|
1135
1315
|
if (a.id === id && a.launch?.cmd)
|
|
1136
1316
|
out.push(a);
|
|
1137
1317
|
} catch {}
|
|
@@ -1139,26 +1319,26 @@ function readInstalled() {
|
|
|
1139
1319
|
return out;
|
|
1140
1320
|
}
|
|
1141
1321
|
function writeInstalled(a) {
|
|
1142
|
-
|
|
1143
|
-
const f =
|
|
1144
|
-
|
|
1145
|
-
|
|
1322
|
+
fs9.mkdirSync(folder(a.id), { recursive: true });
|
|
1323
|
+
const f = path6.join(folder(a.id), "agent.json");
|
|
1324
|
+
fs9.writeFileSync(`${f}.tmp`, JSON.stringify(a, null, 2));
|
|
1325
|
+
fs9.renameSync(`${f}.tmp`, f);
|
|
1146
1326
|
}
|
|
1147
1327
|
function removeAgent(id) {
|
|
1148
|
-
|
|
1328
|
+
fs9.rmSync(folder(id), { recursive: true, force: true });
|
|
1149
1329
|
}
|
|
1150
1330
|
function agentEnv(id) {
|
|
1151
1331
|
try {
|
|
1152
|
-
return JSON.parse(
|
|
1332
|
+
return JSON.parse(fs9.readFileSync(path6.join(folder(id), "env.json"), "utf8"));
|
|
1153
1333
|
} catch {
|
|
1154
1334
|
return {};
|
|
1155
1335
|
}
|
|
1156
1336
|
}
|
|
1157
1337
|
function saveAgentEnv(id, env) {
|
|
1158
|
-
|
|
1159
|
-
const f =
|
|
1160
|
-
|
|
1161
|
-
|
|
1338
|
+
fs9.mkdirSync(folder(id), { recursive: true });
|
|
1339
|
+
const f = path6.join(folder(id), "env.json");
|
|
1340
|
+
fs9.writeFileSync(`${f}.tmp`, JSON.stringify({ ...agentEnv(id), ...env }), { mode: 384 });
|
|
1341
|
+
fs9.renameSync(`${f}.tmp`, f);
|
|
1162
1342
|
}
|
|
1163
1343
|
|
|
1164
1344
|
// src/agent/service.ts
|
|
@@ -1265,29 +1445,38 @@ function commandText(req) {
|
|
|
1265
1445
|
return c.map((a) => typeof a === "string" && /^[\w@%+=:,./-]+$/.test(a) ? a : JSON.stringify(String(a))).join(" ");
|
|
1266
1446
|
return typeof c === "string" ? c : String(req.toolCall.title ?? "");
|
|
1267
1447
|
}
|
|
1448
|
+
function mcpServerFor(agent, url, key, bridge) {
|
|
1449
|
+
const env = [
|
|
1450
|
+
{ name: "HF_MCP_URL", value: url },
|
|
1451
|
+
{ name: "HF_MCP_KUNCI", value: key }
|
|
1452
|
+
];
|
|
1453
|
+
if (agent?.launch.linux)
|
|
1454
|
+
return { name: "hypeframe", command: bridgeScript(), args: [], env };
|
|
1455
|
+
return { name: "hypeframe", command: bridge.command, args: bridge.args, env: [...bridge.env, ...env] };
|
|
1456
|
+
}
|
|
1268
1457
|
function historyFile(projectId, sessionId) {
|
|
1269
|
-
return
|
|
1458
|
+
return path7.join(projectDir(projectId), "riwayat", `${crypto3.createHash("sha256").update(sessionId).digest("hex").slice(0, 32)}.jsonl`);
|
|
1270
1459
|
}
|
|
1271
1460
|
function record(file, updates) {
|
|
1272
1461
|
if (!updates.length)
|
|
1273
1462
|
return;
|
|
1274
1463
|
try {
|
|
1275
|
-
|
|
1276
|
-
|
|
1464
|
+
fs10.mkdirSync(path7.dirname(file), { recursive: true });
|
|
1465
|
+
fs10.appendFileSync(file, `${updates.map((u) => JSON.stringify(u)).join(`
|
|
1277
1466
|
`)}
|
|
1278
1467
|
`);
|
|
1279
|
-
if (
|
|
1280
|
-
const text =
|
|
1468
|
+
if (fs10.statSync(file).size > MAX_HISTORY) {
|
|
1469
|
+
const text = fs10.readFileSync(file, "utf8");
|
|
1281
1470
|
const from = text.indexOf(`
|
|
1282
1471
|
`, text.length - MAX_HISTORY / 2);
|
|
1283
|
-
|
|
1472
|
+
fs10.writeFileSync(file, from >= 0 ? text.slice(from + 1) : "");
|
|
1284
1473
|
}
|
|
1285
1474
|
} catch {}
|
|
1286
1475
|
}
|
|
1287
1476
|
function readHistory(file) {
|
|
1288
1477
|
let text = "";
|
|
1289
1478
|
try {
|
|
1290
|
-
text =
|
|
1479
|
+
text = fs10.readFileSync(file, "utf8");
|
|
1291
1480
|
} catch {
|
|
1292
1481
|
return { update: [], potong: false };
|
|
1293
1482
|
}
|
|
@@ -1306,7 +1495,7 @@ function readHistory(file) {
|
|
|
1306
1495
|
return { update: out.reverse(), potong: false };
|
|
1307
1496
|
}
|
|
1308
1497
|
function createAgentService(o) {
|
|
1309
|
-
const key =
|
|
1498
|
+
const key = crypto3.randomBytes(24).toString("base64url");
|
|
1310
1499
|
const routes = new Map;
|
|
1311
1500
|
const sessionRoute = new Map;
|
|
1312
1501
|
const permissions = new Map;
|
|
@@ -1337,18 +1526,7 @@ function createAgentService(o) {
|
|
|
1337
1526
|
const sessions = new AgentSessions({
|
|
1338
1527
|
agent: (id) => readInstalled().find((a) => a.id === id),
|
|
1339
1528
|
env: (id) => agentEnv(id),
|
|
1340
|
-
mcpServers: (_cwd, projectId, routeId) => [
|
|
1341
|
-
{
|
|
1342
|
-
name: "hypeframe",
|
|
1343
|
-
command: o.bridge.command,
|
|
1344
|
-
args: o.bridge.args,
|
|
1345
|
-
env: [
|
|
1346
|
-
...o.bridge.env,
|
|
1347
|
-
{ name: "HF_MCP_URL", value: `http://127.0.0.1:${o.port()}/agen/mcp/${projectId}/${routeId}` },
|
|
1348
|
-
{ name: "HF_MCP_KUNCI", value: key }
|
|
1349
|
-
]
|
|
1350
|
-
}
|
|
1351
|
-
],
|
|
1529
|
+
mcpServers: (_cwd, projectId, routeId, agent) => [mcpServerFor(agent, `http://127.0.0.1:${o.port()}/agen/mcp/${projectId}/${routeId}`, key, o.bridge)],
|
|
1352
1530
|
onUpdate: (sessionId, list, info) => {
|
|
1353
1531
|
const p = pending.get(sessionId);
|
|
1354
1532
|
if (p)
|
|
@@ -1360,7 +1538,7 @@ function createAgentService(o) {
|
|
|
1360
1538
|
record(file, packUpdates(list).flat());
|
|
1361
1539
|
},
|
|
1362
1540
|
onPermission: (sessionId, req, info) => new Promise((ok) => {
|
|
1363
|
-
const id = `i${
|
|
1541
|
+
const id = `i${crypto3.randomBytes(6).toString("hex")}`;
|
|
1364
1542
|
const done = (v) => (permissions.delete(id), ok(v));
|
|
1365
1543
|
permissions.set(id, done);
|
|
1366
1544
|
setTimeout(() => permissions.has(id) && done(null), 5 * 60000).unref();
|
|
@@ -1439,19 +1617,19 @@ function createAgentService(o) {
|
|
|
1439
1617
|
const folder = projectDir(projectId);
|
|
1440
1618
|
if (!p || !insideFolder(folder, p))
|
|
1441
1619
|
return fail(`Only files inside the HypeFrame project folder (${folder}) can be added.`);
|
|
1442
|
-
const file =
|
|
1443
|
-
const st =
|
|
1620
|
+
const file = path7.resolve(folder, p);
|
|
1621
|
+
const st = fs10.statSync(file, { throwIfNoEntry: false });
|
|
1444
1622
|
if (!st?.isFile())
|
|
1445
1623
|
return fail(`${p} is not a file in the project folder.`);
|
|
1446
|
-
const nama =
|
|
1447
|
-
const mime = MEDIA[
|
|
1624
|
+
const nama = path7.basename(file).slice(0, 120);
|
|
1625
|
+
const mime = MEDIA[path7.extname(file).slice(1).toLowerCase()];
|
|
1448
1626
|
if (!mime)
|
|
1449
1627
|
return fail(`${nama}: only images, audio, video, fonts and Lottie/JSON files can be added to a HypeFrame project.`);
|
|
1450
1628
|
if (st.size > MAX_FILE2)
|
|
1451
1629
|
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.`);
|
|
1452
|
-
const data =
|
|
1630
|
+
const data = fs10.readFileSync(file).toString("base64");
|
|
1453
1631
|
const n = Math.max(1, Math.ceil(data.length / PIECE));
|
|
1454
|
-
const id =
|
|
1632
|
+
const id = crypto3.randomBytes(8).toString("hex");
|
|
1455
1633
|
let last = {};
|
|
1456
1634
|
for (let i = 0;i < n; i++) {
|
|
1457
1635
|
last = await o.conn.request(target.dari, "alat", { nama: "_berkas", arg: { id, i, n, nama, mime, ukuran: st.size, data: data.slice(i * PIECE, (i + 1) * PIECE) } });
|
|
@@ -1474,7 +1652,7 @@ function createAgentService(o) {
|
|
|
1474
1652
|
if (!m)
|
|
1475
1653
|
return false;
|
|
1476
1654
|
const auth = String(req.headers.authorization || "").replace(/^Bearer\s+/i, "");
|
|
1477
|
-
if (req.method !== "POST" || auth.length !== key.length || !
|
|
1655
|
+
if (req.method !== "POST" || auth.length !== key.length || !crypto3.timingSafeEqual(Buffer.from(auth), Buffer.from(key)))
|
|
1478
1656
|
return reply(res, 401, { error: "unauthorized" }), true;
|
|
1479
1657
|
let s = "";
|
|
1480
1658
|
for await (const d of req)
|
|
@@ -1525,15 +1703,15 @@ function createAgentService(o) {
|
|
|
1525
1703
|
}
|
|
1526
1704
|
|
|
1527
1705
|
// src/agent/mcp-bridge.ts
|
|
1528
|
-
import
|
|
1529
|
-
import
|
|
1706
|
+
import fs12 from "node:fs";
|
|
1707
|
+
import path9 from "node:path";
|
|
1530
1708
|
import readline2 from "node:readline";
|
|
1531
1709
|
|
|
1532
1710
|
// src/util/runtime.ts
|
|
1533
|
-
import
|
|
1534
|
-
import
|
|
1711
|
+
import fs11 from "node:fs";
|
|
1712
|
+
import path8 from "node:path";
|
|
1535
1713
|
function isStandalone() {
|
|
1536
|
-
return
|
|
1714
|
+
return path8.basename(process.execPath).toLowerCase().startsWith("hypeframe");
|
|
1537
1715
|
}
|
|
1538
1716
|
function runtimeLabel() {
|
|
1539
1717
|
const bun = process.versions.bun;
|
|
@@ -1543,7 +1721,7 @@ function launchCommand() {
|
|
|
1543
1721
|
if (isStandalone())
|
|
1544
1722
|
return [process.execPath];
|
|
1545
1723
|
try {
|
|
1546
|
-
const script =
|
|
1724
|
+
const script = fs11.realpathSync(process.argv[1] || "");
|
|
1547
1725
|
return /[\\/]_npx[\\/]/.test(script) ? null : [process.execPath, script];
|
|
1548
1726
|
} catch {
|
|
1549
1727
|
return null;
|
|
@@ -1579,13 +1757,13 @@ rl.on('line', (line) => {
|
|
|
1579
1757
|
rl.on('close', () => Promise.all(busy).then(() => process.exit(0)));
|
|
1580
1758
|
`;
|
|
1581
1759
|
function bridgeLaunch() {
|
|
1582
|
-
const file =
|
|
1760
|
+
const file = path9.join(agentDir(), "mcp-bridge.mjs");
|
|
1583
1761
|
let now = "";
|
|
1584
1762
|
try {
|
|
1585
|
-
now =
|
|
1763
|
+
now = fs12.readFileSync(file, "utf8");
|
|
1586
1764
|
} catch {}
|
|
1587
1765
|
if (now !== BRIDGE_SOURCE)
|
|
1588
|
-
|
|
1766
|
+
fs12.writeFileSync(file, BRIDGE_SOURCE);
|
|
1589
1767
|
return { command: process.execPath, args: [file], env: isStandalone() ? [{ name: "BUN_BE_BUN", value: "1" }] : [] };
|
|
1590
1768
|
}
|
|
1591
1769
|
async function runMcpBridge() {
|
|
@@ -1631,7 +1809,7 @@ async function runMcpBridge() {
|
|
|
1631
1809
|
}
|
|
1632
1810
|
|
|
1633
1811
|
// src/config/lock.ts
|
|
1634
|
-
import
|
|
1812
|
+
import fs13 from "node:fs";
|
|
1635
1813
|
class AlreadyRunning extends Error {
|
|
1636
1814
|
code = "SUDAH_JALAN";
|
|
1637
1815
|
}
|
|
@@ -1645,7 +1823,7 @@ var alive = (pid) => {
|
|
|
1645
1823
|
};
|
|
1646
1824
|
function runningPid() {
|
|
1647
1825
|
try {
|
|
1648
|
-
const pid = Number(
|
|
1826
|
+
const pid = Number(fs13.readFileSync(lockFile(), "utf8"));
|
|
1649
1827
|
return Number.isInteger(pid) && pid > 0 && pid !== process.pid && alive(pid) ? pid : null;
|
|
1650
1828
|
} catch {
|
|
1651
1829
|
return null;
|
|
@@ -1655,13 +1833,13 @@ function singleInstance() {
|
|
|
1655
1833
|
const f = lockFile();
|
|
1656
1834
|
for (let attempt = 0;attempt < 2; attempt++) {
|
|
1657
1835
|
try {
|
|
1658
|
-
const fd =
|
|
1659
|
-
|
|
1660
|
-
|
|
1836
|
+
const fd = fs13.openSync(f, "wx");
|
|
1837
|
+
fs13.writeSync(fd, String(process.pid));
|
|
1838
|
+
fs13.closeSync(fd);
|
|
1661
1839
|
const release = () => {
|
|
1662
1840
|
try {
|
|
1663
|
-
if (
|
|
1664
|
-
|
|
1841
|
+
if (fs13.readFileSync(f, "utf8") === String(process.pid))
|
|
1842
|
+
fs13.rmSync(f, { force: true });
|
|
1665
1843
|
} catch {}
|
|
1666
1844
|
process.off("exit", release);
|
|
1667
1845
|
};
|
|
@@ -1670,17 +1848,17 @@ function singleInstance() {
|
|
|
1670
1848
|
} catch (e) {
|
|
1671
1849
|
if (e.code !== "EEXIST")
|
|
1672
1850
|
throw e;
|
|
1673
|
-
const pid = Number(
|
|
1851
|
+
const pid = Number(fs13.readFileSync(f, "utf8"));
|
|
1674
1852
|
if (Number.isInteger(pid) && pid > 0 && alive(pid))
|
|
1675
1853
|
throw new AlreadyRunning("engine already running");
|
|
1676
|
-
|
|
1854
|
+
fs13.rmSync(f, { force: true });
|
|
1677
1855
|
}
|
|
1678
1856
|
}
|
|
1679
1857
|
throw new AlreadyRunning("engine already running");
|
|
1680
1858
|
}
|
|
1681
1859
|
|
|
1682
1860
|
// src/engine/connection.ts
|
|
1683
|
-
import
|
|
1861
|
+
import crypto4 from "node:crypto";
|
|
1684
1862
|
import { EventEmitter as EventEmitter2 } from "node:events";
|
|
1685
1863
|
import WebSocket from "ws";
|
|
1686
1864
|
var SILENCE_MAX_MS = 70000;
|
|
@@ -1726,7 +1904,7 @@ class Connection extends EventEmitter2 {
|
|
|
1726
1904
|
request(ke, kind, body, timeoutMs = 55000) {
|
|
1727
1905
|
if (!this.connected)
|
|
1728
1906
|
return Promise.resolve({ ok: false, error: "terputus" });
|
|
1729
|
-
const id = `q${this.nextReq++}${
|
|
1907
|
+
const id = `q${this.nextReq++}${crypto4.randomBytes(6).toString("hex")}`;
|
|
1730
1908
|
return new Promise((ok) => {
|
|
1731
1909
|
const timer = setTimeout(() => (this.waiting.delete(id), ok({ ok: false, error: "waktu" })), timeoutMs);
|
|
1732
1910
|
timer.unref?.();
|
|
@@ -1909,41 +2087,18 @@ async function pair(o) {
|
|
|
1909
2087
|
}
|
|
1910
2088
|
|
|
1911
2089
|
// src/render/chrome.ts
|
|
1912
|
-
import
|
|
2090
|
+
import fs14 from "node:fs";
|
|
1913
2091
|
import http from "node:http";
|
|
1914
|
-
import
|
|
2092
|
+
import path10 from "node:path";
|
|
1915
2093
|
import { Browser, detectBrowserPlatform, getInstalledBrowsers, install, resolveBuildId } from "@puppeteer/browsers";
|
|
1916
2094
|
import puppeteer from "puppeteer-core";
|
|
1917
|
-
|
|
1918
|
-
// src/util/which.ts
|
|
1919
|
-
import fs12 from "node:fs";
|
|
1920
|
-
import path8 from "node:path";
|
|
1921
|
-
function isAndroid() {
|
|
1922
|
-
return process.platform === "android" || !!process.env.TERMUX_VERSION || (process.env.PREFIX ?? "").includes("/com.termux/");
|
|
1923
|
-
}
|
|
1924
|
-
function onPath(name) {
|
|
1925
|
-
if (!/^[\w.@+-]{1,80}$/.test(name))
|
|
1926
|
-
return null;
|
|
1927
|
-
const file = process.platform === "win32" ? /\.exe$/i.test(name) ? name : `${name}.exe` : name;
|
|
1928
|
-
for (const dir of (process.env.PATH || "").split(path8.delimiter).filter(Boolean)) {
|
|
1929
|
-
const f = path8.join(dir, file);
|
|
1930
|
-
try {
|
|
1931
|
-
const st = fs12.statSync(f);
|
|
1932
|
-
if (st.isFile() && (process.platform === "win32" || st.mode & 73))
|
|
1933
|
-
return f;
|
|
1934
|
-
} catch {}
|
|
1935
|
-
}
|
|
1936
|
-
return null;
|
|
1937
|
-
}
|
|
1938
|
-
|
|
1939
|
-
// src/render/chrome.ts
|
|
1940
2095
|
function chromePlatformArgs(android = isAndroid()) {
|
|
1941
2096
|
return android ? ["--no-sandbox"] : [];
|
|
1942
2097
|
}
|
|
1943
2098
|
function candidates() {
|
|
1944
2099
|
const e = process.env;
|
|
1945
2100
|
if (process.platform === "win32") {
|
|
1946
|
-
return [e.PROGRAMFILES, e["PROGRAMFILES(X86)"], e.LOCALAPPDATA].filter((d) => !!d).flatMap((d) => [
|
|
2101
|
+
return [e.PROGRAMFILES, e["PROGRAMFILES(X86)"], e.LOCALAPPDATA].filter((d) => !!d).flatMap((d) => [path10.join(d, "Google", "Chrome", "Application", "chrome.exe"), path10.join(d, "Microsoft", "Edge", "Application", "msedge.exe")]);
|
|
1947
2102
|
}
|
|
1948
2103
|
if (process.platform === "darwin") {
|
|
1949
2104
|
return ["/Applications/Google Chrome.app/Contents/MacOS/Google Chrome", "/Applications/Chromium.app/Contents/MacOS/Chromium", "/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge"];
|
|
@@ -1953,13 +2108,13 @@ function candidates() {
|
|
|
1953
2108
|
function findChrome() {
|
|
1954
2109
|
const forced = process.env.HYPEFRAME_CHROME;
|
|
1955
2110
|
if (forced)
|
|
1956
|
-
return
|
|
1957
|
-
return candidates().find((p) =>
|
|
2111
|
+
return fs14.existsSync(forced) ? forced : null;
|
|
2112
|
+
return candidates().find((p) => fs14.existsSync(p)) || null;
|
|
1958
2113
|
}
|
|
1959
2114
|
async function cachedChrome(cacheDir) {
|
|
1960
2115
|
try {
|
|
1961
|
-
const all = await getInstalledBrowsers({ cacheDir:
|
|
1962
|
-
return all.find((b) => b.browser === Browser.CHROME &&
|
|
2116
|
+
const all = await getInstalledBrowsers({ cacheDir: path10.join(cacheDir, "chrome") });
|
|
2117
|
+
return all.find((b) => b.browser === Browser.CHROME && fs14.existsSync(b.executablePath))?.executablePath ?? null;
|
|
1963
2118
|
} catch {
|
|
1964
2119
|
return null;
|
|
1965
2120
|
}
|
|
@@ -1975,7 +2130,7 @@ async function prepareChrome(cacheDir, progress = () => {
|
|
|
1975
2130
|
const platform = detectBrowserPlatform();
|
|
1976
2131
|
if (!platform)
|
|
1977
2132
|
throw new Error("Sistem ini belum didukung untuk render (Chrome tidak tersedia).");
|
|
1978
|
-
const dir =
|
|
2133
|
+
const dir = path10.join(cacheDir, "chrome");
|
|
1979
2134
|
const buildId = await resolveBuildId(Browser.CHROME, platform, "stable");
|
|
1980
2135
|
progress(0, `Chrome ${buildId}`);
|
|
1981
2136
|
const r = await install({
|
|
@@ -2025,10 +2180,10 @@ async function checkChrome(chrome, { gpu = false } = {}) {
|
|
|
2025
2180
|
}
|
|
2026
2181
|
|
|
2027
2182
|
// src/render/ffmpeg.ts
|
|
2028
|
-
import
|
|
2029
|
-
import
|
|
2183
|
+
import crypto5 from "node:crypto";
|
|
2184
|
+
import fs15 from "node:fs";
|
|
2030
2185
|
import fsp from "node:fs/promises";
|
|
2031
|
-
import
|
|
2186
|
+
import path11 from "node:path";
|
|
2032
2187
|
import { pipeline } from "node:stream/promises";
|
|
2033
2188
|
import { Readable } from "node:stream";
|
|
2034
2189
|
import zlib from "node:zlib";
|
|
@@ -2042,22 +2197,22 @@ var FFMPEG_PINNED = {
|
|
|
2042
2197
|
"darwin-arm64": { sha256: "6be74d6f449889c2e87a75873894f8520cad56c08ac76f2a628d85b0519daaca", size: 19253088 }
|
|
2043
2198
|
};
|
|
2044
2199
|
var exe = process.platform === "win32" ? "ffmpeg.exe" : "ffmpeg";
|
|
2045
|
-
var cached2 = (cacheDir) =>
|
|
2200
|
+
var cached2 = (cacheDir) => path11.join(cacheDir, "ffmpeg", FFMPEG_RELEASE, exe);
|
|
2046
2201
|
var thisPlatform = () => `${process.platform}-${process.arch}`;
|
|
2047
2202
|
async function findFfmpeg(cacheDir, key = thisPlatform()) {
|
|
2048
2203
|
const forced = process.env.HYPEFRAME_FFMPEG;
|
|
2049
2204
|
if (forced)
|
|
2050
|
-
return
|
|
2205
|
+
return fs15.existsSync(forced) ? forced : null;
|
|
2051
2206
|
if (!FFMPEG_PINNED[key])
|
|
2052
2207
|
return onPath("ffmpeg");
|
|
2053
2208
|
try {
|
|
2054
2209
|
const mod = await import("ffmpeg-static");
|
|
2055
2210
|
const p = typeof mod.default === "string" ? mod.default : null;
|
|
2056
|
-
if (p &&
|
|
2211
|
+
if (p && fs15.existsSync(p))
|
|
2057
2212
|
return p;
|
|
2058
2213
|
} catch {}
|
|
2059
2214
|
const c = cached2(cacheDir);
|
|
2060
|
-
return
|
|
2215
|
+
return fs15.existsSync(c) ? c : null;
|
|
2061
2216
|
}
|
|
2062
2217
|
async function downloadVerified(url, sha256, dest, progress = () => {
|
|
2063
2218
|
return;
|
|
@@ -2066,9 +2221,9 @@ async function downloadVerified(url, sha256, dest, progress = () => {
|
|
|
2066
2221
|
if (!r.ok || !r.body)
|
|
2067
2222
|
throw new Error(`download ${r.status}`);
|
|
2068
2223
|
const total = Number(r.headers.get("content-length")) || 0;
|
|
2069
|
-
await fsp.mkdir(
|
|
2224
|
+
await fsp.mkdir(path11.dirname(dest), { recursive: true });
|
|
2070
2225
|
const tmp = `${dest}.download`;
|
|
2071
|
-
const hash =
|
|
2226
|
+
const hash = crypto5.createHash("sha256");
|
|
2072
2227
|
let got = 0;
|
|
2073
2228
|
let last = -10;
|
|
2074
2229
|
const body = Readable.fromWeb(r.body).on("data", (c) => {
|
|
@@ -2078,13 +2233,13 @@ async function downloadVerified(url, sha256, dest, progress = () => {
|
|
|
2078
2233
|
if (pct - last >= 10)
|
|
2079
2234
|
last = pct, progress(pct);
|
|
2080
2235
|
});
|
|
2081
|
-
await pipeline(body,
|
|
2236
|
+
await pipeline(body, fs15.createWriteStream(tmp));
|
|
2082
2237
|
if (hash.digest("hex") !== sha256) {
|
|
2083
2238
|
await fsp.rm(tmp, { force: true });
|
|
2084
2239
|
throw new Error("ffmpeg: sidik unduhan tidak cocok, berkas ditolak.");
|
|
2085
2240
|
}
|
|
2086
2241
|
if (gunzip) {
|
|
2087
|
-
await pipeline(
|
|
2242
|
+
await pipeline(fs15.createReadStream(tmp), zlib.createGunzip(), fs15.createWriteStream(`${tmp}.raw`));
|
|
2088
2243
|
await fsp.rm(tmp, { force: true });
|
|
2089
2244
|
await fsp.rename(`${tmp}.raw`, dest);
|
|
2090
2245
|
} else
|
|
@@ -2108,10 +2263,10 @@ async function prepareFfmpeg(cacheDir, progress = () => {
|
|
|
2108
2263
|
|
|
2109
2264
|
// src/render/job.ts
|
|
2110
2265
|
import { spawn as spawn2 } from "node:child_process";
|
|
2111
|
-
import
|
|
2112
|
-
import
|
|
2266
|
+
import crypto6 from "node:crypto";
|
|
2267
|
+
import fs16 from "node:fs";
|
|
2113
2268
|
import fsp2 from "node:fs/promises";
|
|
2114
|
-
import
|
|
2269
|
+
import path12 from "node:path";
|
|
2115
2270
|
import puppeteer2 from "puppeteer-core";
|
|
2116
2271
|
var LIMIT_SECONDS = 1800;
|
|
2117
2272
|
function run(cmd, args, limitSeconds = 600) {
|
|
@@ -2128,7 +2283,7 @@ function run(cmd, args, limitSeconds = 600) {
|
|
|
2128
2283
|
function saveBody(req, to, max) {
|
|
2129
2284
|
return new Promise((ok, fail) => {
|
|
2130
2285
|
let n = 0;
|
|
2131
|
-
const out =
|
|
2286
|
+
const out = fs16.createWriteStream(to);
|
|
2132
2287
|
req.on("data", (d) => {
|
|
2133
2288
|
n += d.length;
|
|
2134
2289
|
if (n > max)
|
|
@@ -2159,7 +2314,7 @@ function createJobRunner(o) {
|
|
|
2159
2314
|
const renderer = async (task, { progress, signal }) => {
|
|
2160
2315
|
if (task.kind === "klip" && task.transparent && !transparent)
|
|
2161
2316
|
throw new Error(EngineError.NoTransparent);
|
|
2162
|
-
const key =
|
|
2317
|
+
const key = crypto6.randomBytes(16).toString("hex");
|
|
2163
2318
|
let finish;
|
|
2164
2319
|
const finished = new Promise((ok) => finish = ok);
|
|
2165
2320
|
running.set(task.job, { key, task, progress, finish });
|
|
@@ -2170,9 +2325,9 @@ function createJobRunner(o) {
|
|
|
2170
2325
|
let browser;
|
|
2171
2326
|
try {
|
|
2172
2327
|
progress(0, "Menyiapkan");
|
|
2173
|
-
const profile =
|
|
2174
|
-
await fsp2.mkdir(
|
|
2175
|
-
await fsp2.writeFile(
|
|
2328
|
+
const profile = path12.join(task.dir, "profil");
|
|
2329
|
+
await fsp2.mkdir(path12.join(profile, "Default"), { recursive: true });
|
|
2330
|
+
await fsp2.writeFile(path12.join(profile, "Default", "Preferences"), JSON.stringify({ webkit: { webprefs: { fonts: { standard: { Zyyy: "Roboto" }, sansserif: { Zyyy: "Roboto" }, serif: { Zyyy: "Noto Serif" } } } } }));
|
|
2176
2331
|
browser = await puppeteer2.launch({
|
|
2177
2332
|
executablePath: chrome,
|
|
2178
2333
|
headless: true,
|
|
@@ -2203,9 +2358,9 @@ function createJobRunner(o) {
|
|
|
2203
2358
|
if (result.error)
|
|
2204
2359
|
throw new Error(result.error);
|
|
2205
2360
|
progress(99, clip ? "Menyelesaikan klip" : "Menyelesaikan video");
|
|
2206
|
-
const raw =
|
|
2361
|
+
const raw = path12.join(task.dir, "mentah.mp4");
|
|
2207
2362
|
const webm = clip && task.transparent;
|
|
2208
|
-
const file =
|
|
2363
|
+
const file = path12.join(task.dir, webm ? "hasil.webm" : "hasil.mp4");
|
|
2209
2364
|
if (clip)
|
|
2210
2365
|
await fsp2.rename(raw, file);
|
|
2211
2366
|
else
|
|
@@ -2232,11 +2387,11 @@ function createJobRunner(o) {
|
|
|
2232
2387
|
return res.writeHead(403), res.end(), true;
|
|
2233
2388
|
const pkg = r.task.packageDir;
|
|
2234
2389
|
if (m[2] === "proyek.json" || m[2] === "klip.json" || m[3]) {
|
|
2235
|
-
const f = m[3] ?
|
|
2236
|
-
if (!
|
|
2390
|
+
const f = m[3] ? path12.join(pkg, "aset", m[3]) : path12.join(pkg, m[2]);
|
|
2391
|
+
if (!fs16.existsSync(f))
|
|
2237
2392
|
return res.writeHead(404), res.end(), true;
|
|
2238
2393
|
res.writeHead(200, { "content-type": m[3] ? "application/octet-stream" : "application/json", "content-length": (await fsp2.stat(f)).size });
|
|
2239
|
-
|
|
2394
|
+
fs16.createReadStream(f).pipe(res);
|
|
2240
2395
|
return true;
|
|
2241
2396
|
}
|
|
2242
2397
|
if (m[2] === "kemajuan") {
|
|
@@ -2253,7 +2408,7 @@ function createJobRunner(o) {
|
|
|
2253
2408
|
r.finish({ error: String(b.pesan || "Render gagal.").slice(0, 300) });
|
|
2254
2409
|
return res.writeHead(204), res.end(), true;
|
|
2255
2410
|
}
|
|
2256
|
-
await saveBody(req,
|
|
2411
|
+
await saveBody(req, path12.join(r.task.dir, "mentah.mp4"), 8 * 1073741824);
|
|
2257
2412
|
r.finish({ audio: String(req.headers["x-kodek-audio"] || "") });
|
|
2258
2413
|
res.writeHead(204);
|
|
2259
2414
|
res.end();
|
|
@@ -2263,9 +2418,9 @@ function createJobRunner(o) {
|
|
|
2263
2418
|
}
|
|
2264
2419
|
|
|
2265
2420
|
// src/render/page.ts
|
|
2266
|
-
import
|
|
2421
|
+
import fs17 from "node:fs";
|
|
2267
2422
|
import fsp3 from "node:fs/promises";
|
|
2268
|
-
import
|
|
2423
|
+
import path13 from "node:path";
|
|
2269
2424
|
var TYPES = {
|
|
2270
2425
|
".html": "text/html; charset=utf-8",
|
|
2271
2426
|
".js": "text/javascript",
|
|
@@ -2286,13 +2441,13 @@ var SAFE_PATH = /^[\w@.+-]+(?:\/[\w@.+-]+)*$/;
|
|
|
2286
2441
|
var VERSION_ID = /^[0-9a-f]{12}$/;
|
|
2287
2442
|
function createPage({ web, cacheDir }) {
|
|
2288
2443
|
const base = `${String(web || "").replace(/\/+$/, "")}/render/`;
|
|
2289
|
-
const root =
|
|
2444
|
+
const root = path13.join(cacheDir, "halaman");
|
|
2290
2445
|
let version = null;
|
|
2291
|
-
const versionDir = () =>
|
|
2446
|
+
const versionDir = () => path13.join(root, version);
|
|
2292
2447
|
const pending = new Map;
|
|
2293
2448
|
async function download(rel) {
|
|
2294
|
-
const target =
|
|
2295
|
-
if (
|
|
2449
|
+
const target = path13.join(versionDir(), rel);
|
|
2450
|
+
if (fs17.existsSync(target))
|
|
2296
2451
|
return target;
|
|
2297
2452
|
if (!pending.has(rel)) {
|
|
2298
2453
|
pending.set(rel, (async () => {
|
|
@@ -2300,7 +2455,7 @@ function createPage({ web, cacheDir }) {
|
|
|
2300
2455
|
if (!r.ok)
|
|
2301
2456
|
throw Object.assign(new Error(`halaman ${rel}: ${r.status}`), { status: r.status });
|
|
2302
2457
|
const body = Buffer.from(await r.arrayBuffer());
|
|
2303
|
-
await fsp3.mkdir(
|
|
2458
|
+
await fsp3.mkdir(path13.dirname(target), { recursive: true });
|
|
2304
2459
|
await fsp3.writeFile(`${target}.tmp`, body);
|
|
2305
2460
|
await fsp3.rename(`${target}.tmp`, target);
|
|
2306
2461
|
return target;
|
|
@@ -2324,10 +2479,10 @@ function createPage({ web, cacheDir }) {
|
|
|
2324
2479
|
await download(f);
|
|
2325
2480
|
if (old !== version) {
|
|
2326
2481
|
const all = (await fsp3.readdir(root).catch(() => [])).filter((d) => VERSION_ID.test(d));
|
|
2327
|
-
const dated = await Promise.all(all.map(async (d) => ({ d, t: (await fsp3.stat(
|
|
2482
|
+
const dated = await Promise.all(all.map(async (d) => ({ d, t: (await fsp3.stat(path13.join(root, d))).mtimeMs })));
|
|
2328
2483
|
for (const { d } of dated.sort((a, b) => b.t - a.t).slice(2))
|
|
2329
2484
|
if (d !== version)
|
|
2330
|
-
await fsp3.rm(
|
|
2485
|
+
await fsp3.rm(path13.join(root, d), { recursive: true, force: true });
|
|
2331
2486
|
}
|
|
2332
2487
|
return { version };
|
|
2333
2488
|
}
|
|
@@ -2344,8 +2499,8 @@ function createPage({ web, cacheDir }) {
|
|
|
2344
2499
|
return res.writeHead(404), res.end(), true;
|
|
2345
2500
|
try {
|
|
2346
2501
|
const f = await download(rel);
|
|
2347
|
-
res.writeHead(200, { "content-type": TYPES[
|
|
2348
|
-
|
|
2502
|
+
res.writeHead(200, { "content-type": TYPES[path13.extname(f)] || "application/octet-stream", "cache-control": "no-store" });
|
|
2503
|
+
fs17.createReadStream(f).pipe(res);
|
|
2349
2504
|
} catch (e) {
|
|
2350
2505
|
res.writeHead(e.status === 404 ? 404 : 502);
|
|
2351
2506
|
res.end();
|
|
@@ -2362,14 +2517,14 @@ function createPage({ web, cacheDir }) {
|
|
|
2362
2517
|
}
|
|
2363
2518
|
|
|
2364
2519
|
// src/render/service.ts
|
|
2365
|
-
import
|
|
2366
|
-
import
|
|
2520
|
+
import crypto7 from "node:crypto";
|
|
2521
|
+
import fs18 from "node:fs";
|
|
2367
2522
|
import fsp4 from "node:fs/promises";
|
|
2368
2523
|
import http2 from "node:http";
|
|
2369
|
-
import
|
|
2524
|
+
import path14 from "node:path";
|
|
2370
2525
|
import yauzl from "yauzl";
|
|
2371
2526
|
var ACTIVE = new Set(["unggah", "antre", "jalan"]);
|
|
2372
|
-
var safeEqual = (a, b) => a.length === b.length &&
|
|
2527
|
+
var safeEqual = (a, b) => a.length === b.length && crypto7.timingSafeEqual(Buffer.from(a), Buffer.from(b));
|
|
2373
2528
|
var BAD_ENTRY = /relative path|absolute path|invalid characters/i;
|
|
2374
2529
|
function listZip(f) {
|
|
2375
2530
|
return new Promise((ok, fail) => {
|
|
@@ -2393,14 +2548,14 @@ function extractZip(f, to) {
|
|
|
2393
2548
|
zip.on("entry", (en) => {
|
|
2394
2549
|
if (en.fileName.endsWith("/"))
|
|
2395
2550
|
return zip.readEntry();
|
|
2396
|
-
const target =
|
|
2397
|
-
if (!target.startsWith(to +
|
|
2551
|
+
const target = path14.join(to, en.fileName);
|
|
2552
|
+
if (!target.startsWith(to + path14.sep))
|
|
2398
2553
|
return fail(new Error(EngineError.BadPackage));
|
|
2399
|
-
|
|
2554
|
+
fs18.mkdirSync(path14.dirname(target), { recursive: true });
|
|
2400
2555
|
zip.openReadStream(en, (e2, s) => {
|
|
2401
2556
|
if (e2 || !s)
|
|
2402
2557
|
return fail(e2 ?? new Error("zip"));
|
|
2403
|
-
const out =
|
|
2558
|
+
const out = fs18.createWriteStream(target);
|
|
2404
2559
|
s.pipe(out);
|
|
2405
2560
|
out.on("finish", () => zip.readEntry());
|
|
2406
2561
|
out.on("error", fail);
|
|
@@ -2415,13 +2570,13 @@ function extractZip(f, to) {
|
|
|
2415
2570
|
function saveBody2(req, to, max) {
|
|
2416
2571
|
return new Promise((ok, fail) => {
|
|
2417
2572
|
let n = 0;
|
|
2418
|
-
const out =
|
|
2573
|
+
const out = fs18.createWriteStream(to);
|
|
2419
2574
|
req.on("data", (d) => {
|
|
2420
2575
|
n += d.length;
|
|
2421
2576
|
if (n > max) {
|
|
2422
2577
|
req.destroy();
|
|
2423
2578
|
out.destroy();
|
|
2424
|
-
|
|
2579
|
+
fs18.rm(to, { force: true }, () => fail(new Error("terlalu besar")));
|
|
2425
2580
|
}
|
|
2426
2581
|
});
|
|
2427
2582
|
req.pipe(out);
|
|
@@ -2449,8 +2604,8 @@ async function createRenderService(o) {
|
|
|
2449
2604
|
return;
|
|
2450
2605
|
} } = o;
|
|
2451
2606
|
const origins = new Set([].concat(o.origin || []));
|
|
2452
|
-
const sign = (kind, body) =>
|
|
2453
|
-
const dir = (job) =>
|
|
2607
|
+
const sign = (kind, body) => crypto7.createHmac("sha256", key).update(`${kind}.${body}`).digest("base64url");
|
|
2608
|
+
const dir = (job) => path14.join(folder, job);
|
|
2454
2609
|
await fsp4.mkdir(folder, { recursive: true });
|
|
2455
2610
|
function readTicket(req) {
|
|
2456
2611
|
const tk = String(req.headers.authorization || "").replace(/^Bearer\s+/i, "");
|
|
@@ -2472,7 +2627,7 @@ async function createRenderService(o) {
|
|
|
2472
2627
|
const jobs = new Map;
|
|
2473
2628
|
const queue = [];
|
|
2474
2629
|
let current = null;
|
|
2475
|
-
const persist = (t) => fsp4.writeFile(
|
|
2630
|
+
const persist = (t) => fsp4.writeFile(path14.join(dir(t.job), "status.json"), JSON.stringify(t)).catch(() => {
|
|
2476
2631
|
return;
|
|
2477
2632
|
});
|
|
2478
2633
|
const update = (t, patch) => (Object.assign(t, patch, { diperbarui: Date.now() }), void persist(t));
|
|
@@ -2491,19 +2646,19 @@ async function createRenderService(o) {
|
|
|
2491
2646
|
});
|
|
2492
2647
|
async function clearFiles(t, all = false) {
|
|
2493
2648
|
for (const n of all ? ["."] : ["paket", "paket.zip", "profil", "mentah.mp4", "mentah.webm"])
|
|
2494
|
-
await fsp4.rm(
|
|
2649
|
+
await fsp4.rm(path14.join(dir(t.job), n), { recursive: true, force: true }).catch(() => {
|
|
2495
2650
|
return;
|
|
2496
2651
|
});
|
|
2497
2652
|
if (!all) {
|
|
2498
2653
|
for (const f of await fsp4.readdir(dir(t.job)).catch(() => []))
|
|
2499
2654
|
if (/^p\d+$/.test(f))
|
|
2500
|
-
await fsp4.rm(
|
|
2655
|
+
await fsp4.rm(path14.join(dir(t.job), f), { force: true });
|
|
2501
2656
|
}
|
|
2502
2657
|
}
|
|
2503
2658
|
async function openPackage(t) {
|
|
2504
2659
|
const d = dir(t.job);
|
|
2505
2660
|
const main = t.tiket.jenis === "klip" ? "klip.json" : "proyek.json";
|
|
2506
|
-
const entries = await listZip(
|
|
2661
|
+
const entries = await listZip(path14.join(d, "paket.zip"));
|
|
2507
2662
|
const names = entries.map((x) => x.name).filter((n) => !n.endsWith("/"));
|
|
2508
2663
|
if (names.some((n) => n.startsWith("/") || n.includes("..") || n.includes("\\") || n !== main && !/^aset\/[\w-]+$/.test(n)))
|
|
2509
2664
|
throw new Error(EngineError.BadPackage);
|
|
@@ -2511,10 +2666,10 @@ async function createRenderService(o) {
|
|
|
2511
2666
|
throw new Error(`Paket tidak berisi ${main}.`);
|
|
2512
2667
|
if (entries.reduce((a, x) => a + x.size, 0) > maxUnzippedMb * 1048576)
|
|
2513
2668
|
throw new Error("Isi paket terlalu besar.");
|
|
2514
|
-
await extractZip(
|
|
2515
|
-
await fsp4.rm(
|
|
2516
|
-
const j = JSON.parse(await fsp4.readFile(
|
|
2517
|
-
const has = (id) => /^[\w-]+$/.test(id) &&
|
|
2669
|
+
await extractZip(path14.join(d, "paket.zip"), path14.join(d, "paket"));
|
|
2670
|
+
await fsp4.rm(path14.join(d, "paket.zip"), { force: true });
|
|
2671
|
+
const j = JSON.parse(await fsp4.readFile(path14.join(d, "paket", main), "utf8"));
|
|
2672
|
+
const has = (id) => /^[\w-]+$/.test(id) && fs18.existsSync(path14.join(d, "paket", "aset", id));
|
|
2518
2673
|
if (main === "klip.json") {
|
|
2519
2674
|
const k = j.klip || {};
|
|
2520
2675
|
const seconds = Number(k.durationInFrames) / Number(k.fps);
|
|
@@ -2562,7 +2717,7 @@ async function createRenderService(o) {
|
|
|
2562
2717
|
job: t.job,
|
|
2563
2718
|
kind: t.tiket.jenis,
|
|
2564
2719
|
dir: dir(t.job),
|
|
2565
|
-
packageDir:
|
|
2720
|
+
packageDir: path14.join(dir(t.job), "paket"),
|
|
2566
2721
|
transparent: !!t.transparan,
|
|
2567
2722
|
persen: t.persen,
|
|
2568
2723
|
width: t.tiket.w,
|
|
@@ -2582,7 +2737,7 @@ async function createRenderService(o) {
|
|
|
2582
2737
|
const size = (await fsp4.stat(h.file)).size;
|
|
2583
2738
|
if (size < 200)
|
|
2584
2739
|
throw new Error(EngineError.EmptyResult);
|
|
2585
|
-
update(t, { status: "selesai", persen: 100, tahap: "", selesaiPada: Date.now(), hasilUkuran: size, hasilBerkas:
|
|
2740
|
+
update(t, { status: "selesai", persen: 100, tahap: "", selesaiPada: Date.now(), hasilUkuran: size, hasilBerkas: path14.basename(h.file), hasilJenis: h.type });
|
|
2586
2741
|
onJob("done", t);
|
|
2587
2742
|
} catch (e) {
|
|
2588
2743
|
if (t.status !== "batal") {
|
|
@@ -2620,10 +2775,10 @@ async function createRenderService(o) {
|
|
|
2620
2775
|
if (a > z)
|
|
2621
2776
|
return res.writeHead(416, { ...h, "content-range": `bytes */${st.size}` }), res.end();
|
|
2622
2777
|
res.writeHead(206, { ...h, "content-length": z - a + 1, "content-range": `bytes ${a}-${z}/${st.size}` });
|
|
2623
|
-
return void
|
|
2778
|
+
return void fs18.createReadStream(f, { start: a, end: z }).pipe(res);
|
|
2624
2779
|
}
|
|
2625
2780
|
res.writeHead(200, { ...h, "content-length": st.size });
|
|
2626
|
-
|
|
2781
|
+
fs18.createReadStream(f).pipe(res);
|
|
2627
2782
|
}
|
|
2628
2783
|
const ROUTE = /^\/tugas(?:\/(r_[a-f0-9]{16})(\/potongan\/(\d{1,4})|\/mulai|\/hasil)?)?$/;
|
|
2629
2784
|
const server = http2.createServer(async (req, res) => {
|
|
@@ -2662,13 +2817,13 @@ async function createRenderService(o) {
|
|
|
2662
2817
|
if (t.status !== "unggah")
|
|
2663
2818
|
return json(req, res, 409, { galat: "Unggahan sudah ditutup." });
|
|
2664
2819
|
const n = Number(m[3]);
|
|
2665
|
-
const f =
|
|
2666
|
-
const before =
|
|
2820
|
+
const f = path14.join(dir(job), `p${n}`);
|
|
2821
|
+
const before = fs18.existsSync(f) ? (await fsp4.stat(f)).size : 0;
|
|
2667
2822
|
const room = Number(ticket.maksMb) * 1048576 - (t.terunggah - before);
|
|
2668
2823
|
const size = await saveBody2(req, f, Math.min(partMb * 1048576 + 1024, room));
|
|
2669
2824
|
const expected = String(req.headers["x-sha256"] || "").toLowerCase();
|
|
2670
2825
|
if (expected) {
|
|
2671
|
-
const digest =
|
|
2826
|
+
const digest = crypto7.createHash("sha256").update(await fsp4.readFile(f)).digest("hex");
|
|
2672
2827
|
if (digest !== expected) {
|
|
2673
2828
|
await fsp4.rm(f, { force: true });
|
|
2674
2829
|
update(t, { terunggah: t.terunggah - before });
|
|
@@ -2685,13 +2840,13 @@ async function createRenderService(o) {
|
|
|
2685
2840
|
const count = Number(b.jumlah);
|
|
2686
2841
|
if (!(count > 0 && count < 1e4))
|
|
2687
2842
|
return json(req, res, 400, { galat: "Jumlah potongan tidak valid." });
|
|
2688
|
-
const zip =
|
|
2689
|
-
const out =
|
|
2690
|
-
const hash =
|
|
2843
|
+
const zip = path14.join(dir(job), "paket.zip");
|
|
2844
|
+
const out = fs18.createWriteStream(zip);
|
|
2845
|
+
const hash = crypto7.createHash("sha256");
|
|
2691
2846
|
let total = 0;
|
|
2692
2847
|
for (let i = 0;i < count; i++) {
|
|
2693
|
-
const f =
|
|
2694
|
-
if (!
|
|
2848
|
+
const f = path14.join(dir(job), `p${i}`);
|
|
2849
|
+
if (!fs18.existsSync(f))
|
|
2695
2850
|
return out.destroy(), json(req, res, 400, { galat: `Potongan ${i + 1} belum terunggah.` });
|
|
2696
2851
|
const part = await fsp4.readFile(f);
|
|
2697
2852
|
hash.update(part);
|
|
@@ -2721,8 +2876,8 @@ async function createRenderService(o) {
|
|
|
2721
2876
|
return json(req, res, 200, summary(t));
|
|
2722
2877
|
}
|
|
2723
2878
|
if (m[2] === "/hasil" && (req.method === "GET" || req.method === "HEAD")) {
|
|
2724
|
-
const f = t.hasilBerkas ?
|
|
2725
|
-
if (t.status !== "selesai" || !f || !
|
|
2879
|
+
const f = t.hasilBerkas ? path14.join(dir(job), t.hasilBerkas) : "";
|
|
2880
|
+
if (t.status !== "selesai" || !f || !fs18.existsSync(f))
|
|
2726
2881
|
return json(req, res, 409, { galat: "Video belum jadi." });
|
|
2727
2882
|
const webm = t.hasilJenis === "video/webm";
|
|
2728
2883
|
return sendFile(req, res, f, webm ? "video/webm" : "video/mp4", `hypeframe-${job}.${webm ? "webm" : "mp4"}`);
|
|
@@ -2753,7 +2908,7 @@ async function createRenderService(o) {
|
|
|
2753
2908
|
if (!JOB_ID.test(job))
|
|
2754
2909
|
continue;
|
|
2755
2910
|
try {
|
|
2756
|
-
const t = JSON.parse(await fsp4.readFile(
|
|
2911
|
+
const t = JSON.parse(await fsp4.readFile(path14.join(dir(job), "status.json"), "utf8"));
|
|
2757
2912
|
if (t.status === "jalan" || t.status === "antre")
|
|
2758
2913
|
update(t, { status: "gagal", galat: EngineError.Restarted });
|
|
2759
2914
|
jobs.set(job, t);
|
|
@@ -2863,6 +3018,12 @@ function openUrl(url, allowed) {
|
|
|
2863
3018
|
function openFolder(dir) {
|
|
2864
3019
|
launch(dir, false);
|
|
2865
3020
|
}
|
|
3021
|
+
function openOnPhone(url) {
|
|
3022
|
+
if (!/^https?:\/\/[^\s]{1,2000}$/.test(url))
|
|
3023
|
+
return false;
|
|
3024
|
+
launch(url, true);
|
|
3025
|
+
return true;
|
|
3026
|
+
}
|
|
2866
3027
|
|
|
2867
3028
|
// src/cli/commands/start.ts
|
|
2868
3029
|
async function pairDevice(s, noBrowser = false) {
|
|
@@ -2916,8 +3077,13 @@ async function start(args, { fromMenu = false } = {}) {
|
|
|
2916
3077
|
bridge: bridgeLaunch(),
|
|
2917
3078
|
onToolError: (e) => log.warn(t(e === "tab" ? "agent.toolNoTab" : "agent.toolNoAnswer"))
|
|
2918
3079
|
});
|
|
3080
|
+
if (isAndroid())
|
|
3081
|
+
watchOpenRequests((url) => {
|
|
3082
|
+
log.info(t("linux.openUrl", { url }));
|
|
3083
|
+
openOnPhone(url);
|
|
3084
|
+
});
|
|
2919
3085
|
const capabilities = { render: false, chrome: null, transparan: false, agen: agents.capabilities() };
|
|
2920
|
-
const key =
|
|
3086
|
+
const key = crypto8.randomBytes(32).toString("base64url");
|
|
2921
3087
|
const cache = cacheDir();
|
|
2922
3088
|
const page = createPage({ web: s.web, cacheDir: cache });
|
|
2923
3089
|
let runner = null;
|
|
@@ -3053,24 +3219,24 @@ function logout() {
|
|
|
3053
3219
|
}
|
|
3054
3220
|
|
|
3055
3221
|
// src/cli/commands/autostart.ts
|
|
3056
|
-
import { spawnSync as
|
|
3057
|
-
import
|
|
3222
|
+
import { spawnSync as spawnSync3 } from "node:child_process";
|
|
3223
|
+
import fs19 from "node:fs";
|
|
3058
3224
|
import os3 from "node:os";
|
|
3059
|
-
import
|
|
3225
|
+
import path15 from "node:path";
|
|
3060
3226
|
function entryFile() {
|
|
3061
3227
|
const home = os3.homedir();
|
|
3062
3228
|
if (process.platform === "win32")
|
|
3063
|
-
return
|
|
3229
|
+
return path15.join(process.env.APPDATA || path15.join(home, "AppData", "Roaming"), "Microsoft", "Windows", "Start Menu", "Programs", "Startup", "HypeFrame.cmd");
|
|
3064
3230
|
if (process.platform === "darwin")
|
|
3065
|
-
return
|
|
3231
|
+
return path15.join(home, "Library", "LaunchAgents", "com.hypeframe.engine.plist");
|
|
3066
3232
|
if (hasSystemd())
|
|
3067
|
-
return
|
|
3068
|
-
return
|
|
3233
|
+
return path15.join(home, ".config", "systemd", "user", "hypeframe.service");
|
|
3234
|
+
return path15.join(home, ".config", "autostart", "hypeframe.desktop");
|
|
3069
3235
|
}
|
|
3070
3236
|
function hasSystemd() {
|
|
3071
|
-
return process.platform === "linux" &&
|
|
3237
|
+
return process.platform === "linux" && spawnSync3("systemctl", ["--user", "--version"], { stdio: "ignore" }).status === 0;
|
|
3072
3238
|
}
|
|
3073
|
-
var autostartEnabled = () =>
|
|
3239
|
+
var autostartEnabled = () => fs19.existsSync(entryFile());
|
|
3074
3240
|
var xml = (s) => s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
3075
3241
|
function autostart(mode) {
|
|
3076
3242
|
const file = entryFile();
|
|
@@ -3081,8 +3247,8 @@ function autostart(mode) {
|
|
|
3081
3247
|
}
|
|
3082
3248
|
if (mode === "off") {
|
|
3083
3249
|
if (process.platform === "linux" && file.endsWith(".service"))
|
|
3084
|
-
|
|
3085
|
-
|
|
3250
|
+
spawnSync3("systemctl", ["--user", "disable", "hypeframe.service"], { stdio: "ignore" });
|
|
3251
|
+
fs19.rmSync(file, { force: true });
|
|
3086
3252
|
log.ok(t("autostart.off"));
|
|
3087
3253
|
return;
|
|
3088
3254
|
}
|
|
@@ -3097,14 +3263,14 @@ function autostart(mode) {
|
|
|
3097
3263
|
return;
|
|
3098
3264
|
}
|
|
3099
3265
|
const quoted = cmd.map((c) => `"${c}"`).join(" ");
|
|
3100
|
-
|
|
3266
|
+
fs19.mkdirSync(path15.dirname(file), { recursive: true });
|
|
3101
3267
|
if (process.platform === "win32") {
|
|
3102
|
-
|
|
3268
|
+
fs19.writeFileSync(file, `@echo off\r
|
|
3103
3269
|
start "HypeFrame" /min ${quoted} start --no-browser\r
|
|
3104
3270
|
`);
|
|
3105
3271
|
} else if (process.platform === "darwin") {
|
|
3106
|
-
const out =
|
|
3107
|
-
|
|
3272
|
+
const out = path15.join(logDir(), "autostart.log");
|
|
3273
|
+
fs19.writeFileSync(file, `<?xml version="1.0" encoding="UTF-8"?>
|
|
3108
3274
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
3109
3275
|
<plist version="1.0"><dict>
|
|
3110
3276
|
<key>Label</key><string>com.hypeframe.engine</string>
|
|
@@ -3115,7 +3281,7 @@ start "HypeFrame" /min ${quoted} start --no-browser\r
|
|
|
3115
3281
|
</dict></plist>
|
|
3116
3282
|
`);
|
|
3117
3283
|
} else if (file.endsWith(".service")) {
|
|
3118
|
-
|
|
3284
|
+
fs19.writeFileSync(file, `[Unit]
|
|
3119
3285
|
Description=HypeFrame engine
|
|
3120
3286
|
After=network-online.target
|
|
3121
3287
|
|
|
@@ -3127,10 +3293,10 @@ RestartSec=60
|
|
|
3127
3293
|
[Install]
|
|
3128
3294
|
WantedBy=default.target
|
|
3129
3295
|
`);
|
|
3130
|
-
|
|
3131
|
-
|
|
3296
|
+
spawnSync3("systemctl", ["--user", "daemon-reload"], { stdio: "ignore" });
|
|
3297
|
+
spawnSync3("systemctl", ["--user", "enable", "hypeframe.service"], { stdio: "ignore" });
|
|
3132
3298
|
} else {
|
|
3133
|
-
|
|
3299
|
+
fs19.writeFileSync(file, `[Desktop Entry]
|
|
3134
3300
|
Type=Application
|
|
3135
3301
|
Name=HypeFrame engine
|
|
3136
3302
|
Exec=${quoted} start --no-browser
|
|
@@ -3232,9 +3398,9 @@ async function bench(args) {
|
|
|
3232
3398
|
import * as p from "@clack/prompts";
|
|
3233
3399
|
|
|
3234
3400
|
// src/agent/install.ts
|
|
3235
|
-
import
|
|
3401
|
+
import fs20 from "node:fs";
|
|
3236
3402
|
import fsp5 from "node:fs/promises";
|
|
3237
|
-
import
|
|
3403
|
+
import path16 from "node:path";
|
|
3238
3404
|
import yauzl2 from "yauzl";
|
|
3239
3405
|
function unzip(file, to) {
|
|
3240
3406
|
return new Promise((ok, fail) => {
|
|
@@ -3242,16 +3408,16 @@ function unzip(file, to) {
|
|
|
3242
3408
|
if (e || !zip)
|
|
3243
3409
|
return fail(e ?? new Error("zip"));
|
|
3244
3410
|
zip.on("entry", (en) => {
|
|
3245
|
-
const target =
|
|
3246
|
-
if (!target.startsWith(to +
|
|
3411
|
+
const target = path16.join(to, en.fileName);
|
|
3412
|
+
if (!target.startsWith(to + path16.sep))
|
|
3247
3413
|
return fail(new Error("archive path outside the agent folder"));
|
|
3248
3414
|
if (en.fileName.endsWith("/"))
|
|
3249
|
-
return
|
|
3250
|
-
|
|
3415
|
+
return fs20.mkdirSync(target, { recursive: true }), zip.readEntry();
|
|
3416
|
+
fs20.mkdirSync(path16.dirname(target), { recursive: true });
|
|
3251
3417
|
zip.openReadStream(en, (e2, s) => {
|
|
3252
3418
|
if (e2 || !s)
|
|
3253
3419
|
return fail(e2 ?? new Error("zip"));
|
|
3254
|
-
const out =
|
|
3420
|
+
const out = fs20.createWriteStream(target);
|
|
3255
3421
|
s.pipe(out);
|
|
3256
3422
|
out.on("finish", () => zip.readEntry());
|
|
3257
3423
|
out.on("error", fail);
|
|
@@ -3266,7 +3432,7 @@ function unzip(file, to) {
|
|
|
3266
3432
|
async function untarGz(file, to) {
|
|
3267
3433
|
const { gunzipSync } = await import("node:zlib");
|
|
3268
3434
|
const data = gunzipSync(await fsp5.readFile(file));
|
|
3269
|
-
const root =
|
|
3435
|
+
const root = path16.resolve(to);
|
|
3270
3436
|
const str = (b) => b.toString("utf8").replace(/\0[\s\S]*$/, "");
|
|
3271
3437
|
const octal = (b) => Number.parseInt(str(b).trim() || "0", 8) || 0;
|
|
3272
3438
|
let off = 0;
|
|
@@ -3297,8 +3463,8 @@ async function untarGz(file, to) {
|
|
|
3297
3463
|
name = name.replace(/^\.\//, "");
|
|
3298
3464
|
if (!name)
|
|
3299
3465
|
continue;
|
|
3300
|
-
const target =
|
|
3301
|
-
if (target !== root && !target.startsWith(root +
|
|
3466
|
+
const target = path16.resolve(root, name);
|
|
3467
|
+
if (target !== root && !target.startsWith(root + path16.sep))
|
|
3302
3468
|
throw new Error("archive path outside the agent folder");
|
|
3303
3469
|
if (type === "5") {
|
|
3304
3470
|
await fsp5.mkdir(target, { recursive: true });
|
|
@@ -3306,22 +3472,22 @@ async function untarGz(file, to) {
|
|
|
3306
3472
|
}
|
|
3307
3473
|
if (type !== "0" && type !== "7")
|
|
3308
3474
|
continue;
|
|
3309
|
-
await fsp5.mkdir(
|
|
3475
|
+
await fsp5.mkdir(path16.dirname(target), { recursive: true });
|
|
3310
3476
|
await fsp5.writeFile(target, body, { mode: octal(h.subarray(100, 108)) & 73 ? 493 : 420 });
|
|
3311
3477
|
}
|
|
3312
3478
|
}
|
|
3313
3479
|
function npxRunner(pkg, extra = []) {
|
|
3314
3480
|
if (isStandalone())
|
|
3315
3481
|
return { cmd: process.execPath, args: ["x", pkg, ...extra], env: { BUN_BE_BUN: "1" } };
|
|
3316
|
-
const npxCli =
|
|
3317
|
-
if (!
|
|
3482
|
+
const npxCli = path16.join(path16.dirname(process.execPath), process.platform === "win32" ? "" : "..", process.platform === "win32" ? "node_modules" : "lib/node_modules", "npm", "bin", "npx-cli.js");
|
|
3483
|
+
if (!fs20.existsSync(npxCli))
|
|
3318
3484
|
throw new Error("npx was not found next to Node.js");
|
|
3319
3485
|
return { cmd: process.execPath, args: [npxCli, "-y", pkg, ...extra], env: {} };
|
|
3320
3486
|
}
|
|
3321
3487
|
function ownCopy(a) {
|
|
3322
3488
|
const bin = a.distribution.binary?.[platformKey()];
|
|
3323
3489
|
if (bin) {
|
|
3324
|
-
const cmd = onPath(
|
|
3490
|
+
const cmd = onPath(path16.basename(bin.cmd).replace(/\.exe$/i, ""));
|
|
3325
3491
|
return cmd ? { cmd, args: bin.args ?? [], env: bin.env ?? {} } : null;
|
|
3326
3492
|
}
|
|
3327
3493
|
const npx = a.distribution.npx;
|
|
@@ -3332,6 +3498,108 @@ function ownCopy(a) {
|
|
|
3332
3498
|
}
|
|
3333
3499
|
return null;
|
|
3334
3500
|
}
|
|
3501
|
+
async function unpackBinary(id, version, bin, progress) {
|
|
3502
|
+
if (!/^[0-9a-f]{64}$/i.test(bin.sha256 || ""))
|
|
3503
|
+
throw new Error(`Agent ${id}: the registry gives no sha256; not installed`);
|
|
3504
|
+
const dir = path16.join(agentDir(), id, version);
|
|
3505
|
+
const tmp = `${dir}.tmp`;
|
|
3506
|
+
await fsp5.rm(tmp, { recursive: true, force: true });
|
|
3507
|
+
await fsp5.mkdir(tmp, { recursive: true });
|
|
3508
|
+
try {
|
|
3509
|
+
const name = path16.basename(new URL(bin.archive).pathname);
|
|
3510
|
+
const cmdRel = bin.cmd.replace(/^\.\//, "");
|
|
3511
|
+
if (/\.zip$/i.test(name)) {
|
|
3512
|
+
const file = path16.join(tmp, ".download.zip");
|
|
3513
|
+
await downloadVerified(bin.archive, bin.sha256.toLowerCase(), file, progress);
|
|
3514
|
+
await unzip(file, tmp);
|
|
3515
|
+
await fsp5.rm(file, { force: true });
|
|
3516
|
+
} else if (/\.(tar\.gz|tgz)$/i.test(name)) {
|
|
3517
|
+
const file = path16.join(tmp, ".download.tar.gz");
|
|
3518
|
+
await downloadVerified(bin.archive, bin.sha256.toLowerCase(), file, progress);
|
|
3519
|
+
await untarGz(file, tmp);
|
|
3520
|
+
await fsp5.rm(file, { force: true });
|
|
3521
|
+
} else if (/\.gz$/i.test(name)) {
|
|
3522
|
+
await downloadVerified(bin.archive, bin.sha256.toLowerCase(), path16.join(tmp, cmdRel), progress, true);
|
|
3523
|
+
} else
|
|
3524
|
+
throw new Error(`Agent ${id}: unsupported archive ${name}`);
|
|
3525
|
+
const cmd = path16.join(tmp, cmdRel);
|
|
3526
|
+
if (!fs20.existsSync(cmd))
|
|
3527
|
+
throw new Error(`Agent ${id}: ${bin.cmd} is not in the download`);
|
|
3528
|
+
if (process.platform !== "win32")
|
|
3529
|
+
await fsp5.chmod(cmd, 493);
|
|
3530
|
+
await fsp5.rm(dir, { recursive: true, force: true });
|
|
3531
|
+
await fsp5.rename(tmp, dir);
|
|
3532
|
+
return { cmd: path16.join(dir, cmdRel), args: bin.args ?? [], env: bin.env ?? {} };
|
|
3533
|
+
} catch (e) {
|
|
3534
|
+
await fsp5.rm(tmp, { recursive: true, force: true });
|
|
3535
|
+
throw e;
|
|
3536
|
+
}
|
|
3537
|
+
}
|
|
3538
|
+
var codexAcpRelease = () => process.env.HYPEFRAME_CODEX_ACP_RELEASE || "https://api.github.com/repos/zed-industries/codex-acp/releases/latest";
|
|
3539
|
+
async function codexAcpBuild(arch) {
|
|
3540
|
+
const j = await (await fetch(codexAcpRelease(), { headers: { accept: "application/vnd.github+json", "user-agent": "hypeframe" }, signal: AbortSignal.timeout(20000) })).json();
|
|
3541
|
+
const triple = arch === "x64" ? "x86_64" : "aarch64";
|
|
3542
|
+
const asset = (j.assets ?? []).find((x) => new RegExp(`${triple}-unknown-linux-musl\\.tar\\.gz$`).test(String(x.name)));
|
|
3543
|
+
const sha256 = /^sha256:([0-9a-f]{64})$/i.exec(String(asset?.digest ?? ""))?.[1];
|
|
3544
|
+
const url = String(asset?.browser_download_url ?? "");
|
|
3545
|
+
if (!asset || !sha256 || !url)
|
|
3546
|
+
throw new Error("codex-acp: no checked Linux build for this phone");
|
|
3547
|
+
if (!process.env.HYPEFRAME_CODEX_ACP_RELEASE && !url.startsWith("https://github.com/"))
|
|
3548
|
+
throw new Error("codex-acp: unexpected download address");
|
|
3549
|
+
return { url, sha256: sha256.toLowerCase(), version: String(j.tag_name ?? "latest").replace(/^v/, "") };
|
|
3550
|
+
}
|
|
3551
|
+
var findFile = (dir, name) => {
|
|
3552
|
+
for (const n of fs20.readdirSync(dir)) {
|
|
3553
|
+
const f = path16.join(dir, n);
|
|
3554
|
+
const st = fs20.lstatSync(f);
|
|
3555
|
+
if (st.isFile() && n === name)
|
|
3556
|
+
return f;
|
|
3557
|
+
if (st.isDirectory()) {
|
|
3558
|
+
const inner = findFile(f, name);
|
|
3559
|
+
if (inner)
|
|
3560
|
+
return inner;
|
|
3561
|
+
}
|
|
3562
|
+
}
|
|
3563
|
+
return null;
|
|
3564
|
+
};
|
|
3565
|
+
async function installInLinux(a, id, progress, steps, arch) {
|
|
3566
|
+
steps.prepare();
|
|
3567
|
+
if (id === "antigravity-acp") {
|
|
3568
|
+
if (!steps.run("curl -fsSL https://antigravity.google/cli/install.sh | bash"))
|
|
3569
|
+
throw new Error("Antigravity: Google's installer did not finish in the Linux mini");
|
|
3570
|
+
if (!fs20.existsSync(path16.join(rootfs(), "root", ".local", "bin", "agy")))
|
|
3571
|
+
throw new Error("Antigravity: agy was not installed in the Linux mini");
|
|
3572
|
+
return { launch: { cmd: "/root/.local/bin/agy", args: ["acp"], env: {}, linux: true }, version: a.version };
|
|
3573
|
+
}
|
|
3574
|
+
if (id === "codex-acp") {
|
|
3575
|
+
const b = await codexAcpBuild(arch);
|
|
3576
|
+
const dir = path16.join(agentDir(), id, b.version);
|
|
3577
|
+
const tmp = `${dir}.tmp`;
|
|
3578
|
+
await fsp5.rm(tmp, { recursive: true, force: true });
|
|
3579
|
+
await fsp5.mkdir(tmp, { recursive: true });
|
|
3580
|
+
try {
|
|
3581
|
+
const file = path16.join(tmp, ".download.tar.gz");
|
|
3582
|
+
await downloadVerified(b.url, b.sha256, file, progress);
|
|
3583
|
+
await untarGz(file, tmp);
|
|
3584
|
+
await fsp5.rm(file, { force: true });
|
|
3585
|
+
const found = findFile(tmp, "codex-acp");
|
|
3586
|
+
if (!found)
|
|
3587
|
+
throw new Error("codex-acp: the program is not in the download");
|
|
3588
|
+
const rel = path16.relative(tmp, found);
|
|
3589
|
+
await fsp5.chmod(found, 493);
|
|
3590
|
+
await fsp5.rm(dir, { recursive: true, force: true });
|
|
3591
|
+
await fsp5.rename(tmp, dir);
|
|
3592
|
+
return { launch: { cmd: path16.join(dir, rel), args: [], env: {}, linux: true }, version: b.version };
|
|
3593
|
+
} catch (e) {
|
|
3594
|
+
await fsp5.rm(tmp, { recursive: true, force: true });
|
|
3595
|
+
throw e;
|
|
3596
|
+
}
|
|
3597
|
+
}
|
|
3598
|
+
const bin = a.distribution.binary?.[`linux-${arch === "x64" ? "x86_64" : "aarch64"}`];
|
|
3599
|
+
if (!bin)
|
|
3600
|
+
throw new Error(`Agent ${id} has no Linux build to run on this phone`);
|
|
3601
|
+
return { launch: { ...await unpackBinary(id, a.version, bin, progress), linux: true }, version: a.version };
|
|
3602
|
+
}
|
|
3335
3603
|
async function installAgent(id, progress = () => {
|
|
3336
3604
|
return;
|
|
3337
3605
|
}, opts = {}) {
|
|
@@ -3341,6 +3609,13 @@ async function installAgent(id, progress = () => {
|
|
|
3341
3609
|
const local = a.distribution.local;
|
|
3342
3610
|
if (!isSupported(id) && !local)
|
|
3343
3611
|
throw new Error(`Agent ${id} is not supported`);
|
|
3612
|
+
if (!local && (opts.android ?? isAndroid())) {
|
|
3613
|
+
const steps = opts.linux ?? { prepare: () => prepareLinux(opts.say), run: runInLinux };
|
|
3614
|
+
const r = await installInLinux(a, id, progress, steps, opts.arch ?? process.arch);
|
|
3615
|
+
const installed = { id, name: a.name, version: r.version, launch: r.launch };
|
|
3616
|
+
writeInstalled(installed);
|
|
3617
|
+
return installed;
|
|
3618
|
+
}
|
|
3344
3619
|
let launch;
|
|
3345
3620
|
const bin = a.distribution.binary?.[platformKey()];
|
|
3346
3621
|
const own = local || opts.download ? null : ownCopy(a);
|
|
@@ -3349,41 +3624,7 @@ async function installAgent(id, progress = () => {
|
|
|
3349
3624
|
} else if (own) {
|
|
3350
3625
|
launch = own;
|
|
3351
3626
|
} else if (bin) {
|
|
3352
|
-
|
|
3353
|
-
throw new Error(`Agent ${id}: the registry gives no sha256; not installed`);
|
|
3354
|
-
const dir = path15.join(agentDir(), id, a.version);
|
|
3355
|
-
const tmp = `${dir}.tmp`;
|
|
3356
|
-
await fsp5.rm(tmp, { recursive: true, force: true });
|
|
3357
|
-
await fsp5.mkdir(tmp, { recursive: true });
|
|
3358
|
-
try {
|
|
3359
|
-
const name = path15.basename(new URL(bin.archive).pathname);
|
|
3360
|
-
const cmdRel = bin.cmd.replace(/^\.\//, "");
|
|
3361
|
-
if (/\.zip$/i.test(name)) {
|
|
3362
|
-
const file = path15.join(tmp, ".download.zip");
|
|
3363
|
-
await downloadVerified(bin.archive, bin.sha256.toLowerCase(), file, progress);
|
|
3364
|
-
await unzip(file, tmp);
|
|
3365
|
-
await fsp5.rm(file, { force: true });
|
|
3366
|
-
} else if (/\.(tar\.gz|tgz)$/i.test(name)) {
|
|
3367
|
-
const file = path15.join(tmp, ".download.tar.gz");
|
|
3368
|
-
await downloadVerified(bin.archive, bin.sha256.toLowerCase(), file, progress);
|
|
3369
|
-
await untarGz(file, tmp);
|
|
3370
|
-
await fsp5.rm(file, { force: true });
|
|
3371
|
-
} else if (/\.gz$/i.test(name)) {
|
|
3372
|
-
await downloadVerified(bin.archive, bin.sha256.toLowerCase(), path15.join(tmp, cmdRel), progress, true);
|
|
3373
|
-
} else
|
|
3374
|
-
throw new Error(`Agent ${id}: unsupported archive ${name}`);
|
|
3375
|
-
const cmd = path15.join(tmp, cmdRel);
|
|
3376
|
-
if (!fs19.existsSync(cmd))
|
|
3377
|
-
throw new Error(`Agent ${id}: ${bin.cmd} is not in the download`);
|
|
3378
|
-
if (process.platform !== "win32")
|
|
3379
|
-
await fsp5.chmod(cmd, 493);
|
|
3380
|
-
await fsp5.rm(dir, { recursive: true, force: true });
|
|
3381
|
-
await fsp5.rename(tmp, dir);
|
|
3382
|
-
launch = { cmd: path15.join(dir, cmdRel), args: bin.args ?? [], env: bin.env ?? {} };
|
|
3383
|
-
} catch (e) {
|
|
3384
|
-
await fsp5.rm(tmp, { recursive: true, force: true });
|
|
3385
|
-
throw e;
|
|
3386
|
-
}
|
|
3627
|
+
launch = await unpackBinary(id, a.version, bin, progress);
|
|
3387
3628
|
} else if (a.distribution.npx) {
|
|
3388
3629
|
launch = { ...npxRunner(a.distribution.npx.package, a.distribution.npx.args), env: { ...a.distribution.npx.env ?? {} } };
|
|
3389
3630
|
if (isStandalone())
|
|
@@ -3396,7 +3637,7 @@ async function installAgent(id, progress = () => {
|
|
|
3396
3637
|
}
|
|
3397
3638
|
|
|
3398
3639
|
// src/agent/login.ts
|
|
3399
|
-
import { spawnSync as
|
|
3640
|
+
import { spawnSync as spawnSync4 } from "node:child_process";
|
|
3400
3641
|
async function keyFromShell(name, io) {
|
|
3401
3642
|
const value = process.env[name];
|
|
3402
3643
|
if (!value)
|
|
@@ -3443,7 +3684,8 @@ async function loginAgent(id, io) {
|
|
|
3443
3684
|
}
|
|
3444
3685
|
if (method?.type === "terminal") {
|
|
3445
3686
|
io.say(method.name || method.description || id);
|
|
3446
|
-
const
|
|
3687
|
+
const [cmd, args, env] = agentSpawn(a, { ...agentEnv(id), ...method.env ?? {} }, method.args ?? []);
|
|
3688
|
+
const r = spawnSync4(cmd, args, { stdio: "inherit", env });
|
|
3447
3689
|
if (r.status !== 0)
|
|
3448
3690
|
return setReady(id, false), false;
|
|
3449
3691
|
} else if (method && isKey(method)) {
|
|
@@ -3500,9 +3742,11 @@ async function addAgent(id, download = false) {
|
|
|
3500
3742
|
log.info(t("agent.installing", { name: agentName(id) }));
|
|
3501
3743
|
let last = -10;
|
|
3502
3744
|
const a = await installAgent(id, (pc) => {
|
|
3503
|
-
if (pc - last >= 20)
|
|
3504
|
-
last = pc
|
|
3505
|
-
|
|
3745
|
+
if (pc - last >= 20 || pc >= 100 && last < 100) {
|
|
3746
|
+
last = pc;
|
|
3747
|
+
log.detail(pc >= 100 ? t("agent.unpacking") : `${pc}%`);
|
|
3748
|
+
}
|
|
3749
|
+
}, { download, say: (k) => log.info(t(k)) });
|
|
3506
3750
|
if (a.own)
|
|
3507
3751
|
log.ok(t("agent.own", { name: a.name, path: a.launch.cmd }));
|
|
3508
3752
|
else
|
|
@@ -3514,7 +3758,13 @@ async function addAgent(id, download = false) {
|
|
|
3514
3758
|
}
|
|
3515
3759
|
async function loginOne(id) {
|
|
3516
3760
|
log.info(t("agent.loggingIn", { name: agentName(id) }));
|
|
3517
|
-
const
|
|
3761
|
+
const stop = isAndroid() ? watchOpenRequests((url) => {
|
|
3762
|
+
log.info(t("linux.openUrl", { url }));
|
|
3763
|
+
openOnPhone(url);
|
|
3764
|
+
}) : () => {
|
|
3765
|
+
return;
|
|
3766
|
+
};
|
|
3767
|
+
const ok = await loginAgent(id, io).finally(stop);
|
|
3518
3768
|
if (ok)
|
|
3519
3769
|
log.ok(t("agent.loggedIn", { name: agentName(id) }));
|
|
3520
3770
|
else
|
|
@@ -3640,9 +3890,9 @@ async function config(args) {
|
|
|
3640
3890
|
}
|
|
3641
3891
|
|
|
3642
3892
|
// src/cli/commands/doctor.ts
|
|
3643
|
-
import { spawnSync as
|
|
3644
|
-
import
|
|
3645
|
-
import
|
|
3893
|
+
import { spawnSync as spawnSync5 } from "node:child_process";
|
|
3894
|
+
import fs21 from "node:fs";
|
|
3895
|
+
import path17 from "node:path";
|
|
3646
3896
|
var mark = { ok: color.ok(icon.ok), warn: color.warn(icon.warn), error: color.error(icon.error) };
|
|
3647
3897
|
async function reach(url) {
|
|
3648
3898
|
const t0 = Date.now();
|
|
@@ -3671,10 +3921,10 @@ async function doctor(args) {
|
|
|
3671
3921
|
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")}` : ""}` });
|
|
3672
3922
|
}
|
|
3673
3923
|
try {
|
|
3674
|
-
const probe =
|
|
3675
|
-
|
|
3676
|
-
|
|
3677
|
-
const st =
|
|
3924
|
+
const probe = path17.join(dataDir(), `.probe-${process.pid}`);
|
|
3925
|
+
fs21.writeFileSync(probe, "x");
|
|
3926
|
+
fs21.rmSync(probe);
|
|
3927
|
+
const st = fs21.statfsSync(dataDir());
|
|
3678
3928
|
const free = st.bavail * st.bsize;
|
|
3679
3929
|
show({ label: t("doctor.disk"), result: free > 2 * 1024 ** 3 ? "ok" : "warn", detail: `${dataDir()} ${color.muted(icon.dot)} ${t("doctor.free", { size: bytes2(free) })}` });
|
|
3680
3930
|
} catch (e) {
|
|
@@ -3685,7 +3935,7 @@ async function doctor(args) {
|
|
|
3685
3935
|
const canDownload = !!FFMPEG_PINNED[`${process.platform}-${process.arch}`];
|
|
3686
3936
|
show({ label: "ffmpeg", result: canDownload ? "warn" : "error", detail: canDownload ? t("doctor.ffmpegLater") : t("doctor.noFfmpeg") });
|
|
3687
3937
|
} else {
|
|
3688
|
-
const r =
|
|
3938
|
+
const r = spawnSync5(ff, ["-hide_banner", "-version"], { encoding: "utf8", timeout: 15000 });
|
|
3689
3939
|
const v = /ffmpeg version (\S+)/.exec(r.stdout || "")?.[1];
|
|
3690
3940
|
show({ label: "ffmpeg", result: v ? "ok" : "error", detail: v || t("doctor.noFfmpeg") });
|
|
3691
3941
|
}
|
|
@@ -3718,21 +3968,21 @@ async function doctor(args) {
|
|
|
3718
3968
|
}
|
|
3719
3969
|
|
|
3720
3970
|
// src/cli/commands/history.ts
|
|
3721
|
-
import
|
|
3722
|
-
import
|
|
3971
|
+
import fs22 from "node:fs";
|
|
3972
|
+
import path18 from "node:path";
|
|
3723
3973
|
function readHistory2(hours = 24) {
|
|
3724
3974
|
const root = renderDir();
|
|
3725
3975
|
const since = Date.now() - hours * 3600000;
|
|
3726
3976
|
const out = [];
|
|
3727
|
-
for (const name of
|
|
3977
|
+
for (const name of fs22.readdirSync(root)) {
|
|
3728
3978
|
if (!JOB_ID.test(name))
|
|
3729
3979
|
continue;
|
|
3730
3980
|
try {
|
|
3731
|
-
const j = JSON.parse(
|
|
3981
|
+
const j = JSON.parse(fs22.readFileSync(path18.join(root, name, "status.json"), "utf8"));
|
|
3732
3982
|
if ((j.diperbarui || j.dibuat) < since)
|
|
3733
3983
|
continue;
|
|
3734
|
-
const f = j.hasilBerkas ?
|
|
3735
|
-
out.push({ job: j, file: f &&
|
|
3984
|
+
const f = j.hasilBerkas ? path18.join(root, name, j.hasilBerkas) : null;
|
|
3985
|
+
out.push({ job: j, file: f && fs22.existsSync(f) ? f : null });
|
|
3736
3986
|
} catch {}
|
|
3737
3987
|
}
|
|
3738
3988
|
return out.sort((a, b) => (b.job.diperbarui || 0) - (a.job.diperbarui || 0));
|
|
@@ -3758,31 +4008,31 @@ function history() {
|
|
|
3758
4008
|
}
|
|
3759
4009
|
|
|
3760
4010
|
// src/cli/commands/maintenance.ts
|
|
3761
|
-
import { spawnSync as
|
|
3762
|
-
import
|
|
4011
|
+
import { spawnSync as spawnSync6 } from "node:child_process";
|
|
4012
|
+
import fs23 from "node:fs";
|
|
3763
4013
|
import os4 from "node:os";
|
|
3764
|
-
import
|
|
4014
|
+
import path19 from "node:path";
|
|
3765
4015
|
async function clean() {
|
|
3766
4016
|
if (runningPid()) {
|
|
3767
4017
|
log.warn(t("clean.running"));
|
|
3768
4018
|
return;
|
|
3769
4019
|
}
|
|
3770
|
-
const targets = [
|
|
3771
|
-
for (const job of
|
|
4020
|
+
const targets = [path19.join(cacheDir(), "chrome"), path19.join(cacheDir(), "halaman"), path19.join(logDir(), "hypeframe.log.1")];
|
|
4021
|
+
for (const job of fs23.readdirSync(renderDir())) {
|
|
3772
4022
|
if (!JOB_ID.test(job))
|
|
3773
4023
|
continue;
|
|
3774
4024
|
try {
|
|
3775
|
-
const s = JSON.parse(
|
|
4025
|
+
const s = JSON.parse(fs23.readFileSync(path19.join(renderDir(), job, "status.json"), "utf8")).status;
|
|
3776
4026
|
if (s === "gagal" || s === "batal" || s === "unggah")
|
|
3777
|
-
targets.push(
|
|
4027
|
+
targets.push(path19.join(renderDir(), job));
|
|
3778
4028
|
} catch {
|
|
3779
|
-
targets.push(
|
|
4029
|
+
targets.push(path19.join(renderDir(), job));
|
|
3780
4030
|
}
|
|
3781
4031
|
}
|
|
3782
4032
|
let freed = 0;
|
|
3783
4033
|
for (const p of targets) {
|
|
3784
4034
|
freed += await sizeOf(p);
|
|
3785
|
-
|
|
4035
|
+
fs23.rmSync(p, { recursive: true, force: true });
|
|
3786
4036
|
}
|
|
3787
4037
|
log.ok(t("clean.done", { size: bytes2(freed) }));
|
|
3788
4038
|
}
|
|
@@ -3791,7 +4041,7 @@ function report() {
|
|
|
3791
4041
|
const a = readAccount();
|
|
3792
4042
|
let recent = "";
|
|
3793
4043
|
try {
|
|
3794
|
-
recent =
|
|
4044
|
+
recent = fs23.readFileSync(path19.join(logDir(), "hypeframe.log"), "utf8").split(`
|
|
3795
4045
|
`).slice(-400).join(`
|
|
3796
4046
|
`);
|
|
3797
4047
|
} catch {
|
|
@@ -3812,8 +4062,8 @@ function report() {
|
|
|
3812
4062
|
recent
|
|
3813
4063
|
];
|
|
3814
4064
|
const stamp = new Date().toISOString().slice(0, 19).replace(/[-:T]/g, "");
|
|
3815
|
-
const file =
|
|
3816
|
-
|
|
4065
|
+
const file = path19.join(dataDir(), `laporan-${stamp}.txt`);
|
|
4066
|
+
fs23.writeFileSync(file, mask(lines.join(`
|
|
3817
4067
|
`)), { mode: 384 });
|
|
3818
4068
|
log.ok(t("report.done", { file }));
|
|
3819
4069
|
log.detail(t("report.hint"));
|
|
@@ -3834,7 +4084,7 @@ function update() {
|
|
|
3834
4084
|
}
|
|
3835
4085
|
log.info(t("update.running"));
|
|
3836
4086
|
const [cmd, args, extra] = updateCommand({ standalone: isStandalone(), android: isAndroid(), windows: process.platform === "win32" });
|
|
3837
|
-
const r =
|
|
4087
|
+
const r = spawnSync6(cmd, args, { stdio: "inherit", ...extra });
|
|
3838
4088
|
if (r.status === 0)
|
|
3839
4089
|
log.ok(t("update.done"));
|
|
3840
4090
|
else
|
|
@@ -3849,13 +4099,13 @@ function openWeb(args) {
|
|
|
3849
4099
|
}
|
|
3850
4100
|
|
|
3851
4101
|
// src/cli/commands/status.ts
|
|
3852
|
-
import
|
|
3853
|
-
import
|
|
4102
|
+
import fs24 from "node:fs";
|
|
4103
|
+
import path20 from "node:path";
|
|
3854
4104
|
function statusRows(args) {
|
|
3855
4105
|
const s = resolveSettings(args?.flags);
|
|
3856
4106
|
const a = readAccount();
|
|
3857
4107
|
const pid = runningPid();
|
|
3858
|
-
const chrome = findChrome() ||
|
|
4108
|
+
const chrome = findChrome() || fs24.existsSync(path20.join(cacheDir(), "chrome"));
|
|
3859
4109
|
const recent = readHistory2();
|
|
3860
4110
|
const k = (key) => color.muted(t(key));
|
|
3861
4111
|
return [
|