@aria-cli/tools 1.0.12 → 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 (233) hide show
  1. package/dist/index.js +378 -70
  2. package/dist/network-runtime/index.js +8 -12
  3. package/dist-cjs/index.js +400 -435
  4. package/dist-cjs/network-runtime/index.js +8 -172
  5. package/package.json +8 -6
  6. package/dist/.tsbuildinfo +0 -1
  7. package/dist/ask-user-interaction.js +0 -22
  8. package/dist/cache/web-cache.js +0 -66
  9. package/dist/definitions/arion.js +0 -104
  10. package/dist/definitions/browser/browser.js +0 -418
  11. package/dist/definitions/browser/index.js +0 -4
  12. package/dist/definitions/browser/pw-downloads.js +0 -114
  13. package/dist/definitions/browser/pw-interactions.js +0 -199
  14. package/dist/definitions/browser/pw-responses.js +0 -76
  15. package/dist/definitions/browser/pw-session.js +0 -310
  16. package/dist/definitions/browser/pw-shared.js +0 -66
  17. package/dist/definitions/browser/pw-snapshot.js +0 -301
  18. package/dist/definitions/browser/pw-state.js +0 -62
  19. package/dist/definitions/browser/types.js +0 -4
  20. package/dist/definitions/code-intelligence.js +0 -470
  21. package/dist/definitions/core.js +0 -109
  22. package/dist/definitions/delegation.js +0 -512
  23. package/dist/definitions/deploy.js +0 -65
  24. package/dist/definitions/filesystem.js +0 -196
  25. package/dist/definitions/frg.js +0 -63
  26. package/dist/definitions/index.js +0 -20
  27. package/dist/definitions/memory.js +0 -123
  28. package/dist/definitions/messaging.js +0 -625
  29. package/dist/definitions/meta.js +0 -349
  30. package/dist/definitions/network.js +0 -159
  31. package/dist/definitions/outlook.js +0 -277
  32. package/dist/definitions/patch/apply-patch.js +0 -184
  33. package/dist/definitions/patch/fuzzy-match.js +0 -166
  34. package/dist/definitions/patch/index.js +0 -1
  35. package/dist/definitions/patch/patch-parser.js +0 -207
  36. package/dist/definitions/patch/sandbox-paths.js +0 -105
  37. package/dist/definitions/process/index.js +0 -4
  38. package/dist/definitions/process/process-registry.js +0 -213
  39. package/dist/definitions/process/process.js +0 -386
  40. package/dist/definitions/process/pty-keys.js +0 -254
  41. package/dist/definitions/process/session-slug.js +0 -142
  42. package/dist/definitions/quip.js +0 -195
  43. package/dist/definitions/search.js +0 -60
  44. package/dist/definitions/session-history.js +0 -69
  45. package/dist/definitions/shell.js +0 -181
  46. package/dist/definitions/slack.js +0 -180
  47. package/dist/definitions/web.js +0 -109
  48. package/dist/executors/apply-patch.js +0 -901
  49. package/dist/executors/arion.js +0 -119
  50. package/dist/executors/code-intelligence.js +0 -882
  51. package/dist/executors/deploy.js +0 -848
  52. package/dist/executors/filesystem.js +0 -1122
  53. package/dist/executors/frg-freshness.js +0 -576
  54. package/dist/executors/frg.js +0 -298
  55. package/dist/executors/index.js +0 -46
  56. package/dist/executors/learning-meta.js +0 -1146
  57. package/dist/executors/lsp-client.js +0 -296
  58. package/dist/executors/memory.js +0 -750
  59. package/dist/executors/meta.js +0 -220
  60. package/dist/executors/process-registry.js +0 -465
  61. package/dist/executors/pty-session-store.js +0 -30
  62. package/dist/executors/pty.js +0 -271
  63. package/dist/executors/restart.js +0 -119
  64. package/dist/executors/search-freshness.js +0 -195
  65. package/dist/executors/search-types.js +0 -52
  66. package/dist/executors/search.js +0 -66
  67. package/dist/executors/self-diagnose.js +0 -398
  68. package/dist/executors/session-history.js +0 -283
  69. package/dist/executors/shell-safety.js +0 -473
  70. package/dist/executors/shell.js +0 -954
  71. package/dist/executors/utils.js +0 -33
  72. package/dist/executors/web.js +0 -542
  73. package/dist/extraction/content-extraction.js +0 -235
  74. package/dist/extraction/index.js +0 -4
  75. package/dist/headless-control-contract.js +0 -967
  76. package/dist/local-control-http-auth.js +0 -2
  77. package/dist/mcp/client.js +0 -181
  78. package/dist/mcp/connection.js +0 -480
  79. package/dist/mcp/index.js +0 -10
  80. package/dist/mcp/jsonrpc.js +0 -144
  81. package/dist/mcp/types.js +0 -7
  82. package/dist/network-control-adapter.js +0 -72
  83. package/dist/network-runtime/address-types.js +0 -165
  84. package/dist/network-runtime/db-owner-fencing.js +0 -69
  85. package/dist/network-runtime/delivery-receipts.js +0 -267
  86. package/dist/network-runtime/direct-endpoint-authority.js +0 -25
  87. package/dist/network-runtime/local-control-contract.js +0 -627
  88. package/dist/network-runtime/node-store-contract.js +0 -34
  89. package/dist/network-runtime/pair-route-contract.js +0 -77
  90. package/dist/network-runtime/peer-capabilities.js +0 -28
  91. package/dist/network-runtime/peer-principal-ref.js +0 -12
  92. package/dist/network-runtime/peer-state-machine.js +0 -121
  93. package/dist/network-runtime/protocol-schemas.js +0 -205
  94. package/dist/network-runtime/runtime-bootstrap-contract.js +0 -60
  95. package/dist/outlook/desktop-session.js +0 -279
  96. package/dist/policy.js +0 -149
  97. package/dist/providers/brave.js +0 -62
  98. package/dist/providers/duckduckgo.js +0 -176
  99. package/dist/providers/exa.js +0 -63
  100. package/dist/providers/firecrawl.js +0 -55
  101. package/dist/providers/index.js +0 -7
  102. package/dist/providers/jina.js +0 -49
  103. package/dist/providers/router.js +0 -96
  104. package/dist/providers/search-provider.js +0 -32
  105. package/dist/providers/tavily.js +0 -54
  106. package/dist/quip/desktop-session.js +0 -317
  107. package/dist/registry/index.js +0 -1
  108. package/dist/registry/registry.js +0 -756
  109. package/dist/runtime-socket-local-control-client.js +0 -330
  110. package/dist/security/dns-normalization.js +0 -19
  111. package/dist/security/dns-pinning.js +0 -123
  112. package/dist/security/external-content.js +0 -91
  113. package/dist/security/ssrf.js +0 -181
  114. package/dist/slack/desktop-session.js +0 -324
  115. package/dist/tool-factory.js +0 -47
  116. package/dist/types.js +0 -7
  117. package/dist/utils/retry.js +0 -132
  118. package/dist/utils/safe-parse-json.js +0 -160
  119. package/dist/utils/url.js +0 -19
  120. package/dist-cjs/.tsbuildinfo +0 -1
  121. package/dist-cjs/ask-user-interaction.js +0 -27
  122. package/dist-cjs/cache/web-cache.js +0 -70
  123. package/dist-cjs/definitions/arion.js +0 -107
  124. package/dist-cjs/definitions/browser/browser.js +0 -421
  125. package/dist-cjs/definitions/browser/index.js +0 -8
  126. package/dist-cjs/definitions/browser/pw-downloads.js +0 -117
  127. package/dist-cjs/definitions/browser/pw-interactions.js +0 -213
  128. package/dist-cjs/definitions/browser/pw-responses.js +0 -84
  129. package/dist-cjs/definitions/browser/pw-session.js +0 -326
  130. package/dist-cjs/definitions/browser/pw-shared.js +0 -72
  131. package/dist-cjs/definitions/browser/pw-snapshot.js +0 -307
  132. package/dist-cjs/definitions/browser/pw-state.js +0 -70
  133. package/dist-cjs/definitions/browser/types.js +0 -5
  134. package/dist-cjs/definitions/code-intelligence.js +0 -473
  135. package/dist-cjs/definitions/core.js +0 -133
  136. package/dist-cjs/definitions/delegation.js +0 -515
  137. package/dist-cjs/definitions/deploy.js +0 -68
  138. package/dist-cjs/definitions/filesystem.js +0 -199
  139. package/dist-cjs/definitions/frg.js +0 -66
  140. package/dist-cjs/definitions/index.js +0 -43
  141. package/dist-cjs/definitions/memory.js +0 -126
  142. package/dist-cjs/definitions/messaging.js +0 -631
  143. package/dist-cjs/definitions/meta.js +0 -352
  144. package/dist-cjs/definitions/network.js +0 -162
  145. package/dist-cjs/definitions/outlook.js +0 -280
  146. package/dist-cjs/definitions/patch/apply-patch.js +0 -191
  147. package/dist-cjs/definitions/patch/fuzzy-match.js +0 -172
  148. package/dist-cjs/definitions/patch/index.js +0 -5
  149. package/dist-cjs/definitions/patch/patch-parser.js +0 -215
  150. package/dist-cjs/definitions/patch/sandbox-paths.js +0 -113
  151. package/dist-cjs/definitions/process/index.js +0 -8
  152. package/dist-cjs/definitions/process/process-registry.js +0 -231
  153. package/dist-cjs/definitions/process/process.js +0 -389
  154. package/dist-cjs/definitions/process/pty-keys.js +0 -259
  155. package/dist-cjs/definitions/process/session-slug.js +0 -145
  156. package/dist-cjs/definitions/quip.js +0 -198
  157. package/dist-cjs/definitions/search.js +0 -63
  158. package/dist-cjs/definitions/session-history.js +0 -72
  159. package/dist-cjs/definitions/shell.js +0 -184
  160. package/dist-cjs/definitions/slack.js +0 -183
  161. package/dist-cjs/definitions/web.js +0 -112
  162. package/dist-cjs/executors/apply-patch.js +0 -938
  163. package/dist-cjs/executors/arion.js +0 -125
  164. package/dist-cjs/executors/code-intelligence.js +0 -925
  165. package/dist-cjs/executors/deploy.js +0 -869
  166. package/dist-cjs/executors/filesystem.js +0 -1167
  167. package/dist-cjs/executors/frg-freshness.js +0 -627
  168. package/dist-cjs/executors/frg.js +0 -334
  169. package/dist-cjs/executors/index.js +0 -143
  170. package/dist-cjs/executors/learning-meta.js +0 -1165
  171. package/dist-cjs/executors/lsp-client.js +0 -310
  172. package/dist-cjs/executors/memory.js +0 -796
  173. package/dist-cjs/executors/meta.js +0 -226
  174. package/dist-cjs/executors/process-registry.js +0 -469
  175. package/dist-cjs/executors/pty-session-store.js +0 -34
  176. package/dist-cjs/executors/pty.js +0 -312
  177. package/dist-cjs/executors/restart.js +0 -155
  178. package/dist-cjs/executors/search-freshness.js +0 -234
  179. package/dist-cjs/executors/search-types.js +0 -56
  180. package/dist-cjs/executors/search.js +0 -102
  181. package/dist-cjs/executors/self-diagnose.js +0 -434
  182. package/dist-cjs/executors/session-history.js +0 -320
  183. package/dist-cjs/executors/shell-safety.js +0 -478
  184. package/dist-cjs/executors/shell.js +0 -1001
  185. package/dist-cjs/executors/utils.js +0 -73
  186. package/dist-cjs/executors/web.js +0 -547
  187. package/dist-cjs/extraction/content-extraction.js +0 -243
  188. package/dist-cjs/extraction/index.js +0 -8
  189. package/dist-cjs/headless-control-contract.js +0 -972
  190. package/dist-cjs/local-control-http-auth.js +0 -5
  191. package/dist-cjs/mcp/client.js +0 -185
  192. package/dist-cjs/mcp/connection.js +0 -484
  193. package/dist-cjs/mcp/index.js +0 -30
  194. package/dist-cjs/mcp/jsonrpc.js +0 -148
  195. package/dist-cjs/mcp/types.js +0 -8
  196. package/dist-cjs/network-control-adapter.js +0 -77
  197. package/dist-cjs/network-runtime/address-types.js +0 -168
  198. package/dist-cjs/network-runtime/db-owner-fencing.js +0 -76
  199. package/dist-cjs/network-runtime/delivery-receipts.js +0 -276
  200. package/dist-cjs/network-runtime/direct-endpoint-authority.js +0 -29
  201. package/dist-cjs/network-runtime/local-control-contract.js +0 -633
  202. package/dist-cjs/network-runtime/node-store-contract.js +0 -38
  203. package/dist-cjs/network-runtime/pair-route-contract.js +0 -80
  204. package/dist-cjs/network-runtime/peer-capabilities.js +0 -37
  205. package/dist-cjs/network-runtime/peer-principal-ref.js +0 -15
  206. package/dist-cjs/network-runtime/peer-state-machine.js +0 -129
  207. package/dist-cjs/network-runtime/protocol-schemas.js +0 -212
  208. package/dist-cjs/network-runtime/runtime-bootstrap-contract.js +0 -63
  209. package/dist-cjs/outlook/desktop-session.js +0 -318
  210. package/dist-cjs/policy.js +0 -155
  211. package/dist-cjs/providers/brave.js +0 -66
  212. package/dist-cjs/providers/duckduckgo.js +0 -180
  213. package/dist-cjs/providers/exa.js +0 -67
  214. package/dist-cjs/providers/firecrawl.js +0 -59
  215. package/dist-cjs/providers/index.js +0 -17
  216. package/dist-cjs/providers/jina.js +0 -53
  217. package/dist-cjs/providers/router.js +0 -100
  218. package/dist-cjs/providers/search-provider.js +0 -36
  219. package/dist-cjs/providers/tavily.js +0 -58
  220. package/dist-cjs/quip/desktop-session.js +0 -353
  221. package/dist-cjs/registry/index.js +0 -6
  222. package/dist-cjs/registry/registry.js +0 -761
  223. package/dist-cjs/runtime-socket-local-control-client.js +0 -367
  224. package/dist-cjs/security/dns-normalization.js +0 -22
  225. package/dist-cjs/security/dns-pinning.js +0 -160
  226. package/dist-cjs/security/external-content.js +0 -95
  227. package/dist-cjs/security/ssrf.js +0 -221
  228. package/dist-cjs/slack/desktop-session.js +0 -366
  229. package/dist-cjs/tool-factory.js +0 -50
  230. package/dist-cjs/types.js +0 -8
  231. package/dist-cjs/utils/retry.js +0 -169
  232. package/dist-cjs/utils/safe-parse-json.js +0 -164
  233. package/dist-cjs/utils/url.js +0 -23
@@ -1,199 +0,0 @@
1
- // Originally from OpenClaw (MIT License, Copyright 2025 Peter Steinberger)
2
- // https://github.com/openclaw/openclaw
3
- // Modified for ARIA — stripped OpenClaw runtime, rewired to ARIA Tool interface
4
- import { requireRef, toAIFriendlyError, normalizeTimeoutMs } from "./pw-shared.js";
5
- // ── Ref locator ───────────────────────────────────────────────────────
6
- /**
7
- * Resolve a ref string (e.g. "e1") into a Playwright Locator using the
8
- * role-ref map from the last snapshot.
9
- */
10
- export function refLocator(page, ref, refs) {
11
- const normalized = ref.startsWith("@")
12
- ? ref.slice(1)
13
- : ref.startsWith("ref=")
14
- ? ref.slice(4)
15
- : ref;
16
- if (/^e\d+$/.test(normalized)) {
17
- const info = refs[normalized];
18
- if (!info) {
19
- throw new Error(`Unknown ref "${normalized}". Run a new snapshot and use a ref from that snapshot.`);
20
- }
21
- const locator = info.name
22
- ? page.getByRole(info.role, { name: info.name, exact: true })
23
- : page.getByRole(info.role);
24
- return info.nth !== undefined ? locator.nth(info.nth) : locator;
25
- }
26
- // Fallback: treat as CSS selector
27
- return page.locator(normalized);
28
- }
29
- // ── Click ─────────────────────────────────────────────────────────────
30
- export async function clickViaPlaywright(opts) {
31
- const ref = requireRef(opts.ref);
32
- const locator = refLocator(opts.page, ref, opts.refs);
33
- const timeout = normalizeTimeoutMs(opts.timeoutMs, 8000);
34
- try {
35
- if (opts.doubleClick) {
36
- await locator.dblclick({
37
- timeout,
38
- button: opts.button,
39
- modifiers: opts.modifiers,
40
- });
41
- }
42
- else {
43
- await locator.click({
44
- timeout,
45
- button: opts.button,
46
- modifiers: opts.modifiers,
47
- });
48
- }
49
- }
50
- catch (err) {
51
- throw toAIFriendlyError(err, ref);
52
- }
53
- }
54
- // ── Hover ─────────────────────────────────────────────────────────────
55
- export async function hoverViaPlaywright(opts) {
56
- const ref = requireRef(opts.ref);
57
- try {
58
- await refLocator(opts.page, ref, opts.refs).hover({
59
- timeout: normalizeTimeoutMs(opts.timeoutMs, 8000),
60
- });
61
- }
62
- catch (err) {
63
- throw toAIFriendlyError(err, ref);
64
- }
65
- }
66
- // ── Drag ──────────────────────────────────────────────────────────────
67
- export async function dragViaPlaywright(opts) {
68
- const startRef = requireRef(opts.startRef);
69
- const endRef = requireRef(opts.endRef);
70
- try {
71
- await refLocator(opts.page, startRef, opts.refs).dragTo(refLocator(opts.page, endRef, opts.refs), { timeout: normalizeTimeoutMs(opts.timeoutMs, 8000) });
72
- }
73
- catch (err) {
74
- throw toAIFriendlyError(err, `${startRef} -> ${endRef}`);
75
- }
76
- }
77
- // ── Type ──────────────────────────────────────────────────────────────
78
- export async function typeViaPlaywright(opts) {
79
- const text = String(opts.text ?? "");
80
- const ref = requireRef(opts.ref);
81
- const locator = refLocator(opts.page, ref, opts.refs);
82
- const timeout = normalizeTimeoutMs(opts.timeoutMs, 8000);
83
- try {
84
- if (opts.slowly) {
85
- await locator.click({ timeout });
86
- await locator.type(text, { timeout, delay: 75 });
87
- }
88
- else {
89
- await locator.fill(text, { timeout });
90
- }
91
- if (opts.submit) {
92
- await locator.press("Enter", { timeout });
93
- }
94
- }
95
- catch (err) {
96
- throw toAIFriendlyError(err, ref);
97
- }
98
- }
99
- // ── Select option ─────────────────────────────────────────────────────
100
- export async function selectOptionViaPlaywright(opts) {
101
- const ref = requireRef(opts.ref);
102
- if (!opts.values?.length) {
103
- throw new Error("values are required");
104
- }
105
- try {
106
- await refLocator(opts.page, ref, opts.refs).selectOption(opts.values, {
107
- timeout: normalizeTimeoutMs(opts.timeoutMs, 8000),
108
- });
109
- }
110
- catch (err) {
111
- throw toAIFriendlyError(err, ref);
112
- }
113
- }
114
- // ── Key press ─────────────────────────────────────────────────────────
115
- export async function pressKeyViaPlaywright(opts) {
116
- const key = String(opts.key ?? "").trim();
117
- if (!key) {
118
- throw new Error("key is required");
119
- }
120
- await opts.page.keyboard.press(key);
121
- }
122
- // ── Evaluate ──────────────────────────────────────────────────────────
123
- export async function evaluateViaPlaywright(opts) {
124
- const script = String(opts.script ?? "").trim();
125
- if (!script) {
126
- throw new Error("script is required");
127
- }
128
- const evaluateTimeout = normalizeTimeoutMs(opts.timeoutMs, 20_000);
129
- // Inject a timeout wrapper into the browser context so async scripts
130
- // don't block the Playwright command queue indefinitely.
131
- // We use a string-form evaluate to avoid TypeScript signature conflicts
132
- // with our minimal PwPage interface.
133
- const wrappedScript = `
134
- (function() {
135
- var fnBody = ${JSON.stringify(script)};
136
- var timeoutMs = ${evaluateTimeout};
137
- try {
138
- var candidate = eval("(" + fnBody + ")");
139
- var result = typeof candidate === "function" ? candidate() : candidate;
140
- if (result && typeof result === "object" && typeof result.then === "function") {
141
- return Promise.race([
142
- result,
143
- new Promise(function(_, reject) {
144
- setTimeout(function() { reject(new Error("evaluate timed out after " + timeoutMs + "ms")); }, timeoutMs);
145
- })
146
- ]);
147
- }
148
- return result;
149
- } catch (err) {
150
- throw new Error("Invalid evaluate function: " + (err && err.message ? err.message : String(err)));
151
- }
152
- })()
153
- `;
154
- const result = await opts.page.evaluate(wrappedScript);
155
- return result;
156
- }
157
- // ── Screenshot ────────────────────────────────────────────────────────
158
- export async function takeScreenshot(opts) {
159
- return opts.page.screenshot({
160
- type: "png",
161
- fullPage: Boolean(opts.fullPage),
162
- });
163
- }
164
- // ── Scroll ────────────────────────────────────────────────────────────
165
- export async function scrollPage(opts) {
166
- const pixels = Math.max(100, Math.min(5000, opts.amount ?? 500));
167
- const deltaY = opts.direction === "up" ? -pixels : pixels;
168
- await opts.page.mouse.wheel(0, deltaY);
169
- // Give the page a moment to process the scroll
170
- await opts.page.waitForTimeout(300);
171
- }
172
- // ── Wait ──────────────────────────────────────────────────────────────
173
- export async function waitForCondition(opts) {
174
- const timeout = normalizeTimeoutMs(opts.timeout, 10_000);
175
- if (opts.text) {
176
- await opts.page.locator(`text=${opts.text}`).first().waitFor({ state: "visible", timeout });
177
- return;
178
- }
179
- if (opts.selector) {
180
- await opts.page.locator(opts.selector).first().waitFor({ state: "visible", timeout });
181
- return;
182
- }
183
- // Default: wait for network idle
184
- await opts.page.waitForLoadState("networkidle", { timeout });
185
- }
186
- // ── Upload ────────────────────────────────────────────────────────────
187
- export async function uploadFiles(opts) {
188
- if (!opts.paths?.length) {
189
- throw new Error("paths are required");
190
- }
191
- const ref = requireRef(opts.ref);
192
- const locator = refLocator(opts.page, ref, opts.refs);
193
- try {
194
- await locator.setInputFiles(opts.paths);
195
- }
196
- catch (err) {
197
- throw toAIFriendlyError(err, ref);
198
- }
199
- }
@@ -1,76 +0,0 @@
1
- // Originally from OpenClaw (MIT License, Copyright 2025 Peter Steinberger)
2
- // https://github.com/openclaw/openclaw
3
- // Modified for ARIA — stripped OpenClaw runtime, rewired to ARIA Tool interface
4
- // ── Circular buffer limits ────────────────────────────────────────────
5
- export const MAX_CONSOLE_MESSAGES = 500;
6
- export const MAX_NETWORK_REQUESTS = 500;
7
- export const MAX_PAGE_ERRORS = 200;
8
- // ── Console message filtering ─────────────────────────────────────────
9
- function consolePriority(level) {
10
- switch (level) {
11
- case "error":
12
- return 3;
13
- case "warning":
14
- return 2;
15
- case "info":
16
- case "log":
17
- return 1;
18
- case "debug":
19
- return 0;
20
- default:
21
- return 1;
22
- }
23
- }
24
- /**
25
- * Filter console messages by minimum severity level.
26
- */
27
- export function filterConsoleMessages(messages, level) {
28
- if (!level) {
29
- return [...messages];
30
- }
31
- const min = consolePriority(level);
32
- return messages.filter((msg) => consolePriority(msg.type) >= min);
33
- }
34
- /**
35
- * Filter network requests by URL substring match.
36
- */
37
- export function filterNetworkRequests(requests, filter) {
38
- const pattern = typeof filter === "string" ? filter.trim() : "";
39
- if (!pattern) {
40
- return [...requests];
41
- }
42
- return requests.filter((r) => r.url.includes(pattern));
43
- }
44
- /**
45
- * Format console messages for tool output.
46
- */
47
- export function formatConsoleMessages(messages) {
48
- if (!messages.length) {
49
- return "No console messages captured.";
50
- }
51
- return messages.map((m) => `[${m.type.toUpperCase()}] ${m.text}`).join("\n");
52
- }
53
- /**
54
- * Format network requests for tool output.
55
- */
56
- export function formatNetworkRequests(requests) {
57
- if (!requests.length) {
58
- return "No network requests captured.";
59
- }
60
- return requests
61
- .map((r) => {
62
- const status = r.status !== undefined ? ` ${r.status}` : "";
63
- const failure = r.failureText ? ` (FAILED: ${r.failureText})` : "";
64
- return `${r.method}${status} ${r.url}${failure}`;
65
- })
66
- .join("\n");
67
- }
68
- /**
69
- * Format page errors for tool output.
70
- */
71
- export function formatPageErrors(errors) {
72
- if (!errors.length) {
73
- return "No page errors captured.";
74
- }
75
- return errors.map((e) => `${e.name ?? "Error"}: ${e.message}`).join("\n");
76
- }
@@ -1,310 +0,0 @@
1
- // Originally from OpenClaw (MIT License, Copyright 2025 Peter Steinberger)
2
- // https://github.com/openclaw/openclaw
3
- // Modified for ARIA — stripped OpenClaw runtime, rewired to ARIA Tool interface
4
- import { MAX_CONSOLE_MESSAGES, MAX_NETWORK_REQUESTS, MAX_PAGE_ERRORS } from "./pw-responses.js";
5
- // ── Module-level state (singleton per Node process) ───────────────────
6
- let currentSession = null;
7
- let currentRefs = {};
8
- const consoleMessages = [];
9
- const networkRequests = [];
10
- const pageErrors = [];
11
- let nextRequestId = 0;
12
- const DEFAULT_NAVIGATION_OPTIONS = {
13
- timeout: 20_000,
14
- waitUntil: "domcontentloaded",
15
- };
16
- // ── Accessors ─────────────────────────────────────────────────────────
17
- export function getSession() {
18
- return currentSession;
19
- }
20
- export function getRefs() {
21
- return currentRefs;
22
- }
23
- export function setRefs(refs) {
24
- currentRefs = refs;
25
- }
26
- export function getConsoleMessages() {
27
- return consoleMessages;
28
- }
29
- export function getNetworkRequests() {
30
- return networkRequests;
31
- }
32
- export function getPageErrors() {
33
- return pageErrors;
34
- }
35
- const defaultPlaywrightLoader = () => Function('return import("playwright")')();
36
- let playwrightLoader = defaultPlaywrightLoader;
37
- /**
38
- * Test seam for injecting a mocked playwright loader.
39
- * Passing null restores the production loader.
40
- */
41
- export function setPlaywrightLoaderForTest(loader) {
42
- playwrightLoader = loader ?? defaultPlaywrightLoader;
43
- }
44
- // ── Page listener wiring ──────────────────────────────────────────────
45
- const observedPages = new WeakSet();
46
- function wirePageListeners(page) {
47
- if (observedPages.has(page)) {
48
- return;
49
- }
50
- observedPages.add(page);
51
- page.on("console", (...args) => {
52
- const msg = args[0];
53
- if (!msg)
54
- return;
55
- const entry = {
56
- type: typeof msg.type === "function" ? msg.type() : "log",
57
- text: typeof msg.text === "function" ? msg.text() : String(msg),
58
- timestamp: new Date().toISOString(),
59
- };
60
- consoleMessages.push(entry);
61
- if (consoleMessages.length > MAX_CONSOLE_MESSAGES) {
62
- consoleMessages.shift();
63
- }
64
- });
65
- page.on("pageerror", (...args) => {
66
- const err = args[0];
67
- pageErrors.push({
68
- message: err?.message ? String(err.message) : String(err),
69
- name: err?.name ? String(err.name) : undefined,
70
- timestamp: new Date().toISOString(),
71
- });
72
- if (pageErrors.length > MAX_PAGE_ERRORS) {
73
- pageErrors.shift();
74
- }
75
- });
76
- page.on("request", (...args) => {
77
- const req = args[0];
78
- if (!req)
79
- return;
80
- nextRequestId += 1;
81
- const entry = {
82
- id: `r${nextRequestId}`,
83
- timestamp: new Date().toISOString(),
84
- method: typeof req.method === "function" ? req.method() : "GET",
85
- url: typeof req.url === "function" ? req.url() : "",
86
- resourceType: typeof req.resourceType === "function" ? req.resourceType() : undefined,
87
- };
88
- networkRequests.push(entry);
89
- if (networkRequests.length > MAX_NETWORK_REQUESTS) {
90
- networkRequests.shift();
91
- }
92
- });
93
- page.on("response", (...args) => {
94
- const resp = args[0];
95
- if (!resp)
96
- return;
97
- const respUrl = typeof resp.url === "function" ? resp.url() : "";
98
- // Match by URL (find most recent matching request)
99
- for (let i = networkRequests.length - 1; i >= 0; i -= 1) {
100
- const rec = networkRequests[i];
101
- if (rec && rec.url === respUrl && rec.status === undefined) {
102
- rec.status = typeof resp.status === "function" ? resp.status() : undefined;
103
- rec.ok = typeof resp.ok === "function" ? resp.ok() : undefined;
104
- break;
105
- }
106
- }
107
- });
108
- page.on("requestfailed", (...args) => {
109
- const req = args[0];
110
- if (!req)
111
- return;
112
- const failUrl = typeof req.url === "function" ? req.url() : "";
113
- for (let i = networkRequests.length - 1; i >= 0; i -= 1) {
114
- const rec = networkRequests[i];
115
- if (rec && rec.url === failUrl && rec.ok === undefined) {
116
- rec.ok = false;
117
- rec.failureText = typeof req.failure === "function" ? req.failure()?.errorText : undefined;
118
- break;
119
- }
120
- }
121
- });
122
- }
123
- function isChromiumLike(value) {
124
- return (typeof value === "object" &&
125
- value !== null &&
126
- typeof value.launch === "function");
127
- }
128
- /**
129
- * Resolve Playwright's chromium launcher across module interop shapes.
130
- * Some runtimes expose `{ chromium }`, others only `{ default: { chromium } }`.
131
- */
132
- export function resolveChromiumLauncher(moduleValue) {
133
- const pw = moduleValue;
134
- const chromium = pw?.chromium ?? pw?.default?.chromium;
135
- if (isChromiumLike(chromium)) {
136
- return chromium;
137
- }
138
- const keys = pw && typeof pw === "object"
139
- ? Object.keys(pw)
140
- .sort()
141
- .join(", ")
142
- : String(pw);
143
- throw new Error(`Invalid playwright module shape: missing chromium.launch (module keys: ${keys || "(none)"}).`);
144
- }
145
- /**
146
- * Launch a new Playwright browser session.
147
- * Uses dynamic import so the tool module loads even without playwright installed.
148
- */
149
- export async function launchBrowser(options) {
150
- if (currentSession) {
151
- // Already have a session — navigate if URL given, otherwise return existing
152
- if (options?.url) {
153
- try {
154
- await currentSession.page.goto(options.url, DEFAULT_NAVIGATION_OPTIONS);
155
- }
156
- catch (error) {
157
- const message = error instanceof Error ? error.message : String(error);
158
- throw new Error(`Navigation to ${options.url} failed: ${message}. Session remains active; use 'snapshot' or retry 'navigate'.`);
159
- }
160
- }
161
- return currentSession;
162
- }
163
- // Dynamic import: playwright is an optional peer dependency.
164
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
165
- let pw;
166
- try {
167
- pw = await playwrightLoader();
168
- }
169
- catch {
170
- throw new Error("playwright is not installed. Run: npx playwright install chromium\n" +
171
- "Or: npm install playwright && npx playwright install chromium");
172
- }
173
- const chromium = resolveChromiumLauncher(pw);
174
- const browser = await chromium.launch({
175
- headless: options?.headless !== false, // default headless
176
- });
177
- const context = browser.newContext
178
- ? await browser.newContext({
179
- viewport: { width: 1280, height: 720 },
180
- userAgent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
181
- })
182
- : (browser.contexts()[0] ??
183
- (() => {
184
- throw new Error("No browser context available");
185
- })());
186
- const page = context.pages?.().length
187
- ? context.pages()[0]
188
- : await context.newPage();
189
- wirePageListeners(page);
190
- // Persist session state before first navigation so launch+goto timeout
191
- // cannot leave the tool in a "no session" state.
192
- currentSession = { browser, context, page };
193
- currentRefs = {};
194
- consoleMessages.length = 0;
195
- networkRequests.length = 0;
196
- pageErrors.length = 0;
197
- nextRequestId = 0;
198
- if (options?.url) {
199
- try {
200
- await page.goto(options.url, DEFAULT_NAVIGATION_OPTIONS);
201
- }
202
- catch (error) {
203
- const message = error instanceof Error ? error.message : String(error);
204
- throw new Error(`Browser launched, but initial navigation to ${options.url} failed: ${message}. Session remains active; use 'snapshot' or retry 'navigate'.`);
205
- }
206
- }
207
- return currentSession;
208
- }
209
- /**
210
- * Close the current browser session and clean up all state.
211
- */
212
- export async function closeBrowser() {
213
- const session = currentSession;
214
- currentSession = null;
215
- currentRefs = {};
216
- consoleMessages.length = 0;
217
- networkRequests.length = 0;
218
- pageErrors.length = 0;
219
- nextRequestId = 0;
220
- if (session) {
221
- try {
222
- await session.browser.close();
223
- }
224
- catch {
225
- // Best-effort close.
226
- }
227
- }
228
- }
229
- // ── Tab management ────────────────────────────────────────────────────
230
- /**
231
- * List all open tabs (pages) in the current context.
232
- */
233
- export function listTabs() {
234
- if (!currentSession) {
235
- return [];
236
- }
237
- const pages = currentSession.context.pages();
238
- return pages.map((p, i) => ({
239
- index: i,
240
- url: p.url(),
241
- active: p === currentSession.page,
242
- }));
243
- }
244
- /**
245
- * Open a new tab, optionally navigating to a URL.
246
- */
247
- export async function newTab(url) {
248
- if (!currentSession) {
249
- const launched = await launchBrowser({ url });
250
- return { index: 0, url: launched.page.url() };
251
- }
252
- const page = await currentSession.context.newPage();
253
- wirePageListeners(page);
254
- currentSession.page = page;
255
- currentRefs = {};
256
- if (url) {
257
- await page.goto(url, DEFAULT_NAVIGATION_OPTIONS);
258
- }
259
- const pages = currentSession.context.pages();
260
- return { index: pages.length - 1, url: page.url() };
261
- }
262
- /**
263
- * Switch to a tab by index.
264
- */
265
- export async function selectTab(index) {
266
- if (!currentSession) {
267
- await launchBrowser();
268
- }
269
- if (!currentSession) {
270
- throw new Error("No tabs open.");
271
- }
272
- const pages = currentSession.context.pages();
273
- if (index < 0 || index >= pages.length) {
274
- throw new Error(`Tab index ${index} out of range (0..${pages.length - 1})`);
275
- }
276
- const page = pages[index];
277
- currentSession.page = page;
278
- wirePageListeners(page);
279
- currentRefs = {};
280
- return { url: page.url() };
281
- }
282
- /**
283
- * Close a tab by index (defaults to current tab).
284
- */
285
- export async function closeTab(index) {
286
- if (!currentSession) {
287
- throw new Error("No tabs open.");
288
- }
289
- const pages = currentSession.context.pages();
290
- const targetIndex = index ?? pages.indexOf(currentSession.page);
291
- if (targetIndex < 0 || targetIndex >= pages.length) {
292
- throw new Error(`Tab index ${targetIndex} out of range`);
293
- }
294
- const targetPage = pages[targetIndex];
295
- await targetPage.close();
296
- // Update current page if we closed the active one
297
- const remaining = currentSession.context.pages();
298
- if (!remaining.length) {
299
- // All tabs closed — create a fresh one
300
- const page = await currentSession.context.newPage();
301
- currentSession.page = page;
302
- wirePageListeners(page);
303
- }
304
- else if (targetPage === currentSession.page) {
305
- const newIndex = Math.min(targetIndex, remaining.length - 1);
306
- currentSession.page = remaining[newIndex];
307
- wirePageListeners(currentSession.page);
308
- }
309
- currentRefs = {};
310
- }
@@ -1,66 +0,0 @@
1
- // Originally from OpenClaw (MIT License, Copyright 2025 Peter Steinberger)
2
- // https://github.com/openclaw/openclaw
3
- // Modified for ARIA — stripped OpenClaw runtime, rewired to ARIA Tool interface
4
- /**
5
- * Shared utilities for Playwright-based browser tool functions.
6
- * Ported from OpenClaw's pw-tools-core.shared.ts.
7
- */
8
- /**
9
- * Parse a raw ref string into its canonical "eN" form.
10
- * Accepts: "e1", "@e1", "ref=e1" -> "e1". Returns null if invalid.
11
- */
12
- export function parseRoleRef(raw) {
13
- const trimmed = raw.trim();
14
- if (!trimmed) {
15
- return null;
16
- }
17
- const normalized = trimmed.startsWith("@")
18
- ? trimmed.slice(1)
19
- : trimmed.startsWith("ref=")
20
- ? trimmed.slice(4)
21
- : trimmed;
22
- return /^e\d+$/.test(normalized) ? normalized : null;
23
- }
24
- /**
25
- * Validate and normalize a ref string. Throws if the ref is empty/invalid.
26
- */
27
- export function requireRef(value) {
28
- const raw = typeof value === "string" ? value.trim() : "";
29
- const roleRef = raw ? parseRoleRef(raw) : null;
30
- const ref = roleRef ?? (raw.startsWith("@") ? raw.slice(1) : raw);
31
- if (!ref) {
32
- throw new Error("ref is required");
33
- }
34
- return ref;
35
- }
36
- /**
37
- * Clamp a timeout value to a safe range (500ms .. 120s).
38
- */
39
- export function normalizeTimeoutMs(timeoutMs, fallback) {
40
- return Math.max(500, Math.min(120_000, timeoutMs ?? fallback));
41
- }
42
- /**
43
- * Rewrite Playwright errors into messages that guide the LLM to take
44
- * corrective action (re-snapshot, scroll, etc.).
45
- */
46
- export function toAIFriendlyError(error, selector) {
47
- const message = error instanceof Error ? error.message : String(error);
48
- if (message.includes("strict mode violation")) {
49
- const countMatch = message.match(/resolved to (\d+) elements/);
50
- const count = countMatch ? countMatch[1] : "multiple";
51
- return new Error(`Selector "${selector}" matched ${count} elements. ` +
52
- `Run a new snapshot to get updated refs, or use a different ref.`);
53
- }
54
- if ((message.includes("Timeout") || message.includes("waiting for")) &&
55
- (message.includes("to be visible") || message.includes("not visible"))) {
56
- return new Error(`Element "${selector}" not found or not visible. ` +
57
- `Run a new snapshot to see current page elements.`);
58
- }
59
- if (message.includes("intercepts pointer events") ||
60
- message.includes("not visible") ||
61
- message.includes("not receive pointer events")) {
62
- return new Error(`Element "${selector}" is not interactable (hidden or covered). ` +
63
- `Try scrolling it into view, closing overlays, or re-snapshotting.`);
64
- }
65
- return error instanceof Error ? error : new Error(message);
66
- }