browser-assistant 2.9.0 → 2.9.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.
- package/README.md +19 -19
- package/extension/answer-requests.js +0 -33
- package/extension/automation-policy.js +9 -6
- package/extension/background.js +37 -192
- package/extension/content.js +122 -259
- package/extension/editor-bridge.js +11 -7
- package/extension/journal-automation.js +254 -102
- package/extension/manifest.json +4 -13
- package/extension/popup.html +2 -13
- package/extension/popup.js +0 -42
- package/extension/question-visuals.js +7 -82
- package/extension/styles.css +0 -7
- package/package.json +2 -5
- package/server/.env.example +0 -2
- package/server/journal.py +7 -5
- package/server/local_security.py +1 -74
- package/server/main.py +28 -83
- package/server/inference_jobs.py +0 -90
package/extension/content.js
CHANGED
|
@@ -76,7 +76,7 @@ function mountJournalCountdown(signal) {
|
|
|
76
76
|
return id;
|
|
77
77
|
};
|
|
78
78
|
const navigationCleanup = [];
|
|
79
|
-
console.log("Browser Assistant
|
|
79
|
+
console.log("Browser Assistant v" + extensionVersion + " loaded.");
|
|
80
80
|
const SERVER = 'http://localhost:8000';
|
|
81
81
|
const root = document.createElement('div');
|
|
82
82
|
root.id = 'assistant-root';
|
|
@@ -191,7 +191,6 @@ function mountJournalCountdown(signal) {
|
|
|
191
191
|
let isHidden = false;
|
|
192
192
|
let serverOnline = null; // null = unknown, true/false = checked
|
|
193
193
|
let isScanning = false;
|
|
194
|
-
const pendingInference = new Set();
|
|
195
194
|
let extensionAlive = true; // false after extension reload invalidates context
|
|
196
195
|
let historyItems = [];
|
|
197
196
|
let isHistoryOpen = false;
|
|
@@ -200,17 +199,7 @@ function mountJournalCountdown(signal) {
|
|
|
200
199
|
state: 'IDLE', running: false, paused: false, runId: 0,
|
|
201
200
|
processed: new Set(), completed: 0, error: '', currentSignature: '',
|
|
202
201
|
};
|
|
203
|
-
const updateListener = (request,
|
|
204
|
-
if (request.action === 'assistantShowPanel' || request.action === 'assistantToggleAutomation') {
|
|
205
|
-
if (sender.id !== chrome.runtime.id)
|
|
206
|
-
return false;
|
|
207
|
-
if (request.action === 'assistantShowPanel')
|
|
208
|
-
openPanel();
|
|
209
|
-
else
|
|
210
|
-
toggleAutomation();
|
|
211
|
-
sendResponse({ ok: true });
|
|
212
|
-
return false;
|
|
213
|
-
}
|
|
202
|
+
const updateListener = (request, _sender, sendResponse) => {
|
|
214
203
|
const busy = automation.running || isScanning || Boolean(window.BrowserAssistantJournalBusy);
|
|
215
204
|
if (request.action === 'assistantUpdateStatus') {
|
|
216
205
|
sendResponse({ busy });
|
|
@@ -229,8 +218,6 @@ function mountJournalCountdown(signal) {
|
|
|
229
218
|
disposed = true;
|
|
230
219
|
extensionAlive = false;
|
|
231
220
|
automation.runId++;
|
|
232
|
-
for (const request of pendingInference)
|
|
233
|
-
request.abort();
|
|
234
221
|
lifecycle.abort();
|
|
235
222
|
for (const cleanup of navigationCleanup)
|
|
236
223
|
cleanup();
|
|
@@ -280,16 +267,15 @@ function mountJournalCountdown(signal) {
|
|
|
280
267
|
return false;
|
|
281
268
|
return before.options.every((option, index) => normalizeAutomationText(option.identityText || option.text) === normalizeAutomationText(after.options[index]?.identityText || after.options[index]?.text));
|
|
282
269
|
}
|
|
283
|
-
function getAuthorizedQuestion(context = getAutomationContext()
|
|
270
|
+
function getAuthorizedQuestion(context = getAutomationContext()) {
|
|
284
271
|
// The dashboard contains mentor feedback radios, not quiz answers.
|
|
285
272
|
if (window.location.origin === 'https://learning.ccbp.in' && window.location.pathname === '/')
|
|
286
273
|
return null;
|
|
287
274
|
// Problem-list filters are checkboxes, not an MCQ question.
|
|
288
275
|
if (window.location.pathname.replace(/\/$/, '') === '/problems-set')
|
|
289
276
|
return null;
|
|
290
|
-
const
|
|
291
|
-
|
|
292
|
-
if (!adapter || (!readOnly && (!automationPolicy.canExecute('detect', context) || !automationPolicy.canExecute('read', context))))
|
|
277
|
+
const adapter = getAutomationAdapter(context);
|
|
278
|
+
if (!adapter || !automationPolicy.canExecute('detect', context) || !automationPolicy.canExecute('read', context))
|
|
293
279
|
return null;
|
|
294
280
|
const coding = window.BrowserAssistantCoding?.getQuestion(document);
|
|
295
281
|
if (coding) {
|
|
@@ -312,6 +298,7 @@ function mountJournalCountdown(signal) {
|
|
|
312
298
|
})), signature: questionSignature(question.identityText || question.text, question.options)
|
|
313
299
|
+ (window.BrowserAssistantQuestionVisuals?.nodes(question).length ? `|visual:${window.BrowserAssistantQuestionVisuals.fingerprint(question)}` : '') };
|
|
314
300
|
}
|
|
301
|
+
const AUTO_RESUME_KEY = 'browserAssistantResumeAuthorizedQa';
|
|
315
302
|
function questionDetectionError() {
|
|
316
303
|
const codingPage = window.location.origin === 'https://learning.ccbp.in'
|
|
317
304
|
&& /^\/question\//.test(window.location.pathname);
|
|
@@ -466,7 +453,7 @@ function mountJournalCountdown(signal) {
|
|
|
466
453
|
}
|
|
467
454
|
if (start) {
|
|
468
455
|
start.disabled = current.running;
|
|
469
|
-
start.textContent = '▶
|
|
456
|
+
start.textContent = '▶ Start journal automation';
|
|
470
457
|
}
|
|
471
458
|
if (pause) {
|
|
472
459
|
pause.disabled = !current.running || current.submitting;
|
|
@@ -543,12 +530,11 @@ function mountJournalCountdown(signal) {
|
|
|
543
530
|
updateAutomationUI();
|
|
544
531
|
return;
|
|
545
532
|
}
|
|
546
|
-
|
|
547
|
-
|
|
533
|
+
try {
|
|
534
|
+
sessionStorage.removeItem('browserAssistantCodingBatch');
|
|
548
535
|
}
|
|
536
|
+
catch { /* Stop must work when site storage is blocked. */ }
|
|
549
537
|
automation.batch = null;
|
|
550
|
-
for (const request of pendingInference)
|
|
551
|
-
request.abort();
|
|
552
538
|
automation.runId += 1;
|
|
553
539
|
automation.running = false;
|
|
554
540
|
automation.paused = false;
|
|
@@ -751,11 +737,13 @@ function mountJournalCountdown(signal) {
|
|
|
751
737
|
}
|
|
752
738
|
return false;
|
|
753
739
|
}
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
740
|
+
function saveCourseResume(stage, context, details = {}) {
|
|
741
|
+
try {
|
|
742
|
+
sessionStorage.setItem(AUTO_RESUME_KEY, JSON.stringify({
|
|
743
|
+
stage, targetId: context.target.id, createdAt: Date.now(), ...details,
|
|
744
|
+
}));
|
|
745
|
+
}
|
|
746
|
+
catch { /* Resuming after a full page navigation is optional. */ }
|
|
759
747
|
}
|
|
760
748
|
async function waitForCourseAction(getAction, timeoutMs = 12000) {
|
|
761
749
|
const deadline = Date.now() + timeoutMs;
|
|
@@ -767,45 +755,6 @@ function mountJournalCountdown(signal) {
|
|
|
767
755
|
}
|
|
768
756
|
return null;
|
|
769
757
|
}
|
|
770
|
-
function reviewCodingAction(title, confirmLabel, current, proposed) {
|
|
771
|
-
return new Promise(resolve => {
|
|
772
|
-
const host = document.createElement('div');
|
|
773
|
-
const shadow = host.attachShadow({ mode: 'closed' });
|
|
774
|
-
const dialog = document.createElement('dialog');
|
|
775
|
-
dialog.setAttribute('aria-label', title);
|
|
776
|
-
dialog.style.cssText = 'max-width:92vw;max-height:85vh;padding:16px;color:#17233c;background:white;font:14px system-ui';
|
|
777
|
-
const heading = document.createElement('h2');
|
|
778
|
-
heading.textContent = title;
|
|
779
|
-
dialog.appendChild(heading);
|
|
780
|
-
for (const [label, code] of [['Current code', current], ['Proposed code', proposed]]) {
|
|
781
|
-
if (code === undefined)
|
|
782
|
-
continue;
|
|
783
|
-
const caption = document.createElement('h3');
|
|
784
|
-
caption.textContent = label;
|
|
785
|
-
const block = document.createElement('pre');
|
|
786
|
-
block.textContent = code;
|
|
787
|
-
block.style.cssText = 'max-height:24vh;max-width:82vw;overflow:auto;border:1px solid #aaa;padding:8px';
|
|
788
|
-
block.tabIndex = 0;
|
|
789
|
-
dialog.append(caption, block);
|
|
790
|
-
}
|
|
791
|
-
const cancel = document.createElement('button');
|
|
792
|
-
cancel.textContent = 'Cancel';
|
|
793
|
-
const approve = document.createElement('button');
|
|
794
|
-
approve.textContent = confirmLabel;
|
|
795
|
-
const finish = (accepted) => { clearTimeout(timeout); host.remove(); resolve(accepted); };
|
|
796
|
-
cancel.addEventListener('click', event => { if (event.isTrusted)
|
|
797
|
-
finish(false); });
|
|
798
|
-
approve.addEventListener('click', event => { if (event.isTrusted)
|
|
799
|
-
finish(true); });
|
|
800
|
-
dialog.addEventListener('cancel', event => { event.preventDefault(); finish(false); });
|
|
801
|
-
dialog.append(cancel, approve);
|
|
802
|
-
shadow.appendChild(dialog);
|
|
803
|
-
document.documentElement.appendChild(host);
|
|
804
|
-
const timeout = setTimeout(() => finish(false), 120000);
|
|
805
|
-
dialog.showModal();
|
|
806
|
-
cancel.focus();
|
|
807
|
-
});
|
|
808
|
-
}
|
|
809
758
|
async function runCodingAutomation(question, runId, repairAttempt = 0, feedback = '', starterCode = null) {
|
|
810
759
|
automation.codingQuestionText = question.text;
|
|
811
760
|
const active = () => automation.running && automation.runId === runId;
|
|
@@ -840,7 +789,7 @@ function mountJournalCountdown(signal) {
|
|
|
840
789
|
if (!webProject && response.data.code_reviewed !== true) {
|
|
841
790
|
throw new Error('The running server has not enabled code review before submission. Restart the updated Browser Assistant server. No code was submitted.');
|
|
842
791
|
}
|
|
843
|
-
const results =
|
|
792
|
+
const results = typeof response.data.results === 'string' ? JSON.parse(response.data.results) : response.data.results;
|
|
844
793
|
const solutions = results?.filter(item => item.type === 'code' && typeof item.code === 'string' && item.code.trim());
|
|
845
794
|
if (solutions?.length !== 1)
|
|
846
795
|
throw new Error('Expected one complete coding solution.');
|
|
@@ -861,15 +810,6 @@ function mountJournalCountdown(signal) {
|
|
|
861
810
|
throw new Error('Starter code changed while generating the solution. Restart to use the current code.');
|
|
862
811
|
if (getAuthorizedQuestion()?.signature !== question.signature)
|
|
863
812
|
throw new Error('Question changed before code insertion.');
|
|
864
|
-
automation.state = 'WAITING_FOR_CODE_REVIEW';
|
|
865
|
-
updateAutomationUI();
|
|
866
|
-
if (!(await reviewCodingAction('Review the code change', 'Apply reviewed code', original.value, code))) {
|
|
867
|
-
if (active())
|
|
868
|
-
stopAutomation('REVIEW_NEEDED');
|
|
869
|
-
return false;
|
|
870
|
-
}
|
|
871
|
-
if (!(await waitWhilePaused(runId)) || getAuthorizedQuestion()?.signature !== question.signature)
|
|
872
|
-
return false;
|
|
873
813
|
automation.state = 'FILLING_CODE';
|
|
874
814
|
updateAutomationUI();
|
|
875
815
|
const filled = await safeSendMessage({ action: 'codingEditor', operation: webProject ? 'writeProject' : 'write', selector: question.editorSelector, expected: original.value, value: code });
|
|
@@ -885,19 +825,6 @@ function mountJournalCountdown(signal) {
|
|
|
885
825
|
const current = getAutomationContext();
|
|
886
826
|
if (!verified?.ok || verified.value !== code || getAuthorizedQuestion(current)?.signature !== question.signature)
|
|
887
827
|
throw new Error('Editor or question changed before submission.');
|
|
888
|
-
automation.state = 'WAITING_FOR_SUBMIT_APPROVAL';
|
|
889
|
-
updateAutomationUI();
|
|
890
|
-
if (!(await reviewCodingAction('Code applied. Submit for portal grading?', 'Submit for grading'))) {
|
|
891
|
-
if (active())
|
|
892
|
-
stopAutomation('REVIEW_NEEDED');
|
|
893
|
-
return false;
|
|
894
|
-
}
|
|
895
|
-
if (!(await waitWhilePaused(runId)))
|
|
896
|
-
return false;
|
|
897
|
-
const latest = await read();
|
|
898
|
-
if (!active() || latest?.value !== code || getAuthorizedQuestion()?.signature !== question.signature) {
|
|
899
|
-
throw Error('Editor or question changed after review.');
|
|
900
|
-
}
|
|
901
828
|
const submit = window.BrowserAssistantCoding.getSubmit(document);
|
|
902
829
|
if (!automationPolicy.canExecute('submit', current) || !submit)
|
|
903
830
|
throw new Error('Code filled. No unique enabled Submit button found.');
|
|
@@ -981,6 +908,7 @@ function mountJournalCountdown(signal) {
|
|
|
981
908
|
resultObserver?.disconnect();
|
|
982
909
|
}
|
|
983
910
|
}
|
|
911
|
+
const CODING_BATCH_KEY = 'browserAssistantCodingBatch';
|
|
984
912
|
function codingQuestionPath(value, baseUrl) {
|
|
985
913
|
if (!value)
|
|
986
914
|
return '';
|
|
@@ -1026,12 +954,10 @@ function mountJournalCountdown(signal) {
|
|
|
1026
954
|
isCollapsed = false;
|
|
1027
955
|
selectedTab = 'qa';
|
|
1028
956
|
render();
|
|
1029
|
-
const persist =
|
|
957
|
+
const persist = phase => {
|
|
1030
958
|
batch.phase = phase;
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
if (!saved?.ok)
|
|
1034
|
-
throw Error('Could not save the coding checkpoint. Restart from the problem list.');
|
|
959
|
+
batch.updatedAt = Date.now();
|
|
960
|
+
sessionStorage.setItem(CODING_BATCH_KEY, JSON.stringify(batch));
|
|
1035
961
|
};
|
|
1036
962
|
const waitFor = async (predicate, timeout = 20000) => {
|
|
1037
963
|
const deadline = Date.now() + timeout;
|
|
@@ -1069,7 +995,7 @@ function mountJournalCountdown(signal) {
|
|
|
1069
995
|
return;
|
|
1070
996
|
if (!question)
|
|
1071
997
|
throw new Error(window.BrowserAssistantCoding.getDetectionError() || 'Selected coding question did not load or its title did not match.');
|
|
1072
|
-
|
|
998
|
+
persist('busy');
|
|
1073
999
|
const passed = await runCodingAutomation(question, runId);
|
|
1074
1000
|
if (!passed || !automation.running || automation.runId !== runId)
|
|
1075
1001
|
return;
|
|
@@ -1079,15 +1005,13 @@ function mountJournalCountdown(signal) {
|
|
|
1079
1005
|
rememberCompletedCodingQuestion(batch);
|
|
1080
1006
|
batch.completed = automation.completed;
|
|
1081
1007
|
}
|
|
1082
|
-
|
|
1008
|
+
persist('list');
|
|
1083
1009
|
automation.state = 'RETURNING_TO_LIST';
|
|
1084
1010
|
automation.pendingNavigation = true;
|
|
1085
1011
|
updateAutomationUI();
|
|
1086
1012
|
const back = window.BrowserAssistantCodingBatch.getBackControl(document, batch.listUrl);
|
|
1087
1013
|
if (!back)
|
|
1088
1014
|
throw new Error('Accepted. Question Bank Back button was not found; return to the list to continue.');
|
|
1089
|
-
if (!(await waitWhilePaused(runId)))
|
|
1090
|
-
return;
|
|
1091
1015
|
back.click();
|
|
1092
1016
|
let saveConfirmed = false;
|
|
1093
1017
|
const returned = await waitFor(() => {
|
|
@@ -1109,7 +1033,7 @@ function mountJournalCountdown(signal) {
|
|
|
1109
1033
|
throw new Error('Accepted. Back was clicked, but the problem list did not load.');
|
|
1110
1034
|
visited.clear();
|
|
1111
1035
|
batch.title = '';
|
|
1112
|
-
|
|
1036
|
+
persist('list');
|
|
1113
1037
|
continue;
|
|
1114
1038
|
}
|
|
1115
1039
|
automation.state = 'FINDING_UNSOLVED';
|
|
@@ -1137,12 +1061,10 @@ function mountJournalCountdown(signal) {
|
|
|
1137
1061
|
if (next) {
|
|
1138
1062
|
batch.title = next.title;
|
|
1139
1063
|
batch.questionUrl = next.href || null;
|
|
1140
|
-
|
|
1064
|
+
persist('question');
|
|
1141
1065
|
automation.state = 'OPENING_QUESTION';
|
|
1142
1066
|
automation.pendingNavigation = true;
|
|
1143
1067
|
updateAutomationUI();
|
|
1144
|
-
if (!(await waitWhilePaused(runId)))
|
|
1145
|
-
return;
|
|
1146
1068
|
next.action.click();
|
|
1147
1069
|
continue;
|
|
1148
1070
|
}
|
|
@@ -1159,12 +1081,10 @@ function mountJournalCountdown(signal) {
|
|
|
1159
1081
|
}
|
|
1160
1082
|
throw new Error('No Not Attempted or In Progress questions on this page; the next-page control could not be identified.');
|
|
1161
1083
|
}
|
|
1162
|
-
|
|
1084
|
+
persist('list');
|
|
1163
1085
|
automation.state = 'NEXT_LIST_PAGE';
|
|
1164
1086
|
automation.pendingNavigation = true;
|
|
1165
1087
|
updateAutomationUI();
|
|
1166
|
-
if (!(await waitWhilePaused(runId)))
|
|
1167
|
-
return;
|
|
1168
1088
|
nextPage.click();
|
|
1169
1089
|
const changed = await waitFor(() => {
|
|
1170
1090
|
const updated = window.BrowserAssistantCodingBatch.pageRange(document);
|
|
@@ -1184,11 +1104,20 @@ function mountJournalCountdown(signal) {
|
|
|
1184
1104
|
}
|
|
1185
1105
|
}
|
|
1186
1106
|
async function resumeCodingBatch() {
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1107
|
+
let saved;
|
|
1108
|
+
try {
|
|
1109
|
+
saved = JSON.parse(sessionStorage.getItem(CODING_BATCH_KEY) || 'null');
|
|
1110
|
+
}
|
|
1111
|
+
catch {
|
|
1112
|
+
return false;
|
|
1113
|
+
}
|
|
1114
|
+
if (!saved)
|
|
1190
1115
|
return false;
|
|
1191
|
-
|
|
1116
|
+
if (saved.origin !== location.origin || Date.now() - saved.updatedAt > 120000) {
|
|
1117
|
+
sessionStorage.removeItem(CODING_BATCH_KEY);
|
|
1118
|
+
return false;
|
|
1119
|
+
}
|
|
1120
|
+
await startCodingBatch(saved);
|
|
1192
1121
|
return true;
|
|
1193
1122
|
}
|
|
1194
1123
|
async function runOnlineIdeAutomation(question) {
|
|
@@ -1229,32 +1158,20 @@ function mountJournalCountdown(signal) {
|
|
|
1229
1158
|
return ide;
|
|
1230
1159
|
}
|
|
1231
1160
|
try {
|
|
1232
|
-
const response = await apiRequest('/solve', 'POST', {
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1161
|
+
const [ide, response] = await Promise.all([openOnlineIde(), apiRequest('/solve', 'POST', {
|
|
1162
|
+
url, practice_type: 'code', language: 'javascript', review_before_submit: true,
|
|
1163
|
+
text: `${question.text}\n\nGenerate the complete app.js for the online Node.js IDE. Use the stated database, route methods, response bodies and module format. Use parameterized SQL where applicable. Return source code for app.js only.`,
|
|
1164
|
+
})]);
|
|
1236
1165
|
if (!(await waitWhilePaused(runId)) || !current())
|
|
1237
1166
|
return;
|
|
1238
1167
|
if (!response?.ok)
|
|
1239
1168
|
throw window.BrowserAssistantAnswerRequests.failure(response);
|
|
1240
|
-
const solutions =
|
|
1169
|
+
const solutions = JSON.parse(response.data.results);
|
|
1241
1170
|
if (!Array.isArray(solutions) || solutions.length !== 1 || solutions[0].type !== 'code'
|
|
1242
1171
|
|| typeof solutions[0].code !== 'string' || !solutions[0].code.trim()) {
|
|
1243
1172
|
throw new Error('The server did not return a complete app.js solution.');
|
|
1244
1173
|
}
|
|
1245
1174
|
const solution = solutions[0];
|
|
1246
|
-
automation.state = 'WAITING_FOR_CODE_REVIEW';
|
|
1247
|
-
updateAutomationUI();
|
|
1248
|
-
if (!(await reviewCodingAction('Review the proposed app.js', 'Open IDE and apply', undefined, solution.code))) {
|
|
1249
|
-
if (current())
|
|
1250
|
-
stopAutomation('REVIEW_NEEDED');
|
|
1251
|
-
return;
|
|
1252
|
-
}
|
|
1253
|
-
if (!(await waitWhilePaused(runId)) || !current())
|
|
1254
|
-
return;
|
|
1255
|
-
const ide = await openOnlineIde();
|
|
1256
|
-
if (!current())
|
|
1257
|
-
return;
|
|
1258
1175
|
let instructions = ide?.found
|
|
1259
1176
|
? 'Copy into app.js in the IDE tab after the workspace is ready, then save.'
|
|
1260
1177
|
: 'Use the portal Open IDE button, then copy into app.js and save.';
|
|
@@ -1282,7 +1199,7 @@ function mountJournalCountdown(signal) {
|
|
|
1282
1199
|
return;
|
|
1283
1200
|
}
|
|
1284
1201
|
if (launched?.started) {
|
|
1285
|
-
automation.state = '
|
|
1202
|
+
automation.state = 'WAITING_FOR_IDE_GRADING';
|
|
1286
1203
|
updateAutomationUI();
|
|
1287
1204
|
const resultDeadline = Date.now() + 240000;
|
|
1288
1205
|
while (current() && Date.now() < resultDeadline) {
|
|
@@ -1292,17 +1209,13 @@ function mountJournalCountdown(signal) {
|
|
|
1292
1209
|
if (!current())
|
|
1293
1210
|
return;
|
|
1294
1211
|
if (result?.done) {
|
|
1295
|
-
if (result.
|
|
1212
|
+
if (result.passed)
|
|
1296
1213
|
automation.completed = 1;
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
? 'Code was pasted, but the saved file did not match. Check app.js and save it.'
|
|
1303
|
-
: 'JavaScript syntax check failed. Review the IDE terminal.';
|
|
1304
|
-
stopAutomation('CHECK_IDE_RESULT');
|
|
1305
|
-
}
|
|
1214
|
+
else if (result.saveUnconfirmed)
|
|
1215
|
+
automation.error = 'Code was pasted into app.js, but the saved file did not match. Check app.js and save before running it.';
|
|
1216
|
+
else
|
|
1217
|
+
automation.error = result.submitted ? 'Grading finished. Review the test results in the IDE.' : 'The IDE command finished without a confirmed submission. Check the terminal.';
|
|
1218
|
+
stopAutomation(result.passed ? 'COMPLETED' : 'CHECK_IDE_RESULT');
|
|
1306
1219
|
return;
|
|
1307
1220
|
}
|
|
1308
1221
|
if (result?.ok === false && !result.retry)
|
|
@@ -1439,10 +1352,7 @@ function mountJournalCountdown(signal) {
|
|
|
1439
1352
|
automation.state = 'STARTING_PRACTICE';
|
|
1440
1353
|
automation.targetId = initialContext.target.id;
|
|
1441
1354
|
updateAutomationUI();
|
|
1442
|
-
|
|
1443
|
-
await saveCourseResume('solve', initialContext, startPractice);
|
|
1444
|
-
if (generation !== automation.runId)
|
|
1445
|
-
return;
|
|
1355
|
+
saveCourseResume('solve', initialContext);
|
|
1446
1356
|
startPractice.click();
|
|
1447
1357
|
setTimeout(() => { void resumeAuthorizedQaAfterNavigation(); }, 900);
|
|
1448
1358
|
return;
|
|
@@ -1544,9 +1454,10 @@ function mountJournalCountdown(signal) {
|
|
|
1544
1454
|
automation.pendingNavigation = true;
|
|
1545
1455
|
updateAutomationUI();
|
|
1546
1456
|
const previousUrl = window.location.href;
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1457
|
+
try {
|
|
1458
|
+
sessionStorage.setItem(AUTO_RESUME_KEY, JSON.stringify({ targetId: automation.targetId, fromUrl: previousUrl, createdAt: Date.now() }));
|
|
1459
|
+
}
|
|
1460
|
+
catch { /* Resuming after a full page navigation is optional. */ }
|
|
1550
1461
|
nextPractice.click();
|
|
1551
1462
|
if (!(await waitForNextPracticeQuestion(previousUrl, runId))) {
|
|
1552
1463
|
automation.error = 'Next practice did not load in time.';
|
|
@@ -1659,7 +1570,7 @@ function mountJournalCountdown(signal) {
|
|
|
1659
1570
|
}
|
|
1660
1571
|
let results;
|
|
1661
1572
|
try {
|
|
1662
|
-
results =
|
|
1573
|
+
results = JSON.parse(response.data.results);
|
|
1663
1574
|
}
|
|
1664
1575
|
catch {
|
|
1665
1576
|
automation.error = 'AI returned an invalid answer.';
|
|
@@ -1819,14 +1730,10 @@ function mountJournalCountdown(signal) {
|
|
|
1819
1730
|
automation.state = 'OPENING_COURSE';
|
|
1820
1731
|
automation.pendingNavigation = true;
|
|
1821
1732
|
updateAutomationUI();
|
|
1822
|
-
|
|
1733
|
+
saveCourseResume('course', transition.context, {
|
|
1823
1734
|
currentTitle: currentAdapter.getCurrentPracticeTitle?.(document) || '',
|
|
1824
1735
|
});
|
|
1825
|
-
if (!(await waitWhilePaused(runId)))
|
|
1826
|
-
return;
|
|
1827
|
-
automation.running = false;
|
|
1828
1736
|
transition.proceed.click();
|
|
1829
|
-
setTimeout(() => { void resumeAuthorizedQaAfterNavigation(); }, 900);
|
|
1830
1737
|
return;
|
|
1831
1738
|
}
|
|
1832
1739
|
if (transition?.advance) {
|
|
@@ -1951,34 +1858,23 @@ function mountJournalCountdown(signal) {
|
|
|
1951
1858
|
// Route local API traffic through the extension service worker instead of
|
|
1952
1859
|
// the page context, so visited sites cannot directly access the API.
|
|
1953
1860
|
async function apiRequest(path, method = 'POST', body) {
|
|
1954
|
-
|
|
1955
|
-
if (method === 'POST' && ['/solve', '/solve-vision'].includes(path)) {
|
|
1956
|
-
const request = new AbortController();
|
|
1957
|
-
pendingInference.add(request);
|
|
1958
|
-
try {
|
|
1959
|
-
response = await browserAssistantLocalInference(path, body, msg => safeSendMessage(msg, 15000), request.signal);
|
|
1960
|
-
}
|
|
1961
|
-
finally {
|
|
1962
|
-
pendingInference.delete(request);
|
|
1963
|
-
}
|
|
1964
|
-
}
|
|
1965
|
-
else {
|
|
1966
|
-
response = await safeSendMessage({ action: 'apiRequest', path, method, body }, 15000);
|
|
1967
|
-
}
|
|
1861
|
+
const response = await safeSendMessage({ action: 'apiRequest', path, method, body }, 370000);
|
|
1968
1862
|
if (!response)
|
|
1969
1863
|
throw new Error('Local server did not respond');
|
|
1970
|
-
if (response.error)
|
|
1864
|
+
if (response.error) {
|
|
1865
|
+
if (response.error.startsWith('Local server is offline'))
|
|
1866
|
+
setServerStatus(false);
|
|
1971
1867
|
throw new Error(response.error);
|
|
1868
|
+
}
|
|
1869
|
+
if (path !== '/health' && response.status)
|
|
1870
|
+
setServerStatus(true);
|
|
1972
1871
|
return response;
|
|
1973
1872
|
}
|
|
1974
1873
|
async function saveScanHistory(results, provider, scanType, language = null) {
|
|
1975
1874
|
try {
|
|
1976
|
-
if (!(await chrome.storage.local.get({ assistantSaveHistory: false })).assistantSaveHistory)
|
|
1977
|
-
return;
|
|
1978
|
-
const page = new URL(location.href);
|
|
1979
1875
|
const response = await apiRequest('/history', 'POST', {
|
|
1980
1876
|
scan_type: scanType,
|
|
1981
|
-
url:
|
|
1877
|
+
url: window.location.href,
|
|
1982
1878
|
provider: provider || 'unknown',
|
|
1983
1879
|
results: JSON.stringify(results),
|
|
1984
1880
|
language,
|
|
@@ -1999,14 +1895,7 @@ function mountJournalCountdown(signal) {
|
|
|
1999
1895
|
const response = await apiRequest('/history', 'GET');
|
|
2000
1896
|
if (!response.ok)
|
|
2001
1897
|
throw new Error(response.data?.detail || 'Could not load history');
|
|
2002
|
-
historyItems =
|
|
2003
|
-
try {
|
|
2004
|
-
return new URL(item.url).origin === location.origin;
|
|
2005
|
-
}
|
|
2006
|
-
catch {
|
|
2007
|
-
return false;
|
|
2008
|
-
}
|
|
2009
|
-
});
|
|
1898
|
+
historyItems = response.data?.items || [];
|
|
2010
1899
|
renderHistory();
|
|
2011
1900
|
}
|
|
2012
1901
|
catch (error) {
|
|
@@ -2031,17 +1920,24 @@ function mountJournalCountdown(signal) {
|
|
|
2031
1920
|
}
|
|
2032
1921
|
}
|
|
2033
1922
|
// ── Server health check ───────────────────────────────────────────────────
|
|
1923
|
+
function setServerStatus(online) {
|
|
1924
|
+
serverOnline = online;
|
|
1925
|
+
const dot = root.querySelector('.status-dot');
|
|
1926
|
+
if (!dot)
|
|
1927
|
+
return;
|
|
1928
|
+
dot.classList.remove('unknown', 'online', 'offline');
|
|
1929
|
+
dot.classList.add(online ? 'online' : 'offline');
|
|
1930
|
+
dot.setAttribute('title', online ? 'Server online' : 'Server offline');
|
|
1931
|
+
}
|
|
2034
1932
|
async function checkServer() {
|
|
1933
|
+
let online = false;
|
|
2035
1934
|
try {
|
|
2036
1935
|
const res = await apiRequest('/health', 'GET');
|
|
2037
|
-
|
|
2038
|
-
}
|
|
2039
|
-
catch {
|
|
2040
|
-
serverOnline = false;
|
|
1936
|
+
online = res.ok;
|
|
2041
1937
|
}
|
|
2042
|
-
|
|
2043
|
-
if (
|
|
2044
|
-
|
|
1938
|
+
catch { /* The next request can reconnect when the backend starts. */ }
|
|
1939
|
+
if (serverOnline === null)
|
|
1940
|
+
setServerStatus(online);
|
|
2045
1941
|
}
|
|
2046
1942
|
// Check once on load
|
|
2047
1943
|
checkServer();
|
|
@@ -2174,15 +2070,11 @@ function mountJournalCountdown(signal) {
|
|
|
2174
2070
|
root.style.display = 'none';
|
|
2175
2071
|
}
|
|
2176
2072
|
function handleAutomationShortcut(e) {
|
|
2177
|
-
if (
|
|
2073
|
+
if (e.repeat || e.isComposing || e.defaultPrevented || !e.altKey || e.ctrlKey || e.metaKey
|
|
2178
2074
|
|| (e.code !== 'KeyA' && String(e.key).toLowerCase() !== 'a'))
|
|
2179
2075
|
return false;
|
|
2180
2076
|
e.preventDefault();
|
|
2181
2077
|
e.stopPropagation();
|
|
2182
|
-
toggleAutomation();
|
|
2183
|
-
return true;
|
|
2184
|
-
}
|
|
2185
|
-
function toggleAutomation() {
|
|
2186
2078
|
selectedTab = 'qa';
|
|
2187
2079
|
isHidden = false;
|
|
2188
2080
|
isCollapsed = false;
|
|
@@ -2202,11 +2094,12 @@ function mountJournalCountdown(signal) {
|
|
|
2202
2094
|
stopAutomation('ERROR');
|
|
2203
2095
|
});
|
|
2204
2096
|
}
|
|
2097
|
+
return true;
|
|
2205
2098
|
}
|
|
2206
2099
|
// ── Keyboard shortcuts ────────────────────────────────────────────────────
|
|
2207
2100
|
document.addEventListener('keydown', (e) => {
|
|
2208
2101
|
// Block held-key auto-repeat to prevent rapid-fire race conditions
|
|
2209
|
-
if (
|
|
2102
|
+
if (e.repeat || e.isComposing)
|
|
2210
2103
|
return;
|
|
2211
2104
|
// Explicit automation chord also works while the code editor has focus.
|
|
2212
2105
|
if (handleAutomationShortcut(e))
|
|
@@ -2277,18 +2170,10 @@ function mountJournalCountdown(signal) {
|
|
|
2277
2170
|
}
|
|
2278
2171
|
else {
|
|
2279
2172
|
await new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve)));
|
|
2280
|
-
const response = await safeSendMessage({ action:
|
|
2173
|
+
const response = await safeSendMessage({ action: "captureVisibleTab" });
|
|
2281
2174
|
if (!response?.dataUrl || response.error)
|
|
2282
2175
|
throw new Error(response?.error || 'Screenshot capture failed');
|
|
2283
|
-
|
|
2284
|
-
if (journalCountdownBadge)
|
|
2285
|
-
journalCountdownBadge.style.visibility = countdownVisibility;
|
|
2286
|
-
const reviewed = await visuals.reviewCapture(response.dataUrl, context.question);
|
|
2287
|
-
if (!reviewed) {
|
|
2288
|
-
render();
|
|
2289
|
-
return;
|
|
2290
|
-
}
|
|
2291
|
-
images = [reviewed];
|
|
2176
|
+
images = [response.dataUrl];
|
|
2292
2177
|
}
|
|
2293
2178
|
root.style.visibility = panelVisibility;
|
|
2294
2179
|
if (journalCountdownBadge)
|
|
@@ -2311,7 +2196,7 @@ function mountJournalCountdown(signal) {
|
|
|
2311
2196
|
await assertVisionQuestionCurrent(context);
|
|
2312
2197
|
let parsed;
|
|
2313
2198
|
try {
|
|
2314
|
-
parsed =
|
|
2199
|
+
parsed = JSON.parse(data.results);
|
|
2315
2200
|
}
|
|
2316
2201
|
catch (e) {
|
|
2317
2202
|
throw new Error('Vision returned an invalid answer format. Please scan a clear, complete question again.');
|
|
@@ -2360,7 +2245,7 @@ function mountJournalCountdown(signal) {
|
|
|
2360
2245
|
}
|
|
2361
2246
|
}
|
|
2362
2247
|
async function prepareVisionQuestionContext() {
|
|
2363
|
-
const context = { url: location.href, text: '', question: getAuthorizedQuestion(
|
|
2248
|
+
const context = { url: location.href, text: '', question: getAuthorizedQuestion() };
|
|
2364
2249
|
if (!context.question || context.question.type === 'code') {
|
|
2365
2250
|
context.question = null;
|
|
2366
2251
|
return context;
|
|
@@ -2395,7 +2280,7 @@ function mountJournalCountdown(signal) {
|
|
|
2395
2280
|
throw new Error('Page changed while scanning. Please scan the current question again.');
|
|
2396
2281
|
if (!context.question)
|
|
2397
2282
|
return;
|
|
2398
|
-
const fresh = getAuthorizedQuestion(
|
|
2283
|
+
const fresh = getAuthorizedQuestion();
|
|
2399
2284
|
if (!hasSameQuestionOptions(context.question, fresh)
|
|
2400
2285
|
|| (context.visualSnapshot && window.BrowserAssistantQuestionVisuals.fingerprint(fresh) !== context.visualSnapshot)) {
|
|
2401
2286
|
throw new Error('Question or illustration changed while scanning. Please scan again.');
|
|
@@ -2412,12 +2297,6 @@ function mountJournalCountdown(signal) {
|
|
|
2412
2297
|
if (isScanning)
|
|
2413
2298
|
return;
|
|
2414
2299
|
isScanning = true;
|
|
2415
|
-
// Show server-offline warning early
|
|
2416
|
-
if (serverOnline === false) {
|
|
2417
|
-
showError("Server offline. Start the backend with: python main.py");
|
|
2418
|
-
isScanning = false;
|
|
2419
|
-
return;
|
|
2420
|
-
}
|
|
2421
2300
|
isCollapsed = false;
|
|
2422
2301
|
render();
|
|
2423
2302
|
setLoading("Solving…");
|
|
@@ -2460,10 +2339,9 @@ function mountJournalCountdown(signal) {
|
|
|
2460
2339
|
}
|
|
2461
2340
|
const data = res.data;
|
|
2462
2341
|
await assertVisionQuestionCurrent(context);
|
|
2463
|
-
serverOnline = true;
|
|
2464
2342
|
let parsed;
|
|
2465
2343
|
try {
|
|
2466
|
-
parsed =
|
|
2344
|
+
parsed = JSON.parse(data.results);
|
|
2467
2345
|
}
|
|
2468
2346
|
catch (e) {
|
|
2469
2347
|
if (question || practiceType !== 'code')
|
|
@@ -2487,10 +2365,6 @@ function mountJournalCountdown(signal) {
|
|
|
2487
2365
|
if (error.name === 'AbortError') {
|
|
2488
2366
|
showError("Request timed out — server may be busy, please try again");
|
|
2489
2367
|
}
|
|
2490
|
-
else if (error instanceof TypeError && error.message.includes('fetch')) {
|
|
2491
|
-
serverOnline = false;
|
|
2492
|
-
showError(`Error: ${error.message}`);
|
|
2493
|
-
}
|
|
2494
2368
|
else {
|
|
2495
2369
|
showError(`Error: ${error.message}`);
|
|
2496
2370
|
}
|
|
@@ -2552,8 +2426,7 @@ function mountJournalCountdown(signal) {
|
|
|
2552
2426
|
const retry = document.createElement('button');
|
|
2553
2427
|
retry.className = 'assistant-history-btn';
|
|
2554
2428
|
retry.textContent = 'Retry history';
|
|
2555
|
-
retry.onclick =
|
|
2556
|
-
void openHistory(); };
|
|
2429
|
+
retry.onclick = openHistory;
|
|
2557
2430
|
container.append(error, retry);
|
|
2558
2431
|
}
|
|
2559
2432
|
function renderHistory() {
|
|
@@ -2564,7 +2437,7 @@ function mountJournalCountdown(signal) {
|
|
|
2564
2437
|
const header = document.createElement('div');
|
|
2565
2438
|
header.className = 'assistant-history-header';
|
|
2566
2439
|
const title = document.createElement('strong');
|
|
2567
|
-
title.textContent = 'Recent scans
|
|
2440
|
+
title.textContent = 'Recent scans';
|
|
2568
2441
|
const actions = document.createElement('div');
|
|
2569
2442
|
const back = document.createElement('button');
|
|
2570
2443
|
back.className = 'assistant-history-action';
|
|
@@ -2575,11 +2448,8 @@ function mountJournalCountdown(signal) {
|
|
|
2575
2448
|
const clear = document.createElement('button');
|
|
2576
2449
|
clear.className = 'assistant-history-action danger';
|
|
2577
2450
|
clear.id = 'assistant-clear-history-btn';
|
|
2578
|
-
clear.textContent = 'Clear
|
|
2579
|
-
clear.onclick =
|
|
2580
|
-
if (event.isTrusted && window.confirm('Delete saved scans for all sites?'))
|
|
2581
|
-
void clearHistory();
|
|
2582
|
-
};
|
|
2451
|
+
clear.textContent = 'Clear';
|
|
2452
|
+
clear.onclick = clearHistory;
|
|
2583
2453
|
actions.appendChild(clear);
|
|
2584
2454
|
}
|
|
2585
2455
|
header.append(title, actions);
|
|
@@ -2587,7 +2457,7 @@ function mountJournalCountdown(signal) {
|
|
|
2587
2457
|
if (!historyItems.length) {
|
|
2588
2458
|
const empty = document.createElement('div');
|
|
2589
2459
|
empty.className = 'assistant-placeholder';
|
|
2590
|
-
empty.textContent = 'No saved scans
|
|
2460
|
+
empty.textContent = 'No saved scans yet. Run Text Scan or Vision Scan to build your history.';
|
|
2591
2461
|
container.appendChild(empty);
|
|
2592
2462
|
return;
|
|
2593
2463
|
}
|
|
@@ -2822,19 +2692,10 @@ function mountJournalCountdown(signal) {
|
|
|
2822
2692
|
document.getElementById('mode-code').onclick = () => selectTab('code');
|
|
2823
2693
|
document.getElementById('mode-qa').onclick = () => selectTab('qa');
|
|
2824
2694
|
bindTabKeyboardNavigation();
|
|
2825
|
-
document.getElementById('assistant-history-btn').onclick =
|
|
2826
|
-
|
|
2827
|
-
document.getElementById('assistant-
|
|
2828
|
-
|
|
2829
|
-
document.getElementById('assistant-vision-btn')?.addEventListener('click', event => { if (event.isTrusted)
|
|
2830
|
-
void visionScan(); });
|
|
2831
|
-
document.getElementById('assistant-auto-start-btn')?.addEventListener('click', event => {
|
|
2832
|
-
if (event.isTrusted)
|
|
2833
|
-
void startPracticeAutomation().catch(error => {
|
|
2834
|
-
automation.error = error.message;
|
|
2835
|
-
stopAutomation('ERROR');
|
|
2836
|
-
});
|
|
2837
|
-
});
|
|
2695
|
+
document.getElementById('assistant-history-btn').onclick = openHistory;
|
|
2696
|
+
document.getElementById('assistant-scan-btn')?.addEventListener('click', scanPage);
|
|
2697
|
+
document.getElementById('assistant-vision-btn')?.addEventListener('click', () => { void visionScan(); });
|
|
2698
|
+
document.getElementById('assistant-auto-start-btn')?.addEventListener('click', startPracticeAutomation);
|
|
2838
2699
|
document.getElementById('assistant-export-question-btn')?.addEventListener('click', exportQuestionDiagnostic);
|
|
2839
2700
|
document.getElementById('assistant-auto-pause-btn')?.addEventListener('click', pauseOrResumeAutomation);
|
|
2840
2701
|
document.getElementById('assistant-auto-stop-btn')?.addEventListener('click', () => stopAutomation());
|
|
@@ -2897,12 +2758,14 @@ function mountJournalCountdown(signal) {
|
|
|
2897
2758
|
}
|
|
2898
2759
|
}
|
|
2899
2760
|
function renderFullResults(container, results, provider) {
|
|
2761
|
+
// Show provider with verified badge if applicable
|
|
2900
2762
|
provider = provider || "unknown";
|
|
2901
|
-
const
|
|
2902
|
-
|
|
2903
|
-
|
|
2904
|
-
|
|
2905
|
-
|
|
2763
|
+
const isVerified = provider.includes('[verified]');
|
|
2764
|
+
const safeProvider = escapeHtml(provider.toUpperCase());
|
|
2765
|
+
const providerBadge = isVerified
|
|
2766
|
+
? `<div class="assistant-provider-badge verified">✅ via ${safeProvider}</div>`
|
|
2767
|
+
: `<div class="assistant-provider-badge">via ${safeProvider}</div>`;
|
|
2768
|
+
container.innerHTML = providerBadge;
|
|
2906
2769
|
results.forEach((res, index) => {
|
|
2907
2770
|
if (res.type === 'code') {
|
|
2908
2771
|
const codeContent = res.code || res.answer || "";
|
|
@@ -2994,12 +2857,17 @@ function mountJournalCountdown(signal) {
|
|
|
2994
2857
|
}
|
|
2995
2858
|
}
|
|
2996
2859
|
async function resumeAuthorizedQaAfterNavigation() {
|
|
2997
|
-
|
|
2998
|
-
|
|
2999
|
-
|
|
2860
|
+
let resume;
|
|
2861
|
+
try {
|
|
2862
|
+
resume = JSON.parse(sessionStorage.getItem(AUTO_RESUME_KEY) || 'null');
|
|
2863
|
+
sessionStorage.removeItem(AUTO_RESUME_KEY);
|
|
2864
|
+
}
|
|
2865
|
+
catch {
|
|
2866
|
+
return;
|
|
2867
|
+
}
|
|
3000
2868
|
const context = getAutomationContext();
|
|
3001
|
-
|
|
3002
|
-
|
|
2869
|
+
const isFresh = Number.isFinite(resume?.createdAt) && Date.now() - resume.createdAt < 120000;
|
|
2870
|
+
if (!isFresh || resume.targetId !== context.target?.id || context.mode !== 'FULL')
|
|
3003
2871
|
return;
|
|
3004
2872
|
isCollapsed = false;
|
|
3005
2873
|
render();
|
|
@@ -3016,11 +2884,9 @@ function mountJournalCountdown(signal) {
|
|
|
3016
2884
|
}
|
|
3017
2885
|
automation.state = 'OPENING_NEXT_PRACTICE';
|
|
3018
2886
|
updateAutomationUI();
|
|
3019
|
-
|
|
3020
|
-
|
|
3021
|
-
|
|
3022
|
-
nextPractice.scrollIntoView({ block: 'center' });
|
|
3023
|
-
nextPractice.click();
|
|
2887
|
+
saveCourseResume('start', context);
|
|
2888
|
+
nextPractice.scrollIntoView({ block: 'center', behavior: 'smooth' });
|
|
2889
|
+
setTimeout(() => nextPractice.click(), 250);
|
|
3024
2890
|
setTimeout(() => { void resumeAuthorizedQaAfterNavigation(); }, 900);
|
|
3025
2891
|
return;
|
|
3026
2892
|
}
|
|
@@ -3034,9 +2900,7 @@ function mountJournalCountdown(signal) {
|
|
|
3034
2900
|
}
|
|
3035
2901
|
automation.state = 'STARTING_PRACTICE';
|
|
3036
2902
|
updateAutomationUI();
|
|
3037
|
-
|
|
3038
|
-
if (generation !== automation.runId || !startPractice.isConnected)
|
|
3039
|
-
return;
|
|
2903
|
+
saveCourseResume('solve', context);
|
|
3040
2904
|
startPractice.click();
|
|
3041
2905
|
setTimeout(() => { void resumeAuthorizedQaAfterNavigation(); }, 900);
|
|
3042
2906
|
return;
|
|
@@ -3050,8 +2914,7 @@ function mountJournalCountdown(signal) {
|
|
|
3050
2914
|
return;
|
|
3051
2915
|
}
|
|
3052
2916
|
}
|
|
3053
|
-
|
|
3054
|
-
void startPracticeAutomation();
|
|
2917
|
+
void startPracticeAutomation();
|
|
3055
2918
|
}
|
|
3056
2919
|
let reopenedAfterUpdate = false;
|
|
3057
2920
|
try {
|