libretto 0.4.4 → 0.5.0
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/cli/cli.js +20 -19
- package/dist/cli/commands/ai.js +1 -1
- package/dist/cli/commands/browser.js +3 -3
- package/dist/cli/commands/execution.js +3 -3
- package/dist/cli/commands/logs.js +1 -1
- package/dist/cli/core/browser.js +11 -6
- package/dist/cli/core/context.js +4 -18
- package/dist/cli/core/session.js +2 -2
- package/dist/cli/core/snapshot-analyzer.js +2 -2
- package/dist/cli/router.js +1 -1
- package/dist/cli/workers/run-integration-runtime.js +2 -2
- package/dist/shared/paths/paths.js +2 -1
- package/dist/shared/paths/repo-root.d.ts +3 -0
- package/dist/shared/paths/repo-root.js +24 -0
- package/package.json +6 -7
- package/scripts/postinstall.mjs +12 -3
- package/skills/libretto/SKILL.md +93 -404
- package/skills/libretto/references/auth-profiles.md +30 -0
- package/skills/libretto/references/pages-and-page-targeting.md +29 -0
- package/skills/libretto/references/reverse-engineering-network-requests.md +39 -0
- package/skills/libretto/references/user-action-log.md +31 -0
- package/src/cli/cli.ts +173 -0
- package/src/cli/commands/ai.ts +35 -0
- package/src/cli/commands/browser.ts +165 -0
- package/src/cli/commands/execution.ts +691 -0
- package/src/cli/commands/init.ts +327 -0
- package/src/cli/commands/logs.ts +128 -0
- package/src/cli/commands/shared.ts +70 -0
- package/src/cli/commands/snapshot.ts +327 -0
- package/src/cli/core/ai-config.ts +255 -0
- package/src/cli/core/api-snapshot-analyzer.ts +97 -0
- package/src/cli/core/browser.ts +839 -0
- package/src/cli/core/context.ts +122 -0
- package/src/cli/core/pause-signals.ts +35 -0
- package/src/cli/core/session-telemetry.ts +553 -0
- package/src/cli/core/session.ts +209 -0
- package/src/cli/core/snapshot-analyzer.ts +875 -0
- package/src/cli/core/snapshot-api-config.ts +236 -0
- package/src/cli/core/telemetry.ts +446 -0
- package/src/cli/framework/simple-cli.ts +1273 -0
- package/src/cli/index.ts +13 -0
- package/src/cli/router.ts +28 -0
- package/src/cli/workers/run-integration-runtime.ts +311 -0
- package/src/cli/workers/run-integration-worker-protocol.ts +14 -0
- package/src/cli/workers/run-integration-worker.ts +75 -0
- package/src/index.ts +120 -0
- package/src/runtime/download/download.ts +100 -0
- package/src/runtime/download/index.ts +7 -0
- package/src/runtime/extract/extract.ts +92 -0
- package/src/runtime/extract/index.ts +1 -0
- package/src/runtime/network/index.ts +5 -0
- package/src/runtime/network/network.ts +113 -0
- package/src/runtime/recovery/agent.ts +256 -0
- package/src/runtime/recovery/errors.ts +152 -0
- package/src/runtime/recovery/index.ts +7 -0
- package/src/runtime/recovery/recovery.ts +50 -0
- package/{dist/shared/condense-dom/condense-dom.cjs → src/shared/condense-dom/condense-dom.ts} +243 -115
- package/src/shared/config/config.ts +22 -0
- package/src/shared/config/index.ts +5 -0
- package/src/shared/debug/index.ts +1 -0
- package/src/shared/debug/pause.ts +85 -0
- package/src/shared/instrumentation/errors.ts +82 -0
- package/src/shared/instrumentation/index.ts +9 -0
- package/src/shared/instrumentation/instrument.ts +276 -0
- package/src/shared/llm/ai-sdk-adapter.ts +78 -0
- package/src/shared/llm/client.ts +217 -0
- package/src/shared/llm/index.ts +3 -0
- package/src/shared/llm/types.ts +63 -0
- package/src/shared/logger/index.ts +6 -0
- package/src/shared/logger/logger.ts +352 -0
- package/src/shared/logger/sinks.ts +144 -0
- package/src/shared/paths/paths.ts +109 -0
- package/src/shared/paths/repo-root.ts +27 -0
- package/src/shared/run/api.ts +2 -0
- package/src/shared/run/browser.ts +98 -0
- package/src/shared/state/index.ts +11 -0
- package/src/shared/state/session-state.ts +74 -0
- package/src/shared/visualization/ghost-cursor.ts +200 -0
- package/src/shared/visualization/highlight.ts +146 -0
- package/src/shared/visualization/index.ts +18 -0
- package/src/shared/workflow/workflow.ts +42 -0
- package/dist/index.cjs +0 -144
- package/dist/index.d.cts +0 -21
- package/dist/runtime/download/download.cjs +0 -70
- package/dist/runtime/download/download.d.cts +0 -35
- package/dist/runtime/download/index.cjs +0 -30
- package/dist/runtime/download/index.d.cts +0 -3
- package/dist/runtime/extract/extract.cjs +0 -88
- package/dist/runtime/extract/extract.d.cts +0 -23
- package/dist/runtime/extract/index.cjs +0 -28
- package/dist/runtime/extract/index.d.cts +0 -5
- package/dist/runtime/network/index.cjs +0 -28
- package/dist/runtime/network/index.d.cts +0 -4
- package/dist/runtime/network/network.cjs +0 -91
- package/dist/runtime/network/network.d.cts +0 -28
- package/dist/runtime/recovery/agent.cjs +0 -223
- package/dist/runtime/recovery/agent.d.cts +0 -13
- package/dist/runtime/recovery/errors.cjs +0 -124
- package/dist/runtime/recovery/errors.d.cts +0 -31
- package/dist/runtime/recovery/index.cjs +0 -34
- package/dist/runtime/recovery/index.d.cts +0 -7
- package/dist/runtime/recovery/recovery.cjs +0 -55
- package/dist/runtime/recovery/recovery.d.cts +0 -12
- package/dist/shared/condense-dom/condense-dom.d.cts +0 -34
- package/dist/shared/config/config.cjs +0 -44
- package/dist/shared/config/config.d.cts +0 -10
- package/dist/shared/config/index.cjs +0 -32
- package/dist/shared/config/index.d.cts +0 -1
- package/dist/shared/debug/index.cjs +0 -28
- package/dist/shared/debug/index.d.cts +0 -1
- package/dist/shared/debug/pause.cjs +0 -86
- package/dist/shared/debug/pause.d.cts +0 -12
- package/dist/shared/instrumentation/errors.cjs +0 -81
- package/dist/shared/instrumentation/errors.d.cts +0 -12
- package/dist/shared/instrumentation/index.cjs +0 -35
- package/dist/shared/instrumentation/index.d.cts +0 -6
- package/dist/shared/instrumentation/instrument.cjs +0 -206
- package/dist/shared/instrumentation/instrument.d.cts +0 -32
- package/dist/shared/llm/ai-sdk-adapter.cjs +0 -71
- package/dist/shared/llm/ai-sdk-adapter.d.cts +0 -22
- package/dist/shared/llm/client.cjs +0 -218
- package/dist/shared/llm/client.d.cts +0 -13
- package/dist/shared/llm/index.cjs +0 -31
- package/dist/shared/llm/index.d.cts +0 -5
- package/dist/shared/llm/types.cjs +0 -16
- package/dist/shared/llm/types.d.cts +0 -67
- package/dist/shared/logger/index.cjs +0 -37
- package/dist/shared/logger/index.d.cts +0 -2
- package/dist/shared/logger/logger.cjs +0 -232
- package/dist/shared/logger/logger.d.cts +0 -86
- package/dist/shared/logger/sinks.cjs +0 -160
- package/dist/shared/logger/sinks.d.cts +0 -9
- package/dist/shared/paths/paths.cjs +0 -104
- package/dist/shared/paths/paths.d.cts +0 -10
- package/dist/shared/run/api.cjs +0 -28
- package/dist/shared/run/api.d.cts +0 -2
- package/dist/shared/run/browser.cjs +0 -98
- package/dist/shared/run/browser.d.cts +0 -22
- package/dist/shared/state/index.cjs +0 -38
- package/dist/shared/state/index.d.cts +0 -2
- package/dist/shared/state/session-state.cjs +0 -92
- package/dist/shared/state/session-state.d.cts +0 -40
- package/dist/shared/visualization/ghost-cursor.cjs +0 -174
- package/dist/shared/visualization/ghost-cursor.d.cts +0 -37
- package/dist/shared/visualization/highlight.cjs +0 -134
- package/dist/shared/visualization/highlight.d.cts +0 -22
- package/dist/shared/visualization/index.cjs +0 -45
- package/dist/shared/visualization/index.d.cts +0 -3
- package/dist/shared/workflow/workflow.cjs +0 -47
- package/dist/shared/workflow/workflow.d.cts +0 -21
- package/skills/libretto/code-generation-rules.md +0 -223
- package/skills/libretto/integration-approach-selection.md +0 -174
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* DOM condensation — reduces serialized HTML for LLM consumption.
|
|
3
|
-
*
|
|
4
|
-
* All rules run unconditionally (no tiers). The function operates on
|
|
5
|
-
* already-serialized HTML strings (the output of `page.content()`),
|
|
6
|
-
* not a browser-side DOM walk or parsed DOM tree.
|
|
7
|
-
*
|
|
8
|
-
* Rules applied in order:
|
|
9
|
-
* 1. Noscript blocks — remove entirely
|
|
10
|
-
* 2. HTML comments — remove entirely
|
|
11
|
-
* 3. Script contents — hollow out, keep tags + useful attributes
|
|
12
|
-
* 4. Style contents — hollow out, keep tags + useful attributes
|
|
13
|
-
* 5. Embedded binary data — replace base64 data URIs
|
|
14
|
-
* 6. Attribute allowlist — keep trusted attrs, special-case class/style/URLs
|
|
15
|
-
* 7. SVG elements — collapse to single tag, extract title/desc
|
|
16
|
-
* 8. Inline style properties — keep only layout-relevant props
|
|
17
|
-
* 9. Non-semantic class names — filter or delete class values
|
|
18
|
-
* 10. (Cross-reference IDs — preserved, no action needed)
|
|
19
|
-
* 11. Framework-internal and SVG visual attributes — remove
|
|
20
|
-
* 12. Whitespace — collapse (preserve <pre> content)
|
|
21
|
-
*/
|
|
22
|
-
type CondenseDomResult = {
|
|
23
|
-
/** The condensed HTML string. Valid, parseable HTML. */
|
|
24
|
-
html: string;
|
|
25
|
-
/** Character count of the input. */
|
|
26
|
-
originalLength: number;
|
|
27
|
-
/** Character count of the output. */
|
|
28
|
-
condensedLength: number;
|
|
29
|
-
/** Characters removed, keyed by rule name. */
|
|
30
|
-
reductions: Record<string, number>;
|
|
31
|
-
};
|
|
32
|
-
declare function condenseDom(html: string): CondenseDomResult;
|
|
33
|
-
|
|
34
|
-
export { type CondenseDomResult, condenseDom };
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var config_exports = {};
|
|
20
|
-
__export(config_exports, {
|
|
21
|
-
isDebugMode: () => isDebugMode,
|
|
22
|
-
isDryRun: () => isDryRun,
|
|
23
|
-
shouldPauseBeforeMutation: () => shouldPauseBeforeMutation
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(config_exports);
|
|
26
|
-
function isDebugMode() {
|
|
27
|
-
return process.env.LIBRETTO_DEBUG === "true";
|
|
28
|
-
}
|
|
29
|
-
function isDryRun() {
|
|
30
|
-
const explicit = process.env.LIBRETTO_DRY_RUN;
|
|
31
|
-
if (explicit !== void 0) {
|
|
32
|
-
return explicit === "true";
|
|
33
|
-
}
|
|
34
|
-
return process.env.NODE_ENV === "development";
|
|
35
|
-
}
|
|
36
|
-
function shouldPauseBeforeMutation() {
|
|
37
|
-
return isDryRun() && isDebugMode();
|
|
38
|
-
}
|
|
39
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
40
|
-
0 && (module.exports = {
|
|
41
|
-
isDebugMode,
|
|
42
|
-
isDryRun,
|
|
43
|
-
shouldPauseBeforeMutation
|
|
44
|
-
});
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Runtime configuration for libretto.
|
|
3
|
-
*
|
|
4
|
-
* Values are derived from environment variables only.
|
|
5
|
-
*/
|
|
6
|
-
declare function isDebugMode(): boolean;
|
|
7
|
-
declare function isDryRun(): boolean;
|
|
8
|
-
declare function shouldPauseBeforeMutation(): boolean;
|
|
9
|
-
|
|
10
|
-
export { isDebugMode, isDryRun, shouldPauseBeforeMutation };
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var config_exports = {};
|
|
20
|
-
__export(config_exports, {
|
|
21
|
-
isDebugMode: () => import_config.isDebugMode,
|
|
22
|
-
isDryRun: () => import_config.isDryRun,
|
|
23
|
-
shouldPauseBeforeMutation: () => import_config.shouldPauseBeforeMutation
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(config_exports);
|
|
26
|
-
var import_config = require("./config.js");
|
|
27
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
28
|
-
0 && (module.exports = {
|
|
29
|
-
isDebugMode,
|
|
30
|
-
isDryRun,
|
|
31
|
-
shouldPauseBeforeMutation
|
|
32
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { isDebugMode, isDryRun, shouldPauseBeforeMutation } from './config.cjs';
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var debug_exports = {};
|
|
20
|
-
__export(debug_exports, {
|
|
21
|
-
pause: () => import_pause.pause
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(debug_exports);
|
|
24
|
-
var import_pause = require("./pause.js");
|
|
25
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
26
|
-
0 && (module.exports = {
|
|
27
|
-
pause
|
|
28
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { pause } from './pause.cjs';
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var pause_exports = {};
|
|
20
|
-
__export(pause_exports, {
|
|
21
|
-
pause: () => pause
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(pause_exports);
|
|
24
|
-
var import_node_fs = require("node:fs");
|
|
25
|
-
var import_promises = require("node:fs/promises");
|
|
26
|
-
var import_context = require("../../cli/core/context.js");
|
|
27
|
-
var import_pause_signals = require("../../cli/core/pause-signals.js");
|
|
28
|
-
var import_session = require("../../cli/core/session.js");
|
|
29
|
-
function isPidRunning(pid) {
|
|
30
|
-
try {
|
|
31
|
-
process.kill(pid, 0);
|
|
32
|
-
return true;
|
|
33
|
-
} catch {
|
|
34
|
-
return false;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
function getRunningSessions() {
|
|
38
|
-
return (0, import_session.listSessionsWithStateFile)().filter((candidate) => {
|
|
39
|
-
const state = (0, import_session.readSessionState)(candidate);
|
|
40
|
-
return state !== null && isPidRunning(state.pid);
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
function throwMissingSessionError() {
|
|
44
|
-
const runningSessions = getRunningSessions();
|
|
45
|
-
const lines = ["pause(session) requires a non-empty session ID."];
|
|
46
|
-
if (runningSessions.length > 0) {
|
|
47
|
-
lines.push("", "Running sessions:");
|
|
48
|
-
for (const runningSession of runningSessions) {
|
|
49
|
-
lines.push(` ${runningSession}`);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
throw new Error(lines.join("\n"));
|
|
53
|
-
}
|
|
54
|
-
async function pause(session) {
|
|
55
|
-
if (process.env.NODE_ENV === "production") {
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
if (typeof session !== "string" || session.trim().length === 0) {
|
|
59
|
-
throwMissingSessionError();
|
|
60
|
-
}
|
|
61
|
-
const signalPaths = (0, import_pause_signals.getPauseSignalPaths)(session);
|
|
62
|
-
const { pausedSignalPath, resumeSignalPath } = signalPaths;
|
|
63
|
-
await (0, import_promises.mkdir)((0, import_context.getSessionDir)(session), { recursive: true });
|
|
64
|
-
await (0, import_pause_signals.removeSignalIfExists)(resumeSignalPath);
|
|
65
|
-
const details = {
|
|
66
|
-
sessionName: session,
|
|
67
|
-
pausedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
68
|
-
url: "unknown"
|
|
69
|
-
};
|
|
70
|
-
await (0, import_promises.writeFile)(pausedSignalPath, JSON.stringify(details, null, 2), "utf8");
|
|
71
|
-
console.log(`[pause] Paused (session: ${session})`);
|
|
72
|
-
console.log("[pause] Waiting for resume signal...");
|
|
73
|
-
const RESUME_POLL_INTERVAL_MS = 250;
|
|
74
|
-
while (!(0, import_node_fs.existsSync)(resumeSignalPath)) {
|
|
75
|
-
await new Promise(
|
|
76
|
-
(resolve) => setTimeout(resolve, RESUME_POLL_INTERVAL_MS)
|
|
77
|
-
);
|
|
78
|
-
}
|
|
79
|
-
await (0, import_pause_signals.removeSignalIfExists)(resumeSignalPath);
|
|
80
|
-
await (0, import_pause_signals.removeSignalIfExists)(pausedSignalPath);
|
|
81
|
-
console.log("[pause] Resume signal received. Continuing workflow...");
|
|
82
|
-
}
|
|
83
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
84
|
-
0 && (module.exports = {
|
|
85
|
-
pause
|
|
86
|
-
});
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Standalone pause function.
|
|
3
|
-
*
|
|
4
|
-
* - In production (`NODE_ENV === "production"`), returns immediately (no-op).
|
|
5
|
-
* - Otherwise, writes a `.paused` signal file and polls for a `.resume` signal,
|
|
6
|
-
* using the same file-based mechanism as the CLI runner.
|
|
7
|
-
*
|
|
8
|
-
* Import directly: `import { pause } from "libretto";`
|
|
9
|
-
*/
|
|
10
|
-
declare function pause(session: string): Promise<void>;
|
|
11
|
-
|
|
12
|
-
export { pause };
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var errors_exports = {};
|
|
20
|
-
__export(errors_exports, {
|
|
21
|
-
enrichTimeoutError: () => enrichTimeoutError
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(errors_exports);
|
|
24
|
-
async function enrichTimeoutError(err, locator, page) {
|
|
25
|
-
const reasons = [];
|
|
26
|
-
try {
|
|
27
|
-
const visible = await locator.isVisible().catch(() => null);
|
|
28
|
-
if (visible === false) {
|
|
29
|
-
reasons.push("Element is not visible");
|
|
30
|
-
}
|
|
31
|
-
if (typeof locator.isInViewport === "function") {
|
|
32
|
-
const inViewport = await locator.isInViewport().catch(() => null);
|
|
33
|
-
if (inViewport === false) {
|
|
34
|
-
reasons.push("Element is outside of the viewport");
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
const enabled = await locator.isEnabled().catch(() => null);
|
|
38
|
-
if (enabled === false) {
|
|
39
|
-
reasons.push("Element is not enabled (disabled)");
|
|
40
|
-
}
|
|
41
|
-
if (reasons.length === 0) {
|
|
42
|
-
const box = await locator.boundingBox().catch(() => null);
|
|
43
|
-
if (box) {
|
|
44
|
-
const centerX = box.x + box.width / 2;
|
|
45
|
-
const centerY = box.y + box.height / 2;
|
|
46
|
-
const interceptInfo = await page.evaluate(
|
|
47
|
-
({ x, y }) => {
|
|
48
|
-
const els = document.elementsFromPoint(x, y);
|
|
49
|
-
if (!els || els.length < 2) return null;
|
|
50
|
-
const topEl = els[0];
|
|
51
|
-
if (!topEl) return null;
|
|
52
|
-
const tag = topEl.tagName.toLowerCase();
|
|
53
|
-
const id = topEl.id ? `#${topEl.id}` : "";
|
|
54
|
-
const cls = topEl.className ? `.${String(topEl.className).split(/\s+/).slice(0, 2).join(".")}` : "";
|
|
55
|
-
const text = (topEl.textContent || "").trim().slice(0, 40);
|
|
56
|
-
return {
|
|
57
|
-
tag,
|
|
58
|
-
preview: `<${tag}${id}${cls}>${text ? ` "${text}"` : ""}`
|
|
59
|
-
};
|
|
60
|
-
},
|
|
61
|
-
{ x: centerX, y: centerY }
|
|
62
|
-
).catch(() => null);
|
|
63
|
-
if (interceptInfo) {
|
|
64
|
-
reasons.push(
|
|
65
|
-
`Element may be intercepted by ${interceptInfo.preview}`
|
|
66
|
-
);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
} catch {
|
|
71
|
-
}
|
|
72
|
-
if (reasons.length > 0) {
|
|
73
|
-
const enrichment = `
|
|
74
|
-
[libretto diagnostics] ${reasons.join("; ")}`;
|
|
75
|
-
err.message = (err.message || "") + enrichment;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
79
|
-
0 && (module.exports = {
|
|
80
|
-
enrichTimeoutError
|
|
81
|
-
});
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { Locator, Page } from 'playwright';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Enrich a timeout error from a pointer action (click/dblclick/hover) with
|
|
5
|
-
* diagnostic information about why the action may have failed.
|
|
6
|
-
*
|
|
7
|
-
* Mutates err.message in-place to append the enrichment.
|
|
8
|
-
* Best-effort: if any probe fails, we skip that check silently.
|
|
9
|
-
*/
|
|
10
|
-
declare function enrichTimeoutError(err: any, locator: Locator, page: Page): Promise<void>;
|
|
11
|
-
|
|
12
|
-
export { enrichTimeoutError };
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var instrumentation_exports = {};
|
|
20
|
-
__export(instrumentation_exports, {
|
|
21
|
-
enrichTimeoutError: () => import_errors.enrichTimeoutError,
|
|
22
|
-
installInstrumentation: () => import_instrument.installInstrumentation,
|
|
23
|
-
instrumentContext: () => import_instrument.instrumentContext,
|
|
24
|
-
instrumentPage: () => import_instrument.instrumentPage
|
|
25
|
-
});
|
|
26
|
-
module.exports = __toCommonJS(instrumentation_exports);
|
|
27
|
-
var import_instrument = require("./instrument.js");
|
|
28
|
-
var import_errors = require("./errors.js");
|
|
29
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
30
|
-
0 && (module.exports = {
|
|
31
|
-
enrichTimeoutError,
|
|
32
|
-
installInstrumentation,
|
|
33
|
-
instrumentContext,
|
|
34
|
-
instrumentPage
|
|
35
|
-
});
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export { InstrumentationOptions, InstrumentedPage, installInstrumentation, instrumentContext, instrumentPage } from './instrument.cjs';
|
|
2
|
-
export { enrichTimeoutError } from './errors.cjs';
|
|
3
|
-
import 'playwright';
|
|
4
|
-
import '../logger/logger.cjs';
|
|
5
|
-
import '../visualization/ghost-cursor.cjs';
|
|
6
|
-
import '../visualization/highlight.cjs';
|
|
@@ -1,206 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var instrument_exports = {};
|
|
20
|
-
__export(instrument_exports, {
|
|
21
|
-
installInstrumentation: () => installInstrumentation,
|
|
22
|
-
instrumentContext: () => instrumentContext,
|
|
23
|
-
instrumentPage: () => instrumentPage
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(instrument_exports);
|
|
26
|
-
var import_ghost_cursor = require("../visualization/ghost-cursor.js");
|
|
27
|
-
var import_highlight = require("../visualization/highlight.js");
|
|
28
|
-
var import_errors = require("./errors.js");
|
|
29
|
-
const LOCATOR_ACTIONS = [
|
|
30
|
-
"click",
|
|
31
|
-
"dblclick",
|
|
32
|
-
"hover",
|
|
33
|
-
"fill",
|
|
34
|
-
"type",
|
|
35
|
-
"press",
|
|
36
|
-
"check",
|
|
37
|
-
"uncheck",
|
|
38
|
-
"selectOption",
|
|
39
|
-
"focus"
|
|
40
|
-
];
|
|
41
|
-
const NAV_ACTIONS = ["goto", "reload", "goBack", "goForward"];
|
|
42
|
-
const POINTER_ACTIONS = /* @__PURE__ */ new Set(["click", "dblclick", "hover"]);
|
|
43
|
-
const pageQueues = /* @__PURE__ */ new WeakMap();
|
|
44
|
-
function enqueue(page, fn) {
|
|
45
|
-
const prev = pageQueues.get(page) ?? Promise.resolve();
|
|
46
|
-
const next = prev.then(fn, fn);
|
|
47
|
-
pageQueues.set(page, next);
|
|
48
|
-
return next;
|
|
49
|
-
}
|
|
50
|
-
async function visualizeBeforeAction(page, box, actionName, highlightMs) {
|
|
51
|
-
if (!box) return;
|
|
52
|
-
await (0, import_ghost_cursor.ensureGhostCursor)(page);
|
|
53
|
-
await (0, import_highlight.ensureHighlightLayer)(page);
|
|
54
|
-
const centerX = box.x + box.width / 2;
|
|
55
|
-
const centerY = box.y + box.height / 2;
|
|
56
|
-
await (0, import_highlight.showHighlight)(page, {
|
|
57
|
-
box,
|
|
58
|
-
durationMs: highlightMs + 200
|
|
59
|
-
// keep visible a bit past the cursor arrival
|
|
60
|
-
});
|
|
61
|
-
const cursorPos = await (0, import_ghost_cursor.getGhostCursorPosition)(page);
|
|
62
|
-
if (cursorPos) {
|
|
63
|
-
await (0, import_ghost_cursor.moveGhostCursorWithDistance)(page, cursorPos, {
|
|
64
|
-
x: centerX,
|
|
65
|
-
y: centerY
|
|
66
|
-
});
|
|
67
|
-
} else {
|
|
68
|
-
await (0, import_ghost_cursor.moveGhostCursor)(page, { x: centerX, y: centerY, durationMs: 200 });
|
|
69
|
-
}
|
|
70
|
-
if (actionName === "click" || actionName === "dblclick") {
|
|
71
|
-
await (0, import_ghost_cursor.ghostClick)(page, { x: centerX, y: centerY });
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
async function visualizeAfterAction(page) {
|
|
75
|
-
await (0, import_highlight.clearHighlights)(page);
|
|
76
|
-
}
|
|
77
|
-
function wrapLocatorActions(locator, page, opts) {
|
|
78
|
-
for (const method of LOCATOR_ACTIONS) {
|
|
79
|
-
if (typeof locator[method] !== "function") continue;
|
|
80
|
-
const orig = locator[method].bind(locator);
|
|
81
|
-
locator[method] = async (...args) => {
|
|
82
|
-
if (opts.visualize) {
|
|
83
|
-
await enqueue(page, async () => {
|
|
84
|
-
try {
|
|
85
|
-
const box = await locator.boundingBox();
|
|
86
|
-
await visualizeBeforeAction(
|
|
87
|
-
page,
|
|
88
|
-
box,
|
|
89
|
-
method,
|
|
90
|
-
opts.highlightBeforeActionMs
|
|
91
|
-
);
|
|
92
|
-
} catch {
|
|
93
|
-
}
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
try {
|
|
97
|
-
const result = await orig(...args);
|
|
98
|
-
if (opts.visualize) {
|
|
99
|
-
enqueue(page, () => visualizeAfterAction(page));
|
|
100
|
-
}
|
|
101
|
-
return result;
|
|
102
|
-
} catch (err) {
|
|
103
|
-
if (opts.visualize) {
|
|
104
|
-
enqueue(page, () => visualizeAfterAction(page));
|
|
105
|
-
}
|
|
106
|
-
if (POINTER_ACTIONS.has(method) && isTimeoutError(err)) {
|
|
107
|
-
await (0, import_errors.enrichTimeoutError)(err, locator, page);
|
|
108
|
-
}
|
|
109
|
-
throw err;
|
|
110
|
-
}
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
function isTimeoutError(err) {
|
|
115
|
-
if (!err || typeof err.message !== "string") return false;
|
|
116
|
-
return err.message.includes("Timeout") || err.message.includes("timeout") || err.name === "TimeoutError";
|
|
117
|
-
}
|
|
118
|
-
const LOCATOR_FACTORIES = [
|
|
119
|
-
"locator",
|
|
120
|
-
"getByRole",
|
|
121
|
-
"getByText",
|
|
122
|
-
"getByLabel",
|
|
123
|
-
"getByPlaceholder",
|
|
124
|
-
"getByAltText",
|
|
125
|
-
"getByTitle",
|
|
126
|
-
"getByTestId"
|
|
127
|
-
];
|
|
128
|
-
async function installInstrumentation(page, options) {
|
|
129
|
-
if (page.__librettoInstrumented) return;
|
|
130
|
-
page.__librettoInstrumented = true;
|
|
131
|
-
const visualize = options?.visualize ?? false;
|
|
132
|
-
const highlightBeforeActionMs = options?.highlightBeforeActionMs ?? 350;
|
|
133
|
-
const mergedOpts = { ...options, visualize, highlightBeforeActionMs };
|
|
134
|
-
if (visualize) {
|
|
135
|
-
await (0, import_ghost_cursor.ensureGhostCursor)(page, options?.ghostCursor);
|
|
136
|
-
await (0, import_highlight.ensureHighlightLayer)(page, options?.highlight);
|
|
137
|
-
}
|
|
138
|
-
for (const method of LOCATOR_ACTIONS) {
|
|
139
|
-
if (typeof page[method] !== "function") continue;
|
|
140
|
-
const orig = page[method].bind(page);
|
|
141
|
-
page[method] = async (...args) => {
|
|
142
|
-
if (visualize && typeof args[0] === "string") {
|
|
143
|
-
await enqueue(page, async () => {
|
|
144
|
-
try {
|
|
145
|
-
const loc = page.locator(args[0]);
|
|
146
|
-
const box = await loc.boundingBox();
|
|
147
|
-
await visualizeBeforeAction(page, box, method, highlightBeforeActionMs);
|
|
148
|
-
} catch {
|
|
149
|
-
}
|
|
150
|
-
});
|
|
151
|
-
}
|
|
152
|
-
try {
|
|
153
|
-
const result = await orig(...args);
|
|
154
|
-
if (visualize) {
|
|
155
|
-
enqueue(page, () => visualizeAfterAction(page));
|
|
156
|
-
}
|
|
157
|
-
return result;
|
|
158
|
-
} catch (err) {
|
|
159
|
-
if (visualize) {
|
|
160
|
-
enqueue(page, () => visualizeAfterAction(page));
|
|
161
|
-
}
|
|
162
|
-
if (POINTER_ACTIONS.has(method) && isTimeoutError(err) && typeof args[0] === "string") {
|
|
163
|
-
await (0, import_errors.enrichTimeoutError)(err, page.locator(args[0]), page);
|
|
164
|
-
}
|
|
165
|
-
throw err;
|
|
166
|
-
}
|
|
167
|
-
};
|
|
168
|
-
}
|
|
169
|
-
for (const method of NAV_ACTIONS) {
|
|
170
|
-
if (typeof page[method] !== "function") continue;
|
|
171
|
-
const orig = page[method].bind(page);
|
|
172
|
-
page[method] = async (...args) => {
|
|
173
|
-
options?.logger?.info(`instrumentation:${method}`, {
|
|
174
|
-
url: typeof args[0] === "string" ? args[0] : page.url()
|
|
175
|
-
});
|
|
176
|
-
return orig(...args);
|
|
177
|
-
};
|
|
178
|
-
}
|
|
179
|
-
for (const factory of LOCATOR_FACTORIES) {
|
|
180
|
-
if (typeof page[factory] !== "function") continue;
|
|
181
|
-
const origFactory = page[factory].bind(page);
|
|
182
|
-
page[factory] = (...factoryArgs) => {
|
|
183
|
-
const locator = origFactory(...factoryArgs);
|
|
184
|
-
wrapLocatorActions(locator, page, mergedOpts);
|
|
185
|
-
return locator;
|
|
186
|
-
};
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
async function instrumentPage(page, options) {
|
|
190
|
-
await installInstrumentation(page, options);
|
|
191
|
-
return page;
|
|
192
|
-
}
|
|
193
|
-
async function instrumentContext(context, options) {
|
|
194
|
-
for (const page of context.pages()) {
|
|
195
|
-
await installInstrumentation(page, options);
|
|
196
|
-
}
|
|
197
|
-
context.on("page", async (page) => {
|
|
198
|
-
await installInstrumentation(page, options);
|
|
199
|
-
});
|
|
200
|
-
}
|
|
201
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
202
|
-
0 && (module.exports = {
|
|
203
|
-
installInstrumentation,
|
|
204
|
-
instrumentContext,
|
|
205
|
-
instrumentPage
|
|
206
|
-
});
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { Page, BrowserContext } from 'playwright';
|
|
2
|
-
import { MinimalLogger } from '../logger/logger.cjs';
|
|
3
|
-
import { GhostCursorOptions } from '../visualization/ghost-cursor.cjs';
|
|
4
|
-
import { HighlightOptions } from '../visualization/highlight.cjs';
|
|
5
|
-
|
|
6
|
-
type InstrumentationOptions = {
|
|
7
|
-
visualize?: boolean;
|
|
8
|
-
logger?: MinimalLogger;
|
|
9
|
-
highlightBeforeActionMs?: number;
|
|
10
|
-
ghostCursor?: GhostCursorOptions;
|
|
11
|
-
highlight?: HighlightOptions;
|
|
12
|
-
};
|
|
13
|
-
type InstrumentedPage = Page & {
|
|
14
|
-
__librettoInstrumented: true;
|
|
15
|
-
};
|
|
16
|
-
/**
|
|
17
|
-
* In-place patching of a Page object to add visualization and error enrichment.
|
|
18
|
-
* Modifies the page directly (does not return a new object).
|
|
19
|
-
*/
|
|
20
|
-
declare function installInstrumentation(page: Page, options?: InstrumentationOptions): Promise<void>;
|
|
21
|
-
/**
|
|
22
|
-
* Returns a new object that proxies to the page with instrumentation applied.
|
|
23
|
-
* The original page is not modified.
|
|
24
|
-
*/
|
|
25
|
-
declare function instrumentPage(page: Page, options?: InstrumentationOptions): Promise<InstrumentedPage>;
|
|
26
|
-
/**
|
|
27
|
-
* Install overlays on a page and auto-install on all future pages in the context.
|
|
28
|
-
* Useful when connecting to an existing browser via CDP.
|
|
29
|
-
*/
|
|
30
|
-
declare function instrumentContext(context: BrowserContext, options?: InstrumentationOptions): Promise<void>;
|
|
31
|
-
|
|
32
|
-
export { type InstrumentationOptions, type InstrumentedPage, installInstrumentation, instrumentContext, instrumentPage };
|