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,28 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var network_exports = {};
20
- __export(network_exports, {
21
- pageRequest: () => import_network.pageRequest
22
- });
23
- module.exports = __toCommonJS(network_exports);
24
- var import_network = require("./network.js");
25
- // Annotate the CommonJS export names for ESM import in node:
26
- 0 && (module.exports = {
27
- pageRequest
28
- });
@@ -1,4 +0,0 @@
1
- export { PageRequestOptions, RequestConfig, pageRequest } from './network.cjs';
2
- import 'playwright';
3
- import 'zod';
4
- import '../../shared/logger/logger.cjs';
@@ -1,91 +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 network_exports = {};
20
- __export(network_exports, {
21
- pageRequest: () => pageRequest
22
- });
23
- module.exports = __toCommonJS(network_exports);
24
- async function pageRequest(page, config, options) {
25
- const { url, method = "GET", headers = {}, body, bodyType = "json", responseType = "json" } = config;
26
- const { logger, schema } = options ?? {};
27
- const startTime = Date.now();
28
- const fetchHeaders = { ...headers };
29
- let fetchBody;
30
- if (body !== void 0) {
31
- if (bodyType === "form") {
32
- fetchHeaders["Content-Type"] = "application/x-www-form-urlencoded";
33
- if (typeof body === "string") {
34
- fetchBody = body;
35
- } else {
36
- fetchBody = new URLSearchParams(
37
- Object.entries(body).map(([k, v]) => [k, String(v)])
38
- ).toString();
39
- }
40
- } else {
41
- fetchHeaders["Content-Type"] = "application/json";
42
- fetchBody = typeof body === "string" ? body : JSON.stringify(body);
43
- }
44
- }
45
- const result = await page.evaluate(
46
- async ({ url: url2, method: method2, headers: headers2, body: body2, responseType: responseType2 }) => {
47
- const res = await fetch(url2, {
48
- method: method2,
49
- headers: headers2,
50
- body: body2 ?? void 0
51
- });
52
- const status = res.status;
53
- const ok = res.ok;
54
- let data;
55
- if (responseType2 === "json") {
56
- data = await res.json();
57
- } else {
58
- data = await res.text();
59
- }
60
- return { status, ok, data };
61
- },
62
- { url, method, headers: fetchHeaders, body: fetchBody, responseType }
63
- );
64
- const duration = Date.now() - startTime;
65
- if (!result.ok) {
66
- logger?.warn("network:request:error", {
67
- method,
68
- url,
69
- status: result.status,
70
- duration,
71
- body: typeof result.data === "string" ? result.data.slice(0, 500) : void 0
72
- });
73
- throw new Error(
74
- `pageRequest failed: ${method} ${url} returned ${result.status}`
75
- );
76
- }
77
- logger?.info("network:request", {
78
- method,
79
- url,
80
- status: result.status,
81
- duration
82
- });
83
- if (schema) {
84
- return schema.parse(result.data);
85
- }
86
- return result.data;
87
- }
88
- // Annotate the CommonJS export names for ESM import in node:
89
- 0 && (module.exports = {
90
- pageRequest
91
- });
@@ -1,28 +0,0 @@
1
- import { Page } from 'playwright';
2
- import z from 'zod';
3
- import { MinimalLogger } from '../../shared/logger/logger.cjs';
4
-
5
- type RequestConfig = {
6
- url: string;
7
- method?: "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
8
- headers?: Record<string, string>;
9
- body?: Record<string, any> | string;
10
- /** How to serialize the body. Defaults to "json". */
11
- bodyType?: "json" | "form";
12
- /** How to parse the response. Defaults to "json". */
13
- responseType?: "json" | "text" | "xml";
14
- };
15
- type PageRequestOptions<T extends z.ZodType | undefined = undefined> = {
16
- logger?: MinimalLogger;
17
- /** Optional Zod schema to validate the response body. */
18
- schema?: T;
19
- };
20
- type PageRequestResult<T extends z.ZodType | undefined> = T extends z.ZodType ? z.infer<T> : any;
21
- /**
22
- * Executes a fetch() call inside the browser context via page.evaluate().
23
- * Provides typed request config, automatic response parsing, optional Zod
24
- * validation, and logging.
25
- */
26
- declare function pageRequest<T extends z.ZodType | undefined = undefined>(page: Page, config: RequestConfig, options?: PageRequestOptions<T>): Promise<PageRequestResult<T>>;
27
-
28
- export { type PageRequestOptions, type RequestConfig, pageRequest };
@@ -1,13 +0,0 @@
1
- import { Page } from 'playwright';
2
- import { MinimalLogger } from '../../shared/logger/logger.cjs';
3
- import { LLMClient } from '../../shared/llm/types.cjs';
4
- import 'zod';
5
-
6
- /**
7
- * Executes a vision-based recovery agent to recover from browser automation failures.
8
- * Takes a screenshot, sends it to the LLM with the instruction, and executes
9
- * the LLM's suggested browser actions.
10
- */
11
- declare function executeRecoveryAgent(page: Page, instruction: string, logger?: MinimalLogger, llmClient?: LLMClient): Promise<void>;
12
-
13
- export { executeRecoveryAgent };
@@ -1,124 +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
- detectSubmissionError: () => detectSubmissionError
22
- });
23
- module.exports = __toCommonJS(errors_exports);
24
- var import_logger = require("../../shared/logger/logger.js");
25
- var import_zod = require("zod");
26
- const detectSubmissionErrorSchema = import_zod.z.object({
27
- hasError: import_zod.z.boolean().describe("Whether an error is visible on the page"),
28
- matchedKnownErrorId: import_zod.z.string().nullable().describe("The ID of the matched known error, or null if no match"),
29
- errorMessage: import_zod.z.string().nullable().describe("The error message visible on screen, or null if no error")
30
- });
31
- async function detectSubmissionError(page, error, logContext, llmClient, knownErrors = [], logger) {
32
- const log = logger ?? import_logger.defaultLogger;
33
- let screenshot;
34
- let domSnapshot;
35
- try {
36
- const cdpClient = await page.context().newCDPSession(page);
37
- await cdpClient.send("Page.enable");
38
- const { data } = await cdpClient.send("Page.captureScreenshot", {
39
- format: "png"
40
- });
41
- screenshot = data;
42
- } catch (screenshotError) {
43
- log.warn(
44
- "Failed to take screenshot via CDP for error detection, skipping LLM analysis",
45
- { screenshotError, originalError: error }
46
- );
47
- throw error;
48
- }
49
- try {
50
- const htmlContent = await page.content();
51
- domSnapshot = htmlContent.length > 5e4 ? htmlContent.slice(0, 5e4) + "\n... [truncated]" : htmlContent;
52
- } catch (domError) {
53
- log.warn("Failed to capture DOM snapshot", {
54
- domError: domError instanceof Error ? domError.message : String(domError)
55
- });
56
- }
57
- const knownErrorsDescription = knownErrors.length > 0 ? `
58
- Known error patterns to look for:
59
- ${knownErrors.map((e, i) => `${i + 1}. ID: "${e.id}" - Patterns: ${e.errorPatterns.join(", ")}`).join("\n")}
60
- ` : "";
61
- const prompt = `You are analyzing a screenshot and DOM of a web page to detect if an error occurred during a browser automation process.
62
-
63
- Context: ${logContext}
64
-
65
- ${knownErrorsDescription}
66
-
67
- Analyze the screenshot and DOM snapshot to determine:
68
- 1. Is there any error message, warning, or indication of failure visible on the page?
69
- 2. If yes, does it match any of the known error patterns listed above?
70
- 3. What is the exact error message or description of the problem?
71
-
72
- IMPORTANT:
73
- - Look carefully for error alerts, warning banners, error modals, red text, or any indication of failure
74
- - Check the DOM snapshot for error messages that may not be visible in the screenshot
75
- - If you see a known error pattern, use its exact ID in matchedKnownErrorId
76
- - If there's an error but it doesn't match any known pattern, set matchedKnownErrorId to null
77
- - If the page looks normal with no errors, set hasError to false
78
-
79
- ${domSnapshot ? `<dom_snapshot>
80
- ${domSnapshot}
81
- </dom_snapshot>` : ""}`;
82
- const result = await llmClient.generateObjectFromMessages({
83
- schema: detectSubmissionErrorSchema,
84
- messages: [
85
- {
86
- role: "user",
87
- content: [
88
- { type: "text", text: prompt },
89
- { type: "image", image: `data:image/png;base64,${screenshot}` }
90
- ]
91
- }
92
- ],
93
- temperature: 0
94
- });
95
- if (!result.hasError) {
96
- log.info("No error detected by LLM", { result });
97
- }
98
- if (result.matchedKnownErrorId) {
99
- const knownError = knownErrors.find(
100
- (e) => e.id === result.matchedKnownErrorId
101
- );
102
- if (knownError) {
103
- log.warn(logContext, {
104
- error,
105
- browserError: result.errorMessage,
106
- knownErrorId: result.matchedKnownErrorId
107
- });
108
- return {
109
- matched: true,
110
- errorId: knownError.id,
111
- message: knownError.userMessage
112
- };
113
- }
114
- }
115
- log.warn(logContext, {
116
- error,
117
- browserError: result.errorMessage
118
- });
119
- throw error;
120
- }
121
- // Annotate the CommonJS export names for ESM import in node:
122
- 0 && (module.exports = {
123
- detectSubmissionError
124
- });
@@ -1,31 +0,0 @@
1
- import { Page } from 'playwright';
2
- import { MinimalLogger } from '../../shared/logger/logger.cjs';
3
- import { LLMClient } from '../../shared/llm/types.cjs';
4
- import 'zod';
5
-
6
- /**
7
- * Known error type for classifying submission errors.
8
- * errorPatterns are what the LLM should look for on screen.
9
- * userMessage is the friendly message returned when matched.
10
- */
11
- type KnownSubmissionError = {
12
- id: string;
13
- errorPatterns: string[];
14
- userMessage: string;
15
- };
16
- type DetectedSubmissionError = {
17
- matched: true;
18
- errorId: string;
19
- message: string;
20
- };
21
- /**
22
- * Uses screenshot + LLM vision to detect if an error occurred during a submission process.
23
- * Captures a screenshot via CDP (handles unresponsive pages), sends it to the LLM,
24
- * and checks against the provided known error patterns.
25
- *
26
- * @returns DetectedSubmissionError if a known error is matched
27
- * @throws The original error if no known error matches
28
- */
29
- declare function detectSubmissionError(page: Page, error: unknown, logContext: string, llmClient: LLMClient, knownErrors?: KnownSubmissionError[], logger?: MinimalLogger): Promise<DetectedSubmissionError>;
30
-
31
- export { type DetectedSubmissionError, type KnownSubmissionError, detectSubmissionError };
@@ -1,34 +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 recovery_exports = {};
20
- __export(recovery_exports, {
21
- attemptWithRecovery: () => import_recovery.attemptWithRecovery,
22
- detectSubmissionError: () => import_errors.detectSubmissionError,
23
- executeRecoveryAgent: () => import_agent.executeRecoveryAgent
24
- });
25
- module.exports = __toCommonJS(recovery_exports);
26
- var import_agent = require("./agent.js");
27
- var import_recovery = require("./recovery.js");
28
- var import_errors = require("./errors.js");
29
- // Annotate the CommonJS export names for ESM import in node:
30
- 0 && (module.exports = {
31
- attemptWithRecovery,
32
- detectSubmissionError,
33
- executeRecoveryAgent
34
- });
@@ -1,7 +0,0 @@
1
- export { executeRecoveryAgent } from './agent.cjs';
2
- export { attemptWithRecovery } from './recovery.cjs';
3
- export { DetectedSubmissionError, KnownSubmissionError, detectSubmissionError } from './errors.cjs';
4
- import 'playwright';
5
- import '../../shared/logger/logger.cjs';
6
- import '../../shared/llm/types.cjs';
7
- import 'zod';
@@ -1,55 +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 recovery_exports = {};
20
- __export(recovery_exports, {
21
- attemptWithRecovery: () => attemptWithRecovery
22
- });
23
- module.exports = __toCommonJS(recovery_exports);
24
- var import_logger = require("../../shared/logger/logger.js");
25
- var import_agent = require("./agent.js");
26
- async function attemptWithRecovery(page, fn, logger, llmClient) {
27
- const log = logger ?? import_logger.defaultLogger;
28
- try {
29
- return await fn();
30
- } catch (error) {
31
- if (error instanceof Error && (error.message.includes("Target closed") || error.message.includes("browser has been closed") || error.message.includes("context or browser has been closed"))) {
32
- log.warn("Page/browser has been closed, cannot recover", {
33
- error: error.message
34
- });
35
- throw error;
36
- }
37
- if (!llmClient) {
38
- throw error;
39
- }
40
- log.info("Action failed, attempting popup recovery", {
41
- error: error instanceof Error ? error.message : String(error)
42
- });
43
- await (0, import_agent.executeRecoveryAgent)(
44
- page,
45
- "Look at the page to see if there is a popup blocking the screen. If so, close the popup.",
46
- log,
47
- llmClient
48
- );
49
- return await fn();
50
- }
51
- }
52
- // Annotate the CommonJS export names for ESM import in node:
53
- 0 && (module.exports = {
54
- attemptWithRecovery
55
- });
@@ -1,12 +0,0 @@
1
- import { Page } from 'playwright';
2
- import { MinimalLogger } from '../../shared/logger/logger.cjs';
3
- import { LLMClient } from '../../shared/llm/types.cjs';
4
- import 'zod';
5
-
6
- /**
7
- * Attempts to execute a function, and if it fails, runs popup recovery
8
- * (if an LLM client is provided) and retries the function once.
9
- */
10
- declare function attemptWithRecovery<T>(page: Page, fn: () => Promise<T>, logger?: MinimalLogger, llmClient?: LLMClient): Promise<T>;
11
-
12
- export { attemptWithRecovery };
@@ -1,34 +0,0 @@
1
- /**
2
- * DOM condensation — reduces serialized HTML for LLM consumption.
3
- *
4
- * All rules run unconditionally (no tiers). The function operates on
5
- * already-serialized HTML strings (the output of `page.content()`),
6
- * not a browser-side DOM walk or parsed DOM tree.
7
- *
8
- * Rules applied in order:
9
- * 1. Noscript blocks — remove entirely
10
- * 2. HTML comments — remove entirely
11
- * 3. Script contents — hollow out, keep tags + useful attributes
12
- * 4. Style contents — hollow out, keep tags + useful attributes
13
- * 5. Embedded binary data — replace base64 data URIs
14
- * 6. Attribute allowlist — keep trusted attrs, special-case class/style/URLs
15
- * 7. SVG elements — collapse to single tag, extract title/desc
16
- * 8. Inline style properties — keep only layout-relevant props
17
- * 9. Non-semantic class names — filter or delete class values
18
- * 10. (Cross-reference IDs — preserved, no action needed)
19
- * 11. Framework-internal and SVG visual attributes — remove
20
- * 12. Whitespace — collapse (preserve <pre> content)
21
- */
22
- type CondenseDomResult = {
23
- /** The condensed HTML string. Valid, parseable HTML. */
24
- html: string;
25
- /** Character count of the input. */
26
- originalLength: number;
27
- /** Character count of the output. */
28
- condensedLength: number;
29
- /** Characters removed, keyed by rule name. */
30
- reductions: Record<string, number>;
31
- };
32
- declare function condenseDom(html: string): CondenseDomResult;
33
-
34
- export { type CondenseDomResult, condenseDom };
@@ -1,44 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var config_exports = {};
20
- __export(config_exports, {
21
- isDebugMode: () => isDebugMode,
22
- isDryRun: () => isDryRun,
23
- shouldPauseBeforeMutation: () => shouldPauseBeforeMutation
24
- });
25
- module.exports = __toCommonJS(config_exports);
26
- function isDebugMode() {
27
- return process.env.LIBRETTO_DEBUG === "true";
28
- }
29
- function isDryRun() {
30
- const explicit = process.env.LIBRETTO_DRY_RUN;
31
- if (explicit !== void 0) {
32
- return explicit === "true";
33
- }
34
- return process.env.NODE_ENV === "development";
35
- }
36
- function shouldPauseBeforeMutation() {
37
- return isDryRun() && isDebugMode();
38
- }
39
- // Annotate the CommonJS export names for ESM import in node:
40
- 0 && (module.exports = {
41
- isDebugMode,
42
- isDryRun,
43
- shouldPauseBeforeMutation
44
- });
@@ -1,10 +0,0 @@
1
- /**
2
- * Runtime configuration for libretto.
3
- *
4
- * Values are derived from environment variables only.
5
- */
6
- declare function isDebugMode(): boolean;
7
- declare function isDryRun(): boolean;
8
- declare function shouldPauseBeforeMutation(): boolean;
9
-
10
- export { isDebugMode, isDryRun, shouldPauseBeforeMutation };
@@ -1,32 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var config_exports = {};
20
- __export(config_exports, {
21
- isDebugMode: () => import_config.isDebugMode,
22
- isDryRun: () => import_config.isDryRun,
23
- shouldPauseBeforeMutation: () => import_config.shouldPauseBeforeMutation
24
- });
25
- module.exports = __toCommonJS(config_exports);
26
- var import_config = require("./config.js");
27
- // Annotate the CommonJS export names for ESM import in node:
28
- 0 && (module.exports = {
29
- isDebugMode,
30
- isDryRun,
31
- shouldPauseBeforeMutation
32
- });
@@ -1 +0,0 @@
1
- export { isDebugMode, isDryRun, shouldPauseBeforeMutation } from './config.cjs';
@@ -1,28 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var debug_exports = {};
20
- __export(debug_exports, {
21
- pause: () => import_pause.pause
22
- });
23
- module.exports = __toCommonJS(debug_exports);
24
- var import_pause = require("./pause.js");
25
- // Annotate the CommonJS export names for ESM import in node:
26
- 0 && (module.exports = {
27
- pause
28
- });
@@ -1 +0,0 @@
1
- export { pause } from './pause.cjs';