dsh-agent-enhancer 0.3.16 → 0.3.17
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/README.en.md +2 -2
- package/README.md +2 -2
- package/lib/client/browser-agent/approval-keys.d.ts +20 -0
- package/lib/client/browser-agent/approval-keys.d.ts.map +1 -0
- package/lib/client/browser-agent/banner-geometry.d.ts +13 -0
- package/lib/client/browser-agent/banner-geometry.d.ts.map +1 -0
- package/lib/client/browser-agent/overlay.d.ts.map +1 -1
- package/lib/client/locales.d.ts +9 -5
- package/lib/client/locales.d.ts.map +1 -1
- package/lib/client/remote.d.ts +4 -1
- package/lib/client/remote.d.ts.map +1 -1
- package/lib/client.js +187 -22
- package/lib/client.js.map +1 -1
- package/lib/host/browser-agent/approval-thumbnail.d.ts +36 -0
- package/lib/host/browser-agent/approval-thumbnail.d.ts.map +1 -0
- package/lib/host/browser-agent/approval.d.ts +15 -0
- package/lib/host/browser-agent/approval.d.ts.map +1 -1
- package/lib/host/browser-agent/demo-replay.d.ts +76 -0
- package/lib/host/browser-agent/demo-replay.d.ts.map +1 -0
- package/lib/host/browser-agent/demo.d.ts +33 -5
- package/lib/host/browser-agent/demo.d.ts.map +1 -1
- package/lib/host/browser-agent/driver.d.ts +7 -0
- package/lib/host/browser-agent/driver.d.ts.map +1 -1
- package/lib/host/browser-agent/playwright-driver.d.ts +13 -4
- package/lib/host/browser-agent/playwright-driver.d.ts.map +1 -1
- package/lib/host/browser-agent/prompt.d.ts.map +1 -1
- package/lib/host/browser-agent/tools.d.ts.map +1 -1
- package/lib/host/index.d.ts +2 -1
- package/lib/host/index.d.ts.map +1 -1
- package/lib/host/rpc.d.ts +23 -0
- package/lib/host/rpc.d.ts.map +1 -1
- package/lib/index.js +517 -109
- package/lib/index.js.map +4 -4
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -278,6 +278,10 @@ var BrowserApprovalGate = class {
|
|
|
278
278
|
const first = this.pending.values().next().value;
|
|
279
279
|
return first?.request ?? null;
|
|
280
280
|
}
|
|
281
|
+
/** Crop for one pending approval, or null when it is gone or had none. */
|
|
282
|
+
thumbnailFor(id) {
|
|
283
|
+
return this.pending.get(id)?.request.thumbnail ?? null;
|
|
284
|
+
}
|
|
281
285
|
/**
|
|
282
286
|
* Returns true when the action may proceed without prompting.
|
|
283
287
|
* Read-only tools should skip this gate entirely.
|
|
@@ -299,7 +303,8 @@ var BrowserApprovalGate = class {
|
|
|
299
303
|
tool: input.tool,
|
|
300
304
|
summary: input.summary,
|
|
301
305
|
...input.url === void 0 ? {} : { url: input.url },
|
|
302
|
-
...origin === void 0 ? {} : { origin }
|
|
306
|
+
...origin === void 0 ? {} : { origin },
|
|
307
|
+
...input.thumbnail === void 0 ? {} : { thumbnail: input.thumbnail }
|
|
303
308
|
};
|
|
304
309
|
const decision = await new Promise((resolve17, reject) => {
|
|
305
310
|
const onAbort = () => {
|
|
@@ -1013,14 +1018,78 @@ async function capturePlaywrightSnapshot(page, options = {}) {
|
|
|
1013
1018
|
return { body, refs };
|
|
1014
1019
|
}
|
|
1015
1020
|
|
|
1021
|
+
// src/host/browser-agent/capture.ts
|
|
1022
|
+
var SECRET_PARAM = /^(access_?token|id_?token|auth|authorization|code|key|password|secret|session|sessionid|sig|signature|token)$/i;
|
|
1023
|
+
var URL_IN_TEXT = /https?:\/\/[^\s"'<>]+/g;
|
|
1024
|
+
function redactUrl(raw) {
|
|
1025
|
+
const withoutUserInfo = raw.replace(/^([a-z][a-z0-9+.-]*:\/\/)[^/?#@]*@/i, "$1");
|
|
1026
|
+
const withoutFragment = withoutUserInfo.replace(/#.*$/, "");
|
|
1027
|
+
const masked = withoutFragment.replace(
|
|
1028
|
+
/([?&])([^=&#]+)=([^&#]*)/g,
|
|
1029
|
+
(match, separator, key) => SECRET_PARAM.test(decodeURIComponent(key)) ? `${separator}${key}=***` : match
|
|
1030
|
+
);
|
|
1031
|
+
return masked.length > 300 ? `${masked.slice(0, 300)}\u2026` : masked;
|
|
1032
|
+
}
|
|
1033
|
+
function redactText(text3) {
|
|
1034
|
+
return text3.replace(URL_IN_TEXT, (match) => {
|
|
1035
|
+
const trailing = match.match(/[),.;]+$/)?.[0] ?? "";
|
|
1036
|
+
const core = trailing === "" ? match : match.slice(0, -trailing.length);
|
|
1037
|
+
return `${redactUrl(core)}${trailing}`;
|
|
1038
|
+
});
|
|
1039
|
+
}
|
|
1040
|
+
var CaptureBuffer = class {
|
|
1041
|
+
constructor(max = 300) {
|
|
1042
|
+
this.max = max;
|
|
1043
|
+
}
|
|
1044
|
+
max;
|
|
1045
|
+
entries = [];
|
|
1046
|
+
dropped = 0;
|
|
1047
|
+
get size() {
|
|
1048
|
+
return this.entries.length;
|
|
1049
|
+
}
|
|
1050
|
+
push(entry) {
|
|
1051
|
+
this.entries.push(entry);
|
|
1052
|
+
while (this.entries.length > this.max) {
|
|
1053
|
+
this.entries.shift();
|
|
1054
|
+
this.dropped += 1;
|
|
1055
|
+
}
|
|
1056
|
+
}
|
|
1057
|
+
/** Newest `limit` entries of the requested kind, optionally clearing them. */
|
|
1058
|
+
read(kind, options = {}) {
|
|
1059
|
+
const limit = Math.min(Math.max(Math.trunc(options.limit ?? 40), 1), 200);
|
|
1060
|
+
const ofKind = this.entries.filter((entry) => kind === "all" || entry.kind === (kind === "network" ? "request" : "console"));
|
|
1061
|
+
const matched = options.tabId === void 0 ? ofKind : ofKind.filter((entry) => entry.tabId === options.tabId);
|
|
1062
|
+
const skipped = ofKind.length - matched.length;
|
|
1063
|
+
const selected = matched.slice(-limit);
|
|
1064
|
+
if (options.clear === true) {
|
|
1065
|
+
const keep = this.entries.filter((entry) => !selected.includes(entry));
|
|
1066
|
+
this.entries.length = 0;
|
|
1067
|
+
this.entries.push(...keep);
|
|
1068
|
+
}
|
|
1069
|
+
return { entries: selected, dropped: this.dropped, skipped };
|
|
1070
|
+
}
|
|
1071
|
+
clear() {
|
|
1072
|
+
this.entries.length = 0;
|
|
1073
|
+
this.dropped = 0;
|
|
1074
|
+
}
|
|
1075
|
+
};
|
|
1076
|
+
|
|
1016
1077
|
// src/host/browser-agent/demo.ts
|
|
1078
|
+
function attachDemoTab(step, site) {
|
|
1079
|
+
if (site.tabId === void 0) return step;
|
|
1080
|
+
return {
|
|
1081
|
+
...step,
|
|
1082
|
+
tabId: site.tabId,
|
|
1083
|
+
...site.tabUrl === void 0 ? {} : { tabUrl: site.tabUrl }
|
|
1084
|
+
};
|
|
1085
|
+
}
|
|
1017
1086
|
var SECRET_FIELD = /pass(word)?|\bpw\b|\bpwd\b|otp|one[-_]?time|code|pin|cvv|cvc|secret|token|card[-_]?number|iban/i;
|
|
1018
1087
|
function isSensitiveFieldName(...parts) {
|
|
1019
1088
|
return parts.some((part) => typeof part === "string" && SECRET_FIELD.test(part));
|
|
1020
1089
|
}
|
|
1021
1090
|
function pushDemoStep(steps, step, windowMs = 1500) {
|
|
1022
1091
|
const last = steps[steps.length - 1];
|
|
1023
|
-
if (last !== void 0 && step.at - last.at <= windowMs) {
|
|
1092
|
+
if (last !== void 0 && last.tabId === step.tabId && step.at - last.at <= windowMs) {
|
|
1024
1093
|
if (last.kind === "fill" && step.kind === "fill" && last.selector === step.selector) {
|
|
1025
1094
|
steps[steps.length - 1] = step;
|
|
1026
1095
|
return;
|
|
@@ -1044,6 +1113,7 @@ function mergeDemoSteps(pageSteps, navSteps) {
|
|
|
1044
1113
|
return out;
|
|
1045
1114
|
}
|
|
1046
1115
|
function sameStep(a, b) {
|
|
1116
|
+
if (a.tabId !== b.tabId) return false;
|
|
1047
1117
|
if (a.kind !== b.kind) return false;
|
|
1048
1118
|
if (a.kind === "navigate" && b.kind === "navigate") return a.url === b.url;
|
|
1049
1119
|
if (a.kind === "click" && b.kind === "click") return a.selector === b.selector;
|
|
@@ -1053,39 +1123,66 @@ function sameStep(a, b) {
|
|
|
1053
1123
|
}
|
|
1054
1124
|
function sanitizeDemoSteps(steps) {
|
|
1055
1125
|
return steps.map((step) => {
|
|
1126
|
+
if (step.kind === "navigate") {
|
|
1127
|
+
const url = redactUrl(step.url);
|
|
1128
|
+
return url === step.url ? step : { ...step, url };
|
|
1129
|
+
}
|
|
1056
1130
|
if (step.kind !== "fill") return step;
|
|
1057
1131
|
if (step.masked || !isSensitiveFieldName(step.field, step.name, step.selector)) return step;
|
|
1058
1132
|
return { ...step, value: "***", masked: true };
|
|
1059
1133
|
});
|
|
1060
1134
|
}
|
|
1135
|
+
function describeDemoStep(step) {
|
|
1136
|
+
switch (step.kind) {
|
|
1137
|
+
case "navigate":
|
|
1138
|
+
return `navigate -> ${step.url}`;
|
|
1139
|
+
case "click":
|
|
1140
|
+
return `click ${step.role} ${JSON.stringify(step.name)}${step.href === void 0 ? "" : ` (href ${step.href})`} [selector ${step.selector}]`;
|
|
1141
|
+
case "fill": {
|
|
1142
|
+
const value = step.masked ? "***" : JSON.stringify(step.value);
|
|
1143
|
+
const checked = step.checked === void 0 ? "" : ` checked=${String(step.checked)}`;
|
|
1144
|
+
return `fill ${step.role} ${JSON.stringify(step.name)} = ${value}${checked} [selector ${step.selector}]`;
|
|
1145
|
+
}
|
|
1146
|
+
case "press":
|
|
1147
|
+
return `press ${step.key} [selector ${step.selector}]`;
|
|
1148
|
+
default: {
|
|
1149
|
+
const exhaustive = step;
|
|
1150
|
+
return JSON.stringify(exhaustive);
|
|
1151
|
+
}
|
|
1152
|
+
}
|
|
1153
|
+
}
|
|
1061
1154
|
function summarizeDemoSteps(steps, max = 40) {
|
|
1062
1155
|
const shown = steps.slice(0, Math.max(1, max));
|
|
1156
|
+
const tabs = collectTabs(shown);
|
|
1157
|
+
const multiTab = tabs.length > 1;
|
|
1063
1158
|
const lines = shown.map((step, index) => {
|
|
1064
1159
|
const n = index + 1;
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
return `${n}. navigate -> ${step.url}`;
|
|
1068
|
-
case "click":
|
|
1069
|
-
return `${n}. click ${step.role} ${JSON.stringify(step.name)}${step.href === void 0 ? "" : ` (href ${step.href})`} [selector ${step.selector}]`;
|
|
1070
|
-
case "fill": {
|
|
1071
|
-
const value = step.masked ? "***" : JSON.stringify(step.value);
|
|
1072
|
-
const checked = step.checked === void 0 ? "" : ` checked=${String(step.checked)}`;
|
|
1073
|
-
return `${n}. fill ${step.role} ${JSON.stringify(step.name)} = ${value}${checked} [selector ${step.selector}]`;
|
|
1074
|
-
}
|
|
1075
|
-
case "press":
|
|
1076
|
-
return `${n}. press ${step.key} [selector ${step.selector}]`;
|
|
1077
|
-
default: {
|
|
1078
|
-
const exhaustive = step;
|
|
1079
|
-
return `${n}. ${JSON.stringify(exhaustive)}`;
|
|
1080
|
-
}
|
|
1081
|
-
}
|
|
1160
|
+
const tag = multiTab && step.tabId !== void 0 ? `[tab ${step.tabId}] ` : "";
|
|
1161
|
+
return `${n}. ${tag}${describeDemoStep(step)}`;
|
|
1082
1162
|
});
|
|
1083
1163
|
return {
|
|
1084
1164
|
lines,
|
|
1085
1165
|
shown: shown.length,
|
|
1086
|
-
masked: shown.filter((step) => step.kind === "fill" && step.masked).length
|
|
1166
|
+
masked: shown.filter((step) => step.kind === "fill" && step.masked).length,
|
|
1167
|
+
tabs,
|
|
1168
|
+
multiTab
|
|
1087
1169
|
};
|
|
1088
1170
|
}
|
|
1171
|
+
function collectTabs(steps) {
|
|
1172
|
+
const seen = /* @__PURE__ */ new Map();
|
|
1173
|
+
for (const step of steps) {
|
|
1174
|
+
if (step.tabId === void 0 || seen.has(step.tabId)) continue;
|
|
1175
|
+
seen.set(step.tabId, { tabId: step.tabId, ...step.tabUrl === void 0 ? {} : { url: step.tabUrl } });
|
|
1176
|
+
}
|
|
1177
|
+
return [...seen.values()];
|
|
1178
|
+
}
|
|
1179
|
+
function demoTabLegend(summary) {
|
|
1180
|
+
if (!summary.multiTab) return [];
|
|
1181
|
+
return [
|
|
1182
|
+
`tabs: ${summary.tabs.length} (each step is tagged with the tab it happened in)`,
|
|
1183
|
+
...summary.tabs.map((tab) => `tab ${tab.tabId}: ${tab.url ?? "(url unknown)"}`)
|
|
1184
|
+
];
|
|
1185
|
+
}
|
|
1089
1186
|
var DEMO_SYMBOL = "Symbol.for('dsh-demo')";
|
|
1090
1187
|
var DEMO_RECORDER_SOURCE = `"use strict";
|
|
1091
1188
|
var KEY = ${DEMO_SYMBOL};
|
|
@@ -1149,6 +1246,33 @@ function on(target, type, handler, capture) {
|
|
|
1149
1246
|
target.addEventListener(type, handler, capture === true);
|
|
1150
1247
|
OFF.push(function () { target.removeEventListener(type, handler, capture === true); });
|
|
1151
1248
|
}
|
|
1249
|
+
// Single-page apps change the URL without loading a document, so the driver's
|
|
1250
|
+
// framenavigated never fires. Patch the history API and listen for the events
|
|
1251
|
+
// the browser dispatches for back/forward and hash routes.
|
|
1252
|
+
var lastUrl = String(location.href || "");
|
|
1253
|
+
function routeStep() {
|
|
1254
|
+
var url = String(location.href || "");
|
|
1255
|
+
if (url === lastUrl) return;
|
|
1256
|
+
lastUrl = url;
|
|
1257
|
+
if (!/^https?:\\/\\//i.test(url)) return;
|
|
1258
|
+
push({ kind: "navigate", url: url });
|
|
1259
|
+
}
|
|
1260
|
+
function wrapHistory(name) {
|
|
1261
|
+
var original = history[name];
|
|
1262
|
+
if (typeof original !== "function") return;
|
|
1263
|
+
try {
|
|
1264
|
+
history[name] = function () {
|
|
1265
|
+
var result = original.apply(this, arguments);
|
|
1266
|
+
try { setTimeout(routeStep, 0); } catch (e) { }
|
|
1267
|
+
return result;
|
|
1268
|
+
};
|
|
1269
|
+
OFF.push(function () { try { history[name] = original; } catch (e) { } });
|
|
1270
|
+
} catch (e) { }
|
|
1271
|
+
}
|
|
1272
|
+
wrapHistory("pushState");
|
|
1273
|
+
wrapHistory("replaceState");
|
|
1274
|
+
on(window, "popstate", routeStep);
|
|
1275
|
+
on(window, "hashchange", routeStep);
|
|
1152
1276
|
on(document, "click", function (event) {
|
|
1153
1277
|
var el = event.target && event.target.closest ? event.target.closest("a,button,input,select,textarea,[role],[contenteditable='true']") : null;
|
|
1154
1278
|
if (!el) return;
|
|
@@ -1197,10 +1321,51 @@ on(document, "keydown", function (event) {
|
|
|
1197
1321
|
if (!el || !el.tagName) return;
|
|
1198
1322
|
push({ kind: "press", key: "Enter", selector: selectorOf(el) });
|
|
1199
1323
|
}, true);
|
|
1324
|
+
// Visible "recording" marker. Styles are set through CSSOM (not a <style> tag)
|
|
1325
|
+
// so a strict style-src CSP cannot hide it; the host is pointer-events:none and
|
|
1326
|
+
// aria-hidden, so it can never eat a click or show up in a snapshot.
|
|
1327
|
+
function mountBadge() {
|
|
1328
|
+
try {
|
|
1329
|
+
var stale = document.querySelector("[data-dsh-demo-badge]");
|
|
1330
|
+
if (stale && stale.parentNode) stale.parentNode.removeChild(stale);
|
|
1331
|
+
var host = document.createElement("div");
|
|
1332
|
+
host.setAttribute("data-dsh-demo-badge", "");
|
|
1333
|
+
host.setAttribute("aria-hidden", "true");
|
|
1334
|
+
host.style.cssText = "position:fixed;right:18px;bottom:18px;z-index:2147483647;pointer-events:none;";
|
|
1335
|
+
var root = host.attachShadow ? host.attachShadow({ mode: "open" }) : host;
|
|
1336
|
+
var zh = /^zh/i.test(navigator.language || "");
|
|
1337
|
+
var bar = document.createElement("div");
|
|
1338
|
+
bar.style.cssText = "display:flex;align-items:center;gap:8px;padding:8px 12px;border-radius:12px;"
|
|
1339
|
+
+ "background:rgba(17,24,39,.92);color:#fff;box-shadow:0 6px 20px rgba(0,0,0,.28);"
|
|
1340
|
+
+ "font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',sans-serif;";
|
|
1341
|
+
var dot = document.createElement("span");
|
|
1342
|
+
dot.style.cssText = "width:9px;height:9px;border-radius:50%;background:#ef4444;flex:0 0 auto;"
|
|
1343
|
+
+ "box-shadow:0 0 0 3px rgba(239,68,68,.22);";
|
|
1344
|
+
var text = document.createElement("span");
|
|
1345
|
+
text.style.cssText = "display:flex;flex-direction:column;gap:1px;font-size:12px;line-height:1.35;";
|
|
1346
|
+
var title = document.createElement("span");
|
|
1347
|
+
title.textContent = zh ? "\u6F14\u793A\u5F55\u5236\u4E2D" : "Recording";
|
|
1348
|
+
var hint = document.createElement("span");
|
|
1349
|
+
hint.textContent = zh ? "\u5B8C\u6210\u540E\u56DE\u5230 Desktop \u7ED3\u675F\u5F55\u5236" : "Return to Desktop to stop";
|
|
1350
|
+
hint.style.cssText = "font-size:11px;opacity:.72;";
|
|
1351
|
+
text.appendChild(title);
|
|
1352
|
+
text.appendChild(hint);
|
|
1353
|
+
bar.appendChild(dot);
|
|
1354
|
+
bar.appendChild(text);
|
|
1355
|
+
root.appendChild(bar);
|
|
1356
|
+
(document.body || document.documentElement).appendChild(host);
|
|
1357
|
+
return host;
|
|
1358
|
+
} catch (e) {
|
|
1359
|
+
return null;
|
|
1360
|
+
}
|
|
1361
|
+
}
|
|
1362
|
+
var badge = mountBadge();
|
|
1200
1363
|
var recorder = {
|
|
1201
1364
|
stop: function () {
|
|
1202
1365
|
for (var i = 0; i < OFF.length; i++) { try { OFF[i](); } catch (e) { } }
|
|
1203
1366
|
OFF.length = 0;
|
|
1367
|
+
try { if (badge && badge.parentNode) badge.parentNode.removeChild(badge); } catch (e) { }
|
|
1368
|
+
badge = null;
|
|
1204
1369
|
delete window[KEY];
|
|
1205
1370
|
},
|
|
1206
1371
|
};
|
|
@@ -1213,62 +1378,6 @@ var DEMO_STOP_SOURCE = `(() => {
|
|
|
1213
1378
|
return true;
|
|
1214
1379
|
})()`;
|
|
1215
1380
|
|
|
1216
|
-
// src/host/browser-agent/capture.ts
|
|
1217
|
-
var SECRET_PARAM = /^(access_?token|id_?token|auth|authorization|code|key|password|secret|session|sessionid|sig|signature|token)$/i;
|
|
1218
|
-
var URL_IN_TEXT = /https?:\/\/[^\s"'<>]+/g;
|
|
1219
|
-
function redactUrl(raw) {
|
|
1220
|
-
const withoutUserInfo = raw.replace(/^([a-z][a-z0-9+.-]*:\/\/)[^/?#@]*@/i, "$1");
|
|
1221
|
-
const withoutFragment = withoutUserInfo.replace(/#.*$/, "");
|
|
1222
|
-
const masked = withoutFragment.replace(
|
|
1223
|
-
/([?&])([^=&#]+)=([^&#]*)/g,
|
|
1224
|
-
(match, separator, key) => SECRET_PARAM.test(decodeURIComponent(key)) ? `${separator}${key}=***` : match
|
|
1225
|
-
);
|
|
1226
|
-
return masked.length > 300 ? `${masked.slice(0, 300)}\u2026` : masked;
|
|
1227
|
-
}
|
|
1228
|
-
function redactText(text3) {
|
|
1229
|
-
return text3.replace(URL_IN_TEXT, (match) => {
|
|
1230
|
-
const trailing = match.match(/[),.;]+$/)?.[0] ?? "";
|
|
1231
|
-
const core = trailing === "" ? match : match.slice(0, -trailing.length);
|
|
1232
|
-
return `${redactUrl(core)}${trailing}`;
|
|
1233
|
-
});
|
|
1234
|
-
}
|
|
1235
|
-
var CaptureBuffer = class {
|
|
1236
|
-
constructor(max = 300) {
|
|
1237
|
-
this.max = max;
|
|
1238
|
-
}
|
|
1239
|
-
max;
|
|
1240
|
-
entries = [];
|
|
1241
|
-
dropped = 0;
|
|
1242
|
-
get size() {
|
|
1243
|
-
return this.entries.length;
|
|
1244
|
-
}
|
|
1245
|
-
push(entry) {
|
|
1246
|
-
this.entries.push(entry);
|
|
1247
|
-
while (this.entries.length > this.max) {
|
|
1248
|
-
this.entries.shift();
|
|
1249
|
-
this.dropped += 1;
|
|
1250
|
-
}
|
|
1251
|
-
}
|
|
1252
|
-
/** Newest `limit` entries of the requested kind, optionally clearing them. */
|
|
1253
|
-
read(kind, options = {}) {
|
|
1254
|
-
const limit = Math.min(Math.max(Math.trunc(options.limit ?? 40), 1), 200);
|
|
1255
|
-
const ofKind = this.entries.filter((entry) => kind === "all" || entry.kind === (kind === "network" ? "request" : "console"));
|
|
1256
|
-
const matched = options.tabId === void 0 ? ofKind : ofKind.filter((entry) => entry.tabId === options.tabId);
|
|
1257
|
-
const skipped = ofKind.length - matched.length;
|
|
1258
|
-
const selected = matched.slice(-limit);
|
|
1259
|
-
if (options.clear === true) {
|
|
1260
|
-
const keep = this.entries.filter((entry) => !selected.includes(entry));
|
|
1261
|
-
this.entries.length = 0;
|
|
1262
|
-
this.entries.push(...keep);
|
|
1263
|
-
}
|
|
1264
|
-
return { entries: selected, dropped: this.dropped, skipped };
|
|
1265
|
-
}
|
|
1266
|
-
clear() {
|
|
1267
|
-
this.entries.length = 0;
|
|
1268
|
-
this.dropped = 0;
|
|
1269
|
-
}
|
|
1270
|
-
};
|
|
1271
|
-
|
|
1272
1381
|
// src/host/browser-agent/auto-nav.ts
|
|
1273
1382
|
function pathKey(raw) {
|
|
1274
1383
|
try {
|
|
@@ -1383,6 +1492,28 @@ var TabRegistry = class {
|
|
|
1383
1492
|
}
|
|
1384
1493
|
};
|
|
1385
1494
|
|
|
1495
|
+
// src/host/browser-agent/approval-thumbnail.ts
|
|
1496
|
+
var THUMBNAIL_PADDING = 12;
|
|
1497
|
+
var THUMBNAIL_MAX_WIDTH = 520;
|
|
1498
|
+
var THUMBNAIL_MAX_HEIGHT = 260;
|
|
1499
|
+
var MAX_THUMBNAIL_BASE64 = 4e5;
|
|
1500
|
+
function clampThumbnailClip(box, viewport) {
|
|
1501
|
+
if (!Number.isFinite(box.x) || !Number.isFinite(box.y)) return null;
|
|
1502
|
+
if (!Number.isFinite(box.width) || !Number.isFinite(box.height)) return null;
|
|
1503
|
+
if (box.width <= 0 || box.height <= 0) return null;
|
|
1504
|
+
const left = Math.max(0, box.x - THUMBNAIL_PADDING);
|
|
1505
|
+
const top = Math.max(0, box.y - THUMBNAIL_PADDING);
|
|
1506
|
+
const right = Math.min(viewport.width, box.x + box.width + THUMBNAIL_PADDING);
|
|
1507
|
+
const bottom = Math.min(viewport.height, box.y + box.height + THUMBNAIL_PADDING);
|
|
1508
|
+
if (right - left < 8 || bottom - top < 8) return null;
|
|
1509
|
+
const width = Math.min(right - left, THUMBNAIL_MAX_WIDTH);
|
|
1510
|
+
const height = Math.min(bottom - top, THUMBNAIL_MAX_HEIGHT);
|
|
1511
|
+
return { x: Math.round(left), y: Math.round(top), width: Math.round(width), height: Math.round(height) };
|
|
1512
|
+
}
|
|
1513
|
+
function keepThumbnail(base64) {
|
|
1514
|
+
return base64.length > 0 && base64.length <= MAX_THUMBNAIL_BASE64;
|
|
1515
|
+
}
|
|
1516
|
+
|
|
1386
1517
|
// src/host/browser-agent/playwright-driver.ts
|
|
1387
1518
|
var playwrightModule = null;
|
|
1388
1519
|
async function loadPlaywright() {
|
|
@@ -1828,6 +1959,17 @@ var PlaywrightDriver = class {
|
|
|
1828
1959
|
tabId: this.tabIdFor(page)
|
|
1829
1960
|
};
|
|
1830
1961
|
}
|
|
1962
|
+
async press(key) {
|
|
1963
|
+
const page = await this.requirePage();
|
|
1964
|
+
await page.keyboard.press(key);
|
|
1965
|
+
await sleep(120);
|
|
1966
|
+
return {
|
|
1967
|
+
url: page.url(),
|
|
1968
|
+
title: await page.title().catch(() => ""),
|
|
1969
|
+
changed: false,
|
|
1970
|
+
tabId: this.tabIdFor(page)
|
|
1971
|
+
};
|
|
1972
|
+
}
|
|
1831
1973
|
async scroll(dy) {
|
|
1832
1974
|
const page = await this.requirePage();
|
|
1833
1975
|
await page.mouse.wheel(0, dy);
|
|
@@ -1869,6 +2011,28 @@ var PlaywrightDriver = class {
|
|
|
1869
2011
|
tabId: this.tabIdFor(page)
|
|
1870
2012
|
};
|
|
1871
2013
|
}
|
|
2014
|
+
/** Small crop around the control a pending approval is about. */
|
|
2015
|
+
async thumbnail(ref) {
|
|
2016
|
+
const page = await this.requirePage();
|
|
2017
|
+
const tabId = this.tabIdFor(page);
|
|
2018
|
+
if (this.tabs.ref(tabId, ref) === void 0) return null;
|
|
2019
|
+
const locator = page.locator(`[${PLAYWRIGHT_REF_ATTR}="${ref}"]`).first();
|
|
2020
|
+
const box = await locator.boundingBox().catch(() => null);
|
|
2021
|
+
if (box === null) return null;
|
|
2022
|
+
const viewport = page.viewportSize() ?? { width: 1280, height: 800 };
|
|
2023
|
+
const clip2 = clampThumbnailClip(box, viewport);
|
|
2024
|
+
if (clip2 === null) return null;
|
|
2025
|
+
const buffer = await page.screenshot({
|
|
2026
|
+
clip: clip2,
|
|
2027
|
+
type: "jpeg",
|
|
2028
|
+
quality: 60,
|
|
2029
|
+
scale: "css",
|
|
2030
|
+
timeout: 5e3
|
|
2031
|
+
}).catch(() => null);
|
|
2032
|
+
if (buffer === null) return null;
|
|
2033
|
+
const base64 = buffer.toString("base64");
|
|
2034
|
+
return keepThumbnail(base64) ? { mime: "image/jpeg", base64 } : null;
|
|
2035
|
+
}
|
|
1872
2036
|
async listTabs() {
|
|
1873
2037
|
const pages = this.context?.pages() ?? [];
|
|
1874
2038
|
if (pages.length === 0) {
|
|
@@ -2006,7 +2170,7 @@ var PlaywrightDriver = class {
|
|
|
2006
2170
|
tabId: this.tabIdFor(page)
|
|
2007
2171
|
};
|
|
2008
2172
|
}
|
|
2009
|
-
/** Record a user demonstration
|
|
2173
|
+
/** Record a user demonstration across every tab of the dedicated browser. */
|
|
2010
2174
|
async startDemonstration() {
|
|
2011
2175
|
const page = await this.requirePage();
|
|
2012
2176
|
if (this.demoPage !== null) await this.stopDemonstration().catch(() => void 0);
|
|
@@ -2016,40 +2180,65 @@ var PlaywrightDriver = class {
|
|
|
2016
2180
|
const context = page.context();
|
|
2017
2181
|
if (!this.demoBindingReady) {
|
|
2018
2182
|
try {
|
|
2019
|
-
await context.exposeBinding("__dshDemoPush", (
|
|
2183
|
+
await context.exposeBinding("__dshDemoPush", (source, step) => {
|
|
2020
2184
|
if (this.demoPage === null) return;
|
|
2021
|
-
|
|
2185
|
+
const from = source.page;
|
|
2186
|
+
pushDemoStep(
|
|
2187
|
+
this.demoPageSteps,
|
|
2188
|
+
from === void 0 || from.isClosed() ? step : attachDemoTab(step, this.demoSite(from))
|
|
2189
|
+
);
|
|
2022
2190
|
});
|
|
2023
2191
|
this.demoBindingReady = true;
|
|
2024
2192
|
} catch {
|
|
2025
2193
|
this.demoBindingReady = true;
|
|
2026
2194
|
}
|
|
2027
2195
|
}
|
|
2028
|
-
this.
|
|
2029
|
-
await page.evaluate(`(() => { ${DEMO_RECORDER_SOURCE} })()`).catch(() => void 0);
|
|
2196
|
+
for (const open of context.pages()) this.armDemoPage(open);
|
|
2030
2197
|
if (this.demoPageHandler === null) {
|
|
2031
2198
|
this.demoPageHandler = (opened) => {
|
|
2032
2199
|
if (this.demoPage === null) return;
|
|
2033
|
-
this.
|
|
2034
|
-
void opened.evaluate(`(() => { ${DEMO_RECORDER_SOURCE} })()`).catch(() => void 0);
|
|
2200
|
+
this.armDemoPage(opened);
|
|
2035
2201
|
};
|
|
2036
2202
|
context.on("page", this.demoPageHandler);
|
|
2037
2203
|
}
|
|
2038
2204
|
}
|
|
2205
|
+
/** Tab id plus the redacted URL of a page, for tagging a step. */
|
|
2206
|
+
demoSite(page) {
|
|
2207
|
+
let raw = "";
|
|
2208
|
+
try {
|
|
2209
|
+
raw = page.url();
|
|
2210
|
+
} catch {
|
|
2211
|
+
raw = "";
|
|
2212
|
+
}
|
|
2213
|
+
return {
|
|
2214
|
+
tabId: this.tabIdFor(page),
|
|
2215
|
+
.../^https?:\/\//i.test(raw) ? { tabUrl: redactUrl(raw) } : {}
|
|
2216
|
+
};
|
|
2217
|
+
}
|
|
2039
2218
|
/**
|
|
2040
|
-
*
|
|
2041
|
-
*
|
|
2219
|
+
* Wire one tab for recording: a navigation watcher (attached once per page)
|
|
2220
|
+
* plus the page-side recorder, which is re-injected every call so a second
|
|
2221
|
+
* demonstration in the same browser does not silently record nothing.
|
|
2042
2222
|
*/
|
|
2043
|
-
|
|
2044
|
-
if (this.demoTrackedPages.has(page))
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2223
|
+
armDemoPage(page) {
|
|
2224
|
+
if (!this.demoTrackedPages.has(page)) {
|
|
2225
|
+
this.demoTrackedPages.add(page);
|
|
2226
|
+
page.on("framenavigated", (frame) => {
|
|
2227
|
+
if (this.demoPage === null || frame !== page.mainFrame()) return;
|
|
2228
|
+
const url = frame.url();
|
|
2229
|
+
if (!/^https?:\/\//i.test(url)) return;
|
|
2230
|
+
const safe = redactUrl(url);
|
|
2231
|
+
this.demoNavSteps.push({
|
|
2232
|
+
kind: "navigate",
|
|
2233
|
+
at: Date.now(),
|
|
2234
|
+
url: safe,
|
|
2235
|
+
tabId: this.tabIdFor(page),
|
|
2236
|
+
tabUrl: safe
|
|
2237
|
+
});
|
|
2238
|
+
void frame.page().evaluate(demoRecorderScript()).catch(() => void 0);
|
|
2239
|
+
});
|
|
2240
|
+
}
|
|
2241
|
+
void page.evaluate(demoRecorderScript()).catch(() => void 0);
|
|
2053
2242
|
}
|
|
2054
2243
|
/** Stop recording and return the flow, secrets masked, repeats dropped. */
|
|
2055
2244
|
demonstrationActive() {
|
|
@@ -2128,6 +2317,9 @@ function sleep(ms) {
|
|
|
2128
2317
|
setTimeout(resolve17, ms);
|
|
2129
2318
|
});
|
|
2130
2319
|
}
|
|
2320
|
+
function demoRecorderScript() {
|
|
2321
|
+
return `(() => { ${DEMO_RECORDER_SOURCE} })()`;
|
|
2322
|
+
}
|
|
2131
2323
|
function clipText(text3, max) {
|
|
2132
2324
|
const flat = text3.replace(/\s+/g, " ").trim();
|
|
2133
2325
|
return flat.length > max ? `${flat.slice(0, max)}\u2026` : flat;
|
|
@@ -2195,6 +2387,7 @@ var GUIDANCE = [
|
|
|
2195
2387
|
"Mutation tools may pause for an in-app Allow card \u2014 wait for allow/deny.",
|
|
2196
2388
|
"When the user says they will show you how something works (\u6F14\u793A / \u793A\u8303 / \u6211\u64CD\u4F5C\u4F60\u770B), or you cannot work out a flow after a couple of attempts, call browser_demonstrate with one short instruction instead of guessing. It blocks until the user presses Continue and returns numbered steps.",
|
|
2197
2389
|
"browser_demonstrate returns click/fill/Enter/navigation steps with role + name. Replay them with browser_snapshot, then act by role and name; the selectors in the steps are for humans, and refs change between runs. If the tool reports that demonstration recording is off, ask the user to enable \u8BBE\u7F6E \u2192 \u667A\u80FD\u4F53\u589E\u5F3A \u2192 \u529F\u80FD \u2192 \u6D4F\u89C8\u5668 Agent \u2192 \u6F14\u793A\u5F55\u5236.",
|
|
2390
|
+
'Pass replay: true when the user wants you to just do it ("\u7136\u540E\u4F60\u6765"), not to read a list. Replay runs the recorded steps unattended and stops at the first step it cannot reproduce (a masked secret, a <select>, a control that moved). When it stops, do the remaining steps yourself and never say the flow completed.',
|
|
2198
2391
|
"Login / captcha / 2FA: NEVER type passwords. When needs_human appears, call browser_ask_user and STOP until the user finishes in the dedicated window. A bare \u201CLog in\u201D chip on a normal page is not a wall.",
|
|
2199
2392
|
"Do not invent page content or refs. Prefer finishing the user task over exploring more pages."
|
|
2200
2393
|
].join("\n");
|
|
@@ -2498,6 +2691,133 @@ function classify(input) {
|
|
|
2498
2691
|
|
|
2499
2692
|
// src/host/browser-agent/tools.ts
|
|
2500
2693
|
import { defineTool } from "@deepseek-ai/dsh-tools";
|
|
2694
|
+
|
|
2695
|
+
// src/host/browser-agent/demo-replay.ts
|
|
2696
|
+
function normalizeControlName(raw) {
|
|
2697
|
+
return raw.replace(/[\u200b-\u200d\ufeff]/gu, "").replace(/\s+/gu, " ").trim().toLowerCase();
|
|
2698
|
+
}
|
|
2699
|
+
function matchDemoControl(nodes, role, name2) {
|
|
2700
|
+
const wanted = normalizeControlName(name2);
|
|
2701
|
+
if (wanted === "") return void 0;
|
|
2702
|
+
const sameRole = nodes.filter((node) => node.role === role);
|
|
2703
|
+
const exact = sameRole.find((node) => normalizeControlName(node.name) === wanted);
|
|
2704
|
+
if (exact !== void 0) return exact;
|
|
2705
|
+
const exactAnyRole = nodes.find((node) => normalizeControlName(node.name) === wanted);
|
|
2706
|
+
if (exactAnyRole !== void 0) return exactAnyRole;
|
|
2707
|
+
const partial = sameRole.filter((node) => {
|
|
2708
|
+
const candidate = normalizeControlName(node.name);
|
|
2709
|
+
return candidate.includes(wanted) || wanted.includes(candidate);
|
|
2710
|
+
});
|
|
2711
|
+
return partial.length === 1 ? partial[0] : void 0;
|
|
2712
|
+
}
|
|
2713
|
+
function replayObstacle(step) {
|
|
2714
|
+
if (step.kind !== "fill") return null;
|
|
2715
|
+
if (step.masked) return `secret field ${JSON.stringify(step.name)} was masked; type it yourself`;
|
|
2716
|
+
if (step.role === "combobox") return `select ${JSON.stringify(step.name)} cannot be replayed by name`;
|
|
2717
|
+
if (step.role === "checkbox" || step.role === "radio") {
|
|
2718
|
+
return `${step.role} ${JSON.stringify(step.name)} cannot be replayed by name (click it, then continue)`;
|
|
2719
|
+
}
|
|
2720
|
+
return null;
|
|
2721
|
+
}
|
|
2722
|
+
async function performStep(driver, step) {
|
|
2723
|
+
switch (step.kind) {
|
|
2724
|
+
case "navigate": {
|
|
2725
|
+
const current = (await driver.snapshot()).url;
|
|
2726
|
+
if (current === step.url) return { ok: true, url: current };
|
|
2727
|
+
const result = await driver.navigate(step.url);
|
|
2728
|
+
return { ok: true, url: result.url };
|
|
2729
|
+
}
|
|
2730
|
+
case "click": {
|
|
2731
|
+
const snapshot = await driver.snapshot();
|
|
2732
|
+
const node = matchDemoControl(snapshot.nodes, step.role, step.name);
|
|
2733
|
+
if (node === void 0) {
|
|
2734
|
+
return { ok: false, reason: `no control matching ${step.role} ${JSON.stringify(step.name)} on this page` };
|
|
2735
|
+
}
|
|
2736
|
+
const result = await driver.click(node.ref);
|
|
2737
|
+
return { ok: true, url: result.url };
|
|
2738
|
+
}
|
|
2739
|
+
case "fill": {
|
|
2740
|
+
const snapshot = await driver.snapshot();
|
|
2741
|
+
const node = matchDemoControl(snapshot.nodes, step.role, step.name);
|
|
2742
|
+
if (node === void 0) {
|
|
2743
|
+
return { ok: false, reason: `no field matching ${step.role} ${JSON.stringify(step.name)} on this page` };
|
|
2744
|
+
}
|
|
2745
|
+
const result = await driver.type(node.ref, step.value);
|
|
2746
|
+
return { ok: true, url: result.url };
|
|
2747
|
+
}
|
|
2748
|
+
case "press": {
|
|
2749
|
+
const result = await driver.press(step.key);
|
|
2750
|
+
return { ok: true, url: result.url };
|
|
2751
|
+
}
|
|
2752
|
+
default: {
|
|
2753
|
+
const exhaustive = step;
|
|
2754
|
+
return { ok: false, reason: `unsupported step ${JSON.stringify(exhaustive)}` };
|
|
2755
|
+
}
|
|
2756
|
+
}
|
|
2757
|
+
}
|
|
2758
|
+
async function replayDemoSteps(driver, steps) {
|
|
2759
|
+
const lines = [];
|
|
2760
|
+
let currentTab;
|
|
2761
|
+
let url;
|
|
2762
|
+
for (let index = 0; index < steps.length; index += 1) {
|
|
2763
|
+
const step = steps[index];
|
|
2764
|
+
if (step.tabId !== void 0 && step.tabId !== currentTab) {
|
|
2765
|
+
try {
|
|
2766
|
+
const followed = await driver.followTab(step.tabId);
|
|
2767
|
+
currentTab = step.tabId;
|
|
2768
|
+
url = followed.url;
|
|
2769
|
+
} catch {
|
|
2770
|
+
return {
|
|
2771
|
+
status: "blocked",
|
|
2772
|
+
performed: index,
|
|
2773
|
+
total: steps.length,
|
|
2774
|
+
lines,
|
|
2775
|
+
reason: `tab ${step.tabId} is no longer open`,
|
|
2776
|
+
pending: steps.slice(index),
|
|
2777
|
+
...url === void 0 ? {} : { url }
|
|
2778
|
+
};
|
|
2779
|
+
}
|
|
2780
|
+
}
|
|
2781
|
+
const obstacle = replayObstacle(step);
|
|
2782
|
+
if (obstacle !== null) {
|
|
2783
|
+
return {
|
|
2784
|
+
status: "blocked",
|
|
2785
|
+
performed: index,
|
|
2786
|
+
total: steps.length,
|
|
2787
|
+
lines,
|
|
2788
|
+
reason: obstacle,
|
|
2789
|
+
pending: steps.slice(index),
|
|
2790
|
+
...url === void 0 ? {} : { url }
|
|
2791
|
+
};
|
|
2792
|
+
}
|
|
2793
|
+
const outcome = await performStep(driver, step).catch((error) => ({
|
|
2794
|
+
ok: false,
|
|
2795
|
+
reason: error instanceof Error ? error.message : String(error)
|
|
2796
|
+
}));
|
|
2797
|
+
if (!outcome.ok) {
|
|
2798
|
+
return {
|
|
2799
|
+
status: "blocked",
|
|
2800
|
+
performed: index,
|
|
2801
|
+
total: steps.length,
|
|
2802
|
+
lines,
|
|
2803
|
+
reason: outcome.reason,
|
|
2804
|
+
pending: steps.slice(index),
|
|
2805
|
+
...url === void 0 ? {} : { url }
|
|
2806
|
+
};
|
|
2807
|
+
}
|
|
2808
|
+
url = outcome.url;
|
|
2809
|
+
lines.push(`${index + 1}. ok ${describeDemoStep(step)}`);
|
|
2810
|
+
}
|
|
2811
|
+
return {
|
|
2812
|
+
status: "done",
|
|
2813
|
+
performed: steps.length,
|
|
2814
|
+
total: steps.length,
|
|
2815
|
+
lines,
|
|
2816
|
+
url: url ?? ""
|
|
2817
|
+
};
|
|
2818
|
+
}
|
|
2819
|
+
|
|
2820
|
+
// src/host/browser-agent/tools.ts
|
|
2501
2821
|
var HUMAN_WAIT_TIMEOUT_MS = 15 * 6e4;
|
|
2502
2822
|
function textTool(name2, description, parameters, execute, timeoutMs = 6e4) {
|
|
2503
2823
|
return defineTool({
|
|
@@ -2675,7 +2995,7 @@ function registerBrowserTools(ctx, options) {
|
|
|
2675
2995
|
});
|
|
2676
2996
|
throw new Error(scope.refusal(tabId));
|
|
2677
2997
|
};
|
|
2678
|
-
const requireMutation = async (exec, tool, summary, url) => {
|
|
2998
|
+
const requireMutation = async (exec, tool, summary, url, targetRef) => {
|
|
2679
2999
|
const sessionId = sessionIdOf(exec);
|
|
2680
3000
|
let effectiveUrl = typeof url === "string" && /^https?:\/\//i.test(url) ? url : void 0;
|
|
2681
3001
|
if (effectiveUrl === void 0) {
|
|
@@ -2683,12 +3003,15 @@ function registerBrowserTools(ctx, options) {
|
|
|
2683
3003
|
} else {
|
|
2684
3004
|
options.sessions.rememberHttpUrl(sessionId, effectiveUrl);
|
|
2685
3005
|
}
|
|
3006
|
+
const thumbDriver = driverOf(options);
|
|
3007
|
+
const thumbnail = targetRef === void 0 || typeof thumbDriver.thumbnail !== "function" ? null : await thumbDriver.thumbnail(targetRef).catch(() => null);
|
|
2686
3008
|
const decision = await options.approval.requestApproval({
|
|
2687
3009
|
sessionId,
|
|
2688
3010
|
tool,
|
|
2689
3011
|
summary,
|
|
2690
3012
|
url: effectiveUrl,
|
|
2691
|
-
signal: exec.signal
|
|
3013
|
+
signal: exec.signal,
|
|
3014
|
+
...thumbnail === null ? {} : { thumbnail }
|
|
2692
3015
|
});
|
|
2693
3016
|
if (decision === "deny") {
|
|
2694
3017
|
options.sessions.record({
|
|
@@ -3079,7 +3402,7 @@ function registerBrowserTools(ctx, options) {
|
|
|
3079
3402
|
);
|
|
3080
3403
|
}
|
|
3081
3404
|
const snapshotHref = options.sessions.hrefOfRef(sessionId, ref);
|
|
3082
|
-
await requireMutation(exec, "browser_click", `Click ref ${ref}`, url);
|
|
3405
|
+
await requireMutation(exec, "browser_click", `Click ref ${ref}`, url, ref);
|
|
3083
3406
|
try {
|
|
3084
3407
|
const beforeUrl = typeof url === "string" ? url : "";
|
|
3085
3408
|
let result = await runBridge(() => driverOf(options).click(ref));
|
|
@@ -3194,7 +3517,7 @@ function registerBrowserTools(ctx, options) {
|
|
|
3194
3517
|
url = void 0;
|
|
3195
3518
|
}
|
|
3196
3519
|
requireFreshRef(sessionId, ref, "browser_type");
|
|
3197
|
-
await requireMutation(exec, "browser_type", `Type into ref ${ref}: ${maskTypeSummary(text3)}`, url);
|
|
3520
|
+
await requireMutation(exec, "browser_type", `Type into ref ${ref}: ${maskTypeSummary(text3)}`, url, ref);
|
|
3198
3521
|
try {
|
|
3199
3522
|
const result = await runBridge(() => driverOf(options).type(ref, text3));
|
|
3200
3523
|
await rememberTab(sessionId, result.tabId);
|
|
@@ -3584,7 +3907,7 @@ Action: browser_extract or browser_snapshot next. Do not navigate away unless th
|
|
|
3584
3907
|
)));
|
|
3585
3908
|
disposers.push(ctx.tools.register(textTool(
|
|
3586
3909
|
"browser_demonstrate",
|
|
3587
|
-
"Ask the user to show you a flow in the dedicated browser window (they click and type, you watch), blocking until they press Continue. Records clicks, filled fields, Enter presses
|
|
3910
|
+
"Ask the user to show you a flow in the dedicated browser window (they click and type, you watch), blocking until they press Continue. Records clicks, filled fields, Enter presses, top-level navigations and single-page-app route changes in every tab of that browser; each step is tagged with the tab it happened in. Password / OTP / token fields are masked as ***. Use it when you cannot work out how a flow works. Returns numbered steps to replay with browser_snapshot then browser_click / browser_type by name (refs change between runs), or pass replay: true to run the recorded flow immediately. Requires the Demonstrate switch in Settings \u2192 \u667A\u80FD\u4F53\u589E\u5F3A \u2192 \u6D4F\u89C8\u5668 Agent.",
|
|
3588
3911
|
{
|
|
3589
3912
|
message: {
|
|
3590
3913
|
type: "string",
|
|
@@ -3594,6 +3917,10 @@ Action: browser_extract or browser_snapshot next. Do not navigate away unless th
|
|
|
3594
3917
|
timeoutMs: {
|
|
3595
3918
|
type: "number",
|
|
3596
3919
|
description: "How long to wait for the user, in ms (default 300000)."
|
|
3920
|
+
},
|
|
3921
|
+
replay: {
|
|
3922
|
+
type: "boolean",
|
|
3923
|
+
description: "Run the recorded flow once right after the user finishes (default false). Replay is by role + name against a fresh snapshot; a masked secret, a <select>, or a control that is gone stops it at that step and returns what is left."
|
|
3597
3924
|
}
|
|
3598
3925
|
},
|
|
3599
3926
|
async (args, exec) => {
|
|
@@ -3631,21 +3958,64 @@ Action: browser_extract or browser_snapshot next. Do not navigate away unless th
|
|
|
3631
3958
|
options.sessions.record({
|
|
3632
3959
|
sessionId,
|
|
3633
3960
|
tool: "browser_demonstrate",
|
|
3634
|
-
summary: `Demonstrated ${summary.shown} step(s)`,
|
|
3961
|
+
summary: `Demonstrated ${summary.shown} step(s)${summary.multiTab ? ` across ${summary.tabs.length} tabs` : ""}`,
|
|
3635
3962
|
outcome: "ok"
|
|
3636
3963
|
});
|
|
3637
3964
|
if (summary.shown === 0) {
|
|
3638
3965
|
return [
|
|
3639
3966
|
"demonstrated steps: 0",
|
|
3640
|
-
"Nothing was recorded \u2014 the user may have pressed Continue without acting
|
|
3967
|
+
"Nothing was recorded \u2014 the user may have pressed Continue without acting.",
|
|
3641
3968
|
"Action: call browser_ask_user to check, or browser_snapshot and continue on your own."
|
|
3642
3969
|
].join("\n");
|
|
3643
3970
|
}
|
|
3971
|
+
const heading = `demonstrated steps: ${summary.shown}${steps.length > summary.shown ? ` (of ${steps.length})` : ""}`;
|
|
3972
|
+
const maskedLine = summary.masked > 0 ? [`masked fields: ${summary.masked} (secret values are never shown)`] : [];
|
|
3973
|
+
if (args.replay === true) {
|
|
3974
|
+
const replay = await replayDemoSteps(driver, steps).catch((error) => ({
|
|
3975
|
+
status: "blocked",
|
|
3976
|
+
performed: 0,
|
|
3977
|
+
total: steps.length,
|
|
3978
|
+
lines: [],
|
|
3979
|
+
reason: error instanceof Error ? error.message : String(error),
|
|
3980
|
+
pending: steps
|
|
3981
|
+
}));
|
|
3982
|
+
options.sessions.record({
|
|
3983
|
+
sessionId,
|
|
3984
|
+
tool: "browser_demonstrate",
|
|
3985
|
+
summary: `Replayed ${replay.performed}/${replay.total} demonstrated step(s)`,
|
|
3986
|
+
outcome: replay.status === "done" ? "ok" : "error"
|
|
3987
|
+
});
|
|
3988
|
+
if (replay.status === "done") {
|
|
3989
|
+
return [
|
|
3990
|
+
`${heading} \u2014 replayed ${replay.performed}/${replay.total}`,
|
|
3991
|
+
...maskedLine,
|
|
3992
|
+
...demoTabLegend(summary),
|
|
3993
|
+
...replay.lines,
|
|
3994
|
+
`url: ${replay.url}`,
|
|
3995
|
+
"Action: the recorded flow ran to the end. Report what changed on screen; call browser_snapshot if you need the new page."
|
|
3996
|
+
].join("\n");
|
|
3997
|
+
}
|
|
3998
|
+
const pendingLines = replay.pending.map((step, offset) => {
|
|
3999
|
+
const n = replay.performed + offset + 1;
|
|
4000
|
+
const tag = summary.multiTab && step.tabId !== void 0 ? `[tab ${step.tabId}] ` : "";
|
|
4001
|
+
return `${n}. todo ${tag}${describeDemoStep(step)}`;
|
|
4002
|
+
});
|
|
4003
|
+
return [
|
|
4004
|
+
`${heading} \u2014 replayed ${replay.performed}/${replay.total}`,
|
|
4005
|
+
...maskedLine,
|
|
4006
|
+
...demoTabLegend(summary),
|
|
4007
|
+
...replay.lines,
|
|
4008
|
+
`stopped at step ${replay.performed + 1}: ${replay.reason}`,
|
|
4009
|
+
...pendingLines,
|
|
4010
|
+
"Action: the replay stopped, so the page is whatever the last ok step left behind. Do the remaining steps yourself with browser_snapshot then browser_click / browser_type (role+name), or browser_ask_user if a secret or an unusual control is in the way. Do not claim the flow finished."
|
|
4011
|
+
].join("\n");
|
|
4012
|
+
}
|
|
3644
4013
|
return [
|
|
3645
|
-
|
|
3646
|
-
...
|
|
4014
|
+
heading,
|
|
4015
|
+
...maskedLine,
|
|
4016
|
+
...demoTabLegend(summary),
|
|
3647
4017
|
...summary.lines,
|
|
3648
|
-
"Action: replay with browser_snapshot, then browser_click / browser_type by the role+name shown here. Refs change between runs; never invent selectors."
|
|
4018
|
+
summary.multiTab ? "Action: the flow crossed tabs. browser_list_tabs, then browser_follow_tab for each tab N before acting in it (match by URL; ids are stable while this browser stays open). In each tab: browser_snapshot, then browser_click / browser_type by the role+name shown here. Refs change between runs; never invent selectors." : "Action: replay with browser_snapshot, then browser_click / browser_type by the role+name shown here. Refs change between runs; never invent selectors."
|
|
3649
4019
|
].join("\n");
|
|
3650
4020
|
},
|
|
3651
4021
|
HUMAN_WAIT_TIMEOUT_MS
|
|
@@ -4054,10 +4424,10 @@ function installBrowserAgent(ctx, options) {
|
|
|
4054
4424
|
sessions.record({
|
|
4055
4425
|
sessionId: "sidebar",
|
|
4056
4426
|
tool: "browser_demonstrate",
|
|
4057
|
-
summary: `Demonstration stopped from the sidebar (${summary.shown} step(s))`,
|
|
4427
|
+
summary: `Demonstration stopped from the sidebar (${summary.shown} step(s)${summary.multiTab ? ` across ${summary.tabs.length} tabs` : ""})`,
|
|
4058
4428
|
outcome: "ok"
|
|
4059
4429
|
});
|
|
4060
|
-
return { ok: true, steps: summary.lines };
|
|
4430
|
+
return { ok: true, steps: [...demoTabLegend(summary), ...summary.lines] };
|
|
4061
4431
|
} catch (error) {
|
|
4062
4432
|
return { ok: false, error: error instanceof Error ? error.message : String(error) };
|
|
4063
4433
|
}
|
|
@@ -16163,7 +16533,9 @@ var browserAgentPendingSchema = z4.strictObject({
|
|
|
16163
16533
|
tool: z4.string().min(1),
|
|
16164
16534
|
summary: z4.string().min(1),
|
|
16165
16535
|
url: z4.string().optional(),
|
|
16166
|
-
origin: z4.string().optional()
|
|
16536
|
+
origin: z4.string().optional(),
|
|
16537
|
+
/** A crop of the target control exists; fetch it with browserAgentThumbnail. */
|
|
16538
|
+
hasThumbnail: z4.boolean().optional()
|
|
16167
16539
|
});
|
|
16168
16540
|
var browserAgentTabConflictSchema = z4.strictObject({
|
|
16169
16541
|
sessionId: z4.string().min(1),
|
|
@@ -16262,6 +16634,23 @@ var browserAgentDemoResultCodec = codec(
|
|
|
16262
16634
|
"dsh-agent-enhancer#BrowserAgentDemoResult",
|
|
16263
16635
|
browserAgentDemoResultSchema
|
|
16264
16636
|
);
|
|
16637
|
+
var browserAgentThumbnailRequestSchema = z4.strictObject({
|
|
16638
|
+
id: z4.string().min(1)
|
|
16639
|
+
});
|
|
16640
|
+
var browserAgentThumbnailRequestCodec = codec(
|
|
16641
|
+
"dsh-agent-enhancer#BrowserAgentThumbnailRequest",
|
|
16642
|
+
browserAgentThumbnailRequestSchema
|
|
16643
|
+
);
|
|
16644
|
+
var browserAgentThumbnailResultSchema = z4.strictObject({
|
|
16645
|
+
ok: z4.boolean(),
|
|
16646
|
+
mime: z4.string().optional(),
|
|
16647
|
+
base64: z4.string().optional(),
|
|
16648
|
+
error: z4.string().optional()
|
|
16649
|
+
});
|
|
16650
|
+
var browserAgentThumbnailResultCodec = codec(
|
|
16651
|
+
"dsh-agent-enhancer#BrowserAgentThumbnailResult",
|
|
16652
|
+
browserAgentThumbnailResultSchema
|
|
16653
|
+
);
|
|
16265
16654
|
var browserAgentResolveRequestSchema = z4.strictObject({
|
|
16266
16655
|
id: z4.string().min(1),
|
|
16267
16656
|
decision: browserAgentApprovalDecisionSchema
|
|
@@ -17156,6 +17545,18 @@ var remoteInfo = createTypertRemoteInfo({
|
|
|
17156
17545
|
}],
|
|
17157
17546
|
result: browserAgentSelectTabResultCodec
|
|
17158
17547
|
},
|
|
17548
|
+
"agentEnhancer/browserAgentThumbnail": {
|
|
17549
|
+
service: "agentEnhancer",
|
|
17550
|
+
implementation: "browserAgentThumbnail",
|
|
17551
|
+
invocation: { kind: "direct" },
|
|
17552
|
+
parameters: [{
|
|
17553
|
+
name: "request",
|
|
17554
|
+
source: "json",
|
|
17555
|
+
codec: browserAgentThumbnailRequestCodec,
|
|
17556
|
+
strictCodec: browserAgentThumbnailRequestCodec
|
|
17557
|
+
}],
|
|
17558
|
+
result: browserAgentThumbnailResultCodec
|
|
17559
|
+
},
|
|
17159
17560
|
"agentEnhancer/browserAgentDemo": {
|
|
17160
17561
|
service: "agentEnhancer",
|
|
17161
17562
|
implementation: "browserAgentDemo",
|
|
@@ -17983,7 +18384,8 @@ var AgentEnhancerService = class extends TypertRemoteService {
|
|
|
17983
18384
|
tool: pending.tool,
|
|
17984
18385
|
summary: pending.summary,
|
|
17985
18386
|
...pending.url === void 0 ? {} : { url: pending.url },
|
|
17986
|
-
...pending.origin === void 0 ? {} : { origin: pending.origin }
|
|
18387
|
+
...pending.origin === void 0 ? {} : { origin: pending.origin },
|
|
18388
|
+
hasThumbnail: pending.thumbnail !== void 0
|
|
17987
18389
|
},
|
|
17988
18390
|
demo: {
|
|
17989
18391
|
enabled: settings.demonstrate,
|
|
@@ -18696,6 +19098,12 @@ var AgentEnhancerService = class extends TypertRemoteService {
|
|
|
18696
19098
|
snapshot: await this.browserSnapshotNow()
|
|
18697
19099
|
};
|
|
18698
19100
|
}
|
|
19101
|
+
async browserAgentThumbnail(request) {
|
|
19102
|
+
this.assertOwner();
|
|
19103
|
+
const thumb = this.browserAgent?.approval.thumbnailFor(request.id) ?? null;
|
|
19104
|
+
if (thumb === null) return { ok: false, error: "no preview for this approval" };
|
|
19105
|
+
return { ok: true, mime: thumb.mime, base64: thumb.base64 };
|
|
19106
|
+
}
|
|
18699
19107
|
async browserAgentDemo(request) {
|
|
18700
19108
|
this.assertOwner();
|
|
18701
19109
|
if (request.action === "start") {
|