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.
- package/LICENSE +21 -0
- package/package.json +12 -12
- package/skill/SKILL.md +20 -18
- package/skill/code-generation-rules.md +3 -3
- package/skill/integration-approach-selection.md +3 -3
- package/dist/cli/cli.js +0 -209
- package/dist/cli/commands/ai.js +0 -21
- package/dist/cli/commands/browser.js +0 -82
- package/dist/cli/commands/execution.js +0 -461
- package/dist/cli/commands/init.js +0 -95
- package/dist/cli/commands/logs.js +0 -93
- package/dist/cli/commands/snapshot.js +0 -106
- package/dist/cli/core/ai-config.js +0 -149
- package/dist/cli/core/browser.js +0 -648
- package/dist/cli/core/context.js +0 -118
- package/dist/cli/core/pause-signals.js +0 -29
- package/dist/cli/core/session-telemetry.js +0 -491
- package/dist/cli/core/session.js +0 -183
- package/dist/cli/core/snapshot-analyzer.js +0 -492
- package/dist/cli/core/telemetry.js +0 -362
- package/dist/cli/index.js +0 -13
- package/dist/cli/workers/run-integration-runtime.js +0 -227
- package/dist/cli/workers/run-integration-worker-protocol.js +0 -12
- package/dist/cli/workers/run-integration-worker.js +0 -66
- package/dist/index.cjs +0 -116
- package/dist/index.d.cts +0 -21
- package/dist/index.d.ts +0 -21
- package/dist/index.js +0 -97
- package/dist/runtime/download/download.cjs +0 -70
- package/dist/runtime/download/download.d.cts +0 -35
- package/dist/runtime/download/download.d.ts +0 -35
- package/dist/runtime/download/download.js +0 -45
- package/dist/runtime/download/index.cjs +0 -30
- package/dist/runtime/download/index.d.cts +0 -3
- package/dist/runtime/download/index.d.ts +0 -3
- package/dist/runtime/download/index.js +0 -8
- package/dist/runtime/extract/extract.cjs +0 -88
- package/dist/runtime/extract/extract.d.cts +0 -23
- package/dist/runtime/extract/extract.d.ts +0 -23
- package/dist/runtime/extract/extract.js +0 -64
- package/dist/runtime/extract/index.cjs +0 -28
- package/dist/runtime/extract/index.d.cts +0 -5
- package/dist/runtime/extract/index.d.ts +0 -5
- package/dist/runtime/extract/index.js +0 -4
- package/dist/runtime/network/index.cjs +0 -28
- package/dist/runtime/network/index.d.cts +0 -4
- package/dist/runtime/network/index.d.ts +0 -4
- package/dist/runtime/network/index.js +0 -6
- package/dist/runtime/network/network.cjs +0 -91
- package/dist/runtime/network/network.d.cts +0 -28
- package/dist/runtime/network/network.d.ts +0 -28
- package/dist/runtime/network/network.js +0 -67
- package/dist/runtime/recovery/agent.cjs +0 -223
- package/dist/runtime/recovery/agent.d.cts +0 -13
- package/dist/runtime/recovery/agent.d.ts +0 -13
- package/dist/runtime/recovery/agent.js +0 -199
- package/dist/runtime/recovery/errors.cjs +0 -124
- package/dist/runtime/recovery/errors.d.cts +0 -31
- package/dist/runtime/recovery/errors.d.ts +0 -31
- package/dist/runtime/recovery/errors.js +0 -100
- package/dist/runtime/recovery/index.cjs +0 -34
- package/dist/runtime/recovery/index.d.cts +0 -7
- package/dist/runtime/recovery/index.d.ts +0 -7
- package/dist/runtime/recovery/index.js +0 -10
- package/dist/runtime/recovery/recovery.cjs +0 -55
- package/dist/runtime/recovery/recovery.d.cts +0 -12
- package/dist/runtime/recovery/recovery.d.ts +0 -12
- package/dist/runtime/recovery/recovery.js +0 -31
- package/dist/shared/config/config.cjs +0 -44
- package/dist/shared/config/config.d.cts +0 -10
- package/dist/shared/config/config.d.ts +0 -10
- package/dist/shared/config/config.js +0 -18
- package/dist/shared/config/index.cjs +0 -32
- package/dist/shared/config/index.d.cts +0 -1
- package/dist/shared/config/index.d.ts +0 -1
- package/dist/shared/config/index.js +0 -10
- package/dist/shared/debug/index.cjs +0 -30
- package/dist/shared/debug/index.d.cts +0 -1
- package/dist/shared/debug/index.d.ts +0 -1
- package/dist/shared/debug/index.js +0 -5
- package/dist/shared/debug/pause.cjs +0 -90
- package/dist/shared/debug/pause.d.cts +0 -16
- package/dist/shared/debug/pause.d.ts +0 -16
- package/dist/shared/debug/pause.js +0 -55
- package/dist/shared/instrumentation/errors.cjs +0 -81
- package/dist/shared/instrumentation/errors.d.cts +0 -12
- package/dist/shared/instrumentation/errors.d.ts +0 -12
- package/dist/shared/instrumentation/errors.js +0 -57
- package/dist/shared/instrumentation/index.cjs +0 -35
- package/dist/shared/instrumentation/index.d.cts +0 -6
- package/dist/shared/instrumentation/index.d.ts +0 -6
- package/dist/shared/instrumentation/index.js +0 -12
- package/dist/shared/instrumentation/instrument.cjs +0 -206
- package/dist/shared/instrumentation/instrument.d.cts +0 -32
- package/dist/shared/instrumentation/instrument.d.ts +0 -32
- package/dist/shared/instrumentation/instrument.js +0 -190
- package/dist/shared/llm/ai-sdk-adapter.cjs +0 -67
- package/dist/shared/llm/ai-sdk-adapter.d.cts +0 -22
- package/dist/shared/llm/ai-sdk-adapter.d.ts +0 -22
- package/dist/shared/llm/ai-sdk-adapter.js +0 -43
- package/dist/shared/llm/client.cjs +0 -139
- package/dist/shared/llm/client.d.cts +0 -6
- package/dist/shared/llm/client.d.ts +0 -6
- package/dist/shared/llm/client.js +0 -115
- package/dist/shared/llm/index.cjs +0 -31
- package/dist/shared/llm/index.d.cts +0 -5
- package/dist/shared/llm/index.d.ts +0 -5
- package/dist/shared/llm/index.js +0 -6
- package/dist/shared/llm/types.cjs +0 -16
- package/dist/shared/llm/types.d.cts +0 -66
- package/dist/shared/llm/types.d.ts +0 -66
- package/dist/shared/llm/types.js +0 -0
- package/dist/shared/logger/index.cjs +0 -37
- package/dist/shared/logger/index.d.cts +0 -2
- package/dist/shared/logger/index.d.ts +0 -2
- package/dist/shared/logger/index.js +0 -13
- package/dist/shared/logger/logger.cjs +0 -213
- package/dist/shared/logger/logger.d.cts +0 -82
- package/dist/shared/logger/logger.d.ts +0 -82
- package/dist/shared/logger/logger.js +0 -188
- package/dist/shared/logger/sinks.cjs +0 -160
- package/dist/shared/logger/sinks.d.cts +0 -9
- package/dist/shared/logger/sinks.d.ts +0 -9
- package/dist/shared/logger/sinks.js +0 -124
- package/dist/shared/paths/paths.cjs +0 -104
- package/dist/shared/paths/paths.d.cts +0 -10
- package/dist/shared/paths/paths.d.ts +0 -10
- package/dist/shared/paths/paths.js +0 -73
- package/dist/shared/run/api.cjs +0 -28
- package/dist/shared/run/api.d.cts +0 -2
- package/dist/shared/run/api.d.ts +0 -2
- package/dist/shared/run/api.js +0 -4
- package/dist/shared/run/browser.cjs +0 -98
- package/dist/shared/run/browser.d.cts +0 -22
- package/dist/shared/run/browser.d.ts +0 -22
- package/dist/shared/run/browser.js +0 -74
- package/dist/shared/state/index.cjs +0 -38
- package/dist/shared/state/index.d.cts +0 -2
- package/dist/shared/state/index.d.ts +0 -2
- package/dist/shared/state/index.js +0 -16
- package/dist/shared/state/session-state.cjs +0 -85
- package/dist/shared/state/session-state.d.cts +0 -34
- package/dist/shared/state/session-state.d.ts +0 -34
- package/dist/shared/state/session-state.js +0 -56
- package/dist/shared/visualization/ghost-cursor.cjs +0 -174
- package/dist/shared/visualization/ghost-cursor.d.cts +0 -37
- package/dist/shared/visualization/ghost-cursor.d.ts +0 -37
- package/dist/shared/visualization/ghost-cursor.js +0 -145
- package/dist/shared/visualization/highlight.cjs +0 -134
- package/dist/shared/visualization/highlight.d.cts +0 -22
- package/dist/shared/visualization/highlight.d.ts +0 -22
- package/dist/shared/visualization/highlight.js +0 -108
- package/dist/shared/visualization/index.cjs +0 -45
- package/dist/shared/visualization/index.d.cts +0 -3
- package/dist/shared/visualization/index.d.ts +0 -3
- package/dist/shared/visualization/index.js +0 -24
- package/dist/shared/workflow/workflow.cjs +0 -47
- package/dist/shared/workflow/workflow.d.cts +0 -21
- package/dist/shared/workflow/workflow.d.ts +0 -21
- package/dist/shared/workflow/workflow.js +0 -21
|
@@ -1,199 +0,0 @@
|
|
|
1
|
-
import { defaultLogger } from "../../shared/logger/logger.js";
|
|
2
|
-
function delay(ms) {
|
|
3
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
4
|
-
}
|
|
5
|
-
const KEY_MAPPINGS = {
|
|
6
|
-
ENTER: "Enter",
|
|
7
|
-
RETURN: "Enter",
|
|
8
|
-
TAB: "Tab",
|
|
9
|
-
SPACE: " ",
|
|
10
|
-
BACKSPACE: "Backspace",
|
|
11
|
-
DELETE: "Delete",
|
|
12
|
-
ESCAPE: "Escape",
|
|
13
|
-
ESC: "Escape",
|
|
14
|
-
UP: "ArrowUp",
|
|
15
|
-
DOWN: "ArrowDown",
|
|
16
|
-
LEFT: "ArrowLeft",
|
|
17
|
-
RIGHT: "ArrowRight",
|
|
18
|
-
HOME: "Home",
|
|
19
|
-
END: "End",
|
|
20
|
-
PAGEUP: "PageUp",
|
|
21
|
-
PAGEDOWN: "PageDown",
|
|
22
|
-
CTRL: "Control",
|
|
23
|
-
CONTROL: "Control",
|
|
24
|
-
ALT: "Alt",
|
|
25
|
-
SHIFT: "Shift",
|
|
26
|
-
META: "Meta",
|
|
27
|
-
CMD: "Meta",
|
|
28
|
-
COMMAND: "Meta"
|
|
29
|
-
};
|
|
30
|
-
function mapKeyName(key) {
|
|
31
|
-
return KEY_MAPPINGS[key.toUpperCase()] ?? key;
|
|
32
|
-
}
|
|
33
|
-
async function executeBrowserAction(page, action, logger = defaultLogger) {
|
|
34
|
-
switch (action.type) {
|
|
35
|
-
case "click": {
|
|
36
|
-
const { x, y, button = "left" } = action;
|
|
37
|
-
const playwrightButton = button === "wheel" || button === "back" || button === "forward" ? "left" : button;
|
|
38
|
-
await page.mouse.click(x, y, { button: playwrightButton });
|
|
39
|
-
logger.info(`Clicked at (${x}, ${y}) with ${button} button`);
|
|
40
|
-
break;
|
|
41
|
-
}
|
|
42
|
-
case "double_click": {
|
|
43
|
-
const { x, y } = action;
|
|
44
|
-
await page.mouse.dblclick(x, y);
|
|
45
|
-
logger.info(`Double-clicked at (${x}, ${y})`);
|
|
46
|
-
break;
|
|
47
|
-
}
|
|
48
|
-
case "scroll": {
|
|
49
|
-
const { x, y, scroll_x, scroll_y } = action;
|
|
50
|
-
await page.mouse.move(x, y);
|
|
51
|
-
await page.evaluate(`window.scrollBy(${scroll_x}, ${scroll_y})`);
|
|
52
|
-
logger.info(`Scrolled at (${x}, ${y}) by (${scroll_x}, ${scroll_y})`);
|
|
53
|
-
break;
|
|
54
|
-
}
|
|
55
|
-
case "keypress": {
|
|
56
|
-
for (const key of action.keys) {
|
|
57
|
-
const mapped = mapKeyName(key);
|
|
58
|
-
await page.keyboard.press(mapped);
|
|
59
|
-
logger.info(`Pressed key: ${key} (mapped to ${mapped})`);
|
|
60
|
-
}
|
|
61
|
-
break;
|
|
62
|
-
}
|
|
63
|
-
case "type": {
|
|
64
|
-
await page.keyboard.type(action.text);
|
|
65
|
-
logger.info(`Typed text: ${action.text}`);
|
|
66
|
-
break;
|
|
67
|
-
}
|
|
68
|
-
case "wait": {
|
|
69
|
-
await delay(2e3);
|
|
70
|
-
logger.info("Waited 2 seconds");
|
|
71
|
-
break;
|
|
72
|
-
}
|
|
73
|
-
case "screenshot": {
|
|
74
|
-
logger.info("Screenshot action (no-op, taken automatically)");
|
|
75
|
-
break;
|
|
76
|
-
}
|
|
77
|
-
case "drag": {
|
|
78
|
-
const { path } = action;
|
|
79
|
-
const start = path[0];
|
|
80
|
-
const end = path[path.length - 1];
|
|
81
|
-
if (path.length >= 2 && start && end) {
|
|
82
|
-
await page.mouse.move(start.x, start.y);
|
|
83
|
-
await page.mouse.down();
|
|
84
|
-
for (let i = 1; i < path.length; i++) {
|
|
85
|
-
const point = path[i];
|
|
86
|
-
if (point) await page.mouse.move(point.x, point.y);
|
|
87
|
-
}
|
|
88
|
-
await page.mouse.up();
|
|
89
|
-
logger.info(`Dragged from (${start.x}, ${start.y}) to (${end.x}, ${end.y})`);
|
|
90
|
-
}
|
|
91
|
-
break;
|
|
92
|
-
}
|
|
93
|
-
case "move": {
|
|
94
|
-
const { x, y } = action;
|
|
95
|
-
await page.mouse.move(x, y);
|
|
96
|
-
logger.info(`Moved mouse to (${x}, ${y})`);
|
|
97
|
-
break;
|
|
98
|
-
}
|
|
99
|
-
case "done": {
|
|
100
|
-
break;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
import { z } from "zod";
|
|
105
|
-
const recoveryActionSchema = z.object({
|
|
106
|
-
reasoning: z.string().describe("Your reasoning about what you see and what action to take"),
|
|
107
|
-
action: z.discriminatedUnion("type", [
|
|
108
|
-
z.object({
|
|
109
|
-
type: z.literal("click"),
|
|
110
|
-
x: z.number(),
|
|
111
|
-
y: z.number()
|
|
112
|
-
}),
|
|
113
|
-
z.object({
|
|
114
|
-
type: z.literal("type"),
|
|
115
|
-
text: z.string()
|
|
116
|
-
}),
|
|
117
|
-
z.object({
|
|
118
|
-
type: z.literal("keypress"),
|
|
119
|
-
keys: z.array(z.string())
|
|
120
|
-
}),
|
|
121
|
-
z.object({
|
|
122
|
-
type: z.literal("scroll"),
|
|
123
|
-
x: z.number(),
|
|
124
|
-
y: z.number(),
|
|
125
|
-
scroll_x: z.number(),
|
|
126
|
-
scroll_y: z.number()
|
|
127
|
-
}),
|
|
128
|
-
z.object({
|
|
129
|
-
type: z.literal("wait")
|
|
130
|
-
}),
|
|
131
|
-
z.object({
|
|
132
|
-
type: z.literal("done")
|
|
133
|
-
})
|
|
134
|
-
])
|
|
135
|
-
});
|
|
136
|
-
async function executeRecoveryAgent(page, instruction, logger, llmClient) {
|
|
137
|
-
if (!llmClient) {
|
|
138
|
-
return;
|
|
139
|
-
}
|
|
140
|
-
const log = logger ?? defaultLogger;
|
|
141
|
-
log.info("Executing vision-based recovery agent", { instruction });
|
|
142
|
-
const viewport = page.viewportSize();
|
|
143
|
-
if (!viewport) {
|
|
144
|
-
throw new Error("Viewport size not found");
|
|
145
|
-
}
|
|
146
|
-
let screenshot;
|
|
147
|
-
try {
|
|
148
|
-
screenshot = (await page.screenshot({ fullPage: false, timeout: 1e4 })).toString("base64");
|
|
149
|
-
} catch (screenshotError) {
|
|
150
|
-
log.warn("Failed to take screenshot for recovery agent, skipping", {
|
|
151
|
-
screenshotError: screenshotError instanceof Error ? screenshotError.message : String(screenshotError)
|
|
152
|
-
});
|
|
153
|
-
throw new Error("Failed to take screenshot for recovery agent");
|
|
154
|
-
}
|
|
155
|
-
const maxSteps = 3;
|
|
156
|
-
for (let step = 1; step <= maxSteps; step++) {
|
|
157
|
-
const result = await llmClient.generateObjectFromMessages({
|
|
158
|
-
schema: recoveryActionSchema,
|
|
159
|
-
messages: [
|
|
160
|
-
{
|
|
161
|
-
role: "user",
|
|
162
|
-
content: [
|
|
163
|
-
{
|
|
164
|
-
type: "text",
|
|
165
|
-
text: `You are an expert browser support agent. Your job is to resolve issues when browser automation encounters unexpected website behavior (e.g., popups blocking interaction).
|
|
166
|
-
|
|
167
|
-
Your task: ${instruction}
|
|
168
|
-
|
|
169
|
-
Viewport: ${viewport.width}x${viewport.height}px. Complete this in as few steps as possible.
|
|
170
|
-
Analyze the screenshot and decide what action to take. If the task is complete or no action is needed, use the "done" action type.`
|
|
171
|
-
},
|
|
172
|
-
{
|
|
173
|
-
type: "image",
|
|
174
|
-
image: `data:image/png;base64,${screenshot}`
|
|
175
|
-
}
|
|
176
|
-
]
|
|
177
|
-
}
|
|
178
|
-
],
|
|
179
|
-
temperature: 0
|
|
180
|
-
});
|
|
181
|
-
log.info(`Recovery step ${step}/${maxSteps}`, {
|
|
182
|
-
reasoning: result.reasoning,
|
|
183
|
-
action: result.action
|
|
184
|
-
});
|
|
185
|
-
if (result.action.type === "done") {
|
|
186
|
-
log.info("Recovery agent completed - no more actions needed");
|
|
187
|
-
break;
|
|
188
|
-
}
|
|
189
|
-
await executeBrowserAction(page, result.action, log);
|
|
190
|
-
await delay(2e3);
|
|
191
|
-
screenshot = (await page.screenshot({ fullPage: false })).toString(
|
|
192
|
-
"base64"
|
|
193
|
-
);
|
|
194
|
-
}
|
|
195
|
-
log.info("Recovery agent execution completed");
|
|
196
|
-
}
|
|
197
|
-
export {
|
|
198
|
-
executeRecoveryAgent
|
|
199
|
-
};
|
|
@@ -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,31 +0,0 @@
|
|
|
1
|
-
import { Page } from 'playwright';
|
|
2
|
-
import { MinimalLogger } from '../../shared/logger/logger.js';
|
|
3
|
-
import { LLMClient } from '../../shared/llm/types.js';
|
|
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,100 +0,0 @@
|
|
|
1
|
-
import { defaultLogger } from "../../shared/logger/logger.js";
|
|
2
|
-
import { z } from "zod";
|
|
3
|
-
const detectSubmissionErrorSchema = z.object({
|
|
4
|
-
hasError: z.boolean().describe("Whether an error is visible on the page"),
|
|
5
|
-
matchedKnownErrorId: z.string().nullable().describe("The ID of the matched known error, or null if no match"),
|
|
6
|
-
errorMessage: z.string().nullable().describe("The error message visible on screen, or null if no error")
|
|
7
|
-
});
|
|
8
|
-
async function detectSubmissionError(page, error, logContext, llmClient, knownErrors = [], logger) {
|
|
9
|
-
const log = logger ?? defaultLogger;
|
|
10
|
-
let screenshot;
|
|
11
|
-
let domSnapshot;
|
|
12
|
-
try {
|
|
13
|
-
const cdpClient = await page.context().newCDPSession(page);
|
|
14
|
-
await cdpClient.send("Page.enable");
|
|
15
|
-
const { data } = await cdpClient.send("Page.captureScreenshot", {
|
|
16
|
-
format: "png"
|
|
17
|
-
});
|
|
18
|
-
screenshot = data;
|
|
19
|
-
} catch (screenshotError) {
|
|
20
|
-
log.warn(
|
|
21
|
-
"Failed to take screenshot via CDP for error detection, skipping LLM analysis",
|
|
22
|
-
{ screenshotError, originalError: error }
|
|
23
|
-
);
|
|
24
|
-
throw error;
|
|
25
|
-
}
|
|
26
|
-
try {
|
|
27
|
-
const htmlContent = await page.content();
|
|
28
|
-
domSnapshot = htmlContent.length > 5e4 ? htmlContent.slice(0, 5e4) + "\n... [truncated]" : htmlContent;
|
|
29
|
-
} catch (domError) {
|
|
30
|
-
log.warn("Failed to capture DOM snapshot", {
|
|
31
|
-
domError: domError instanceof Error ? domError.message : String(domError)
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
const knownErrorsDescription = knownErrors.length > 0 ? `
|
|
35
|
-
Known error patterns to look for:
|
|
36
|
-
${knownErrors.map((e, i) => `${i + 1}. ID: "${e.id}" - Patterns: ${e.errorPatterns.join(", ")}`).join("\n")}
|
|
37
|
-
` : "";
|
|
38
|
-
const prompt = `You are analyzing a screenshot and DOM of a web page to detect if an error occurred during a browser automation process.
|
|
39
|
-
|
|
40
|
-
Context: ${logContext}
|
|
41
|
-
|
|
42
|
-
${knownErrorsDescription}
|
|
43
|
-
|
|
44
|
-
Analyze the screenshot and DOM snapshot to determine:
|
|
45
|
-
1. Is there any error message, warning, or indication of failure visible on the page?
|
|
46
|
-
2. If yes, does it match any of the known error patterns listed above?
|
|
47
|
-
3. What is the exact error message or description of the problem?
|
|
48
|
-
|
|
49
|
-
IMPORTANT:
|
|
50
|
-
- Look carefully for error alerts, warning banners, error modals, red text, or any indication of failure
|
|
51
|
-
- Check the DOM snapshot for error messages that may not be visible in the screenshot
|
|
52
|
-
- If you see a known error pattern, use its exact ID in matchedKnownErrorId
|
|
53
|
-
- If there's an error but it doesn't match any known pattern, set matchedKnownErrorId to null
|
|
54
|
-
- If the page looks normal with no errors, set hasError to false
|
|
55
|
-
|
|
56
|
-
${domSnapshot ? `<dom_snapshot>
|
|
57
|
-
${domSnapshot}
|
|
58
|
-
</dom_snapshot>` : ""}`;
|
|
59
|
-
const result = await llmClient.generateObjectFromMessages({
|
|
60
|
-
schema: detectSubmissionErrorSchema,
|
|
61
|
-
messages: [
|
|
62
|
-
{
|
|
63
|
-
role: "user",
|
|
64
|
-
content: [
|
|
65
|
-
{ type: "text", text: prompt },
|
|
66
|
-
{ type: "image", image: `data:image/png;base64,${screenshot}` }
|
|
67
|
-
]
|
|
68
|
-
}
|
|
69
|
-
],
|
|
70
|
-
temperature: 0
|
|
71
|
-
});
|
|
72
|
-
if (!result.hasError) {
|
|
73
|
-
log.info("No error detected by LLM", { result });
|
|
74
|
-
}
|
|
75
|
-
if (result.matchedKnownErrorId) {
|
|
76
|
-
const knownError = knownErrors.find(
|
|
77
|
-
(e) => e.id === result.matchedKnownErrorId
|
|
78
|
-
);
|
|
79
|
-
if (knownError) {
|
|
80
|
-
log.warn(logContext, {
|
|
81
|
-
error,
|
|
82
|
-
browserError: result.errorMessage,
|
|
83
|
-
knownErrorId: result.matchedKnownErrorId
|
|
84
|
-
});
|
|
85
|
-
return {
|
|
86
|
-
matched: true,
|
|
87
|
-
errorId: knownError.id,
|
|
88
|
-
message: knownError.userMessage
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
log.warn(logContext, {
|
|
93
|
-
error,
|
|
94
|
-
browserError: result.errorMessage
|
|
95
|
-
});
|
|
96
|
-
throw error;
|
|
97
|
-
}
|
|
98
|
-
export {
|
|
99
|
-
detectSubmissionError
|
|
100
|
-
};
|
|
@@ -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,7 +0,0 @@
|
|
|
1
|
-
export { executeRecoveryAgent } from './agent.js';
|
|
2
|
-
export { attemptWithRecovery } from './recovery.js';
|
|
3
|
-
export { DetectedSubmissionError, KnownSubmissionError, detectSubmissionError } from './errors.js';
|
|
4
|
-
import 'playwright';
|
|
5
|
-
import '../../shared/logger/logger.js';
|
|
6
|
-
import '../../shared/llm/types.js';
|
|
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,12 +0,0 @@
|
|
|
1
|
-
import { Page } from 'playwright';
|
|
2
|
-
import { MinimalLogger } from '../../shared/logger/logger.js';
|
|
3
|
-
import { LLMClient } from '../../shared/llm/types.js';
|
|
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,31 +0,0 @@
|
|
|
1
|
-
import { defaultLogger } from "../../shared/logger/logger.js";
|
|
2
|
-
import { executeRecoveryAgent } from "./agent.js";
|
|
3
|
-
async function attemptWithRecovery(page, fn, logger, llmClient) {
|
|
4
|
-
const log = logger ?? defaultLogger;
|
|
5
|
-
try {
|
|
6
|
-
return await fn();
|
|
7
|
-
} catch (error) {
|
|
8
|
-
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"))) {
|
|
9
|
-
log.warn("Page/browser has been closed, cannot recover", {
|
|
10
|
-
error: error.message
|
|
11
|
-
});
|
|
12
|
-
throw error;
|
|
13
|
-
}
|
|
14
|
-
if (!llmClient) {
|
|
15
|
-
throw error;
|
|
16
|
-
}
|
|
17
|
-
log.info("Action failed, attempting popup recovery", {
|
|
18
|
-
error: error instanceof Error ? error.message : String(error)
|
|
19
|
-
});
|
|
20
|
-
await executeRecoveryAgent(
|
|
21
|
-
page,
|
|
22
|
-
"Look at the page to see if there is a popup blocking the screen. If so, close the popup.",
|
|
23
|
-
log,
|
|
24
|
-
llmClient
|
|
25
|
-
);
|
|
26
|
-
return await fn();
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
export {
|
|
30
|
-
attemptWithRecovery
|
|
31
|
-
};
|