hypeframe 0.8.0 → 0.8.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +365 -84
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -102,30 +102,53 @@ function maskEmail(email) {
102
102
  }
103
103
 
104
104
  // src/config/settings.ts
105
- import fs3 from "node:fs";
105
+ import fs4 from "node:fs";
106
106
  import os2 from "node:os";
107
+
108
+ // src/util/which.ts
109
+ import fs3 from "node:fs";
110
+ import path2 from "node:path";
111
+ function isAndroid() {
112
+ return process.platform === "android" || !!process.env.TERMUX_VERSION || (process.env.PREFIX ?? "").includes("/com.termux/");
113
+ }
114
+ function onPath(name) {
115
+ if (!/^[\w.@+-]{1,80}$/.test(name))
116
+ return null;
117
+ const file = process.platform === "win32" ? /\.exe$/i.test(name) ? name : `${name}.exe` : name;
118
+ for (const dir of (process.env.PATH || "").split(path2.delimiter).filter(Boolean)) {
119
+ const f = path2.join(dir, file);
120
+ try {
121
+ const st = fs3.statSync(f);
122
+ if (st.isFile() && (process.platform === "win32" || st.mode & 73))
123
+ return f;
124
+ } catch {}
125
+ }
126
+ return null;
127
+ }
128
+
129
+ // src/config/settings.ts
107
130
  var DEFAULT_GATEWAY = "https://api.sairipedia.com";
108
131
  var DEFAULT_WEB = "https://hype-frame.com";
109
132
  function readSettings() {
110
133
  try {
111
- return JSON.parse(fs3.readFileSync(settingsFile(), "utf8"));
134
+ return JSON.parse(fs4.readFileSync(settingsFile(), "utf8"));
112
135
  } catch {
113
136
  return {};
114
137
  }
115
138
  }
116
139
  function saveSettings(s) {
117
140
  const f = settingsFile();
118
- fs3.writeFileSync(`${f}.tmp`, JSON.stringify({ ...readSettings(), ...s }, null, 2), { mode: 384 });
119
- fs3.renameSync(`${f}.tmp`, f);
141
+ fs4.writeFileSync(`${f}.tmp`, JSON.stringify({ ...readSettings(), ...s }, null, 2), { mode: 384 });
142
+ fs4.renameSync(`${f}.tmp`, f);
120
143
  }
121
- function resolveSettings(flags = {}) {
144
+ function resolveSettings(flags = {}, android = isAndroid()) {
122
145
  const s = readSettings();
123
146
  const clean = (u) => u.replace(/\/+$/, "");
124
147
  return {
125
148
  gateway: clean(flags.gateway || process.env.HYPEFRAME_GATEWAY_URL || s.gateway || DEFAULT_GATEWAY),
126
149
  web: clean(flags.web || process.env.HYPEFRAME_WEB_URL || s.web || DEFAULT_WEB),
127
150
  name: (flags.name || s.name || os2.hostname()).slice(0, 40),
128
- gpu: flags.gpu ?? s.gpu ?? false
151
+ gpu: android ? false : flags.gpu ?? s.gpu ?? false
129
152
  };
130
153
  }
131
154
  function osName() {
@@ -269,7 +292,29 @@ Tekan Esc untuk melewati satu langkah. Panduan ini bisa dibuka lagi dari Bantuan
269
292
  "agent.needLogin": "perlu masuk akun",
270
293
  "agent.notInstalled": "belum dipasang",
271
294
  "agent.add": "Pasang dan masuk akun",
272
- "agent.login": "Masuk akun lagi (ganti akun)",
295
+ "agent.login": "Ganti akun (keluar, lalu masuk dengan akun lain)",
296
+ "agent.logout": "Keluar akun",
297
+ "agent.ownApi": "Pakai URL API sendiri (alamat + kunci API)",
298
+ "agent.ownApiChange": "Ganti API sendiri ({host})",
299
+ "agent.ownApiOff": "Berhenti memakai API sendiri",
300
+ "agent.ownApiOffDone": "OpenCode kembali memakai penyedia bawaannya.",
301
+ "agent.ownApiTag": "API sendiri ({host})",
302
+ "agent.apiUrl": "Alamat API (kompatibel OpenAI, biasanya berakhiran /v1)",
303
+ "agent.apiUrlBad": "Alamat harus diawali http:// atau https://",
304
+ "agent.apiKey": "Kunci API (kosongkan kalau servernya tidak memakai kunci)",
305
+ "agent.apiModelsLoading": "Mengambil daftar model dari alamat itu...",
306
+ "agent.apiModelsFound": "{n} model ditemukan",
307
+ "agent.apiModelsNone": "Daftar model tidak bisa diambil, ketik nama modelnya",
308
+ "agent.apiModel": "Model utama (model lain di daftar tetap bisa dipilih di HypeFrame Web)",
309
+ "agent.apiModelType": "Nama model persis seperti di penyedianya (mis. gpt-4o-mini)",
310
+ "agent.apiSaved": "OpenCode memakai {host}, model {model}. Kunci disimpan di perangkat ini saja.",
311
+ "agent.apiNotReady": "OpenCode belum bisa membuka obrolan dengan API ini. Periksa alamat, kunci, dan nama modelnya, lalu coba lagi.",
312
+ "agent.logoutAsk": "Keluar dari akun {name} di perangkat ini?",
313
+ "agent.loggingOut": "Keluar dari akun {name}...",
314
+ "agent.loggedOut": "{name} sudah keluar akun. Pilih Masuk akun untuk memakai akun lain.",
315
+ "agent.keyRemoved": "Kunci {name} yang disimpan HypeFrame sudah dihapus.",
316
+ "agent.logoutUnsupported": "{name} tidak menyediakan keluar akun dari luar aplikasinya. Pilih Ganti akun: masuk dengan akun lain menggantikan akun lama.",
317
+ "agent.logoutRestart": "Mesin sedang menyala: matikan lalu nyalakan lagi supaya {name} berhenti memakai akun lama.",
273
318
  "agent.remove": "Hapus dari perangkat ini",
274
319
  "agent.back": "Kembali",
275
320
  "agent.installing": "Memasang {name} dari daftar resmi ACP...",
@@ -336,6 +381,7 @@ Tekan Esc untuk melewati satu langkah. Panduan ini bisa dibuka lagi dari Bantuan
336
381
  "doctor.ffmpegLater": "belum ada; diunduh otomatis saat mesin menyala",
337
382
  "doctor.alpha": "Klip transparan",
338
383
  "doctor.alphaNo": "tidak didukung Chrome ini; dibuat di server atau HP",
384
+ "doctor.tryChromiumMini": "Chromium Termux belum bisa render di HP ini. Coba Chromium di Linux mini: hypeframe chromium",
339
385
  "doctor.yes": "bisa",
340
386
  "doctor.no": "tidak bisa",
341
387
  "doctor.unreachable": "tidak terjangkau",
@@ -516,7 +562,29 @@ Press Esc to skip a step. You can open this guide again from Help & maintenance.
516
562
  "agent.needLogin": "needs login",
517
563
  "agent.notInstalled": "not installed",
518
564
  "agent.add": "Install and log in",
519
- "agent.login": "Log in again (switch account)",
565
+ "agent.login": "Switch account (sign out, then sign in with another account)",
566
+ "agent.logout": "Sign out",
567
+ "agent.ownApi": "Use your own API URL (address + API key)",
568
+ "agent.ownApiChange": "Change own API ({host})",
569
+ "agent.ownApiOff": "Stop using own API",
570
+ "agent.ownApiOffDone": "OpenCode is back on its own providers.",
571
+ "agent.ownApiTag": "own API ({host})",
572
+ "agent.apiUrl": "API address (OpenAI-compatible, usually ending in /v1)",
573
+ "agent.apiUrlBad": "The address must start with http:// or https://",
574
+ "agent.apiKey": "API key (leave empty if the server needs none)",
575
+ "agent.apiModelsLoading": "Getting the model list from that address...",
576
+ "agent.apiModelsFound": "{n} models found",
577
+ "agent.apiModelsNone": "Could not get the model list, type the model name",
578
+ "agent.apiModel": "Main model (the other models in the list stay pickable in HypeFrame Web)",
579
+ "agent.apiModelType": "Model name exactly as the provider calls it (e.g. gpt-4o-mini)",
580
+ "agent.apiSaved": "OpenCode uses {host}, model {model}. The key is kept on this device only.",
581
+ "agent.apiNotReady": "OpenCode cannot open a chat with this API yet. Check the address, key and model name, then try again.",
582
+ "agent.logoutAsk": "Sign out of {name} on this device?",
583
+ "agent.loggingOut": "Signing out of {name}...",
584
+ "agent.loggedOut": "{name} is signed out. Pick Log in to use another account.",
585
+ "agent.keyRemoved": "The {name} key saved by HypeFrame was removed.",
586
+ "agent.logoutUnsupported": "{name} offers no sign-out from outside its own app. Pick Switch account: signing in with another account replaces the old one.",
587
+ "agent.logoutRestart": "The engine is running: stop it and start it again so {name} stops using the old account.",
520
588
  "agent.remove": "Remove from this device",
521
589
  "agent.back": "Back",
522
590
  "agent.installing": "Installing {name} from the official ACP registry...",
@@ -583,6 +651,7 @@ Press Esc to skip a step. You can open this guide again from Help & maintenance.
583
651
  "doctor.ffmpegLater": "not yet; downloaded automatically when the engine starts",
584
652
  "doctor.alpha": "Transparent clips",
585
653
  "doctor.alphaNo": "not supported by this Chrome; made on the server or phone",
654
+ "doctor.tryChromiumMini": "Termux's Chromium cannot render on this phone yet. Try Chromium in the Linux mini: hypeframe chromium",
586
655
  "doctor.yes": "yes",
587
656
  "doctor.no": "no",
588
657
  "doctor.unreachable": "unreachable",
@@ -647,8 +716,8 @@ function t(key, vars = {}) {
647
716
  }
648
717
 
649
718
  // src/ui/log.ts
650
- import fs4 from "node:fs";
651
- import path2 from "node:path";
719
+ import fs5 from "node:fs";
720
+ import path3 from "node:path";
652
721
 
653
722
  // src/ui/theme.ts
654
723
  import picocolors from "picocolors";
@@ -691,13 +760,13 @@ var MAX_FILE = 1024 * 1024;
691
760
  var fileReady = false;
692
761
  function toFile(line) {
693
762
  try {
694
- const f = path2.join(logDir(), "hypeframe.log");
763
+ const f = path3.join(logDir(), "hypeframe.log");
695
764
  if (!fileReady) {
696
765
  fileReady = true;
697
- if (fs4.existsSync(f) && fs4.statSync(f).size > MAX_FILE)
698
- fs4.renameSync(f, `${f}.1`);
766
+ if (fs5.existsSync(f) && fs5.statSync(f).size > MAX_FILE)
767
+ fs5.renameSync(f, `${f}.1`);
699
768
  }
700
- fs4.appendFileSync(f, `${new Date().toISOString()} ${line}
769
+ fs5.appendFileSync(f, `${new Date().toISOString()} ${line}
701
770
  `, { mode: 384 });
702
771
  } catch {}
703
772
  }
@@ -756,7 +825,7 @@ import path7 from "node:path";
756
825
  // package.json
757
826
  var package_default = {
758
827
  name: "hypeframe",
759
- version: "0.8.0",
828
+ version: "0.8.2",
760
829
  description: "Local engine for HypeFrame Web: code clips, video renders and AI agents run on your own machine; the web is just the view.",
761
830
  keywords: [
762
831
  "hypeframe",
@@ -824,14 +893,14 @@ You are running on the user's computer through the HypeFrame engine. The user ty
824
893
 
825
894
  // src/agent/registry.ts
826
895
  import { spawnSync } from "node:child_process";
827
- import fs5 from "node:fs";
896
+ import fs6 from "node:fs";
828
897
  var SUPPORTED_AGENTS = ["antigravity-acp", "codex-acp", "opencode"];
829
898
  var isSupported = (id) => SUPPORTED_AGENTS.includes(id);
830
899
  var OFFICIAL_REGISTRY = "https://cdn.agentclientprotocol.com/registry/v1/latest/registry.json";
831
900
  var registryUrl = () => process.env.HYPEFRAME_ACP_REGISTRY || OFFICIAL_REGISTRY;
832
901
  var isLocalRegistry = (u) => u.startsWith("file:") || /^http:\/\/127\.0\.0\.1[:/]/.test(u);
833
902
  function isMusl() {
834
- if (fs5.existsSync("/etc/alpine-release"))
903
+ if (fs6.existsSync("/etc/alpine-release"))
835
904
  return true;
836
905
  const r = spawnSync("ldd", ["--version"], { encoding: "utf8" });
837
906
  return /musl/i.test(`${r.stdout ?? ""}${r.stderr ?? ""}`);
@@ -848,7 +917,7 @@ function valid(a) {
848
917
  }
849
918
  async function fetchRegistry() {
850
919
  const u = registryUrl();
851
- const text = u.startsWith("file:") ? fs5.readFileSync(new URL(u), "utf8") : await (await fetch(u, { signal: AbortSignal.timeout(20000) })).text();
920
+ const text = u.startsWith("file:") ? fs6.readFileSync(new URL(u), "utf8") : await (await fetch(u, { signal: AbortSignal.timeout(20000) })).text();
852
921
  const j = JSON.parse(text);
853
922
  const local = isLocalRegistry(u);
854
923
  return (Array.isArray(j.agents) ? j.agents : []).filter(valid).map((a) => local ? a : { ...a, distribution: { ...a.distribution, local: undefined } });
@@ -859,29 +928,6 @@ import { spawnSync as spawnSync2 } from "node:child_process";
859
928
  import crypto from "node:crypto";
860
929
  import fs7 from "node:fs";
861
930
  import path4 from "node:path";
862
-
863
- // src/util/which.ts
864
- import fs6 from "node:fs";
865
- import path3 from "node:path";
866
- function isAndroid() {
867
- return process.platform === "android" || !!process.env.TERMUX_VERSION || (process.env.PREFIX ?? "").includes("/com.termux/");
868
- }
869
- function onPath(name) {
870
- if (!/^[\w.@+-]{1,80}$/.test(name))
871
- return null;
872
- const file = process.platform === "win32" ? /\.exe$/i.test(name) ? name : `${name}.exe` : name;
873
- for (const dir of (process.env.PATH || "").split(path3.delimiter).filter(Boolean)) {
874
- const f = path3.join(dir, file);
875
- try {
876
- const st = fs6.statSync(f);
877
- if (st.isFile() && (process.platform === "win32" || st.mode & 73))
878
- return f;
879
- } catch {}
880
- }
881
- return null;
882
- }
883
-
884
- // src/agent/linux.ts
885
931
  var DISTRO = "ubuntu";
886
932
  function linuxDir() {
887
933
  const d = path4.join(dataDir(), "linux");
@@ -1283,8 +1329,14 @@ class AgentSessions {
1283
1329
  const proc = new AcpProcess;
1284
1330
  proc.onRequest = (m, p) => this.fromAgent(agentId, m, p);
1285
1331
  proc.onNotification = (m, p) => {
1286
- if (m === "session/update")
1287
- this.queue(`${agentId}/${String(p?.sessionId ?? "")}`, p?.update);
1332
+ if (m !== "session/update")
1333
+ return;
1334
+ const key = `${agentId}/${String(p?.sessionId ?? "")}`;
1335
+ const u = p?.update;
1336
+ const s = this.sessions.get(key);
1337
+ if (s && /^config_options?_update$/.test(String(u?.sessionUpdate ?? "")) && Array.isArray(u?.configOptions))
1338
+ s.opsi = { ...s.opsi, configOptions: safeConfig(u.configOptions) };
1339
+ this.queue(key, u);
1288
1340
  };
1289
1341
  proc.on("exit", (code) => {
1290
1342
  if (this.procs.get(agentId)?.proc === proc)
@@ -1385,9 +1437,17 @@ class AgentSessions {
1385
1437
  const e = this.procs.get(s.agentId);
1386
1438
  if (!e)
1387
1439
  throw new Error("Agent stopped");
1388
- const id = String(o.id ?? "").slice(0, 100);
1440
+ let id = String(o.id ?? "").slice(0, 100);
1389
1441
  const value = String(o.nilai ?? "").slice(0, 200);
1390
- const config = s.opsi?.configOptions?.find((c) => c.id === id);
1442
+ const current = s.opsi?.configOptions ?? [];
1443
+ let config = current.find((c) => c.id === id);
1444
+ if (!config && current.length && o.jenis !== "model" && o.jenis !== "mode") {
1445
+ const hint = String(o.nama ?? "").trim().toLowerCase();
1446
+ config = hint ? current.find((c) => String(c.name ?? "").trim().toLowerCase() === hint || String(c.category ?? "").toLowerCase() === hint) : undefined;
1447
+ if (!config)
1448
+ throw new Error("This choice is no longer offered by the agent. Start a new chat to see its current choices.");
1449
+ id = String(config.id);
1450
+ }
1391
1451
  const modeLike = o.jenis === "mode" || o.jenis !== "model" && (isModeOption(config) || /mode/i.test(id));
1392
1452
  if (modeLike && UNSAFE_MODE.test(value))
1393
1453
  throw new Error("A mode that skips asking is not allowed in HypeFrame");
@@ -1541,6 +1601,22 @@ function agentEnv(id) {
1541
1601
  return {};
1542
1602
  }
1543
1603
  }
1604
+ var SECRET_NAME = /KEY|TOKEN|SECRET|PASSWORD/i;
1605
+ function forgetAgentSecrets(id) {
1606
+ const gone = Object.keys(agentEnv(id)).filter((k) => SECRET_NAME.test(k));
1607
+ removeAgentEnv(id, gone);
1608
+ return gone;
1609
+ }
1610
+ function removeAgentEnv(id, names) {
1611
+ const env = agentEnv(id);
1612
+ if (!names.some((k) => (k in env)))
1613
+ return;
1614
+ for (const k of names)
1615
+ delete env[k];
1616
+ const f = path6.join(folder(id), "env.json");
1617
+ fs9.writeFileSync(`${f}.tmp`, JSON.stringify(env), { mode: 384 });
1618
+ fs9.renameSync(`${f}.tmp`, f);
1619
+ }
1544
1620
  function saveAgentEnv(id, env) {
1545
1621
  fs9.mkdirSync(folder(id), { recursive: true });
1546
1622
  const f = path6.join(folder(id), "env.json");
@@ -1836,7 +1912,7 @@ function createAgentService(o) {
1836
1912
  const macam = text(c, "macam");
1837
1913
  if (!["model", "mode", "opsi"].includes(macam))
1838
1914
  throw new Error("Pilihan tidak dikenal.");
1839
- const r = await sessions.setOption(text(c, "sessionId"), { jenis: macam, id: text(c, "id"), nilai: text(c, "nilai") });
1915
+ const r = await sessions.setOption(text(c, "sessionId"), { jenis: macam, id: text(c, "id"), nilai: text(c, "nilai"), nama: text(c, "nama") });
1840
1916
  emit({ type: "option", agent: nameOf(sessions.agentOf(text(c, "sessionId"))), what: macam === "opsi" ? text(c, "id") : macam, value: text(c, "nilai") });
1841
1917
  return r;
1842
1918
  },
@@ -2335,8 +2411,49 @@ import http from "node:http";
2335
2411
  import path10 from "node:path";
2336
2412
  import { Browser, detectBrowserPlatform, getInstalledBrowsers, install, resolveBuildId } from "@puppeteer/browsers";
2337
2413
  import puppeteer from "puppeteer-core";
2414
+ var ANDROID_ARGS = ["--no-sandbox", "--disable-dev-shm-usage"];
2415
+ var ANDROID_FALLBACKS = [[], ["--enable-features=NetworkServiceInProcess2"], ["--single-process", "--no-zygote"]];
2416
+ var flagsFile = () => path10.join(dataDir(), "chrome-flags.json");
2417
+ var sameFlags = (a, b) => a.length === b.length && a.every((x, i) => x === b[i]);
2418
+ function savedFlags() {
2419
+ try {
2420
+ const a = JSON.parse(fs14.readFileSync(flagsFile(), "utf8")).args;
2421
+ return Array.isArray(a) && ANDROID_FALLBACKS.some((f) => sameFlags(f, a)) ? [...a] : [];
2422
+ } catch {
2423
+ return [];
2424
+ }
2425
+ }
2426
+ function saveFlags(a) {
2427
+ try {
2428
+ if (a.length)
2429
+ fs14.writeFileSync(flagsFile(), JSON.stringify({ args: a }));
2430
+ else
2431
+ fs14.rmSync(flagsFile(), { force: true });
2432
+ } catch {}
2433
+ }
2338
2434
  function chromePlatformArgs(android = isAndroid()) {
2339
- return android ? ["--no-sandbox"] : [];
2435
+ return android ? [...ANDROID_ARGS, ...savedFlags()] : [];
2436
+ }
2437
+ async function probeChrome(attempt, android = isAndroid()) {
2438
+ if (!android)
2439
+ return attempt([]);
2440
+ const saved = savedFlags();
2441
+ let first;
2442
+ for (const extra of [saved, ...ANDROID_FALLBACKS.filter((f) => !sameFlags(f, saved))]) {
2443
+ try {
2444
+ const r = await attempt([...extra]);
2445
+ if (!sameFlags(extra, saved))
2446
+ saveFlags(extra);
2447
+ return r;
2448
+ } catch (e) {
2449
+ first ??= e;
2450
+ }
2451
+ }
2452
+ throw first;
2453
+ }
2454
+ function chromeLogHint(log) {
2455
+ return log.split(`
2456
+ `).filter((l) => /:(ERROR|FATAL):|crash/i.test(l)).slice(-2).map((l) => l.replace(/^\[[^\]]*\]\s*/, "").trim().slice(0, 160)).join(" / ");
2340
2457
  }
2341
2458
  function candidates() {
2342
2459
  const e = process.env;
@@ -2348,10 +2465,12 @@ function candidates() {
2348
2465
  }
2349
2466
  return ["google-chrome", "google-chrome-stable", "chromium", "chromium-browser"].map((n) => onPath(n)).filter((p) => !!p);
2350
2467
  }
2351
- function findChrome() {
2468
+ function findChrome(android = isAndroid()) {
2352
2469
  const forced = process.env.HYPEFRAME_CHROME;
2353
2470
  if (forced)
2354
2471
  return fs14.existsSync(forced) ? forced : null;
2472
+ if (android && linuxChromiumReady())
2473
+ return chromiumWrapper();
2355
2474
  return candidates().find((p) => fs14.existsSync(p)) || null;
2356
2475
  }
2357
2476
  async function cachedChrome(cacheDir) {
@@ -2404,10 +2523,21 @@ var TRY_ENCODER = `async (c) => {
2404
2523
  setTimeout(() => ok(false), 10000);
2405
2524
  });
2406
2525
  }`;
2407
- async function checkChrome(chrome, { gpu = false } = {}) {
2526
+ async function checkChrome(chrome, { gpu = false, android = isAndroid() } = {}) {
2527
+ return probeChrome(async (extra) => ({ ...await checkOnce(chrome, gpu, android ? [...ANDROID_ARGS, ...extra] : []), extra }), android);
2528
+ }
2529
+ async function checkOnce(chrome, gpu, platformArgs) {
2408
2530
  const srv = http.createServer((_q, r) => (r.writeHead(200, { "content-type": "text/html" }), r.end("<!doctype html><title>check</title>")));
2409
2531
  await new Promise((ok) => srv.listen(0, "127.0.0.1", ok));
2410
- const b = await puppeteer.launch({ executablePath: chrome, headless: true, protocolTimeout: 60000, args: ["--no-first-run", "--disable-extensions", ...gpu ? [] : softwareGpuArgs, ...chromePlatformArgs()] });
2532
+ let b;
2533
+ try {
2534
+ b = await puppeteer.launch({ executablePath: chrome, headless: true, protocolTimeout: 60000, args: ["--no-first-run", "--disable-extensions", ...gpu ? [] : softwareGpuArgs, ...platformArgs] });
2535
+ } catch (e) {
2536
+ srv.close();
2537
+ throw e;
2538
+ }
2539
+ let log = "";
2540
+ b.process()?.stderr?.on("data", (d) => log = (log + d).slice(-8000));
2411
2541
  try {
2412
2542
  const p = await b.newPage();
2413
2543
  await p.goto(`http://127.0.0.1:${srv.address().port}/`);
@@ -2417,6 +2547,9 @@ async function checkChrome(chrome, { gpu = false } = {}) {
2417
2547
  avc: await attempt({ codec: "avc1.42001f", width: 320, height: 568, bitrate: 1e6, framerate: 30 }),
2418
2548
  transparent: await attempt({ codec: "vp09.00.10.08", width: 320, height: 568, bitrate: 1e6, framerate: 30, alpha: "keep" })
2419
2549
  };
2550
+ } catch (e) {
2551
+ const hint = chromeLogHint(log);
2552
+ throw hint ? new Error(`${e.message} · Chrome: ${hint}`) : e;
2420
2553
  } finally {
2421
2554
  await b.close().catch(() => {
2422
2555
  return;
@@ -4139,6 +4272,25 @@ var isKey = (m) => m.type === "env_var" || !!m.varName;
4139
4272
  function pick(methods) {
4140
4273
  return methods.find((m) => m.type === "terminal") ?? methods.find((m) => (!m.type || m.type === "agent") && !isKey(m)) ?? methods.find(isKey);
4141
4274
  }
4275
+ async function logoutAgent(id) {
4276
+ const a = readInstalled().find((x) => x.id === id);
4277
+ if (!a)
4278
+ throw new Error(`Agent ${id} is not installed`);
4279
+ let signedOut = false;
4280
+ const proc = new AcpProcess;
4281
+ try {
4282
+ const init = await proc.start(a, projectDir("_cek"), agentEnv(id));
4283
+ if (init.agentCapabilities?.auth?.logout)
4284
+ signedOut = await proc.request("logout", {}, 60000).then(() => true, () => false) || false;
4285
+ } finally {
4286
+ await proc.stop();
4287
+ }
4288
+ const keys = forgetAgentSecrets(id).length > 0;
4289
+ if (!signedOut && !keys)
4290
+ return "unsupported";
4291
+ setReady(id, false);
4292
+ return signedOut ? "signed-out" : "key-removed";
4293
+ }
4142
4294
  async function loginAgent(id, io) {
4143
4295
  const a = readInstalled().find((x) => x.id === id);
4144
4296
  if (!a)
@@ -4170,6 +4322,72 @@ async function loginAgent(id, io) {
4170
4322
  return checkReady(id);
4171
4323
  }
4172
4324
 
4325
+ // src/agent/opencode.ts
4326
+ import fs21 from "node:fs";
4327
+ import path17 from "node:path";
4328
+ var OPENCODE = "opencode";
4329
+ var OPENCODE_KEY = "HF_OPENCODE_KEY";
4330
+ var PROVIDER = "hypeframe";
4331
+ var configFile = () => path17.join(dataDir(), "opencode.json");
4332
+ var cleanUrl = (u) => u.trim().replace(/\/+$/, "");
4333
+ function saveOpencodeApi(api) {
4334
+ const url = cleanUrl(api.url);
4335
+ if (!/^https?:\/\/[^\s/]+/i.test(url))
4336
+ throw new Error("The API address must start with http:// or https://");
4337
+ const models = [...new Set(api.models.map((m) => m.trim()).filter(Boolean))].slice(0, 50);
4338
+ if (!models.length)
4339
+ throw new Error("Pick at least one model");
4340
+ const key = api.key.trim();
4341
+ const config = {
4342
+ $schema: "https://opencode.ai/config.json",
4343
+ provider: {
4344
+ [PROVIDER]: {
4345
+ npm: "@ai-sdk/openai-compatible",
4346
+ name: (api.name || new URL(url).hostname).slice(0, 60),
4347
+ options: { baseURL: url, ...key ? { apiKey: `{env:${OPENCODE_KEY}}` } : {} },
4348
+ models: Object.fromEntries(models.map((m) => [m, { name: m }]))
4349
+ }
4350
+ },
4351
+ model: `${PROVIDER}/${models[0]}`
4352
+ };
4353
+ const f = configFile();
4354
+ fs21.writeFileSync(`${f}.tmp`, `${JSON.stringify(config, null, 2)}
4355
+ `, { mode: 384 });
4356
+ fs21.renameSync(`${f}.tmp`, f);
4357
+ if (key)
4358
+ saveAgentEnv(OPENCODE, { [OPENCODE_KEY]: key, OPENCODE_CONFIG: f });
4359
+ else
4360
+ removeAgentEnv(OPENCODE, [OPENCODE_KEY]), saveAgentEnv(OPENCODE, { OPENCODE_CONFIG: f });
4361
+ return f;
4362
+ }
4363
+ function opencodeApi() {
4364
+ try {
4365
+ const c = JSON.parse(fs21.readFileSync(configFile(), "utf8"));
4366
+ const p = c?.provider?.[PROVIDER];
4367
+ if (!p?.options?.baseURL)
4368
+ return null;
4369
+ return { url: String(p.options.baseURL), name: String(p.name ?? ""), model: String(c.model ?? "").replace(`${PROVIDER}/`, "") };
4370
+ } catch {
4371
+ return null;
4372
+ }
4373
+ }
4374
+ function removeOpencodeApi() {
4375
+ fs21.rmSync(configFile(), { force: true });
4376
+ removeAgentEnv(OPENCODE, [OPENCODE_KEY, "OPENCODE_CONFIG"]);
4377
+ }
4378
+ async function fetchApiModels(url, key, timeoutMs = 1e4) {
4379
+ try {
4380
+ const r = await fetch(`${cleanUrl(url)}/models`, { headers: key.trim() ? { authorization: `Bearer ${key.trim()}` } : {}, signal: AbortSignal.timeout(timeoutMs) });
4381
+ if (!r.ok)
4382
+ return [];
4383
+ const j = await r.json();
4384
+ const ids = (Array.isArray(j?.data) ? j.data : []).map((m) => typeof m?.id === "string" ? m.id : "").filter((x) => x && x.length < 200);
4385
+ return [...new Set(ids)].sort();
4386
+ } catch {
4387
+ return [];
4388
+ }
4389
+ }
4390
+
4173
4391
  // src/cli/commands/agent.ts
4174
4392
  var NAMES = { "antigravity-acp": "Antigravity", "codex-acp": "Codex", opencode: "OpenCode" };
4175
4393
  var agentName = (id) => NAMES[id] ?? readInstalled().find((a) => a.id === id)?.name ?? id;
@@ -4184,7 +4402,39 @@ var stateText = (s) => s === "ready" ? color.ok(t("agent.ready")) : s === "login
4184
4402
  function agentHint(id, s) {
4185
4403
  const mark = s === "ready" ? "✔" : s === "login" ? "▲" : "○";
4186
4404
  const state = t(s === "ready" ? "agent.ready" : s === "login" ? "agent.needLogin" : "agent.notInstalled");
4187
- return `${mark} ${state}${ACCOUNT[id] ? ` · ${t(ACCOUNT[id])}` : ""}`;
4405
+ const api = id === OPENCODE && s !== "none" ? opencodeApi() : null;
4406
+ const account = api ? t("agent.ownApiTag", { host: hostOf(api.url) }) : ACCOUNT[id] ? t(ACCOUNT[id]) : "";
4407
+ return `${mark} ${state}${account ? ` · ${account}` : ""}`;
4408
+ }
4409
+ var hostOf = (u) => {
4410
+ try {
4411
+ return new URL(u).host;
4412
+ } catch {
4413
+ return u;
4414
+ }
4415
+ };
4416
+ async function ownApi() {
4417
+ const now = opencodeApi();
4418
+ const url = await p.text({ message: t("agent.apiUrl"), placeholder: "https://api.contoh.com/v1", initialValue: now?.url ?? "", validate: (v) => /^https?:\/\/\S+$/i.test(String(v ?? "").trim()) ? undefined : t("agent.apiUrlBad") });
4419
+ if (p.isCancel(url))
4420
+ return;
4421
+ const key = await p.password({ message: t("agent.apiKey") });
4422
+ if (p.isCancel(key))
4423
+ return;
4424
+ const s = p.spinner();
4425
+ s.start(t("agent.apiModelsLoading"));
4426
+ const list = await fetchApiModels(String(url), String(key ?? ""));
4427
+ s.stop(list.length ? t("agent.apiModelsFound", { n: list.length }) : t("agent.apiModelsNone"));
4428
+ const model = list.length ? await p.select({ message: t("agent.apiModel"), options: list.slice(0, 300).map((m) => ({ value: m, label: m })), initialValue: now && list.includes(now.model) ? now.model : list[0], maxItems: 12 }) : await p.text({ message: t("agent.apiModelType"), placeholder: "gpt-4o-mini", initialValue: now?.model ?? "", validate: (v) => String(v ?? "").trim() ? undefined : "—" });
4429
+ if (p.isCancel(model))
4430
+ return;
4431
+ const main = String(model).trim();
4432
+ saveOpencodeApi({ url: String(url), key: String(key ?? ""), models: [main, ...list.filter((m) => m !== main).slice(0, 40)] });
4433
+ log.ok(t("agent.apiSaved", { host: hostOf(String(url).trim()), model: main }));
4434
+ if (await checkReady(OPENCODE))
4435
+ log.detail(t(runningPid() ? "agent.nextRunning" : "agent.nextStart", { name: agentName(OPENCODE) }));
4436
+ else
4437
+ log.warn(t("agent.apiNotReady"));
4188
4438
  }
4189
4439
  var io = {
4190
4440
  ask: async (label) => {
@@ -4259,13 +4509,24 @@ async function loginOne(id) {
4259
4509
  log.warn(t("agent.loginFailed", { name: agentName(id) }));
4260
4510
  return ok;
4261
4511
  }
4512
+ async function logoutOne(id) {
4513
+ const name = agentName(id);
4514
+ log.info(t("agent.loggingOut", { name }));
4515
+ const r = await logoutAgent(id);
4516
+ if (r === "unsupported")
4517
+ return log.warn(t("agent.logoutUnsupported", { name })), false;
4518
+ log.ok(t(r === "signed-out" ? "agent.loggedOut" : "agent.keyRemoved", { name }));
4519
+ if (runningPid())
4520
+ log.detail(t("agent.logoutRestart", { name }));
4521
+ return true;
4522
+ }
4262
4523
  async function agentCommand(args) {
4263
4524
  const [sub, raw] = args.rest;
4264
4525
  const id = raw ? resolveAgentId(raw) : raw;
4265
4526
  if (!sub || sub === "list")
4266
4527
  return listAgents();
4267
4528
  if (!id)
4268
- return log.error("hypeframe agent add|login|remove <id>");
4529
+ return log.error("hypeframe agent add|login|logout|remove <id>");
4269
4530
  if (sub === "add")
4270
4531
  return void await addAgent(id, args.flags.download === true);
4271
4532
  if (sub === "login") {
@@ -4273,11 +4534,16 @@ async function agentCommand(args) {
4273
4534
  return log.error(t("agent.notInstalledYet", { name: agentName(id) }));
4274
4535
  return void await loginOne(id);
4275
4536
  }
4537
+ if (sub === "logout") {
4538
+ if (agentState(id) === "none")
4539
+ return log.error(t("agent.notInstalledYet", { name: agentName(id) }));
4540
+ return void await logoutOne(id);
4541
+ }
4276
4542
  if (sub === "remove") {
4277
4543
  removeAgent(id);
4278
4544
  return log.ok(t("agent.removed", { name: agentName(id) }));
4279
4545
  }
4280
- log.error("hypeframe agent list|add|login|remove codex|antigravity|opencode");
4546
+ log.error("hypeframe agent list|add|login|logout|remove codex|antigravity|opencode");
4281
4547
  }
4282
4548
  async function agentMenu() {
4283
4549
  for (;; ) {
@@ -4293,7 +4559,8 @@ async function agentMenu() {
4293
4559
  options: [
4294
4560
  ...state === "none" ? [{ value: "add", label: t("agent.add") }] : [],
4295
4561
  ...state === "login" ? [{ value: "login", label: t("agent.loginNow") }] : [],
4296
- ...state === "ready" ? [{ value: "login", label: t("agent.login") }] : [],
4562
+ ...state === "ready" ? [{ value: "switch", label: t("agent.login") }, { value: "logout", label: t("agent.logout") }] : [],
4563
+ ...choice === OPENCODE && state !== "none" ? [{ value: "api", label: opencodeApi() ? t("agent.ownApiChange", { host: hostOf(opencodeApi().url) }) : t("agent.ownApi") }, ...opencodeApi() ? [{ value: "api-off", label: t("agent.ownApiOff") }] : []] : [],
4297
4564
  ...state !== "none" ? [{ value: "remove", label: t("agent.remove") }] : [],
4298
4565
  { value: "", label: color.muted(t("agent.back")) }
4299
4566
  ]
@@ -4305,6 +4572,17 @@ async function agentMenu() {
4305
4572
  await addAgent(choice);
4306
4573
  if (action === "login")
4307
4574
  await loginOne(choice);
4575
+ if (action === "switch")
4576
+ await logoutAgent(choice).catch(() => "unsupported"), await loginOne(choice);
4577
+ if (action === "api")
4578
+ await ownApi();
4579
+ if (action === "api-off")
4580
+ removeOpencodeApi(), log.ok(t("agent.ownApiOffDone"));
4581
+ if (action === "logout") {
4582
+ const sure = await p.confirm({ message: t("agent.logoutAsk", { name: agentName(choice) }), initialValue: false });
4583
+ if (sure === true)
4584
+ await logoutOne(choice);
4585
+ }
4308
4586
  if (action === "remove") {
4309
4587
  const sure = await p.confirm({ message: t("agent.removeAsk", { name: agentName(choice) }), initialValue: false });
4310
4588
  if (sure === true)
@@ -4362,7 +4640,7 @@ async function config(args) {
4362
4640
  const name = await p2.text({ message: t("config.name"), initialValue: s.name, validate: (v) => v && v.trim() ? undefined : "—" });
4363
4641
  if (p2.isCancel(name))
4364
4642
  return;
4365
- const gpu = await p2.confirm({ message: t("config.gpu"), initialValue: s.gpu });
4643
+ const gpu = isAndroid() ? false : await p2.confirm({ message: t("config.gpu"), initialValue: s.gpu });
4366
4644
  if (p2.isCancel(gpu))
4367
4645
  return;
4368
4646
  const language = await p2.select({
@@ -4384,8 +4662,8 @@ async function config(args) {
4384
4662
 
4385
4663
  // src/cli/commands/doctor.ts
4386
4664
  import { spawnSync as spawnSync4 } from "node:child_process";
4387
- import fs21 from "node:fs";
4388
- import path17 from "node:path";
4665
+ import fs22 from "node:fs";
4666
+ import path18 from "node:path";
4389
4667
  var mark = { ok: color.ok(icon.ok), warn: color.warn(icon.warn), error: color.error(icon.error) };
4390
4668
  async function reach(url) {
4391
4669
  const t0 = Date.now();
@@ -4414,10 +4692,10 @@ async function doctor(args) {
4414
4692
  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")}` : ""}` });
4415
4693
  }
4416
4694
  try {
4417
- const probe = path17.join(dataDir(), `.probe-${process.pid}`);
4418
- fs21.writeFileSync(probe, "x");
4419
- fs21.rmSync(probe);
4420
- const st = fs21.statfsSync(dataDir());
4695
+ const probe = path18.join(dataDir(), `.probe-${process.pid}`);
4696
+ fs22.writeFileSync(probe, "x");
4697
+ fs22.rmSync(probe);
4698
+ const st = fs22.statfsSync(dataDir());
4421
4699
  const free = st.bavail * st.bsize;
4422
4700
  show({ label: t("doctor.disk"), result: free > 2 * 1024 ** 3 ? "ok" : "warn", detail: `${dataDir()} ${color.muted(icon.dot)} ${t("doctor.free", { size: bytes2(free) })}` });
4423
4701
  } catch (e) {
@@ -4438,11 +4716,14 @@ async function doctor(args) {
4438
4716
  else {
4439
4717
  try {
4440
4718
  const info = await checkChrome(chrome, { gpu: s.gpu });
4441
- show({ label: "Chrome", result: info.avc ? "ok" : "error", detail: `${info.version} ${color.muted(icon.dot)} H.264 ${info.avc ? t("doctor.yes") : t("doctor.no")}` });
4719
+ const extra = info.extra?.length ? ` ${color.muted(`${icon.dot} ${info.extra.join(" ")}`)}` : "";
4720
+ show({ label: "Chrome", result: info.avc ? "ok" : "error", detail: `${info.version} ${color.muted(icon.dot)} H.264 ${info.avc ? t("doctor.yes") : t("doctor.no")}${extra}` });
4442
4721
  show({ label: t("doctor.alpha"), result: info.transparent ? "ok" : "warn", detail: info.transparent ? t("doctor.yes") : t("doctor.alphaNo") });
4443
4722
  } catch (e) {
4444
4723
  show({ label: "Chrome", result: "error", detail: String(e.message).split(`
4445
- `)[0].slice(0, 120) });
4724
+ `)[0].slice(0, 280) });
4725
+ if (isAndroid() && !linuxChromiumReady())
4726
+ show({ label: "Chromium", result: "warn", detail: t("doctor.tryChromiumMini") });
4446
4727
  }
4447
4728
  }
4448
4729
  const gw = await reach(`${s.gateway}/`);
@@ -4461,21 +4742,21 @@ async function doctor(args) {
4461
4742
  }
4462
4743
 
4463
4744
  // src/cli/commands/history.ts
4464
- import fs22 from "node:fs";
4465
- import path18 from "node:path";
4745
+ import fs23 from "node:fs";
4746
+ import path19 from "node:path";
4466
4747
  function readHistory2(hours = 24) {
4467
4748
  const root = renderDir();
4468
4749
  const since = Date.now() - hours * 3600000;
4469
4750
  const out = [];
4470
- for (const name of fs22.readdirSync(root)) {
4751
+ for (const name of fs23.readdirSync(root)) {
4471
4752
  if (!JOB_ID.test(name))
4472
4753
  continue;
4473
4754
  try {
4474
- const j = JSON.parse(fs22.readFileSync(path18.join(root, name, "status.json"), "utf8"));
4755
+ const j = JSON.parse(fs23.readFileSync(path19.join(root, name, "status.json"), "utf8"));
4475
4756
  if ((j.diperbarui || j.dibuat) < since)
4476
4757
  continue;
4477
- const f = j.hasilBerkas ? path18.join(root, name, j.hasilBerkas) : null;
4478
- out.push({ job: j, file: f && fs22.existsSync(f) ? f : null });
4758
+ const f = j.hasilBerkas ? path19.join(root, name, j.hasilBerkas) : null;
4759
+ out.push({ job: j, file: f && fs23.existsSync(f) ? f : null });
4479
4760
  } catch {}
4480
4761
  }
4481
4762
  return out.sort((a, b) => (b.job.diperbarui || 0) - (a.job.diperbarui || 0));
@@ -4502,30 +4783,30 @@ function history() {
4502
4783
 
4503
4784
  // src/cli/commands/maintenance.ts
4504
4785
  import { spawnSync as spawnSync5 } from "node:child_process";
4505
- import fs23 from "node:fs";
4786
+ import fs24 from "node:fs";
4506
4787
  import os4 from "node:os";
4507
- import path19 from "node:path";
4788
+ import path20 from "node:path";
4508
4789
  async function clean() {
4509
4790
  if (runningPid()) {
4510
4791
  log.warn(t("clean.running"));
4511
4792
  return;
4512
4793
  }
4513
- const targets = [path19.join(cacheDir(), "chrome"), path19.join(cacheDir(), "halaman"), path19.join(logDir(), "hypeframe.log.1")];
4514
- for (const job of fs23.readdirSync(renderDir())) {
4794
+ const targets = [path20.join(cacheDir(), "chrome"), path20.join(cacheDir(), "halaman"), path20.join(logDir(), "hypeframe.log.1")];
4795
+ for (const job of fs24.readdirSync(renderDir())) {
4515
4796
  if (!JOB_ID.test(job))
4516
4797
  continue;
4517
4798
  try {
4518
- const s = JSON.parse(fs23.readFileSync(path19.join(renderDir(), job, "status.json"), "utf8")).status;
4799
+ const s = JSON.parse(fs24.readFileSync(path20.join(renderDir(), job, "status.json"), "utf8")).status;
4519
4800
  if (s === "gagal" || s === "batal" || s === "unggah")
4520
- targets.push(path19.join(renderDir(), job));
4801
+ targets.push(path20.join(renderDir(), job));
4521
4802
  } catch {
4522
- targets.push(path19.join(renderDir(), job));
4803
+ targets.push(path20.join(renderDir(), job));
4523
4804
  }
4524
4805
  }
4525
4806
  let freed = 0;
4526
4807
  for (const p of targets) {
4527
4808
  freed += await sizeOf(p);
4528
- fs23.rmSync(p, { recursive: true, force: true });
4809
+ fs24.rmSync(p, { recursive: true, force: true });
4529
4810
  }
4530
4811
  log.ok(t("clean.done", { size: bytes2(freed) }));
4531
4812
  }
@@ -4534,7 +4815,7 @@ function report() {
4534
4815
  const a = readAccount();
4535
4816
  let recent = "";
4536
4817
  try {
4537
- recent = fs23.readFileSync(path19.join(logDir(), "hypeframe.log"), "utf8").split(`
4818
+ recent = fs24.readFileSync(path20.join(logDir(), "hypeframe.log"), "utf8").split(`
4538
4819
  `).slice(-400).join(`
4539
4820
  `);
4540
4821
  } catch {
@@ -4555,8 +4836,8 @@ function report() {
4555
4836
  recent
4556
4837
  ];
4557
4838
  const stamp = new Date().toISOString().slice(0, 19).replace(/[-:T]/g, "");
4558
- const file = path19.join(dataDir(), `laporan-${stamp}.txt`);
4559
- fs23.writeFileSync(file, mask(lines.join(`
4839
+ const file = path20.join(dataDir(), `laporan-${stamp}.txt`);
4840
+ fs24.writeFileSync(file, mask(lines.join(`
4560
4841
  `)), { mode: 384 });
4561
4842
  log.ok(t("report.done", { file }));
4562
4843
  log.detail(t("report.hint"));
@@ -4592,13 +4873,13 @@ function openWeb(args) {
4592
4873
  }
4593
4874
 
4594
4875
  // src/cli/commands/status.ts
4595
- import fs24 from "node:fs";
4596
- import path20 from "node:path";
4876
+ import fs25 from "node:fs";
4877
+ import path21 from "node:path";
4597
4878
  function statusRows(args) {
4598
4879
  const s = resolveSettings(args?.flags);
4599
4880
  const a = readAccount();
4600
4881
  const pid = runningPid();
4601
- const chrome = findChrome() || fs24.existsSync(path20.join(cacheDir(), "chrome"));
4882
+ const chrome = findChrome() || fs25.existsSync(path21.join(cacheDir(), "chrome"));
4602
4883
  const recent = readHistory2();
4603
4884
  const k = (key) => color.muted(t(key));
4604
4885
  return [
@@ -4820,7 +5101,7 @@ function help() {
4820
5101
  ["open", t("help.open")],
4821
5102
  ["doctor", t("help.doctor")],
4822
5103
  ["bench", t("help.bench")],
4823
- ["agent list|add|login|remove", t("help.agent")],
5104
+ ["agent list|add|login|logout|remove", t("help.agent")],
4824
5105
  ["chromium", t("help.chromium")],
4825
5106
  ["history", t("help.history")],
4826
5107
  ["autostart on|off", t("help.autostart")],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hypeframe",
3
- "version": "0.8.0",
3
+ "version": "0.8.2",
4
4
  "description": "Local engine for HypeFrame Web: code clips, video renders and AI agents run on your own machine; the web is just the view.",
5
5
  "keywords": [
6
6
  "hypeframe",