@wenathlan/extension 1.1.32 → 1.1.33
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.md +5 -4
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +221 -12
- package/dist/index.js.map +2 -2
- package/dist/memory.d.ts +33 -1
- package/dist/memory.d.ts.map +1 -1
- package/dist/policy.d.ts +8 -0
- package/dist/policy.d.ts.map +1 -1
- package/dist/protocol.d.ts +33 -2
- package/dist/protocol.d.ts.map +1 -1
- package/dist/types.d.ts +114 -3
- package/dist/types.d.ts.map +1 -1
- package/dist/version.d.ts +1 -1
- package/extension/dist/background.js +565 -23
- package/extension/dist/background.js.map +4 -4
- package/extension/dist/manifest.json +1 -1
- package/extension/dist/pagebridge.js +894 -86
- package/extension/dist/pagebridge.js.map +4 -4
- package/extension/dist/popup.html +1 -1
- package/extension/dist/popup.js +12 -3
- package/extension/dist/popup.js.map +2 -2
- package/extension/dist/sidepanel.html +1 -1
- package/extension/dist/sidepanel.js +134 -25
- package/extension/dist/sidepanel.js.map +2 -2
- package/extension/dist/style.css +1 -1
- package/extension/manifest.json +1 -1
- package/package.json +1 -1
|
@@ -66,18 +66,80 @@ var sessionmemory = class {
|
|
|
66
66
|
const retention = (await this.getsettings())?.outcomeretention;
|
|
67
67
|
await this.adapter.set("outcomes", retention === void 0 ? combined : combined.slice(0, retention));
|
|
68
68
|
}
|
|
69
|
+
/** Stores one clickable map under its observation version so every captured map stays available. */
|
|
70
|
+
async setmap(map) {
|
|
71
|
+
return this.adapter.set(`map${map.version}`, map);
|
|
72
|
+
}
|
|
73
|
+
/** Returns one stored clickable map by its observation version. */
|
|
74
|
+
async getmap(version) {
|
|
75
|
+
return this.adapter.get(`map${version}`);
|
|
76
|
+
}
|
|
77
|
+
/** Advances and persists the observation version counter used to stamp clickable maps. */
|
|
78
|
+
async nextobservationversion() {
|
|
79
|
+
const current = await this.adapter.get("observationversion") ?? 0;
|
|
80
|
+
const next = current + 1;
|
|
81
|
+
await this.adapter.set("observationversion", next);
|
|
82
|
+
return next;
|
|
83
|
+
}
|
|
84
|
+
/** Returns the latest observation version used to stamp a clickable map. */
|
|
85
|
+
async getobservationversion() {
|
|
86
|
+
return this.adapter.get("observationversion");
|
|
87
|
+
}
|
|
88
|
+
/** Returns the key hold registry, persisted so holds survive service worker restarts. */
|
|
89
|
+
async getholds() {
|
|
90
|
+
return await this.adapter.get("holds") ?? [];
|
|
91
|
+
}
|
|
92
|
+
/** Replaces the key hold registry after one press or release transition. */
|
|
93
|
+
async setholds(holds) {
|
|
94
|
+
return this.adapter.set("holds", holds);
|
|
95
|
+
}
|
|
96
|
+
/** Returns every dialog decision recorded for the audit trail. */
|
|
97
|
+
async getdialogs() {
|
|
98
|
+
return await this.adapter.get("dialogs") ?? [];
|
|
99
|
+
}
|
|
100
|
+
/** Records one dialog decision with the reviewed answer and the observed dialog text. */
|
|
101
|
+
async adddialog(decision) {
|
|
102
|
+
const records = await this.getdialogs();
|
|
103
|
+
await this.adapter.set("dialogs", [decision, ...records]);
|
|
104
|
+
}
|
|
105
|
+
/** Returns every retry outcome recorded with attempts and movement deltas. */
|
|
106
|
+
async getretries() {
|
|
107
|
+
return await this.adapter.get("retries") ?? [];
|
|
108
|
+
}
|
|
109
|
+
/** Records one retry outcome with the attempts made and the movement delta observed. */
|
|
110
|
+
async addretry(outcome) {
|
|
111
|
+
const records = await this.getretries();
|
|
112
|
+
await this.adapter.set("retries", [outcome, ...records]);
|
|
113
|
+
}
|
|
114
|
+
/** Returns every resolution summary stored per target mode. */
|
|
115
|
+
async getresolutions() {
|
|
116
|
+
return await this.adapter.get("resolutions") ?? [];
|
|
117
|
+
}
|
|
118
|
+
/** Records one resolution summary for later selector derivation. */
|
|
119
|
+
async addresolution(summary) {
|
|
120
|
+
const records = await this.getresolutions();
|
|
121
|
+
await this.adapter.set("resolutions", [summary, ...records]);
|
|
122
|
+
}
|
|
123
|
+
/** Returns the reviewed default dialog policy kept for the session auto handler. */
|
|
124
|
+
async getdialogpolicy() {
|
|
125
|
+
return this.adapter.get("dialogpolicy");
|
|
126
|
+
}
|
|
127
|
+
/** Stores the reviewed default dialog policy of the latest approved plan. */
|
|
128
|
+
async setdialogpolicy(policy) {
|
|
129
|
+
return this.adapter.set("dialogpolicy", policy);
|
|
130
|
+
}
|
|
69
131
|
};
|
|
70
132
|
function randomid() {
|
|
71
133
|
return crypto.randomUUID();
|
|
72
134
|
}
|
|
73
135
|
|
|
74
136
|
// policy.ts
|
|
75
|
-
var sensitiveactions = /* @__PURE__ */ new Set(["click", "type", "navigate", "select", "presskey", "drag", "drop", "upload", "clear", "check", "uncheck", "toggle", "submit", "reload", "back", "forward", "writestorage", "setattribute", "removeattribute", "evaluate", "tabcreate", "tabactivate", "tabclose", "tabreload", "windowcreate", "windowclose", "windowresize", "downloadfile"]);
|
|
76
|
-
var interactionactions = /* @__PURE__ */ new Set(["focus", "scroll", "hover", "clickdeep", "rightclick", "doubleclick", "scrollpage", "scrollby", "scrollend", "scrolltop", "fullscreen", "zoomset"]);
|
|
77
|
-
var readactions = /* @__PURE__ */ new Set(["observe", "inspect", "extract", "wait", "waitfor", "waittext", "readattribute", "readstyle", "readgeometry", "readvalue", "readtext", "readhtml", "countelements", "readtable", "readlinks", "readimages", "readmeta", "readforms", "readstorage", "highlight", "tablist", "windowlist", "tabsnapshot"]);
|
|
137
|
+
var sensitiveactions = /* @__PURE__ */ new Set(["click", "type", "navigate", "select", "presskey", "drag", "drop", "upload", "clear", "check", "uncheck", "toggle", "submit", "reload", "back", "forward", "writestorage", "setattribute", "removeattribute", "evaluate", "tabcreate", "tabactivate", "tabclose", "tabreload", "windowcreate", "windowclose", "windowresize", "downloadfile", "clickpoint", "shiftclick", "dismissdialog", "enterframe", "typetime", "appendtext", "setvalue", "typeedit", "keyhold", "keyrelease", "submitsearch", "selectmulti", "chooseradio", "setslider", "setdate", "setcolor"]);
|
|
138
|
+
var interactionactions = /* @__PURE__ */ new Set(["focus", "scroll", "hover", "clickdeep", "rightclick", "doubleclick", "scrollpage", "scrollby", "scrollend", "scrolltop", "fullscreen", "zoomset", "movepointer", "clicktext", "clickaria", "clickname", "expanddetails", "pierceshadow", "retryaction"]);
|
|
139
|
+
var readactions = /* @__PURE__ */ new Set(["observe", "inspect", "extract", "wait", "waitfor", "waittext", "readattribute", "readstyle", "readgeometry", "readvalue", "readtext", "readhtml", "countelements", "readtable", "readlinks", "readimages", "readmeta", "readforms", "readstorage", "highlight", "tablist", "windowlist", "tabsnapshot", "mapclicks", "verifyvisible", "verifyenabled", "resolvexpath"]);
|
|
78
140
|
var allowedactions = /* @__PURE__ */ new Set([...sensitiveactions, ...interactionactions, ...readactions]);
|
|
79
|
-
var targetactions = /* @__PURE__ */ new Set(["inspect", "focus", "click", "type", "scroll", "select", "hover", "clickdeep", "rightclick", "doubleclick", "drag", "drop", "upload", "clear", "check", "uncheck", "toggle", "submit", "readattribute", "readstyle", "readgeometry", "readvalue", "readtext", "readhtml", "countelements", "readtable", "highlight", "setattribute", "removeattribute", "waitfor"]);
|
|
80
|
-
var valueactions = /* @__PURE__ */ new Set(["presskey", "drag", "drop", "upload", "readattribute", "removeattribute", "waittext", "evaluate", "zoomset", "tabactivate", "tabclose", "tabreload", "windowclose", "windowresize", "tabcreate", "windowcreate", "downloadfile"]);
|
|
141
|
+
var targetactions = /* @__PURE__ */ new Set(["inspect", "focus", "click", "type", "scroll", "select", "hover", "clickdeep", "rightclick", "doubleclick", "drag", "drop", "upload", "clear", "check", "uncheck", "toggle", "submit", "readattribute", "readstyle", "readgeometry", "readvalue", "readtext", "readhtml", "countelements", "readtable", "highlight", "setattribute", "removeattribute", "waitfor", "shiftclick", "typetime", "appendtext", "setvalue", "typeedit", "submitsearch", "selectmulti", "chooseradio", "setslider", "setdate", "setcolor", "expanddetails", "verifyvisible", "verifyenabled", "pierceshadow"]);
|
|
142
|
+
var valueactions = /* @__PURE__ */ new Set(["presskey", "drag", "drop", "upload", "readattribute", "removeattribute", "waittext", "evaluate", "zoomset", "tabactivate", "tabclose", "tabreload", "windowclose", "windowresize", "tabcreate", "windowcreate", "downloadfile", "typetime", "appendtext", "setvalue", "typeedit", "keyhold", "keyrelease", "chooseradio", "setslider", "setdate", "setcolor"]);
|
|
81
143
|
function normalizeendpoint(value) {
|
|
82
144
|
const endpoint = new URL(value.trim());
|
|
83
145
|
if (endpoint.protocol !== "https:") throw new Error("Devthink accepts HTTPS endpoints only.");
|
|
@@ -121,19 +183,84 @@ function isnumericid(value) {
|
|
|
121
183
|
function numericoption(options, key) {
|
|
122
184
|
return options[key] === void 0 || typeof options[key] === "number" && Number.isFinite(options[key]);
|
|
123
185
|
}
|
|
186
|
+
function nonnegativeoption(options, key) {
|
|
187
|
+
return numericoption(options, key) && !(typeof options[key] === "number" && options[key] < 0);
|
|
188
|
+
}
|
|
189
|
+
function isnonempty(value) {
|
|
190
|
+
return typeof value === "string" && value.trim().length > 0;
|
|
191
|
+
}
|
|
192
|
+
function ispoint(value) {
|
|
193
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
194
|
+
const point = value;
|
|
195
|
+
return typeof point.x === "number" && Number.isFinite(point.x) && typeof point.y === "number" && Number.isFinite(point.y);
|
|
196
|
+
}
|
|
197
|
+
function validatetargetref(reference) {
|
|
198
|
+
if (!reference || typeof reference !== "object" || Array.isArray(reference)) return { allowed: false, reason: "The reviewed target reference must be an object." };
|
|
199
|
+
const ref = reference;
|
|
200
|
+
if (ref.mode === "selector") return isnonempty(ref.selector) ? { allowed: true } : { allowed: false, reason: "The selector target reference needs a non-empty selector." };
|
|
201
|
+
if (ref.mode === "text") return isnonempty(ref.text) ? { allowed: true } : { allowed: false, reason: "The text target reference needs non-empty text." };
|
|
202
|
+
if (ref.mode === "aria") {
|
|
203
|
+
if (!isnonempty(ref.role)) return { allowed: false, reason: "The aria target reference needs a non-empty role." };
|
|
204
|
+
return isnonempty(ref.name) ? { allowed: true } : { allowed: false, reason: "The aria target reference needs a non-empty name." };
|
|
205
|
+
}
|
|
206
|
+
if (ref.mode === "name") return isnonempty(ref.name) ? { allowed: true } : { allowed: false, reason: "The name target reference needs a non-empty name." };
|
|
207
|
+
if (ref.mode === "xpath") return isnonempty(ref.xpath) ? { allowed: true } : { allowed: false, reason: "The xpath target reference needs a non-empty expression." };
|
|
208
|
+
if (ref.mode === "index") {
|
|
209
|
+
const index = ref.index;
|
|
210
|
+
return typeof index === "number" && Number.isInteger(index) && index >= 1 ? { allowed: true } : { allowed: false, reason: "The index target reference needs a positive integer map number." };
|
|
211
|
+
}
|
|
212
|
+
if (ref.mode === "point") {
|
|
213
|
+
const pointok = typeof ref.x === "number" && Number.isFinite(ref.x) && typeof ref.y === "number" && Number.isFinite(ref.y);
|
|
214
|
+
return pointok ? { allowed: true } : { allowed: false, reason: "The point target reference needs numeric x and y coordinates." };
|
|
215
|
+
}
|
|
216
|
+
return { allowed: false, reason: "The target reference mode must be selector, text, aria, name, xpath, index or point." };
|
|
217
|
+
}
|
|
218
|
+
function origingranted(session, origin) {
|
|
219
|
+
if (!session) return false;
|
|
220
|
+
const grants = session.grants ?? [session.origin];
|
|
221
|
+
return grants.includes(origin);
|
|
222
|
+
}
|
|
223
|
+
function validateinnerstep(options, origin) {
|
|
224
|
+
const stepid = options.stepid;
|
|
225
|
+
const kind = options.kind;
|
|
226
|
+
if (isnonempty(stepid)) {
|
|
227
|
+
if (kind !== void 0) return { allowed: false, reason: "The reviewed wrapper must reference a step id or an inline step, not both." };
|
|
228
|
+
return { allowed: true };
|
|
229
|
+
}
|
|
230
|
+
if (typeof kind !== "string" || !kind.trim()) return { allowed: false, reason: "A reviewed step id or inline step kind is required in options." };
|
|
231
|
+
if (kind === "retryaction" || kind === "enterframe") return { allowed: false, reason: "The reviewed inner step cannot be another wrapper kind." };
|
|
232
|
+
if (!allowedactions.has(kind)) return { allowed: false, reason: "The reviewed inner step kind is unsupported." };
|
|
233
|
+
const inneroptions = options.options;
|
|
234
|
+
if (inneroptions !== void 0 && (!inneroptions || typeof inneroptions !== "object" || Array.isArray(inneroptions))) return { allowed: false, reason: "The reviewed inner step options must be an object." };
|
|
235
|
+
const inner = {
|
|
236
|
+
id: "inner",
|
|
237
|
+
kind,
|
|
238
|
+
summary: "Reviewed inner step.",
|
|
239
|
+
risk: actionrisk(kind),
|
|
240
|
+
...isnonempty(options.target) ? { target: options.target } : {},
|
|
241
|
+
...isnonempty(options.value) ? { value: options.value } : {},
|
|
242
|
+
...inneroptions !== void 0 ? { options: JSON.stringify(inneroptions) } : {}
|
|
243
|
+
};
|
|
244
|
+
return validatestep(inner, origin);
|
|
245
|
+
}
|
|
124
246
|
function validatestep(step, origin) {
|
|
125
247
|
if (!allowedactions.has(step.kind)) return { allowed: false, reason: "Unsupported action kind." };
|
|
126
248
|
if (!step.summary.trim()) return { allowed: false, reason: "A human-readable action summary is required." };
|
|
127
|
-
if (targetactions.has(step.kind) && !step.target?.trim()) return { allowed: false, reason: "A page target is required." };
|
|
128
|
-
if (valueactions.has(step.kind) && !step.value?.trim()) return { allowed: false, reason: "A reviewed value is required." };
|
|
129
|
-
if (step.kind === "select" && !step.value?.trim()) return { allowed: false, reason: "A reviewed option value is required." };
|
|
130
|
-
if (step.kind === "navigate" && !step.value) return { allowed: false, reason: "A navigation URL is required." };
|
|
131
249
|
let options;
|
|
132
250
|
try {
|
|
133
251
|
options = parseoptions(step);
|
|
134
252
|
} catch {
|
|
135
253
|
return { allowed: false, reason: "Step options must be a JSON object." };
|
|
136
254
|
}
|
|
255
|
+
const hastargetref = options.targetref !== void 0;
|
|
256
|
+
if (targetactions.has(step.kind) && !step.target?.trim() && !hastargetref) return { allowed: false, reason: "A page target is required." };
|
|
257
|
+
if (valueactions.has(step.kind) && !step.value?.trim()) return { allowed: false, reason: "A reviewed value is required." };
|
|
258
|
+
if (step.kind === "select" && !step.value?.trim()) return { allowed: false, reason: "A reviewed option value is required." };
|
|
259
|
+
if (step.kind === "navigate" && !step.value) return { allowed: false, reason: "A navigation URL is required." };
|
|
260
|
+
if (hastargetref) {
|
|
261
|
+
const reference = validatetargetref(options.targetref);
|
|
262
|
+
if (!reference.allowed) return reference;
|
|
263
|
+
}
|
|
137
264
|
if (step.kind === "wait") {
|
|
138
265
|
try {
|
|
139
266
|
waitduration(step);
|
|
@@ -173,6 +300,68 @@ function validatestep(step, origin) {
|
|
|
173
300
|
}
|
|
174
301
|
if ((step.kind === "scrollpage" || step.kind === "scrollby") && (!numericoption(options, "x") || !numericoption(options, "y"))) return { allowed: false, reason: "Scroll amounts must be numbers in options." };
|
|
175
302
|
if (step.kind === "waitfor" && options.timeout !== void 0 && (typeof options.timeout !== "number" || options.timeout < 0)) return { allowed: false, reason: "The waitfor timeout must be zero or a positive number of milliseconds." };
|
|
303
|
+
if (step.kind === "movepointer") {
|
|
304
|
+
const path = options.pointpath;
|
|
305
|
+
if (!path || typeof path !== "object" || Array.isArray(path)) return { allowed: false, reason: "A reviewed pointpath with start and end points is required in options." };
|
|
306
|
+
const points = path;
|
|
307
|
+
if (!ispoint(points.start) || !ispoint(points.end)) return { allowed: false, reason: "The reviewed pointpath needs numeric start and end points." };
|
|
308
|
+
if (points.waypoints !== void 0 && (!Array.isArray(points.waypoints) || !points.waypoints.every((waypoint) => ispoint(waypoint)))) return { allowed: false, reason: "The reviewed pointpath waypoints must be numeric points." };
|
|
309
|
+
if (!nonnegativeoption(points, "duration")) return { allowed: false, reason: "The reviewed pointpath duration must be zero or a positive number of milliseconds." };
|
|
310
|
+
const speed = options.speedprofile;
|
|
311
|
+
if (speed !== void 0) {
|
|
312
|
+
if (!speed || typeof speed !== "object" || Array.isArray(speed)) return { allowed: false, reason: "The reviewed speed profile must be an object." };
|
|
313
|
+
const profile = speed;
|
|
314
|
+
if (profile.easing !== void 0 && profile.easing !== "linear" && profile.easing !== "easeinout") return { allowed: false, reason: "The reviewed easing must be linear or easeinout." };
|
|
315
|
+
if (!nonnegativeoption(profile, "peak")) return { allowed: false, reason: "The reviewed peak velocity must be zero or a positive number." };
|
|
316
|
+
if (!nonnegativeoption(profile, "jitter")) return { allowed: false, reason: "The reviewed jitter window must be zero or a positive number of milliseconds." };
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
if (step.kind === "clickpoint" && (!hastargetref || options.targetref.mode !== "point")) return { allowed: false, reason: "A reviewed point target reference is required in options." };
|
|
320
|
+
if (step.kind === "clicktext" && (!hastargetref || options.targetref.mode !== "text")) return { allowed: false, reason: "A reviewed text target reference is required in options." };
|
|
321
|
+
if (step.kind === "clickaria" && (!hastargetref || options.targetref.mode !== "aria")) return { allowed: false, reason: "A reviewed aria target reference is required in options." };
|
|
322
|
+
if (step.kind === "clickname" && (!hastargetref || options.targetref.mode !== "name")) return { allowed: false, reason: "A reviewed name target reference is required in options." };
|
|
323
|
+
if (step.kind === "resolvexpath" && (!hastargetref || options.targetref.mode !== "xpath")) return { allowed: false, reason: "A reviewed xpath target reference is required in options." };
|
|
324
|
+
if (step.kind === "typetime" && options.delay !== void 0 && (typeof options.delay !== "number" || !Number.isFinite(options.delay) || options.delay < 0)) return { allowed: false, reason: "The reviewed per keystroke delay must be zero or a positive number of milliseconds." };
|
|
325
|
+
if (step.kind === "submitsearch") {
|
|
326
|
+
if (!isnonempty(options.results)) return { allowed: false, reason: "A reviewed results region selector is required in options." };
|
|
327
|
+
if (options.timeout !== void 0 && (typeof options.timeout !== "number" || !Number.isFinite(options.timeout) || options.timeout < 0)) return { allowed: false, reason: "The submitsearch timeout must be zero or a positive number of milliseconds." };
|
|
328
|
+
}
|
|
329
|
+
if (step.kind === "selectmulti") {
|
|
330
|
+
const values = options.values;
|
|
331
|
+
if (!Array.isArray(values) || values.length === 0 || !values.every((value) => isnonempty(value))) return { allowed: false, reason: "A reviewed list of option values is required in options." };
|
|
332
|
+
}
|
|
333
|
+
if (step.kind === "setslider") {
|
|
334
|
+
const slider = Number(step.value);
|
|
335
|
+
if (!Number.isFinite(slider)) return { allowed: false, reason: "The reviewed slider value must be a number." };
|
|
336
|
+
}
|
|
337
|
+
if (step.kind === "setdate" && !/^\d{4}-\d{2}-\d{2}$/.test(step.value ?? "")) return { allowed: false, reason: "The reviewed date must use the yyyy-mm-dd form." };
|
|
338
|
+
if (step.kind === "setcolor" && !/^#[0-9a-fA-F]{6}$/.test(step.value ?? "")) return { allowed: false, reason: "The reviewed color must use the #rrggbb form." };
|
|
339
|
+
if (step.kind === "keyhold" && options.holdid !== void 0 && !isnonempty(options.holdid)) return { allowed: false, reason: "The reviewed hold id must be a non-empty string." };
|
|
340
|
+
if (step.kind === "dismissdialog") {
|
|
341
|
+
const accept = options.accept;
|
|
342
|
+
const answer = options.answer;
|
|
343
|
+
if (accept === void 0 && !isnonempty(answer)) return { allowed: false, reason: "A reviewed accept flag or prompt answer is required in options." };
|
|
344
|
+
if (accept !== void 0 && typeof accept !== "boolean") return { allowed: false, reason: "The reviewed dialog accept flag must be a boolean." };
|
|
345
|
+
if (answer !== void 0 && !isnonempty(answer)) return { allowed: false, reason: "The reviewed prompt answer must be a non-empty string." };
|
|
346
|
+
}
|
|
347
|
+
if (step.kind === "pierceshadow" && options.shadow !== void 0) {
|
|
348
|
+
if (!Array.isArray(options.shadow) || !options.shadow.every((item) => isnonempty(item))) return { allowed: false, reason: "The reviewed shadow path must be a list of non-empty selectors." };
|
|
349
|
+
}
|
|
350
|
+
if (step.kind === "enterframe") {
|
|
351
|
+
const path = options.framepath;
|
|
352
|
+
if (!Array.isArray(path) || path.length === 0 || !path.every((item) => typeof item === "number" && Number.isInteger(item) && item >= 0)) return { allowed: false, reason: "A reviewed frame path of frame indexes is required in options." };
|
|
353
|
+
return validateinnerstep(options, origin);
|
|
354
|
+
}
|
|
355
|
+
if (step.kind === "retryaction") {
|
|
356
|
+
const inner = validateinnerstep(options, origin);
|
|
357
|
+
if (!inner.allowed) return inner;
|
|
358
|
+
const rule = options.retryrule;
|
|
359
|
+
if (!rule || typeof rule !== "object" || Array.isArray(rule)) return { allowed: false, reason: "A reviewed retry rule with attempts is required in options." };
|
|
360
|
+
const retry = rule;
|
|
361
|
+
if (typeof retry.attempts !== "number" || !Number.isInteger(retry.attempts) || retry.attempts < 1) return { allowed: false, reason: "The reviewed retry attempts must be a positive integer with no code ceiling." };
|
|
362
|
+
if (!nonnegativeoption(retry, "settle")) return { allowed: false, reason: "The reviewed retry settle window must be zero or a positive number of milliseconds." };
|
|
363
|
+
if (!nonnegativeoption(retry, "tolerance")) return { allowed: false, reason: "The reviewed retry movement tolerance must be zero or a positive number of pixels." };
|
|
364
|
+
}
|
|
176
365
|
return { allowed: true };
|
|
177
366
|
}
|
|
178
367
|
function sessiongate(input) {
|
|
@@ -188,6 +377,7 @@ function canexecute(input) {
|
|
|
188
377
|
if (!gate.allowed) return gate;
|
|
189
378
|
if (!input.plan || input.plan.state !== "approved") return { allowed: false, reason: "The plan has not received explicit approval." };
|
|
190
379
|
if (input.plan.expiresat <= now) return { allowed: false, reason: "The approved plan has expired." };
|
|
380
|
+
if ((input.step.kind === "pierceshadow" || input.step.kind === "enterframe") && !origingranted(input.session, input.origin)) return { allowed: false, reason: "The shadow or frame step is outside the session origin grants." };
|
|
191
381
|
return validatestep(input.step, input.origin);
|
|
192
382
|
}
|
|
193
383
|
function canpreview(input) {
|
|
@@ -196,7 +386,13 @@ function canpreview(input) {
|
|
|
196
386
|
if (!gate.allowed) return gate;
|
|
197
387
|
if (!input.plan || !["pending", "approved"].includes(input.plan.state)) return { allowed: false, reason: "Only a reviewed pending or approved plan can be previewed." };
|
|
198
388
|
if (input.plan.expiresat <= now) return { allowed: false, reason: "The reviewed plan has expired." };
|
|
199
|
-
|
|
389
|
+
let options = {};
|
|
390
|
+
try {
|
|
391
|
+
options = parseoptions(input.step);
|
|
392
|
+
} catch {
|
|
393
|
+
options = {};
|
|
394
|
+
}
|
|
395
|
+
if (!targetactions.has(input.step.kind) && options.targetref === void 0) return { allowed: false, reason: "Only a target-based action can be previewed." };
|
|
200
396
|
return validatestep(input.step, input.origin);
|
|
201
397
|
}
|
|
202
398
|
|
|
@@ -226,7 +422,7 @@ function resetforplan(progress, plan, now) {
|
|
|
226
422
|
}
|
|
227
423
|
|
|
228
424
|
// version.ts
|
|
229
|
-
var packageversion = "1.1.
|
|
425
|
+
var packageversion = "1.1.33";
|
|
230
426
|
|
|
231
427
|
// types.ts
|
|
232
428
|
var protocolversion = packageversion;
|
|
@@ -262,6 +458,11 @@ function parseproposal(value, origin) {
|
|
|
262
458
|
if (!evaluation.allowed) throw new Error(evaluation.reason);
|
|
263
459
|
return step;
|
|
264
460
|
});
|
|
461
|
+
for (const step of steps) {
|
|
462
|
+
if (step.kind !== "retryaction" && step.kind !== "enterframe") continue;
|
|
463
|
+
const options = parseoptions(step);
|
|
464
|
+
if (typeof options.stepid === "string" && !steps.some((candidate) => candidate.id === options.stepid)) throw new Error("A retry or frame wrapper references an unknown step id.");
|
|
465
|
+
}
|
|
265
466
|
const createdat = Date.now();
|
|
266
467
|
const expiresat = typeof planinput.expiresat === "number" ? planinput.expiresat : createdat + 10 * 60 * 1e3;
|
|
267
468
|
const plan = {
|
|
@@ -279,6 +480,15 @@ function parseproposal(value, origin) {
|
|
|
279
480
|
function requestbody(input) {
|
|
280
481
|
return JSON.stringify({ version: protocolversion, objective: input.objective, session: input.session, observation: input.observation, capabilities: input.capabilities });
|
|
281
482
|
}
|
|
483
|
+
function outcomeresponse(input) {
|
|
484
|
+
return JSON.stringify({ version: protocolversion, planid: input.plan.id, planstate: input.plan.state, outcome: input.outcome, ...input.resolvedtarget ? { resolvedtarget: input.resolvedtarget } : {} });
|
|
485
|
+
}
|
|
486
|
+
function mapresponse(input) {
|
|
487
|
+
return JSON.stringify({ version: protocolversion, planid: input.plan.id, planstate: input.plan.state, map: input.map });
|
|
488
|
+
}
|
|
489
|
+
function heldkeysreport(input) {
|
|
490
|
+
return { version: protocolversion, tabid: input.tabid, heldkeys: input.holds };
|
|
491
|
+
}
|
|
282
492
|
|
|
283
493
|
// extension/browsertabs.ts
|
|
284
494
|
var browserkinds = /* @__PURE__ */ new Set(["tablist", "tabcreate", "tabactivate", "tabclose", "tabreload", "tabsnapshot", "windowlist", "windowcreate", "windowclose", "zoomset", "windowresize", "downloadfile"]);
|
|
@@ -363,9 +573,143 @@ async function runbrowseraction(step, sessiontabid, windowid) {
|
|
|
363
573
|
}
|
|
364
574
|
}
|
|
365
575
|
|
|
576
|
+
// extension/pagedialogs.ts
|
|
577
|
+
function parsedialogpolicy(step) {
|
|
578
|
+
let options = {};
|
|
579
|
+
try {
|
|
580
|
+
options = parseoptions(step);
|
|
581
|
+
} catch {
|
|
582
|
+
return null;
|
|
583
|
+
}
|
|
584
|
+
const accept = options.accept;
|
|
585
|
+
const answer = options.answer;
|
|
586
|
+
if (typeof accept !== "boolean" && typeof answer !== "string") return null;
|
|
587
|
+
return { accept: accept === true, ...typeof answer === "string" && answer.trim() ? { answer } : {} };
|
|
588
|
+
}
|
|
589
|
+
function dialoganswer(policy, dialog) {
|
|
590
|
+
if (dialog === "prompt") {
|
|
591
|
+
if (policy.answer === void 0 || policy.answer === "") return { accept: false };
|
|
592
|
+
return { accept: policy.accept !== false, ...policy.answer !== void 0 ? { answer: policy.answer } : {} };
|
|
593
|
+
}
|
|
594
|
+
return { accept: policy.accept };
|
|
595
|
+
}
|
|
596
|
+
function installdialoghandler(accept, answer, persistent) {
|
|
597
|
+
const world = globalThis;
|
|
598
|
+
const originals = world.devthinkoriginaldialogs ?? { confirm: window.confirm.bind(window), alert: window.alert.bind(window), prompt: window.prompt.bind(window) };
|
|
599
|
+
world.devthinkoriginaldialogs = originals;
|
|
600
|
+
const decide = (dialog) => {
|
|
601
|
+
if (dialog === "prompt") return answer ? { accept: true, answer } : { accept: false, answer: null };
|
|
602
|
+
return { accept, answer: null };
|
|
603
|
+
};
|
|
604
|
+
const record2 = (dialog, text2, result) => {
|
|
605
|
+
try {
|
|
606
|
+
const root = document.documentElement;
|
|
607
|
+
const log = JSON.parse(root.dataset.devthinkdialoglog ?? "[]");
|
|
608
|
+
log.push({ dialog, text: text2, result, at: Date.now() });
|
|
609
|
+
root.dataset.devthinkdialoglog = JSON.stringify(log);
|
|
610
|
+
} catch {
|
|
611
|
+
}
|
|
612
|
+
};
|
|
613
|
+
window.confirm = (text2) => {
|
|
614
|
+
const decision = decide("confirm");
|
|
615
|
+
record2("confirm", text2 ?? "", decision.accept);
|
|
616
|
+
if (!persistent) window.confirm = originals.confirm;
|
|
617
|
+
return decision.accept;
|
|
618
|
+
};
|
|
619
|
+
window.alert = (text2) => {
|
|
620
|
+
record2("alert", text2 ?? "", true);
|
|
621
|
+
if (!persistent) window.alert = originals.alert;
|
|
622
|
+
};
|
|
623
|
+
window.prompt = (text2, defaultvalue) => {
|
|
624
|
+
const decision = decide("prompt");
|
|
625
|
+
const outcome = decision.accept ? decision.answer ?? defaultvalue ?? "" : null;
|
|
626
|
+
record2("prompt", text2 ?? "", outcome);
|
|
627
|
+
if (!persistent) window.prompt = originals.prompt;
|
|
628
|
+
return outcome;
|
|
629
|
+
};
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
// extension/pageinteract.ts
|
|
633
|
+
function optionsof(step) {
|
|
634
|
+
try {
|
|
635
|
+
return parseoptions(step);
|
|
636
|
+
} catch {
|
|
637
|
+
return {};
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
function innerstep(step) {
|
|
641
|
+
const options = optionsof(step);
|
|
642
|
+
const kind = options.kind;
|
|
643
|
+
if (typeof kind !== "string" || !kind.trim()) return null;
|
|
644
|
+
const inneroptions = options.options;
|
|
645
|
+
return {
|
|
646
|
+
id: `${step.id}inner`,
|
|
647
|
+
kind,
|
|
648
|
+
summary: step.summary,
|
|
649
|
+
risk: step.risk,
|
|
650
|
+
...typeof options.target === "string" ? { target: options.target } : {},
|
|
651
|
+
...typeof options.value === "string" ? { value: options.value } : {},
|
|
652
|
+
...inneroptions && typeof inneroptions === "object" && !Array.isArray(inneroptions) ? { options: JSON.stringify(inneroptions) } : {}
|
|
653
|
+
};
|
|
654
|
+
}
|
|
655
|
+
function pointdistance(a, b) {
|
|
656
|
+
return Math.hypot(b.x - a.x, b.y - a.y);
|
|
657
|
+
}
|
|
658
|
+
function settle(delay) {
|
|
659
|
+
return new Promise((resolve) => setTimeout(resolve, delay));
|
|
660
|
+
}
|
|
661
|
+
async function runretries(rule, probe, execute) {
|
|
662
|
+
const attempts = Math.max(1, Number.isFinite(rule.attempts) ? Math.floor(rule.attempts) : 1);
|
|
663
|
+
const tolerance = typeof rule.tolerance === "number" && Number.isFinite(rule.tolerance) ? rule.tolerance : 0;
|
|
664
|
+
const settles = typeof rule.settle === "number" && Number.isFinite(rule.settle) ? rule.settle : 0;
|
|
665
|
+
let previous = await probe();
|
|
666
|
+
let movement = 0;
|
|
667
|
+
let made = 0;
|
|
668
|
+
let last = "";
|
|
669
|
+
for (let attempt = 1; attempt <= attempts; attempt += 1) {
|
|
670
|
+
made = attempt;
|
|
671
|
+
const result = await execute(attempt);
|
|
672
|
+
last = result.summary;
|
|
673
|
+
if (result.ok) return { ok: true, attempts: made, movement, summary: `Retry interaction succeeded on attempt ${made} after ${movement.toFixed(1)} pixels of observed movement.` };
|
|
674
|
+
if (attempt >= attempts) break;
|
|
675
|
+
if (settles > 0) await settle(settles);
|
|
676
|
+
const current = await probe();
|
|
677
|
+
if (!current) {
|
|
678
|
+
previous = null;
|
|
679
|
+
continue;
|
|
680
|
+
}
|
|
681
|
+
if (previous) {
|
|
682
|
+
const delta = pointdistance(previous, current);
|
|
683
|
+
movement = Math.max(movement, delta);
|
|
684
|
+
if (delta <= tolerance) return { ok: false, attempts: made, movement, summary: `The target stayed within the reviewed tolerance of ${tolerance} pixels; retry stopped after attempt ${made}. ${last}` };
|
|
685
|
+
}
|
|
686
|
+
previous = current;
|
|
687
|
+
}
|
|
688
|
+
return { ok: false, attempts: made, movement, summary: `Retry interaction failed after ${made} attempt${made === 1 ? "" : "s"} with ${movement.toFixed(1)} pixels of observed movement. ${last}` };
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
// extension/pagecontrols.ts
|
|
692
|
+
function presshold(holds, hold) {
|
|
693
|
+
if (holds.some((existing) => existing.holdid === hold.holdid && existing.releasedat === void 0)) return { holds, ok: false };
|
|
694
|
+
return { holds: [...holds, hold], ok: true };
|
|
695
|
+
}
|
|
696
|
+
function releasehold(holds, holdid, releasedat) {
|
|
697
|
+
let released;
|
|
698
|
+
const next = holds.map((hold) => {
|
|
699
|
+
if (hold.holdid !== holdid || hold.releasedat !== void 0) return hold;
|
|
700
|
+
released = { ...hold, releasedat };
|
|
701
|
+
return released;
|
|
702
|
+
});
|
|
703
|
+
return { holds: next, ...released ? { released } : {} };
|
|
704
|
+
}
|
|
705
|
+
function heldkeys(holds, tabid2) {
|
|
706
|
+
return holds.filter((hold) => hold.releasedat === void 0 && (tabid2 === void 0 || hold.tabid === void 0 || hold.tabid === tabid2));
|
|
707
|
+
}
|
|
708
|
+
|
|
366
709
|
// extension/background.ts
|
|
367
710
|
var sessionduration = 15 * 60 * 1e3;
|
|
368
711
|
var freshcheckkinds = /* @__PURE__ */ new Set(["focus", "inspect", "click", "type", "scroll", "select", "hover"]);
|
|
712
|
+
var pointerkinds = /* @__PURE__ */ new Set(["movepointer", "clickpoint", "shiftclick", "clicktext", "clickaria", "clickname", "pierceshadow"]);
|
|
369
713
|
var chromestorage = {
|
|
370
714
|
async get(key) {
|
|
371
715
|
return (await chrome.storage.local.get(key))[key];
|
|
@@ -381,6 +725,13 @@ function extensionpage(sender) {
|
|
|
381
725
|
async function audit(kind, summary, extra = {}) {
|
|
382
726
|
await memory.addaudi({ id: randomid(), kind, at: Date.now(), summary, ...extra });
|
|
383
727
|
}
|
|
728
|
+
function stepoptions2(step) {
|
|
729
|
+
try {
|
|
730
|
+
return parseoptions(step);
|
|
731
|
+
} catch {
|
|
732
|
+
return {};
|
|
733
|
+
}
|
|
734
|
+
}
|
|
384
735
|
async function refreshcapabilities() {
|
|
385
736
|
const report = await readcapabilities();
|
|
386
737
|
await memory.setcapabilities(report);
|
|
@@ -404,11 +755,77 @@ async function snapshot(tabid2) {
|
|
|
404
755
|
if (!value) throw new Error("The page did not return an observation.");
|
|
405
756
|
return value;
|
|
406
757
|
}
|
|
758
|
+
function plandialogpolicy(plan) {
|
|
759
|
+
const step = plan?.steps.find((candidate) => candidate.kind === "dismissdialog");
|
|
760
|
+
return step ? parsedialogpolicy(step) : null;
|
|
761
|
+
}
|
|
762
|
+
async function installdialogpolicy(tabid2, policy, persistent) {
|
|
763
|
+
await chrome.scripting.executeScript({
|
|
764
|
+
target: { tabId: tabid2 },
|
|
765
|
+
world: "MAIN",
|
|
766
|
+
func: installdialoghandler,
|
|
767
|
+
args: [policy.accept, policy.answer ?? "", persistent]
|
|
768
|
+
});
|
|
769
|
+
}
|
|
770
|
+
async function ensuredialoghandler(plan, tabid2) {
|
|
771
|
+
const policy = plandialogpolicy(plan) ?? await memory.getdialogpolicy();
|
|
772
|
+
if (!policy) return;
|
|
773
|
+
try {
|
|
774
|
+
await installdialogpolicy(tabid2, policy, true);
|
|
775
|
+
} catch {
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
async function harvestdialogs(session, plan, stepid, tabid2) {
|
|
779
|
+
const policy = plandialogpolicy(plan) ?? await memory.getdialogpolicy();
|
|
780
|
+
let observed = [];
|
|
781
|
+
try {
|
|
782
|
+
const result = await chrome.scripting.executeScript({ target: { tabId: tabid2 }, func: () => {
|
|
783
|
+
const bridge = globalThis.devthinkbridge;
|
|
784
|
+
return bridge?.readdialogs ? bridge.readdialogs() : [];
|
|
785
|
+
} });
|
|
786
|
+
const value = result[0]?.result;
|
|
787
|
+
if (Array.isArray(value)) observed = value;
|
|
788
|
+
} catch {
|
|
789
|
+
}
|
|
790
|
+
for (const entry of observed) {
|
|
791
|
+
const reviewed = policy ? dialoganswer(policy, ["confirm", "alert", "prompt"].includes(entry.dialog) ? entry.dialog : "confirm") : void 0;
|
|
792
|
+
const decision = {
|
|
793
|
+
id: randomid(),
|
|
794
|
+
dialog: entry.dialog,
|
|
795
|
+
text: entry.text,
|
|
796
|
+
accept: reviewed ? reviewed.accept : entry.result !== null && entry.result !== false,
|
|
797
|
+
...reviewed?.answer !== void 0 ? { answer: reviewed.answer } : {},
|
|
798
|
+
...session ? { sessionid: session.id } : {},
|
|
799
|
+
at: Number.isFinite(entry.at) ? entry.at : Date.now()
|
|
800
|
+
};
|
|
801
|
+
await memory.adddialog(decision);
|
|
802
|
+
await audit("dialog", `Dialog ${decision.dialog} answered ${decision.accept ? "accept" : "dismiss"}${decision.answer ? ` with the reviewed answer "${decision.answer}"` : ""} for dialog text "${decision.text.slice(0, 120)}".`, { ...session ? { sessionid: session.id } : {}, ...plan ? { planid: plan.id } : {}, stepid });
|
|
803
|
+
}
|
|
804
|
+
}
|
|
805
|
+
async function dispatchpagestep(step, tabid2, origin, plan) {
|
|
806
|
+
const session = await memory.getsession();
|
|
807
|
+
const activeplan = plan ?? await memory.getplan();
|
|
808
|
+
await ensuredialoghandler(activeplan, tabid2);
|
|
809
|
+
const result = await chrome.scripting.executeScript({ target: { tabId: tabid2 }, func: (action, expectedorigin) => {
|
|
810
|
+
const bridge = globalThis.devthinkbridge;
|
|
811
|
+
if (!bridge) throw new Error("Devthink page bridge is unavailable.");
|
|
812
|
+
return bridge.performstep(action, expectedorigin);
|
|
813
|
+
}, args: [step, origin] });
|
|
814
|
+
await harvestdialogs(session, activeplan, step.id, tabid2);
|
|
815
|
+
return result[0]?.result;
|
|
816
|
+
}
|
|
407
817
|
async function startsession() {
|
|
408
818
|
const { tab, origin } = await activecontext();
|
|
409
819
|
const session = { id: randomid(), tabid: tab.id, origin, startedat: Date.now(), expiresat: Date.now() + sessionduration, grants: [origin] };
|
|
410
820
|
await memory.setsession(session);
|
|
411
821
|
await audit("session", `Session started for ${origin}.`, { sessionid: session.id });
|
|
822
|
+
const policy = await memory.getdialogpolicy();
|
|
823
|
+
if (policy) {
|
|
824
|
+
try {
|
|
825
|
+
await installdialogpolicy(session.tabid, policy, true);
|
|
826
|
+
} catch {
|
|
827
|
+
}
|
|
828
|
+
}
|
|
412
829
|
return session;
|
|
413
830
|
}
|
|
414
831
|
async function diagnostic() {
|
|
@@ -451,6 +868,98 @@ function browserauditkind(step) {
|
|
|
451
868
|
if (step.kind.startsWith("window")) return "window";
|
|
452
869
|
return "tab";
|
|
453
870
|
}
|
|
871
|
+
function stepauditkind(step, ok) {
|
|
872
|
+
if (isbrowserkind(step.kind)) return browserauditkind(step);
|
|
873
|
+
if (step.kind === "dismissdialog") return "dialog";
|
|
874
|
+
if (step.kind === "keyhold" || step.kind === "keyrelease") return "hold";
|
|
875
|
+
if (step.kind === "retryaction") return "retry";
|
|
876
|
+
if (pointerkinds.has(step.kind)) return "pointer";
|
|
877
|
+
return ok ? "action" : "error";
|
|
878
|
+
}
|
|
879
|
+
function resolvedinnerstep(step, plan) {
|
|
880
|
+
const options = stepoptions2(step);
|
|
881
|
+
if (typeof options.stepid === "string" && options.stepid.trim()) {
|
|
882
|
+
return plan.steps.find((candidate) => candidate.id === options.stepid) ?? null;
|
|
883
|
+
}
|
|
884
|
+
return innerstep(step);
|
|
885
|
+
}
|
|
886
|
+
async function executekeyhold(step, session, plan, tabid2, origin) {
|
|
887
|
+
const output = await dispatchpagestep(step, tabid2, origin, plan);
|
|
888
|
+
if (!output?.ok) return output ?? { ok: false, summary: "The key hold was not delivered." };
|
|
889
|
+
const options = stepoptions2(step);
|
|
890
|
+
const holdid = typeof options.holdid === "string" && options.holdid.trim() ? options.holdid : randomid();
|
|
891
|
+
const modifiers = Array.isArray(options.modifiers) ? options.modifiers.filter((item) => typeof item === "string") : [];
|
|
892
|
+
const hold = { holdid, key: step.value ?? "", ...modifiers.length > 0 ? { modifiers } : {}, tabid: tabid2, stepid: step.id, pressedat: Date.now() };
|
|
893
|
+
const next = presshold(await memory.getholds(), hold);
|
|
894
|
+
if (!next.ok) return { ok: false, summary: `Hold id ${holdid} is already held.` };
|
|
895
|
+
await memory.setholds(next.holds);
|
|
896
|
+
await audit("hold", `Key ${hold.key} held under hold id ${holdid} pressed at ${new Date(hold.pressedat).toISOString()}.`, { ...session ? { sessionid: session.id } : {}, planid: plan.id, stepid: step.id });
|
|
897
|
+
return { ok: true, summary: `Key ${hold.key} held under hold id ${holdid}.`, details: { holdid } };
|
|
898
|
+
}
|
|
899
|
+
async function executekeyrelease(step, session, plan, tabid2, origin) {
|
|
900
|
+
const holdid = step.value ?? "";
|
|
901
|
+
const holds = await memory.getholds();
|
|
902
|
+
const held = holds.find((candidate) => candidate.holdid === holdid && candidate.releasedat === void 0);
|
|
903
|
+
if (!held) throw new Error(`No held key matches hold id ${holdid}.`);
|
|
904
|
+
const modifiers = held.modifiers ?? [];
|
|
905
|
+
const dispatchstep = { ...step, value: held.key, options: JSON.stringify({ ...modifiers.length > 0 ? { modifiers } : {} }) };
|
|
906
|
+
const output = await dispatchpagestep(dispatchstep, tabid2, origin, plan);
|
|
907
|
+
const releasedat = Date.now();
|
|
908
|
+
const transition = releasehold(holds, holdid, releasedat);
|
|
909
|
+
await memory.setholds(transition.holds);
|
|
910
|
+
await audit("hold", `Key ${held.key} released from hold id ${holdid} at ${new Date(releasedat).toISOString()} after ${Math.max(0, releasedat - held.pressedat)} milliseconds.`, { ...session ? { sessionid: session.id } : {}, planid: plan.id, stepid: step.id });
|
|
911
|
+
return { ok: output?.ok ?? false, summary: output?.summary ?? "Key release delivered.", details: { holdid } };
|
|
912
|
+
}
|
|
913
|
+
async function executedismissdialog(step, session, plan, tabid2, origin) {
|
|
914
|
+
const policy = parsedialogpolicy(step);
|
|
915
|
+
if (!policy) throw new Error("A reviewed dialog policy is required.");
|
|
916
|
+
await installdialogpolicy(tabid2, policy, false);
|
|
917
|
+
await harvestdialogs(session, plan, step.id, tabid2);
|
|
918
|
+
const answer = policy.answer !== void 0 ? ` with the reviewed answer "${policy.answer}"` : "";
|
|
919
|
+
return { ok: true, summary: `Dialog handler armed${answer} for the next confirm, alert or prompt.` };
|
|
920
|
+
}
|
|
921
|
+
async function executeretryaction(step, session, plan, tabid2, origin) {
|
|
922
|
+
const rule = stepoptions2(step).retryrule;
|
|
923
|
+
const inner = resolvedinnerstep(step, plan);
|
|
924
|
+
if (!inner) throw new Error("The reviewed wrapper step could not be resolved.");
|
|
925
|
+
const innergate = validatestep(inner, origin);
|
|
926
|
+
if (!innergate.allowed) throw new Error(`The wrapped step is not allowed: ${innergate.reason}`);
|
|
927
|
+
const probe = async () => {
|
|
928
|
+
const probestep = { id: `${step.id}probe`, kind: "readgeometry", summary: step.summary, risk: "read", ...inner.target ? { target: inner.target } : {}, ...inner.options ? { options: inner.options } : {} };
|
|
929
|
+
const output = await dispatchpagestep(probestep, tabid2, origin, plan);
|
|
930
|
+
const geometry = output?.details?.geometry;
|
|
931
|
+
if (!geometry || typeof geometry.x !== "number" || typeof geometry.y !== "number" || !Number.isFinite(geometry.x) || !Number.isFinite(geometry.y)) return null;
|
|
932
|
+
return { x: geometry.x, y: geometry.y };
|
|
933
|
+
};
|
|
934
|
+
const execute = async () => {
|
|
935
|
+
const output = await dispatchpagestep(inner, tabid2, origin, plan);
|
|
936
|
+
return { ok: Boolean(output?.ok), summary: output?.summary ?? "The wrapped step returned no result." };
|
|
937
|
+
};
|
|
938
|
+
const outcome = await runretries(rule ?? { attempts: 1 }, probe, execute);
|
|
939
|
+
const record2 = { stepid: step.id, attempts: outcome.attempts, movement: outcome.movement, ok: outcome.ok, at: Date.now() };
|
|
940
|
+
await memory.addretry(record2);
|
|
941
|
+
await audit("retry", outcome.summary, { ...session ? { sessionid: session.id } : {}, planid: plan.id, stepid: step.id });
|
|
942
|
+
return { ok: outcome.ok, summary: outcome.summary, details: { attempts: outcome.attempts, movement: outcome.movement } };
|
|
943
|
+
}
|
|
944
|
+
async function executemapclicks(step, plan, tabid2, origin) {
|
|
945
|
+
const output = await dispatchpagestep(step, tabid2, origin, plan);
|
|
946
|
+
if (!output?.ok) return output ?? { ok: false, summary: "The clickable map was not captured." };
|
|
947
|
+
const entries = Array.isArray(output.details?.entries) ? output.details?.entries : [];
|
|
948
|
+
const version = await memory.nextobservationversion();
|
|
949
|
+
const map = { version, entries, builtat: Date.now() };
|
|
950
|
+
await memory.setmap(map);
|
|
951
|
+
return { ok: true, summary: output.summary, details: { entries, mapversion: version } };
|
|
952
|
+
}
|
|
953
|
+
async function executeenterframe(step, plan, tabid2, origin) {
|
|
954
|
+
const inner = resolvedinnerstep(step, plan);
|
|
955
|
+
if (!inner) throw new Error("The reviewed frame wrapper step could not be resolved.");
|
|
956
|
+
const innergate = validatestep(inner, origin);
|
|
957
|
+
if (!innergate.allowed) throw new Error(`The wrapped step is not allowed: ${innergate.reason}`);
|
|
958
|
+
const options = stepoptions2(step);
|
|
959
|
+
const inneroptions = inner.options ? stepoptions2(inner) : void 0;
|
|
960
|
+
const derived = { ...step, options: JSON.stringify({ ...options, kind: inner.kind, ...inner.target ? { target: inner.target } : {}, ...inner.value ? { value: inner.value } : {}, ...inneroptions ? { options: inneroptions } : {} }) };
|
|
961
|
+
return dispatchpagestep(derived, tabid2, origin, plan);
|
|
962
|
+
}
|
|
454
963
|
async function executestep(stepid) {
|
|
455
964
|
const session = await memory.getsession();
|
|
456
965
|
const plan = await memory.getplan();
|
|
@@ -467,21 +976,32 @@ async function executestep(stepid) {
|
|
|
467
976
|
if (!granted) throw new Error(`The ${capability} capability has not been granted; request it from the review panel.`);
|
|
468
977
|
}
|
|
469
978
|
output = await runbrowseraction(step, tab.id, tab.windowId ?? chrome.windows.WINDOW_ID_CURRENT);
|
|
979
|
+
} else if (step.kind === "keyhold") {
|
|
980
|
+
output = await executekeyhold(step, session, plan, tab.id, origin);
|
|
981
|
+
} else if (step.kind === "keyrelease") {
|
|
982
|
+
output = await executekeyrelease(step, session, plan, tab.id, origin);
|
|
983
|
+
} else if (step.kind === "dismissdialog") {
|
|
984
|
+
output = await executedismissdialog(step, session, plan, tab.id, origin);
|
|
985
|
+
} else if (step.kind === "retryaction") {
|
|
986
|
+
output = await executeretryaction(step, session, plan, tab.id, origin);
|
|
987
|
+
} else if (step.kind === "mapclicks") {
|
|
988
|
+
output = await executemapclicks(step, plan, tab.id, origin);
|
|
989
|
+
} else if (step.kind === "enterframe") {
|
|
990
|
+
output = await executeenterframe(step, plan, tab.id, origin);
|
|
470
991
|
} else {
|
|
471
992
|
if (step.target && freshcheckkinds.has(step.kind)) {
|
|
472
993
|
const fresh = await snapshot(tab.id);
|
|
473
994
|
if (!fresh.interactive.some((item) => item.selector === step.target)) throw new Error("The page changed and the target must be reviewed again.");
|
|
474
995
|
}
|
|
475
|
-
|
|
476
|
-
const bridge = globalThis.devthinkbridge;
|
|
477
|
-
if (!bridge) throw new Error("Devthink page bridge is unavailable.");
|
|
478
|
-
return bridge.performstep(action, expectedorigin);
|
|
479
|
-
}, args: [step, origin] });
|
|
480
|
-
output = result[0]?.result;
|
|
996
|
+
output = await dispatchpagestep(step, tab.id, origin, plan);
|
|
481
997
|
}
|
|
482
998
|
const summary = output?.summary ?? "The page action returned no result.";
|
|
999
|
+
const resolved = output?.details?.resolvedtarget;
|
|
1000
|
+
if (resolved) {
|
|
1001
|
+
await memory.addresolution({ stepid, mode: resolved.mode, selector: resolved.selector, label: resolved.label, at: Date.now() });
|
|
1002
|
+
}
|
|
483
1003
|
const outcome = { stepid, ok: Boolean(output?.ok), summary, ...output?.details ? { details: output.details } : {}, at: Date.now() };
|
|
484
|
-
const auditkind =
|
|
1004
|
+
const auditkind = stepauditkind(step, Boolean(output?.ok));
|
|
485
1005
|
await audit(auditkind, summary, { ...session ? { sessionid: session.id } : {}, ...plan ? { planid: plan.id } : {}, stepid });
|
|
486
1006
|
await memory.addoutcome(outcome);
|
|
487
1007
|
if (output?.ok && plan) {
|
|
@@ -504,12 +1024,12 @@ async function previewstep(stepid) {
|
|
|
504
1024
|
if (!step) throw new Error("Reviewed step was not found.");
|
|
505
1025
|
const gate = canpreview({ session, plan, step, tabid: tab.id, origin });
|
|
506
1026
|
if (!gate.allowed) throw new Error(gate.reason);
|
|
507
|
-
if (!step.target) throw new Error("Only a target-based step can be previewed.");
|
|
508
|
-
const result = await chrome.scripting.executeScript({ target: { tabId: tab.id }, func: (
|
|
1027
|
+
if (!step.target && !stepoptions2(step).targetref) throw new Error("Only a target-based step can be previewed.");
|
|
1028
|
+
const result = await chrome.scripting.executeScript({ target: { tabId: tab.id }, func: (action, expectedorigin) => {
|
|
509
1029
|
const bridge = globalThis.devthinkbridge;
|
|
510
1030
|
if (!bridge) throw new Error("Devthink page bridge is unavailable.");
|
|
511
|
-
return bridge.previewtarget(
|
|
512
|
-
}, args: [step
|
|
1031
|
+
return bridge.previewtarget(action, expectedorigin);
|
|
1032
|
+
}, args: [step, origin] });
|
|
513
1033
|
const output = result[0]?.result;
|
|
514
1034
|
const summary = output?.summary ?? "The target preview returned no result.";
|
|
515
1035
|
await audit(output?.ok ? "observe" : "error", summary, { ...session ? { sessionid: session.id } : {}, ...plan ? { planid: plan.id } : {}, stepid });
|
|
@@ -559,7 +1079,11 @@ async function handlerequest(message, sender) {
|
|
|
559
1079
|
case "context": {
|
|
560
1080
|
const plan = await memory.getplan();
|
|
561
1081
|
const progress = await memory.getprogress();
|
|
562
|
-
|
|
1082
|
+
const session = await memory.getsession();
|
|
1083
|
+
const holds = heldkeys(await memory.getholds());
|
|
1084
|
+
const observationversion = await memory.getobservationversion();
|
|
1085
|
+
const map = observationversion !== void 0 && observationversion > 0 ? await memory.getmap(observationversion) : void 0;
|
|
1086
|
+
return { config: await memory.getconfig(), session, plan, progress: plan && progress?.planid === plan.id ? progress : void 0, diagnostic: await memory.getdiagnostic(), audit: await memory.getaudit(), capabilities: await refreshcapabilities(), outcomes: await memory.getoutcomes(), holds: heldkeysreport({ tabid: session?.tabid ?? 0, holds }), dialogs: await memory.getdialogs(), retries: await memory.getretries(), ...map ? { map } : {} };
|
|
563
1087
|
}
|
|
564
1088
|
case "capabilities":
|
|
565
1089
|
return refreshcapabilities();
|
|
@@ -576,6 +1100,8 @@ async function handlerequest(message, sender) {
|
|
|
576
1100
|
if (!plan || plan.state !== "pending") throw new Error("Only a pending plan can be approved.");
|
|
577
1101
|
const approved = { ...plan, state: "approved", approvedat: Date.now() };
|
|
578
1102
|
await memory.setplan(approved);
|
|
1103
|
+
const policy = plandialogpolicy(approved);
|
|
1104
|
+
if (policy) await memory.setdialogpolicy(policy);
|
|
579
1105
|
const current = await memory.getsession();
|
|
580
1106
|
await audit("approval", "The user approved the reviewed plan.", { ...current ? { sessionid: current.id } : {}, planid: approved.id });
|
|
581
1107
|
return approved;
|
|
@@ -593,6 +1119,22 @@ async function handlerequest(message, sender) {
|
|
|
593
1119
|
return previewstep(input.stepid ?? "");
|
|
594
1120
|
case "execute":
|
|
595
1121
|
return executestep(input.stepid ?? "");
|
|
1122
|
+
case "outcome": {
|
|
1123
|
+
const plan = await memory.getplan();
|
|
1124
|
+
if (!plan) throw new Error("No plan is available for an outcome envelope.");
|
|
1125
|
+
const outcome = (await memory.getoutcomes()).find((candidate) => candidate.stepid === (input.stepid ?? ""));
|
|
1126
|
+
if (!outcome) throw new Error("No outcome exists for the reviewed step.");
|
|
1127
|
+
const resolved = outcome.details?.resolvedtarget;
|
|
1128
|
+
return JSON.parse(outcomeresponse({ outcome, plan, ...resolved ? { resolvedtarget: resolved } : {} }));
|
|
1129
|
+
}
|
|
1130
|
+
case "map": {
|
|
1131
|
+
const plan = await memory.getplan();
|
|
1132
|
+
if (!plan) throw new Error("No plan is available for a map envelope.");
|
|
1133
|
+
const version = await memory.getobservationversion();
|
|
1134
|
+
const map = version !== void 0 ? await memory.getmap(version) : void 0;
|
|
1135
|
+
if (!map) throw new Error("No clickable map has been captured yet.");
|
|
1136
|
+
return JSON.parse(mapresponse({ map, plan }));
|
|
1137
|
+
}
|
|
596
1138
|
case "pausesession":
|
|
597
1139
|
return pausesession();
|
|
598
1140
|
case "resumesession":
|