dsh-agent-enhancer 0.3.29 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +4 -4
- package/README.md +4 -4
- package/lib/client/browser-agent/tab.d.ts.map +1 -1
- package/lib/client/dsh/settings-features.d.ts +2 -1
- 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 +19 -11
- package/lib/client/locales.d.ts.map +1 -1
- package/lib/client.js +188 -39
- package/lib/client.js.map +1 -1
- package/lib/config.d.ts +23 -2
- package/lib/config.d.ts.map +1 -1
- package/lib/host/browser-agent/approval.d.ts +5 -0
- package/lib/host/browser-agent/approval.d.ts.map +1 -1
- package/lib/host/browser-agent/demo-heal.d.ts +2 -16
- package/lib/host/browser-agent/demo-heal.d.ts.map +1 -1
- package/lib/host/browser-agent/demo-recipes.d.ts +18 -8
- package/lib/host/browser-agent/demo-recipes.d.ts.map +1 -1
- package/lib/host/browser-agent/install.d.ts +5 -2
- package/lib/host/browser-agent/install.d.ts.map +1 -1
- package/lib/host/browser-agent/playwright-driver.d.ts +17 -0
- package/lib/host/browser-agent/playwright-driver.d.ts.map +1 -1
- package/lib/host/browser-agent/tools.d.ts +8 -0
- package/lib/host/browser-agent/tools.d.ts.map +1 -1
- package/lib/host/index.d.ts +8 -4
- package/lib/host/index.d.ts.map +1 -1
- package/lib/host/rpc.d.ts +44 -0
- package/lib/host/rpc.d.ts.map +1 -1
- package/lib/index.js +162 -77
- package/lib/index.js.map +2 -2
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -42,6 +42,24 @@ function browserAgentIdleCloseMs(value) {
|
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
|
+
var BROWSER_AGENT_UNATTENDED = {
|
|
46
|
+
minutes: { min: 5, max: 60, default: 20 },
|
|
47
|
+
actions: { min: 10, max: 200, default: 30 }
|
|
48
|
+
};
|
|
49
|
+
function clampUnattended(value, limits) {
|
|
50
|
+
if (value === void 0 || value === null) return limits.default;
|
|
51
|
+
const raw = typeof value === "string" ? value.trim() : value;
|
|
52
|
+
if (raw === "") return limits.default;
|
|
53
|
+
const number = typeof raw === "number" ? raw : Number(raw);
|
|
54
|
+
if (!Number.isFinite(number)) return limits.default;
|
|
55
|
+
return Math.min(limits.max, Math.max(limits.min, Math.round(number)));
|
|
56
|
+
}
|
|
57
|
+
function resolveBrowserAgentUnattendedMinutes(value) {
|
|
58
|
+
return clampUnattended(value, BROWSER_AGENT_UNATTENDED.minutes);
|
|
59
|
+
}
|
|
60
|
+
function resolveBrowserAgentUnattendedActions(value) {
|
|
61
|
+
return clampUnattended(value, BROWSER_AGENT_UNATTENDED.actions);
|
|
62
|
+
}
|
|
45
63
|
function resolveBrowserAgentBrowser(value) {
|
|
46
64
|
switch (value) {
|
|
47
65
|
case "auto":
|
|
@@ -92,8 +110,9 @@ var DEFAULT_SETTINGS = {
|
|
|
92
110
|
browserAgentBrowser: "auto",
|
|
93
111
|
browserAgentDebugTools: false,
|
|
94
112
|
browserAgentDemonstrate: false,
|
|
95
|
-
browserAgentAutoHeal: false,
|
|
96
113
|
browserAgentIdleClose: "10m",
|
|
114
|
+
browserAgentUnattendedMinutes: BROWSER_AGENT_UNATTENDED.minutes.default,
|
|
115
|
+
browserAgentUnattendedActions: BROWSER_AGENT_UNATTENDED.actions.default,
|
|
97
116
|
webChatBridgeEnabled: true,
|
|
98
117
|
instructionsSkillsEnabled: true,
|
|
99
118
|
mcpConnectorsEnabled: true,
|
|
@@ -141,8 +160,9 @@ function resolveSettings(value) {
|
|
|
141
160
|
browserAgentBrowser: resolveBrowserAgentBrowser(value?.browserAgentBrowser),
|
|
142
161
|
browserAgentDebugTools: value?.browserAgentDebugTools === true,
|
|
143
162
|
browserAgentDemonstrate: value?.browserAgentDemonstrate === true,
|
|
144
|
-
browserAgentAutoHeal: value?.browserAgentAutoHeal === true,
|
|
145
163
|
browserAgentIdleClose: resolveBrowserAgentIdleClose(value?.browserAgentIdleClose),
|
|
164
|
+
browserAgentUnattendedMinutes: resolveBrowserAgentUnattendedMinutes(value?.browserAgentUnattendedMinutes),
|
|
165
|
+
browserAgentUnattendedActions: resolveBrowserAgentUnattendedActions(value?.browserAgentUnattendedActions),
|
|
146
166
|
webChatBridgeEnabled: value?.webChatBridgeEnabled ?? true,
|
|
147
167
|
instructionsSkillsEnabled: value?.instructionsSkillsEnabled ?? true,
|
|
148
168
|
mcpConnectorsEnabled: value?.mcpConnectorsEnabled ?? true,
|
|
@@ -274,6 +294,12 @@ var BrowserApprovalGate = class {
|
|
|
274
294
|
});
|
|
275
295
|
return true;
|
|
276
296
|
}
|
|
297
|
+
/** Drop the grant for one origin, e.g. because its run was denied. */
|
|
298
|
+
revokeOrigin(input) {
|
|
299
|
+
const origin = originOfUrl(input.url);
|
|
300
|
+
if (origin === void 0) return false;
|
|
301
|
+
return this.grants.delete(this.grantKey(input.sessionId, origin));
|
|
302
|
+
}
|
|
277
303
|
/** Active grants, for the panel and for tests. */
|
|
278
304
|
activeGrants() {
|
|
279
305
|
this.pruneGrants();
|
|
@@ -1591,6 +1617,20 @@ async function loadPlaywright() {
|
|
|
1591
1617
|
playwrightModule ??= await import("playwright-core");
|
|
1592
1618
|
return playwrightModule;
|
|
1593
1619
|
}
|
|
1620
|
+
var AGENT_CHROMIUM_ARGS = [
|
|
1621
|
+
"--no-first-run",
|
|
1622
|
+
"--no-default-browser-check",
|
|
1623
|
+
"--disable-default-apps"
|
|
1624
|
+
];
|
|
1625
|
+
function hideWebdriver() {
|
|
1626
|
+
try {
|
|
1627
|
+
Object.defineProperty(Navigator.prototype, "webdriver", {
|
|
1628
|
+
configurable: true,
|
|
1629
|
+
get: () => false
|
|
1630
|
+
});
|
|
1631
|
+
} catch {
|
|
1632
|
+
}
|
|
1633
|
+
}
|
|
1594
1634
|
var PlaywrightDriver = class {
|
|
1595
1635
|
kind = "playwright";
|
|
1596
1636
|
profileDirOption;
|
|
@@ -1782,10 +1822,12 @@ var PlaywrightDriver = class {
|
|
|
1782
1822
|
this.lastError = "WEBKIT_MISSING: Playwright WebKit is not installed. Run: npx playwright install webkit";
|
|
1783
1823
|
return null;
|
|
1784
1824
|
}
|
|
1785
|
-
|
|
1825
|
+
const context = await webkit.launchPersistentContext(profileDir, {
|
|
1786
1826
|
headless: this.headless,
|
|
1787
1827
|
viewport: this.headless ? { width: 1280, height: 800 } : null
|
|
1788
1828
|
});
|
|
1829
|
+
await context.addInitScript(hideWebdriver);
|
|
1830
|
+
return context;
|
|
1789
1831
|
}
|
|
1790
1832
|
async launchChromium(profileDir, preference, channel) {
|
|
1791
1833
|
const kind = channel === "msedge" ? "edge" : "chrome";
|
|
@@ -1800,15 +1842,17 @@ var PlaywrightDriver = class {
|
|
|
1800
1842
|
return null;
|
|
1801
1843
|
}
|
|
1802
1844
|
const { chromium } = await loadPlaywright();
|
|
1803
|
-
|
|
1845
|
+
const context = await chromium.launchPersistentContext(profileDir, {
|
|
1804
1846
|
executablePath: resolved.executable,
|
|
1805
1847
|
headless: this.headless,
|
|
1806
1848
|
// Avoid Edge/Chrome infobar: "unsupported command-line flag: --no-sandbox".
|
|
1807
1849
|
chromiumSandbox: true,
|
|
1808
1850
|
ignoreDefaultArgs: ["--no-sandbox"],
|
|
1809
1851
|
viewport: this.headless ? { width: 1280, height: 800 } : null,
|
|
1810
|
-
args: [
|
|
1852
|
+
args: [...AGENT_CHROMIUM_ARGS]
|
|
1811
1853
|
});
|
|
1854
|
+
await context.addInitScript(hideWebdriver);
|
|
1855
|
+
return context;
|
|
1812
1856
|
}
|
|
1813
1857
|
stopPreferenceProfiles(activeProfileDir) {
|
|
1814
1858
|
stopAgentBrowserProcesses(activeProfileDir);
|
|
@@ -3367,16 +3411,6 @@ function describeHealProposal(proposal) {
|
|
|
3367
3411
|
}
|
|
3368
3412
|
return lines;
|
|
3369
3413
|
}
|
|
3370
|
-
var AUTO_HEAL_BUDGET = 3;
|
|
3371
|
-
var AUTO_HEAL_WINDOW_MS = 24 * 60 * 6e4;
|
|
3372
|
-
function sameOrigin(a, b) {
|
|
3373
|
-
if (a === void 0 || b === void 0) return false;
|
|
3374
|
-
try {
|
|
3375
|
-
return new URL(a).origin === new URL(b).origin;
|
|
3376
|
-
} catch {
|
|
3377
|
-
return false;
|
|
3378
|
-
}
|
|
3379
|
-
}
|
|
3380
3414
|
function createRepairHooks(input) {
|
|
3381
3415
|
const clock = input.now ?? Date.now;
|
|
3382
3416
|
return {
|
|
@@ -3404,20 +3438,11 @@ function createRepairHooks(input) {
|
|
|
3404
3438
|
});
|
|
3405
3439
|
if (proposal === null) return null;
|
|
3406
3440
|
if (!input.store.recordHeal({ id: recipe.id, proposal }).ok) return null;
|
|
3407
|
-
let autoApplied = false;
|
|
3408
|
-
if (input.autoApply?.() === true) {
|
|
3409
|
-
const recorded = recipe.steps.find((step) => step.tabUrl !== void 0)?.tabUrl;
|
|
3410
|
-
const recent = recipe.autoHeals.filter((at) => now - at < AUTO_HEAL_WINDOW_MS);
|
|
3411
|
-
if (sameOrigin(recorded, pending.target.tabUrl) && recent.length < AUTO_HEAL_BUDGET) {
|
|
3412
|
-
autoApplied = input.store.resolveHeal({ id: recipe.id, accept: true, auto: true, now }).ok;
|
|
3413
|
-
}
|
|
3414
|
-
}
|
|
3415
3441
|
return {
|
|
3416
3442
|
recipeId: recipe.id,
|
|
3417
3443
|
recipeName: recipe.name,
|
|
3418
3444
|
failedAt: proposal.failedAt,
|
|
3419
|
-
lines: describeHealProposal(proposal)
|
|
3420
|
-
autoApplied
|
|
3445
|
+
lines: describeHealProposal(proposal)
|
|
3421
3446
|
};
|
|
3422
3447
|
}
|
|
3423
3448
|
};
|
|
@@ -3455,7 +3480,6 @@ var MAX_RECIPE_NAME = 60;
|
|
|
3455
3480
|
var MAX_RECIPE_STEPS = 200;
|
|
3456
3481
|
var MAX_HISTORY = 5;
|
|
3457
3482
|
var MAX_VARIABLE_LABEL = 60;
|
|
3458
|
-
var MAX_AUTO_HEALS = 3;
|
|
3459
3483
|
var FILE_VERSION = 2;
|
|
3460
3484
|
function metaOf(recipe) {
|
|
3461
3485
|
const site = siteOf(recipe.steps);
|
|
@@ -3468,8 +3492,8 @@ function metaOf(recipe) {
|
|
|
3468
3492
|
variables: recipe.variables,
|
|
3469
3493
|
rev: recipe.rev,
|
|
3470
3494
|
history: recipe.history.length,
|
|
3471
|
-
autoHeals: recipe.autoHeals.length,
|
|
3472
3495
|
unattended: recipe.unattended,
|
|
3496
|
+
...recipe.lastRun === void 0 ? {} : { lastRun: recipe.lastRun },
|
|
3473
3497
|
...site === void 0 ? {} : { site },
|
|
3474
3498
|
...recipe.pendingHeal === void 0 ? {} : { pendingHeal: recipe.pendingHeal }
|
|
3475
3499
|
};
|
|
@@ -3541,6 +3565,22 @@ function prepareRecipeValues(recipe, provided, now = /* @__PURE__ */ new Date())
|
|
|
3541
3565
|
const missing = recipe.variables.filter((variable) => (values[variable.name] ?? "").trim() === "");
|
|
3542
3566
|
return { values, missing, resolved, unknown: matched.unknown };
|
|
3543
3567
|
}
|
|
3568
|
+
function sanitizeRunResult(raw) {
|
|
3569
|
+
if (raw === null || typeof raw !== "object") return void 0;
|
|
3570
|
+
const entry = raw;
|
|
3571
|
+
if (entry.status !== "ok" && entry.status !== "stopped" && entry.status !== "failed") return void 0;
|
|
3572
|
+
const at = Number(entry.at);
|
|
3573
|
+
const performed = Number(entry.performed);
|
|
3574
|
+
const total = Number(entry.total);
|
|
3575
|
+
if (!Number.isFinite(at) || !Number.isFinite(performed) || !Number.isFinite(total)) return void 0;
|
|
3576
|
+
return {
|
|
3577
|
+
at,
|
|
3578
|
+
status: entry.status,
|
|
3579
|
+
performed: Math.max(0, Math.floor(performed)),
|
|
3580
|
+
total: Math.max(0, Math.floor(total)),
|
|
3581
|
+
...typeof entry.reason === "string" && entry.reason !== "" ? { reason: entry.reason.slice(0, 200) } : {}
|
|
3582
|
+
};
|
|
3583
|
+
}
|
|
3544
3584
|
function sanitizeVariables(raw) {
|
|
3545
3585
|
if (!Array.isArray(raw)) return [];
|
|
3546
3586
|
return raw.filter((value) => {
|
|
@@ -3573,10 +3613,6 @@ function sanitizeHistory(raw) {
|
|
|
3573
3613
|
}
|
|
3574
3614
|
return versions.slice(-MAX_HISTORY);
|
|
3575
3615
|
}
|
|
3576
|
-
function sanitizeTimestamps(raw) {
|
|
3577
|
-
if (!Array.isArray(raw)) return [];
|
|
3578
|
-
return raw.filter((value) => typeof value === "number" && Number.isFinite(value) && value > 0).slice(-MAX_AUTO_HEALS * 4);
|
|
3579
|
-
}
|
|
3580
3616
|
function sanitizeProposal(raw) {
|
|
3581
3617
|
if (raw === null || typeof raw !== "object") return void 0;
|
|
3582
3618
|
const entry = raw;
|
|
@@ -3660,7 +3696,6 @@ var DemoRecipeStore = class {
|
|
|
3660
3696
|
variables: [],
|
|
3661
3697
|
rev: 1,
|
|
3662
3698
|
history: [],
|
|
3663
|
-
autoHeals: [],
|
|
3664
3699
|
unattended: false
|
|
3665
3700
|
};
|
|
3666
3701
|
}
|
|
@@ -3762,8 +3797,7 @@ var DemoRecipeStore = class {
|
|
|
3762
3797
|
steps,
|
|
3763
3798
|
updatedAt: now,
|
|
3764
3799
|
rev: current.rev + 1,
|
|
3765
|
-
history: nextVersion(current, "heal", now)
|
|
3766
|
-
autoHeals: input.auto === true ? [...current.autoHeals, now].slice(-MAX_AUTO_HEALS) : current.autoHeals
|
|
3800
|
+
history: nextVersion(current, "heal", now)
|
|
3767
3801
|
};
|
|
3768
3802
|
this.write(recipes.map((recipe) => recipe.id === current.id ? next : recipe));
|
|
3769
3803
|
return { ok: true, recipe: metaOf(next) };
|
|
@@ -3822,6 +3856,15 @@ var DemoRecipeStore = class {
|
|
|
3822
3856
|
this.write(recipes.map((recipe) => recipe.id === current.id ? next : recipe));
|
|
3823
3857
|
return { ok: true, recipe: metaOf(next) };
|
|
3824
3858
|
}
|
|
3859
|
+
/** Record how the last run ended. Not flow content: `rev` does not move. */
|
|
3860
|
+
recordRun(input) {
|
|
3861
|
+
const recipes = this.read();
|
|
3862
|
+
const current = recipes.find((recipe) => recipe.id === input.id);
|
|
3863
|
+
if (current === void 0) return false;
|
|
3864
|
+
const next = { ...current, lastRun: input.result };
|
|
3865
|
+
this.write(recipes.map((recipe) => recipe.id === current.id ? next : recipe));
|
|
3866
|
+
return true;
|
|
3867
|
+
}
|
|
3825
3868
|
/**
|
|
3826
3869
|
* Allow (or stop allowing) this flow to run without per-action cards. Kept
|
|
3827
3870
|
* out of `rev`: it is a policy flag, not flow content.
|
|
@@ -3870,16 +3913,17 @@ var DemoRecipeStore = class {
|
|
|
3870
3913
|
if (typeof recipe.id !== "string" || typeof recipe.name !== "string") return false;
|
|
3871
3914
|
return typeof recipe.createdAt === "number" && typeof recipe.updatedAt === "number";
|
|
3872
3915
|
}).map((recipe) => {
|
|
3873
|
-
const { pendingHeal: rawProposal, ...rest } = recipe;
|
|
3916
|
+
const { pendingHeal: rawProposal, lastRun: rawLastRun, ...rest } = recipe;
|
|
3874
3917
|
const proposal = sanitizeProposal(rawProposal);
|
|
3918
|
+
const lastRun = sanitizeRunResult(rawLastRun);
|
|
3875
3919
|
return {
|
|
3876
3920
|
...rest,
|
|
3877
3921
|
steps: sanitizeRecipeSteps(recipe.steps),
|
|
3878
3922
|
variables: sanitizeVariables(recipe.variables),
|
|
3879
3923
|
rev: Number.isFinite(recipe.rev) && recipe.rev > 0 ? recipe.rev : 1,
|
|
3880
3924
|
history: sanitizeHistory(recipe.history),
|
|
3881
|
-
autoHeals: sanitizeTimestamps(recipe.autoHeals),
|
|
3882
3925
|
unattended: recipe.unattended === true,
|
|
3926
|
+
...lastRun === void 0 ? {} : { lastRun },
|
|
3883
3927
|
...proposal === void 0 ? {} : { pendingHeal: proposal }
|
|
3884
3928
|
};
|
|
3885
3929
|
}).filter((recipe) => recipe.steps.length > 0).slice(0, MAX_RECIPES);
|
|
@@ -5117,6 +5161,7 @@ Action: browser_extract or browser_snapshot next. Do not navigate away unless th
|
|
|
5117
5161
|
guardEnabled();
|
|
5118
5162
|
requireDemonstrate();
|
|
5119
5163
|
const sessionId = sessionIdOf(exec);
|
|
5164
|
+
if (args.replay === true) requireWritableTab(sessionId, "browser_demonstrate");
|
|
5120
5165
|
const message = String(args.message ?? "").trim();
|
|
5121
5166
|
if (message === "") throw new Error("message is required");
|
|
5122
5167
|
const timeoutRaw = Number(args.timeoutMs);
|
|
@@ -5260,10 +5305,9 @@ Action: browser_extract or browser_snapshot next. Do not navigate away unless th
|
|
|
5260
5305
|
...afterCommit.map((row) => {
|
|
5261
5306
|
const vars = row.variables.length === 0 ? "" : `; vars: ${row.variables.map((variable) => variable.name).join(", ")}`;
|
|
5262
5307
|
const heal = row.pendingHeal === void 0 ? "" : `; repair waiting: step ${row.pendingHeal.failedAt}`;
|
|
5263
|
-
const auto = row.autoHeals === 0 ? "" : `; auto-adapted ${row.autoHeals}x`;
|
|
5264
5308
|
const site = row.site === void 0 ? "" : `; site: ${row.site}`;
|
|
5265
5309
|
const unattended2 = row.unattended ? "; unattended: yes" : "";
|
|
5266
|
-
return `- ${row.name} (${row.steps} step(s)${vars}${heal}${
|
|
5310
|
+
return `- ${row.name} (${row.steps} step(s)${vars}${heal}${site}${unattended2})`;
|
|
5267
5311
|
}),
|
|
5268
5312
|
'Action: run one with browser_demo_recipes { action: "run", name: "<name>" }.'
|
|
5269
5313
|
].join("\n");
|
|
@@ -5274,19 +5318,6 @@ Action: browser_extract or browser_snapshot next. Do not navigate away unless th
|
|
|
5274
5318
|
if (id === "") {
|
|
5275
5319
|
return "nothing to remember: no saved flow stopped recently, so there is no repair to store.";
|
|
5276
5320
|
}
|
|
5277
|
-
if (committed?.autoApplied === true) {
|
|
5278
|
-
options.sessions.record({
|
|
5279
|
-
sessionId: sessionIdOf(exec),
|
|
5280
|
-
tool: "browser_demo_recipe",
|
|
5281
|
-
summary: `Auto-adapted saved flow "${committed.recipeName}"`,
|
|
5282
|
-
outcome: "ok"
|
|
5283
|
-
});
|
|
5284
|
-
return [
|
|
5285
|
-
`saved flow: ${committed.recipeName} \u2014 repair applied automatically (\u81EA\u52A8\u9002\u5E94 is on)`,
|
|
5286
|
-
...committed.lines.map((line) => `- ${line}`),
|
|
5287
|
-
"Action: tell the user the flow was updated without asking, and that \u64A4\u9500\u4E0A\u6B21\u4FEE\u6539 in the sidebar restores the previous version."
|
|
5288
|
-
].join("\n");
|
|
5289
|
-
}
|
|
5290
5321
|
if (args.accept !== true) {
|
|
5291
5322
|
const row = store.list().find((candidate) => candidate.id === id);
|
|
5292
5323
|
const proposal = row?.pendingHeal;
|
|
@@ -5337,15 +5368,8 @@ Action: browser_extract or browser_snapshot next. Do not navigate away unless th
|
|
|
5337
5368
|
throw new Error(`site ${JSON.stringify(wantedSite)} does not match flow "${meta.name}" (${meta.site}). Pass the site exactly as action=list shows it.`);
|
|
5338
5369
|
}
|
|
5339
5370
|
const sessionId = sessionIdOf(exec);
|
|
5371
|
+
requireWritableTab(sessionId, "browser_demo_recipes");
|
|
5340
5372
|
const unattended = recipe.unattended && meta.site !== void 0;
|
|
5341
|
-
if (unattended) {
|
|
5342
|
-
options.approval.grantOrigin({
|
|
5343
|
-
sessionId,
|
|
5344
|
-
url: meta.site,
|
|
5345
|
-
ttlMs: 20 * 6e4,
|
|
5346
|
-
actions: 30
|
|
5347
|
-
});
|
|
5348
|
-
}
|
|
5349
5373
|
options.repair?.commit();
|
|
5350
5374
|
const provided = args.vars !== null && typeof args.vars === "object" ? Object.fromEntries(Object.entries(args.vars).filter(([, value]) => typeof value === "string").map(([key, value]) => [key, String(value)])) : {};
|
|
5351
5375
|
const prepared = prepareRecipeValues(recipe, provided);
|
|
@@ -5361,14 +5385,51 @@ Action: browser_extract or browser_snapshot next. Do not navigate away unless th
|
|
|
5361
5385
|
await ensureConnected();
|
|
5362
5386
|
await ensureSessionTab(sessionId);
|
|
5363
5387
|
const firstUrl = recipe.steps.find((step) => step.tabUrl !== void 0)?.tabUrl;
|
|
5364
|
-
|
|
5365
|
-
|
|
5366
|
-
|
|
5367
|
-
|
|
5368
|
-
|
|
5369
|
-
|
|
5370
|
-
|
|
5388
|
+
const budget = options.unattended?.() ?? {
|
|
5389
|
+
minutes: BROWSER_AGENT_UNATTENDED.minutes.default,
|
|
5390
|
+
actions: BROWSER_AGENT_UNATTENDED.actions.default
|
|
5391
|
+
};
|
|
5392
|
+
const grantedSite = unattended && meta.site !== void 0 ? options.approval.grantOrigin({
|
|
5393
|
+
sessionId,
|
|
5394
|
+
url: meta.site,
|
|
5395
|
+
ttlMs: budget.minutes * 6e4,
|
|
5396
|
+
actions: budget.actions
|
|
5397
|
+
}) ? meta.site : void 0 : void 0;
|
|
5398
|
+
try {
|
|
5399
|
+
await requireMutation(
|
|
5400
|
+
exec,
|
|
5401
|
+
"browser_demo_recipes",
|
|
5402
|
+
`\u8FD0\u884C\u5DF2\u4FDD\u5B58\u6D41\u7A0B\u300C${recipe.name}\u300D\uFF08${recipe.steps.length} \u6B65\uFF09`,
|
|
5403
|
+
firstUrl
|
|
5404
|
+
);
|
|
5405
|
+
} catch (error) {
|
|
5406
|
+
if (grantedSite !== void 0) options.approval.revokeOrigin({ sessionId, url: grantedSite });
|
|
5407
|
+
throw error;
|
|
5408
|
+
}
|
|
5409
|
+
const outcome = await replayDemoSteps(driverOf(options), replaySteps).catch((error) => {
|
|
5410
|
+
store.recordRun({
|
|
5411
|
+
id: recipe.id,
|
|
5412
|
+
result: {
|
|
5413
|
+
at: Date.now(),
|
|
5414
|
+
status: "failed",
|
|
5415
|
+
performed: 0,
|
|
5416
|
+
total: replaySteps.length,
|
|
5417
|
+
reason: error instanceof Error ? error.message.slice(0, 200) : String(error).slice(0, 200)
|
|
5418
|
+
}
|
|
5419
|
+
});
|
|
5420
|
+
throw error;
|
|
5421
|
+
});
|
|
5371
5422
|
const ranAll = outcome.status === "done";
|
|
5423
|
+
store.recordRun({
|
|
5424
|
+
id: recipe.id,
|
|
5425
|
+
result: {
|
|
5426
|
+
at: Date.now(),
|
|
5427
|
+
status: ranAll ? "ok" : "stopped",
|
|
5428
|
+
performed: outcome.performed,
|
|
5429
|
+
total: outcome.total,
|
|
5430
|
+
...ranAll ? {} : { reason: outcome.reason.slice(0, 200) }
|
|
5431
|
+
}
|
|
5432
|
+
});
|
|
5372
5433
|
if (!ranAll) {
|
|
5373
5434
|
const failedStep = recipe.steps[outcome.performed];
|
|
5374
5435
|
const isSecret = /masked|secret field/i.test(outcome.reason) || failedStep !== void 0 && failedStep.kind === "fill" && failedStep.masked;
|
|
@@ -5394,7 +5455,7 @@ Action: browser_extract or browser_snapshot next. Do not navigate away unless th
|
|
|
5394
5455
|
if (ranAll) {
|
|
5395
5456
|
return [
|
|
5396
5457
|
`saved flow: ${recipe.name} \u2014 replayed ${outcome.performed}/${outcome.total}`,
|
|
5397
|
-
...unattended ? [`unattended: ${meta.site} is authorized for
|
|
5458
|
+
...unattended ? [`unattended: ${meta.site} is authorized for ${budget.minutes} min / ${budget.actions} actions in this session`] : [],
|
|
5398
5459
|
...resolvedNote,
|
|
5399
5460
|
...outcome.lines,
|
|
5400
5461
|
`url: ${outcome.url}`,
|
|
@@ -5407,7 +5468,7 @@ Action: browser_extract or browser_snapshot next. Do not navigate away unless th
|
|
|
5407
5468
|
});
|
|
5408
5469
|
return [
|
|
5409
5470
|
`saved flow: ${recipe.name} \u2014 replayed ${outcome.performed}/${outcome.total}`,
|
|
5410
|
-
...unattended ? [`unattended: ${meta.site} is authorized for
|
|
5471
|
+
...unattended ? [`unattended: ${meta.site} is authorized for ${budget.minutes} min / ${budget.actions} actions in this session`] : [],
|
|
5411
5472
|
...resolvedNote,
|
|
5412
5473
|
...outcome.lines,
|
|
5413
5474
|
`stopped at step ${outcome.performed + 1}: ${outcome.reason}`,
|
|
@@ -5531,8 +5592,7 @@ function installBrowserAgent(ctx, options) {
|
|
|
5531
5592
|
const repairTracker = new DemoRepairTracker();
|
|
5532
5593
|
const repairHooks = createRepairHooks({
|
|
5533
5594
|
tracker: repairTracker,
|
|
5534
|
-
...recipes === void 0 ? {} : { store: recipes }
|
|
5535
|
-
...options.autoHeal === void 0 ? {} : { autoApply: options.autoHeal }
|
|
5595
|
+
...recipes === void 0 ? {} : { store: recipes }
|
|
5536
5596
|
});
|
|
5537
5597
|
let availabilityCache = null;
|
|
5538
5598
|
const browserAvailability = () => {
|
|
@@ -5653,6 +5713,7 @@ function installBrowserAgent(ctx, options) {
|
|
|
5653
5713
|
tabScope,
|
|
5654
5714
|
debugTools: () => options.debugTools?.() === true,
|
|
5655
5715
|
demonstrate: () => options.demonstrate?.() === true,
|
|
5716
|
+
...options.unattended === void 0 ? {} : { unattended: options.unattended },
|
|
5656
5717
|
onDemonstration: (steps) => {
|
|
5657
5718
|
lastDemoSteps = steps;
|
|
5658
5719
|
},
|
|
@@ -6054,6 +6115,16 @@ function installBrowserAgent(ctx, options) {
|
|
|
6054
6115
|
pending: [...steps]
|
|
6055
6116
|
}));
|
|
6056
6117
|
const ranAll = outcome.status === "done";
|
|
6118
|
+
recipes.recordRun({
|
|
6119
|
+
id: recipe.id,
|
|
6120
|
+
result: {
|
|
6121
|
+
at: Date.now(),
|
|
6122
|
+
status: ranAll ? "ok" : "stopped",
|
|
6123
|
+
performed: outcome.performed,
|
|
6124
|
+
total: outcome.total,
|
|
6125
|
+
...ranAll ? {} : { reason: outcome.reason.slice(0, 200) }
|
|
6126
|
+
}
|
|
6127
|
+
});
|
|
6057
6128
|
if (!ranAll) {
|
|
6058
6129
|
const failedStep = recipe.steps[outcome.performed];
|
|
6059
6130
|
const isSecret = /masked|secret field/i.test(outcome.reason) || failedStep !== void 0 && failedStep.kind === "fill" && failedStep.masked;
|
|
@@ -18333,6 +18404,13 @@ var demoRecipeHealSchema = z4.strictObject({
|
|
|
18333
18404
|
inserted: z4.number().int().min(0),
|
|
18334
18405
|
reason: z4.string()
|
|
18335
18406
|
});
|
|
18407
|
+
var demoRunResultSchema = z4.strictObject({
|
|
18408
|
+
at: z4.number(),
|
|
18409
|
+
status: z4.enum(["ok", "stopped", "failed"]),
|
|
18410
|
+
performed: z4.number().int(),
|
|
18411
|
+
total: z4.number().int(),
|
|
18412
|
+
reason: z4.string().optional()
|
|
18413
|
+
});
|
|
18336
18414
|
var demoRecipeMetaSchema = z4.strictObject({
|
|
18337
18415
|
id: z4.string().min(1),
|
|
18338
18416
|
name: z4.string().min(1),
|
|
@@ -18348,6 +18426,8 @@ var demoRecipeMetaSchema = z4.strictObject({
|
|
|
18348
18426
|
unattended: z4.boolean(),
|
|
18349
18427
|
/** Origin the flow was recorded on. */
|
|
18350
18428
|
site: z4.string().optional(),
|
|
18429
|
+
/** Last run outcome. */
|
|
18430
|
+
lastRun: demoRunResultSchema.optional(),
|
|
18351
18431
|
/** A repair worked out by the agent, waiting for the user. */
|
|
18352
18432
|
pendingHeal: demoRecipeHealSchema.optional()
|
|
18353
18433
|
});
|
|
@@ -20036,10 +20116,12 @@ var Config = z5.object({
|
|
|
20036
20116
|
browserAgentDebugTools: z5.boolean().default(false).volatile(),
|
|
20037
20117
|
/** "Show me" recorder; observes user actions in the bound tab, default off. */
|
|
20038
20118
|
browserAgentDemonstrate: z5.boolean().default(false).volatile(),
|
|
20039
|
-
/** Keep a repair automatically when the site changed (locator only). Default off. */
|
|
20040
|
-
browserAgentAutoHeal: z5.boolean().default(false).volatile(),
|
|
20041
20119
|
/** Close idle agent tabs after ~10 min; coerced via resolveBrowserAgentIdleClose. */
|
|
20042
20120
|
browserAgentIdleClose: z5.union([z5.boolean(), z5.string()]).default("10m").volatile(),
|
|
20121
|
+
/** Unattended-run grant: bounded minutes (default 20). */
|
|
20122
|
+
browserAgentUnattendedMinutes: z5.number().default(BROWSER_AGENT_UNATTENDED.minutes.default).volatile(),
|
|
20123
|
+
/** Unattended-run grant: bounded action budget (default 30). */
|
|
20124
|
+
browserAgentUnattendedActions: z5.number().default(BROWSER_AGENT_UNATTENDED.actions.default).volatile(),
|
|
20043
20125
|
/** Default off; embeds official web chat + import to work. */
|
|
20044
20126
|
webChatBridgeEnabled: z5.boolean().default(true).volatile(),
|
|
20045
20127
|
instructionsSkillsEnabled: z5.boolean().default(true).volatile(),
|
|
@@ -20917,6 +20999,7 @@ var AgentEnhancerService = class extends TypertRemoteService {
|
|
|
20917
20999
|
history: recipe.history,
|
|
20918
21000
|
unattended: recipe.unattended,
|
|
20919
21001
|
...recipe.site === void 0 ? {} : { site: recipe.site },
|
|
21002
|
+
...recipe.lastRun === void 0 ? {} : { lastRun: { ...recipe.lastRun } },
|
|
20920
21003
|
...recipe.pendingHeal === void 0 ? {} : {
|
|
20921
21004
|
pendingHeal: {
|
|
20922
21005
|
id: recipe.pendingHeal.id,
|
|
@@ -21056,8 +21139,9 @@ function readSettings(config) {
|
|
|
21056
21139
|
browserAgentBrowser: hostBrowserPreference(config.browserAgentBrowser.get()),
|
|
21057
21140
|
browserAgentDebugTools: config.browserAgentDebugTools.get(),
|
|
21058
21141
|
browserAgentDemonstrate: config.browserAgentDemonstrate.get(),
|
|
21059
|
-
browserAgentAutoHeal: config.browserAgentAutoHeal.get(),
|
|
21060
21142
|
browserAgentIdleClose: resolveBrowserAgentIdleClose(config.browserAgentIdleClose.get()),
|
|
21143
|
+
browserAgentUnattendedMinutes: config.browserAgentUnattendedMinutes.get(),
|
|
21144
|
+
browserAgentUnattendedActions: config.browserAgentUnattendedActions.get(),
|
|
21061
21145
|
webChatBridgeEnabled: config.webChatBridgeEnabled.get(),
|
|
21062
21146
|
instructionsSkillsEnabled: config.instructionsSkillsEnabled.get(),
|
|
21063
21147
|
mcpConnectorsEnabled: config.mcpConnectorsEnabled.get(),
|
|
@@ -21140,16 +21224,18 @@ function apply(ctx, config) {
|
|
|
21140
21224
|
const browserAgentLive = {
|
|
21141
21225
|
enabled: settings().browserAgentEnabled,
|
|
21142
21226
|
browser: settings().browserAgentBrowser,
|
|
21143
|
-
demonstrate: settings().browserAgentDemonstrate
|
|
21144
|
-
autoHeal: settings().browserAgentAutoHeal
|
|
21227
|
+
demonstrate: settings().browserAgentDemonstrate
|
|
21145
21228
|
};
|
|
21146
21229
|
const browserAgent = installBrowserAgent(ctx, {
|
|
21147
21230
|
enabled: () => browserAgentLive.enabled,
|
|
21148
21231
|
browserPreference: () => browserAgentLive.browser,
|
|
21149
21232
|
debugTools: () => settings().browserAgentDebugTools,
|
|
21150
21233
|
demonstrate: () => settings().browserAgentDemonstrate,
|
|
21151
|
-
autoHeal: () => settings().browserAgentAutoHeal,
|
|
21152
21234
|
idleClose: () => settings().browserAgentIdleClose,
|
|
21235
|
+
unattended: () => ({
|
|
21236
|
+
minutes: settings().browserAgentUnattendedMinutes,
|
|
21237
|
+
actions: settings().browserAgentUnattendedActions
|
|
21238
|
+
}),
|
|
21153
21239
|
recipes: new DemoRecipeStore(join30(pluginDataPackageRoot, "demo-recipes.json")),
|
|
21154
21240
|
profileRoot: pluginDataPackageRoot,
|
|
21155
21241
|
softPause: softPauseGate,
|
|
@@ -21218,7 +21304,6 @@ function apply(ctx, config) {
|
|
|
21218
21304
|
browserAgentLive.enabled = cfg.browserAgentEnabled.get();
|
|
21219
21305
|
browserAgentLive.browser = hostBrowserPreference(cfg.browserAgentBrowser.get());
|
|
21220
21306
|
browserAgentLive.demonstrate = cfg.browserAgentDemonstrate.get();
|
|
21221
|
-
browserAgentLive.autoHeal = cfg.browserAgentAutoHeal.get();
|
|
21222
21307
|
browserAgent.refresh();
|
|
21223
21308
|
if (browserAgentLive.enabled && prevBrowser !== browserAgentLive.browser && browserAgent.driverStatus()?.ready === true) {
|
|
21224
21309
|
void browserAgent.alignToPreference().catch((error) => {
|