browser-assistant 2.9.31 → 2.9.32

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.
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "manifest_version": 3,
3
3
  "name": "Browser Assistant",
4
- "version": "2.9.31",
4
+ "version": "2.9.32",
5
5
  "description": "Scans webpages for MCQs and coding problems. Powered by Groq (cloud) and Ollama (local fallback).",
6
6
  "permissions": [
7
7
  "activeTab",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "browser-assistant",
3
- "version": "2.9.31",
3
+ "version": "2.9.32",
4
4
  "description": "Chrome extension and local Python backend for exploring webpage questions and coding exercises",
5
5
  "license": "MIT",
6
6
  "repository": {
package/server/main.py CHANGED
@@ -29,7 +29,7 @@ from vision_images import (compress_image_base64, unique_image_blocks, collect_i
29
29
  answer_permutation, cross_check_text_answers, solve_matrix_choice, solve_row_parallel_choice,
30
30
  solve_relu_parallel_choice,
31
31
  ordering_question, solve_sorted_list_merge_order, solve_stack_empty_order, solve_pseudocode_choice,
32
- solve_stack_push_order, solve_stack_pop_order,
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,
34
34
  reading_response_constraints,
35
35
  VisionRateLimitError, VisionUnconfirmedError)
@@ -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.31", lifespan=lifespan)
198
+ app = FastAPI(title="Browser Assistant API", version="2.9.32", lifespan=lifespan)
199
199
  install_local_guards(app)
200
200
 
201
201
  @app.exception_handler(HTTPException)
@@ -1424,6 +1424,9 @@ async def solve_questions(content: PageContent):
1424
1424
  if item is None:
1425
1425
  item = solve_stack_pop_order(ordering)
1426
1426
  provider = 'local stack pop check'
1427
+ if item is None:
1428
+ item = solve_next_greater_element_order(ordering)
1429
+ provider = 'local next greater element check'
1427
1430
  if item is not None:
1428
1431
  return {"results": json.dumps([item], ensure_ascii=False), "provider": f"{provider} [verified]",
1429
1432
  "language": language, "answer_verified": True, "code_reviewed": False}
@@ -278,6 +278,37 @@ def solve_stack_pop_order(ordering):
278
278
  )
279
279
 
280
280
 
281
+ def solve_next_greater_element_order(ordering):
282
+ """Verify the specified right-to-left monotonic-stack dependency chain."""
283
+ if not ordering:
284
+ return None
285
+ prompt, options = ordering
286
+ if not re.fullmatch(
287
+ r'arrange the steps of the optimal stack[- ]based approach to find the '
288
+ r'(?:NGE|next greater element) in the correct order[.:?]?',
289
+ ' '.join(prompt.replace('\x60', '').split()), re.I,
290
+ ):
291
+ return None
292
+ steps = (
293
+ 'initialize a result array with -1 values',
294
+ 'loop through each element from the end of the array to the beginning',
295
+ 'use a while loop to remove elements from the stack that are less than or equal to the current element',
296
+ 'if the stack is not empty, set the top of the stack as the next greater element',
297
+ 'push the current element onto the stack',
298
+ 'return the result array ans',
299
+ )
300
+ normalized = [' '.join(option.replace('\x60', '').replace('−', '-').split()).lower().rstrip(' .;')
301
+ for option in options]
302
+ if len(normalized) != len(steps) or set(normalized) != set(steps):
303
+ return None
304
+ return {
305
+ 'type': 'mcq', 'question': prompt, 'answer': [normalized.index(step) + 1 for step in steps],
306
+ 'reasoning': 'Initialize answers to -1, then traverse right to left. Remove stack values that are not '
307
+ 'greater than the current value, read the remaining top if any, then push the current value. '
308
+ 'Return the answers after traversal.',
309
+ }
310
+
311
+
281
312
  def ordering_key(value, size):
282
313
  if isinstance(value, str):
283
314
  try:
@@ -287,6 +318,36 @@ def ordering_key(value, size):
287
318
  return tuple(value) if answer_permutation(value) and len(value) == size else None
288
319
 
289
320
 
321
+ def checked_step_order(raw, options):
322
+ """Bind an independent ordering response to the exact supplied steps."""
323
+ normalized = [' '.join(option.split()) for option in options]
324
+ if len(set(normalized)) != len(normalized):
325
+ return None
326
+ payload = _verification_payload(raw)
327
+ if payload.get('readable') is False:
328
+ raise VisionUnconfirmedError('The independent solve could not read every step.')
329
+ entries = payload.get('answers')
330
+ if payload.get('readable') is not True or not isinstance(entries, list) or len(entries) != 1:
331
+ return None
332
+ entry = entries[0]
333
+ if not isinstance(entry, dict) or type(entry.get('id')) is not int or entry['id'] != 1:
334
+ return None
335
+ numeric = ordering_key(entry.get('answer'), len(options))
336
+ if 'ordered_steps' not in entry:
337
+ return numeric
338
+ ordered_steps = entry['ordered_steps']
339
+ if not isinstance(ordered_steps, list) or len(ordered_steps) != len(options):
340
+ return None
341
+ positions = {text: index for index, text in enumerate(normalized, 1)}
342
+ by_text = tuple(positions.get(' '.join(step.split())) if isinstance(step, str) else None
343
+ for step in ordered_steps)
344
+ if None in by_text or len(set(by_text)) != len(options):
345
+ return None
346
+ if 'answer' in entry and numeric != by_text:
347
+ return None
348
+ return by_text
349
+
350
+
290
351
  MATRIX_SYNTAX = re.compile(r'\\begin\{(?:[bpBvV]?matrix|smallmatrix)\}')
291
352
 
292
353
 
@@ -756,8 +817,18 @@ async def cross_check_text_answers(messages, results, complete, *, question_text
756
817
  if step_count:
757
818
  check_messages[0]['content'] = (
758
819
  'Independently order the displayed steps. Use every displayed item number once, check all prerequisite '
759
- f'relationships, and return only JSON with readable=true and one answers entry with id=1. '
760
- f'The answer value must be a JSON array of all {step_count} numbers from the list in this message.'
820
+ 'relationships, including initialization, loop direction, comparisons, updates and return. '
821
+ 'Use the NEW numbers in the numbered list supplied with this verification request. '
822
+ 'The previous displayed numbering is unavailable and must not be inferred. '
823
+ 'Return ONLY this JSON object schema: '
824
+ '{"readable":true,"answers":[{"id":1,"answer":[2,1,3]}]}. '
825
+ f'The example illustrates the schema only. For this question the answer array must contain all '
826
+ f'{step_count} integers from 1 through {step_count}, each exactly once, in dependency order. '
827
+ 'Use JSON integers, with no option labels, step prose or Markdown in the answer field. '
828
+ 'Alternatively, return {"readable":true,"answers":[{"id":1,"ordered_steps":'
829
+ '["exact text of first step","exact text of second step"]}]}, copying ALL displayed step texts '
830
+ 'exactly once in dependency order. This alternative needs no numeric answer. '
831
+ 'If any step is missing or the ordering cannot be determined, return {"readable":false,"answers":[]}.'
761
832
  )
762
833
  elif constraints:
763
834
  _, _, keyword = constraints
@@ -798,10 +869,14 @@ async def cross_check_text_answers(messages, results, complete, *, question_text
798
869
  check_messages = [check_messages[0], {'role': 'user', 'content': f'{prompt}\n\nNumbered steps:\n{rows}'}]
799
870
  raw = await complete(check_messages)
800
871
  try:
801
- verified = parse_answer_check(raw, len(items))
802
- current = answer_key(verified)
803
- if step_count and current is not None:
804
- current = tuple(numbers[index - 1] for index in current)
872
+ if step_count:
873
+ shuffled = [options[number - 1] for number in numbers]
874
+ current = checked_step_order(raw, shuffled)
875
+ if current is not None:
876
+ current = tuple(numbers[index - 1] for index in current)
877
+ else:
878
+ verified = parse_answer_check(raw, len(items))
879
+ current = answer_key(verified)
805
880
  except ValueError:
806
881
  current = None
807
882
  if current is not None and (current == first or current == previous):