@blazediff/agent 0.8.2 → 0.9.0
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/dist/cli.js +570 -228
- package/dist/index.d.mts +19 -1
- package/dist/index.d.ts +19 -1
- package/dist/index.js +292 -100
- package/dist/index.mjs +292 -100
- package/dist/review/client/assets/index-9wONQNrk.js +8 -0
- package/dist/review/client/assets/index-Bod0vbl9.css +1 -0
- package/dist/review/client/assets/logo-DtDpqlir.png +0 -0
- package/dist/review/client/index.html +2 -2
- package/package.json +1 -1
- package/dist/review/client/assets/index-5OALw55C.js +0 -47
- package/dist/review/client/assets/index-CQM1Tg8y.css +0 -1
package/dist/index.d.mts
CHANGED
|
@@ -216,7 +216,7 @@ interface ResolvedHarness {
|
|
|
216
216
|
harness: Harness;
|
|
217
217
|
params: Record<string, unknown>;
|
|
218
218
|
}
|
|
219
|
-
declare function captureScreenshot(baseUrl: string, opts: CaptureOptions, cwd?: string, harnesses?: ResolvedHarness[]): Promise<CaptureResult>;
|
|
219
|
+
declare function captureScreenshot(baseUrl: string, opts: CaptureOptions, cwd?: string, harnesses?: ResolvedHarness[], signal?: AbortSignal): Promise<CaptureResult>;
|
|
220
220
|
|
|
221
221
|
interface BrowsersInstallOptions {
|
|
222
222
|
check?: boolean;
|
|
@@ -363,8 +363,20 @@ interface JudgmentInterrupt {
|
|
|
363
363
|
|
|
364
364
|
type ResumeMap = Record<string, Verdict>;
|
|
365
365
|
type RunEvent = {
|
|
366
|
+
type: "capturing";
|
|
367
|
+
entryId: string;
|
|
368
|
+
url: string;
|
|
369
|
+
} | {
|
|
366
370
|
type: "captured";
|
|
367
371
|
entryId: string;
|
|
372
|
+
} | {
|
|
373
|
+
type: "capture-complete";
|
|
374
|
+
captured: number;
|
|
375
|
+
total: number;
|
|
376
|
+
} | {
|
|
377
|
+
type: "diffing";
|
|
378
|
+
entryId: string;
|
|
379
|
+
url: string;
|
|
368
380
|
} | {
|
|
369
381
|
type: "result";
|
|
370
382
|
result: CheckResult;
|
|
@@ -464,12 +476,18 @@ interface ReviewRegion {
|
|
|
464
476
|
pixels: number;
|
|
465
477
|
change: number;
|
|
466
478
|
}
|
|
479
|
+
interface ReviewImageSize {
|
|
480
|
+
width: number;
|
|
481
|
+
height: number;
|
|
482
|
+
}
|
|
467
483
|
interface ReviewEntry {
|
|
468
484
|
id: string;
|
|
469
485
|
name: string;
|
|
470
486
|
url: string;
|
|
471
487
|
width: number;
|
|
472
488
|
height: number;
|
|
489
|
+
baselineSize?: ReviewImageSize;
|
|
490
|
+
candidateSize?: ReviewImageSize;
|
|
473
491
|
diff: number;
|
|
474
492
|
classification: ReviewClass;
|
|
475
493
|
severity: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -216,7 +216,7 @@ interface ResolvedHarness {
|
|
|
216
216
|
harness: Harness;
|
|
217
217
|
params: Record<string, unknown>;
|
|
218
218
|
}
|
|
219
|
-
declare function captureScreenshot(baseUrl: string, opts: CaptureOptions, cwd?: string, harnesses?: ResolvedHarness[]): Promise<CaptureResult>;
|
|
219
|
+
declare function captureScreenshot(baseUrl: string, opts: CaptureOptions, cwd?: string, harnesses?: ResolvedHarness[], signal?: AbortSignal): Promise<CaptureResult>;
|
|
220
220
|
|
|
221
221
|
interface BrowsersInstallOptions {
|
|
222
222
|
check?: boolean;
|
|
@@ -363,8 +363,20 @@ interface JudgmentInterrupt {
|
|
|
363
363
|
|
|
364
364
|
type ResumeMap = Record<string, Verdict>;
|
|
365
365
|
type RunEvent = {
|
|
366
|
+
type: "capturing";
|
|
367
|
+
entryId: string;
|
|
368
|
+
url: string;
|
|
369
|
+
} | {
|
|
366
370
|
type: "captured";
|
|
367
371
|
entryId: string;
|
|
372
|
+
} | {
|
|
373
|
+
type: "capture-complete";
|
|
374
|
+
captured: number;
|
|
375
|
+
total: number;
|
|
376
|
+
} | {
|
|
377
|
+
type: "diffing";
|
|
378
|
+
entryId: string;
|
|
379
|
+
url: string;
|
|
368
380
|
} | {
|
|
369
381
|
type: "result";
|
|
370
382
|
result: CheckResult;
|
|
@@ -464,12 +476,18 @@ interface ReviewRegion {
|
|
|
464
476
|
pixels: number;
|
|
465
477
|
change: number;
|
|
466
478
|
}
|
|
479
|
+
interface ReviewImageSize {
|
|
480
|
+
width: number;
|
|
481
|
+
height: number;
|
|
482
|
+
}
|
|
467
483
|
interface ReviewEntry {
|
|
468
484
|
id: string;
|
|
469
485
|
name: string;
|
|
470
486
|
url: string;
|
|
471
487
|
width: number;
|
|
472
488
|
height: number;
|
|
489
|
+
baselineSize?: ReviewImageSize;
|
|
490
|
+
candidateSize?: ReviewImageSize;
|
|
473
491
|
diff: number;
|
|
474
492
|
classification: ReviewClass;
|
|
475
493
|
severity: string;
|
package/dist/index.js
CHANGED
|
@@ -378,7 +378,7 @@ async function stabilize(page, waitFor, masks) {
|
|
|
378
378
|
() => new Promise((r) => requestAnimationFrame(() => r()))
|
|
379
379
|
);
|
|
380
380
|
}
|
|
381
|
-
async function captureScreenshot(baseUrl, opts, cwd = process.cwd(), harnesses) {
|
|
381
|
+
async function captureScreenshot(baseUrl, opts, cwd = process.cwd(), harnesses, signal) {
|
|
382
382
|
const viewport = opts.viewport ?? DEFAULT_VIEWPORT;
|
|
383
383
|
const waitFor = opts.waitFor ?? DEFAULT_WAIT_FOR;
|
|
384
384
|
const masks = opts.mask ?? [];
|
|
@@ -396,7 +396,17 @@ async function captureScreenshot(baseUrl, opts, cwd = process.cwd(), harnesses)
|
|
|
396
396
|
const context = handle.context;
|
|
397
397
|
const browser = await getBrowser();
|
|
398
398
|
const page = await openStablePage(handle);
|
|
399
|
+
const abortCapture = () => {
|
|
400
|
+
handle.disposable = true;
|
|
401
|
+
void context.close().catch(() => {
|
|
402
|
+
});
|
|
403
|
+
};
|
|
404
|
+
signal?.addEventListener("abort", abortCapture, { once: true });
|
|
399
405
|
try {
|
|
406
|
+
if (signal?.aborted) {
|
|
407
|
+
abortCapture();
|
|
408
|
+
throw signal.reason instanceof Error ? signal.reason : new Error("capture aborted");
|
|
409
|
+
}
|
|
400
410
|
const rejectScreenshot = async () => {
|
|
401
411
|
throw new HarnessError("setup harness must not call screenshot()");
|
|
402
412
|
};
|
|
@@ -443,6 +453,7 @@ async function captureScreenshot(baseUrl, opts, cwd = process.cwd(), harnesses)
|
|
|
443
453
|
subCaptures: subCaptures.length > 0 ? subCaptures : void 0
|
|
444
454
|
};
|
|
445
455
|
} finally {
|
|
456
|
+
signal?.removeEventListener("abort", abortCapture);
|
|
446
457
|
await page.close().catch(() => {
|
|
447
458
|
});
|
|
448
459
|
await releaseStableContext(handle);
|
|
@@ -519,21 +530,44 @@ function resolveBaseUrl(config, override) {
|
|
|
519
530
|
}
|
|
520
531
|
|
|
521
532
|
// src/graph/semaphore.ts
|
|
533
|
+
function abortReason(signal) {
|
|
534
|
+
return signal.reason instanceof Error ? signal.reason : new Error("operation aborted");
|
|
535
|
+
}
|
|
522
536
|
function createSemaphore(limit) {
|
|
523
537
|
if (limit < 1) throw new Error(`semaphore limit must be >= 1 (got ${limit})`);
|
|
524
538
|
let current = 0;
|
|
525
539
|
const queue = [];
|
|
526
|
-
async function run(fn) {
|
|
540
|
+
async function run(fn, signal) {
|
|
541
|
+
if (signal?.aborted) throw abortReason(signal);
|
|
527
542
|
if (current >= limit) {
|
|
528
|
-
await new Promise((resolve) =>
|
|
543
|
+
await new Promise((resolve, reject) => {
|
|
544
|
+
const onAbort = () => {
|
|
545
|
+
const index = queue.indexOf(waiter);
|
|
546
|
+
if (index >= 0) queue.splice(index, 1);
|
|
547
|
+
reject(abortReason(signal));
|
|
548
|
+
};
|
|
549
|
+
const waiter = {
|
|
550
|
+
start: () => {
|
|
551
|
+
signal?.removeEventListener("abort", onAbort);
|
|
552
|
+
if (signal?.aborted) {
|
|
553
|
+
reject(abortReason(signal));
|
|
554
|
+
return;
|
|
555
|
+
}
|
|
556
|
+
current++;
|
|
557
|
+
resolve();
|
|
558
|
+
}
|
|
559
|
+
};
|
|
560
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
561
|
+
queue.push(waiter);
|
|
562
|
+
});
|
|
563
|
+
} else {
|
|
564
|
+
current++;
|
|
529
565
|
}
|
|
530
|
-
current++;
|
|
531
566
|
try {
|
|
532
567
|
return await fn();
|
|
533
568
|
} finally {
|
|
534
569
|
current--;
|
|
535
|
-
|
|
536
|
-
if (next) next();
|
|
570
|
+
queue.shift()?.start();
|
|
537
571
|
}
|
|
538
572
|
}
|
|
539
573
|
return { run };
|
|
@@ -1309,66 +1343,196 @@ var dim = pc__default.default.dim;
|
|
|
1309
1343
|
var bold = pc__default.default.bold;
|
|
1310
1344
|
|
|
1311
1345
|
// src/judge/transformers.ts
|
|
1346
|
+
var SPINNER_FRAMES = ["\u280B", "\u2819", "\u2839", "\u2838", "\u283C", "\u2834", "\u2826", "\u2827", "\u2807", "\u280F"];
|
|
1347
|
+
var INTERACTIVE_REFRESH_MS = 80;
|
|
1348
|
+
var NON_INTERACTIVE_HEARTBEAT_MS = 1e4;
|
|
1349
|
+
var interactiveLoads = /* @__PURE__ */ new Map();
|
|
1350
|
+
var interactiveLinesDrawn = 0;
|
|
1351
|
+
var interactiveFrame = 0;
|
|
1352
|
+
var interactiveTimer;
|
|
1312
1353
|
var toMb = (bytes) => (bytes / 1048576).toFixed(1);
|
|
1313
|
-
|
|
1354
|
+
var elapsed = (startedAt) => `${((Date.now() - startedAt) / 1e3).toFixed(1)}s`;
|
|
1355
|
+
function clearInteractiveRows() {
|
|
1356
|
+
if (interactiveLinesDrawn === 0) return;
|
|
1357
|
+
process.stderr.write(`\x1B[${interactiveLinesDrawn}F\x1B[J`);
|
|
1358
|
+
interactiveLinesDrawn = 0;
|
|
1359
|
+
}
|
|
1360
|
+
function interactiveLine(load) {
|
|
1361
|
+
const duration = dim(`\xB7 ${elapsed(load.startedAt)}`);
|
|
1362
|
+
const size = load.total > 0 ? dim(`(${toMb(load.total)} MB)`) : "";
|
|
1363
|
+
if (load.status === "ready") {
|
|
1364
|
+
return ` ${pc__default.default.green("\u2713")} ${bold(load.label)} model ready ${size} ${duration}`.trimEnd();
|
|
1365
|
+
}
|
|
1366
|
+
if (load.status === "failed") {
|
|
1367
|
+
return ` ${pc__default.default.red("\u2717")} ${bold(load.label)} model failed ${duration}`;
|
|
1368
|
+
}
|
|
1369
|
+
const pct = load.total > 0 ? Math.min(100, Math.floor(load.loaded / load.total * 100)) : 0;
|
|
1370
|
+
const transferred = load.total > 0 ? `${pct}% ${dim(`(${toMb(load.loaded)}/${toMb(load.total)} MB)`)}` : `0% ${dim("(0.0 MB)")}`;
|
|
1371
|
+
const phase = load.total > 0 && load.loaded >= load.total ? dim("initializing runtime") : "loading";
|
|
1372
|
+
return ` ${pc__default.default.cyan(SPINNER_FRAMES[interactiveFrame])} ${bold(load.label)} model ${phase} ${transferred} ${duration}`;
|
|
1373
|
+
}
|
|
1374
|
+
function stopInteractiveTimer() {
|
|
1375
|
+
if (!interactiveTimer) return;
|
|
1376
|
+
clearInterval(interactiveTimer);
|
|
1377
|
+
interactiveTimer = void 0;
|
|
1378
|
+
}
|
|
1379
|
+
function redrawInteractiveRows() {
|
|
1380
|
+
clearInteractiveRows();
|
|
1381
|
+
let complete = interactiveLoads.size > 0;
|
|
1382
|
+
for (const load of interactiveLoads.values()) {
|
|
1383
|
+
process.stderr.write(`${interactiveLine(load)}
|
|
1384
|
+
`);
|
|
1385
|
+
if (load.status === "loading") complete = false;
|
|
1386
|
+
}
|
|
1387
|
+
if (complete) {
|
|
1388
|
+
interactiveLinesDrawn = 0;
|
|
1389
|
+
interactiveLoads.clear();
|
|
1390
|
+
stopInteractiveTimer();
|
|
1391
|
+
return;
|
|
1392
|
+
}
|
|
1393
|
+
interactiveLinesDrawn = interactiveLoads.size;
|
|
1394
|
+
}
|
|
1395
|
+
function startInteractiveTimer() {
|
|
1396
|
+
if (interactiveTimer) return;
|
|
1397
|
+
interactiveTimer = setInterval(() => {
|
|
1398
|
+
interactiveFrame = (interactiveFrame + 1) % SPINNER_FRAMES.length;
|
|
1399
|
+
redrawInteractiveRows();
|
|
1400
|
+
}, INTERACTIVE_REFRESH_MS);
|
|
1401
|
+
interactiveTimer.unref();
|
|
1402
|
+
}
|
|
1403
|
+
function setInteractiveLoad(id, load, status) {
|
|
1404
|
+
load.status = status;
|
|
1405
|
+
interactiveLoads.set(id, load);
|
|
1406
|
+
redrawInteractiveRows();
|
|
1407
|
+
}
|
|
1408
|
+
function createLoadProgress(label, opts) {
|
|
1314
1409
|
const interactive = Boolean(process.stderr.isTTY);
|
|
1315
|
-
const
|
|
1316
|
-
|
|
1410
|
+
const id = Symbol(label);
|
|
1411
|
+
const files = /* @__PURE__ */ new Map();
|
|
1412
|
+
const load = {
|
|
1413
|
+
label,
|
|
1414
|
+
startedAt: Date.now(),
|
|
1415
|
+
loaded: 0,
|
|
1416
|
+
total: 0,
|
|
1417
|
+
status: "loading"
|
|
1418
|
+
};
|
|
1419
|
+
let started = false;
|
|
1420
|
+
let finished = false;
|
|
1317
1421
|
let lastPct = -1;
|
|
1318
1422
|
let lastBucket = -1;
|
|
1423
|
+
let heartbeat;
|
|
1319
1424
|
const totals = () => {
|
|
1320
1425
|
let loaded = 0;
|
|
1321
1426
|
let total = 0;
|
|
1322
|
-
for (const
|
|
1323
|
-
loaded +=
|
|
1324
|
-
total +=
|
|
1427
|
+
for (const file of files.values()) {
|
|
1428
|
+
loaded += file.loaded;
|
|
1429
|
+
total += file.total;
|
|
1325
1430
|
}
|
|
1326
1431
|
const pct = total > 0 ? Math.min(100, Math.floor(loaded / total * 100)) : 0;
|
|
1327
1432
|
return { loaded, total, pct };
|
|
1328
1433
|
};
|
|
1434
|
+
const stopHeartbeat = () => {
|
|
1435
|
+
if (!heartbeat) return;
|
|
1436
|
+
clearInterval(heartbeat);
|
|
1437
|
+
heartbeat = void 0;
|
|
1438
|
+
};
|
|
1439
|
+
const start = () => {
|
|
1440
|
+
if (started) return;
|
|
1441
|
+
started = true;
|
|
1442
|
+
load.startedAt = Date.now();
|
|
1443
|
+
if (interactive) {
|
|
1444
|
+
interactiveLoads.set(id, load);
|
|
1445
|
+
startInteractiveTimer();
|
|
1446
|
+
redrawInteractiveRows();
|
|
1447
|
+
return;
|
|
1448
|
+
}
|
|
1449
|
+
process.stderr.write(
|
|
1450
|
+
`${dim("[blazediff]")} loading ${bold(label)} model ${dim("(first run may download weights)\u2026")}
|
|
1451
|
+
`
|
|
1452
|
+
);
|
|
1453
|
+
process.stderr.write(` ${label}: 0% ${dim("(0.0 MB)")}
|
|
1454
|
+
`);
|
|
1455
|
+
lastBucket = 0;
|
|
1456
|
+
heartbeat = setInterval(() => {
|
|
1457
|
+
const { loaded, total, pct } = totals();
|
|
1458
|
+
const phase = total > 0 && loaded >= total ? "initializing runtime" : "still loading";
|
|
1459
|
+
const transfer = total > 0 ? `${pct}% (${toMb(loaded)}/${toMb(total)} MB)` : "0% (0.0 MB)";
|
|
1460
|
+
process.stderr.write(
|
|
1461
|
+
` ${label}: ${phase} ${transfer} ${dim(`\xB7 ${elapsed(load.startedAt)}`)}
|
|
1462
|
+
`
|
|
1463
|
+
);
|
|
1464
|
+
}, NON_INTERACTIVE_HEARTBEAT_MS);
|
|
1465
|
+
heartbeat.unref();
|
|
1466
|
+
};
|
|
1467
|
+
const finish = (status) => {
|
|
1468
|
+
if (finished) return;
|
|
1469
|
+
start();
|
|
1470
|
+
finished = true;
|
|
1471
|
+
stopHeartbeat();
|
|
1472
|
+
if (interactive) {
|
|
1473
|
+
setInteractiveLoad(id, load, status);
|
|
1474
|
+
return;
|
|
1475
|
+
}
|
|
1476
|
+
const { total } = totals();
|
|
1477
|
+
const size = total > 0 ? dim(` (${toMb(total)} MB)`) : "";
|
|
1478
|
+
const state = status === "ready" ? pc__default.default.green("ready") : pc__default.default.red("failed");
|
|
1479
|
+
process.stderr.write(
|
|
1480
|
+
` ${label}: ${state}${size} ${dim(`\xB7 ${elapsed(load.startedAt)}`)}
|
|
1481
|
+
`
|
|
1482
|
+
);
|
|
1483
|
+
};
|
|
1329
1484
|
return {
|
|
1485
|
+
start,
|
|
1330
1486
|
onProgress(event) {
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
);
|
|
1336
|
-
|
|
1487
|
+
start();
|
|
1488
|
+
if (!event.file) return;
|
|
1489
|
+
if (event.status === "done") {
|
|
1490
|
+
const file = files.get(event.file);
|
|
1491
|
+
if (!file) return;
|
|
1492
|
+
files.set(event.file, { loaded: file.total, total: file.total });
|
|
1493
|
+
} else {
|
|
1494
|
+
if (event.status !== "progress" || typeof event.total !== "number")
|
|
1495
|
+
return;
|
|
1496
|
+
files.set(event.file, {
|
|
1497
|
+
loaded: event.loaded ?? 0,
|
|
1498
|
+
total: event.total
|
|
1499
|
+
});
|
|
1337
1500
|
}
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
lastPct = pct;
|
|
1344
|
-
const line = ` ${label}: ${pct}% ${dim(`(${toMb(loaded)}/${toMb(total)} MB)`)}`;
|
|
1501
|
+
const current = totals();
|
|
1502
|
+
load.loaded = current.loaded;
|
|
1503
|
+
load.total = current.total;
|
|
1504
|
+
if (current.pct === lastPct) return;
|
|
1505
|
+
lastPct = current.pct;
|
|
1345
1506
|
if (interactive) {
|
|
1346
|
-
|
|
1507
|
+
redrawInteractiveRows();
|
|
1347
1508
|
return;
|
|
1348
1509
|
}
|
|
1349
|
-
const bucket = Math.floor(pct / 25);
|
|
1510
|
+
const bucket = Math.floor(current.pct / 25);
|
|
1350
1511
|
if (bucket > lastBucket) {
|
|
1351
1512
|
lastBucket = bucket;
|
|
1352
|
-
process.stderr.write(`${line}
|
|
1353
|
-
`);
|
|
1354
|
-
}
|
|
1355
|
-
},
|
|
1356
|
-
done() {
|
|
1357
|
-
if (!announced) return;
|
|
1358
|
-
if (interactive) {
|
|
1359
|
-
const { total } = totals();
|
|
1360
|
-
const size = total > 0 ? dim(` (${toMb(total)} MB)`) : "";
|
|
1361
1513
|
process.stderr.write(
|
|
1362
|
-
|
|
1514
|
+
` ${label}: ${current.pct}% ${dim(`(${toMb(current.loaded)}/${toMb(current.total)} MB)`)}
|
|
1363
1515
|
`
|
|
1364
1516
|
);
|
|
1365
|
-
} else if (lastPct < 100) {
|
|
1366
|
-
process.stderr.write(` ${label}: ${pc__default.default.green("ready")}
|
|
1367
|
-
`);
|
|
1368
1517
|
}
|
|
1369
|
-
}
|
|
1518
|
+
},
|
|
1519
|
+
done: () => finish("ready"),
|
|
1520
|
+
fail: () => finish("failed")
|
|
1370
1521
|
};
|
|
1371
1522
|
}
|
|
1523
|
+
async function loadTransformersModel(label, load) {
|
|
1524
|
+
const progress = createLoadProgress(label);
|
|
1525
|
+
progress.start();
|
|
1526
|
+
try {
|
|
1527
|
+
const mod = await loadTransformers();
|
|
1528
|
+
const result = await load(mod, progress.onProgress);
|
|
1529
|
+
progress.done();
|
|
1530
|
+
return result;
|
|
1531
|
+
} catch (error) {
|
|
1532
|
+
progress.fail();
|
|
1533
|
+
throw error;
|
|
1534
|
+
}
|
|
1535
|
+
}
|
|
1372
1536
|
async function loadTransformers() {
|
|
1373
1537
|
try {
|
|
1374
1538
|
return await import('@huggingface/transformers');
|
|
@@ -1384,22 +1548,24 @@ async function loadTransformers() {
|
|
|
1384
1548
|
var MODEL_ID = "onnx-community/Qwen3.5-0.8B-ONNX";
|
|
1385
1549
|
var MAX_NEW_TOKENS = 64;
|
|
1386
1550
|
async function defaultFactory() {
|
|
1387
|
-
const
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1551
|
+
const { tokenizer, model } = await loadTransformersModel(
|
|
1552
|
+
"classifier",
|
|
1553
|
+
async (mod, progress_callback) => {
|
|
1554
|
+
const [tokenizer2, model2] = await Promise.all([
|
|
1555
|
+
mod.AutoTokenizer.from_pretrained(MODEL_ID, { progress_callback }),
|
|
1556
|
+
mod.Qwen3_5ForConditionalGeneration.from_pretrained(MODEL_ID, {
|
|
1557
|
+
dtype: {
|
|
1558
|
+
embed_tokens: "fp32",
|
|
1559
|
+
vision_encoder: "q8",
|
|
1560
|
+
decoder_model_merged: "q4"
|
|
1561
|
+
},
|
|
1562
|
+
device: "cpu",
|
|
1563
|
+
progress_callback
|
|
1564
|
+
})
|
|
1565
|
+
]);
|
|
1566
|
+
return { tokenizer: tokenizer2, model: model2 };
|
|
1567
|
+
}
|
|
1568
|
+
);
|
|
1403
1569
|
return {
|
|
1404
1570
|
async complete(prompt) {
|
|
1405
1571
|
const inputs = tokenizer.apply_chat_template(
|
|
@@ -1637,23 +1803,25 @@ var PATCH_SIZE = 14;
|
|
|
1637
1803
|
var MAX_NEW_TOKENS2 = 64;
|
|
1638
1804
|
var ANSWER_MARKER = "Answer:";
|
|
1639
1805
|
async function defaultFactory2() {
|
|
1640
|
-
const mod = await
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1806
|
+
const { mod, tokenizer, processor, model } = await loadTransformersModel(
|
|
1807
|
+
"vision",
|
|
1808
|
+
async (mod2, progress_callback) => {
|
|
1809
|
+
const [tokenizer2, processor2, model2] = await Promise.all([
|
|
1810
|
+
mod2.AutoTokenizer.from_pretrained(MODEL_ID2, { progress_callback }),
|
|
1811
|
+
mod2.AutoProcessor.from_pretrained(MODEL_ID2, { progress_callback }),
|
|
1812
|
+
mod2.Moondream1ForConditionalGeneration.from_pretrained(MODEL_ID2, {
|
|
1813
|
+
dtype: {
|
|
1814
|
+
embed_tokens: "fp32",
|
|
1815
|
+
vision_encoder: "q8",
|
|
1816
|
+
decoder_model_merged: "q4"
|
|
1817
|
+
},
|
|
1818
|
+
device: "cpu",
|
|
1819
|
+
progress_callback
|
|
1820
|
+
})
|
|
1821
|
+
]);
|
|
1822
|
+
return { mod: mod2, tokenizer: tokenizer2, processor: processor2, model: model2 };
|
|
1823
|
+
}
|
|
1824
|
+
);
|
|
1657
1825
|
return {
|
|
1658
1826
|
async describe(imagePath, question) {
|
|
1659
1827
|
const image = await mod.RawImage.read(imagePath);
|
|
@@ -2627,7 +2795,7 @@ function failResult(entry, outcome, actualPath, baselinePath, verdict) {
|
|
|
2627
2795
|
function asCaptured(entry, output) {
|
|
2628
2796
|
return { entry, output };
|
|
2629
2797
|
}
|
|
2630
|
-
function makeCaptureNode(semaphore) {
|
|
2798
|
+
function makeCaptureNode(semaphore, abortController) {
|
|
2631
2799
|
return async function captureNode(state) {
|
|
2632
2800
|
const entry = state.entry;
|
|
2633
2801
|
const options = state.options;
|
|
@@ -2670,22 +2838,33 @@ function makeCaptureNode(semaphore) {
|
|
|
2670
2838
|
}
|
|
2671
2839
|
const baselinePath = path__default.default.join(options.baselinesDir, `${entry.id}.png`);
|
|
2672
2840
|
try {
|
|
2673
|
-
const capture = await semaphore.run(
|
|
2674
|
-
(
|
|
2675
|
-
|
|
2676
|
-
|
|
2677
|
-
|
|
2678
|
-
|
|
2679
|
-
|
|
2680
|
-
|
|
2681
|
-
|
|
2682
|
-
|
|
2683
|
-
|
|
2684
|
-
|
|
2685
|
-
|
|
2686
|
-
|
|
2687
|
-
|
|
2688
|
-
|
|
2841
|
+
const capture = await semaphore.run(async () => {
|
|
2842
|
+
emitEvent({
|
|
2843
|
+
type: "capturing",
|
|
2844
|
+
entryId: entry.id,
|
|
2845
|
+
url: entry.url
|
|
2846
|
+
});
|
|
2847
|
+
try {
|
|
2848
|
+
return await captureScreenshot(
|
|
2849
|
+
options.baseUrl,
|
|
2850
|
+
{
|
|
2851
|
+
id: entry.id,
|
|
2852
|
+
url: entry.url,
|
|
2853
|
+
viewport: entry.viewport,
|
|
2854
|
+
mask: entry.mask,
|
|
2855
|
+
waitFor: entry.waitFor,
|
|
2856
|
+
fullPage: entry.fullPage ?? DEFAULT_FULL_PAGE,
|
|
2857
|
+
mode: "actual"
|
|
2858
|
+
},
|
|
2859
|
+
options.cwd,
|
|
2860
|
+
harnesses,
|
|
2861
|
+
abortController.signal
|
|
2862
|
+
);
|
|
2863
|
+
} catch (err) {
|
|
2864
|
+
if (!(err instanceof HarnessError)) abortController.abort(err);
|
|
2865
|
+
throw err;
|
|
2866
|
+
}
|
|
2867
|
+
}, abortController.signal);
|
|
2689
2868
|
const items = [
|
|
2690
2869
|
asCaptured(entry, {
|
|
2691
2870
|
id: entry.id,
|
|
@@ -2754,15 +2933,16 @@ function makeDiffNode(semaphore) {
|
|
|
2754
2933
|
if (!capture.captureOutputPath || !capture.baselinePath) {
|
|
2755
2934
|
throw new Error("diffNode: capture output paths missing");
|
|
2756
2935
|
}
|
|
2757
|
-
const outcome = await semaphore.run(
|
|
2758
|
-
(
|
|
2936
|
+
const outcome = await semaphore.run(() => {
|
|
2937
|
+
emitEvent({ type: "diffing", entryId: entry.id, url: entry.url });
|
|
2938
|
+
return diffEntry(
|
|
2759
2939
|
entry.id,
|
|
2760
2940
|
capture.baselinePath,
|
|
2761
2941
|
capture.captureOutputPath,
|
|
2762
2942
|
{ threshold: options.threshold, emitDiffPng: options.emitDiffPng },
|
|
2763
2943
|
options.cwd
|
|
2764
|
-
)
|
|
2765
|
-
);
|
|
2944
|
+
);
|
|
2945
|
+
});
|
|
2766
2946
|
if (outcome.reason === "file-not-exists") {
|
|
2767
2947
|
return {
|
|
2768
2948
|
diffOutput: {
|
|
@@ -3089,18 +3269,23 @@ var GraphState = langgraph.Annotation.Root({
|
|
|
3089
3269
|
function threadIdFor(cwd) {
|
|
3090
3270
|
return crypto$1.createHash("sha1").update(paths(cwd).manifest).digest("hex").slice(0, 16);
|
|
3091
3271
|
}
|
|
3092
|
-
function buildCaptureGraph(captureSemaphore) {
|
|
3093
|
-
return new langgraph.StateGraph(CaptureState).addNode("capture", makeCaptureNode(captureSemaphore)).addEdge(langgraph.START, "capture").addEdge("capture", langgraph.END).compile();
|
|
3272
|
+
function buildCaptureGraph(captureSemaphore, abortController) {
|
|
3273
|
+
return new langgraph.StateGraph(CaptureState).addNode("capture", makeCaptureNode(captureSemaphore, abortController)).addEdge(langgraph.START, "capture").addEdge("capture", langgraph.END).compile();
|
|
3094
3274
|
}
|
|
3095
3275
|
function buildBranchGraph(diffSemaphore) {
|
|
3096
3276
|
return new langgraph.StateGraph(BranchState).addNode("diff", makeDiffNode(diffSemaphore)).addNode("judge", judgeNode).addEdge(langgraph.START, "diff").addEdge("diff", "judge").addEdge("judge", langgraph.END).compile();
|
|
3097
3277
|
}
|
|
3098
3278
|
async function dispatchNode(state) {
|
|
3279
|
+
const total = state.captured.length;
|
|
3280
|
+
const captured = state.captured.filter(
|
|
3281
|
+
(item) => item.output.captureOutputPath
|
|
3282
|
+
).length;
|
|
3283
|
+
emitEvent({ type: "capture-complete", captured, total });
|
|
3099
3284
|
if (state.options) await resolveJudge(state.options.judge).warmup?.();
|
|
3100
3285
|
return {};
|
|
3101
3286
|
}
|
|
3102
|
-
function buildGraph(captureSemaphore, diffSemaphore, checkpointer) {
|
|
3103
|
-
const captureBranch = buildCaptureGraph(captureSemaphore);
|
|
3287
|
+
function buildGraph(captureSemaphore, diffSemaphore, checkpointer, abortController) {
|
|
3288
|
+
const captureBranch = buildCaptureGraph(captureSemaphore, abortController);
|
|
3104
3289
|
const branch = buildBranchGraph(diffSemaphore);
|
|
3105
3290
|
return new langgraph.StateGraph(GraphState).addNode("load", loadNode).addNode("capture", captureBranch).addNode("dispatch", dispatchNode).addNode("branch", branch).addEdge(langgraph.START, "load").addConditionalEdges(
|
|
3106
3291
|
"load",
|
|
@@ -3192,9 +3377,15 @@ async function runGraph(opts) {
|
|
|
3192
3377
|
const concurrency = opts.concurrency ?? defaultConcurrency();
|
|
3193
3378
|
const captureSemaphore = createSemaphore(concurrency);
|
|
3194
3379
|
const diffSemaphore = createSemaphore(cpuCores());
|
|
3380
|
+
const abortController = new AbortController();
|
|
3195
3381
|
const baselinesDir = paths(cwd).baselines;
|
|
3196
3382
|
const checkpointer = new FsCheckpointSaver(paths(cwd).checkpoints);
|
|
3197
|
-
const graph = buildGraph(
|
|
3383
|
+
const graph = buildGraph(
|
|
3384
|
+
captureSemaphore,
|
|
3385
|
+
diffSemaphore,
|
|
3386
|
+
checkpointer,
|
|
3387
|
+
abortController
|
|
3388
|
+
);
|
|
3198
3389
|
const threadId = opts.threadId ?? threadIdFor(cwd);
|
|
3199
3390
|
if (!opts.resume) {
|
|
3200
3391
|
await checkpointer.deleteThread(threadId);
|
|
@@ -3215,6 +3406,7 @@ async function runGraph(opts) {
|
|
|
3215
3406
|
try {
|
|
3216
3407
|
collect = await streamGraph(graph, input, threadId, opts.onEvent);
|
|
3217
3408
|
} finally {
|
|
3409
|
+
abortController.abort();
|
|
3218
3410
|
setEventSink(void 0);
|
|
3219
3411
|
await closeBrowser();
|
|
3220
3412
|
}
|