tesseract-agent 0.1.0 → 0.1.1
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-bundle/cli.js +66 -21
- package/package.json +1 -1
package/dist-bundle/cli.js
CHANGED
|
@@ -6458,7 +6458,6 @@ async function runDaemon(opts = {}) {
|
|
|
6458
6458
|
}
|
|
6459
6459
|
|
|
6460
6460
|
// src/auth.ts
|
|
6461
|
-
import { createInterface } from "node:readline";
|
|
6462
6461
|
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
6463
6462
|
import { existsSync as existsSync6, rmSync } from "node:fs";
|
|
6464
6463
|
import { join as join7 } from "node:path";
|
|
@@ -6484,22 +6483,68 @@ function defaultLabel() {
|
|
|
6484
6483
|
}
|
|
6485
6484
|
|
|
6486
6485
|
// src/auth.ts
|
|
6487
|
-
|
|
6488
|
-
|
|
6486
|
+
var CR = String.fromCharCode(13);
|
|
6487
|
+
var LF = String.fromCharCode(10);
|
|
6488
|
+
var EOT = String.fromCharCode(4);
|
|
6489
|
+
var ETX = String.fromCharCode(3);
|
|
6490
|
+
var DEL = String.fromCharCode(127);
|
|
6491
|
+
var BS = String.fromCharCode(8);
|
|
6492
|
+
var ERASE = BS + " " + BS;
|
|
6493
|
+
function ask(question, hidden = false) {
|
|
6494
|
+
const { stdin, stdout } = process;
|
|
6489
6495
|
return new Promise((resolve3) => {
|
|
6490
|
-
|
|
6491
|
-
|
|
6492
|
-
|
|
6493
|
-
|
|
6494
|
-
|
|
6496
|
+
stdout.write(question);
|
|
6497
|
+
stdin.setEncoding("utf8");
|
|
6498
|
+
if (!stdin.isTTY || typeof stdin.setRawMode !== "function") {
|
|
6499
|
+
let data = "";
|
|
6500
|
+
const onLine = (chunk) => {
|
|
6501
|
+
data += chunk;
|
|
6502
|
+
const nl = data.indexOf(LF);
|
|
6503
|
+
if (nl >= 0) {
|
|
6504
|
+
stdin.removeListener("data", onLine);
|
|
6505
|
+
stdin.pause();
|
|
6506
|
+
let line = data.slice(0, nl);
|
|
6507
|
+
if (line.endsWith(CR)) line = line.slice(0, -1);
|
|
6508
|
+
resolve3(line.trim());
|
|
6509
|
+
}
|
|
6495
6510
|
};
|
|
6496
|
-
|
|
6511
|
+
stdin.resume();
|
|
6512
|
+
stdin.on("data", onLine);
|
|
6513
|
+
return;
|
|
6497
6514
|
}
|
|
6498
|
-
|
|
6499
|
-
|
|
6500
|
-
|
|
6501
|
-
|
|
6502
|
-
|
|
6515
|
+
stdin.setRawMode(true);
|
|
6516
|
+
stdin.resume();
|
|
6517
|
+
let buf = "";
|
|
6518
|
+
function done() {
|
|
6519
|
+
stdin.setRawMode(false);
|
|
6520
|
+
stdin.pause();
|
|
6521
|
+
stdin.removeListener("data", onData);
|
|
6522
|
+
stdout.write(LF);
|
|
6523
|
+
resolve3(buf.trim());
|
|
6524
|
+
}
|
|
6525
|
+
function onData(chunk) {
|
|
6526
|
+
for (const ch of chunk) {
|
|
6527
|
+
if (ch === CR || ch === LF || ch === EOT) {
|
|
6528
|
+
done();
|
|
6529
|
+
return;
|
|
6530
|
+
}
|
|
6531
|
+
if (ch === ETX) {
|
|
6532
|
+
stdin.setRawMode(false);
|
|
6533
|
+
stdout.write(LF);
|
|
6534
|
+
process.exit(130);
|
|
6535
|
+
}
|
|
6536
|
+
if (ch === DEL || ch === BS) {
|
|
6537
|
+
if (buf) {
|
|
6538
|
+
buf = buf.slice(0, -1);
|
|
6539
|
+
if (!hidden) stdout.write(ERASE);
|
|
6540
|
+
}
|
|
6541
|
+
continue;
|
|
6542
|
+
}
|
|
6543
|
+
buf += ch;
|
|
6544
|
+
if (!hidden) stdout.write(ch);
|
|
6545
|
+
}
|
|
6546
|
+
}
|
|
6547
|
+
stdin.on("data", onData);
|
|
6503
6548
|
});
|
|
6504
6549
|
}
|
|
6505
6550
|
async function login(opts) {
|
|
@@ -6507,8 +6552,8 @@ async function login(opts) {
|
|
|
6507
6552
|
const relay = (opts.relay ?? defaultRelay(api)).replace(/\/$/, "");
|
|
6508
6553
|
let token = opts.token;
|
|
6509
6554
|
if (!token) {
|
|
6510
|
-
const email = opts.email ?? await
|
|
6511
|
-
const password = opts.password ?? process.env.CCB_LOGIN_PASSWORD ?? await
|
|
6555
|
+
const email = opts.email ?? await ask("Email: ");
|
|
6556
|
+
const password = opts.password ?? process.env.CCB_LOGIN_PASSWORD ?? await ask("Password: ", true);
|
|
6512
6557
|
if (!email || !password) throw new Error("Email and password are required (or pass --token <jwt>).");
|
|
6513
6558
|
const r = await fetch(`${api}/auth/login`, {
|
|
6514
6559
|
method: "POST",
|
|
@@ -6520,7 +6565,7 @@ async function login(opts) {
|
|
|
6520
6565
|
}
|
|
6521
6566
|
if (!token) throw new Error("Login returned no token.");
|
|
6522
6567
|
const userId = decodeJwtSub(token);
|
|
6523
|
-
if (!userId) throw new Error("Could not read the user id from the token.");
|
|
6568
|
+
if (!userId) throw new Error("Could not read the user id from the token (is it a valid tesseract token?).");
|
|
6524
6569
|
const deviceId2 = readCredentials()?.deviceId ?? randomUUID2().slice(0, 8);
|
|
6525
6570
|
const label = opts.name ?? defaultLabel();
|
|
6526
6571
|
const mr = await fetch(`${api}/auth/device-token`, {
|
|
@@ -6540,8 +6585,8 @@ async function login(opts) {
|
|
|
6540
6585
|
apiOrigin: api,
|
|
6541
6586
|
expiresAt: dt.expiresAt
|
|
6542
6587
|
});
|
|
6543
|
-
console.log(
|
|
6544
|
-
console.log("
|
|
6588
|
+
console.log(`Logged in. This machine ("${label}", device ${deviceId2}) is provisioned for user ${userId}.`);
|
|
6589
|
+
console.log("Next: `tesseract-agent install` to run it as a background service (recommended), or `tesseract-agent run` to run it in the foreground.");
|
|
6545
6590
|
}
|
|
6546
6591
|
async function logout() {
|
|
6547
6592
|
const c = readCredentials();
|
|
@@ -6562,7 +6607,7 @@ async function logout() {
|
|
|
6562
6607
|
} catch {
|
|
6563
6608
|
}
|
|
6564
6609
|
}
|
|
6565
|
-
console.log("
|
|
6610
|
+
console.log("Logged out. Run `tesseract-agent uninstall` to also remove the background service.");
|
|
6566
6611
|
}
|
|
6567
6612
|
function whoami() {
|
|
6568
6613
|
const c = readCredentials();
|
|
@@ -6673,7 +6718,7 @@ function logs(system, follow) {
|
|
|
6673
6718
|
}
|
|
6674
6719
|
|
|
6675
6720
|
// src/cli.ts
|
|
6676
|
-
var CLI_VERSION = process.env.CCB_DAEMON_VERSION ?? "0.1.
|
|
6721
|
+
var CLI_VERSION = process.env.CCB_DAEMON_VERSION ?? "0.1.1";
|
|
6677
6722
|
function parseFlags(argv) {
|
|
6678
6723
|
const out = {};
|
|
6679
6724
|
for (let i = 0; i < argv.length; i++) {
|