@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,326 +0,0 @@
1
- "use strict";
2
- // Originally from OpenClaw (MIT License, Copyright 2025 Peter Steinberger)
3
- // https://github.com/openclaw/openclaw
4
- // Modified for ARIA — stripped OpenClaw runtime, rewired to ARIA Tool interface
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getSession = getSession;
7
- exports.getRefs = getRefs;
8
- exports.setRefs = setRefs;
9
- exports.getConsoleMessages = getConsoleMessages;
10
- exports.getNetworkRequests = getNetworkRequests;
11
- exports.getPageErrors = getPageErrors;
12
- exports.setPlaywrightLoaderForTest = setPlaywrightLoaderForTest;
13
- exports.resolveChromiumLauncher = resolveChromiumLauncher;
14
- exports.launchBrowser = launchBrowser;
15
- exports.closeBrowser = closeBrowser;
16
- exports.listTabs = listTabs;
17
- exports.newTab = newTab;
18
- exports.selectTab = selectTab;
19
- exports.closeTab = closeTab;
20
- const pw_responses_js_1 = require("./pw-responses.js");
21
- // ── Module-level state (singleton per Node process) ───────────────────
22
- let currentSession = null;
23
- let currentRefs = {};
24
- const consoleMessages = [];
25
- const networkRequests = [];
26
- const pageErrors = [];
27
- let nextRequestId = 0;
28
- const DEFAULT_NAVIGATION_OPTIONS = {
29
- timeout: 20_000,
30
- waitUntil: "domcontentloaded",
31
- };
32
- // ── Accessors ─────────────────────────────────────────────────────────
33
- function getSession() {
34
- return currentSession;
35
- }
36
- function getRefs() {
37
- return currentRefs;
38
- }
39
- function setRefs(refs) {
40
- currentRefs = refs;
41
- }
42
- function getConsoleMessages() {
43
- return consoleMessages;
44
- }
45
- function getNetworkRequests() {
46
- return networkRequests;
47
- }
48
- function getPageErrors() {
49
- return pageErrors;
50
- }
51
- const defaultPlaywrightLoader = () => Function('return import("playwright")')();
52
- let playwrightLoader = defaultPlaywrightLoader;
53
- /**
54
- * Test seam for injecting a mocked playwright loader.
55
- * Passing null restores the production loader.
56
- */
57
- function setPlaywrightLoaderForTest(loader) {
58
- playwrightLoader = loader ?? defaultPlaywrightLoader;
59
- }
60
- // ── Page listener wiring ──────────────────────────────────────────────
61
- const observedPages = new WeakSet();
62
- function wirePageListeners(page) {
63
- if (observedPages.has(page)) {
64
- return;
65
- }
66
- observedPages.add(page);
67
- page.on("console", (...args) => {
68
- const msg = args[0];
69
- if (!msg)
70
- return;
71
- const entry = {
72
- type: typeof msg.type === "function" ? msg.type() : "log",
73
- text: typeof msg.text === "function" ? msg.text() : String(msg),
74
- timestamp: new Date().toISOString(),
75
- };
76
- consoleMessages.push(entry);
77
- if (consoleMessages.length > pw_responses_js_1.MAX_CONSOLE_MESSAGES) {
78
- consoleMessages.shift();
79
- }
80
- });
81
- page.on("pageerror", (...args) => {
82
- const err = args[0];
83
- pageErrors.push({
84
- message: err?.message ? String(err.message) : String(err),
85
- name: err?.name ? String(err.name) : undefined,
86
- timestamp: new Date().toISOString(),
87
- });
88
- if (pageErrors.length > pw_responses_js_1.MAX_PAGE_ERRORS) {
89
- pageErrors.shift();
90
- }
91
- });
92
- page.on("request", (...args) => {
93
- const req = args[0];
94
- if (!req)
95
- return;
96
- nextRequestId += 1;
97
- const entry = {
98
- id: `r${nextRequestId}`,
99
- timestamp: new Date().toISOString(),
100
- method: typeof req.method === "function" ? req.method() : "GET",
101
- url: typeof req.url === "function" ? req.url() : "",
102
- resourceType: typeof req.resourceType === "function" ? req.resourceType() : undefined,
103
- };
104
- networkRequests.push(entry);
105
- if (networkRequests.length > pw_responses_js_1.MAX_NETWORK_REQUESTS) {
106
- networkRequests.shift();
107
- }
108
- });
109
- page.on("response", (...args) => {
110
- const resp = args[0];
111
- if (!resp)
112
- return;
113
- const respUrl = typeof resp.url === "function" ? resp.url() : "";
114
- // Match by URL (find most recent matching request)
115
- for (let i = networkRequests.length - 1; i >= 0; i -= 1) {
116
- const rec = networkRequests[i];
117
- if (rec && rec.url === respUrl && rec.status === undefined) {
118
- rec.status = typeof resp.status === "function" ? resp.status() : undefined;
119
- rec.ok = typeof resp.ok === "function" ? resp.ok() : undefined;
120
- break;
121
- }
122
- }
123
- });
124
- page.on("requestfailed", (...args) => {
125
- const req = args[0];
126
- if (!req)
127
- return;
128
- const failUrl = typeof req.url === "function" ? req.url() : "";
129
- for (let i = networkRequests.length - 1; i >= 0; i -= 1) {
130
- const rec = networkRequests[i];
131
- if (rec && rec.url === failUrl && rec.ok === undefined) {
132
- rec.ok = false;
133
- rec.failureText = typeof req.failure === "function" ? req.failure()?.errorText : undefined;
134
- break;
135
- }
136
- }
137
- });
138
- }
139
- function isChromiumLike(value) {
140
- return (typeof value === "object" &&
141
- value !== null &&
142
- typeof value.launch === "function");
143
- }
144
- /**
145
- * Resolve Playwright's chromium launcher across module interop shapes.
146
- * Some runtimes expose `{ chromium }`, others only `{ default: { chromium } }`.
147
- */
148
- function resolveChromiumLauncher(moduleValue) {
149
- const pw = moduleValue;
150
- const chromium = pw?.chromium ?? pw?.default?.chromium;
151
- if (isChromiumLike(chromium)) {
152
- return chromium;
153
- }
154
- const keys = pw && typeof pw === "object"
155
- ? Object.keys(pw)
156
- .sort()
157
- .join(", ")
158
- : String(pw);
159
- throw new Error(`Invalid playwright module shape: missing chromium.launch (module keys: ${keys || "(none)"}).`);
160
- }
161
- /**
162
- * Launch a new Playwright browser session.
163
- * Uses dynamic import so the tool module loads even without playwright installed.
164
- */
165
- async function launchBrowser(options) {
166
- if (currentSession) {
167
- // Already have a session — navigate if URL given, otherwise return existing
168
- if (options?.url) {
169
- try {
170
- await currentSession.page.goto(options.url, DEFAULT_NAVIGATION_OPTIONS);
171
- }
172
- catch (error) {
173
- const message = error instanceof Error ? error.message : String(error);
174
- throw new Error(`Navigation to ${options.url} failed: ${message}. Session remains active; use 'snapshot' or retry 'navigate'.`);
175
- }
176
- }
177
- return currentSession;
178
- }
179
- // Dynamic import: playwright is an optional peer dependency.
180
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
181
- let pw;
182
- try {
183
- pw = await playwrightLoader();
184
- }
185
- catch {
186
- throw new Error("playwright is not installed. Run: npx playwright install chromium\n" +
187
- "Or: npm install playwright && npx playwright install chromium");
188
- }
189
- const chromium = resolveChromiumLauncher(pw);
190
- const browser = await chromium.launch({
191
- headless: options?.headless !== false, // default headless
192
- });
193
- const context = browser.newContext
194
- ? await browser.newContext({
195
- viewport: { width: 1280, height: 720 },
196
- 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",
197
- })
198
- : (browser.contexts()[0] ??
199
- (() => {
200
- throw new Error("No browser context available");
201
- })());
202
- const page = context.pages?.().length
203
- ? context.pages()[0]
204
- : await context.newPage();
205
- wirePageListeners(page);
206
- // Persist session state before first navigation so launch+goto timeout
207
- // cannot leave the tool in a "no session" state.
208
- currentSession = { browser, context, page };
209
- currentRefs = {};
210
- consoleMessages.length = 0;
211
- networkRequests.length = 0;
212
- pageErrors.length = 0;
213
- nextRequestId = 0;
214
- if (options?.url) {
215
- try {
216
- await page.goto(options.url, DEFAULT_NAVIGATION_OPTIONS);
217
- }
218
- catch (error) {
219
- const message = error instanceof Error ? error.message : String(error);
220
- throw new Error(`Browser launched, but initial navigation to ${options.url} failed: ${message}. Session remains active; use 'snapshot' or retry 'navigate'.`);
221
- }
222
- }
223
- return currentSession;
224
- }
225
- /**
226
- * Close the current browser session and clean up all state.
227
- */
228
- async function closeBrowser() {
229
- const session = currentSession;
230
- currentSession = null;
231
- currentRefs = {};
232
- consoleMessages.length = 0;
233
- networkRequests.length = 0;
234
- pageErrors.length = 0;
235
- nextRequestId = 0;
236
- if (session) {
237
- try {
238
- await session.browser.close();
239
- }
240
- catch {
241
- // Best-effort close.
242
- }
243
- }
244
- }
245
- // ── Tab management ────────────────────────────────────────────────────
246
- /**
247
- * List all open tabs (pages) in the current context.
248
- */
249
- function listTabs() {
250
- if (!currentSession) {
251
- return [];
252
- }
253
- const pages = currentSession.context.pages();
254
- return pages.map((p, i) => ({
255
- index: i,
256
- url: p.url(),
257
- active: p === currentSession.page,
258
- }));
259
- }
260
- /**
261
- * Open a new tab, optionally navigating to a URL.
262
- */
263
- async function newTab(url) {
264
- if (!currentSession) {
265
- const launched = await launchBrowser({ url });
266
- return { index: 0, url: launched.page.url() };
267
- }
268
- const page = await currentSession.context.newPage();
269
- wirePageListeners(page);
270
- currentSession.page = page;
271
- currentRefs = {};
272
- if (url) {
273
- await page.goto(url, DEFAULT_NAVIGATION_OPTIONS);
274
- }
275
- const pages = currentSession.context.pages();
276
- return { index: pages.length - 1, url: page.url() };
277
- }
278
- /**
279
- * Switch to a tab by index.
280
- */
281
- async function selectTab(index) {
282
- if (!currentSession) {
283
- await launchBrowser();
284
- }
285
- if (!currentSession) {
286
- throw new Error("No tabs open.");
287
- }
288
- const pages = currentSession.context.pages();
289
- if (index < 0 || index >= pages.length) {
290
- throw new Error(`Tab index ${index} out of range (0..${pages.length - 1})`);
291
- }
292
- const page = pages[index];
293
- currentSession.page = page;
294
- wirePageListeners(page);
295
- currentRefs = {};
296
- return { url: page.url() };
297
- }
298
- /**
299
- * Close a tab by index (defaults to current tab).
300
- */
301
- async function closeTab(index) {
302
- if (!currentSession) {
303
- throw new Error("No tabs open.");
304
- }
305
- const pages = currentSession.context.pages();
306
- const targetIndex = index ?? pages.indexOf(currentSession.page);
307
- if (targetIndex < 0 || targetIndex >= pages.length) {
308
- throw new Error(`Tab index ${targetIndex} out of range`);
309
- }
310
- const targetPage = pages[targetIndex];
311
- await targetPage.close();
312
- // Update current page if we closed the active one
313
- const remaining = currentSession.context.pages();
314
- if (!remaining.length) {
315
- // All tabs closed — create a fresh one
316
- const page = await currentSession.context.newPage();
317
- currentSession.page = page;
318
- wirePageListeners(page);
319
- }
320
- else if (targetPage === currentSession.page) {
321
- const newIndex = Math.min(targetIndex, remaining.length - 1);
322
- currentSession.page = remaining[newIndex];
323
- wirePageListeners(currentSession.page);
324
- }
325
- currentRefs = {};
326
- }
@@ -1,72 +0,0 @@
1
- "use strict";
2
- // Originally from OpenClaw (MIT License, Copyright 2025 Peter Steinberger)
3
- // https://github.com/openclaw/openclaw
4
- // Modified for ARIA — stripped OpenClaw runtime, rewired to ARIA Tool interface
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.parseRoleRef = parseRoleRef;
7
- exports.requireRef = requireRef;
8
- exports.normalizeTimeoutMs = normalizeTimeoutMs;
9
- exports.toAIFriendlyError = toAIFriendlyError;
10
- /**
11
- * Shared utilities for Playwright-based browser tool functions.
12
- * Ported from OpenClaw's pw-tools-core.shared.ts.
13
- */
14
- /**
15
- * Parse a raw ref string into its canonical "eN" form.
16
- * Accepts: "e1", "@e1", "ref=e1" -> "e1". Returns null if invalid.
17
- */
18
- function parseRoleRef(raw) {
19
- const trimmed = raw.trim();
20
- if (!trimmed) {
21
- return null;
22
- }
23
- const normalized = trimmed.startsWith("@")
24
- ? trimmed.slice(1)
25
- : trimmed.startsWith("ref=")
26
- ? trimmed.slice(4)
27
- : trimmed;
28
- return /^e\d+$/.test(normalized) ? normalized : null;
29
- }
30
- /**
31
- * Validate and normalize a ref string. Throws if the ref is empty/invalid.
32
- */
33
- function requireRef(value) {
34
- const raw = typeof value === "string" ? value.trim() : "";
35
- const roleRef = raw ? parseRoleRef(raw) : null;
36
- const ref = roleRef ?? (raw.startsWith("@") ? raw.slice(1) : raw);
37
- if (!ref) {
38
- throw new Error("ref is required");
39
- }
40
- return ref;
41
- }
42
- /**
43
- * Clamp a timeout value to a safe range (500ms .. 120s).
44
- */
45
- function normalizeTimeoutMs(timeoutMs, fallback) {
46
- return Math.max(500, Math.min(120_000, timeoutMs ?? fallback));
47
- }
48
- /**
49
- * Rewrite Playwright errors into messages that guide the LLM to take
50
- * corrective action (re-snapshot, scroll, etc.).
51
- */
52
- function toAIFriendlyError(error, selector) {
53
- const message = error instanceof Error ? error.message : String(error);
54
- if (message.includes("strict mode violation")) {
55
- const countMatch = message.match(/resolved to (\d+) elements/);
56
- const count = countMatch ? countMatch[1] : "multiple";
57
- return new Error(`Selector "${selector}" matched ${count} elements. ` +
58
- `Run a new snapshot to get updated refs, or use a different ref.`);
59
- }
60
- if ((message.includes("Timeout") || message.includes("waiting for")) &&
61
- (message.includes("to be visible") || message.includes("not visible"))) {
62
- return new Error(`Element "${selector}" not found or not visible. ` +
63
- `Run a new snapshot to see current page elements.`);
64
- }
65
- if (message.includes("intercepts pointer events") ||
66
- message.includes("not visible") ||
67
- message.includes("not receive pointer events")) {
68
- return new Error(`Element "${selector}" is not interactable (hidden or covered). ` +
69
- `Try scrolling it into view, closing overlays, or re-snapshotting.`);
70
- }
71
- return error instanceof Error ? error : new Error(message);
72
- }
@@ -1,307 +0,0 @@
1
- "use strict";
2
- // Originally from OpenClaw (MIT License, Copyright 2025 Peter Steinberger)
3
- // https://github.com/openclaw/openclaw
4
- // Modified for ARIA — stripped OpenClaw runtime, rewired to ARIA Tool interface
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getRoleSnapshotStats = getRoleSnapshotStats;
7
- exports.buildRoleSnapshotFromAriaSnapshot = buildRoleSnapshotFromAriaSnapshot;
8
- exports.snapshotPage = snapshotPage;
9
- exports.navigatePage = navigatePage;
10
- // ── Role classification sets ──────────────────────────────────────────
11
- const INTERACTIVE_ROLES = new Set([
12
- "button",
13
- "link",
14
- "textbox",
15
- "checkbox",
16
- "radio",
17
- "combobox",
18
- "listbox",
19
- "menuitem",
20
- "menuitemcheckbox",
21
- "menuitemradio",
22
- "option",
23
- "searchbox",
24
- "slider",
25
- "spinbutton",
26
- "switch",
27
- "tab",
28
- "treeitem",
29
- ]);
30
- const CONTENT_ROLES = new Set([
31
- "heading",
32
- "cell",
33
- "gridcell",
34
- "columnheader",
35
- "rowheader",
36
- "listitem",
37
- "article",
38
- "region",
39
- "main",
40
- "navigation",
41
- ]);
42
- const STRUCTURAL_ROLES = new Set([
43
- "generic",
44
- "group",
45
- "list",
46
- "table",
47
- "row",
48
- "rowgroup",
49
- "grid",
50
- "treegrid",
51
- "menu",
52
- "menubar",
53
- "toolbar",
54
- "tablist",
55
- "tree",
56
- "directory",
57
- "document",
58
- "application",
59
- "presentation",
60
- "none",
61
- ]);
62
- // ── Stats ─────────────────────────────────────────────────────────────
63
- function getRoleSnapshotStats(snapshot, refs) {
64
- const interactive = Object.values(refs).filter((r) => INTERACTIVE_ROLES.has(r.role)).length;
65
- return {
66
- lines: snapshot.split("\n").length,
67
- chars: snapshot.length,
68
- refs: Object.keys(refs).length,
69
- interactive,
70
- };
71
- }
72
- // ── Internal helpers ──────────────────────────────────────────────────
73
- function getIndentLevel(line) {
74
- const match = line.match(/^(\s*)/);
75
- return match ? Math.floor(match[1].length / 2) : 0;
76
- }
77
- function createRoleNameTracker() {
78
- const counts = new Map();
79
- const refsByKey = new Map();
80
- return {
81
- counts,
82
- refsByKey,
83
- getKey(role, name) {
84
- return `${role}:${name ?? ""}`;
85
- },
86
- getNextIndex(role, name) {
87
- const key = this.getKey(role, name);
88
- const current = counts.get(key) ?? 0;
89
- counts.set(key, current + 1);
90
- return current;
91
- },
92
- trackRef(role, name, ref) {
93
- const key = this.getKey(role, name);
94
- const list = refsByKey.get(key) ?? [];
95
- list.push(ref);
96
- refsByKey.set(key, list);
97
- },
98
- getDuplicateKeys() {
99
- const out = new Set();
100
- for (const [key, refs] of refsByKey) {
101
- if (refs.length > 1) {
102
- out.add(key);
103
- }
104
- }
105
- return out;
106
- },
107
- };
108
- }
109
- function removeNthFromNonDuplicates(refs, tracker) {
110
- const duplicates = tracker.getDuplicateKeys();
111
- for (const [ref, data] of Object.entries(refs)) {
112
- const key = tracker.getKey(data.role, data.name);
113
- if (!duplicates.has(key)) {
114
- delete refs[ref]?.nth;
115
- }
116
- }
117
- }
118
- function compactTree(tree) {
119
- const lines = tree.split("\n");
120
- const result = [];
121
- for (let i = 0; i < lines.length; i += 1) {
122
- const line = lines[i];
123
- if (line.includes("[ref=")) {
124
- result.push(line);
125
- continue;
126
- }
127
- if (line.includes(":") && !line.trimEnd().endsWith(":")) {
128
- result.push(line);
129
- continue;
130
- }
131
- const currentIndent = getIndentLevel(line);
132
- let hasRelevantChildren = false;
133
- for (let j = i + 1; j < lines.length; j += 1) {
134
- const childIndent = getIndentLevel(lines[j]);
135
- if (childIndent <= currentIndent) {
136
- break;
137
- }
138
- if (lines[j]?.includes("[ref=")) {
139
- hasRelevantChildren = true;
140
- break;
141
- }
142
- }
143
- if (hasRelevantChildren) {
144
- result.push(line);
145
- }
146
- }
147
- return result.join("\n");
148
- }
149
- function matchInteractiveSnapshotLine(line, options) {
150
- const depth = getIndentLevel(line);
151
- if (options.maxDepth !== undefined && depth > options.maxDepth) {
152
- return null;
153
- }
154
- const match = line.match(/^(\s*-\s*)(\w+)(?:\s+"([^"]*)")?(.*)$/);
155
- if (!match) {
156
- return null;
157
- }
158
- const [, , roleRaw, name, suffix] = match;
159
- if (roleRaw.startsWith("/")) {
160
- return null;
161
- }
162
- const role = roleRaw.toLowerCase();
163
- return {
164
- roleRaw: roleRaw,
165
- role,
166
- ...(name ? { name } : {}),
167
- suffix: suffix,
168
- };
169
- }
170
- function processLine(line, refs, options, tracker, nextRef) {
171
- const depth = getIndentLevel(line);
172
- if (options.maxDepth !== undefined && depth > options.maxDepth) {
173
- return null;
174
- }
175
- const match = line.match(/^(\s*-\s*)(\w+)(?:\s+"([^"]*)")?(.*)$/);
176
- if (!match) {
177
- return options.interactive ? null : line;
178
- }
179
- const [, prefix, roleRaw, name, suffix] = match;
180
- if (roleRaw.startsWith("/")) {
181
- return options.interactive ? null : line;
182
- }
183
- const role = roleRaw.toLowerCase();
184
- const isInteractive = INTERACTIVE_ROLES.has(role);
185
- const isContent = CONTENT_ROLES.has(role);
186
- const isStructural = STRUCTURAL_ROLES.has(role);
187
- if (options.interactive && !isInteractive) {
188
- return null;
189
- }
190
- if (options.compact && isStructural && !name) {
191
- return null;
192
- }
193
- const shouldHaveRef = isInteractive || (isContent && !!name);
194
- if (!shouldHaveRef) {
195
- return line;
196
- }
197
- const ref = nextRef();
198
- const nth = tracker.getNextIndex(role, name);
199
- tracker.trackRef(role, name, ref);
200
- refs[ref] = { role, name, nth };
201
- let enhanced = `${prefix}${roleRaw}`;
202
- if (name) {
203
- enhanced += ` "${name}"`;
204
- }
205
- enhanced += ` [ref=${ref}]`;
206
- if (nth > 0) {
207
- enhanced += ` [nth=${nth}]`;
208
- }
209
- if (suffix) {
210
- enhanced += suffix;
211
- }
212
- return enhanced;
213
- }
214
- // ── Public API ────────────────────────────────────────────────────────
215
- /**
216
- * Build a role-ref snapshot from Playwright's ariaSnapshot() output.
217
- * This is the core transform: raw ARIA tree text -> annotated tree + ref map.
218
- */
219
- function buildRoleSnapshotFromAriaSnapshot(ariaSnapshot, options = {}) {
220
- const lines = ariaSnapshot.split("\n");
221
- const refs = {};
222
- const tracker = createRoleNameTracker();
223
- let counter = 0;
224
- const nextRef = () => {
225
- counter += 1;
226
- return `e${counter}`;
227
- };
228
- if (options.interactive) {
229
- const result = [];
230
- for (const line of lines) {
231
- const parsed = matchInteractiveSnapshotLine(line, options);
232
- if (!parsed) {
233
- continue;
234
- }
235
- const { roleRaw, role, name, suffix } = parsed;
236
- if (!INTERACTIVE_ROLES.has(role)) {
237
- continue;
238
- }
239
- const ref = nextRef();
240
- const nth = tracker.getNextIndex(role, name);
241
- tracker.trackRef(role, name, ref);
242
- refs[ref] = { role, name, nth };
243
- let enhanced = `- ${roleRaw}`;
244
- if (name) {
245
- enhanced += ` "${name}"`;
246
- }
247
- enhanced += ` [ref=${ref}]`;
248
- if (nth > 0) {
249
- enhanced += ` [nth=${nth}]`;
250
- }
251
- if (suffix.includes("[")) {
252
- enhanced += suffix;
253
- }
254
- result.push(enhanced);
255
- }
256
- removeNthFromNonDuplicates(refs, tracker);
257
- return {
258
- snapshot: result.join("\n") || "(no interactive elements)",
259
- refs,
260
- };
261
- }
262
- const result = [];
263
- for (const line of lines) {
264
- const processed = processLine(line, refs, options, tracker, nextRef);
265
- if (processed !== null) {
266
- result.push(processed);
267
- }
268
- }
269
- removeNthFromNonDuplicates(refs, tracker);
270
- const tree = result.join("\n") || "(empty)";
271
- return {
272
- snapshot: options.compact ? compactTree(tree) : tree,
273
- refs,
274
- };
275
- }
276
- /**
277
- * Take a role-based accessibility snapshot of a page.
278
- * Uses Playwright's built-in ariaSnapshot() on the :root locator,
279
- * then annotates elements with [ref=eN] markers.
280
- */
281
- async function snapshotPage(page, options) {
282
- const locator = page.locator(":root");
283
- const ariaSnapshot = await locator.ariaSnapshot();
284
- const built = buildRoleSnapshotFromAriaSnapshot(String(ariaSnapshot ?? ""), options);
285
- const stats = getRoleSnapshotStats(built.snapshot, built.refs);
286
- return {
287
- snapshot: built.snapshot,
288
- refs: built.refs,
289
- stats,
290
- url: page.url(),
291
- title: await page.title(),
292
- };
293
- }
294
- /**
295
- * Navigate a page to a URL.
296
- */
297
- async function navigatePage(page, url, timeoutMs) {
298
- const target = String(url ?? "").trim();
299
- if (!target) {
300
- throw new Error("url is required");
301
- }
302
- await page.goto(target, {
303
- timeout: Math.max(1000, Math.min(120_000, timeoutMs ?? 20_000)),
304
- waitUntil: "domcontentloaded",
305
- });
306
- return { url: page.url() };
307
- }