browser-assistant 2.9.3 → 2.9.5
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 +2 -0
- package/extension/automation-policy.js +21 -2
- package/extension/background.js +13 -5
- package/extension/content.js +389 -53
- package/extension/detached-panel-background.js +101 -0
- package/extension/detached-panel.html +18 -0
- package/extension/detached-panel.js +201 -0
- package/extension/journal-automation.js +11 -6
- package/extension/manifest.json +1 -1
- package/extension/popup.html +2 -0
- package/extension/popup.js +24 -0
- package/extension/styles.css +89 -0
- package/package.json +7 -2
- package/server/main.py +62 -2
- package/server/vision_images.py +13 -1
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
const DETACHED_PANEL_KEY = 'assistantDetachedPanel';
|
|
2
|
+
const DETACHED_PANEL_MODE = 'assistantPanelMode';
|
|
3
|
+
const detachedPage = () => chrome.runtime.getURL('detached-panel.html');
|
|
4
|
+
let detachedPanelQueue = Promise.resolve();
|
|
5
|
+
function serializeDetachedPanel(action) {
|
|
6
|
+
const result = detachedPanelQueue.then(action);
|
|
7
|
+
detachedPanelQueue = result.catch(() => undefined);
|
|
8
|
+
return result;
|
|
9
|
+
}
|
|
10
|
+
async function detachedPanelSession() {
|
|
11
|
+
return (await chrome.storage.session.get(DETACHED_PANEL_KEY))[DETACHED_PANEL_KEY];
|
|
12
|
+
}
|
|
13
|
+
function messagePanelTab(tabId, message) {
|
|
14
|
+
return chrome.tabs.sendMessage(tabId, message, { frameId: 0 });
|
|
15
|
+
}
|
|
16
|
+
async function releasePanelTab(session) {
|
|
17
|
+
await messagePanelTab(session.targetTabId, { action: 'assistantPanelDetach', token: session.token })
|
|
18
|
+
.catch(() => undefined);
|
|
19
|
+
}
|
|
20
|
+
async function openDetachedPanel(tabId) {
|
|
21
|
+
const tab = await chrome.tabs.get(tabId);
|
|
22
|
+
if (!tab.active || !/^https?:\/\//.test(tab.url || '')) {
|
|
23
|
+
throw Error('Open the toolbar on the web tab you want to control.');
|
|
24
|
+
}
|
|
25
|
+
const ready = await messagePanelTab(tabId, { action: 'assistantPanelPing' }).catch(() => null);
|
|
26
|
+
if (!ready?.ok)
|
|
27
|
+
throw Error('Refresh the web tab to load Browser Assistant, then try again.');
|
|
28
|
+
let previous = await detachedPanelSession();
|
|
29
|
+
const existing = previous && await chrome.windows.get(previous.windowId, { populate: true }).catch(() => null);
|
|
30
|
+
if (previous && !existing?.tabs?.some(item => (item.url || item.pendingUrl) === detachedPage())) {
|
|
31
|
+
await releasePanelTab(previous);
|
|
32
|
+
await chrome.storage.session.remove(DETACHED_PANEL_KEY);
|
|
33
|
+
previous = undefined;
|
|
34
|
+
}
|
|
35
|
+
const created = previous ? undefined : await chrome.windows.create({
|
|
36
|
+
url: detachedPage(), type: 'popup', width: 420, height: 690, focused: true,
|
|
37
|
+
});
|
|
38
|
+
const windowId = previous?.windowId ?? created?.id;
|
|
39
|
+
if (windowId === undefined)
|
|
40
|
+
throw Error('Chrome could not open the separate panel.');
|
|
41
|
+
if (previous && previous.targetTabId !== tabId)
|
|
42
|
+
await releasePanelTab(previous);
|
|
43
|
+
const session = previous?.targetTabId === tabId ? previous : { windowId, targetTabId: tabId, token: crypto.randomUUID() };
|
|
44
|
+
await chrome.storage.session.set({ [DETACHED_PANEL_KEY]: session });
|
|
45
|
+
await chrome.storage.local.set({ [DETACHED_PANEL_MODE]: 'separate' });
|
|
46
|
+
if (previous)
|
|
47
|
+
await chrome.windows.update(windowId, { focused: true, state: 'normal' });
|
|
48
|
+
return { ok: true };
|
|
49
|
+
}
|
|
50
|
+
function browserAssistantDetachedMessage(request, sender, reply) {
|
|
51
|
+
if (sender.id !== chrome.runtime.id) {
|
|
52
|
+
reply({ error: 'Extension sender required.' });
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
void serializeDetachedPanel(async () => {
|
|
56
|
+
if (request.action === 'panel:open' && sender.url === chrome.runtime.getURL('popup.html')) {
|
|
57
|
+
if (!Number.isInteger(request.targetTabId))
|
|
58
|
+
throw Error('Choose a web tab first.');
|
|
59
|
+
return openDetachedPanel(request.targetTabId);
|
|
60
|
+
}
|
|
61
|
+
const session = await detachedPanelSession();
|
|
62
|
+
if (request.action === 'panel:target-status' && sender.tab && sender.frameId === 0) {
|
|
63
|
+
return { token: session?.targetTabId === sender.tab.id ? session.token : '' };
|
|
64
|
+
}
|
|
65
|
+
if (sender.url !== detachedPage() || !session || sender.tab?.windowId !== session.windowId) {
|
|
66
|
+
throw Error('Open the separate panel from the Browser Assistant toolbar on a web tab.');
|
|
67
|
+
}
|
|
68
|
+
if (request.action === 'panel:return') {
|
|
69
|
+
await chrome.storage.local.set({ [DETACHED_PANEL_MODE]: 'floating' });
|
|
70
|
+
await chrome.storage.session.remove(DETACHED_PANEL_KEY);
|
|
71
|
+
await releasePanelTab(session);
|
|
72
|
+
await chrome.windows.remove(session.windowId);
|
|
73
|
+
return { ok: true };
|
|
74
|
+
}
|
|
75
|
+
const tab = await chrome.tabs.get(session.targetTabId).catch(() => null);
|
|
76
|
+
if (!tab)
|
|
77
|
+
throw Error('The selected tab was closed. Open the toolbar on another web tab to reconnect.');
|
|
78
|
+
if (!/^https?:\/\//.test(tab.url || ''))
|
|
79
|
+
throw Error('Return to a webpage in the selected tab.');
|
|
80
|
+
if (request.action === 'panel:action' && request.token !== session.token) {
|
|
81
|
+
throw Error('The selected tab changed. Try the control again.');
|
|
82
|
+
}
|
|
83
|
+
const response = await messagePanelTab(tab.id, {
|
|
84
|
+
action: request.action === 'panel:snapshot' ? 'assistantPanelSnapshot' : 'assistantPanelAction',
|
|
85
|
+
token: session.token, panelControl: request.panelControl, operation: request.operation, value: request.value,
|
|
86
|
+
}).catch(() => null);
|
|
87
|
+
if (!response)
|
|
88
|
+
throw Error('Waiting for Browser Assistant in the selected tab. Refresh that tab if needed.');
|
|
89
|
+
return { ...response, token: session.token, title: tab.title || new URL(tab.url).hostname, active: tab.active };
|
|
90
|
+
}).then(reply, error => reply({ error: error.message }));
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
93
|
+
chrome.windows.onRemoved.addListener(windowId => {
|
|
94
|
+
void serializeDetachedPanel(async () => {
|
|
95
|
+
const session = await detachedPanelSession();
|
|
96
|
+
if (session?.windowId !== windowId)
|
|
97
|
+
return;
|
|
98
|
+
await chrome.storage.session.remove(DETACHED_PANEL_KEY);
|
|
99
|
+
await releasePanelTab(session);
|
|
100
|
+
}).catch(() => { });
|
|
101
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
6
|
+
<title>Browser Assistant — Separate Panel</title>
|
|
7
|
+
<link rel="stylesheet" href="styles.css">
|
|
8
|
+
</head>
|
|
9
|
+
<body class="detached-panel">
|
|
10
|
+
<header class="detached-toolbar">
|
|
11
|
+
<div id="detached-status" role="status">Connecting to the selected tab…</div>
|
|
12
|
+
<button type="button" id="detached-return">Return to floating panel</button>
|
|
13
|
+
</header>
|
|
14
|
+
<p id="detached-countdown" role="timer" hidden></p>
|
|
15
|
+
<main id="assistant-root"></main>
|
|
16
|
+
<script src="detached-panel.js"></script>
|
|
17
|
+
</body>
|
|
18
|
+
</html>
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
/* Render only the assistant's supported controls from the selected tab. */
|
|
2
|
+
(() => {
|
|
3
|
+
const shell = document.getElementById('assistant-root');
|
|
4
|
+
const status = document.getElementById('detached-status');
|
|
5
|
+
const countdown = document.getElementById('detached-countdown');
|
|
6
|
+
const returnButton = document.getElementById('detached-return');
|
|
7
|
+
const tags = new Set(['DIV', 'SPAN', 'P', 'SMALL', 'STRONG', 'DL', 'DT', 'DD', 'H3', 'H4', 'SECTION', 'BUTTON', 'SVG', 'PATH',
|
|
8
|
+
'PRE', 'CODE', 'DETAILS', 'SUMMARY', 'KBD', 'TEXTAREA', 'LABEL', 'SELECT', 'OPTION', 'BR']);
|
|
9
|
+
const attributes = new Set(['id', 'class', 'type', 'role', 'title', 'tabindex', 'disabled', 'hidden', 'open', 'selected',
|
|
10
|
+
'placeholder', 'rows', 'value', 'viewBox', 'd', 'data-panel-control', 'data-state', 'data-info', 'data-countdown']);
|
|
11
|
+
let token = '';
|
|
12
|
+
let lastHtml;
|
|
13
|
+
let requesting = false;
|
|
14
|
+
function safePanelNode(node) {
|
|
15
|
+
if (node.nodeType === Node.TEXT_NODE)
|
|
16
|
+
return document.createTextNode(node.textContent || '');
|
|
17
|
+
if (!(node instanceof Element) || !tags.has(node.tagName.toUpperCase()))
|
|
18
|
+
return null;
|
|
19
|
+
const tag = node.tagName.toLowerCase();
|
|
20
|
+
const element = tag === 'svg' || tag === 'path'
|
|
21
|
+
? document.createElementNS('http://www.w3.org/2000/svg', tag)
|
|
22
|
+
: document.createElement(tag);
|
|
23
|
+
for (const attr of node.attributes) {
|
|
24
|
+
if (attributes.has(attr.name) || /^aria-[a-z-]+$/.test(attr.name))
|
|
25
|
+
element.setAttribute(attr.name, attr.value);
|
|
26
|
+
}
|
|
27
|
+
for (const child of node.childNodes) {
|
|
28
|
+
const copy = safePanelNode(child);
|
|
29
|
+
if (copy)
|
|
30
|
+
element.appendChild(copy);
|
|
31
|
+
}
|
|
32
|
+
return element;
|
|
33
|
+
}
|
|
34
|
+
function updatePanel(html) {
|
|
35
|
+
if (html === lastHtml)
|
|
36
|
+
return;
|
|
37
|
+
const active = document.activeElement;
|
|
38
|
+
const activeId = active?.getAttribute('data-panel-control');
|
|
39
|
+
const activeMode = active?.matches('[role="tab"]') ? active.id : '';
|
|
40
|
+
const caret = active instanceof HTMLTextAreaElement
|
|
41
|
+
? [active.selectionStart, active.selectionEnd] : null;
|
|
42
|
+
const scrolls = ['.assistant-body', '.assistant-qa-panel'].map(selector => [selector, shell.querySelector(selector)?.scrollTop ?? 0]);
|
|
43
|
+
const source = document.createElement('template');
|
|
44
|
+
source.innerHTML = html;
|
|
45
|
+
const content = document.createDocumentFragment();
|
|
46
|
+
for (const child of source.content.childNodes) {
|
|
47
|
+
const copy = safePanelNode(child);
|
|
48
|
+
if (copy)
|
|
49
|
+
content.appendChild(copy);
|
|
50
|
+
}
|
|
51
|
+
shell.replaceChildren(content);
|
|
52
|
+
for (const [selector, scrollTop] of scrolls) {
|
|
53
|
+
const region = shell.querySelector(selector);
|
|
54
|
+
if (region)
|
|
55
|
+
region.scrollTop = scrollTop;
|
|
56
|
+
}
|
|
57
|
+
if (activeId) {
|
|
58
|
+
const replacement = shell.querySelector('[data-panel-control="' + CSS.escape(activeId) + '"]')
|
|
59
|
+
?? (activeMode ? shell.querySelector('#' + CSS.escape(activeMode)) : null);
|
|
60
|
+
replacement?.focus({ preventScroll: true });
|
|
61
|
+
if (caret && replacement instanceof HTMLTextAreaElement) {
|
|
62
|
+
replacement.value = active.value;
|
|
63
|
+
replacement.setSelectionRange(...caret);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
lastHtml = html;
|
|
67
|
+
}
|
|
68
|
+
async function refresh() {
|
|
69
|
+
if (requesting)
|
|
70
|
+
return;
|
|
71
|
+
requesting = true;
|
|
72
|
+
try {
|
|
73
|
+
const result = await chrome.runtime.sendMessage({ action: 'panel:snapshot' });
|
|
74
|
+
if (!result?.ok)
|
|
75
|
+
throw Error(result?.error || 'The selected tab did not respond.');
|
|
76
|
+
token = result.token;
|
|
77
|
+
const label = result.title + (result.active ? '' : ' · Select this tab in Chrome for Vision Scan.');
|
|
78
|
+
if (status.textContent !== label)
|
|
79
|
+
status.textContent = label;
|
|
80
|
+
if (countdown.textContent !== result.countdown)
|
|
81
|
+
countdown.textContent = result.countdown;
|
|
82
|
+
countdown.hidden = !result.countdown;
|
|
83
|
+
updatePanel(result.html);
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
token = '';
|
|
87
|
+
lastHtml = undefined;
|
|
88
|
+
shell.replaceChildren();
|
|
89
|
+
countdown.hidden = true;
|
|
90
|
+
status.textContent = error.message;
|
|
91
|
+
}
|
|
92
|
+
finally {
|
|
93
|
+
requesting = false;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
async function send(operation, control, value) {
|
|
97
|
+
if (!token)
|
|
98
|
+
return;
|
|
99
|
+
try {
|
|
100
|
+
const response = await chrome.runtime.sendMessage({
|
|
101
|
+
action: 'panel:action', token, operation, panelControl: control?.dataset.panelControl, value,
|
|
102
|
+
});
|
|
103
|
+
if (!response?.ok)
|
|
104
|
+
throw Error(response?.error || 'The selected tab did not respond.');
|
|
105
|
+
}
|
|
106
|
+
catch (error) {
|
|
107
|
+
status.textContent = error.message;
|
|
108
|
+
}
|
|
109
|
+
void refresh();
|
|
110
|
+
}
|
|
111
|
+
async function returnToFloating() {
|
|
112
|
+
try {
|
|
113
|
+
const response = await chrome.runtime.sendMessage({ action: 'panel:return' });
|
|
114
|
+
if (response?.error)
|
|
115
|
+
status.textContent = response.error;
|
|
116
|
+
}
|
|
117
|
+
catch (error) {
|
|
118
|
+
status.textContent = error.message;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
returnButton.addEventListener('click', returnToFloating);
|
|
122
|
+
shell.addEventListener('click', event => {
|
|
123
|
+
const control = event.target.closest('[data-panel-control]');
|
|
124
|
+
if (!control?.matches('button,summary') || control.matches(':disabled'))
|
|
125
|
+
return;
|
|
126
|
+
event.preventDefault();
|
|
127
|
+
if (control.id === 'assistant-close-btn') {
|
|
128
|
+
returnToFloating();
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
if (control.classList.contains('assistant-copy-btn')) {
|
|
132
|
+
const code = control.closest('.assistant-code-container')?.querySelector('code')?.textContent;
|
|
133
|
+
if (code === undefined)
|
|
134
|
+
return;
|
|
135
|
+
void navigator.clipboard.writeText(code).then(() => {
|
|
136
|
+
control.textContent = 'Copied';
|
|
137
|
+
setTimeout(() => { control.textContent = 'Copy'; }, 2000);
|
|
138
|
+
}).catch(error => { status.textContent = error.message; });
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
void send('click', control);
|
|
142
|
+
});
|
|
143
|
+
shell.addEventListener('input', event => {
|
|
144
|
+
if (event.target instanceof HTMLTextAreaElement)
|
|
145
|
+
void send('value', event.target, event.target.value);
|
|
146
|
+
});
|
|
147
|
+
shell.addEventListener('change', event => {
|
|
148
|
+
if (event.target instanceof HTMLSelectElement)
|
|
149
|
+
void send('value', event.target, event.target.value);
|
|
150
|
+
});
|
|
151
|
+
document.addEventListener('keydown', event => {
|
|
152
|
+
if (event.repeat || event.isComposing || event.defaultPrevented || event.ctrlKey || event.metaKey)
|
|
153
|
+
return;
|
|
154
|
+
const key = event.key.toLowerCase();
|
|
155
|
+
if (event.altKey) {
|
|
156
|
+
if (key === 'a' || event.code === 'KeyA') {
|
|
157
|
+
event.preventDefault();
|
|
158
|
+
void send('automation');
|
|
159
|
+
}
|
|
160
|
+
else if (event.shiftKey && (key === 'j' || event.code === 'KeyJ')) {
|
|
161
|
+
event.preventDefault();
|
|
162
|
+
void send('journal');
|
|
163
|
+
}
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
const focused = event.target;
|
|
167
|
+
if (focused.closest('input,textarea,select,[contenteditable="true"]'))
|
|
168
|
+
return;
|
|
169
|
+
if (focused.matches('[role="tab"]')) {
|
|
170
|
+
const tabs = [...shell.querySelectorAll('[role="tab"]')];
|
|
171
|
+
const index = tabs.indexOf(focused);
|
|
172
|
+
const next = { arrowright: (index + 1) % tabs.length, arrowleft: (index + tabs.length - 1) % tabs.length,
|
|
173
|
+
home: 0, end: tabs.length - 1 }[key];
|
|
174
|
+
if (next !== undefined && tabs[next]) {
|
|
175
|
+
event.preventDefault();
|
|
176
|
+
tabs[next].focus();
|
|
177
|
+
void send('click', tabs[next]);
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
if (key === ']') {
|
|
182
|
+
event.preventDefault();
|
|
183
|
+
returnToFloating();
|
|
184
|
+
}
|
|
185
|
+
else if (key === '\\') {
|
|
186
|
+
event.preventDefault();
|
|
187
|
+
shell.hidden = false;
|
|
188
|
+
void send('vision');
|
|
189
|
+
}
|
|
190
|
+
else if (key === '[') {
|
|
191
|
+
event.preventDefault();
|
|
192
|
+
shell.hidden = !shell.hidden;
|
|
193
|
+
}
|
|
194
|
+
else if (key === '`') {
|
|
195
|
+
event.preventDefault();
|
|
196
|
+
shell.hidden = false;
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
void refresh();
|
|
200
|
+
setInterval(refresh, 650);
|
|
201
|
+
})();
|
|
@@ -591,6 +591,12 @@ function browserAssistantJournal(global) {
|
|
|
591
591
|
}
|
|
592
592
|
}
|
|
593
593
|
if (typeof window !== 'undefined' && location.origin === 'https://admissions.aurora.edu.in') {
|
|
594
|
+
const ongoingJournalStartLink = () => {
|
|
595
|
+
const links = [...document.querySelectorAll('a[href*="/modules/reflective-journal/"]')].filter(link => [...(link.closest('tr,[role="row"]')?.querySelectorAll('*') || [])].some(node => /^Ongoing$/i.test(node.textContent.trim())) && link.getClientRects().length
|
|
596
|
+
&& new URL(link.href, location.origin).origin === location.origin
|
|
597
|
+
&& /^\/modules\/reflective-journal\//.test(new URL(link.href, location.origin).pathname));
|
|
598
|
+
return links.length === 1 ? links[0] : null;
|
|
599
|
+
};
|
|
594
600
|
window.BrowserAssistantJournal = window.BrowserAssistantJournal || {
|
|
595
601
|
current: null,
|
|
596
602
|
opening: false,
|
|
@@ -604,6 +610,7 @@ if (typeof window !== 'undefined' && location.origin === 'https://admissions.aur
|
|
|
604
610
|
}
|
|
605
611
|
catch { } },
|
|
606
612
|
pause() { this.active()?.pause(); },
|
|
613
|
+
getStartLink() { return ongoingJournalStartLink(); },
|
|
607
614
|
start() {
|
|
608
615
|
if (this.active())
|
|
609
616
|
return this.active().start();
|
|
@@ -613,16 +620,14 @@ if (typeof window !== 'undefined' && location.origin === 'https://admissions.aur
|
|
|
613
620
|
}
|
|
614
621
|
if (this.opening)
|
|
615
622
|
return;
|
|
616
|
-
const
|
|
617
|
-
|
|
618
|
-
&& /^\/modules\/reflective-journal\//.test(new URL(link.href, location.origin).pathname));
|
|
619
|
-
if (links.length === 1) {
|
|
623
|
+
const link = ongoingJournalStartLink();
|
|
624
|
+
if (link) {
|
|
620
625
|
this.opening = true;
|
|
621
626
|
try {
|
|
622
|
-
sessionStorage.setItem('assistantPendingJournal', JSON.stringify({ path: new URL(
|
|
627
|
+
sessionStorage.setItem('assistantPendingJournal', JSON.stringify({ path: new URL(link.href, location.origin).pathname, createdAt: Date.now() }));
|
|
623
628
|
}
|
|
624
629
|
catch { }
|
|
625
|
-
|
|
630
|
+
link.click();
|
|
626
631
|
}
|
|
627
632
|
},
|
|
628
633
|
};
|
package/extension/manifest.json
CHANGED
package/extension/popup.html
CHANGED
|
@@ -15,6 +15,8 @@
|
|
|
15
15
|
<section class="popup-card" aria-label="Server status">
|
|
16
16
|
<div>Server <span id="server-status" role="status">Checking…</span></div>
|
|
17
17
|
<p id="journal-countdown" hidden></p>
|
|
18
|
+
<button type="button" id="open-separate-panel">Open separate panel for this tab</button>
|
|
19
|
+
<p id="separate-panel-status" role="status" hidden></p>
|
|
18
20
|
</section>
|
|
19
21
|
<section class="popup-card" aria-labelledby="popup-shortcuts">
|
|
20
22
|
<h2 id="popup-shortcuts">Keyboard shortcuts</h2>
|
package/extension/popup.js
CHANGED
|
@@ -48,3 +48,27 @@ journalTimerStorage.onChanged.addListener(changes => {
|
|
|
48
48
|
});
|
|
49
49
|
void refreshPopupJournalTimers();
|
|
50
50
|
setInterval(showJournalCountdown, 1000);
|
|
51
|
+
const separatePanelButton = document.querySelector('#open-separate-panel');
|
|
52
|
+
const separatePanelStatus = document.getElementById('separate-panel-status');
|
|
53
|
+
if (separatePanelButton) {
|
|
54
|
+
void chrome.storage.local.get('assistantPanelMode').then(settings => {
|
|
55
|
+
if (settings.assistantPanelMode === 'separate')
|
|
56
|
+
separatePanelButton.textContent = 'Resume separate panel for this tab';
|
|
57
|
+
}).catch(() => { });
|
|
58
|
+
separatePanelButton.addEventListener('click', async () => {
|
|
59
|
+
separatePanelButton.disabled = true;
|
|
60
|
+
separatePanelStatus.hidden = true;
|
|
61
|
+
try {
|
|
62
|
+
const [tab] = await chrome.tabs.query({ active: true, currentWindow: true });
|
|
63
|
+
const result = await chrome.runtime.sendMessage({ action: 'panel:open', targetTabId: tab?.id });
|
|
64
|
+
if (!result?.ok)
|
|
65
|
+
throw Error(result?.error || 'Could not open the separate panel.');
|
|
66
|
+
window.close();
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
separatePanelStatus.textContent = error.message;
|
|
70
|
+
separatePanelStatus.hidden = false;
|
|
71
|
+
separatePanelButton.disabled = false;
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
}
|
package/extension/styles.css
CHANGED
|
@@ -551,3 +551,92 @@ body.assistant-popup {
|
|
|
551
551
|
#assistant-root :is(button, summary):focus-visible,
|
|
552
552
|
#assistant-journal :is(button, select, textarea):focus-visible { outline-color: Highlight; }
|
|
553
553
|
}
|
|
554
|
+
|
|
555
|
+
/* The original controller stays attached to its tab while its window is open. */
|
|
556
|
+
.assistant-popup #open-separate-panel {
|
|
557
|
+
width: 100%;
|
|
558
|
+
margin-top: 8px;
|
|
559
|
+
padding: 7px 8px;
|
|
560
|
+
border: 1px solid var(--edge);
|
|
561
|
+
border-radius: 6px;
|
|
562
|
+
background: var(--well);
|
|
563
|
+
color: var(--ink);
|
|
564
|
+
font: inherit;
|
|
565
|
+
cursor: pointer;
|
|
566
|
+
}
|
|
567
|
+
.assistant-popup #separate-panel-status { color: #fca5a5; }
|
|
568
|
+
#assistant-automation-notice {
|
|
569
|
+
position: fixed;
|
|
570
|
+
right: 16px;
|
|
571
|
+
bottom: 16px;
|
|
572
|
+
z-index: 2147483647;
|
|
573
|
+
max-width: min(320px, calc(100vw - 48px));
|
|
574
|
+
padding: 8px 12px;
|
|
575
|
+
border-radius: 8px;
|
|
576
|
+
background: #18253c;
|
|
577
|
+
color: #fff;
|
|
578
|
+
font: 13px/1.5 system-ui, sans-serif;
|
|
579
|
+
pointer-events: none;
|
|
580
|
+
}
|
|
581
|
+
#assistant-root.assistant-detached,
|
|
582
|
+
#assistant-journal-countdown-badge.assistant-detached,
|
|
583
|
+
#assistant-root.assistant-panel-initializing,
|
|
584
|
+
#assistant-journal-countdown-badge.assistant-panel-initializing { display: none !important; }
|
|
585
|
+
|
|
586
|
+
body.detached-panel {
|
|
587
|
+
margin: 0;
|
|
588
|
+
padding: 10px;
|
|
589
|
+
background: #11121a;
|
|
590
|
+
color: #e6eaff;
|
|
591
|
+
font: 13px/1.5 Inter, system-ui, sans-serif;
|
|
592
|
+
}
|
|
593
|
+
.detached-panel .detached-toolbar {
|
|
594
|
+
display: flex;
|
|
595
|
+
align-items: center;
|
|
596
|
+
gap: 8px;
|
|
597
|
+
justify-content: space-between;
|
|
598
|
+
margin-bottom: 10px;
|
|
599
|
+
}
|
|
600
|
+
.detached-panel #detached-status { overflow-wrap: anywhere; }
|
|
601
|
+
.detached-panel #detached-countdown { margin: 0 0 10px; color: #ddd0ff; font-variant-numeric: tabular-nums; }
|
|
602
|
+
.detached-panel #detached-return {
|
|
603
|
+
flex: 0 0 auto;
|
|
604
|
+
padding: 5px 8px;
|
|
605
|
+
border: 1px solid #57668d;
|
|
606
|
+
border-radius: 6px;
|
|
607
|
+
background: #242c4b;
|
|
608
|
+
color: #fff;
|
|
609
|
+
font: inherit;
|
|
610
|
+
font-size: 11px;
|
|
611
|
+
cursor: pointer;
|
|
612
|
+
}
|
|
613
|
+
.detached-panel #detached-return:focus-visible { outline: 2px solid #b9c7ff; outline-offset: 2px; }
|
|
614
|
+
.detached-panel #assistant-root { position: static; }
|
|
615
|
+
.detached-panel #assistant-root[hidden],
|
|
616
|
+
.detached-panel #assistant-root [hidden] { display: none !important; }
|
|
617
|
+
.detached-panel #assistant-root .assistant-tab:not(.collapsed) {
|
|
618
|
+
box-sizing: border-box;
|
|
619
|
+
width: 100%;
|
|
620
|
+
max-height: none;
|
|
621
|
+
max-width: none;
|
|
622
|
+
resize: none;
|
|
623
|
+
}
|
|
624
|
+
.detached-panel .assistant-header { cursor: default; }
|
|
625
|
+
.detached-panel #assistant-journal {
|
|
626
|
+
display: block;
|
|
627
|
+
width: 100%;
|
|
628
|
+
box-sizing: border-box;
|
|
629
|
+
padding: 10px;
|
|
630
|
+
border: 1px solid #6c58aa;
|
|
631
|
+
border-radius: 8px;
|
|
632
|
+
background: #fff;
|
|
633
|
+
color: #17233d;
|
|
634
|
+
font: 13px Arial, sans-serif;
|
|
635
|
+
margin: 10px 0;
|
|
636
|
+
}
|
|
637
|
+
.detached-panel #assistant-journal label { display: block; margin: 8px 0; }
|
|
638
|
+
.detached-panel #assistant-journal select,
|
|
639
|
+
.detached-panel #assistant-journal textarea { display: block; width: 100%; box-sizing: border-box; }
|
|
640
|
+
.detached-panel #assistant-journal select { padding: 5px; color: #17233d; background: #fff; border: 1px solid #abb3c3; }
|
|
641
|
+
.detached-panel #assistant-journal button { margin-top: 8px; padding: 10px; }
|
|
642
|
+
.detached-panel #assistant-journal [data-countdown] { margin: 8px 0; font-weight: 600; }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "browser-assistant",
|
|
3
|
-
"version": "2.9.
|
|
3
|
+
"version": "2.9.5",
|
|
4
4
|
"description": "Chrome extension and local Python backend for exploring webpage questions and coding exercises",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -15,6 +15,9 @@
|
|
|
15
15
|
"LICENSE",
|
|
16
16
|
"extension/manifest.json",
|
|
17
17
|
"extension/background.js",
|
|
18
|
+
"extension/detached-panel-background.js",
|
|
19
|
+
"extension/detached-panel.html",
|
|
20
|
+
"extension/detached-panel.js",
|
|
18
21
|
"extension/editor-bridge.js",
|
|
19
22
|
"extension/automation-policy.js",
|
|
20
23
|
"extension/question-visuals.js",
|
|
@@ -42,11 +45,13 @@
|
|
|
42
45
|
"build": "tsc --project tsconfig.json",
|
|
43
46
|
"prepack": "npm run build",
|
|
44
47
|
"typecheck": "tsc --project tsconfig.json --noEmit",
|
|
45
|
-
"test": "npm run build && node --test extension/*.test.cts"
|
|
48
|
+
"test": "npm run build && node --test extension/*.test.cts",
|
|
49
|
+
"test:browser": "npm run build && node --test scripts/test_separate_panel.cjs"
|
|
46
50
|
},
|
|
47
51
|
"devDependencies": {
|
|
48
52
|
"@types/chrome": "0.3.7",
|
|
49
53
|
"linkedom": "^0.18.12",
|
|
54
|
+
"playwright": "1.65.0",
|
|
50
55
|
"typescript": "5.9.3"
|
|
51
56
|
}
|
|
52
57
|
}
|
package/server/main.py
CHANGED
|
@@ -7,7 +7,10 @@ import math
|
|
|
7
7
|
import re
|
|
8
8
|
import time
|
|
9
9
|
from fastapi import FastAPI, HTTPException
|
|
10
|
-
from pydantic import BaseModel, field_validator
|
|
10
|
+
from pydantic import BaseModel, Field, field_validator
|
|
11
|
+
from typing import Literal
|
|
12
|
+
from uuid import UUID
|
|
13
|
+
from urllib.parse import urlsplit
|
|
11
14
|
from dotenv import load_dotenv
|
|
12
15
|
from groq import Groq
|
|
13
16
|
import ollama
|
|
@@ -167,6 +170,15 @@ def initialize_history_database() -> None:
|
|
|
167
170
|
connection.execute(
|
|
168
171
|
"CREATE INDEX IF NOT EXISTS idx_scan_history_created_at ON scan_history(created_at DESC)"
|
|
169
172
|
)
|
|
173
|
+
connection.execute(
|
|
174
|
+
"""CREATE TABLE IF NOT EXISTS automation_history (
|
|
175
|
+
id TEXT PRIMARY KEY,
|
|
176
|
+
started_at TEXT NOT NULL,
|
|
177
|
+
revision INTEGER NOT NULL,
|
|
178
|
+
status TEXT NOT NULL,
|
|
179
|
+
record TEXT NOT NULL
|
|
180
|
+
)"""
|
|
181
|
+
)
|
|
170
182
|
|
|
171
183
|
|
|
172
184
|
@asynccontextmanager
|
|
@@ -179,7 +191,7 @@ async def lifespan(_app: FastAPI):
|
|
|
179
191
|
client.close()
|
|
180
192
|
|
|
181
193
|
|
|
182
|
-
app = FastAPI(title="Browser Assistant API", version="2.9.
|
|
194
|
+
app = FastAPI(title="Browser Assistant API", version="2.9.5", lifespan=lifespan)
|
|
183
195
|
install_local_guards(app)
|
|
184
196
|
|
|
185
197
|
@app.exception_handler(HTTPException)
|
|
@@ -268,6 +280,27 @@ class HistoryEntry(BaseModel):
|
|
|
268
280
|
return value
|
|
269
281
|
|
|
270
282
|
|
|
283
|
+
class AutomationHistoryEntry(BaseModel):
|
|
284
|
+
id: UUID
|
|
285
|
+
type: Literal["MCQ", "Quiz", "Coding", "Batch Coding", "Journal"]
|
|
286
|
+
url: str = Field(max_length=2048)
|
|
287
|
+
started_at: datetime
|
|
288
|
+
ended_at: datetime | None = None
|
|
289
|
+
total: int | None = Field(default=None, ge=0)
|
|
290
|
+
completed: int = Field(ge=0)
|
|
291
|
+
failed: int = Field(ge=0)
|
|
292
|
+
status: Literal["Running", "Completed", "Failed", "Stopped"]
|
|
293
|
+
revision: int = Field(ge=1)
|
|
294
|
+
|
|
295
|
+
@field_validator("url")
|
|
296
|
+
@classmethod
|
|
297
|
+
def validate_page_url(cls, value):
|
|
298
|
+
parsed = urlsplit(value)
|
|
299
|
+
if parsed.scheme not in ("http", "https") or not parsed.hostname or parsed.username or parsed.password or parsed.query or parsed.fragment:
|
|
300
|
+
raise ValueError("Provide a webpage URL without credentials, a query or a fragment")
|
|
301
|
+
return value
|
|
302
|
+
|
|
303
|
+
|
|
271
304
|
# ── Health check ──────────────────────────────────────────────────────────────
|
|
272
305
|
|
|
273
306
|
@app.get("/health")
|
|
@@ -360,6 +393,33 @@ def clear_history():
|
|
|
360
393
|
connection.execute("DELETE FROM scan_history")
|
|
361
394
|
|
|
362
395
|
|
|
396
|
+
@app.get("/automation-history")
|
|
397
|
+
def list_automation_history(limit: int = Query(default=20, ge=1, le=HISTORY_MAX_ITEMS)):
|
|
398
|
+
with get_history_connection() as connection:
|
|
399
|
+
rows = connection.execute(
|
|
400
|
+
"SELECT record FROM automation_history ORDER BY started_at DESC LIMIT ?", (limit,)
|
|
401
|
+
).fetchall()
|
|
402
|
+
return {"items": [json.loads(row["record"]) for row in rows]}
|
|
403
|
+
|
|
404
|
+
|
|
405
|
+
@app.put("/automation-history")
|
|
406
|
+
def save_automation_history(entry: AutomationHistoryEntry):
|
|
407
|
+
if (entry.status == "Running") != (entry.ended_at is None):
|
|
408
|
+
raise HTTPException(422, "Only a finished run has an end time.")
|
|
409
|
+
with get_history_connection() as connection:
|
|
410
|
+
connection.execute(
|
|
411
|
+
"""INSERT INTO automation_history (id, started_at, revision, status, record)
|
|
412
|
+
VALUES (?, ?, ?, ?, ?)
|
|
413
|
+
ON CONFLICT(id) DO UPDATE SET
|
|
414
|
+
revision=excluded.revision, status=excluded.status, record=excluded.record
|
|
415
|
+
WHERE automation_history.status='Running'
|
|
416
|
+
AND excluded.revision > automation_history.revision
|
|
417
|
+
AND excluded.started_at=automation_history.started_at""",
|
|
418
|
+
(str(entry.id), entry.started_at.isoformat(), entry.revision, entry.status, entry.model_dump_json()),
|
|
419
|
+
)
|
|
420
|
+
return {"id": str(entry.id)}
|
|
421
|
+
|
|
422
|
+
|
|
363
423
|
# ── AI providers ──────────────────────────────────────────────────────────────
|
|
364
424
|
|
|
365
425
|
async def try_groq(messages: list, model: str = None, temperature: float = 0.0, _token_limit: int = GROQ_COMPLETION_TOKEN_LIMIT, _review: bool = False) -> str:
|
package/server/vision_images.py
CHANGED
|
@@ -469,8 +469,20 @@ async def cross_check_text_answers(messages, results, complete, *, question_text
|
|
|
469
469
|
'role': 'user',
|
|
470
470
|
'content': 'Solve again using the original question and options. Return the full verification JSON with the required ids.',
|
|
471
471
|
}]
|
|
472
|
+
# When both independent verifications failed to parse, prefer delivering the
|
|
473
|
+
# primary answer over blocking the automation entirely. The primary solve was
|
|
474
|
+
# validated and the verification provider returned unusable JSON — a parsing
|
|
475
|
+
# failure, not a disagreement — so a hard 422 is disproportionate.
|
|
472
476
|
if current is None and previous is None:
|
|
473
|
-
|
|
477
|
+
return results
|
|
478
|
+
# For multi-answer questions (fill-in-the-blank), accept the primary answers
|
|
479
|
+
# when the majority of individual answers agree with any independent solve.
|
|
480
|
+
if not choices and first is not None and len(first) > 1:
|
|
481
|
+
best = current or previous
|
|
482
|
+
if best is not None:
|
|
483
|
+
agreed = sum(a == b for a, b in zip(first, best))
|
|
484
|
+
if agreed > len(first) // 2:
|
|
485
|
+
return results
|
|
474
486
|
raise VisionUnconfirmedError('The independent solves could not agree on the displayed answer.')
|
|
475
487
|
|
|
476
488
|
|