tesseract-agent 0.4.12 → 0.4.14
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/browser-cli.js +71 -0
- package/dist-bundle/cli.js +1989 -594
- package/package.json +1 -1
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// ../../packages/agent-core/src/browser-cli.ts
|
|
4
|
+
import { createConnection } from "node:net";
|
|
5
|
+
import { readFileSync } from "node:fs";
|
|
6
|
+
import { join } from "node:path";
|
|
7
|
+
import { tmpdir } from "node:os";
|
|
8
|
+
function getIpcPort() {
|
|
9
|
+
const envPort = parseInt(process.env.CCB_IPC_PORT ?? "0", 10);
|
|
10
|
+
if (envPort) return envPort;
|
|
11
|
+
try {
|
|
12
|
+
return parseInt(readFileSync(join(tmpdir(), "ccb-ipc-port"), "utf-8").trim(), 10);
|
|
13
|
+
} catch {
|
|
14
|
+
return 0;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
var IPC_PORT = getIpcPort();
|
|
18
|
+
var action = process.argv[2];
|
|
19
|
+
var params = process.argv[3] ? JSON.parse(process.argv[3]) : {};
|
|
20
|
+
if (!IPC_PORT || !action) {
|
|
21
|
+
console.error("Usage: browser-cli <action> [params-json]");
|
|
22
|
+
console.error("CCB_IPC_PORT not found in env or port file");
|
|
23
|
+
process.exit(1);
|
|
24
|
+
}
|
|
25
|
+
var requestId = crypto.randomUUID();
|
|
26
|
+
var sock = createConnection({ port: IPC_PORT, host: "127.0.0.1" }, () => {
|
|
27
|
+
sock.write(JSON.stringify({ requestId, action, params }) + "\n");
|
|
28
|
+
});
|
|
29
|
+
var buffer = "";
|
|
30
|
+
sock.on("data", (data) => {
|
|
31
|
+
buffer += data.toString();
|
|
32
|
+
const idx = buffer.indexOf("\n");
|
|
33
|
+
if (idx !== -1) {
|
|
34
|
+
const line = buffer.slice(0, idx);
|
|
35
|
+
try {
|
|
36
|
+
const msg = JSON.parse(line);
|
|
37
|
+
if (msg.requestId === requestId) {
|
|
38
|
+
if (msg.error) {
|
|
39
|
+
console.error(msg.error);
|
|
40
|
+
process.exit(1);
|
|
41
|
+
} else {
|
|
42
|
+
const result = msg.result;
|
|
43
|
+
if (typeof result === "object" && result !== null) {
|
|
44
|
+
if (action === "snapshot") {
|
|
45
|
+
console.log(`Page: ${result.title ?? "?"}
|
|
46
|
+
URL: ${result.url ?? "?"}
|
|
47
|
+
|
|
48
|
+
${result.snapshot ?? "No snapshot"}`);
|
|
49
|
+
} else if (action === "screenshot" && result.dataUrl) {
|
|
50
|
+
console.log("[Screenshot captured successfully]");
|
|
51
|
+
} else {
|
|
52
|
+
console.log(JSON.stringify(result, null, 2));
|
|
53
|
+
}
|
|
54
|
+
} else {
|
|
55
|
+
console.log(String(result));
|
|
56
|
+
}
|
|
57
|
+
process.exit(0);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
} catch {
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
sock.on("error", (err) => {
|
|
65
|
+
console.error(`Connection failed: ${err.message}`);
|
|
66
|
+
process.exit(1);
|
|
67
|
+
});
|
|
68
|
+
setTimeout(() => {
|
|
69
|
+
console.error("Browser request timed out");
|
|
70
|
+
process.exit(1);
|
|
71
|
+
}, 3e4);
|