@jantcz/webai 0.0.0-stage → 0.2.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/LICENSE +135 -0
- package/README.md +24 -2
- package/agents/.claude-plugin/plugin.json +4 -0
- package/agents/README.md +17 -0
- package/agents/agents/a11y-reviewer.md +16 -0
- package/agents/agents/copy-editor.md +14 -0
- package/agents/skills/czech-copy/SKILL.md +18 -0
- package/agents/skills/element-edit/SKILL.md +51 -0
- package/agents/skills/stock-images/SKILL.md +25 -0
- package/agents/skills/verify-change/SKILL.md +19 -0
- package/agents/skills/web-styling/SKILL.md +20 -0
- package/bin/webai-agent.js +355 -0
- package/bin/webai-bridge.js +5 -0
- package/bin/webai.js +4 -0
- package/package.json +85 -4
- package/src/agents/claude.js +161 -0
- package/src/agents/codex.js +111 -0
- package/src/agents/custom.js +64 -0
- package/src/agents/docker.js +46 -0
- package/src/agents/gemini.js +102 -0
- package/src/agents/index.js +25 -0
- package/src/agents/opencode.js +117 -0
- package/src/agents/pack.js +99 -0
- package/src/agents/pi.js +143 -0
- package/src/agents/webai.js +66 -0
- package/src/astro/annotate.js +163 -0
- package/src/astro/index.d.ts +5 -0
- package/src/astro/index.js +40 -0
- package/src/bridge.js +62 -0
- package/src/cli.js +108 -0
- package/src/client/overlay.js +887 -0
- package/src/config.js +23 -0
- package/src/core.js +102 -0
- package/src/history.js +108 -0
- package/src/html.js +43 -0
- package/src/index.d.ts +228 -0
- package/src/index.js +10 -0
- package/src/inject.js +80 -0
- package/src/next/index.d.ts +8 -0
- package/src/next/index.js +59 -0
- package/src/next/script.d.ts +3 -0
- package/src/next/script.js +13 -0
- package/src/prompt.js +17 -0
- package/src/proxy.js +68 -0
- package/src/server.js +211 -0
- package/src/session.js +455 -0
- package/src/static.js +64 -0
- package/src/vite.d.ts +5 -0
- package/src/vite.js +42 -0
|
@@ -0,0 +1,887 @@
|
|
|
1
|
+
// Client side: element inspector and chat panel. Runs only in development.
|
|
2
|
+
// Everything lives in the shadow DOM of <webai-overlay>, so site styles don't leak in.
|
|
3
|
+
//
|
|
4
|
+
// Talks to the agent through a transport: the default is HTTP + SSE to the dev server
|
|
5
|
+
// (`/__webai/*`); the web demo (`demo/`) injects its own that runs
|
|
6
|
+
// entirely in the browser.
|
|
7
|
+
|
|
8
|
+
const STORE_OPEN = 'webai:open';
|
|
9
|
+
const STORE_TARGET = 'webai:target';
|
|
10
|
+
const STORE_SIDE = 'webai:side';
|
|
11
|
+
const STORE_GEOMETRY = 'webai:geometry';
|
|
12
|
+
const MIN_W = 300;
|
|
13
|
+
const MIN_H = 320;
|
|
14
|
+
const STORE_TRIGGERS = 'webai:triggers';
|
|
15
|
+
|
|
16
|
+
const TRIGGERS = [
|
|
17
|
+
['shift-click', 'Shift + click'],
|
|
18
|
+
['alt-click', 'Alt + click'],
|
|
19
|
+
['contextmenu', 'Right click (Shift + right click = native menu)'],
|
|
20
|
+
];
|
|
21
|
+
|
|
22
|
+
const TOOL_ICONS = { Edit: '✎', MultiEdit: '✎', Write: '✚', Read: '◉', Bash: '$', Grep: '⌕', Glob: '⌕' };
|
|
23
|
+
|
|
24
|
+
export function start(cfg) {
|
|
25
|
+
if (window.__webai) return;
|
|
26
|
+
window.__webai = true;
|
|
27
|
+
const run = () => new Overlay(cfg);
|
|
28
|
+
if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', run, { once: true });
|
|
29
|
+
else run();
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Transport to the dev server. Interface:
|
|
34
|
+
* - `request(method, path, body)` → data; failures throw an Error with a readable message
|
|
35
|
+
* - `subscribe({ onEvent, onReady, onLost })` → unsubscribe function; first
|
|
36
|
+
* replays the whole history, then `onReady({ busy })`, then live events
|
|
37
|
+
*/
|
|
38
|
+
export function httpTransport(cfg) {
|
|
39
|
+
return {
|
|
40
|
+
async request(method, path, body) {
|
|
41
|
+
let res;
|
|
42
|
+
try {
|
|
43
|
+
res = await fetch(cfg.base + path, {
|
|
44
|
+
method,
|
|
45
|
+
headers: { 'Content-Type': 'application/json', 'X-WebAI-Token': cfg.token },
|
|
46
|
+
body: body ? JSON.stringify(body) : undefined,
|
|
47
|
+
});
|
|
48
|
+
} catch {
|
|
49
|
+
throw new Error('The dev server is not responding. Is it running? Reload the page after a restart.');
|
|
50
|
+
}
|
|
51
|
+
const data = await res.json().catch(() => ({}));
|
|
52
|
+
if (res.status === 403) throw new Error('The dev server has restarted in the meantime, reload the page.');
|
|
53
|
+
if (!res.ok) throw new Error(data.error ?? `HTTP ${res.status}`);
|
|
54
|
+
return data;
|
|
55
|
+
},
|
|
56
|
+
|
|
57
|
+
subscribe({ onEvent, onReady, onLost }) {
|
|
58
|
+
const es = new EventSource(`${cfg.base}/events?token=${cfg.token}`);
|
|
59
|
+
es.onmessage = (m) => onEvent(JSON.parse(m.data));
|
|
60
|
+
es.addEventListener('ready', (m) => onReady(JSON.parse(m.data)));
|
|
61
|
+
es.onerror = () => {
|
|
62
|
+
if (es.readyState === EventSource.CLOSED) onLost('Lost connection to the dev server. Reload the page.');
|
|
63
|
+
};
|
|
64
|
+
return () => es.close();
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
class Overlay {
|
|
70
|
+
constructor(cfg) {
|
|
71
|
+
this.cfg = cfg;
|
|
72
|
+
this.transport = cfg.transport ?? httpTransport(cfg);
|
|
73
|
+
this.target = null;
|
|
74
|
+
this.busy = false;
|
|
75
|
+
this.live = null;
|
|
76
|
+
this.unsubscribe = null;
|
|
77
|
+
this.mount();
|
|
78
|
+
this.bindInspector();
|
|
79
|
+
if (sessionStorage.getItem(STORE_OPEN) === '1') {
|
|
80
|
+
const saved = readJson(sessionStorage.getItem(STORE_TARGET));
|
|
81
|
+
if (saved) this.setTarget(saved, findElement(saved, cfg.srcAttr));
|
|
82
|
+
this.open();
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// ---------- DOM ----------
|
|
87
|
+
|
|
88
|
+
mount() {
|
|
89
|
+
this.host = document.createElement('webai-overlay');
|
|
90
|
+
const root = this.host.attachShadow({ mode: 'open' });
|
|
91
|
+
root.innerHTML = `<style>${STYLES}</style>
|
|
92
|
+
<div class="hover" hidden><span class="label"></span></div>
|
|
93
|
+
<div class="pick" hidden></div>
|
|
94
|
+
<button class="fab" hidden title="WebAI – open chat (or Shift+click an element)">✦</button>
|
|
95
|
+
<section class="panel" hidden>
|
|
96
|
+
<header>
|
|
97
|
+
<strong>WebAI</strong><span class="agent"></span>
|
|
98
|
+
<span class="spacer"></span>
|
|
99
|
+
<span class="versions" hidden><button class="back" title="Previous version">◀</button><span class="vnum"></span><button class="fwd" title="Next version">▶</button></span>
|
|
100
|
+
<button class="gear" title="Settings" aria-label="Settings">${GEAR_ICON}</button>
|
|
101
|
+
<button class="reset" title="Start a new conversation">New</button>
|
|
102
|
+
<button class="close" title="Close (Esc)">×</button>
|
|
103
|
+
</header>
|
|
104
|
+
<div class="settings" hidden></div>
|
|
105
|
+
<div class="log"></div>
|
|
106
|
+
<div class="target" hidden><code></code><button title="Don't send the element">×</button></div>
|
|
107
|
+
<form>
|
|
108
|
+
<textarea rows="2" placeholder="What should happen to the element? Enter sends, Shift+Enter adds a new line"></textarea>
|
|
109
|
+
<button type="submit" class="send">Send</button>
|
|
110
|
+
</form>
|
|
111
|
+
<footer class="hint"></footer>
|
|
112
|
+
<div class="grip nw" data-grip="-1,-1"></div><div class="grip ne" data-grip="1,-1"></div>
|
|
113
|
+
<div class="grip sw" data-grip="-1,1"></div><div class="grip se" data-grip="1,1"></div>
|
|
114
|
+
</section>`;
|
|
115
|
+
const $ = (s) => root.querySelector(s);
|
|
116
|
+
this.el = {
|
|
117
|
+
hover: $('.hover'), label: $('.hover .label'), pick: $('.pick'), panel: $('.panel'),
|
|
118
|
+
agent: $('.agent'), log: $('.log'), target: $('.target'), targetCode: $('.target code'),
|
|
119
|
+
form: $('form'), input: $('textarea'), send: $('.send'), fab: $('.fab'), settings: $('.settings'),
|
|
120
|
+
gear: $('.gear'), hint: $('.hint'),
|
|
121
|
+
versions: $('.versions'), vnum: $('.vnum'), back: $('.back'), fwd: $('.fwd'),
|
|
122
|
+
};
|
|
123
|
+
this.el.back.onclick = () => this.restoreVersion(this.history.current - 1);
|
|
124
|
+
this.el.fwd.onclick = () => this.restoreVersion(this.history.current + 1);
|
|
125
|
+
$('.close').onclick = () => this.close();
|
|
126
|
+
$('.reset').onclick = () => this.reset();
|
|
127
|
+
this.el.gear.onclick = () => this.toggleSettings();
|
|
128
|
+
this.el.fab.onclick = () => {
|
|
129
|
+
this.open();
|
|
130
|
+
this.el.input.focus();
|
|
131
|
+
};
|
|
132
|
+
this.el.fab.hidden = !this.cfg.fab;
|
|
133
|
+
$('.target button').onclick = () => this.setTarget(null);
|
|
134
|
+
this.el.form.onsubmit = (e) => {
|
|
135
|
+
e.preventDefault();
|
|
136
|
+
this.busy ? this.stop() : this.send();
|
|
137
|
+
};
|
|
138
|
+
this.el.input.addEventListener('keydown', (e) => {
|
|
139
|
+
if (e.key === 'Enter' && !e.shiftKey && !e.isComposing) {
|
|
140
|
+
e.preventDefault();
|
|
141
|
+
if (!this.busy) this.send();
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
this.applySide();
|
|
145
|
+
this.initGeometry(root);
|
|
146
|
+
this.updateHint();
|
|
147
|
+
document.documentElement.appendChild(this.host);
|
|
148
|
+
const follow = () => this.drawPick();
|
|
149
|
+
addEventListener('scroll', follow, { passive: true, capture: true });
|
|
150
|
+
addEventListener('resize', follow, { passive: true });
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// ---------- inspector ----------
|
|
154
|
+
|
|
155
|
+
// Read on every mouse move, so cached in memory rather than read from localStorage.
|
|
156
|
+
get triggers() {
|
|
157
|
+
this._triggers ??= readJson(localStorage.getItem(STORE_TRIGGERS)) ?? this.cfg.triggers;
|
|
158
|
+
return this._triggers;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
bindInspector() {
|
|
162
|
+
const ours = (e) => e.composedPath().includes(this.host);
|
|
163
|
+
const armed = (e) => {
|
|
164
|
+
const triggers = this.triggers;
|
|
165
|
+
return (triggers.includes('shift-click') && e.shiftKey && !e.metaKey && !e.ctrlKey) ||
|
|
166
|
+
(triggers.includes('alt-click') && e.altKey && !e.metaKey && !e.ctrlKey);
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
addEventListener('mousemove', (e) => {
|
|
170
|
+
if (!armed(e) || ours(e)) return this.hideHover();
|
|
171
|
+
this.showHover(e.target);
|
|
172
|
+
}, { passive: true, capture: true });
|
|
173
|
+
addEventListener('keyup', (e) => (e.key === 'Shift' || e.key === 'Alt') && this.hideHover(), true);
|
|
174
|
+
addEventListener('blur', () => this.hideHover());
|
|
175
|
+
|
|
176
|
+
// Otherwise Shift+mousedown would start selecting text.
|
|
177
|
+
addEventListener('mousedown', (e) => {
|
|
178
|
+
if (e.button === 0 && armed(e) && !ours(e)) e.preventDefault();
|
|
179
|
+
}, true);
|
|
180
|
+
addEventListener('click', (e) => {
|
|
181
|
+
if (e.button !== 0 || !armed(e) || ours(e)) return;
|
|
182
|
+
e.preventDefault();
|
|
183
|
+
e.stopImmediatePropagation();
|
|
184
|
+
this.pick(e.target);
|
|
185
|
+
}, true);
|
|
186
|
+
// Shift+right click keeps the native menu (Inspect element).
|
|
187
|
+
addEventListener('contextmenu', (e) => {
|
|
188
|
+
if (!this.triggers.includes('contextmenu') || e.shiftKey || ours(e)) return;
|
|
189
|
+
e.preventDefault();
|
|
190
|
+
this.pick(e.target);
|
|
191
|
+
}, true);
|
|
192
|
+
addEventListener('keydown', (e) => {
|
|
193
|
+
if (e.key === 'Escape' && !this.el.panel.hidden) this.close();
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
showHover(node) {
|
|
198
|
+
const el = node instanceof Element ? node : node.parentElement;
|
|
199
|
+
if (!el) return;
|
|
200
|
+
const r = el.getBoundingClientRect();
|
|
201
|
+
Object.assign(this.el.hover.style, box(r));
|
|
202
|
+
const src = el.closest(`[${this.cfg.srcAttr}]`)?.getAttribute(this.cfg.srcAttr);
|
|
203
|
+
this.el.label.textContent = `${el.tagName.toLowerCase()}${src ? ` ${src}` : ''}`;
|
|
204
|
+
this.el.label.classList.toggle('below', r.top < 24);
|
|
205
|
+
this.el.hover.hidden = false;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
hideHover() {
|
|
209
|
+
this.el.hover.hidden = true;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
pick(node) {
|
|
213
|
+
const el = node instanceof Element ? node : node.parentElement;
|
|
214
|
+
if (!el) return;
|
|
215
|
+
this.hideHover();
|
|
216
|
+
getSelection()?.removeAllRanges(); // Shift+click extends the text selection
|
|
217
|
+
this.setTarget(describe(el, this.cfg.srcAttr), el);
|
|
218
|
+
this.open();
|
|
219
|
+
this.el.input.focus();
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
setTarget(info, el = null) {
|
|
223
|
+
this.target = info;
|
|
224
|
+
this.targetEl = el;
|
|
225
|
+
if (info) sessionStorage.setItem(STORE_TARGET, JSON.stringify(info));
|
|
226
|
+
else sessionStorage.removeItem(STORE_TARGET);
|
|
227
|
+
this.el.target.hidden = !info;
|
|
228
|
+
if (info) this.el.targetCode.textContent = `<${info.tag.match(/^<?([\w-]+)/)?.[1] ?? '?'}> ${info.src ?? info.selector}`;
|
|
229
|
+
this.drawPick();
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
drawPick() {
|
|
233
|
+
const el = this.targetEl;
|
|
234
|
+
if (!el || !el.isConnected || this.el.panel.hidden) {
|
|
235
|
+
this.el.pick.hidden = true;
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
Object.assign(this.el.pick.style, box(el.getBoundingClientRect()));
|
|
239
|
+
this.el.pick.hidden = false;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
// ---------- panel ----------
|
|
243
|
+
|
|
244
|
+
open() {
|
|
245
|
+
sessionStorage.setItem(STORE_OPEN, '1');
|
|
246
|
+
this.el.panel.hidden = false;
|
|
247
|
+
this.el.fab.hidden = true;
|
|
248
|
+
this.drawPick();
|
|
249
|
+
if (!this.unsubscribe) this.connect();
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
close() {
|
|
253
|
+
sessionStorage.removeItem(STORE_OPEN);
|
|
254
|
+
this.el.panel.hidden = true;
|
|
255
|
+
this.el.pick.hidden = true;
|
|
256
|
+
this.el.fab.hidden = !this.cfg.fab;
|
|
257
|
+
this.showSettings(false);
|
|
258
|
+
this.unsubscribe?.();
|
|
259
|
+
this.unsubscribe = null;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
applySide() {
|
|
263
|
+
const left = localStorage.getItem(STORE_SIDE) === 'left';
|
|
264
|
+
this.el.panel.classList.toggle('left', left);
|
|
265
|
+
this.el.fab.classList.toggle('left', left);
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
// ---------- moving and resizing ----------
|
|
269
|
+
|
|
270
|
+
// The header moves the panel, the corners resize it; both remember the result.
|
|
271
|
+
// A double click on the header docks it back to its side at its default size.
|
|
272
|
+
initGeometry(root) {
|
|
273
|
+
const header = root.querySelector('header');
|
|
274
|
+
header.addEventListener('pointerdown', (e) => {
|
|
275
|
+
if (e.button === 0 && !e.target.closest('button')) this.gesture(e, null);
|
|
276
|
+
});
|
|
277
|
+
header.addEventListener('dblclick', (e) => {
|
|
278
|
+
if (e.target.closest('button')) return;
|
|
279
|
+
localStorage.removeItem(STORE_GEOMETRY);
|
|
280
|
+
this.applyGeometry();
|
|
281
|
+
});
|
|
282
|
+
for (const grip of root.querySelectorAll('[data-grip]')) {
|
|
283
|
+
grip.addEventListener('pointerdown', (e) => {
|
|
284
|
+
if (e.button === 0) this.gesture(e, grip.dataset.grip.split(',').map(Number));
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
addEventListener('resize', () => this.applyGeometry(), { passive: true });
|
|
288
|
+
this.applyGeometry();
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/** Move (`dir` null) or resize from a corner (`dir` = [±1, ±1]) while the pointer is down. */
|
|
292
|
+
gesture(e, dir) {
|
|
293
|
+
e.preventDefault();
|
|
294
|
+
const panel = this.el.panel;
|
|
295
|
+
const start = panel.getBoundingClientRect();
|
|
296
|
+
const [x0, y0] = [e.clientX, e.clientY];
|
|
297
|
+
let started = false;
|
|
298
|
+
const move = (ev) => {
|
|
299
|
+
const dx = ev.clientX - x0;
|
|
300
|
+
const dy = ev.clientY - y0;
|
|
301
|
+
// A click (or the first half of a double click) moves nothing.
|
|
302
|
+
if (!started) {
|
|
303
|
+
if (Math.hypot(dx, dy) < 4) return;
|
|
304
|
+
started = true;
|
|
305
|
+
panel.setPointerCapture(ev.pointerId);
|
|
306
|
+
panel.classList.add('dragging');
|
|
307
|
+
}
|
|
308
|
+
let { left: x, top: y, width: w, height: h } = start;
|
|
309
|
+
if (!dir) {
|
|
310
|
+
x += dx;
|
|
311
|
+
y += dy;
|
|
312
|
+
} else {
|
|
313
|
+
const [sx, sy] = dir;
|
|
314
|
+
const nw = Math.max(MIN_W, w + sx * dx);
|
|
315
|
+
const nh = Math.max(MIN_H, h + sy * dy);
|
|
316
|
+
if (sx < 0) x += w - nw;
|
|
317
|
+
if (sy < 0) y += h - nh;
|
|
318
|
+
[w, h] = [nw, nh];
|
|
319
|
+
}
|
|
320
|
+
this.applyGeometry({ x, y, w, h });
|
|
321
|
+
};
|
|
322
|
+
const end = (ev) => {
|
|
323
|
+
removeEventListener('pointermove', move);
|
|
324
|
+
removeEventListener('pointerup', end);
|
|
325
|
+
removeEventListener('pointercancel', end);
|
|
326
|
+
if (!started) return;
|
|
327
|
+
panel.releasePointerCapture(ev.pointerId);
|
|
328
|
+
panel.classList.remove('dragging');
|
|
329
|
+
const r = panel.getBoundingClientRect();
|
|
330
|
+
localStorage.setItem(STORE_GEOMETRY, JSON.stringify({ x: r.left, y: r.top, w: r.width, h: r.height }));
|
|
331
|
+
};
|
|
332
|
+
addEventListener('pointermove', move);
|
|
333
|
+
addEventListener('pointerup', end);
|
|
334
|
+
addEventListener('pointercancel', end);
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
/** The remembered (or given) position and size, kept inside the window; none = docked to its side. */
|
|
338
|
+
applyGeometry(g = JSON.parse(localStorage.getItem(STORE_GEOMETRY) ?? 'null')) {
|
|
339
|
+
const style = this.el.panel.style;
|
|
340
|
+
if (!g) {
|
|
341
|
+
for (const k of ['left', 'top', 'width', 'height', 'right', 'bottom']) style[k] = '';
|
|
342
|
+
return;
|
|
343
|
+
}
|
|
344
|
+
const w = Math.min(Math.max(MIN_W, g.w), innerWidth - 16);
|
|
345
|
+
const h = Math.min(Math.max(MIN_H, g.h), innerHeight - 16);
|
|
346
|
+
const x = Math.min(Math.max(8, g.x), innerWidth - w - 8);
|
|
347
|
+
const y = Math.min(Math.max(8, g.y), innerHeight - h - 8);
|
|
348
|
+
Object.assign(style, { left: `${x}px`, top: `${y}px`, width: `${w}px`, height: `${h}px`, right: 'auto', bottom: 'auto' });
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
// ---------- settings ----------
|
|
352
|
+
|
|
353
|
+
toggleSettings() {
|
|
354
|
+
this.showSettings(this.el.settings.hidden);
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
async showSettings(show) {
|
|
358
|
+
this.el.settings.hidden = !show;
|
|
359
|
+
this.el.log.hidden = show;
|
|
360
|
+
this.el.form.hidden = show;
|
|
361
|
+
this.el.gear.classList.toggle('active', show);
|
|
362
|
+
this.el.target.hidden = show || !this.target;
|
|
363
|
+
if (show) await this.renderSettings();
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
async renderSettings() {
|
|
367
|
+
const box = this.el.settings;
|
|
368
|
+
let state;
|
|
369
|
+
try {
|
|
370
|
+
state = await this.api('GET', '/state');
|
|
371
|
+
} catch (err) {
|
|
372
|
+
box.textContent = err.message;
|
|
373
|
+
return;
|
|
374
|
+
}
|
|
375
|
+
this.el.agent.textContent = state.agent;
|
|
376
|
+
const current = state.agents.find((a) => a.name === state.settings.agent);
|
|
377
|
+
const mine = state.settings[current.name] ?? {};
|
|
378
|
+
// Choices with a `group` go into <optgroup>s, in the order the groups first appear.
|
|
379
|
+
const options = (choices, value) => {
|
|
380
|
+
const option = (c) => `<option value="${escapeHtml(c.value)}"${c.value === value ? ' selected' : ''}${c.disabled ? ' disabled' : ''}>${escapeHtml(c.label)}</option>`;
|
|
381
|
+
return [...new Set(choices.map((c) => c.group ?? ''))]
|
|
382
|
+
.map((g) => {
|
|
383
|
+
const inner = choices.filter((c) => (c.group ?? '') === g).map(option).join('');
|
|
384
|
+
return g ? `<optgroup label="${escapeHtml(g)}">${inner}</optgroup>` : inner;
|
|
385
|
+
})
|
|
386
|
+
.join('');
|
|
387
|
+
};
|
|
388
|
+
const select = (key, label, choices, value, hint = '') => `
|
|
389
|
+
<label>${escapeHtml(label)}<select data-key="${escapeHtml(key)}">${options(choices, value)}</select>${hint ? `<small>${escapeHtml(hint)}</small>` : ''}</label>`;
|
|
390
|
+
const triggers = this.triggers;
|
|
391
|
+
box.innerHTML = `
|
|
392
|
+
<h3>Agent</h3>
|
|
393
|
+
${state.agents.length < 2 ? '' : select('agent', 'CLI', state.agents.map((a) => ({
|
|
394
|
+
value: a.name,
|
|
395
|
+
label: a.version ? `${a.label} (${a.version})` : `${a.label}: not installed`,
|
|
396
|
+
disabled: !a.version,
|
|
397
|
+
})), current.name, 'Each agent has its own conversation. Switching back to an agent resumes its context.')}
|
|
398
|
+
${Object.entries(current.settings).map(([key, spec]) => Array.isArray(spec)
|
|
399
|
+
? select(key, SETTING_LABELS[key] ?? key, spec, mine[key] ?? '', SETTING_HINTS[key])
|
|
400
|
+
: spec.type === 'action'
|
|
401
|
+
? `<div class="action"><button type="button" data-action="${escapeHtml(spec.action)}">${escapeHtml(spec.label)}</button>${spec.hint ? `<small>${escapeHtml(spec.hint)}</small>` : ''}</div>`
|
|
402
|
+
: `<label>${escapeHtml(spec.label ?? key)}<input type="${spec.secret ? 'password' : 'text'}" data-text="${escapeHtml(key)}" value="${escapeHtml((!spec.readonly && mine[key]) || spec.default || '')}" placeholder="${escapeHtml(spec.placeholder ?? '')}" spellcheck="false"${spec.readonly ? ' disabled' : ''}>${spec.hint ? `<small>${escapeHtml(spec.hint)}</small>` : ''}</label>`).join('')}
|
|
403
|
+
<h3>Element picking</h3>
|
|
404
|
+
${TRIGGERS.map(([value, label]) => `<label class="check"><input type="checkbox" data-trigger="${value}"${triggers.includes(value) ? ' checked' : ''}> ${label}</label>`).join('')}
|
|
405
|
+
<h3>Panel</h3>
|
|
406
|
+
${select('side', 'Position', [{ value: 'right', label: 'Right' }, { value: 'left', label: 'Left' }], localStorage.getItem(STORE_SIDE) ?? 'right')}
|
|
407
|
+
<h3>Conversation</h3>
|
|
408
|
+
<p class="meta">${escapeHtml(current.label)} · ${state.session.started ? `session <code>${escapeHtml(String(state.session.id).slice(0, 8))}</code>` : 'not started yet'}${state.session.totalCostUsd ? ` · total $${state.session.totalCostUsd.toFixed(3)}` : ''}</p>`;
|
|
409
|
+
|
|
410
|
+
for (const el of box.querySelectorAll('select[data-key]')) {
|
|
411
|
+
el.onchange = () => this.changeSetting(el.dataset.key, el.value, current.name);
|
|
412
|
+
}
|
|
413
|
+
for (const el of box.querySelectorAll('input[data-text]')) {
|
|
414
|
+
// Saved on blur or Enter, not on every keystroke.
|
|
415
|
+
el.onchange = () => this.changeSetting(el.dataset.text, el.value, current.name);
|
|
416
|
+
el.onkeydown = (e) => e.key === 'Enter' && el.blur();
|
|
417
|
+
}
|
|
418
|
+
// Buttons the agent offers (e.g. signing in to a provider in the browser editor).
|
|
419
|
+
for (const el of box.querySelectorAll('button[data-action]')) {
|
|
420
|
+
el.onclick = async () => {
|
|
421
|
+
try {
|
|
422
|
+
await this.api('POST', '/action', { agent: current.name, action: el.dataset.action });
|
|
423
|
+
} catch (err) {
|
|
424
|
+
return this.flashSettingsError(err.message);
|
|
425
|
+
}
|
|
426
|
+
await this.renderSettings();
|
|
427
|
+
};
|
|
428
|
+
}
|
|
429
|
+
for (const el of box.querySelectorAll('input[data-trigger]')) {
|
|
430
|
+
el.onchange = () => {
|
|
431
|
+
const picked = [...box.querySelectorAll('input[data-trigger]:checked')].map((i) => i.dataset.trigger);
|
|
432
|
+
localStorage.setItem(STORE_TRIGGERS, JSON.stringify(picked));
|
|
433
|
+
this._triggers = picked;
|
|
434
|
+
this.updateHint();
|
|
435
|
+
};
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
async changeSetting(key, value, agentName) {
|
|
440
|
+
if (key === 'side') {
|
|
441
|
+
localStorage.setItem(STORE_SIDE, value);
|
|
442
|
+
localStorage.removeItem(STORE_GEOMETRY); // choosing a side docks the panel there
|
|
443
|
+
this.applySide();
|
|
444
|
+
this.applyGeometry();
|
|
445
|
+
return;
|
|
446
|
+
}
|
|
447
|
+
try {
|
|
448
|
+
await this.api('POST', '/settings', key === 'agent' ? { agent: value } : { [agentName]: { [key]: value } });
|
|
449
|
+
} catch (err) {
|
|
450
|
+
this.flashSettingsError(err.message);
|
|
451
|
+
}
|
|
452
|
+
await this.renderSettings();
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
flashSettingsError(text) {
|
|
456
|
+
const p = document.createElement('p');
|
|
457
|
+
p.className = 'msg error';
|
|
458
|
+
p.textContent = text;
|
|
459
|
+
this.el.settings.prepend(p);
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
updateHint() {
|
|
463
|
+
const labels = TRIGGERS.filter(([v]) => this.triggers.includes(v)).map(([, l]) => l.split(' (')[0]);
|
|
464
|
+
this.el.hint.textContent = labels.length ? `${labels.join(' / ')} selects an element on the page` : 'Element picking is off (⚙)';
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
connect() {
|
|
468
|
+
this.el.log.textContent = '';
|
|
469
|
+
this.live = null;
|
|
470
|
+
this.unsubscribe = this.transport.subscribe({
|
|
471
|
+
onEvent: (ev) => this.handle(ev),
|
|
472
|
+
onReady: ({ busy }) => {
|
|
473
|
+
this.caughtUp = true; // events from here on are new, not the replayed history
|
|
474
|
+
this.setBusy(busy);
|
|
475
|
+
this.scroll(true);
|
|
476
|
+
},
|
|
477
|
+
onLost: (text) => {
|
|
478
|
+
this.line('error', text);
|
|
479
|
+
this.unsubscribe = null;
|
|
480
|
+
},
|
|
481
|
+
});
|
|
482
|
+
this.api('GET', '/state').then((s) => (this.el.agent.textContent = s.agent)).catch(() => {});
|
|
483
|
+
this.loadHistory();
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
// ---------- versions ----------
|
|
487
|
+
|
|
488
|
+
loadHistory() {
|
|
489
|
+
this.api('GET', '/history').then((h) => this.showHistory(h)).catch(() => {});
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
showHistory(h) {
|
|
493
|
+
this.history = h;
|
|
494
|
+
const { versions, current } = h;
|
|
495
|
+
this.el.versions.hidden = !h.enabled || versions.length < 2;
|
|
496
|
+
this.el.vnum.textContent = `v${current + 1}/${versions.length}`;
|
|
497
|
+
const v = versions[current];
|
|
498
|
+
this.el.vnum.title = v ? `${v.label} · ${new Date(v.ts).toLocaleString()}` : '';
|
|
499
|
+
this.el.back.disabled = this.busy || current <= 0;
|
|
500
|
+
this.el.fwd.disabled = this.busy || current >= versions.length - 1;
|
|
501
|
+
const tip = (i) => (versions[i] ? `: ${versions[i].label}` : '');
|
|
502
|
+
this.el.back.title = `Previous version${tip(current - 1)}`;
|
|
503
|
+
this.el.fwd.title = `Next version${tip(current + 1)}`;
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
async restoreVersion(index) {
|
|
507
|
+
try {
|
|
508
|
+
this.showHistory(await this.api('POST', '/history/restore', { index }));
|
|
509
|
+
} catch (err) {
|
|
510
|
+
this.line('error', err.message);
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
api(method, path, body) {
|
|
515
|
+
return this.transport.request(method, path, body);
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
async send() {
|
|
519
|
+
const message = this.el.input.value.trim();
|
|
520
|
+
if (!message) return;
|
|
521
|
+
// After an edit and reload the element may have moved or disappeared: describe it again.
|
|
522
|
+
if (this.target && this.targetEl?.isConnected) this.target = describe(this.targetEl, this.cfg.srcAttr);
|
|
523
|
+
this.setBusy(true);
|
|
524
|
+
try {
|
|
525
|
+
await this.api('POST', '/send', {
|
|
526
|
+
message,
|
|
527
|
+
element: this.target,
|
|
528
|
+
page: { url: location.pathname + location.search, title: document.title },
|
|
529
|
+
});
|
|
530
|
+
this.el.input.value = '';
|
|
531
|
+
} catch (err) {
|
|
532
|
+
this.setBusy(false);
|
|
533
|
+
this.line('error', err.message);
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
stop() {
|
|
538
|
+
this.api('POST', '/stop').catch((err) => this.line('error', err.message));
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
reset() {
|
|
542
|
+
if (this.el.log.childElementCount && !confirmReset()) {
|
|
543
|
+
this.line('status', 'Click "New" again to discard the context and start a new conversation.');
|
|
544
|
+
this.scroll(true);
|
|
545
|
+
return;
|
|
546
|
+
}
|
|
547
|
+
this.api('POST', '/reset').catch((err) => this.line('error', err.message));
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
setBusy(busy) {
|
|
551
|
+
this.busy = busy;
|
|
552
|
+
this.el.send.textContent = busy ? 'Stop' : 'Send';
|
|
553
|
+
this.el.send.classList.toggle('stop', busy);
|
|
554
|
+
this.el.panel.classList.toggle('busy', busy);
|
|
555
|
+
this.el.fab.classList.toggle('busy', busy);
|
|
556
|
+
if (this.history) this.showHistory(this.history);
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
// ---------- agent events ----------
|
|
560
|
+
|
|
561
|
+
handle(ev) {
|
|
562
|
+
const stick = this.atBottom();
|
|
563
|
+
switch (ev.type) {
|
|
564
|
+
case 'reset':
|
|
565
|
+
this.el.log.textContent = '';
|
|
566
|
+
this.live = null;
|
|
567
|
+
this.setBusy(false);
|
|
568
|
+
break;
|
|
569
|
+
case 'user': {
|
|
570
|
+
const div = this.line('user', '');
|
|
571
|
+
div.textContent = ev.text;
|
|
572
|
+
const where = ev.element?.src ?? ev.element?.selector;
|
|
573
|
+
const how = [ev.agent, ev.settings?.model, ev.settings?.effort].filter(Boolean).join(' · ');
|
|
574
|
+
if (where || how) {
|
|
575
|
+
const chip = document.createElement('code');
|
|
576
|
+
chip.textContent = [where, how].filter(Boolean).join(' · ');
|
|
577
|
+
div.prepend(chip);
|
|
578
|
+
}
|
|
579
|
+
this.live = null;
|
|
580
|
+
break;
|
|
581
|
+
}
|
|
582
|
+
case 'status':
|
|
583
|
+
if (ev.busy) this.setBusy(true);
|
|
584
|
+
else this.line('status', ev.text);
|
|
585
|
+
break;
|
|
586
|
+
case 'delta':
|
|
587
|
+
this.live ??= this.line('assistant live', '');
|
|
588
|
+
this.live.dataset.raw = (this.live.dataset.raw ?? '') + ev.text;
|
|
589
|
+
this.live.innerHTML = render(this.live.dataset.raw, ev.plain);
|
|
590
|
+
break;
|
|
591
|
+
case 'text':
|
|
592
|
+
if (this.live) {
|
|
593
|
+
this.live.classList.remove('live');
|
|
594
|
+
this.live.innerHTML = render(ev.text, ev.plain);
|
|
595
|
+
this.live = null;
|
|
596
|
+
} else {
|
|
597
|
+
this.line('assistant', '').innerHTML = render(ev.text, ev.plain);
|
|
598
|
+
}
|
|
599
|
+
break;
|
|
600
|
+
case 'tool':
|
|
601
|
+
this.live = null;
|
|
602
|
+
this.line('tool', `${TOOL_ICONS[ev.name] ?? '•'} ${ev.name} ${ev.summary ?? ''}`);
|
|
603
|
+
break;
|
|
604
|
+
case 'tool-error':
|
|
605
|
+
this.line('tool error', ev.text);
|
|
606
|
+
break;
|
|
607
|
+
case 'denied':
|
|
608
|
+
this.line('denied', `Denied: ${ev.name} ${ev.summary ?? ''}. Allow it in options.claude.allowedTools.`);
|
|
609
|
+
break;
|
|
610
|
+
case 'history':
|
|
611
|
+
// Without hot reload (CLI, Next.js wrapper) the page shows the new files after a reload.
|
|
612
|
+
// A moment first: a dev server behind the proxy may not have noticed the change yet.
|
|
613
|
+
if (this.cfg.reload && ev.reload && this.caughtUp) setTimeout(() => location.reload(), 400);
|
|
614
|
+
else this.loadHistory();
|
|
615
|
+
break;
|
|
616
|
+
case 'done': {
|
|
617
|
+
this.live = null;
|
|
618
|
+
this.setBusy(false);
|
|
619
|
+
if (!ev.ok) this.line('error', ev.error ?? 'The agent finished with an error.');
|
|
620
|
+
const meta = [ev.durationMs && `${Math.round(ev.durationMs / 1000)} s`, ev.costUsd != null && `$${ev.costUsd.toFixed(3)}`]
|
|
621
|
+
.filter(Boolean).join(' · ');
|
|
622
|
+
if (ev.ok) this.line('meta', meta ? `done · ${meta}` : 'done');
|
|
623
|
+
break;
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
this.scroll(stick);
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
line(kind, text) {
|
|
630
|
+
const div = document.createElement('div');
|
|
631
|
+
div.className = `msg ${kind}`;
|
|
632
|
+
div.textContent = text;
|
|
633
|
+
this.el.log.appendChild(div);
|
|
634
|
+
return div;
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
atBottom() {
|
|
638
|
+
const l = this.el.log;
|
|
639
|
+
return l.scrollHeight - l.scrollTop - l.clientHeight < 40;
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
scroll(stick) {
|
|
643
|
+
if (stick) this.el.log.scrollTop = this.el.log.scrollHeight;
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
// ---------- element description for the agent ----------
|
|
648
|
+
|
|
649
|
+
function describe(el, srcAttr) {
|
|
650
|
+
const annotated = el.closest(`[${srcAttr}]`);
|
|
651
|
+
const src = annotated?.getAttribute(srcAttr);
|
|
652
|
+
|
|
653
|
+
// Where the component is used: nearest ancestors from other files.
|
|
654
|
+
const chain = [];
|
|
655
|
+
let file = src?.split(':')[0];
|
|
656
|
+
for (let p = annotated?.parentElement?.closest(`[${srcAttr}]`); p && chain.length < 4; p = p.parentElement?.closest(`[${srcAttr}]`)) {
|
|
657
|
+
const s = p.getAttribute(srcAttr);
|
|
658
|
+
const f = s.split(':')[0];
|
|
659
|
+
if (f !== file) {
|
|
660
|
+
chain.push(s);
|
|
661
|
+
file = f;
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
const testEl = el.closest('[data-testid],[data-test-id],[data-test]');
|
|
666
|
+
return {
|
|
667
|
+
src,
|
|
668
|
+
exact: annotated === el,
|
|
669
|
+
chain,
|
|
670
|
+
tag: openTag(el),
|
|
671
|
+
testId: testEl?.getAttribute('data-testid') ?? testEl?.getAttribute('data-test-id') ?? testEl?.getAttribute('data-test') ?? undefined,
|
|
672
|
+
selector: selectorOf(el),
|
|
673
|
+
text: (el.innerText ?? el.textContent ?? '').replace(/\s+/g, ' ').trim().slice(0, 200) || undefined,
|
|
674
|
+
html: cleanHtml(el.outerHTML, srcAttr).slice(0, 1500),
|
|
675
|
+
};
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
function findElement(info, srcAttr) {
|
|
679
|
+
if (info.src) {
|
|
680
|
+
const els = document.querySelectorAll(`[${srcAttr}="${CSS.escape(info.src)}"]`);
|
|
681
|
+
if (els.length === 1) return els[0];
|
|
682
|
+
}
|
|
683
|
+
try {
|
|
684
|
+
return document.querySelector(info.selector);
|
|
685
|
+
} catch {
|
|
686
|
+
return null;
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
function openTag(el) {
|
|
691
|
+
const attrs = [...el.attributes]
|
|
692
|
+
.filter((a) => !noise(a.name))
|
|
693
|
+
.map((a) => (a.value ? `${a.name}="${a.value.slice(0, 80)}"` : a.name));
|
|
694
|
+
return `<${el.tagName.toLowerCase()}${attrs.length ? ' ' + attrs.join(' ') : ''}>`;
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
function noise(name) {
|
|
698
|
+
return name.startsWith('data-webai-') || name.startsWith('data-astro-cid') || name === 'data-astro-source-file' || name === 'data-astro-source-loc';
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
function cleanHtml(html, srcAttr) {
|
|
702
|
+
return html
|
|
703
|
+
.replace(new RegExp(`\\s${srcAttr}="[^"]*"`, 'g'), '')
|
|
704
|
+
.replace(/\sdata-astro-cid-[\w-]+(="[^"]*")?/g, '');
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
function selectorOf(el) {
|
|
708
|
+
const parts = [];
|
|
709
|
+
for (let n = el; n && n.nodeType === 1 && n !== document.documentElement && parts.length < 6; n = n.parentElement) {
|
|
710
|
+
if (n.id) {
|
|
711
|
+
parts.unshift(`#${CSS.escape(n.id)}`);
|
|
712
|
+
break;
|
|
713
|
+
}
|
|
714
|
+
let part = n.tagName.toLowerCase();
|
|
715
|
+
const classes = [...n.classList].filter((c) => !c.startsWith('astro-')).slice(0, 2);
|
|
716
|
+
if (classes.length) part += classes.map((c) => `.${CSS.escape(c)}`).join('');
|
|
717
|
+
const same = n.parentElement ? [...n.parentElement.children].filter((c) => c.tagName === n.tagName) : [];
|
|
718
|
+
if (same.length > 1) part += `:nth-of-type(${same.indexOf(n) + 1})`;
|
|
719
|
+
parts.unshift(part);
|
|
720
|
+
}
|
|
721
|
+
return parts.join(' > ');
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
// ---------- helpers ----------
|
|
725
|
+
|
|
726
|
+
function box(r) {
|
|
727
|
+
return { top: `${r.top}px`, left: `${r.left}px`, width: `${r.width}px`, height: `${r.height}px` };
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
function readJson(s) {
|
|
731
|
+
try {
|
|
732
|
+
return s ? JSON.parse(s) : null;
|
|
733
|
+
} catch {
|
|
734
|
+
return null;
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
|
|
738
|
+
function confirmReset() {
|
|
739
|
+
// No window.confirm: it blocks the page. A second click within 3 s confirms.
|
|
740
|
+
const now = Date.now();
|
|
741
|
+
const ok = now - (confirmReset.at ?? 0) < 3000;
|
|
742
|
+
confirmReset.at = now;
|
|
743
|
+
return ok;
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
function escapeHtml(s) {
|
|
747
|
+
return String(s ?? '').replace(/[&<>"]/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"' })[c]);
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
/** Custom command output is plain text; agent replies are Markdown. */
|
|
751
|
+
function render(text, plain) {
|
|
752
|
+
return plain ? `<pre class="plain">${escapeHtml(text)}</pre>` : markdown(text);
|
|
753
|
+
}
|
|
754
|
+
|
|
755
|
+
function markdown(src) {
|
|
756
|
+
const blocks = escapeHtml(src).split(/```(?:[\w-]*)\n?/);
|
|
757
|
+
return blocks
|
|
758
|
+
.map((b, i) =>
|
|
759
|
+
i % 2
|
|
760
|
+
? `<pre>${b}</pre>`
|
|
761
|
+
: b
|
|
762
|
+
.replace(/`([^`\n]+)`/g, '<code>$1</code>')
|
|
763
|
+
.replace(/\*\*([^*\n]+)\*\*/g, '<strong>$1</strong>')
|
|
764
|
+
.replace(/\n/g, '<br>'),
|
|
765
|
+
)
|
|
766
|
+
.join('');
|
|
767
|
+
}
|
|
768
|
+
|
|
769
|
+
const SETTING_LABELS = { model: 'Model', effort: 'Effort', thinking: 'Thinking', provider: 'Provider' };
|
|
770
|
+
const SETTING_HINTS = {
|
|
771
|
+
model: 'Switching models mid-conversation makes the next message more expensive once, because the new model has to write the whole context to the cache again.',
|
|
772
|
+
};
|
|
773
|
+
|
|
774
|
+
const GEAR_ICON = `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="12" r="3"/><path d="M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 1 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 1 1-4 0v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 1 1-2.83-2.83l.06-.06A1.65 1.65 0 0 0 4.68 15a1.65 1.65 0 0 0-1.51-1H3a2 2 0 1 1 0-4h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 1 1 2.83-2.83l.06.06A1.65 1.65 0 0 0 9 4.68a1.65 1.65 0 0 0 1-1.51V3a2 2 0 1 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 1 1 2.83 2.83l-.06.06A1.65 1.65 0 0 0 19.4 9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 1 1 0 4h-.09a1.65 1.65 0 0 0-1.51 1z"/></svg>`;
|
|
775
|
+
|
|
776
|
+
const STYLES = `
|
|
777
|
+
:host { all: initial; }
|
|
778
|
+
* { box-sizing: border-box; }
|
|
779
|
+
.hover, .pick {
|
|
780
|
+
position: fixed; pointer-events: none; z-index: 2147483646;
|
|
781
|
+
outline: 2px solid #7c5cff; background: rgba(124, 92, 255, .12); border-radius: 2px;
|
|
782
|
+
}
|
|
783
|
+
.pick { outline: 2px dashed #ffb020; background: transparent; }
|
|
784
|
+
.label {
|
|
785
|
+
position: absolute; left: -2px; bottom: 100%; margin-bottom: 4px; white-space: nowrap;
|
|
786
|
+
font: 11px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; color: #fff;
|
|
787
|
+
background: #7c5cff; padding: 2px 6px; border-radius: 3px;
|
|
788
|
+
}
|
|
789
|
+
.label.below { bottom: auto; top: 100%; margin: 4px 0 0; }
|
|
790
|
+
[hidden] { display: none !important; }
|
|
791
|
+
.panel {
|
|
792
|
+
position: fixed; right: 16px; bottom: 16px; z-index: 2147483647;
|
|
793
|
+
width: min(400px, calc(100vw - 32px)); height: min(560px, calc(100vh - 32px));
|
|
794
|
+
display: flex; flex-direction: column;
|
|
795
|
+
font: 13px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
|
|
796
|
+
color: #e7e7ee; background: #17171f; border: 1px solid #33334a; border-radius: 10px;
|
|
797
|
+
box-shadow: 0 12px 40px rgba(0,0,0,.45); overflow: hidden;
|
|
798
|
+
}
|
|
799
|
+
.panel.left { right: auto; left: 16px; }
|
|
800
|
+
.panel header { cursor: move; user-select: none; touch-action: none; }
|
|
801
|
+
.panel header button { cursor: pointer; }
|
|
802
|
+
.panel.dragging { user-select: none; opacity: .97; }
|
|
803
|
+
.grip { position: absolute; width: 14px; height: 14px; z-index: 2; touch-action: none; }
|
|
804
|
+
.grip.nw { top: 0; left: 0; cursor: nwse-resize; }
|
|
805
|
+
.grip.ne { top: 0; right: 0; cursor: nesw-resize; }
|
|
806
|
+
.grip.sw { bottom: 0; left: 0; cursor: nesw-resize; }
|
|
807
|
+
.grip.se { bottom: 0; right: 0; cursor: nwse-resize; }
|
|
808
|
+
.grip.se::after { content: ""; position: absolute; right: 3px; bottom: 3px; width: 7px; height: 7px;
|
|
809
|
+
border-right: 2px solid #4a4a66; border-bottom: 2px solid #4a4a66; }
|
|
810
|
+
.fab {
|
|
811
|
+
position: fixed; right: 16px; bottom: 16px; z-index: 2147483647;
|
|
812
|
+
width: 44px; height: 44px; border-radius: 50%; padding: 0;
|
|
813
|
+
font: 20px/1 -apple-system, BlinkMacSystemFont, sans-serif; color: #fff;
|
|
814
|
+
background: #7c5cff; border: 0; box-shadow: 0 6px 20px rgba(0,0,0,.4); opacity: .85;
|
|
815
|
+
}
|
|
816
|
+
.fab:hover { background: #8d71ff; opacity: 1; }
|
|
817
|
+
.fab.left { right: auto; left: 16px; }
|
|
818
|
+
.fab.busy { animation: pulse 1s infinite; }
|
|
819
|
+
.gear { display: inline-flex; align-items: center; justify-content: center; padding: 3px 6px; }
|
|
820
|
+
.gear svg { width: 18px; height: 18px; }
|
|
821
|
+
header button.active { background: #7c5cff; border-color: #7c5cff; }
|
|
822
|
+
.settings { flex: 1; overflow-y: auto; padding: 4px 12px 12px; }
|
|
823
|
+
.settings h3 { margin: 12px 0 6px; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: #8f8fa8; }
|
|
824
|
+
.settings label { display: block; margin-bottom: 8px; }
|
|
825
|
+
.settings select {
|
|
826
|
+
display: block; width: 100%; margin-top: 3px; font: inherit; color: inherit;
|
|
827
|
+
background: #101018; border: 1px solid #33334a; border-radius: 6px; padding: 4px 6px;
|
|
828
|
+
}
|
|
829
|
+
.settings input[data-text] {
|
|
830
|
+
display: block; width: 100%; margin-top: 3px; color: inherit; background: #101018;
|
|
831
|
+
border: 1px solid #33334a; border-radius: 6px; padding: 5px 7px;
|
|
832
|
+
font: 12px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace;
|
|
833
|
+
}
|
|
834
|
+
.settings input[data-text]:focus { border-color: #7c5cff; outline: none; }
|
|
835
|
+
.settings input[data-text]:disabled { opacity: .6; cursor: not-allowed; }
|
|
836
|
+
.settings small { display: block; margin-top: 3px; color: #8f8fa8; font-size: 11px; }
|
|
837
|
+
.settings .action { margin-bottom: 10px; }
|
|
838
|
+
.settings .action button { width: 100%; padding: 6px 8px; background: #7c5cff; border-color: #7c5cff; }
|
|
839
|
+
.settings label.check { display: flex; gap: 6px; align-items: center; margin-bottom: 4px; }
|
|
840
|
+
.settings .meta { color: #8f8fa8; font-size: 12px; }
|
|
841
|
+
header { display: flex; align-items: center; gap: 6px; padding: 8px 10px; border-bottom: 1px solid #2a2a3c; }
|
|
842
|
+
header .agent { color: #8f8fa8; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
|
|
843
|
+
.versions { display: flex; align-items: center; gap: 2px; font-size: 12px; color: #8f8fa8; }
|
|
844
|
+
.versions button { padding: 1px 6px; font-size: 10px; }
|
|
845
|
+
.versions button:disabled { opacity: .4; cursor: default; }
|
|
846
|
+
.vnum { min-width: 38px; text-align: center; cursor: help; }
|
|
847
|
+
.spacer { flex: 1; }
|
|
848
|
+
button {
|
|
849
|
+
font: inherit; color: #e7e7ee; background: #2a2a3c; border: 1px solid #3a3a52;
|
|
850
|
+
border-radius: 6px; padding: 3px 8px; cursor: pointer;
|
|
851
|
+
}
|
|
852
|
+
button:hover { background: #34344a; }
|
|
853
|
+
.log { flex: 1; overflow-y: auto; padding: 10px; display: flex; flex-direction: column; gap: 8px; }
|
|
854
|
+
.msg { white-space: normal; overflow-wrap: anywhere; }
|
|
855
|
+
.msg.user {
|
|
856
|
+
align-self: flex-end; max-width: 90%; background: #3b2f86; padding: 6px 10px;
|
|
857
|
+
border-radius: 10px 10px 2px 10px; white-space: pre-wrap;
|
|
858
|
+
}
|
|
859
|
+
.msg.user code { display: block; font-size: 11px; color: #c9bfff; margin-bottom: 2px; }
|
|
860
|
+
.msg.assistant { background: #22222f; padding: 6px 10px; border-radius: 10px 10px 10px 2px; }
|
|
861
|
+
.msg.assistant.live::after { content: "▍"; color: #7c5cff; }
|
|
862
|
+
.msg.tool, .msg.status, .msg.meta { color: #8f8fa8; font: 11.5px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; }
|
|
863
|
+
.msg.meta { text-align: right; }
|
|
864
|
+
.msg.error, .msg.tool.error { color: #ff7a7a; }
|
|
865
|
+
.msg.denied { color: #ffb020; font-size: 12px; }
|
|
866
|
+
code, pre { font: 12px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; }
|
|
867
|
+
.msg code { background: #2d2d40; padding: 0 3px; border-radius: 3px; }
|
|
868
|
+
pre.plain { margin: 0; background: transparent; padding: 0; white-space: pre-wrap; }
|
|
869
|
+
pre { background: #101018; padding: 8px; border-radius: 6px; overflow-x: auto; white-space: pre; }
|
|
870
|
+
.target {
|
|
871
|
+
display: flex; align-items: center; gap: 6px; margin: 0 10px; padding: 4px 6px 4px 8px;
|
|
872
|
+
background: #2b2414; border: 1px solid #5c4a1c; border-radius: 6px; color: #ffcf70;
|
|
873
|
+
}
|
|
874
|
+
.target code { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
875
|
+
.target button { padding: 0 6px; background: transparent; border: 0; color: inherit; }
|
|
876
|
+
form { display: flex; gap: 6px; padding: 8px 10px; }
|
|
877
|
+
textarea {
|
|
878
|
+
flex: 1; resize: none; font: inherit; color: inherit; background: #101018;
|
|
879
|
+
border: 1px solid #33334a; border-radius: 6px; padding: 6px 8px; outline: none;
|
|
880
|
+
}
|
|
881
|
+
textarea:focus { border-color: #7c5cff; }
|
|
882
|
+
.send { background: #7c5cff; border-color: #7c5cff; color: #fff; }
|
|
883
|
+
.send.stop { background: #b33a3a; border-color: #b33a3a; }
|
|
884
|
+
.panel.busy header strong::after { content: " ●"; color: #7c5cff; animation: pulse 1s infinite; }
|
|
885
|
+
@keyframes pulse { 50% { opacity: .2; } }
|
|
886
|
+
footer { padding: 0 10px 8px; color: #6f6f88; font-size: 11px; }
|
|
887
|
+
`;
|