@oya-ai/cli 1.0.261 → 1.0.265
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/dist/index.js +339 -169
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -64,15 +64,16 @@ var VALUE_FLAGS = {
|
|
|
64
64
|
url: "--url http://127.0.0.1:3100",
|
|
65
65
|
"ws-url": "--ws-url ws://127.0.0.1:9222"
|
|
66
66
|
};
|
|
67
|
+
var invocation = ([command = "help", ...args], flags) => ({ command, args, flags });
|
|
67
68
|
function parse(argv2) {
|
|
68
|
-
const
|
|
69
|
-
const args = [];
|
|
69
|
+
const positionals = [];
|
|
70
70
|
const flags = {};
|
|
71
|
-
for (let i = 0; i <
|
|
72
|
-
if (
|
|
73
|
-
|
|
71
|
+
for (let i = 0; i < argv2.length; i++) {
|
|
72
|
+
if (argv2[i] === "--") return invocation([...positionals, ...argv2.slice(i + 1)], flags);
|
|
73
|
+
if (!argv2[i].startsWith("--")) positionals.push(argv2[i]);
|
|
74
|
+
else if (takeFlag(argv2[i].slice("--".length), argv2[i + 1], flags)) i++;
|
|
74
75
|
}
|
|
75
|
-
return
|
|
76
|
+
return invocation(positionals, flags);
|
|
76
77
|
}
|
|
77
78
|
function takeFlag(token2, next, flags) {
|
|
78
79
|
const [name, inline] = splitOnce(token2);
|
|
@@ -124,7 +125,7 @@ function readJsonFile(file) {
|
|
|
124
125
|
|
|
125
126
|
// src/install.ts
|
|
126
127
|
import { writeFileSync as writeFileSync4 } from "fs";
|
|
127
|
-
import { join as
|
|
128
|
+
import { join as join8 } from "path";
|
|
128
129
|
|
|
129
130
|
// src/prompt/style.ts
|
|
130
131
|
import { stdout } from "process";
|
|
@@ -422,15 +423,18 @@ function writeMask(output, newline) {
|
|
|
422
423
|
output.write(newline ? "\n" : "*");
|
|
423
424
|
}
|
|
424
425
|
var maskedCells = () => maskCells;
|
|
426
|
+
function scrubHistory(history) {
|
|
427
|
+
if (masked || setupInput) history.shift();
|
|
428
|
+
}
|
|
425
429
|
function iface() {
|
|
426
430
|
if (rl) return rl;
|
|
427
431
|
rl = createReader();
|
|
428
432
|
rl.setPrompt(currentPrompt);
|
|
433
|
+
rl.on("history", scrubHistory);
|
|
429
434
|
rl.on("line", readLine);
|
|
430
435
|
rl.on("close", close);
|
|
431
436
|
rl.on("SIGINT", interruptLine);
|
|
432
|
-
maskEcho(rl);
|
|
433
|
-
return rl;
|
|
437
|
+
return maskEcho(rl), rl;
|
|
434
438
|
}
|
|
435
439
|
function createReader() {
|
|
436
440
|
const keys = new Set(stdin.listeners("keypress")), resize = new Set(stdout4.listeners("resize"));
|
|
@@ -623,12 +627,23 @@ var select = (menu) => ({ id: menu.options[menu.active].id });
|
|
|
623
627
|
var KEYS = {
|
|
624
628
|
"": () => ({ id: null }),
|
|
625
629
|
[`${ESC}[A`]: move(-1),
|
|
630
|
+
[`${ESC}OA`]: move(-1),
|
|
626
631
|
k: move(-1),
|
|
627
632
|
[`${ESC}[B`]: move(1),
|
|
633
|
+
[`${ESC}OB`]: move(1),
|
|
628
634
|
j: move(1),
|
|
629
635
|
"\r": select,
|
|
630
636
|
"\n": select
|
|
631
637
|
};
|
|
638
|
+
var KEY_PATTERN = new RegExp(`${ESC}(?:\\[[0-9;]*[A-Za-z~]|O[A-Za-z])|[\\s\\S]`, "g");
|
|
639
|
+
var keyTokens = (chunk) => chunk.match(KEY_PATTERN) ?? [];
|
|
640
|
+
function runChunk(menu, chunk) {
|
|
641
|
+
for (const key of keyTokens(chunk)) {
|
|
642
|
+
const outcome = actionFor(key)?.(menu);
|
|
643
|
+
if (outcome) return outcome;
|
|
644
|
+
}
|
|
645
|
+
return void 0;
|
|
646
|
+
}
|
|
632
647
|
function actionFor(key) {
|
|
633
648
|
if (Object.hasOwn(KEYS, key)) return KEYS[key];
|
|
634
649
|
return /^[1-9]$/.test(key) ? jump(key) : void 0;
|
|
@@ -693,7 +708,7 @@ function release(onData, wasRaw) {
|
|
|
693
708
|
function listen(menu, wasRaw, resolve2, reject) {
|
|
694
709
|
const onData = (buf) => {
|
|
695
710
|
if (windowChanged(menu, buf)) return resizeFallback(menu, onData, wasRaw, resolve2, reject);
|
|
696
|
-
const outcome =
|
|
711
|
+
const outcome = runChunk(menu, buf.toString());
|
|
697
712
|
if (!outcome) return;
|
|
698
713
|
release(onData, wasRaw);
|
|
699
714
|
finish(menu, outcome, resolve2, reject);
|
|
@@ -701,7 +716,7 @@ function listen(menu, wasRaw, resolve2, reject) {
|
|
|
701
716
|
stdin3.on("data", onData);
|
|
702
717
|
}
|
|
703
718
|
function windowChanged(menu, buffer) {
|
|
704
|
-
return buffer.toString()
|
|
719
|
+
return !buffer.toString().includes("") && !!menu.presentation && !menu.presentation.canNavigate(menu.options);
|
|
705
720
|
}
|
|
706
721
|
function resizeFallback(menu, onData, wasRaw, resolve2, reject) {
|
|
707
722
|
release(onData, wasRaw);
|
|
@@ -1321,7 +1336,153 @@ async function preflight(root, a) {
|
|
|
1321
1336
|
}
|
|
1322
1337
|
|
|
1323
1338
|
// src/install/env-file.ts
|
|
1324
|
-
import { existsSync as existsSync3, readFileSync as
|
|
1339
|
+
import { existsSync as existsSync3, readFileSync as readFileSync3 } from "fs";
|
|
1340
|
+
|
|
1341
|
+
// src/config.ts
|
|
1342
|
+
import {
|
|
1343
|
+
chmodSync,
|
|
1344
|
+
closeSync,
|
|
1345
|
+
constants as fsConstants,
|
|
1346
|
+
mkdirSync,
|
|
1347
|
+
openSync,
|
|
1348
|
+
readFileSync as readFileSync2,
|
|
1349
|
+
renameSync,
|
|
1350
|
+
unlinkSync,
|
|
1351
|
+
writeFileSync
|
|
1352
|
+
} from "fs";
|
|
1353
|
+
import { randomUUID } from "crypto";
|
|
1354
|
+
import { homedir } from "os";
|
|
1355
|
+
import { basename, join as join3, dirname as dirname2 } from "path";
|
|
1356
|
+
|
|
1357
|
+
// src/constants.ts
|
|
1358
|
+
var ARGV_SKIP = 2;
|
|
1359
|
+
var KEY_TAIL = 4;
|
|
1360
|
+
var MIN_KEY_FOR_TAIL = 12;
|
|
1361
|
+
var LOGIN_TIMEOUT_MS = 6e4;
|
|
1362
|
+
var ExitCode = {
|
|
1363
|
+
/** Done. */
|
|
1364
|
+
DONE: 0,
|
|
1365
|
+
/** The request failed: the server or the browser refused it, or no answer came. */
|
|
1366
|
+
FAILED: 1,
|
|
1367
|
+
/** The command could not be run as typed; nothing was sent. */
|
|
1368
|
+
USAGE: 2
|
|
1369
|
+
};
|
|
1370
|
+
var JSON_INDENT2 = 2;
|
|
1371
|
+
var DEFAULT_BASE_URL = "https://oyabrowser.com";
|
|
1372
|
+
var CONFIG_DIR_MODE = 448;
|
|
1373
|
+
var CONFIG_FILE_MODE = 384;
|
|
1374
|
+
var PRIVATE_FILE_MODE = 384;
|
|
1375
|
+
var LsColumns = {
|
|
1376
|
+
/** Provider name. */
|
|
1377
|
+
PROVIDER: 14,
|
|
1378
|
+
/** Persona name. */
|
|
1379
|
+
PERSONA: 14,
|
|
1380
|
+
/** Browser name. */
|
|
1381
|
+
NAME: 18,
|
|
1382
|
+
/** Current URL, after the scheme is dropped. */
|
|
1383
|
+
URL: 40
|
|
1384
|
+
};
|
|
1385
|
+
var StatusColumns = {
|
|
1386
|
+
/** Recent actions shown. */
|
|
1387
|
+
RECENT: 10,
|
|
1388
|
+
/** Action name column. */
|
|
1389
|
+
ACTION: 18
|
|
1390
|
+
};
|
|
1391
|
+
var PERSONA_NAME_WIDTH = 20;
|
|
1392
|
+
var Status2 = {
|
|
1393
|
+
/** The API key was rejected. */
|
|
1394
|
+
UNAUTHORIZED: 401,
|
|
1395
|
+
/** A role refusal, or the auth layer's answer for an unknown key. */
|
|
1396
|
+
FORBIDDEN: 403,
|
|
1397
|
+
/** An endpoint another browser already holds. */
|
|
1398
|
+
CONFLICT: 409,
|
|
1399
|
+
/** A quota or a persona concurrency cap. */
|
|
1400
|
+
TOO_MANY_REQUESTS: 429
|
|
1401
|
+
};
|
|
1402
|
+
var MODELS_SHOWN = 8;
|
|
1403
|
+
|
|
1404
|
+
// src/config.ts
|
|
1405
|
+
var FILE = join3(process.env.OYA_CONFIG_HOME || join3(homedir(), ".oya"), "config.json");
|
|
1406
|
+
function load() {
|
|
1407
|
+
try {
|
|
1408
|
+
return JSON.parse(readFileSync2(FILE, "utf8"));
|
|
1409
|
+
} catch {
|
|
1410
|
+
return {};
|
|
1411
|
+
}
|
|
1412
|
+
}
|
|
1413
|
+
function ensureConfigDir(dir) {
|
|
1414
|
+
mkdirSync(dir, { recursive: true, mode: CONFIG_DIR_MODE });
|
|
1415
|
+
try {
|
|
1416
|
+
chmodSync(dir, CONFIG_DIR_MODE);
|
|
1417
|
+
} catch {
|
|
1418
|
+
}
|
|
1419
|
+
}
|
|
1420
|
+
function openTempFile(tmp, mode) {
|
|
1421
|
+
const { O_WRONLY, O_CREAT, O_EXCL, O_NOFOLLOW = 0 } = fsConstants;
|
|
1422
|
+
return openSync(tmp, O_WRONLY | O_CREAT | O_EXCL | O_NOFOLLOW, mode);
|
|
1423
|
+
}
|
|
1424
|
+
function writeFd(fd, text) {
|
|
1425
|
+
try {
|
|
1426
|
+
writeFileSync(fd, text);
|
|
1427
|
+
} finally {
|
|
1428
|
+
closeSync(fd);
|
|
1429
|
+
}
|
|
1430
|
+
}
|
|
1431
|
+
function removeTemp(tmp) {
|
|
1432
|
+
try {
|
|
1433
|
+
unlinkSync(tmp);
|
|
1434
|
+
} catch {
|
|
1435
|
+
}
|
|
1436
|
+
}
|
|
1437
|
+
function writePrivateFile(filePath, text, mode = CONFIG_FILE_MODE) {
|
|
1438
|
+
const tmp = join3(dirname2(filePath), `.${basename(filePath)}.${process.pid}-${randomUUID()}.tmp`);
|
|
1439
|
+
try {
|
|
1440
|
+
writeFd(openTempFile(tmp, mode), text);
|
|
1441
|
+
renameSync(tmp, filePath);
|
|
1442
|
+
} catch (err) {
|
|
1443
|
+
removeTemp(tmp);
|
|
1444
|
+
throw err;
|
|
1445
|
+
}
|
|
1446
|
+
}
|
|
1447
|
+
function save(values) {
|
|
1448
|
+
const text = JSON.stringify({ ...load(), ...values }, null, JSON_INDENT2);
|
|
1449
|
+
ensureConfigDir(dirname2(FILE));
|
|
1450
|
+
writePrivateFile(FILE, text, CONFIG_FILE_MODE);
|
|
1451
|
+
}
|
|
1452
|
+
var configPath = FILE;
|
|
1453
|
+
function first(flag, env2, saved, names) {
|
|
1454
|
+
if (flag) return { value: flag, from: names[0] };
|
|
1455
|
+
if (env2) return { value: env2, from: names[1] };
|
|
1456
|
+
return saved ? { value: saved, from: names[2] } : null;
|
|
1457
|
+
}
|
|
1458
|
+
function origin({ apiKey, baseUrl } = {}) {
|
|
1459
|
+
const saved = load();
|
|
1460
|
+
const url = first(baseUrl, process.env.OYA_BASE_URL, saved.baseUrl, URL_SOURCES);
|
|
1461
|
+
const address = (url?.value ?? DEFAULT_BASE_URL).replace(/\/+$/, "");
|
|
1462
|
+
const key = first(apiKey, process.env.OYA_API_KEY, savedKeyFor(saved, address), KEY_SOURCES);
|
|
1463
|
+
const found = { apiKey: key?.value ?? "", apiKeyFrom: key?.from ?? "none", baseUrl: address };
|
|
1464
|
+
return { ...found, baseUrlFrom: url?.from ?? "default", savedKey: !!saved.apiKey, savedUrl: saved.baseUrl };
|
|
1465
|
+
}
|
|
1466
|
+
function savedKeyFor(saved, address) {
|
|
1467
|
+
if (!saved.baseUrl || deploymentOf(saved.baseUrl) === deploymentOf(address)) return saved.apiKey;
|
|
1468
|
+
return void 0;
|
|
1469
|
+
}
|
|
1470
|
+
function deploymentOf(url) {
|
|
1471
|
+
try {
|
|
1472
|
+
const { origin: site, pathname } = new URL(String(url).trim());
|
|
1473
|
+
return `${site}${pathname.replace(/\/+$/, "")}`;
|
|
1474
|
+
} catch {
|
|
1475
|
+
return String(url).trim().replace(/\/+$/, "");
|
|
1476
|
+
}
|
|
1477
|
+
}
|
|
1478
|
+
var KEY_SOURCES = ["--key", "OYA_API_KEY", "saved"];
|
|
1479
|
+
var URL_SOURCES = ["--url", "OYA_BASE_URL", "saved"];
|
|
1480
|
+
function resolved() {
|
|
1481
|
+
const { apiKey, baseUrl } = origin();
|
|
1482
|
+
return { apiKey, baseUrl };
|
|
1483
|
+
}
|
|
1484
|
+
|
|
1485
|
+
// src/install/env-file.ts
|
|
1325
1486
|
var SECRET_KEYS = /* @__PURE__ */ new Set([
|
|
1326
1487
|
"OYA_PROFILE_SECRET",
|
|
1327
1488
|
"OYA_OPERATOR_TOKEN",
|
|
@@ -1371,17 +1532,32 @@ var SECTIONS = [
|
|
|
1371
1532
|
["CAPTCHA", ["OYA_CAPTCHA_PROVIDER", "OYA_CAPTCHA_API_KEY"]],
|
|
1372
1533
|
["Multi-replica. One SQLite control database allows exactly one writer", ["OYA_INSTANCE_URL", "OYA_CLUSTER_SECRET"]]
|
|
1373
1534
|
];
|
|
1535
|
+
var MANAGED_KEYS = /* @__PURE__ */ new Set([...SECTIONS.flatMap(([, keys]) => keys), "DAYTONA_SNAPSHOT"]);
|
|
1536
|
+
function unquoteDouble(raw) {
|
|
1537
|
+
return raw.slice(1, -1).replace(/\\(["\\nr])/g, (_m, c) => c === "n" ? "\n" : c === "r" ? "\r" : c);
|
|
1538
|
+
}
|
|
1539
|
+
function parseEnvValue(raw) {
|
|
1540
|
+
const trimmed = raw.trim();
|
|
1541
|
+
if (trimmed.length > 1 && trimmed.startsWith("'") && trimmed.endsWith("'")) return trimmed.slice(1, -1);
|
|
1542
|
+
if (trimmed.length > 1 && trimmed.startsWith('"') && trimmed.endsWith('"')) return unquoteDouble(trimmed);
|
|
1543
|
+
return trimmed.replace(/\s+#.*$/, "").trim();
|
|
1544
|
+
}
|
|
1545
|
+
function formatEnvValue(value) {
|
|
1546
|
+
if (!/[\s#"'\\]/.test(value)) return value;
|
|
1547
|
+
const escaped = value.replace(/\\/g, "\\\\").replace(/"/g, '\\"').replace(/\n/g, "\\n").replace(/\r/g, "\\r");
|
|
1548
|
+
return `"${escaped}"`;
|
|
1549
|
+
}
|
|
1374
1550
|
function readEnv(path) {
|
|
1375
1551
|
if (!existsSync3(path)) return {};
|
|
1376
1552
|
const out2 = {};
|
|
1377
|
-
for (const line of
|
|
1378
|
-
const m = /^([A-Z0-9_]+)=(.*)$/.exec(line.trim());
|
|
1379
|
-
if (m) out2[m[1]] = m[2];
|
|
1553
|
+
for (const line of readFileSync3(path, "utf8").split("\n")) {
|
|
1554
|
+
const m = /^(?:export\s+)?([A-Z0-9_]+)=(.*)$/.exec(line.trim());
|
|
1555
|
+
if (m) out2[m[1]] = parseEnvValue(m[2]);
|
|
1380
1556
|
}
|
|
1381
1557
|
return out2;
|
|
1382
1558
|
}
|
|
1383
1559
|
function block(title, keys, values) {
|
|
1384
|
-
return [`# \u2500\u2500 ${title} \u2500\u2500`, ...keys.map((k) => `${k}=${values[k]}`), ""];
|
|
1560
|
+
return [`# \u2500\u2500 ${title} \u2500\u2500`, ...keys.map((k) => `${k}=${formatEnvValue(values[k])}`), ""];
|
|
1385
1561
|
}
|
|
1386
1562
|
function sectionLines(values, placed) {
|
|
1387
1563
|
const lines = [];
|
|
@@ -1402,8 +1578,7 @@ function renderEnv(values, extra) {
|
|
|
1402
1578
|
return lines.join("\n");
|
|
1403
1579
|
}
|
|
1404
1580
|
function writeEnv(path, body) {
|
|
1405
|
-
|
|
1406
|
-
chmodSync(path, ENV_FILE_MODE);
|
|
1581
|
+
writePrivateFile(path, body, ENV_FILE_MODE);
|
|
1407
1582
|
}
|
|
1408
1583
|
|
|
1409
1584
|
// src/install/build-env.ts
|
|
@@ -1470,9 +1645,18 @@ var fleetTokenLines = () => [
|
|
|
1470
1645
|
`# FLEET_TOKEN=${token()}`
|
|
1471
1646
|
];
|
|
1472
1647
|
var STORAGE_FOR = { sqlite: "sqlite", postgres: "postgres", supabase: "postgres" };
|
|
1648
|
+
function mergeSecrets(v, existing, secrets) {
|
|
1649
|
+
for (const [k, val] of Object.entries(existing)) {
|
|
1650
|
+
const keepSecret = SECRET_KEYS.has(k) && k !== "OYA_METRICS_TOKEN";
|
|
1651
|
+
if (val && (keepSecret || !MANAGED_KEYS.has(k)) && !v[k]) v[k] = val;
|
|
1652
|
+
}
|
|
1653
|
+
for (const [k, val] of Object.entries(secrets)) {
|
|
1654
|
+
if (val !== void 0 && val !== "") v[k] = val;
|
|
1655
|
+
}
|
|
1656
|
+
}
|
|
1473
1657
|
function buildEnv(a, secrets, existing) {
|
|
1474
1658
|
const { v, apiKey } = baseSecrets(a, existing);
|
|
1475
|
-
|
|
1659
|
+
mergeSecrets(v, existing, secrets);
|
|
1476
1660
|
v.OYA_STORAGE = STORAGE_FOR[a.database] ?? "sqlite";
|
|
1477
1661
|
if (a.llm.provider !== "skip") Object.assign(v, { OPENAI_BASE_URL: a.llm.baseUrl, CHAT_MODEL: a.llm.model });
|
|
1478
1662
|
fleetSettings(v, { a, existing, wsUrl: a.publicUrl.replace(/^http/, "ws") + "/ws" });
|
|
@@ -1528,8 +1712,8 @@ async function resolveKekConflict(volume, root) {
|
|
|
1528
1712
|
|
|
1529
1713
|
// src/install/migrate.ts
|
|
1530
1714
|
import { spawn as spawn2 } from "child_process";
|
|
1531
|
-
import { join as
|
|
1532
|
-
var startMigrations = (root, databaseUrl2) => spawn2(process.execPath, [
|
|
1715
|
+
import { join as join4 } from "path";
|
|
1716
|
+
var startMigrations = (root, databaseUrl2) => spawn2(process.execPath, [join4(root, "server", "migrations", "run.mjs")], {
|
|
1533
1717
|
cwd: root,
|
|
1534
1718
|
stdio: ["ignore", "pipe", "pipe"],
|
|
1535
1719
|
env: { ...process.env, DATABASE_URL: databaseUrl2 }
|
|
@@ -1558,8 +1742,8 @@ async function migrate(root, databaseUrl2) {
|
|
|
1558
1742
|
}
|
|
1559
1743
|
|
|
1560
1744
|
// src/install/k8s.ts
|
|
1561
|
-
import { mkdirSync, writeFileSync as writeFileSync2 } from "fs";
|
|
1562
|
-
import { join as
|
|
1745
|
+
import { mkdirSync as mkdirSync2, writeFileSync as writeFileSync2 } from "fs";
|
|
1746
|
+
import { join as join5 } from "path";
|
|
1563
1747
|
var POLICY_NAME = "oya-governed-egress";
|
|
1564
1748
|
function unpinnable(reference) {
|
|
1565
1749
|
return new Error(
|
|
@@ -1607,8 +1791,8 @@ function networkPolicy(namespace, name) {
|
|
|
1607
1791
|
return JSON.stringify(policy, null, JSON_INDENT);
|
|
1608
1792
|
}
|
|
1609
1793
|
function savePolicy(root, namespace) {
|
|
1610
|
-
const policyPath =
|
|
1611
|
-
|
|
1794
|
+
const policyPath = join5(root, "k8s", "fleet", "networkpolicy.json");
|
|
1795
|
+
mkdirSync2(join5(root, "k8s", "fleet"), { recursive: true });
|
|
1612
1796
|
writeFileSync2(policyPath, networkPolicy(namespace, POLICY_NAME) + "\n");
|
|
1613
1797
|
return policyPath;
|
|
1614
1798
|
}
|
|
@@ -1756,8 +1940,8 @@ function defaultInstall(env2 = process.env) {
|
|
|
1756
1940
|
}
|
|
1757
1941
|
|
|
1758
1942
|
// src/install/deployment.ts
|
|
1759
|
-
import { renameSync, writeFileSync as writeFileSync3 } from "fs";
|
|
1760
|
-
import { join as
|
|
1943
|
+
import { renameSync as renameSync2, writeFileSync as writeFileSync3 } from "fs";
|
|
1944
|
+
import { join as join7 } from "path";
|
|
1761
1945
|
|
|
1762
1946
|
// src/install/deployment-targets.ts
|
|
1763
1947
|
var DEPLOYMENT_TARGETS = {
|
|
@@ -2558,7 +2742,7 @@ async function showContextHint(target) {
|
|
|
2558
2742
|
|
|
2559
2743
|
// src/install/deployment-preflight.ts
|
|
2560
2744
|
import { existsSync as existsSync4 } from "fs";
|
|
2561
|
-
import { join as
|
|
2745
|
+
import { join as join6, resolve } from "path";
|
|
2562
2746
|
var VERSION_ARGS = {
|
|
2563
2747
|
openssl: ["version"],
|
|
2564
2748
|
kubectl: ["version", "--client=true", "-o", "json"]
|
|
@@ -2624,7 +2808,7 @@ function settingsChecks(root, p) {
|
|
|
2624
2808
|
return [{ ok, label: "Optional settings file", fatal: true, detail: "The selected env-file must exist." }];
|
|
2625
2809
|
}
|
|
2626
2810
|
function fileChecks(root, p) {
|
|
2627
|
-
const script =
|
|
2811
|
+
const script = join6(root, "deployments", p.target, "deploy.sh"), ok = existsSync4(script);
|
|
2628
2812
|
const detail = "Use an up-to-date Oya checkout containing deployments/.";
|
|
2629
2813
|
return [{ ok, label: `deployments/${p.target}/deploy.sh`, fatal: true, detail }, ...settingsChecks(root, p)];
|
|
2630
2814
|
}
|
|
@@ -2784,10 +2968,10 @@ function replayDeployment(flags, saved) {
|
|
|
2784
2968
|
return plan2;
|
|
2785
2969
|
}
|
|
2786
2970
|
function saveDeploymentPlan(root, p) {
|
|
2787
|
-
const path =
|
|
2971
|
+
const path = join7(root, PLAN_FILE), temporary = `${path}.${process.pid}.tmp`;
|
|
2788
2972
|
writeFileSync3(temporary, `${JSON.stringify(p, null, JSON_INDENT)}
|
|
2789
2973
|
`, { mode: ENV_FILE_MODE, flag: "wx" });
|
|
2790
|
-
|
|
2974
|
+
renameSync2(temporary, path);
|
|
2791
2975
|
note(`Saved ${path}; credentials stay in the target's secret store.`);
|
|
2792
2976
|
}
|
|
2793
2977
|
async function executeDeployment(root, p, databaseUrl2) {
|
|
@@ -2800,7 +2984,7 @@ async function executeDeployment(root, p, databaseUrl2) {
|
|
|
2800
2984
|
printDeploymentDone(p, root);
|
|
2801
2985
|
}
|
|
2802
2986
|
async function deployAndVerify(root, p, databaseUrl2) {
|
|
2803
|
-
const script =
|
|
2987
|
+
const script = join7(root, "deployments", p.target, "deploy.sh");
|
|
2804
2988
|
const env2 = deploymentEnvironment(p, databaseUrl2);
|
|
2805
2989
|
setupPhase("Deploy");
|
|
2806
2990
|
await runDeploymentScript(script, ["deploy", ...optionArguments(p.options)], root, env2);
|
|
@@ -2895,19 +3079,25 @@ async function guardKek(existing, answers, root, m) {
|
|
|
2895
3079
|
const reused = m.yes ? unattendedKek(volume) : await resolveKekConflict(volume, root);
|
|
2896
3080
|
if (reused) existing.OYA_PROFILE_SECRET = reused;
|
|
2897
3081
|
}
|
|
3082
|
+
var migrateUrlFor = (i, existing) => i.migrateUrl || (i.answers.database !== "sqlite" ? existing.DATABASE_URL || "" : "");
|
|
3083
|
+
function buildPlan(interviewed, envPath, existing) {
|
|
3084
|
+
const { answers, secrets } = interviewed;
|
|
3085
|
+
const migrateUrl = migrateUrlFor(interviewed, existing);
|
|
3086
|
+
return { ...interviewed, migrateUrl, envPath, existing, env: buildEnv(answers, secrets, existing) };
|
|
3087
|
+
}
|
|
2898
3088
|
async function plan(m) {
|
|
2899
3089
|
const interviewed = await gather(m);
|
|
2900
3090
|
const { root, answers, secrets } = interviewed;
|
|
2901
3091
|
await checkMachine(root, answers, m.dryRun);
|
|
2902
|
-
|
|
2903
|
-
const envPath = join7(root, ".env");
|
|
3092
|
+
const envPath = join8(root, ".env");
|
|
2904
3093
|
const existing = readEnv(envPath);
|
|
3094
|
+
warnLocalDatabase(answers, secrets.DATABASE_URL || existing.DATABASE_URL);
|
|
2905
3095
|
await guardKek(existing, answers, root, m);
|
|
2906
|
-
return
|
|
3096
|
+
return buildPlan(interviewed, envPath, existing);
|
|
2907
3097
|
}
|
|
2908
3098
|
function writeFiles(p) {
|
|
2909
3099
|
writeEnv(p.envPath, renderEnv(p.env.values, p.env.extra));
|
|
2910
|
-
writeFileSync4(
|
|
3100
|
+
writeFileSync4(join8(p.root, ANSWERS_FILE), JSON.stringify(p.answers, null, JSON_INDENT) + "\n");
|
|
2911
3101
|
success(`wrote ${p.envPath}`);
|
|
2912
3102
|
if (p.existing.OYA_PROFILE_SECRET) return;
|
|
2913
3103
|
warn("OYA_PROFILE_SECRET was generated, back it up.");
|
|
@@ -2938,105 +3128,6 @@ async function cmdInstall(flags) {
|
|
|
2938
3128
|
await apply2(p);
|
|
2939
3129
|
}
|
|
2940
3130
|
|
|
2941
|
-
// src/config.ts
|
|
2942
|
-
import { readFileSync as readFileSync3, writeFileSync as writeFileSync5, mkdirSync as mkdirSync2, chmodSync as chmodSync2 } from "fs";
|
|
2943
|
-
import { homedir } from "os";
|
|
2944
|
-
import { join as join8, dirname as dirname2 } from "path";
|
|
2945
|
-
|
|
2946
|
-
// src/constants.ts
|
|
2947
|
-
var ARGV_SKIP = 2;
|
|
2948
|
-
var KEY_TAIL = 4;
|
|
2949
|
-
var MIN_KEY_FOR_TAIL = 12;
|
|
2950
|
-
var LOGIN_TIMEOUT_MS = 6e4;
|
|
2951
|
-
var ExitCode = {
|
|
2952
|
-
/** Done. */
|
|
2953
|
-
DONE: 0,
|
|
2954
|
-
/** The request failed: the server or the browser refused it, or no answer came. */
|
|
2955
|
-
FAILED: 1,
|
|
2956
|
-
/** The command could not be run as typed; nothing was sent. */
|
|
2957
|
-
USAGE: 2
|
|
2958
|
-
};
|
|
2959
|
-
var JSON_INDENT2 = 2;
|
|
2960
|
-
var DEFAULT_BASE_URL = "https://oyabrowser.com";
|
|
2961
|
-
var CONFIG_FILE_MODE = 384;
|
|
2962
|
-
var PRIVATE_FILE_MODE = 384;
|
|
2963
|
-
var LsColumns = {
|
|
2964
|
-
/** Provider name. */
|
|
2965
|
-
PROVIDER: 14,
|
|
2966
|
-
/** Persona name. */
|
|
2967
|
-
PERSONA: 14,
|
|
2968
|
-
/** Browser name. */
|
|
2969
|
-
NAME: 18,
|
|
2970
|
-
/** Current URL, after the scheme is dropped. */
|
|
2971
|
-
URL: 40
|
|
2972
|
-
};
|
|
2973
|
-
var StatusColumns = {
|
|
2974
|
-
/** Recent actions shown. */
|
|
2975
|
-
RECENT: 10,
|
|
2976
|
-
/** Action name column. */
|
|
2977
|
-
ACTION: 18
|
|
2978
|
-
};
|
|
2979
|
-
var PERSONA_NAME_WIDTH = 20;
|
|
2980
|
-
var Status2 = {
|
|
2981
|
-
/** The API key was rejected. */
|
|
2982
|
-
UNAUTHORIZED: 401,
|
|
2983
|
-
/** A role refusal, or the auth layer's answer for an unknown key. */
|
|
2984
|
-
FORBIDDEN: 403,
|
|
2985
|
-
/** An endpoint another browser already holds. */
|
|
2986
|
-
CONFLICT: 409,
|
|
2987
|
-
/** A quota or a persona concurrency cap. */
|
|
2988
|
-
TOO_MANY_REQUESTS: 429
|
|
2989
|
-
};
|
|
2990
|
-
var MODELS_SHOWN = 8;
|
|
2991
|
-
|
|
2992
|
-
// src/config.ts
|
|
2993
|
-
var FILE = join8(process.env.OYA_CONFIG_HOME || join8(homedir(), ".oya"), "config.json");
|
|
2994
|
-
function load() {
|
|
2995
|
-
try {
|
|
2996
|
-
return JSON.parse(readFileSync3(FILE, "utf8"));
|
|
2997
|
-
} catch {
|
|
2998
|
-
return {};
|
|
2999
|
-
}
|
|
3000
|
-
}
|
|
3001
|
-
function save(values) {
|
|
3002
|
-
const merged = { ...load(), ...values };
|
|
3003
|
-
mkdirSync2(dirname2(FILE), { recursive: true });
|
|
3004
|
-
writeFileSync5(FILE, JSON.stringify(merged, null, JSON_INDENT2), { mode: CONFIG_FILE_MODE });
|
|
3005
|
-
chmodSync2(FILE, CONFIG_FILE_MODE);
|
|
3006
|
-
}
|
|
3007
|
-
var configPath = FILE;
|
|
3008
|
-
function first(flag, env2, saved, names) {
|
|
3009
|
-
if (flag) return { value: flag, from: names[0] };
|
|
3010
|
-
if (env2) return { value: env2, from: names[1] };
|
|
3011
|
-
return saved ? { value: saved, from: names[2] } : null;
|
|
3012
|
-
}
|
|
3013
|
-
function origin({ apiKey, baseUrl } = {}) {
|
|
3014
|
-
const saved = load();
|
|
3015
|
-
const url = first(baseUrl, process.env.OYA_BASE_URL, saved.baseUrl, URL_SOURCES);
|
|
3016
|
-
const address = (url?.value ?? DEFAULT_BASE_URL).replace(/\/+$/, "");
|
|
3017
|
-
const key = first(apiKey, process.env.OYA_API_KEY, savedKeyFor(saved, address), KEY_SOURCES);
|
|
3018
|
-
const found = { apiKey: key?.value ?? "", apiKeyFrom: key?.from ?? "none", baseUrl: address };
|
|
3019
|
-
return { ...found, baseUrlFrom: url?.from ?? "default", savedKey: !!saved.apiKey, savedUrl: saved.baseUrl };
|
|
3020
|
-
}
|
|
3021
|
-
function savedKeyFor(saved, address) {
|
|
3022
|
-
if (!saved.baseUrl || deploymentOf(saved.baseUrl) === deploymentOf(address)) return saved.apiKey;
|
|
3023
|
-
return void 0;
|
|
3024
|
-
}
|
|
3025
|
-
function deploymentOf(url) {
|
|
3026
|
-
try {
|
|
3027
|
-
const { origin: site, pathname } = new URL(String(url).trim());
|
|
3028
|
-
return `${site}${pathname.replace(/\/+$/, "")}`;
|
|
3029
|
-
} catch {
|
|
3030
|
-
return String(url).trim().replace(/\/+$/, "");
|
|
3031
|
-
}
|
|
3032
|
-
}
|
|
3033
|
-
var KEY_SOURCES = ["--key", "OYA_API_KEY", "saved"];
|
|
3034
|
-
var URL_SOURCES = ["--url", "OYA_BASE_URL", "saved"];
|
|
3035
|
-
function resolved() {
|
|
3036
|
-
const { apiKey, baseUrl } = origin();
|
|
3037
|
-
return { apiKey, baseUrl };
|
|
3038
|
-
}
|
|
3039
|
-
|
|
3040
3131
|
// ../sdk/dist/index.js
|
|
3041
3132
|
var DEFAULT_BASE_URL2 = "https://oyabrowser.com";
|
|
3042
3133
|
var DEFAULT_TIMEOUT_MS = 6e4;
|
|
@@ -3116,16 +3207,50 @@ function savedConfig() {
|
|
|
3116
3207
|
return {};
|
|
3117
3208
|
}
|
|
3118
3209
|
}
|
|
3210
|
+
var PRIVATE_DIR = 448;
|
|
3119
3211
|
var PRIVATE_FILE = 384;
|
|
3120
3212
|
var JSON_INDENT3 = 2;
|
|
3213
|
+
function ensurePrivateDir(fs, dir) {
|
|
3214
|
+
fs.mkdirSync(dir, { recursive: true, mode: PRIVATE_DIR });
|
|
3215
|
+
try {
|
|
3216
|
+
fs.chmodSync(dir, PRIVATE_DIR);
|
|
3217
|
+
} catch {
|
|
3218
|
+
}
|
|
3219
|
+
}
|
|
3220
|
+
function openTemp(fs, tmp) {
|
|
3221
|
+
const { O_WRONLY, O_CREAT, O_EXCL, O_NOFOLLOW = 0 } = fs.constants;
|
|
3222
|
+
return fs.openSync(tmp, O_WRONLY | O_CREAT | O_EXCL | O_NOFOLLOW, PRIVATE_FILE);
|
|
3223
|
+
}
|
|
3224
|
+
function writeFd2(fs, fd, text) {
|
|
3225
|
+
try {
|
|
3226
|
+
fs.writeFileSync(fd, text);
|
|
3227
|
+
} finally {
|
|
3228
|
+
fs.closeSync(fd);
|
|
3229
|
+
}
|
|
3230
|
+
}
|
|
3231
|
+
function removeTemp2(fs, tmp) {
|
|
3232
|
+
try {
|
|
3233
|
+
fs.unlinkSync(tmp);
|
|
3234
|
+
} catch {
|
|
3235
|
+
}
|
|
3236
|
+
}
|
|
3237
|
+
var tempFile = (file2) => `${file2.slice(0, file2.lastIndexOf("/"))}/.config.json.${node()?.pid ?? 0}-${globalThis.crypto.randomUUID()}.tmp`;
|
|
3238
|
+
function writePrivate(fs, file2, text) {
|
|
3239
|
+
const tmp = tempFile(file2);
|
|
3240
|
+
try {
|
|
3241
|
+
writeFd2(fs, openTemp(fs, tmp), text);
|
|
3242
|
+
fs.renameSync(tmp, file2);
|
|
3243
|
+
} catch (err) {
|
|
3244
|
+
removeTemp2(fs, tmp);
|
|
3245
|
+
throw err;
|
|
3246
|
+
}
|
|
3247
|
+
}
|
|
3121
3248
|
function saveKey(apiKey, baseUrl) {
|
|
3122
3249
|
const fs = builtin("node:fs");
|
|
3123
3250
|
const file2 = configFile();
|
|
3124
3251
|
if (!fs || !file2 || savedConfig().apiKey) return false;
|
|
3125
|
-
fs
|
|
3126
|
-
fs
|
|
3127
|
-
mode: PRIVATE_FILE
|
|
3128
|
-
});
|
|
3252
|
+
ensurePrivateDir(fs, file2.slice(0, file2.lastIndexOf("/")));
|
|
3253
|
+
writePrivate(fs, file2, JSON.stringify({ ...savedConfig(), apiKey, baseUrl }, null, JSON_INDENT3));
|
|
3129
3254
|
return true;
|
|
3130
3255
|
}
|
|
3131
3256
|
var OPTIONS_ORIGIN = { apiKeyFrom: "the apiKey option", baseUrlFrom: "the baseUrl option", savedKey: false };
|
|
@@ -3383,12 +3508,12 @@ var Run = class {
|
|
|
3383
3508
|
/** Settles with the result when the run succeeds, or rejects when it fails. */
|
|
3384
3509
|
done;
|
|
3385
3510
|
/** The run's current state. */
|
|
3386
|
-
status() {
|
|
3387
|
-
return this.http.request("GET", `/api/runs/${
|
|
3511
|
+
async status() {
|
|
3512
|
+
return this.http.request("GET", `/api/runs/${segment(this.id)}`);
|
|
3388
3513
|
}
|
|
3389
3514
|
/** Answer the open attention request: `'done'` after handling it by hand, or your reply to the agent. */
|
|
3390
3515
|
async respond(response = "done") {
|
|
3391
|
-
await this.http.request("POST", `/api/runs/${
|
|
3516
|
+
await this.http.request("POST", `/api/runs/${segment(this.id)}/respond`, { response });
|
|
3392
3517
|
}
|
|
3393
3518
|
/** Polls until the run ends, firing callbacks on the way. */
|
|
3394
3519
|
watch(cb, pollMs) {
|
|
@@ -3424,7 +3549,7 @@ var Browser = class {
|
|
|
3424
3549
|
http;
|
|
3425
3550
|
/** Runs one browser command; a command that ran and failed throws. */
|
|
3426
3551
|
async command(action, params = {}, timeoutMs) {
|
|
3427
|
-
const path = `/api/browsers/${this.id}/command`;
|
|
3552
|
+
const path = `/api/browsers/${segment(this.id)}/command`;
|
|
3428
3553
|
const result = await this.http.request("POST", path, { action, params }, timeoutMs);
|
|
3429
3554
|
if (result.ok === false) throw new OyaError(result.error || `${action} failed`, Status3.UNPROCESSABLE, result);
|
|
3430
3555
|
return result.data;
|
|
@@ -3507,15 +3632,25 @@ var Browser = class {
|
|
|
3507
3632
|
* Detect and clear a CAPTCHA. Providers that solve natively are left to do
|
|
3508
3633
|
* it; everything else goes to the configured solver.
|
|
3509
3634
|
*/
|
|
3510
|
-
solveCaptcha() {
|
|
3511
|
-
return this.http.request(
|
|
3635
|
+
async solveCaptcha() {
|
|
3636
|
+
return this.http.request(
|
|
3637
|
+
"POST",
|
|
3638
|
+
`/api/browsers/${segment(this.id)}/captcha`,
|
|
3639
|
+
{},
|
|
3640
|
+
CHALLENGE_TIMEOUT_MS
|
|
3641
|
+
);
|
|
3512
3642
|
}
|
|
3513
3643
|
/**
|
|
3514
3644
|
* Answer an MFA prompt with the persona's configured factor. When nothing can
|
|
3515
3645
|
* answer it, `liveViewUrl` is where a person finishes by hand.
|
|
3516
3646
|
*/
|
|
3517
3647
|
async completeMfa() {
|
|
3518
|
-
const result = await this.http.request(
|
|
3648
|
+
const result = await this.http.request(
|
|
3649
|
+
"POST",
|
|
3650
|
+
`/api/browsers/${segment(this.id)}/mfa`,
|
|
3651
|
+
{},
|
|
3652
|
+
CHALLENGE_TIMEOUT_MS
|
|
3653
|
+
);
|
|
3519
3654
|
if (result.liveViewUrl) result.liveViewUrl = new URL(result.liveViewUrl, this.http.baseUrl).href;
|
|
3520
3655
|
return result;
|
|
3521
3656
|
}
|
|
@@ -3527,7 +3662,7 @@ var Browser = class {
|
|
|
3527
3662
|
*/
|
|
3528
3663
|
async ask(prompt, { data, secrets } = {}) {
|
|
3529
3664
|
const body = { messages: [{ role: "user", content: prompt }], data, secrets };
|
|
3530
|
-
const path = `/api/browsers/${this.id}/chat`;
|
|
3665
|
+
const path = `/api/browsers/${segment(this.id)}/chat`;
|
|
3531
3666
|
return agentAnswer(await this.http.request("POST", path, body, AGENT_TIMEOUT_MS)).text;
|
|
3532
3667
|
}
|
|
3533
3668
|
/**
|
|
@@ -3536,7 +3671,7 @@ var Browser = class {
|
|
|
3536
3671
|
*/
|
|
3537
3672
|
async extract(prompt, schema, values = {}) {
|
|
3538
3673
|
const body = { messages: [{ role: "user", content: prompt }], ...values, schema };
|
|
3539
|
-
const path = `/api/browsers/${this.id}/chat`;
|
|
3674
|
+
const path = `/api/browsers/${segment(this.id)}/chat`;
|
|
3540
3675
|
const res = agentAnswer(await this.http.request("POST", path, body, AGENT_TIMEOUT_MS));
|
|
3541
3676
|
if (res.failed || res.data === void 0) throw new OyaError(res.text, Status3.UNPROCESSABLE, res);
|
|
3542
3677
|
return res.data;
|
|
@@ -3547,8 +3682,13 @@ var Browser = class {
|
|
|
3547
3682
|
* `defaults`, so `play()` with nothing repeats the run and any one value can be
|
|
3548
3683
|
* swapped. `code` is the same flow as a Playwright module, to read or run yourself.
|
|
3549
3684
|
*/
|
|
3550
|
-
toPlaybook(name) {
|
|
3551
|
-
return this.http.request(
|
|
3685
|
+
async toPlaybook(name) {
|
|
3686
|
+
return this.http.request(
|
|
3687
|
+
"POST",
|
|
3688
|
+
`/api/browsers/${segment(this.id)}/playbooks`,
|
|
3689
|
+
{ name },
|
|
3690
|
+
PLAYBOOK_TIMEOUT_MS
|
|
3691
|
+
);
|
|
3552
3692
|
}
|
|
3553
3693
|
/**
|
|
3554
3694
|
* Replay a playbook with no LLM in the loop. Variables left out reuse the
|
|
@@ -3557,7 +3697,7 @@ var Browser = class {
|
|
|
3557
3697
|
* replaces the broken steps in the playbook (`healed`); off, the step's error is thrown.
|
|
3558
3698
|
*/
|
|
3559
3699
|
async play(name, data = {}, { autoHeal = true } = {}) {
|
|
3560
|
-
const path = `/api/browsers/${this.id}/playbooks/${segment(name, "name")}/play`;
|
|
3700
|
+
const path = `/api/browsers/${segment(this.id)}/playbooks/${segment(name, "name")}/play`;
|
|
3561
3701
|
return agentAnswer(
|
|
3562
3702
|
await this.http.request("POST", path, { variables: data, autoHeal }, AGENT_TIMEOUT_MS)
|
|
3563
3703
|
);
|
|
@@ -3570,7 +3710,10 @@ var Browser = class {
|
|
|
3570
3710
|
*/
|
|
3571
3711
|
async submit(task, options = {}) {
|
|
3572
3712
|
const { onSuccess, onFailure, onHumanAttention, onHealed, pollMs, ...body } = options;
|
|
3573
|
-
const started = await this.http.request("POST", `/api/browsers/${this.id}/runs`, {
|
|
3713
|
+
const started = await this.http.request("POST", `/api/browsers/${segment(this.id)}/runs`, {
|
|
3714
|
+
...task,
|
|
3715
|
+
...body
|
|
3716
|
+
});
|
|
3574
3717
|
return new Run(this.http, started.id, { onSuccess, onFailure, onHumanAttention, onHealed }, pollMs);
|
|
3575
3718
|
}
|
|
3576
3719
|
/**
|
|
@@ -3586,9 +3729,9 @@ var Browser = class {
|
|
|
3586
3729
|
* 60 seconds. Mint one per viewer, the first connection spends it.
|
|
3587
3730
|
*/
|
|
3588
3731
|
async liveStreamUrl() {
|
|
3589
|
-
const path = `/api/control/sessions/${
|
|
3732
|
+
const path = `/api/control/sessions/${segment(this.id)}/ticket`;
|
|
3590
3733
|
const { ticket } = await this.http.request("POST", path, {});
|
|
3591
|
-
return `${this.http.baseUrl}/api/live/${this.id}?ticket=${encodeURIComponent(ticket)}`;
|
|
3734
|
+
return `${this.http.baseUrl}/api/live/${segment(this.id)}?ticket=${encodeURIComponent(ticket)}`;
|
|
3592
3735
|
}
|
|
3593
3736
|
/**
|
|
3594
3737
|
* A shareable link to this browser's live view, for handing to a person or
|
|
@@ -3602,7 +3745,7 @@ var Browser = class {
|
|
|
3602
3745
|
* expires or you revoke it, so treat it like a password.
|
|
3603
3746
|
*/
|
|
3604
3747
|
async shareUrl({ control = false, expiresInSeconds = 3600 } = {}) {
|
|
3605
|
-
const path = `/api/control/sessions/${
|
|
3748
|
+
const path = `/api/control/sessions/${segment(this.id)}/share`;
|
|
3606
3749
|
const c = await this.http.request("POST", path, { control, expiresIn: expiresInSeconds });
|
|
3607
3750
|
return { url: shareLink(this.http.baseUrl, this.id, c.token), id: c.id, expiresAt: c.expiresAt };
|
|
3608
3751
|
}
|
|
@@ -3611,23 +3754,23 @@ var Browser = class {
|
|
|
3611
3754
|
await this.http.request("DELETE", `/api/control/credentials/${segment(id)}`);
|
|
3612
3755
|
}
|
|
3613
3756
|
/** Counters, health and the last 50 things this browser did. */
|
|
3614
|
-
status() {
|
|
3615
|
-
return this.http.request("GET", `/api/browsers/${this.id}`);
|
|
3757
|
+
async status() {
|
|
3758
|
+
return this.http.request("GET", `/api/browsers/${segment(this.id)}`);
|
|
3616
3759
|
}
|
|
3617
3760
|
/**
|
|
3618
3761
|
* Stop it, whatever it is: a cloud sandbox is destroyed so billing ends, a
|
|
3619
3762
|
* CDP session is handed back to its provider, a desktop browser disconnects.
|
|
3620
3763
|
*/
|
|
3621
|
-
stop() {
|
|
3764
|
+
async stop() {
|
|
3622
3765
|
if (this.reused) return this.endLane();
|
|
3623
|
-
return this.http.request("POST", `/api/browsers/${this.id}/stop`, {}, STOP_TIMEOUT_MS);
|
|
3766
|
+
return this.http.request("POST", `/api/browsers/${segment(this.id)}/stop`, {}, STOP_TIMEOUT_MS);
|
|
3624
3767
|
}
|
|
3625
3768
|
/**
|
|
3626
3769
|
* Ends this browser's lane, best effort: a server too old to know lanes, or one out of reach,
|
|
3627
3770
|
* leaves the tab to lapse on its own, and `stop()` on someone's browser has never thrown.
|
|
3628
3771
|
*/
|
|
3629
3772
|
async endLane() {
|
|
3630
|
-
await this.http.request("POST", `/api/browsers/${this.id}/lane/end`, {}, STOP_TIMEOUT_MS).catch(() => void 0);
|
|
3773
|
+
await this.http.request("POST", `/api/browsers/${segment(this.id)}/lane/end`, {}, STOP_TIMEOUT_MS).catch(() => void 0);
|
|
3631
3774
|
return { id: this.id, ok: true, reused: true };
|
|
3632
3775
|
}
|
|
3633
3776
|
/** `await using browser = await oya.browser.start()` stops it however the block exits, errors included. */
|
|
@@ -3664,7 +3807,7 @@ function consoleLink(baseUrl, id) {
|
|
|
3664
3807
|
return `${baseUrl}/dashboard/?browser=${encodeURIComponent(id)}`;
|
|
3665
3808
|
}
|
|
3666
3809
|
function shareLink(baseUrl, id, token2) {
|
|
3667
|
-
return `${baseUrl}/live/${
|
|
3810
|
+
return `${baseUrl}/live/${segment(id)}#t=${encodeURIComponent(token2)}`;
|
|
3668
3811
|
}
|
|
3669
3812
|
function startBody(options) {
|
|
3670
3813
|
const { profile, persona, provider, wsUrl, name, queueMs, priority, budgetUsd, governed, policy } = options;
|
|
@@ -4125,11 +4268,18 @@ var credentials = (token2, cookie = "") => ({
|
|
|
4125
4268
|
...token2 ? { Authorization: `Bearer ${token2}` } : {},
|
|
4126
4269
|
...cookie ? { Cookie: cookie } : {}
|
|
4127
4270
|
});
|
|
4271
|
+
function originOf(url) {
|
|
4272
|
+
try {
|
|
4273
|
+
return new URL(url).origin;
|
|
4274
|
+
} catch {
|
|
4275
|
+
return url;
|
|
4276
|
+
}
|
|
4277
|
+
}
|
|
4128
4278
|
async function postJson(url, body, token2, cookie = "") {
|
|
4129
4279
|
const headers = { ...credentials(token2, cookie), "Content-Type": "application/json" };
|
|
4130
4280
|
const signal = AbortSignal.timeout(LOGIN_TIMEOUT_MS);
|
|
4131
4281
|
const res = await fetch(url, { method: "POST", headers, body: JSON.stringify(body), signal }).catch(() => {
|
|
4132
|
-
throw new CliError(`Could not reach ${
|
|
4282
|
+
throw new CliError(`Could not reach ${originOf(url)}.`, "unreachable", {
|
|
4133
4283
|
hint: "Check the address, then run oya login again."
|
|
4134
4284
|
});
|
|
4135
4285
|
});
|
|
@@ -4199,10 +4349,32 @@ function namedFailure(err, baseUrl) {
|
|
|
4199
4349
|
if (status !== Status2.UNAUTHORIZED && status !== Status2.FORBIDDEN) return err;
|
|
4200
4350
|
return new CliError(`${baseUrl} rejected that key.`, "invalid_key", { hint: `Check the key, ${again}` });
|
|
4201
4351
|
}
|
|
4352
|
+
function withScheme(raw) {
|
|
4353
|
+
const trimmed = raw.trim();
|
|
4354
|
+
if (/^[a-z][a-z0-9+.-]*:/i.test(trimmed) && !/^[^:/]+:\d+(\/|$)/.test(trimmed)) return trimmed;
|
|
4355
|
+
return `${/^(localhost|127\.)/i.test(trimmed) ? "http" : "https"}://${trimmed}`;
|
|
4356
|
+
}
|
|
4357
|
+
function urlProblem(raw) {
|
|
4358
|
+
const bad = "That is not a URL, try https://oyabrowser.com or http://localhost:3100";
|
|
4359
|
+
try {
|
|
4360
|
+
const parsed = new URL(withScheme(raw));
|
|
4361
|
+
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") return "Must be http:// or https://";
|
|
4362
|
+
return parsed.hostname ? void 0 : bad;
|
|
4363
|
+
} catch {
|
|
4364
|
+
return bad;
|
|
4365
|
+
}
|
|
4366
|
+
}
|
|
4367
|
+
function normalizeLoginUrl(raw) {
|
|
4368
|
+
if (urlProblem(raw)) throw usage("Control plane URL must be an http:// or https:// address.");
|
|
4369
|
+
return withScheme(raw).replace(/\/+$/, "");
|
|
4370
|
+
}
|
|
4202
4371
|
async function loginUrl(flags) {
|
|
4203
4372
|
const current = resolved().baseUrl;
|
|
4204
|
-
const
|
|
4205
|
-
return
|
|
4373
|
+
const given = flagStr(flags, "url");
|
|
4374
|
+
if (given) return normalizeLoginUrl(given);
|
|
4375
|
+
if (flagStr(flags, "key")) return normalizeLoginUrl(current);
|
|
4376
|
+
const raw = await ask("Control plane URL:", current, { validate: urlProblem });
|
|
4377
|
+
return normalizeLoginUrl(raw);
|
|
4206
4378
|
}
|
|
4207
4379
|
async function cmdLogin(flags) {
|
|
4208
4380
|
if (flags.json && !flagStr(flags, "key")) throw usage("oya login --json never prompts, so it needs --key <key>.");
|
|
@@ -4530,7 +4702,6 @@ async function cmdPersonas(args, flags) {
|
|
|
4530
4702
|
}
|
|
4531
4703
|
|
|
4532
4704
|
// src/commands/cookies.ts
|
|
4533
|
-
import { chmodSync as chmodSync3, writeFileSync as writeFileSync6 } from "fs";
|
|
4534
4705
|
var FORMATS = ["json", "playwright"];
|
|
4535
4706
|
function formatOf(flags) {
|
|
4536
4707
|
const format = flagStr(flags, "format") || "json";
|
|
@@ -4538,8 +4709,7 @@ function formatOf(flags) {
|
|
|
4538
4709
|
throw usage(`Unknown format "${format}". Use --format json or --format playwright.`);
|
|
4539
4710
|
}
|
|
4540
4711
|
function writeJar(file, cookies) {
|
|
4541
|
-
|
|
4542
|
-
chmodSync3(file, PRIVATE_FILE_MODE);
|
|
4712
|
+
writePrivateFile(file, JSON.stringify(cookies, null, JSON_INDENT2) + "\n", PRIVATE_FILE_MODE);
|
|
4543
4713
|
}
|
|
4544
4714
|
var exportJar = async (oya, rest, flags) => {
|
|
4545
4715
|
if (!rest[0]) throw usage("oya cookies export needs a persona id: oya cookies export <persona> [--out <file>].");
|
|
@@ -4586,7 +4756,7 @@ async function cmdCookies(args, flags) {
|
|
|
4586
4756
|
}
|
|
4587
4757
|
|
|
4588
4758
|
// src/commands/playbooks.ts
|
|
4589
|
-
import { writeFileSync as
|
|
4759
|
+
import { writeFileSync as writeFileSync5 } from "fs";
|
|
4590
4760
|
var list2 = async (oya, _rest, flags) => {
|
|
4591
4761
|
const playbooks = await oya.playbooks.list();
|
|
4592
4762
|
out(flags, playbooks, () => {
|
|
@@ -4599,7 +4769,7 @@ var exportOne = async (oya, rest, flags) => {
|
|
|
4599
4769
|
const doc = await oya.playbooks.export(rest[0]);
|
|
4600
4770
|
const file = flagStr(flags, "out");
|
|
4601
4771
|
if (!file) return console.log(JSON.stringify(doc, null, JSON_INDENT2));
|
|
4602
|
-
|
|
4772
|
+
writeFileSync5(file, JSON.stringify(doc, null, JSON_INDENT2) + "\n");
|
|
4603
4773
|
out(flags, { ok: true, name: rest[0], file }, () => console.log(`\u2705 ${rest[0]} written to ${file}`));
|
|
4604
4774
|
};
|
|
4605
4775
|
var importOne = async (oya, rest, flags) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oya-ai/cli",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.265",
|
|
4
4
|
"description": "Command line for Oya, the HIPAA-compliant agentic browser: start browsers and run playbooks from your terminal.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://oyabrowser.com",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"access": "public"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
|
-
"@oya-ai/browser": "1.0.
|
|
53
|
+
"@oya-ai/browser": "1.0.265",
|
|
54
54
|
"@types/node": "^20.19.43",
|
|
55
55
|
"tsup": "^9.0.0",
|
|
56
56
|
"typescript": "^6.0.3"
|