cdp-skill 1.0.7 → 1.0.14
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/README.md +80 -35
- package/SKILL.md +198 -1344
- package/install.js +1 -0
- package/package.json +1 -1
- package/src/aria/index.js +8 -0
- package/src/aria/output-processor.js +173 -0
- package/src/aria/role-query.js +1229 -0
- package/src/aria/snapshot.js +459 -0
- package/src/aria.js +237 -43
- package/src/cdp/browser.js +22 -4
- package/src/cdp-skill.js +268 -68
- package/src/dom/click-executor.js +240 -76
- package/src/dom/element-locator.js +34 -25
- package/src/dom/fill-executor.js +55 -27
- package/src/page/dialog-handler.js +119 -0
- package/src/page/page-controller.js +190 -3
- package/src/runner/context-helpers.js +33 -55
- package/src/runner/execute-dynamic.js +34 -143
- package/src/runner/execute-form.js +11 -11
- package/src/runner/execute-input.js +2 -2
- package/src/runner/execute-interaction.js +99 -120
- package/src/runner/execute-navigation.js +11 -26
- package/src/runner/execute-query.js +8 -5
- package/src/runner/step-executors.js +256 -95
- package/src/runner/step-registry.js +1064 -0
- package/src/runner/step-validator.js +16 -740
- package/src/tests/Aria.test.js +1025 -0
- package/src/tests/ContextHelpers.test.js +39 -28
- package/src/tests/ExecuteBrowser.test.js +572 -0
- package/src/tests/ExecuteDynamic.test.js +34 -736
- package/src/tests/ExecuteForm.test.js +700 -0
- package/src/tests/ExecuteInput.test.js +540 -0
- package/src/tests/ExecuteInteraction.test.js +319 -0
- package/src/tests/ExecuteQuery.test.js +820 -0
- package/src/tests/FillExecutor.test.js +2 -2
- package/src/tests/StepValidator.test.js +222 -76
- package/src/tests/TestRunner.test.js +36 -25
- package/src/tests/integration.test.js +2 -1
- package/src/types.js +9 -9
- package/src/utils/backoff.js +118 -0
- package/src/utils/cdp-helpers.js +130 -0
- package/src/utils/devices.js +140 -0
- package/src/utils/errors.js +242 -0
- package/src/utils/index.js +65 -0
- package/src/utils/temp.js +75 -0
- package/src/utils/validators.js +433 -0
- package/src/utils.js +14 -1142
package/install.js
CHANGED
package/package.json
CHANGED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ARIA Module
|
|
3
|
+
* Re-exports accessibility tree and role-based query functionality
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export { createQueryOutputProcessor } from './output-processor.js';
|
|
7
|
+
export { createRoleQueryExecutor } from './role-query.js';
|
|
8
|
+
export { createAriaSnapshot } from './snapshot.js';
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ARIA - Accessibility tree generation and role-based queries for AI agents
|
|
3
|
+
*
|
|
4
|
+
* Consolidated module containing:
|
|
5
|
+
* - AriaSnapshot: Generates semantic tree representation based on ARIA roles
|
|
6
|
+
* - RoleQueryExecutor: Advanced role-based queries with filtering
|
|
7
|
+
* - QueryOutputProcessor: Output formatting and attribute extraction
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
// Query Output Processor (from QueryOutputProcessor.js)
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Create a query output processor for handling multiple output modes
|
|
14
|
+
* @param {Object} session - CDP session
|
|
15
|
+
* @returns {Object} Query output processor interface
|
|
16
|
+
*/
|
|
17
|
+
export function createQueryOutputProcessor(session) {
|
|
18
|
+
/**
|
|
19
|
+
* Get a single output value by mode
|
|
20
|
+
* @param {Object} elementHandle - Element handle
|
|
21
|
+
* @param {string} mode - Output mode
|
|
22
|
+
* @param {boolean} clean - Whether to trim whitespace
|
|
23
|
+
* @returns {Promise<string>}
|
|
24
|
+
*/
|
|
25
|
+
async function getSingleOutput(elementHandle, mode, clean) {
|
|
26
|
+
let value;
|
|
27
|
+
|
|
28
|
+
switch (mode) {
|
|
29
|
+
case 'text':
|
|
30
|
+
value = await elementHandle.evaluate(`function() {
|
|
31
|
+
return this.textContent ? this.textContent.substring(0, 100) : '';
|
|
32
|
+
}`);
|
|
33
|
+
break;
|
|
34
|
+
|
|
35
|
+
case 'html':
|
|
36
|
+
value = await elementHandle.evaluate(`function() {
|
|
37
|
+
return this.outerHTML ? this.outerHTML.substring(0, 200) : '';
|
|
38
|
+
}`);
|
|
39
|
+
break;
|
|
40
|
+
|
|
41
|
+
case 'href':
|
|
42
|
+
value = await elementHandle.evaluate(`function() {
|
|
43
|
+
return this.href || this.getAttribute('href') || '';
|
|
44
|
+
}`);
|
|
45
|
+
break;
|
|
46
|
+
|
|
47
|
+
case 'value':
|
|
48
|
+
value = await elementHandle.evaluate(`function() {
|
|
49
|
+
return this.value || '';
|
|
50
|
+
}`);
|
|
51
|
+
break;
|
|
52
|
+
|
|
53
|
+
case 'tag':
|
|
54
|
+
value = await elementHandle.evaluate(`function() {
|
|
55
|
+
return this.tagName ? this.tagName.toLowerCase() : '';
|
|
56
|
+
}`);
|
|
57
|
+
break;
|
|
58
|
+
|
|
59
|
+
default:
|
|
60
|
+
value = await elementHandle.evaluate(`function() {
|
|
61
|
+
return this.textContent ? this.textContent.substring(0, 100) : '';
|
|
62
|
+
}`);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Apply text cleanup
|
|
66
|
+
if (clean && typeof value === 'string') {
|
|
67
|
+
value = value.trim();
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return value || '';
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Get an attribute value from element
|
|
75
|
+
* @param {Object} elementHandle - Element handle
|
|
76
|
+
* @param {string} attributeName - Attribute name to retrieve
|
|
77
|
+
* @param {boolean} clean - Whether to trim whitespace
|
|
78
|
+
* @returns {Promise<string|null>}
|
|
79
|
+
*/
|
|
80
|
+
async function getAttribute(elementHandle, attributeName, clean) {
|
|
81
|
+
const value = await elementHandle.evaluate(`function() {
|
|
82
|
+
return this.getAttribute(${JSON.stringify(attributeName)});
|
|
83
|
+
}`);
|
|
84
|
+
|
|
85
|
+
if (clean && typeof value === 'string') {
|
|
86
|
+
return value.trim();
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return value;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Process output for an element based on output specification
|
|
94
|
+
* @param {Object} elementHandle - Element handle with evaluate method
|
|
95
|
+
* @param {string|string[]|Object} output - Output specification
|
|
96
|
+
* @param {Object} options - Additional options
|
|
97
|
+
* @param {boolean} options.clean - Whether to trim whitespace
|
|
98
|
+
* @returns {Promise<*>} Processed output value
|
|
99
|
+
*/
|
|
100
|
+
async function processOutput(elementHandle, output, options = {}) {
|
|
101
|
+
const clean = options.clean === true;
|
|
102
|
+
|
|
103
|
+
// Handle multiple output modes
|
|
104
|
+
if (Array.isArray(output)) {
|
|
105
|
+
const result = {};
|
|
106
|
+
for (const mode of output) {
|
|
107
|
+
result[mode] = await getSingleOutput(elementHandle, mode, clean);
|
|
108
|
+
}
|
|
109
|
+
return result;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// Handle attribute output
|
|
113
|
+
if (typeof output === 'object' && output !== null) {
|
|
114
|
+
if (output.attribute) {
|
|
115
|
+
return getAttribute(elementHandle, output.attribute, clean);
|
|
116
|
+
}
|
|
117
|
+
// Default to text if object doesn't specify attribute
|
|
118
|
+
return getSingleOutput(elementHandle, 'text', clean);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// Handle single output mode
|
|
122
|
+
return getSingleOutput(elementHandle, output || 'text', clean);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Get element metadata
|
|
127
|
+
* @param {Object} elementHandle - Element handle
|
|
128
|
+
* @returns {Promise<Object>} Element metadata
|
|
129
|
+
*/
|
|
130
|
+
async function getElementMetadata(elementHandle) {
|
|
131
|
+
return elementHandle.evaluate(`function() {
|
|
132
|
+
const el = this;
|
|
133
|
+
|
|
134
|
+
// Build selector path
|
|
135
|
+
const getSelectorPath = (element) => {
|
|
136
|
+
const path = [];
|
|
137
|
+
let current = element;
|
|
138
|
+
while (current && current !== document.body && path.length < 5) {
|
|
139
|
+
let selector = current.tagName.toLowerCase();
|
|
140
|
+
if (current.id) {
|
|
141
|
+
selector += '#' + current.id;
|
|
142
|
+
path.unshift(selector);
|
|
143
|
+
break; // ID is unique, stop here
|
|
144
|
+
}
|
|
145
|
+
if (current.className && typeof current.className === 'string') {
|
|
146
|
+
const classes = current.className.trim().split(/\\s+/).slice(0, 2);
|
|
147
|
+
if (classes.length > 0 && classes[0]) {
|
|
148
|
+
selector += '.' + classes.join('.');
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
path.unshift(selector);
|
|
152
|
+
current = current.parentElement;
|
|
153
|
+
}
|
|
154
|
+
return path.join(' > ');
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
return {
|
|
158
|
+
tag: el.tagName ? el.tagName.toLowerCase() : null,
|
|
159
|
+
classes: el.className && typeof el.className === 'string'
|
|
160
|
+
? el.className.trim().split(/\\s+/).filter(c => c)
|
|
161
|
+
: [],
|
|
162
|
+
selectorPath: getSelectorPath(el)
|
|
163
|
+
};
|
|
164
|
+
}`);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
return {
|
|
168
|
+
processOutput,
|
|
169
|
+
getSingleOutput,
|
|
170
|
+
getAttribute,
|
|
171
|
+
getElementMetadata
|
|
172
|
+
};
|
|
173
|
+
}
|