dsh-agent-enhancer 0.3.15 → 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/browser-agent/tab.d.ts.map +1 -1
- package/lib/client/dsh/settings-features.d.ts +1 -0
- package/lib/client/dsh/settings-features.d.ts.map +1 -1
- package/lib/client/dsh/settings.d.ts.map +1 -1
- package/lib/client/locales.d.ts +41 -1
- package/lib/client/locales.d.ts.map +1 -1
- package/lib/client/remote.d.ts +7 -1
- package/lib/client/remote.d.ts.map +1 -1
- package/lib/client.js +388 -18
- package/lib/client.js.map +1 -1
- package/lib/config.d.ts +2 -0
- package/lib/config.d.ts.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 +88 -0
- package/lib/host/browser-agent/demo.d.ts.map +1 -0
- package/lib/host/browser-agent/driver.d.ts +14 -0
- package/lib/host/browser-agent/driver.d.ts.map +1 -1
- package/lib/host/browser-agent/install.d.ts +13 -0
- package/lib/host/browser-agent/install.d.ts.map +1 -1
- package/lib/host/browser-agent/playwright-driver.d.ts +27 -0
- 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 +2 -0
- package/lib/host/browser-agent/tools.d.ts.map +1 -1
- package/lib/host/index.d.ts +8 -1
- package/lib/host/index.d.ts.map +1 -1
- package/lib/host/rpc.d.ts +164 -0
- package/lib/host/rpc.d.ts.map +1 -1
- package/lib/index.js +877 -10
- package/lib/index.js.map +4 -4
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -91,6 +91,7 @@ var DEFAULT_SETTINGS = {
|
|
|
91
91
|
browserAgentEnabled: false,
|
|
92
92
|
browserAgentBrowser: "auto",
|
|
93
93
|
browserAgentDebugTools: false,
|
|
94
|
+
browserAgentDemonstrate: false,
|
|
94
95
|
browserAgentIdleClose: "10m",
|
|
95
96
|
webChatBridgeEnabled: true,
|
|
96
97
|
instructionsSkillsEnabled: true,
|
|
@@ -138,6 +139,7 @@ function resolveSettings(value) {
|
|
|
138
139
|
browserAgentEnabled: value?.browserAgentEnabled ?? false,
|
|
139
140
|
browserAgentBrowser: resolveBrowserAgentBrowser(value?.browserAgentBrowser),
|
|
140
141
|
browserAgentDebugTools: value?.browserAgentDebugTools === true,
|
|
142
|
+
browserAgentDemonstrate: value?.browserAgentDemonstrate === true,
|
|
141
143
|
browserAgentIdleClose: resolveBrowserAgentIdleClose(value?.browserAgentIdleClose),
|
|
142
144
|
webChatBridgeEnabled: value?.webChatBridgeEnabled ?? true,
|
|
143
145
|
instructionsSkillsEnabled: value?.instructionsSkillsEnabled ?? true,
|
|
@@ -276,6 +278,10 @@ var BrowserApprovalGate = class {
|
|
|
276
278
|
const first = this.pending.values().next().value;
|
|
277
279
|
return first?.request ?? null;
|
|
278
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
|
+
}
|
|
279
285
|
/**
|
|
280
286
|
* Returns true when the action may proceed without prompting.
|
|
281
287
|
* Read-only tools should skip this gate entirely.
|
|
@@ -297,7 +303,8 @@ var BrowserApprovalGate = class {
|
|
|
297
303
|
tool: input.tool,
|
|
298
304
|
summary: input.summary,
|
|
299
305
|
...input.url === void 0 ? {} : { url: input.url },
|
|
300
|
-
...origin === void 0 ? {} : { origin }
|
|
306
|
+
...origin === void 0 ? {} : { origin },
|
|
307
|
+
...input.thumbnail === void 0 ? {} : { thumbnail: input.thumbnail }
|
|
301
308
|
};
|
|
302
309
|
const decision = await new Promise((resolve17, reject) => {
|
|
303
310
|
const onAbort = () => {
|
|
@@ -1067,6 +1074,310 @@ var CaptureBuffer = class {
|
|
|
1067
1074
|
}
|
|
1068
1075
|
};
|
|
1069
1076
|
|
|
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
|
+
}
|
|
1086
|
+
var SECRET_FIELD = /pass(word)?|\bpw\b|\bpwd\b|otp|one[-_]?time|code|pin|cvv|cvc|secret|token|card[-_]?number|iban/i;
|
|
1087
|
+
function isSensitiveFieldName(...parts) {
|
|
1088
|
+
return parts.some((part) => typeof part === "string" && SECRET_FIELD.test(part));
|
|
1089
|
+
}
|
|
1090
|
+
function pushDemoStep(steps, step, windowMs = 1500) {
|
|
1091
|
+
const last = steps[steps.length - 1];
|
|
1092
|
+
if (last !== void 0 && last.tabId === step.tabId && step.at - last.at <= windowMs) {
|
|
1093
|
+
if (last.kind === "fill" && step.kind === "fill" && last.selector === step.selector) {
|
|
1094
|
+
steps[steps.length - 1] = step;
|
|
1095
|
+
return;
|
|
1096
|
+
}
|
|
1097
|
+
if (last.kind === "click" && step.kind === "fill" && last.selector === step.selector) {
|
|
1098
|
+
steps[steps.length - 1] = step;
|
|
1099
|
+
return;
|
|
1100
|
+
}
|
|
1101
|
+
}
|
|
1102
|
+
if (steps.length >= 200) return;
|
|
1103
|
+
steps.push(step);
|
|
1104
|
+
}
|
|
1105
|
+
function mergeDemoSteps(pageSteps, navSteps) {
|
|
1106
|
+
const all = [...pageSteps, ...navSteps].sort((a, b) => a.at - b.at);
|
|
1107
|
+
const out = [];
|
|
1108
|
+
for (const step of all) {
|
|
1109
|
+
const prev = out[out.length - 1];
|
|
1110
|
+
if (prev !== void 0 && sameStep(prev, step)) continue;
|
|
1111
|
+
out.push(step);
|
|
1112
|
+
}
|
|
1113
|
+
return out;
|
|
1114
|
+
}
|
|
1115
|
+
function sameStep(a, b) {
|
|
1116
|
+
if (a.tabId !== b.tabId) return false;
|
|
1117
|
+
if (a.kind !== b.kind) return false;
|
|
1118
|
+
if (a.kind === "navigate" && b.kind === "navigate") return a.url === b.url;
|
|
1119
|
+
if (a.kind === "click" && b.kind === "click") return a.selector === b.selector;
|
|
1120
|
+
if (a.kind === "fill" && b.kind === "fill") return a.selector === b.selector && a.value === b.value;
|
|
1121
|
+
if (a.kind === "press" && b.kind === "press") return a.selector === b.selector && a.key === b.key;
|
|
1122
|
+
return false;
|
|
1123
|
+
}
|
|
1124
|
+
function sanitizeDemoSteps(steps) {
|
|
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
|
+
}
|
|
1130
|
+
if (step.kind !== "fill") return step;
|
|
1131
|
+
if (step.masked || !isSensitiveFieldName(step.field, step.name, step.selector)) return step;
|
|
1132
|
+
return { ...step, value: "***", masked: true };
|
|
1133
|
+
});
|
|
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
|
+
}
|
|
1154
|
+
function summarizeDemoSteps(steps, max = 40) {
|
|
1155
|
+
const shown = steps.slice(0, Math.max(1, max));
|
|
1156
|
+
const tabs = collectTabs(shown);
|
|
1157
|
+
const multiTab = tabs.length > 1;
|
|
1158
|
+
const lines = shown.map((step, index) => {
|
|
1159
|
+
const n = index + 1;
|
|
1160
|
+
const tag = multiTab && step.tabId !== void 0 ? `[tab ${step.tabId}] ` : "";
|
|
1161
|
+
return `${n}. ${tag}${describeDemoStep(step)}`;
|
|
1162
|
+
});
|
|
1163
|
+
return {
|
|
1164
|
+
lines,
|
|
1165
|
+
shown: shown.length,
|
|
1166
|
+
masked: shown.filter((step) => step.kind === "fill" && step.masked).length,
|
|
1167
|
+
tabs,
|
|
1168
|
+
multiTab
|
|
1169
|
+
};
|
|
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
|
+
}
|
|
1186
|
+
var DEMO_SYMBOL = "Symbol.for('dsh-demo')";
|
|
1187
|
+
var DEMO_RECORDER_SOURCE = `"use strict";
|
|
1188
|
+
var KEY = ${DEMO_SYMBOL};
|
|
1189
|
+
var existing = window[KEY];
|
|
1190
|
+
if (existing) { try { existing.stop(); } catch (e) { } }
|
|
1191
|
+
var SECRET = /pass(word)?|\\bpw\\b|\\bpwd\\b|otp|one[-_]?time|code|pin|cvv|cvc|secret|token|card[-_]?number|iban/i;
|
|
1192
|
+
var steps = [];
|
|
1193
|
+
var OFF = [];
|
|
1194
|
+
function textOf(el, max) {
|
|
1195
|
+
var raw = el.getAttribute("aria-label") || el.getAttribute("title") || (el.innerText || el.textContent || "");
|
|
1196
|
+
return String(raw || "").replace(/\\s+/g, " ").trim().slice(0, max || 60);
|
|
1197
|
+
}
|
|
1198
|
+
function roleOf(el) {
|
|
1199
|
+
var explicit = el.getAttribute("role");
|
|
1200
|
+
if (explicit) return explicit;
|
|
1201
|
+
var tag = el.tagName.toLowerCase();
|
|
1202
|
+
if (tag === "a") return "link";
|
|
1203
|
+
if (tag === "button") return "button";
|
|
1204
|
+
if (tag === "select") return "combobox";
|
|
1205
|
+
if (tag === "textarea") return "textbox";
|
|
1206
|
+
if (tag === "input") {
|
|
1207
|
+
var type = (el.getAttribute("type") || "text").toLowerCase();
|
|
1208
|
+
if (type === "checkbox") return "checkbox";
|
|
1209
|
+
if (type === "radio") return "radio";
|
|
1210
|
+
if (type === "submit" || type === "button") return "button";
|
|
1211
|
+
return "textbox";
|
|
1212
|
+
}
|
|
1213
|
+
return tag;
|
|
1214
|
+
}
|
|
1215
|
+
function selectorOf(el) {
|
|
1216
|
+
try {
|
|
1217
|
+
if (el.id && document.querySelectorAll("#" + CSS.escape(el.id)).length === 1) return "#" + CSS.escape(el.id);
|
|
1218
|
+
} catch (e) { }
|
|
1219
|
+
var testid = el.getAttribute("data-testid") || el.getAttribute("data-test-id");
|
|
1220
|
+
if (testid) return '[data-testid="' + testid + '"]';
|
|
1221
|
+
var name = el.getAttribute("name");
|
|
1222
|
+
if (name) return el.tagName.toLowerCase() + '[name="' + name + '"]';
|
|
1223
|
+
var parts = [];
|
|
1224
|
+
var node = el;
|
|
1225
|
+
while (node && node.nodeType === 1 && parts.length < 6) {
|
|
1226
|
+
var tag = node.tagName.toLowerCase();
|
|
1227
|
+
if (node.id) { parts.unshift("#" + CSS.escape(node.id)); break; }
|
|
1228
|
+
var parent = node.parentElement;
|
|
1229
|
+
var same = parent ? Array.prototype.filter.call(parent.children, function (child) { return child.tagName === node.tagName; }) : [];
|
|
1230
|
+
parts.unshift(same.length > 1 ? tag + ":nth-of-type(" + (same.indexOf(node) + 1) + ")" : tag);
|
|
1231
|
+
node = parent;
|
|
1232
|
+
}
|
|
1233
|
+
return parts.join(" > ");
|
|
1234
|
+
}
|
|
1235
|
+
function push(step) {
|
|
1236
|
+
step.at = Date.now();
|
|
1237
|
+
try { if (typeof window.__dshDemoPush === "function") window.__dshDemoPush(step); } catch (e) { }
|
|
1238
|
+
}
|
|
1239
|
+
function isSecret(el) {
|
|
1240
|
+
var type = (el.getAttribute("type") || "").toLowerCase();
|
|
1241
|
+
if (type === "password") return true;
|
|
1242
|
+
return SECRET.test(el.getAttribute("name") || "") || SECRET.test(el.id || "")
|
|
1243
|
+
|| SECRET.test(el.getAttribute("autocomplete") || "") || SECRET.test(el.getAttribute("placeholder") || "");
|
|
1244
|
+
}
|
|
1245
|
+
function on(target, type, handler, capture) {
|
|
1246
|
+
target.addEventListener(type, handler, capture === true);
|
|
1247
|
+
OFF.push(function () { target.removeEventListener(type, handler, capture === true); });
|
|
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);
|
|
1276
|
+
on(document, "click", function (event) {
|
|
1277
|
+
var el = event.target && event.target.closest ? event.target.closest("a,button,input,select,textarea,[role],[contenteditable='true']") : null;
|
|
1278
|
+
if (!el) return;
|
|
1279
|
+
var href = el.tagName === "A" && el.href ? String(el.href) : "";
|
|
1280
|
+
push({ kind: "click", role: roleOf(el), name: textOf(el), selector: selectorOf(el), href: /^https?:\\/\\//i.test(href) ? href : "" });
|
|
1281
|
+
}, true);
|
|
1282
|
+
function fieldStep(el) {
|
|
1283
|
+
var tag = el.tagName.toLowerCase();
|
|
1284
|
+
var type = (el.getAttribute("type") || "").toLowerCase();
|
|
1285
|
+
if (tag === "select") {
|
|
1286
|
+
push({ kind: "fill", role: "combobox", name: textOf(el), selector: selectorOf(el), field: el.name || el.id || "select", value: String(el.value || ""), masked: false });
|
|
1287
|
+
return;
|
|
1288
|
+
}
|
|
1289
|
+
if (type === "checkbox" || type === "radio") {
|
|
1290
|
+
push({ kind: "fill", role: type, name: textOf(el), selector: selectorOf(el), field: el.name || el.id || type, value: el.checked ? "on" : "off", masked: false, checked: el.checked });
|
|
1291
|
+
return;
|
|
1292
|
+
}
|
|
1293
|
+
if (tag !== "input" && tag !== "textarea") return;
|
|
1294
|
+
var secret = isSecret(el);
|
|
1295
|
+
push({
|
|
1296
|
+
kind: "fill",
|
|
1297
|
+
role: roleOf(el),
|
|
1298
|
+
name: textOf(el) || el.getAttribute("placeholder") || "",
|
|
1299
|
+
selector: selectorOf(el),
|
|
1300
|
+
field: el.name || el.id || type || "field",
|
|
1301
|
+
value: secret ? "***" : String(el.value || ""),
|
|
1302
|
+
masked: secret,
|
|
1303
|
+
});
|
|
1304
|
+
}
|
|
1305
|
+
// "input" catches typing as it happens; "change" catches selects, checkboxes and blur.
|
|
1306
|
+
on(document, "input", function (event) {
|
|
1307
|
+
var el = event.target;
|
|
1308
|
+
if (!el || !el.tagName) return;
|
|
1309
|
+
fieldStep(el);
|
|
1310
|
+
}, true);
|
|
1311
|
+
on(document, "change", function (event) {
|
|
1312
|
+
var el = event.target;
|
|
1313
|
+
if (!el || !el.tagName) return;
|
|
1314
|
+
var tag = el.tagName.toLowerCase();
|
|
1315
|
+
var type = (el.getAttribute("type") || "").toLowerCase();
|
|
1316
|
+
if (tag === "select" || type === "checkbox" || type === "radio") fieldStep(el);
|
|
1317
|
+
}, true);
|
|
1318
|
+
on(document, "keydown", function (event) {
|
|
1319
|
+
if (event.key !== "Enter") return;
|
|
1320
|
+
var el = event.target;
|
|
1321
|
+
if (!el || !el.tagName) return;
|
|
1322
|
+
push({ kind: "press", key: "Enter", selector: selectorOf(el) });
|
|
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();
|
|
1363
|
+
var recorder = {
|
|
1364
|
+
stop: function () {
|
|
1365
|
+
for (var i = 0; i < OFF.length; i++) { try { OFF[i](); } catch (e) { } }
|
|
1366
|
+
OFF.length = 0;
|
|
1367
|
+
try { if (badge && badge.parentNode) badge.parentNode.removeChild(badge); } catch (e) { }
|
|
1368
|
+
badge = null;
|
|
1369
|
+
delete window[KEY];
|
|
1370
|
+
},
|
|
1371
|
+
};
|
|
1372
|
+
window[KEY] = recorder;
|
|
1373
|
+
return true;
|
|
1374
|
+
`;
|
|
1375
|
+
var DEMO_STOP_SOURCE = `(() => {
|
|
1376
|
+
const r = window[${DEMO_SYMBOL}];
|
|
1377
|
+
if (r) { try { r.stop(); } catch (e) { } }
|
|
1378
|
+
return true;
|
|
1379
|
+
})()`;
|
|
1380
|
+
|
|
1070
1381
|
// src/host/browser-agent/auto-nav.ts
|
|
1071
1382
|
function pathKey(raw) {
|
|
1072
1383
|
try {
|
|
@@ -1181,6 +1492,28 @@ var TabRegistry = class {
|
|
|
1181
1492
|
}
|
|
1182
1493
|
};
|
|
1183
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
|
+
|
|
1184
1517
|
// src/host/browser-agent/playwright-driver.ts
|
|
1185
1518
|
var playwrightModule = null;
|
|
1186
1519
|
async function loadPlaywright() {
|
|
@@ -1208,6 +1541,13 @@ var PlaywrightDriver = class {
|
|
|
1208
1541
|
requestStart = /* @__PURE__ */ new WeakMap();
|
|
1209
1542
|
/** Last applied emulation per tab, echoed in snapshot so the agent can see it. */
|
|
1210
1543
|
emulationByTab = /* @__PURE__ */ new Map();
|
|
1544
|
+
/** Active "show me" recording: bound page plus navigations seen meanwhile. */
|
|
1545
|
+
demoPage = null;
|
|
1546
|
+
demoNavSteps = [];
|
|
1547
|
+
demoPageSteps = [];
|
|
1548
|
+
demoTrackedPages = /* @__PURE__ */ new WeakSet();
|
|
1549
|
+
demoPageHandler = null;
|
|
1550
|
+
demoBindingReady = false;
|
|
1211
1551
|
/** Last agent/UI use per page; a page's clock starts when it is first seen. */
|
|
1212
1552
|
lastUse = /* @__PURE__ */ new WeakMap();
|
|
1213
1553
|
constructor(options) {
|
|
@@ -1619,6 +1959,17 @@ var PlaywrightDriver = class {
|
|
|
1619
1959
|
tabId: this.tabIdFor(page)
|
|
1620
1960
|
};
|
|
1621
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
|
+
}
|
|
1622
1973
|
async scroll(dy) {
|
|
1623
1974
|
const page = await this.requirePage();
|
|
1624
1975
|
await page.mouse.wheel(0, dy);
|
|
@@ -1660,6 +2011,28 @@ var PlaywrightDriver = class {
|
|
|
1660
2011
|
tabId: this.tabIdFor(page)
|
|
1661
2012
|
};
|
|
1662
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
|
+
}
|
|
1663
2036
|
async listTabs() {
|
|
1664
2037
|
const pages = this.context?.pages() ?? [];
|
|
1665
2038
|
if (pages.length === 0) {
|
|
@@ -1797,6 +2170,99 @@ var PlaywrightDriver = class {
|
|
|
1797
2170
|
tabId: this.tabIdFor(page)
|
|
1798
2171
|
};
|
|
1799
2172
|
}
|
|
2173
|
+
/** Record a user demonstration across every tab of the dedicated browser. */
|
|
2174
|
+
async startDemonstration() {
|
|
2175
|
+
const page = await this.requirePage();
|
|
2176
|
+
if (this.demoPage !== null) await this.stopDemonstration().catch(() => void 0);
|
|
2177
|
+
this.demoPage = page;
|
|
2178
|
+
this.demoNavSteps = [];
|
|
2179
|
+
this.demoPageSteps = [];
|
|
2180
|
+
const context = page.context();
|
|
2181
|
+
if (!this.demoBindingReady) {
|
|
2182
|
+
try {
|
|
2183
|
+
await context.exposeBinding("__dshDemoPush", (source, step) => {
|
|
2184
|
+
if (this.demoPage === null) return;
|
|
2185
|
+
const from = source.page;
|
|
2186
|
+
pushDemoStep(
|
|
2187
|
+
this.demoPageSteps,
|
|
2188
|
+
from === void 0 || from.isClosed() ? step : attachDemoTab(step, this.demoSite(from))
|
|
2189
|
+
);
|
|
2190
|
+
});
|
|
2191
|
+
this.demoBindingReady = true;
|
|
2192
|
+
} catch {
|
|
2193
|
+
this.demoBindingReady = true;
|
|
2194
|
+
}
|
|
2195
|
+
}
|
|
2196
|
+
for (const open of context.pages()) this.armDemoPage(open);
|
|
2197
|
+
if (this.demoPageHandler === null) {
|
|
2198
|
+
this.demoPageHandler = (opened) => {
|
|
2199
|
+
if (this.demoPage === null) return;
|
|
2200
|
+
this.armDemoPage(opened);
|
|
2201
|
+
};
|
|
2202
|
+
context.on("page", this.demoPageHandler);
|
|
2203
|
+
}
|
|
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
|
+
}
|
|
2218
|
+
/**
|
|
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.
|
|
2222
|
+
*/
|
|
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);
|
|
2242
|
+
}
|
|
2243
|
+
/** Stop recording and return the flow, secrets masked, repeats dropped. */
|
|
2244
|
+
demonstrationActive() {
|
|
2245
|
+
return this.demoPage !== null;
|
|
2246
|
+
}
|
|
2247
|
+
async stopDemonstration() {
|
|
2248
|
+
const page = this.demoPage;
|
|
2249
|
+
this.demoPage = null;
|
|
2250
|
+
if (this.demoPageHandler !== null) {
|
|
2251
|
+
this.context?.off("page", this.demoPageHandler);
|
|
2252
|
+
this.demoPageHandler = null;
|
|
2253
|
+
}
|
|
2254
|
+
if (page !== null && !page.isClosed()) {
|
|
2255
|
+
await page.evaluate(DEMO_STOP_SOURCE).catch(() => void 0);
|
|
2256
|
+
}
|
|
2257
|
+
for (const other of this.context?.pages() ?? []) {
|
|
2258
|
+
if (other === page || other.isClosed()) continue;
|
|
2259
|
+
await other.evaluate(DEMO_STOP_SOURCE).catch(() => void 0);
|
|
2260
|
+
}
|
|
2261
|
+
const steps = sanitizeDemoSteps(mergeDemoSteps(this.demoPageSteps, this.demoNavSteps));
|
|
2262
|
+
this.demoNavSteps = [];
|
|
2263
|
+
this.demoPageSteps = [];
|
|
2264
|
+
return steps;
|
|
2265
|
+
}
|
|
1800
2266
|
/** Record what is now emulated on this tab, so snapshot can echo it. */
|
|
1801
2267
|
rememberEmulation(tabId, input) {
|
|
1802
2268
|
const next = { ...this.emulationByTab.get(tabId) ?? {} };
|
|
@@ -1851,6 +2317,9 @@ function sleep(ms) {
|
|
|
1851
2317
|
setTimeout(resolve17, ms);
|
|
1852
2318
|
});
|
|
1853
2319
|
}
|
|
2320
|
+
function demoRecorderScript() {
|
|
2321
|
+
return `(() => { ${DEMO_RECORDER_SOURCE} })()`;
|
|
2322
|
+
}
|
|
1854
2323
|
function clipText(text3, max) {
|
|
1855
2324
|
const flat = text3.replace(/\s+/g, " ").trim();
|
|
1856
2325
|
return flat.length > max ? `${flat.slice(0, max)}\u2026` : flat;
|
|
@@ -1916,6 +2385,9 @@ var GUIDANCE = [
|
|
|
1916
2385
|
"Below-the-fold or long content: browser_scroll \u2192 browser_wait \u2192 browser_extract. Report what extract returns; do not hop to unrelated pages.",
|
|
1917
2386
|
"The dedicated browser auto-launches when needed; never tell the user to click \u201CLaunch browser agent\u201D unless the tool error says so.",
|
|
1918
2387
|
"Mutation tools may pause for an in-app Allow card \u2014 wait for allow/deny.",
|
|
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.",
|
|
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.',
|
|
1919
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.",
|
|
1920
2392
|
"Do not invent page content or refs. Prefer finishing the user task over exploring more pages."
|
|
1921
2393
|
].join("\n");
|
|
@@ -2219,6 +2691,133 @@ function classify(input) {
|
|
|
2219
2691
|
|
|
2220
2692
|
// src/host/browser-agent/tools.ts
|
|
2221
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
|
|
2222
2821
|
var HUMAN_WAIT_TIMEOUT_MS = 15 * 6e4;
|
|
2223
2822
|
function textTool(name2, description, parameters, execute, timeoutMs = 6e4) {
|
|
2224
2823
|
return defineTool({
|
|
@@ -2367,6 +2966,12 @@ function registerBrowserTools(ctx, options) {
|
|
|
2367
2966
|
}
|
|
2368
2967
|
await driverOf(options).ensureReady(startUrl);
|
|
2369
2968
|
};
|
|
2969
|
+
const requireDemonstrate = () => {
|
|
2970
|
+
if (options.demonstrate?.() === true) return;
|
|
2971
|
+
throw new Error(
|
|
2972
|
+
"browser_demonstrate: demonstration recording is off. Nothing is recording. 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, then retry."
|
|
2973
|
+
);
|
|
2974
|
+
};
|
|
2370
2975
|
const requireDebugTools = (tool) => {
|
|
2371
2976
|
if (options.debugTools?.() === true) return;
|
|
2372
2977
|
try {
|
|
@@ -2390,7 +2995,7 @@ function registerBrowserTools(ctx, options) {
|
|
|
2390
2995
|
});
|
|
2391
2996
|
throw new Error(scope.refusal(tabId));
|
|
2392
2997
|
};
|
|
2393
|
-
const requireMutation = async (exec, tool, summary, url) => {
|
|
2998
|
+
const requireMutation = async (exec, tool, summary, url, targetRef) => {
|
|
2394
2999
|
const sessionId = sessionIdOf(exec);
|
|
2395
3000
|
let effectiveUrl = typeof url === "string" && /^https?:\/\//i.test(url) ? url : void 0;
|
|
2396
3001
|
if (effectiveUrl === void 0) {
|
|
@@ -2398,12 +3003,15 @@ function registerBrowserTools(ctx, options) {
|
|
|
2398
3003
|
} else {
|
|
2399
3004
|
options.sessions.rememberHttpUrl(sessionId, effectiveUrl);
|
|
2400
3005
|
}
|
|
3006
|
+
const thumbDriver = driverOf(options);
|
|
3007
|
+
const thumbnail = targetRef === void 0 || typeof thumbDriver.thumbnail !== "function" ? null : await thumbDriver.thumbnail(targetRef).catch(() => null);
|
|
2401
3008
|
const decision = await options.approval.requestApproval({
|
|
2402
3009
|
sessionId,
|
|
2403
3010
|
tool,
|
|
2404
3011
|
summary,
|
|
2405
3012
|
url: effectiveUrl,
|
|
2406
|
-
signal: exec.signal
|
|
3013
|
+
signal: exec.signal,
|
|
3014
|
+
...thumbnail === null ? {} : { thumbnail }
|
|
2407
3015
|
});
|
|
2408
3016
|
if (decision === "deny") {
|
|
2409
3017
|
options.sessions.record({
|
|
@@ -2794,7 +3402,7 @@ function registerBrowserTools(ctx, options) {
|
|
|
2794
3402
|
);
|
|
2795
3403
|
}
|
|
2796
3404
|
const snapshotHref = options.sessions.hrefOfRef(sessionId, ref);
|
|
2797
|
-
await requireMutation(exec, "browser_click", `Click ref ${ref}`, url);
|
|
3405
|
+
await requireMutation(exec, "browser_click", `Click ref ${ref}`, url, ref);
|
|
2798
3406
|
try {
|
|
2799
3407
|
const beforeUrl = typeof url === "string" ? url : "";
|
|
2800
3408
|
let result = await runBridge(() => driverOf(options).click(ref));
|
|
@@ -2909,7 +3517,7 @@ function registerBrowserTools(ctx, options) {
|
|
|
2909
3517
|
url = void 0;
|
|
2910
3518
|
}
|
|
2911
3519
|
requireFreshRef(sessionId, ref, "browser_type");
|
|
2912
|
-
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);
|
|
2913
3521
|
try {
|
|
2914
3522
|
const result = await runBridge(() => driverOf(options).type(ref, text3));
|
|
2915
3523
|
await rememberTab(sessionId, result.tabId);
|
|
@@ -3297,6 +3905,121 @@ Action: browser_extract or browser_snapshot next. Do not navigate away unless th
|
|
|
3297
3905
|
].filter((line) => line !== null).join("\n");
|
|
3298
3906
|
}
|
|
3299
3907
|
)));
|
|
3908
|
+
disposers.push(ctx.tools.register(textTool(
|
|
3909
|
+
"browser_demonstrate",
|
|
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.",
|
|
3911
|
+
{
|
|
3912
|
+
message: {
|
|
3913
|
+
type: "string",
|
|
3914
|
+
required: true,
|
|
3915
|
+
description: `What to show, in the user's language, e.g. "Show me how you export the report, then click Continue."`
|
|
3916
|
+
},
|
|
3917
|
+
timeoutMs: {
|
|
3918
|
+
type: "number",
|
|
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."
|
|
3924
|
+
}
|
|
3925
|
+
},
|
|
3926
|
+
async (args, exec) => {
|
|
3927
|
+
guardEnabled();
|
|
3928
|
+
requireDemonstrate();
|
|
3929
|
+
const sessionId = sessionIdOf(exec);
|
|
3930
|
+
const message = String(args.message ?? "").trim();
|
|
3931
|
+
if (message === "") throw new Error("message is required");
|
|
3932
|
+
const timeoutRaw = Number(args.timeoutMs);
|
|
3933
|
+
const timeoutMs = Number.isFinite(timeoutRaw) ? Math.min(Math.max(Math.trunc(timeoutRaw), 3e4), 9e5) : HUMAN_WAIT_TIMEOUT_MS;
|
|
3934
|
+
await ensureConnected();
|
|
3935
|
+
await ensureSessionTab(sessionId);
|
|
3936
|
+
const driver = driverOf(options);
|
|
3937
|
+
const tabId = options.sessions.tabOf(sessionId);
|
|
3938
|
+
await driver.startDemonstration();
|
|
3939
|
+
options.sessions.record({
|
|
3940
|
+
sessionId,
|
|
3941
|
+
tool: "browser_demonstrate",
|
|
3942
|
+
summary: message.slice(0, 160),
|
|
3943
|
+
outcome: "needs_human"
|
|
3944
|
+
});
|
|
3945
|
+
const status = await pauseForHuman({
|
|
3946
|
+
sessionId,
|
|
3947
|
+
prompt: message,
|
|
3948
|
+
detail: message.slice(0, 240),
|
|
3949
|
+
kind: "ask",
|
|
3950
|
+
...tabId === void 0 ? {} : { tabId },
|
|
3951
|
+
signal: exec.signal
|
|
3952
|
+
});
|
|
3953
|
+
const steps = await driver.stopDemonstration().catch(() => []);
|
|
3954
|
+
if (status === "cancelled") {
|
|
3955
|
+
return "user_ack: cancelled\nAction: the demonstration was cancelled. Ask what they want next.";
|
|
3956
|
+
}
|
|
3957
|
+
const summary = summarizeDemoSteps(steps);
|
|
3958
|
+
options.sessions.record({
|
|
3959
|
+
sessionId,
|
|
3960
|
+
tool: "browser_demonstrate",
|
|
3961
|
+
summary: `Demonstrated ${summary.shown} step(s)${summary.multiTab ? ` across ${summary.tabs.length} tabs` : ""}`,
|
|
3962
|
+
outcome: "ok"
|
|
3963
|
+
});
|
|
3964
|
+
if (summary.shown === 0) {
|
|
3965
|
+
return [
|
|
3966
|
+
"demonstrated steps: 0",
|
|
3967
|
+
"Nothing was recorded \u2014 the user may have pressed Continue without acting.",
|
|
3968
|
+
"Action: call browser_ask_user to check, or browser_snapshot and continue on your own."
|
|
3969
|
+
].join("\n");
|
|
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
|
+
}
|
|
4013
|
+
return [
|
|
4014
|
+
heading,
|
|
4015
|
+
...maskedLine,
|
|
4016
|
+
...demoTabLegend(summary),
|
|
4017
|
+
...summary.lines,
|
|
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."
|
|
4019
|
+
].join("\n");
|
|
4020
|
+
},
|
|
4021
|
+
HUMAN_WAIT_TIMEOUT_MS
|
|
4022
|
+
)));
|
|
3300
4023
|
disposers.push(ctx.tools.register(textTool(
|
|
3301
4024
|
"browser_list_tabs",
|
|
3302
4025
|
"List open browser tabs (id, title, url, active, bound). Read-only; no approval. Use with browser_follow_tab to bind this session to another tab.",
|
|
@@ -3501,6 +4224,7 @@ function installBrowserAgent(ctx, options) {
|
|
|
3501
4224
|
sessions,
|
|
3502
4225
|
tabScope,
|
|
3503
4226
|
debugTools: () => options.debugTools?.() === true,
|
|
4227
|
+
demonstrate: () => options.demonstrate?.() === true,
|
|
3504
4228
|
diagnosis: diagnoseNow,
|
|
3505
4229
|
// Gate on settings only — `active` flips false during driver align and
|
|
3506
4230
|
// must not make browser_* look "disabled" mid-turn.
|
|
@@ -3671,6 +4395,46 @@ function installBrowserAgent(ctx, options) {
|
|
|
3671
4395
|
});
|
|
3672
4396
|
return { ok: true };
|
|
3673
4397
|
},
|
|
4398
|
+
async demoStart() {
|
|
4399
|
+
if (!options.enabled()) return { ok: false, error: "Browser agent disabled" };
|
|
4400
|
+
if (options.demonstrate?.() !== true) {
|
|
4401
|
+
return { ok: false, error: "\u6F14\u793A\u5F55\u5236\u672A\u5F00\u542F\uFF1A\u8BBE\u7F6E \u2192 \u529F\u80FD \u2192 \u6D4F\u89C8\u5668 Agent" };
|
|
4402
|
+
}
|
|
4403
|
+
try {
|
|
4404
|
+
const aligned = await alignToPreference();
|
|
4405
|
+
if (!aligned.ok) return { ok: false, error: aligned.error ?? "Browser agent failed to start" };
|
|
4406
|
+
await requireDriver().startDemonstration();
|
|
4407
|
+
sessions.record({
|
|
4408
|
+
sessionId: "sidebar",
|
|
4409
|
+
tool: "browser_demonstrate",
|
|
4410
|
+
summary: "Demonstration recording started from the sidebar",
|
|
4411
|
+
outcome: "needs_human"
|
|
4412
|
+
});
|
|
4413
|
+
return { ok: true };
|
|
4414
|
+
} catch (error) {
|
|
4415
|
+
return { ok: false, error: error instanceof Error ? error.message : String(error) };
|
|
4416
|
+
}
|
|
4417
|
+
},
|
|
4418
|
+
async demoStop() {
|
|
4419
|
+
const driver = activeDriver;
|
|
4420
|
+
if (driver === null) return { ok: false, error: "Browser agent is not running" };
|
|
4421
|
+
try {
|
|
4422
|
+
const steps = await driver.stopDemonstration();
|
|
4423
|
+
const summary = summarizeDemoSteps(steps);
|
|
4424
|
+
sessions.record({
|
|
4425
|
+
sessionId: "sidebar",
|
|
4426
|
+
tool: "browser_demonstrate",
|
|
4427
|
+
summary: `Demonstration stopped from the sidebar (${summary.shown} step(s)${summary.multiTab ? ` across ${summary.tabs.length} tabs` : ""})`,
|
|
4428
|
+
outcome: "ok"
|
|
4429
|
+
});
|
|
4430
|
+
return { ok: true, steps: [...demoTabLegend(summary), ...summary.lines] };
|
|
4431
|
+
} catch (error) {
|
|
4432
|
+
return { ok: false, error: error instanceof Error ? error.message : String(error) };
|
|
4433
|
+
}
|
|
4434
|
+
},
|
|
4435
|
+
demoActive() {
|
|
4436
|
+
return activeDriver?.demonstrationActive() === true;
|
|
4437
|
+
},
|
|
3674
4438
|
async selectTab(input) {
|
|
3675
4439
|
if (!options.enabled()) return { ok: false, error: "Browser agent disabled" };
|
|
3676
4440
|
await switchGate.catch(() => void 0);
|
|
@@ -15769,7 +16533,9 @@ var browserAgentPendingSchema = z4.strictObject({
|
|
|
15769
16533
|
tool: z4.string().min(1),
|
|
15770
16534
|
summary: z4.string().min(1),
|
|
15771
16535
|
url: z4.string().optional(),
|
|
15772
|
-
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()
|
|
15773
16539
|
});
|
|
15774
16540
|
var browserAgentTabConflictSchema = z4.strictObject({
|
|
15775
16541
|
sessionId: z4.string().min(1),
|
|
@@ -15832,6 +16598,11 @@ var browserAgentSnapshotSchema = z4.strictObject({
|
|
|
15832
16598
|
pending: browserAgentPendingSchema.nullable(),
|
|
15833
16599
|
/** Why the browser is (not) usable and the concrete next step. */
|
|
15834
16600
|
diagnosis: browserAgentDiagnosisSchema,
|
|
16601
|
+
/** Demonstration recorder: switch state and whether it is recording now. */
|
|
16602
|
+
demo: z4.strictObject({
|
|
16603
|
+
enabled: z4.boolean(),
|
|
16604
|
+
recording: z4.boolean()
|
|
16605
|
+
}),
|
|
15835
16606
|
tabConflict: browserAgentTabConflictSchema.nullable(),
|
|
15836
16607
|
needsHuman: browserAgentNeedsHumanSchema.nullable(),
|
|
15837
16608
|
boundTabId: z4.number().int().nullable(),
|
|
@@ -15845,6 +16616,41 @@ var browserAgentSnapshotCodec = codec(
|
|
|
15845
16616
|
"dsh-agent-enhancer#BrowserAgentSnapshot",
|
|
15846
16617
|
browserAgentSnapshotSchema
|
|
15847
16618
|
);
|
|
16619
|
+
var browserAgentDemoRequestSchema = z4.strictObject({
|
|
16620
|
+
action: z4.enum(["start", "stop"])
|
|
16621
|
+
});
|
|
16622
|
+
var browserAgentDemoRequestCodec = codec(
|
|
16623
|
+
"dsh-agent-enhancer#BrowserAgentDemoRequest",
|
|
16624
|
+
browserAgentDemoRequestSchema
|
|
16625
|
+
);
|
|
16626
|
+
var browserAgentDemoResultSchema = z4.strictObject({
|
|
16627
|
+
ok: z4.boolean(),
|
|
16628
|
+
/** One line per recorded step, when stopping. */
|
|
16629
|
+
steps: z4.array(z4.string()).optional(),
|
|
16630
|
+
error: z4.string().optional(),
|
|
16631
|
+
snapshot: browserAgentSnapshotSchema
|
|
16632
|
+
});
|
|
16633
|
+
var browserAgentDemoResultCodec = codec(
|
|
16634
|
+
"dsh-agent-enhancer#BrowserAgentDemoResult",
|
|
16635
|
+
browserAgentDemoResultSchema
|
|
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
|
+
);
|
|
15848
16654
|
var browserAgentResolveRequestSchema = z4.strictObject({
|
|
15849
16655
|
id: z4.string().min(1),
|
|
15850
16656
|
decision: browserAgentApprovalDecisionSchema
|
|
@@ -16739,6 +17545,30 @@ var remoteInfo = createTypertRemoteInfo({
|
|
|
16739
17545
|
}],
|
|
16740
17546
|
result: browserAgentSelectTabResultCodec
|
|
16741
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
|
+
},
|
|
17560
|
+
"agentEnhancer/browserAgentDemo": {
|
|
17561
|
+
service: "agentEnhancer",
|
|
17562
|
+
implementation: "browserAgentDemo",
|
|
17563
|
+
invocation: { kind: "direct" },
|
|
17564
|
+
parameters: [{
|
|
17565
|
+
name: "request",
|
|
17566
|
+
source: "json",
|
|
17567
|
+
codec: browserAgentDemoRequestCodec,
|
|
17568
|
+
strictCodec: browserAgentDemoRequestCodec
|
|
17569
|
+
}],
|
|
17570
|
+
result: browserAgentDemoResultCodec
|
|
17571
|
+
},
|
|
16742
17572
|
"agentEnhancer/browserAgentSetTabReadOnly": {
|
|
16743
17573
|
service: "agentEnhancer",
|
|
16744
17574
|
implementation: "browserAgentSetTabReadOnly",
|
|
@@ -17428,6 +18258,8 @@ var Config = z5.object({
|
|
|
17428
18258
|
browserAgentBrowser: z5.string().default("auto").volatile(),
|
|
17429
18259
|
/** Debug tools (network / console / emulate); default off, gated per tool. */
|
|
17430
18260
|
browserAgentDebugTools: z5.boolean().default(false).volatile(),
|
|
18261
|
+
/** "Show me" recorder; observes user actions in the bound tab, default off. */
|
|
18262
|
+
browserAgentDemonstrate: z5.boolean().default(false).volatile(),
|
|
17431
18263
|
/** Close idle agent tabs after ~10 min; coerced via resolveBrowserAgentIdleClose. */
|
|
17432
18264
|
browserAgentIdleClose: z5.union([z5.boolean(), z5.string()]).default("10m").volatile(),
|
|
17433
18265
|
/** Default off; embeds official web chat + import to work. */
|
|
@@ -17481,7 +18313,8 @@ var AgentEnhancerService = class extends TypertRemoteService {
|
|
|
17481
18313
|
join30(homedir5(), ".dsh", "profiles", "desktop", "plugin-data", PACKAGE_NAME, "extra-folders")
|
|
17482
18314
|
), softPause = new SoftPauseGate(), softPauseEnabled = () => true, installLedgerRoot = void 0, mcpHost = null, browserAgent = null, browserAgentSettings = () => ({
|
|
17483
18315
|
enabled: false,
|
|
17484
|
-
browser: "auto"
|
|
18316
|
+
browser: "auto",
|
|
18317
|
+
demonstrate: false
|
|
17485
18318
|
}), setBrowserAgentBrowser = () => void 0, browserAgentProfileDir = defaultBrowserAgentProfileDir(
|
|
17486
18319
|
join30(homedir5(), ".dsh", "profiles", "desktop", "plugin-data", PACKAGE_NAME)
|
|
17487
18320
|
)) {
|
|
@@ -17551,7 +18384,12 @@ var AgentEnhancerService = class extends TypertRemoteService {
|
|
|
17551
18384
|
tool: pending.tool,
|
|
17552
18385
|
summary: pending.summary,
|
|
17553
18386
|
...pending.url === void 0 ? {} : { url: pending.url },
|
|
17554
|
-
...pending.origin === void 0 ? {} : { origin: pending.origin }
|
|
18387
|
+
...pending.origin === void 0 ? {} : { origin: pending.origin },
|
|
18388
|
+
hasThumbnail: pending.thumbnail !== void 0
|
|
18389
|
+
},
|
|
18390
|
+
demo: {
|
|
18391
|
+
enabled: settings.demonstrate,
|
|
18392
|
+
recording: this.browserAgent?.demoActive() === true
|
|
17555
18393
|
},
|
|
17556
18394
|
diagnosis: diag ?? {
|
|
17557
18395
|
code: settings.enabled ? "idle" : "disabled",
|
|
@@ -18260,6 +19098,30 @@ var AgentEnhancerService = class extends TypertRemoteService {
|
|
|
18260
19098
|
snapshot: await this.browserSnapshotNow()
|
|
18261
19099
|
};
|
|
18262
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
|
+
}
|
|
19107
|
+
async browserAgentDemo(request) {
|
|
19108
|
+
this.assertOwner();
|
|
19109
|
+
if (request.action === "start") {
|
|
19110
|
+
const result = await (this.browserAgent?.demoStart() ?? Promise.resolve({ ok: false, error: "runtime unavailable" }));
|
|
19111
|
+
return {
|
|
19112
|
+
ok: result.ok === true,
|
|
19113
|
+
...result.error === void 0 ? {} : { error: result.error },
|
|
19114
|
+
snapshot: await this.browserSnapshotNow()
|
|
19115
|
+
};
|
|
19116
|
+
}
|
|
19117
|
+
const stopped = await (this.browserAgent?.demoStop() ?? Promise.resolve({ ok: false, error: "runtime unavailable" }));
|
|
19118
|
+
return {
|
|
19119
|
+
ok: stopped.ok === true,
|
|
19120
|
+
...stopped.steps === void 0 ? {} : { steps: [...stopped.steps] },
|
|
19121
|
+
...stopped.error === void 0 ? {} : { error: stopped.error },
|
|
19122
|
+
snapshot: await this.browserSnapshotNow()
|
|
19123
|
+
};
|
|
19124
|
+
}
|
|
18263
19125
|
async browserAgentSetTabReadOnly(request) {
|
|
18264
19126
|
this.assertOwner();
|
|
18265
19127
|
const result = this.browserAgent?.setTabReadOnly({
|
|
@@ -18356,6 +19218,7 @@ function readSettings(config) {
|
|
|
18356
19218
|
browserAgentEnabled: config.browserAgentEnabled.get(),
|
|
18357
19219
|
browserAgentBrowser: hostBrowserPreference(config.browserAgentBrowser.get()),
|
|
18358
19220
|
browserAgentDebugTools: config.browserAgentDebugTools.get(),
|
|
19221
|
+
browserAgentDemonstrate: config.browserAgentDemonstrate.get(),
|
|
18359
19222
|
browserAgentIdleClose: resolveBrowserAgentIdleClose(config.browserAgentIdleClose.get()),
|
|
18360
19223
|
webChatBridgeEnabled: config.webChatBridgeEnabled.get(),
|
|
18361
19224
|
instructionsSkillsEnabled: config.instructionsSkillsEnabled.get(),
|
|
@@ -18438,12 +19301,14 @@ function apply(ctx, config) {
|
|
|
18438
19301
|
const browserAgentProfileDir = defaultBrowserAgentProfileDir(pluginDataPackageRoot);
|
|
18439
19302
|
const browserAgentLive = {
|
|
18440
19303
|
enabled: settings().browserAgentEnabled,
|
|
18441
|
-
browser: settings().browserAgentBrowser
|
|
19304
|
+
browser: settings().browserAgentBrowser,
|
|
19305
|
+
demonstrate: settings().browserAgentDemonstrate
|
|
18442
19306
|
};
|
|
18443
19307
|
const browserAgent = installBrowserAgent(ctx, {
|
|
18444
19308
|
enabled: () => browserAgentLive.enabled,
|
|
18445
19309
|
browserPreference: () => browserAgentLive.browser,
|
|
18446
19310
|
debugTools: () => settings().browserAgentDebugTools,
|
|
19311
|
+
demonstrate: () => settings().browserAgentDemonstrate,
|
|
18447
19312
|
idleClose: () => settings().browserAgentIdleClose,
|
|
18448
19313
|
profileRoot: pluginDataPackageRoot,
|
|
18449
19314
|
softPause: softPauseGate,
|
|
@@ -18491,7 +19356,8 @@ function apply(ctx, config) {
|
|
|
18491
19356
|
browserAgent,
|
|
18492
19357
|
() => ({
|
|
18493
19358
|
enabled: browserAgentLive.enabled,
|
|
18494
|
-
browser: browserAgentLive.browser
|
|
19359
|
+
browser: browserAgentLive.browser,
|
|
19360
|
+
demonstrate: browserAgentLive.demonstrate
|
|
18495
19361
|
}),
|
|
18496
19362
|
(browser) => {
|
|
18497
19363
|
browserAgentLive.browser = hostBrowserPreference(browser);
|
|
@@ -18510,6 +19376,7 @@ function apply(ctx, config) {
|
|
|
18510
19376
|
const prevBrowser = browserAgentLive.browser;
|
|
18511
19377
|
browserAgentLive.enabled = cfg.browserAgentEnabled.get();
|
|
18512
19378
|
browserAgentLive.browser = hostBrowserPreference(cfg.browserAgentBrowser.get());
|
|
19379
|
+
browserAgentLive.demonstrate = cfg.browserAgentDemonstrate.get();
|
|
18513
19380
|
browserAgent.refresh();
|
|
18514
19381
|
if (browserAgentLive.enabled && prevBrowser !== browserAgentLive.browser && browserAgent.driverStatus()?.ready === true) {
|
|
18515
19382
|
void browserAgent.alignToPreference().catch((error) => {
|