libretto 0.4.4 → 0.5.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.
Files changed (194) hide show
  1. package/README.md +106 -36
  2. package/dist/cli/cli.js +39 -113
  3. package/dist/cli/commands/ai.js +1 -1
  4. package/dist/cli/commands/browser.js +87 -60
  5. package/dist/cli/commands/execution.js +201 -88
  6. package/dist/cli/commands/init.js +30 -8
  7. package/dist/cli/commands/logs.js +5 -6
  8. package/dist/cli/commands/shared.js +30 -29
  9. package/dist/cli/commands/snapshot.js +26 -39
  10. package/dist/cli/core/ai-config.js +9 -2
  11. package/dist/cli/core/api-snapshot-analyzer.js +15 -5
  12. package/dist/cli/core/browser.js +141 -33
  13. package/dist/cli/core/context.js +7 -18
  14. package/dist/cli/core/session-telemetry.js +5 -2
  15. package/dist/cli/core/session.js +23 -10
  16. package/dist/cli/core/snapshot-analyzer.js +16 -33
  17. package/dist/cli/core/snapshot-api-config.js +2 -6
  18. package/dist/cli/core/telemetry.js +10 -2
  19. package/dist/cli/framework/simple-cli.js +45 -25
  20. package/dist/cli/router.js +14 -21
  21. package/dist/cli/workers/run-integration-runtime.js +26 -7
  22. package/dist/cli/workers/run-integration-worker-protocol.js +3 -1
  23. package/dist/cli/workers/run-integration-worker.js +1 -4
  24. package/dist/index.d.ts +1 -2
  25. package/dist/index.js +7 -10
  26. package/dist/runtime/download/download.js +5 -1
  27. package/dist/runtime/extract/extract.js +11 -2
  28. package/dist/runtime/network/network.js +8 -1
  29. package/dist/runtime/recovery/agent.js +6 -2
  30. package/dist/runtime/recovery/errors.js +3 -1
  31. package/dist/runtime/recovery/recovery.js +3 -1
  32. package/dist/shared/condense-dom/condense-dom.js +6 -13
  33. package/dist/shared/config/config.d.ts +1 -9
  34. package/dist/shared/config/config.js +0 -18
  35. package/dist/shared/config/index.d.ts +2 -1
  36. package/dist/shared/config/index.js +0 -10
  37. package/dist/shared/debug/pause.js +9 -3
  38. package/dist/shared/instrumentation/instrument.js +101 -5
  39. package/dist/shared/llm/ai-sdk-adapter.js +3 -1
  40. package/dist/shared/llm/client.js +3 -1
  41. package/dist/shared/logger/index.js +4 -1
  42. package/dist/shared/paths/paths.js +2 -1
  43. package/dist/shared/paths/repo-root.d.ts +3 -0
  44. package/dist/shared/paths/repo-root.js +24 -0
  45. package/dist/shared/run/api.js +3 -1
  46. package/dist/shared/run/browser.js +7 -2
  47. package/dist/shared/state/session-state.d.ts +2 -1
  48. package/dist/shared/state/session-state.js +5 -2
  49. package/dist/shared/visualization/ghost-cursor.js +19 -10
  50. package/dist/shared/visualization/highlight.js +9 -6
  51. package/dist/shared/workflow/workflow.d.ts +4 -5
  52. package/dist/shared/workflow/workflow.js +3 -5
  53. package/package.json +11 -8
  54. package/scripts/check-skills-sync.mjs +25 -0
  55. package/scripts/compare-eval-summary.mjs +47 -0
  56. package/scripts/postinstall.mjs +26 -17
  57. package/scripts/prepare-release.sh +97 -0
  58. package/scripts/skills-libretto.mjs +103 -0
  59. package/scripts/summarize-evals.mjs +135 -0
  60. package/scripts/sync-skills.mjs +12 -0
  61. package/skills/libretto/SKILL.md +130 -377
  62. package/skills/libretto/references/auth-profiles.md +30 -0
  63. package/skills/libretto/{code-generation-rules.md → references/code-generation-rules.md} +27 -42
  64. package/skills/libretto/references/configuration-file-reference.md +53 -0
  65. package/skills/libretto/references/pages-and-page-targeting.md +29 -0
  66. package/skills/libretto/references/site-security-review.md +143 -0
  67. package/src/cli/cli.ts +86 -0
  68. package/src/cli/commands/ai.ts +35 -0
  69. package/src/cli/commands/browser.ts +189 -0
  70. package/src/cli/commands/execution.ts +822 -0
  71. package/src/cli/commands/init.ts +350 -0
  72. package/src/cli/commands/logs.ts +128 -0
  73. package/src/cli/commands/shared.ts +69 -0
  74. package/src/cli/commands/snapshot.ts +312 -0
  75. package/src/cli/core/ai-config.ts +264 -0
  76. package/src/cli/core/api-snapshot-analyzer.ts +108 -0
  77. package/src/cli/core/browser.ts +976 -0
  78. package/src/cli/core/context.ts +127 -0
  79. package/src/cli/core/pause-signals.ts +35 -0
  80. package/src/cli/core/session-telemetry.ts +564 -0
  81. package/src/cli/core/session.ts +223 -0
  82. package/src/cli/core/snapshot-analyzer.ts +855 -0
  83. package/src/cli/core/snapshot-api-config.ts +231 -0
  84. package/src/cli/core/telemetry.ts +459 -0
  85. package/src/cli/framework/simple-cli.ts +1340 -0
  86. package/src/cli/index.ts +13 -0
  87. package/src/cli/router.ts +20 -0
  88. package/src/cli/workers/run-integration-runtime.ts +338 -0
  89. package/src/cli/workers/run-integration-worker-protocol.ts +16 -0
  90. package/src/cli/workers/run-integration-worker.ts +72 -0
  91. package/src/index.ts +127 -0
  92. package/src/runtime/download/download.ts +104 -0
  93. package/src/runtime/download/index.ts +7 -0
  94. package/src/runtime/extract/extract.ts +102 -0
  95. package/src/runtime/extract/index.ts +1 -0
  96. package/src/runtime/network/index.ts +5 -0
  97. package/src/runtime/network/network.ts +119 -0
  98. package/{dist/runtime/recovery/agent.cjs → src/runtime/recovery/agent.ts} +114 -76
  99. package/src/runtime/recovery/errors.ts +155 -0
  100. package/src/runtime/recovery/index.ts +7 -0
  101. package/src/runtime/recovery/recovery.ts +53 -0
  102. package/{dist/shared/condense-dom/condense-dom.cjs → src/shared/condense-dom/condense-dom.ts} +249 -124
  103. package/src/shared/config/config.ts +3 -0
  104. package/src/shared/config/index.ts +0 -0
  105. package/src/shared/debug/index.ts +1 -0
  106. package/src/shared/debug/pause.ts +91 -0
  107. package/src/shared/instrumentation/errors.ts +84 -0
  108. package/src/shared/instrumentation/index.ts +9 -0
  109. package/src/shared/instrumentation/instrument.ts +406 -0
  110. package/src/shared/llm/ai-sdk-adapter.ts +81 -0
  111. package/{dist/shared/llm/client.cjs → src/shared/llm/client.ts} +86 -80
  112. package/src/shared/llm/index.ts +3 -0
  113. package/src/shared/llm/types.ts +63 -0
  114. package/src/shared/logger/index.ts +13 -0
  115. package/src/shared/logger/logger.ts +358 -0
  116. package/src/shared/logger/sinks.ts +148 -0
  117. package/src/shared/paths/paths.ts +110 -0
  118. package/src/shared/paths/repo-root.ts +27 -0
  119. package/src/shared/run/api.ts +6 -0
  120. package/src/shared/run/browser.ts +107 -0
  121. package/src/shared/state/index.ts +11 -0
  122. package/src/shared/state/session-state.ts +77 -0
  123. package/src/shared/visualization/ghost-cursor.ts +213 -0
  124. package/src/shared/visualization/highlight.ts +149 -0
  125. package/src/shared/visualization/index.ts +18 -0
  126. package/src/shared/workflow/workflow.ts +36 -0
  127. package/dist/index.cjs +0 -144
  128. package/dist/index.d.cts +0 -21
  129. package/dist/runtime/download/download.cjs +0 -70
  130. package/dist/runtime/download/download.d.cts +0 -35
  131. package/dist/runtime/download/index.cjs +0 -30
  132. package/dist/runtime/download/index.d.cts +0 -3
  133. package/dist/runtime/extract/extract.cjs +0 -88
  134. package/dist/runtime/extract/extract.d.cts +0 -23
  135. package/dist/runtime/extract/index.cjs +0 -28
  136. package/dist/runtime/extract/index.d.cts +0 -5
  137. package/dist/runtime/network/index.cjs +0 -28
  138. package/dist/runtime/network/index.d.cts +0 -4
  139. package/dist/runtime/network/network.cjs +0 -91
  140. package/dist/runtime/network/network.d.cts +0 -28
  141. package/dist/runtime/recovery/agent.d.cts +0 -13
  142. package/dist/runtime/recovery/errors.cjs +0 -124
  143. package/dist/runtime/recovery/errors.d.cts +0 -31
  144. package/dist/runtime/recovery/index.cjs +0 -34
  145. package/dist/runtime/recovery/index.d.cts +0 -7
  146. package/dist/runtime/recovery/recovery.cjs +0 -55
  147. package/dist/runtime/recovery/recovery.d.cts +0 -12
  148. package/dist/shared/condense-dom/condense-dom.d.cts +0 -34
  149. package/dist/shared/config/config.cjs +0 -44
  150. package/dist/shared/config/config.d.cts +0 -10
  151. package/dist/shared/config/index.cjs +0 -32
  152. package/dist/shared/config/index.d.cts +0 -1
  153. package/dist/shared/debug/index.cjs +0 -28
  154. package/dist/shared/debug/index.d.cts +0 -1
  155. package/dist/shared/debug/pause.cjs +0 -86
  156. package/dist/shared/debug/pause.d.cts +0 -12
  157. package/dist/shared/instrumentation/errors.cjs +0 -81
  158. package/dist/shared/instrumentation/errors.d.cts +0 -12
  159. package/dist/shared/instrumentation/index.cjs +0 -35
  160. package/dist/shared/instrumentation/index.d.cts +0 -6
  161. package/dist/shared/instrumentation/instrument.cjs +0 -206
  162. package/dist/shared/instrumentation/instrument.d.cts +0 -32
  163. package/dist/shared/llm/ai-sdk-adapter.cjs +0 -71
  164. package/dist/shared/llm/ai-sdk-adapter.d.cts +0 -22
  165. package/dist/shared/llm/client.d.cts +0 -13
  166. package/dist/shared/llm/index.cjs +0 -31
  167. package/dist/shared/llm/index.d.cts +0 -5
  168. package/dist/shared/llm/types.cjs +0 -16
  169. package/dist/shared/llm/types.d.cts +0 -67
  170. package/dist/shared/logger/index.cjs +0 -37
  171. package/dist/shared/logger/index.d.cts +0 -2
  172. package/dist/shared/logger/logger.cjs +0 -232
  173. package/dist/shared/logger/logger.d.cts +0 -86
  174. package/dist/shared/logger/sinks.cjs +0 -160
  175. package/dist/shared/logger/sinks.d.cts +0 -9
  176. package/dist/shared/paths/paths.cjs +0 -104
  177. package/dist/shared/paths/paths.d.cts +0 -10
  178. package/dist/shared/run/api.cjs +0 -28
  179. package/dist/shared/run/api.d.cts +0 -2
  180. package/dist/shared/run/browser.cjs +0 -98
  181. package/dist/shared/run/browser.d.cts +0 -22
  182. package/dist/shared/state/index.cjs +0 -38
  183. package/dist/shared/state/index.d.cts +0 -2
  184. package/dist/shared/state/session-state.cjs +0 -92
  185. package/dist/shared/state/session-state.d.cts +0 -40
  186. package/dist/shared/visualization/ghost-cursor.cjs +0 -174
  187. package/dist/shared/visualization/ghost-cursor.d.cts +0 -37
  188. package/dist/shared/visualization/highlight.cjs +0 -134
  189. package/dist/shared/visualization/highlight.d.cts +0 -22
  190. package/dist/shared/visualization/index.cjs +0 -45
  191. package/dist/shared/visualization/index.d.cts +0 -3
  192. package/dist/shared/workflow/workflow.cjs +0 -47
  193. package/dist/shared/workflow/workflow.d.cts +0 -21
  194. package/skills/libretto/integration-approach-selection.md +0 -174
@@ -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 };
@@ -1,71 +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 ai_sdk_adapter_exports = {};
20
- __export(ai_sdk_adapter_exports, {
21
- createLLMClientFromModel: () => createLLMClientFromModel
22
- });
23
- module.exports = __toCommonJS(ai_sdk_adapter_exports);
24
- var import_ai = require("ai");
25
- function createLLMClientFromModel(model) {
26
- return {
27
- async generateObject(opts) {
28
- const { object } = await (0, import_ai.generateObject)({
29
- model,
30
- schema: opts.schema,
31
- prompt: opts.prompt,
32
- temperature: opts.temperature ?? 0
33
- });
34
- return object;
35
- },
36
- async generateObjectFromMessages(opts) {
37
- const messages = opts.messages.map((msg) => {
38
- if (typeof msg.content === "string") {
39
- return { role: msg.role, content: msg.content };
40
- }
41
- if (msg.role === "assistant") {
42
- return {
43
- role: "assistant",
44
- content: msg.content.filter((part) => part.type === "text").map((part) => ({ type: "text", text: part.text }))
45
- };
46
- }
47
- return {
48
- role: "user",
49
- content: msg.content.map(
50
- (part) => part.type === "text" ? { type: "text", text: part.text } : {
51
- type: "image",
52
- image: part.image,
53
- ...part.mediaType ? { mediaType: part.mediaType } : {}
54
- }
55
- )
56
- };
57
- });
58
- const { object } = await (0, import_ai.generateObject)({
59
- model,
60
- schema: opts.schema,
61
- messages,
62
- temperature: opts.temperature ?? 0
63
- });
64
- return object;
65
- }
66
- };
67
- }
68
- // Annotate the CommonJS export names for ESM import in node:
69
- 0 && (module.exports = {
70
- createLLMClientFromModel
71
- });
@@ -1,22 +0,0 @@
1
- import { LanguageModel } from 'ai';
2
- import { LLMClient } from './types.cjs';
3
- import 'zod';
4
-
5
- /**
6
- * Creates a libretto LLMClient from a Vercel AI SDK LanguageModel.
7
- *
8
- * This eliminates the need for consumers to write their own adapter
9
- * when using @ai-sdk/openai, @ai-sdk/anthropic, @ai-sdk/google-vertex,
10
- * or any other Vercel AI SDK-compatible provider.
11
- *
12
- * @example
13
- * ```typescript
14
- * import { createLLMClientFromModel } from "libretto/llm";
15
- * import { openai } from "@ai-sdk/openai";
16
- *
17
- * const llmClient = createLLMClientFromModel(openai("gpt-4o"));
18
- * ```
19
- */
20
- declare function createLLMClientFromModel(model: LanguageModel): LLMClient;
21
-
22
- export { createLLMClientFromModel };
@@ -1,13 +0,0 @@
1
- import { LLMClient } from './types.cjs';
2
- import 'zod';
3
-
4
- type Provider = "google" | "vertex" | "anthropic" | "openai";
5
- declare function parseModel(model: string): {
6
- provider: Provider;
7
- modelId: string;
8
- };
9
- declare function hasProviderCredentials(provider: Provider, env?: NodeJS.ProcessEnv): boolean;
10
- declare function missingProviderCredentialsMessage(provider: Provider): string;
11
- declare function createLLMClient(model: string): LLMClient;
12
-
13
- export { type Provider, createLLMClient, hasProviderCredentials, missingProviderCredentialsMessage, parseModel };
@@ -1,31 +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 llm_exports = {};
20
- __export(llm_exports, {
21
- createLLMClient: () => import_client.createLLMClient,
22
- createLLMClientFromModel: () => import_ai_sdk_adapter.createLLMClientFromModel
23
- });
24
- module.exports = __toCommonJS(llm_exports);
25
- var import_client = require("./client.js");
26
- var import_ai_sdk_adapter = require("./ai-sdk-adapter.js");
27
- // Annotate the CommonJS export names for ESM import in node:
28
- 0 && (module.exports = {
29
- createLLMClient,
30
- createLLMClientFromModel
31
- });
@@ -1,5 +0,0 @@
1
- export { LLMClient, Message, MessageContentPart } from './types.cjs';
2
- export { createLLMClient } from './client.cjs';
3
- export { createLLMClientFromModel } from './ai-sdk-adapter.cjs';
4
- import 'zod';
5
- import 'ai';
@@ -1,16 +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 __copyProps = (to, from, except, desc) => {
7
- if (from && typeof from === "object" || typeof from === "function") {
8
- for (let key of __getOwnPropNames(from))
9
- if (!__hasOwnProp.call(to, key) && key !== except)
10
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
- }
12
- return to;
13
- };
14
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
- var types_exports = {};
16
- module.exports = __toCommonJS(types_exports);