browser-assistant 2.9.22 → 2.9.24
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 +18 -2
- package/extension/editor-bridge.js +80 -32
- package/extension/manifest.json +1 -1
- package/package.json +1 -1
- package/server/main.py +5 -1
- package/server/vision_images.py +30 -0
package/extension/content.js
CHANGED
|
@@ -2110,8 +2110,13 @@ function mountJournalCountdown(signal) {
|
|
|
2110
2110
|
if (ordering) {
|
|
2111
2111
|
const active = () => automation.running && automation.runId === runId && getAutomationContext().mode === 'FULL';
|
|
2112
2112
|
const nativeDrag = (prompt, options, from, to) => safeSendMessage({ action: 'orderingDrag', prompt, options, from, to });
|
|
2113
|
-
|
|
2114
|
-
|
|
2113
|
+
const orderUrl = location.href;
|
|
2114
|
+
const applied = await currentAdapter.applyOrder(document, current, answerIndexes, active, nativeDrag);
|
|
2115
|
+
if (!automation.running || automation.runId !== runId)
|
|
2116
|
+
break;
|
|
2117
|
+
if (!applied) {
|
|
2118
|
+
const visibleQuestion = location.href === orderUrl ? getAuthorizedQuestion() : null;
|
|
2119
|
+
automation.error = orderingReviewMessage(question, answerIndexes, visibleQuestion);
|
|
2115
2120
|
stopAutomation('PAUSED');
|
|
2116
2121
|
break;
|
|
2117
2122
|
}
|
|
@@ -2849,6 +2854,17 @@ function mountJournalCountdown(signal) {
|
|
|
2849
2854
|
throw new Error('The verified answer did not match the displayed options exactly.');
|
|
2850
2855
|
}
|
|
2851
2856
|
}
|
|
2857
|
+
function orderingReviewMessage(question, order, current) {
|
|
2858
|
+
const message = 'The page did not confirm the drag.';
|
|
2859
|
+
if (current?.type !== 'ordering' || current.text !== question.text || current.options.length !== order.length) {
|
|
2860
|
+
return message + ' Check the current rows before submitting.';
|
|
2861
|
+
}
|
|
2862
|
+
const positions = order.map(index => current.options.findIndex(option => option.text === question.options[index].text) + 1);
|
|
2863
|
+
if (positions.includes(0) || new Set(positions).size !== order.length) {
|
|
2864
|
+
return message + ' Check the current rows before submitting.';
|
|
2865
|
+
}
|
|
2866
|
+
return message + ` Arrange the current rows in the order ${positions.join(' → ')}.`;
|
|
2867
|
+
}
|
|
2852
2868
|
async function prepareVisionQuestionContext() {
|
|
2853
2869
|
const context = { url: location.href, text: '', question: getAuthorizedQuestion() };
|
|
2854
2870
|
if (!context.question || context.question.type === 'code') {
|
|
@@ -286,50 +286,98 @@ function browserAssistantReadMcqSnippets() {
|
|
|
286
286
|
return { ok: false, error: error.message };
|
|
287
287
|
}
|
|
288
288
|
}
|
|
289
|
-
//
|
|
290
|
-
// native DataTransfer object only when these events originate in this world.
|
|
289
|
+
// Run in the page's main world so the practice page receives the drag data.
|
|
291
290
|
async function browserAssistantOrderingDrag(prompt, optionTexts, from, to) {
|
|
292
291
|
try {
|
|
293
292
|
const normalize = value => (value || '').replace(/\s+/g, ' ').trim();
|
|
294
|
-
|
|
295
|
-
const actualPrompt = normalize(question?.querySelector('#generic-question-wrapper-id')?.textContent);
|
|
296
|
-
if (!question || actualPrompt !== normalize(prompt) || !Array.isArray(optionTexts)
|
|
293
|
+
if (!Array.isArray(optionTexts)
|
|
297
294
|
|| !Number.isInteger(from) || !Number.isInteger(to) || from < 0 || to < 0)
|
|
298
295
|
return { ok: false };
|
|
299
|
-
const
|
|
300
|
-
|
|
301
|
-
|
|
296
|
+
const requestedPrompt = normalize(prompt);
|
|
297
|
+
if (!requestedPrompt)
|
|
298
|
+
return { ok: false };
|
|
299
|
+
const expectedTexts = optionTexts.map(normalize);
|
|
300
|
+
const uniqueTexts = new Set(expectedTexts);
|
|
301
|
+
if (uniqueTexts.size !== expectedTexts.length)
|
|
302
|
+
return { ok: false };
|
|
303
|
+
const rows = () => {
|
|
304
|
+
const question = document.querySelector('#generic-question-container');
|
|
305
|
+
if (normalize(question?.querySelector('#generic-question-wrapper-id')?.textContent) !== requestedPrompt)
|
|
306
|
+
return [];
|
|
307
|
+
const visible = [...question.querySelectorAll('.drag-and-drop-option-label')]
|
|
308
|
+
.filter(label => label.getClientRects().length)
|
|
309
|
+
.map(label => ({
|
|
310
|
+
label, row: label.parentElement, text: normalize(label.textContent),
|
|
311
|
+
handle: label.parentElement?.querySelector('.drag-icon-container[draggable="true"]'),
|
|
312
|
+
}));
|
|
313
|
+
return visible.length === expectedTexts.length && visible.every(row => uniqueTexts.has(row.text) && row.handle)
|
|
314
|
+
&& new Set(visible.map(row => row.text)).size === uniqueTexts.size ? visible : [];
|
|
315
|
+
};
|
|
302
316
|
const before = rows();
|
|
303
|
-
if (before.length !==
|
|
317
|
+
if (before.length !== expectedTexts.length || before.some((row, index) => row.text !== expectedTexts[index])
|
|
304
318
|
|| from >= before.length || to >= before.length)
|
|
305
319
|
return { ok: false };
|
|
306
320
|
if (from === to)
|
|
307
321
|
return { ok: true };
|
|
308
|
-
const
|
|
309
|
-
const
|
|
310
|
-
const
|
|
311
|
-
|
|
312
|
-
const
|
|
322
|
+
const moving = before[from].text;
|
|
323
|
+
const destination = before[to].text;
|
|
324
|
+
const findRow = text => rows().find(row => row.text === text);
|
|
325
|
+
const wait = (ms) => new Promise(resolve => setTimeout(resolve, ms));
|
|
326
|
+
const center = node => {
|
|
313
327
|
const rect = node.getBoundingClientRect();
|
|
314
|
-
node.
|
|
315
|
-
bubbles: true, cancelable: true, dataTransfer,
|
|
316
|
-
clientX: rect.left + rect.width / 2, clientY: rect.top + rect.height / 2,
|
|
317
|
-
}));
|
|
328
|
+
return { node, clientX: rect.left + rect.width / 2, clientY: rect.top + rect.height / 2 };
|
|
318
329
|
};
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
330
|
+
for (const useRowBody of [true, false]) {
|
|
331
|
+
const current = rows();
|
|
332
|
+
if (current.length !== before.length || current.some((row, index) => row.text !== expectedTexts[index]))
|
|
333
|
+
break;
|
|
334
|
+
const source = current[from].handle;
|
|
335
|
+
const dataTransfer = new DataTransfer();
|
|
336
|
+
dataTransfer.setData('text/plain', moving);
|
|
337
|
+
dataTransfer.effectAllowed = 'move';
|
|
338
|
+
const send = ({ node, clientX, clientY }, type) => node.dispatchEvent(new DragEvent(type, {
|
|
339
|
+
bubbles: true, cancelable: true, dataTransfer, clientX, clientY,
|
|
340
|
+
}));
|
|
341
|
+
const target = () => {
|
|
342
|
+
const row = findRow(destination);
|
|
343
|
+
if (!row)
|
|
344
|
+
return null;
|
|
345
|
+
if (!useRowBody)
|
|
346
|
+
return center(row.handle);
|
|
347
|
+
const { clientX } = center(row.label);
|
|
348
|
+
const rect = row.row.getBoundingClientRect();
|
|
349
|
+
const clientY = rect.top + rect.height * (from > to ? 0.25 : 0.75);
|
|
350
|
+
const hit = document.elementFromPoint?.(clientX, clientY);
|
|
351
|
+
return { node: hit && row.row.contains(hit) ? hit : row.label, clientX, clientY };
|
|
352
|
+
};
|
|
353
|
+
if (!send(center(source), 'dragstart'))
|
|
354
|
+
break;
|
|
355
|
+
try {
|
|
356
|
+
// A drag handler can render fresh row nodes between events.
|
|
357
|
+
await wait(220);
|
|
358
|
+
dataTransfer.dropEffect = 'move';
|
|
359
|
+
const entered = target();
|
|
360
|
+
if (!entered)
|
|
361
|
+
break;
|
|
362
|
+
send(entered, 'dragenter');
|
|
363
|
+
const hovered = target();
|
|
364
|
+
if (!hovered)
|
|
365
|
+
break;
|
|
366
|
+
send(hovered, 'dragover');
|
|
367
|
+
await wait(220);
|
|
368
|
+
const dropped = target();
|
|
369
|
+
if (!dropped)
|
|
370
|
+
break;
|
|
371
|
+
send(dropped, 'drop');
|
|
372
|
+
}
|
|
373
|
+
finally {
|
|
374
|
+
send(center(findRow(moving)?.handle || source), 'dragend');
|
|
375
|
+
}
|
|
376
|
+
for (let attempt = 0; attempt < 10; attempt++) {
|
|
377
|
+
await wait(160);
|
|
378
|
+
if (rows()[to]?.text === moving)
|
|
379
|
+
return { ok: true };
|
|
380
|
+
}
|
|
333
381
|
}
|
|
334
382
|
return { ok: false };
|
|
335
383
|
}
|
package/extension/manifest.json
CHANGED
package/package.json
CHANGED
package/server/main.py
CHANGED
|
@@ -29,6 +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,
|
|
32
33
|
reading_response_constraints,
|
|
33
34
|
VisionRateLimitError, VisionUnconfirmedError)
|
|
34
35
|
|
|
@@ -193,7 +194,7 @@ async def lifespan(_app: FastAPI):
|
|
|
193
194
|
client.close()
|
|
194
195
|
|
|
195
196
|
|
|
196
|
-
app = FastAPI(title="Browser Assistant API", version="2.9.
|
|
197
|
+
app = FastAPI(title="Browser Assistant API", version="2.9.24", lifespan=lifespan)
|
|
197
198
|
install_local_guards(app)
|
|
198
199
|
|
|
199
200
|
@app.exception_handler(HTTPException)
|
|
@@ -1363,6 +1364,9 @@ REPAIR MODE:
|
|
|
1363
1364
|
if item is None:
|
|
1364
1365
|
item = solve_stack_empty_order(ordering)
|
|
1365
1366
|
provider = 'local stack empty check'
|
|
1367
|
+
if item is None:
|
|
1368
|
+
item = solve_stack_push_order(ordering)
|
|
1369
|
+
provider = 'local stack push check'
|
|
1366
1370
|
if item is not None:
|
|
1367
1371
|
return {"results": json.dumps([item], ensure_ascii=False), "provider": f"{provider} [verified]",
|
|
1368
1372
|
"language": language, "answer_verified": True, "code_reviewed": False}
|
package/server/vision_images.py
CHANGED
|
@@ -228,6 +228,36 @@ def solve_stack_empty_order(ordering):
|
|
|
228
228
|
}
|
|
229
229
|
|
|
230
230
|
|
|
231
|
+
def solve_stack_push_order(ordering):
|
|
232
|
+
"""Check the dependencies of a linked-list stack push."""
|
|
233
|
+
if not ordering:
|
|
234
|
+
return None
|
|
235
|
+
prompt, options = ordering
|
|
236
|
+
if not re.fullmatch(
|
|
237
|
+
r'arrange the steps in the correct order for the push\s*\(\s*\) operation '
|
|
238
|
+
r'in a stack implemented (?:using|with) a linked list[.:?]?',
|
|
239
|
+
' '.join(prompt.replace('\x60', '').split()), re.I,
|
|
240
|
+
):
|
|
241
|
+
return None
|
|
242
|
+
steps = (
|
|
243
|
+
r'create a new node with temp pointing to it',
|
|
244
|
+
r'(?:point temp\s*->\s*next to (?:the )?top(?: pointer)?|temp\s*->\s*next\s*=\s*top)',
|
|
245
|
+
r'(?:update (?:the )?top(?: pointer)? to temp|top\s*=\s*temp)',
|
|
246
|
+
)
|
|
247
|
+
if len(options) != len(steps):
|
|
248
|
+
return None
|
|
249
|
+
normalized = [' '.join(option.replace('\x60', '').replace('→', '->').split()).lower().rstrip(' .;')
|
|
250
|
+
for option in options]
|
|
251
|
+
matches = [[index for index, option in enumerate(normalized, 1) if re.fullmatch(step, option)]
|
|
252
|
+
for step in steps]
|
|
253
|
+
if any(len(indices) != 1 for indices in matches):
|
|
254
|
+
return None
|
|
255
|
+
return {
|
|
256
|
+
'type': 'mcq', 'question': prompt, 'answer': [indices[0] for indices in matches],
|
|
257
|
+
'reasoning': 'Allocate temp first, link temp->next to the old top, then make temp the new top.',
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
|
|
231
261
|
def ordering_key(value, size):
|
|
232
262
|
if isinstance(value, str):
|
|
233
263
|
try:
|