@mizchi/vlmkit-ai 0.23.2 → 0.28.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/claims.d.mts +34 -0
- package/dist/claims.mjs +66 -0
- package/dist/errors.d.mts +17 -6
- package/dist/errors.mjs +1 -2
- package/dist/image-gen-client.d.mts +25 -26
- package/dist/image-gen-client.mjs +5 -6
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +2 -2
- package/dist/intent.d.mts +6 -10
- package/dist/intent.mjs +2 -3
- package/dist/jev-client.d.mts +131 -0
- package/dist/jev-client.mjs +146 -0
- package/dist/llm-client.d.mts +11 -15
- package/dist/llm-client.mjs +9 -7
- package/dist/locate.d.mts +67 -0
- package/dist/locate.mjs +158 -0
- package/dist/motion-check.d.mts +201 -0
- package/dist/motion-check.mjs +304 -0
- package/dist/nlp.d.mts +2 -5
- package/dist/nlp.mjs +2 -3
- package/dist/reasoning-pipeline.d.mts +12 -14
- package/dist/reasoning-pipeline.mjs +4 -4
- package/dist/reasoning.d.mts +4 -8
- package/dist/reasoning.mjs +2 -3
- package/dist/region-kind.d.mts +69 -0
- package/dist/region-kind.mjs +139 -0
- package/dist/vlm-client.d.mts +15 -18
- package/dist/vlm-client.mjs +4 -4
- package/dist/zoom-drivers.d.mts +7 -10
- package/dist/zoom-drivers.mjs +1 -2
- package/dist/zoom-geometry.d.mts +11 -14
- package/dist/zoom-geometry.mjs +1 -2
- package/dist/zoom-image.d.mts +17 -17
- package/dist/zoom-image.mjs +1 -2
- package/dist/zoom-loop.d.mts +21 -23
- package/dist/zoom-loop.mjs +1 -2
- package/dist/zoom.d.mts +6 -9
- package/dist/zoom.mjs +5 -5
- package/package.json +5 -4
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import { JevClientOptions } from "./jev-client.mjs";
|
|
2
|
+
import { JevAsk } from "./locate.mjs";
|
|
3
|
+
import { EasingName, MotionDirection, MotionPathReport, MotionSegment, OriginName, OriginPoint } from "@mizchi/vlmkit-judge/motion-path.ts";
|
|
4
|
+
/** A target measured by the page at a frame: border box (frame pixels), rendered opacity, transform scale. */
|
|
5
|
+
export interface MotionDom {
|
|
6
|
+
box: {
|
|
7
|
+
x: number;
|
|
8
|
+
y: number;
|
|
9
|
+
width: number;
|
|
10
|
+
height: number;
|
|
11
|
+
};
|
|
12
|
+
opacity: number;
|
|
13
|
+
scale: number;
|
|
14
|
+
/** Its own animation's progress in time, 0-1 (delay and duration its own), when it has one. */
|
|
15
|
+
t?: number | null;
|
|
16
|
+
/**
|
|
17
|
+
* Share of its box, within the viewport, where it is the topmost thing painted (0-1): what a
|
|
18
|
+
* clip, a cover or a stacking mistake leaves of it. What `jev: false` judges presence from.
|
|
19
|
+
*/
|
|
20
|
+
visible?: number;
|
|
21
|
+
/** Why it is not seen, when the page could tell: "clipped by header.topbar (overflow: hidden)…". */
|
|
22
|
+
hiddenBy?: string;
|
|
23
|
+
/** How long its own animation has been active (ms, negative in its delay): when it begins. */
|
|
24
|
+
elapsedMs?: number | null;
|
|
25
|
+
scaleX?: number;
|
|
26
|
+
scaleY?: number;
|
|
27
|
+
durationMs?: number;
|
|
28
|
+
iterations?: number | null;
|
|
29
|
+
/** The share of its box inside the viewport (0-1). */
|
|
30
|
+
onScreen?: number;
|
|
31
|
+
/** Its own opacity, before its ancestors': unchanged while it fades, the fade is theirs. */
|
|
32
|
+
ownOpacity?: number;
|
|
33
|
+
/** The ancestor with the lowest opacity under 1 at this frame. */
|
|
34
|
+
fadeBy?: string;
|
|
35
|
+
/** No layout box at all (display: none on it or an ancestor). */
|
|
36
|
+
notRendered?: boolean;
|
|
37
|
+
/** Every colour it paints (background stops, text, border), RGBA in order. */
|
|
38
|
+
paint?: number[];
|
|
39
|
+
/** Its gradients' stop positions and angles, on paint's 0-255 scale (100% or a turn is 255). */
|
|
40
|
+
stops?: number[];
|
|
41
|
+
/** Its box shadows: RGBA of each, then offsets, blur and spread (px). */
|
|
42
|
+
shadow?: number[];
|
|
43
|
+
/** A conic gradient's first arc, in degrees from its start (it grows as a ring fills clockwise). */
|
|
44
|
+
sweepDeg?: number;
|
|
45
|
+
/** Its own transform's translation (px): what carries its centre when it slides. */
|
|
46
|
+
shift?: number[];
|
|
47
|
+
/** Its clip-path's numbers (inset edges, radii), on paint's scale (100% is 255). */
|
|
48
|
+
clip?: number[];
|
|
49
|
+
/** Its filter's numbers (a blur's radius x 8, fractions x 255). */
|
|
50
|
+
filter?: number[];
|
|
51
|
+
/** A filter its finished animation's fill holds at rest, and why that matters. */
|
|
52
|
+
heldFilter?: string;
|
|
53
|
+
/** Its animation's @keyframes name is defined more than once, and what each defines. */
|
|
54
|
+
dupKeyframes?: string;
|
|
55
|
+
/** Its angle as drawn through every transform up the tree (2D only), and the ancestor that turns. */
|
|
56
|
+
screenDeg?: number;
|
|
57
|
+
turnedBy?: string;
|
|
58
|
+
/** One of its animations overridden on a property by a later one in animation-name. */
|
|
59
|
+
overriddenBy?: string;
|
|
60
|
+
/** Its own timing function when it is a curve with no name (cubic-bezier(…), linear(…)). */
|
|
61
|
+
ownEasing?: string;
|
|
62
|
+
/** A transition / animation duration var() that resolves to a unitless number. */
|
|
63
|
+
varDuration?: string;
|
|
64
|
+
/** Every run of its own animations (ms), when there is more than one. */
|
|
65
|
+
durations?: number[];
|
|
66
|
+
/** A keyframe of its own animation sets a timing function that overrides the element's. */
|
|
67
|
+
kfEasing?: string;
|
|
68
|
+
/** Points along its edge another element paints over (the 5x5 grid never reaches an edge). */
|
|
69
|
+
edgeCover?: {
|
|
70
|
+
share: number;
|
|
71
|
+
message: string;
|
|
72
|
+
};
|
|
73
|
+
/** It turns in 3D with no perspective to give the turn depth, and what to set. */
|
|
74
|
+
flat3d?: string;
|
|
75
|
+
/** Its own animation offsets a box that is position: static, where top / left do nothing. */
|
|
76
|
+
inertOffsets?: string;
|
|
77
|
+
/** A finished animation's forwards fill still holds what it animated, and why that matters. */
|
|
78
|
+
heldByFill?: string;
|
|
79
|
+
/** Its transition on background runs over a gradient (which steps: gradients do not interpolate). */
|
|
80
|
+
discreteBg?: boolean;
|
|
81
|
+
/** It takes a click at its centre as the page is. */
|
|
82
|
+
catches?: boolean;
|
|
83
|
+
/** An SVG element inside an <svg> (transform-origin from the viewBox by default). */
|
|
84
|
+
svg?: boolean;
|
|
85
|
+
}
|
|
86
|
+
export interface MotionFrame {
|
|
87
|
+
atMs: number;
|
|
88
|
+
png: Uint8Array;
|
|
89
|
+
/** Per target, in order, when the page could measure it (`--selector`); null for one it could not. */
|
|
90
|
+
dom?: (MotionDom | null)[];
|
|
91
|
+
}
|
|
92
|
+
export interface MotionCheckOptions {
|
|
93
|
+
/** What moves, in words, as a person would point at it: "the blue 'Saved' toast". */
|
|
94
|
+
targets: readonly string[];
|
|
95
|
+
/** Statements no frame may show: "text overlapping other text so that it is hard to read". */
|
|
96
|
+
forbid?: readonly string[];
|
|
97
|
+
/** The motion runs over [startMs, endMs]; frames after `endMs` show it at rest. */
|
|
98
|
+
startMs: number;
|
|
99
|
+
endMs: number;
|
|
100
|
+
/** Spans some animation runs in (entrance, exit…): each is fitted and searched for jumps alone. */
|
|
101
|
+
segments?: readonly MotionSegment[];
|
|
102
|
+
/** The targets are meant to leave by the end (a dismissed toast): gone at rest is not a fail. */
|
|
103
|
+
exits?: boolean;
|
|
104
|
+
/** Per target in order: this one is meant to leave (a flip card's front face, turned away). */
|
|
105
|
+
exitsFor?: readonly boolean[];
|
|
106
|
+
/** The timing function the author meant, for every segment or per segment in order. */
|
|
107
|
+
expectEasing?: EasingName | readonly EasingName[];
|
|
108
|
+
/** Per target, in order, overriding `expectEasing` for that target (cards ease-out, a bar ease-in-out). */
|
|
109
|
+
targetEasing?: readonly (EasingName | readonly EasingName[] | undefined)[];
|
|
110
|
+
/** The point a scale grows from: every target's, or per target in order. */
|
|
111
|
+
expectOrigin?: OriginName | readonly (OriginName | undefined)[];
|
|
112
|
+
/** The point a turn keeps still, in the element's own units: every target's, or per target in order. */
|
|
113
|
+
expectPivot?: readonly (OriginPoint | undefined)[];
|
|
114
|
+
/** When each target's own animation begins (page ms), per target in order. */
|
|
115
|
+
expectStartMs?: readonly (number | undefined)[];
|
|
116
|
+
/**
|
|
117
|
+
* Consecutive targets begin this far apart (ms), in the order given: each one's start is the
|
|
118
|
+
* first target's (or its --expect-start) plus k times this.
|
|
119
|
+
*/
|
|
120
|
+
expectStaggerMs?: number;
|
|
121
|
+
/** Device pixels per CSS px in the frames (a 2x capture): the frame's size in CSS px is its size over this. */
|
|
122
|
+
frameScale?: number;
|
|
123
|
+
/** How long one run takes (ms) and how many runs (null: infinite): one for all, or per target. */
|
|
124
|
+
expectDurationMs?: readonly (number | undefined)[];
|
|
125
|
+
expectIterations?: readonly (number | null | undefined)[];
|
|
126
|
+
expectLines?: readonly (number | undefined)[];
|
|
127
|
+
/** Which way each target's first segment moves: one for all, or per target. */
|
|
128
|
+
expectDirection?: readonly (MotionDirection | undefined)[];
|
|
129
|
+
/** Every target's centre must not move: only its size and opacity change. */
|
|
130
|
+
expectStill?: boolean;
|
|
131
|
+
/** Its angle on screen must not change (a label kept level inside a turning dial). */
|
|
132
|
+
expectUpright?: boolean;
|
|
133
|
+
/** Per target in order: this one's centre must not move. */
|
|
134
|
+
expectStillFor?: readonly boolean[];
|
|
135
|
+
/** Animations that change layout on the page ("div.notice animates margin-top"). */
|
|
136
|
+
layoutMovers?: readonly string[];
|
|
137
|
+
/** A statement is true at or above this (default 0.5). */
|
|
138
|
+
threshold?: number;
|
|
139
|
+
/** Within this of the threshold an answer is `uncertain` (default 0.3). */
|
|
140
|
+
uncertainBand?: number;
|
|
141
|
+
model?: string;
|
|
142
|
+
/**
|
|
143
|
+
* Ask Jev (default true). False judges from the page alone: every frame must carry every
|
|
144
|
+
* target's `dom` (`--selector`), presence is its `visible` share, and no statement is asked.
|
|
145
|
+
*/
|
|
146
|
+
jev?: boolean;
|
|
147
|
+
ask?: JevAsk;
|
|
148
|
+
client?: JevClientOptions;
|
|
149
|
+
/**
|
|
150
|
+
* Ask each target's box a second time on a magnified crop of the region it moves through
|
|
151
|
+
* (default true): a first look's edges are 1% steps, 12.8px on a 1280px frame, which is a jump's
|
|
152
|
+
* size on a short travel; magnified, they were ~5px in the jev-box bench. One more request per
|
|
153
|
+
* frame that shows a target.
|
|
154
|
+
*/
|
|
155
|
+
refine?: boolean;
|
|
156
|
+
/** Requests in flight at once (default 4). */
|
|
157
|
+
concurrency?: number;
|
|
158
|
+
}
|
|
159
|
+
export interface MotionFrameAnswer {
|
|
160
|
+
atMs: number;
|
|
161
|
+
rest: boolean;
|
|
162
|
+
targets: {
|
|
163
|
+
present: number;
|
|
164
|
+
box: {
|
|
165
|
+
x: number;
|
|
166
|
+
y: number;
|
|
167
|
+
width: number;
|
|
168
|
+
height: number;
|
|
169
|
+
};
|
|
170
|
+
refined?: boolean;
|
|
171
|
+
/** Its box coincides with another target's in this frame: one of them is the wrong element. */
|
|
172
|
+
unsure?: boolean;
|
|
173
|
+
}[];
|
|
174
|
+
forbid: number[];
|
|
175
|
+
}
|
|
176
|
+
export interface ForbidFinding {
|
|
177
|
+
statement: string;
|
|
178
|
+
/** Fail when it is seen once the motion stops, warn when only mid-motion. */
|
|
179
|
+
severity: "fail" | "warn";
|
|
180
|
+
/** Frames that show it, with Jev's noul. */
|
|
181
|
+
frames: {
|
|
182
|
+
atMs: number;
|
|
183
|
+
noul: number;
|
|
184
|
+
uncertain: boolean;
|
|
185
|
+
}[];
|
|
186
|
+
atRest: boolean;
|
|
187
|
+
}
|
|
188
|
+
export interface MotionCheckReport {
|
|
189
|
+
frames: MotionFrameAnswer[];
|
|
190
|
+
targets: (MotionPathReport & {
|
|
191
|
+
target: string;
|
|
192
|
+
})[];
|
|
193
|
+
forbidden: ForbidFinding[];
|
|
194
|
+
/** No fail finding on any target and no forbidden statement seen at rest. */
|
|
195
|
+
passed: boolean;
|
|
196
|
+
model: string;
|
|
197
|
+
calls: number;
|
|
198
|
+
costUsd: number;
|
|
199
|
+
inputTokens: number;
|
|
200
|
+
}
|
|
201
|
+
export declare function checkMotionFrames(frames: readonly MotionFrame[], options: MotionCheckOptions): Promise<MotionCheckReport>;
|
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
import { JEV_IMAGE_LIMITS, askJev, jevBoxToPixels, pngImage } from "./jev-client.mjs";
|
|
2
|
+
import { claimInstruction } from "./claims.mjs";
|
|
3
|
+
import { firstLookScale } from "./locate.mjs";
|
|
4
|
+
import { regionKindScale, regionKindView, regionKindWindow } from "./region-kind.mjs";
|
|
5
|
+
import { decodeImage, encodePngImage, resample } from "./zoom-image.mjs";
|
|
6
|
+
import { judgeMotionPath } from "@mizchi/vlmkit-judge/motion-path.ts";
|
|
7
|
+
// src/motion-check.ts
|
|
8
|
+
/**
|
|
9
|
+
* Is an animation visually broken? Frames of it, a target described in words, and statements
|
|
10
|
+
* that must not be seen. Jev answers per frame; vlmkit judges the motion.
|
|
11
|
+
*
|
|
12
|
+
* One request per frame, on one image: for each target a `noul` (shown?) and a `box` (where?),
|
|
13
|
+
* and a `noul` per forbidden statement — so a frame costs about what one screenshot does
|
|
14
|
+
* (~3.1k tokens at 1280x800, $0.00013) however many questions it carries.
|
|
15
|
+
*
|
|
16
|
+
* Jev is asked only what it is good at, measured (`docs/reports/2026-10-18-jev-easing.md`):
|
|
17
|
+
* asked for an easing name it was at chance (7/21); asked where the object was in each frame and
|
|
18
|
+
* the curve fitted here, 21/21. So the motion — jumps, snap-backs, a target lost mid-way, the
|
|
19
|
+
* easing — is `judgeMotionPath`'s, from positions and presence, and Jev never names it.
|
|
20
|
+
*
|
|
21
|
+
* Advisory: a model's reading of the pixels. The deterministic motion checks (`check animation`,
|
|
22
|
+
* `check integrity --timeline`) measure; this asks what a person would see in the frames.
|
|
23
|
+
*/
|
|
24
|
+
async function pool(items, n, f) {
|
|
25
|
+
const out = new Array(items.length);
|
|
26
|
+
let next = 0;
|
|
27
|
+
await Promise.all(Array.from({ length: Math.min(n, items.length) }, async () => {
|
|
28
|
+
while (next < items.length) {
|
|
29
|
+
const i = next++;
|
|
30
|
+
out[i] = await f(items[i]);
|
|
31
|
+
}
|
|
32
|
+
}));
|
|
33
|
+
return out;
|
|
34
|
+
}
|
|
35
|
+
async function checkMotionFrames(frames, options) {
|
|
36
|
+
if (frames.length === 0) throw new Error("no frames to check");
|
|
37
|
+
if (options.targets.length === 0 && (options.forbid ?? []).length === 0) throw new Error("nothing to check: give a target or a forbidden statement");
|
|
38
|
+
const ask = options.ask ?? ((req) => askJev(req, options.client));
|
|
39
|
+
const threshold = options.threshold ?? .5;
|
|
40
|
+
const band = options.uncertainBand ?? .3;
|
|
41
|
+
const forbid = options.forbid ?? [];
|
|
42
|
+
const model = options.model ?? "jev-1.14.0";
|
|
43
|
+
let costUsd = 0;
|
|
44
|
+
let inputTokens = 0;
|
|
45
|
+
let served = model;
|
|
46
|
+
let frameSize;
|
|
47
|
+
let calls = 0;
|
|
48
|
+
if (options.jev === false) {
|
|
49
|
+
if (forbid.length > 0) throw new Error("a forbidden statement can only be asked of Jev (jev: true)");
|
|
50
|
+
const missing = options.targets.findIndex((_, i) => !frames.every((f) => f.dom?.[i]));
|
|
51
|
+
if (missing >= 0) throw new Error(`without Jev every target needs the page's measurement: ${options.targets[missing]}`);
|
|
52
|
+
}
|
|
53
|
+
const answers = options.jev === false ? frames.map((frame) => {
|
|
54
|
+
const img = decodeImage(Buffer.from(frame.png));
|
|
55
|
+
const k = options.frameScale ?? 1;
|
|
56
|
+
frameSize ??= {
|
|
57
|
+
width: Math.round(img.width / k),
|
|
58
|
+
height: Math.round(img.height / k)
|
|
59
|
+
};
|
|
60
|
+
return {
|
|
61
|
+
atMs: frame.atMs,
|
|
62
|
+
rest: frame.atMs > options.endMs,
|
|
63
|
+
targets: options.targets.map((_, i) => {
|
|
64
|
+
const d = frame.dom[i];
|
|
65
|
+
return {
|
|
66
|
+
present: d.opacity < .05 ? 0 : d.visible ?? 1,
|
|
67
|
+
box: d.box
|
|
68
|
+
};
|
|
69
|
+
}),
|
|
70
|
+
forbid: []
|
|
71
|
+
};
|
|
72
|
+
}) : await askFrames();
|
|
73
|
+
async function askFrames() {
|
|
74
|
+
return pool(frames, options.concurrency ?? 4, async (frame) => {
|
|
75
|
+
const img = decodeImage(Buffer.from(frame.png));
|
|
76
|
+
frameSize ??= {
|
|
77
|
+
width: img.width,
|
|
78
|
+
height: img.height
|
|
79
|
+
};
|
|
80
|
+
const scale = firstLookScale(img.width, img.height);
|
|
81
|
+
if (scale === null) throw new Error(`a ${img.width}x${img.height} frame cannot be shown within Jev's ${JEV_IMAGE_LIMITS.minEdge}-${JEV_IMAGE_LIMITS.maxEdge}px edges`);
|
|
82
|
+
const shown = scale === 1 ? frame.png : encodePngImage(resample(img, {
|
|
83
|
+
width: Math.round(img.width * scale),
|
|
84
|
+
height: Math.round(img.height * scale)
|
|
85
|
+
}));
|
|
86
|
+
const questions = {};
|
|
87
|
+
options.targets.forEach((t, i) => {
|
|
88
|
+
questions[`p${i}`] = {
|
|
89
|
+
type: "noul",
|
|
90
|
+
instructions: claimInstruction(t)
|
|
91
|
+
};
|
|
92
|
+
questions[`b${i}`] = {
|
|
93
|
+
type: "box",
|
|
94
|
+
instructions: `${t.trim().replace(/[.\s]+$/, "")} in \`screenshot\``
|
|
95
|
+
};
|
|
96
|
+
});
|
|
97
|
+
forbid.forEach((f, i) => {
|
|
98
|
+
questions[`f${i}`] = {
|
|
99
|
+
type: "noul",
|
|
100
|
+
instructions: claimInstruction(f)
|
|
101
|
+
};
|
|
102
|
+
});
|
|
103
|
+
const r = await ask({
|
|
104
|
+
model,
|
|
105
|
+
state: { screenshot: "SHOT" },
|
|
106
|
+
assets: { SHOT: pngImage(shown) },
|
|
107
|
+
questions
|
|
108
|
+
});
|
|
109
|
+
calls++;
|
|
110
|
+
costUsd += r.costUsd;
|
|
111
|
+
inputTokens += r.usage.input_tokens;
|
|
112
|
+
served = r.model;
|
|
113
|
+
const a = r.answers;
|
|
114
|
+
const noul = (k) => a[k].noul;
|
|
115
|
+
return {
|
|
116
|
+
atMs: frame.atMs,
|
|
117
|
+
rest: frame.atMs > options.endMs,
|
|
118
|
+
targets: options.targets.map((_, i) => {
|
|
119
|
+
const b = jevBoxToPixels(a[`b${i}`].box, img.width, img.height);
|
|
120
|
+
return {
|
|
121
|
+
present: noul(`p${i}`),
|
|
122
|
+
box: {
|
|
123
|
+
x: b.x1,
|
|
124
|
+
y: b.y1,
|
|
125
|
+
width: b.x2 - b.x1,
|
|
126
|
+
height: b.y2 - b.y1
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
}),
|
|
130
|
+
forbid: forbid.map((_, i) => noul(`f${i}`))
|
|
131
|
+
};
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
if (options.jev !== false && options.refine !== false && frameSize) {
|
|
135
|
+
const size = frameSize;
|
|
136
|
+
for (const [i, target] of options.targets.entries()) {
|
|
137
|
+
if (frames.every((f) => f.dom?.[i])) continue;
|
|
138
|
+
const seen = answers.filter((f) => f.targets[i].present >= threshold);
|
|
139
|
+
if (seen.length === 0) continue;
|
|
140
|
+
const x1 = Math.min(...seen.map((f) => f.targets[i].box.x));
|
|
141
|
+
const y1 = Math.min(...seen.map((f) => f.targets[i].box.y));
|
|
142
|
+
const x2 = Math.max(...seen.map((f) => f.targets[i].box.x + f.targets[i].box.width));
|
|
143
|
+
const y2 = Math.max(...seen.map((f) => f.targets[i].box.y + f.targets[i].box.height));
|
|
144
|
+
const win = regionKindWindow({
|
|
145
|
+
x: x1,
|
|
146
|
+
y: y1,
|
|
147
|
+
width: x2 - x1,
|
|
148
|
+
height: y2 - y1
|
|
149
|
+
}, size);
|
|
150
|
+
const scale = regionKindScale(win.x2 - win.x1, win.y2 - win.y1);
|
|
151
|
+
if (scale === null || scale <= 1.05) continue;
|
|
152
|
+
const byTime = new Map(frames.map((f) => [f.atMs, f]));
|
|
153
|
+
await pool(seen, options.concurrency ?? 4, async (f) => {
|
|
154
|
+
const view = regionKindView(decodeImage(Buffer.from(byTime.get(f.atMs).png)), win, scale);
|
|
155
|
+
const r = await ask({
|
|
156
|
+
model,
|
|
157
|
+
state: { screenshot: "SHOT" },
|
|
158
|
+
assets: { SHOT: pngImage(encodePngImage(view)) },
|
|
159
|
+
questions: { b: {
|
|
160
|
+
type: "box",
|
|
161
|
+
instructions: `${target.trim().replace(/[.\s]+$/, "")} in \`screenshot\``
|
|
162
|
+
} }
|
|
163
|
+
});
|
|
164
|
+
calls++;
|
|
165
|
+
costUsd += r.costUsd;
|
|
166
|
+
inputTokens += r.usage.input_tokens;
|
|
167
|
+
const b = r.answers.b;
|
|
168
|
+
const w = win.x2 - win.x1;
|
|
169
|
+
const h = win.y2 - win.y1;
|
|
170
|
+
f.targets[i].box = {
|
|
171
|
+
x: win.x1 + b.box.left * w,
|
|
172
|
+
y: win.y1 + b.box.top * h,
|
|
173
|
+
width: (b.box.right - b.box.left) * w,
|
|
174
|
+
height: (b.box.bottom - b.box.top) * h
|
|
175
|
+
};
|
|
176
|
+
f.targets[i].refined = true;
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
const iou = (a, b) => {
|
|
181
|
+
const inter = Math.max(0, Math.min(a.x + a.width, b.x + b.width) - Math.max(a.x, b.x)) * Math.max(0, Math.min(a.y + a.height, b.y + b.height) - Math.max(a.y, b.y));
|
|
182
|
+
return inter / Math.max(1e-9, a.width * a.height + b.width * b.height - inter);
|
|
183
|
+
};
|
|
184
|
+
for (const f of answers) for (let i = 0; i < f.targets.length; i++) for (let j = i + 1; j < f.targets.length; j++) {
|
|
185
|
+
const [a, b] = [f.targets[i], f.targets[j]];
|
|
186
|
+
if (a.present >= threshold && b.present >= threshold && iou(a.box, b.box) > .5) a.unsure = b.unsure = true;
|
|
187
|
+
}
|
|
188
|
+
const domAt = new Map(frames.map((f) => [f.atMs, f.dom]));
|
|
189
|
+
const side = (i) => !!(options.expectStillFor?.[i] || options.exitsFor?.[i]);
|
|
190
|
+
const someMain = options.targets.some((_, i) => !side(i));
|
|
191
|
+
const sharedOff = (i) => side(i) && someMain;
|
|
192
|
+
const perTarget = (xs, i) => xs === void 0 ? void 0 : xs.length === 1 ? sharedOff(i) ? void 0 : xs[0] : xs[i];
|
|
193
|
+
const originFor = (i) => typeof options.expectOrigin === "string" ? sharedOff(i) ? void 0 : options.expectOrigin : options.expectOrigin?.length === 1 ? sharedOff(i) ? void 0 : options.expectOrigin[0] : options.expectOrigin?.[i];
|
|
194
|
+
const easingFor = (i) => options.targetEasing?.[i] ?? (sharedOff(i) ? void 0 : options.expectEasing);
|
|
195
|
+
let staggerFrom = options.expectStartMs?.[0];
|
|
196
|
+
const startFor = (i) => options.expectStartMs?.[i] ?? (options.expectStaggerMs !== void 0 && i > 0 && staggerFrom !== void 0 ? staggerFrom + i * options.expectStaggerMs : void 0);
|
|
197
|
+
const startFrom = (i) => options.expectStartMs?.[i] !== void 0 ? `--expect-start ${Math.round(options.expectStartMs[i])}` : `${options.expectStartMs?.[0] !== void 0 ? `--expect-start ${Math.round(options.expectStartMs[0])}` : `the first target's measured start ${Math.round(staggerFrom)}ms`} + ${i} × --expect-stagger ${Math.round(options.expectStaggerMs)}`;
|
|
198
|
+
const targets = options.targets.map((target, i) => {
|
|
199
|
+
const measured = frames.every((f) => f.dom?.[i]);
|
|
200
|
+
const samples = answers.map((f) => ({
|
|
201
|
+
atMs: f.atMs,
|
|
202
|
+
present: f.targets[i].present,
|
|
203
|
+
box: f.targets[i].box,
|
|
204
|
+
...measured ? { dom: domAt.get(f.atMs)[i] } : f.targets[i].unsure ? { unsure: true } : {}
|
|
205
|
+
}));
|
|
206
|
+
const judged = {
|
|
207
|
+
target,
|
|
208
|
+
...judgeMotionPath(samples, {
|
|
209
|
+
startMs: options.startMs,
|
|
210
|
+
endMs: options.endMs,
|
|
211
|
+
...options.segments ? { segments: options.segments } : {},
|
|
212
|
+
...frameSize ? { frame: frameSize } : {},
|
|
213
|
+
presenceThreshold: threshold,
|
|
214
|
+
...options.exits || options.exitsFor?.[i] ? { exits: true } : {},
|
|
215
|
+
...easingFor(i) ? { expectEasing: easingFor(i) } : {},
|
|
216
|
+
...originFor(i) ? { expectOrigin: originFor(i) } : {},
|
|
217
|
+
...perTarget(options.expectPivot, i) ? { expectPivot: perTarget(options.expectPivot, i) } : {},
|
|
218
|
+
...startFor(i) !== void 0 ? {
|
|
219
|
+
expectStartMs: startFor(i),
|
|
220
|
+
expectStartFrom: startFrom(i)
|
|
221
|
+
} : {},
|
|
222
|
+
...perTarget(options.expectDurationMs, i) !== void 0 ? { expectDurationMs: perTarget(options.expectDurationMs, i) } : {},
|
|
223
|
+
...perTarget(options.expectDirection, i) !== void 0 ? { expectDirection: perTarget(options.expectDirection, i) } : {},
|
|
224
|
+
...perTarget(options.expectLines, i) !== void 0 ? { expectLines: perTarget(options.expectLines, i) } : {},
|
|
225
|
+
...perTarget(options.expectIterations, i) !== void 0 ? { expectIterations: perTarget(options.expectIterations, i) } : {},
|
|
226
|
+
...options.expectStill || options.expectStillFor?.[i] ? { expectStill: true } : {},
|
|
227
|
+
...options.expectUpright ? { expectUpright: true } : {},
|
|
228
|
+
...options.layoutMovers ? { layoutMovers: options.layoutMovers } : {}
|
|
229
|
+
})
|
|
230
|
+
};
|
|
231
|
+
if (i === 0) staggerFrom ??= judged.startsAtMs;
|
|
232
|
+
return judged;
|
|
233
|
+
});
|
|
234
|
+
if (options.targets.length > 1) {
|
|
235
|
+
const once = [
|
|
236
|
+
[
|
|
237
|
+
"direction-mismatch",
|
|
238
|
+
"--expect-direction",
|
|
239
|
+
options.expectDirection?.length === 1
|
|
240
|
+
],
|
|
241
|
+
[
|
|
242
|
+
"duration-mismatch",
|
|
243
|
+
"--expect-duration",
|
|
244
|
+
options.expectDurationMs?.length === 1
|
|
245
|
+
],
|
|
246
|
+
[
|
|
247
|
+
"iterations-mismatch",
|
|
248
|
+
"--expect-iterations",
|
|
249
|
+
options.expectIterations?.length === 1
|
|
250
|
+
],
|
|
251
|
+
[
|
|
252
|
+
"lines-mismatch",
|
|
253
|
+
"--expect-lines",
|
|
254
|
+
options.expectLines?.length === 1
|
|
255
|
+
],
|
|
256
|
+
[
|
|
257
|
+
"origin-mismatch",
|
|
258
|
+
"--expect-origin",
|
|
259
|
+
typeof options.expectOrigin === "string" || options.expectOrigin?.length === 1 || options.expectPivot?.length === 1
|
|
260
|
+
],
|
|
261
|
+
[
|
|
262
|
+
"easing-mismatch",
|
|
263
|
+
"--expect-easing",
|
|
264
|
+
!!options.expectEasing && !options.targetEasing
|
|
265
|
+
],
|
|
266
|
+
[
|
|
267
|
+
"still-mismatch",
|
|
268
|
+
"--expect-still",
|
|
269
|
+
!!options.expectStill
|
|
270
|
+
]
|
|
271
|
+
];
|
|
272
|
+
for (const t of targets) for (const f of t.findings) {
|
|
273
|
+
const hit = once.find(([rule, , given]) => given && f.rule === rule);
|
|
274
|
+
if (hit) f.message += ` (${hit[1]} was given once, so it is every target's: give one per target in order${hit[1] === "--expect-still" ? ", or --still <css> for the one that stays" : ", any for one it does not describe"})`;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
const forbidden = [];
|
|
278
|
+
forbid.forEach((statement, i) => {
|
|
279
|
+
const seen = answers.filter((f) => f.forbid[i] >= threshold).map((f) => ({
|
|
280
|
+
atMs: f.atMs,
|
|
281
|
+
noul: f.forbid[i],
|
|
282
|
+
uncertain: Math.abs(f.forbid[i] - threshold) < band
|
|
283
|
+
}));
|
|
284
|
+
if (seen.length === 0) return;
|
|
285
|
+
const atRest = answers.some((f) => f.rest && f.forbid[i] >= threshold);
|
|
286
|
+
forbidden.push({
|
|
287
|
+
statement,
|
|
288
|
+
severity: atRest ? "fail" : "warn",
|
|
289
|
+
frames: seen,
|
|
290
|
+
atRest
|
|
291
|
+
});
|
|
292
|
+
});
|
|
293
|
+
return {
|
|
294
|
+
frames: answers,
|
|
295
|
+
targets,
|
|
296
|
+
forbidden,
|
|
297
|
+
passed: targets.every((t) => t.findings.every((f) => f.severity !== "fail")) && forbidden.every((f) => f.severity !== "fail"),
|
|
298
|
+
model: options.jev === false ? "none (measured from the page)" : served,
|
|
299
|
+
calls,
|
|
300
|
+
costUsd,
|
|
301
|
+
inputTokens
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
export { checkMotionFrames };
|
package/dist/nlp.d.mts
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
//#region src/nlp.d.ts
|
|
2
1
|
/**
|
|
3
2
|
* Text-matching helpers shared between expectation matching and reasoning.
|
|
4
3
|
*/
|
|
5
|
-
declare const STOP_WORDS: Set<string>;
|
|
6
|
-
declare const SYNONYMS: Record<string, string[]>;
|
|
7
|
-
//#endregion
|
|
8
|
-
export { STOP_WORDS, SYNONYMS };
|
|
4
|
+
export declare const STOP_WORDS: Set<string>;
|
|
5
|
+
export declare const SYNONYMS: Record<string, string[]>;
|
package/dist/nlp.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
// src/nlp.ts
|
|
2
2
|
/**
|
|
3
3
|
* Text-matching helpers shared between expectation matching and reasoning.
|
|
4
4
|
*/
|
|
5
|
-
const STOP_WORDS = new Set([
|
|
5
|
+
const STOP_WORDS = /* @__PURE__ */ new Set([
|
|
6
6
|
"gets",
|
|
7
7
|
"from",
|
|
8
8
|
"with",
|
|
@@ -46,5 +46,4 @@ const SYNONYMS = {
|
|
|
46
46
|
column: ["columnheader", "header"],
|
|
47
47
|
header: ["columnheader", "column"]
|
|
48
48
|
};
|
|
49
|
-
//#endregion
|
|
50
49
|
export { STOP_WORDS, SYNONYMS };
|
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
import { ResolutionPreset } from "@mizchi/vlmkit-core/image-resize.ts";
|
|
2
|
-
|
|
3
|
-
//#region src/reasoning-pipeline.d.ts
|
|
4
|
-
interface VisualChange {
|
|
2
|
+
export interface VisualChange {
|
|
5
3
|
element: string;
|
|
6
4
|
property: string;
|
|
7
5
|
before: string;
|
|
8
6
|
after: string;
|
|
9
7
|
severity: "low" | "medium" | "high";
|
|
10
8
|
}
|
|
11
|
-
interface StructuredDiffReport {
|
|
9
|
+
export interface StructuredDiffReport {
|
|
12
10
|
changes: VisualChange[];
|
|
13
11
|
summary: string;
|
|
14
12
|
regression: boolean;
|
|
@@ -17,13 +15,13 @@ interface StructuredDiffReport {
|
|
|
17
15
|
vlmLatencyMs: number;
|
|
18
16
|
vlmCostUsd: number;
|
|
19
17
|
}
|
|
20
|
-
interface CssFix {
|
|
18
|
+
export interface CssFix {
|
|
21
19
|
selector: string;
|
|
22
20
|
property: string;
|
|
23
21
|
value: string;
|
|
24
22
|
reason: string;
|
|
25
23
|
}
|
|
26
|
-
interface FixSuggestion {
|
|
24
|
+
export interface FixSuggestion {
|
|
27
25
|
fixes: CssFix[];
|
|
28
26
|
explanation: string;
|
|
29
27
|
confidence: "high" | "medium" | "low";
|
|
@@ -32,7 +30,7 @@ interface FixSuggestion {
|
|
|
32
30
|
llmLatencyMs: number;
|
|
33
31
|
llmCostUsd: number;
|
|
34
32
|
}
|
|
35
|
-
interface PipelineConfig {
|
|
33
|
+
export interface PipelineConfig {
|
|
36
34
|
/** Stage 1: VLM for image analysis (default: qwen3-vl-8b via OpenRouter) */
|
|
37
35
|
vlmModel?: string;
|
|
38
36
|
/** Stage 2: LLM for code generation (default: from VLMKIT_LLM_PROVIDER) */
|
|
@@ -50,7 +48,7 @@ interface PipelineConfig {
|
|
|
50
48
|
*/
|
|
51
49
|
throwIfMissing?: boolean;
|
|
52
50
|
}
|
|
53
|
-
interface AnalyzeOptions {
|
|
51
|
+
export interface AnalyzeOptions {
|
|
54
52
|
heatmapBase64?: string;
|
|
55
53
|
baselineBase64?: string;
|
|
56
54
|
currentBase64?: string;
|
|
@@ -69,15 +67,17 @@ interface AnalyzeOptions {
|
|
|
69
67
|
contentChangeCount: number;
|
|
70
68
|
};
|
|
71
69
|
}
|
|
72
|
-
interface ReasoningPipeline {
|
|
70
|
+
export interface ReasoningPipeline {
|
|
73
71
|
/** Stage 1: image -> structured diff */
|
|
74
72
|
analyze(options: AnalyzeOptions): Promise<StructuredDiffReport>;
|
|
75
73
|
/** Stage 2: structured diff + CSS -> fix proposal */
|
|
76
74
|
suggestFix(report: StructuredDiffReport, cssSource: string, cssDiff?: string): Promise<FixSuggestion>;
|
|
77
75
|
/** Run Stage 1 + 2 sequentially. Auto-escalates resolution if needed */
|
|
78
76
|
analyzeAndFix(options: AnalyzeOptions & {
|
|
79
|
-
cssSource: string;
|
|
80
|
-
|
|
77
|
+
cssSource: string;
|
|
78
|
+
/** CSS text diff (MISSING/CHANGED lines. Passed directly to Stage 2) */
|
|
79
|
+
cssDiff?: string;
|
|
80
|
+
/** High-resolution image for escalation (used by adaptive resolution) */
|
|
81
81
|
highResHeatmapBase64?: string;
|
|
82
82
|
}): Promise<{
|
|
83
83
|
analysis: StructuredDiffReport;
|
|
@@ -87,6 +87,4 @@ interface ReasoningPipeline {
|
|
|
87
87
|
vlmModel: string;
|
|
88
88
|
llmModel: string;
|
|
89
89
|
}
|
|
90
|
-
declare function createReasoningPipeline(config?: PipelineConfig): ReasoningPipeline | null;
|
|
91
|
-
//#endregion
|
|
92
|
-
export { AnalyzeOptions, CssFix, FixSuggestion, PipelineConfig, ReasoningPipeline, StructuredDiffReport, VisualChange, createReasoningPipeline };
|
|
90
|
+
export declare function createReasoningPipeline(config?: PipelineConfig): ReasoningPipeline | null;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { VrtConfigError } from "./errors.mjs";
|
|
2
1
|
import { createUnifiedLLMClient } from "./llm-client.mjs";
|
|
3
2
|
import { createVlmClient, resolveModel } from "./vlm-client.mjs";
|
|
3
|
+
import { VrtConfigError } from "./errors.mjs";
|
|
4
4
|
import { readEnv } from "@mizchi/vlmkit-core/project-config.ts";
|
|
5
5
|
import { resizeBase64Png } from "@mizchi/vlmkit-core/image-resize.ts";
|
|
6
|
-
|
|
6
|
+
// src/reasoning-pipeline.ts
|
|
7
7
|
/**
|
|
8
8
|
* VRT Reasoning Pipeline -- two-stage VLM + LLM pipeline
|
|
9
9
|
*
|
|
@@ -160,7 +160,8 @@ function createReasoningPipeline(config) {
|
|
|
160
160
|
llmModel: llmClient?.model ?? "none",
|
|
161
161
|
async analyze(options) {
|
|
162
162
|
if (!vlmClient) try {
|
|
163
|
-
|
|
163
|
+
const model = await resolveModel(vlmModelId);
|
|
164
|
+
vlmClient = await createVlmClient(model, { throwIfMissing: false });
|
|
164
165
|
} catch {
|
|
165
166
|
vlmClient = null;
|
|
166
167
|
}
|
|
@@ -253,5 +254,4 @@ function createReasoningPipeline(config) {
|
|
|
253
254
|
}
|
|
254
255
|
};
|
|
255
256
|
}
|
|
256
|
-
//#endregion
|
|
257
257
|
export { createReasoningPipeline };
|
package/dist/reasoning.d.mts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import { A11yDiff, ChangeIntent, PageExpectation } from "@mizchi/vlmkit-core/types.ts";
|
|
2
|
-
|
|
3
|
-
//#region src/reasoning.d.ts
|
|
4
2
|
/**
|
|
5
3
|
* Expectation -> change -> realization reasoning chain
|
|
6
4
|
*
|
|
@@ -8,7 +6,7 @@ import { A11yDiff, ChangeIntent, PageExpectation } from "@mizchi/vlmkit-core/typ
|
|
|
8
6
|
* 2. Change: what actually changed (a11y diff)
|
|
9
7
|
* 3. Realization: whether the expectation was realized in a11y semantics
|
|
10
8
|
*/
|
|
11
|
-
interface ReasoningChain {
|
|
9
|
+
export interface ReasoningChain {
|
|
12
10
|
testId: string;
|
|
13
11
|
/** Expectation summary */
|
|
14
12
|
expectation: string;
|
|
@@ -21,13 +19,13 @@ interface ReasoningChain {
|
|
|
21
19
|
/** Human-readable reasoning */
|
|
22
20
|
reasoning: string;
|
|
23
21
|
}
|
|
24
|
-
interface ActualChange {
|
|
22
|
+
export interface ActualChange {
|
|
25
23
|
type: string;
|
|
26
24
|
description: string;
|
|
27
25
|
path: string;
|
|
28
26
|
severity: string;
|
|
29
27
|
}
|
|
30
|
-
interface ExpectationMapping {
|
|
28
|
+
export interface ExpectationMapping {
|
|
31
29
|
expected: string;
|
|
32
30
|
actual: string | null;
|
|
33
31
|
realized: boolean;
|
|
@@ -36,6 +34,4 @@ interface ExpectationMapping {
|
|
|
36
34
|
/**
|
|
37
35
|
* Reason about whether expected changes were realized in the a11y tree diff.
|
|
38
36
|
*/
|
|
39
|
-
declare function reasonAboutChanges(testId: string, pageExp: PageExpectation, a11yDiff: A11yDiff | undefined, intent: ChangeIntent): ReasoningChain;
|
|
40
|
-
//#endregion
|
|
41
|
-
export { ActualChange, ExpectationMapping, ReasoningChain, reasonAboutChanges };
|
|
37
|
+
export declare function reasonAboutChanges(testId: string, pageExp: PageExpectation, a11yDiff: A11yDiff | undefined, intent: ChangeIntent): ReasoningChain;
|