@spaxe-dev/zen-mcp 0.3.3 → 0.5.0
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 +23 -10
- package/dist/bridge.js +1587 -66
- package/dist/cli.js +1411 -83
- package/dist/cli.js.map +4 -4
- package/package.json +1 -1
package/dist/bridge.js
CHANGED
|
@@ -21,7 +21,8 @@
|
|
|
21
21
|
"links",
|
|
22
22
|
"tables",
|
|
23
23
|
"metadata",
|
|
24
|
-
"outline"
|
|
24
|
+
"outline",
|
|
25
|
+
"interactive"
|
|
25
26
|
];
|
|
26
27
|
var MAX_TEXT = 2e5;
|
|
27
28
|
var MAX_SELECTED = 4e3;
|
|
@@ -31,6 +32,8 @@
|
|
|
31
32
|
var MAX_TABLE_COLUMNS = 12;
|
|
32
33
|
var MAX_CELL = 300;
|
|
33
34
|
var MAX_HEADINGS = 200;
|
|
35
|
+
var MAX_PAGE_ELEMENTS = 200;
|
|
36
|
+
var REF_PREFIX_PATTERN = /^(?:f[0-9]+(?:\.[0-9]+){0,2}-)?$/;
|
|
34
37
|
function normalizeFormat(value) {
|
|
35
38
|
return typeof value === "string" && READ_FORMATS.includes(value) ? value : "text";
|
|
36
39
|
}
|
|
@@ -100,6 +103,41 @@
|
|
|
100
103
|
}
|
|
101
104
|
return headings;
|
|
102
105
|
}
|
|
106
|
+
function coerceElements(value) {
|
|
107
|
+
if (!Array.isArray(value)) return [];
|
|
108
|
+
const elements = [];
|
|
109
|
+
for (const entry of value.slice(0, MAX_PAGE_ELEMENTS)) {
|
|
110
|
+
if (!entry || typeof entry !== "object") continue;
|
|
111
|
+
const raw = entry;
|
|
112
|
+
const ref = asString(raw.ref, 24);
|
|
113
|
+
const tag = asString(raw.tag, 40);
|
|
114
|
+
if (!ref || !tag) continue;
|
|
115
|
+
elements.push({
|
|
116
|
+
ref,
|
|
117
|
+
tag,
|
|
118
|
+
role: asString(raw.role, 40) || "generic",
|
|
119
|
+
type: asNullableString(raw.type, 40),
|
|
120
|
+
label: asString(raw.label, 300),
|
|
121
|
+
value: asNullableString(raw.value, 300),
|
|
122
|
+
placeholder: asNullableString(raw.placeholder, 300),
|
|
123
|
+
href: asNullableString(raw.href, 8e3),
|
|
124
|
+
disabled: asBoolean(raw.disabled, false),
|
|
125
|
+
checked: typeof raw.checked === "boolean" ? raw.checked : null,
|
|
126
|
+
readOnly: asBoolean(raw.readOnly, false),
|
|
127
|
+
sensitive: asBoolean(raw.sensitive, false),
|
|
128
|
+
editable: asBoolean(raw.editable, false),
|
|
129
|
+
...Array.isArray(raw.framePath) ? {
|
|
130
|
+
framePath: raw.framePath.slice(0, 3).map(
|
|
131
|
+
(index) => Math.max(0, Math.floor(Number(index) || 0))
|
|
132
|
+
)
|
|
133
|
+
} : {},
|
|
134
|
+
...raw.frameUrl !== void 0 ? {
|
|
135
|
+
frameUrl: raw.frameUrl === null ? null : asString(raw.frameUrl, 8e3)
|
|
136
|
+
} : {}
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
return elements;
|
|
140
|
+
}
|
|
103
141
|
function coerceRecord(value) {
|
|
104
142
|
const record = {};
|
|
105
143
|
if (!value || typeof value !== "object") return record;
|
|
@@ -145,11 +183,15 @@
|
|
|
145
183
|
const offset = Number.isFinite(requestedOffset) ? Math.max(0, Math.floor(requestedOffset)) : 0;
|
|
146
184
|
const format = normalizeFormat(options?.format);
|
|
147
185
|
const selector = typeof options?.selector === "string" && options.selector.trim() ? options.selector.trim() : null;
|
|
186
|
+
const refPrefix = typeof options?.refPrefix === "string" && REF_PREFIX_PATTERN.test(options.refPrefix) ? options.refPrefix : "";
|
|
148
187
|
return String.raw`
|
|
149
188
|
const maxChars = ${JSON.stringify(maxChars)};
|
|
150
189
|
const offset = ${JSON.stringify(offset)};
|
|
151
190
|
const format = ${JSON.stringify(format)};
|
|
152
191
|
const selector = ${JSON.stringify(selector)};
|
|
192
|
+
const refPrefix = ${JSON.stringify(refPrefix)};
|
|
193
|
+
const REF_ATTR = "data-zen-mcp-ref";
|
|
194
|
+
const MAX_ELEMENTS = ${MAX_PAGE_ELEMENTS};
|
|
153
195
|
const FENCE = String.fromCharCode(96, 96, 96);
|
|
154
196
|
const SENTINEL = "\u0000";
|
|
155
197
|
|
|
@@ -780,12 +822,269 @@ function safeCall(fn, fallback) {
|
|
|
780
822
|
}
|
|
781
823
|
}
|
|
782
824
|
|
|
825
|
+
function elementText(el) {
|
|
826
|
+
var text = "";
|
|
827
|
+
try {
|
|
828
|
+
text = el.innerText || el.textContent || "";
|
|
829
|
+
} catch (e) {}
|
|
830
|
+
return normalizeText(text).replace(/\n+/g, " ").slice(0, 200);
|
|
831
|
+
}
|
|
832
|
+
|
|
833
|
+
function elementLabel(el, tag, type) {
|
|
834
|
+
var label = "";
|
|
835
|
+
try {
|
|
836
|
+
label = String(el.getAttribute("aria-label") || "");
|
|
837
|
+
if (!label) {
|
|
838
|
+
var ids = String(el.getAttribute("aria-labelledby") || "").split(/\s+/);
|
|
839
|
+
var root = el.getRootNode ? el.getRootNode() : document;
|
|
840
|
+
for (var i = 0; i < ids.length && i < 4; i += 1) {
|
|
841
|
+
if (!ids[i]) continue;
|
|
842
|
+
var peer = null;
|
|
843
|
+
try {
|
|
844
|
+
peer = root.getElementById ? root.getElementById(ids[i]) : null;
|
|
845
|
+
} catch (e) {}
|
|
846
|
+
if (!peer) {
|
|
847
|
+
try {
|
|
848
|
+
peer = document.getElementById(ids[i]);
|
|
849
|
+
} catch (e2) {}
|
|
850
|
+
}
|
|
851
|
+
if (peer) label += " " + String(peer.innerText || peer.textContent || "");
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
} catch (e) {}
|
|
855
|
+
label = normalizeText(label);
|
|
856
|
+
if (!label) {
|
|
857
|
+
try {
|
|
858
|
+
if (el.labels && el.labels.length) {
|
|
859
|
+
var parts = [];
|
|
860
|
+
for (var l = 0; l < el.labels.length && l < 3; l += 1) {
|
|
861
|
+
parts.push(String(el.labels[l].innerText || el.labels[l].textContent || ""));
|
|
862
|
+
}
|
|
863
|
+
label = normalizeText(parts.join(" "));
|
|
864
|
+
}
|
|
865
|
+
} catch (e) {}
|
|
866
|
+
}
|
|
867
|
+
if (!label) {
|
|
868
|
+
if (tag === "input" && /^(submit|button|reset)$/.test(type || "")) {
|
|
869
|
+
label = String(el.value || "");
|
|
870
|
+
} else if (tag === "button" || tag === "a" || tag === "summary") {
|
|
871
|
+
label = elementText(el);
|
|
872
|
+
}
|
|
873
|
+
}
|
|
874
|
+
if (!label) {
|
|
875
|
+
label =
|
|
876
|
+
String(el.getAttribute("placeholder") || "") ||
|
|
877
|
+
String(el.getAttribute("title") || "") ||
|
|
878
|
+
String(el.getAttribute("alt") || "") ||
|
|
879
|
+
String(el.getAttribute("name") || "");
|
|
880
|
+
}
|
|
881
|
+
return normalizeText(label).replace(/\n+/g, " ").slice(0, 200);
|
|
882
|
+
}
|
|
883
|
+
|
|
884
|
+
function elementRole(el, tag, type) {
|
|
885
|
+
var explicit = "";
|
|
886
|
+
try {
|
|
887
|
+
explicit = String(el.getAttribute("role") || "").trim().toLowerCase();
|
|
888
|
+
} catch (e) {}
|
|
889
|
+
if (explicit) return explicit;
|
|
890
|
+
if (tag === "a" && el.hasAttribute("href")) return "link";
|
|
891
|
+
if (tag === "button" || tag === "summary") return "button";
|
|
892
|
+
if (tag === "textarea") return "textbox";
|
|
893
|
+
if (tag === "select") return el.multiple ? "listbox" : "combobox";
|
|
894
|
+
if (tag === "input") {
|
|
895
|
+
if (type === "checkbox") return "checkbox";
|
|
896
|
+
if (type === "radio") return "radio";
|
|
897
|
+
if (type === "range") return "slider";
|
|
898
|
+
if (
|
|
899
|
+
type === "submit" ||
|
|
900
|
+
type === "button" ||
|
|
901
|
+
type === "reset" ||
|
|
902
|
+
type === "image"
|
|
903
|
+
) {
|
|
904
|
+
return "button";
|
|
905
|
+
}
|
|
906
|
+
if (type === "search") return "searchbox";
|
|
907
|
+
if (type === "number") return "spinbutton";
|
|
908
|
+
return "textbox";
|
|
909
|
+
}
|
|
910
|
+
if (el.isContentEditable) return "textbox";
|
|
911
|
+
return "generic";
|
|
912
|
+
}
|
|
913
|
+
|
|
914
|
+
function isElementVisible(el) {
|
|
915
|
+
try {
|
|
916
|
+
var view = el.ownerDocument && el.ownerDocument.defaultView;
|
|
917
|
+
if (!view) return true;
|
|
918
|
+
var style = view.getComputedStyle(el);
|
|
919
|
+
if (
|
|
920
|
+
style &&
|
|
921
|
+
(style.display === "none" ||
|
|
922
|
+
style.visibility === "hidden" ||
|
|
923
|
+
style.visibility === "collapse")
|
|
924
|
+
) {
|
|
925
|
+
return false;
|
|
926
|
+
}
|
|
927
|
+
var rect = el.getBoundingClientRect();
|
|
928
|
+
if (rect && rect.width <= 0 && rect.height <= 0) return false;
|
|
929
|
+
} catch (e) {}
|
|
930
|
+
return true;
|
|
931
|
+
}
|
|
932
|
+
|
|
933
|
+
function elementHref(el) {
|
|
934
|
+
try {
|
|
935
|
+
var raw = el.getAttribute("href");
|
|
936
|
+
if (!raw) return null;
|
|
937
|
+
var url = new URL(raw, location.href);
|
|
938
|
+
if (url.protocol === "http:" || url.protocol === "https:") return url.href;
|
|
939
|
+
} catch (e) {}
|
|
940
|
+
return null;
|
|
941
|
+
}
|
|
942
|
+
|
|
943
|
+
function describeElement(el, ref) {
|
|
944
|
+
var tag = String(el.tagName || "").toLowerCase();
|
|
945
|
+
var type = tag === "input" ? String(el.type || "text").toLowerCase() : null;
|
|
946
|
+
var sensitive = tag === "input" && type === "password";
|
|
947
|
+
var editable = false;
|
|
948
|
+
if (tag === "textarea") {
|
|
949
|
+
editable = true;
|
|
950
|
+
} else if (tag === "input") {
|
|
951
|
+
editable = !/^(button|submit|reset|checkbox|radio|range|file|image|color|hidden)$/.test(
|
|
952
|
+
type || ""
|
|
953
|
+
);
|
|
954
|
+
} else if (el.isContentEditable) {
|
|
955
|
+
editable = true;
|
|
956
|
+
}
|
|
957
|
+
|
|
958
|
+
var value = null;
|
|
959
|
+
if (!sensitive) {
|
|
960
|
+
try {
|
|
961
|
+
if (tag === "select") {
|
|
962
|
+
var option = el.options && el.options[el.selectedIndex];
|
|
963
|
+
if (option) value = String(option.text || option.value || "").slice(0, 200);
|
|
964
|
+
} else if (tag === "input" && type !== "file") {
|
|
965
|
+
value = String(el.value || "").slice(0, 200);
|
|
966
|
+
}
|
|
967
|
+
} catch (e) {}
|
|
968
|
+
}
|
|
969
|
+
|
|
970
|
+
return {
|
|
971
|
+
ref: ref,
|
|
972
|
+
tag: tag,
|
|
973
|
+
role: elementRole(el, tag, type),
|
|
974
|
+
type: type,
|
|
975
|
+
label: elementLabel(el, tag, type),
|
|
976
|
+
value: value,
|
|
977
|
+
placeholder: safeCall(function () {
|
|
978
|
+
return el.getAttribute("placeholder") || null;
|
|
979
|
+
}, null),
|
|
980
|
+
href: elementHref(el),
|
|
981
|
+
disabled: !!el.disabled || el.getAttribute("aria-disabled") === "true",
|
|
982
|
+
checked: type === "checkbox" || type === "radio" ? !!el.checked : null,
|
|
983
|
+
readOnly: !!(el.readOnly || el.getAttribute("aria-readonly") === "true"),
|
|
984
|
+
sensitive: sensitive,
|
|
985
|
+
editable: editable
|
|
986
|
+
};
|
|
987
|
+
}
|
|
988
|
+
|
|
989
|
+
var INTERACTIVE_SELECTOR = [
|
|
990
|
+
"a[href]",
|
|
991
|
+
"button",
|
|
992
|
+
"input:not([type='hidden'])",
|
|
993
|
+
"textarea",
|
|
994
|
+
"select",
|
|
995
|
+
"summary",
|
|
996
|
+
"[contenteditable='']",
|
|
997
|
+
"[contenteditable='true']",
|
|
998
|
+
"[tabindex]:not([tabindex='-1'])",
|
|
999
|
+
"[role='button']",
|
|
1000
|
+
"[role='link']",
|
|
1001
|
+
"[role='checkbox']",
|
|
1002
|
+
"[role='radio']",
|
|
1003
|
+
"[role='switch']",
|
|
1004
|
+
"[role='tab']",
|
|
1005
|
+
"[role='menuitem']",
|
|
1006
|
+
"[role='menuitemcheckbox']",
|
|
1007
|
+
"[role='menuitemradio']",
|
|
1008
|
+
"[role='option']",
|
|
1009
|
+
"[role='combobox']",
|
|
1010
|
+
"[role='textbox']",
|
|
1011
|
+
"[role='searchbox']"
|
|
1012
|
+
].join(",");
|
|
1013
|
+
|
|
1014
|
+
function findCandidates(root, out) {
|
|
1015
|
+
if (!root || !root.querySelectorAll) return;
|
|
1016
|
+
var found = [];
|
|
1017
|
+
try {
|
|
1018
|
+
found = root.querySelectorAll(INTERACTIVE_SELECTOR);
|
|
1019
|
+
} catch (e) {}
|
|
1020
|
+
for (var i = 0; i < found.length; i += 1) {
|
|
1021
|
+
out.push(found[i]);
|
|
1022
|
+
}
|
|
1023
|
+
var all = [];
|
|
1024
|
+
try {
|
|
1025
|
+
all = root.querySelectorAll("*");
|
|
1026
|
+
} catch (e) {}
|
|
1027
|
+
for (var n = 0; n < all.length; n += 1) {
|
|
1028
|
+
if (all[n].shadowRoot) findCandidates(all[n].shadowRoot, out);
|
|
1029
|
+
}
|
|
1030
|
+
}
|
|
1031
|
+
|
|
1032
|
+
function clearElementRefs(root) {
|
|
1033
|
+
if (!root || !root.querySelectorAll) return;
|
|
1034
|
+
var tagged = [];
|
|
1035
|
+
try {
|
|
1036
|
+
tagged = root.querySelectorAll("[" + REF_ATTR + "]");
|
|
1037
|
+
} catch (e) {}
|
|
1038
|
+
for (var i = 0; i < tagged.length; i += 1) {
|
|
1039
|
+
try {
|
|
1040
|
+
tagged[i].removeAttribute(REF_ATTR);
|
|
1041
|
+
} catch (e) {}
|
|
1042
|
+
}
|
|
1043
|
+
var all = [];
|
|
1044
|
+
try {
|
|
1045
|
+
all = root.querySelectorAll("*");
|
|
1046
|
+
} catch (e) {}
|
|
1047
|
+
for (var n = 0; n < all.length; n += 1) {
|
|
1048
|
+
if (all[n].shadowRoot) clearElementRefs(all[n].shadowRoot);
|
|
1049
|
+
}
|
|
1050
|
+
}
|
|
1051
|
+
|
|
1052
|
+
function collectInteractive(root) {
|
|
1053
|
+
clearElementRefs(document);
|
|
1054
|
+
var candidates = [];
|
|
1055
|
+
findCandidates(root || document.body, candidates);
|
|
1056
|
+
var elements = [];
|
|
1057
|
+
var eligible = 0;
|
|
1058
|
+
for (var i = 0; i < candidates.length; i += 1) {
|
|
1059
|
+
var el = candidates[i];
|
|
1060
|
+
if (!el || !el.isConnected) continue;
|
|
1061
|
+
if (!isElementVisible(el)) continue;
|
|
1062
|
+
var tag = String(el.tagName || "").toLowerCase();
|
|
1063
|
+
if (tag === "input" && String(el.type || "").toLowerCase() === "hidden") {
|
|
1064
|
+
continue;
|
|
1065
|
+
}
|
|
1066
|
+
eligible += 1;
|
|
1067
|
+
if (elements.length >= MAX_ELEMENTS) continue;
|
|
1068
|
+
var localRef = "e" + (elements.length + 1);
|
|
1069
|
+
var ref = refPrefix + localRef;
|
|
1070
|
+
try {
|
|
1071
|
+
el.setAttribute(REF_ATTR, localRef);
|
|
1072
|
+
} catch (e) {
|
|
1073
|
+
continue;
|
|
1074
|
+
}
|
|
1075
|
+
elements.push(describeElement(el, ref));
|
|
1076
|
+
}
|
|
1077
|
+
return { elements: elements, truncated: eligible > elements.length };
|
|
1078
|
+
}
|
|
1079
|
+
|
|
783
1080
|
var selectorMatched = true;
|
|
784
1081
|
var root = null;
|
|
785
1082
|
try {
|
|
786
1083
|
if (selector) {
|
|
787
1084
|
root = document.querySelector(selector);
|
|
788
1085
|
if (!root) selectorMatched = false;
|
|
1086
|
+
} else if (format === "interactive") {
|
|
1087
|
+
root = document.body;
|
|
789
1088
|
} else {
|
|
790
1089
|
root = document.querySelector("article, main, [role='main']");
|
|
791
1090
|
}
|
|
@@ -832,6 +1131,9 @@ var visibleText = text.slice(appliedOffset, appliedOffset + maxChars);
|
|
|
832
1131
|
if (format === "markdown") {
|
|
833
1132
|
markdown = primarySource.slice(appliedOffset, appliedOffset + maxChars);
|
|
834
1133
|
}
|
|
1134
|
+
if (format === "interactive") {
|
|
1135
|
+
visibleText = "";
|
|
1136
|
+
}
|
|
835
1137
|
|
|
836
1138
|
var selectedText = "";
|
|
837
1139
|
try {
|
|
@@ -852,8 +1154,8 @@ var out = {
|
|
|
852
1154
|
url: String(location.href || ""),
|
|
853
1155
|
selectedText: selectedText,
|
|
854
1156
|
text: visibleText,
|
|
855
|
-
fullLength: primaryLength,
|
|
856
|
-
offset: appliedOffset,
|
|
1157
|
+
fullLength: format === "interactive" ? 0 : primaryLength,
|
|
1158
|
+
offset: format === "interactive" ? 0 : appliedOffset,
|
|
857
1159
|
readyState: String(document.readyState || ""),
|
|
858
1160
|
description: description || null,
|
|
859
1161
|
format: format,
|
|
@@ -887,11 +1189,331 @@ if (format === "markdown") {
|
|
|
887
1189
|
return buildOutline(root);
|
|
888
1190
|
}, []);
|
|
889
1191
|
if (outline) out.outline = outline;
|
|
1192
|
+
} else if (format === "interactive") {
|
|
1193
|
+
var interactive = safeCall(function () {
|
|
1194
|
+
return collectInteractive(root);
|
|
1195
|
+
}, null);
|
|
1196
|
+
if (interactive) {
|
|
1197
|
+
out.elements = interactive.elements;
|
|
1198
|
+
out.elementsTruncated = interactive.truncated;
|
|
1199
|
+
}
|
|
890
1200
|
}
|
|
891
1201
|
|
|
892
1202
|
return out;
|
|
893
1203
|
`;
|
|
894
1204
|
}
|
|
1205
|
+
function buildResolveTargetScript(options = {}) {
|
|
1206
|
+
const ref = typeof options.ref === "string" && options.ref.trim() ? options.ref.trim() : null;
|
|
1207
|
+
const selector = typeof options.selector === "string" && options.selector.trim() ? options.selector.trim() : null;
|
|
1208
|
+
return String.raw`
|
|
1209
|
+
const REF_ATTR = "data-zen-mcp-ref";
|
|
1210
|
+
const ref = ${JSON.stringify(ref)};
|
|
1211
|
+
const selector = ${JSON.stringify(selector)};
|
|
1212
|
+
|
|
1213
|
+
function normalizeText(value) {
|
|
1214
|
+
return String(value == null ? "" : value)
|
|
1215
|
+
.replace(/\s+/g, " ")
|
|
1216
|
+
.trim();
|
|
1217
|
+
}
|
|
1218
|
+
|
|
1219
|
+
function findByRef(root) {
|
|
1220
|
+
var match = null;
|
|
1221
|
+
try {
|
|
1222
|
+
match = root.querySelector("[" + REF_ATTR + "='" + ref + "']");
|
|
1223
|
+
} catch (e) {}
|
|
1224
|
+
if (match) return match;
|
|
1225
|
+
var all = [];
|
|
1226
|
+
try {
|
|
1227
|
+
all = root.querySelectorAll("*");
|
|
1228
|
+
} catch (e) {}
|
|
1229
|
+
for (var i = 0; i < all.length; i += 1) {
|
|
1230
|
+
var shadow = all[i].shadowRoot;
|
|
1231
|
+
if (!shadow) continue;
|
|
1232
|
+
var nested = findByRef(shadow);
|
|
1233
|
+
if (nested) return nested;
|
|
1234
|
+
}
|
|
1235
|
+
return null;
|
|
1236
|
+
}
|
|
1237
|
+
|
|
1238
|
+
function elementText(el) {
|
|
1239
|
+
var text = "";
|
|
1240
|
+
try {
|
|
1241
|
+
text = el.innerText || el.textContent || "";
|
|
1242
|
+
} catch (e) {}
|
|
1243
|
+
return normalizeText(text).slice(0, 200);
|
|
1244
|
+
}
|
|
1245
|
+
|
|
1246
|
+
function elementLabel(el, tag, type) {
|
|
1247
|
+
var label = "";
|
|
1248
|
+
try {
|
|
1249
|
+
label = String(el.getAttribute("aria-label") || "");
|
|
1250
|
+
if (!label) {
|
|
1251
|
+
var ids = String(el.getAttribute("aria-labelledby") || "").split(/\s+/);
|
|
1252
|
+
var root = el.getRootNode ? el.getRootNode() : document;
|
|
1253
|
+
for (var i = 0; i < ids.length && i < 4; i += 1) {
|
|
1254
|
+
if (!ids[i]) continue;
|
|
1255
|
+
var peer = null;
|
|
1256
|
+
try {
|
|
1257
|
+
peer = root.getElementById ? root.getElementById(ids[i]) : null;
|
|
1258
|
+
} catch (e) {}
|
|
1259
|
+
if (!peer) {
|
|
1260
|
+
try {
|
|
1261
|
+
peer = document.getElementById(ids[i]);
|
|
1262
|
+
} catch (e2) {}
|
|
1263
|
+
}
|
|
1264
|
+
if (peer) label += " " + String(peer.innerText || peer.textContent || "");
|
|
1265
|
+
}
|
|
1266
|
+
}
|
|
1267
|
+
} catch (e) {}
|
|
1268
|
+
label = normalizeText(label);
|
|
1269
|
+
if (!label) {
|
|
1270
|
+
try {
|
|
1271
|
+
if (el.labels && el.labels.length) {
|
|
1272
|
+
var parts = [];
|
|
1273
|
+
for (var l = 0; l < el.labels.length && l < 3; l += 1) {
|
|
1274
|
+
parts.push(String(el.labels[l].innerText || el.labels[l].textContent || ""));
|
|
1275
|
+
}
|
|
1276
|
+
label = normalizeText(parts.join(" "));
|
|
1277
|
+
}
|
|
1278
|
+
} catch (e) {}
|
|
1279
|
+
}
|
|
1280
|
+
if (!label) {
|
|
1281
|
+
if (tag === "input" && /^(submit|button|reset)$/.test(type || "")) {
|
|
1282
|
+
label = String(el.value || "");
|
|
1283
|
+
} else if (tag === "button" || tag === "a" || tag === "summary") {
|
|
1284
|
+
label = elementText(el);
|
|
1285
|
+
}
|
|
1286
|
+
}
|
|
1287
|
+
if (!label) {
|
|
1288
|
+
label =
|
|
1289
|
+
String(el.getAttribute("placeholder") || "") ||
|
|
1290
|
+
String(el.getAttribute("title") || "") ||
|
|
1291
|
+
String(el.getAttribute("alt") || "") ||
|
|
1292
|
+
String(el.getAttribute("name") || "");
|
|
1293
|
+
}
|
|
1294
|
+
return normalizeText(label).slice(0, 200);
|
|
1295
|
+
}
|
|
1296
|
+
|
|
1297
|
+
function elementRole(el, tag, type) {
|
|
1298
|
+
var explicit = "";
|
|
1299
|
+
try {
|
|
1300
|
+
explicit = String(el.getAttribute("role") || "").trim().toLowerCase();
|
|
1301
|
+
} catch (e) {}
|
|
1302
|
+
if (explicit) return explicit;
|
|
1303
|
+
if (tag === "a" && el.hasAttribute("href")) return "link";
|
|
1304
|
+
if (tag === "button" || tag === "summary") return "button";
|
|
1305
|
+
if (tag === "textarea") return "textbox";
|
|
1306
|
+
if (tag === "select") return el.multiple ? "listbox" : "combobox";
|
|
1307
|
+
if (tag === "input") {
|
|
1308
|
+
if (type === "checkbox") return "checkbox";
|
|
1309
|
+
if (type === "radio") return "radio";
|
|
1310
|
+
if (type === "range") return "slider";
|
|
1311
|
+
if (
|
|
1312
|
+
type === "submit" ||
|
|
1313
|
+
type === "button" ||
|
|
1314
|
+
type === "reset" ||
|
|
1315
|
+
type === "image"
|
|
1316
|
+
) {
|
|
1317
|
+
return "button";
|
|
1318
|
+
}
|
|
1319
|
+
if (type === "search") return "searchbox";
|
|
1320
|
+
if (type === "number") return "spinbutton";
|
|
1321
|
+
return "textbox";
|
|
1322
|
+
}
|
|
1323
|
+
if (el.isContentEditable) return "textbox";
|
|
1324
|
+
return "generic";
|
|
1325
|
+
}
|
|
1326
|
+
|
|
1327
|
+
function elementHref(el) {
|
|
1328
|
+
try {
|
|
1329
|
+
var raw = el.getAttribute("href");
|
|
1330
|
+
if (!raw) return null;
|
|
1331
|
+
var url = new URL(raw, location.href);
|
|
1332
|
+
if (url.protocol === "http:" || url.protocol === "https:") return url.href;
|
|
1333
|
+
} catch (e) {}
|
|
1334
|
+
return null;
|
|
1335
|
+
}
|
|
1336
|
+
|
|
1337
|
+
var found = null;
|
|
1338
|
+
try {
|
|
1339
|
+
found = ref ? findByRef(document) : selector ? document.querySelector(selector) : null;
|
|
1340
|
+
} catch (e) {
|
|
1341
|
+
found = null;
|
|
1342
|
+
}
|
|
1343
|
+
if (!found) {
|
|
1344
|
+
return { found: false };
|
|
1345
|
+
}
|
|
1346
|
+
|
|
1347
|
+
var tag = String(found.tagName || "").toLowerCase();
|
|
1348
|
+
var type = tag === "input" ? String(found.type || "text").toLowerCase() : null;
|
|
1349
|
+
var editable = false;
|
|
1350
|
+
if (tag === "textarea") {
|
|
1351
|
+
editable = true;
|
|
1352
|
+
} else if (tag === "input") {
|
|
1353
|
+
editable = !/^(button|submit|reset|checkbox|radio|range|file|image|color|hidden)$/.test(
|
|
1354
|
+
type || ""
|
|
1355
|
+
);
|
|
1356
|
+
} else if (found.isContentEditable) {
|
|
1357
|
+
editable = true;
|
|
1358
|
+
}
|
|
1359
|
+
|
|
1360
|
+
return {
|
|
1361
|
+
found: true,
|
|
1362
|
+
element: found,
|
|
1363
|
+
tag: tag,
|
|
1364
|
+
role: elementRole(found, tag, type),
|
|
1365
|
+
type: type,
|
|
1366
|
+
label: elementLabel(found, tag, type),
|
|
1367
|
+
href: elementHref(found),
|
|
1368
|
+
disabled: !!found.disabled || found.getAttribute("aria-disabled") === "true",
|
|
1369
|
+
readOnly: !!(
|
|
1370
|
+
found.readOnly || found.getAttribute("aria-readonly") === "true"
|
|
1371
|
+
),
|
|
1372
|
+
sensitive: tag === "input" && type === "password",
|
|
1373
|
+
editable: editable
|
|
1374
|
+
};
|
|
1375
|
+
`;
|
|
1376
|
+
}
|
|
1377
|
+
function buildWaitProbeScript(options = {}) {
|
|
1378
|
+
const selector = typeof options.selector === "string" && options.selector.trim() ? options.selector.trim() : null;
|
|
1379
|
+
const text = typeof options.text === "string" && options.text.trim() ? options.text.trim() : null;
|
|
1380
|
+
const urlContains = typeof options.urlContains === "string" && options.urlContains.trim() ? options.urlContains.trim() : null;
|
|
1381
|
+
const titleContains = typeof options.titleContains === "string" && options.titleContains.trim() ? options.titleContains.trim() : null;
|
|
1382
|
+
return String.raw`
|
|
1383
|
+
const selector = ${JSON.stringify(selector)};
|
|
1384
|
+
const text = ${JSON.stringify(text)};
|
|
1385
|
+
const urlContains = ${JSON.stringify(urlContains)};
|
|
1386
|
+
const titleContains = ${JSON.stringify(titleContains)};
|
|
1387
|
+
|
|
1388
|
+
var url = "";
|
|
1389
|
+
try {
|
|
1390
|
+
url = String(location.href || "");
|
|
1391
|
+
} catch (e) {}
|
|
1392
|
+
var title = "";
|
|
1393
|
+
try {
|
|
1394
|
+
title = String(document.title || "");
|
|
1395
|
+
} catch (e) {}
|
|
1396
|
+
var readyState = "";
|
|
1397
|
+
try {
|
|
1398
|
+
readyState = String(document.readyState || "");
|
|
1399
|
+
} catch (e) {}
|
|
1400
|
+
|
|
1401
|
+
var matched = false;
|
|
1402
|
+
if (selector) {
|
|
1403
|
+
try {
|
|
1404
|
+
matched = !!document.querySelector(selector);
|
|
1405
|
+
} catch (e) {
|
|
1406
|
+
matched = false;
|
|
1407
|
+
}
|
|
1408
|
+
} else if (text) {
|
|
1409
|
+
var needle = text.toLowerCase();
|
|
1410
|
+
try {
|
|
1411
|
+
var body = document.body;
|
|
1412
|
+
var haystack = body
|
|
1413
|
+
? String(body.innerText || body.textContent || "")
|
|
1414
|
+
: "";
|
|
1415
|
+
matched = haystack.toLowerCase().indexOf(needle) >= 0;
|
|
1416
|
+
} catch (e) {
|
|
1417
|
+
matched = false;
|
|
1418
|
+
}
|
|
1419
|
+
} else if (urlContains) {
|
|
1420
|
+
matched = url.toLowerCase().indexOf(urlContains.toLowerCase()) >= 0;
|
|
1421
|
+
} else if (titleContains) {
|
|
1422
|
+
matched = title.toLowerCase().indexOf(titleContains.toLowerCase()) >= 0;
|
|
1423
|
+
}
|
|
1424
|
+
|
|
1425
|
+
return {
|
|
1426
|
+
url: url,
|
|
1427
|
+
title: title,
|
|
1428
|
+
readyState: readyState,
|
|
1429
|
+
matched: matched
|
|
1430
|
+
};
|
|
1431
|
+
`;
|
|
1432
|
+
}
|
|
1433
|
+
function coerceWaitProbe(value) {
|
|
1434
|
+
if (!value || typeof value !== "object") return null;
|
|
1435
|
+
const raw = value;
|
|
1436
|
+
if (typeof raw.url !== "string") return null;
|
|
1437
|
+
return {
|
|
1438
|
+
url: raw.url.slice(0, 8e3),
|
|
1439
|
+
title: asString(raw.title, 1e3),
|
|
1440
|
+
readyState: asString(raw.readyState, 40),
|
|
1441
|
+
matched: raw.matched === true
|
|
1442
|
+
};
|
|
1443
|
+
}
|
|
1444
|
+
function buildPageSignatureScript() {
|
|
1445
|
+
return String.raw`
|
|
1446
|
+
const MAX_TEXT = 200000;
|
|
1447
|
+
|
|
1448
|
+
function hashString(value) {
|
|
1449
|
+
var hash = 2166136261;
|
|
1450
|
+
var text = String(value == null ? "" : value);
|
|
1451
|
+
for (var i = 0; i < text.length; i += 1) {
|
|
1452
|
+
hash ^= text.charCodeAt(i);
|
|
1453
|
+
hash = Math.imul(hash, 16777619);
|
|
1454
|
+
}
|
|
1455
|
+
return hash >>> 0;
|
|
1456
|
+
}
|
|
1457
|
+
|
|
1458
|
+
var body = null;
|
|
1459
|
+
try {
|
|
1460
|
+
body = document.body;
|
|
1461
|
+
} catch (e) {}
|
|
1462
|
+
var rawText = body ? String(body.textContent || "") : "";
|
|
1463
|
+
var values = [];
|
|
1464
|
+
try {
|
|
1465
|
+
var controls = document.querySelectorAll("input, textarea, select");
|
|
1466
|
+
for (var i = 0; i < controls.length && i < 200; i += 1) {
|
|
1467
|
+
var control = controls[i];
|
|
1468
|
+
var type = String(control.type || "").toLowerCase();
|
|
1469
|
+
if (type === "password" || type === "file") continue;
|
|
1470
|
+
values.push(
|
|
1471
|
+
String(control.name || control.id || "") +
|
|
1472
|
+
"=" +
|
|
1473
|
+
String(control.value == null ? "" : control.value)
|
|
1474
|
+
);
|
|
1475
|
+
}
|
|
1476
|
+
} catch (e) {}
|
|
1477
|
+
|
|
1478
|
+
return {
|
|
1479
|
+
url: String(location.href || ""),
|
|
1480
|
+
title: String(document.title || ""),
|
|
1481
|
+
readyState: String(document.readyState || ""),
|
|
1482
|
+
textLength: rawText.length,
|
|
1483
|
+
textHash: hashString(rawText.slice(0, MAX_TEXT)),
|
|
1484
|
+
elementCount: document.querySelectorAll("*").length,
|
|
1485
|
+
valueHash: hashString(values.join("\u0001"))
|
|
1486
|
+
};
|
|
1487
|
+
`;
|
|
1488
|
+
}
|
|
1489
|
+
function coercePageSignature(value) {
|
|
1490
|
+
if (!value || typeof value !== "object") return null;
|
|
1491
|
+
const raw = value;
|
|
1492
|
+
if (typeof raw.url !== "string") return null;
|
|
1493
|
+
const number = (input) => typeof input === "number" && Number.isFinite(input) ? Math.max(0, Math.floor(input)) : Number(input) || 0;
|
|
1494
|
+
return {
|
|
1495
|
+
url: raw.url.slice(0, 8e3),
|
|
1496
|
+
title: asString(raw.title, 1e3),
|
|
1497
|
+
readyState: asString(raw.readyState, 40),
|
|
1498
|
+
textLength: number(raw.textLength),
|
|
1499
|
+
textHash: number(raw.textHash),
|
|
1500
|
+
elementCount: number(raw.elementCount),
|
|
1501
|
+
valueHash: number(raw.valueHash)
|
|
1502
|
+
};
|
|
1503
|
+
}
|
|
1504
|
+
function comparePageSignatures(before, after) {
|
|
1505
|
+
const urlChanged = before.url !== after.url;
|
|
1506
|
+
const titleChanged = before.title !== after.title;
|
|
1507
|
+
const valueChanged = before.valueHash !== after.valueHash;
|
|
1508
|
+
const domChanged = before.textLength !== after.textLength || before.textHash !== after.textHash || before.elementCount !== after.elementCount || before.readyState !== after.readyState;
|
|
1509
|
+
return {
|
|
1510
|
+
changed: urlChanged || titleChanged || domChanged || valueChanged,
|
|
1511
|
+
urlChanged,
|
|
1512
|
+
titleChanged,
|
|
1513
|
+
domChanged,
|
|
1514
|
+
valueChanged
|
|
1515
|
+
};
|
|
1516
|
+
}
|
|
895
1517
|
function coercePageSnapshot(value) {
|
|
896
1518
|
if (!value || typeof value !== "object") return null;
|
|
897
1519
|
const raw = value;
|
|
@@ -931,8 +1553,15 @@ return out;
|
|
|
931
1553
|
if (Array.isArray(raw.outline)) {
|
|
932
1554
|
snapshot.outline = coerceHeadings(raw.outline);
|
|
933
1555
|
}
|
|
1556
|
+
if (Array.isArray(raw.elements)) {
|
|
1557
|
+
snapshot.elements = coerceElements(raw.elements);
|
|
1558
|
+
snapshot.elementsTruncated = raw.elementsTruncated === true;
|
|
1559
|
+
}
|
|
934
1560
|
return snapshot;
|
|
935
1561
|
}
|
|
1562
|
+
function joinLimitations(existing, addition) {
|
|
1563
|
+
return existing ? `${existing} ${addition}` : addition;
|
|
1564
|
+
}
|
|
936
1565
|
function toPageReadResult(page, options = {}) {
|
|
937
1566
|
const format = normalizeFormat(page?.format);
|
|
938
1567
|
const structured = format !== "text" && format !== "markdown";
|
|
@@ -947,7 +1576,7 @@ return out;
|
|
|
947
1576
|
const rawOffset = Number(page?.offset);
|
|
948
1577
|
const appliedOffset = structured ? 0 : Number.isFinite(rawOffset) ? Math.min(fullLength, Math.max(0, Math.floor(rawOffset))) : 0;
|
|
949
1578
|
const nextOffset = !structured && primary > 0 && appliedOffset + primary < fullLength ? appliedOffset + primary : null;
|
|
950
|
-
const truncated = structured ? maxChars !== null ? fullLength > maxChars : fullLength > primary : nextOffset !== null;
|
|
1579
|
+
const truncated = (structured ? maxChars !== null ? fullLength > maxChars : fullLength > primary : nextOffset !== null) || page?.elementsTruncated === true;
|
|
951
1580
|
const requestedOffset = Math.max(
|
|
952
1581
|
0,
|
|
953
1582
|
Math.floor(Number(options?.offset) || 0)
|
|
@@ -993,8 +1622,43 @@ return out;
|
|
|
993
1622
|
text: String(heading?.text ?? "")
|
|
994
1623
|
}));
|
|
995
1624
|
}
|
|
1625
|
+
if (Array.isArray(page?.elements)) {
|
|
1626
|
+
result.elements = page.elements.map((element) => ({
|
|
1627
|
+
ref: String(element?.ref ?? ""),
|
|
1628
|
+
tag: String(element?.tag ?? ""),
|
|
1629
|
+
role: String(element?.role ?? "generic"),
|
|
1630
|
+
type: element?.type ?? null,
|
|
1631
|
+
label: String(element?.label ?? ""),
|
|
1632
|
+
value: element?.value ?? null,
|
|
1633
|
+
placeholder: element?.placeholder ?? null,
|
|
1634
|
+
href: element?.href ?? null,
|
|
1635
|
+
disabled: element?.disabled === true,
|
|
1636
|
+
checked: typeof element?.checked === "boolean" ? element.checked : null,
|
|
1637
|
+
readOnly: element?.readOnly === true,
|
|
1638
|
+
sensitive: element?.sensitive === true,
|
|
1639
|
+
editable: element?.editable === true,
|
|
1640
|
+
...Array.isArray(element?.framePath) ? {
|
|
1641
|
+
framePath: element.framePath.map(
|
|
1642
|
+
(index) => Math.max(0, Math.floor(Number(index) || 0))
|
|
1643
|
+
)
|
|
1644
|
+
} : {},
|
|
1645
|
+
...element?.frameUrl !== void 0 ? {
|
|
1646
|
+
frameUrl: element.frameUrl === null ? null : String(element.frameUrl)
|
|
1647
|
+
} : {}
|
|
1648
|
+
}));
|
|
1649
|
+
if (page.elementsTruncated === true) {
|
|
1650
|
+
result.elementsTruncated = true;
|
|
1651
|
+
result.limitation = joinLimitations(
|
|
1652
|
+
result.limitation,
|
|
1653
|
+
"The interactive scan reached its element cap. Narrow it with selector to see the rest."
|
|
1654
|
+
);
|
|
1655
|
+
}
|
|
1656
|
+
}
|
|
996
1657
|
if (structured && requestedOffset > 0) {
|
|
997
|
-
result.limitation =
|
|
1658
|
+
result.limitation = joinLimitations(
|
|
1659
|
+
result.limitation,
|
|
1660
|
+
`offset is only supported for text and markdown reads. This ${format} read ignored offset=${requestedOffset} and returned the complete ${format} data.`
|
|
1661
|
+
);
|
|
998
1662
|
}
|
|
999
1663
|
return result;
|
|
1000
1664
|
}
|
|
@@ -2246,6 +2910,32 @@ return { cleared: removed > 0, removed: removed };
|
|
|
2246
2910
|
return Math.min(maximum, Math.max(minimum, value));
|
|
2247
2911
|
}
|
|
2248
2912
|
|
|
2913
|
+
// src/shared/frame-path.ts
|
|
2914
|
+
var MAX_FRAME_DEPTH = 3;
|
|
2915
|
+
var ACTION_REF_PATTERN = /^(?:f([0-9]+(?:\.[0-9]+){0,2})-)?(e[0-9]{1,4})$/;
|
|
2916
|
+
function parseFrameRef(value) {
|
|
2917
|
+
if (typeof value !== "string") return null;
|
|
2918
|
+
const match = ACTION_REF_PATTERN.exec(value);
|
|
2919
|
+
if (!match) return null;
|
|
2920
|
+
const path = match[1] ? match[1].split(".").map(Number) : [];
|
|
2921
|
+
if (path.length > MAX_FRAME_DEPTH) return null;
|
|
2922
|
+
return { path, ref: match[2] };
|
|
2923
|
+
}
|
|
2924
|
+
function frameRefPrefix(path) {
|
|
2925
|
+
return path.length ? `f${path.join(".")}-` : "";
|
|
2926
|
+
}
|
|
2927
|
+
function normalizeFramePath(value) {
|
|
2928
|
+
if (value === void 0 || value === null) return [];
|
|
2929
|
+
if (!Array.isArray(value) || value.length > MAX_FRAME_DEPTH) return null;
|
|
2930
|
+
const path = [];
|
|
2931
|
+
for (const entry of value) {
|
|
2932
|
+
const index = Number(entry);
|
|
2933
|
+
if (!Number.isInteger(index) || index < 0) return null;
|
|
2934
|
+
path.push(index);
|
|
2935
|
+
}
|
|
2936
|
+
return path;
|
|
2937
|
+
}
|
|
2938
|
+
|
|
2249
2939
|
// src/shared/search.ts
|
|
2250
2940
|
var DEFAULT_MAX_MATCHES = 20;
|
|
2251
2941
|
var MAX_MATCHES = 50;
|
|
@@ -2721,6 +3411,18 @@ return { cleared: removed > 0, removed: removed };
|
|
|
2721
3411
|
var LAYOUT_SETTLE_MS = 120;
|
|
2722
3412
|
var SPLIT_CLOSE_TIMEOUT_MS = 1e3;
|
|
2723
3413
|
var SPLIT_CLOSE_POLL_MS = 100;
|
|
3414
|
+
var MAX_FRAMES = 20;
|
|
3415
|
+
var MAX_FRAME_SCANS = 10;
|
|
3416
|
+
var ACTION_SETTLE_MS = 1200;
|
|
3417
|
+
var ACTION_PROBE_INTERVAL_MS = 120;
|
|
3418
|
+
var ACTION_PROBE_TIMEOUT_MS = 2500;
|
|
3419
|
+
var SIGNATURE_BEFORE_TIMEOUT_MS = 1500;
|
|
3420
|
+
var WAIT_TIMEOUT_MS = 5e3;
|
|
3421
|
+
var WAIT_POLL_MS = 250;
|
|
3422
|
+
var WAIT_MAX_TIMEOUT_MS = 3e4;
|
|
3423
|
+
var WAIT_MIN_POLL_MS = 100;
|
|
3424
|
+
var WAIT_MAX_POLL_MS = 2e3;
|
|
3425
|
+
var WAIT_PROBE_TIMEOUT_MS = 2500;
|
|
2724
3426
|
function isHttpUrl(url) {
|
|
2725
3427
|
try {
|
|
2726
3428
|
const scheme = new URL(url).protocol;
|
|
@@ -3239,34 +3941,317 @@ return { cleared: removed > 0, removed: removed };
|
|
|
3239
3941
|
);
|
|
3240
3942
|
}
|
|
3241
3943
|
};
|
|
3242
|
-
const
|
|
3243
|
-
|
|
3244
|
-
|
|
3245
|
-
|
|
3246
|
-
|
|
3247
|
-
|
|
3248
|
-
|
|
3249
|
-
|
|
3250
|
-
|
|
3251
|
-
|
|
3252
|
-
|
|
3253
|
-
|
|
3254
|
-
|
|
3255
|
-
|
|
3256
|
-
|
|
3257
|
-
|
|
3258
|
-
|
|
3259
|
-
|
|
3260
|
-
|
|
3261
|
-
|
|
3262
|
-
|
|
3263
|
-
|
|
3264
|
-
|
|
3265
|
-
|
|
3266
|
-
|
|
3267
|
-
|
|
3268
|
-
|
|
3269
|
-
|
|
3944
|
+
const pageActor = (tab) => {
|
|
3945
|
+
const global = tab.linkedBrowser?.browsingContext?.currentWindowGlobal;
|
|
3946
|
+
if (!global) {
|
|
3947
|
+
throw new OpsError(
|
|
3948
|
+
"tab_not_loaded",
|
|
3949
|
+
`The tab "${tabTitle(tab)}" has no loaded page yet. Wait for it to finish loading, then try again.`
|
|
3950
|
+
);
|
|
3951
|
+
}
|
|
3952
|
+
const actor = typeof global.getActor === "function" ? global.getActor("MarionetteCommands") : null;
|
|
3953
|
+
if (!actor) {
|
|
3954
|
+
throw new OpsError(
|
|
3955
|
+
"actor_unavailable",
|
|
3956
|
+
"Zen MCP's Marionette session does not expose page interaction in this window. Restart Zen with zen_launch."
|
|
3957
|
+
);
|
|
3958
|
+
}
|
|
3959
|
+
return actor;
|
|
3960
|
+
};
|
|
3961
|
+
const actorForContext = (context) => {
|
|
3962
|
+
const global = context?.currentWindowGlobal;
|
|
3963
|
+
if (!global) return null;
|
|
3964
|
+
return typeof global.getActor === "function" ? global.getActor("MarionetteCommands") : null;
|
|
3965
|
+
};
|
|
3966
|
+
const childFrameContexts = (context) => {
|
|
3967
|
+
try {
|
|
3968
|
+
return Array.from(context?.children ?? []);
|
|
3969
|
+
} catch {
|
|
3970
|
+
return [];
|
|
3971
|
+
}
|
|
3972
|
+
};
|
|
3973
|
+
const frameUrlOfContext = (context) => {
|
|
3974
|
+
try {
|
|
3975
|
+
const spec = context?.currentWindowGlobal?.documentURI?.spec;
|
|
3976
|
+
if (typeof spec === "string") return spec;
|
|
3977
|
+
} catch {
|
|
3978
|
+
}
|
|
3979
|
+
return "";
|
|
3980
|
+
};
|
|
3981
|
+
const frameNameOfContext = (context) => {
|
|
3982
|
+
try {
|
|
3983
|
+
return String(context?.name ?? "");
|
|
3984
|
+
} catch {
|
|
3985
|
+
return "";
|
|
3986
|
+
}
|
|
3987
|
+
};
|
|
3988
|
+
const frameIsVisible = (url, allowedDomains) => {
|
|
3989
|
+
if (!isHttpUrl(url)) return false;
|
|
3990
|
+
return !allowedDomains?.length || isUrlAllowed(url, allowedDomains);
|
|
3991
|
+
};
|
|
3992
|
+
const requireFramePath = (raw) => {
|
|
3993
|
+
const path = normalizeFramePath(raw);
|
|
3994
|
+
if (!path) {
|
|
3995
|
+
throw new OpsError(
|
|
3996
|
+
"invalid_frame",
|
|
3997
|
+
`framePath must be an array of at most ${MAX_FRAME_DEPTH} non-negative child frame indexes, such as [0] or [0,1].`
|
|
3998
|
+
);
|
|
3999
|
+
}
|
|
4000
|
+
return path;
|
|
4001
|
+
};
|
|
4002
|
+
const listFrames = (tab, allowedDomains) => {
|
|
4003
|
+
const frames = [];
|
|
4004
|
+
let skipped = 0;
|
|
4005
|
+
let truncated = false;
|
|
4006
|
+
const root = tab.linkedBrowser?.browsingContext;
|
|
4007
|
+
const walk = (context, prefix) => {
|
|
4008
|
+
for (const [index, child] of childFrameContexts(context).entries()) {
|
|
4009
|
+
if (frames.length >= MAX_FRAMES) {
|
|
4010
|
+
truncated = true;
|
|
4011
|
+
return;
|
|
4012
|
+
}
|
|
4013
|
+
const path = [...prefix, index];
|
|
4014
|
+
const url = frameUrlOfContext(child);
|
|
4015
|
+
if (!frameIsVisible(url, allowedDomains)) {
|
|
4016
|
+
skipped += 1;
|
|
4017
|
+
continue;
|
|
4018
|
+
}
|
|
4019
|
+
frames.push({ path, url, name: frameNameOfContext(child) });
|
|
4020
|
+
if (path.length < MAX_FRAME_DEPTH) walk(child, path);
|
|
4021
|
+
}
|
|
4022
|
+
};
|
|
4023
|
+
if (root) walk(root, []);
|
|
4024
|
+
return { frames, skipped, truncated };
|
|
4025
|
+
};
|
|
4026
|
+
const resolveFrame = (tab, path, allowedDomains) => {
|
|
4027
|
+
let context = tab.linkedBrowser?.browsingContext;
|
|
4028
|
+
if (!context) {
|
|
4029
|
+
throw new OpsError(
|
|
4030
|
+
"tab_not_loaded",
|
|
4031
|
+
`The tab "${tabTitle(tab)}" has no loaded page yet.`
|
|
4032
|
+
);
|
|
4033
|
+
}
|
|
4034
|
+
for (let depth = 0; depth < path.length; depth += 1) {
|
|
4035
|
+
const index = path[depth];
|
|
4036
|
+
const children = childFrameContexts(context);
|
|
4037
|
+
if (index >= children.length) {
|
|
4038
|
+
throw new OpsError(
|
|
4039
|
+
"frame_not_found",
|
|
4040
|
+
`Frame path [${path.join(", ")}] does not exist: the document at level ${depth} has ${children.length} child frame(s).`
|
|
4041
|
+
);
|
|
4042
|
+
}
|
|
4043
|
+
context = children[index];
|
|
4044
|
+
}
|
|
4045
|
+
const url = frameUrlOfContext(context);
|
|
4046
|
+
if (!url) {
|
|
4047
|
+
throw new OpsError(
|
|
4048
|
+
"frame_not_loaded",
|
|
4049
|
+
`The frame at [${path.join(", ")}] has not loaded a page yet.`
|
|
4050
|
+
);
|
|
4051
|
+
}
|
|
4052
|
+
if (!isHttpUrl(url)) {
|
|
4053
|
+
throw new OpsError(
|
|
4054
|
+
"unsupported_frame",
|
|
4055
|
+
`Zen MCP only reads and drives http(s) frames. This frame is ${isPrivilegedUrl(url) ? "browser-internal" : "not a web page"}.`
|
|
4056
|
+
);
|
|
4057
|
+
}
|
|
4058
|
+
assertActionUrlAllowed(url, allowedDomains, "reading frame");
|
|
4059
|
+
const actor = actorForContext(context);
|
|
4060
|
+
if (!actor) {
|
|
4061
|
+
throw new OpsError(
|
|
4062
|
+
"actor_unavailable",
|
|
4063
|
+
"Zen MCP's Marionette session does not expose page interaction in this frame. Restart Zen with zen_launch."
|
|
4064
|
+
);
|
|
4065
|
+
}
|
|
4066
|
+
return { actor, path: [...path], url, name: frameNameOfContext(context) };
|
|
4067
|
+
};
|
|
4068
|
+
const currentFrameUrl = (tab, path) => {
|
|
4069
|
+
let context = tab.linkedBrowser?.browsingContext;
|
|
4070
|
+
for (const index of path) {
|
|
4071
|
+
if (!context) return null;
|
|
4072
|
+
context = childFrameContexts(context)[index];
|
|
4073
|
+
}
|
|
4074
|
+
return frameUrlOfContext(context) || null;
|
|
4075
|
+
};
|
|
4076
|
+
const requireActionTab = (tabId, action) => {
|
|
4077
|
+
if (!tabId) {
|
|
4078
|
+
throw new OpsError("no_tab", `Provide the tabId to ${action}.`);
|
|
4079
|
+
}
|
|
4080
|
+
const [tab] = resolveTabs([tabId]);
|
|
4081
|
+
const url = tabUrl(tab);
|
|
4082
|
+
if (!isHttpUrl(url)) {
|
|
4083
|
+
throw new OpsError(
|
|
4084
|
+
isPrivilegedUrl(url) ? "privileged_page" : "unsupported_page",
|
|
4085
|
+
"Zen MCP only interacts with http(s) pages. Browser-internal and local-file pages are never driven."
|
|
4086
|
+
);
|
|
4087
|
+
}
|
|
4088
|
+
if (isPdfTab(tab)) {
|
|
4089
|
+
throw new OpsError(
|
|
4090
|
+
"unsupported_page",
|
|
4091
|
+
"Zen MCP cannot click or type inside the PDF viewer. Open the page as HTML instead."
|
|
4092
|
+
);
|
|
4093
|
+
}
|
|
4094
|
+
return tab;
|
|
4095
|
+
};
|
|
4096
|
+
const assertActionUrlAllowed = (url, allowedDomains, action) => {
|
|
4097
|
+
if (!url || !allowedDomains?.length) return;
|
|
4098
|
+
if (isUrlAllowed(url, allowedDomains)) return;
|
|
4099
|
+
throw new OpsError(
|
|
4100
|
+
"domain_not_allowed",
|
|
4101
|
+
`Blocked by domain allowlist: ${action} ${url} is outside the configured domains.`
|
|
4102
|
+
);
|
|
4103
|
+
};
|
|
4104
|
+
const resolvePageTarget = async (tab, params, allowedDomains) => {
|
|
4105
|
+
const ref = typeof params?.ref === "string" ? params.ref.trim() : "";
|
|
4106
|
+
const selector = typeof params?.selector === "string" ? params.selector.trim() : "";
|
|
4107
|
+
if (!ref === !selector) {
|
|
4108
|
+
throw new OpsError(
|
|
4109
|
+
"invalid_target",
|
|
4110
|
+
"Provide exactly one of ref or selector."
|
|
4111
|
+
);
|
|
4112
|
+
}
|
|
4113
|
+
const parsed = ref ? parseFrameRef(ref) : null;
|
|
4114
|
+
if (ref && !parsed) {
|
|
4115
|
+
throw new OpsError(
|
|
4116
|
+
"invalid_target",
|
|
4117
|
+
`"${ref}" is not an interactive-read ref. Use a value such as "e1", "f0-e3" for a child frame, or "f0.1-e2" for a nested frame.`
|
|
4118
|
+
);
|
|
4119
|
+
}
|
|
4120
|
+
if (selector.length > 500) {
|
|
4121
|
+
throw new OpsError(
|
|
4122
|
+
"invalid_target",
|
|
4123
|
+
"selector must be 500 characters or fewer."
|
|
4124
|
+
);
|
|
4125
|
+
}
|
|
4126
|
+
const frame = parsed?.path.length ? resolveFrame(tab, parsed.path, allowedDomains) : null;
|
|
4127
|
+
const actor = frame?.actor ?? pageActor(tab);
|
|
4128
|
+
let raw;
|
|
4129
|
+
try {
|
|
4130
|
+
raw = await actor.sendQuery("MarionetteCommandsParent:executeScript", {
|
|
4131
|
+
script: buildResolveTargetScript({
|
|
4132
|
+
...parsed ? { ref: parsed.ref } : {},
|
|
4133
|
+
...selector ? { selector } : {}
|
|
4134
|
+
}),
|
|
4135
|
+
args: [],
|
|
4136
|
+
opts: { timeout: 1e4 }
|
|
4137
|
+
});
|
|
4138
|
+
} catch (error) {
|
|
4139
|
+
throw new OpsError(
|
|
4140
|
+
"element_not_found",
|
|
4141
|
+
`Could not resolve the target: ${String(
|
|
4142
|
+
error?.message ?? error
|
|
4143
|
+
)}`
|
|
4144
|
+
);
|
|
4145
|
+
}
|
|
4146
|
+
const target = raw;
|
|
4147
|
+
if (!target || target.found !== true || !target.element) {
|
|
4148
|
+
throw new OpsError(
|
|
4149
|
+
"element_not_found",
|
|
4150
|
+
ref ? `No element has ref "${ref}". Call zen_read_page with format="interactive" again; refs expire after another interactive read or a navigation.` : `No element matches selector "${selector}".`
|
|
4151
|
+
);
|
|
4152
|
+
}
|
|
4153
|
+
return {
|
|
4154
|
+
target,
|
|
4155
|
+
actor,
|
|
4156
|
+
framePath: frame?.path ?? [],
|
|
4157
|
+
frameUrl: frame?.url ?? null
|
|
4158
|
+
};
|
|
4159
|
+
};
|
|
4160
|
+
const actionTarget = (target) => ({
|
|
4161
|
+
tag: String(target.tag ?? ""),
|
|
4162
|
+
role: String(target.role ?? "generic"),
|
|
4163
|
+
label: String(target.label ?? ""),
|
|
4164
|
+
type: typeof target.type === "string" ? target.type : null,
|
|
4165
|
+
sensitive: target.sensitive === true
|
|
4166
|
+
});
|
|
4167
|
+
const clickCapabilities = {
|
|
4168
|
+
"moz:accessibilityChecks": false,
|
|
4169
|
+
"moz:webdriverClick": true
|
|
4170
|
+
};
|
|
4171
|
+
const captureSignature = async (actor, timeoutMs) => {
|
|
4172
|
+
try {
|
|
4173
|
+
const raw = await actor.sendQuery(
|
|
4174
|
+
"MarionetteCommandsParent:executeScript",
|
|
4175
|
+
{
|
|
4176
|
+
script: buildPageSignatureScript(),
|
|
4177
|
+
args: [],
|
|
4178
|
+
opts: { timeout: timeoutMs }
|
|
4179
|
+
}
|
|
4180
|
+
);
|
|
4181
|
+
return coercePageSignature(raw);
|
|
4182
|
+
} catch {
|
|
4183
|
+
return null;
|
|
4184
|
+
}
|
|
4185
|
+
};
|
|
4186
|
+
const observeActionEffect = async (tab, framePath, allowedDomains, before) => {
|
|
4187
|
+
const started = Date.now();
|
|
4188
|
+
let after = null;
|
|
4189
|
+
let waitedMs = 0;
|
|
4190
|
+
if (!before) {
|
|
4191
|
+
await sleep2(ACTION_PROBE_INTERVAL_MS * 2);
|
|
4192
|
+
waitedMs = Date.now() - started;
|
|
4193
|
+
}
|
|
4194
|
+
while (before && waitedMs < ACTION_SETTLE_MS) {
|
|
4195
|
+
await sleep2(Math.min(ACTION_PROBE_INTERVAL_MS, ACTION_SETTLE_MS - waitedMs));
|
|
4196
|
+
try {
|
|
4197
|
+
const actor = framePath.length ? resolveFrame(tab, framePath, allowedDomains).actor : pageActor(tab);
|
|
4198
|
+
after = await captureSignature(actor, ACTION_PROBE_TIMEOUT_MS);
|
|
4199
|
+
} catch {
|
|
4200
|
+
after = null;
|
|
4201
|
+
}
|
|
4202
|
+
waitedMs = Date.now() - started;
|
|
4203
|
+
if (before && after && comparePageSignatures(before, after).changed) break;
|
|
4204
|
+
}
|
|
4205
|
+
if (!before || !after) {
|
|
4206
|
+
const currentUrl = framePath.length ? "" : tabUrl(tab);
|
|
4207
|
+
const urlChanged = !!before && !!currentUrl && currentUrl !== before.url;
|
|
4208
|
+
return {
|
|
4209
|
+
changed: urlChanged,
|
|
4210
|
+
urlChanged,
|
|
4211
|
+
titleChanged: false,
|
|
4212
|
+
domChanged: false,
|
|
4213
|
+
valueChanged: false,
|
|
4214
|
+
waitedMs,
|
|
4215
|
+
probeFailed: true
|
|
4216
|
+
};
|
|
4217
|
+
}
|
|
4218
|
+
return {
|
|
4219
|
+
...comparePageSignatures(before, after),
|
|
4220
|
+
waitedMs
|
|
4221
|
+
};
|
|
4222
|
+
};
|
|
4223
|
+
const typeCapabilities = {
|
|
4224
|
+
...clickCapabilities,
|
|
4225
|
+
strictFileInteractability: false
|
|
4226
|
+
};
|
|
4227
|
+
const ops = {
|
|
4228
|
+
status: () => {
|
|
4229
|
+
const manager = win.gZenWorkspaces;
|
|
4230
|
+
const tabs = realTabs();
|
|
4231
|
+
const activeTab = win.gBrowser?.selectedTab;
|
|
4232
|
+
const activeFolder = activeTab ? folderOf(activeTab) : null;
|
|
4233
|
+
const spaces = allSpaceInfo();
|
|
4234
|
+
const profile = (() => {
|
|
4235
|
+
try {
|
|
4236
|
+
return Services.dirsvc.get("ProfD", Components.interfaces.nsIFile).path;
|
|
4237
|
+
} catch {
|
|
4238
|
+
return "";
|
|
4239
|
+
}
|
|
4240
|
+
})();
|
|
4241
|
+
return {
|
|
4242
|
+
appName: Services.appinfo.name,
|
|
4243
|
+
appVersion: Services.appinfo.version,
|
|
4244
|
+
buildId: Services.appinfo.appBuildID,
|
|
4245
|
+
platform: Services.appinfo.OS,
|
|
4246
|
+
profile,
|
|
4247
|
+
windowId,
|
|
4248
|
+
focused: win.document.hasFocus(),
|
|
4249
|
+
workspacesEnabled: spacesEnabled(),
|
|
4250
|
+
activeSpaceId: spacesEnabled() ? manager.activeWorkspace : null,
|
|
4251
|
+
activeTab: activeTab ? {
|
|
4252
|
+
id: idForTab(activeTab),
|
|
4253
|
+
title: tabTitle(activeTab),
|
|
4254
|
+
url: tabUrl(activeTab),
|
|
3270
4255
|
spaceId: activeTab.getAttribute("zen-workspace-id") || null,
|
|
3271
4256
|
folderId: activeFolder?.id ?? null
|
|
3272
4257
|
} : null,
|
|
@@ -3534,38 +4519,41 @@ ${tab.url}`.toLowerCase();
|
|
|
3534
4519
|
const offset = Number.isFinite(requestedOffset) ? Math.max(0, Math.floor(requestedOffset)) : 0;
|
|
3535
4520
|
const format = params?.format;
|
|
3536
4521
|
const selector = params?.selector ? String(params.selector).trim() : void 0;
|
|
3537
|
-
|
|
3538
|
-
|
|
3539
|
-
|
|
3540
|
-
const contentType = contentTypeOf(tab);
|
|
3541
|
-
const global = tab.linkedBrowser?.browsingContext?.currentWindowGlobal;
|
|
3542
|
-
if (!global) {
|
|
4522
|
+
const framePath = requireFramePath(params?.framePath);
|
|
4523
|
+
const allowedDomains = params?.allowedDomains;
|
|
4524
|
+
if (format === "interactive" && isPdfTab(tab)) {
|
|
3543
4525
|
throw new OpsError(
|
|
3544
|
-
"
|
|
3545
|
-
|
|
4526
|
+
"unsupported_page",
|
|
4527
|
+
"Zen MCP cannot build an interactive snapshot of the PDF viewer. Open the page as HTML instead."
|
|
3546
4528
|
);
|
|
3547
4529
|
}
|
|
3548
|
-
|
|
3549
|
-
|
|
3550
|
-
|
|
3551
|
-
|
|
3552
|
-
|
|
3553
|
-
|
|
4530
|
+
if (isPdfTab(tab)) {
|
|
4531
|
+
if (framePath.length) {
|
|
4532
|
+
throw new OpsError(
|
|
4533
|
+
"unsupported_frame",
|
|
4534
|
+
"PDF text is only read from the tab's top-level document."
|
|
4535
|
+
);
|
|
4536
|
+
}
|
|
4537
|
+
return readPdfTab(tab, maxChars, offset);
|
|
3554
4538
|
}
|
|
4539
|
+
const frame = framePath.length ? resolveFrame(tab, framePath, allowedDomains) : null;
|
|
4540
|
+
const contentType = frame ? null : contentTypeOf(tab);
|
|
4541
|
+
const runRead = (actor, refPrefix) => actor.sendQuery("MarionetteCommandsParent:executeScript", {
|
|
4542
|
+
script: buildReadScript({
|
|
4543
|
+
maxChars,
|
|
4544
|
+
offset,
|
|
4545
|
+
...format ? { format } : {},
|
|
4546
|
+
...selector ? { selector } : {},
|
|
4547
|
+
...refPrefix ? { refPrefix } : {}
|
|
4548
|
+
}),
|
|
4549
|
+
args: [],
|
|
4550
|
+
opts: { timeout: 15e3 }
|
|
4551
|
+
});
|
|
3555
4552
|
let raw;
|
|
3556
4553
|
try {
|
|
3557
|
-
raw = await
|
|
3558
|
-
|
|
3559
|
-
|
|
3560
|
-
script: buildReadScript({
|
|
3561
|
-
maxChars,
|
|
3562
|
-
offset,
|
|
3563
|
-
...format ? { format } : {},
|
|
3564
|
-
...selector ? { selector } : {}
|
|
3565
|
-
}),
|
|
3566
|
-
args: [],
|
|
3567
|
-
opts: { timeout: 15e3 }
|
|
3568
|
-
}
|
|
4554
|
+
raw = await runRead(
|
|
4555
|
+
frame?.actor ?? pageActor(tab),
|
|
4556
|
+
frameRefPrefix(framePath)
|
|
3569
4557
|
);
|
|
3570
4558
|
} catch (error) {
|
|
3571
4559
|
throw new OpsError(
|
|
@@ -3588,11 +4576,361 @@ ${tab.url}`.toLowerCase();
|
|
|
3588
4576
|
`No element matches selector "${selector}"`
|
|
3589
4577
|
);
|
|
3590
4578
|
}
|
|
3591
|
-
|
|
4579
|
+
const listed = listFrames(tab, allowedDomains);
|
|
4580
|
+
const notes = [];
|
|
4581
|
+
if (listed.skipped > 0) {
|
|
4582
|
+
notes.push(
|
|
4583
|
+
`${listed.skipped} frame(s) were skipped because they are not http(s) pages or are outside the domain allowlist.`
|
|
4584
|
+
);
|
|
4585
|
+
}
|
|
4586
|
+
if (listed.truncated) {
|
|
4587
|
+
notes.push(
|
|
4588
|
+
`Only the first ${MAX_FRAMES} frames are listed; deeper frames were not inspected.`
|
|
4589
|
+
);
|
|
4590
|
+
}
|
|
4591
|
+
if (format === "interactive" && !selector) {
|
|
4592
|
+
const descendants = listed.frames.filter(
|
|
4593
|
+
(candidate) => candidate.path.length > framePath.length && framePath.every(
|
|
4594
|
+
(index, position) => candidate.path[position] === index
|
|
4595
|
+
)
|
|
4596
|
+
);
|
|
4597
|
+
const scanned = descendants.slice(0, MAX_FRAME_SCANS);
|
|
4598
|
+
if (descendants.length > scanned.length) {
|
|
4599
|
+
notes.push(
|
|
4600
|
+
`Only the first ${MAX_FRAME_SCANS} frames were scanned for controls.`
|
|
4601
|
+
);
|
|
4602
|
+
}
|
|
4603
|
+
const merged = (page.elements ?? []).map(
|
|
4604
|
+
(element) => framePath.length ? {
|
|
4605
|
+
...element,
|
|
4606
|
+
framePath: [...framePath],
|
|
4607
|
+
frameUrl: frame?.url ?? null
|
|
4608
|
+
} : element
|
|
4609
|
+
);
|
|
4610
|
+
let truncated = page.elementsTruncated === true;
|
|
4611
|
+
const pending = scanned.map(async (candidate) => {
|
|
4612
|
+
try {
|
|
4613
|
+
const context = resolveFrame(tab, candidate.path, allowedDomains);
|
|
4614
|
+
const frameRaw = await runRead(
|
|
4615
|
+
context.actor,
|
|
4616
|
+
frameRefPrefix(candidate.path)
|
|
4617
|
+
);
|
|
4618
|
+
return {
|
|
4619
|
+
frame: candidate,
|
|
4620
|
+
page: coercePageSnapshot(frameRaw)
|
|
4621
|
+
};
|
|
4622
|
+
} catch {
|
|
4623
|
+
return { frame: candidate, page: null };
|
|
4624
|
+
}
|
|
4625
|
+
});
|
|
4626
|
+
const outcomes = await Promise.all(pending);
|
|
4627
|
+
let failed = 0;
|
|
4628
|
+
for (const outcome of outcomes) {
|
|
4629
|
+
if (!outcome.page) {
|
|
4630
|
+
failed += 1;
|
|
4631
|
+
continue;
|
|
4632
|
+
}
|
|
4633
|
+
if (outcome.page.elementsTruncated === true) truncated = true;
|
|
4634
|
+
for (const element of outcome.page.elements ?? []) {
|
|
4635
|
+
if (merged.length >= MAX_PAGE_ELEMENTS) {
|
|
4636
|
+
truncated = true;
|
|
4637
|
+
break;
|
|
4638
|
+
}
|
|
4639
|
+
merged.push({
|
|
4640
|
+
...element,
|
|
4641
|
+
framePath: [...outcome.frame.path],
|
|
4642
|
+
frameUrl: outcome.frame.url
|
|
4643
|
+
});
|
|
4644
|
+
}
|
|
4645
|
+
}
|
|
4646
|
+
if (failed > 0) {
|
|
4647
|
+
notes.push(`${failed} frame(s) could not be read.`);
|
|
4648
|
+
}
|
|
4649
|
+
page.elements = merged;
|
|
4650
|
+
page.elementsTruncated = truncated;
|
|
4651
|
+
} else if (format === "interactive" && listed.frames.length) {
|
|
4652
|
+
notes.push(
|
|
4653
|
+
"Frame controls are not included because selector was used."
|
|
4654
|
+
);
|
|
4655
|
+
}
|
|
4656
|
+
const result = toPageReadResult(page, {
|
|
3592
4657
|
maxChars,
|
|
3593
|
-
contentType,
|
|
4658
|
+
...contentType !== null ? { contentType } : {},
|
|
3594
4659
|
offset
|
|
3595
4660
|
});
|
|
4661
|
+
result.frames = listed.frames;
|
|
4662
|
+
if (framePath.length) result.framePath = framePath;
|
|
4663
|
+
if (notes.length) {
|
|
4664
|
+
const note = notes.join(" ");
|
|
4665
|
+
result.limitation = result.limitation ? `${result.limitation} ${note}` : note;
|
|
4666
|
+
}
|
|
4667
|
+
return result;
|
|
4668
|
+
},
|
|
4669
|
+
"tabs.click": async (params) => {
|
|
4670
|
+
const tabId = String(params?.tabId ?? "");
|
|
4671
|
+
const tab = requireActionTab(tabId, "click");
|
|
4672
|
+
assertActionUrlAllowed(
|
|
4673
|
+
tabUrl(tab),
|
|
4674
|
+
params?.allowedDomains,
|
|
4675
|
+
"clicking in"
|
|
4676
|
+
);
|
|
4677
|
+
const resolved = await resolvePageTarget(
|
|
4678
|
+
tab,
|
|
4679
|
+
params ?? {},
|
|
4680
|
+
params?.allowedDomains
|
|
4681
|
+
);
|
|
4682
|
+
const target = resolved.target;
|
|
4683
|
+
if (target.disabled) {
|
|
4684
|
+
throw new OpsError(
|
|
4685
|
+
"element_disabled",
|
|
4686
|
+
`The target "${target.label || target.tag}" is disabled.`
|
|
4687
|
+
);
|
|
4688
|
+
}
|
|
4689
|
+
if (target.href) {
|
|
4690
|
+
assertActionUrlAllowed(
|
|
4691
|
+
target.href,
|
|
4692
|
+
params?.allowedDomains,
|
|
4693
|
+
"following a link to"
|
|
4694
|
+
);
|
|
4695
|
+
}
|
|
4696
|
+
const before = await captureSignature(
|
|
4697
|
+
resolved.actor,
|
|
4698
|
+
SIGNATURE_BEFORE_TIMEOUT_MS
|
|
4699
|
+
);
|
|
4700
|
+
try {
|
|
4701
|
+
await resolved.actor.sendQuery("MarionetteCommandsParent:clickElement", {
|
|
4702
|
+
elem: target.element,
|
|
4703
|
+
capabilities: clickCapabilities
|
|
4704
|
+
});
|
|
4705
|
+
} catch (error) {
|
|
4706
|
+
throw new OpsError(
|
|
4707
|
+
"click_failed",
|
|
4708
|
+
`Could not click "${target.label || target.tag}": ${String(
|
|
4709
|
+
error?.message ?? error
|
|
4710
|
+
)}`
|
|
4711
|
+
);
|
|
4712
|
+
}
|
|
4713
|
+
const effect = await observeActionEffect(
|
|
4714
|
+
tab,
|
|
4715
|
+
resolved.framePath,
|
|
4716
|
+
params?.allowedDomains,
|
|
4717
|
+
before
|
|
4718
|
+
);
|
|
4719
|
+
const url = tabUrl(tab);
|
|
4720
|
+
return {
|
|
4721
|
+
clicked: true,
|
|
4722
|
+
tabId,
|
|
4723
|
+
url: isHttpUrl(url) ? url : "",
|
|
4724
|
+
title: tabTitle(tab),
|
|
4725
|
+
target: actionTarget(target),
|
|
4726
|
+
effect,
|
|
4727
|
+
...resolved.framePath.length ? {
|
|
4728
|
+
framePath: resolved.framePath,
|
|
4729
|
+
frameUrl: currentFrameUrl(tab, resolved.framePath) ?? resolved.frameUrl
|
|
4730
|
+
} : {}
|
|
4731
|
+
};
|
|
4732
|
+
},
|
|
4733
|
+
"tabs.type": async (params) => {
|
|
4734
|
+
const tabId = String(params?.tabId ?? "");
|
|
4735
|
+
const tab = requireActionTab(tabId, "type into");
|
|
4736
|
+
const text = String(params?.text ?? "");
|
|
4737
|
+
const clear = params?.clear === true;
|
|
4738
|
+
if (!text && !clear) {
|
|
4739
|
+
throw new OpsError(
|
|
4740
|
+
"invalid_args",
|
|
4741
|
+
"Provide text to type, or set clear=true to empty the field."
|
|
4742
|
+
);
|
|
4743
|
+
}
|
|
4744
|
+
if (text.length > 1e4) {
|
|
4745
|
+
throw new OpsError(
|
|
4746
|
+
"invalid_args",
|
|
4747
|
+
"text must be 10,000 characters or fewer."
|
|
4748
|
+
);
|
|
4749
|
+
}
|
|
4750
|
+
assertActionUrlAllowed(
|
|
4751
|
+
tabUrl(tab),
|
|
4752
|
+
params?.allowedDomains,
|
|
4753
|
+
"typing into"
|
|
4754
|
+
);
|
|
4755
|
+
const resolved = await resolvePageTarget(
|
|
4756
|
+
tab,
|
|
4757
|
+
params ?? {},
|
|
4758
|
+
params?.allowedDomains
|
|
4759
|
+
);
|
|
4760
|
+
const target = resolved.target;
|
|
4761
|
+
if (target.disabled) {
|
|
4762
|
+
throw new OpsError(
|
|
4763
|
+
"element_disabled",
|
|
4764
|
+
`The target "${target.label || target.tag}" is disabled.`
|
|
4765
|
+
);
|
|
4766
|
+
}
|
|
4767
|
+
if (target.readOnly) {
|
|
4768
|
+
throw new OpsError(
|
|
4769
|
+
"element_readonly",
|
|
4770
|
+
`The target "${target.label || target.tag}" is read-only.`
|
|
4771
|
+
);
|
|
4772
|
+
}
|
|
4773
|
+
if (target.tag === "input" && target.type === "file") {
|
|
4774
|
+
throw new OpsError(
|
|
4775
|
+
"unsupported_target",
|
|
4776
|
+
"Zen MCP does not attach files. Ask the user to choose the file in Zen."
|
|
4777
|
+
);
|
|
4778
|
+
}
|
|
4779
|
+
const before = await captureSignature(
|
|
4780
|
+
resolved.actor,
|
|
4781
|
+
SIGNATURE_BEFORE_TIMEOUT_MS
|
|
4782
|
+
);
|
|
4783
|
+
try {
|
|
4784
|
+
if (clear) {
|
|
4785
|
+
await resolved.actor.sendQuery(
|
|
4786
|
+
"MarionetteCommandsParent:clearElement",
|
|
4787
|
+
{
|
|
4788
|
+
elem: target.element
|
|
4789
|
+
}
|
|
4790
|
+
);
|
|
4791
|
+
}
|
|
4792
|
+
await resolved.actor.sendQuery(
|
|
4793
|
+
"MarionetteCommandsParent:sendKeysToElement",
|
|
4794
|
+
{
|
|
4795
|
+
elem: target.element,
|
|
4796
|
+
text,
|
|
4797
|
+
capabilities: typeCapabilities
|
|
4798
|
+
}
|
|
4799
|
+
);
|
|
4800
|
+
} catch (error) {
|
|
4801
|
+
throw new OpsError(
|
|
4802
|
+
"type_failed",
|
|
4803
|
+
`Could not type into "${target.label || target.tag}": ${String(
|
|
4804
|
+
error?.message ?? error
|
|
4805
|
+
)}`
|
|
4806
|
+
);
|
|
4807
|
+
}
|
|
4808
|
+
const effect = await observeActionEffect(
|
|
4809
|
+
tab,
|
|
4810
|
+
resolved.framePath,
|
|
4811
|
+
params?.allowedDomains,
|
|
4812
|
+
before
|
|
4813
|
+
);
|
|
4814
|
+
const url = tabUrl(tab);
|
|
4815
|
+
return {
|
|
4816
|
+
typed: text.length,
|
|
4817
|
+
cleared: clear,
|
|
4818
|
+
tabId,
|
|
4819
|
+
url: isHttpUrl(url) ? url : "",
|
|
4820
|
+
title: tabTitle(tab),
|
|
4821
|
+
target: actionTarget(target),
|
|
4822
|
+
effect,
|
|
4823
|
+
...resolved.framePath.length ? {
|
|
4824
|
+
framePath: resolved.framePath,
|
|
4825
|
+
frameUrl: currentFrameUrl(tab, resolved.framePath) ?? resolved.frameUrl
|
|
4826
|
+
} : {},
|
|
4827
|
+
...target.sensitive ? {
|
|
4828
|
+
limitation: "This is a password field. The text is not echoed or stored in the result."
|
|
4829
|
+
} : {}
|
|
4830
|
+
};
|
|
4831
|
+
},
|
|
4832
|
+
"tabs.waitFor": async (params) => {
|
|
4833
|
+
const tabId = String(params?.tabId ?? "");
|
|
4834
|
+
if (!tabId) {
|
|
4835
|
+
throw new OpsError("no_tab", "Provide the tabId to wait in.");
|
|
4836
|
+
}
|
|
4837
|
+
const tab = requireActionTab(tabId, "wait in");
|
|
4838
|
+
const framePath = requireFramePath(params?.framePath);
|
|
4839
|
+
const allowedDomains = params?.allowedDomains;
|
|
4840
|
+
assertActionUrlAllowed(tabUrl(tab), allowedDomains, "waiting in");
|
|
4841
|
+
const value = (input) => typeof input === "string" ? input.trim() : "";
|
|
4842
|
+
const candidates = [
|
|
4843
|
+
["selector", value(params?.selector)],
|
|
4844
|
+
["text", value(params?.text)],
|
|
4845
|
+
["urlContains", value(params?.urlContains)],
|
|
4846
|
+
["titleContains", value(params?.titleContains)]
|
|
4847
|
+
].filter((entry) => !!entry[1]);
|
|
4848
|
+
if (candidates.length !== 1) {
|
|
4849
|
+
throw new OpsError(
|
|
4850
|
+
"invalid_args",
|
|
4851
|
+
"Provide exactly one of selector, text, urlContains, or titleContains."
|
|
4852
|
+
);
|
|
4853
|
+
}
|
|
4854
|
+
const [condition, query] = candidates[0];
|
|
4855
|
+
if (query.length > 2e3) {
|
|
4856
|
+
throw new OpsError(
|
|
4857
|
+
"invalid_args",
|
|
4858
|
+
"The condition text must be 2,000 characters or fewer."
|
|
4859
|
+
);
|
|
4860
|
+
}
|
|
4861
|
+
const until = params?.until === "absent" ? "absent" : "present";
|
|
4862
|
+
const requestedTimeout = Number(params?.timeoutMs);
|
|
4863
|
+
const timeoutMs = clamp3(
|
|
4864
|
+
Number.isFinite(requestedTimeout) && requestedTimeout > 0 ? requestedTimeout : WAIT_TIMEOUT_MS,
|
|
4865
|
+
0,
|
|
4866
|
+
WAIT_MAX_TIMEOUT_MS
|
|
4867
|
+
);
|
|
4868
|
+
const requestedPoll = Number(params?.pollMs);
|
|
4869
|
+
const pollMs = clamp3(
|
|
4870
|
+
Number.isFinite(requestedPoll) && requestedPoll > 0 ? requestedPoll : WAIT_POLL_MS,
|
|
4871
|
+
WAIT_MIN_POLL_MS,
|
|
4872
|
+
WAIT_MAX_POLL_MS
|
|
4873
|
+
);
|
|
4874
|
+
const started = Date.now();
|
|
4875
|
+
const probeOptions = {
|
|
4876
|
+
[condition]: query
|
|
4877
|
+
};
|
|
4878
|
+
let probe = null;
|
|
4879
|
+
let lastError = "";
|
|
4880
|
+
let matched = false;
|
|
4881
|
+
let waitedMs = 0;
|
|
4882
|
+
for (; ; ) {
|
|
4883
|
+
let actor = null;
|
|
4884
|
+
try {
|
|
4885
|
+
actor = framePath.length ? resolveFrame(tab, framePath, allowedDomains).actor : pageActor(tab);
|
|
4886
|
+
} catch (error) {
|
|
4887
|
+
if (error instanceof OpsError && error.code === "domain_not_allowed") {
|
|
4888
|
+
throw error;
|
|
4889
|
+
}
|
|
4890
|
+
lastError = String(error?.message ?? error);
|
|
4891
|
+
}
|
|
4892
|
+
if (actor) {
|
|
4893
|
+
try {
|
|
4894
|
+
const raw = await actor.sendQuery(
|
|
4895
|
+
"MarionetteCommandsParent:executeScript",
|
|
4896
|
+
{
|
|
4897
|
+
script: buildWaitProbeScript(probeOptions),
|
|
4898
|
+
args: [],
|
|
4899
|
+
opts: { timeout: WAIT_PROBE_TIMEOUT_MS }
|
|
4900
|
+
}
|
|
4901
|
+
);
|
|
4902
|
+
probe = coerceWaitProbe(raw);
|
|
4903
|
+
if (!probe) lastError = "the probe returned no document state";
|
|
4904
|
+
} catch (error) {
|
|
4905
|
+
probe = null;
|
|
4906
|
+
lastError = String(error?.message ?? error);
|
|
4907
|
+
}
|
|
4908
|
+
}
|
|
4909
|
+
matched = probe ? until === "absent" ? probe.matched === false : probe.matched === true : false;
|
|
4910
|
+
waitedMs = Date.now() - started;
|
|
4911
|
+
if (matched || waitedMs >= timeoutMs) break;
|
|
4912
|
+
await sleep2(Math.min(pollMs, timeoutMs - waitedMs));
|
|
4913
|
+
}
|
|
4914
|
+
const finalUrl = tabUrl(tab);
|
|
4915
|
+
let limitation;
|
|
4916
|
+
if (!matched) {
|
|
4917
|
+
limitation = probe ? `The condition did not hold within ${waitedMs} ms.` : `The document could not be inspected after ${waitedMs} ms` + (lastError ? `: ${lastError}` : ".");
|
|
4918
|
+
}
|
|
4919
|
+
return {
|
|
4920
|
+
matched,
|
|
4921
|
+
waitedMs,
|
|
4922
|
+
condition,
|
|
4923
|
+
until,
|
|
4924
|
+
query,
|
|
4925
|
+
tabId,
|
|
4926
|
+
url: isHttpUrl(finalUrl) ? finalUrl : "",
|
|
4927
|
+
title: tabTitle(tab),
|
|
4928
|
+
...framePath.length ? {
|
|
4929
|
+
framePath,
|
|
4930
|
+
frameUrl: currentFrameUrl(tab, framePath) ?? (probe?.url ? probe.url : null)
|
|
4931
|
+
} : {},
|
|
4932
|
+
...limitation ? { limitation } : {}
|
|
4933
|
+
};
|
|
3596
4934
|
},
|
|
3597
4935
|
"tabs.findText": async (params) => {
|
|
3598
4936
|
const tabId = String(params?.tabId ?? "");
|
|
@@ -5120,7 +6458,8 @@ ${tab.url}`.toLowerCase();
|
|
|
5120
6458
|
color: var(--sk-muted);
|
|
5121
6459
|
overflow-wrap: anywhere;
|
|
5122
6460
|
}
|
|
5123
|
-
.banner-button
|
|
6461
|
+
.banner-button,
|
|
6462
|
+
.update-apply {
|
|
5124
6463
|
flex: none;
|
|
5125
6464
|
padding: 5px 9px;
|
|
5126
6465
|
border-radius: 7px;
|
|
@@ -5133,8 +6472,10 @@ ${tab.url}`.toLowerCase();
|
|
|
5133
6472
|
cursor: pointer;
|
|
5134
6473
|
white-space: nowrap;
|
|
5135
6474
|
}
|
|
5136
|
-
.banner-button:hover
|
|
5137
|
-
.
|
|
6475
|
+
.banner-button:hover,
|
|
6476
|
+
.update-apply:hover { background: var(--sk-hover); }
|
|
6477
|
+
.banner-button:focus-visible,
|
|
6478
|
+
.update-apply:focus-visible {
|
|
5138
6479
|
outline: 2px solid color-mix(in srgb, var(--sk-accent) 65%, transparent);
|
|
5139
6480
|
outline-offset: 1px;
|
|
5140
6481
|
}
|
|
@@ -5143,6 +6484,66 @@ ${tab.url}`.toLowerCase();
|
|
|
5143
6484
|
background: color-mix(in srgb, var(--sk-success) 12%, transparent);
|
|
5144
6485
|
color: var(--sk-success);
|
|
5145
6486
|
}
|
|
6487
|
+
.banner-update,
|
|
6488
|
+
.banner-update-prompt {
|
|
6489
|
+
flex: none;
|
|
6490
|
+
display: flex;
|
|
6491
|
+
align-items: center;
|
|
6492
|
+
gap: 4px;
|
|
6493
|
+
}
|
|
6494
|
+
.banner-update[hidden],
|
|
6495
|
+
.banner-update-icon[hidden],
|
|
6496
|
+
.banner-update-prompt[hidden],
|
|
6497
|
+
.banner-dismiss[hidden],
|
|
6498
|
+
.update-apply[hidden] { display: none; }
|
|
6499
|
+
.banner-update-icon {
|
|
6500
|
+
width: 20px;
|
|
6501
|
+
height: 20px;
|
|
6502
|
+
padding: 0;
|
|
6503
|
+
display: grid;
|
|
6504
|
+
place-items: center;
|
|
6505
|
+
border: none;
|
|
6506
|
+
border-radius: 6px;
|
|
6507
|
+
background: var(--sk-faint);
|
|
6508
|
+
color: var(--sk-accent);
|
|
6509
|
+
cursor: pointer;
|
|
6510
|
+
}
|
|
6511
|
+
.banner-update-icon:hover { background: var(--sk-hover); }
|
|
6512
|
+
.banner-update-icon:focus-visible {
|
|
6513
|
+
outline: 2px solid color-mix(in srgb, var(--sk-accent) 65%, transparent);
|
|
6514
|
+
outline-offset: 1px;
|
|
6515
|
+
}
|
|
6516
|
+
.banner-update-icon svg { width: 12px; height: 12px; display: block; }
|
|
6517
|
+
.update-label {
|
|
6518
|
+
max-width: 112px;
|
|
6519
|
+
font-size: 10.5px;
|
|
6520
|
+
font-weight: 600;
|
|
6521
|
+
line-height: 1.3;
|
|
6522
|
+
color: var(--sk-accent);
|
|
6523
|
+
overflow-wrap: anywhere;
|
|
6524
|
+
}
|
|
6525
|
+
.update-label.muted { color: var(--sk-muted); font-weight: 550; }
|
|
6526
|
+
.banner-dismiss {
|
|
6527
|
+
flex: none;
|
|
6528
|
+
width: 18px;
|
|
6529
|
+
height: 18px;
|
|
6530
|
+
padding: 0;
|
|
6531
|
+
display: grid;
|
|
6532
|
+
place-items: center;
|
|
6533
|
+
border: none;
|
|
6534
|
+
border-radius: 5px;
|
|
6535
|
+
background: none;
|
|
6536
|
+
color: var(--sk-muted);
|
|
6537
|
+
font: inherit;
|
|
6538
|
+
font-size: 12px;
|
|
6539
|
+
line-height: 1;
|
|
6540
|
+
cursor: pointer;
|
|
6541
|
+
}
|
|
6542
|
+
.banner-dismiss:hover { color: var(--sk-fg); background: var(--sk-faint); }
|
|
6543
|
+
.banner-dismiss:focus-visible {
|
|
6544
|
+
outline: 2px solid color-mix(in srgb, var(--sk-accent) 65%, transparent);
|
|
6545
|
+
outline-offset: 1px;
|
|
6546
|
+
}
|
|
5146
6547
|
.consent { padding: 14px 15px 13px; }
|
|
5147
6548
|
.consent-title {
|
|
5148
6549
|
margin: 0 0 6px;
|
|
@@ -5537,6 +6938,12 @@ ${tab.url}`.toLowerCase();
|
|
|
5537
6938
|
#bannerTitle;
|
|
5538
6939
|
#bannerDetail;
|
|
5539
6940
|
#bannerButton;
|
|
6941
|
+
#bannerUpdate;
|
|
6942
|
+
#updateIcon;
|
|
6943
|
+
#updatePrompt;
|
|
6944
|
+
#updateLabel;
|
|
6945
|
+
#updateApply;
|
|
6946
|
+
#updateDismiss;
|
|
5540
6947
|
#consentEl;
|
|
5541
6948
|
#questionsEl;
|
|
5542
6949
|
#progressEl;
|
|
@@ -5582,7 +6989,54 @@ ${tab.url}`.toLowerCase();
|
|
|
5582
6989
|
const action = this.#bannerState === "paused" ? "resume" : "pause";
|
|
5583
6990
|
this.#handlers.onBannerAction?.(action);
|
|
5584
6991
|
});
|
|
5585
|
-
this.#
|
|
6992
|
+
this.#bannerUpdate = doc.createElement("span");
|
|
6993
|
+
this.#bannerUpdate.className = "banner-update";
|
|
6994
|
+
this.#bannerUpdate.hidden = true;
|
|
6995
|
+
this.#updateIcon = doc.createElement("button");
|
|
6996
|
+
this.#updateIcon.type = "button";
|
|
6997
|
+
this.#updateIcon.className = "banner-update-icon";
|
|
6998
|
+
this.#updateIcon.title = "Update available";
|
|
6999
|
+
this.#updateIcon.setAttribute("aria-label", "Update available");
|
|
7000
|
+
this.#updateIcon.appendChild(createDownloadIcon(doc));
|
|
7001
|
+
this.#updateIcon.addEventListener("click", () => {
|
|
7002
|
+
this.#handlers.onUpdateAction?.("expand");
|
|
7003
|
+
});
|
|
7004
|
+
this.#updatePrompt = doc.createElement("span");
|
|
7005
|
+
this.#updatePrompt.className = "banner-update-prompt";
|
|
7006
|
+
this.#updatePrompt.hidden = true;
|
|
7007
|
+
this.#updatePrompt.setAttribute("role", "group");
|
|
7008
|
+
this.#updatePrompt.setAttribute("aria-label", "Zen MCP update available");
|
|
7009
|
+
this.#updateLabel = doc.createElement("span");
|
|
7010
|
+
this.#updateLabel.className = "update-label";
|
|
7011
|
+
this.#updateApply = doc.createElement("button");
|
|
7012
|
+
this.#updateApply.type = "button";
|
|
7013
|
+
this.#updateApply.className = "update-apply";
|
|
7014
|
+
this.#updateApply.textContent = "Update";
|
|
7015
|
+
this.#updateApply.setAttribute("aria-label", "Install the update");
|
|
7016
|
+
this.#updateApply.addEventListener("click", () => {
|
|
7017
|
+
this.#handlers.onUpdateAction?.("install");
|
|
7018
|
+
});
|
|
7019
|
+
this.#updateDismiss = doc.createElement("button");
|
|
7020
|
+
this.#updateDismiss.type = "button";
|
|
7021
|
+
this.#updateDismiss.className = "banner-dismiss";
|
|
7022
|
+
this.#updateDismiss.textContent = "×";
|
|
7023
|
+
this.#updateDismiss.title = "Dismiss";
|
|
7024
|
+
this.#updateDismiss.setAttribute("aria-label", "Dismiss update notice");
|
|
7025
|
+
this.#updateDismiss.addEventListener("click", () => {
|
|
7026
|
+
this.#handlers.onUpdateAction?.("dismiss");
|
|
7027
|
+
});
|
|
7028
|
+
this.#updatePrompt.append(
|
|
7029
|
+
this.#updateLabel,
|
|
7030
|
+
this.#updateApply,
|
|
7031
|
+
this.#updateDismiss
|
|
7032
|
+
);
|
|
7033
|
+
this.#bannerUpdate.append(this.#updateIcon, this.#updatePrompt);
|
|
7034
|
+
this.#bannerEl.append(
|
|
7035
|
+
bannerDot,
|
|
7036
|
+
bannerText,
|
|
7037
|
+
this.#bannerUpdate,
|
|
7038
|
+
this.#bannerButton
|
|
7039
|
+
);
|
|
5586
7040
|
this.#consentEl = doc.createElement("div");
|
|
5587
7041
|
this.#consentEl.className = "sk-consent-stack";
|
|
5588
7042
|
this.#questionsEl = doc.createElement("div");
|
|
@@ -5632,6 +7086,7 @@ ${tab.url}`.toLowerCase();
|
|
|
5632
7086
|
this.#bannerEl.hidden = false;
|
|
5633
7087
|
this.#bannerTitle.textContent = banner.text;
|
|
5634
7088
|
setOptionalText(this.#bannerDetail, banner.detail);
|
|
7089
|
+
this.#renderUpdate(banner.update, banner.state);
|
|
5635
7090
|
this.#bannerButton.hidden = banner.state === "pending";
|
|
5636
7091
|
this.#bannerButton.textContent = banner.state === "paused" ? "Resume" : "Pause";
|
|
5637
7092
|
this.#bannerButton.setAttribute(
|
|
@@ -5639,6 +7094,56 @@ ${tab.url}`.toLowerCase();
|
|
|
5639
7094
|
banner.state === "paused" ? "Resume agent access" : "Pause agent access"
|
|
5640
7095
|
);
|
|
5641
7096
|
}
|
|
7097
|
+
#renderUpdate(update, state) {
|
|
7098
|
+
const notice = update ?? null;
|
|
7099
|
+
const visible = !!notice && state === "active";
|
|
7100
|
+
this.#bannerUpdate.hidden = !visible;
|
|
7101
|
+
if (!notice || !visible) return;
|
|
7102
|
+
const version = `v${notice.latestVersion}`;
|
|
7103
|
+
this.#updateIcon.hidden = notice.state !== "icon";
|
|
7104
|
+
this.#updateIcon.title = `Update ${version} available`;
|
|
7105
|
+
this.#updateIcon.setAttribute(
|
|
7106
|
+
"aria-label",
|
|
7107
|
+
`Update ${version} available. Installed version ${notice.currentVersion}.`
|
|
7108
|
+
);
|
|
7109
|
+
this.#updatePrompt.hidden = notice.state === "icon";
|
|
7110
|
+
if (notice.state === "icon") return;
|
|
7111
|
+
this.#updateLabel.classList.remove("muted");
|
|
7112
|
+
this.#updateLabel.title = "";
|
|
7113
|
+
this.#updateApply.hidden = true;
|
|
7114
|
+
this.#updateDismiss.hidden = false;
|
|
7115
|
+
switch (notice.state) {
|
|
7116
|
+
case "installing":
|
|
7117
|
+
this.#updateLabel.textContent = `Updating to ${version}…`;
|
|
7118
|
+
this.#updateDismiss.hidden = true;
|
|
7119
|
+
return;
|
|
7120
|
+
case "installed":
|
|
7121
|
+
this.#updateLabel.textContent = "Updated. Restart client.";
|
|
7122
|
+
this.#updateLabel.title = `Zen MCP ${notice.latestVersion} is installed. Restart the MCP client to load it.`;
|
|
7123
|
+
this.#updateLabel.classList.add("muted");
|
|
7124
|
+
return;
|
|
7125
|
+
case "failed":
|
|
7126
|
+
this.#updateLabel.textContent = "Update failed";
|
|
7127
|
+
this.#updateLabel.title = notice.message ?? "Run `zen-mcp update` in a terminal.";
|
|
7128
|
+
this.#updateApply.hidden = false;
|
|
7129
|
+
this.#updateApply.textContent = "Retry";
|
|
7130
|
+
this.#updateApply.setAttribute(
|
|
7131
|
+
"aria-label",
|
|
7132
|
+
`Retry installing Zen MCP ${version}`
|
|
7133
|
+
);
|
|
7134
|
+
return;
|
|
7135
|
+
default:
|
|
7136
|
+
this.#updateLabel.textContent = version;
|
|
7137
|
+
this.#updateLabel.title = `Installed version ${notice.currentVersion}`;
|
|
7138
|
+
this.#updateApply.hidden = false;
|
|
7139
|
+
this.#updateApply.textContent = "Update";
|
|
7140
|
+
this.#updateApply.setAttribute(
|
|
7141
|
+
"aria-label",
|
|
7142
|
+
`Install Zen MCP ${version}`
|
|
7143
|
+
);
|
|
7144
|
+
return;
|
|
7145
|
+
}
|
|
7146
|
+
}
|
|
5642
7147
|
showConsent(consent) {
|
|
5643
7148
|
this.#refreshTheme();
|
|
5644
7149
|
this.cancelConsent();
|
|
@@ -6252,6 +7757,21 @@ ${tab.url}`.toLowerCase();
|
|
|
6252
7757
|
function normalizeTone(tone) {
|
|
6253
7758
|
return tone === "success" || tone === "warning" ? tone : "info";
|
|
6254
7759
|
}
|
|
7760
|
+
function createDownloadIcon(doc) {
|
|
7761
|
+
const ns = "http://www.w3.org/2000/svg";
|
|
7762
|
+
const svg = doc.createElementNS(ns, "svg");
|
|
7763
|
+
svg.setAttribute("viewBox", "0 0 16 16");
|
|
7764
|
+
svg.setAttribute("aria-hidden", "true");
|
|
7765
|
+
const path = doc.createElementNS(ns, "path");
|
|
7766
|
+
path.setAttribute("d", "M8 2.5v7m0 0 2.75-2.75M8 9.5 5.25 6.75M3 12.5h10");
|
|
7767
|
+
path.setAttribute("fill", "none");
|
|
7768
|
+
path.setAttribute("stroke", "currentColor");
|
|
7769
|
+
path.setAttribute("stroke-width", "1.6");
|
|
7770
|
+
path.setAttribute("stroke-linecap", "round");
|
|
7771
|
+
path.setAttribute("stroke-linejoin", "round");
|
|
7772
|
+
svg.appendChild(path);
|
|
7773
|
+
return svg;
|
|
7774
|
+
}
|
|
6255
7775
|
function relativeLuminance(color) {
|
|
6256
7776
|
const match = color.match(/rgba?\(\s*([\d.]+)[,\s]+([\d.]+)[,\s]+([\d.]+)/i);
|
|
6257
7777
|
if (!match) return 0;
|
|
@@ -6350,7 +7870,8 @@ ${tab.url}`.toLowerCase();
|
|
|
6350
7870
|
})
|
|
6351
7871
|
),
|
|
6352
7872
|
onConsent: (id, granted) => send({ type: "ui.consentResult", id, granted }),
|
|
6353
|
-
onBannerAction: (action) => send({ type: "ui.bannerAction", action, ts: Date.now() })
|
|
7873
|
+
onBannerAction: (action) => send({ type: "ui.bannerAction", action, ts: Date.now() }),
|
|
7874
|
+
onUpdateAction: (action) => send({ type: "ui.updateAction", action, ts: Date.now() })
|
|
6354
7875
|
});
|
|
6355
7876
|
const ops = createOps(win, windowId);
|
|
6356
7877
|
const evidenceRecords = new EvidenceRecordStore();
|