browser-assistant 2.9.33 → 2.9.34
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/content.js +16 -9
- package/extension/manifest.json +1 -1
- package/package.json +1 -1
- package/server/main.py +12 -3
- package/server/vision_images.py +45 -5
package/extension/content.js
CHANGED
|
@@ -1541,7 +1541,8 @@ function mountJournalCountdown(signal) {
|
|
|
1541
1541
|
const practice = initial.target.id === 'ccbp-learning-practice'
|
|
1542
1542
|
&& /^\/(?:default-question|primitive-coding(?:-review)?)\/practice\//.test(location.pathname);
|
|
1543
1543
|
const hasDraft = fresh?.input?.value?.trim() || fresh?.options.some(option => option.isSelected?.() || option.input?.checked);
|
|
1544
|
-
if (allowSkip &&
|
|
1544
|
+
if (allowSkip && !automation.retriedDeferredQuestions?.has(question.signature)
|
|
1545
|
+
&& practice && sameQuestion && !hasDraft && question.type !== 'ordering'
|
|
1545
1546
|
&& !adapter.isSaving?.(document) && !adapter.getSubmittedAdvance?.(document)
|
|
1546
1547
|
&& automationPolicy.canExecute('click', initial) && automationPolicy.canExecute('validate', initial)) {
|
|
1547
1548
|
const skip = adapter.getPracticeSkip?.(document, fresh);
|
|
@@ -1747,8 +1748,10 @@ function mountJournalCountdown(signal) {
|
|
|
1747
1748
|
if (!automation.running || automation.runId !== runId)
|
|
1748
1749
|
return false;
|
|
1749
1750
|
}
|
|
1750
|
-
if (transition === 'next' || transition === 'complete')
|
|
1751
|
+
if (transition === 'next' || transition === 'complete') {
|
|
1751
1752
|
automation.completed += 1;
|
|
1753
|
+
automation.deferredQuestions.delete(question.signature);
|
|
1754
|
+
}
|
|
1752
1755
|
if (transition === 'complete') {
|
|
1753
1756
|
stopAutomation(automation.deferredQuestions.size ? 'REVIEW_NEEDED' : 'COMPLETED');
|
|
1754
1757
|
}
|
|
@@ -1813,6 +1816,7 @@ function mountJournalCountdown(signal) {
|
|
|
1813
1816
|
automation.error = '';
|
|
1814
1817
|
automation.completed = 0;
|
|
1815
1818
|
automation.deferredQuestions = new Set();
|
|
1819
|
+
automation.retriedDeferredQuestions = new Set();
|
|
1816
1820
|
automation.targetId = initialContext.target.id;
|
|
1817
1821
|
automation.pendingNavigation = false;
|
|
1818
1822
|
automation.currentSignature = null;
|
|
@@ -1941,9 +1945,12 @@ function mountJournalCountdown(signal) {
|
|
|
1941
1945
|
}
|
|
1942
1946
|
if (automation.deferredQuestions.has(question.signature)) {
|
|
1943
1947
|
automation.currentSignature = question.signature;
|
|
1944
|
-
if (
|
|
1945
|
-
|
|
1946
|
-
|
|
1948
|
+
if (automation.retriedDeferredQuestions.has(question.signature)) {
|
|
1949
|
+
if (await continueAfterUnverifiedQuestion(question, runId, 'The answer could not be verified after retrying.', false))
|
|
1950
|
+
continue;
|
|
1951
|
+
break;
|
|
1952
|
+
}
|
|
1953
|
+
automation.retriedDeferredQuestions.add(question.signature);
|
|
1947
1954
|
}
|
|
1948
1955
|
if (automation.processed.has(question.signature)) {
|
|
1949
1956
|
automation.error = 'Repeated question detected.';
|
|
@@ -2002,7 +2009,7 @@ function mountJournalCountdown(signal) {
|
|
|
2002
2009
|
text: `${requestText}\nQuestion format: ${question.type === 'short-answer' ? 'Free response. Return only the exact value to enter in the JSON answer field, without an option label, explanation, or Markdown.' : question.selectionType === 'multiple' ? 'select all that apply; return every correct option as "Option A: ...; Option B: ...".' : 'select one answer.'}\n${question.options.map((option, index) => `${String.fromCharCode(65 + index)}. ${option.text}`).join('\n')}`,
|
|
2003
2010
|
...(question.type === 'ordering' ? { text: `${requestText}\nReorder ALL items. Return the complete permutation as a JSON array of 1-based item numbers in the answer field (example: [2,1,3]). Check every item appears exactly once.\n${question.options.map((option, index) => `${index + 1}. ${option.text}`).join('\n')}` } : {}),
|
|
2004
2011
|
url: window.location.href, practice_type: 'mcq', verify_answer: true,
|
|
2005
|
-
require_answer_agreement: question.selectionType === 'multiple',
|
|
2012
|
+
require_answer_agreement: question.selectionType === 'multiple' || question.type === 'short-answer',
|
|
2006
2013
|
};
|
|
2007
2014
|
const visuals = window.BrowserAssistantQuestionVisuals;
|
|
2008
2015
|
if (visuals?.nodes(question).length) {
|
|
@@ -2816,7 +2823,7 @@ function mountJournalCountdown(signal) {
|
|
|
2816
2823
|
practice_type: context.question ? 'mcq' : practiceType,
|
|
2817
2824
|
language: context.question ? undefined : requestedLanguage,
|
|
2818
2825
|
verify_answer: true,
|
|
2819
|
-
require_answer_agreement: context.question?.selectionType === 'multiple',
|
|
2826
|
+
require_answer_agreement: context.question?.selectionType === 'multiple' || context.question?.type === 'short-answer',
|
|
2820
2827
|
allow_overview: !context.question && practiceType === 'auto' && !requestedLanguage,
|
|
2821
2828
|
});
|
|
2822
2829
|
if (!res.ok) {
|
|
@@ -2978,14 +2985,14 @@ function mountJournalCountdown(signal) {
|
|
|
2978
2985
|
image: snapshot.images[0], images: snapshot.images.slice(1),
|
|
2979
2986
|
text: context.text,
|
|
2980
2987
|
url: location.href, practice_type: 'mcq', verify_answer: true,
|
|
2981
|
-
require_answer_agreement: question.selectionType === 'multiple',
|
|
2988
|
+
require_answer_agreement: question.selectionType === 'multiple' || question.type === 'short-answer',
|
|
2982
2989
|
});
|
|
2983
2990
|
}
|
|
2984
2991
|
else {
|
|
2985
2992
|
res = await apiRequest('/solve', 'POST', {
|
|
2986
2993
|
text: question ? context.text : extractSmartText(), url: context.url,
|
|
2987
2994
|
practice_type: question ? 'mcq' : practiceType, verify_answer: Boolean(question) || practiceType !== 'code',
|
|
2988
|
-
require_answer_agreement: question?.selectionType === 'multiple',
|
|
2995
|
+
require_answer_agreement: question?.selectionType === 'multiple' || question?.type === 'short-answer',
|
|
2989
2996
|
review_before_submit: !question && practiceType === 'code',
|
|
2990
2997
|
});
|
|
2991
2998
|
}
|
package/extension/manifest.json
CHANGED
package/package.json
CHANGED
package/server/main.py
CHANGED
|
@@ -31,7 +31,7 @@ from vision_images import (compress_image_base64, unique_image_blocks, collect_i
|
|
|
31
31
|
ordering_question, solve_sorted_list_merge_order, solve_stack_empty_order, solve_pseudocode_choice,
|
|
32
32
|
solve_stack_push_order, solve_stack_pop_order, solve_next_greater_element_order,
|
|
33
33
|
multiple_choice_question, solve_linked_stack_choices, cross_check_multiple_choice, stack_reasoning_guidance,
|
|
34
|
-
reading_response_constraints,
|
|
34
|
+
reading_response_constraints, free_response_question,
|
|
35
35
|
VisionRateLimitError, VisionUnconfirmedError)
|
|
36
36
|
|
|
37
37
|
logging.basicConfig(level=logging.INFO, format="%(asctime)s [%(levelname)s] %(message)s")
|
|
@@ -195,7 +195,7 @@ async def lifespan(_app: FastAPI):
|
|
|
195
195
|
client.close()
|
|
196
196
|
|
|
197
197
|
|
|
198
|
-
app = FastAPI(title="Browser Assistant API", version="2.9.
|
|
198
|
+
app = FastAPI(title="Browser Assistant API", version="2.9.34", lifespan=lifespan)
|
|
199
199
|
install_local_guards(app)
|
|
200
200
|
|
|
201
201
|
@app.exception_handler(HTTPException)
|
|
@@ -1360,6 +1360,7 @@ async def solve_questions(content: PageContent):
|
|
|
1360
1360
|
multiple_choice = None if require_code else multiple_choice_question(trimmed_text)
|
|
1361
1361
|
reading_constraints = (reading_response_constraints(trimmed_text)
|
|
1362
1362
|
if content.require_answer_agreement and not require_code else None)
|
|
1363
|
+
free_response = not require_code and free_response_question(trimmed_text)
|
|
1363
1364
|
if ordering:
|
|
1364
1365
|
system_prompt = (
|
|
1365
1366
|
'Arrange all steps in the order required by the problem. Check prerequisites and use each displayed '
|
|
@@ -1385,6 +1386,14 @@ async def solve_questions(content: PageContent):
|
|
|
1385
1386
|
'and an answer string containing only the words that belong in the gap. Use no option label, quotation marks '
|
|
1386
1387
|
'inside the answer value, surrounding punctuation, or Markdown. If the blank is unclear, return [].'
|
|
1387
1388
|
)
|
|
1389
|
+
elif free_response:
|
|
1390
|
+
system_prompt = (
|
|
1391
|
+
'Read the complete question and any supplied code or context. Return exactly one JSON array item '
|
|
1392
|
+
'with type "mcq", the question, a brief reasoning string, and an answer string containing only '
|
|
1393
|
+
'the exact value to enter into the field. Preserve signs, case, and required separators. '
|
|
1394
|
+
'Use no option label, explanation or Markdown in the answer field. '
|
|
1395
|
+
'If a required implementation convention is unspecified and changes the answer, return [].'
|
|
1396
|
+
)
|
|
1388
1397
|
if require_code:
|
|
1389
1398
|
system_prompt += '\n\n' + CODE_DESCRIPTION_PRIORITY
|
|
1390
1399
|
if content.repair_attempt > 0:
|
|
@@ -1616,7 +1625,7 @@ async def _solve_vision(content: VisionContent):
|
|
|
1616
1625
|
allow_overview = content.allow_overview and content.practice_type == 'auto' and not is_code_scan and not content.text.strip()
|
|
1617
1626
|
checkbox_question = None if is_code_scan else multiple_choice_question(content.text)
|
|
1618
1627
|
if ((checkbox_question is not None and not checkbox_question[1])
|
|
1619
|
-
or (content.require_answer_agreement and checkbox_question is None)):
|
|
1628
|
+
or (content.require_answer_agreement and checkbox_question is None and not free_response_question(content.text))):
|
|
1620
1629
|
raise HTTPException(422, detail={'code': 'vision_unconfirmed',
|
|
1621
1630
|
'message': 'Every displayed checkbox option is required for verification.'})
|
|
1622
1631
|
if not is_code_scan and checkbox_question is None and content.practice_type in {'auto', 'mcq', 'math', 'aptitude'}:
|
package/server/vision_images.py
CHANGED
|
@@ -3,6 +3,7 @@ import base64
|
|
|
3
3
|
from fractions import Fraction
|
|
4
4
|
from io import BytesIO
|
|
5
5
|
import json
|
|
6
|
+
import math
|
|
6
7
|
import re
|
|
7
8
|
|
|
8
9
|
from PIL import Image, ImageOps
|
|
@@ -578,6 +579,20 @@ def displayed_single_choices(text):
|
|
|
578
579
|
return parse_labeled_choices(option_text)
|
|
579
580
|
|
|
580
581
|
|
|
582
|
+
def free_response_question(text):
|
|
583
|
+
return bool(re.search(r'\n(?:Question format: Free response\.|Free response: return only the exact value\.)',
|
|
584
|
+
text, re.I))
|
|
585
|
+
|
|
586
|
+
|
|
587
|
+
def free_response_value(value):
|
|
588
|
+
if type(value) not in (str, int, float):
|
|
589
|
+
return None
|
|
590
|
+
if isinstance(value, float) and not math.isfinite(value):
|
|
591
|
+
return None
|
|
592
|
+
answer = str(value).replace('\r\n', '\n').strip()
|
|
593
|
+
return answer if answer and not re.match(r'^(?:option\s+)?[A-Z]\s*[:.)]\s', answer, re.I) else None
|
|
594
|
+
|
|
595
|
+
|
|
581
596
|
MULTIPLE_CHOICE_FORMAT = re.compile(
|
|
582
597
|
r'^(?:Question format: select all that apply(?:[.;][^\r\n]*)?|Select ALL correct options\.)[ \t]*\r?$',
|
|
583
598
|
re.I | re.M,
|
|
@@ -746,7 +761,7 @@ def bind_displayed_choice(value, choices, *, matrix_math):
|
|
|
746
761
|
|
|
747
762
|
|
|
748
763
|
def stack_reasoning_guidance(text):
|
|
749
|
-
if not re.search(r'\
|
|
764
|
+
if not re.search(r'\b(?:stacks?|queues?)\b|\bstk\w*\s*\.|\.(?:push|pop|top|peek|empty)\s*\(', text, re.I):
|
|
750
765
|
return ''
|
|
751
766
|
return (
|
|
752
767
|
'\nSTACK QUESTION CHECKS: Use the complete supplied implementation and the exact question. '
|
|
@@ -755,6 +770,10 @@ def stack_reasoning_guidance(text):
|
|
|
755
770
|
'For an array implementation use its stated capacity and top index; for a linked implementation check '
|
|
756
771
|
'its node and pointer updates and any explicitly stated capacity. Check underflow before reading/removing. '
|
|
757
772
|
'For a queue implemented with stacks, trace transfers and restoration to establish the front element. '
|
|
773
|
+
'For queue initialization, read the actual constructor or initialization code. Array indices may use -1 '
|
|
774
|
+
'or 0 depending on the convention, while linked-node front/back pointers may use NULL, nullptr or None. '
|
|
775
|
+
'Preserve the implementation and requested answer format. Ask for review when that convention cannot '
|
|
776
|
+
'be established from the question and supplied context. '
|
|
758
777
|
'Identify which loop is referenced. Explain its body and net effect separately from its continuation '
|
|
759
778
|
'condition and from statements after the loop. If several loops fit the question, check whether their '
|
|
760
779
|
'effects agree before selecting an option. Trace transfers separately from a later push(x) statement. '
|
|
@@ -836,9 +855,12 @@ async def cross_check_text_answers(messages, results, complete, *, question_text
|
|
|
836
855
|
if ordering and len(items) != 1:
|
|
837
856
|
raise VisionUnconfirmedError('Expected one answer containing all numbered steps.')
|
|
838
857
|
step_count = len(ordering[1]) if ordering else 0
|
|
858
|
+
free_response = free_response_question(question_text)
|
|
859
|
+
if free_response and len(items) != 1:
|
|
860
|
+
raise VisionUnconfirmedError('Expected one exact typed answer for the current question.')
|
|
839
861
|
choices = displayed_single_choices(question_text) if len(items) == 1 else {}
|
|
840
862
|
constraints = reading_response_constraints(question_text) if require_agreement and len(items) == 1 else None
|
|
841
|
-
if require_agreement and not (choices or constraints or step_count):
|
|
863
|
+
if require_agreement and not (choices or constraints or step_count or free_response):
|
|
842
864
|
raise VisionUnconfirmedError('Expected one linked answer with displayed options or a reading response format.')
|
|
843
865
|
if step_count:
|
|
844
866
|
check_messages[0]['content'] = (
|
|
@@ -862,8 +884,19 @@ async def cross_check_text_answers(messages, results, complete, *, question_text
|
|
|
862
884
|
if keyword else 'Return exactly one word.')
|
|
863
885
|
instruction += f' Fill the numbered gap using the entire passage. {rule} Use no option label or surrounding punctuation.'
|
|
864
886
|
check_messages[0]['content'] = instruction
|
|
887
|
+
elif free_response:
|
|
888
|
+
check_messages[0]['content'] = (
|
|
889
|
+
'Independently solve the original question using its complete context and any code. '
|
|
890
|
+
'Return the exact text to enter into its answer field, preserving signs, case, and required formatting. '
|
|
891
|
+
'Return only JSON {"readable":true,"answers":[{"id":1,"answer":"exact value"}]}. '
|
|
892
|
+
'Use no option label, explanation or Markdown in the answer value. '
|
|
893
|
+
'If the implementation or a required convention is unspecified and changes the answer, '
|
|
894
|
+
'return {"readable":false,"answers":[]}.' + stack_reasoning_guidance(question_text)
|
|
895
|
+
)
|
|
865
896
|
|
|
866
897
|
def answer_key(entries):
|
|
898
|
+
if free_response:
|
|
899
|
+
return free_response_value(entries[0].get('answer'))
|
|
867
900
|
if step_count:
|
|
868
901
|
return ordering_key(entries[0].get('answer'), step_count)
|
|
869
902
|
if choices:
|
|
@@ -921,8 +954,13 @@ async def cross_check_text_answers(messages, results, complete, *, question_text
|
|
|
921
954
|
items[0].pop('reasoning', None)
|
|
922
955
|
items[0]['answer'] = ' '.join((items[0] if current == first else verified[0])['answer'].split())
|
|
923
956
|
return json.dumps(items, ensure_ascii=False)
|
|
957
|
+
if free_response:
|
|
958
|
+
if current != first:
|
|
959
|
+
items[0].pop('reasoning', None)
|
|
960
|
+
items[0]['answer'] = current
|
|
961
|
+
return json.dumps(items, ensure_ascii=False)
|
|
924
962
|
return results
|
|
925
|
-
if not (choices or constraints or step_count) and current is not None:
|
|
963
|
+
if not (choices or constraints or step_count or free_response) and current is not None:
|
|
926
964
|
break
|
|
927
965
|
if not attempt:
|
|
928
966
|
previous = current
|
|
@@ -935,11 +973,11 @@ async def cross_check_text_answers(messages, results, complete, *, question_text
|
|
|
935
973
|
# primary answer over blocking the automation entirely. The primary solve was
|
|
936
974
|
# validated and the verification provider returned unusable JSON — a parsing
|
|
937
975
|
# failure, not a disagreement — so a hard 422 is disproportionate.
|
|
938
|
-
if not require_agreement and not step_count and current is None and previous is None:
|
|
976
|
+
if not require_agreement and not step_count and not free_response and current is None and previous is None:
|
|
939
977
|
return results
|
|
940
978
|
# For multi-answer questions (fill-in-the-blank), accept the primary answers
|
|
941
979
|
# when the majority of individual answers agree with any independent solve.
|
|
942
|
-
if not require_agreement and not choices and not step_count and first is not None and len(first) > 1:
|
|
980
|
+
if not require_agreement and not choices and not step_count and not free_response and first is not None and len(first) > 1:
|
|
943
981
|
best = current or previous
|
|
944
982
|
if best is not None:
|
|
945
983
|
agreed = sum(a == b for a, b in zip(first, best))
|
|
@@ -947,6 +985,8 @@ async def cross_check_text_answers(messages, results, complete, *, question_text
|
|
|
947
985
|
return results
|
|
948
986
|
if step_count:
|
|
949
987
|
raise VisionUnconfirmedError('The independent checks could not confirm a complete order for the displayed steps.')
|
|
988
|
+
if free_response:
|
|
989
|
+
raise VisionUnconfirmedError('The independent checks could not confirm the exact value to enter.')
|
|
950
990
|
raise VisionUnconfirmedError('The independent solves could not agree on the answer for this blank.' if constraints
|
|
951
991
|
else 'The independent solves could not agree on the displayed answer.')
|
|
952
992
|
|