browser-assistant 2.9.5 → 2.9.6
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/extension/automation-policy.js +83 -1
- package/extension/content.js +122 -96
- package/extension/manifest.json +1 -1
- package/package.json +1 -1
- package/server/main.py +10 -4
- package/server/vision_images.py +5 -3
|
@@ -153,6 +153,82 @@
|
|
|
153
153
|
};
|
|
154
154
|
const labelledText = (element) => (element?.getAttribute('aria-labelledby') || '')
|
|
155
155
|
.split(/\s+/).filter(Boolean).map((id) => doc.getElementById(id)).filter(Boolean).map(textOf).join(' ');
|
|
156
|
+
const radioSelector = 'input[type="radio"],[role="radio"]';
|
|
157
|
+
const blankPrompt = /^which word best fits (?:the )?blank\s*\(\s*(\d+)\s*\)\s*\?$/i;
|
|
158
|
+
const blankNumbers = (text) => [...text.matchAll(/\(\s*(\d+)\s*\)\s*(?:_{2,}|\.{3,}|…)/g)]
|
|
159
|
+
.map(match => Number(match[1]));
|
|
160
|
+
const pageText = doc.body.textContent || '';
|
|
161
|
+
if (blankNumbers(pageText).length >= 2 && /which word best fits/i.test(pageText)) {
|
|
162
|
+
const blocks = [...doc.querySelectorAll('div,p,h1,h2,h3,h4,span,legend,[role="heading"]')]
|
|
163
|
+
.filter(node => visible(node) && !node.closest('#assistant-root,nav,aside'));
|
|
164
|
+
const headings = blocks.filter(node => blankPrompt.test((node.textContent || '').trim())
|
|
165
|
+
&& ![...node.children].some(child => blankPrompt.test((child.textContent || '').trim())));
|
|
166
|
+
const passage = blocks.find(node => {
|
|
167
|
+
const text = node.textContent || '';
|
|
168
|
+
return text.length <= 12000 && blankNumbers(text).length >= 2
|
|
169
|
+
&& !/which word best fits/i.test(text) && !node.querySelector(radioSelector)
|
|
170
|
+
&& ![...node.children].some(child => blankNumbers(child.textContent || '').length >= 2);
|
|
171
|
+
});
|
|
172
|
+
if (passage && headings.length) {
|
|
173
|
+
const context = textOf(passage);
|
|
174
|
+
const numbers = blankNumbers(context).sort((a, b) => a - b);
|
|
175
|
+
const headingNumbers = headings.map(node => Number(textOf(node).match(blankPrompt)?.[1]));
|
|
176
|
+
// A partially rendered or unrecognized reading set must
|
|
177
|
+
// never fall through to the ordinary single-answer solver.
|
|
178
|
+
if (new Set(numbers).size !== numbers.length
|
|
179
|
+
|| [...headingNumbers].sort((a, b) => a - b).join() !== numbers.join())
|
|
180
|
+
return null;
|
|
181
|
+
const submitSelector = 'button,input[type="submit"],[role="button"]';
|
|
182
|
+
let scope = headings[0].parentElement;
|
|
183
|
+
let submit;
|
|
184
|
+
for (; scope && scope !== doc.body; scope = scope.parentElement) {
|
|
185
|
+
if (!headings.every(node => scope.contains(node)))
|
|
186
|
+
continue;
|
|
187
|
+
const submits = [...scope.querySelectorAll(submitSelector)].filter(node => visible(node)
|
|
188
|
+
&& !node.closest('#assistant-root')
|
|
189
|
+
&& /^submit(?: answer)?$/i.test(textOf(node) || node.getAttribute('value') || node.getAttribute('aria-label') || ''));
|
|
190
|
+
if (submits.length > 1)
|
|
191
|
+
return null;
|
|
192
|
+
if (submits.length === 1) {
|
|
193
|
+
[submit] = submits;
|
|
194
|
+
break;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
if (!submit)
|
|
198
|
+
return null;
|
|
199
|
+
const controls = [...scope.querySelectorAll(radioSelector)].filter(node => !node.parentElement?.closest('[role="radio"]') && (visible(node)
|
|
200
|
+
|| (node.matches('input') && ([...(node.labels || [])].some(visible)
|
|
201
|
+
|| (node.parentElement !== scope && visible(node.parentElement))))));
|
|
202
|
+
const positions = new Map([...scope.querySelectorAll('*')].map((node, index) => [node, index]));
|
|
203
|
+
const follows = (before, after) => positions.get(before) < positions.get(after);
|
|
204
|
+
const questions = headings.map((heading, position) => {
|
|
205
|
+
const next = headings[position + 1] || submit;
|
|
206
|
+
const group = controls.filter(node => follows(heading, node) && follows(node, next));
|
|
207
|
+
const options = group.map((control, index) => {
|
|
208
|
+
const input = control.matches('input') ? control : control.querySelector('input[type="radio"]');
|
|
209
|
+
let label = input?.labels?.[0] || control.closest('label') || control;
|
|
210
|
+
// Some reading options have an unlabelled radio
|
|
211
|
+
// alongside a text span in the clickable row.
|
|
212
|
+
while (!textOf(label) && label.parentElement && label.parentElement !== scope
|
|
213
|
+
&& !label.parentElement.contains(heading)
|
|
214
|
+
&& label.parentElement.querySelectorAll(radioSelector).length === 1) {
|
|
215
|
+
label = label.parentElement;
|
|
216
|
+
}
|
|
217
|
+
const text = textOf(label) || control.getAttribute('aria-label') || labelledText(control);
|
|
218
|
+
return { index, text, input, control, node: label,
|
|
219
|
+
isSelected: () => Boolean(input?.checked || control.getAttribute('aria-checked') === 'true'),
|
|
220
|
+
disabled: control.matches(':disabled,[aria-disabled="true"]') || Boolean(input?.disabled) };
|
|
221
|
+
});
|
|
222
|
+
return { text: textOf(heading), options, selectionType: 'single', container: scope };
|
|
223
|
+
});
|
|
224
|
+
if (questions.some(question => question.options.length < 2
|
|
225
|
+
|| question.options.some(option => !option.text)
|
|
226
|
+
|| new Set(question.options.map(option => option.text)).size !== question.options.length))
|
|
227
|
+
return null;
|
|
228
|
+
return { ...questions[0], type: 'compound-mcq', compoundQuestions: questions,
|
|
229
|
+
compoundContext: context, compoundSubmit: submit };
|
|
230
|
+
}
|
|
231
|
+
}
|
|
156
232
|
const nativeRegion = doc.querySelector('#generic-question-container');
|
|
157
233
|
const nativeLabels = [...(nativeRegion?.querySelectorAll('.drag-and-drop-option-label') || [])].filter(visible);
|
|
158
234
|
const nativePrompt = nativeRegion?.querySelector('#generic-question-wrapper-id');
|
|
@@ -194,7 +270,7 @@
|
|
|
194
270
|
? `checkbox:${control.form?.id || '__page__'}`
|
|
195
271
|
: control.matches('input[type="radio"]')
|
|
196
272
|
? `native:${control.form?.id || ''}:${control.name || control.closest('form')?.id || ''}`
|
|
197
|
-
:
|
|
273
|
+
: control.closest('[role="radiogroup"]') || control.parentElement;
|
|
198
274
|
if (!groups.has(key))
|
|
199
275
|
groups.set(key, []);
|
|
200
276
|
groups.get(key).push(control);
|
|
@@ -408,6 +484,12 @@
|
|
|
408
484
|
const scope = question.form || question.container?.closest('fieldset,[role="group"],article,section,main') || question.container?.parentElement;
|
|
409
485
|
const enabled = button => button.isConnected && button.getClientRects().length > 0
|
|
410
486
|
&& !button.disabled && button.getAttribute('aria-disabled') !== 'true' && !button.closest('#assistant-root');
|
|
487
|
+
if (question.type === 'compound-mcq') {
|
|
488
|
+
if (question.compoundSubmit)
|
|
489
|
+
return enabled(question.compoundSubmit) ? question.compoundSubmit : null;
|
|
490
|
+
const buttons = question.compoundQuestions.map(group => this.getSubmit(_doc, group));
|
|
491
|
+
return buttons[0] && buttons.every(button => button === buttons[0]) ? buttons[0] : null;
|
|
492
|
+
}
|
|
411
493
|
const explicitSubmits = [...(scope?.querySelectorAll('button[type="submit"],input[type="submit"],[role="button"][type="submit"]') || [])].filter(enabled);
|
|
412
494
|
if (explicitSubmits.length)
|
|
413
495
|
return explicitSubmits.length === 1 ? explicitSubmits[0] : null;
|
package/extension/content.js
CHANGED
|
@@ -434,6 +434,12 @@ function mountJournalCountdown(signal) {
|
|
|
434
434
|
const question = adapter.getQuestion(document);
|
|
435
435
|
if (!question || !normalizeAutomationText(question.text) || (question.type !== 'short-answer' && question.options.length < 2))
|
|
436
436
|
return null;
|
|
437
|
+
if (question.type === 'compound-mcq') {
|
|
438
|
+
return { ...question, signature: JSON.stringify(['compound-mcq',
|
|
439
|
+
question.compoundSubmit ? question.compoundContext : '',
|
|
440
|
+
question.compoundQuestions.map(group => [group.identityText || group.text, group.options.map(option => option.identityText || option.text)]),
|
|
441
|
+
]) };
|
|
442
|
+
}
|
|
437
443
|
return { ...question, text: normalizeAutomationText(question.text), options: question.options.map((option, index) => ({
|
|
438
444
|
...option, index, text: normalizeAutomationText(option.text),
|
|
439
445
|
})), signature: questionSignature(question.identityText || question.text, question.options)
|
|
@@ -751,13 +757,15 @@ function mountJournalCountdown(signal) {
|
|
|
751
757
|
automation.state = 'WAITING_FOR_SAVE';
|
|
752
758
|
updateAutomationUI();
|
|
753
759
|
}
|
|
754
|
-
else if (adapter.getSubmittedAdvance?.(document)) {
|
|
760
|
+
else if (question.type !== 'compound-mcq' && adapter.getSubmittedAdvance?.(document)) {
|
|
755
761
|
return { submitted: true };
|
|
756
762
|
}
|
|
757
763
|
else if (fresh) {
|
|
758
764
|
if ((question.type === 'short-answer' && fresh.input?.value !== answerText)
|
|
759
|
-
|| (
|
|
760
|
-
&& fresh.options.some(option =>
|
|
765
|
+
|| (question.type === 'compound-mcq'
|
|
766
|
+
&& !fresh.compoundQuestions.every((group, index) => !group.options.some(option => option.disabled) && selectionMatches(group, [answerIndexes[index]])))
|
|
767
|
+
|| (answerIndexes && !['short-answer', 'ordering', 'compound-mcq'].includes(question.type)
|
|
768
|
+
&& !selectionMatches(fresh, answerIndexes))) {
|
|
761
769
|
throw new Error('The selected answer changed while waiting. No Submit was clicked.');
|
|
762
770
|
}
|
|
763
771
|
const button = adapter.getSubmit(document, fresh);
|
|
@@ -774,6 +782,9 @@ function mountJournalCountdown(signal) {
|
|
|
774
782
|
}
|
|
775
783
|
return null;
|
|
776
784
|
}
|
|
785
|
+
function selectionMatches(question, answerIndexes) {
|
|
786
|
+
return question.options.every((option, index) => Boolean(option.isSelected?.() || option.input?.checked) === answerIndexes.includes(index));
|
|
787
|
+
}
|
|
777
788
|
async function waitForPracticeTransition(previousSignature, runId) {
|
|
778
789
|
let deadline = Date.now() + 15000;
|
|
779
790
|
while (Date.now() < deadline && automation.running && automation.runId === runId) {
|
|
@@ -1459,26 +1470,35 @@ function mountJournalCountdown(signal) {
|
|
|
1459
1470
|
return false;
|
|
1460
1471
|
}
|
|
1461
1472
|
async function solveCompoundMcq(compound, runId, adapter) {
|
|
1462
|
-
const
|
|
1463
|
-
|
|
1464
|
-
|
|
1473
|
+
const url = location.href;
|
|
1474
|
+
const findCurrent = (position) => {
|
|
1475
|
+
const context = getAutomationContext();
|
|
1476
|
+
if (location.href !== url || context.target.id !== automation.targetId
|
|
1477
|
+
|| !automationPolicy.canExecute('select', context) || !automationPolicy.canExecute('validate', context))
|
|
1478
|
+
return null;
|
|
1479
|
+
const fresh = getAuthorizedQuestion(context);
|
|
1480
|
+
if (fresh?.signature !== compound.signature)
|
|
1481
|
+
return null;
|
|
1482
|
+
const group = fresh.compoundQuestions[position];
|
|
1483
|
+
return group?.options.some(option => option.disabled) ? null : group;
|
|
1465
1484
|
};
|
|
1466
|
-
|
|
1485
|
+
const answerIndexes = [];
|
|
1486
|
+
for (let position = 0; position < compound.compoundQuestions.length; position++) {
|
|
1467
1487
|
if (!(await waitWhilePaused(runId)))
|
|
1468
|
-
return
|
|
1469
|
-
|
|
1488
|
+
return null;
|
|
1489
|
+
const question = findCurrent(position);
|
|
1470
1490
|
if (!question)
|
|
1471
|
-
throw new Error('A linked question changed
|
|
1472
|
-
if (question.options.some(option => option.isSelected?.() || option.input?.checked))
|
|
1473
|
-
continue;
|
|
1491
|
+
throw new Error('A linked question changed or is already locked. Review it on the page.');
|
|
1474
1492
|
automation.state = 'SOLVING';
|
|
1475
1493
|
updateAutomationUI();
|
|
1476
|
-
const prompt =
|
|
1494
|
+
const prompt = `Reading context:\n${compound.compoundContext || ''}\n\nAnswer only this question: ${question.text}\nQuestion format: select one answer.\n${question.options.map((option, index) => `${String.fromCharCode(65 + index)}. ${option.text}`).join('\n')}`;
|
|
1477
1495
|
const response = await window.BrowserAssistantAnswerRequests.run({
|
|
1478
|
-
request: () => apiRequest('/solve', 'POST', {
|
|
1496
|
+
request: () => apiRequest('/solve', 'POST', {
|
|
1497
|
+
text: prompt, url, practice_type: 'mcq', verify_answer: true, require_answer_agreement: true,
|
|
1498
|
+
}),
|
|
1479
1499
|
active: () => automation.running && automation.runId === runId,
|
|
1480
1500
|
ready: () => waitWhilePaused(runId),
|
|
1481
|
-
current: () => Boolean(findCurrent(
|
|
1501
|
+
current: () => Boolean(findCurrent(position)),
|
|
1482
1502
|
onRetry: ({ attempt, attempts, message }) => {
|
|
1483
1503
|
automation.state = 'RETRYING_REQUEST';
|
|
1484
1504
|
automation.error = `Temporary answer service issue. Retrying ${attempt}/${attempts}: ${message}`;
|
|
@@ -1486,8 +1506,10 @@ function mountJournalCountdown(signal) {
|
|
|
1486
1506
|
},
|
|
1487
1507
|
sleep: ms => new Promise(resolve => setTimeout(resolve, ms)),
|
|
1488
1508
|
});
|
|
1489
|
-
if (!response
|
|
1490
|
-
|
|
1509
|
+
if (!response)
|
|
1510
|
+
return null;
|
|
1511
|
+
if (response.data?.answer_agreement !== true)
|
|
1512
|
+
throw new Error('Update and restart the Browser Assistant backend to verify linked answers.');
|
|
1491
1513
|
let results;
|
|
1492
1514
|
try {
|
|
1493
1515
|
results = JSON.parse(response.data.results);
|
|
@@ -1495,45 +1517,80 @@ function mountJournalCountdown(signal) {
|
|
|
1495
1517
|
catch {
|
|
1496
1518
|
throw new Error('The answer service returned invalid linked-question data.');
|
|
1497
1519
|
}
|
|
1498
|
-
const
|
|
1499
|
-
if (
|
|
1520
|
+
const indexes = answerIndexesFromResult(results, question);
|
|
1521
|
+
if (results[0]?.type !== 'mcq' || indexes.length !== 1)
|
|
1500
1522
|
throw new Error('The verified answer did not match this linked question’s displayed options.');
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1523
|
+
answerIndexes.push(indexes[0]);
|
|
1524
|
+
}
|
|
1525
|
+
automation.error = '';
|
|
1526
|
+
automation.state = 'SELECTING';
|
|
1527
|
+
updateAutomationUI();
|
|
1528
|
+
for (const [position, index] of answerIndexes.entries()) {
|
|
1529
|
+
if (!(await waitWhilePaused(runId)))
|
|
1530
|
+
return null;
|
|
1531
|
+
const question = findCurrent(position);
|
|
1532
|
+
const option = question?.options[index];
|
|
1533
|
+
if (!option)
|
|
1534
|
+
throw new Error('A linked question option disappeared before selection.');
|
|
1535
|
+
if (!(option.isSelected?.() || option.input?.checked))
|
|
1536
|
+
(option.input || option.control)?.click();
|
|
1537
|
+
let selected = false;
|
|
1538
|
+
for (let attempt = 0; attempt < 50; attempt++) {
|
|
1539
|
+
if (!(await waitWhilePaused(runId)))
|
|
1540
|
+
return null;
|
|
1541
|
+
const current = findCurrent(position);
|
|
1542
|
+
if (current && selectionMatches(current, [index])) {
|
|
1543
|
+
selected = true;
|
|
1544
|
+
break;
|
|
1519
1545
|
}
|
|
1520
|
-
|
|
1521
|
-
throw new Error('A linked answer could not be verified after selection.');
|
|
1546
|
+
await new Promise(resolve => setTimeout(resolve, 50));
|
|
1522
1547
|
}
|
|
1548
|
+
if (!selected)
|
|
1549
|
+
throw new Error(`Selection could not be confirmed for linked question ${position + 1}. Review the group before submitting.`);
|
|
1523
1550
|
}
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
if (!submit?.isConnected || submit.disabled || submit.getAttribute('aria-disabled') === 'true') {
|
|
1528
|
-
throw new Error('All linked answers were selected, but the portal did not enable a unique Submit button.');
|
|
1529
|
-
}
|
|
1551
|
+
return waitForQuestionSubmit(compound, runId, adapter, answerIndexes, '');
|
|
1552
|
+
}
|
|
1553
|
+
async function submitPracticeAnswer(question, button, runId, adapter) {
|
|
1530
1554
|
automation.state = 'SUBMITTING';
|
|
1531
1555
|
updateAutomationUI();
|
|
1532
|
-
automation.processed.add(
|
|
1533
|
-
|
|
1556
|
+
automation.processed.add(question.signature);
|
|
1557
|
+
button.click();
|
|
1534
1558
|
automation.state = 'WAITING_FOR_NEXT';
|
|
1535
1559
|
updateAutomationUI();
|
|
1536
|
-
|
|
1560
|
+
let transition = await waitForAdvanceOrTransition(question.signature, runId, adapter);
|
|
1561
|
+
if (!automation.running || automation.runId !== runId)
|
|
1562
|
+
return false;
|
|
1563
|
+
if (transition?.proceed) {
|
|
1564
|
+
automation.state = 'OPENING_COURSE';
|
|
1565
|
+
automation.pendingNavigation = true;
|
|
1566
|
+
updateAutomationUI();
|
|
1567
|
+
saveCourseResume('course', transition.context, {
|
|
1568
|
+
currentTitle: adapter.getCurrentPracticeTitle?.(document) || '',
|
|
1569
|
+
});
|
|
1570
|
+
transition.proceed.click();
|
|
1571
|
+
return false;
|
|
1572
|
+
}
|
|
1573
|
+
if (transition?.advance) {
|
|
1574
|
+
if (!automationPolicy.canExecute('click', transition.context)) {
|
|
1575
|
+
automation.error = 'Target policy does not permit Next.';
|
|
1576
|
+
stopAutomation('UNAUTHORIZED');
|
|
1577
|
+
return false;
|
|
1578
|
+
}
|
|
1579
|
+
transition.advance.click();
|
|
1580
|
+
transition = await waitForPracticeTransition(question.signature, runId);
|
|
1581
|
+
if (!automation.running || automation.runId !== runId)
|
|
1582
|
+
return false;
|
|
1583
|
+
}
|
|
1584
|
+
if (transition === 'next' || transition === 'complete')
|
|
1585
|
+
automation.completed += 1;
|
|
1586
|
+
if (transition === 'complete') {
|
|
1587
|
+
stopAutomation(automation.deferredQuestions.size ? 'REVIEW_NEEDED' : 'COMPLETED');
|
|
1588
|
+
}
|
|
1589
|
+
else if (transition !== 'next') {
|
|
1590
|
+
automation.error = transition?.blocked || 'Next question did not appear in time.';
|
|
1591
|
+
stopAutomation('PAUSED');
|
|
1592
|
+
}
|
|
1593
|
+
return transition === 'next';
|
|
1537
1594
|
}
|
|
1538
1595
|
async function startPracticeAutomation() {
|
|
1539
1596
|
if (window.BrowserAssistantJournal?.matches()) {
|
|
@@ -1615,7 +1672,7 @@ function mountJournalCountdown(signal) {
|
|
|
1615
1672
|
continue;
|
|
1616
1673
|
}
|
|
1617
1674
|
const finalSubmit = currentAdapter.getFinalQuizSubmit?.(document);
|
|
1618
|
-
if (finalSubmit) {
|
|
1675
|
+
if (finalSubmit && getAuthorizedQuestion(context)?.compoundSubmit !== finalSubmit) {
|
|
1619
1676
|
const submitted = await submitCompletedQuiz(finalSubmit, currentAdapter, runId);
|
|
1620
1677
|
if (!automation.running || automation.runId !== runId)
|
|
1621
1678
|
break;
|
|
@@ -1705,16 +1762,6 @@ function mountJournalCountdown(signal) {
|
|
|
1705
1762
|
await runCodingAutomation(question, runId);
|
|
1706
1763
|
break;
|
|
1707
1764
|
}
|
|
1708
|
-
if (question.type === 'compound-mcq') {
|
|
1709
|
-
try {
|
|
1710
|
-
await solveCompoundMcq(question, runId, adapter);
|
|
1711
|
-
}
|
|
1712
|
-
catch (error) {
|
|
1713
|
-
automation.error = error.message || 'Linked questions could not be completed.';
|
|
1714
|
-
stopAutomation('PAUSED');
|
|
1715
|
-
}
|
|
1716
|
-
break;
|
|
1717
|
-
}
|
|
1718
1765
|
if (automation.deferredQuestions.has(question.signature)) {
|
|
1719
1766
|
automation.currentSignature = question.signature;
|
|
1720
1767
|
if (await continueAfterUnverifiedQuestion(question, runId, 'This question was deferred earlier.', false))
|
|
@@ -1727,6 +1774,21 @@ function mountJournalCountdown(signal) {
|
|
|
1727
1774
|
break;
|
|
1728
1775
|
}
|
|
1729
1776
|
automation.currentSignature = question.signature;
|
|
1777
|
+
if (question.type === 'compound-mcq') {
|
|
1778
|
+
try {
|
|
1779
|
+
const ready = await solveCompoundMcq(question, runId, currentAdapter);
|
|
1780
|
+
if (ready?.button && automation.running && automation.runId === runId
|
|
1781
|
+
&& await submitPracticeAnswer(question, ready.button, runId, currentAdapter))
|
|
1782
|
+
continue;
|
|
1783
|
+
}
|
|
1784
|
+
catch (error) {
|
|
1785
|
+
if (automation.running && automation.runId === runId) {
|
|
1786
|
+
automation.error = error.message || 'Linked questions could not be completed.';
|
|
1787
|
+
stopAutomation('PAUSED');
|
|
1788
|
+
}
|
|
1789
|
+
}
|
|
1790
|
+
break;
|
|
1791
|
+
}
|
|
1730
1792
|
automation.state = 'SOLVING';
|
|
1731
1793
|
updateAutomationUI();
|
|
1732
1794
|
let response;
|
|
@@ -1951,44 +2013,8 @@ function mountJournalCountdown(signal) {
|
|
|
1951
2013
|
break;
|
|
1952
2014
|
if (ready.submitted)
|
|
1953
2015
|
continue;
|
|
1954
|
-
|
|
1955
|
-
automation.state = 'SUBMITTING';
|
|
1956
|
-
updateAutomationUI();
|
|
1957
|
-
automation.processed.add(question.signature);
|
|
1958
|
-
submit.click();
|
|
1959
|
-
automation.state = 'WAITING_FOR_NEXT';
|
|
1960
|
-
updateAutomationUI();
|
|
1961
|
-
let transition = await waitForAdvanceOrTransition(question.signature, runId, currentAdapter);
|
|
1962
|
-
if (transition?.proceed) {
|
|
1963
|
-
automation.state = 'OPENING_COURSE';
|
|
1964
|
-
automation.pendingNavigation = true;
|
|
1965
|
-
updateAutomationUI();
|
|
1966
|
-
saveCourseResume('course', transition.context, {
|
|
1967
|
-
currentTitle: currentAdapter.getCurrentPracticeTitle?.(document) || '',
|
|
1968
|
-
});
|
|
1969
|
-
transition.proceed.click();
|
|
1970
|
-
return;
|
|
1971
|
-
}
|
|
1972
|
-
if (transition?.advance) {
|
|
1973
|
-
if (!automationPolicy.canExecute('click', transition.context)) {
|
|
1974
|
-
automation.error = 'Target policy does not permit Next.';
|
|
1975
|
-
stopAutomation('UNAUTHORIZED');
|
|
1976
|
-
break;
|
|
1977
|
-
}
|
|
1978
|
-
transition.advance.click();
|
|
1979
|
-
transition = await waitForPracticeTransition(question.signature, runId);
|
|
1980
|
-
}
|
|
1981
|
-
if (transition === 'complete') {
|
|
1982
|
-
automation.completed += 1;
|
|
1983
|
-
stopAutomation(automation.deferredQuestions.size ? 'REVIEW_NEEDED' : 'COMPLETED');
|
|
2016
|
+
if (!(await submitPracticeAnswer(question, ready.button, runId, currentAdapter)))
|
|
1984
2017
|
break;
|
|
1985
|
-
}
|
|
1986
|
-
if (transition !== 'next') {
|
|
1987
|
-
automation.error = transition?.blocked || 'Next question did not appear in time.';
|
|
1988
|
-
stopAutomation('PAUSED');
|
|
1989
|
-
break;
|
|
1990
|
-
}
|
|
1991
|
-
automation.completed += 1;
|
|
1992
2018
|
}
|
|
1993
2019
|
}
|
|
1994
2020
|
async function readMcqSnippetSnapshot(question, runId) {
|
package/extension/manifest.json
CHANGED
package/package.json
CHANGED
package/server/main.py
CHANGED
|
@@ -191,7 +191,7 @@ async def lifespan(_app: FastAPI):
|
|
|
191
191
|
client.close()
|
|
192
192
|
|
|
193
193
|
|
|
194
|
-
app = FastAPI(title="Browser Assistant API", version="2.9.
|
|
194
|
+
app = FastAPI(title="Browser Assistant API", version="2.9.6", lifespan=lifespan)
|
|
195
195
|
install_local_guards(app)
|
|
196
196
|
|
|
197
197
|
@app.exception_handler(HTTPException)
|
|
@@ -209,6 +209,7 @@ class PageContent(BaseModel):
|
|
|
209
209
|
repair_attempt: int = 0
|
|
210
210
|
review_before_submit: bool = False
|
|
211
211
|
verify_answer: bool = False
|
|
212
|
+
require_answer_agreement: bool = False
|
|
212
213
|
starter_code: str | None = None
|
|
213
214
|
|
|
214
215
|
@field_validator('starter_code')
|
|
@@ -1303,8 +1304,8 @@ REPAIR MODE:
|
|
|
1303
1304
|
detect_requested_language(content.text) is not None or content.language is not None,
|
|
1304
1305
|
)
|
|
1305
1306
|
strict_code_review = require_code and (content.review_before_submit or not FAST_CODE_MODE or STRICT_REPAIR_REVIEW)
|
|
1306
|
-
verify_answers = not require_code and (content.verify_answer or not FAST_SCAN_MODE)
|
|
1307
|
-
if not require_code and content.practice_type in {'auto', 'mcq', 'math', 'aptitude'}:
|
|
1307
|
+
verify_answers = not require_code and (content.verify_answer or content.require_answer_agreement or not FAST_SCAN_MODE)
|
|
1308
|
+
if not require_code and not content.require_answer_agreement and content.practice_type in {'auto', 'mcq', 'math', 'aptitude'}:
|
|
1308
1309
|
local_result = local_choice_result(trimmed_text, language)
|
|
1309
1310
|
if local_result is not None:
|
|
1310
1311
|
return local_result
|
|
@@ -1325,7 +1326,10 @@ REPAIR MODE:
|
|
|
1325
1326
|
return await try_groq(prompt_messages, model=source_model, temperature=0.0)
|
|
1326
1327
|
|
|
1327
1328
|
try:
|
|
1328
|
-
checked = await cross_check_text_answers(
|
|
1329
|
+
checked = await cross_check_text_answers(
|
|
1330
|
+
messages, cleaned, independent_solve, question_text=trimmed_text,
|
|
1331
|
+
require_agreement=content.require_answer_agreement,
|
|
1332
|
+
)
|
|
1329
1333
|
except Exception as exc:
|
|
1330
1334
|
if isinstance(exc, VisionUnconfirmedError):
|
|
1331
1335
|
message = str(exc)
|
|
@@ -1361,6 +1365,7 @@ REPAIR MODE:
|
|
|
1361
1365
|
cleaned, verified = await confirm_answers(cleaned, model_id)
|
|
1362
1366
|
return {"results": cleaned, "provider": f"groq ({model_id})" + (' [cross-checked]' if verified else ''),
|
|
1363
1367
|
"language": language, "answer_verified": verified,
|
|
1368
|
+
"answer_agreement": verified and content.require_answer_agreement,
|
|
1364
1369
|
"code_reviewed": strict_code_review and language != 'web'}
|
|
1365
1370
|
else:
|
|
1366
1371
|
errors.append(f"{model_id}: returned empty/unparseable results")
|
|
@@ -1399,6 +1404,7 @@ REPAIR MODE:
|
|
|
1399
1404
|
"results": cleaned,
|
|
1400
1405
|
"provider": f"ollama ({OLLAMA_MODEL})" + (' [cross-checked]' if verified else ''),
|
|
1401
1406
|
"answer_verified": verified,
|
|
1407
|
+
"answer_agreement": verified and content.require_answer_agreement,
|
|
1402
1408
|
"language": language,
|
|
1403
1409
|
"code_reviewed": strict_code_review and language != 'web',
|
|
1404
1410
|
}
|
package/server/vision_images.py
CHANGED
|
@@ -422,7 +422,7 @@ def bind_displayed_choice(value, choices, *, matrix_math):
|
|
|
422
422
|
return unique.pop() if len(unique) == 1 else None
|
|
423
423
|
|
|
424
424
|
|
|
425
|
-
async def cross_check_text_answers(messages, results, complete, *, question_text=''):
|
|
425
|
+
async def cross_check_text_answers(messages, results, complete, *, question_text='', require_agreement=False):
|
|
426
426
|
items = json.loads(results)
|
|
427
427
|
if not items or any(item.get('type') != 'mcq' for item in items):
|
|
428
428
|
raise VisionUnconfirmedError('Verification requires a complete set of question answers.')
|
|
@@ -438,6 +438,8 @@ async def cross_check_text_answers(messages, results, complete, *, question_text
|
|
|
438
438
|
check_messages = [{'role': 'system', 'content': instruction}, *messages[1:]]
|
|
439
439
|
matrix_math = matrix_question(messages)
|
|
440
440
|
choices = displayed_single_choices(question_text) if len(items) == 1 else {}
|
|
441
|
+
if require_agreement and not choices:
|
|
442
|
+
raise VisionUnconfirmedError('Expected one linked answer with its displayed options.')
|
|
441
443
|
|
|
442
444
|
def answer_key(entries):
|
|
443
445
|
if choices:
|
|
@@ -473,11 +475,11 @@ async def cross_check_text_answers(messages, results, complete, *, question_text
|
|
|
473
475
|
# primary answer over blocking the automation entirely. The primary solve was
|
|
474
476
|
# validated and the verification provider returned unusable JSON — a parsing
|
|
475
477
|
# failure, not a disagreement — so a hard 422 is disproportionate.
|
|
476
|
-
if current is None and previous is None:
|
|
478
|
+
if not require_agreement and current is None and previous is None:
|
|
477
479
|
return results
|
|
478
480
|
# For multi-answer questions (fill-in-the-blank), accept the primary answers
|
|
479
481
|
# when the majority of individual answers agree with any independent solve.
|
|
480
|
-
if not choices and first is not None and len(first) > 1:
|
|
482
|
+
if not require_agreement and not choices and first is not None and len(first) > 1:
|
|
481
483
|
best = current or previous
|
|
482
484
|
if best is not None:
|
|
483
485
|
agreed = sum(a == b for a, b in zip(first, best))
|