browser-assistant 2.9.24 → 2.9.26
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/editor-bridge.js +45 -7
- package/extension/manifest.json +1 -1
- package/package.json +1 -1
- package/server/main.py +5 -2
- package/server/vision_images.py +29 -9
|
@@ -327,11 +327,32 @@ async function browserAssistantOrderingDrag(prompt, optionTexts, from, to) {
|
|
|
327
327
|
const rect = node.getBoundingClientRect();
|
|
328
328
|
return { node, clientX: rect.left + rect.width / 2, clientY: rect.top + rect.height / 2 };
|
|
329
329
|
};
|
|
330
|
-
|
|
330
|
+
const unchangedRows = () => {
|
|
331
331
|
const current = rows();
|
|
332
|
-
|
|
332
|
+
return current.length === before.length && current.every((row, index) => row.text === expectedTexts[index]) ? current : [];
|
|
333
|
+
};
|
|
334
|
+
const pressHandle = (original, pressed) => {
|
|
335
|
+
const point = () => center(findRow(moving)?.handle || original);
|
|
336
|
+
const init = {
|
|
337
|
+
bubbles: true, cancelable: true, button: 0, buttons: pressed ? 1 : 0,
|
|
338
|
+
};
|
|
339
|
+
const pointer = point();
|
|
340
|
+
if (typeof PointerEvent === 'function' && !pointer.node.dispatchEvent(new PointerEvent(pressed ? 'pointerdown' : 'pointerup', { ...init, clientX: pointer.clientX, clientY: pointer.clientY, pointerType: 'mouse', pointerId: 1, isPrimary: true })) && pressed)
|
|
341
|
+
return;
|
|
342
|
+
const mouse = point();
|
|
343
|
+
mouse.node.dispatchEvent(new MouseEvent(pressed ? 'mousedown' : 'mouseup', {
|
|
344
|
+
...init, clientX: mouse.clientX, clientY: mouse.clientY,
|
|
345
|
+
}));
|
|
346
|
+
};
|
|
347
|
+
for (const mode of ['row', 'handle', 'press']) {
|
|
348
|
+
if (mode === 'press' && typeof MouseEvent !== 'function')
|
|
333
349
|
break;
|
|
334
|
-
const
|
|
350
|
+
const current = unchangedRows();
|
|
351
|
+
if (!current.length)
|
|
352
|
+
break;
|
|
353
|
+
const handle = current[from].handle;
|
|
354
|
+
let source = handle;
|
|
355
|
+
let started = false;
|
|
335
356
|
const dataTransfer = new DataTransfer();
|
|
336
357
|
dataTransfer.setData('text/plain', moving);
|
|
337
358
|
dataTransfer.effectAllowed = 'move';
|
|
@@ -342,7 +363,7 @@ async function browserAssistantOrderingDrag(prompt, optionTexts, from, to) {
|
|
|
342
363
|
const row = findRow(destination);
|
|
343
364
|
if (!row)
|
|
344
365
|
return null;
|
|
345
|
-
if (
|
|
366
|
+
if (mode === 'handle')
|
|
346
367
|
return center(row.handle);
|
|
347
368
|
const { clientX } = center(row.label);
|
|
348
369
|
const rect = row.row.getBoundingClientRect();
|
|
@@ -350,9 +371,20 @@ async function browserAssistantOrderingDrag(prompt, optionTexts, from, to) {
|
|
|
350
371
|
const hit = document.elementFromPoint?.(clientX, clientY);
|
|
351
372
|
return { node: hit && row.row.contains(hit) ? hit : row.label, clientX, clientY };
|
|
352
373
|
};
|
|
353
|
-
if (!send(center(source), 'dragstart'))
|
|
354
|
-
break;
|
|
355
374
|
try {
|
|
375
|
+
if (mode === 'press') {
|
|
376
|
+
// Some practice rows become draggable only after the handle is pressed.
|
|
377
|
+
pressHandle(handle, true);
|
|
378
|
+
await wait(100);
|
|
379
|
+
const armed = unchangedRows()[from];
|
|
380
|
+
if (!armed?.row.matches('[draggable="true"]'))
|
|
381
|
+
break;
|
|
382
|
+
source = armed.row;
|
|
383
|
+
}
|
|
384
|
+
started = send({ ...center(findRow(moving)?.handle || handle), node: source }, 'dragstart');
|
|
385
|
+
// A cancelled start can mean the row has yet to be enabled by its handle.
|
|
386
|
+
if (!started)
|
|
387
|
+
continue;
|
|
356
388
|
// A drag handler can render fresh row nodes between events.
|
|
357
389
|
await wait(220);
|
|
358
390
|
dataTransfer.dropEffect = 'move';
|
|
@@ -371,7 +403,13 @@ async function browserAssistantOrderingDrag(prompt, optionTexts, from, to) {
|
|
|
371
403
|
send(dropped, 'drop');
|
|
372
404
|
}
|
|
373
405
|
finally {
|
|
374
|
-
|
|
406
|
+
if (started) {
|
|
407
|
+
const latest = findRow(moving);
|
|
408
|
+
const endSource = latest && (source.matches('.drag-icon-container') ? latest.handle : latest.row);
|
|
409
|
+
send(center(endSource || source), 'dragend');
|
|
410
|
+
}
|
|
411
|
+
if (mode === 'press')
|
|
412
|
+
pressHandle(handle, false);
|
|
375
413
|
}
|
|
376
414
|
for (let attempt = 0; attempt < 10; attempt++) {
|
|
377
415
|
await wait(160);
|
package/extension/manifest.json
CHANGED
package/package.json
CHANGED
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,
|
|
32
|
+
solve_stack_push_order, solve_stack_pop_order,
|
|
33
33
|
reading_response_constraints,
|
|
34
34
|
VisionRateLimitError, VisionUnconfirmedError)
|
|
35
35
|
|
|
@@ -194,7 +194,7 @@ async def lifespan(_app: FastAPI):
|
|
|
194
194
|
client.close()
|
|
195
195
|
|
|
196
196
|
|
|
197
|
-
app = FastAPI(title="Browser Assistant API", version="2.9.
|
|
197
|
+
app = FastAPI(title="Browser Assistant API", version="2.9.26", lifespan=lifespan)
|
|
198
198
|
install_local_guards(app)
|
|
199
199
|
|
|
200
200
|
@app.exception_handler(HTTPException)
|
|
@@ -1367,6 +1367,9 @@ REPAIR MODE:
|
|
|
1367
1367
|
if item is None:
|
|
1368
1368
|
item = solve_stack_push_order(ordering)
|
|
1369
1369
|
provider = 'local stack push check'
|
|
1370
|
+
if item is None:
|
|
1371
|
+
item = solve_stack_pop_order(ordering)
|
|
1372
|
+
provider = 'local stack pop check'
|
|
1370
1373
|
if item is not None:
|
|
1371
1374
|
return {"results": json.dumps([item], ensure_ascii=False), "provider": f"{provider} [verified]",
|
|
1372
1375
|
"language": language, "answer_verified": True, "code_reviewed": False}
|
package/server/vision_images.py
CHANGED
|
@@ -228,22 +228,16 @@ def solve_stack_empty_order(ordering):
|
|
|
228
228
|
}
|
|
229
229
|
|
|
230
230
|
|
|
231
|
-
def
|
|
232
|
-
"""Check the dependencies of a linked-list stack push."""
|
|
231
|
+
def _solve_linked_stack_order(ordering, operation, steps, reasoning):
|
|
233
232
|
if not ordering:
|
|
234
233
|
return None
|
|
235
234
|
prompt, options = ordering
|
|
236
235
|
if not re.fullmatch(
|
|
237
|
-
|
|
236
|
+
rf'arrange the steps in the correct order for the {operation}\s*\(\s*\) operation '
|
|
238
237
|
r'in a stack implemented (?:using|with) a linked list[.:?]?',
|
|
239
238
|
' '.join(prompt.replace('\x60', '').split()), re.I,
|
|
240
239
|
):
|
|
241
240
|
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
241
|
if len(options) != len(steps):
|
|
248
242
|
return None
|
|
249
243
|
normalized = [' '.join(option.replace('\x60', '').replace('→', '->').split()).lower().rstrip(' .;')
|
|
@@ -254,10 +248,36 @@ def solve_stack_push_order(ordering):
|
|
|
254
248
|
return None
|
|
255
249
|
return {
|
|
256
250
|
'type': 'mcq', 'question': prompt, 'answer': [indices[0] for indices in matches],
|
|
257
|
-
'reasoning':
|
|
251
|
+
'reasoning': reasoning,
|
|
258
252
|
}
|
|
259
253
|
|
|
260
254
|
|
|
255
|
+
def solve_stack_push_order(ordering):
|
|
256
|
+
steps = (
|
|
257
|
+
r'create a new node with temp pointing to it',
|
|
258
|
+
r'(?:point temp\s*->\s*next to (?:the )?top(?: pointer)?|temp\s*->\s*next\s*=\s*top)',
|
|
259
|
+
r'(?:update (?:the )?top(?: pointer)? to temp|top\s*=\s*temp)',
|
|
260
|
+
)
|
|
261
|
+
return _solve_linked_stack_order(
|
|
262
|
+
ordering, 'push', steps, 'Allocate temp first, link temp->next to the old top, then make temp the new top.'
|
|
263
|
+
)
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
def solve_stack_pop_order(ordering):
|
|
267
|
+
steps = (
|
|
268
|
+
r'check (?:if|whether) the stack is empty using empty\s*\(\s*\)',
|
|
269
|
+
r'(?:create a temp pointer (?:which|that) points to the node the top pointer is pointing to'
|
|
270
|
+
r'|(?:save|store) (?:the )?(?:current )?top(?: pointer)? in temp|temp\s*=\s*top)',
|
|
271
|
+
r'(?:update (?:the )?top(?: pointer)? to|top\s*=)\s*(?:top|temp)\s*->\s*next',
|
|
272
|
+
r'(?:delete the node pointed to by temp|delete temp|free\s*\(\s*temp\s*\))',
|
|
273
|
+
)
|
|
274
|
+
return _solve_linked_stack_order(
|
|
275
|
+
ordering, 'pop', steps,
|
|
276
|
+
'Check for an empty stack first. If it has a node, save the old top in temp, advance top to the next node, '
|
|
277
|
+
'then delete the saved node.',
|
|
278
|
+
)
|
|
279
|
+
|
|
280
|
+
|
|
261
281
|
def ordering_key(value, size):
|
|
262
282
|
if isinstance(value, str):
|
|
263
283
|
try:
|