wield-mcp 0.0.0-stage → 0.1.2

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.
@@ -0,0 +1,162 @@
1
+ "use strict";
2
+ (() => {
3
+ // apps/extension/src/ui/confirm.ts
4
+ var $ = (id2) => document.getElementById(id2);
5
+ var id = location.hash.slice(1);
6
+ var answered = false;
7
+ function el(tag, cls, text) {
8
+ const e = document.createElement(tag);
9
+ e.className = cls;
10
+ if (text !== void 0) e.textContent = text;
11
+ return e;
12
+ }
13
+ function setButtons(enabled) {
14
+ $("allow").disabled = !enabled;
15
+ $("deny").disabled = !enabled;
16
+ }
17
+ async function answer(allow) {
18
+ if (answered) return;
19
+ answered = true;
20
+ setButtons(false);
21
+ await chrome.runtime.sendMessage({ type: "ask_answer", id, allow });
22
+ window.close();
23
+ }
24
+ function gone(msg) {
25
+ $("main").replaceChildren(el("p", "ask-gone", msg));
26
+ document.querySelector(".ask-foot")?.remove();
27
+ }
28
+ function renderWrite(ask) {
29
+ const host = new URL(ask.site.origin).host;
30
+ document.title = `Wield \xB7 Allow on ${host}?`;
31
+ $("title").textContent = ask.info.summary || ask.task;
32
+ $("site").replaceChildren("on ", el("b", "", ask.site.name), ` \xB7 ${host}`);
33
+ const list = $("writes");
34
+ for (const w of ask.info.writes) {
35
+ const li = el("li", "ask-write");
36
+ const line = el("div", "ask-request");
37
+ line.append(el("span", "ask-method", w.method));
38
+ const whereHost = new URL(w.origin).host;
39
+ line.append(el("span", "ask-path", `${whereHost === host ? "" : whereHost}${w.path}`));
40
+ li.append(line);
41
+ if (w.body_preview) {
42
+ const pre = el("pre", "ask-body-preview");
43
+ let text = w.body_preview;
44
+ try {
45
+ text = JSON.stringify(JSON.parse(text), null, 2);
46
+ } catch {
47
+ }
48
+ pre.textContent = text;
49
+ pre.setAttribute("aria-label", "Exactly what is sent");
50
+ li.append(pre);
51
+ } else if (w.body_fields.length) {
52
+ const fields = el("ul", "ask-fields");
53
+ fields.setAttribute("aria-label", "Fields sent");
54
+ for (const f of w.body_fields) fields.append(el("li", "ask-field", f));
55
+ li.append(fields);
56
+ } else {
57
+ li.append(el("p", "ask-nofields", "No form fields"));
58
+ }
59
+ list.append(li);
60
+ }
61
+ $("write").hidden = false;
62
+ $("note").textContent = `Sent from this browser to ${host} only, with your own login. One Allow covers this one task.`;
63
+ $("allow").addEventListener("click", () => void answer(true));
64
+ }
65
+ function renderPermission(ask) {
66
+ const host = new URL(ask.site.origin).host;
67
+ document.body.dataset.kind = "permission";
68
+ document.title = `Wield \xB7 Use ${host}?`;
69
+ $("kind").textContent = "New site";
70
+ $("eyebrow").textContent = "Your agent wants to use a new site";
71
+ $("title").textContent = `Let Wield use ${host}?`;
72
+ $("site").replaceChildren(el("b", "", ask.site.name), ` \xB7 for \u201C${ask.task}\u201D`);
73
+ $("perm-text").textContent = `Wield runs the task in your own tab of ${host}, with your own login. Requests go only to that site.`;
74
+ $("perm").hidden = false;
75
+ $("note").textContent = "Nothing is sent until you allow it.";
76
+ $("allow").textContent = "Allow access";
77
+ $("allow").addEventListener("click", async () => {
78
+ let granted = false;
79
+ try {
80
+ granted = await chrome.permissions.request({ origins: [`${ask.site.origin}/*`] });
81
+ } catch {
82
+ granted = false;
83
+ }
84
+ void answer(granted);
85
+ });
86
+ }
87
+ function renderDraft(ask) {
88
+ const host = new URL(ask.site.origin).host;
89
+ document.body.dataset.kind = "draft";
90
+ document.title = `Wield \xB7 Test a new recipe on ${host}?`;
91
+ $("kind").textContent = "New recipe";
92
+ $("eyebrow").textContent = "Your agent wants to test a recipe it just built";
93
+ $("title").textContent = `Test \u201C${ask.task}\u201D on ${host}?`;
94
+ $("site").replaceChildren("Not signed or published yet. It runs once in your tab of ", el("b", "", host), ", with your login.");
95
+ const foreign = (ask.draft?.origins ?? []).filter((o) => o.foreign).map((o) => new URL(o.origin).host);
96
+ for (const o of ask.draft?.origins ?? []) {
97
+ const host2 = new URL(o.origin).host;
98
+ $("draft-origins").append(o.foreign ? el("li", "ask-field ask-field-foreign", `\u26A0 ${host2} (not ${ask.draft.domain})`) : el("li", "ask-field", host2));
99
+ }
100
+ if (foreign.length) {
101
+ const warn = $("draft-warning");
102
+ warn.textContent = `This recipe would also send requests to ${foreign.join(", ")}, which ${foreign.length === 1 ? "is" : "are"} not part of ${ask.draft.domain}. A page you recorded can make another site look like part of the task. Deny unless you expected ${foreign.length === 1 ? "this site" : "these sites"}.`;
103
+ warn.hidden = false;
104
+ }
105
+ for (const s of ask.draft?.steps ?? []) {
106
+ const li = el("li", "ask-write");
107
+ const line = el("div", "ask-request");
108
+ line.append(el("span", "ask-method", s.method), el("span", "ask-path", s.url));
109
+ li.append(line);
110
+ $("draft-steps").append(li);
111
+ }
112
+ $("draft").hidden = false;
113
+ $("note").textContent = "Anything that changes something on a site still asks you again before it is sent.";
114
+ $("allow").textContent = "Run the test";
115
+ $("allow").addEventListener("click", () => void answer(true));
116
+ }
117
+ function renderRecord(ask) {
118
+ const host = new URL(ask.site.origin).host;
119
+ document.body.dataset.kind = "record";
120
+ document.title = `Wield \xB7 Record on ${host}?`;
121
+ $("kind").textContent = "Recording";
122
+ $("eyebrow").textContent = "Your agent asks you to show it a task";
123
+ $("title").textContent = ask.task ? `Show Wield how to \u201C${ask.task}\u201D on ${host}?` : `Record a task on ${host}?`;
124
+ $("site").replaceChildren(el("b", "", host));
125
+ $("perm-text").textContent = "You do the task once in your own tab. Wield notes the requests that page makes, removes logins, cookies, tokens and what you type, and shows you exactly what it would send. Nothing leaves your browser until you click Send.";
126
+ $("perm").hidden = false;
127
+ $("perm-chrome").hidden = true;
128
+ $("note").textContent = "A Wield bar stays in the page while it records, with Done and Cancel.";
129
+ $("allow").textContent = "Allow recording";
130
+ $("allow").addEventListener("click", () => void answer(true));
131
+ }
132
+ async function main() {
133
+ const key = `ask:${id}`;
134
+ const ask = (await chrome.storage.session.get(key))[key];
135
+ if (!ask) return gone("This request has expired. Nothing was sent.");
136
+ if (ask.kind === "write" && ask.info) renderWrite(ask);
137
+ else if (ask.kind === "record") renderRecord(ask);
138
+ else if (ask.kind === "draft") renderDraft(ask);
139
+ else renderPermission(ask);
140
+ $("deny").addEventListener("click", () => void answer(false));
141
+ document.addEventListener("keydown", (e) => e.key === "Escape" && void answer(false));
142
+ setButtons(true);
143
+ $("deny").focus();
144
+ const total = Math.max(1, ask.expires_at - Date.now());
145
+ const bar = $("timer-bar");
146
+ bar.style.transitionDuration = `${total}ms`;
147
+ requestAnimationFrame(() => requestAnimationFrame(() => bar.classList.add("run")));
148
+ const tick = () => {
149
+ const left = Math.max(0, Math.round((ask.expires_at - Date.now()) / 1e3));
150
+ if (left <= 0) {
151
+ setButtons(false);
152
+ $("countdown").textContent = "No answer, so nothing was sent.";
153
+ clearInterval(timer);
154
+ return;
155
+ }
156
+ $("countdown").textContent = `No answer in ${Math.floor(left / 60)}:${String(left % 60).padStart(2, "0")} means no.`;
157
+ };
158
+ tick();
159
+ const timer = setInterval(tick, 1e3);
160
+ }
161
+ void main();
162
+ })();