@amd-gaia/agent-ui 0.26.1-rc.2 → 0.27.0-rc.2

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 (56) hide show
  1. package/dist/assets/AdvancedSettings-DHERtrno.js +1 -0
  2. package/dist/assets/AutomationsSettings-4FWcRau9.js +1 -0
  3. package/dist/assets/ConnectorsPane-BGI8nBUb.css +1 -0
  4. package/dist/assets/ConnectorsPane-Dkat1zLC.js +1 -0
  5. package/dist/assets/DocumentLibrary-Dll55N7l.js +5 -0
  6. package/dist/assets/DocumentLibrary-fEMoY7lH.css +1 -0
  7. package/dist/assets/FileBrowser-1goNp4CP.css +1 -0
  8. package/dist/assets/FileBrowser-wFHqH6K_.js +4 -0
  9. package/dist/assets/MemoryDashboard-BuUBoNq8.js +1 -0
  10. package/dist/assets/MemoryDashboard-RpfLag-v.css +1 -0
  11. package/dist/assets/MessagingSettings-DomiT2rX.js +1 -0
  12. package/dist/assets/MobileAccessModal-B2gaE8nk.js +2 -0
  13. package/dist/assets/{MobileAccessModal-CX4NZmr4.css → MobileAccessModal-BrZMaERi.css} +1 -1
  14. package/dist/assets/ScheduleManager-8UE81KlQ.js +1 -0
  15. package/dist/assets/ScheduleManager-BZzEH2-W.css +1 -0
  16. package/dist/assets/Temml-CCjoacWt.woff2 +0 -0
  17. package/dist/assets/index-BiETDNik.css +1 -0
  18. package/dist/assets/index-HCZ86cyP.js +220 -0
  19. package/dist/assets/useFocusTrap-BFi0chLf.js +6 -0
  20. package/dist/assets/zap-DjkIffnX.js +1 -0
  21. package/dist/index.html +3 -3
  22. package/dist/sw.js +1 -1
  23. package/main.cjs +130 -40
  24. package/package.json +5 -3
  25. package/preload.cjs +28 -0
  26. package/services/browser-pane/bridge-error.cjs +20 -0
  27. package/services/browser-pane/bridge-server.cjs +496 -0
  28. package/services/browser-pane/cdp-session.cjs +375 -0
  29. package/services/browser-pane/contract.d.ts +448 -0
  30. package/services/browser-pane/dev-servers.cjs +478 -0
  31. package/services/browser-pane/input.cjs +375 -0
  32. package/services/browser-pane/ipc.cjs +267 -0
  33. package/services/browser-pane/navigation-policy.cjs +255 -0
  34. package/services/browser-pane/pane-host.cjs +1686 -0
  35. package/services/browser-pane/picker-world.js +360 -0
  36. package/services/browser-pane/picker.cjs +261 -0
  37. package/services/browser-pane/service-ports.cjs +66 -0
  38. package/services/dev-qa-mode.cjs +32 -0
  39. package/dist/assets/AdvancedSettings-C-9ErldS.js +0 -1
  40. package/dist/assets/AutomationsSettings-CL3K4hLZ.js +0 -1
  41. package/dist/assets/ConnectorsPane-DpGR78cA.js +0 -1
  42. package/dist/assets/ConnectorsPane-w-HLcq3n.css +0 -1
  43. package/dist/assets/DocumentLibrary-BKZdx6rJ.css +0 -1
  44. package/dist/assets/DocumentLibrary-N7tBbt9v.js +0 -5
  45. package/dist/assets/FileBrowser-CO2p3xa2.js +0 -4
  46. package/dist/assets/FileBrowser-CrRQXiPo.css +0 -1
  47. package/dist/assets/MemoryDashboard-1OIrKFIa.js +0 -1
  48. package/dist/assets/MemoryDashboard-B4AO_CU8.css +0 -1
  49. package/dist/assets/MessagingSettings-0AJnsoWA.js +0 -1
  50. package/dist/assets/MobileAccessModal-CnPB1BEN.js +0 -2
  51. package/dist/assets/ScheduleManager-BYOhqnfv.js +0 -1
  52. package/dist/assets/ScheduleManager-DQBnf_IN.css +0 -1
  53. package/dist/assets/index-Bkx-QRv4.css +0 -1
  54. package/dist/assets/index-C-3wCH_s.js +0 -116
  55. package/dist/assets/useT-DuzpQY8p.js +0 -6
  56. package/dist/assets/zap-gF9QDKfa.js +0 -1
@@ -0,0 +1,375 @@
1
+ // Copyright(C) 2026 Advanced Micro Devices, Inc. All rights reserved.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ /**
5
+ * One tab's Chrome DevTools Protocol attachment, through webContents.debugger,
6
+ * never a debugging port. It keeps the tab's console and network activity in
7
+ * two bounded rings from the moment the tab opens, so the agent can read what
8
+ * happened before it was asked, and takes screenshots through
9
+ * Page.captureScreenshot, which stays fresh while the view is hidden.
10
+ */
11
+
12
+ "use strict";
13
+
14
+ /** @typedef {import("./contract").LogEntry} LogEntry */
15
+ /** @typedef {import("./contract").NetworkEntry} NetworkEntry */
16
+
17
+ const PROTOCOL_VERSION = "1.3";
18
+ const RING_SIZE = 500;
19
+ const MAX_TEXT = 500;
20
+ const MAX_URL = 300;
21
+ const MAX_PENDING_REQUESTS = 1000;
22
+ const MAX_FRAME_DEPTH = 16;
23
+ const AUTO_ATTACH = { autoAttach: true, waitForDebuggerOnStart: false, flatten: true };
24
+
25
+ const CONSOLE_LEVELS = {
26
+ error: "error",
27
+ assert: "error",
28
+ warning: "warning",
29
+ info: "info",
30
+ log: "log",
31
+ debug: "log",
32
+ verbose: "log",
33
+ };
34
+
35
+ function truncate(text, max) {
36
+ const s = String(text ?? "");
37
+ return s.length > max ? `${s.slice(0, max)}…` : s;
38
+ }
39
+
40
+ /** A bounded log whose entries carry a per-tab sequence number, the reader's cursor. */
41
+ class Ring {
42
+ constructor(capacity = RING_SIZE) {
43
+ this.capacity = capacity;
44
+ /** @type {Array<{ seq: number }>} */
45
+ this.entries = [];
46
+ this.nextSeq = 1;
47
+ }
48
+
49
+ push(entry) {
50
+ const stamped = { seq: this.nextSeq++, ...entry };
51
+ this.entries.push(stamped);
52
+ if (this.entries.length > this.capacity) this.entries.shift();
53
+ return stamped;
54
+ }
55
+
56
+ clear() {
57
+ this.entries = [];
58
+ }
59
+
60
+ /**
61
+ * @param {{ afterSeq: number, limit: number, keep: (e: object) => boolean }} q
62
+ * @returns {{ entries: object[], lastSeq: number, dropped: number }}
63
+ */
64
+ query({ afterSeq, limit, keep }) {
65
+ const lastSeq = this.nextSeq - 1;
66
+ const oldest = this.entries.length ? this.entries[0].seq : this.nextSeq;
67
+ const dropped = Math.max(0, oldest - afterSeq - 1);
68
+ const matching = this.entries.filter((e) => e.seq > afterSeq && keep(e));
69
+ return { entries: matching.slice(-limit), lastSeq, dropped };
70
+ }
71
+ }
72
+
73
+ function remoteText(arg) {
74
+ if (!arg) return "";
75
+ if (arg.value !== undefined) return typeof arg.value === "string" ? arg.value : JSON.stringify(arg.value);
76
+ return arg.unserializableValue || arg.description || arg.type || "";
77
+ }
78
+
79
+ function sourceOf(url, lineNumber) {
80
+ if (!url) return undefined;
81
+ return typeof lineNumber === "number" ? `${url}:${lineNumber + 1}` : url;
82
+ }
83
+
84
+ /**
85
+ * @param {string} method
86
+ * @param {any} params
87
+ * @returns {Omit<LogEntry, "seq"> | null}
88
+ */
89
+ function consoleEntry(method, params) {
90
+ const at = Date.now();
91
+ if (method === "Runtime.consoleAPICalled") {
92
+ const frame = params.stackTrace && params.stackTrace.callFrames && params.stackTrace.callFrames[0];
93
+ return {
94
+ at,
95
+ level: CONSOLE_LEVELS[params.type] || "log",
96
+ text: truncate((params.args || []).map(remoteText).join(" "), MAX_TEXT),
97
+ source: frame ? sourceOf(frame.url, frame.lineNumber) : undefined,
98
+ };
99
+ }
100
+ if (method === "Runtime.exceptionThrown") {
101
+ const d = params.exceptionDetails || {};
102
+ const text = (d.exception && d.exception.description) || d.text || "Uncaught exception";
103
+ return { at, level: "error", text: truncate(text, MAX_TEXT), source: sourceOf(d.url, d.lineNumber) };
104
+ }
105
+ if (method === "Log.entryAdded") {
106
+ const e = params.entry || {};
107
+ return {
108
+ at,
109
+ level: CONSOLE_LEVELS[e.level] || "log",
110
+ text: truncate(e.text, MAX_TEXT),
111
+ source: sourceOf(e.url, e.lineNumber),
112
+ };
113
+ }
114
+ return null;
115
+ }
116
+
117
+ class TabCdp {
118
+ /**
119
+ * @param {Electron.WebContents} webContents
120
+ * @param {{ error: (...args: any[]) => void }} [logger]
121
+ */
122
+ constructor(webContents, logger = console) {
123
+ this.wc = webContents;
124
+ this.logger = logger;
125
+ this.console = new Ring();
126
+ this.network = new Ring();
127
+ /** @type {Map<string, { method: string, url: string, resourceType: string, startedAt: number, status: number | null }>} */
128
+ this.pending = new Map();
129
+ this.attached = false;
130
+ this.detachReason = null;
131
+ /** @type {Set<(params: any) => void>} */
132
+ this.bindingListeners = new Set();
133
+ /** Child sessions for out-of-process frames: sessionId -> the session that attached it. */
134
+ this.sessions = new Map();
135
+ this.ready = this.attach();
136
+ }
137
+
138
+ async attach() {
139
+ const dbg = this.wc.debugger;
140
+ try {
141
+ dbg.attach(PROTOCOL_VERSION);
142
+ this.attached = true;
143
+ dbg.on("message", (_event, method, params, sessionId) => {
144
+ if (sessionId) this.onChildMessage(method, params || {}, sessionId);
145
+ else this.onMessage(method, params || {});
146
+ });
147
+ dbg.on("detach", (_event, reason) => {
148
+ this.attached = false;
149
+ this.detachReason = reason;
150
+ });
151
+ await Promise.all([dbg.sendCommand("Runtime.enable"), dbg.sendCommand("Log.enable"), dbg.sendCommand("Network.enable")]);
152
+ // Out-of-process frames get sessions of their own, so a hit test can follow a point into them.
153
+ await dbg.sendCommand("Target.setAutoAttach", AUTO_ATTACH);
154
+ } catch (err) {
155
+ this.attached = false;
156
+ this.detachReason = err.message;
157
+ this.logger.error(`[browser-pane] Could not attach DevTools protocol to a tab: ${err.message}`);
158
+ }
159
+ }
160
+
161
+ /** A new page starts with empty logs, as DevTools does without "Preserve log". */
162
+ onNavigationStarted() {
163
+ this.console.clear();
164
+ this.network.clear();
165
+ this.pending.clear();
166
+ }
167
+
168
+ /** Calls `fn` with each Runtime.bindingCalled event; returns its unsubscribe. */
169
+ onBinding(fn) {
170
+ this.bindingListeners.add(fn);
171
+ return () => this.bindingListeners.delete(fn);
172
+ }
173
+
174
+ onMessage(method, params) {
175
+ if (method === "Target.attachedToTarget" || method === "Target.detachedFromTarget") {
176
+ this.onChildMessage(method, params, null);
177
+ return;
178
+ }
179
+ if (method === "Runtime.bindingCalled") {
180
+ for (const fn of this.bindingListeners) fn(params);
181
+ return;
182
+ }
183
+ const entry = consoleEntry(method, params);
184
+ if (entry) {
185
+ this.console.push(entry);
186
+ return;
187
+ }
188
+ if (method === "Network.requestWillBeSent") this.requestStarted(params);
189
+ else if (method === "Network.responseReceived") {
190
+ const req = this.pending.get(params.requestId);
191
+ if (req) req.status = params.response ? params.response.status : null;
192
+ } else if (method === "Network.loadingFinished") this.requestEnded(params.requestId, null);
193
+ else if (method === "Network.loadingFailed") {
194
+ this.requestEnded(params.requestId, params.canceled ? "canceled" : params.errorText || "failed");
195
+ }
196
+ }
197
+
198
+ requestStarted(params) {
199
+ const url = (params.request && params.request.url) || "";
200
+ if (url.startsWith("data:")) return;
201
+ if (params.redirectResponse) {
202
+ const hop = this.pending.get(params.requestId);
203
+ if (hop) {
204
+ hop.status = params.redirectResponse.status;
205
+ this.requestEnded(params.requestId, null);
206
+ }
207
+ }
208
+ if (this.pending.size >= MAX_PENDING_REQUESTS) this.pending.delete(this.pending.keys().next().value);
209
+ this.pending.set(params.requestId, {
210
+ method: (params.request && params.request.method) || "GET",
211
+ url,
212
+ resourceType: params.type || "Other",
213
+ startedAt: Date.now(),
214
+ status: null,
215
+ });
216
+ }
217
+
218
+ requestEnded(requestId, failure) {
219
+ const req = this.pending.get(requestId);
220
+ if (!req) return;
221
+ this.pending.delete(requestId);
222
+ /** @type {Omit<NetworkEntry, "seq">} */
223
+ const entry = {
224
+ at: req.startedAt,
225
+ method: req.method,
226
+ url: truncate(req.url, MAX_URL),
227
+ status: failure ? null : req.status,
228
+ resourceType: req.resourceType,
229
+ durationMs: Date.now() - req.startedAt,
230
+ };
231
+ if (failure) entry.failure = failure;
232
+ this.network.push(entry);
233
+ }
234
+
235
+ /**
236
+ * @param {{ kind: "console" | "network", afterSeq: number, errorsOnly: boolean, pattern: string | null, limit: number }} q
237
+ */
238
+ logs({ kind, afterSeq, errorsOnly, pattern, limit }) {
239
+ const needle = pattern ? pattern.toLowerCase() : null;
240
+ const isConsole = kind === "console";
241
+ const keep = (e) => {
242
+ if (errorsOnly && (isConsole ? e.level !== "error" : e.status !== null && e.status < 400)) return false;
243
+ if (!needle) return true;
244
+ const hay = isConsole ? `${e.text} ${e.source || ""}` : `${e.method} ${e.url} ${e.status ?? ""} ${e.failure || ""}`;
245
+ return hay.toLowerCase().includes(needle);
246
+ };
247
+ return (isConsole ? this.console : this.network).query({ afterSeq, limit, keep });
248
+ }
249
+
250
+ /** One CDP command on this tab, once attached. */
251
+ async send(method, params = {}, sessionId = null) {
252
+ await this.ready;
253
+ if (!this.attached) {
254
+ throw new Error(`the DevTools protocol is not attached to this tab (${this.detachReason || "unknown reason"})`);
255
+ }
256
+ return sessionId ? this.wc.debugger.sendCommand(method, params, sessionId) : this.wc.debugger.sendCommand(method, params);
257
+ }
258
+
259
+ /** Track the sessions of out-of-process frames, and attach to their own frames in turn. */
260
+ onChildMessage(method, params, parentSession) {
261
+ if (method === "Target.attachedToTarget" && params.targetInfo && params.targetInfo.type === "iframe") {
262
+ this.sessions.set(params.sessionId, parentSession);
263
+ this.wc.debugger.sendCommand("Target.setAutoAttach", AUTO_ATTACH, params.sessionId).catch((err) => {
264
+ this.logger.error(`[browser-pane] Could not follow the frames inside an out-of-process frame: ${err.message}`);
265
+ });
266
+ } else if (method === "Target.detachedFromTarget") {
267
+ this.sessions.delete(params.sessionId);
268
+ }
269
+ }
270
+
271
+ /**
272
+ * Every frame on the page as Chromium lays it out, from this tab's session
273
+ * and its frames' own: frameId -> { sessionId, parentId, url }. Read in the
274
+ * browser, so nothing the page runs can change the answer.
275
+ */
276
+ async frameMap() {
277
+ const frames = new Map();
278
+ for (const sessionId of [null, ...this.sessions.keys()]) {
279
+ let tree;
280
+ try {
281
+ ({ frameTree: tree } = await this.send("Page.getFrameTree", {}, sessionId));
282
+ } catch (err) {
283
+ if (sessionId && !this.sessions.has(sessionId)) continue; // detached while we looked
284
+ throw err;
285
+ }
286
+ const walk = (node) => {
287
+ frames.set(node.frame.id, { sessionId, parentId: node.frame.parentId || null, url: node.frame.url || "" });
288
+ for (const child of node.childFrames || []) walk(child);
289
+ };
290
+ walk(tree);
291
+ }
292
+ return frames;
293
+ }
294
+
295
+ /**
296
+ * The site a point in the page's viewport lands on: the innermost frame
297
+ * under it, followed into out-of-process frames, as an http(s) origin or
298
+ * null. A trusted click goes there whatever the page's own scripts claim.
299
+ */
300
+ async landingOrigin(x, y) {
301
+ const frames = await this.frameMap();
302
+ let sessionId = null;
303
+ for (let depth = 0; depth < MAX_FRAME_DEPTH; depth += 1) {
304
+ await this.send("DOM.getDocument", { depth: 0 }, sessionId);
305
+ const hit = await this.send("DOM.getNodeForLocation", { x: Math.round(x), y: Math.round(y), includeUserAgentShadowDOM: true, ignorePointerEventsNone: false }, sessionId);
306
+ const { node } = await this.send("DOM.describeNode", { backendNodeId: hit.backendNodeId }, sessionId);
307
+ const inner = node.frameId && node.frameId !== hit.frameId ? frames.get(node.frameId) : null;
308
+ if (!inner || inner.sessionId === sessionId) return siteOf(frames, inner ? node.frameId : hit.frameId);
309
+ const { model } = await this.send("DOM.getBoxModel", { backendNodeId: hit.backendNodeId }, sessionId);
310
+ x -= model.content[0];
311
+ y -= model.content[1];
312
+ sessionId = inner.sessionId;
313
+ }
314
+ return null;
315
+ }
316
+
317
+ /**
318
+ * The sites of frames a picture of the page would show that `allowed`
319
+ * doesn't cover, outermost only: a frame with no box (hidden, or no size)
320
+ * shows nothing and is left out.
321
+ */
322
+ async shownUnapprovedSites(allowed) {
323
+ const frames = await this.frameMap();
324
+ const approved = (id) => {
325
+ const site = siteOf(frames, id);
326
+ return site !== null && allowed.includes(site);
327
+ };
328
+ const sites = [];
329
+ for (const [id, f] of frames) {
330
+ if (!f.parentId || approved(id) || !approved(f.parentId)) continue;
331
+ const parent = frames.get(f.parentId);
332
+ if (!parent) continue;
333
+ let model = null;
334
+ try {
335
+ const owner = await this.send("DOM.getFrameOwner", { frameId: id }, parent.sessionId);
336
+ ({ model } = await this.send("DOM.getBoxModel", { backendNodeId: owner.backendNodeId }, parent.sessionId));
337
+ } catch (err) {
338
+ if (!/box model|No node|not found/i.test(err.message)) throw err;
339
+ }
340
+ if (model && model.width * model.height > 0) sites.push(siteOf(frames, id));
341
+ }
342
+ return sites;
343
+ }
344
+
345
+ /**
346
+ * PNG of the viewport, or of `clip` (CSS pixels relative to the page) when given.
347
+ * @returns {Promise<Buffer>}
348
+ */
349
+ async screenshot(clip) {
350
+ const params = { format: "png", captureBeyondViewport: Boolean(clip) };
351
+ if (clip) params.clip = { ...clip, scale: 1 };
352
+ const { data } = await this.send("Page.captureScreenshot", params);
353
+ return Buffer.from(data, "base64");
354
+ }
355
+ }
356
+
357
+ /**
358
+ * The http(s) origin a frame's content belongs to, or null. A blank or srcdoc
359
+ * frame holds what the frame around it wrote, so it counts as that frame.
360
+ */
361
+ function siteOf(frames, id) {
362
+ for (let f = frames.get(id), hops = 0; f && hops < MAX_FRAME_DEPTH; f = frames.get(f.parentId), hops += 1) {
363
+ let url;
364
+ try {
365
+ url = new URL(f.url);
366
+ } catch {
367
+ return null;
368
+ }
369
+ if (url.protocol === "http:" || url.protocol === "https:") return url.origin;
370
+ if (url.href !== "about:blank" && url.href !== "about:srcdoc") return null;
371
+ }
372
+ return null;
373
+ }
374
+
375
+ module.exports = { Ring, TabCdp, consoleEntry, siteOf, RING_SIZE };