@particle-academy/agent-integrations 0.47.0 → 0.47.1
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/CHANGELOG.md +50 -0
- package/README.md +10 -1
- package/dist/bridges/navigation.d.cts +16 -3
- package/dist/bridges/navigation.d.ts +16 -3
- package/dist/bridges-navigation.cjs +67 -21
- package/dist/bridges-navigation.cjs.map +1 -1
- package/dist/bridges-navigation.js +1 -1
- package/dist/{chunk-JGJHPH65.js → chunk-OHNGURUJ.js} +69 -23
- package/dist/chunk-OHNGURUJ.js.map +1 -0
- package/dist/dom-navigation/index.d.cts +19 -8
- package/dist/dom-navigation/index.d.ts +19 -8
- package/dist/dom-navigation-script.cjs +1 -1
- package/dist/dom-navigation-script.cjs.map +1 -1
- package/dist/dom-navigation-script.js +1 -1
- package/dist/dom-navigation-script.js.map +1 -1
- package/dist/dom-navigation.cjs +23 -5
- package/dist/dom-navigation.cjs.map +1 -1
- package/dist/dom-navigation.js +23 -5
- package/dist/dom-navigation.js.map +1 -1
- package/dist/index.cjs +67 -21
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -2
- package/package.json +1 -1
- package/dist/chunk-JGJHPH65.js.map +0 -1
|
@@ -4,6 +4,22 @@ import { textResult, errorResult } from './chunk-CZV3WUW5.js';
|
|
|
4
4
|
|
|
5
5
|
// src/bridges/navigation.ts
|
|
6
6
|
var DEFAULT_AGENT = { id: "agent", name: "Agent", color: "#a855f7" };
|
|
7
|
+
var isControl = (code) => code < 32 || code >= 127 && code <= 159 || code === 8232 || code === 8233;
|
|
8
|
+
function oneLine(value, max) {
|
|
9
|
+
const raw = typeof value === "string" ? value : value == null ? "" : String(value);
|
|
10
|
+
const bounded = raw.length > max * 4 ? raw.slice(0, max * 4) : raw;
|
|
11
|
+
let out = "";
|
|
12
|
+
for (const c of bounded) out += isControl(c.charCodeAt(0)) ? " " : c;
|
|
13
|
+
out = out.replace(/\s+/g, " ").trim();
|
|
14
|
+
return out.length > max ? out.slice(0, max - 3) + "..." : out;
|
|
15
|
+
}
|
|
16
|
+
var SAFE_HANDLE = /^[A-Za-z0-9_.:#@/-]{1,80}$/;
|
|
17
|
+
var CAP = { url: 500, title: 200, role: 40, label: 200, heading: 200, text: 4e3, error: 300, headings: 50 };
|
|
18
|
+
function formatReadout(r) {
|
|
19
|
+
if (typeof r === "string") return oneLine(r, CAP.text);
|
|
20
|
+
const headings = (Array.isArray(r.headings) ? r.headings : []).slice(0, CAP.headings).map((h) => `H${Math.min(6, Math.max(1, Math.trunc(Number(h?.level)) || 1))}: ${oneLine(h?.text, CAP.heading)}`);
|
|
21
|
+
return [oneLine(r.title, CAP.title), ...headings, "", oneLine(r.text, CAP.text)].join("\n");
|
|
22
|
+
}
|
|
7
23
|
function registerNavigationBridge(host, options) {
|
|
8
24
|
const { adapter } = options;
|
|
9
25
|
const agent = { ...DEFAULT_AGENT, ...options.agent ?? {} };
|
|
@@ -20,6 +36,9 @@ function registerNavigationBridge(host, options) {
|
|
|
20
36
|
}
|
|
21
37
|
return null;
|
|
22
38
|
};
|
|
39
|
+
let aliases = /* @__PURE__ */ new Map();
|
|
40
|
+
const pageHandle = (handle) => aliases.get(handle) ?? handle;
|
|
41
|
+
const failure = (message, fallback) => errorResult(oneLine(message ?? fallback, CAP.error) || fallback);
|
|
23
42
|
ensureUndoToolsRegistered(host, { defaultAgentId: agent.id });
|
|
24
43
|
const target = (label, elementId) => ({
|
|
25
44
|
kind: "navigation",
|
|
@@ -32,7 +51,7 @@ function registerNavigationBridge(host, options) {
|
|
|
32
51
|
try {
|
|
33
52
|
return await handler(args);
|
|
34
53
|
} catch (e) {
|
|
35
|
-
return
|
|
54
|
+
return failure(e instanceof Error ? e.message : String(e), `${name} failed`);
|
|
36
55
|
}
|
|
37
56
|
};
|
|
38
57
|
const final = activity ? wrapToolWithActivity(wrapped, {
|
|
@@ -59,17 +78,29 @@ function registerNavigationBridge(host, options) {
|
|
|
59
78
|
{},
|
|
60
79
|
[],
|
|
61
80
|
async () => {
|
|
62
|
-
const
|
|
81
|
+
const raw = await adapter.describe();
|
|
82
|
+
const next = /* @__PURE__ */ new Map();
|
|
83
|
+
const actions = (Array.isArray(raw.actions) ? raw.actions : []).map((a) => {
|
|
84
|
+
const handle = String(a.handle ?? "");
|
|
85
|
+
if (SAFE_HANDLE.test(handle)) return a;
|
|
86
|
+
const alias = `~${next.size}`;
|
|
87
|
+
next.set(alias, handle);
|
|
88
|
+
return { ...a, handle: alias };
|
|
89
|
+
});
|
|
90
|
+
aliases = next;
|
|
91
|
+
const snap = { ...raw, actions };
|
|
63
92
|
const revision = await adapter.getRevision?.();
|
|
64
93
|
if (revision !== void 0) {
|
|
65
94
|
snap.revision = revision;
|
|
66
95
|
groundedRevision = revision;
|
|
67
96
|
}
|
|
68
97
|
const text = [
|
|
69
|
-
`URL: ${snap.url}`,
|
|
70
|
-
`Title: ${snap.title}`,
|
|
98
|
+
`URL: ${oneLine(snap.url, CAP.url)}`,
|
|
99
|
+
`Title: ${oneLine(snap.title, CAP.title)}`,
|
|
71
100
|
"",
|
|
72
|
-
...
|
|
101
|
+
...actions.map(
|
|
102
|
+
(a) => `[${a.handle}] ${oneLine(a.role, CAP.role)}: ${oneLine(a.label, CAP.label)}${a.destructive ? " (destructive)" : ""}`
|
|
103
|
+
)
|
|
73
104
|
].join("\n");
|
|
74
105
|
return textResult(text, snap);
|
|
75
106
|
},
|
|
@@ -80,7 +111,10 @@ function registerNavigationBridge(host, options) {
|
|
|
80
111
|
"Read the page's visible text / heading outline for grounding.",
|
|
81
112
|
{},
|
|
82
113
|
[],
|
|
83
|
-
async () =>
|
|
114
|
+
async () => {
|
|
115
|
+
const r = adapter.read ? await adapter.read() : void 0;
|
|
116
|
+
return textResult(r == null ? "(host did not provide page text)" : formatReadout(r));
|
|
117
|
+
},
|
|
84
118
|
() => target("Read page")
|
|
85
119
|
);
|
|
86
120
|
reg(
|
|
@@ -91,11 +125,12 @@ function registerNavigationBridge(host, options) {
|
|
|
91
125
|
async (args) => {
|
|
92
126
|
const stale = await staleIntent();
|
|
93
127
|
if (stale) return stale;
|
|
94
|
-
const
|
|
128
|
+
const shown = String(args.handle ?? "");
|
|
129
|
+
const handle = pageHandle(shown);
|
|
95
130
|
const action = (await adapter.describe()).actions.find((candidate) => candidate.handle === handle);
|
|
96
|
-
if (!action) return
|
|
97
|
-
return textResult(`Focused ${
|
|
98
|
-
handle,
|
|
131
|
+
if (!action) return failure(`No element for handle "${shown}"`, "No element for that handle");
|
|
132
|
+
return textResult(`Focused ${oneLine(shown, CAP.label)}`, {
|
|
133
|
+
handle: shown,
|
|
99
134
|
rect: await adapter.rectFor?.(handle) ?? void 0
|
|
100
135
|
});
|
|
101
136
|
},
|
|
@@ -175,13 +210,17 @@ function registerNavigationBridge(host, options) {
|
|
|
175
210
|
async (args) => {
|
|
176
211
|
const stale = await staleIntent();
|
|
177
212
|
if (stale) return stale;
|
|
178
|
-
const
|
|
213
|
+
const shown = typeof args.handle === "string" ? args.handle : void 0;
|
|
214
|
+
const handle = shown === void 0 ? void 0 : pageHandle(shown);
|
|
179
215
|
await adapter.scrollTo({
|
|
180
216
|
handle,
|
|
181
217
|
x: typeof args.x === "number" ? args.x : void 0,
|
|
182
218
|
y: typeof args.y === "number" ? args.y : void 0
|
|
183
219
|
});
|
|
184
|
-
return textResult(
|
|
220
|
+
return textResult(
|
|
221
|
+
"Scrolled",
|
|
222
|
+
handle ? { handle: shown, rect: await adapter.rectFor?.(handle) ?? void 0 } : void 0
|
|
223
|
+
);
|
|
185
224
|
},
|
|
186
225
|
() => target("Scroll")
|
|
187
226
|
);
|
|
@@ -209,10 +248,15 @@ function registerNavigationBridge(host, options) {
|
|
|
209
248
|
async (args) => {
|
|
210
249
|
const stale = await staleIntent();
|
|
211
250
|
if (stale) return stale;
|
|
212
|
-
const
|
|
251
|
+
const shown = String(args.handle ?? "");
|
|
252
|
+
const handle = pageHandle(shown);
|
|
213
253
|
const res = await adapter.setField(handle, args.value);
|
|
214
|
-
if (!res.ok) return
|
|
215
|
-
return textResult(`${
|
|
254
|
+
if (!res.ok) return failure(res.error, `Could not set ${oneLine(shown, CAP.label)}`);
|
|
255
|
+
return textResult(`${oneLine(shown, CAP.label)} \u2190 ${JSON.stringify(args.value)}`, {
|
|
256
|
+
handle: shown,
|
|
257
|
+
value: args.value,
|
|
258
|
+
rect: await adapter.rectFor?.(handle) ?? void 0
|
|
259
|
+
});
|
|
216
260
|
},
|
|
217
261
|
(args) => target(`Set ${String(args.handle ?? "")}`, String(args.handle ?? ""))
|
|
218
262
|
);
|
|
@@ -224,7 +268,8 @@ function registerNavigationBridge(host, options) {
|
|
|
224
268
|
async (args) => {
|
|
225
269
|
const stale = await staleIntent();
|
|
226
270
|
if (stale) return stale;
|
|
227
|
-
const
|
|
271
|
+
const shown = String(args.handle ?? "");
|
|
272
|
+
const handle = pageHandle(shown);
|
|
228
273
|
const action = (await adapter.describe()).actions.find((a) => a.handle === handle);
|
|
229
274
|
const rect = await adapter.rectFor?.(handle) ?? void 0;
|
|
230
275
|
if (pendingMode && action?.destructive && adapter.confirm) {
|
|
@@ -232,8 +277,8 @@ function registerNavigationBridge(host, options) {
|
|
|
232
277
|
if (!ok) return errorResult("Declined by user");
|
|
233
278
|
}
|
|
234
279
|
const res = await adapter.click(handle);
|
|
235
|
-
if (!res.ok) return
|
|
236
|
-
return textResult(`Clicked ${
|
|
280
|
+
if (!res.ok) return failure(res.error, `Could not click ${oneLine(shown, CAP.label)}`);
|
|
281
|
+
return textResult(`Clicked ${oneLine(shown, CAP.label)}`, { handle: shown, rect });
|
|
237
282
|
},
|
|
238
283
|
(args) => target(`Click ${String(args.handle ?? "")}`, String(args.handle ?? ""))
|
|
239
284
|
);
|
|
@@ -245,15 +290,16 @@ function registerNavigationBridge(host, options) {
|
|
|
245
290
|
async (args) => {
|
|
246
291
|
const stale = await staleIntent();
|
|
247
292
|
if (stale) return stale;
|
|
248
|
-
const
|
|
293
|
+
const shown = String(args.handle ?? "");
|
|
294
|
+
const handle = pageHandle(shown);
|
|
249
295
|
const rect = await adapter.rectFor?.(handle) ?? void 0;
|
|
250
296
|
if (pendingMode && adapter.confirm) {
|
|
251
297
|
const ok = await adapter.confirm({ action: "submit", handle, label: handle });
|
|
252
298
|
if (!ok) return errorResult("Declined by user");
|
|
253
299
|
}
|
|
254
300
|
const res = await adapter.submit(handle);
|
|
255
|
-
if (!res.ok) return
|
|
256
|
-
return textResult(`Submitted ${
|
|
301
|
+
if (!res.ok) return failure(res.error, "Submit failed");
|
|
302
|
+
return textResult(`Submitted ${oneLine(shown, CAP.label)}`, { handle: shown, rect });
|
|
257
303
|
},
|
|
258
304
|
(args) => target(`Submit ${String(args.handle ?? "")}`, String(args.handle ?? ""))
|
|
259
305
|
);
|
|
@@ -267,5 +313,5 @@ function registerNavigationBridge(host, options) {
|
|
|
267
313
|
}
|
|
268
314
|
|
|
269
315
|
export { registerNavigationBridge };
|
|
270
|
-
//# sourceMappingURL=chunk-
|
|
271
|
-
//# sourceMappingURL=chunk-
|
|
316
|
+
//# sourceMappingURL=chunk-OHNGURUJ.js.map
|
|
317
|
+
//# sourceMappingURL=chunk-OHNGURUJ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/bridges/navigation.ts"],"names":[],"mappings":";;;;;AAgHA,IAAM,gBAAgB,EAAE,EAAA,EAAI,SAAS,IAAA,EAAM,OAAA,EAAS,OAAO,SAAA,EAAU;AAYrE,IAAM,SAAA,GAAY,CAAC,IAAA,KACjB,IAAA,GAAO,EAAA,IAAS,IAAA,IAAQ,GAAA,IAAQ,IAAA,IAAQ,GAAA,IAAS,IAAA,KAAS,IAAA,IAAU,IAAA,KAAS,IAAA;AAG/E,SAAS,OAAA,CAAQ,OAAgB,GAAA,EAAqB;AACpD,EAAA,MAAM,GAAA,GAAM,OAAO,KAAA,KAAU,QAAA,GAAW,QAAQ,KAA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J,KAAA,EAAO,aAAA;AAAA,IACP,SAAS,MAAM;AACb,MAAA,KAAA,MAAW,CAAA,IAAK,WAAW,CAAA,EAAE;AAAA,IAC/B;AAAA,GACF;AACF","file":"chunk-OHNGURUJ.js","sourcesContent":["import { textResult, errorResult } from \"../mcp/server\";\nimport type { ToolHost } from \"../mcp/tool-host\";\nimport type { JsonObject } from \"../mcp/types\";\nimport type { Bridge } from \"./types\";\nimport { wrapToolWithActivity } from \"../presence/wrap-tool-with-activity\";\nimport type { AgentTarget } from \"../presence/types\";\nimport { pushUndoEntry } from \"../undo/undo-stack\";\nimport { ensureUndoToolsRegistered } from \"../undo/undo-tools\";\n\n/**\n * One interactive element the agent can act on, addressed by a STABLE handle\n * (not a CSS selector) so the agent drives the page the Human+ way — never DOM\n * scraping. The host builds these in `describe()` (data-co-handle → name/id →\n * ARIA role + accessible name).\n */\nexport type PageAction = {\n /** Stable, opaque handle the agent passes back to act on this element. */\n handle: string;\n /** ARIA-ish role: \"link\" | \"button\" | \"textbox\" | \"checkbox\" | \"select\" | … */\n role: string;\n /** Accessible name / label. */\n label: string;\n /** Current value for inputs (omitted/masked for sensitive fields). */\n value?: unknown;\n /** True when activating this is destructive / submits (agent should stage). */\n destructive?: boolean;\n};\n\n/** The page as the agent sees it: where it is + what it can do. */\nexport type PageSnapshot = {\n url: string;\n title: string;\n actions: PageAction[];\n /** Monotonic host revision. Human input advances it and invalidates stale agent intent. */\n revision?: number;\n};\n\n/**\n * Structured page text. Preferred over a plain string from `read()`: the bridge\n * can then put every page-supplied string on its own single line and keep the\n * outline. A plain string is untrusted as a whole and is rendered as ONE line.\n */\nexport type PageReadout = {\n title: string;\n headings: Array<{ level: number; text: string }>;\n text: string;\n};\n\n/** A write the host may want the human to confirm (trust-but-verify). */\nexport type NavigationConfirmRequest = {\n action: \"submit\" | \"click\";\n handle: string;\n label: string;\n};\n\ntype MaybePromise<T> = T | Promise<T>;\n\n/**\n * Host-provided adapter. In the sandbox this is backed by Inertia's `router` +\n * the DOM walker from `@particle-academy/agent-integrations/dom-navigation`.\n * Every method works on stable handles, never raw selectors.\n *\n * Any method may return a Promise: a host driving a page it does not run in\n * (an Electron WebContentsView, via `createRemoteNavigationAdapter`) can only\n * answer asynchronously. The bridge awaits every call.\n */\nexport type NavigationBridgeAdapter = {\n /** Optional fancy-screens screen id for presence targeting. */\n screenId?: string;\n /** Current location. */\n getLocation: () => MaybePromise<{ url: string; title: string }>;\n /** Current human-control revision. Omit to disable stale-intent protection. */\n getRevision?: () => MaybePromise<number>;\n /** Snapshot of the page's actionable elements (stable handles + labels). */\n describe: () => MaybePromise<PageSnapshot>;\n /** Visible text / heading outline for grounding (optional). Prefer a {@link PageReadout}. */\n read?: () => MaybePromise<string | PageReadout>;\n /** Navigate to a URL (host wires to router.visit). */\n visit: (url: string) => void | Promise<void>;\n back?: () => void | Promise<void>;\n forward?: () => void | Promise<void>;\n /** Scroll to coords or to a handle's element. */\n scrollTo: (opts: { x?: number; y?: number; handle?: string }) => void | Promise<void>;\n scrollBy: (dy: number) => void | Promise<void>;\n /** Set a field's value by handle (host dispatches input/change for React). */\n setField: (handle: string, value: unknown) => MaybePromise<{ ok: boolean; error?: string }>;\n /** Activate an element by handle. */\n click: (handle: string) => MaybePromise<{ ok: boolean; error?: string }>;\n /** Submit a form by handle. */\n submit: (handle: string) => Promise<{ ok: boolean; error?: string }> | { ok: boolean; error?: string };\n /**\n * Viewport rect of a handle's element, for agent-presence rendering (cursor +\n * highlight). Returned in tool `meta.rect` so `<CoBrowseCursorLayer>` can show\n * the agent acting on the page. Optional — omit and there's just no cursor.\n */\n rectFor?: (handle: string) => MaybePromise<{ x: number; y: number; width: number; height: number } | null>;\n /**\n * Trust-but-verify hook. When `pendingMode` is on, `page_submit` and\n * destructive `page_click` route through this; the host shows a prompt and\n * resolves true (proceed) / false (declined).\n */\n confirm?: (req: NavigationConfirmRequest) => Promise<boolean>;\n};\n\nexport type NavigationBridgeOptions = {\n adapter: NavigationBridgeAdapter;\n /** Identity tagged into activity events (so the human sees who's driving). */\n agent?: { id: string; name?: string; color?: string };\n /** Route submit + destructive clicks through `adapter.confirm`. Default true. */\n pendingMode?: boolean;\n};\n\nconst DEFAULT_AGENT = { id: \"agent\", name: \"Agent\", color: \"#a855f7\" };\n\n// ───────────── Text safety ─────────────\n//\n// Every string below the adapter is page-supplied, and the page may be hostile.\n// The tool TEXT is what lands in the agent's context, so a line break inside a\n// label would let the page write its own lines there: a forged action, a forged\n// heading, forged tool framing. Each page string is therefore rendered on ONE\n// line, with C0/C1 controls and the Unicode line/paragraph separators replaced,\n// and capped. (Control characters are tested by code point, so no escape\n// sequence is involved.)\n\nconst isControl = (code: number) =>\n code < 0x20 || (code >= 0x7f && code <= 0x9f) || code === 0x2028 || code === 0x2029;\n\n/** One line, controls replaced by spaces, whitespace collapsed, capped at `max`. */\nfunction oneLine(value: unknown, max: number): string {\n const raw = typeof value === \"string\" ? value : value == null ? \"\" : String(value);\n // Bound the work on a hostile multi-megabyte string before scanning it.\n const bounded = raw.length > max * 4 ? raw.slice(0, max * 4) : raw;\n let out = \"\";\n for (const c of bounded) out += isControl(c.charCodeAt(0)) ? \" \" : c;\n out = out.replace(/\\s+/g, \" \").trim();\n return out.length > max ? out.slice(0, max - 3) + \"...\" : out;\n}\n\n/**\n * A handle shown verbatim must not be able to imitate the `[handle] role:`\n * syntax, so only this charset is shown as-is. Anything else — spaces,\n * brackets, controls, or a `~`, which is reserved so a page cannot squat on an\n * alias — is shown as a bridge-minted `~N` alias that resolves back to it.\n */\nconst SAFE_HANDLE = /^[A-Za-z0-9_.:#@/-]{1,80}$/;\n\nconst CAP = { url: 500, title: 200, role: 40, label: 200, heading: 200, text: 4000, error: 300, headings: 50 };\n\nfunction formatReadout(r: string | PageReadout): string {\n if (typeof r === \"string\") return oneLine(r, CAP.text);\n const headings = (Array.isArray(r.headings) ? r.headings : [])\n .slice(0, CAP.headings)\n .map((h) => `H${Math.min(6, Math.max(1, Math.trunc(Number(h?.level)) || 1))}: ${oneLine(h?.text, CAP.heading)}`);\n return [oneLine(r.title, CAP.title), ...headings, \"\", oneLine(r.text, CAP.text)].join(\"\\n\");\n}\n\n/**\n * registerNavigationBridge — site-wide co-browsing. Lets a connected agent\n * navigate, scroll, and (with staged confirm) fill + click any page, addressed\n * by stable handles. Pairs with `useCoBrowseSession` (server + relay) and\n * `<CoBrowsePresence>` (the human's view of the agent). The 12th Fancy bridge.\n */\nexport function registerNavigationBridge(\n host: ToolHost,\n options: NavigationBridgeOptions,\n): Bridge {\n const { adapter } = options;\n const agent = { ...DEFAULT_AGENT, ...(options.agent ?? {}) };\n const pendingMode = options.pendingMode ?? true;\n const disposers: Array<() => void> = [];\n let groundedRevision: number | null = null;\n\n const staleIntent = async () => {\n const current = await adapter.getRevision?.();\n if (current === undefined) return null;\n if (groundedRevision === null || groundedRevision !== current) {\n return errorResult(\n `Human took control at page revision ${current}. This agent action was cancelled; call page_describe before acting again.`,\n );\n }\n return null;\n };\n\n /** Alias → page handle, from the latest page_describe. */\n let aliases = new Map<string, string>();\n /** The handle the adapter knows, for a handle the agent passed back. */\n const pageHandle = (handle: string) => aliases.get(handle) ?? handle;\n /** A failure message that may carry page-supplied text. */\n const failure = (message: unknown, fallback: string) => errorResult(oneLine(message ?? fallback, CAP.error) || fallback);\n\n ensureUndoToolsRegistered(host, { defaultAgentId: agent.id });\n\n const target = (label: string, elementId?: string): AgentTarget => ({\n kind: \"navigation\",\n screenId: adapter.screenId,\n elementId,\n label,\n });\n\n const reg = (\n name: string,\n description: string,\n properties: Record<string, unknown>,\n required: string[],\n handler: (args: JsonObject) => Promise<any> | any,\n activity: false | ((args: JsonObject) => AgentTarget),\n ) => {\n const wrapped = async (args: JsonObject) => {\n try {\n return await handler(args);\n } catch (e) {\n // A transport into the page can surface the page's own error text.\n return failure(e instanceof Error ? e.message : String(e), `${name} failed`);\n }\n };\n const final = activity\n ? wrapToolWithActivity(wrapped, {\n toolName: name,\n agent: { id: agent.id, name: agent.name, color: agent.color },\n kind: \"navigation\",\n screenId: adapter.screenId,\n resolveTarget: ({ args }) => activity(args),\n })\n : wrapped;\n disposers.push(\n host.registerTool(\n {\n name,\n description,\n inputSchema: { type: \"object\", properties: properties as any, required, additionalProperties: false },\n },\n final as any,\n ),\n );\n };\n\n // ───────────── Read ─────────────\n\n reg(\n \"page_describe\",\n \"Describe the current page: its URL, title, and the interactive elements you can act on (each with a stable `handle`, role, and label). Call this first, and again after navigating.\",\n {},\n [],\n async () => {\n const raw = await adapter.describe();\n const next = new Map<string, string>();\n const actions = (Array.isArray(raw.actions) ? raw.actions : []).map((a) => {\n const handle = String(a.handle ?? \"\");\n if (SAFE_HANDLE.test(handle)) return a;\n const alias = `~${next.size}`;\n next.set(alias, handle);\n return { ...a, handle: alias };\n });\n aliases = next;\n const snap: PageSnapshot = { ...raw, actions };\n const revision = await adapter.getRevision?.();\n if (revision !== undefined) {\n snap.revision = revision;\n groundedRevision = revision;\n }\n const text = [\n `URL: ${oneLine(snap.url, CAP.url)}`,\n `Title: ${oneLine(snap.title, CAP.title)}`,\n \"\",\n ...actions.map(\n (a) =>\n `[${a.handle}] ${oneLine(a.role, CAP.role)}: ${oneLine(a.label, CAP.label)}${a.destructive ? \" (destructive)\" : \"\"}`,\n ),\n ].join(\"\\n\");\n return textResult(text, snap);\n },\n () => target(\"Inspect page\"),\n );\n\n reg(\n \"page_read\",\n \"Read the page's visible text / heading outline for grounding.\",\n {},\n [],\n async () => {\n const r = adapter.read ? await adapter.read() : undefined;\n return textResult(r == null ? \"(host did not provide page text)\" : formatReadout(r));\n },\n () => target(\"Read page\"),\n );\n\n reg(\n \"page_focus\",\n \"Move the agent's visible focus to an interactive element by stable handle without activating it.\",\n { handle: { type: \"string\" } },\n [\"handle\"],\n async (args) => {\n const stale = await staleIntent();\n if (stale) return stale;\n const shown = String(args.handle ?? \"\");\n const handle = pageHandle(shown);\n const action = (await adapter.describe()).actions.find((candidate) => candidate.handle === handle);\n if (!action) return failure(`No element for handle \"${shown}\"`, \"No element for that handle\");\n return textResult(`Focused ${oneLine(shown, CAP.label)}`, {\n handle: shown,\n rect: (await adapter.rectFor?.(handle)) ?? undefined,\n });\n },\n (args) => target(`Focus ${String(args.handle ?? \"\")}`, String(args.handle ?? \"\")),\n );\n\n // ───────────── Navigate / scroll ─────────────\n\n reg(\n \"nav_visit\",\n \"Navigate to a URL (same-site path or absolute). The human watches the page change.\",\n { url: { type: \"string\", description: \"Path like /packages or an absolute URL.\" } },\n [\"url\"],\n async (args) => {\n const stale = await staleIntent();\n if (stale) return stale;\n const url = String(args.url ?? \"\");\n if (!url) return errorResult(\"url is required\");\n // Scheme allow-list: permit only same-site/relative paths and http(s)\n // absolutes. A `javascript:` / `data:` / `file:` / `vbscript:` URL handed\n // to a host that wires visit() to window.location would execute as the\n // human — a semi-trusted agent (steerable via page_read prompt injection)\n // must not reach those.\n const scheme = /^([a-zA-Z][a-zA-Z0-9+.-]*):/.exec(url)?.[1]?.toLowerCase();\n if (scheme && scheme !== \"http\" && scheme !== \"https\") {\n return errorResult(\n `Refusing to navigate to a '${scheme}:' URL. Only http(s) URLs or same-site paths are allowed.`,\n );\n }\n const from = (await adapter.getLocation()).url;\n await adapter.visit(url);\n pushUndoEntry(agent.id, {\n timestamp: Date.now(),\n bridgeId: \"navigation\",\n action: \"nav_visit\",\n label: `Navigate to ${url}`,\n undo: () => {\n adapter.visit(from);\n },\n redo: () => {\n adapter.visit(url);\n },\n });\n return textResult(`Navigated to ${url}`, { url });\n },\n (args) => target(`Navigate → ${String(args.url ?? \"\")}`),\n );\n\n reg(\n \"nav_back\",\n \"Go back to the previous page.\",\n {},\n [],\n async () => {\n const stale = await staleIntent();\n if (stale) return stale;\n if (!adapter.back) return errorResult(\"Host did not provide back navigation.\");\n await adapter.back();\n return textResult(\"Went back\");\n },\n () => target(\"Back\"),\n );\n\n reg(\n \"nav_forward\",\n \"Go forward to the next page.\",\n {},\n [],\n async () => {\n const stale = await staleIntent();\n if (stale) return stale;\n if (!adapter.forward) return errorResult(\"Host did not provide forward navigation.\");\n await adapter.forward();\n return textResult(\"Went forward\");\n },\n () => target(\"Forward\"),\n );\n\n reg(\n \"nav_scroll_to\",\n \"Scroll the page to absolute coordinates, or to a specific element by its handle.\",\n {\n handle: { type: \"string\", description: \"Scroll this element into view.\" },\n x: { type: \"number\" },\n y: { type: \"number\" },\n },\n [],\n async (args) => {\n const stale = await staleIntent();\n if (stale) return stale;\n const shown = typeof args.handle === \"string\" ? args.handle : undefined;\n const handle = shown === undefined ? undefined : pageHandle(shown);\n await adapter.scrollTo({\n handle,\n x: typeof args.x === \"number\" ? args.x : undefined,\n y: typeof args.y === \"number\" ? args.y : undefined,\n });\n return textResult(\n \"Scrolled\",\n handle ? { handle: shown, rect: (await adapter.rectFor?.(handle)) ?? undefined } : undefined,\n );\n },\n () => target(\"Scroll\"),\n );\n\n reg(\n \"nav_scroll_by\",\n \"Scroll the page by a vertical delta in pixels (negative scrolls up).\",\n { dy: { type: \"number\" } },\n [\"dy\"],\n async (args) => {\n const stale = await staleIntent();\n if (stale) return stale;\n await adapter.scrollBy(Number(args.dy ?? 0));\n return textResult(`Scrolled by ${Number(args.dy ?? 0)}px`);\n },\n () => target(\"Scroll\"),\n );\n\n // ───────────── Co-drive (fill / click / submit) ─────────────\n\n reg(\n \"page_set_field\",\n \"Set a form field's value by handle. The host updates the controlled input and the human sees it change.\",\n {\n handle: { type: \"string\" },\n value: { description: \"Value to set; type matches the field.\" },\n },\n [\"handle\", \"value\"],\n async (args) => {\n const stale = await staleIntent();\n if (stale) return stale;\n const shown = String(args.handle ?? \"\");\n const handle = pageHandle(shown);\n const res = await adapter.setField(handle, args.value);\n if (!res.ok) return failure(res.error, `Could not set ${oneLine(shown, CAP.label)}`);\n return textResult(`${oneLine(shown, CAP.label)} ← ${JSON.stringify(args.value)}`, {\n handle: shown,\n value: args.value,\n rect: (await adapter.rectFor?.(handle)) ?? undefined,\n });\n },\n (args) => target(`Set ${String(args.handle ?? \"\")}`, String(args.handle ?? \"\")),\n );\n\n reg(\n \"page_click\",\n \"Activate an element by handle (link, button, checkbox…). Destructive elements are staged for the human to confirm.\",\n { handle: { type: \"string\" } },\n [\"handle\"],\n async (args) => {\n const stale = await staleIntent();\n if (stale) return stale;\n const shown = String(args.handle ?? \"\");\n const handle = pageHandle(shown);\n const action = (await adapter.describe()).actions.find((a) => a.handle === handle);\n const rect = (await adapter.rectFor?.(handle)) ?? undefined; // capture before the click may navigate away\n if (pendingMode && action?.destructive && adapter.confirm) {\n const ok = await adapter.confirm({ action: \"click\", handle, label: action.label });\n if (!ok) return errorResult(\"Declined by user\");\n }\n const res = await adapter.click(handle);\n if (!res.ok) return failure(res.error, `Could not click ${oneLine(shown, CAP.label)}`);\n return textResult(`Clicked ${oneLine(shown, CAP.label)}`, { handle: shown, rect });\n },\n (args) => target(`Click ${String(args.handle ?? \"\")}`, String(args.handle ?? \"\")),\n );\n\n reg(\n \"page_submit\",\n \"Submit a form by handle. Always staged for the human to confirm when pendingMode is on.\",\n { handle: { type: \"string\" } },\n [\"handle\"],\n async (args) => {\n const stale = await staleIntent();\n if (stale) return stale;\n const shown = String(args.handle ?? \"\");\n const handle = pageHandle(shown);\n const rect = (await adapter.rectFor?.(handle)) ?? undefined; // capture before the submit navigates\n if (pendingMode && adapter.confirm) {\n const ok = await adapter.confirm({ action: \"submit\", handle, label: handle });\n if (!ok) return errorResult(\"Declined by user\");\n }\n const res = await adapter.submit(handle);\n if (!res.ok) return failure(res.error, \"Submit failed\");\n return textResult(`Submitted ${oneLine(shown, CAP.label)}`, { handle: shown, rect });\n },\n (args) => target(`Submit ${String(args.handle ?? \"\")}`, String(args.handle ?? \"\")),\n );\n\n return {\n id: \"navigation\",\n title: \"Co-browsing\",\n dispose: () => {\n for (const d of disposers) d();\n },\n };\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PageSnapshot, NavigationConfirmRequest, NavigationBridgeAdapter } from '../bridges/navigation.cjs';
|
|
1
|
+
import { PageSnapshot, PageReadout, NavigationConfirmRequest, NavigationBridgeAdapter } from '../bridges/navigation.cjs';
|
|
2
2
|
export { PageAction } from '../bridges/navigation.cjs';
|
|
3
3
|
import '../tool-host-D67N2a2h.cjs';
|
|
4
4
|
import '../types-gzIpsUDE.cjs';
|
|
@@ -68,13 +68,24 @@ declare function walk(doc?: Document): {
|
|
|
68
68
|
registry: Map<string, Element>;
|
|
69
69
|
};
|
|
70
70
|
/**
|
|
71
|
-
* Set a field's value so a React-controlled input sees the change
|
|
72
|
-
*
|
|
73
|
-
*
|
|
71
|
+
* Set a field's value so a React-controlled input sees the change.
|
|
72
|
+
*
|
|
73
|
+
* - Text, textarea, select: call the PROTOTYPE `value` setter (React shadows
|
|
74
|
+
* `value` on the instance with its value tracker), then dispatch bubbling
|
|
75
|
+
* `input` + `change`.
|
|
76
|
+
* - Checkbox, radio: React's onChange for these listens to `click`, not
|
|
77
|
+
* `input` / `change`, so the write is a real `click()` — the browser toggles
|
|
78
|
+
* the box and fires click, input and change itself. Only when the state
|
|
79
|
+
* actually differs, so setting the current value is a no-op rather than a
|
|
80
|
+
* toggle. A radio cannot be unchecked by clicking it; that one case falls
|
|
81
|
+
* back to the setter.
|
|
74
82
|
*/
|
|
75
83
|
declare function setNativeValue(el: FieldElement, value: unknown): void;
|
|
76
|
-
/**
|
|
77
|
-
|
|
84
|
+
/**
|
|
85
|
+
* Visible text / heading outline, with sensitive text removed. Structured, so
|
|
86
|
+
* the bridge can render each page-supplied string on its own single line.
|
|
87
|
+
*/
|
|
88
|
+
declare function readPage(doc?: Document): PageReadout;
|
|
78
89
|
type DomNavigationAgentOptions = {
|
|
79
90
|
/** Document to drive. Default: the global `document`, read lazily. */
|
|
80
91
|
document?: Document;
|
|
@@ -92,7 +103,7 @@ type DomNavigationAgent = {
|
|
|
92
103
|
title: string;
|
|
93
104
|
};
|
|
94
105
|
describe(): PageSnapshot;
|
|
95
|
-
read():
|
|
106
|
+
read(): PageReadout;
|
|
96
107
|
/** Navigate. Only http(s) or same-site paths; deferred a tick so a remote call returns first. */
|
|
97
108
|
visit(url: string): void;
|
|
98
109
|
back(): void;
|
|
@@ -161,4 +172,4 @@ declare function domNavigationCallScript(method: DomNavigationMethod, args?: unk
|
|
|
161
172
|
/** Build a NavigationBridgeAdapter backed by a transport into the page. */
|
|
162
173
|
declare function createRemoteNavigationAdapter(options: RemoteNavigationAdapterOptions): NavigationBridgeAdapter;
|
|
163
174
|
|
|
164
|
-
export { type ActionResult, DOM_NAVIGATION_GLOBAL, DOM_NAVIGATION_METHODS, DOM_NAVIGATION_PROTOCOL, type DomNavigationAgent, type DomNavigationAgentOptions, type DomNavigationMethod, type DomNavigationTransport, type HandleRect, INTERACTIVE, NavigationBridgeAdapter, NavigationConfirmRequest, PageSnapshot, type RemoteNavigationAdapterOptions, accessibleName, attributeHandle, createDomNavigationAgent, createRemoteNavigationAdapter, domNavigationCallScript, isDestructive, isSensitive, isVisible, readPage, roleOf, setNativeValue, walk };
|
|
175
|
+
export { type ActionResult, DOM_NAVIGATION_GLOBAL, DOM_NAVIGATION_METHODS, DOM_NAVIGATION_PROTOCOL, type DomNavigationAgent, type DomNavigationAgentOptions, type DomNavigationMethod, type DomNavigationTransport, type HandleRect, INTERACTIVE, NavigationBridgeAdapter, NavigationConfirmRequest, PageReadout, PageSnapshot, type RemoteNavigationAdapterOptions, accessibleName, attributeHandle, createDomNavigationAgent, createRemoteNavigationAdapter, domNavigationCallScript, isDestructive, isSensitive, isVisible, readPage, roleOf, setNativeValue, walk };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PageSnapshot, NavigationConfirmRequest, NavigationBridgeAdapter } from '../bridges/navigation.js';
|
|
1
|
+
import { PageSnapshot, PageReadout, NavigationConfirmRequest, NavigationBridgeAdapter } from '../bridges/navigation.js';
|
|
2
2
|
export { PageAction } from '../bridges/navigation.js';
|
|
3
3
|
import '../tool-host-LYfdPE8u.js';
|
|
4
4
|
import '../types-gzIpsUDE.js';
|
|
@@ -68,13 +68,24 @@ declare function walk(doc?: Document): {
|
|
|
68
68
|
registry: Map<string, Element>;
|
|
69
69
|
};
|
|
70
70
|
/**
|
|
71
|
-
* Set a field's value so a React-controlled input sees the change
|
|
72
|
-
*
|
|
73
|
-
*
|
|
71
|
+
* Set a field's value so a React-controlled input sees the change.
|
|
72
|
+
*
|
|
73
|
+
* - Text, textarea, select: call the PROTOTYPE `value` setter (React shadows
|
|
74
|
+
* `value` on the instance with its value tracker), then dispatch bubbling
|
|
75
|
+
* `input` + `change`.
|
|
76
|
+
* - Checkbox, radio: React's onChange for these listens to `click`, not
|
|
77
|
+
* `input` / `change`, so the write is a real `click()` — the browser toggles
|
|
78
|
+
* the box and fires click, input and change itself. Only when the state
|
|
79
|
+
* actually differs, so setting the current value is a no-op rather than a
|
|
80
|
+
* toggle. A radio cannot be unchecked by clicking it; that one case falls
|
|
81
|
+
* back to the setter.
|
|
74
82
|
*/
|
|
75
83
|
declare function setNativeValue(el: FieldElement, value: unknown): void;
|
|
76
|
-
/**
|
|
77
|
-
|
|
84
|
+
/**
|
|
85
|
+
* Visible text / heading outline, with sensitive text removed. Structured, so
|
|
86
|
+
* the bridge can render each page-supplied string on its own single line.
|
|
87
|
+
*/
|
|
88
|
+
declare function readPage(doc?: Document): PageReadout;
|
|
78
89
|
type DomNavigationAgentOptions = {
|
|
79
90
|
/** Document to drive. Default: the global `document`, read lazily. */
|
|
80
91
|
document?: Document;
|
|
@@ -92,7 +103,7 @@ type DomNavigationAgent = {
|
|
|
92
103
|
title: string;
|
|
93
104
|
};
|
|
94
105
|
describe(): PageSnapshot;
|
|
95
|
-
read():
|
|
106
|
+
read(): PageReadout;
|
|
96
107
|
/** Navigate. Only http(s) or same-site paths; deferred a tick so a remote call returns first. */
|
|
97
108
|
visit(url: string): void;
|
|
98
109
|
back(): void;
|
|
@@ -161,4 +172,4 @@ declare function domNavigationCallScript(method: DomNavigationMethod, args?: unk
|
|
|
161
172
|
/** Build a NavigationBridgeAdapter backed by a transport into the page. */
|
|
162
173
|
declare function createRemoteNavigationAdapter(options: RemoteNavigationAdapterOptions): NavigationBridgeAdapter;
|
|
163
174
|
|
|
164
|
-
export { type ActionResult, DOM_NAVIGATION_GLOBAL, DOM_NAVIGATION_METHODS, DOM_NAVIGATION_PROTOCOL, type DomNavigationAgent, type DomNavigationAgentOptions, type DomNavigationMethod, type DomNavigationTransport, type HandleRect, INTERACTIVE, NavigationBridgeAdapter, NavigationConfirmRequest, PageSnapshot, type RemoteNavigationAdapterOptions, accessibleName, attributeHandle, createDomNavigationAgent, createRemoteNavigationAdapter, domNavigationCallScript, isDestructive, isSensitive, isVisible, readPage, roleOf, setNativeValue, walk };
|
|
175
|
+
export { type ActionResult, DOM_NAVIGATION_GLOBAL, DOM_NAVIGATION_METHODS, DOM_NAVIGATION_PROTOCOL, type DomNavigationAgent, type DomNavigationAgentOptions, type DomNavigationMethod, type DomNavigationTransport, type HandleRect, INTERACTIVE, NavigationBridgeAdapter, NavigationConfirmRequest, PageReadout, PageSnapshot, type RemoteNavigationAdapterOptions, accessibleName, attributeHandle, createDomNavigationAgent, createRemoteNavigationAdapter, domNavigationCallScript, isDestructive, isSensitive, isVisible, readPage, roleOf, setNativeValue, walk };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
// dom-navigation-inject:virtual:dom-navigation-inject
|
|
4
|
-
var virtual_dom_navigation_inject_default = '"use strict";\n(() => {\n // src/dom-navigation/agent.ts\n var INTERACTIVE = "a[href], button, input, select, textarea, [role=button], [role=link], [role=checkbox], [role=tab], [data-co-handle]";\n var tag = (el) => el.tagName.toUpperCase();\n function isVisible(el) {\n const he = el;\n if (el.type === "hidden") return false;\n if (he.hidden || he.getAttribute("aria-hidden") === "true") return false;\n return he.offsetParent !== null || he.getClientRects().length > 0;\n }\n function isSensitive(el) {\n const input = el;\n const ac = (el.getAttribute("autocomplete") ?? "").toLowerCase();\n return input.type === "password" || ac.startsWith("cc-") || ac === "one-time-code" || el.hasAttribute("data-private");\n }\n function insideSensitive(node) {\n for (let el = node.parentElement; el; el = el.parentElement) {\n if (isSensitive(el)) return true;\n }\n return false;\n }\n function safeText(root) {\n const doc = root.ownerDocument ?? root;\n const walker = doc.createTreeWalker(root, 4);\n let out = "";\n for (let n = walker.nextNode(); n; n = walker.nextNode()) {\n if (!insideSensitive(n)) out += n.nodeValue ?? "";\n }\n return out;\n }\n function roleOf(el) {\n const explicit = el.getAttribute("role");\n if (explicit) return explicit;\n const t = tag(el);\n if (t === "A") return "link";\n if (t === "BUTTON") return "button";\n if (t === "SELECT") return "select";\n if (t === "TEXTAREA") return "textbox";\n if (t === "INPUT") {\n const type = el.type;\n if (type === "checkbox") return "checkbox";\n if (type === "radio") return "radio";\n if (type === "submit" || type === "button") return "button";\n return "textbox";\n }\n return "generic";\n }\n function labelFor(doc, id) {\n for (const lbl of Array.from(doc.querySelectorAll("label[for]"))) {\n if (lbl.getAttribute("for") === id) return lbl;\n }\n return null;\n }\n function accessibleName(el) {\n const doc = el.ownerDocument;\n const aria = el.getAttribute("aria-label");\n if (aria) return aria.trim();\n const labelledby = el.getAttribute("aria-labelledby");\n if (labelledby) {\n const txt = labelledby.split(/\\s+/).map((id2) => doc.getElementById(id2)?.textContent ?? "").join(" ").trim();\n if (txt) return txt;\n }\n const id = el.getAttribute("id");\n if (id) {\n const lbl = labelFor(doc, id);\n if (lbl?.textContent?.trim()) return lbl.textContent.trim();\n }\n const wrapping = el.closest("label");\n if (wrapping) {\n const txt = safeText(wrapping).trim();\n if (txt) return txt;\n }\n const placeholder = el.getAttribute("placeholder");\n if (placeholder) return placeholder.trim();\n const text = isSensitive(el) ? "" : el.textContent?.trim();\n if (text) return text.replace(/\\s+/g, " ").slice(0, 80);\n return el.getAttribute("name") ?? el.getAttribute("id") ?? roleOf(el);\n }\n function isDestructive(el, label) {\n if (el.hasAttribute("data-co-confirm")) return true;\n if (el.type === "submit") return true;\n if (tag(el) === "BUTTON" && el.type === "submit") return true;\n return /\\b(delete|remove|destroy|sign out|log ?out|cancel subscription|deactivate)\\b/i.test(label);\n }\n function attributeHandle(el) {\n return el.getAttribute("data-co-handle") || el.getAttribute("name") || el.getAttribute("id") || "";\n }\n function walk(doc = document) {\n const registry = /* @__PURE__ */ new Map();\n const actions = [];\n const seen = /* @__PURE__ */ new Set();\n let synthetic = 0;\n for (const el of Array.from(doc.querySelectorAll(INTERACTIVE))) {\n if (seen.has(el) || !isVisible(el)) continue;\n seen.add(el);\n const label = accessibleName(el);\n const role = roleOf(el);\n let handle = attributeHandle(el);\n if (!handle || registry.has(handle)) handle = `${role}#${synthetic++}`;\n registry.set(handle, el);\n let value;\n if (role === "textbox" || role === "select") {\n value = isSensitive(el) ? void 0 : el.value;\n } else if (role === "checkbox" || role === "radio") {\n value = el.checked;\n }\n const action = { handle, role, label, destructive: isDestructive(el, label) };\n if (value !== void 0) action.value = value;\n actions.push(action);\n }\n const loc = doc.defaultView?.location;\n return {\n snapshot: { url: loc ? loc.pathname + loc.search : "", title: doc.title, actions },\n registry\n };\n }\n function isField(el) {\n const t = tag(el);\n return t === "INPUT" || t === "TEXTAREA" || t === "SELECT";\n }\n function setNativeValue(el, value) {\n const view = el.ownerDocument.defaultView ?? globalThis;\n const fire = () => {\n el.dispatchEvent(new view.Event("input", { bubbles: true }));\n el.dispatchEvent(new view.Event("change", { bubbles: true }));\n };\n const t = tag(el);\n if (t === "INPUT" && (el.type === "checkbox" || el.type === "radio")) {\n const setter2 = Object.getOwnPropertyDescriptor(view.HTMLInputElement.prototype, "checked")?.set;\n setter2?.call(el, Boolean(value));\n fire();\n return;\n }\n const proto = t === "TEXTAREA" ? view.HTMLTextAreaElement.prototype : t === "SELECT" ? view.HTMLSelectElement.prototype : view.HTMLInputElement.prototype;\n const setter = Object.getOwnPropertyDescriptor(proto, "value")?.set;\n setter?.call(el, String(value));\n fire();\n }\n function readPage(doc = document) {\n const main = doc.querySelector("main") ?? doc.body;\n if (!main) return doc.title;\n const heads = Array.from(main.querySelectorAll("h1, h2, h3")).map((h) => `${h.tagName}: ${safeText(h).trim()}`).filter(Boolean);\n const text = safeText(main).replace(/\\s+/g, " ").trim().slice(0, 4e3);\n return [doc.title, ...heads, "", text].join("\\n");\n }\n function findByAttribute(doc, attr, value) {\n for (const el of Array.from(doc.querySelectorAll(`[${attr}]`))) {\n if (el.getAttribute(attr) === value) return el;\n }\n return null;\n }\n var num = (v) => typeof v === "number" ? v : void 0;\n function createDomNavigationAgent(options = {}) {\n let registry = /* @__PURE__ */ new Map();\n const doc = () => options.document ?? document;\n const win = () => doc().defaultView ?? window;\n const before = (action) => options.beforeAction?.(action);\n const resolve = (handle) => {\n const hit = registry.get(handle);\n if (hit && hit.isConnected) return hit;\n const d = doc();\n return findByAttribute(d, "data-co-handle", handle) ?? findByAttribute(d, "name", handle) ?? d.getElementById(handle);\n };\n const agent = {\n getLocation: () => {\n const loc = win().location;\n return { url: loc.pathname + loc.search, title: doc().title };\n },\n describe: () => {\n const res = walk(doc());\n registry = res.registry;\n return res.snapshot;\n },\n read: () => readPage(doc()),\n visit: (url) => {\n const w = win();\n const target = new URL(String(url), w.location.href);\n if (target.protocol !== "http:" && target.protocol !== "https:") {\n throw new Error(`Refusing to navigate to a \'${target.protocol}\' URL.`);\n }\n w.setTimeout(() => w.location.assign(target.href), 0);\n },\n back: () => win().history.back(),\n forward: () => win().history.forward(),\n scrollTo: ({ x, y, handle }) => {\n const w = win();\n if (handle) {\n resolve(handle)?.scrollIntoView({ behavior: "smooth", block: "center" });\n return;\n }\n w.scrollTo({ left: x ?? w.scrollX, top: y ?? w.scrollY, behavior: "smooth" });\n },\n scrollBy: (dy) => win().scrollBy({ top: dy, behavior: "smooth" }),\n setField: (handle, value) => {\n before("setField");\n const el = resolve(handle);\n if (!el) return { ok: false, error: `No element for handle "${handle}"` };\n if (isField(el)) {\n setNativeValue(el, value);\n return { ok: true };\n }\n return { ok: false, error: `Handle "${handle}" is not a form field` };\n },\n click: (handle) => {\n const el = resolve(handle);\n if (!el) return { ok: false, error: `No element for handle "${handle}"` };\n before("click");\n el.click();\n return { ok: true };\n },\n submit: (handle) => {\n const el = resolve(handle);\n if (!el) return { ok: false, error: `No element for handle "${handle}"` };\n const form = tag(el) === "FORM" ? el : el.closest("form");\n if (!form) return { ok: false, error: `Handle "${handle}" is not inside a form` };\n before("submit");\n if (typeof form.requestSubmit === "function") form.requestSubmit();\n else form.submit();\n return { ok: true };\n },\n rectFor: (handle) => {\n const el = resolve(handle);\n if (!el) return null;\n const r = el.getBoundingClientRect();\n return { x: r.left, y: r.top, width: r.width, height: r.height };\n },\n resolve,\n call: (method, args = []) => {\n const a = Array.isArray(args) ? args : [];\n const handle = String(a[0] ?? "");\n switch (method) {\n case "getLocation":\n return agent.getLocation();\n case "describe":\n return agent.describe();\n case "read":\n return agent.read();\n case "visit":\n agent.visit(String(a[0] ?? ""));\n return void 0;\n case "back":\n agent.back();\n return void 0;\n case "forward":\n agent.forward();\n return void 0;\n case "scrollTo": {\n const o = a[0] && typeof a[0] === "object" ? a[0] : {};\n agent.scrollTo({\n x: num(o.x),\n y: num(o.y),\n handle: typeof o.handle === "string" ? o.handle : void 0\n });\n return void 0;\n }\n case "scrollBy":\n agent.scrollBy(Number(a[0] ?? 0));\n return void 0;\n case "setField":\n return agent.setField(handle, a[1]);\n case "click":\n return agent.click(handle);\n case "submit":\n return agent.submit(handle);\n case "rectFor":\n return agent.rectFor(handle);\n default:\n throw new Error(`Unknown dom-navigation method: ${String(method)}`);\n }\n }\n };\n return agent;\n }\n\n // src/dom-navigation/inject.ts\n var KEY = "__fancyDomNavigation";\n var PROTOCOL = 1;\n var g = globalThis;\n var existing = g[KEY];\n if (!existing || existing.protocol !== PROTOCOL) {\n const agent = createDomNavigationAgent();\n Object.defineProperty(globalThis, KEY, {\n configurable: true,\n enumerable: false,\n writable: false,\n value: Object.freeze({\n protocol: PROTOCOL,\n call: (method, args) => agent.call(method, args)\n })\n });\n }\n})();\n';
|
|
4
|
+
var virtual_dom_navigation_inject_default = '"use strict";\n(() => {\n // src/dom-navigation/agent.ts\n var INTERACTIVE = "a[href], button, input, select, textarea, [role=button], [role=link], [role=checkbox], [role=tab], [data-co-handle]";\n var tag = (el) => el.tagName.toUpperCase();\n function isVisible(el) {\n const he = el;\n if (el.type === "hidden") return false;\n if (he.hidden || he.getAttribute("aria-hidden") === "true") return false;\n return he.offsetParent !== null || he.getClientRects().length > 0;\n }\n function isSensitive(el) {\n const input = el;\n const ac = (el.getAttribute("autocomplete") ?? "").toLowerCase();\n return input.type === "password" || ac.startsWith("cc-") || ac === "one-time-code" || el.hasAttribute("data-private");\n }\n function insideSensitive(node) {\n for (let el = node.parentElement; el; el = el.parentElement) {\n if (isSensitive(el)) return true;\n }\n return false;\n }\n function safeText(root) {\n const doc = root.ownerDocument ?? root;\n const walker = doc.createTreeWalker(root, 4);\n let out = "";\n for (let n = walker.nextNode(); n; n = walker.nextNode()) {\n if (!insideSensitive(n)) out += n.nodeValue ?? "";\n }\n return out;\n }\n function roleOf(el) {\n const explicit = el.getAttribute("role");\n if (explicit) return explicit;\n const t = tag(el);\n if (t === "A") return "link";\n if (t === "BUTTON") return "button";\n if (t === "SELECT") return "select";\n if (t === "TEXTAREA") return "textbox";\n if (t === "INPUT") {\n const type = el.type;\n if (type === "checkbox") return "checkbox";\n if (type === "radio") return "radio";\n if (type === "submit" || type === "button") return "button";\n return "textbox";\n }\n return "generic";\n }\n function labelFor(doc, id) {\n for (const lbl of Array.from(doc.querySelectorAll("label[for]"))) {\n if (lbl.getAttribute("for") === id) return lbl;\n }\n return null;\n }\n function accessibleName(el) {\n const doc = el.ownerDocument;\n const aria = el.getAttribute("aria-label");\n if (aria) return aria.trim();\n const labelledby = el.getAttribute("aria-labelledby");\n if (labelledby) {\n const txt = labelledby.split(/\\s+/).map((id2) => doc.getElementById(id2)?.textContent ?? "").join(" ").trim();\n if (txt) return txt;\n }\n const id = el.getAttribute("id");\n if (id) {\n const lbl = labelFor(doc, id);\n if (lbl?.textContent?.trim()) return lbl.textContent.trim();\n }\n const wrapping = el.closest("label");\n if (wrapping) {\n const txt = safeText(wrapping).trim();\n if (txt) return txt;\n }\n const placeholder = el.getAttribute("placeholder");\n if (placeholder) return placeholder.trim();\n const text = isSensitive(el) ? "" : el.textContent?.trim();\n if (text) return text.replace(/\\s+/g, " ").slice(0, 80);\n return el.getAttribute("name") ?? el.getAttribute("id") ?? roleOf(el);\n }\n function isDestructive(el, label) {\n if (el.hasAttribute("data-co-confirm")) return true;\n if (el.type === "submit") return true;\n if (tag(el) === "BUTTON" && el.type === "submit") return true;\n return /\\b(delete|remove|destroy|sign out|log ?out|cancel subscription|deactivate)\\b/i.test(label);\n }\n function attributeHandle(el) {\n return el.getAttribute("data-co-handle") || el.getAttribute("name") || el.getAttribute("id") || "";\n }\n function walk(doc = document) {\n const registry = /* @__PURE__ */ new Map();\n const actions = [];\n const seen = /* @__PURE__ */ new Set();\n let synthetic = 0;\n for (const el of Array.from(doc.querySelectorAll(INTERACTIVE))) {\n if (seen.has(el) || !isVisible(el)) continue;\n seen.add(el);\n const label = accessibleName(el);\n const role = roleOf(el);\n let handle = attributeHandle(el);\n if (!handle || registry.has(handle)) handle = `${role}#${synthetic++}`;\n registry.set(handle, el);\n let value;\n if (role === "textbox" || role === "select") {\n value = isSensitive(el) ? void 0 : el.value;\n } else if (role === "checkbox" || role === "radio") {\n value = el.checked;\n }\n const action = { handle, role, label, destructive: isDestructive(el, label) };\n if (value !== void 0) action.value = value;\n actions.push(action);\n }\n const loc = doc.defaultView?.location;\n return {\n snapshot: { url: loc ? loc.pathname + loc.search : "", title: doc.title, actions },\n registry\n };\n }\n function isField(el) {\n const t = tag(el);\n return t === "INPUT" || t === "TEXTAREA" || t === "SELECT";\n }\n function setNativeValue(el, value) {\n const view = el.ownerDocument.defaultView ?? globalThis;\n const fire = () => {\n el.dispatchEvent(new view.Event("input", { bubbles: true }));\n el.dispatchEvent(new view.Event("change", { bubbles: true }));\n };\n const t = tag(el);\n if (t === "INPUT" && (el.type === "checkbox" || el.type === "radio")) {\n const input = el;\n const want = Boolean(value);\n if (input.checked === want) return;\n if (input.type === "checkbox" || want) {\n input.click();\n return;\n }\n const setter2 = Object.getOwnPropertyDescriptor(view.HTMLInputElement.prototype, "checked")?.set;\n setter2?.call(el, false);\n fire();\n return;\n }\n const proto = t === "TEXTAREA" ? view.HTMLTextAreaElement.prototype : t === "SELECT" ? view.HTMLSelectElement.prototype : view.HTMLInputElement.prototype;\n const setter = Object.getOwnPropertyDescriptor(proto, "value")?.set;\n setter?.call(el, String(value));\n fire();\n }\n function readPage(doc = document) {\n const main = doc.querySelector("main") ?? doc.body;\n if (!main) return { title: doc.title, headings: [], text: "" };\n const headings = Array.from(main.querySelectorAll("h1, h2, h3")).map((h) => ({\n level: Number(h.tagName.slice(1)),\n text: safeText(h).trim()\n }));\n const text = safeText(main).replace(/\\s+/g, " ").trim().slice(0, 4e3);\n return { title: doc.title, headings, text };\n }\n function findByAttribute(doc, attr, value) {\n for (const el of Array.from(doc.querySelectorAll(`[${attr}]`))) {\n if (el.getAttribute(attr) === value) return el;\n }\n return null;\n }\n var num = (v) => typeof v === "number" ? v : void 0;\n function createDomNavigationAgent(options = {}) {\n let registry = /* @__PURE__ */ new Map();\n const doc = () => options.document ?? document;\n const win = () => doc().defaultView ?? window;\n const before = (action) => options.beforeAction?.(action);\n const resolve = (handle) => {\n const hit = registry.get(handle);\n if (hit && hit.isConnected) return hit;\n const d = doc();\n return findByAttribute(d, "data-co-handle", handle) ?? findByAttribute(d, "name", handle) ?? d.getElementById(handle);\n };\n const agent = {\n getLocation: () => {\n const loc = win().location;\n return { url: loc.pathname + loc.search, title: doc().title };\n },\n describe: () => {\n const res = walk(doc());\n registry = res.registry;\n return res.snapshot;\n },\n read: () => readPage(doc()),\n visit: (url) => {\n const w = win();\n const target = new URL(String(url), w.location.href);\n if (target.protocol !== "http:" && target.protocol !== "https:") {\n throw new Error(`Refusing to navigate to a \'${target.protocol}\' URL.`);\n }\n w.setTimeout(() => w.location.assign(target.href), 0);\n },\n back: () => win().history.back(),\n forward: () => win().history.forward(),\n scrollTo: ({ x, y, handle }) => {\n const w = win();\n if (handle) {\n resolve(handle)?.scrollIntoView({ behavior: "smooth", block: "center" });\n return;\n }\n w.scrollTo({ left: x ?? w.scrollX, top: y ?? w.scrollY, behavior: "smooth" });\n },\n scrollBy: (dy) => win().scrollBy({ top: dy, behavior: "smooth" }),\n setField: (handle, value) => {\n before("setField");\n const el = resolve(handle);\n if (!el) return { ok: false, error: `No element for handle "${handle}"` };\n if (isField(el)) {\n setNativeValue(el, value);\n return { ok: true };\n }\n return { ok: false, error: `Handle "${handle}" is not a form field` };\n },\n click: (handle) => {\n const el = resolve(handle);\n if (!el) return { ok: false, error: `No element for handle "${handle}"` };\n before("click");\n el.click();\n return { ok: true };\n },\n submit: (handle) => {\n const el = resolve(handle);\n if (!el) return { ok: false, error: `No element for handle "${handle}"` };\n const form = tag(el) === "FORM" ? el : el.closest("form");\n if (!form) return { ok: false, error: `Handle "${handle}" is not inside a form` };\n before("submit");\n if (typeof form.requestSubmit === "function") form.requestSubmit();\n else form.submit();\n return { ok: true };\n },\n rectFor: (handle) => {\n const el = resolve(handle);\n if (!el) return null;\n const r = el.getBoundingClientRect();\n return { x: r.left, y: r.top, width: r.width, height: r.height };\n },\n resolve,\n call: (method, args = []) => {\n const a = Array.isArray(args) ? args : [];\n const handle = String(a[0] ?? "");\n switch (method) {\n case "getLocation":\n return agent.getLocation();\n case "describe":\n return agent.describe();\n case "read":\n return agent.read();\n case "visit":\n agent.visit(String(a[0] ?? ""));\n return void 0;\n case "back":\n agent.back();\n return void 0;\n case "forward":\n agent.forward();\n return void 0;\n case "scrollTo": {\n const o = a[0] && typeof a[0] === "object" ? a[0] : {};\n agent.scrollTo({\n x: num(o.x),\n y: num(o.y),\n handle: typeof o.handle === "string" ? o.handle : void 0\n });\n return void 0;\n }\n case "scrollBy":\n agent.scrollBy(Number(a[0] ?? 0));\n return void 0;\n case "setField":\n return agent.setField(handle, a[1]);\n case "click":\n return agent.click(handle);\n case "submit":\n return agent.submit(handle);\n case "rectFor":\n return agent.rectFor(handle);\n default:\n throw new Error(`Unknown dom-navigation method: ${String(method)}`);\n }\n }\n };\n return agent;\n }\n\n // src/dom-navigation/inject.ts\n var KEY = "__fancyDomNavigation";\n var PROTOCOL = 1;\n var g = globalThis;\n var existing = g[KEY];\n if (!existing || existing.protocol !== PROTOCOL) {\n const agent = createDomNavigationAgent();\n Object.defineProperty(globalThis, KEY, {\n configurable: true,\n enumerable: false,\n writable: false,\n value: Object.freeze({\n protocol: PROTOCOL,\n call: (method, args) => agent.call(method, args)\n })\n });\n }\n})();\n';
|
|
5
5
|
|
|
6
6
|
// src/dom-navigation/script.ts
|
|
7
7
|
var DOM_NAVIGATION_SCRIPT = virtual_dom_navigation_inject_default;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["dom-navigation-inject:virtual:dom-navigation-inject","../src/dom-navigation/script.ts"],"names":[],"mappings":";;;AAAA,IAAA,qCAAA,GAAA,ihWAAA;;;ACcO,IAAM,qBAAA,GAAgC","file":"dom-navigation-script.cjs","sourcesContent":["\"use strict\";\n(() => {\n // src/dom-navigation/agent.ts\n var INTERACTIVE = \"a[href], button, input, select, textarea, [role=button], [role=link], [role=checkbox], [role=tab], [data-co-handle]\";\n var tag = (el) => el.tagName.toUpperCase();\n function isVisible(el) {\n const he = el;\n if (el.type === \"hidden\") return false;\n if (he.hidden || he.getAttribute(\"aria-hidden\") === \"true\") return false;\n return he.offsetParent !== null || he.getClientRects().length > 0;\n }\n function isSensitive(el) {\n const input = el;\n const ac = (el.getAttribute(\"autocomplete\") ?? \"\").toLowerCase();\n return input.type === \"password\" || ac.startsWith(\"cc-\") || ac === \"one-time-code\" || el.hasAttribute(\"data-private\");\n }\n function insideSensitive(node) {\n for (let el = node.parentElement; el; el = el.parentElement) {\n if (isSensitive(el)) return true;\n }\n return false;\n }\n function safeText(root) {\n const doc = root.ownerDocument ?? root;\n const walker = doc.createTreeWalker(root, 4);\n let out = \"\";\n for (let n = walker.nextNode(); n; n = walker.nextNode()) {\n if (!insideSensitive(n)) out += n.nodeValue ?? \"\";\n }\n return out;\n }\n function roleOf(el) {\n const explicit = el.getAttribute(\"role\");\n if (explicit) return explicit;\n const t = tag(el);\n if (t === \"A\") return \"link\";\n if (t === \"BUTTON\") return \"button\";\n if (t === \"SELECT\") return \"select\";\n if (t === \"TEXTAREA\") return \"textbox\";\n if (t === \"INPUT\") {\n const type = el.type;\n if (type === \"checkbox\") return \"checkbox\";\n if (type === \"radio\") return \"radio\";\n if (type === \"submit\" || type === \"button\") return \"button\";\n return \"textbox\";\n }\n return \"generic\";\n }\n function labelFor(doc, id) {\n for (const lbl of Array.from(doc.querySelectorAll(\"label[for]\"))) {\n if (lbl.getAttribute(\"for\") === id) return lbl;\n }\n return null;\n }\n function accessibleName(el) {\n const doc = el.ownerDocument;\n const aria = el.getAttribute(\"aria-label\");\n if (aria) return aria.trim();\n const labelledby = el.getAttribute(\"aria-labelledby\");\n if (labelledby) {\n const txt = labelledby.split(/\\s+/).map((id2) => doc.getElementById(id2)?.textContent ?? \"\").join(\" \").trim();\n if (txt) return txt;\n }\n const id = el.getAttribute(\"id\");\n if (id) {\n const lbl = labelFor(doc, id);\n if (lbl?.textContent?.trim()) return lbl.textContent.trim();\n }\n const wrapping = el.closest(\"label\");\n if (wrapping) {\n const txt = safeText(wrapping).trim();\n if (txt) return txt;\n }\n const placeholder = el.getAttribute(\"placeholder\");\n if (placeholder) return placeholder.trim();\n const text = isSensitive(el) ? \"\" : el.textContent?.trim();\n if (text) return text.replace(/\\s+/g, \" \").slice(0, 80);\n return el.getAttribute(\"name\") ?? el.getAttribute(\"id\") ?? roleOf(el);\n }\n function isDestructive(el, label) {\n if (el.hasAttribute(\"data-co-confirm\")) return true;\n if (el.type === \"submit\") return true;\n if (tag(el) === \"BUTTON\" && el.type === \"submit\") return true;\n return /\\b(delete|remove|destroy|sign out|log ?out|cancel subscription|deactivate)\\b/i.test(label);\n }\n function attributeHandle(el) {\n return el.getAttribute(\"data-co-handle\") || el.getAttribute(\"name\") || el.getAttribute(\"id\") || \"\";\n }\n function walk(doc = document) {\n const registry = /* @__PURE__ */ new Map();\n const actions = [];\n const seen = /* @__PURE__ */ new Set();\n let synthetic = 0;\n for (const el of Array.from(doc.querySelectorAll(INTERACTIVE))) {\n if (seen.has(el) || !isVisible(el)) continue;\n seen.add(el);\n const label = accessibleName(el);\n const role = roleOf(el);\n let handle = attributeHandle(el);\n if (!handle || registry.has(handle)) handle = `${role}#${synthetic++}`;\n registry.set(handle, el);\n let value;\n if (role === \"textbox\" || role === \"select\") {\n value = isSensitive(el) ? void 0 : el.value;\n } else if (role === \"checkbox\" || role === \"radio\") {\n value = el.checked;\n }\n const action = { handle, role, label, destructive: isDestructive(el, label) };\n if (value !== void 0) action.value = value;\n actions.push(action);\n }\n const loc = doc.defaultView?.location;\n return {\n snapshot: { url: loc ? loc.pathname + loc.search : \"\", title: doc.title, actions },\n registry\n };\n }\n function isField(el) {\n const t = tag(el);\n return t === \"INPUT\" || t === \"TEXTAREA\" || t === \"SELECT\";\n }\n function setNativeValue(el, value) {\n const view = el.ownerDocument.defaultView ?? globalThis;\n const fire = () => {\n el.dispatchEvent(new view.Event(\"input\", { bubbles: true }));\n el.dispatchEvent(new view.Event(\"change\", { bubbles: true }));\n };\n const t = tag(el);\n if (t === \"INPUT\" && (el.type === \"checkbox\" || el.type === \"radio\")) {\n const setter2 = Object.getOwnPropertyDescriptor(view.HTMLInputElement.prototype, \"checked\")?.set;\n setter2?.call(el, Boolean(value));\n fire();\n return;\n }\n const proto = t === \"TEXTAREA\" ? view.HTMLTextAreaElement.prototype : t === \"SELECT\" ? view.HTMLSelectElement.prototype : view.HTMLInputElement.prototype;\n const setter = Object.getOwnPropertyDescriptor(proto, \"value\")?.set;\n setter?.call(el, String(value));\n fire();\n }\n function readPage(doc = document) {\n const main = doc.querySelector(\"main\") ?? doc.body;\n if (!main) return doc.title;\n const heads = Array.from(main.querySelectorAll(\"h1, h2, h3\")).map((h) => `${h.tagName}: ${safeText(h).trim()}`).filter(Boolean);\n const text = safeText(main).replace(/\\s+/g, \" \").trim().slice(0, 4e3);\n return [doc.title, ...heads, \"\", text].join(\"\\n\");\n }\n function findByAttribute(doc, attr, value) {\n for (const el of Array.from(doc.querySelectorAll(`[${attr}]`))) {\n if (el.getAttribute(attr) === value) return el;\n }\n return null;\n }\n var num = (v) => typeof v === \"number\" ? v : void 0;\n function createDomNavigationAgent(options = {}) {\n let registry = /* @__PURE__ */ new Map();\n const doc = () => options.document ?? document;\n const win = () => doc().defaultView ?? window;\n const before = (action) => options.beforeAction?.(action);\n const resolve = (handle) => {\n const hit = registry.get(handle);\n if (hit && hit.isConnected) return hit;\n const d = doc();\n return findByAttribute(d, \"data-co-handle\", handle) ?? findByAttribute(d, \"name\", handle) ?? d.getElementById(handle);\n };\n const agent = {\n getLocation: () => {\n const loc = win().location;\n return { url: loc.pathname + loc.search, title: doc().title };\n },\n describe: () => {\n const res = walk(doc());\n registry = res.registry;\n return res.snapshot;\n },\n read: () => readPage(doc()),\n visit: (url) => {\n const w = win();\n const target = new URL(String(url), w.location.href);\n if (target.protocol !== \"http:\" && target.protocol !== \"https:\") {\n throw new Error(`Refusing to navigate to a '${target.protocol}' URL.`);\n }\n w.setTimeout(() => w.location.assign(target.href), 0);\n },\n back: () => win().history.back(),\n forward: () => win().history.forward(),\n scrollTo: ({ x, y, handle }) => {\n const w = win();\n if (handle) {\n resolve(handle)?.scrollIntoView({ behavior: \"smooth\", block: \"center\" });\n return;\n }\n w.scrollTo({ left: x ?? w.scrollX, top: y ?? w.scrollY, behavior: \"smooth\" });\n },\n scrollBy: (dy) => win().scrollBy({ top: dy, behavior: \"smooth\" }),\n setField: (handle, value) => {\n before(\"setField\");\n const el = resolve(handle);\n if (!el) return { ok: false, error: `No element for handle \"${handle}\"` };\n if (isField(el)) {\n setNativeValue(el, value);\n return { ok: true };\n }\n return { ok: false, error: `Handle \"${handle}\" is not a form field` };\n },\n click: (handle) => {\n const el = resolve(handle);\n if (!el) return { ok: false, error: `No element for handle \"${handle}\"` };\n before(\"click\");\n el.click();\n return { ok: true };\n },\n submit: (handle) => {\n const el = resolve(handle);\n if (!el) return { ok: false, error: `No element for handle \"${handle}\"` };\n const form = tag(el) === \"FORM\" ? el : el.closest(\"form\");\n if (!form) return { ok: false, error: `Handle \"${handle}\" is not inside a form` };\n before(\"submit\");\n if (typeof form.requestSubmit === \"function\") form.requestSubmit();\n else form.submit();\n return { ok: true };\n },\n rectFor: (handle) => {\n const el = resolve(handle);\n if (!el) return null;\n const r = el.getBoundingClientRect();\n return { x: r.left, y: r.top, width: r.width, height: r.height };\n },\n resolve,\n call: (method, args = []) => {\n const a = Array.isArray(args) ? args : [];\n const handle = String(a[0] ?? \"\");\n switch (method) {\n case \"getLocation\":\n return agent.getLocation();\n case \"describe\":\n return agent.describe();\n case \"read\":\n return agent.read();\n case \"visit\":\n agent.visit(String(a[0] ?? \"\"));\n return void 0;\n case \"back\":\n agent.back();\n return void 0;\n case \"forward\":\n agent.forward();\n return void 0;\n case \"scrollTo\": {\n const o = a[0] && typeof a[0] === \"object\" ? a[0] : {};\n agent.scrollTo({\n x: num(o.x),\n y: num(o.y),\n handle: typeof o.handle === \"string\" ? o.handle : void 0\n });\n return void 0;\n }\n case \"scrollBy\":\n agent.scrollBy(Number(a[0] ?? 0));\n return void 0;\n case \"setField\":\n return agent.setField(handle, a[1]);\n case \"click\":\n return agent.click(handle);\n case \"submit\":\n return agent.submit(handle);\n case \"rectFor\":\n return agent.rectFor(handle);\n default:\n throw new Error(`Unknown dom-navigation method: ${String(method)}`);\n }\n }\n };\n return agent;\n }\n\n // src/dom-navigation/inject.ts\n var KEY = \"__fancyDomNavigation\";\n var PROTOCOL = 1;\n var g = globalThis;\n var existing = g[KEY];\n if (!existing || existing.protocol !== PROTOCOL) {\n const agent = createDomNavigationAgent();\n Object.defineProperty(globalThis, KEY, {\n configurable: true,\n enumerable: false,\n writable: false,\n value: Object.freeze({\n protocol: PROTOCOL,\n call: (method, args) => agent.call(method, args)\n })\n });\n }\n})();\n","/**\n * `@particle-academy/agent-integrations/dom-navigation/script`\n *\n * The in-page walker as one self-contained script string — no imports, no\n * module system — for a host to inject into a page it does not own:\n *\n * await webContents.executeJavaScriptInIsolatedWorld(worldId, [{ code: DOM_NAVIGATION_SCRIPT }]);\n *\n * Built at package build time from ./inject.ts (see\n * scripts/dom-navigation-inject-plugin.ts). Its own subpath so a host process\n * that only injects never loads the walker as a module, and vice versa.\n */\nimport source from \"virtual:dom-navigation-inject\";\n\nexport const DOM_NAVIGATION_SCRIPT: string = source;\n"]}
|
|
1
|
+
{"version":3,"sources":["dom-navigation-inject:virtual:dom-navigation-inject","../src/dom-navigation/script.ts"],"names":[],"mappings":";;;AAAA,IAAA,qCAAA,GAAA,gxWAAA;;;ACcO,IAAM,qBAAA,GAAgC","file":"dom-navigation-script.cjs","sourcesContent":["\"use strict\";\n(() => {\n // src/dom-navigation/agent.ts\n var INTERACTIVE = \"a[href], button, input, select, textarea, [role=button], [role=link], [role=checkbox], [role=tab], [data-co-handle]\";\n var tag = (el) => el.tagName.toUpperCase();\n function isVisible(el) {\n const he = el;\n if (el.type === \"hidden\") return false;\n if (he.hidden || he.getAttribute(\"aria-hidden\") === \"true\") return false;\n return he.offsetParent !== null || he.getClientRects().length > 0;\n }\n function isSensitive(el) {\n const input = el;\n const ac = (el.getAttribute(\"autocomplete\") ?? \"\").toLowerCase();\n return input.type === \"password\" || ac.startsWith(\"cc-\") || ac === \"one-time-code\" || el.hasAttribute(\"data-private\");\n }\n function insideSensitive(node) {\n for (let el = node.parentElement; el; el = el.parentElement) {\n if (isSensitive(el)) return true;\n }\n return false;\n }\n function safeText(root) {\n const doc = root.ownerDocument ?? root;\n const walker = doc.createTreeWalker(root, 4);\n let out = \"\";\n for (let n = walker.nextNode(); n; n = walker.nextNode()) {\n if (!insideSensitive(n)) out += n.nodeValue ?? \"\";\n }\n return out;\n }\n function roleOf(el) {\n const explicit = el.getAttribute(\"role\");\n if (explicit) return explicit;\n const t = tag(el);\n if (t === \"A\") return \"link\";\n if (t === \"BUTTON\") return \"button\";\n if (t === \"SELECT\") return \"select\";\n if (t === \"TEXTAREA\") return \"textbox\";\n if (t === \"INPUT\") {\n const type = el.type;\n if (type === \"checkbox\") return \"checkbox\";\n if (type === \"radio\") return \"radio\";\n if (type === \"submit\" || type === \"button\") return \"button\";\n return \"textbox\";\n }\n return \"generic\";\n }\n function labelFor(doc, id) {\n for (const lbl of Array.from(doc.querySelectorAll(\"label[for]\"))) {\n if (lbl.getAttribute(\"for\") === id) return lbl;\n }\n return null;\n }\n function accessibleName(el) {\n const doc = el.ownerDocument;\n const aria = el.getAttribute(\"aria-label\");\n if (aria) return aria.trim();\n const labelledby = el.getAttribute(\"aria-labelledby\");\n if (labelledby) {\n const txt = labelledby.split(/\\s+/).map((id2) => doc.getElementById(id2)?.textContent ?? \"\").join(\" \").trim();\n if (txt) return txt;\n }\n const id = el.getAttribute(\"id\");\n if (id) {\n const lbl = labelFor(doc, id);\n if (lbl?.textContent?.trim()) return lbl.textContent.trim();\n }\n const wrapping = el.closest(\"label\");\n if (wrapping) {\n const txt = safeText(wrapping).trim();\n if (txt) return txt;\n }\n const placeholder = el.getAttribute(\"placeholder\");\n if (placeholder) return placeholder.trim();\n const text = isSensitive(el) ? \"\" : el.textContent?.trim();\n if (text) return text.replace(/\\s+/g, \" \").slice(0, 80);\n return el.getAttribute(\"name\") ?? el.getAttribute(\"id\") ?? roleOf(el);\n }\n function isDestructive(el, label) {\n if (el.hasAttribute(\"data-co-confirm\")) return true;\n if (el.type === \"submit\") return true;\n if (tag(el) === \"BUTTON\" && el.type === \"submit\") return true;\n return /\\b(delete|remove|destroy|sign out|log ?out|cancel subscription|deactivate)\\b/i.test(label);\n }\n function attributeHandle(el) {\n return el.getAttribute(\"data-co-handle\") || el.getAttribute(\"name\") || el.getAttribute(\"id\") || \"\";\n }\n function walk(doc = document) {\n const registry = /* @__PURE__ */ new Map();\n const actions = [];\n const seen = /* @__PURE__ */ new Set();\n let synthetic = 0;\n for (const el of Array.from(doc.querySelectorAll(INTERACTIVE))) {\n if (seen.has(el) || !isVisible(el)) continue;\n seen.add(el);\n const label = accessibleName(el);\n const role = roleOf(el);\n let handle = attributeHandle(el);\n if (!handle || registry.has(handle)) handle = `${role}#${synthetic++}`;\n registry.set(handle, el);\n let value;\n if (role === \"textbox\" || role === \"select\") {\n value = isSensitive(el) ? void 0 : el.value;\n } else if (role === \"checkbox\" || role === \"radio\") {\n value = el.checked;\n }\n const action = { handle, role, label, destructive: isDestructive(el, label) };\n if (value !== void 0) action.value = value;\n actions.push(action);\n }\n const loc = doc.defaultView?.location;\n return {\n snapshot: { url: loc ? loc.pathname + loc.search : \"\", title: doc.title, actions },\n registry\n };\n }\n function isField(el) {\n const t = tag(el);\n return t === \"INPUT\" || t === \"TEXTAREA\" || t === \"SELECT\";\n }\n function setNativeValue(el, value) {\n const view = el.ownerDocument.defaultView ?? globalThis;\n const fire = () => {\n el.dispatchEvent(new view.Event(\"input\", { bubbles: true }));\n el.dispatchEvent(new view.Event(\"change\", { bubbles: true }));\n };\n const t = tag(el);\n if (t === \"INPUT\" && (el.type === \"checkbox\" || el.type === \"radio\")) {\n const input = el;\n const want = Boolean(value);\n if (input.checked === want) return;\n if (input.type === \"checkbox\" || want) {\n input.click();\n return;\n }\n const setter2 = Object.getOwnPropertyDescriptor(view.HTMLInputElement.prototype, \"checked\")?.set;\n setter2?.call(el, false);\n fire();\n return;\n }\n const proto = t === \"TEXTAREA\" ? view.HTMLTextAreaElement.prototype : t === \"SELECT\" ? view.HTMLSelectElement.prototype : view.HTMLInputElement.prototype;\n const setter = Object.getOwnPropertyDescriptor(proto, \"value\")?.set;\n setter?.call(el, String(value));\n fire();\n }\n function readPage(doc = document) {\n const main = doc.querySelector(\"main\") ?? doc.body;\n if (!main) return { title: doc.title, headings: [], text: \"\" };\n const headings = Array.from(main.querySelectorAll(\"h1, h2, h3\")).map((h) => ({\n level: Number(h.tagName.slice(1)),\n text: safeText(h).trim()\n }));\n const text = safeText(main).replace(/\\s+/g, \" \").trim().slice(0, 4e3);\n return { title: doc.title, headings, text };\n }\n function findByAttribute(doc, attr, value) {\n for (const el of Array.from(doc.querySelectorAll(`[${attr}]`))) {\n if (el.getAttribute(attr) === value) return el;\n }\n return null;\n }\n var num = (v) => typeof v === \"number\" ? v : void 0;\n function createDomNavigationAgent(options = {}) {\n let registry = /* @__PURE__ */ new Map();\n const doc = () => options.document ?? document;\n const win = () => doc().defaultView ?? window;\n const before = (action) => options.beforeAction?.(action);\n const resolve = (handle) => {\n const hit = registry.get(handle);\n if (hit && hit.isConnected) return hit;\n const d = doc();\n return findByAttribute(d, \"data-co-handle\", handle) ?? findByAttribute(d, \"name\", handle) ?? d.getElementById(handle);\n };\n const agent = {\n getLocation: () => {\n const loc = win().location;\n return { url: loc.pathname + loc.search, title: doc().title };\n },\n describe: () => {\n const res = walk(doc());\n registry = res.registry;\n return res.snapshot;\n },\n read: () => readPage(doc()),\n visit: (url) => {\n const w = win();\n const target = new URL(String(url), w.location.href);\n if (target.protocol !== \"http:\" && target.protocol !== \"https:\") {\n throw new Error(`Refusing to navigate to a '${target.protocol}' URL.`);\n }\n w.setTimeout(() => w.location.assign(target.href), 0);\n },\n back: () => win().history.back(),\n forward: () => win().history.forward(),\n scrollTo: ({ x, y, handle }) => {\n const w = win();\n if (handle) {\n resolve(handle)?.scrollIntoView({ behavior: \"smooth\", block: \"center\" });\n return;\n }\n w.scrollTo({ left: x ?? w.scrollX, top: y ?? w.scrollY, behavior: \"smooth\" });\n },\n scrollBy: (dy) => win().scrollBy({ top: dy, behavior: \"smooth\" }),\n setField: (handle, value) => {\n before(\"setField\");\n const el = resolve(handle);\n if (!el) return { ok: false, error: `No element for handle \"${handle}\"` };\n if (isField(el)) {\n setNativeValue(el, value);\n return { ok: true };\n }\n return { ok: false, error: `Handle \"${handle}\" is not a form field` };\n },\n click: (handle) => {\n const el = resolve(handle);\n if (!el) return { ok: false, error: `No element for handle \"${handle}\"` };\n before(\"click\");\n el.click();\n return { ok: true };\n },\n submit: (handle) => {\n const el = resolve(handle);\n if (!el) return { ok: false, error: `No element for handle \"${handle}\"` };\n const form = tag(el) === \"FORM\" ? el : el.closest(\"form\");\n if (!form) return { ok: false, error: `Handle \"${handle}\" is not inside a form` };\n before(\"submit\");\n if (typeof form.requestSubmit === \"function\") form.requestSubmit();\n else form.submit();\n return { ok: true };\n },\n rectFor: (handle) => {\n const el = resolve(handle);\n if (!el) return null;\n const r = el.getBoundingClientRect();\n return { x: r.left, y: r.top, width: r.width, height: r.height };\n },\n resolve,\n call: (method, args = []) => {\n const a = Array.isArray(args) ? args : [];\n const handle = String(a[0] ?? \"\");\n switch (method) {\n case \"getLocation\":\n return agent.getLocation();\n case \"describe\":\n return agent.describe();\n case \"read\":\n return agent.read();\n case \"visit\":\n agent.visit(String(a[0] ?? \"\"));\n return void 0;\n case \"back\":\n agent.back();\n return void 0;\n case \"forward\":\n agent.forward();\n return void 0;\n case \"scrollTo\": {\n const o = a[0] && typeof a[0] === \"object\" ? a[0] : {};\n agent.scrollTo({\n x: num(o.x),\n y: num(o.y),\n handle: typeof o.handle === \"string\" ? o.handle : void 0\n });\n return void 0;\n }\n case \"scrollBy\":\n agent.scrollBy(Number(a[0] ?? 0));\n return void 0;\n case \"setField\":\n return agent.setField(handle, a[1]);\n case \"click\":\n return agent.click(handle);\n case \"submit\":\n return agent.submit(handle);\n case \"rectFor\":\n return agent.rectFor(handle);\n default:\n throw new Error(`Unknown dom-navigation method: ${String(method)}`);\n }\n }\n };\n return agent;\n }\n\n // src/dom-navigation/inject.ts\n var KEY = \"__fancyDomNavigation\";\n var PROTOCOL = 1;\n var g = globalThis;\n var existing = g[KEY];\n if (!existing || existing.protocol !== PROTOCOL) {\n const agent = createDomNavigationAgent();\n Object.defineProperty(globalThis, KEY, {\n configurable: true,\n enumerable: false,\n writable: false,\n value: Object.freeze({\n protocol: PROTOCOL,\n call: (method, args) => agent.call(method, args)\n })\n });\n }\n})();\n","/**\n * `@particle-academy/agent-integrations/dom-navigation/script`\n *\n * The in-page walker as one self-contained script string — no imports, no\n * module system — for a host to inject into a page it does not own:\n *\n * await webContents.executeJavaScriptInIsolatedWorld(worldId, [{ code: DOM_NAVIGATION_SCRIPT }]);\n *\n * Built at package build time from ./inject.ts (see\n * scripts/dom-navigation-inject-plugin.ts). Its own subpath so a host process\n * that only injects never loads the walker as a module, and vice versa.\n */\nimport source from \"virtual:dom-navigation-inject\";\n\nexport const DOM_NAVIGATION_SCRIPT: string = source;\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// dom-navigation-inject:virtual:dom-navigation-inject
|
|
2
|
-
var virtual_dom_navigation_inject_default = '"use strict";\n(() => {\n // src/dom-navigation/agent.ts\n var INTERACTIVE = "a[href], button, input, select, textarea, [role=button], [role=link], [role=checkbox], [role=tab], [data-co-handle]";\n var tag = (el) => el.tagName.toUpperCase();\n function isVisible(el) {\n const he = el;\n if (el.type === "hidden") return false;\n if (he.hidden || he.getAttribute("aria-hidden") === "true") return false;\n return he.offsetParent !== null || he.getClientRects().length > 0;\n }\n function isSensitive(el) {\n const input = el;\n const ac = (el.getAttribute("autocomplete") ?? "").toLowerCase();\n return input.type === "password" || ac.startsWith("cc-") || ac === "one-time-code" || el.hasAttribute("data-private");\n }\n function insideSensitive(node) {\n for (let el = node.parentElement; el; el = el.parentElement) {\n if (isSensitive(el)) return true;\n }\n return false;\n }\n function safeText(root) {\n const doc = root.ownerDocument ?? root;\n const walker = doc.createTreeWalker(root, 4);\n let out = "";\n for (let n = walker.nextNode(); n; n = walker.nextNode()) {\n if (!insideSensitive(n)) out += n.nodeValue ?? "";\n }\n return out;\n }\n function roleOf(el) {\n const explicit = el.getAttribute("role");\n if (explicit) return explicit;\n const t = tag(el);\n if (t === "A") return "link";\n if (t === "BUTTON") return "button";\n if (t === "SELECT") return "select";\n if (t === "TEXTAREA") return "textbox";\n if (t === "INPUT") {\n const type = el.type;\n if (type === "checkbox") return "checkbox";\n if (type === "radio") return "radio";\n if (type === "submit" || type === "button") return "button";\n return "textbox";\n }\n return "generic";\n }\n function labelFor(doc, id) {\n for (const lbl of Array.from(doc.querySelectorAll("label[for]"))) {\n if (lbl.getAttribute("for") === id) return lbl;\n }\n return null;\n }\n function accessibleName(el) {\n const doc = el.ownerDocument;\n const aria = el.getAttribute("aria-label");\n if (aria) return aria.trim();\n const labelledby = el.getAttribute("aria-labelledby");\n if (labelledby) {\n const txt = labelledby.split(/\\s+/).map((id2) => doc.getElementById(id2)?.textContent ?? "").join(" ").trim();\n if (txt) return txt;\n }\n const id = el.getAttribute("id");\n if (id) {\n const lbl = labelFor(doc, id);\n if (lbl?.textContent?.trim()) return lbl.textContent.trim();\n }\n const wrapping = el.closest("label");\n if (wrapping) {\n const txt = safeText(wrapping).trim();\n if (txt) return txt;\n }\n const placeholder = el.getAttribute("placeholder");\n if (placeholder) return placeholder.trim();\n const text = isSensitive(el) ? "" : el.textContent?.trim();\n if (text) return text.replace(/\\s+/g, " ").slice(0, 80);\n return el.getAttribute("name") ?? el.getAttribute("id") ?? roleOf(el);\n }\n function isDestructive(el, label) {\n if (el.hasAttribute("data-co-confirm")) return true;\n if (el.type === "submit") return true;\n if (tag(el) === "BUTTON" && el.type === "submit") return true;\n return /\\b(delete|remove|destroy|sign out|log ?out|cancel subscription|deactivate)\\b/i.test(label);\n }\n function attributeHandle(el) {\n return el.getAttribute("data-co-handle") || el.getAttribute("name") || el.getAttribute("id") || "";\n }\n function walk(doc = document) {\n const registry = /* @__PURE__ */ new Map();\n const actions = [];\n const seen = /* @__PURE__ */ new Set();\n let synthetic = 0;\n for (const el of Array.from(doc.querySelectorAll(INTERACTIVE))) {\n if (seen.has(el) || !isVisible(el)) continue;\n seen.add(el);\n const label = accessibleName(el);\n const role = roleOf(el);\n let handle = attributeHandle(el);\n if (!handle || registry.has(handle)) handle = `${role}#${synthetic++}`;\n registry.set(handle, el);\n let value;\n if (role === "textbox" || role === "select") {\n value = isSensitive(el) ? void 0 : el.value;\n } else if (role === "checkbox" || role === "radio") {\n value = el.checked;\n }\n const action = { handle, role, label, destructive: isDestructive(el, label) };\n if (value !== void 0) action.value = value;\n actions.push(action);\n }\n const loc = doc.defaultView?.location;\n return {\n snapshot: { url: loc ? loc.pathname + loc.search : "", title: doc.title, actions },\n registry\n };\n }\n function isField(el) {\n const t = tag(el);\n return t === "INPUT" || t === "TEXTAREA" || t === "SELECT";\n }\n function setNativeValue(el, value) {\n const view = el.ownerDocument.defaultView ?? globalThis;\n const fire = () => {\n el.dispatchEvent(new view.Event("input", { bubbles: true }));\n el.dispatchEvent(new view.Event("change", { bubbles: true }));\n };\n const t = tag(el);\n if (t === "INPUT" && (el.type === "checkbox" || el.type === "radio")) {\n const setter2 = Object.getOwnPropertyDescriptor(view.HTMLInputElement.prototype, "checked")?.set;\n setter2?.call(el, Boolean(value));\n fire();\n return;\n }\n const proto = t === "TEXTAREA" ? view.HTMLTextAreaElement.prototype : t === "SELECT" ? view.HTMLSelectElement.prototype : view.HTMLInputElement.prototype;\n const setter = Object.getOwnPropertyDescriptor(proto, "value")?.set;\n setter?.call(el, String(value));\n fire();\n }\n function readPage(doc = document) {\n const main = doc.querySelector("main") ?? doc.body;\n if (!main) return doc.title;\n const heads = Array.from(main.querySelectorAll("h1, h2, h3")).map((h) => `${h.tagName}: ${safeText(h).trim()}`).filter(Boolean);\n const text = safeText(main).replace(/\\s+/g, " ").trim().slice(0, 4e3);\n return [doc.title, ...heads, "", text].join("\\n");\n }\n function findByAttribute(doc, attr, value) {\n for (const el of Array.from(doc.querySelectorAll(`[${attr}]`))) {\n if (el.getAttribute(attr) === value) return el;\n }\n return null;\n }\n var num = (v) => typeof v === "number" ? v : void 0;\n function createDomNavigationAgent(options = {}) {\n let registry = /* @__PURE__ */ new Map();\n const doc = () => options.document ?? document;\n const win = () => doc().defaultView ?? window;\n const before = (action) => options.beforeAction?.(action);\n const resolve = (handle) => {\n const hit = registry.get(handle);\n if (hit && hit.isConnected) return hit;\n const d = doc();\n return findByAttribute(d, "data-co-handle", handle) ?? findByAttribute(d, "name", handle) ?? d.getElementById(handle);\n };\n const agent = {\n getLocation: () => {\n const loc = win().location;\n return { url: loc.pathname + loc.search, title: doc().title };\n },\n describe: () => {\n const res = walk(doc());\n registry = res.registry;\n return res.snapshot;\n },\n read: () => readPage(doc()),\n visit: (url) => {\n const w = win();\n const target = new URL(String(url), w.location.href);\n if (target.protocol !== "http:" && target.protocol !== "https:") {\n throw new Error(`Refusing to navigate to a \'${target.protocol}\' URL.`);\n }\n w.setTimeout(() => w.location.assign(target.href), 0);\n },\n back: () => win().history.back(),\n forward: () => win().history.forward(),\n scrollTo: ({ x, y, handle }) => {\n const w = win();\n if (handle) {\n resolve(handle)?.scrollIntoView({ behavior: "smooth", block: "center" });\n return;\n }\n w.scrollTo({ left: x ?? w.scrollX, top: y ?? w.scrollY, behavior: "smooth" });\n },\n scrollBy: (dy) => win().scrollBy({ top: dy, behavior: "smooth" }),\n setField: (handle, value) => {\n before("setField");\n const el = resolve(handle);\n if (!el) return { ok: false, error: `No element for handle "${handle}"` };\n if (isField(el)) {\n setNativeValue(el, value);\n return { ok: true };\n }\n return { ok: false, error: `Handle "${handle}" is not a form field` };\n },\n click: (handle) => {\n const el = resolve(handle);\n if (!el) return { ok: false, error: `No element for handle "${handle}"` };\n before("click");\n el.click();\n return { ok: true };\n },\n submit: (handle) => {\n const el = resolve(handle);\n if (!el) return { ok: false, error: `No element for handle "${handle}"` };\n const form = tag(el) === "FORM" ? el : el.closest("form");\n if (!form) return { ok: false, error: `Handle "${handle}" is not inside a form` };\n before("submit");\n if (typeof form.requestSubmit === "function") form.requestSubmit();\n else form.submit();\n return { ok: true };\n },\n rectFor: (handle) => {\n const el = resolve(handle);\n if (!el) return null;\n const r = el.getBoundingClientRect();\n return { x: r.left, y: r.top, width: r.width, height: r.height };\n },\n resolve,\n call: (method, args = []) => {\n const a = Array.isArray(args) ? args : [];\n const handle = String(a[0] ?? "");\n switch (method) {\n case "getLocation":\n return agent.getLocation();\n case "describe":\n return agent.describe();\n case "read":\n return agent.read();\n case "visit":\n agent.visit(String(a[0] ?? ""));\n return void 0;\n case "back":\n agent.back();\n return void 0;\n case "forward":\n agent.forward();\n return void 0;\n case "scrollTo": {\n const o = a[0] && typeof a[0] === "object" ? a[0] : {};\n agent.scrollTo({\n x: num(o.x),\n y: num(o.y),\n handle: typeof o.handle === "string" ? o.handle : void 0\n });\n return void 0;\n }\n case "scrollBy":\n agent.scrollBy(Number(a[0] ?? 0));\n return void 0;\n case "setField":\n return agent.setField(handle, a[1]);\n case "click":\n return agent.click(handle);\n case "submit":\n return agent.submit(handle);\n case "rectFor":\n return agent.rectFor(handle);\n default:\n throw new Error(`Unknown dom-navigation method: ${String(method)}`);\n }\n }\n };\n return agent;\n }\n\n // src/dom-navigation/inject.ts\n var KEY = "__fancyDomNavigation";\n var PROTOCOL = 1;\n var g = globalThis;\n var existing = g[KEY];\n if (!existing || existing.protocol !== PROTOCOL) {\n const agent = createDomNavigationAgent();\n Object.defineProperty(globalThis, KEY, {\n configurable: true,\n enumerable: false,\n writable: false,\n value: Object.freeze({\n protocol: PROTOCOL,\n call: (method, args) => agent.call(method, args)\n })\n });\n }\n})();\n';
|
|
2
|
+
var virtual_dom_navigation_inject_default = '"use strict";\n(() => {\n // src/dom-navigation/agent.ts\n var INTERACTIVE = "a[href], button, input, select, textarea, [role=button], [role=link], [role=checkbox], [role=tab], [data-co-handle]";\n var tag = (el) => el.tagName.toUpperCase();\n function isVisible(el) {\n const he = el;\n if (el.type === "hidden") return false;\n if (he.hidden || he.getAttribute("aria-hidden") === "true") return false;\n return he.offsetParent !== null || he.getClientRects().length > 0;\n }\n function isSensitive(el) {\n const input = el;\n const ac = (el.getAttribute("autocomplete") ?? "").toLowerCase();\n return input.type === "password" || ac.startsWith("cc-") || ac === "one-time-code" || el.hasAttribute("data-private");\n }\n function insideSensitive(node) {\n for (let el = node.parentElement; el; el = el.parentElement) {\n if (isSensitive(el)) return true;\n }\n return false;\n }\n function safeText(root) {\n const doc = root.ownerDocument ?? root;\n const walker = doc.createTreeWalker(root, 4);\n let out = "";\n for (let n = walker.nextNode(); n; n = walker.nextNode()) {\n if (!insideSensitive(n)) out += n.nodeValue ?? "";\n }\n return out;\n }\n function roleOf(el) {\n const explicit = el.getAttribute("role");\n if (explicit) return explicit;\n const t = tag(el);\n if (t === "A") return "link";\n if (t === "BUTTON") return "button";\n if (t === "SELECT") return "select";\n if (t === "TEXTAREA") return "textbox";\n if (t === "INPUT") {\n const type = el.type;\n if (type === "checkbox") return "checkbox";\n if (type === "radio") return "radio";\n if (type === "submit" || type === "button") return "button";\n return "textbox";\n }\n return "generic";\n }\n function labelFor(doc, id) {\n for (const lbl of Array.from(doc.querySelectorAll("label[for]"))) {\n if (lbl.getAttribute("for") === id) return lbl;\n }\n return null;\n }\n function accessibleName(el) {\n const doc = el.ownerDocument;\n const aria = el.getAttribute("aria-label");\n if (aria) return aria.trim();\n const labelledby = el.getAttribute("aria-labelledby");\n if (labelledby) {\n const txt = labelledby.split(/\\s+/).map((id2) => doc.getElementById(id2)?.textContent ?? "").join(" ").trim();\n if (txt) return txt;\n }\n const id = el.getAttribute("id");\n if (id) {\n const lbl = labelFor(doc, id);\n if (lbl?.textContent?.trim()) return lbl.textContent.trim();\n }\n const wrapping = el.closest("label");\n if (wrapping) {\n const txt = safeText(wrapping).trim();\n if (txt) return txt;\n }\n const placeholder = el.getAttribute("placeholder");\n if (placeholder) return placeholder.trim();\n const text = isSensitive(el) ? "" : el.textContent?.trim();\n if (text) return text.replace(/\\s+/g, " ").slice(0, 80);\n return el.getAttribute("name") ?? el.getAttribute("id") ?? roleOf(el);\n }\n function isDestructive(el, label) {\n if (el.hasAttribute("data-co-confirm")) return true;\n if (el.type === "submit") return true;\n if (tag(el) === "BUTTON" && el.type === "submit") return true;\n return /\\b(delete|remove|destroy|sign out|log ?out|cancel subscription|deactivate)\\b/i.test(label);\n }\n function attributeHandle(el) {\n return el.getAttribute("data-co-handle") || el.getAttribute("name") || el.getAttribute("id") || "";\n }\n function walk(doc = document) {\n const registry = /* @__PURE__ */ new Map();\n const actions = [];\n const seen = /* @__PURE__ */ new Set();\n let synthetic = 0;\n for (const el of Array.from(doc.querySelectorAll(INTERACTIVE))) {\n if (seen.has(el) || !isVisible(el)) continue;\n seen.add(el);\n const label = accessibleName(el);\n const role = roleOf(el);\n let handle = attributeHandle(el);\n if (!handle || registry.has(handle)) handle = `${role}#${synthetic++}`;\n registry.set(handle, el);\n let value;\n if (role === "textbox" || role === "select") {\n value = isSensitive(el) ? void 0 : el.value;\n } else if (role === "checkbox" || role === "radio") {\n value = el.checked;\n }\n const action = { handle, role, label, destructive: isDestructive(el, label) };\n if (value !== void 0) action.value = value;\n actions.push(action);\n }\n const loc = doc.defaultView?.location;\n return {\n snapshot: { url: loc ? loc.pathname + loc.search : "", title: doc.title, actions },\n registry\n };\n }\n function isField(el) {\n const t = tag(el);\n return t === "INPUT" || t === "TEXTAREA" || t === "SELECT";\n }\n function setNativeValue(el, value) {\n const view = el.ownerDocument.defaultView ?? globalThis;\n const fire = () => {\n el.dispatchEvent(new view.Event("input", { bubbles: true }));\n el.dispatchEvent(new view.Event("change", { bubbles: true }));\n };\n const t = tag(el);\n if (t === "INPUT" && (el.type === "checkbox" || el.type === "radio")) {\n const input = el;\n const want = Boolean(value);\n if (input.checked === want) return;\n if (input.type === "checkbox" || want) {\n input.click();\n return;\n }\n const setter2 = Object.getOwnPropertyDescriptor(view.HTMLInputElement.prototype, "checked")?.set;\n setter2?.call(el, false);\n fire();\n return;\n }\n const proto = t === "TEXTAREA" ? view.HTMLTextAreaElement.prototype : t === "SELECT" ? view.HTMLSelectElement.prototype : view.HTMLInputElement.prototype;\n const setter = Object.getOwnPropertyDescriptor(proto, "value")?.set;\n setter?.call(el, String(value));\n fire();\n }\n function readPage(doc = document) {\n const main = doc.querySelector("main") ?? doc.body;\n if (!main) return { title: doc.title, headings: [], text: "" };\n const headings = Array.from(main.querySelectorAll("h1, h2, h3")).map((h) => ({\n level: Number(h.tagName.slice(1)),\n text: safeText(h).trim()\n }));\n const text = safeText(main).replace(/\\s+/g, " ").trim().slice(0, 4e3);\n return { title: doc.title, headings, text };\n }\n function findByAttribute(doc, attr, value) {\n for (const el of Array.from(doc.querySelectorAll(`[${attr}]`))) {\n if (el.getAttribute(attr) === value) return el;\n }\n return null;\n }\n var num = (v) => typeof v === "number" ? v : void 0;\n function createDomNavigationAgent(options = {}) {\n let registry = /* @__PURE__ */ new Map();\n const doc = () => options.document ?? document;\n const win = () => doc().defaultView ?? window;\n const before = (action) => options.beforeAction?.(action);\n const resolve = (handle) => {\n const hit = registry.get(handle);\n if (hit && hit.isConnected) return hit;\n const d = doc();\n return findByAttribute(d, "data-co-handle", handle) ?? findByAttribute(d, "name", handle) ?? d.getElementById(handle);\n };\n const agent = {\n getLocation: () => {\n const loc = win().location;\n return { url: loc.pathname + loc.search, title: doc().title };\n },\n describe: () => {\n const res = walk(doc());\n registry = res.registry;\n return res.snapshot;\n },\n read: () => readPage(doc()),\n visit: (url) => {\n const w = win();\n const target = new URL(String(url), w.location.href);\n if (target.protocol !== "http:" && target.protocol !== "https:") {\n throw new Error(`Refusing to navigate to a \'${target.protocol}\' URL.`);\n }\n w.setTimeout(() => w.location.assign(target.href), 0);\n },\n back: () => win().history.back(),\n forward: () => win().history.forward(),\n scrollTo: ({ x, y, handle }) => {\n const w = win();\n if (handle) {\n resolve(handle)?.scrollIntoView({ behavior: "smooth", block: "center" });\n return;\n }\n w.scrollTo({ left: x ?? w.scrollX, top: y ?? w.scrollY, behavior: "smooth" });\n },\n scrollBy: (dy) => win().scrollBy({ top: dy, behavior: "smooth" }),\n setField: (handle, value) => {\n before("setField");\n const el = resolve(handle);\n if (!el) return { ok: false, error: `No element for handle "${handle}"` };\n if (isField(el)) {\n setNativeValue(el, value);\n return { ok: true };\n }\n return { ok: false, error: `Handle "${handle}" is not a form field` };\n },\n click: (handle) => {\n const el = resolve(handle);\n if (!el) return { ok: false, error: `No element for handle "${handle}"` };\n before("click");\n el.click();\n return { ok: true };\n },\n submit: (handle) => {\n const el = resolve(handle);\n if (!el) return { ok: false, error: `No element for handle "${handle}"` };\n const form = tag(el) === "FORM" ? el : el.closest("form");\n if (!form) return { ok: false, error: `Handle "${handle}" is not inside a form` };\n before("submit");\n if (typeof form.requestSubmit === "function") form.requestSubmit();\n else form.submit();\n return { ok: true };\n },\n rectFor: (handle) => {\n const el = resolve(handle);\n if (!el) return null;\n const r = el.getBoundingClientRect();\n return { x: r.left, y: r.top, width: r.width, height: r.height };\n },\n resolve,\n call: (method, args = []) => {\n const a = Array.isArray(args) ? args : [];\n const handle = String(a[0] ?? "");\n switch (method) {\n case "getLocation":\n return agent.getLocation();\n case "describe":\n return agent.describe();\n case "read":\n return agent.read();\n case "visit":\n agent.visit(String(a[0] ?? ""));\n return void 0;\n case "back":\n agent.back();\n return void 0;\n case "forward":\n agent.forward();\n return void 0;\n case "scrollTo": {\n const o = a[0] && typeof a[0] === "object" ? a[0] : {};\n agent.scrollTo({\n x: num(o.x),\n y: num(o.y),\n handle: typeof o.handle === "string" ? o.handle : void 0\n });\n return void 0;\n }\n case "scrollBy":\n agent.scrollBy(Number(a[0] ?? 0));\n return void 0;\n case "setField":\n return agent.setField(handle, a[1]);\n case "click":\n return agent.click(handle);\n case "submit":\n return agent.submit(handle);\n case "rectFor":\n return agent.rectFor(handle);\n default:\n throw new Error(`Unknown dom-navigation method: ${String(method)}`);\n }\n }\n };\n return agent;\n }\n\n // src/dom-navigation/inject.ts\n var KEY = "__fancyDomNavigation";\n var PROTOCOL = 1;\n var g = globalThis;\n var existing = g[KEY];\n if (!existing || existing.protocol !== PROTOCOL) {\n const agent = createDomNavigationAgent();\n Object.defineProperty(globalThis, KEY, {\n configurable: true,\n enumerable: false,\n writable: false,\n value: Object.freeze({\n protocol: PROTOCOL,\n call: (method, args) => agent.call(method, args)\n })\n });\n }\n})();\n';
|
|
3
3
|
|
|
4
4
|
// src/dom-navigation/script.ts
|
|
5
5
|
var DOM_NAVIGATION_SCRIPT = virtual_dom_navigation_inject_default;
|