cdp-skill 1.0.8 → 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.
Files changed (47) hide show
  1. package/README.md +80 -35
  2. package/SKILL.md +151 -239
  3. package/install.js +1 -0
  4. package/package.json +1 -1
  5. package/src/aria/index.js +8 -0
  6. package/src/aria/output-processor.js +173 -0
  7. package/src/aria/role-query.js +1229 -0
  8. package/src/aria/snapshot.js +459 -0
  9. package/src/aria.js +237 -43
  10. package/src/cdp/browser.js +22 -4
  11. package/src/cdp-skill.js +245 -69
  12. package/src/dom/click-executor.js +240 -76
  13. package/src/dom/element-locator.js +34 -25
  14. package/src/dom/fill-executor.js +55 -27
  15. package/src/page/dialog-handler.js +119 -0
  16. package/src/page/page-controller.js +190 -3
  17. package/src/runner/context-helpers.js +33 -55
  18. package/src/runner/execute-dynamic.js +8 -7
  19. package/src/runner/execute-form.js +11 -11
  20. package/src/runner/execute-input.js +2 -2
  21. package/src/runner/execute-interaction.js +99 -120
  22. package/src/runner/execute-navigation.js +11 -26
  23. package/src/runner/execute-query.js +8 -5
  24. package/src/runner/step-executors.js +225 -84
  25. package/src/runner/step-registry.js +1064 -0
  26. package/src/runner/step-validator.js +16 -754
  27. package/src/tests/Aria.test.js +1025 -0
  28. package/src/tests/ContextHelpers.test.js +39 -28
  29. package/src/tests/ExecuteBrowser.test.js +572 -0
  30. package/src/tests/ExecuteDynamic.test.js +2 -457
  31. package/src/tests/ExecuteForm.test.js +700 -0
  32. package/src/tests/ExecuteInput.test.js +540 -0
  33. package/src/tests/ExecuteInteraction.test.js +319 -0
  34. package/src/tests/ExecuteQuery.test.js +820 -0
  35. package/src/tests/FillExecutor.test.js +2 -2
  36. package/src/tests/StepValidator.test.js +222 -76
  37. package/src/tests/TestRunner.test.js +36 -25
  38. package/src/tests/integration.test.js +2 -1
  39. package/src/types.js +9 -9
  40. package/src/utils/backoff.js +118 -0
  41. package/src/utils/cdp-helpers.js +130 -0
  42. package/src/utils/devices.js +140 -0
  43. package/src/utils/errors.js +242 -0
  44. package/src/utils/index.js +65 -0
  45. package/src/utils/temp.js +75 -0
  46. package/src/utils/validators.js +433 -0
  47. package/src/utils.js +14 -1142
@@ -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
+ }