@aria-cli/tools 1.0.9 → 1.0.11
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/package.json +9 -5
- package/src/__tests__/web-fetch-download.test.ts +0 -433
- package/src/__tests__/web-tools.test.ts +0 -619
- package/src/ask-user-interaction.ts +0 -33
- package/src/cache/web-cache.ts +0 -110
- package/src/definitions/arion.ts +0 -118
- package/src/definitions/browser/browser.ts +0 -502
- package/src/definitions/browser/index.ts +0 -5
- package/src/definitions/browser/pw-downloads.ts +0 -142
- package/src/definitions/browser/pw-interactions.ts +0 -282
- package/src/definitions/browser/pw-responses.ts +0 -98
- package/src/definitions/browser/pw-session.ts +0 -405
- package/src/definitions/browser/pw-shared.ts +0 -85
- package/src/definitions/browser/pw-snapshot.ts +0 -383
- package/src/definitions/browser/pw-state.ts +0 -101
- package/src/definitions/browser/types.ts +0 -203
- package/src/definitions/code-intelligence.ts +0 -526
- package/src/definitions/core.ts +0 -118
- package/src/definitions/delegation.ts +0 -567
- package/src/definitions/deploy.ts +0 -73
- package/src/definitions/filesystem.ts +0 -217
- package/src/definitions/frg.ts +0 -67
- package/src/definitions/index.ts +0 -28
- package/src/definitions/memory.ts +0 -150
- package/src/definitions/messaging.ts +0 -734
- package/src/definitions/meta.ts +0 -392
- package/src/definitions/network.ts +0 -179
- package/src/definitions/outlook.ts +0 -318
- package/src/definitions/patch/apply-patch.ts +0 -235
- package/src/definitions/patch/fuzzy-match.ts +0 -217
- package/src/definitions/patch/index.ts +0 -1
- package/src/definitions/patch/patch-parser.ts +0 -297
- package/src/definitions/patch/sandbox-paths.ts +0 -129
- package/src/definitions/process/index.ts +0 -5
- package/src/definitions/process/process-registry.ts +0 -303
- package/src/definitions/process/process.ts +0 -456
- package/src/definitions/process/pty-keys.ts +0 -298
- package/src/definitions/process/session-slug.ts +0 -147
- package/src/definitions/quip.ts +0 -225
- package/src/definitions/search.ts +0 -67
- package/src/definitions/session-history.ts +0 -79
- package/src/definitions/shell.ts +0 -202
- package/src/definitions/slack.ts +0 -211
- package/src/definitions/web.ts +0 -119
- package/src/executors/apply-patch.ts +0 -1035
- package/src/executors/arion.ts +0 -199
- package/src/executors/code-intelligence.ts +0 -1179
- package/src/executors/deploy.ts +0 -1066
- package/src/executors/filesystem.ts +0 -1428
- package/src/executors/frg-freshness.ts +0 -743
- package/src/executors/frg.ts +0 -394
- package/src/executors/index.ts +0 -280
- package/src/executors/learning-meta.ts +0 -1367
- package/src/executors/lsp-client.ts +0 -355
- package/src/executors/memory.ts +0 -978
- package/src/executors/meta.ts +0 -293
- package/src/executors/process-registry.ts +0 -570
- package/src/executors/pty-session-store.ts +0 -43
- package/src/executors/pty.ts +0 -342
- package/src/executors/restart.ts +0 -133
- package/src/executors/search-freshness.ts +0 -249
- package/src/executors/search-types.ts +0 -98
- package/src/executors/search.ts +0 -89
- package/src/executors/self-diagnose.ts +0 -552
- package/src/executors/session-history.ts +0 -435
- package/src/executors/shell-safety.ts +0 -519
- package/src/executors/shell.ts +0 -1243
- package/src/executors/utils.ts +0 -40
- package/src/executors/web.ts +0 -786
- package/src/extraction/content-extraction.ts +0 -281
- package/src/extraction/index.ts +0 -5
- package/src/headless-control-contract.ts +0 -1149
- package/src/index.ts +0 -788
- package/src/local-control-http-auth.ts +0 -2
- package/src/mcp/client.ts +0 -218
- package/src/mcp/connection.ts +0 -568
- package/src/mcp/index.ts +0 -11
- package/src/mcp/jsonrpc.ts +0 -195
- package/src/mcp/types.ts +0 -199
- package/src/network-control-adapter.ts +0 -88
- package/src/network-runtime/address-types.ts +0 -218
- package/src/network-runtime/db-owner-fencing.ts +0 -91
- package/src/network-runtime/delivery-receipts.ts +0 -372
- package/src/network-runtime/direct-endpoint-authority.ts +0 -35
- package/src/network-runtime/index.ts +0 -316
- package/src/network-runtime/local-control-contract.ts +0 -784
- package/src/network-runtime/node-store-contract.ts +0 -46
- package/src/network-runtime/pair-route-contract.ts +0 -97
- package/src/network-runtime/peer-capabilities.ts +0 -48
- package/src/network-runtime/peer-principal-ref.ts +0 -20
- package/src/network-runtime/peer-state-machine.ts +0 -160
- package/src/network-runtime/protocol-schemas.ts +0 -265
- package/src/network-runtime/runtime-bootstrap-contract.ts +0 -83
- package/src/outlook/desktop-session.ts +0 -409
- package/src/policy.ts +0 -171
- package/src/providers/brave.ts +0 -80
- package/src/providers/duckduckgo.ts +0 -199
- package/src/providers/exa.ts +0 -85
- package/src/providers/firecrawl.ts +0 -77
- package/src/providers/index.ts +0 -8
- package/src/providers/jina.ts +0 -70
- package/src/providers/router.ts +0 -121
- package/src/providers/search-provider.ts +0 -74
- package/src/providers/tavily.ts +0 -74
- package/src/quip/desktop-session.ts +0 -435
- package/src/registry/index.ts +0 -1
- package/src/registry/registry.ts +0 -905
- package/src/runtime-socket-local-control-client.ts +0 -632
- package/src/security/dns-normalization.ts +0 -34
- package/src/security/dns-pinning.ts +0 -138
- package/src/security/external-content.ts +0 -129
- package/src/security/ssrf.ts +0 -207
- package/src/slack/desktop-session.ts +0 -493
- package/src/tool-factory.ts +0 -91
- package/src/types.ts +0 -1341
- package/src/utils/retry.ts +0 -163
- package/src/utils/safe-parse-json.ts +0 -176
- package/src/utils/url.ts +0 -20
- package/tests/benchmarks/registry.bench.ts +0 -57
- package/tests/cache/web-cache.test.ts +0 -147
- package/tests/critical-integration.test.ts +0 -1465
- package/tests/definitions/apply-patch.test.ts +0 -586
- package/tests/definitions/browser.test.ts +0 -495
- package/tests/definitions/delegation-pause-resume.test.ts +0 -758
- package/tests/definitions/execution.test.ts +0 -671
- package/tests/definitions/messaging-inbox-scope.test.ts +0 -229
- package/tests/definitions/messaging.test.ts +0 -1468
- package/tests/definitions/outlook.test.ts +0 -30
- package/tests/definitions/process.test.ts +0 -469
- package/tests/definitions/slack.test.ts +0 -28
- package/tests/definitions/tool-inventory.test.ts +0 -218
- package/tests/e2e/delegation-quest-orchestration.e2e.test.ts +0 -433
- package/tests/e2e/memory-tool-discovery-contract.e2e.test.ts +0 -81
- package/tests/executors/apply-patch.test.ts +0 -538
- package/tests/executors/arion.test.ts +0 -309
- package/tests/executors/conversation-primitives.test.ts +0 -250
- package/tests/executors/deploy.test.ts +0 -746
- package/tests/executors/filesystem-tools.test.ts +0 -357
- package/tests/executors/filesystem.test.ts +0 -959
- package/tests/executors/frg-freshness.test.ts +0 -136
- package/tests/executors/frg-merge.test.ts +0 -70
- package/tests/executors/frg-session-content.test.ts +0 -40
- package/tests/executors/frg.test.ts +0 -56
- package/tests/executors/memory-bugfixes.test.ts +0 -257
- package/tests/executors/memory-real-memoria.integration.test.ts +0 -316
- package/tests/executors/memory.test.ts +0 -853
- package/tests/executors/meta-tools.test.ts +0 -411
- package/tests/executors/meta.test.ts +0 -683
- package/tests/executors/path-containment.test.ts +0 -51
- package/tests/executors/process-registry.test.ts +0 -505
- package/tests/executors/pty.test.ts +0 -664
- package/tests/executors/quest-security.test.ts +0 -249
- package/tests/executors/read-file-media.test.ts +0 -230
- package/tests/executors/recall-knowledge-schema.test.ts +0 -209
- package/tests/executors/recall-tags.test.ts +0 -278
- package/tests/executors/remember-null-safety.contract.test.ts +0 -41
- package/tests/executors/restart.test.ts +0 -67
- package/tests/executors/search-unified.test.ts +0 -381
- package/tests/executors/session-history.test.ts +0 -340
- package/tests/executors/session-transcript.test.ts +0 -561
- package/tests/executors/shell-abort.test.ts +0 -416
- package/tests/executors/shell-env-blocklist.test.ts +0 -648
- package/tests/executors/shell-env-process.test.ts +0 -245
- package/tests/executors/shell-process-registry.test.ts +0 -334
- package/tests/executors/shell-tools.test.ts +0 -393
- package/tests/executors/shell.test.ts +0 -690
- package/tests/executors/web-abort-vs-timeout.test.ts +0 -213
- package/tests/executors/web-integration.test.ts +0 -633
- package/tests/executors/web-symlink.test.ts +0 -18
- package/tests/executors/web.test.ts +0 -1400
- package/tests/executors/write-stdin.test.ts +0 -145
- package/tests/extraction/content-extraction.test.ts +0 -153
- package/tests/guards/tools-default-test-lane.integration.test.ts +0 -21
- package/tests/guards/tools-package-test-commands.e2e.test.ts +0 -43
- package/tests/guards/tools-test-lane-manifest.contract.test.ts +0 -76
- package/tests/guards/tools-vitest-workspace-alias.contract.test.ts +0 -63
- package/tests/helpers/async-waits.ts +0 -53
- package/tests/integration/headless-control-contract.integration.test.ts +0 -153
- package/tests/integration/memory-tool-schema-parity.integration.test.ts +0 -67
- package/tests/integration/meta-tools-round-trip.integration.test.ts +0 -506
- package/tests/integration/quest-round-trip.test.ts +0 -303
- package/tests/integration/registry-executor-flow.test.ts +0 -85
- package/tests/integration.test.ts +0 -177
- package/tests/loading-tier.test.ts +0 -126
- package/tests/mcp/client-reconnect.test.ts +0 -267
- package/tests/mcp/connection.test.ts +0 -846
- package/tests/mcp/injectable-logger.test.ts +0 -83
- package/tests/mcp/jsonrpc.test.ts +0 -109
- package/tests/mcp/lifecycle.test.ts +0 -879
- package/tests/network-runtime/address-types.contract.test.ts +0 -143
- package/tests/network-runtime/continuity-bind-schema.contract.test.ts +0 -203
- package/tests/network-runtime/local-control-contract.test.ts +0 -869
- package/tests/network-runtime/local-control-invite-token.contract.test.ts +0 -146
- package/tests/network-runtime/node-store-contract.test.ts +0 -11
- package/tests/network-runtime/pair-protocol-nodeid.contract.test.ts +0 -15
- package/tests/network-runtime/peer-state-machine.contract.test.ts +0 -148
- package/tests/network-runtime/protocol-schemas.contract.test.ts +0 -512
- package/tests/network-runtime/relay-pending-nodeid.contract.test.ts +0 -62
- package/tests/network-runtime/runtime-bootstrap-contract.test.ts +0 -227
- package/tests/network-runtime/runtime-socket-local-control-client.test.ts +0 -621
- package/tests/network-runtime/wait-for-message-script.test.ts +0 -288
- package/tests/parallel.test.ts +0 -71
- package/tests/policy.test.ts +0 -184
- package/tests/print-default-test-lane.ts +0 -14
- package/tests/print-test-lane-manifest.ts +0 -22
- package/tests/providers/brave.test.ts +0 -159
- package/tests/providers/duckduckgo.test.ts +0 -207
- package/tests/providers/exa.test.ts +0 -175
- package/tests/providers/firecrawl.test.ts +0 -168
- package/tests/providers/jina.test.ts +0 -144
- package/tests/providers/router.test.ts +0 -328
- package/tests/providers/tavily.test.ts +0 -165
- package/tests/registry/discovery.test.ts +0 -154
- package/tests/registry/injectable-logger.test.ts +0 -230
- package/tests/registry/input-validation.test.ts +0 -361
- package/tests/registry/interface-completeness.test.ts +0 -85
- package/tests/registry/mcp-integration.test.ts +0 -103
- package/tests/registry/mcp-read-only-hint.test.ts +0 -60
- package/tests/registry/memoria-discovery.test.ts +0 -390
- package/tests/registry/nested-validation.test.ts +0 -283
- package/tests/registry/pseudo-tool-filtering.test.ts +0 -258
- package/tests/registry/registration-lifecycle.test.ts +0 -133
- package/tests/registry-validation.test.ts +0 -424
- package/tests/registry.test.ts +0 -460
- package/tests/security/dns-pinning.test.ts +0 -162
- package/tests/security/external-content.test.ts +0 -144
- package/tests/security/ssrf.test.ts +0 -118
- package/tests/shell-safety-integration.test.ts +0 -32
- package/tests/shell-safety.test.ts +0 -365
- package/tests/slack/desktop-session.test.ts +0 -50
- package/tests/test-lane-manifest.ts +0 -440
- package/tests/test-utils.ts +0 -27
- package/tests/tool-factory.test.ts +0 -188
- package/tests/utils/retry.test.ts +0 -231
- package/tests/utils/url.test.ts +0 -63
- package/tsconfig.cjs.json +0 -24
- package/tsconfig.json +0 -12
- package/vitest.config.ts +0 -55
- package/vitest.e2e.config.ts +0 -24
- package/vitest.integration.config.ts +0 -24
- package/vitest.native.config.ts +0 -24
|
@@ -1,405 +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
|
-
/**
|
|
6
|
-
* Browser session lifecycle management.
|
|
7
|
-
* Unlike OpenClaw (which connects to an external Chrome via CDP), ARIA
|
|
8
|
-
* launches its own Playwright browser instance directly.
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
import type {
|
|
12
|
-
BrowserConsoleMessage,
|
|
13
|
-
BrowserNetworkRequest,
|
|
14
|
-
BrowserPageError,
|
|
15
|
-
BrowserSession,
|
|
16
|
-
PwBrowser,
|
|
17
|
-
PwBrowserContext,
|
|
18
|
-
PwPage,
|
|
19
|
-
RoleRefMap,
|
|
20
|
-
} from "./types.js";
|
|
21
|
-
import { MAX_CONSOLE_MESSAGES, MAX_NETWORK_REQUESTS, MAX_PAGE_ERRORS } from "./pw-responses.js";
|
|
22
|
-
|
|
23
|
-
// ── Module-level state (singleton per Node process) ───────────────────
|
|
24
|
-
|
|
25
|
-
let currentSession: BrowserSession | null = null;
|
|
26
|
-
let currentRefs: RoleRefMap = {};
|
|
27
|
-
const consoleMessages: BrowserConsoleMessage[] = [];
|
|
28
|
-
const networkRequests: BrowserNetworkRequest[] = [];
|
|
29
|
-
const pageErrors: BrowserPageError[] = [];
|
|
30
|
-
let nextRequestId = 0;
|
|
31
|
-
|
|
32
|
-
const DEFAULT_NAVIGATION_OPTIONS = {
|
|
33
|
-
timeout: 20_000,
|
|
34
|
-
waitUntil: "domcontentloaded" as const,
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
// ── Accessors ─────────────────────────────────────────────────────────
|
|
38
|
-
|
|
39
|
-
export function getSession(): BrowserSession | null {
|
|
40
|
-
return currentSession;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export function getRefs(): RoleRefMap {
|
|
44
|
-
return currentRefs;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export function setRefs(refs: RoleRefMap): void {
|
|
48
|
-
currentRefs = refs;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export function getConsoleMessages(): BrowserConsoleMessage[] {
|
|
52
|
-
return consoleMessages;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export function getNetworkRequests(): BrowserNetworkRequest[] {
|
|
56
|
-
return networkRequests;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export function getPageErrors(): BrowserPageError[] {
|
|
60
|
-
return pageErrors;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const defaultPlaywrightLoader = (): Promise<unknown> =>
|
|
64
|
-
Function('return import("playwright")')() as Promise<unknown>;
|
|
65
|
-
|
|
66
|
-
let playwrightLoader = defaultPlaywrightLoader;
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Test seam for injecting a mocked playwright loader.
|
|
70
|
-
* Passing null restores the production loader.
|
|
71
|
-
*/
|
|
72
|
-
export function setPlaywrightLoaderForTest(loader: (() => Promise<unknown>) | null): void {
|
|
73
|
-
playwrightLoader = loader ?? defaultPlaywrightLoader;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
// ── Page listener wiring ──────────────────────────────────────────────
|
|
77
|
-
|
|
78
|
-
const observedPages = new WeakSet<object>();
|
|
79
|
-
|
|
80
|
-
function wirePageListeners(page: PwPage): void {
|
|
81
|
-
if (observedPages.has(page as unknown as object)) {
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
observedPages.add(page as unknown as object);
|
|
85
|
-
|
|
86
|
-
page.on("console", (...args: unknown[]) => {
|
|
87
|
-
const msg = args[0] as { type?: () => string; text?: () => string } | undefined;
|
|
88
|
-
if (!msg) return;
|
|
89
|
-
const entry: BrowserConsoleMessage = {
|
|
90
|
-
type: typeof msg.type === "function" ? msg.type() : "log",
|
|
91
|
-
text: typeof msg.text === "function" ? msg.text() : String(msg),
|
|
92
|
-
timestamp: new Date().toISOString(),
|
|
93
|
-
};
|
|
94
|
-
consoleMessages.push(entry);
|
|
95
|
-
if (consoleMessages.length > MAX_CONSOLE_MESSAGES) {
|
|
96
|
-
consoleMessages.shift();
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
page.on("pageerror", (...args: unknown[]) => {
|
|
101
|
-
const err = args[0] as Error | undefined;
|
|
102
|
-
pageErrors.push({
|
|
103
|
-
message: err?.message ? String(err.message) : String(err),
|
|
104
|
-
name: err?.name ? String(err.name) : undefined,
|
|
105
|
-
timestamp: new Date().toISOString(),
|
|
106
|
-
});
|
|
107
|
-
if (pageErrors.length > MAX_PAGE_ERRORS) {
|
|
108
|
-
pageErrors.shift();
|
|
109
|
-
}
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
page.on("request", (...args: unknown[]) => {
|
|
113
|
-
const req = args[0] as
|
|
114
|
-
| {
|
|
115
|
-
method?: () => string;
|
|
116
|
-
url?: () => string;
|
|
117
|
-
resourceType?: () => string;
|
|
118
|
-
}
|
|
119
|
-
| undefined;
|
|
120
|
-
if (!req) return;
|
|
121
|
-
nextRequestId += 1;
|
|
122
|
-
const entry: BrowserNetworkRequest = {
|
|
123
|
-
id: `r${nextRequestId}`,
|
|
124
|
-
timestamp: new Date().toISOString(),
|
|
125
|
-
method: typeof req.method === "function" ? req.method() : "GET",
|
|
126
|
-
url: typeof req.url === "function" ? req.url() : "",
|
|
127
|
-
resourceType: typeof req.resourceType === "function" ? req.resourceType() : undefined,
|
|
128
|
-
};
|
|
129
|
-
networkRequests.push(entry);
|
|
130
|
-
if (networkRequests.length > MAX_NETWORK_REQUESTS) {
|
|
131
|
-
networkRequests.shift();
|
|
132
|
-
}
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
page.on("response", (...args: unknown[]) => {
|
|
136
|
-
const resp = args[0] as
|
|
137
|
-
| {
|
|
138
|
-
url?: () => string;
|
|
139
|
-
status?: () => number;
|
|
140
|
-
ok?: () => boolean;
|
|
141
|
-
request?: () => { url?: () => string };
|
|
142
|
-
}
|
|
143
|
-
| undefined;
|
|
144
|
-
if (!resp) return;
|
|
145
|
-
const respUrl = typeof resp.url === "function" ? resp.url() : "";
|
|
146
|
-
// Match by URL (find most recent matching request)
|
|
147
|
-
for (let i = networkRequests.length - 1; i >= 0; i -= 1) {
|
|
148
|
-
const rec = networkRequests[i];
|
|
149
|
-
if (rec && rec.url === respUrl && rec.status === undefined) {
|
|
150
|
-
rec.status = typeof resp.status === "function" ? resp.status() : undefined;
|
|
151
|
-
rec.ok = typeof resp.ok === "function" ? resp.ok() : undefined;
|
|
152
|
-
break;
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
page.on("requestfailed", (...args: unknown[]) => {
|
|
158
|
-
const req = args[0] as
|
|
159
|
-
| {
|
|
160
|
-
url?: () => string;
|
|
161
|
-
failure?: () => { errorText?: string } | null;
|
|
162
|
-
}
|
|
163
|
-
| undefined;
|
|
164
|
-
if (!req) return;
|
|
165
|
-
const failUrl = typeof req.url === "function" ? req.url() : "";
|
|
166
|
-
for (let i = networkRequests.length - 1; i >= 0; i -= 1) {
|
|
167
|
-
const rec = networkRequests[i];
|
|
168
|
-
if (rec && rec.url === failUrl && rec.ok === undefined) {
|
|
169
|
-
rec.ok = false;
|
|
170
|
-
rec.failureText = typeof req.failure === "function" ? req.failure()?.errorText : undefined;
|
|
171
|
-
break;
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
});
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
// ── Launch / Close ────────────────────────────────────────────────────
|
|
178
|
-
|
|
179
|
-
type ChromiumLike = {
|
|
180
|
-
launch: (options?: { headless?: boolean }) => Promise<PwBrowser>;
|
|
181
|
-
};
|
|
182
|
-
|
|
183
|
-
function isChromiumLike(value: unknown): value is ChromiumLike {
|
|
184
|
-
return (
|
|
185
|
-
typeof value === "object" &&
|
|
186
|
-
value !== null &&
|
|
187
|
-
typeof (value as { launch?: unknown }).launch === "function"
|
|
188
|
-
);
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
/**
|
|
192
|
-
* Resolve Playwright's chromium launcher across module interop shapes.
|
|
193
|
-
* Some runtimes expose `{ chromium }`, others only `{ default: { chromium } }`.
|
|
194
|
-
*/
|
|
195
|
-
export function resolveChromiumLauncher(moduleValue: unknown): ChromiumLike {
|
|
196
|
-
const pw = moduleValue as { chromium?: unknown; default?: { chromium?: unknown } } | null;
|
|
197
|
-
const chromium = pw?.chromium ?? pw?.default?.chromium;
|
|
198
|
-
if (isChromiumLike(chromium)) {
|
|
199
|
-
return chromium;
|
|
200
|
-
}
|
|
201
|
-
const keys =
|
|
202
|
-
pw && typeof pw === "object"
|
|
203
|
-
? Object.keys(pw as Record<string, unknown>)
|
|
204
|
-
.sort()
|
|
205
|
-
.join(", ")
|
|
206
|
-
: String(pw);
|
|
207
|
-
throw new Error(
|
|
208
|
-
`Invalid playwright module shape: missing chromium.launch (module keys: ${keys || "(none)"}).`,
|
|
209
|
-
);
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
/**
|
|
213
|
-
* Launch a new Playwright browser session.
|
|
214
|
-
* Uses dynamic import so the tool module loads even without playwright installed.
|
|
215
|
-
*/
|
|
216
|
-
export async function launchBrowser(options?: {
|
|
217
|
-
headless?: boolean;
|
|
218
|
-
url?: string;
|
|
219
|
-
}): Promise<BrowserSession> {
|
|
220
|
-
if (currentSession) {
|
|
221
|
-
// Already have a session — navigate if URL given, otherwise return existing
|
|
222
|
-
if (options?.url) {
|
|
223
|
-
try {
|
|
224
|
-
await currentSession.page.goto(options.url, DEFAULT_NAVIGATION_OPTIONS);
|
|
225
|
-
} catch (error) {
|
|
226
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
227
|
-
throw new Error(
|
|
228
|
-
`Navigation to ${options.url} failed: ${message}. Session remains active; use 'snapshot' or retry 'navigate'.`,
|
|
229
|
-
);
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
return currentSession;
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
// Dynamic import: playwright is an optional peer dependency.
|
|
236
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
237
|
-
let pw: any;
|
|
238
|
-
try {
|
|
239
|
-
pw = await playwrightLoader();
|
|
240
|
-
} catch {
|
|
241
|
-
throw new Error(
|
|
242
|
-
"playwright is not installed. Run: npx playwright install chromium\n" +
|
|
243
|
-
"Or: npm install playwright && npx playwright install chromium",
|
|
244
|
-
);
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
const chromium = resolveChromiumLauncher(pw);
|
|
248
|
-
const browser = await chromium.launch({
|
|
249
|
-
headless: options?.headless !== false, // default headless
|
|
250
|
-
});
|
|
251
|
-
|
|
252
|
-
const context = (
|
|
253
|
-
browser as unknown as { newContext: (opts: unknown) => Promise<PwBrowserContext> }
|
|
254
|
-
).newContext
|
|
255
|
-
? await (
|
|
256
|
-
browser as unknown as { newContext: (opts: unknown) => Promise<PwBrowserContext> }
|
|
257
|
-
).newContext({
|
|
258
|
-
viewport: { width: 1280, height: 720 },
|
|
259
|
-
userAgent:
|
|
260
|
-
"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",
|
|
261
|
-
})
|
|
262
|
-
: (browser.contexts()[0] ??
|
|
263
|
-
(() => {
|
|
264
|
-
throw new Error("No browser context available");
|
|
265
|
-
})());
|
|
266
|
-
|
|
267
|
-
const page = (context as unknown as { pages: () => PwPage[] }).pages?.().length
|
|
268
|
-
? (context as unknown as { pages: () => PwPage[] }).pages()[0]!
|
|
269
|
-
: await context.newPage();
|
|
270
|
-
|
|
271
|
-
wirePageListeners(page);
|
|
272
|
-
|
|
273
|
-
// Persist session state before first navigation so launch+goto timeout
|
|
274
|
-
// cannot leave the tool in a "no session" state.
|
|
275
|
-
currentSession = { browser, context, page };
|
|
276
|
-
currentRefs = {};
|
|
277
|
-
consoleMessages.length = 0;
|
|
278
|
-
networkRequests.length = 0;
|
|
279
|
-
pageErrors.length = 0;
|
|
280
|
-
nextRequestId = 0;
|
|
281
|
-
|
|
282
|
-
if (options?.url) {
|
|
283
|
-
try {
|
|
284
|
-
await page.goto(options.url, DEFAULT_NAVIGATION_OPTIONS);
|
|
285
|
-
} catch (error) {
|
|
286
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
287
|
-
throw new Error(
|
|
288
|
-
`Browser launched, but initial navigation to ${options.url} failed: ${message}. Session remains active; use 'snapshot' or retry 'navigate'.`,
|
|
289
|
-
);
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
return currentSession;
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
/**
|
|
297
|
-
* Close the current browser session and clean up all state.
|
|
298
|
-
*/
|
|
299
|
-
export async function closeBrowser(): Promise<void> {
|
|
300
|
-
const session = currentSession;
|
|
301
|
-
currentSession = null;
|
|
302
|
-
currentRefs = {};
|
|
303
|
-
consoleMessages.length = 0;
|
|
304
|
-
networkRequests.length = 0;
|
|
305
|
-
pageErrors.length = 0;
|
|
306
|
-
nextRequestId = 0;
|
|
307
|
-
|
|
308
|
-
if (session) {
|
|
309
|
-
try {
|
|
310
|
-
await session.browser.close();
|
|
311
|
-
} catch {
|
|
312
|
-
// Best-effort close.
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
// ── Tab management ────────────────────────────────────────────────────
|
|
318
|
-
|
|
319
|
-
/**
|
|
320
|
-
* List all open tabs (pages) in the current context.
|
|
321
|
-
*/
|
|
322
|
-
export function listTabs(): Array<{ index: number; url: string; active: boolean }> {
|
|
323
|
-
if (!currentSession) {
|
|
324
|
-
return [];
|
|
325
|
-
}
|
|
326
|
-
const pages = currentSession.context.pages();
|
|
327
|
-
return pages.map((p, i) => ({
|
|
328
|
-
index: i,
|
|
329
|
-
url: (p as PwPage).url(),
|
|
330
|
-
active: p === currentSession!.page,
|
|
331
|
-
}));
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
/**
|
|
335
|
-
* Open a new tab, optionally navigating to a URL.
|
|
336
|
-
*/
|
|
337
|
-
export async function newTab(url?: string): Promise<{ index: number; url: string }> {
|
|
338
|
-
if (!currentSession) {
|
|
339
|
-
const launched = await launchBrowser({ url });
|
|
340
|
-
return { index: 0, url: launched.page.url() };
|
|
341
|
-
}
|
|
342
|
-
const page = await currentSession.context.newPage();
|
|
343
|
-
wirePageListeners(page as PwPage);
|
|
344
|
-
currentSession.page = page as PwPage;
|
|
345
|
-
currentRefs = {};
|
|
346
|
-
|
|
347
|
-
if (url) {
|
|
348
|
-
await (page as PwPage).goto(url, DEFAULT_NAVIGATION_OPTIONS);
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
const pages = currentSession.context.pages();
|
|
352
|
-
return { index: pages.length - 1, url: (page as PwPage).url() };
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
/**
|
|
356
|
-
* Switch to a tab by index.
|
|
357
|
-
*/
|
|
358
|
-
export async function selectTab(index: number): Promise<{ url: string }> {
|
|
359
|
-
if (!currentSession) {
|
|
360
|
-
await launchBrowser();
|
|
361
|
-
}
|
|
362
|
-
if (!currentSession) {
|
|
363
|
-
throw new Error("No tabs open.");
|
|
364
|
-
}
|
|
365
|
-
const pages = currentSession.context.pages();
|
|
366
|
-
if (index < 0 || index >= pages.length) {
|
|
367
|
-
throw new Error(`Tab index ${index} out of range (0..${pages.length - 1})`);
|
|
368
|
-
}
|
|
369
|
-
const page = pages[index] as PwPage;
|
|
370
|
-
currentSession.page = page;
|
|
371
|
-
wirePageListeners(page);
|
|
372
|
-
currentRefs = {};
|
|
373
|
-
return { url: page.url() };
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
/**
|
|
377
|
-
* Close a tab by index (defaults to current tab).
|
|
378
|
-
*/
|
|
379
|
-
export async function closeTab(index?: number): Promise<void> {
|
|
380
|
-
if (!currentSession) {
|
|
381
|
-
throw new Error("No tabs open.");
|
|
382
|
-
}
|
|
383
|
-
const pages = currentSession.context.pages();
|
|
384
|
-
const targetIndex = index ?? pages.indexOf(currentSession.page as never);
|
|
385
|
-
if (targetIndex < 0 || targetIndex >= pages.length) {
|
|
386
|
-
throw new Error(`Tab index ${targetIndex} out of range`);
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
const targetPage = pages[targetIndex] as PwPage;
|
|
390
|
-
await targetPage.close();
|
|
391
|
-
|
|
392
|
-
// Update current page if we closed the active one
|
|
393
|
-
const remaining = currentSession.context.pages();
|
|
394
|
-
if (!remaining.length) {
|
|
395
|
-
// All tabs closed — create a fresh one
|
|
396
|
-
const page = await currentSession.context.newPage();
|
|
397
|
-
currentSession.page = page as PwPage;
|
|
398
|
-
wirePageListeners(page as PwPage);
|
|
399
|
-
} else if (targetPage === currentSession.page) {
|
|
400
|
-
const newIndex = Math.min(targetIndex, remaining.length - 1);
|
|
401
|
-
currentSession.page = remaining[newIndex] as PwPage;
|
|
402
|
-
wirePageListeners(currentSession.page);
|
|
403
|
-
}
|
|
404
|
-
currentRefs = {};
|
|
405
|
-
}
|
|
@@ -1,85 +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
|
-
/**
|
|
6
|
-
* Shared utilities for Playwright-based browser tool functions.
|
|
7
|
-
* Ported from OpenClaw's pw-tools-core.shared.ts.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Parse a raw ref string into its canonical "eN" form.
|
|
12
|
-
* Accepts: "e1", "@e1", "ref=e1" -> "e1". Returns null if invalid.
|
|
13
|
-
*/
|
|
14
|
-
export function parseRoleRef(raw: string): string | null {
|
|
15
|
-
const trimmed = raw.trim();
|
|
16
|
-
if (!trimmed) {
|
|
17
|
-
return null;
|
|
18
|
-
}
|
|
19
|
-
const normalized = trimmed.startsWith("@")
|
|
20
|
-
? trimmed.slice(1)
|
|
21
|
-
: trimmed.startsWith("ref=")
|
|
22
|
-
? trimmed.slice(4)
|
|
23
|
-
: trimmed;
|
|
24
|
-
return /^e\d+$/.test(normalized) ? normalized : null;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Validate and normalize a ref string. Throws if the ref is empty/invalid.
|
|
29
|
-
*/
|
|
30
|
-
export function requireRef(value: unknown): string {
|
|
31
|
-
const raw = typeof value === "string" ? value.trim() : "";
|
|
32
|
-
const roleRef = raw ? parseRoleRef(raw) : null;
|
|
33
|
-
const ref = roleRef ?? (raw.startsWith("@") ? raw.slice(1) : raw);
|
|
34
|
-
if (!ref) {
|
|
35
|
-
throw new Error("ref is required");
|
|
36
|
-
}
|
|
37
|
-
return ref;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Clamp a timeout value to a safe range (500ms .. 120s).
|
|
42
|
-
*/
|
|
43
|
-
export function normalizeTimeoutMs(timeoutMs: number | undefined, fallback: number): number {
|
|
44
|
-
return Math.max(500, Math.min(120_000, timeoutMs ?? fallback));
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Rewrite Playwright errors into messages that guide the LLM to take
|
|
49
|
-
* corrective action (re-snapshot, scroll, etc.).
|
|
50
|
-
*/
|
|
51
|
-
export function toAIFriendlyError(error: unknown, selector: string): Error {
|
|
52
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
53
|
-
|
|
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(
|
|
58
|
-
`Selector "${selector}" matched ${count} elements. ` +
|
|
59
|
-
`Run a new snapshot to get updated refs, or use a different ref.`,
|
|
60
|
-
);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
if (
|
|
64
|
-
(message.includes("Timeout") || message.includes("waiting for")) &&
|
|
65
|
-
(message.includes("to be visible") || message.includes("not visible"))
|
|
66
|
-
) {
|
|
67
|
-
return new Error(
|
|
68
|
-
`Element "${selector}" not found or not visible. ` +
|
|
69
|
-
`Run a new snapshot to see current page elements.`,
|
|
70
|
-
);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
if (
|
|
74
|
-
message.includes("intercepts pointer events") ||
|
|
75
|
-
message.includes("not visible") ||
|
|
76
|
-
message.includes("not receive pointer events")
|
|
77
|
-
) {
|
|
78
|
-
return new Error(
|
|
79
|
-
`Element "${selector}" is not interactable (hidden or covered). ` +
|
|
80
|
-
`Try scrolling it into view, closing overlays, or re-snapshotting.`,
|
|
81
|
-
);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
return error instanceof Error ? error : new Error(message);
|
|
85
|
-
}
|