browser-assistant 2.9.22 → 2.9.23
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 +40 -14
- package/extension/manifest.json +1 -1
- package/package.json +1 -1
- package/server/main.py +5 -1
- package/server/vision_images.py +30 -0
|
@@ -291,22 +291,34 @@ function browserAssistantReadMcqSnippets() {
|
|
|
291
291
|
async function browserAssistantOrderingDrag(prompt, optionTexts, from, to) {
|
|
292
292
|
try {
|
|
293
293
|
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)
|
|
294
|
+
if (!Array.isArray(optionTexts)
|
|
297
295
|
|| !Number.isInteger(from) || !Number.isInteger(to) || from < 0 || to < 0)
|
|
298
296
|
return { ok: false };
|
|
299
|
-
const
|
|
300
|
-
|
|
301
|
-
|
|
297
|
+
const requestedPrompt = normalize(prompt);
|
|
298
|
+
if (!requestedPrompt)
|
|
299
|
+
return { ok: false };
|
|
300
|
+
const expectedTexts = optionTexts.map(normalize);
|
|
301
|
+
const uniqueTexts = new Set(expectedTexts);
|
|
302
|
+
if (uniqueTexts.size !== expectedTexts.length)
|
|
303
|
+
return { ok: false };
|
|
304
|
+
const rows = () => {
|
|
305
|
+
const question = document.querySelector('#generic-question-container');
|
|
306
|
+
if (normalize(question?.querySelector('#generic-question-wrapper-id')?.textContent) !== requestedPrompt)
|
|
307
|
+
return [];
|
|
308
|
+
const visible = [...question.querySelectorAll('.drag-and-drop-option-label')]
|
|
309
|
+
.filter(label => label.getClientRects().length)
|
|
310
|
+
.map(label => ({ text: normalize(label.textContent), handle: label.parentElement?.querySelector('.drag-icon-container[draggable="true"]') }));
|
|
311
|
+
return visible.length === expectedTexts.length && visible.every(row => uniqueTexts.has(row.text) && row.handle)
|
|
312
|
+
&& new Set(visible.map(row => row.text)).size === uniqueTexts.size ? visible : [];
|
|
313
|
+
};
|
|
302
314
|
const before = rows();
|
|
303
|
-
if (before.length !==
|
|
315
|
+
if (before.length !== expectedTexts.length || before.some((row, index) => row.text !== expectedTexts[index])
|
|
304
316
|
|| from >= before.length || to >= before.length)
|
|
305
317
|
return { ok: false };
|
|
306
318
|
if (from === to)
|
|
307
319
|
return { ok: true };
|
|
308
320
|
const source = before[from].handle;
|
|
309
|
-
const
|
|
321
|
+
const findHandle = index => rows().find(row => row.text === before[index].text)?.handle;
|
|
310
322
|
const dataTransfer = new DataTransfer();
|
|
311
323
|
dataTransfer.effectAllowed = 'move';
|
|
312
324
|
const send = (node, type) => {
|
|
@@ -317,12 +329,26 @@ async function browserAssistantOrderingDrag(prompt, optionTexts, from, to) {
|
|
|
317
329
|
}));
|
|
318
330
|
};
|
|
319
331
|
send(source, 'dragstart');
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
332
|
+
try {
|
|
333
|
+
// The portal can replace row nodes while the drag is in progress.
|
|
334
|
+
await new Promise(resolve => setTimeout(resolve, 220));
|
|
335
|
+
const entered = findHandle(to);
|
|
336
|
+
if (!entered)
|
|
337
|
+
return { ok: false };
|
|
338
|
+
send(entered, 'dragenter');
|
|
339
|
+
const hovered = findHandle(to);
|
|
340
|
+
if (!hovered)
|
|
341
|
+
return { ok: false };
|
|
342
|
+
send(hovered, 'dragover');
|
|
343
|
+
await new Promise(resolve => setTimeout(resolve, 220));
|
|
344
|
+
const target = findHandle(to);
|
|
345
|
+
if (!target)
|
|
346
|
+
return { ok: false };
|
|
347
|
+
send(target, 'drop');
|
|
348
|
+
}
|
|
349
|
+
finally {
|
|
350
|
+
send(findHandle(from) || source, 'dragend');
|
|
351
|
+
}
|
|
326
352
|
for (let attempt = 0; attempt < 10; attempt++) {
|
|
327
353
|
await new Promise(resolve => setTimeout(resolve, 160));
|
|
328
354
|
const after = rows();
|
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.23", 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:
|