browser-assistant 2.9.0 → 2.9.1
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 +11 -14
- package/extension/answer-requests.js +0 -33
- package/extension/automation-policy.js +1 -2
- package/extension/background.js +36 -191
- package/extension/content.js +101 -239
- 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 +1 -80
- package/extension/styles.css +0 -7
- package/package.json +2 -5
- package/server/.env.example +0 -2
- package/server/journal.py +1 -2
- package/server/local_security.py +1 -74
- package/server/main.py +7 -62
- package/server/inference_jobs.py +0 -90
package/extension/content.js
CHANGED
|
@@ -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,20 +1858,7 @@ 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
1864
|
if (response.error)
|
|
@@ -1973,12 +1867,9 @@ function mountJournalCountdown(signal) {
|
|
|
1973
1867
|
}
|
|
1974
1868
|
async function saveScanHistory(results, provider, scanType, language = null) {
|
|
1975
1869
|
try {
|
|
1976
|
-
if (!(await chrome.storage.local.get({ assistantSaveHistory: false })).assistantSaveHistory)
|
|
1977
|
-
return;
|
|
1978
|
-
const page = new URL(location.href);
|
|
1979
1870
|
const response = await apiRequest('/history', 'POST', {
|
|
1980
1871
|
scan_type: scanType,
|
|
1981
|
-
url:
|
|
1872
|
+
url: window.location.href,
|
|
1982
1873
|
provider: provider || 'unknown',
|
|
1983
1874
|
results: JSON.stringify(results),
|
|
1984
1875
|
language,
|
|
@@ -1999,14 +1890,7 @@ function mountJournalCountdown(signal) {
|
|
|
1999
1890
|
const response = await apiRequest('/history', 'GET');
|
|
2000
1891
|
if (!response.ok)
|
|
2001
1892
|
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
|
-
});
|
|
1893
|
+
historyItems = response.data?.items || [];
|
|
2010
1894
|
renderHistory();
|
|
2011
1895
|
}
|
|
2012
1896
|
catch (error) {
|
|
@@ -2174,15 +2058,11 @@ function mountJournalCountdown(signal) {
|
|
|
2174
2058
|
root.style.display = 'none';
|
|
2175
2059
|
}
|
|
2176
2060
|
function handleAutomationShortcut(e) {
|
|
2177
|
-
if (
|
|
2061
|
+
if (e.repeat || e.isComposing || e.defaultPrevented || !e.altKey || e.ctrlKey || e.metaKey
|
|
2178
2062
|
|| (e.code !== 'KeyA' && String(e.key).toLowerCase() !== 'a'))
|
|
2179
2063
|
return false;
|
|
2180
2064
|
e.preventDefault();
|
|
2181
2065
|
e.stopPropagation();
|
|
2182
|
-
toggleAutomation();
|
|
2183
|
-
return true;
|
|
2184
|
-
}
|
|
2185
|
-
function toggleAutomation() {
|
|
2186
2066
|
selectedTab = 'qa';
|
|
2187
2067
|
isHidden = false;
|
|
2188
2068
|
isCollapsed = false;
|
|
@@ -2202,11 +2082,12 @@ function mountJournalCountdown(signal) {
|
|
|
2202
2082
|
stopAutomation('ERROR');
|
|
2203
2083
|
});
|
|
2204
2084
|
}
|
|
2085
|
+
return true;
|
|
2205
2086
|
}
|
|
2206
2087
|
// ── Keyboard shortcuts ────────────────────────────────────────────────────
|
|
2207
2088
|
document.addEventListener('keydown', (e) => {
|
|
2208
2089
|
// Block held-key auto-repeat to prevent rapid-fire race conditions
|
|
2209
|
-
if (
|
|
2090
|
+
if (e.repeat || e.isComposing)
|
|
2210
2091
|
return;
|
|
2211
2092
|
// Explicit automation chord also works while the code editor has focus.
|
|
2212
2093
|
if (handleAutomationShortcut(e))
|
|
@@ -2277,18 +2158,10 @@ function mountJournalCountdown(signal) {
|
|
|
2277
2158
|
}
|
|
2278
2159
|
else {
|
|
2279
2160
|
await new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve)));
|
|
2280
|
-
const response = await safeSendMessage({ action:
|
|
2161
|
+
const response = await safeSendMessage({ action: "captureVisibleTab" });
|
|
2281
2162
|
if (!response?.dataUrl || response.error)
|
|
2282
2163
|
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];
|
|
2164
|
+
images = [response.dataUrl];
|
|
2292
2165
|
}
|
|
2293
2166
|
root.style.visibility = panelVisibility;
|
|
2294
2167
|
if (journalCountdownBadge)
|
|
@@ -2311,7 +2184,7 @@ function mountJournalCountdown(signal) {
|
|
|
2311
2184
|
await assertVisionQuestionCurrent(context);
|
|
2312
2185
|
let parsed;
|
|
2313
2186
|
try {
|
|
2314
|
-
parsed =
|
|
2187
|
+
parsed = JSON.parse(data.results);
|
|
2315
2188
|
}
|
|
2316
2189
|
catch (e) {
|
|
2317
2190
|
throw new Error('Vision returned an invalid answer format. Please scan a clear, complete question again.');
|
|
@@ -2360,7 +2233,7 @@ function mountJournalCountdown(signal) {
|
|
|
2360
2233
|
}
|
|
2361
2234
|
}
|
|
2362
2235
|
async function prepareVisionQuestionContext() {
|
|
2363
|
-
const context = { url: location.href, text: '', question: getAuthorizedQuestion(
|
|
2236
|
+
const context = { url: location.href, text: '', question: getAuthorizedQuestion() };
|
|
2364
2237
|
if (!context.question || context.question.type === 'code') {
|
|
2365
2238
|
context.question = null;
|
|
2366
2239
|
return context;
|
|
@@ -2395,7 +2268,7 @@ function mountJournalCountdown(signal) {
|
|
|
2395
2268
|
throw new Error('Page changed while scanning. Please scan the current question again.');
|
|
2396
2269
|
if (!context.question)
|
|
2397
2270
|
return;
|
|
2398
|
-
const fresh = getAuthorizedQuestion(
|
|
2271
|
+
const fresh = getAuthorizedQuestion();
|
|
2399
2272
|
if (!hasSameQuestionOptions(context.question, fresh)
|
|
2400
2273
|
|| (context.visualSnapshot && window.BrowserAssistantQuestionVisuals.fingerprint(fresh) !== context.visualSnapshot)) {
|
|
2401
2274
|
throw new Error('Question or illustration changed while scanning. Please scan again.');
|
|
@@ -2463,7 +2336,7 @@ function mountJournalCountdown(signal) {
|
|
|
2463
2336
|
serverOnline = true;
|
|
2464
2337
|
let parsed;
|
|
2465
2338
|
try {
|
|
2466
|
-
parsed =
|
|
2339
|
+
parsed = JSON.parse(data.results);
|
|
2467
2340
|
}
|
|
2468
2341
|
catch (e) {
|
|
2469
2342
|
if (question || practiceType !== 'code')
|
|
@@ -2552,8 +2425,7 @@ function mountJournalCountdown(signal) {
|
|
|
2552
2425
|
const retry = document.createElement('button');
|
|
2553
2426
|
retry.className = 'assistant-history-btn';
|
|
2554
2427
|
retry.textContent = 'Retry history';
|
|
2555
|
-
retry.onclick =
|
|
2556
|
-
void openHistory(); };
|
|
2428
|
+
retry.onclick = openHistory;
|
|
2557
2429
|
container.append(error, retry);
|
|
2558
2430
|
}
|
|
2559
2431
|
function renderHistory() {
|
|
@@ -2564,7 +2436,7 @@ function mountJournalCountdown(signal) {
|
|
|
2564
2436
|
const header = document.createElement('div');
|
|
2565
2437
|
header.className = 'assistant-history-header';
|
|
2566
2438
|
const title = document.createElement('strong');
|
|
2567
|
-
title.textContent = 'Recent scans
|
|
2439
|
+
title.textContent = 'Recent scans';
|
|
2568
2440
|
const actions = document.createElement('div');
|
|
2569
2441
|
const back = document.createElement('button');
|
|
2570
2442
|
back.className = 'assistant-history-action';
|
|
@@ -2575,11 +2447,8 @@ function mountJournalCountdown(signal) {
|
|
|
2575
2447
|
const clear = document.createElement('button');
|
|
2576
2448
|
clear.className = 'assistant-history-action danger';
|
|
2577
2449
|
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
|
-
};
|
|
2450
|
+
clear.textContent = 'Clear';
|
|
2451
|
+
clear.onclick = clearHistory;
|
|
2583
2452
|
actions.appendChild(clear);
|
|
2584
2453
|
}
|
|
2585
2454
|
header.append(title, actions);
|
|
@@ -2587,7 +2456,7 @@ function mountJournalCountdown(signal) {
|
|
|
2587
2456
|
if (!historyItems.length) {
|
|
2588
2457
|
const empty = document.createElement('div');
|
|
2589
2458
|
empty.className = 'assistant-placeholder';
|
|
2590
|
-
empty.textContent = 'No saved scans
|
|
2459
|
+
empty.textContent = 'No saved scans yet. Run Text Scan or Vision Scan to build your history.';
|
|
2591
2460
|
container.appendChild(empty);
|
|
2592
2461
|
return;
|
|
2593
2462
|
}
|
|
@@ -2822,19 +2691,10 @@ function mountJournalCountdown(signal) {
|
|
|
2822
2691
|
document.getElementById('mode-code').onclick = () => selectTab('code');
|
|
2823
2692
|
document.getElementById('mode-qa').onclick = () => selectTab('qa');
|
|
2824
2693
|
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
|
-
});
|
|
2694
|
+
document.getElementById('assistant-history-btn').onclick = openHistory;
|
|
2695
|
+
document.getElementById('assistant-scan-btn')?.addEventListener('click', scanPage);
|
|
2696
|
+
document.getElementById('assistant-vision-btn')?.addEventListener('click', visionScan);
|
|
2697
|
+
document.getElementById('assistant-auto-start-btn')?.addEventListener('click', startPracticeAutomation);
|
|
2838
2698
|
document.getElementById('assistant-export-question-btn')?.addEventListener('click', exportQuestionDiagnostic);
|
|
2839
2699
|
document.getElementById('assistant-auto-pause-btn')?.addEventListener('click', pauseOrResumeAutomation);
|
|
2840
2700
|
document.getElementById('assistant-auto-stop-btn')?.addEventListener('click', () => stopAutomation());
|
|
@@ -2897,12 +2757,14 @@ function mountJournalCountdown(signal) {
|
|
|
2897
2757
|
}
|
|
2898
2758
|
}
|
|
2899
2759
|
function renderFullResults(container, results, provider) {
|
|
2760
|
+
// Show provider with verified badge if applicable
|
|
2900
2761
|
provider = provider || "unknown";
|
|
2901
|
-
const
|
|
2902
|
-
|
|
2903
|
-
|
|
2904
|
-
|
|
2905
|
-
|
|
2762
|
+
const isVerified = provider.includes('[verified]');
|
|
2763
|
+
const safeProvider = escapeHtml(provider.toUpperCase());
|
|
2764
|
+
const providerBadge = isVerified
|
|
2765
|
+
? `<div class="assistant-provider-badge verified">✅ via ${safeProvider}</div>`
|
|
2766
|
+
: `<div class="assistant-provider-badge">via ${safeProvider}</div>`;
|
|
2767
|
+
container.innerHTML = providerBadge;
|
|
2906
2768
|
results.forEach((res, index) => {
|
|
2907
2769
|
if (res.type === 'code') {
|
|
2908
2770
|
const codeContent = res.code || res.answer || "";
|
|
@@ -2994,12 +2856,17 @@ function mountJournalCountdown(signal) {
|
|
|
2994
2856
|
}
|
|
2995
2857
|
}
|
|
2996
2858
|
async function resumeAuthorizedQaAfterNavigation() {
|
|
2997
|
-
|
|
2998
|
-
|
|
2999
|
-
|
|
2859
|
+
let resume;
|
|
2860
|
+
try {
|
|
2861
|
+
resume = JSON.parse(sessionStorage.getItem(AUTO_RESUME_KEY) || 'null');
|
|
2862
|
+
sessionStorage.removeItem(AUTO_RESUME_KEY);
|
|
2863
|
+
}
|
|
2864
|
+
catch {
|
|
2865
|
+
return;
|
|
2866
|
+
}
|
|
3000
2867
|
const context = getAutomationContext();
|
|
3001
|
-
|
|
3002
|
-
|
|
2868
|
+
const isFresh = Number.isFinite(resume?.createdAt) && Date.now() - resume.createdAt < 120000;
|
|
2869
|
+
if (!isFresh || resume.targetId !== context.target?.id || context.mode !== 'FULL')
|
|
3003
2870
|
return;
|
|
3004
2871
|
isCollapsed = false;
|
|
3005
2872
|
render();
|
|
@@ -3016,11 +2883,9 @@ function mountJournalCountdown(signal) {
|
|
|
3016
2883
|
}
|
|
3017
2884
|
automation.state = 'OPENING_NEXT_PRACTICE';
|
|
3018
2885
|
updateAutomationUI();
|
|
3019
|
-
|
|
3020
|
-
|
|
3021
|
-
|
|
3022
|
-
nextPractice.scrollIntoView({ block: 'center' });
|
|
3023
|
-
nextPractice.click();
|
|
2886
|
+
saveCourseResume('start', context);
|
|
2887
|
+
nextPractice.scrollIntoView({ block: 'center', behavior: 'smooth' });
|
|
2888
|
+
setTimeout(() => nextPractice.click(), 250);
|
|
3024
2889
|
setTimeout(() => { void resumeAuthorizedQaAfterNavigation(); }, 900);
|
|
3025
2890
|
return;
|
|
3026
2891
|
}
|
|
@@ -3034,9 +2899,7 @@ function mountJournalCountdown(signal) {
|
|
|
3034
2899
|
}
|
|
3035
2900
|
automation.state = 'STARTING_PRACTICE';
|
|
3036
2901
|
updateAutomationUI();
|
|
3037
|
-
|
|
3038
|
-
if (generation !== automation.runId || !startPractice.isConnected)
|
|
3039
|
-
return;
|
|
2902
|
+
saveCourseResume('solve', context);
|
|
3040
2903
|
startPractice.click();
|
|
3041
2904
|
setTimeout(() => { void resumeAuthorizedQaAfterNavigation(); }, 900);
|
|
3042
2905
|
return;
|
|
@@ -3050,8 +2913,7 @@ function mountJournalCountdown(signal) {
|
|
|
3050
2913
|
return;
|
|
3051
2914
|
}
|
|
3052
2915
|
}
|
|
3053
|
-
|
|
3054
|
-
void startPracticeAutomation();
|
|
2916
|
+
void startPracticeAutomation();
|
|
3055
2917
|
}
|
|
3056
2918
|
let reopenedAfterUpdate = false;
|
|
3057
2919
|
try {
|