@xbrowser/cli 1.0.0 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/README.md +17 -26
  2. package/dist/{browser-DSVV4GHS.js → browser-5CTOA2WS.js} +4 -3
  3. package/dist/{browser-53KUFEEM.js → browser-ITLZZDHJ.js} +5 -5
  4. package/dist/{browser-GURRY444.js → browser-IUJXXNBT.js} +6 -3
  5. package/dist/{cdp-driver-MNPR3HZH.js → cdp-driver-4X3DK6PS.js} +339 -59
  6. package/dist/{cdp-driver-SSXUGXP6.js → cdp-driver-D6WMSMWX.js} +4 -3
  7. package/dist/chunk-2SVQTI2O.js +2794 -0
  8. package/dist/{chunk-IDVD44ED.js → chunk-6WOSXSCQ.js} +23 -7
  9. package/dist/{chunk-ZZ2TFWIV.js → chunk-ABXMBNQ6.js} +1 -1
  10. package/dist/{chunk-2MFXKN32.js → chunk-ACFE6PKF.js} +1013 -119
  11. package/dist/chunk-AMI64BSD.js +268 -0
  12. package/dist/{chunk-E4O5ZU3H.js → chunk-DKWR54XQ.js} +412 -98
  13. package/dist/{chunk-DTJRVA76.js → chunk-ETCO4SNK.js} +2 -2
  14. package/dist/chunk-GDKLH7ZY.js +8 -0
  15. package/dist/chunk-KFQGP6VL.js +33 -0
  16. package/dist/{chunk-2BQZIT3S.js → chunk-LRBSUKUZ.js} +85 -2497
  17. package/dist/{chunk-ITKPSIP7.js → chunk-MDAPTB7C.js} +6 -25
  18. package/dist/{chunk-42RPMJ76.js → chunk-N2JFPWMI.js} +342 -60
  19. package/dist/chunk-OZKD3W4X.js +417 -0
  20. package/dist/{chunk-T4J4C2NZ.js → chunk-TNEN6VQ2.js} +17 -4
  21. package/dist/{chunk-YKOHDEFV.js → chunk-TWWOIJM7.js} +74 -38
  22. package/dist/chunk-WJRE55TN.js +83 -0
  23. package/dist/cli.js +1558 -1122
  24. package/dist/{convert-EGFYNICZ.js → convert-LB3GJTLR.js} +3 -3
  25. package/dist/{convert-EKQVHKB4.js → convert-R3XXYKC6.js} +2 -2
  26. package/dist/{daemon-client-YAVQ343A.js → daemon-client-3JOKX2L2.js} +3 -2
  27. package/dist/{daemon-client-3VM7VU7O.js → daemon-client-DIEHGP5B.js} +28 -74
  28. package/dist/daemon-main.js +2296 -1722
  29. package/dist/{extract-JUOQQX4V.js → extract-2ZFW2MX7.js} +1 -1
  30. package/dist/{extract-L2IW3IUB.js → extract-BSYBM4MR.js} +1 -1
  31. package/dist/{filter-HC4RA7JY.js → filter-KCFO4RSV.js} +1 -1
  32. package/dist/{filter-VID2GGZ7.js → filter-T7DSZ2X7.js} +1 -1
  33. package/dist/{human-interaction-W753RVJB.js → human-interaction-UKAS5ZXV.js} +2 -2
  34. package/dist/index.d.ts +166 -109
  35. package/dist/index.js +2668 -1742
  36. package/dist/launcher-L2JNDB2H.js +20 -0
  37. package/dist/{launcher-KA7J32K5.js → launcher-OZXJQPNG.js} +1 -1
  38. package/dist/{network-store-66A2RATI.js → network-store-XGZ25FFC.js} +1 -1
  39. package/dist/{network-store-BN6QEZ7R.js → network-store-YVDNUREI.js} +1 -1
  40. package/dist/{parse-action-dsl-T3DYC33D.js → parse-action-dsl-UM333TL2.js} +1 -1
  41. package/dist/{proxy-WKGUCH2C.js → proxy-C6CK3UH5.js} +2 -2
  42. package/dist/session-recorder-RTDGURIJ.js +8 -0
  43. package/dist/session-recorder-YI7YYM36.js +7 -0
  44. package/dist/session-replayer-MY27H4DX.js +276 -0
  45. package/dist/site-knowledge-SYC6VCDB.js +23 -0
  46. package/package.json +5 -4
  47. package/dist/screenshot-CWAWMXVA.js +0 -28
  48. package/dist/session-recorder-MA75PKTQ.js +0 -7
@@ -1,4 +1,4 @@
1
- import "./chunk-3RG5ZIWI.js";
1
+ import "./chunk-KFQGP6VL.js";
2
2
 
3
3
  // src/commands/convert.ts
4
4
  function escapeString(str) {
@@ -11,12 +11,12 @@ function generateJSScript(recording) {
11
11
  // Start URL: ${recording.startUrl}
12
12
  // Events: ${events.length}
13
13
 
14
- import { chromium } from 'playwright';
14
+ import { launch } from '@xbrowser/cli';
15
15
 
16
16
  const START_URL = '${escapeString(recording.startUrl)}';
17
17
 
18
18
  async function main() {
19
- const browser = await chromium.launch({ headless: true });
19
+ const { browser } = await launch({ headless: true });
20
20
  const context = await browser.newContext();
21
21
  const page = await context.newPage();
22
22
 
@@ -2,8 +2,8 @@ import {
2
2
  generateBashScript,
3
3
  generateJSScript,
4
4
  generatePythonScript
5
- } from "./chunk-DTJRVA76.js";
6
- import "./chunk-3RG5ZIWI.js";
5
+ } from "./chunk-ETCO4SNK.js";
6
+ import "./chunk-KFQGP6VL.js";
7
7
  export {
8
8
  generateBashScript,
9
9
  generateJSScript,
@@ -29,8 +29,9 @@ import {
29
29
  forwardSessionList,
30
30
  forwardViewerCheckSelector,
31
31
  isDaemonRunning
32
- } from "./chunk-IDVD44ED.js";
33
- import "./chunk-3RG5ZIWI.js";
32
+ } from "./chunk-6WOSXSCQ.js";
33
+ import "./chunk-GDKLH7ZY.js";
34
+ import "./chunk-KFQGP6VL.js";
34
35
  export {
35
36
  daemonPing,
36
37
  forwardAgentAct,
@@ -1,68 +1,10 @@
1
- import "./chunk-3RG5ZIWI.js";
2
-
3
- // src/daemon/daemon.ts
4
- import { spawn } from "child_process";
5
- import { join, dirname } from "path";
6
- import { homedir } from "os";
7
- import { fileURLToPath } from "url";
8
- import { stopDaemon as xcliStopDaemon, isDaemonRunning, getDaemonStatus, killAllDaemon } from "@dyyz1993/xcli-core";
9
- var CONFIG_DIR = join(homedir(), ".xbrowser");
10
- var __dirname = dirname(fileURLToPath(import.meta.url));
11
- var WORKER_PATH = join(__dirname, "daemon-main.js");
12
- function getDaemonConfig() {
13
- return {
14
- configDir: CONFIG_DIR,
15
- workerEntryPath: WORKER_PATH,
16
- basePort: 9224
17
- };
18
- }
19
- async function startDaemonProcess(port = 9224) {
20
- const config = getDaemonConfig();
21
- if (isDaemonRunning(config)) {
22
- const status = getDaemonStatus(config);
23
- if (status.port === port && status.pid) {
24
- return { pid: status.pid, port: status.port, startedAt: (/* @__PURE__ */ new Date()).toISOString() };
25
- }
26
- await xcliStopDaemon(config);
27
- }
28
- const child = spawn("node", [WORKER_PATH], {
29
- detached: true,
30
- stdio: "ignore",
31
- env: {
32
- ...process.env,
33
- XBROWSER_DAEMON_PORT: String(port)
34
- }
35
- });
36
- child.unref();
37
- return new Promise((resolve, reject) => {
38
- let resolved = false;
39
- const timeout = setTimeout(() => {
40
- if (!resolved) {
41
- resolved = true;
42
- reject(new Error("Daemon start timeout after 15s"));
43
- }
44
- }, 15e3);
45
- const checkInterval = setInterval(() => {
46
- if (isDaemonRunning(config)) {
47
- const s = getDaemonStatus(config);
48
- if (s.port === port && s.pid) {
49
- resolved = true;
50
- clearTimeout(timeout);
51
- clearInterval(checkInterval);
52
- resolve({ pid: s.pid, port: s.port, startedAt: (/* @__PURE__ */ new Date()).toISOString() });
53
- }
54
- }
55
- }, 200);
56
- child.on("error", (err) => {
57
- if (!resolved) {
58
- resolved = true;
59
- clearTimeout(timeout);
60
- clearInterval(checkInterval);
61
- reject(err);
62
- }
63
- });
64
- });
65
- }
1
+ import {
2
+ startDaemonProcess
3
+ } from "./chunk-WJRE55TN.js";
4
+ import {
5
+ errMsg
6
+ } from "./chunk-GDKLH7ZY.js";
7
+ import "./chunk-KFQGP6VL.js";
66
8
 
67
9
  // src/client/daemon-client.ts
68
10
  var DAEMON_PORT = 9224;
@@ -92,6 +34,12 @@ async function ensureDaemonRunning() {
92
34
  _ensurePromise = null;
93
35
  throw new Error("Daemon not available");
94
36
  }
37
+ for (let attempt = 0; attempt < 20; attempt++) {
38
+ const ready = await fetch(`${DAEMON_BASE}/health`, { signal: AbortSignal.timeout(1e3) }).then((r) => r.ok ? r.json() : null).then((d) => d?.status === "ok").catch(() => false);
39
+ if (ready) return;
40
+ await new Promise((r) => setTimeout(r, 200));
41
+ }
42
+ throw new Error("Daemon HTTP server not ready after 4s");
95
43
  }
96
44
  async function rpcCall(method, params = {}, timeoutMs = 1e4) {
97
45
  await ensureDaemonRunning();
@@ -102,11 +50,17 @@ async function rpcCall(method, params = {}, timeoutMs = 1e4) {
102
50
  signal: AbortSignal.timeout(timeoutMs)
103
51
  });
104
52
  if (!resp.ok) {
105
- throw new Error(`Daemon error: ${resp.statusText}`);
53
+ let detail = resp.statusText;
54
+ try {
55
+ const body = await resp.json();
56
+ if (body?.error) detail = body.error;
57
+ } catch {
58
+ }
59
+ throw new Error(`Daemon error: ${detail}`);
106
60
  }
107
61
  return resp.json();
108
62
  }
109
- async function isDaemonRunning2() {
63
+ async function isDaemonRunning() {
110
64
  try {
111
65
  const resp = await fetch(`${DAEMON_BASE}/health`, { signal: AbortSignal.timeout(2e3) });
112
66
  if (!resp.ok) return false;
@@ -139,8 +93,8 @@ async function forwardExec(command, params, session = "default", cdpEndpoint, ti
139
93
  if (cdpEndpoint) rpcParams.cdpEndpoint = cdpEndpoint;
140
94
  try {
141
95
  return await rpcCall("exec", rpcParams, timeoutMs);
142
- } catch {
143
- return { success: false, data: null, message: `Daemon error: exec failed`, duration: 0 };
96
+ } catch (e) {
97
+ return { success: false, data: null, message: errMsg(e), duration: 0 };
144
98
  }
145
99
  }
146
100
  async function forwardChain(input, session = "default", cdpEndpoint) {
@@ -148,8 +102,8 @@ async function forwardChain(input, session = "default", cdpEndpoint) {
148
102
  if (cdpEndpoint) params.cdpEndpoint = cdpEndpoint;
149
103
  try {
150
104
  return await rpcCall("chain", params, 12e4);
151
- } catch {
152
- return { success: false, steps: [], totalDuration: 0, stoppedReason: "Daemon error" };
105
+ } catch (e) {
106
+ return { success: false, steps: [], totalDuration: 0, stoppedReason: errMsg(e) };
153
107
  }
154
108
  }
155
109
  async function forwardAgentObserve(session = "default", options) {
@@ -205,8 +159,8 @@ async function forwardNetworkExport(sessionName, id, lang) {
205
159
  async function forwardNetworkInspect(sessionName, id) {
206
160
  return rpcCall("network:inspect", { session: sessionName, id }, 1e4);
207
161
  }
208
- async function forwardRecordStart(session, url) {
209
- return rpcCall("record:start", { session, url }, 15e3);
162
+ async function forwardRecordStart(session, url, cdpEndpoint) {
163
+ return rpcCall("record:start", { session, url, cdpEndpoint }, 15e3);
210
164
  }
211
165
  async function forwardRecordStop(session) {
212
166
  return rpcCall("record:stop", { session }, 1e4);
@@ -259,5 +213,5 @@ export {
259
213
  forwardSessionCreate,
260
214
  forwardSessionList,
261
215
  forwardViewerCheckSelector,
262
- isDaemonRunning2 as isDaemonRunning
216
+ isDaemonRunning
263
217
  };