@particle-academy/agent-integrations 0.46.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.
Files changed (96) hide show
  1. package/CHANGELOG.md +885 -0
  2. package/LICENSE +21 -0
  3. package/README.md +53 -3
  4. package/dist/bridges/artboard.d.cts +3 -3
  5. package/dist/bridges/artboard.d.ts +3 -3
  6. package/dist/bridges/catalog.d.cts +3 -3
  7. package/dist/bridges/catalog.d.ts +3 -3
  8. package/dist/bridges/charts.d.cts +3 -3
  9. package/dist/bridges/charts.d.ts +3 -3
  10. package/dist/bridges/cms.d.cts +3 -3
  11. package/dist/bridges/cms.d.ts +3 -3
  12. package/dist/bridges/code.d.cts +3 -3
  13. package/dist/bridges/code.d.ts +3 -3
  14. package/dist/bridges/doc.d.cts +3 -3
  15. package/dist/bridges/doc.d.ts +3 -3
  16. package/dist/bridges/features.d.cts +3 -3
  17. package/dist/bridges/features.d.ts +3 -3
  18. package/dist/bridges/files.d.cts +3 -3
  19. package/dist/bridges/files.d.ts +3 -3
  20. package/dist/bridges/flow.d.cts +3 -3
  21. package/dist/bridges/flow.d.ts +3 -3
  22. package/dist/bridges/forms.d.cts +3 -3
  23. package/dist/bridges/forms.d.ts +3 -3
  24. package/dist/bridges/git.d.cts +3 -3
  25. package/dist/bridges/git.d.ts +3 -3
  26. package/dist/bridges/grid.d.cts +3 -3
  27. package/dist/bridges/grid.d.ts +3 -3
  28. package/dist/bridges/map.d.cts +3 -3
  29. package/dist/bridges/map.d.ts +3 -3
  30. package/dist/bridges/navigation.d.cts +140 -0
  31. package/dist/bridges/navigation.d.ts +140 -0
  32. package/dist/bridges/passkeys.d.cts +4 -4
  33. package/dist/bridges/passkeys.d.ts +4 -4
  34. package/dist/bridges/scene.d.cts +3 -3
  35. package/dist/bridges/scene.d.ts +3 -3
  36. package/dist/bridges/screens.d.cts +3 -3
  37. package/dist/bridges/screens.d.ts +3 -3
  38. package/dist/bridges/sheets.d.cts +3 -3
  39. package/dist/bridges/sheets.d.ts +3 -3
  40. package/dist/bridges/slides.d.cts +3 -3
  41. package/dist/bridges/slides.d.ts +3 -3
  42. package/dist/bridges/terminal.d.cts +3 -3
  43. package/dist/bridges/terminal.d.ts +3 -3
  44. package/dist/bridges/tui.d.cts +2 -2
  45. package/dist/bridges/tui.d.ts +2 -2
  46. package/dist/bridges/whiteboard.d.cts +3 -3
  47. package/dist/bridges/whiteboard.d.ts +3 -3
  48. package/dist/bridges-navigation.cjs +437 -0
  49. package/dist/bridges-navigation.cjs.map +1 -0
  50. package/dist/bridges-navigation.js +7 -0
  51. package/dist/bridges-navigation.js.map +1 -0
  52. package/dist/bridges-passkeys.cjs.map +1 -1
  53. package/dist/bridges-passkeys.js +1 -1
  54. package/dist/{chunk-PWYEW6NL.js → chunk-G6CRHFWU.js} +2 -2
  55. package/dist/{chunk-PWYEW6NL.js.map → chunk-G6CRHFWU.js.map} +1 -1
  56. package/dist/chunk-OHNGURUJ.js +317 -0
  57. package/dist/chunk-OHNGURUJ.js.map +1 -0
  58. package/dist/dom-navigation/index.d.cts +175 -0
  59. package/dist/dom-navigation/index.d.ts +175 -0
  60. package/dist/dom-navigation/script.d.cts +3 -0
  61. package/dist/dom-navigation/script.d.ts +3 -0
  62. package/dist/dom-navigation-script.cjs +11 -0
  63. package/dist/dom-navigation-script.cjs.map +1 -0
  64. package/dist/dom-navigation-script.js +9 -0
  65. package/dist/dom-navigation-script.js.map +1 -0
  66. package/dist/dom-navigation.cjs +405 -0
  67. package/dist/dom-navigation.cjs.map +1 -0
  68. package/dist/dom-navigation.js +388 -0
  69. package/dist/dom-navigation.js.map +1 -0
  70. package/dist/index.cjs +94 -48
  71. package/dist/index.cjs.map +1 -1
  72. package/dist/index.d.cts +10 -125
  73. package/dist/index.d.ts +10 -125
  74. package/dist/index.js +12 -275
  75. package/dist/index.js.map +1 -1
  76. package/dist/mcp/index.d.cts +5 -5
  77. package/dist/mcp/index.d.ts +5 -5
  78. package/dist/mcp/stdio.d.cts +3 -3
  79. package/dist/mcp/stdio.d.ts +3 -3
  80. package/dist/presence/index.d.cts +1 -1
  81. package/dist/presence/index.d.ts +1 -1
  82. package/dist/{server-BIcA3ZtK.d.cts → server-1y0n61R5.d.cts} +2 -2
  83. package/dist/{server-DnUyeavY.d.ts → server-vq6qVl3T.d.ts} +2 -2
  84. package/dist/sharing/index.d.cts +3 -3
  85. package/dist/sharing/index.d.ts +3 -3
  86. package/dist/sheets-adapter.d.cts +3 -3
  87. package/dist/sheets-adapter.d.ts +3 -3
  88. package/dist/{tool-host-LVBgCN5m.d.cts → tool-host-D67N2a2h.d.cts} +1 -1
  89. package/dist/{tool-host-Wo0pkY83.d.ts → tool-host-LYfdPE8u.d.ts} +1 -1
  90. package/dist/{types-EcElKOlk.d.cts → types-DP5yQZQU.d.cts} +1 -1
  91. package/dist/{types-BxNRKSVd.d.ts → types-VX_9je7w.d.ts} +1 -1
  92. package/dist/{types-C2DtnHIn.d.cts → types-gzIpsUDE.d.cts} +1 -1
  93. package/dist/{types-C2DtnHIn.d.ts → types-gzIpsUDE.d.ts} +1 -1
  94. package/dist/undo/index.d.cts +2 -2
  95. package/dist/undo/index.d.ts +2 -2
  96. package/package.json +35 -3
@@ -0,0 +1,317 @@
1
+ import { ensureUndoToolsRegistered, pushUndoEntry } from './chunk-R4XXOGQH.js';
2
+ import { wrapToolWithActivity } from './chunk-2VENWGLZ.js';
3
+ import { textResult, errorResult } from './chunk-CZV3WUW5.js';
4
+
5
+ // src/bridges/navigation.ts
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
+ }
23
+ function registerNavigationBridge(host, options) {
24
+ const { adapter } = options;
25
+ const agent = { ...DEFAULT_AGENT, ...options.agent ?? {} };
26
+ const pendingMode = options.pendingMode ?? true;
27
+ const disposers = [];
28
+ let groundedRevision = null;
29
+ const staleIntent = async () => {
30
+ const current = await adapter.getRevision?.();
31
+ if (current === void 0) return null;
32
+ if (groundedRevision === null || groundedRevision !== current) {
33
+ return errorResult(
34
+ `Human took control at page revision ${current}. This agent action was cancelled; call page_describe before acting again.`
35
+ );
36
+ }
37
+ return null;
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);
42
+ ensureUndoToolsRegistered(host, { defaultAgentId: agent.id });
43
+ const target = (label, elementId) => ({
44
+ kind: "navigation",
45
+ screenId: adapter.screenId,
46
+ elementId,
47
+ label
48
+ });
49
+ const reg = (name, description, properties, required, handler, activity) => {
50
+ const wrapped = async (args) => {
51
+ try {
52
+ return await handler(args);
53
+ } catch (e) {
54
+ return failure(e instanceof Error ? e.message : String(e), `${name} failed`);
55
+ }
56
+ };
57
+ const final = activity ? wrapToolWithActivity(wrapped, {
58
+ toolName: name,
59
+ agent: { id: agent.id, name: agent.name, color: agent.color },
60
+ kind: "navigation",
61
+ screenId: adapter.screenId,
62
+ resolveTarget: ({ args }) => activity(args)
63
+ }) : wrapped;
64
+ disposers.push(
65
+ host.registerTool(
66
+ {
67
+ name,
68
+ description,
69
+ inputSchema: { type: "object", properties, required, additionalProperties: false }
70
+ },
71
+ final
72
+ )
73
+ );
74
+ };
75
+ reg(
76
+ "page_describe",
77
+ "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.",
78
+ {},
79
+ [],
80
+ async () => {
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 };
92
+ const revision = await adapter.getRevision?.();
93
+ if (revision !== void 0) {
94
+ snap.revision = revision;
95
+ groundedRevision = revision;
96
+ }
97
+ const text = [
98
+ `URL: ${oneLine(snap.url, CAP.url)}`,
99
+ `Title: ${oneLine(snap.title, CAP.title)}`,
100
+ "",
101
+ ...actions.map(
102
+ (a) => `[${a.handle}] ${oneLine(a.role, CAP.role)}: ${oneLine(a.label, CAP.label)}${a.destructive ? " (destructive)" : ""}`
103
+ )
104
+ ].join("\n");
105
+ return textResult(text, snap);
106
+ },
107
+ () => target("Inspect page")
108
+ );
109
+ reg(
110
+ "page_read",
111
+ "Read the page's visible text / heading outline for grounding.",
112
+ {},
113
+ [],
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
+ },
118
+ () => target("Read page")
119
+ );
120
+ reg(
121
+ "page_focus",
122
+ "Move the agent's visible focus to an interactive element by stable handle without activating it.",
123
+ { handle: { type: "string" } },
124
+ ["handle"],
125
+ async (args) => {
126
+ const stale = await staleIntent();
127
+ if (stale) return stale;
128
+ const shown = String(args.handle ?? "");
129
+ const handle = pageHandle(shown);
130
+ const action = (await adapter.describe()).actions.find((candidate) => candidate.handle === 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,
134
+ rect: await adapter.rectFor?.(handle) ?? void 0
135
+ });
136
+ },
137
+ (args) => target(`Focus ${String(args.handle ?? "")}`, String(args.handle ?? ""))
138
+ );
139
+ reg(
140
+ "nav_visit",
141
+ "Navigate to a URL (same-site path or absolute). The human watches the page change.",
142
+ { url: { type: "string", description: "Path like /packages or an absolute URL." } },
143
+ ["url"],
144
+ async (args) => {
145
+ const stale = await staleIntent();
146
+ if (stale) return stale;
147
+ const url = String(args.url ?? "");
148
+ if (!url) return errorResult("url is required");
149
+ const scheme = /^([a-zA-Z][a-zA-Z0-9+.-]*):/.exec(url)?.[1]?.toLowerCase();
150
+ if (scheme && scheme !== "http" && scheme !== "https") {
151
+ return errorResult(
152
+ `Refusing to navigate to a '${scheme}:' URL. Only http(s) URLs or same-site paths are allowed.`
153
+ );
154
+ }
155
+ const from = (await adapter.getLocation()).url;
156
+ await adapter.visit(url);
157
+ pushUndoEntry(agent.id, {
158
+ timestamp: Date.now(),
159
+ bridgeId: "navigation",
160
+ action: "nav_visit",
161
+ label: `Navigate to ${url}`,
162
+ undo: () => {
163
+ adapter.visit(from);
164
+ },
165
+ redo: () => {
166
+ adapter.visit(url);
167
+ }
168
+ });
169
+ return textResult(`Navigated to ${url}`, { url });
170
+ },
171
+ (args) => target(`Navigate \u2192 ${String(args.url ?? "")}`)
172
+ );
173
+ reg(
174
+ "nav_back",
175
+ "Go back to the previous page.",
176
+ {},
177
+ [],
178
+ async () => {
179
+ const stale = await staleIntent();
180
+ if (stale) return stale;
181
+ if (!adapter.back) return errorResult("Host did not provide back navigation.");
182
+ await adapter.back();
183
+ return textResult("Went back");
184
+ },
185
+ () => target("Back")
186
+ );
187
+ reg(
188
+ "nav_forward",
189
+ "Go forward to the next page.",
190
+ {},
191
+ [],
192
+ async () => {
193
+ const stale = await staleIntent();
194
+ if (stale) return stale;
195
+ if (!adapter.forward) return errorResult("Host did not provide forward navigation.");
196
+ await adapter.forward();
197
+ return textResult("Went forward");
198
+ },
199
+ () => target("Forward")
200
+ );
201
+ reg(
202
+ "nav_scroll_to",
203
+ "Scroll the page to absolute coordinates, or to a specific element by its handle.",
204
+ {
205
+ handle: { type: "string", description: "Scroll this element into view." },
206
+ x: { type: "number" },
207
+ y: { type: "number" }
208
+ },
209
+ [],
210
+ async (args) => {
211
+ const stale = await staleIntent();
212
+ if (stale) return stale;
213
+ const shown = typeof args.handle === "string" ? args.handle : void 0;
214
+ const handle = shown === void 0 ? void 0 : pageHandle(shown);
215
+ await adapter.scrollTo({
216
+ handle,
217
+ x: typeof args.x === "number" ? args.x : void 0,
218
+ y: typeof args.y === "number" ? args.y : void 0
219
+ });
220
+ return textResult(
221
+ "Scrolled",
222
+ handle ? { handle: shown, rect: await adapter.rectFor?.(handle) ?? void 0 } : void 0
223
+ );
224
+ },
225
+ () => target("Scroll")
226
+ );
227
+ reg(
228
+ "nav_scroll_by",
229
+ "Scroll the page by a vertical delta in pixels (negative scrolls up).",
230
+ { dy: { type: "number" } },
231
+ ["dy"],
232
+ async (args) => {
233
+ const stale = await staleIntent();
234
+ if (stale) return stale;
235
+ await adapter.scrollBy(Number(args.dy ?? 0));
236
+ return textResult(`Scrolled by ${Number(args.dy ?? 0)}px`);
237
+ },
238
+ () => target("Scroll")
239
+ );
240
+ reg(
241
+ "page_set_field",
242
+ "Set a form field's value by handle. The host updates the controlled input and the human sees it change.",
243
+ {
244
+ handle: { type: "string" },
245
+ value: { description: "Value to set; type matches the field." }
246
+ },
247
+ ["handle", "value"],
248
+ async (args) => {
249
+ const stale = await staleIntent();
250
+ if (stale) return stale;
251
+ const shown = String(args.handle ?? "");
252
+ const handle = pageHandle(shown);
253
+ const res = await adapter.setField(handle, args.value);
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
+ });
260
+ },
261
+ (args) => target(`Set ${String(args.handle ?? "")}`, String(args.handle ?? ""))
262
+ );
263
+ reg(
264
+ "page_click",
265
+ "Activate an element by handle (link, button, checkbox\u2026). Destructive elements are staged for the human to confirm.",
266
+ { handle: { type: "string" } },
267
+ ["handle"],
268
+ async (args) => {
269
+ const stale = await staleIntent();
270
+ if (stale) return stale;
271
+ const shown = String(args.handle ?? "");
272
+ const handle = pageHandle(shown);
273
+ const action = (await adapter.describe()).actions.find((a) => a.handle === handle);
274
+ const rect = await adapter.rectFor?.(handle) ?? void 0;
275
+ if (pendingMode && action?.destructive && adapter.confirm) {
276
+ const ok = await adapter.confirm({ action: "click", handle, label: action.label });
277
+ if (!ok) return errorResult("Declined by user");
278
+ }
279
+ const res = await adapter.click(handle);
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 });
282
+ },
283
+ (args) => target(`Click ${String(args.handle ?? "")}`, String(args.handle ?? ""))
284
+ );
285
+ reg(
286
+ "page_submit",
287
+ "Submit a form by handle. Always staged for the human to confirm when pendingMode is on.",
288
+ { handle: { type: "string" } },
289
+ ["handle"],
290
+ async (args) => {
291
+ const stale = await staleIntent();
292
+ if (stale) return stale;
293
+ const shown = String(args.handle ?? "");
294
+ const handle = pageHandle(shown);
295
+ const rect = await adapter.rectFor?.(handle) ?? void 0;
296
+ if (pendingMode && adapter.confirm) {
297
+ const ok = await adapter.confirm({ action: "submit", handle, label: handle });
298
+ if (!ok) return errorResult("Declined by user");
299
+ }
300
+ const res = await adapter.submit(handle);
301
+ if (!res.ok) return failure(res.error, "Submit failed");
302
+ return textResult(`Submitted ${oneLine(shown, CAP.label)}`, { handle: shown, rect });
303
+ },
304
+ (args) => target(`Submit ${String(args.handle ?? "")}`, String(args.handle ?? ""))
305
+ );
306
+ return {
307
+ id: "navigation",
308
+ title: "Co-browsing",
309
+ dispose: () => {
310
+ for (const d of disposers) d();
311
+ }
312
+ };
313
+ }
314
+
315
+ export { registerNavigationBridge };
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,KAAA,IAAS,IAAA,GAAO,EAAA,GAAK,MAAA,CAAO,KAAK,CAAA;AAEjF,EAAA,MAAM,OAAA,GAAU,GAAA,CAAI,MAAA,GAAS,GAAA,GAAM,CAAA,GAAI,IAAI,KAAA,CAAM,CAAA,EAAG,GAAA,GAAM,CAAC,CAAA,GAAI,GAAA;AAC/D,EAAA,IAAI,GAAA,GAAM,EAAA;AACV,EAAA,KAAA,MAAW,CAAA,IAAK,SAAS,GAAA,IAAO,SAAA,CAAU,EAAE,UAAA,CAAW,CAAC,CAAC,CAAA,GAAI,GAAA,GAAM,CAAA;AACnE,EAAA,GAAA,GAAM,GAAA,CAAI,OAAA,CAAQ,MAAA,EAAQ,GAAG,E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S;AAClC,QAAA,MAAM,EAAA,GAAK,MAAM,OAAA,CAAQ,OAAA,CAAQ,EAAE,QAAQ,QAAA,EAAU,MAAA,EAAQ,KAAA,EAAO,MAAA,EAAQ,CAAA;AAC5E,QAAA,IAAI,CAAC,EAAA,EAAI,OAAO,WAAA,CAAY,kBAAkB,CAAA;AAAA,MAChD;AACA,MAAA,MAAM,GAAA,GAAM,MAAM,OAAA,CAAQ,MAAA,CAAO,MAAM,CAAA;AACvC,MAAA,IAAI,CAAC,GAAA,CAAI,EAAA,SAAW,OAAA,CAAQ,GAAA,CAAI,OAAO,eAAe,CAAA;AACtD,MAAA,OAAO,UAAA,CAAW,CAAA,UAAA,EAAa,OAAA,CAAQ,KAAA,EAAO,GAAA,CAAI,KAAK,CAAC,CAAA,CAAA,EAAI,EAAE,MAAA,EAAQ,KAAA,EAAO,IAAA,EAAM,CAAA;AAAA,IACrF,CAAA;AAAA,IACA,CAAC,IAAA,KAAS,MAAA,CAAO,CAAA,OAAA,EAAU,OAAO,IAAA,CAAK,MAAA,IAAU,EAAE,CAAC,CAAA,CAAA,EAAI,MAAA,CAAO,IAAA,CAAK,MAAA,IAAU,EAAE,CAAC;AAAA,GACnF;AAEA,EAAA,OAAO;AAAA,IACL,EAAA,EAAI,YAAA;AAAA,IACJ,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"]}
@@ -0,0 +1,175 @@
1
+ import { PageSnapshot, PageReadout, NavigationConfirmRequest, NavigationBridgeAdapter } from '../bridges/navigation.cjs';
2
+ export { PageAction } from '../bridges/navigation.cjs';
3
+ import '../tool-host-D67N2a2h.cjs';
4
+ import '../types-gzIpsUDE.cjs';
5
+ import '../types-DP5yQZQU.cjs';
6
+
7
+ /**
8
+ * The in-page half of DOM co-browsing: a framework-free walker that turns a
9
+ * live document into a {@link PageSnapshot} of stable handles, and acts on
10
+ * those handles.
11
+ *
12
+ * Extracted from px-ui-sandbox's CoBrowseProvider so a host that does NOT own
13
+ * the page (Genie's browser, showing sites through an Electron
14
+ * WebContentsView) can run the same walker, injected into an isolated world.
15
+ *
16
+ * Constraints this file holds, because the injected IIFE is built from it:
17
+ *
18
+ * - NO runtime imports. Type-only imports are erased; anything else would be
19
+ * bundled into a script that must run with no module loader.
20
+ * - Nothing touches `document` / `window` until a method is called, so the
21
+ * script can be evaluated in a context with no DOM at all.
22
+ * - Every result is plain, structured-cloneable data.
23
+ *
24
+ * Trust boundary: the page is hostile input. It controls every attribute,
25
+ * label and text node read here. Two consequences:
26
+ * - Sensitive values (passwords, card fields, one-time codes, anything marked
27
+ * `data-private`) are masked HERE, before anything leaves the page — the host
28
+ * cannot mask what it has already received.
29
+ * - Handles are compared as plain strings, never spliced into a CSS selector,
30
+ * so a crafted handle cannot change what a lookup matches.
31
+ */
32
+
33
+ /** Elements the walker considers actionable. */
34
+ declare const INTERACTIVE = "a[href], button, input, select, textarea, [role=button], [role=link], [role=checkbox], [role=tab], [data-co-handle]";
35
+ /** Every method the in-page agent answers. The wire protocol is exactly this list. */
36
+ declare const DOM_NAVIGATION_METHODS: readonly ["getLocation", "describe", "read", "visit", "back", "forward", "scrollTo", "scrollBy", "setField", "click", "submit", "rectFor"];
37
+ type DomNavigationMethod = (typeof DOM_NAVIGATION_METHODS)[number];
38
+ type ActionResult = {
39
+ ok: boolean;
40
+ error?: string;
41
+ };
42
+ type HandleRect = {
43
+ x: number;
44
+ y: number;
45
+ width: number;
46
+ height: number;
47
+ };
48
+ type FieldElement = HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement;
49
+ declare function isVisible(el: Element): boolean;
50
+ /** Sensitive fields whose value is never read into the snapshot. */
51
+ declare function isSensitive(el: Element): boolean;
52
+ declare function roleOf(el: Element): string;
53
+ declare function accessibleName(el: Element): string;
54
+ declare function isDestructive(el: Element, label: string): boolean;
55
+ /**
56
+ * The element's own stable handle: data-co-handle → name → id, or "" when it
57
+ * has none. An EMPTY attribute counts as absent — `button.name` is `""`, not
58
+ * null, on every button, anchor and input without one, so a plain `??` chain
59
+ * never reaches the id.
60
+ */
61
+ declare function attributeHandle(el: Element): string;
62
+ /**
63
+ * Build a fresh snapshot + a handle→element registry. Handle preference:
64
+ * data-co-handle → name → id → `role#index` (stable within a snapshot).
65
+ */
66
+ declare function walk(doc?: Document): {
67
+ snapshot: PageSnapshot;
68
+ registry: Map<string, Element>;
69
+ };
70
+ /**
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.
82
+ */
83
+ declare function setNativeValue(el: FieldElement, value: unknown): void;
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;
89
+ type DomNavigationAgentOptions = {
90
+ /** Document to drive. Default: the global `document`, read lazily. */
91
+ document?: Document;
92
+ /**
93
+ * Called just before the agent acts on the page — before resolving a field
94
+ * for `setField`, and after resolving (only when the element exists) for
95
+ * `click` / `submit`. The sandbox uses it to attribute the request an action
96
+ * causes to the agent.
97
+ */
98
+ beforeAction?: (action: "setField" | "click" | "submit") => void;
99
+ };
100
+ type DomNavigationAgent = {
101
+ getLocation(): {
102
+ url: string;
103
+ title: string;
104
+ };
105
+ describe(): PageSnapshot;
106
+ read(): PageReadout;
107
+ /** Navigate. Only http(s) or same-site paths; deferred a tick so a remote call returns first. */
108
+ visit(url: string): void;
109
+ back(): void;
110
+ forward(): void;
111
+ scrollTo(opts: {
112
+ x?: number;
113
+ y?: number;
114
+ handle?: string;
115
+ }): void;
116
+ scrollBy(dy: number): void;
117
+ setField(handle: string, value: unknown): ActionResult;
118
+ click(handle: string): ActionResult;
119
+ submit(handle: string): ActionResult;
120
+ rectFor(handle: string): HandleRect | null;
121
+ /** Element for a handle: this snapshot's registry, then a live attribute lookup. */
122
+ resolve(handle: string): Element | null;
123
+ /** Serialisable dispatch — what the injected script exposes to a host. */
124
+ call(method: DomNavigationMethod, args?: unknown[]): unknown;
125
+ };
126
+ declare function createDomNavigationAgent(options?: DomNavigationAgentOptions): DomNavigationAgent;
127
+
128
+ /**
129
+ * The host half: a {@link NavigationBridgeAdapter} that drives a page it does
130
+ * not run in, through any transport that can carry a method name and plain
131
+ * arguments into the page and a plain result back — Electron's
132
+ * `executeJavaScript` / `executeJavaScriptInIsolatedWorld`, a MessagePort, a
133
+ * WebSocket to a remote browser.
134
+ *
135
+ * Every result is treated as hostile: the page owns the DOM the in-page walker
136
+ * reads, and if the script was injected into the MAIN world the page can
137
+ * replace the walker outright. So results are coerced to the declared shapes
138
+ * here, and anything malformed is dropped rather than passed on to the agent.
139
+ */
140
+
141
+ /** The global the injected script installs in the world it runs in. */
142
+ declare const DOM_NAVIGATION_GLOBAL = "__fancyDomNavigation";
143
+ /** Bumped only if the wire protocol changes incompatibly. */
144
+ declare const DOM_NAVIGATION_PROTOCOL = 1;
145
+ /**
146
+ * Carries one call into the page. `args` and the resolved value are plain,
147
+ * structured-cloneable data. Reject (or throw) when the call could not be
148
+ * delivered — e.g. the page navigated and the script must be re-injected.
149
+ */
150
+ type DomNavigationTransport = {
151
+ call(method: DomNavigationMethod, args: unknown[]): Promise<unknown>;
152
+ };
153
+ type RemoteNavigationAdapterOptions = {
154
+ transport: DomNavigationTransport;
155
+ /** Optional fancy-screens screen id for presence targeting. */
156
+ screenId?: string;
157
+ /** Human-control revision, if the host tracks one. Omit to disable stale-intent protection. */
158
+ getRevision?: () => number | Promise<number>;
159
+ /**
160
+ * Trust-but-verify. Without it, `page_submit` and destructive `page_click`
161
+ * are NOT staged — they run as soon as the agent asks. A host showing pages
162
+ * it does not own should always supply one.
163
+ */
164
+ confirm?: (req: NavigationConfirmRequest) => Promise<boolean>;
165
+ };
166
+ /**
167
+ * A JavaScript expression that performs one call against the injected global —
168
+ * what a host passes to `executeJavaScript`. Arguments are embedded as JSON,
169
+ * which is a valid JS expression, so no argument can break out of its literal.
170
+ */
171
+ declare function domNavigationCallScript(method: DomNavigationMethod, args?: unknown[]): string;
172
+ /** Build a NavigationBridgeAdapter backed by a transport into the page. */
173
+ declare function createRemoteNavigationAdapter(options: RemoteNavigationAdapterOptions): NavigationBridgeAdapter;
174
+
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 };