hypeframe 0.9.2 → 0.9.3
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 +14 -5
- package/dist/index.js +930 -548
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -244,6 +244,8 @@ var id = {
|
|
|
244
244
|
"agentLog.option": "{agent}: {what} diganti ke {value}",
|
|
245
245
|
"agentLog.stopped": "✦ {agent} berhenti (kode {code}). Obrolan baru menyalakannya lagi.",
|
|
246
246
|
"agentLog.account": "✦ Akun {agent} berganti: dimuat ulang, obrolan berikutnya memakai akun baru.",
|
|
247
|
+
"agentLog.terminal": "✦ Terminal penuh {agent} dibuka dari web.",
|
|
248
|
+
"agentLog.terminalClosed": "Terminal penuh {agent} ditutup.",
|
|
247
249
|
"engine.agentsReady": "Asisten AI siap: {list}",
|
|
248
250
|
"engine.agentsNone": "Belum ada asisten AI. Pasang dari menu hypeframe > Asisten AI.",
|
|
249
251
|
"engine.statusHint": "Tekan Enter kapan saja untuk melihat status.",
|
|
@@ -516,6 +518,8 @@ var en = {
|
|
|
516
518
|
"agentLog.option": "{agent}: {what} changed to {value}",
|
|
517
519
|
"agentLog.stopped": "✦ {agent} stopped (code {code}). A new chat starts it again.",
|
|
518
520
|
"agentLog.account": "✦ {agent} account changed: reloaded, the next chat uses the new account.",
|
|
521
|
+
"agentLog.terminal": "✦ {agent} full terminal opened from the web.",
|
|
522
|
+
"agentLog.terminalClosed": "{agent} full terminal closed.",
|
|
519
523
|
"engine.agentsReady": "AI assistants ready: {list}",
|
|
520
524
|
"engine.agentsNone": "No AI assistant yet. Add one from the hypeframe menu > AI assistant.",
|
|
521
525
|
"engine.statusHint": "Press Enter at any time to see the status.",
|
|
@@ -796,12 +800,12 @@ var log = {
|
|
|
796
800
|
};
|
|
797
801
|
|
|
798
802
|
// packages/hypeframe/src/cli/commands/start.ts
|
|
799
|
-
import
|
|
803
|
+
import crypto10 from "node:crypto";
|
|
800
804
|
import readline3 from "node:readline";
|
|
801
805
|
|
|
802
806
|
// packages/protocol/src/index.ts
|
|
803
807
|
var PROTOCOL_VERSION = 1;
|
|
804
|
-
var ALLOWED_KINDS = ["status", "kunci", "agen.mulai", "agen.kirim", "agen.izin", "agen.batal", "agen.opsi", "agen.riwayat", "agen.akun", "render.relai"];
|
|
808
|
+
var ALLOWED_KINDS = ["status", "kunci", "agen.mulai", "agen.kirim", "agen.izin", "agen.batal", "agen.opsi", "agen.riwayat", "agen.akun", "terminal.buka", "terminal.tutup", "render.relai"];
|
|
805
809
|
var CloseCode = {
|
|
806
810
|
BadHello: 4001,
|
|
807
811
|
Replaced: 4002,
|
|
@@ -823,13 +827,13 @@ var EngineError = {
|
|
|
823
827
|
};
|
|
824
828
|
|
|
825
829
|
// packages/hypeframe/src/agent/service.ts
|
|
826
|
-
import
|
|
827
|
-
import
|
|
828
|
-
import
|
|
830
|
+
import crypto5 from "node:crypto";
|
|
831
|
+
import fs15 from "node:fs";
|
|
832
|
+
import path12 from "node:path";
|
|
829
833
|
// packages/hypeframe/package.json
|
|
830
834
|
var package_default = {
|
|
831
835
|
name: "hypeframe",
|
|
832
|
-
version: "0.9.
|
|
836
|
+
version: "0.9.3",
|
|
833
837
|
description: "Local engine for HypeFrame Web: code clips, video renders and AI agents run on your own machine; the web is just the view.",
|
|
834
838
|
keywords: [
|
|
835
839
|
"hypeframe",
|
|
@@ -883,7 +887,7 @@ var package_default = {
|
|
|
883
887
|
var VERSION = process.env.HF_MESIN_VERSI || package_default.version;
|
|
884
888
|
|
|
885
889
|
// packages/hypeframe/src/agent/instructions.ts
|
|
886
|
-
var MCP_INSTRUCTIONS = "Tools to make videos from code in HypeFrame Web, open in the user's browser. Tools run in that browser tab, so HypeFrame Web must stay open. " +
|
|
890
|
+
var MCP_INSTRUCTIONS = "Tools to make videos from code in HypeFrame Web, open in the user's browser. Tools run in that browser tab, so HypeFrame Web must stay open. " + 'A project is a sequence of scenes written in code plus sound written in code (create_audio, Web Audio). Every scene is ONE complete HTML page whose script defines window.seek(t) (the only engine: "halaman"); built in, offline: GSAP (window.gsap), three.js, Lottie, PixiJS and HF.shader for GLSL shaders (see the motion code rules in the tool descriptions). ' + "CODE FIRST (the main feature of HypeFrame): build every scene of a new video by writing that page and passing it in the html argument of preview_motion and then create_motion, and make sound with create_audio. Writing that code through these tools is your main job here; never say you cannot write code. Do not build scenes from add_text, add_shape or add_image layers: use those (and set_keyframe) only when the user asks for a small manual change to a video that already exists. " + "Try code with preview_motion first. Depending on the permission setting of the user, create_motion / create_audio runs at once (the code is still shown in HypeFrame Web) or waits until the user approves it, so wait for the job result with get_job_status. " + "At the start of every conversation call get_memory first: it shows unfinished work saved by earlier conversations. If there is unfinished work, say in one or two sentences what it was and ask whether to continue it. " + "Keep the memory current: call save_memory after every finished step. " + "Before creating a project, call list_skills, pick the best skill (say which) and read it with use_skill. A skill can be a package with files: read examples with read_skill_file and put assets into the project with import_skill_files. " + "All times are in frames (seconds x project fps). " + "render_video may ask the user to approve (their setting) and returns immediately: poll get_render_status until it finishes. Most users write in Indonesian: write every message, including progress notes, in their language.";
|
|
887
891
|
var AGENTS_MD = `# HypeFrame
|
|
888
892
|
|
|
889
893
|
You are running on the user's computer through the HypeFrame engine. The user types to you from HypeFrame Web (in a browser, possibly on another device) to make videos. This folder is the only place you may read or write files.
|
|
@@ -1942,6 +1946,691 @@ class AgentSessions {
|
|
|
1942
1946
|
}
|
|
1943
1947
|
}
|
|
1944
1948
|
|
|
1949
|
+
// packages/hypeframe/src/agent/terminal.ts
|
|
1950
|
+
import { spawn as spawn3, spawnSync as spawnSync3 } from "node:child_process";
|
|
1951
|
+
import crypto4 from "node:crypto";
|
|
1952
|
+
import fs14 from "node:fs";
|
|
1953
|
+
import fsp3 from "node:fs/promises";
|
|
1954
|
+
import os3 from "node:os";
|
|
1955
|
+
import path11 from "node:path";
|
|
1956
|
+
|
|
1957
|
+
// packages/hypeframe/src/render/ffmpeg.ts
|
|
1958
|
+
import crypto3 from "node:crypto";
|
|
1959
|
+
import fs11 from "node:fs";
|
|
1960
|
+
import fsp from "node:fs/promises";
|
|
1961
|
+
import path8 from "node:path";
|
|
1962
|
+
import { pipeline } from "node:stream/promises";
|
|
1963
|
+
import { Readable } from "node:stream";
|
|
1964
|
+
import zlib from "node:zlib";
|
|
1965
|
+
var FFMPEG_RELEASE = "b6.0";
|
|
1966
|
+
var BASE = `https://github.com/eugeneware/ffmpeg-static/releases/download/${FFMPEG_RELEASE}/`;
|
|
1967
|
+
var FFMPEG_PINNED = {
|
|
1968
|
+
"win32-x64": { sha256: "450d66226c79405c724e821f291cab0911e934bfa9fa2231adcab587f3e07b50", size: 28894894 },
|
|
1969
|
+
"linux-x64": { sha256: "17c1ae10b52ac499180679fe6ba77e17642390c4eedb0f1e3b0ac045da55128f", size: 28928723 },
|
|
1970
|
+
"linux-arm64": { sha256: "2b708b2d15041d2a192c1db24c7a8a1d24f645a8242dce1c744ff2392b86ada1", size: 25131803 },
|
|
1971
|
+
"darwin-x64": { sha256: "a12354fce7eb62361473bbe10d53a1893695babd35869ec8e92e5dfea8d0440b", size: 25067704 },
|
|
1972
|
+
"darwin-arm64": { sha256: "6be74d6f449889c2e87a75873894f8520cad56c08ac76f2a628d85b0519daaca", size: 19253088 }
|
|
1973
|
+
};
|
|
1974
|
+
var exe = process.platform === "win32" ? "ffmpeg.exe" : "ffmpeg";
|
|
1975
|
+
var cached2 = (cacheDir) => path8.join(cacheDir, "ffmpeg", FFMPEG_RELEASE, exe);
|
|
1976
|
+
var thisPlatform = () => `${process.platform}-${process.arch}`;
|
|
1977
|
+
async function findFfmpeg(cacheDir, key = thisPlatform()) {
|
|
1978
|
+
const forced = process.env.HYPEFRAME_FFMPEG;
|
|
1979
|
+
if (forced)
|
|
1980
|
+
return fs11.existsSync(forced) ? forced : null;
|
|
1981
|
+
if (!FFMPEG_PINNED[key])
|
|
1982
|
+
return onPath("ffmpeg");
|
|
1983
|
+
try {
|
|
1984
|
+
const mod = await import("ffmpeg-static");
|
|
1985
|
+
const p = typeof mod.default === "string" ? mod.default : null;
|
|
1986
|
+
if (p && fs11.existsSync(p))
|
|
1987
|
+
return p;
|
|
1988
|
+
} catch {}
|
|
1989
|
+
const c = cached2(cacheDir);
|
|
1990
|
+
return fs11.existsSync(c) ? c : null;
|
|
1991
|
+
}
|
|
1992
|
+
async function downloadVerified(url, sha256, dest, progress = () => {
|
|
1993
|
+
return;
|
|
1994
|
+
}, gunzip = false) {
|
|
1995
|
+
const r = await fetch(url, { signal: AbortSignal.timeout(900000) });
|
|
1996
|
+
if (!r.ok || !r.body)
|
|
1997
|
+
throw new Error(`download ${r.status}`);
|
|
1998
|
+
const total = Number(r.headers.get("content-length")) || 0;
|
|
1999
|
+
await fsp.mkdir(path8.dirname(dest), { recursive: true });
|
|
2000
|
+
const tmp = `${dest}.download`;
|
|
2001
|
+
const hash = crypto3.createHash("sha256");
|
|
2002
|
+
let got = 0;
|
|
2003
|
+
let last = -10;
|
|
2004
|
+
const body = Readable.fromWeb(r.body).on("data", (c) => {
|
|
2005
|
+
hash.update(c);
|
|
2006
|
+
got += c.length;
|
|
2007
|
+
const pct = total ? Math.floor(got / total * 100) : 0;
|
|
2008
|
+
if (pct - last >= 10)
|
|
2009
|
+
last = pct, progress(pct);
|
|
2010
|
+
});
|
|
2011
|
+
await pipeline(body, fs11.createWriteStream(tmp));
|
|
2012
|
+
if (hash.digest("hex") !== sha256) {
|
|
2013
|
+
await fsp.rm(tmp, { force: true });
|
|
2014
|
+
throw new Error("ffmpeg: sidik unduhan tidak cocok, berkas ditolak.");
|
|
2015
|
+
}
|
|
2016
|
+
if (gunzip) {
|
|
2017
|
+
await pipeline(fs11.createReadStream(tmp), zlib.createGunzip(), fs11.createWriteStream(`${tmp}.raw`));
|
|
2018
|
+
await fsp.rm(tmp, { force: true });
|
|
2019
|
+
await fsp.rename(`${tmp}.raw`, dest);
|
|
2020
|
+
} else
|
|
2021
|
+
await fsp.rename(tmp, dest);
|
|
2022
|
+
if (process.platform !== "win32")
|
|
2023
|
+
await fsp.chmod(dest, 493);
|
|
2024
|
+
}
|
|
2025
|
+
async function prepareFfmpeg(cacheDir, progress = () => {
|
|
2026
|
+
return;
|
|
2027
|
+
}, key = thisPlatform()) {
|
|
2028
|
+
const found = await findFfmpeg(cacheDir, key);
|
|
2029
|
+
if (found)
|
|
2030
|
+
return found;
|
|
2031
|
+
const pin = FFMPEG_PINNED[key];
|
|
2032
|
+
if (!pin)
|
|
2033
|
+
throw new Error(key.startsWith("android") ? "ffmpeg belum terpasang. Di Termux jalankan: pkg install ffmpeg" : `ffmpeg tidak tersedia untuk ${key}`);
|
|
2034
|
+
progress(0);
|
|
2035
|
+
await downloadVerified(`${BASE}ffmpeg-${key}.gz`, pin.sha256, cached2(cacheDir), progress, true);
|
|
2036
|
+
return cached2(cacheDir);
|
|
2037
|
+
}
|
|
2038
|
+
|
|
2039
|
+
// packages/hypeframe/src/agent/install.ts
|
|
2040
|
+
import fs13 from "node:fs";
|
|
2041
|
+
import fsp2 from "node:fs/promises";
|
|
2042
|
+
import path10 from "node:path";
|
|
2043
|
+
import yauzl from "yauzl";
|
|
2044
|
+
|
|
2045
|
+
// packages/hypeframe/src/util/runtime.ts
|
|
2046
|
+
import fs12 from "node:fs";
|
|
2047
|
+
import path9 from "node:path";
|
|
2048
|
+
function isStandalone() {
|
|
2049
|
+
return path9.basename(process.execPath).toLowerCase().startsWith("hypeframe");
|
|
2050
|
+
}
|
|
2051
|
+
function runtimeLabel() {
|
|
2052
|
+
const bun = process.versions.bun;
|
|
2053
|
+
return bun && !isStandalone() ? `Bun ${bun}` : isStandalone() ? `Bun ${bun ?? "?"} (standalone)` : `Node ${process.versions.node}`;
|
|
2054
|
+
}
|
|
2055
|
+
function launchCommand() {
|
|
2056
|
+
if (isStandalone())
|
|
2057
|
+
return [process.execPath];
|
|
2058
|
+
try {
|
|
2059
|
+
const script = fs12.realpathSync(process.argv[1] || "");
|
|
2060
|
+
return /[\\/]_npx[\\/]/.test(script) ? null : [process.execPath, script];
|
|
2061
|
+
} catch {
|
|
2062
|
+
return null;
|
|
2063
|
+
}
|
|
2064
|
+
}
|
|
2065
|
+
var INSTALL_URL = "https://hype-frame.com/install";
|
|
2066
|
+
|
|
2067
|
+
// packages/hypeframe/src/agent/install.ts
|
|
2068
|
+
function unzip(file, to) {
|
|
2069
|
+
return new Promise((ok, fail) => {
|
|
2070
|
+
yauzl.open(file, { lazyEntries: true }, (e, zip) => {
|
|
2071
|
+
if (e || !zip)
|
|
2072
|
+
return fail(e ?? new Error("zip"));
|
|
2073
|
+
zip.on("entry", (en) => {
|
|
2074
|
+
const target = path10.join(to, en.fileName);
|
|
2075
|
+
if (!target.startsWith(to + path10.sep))
|
|
2076
|
+
return fail(new Error("archive path outside the agent folder"));
|
|
2077
|
+
if (en.fileName.endsWith("/"))
|
|
2078
|
+
return fs13.mkdirSync(target, { recursive: true }), zip.readEntry();
|
|
2079
|
+
fs13.mkdirSync(path10.dirname(target), { recursive: true });
|
|
2080
|
+
zip.openReadStream(en, (e2, s) => {
|
|
2081
|
+
if (e2 || !s)
|
|
2082
|
+
return fail(e2 ?? new Error("zip"));
|
|
2083
|
+
const out = fs13.createWriteStream(target);
|
|
2084
|
+
s.pipe(out);
|
|
2085
|
+
out.on("finish", () => zip.readEntry());
|
|
2086
|
+
out.on("error", fail);
|
|
2087
|
+
});
|
|
2088
|
+
});
|
|
2089
|
+
zip.on("end", () => ok());
|
|
2090
|
+
zip.on("error", fail);
|
|
2091
|
+
zip.readEntry();
|
|
2092
|
+
});
|
|
2093
|
+
});
|
|
2094
|
+
}
|
|
2095
|
+
async function untarGz(file, to) {
|
|
2096
|
+
const { gunzipSync } = await import("node:zlib");
|
|
2097
|
+
const data = gunzipSync(await fsp2.readFile(file));
|
|
2098
|
+
const root = path10.resolve(to);
|
|
2099
|
+
const str = (b) => b.toString("utf8").replace(/\0[\s\S]*$/, "");
|
|
2100
|
+
const octal = (b) => Number.parseInt(str(b).trim() || "0", 8) || 0;
|
|
2101
|
+
let off = 0;
|
|
2102
|
+
let longName = null;
|
|
2103
|
+
while (off + 512 <= data.length) {
|
|
2104
|
+
const h = data.subarray(off, off + 512);
|
|
2105
|
+
if (h.every((x) => x === 0))
|
|
2106
|
+
break;
|
|
2107
|
+
const size = octal(h.subarray(124, 136));
|
|
2108
|
+
const type = String.fromCharCode(h[156] || 48);
|
|
2109
|
+
const body = data.subarray(off + 512, off + 512 + size);
|
|
2110
|
+
off += 512 + Math.ceil(size / 512) * 512;
|
|
2111
|
+
const prefix = str(h.subarray(345, 500));
|
|
2112
|
+
let name = longName ?? (prefix ? `${prefix}/${str(h.subarray(0, 100))}` : str(h.subarray(0, 100)));
|
|
2113
|
+
longName = null;
|
|
2114
|
+
if (type === "x") {
|
|
2115
|
+
const m = body.toString("utf8").match(/(?:^|\n)\d+ path=([^\n]*)\n/);
|
|
2116
|
+
if (m)
|
|
2117
|
+
longName = m[1];
|
|
2118
|
+
continue;
|
|
2119
|
+
}
|
|
2120
|
+
if (type === "L") {
|
|
2121
|
+
longName = str(body);
|
|
2122
|
+
continue;
|
|
2123
|
+
}
|
|
2124
|
+
if (type === "g")
|
|
2125
|
+
continue;
|
|
2126
|
+
name = name.replace(/^\.\//, "");
|
|
2127
|
+
if (!name)
|
|
2128
|
+
continue;
|
|
2129
|
+
const target = path10.resolve(root, name);
|
|
2130
|
+
if (target !== root && !target.startsWith(root + path10.sep))
|
|
2131
|
+
throw new Error("archive path outside the agent folder");
|
|
2132
|
+
if (type === "5") {
|
|
2133
|
+
await fsp2.mkdir(target, { recursive: true });
|
|
2134
|
+
continue;
|
|
2135
|
+
}
|
|
2136
|
+
if (type !== "0" && type !== "7")
|
|
2137
|
+
continue;
|
|
2138
|
+
await fsp2.mkdir(path10.dirname(target), { recursive: true });
|
|
2139
|
+
await fsp2.writeFile(target, body, { mode: octal(h.subarray(100, 108)) & 73 ? 493 : 420 });
|
|
2140
|
+
}
|
|
2141
|
+
}
|
|
2142
|
+
function npxRunner(pkg, extra = []) {
|
|
2143
|
+
if (isStandalone())
|
|
2144
|
+
return { cmd: process.execPath, args: ["x", pkg, ...extra], env: { BUN_BE_BUN: "1" } };
|
|
2145
|
+
const npxCli = path10.join(path10.dirname(process.execPath), process.platform === "win32" ? "" : "..", process.platform === "win32" ? "node_modules" : "lib/node_modules", "npm", "bin", "npx-cli.js");
|
|
2146
|
+
if (!fs13.existsSync(npxCli))
|
|
2147
|
+
throw new Error("npx was not found next to Node.js");
|
|
2148
|
+
return { cmd: process.execPath, args: [npxCli, "-y", pkg, ...extra], env: {} };
|
|
2149
|
+
}
|
|
2150
|
+
function ownCopy(a) {
|
|
2151
|
+
const bin = a.distribution.binary?.[platformKey()];
|
|
2152
|
+
if (bin) {
|
|
2153
|
+
const cmd = onPath(path10.basename(bin.cmd).replace(/\.exe$/i, ""));
|
|
2154
|
+
return cmd ? { cmd, args: bin.args ?? [], env: bin.env ?? {} } : null;
|
|
2155
|
+
}
|
|
2156
|
+
const npx = a.distribution.npx;
|
|
2157
|
+
if (npx) {
|
|
2158
|
+
const name = npx.package.replace(/(?!^)@[^@/]*$/, "").split("/").pop() ?? "";
|
|
2159
|
+
const cmd = onPath(name);
|
|
2160
|
+
return cmd ? { cmd, args: npx.args ?? [], env: npx.env ?? {} } : null;
|
|
2161
|
+
}
|
|
2162
|
+
return null;
|
|
2163
|
+
}
|
|
2164
|
+
async function unpackBinary(id, version, bin, progress) {
|
|
2165
|
+
if (!/^[0-9a-f]{64}$/i.test(bin.sha256 || ""))
|
|
2166
|
+
throw new Error(`Agent ${id}: the registry gives no sha256; not installed`);
|
|
2167
|
+
const dir = path10.join(agentDir(), id, version);
|
|
2168
|
+
const tmp = `${dir}.tmp`;
|
|
2169
|
+
await fsp2.rm(tmp, { recursive: true, force: true });
|
|
2170
|
+
await fsp2.mkdir(tmp, { recursive: true });
|
|
2171
|
+
try {
|
|
2172
|
+
const name = path10.basename(new URL(bin.archive).pathname);
|
|
2173
|
+
const cmdRel = bin.cmd.replace(/^\.\//, "");
|
|
2174
|
+
if (/\.zip$/i.test(name)) {
|
|
2175
|
+
const file = path10.join(tmp, ".download.zip");
|
|
2176
|
+
await downloadVerified(bin.archive, bin.sha256.toLowerCase(), file, progress);
|
|
2177
|
+
await unzip(file, tmp);
|
|
2178
|
+
await fsp2.rm(file, { force: true });
|
|
2179
|
+
} else if (/\.(tar\.gz|tgz)$/i.test(name)) {
|
|
2180
|
+
const file = path10.join(tmp, ".download.tar.gz");
|
|
2181
|
+
await downloadVerified(bin.archive, bin.sha256.toLowerCase(), file, progress);
|
|
2182
|
+
await untarGz(file, tmp);
|
|
2183
|
+
await fsp2.rm(file, { force: true });
|
|
2184
|
+
} else if (/\.gz$/i.test(name)) {
|
|
2185
|
+
await downloadVerified(bin.archive, bin.sha256.toLowerCase(), path10.join(tmp, cmdRel), progress, true);
|
|
2186
|
+
} else
|
|
2187
|
+
throw new Error(`Agent ${id}: unsupported archive ${name}`);
|
|
2188
|
+
const cmd = path10.join(tmp, cmdRel);
|
|
2189
|
+
if (!fs13.existsSync(cmd))
|
|
2190
|
+
throw new Error(`Agent ${id}: ${bin.cmd} is not in the download`);
|
|
2191
|
+
if (process.platform !== "win32")
|
|
2192
|
+
await fsp2.chmod(cmd, 493);
|
|
2193
|
+
await fsp2.rm(dir, { recursive: true, force: true });
|
|
2194
|
+
await fsp2.rename(tmp, dir);
|
|
2195
|
+
return { cmd: path10.join(dir, cmdRel), args: bin.args ?? [], env: bin.env ?? {} };
|
|
2196
|
+
} catch (e) {
|
|
2197
|
+
await fsp2.rm(tmp, { recursive: true, force: true });
|
|
2198
|
+
throw e;
|
|
2199
|
+
}
|
|
2200
|
+
}
|
|
2201
|
+
var codexAcpRelease = () => process.env.HYPEFRAME_CODEX_ACP_RELEASE || "https://api.github.com/repos/zed-industries/codex-acp/releases/latest";
|
|
2202
|
+
async function codexAcpBuild(arch) {
|
|
2203
|
+
const j = await (await fetch(codexAcpRelease(), { headers: { accept: "application/vnd.github+json", "user-agent": "hypeframe" }, signal: AbortSignal.timeout(20000) })).json();
|
|
2204
|
+
const triple = arch === "x64" ? "x86_64" : "aarch64";
|
|
2205
|
+
const asset = (j.assets ?? []).find((x) => new RegExp(`${triple}-unknown-linux-musl\\.tar\\.gz$`).test(String(x.name)));
|
|
2206
|
+
const sha256 = /^sha256:([0-9a-f]{64})$/i.exec(String(asset?.digest ?? ""))?.[1];
|
|
2207
|
+
const url = String(asset?.browser_download_url ?? "");
|
|
2208
|
+
if (!asset || !sha256 || !url)
|
|
2209
|
+
throw new Error("codex-acp: no checked Linux build for this phone");
|
|
2210
|
+
if (!process.env.HYPEFRAME_CODEX_ACP_RELEASE && !url.startsWith("https://github.com/"))
|
|
2211
|
+
throw new Error("codex-acp: unexpected download address");
|
|
2212
|
+
return { url, sha256: sha256.toLowerCase(), version: String(j.tag_name ?? "latest").replace(/^v/, "") };
|
|
2213
|
+
}
|
|
2214
|
+
var findFile = (dir, name) => {
|
|
2215
|
+
for (const n of fs13.readdirSync(dir)) {
|
|
2216
|
+
const f = path10.join(dir, n);
|
|
2217
|
+
const st = fs13.lstatSync(f);
|
|
2218
|
+
if (st.isFile() && n === name)
|
|
2219
|
+
return f;
|
|
2220
|
+
if (st.isDirectory()) {
|
|
2221
|
+
const inner = findFile(f, name);
|
|
2222
|
+
if (inner)
|
|
2223
|
+
return inner;
|
|
2224
|
+
}
|
|
2225
|
+
}
|
|
2226
|
+
return null;
|
|
2227
|
+
};
|
|
2228
|
+
async function installInLinux(a, id, progress, steps, arch) {
|
|
2229
|
+
steps.prepare();
|
|
2230
|
+
if (id === "antigravity-acp") {
|
|
2231
|
+
if (!steps.run("(test -x /root/.local/bin/agy || curl -fsSL https://antigravity.google/cli/install.sh | bash) && test -x /root/.local/bin/agy"))
|
|
2232
|
+
throw new Error("Antigravity: Google's installer did not finish in the Linux mini, or agy is not at /root/.local/bin/agy");
|
|
2233
|
+
return { launch: { cmd: "/root/.local/bin/agy", args: ["acp"], env: {}, linux: true }, version: a.version };
|
|
2234
|
+
}
|
|
2235
|
+
if (id === "codex-acp") {
|
|
2236
|
+
const b = await codexAcpBuild(arch);
|
|
2237
|
+
const dir = path10.join(agentDir(), id, b.version);
|
|
2238
|
+
const tmp = `${dir}.tmp`;
|
|
2239
|
+
await fsp2.rm(tmp, { recursive: true, force: true });
|
|
2240
|
+
await fsp2.mkdir(tmp, { recursive: true });
|
|
2241
|
+
try {
|
|
2242
|
+
const file = path10.join(tmp, ".download.tar.gz");
|
|
2243
|
+
await downloadVerified(b.url, b.sha256, file, progress);
|
|
2244
|
+
await untarGz(file, tmp);
|
|
2245
|
+
await fsp2.rm(file, { force: true });
|
|
2246
|
+
const found = findFile(tmp, "codex-acp");
|
|
2247
|
+
if (!found)
|
|
2248
|
+
throw new Error("codex-acp: the program is not in the download");
|
|
2249
|
+
const rel = path10.relative(tmp, found);
|
|
2250
|
+
await fsp2.chmod(found, 493);
|
|
2251
|
+
await fsp2.rm(dir, { recursive: true, force: true });
|
|
2252
|
+
await fsp2.rename(tmp, dir);
|
|
2253
|
+
return { launch: { cmd: path10.join(dir, rel), args: [], env: {}, linux: true }, version: b.version };
|
|
2254
|
+
} catch (e) {
|
|
2255
|
+
await fsp2.rm(tmp, { recursive: true, force: true });
|
|
2256
|
+
throw e;
|
|
2257
|
+
}
|
|
2258
|
+
}
|
|
2259
|
+
const bin = a.distribution.binary?.[`linux-${arch === "x64" ? "x86_64" : "aarch64"}`];
|
|
2260
|
+
if (!bin)
|
|
2261
|
+
throw new Error(`Agent ${id} has no Linux build to run on this phone`);
|
|
2262
|
+
return { launch: { ...await unpackBinary(id, a.version, bin, progress), linux: true }, version: a.version };
|
|
2263
|
+
}
|
|
2264
|
+
async function installAgent(id, progress = () => {
|
|
2265
|
+
return;
|
|
2266
|
+
}, opts = {}) {
|
|
2267
|
+
const a = (await fetchRegistry()).find((x) => x.id === id);
|
|
2268
|
+
if (!a)
|
|
2269
|
+
throw new Error(`Agent ${id} is not in the registry`);
|
|
2270
|
+
const local = a.distribution.local;
|
|
2271
|
+
if (!isSupported(id) && !local)
|
|
2272
|
+
throw new Error(`Agent ${id} is not supported`);
|
|
2273
|
+
if (!local && (opts.android ?? isAndroid())) {
|
|
2274
|
+
const steps = opts.linux ?? { prepare: () => prepareLinux(opts.say), run: runInLinux };
|
|
2275
|
+
const r = await installInLinux(a, id, progress, steps, opts.arch ?? process.arch);
|
|
2276
|
+
const installed = { id, name: a.name, version: r.version, launch: r.launch };
|
|
2277
|
+
writeInstalled(installed);
|
|
2278
|
+
return installed;
|
|
2279
|
+
}
|
|
2280
|
+
let launch;
|
|
2281
|
+
const bin = a.distribution.binary?.[platformKey()];
|
|
2282
|
+
const own = local || opts.download ? null : ownCopy(a);
|
|
2283
|
+
if (local) {
|
|
2284
|
+
launch = { cmd: local.cmd, args: local.args ?? [], env: {} };
|
|
2285
|
+
} else if (own) {
|
|
2286
|
+
launch = own;
|
|
2287
|
+
} else if (bin) {
|
|
2288
|
+
launch = await unpackBinary(id, a.version, bin, progress);
|
|
2289
|
+
} else if (a.distribution.npx) {
|
|
2290
|
+
launch = { ...npxRunner(a.distribution.npx.package, a.distribution.npx.args), env: { ...a.distribution.npx.env ?? {} } };
|
|
2291
|
+
if (isStandalone())
|
|
2292
|
+
launch.env.BUN_BE_BUN = "1";
|
|
2293
|
+
} else
|
|
2294
|
+
throw new Error(`Agent ${id} has no download for ${platformKey()}`);
|
|
2295
|
+
const installed = { id, name: a.name, version: a.version, launch, ...own ? { own: true } : {} };
|
|
2296
|
+
writeInstalled(installed);
|
|
2297
|
+
return installed;
|
|
2298
|
+
}
|
|
2299
|
+
|
|
2300
|
+
// packages/hypeframe/src/agent/terminal.ts
|
|
2301
|
+
var MAX_TERMINALS = 4;
|
|
2302
|
+
var KEEP = 160 * 1024;
|
|
2303
|
+
var PIECE = 60 * 1024;
|
|
2304
|
+
var GAP_MS = 25;
|
|
2305
|
+
var IDLE_MS = 15 * 60000;
|
|
2306
|
+
var MAX_INPUT = 64 * 1024;
|
|
2307
|
+
var bun = () => globalThis.Bun?.spawn ? globalThis.Bun : null;
|
|
2308
|
+
function ptySupported() {
|
|
2309
|
+
return !!bun() || isAndroid() || process.platform === "linux" && !!onPath("script");
|
|
2310
|
+
}
|
|
2311
|
+
function agyOnComputer() {
|
|
2312
|
+
const own = onPath("agy");
|
|
2313
|
+
if (own)
|
|
2314
|
+
return own;
|
|
2315
|
+
const f = path11.join(os3.homedir(), ".local", "bin", process.platform === "win32" ? "agy.exe" : "agy");
|
|
2316
|
+
return fs14.existsSync(f) ? f : null;
|
|
2317
|
+
}
|
|
2318
|
+
function hasTerminal(a) {
|
|
2319
|
+
if (!ptySupported())
|
|
2320
|
+
return false;
|
|
2321
|
+
if (a.id === "antigravity-acp")
|
|
2322
|
+
return !!a.launch.linux || !!agyOnComputer();
|
|
2323
|
+
return true;
|
|
2324
|
+
}
|
|
2325
|
+
var codexRelease = () => process.env.HYPEFRAME_CODEX_RELEASE || "https://api.github.com/repos/openai/codex/releases/latest";
|
|
2326
|
+
function codexTriple(linux) {
|
|
2327
|
+
const arch = process.arch === "arm64" ? "aarch64" : "x86_64";
|
|
2328
|
+
if (linux || isAndroid() || process.platform === "linux")
|
|
2329
|
+
return `${arch}-unknown-linux-musl`;
|
|
2330
|
+
if (process.platform === "darwin")
|
|
2331
|
+
return `${arch}-apple-darwin`;
|
|
2332
|
+
if (process.platform === "win32")
|
|
2333
|
+
return `${arch}-pc-windows-msvc.exe`;
|
|
2334
|
+
throw new Error(`Codex CLI tidak tersedia untuk ${process.platform}.`);
|
|
2335
|
+
}
|
|
2336
|
+
async function untar(file, to) {
|
|
2337
|
+
const r = spawnSync3("tar", ["-xzf", file, "-C", to], { stdio: "ignore", windowsHide: true, timeout: 10 * 60000 });
|
|
2338
|
+
if (r.status === 0)
|
|
2339
|
+
return;
|
|
2340
|
+
await untarGz(file, to);
|
|
2341
|
+
}
|
|
2342
|
+
async function codexCli(linux, say) {
|
|
2343
|
+
if (!linux) {
|
|
2344
|
+
const own = onPath("codex");
|
|
2345
|
+
if (own)
|
|
2346
|
+
return own;
|
|
2347
|
+
}
|
|
2348
|
+
const triple = codexTriple(linux);
|
|
2349
|
+
const base = path11.join(agentDir(), "codex-acp", "cli");
|
|
2350
|
+
const mark = path11.join(base, `${triple}.json`);
|
|
2351
|
+
try {
|
|
2352
|
+
const saved = JSON.parse(fs14.readFileSync(mark, "utf8"));
|
|
2353
|
+
if (saved.cmd && fs14.existsSync(saved.cmd))
|
|
2354
|
+
return saved.cmd;
|
|
2355
|
+
} catch {}
|
|
2356
|
+
const j = await (await fetch(codexRelease(), { headers: { accept: "application/vnd.github+json", "user-agent": "hypeframe" }, signal: AbortSignal.timeout(20000) })).json();
|
|
2357
|
+
const asset = (j.assets ?? []).find((x) => x.name === `codex-${triple}.tar.gz`);
|
|
2358
|
+
const sha256 = /^sha256:([0-9a-f]{64})$/i.exec(String(asset?.digest ?? ""))?.[1]?.toLowerCase();
|
|
2359
|
+
const url = String(asset?.browser_download_url ?? "");
|
|
2360
|
+
if (!asset || !sha256 || !url)
|
|
2361
|
+
throw new Error("Codex CLI: tidak ada unduhan resmi yang bisa diperiksa untuk perangkat ini.");
|
|
2362
|
+
if (!process.env.HYPEFRAME_CODEX_RELEASE && !url.startsWith("https://github.com/"))
|
|
2363
|
+
throw new Error("Codex CLI: alamat unduhan tidak dikenal.");
|
|
2364
|
+
const version = String(j.tag_name ?? "latest").replace(/^rust-v|^v/, "");
|
|
2365
|
+
const mb = asset.size ? ` (${Math.round(asset.size / 1048576)} MB)` : "";
|
|
2366
|
+
say(`Mengunduh Codex CLI ${version}${mb}, sekali saja...`);
|
|
2367
|
+
const dir = path11.join(base, `${triple}-${version}`);
|
|
2368
|
+
const tmp = `${dir}.tmp`;
|
|
2369
|
+
await fsp3.rm(tmp, { recursive: true, force: true });
|
|
2370
|
+
await fsp3.mkdir(tmp, { recursive: true });
|
|
2371
|
+
try {
|
|
2372
|
+
const file = path11.join(tmp, ".unduh.tar.gz");
|
|
2373
|
+
await downloadVerified(url, sha256, file, (p) => say(`Codex CLI ${p}%`));
|
|
2374
|
+
say("Membuka unduhan...");
|
|
2375
|
+
await untar(file, tmp);
|
|
2376
|
+
await fsp3.rm(file, { force: true });
|
|
2377
|
+
const found = fs14.readdirSync(tmp).find((n) => /^codex/.test(n) && !/\.(tar\.gz|zip|zst)$/.test(n));
|
|
2378
|
+
if (!found)
|
|
2379
|
+
throw new Error("Codex CLI: programnya tidak ada di unduhan.");
|
|
2380
|
+
if (process.platform !== "win32")
|
|
2381
|
+
await fsp3.chmod(path11.join(tmp, found), 493);
|
|
2382
|
+
await fsp3.rm(dir, { recursive: true, force: true });
|
|
2383
|
+
await fsp3.rename(tmp, dir);
|
|
2384
|
+
const cmd = path11.join(dir, found);
|
|
2385
|
+
fs14.writeFileSync(mark, JSON.stringify({ cmd, version }));
|
|
2386
|
+
return cmd;
|
|
2387
|
+
} catch (e) {
|
|
2388
|
+
await fsp3.rm(tmp, { recursive: true, force: true });
|
|
2389
|
+
throw e;
|
|
2390
|
+
}
|
|
2391
|
+
}
|
|
2392
|
+
var envOf = (m) => Object.fromEntries((m?.env ?? []).map((e) => [e.name, e.value]));
|
|
2393
|
+
var tomlTable = (o) => `{${Object.entries(o).map(([k, v]) => `${/^[A-Za-z0-9_-]+$/.test(k) ? k : JSON.stringify(k)} = ${JSON.stringify(v)}`).join(", ")}}`;
|
|
2394
|
+
var codexMcpArgs = (mcp) => ["-c", `mcp_servers.hypeframe.command=${JSON.stringify(mcp.command)}`, "-c", `mcp_servers.hypeframe.args=${JSON.stringify(mcp.args)}`, "-c", `mcp_servers.hypeframe.env=${tomlTable(envOf(mcp))}`];
|
|
2395
|
+
async function tuiSpec(a, mcp, say) {
|
|
2396
|
+
const linux = !!a.launch.linux;
|
|
2397
|
+
const env = { ...a.launch.env, ...agentEnv(a.id), TERM: "xterm-256color", COLORTERM: "truecolor" };
|
|
2398
|
+
const tools = envOf(mcp);
|
|
2399
|
+
if (a.id === "opencode") {
|
|
2400
|
+
if (mcp)
|
|
2401
|
+
env.OPENCODE_CONFIG_CONTENT = JSON.stringify({ mcp: { hypeframe: { type: "local", command: [mcp.command, ...mcp.args], environment: tools, enabled: true } } });
|
|
2402
|
+
return { cmd: a.launch.cmd, args: a.launch.args.filter((x) => x !== "acp"), env, linux };
|
|
2403
|
+
}
|
|
2404
|
+
if (a.id === "codex-acp") {
|
|
2405
|
+
delete env.BUN_BE_BUN;
|
|
2406
|
+
const cmd = await codexCli(linux, say);
|
|
2407
|
+
return { cmd, args: mcp ? codexMcpArgs(mcp) : [], env, linux };
|
|
2408
|
+
}
|
|
2409
|
+
if (a.id === "antigravity-acp") {
|
|
2410
|
+
if (linux)
|
|
2411
|
+
return { cmd: "/root/.local/bin/agy", args: [], env, linux };
|
|
2412
|
+
const agy = agyOnComputer();
|
|
2413
|
+
if (!agy)
|
|
2414
|
+
throw new Error("Antigravity CLI (agy) belum ada di komputer ini. Pasang dari antigravity.google/cli, lalu buka terminal ini lagi.");
|
|
2415
|
+
return { cmd: agy, args: [], env, linux };
|
|
2416
|
+
}
|
|
2417
|
+
return { cmd: a.launch.cmd, args: a.launch.args, env: { ...env, ...tools, HYPEFRAME_TUI: "1" }, linux };
|
|
2418
|
+
}
|
|
2419
|
+
function killTree(pid) {
|
|
2420
|
+
if (!pid)
|
|
2421
|
+
return;
|
|
2422
|
+
if (process.platform === "win32") {
|
|
2423
|
+
const k = spawn3("taskkill", ["/pid", String(pid), "/T", "/F"], { windowsHide: true, stdio: "ignore" });
|
|
2424
|
+
k.on("error", () => {
|
|
2425
|
+
return;
|
|
2426
|
+
});
|
|
2427
|
+
return;
|
|
2428
|
+
}
|
|
2429
|
+
try {
|
|
2430
|
+
process.kill(pid, "SIGTERM");
|
|
2431
|
+
} catch {}
|
|
2432
|
+
}
|
|
2433
|
+
function scriptInner(spec, cwd, cols, rows, sizeFile) {
|
|
2434
|
+
const loop = `(while kill -0 $$ 2>/dev/null; do if [ -s ${shQuote(sizeFile)} ]; then read r c < ${shQuote(sizeFile)}; : > ${shQuote(sizeFile)}; stty rows "$r" cols "$c" < /dev/tty 2>/dev/null; fi; sleep 0.3; done) >/dev/null 2>&1 &`;
|
|
2435
|
+
return `cd ${shQuote(cwd)} 2>/dev/null; stty rows ${rows} cols ${cols} 2>/dev/null; ${loop} exec ${[spec.cmd, ...spec.args].map(shQuote).join(" ")}`;
|
|
2436
|
+
}
|
|
2437
|
+
function startPty(spec, cwd, cols, rows, sizeFile, onData, onExit) {
|
|
2438
|
+
const dec = new TextDecoder;
|
|
2439
|
+
const b = bun();
|
|
2440
|
+
if (!spec.linux && b) {
|
|
2441
|
+
let ended = false;
|
|
2442
|
+
const p = b.spawn([spec.cmd, ...spec.args], {
|
|
2443
|
+
cwd,
|
|
2444
|
+
env: { ...process.env, ...spec.env },
|
|
2445
|
+
terminal: { cols, rows, data: (_t, d) => onData(dec.decode(d, { stream: true })) }
|
|
2446
|
+
});
|
|
2447
|
+
p.exited.then((code) => (ended = true, onExit(code)), () => (ended = true, onExit(null)));
|
|
2448
|
+
return {
|
|
2449
|
+
write: (s) => !ended && p.terminal?.write(s),
|
|
2450
|
+
resize: (c, r) => !ended && p.terminal?.resize(c, r),
|
|
2451
|
+
kill: () => {
|
|
2452
|
+
killTree(p.pid);
|
|
2453
|
+
try {
|
|
2454
|
+
p.kill();
|
|
2455
|
+
p.terminal?.close();
|
|
2456
|
+
} catch {}
|
|
2457
|
+
}
|
|
2458
|
+
};
|
|
2459
|
+
}
|
|
2460
|
+
let child;
|
|
2461
|
+
const inner = scriptInner(spec, cwd, cols, rows, sizeFile);
|
|
2462
|
+
if (spec.linux) {
|
|
2463
|
+
const [cmd, args] = linuxCommand("/usr/bin/script", ["-qfec", inner, "/dev/null"], spec.env);
|
|
2464
|
+
child = spawn3(cmd, args, { stdio: ["pipe", "pipe", "pipe"], env: { ...process.env } });
|
|
2465
|
+
} else if (process.platform === "linux" && onPath("script")) {
|
|
2466
|
+
child = spawn3("script", ["-qfec", inner, "/dev/null"], { cwd, stdio: ["pipe", "pipe", "pipe"], env: { ...process.env, ...spec.env } });
|
|
2467
|
+
} else
|
|
2468
|
+
throw new Error("Terminal penuh butuh mesin dari pemasang HypeFrame (bukan npm) di komputer ini. Jalankan: hypeframe update");
|
|
2469
|
+
child.stdout?.on("data", (d) => onData(dec.decode(d, { stream: true })));
|
|
2470
|
+
child.stderr?.on("data", (d) => onData(dec.decode(d, { stream: true })));
|
|
2471
|
+
child.stdin?.on("error", () => {
|
|
2472
|
+
return;
|
|
2473
|
+
});
|
|
2474
|
+
let ended = false;
|
|
2475
|
+
child.on("error", () => (ended = true, onExit(null)));
|
|
2476
|
+
child.on("exit", (code) => (ended = true, onExit(code)));
|
|
2477
|
+
return {
|
|
2478
|
+
write: (s) => !ended && child.stdin?.write(s),
|
|
2479
|
+
resize: (c, r) => {
|
|
2480
|
+
try {
|
|
2481
|
+
fs14.writeFileSync(sizeFile, `${r} ${c}
|
|
2482
|
+
`);
|
|
2483
|
+
} catch {}
|
|
2484
|
+
},
|
|
2485
|
+
kill: () => killTree(child.pid)
|
|
2486
|
+
};
|
|
2487
|
+
}
|
|
2488
|
+
var clampInt = (v, lo, hi, d) => {
|
|
2489
|
+
const n = Math.round(Number(v));
|
|
2490
|
+
return Number.isFinite(n) ? Math.min(hi, Math.max(lo, n)) : d;
|
|
2491
|
+
};
|
|
2492
|
+
var cutAt = (s, n) => s.length <= n ? s.length : /[\uD800-\uDBFF]/.test(s[n - 1]) ? n - 1 : n;
|
|
2493
|
+
function createTerminals(h) {
|
|
2494
|
+
const list = new Map;
|
|
2495
|
+
let lastSend = 0;
|
|
2496
|
+
const str = (c, k) => typeof c[k] === "string" ? c[k] : "";
|
|
2497
|
+
function flush(t) {
|
|
2498
|
+
t.timer = null;
|
|
2499
|
+
if (!t.pend)
|
|
2500
|
+
return;
|
|
2501
|
+
const wait = lastSend + GAP_MS - Date.now();
|
|
2502
|
+
if (wait > 0)
|
|
2503
|
+
return void (t.timer = setTimeout(() => flush(t), wait));
|
|
2504
|
+
const n = cutAt(t.pend, PIECE);
|
|
2505
|
+
const data = t.pend.slice(0, n);
|
|
2506
|
+
t.pend = t.pend.slice(n);
|
|
2507
|
+
lastSend = Date.now();
|
|
2508
|
+
h.conn.tty(t.dari, { id: t.id, data });
|
|
2509
|
+
if (t.pend)
|
|
2510
|
+
t.timer = setTimeout(() => flush(t), GAP_MS);
|
|
2511
|
+
}
|
|
2512
|
+
function out(t, s) {
|
|
2513
|
+
if (!s || t.ended)
|
|
2514
|
+
return;
|
|
2515
|
+
t.keep = (t.keep + s).slice(-KEEP);
|
|
2516
|
+
t.pend = (t.pend + s).slice(-4 * KEEP);
|
|
2517
|
+
if (!t.timer)
|
|
2518
|
+
t.timer = setTimeout(() => flush(t), t.pend.length >= PIECE ? 0 : 12);
|
|
2519
|
+
}
|
|
2520
|
+
const note = (t, s) => out(t, `\x1B[2m${s}\x1B[0m\r
|
|
2521
|
+
`);
|
|
2522
|
+
function end(t, code) {
|
|
2523
|
+
if (t.ended)
|
|
2524
|
+
return;
|
|
2525
|
+
t.ended = true;
|
|
2526
|
+
if (t.timer)
|
|
2527
|
+
clearTimeout(t.timer);
|
|
2528
|
+
while (t.pend) {
|
|
2529
|
+
const n = cutAt(t.pend, PIECE);
|
|
2530
|
+
h.conn.tty(t.dari, { id: t.id, data: t.pend.slice(0, n) });
|
|
2531
|
+
t.pend = t.pend.slice(n);
|
|
2532
|
+
}
|
|
2533
|
+
h.conn.tty(t.dari, { id: t.id, selesai: code });
|
|
2534
|
+
list.delete(t.id);
|
|
2535
|
+
h.dropRoute(t.routeId);
|
|
2536
|
+
fs14.rmSync(t.sizeFile, { force: true });
|
|
2537
|
+
h.onEvent?.({ type: "closed", agent: t.name, code });
|
|
2538
|
+
}
|
|
2539
|
+
async function launch(t, a, mcp) {
|
|
2540
|
+
try {
|
|
2541
|
+
const spec = await tuiSpec(a, mcp, (s) => note(t, s));
|
|
2542
|
+
if (t.ended)
|
|
2543
|
+
return;
|
|
2544
|
+
t.pty = startPty(spec, projectDir(t.projectId), t.cols, t.rows, t.sizeFile, (s) => out(t, s), (code) => end(t, code));
|
|
2545
|
+
h.onEvent?.({ type: "open", agent: t.name });
|
|
2546
|
+
} catch (e) {
|
|
2547
|
+
note(t, `${e.message}`.slice(0, 400));
|
|
2548
|
+
end(t, null);
|
|
2549
|
+
}
|
|
2550
|
+
}
|
|
2551
|
+
const work = {
|
|
2552
|
+
"terminal.buka": async (c) => {
|
|
2553
|
+
const agentId = str(c, "agentId");
|
|
2554
|
+
const projectId = str(c, "projectId");
|
|
2555
|
+
if (!/^[A-Za-z0-9_-]{1,80}$/.test(projectId))
|
|
2556
|
+
throw new Error("Buka project dulu.");
|
|
2557
|
+
const a = h.agent(agentId);
|
|
2558
|
+
if (!a)
|
|
2559
|
+
throw new Error("Agen belum dipasang di mesin ini.");
|
|
2560
|
+
if (!ptySupported())
|
|
2561
|
+
throw new Error("Terminal penuh butuh mesin dari pemasang HypeFrame (bukan npm) di komputer ini. Jalankan: hypeframe update");
|
|
2562
|
+
if (!hasTerminal(a))
|
|
2563
|
+
throw new Error(`${a.name} belum punya program terminal di komputer ini.`);
|
|
2564
|
+
const dari = str(c, "dari");
|
|
2565
|
+
const tab = str(c, "tab");
|
|
2566
|
+
const alat = Array.isArray(c.alat) ? c.alat : undefined;
|
|
2567
|
+
const cols = clampInt(c.cols, 20, 400, 100);
|
|
2568
|
+
const rows = clampInt(c.rows, 5, 200, 30);
|
|
2569
|
+
const old = [...list.values()].find((x) => x.agentId === agentId && x.projectId === projectId && !x.ended);
|
|
2570
|
+
if (old) {
|
|
2571
|
+
old.dari = dari;
|
|
2572
|
+
old.tab = tab;
|
|
2573
|
+
old.seen = Date.now();
|
|
2574
|
+
h.moveRoute(old.routeId, dari, tab, alat);
|
|
2575
|
+
const ulang = old.keep;
|
|
2576
|
+
old.pend = "";
|
|
2577
|
+
if (old.pty) {
|
|
2578
|
+
old.pty.resize(cols, Math.max(5, rows - 1));
|
|
2579
|
+
setTimeout(() => (old.pty?.resize(cols, rows), old.cols = cols, old.rows = rows), 60);
|
|
2580
|
+
}
|
|
2581
|
+
return { terminal: old.id, nama: old.name, ulang, lama: true };
|
|
2582
|
+
}
|
|
2583
|
+
if (list.size >= MAX_TERMINALS)
|
|
2584
|
+
throw new Error(`Sudah ada ${MAX_TERMINALS} terminal terbuka di mesin ini. Tutup salah satu dulu.`);
|
|
2585
|
+
const id = `t${crypto4.randomBytes(8).toString("hex")}`;
|
|
2586
|
+
const r = h.openRoute({ dari, tab, alat: alat ?? [], projectId, agentId });
|
|
2587
|
+
const ttyDir = path11.join(dataDir(), "tty");
|
|
2588
|
+
fs14.mkdirSync(ttyDir, { recursive: true, mode: 448 });
|
|
2589
|
+
const t = { id, agentId, projectId, name: a.name, dari, tab, routeId: r.routeId, cols, rows, keep: "", pend: "", timer: null, seen: Date.now(), pty: null, ended: false, sizeFile: path11.join(ttyDir, id) };
|
|
2590
|
+
list.set(id, t);
|
|
2591
|
+
launch(t, a, r.mcp);
|
|
2592
|
+
return { terminal: id, nama: a.name, ulang: "", lama: false };
|
|
2593
|
+
},
|
|
2594
|
+
"terminal.tutup": async (c) => {
|
|
2595
|
+
const t = list.get(str(c, "terminal"));
|
|
2596
|
+
if (t)
|
|
2597
|
+
t.pty ? t.pty.kill() : end(t, null);
|
|
2598
|
+
return {};
|
|
2599
|
+
}
|
|
2600
|
+
};
|
|
2601
|
+
function input(dari, m) {
|
|
2602
|
+
const t = list.get(String(m.id ?? ""));
|
|
2603
|
+
if (!t || t.ended || t.dari !== dari)
|
|
2604
|
+
return;
|
|
2605
|
+
t.seen = Date.now();
|
|
2606
|
+
if (typeof m.data === "string" && m.data && m.data.length <= MAX_INPUT)
|
|
2607
|
+
t.pty?.write(m.data);
|
|
2608
|
+
if (Array.isArray(m.ukuran) && m.ukuran.length === 2) {
|
|
2609
|
+
const cols = clampInt(m.ukuran[0], 20, 400, t.cols);
|
|
2610
|
+
const rows = clampInt(m.ukuran[1], 5, 200, t.rows);
|
|
2611
|
+
if (cols !== t.cols || rows !== t.rows)
|
|
2612
|
+
t.cols = cols, t.rows = rows, t.pty?.resize(cols, rows);
|
|
2613
|
+
}
|
|
2614
|
+
}
|
|
2615
|
+
const sweep = setInterval(() => {
|
|
2616
|
+
for (const t of list.values())
|
|
2617
|
+
if (Date.now() - t.seen > IDLE_MS)
|
|
2618
|
+
note(t, "Ditutup karena 15 menit tidak dibuka."), t.pty ? t.pty.kill() : end(t, null);
|
|
2619
|
+
}, 60000);
|
|
2620
|
+
sweep.unref();
|
|
2621
|
+
return {
|
|
2622
|
+
work,
|
|
2623
|
+
input,
|
|
2624
|
+
count: () => list.size,
|
|
2625
|
+
stopAll: () => {
|
|
2626
|
+
clearInterval(sweep);
|
|
2627
|
+
for (const t of list.values())
|
|
2628
|
+
t.pty?.kill();
|
|
2629
|
+
list.clear();
|
|
2630
|
+
}
|
|
2631
|
+
};
|
|
2632
|
+
}
|
|
2633
|
+
|
|
1945
2634
|
// packages/hypeframe/src/agent/service.ts
|
|
1946
2635
|
var hostOf = (u) => {
|
|
1947
2636
|
try {
|
|
@@ -1962,7 +2651,7 @@ var ERRORS = {
|
|
|
1962
2651
|
var MAX_HISTORY = 2 * 1024 * 1024;
|
|
1963
2652
|
var HISTORY_ANSWER = 170 * 1024;
|
|
1964
2653
|
var MAX_FILE2 = 4 * 1024 * 1024;
|
|
1965
|
-
var
|
|
2654
|
+
var PIECE2 = 150 * 1024;
|
|
1966
2655
|
var MEDIA = {
|
|
1967
2656
|
png: "image/png",
|
|
1968
2657
|
jpg: "image/jpeg",
|
|
@@ -2063,28 +2752,28 @@ function mcpServerFor(agent, url, key, bridge) {
|
|
|
2063
2752
|
return { name: "hypeframe", command: bridge.command, args: bridge.args, env: [...bridge.env, ...env] };
|
|
2064
2753
|
}
|
|
2065
2754
|
function historyFile(projectId, sessionId) {
|
|
2066
|
-
return
|
|
2755
|
+
return path12.join(projectDir(projectId), "riwayat", `${crypto5.createHash("sha256").update(sessionId).digest("hex").slice(0, 32)}.jsonl`);
|
|
2067
2756
|
}
|
|
2068
2757
|
function record(file, updates) {
|
|
2069
2758
|
if (!updates.length)
|
|
2070
2759
|
return;
|
|
2071
2760
|
try {
|
|
2072
|
-
|
|
2073
|
-
|
|
2761
|
+
fs15.mkdirSync(path12.dirname(file), { recursive: true });
|
|
2762
|
+
fs15.appendFileSync(file, `${updates.map((u) => JSON.stringify(u)).join(`
|
|
2074
2763
|
`)}
|
|
2075
2764
|
`);
|
|
2076
|
-
if (
|
|
2077
|
-
const text =
|
|
2765
|
+
if (fs15.statSync(file).size > MAX_HISTORY) {
|
|
2766
|
+
const text = fs15.readFileSync(file, "utf8");
|
|
2078
2767
|
const from = text.indexOf(`
|
|
2079
2768
|
`, text.length - MAX_HISTORY / 2);
|
|
2080
|
-
|
|
2769
|
+
fs15.writeFileSync(file, from >= 0 ? text.slice(from + 1) : "");
|
|
2081
2770
|
}
|
|
2082
2771
|
} catch {}
|
|
2083
2772
|
}
|
|
2084
2773
|
function readHistory(file) {
|
|
2085
2774
|
let text = "";
|
|
2086
2775
|
try {
|
|
2087
|
-
text =
|
|
2776
|
+
text = fs15.readFileSync(file, "utf8");
|
|
2088
2777
|
} catch {
|
|
2089
2778
|
return { update: [], potong: false };
|
|
2090
2779
|
}
|
|
@@ -2103,7 +2792,7 @@ function readHistory(file) {
|
|
|
2103
2792
|
return { update: out.reverse(), potong: false };
|
|
2104
2793
|
}
|
|
2105
2794
|
function createAgentService(o) {
|
|
2106
|
-
const key =
|
|
2795
|
+
const key = crypto5.randomBytes(24).toString("base64url");
|
|
2107
2796
|
const routes = new Map;
|
|
2108
2797
|
const sessionRoute = new Map;
|
|
2109
2798
|
const permissions = new Map;
|
|
@@ -2161,7 +2850,7 @@ function createAgentService(o) {
|
|
|
2161
2850
|
record(file, packUpdates(list).flat());
|
|
2162
2851
|
},
|
|
2163
2852
|
onPermission: (sessionId, req, info) => new Promise((ok) => {
|
|
2164
|
-
const id = `i${
|
|
2853
|
+
const id = `i${crypto5.randomBytes(6).toString("hex")}`;
|
|
2165
2854
|
const done = (v) => (permissions.delete(id), asked.delete(id), ok(v));
|
|
2166
2855
|
permissions.set(id, done);
|
|
2167
2856
|
const agent = nameOf(sessions.agentOf(sessionId));
|
|
@@ -2179,7 +2868,26 @@ function createAgentService(o) {
|
|
|
2179
2868
|
flushMs: o.flushMs ?? 100
|
|
2180
2869
|
});
|
|
2181
2870
|
const text = (c, k) => typeof c[k] === "string" ? c[k] : "";
|
|
2871
|
+
const terminals = createTerminals({
|
|
2872
|
+
conn: { tty: (ke, b) => o.conn.tty?.(ke, b) },
|
|
2873
|
+
agent: (id) => readInstalled().find((a) => a.id === id),
|
|
2874
|
+
openRoute: (r) => {
|
|
2875
|
+
const routeId = `t${crypto5.randomBytes(12).toString("base64url")}`;
|
|
2876
|
+
routes.set(routeId, { ...r });
|
|
2877
|
+
const agent = readInstalled().find((a) => a.id === r.agentId);
|
|
2878
|
+
return { routeId, mcp: mcpServerFor(agent, `http://127.0.0.1:${o.port()}/agen/mcp/${r.projectId}/${routeId}`, key, o.bridge) };
|
|
2879
|
+
},
|
|
2880
|
+
moveRoute: (id, dari, tab, alat) => {
|
|
2881
|
+
const r = routes.get(id);
|
|
2882
|
+
if (r)
|
|
2883
|
+
r.dari = dari, r.tab = tab || r.tab, alat && (r.alat = alat);
|
|
2884
|
+
},
|
|
2885
|
+
dropRoute: (id) => void routes.delete(id),
|
|
2886
|
+
onEvent: (e) => emit(e.type === "open" ? { type: "terminal", agent: e.agent } : { type: "terminalClosed", agent: e.agent, code: e.code ?? null })
|
|
2887
|
+
});
|
|
2182
2888
|
const work = {
|
|
2889
|
+
"terminal.buka": (c) => terminals.work["terminal.buka"](c),
|
|
2890
|
+
"terminal.tutup": (c) => terminals.work["terminal.tutup"](c),
|
|
2183
2891
|
"agen.mulai": async (c) => {
|
|
2184
2892
|
const agentId = text(c, "agentId");
|
|
2185
2893
|
const projectId = text(c, "projectId");
|
|
@@ -2317,22 +3025,22 @@ function createAgentService(o) {
|
|
|
2317
3025
|
const folder = projectDir(projectId);
|
|
2318
3026
|
if (!p || !insideFolder(folder, p))
|
|
2319
3027
|
return fail(`Only files inside the HypeFrame project folder (${folder}) can be added.`);
|
|
2320
|
-
const file =
|
|
2321
|
-
const st =
|
|
3028
|
+
const file = path12.resolve(folder, p);
|
|
3029
|
+
const st = fs15.statSync(file, { throwIfNoEntry: false });
|
|
2322
3030
|
if (!st?.isFile())
|
|
2323
3031
|
return fail(`${p} is not a file in the project folder.`);
|
|
2324
|
-
const nama =
|
|
2325
|
-
const mime = MEDIA[
|
|
3032
|
+
const nama = path12.basename(file).slice(0, 120);
|
|
3033
|
+
const mime = MEDIA[path12.extname(file).slice(1).toLowerCase()];
|
|
2326
3034
|
if (!mime)
|
|
2327
3035
|
return fail(`${nama}: only images, audio, video, fonts and Lottie/JSON files can be added to a HypeFrame project.`);
|
|
2328
3036
|
if (st.size > MAX_FILE2)
|
|
2329
3037
|
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.`);
|
|
2330
|
-
const data =
|
|
2331
|
-
const n = Math.max(1, Math.ceil(data.length /
|
|
2332
|
-
const id =
|
|
3038
|
+
const data = fs15.readFileSync(file).toString("base64");
|
|
3039
|
+
const n = Math.max(1, Math.ceil(data.length / PIECE2));
|
|
3040
|
+
const id = crypto5.randomBytes(8).toString("hex");
|
|
2333
3041
|
let last = {};
|
|
2334
3042
|
for (let i = 0;i < n; i++) {
|
|
2335
|
-
last = await o.conn.request(target.dari, "alat", { nama: "_berkas", arg: { id, i, n, nama, mime, ukuran: st.size, data: data.slice(i *
|
|
3043
|
+
last = await o.conn.request(target.dari, "alat", { nama: "_berkas", arg: { id, i, n, nama, mime, ukuran: st.size, data: data.slice(i * PIECE2, (i + 1) * PIECE2) } });
|
|
2336
3044
|
if (last.ok === false) {
|
|
2337
3045
|
const error = String(last.error) in ERRORS ? String(last.error) : "tab";
|
|
2338
3046
|
o.onToolError?.(error);
|
|
@@ -2352,7 +3060,7 @@ function createAgentService(o) {
|
|
|
2352
3060
|
if (!m)
|
|
2353
3061
|
return false;
|
|
2354
3062
|
const auth = String(req.headers.authorization || "").replace(/^Bearer\s+/i, "");
|
|
2355
|
-
if (req.method !== "POST" || auth.length !== key.length || !
|
|
3063
|
+
if (req.method !== "POST" || auth.length !== key.length || !crypto5.timingSafeEqual(Buffer.from(auth), Buffer.from(key)))
|
|
2356
3064
|
return reply(res, 401, { error: "unauthorized" }), true;
|
|
2357
3065
|
let s = "";
|
|
2358
3066
|
for await (const d of req)
|
|
@@ -2401,10 +3109,10 @@ function createAgentService(o) {
|
|
|
2401
3109
|
}
|
|
2402
3110
|
function capabilities() {
|
|
2403
3111
|
const api = opencodeApi();
|
|
2404
|
-
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) } : {} }));
|
|
3112
|
+
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) } : {}, ...hasTerminal(a) ? { terminal: true } : {} }));
|
|
2405
3113
|
}
|
|
2406
3114
|
const stamps = new Map;
|
|
2407
|
-
const stampOf = (id) => [
|
|
3115
|
+
const stampOf = (id) => [path12.join(agentDir(), id, "agent.json"), path12.join(agentDir(), id, "env.json"), ...id === OPENCODE ? [path12.join(dataDir(), "opencode.json")] : []].map((f) => fs15.statSync(f, { throwIfNoEntry: false })?.mtimeMs ?? 0).join(":");
|
|
2408
3116
|
function checkAccounts() {
|
|
2409
3117
|
const running = sessions.running();
|
|
2410
3118
|
const restarted = [];
|
|
@@ -2427,37 +3135,22 @@ function createAgentService(o) {
|
|
|
2427
3135
|
function activity() {
|
|
2428
3136
|
return { chats: sessions.count(), working: sessions.working(), agents: sessions.running().map((id) => nameOf(id)) };
|
|
2429
3137
|
}
|
|
2430
|
-
return {
|
|
3138
|
+
return {
|
|
3139
|
+
work,
|
|
3140
|
+
route,
|
|
3141
|
+
capabilities,
|
|
3142
|
+
checkAccounts,
|
|
3143
|
+
activity,
|
|
3144
|
+
key,
|
|
3145
|
+
tty: terminals.input,
|
|
3146
|
+
stop: () => (stopping = true, clearInterval(ticker), terminals.stopAll(), sessions.stopAll())
|
|
3147
|
+
};
|
|
2431
3148
|
}
|
|
2432
3149
|
|
|
2433
3150
|
// packages/hypeframe/src/agent/mcp-bridge.ts
|
|
2434
|
-
import
|
|
2435
|
-
import
|
|
3151
|
+
import fs16 from "node:fs";
|
|
3152
|
+
import path13 from "node:path";
|
|
2436
3153
|
import readline2 from "node:readline";
|
|
2437
|
-
|
|
2438
|
-
// packages/hypeframe/src/util/runtime.ts
|
|
2439
|
-
import fs12 from "node:fs";
|
|
2440
|
-
import path9 from "node:path";
|
|
2441
|
-
function isStandalone() {
|
|
2442
|
-
return path9.basename(process.execPath).toLowerCase().startsWith("hypeframe");
|
|
2443
|
-
}
|
|
2444
|
-
function runtimeLabel() {
|
|
2445
|
-
const bun = process.versions.bun;
|
|
2446
|
-
return bun && !isStandalone() ? `Bun ${bun}` : isStandalone() ? `Bun ${bun ?? "?"} (standalone)` : `Node ${process.versions.node}`;
|
|
2447
|
-
}
|
|
2448
|
-
function launchCommand() {
|
|
2449
|
-
if (isStandalone())
|
|
2450
|
-
return [process.execPath];
|
|
2451
|
-
try {
|
|
2452
|
-
const script = fs12.realpathSync(process.argv[1] || "");
|
|
2453
|
-
return /[\\/]_npx[\\/]/.test(script) ? null : [process.execPath, script];
|
|
2454
|
-
} catch {
|
|
2455
|
-
return null;
|
|
2456
|
-
}
|
|
2457
|
-
}
|
|
2458
|
-
var INSTALL_URL = "https://hype-frame.com/install";
|
|
2459
|
-
|
|
2460
|
-
// packages/hypeframe/src/agent/mcp-bridge.ts
|
|
2461
3154
|
var BRIDGE_SOURCE = `// HypeFrame MCP bridge (written by hypeframe; do not edit). stdin JSON-RPC lines -> engine -> stdout.
|
|
2462
3155
|
import readline from 'node:readline';
|
|
2463
3156
|
const url = process.env.HF_MCP_URL, key = process.env.HF_MCP_KUNCI;
|
|
@@ -2485,13 +3178,13 @@ rl.on('line', (line) => {
|
|
|
2485
3178
|
rl.on('close', () => Promise.all(busy).then(() => process.exit(0)));
|
|
2486
3179
|
`;
|
|
2487
3180
|
function bridgeLaunch() {
|
|
2488
|
-
const file =
|
|
3181
|
+
const file = path13.join(agentDir(), "mcp-bridge.mjs");
|
|
2489
3182
|
let now = "";
|
|
2490
3183
|
try {
|
|
2491
|
-
now =
|
|
3184
|
+
now = fs16.readFileSync(file, "utf8");
|
|
2492
3185
|
} catch {}
|
|
2493
3186
|
if (now !== BRIDGE_SOURCE)
|
|
2494
|
-
|
|
3187
|
+
fs16.writeFileSync(file, BRIDGE_SOURCE);
|
|
2495
3188
|
return { command: process.execPath, args: [file], env: isStandalone() ? [{ name: "BUN_BE_BUN", value: "1" }] : [] };
|
|
2496
3189
|
}
|
|
2497
3190
|
async function runMcpBridge() {
|
|
@@ -2537,7 +3230,7 @@ async function runMcpBridge() {
|
|
|
2537
3230
|
}
|
|
2538
3231
|
|
|
2539
3232
|
// packages/hypeframe/src/config/lock.ts
|
|
2540
|
-
import
|
|
3233
|
+
import fs17 from "node:fs";
|
|
2541
3234
|
class AlreadyRunning extends Error {
|
|
2542
3235
|
code = "SUDAH_JALAN";
|
|
2543
3236
|
}
|
|
@@ -2551,7 +3244,7 @@ var alive = (pid) => {
|
|
|
2551
3244
|
};
|
|
2552
3245
|
function runningPid() {
|
|
2553
3246
|
try {
|
|
2554
|
-
const pid = Number(
|
|
3247
|
+
const pid = Number(fs17.readFileSync(lockFile(), "utf8"));
|
|
2555
3248
|
return Number.isInteger(pid) && pid > 0 && pid !== process.pid && alive(pid) ? pid : null;
|
|
2556
3249
|
} catch {
|
|
2557
3250
|
return null;
|
|
@@ -2561,13 +3254,13 @@ function singleInstance() {
|
|
|
2561
3254
|
const f = lockFile();
|
|
2562
3255
|
for (let attempt = 0;attempt < 2; attempt++) {
|
|
2563
3256
|
try {
|
|
2564
|
-
const fd =
|
|
2565
|
-
|
|
2566
|
-
|
|
3257
|
+
const fd = fs17.openSync(f, "wx");
|
|
3258
|
+
fs17.writeSync(fd, String(process.pid));
|
|
3259
|
+
fs17.closeSync(fd);
|
|
2567
3260
|
const release = () => {
|
|
2568
3261
|
try {
|
|
2569
|
-
if (
|
|
2570
|
-
|
|
3262
|
+
if (fs17.readFileSync(f, "utf8") === String(process.pid))
|
|
3263
|
+
fs17.rmSync(f, { force: true });
|
|
2571
3264
|
} catch {}
|
|
2572
3265
|
process.off("exit", release);
|
|
2573
3266
|
};
|
|
@@ -2576,17 +3269,17 @@ function singleInstance() {
|
|
|
2576
3269
|
} catch (e) {
|
|
2577
3270
|
if (e.code !== "EEXIST")
|
|
2578
3271
|
throw e;
|
|
2579
|
-
const pid = Number(
|
|
3272
|
+
const pid = Number(fs17.readFileSync(f, "utf8"));
|
|
2580
3273
|
if (Number.isInteger(pid) && pid > 0 && alive(pid))
|
|
2581
3274
|
throw new AlreadyRunning("engine already running");
|
|
2582
|
-
|
|
3275
|
+
fs17.rmSync(f, { force: true });
|
|
2583
3276
|
}
|
|
2584
3277
|
}
|
|
2585
3278
|
throw new AlreadyRunning("engine already running");
|
|
2586
3279
|
}
|
|
2587
3280
|
|
|
2588
3281
|
// packages/hypeframe/src/engine/connection.ts
|
|
2589
|
-
import
|
|
3282
|
+
import crypto6 from "node:crypto";
|
|
2590
3283
|
import { EventEmitter as EventEmitter2 } from "node:events";
|
|
2591
3284
|
import WebSocket from "ws";
|
|
2592
3285
|
var SILENCE_MAX_MS = 70000;
|
|
@@ -2627,12 +3320,15 @@ class Connection extends EventEmitter2 {
|
|
|
2627
3320
|
news(kind, body = {}) {
|
|
2628
3321
|
this.send({ ...body, t: "kabar", jenis: kind });
|
|
2629
3322
|
}
|
|
3323
|
+
tty(ke, body) {
|
|
3324
|
+
this.send({ ...body, t: "tty", ke });
|
|
3325
|
+
}
|
|
2630
3326
|
nextReq = 1;
|
|
2631
3327
|
waiting = new Map;
|
|
2632
3328
|
request(ke, kind, body, timeoutMs = 55000) {
|
|
2633
3329
|
if (!this.connected)
|
|
2634
3330
|
return Promise.resolve({ ok: false, error: "terputus" });
|
|
2635
|
-
const id = `q${this.nextReq++}${
|
|
3331
|
+
const id = `q${this.nextReq++}${crypto6.randomBytes(6).toString("hex")}`;
|
|
2636
3332
|
return new Promise((ok) => {
|
|
2637
3333
|
const timer = setTimeout(() => (this.waiting.delete(id), ok({ ok: false, error: "waktu" })), timeoutMs);
|
|
2638
3334
|
timer.unref?.();
|
|
@@ -2694,6 +3390,8 @@ class Connection extends EventEmitter2 {
|
|
|
2694
3390
|
this.send({ t: "balas", ke: m.dari, id: m.id, ...result });
|
|
2695
3391
|
} else if (m.t === "jawab") {
|
|
2696
3392
|
this.answer(m);
|
|
3393
|
+
} else if (m.t === "tty") {
|
|
3394
|
+
this.emit("tty", m);
|
|
2697
3395
|
}
|
|
2698
3396
|
});
|
|
2699
3397
|
ws.on("error", () => {
|
|
@@ -2815,9 +3513,9 @@ async function pair(o) {
|
|
|
2815
3513
|
}
|
|
2816
3514
|
|
|
2817
3515
|
// packages/hypeframe/src/render/chrome.ts
|
|
2818
|
-
import
|
|
3516
|
+
import fs18 from "node:fs";
|
|
2819
3517
|
import http from "node:http";
|
|
2820
|
-
import
|
|
3518
|
+
import path14 from "node:path";
|
|
2821
3519
|
import { Browser, detectBrowserPlatform, getInstalledBrowsers, install, resolveBuildId } from "@puppeteer/browsers";
|
|
2822
3520
|
import puppeteer from "puppeteer-core";
|
|
2823
3521
|
var ANDROID_ARGS = ["--no-sandbox", "--disable-dev-shm-usage"];
|
|
@@ -2831,11 +3529,11 @@ var ANDROID_FALLBACKS = [
|
|
|
2831
3529
|
{ args: ["--enable-features=NetworkServiceInProcess2"], pipe: false },
|
|
2832
3530
|
{ args: ["--single-process", "--no-zygote"], pipe: false }
|
|
2833
3531
|
];
|
|
2834
|
-
var flagsFile = () =>
|
|
3532
|
+
var flagsFile = () => path14.join(dataDir(), "chrome-flags.json");
|
|
2835
3533
|
var sameCara = (a, b) => a.pipe === b.pipe && a.args.length === b.args.length && a.args.every((x, i) => x === b.args[i]);
|
|
2836
3534
|
function savedCara() {
|
|
2837
3535
|
try {
|
|
2838
|
-
const j = JSON.parse(
|
|
3536
|
+
const j = JSON.parse(fs18.readFileSync(flagsFile(), "utf8"));
|
|
2839
3537
|
const c = { args: Array.isArray(j.args) ? j.args.map(String) : [], pipe: j.pipe === true };
|
|
2840
3538
|
return ANDROID_FALLBACKS.some((f) => sameCara(f, c)) ? c : { args: [], pipe: false };
|
|
2841
3539
|
} catch {
|
|
@@ -2845,9 +3543,9 @@ function savedCara() {
|
|
|
2845
3543
|
function saveCara(c) {
|
|
2846
3544
|
try {
|
|
2847
3545
|
if (c.args.length || c.pipe)
|
|
2848
|
-
|
|
3546
|
+
fs18.writeFileSync(flagsFile(), JSON.stringify(c));
|
|
2849
3547
|
else
|
|
2850
|
-
|
|
3548
|
+
fs18.rmSync(flagsFile(), { force: true });
|
|
2851
3549
|
} catch {}
|
|
2852
3550
|
}
|
|
2853
3551
|
function chromePlatformArgs(android = isAndroid()) {
|
|
@@ -2889,7 +3587,7 @@ function chromeLogHint(log) {
|
|
|
2889
3587
|
function candidates() {
|
|
2890
3588
|
const e = process.env;
|
|
2891
3589
|
if (process.platform === "win32") {
|
|
2892
|
-
return [e.PROGRAMFILES, e["PROGRAMFILES(X86)"], e.LOCALAPPDATA].filter((d) => !!d).flatMap((d) => [
|
|
3590
|
+
return [e.PROGRAMFILES, e["PROGRAMFILES(X86)"], e.LOCALAPPDATA].filter((d) => !!d).flatMap((d) => [path14.join(d, "Google", "Chrome", "Application", "chrome.exe"), path14.join(d, "Microsoft", "Edge", "Application", "msedge.exe")]);
|
|
2893
3591
|
}
|
|
2894
3592
|
if (process.platform === "darwin") {
|
|
2895
3593
|
return ["/Applications/Google Chrome.app/Contents/MacOS/Google Chrome", "/Applications/Chromium.app/Contents/MacOS/Chromium", "/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge"];
|
|
@@ -2899,15 +3597,15 @@ function candidates() {
|
|
|
2899
3597
|
function findChrome(android = isAndroid()) {
|
|
2900
3598
|
const forced = process.env.HYPEFRAME_CHROME;
|
|
2901
3599
|
if (forced)
|
|
2902
|
-
return
|
|
3600
|
+
return fs18.existsSync(forced) ? forced : null;
|
|
2903
3601
|
if (android && linuxChromiumReady())
|
|
2904
3602
|
return chromiumWrapper();
|
|
2905
|
-
return candidates().find((p) =>
|
|
3603
|
+
return candidates().find((p) => fs18.existsSync(p)) || null;
|
|
2906
3604
|
}
|
|
2907
3605
|
async function cachedChrome(cacheDir) {
|
|
2908
3606
|
try {
|
|
2909
|
-
const all = await getInstalledBrowsers({ cacheDir:
|
|
2910
|
-
return all.find((b) => b.browser === Browser.CHROME &&
|
|
3607
|
+
const all = await getInstalledBrowsers({ cacheDir: path14.join(cacheDir, "chrome") });
|
|
3608
|
+
return all.find((b) => b.browser === Browser.CHROME && fs18.existsSync(b.executablePath))?.executablePath ?? null;
|
|
2911
3609
|
} catch {
|
|
2912
3610
|
return null;
|
|
2913
3611
|
}
|
|
@@ -2926,7 +3624,7 @@ async function prepareChrome(cacheDir, progress = () => {
|
|
|
2926
3624
|
const platform = detectBrowserPlatform();
|
|
2927
3625
|
if (!platform)
|
|
2928
3626
|
throw new Error("Sistem ini belum didukung untuk render (Chrome tidak tersedia).");
|
|
2929
|
-
const dir =
|
|
3627
|
+
const dir = path14.join(cacheDir, "chrome");
|
|
2930
3628
|
const buildId = await resolveBuildId(Browser.CHROME, platform, "stable");
|
|
2931
3629
|
progress(0, `Chrome ${buildId}`);
|
|
2932
3630
|
const r = await install({
|
|
@@ -2986,102 +3684,20 @@ async function checkOnce(chrome, gpu, platformArgs, pipe = false) {
|
|
|
2986
3684
|
return;
|
|
2987
3685
|
});
|
|
2988
3686
|
srv.close();
|
|
2989
|
-
}
|
|
2990
|
-
}
|
|
2991
|
-
|
|
2992
|
-
// packages/hypeframe/src/render/ffmpeg.ts
|
|
2993
|
-
import crypto5 from "node:crypto";
|
|
2994
|
-
import fs16 from "node:fs";
|
|
2995
|
-
import fsp from "node:fs/promises";
|
|
2996
|
-
import path12 from "node:path";
|
|
2997
|
-
import { pipeline } from "node:stream/promises";
|
|
2998
|
-
import { Readable } from "node:stream";
|
|
2999
|
-
import zlib from "node:zlib";
|
|
3000
|
-
var FFMPEG_RELEASE = "b6.0";
|
|
3001
|
-
var BASE = `https://github.com/eugeneware/ffmpeg-static/releases/download/${FFMPEG_RELEASE}/`;
|
|
3002
|
-
var FFMPEG_PINNED = {
|
|
3003
|
-
"win32-x64": { sha256: "450d66226c79405c724e821f291cab0911e934bfa9fa2231adcab587f3e07b50", size: 28894894 },
|
|
3004
|
-
"linux-x64": { sha256: "17c1ae10b52ac499180679fe6ba77e17642390c4eedb0f1e3b0ac045da55128f", size: 28928723 },
|
|
3005
|
-
"linux-arm64": { sha256: "2b708b2d15041d2a192c1db24c7a8a1d24f645a8242dce1c744ff2392b86ada1", size: 25131803 },
|
|
3006
|
-
"darwin-x64": { sha256: "a12354fce7eb62361473bbe10d53a1893695babd35869ec8e92e5dfea8d0440b", size: 25067704 },
|
|
3007
|
-
"darwin-arm64": { sha256: "6be74d6f449889c2e87a75873894f8520cad56c08ac76f2a628d85b0519daaca", size: 19253088 }
|
|
3008
|
-
};
|
|
3009
|
-
var exe = process.platform === "win32" ? "ffmpeg.exe" : "ffmpeg";
|
|
3010
|
-
var cached2 = (cacheDir) => path12.join(cacheDir, "ffmpeg", FFMPEG_RELEASE, exe);
|
|
3011
|
-
var thisPlatform = () => `${process.platform}-${process.arch}`;
|
|
3012
|
-
async function findFfmpeg(cacheDir, key = thisPlatform()) {
|
|
3013
|
-
const forced = process.env.HYPEFRAME_FFMPEG;
|
|
3014
|
-
if (forced)
|
|
3015
|
-
return fs16.existsSync(forced) ? forced : null;
|
|
3016
|
-
if (!FFMPEG_PINNED[key])
|
|
3017
|
-
return onPath("ffmpeg");
|
|
3018
|
-
try {
|
|
3019
|
-
const mod = await import("ffmpeg-static");
|
|
3020
|
-
const p = typeof mod.default === "string" ? mod.default : null;
|
|
3021
|
-
if (p && fs16.existsSync(p))
|
|
3022
|
-
return p;
|
|
3023
|
-
} catch {}
|
|
3024
|
-
const c = cached2(cacheDir);
|
|
3025
|
-
return fs16.existsSync(c) ? c : null;
|
|
3026
|
-
}
|
|
3027
|
-
async function downloadVerified(url, sha256, dest, progress = () => {
|
|
3028
|
-
return;
|
|
3029
|
-
}, gunzip = false) {
|
|
3030
|
-
const r = await fetch(url, { signal: AbortSignal.timeout(900000) });
|
|
3031
|
-
if (!r.ok || !r.body)
|
|
3032
|
-
throw new Error(`download ${r.status}`);
|
|
3033
|
-
const total = Number(r.headers.get("content-length")) || 0;
|
|
3034
|
-
await fsp.mkdir(path12.dirname(dest), { recursive: true });
|
|
3035
|
-
const tmp = `${dest}.download`;
|
|
3036
|
-
const hash = crypto5.createHash("sha256");
|
|
3037
|
-
let got = 0;
|
|
3038
|
-
let last = -10;
|
|
3039
|
-
const body = Readable.fromWeb(r.body).on("data", (c) => {
|
|
3040
|
-
hash.update(c);
|
|
3041
|
-
got += c.length;
|
|
3042
|
-
const pct = total ? Math.floor(got / total * 100) : 0;
|
|
3043
|
-
if (pct - last >= 10)
|
|
3044
|
-
last = pct, progress(pct);
|
|
3045
|
-
});
|
|
3046
|
-
await pipeline(body, fs16.createWriteStream(tmp));
|
|
3047
|
-
if (hash.digest("hex") !== sha256) {
|
|
3048
|
-
await fsp.rm(tmp, { force: true });
|
|
3049
|
-
throw new Error("ffmpeg: sidik unduhan tidak cocok, berkas ditolak.");
|
|
3050
|
-
}
|
|
3051
|
-
if (gunzip) {
|
|
3052
|
-
await pipeline(fs16.createReadStream(tmp), zlib.createGunzip(), fs16.createWriteStream(`${tmp}.raw`));
|
|
3053
|
-
await fsp.rm(tmp, { force: true });
|
|
3054
|
-
await fsp.rename(`${tmp}.raw`, dest);
|
|
3055
|
-
} else
|
|
3056
|
-
await fsp.rename(tmp, dest);
|
|
3057
|
-
if (process.platform !== "win32")
|
|
3058
|
-
await fsp.chmod(dest, 493);
|
|
3059
|
-
}
|
|
3060
|
-
async function prepareFfmpeg(cacheDir, progress = () => {
|
|
3061
|
-
return;
|
|
3062
|
-
}, key = thisPlatform()) {
|
|
3063
|
-
const found = await findFfmpeg(cacheDir, key);
|
|
3064
|
-
if (found)
|
|
3065
|
-
return found;
|
|
3066
|
-
const pin = FFMPEG_PINNED[key];
|
|
3067
|
-
if (!pin)
|
|
3068
|
-
throw new Error(key.startsWith("android") ? "ffmpeg belum terpasang. Di Termux jalankan: pkg install ffmpeg" : `ffmpeg tidak tersedia untuk ${key}`);
|
|
3069
|
-
progress(0);
|
|
3070
|
-
await downloadVerified(`${BASE}ffmpeg-${key}.gz`, pin.sha256, cached2(cacheDir), progress, true);
|
|
3071
|
-
return cached2(cacheDir);
|
|
3687
|
+
}
|
|
3072
3688
|
}
|
|
3073
3689
|
|
|
3074
3690
|
// packages/hypeframe/src/render/job.ts
|
|
3075
|
-
import { spawn as
|
|
3076
|
-
import
|
|
3077
|
-
import
|
|
3078
|
-
import
|
|
3079
|
-
import
|
|
3691
|
+
import { spawn as spawn4 } from "node:child_process";
|
|
3692
|
+
import crypto7 from "node:crypto";
|
|
3693
|
+
import fs19 from "node:fs";
|
|
3694
|
+
import fsp4 from "node:fs/promises";
|
|
3695
|
+
import path15 from "node:path";
|
|
3080
3696
|
import puppeteer2 from "puppeteer-core";
|
|
3081
3697
|
var LIMIT_SECONDS = 1800;
|
|
3082
3698
|
function run(cmd, args, limitSeconds = 600) {
|
|
3083
3699
|
return new Promise((ok, fail) => {
|
|
3084
|
-
const p =
|
|
3700
|
+
const p = spawn4(cmd, args, { stdio: ["ignore", "ignore", "pipe"] });
|
|
3085
3701
|
let err = "";
|
|
3086
3702
|
p.stderr.on("data", (d) => err = (err + d).slice(-2000));
|
|
3087
3703
|
const timer = setTimeout(() => p.kill("SIGKILL"), limitSeconds * 1000);
|
|
@@ -3093,7 +3709,7 @@ function run(cmd, args, limitSeconds = 600) {
|
|
|
3093
3709
|
function saveBody(req, to, max) {
|
|
3094
3710
|
return new Promise((ok, fail) => {
|
|
3095
3711
|
let n = 0;
|
|
3096
|
-
const out =
|
|
3712
|
+
const out = fs19.createWriteStream(to);
|
|
3097
3713
|
req.on("data", (d) => {
|
|
3098
3714
|
n += d.length;
|
|
3099
3715
|
if (n > max)
|
|
@@ -3124,7 +3740,7 @@ function createJobRunner(o) {
|
|
|
3124
3740
|
const renderer = async (task, { progress, signal }) => {
|
|
3125
3741
|
if (task.kind === "klip" && task.transparent && !transparent)
|
|
3126
3742
|
throw new Error(EngineError.NoTransparent);
|
|
3127
|
-
const key =
|
|
3743
|
+
const key = crypto7.randomBytes(16).toString("hex");
|
|
3128
3744
|
let finish;
|
|
3129
3745
|
const finished = new Promise((ok) => finish = ok);
|
|
3130
3746
|
running.set(task.job, { key, task, progress, finish });
|
|
@@ -3135,9 +3751,9 @@ function createJobRunner(o) {
|
|
|
3135
3751
|
let browser;
|
|
3136
3752
|
try {
|
|
3137
3753
|
progress(0, "Menyiapkan");
|
|
3138
|
-
const profile =
|
|
3139
|
-
await
|
|
3140
|
-
await
|
|
3754
|
+
const profile = path15.join(task.dir, "profil");
|
|
3755
|
+
await fsp4.mkdir(path15.join(profile, "Default"), { recursive: true });
|
|
3756
|
+
await fsp4.writeFile(path15.join(profile, "Default", "Preferences"), JSON.stringify({ webkit: { webprefs: { fonts: { standard: { Zyyy: "Roboto" }, sansserif: { Zyyy: "Roboto" }, serif: { Zyyy: "Noto Serif" } } } } }));
|
|
3141
3757
|
browser = await puppeteer2.launch({
|
|
3142
3758
|
executablePath: chrome,
|
|
3143
3759
|
headless: true,
|
|
@@ -3169,11 +3785,11 @@ function createJobRunner(o) {
|
|
|
3169
3785
|
if (result.error)
|
|
3170
3786
|
throw new Error(result.error);
|
|
3171
3787
|
progress(99, clip ? "Menyelesaikan klip" : "Menyelesaikan video");
|
|
3172
|
-
const raw =
|
|
3788
|
+
const raw = path15.join(task.dir, "mentah.mp4");
|
|
3173
3789
|
const webm = clip && task.transparent;
|
|
3174
|
-
const file =
|
|
3790
|
+
const file = path15.join(task.dir, webm ? "hasil.webm" : "hasil.mp4");
|
|
3175
3791
|
if (clip)
|
|
3176
|
-
await
|
|
3792
|
+
await fsp4.rename(raw, file);
|
|
3177
3793
|
else
|
|
3178
3794
|
await run(ffmpeg, ["-y", "-v", "error", "-i", raw, "-map", "0", "-c:v", "copy", ...result.audio === "opus" ? ["-c:a", "aac", "-b:a", "192k"] : ["-c:a", "copy"], "-movflags", "+faststart", file]);
|
|
3179
3795
|
return { file, type: webm ? "video/webm" : "video/mp4" };
|
|
@@ -3198,11 +3814,11 @@ function createJobRunner(o) {
|
|
|
3198
3814
|
return res.writeHead(403), res.end(), true;
|
|
3199
3815
|
const pkg = r.task.packageDir;
|
|
3200
3816
|
if (m[2] === "proyek.json" || m[2] === "klip.json" || m[3]) {
|
|
3201
|
-
const f = m[3] ?
|
|
3202
|
-
if (!
|
|
3817
|
+
const f = m[3] ? path15.join(pkg, "aset", m[3]) : path15.join(pkg, m[2]);
|
|
3818
|
+
if (!fs19.existsSync(f))
|
|
3203
3819
|
return res.writeHead(404), res.end(), true;
|
|
3204
|
-
res.writeHead(200, { "content-type": m[3] ? "application/octet-stream" : "application/json", "content-length": (await
|
|
3205
|
-
|
|
3820
|
+
res.writeHead(200, { "content-type": m[3] ? "application/octet-stream" : "application/json", "content-length": (await fsp4.stat(f)).size });
|
|
3821
|
+
fs19.createReadStream(f).pipe(res);
|
|
3206
3822
|
return true;
|
|
3207
3823
|
}
|
|
3208
3824
|
if (m[2] === "kemajuan") {
|
|
@@ -3219,7 +3835,7 @@ function createJobRunner(o) {
|
|
|
3219
3835
|
r.finish({ error: String(b.pesan || "Render gagal.").slice(0, 300) });
|
|
3220
3836
|
return res.writeHead(204), res.end(), true;
|
|
3221
3837
|
}
|
|
3222
|
-
await saveBody(req,
|
|
3838
|
+
await saveBody(req, path15.join(r.task.dir, "mentah.mp4"), 8 * 1073741824);
|
|
3223
3839
|
r.finish({ audio: String(req.headers["x-kodek-audio"] || "") });
|
|
3224
3840
|
res.writeHead(204);
|
|
3225
3841
|
res.end();
|
|
@@ -3229,9 +3845,9 @@ function createJobRunner(o) {
|
|
|
3229
3845
|
}
|
|
3230
3846
|
|
|
3231
3847
|
// packages/hypeframe/src/render/page.ts
|
|
3232
|
-
import
|
|
3233
|
-
import
|
|
3234
|
-
import
|
|
3848
|
+
import fs20 from "node:fs";
|
|
3849
|
+
import fsp5 from "node:fs/promises";
|
|
3850
|
+
import path16 from "node:path";
|
|
3235
3851
|
var TYPES = {
|
|
3236
3852
|
".html": "text/html; charset=utf-8",
|
|
3237
3853
|
".js": "text/javascript",
|
|
@@ -3252,13 +3868,13 @@ var SAFE_PATH = /^[\w@.+-]+(?:\/[\w@.+-]+)*$/;
|
|
|
3252
3868
|
var VERSION_ID = /^[0-9a-f]{12}$/;
|
|
3253
3869
|
function createPage({ web, cacheDir }) {
|
|
3254
3870
|
const base = `${String(web || "").replace(/\/+$/, "")}/render/`;
|
|
3255
|
-
const root =
|
|
3871
|
+
const root = path16.join(cacheDir, "halaman");
|
|
3256
3872
|
let version = null;
|
|
3257
|
-
const versionDir = () =>
|
|
3873
|
+
const versionDir = () => path16.join(root, version);
|
|
3258
3874
|
const pending = new Map;
|
|
3259
3875
|
async function download(rel) {
|
|
3260
|
-
const target =
|
|
3261
|
-
if (
|
|
3876
|
+
const target = path16.join(versionDir(), rel);
|
|
3877
|
+
if (fs20.existsSync(target))
|
|
3262
3878
|
return target;
|
|
3263
3879
|
if (!pending.has(rel)) {
|
|
3264
3880
|
pending.set(rel, (async () => {
|
|
@@ -3266,9 +3882,9 @@ function createPage({ web, cacheDir }) {
|
|
|
3266
3882
|
if (!r.ok)
|
|
3267
3883
|
throw Object.assign(new Error(`halaman ${rel}: ${r.status}`), { status: r.status });
|
|
3268
3884
|
const body = Buffer.from(await r.arrayBuffer());
|
|
3269
|
-
await
|
|
3270
|
-
await
|
|
3271
|
-
await
|
|
3885
|
+
await fsp5.mkdir(path16.dirname(target), { recursive: true });
|
|
3886
|
+
await fsp5.writeFile(`${target}.tmp`, body);
|
|
3887
|
+
await fsp5.rename(`${target}.tmp`, target);
|
|
3272
3888
|
return target;
|
|
3273
3889
|
})().finally(() => pending.delete(rel)));
|
|
3274
3890
|
}
|
|
@@ -3289,11 +3905,11 @@ function createPage({ web, cacheDir }) {
|
|
|
3289
3905
|
if (typeof f === "string" && SAFE_PATH.test(f))
|
|
3290
3906
|
await download(f);
|
|
3291
3907
|
if (old !== version) {
|
|
3292
|
-
const all = (await
|
|
3293
|
-
const dated = await Promise.all(all.map(async (d) => ({ d, t: (await
|
|
3908
|
+
const all = (await fsp5.readdir(root).catch(() => [])).filter((d) => VERSION_ID.test(d));
|
|
3909
|
+
const dated = await Promise.all(all.map(async (d) => ({ d, t: (await fsp5.stat(path16.join(root, d))).mtimeMs })));
|
|
3294
3910
|
for (const { d } of dated.sort((a, b) => b.t - a.t).slice(2))
|
|
3295
3911
|
if (d !== version)
|
|
3296
|
-
await
|
|
3912
|
+
await fsp5.rm(path16.join(root, d), { recursive: true, force: true });
|
|
3297
3913
|
}
|
|
3298
3914
|
return { version };
|
|
3299
3915
|
}
|
|
@@ -3310,8 +3926,8 @@ function createPage({ web, cacheDir }) {
|
|
|
3310
3926
|
return res.writeHead(404), res.end(), true;
|
|
3311
3927
|
try {
|
|
3312
3928
|
const f = await download(rel);
|
|
3313
|
-
res.writeHead(200, { "content-type": TYPES[
|
|
3314
|
-
|
|
3929
|
+
res.writeHead(200, { "content-type": TYPES[path16.extname(f)] || "application/octet-stream", "cache-control": "no-store" });
|
|
3930
|
+
fs20.createReadStream(f).pipe(res);
|
|
3315
3931
|
} catch (e) {
|
|
3316
3932
|
res.writeHead(e.status === 404 ? 404 : 502);
|
|
3317
3933
|
res.end();
|
|
@@ -3328,8 +3944,8 @@ function createPage({ web, cacheDir }) {
|
|
|
3328
3944
|
}
|
|
3329
3945
|
|
|
3330
3946
|
// packages/hypeframe/src/render/relay.ts
|
|
3331
|
-
import
|
|
3332
|
-
var sha = (b) =>
|
|
3947
|
+
import crypto8 from "node:crypto";
|
|
3948
|
+
var sha = (b) => crypto8.createHash("sha256").update(b).digest("hex");
|
|
3333
3949
|
var sleep2 = (ms) => new Promise((ok) => setTimeout(ok, ms));
|
|
3334
3950
|
async function runRelayJob(j, o) {
|
|
3335
3951
|
const step = o.onStep ?? (() => {
|
|
@@ -3398,7 +4014,7 @@ async function runRelayJob(j, o) {
|
|
|
3398
4014
|
return fail(`The finished video could not be read (${r.status}).`);
|
|
3399
4015
|
const type = r.headers.get("content-type") === "video/webm" ? "video/webm" : "video/mp4";
|
|
3400
4016
|
const size = Math.max(1, o.resultPartMb ?? 32) * 1048576;
|
|
3401
|
-
const total =
|
|
4017
|
+
const total = crypto8.createHash("sha256");
|
|
3402
4018
|
let sent = 0;
|
|
3403
4019
|
let n = 0;
|
|
3404
4020
|
let buf = [];
|
|
@@ -3445,19 +4061,19 @@ async function runRelayJob(j, o) {
|
|
|
3445
4061
|
}
|
|
3446
4062
|
|
|
3447
4063
|
// packages/hypeframe/src/render/service.ts
|
|
3448
|
-
import
|
|
3449
|
-
import
|
|
3450
|
-
import
|
|
4064
|
+
import crypto9 from "node:crypto";
|
|
4065
|
+
import fs21 from "node:fs";
|
|
4066
|
+
import fsp6 from "node:fs/promises";
|
|
3451
4067
|
import http2 from "node:http";
|
|
3452
|
-
import
|
|
3453
|
-
import
|
|
4068
|
+
import path17 from "node:path";
|
|
4069
|
+
import yauzl2 from "yauzl";
|
|
3454
4070
|
var ACTIVE = new Set(["unggah", "antre", "jalan"]);
|
|
3455
|
-
var safeEqual = (a, b) => a.length === b.length &&
|
|
4071
|
+
var safeEqual = (a, b) => a.length === b.length && crypto9.timingSafeEqual(Buffer.from(a), Buffer.from(b));
|
|
3456
4072
|
var BAD_ENTRY = /relative path|absolute path|invalid characters/i;
|
|
3457
4073
|
function listZip(f) {
|
|
3458
4074
|
return new Promise((ok, fail) => {
|
|
3459
4075
|
const refuse = (e) => fail(BAD_ENTRY.test(e.message) ? new Error(EngineError.BadPackage) : e);
|
|
3460
|
-
|
|
4076
|
+
yauzl2.open(f, { lazyEntries: true }, (e, zip) => {
|
|
3461
4077
|
if (e || !zip)
|
|
3462
4078
|
return refuse(e ?? new Error("zip"));
|
|
3463
4079
|
const entries = [];
|
|
@@ -3470,20 +4086,20 @@ function listZip(f) {
|
|
|
3470
4086
|
}
|
|
3471
4087
|
function extractZip(f, to) {
|
|
3472
4088
|
return new Promise((ok, fail) => {
|
|
3473
|
-
|
|
4089
|
+
yauzl2.open(f, { lazyEntries: true }, (e, zip) => {
|
|
3474
4090
|
if (e || !zip)
|
|
3475
4091
|
return fail(e ?? new Error("zip"));
|
|
3476
4092
|
zip.on("entry", (en) => {
|
|
3477
4093
|
if (en.fileName.endsWith("/"))
|
|
3478
4094
|
return zip.readEntry();
|
|
3479
|
-
const target =
|
|
3480
|
-
if (!target.startsWith(to +
|
|
4095
|
+
const target = path17.join(to, en.fileName);
|
|
4096
|
+
if (!target.startsWith(to + path17.sep))
|
|
3481
4097
|
return fail(new Error(EngineError.BadPackage));
|
|
3482
|
-
|
|
4098
|
+
fs21.mkdirSync(path17.dirname(target), { recursive: true });
|
|
3483
4099
|
zip.openReadStream(en, (e2, s) => {
|
|
3484
4100
|
if (e2 || !s)
|
|
3485
4101
|
return fail(e2 ?? new Error("zip"));
|
|
3486
|
-
const out =
|
|
4102
|
+
const out = fs21.createWriteStream(target);
|
|
3487
4103
|
s.pipe(out);
|
|
3488
4104
|
out.on("finish", () => zip.readEntry());
|
|
3489
4105
|
out.on("error", fail);
|
|
@@ -3498,13 +4114,13 @@ function extractZip(f, to) {
|
|
|
3498
4114
|
function saveBody2(req, to, max) {
|
|
3499
4115
|
return new Promise((ok, fail) => {
|
|
3500
4116
|
let n = 0;
|
|
3501
|
-
const out =
|
|
4117
|
+
const out = fs21.createWriteStream(to);
|
|
3502
4118
|
req.on("data", (d) => {
|
|
3503
4119
|
n += d.length;
|
|
3504
4120
|
if (n > max) {
|
|
3505
4121
|
req.destroy();
|
|
3506
4122
|
out.destroy();
|
|
3507
|
-
|
|
4123
|
+
fs21.rm(to, { force: true }, () => fail(new Error("terlalu besar")));
|
|
3508
4124
|
}
|
|
3509
4125
|
});
|
|
3510
4126
|
req.pipe(out);
|
|
@@ -3532,9 +4148,9 @@ async function createRenderService(o) {
|
|
|
3532
4148
|
return;
|
|
3533
4149
|
} } = o;
|
|
3534
4150
|
const origins = new Set([].concat(o.origin || []));
|
|
3535
|
-
const sign = (kind, body) =>
|
|
3536
|
-
const dir = (job) =>
|
|
3537
|
-
await
|
|
4151
|
+
const sign = (kind, body) => crypto9.createHmac("sha256", key).update(`${kind}.${body}`).digest("base64url");
|
|
4152
|
+
const dir = (job) => path17.join(folder, job);
|
|
4153
|
+
await fsp6.mkdir(folder, { recursive: true });
|
|
3538
4154
|
function readTicket(req) {
|
|
3539
4155
|
const tk = String(req.headers.authorization || "").replace(/^Bearer\s+/i, "");
|
|
3540
4156
|
const [v, body, sig] = tk.split(".");
|
|
@@ -3555,7 +4171,7 @@ async function createRenderService(o) {
|
|
|
3555
4171
|
const jobs = new Map;
|
|
3556
4172
|
const queue = [];
|
|
3557
4173
|
let current = null;
|
|
3558
|
-
const persist = (t) =>
|
|
4174
|
+
const persist = (t) => fsp6.writeFile(path17.join(dir(t.job), "status.json"), JSON.stringify(t)).catch(() => {
|
|
3559
4175
|
return;
|
|
3560
4176
|
});
|
|
3561
4177
|
const update = (t, patch) => (Object.assign(t, patch, { diperbarui: Date.now() }), void persist(t));
|
|
@@ -3574,19 +4190,19 @@ async function createRenderService(o) {
|
|
|
3574
4190
|
});
|
|
3575
4191
|
async function clearFiles(t, all = false) {
|
|
3576
4192
|
for (const n of all ? ["."] : ["paket", "paket.zip", "profil", "mentah.mp4", "mentah.webm"])
|
|
3577
|
-
await
|
|
4193
|
+
await fsp6.rm(path17.join(dir(t.job), n), { recursive: true, force: true }).catch(() => {
|
|
3578
4194
|
return;
|
|
3579
4195
|
});
|
|
3580
4196
|
if (!all) {
|
|
3581
|
-
for (const f of await
|
|
4197
|
+
for (const f of await fsp6.readdir(dir(t.job)).catch(() => []))
|
|
3582
4198
|
if (/^p\d+$/.test(f))
|
|
3583
|
-
await
|
|
4199
|
+
await fsp6.rm(path17.join(dir(t.job), f), { force: true });
|
|
3584
4200
|
}
|
|
3585
4201
|
}
|
|
3586
4202
|
async function openPackage(t) {
|
|
3587
4203
|
const d = dir(t.job);
|
|
3588
4204
|
const main = t.tiket.jenis === "klip" ? "klip.json" : "proyek.json";
|
|
3589
|
-
const entries = await listZip(
|
|
4205
|
+
const entries = await listZip(path17.join(d, "paket.zip"));
|
|
3590
4206
|
const names = entries.map((x) => x.name).filter((n) => !n.endsWith("/"));
|
|
3591
4207
|
if (names.some((n) => n.startsWith("/") || n.includes("..") || n.includes("\\") || n !== main && !/^aset\/[\w-]+$/.test(n)))
|
|
3592
4208
|
throw new Error(EngineError.BadPackage);
|
|
@@ -3594,10 +4210,10 @@ async function createRenderService(o) {
|
|
|
3594
4210
|
throw new Error(`Paket tidak berisi ${main}.`);
|
|
3595
4211
|
if (entries.reduce((a, x) => a + x.size, 0) > maxUnzippedMb * 1048576)
|
|
3596
4212
|
throw new Error("Isi paket terlalu besar.");
|
|
3597
|
-
await extractZip(
|
|
3598
|
-
await
|
|
3599
|
-
const j = JSON.parse(await
|
|
3600
|
-
const has = (id) => /^[\w-]+$/.test(id) &&
|
|
4213
|
+
await extractZip(path17.join(d, "paket.zip"), path17.join(d, "paket"));
|
|
4214
|
+
await fsp6.rm(path17.join(d, "paket.zip"), { force: true });
|
|
4215
|
+
const j = JSON.parse(await fsp6.readFile(path17.join(d, "paket", main), "utf8"));
|
|
4216
|
+
const has = (id) => /^[\w-]+$/.test(id) && fs21.existsSync(path17.join(d, "paket", "aset", id));
|
|
3601
4217
|
if (main === "klip.json") {
|
|
3602
4218
|
const k = j.klip || {};
|
|
3603
4219
|
const seconds = Number(k.durationInFrames) / Number(k.fps);
|
|
@@ -3645,7 +4261,7 @@ async function createRenderService(o) {
|
|
|
3645
4261
|
job: t.job,
|
|
3646
4262
|
kind: t.tiket.jenis,
|
|
3647
4263
|
dir: dir(t.job),
|
|
3648
|
-
packageDir:
|
|
4264
|
+
packageDir: path17.join(dir(t.job), "paket"),
|
|
3649
4265
|
transparent: !!t.transparan,
|
|
3650
4266
|
persen: t.persen,
|
|
3651
4267
|
width: t.tiket.w,
|
|
@@ -3662,10 +4278,10 @@ async function createRenderService(o) {
|
|
|
3662
4278
|
const h = await renderer(task, { progress, signal: cancel.signal });
|
|
3663
4279
|
if (cancel.signal.aborted)
|
|
3664
4280
|
throw new Error("Dibatalkan.");
|
|
3665
|
-
const size = (await
|
|
4281
|
+
const size = (await fsp6.stat(h.file)).size;
|
|
3666
4282
|
if (size < 200)
|
|
3667
4283
|
throw new Error(EngineError.EmptyResult);
|
|
3668
|
-
update(t, { status: "selesai", persen: 100, tahap: "", selesaiPada: Date.now(), hasilUkuran: size, hasilBerkas:
|
|
4284
|
+
update(t, { status: "selesai", persen: 100, tahap: "", selesaiPada: Date.now(), hasilUkuran: size, hasilBerkas: path17.basename(h.file), hasilJenis: h.type });
|
|
3669
4285
|
onJob("done", t);
|
|
3670
4286
|
} catch (e) {
|
|
3671
4287
|
if (t.status !== "batal") {
|
|
@@ -3694,7 +4310,7 @@ async function createRenderService(o) {
|
|
|
3694
4310
|
}
|
|
3695
4311
|
const json = (req, res, code, body) => (res.writeHead(code, { ...cors(req), "content-type": "application/json", "cache-control": "no-store" }), res.end(JSON.stringify(body)));
|
|
3696
4312
|
async function sendFile(req, res, f, type, name) {
|
|
3697
|
-
const st = await
|
|
4313
|
+
const st = await fsp6.stat(f);
|
|
3698
4314
|
const range = /^bytes=(\d+)-(\d*)$/.exec(String(req.headers.range || ""));
|
|
3699
4315
|
const h = { ...cors(req), "content-type": type, "accept-ranges": "bytes", "cache-control": "no-store", "content-disposition": `attachment; filename="${name}"` };
|
|
3700
4316
|
if (range) {
|
|
@@ -3703,10 +4319,10 @@ async function createRenderService(o) {
|
|
|
3703
4319
|
if (a > z)
|
|
3704
4320
|
return res.writeHead(416, { ...h, "content-range": `bytes */${st.size}` }), res.end();
|
|
3705
4321
|
res.writeHead(206, { ...h, "content-length": z - a + 1, "content-range": `bytes ${a}-${z}/${st.size}` });
|
|
3706
|
-
return void
|
|
4322
|
+
return void fs21.createReadStream(f, { start: a, end: z }).pipe(res);
|
|
3707
4323
|
}
|
|
3708
4324
|
res.writeHead(200, { ...h, "content-length": st.size });
|
|
3709
|
-
|
|
4325
|
+
fs21.createReadStream(f).pipe(res);
|
|
3710
4326
|
}
|
|
3711
4327
|
const ROUTE = /^\/tugas(?:\/(r_[a-f0-9]{16})(\/potongan\/(\d{1,4})|\/mulai|\/hasil)?)?$/;
|
|
3712
4328
|
const server = http2.createServer(async (req, res) => {
|
|
@@ -3733,7 +4349,7 @@ async function createRenderService(o) {
|
|
|
3733
4349
|
return json(req, res, 200, summary(t));
|
|
3734
4350
|
if (queue.length >= maxQueue)
|
|
3735
4351
|
return json(req, res, 503, { galat: EngineError.QueueFull });
|
|
3736
|
-
await
|
|
4352
|
+
await fsp6.mkdir(dir(job), { recursive: true });
|
|
3737
4353
|
t = { job, tiket: ticket, status: "unggah", dibuat: Date.now(), diperbarui: Date.now(), terunggah: 0 };
|
|
3738
4354
|
jobs.set(job, t);
|
|
3739
4355
|
persist(t);
|
|
@@ -3745,15 +4361,15 @@ async function createRenderService(o) {
|
|
|
3745
4361
|
if (t.status !== "unggah")
|
|
3746
4362
|
return json(req, res, 409, { galat: "Unggahan sudah ditutup." });
|
|
3747
4363
|
const n = Number(m[3]);
|
|
3748
|
-
const f =
|
|
3749
|
-
const before =
|
|
4364
|
+
const f = path17.join(dir(job), `p${n}`);
|
|
4365
|
+
const before = fs21.existsSync(f) ? (await fsp6.stat(f)).size : 0;
|
|
3750
4366
|
const room = Number(ticket.maksMb) * 1048576 - (t.terunggah - before);
|
|
3751
4367
|
const size = await saveBody2(req, f, Math.min(partMb * 1048576 + 1024, room));
|
|
3752
4368
|
const expected = String(req.headers["x-sha256"] || "").toLowerCase();
|
|
3753
4369
|
if (expected) {
|
|
3754
|
-
const digest =
|
|
4370
|
+
const digest = crypto9.createHash("sha256").update(await fsp6.readFile(f)).digest("hex");
|
|
3755
4371
|
if (digest !== expected) {
|
|
3756
|
-
await
|
|
4372
|
+
await fsp6.rm(f, { force: true });
|
|
3757
4373
|
update(t, { terunggah: t.terunggah - before });
|
|
3758
4374
|
return json(req, res, 400, { galat: "Potongan rusak di jalan. Kirim ulang." });
|
|
3759
4375
|
}
|
|
@@ -3768,24 +4384,24 @@ async function createRenderService(o) {
|
|
|
3768
4384
|
const count = Number(b.jumlah);
|
|
3769
4385
|
if (!(count > 0 && count < 1e4))
|
|
3770
4386
|
return json(req, res, 400, { galat: "Jumlah potongan tidak valid." });
|
|
3771
|
-
const zip =
|
|
3772
|
-
const out =
|
|
3773
|
-
const hash =
|
|
4387
|
+
const zip = path17.join(dir(job), "paket.zip");
|
|
4388
|
+
const out = fs21.createWriteStream(zip);
|
|
4389
|
+
const hash = crypto9.createHash("sha256");
|
|
3774
4390
|
let total = 0;
|
|
3775
4391
|
for (let i = 0;i < count; i++) {
|
|
3776
|
-
const f =
|
|
3777
|
-
if (!
|
|
4392
|
+
const f = path17.join(dir(job), `p${i}`);
|
|
4393
|
+
if (!fs21.existsSync(f))
|
|
3778
4394
|
return out.destroy(), json(req, res, 400, { galat: `Potongan ${i + 1} belum terunggah.` });
|
|
3779
|
-
const part = await
|
|
4395
|
+
const part = await fsp6.readFile(f);
|
|
3780
4396
|
hash.update(part);
|
|
3781
4397
|
total += part.length;
|
|
3782
4398
|
await new Promise((ok) => out.write(part) ? ok() : out.once("drain", ok));
|
|
3783
|
-
await
|
|
4399
|
+
await fsp6.rm(f, { force: true });
|
|
3784
4400
|
}
|
|
3785
4401
|
await new Promise((ok) => out.end(ok));
|
|
3786
4402
|
const digest = hash.digest("hex");
|
|
3787
4403
|
if (total !== Number(b.ukuran) || b.sha256 && digest !== String(b.sha256).toLowerCase()) {
|
|
3788
|
-
await
|
|
4404
|
+
await fsp6.rm(zip, { force: true });
|
|
3789
4405
|
update(t, { terunggah: 0 });
|
|
3790
4406
|
return json(req, res, 400, { galat: "Unggahan rusak di jalan. Coba render lagi." });
|
|
3791
4407
|
}
|
|
@@ -3804,8 +4420,8 @@ async function createRenderService(o) {
|
|
|
3804
4420
|
return json(req, res, 200, summary(t));
|
|
3805
4421
|
}
|
|
3806
4422
|
if (m[2] === "/hasil" && (req.method === "GET" || req.method === "HEAD")) {
|
|
3807
|
-
const f = t.hasilBerkas ?
|
|
3808
|
-
if (t.status !== "selesai" || !f || !
|
|
4423
|
+
const f = t.hasilBerkas ? path17.join(dir(job), t.hasilBerkas) : "";
|
|
4424
|
+
if (t.status !== "selesai" || !f || !fs21.existsSync(f))
|
|
3809
4425
|
return json(req, res, 409, { galat: "Video belum jadi." });
|
|
3810
4426
|
const webm = t.hasilJenis === "video/webm";
|
|
3811
4427
|
return sendFile(req, res, f, webm ? "video/webm" : "video/mp4", `hypeframe-${job}.${webm ? "webm" : "mp4"}`);
|
|
@@ -3832,16 +4448,16 @@ async function createRenderService(o) {
|
|
|
3832
4448
|
json(req, res, 500, { galat: EngineError.ServiceError });
|
|
3833
4449
|
}
|
|
3834
4450
|
});
|
|
3835
|
-
for (const job of await
|
|
4451
|
+
for (const job of await fsp6.readdir(folder).catch(() => [])) {
|
|
3836
4452
|
if (!JOB_ID.test(job))
|
|
3837
4453
|
continue;
|
|
3838
4454
|
try {
|
|
3839
|
-
const t = JSON.parse(await
|
|
4455
|
+
const t = JSON.parse(await fsp6.readFile(path17.join(dir(job), "status.json"), "utf8"));
|
|
3840
4456
|
if (t.status === "jalan" || t.status === "antre")
|
|
3841
4457
|
update(t, { status: "gagal", galat: EngineError.Restarted });
|
|
3842
4458
|
jobs.set(job, t);
|
|
3843
4459
|
} catch {
|
|
3844
|
-
await
|
|
4460
|
+
await fsp6.rm(dir(job), { recursive: true, force: true });
|
|
3845
4461
|
}
|
|
3846
4462
|
}
|
|
3847
4463
|
const sweep = setInterval(async () => {
|
|
@@ -3917,7 +4533,7 @@ function table(rows, indent = " ") {
|
|
|
3917
4533
|
}
|
|
3918
4534
|
|
|
3919
4535
|
// packages/hypeframe/src/util/open.ts
|
|
3920
|
-
import { spawn as
|
|
4536
|
+
import { spawn as spawn5 } from "node:child_process";
|
|
3921
4537
|
var PAIRING_LINK = new RegExp(`^https?://[A-Za-z0-9.-]+(:\\d+)?/sambung\\?kode=${PAIRING_CODE.source.slice(1, -1)}$`);
|
|
3922
4538
|
var WEB_ORIGIN = /^https?:\/\/[A-Za-z0-9.-]+(:\d+)?\/?$/;
|
|
3923
4539
|
function openCommand(target, platform, url) {
|
|
@@ -3931,7 +4547,7 @@ function openCommand(target, platform, url) {
|
|
|
3931
4547
|
}
|
|
3932
4548
|
function launch(target, url) {
|
|
3933
4549
|
const [cmd, args] = openCommand(target, isAndroid() ? "android" : process.platform, url);
|
|
3934
|
-
const p =
|
|
4550
|
+
const p = spawn5(cmd, args, { stdio: "ignore", detached: true });
|
|
3935
4551
|
p.on("error", () => {
|
|
3936
4552
|
return;
|
|
3937
4553
|
});
|
|
@@ -3987,6 +4603,10 @@ function logAgentEvent(e) {
|
|
|
3987
4603
|
return log.warn(t("agentLog.stopped", { agent: a, code: String(e.code) }));
|
|
3988
4604
|
case "account":
|
|
3989
4605
|
return log.info(t("agentLog.account", { agent: a }));
|
|
4606
|
+
case "terminal":
|
|
4607
|
+
return log.info(t("agentLog.terminal", { agent: a }));
|
|
4608
|
+
case "terminalClosed":
|
|
4609
|
+
return log.detail(t("agentLog.terminalClosed", { agent: e.agent }));
|
|
3990
4610
|
}
|
|
3991
4611
|
}
|
|
3992
4612
|
async function pairDevice(s, noBrowser = false) {
|
|
@@ -4035,7 +4655,7 @@ async function start(args, { fromMenu = false } = {}) {
|
|
|
4035
4655
|
let conn = null;
|
|
4036
4656
|
let servicePort = 0;
|
|
4037
4657
|
const agents = createAgentService({
|
|
4038
|
-
conn: { news: (k, b) => conn?.news(k, b), request: (ke, kind, body, ms) => conn?.request(ke, kind, body, ms) ?? Promise.resolve({ ok: false, error: "terputus" }) },
|
|
4658
|
+
conn: { news: (k, b) => conn?.news(k, b), request: (ke, kind, body, ms) => conn?.request(ke, kind, body, ms) ?? Promise.resolve({ ok: false, error: "terputus" }), tty: (ke, b) => conn?.tty(ke, b) },
|
|
4039
4659
|
port: () => servicePort,
|
|
4040
4660
|
bridge: bridgeLaunch(),
|
|
4041
4661
|
onToolError: (e) => log.warn(t(e === "tab" ? "agent.toolNoTab" : "agent.toolNoAnswer")),
|
|
@@ -4046,8 +4666,8 @@ async function start(args, { fromMenu = false } = {}) {
|
|
|
4046
4666
|
log.info(t("linux.openUrl", { url }));
|
|
4047
4667
|
openOnPhone(url);
|
|
4048
4668
|
});
|
|
4049
|
-
const capabilities = { render: false, chrome: null, transparan: false, agen: agents.capabilities() };
|
|
4050
|
-
const key =
|
|
4669
|
+
const capabilities = { render: false, chrome: null, transparan: false, agen: agents.capabilities(), terminal: ptySupported() };
|
|
4670
|
+
const key = crypto10.randomBytes(32).toString("base64url");
|
|
4051
4671
|
const cache = cacheDir();
|
|
4052
4672
|
const page = createPage({ web: s.web, cacheDir: cache });
|
|
4053
4673
|
let runner = null;
|
|
@@ -4111,6 +4731,7 @@ async function start(args, { fromMenu = false } = {}) {
|
|
|
4111
4731
|
});
|
|
4112
4732
|
const engineConn = new Connection({ gateway: s.gateway, token: account.token, info: { versi: VERSION, os: osName(), nama: s.name, kemampuan: capabilities, portLokal: service.port }, handler });
|
|
4113
4733
|
conn = engineConn;
|
|
4734
|
+
engineConn.on("tty", (m) => agents.tty(String(m.dari ?? ""), m));
|
|
4114
4735
|
setInterval(() => {
|
|
4115
4736
|
agents.checkAccounts();
|
|
4116
4737
|
const now = agents.capabilities();
|
|
@@ -4255,24 +4876,24 @@ function logout() {
|
|
|
4255
4876
|
}
|
|
4256
4877
|
|
|
4257
4878
|
// packages/hypeframe/src/cli/commands/autostart.ts
|
|
4258
|
-
import { spawnSync as
|
|
4259
|
-
import
|
|
4260
|
-
import
|
|
4261
|
-
import
|
|
4879
|
+
import { spawnSync as spawnSync4 } from "node:child_process";
|
|
4880
|
+
import fs22 from "node:fs";
|
|
4881
|
+
import os4 from "node:os";
|
|
4882
|
+
import path18 from "node:path";
|
|
4262
4883
|
function entryFile() {
|
|
4263
|
-
const home =
|
|
4884
|
+
const home = os4.homedir();
|
|
4264
4885
|
if (process.platform === "win32")
|
|
4265
|
-
return
|
|
4886
|
+
return path18.join(process.env.APPDATA || path18.join(home, "AppData", "Roaming"), "Microsoft", "Windows", "Start Menu", "Programs", "Startup", "HypeFrame.cmd");
|
|
4266
4887
|
if (process.platform === "darwin")
|
|
4267
|
-
return
|
|
4888
|
+
return path18.join(home, "Library", "LaunchAgents", "com.hypeframe.engine.plist");
|
|
4268
4889
|
if (hasSystemd())
|
|
4269
|
-
return
|
|
4270
|
-
return
|
|
4890
|
+
return path18.join(home, ".config", "systemd", "user", "hypeframe.service");
|
|
4891
|
+
return path18.join(home, ".config", "autostart", "hypeframe.desktop");
|
|
4271
4892
|
}
|
|
4272
4893
|
function hasSystemd() {
|
|
4273
|
-
return process.platform === "linux" &&
|
|
4894
|
+
return process.platform === "linux" && spawnSync4("systemctl", ["--user", "--version"], { stdio: "ignore" }).status === 0;
|
|
4274
4895
|
}
|
|
4275
|
-
var autostartEnabled = () =>
|
|
4896
|
+
var autostartEnabled = () => fs22.existsSync(entryFile());
|
|
4276
4897
|
var xml = (s) => s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
4277
4898
|
function autostart(mode) {
|
|
4278
4899
|
const file = entryFile();
|
|
@@ -4283,8 +4904,8 @@ function autostart(mode) {
|
|
|
4283
4904
|
}
|
|
4284
4905
|
if (mode === "off") {
|
|
4285
4906
|
if (process.platform === "linux" && file.endsWith(".service"))
|
|
4286
|
-
|
|
4287
|
-
|
|
4907
|
+
spawnSync4("systemctl", ["--user", "disable", "hypeframe.service"], { stdio: "ignore" });
|
|
4908
|
+
fs22.rmSync(file, { force: true });
|
|
4288
4909
|
log.ok(t("autostart.off"));
|
|
4289
4910
|
return;
|
|
4290
4911
|
}
|
|
@@ -4299,14 +4920,14 @@ function autostart(mode) {
|
|
|
4299
4920
|
return;
|
|
4300
4921
|
}
|
|
4301
4922
|
const quoted = cmd.map((c) => `"${c}"`).join(" ");
|
|
4302
|
-
|
|
4923
|
+
fs22.mkdirSync(path18.dirname(file), { recursive: true });
|
|
4303
4924
|
if (process.platform === "win32") {
|
|
4304
|
-
|
|
4925
|
+
fs22.writeFileSync(file, `@echo off\r
|
|
4305
4926
|
start "HypeFrame" /min ${quoted} start --no-browser\r
|
|
4306
4927
|
`);
|
|
4307
4928
|
} else if (process.platform === "darwin") {
|
|
4308
|
-
const out =
|
|
4309
|
-
|
|
4929
|
+
const out = path18.join(logDir(), "autostart.log");
|
|
4930
|
+
fs22.writeFileSync(file, `<?xml version="1.0" encoding="UTF-8"?>
|
|
4310
4931
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
4311
4932
|
<plist version="1.0"><dict>
|
|
4312
4933
|
<key>Label</key><string>com.hypeframe.engine</string>
|
|
@@ -4317,7 +4938,7 @@ start "HypeFrame" /min ${quoted} start --no-browser\r
|
|
|
4317
4938
|
</dict></plist>
|
|
4318
4939
|
`);
|
|
4319
4940
|
} else if (file.endsWith(".service")) {
|
|
4320
|
-
|
|
4941
|
+
fs22.writeFileSync(file, `[Unit]
|
|
4321
4942
|
Description=HypeFrame engine
|
|
4322
4943
|
After=network-online.target
|
|
4323
4944
|
|
|
@@ -4329,10 +4950,10 @@ RestartSec=60
|
|
|
4329
4950
|
[Install]
|
|
4330
4951
|
WantedBy=default.target
|
|
4331
4952
|
`);
|
|
4332
|
-
|
|
4333
|
-
|
|
4953
|
+
spawnSync4("systemctl", ["--user", "daemon-reload"], { stdio: "ignore" });
|
|
4954
|
+
spawnSync4("systemctl", ["--user", "enable", "hypeframe.service"], { stdio: "ignore" });
|
|
4334
4955
|
} else {
|
|
4335
|
-
|
|
4956
|
+
fs22.writeFileSync(file, `[Desktop Entry]
|
|
4336
4957
|
Type=Application
|
|
4337
4958
|
Name=HypeFrame engine
|
|
4338
4959
|
Exec=${quoted} start --no-browser
|
|
@@ -4444,245 +5065,6 @@ async function bench(args) {
|
|
|
4444
5065
|
|
|
4445
5066
|
// packages/hypeframe/src/cli/commands/agent.ts
|
|
4446
5067
|
import * as p from "@clack/prompts";
|
|
4447
|
-
|
|
4448
|
-
// packages/hypeframe/src/agent/install.ts
|
|
4449
|
-
import fs21 from "node:fs";
|
|
4450
|
-
import fsp5 from "node:fs/promises";
|
|
4451
|
-
import path17 from "node:path";
|
|
4452
|
-
import yauzl2 from "yauzl";
|
|
4453
|
-
function unzip(file, to) {
|
|
4454
|
-
return new Promise((ok, fail) => {
|
|
4455
|
-
yauzl2.open(file, { lazyEntries: true }, (e, zip) => {
|
|
4456
|
-
if (e || !zip)
|
|
4457
|
-
return fail(e ?? new Error("zip"));
|
|
4458
|
-
zip.on("entry", (en) => {
|
|
4459
|
-
const target = path17.join(to, en.fileName);
|
|
4460
|
-
if (!target.startsWith(to + path17.sep))
|
|
4461
|
-
return fail(new Error("archive path outside the agent folder"));
|
|
4462
|
-
if (en.fileName.endsWith("/"))
|
|
4463
|
-
return fs21.mkdirSync(target, { recursive: true }), zip.readEntry();
|
|
4464
|
-
fs21.mkdirSync(path17.dirname(target), { recursive: true });
|
|
4465
|
-
zip.openReadStream(en, (e2, s) => {
|
|
4466
|
-
if (e2 || !s)
|
|
4467
|
-
return fail(e2 ?? new Error("zip"));
|
|
4468
|
-
const out = fs21.createWriteStream(target);
|
|
4469
|
-
s.pipe(out);
|
|
4470
|
-
out.on("finish", () => zip.readEntry());
|
|
4471
|
-
out.on("error", fail);
|
|
4472
|
-
});
|
|
4473
|
-
});
|
|
4474
|
-
zip.on("end", () => ok());
|
|
4475
|
-
zip.on("error", fail);
|
|
4476
|
-
zip.readEntry();
|
|
4477
|
-
});
|
|
4478
|
-
});
|
|
4479
|
-
}
|
|
4480
|
-
async function untarGz(file, to) {
|
|
4481
|
-
const { gunzipSync } = await import("node:zlib");
|
|
4482
|
-
const data = gunzipSync(await fsp5.readFile(file));
|
|
4483
|
-
const root = path17.resolve(to);
|
|
4484
|
-
const str = (b) => b.toString("utf8").replace(/\0[\s\S]*$/, "");
|
|
4485
|
-
const octal = (b) => Number.parseInt(str(b).trim() || "0", 8) || 0;
|
|
4486
|
-
let off = 0;
|
|
4487
|
-
let longName = null;
|
|
4488
|
-
while (off + 512 <= data.length) {
|
|
4489
|
-
const h = data.subarray(off, off + 512);
|
|
4490
|
-
if (h.every((x) => x === 0))
|
|
4491
|
-
break;
|
|
4492
|
-
const size = octal(h.subarray(124, 136));
|
|
4493
|
-
const type = String.fromCharCode(h[156] || 48);
|
|
4494
|
-
const body = data.subarray(off + 512, off + 512 + size);
|
|
4495
|
-
off += 512 + Math.ceil(size / 512) * 512;
|
|
4496
|
-
const prefix = str(h.subarray(345, 500));
|
|
4497
|
-
let name = longName ?? (prefix ? `${prefix}/${str(h.subarray(0, 100))}` : str(h.subarray(0, 100)));
|
|
4498
|
-
longName = null;
|
|
4499
|
-
if (type === "x") {
|
|
4500
|
-
const m = body.toString("utf8").match(/(?:^|\n)\d+ path=([^\n]*)\n/);
|
|
4501
|
-
if (m)
|
|
4502
|
-
longName = m[1];
|
|
4503
|
-
continue;
|
|
4504
|
-
}
|
|
4505
|
-
if (type === "L") {
|
|
4506
|
-
longName = str(body);
|
|
4507
|
-
continue;
|
|
4508
|
-
}
|
|
4509
|
-
if (type === "g")
|
|
4510
|
-
continue;
|
|
4511
|
-
name = name.replace(/^\.\//, "");
|
|
4512
|
-
if (!name)
|
|
4513
|
-
continue;
|
|
4514
|
-
const target = path17.resolve(root, name);
|
|
4515
|
-
if (target !== root && !target.startsWith(root + path17.sep))
|
|
4516
|
-
throw new Error("archive path outside the agent folder");
|
|
4517
|
-
if (type === "5") {
|
|
4518
|
-
await fsp5.mkdir(target, { recursive: true });
|
|
4519
|
-
continue;
|
|
4520
|
-
}
|
|
4521
|
-
if (type !== "0" && type !== "7")
|
|
4522
|
-
continue;
|
|
4523
|
-
await fsp5.mkdir(path17.dirname(target), { recursive: true });
|
|
4524
|
-
await fsp5.writeFile(target, body, { mode: octal(h.subarray(100, 108)) & 73 ? 493 : 420 });
|
|
4525
|
-
}
|
|
4526
|
-
}
|
|
4527
|
-
function npxRunner(pkg, extra = []) {
|
|
4528
|
-
if (isStandalone())
|
|
4529
|
-
return { cmd: process.execPath, args: ["x", pkg, ...extra], env: { BUN_BE_BUN: "1" } };
|
|
4530
|
-
const npxCli = path17.join(path17.dirname(process.execPath), process.platform === "win32" ? "" : "..", process.platform === "win32" ? "node_modules" : "lib/node_modules", "npm", "bin", "npx-cli.js");
|
|
4531
|
-
if (!fs21.existsSync(npxCli))
|
|
4532
|
-
throw new Error("npx was not found next to Node.js");
|
|
4533
|
-
return { cmd: process.execPath, args: [npxCli, "-y", pkg, ...extra], env: {} };
|
|
4534
|
-
}
|
|
4535
|
-
function ownCopy(a) {
|
|
4536
|
-
const bin = a.distribution.binary?.[platformKey()];
|
|
4537
|
-
if (bin) {
|
|
4538
|
-
const cmd = onPath(path17.basename(bin.cmd).replace(/\.exe$/i, ""));
|
|
4539
|
-
return cmd ? { cmd, args: bin.args ?? [], env: bin.env ?? {} } : null;
|
|
4540
|
-
}
|
|
4541
|
-
const npx = a.distribution.npx;
|
|
4542
|
-
if (npx) {
|
|
4543
|
-
const name = npx.package.replace(/(?!^)@[^@/]*$/, "").split("/").pop() ?? "";
|
|
4544
|
-
const cmd = onPath(name);
|
|
4545
|
-
return cmd ? { cmd, args: npx.args ?? [], env: npx.env ?? {} } : null;
|
|
4546
|
-
}
|
|
4547
|
-
return null;
|
|
4548
|
-
}
|
|
4549
|
-
async function unpackBinary(id, version, bin, progress) {
|
|
4550
|
-
if (!/^[0-9a-f]{64}$/i.test(bin.sha256 || ""))
|
|
4551
|
-
throw new Error(`Agent ${id}: the registry gives no sha256; not installed`);
|
|
4552
|
-
const dir = path17.join(agentDir(), id, version);
|
|
4553
|
-
const tmp = `${dir}.tmp`;
|
|
4554
|
-
await fsp5.rm(tmp, { recursive: true, force: true });
|
|
4555
|
-
await fsp5.mkdir(tmp, { recursive: true });
|
|
4556
|
-
try {
|
|
4557
|
-
const name = path17.basename(new URL(bin.archive).pathname);
|
|
4558
|
-
const cmdRel = bin.cmd.replace(/^\.\//, "");
|
|
4559
|
-
if (/\.zip$/i.test(name)) {
|
|
4560
|
-
const file = path17.join(tmp, ".download.zip");
|
|
4561
|
-
await downloadVerified(bin.archive, bin.sha256.toLowerCase(), file, progress);
|
|
4562
|
-
await unzip(file, tmp);
|
|
4563
|
-
await fsp5.rm(file, { force: true });
|
|
4564
|
-
} else if (/\.(tar\.gz|tgz)$/i.test(name)) {
|
|
4565
|
-
const file = path17.join(tmp, ".download.tar.gz");
|
|
4566
|
-
await downloadVerified(bin.archive, bin.sha256.toLowerCase(), file, progress);
|
|
4567
|
-
await untarGz(file, tmp);
|
|
4568
|
-
await fsp5.rm(file, { force: true });
|
|
4569
|
-
} else if (/\.gz$/i.test(name)) {
|
|
4570
|
-
await downloadVerified(bin.archive, bin.sha256.toLowerCase(), path17.join(tmp, cmdRel), progress, true);
|
|
4571
|
-
} else
|
|
4572
|
-
throw new Error(`Agent ${id}: unsupported archive ${name}`);
|
|
4573
|
-
const cmd = path17.join(tmp, cmdRel);
|
|
4574
|
-
if (!fs21.existsSync(cmd))
|
|
4575
|
-
throw new Error(`Agent ${id}: ${bin.cmd} is not in the download`);
|
|
4576
|
-
if (process.platform !== "win32")
|
|
4577
|
-
await fsp5.chmod(cmd, 493);
|
|
4578
|
-
await fsp5.rm(dir, { recursive: true, force: true });
|
|
4579
|
-
await fsp5.rename(tmp, dir);
|
|
4580
|
-
return { cmd: path17.join(dir, cmdRel), args: bin.args ?? [], env: bin.env ?? {} };
|
|
4581
|
-
} catch (e) {
|
|
4582
|
-
await fsp5.rm(tmp, { recursive: true, force: true });
|
|
4583
|
-
throw e;
|
|
4584
|
-
}
|
|
4585
|
-
}
|
|
4586
|
-
var codexAcpRelease = () => process.env.HYPEFRAME_CODEX_ACP_RELEASE || "https://api.github.com/repos/zed-industries/codex-acp/releases/latest";
|
|
4587
|
-
async function codexAcpBuild(arch) {
|
|
4588
|
-
const j = await (await fetch(codexAcpRelease(), { headers: { accept: "application/vnd.github+json", "user-agent": "hypeframe" }, signal: AbortSignal.timeout(20000) })).json();
|
|
4589
|
-
const triple = arch === "x64" ? "x86_64" : "aarch64";
|
|
4590
|
-
const asset = (j.assets ?? []).find((x) => new RegExp(`${triple}-unknown-linux-musl\\.tar\\.gz$`).test(String(x.name)));
|
|
4591
|
-
const sha256 = /^sha256:([0-9a-f]{64})$/i.exec(String(asset?.digest ?? ""))?.[1];
|
|
4592
|
-
const url = String(asset?.browser_download_url ?? "");
|
|
4593
|
-
if (!asset || !sha256 || !url)
|
|
4594
|
-
throw new Error("codex-acp: no checked Linux build for this phone");
|
|
4595
|
-
if (!process.env.HYPEFRAME_CODEX_ACP_RELEASE && !url.startsWith("https://github.com/"))
|
|
4596
|
-
throw new Error("codex-acp: unexpected download address");
|
|
4597
|
-
return { url, sha256: sha256.toLowerCase(), version: String(j.tag_name ?? "latest").replace(/^v/, "") };
|
|
4598
|
-
}
|
|
4599
|
-
var findFile = (dir, name) => {
|
|
4600
|
-
for (const n of fs21.readdirSync(dir)) {
|
|
4601
|
-
const f = path17.join(dir, n);
|
|
4602
|
-
const st = fs21.lstatSync(f);
|
|
4603
|
-
if (st.isFile() && n === name)
|
|
4604
|
-
return f;
|
|
4605
|
-
if (st.isDirectory()) {
|
|
4606
|
-
const inner = findFile(f, name);
|
|
4607
|
-
if (inner)
|
|
4608
|
-
return inner;
|
|
4609
|
-
}
|
|
4610
|
-
}
|
|
4611
|
-
return null;
|
|
4612
|
-
};
|
|
4613
|
-
async function installInLinux(a, id, progress, steps, arch) {
|
|
4614
|
-
steps.prepare();
|
|
4615
|
-
if (id === "antigravity-acp") {
|
|
4616
|
-
if (!steps.run("(test -x /root/.local/bin/agy || curl -fsSL https://antigravity.google/cli/install.sh | bash) && test -x /root/.local/bin/agy"))
|
|
4617
|
-
throw new Error("Antigravity: Google's installer did not finish in the Linux mini, or agy is not at /root/.local/bin/agy");
|
|
4618
|
-
return { launch: { cmd: "/root/.local/bin/agy", args: ["acp"], env: {}, linux: true }, version: a.version };
|
|
4619
|
-
}
|
|
4620
|
-
if (id === "codex-acp") {
|
|
4621
|
-
const b = await codexAcpBuild(arch);
|
|
4622
|
-
const dir = path17.join(agentDir(), id, b.version);
|
|
4623
|
-
const tmp = `${dir}.tmp`;
|
|
4624
|
-
await fsp5.rm(tmp, { recursive: true, force: true });
|
|
4625
|
-
await fsp5.mkdir(tmp, { recursive: true });
|
|
4626
|
-
try {
|
|
4627
|
-
const file = path17.join(tmp, ".download.tar.gz");
|
|
4628
|
-
await downloadVerified(b.url, b.sha256, file, progress);
|
|
4629
|
-
await untarGz(file, tmp);
|
|
4630
|
-
await fsp5.rm(file, { force: true });
|
|
4631
|
-
const found = findFile(tmp, "codex-acp");
|
|
4632
|
-
if (!found)
|
|
4633
|
-
throw new Error("codex-acp: the program is not in the download");
|
|
4634
|
-
const rel = path17.relative(tmp, found);
|
|
4635
|
-
await fsp5.chmod(found, 493);
|
|
4636
|
-
await fsp5.rm(dir, { recursive: true, force: true });
|
|
4637
|
-
await fsp5.rename(tmp, dir);
|
|
4638
|
-
return { launch: { cmd: path17.join(dir, rel), args: [], env: {}, linux: true }, version: b.version };
|
|
4639
|
-
} catch (e) {
|
|
4640
|
-
await fsp5.rm(tmp, { recursive: true, force: true });
|
|
4641
|
-
throw e;
|
|
4642
|
-
}
|
|
4643
|
-
}
|
|
4644
|
-
const bin = a.distribution.binary?.[`linux-${arch === "x64" ? "x86_64" : "aarch64"}`];
|
|
4645
|
-
if (!bin)
|
|
4646
|
-
throw new Error(`Agent ${id} has no Linux build to run on this phone`);
|
|
4647
|
-
return { launch: { ...await unpackBinary(id, a.version, bin, progress), linux: true }, version: a.version };
|
|
4648
|
-
}
|
|
4649
|
-
async function installAgent(id, progress = () => {
|
|
4650
|
-
return;
|
|
4651
|
-
}, opts = {}) {
|
|
4652
|
-
const a = (await fetchRegistry()).find((x) => x.id === id);
|
|
4653
|
-
if (!a)
|
|
4654
|
-
throw new Error(`Agent ${id} is not in the registry`);
|
|
4655
|
-
const local = a.distribution.local;
|
|
4656
|
-
if (!isSupported(id) && !local)
|
|
4657
|
-
throw new Error(`Agent ${id} is not supported`);
|
|
4658
|
-
if (!local && (opts.android ?? isAndroid())) {
|
|
4659
|
-
const steps = opts.linux ?? { prepare: () => prepareLinux(opts.say), run: runInLinux };
|
|
4660
|
-
const r = await installInLinux(a, id, progress, steps, opts.arch ?? process.arch);
|
|
4661
|
-
const installed = { id, name: a.name, version: r.version, launch: r.launch };
|
|
4662
|
-
writeInstalled(installed);
|
|
4663
|
-
return installed;
|
|
4664
|
-
}
|
|
4665
|
-
let launch;
|
|
4666
|
-
const bin = a.distribution.binary?.[platformKey()];
|
|
4667
|
-
const own = local || opts.download ? null : ownCopy(a);
|
|
4668
|
-
if (local) {
|
|
4669
|
-
launch = { cmd: local.cmd, args: local.args ?? [], env: {} };
|
|
4670
|
-
} else if (own) {
|
|
4671
|
-
launch = own;
|
|
4672
|
-
} else if (bin) {
|
|
4673
|
-
launch = await unpackBinary(id, a.version, bin, progress);
|
|
4674
|
-
} else if (a.distribution.npx) {
|
|
4675
|
-
launch = { ...npxRunner(a.distribution.npx.package, a.distribution.npx.args), env: { ...a.distribution.npx.env ?? {} } };
|
|
4676
|
-
if (isStandalone())
|
|
4677
|
-
launch.env.BUN_BE_BUN = "1";
|
|
4678
|
-
} else
|
|
4679
|
-
throw new Error(`Agent ${id} has no download for ${platformKey()}`);
|
|
4680
|
-
const installed = { id, name: a.name, version: a.version, launch, ...own ? { own: true } : {} };
|
|
4681
|
-
writeInstalled(installed);
|
|
4682
|
-
return installed;
|
|
4683
|
-
}
|
|
4684
|
-
|
|
4685
|
-
// packages/hypeframe/src/cli/commands/agent.ts
|
|
4686
5068
|
var NAMES = { "antigravity-acp": "Antigravity", "codex-acp": "Codex", opencode: "OpenCode" };
|
|
4687
5069
|
var agentName = (id) => NAMES[id] ?? readInstalled().find((a) => a.id === id)?.name ?? id;
|
|
4688
5070
|
var ALIASES = { codex: "codex-acp", antigravity: "antigravity-acp", agy: "antigravity-acp", gemini: "antigravity-acp", opencode: "opencode" };
|
|
@@ -4955,9 +5337,9 @@ async function config(args) {
|
|
|
4955
5337
|
}
|
|
4956
5338
|
|
|
4957
5339
|
// packages/hypeframe/src/cli/commands/doctor.ts
|
|
4958
|
-
import { spawnSync as
|
|
4959
|
-
import
|
|
4960
|
-
import
|
|
5340
|
+
import { spawnSync as spawnSync5 } from "node:child_process";
|
|
5341
|
+
import fs23 from "node:fs";
|
|
5342
|
+
import path19 from "node:path";
|
|
4961
5343
|
var mark = { ok: color.ok(icon.ok), warn: color.warn(icon.warn), error: color.error(icon.error) };
|
|
4962
5344
|
async function reach(url) {
|
|
4963
5345
|
const t0 = Date.now();
|
|
@@ -4986,10 +5368,10 @@ async function doctor(args) {
|
|
|
4986
5368
|
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")}` : ""}` });
|
|
4987
5369
|
}
|
|
4988
5370
|
try {
|
|
4989
|
-
const probe =
|
|
4990
|
-
|
|
4991
|
-
|
|
4992
|
-
const st =
|
|
5371
|
+
const probe = path19.join(dataDir(), `.probe-${process.pid}`);
|
|
5372
|
+
fs23.writeFileSync(probe, "x");
|
|
5373
|
+
fs23.rmSync(probe);
|
|
5374
|
+
const st = fs23.statfsSync(dataDir());
|
|
4993
5375
|
const free = st.bavail * st.bsize;
|
|
4994
5376
|
show({ label: t("doctor.disk"), result: free > 2 * 1024 ** 3 ? "ok" : "warn", detail: `${dataDir()} ${color.muted(icon.dot)} ${t("doctor.free", { size: bytes2(free) })}` });
|
|
4995
5377
|
} catch (e) {
|
|
@@ -5000,7 +5382,7 @@ async function doctor(args) {
|
|
|
5000
5382
|
const canDownload = !!FFMPEG_PINNED[`${process.platform}-${process.arch}`];
|
|
5001
5383
|
show({ label: "ffmpeg", result: canDownload ? "warn" : "error", detail: canDownload ? t("doctor.ffmpegLater") : t("doctor.noFfmpeg") });
|
|
5002
5384
|
} else {
|
|
5003
|
-
const r =
|
|
5385
|
+
const r = spawnSync5(ff, ["-hide_banner", "-version"], { encoding: "utf8", timeout: 15000 });
|
|
5004
5386
|
const v = /ffmpeg version (\S+)/.exec(r.stdout || "")?.[1];
|
|
5005
5387
|
show({ label: "ffmpeg", result: v ? "ok" : "error", detail: v || t("doctor.noFfmpeg") });
|
|
5006
5388
|
}
|
|
@@ -5036,21 +5418,21 @@ async function doctor(args) {
|
|
|
5036
5418
|
}
|
|
5037
5419
|
|
|
5038
5420
|
// packages/hypeframe/src/cli/commands/history.ts
|
|
5039
|
-
import
|
|
5040
|
-
import
|
|
5421
|
+
import fs24 from "node:fs";
|
|
5422
|
+
import path20 from "node:path";
|
|
5041
5423
|
function readHistory2(hours = 24) {
|
|
5042
5424
|
const root = renderDir();
|
|
5043
5425
|
const since = Date.now() - hours * 3600000;
|
|
5044
5426
|
const out = [];
|
|
5045
|
-
for (const name of
|
|
5427
|
+
for (const name of fs24.readdirSync(root)) {
|
|
5046
5428
|
if (!JOB_ID.test(name))
|
|
5047
5429
|
continue;
|
|
5048
5430
|
try {
|
|
5049
|
-
const j = JSON.parse(
|
|
5431
|
+
const j = JSON.parse(fs24.readFileSync(path20.join(root, name, "status.json"), "utf8"));
|
|
5050
5432
|
if ((j.diperbarui || j.dibuat) < since)
|
|
5051
5433
|
continue;
|
|
5052
|
-
const f = j.hasilBerkas ?
|
|
5053
|
-
out.push({ job: j, file: f &&
|
|
5434
|
+
const f = j.hasilBerkas ? path20.join(root, name, j.hasilBerkas) : null;
|
|
5435
|
+
out.push({ job: j, file: f && fs24.existsSync(f) ? f : null });
|
|
5054
5436
|
} catch {}
|
|
5055
5437
|
}
|
|
5056
5438
|
return out.sort((a, b) => (b.job.diperbarui || 0) - (a.job.diperbarui || 0));
|
|
@@ -5076,31 +5458,31 @@ function history() {
|
|
|
5076
5458
|
}
|
|
5077
5459
|
|
|
5078
5460
|
// packages/hypeframe/src/cli/commands/maintenance.ts
|
|
5079
|
-
import { spawnSync as
|
|
5080
|
-
import
|
|
5081
|
-
import
|
|
5082
|
-
import
|
|
5461
|
+
import { spawnSync as spawnSync6 } from "node:child_process";
|
|
5462
|
+
import fs25 from "node:fs";
|
|
5463
|
+
import os5 from "node:os";
|
|
5464
|
+
import path21 from "node:path";
|
|
5083
5465
|
async function clean() {
|
|
5084
5466
|
if (runningPid()) {
|
|
5085
5467
|
log.warn(t("clean.running"));
|
|
5086
5468
|
return;
|
|
5087
5469
|
}
|
|
5088
|
-
const targets = [
|
|
5089
|
-
for (const job of
|
|
5470
|
+
const targets = [path21.join(cacheDir(), "chrome"), path21.join(cacheDir(), "halaman"), path21.join(logDir(), "hypeframe.log.1")];
|
|
5471
|
+
for (const job of fs25.readdirSync(renderDir())) {
|
|
5090
5472
|
if (!JOB_ID.test(job))
|
|
5091
5473
|
continue;
|
|
5092
5474
|
try {
|
|
5093
|
-
const s = JSON.parse(
|
|
5475
|
+
const s = JSON.parse(fs25.readFileSync(path21.join(renderDir(), job, "status.json"), "utf8")).status;
|
|
5094
5476
|
if (s === "gagal" || s === "batal" || s === "unggah")
|
|
5095
|
-
targets.push(
|
|
5477
|
+
targets.push(path21.join(renderDir(), job));
|
|
5096
5478
|
} catch {
|
|
5097
|
-
targets.push(
|
|
5479
|
+
targets.push(path21.join(renderDir(), job));
|
|
5098
5480
|
}
|
|
5099
5481
|
}
|
|
5100
5482
|
let freed = 0;
|
|
5101
5483
|
for (const p of targets) {
|
|
5102
5484
|
freed += await sizeOf(p);
|
|
5103
|
-
|
|
5485
|
+
fs25.rmSync(p, { recursive: true, force: true });
|
|
5104
5486
|
}
|
|
5105
5487
|
log.ok(t("clean.done", { size: bytes2(freed) }));
|
|
5106
5488
|
}
|
|
@@ -5109,7 +5491,7 @@ function report() {
|
|
|
5109
5491
|
const a = readAccount();
|
|
5110
5492
|
let recent = "";
|
|
5111
5493
|
try {
|
|
5112
|
-
recent =
|
|
5494
|
+
recent = fs25.readFileSync(path21.join(logDir(), "hypeframe.log"), "utf8").split(`
|
|
5113
5495
|
`).slice(-400).join(`
|
|
5114
5496
|
`);
|
|
5115
5497
|
} catch {
|
|
@@ -5118,7 +5500,7 @@ function report() {
|
|
|
5118
5500
|
const lines = [
|
|
5119
5501
|
`hypeframe ${VERSION}`,
|
|
5120
5502
|
`created ${new Date().toISOString()}`,
|
|
5121
|
-
`${runtimeLabel()} · ${process.platform} ${
|
|
5503
|
+
`${runtimeLabel()} · ${process.platform} ${os5.release()} ${process.arch} · ${os5.cpus()[0]?.model ?? "?"} ×${os5.cpus().length} · ${bytes2(os5.totalmem())} RAM`,
|
|
5122
5504
|
`gateway ${s.gateway}`,
|
|
5123
5505
|
`web ${s.web}`,
|
|
5124
5506
|
`gpu ${s.gpu}`,
|
|
@@ -5130,8 +5512,8 @@ function report() {
|
|
|
5130
5512
|
recent
|
|
5131
5513
|
];
|
|
5132
5514
|
const stamp = new Date().toISOString().slice(0, 19).replace(/[-:T]/g, "");
|
|
5133
|
-
const file =
|
|
5134
|
-
|
|
5515
|
+
const file = path21.join(dataDir(), `laporan-${stamp}.txt`);
|
|
5516
|
+
fs25.writeFileSync(file, mask(lines.join(`
|
|
5135
5517
|
`)), { mode: 384 });
|
|
5136
5518
|
log.ok(t("report.done", { file }));
|
|
5137
5519
|
log.detail(t("report.hint"));
|
|
@@ -5152,7 +5534,7 @@ function update() {
|
|
|
5152
5534
|
}
|
|
5153
5535
|
log.info(t("update.running"));
|
|
5154
5536
|
const [cmd, args, extra] = updateCommand({ standalone: isStandalone(), android: isAndroid(), windows: process.platform === "win32" });
|
|
5155
|
-
const r =
|
|
5537
|
+
const r = spawnSync6(cmd, args, { stdio: "inherit", ...extra });
|
|
5156
5538
|
if (r.status === 0)
|
|
5157
5539
|
log.ok(t("update.done"));
|
|
5158
5540
|
else
|
|
@@ -5167,13 +5549,13 @@ function openWeb(args) {
|
|
|
5167
5549
|
}
|
|
5168
5550
|
|
|
5169
5551
|
// packages/hypeframe/src/cli/commands/status.ts
|
|
5170
|
-
import
|
|
5171
|
-
import
|
|
5552
|
+
import fs26 from "node:fs";
|
|
5553
|
+
import path22 from "node:path";
|
|
5172
5554
|
function statusRows(args) {
|
|
5173
5555
|
const s = resolveSettings(args?.flags);
|
|
5174
5556
|
const a = readAccount();
|
|
5175
5557
|
const pid = runningPid();
|
|
5176
|
-
const chrome = findChrome() ||
|
|
5558
|
+
const chrome = findChrome() || fs26.existsSync(path22.join(cacheDir(), "chrome"));
|
|
5177
5559
|
const recent = readHistory2();
|
|
5178
5560
|
const k = (key) => color.muted(t(key));
|
|
5179
5561
|
return [
|