@xbrowser/cli 1.0.0 → 1.0.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 (46) hide show
  1. package/README.md +17 -26
  2. package/dist/{browser-GURRY444.js → browser-GITRHHFO.js} +4 -3
  3. package/dist/{browser-DSVV4GHS.js → browser-R56O3CW6.js} +3 -3
  4. package/dist/{browser-53KUFEEM.js → browser-ZJOZB5CR.js} +4 -4
  5. package/dist/{cdp-driver-MNPR3HZH.js → cdp-driver-BE3FOMRN.js} +324 -58
  6. package/dist/{cdp-driver-SSXUGXP6.js → cdp-driver-TOPYJIFL.js} +3 -3
  7. package/dist/chunk-2SVQTI2O.js +2794 -0
  8. package/dist/{chunk-2MFXKN32.js → chunk-ACFE6PKF.js} +1013 -119
  9. package/dist/chunk-BBMRDUYQ.js +260 -0
  10. package/dist/{chunk-E4O5ZU3H.js → chunk-CAFNSGYM.js} +393 -95
  11. package/dist/{chunk-DTJRVA76.js → chunk-ETCO4SNK.js} +2 -2
  12. package/dist/{chunk-YKOHDEFV.js → chunk-JPA2ZT2R.js} +69 -36
  13. package/dist/{chunk-T4J4C2NZ.js → chunk-JPHCY4TC.js} +12 -2
  14. package/dist/chunk-KFQGP6VL.js +33 -0
  15. package/dist/{chunk-ITKPSIP7.js → chunk-MDAPTB7C.js} +6 -25
  16. package/dist/chunk-OZKD3W4X.js +417 -0
  17. package/dist/{chunk-42RPMJ76.js → chunk-PPG4D2EW.js} +325 -59
  18. package/dist/{chunk-IDVD44ED.js → chunk-Q4IGYTKR.js} +19 -7
  19. package/dist/{chunk-2BQZIT3S.js → chunk-QIK2I3VQ.js} +86 -2501
  20. package/dist/chunk-WJRE55TN.js +83 -0
  21. package/dist/cli.js +1435 -1077
  22. package/dist/{convert-EGFYNICZ.js → convert-LB3GJTLR.js} +3 -3
  23. package/dist/{convert-EKQVHKB4.js → convert-R3XXYKC6.js} +2 -2
  24. package/dist/{daemon-client-3VM7VU7O.js → daemon-client-DRCUMNHK.js} +25 -74
  25. package/dist/{daemon-client-YAVQ343A.js → daemon-client-UZZEHHIV.js} +2 -2
  26. package/dist/daemon-main.js +2200 -1691
  27. package/dist/{extract-JUOQQX4V.js → extract-2ZFW2MX7.js} +1 -1
  28. package/dist/{extract-L2IW3IUB.js → extract-BSYBM4MR.js} +1 -1
  29. package/dist/{filter-HC4RA7JY.js → filter-KCFO4RSV.js} +1 -1
  30. package/dist/{filter-VID2GGZ7.js → filter-T7DSZ2X7.js} +1 -1
  31. package/dist/{human-interaction-W753RVJB.js → human-interaction-UKAS5ZXV.js} +2 -2
  32. package/dist/index.d.ts +165 -108
  33. package/dist/index.js +2531 -1680
  34. package/dist/launcher-QUJ4M2VS.js +19 -0
  35. package/dist/{launcher-KA7J32K5.js → launcher-YARP45UY.js} +1 -1
  36. package/dist/{network-store-66A2RATI.js → network-store-XGZ25FFC.js} +1 -1
  37. package/dist/{network-store-BN6QEZ7R.js → network-store-YVDNUREI.js} +1 -1
  38. package/dist/{parse-action-dsl-T3DYC33D.js → parse-action-dsl-UM333TL2.js} +1 -1
  39. package/dist/{proxy-WKGUCH2C.js → proxy-LV4BJ5RC.js} +1 -1
  40. package/dist/session-recorder-RTDGURIJ.js +8 -0
  41. package/dist/session-recorder-YI7YYM36.js +7 -0
  42. package/dist/session-replayer-GLTUICSD.js +276 -0
  43. package/dist/site-knowledge-SYC6VCDB.js +23 -0
  44. package/package.json +5 -4
  45. package/dist/screenshot-CWAWMXVA.js +0 -28
  46. 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,
@@ -1,68 +1,7 @@
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 "./chunk-KFQGP6VL.js";
66
5
 
67
6
  // src/client/daemon-client.ts
68
7
  var DAEMON_PORT = 9224;
@@ -92,6 +31,12 @@ async function ensureDaemonRunning() {
92
31
  _ensurePromise = null;
93
32
  throw new Error("Daemon not available");
94
33
  }
34
+ for (let attempt = 0; attempt < 20; attempt++) {
35
+ 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);
36
+ if (ready) return;
37
+ await new Promise((r) => setTimeout(r, 200));
38
+ }
39
+ throw new Error("Daemon HTTP server not ready after 4s");
95
40
  }
96
41
  async function rpcCall(method, params = {}, timeoutMs = 1e4) {
97
42
  await ensureDaemonRunning();
@@ -102,11 +47,17 @@ async function rpcCall(method, params = {}, timeoutMs = 1e4) {
102
47
  signal: AbortSignal.timeout(timeoutMs)
103
48
  });
104
49
  if (!resp.ok) {
105
- throw new Error(`Daemon error: ${resp.statusText}`);
50
+ let detail = resp.statusText;
51
+ try {
52
+ const body = await resp.json();
53
+ if (body?.error) detail = body.error;
54
+ } catch {
55
+ }
56
+ throw new Error(`Daemon error: ${detail}`);
106
57
  }
107
58
  return resp.json();
108
59
  }
109
- async function isDaemonRunning2() {
60
+ async function isDaemonRunning() {
110
61
  try {
111
62
  const resp = await fetch(`${DAEMON_BASE}/health`, { signal: AbortSignal.timeout(2e3) });
112
63
  if (!resp.ok) return false;
@@ -139,8 +90,8 @@ async function forwardExec(command, params, session = "default", cdpEndpoint, ti
139
90
  if (cdpEndpoint) rpcParams.cdpEndpoint = cdpEndpoint;
140
91
  try {
141
92
  return await rpcCall("exec", rpcParams, timeoutMs);
142
- } catch {
143
- return { success: false, data: null, message: `Daemon error: exec failed`, duration: 0 };
93
+ } catch (e) {
94
+ return { success: false, data: null, message: e.message, duration: 0 };
144
95
  }
145
96
  }
146
97
  async function forwardChain(input, session = "default", cdpEndpoint) {
@@ -148,8 +99,8 @@ async function forwardChain(input, session = "default", cdpEndpoint) {
148
99
  if (cdpEndpoint) params.cdpEndpoint = cdpEndpoint;
149
100
  try {
150
101
  return await rpcCall("chain", params, 12e4);
151
- } catch {
152
- return { success: false, steps: [], totalDuration: 0, stoppedReason: "Daemon error" };
102
+ } catch (e) {
103
+ return { success: false, steps: [], totalDuration: 0, stoppedReason: e.message };
153
104
  }
154
105
  }
155
106
  async function forwardAgentObserve(session = "default", options) {
@@ -205,8 +156,8 @@ async function forwardNetworkExport(sessionName, id, lang) {
205
156
  async function forwardNetworkInspect(sessionName, id) {
206
157
  return rpcCall("network:inspect", { session: sessionName, id }, 1e4);
207
158
  }
208
- async function forwardRecordStart(session, url) {
209
- return rpcCall("record:start", { session, url }, 15e3);
159
+ async function forwardRecordStart(session, url, cdpEndpoint) {
160
+ return rpcCall("record:start", { session, url, cdpEndpoint }, 15e3);
210
161
  }
211
162
  async function forwardRecordStop(session) {
212
163
  return rpcCall("record:stop", { session }, 1e4);
@@ -259,5 +210,5 @@ export {
259
210
  forwardSessionCreate,
260
211
  forwardSessionList,
261
212
  forwardViewerCheckSelector,
262
- isDaemonRunning2 as isDaemonRunning
213
+ isDaemonRunning
263
214
  };
@@ -29,8 +29,8 @@ import {
29
29
  forwardSessionList,
30
30
  forwardViewerCheckSelector,
31
31
  isDaemonRunning
32
- } from "./chunk-IDVD44ED.js";
33
- import "./chunk-3RG5ZIWI.js";
32
+ } from "./chunk-Q4IGYTKR.js";
33
+ import "./chunk-KFQGP6VL.js";
34
34
  export {
35
35
  daemonPing,
36
36
  forwardAgentAct,