libretto 0.2.6 → 0.3.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 (160) hide show
  1. package/LICENSE +21 -0
  2. package/package.json +12 -12
  3. package/skill/SKILL.md +20 -18
  4. package/skill/code-generation-rules.md +3 -3
  5. package/skill/integration-approach-selection.md +3 -3
  6. package/dist/cli/cli.js +0 -209
  7. package/dist/cli/commands/ai.js +0 -21
  8. package/dist/cli/commands/browser.js +0 -82
  9. package/dist/cli/commands/execution.js +0 -461
  10. package/dist/cli/commands/init.js +0 -95
  11. package/dist/cli/commands/logs.js +0 -93
  12. package/dist/cli/commands/snapshot.js +0 -106
  13. package/dist/cli/core/ai-config.js +0 -149
  14. package/dist/cli/core/browser.js +0 -648
  15. package/dist/cli/core/context.js +0 -118
  16. package/dist/cli/core/pause-signals.js +0 -29
  17. package/dist/cli/core/session-telemetry.js +0 -491
  18. package/dist/cli/core/session.js +0 -183
  19. package/dist/cli/core/snapshot-analyzer.js +0 -492
  20. package/dist/cli/core/telemetry.js +0 -362
  21. package/dist/cli/index.js +0 -13
  22. package/dist/cli/workers/run-integration-runtime.js +0 -227
  23. package/dist/cli/workers/run-integration-worker-protocol.js +0 -12
  24. package/dist/cli/workers/run-integration-worker.js +0 -66
  25. package/dist/index.cjs +0 -116
  26. package/dist/index.d.cts +0 -21
  27. package/dist/index.d.ts +0 -21
  28. package/dist/index.js +0 -97
  29. package/dist/runtime/download/download.cjs +0 -70
  30. package/dist/runtime/download/download.d.cts +0 -35
  31. package/dist/runtime/download/download.d.ts +0 -35
  32. package/dist/runtime/download/download.js +0 -45
  33. package/dist/runtime/download/index.cjs +0 -30
  34. package/dist/runtime/download/index.d.cts +0 -3
  35. package/dist/runtime/download/index.d.ts +0 -3
  36. package/dist/runtime/download/index.js +0 -8
  37. package/dist/runtime/extract/extract.cjs +0 -88
  38. package/dist/runtime/extract/extract.d.cts +0 -23
  39. package/dist/runtime/extract/extract.d.ts +0 -23
  40. package/dist/runtime/extract/extract.js +0 -64
  41. package/dist/runtime/extract/index.cjs +0 -28
  42. package/dist/runtime/extract/index.d.cts +0 -5
  43. package/dist/runtime/extract/index.d.ts +0 -5
  44. package/dist/runtime/extract/index.js +0 -4
  45. package/dist/runtime/network/index.cjs +0 -28
  46. package/dist/runtime/network/index.d.cts +0 -4
  47. package/dist/runtime/network/index.d.ts +0 -4
  48. package/dist/runtime/network/index.js +0 -6
  49. package/dist/runtime/network/network.cjs +0 -91
  50. package/dist/runtime/network/network.d.cts +0 -28
  51. package/dist/runtime/network/network.d.ts +0 -28
  52. package/dist/runtime/network/network.js +0 -67
  53. package/dist/runtime/recovery/agent.cjs +0 -223
  54. package/dist/runtime/recovery/agent.d.cts +0 -13
  55. package/dist/runtime/recovery/agent.d.ts +0 -13
  56. package/dist/runtime/recovery/agent.js +0 -199
  57. package/dist/runtime/recovery/errors.cjs +0 -124
  58. package/dist/runtime/recovery/errors.d.cts +0 -31
  59. package/dist/runtime/recovery/errors.d.ts +0 -31
  60. package/dist/runtime/recovery/errors.js +0 -100
  61. package/dist/runtime/recovery/index.cjs +0 -34
  62. package/dist/runtime/recovery/index.d.cts +0 -7
  63. package/dist/runtime/recovery/index.d.ts +0 -7
  64. package/dist/runtime/recovery/index.js +0 -10
  65. package/dist/runtime/recovery/recovery.cjs +0 -55
  66. package/dist/runtime/recovery/recovery.d.cts +0 -12
  67. package/dist/runtime/recovery/recovery.d.ts +0 -12
  68. package/dist/runtime/recovery/recovery.js +0 -31
  69. package/dist/shared/config/config.cjs +0 -44
  70. package/dist/shared/config/config.d.cts +0 -10
  71. package/dist/shared/config/config.d.ts +0 -10
  72. package/dist/shared/config/config.js +0 -18
  73. package/dist/shared/config/index.cjs +0 -32
  74. package/dist/shared/config/index.d.cts +0 -1
  75. package/dist/shared/config/index.d.ts +0 -1
  76. package/dist/shared/config/index.js +0 -10
  77. package/dist/shared/debug/index.cjs +0 -30
  78. package/dist/shared/debug/index.d.cts +0 -1
  79. package/dist/shared/debug/index.d.ts +0 -1
  80. package/dist/shared/debug/index.js +0 -5
  81. package/dist/shared/debug/pause.cjs +0 -90
  82. package/dist/shared/debug/pause.d.cts +0 -16
  83. package/dist/shared/debug/pause.d.ts +0 -16
  84. package/dist/shared/debug/pause.js +0 -55
  85. package/dist/shared/instrumentation/errors.cjs +0 -81
  86. package/dist/shared/instrumentation/errors.d.cts +0 -12
  87. package/dist/shared/instrumentation/errors.d.ts +0 -12
  88. package/dist/shared/instrumentation/errors.js +0 -57
  89. package/dist/shared/instrumentation/index.cjs +0 -35
  90. package/dist/shared/instrumentation/index.d.cts +0 -6
  91. package/dist/shared/instrumentation/index.d.ts +0 -6
  92. package/dist/shared/instrumentation/index.js +0 -12
  93. package/dist/shared/instrumentation/instrument.cjs +0 -206
  94. package/dist/shared/instrumentation/instrument.d.cts +0 -32
  95. package/dist/shared/instrumentation/instrument.d.ts +0 -32
  96. package/dist/shared/instrumentation/instrument.js +0 -190
  97. package/dist/shared/llm/ai-sdk-adapter.cjs +0 -67
  98. package/dist/shared/llm/ai-sdk-adapter.d.cts +0 -22
  99. package/dist/shared/llm/ai-sdk-adapter.d.ts +0 -22
  100. package/dist/shared/llm/ai-sdk-adapter.js +0 -43
  101. package/dist/shared/llm/client.cjs +0 -139
  102. package/dist/shared/llm/client.d.cts +0 -6
  103. package/dist/shared/llm/client.d.ts +0 -6
  104. package/dist/shared/llm/client.js +0 -115
  105. package/dist/shared/llm/index.cjs +0 -31
  106. package/dist/shared/llm/index.d.cts +0 -5
  107. package/dist/shared/llm/index.d.ts +0 -5
  108. package/dist/shared/llm/index.js +0 -6
  109. package/dist/shared/llm/types.cjs +0 -16
  110. package/dist/shared/llm/types.d.cts +0 -66
  111. package/dist/shared/llm/types.d.ts +0 -66
  112. package/dist/shared/llm/types.js +0 -0
  113. package/dist/shared/logger/index.cjs +0 -37
  114. package/dist/shared/logger/index.d.cts +0 -2
  115. package/dist/shared/logger/index.d.ts +0 -2
  116. package/dist/shared/logger/index.js +0 -13
  117. package/dist/shared/logger/logger.cjs +0 -213
  118. package/dist/shared/logger/logger.d.cts +0 -82
  119. package/dist/shared/logger/logger.d.ts +0 -82
  120. package/dist/shared/logger/logger.js +0 -188
  121. package/dist/shared/logger/sinks.cjs +0 -160
  122. package/dist/shared/logger/sinks.d.cts +0 -9
  123. package/dist/shared/logger/sinks.d.ts +0 -9
  124. package/dist/shared/logger/sinks.js +0 -124
  125. package/dist/shared/paths/paths.cjs +0 -104
  126. package/dist/shared/paths/paths.d.cts +0 -10
  127. package/dist/shared/paths/paths.d.ts +0 -10
  128. package/dist/shared/paths/paths.js +0 -73
  129. package/dist/shared/run/api.cjs +0 -28
  130. package/dist/shared/run/api.d.cts +0 -2
  131. package/dist/shared/run/api.d.ts +0 -2
  132. package/dist/shared/run/api.js +0 -4
  133. package/dist/shared/run/browser.cjs +0 -98
  134. package/dist/shared/run/browser.d.cts +0 -22
  135. package/dist/shared/run/browser.d.ts +0 -22
  136. package/dist/shared/run/browser.js +0 -74
  137. package/dist/shared/state/index.cjs +0 -38
  138. package/dist/shared/state/index.d.cts +0 -2
  139. package/dist/shared/state/index.d.ts +0 -2
  140. package/dist/shared/state/index.js +0 -16
  141. package/dist/shared/state/session-state.cjs +0 -85
  142. package/dist/shared/state/session-state.d.cts +0 -34
  143. package/dist/shared/state/session-state.d.ts +0 -34
  144. package/dist/shared/state/session-state.js +0 -56
  145. package/dist/shared/visualization/ghost-cursor.cjs +0 -174
  146. package/dist/shared/visualization/ghost-cursor.d.cts +0 -37
  147. package/dist/shared/visualization/ghost-cursor.d.ts +0 -37
  148. package/dist/shared/visualization/ghost-cursor.js +0 -145
  149. package/dist/shared/visualization/highlight.cjs +0 -134
  150. package/dist/shared/visualization/highlight.d.cts +0 -22
  151. package/dist/shared/visualization/highlight.d.ts +0 -22
  152. package/dist/shared/visualization/highlight.js +0 -108
  153. package/dist/shared/visualization/index.cjs +0 -45
  154. package/dist/shared/visualization/index.d.cts +0 -3
  155. package/dist/shared/visualization/index.d.ts +0 -3
  156. package/dist/shared/visualization/index.js +0 -24
  157. package/dist/shared/workflow/workflow.cjs +0 -47
  158. package/dist/shared/workflow/workflow.d.cts +0 -21
  159. package/dist/shared/workflow/workflow.d.ts +0 -21
  160. package/dist/shared/workflow/workflow.js +0 -21
@@ -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,74 +0,0 @@
1
- import { chromium } from "playwright";
2
- import { createServer } from "node:net";
3
- import { existsSync, readFileSync, writeFileSync } from "node:fs";
4
- import { ensureLibrettoSessionStatePath } from "../paths/paths.js";
5
- import { SESSION_STATE_VERSION, SessionStateFileSchema } from "../state/session-state.js";
6
- async function pickFreePort() {
7
- return await new Promise((resolve, reject) => {
8
- const server = createServer();
9
- server.unref();
10
- server.on("error", reject);
11
- server.listen(0, "127.0.0.1", () => {
12
- const addr = server.address();
13
- if (addr && typeof addr === "object") {
14
- server.close(() => resolve(addr.port));
15
- return;
16
- }
17
- server.close(() => reject(new Error("Failed to resolve debug port")));
18
- });
19
- });
20
- }
21
- async function launchBrowser({
22
- sessionName,
23
- headless = false,
24
- viewport = { width: 1366, height: 768 },
25
- storageStatePath
26
- }) {
27
- const debugPort = await pickFreePort();
28
- const browser = await chromium.launch({
29
- headless,
30
- args: [
31
- "--disable-blink-features=AutomationControlled",
32
- `--remote-debugging-port=${debugPort}`,
33
- "--no-focus-on-check"
34
- ]
35
- });
36
- const context = await browser.newContext({
37
- viewport,
38
- ...storageStatePath ? { storageState: storageStatePath } : {}
39
- });
40
- const page = await context.newPage();
41
- page.setDefaultTimeout(3e4);
42
- page.setDefaultNavigationTimeout(45e3);
43
- const metadataPath = ensureLibrettoSessionStatePath(sessionName);
44
- const existingStateRaw = existsSync(metadataPath) ? JSON.parse(readFileSync(metadataPath, "utf-8")) : void 0;
45
- const parsedExistingState = SessionStateFileSchema.safeParse(existingStateRaw);
46
- writeFileSync(
47
- metadataPath,
48
- JSON.stringify(
49
- {
50
- version: parsedExistingState.success ? parsedExistingState.data.version : SESSION_STATE_VERSION,
51
- session: sessionName,
52
- port: debugPort,
53
- pid: process.pid,
54
- startedAt: (/* @__PURE__ */ new Date()).toISOString(),
55
- status: "active"
56
- },
57
- null,
58
- 2
59
- )
60
- );
61
- return {
62
- browser,
63
- context,
64
- page,
65
- debugPort,
66
- metadataPath,
67
- close: async () => {
68
- await browser.close();
69
- }
70
- };
71
- }
72
- export {
73
- launchBrowser
74
- };
@@ -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,2 +0,0 @@
1
- export { SESSION_STATE_VERSION, SessionState, SessionStateFile, SessionStateFileSchema, SessionStatus, SessionStatusSchema, parseSessionStateContent, parseSessionStateData, serializeSessionState } from './session-state.js';
2
- import 'zod';
@@ -1,16 +0,0 @@
1
- import {
2
- SESSION_STATE_VERSION,
3
- SessionStatusSchema,
4
- SessionStateFileSchema,
5
- parseSessionStateData,
6
- parseSessionStateContent,
7
- serializeSessionState
8
- } from "./session-state.js";
9
- export {
10
- SESSION_STATE_VERSION,
11
- SessionStateFileSchema,
12
- SessionStatusSchema,
13
- parseSessionStateContent,
14
- parseSessionStateData,
15
- serializeSessionState
16
- };
@@ -1,85 +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
- parseSessionStateContent: () => parseSessionStateContent,
25
- parseSessionStateData: () => parseSessionStateData,
26
- serializeSessionState: () => serializeSessionState
27
- });
28
- module.exports = __toCommonJS(session_state_exports);
29
- var import_zod = require("zod");
30
- const SESSION_STATE_VERSION = 1;
31
- const SessionStatusSchema = import_zod.z.enum([
32
- "active",
33
- "paused",
34
- "completed",
35
- "failed",
36
- "exited"
37
- ]);
38
- const SessionStateFileSchema = import_zod.z.object({
39
- version: import_zod.z.literal(SESSION_STATE_VERSION),
40
- port: import_zod.z.number().int().min(0).max(65535),
41
- pid: import_zod.z.number().int(),
42
- session: import_zod.z.string().min(1),
43
- startedAt: import_zod.z.string().datetime({ offset: true }),
44
- status: SessionStatusSchema.optional()
45
- });
46
- function formatIssues(error) {
47
- return error.issues.map((issue) => {
48
- const path = issue.path.join(".") || "root";
49
- return `${path}: ${issue.message}`;
50
- }).join("; ");
51
- }
52
- function parseSessionStateData(rawState, source) {
53
- const parsed = SessionStateFileSchema.safeParse(rawState);
54
- if (!parsed.success) {
55
- throw new Error(`Session state at ${source} is invalid: ${formatIssues(parsed.error)}`);
56
- }
57
- const { version: _version, ...state } = parsed.data;
58
- return state;
59
- }
60
- function parseSessionStateContent(content, source) {
61
- let rawState;
62
- try {
63
- rawState = JSON.parse(content);
64
- } catch (error) {
65
- throw new Error(
66
- `Session state at ${source} is not valid JSON: ${error instanceof Error ? error.message : String(error)}`
67
- );
68
- }
69
- return parseSessionStateData(rawState, source);
70
- }
71
- function serializeSessionState(state) {
72
- return SessionStateFileSchema.parse({
73
- version: SESSION_STATE_VERSION,
74
- ...state
75
- });
76
- }
77
- // Annotate the CommonJS export names for ESM import in node:
78
- 0 && (module.exports = {
79
- SESSION_STATE_VERSION,
80
- SessionStateFileSchema,
81
- SessionStatusSchema,
82
- parseSessionStateContent,
83
- parseSessionStateData,
84
- serializeSessionState
85
- });
@@ -1,34 +0,0 @@
1
- import { z } from 'zod';
2
-
3
- declare const SESSION_STATE_VERSION = 1;
4
- declare const SessionStatusSchema: z.ZodEnum<["active", "paused", "completed", "failed", "exited"]>;
5
- declare const SessionStateFileSchema: z.ZodObject<{
6
- version: z.ZodLiteral<1>;
7
- port: z.ZodNumber;
8
- pid: z.ZodNumber;
9
- session: z.ZodString;
10
- startedAt: z.ZodString;
11
- status: z.ZodOptional<z.ZodEnum<["active", "paused", "completed", "failed", "exited"]>>;
12
- }, "strip", z.ZodTypeAny, {
13
- version: 1;
14
- port: number;
15
- pid: number;
16
- session: string;
17
- startedAt: string;
18
- status?: "active" | "paused" | "completed" | "failed" | "exited" | undefined;
19
- }, {
20
- version: 1;
21
- port: number;
22
- pid: number;
23
- session: string;
24
- startedAt: string;
25
- status?: "active" | "paused" | "completed" | "failed" | "exited" | undefined;
26
- }>;
27
- type SessionStatus = z.infer<typeof SessionStatusSchema>;
28
- type SessionStateFile = z.infer<typeof SessionStateFileSchema>;
29
- type SessionState = Omit<SessionStateFile, "version">;
30
- declare function parseSessionStateData(rawState: unknown, source: string): SessionState;
31
- declare function parseSessionStateContent(content: string, source: string): SessionState;
32
- declare function serializeSessionState(state: SessionState): SessionStateFile;
33
-
34
- export { SESSION_STATE_VERSION, type SessionState, type SessionStateFile, SessionStateFileSchema, type SessionStatus, SessionStatusSchema, parseSessionStateContent, parseSessionStateData, serializeSessionState };
@@ -1,34 +0,0 @@
1
- import { z } from 'zod';
2
-
3
- declare const SESSION_STATE_VERSION = 1;
4
- declare const SessionStatusSchema: z.ZodEnum<["active", "paused", "completed", "failed", "exited"]>;
5
- declare const SessionStateFileSchema: z.ZodObject<{
6
- version: z.ZodLiteral<1>;
7
- port: z.ZodNumber;
8
- pid: z.ZodNumber;
9
- session: z.ZodString;
10
- startedAt: z.ZodString;
11
- status: z.ZodOptional<z.ZodEnum<["active", "paused", "completed", "failed", "exited"]>>;
12
- }, "strip", z.ZodTypeAny, {
13
- version: 1;
14
- port: number;
15
- pid: number;
16
- session: string;
17
- startedAt: string;
18
- status?: "active" | "paused" | "completed" | "failed" | "exited" | undefined;
19
- }, {
20
- version: 1;
21
- port: number;
22
- pid: number;
23
- session: string;
24
- startedAt: string;
25
- status?: "active" | "paused" | "completed" | "failed" | "exited" | undefined;
26
- }>;
27
- type SessionStatus = z.infer<typeof SessionStatusSchema>;
28
- type SessionStateFile = z.infer<typeof SessionStateFileSchema>;
29
- type SessionState = Omit<SessionStateFile, "version">;
30
- declare function parseSessionStateData(rawState: unknown, source: string): SessionState;
31
- declare function parseSessionStateContent(content: string, source: string): SessionState;
32
- declare function serializeSessionState(state: SessionState): SessionStateFile;
33
-
34
- export { SESSION_STATE_VERSION, type SessionState, type SessionStateFile, SessionStateFileSchema, type SessionStatus, SessionStatusSchema, parseSessionStateContent, parseSessionStateData, serializeSessionState };
@@ -1,56 +0,0 @@
1
- import { z } from "zod";
2
- const SESSION_STATE_VERSION = 1;
3
- const SessionStatusSchema = z.enum([
4
- "active",
5
- "paused",
6
- "completed",
7
- "failed",
8
- "exited"
9
- ]);
10
- const SessionStateFileSchema = z.object({
11
- version: z.literal(SESSION_STATE_VERSION),
12
- port: z.number().int().min(0).max(65535),
13
- pid: z.number().int(),
14
- session: z.string().min(1),
15
- startedAt: z.string().datetime({ offset: true }),
16
- status: SessionStatusSchema.optional()
17
- });
18
- function formatIssues(error) {
19
- return error.issues.map((issue) => {
20
- const path = issue.path.join(".") || "root";
21
- return `${path}: ${issue.message}`;
22
- }).join("; ");
23
- }
24
- function parseSessionStateData(rawState, source) {
25
- const parsed = SessionStateFileSchema.safeParse(rawState);
26
- if (!parsed.success) {
27
- throw new Error(`Session state at ${source} is invalid: ${formatIssues(parsed.error)}`);
28
- }
29
- const { version: _version, ...state } = parsed.data;
30
- return state;
31
- }
32
- function parseSessionStateContent(content, source) {
33
- let rawState;
34
- try {
35
- rawState = JSON.parse(content);
36
- } catch (error) {
37
- throw new Error(
38
- `Session state at ${source} is not valid JSON: ${error instanceof Error ? error.message : String(error)}`
39
- );
40
- }
41
- return parseSessionStateData(rawState, source);
42
- }
43
- function serializeSessionState(state) {
44
- return SessionStateFileSchema.parse({
45
- version: SESSION_STATE_VERSION,
46
- ...state
47
- });
48
- }
49
- export {
50
- SESSION_STATE_VERSION,
51
- SessionStateFileSchema,
52
- SessionStatusSchema,
53
- parseSessionStateContent,
54
- parseSessionStateData,
55
- serializeSessionState
56
- };
@@ -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,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 };