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.
Files changed (152) hide show
  1. package/dist/cli/cli.js +20 -19
  2. package/dist/cli/commands/ai.js +1 -1
  3. package/dist/cli/commands/browser.js +3 -3
  4. package/dist/cli/commands/execution.js +3 -3
  5. package/dist/cli/commands/logs.js +1 -1
  6. package/dist/cli/core/browser.js +11 -6
  7. package/dist/cli/core/context.js +4 -18
  8. package/dist/cli/core/session.js +2 -2
  9. package/dist/cli/core/snapshot-analyzer.js +2 -2
  10. package/dist/cli/router.js +1 -1
  11. package/dist/cli/workers/run-integration-runtime.js +2 -2
  12. package/dist/shared/paths/paths.js +2 -1
  13. package/dist/shared/paths/repo-root.d.ts +3 -0
  14. package/dist/shared/paths/repo-root.js +24 -0
  15. package/package.json +6 -7
  16. package/scripts/postinstall.mjs +12 -3
  17. package/skills/libretto/SKILL.md +93 -404
  18. package/skills/libretto/references/auth-profiles.md +30 -0
  19. package/skills/libretto/references/pages-and-page-targeting.md +29 -0
  20. package/skills/libretto/references/reverse-engineering-network-requests.md +39 -0
  21. package/skills/libretto/references/user-action-log.md +31 -0
  22. package/src/cli/cli.ts +173 -0
  23. package/src/cli/commands/ai.ts +35 -0
  24. package/src/cli/commands/browser.ts +165 -0
  25. package/src/cli/commands/execution.ts +691 -0
  26. package/src/cli/commands/init.ts +327 -0
  27. package/src/cli/commands/logs.ts +128 -0
  28. package/src/cli/commands/shared.ts +70 -0
  29. package/src/cli/commands/snapshot.ts +327 -0
  30. package/src/cli/core/ai-config.ts +255 -0
  31. package/src/cli/core/api-snapshot-analyzer.ts +97 -0
  32. package/src/cli/core/browser.ts +839 -0
  33. package/src/cli/core/context.ts +122 -0
  34. package/src/cli/core/pause-signals.ts +35 -0
  35. package/src/cli/core/session-telemetry.ts +553 -0
  36. package/src/cli/core/session.ts +209 -0
  37. package/src/cli/core/snapshot-analyzer.ts +875 -0
  38. package/src/cli/core/snapshot-api-config.ts +236 -0
  39. package/src/cli/core/telemetry.ts +446 -0
  40. package/src/cli/framework/simple-cli.ts +1273 -0
  41. package/src/cli/index.ts +13 -0
  42. package/src/cli/router.ts +28 -0
  43. package/src/cli/workers/run-integration-runtime.ts +311 -0
  44. package/src/cli/workers/run-integration-worker-protocol.ts +14 -0
  45. package/src/cli/workers/run-integration-worker.ts +75 -0
  46. package/src/index.ts +120 -0
  47. package/src/runtime/download/download.ts +100 -0
  48. package/src/runtime/download/index.ts +7 -0
  49. package/src/runtime/extract/extract.ts +92 -0
  50. package/src/runtime/extract/index.ts +1 -0
  51. package/src/runtime/network/index.ts +5 -0
  52. package/src/runtime/network/network.ts +113 -0
  53. package/src/runtime/recovery/agent.ts +256 -0
  54. package/src/runtime/recovery/errors.ts +152 -0
  55. package/src/runtime/recovery/index.ts +7 -0
  56. package/src/runtime/recovery/recovery.ts +50 -0
  57. package/{dist/shared/condense-dom/condense-dom.cjs → src/shared/condense-dom/condense-dom.ts} +243 -115
  58. package/src/shared/config/config.ts +22 -0
  59. package/src/shared/config/index.ts +5 -0
  60. package/src/shared/debug/index.ts +1 -0
  61. package/src/shared/debug/pause.ts +85 -0
  62. package/src/shared/instrumentation/errors.ts +82 -0
  63. package/src/shared/instrumentation/index.ts +9 -0
  64. package/src/shared/instrumentation/instrument.ts +276 -0
  65. package/src/shared/llm/ai-sdk-adapter.ts +78 -0
  66. package/src/shared/llm/client.ts +217 -0
  67. package/src/shared/llm/index.ts +3 -0
  68. package/src/shared/llm/types.ts +63 -0
  69. package/src/shared/logger/index.ts +6 -0
  70. package/src/shared/logger/logger.ts +352 -0
  71. package/src/shared/logger/sinks.ts +144 -0
  72. package/src/shared/paths/paths.ts +109 -0
  73. package/src/shared/paths/repo-root.ts +27 -0
  74. package/src/shared/run/api.ts +2 -0
  75. package/src/shared/run/browser.ts +98 -0
  76. package/src/shared/state/index.ts +11 -0
  77. package/src/shared/state/session-state.ts +74 -0
  78. package/src/shared/visualization/ghost-cursor.ts +200 -0
  79. package/src/shared/visualization/highlight.ts +146 -0
  80. package/src/shared/visualization/index.ts +18 -0
  81. package/src/shared/workflow/workflow.ts +42 -0
  82. package/dist/index.cjs +0 -144
  83. package/dist/index.d.cts +0 -21
  84. package/dist/runtime/download/download.cjs +0 -70
  85. package/dist/runtime/download/download.d.cts +0 -35
  86. package/dist/runtime/download/index.cjs +0 -30
  87. package/dist/runtime/download/index.d.cts +0 -3
  88. package/dist/runtime/extract/extract.cjs +0 -88
  89. package/dist/runtime/extract/extract.d.cts +0 -23
  90. package/dist/runtime/extract/index.cjs +0 -28
  91. package/dist/runtime/extract/index.d.cts +0 -5
  92. package/dist/runtime/network/index.cjs +0 -28
  93. package/dist/runtime/network/index.d.cts +0 -4
  94. package/dist/runtime/network/network.cjs +0 -91
  95. package/dist/runtime/network/network.d.cts +0 -28
  96. package/dist/runtime/recovery/agent.cjs +0 -223
  97. package/dist/runtime/recovery/agent.d.cts +0 -13
  98. package/dist/runtime/recovery/errors.cjs +0 -124
  99. package/dist/runtime/recovery/errors.d.cts +0 -31
  100. package/dist/runtime/recovery/index.cjs +0 -34
  101. package/dist/runtime/recovery/index.d.cts +0 -7
  102. package/dist/runtime/recovery/recovery.cjs +0 -55
  103. package/dist/runtime/recovery/recovery.d.cts +0 -12
  104. package/dist/shared/condense-dom/condense-dom.d.cts +0 -34
  105. package/dist/shared/config/config.cjs +0 -44
  106. package/dist/shared/config/config.d.cts +0 -10
  107. package/dist/shared/config/index.cjs +0 -32
  108. package/dist/shared/config/index.d.cts +0 -1
  109. package/dist/shared/debug/index.cjs +0 -28
  110. package/dist/shared/debug/index.d.cts +0 -1
  111. package/dist/shared/debug/pause.cjs +0 -86
  112. package/dist/shared/debug/pause.d.cts +0 -12
  113. package/dist/shared/instrumentation/errors.cjs +0 -81
  114. package/dist/shared/instrumentation/errors.d.cts +0 -12
  115. package/dist/shared/instrumentation/index.cjs +0 -35
  116. package/dist/shared/instrumentation/index.d.cts +0 -6
  117. package/dist/shared/instrumentation/instrument.cjs +0 -206
  118. package/dist/shared/instrumentation/instrument.d.cts +0 -32
  119. package/dist/shared/llm/ai-sdk-adapter.cjs +0 -71
  120. package/dist/shared/llm/ai-sdk-adapter.d.cts +0 -22
  121. package/dist/shared/llm/client.cjs +0 -218
  122. package/dist/shared/llm/client.d.cts +0 -13
  123. package/dist/shared/llm/index.cjs +0 -31
  124. package/dist/shared/llm/index.d.cts +0 -5
  125. package/dist/shared/llm/types.cjs +0 -16
  126. package/dist/shared/llm/types.d.cts +0 -67
  127. package/dist/shared/logger/index.cjs +0 -37
  128. package/dist/shared/logger/index.d.cts +0 -2
  129. package/dist/shared/logger/logger.cjs +0 -232
  130. package/dist/shared/logger/logger.d.cts +0 -86
  131. package/dist/shared/logger/sinks.cjs +0 -160
  132. package/dist/shared/logger/sinks.d.cts +0 -9
  133. package/dist/shared/paths/paths.cjs +0 -104
  134. package/dist/shared/paths/paths.d.cts +0 -10
  135. package/dist/shared/run/api.cjs +0 -28
  136. package/dist/shared/run/api.d.cts +0 -2
  137. package/dist/shared/run/browser.cjs +0 -98
  138. package/dist/shared/run/browser.d.cts +0 -22
  139. package/dist/shared/state/index.cjs +0 -38
  140. package/dist/shared/state/index.d.cts +0 -2
  141. package/dist/shared/state/session-state.cjs +0 -92
  142. package/dist/shared/state/session-state.d.cts +0 -40
  143. package/dist/shared/visualization/ghost-cursor.cjs +0 -174
  144. package/dist/shared/visualization/ghost-cursor.d.cts +0 -37
  145. package/dist/shared/visualization/highlight.cjs +0 -134
  146. package/dist/shared/visualization/highlight.d.cts +0 -22
  147. package/dist/shared/visualization/index.cjs +0 -45
  148. package/dist/shared/visualization/index.d.cts +0 -3
  149. package/dist/shared/workflow/workflow.cjs +0 -47
  150. package/dist/shared/workflow/workflow.d.cts +0 -21
  151. package/skills/libretto/code-generation-rules.md +0 -223
  152. package/skills/libretto/integration-approach-selection.md +0 -174
@@ -1,98 +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 browser_exports = {};
20
- __export(browser_exports, {
21
- launchBrowser: () => launchBrowser
22
- });
23
- module.exports = __toCommonJS(browser_exports);
24
- var import_playwright = require("playwright");
25
- var import_node_net = require("node:net");
26
- var import_node_fs = require("node:fs");
27
- var import_paths = require("../paths/paths.js");
28
- var import_session_state = require("../state/session-state.js");
29
- async function pickFreePort() {
30
- return await new Promise((resolve, reject) => {
31
- const server = (0, import_node_net.createServer)();
32
- server.unref();
33
- server.on("error", reject);
34
- server.listen(0, "127.0.0.1", () => {
35
- const addr = server.address();
36
- if (addr && typeof addr === "object") {
37
- server.close(() => resolve(addr.port));
38
- return;
39
- }
40
- server.close(() => reject(new Error("Failed to resolve debug port")));
41
- });
42
- });
43
- }
44
- async function launchBrowser({
45
- sessionName,
46
- headless = false,
47
- viewport = { width: 1366, height: 768 },
48
- storageStatePath
49
- }) {
50
- const debugPort = await pickFreePort();
51
- const browser = await import_playwright.chromium.launch({
52
- headless,
53
- args: [
54
- "--disable-blink-features=AutomationControlled",
55
- `--remote-debugging-port=${debugPort}`,
56
- "--no-focus-on-check"
57
- ]
58
- });
59
- const context = await browser.newContext({
60
- viewport,
61
- ...storageStatePath ? { storageState: storageStatePath } : {}
62
- });
63
- const page = await context.newPage();
64
- page.setDefaultTimeout(3e4);
65
- page.setDefaultNavigationTimeout(45e3);
66
- const metadataPath = (0, import_paths.ensureLibrettoSessionStatePath)(sessionName);
67
- const existingStateRaw = (0, import_node_fs.existsSync)(metadataPath) ? JSON.parse((0, import_node_fs.readFileSync)(metadataPath, "utf-8")) : void 0;
68
- const parsedExistingState = import_session_state.SessionStateFileSchema.safeParse(existingStateRaw);
69
- (0, import_node_fs.writeFileSync)(
70
- metadataPath,
71
- JSON.stringify(
72
- {
73
- version: parsedExistingState.success ? parsedExistingState.data.version : import_session_state.SESSION_STATE_VERSION,
74
- session: sessionName,
75
- port: debugPort,
76
- pid: process.pid,
77
- startedAt: (/* @__PURE__ */ new Date()).toISOString(),
78
- status: "active"
79
- },
80
- null,
81
- 2
82
- )
83
- );
84
- return {
85
- browser,
86
- context,
87
- page,
88
- debugPort,
89
- metadataPath,
90
- close: async () => {
91
- await browser.close();
92
- }
93
- };
94
- }
95
- // Annotate the CommonJS export names for ESM import in node:
96
- 0 && (module.exports = {
97
- launchBrowser
98
- });
@@ -1,22 +0,0 @@
1
- import { Browser, BrowserContext, Page } from 'playwright';
2
-
3
- type LaunchBrowserArgs = {
4
- sessionName: string;
5
- headless?: boolean;
6
- viewport?: {
7
- width: number;
8
- height: number;
9
- };
10
- storageStatePath?: string;
11
- };
12
- type BrowserSession = {
13
- browser: Browser;
14
- context: BrowserContext;
15
- page: Page;
16
- debugPort: number;
17
- metadataPath: string;
18
- close: () => Promise<void>;
19
- };
20
- declare function launchBrowser({ sessionName, headless, viewport, storageStatePath, }: LaunchBrowserArgs): Promise<BrowserSession>;
21
-
22
- export { type BrowserSession, type LaunchBrowserArgs, launchBrowser };
@@ -1,38 +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 state_exports = {};
20
- __export(state_exports, {
21
- SESSION_STATE_VERSION: () => import_session_state.SESSION_STATE_VERSION,
22
- SessionStateFileSchema: () => import_session_state.SessionStateFileSchema,
23
- SessionStatusSchema: () => import_session_state.SessionStatusSchema,
24
- parseSessionStateContent: () => import_session_state.parseSessionStateContent,
25
- parseSessionStateData: () => import_session_state.parseSessionStateData,
26
- serializeSessionState: () => import_session_state.serializeSessionState
27
- });
28
- module.exports = __toCommonJS(state_exports);
29
- var import_session_state = require("./session-state.js");
30
- // Annotate the CommonJS export names for ESM import in node:
31
- 0 && (module.exports = {
32
- SESSION_STATE_VERSION,
33
- SessionStateFileSchema,
34
- SessionStatusSchema,
35
- parseSessionStateContent,
36
- parseSessionStateData,
37
- serializeSessionState
38
- });
@@ -1,2 +0,0 @@
1
- export { SESSION_STATE_VERSION, SessionState, SessionStateFile, SessionStateFileSchema, SessionStatus, SessionStatusSchema, parseSessionStateContent, parseSessionStateData, serializeSessionState } from './session-state.cjs';
2
- import 'zod';
@@ -1,92 +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 session_state_exports = {};
20
- __export(session_state_exports, {
21
- SESSION_STATE_VERSION: () => SESSION_STATE_VERSION,
22
- SessionStateFileSchema: () => SessionStateFileSchema,
23
- SessionStatusSchema: () => SessionStatusSchema,
24
- SessionViewportSchema: () => SessionViewportSchema,
25
- parseSessionStateContent: () => parseSessionStateContent,
26
- parseSessionStateData: () => parseSessionStateData,
27
- serializeSessionState: () => serializeSessionState
28
- });
29
- module.exports = __toCommonJS(session_state_exports);
30
- var import_zod = require("zod");
31
- const SESSION_STATE_VERSION = 1;
32
- const SessionStatusSchema = import_zod.z.enum([
33
- "active",
34
- "paused",
35
- "completed",
36
- "failed",
37
- "exited"
38
- ]);
39
- const SessionViewportSchema = import_zod.z.object({
40
- width: import_zod.z.number().int().min(1),
41
- height: import_zod.z.number().int().min(1)
42
- });
43
- const SessionStateFileSchema = import_zod.z.object({
44
- version: import_zod.z.literal(SESSION_STATE_VERSION),
45
- port: import_zod.z.number().int().min(0).max(65535),
46
- pid: import_zod.z.number().int(),
47
- session: import_zod.z.string().min(1),
48
- startedAt: import_zod.z.string().datetime({ offset: true }),
49
- status: SessionStatusSchema.optional(),
50
- viewport: SessionViewportSchema.optional()
51
- });
52
- function formatIssues(error) {
53
- return error.issues.map((issue) => {
54
- const path = issue.path.join(".") || "root";
55
- return `${path}: ${issue.message}`;
56
- }).join("; ");
57
- }
58
- function parseSessionStateData(rawState, source) {
59
- const parsed = SessionStateFileSchema.safeParse(rawState);
60
- if (!parsed.success) {
61
- throw new Error(`Session state at ${source} is invalid: ${formatIssues(parsed.error)}`);
62
- }
63
- const { version: _version, ...state } = parsed.data;
64
- return state;
65
- }
66
- function parseSessionStateContent(content, source) {
67
- let rawState;
68
- try {
69
- rawState = JSON.parse(content);
70
- } catch (error) {
71
- throw new Error(
72
- `Session state at ${source} is not valid JSON: ${error instanceof Error ? error.message : String(error)}`
73
- );
74
- }
75
- return parseSessionStateData(rawState, source);
76
- }
77
- function serializeSessionState(state) {
78
- return SessionStateFileSchema.parse({
79
- version: SESSION_STATE_VERSION,
80
- ...state
81
- });
82
- }
83
- // Annotate the CommonJS export names for ESM import in node:
84
- 0 && (module.exports = {
85
- SESSION_STATE_VERSION,
86
- SessionStateFileSchema,
87
- SessionStatusSchema,
88
- SessionViewportSchema,
89
- parseSessionStateContent,
90
- parseSessionStateData,
91
- serializeSessionState
92
- });
@@ -1,40 +0,0 @@
1
- import { z } from 'zod';
2
-
3
- declare const SESSION_STATE_VERSION = 1;
4
- declare const SessionStatusSchema: z.ZodEnum<{
5
- active: "active";
6
- paused: "paused";
7
- completed: "completed";
8
- failed: "failed";
9
- exited: "exited";
10
- }>;
11
- declare const SessionViewportSchema: z.ZodObject<{
12
- width: z.ZodNumber;
13
- height: z.ZodNumber;
14
- }, z.core.$strip>;
15
- declare const SessionStateFileSchema: z.ZodObject<{
16
- version: z.ZodLiteral<1>;
17
- port: z.ZodNumber;
18
- pid: z.ZodNumber;
19
- session: z.ZodString;
20
- startedAt: z.ZodString;
21
- status: z.ZodOptional<z.ZodEnum<{
22
- active: "active";
23
- paused: "paused";
24
- completed: "completed";
25
- failed: "failed";
26
- exited: "exited";
27
- }>>;
28
- viewport: z.ZodOptional<z.ZodObject<{
29
- width: z.ZodNumber;
30
- height: z.ZodNumber;
31
- }, z.core.$strip>>;
32
- }, z.core.$strip>;
33
- type SessionStatus = z.infer<typeof SessionStatusSchema>;
34
- type SessionStateFile = z.infer<typeof SessionStateFileSchema>;
35
- type SessionState = Omit<SessionStateFile, "version">;
36
- declare function parseSessionStateData(rawState: unknown, source: string): SessionState;
37
- declare function parseSessionStateContent(content: string, source: string): SessionState;
38
- declare function serializeSessionState(state: SessionState): SessionStateFile;
39
-
40
- export { SESSION_STATE_VERSION, type SessionState, type SessionStateFile, SessionStateFileSchema, type SessionStatus, SessionStatusSchema, SessionViewportSchema, parseSessionStateContent, parseSessionStateData, serializeSessionState };
@@ -1,174 +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 ghost_cursor_exports = {};
20
- __export(ghost_cursor_exports, {
21
- ensureGhostCursor: () => ensureGhostCursor,
22
- getGhostCursorPosition: () => getGhostCursorPosition,
23
- ghostClick: () => ghostClick,
24
- hideGhostCursor: () => hideGhostCursor,
25
- moveGhostCursor: () => moveGhostCursor,
26
- moveGhostCursorWithDistance: () => moveGhostCursorWithDistance
27
- });
28
- module.exports = __toCommonJS(ghost_cursor_exports);
29
- const DEFAULTS = {
30
- style: "minimal",
31
- color: "rgba(255, 70, 70, 0.9)",
32
- size: 20,
33
- zIndex: 2147483646,
34
- easing: "cubic-bezier(0.16, 1, 0.3, 1)",
35
- minDurationMs: 100,
36
- maxDurationMs: 600,
37
- speedPxPerMs: 1.5
38
- };
39
- const CURSOR_ID = "__libretto_ghost_cursor__";
40
- function buildCursorSvg(style, color, size) {
41
- if (style === "dot") {
42
- return `<div style="width:${size}px;height:${size}px;border-radius:50%;background:${color};"></div>`;
43
- }
44
- if (style === "screenstudio") {
45
- return `<div style="width:${size * 1.4}px;height:${size * 1.4}px;border-radius:50%;background:${color};box-shadow:0 0 ${size * 0.6}px ${color};opacity:0.7;"></div>`;
46
- }
47
- return `<svg width="${size}" height="${size}" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
48
- <path d="M5 3L19 12L12 13L9 20L5 3Z" fill="${color}" stroke="rgba(0,0,0,0.3)" stroke-width="1"/>
49
- </svg>`;
50
- }
51
- function buildInitScript(opts) {
52
- const svg = buildCursorSvg(opts.style, opts.color, opts.size);
53
- return `
54
- (function() {
55
- if (document.getElementById("${CURSOR_ID}")) return;
56
- var el = document.createElement("div");
57
- el.id = "${CURSOR_ID}";
58
- el.style.cssText = "position:fixed;top:0;left:0;z-index:${opts.zIndex};pointer-events:none;transform:translate3d(-100px,-100px,0);transition:none;will-change:transform,opacity;opacity:0;";
59
- el.innerHTML = ${JSON.stringify(svg)};
60
- document.documentElement.appendChild(el);
61
- })();
62
- `;
63
- }
64
- const installedPages = /* @__PURE__ */ new WeakSet();
65
- async function ensureGhostCursor(page, options) {
66
- const existingOpts = page.__librettoGhostCursorOpts;
67
- const opts = { ...DEFAULTS, ...existingOpts ?? {}, ...options };
68
- const initScript = buildInitScript(opts);
69
- if (!installedPages.has(page)) {
70
- installedPages.add(page);
71
- await page.addInitScript({ content: initScript });
72
- }
73
- page.__librettoGhostCursorOpts = opts;
74
- try {
75
- await page.evaluate(new Function(initScript));
76
- } catch {
77
- }
78
- }
79
- async function moveGhostCursor(page, target) {
80
- const opts = page.__librettoGhostCursorOpts ?? DEFAULTS;
81
- const durationMs = target.durationMs ?? Math.min(
82
- opts.maxDurationMs,
83
- Math.max(opts.minDurationMs, 200)
84
- // default ~200ms if no distance info
85
- );
86
- try {
87
- await page.evaluate(
88
- ({ id, x, y, duration, easing }) => {
89
- const el = document.getElementById(id);
90
- if (!el) return;
91
- el.style.opacity = "1";
92
- el.style.transition = `transform ${duration}ms ${easing}`;
93
- el.style.transform = `translate3d(${x}px, ${y}px, 0)`;
94
- },
95
- { id: CURSOR_ID, x: target.x, y: target.y, duration: durationMs, easing: opts.easing }
96
- );
97
- await page.waitForTimeout(durationMs);
98
- } catch {
99
- }
100
- }
101
- async function moveGhostCursorWithDistance(page, from, to) {
102
- const opts = page.__librettoGhostCursorOpts ?? DEFAULTS;
103
- const dx = to.x - from.x;
104
- const dy = to.y - from.y;
105
- const distance = Math.sqrt(dx * dx + dy * dy);
106
- const durationMs = Math.min(
107
- opts.maxDurationMs,
108
- Math.max(opts.minDurationMs, distance / opts.speedPxPerMs)
109
- );
110
- await moveGhostCursor(page, { x: to.x, y: to.y, durationMs });
111
- }
112
- async function ghostClick(page, target) {
113
- try {
114
- await page.evaluate(
115
- ({ id, x, y }) => {
116
- const el = document.getElementById(id);
117
- if (!el) return;
118
- el.style.transform = `translate3d(${x}px, ${y}px, 0) scale(0.93)`;
119
- el.style.transition = "transform 80ms ease-out";
120
- },
121
- { id: CURSOR_ID, x: target.x, y: target.y }
122
- );
123
- await page.waitForTimeout(100);
124
- await page.evaluate(
125
- ({ id, x, y }) => {
126
- const el = document.getElementById(id);
127
- if (!el) return;
128
- el.style.transform = `translate3d(${x}px, ${y}px, 0) scale(1)`;
129
- el.style.transition = "transform 120ms ease-out";
130
- },
131
- { id: CURSOR_ID, x: target.x, y: target.y }
132
- );
133
- await page.waitForTimeout(130);
134
- } catch {
135
- }
136
- }
137
- async function hideGhostCursor(page) {
138
- try {
139
- await page.evaluate(
140
- ({ id }) => {
141
- const el = document.getElementById(id);
142
- if (!el) return;
143
- el.style.transition = "opacity 300ms ease-out";
144
- el.style.opacity = "0";
145
- },
146
- { id: CURSOR_ID }
147
- );
148
- } catch {
149
- }
150
- }
151
- async function getGhostCursorPosition(page) {
152
- try {
153
- return await page.evaluate(({ id }) => {
154
- const el = document.getElementById(id);
155
- if (!el) return null;
156
- const match = el.style.transform.match(
157
- /translate3d\(\s*([\d.-]+)px\s*,\s*([\d.-]+)px/
158
- );
159
- if (!match) return null;
160
- return { x: parseFloat(match[1]), y: parseFloat(match[2]) };
161
- }, { id: CURSOR_ID });
162
- } catch {
163
- return null;
164
- }
165
- }
166
- // Annotate the CommonJS export names for ESM import in node:
167
- 0 && (module.exports = {
168
- ensureGhostCursor,
169
- getGhostCursorPosition,
170
- ghostClick,
171
- hideGhostCursor,
172
- moveGhostCursor,
173
- moveGhostCursorWithDistance
174
- });
@@ -1,37 +0,0 @@
1
- import { Page } from 'playwright';
2
-
3
- type GhostCursorStyle = "minimal" | "dot" | "screenstudio";
4
- type GhostCursorOptions = {
5
- style?: GhostCursorStyle;
6
- color?: string;
7
- size?: number;
8
- zIndex?: number;
9
- easing?: string;
10
- minDurationMs?: number;
11
- maxDurationMs?: number;
12
- speedPxPerMs?: number;
13
- };
14
- declare function ensureGhostCursor(page: Page, options?: GhostCursorOptions): Promise<void>;
15
- declare function moveGhostCursor(page: Page, target: {
16
- x: number;
17
- y: number;
18
- durationMs?: number;
19
- }): Promise<void>;
20
- declare function moveGhostCursorWithDistance(page: Page, from: {
21
- x: number;
22
- y: number;
23
- }, to: {
24
- x: number;
25
- y: number;
26
- }): Promise<void>;
27
- declare function ghostClick(page: Page, target: {
28
- x: number;
29
- y: number;
30
- }): Promise<void>;
31
- declare function hideGhostCursor(page: Page): Promise<void>;
32
- declare function getGhostCursorPosition(page: Page): Promise<{
33
- x: number;
34
- y: number;
35
- } | null>;
36
-
37
- export { type GhostCursorOptions, type GhostCursorStyle, ensureGhostCursor, getGhostCursorPosition, ghostClick, hideGhostCursor, moveGhostCursor, moveGhostCursorWithDistance };
@@ -1,134 +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 highlight_exports = {};
20
- __export(highlight_exports, {
21
- clearHighlights: () => clearHighlights,
22
- ensureHighlightLayer: () => ensureHighlightLayer,
23
- showHighlight: () => showHighlight
24
- });
25
- module.exports = __toCommonJS(highlight_exports);
26
- const HIGHLIGHT_DEFAULTS = {
27
- color: "rgba(59, 130, 246, 0.25)",
28
- zIndex: 2147483645
29
- };
30
- const LAYER_ID = "__libretto_highlight_layer__";
31
- function buildHighlightInitScript(opts) {
32
- return `
33
- (function() {
34
- if (document.getElementById("${LAYER_ID}")) return;
35
- var el = document.createElement("div");
36
- el.id = "${LAYER_ID}";
37
- el.style.cssText = "position:fixed;top:0;left:0;width:100%;height:100%;z-index:${opts.zIndex};pointer-events:none;overflow:hidden;";
38
- document.documentElement.appendChild(el);
39
- })();
40
- `;
41
- }
42
- const installedPages = /* @__PURE__ */ new WeakSet();
43
- async function ensureHighlightLayer(page, options) {
44
- const existingOpts = page.__librettoHighlightOpts;
45
- const zIndex = options?.zIndex ?? existingOpts?.zIndex ?? HIGHLIGHT_DEFAULTS.zIndex;
46
- const initScript = buildHighlightInitScript({ zIndex });
47
- if (!installedPages.has(page)) {
48
- installedPages.add(page);
49
- await page.addInitScript({ content: initScript });
50
- }
51
- page.__librettoHighlightOpts = {
52
- color: options?.color ?? existingOpts?.color ?? HIGHLIGHT_DEFAULTS.color,
53
- zIndex
54
- };
55
- try {
56
- await page.evaluate(new Function(initScript));
57
- } catch {
58
- }
59
- }
60
- async function showHighlight(page, params) {
61
- const opts = page.__librettoHighlightOpts ?? HIGHLIGHT_DEFAULTS;
62
- const color = params.color ?? opts.color;
63
- const durationMs = params.durationMs ?? 350;
64
- try {
65
- await page.evaluate(
66
- ({ layerId, box, color: color2, label, durationMs: durationMs2 }) => {
67
- const layer = document.getElementById(layerId);
68
- if (!layer) return;
69
- const rect = document.createElement("div");
70
- rect.className = "__libretto_highlight_rect__";
71
- rect.style.cssText = `
72
- position:absolute;
73
- left:${box.x}px;
74
- top:${box.y}px;
75
- width:${box.width}px;
76
- height:${box.height}px;
77
- background:${color2};
78
- border:2px solid ${color2.replace(/[\d.]+\)$/, "0.6)")};
79
- border-radius:3px;
80
- pointer-events:none;
81
- transition:opacity 200ms ease-out;
82
- opacity:1;
83
- `;
84
- if (label) {
85
- const labelEl = document.createElement("div");
86
- labelEl.textContent = label;
87
- labelEl.style.cssText = `
88
- position:absolute;
89
- top:-22px;
90
- left:0;
91
- font:11px/1.2 -apple-system,BlinkMacSystemFont,sans-serif;
92
- color:#fff;
93
- background:rgba(0,0,0,0.7);
94
- padding:2px 6px;
95
- border-radius:3px;
96
- white-space:nowrap;
97
- pointer-events:none;
98
- `;
99
- rect.appendChild(labelEl);
100
- }
101
- layer.appendChild(rect);
102
- setTimeout(() => {
103
- rect.style.opacity = "0";
104
- setTimeout(() => rect.remove(), 250);
105
- }, durationMs2);
106
- },
107
- {
108
- layerId: LAYER_ID,
109
- box: params.box,
110
- color,
111
- label: params.label,
112
- durationMs
113
- }
114
- );
115
- } catch {
116
- }
117
- }
118
- async function clearHighlights(page) {
119
- try {
120
- await page.evaluate(({ layerId }) => {
121
- const layer = document.getElementById(layerId);
122
- if (!layer) return;
123
- const rects = layer.querySelectorAll(".__libretto_highlight_rect__");
124
- rects.forEach((r) => r.remove());
125
- }, { layerId: LAYER_ID });
126
- } catch {
127
- }
128
- }
129
- // Annotate the CommonJS export names for ESM import in node:
130
- 0 && (module.exports = {
131
- clearHighlights,
132
- ensureHighlightLayer,
133
- showHighlight
134
- });
@@ -1,22 +0,0 @@
1
- import { Page } from 'playwright';
2
-
3
- type HighlightOptions = {
4
- color?: string;
5
- zIndex?: number;
6
- };
7
- declare function ensureHighlightLayer(page: Page, options?: HighlightOptions): Promise<void>;
8
- type ShowHighlightParams = {
9
- box: {
10
- x: number;
11
- y: number;
12
- width: number;
13
- height: number;
14
- };
15
- label?: string;
16
- color?: string;
17
- durationMs?: number;
18
- };
19
- declare function showHighlight(page: Page, params: ShowHighlightParams): Promise<void>;
20
- declare function clearHighlights(page: Page): Promise<void>;
21
-
22
- export { type HighlightOptions, type ShowHighlightParams, clearHighlights, ensureHighlightLayer, showHighlight };