@runflow-ai/sdk 1.0.99 → 1.0.200
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/dist/core/api-client.d.ts.map +1 -1
- package/dist/core/api-client.js +0 -2
- package/dist/core/api-client.js.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +15 -2
- package/dist/index.js.map +1 -1
- package/dist/observability/trace-collector.d.ts.map +1 -1
- package/dist/observability/trace-collector.js +5 -2
- package/dist/observability/trace-collector.js.map +1 -1
- package/dist/rpa/actions.d.ts +58 -0
- package/dist/rpa/actions.d.ts.map +1 -0
- package/dist/rpa/actions.js +214 -0
- package/dist/rpa/actions.js.map +1 -0
- package/dist/rpa/browser-session.d.ts +70 -0
- package/dist/rpa/browser-session.d.ts.map +1 -0
- package/dist/rpa/browser-session.js +213 -0
- package/dist/rpa/browser-session.js.map +1 -0
- package/dist/rpa/browser-tool.d.ts +20 -0
- package/dist/rpa/browser-tool.d.ts.map +1 -0
- package/dist/rpa/browser-tool.js +116 -0
- package/dist/rpa/browser-tool.js.map +1 -0
- package/dist/rpa/index.d.ts +7 -0
- package/dist/rpa/index.d.ts.map +1 -0
- package/dist/rpa/index.js +21 -0
- package/dist/rpa/index.js.map +1 -0
- package/dist/types/all-types.d.ts +10 -0
- package/dist/types/all-types.d.ts.map +1 -1
- package/package.json +16 -2
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// ============================================================================
|
|
3
|
+
// RPA ACTIONS - High-level helpers for common browser automation patterns
|
|
4
|
+
// ============================================================================
|
|
5
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
8
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
9
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
10
|
+
}
|
|
11
|
+
Object.defineProperty(o, k2, desc);
|
|
12
|
+
}) : (function(o, m, k, k2) {
|
|
13
|
+
if (k2 === undefined) k2 = k;
|
|
14
|
+
o[k2] = m[k];
|
|
15
|
+
}));
|
|
16
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
17
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
18
|
+
}) : function(o, v) {
|
|
19
|
+
o["default"] = v;
|
|
20
|
+
});
|
|
21
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
22
|
+
var ownKeys = function(o) {
|
|
23
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
24
|
+
var ar = [];
|
|
25
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
26
|
+
return ar;
|
|
27
|
+
};
|
|
28
|
+
return ownKeys(o);
|
|
29
|
+
};
|
|
30
|
+
return function (mod) {
|
|
31
|
+
if (mod && mod.__esModule) return mod;
|
|
32
|
+
var result = {};
|
|
33
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
34
|
+
__setModuleDefault(result, mod);
|
|
35
|
+
return result;
|
|
36
|
+
};
|
|
37
|
+
})();
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.login = login;
|
|
40
|
+
exports.fillForm = fillForm;
|
|
41
|
+
exports.clickButton = clickButton;
|
|
42
|
+
exports.waitAndClick = waitAndClick;
|
|
43
|
+
exports.extractTable = extractTable;
|
|
44
|
+
exports.extractText = extractText;
|
|
45
|
+
exports.downloadFile = downloadFile;
|
|
46
|
+
exports.screenshotPage = screenshotPage;
|
|
47
|
+
exports.waitForResponse = waitForResponse;
|
|
48
|
+
/**
|
|
49
|
+
* Fill a login form and submit.
|
|
50
|
+
* Supports custom selectors or defaults to common patterns.
|
|
51
|
+
*/
|
|
52
|
+
async function login(page, config) {
|
|
53
|
+
await page.goto(config.url, { waitUntil: 'domcontentloaded' });
|
|
54
|
+
if (config.usernameSelector) {
|
|
55
|
+
await page.locator(config.usernameSelector).fill(config.username);
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
await page.getByRole('textbox').first().fill(config.username);
|
|
59
|
+
}
|
|
60
|
+
if (config.passwordSelector) {
|
|
61
|
+
await page.locator(config.passwordSelector).fill(config.password);
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
const textboxes = page.getByRole('textbox');
|
|
65
|
+
const count = await textboxes.count();
|
|
66
|
+
if (count >= 2) {
|
|
67
|
+
await textboxes.nth(1).fill(config.password);
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
await page.locator('input[type="password"]').fill(config.password);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
if (config.submitSelector) {
|
|
74
|
+
await page.locator(config.submitSelector).click();
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
const loginButton = page.getByRole('button', { name: /login|entrar|sign.?in|acessar/i });
|
|
78
|
+
await loginButton.click();
|
|
79
|
+
}
|
|
80
|
+
if (config.waitAfterLogin) {
|
|
81
|
+
const timeout = config.timeout ?? 30000;
|
|
82
|
+
if (config.waitAfterLogin instanceof RegExp) {
|
|
83
|
+
await page.waitForURL(config.waitAfterLogin, { timeout });
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
await page.waitForURL(config.waitAfterLogin, { timeout });
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Fill multiple form fields using flexible selectors.
|
|
92
|
+
*/
|
|
93
|
+
async function fillForm(page, fields) {
|
|
94
|
+
for (const field of fields) {
|
|
95
|
+
const locator = resolveLocator(page, field);
|
|
96
|
+
switch (field.type ?? 'fill') {
|
|
97
|
+
case 'fill':
|
|
98
|
+
await locator.fill(field.value);
|
|
99
|
+
break;
|
|
100
|
+
case 'select':
|
|
101
|
+
await locator.selectOption(field.value);
|
|
102
|
+
break;
|
|
103
|
+
case 'check':
|
|
104
|
+
await locator.check();
|
|
105
|
+
break;
|
|
106
|
+
case 'uncheck':
|
|
107
|
+
await locator.uncheck();
|
|
108
|
+
break;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Click a button by its accessible label.
|
|
114
|
+
*/
|
|
115
|
+
async function clickButton(page, label) {
|
|
116
|
+
await page.getByRole('button', { name: new RegExp(label, 'i') }).click();
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Wait for a selector to appear and then click it.
|
|
120
|
+
*/
|
|
121
|
+
async function waitAndClick(page, selector, timeout) {
|
|
122
|
+
await page.waitForSelector(selector, { timeout: timeout ?? 30000 });
|
|
123
|
+
await page.locator(selector).click();
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Extract an HTML table into an array of key-value objects.
|
|
127
|
+
* Keys are taken from <th> cells; values from <td> cells.
|
|
128
|
+
*/
|
|
129
|
+
async function extractTable(page, selector) {
|
|
130
|
+
return page.evaluate((sel) => {
|
|
131
|
+
const table = document.querySelector(sel);
|
|
132
|
+
if (!table)
|
|
133
|
+
return [];
|
|
134
|
+
const headers = [];
|
|
135
|
+
table.querySelectorAll('thead th, tr:first-child th').forEach((th) => {
|
|
136
|
+
headers.push(th.textContent?.trim() ?? '');
|
|
137
|
+
});
|
|
138
|
+
const rows = [];
|
|
139
|
+
const bodyRows = table.querySelectorAll('tbody tr, tr:not(:first-child)');
|
|
140
|
+
bodyRows.forEach((tr) => {
|
|
141
|
+
const cells = tr.querySelectorAll('td');
|
|
142
|
+
if (cells.length === 0)
|
|
143
|
+
return;
|
|
144
|
+
const row = {};
|
|
145
|
+
cells.forEach((td, i) => {
|
|
146
|
+
const key = headers[i] || `col_${i}`;
|
|
147
|
+
row[key] = td.textContent?.trim() ?? '';
|
|
148
|
+
});
|
|
149
|
+
rows.push(row);
|
|
150
|
+
});
|
|
151
|
+
return rows;
|
|
152
|
+
}, selector);
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Extract text content from matched elements.
|
|
156
|
+
*/
|
|
157
|
+
async function extractText(page, selector) {
|
|
158
|
+
return page.evaluate((sel) => {
|
|
159
|
+
const elements = document.querySelectorAll(sel);
|
|
160
|
+
return Array.from(elements).map((el) => el.textContent?.trim() ?? '');
|
|
161
|
+
}, selector);
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Trigger a download by clicking an element, and wait for the download to complete.
|
|
165
|
+
* Returns the downloaded file path.
|
|
166
|
+
*/
|
|
167
|
+
async function downloadFile(page, triggerSelector, downloadDir) {
|
|
168
|
+
const fs = await Promise.resolve().then(() => __importStar(require('fs')));
|
|
169
|
+
fs.mkdirSync(downloadDir, { recursive: true });
|
|
170
|
+
const [download] = await Promise.all([
|
|
171
|
+
page.waitForEvent('download'),
|
|
172
|
+
page.locator(triggerSelector).click(),
|
|
173
|
+
]);
|
|
174
|
+
const filePath = `${downloadDir}/${download.suggestedFilename()}`;
|
|
175
|
+
await download.saveAs(filePath);
|
|
176
|
+
return filePath;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Take a full-page screenshot and return the file path.
|
|
180
|
+
*/
|
|
181
|
+
async function screenshotPage(page, outputPath) {
|
|
182
|
+
const fs = await Promise.resolve().then(() => __importStar(require('fs')));
|
|
183
|
+
const path = await Promise.resolve().then(() => __importStar(require('path')));
|
|
184
|
+
fs.mkdirSync(path.dirname(outputPath), { recursive: true });
|
|
185
|
+
await page.screenshot({ path: outputPath, fullPage: true });
|
|
186
|
+
return outputPath;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Wait for a network response matching a URL pattern.
|
|
190
|
+
*/
|
|
191
|
+
async function waitForResponse(page, urlPattern, timeout) {
|
|
192
|
+
return page.waitForResponse((response) => {
|
|
193
|
+
const url = response.url();
|
|
194
|
+
return urlPattern instanceof RegExp ? urlPattern.test(url) : url.includes(urlPattern);
|
|
195
|
+
}, { timeout: timeout ?? 30000 });
|
|
196
|
+
}
|
|
197
|
+
function resolveLocator(page, field) {
|
|
198
|
+
if (field.selector) {
|
|
199
|
+
return page.locator(field.selector);
|
|
200
|
+
}
|
|
201
|
+
if (field.role && field.label) {
|
|
202
|
+
const locator = page.getByRole(field.role, { name: new RegExp(field.label, 'i') });
|
|
203
|
+
return field.nth !== undefined ? locator.nth(field.nth) : locator;
|
|
204
|
+
}
|
|
205
|
+
if (field.role) {
|
|
206
|
+
const locator = page.getByRole(field.role);
|
|
207
|
+
return field.nth !== undefined ? locator.nth(field.nth) : locator;
|
|
208
|
+
}
|
|
209
|
+
if (field.label) {
|
|
210
|
+
return page.getByLabel(new RegExp(field.label, 'i'));
|
|
211
|
+
}
|
|
212
|
+
throw new Error(`FormField must have at least one of: selector, role, or label`);
|
|
213
|
+
}
|
|
214
|
+
//# sourceMappingURL=actions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"actions.js","sourceRoot":"","sources":["../../src/rpa/actions.ts"],"names":[],"mappings":";AAAA,+EAA+E;AAC/E,0EAA0E;AAC1E,+EAA+E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0B/E,sBAqCC;AAKD,4BAkBC;AAKD,kCAEC;AAKD,oCAOC;AAMD,oCA4BC;AAKD,kCAQC;AAMD,oCAgBC;AAKD,wCASC;AAKD,0CAYC;AAvLD;;;GAGG;AACI,KAAK,UAAU,KAAK,CAAC,IAAS,EAAE,MAAmB;IACxD,MAAM,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,EAAE,SAAS,EAAE,kBAAkB,EAAE,CAAC,CAAC;IAE/D,IAAI,MAAM,CAAC,gBAAgB,EAAE,CAAC;QAC5B,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC,IA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AI,KAAK,CAAC,IAAI,EAAE,CAAC;QACf,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAC3C,OAAO,KAAK,CAAC,GAAG,KAAK,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;IACpE,CAAC;IACD,IAAI,KAAK,CAAC,KAAK,EAAE,CAAC;QAChB,OAAO,IAAI,CAAC,UAAU,CAAC,IAAI,MAAM,CAAC,KAAK,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,CAAC;IACvD,CAAC;IACD,MAAM,IAAI,KAAK,CAAC,+DAA+D,CAAC,CAAC;AACnF,CAAC"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
export interface BrowserSessionConfig {
|
|
2
|
+
headless?: boolean;
|
|
3
|
+
viewport?: {
|
|
4
|
+
width: number;
|
|
5
|
+
height: number;
|
|
6
|
+
};
|
|
7
|
+
timeout?: number;
|
|
8
|
+
acceptDownloads?: boolean;
|
|
9
|
+
slowMo?: number;
|
|
10
|
+
screenshotsDir?: string;
|
|
11
|
+
userAgent?: string;
|
|
12
|
+
locale?: string;
|
|
13
|
+
timezoneId?: string;
|
|
14
|
+
extraHTTPHeaders?: Record<string, string>;
|
|
15
|
+
}
|
|
16
|
+
export interface BrowserSessionArtifact {
|
|
17
|
+
type: 'screenshot' | 'download' | 'pdf';
|
|
18
|
+
name: string;
|
|
19
|
+
path: string;
|
|
20
|
+
timestamp: number;
|
|
21
|
+
}
|
|
22
|
+
export interface BrowserActionSpan {
|
|
23
|
+
action: string;
|
|
24
|
+
selector?: string;
|
|
25
|
+
url?: string;
|
|
26
|
+
startedAt: number;
|
|
27
|
+
completedAt?: number;
|
|
28
|
+
durationMs?: number;
|
|
29
|
+
error?: string;
|
|
30
|
+
}
|
|
31
|
+
export declare class BrowserSession {
|
|
32
|
+
private browser;
|
|
33
|
+
private context;
|
|
34
|
+
private _page;
|
|
35
|
+
private _config;
|
|
36
|
+
private _artifacts;
|
|
37
|
+
private _actionSpans;
|
|
38
|
+
private _launched;
|
|
39
|
+
constructor(config?: BrowserSessionConfig);
|
|
40
|
+
get page(): any;
|
|
41
|
+
get artifacts(): BrowserSessionArtifact[];
|
|
42
|
+
get isLaunched(): boolean;
|
|
43
|
+
get actionSpans(): BrowserActionSpan[];
|
|
44
|
+
/**
|
|
45
|
+
* Record a traced browser action. Use this to wrap any significant
|
|
46
|
+
* browser operation so it appears in observability traces.
|
|
47
|
+
*/
|
|
48
|
+
traced<T>(action: string, fn: () => Promise<T>, meta?: {
|
|
49
|
+
selector?: string;
|
|
50
|
+
url?: string;
|
|
51
|
+
}): Promise<T>;
|
|
52
|
+
/**
|
|
53
|
+
* Get a summary of all traced actions for inclusion in execution traces.
|
|
54
|
+
*/
|
|
55
|
+
getTraceSummary(): {
|
|
56
|
+
totalActions: number;
|
|
57
|
+
totalDurationMs: number;
|
|
58
|
+
actions: BrowserActionSpan[];
|
|
59
|
+
artifacts: BrowserSessionArtifact[];
|
|
60
|
+
errors: string[];
|
|
61
|
+
};
|
|
62
|
+
launch(configOverride?: BrowserSessionConfig): Promise<any>;
|
|
63
|
+
screenshot(name: string): Promise<string>;
|
|
64
|
+
waitForNavigation(urlPattern: RegExp, timeout?: number): Promise<void>;
|
|
65
|
+
waitForSelector(selector: string, timeout?: number): Promise<any>;
|
|
66
|
+
getContent(): Promise<string>;
|
|
67
|
+
newPage(): Promise<any>;
|
|
68
|
+
close(): Promise<void>;
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=browser-session.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser-session.d.ts","sourceRoot":"","sources":["../../src/rpa/browser-session.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE;QAA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ED,IAAI,WAAW,IAAI,iBAAiB,EAAE,CAErC;IAED;;;OAGG;IACG,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE;QAAE,QAAQ,CAAC,EAAE,MAAM,CAAC;QAAC,GAAG,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,CAAC,CAAC;IAuB7G;;OAEG;IACH,eAAe,IAAI;QACjB,YAAY,EAAE,MAAM,CAAC;QACrB,eAAe,EAAE,MAAM,CAAC;QACxB,OAAO,EAAE,iBAAiB,EAAE,CAAC;QAC7B,SAAS,EAAE,sBAAsB,EAAE,CAAC;QACpC,MAAM,EAAE,MAAM,EAAE,CAAC;KAClB;IAcK,MAAM,CAAC,cAAc,CAAC,EAAE,oBAAoB,GAAG,OAAO,CAAC,GAAG,CAAC;IAwC3D,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IA0BzC,iBAAiB,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAStE,eAAe,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC;IASjE,UAAU,IAAI,OAAO,CAAC,MAAM,CAAC;IAO7B,OAAO,IAAI,OAAO,CAAC,GAAG,CAAC;IAOvB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAgB7B"}
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// ============================================================================
|
|
3
|
+
// BROWSER SESSION - Managed Playwright browser lifecycle
|
|
4
|
+
// ============================================================================
|
|
5
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
8
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
9
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
10
|
+
}
|
|
11
|
+
Object.defineProperty(o, k2, desc);
|
|
12
|
+
}) : (function(o, m, k, k2) {
|
|
13
|
+
if (k2 === undefined) k2 = k;
|
|
14
|
+
o[k2] = m[k];
|
|
15
|
+
}));
|
|
16
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
17
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
18
|
+
}) : function(o, v) {
|
|
19
|
+
o["default"] = v;
|
|
20
|
+
});
|
|
21
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
22
|
+
var ownKeys = function(o) {
|
|
23
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
24
|
+
var ar = [];
|
|
25
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
26
|
+
return ar;
|
|
27
|
+
};
|
|
28
|
+
return ownKeys(o);
|
|
29
|
+
};
|
|
30
|
+
return function (mod) {
|
|
31
|
+
if (mod && mod.__esModule) return mod;
|
|
32
|
+
var result = {};
|
|
33
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
34
|
+
__setModuleDefault(result, mod);
|
|
35
|
+
return result;
|
|
36
|
+
};
|
|
37
|
+
})();
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.BrowserSession = void 0;
|
|
40
|
+
const DEFAULT_CONFIG = {
|
|
41
|
+
headless: true,
|
|
42
|
+
viewport: { width: 1440, height: 900 },
|
|
43
|
+
timeout: 30000,
|
|
44
|
+
acceptDownloads: true,
|
|
45
|
+
};
|
|
46
|
+
class BrowserSession {
|
|
47
|
+
constructor(config) {
|
|
48
|
+
this.browser = null;
|
|
49
|
+
this.context = null;
|
|
50
|
+
this._page = null;
|
|
51
|
+
this._artifacts = [];
|
|
52
|
+
this._actionSpans = [];
|
|
53
|
+
this._launched = false;
|
|
54
|
+
this._config = { ...DEFAULT_CONFIG, ...config };
|
|
55
|
+
}
|
|
56
|
+
get page() {
|
|
57
|
+
if (!this._page) {
|
|
58
|
+
throw new Error('BrowserSession not launched. Call launch() first.');
|
|
59
|
+
}
|
|
60
|
+
return this._page;
|
|
61
|
+
}
|
|
62
|
+
get artifacts() {
|
|
63
|
+
return [...this._artifacts];
|
|
64
|
+
}
|
|
65
|
+
get isLaunched() {
|
|
66
|
+
return this._launched;
|
|
67
|
+
}
|
|
68
|
+
get actionSpans() {
|
|
69
|
+
return [...this._actionSpans];
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Record a traced browser action. Use this to wrap any significant
|
|
73
|
+
* browser operation so it appears in observability traces.
|
|
74
|
+
*/
|
|
75
|
+
async traced(action, fn, meta) {
|
|
76
|
+
const span = {
|
|
77
|
+
action,
|
|
78
|
+
selector: meta?.selector,
|
|
79
|
+
url: meta?.url,
|
|
80
|
+
startedAt: Date.now(),
|
|
81
|
+
};
|
|
82
|
+
try {
|
|
83
|
+
const result = await fn();
|
|
84
|
+
span.completedAt = Date.now();
|
|
85
|
+
span.durationMs = span.completedAt - span.startedAt;
|
|
86
|
+
this._actionSpans.push(span);
|
|
87
|
+
return result;
|
|
88
|
+
}
|
|
89
|
+
catch (error) {
|
|
90
|
+
span.completedAt = Date.now();
|
|
91
|
+
span.durationMs = span.completedAt - span.startedAt;
|
|
92
|
+
span.error = error instanceof Error ? error.message : String(error);
|
|
93
|
+
this._actionSpans.push(span);
|
|
94
|
+
throw error;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Get a summary of all traced actions for inclusion in execution traces.
|
|
99
|
+
*/
|
|
100
|
+
getTraceSummary() {
|
|
101
|
+
const errors = this._actionSpans
|
|
102
|
+
.filter(s => s.error)
|
|
103
|
+
.map(s => `${s.action}: ${s.error}`);
|
|
104
|
+
return {
|
|
105
|
+
totalActions: this._actionSpans.length,
|
|
106
|
+
totalDurationMs: this._actionSpans.reduce((sum, s) => sum + (s.durationMs || 0), 0),
|
|
107
|
+
actions: this._actionSpans,
|
|
108
|
+
artifacts: this._artifacts,
|
|
109
|
+
errors,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
async launch(configOverride) {
|
|
113
|
+
if (this._launched) {
|
|
114
|
+
return this._page;
|
|
115
|
+
}
|
|
116
|
+
const config = { ...this._config, ...configOverride };
|
|
117
|
+
let playwright;
|
|
118
|
+
try {
|
|
119
|
+
playwright = await Promise.resolve().then(() => __importStar(require('playwright')));
|
|
120
|
+
}
|
|
121
|
+
catch {
|
|
122
|
+
throw new Error('Playwright is not installed. Install it with: npm install playwright && npx playwright install chromium');
|
|
123
|
+
}
|
|
124
|
+
this.browser = await playwright.chromium.launch({
|
|
125
|
+
headless: config.headless ?? DEFAULT_CONFIG.headless,
|
|
126
|
+
slowMo: config.slowMo,
|
|
127
|
+
});
|
|
128
|
+
const contextOptions = {
|
|
129
|
+
viewport: config.viewport ?? DEFAULT_CONFIG.viewport,
|
|
130
|
+
acceptDownloads: config.acceptDownloads ?? DEFAULT_CONFIG.acceptDownloads,
|
|
131
|
+
};
|
|
132
|
+
if (config.userAgent)
|
|
133
|
+
contextOptions.userAgent = config.userAgent;
|
|
134
|
+
if (config.locale)
|
|
135
|
+
contextOptions.locale = config.locale;
|
|
136
|
+
if (config.timezoneId)
|
|
137
|
+
contextOptions.timezoneId = config.timezoneId;
|
|
138
|
+
if (config.extraHTTPHeaders)
|
|
139
|
+
contextOptions.extraHTTPHeaders = config.extraHTTPHeaders;
|
|
140
|
+
this.context = await this.browser.newContext(contextOptions);
|
|
141
|
+
this.context.setDefaultTimeout(config.timeout ?? DEFAULT_CONFIG.timeout);
|
|
142
|
+
this._page = await this.context.newPage();
|
|
143
|
+
this._launched = true;
|
|
144
|
+
return this._page;
|
|
145
|
+
}
|
|
146
|
+
async screenshot(name) {
|
|
147
|
+
if (!this._page) {
|
|
148
|
+
throw new Error('BrowserSession not launched. Call launch() first.');
|
|
149
|
+
}
|
|
150
|
+
const fs = await Promise.resolve().then(() => __importStar(require('fs')));
|
|
151
|
+
const path = await Promise.resolve().then(() => __importStar(require('path')));
|
|
152
|
+
const dir = this._config.screenshotsDir || process.cwd();
|
|
153
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
154
|
+
const sanitizedName = name.replace(/[^a-zA-Z0-9_-]/g, '_');
|
|
155
|
+
const filePath = path.join(dir, `${sanitizedName}-${Date.now()}.png`);
|
|
156
|
+
await this._page.screenshot({ path: filePath, fullPage: true });
|
|
157
|
+
this._artifacts.push({
|
|
158
|
+
type: 'screenshot',
|
|
159
|
+
name,
|
|
160
|
+
path: filePath,
|
|
161
|
+
timestamp: Date.now(),
|
|
162
|
+
});
|
|
163
|
+
return filePath;
|
|
164
|
+
}
|
|
165
|
+
async waitForNavigation(urlPattern, timeout) {
|
|
166
|
+
if (!this._page) {
|
|
167
|
+
throw new Error('BrowserSession not launched. Call launch() first.');
|
|
168
|
+
}
|
|
169
|
+
await this._page.waitForURL(urlPattern, {
|
|
170
|
+
timeout: timeout ?? this._config.timeout ?? DEFAULT_CONFIG.timeout,
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
async waitForSelector(selector, timeout) {
|
|
174
|
+
if (!this._page) {
|
|
175
|
+
throw new Error('BrowserSession not launched. Call launch() first.');
|
|
176
|
+
}
|
|
177
|
+
return this._page.waitForSelector(selector, {
|
|
178
|
+
timeout: timeout ?? this._config.timeout ?? DEFAULT_CONFIG.timeout,
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
async getContent() {
|
|
182
|
+
if (!this._page) {
|
|
183
|
+
throw new Error('BrowserSession not launched. Call launch() first.');
|
|
184
|
+
}
|
|
185
|
+
return this._page.content();
|
|
186
|
+
}
|
|
187
|
+
async newPage() {
|
|
188
|
+
if (!this.context) {
|
|
189
|
+
throw new Error('BrowserSession not launched. Call launch() first.');
|
|
190
|
+
}
|
|
191
|
+
return this.context.newPage();
|
|
192
|
+
}
|
|
193
|
+
async close() {
|
|
194
|
+
if (this.context) {
|
|
195
|
+
try {
|
|
196
|
+
await this.context.close();
|
|
197
|
+
}
|
|
198
|
+
catch { /* ignore close errors */ }
|
|
199
|
+
this.context = null;
|
|
200
|
+
}
|
|
201
|
+
if (this.browser) {
|
|
202
|
+
try {
|
|
203
|
+
await this.browser.close();
|
|
204
|
+
}
|
|
205
|
+
catch { /* ignore close errors */ }
|
|
206
|
+
this.browser = null;
|
|
207
|
+
}
|
|
208
|
+
this._page = null;
|
|
209
|
+
this._launched = false;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
exports.BrowserSession = BrowserSession;
|
|
213
|
+
//# sourceMappingURL=browser-session.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser-session.js","sourceRoot":"","sources":["../../src/rpa/browser-session.ts"],"names":[],"mappings":";AAAA,+EAA+E;AAC/E,yDAAyD;AACzD,+EAA+E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsB/E,MAAM,cAAc,GAAkG;IACpH,QAAQ,EAAE,IAAI;IACd,QAAQ,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE;IACtC,OAAO,EAAE,KAAM;IACf,eAAe,EAAE,IAAI;CACtB,CAAC;AAYF,MAAa,cAAc;IASzB,YAAY,MAA6B;QARjC,YAAO,GAAe,IAAI,CAAC;QAC3B,YAAO,GAAe,IAAI,CAAC;QAC3B,UAAK,GAAe,IAAI,CAAC;QAEzB,eAAU,GAA6B,EAAE,CAAC;QAC1C,iBAAY,GAAwB,EAAE,CAAC;QACvC,cAAS,GAAG,KAAK,CAAC;QAGxB,IAAI,CAAC,OAAO,GAAG,EAAE,GAAG,cAAc,EAAE,GAAG,MAAM,E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O,IAAI,IAAI,CAAC,OAAO,CAAC,OAAO,IAAI,cAAc,CAAC,OAAO;SACnE,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,UAAU;QACd,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;YAChB,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC;QACvE,CAAC;QACD,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC;IAC9B,CAAC;IAED,KAAK,CAAC,OAAO;QACX,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;YAClB,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC;QACvE,CAAC;QACD,OAAO,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;IAChC,CAAC;IAED,KAAK,CAAC,KAAK;QACT,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YACjB,IAAI,CAAC;gBACH,MAAM,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;YAC7B,CAAC;YAAC,MAAM,CAAC,CAAC,yBAAyB,CAAC,CAAC;YACrC,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;QACtB,CAAC;QACD,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YACjB,IAAI,CAAC;gBACH,MAAM,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;YAC7B,CAAC;YAAC,MAAM,CAAC,CAAC,yBAAyB,CAAC,CAAC;YACrC,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;QACtB,CAAC;QACD,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QAClB,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC;IACzB,CAAC;CACF;AApMD,wCAoMC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { RunflowTool } from '../types';
|
|
3
|
+
import { BrowserSession, BrowserSessionConfig } from './browser-session';
|
|
4
|
+
export interface BrowserToolConfig<TInput = any, TOutput = any> {
|
|
5
|
+
id: string;
|
|
6
|
+
description: string;
|
|
7
|
+
inputSchema: z.ZodSchema<TInput>;
|
|
8
|
+
outputSchema?: z.ZodSchema<TOutput>;
|
|
9
|
+
browser?: BrowserSessionConfig;
|
|
10
|
+
execute: (params: {
|
|
11
|
+
context: TInput;
|
|
12
|
+
browser: BrowserSession;
|
|
13
|
+
projectId: string;
|
|
14
|
+
companyId: string;
|
|
15
|
+
userId?: string;
|
|
16
|
+
sessionId?: string;
|
|
17
|
+
}) => Promise<TOutput>;
|
|
18
|
+
}
|
|
19
|
+
export declare function createBrowserTool<TInput = any, TOutput = any>(config: BrowserToolConfig<TInput, TOutput>): RunflowTool;
|
|
20
|
+
//# sourceMappingURL=browser-tool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser-tool.d.ts","sourceRoot":"","sources":["../../src/rpa/browser-tool.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,WAAW,EAAiB,MAAM,UAAU,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAEzE,MAAM,WAAW,iBAAiB,CAAC,MAAM,GAAG,GAAG,EAAE,OAAO,GAAG,GAAG;IAC5D,EAAE,EAAE,MAAM,CAAC;IACX,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,CAAC,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;IACjC,YAAY,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;IACpC,OAAO,CAAC,EAAE,oBAAoB,CAAC;IAC/B,OAAO,EAAE,CAAC,MAAM,EAAE;QAChB,OAAO,EAAE,MAAM,CAAC;QAChB,OAAO,EAAE,cAAc,CAAC;QACxB,SAAS,EAAE,MAAM,CAAC;QAClB,SAAS,EAAE,MAAM,CAAC;QAClB,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;CACxB;AAED,wBAAgB,iBAAiB,CAAC,MAAM,GAAG,GAAG,EAAE,OAAO,GAAG,GAAG,EAC3D,MAAM,EAAE,iBAAiB,CAAC,MAAM,EAAE,OAAO,CAAC,GACzC,WAAW,CAyDb"}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// ============================================================================
|
|
3
|
+
// BROWSER TOOL - Factory for creating RPA tools with managed browser lifecycle
|
|
4
|
+
// ============================================================================
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.createBrowserTool = createBrowserTool;
|
|
7
|
+
const zod_1 = require("zod");
|
|
8
|
+
const browser_session_1 = require("./browser-session");
|
|
9
|
+
function createBrowserTool(config) {
|
|
10
|
+
const tool = {
|
|
11
|
+
id: config.id,
|
|
12
|
+
name: config.id,
|
|
13
|
+
description: config.description,
|
|
14
|
+
parameters: zodToParameters(config.inputSchema),
|
|
15
|
+
_isBrowserTool: true,
|
|
16
|
+
execute: async (params, context) => {
|
|
17
|
+
const validatedInput = config.inputSchema.parse(params);
|
|
18
|
+
const session = new browser_session_1.BrowserSession(config.browser);
|
|
19
|
+
try {
|
|
20
|
+
await session.launch();
|
|
21
|
+
const result = await config.execute({
|
|
22
|
+
context: validatedInput,
|
|
23
|
+
browser: session,
|
|
24
|
+
projectId: context.projectId,
|
|
25
|
+
companyId: context.companyId,
|
|
26
|
+
userId: context.userId,
|
|
27
|
+
sessionId: context.sessionId,
|
|
28
|
+
});
|
|
29
|
+
const output = config.outputSchema ? config.outputSchema.parse(result) : result;
|
|
30
|
+
// Attach RPA trace summary to the output for observability
|
|
31
|
+
const traceSummary = session.getTraceSummary();
|
|
32
|
+
if (typeof output === 'object' && output !== null) {
|
|
33
|
+
output._rpaTrace = {
|
|
34
|
+
rpaUsed: true,
|
|
35
|
+
...traceSummary,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
return output;
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
// Auto-screenshot on error when a screenshots dir is configured
|
|
42
|
+
if (config.browser?.screenshotsDir && session.isLaunched) {
|
|
43
|
+
try {
|
|
44
|
+
await session.screenshot('error-capture');
|
|
45
|
+
}
|
|
46
|
+
catch { /* best-effort error screenshot */ }
|
|
47
|
+
}
|
|
48
|
+
// Attach trace summary to error for debugging
|
|
49
|
+
if (error instanceof Error) {
|
|
50
|
+
error._rpaTrace = session.getTraceSummary();
|
|
51
|
+
}
|
|
52
|
+
throw error;
|
|
53
|
+
}
|
|
54
|
+
finally {
|
|
55
|
+
await session.close();
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
return tool;
|
|
60
|
+
}
|
|
61
|
+
// ============================================================================
|
|
62
|
+
// ZOD TO PARAMETERS (reused from tool-creator pattern)
|
|
63
|
+
// ============================================================================
|
|
64
|
+
function zodToParameters(schema) {
|
|
65
|
+
if (schema instanceof zod_1.z.ZodObject) {
|
|
66
|
+
const shape = schema.shape;
|
|
67
|
+
const parameters = {};
|
|
68
|
+
for (const [key, fieldSchema] of Object.entries(shape)) {
|
|
69
|
+
parameters[key] = zodFieldToParameter(fieldSchema);
|
|
70
|
+
}
|
|
71
|
+
return parameters;
|
|
72
|
+
}
|
|
73
|
+
if (schema._def && schema._def.typeName === 'ZodObject') {
|
|
74
|
+
const shape = schema.shape;
|
|
75
|
+
const parameters = {};
|
|
76
|
+
for (const [key, fieldSchema] of Object.entries(shape)) {
|
|
77
|
+
parameters[key] = zodFieldToParameter(fieldSchema);
|
|
78
|
+
}
|
|
79
|
+
return parameters;
|
|
80
|
+
}
|
|
81
|
+
return { input: zodFieldToParameter(schema) };
|
|
82
|
+
}
|
|
83
|
+
function zodFieldToParameter(schema) {
|
|
84
|
+
if (schema instanceof zod_1.z.ZodString) {
|
|
85
|
+
const param = { type: 'string', description: schema.description };
|
|
86
|
+
if ('_def' in schema && 'values' in schema._def) {
|
|
87
|
+
param.enum = schema._def.values;
|
|
88
|
+
}
|
|
89
|
+
return param;
|
|
90
|
+
}
|
|
91
|
+
if (schema instanceof zod_1.z.ZodEnum) {
|
|
92
|
+
return { type: 'string', description: schema.description, enum: schema._def.values };
|
|
93
|
+
}
|
|
94
|
+
if (schema instanceof zod_1.z.ZodNumber) {
|
|
95
|
+
return { type: 'number', description: schema.description };
|
|
96
|
+
}
|
|
97
|
+
if (schema instanceof zod_1.z.ZodBoolean) {
|
|
98
|
+
return { type: 'boolean', description: schema.description };
|
|
99
|
+
}
|
|
100
|
+
if (schema instanceof zod_1.z.ZodArray) {
|
|
101
|
+
return { type: 'array', description: schema.description };
|
|
102
|
+
}
|
|
103
|
+
if (schema instanceof zod_1.z.ZodObject) {
|
|
104
|
+
return { type: 'object', description: schema.description };
|
|
105
|
+
}
|
|
106
|
+
if (schema instanceof zod_1.z.ZodOptional) {
|
|
107
|
+
const param = zodFieldToParameter(schema._def.innerType);
|
|
108
|
+
param.required = false;
|
|
109
|
+
return param;
|
|
110
|
+
}
|
|
111
|
+
if (schema instanceof zod_1.z.ZodDefault) {
|
|
112
|
+
return zodFieldToParameter(schema._def.innerType);
|
|
113
|
+
}
|
|
114
|
+
return { type: 'string', description: schema.description || 'Parameter' };
|
|
115
|
+
}
|
|
116
|
+
//# sourceMappingURL=browser-tool.js.map
|