@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
package/dist/reasoning.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { STOP_WORDS, SYNONYMS } from "./nlp.mjs";
|
|
2
|
-
|
|
2
|
+
// src/reasoning.ts
|
|
3
3
|
/**
|
|
4
4
|
* Reason about whether expected changes were realized in the a11y tree diff.
|
|
5
5
|
*/
|
|
@@ -137,12 +137,11 @@ function buildReasoning(testId, expectation, mappings, sideEffects, verdict) {
|
|
|
137
137
|
lines.push("");
|
|
138
138
|
}
|
|
139
139
|
lines.push(`Verdict: ${verdict.toUpperCase()} — ${{
|
|
140
|
-
|
|
140
|
+
realized: "All expected changes were realized in the a11y tree",
|
|
141
141
|
"partially-realized": "Some expected changes were realized, but not all",
|
|
142
142
|
"not-realized": "Expected changes were not detected in the a11y tree",
|
|
143
143
|
"unexpected-side-effects": "All expected changes were realized, but additional unexpected changes were detected"
|
|
144
144
|
}[verdict]}`);
|
|
145
145
|
return lines.join("\n");
|
|
146
146
|
}
|
|
147
|
-
//#endregion
|
|
148
147
|
export { reasonAboutChanges };
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { JevClientOptions, JevResponse } from "./jev-client.mjs";
|
|
2
|
+
import { RgbaImage } from "./zoom-image.mjs";
|
|
3
|
+
export type RegionKindLabel = "text" | "color" | "position" | "presence";
|
|
4
|
+
/** The options as Jev reads them. Changing a description changes the measured accuracy: re-run the bench. */
|
|
5
|
+
export declare const REGION_KIND_OPTIONS: Record<RegionKindLabel, string>;
|
|
6
|
+
export declare const REGION_KIND_QUESTION = "How does `current` differ from `baseline`?";
|
|
7
|
+
/**
|
|
8
|
+
* Below this confidence a label is marked `uncertain`: look at the crop before acting on it.
|
|
9
|
+
* Measured on real `diff png` regions (2026-10-16): every wrong label was below it (7 of 7),
|
|
10
|
+
* and 59 of 64 right ones were at or above it. A `choice`'s confidence carries signal here,
|
|
11
|
+
* unlike a `box`'s (AUROC 0.56 in the grounding bench).
|
|
12
|
+
*/
|
|
13
|
+
export declare const REGION_KIND_SURE = 0.6;
|
|
14
|
+
export interface RegionKind {
|
|
15
|
+
label: RegionKindLabel;
|
|
16
|
+
confidence: number;
|
|
17
|
+
/** `confidence < REGION_KIND_SURE`. Shift-only regions of 1-2px are the usual case (read as colour). */
|
|
18
|
+
uncertain: boolean;
|
|
19
|
+
probabilities: Record<string, number>;
|
|
20
|
+
model: string;
|
|
21
|
+
}
|
|
22
|
+
export interface RegionBox {
|
|
23
|
+
x: number;
|
|
24
|
+
y: number;
|
|
25
|
+
width: number;
|
|
26
|
+
height: number;
|
|
27
|
+
}
|
|
28
|
+
/** A half-open box in image pixels. */
|
|
29
|
+
interface Win {
|
|
30
|
+
x1: number;
|
|
31
|
+
y1: number;
|
|
32
|
+
x2: number;
|
|
33
|
+
y2: number;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* The window both captures are cut to. The region is padded by half its size on each side
|
|
37
|
+
* (at least 16px), then grown about its centre to Jev's 280px minimum where the image allows.
|
|
38
|
+
* It is snapped to whole pixels inside the image.
|
|
39
|
+
*/
|
|
40
|
+
export declare function regionKindWindow(region: RegionBox, image: {
|
|
41
|
+
width: number;
|
|
42
|
+
height: number;
|
|
43
|
+
}): Win;
|
|
44
|
+
/**
|
|
45
|
+
* How much to magnify a window: up to 4x (the bench's setting) within Jev's limits, and at least
|
|
46
|
+
* enough to lift a short edge to 280px, past 4x if a small image needs it. Null when no scale
|
|
47
|
+
* fits both edges: a strip longer than 1568 / 280 = 5.6 times its width.
|
|
48
|
+
*/
|
|
49
|
+
export declare function regionKindScale(width: number, height: number): number | null;
|
|
50
|
+
/** The view Jev gets of one capture: the window cropped and resampled, with edges clamped into the limits. */
|
|
51
|
+
export declare function regionKindView(img: RgbaImage, win: Win, scale: number): RgbaImage;
|
|
52
|
+
export type AskRegionKind = (baseline: Uint8Array, current: Uint8Array) => Promise<RegionKind>;
|
|
53
|
+
/** The real call: one `choice` over both views. Inject another `AskRegionKind` in tests. */
|
|
54
|
+
export declare function jevRegionKindAsker(options?: JevClientOptions & {
|
|
55
|
+
model?: string;
|
|
56
|
+
onResponse?: (r: JevResponse) => void;
|
|
57
|
+
}): AskRegionKind;
|
|
58
|
+
export type RegionKindOutcome = {
|
|
59
|
+
kind: RegionKind;
|
|
60
|
+
} | {
|
|
61
|
+
skipped: string;
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* Label each region, in input order. Regions are asked in parallel (`concurrency`, default 4),
|
|
65
|
+
* one request each: a request holding several regions' crops would pass Jev's 64k context.
|
|
66
|
+
* One region that fails is reported with its reason and leaves the others labelled.
|
|
67
|
+
*/
|
|
68
|
+
export declare function labelRegionKinds(baseline: RgbaImage, current: RgbaImage, regions: readonly RegionBox[], ask: AskRegionKind, concurrency?: number): Promise<RegionKindOutcome[]>;
|
|
69
|
+
export {};
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { JEV_IMAGE_LIMITS, askJev, pngImage } from "./jev-client.mjs";
|
|
2
|
+
import { cropImage, encodePngImage, resample } from "./zoom-image.mjs";
|
|
3
|
+
// src/region-kind.ts
|
|
4
|
+
/**
|
|
5
|
+
* Name what changed in a pixel-diff region: text, colour, position, or presence.
|
|
6
|
+
*
|
|
7
|
+
* The pixel diff has already found WHERE, deterministically. This asks Jev only WHAT, on both
|
|
8
|
+
* captures cut to the region and magnified, as one typed `choice`. The split is the point. In
|
|
9
|
+
* `diff region` (deprecated) a VLM was asked for the regions and the values too, and fabricated
|
|
10
|
+
* both. Here the region and every value (shift, colours) stay the pixels', and the label is one
|
|
11
|
+
* that a person can check against the crop.
|
|
12
|
+
*
|
|
13
|
+
* Measured 2026-10-16 (`docs/reports/2026-10-16-jev-box-bench.md`, and the end-to-end round on
|
|
14
|
+
* real `diff png` regions in `…-jev-region-kind.md`). Do not take a shift's direction from here:
|
|
15
|
+
* Jev got it 8/16 on the crop, and `region.shift` measures it.
|
|
16
|
+
*/
|
|
17
|
+
/** The options as Jev reads them. Changing a description changes the measured accuracy: re-run the bench. */
|
|
18
|
+
const REGION_KIND_OPTIONS = {
|
|
19
|
+
text: "A character or word of text is different",
|
|
20
|
+
color: "A colour is different (text, fill or border); the shapes are the same",
|
|
21
|
+
position: "Something moved: the same content sits a few pixels away from where it was",
|
|
22
|
+
presence: "Something appeared or disappeared: content is in one image and missing from the other"
|
|
23
|
+
};
|
|
24
|
+
const REGION_KIND_QUESTION = "How does `current` differ from `baseline`?";
|
|
25
|
+
/**
|
|
26
|
+
* Below this confidence a label is marked `uncertain`: look at the crop before acting on it.
|
|
27
|
+
* Measured on real `diff png` regions (2026-10-16): every wrong label was below it (7 of 7),
|
|
28
|
+
* and 59 of 64 right ones were at or above it. A `choice`'s confidence carries signal here,
|
|
29
|
+
* unlike a `box`'s (AUROC 0.56 in the grounding bench).
|
|
30
|
+
*/
|
|
31
|
+
const REGION_KIND_SURE = .6;
|
|
32
|
+
/**
|
|
33
|
+
* The window both captures are cut to. The region is padded by half its size on each side
|
|
34
|
+
* (at least 16px), then grown about its centre to Jev's 280px minimum where the image allows.
|
|
35
|
+
* It is snapped to whole pixels inside the image.
|
|
36
|
+
*/
|
|
37
|
+
function regionKindWindow(region, image) {
|
|
38
|
+
const grow = (lo, size, limit) => {
|
|
39
|
+
const pad = Math.max(16, size * .5);
|
|
40
|
+
let a = lo - pad;
|
|
41
|
+
let z = lo + size + pad;
|
|
42
|
+
const need = Math.max(0, JEV_IMAGE_LIMITS.minEdge - (z - a));
|
|
43
|
+
a -= need / 2;
|
|
44
|
+
z += need / 2;
|
|
45
|
+
if (a < 0) [a, z] = [0, z - a];
|
|
46
|
+
if (z > limit) [a, z] = [Math.max(0, a - (z - limit)), limit];
|
|
47
|
+
return [Math.max(0, Math.floor(a)), Math.min(limit, Math.ceil(z))];
|
|
48
|
+
};
|
|
49
|
+
const [x1, x2] = grow(region.x, region.width, image.width);
|
|
50
|
+
const [y1, y2] = grow(region.y, region.height, image.height);
|
|
51
|
+
return {
|
|
52
|
+
x1,
|
|
53
|
+
y1,
|
|
54
|
+
x2,
|
|
55
|
+
y2
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* How much to magnify a window: up to 4x (the bench's setting) within Jev's limits, and at least
|
|
60
|
+
* enough to lift a short edge to 280px, past 4x if a small image needs it. Null when no scale
|
|
61
|
+
* fits both edges: a strip longer than 1568 / 280 = 5.6 times its width.
|
|
62
|
+
*/
|
|
63
|
+
function regionKindScale(width, height) {
|
|
64
|
+
const L = JEV_IMAGE_LIMITS;
|
|
65
|
+
const limit = Math.min(L.maxEdge / Math.max(width, height), Math.sqrt(L.maxPixels / (width * height)));
|
|
66
|
+
const min = L.minEdge / Math.min(width, height);
|
|
67
|
+
if (min > limit + 1e-9) return null;
|
|
68
|
+
return Math.max(min, Math.min(4, limit));
|
|
69
|
+
}
|
|
70
|
+
/** The view Jev gets of one capture: the window cropped and resampled, with edges clamped into the limits. */
|
|
71
|
+
function regionKindView(img, win, scale) {
|
|
72
|
+
const L = JEV_IMAGE_LIMITS;
|
|
73
|
+
const crop = cropImage(img, win);
|
|
74
|
+
const size = (n) => Math.min(L.maxEdge, Math.max(L.minEdge, Math.round(n * scale)));
|
|
75
|
+
return resample(crop, {
|
|
76
|
+
width: size(crop.width),
|
|
77
|
+
height: size(crop.height)
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
/** The real call: one `choice` over both views. Inject another `AskRegionKind` in tests. */
|
|
81
|
+
function jevRegionKindAsker(options = {}) {
|
|
82
|
+
return async (baseline, current) => {
|
|
83
|
+
const r = await askJev({
|
|
84
|
+
model: options.model ?? "jev-1.14.0",
|
|
85
|
+
state: {
|
|
86
|
+
baseline: "BASE",
|
|
87
|
+
current: "CUR"
|
|
88
|
+
},
|
|
89
|
+
assets: {
|
|
90
|
+
BASE: pngImage(baseline),
|
|
91
|
+
CUR: pngImage(current)
|
|
92
|
+
},
|
|
93
|
+
questions: { kind: {
|
|
94
|
+
type: "choice",
|
|
95
|
+
instructions: REGION_KIND_QUESTION,
|
|
96
|
+
criteria: { ...REGION_KIND_OPTIONS }
|
|
97
|
+
} }
|
|
98
|
+
}, options);
|
|
99
|
+
options.onResponse?.(r);
|
|
100
|
+
const a = r.answers.kind;
|
|
101
|
+
return {
|
|
102
|
+
label: a.choice,
|
|
103
|
+
confidence: a.confidence,
|
|
104
|
+
uncertain: a.confidence < REGION_KIND_SURE,
|
|
105
|
+
probabilities: a.probabilities,
|
|
106
|
+
model: r.model
|
|
107
|
+
};
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Label each region, in input order. Regions are asked in parallel (`concurrency`, default 4),
|
|
112
|
+
* one request each: a request holding several regions' crops would pass Jev's 64k context.
|
|
113
|
+
* One region that fails is reported with its reason and leaves the others labelled.
|
|
114
|
+
*/
|
|
115
|
+
async function labelRegionKinds(baseline, current, regions, ask, concurrency = 4) {
|
|
116
|
+
if (baseline.width !== current.width || baseline.height !== current.height) return regions.map(() => ({ skipped: `capture sizes differ (${baseline.width}x${baseline.height} vs ${current.width}x${current.height})` }));
|
|
117
|
+
const out = new Array(regions.length);
|
|
118
|
+
let next = 0;
|
|
119
|
+
const worker = async () => {
|
|
120
|
+
while (next < regions.length) {
|
|
121
|
+
const i = next++;
|
|
122
|
+
const win = regionKindWindow(regions[i], baseline);
|
|
123
|
+
const scale = regionKindScale(win.x2 - win.x1, win.y2 - win.y1);
|
|
124
|
+
if (scale === null) {
|
|
125
|
+
out[i] = { skipped: `window ${win.x2 - win.x1}x${win.y2 - win.y1} cannot fit Jev's 280-1568px edges` };
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
try {
|
|
129
|
+
const kind = await ask(encodePngImage(regionKindView(baseline, win, scale)), encodePngImage(regionKindView(current, win, scale)));
|
|
130
|
+
out[i] = { kind };
|
|
131
|
+
} catch (error) {
|
|
132
|
+
out[i] = { skipped: error.message.slice(0, 300) };
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
await Promise.all(Array.from({ length: Math.min(concurrency, regions.length) }, worker));
|
|
137
|
+
return out;
|
|
138
|
+
}
|
|
139
|
+
export { REGION_KIND_OPTIONS, REGION_KIND_QUESTION, REGION_KIND_SURE, jevRegionKindAsker, labelRegionKinds, regionKindScale, regionKindView, regionKindWindow };
|
package/dist/vlm-client.d.mts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
interface VlmModel {
|
|
1
|
+
export interface VlmModel {
|
|
3
2
|
id: string;
|
|
4
3
|
name: string;
|
|
5
4
|
promptCostPer1k: number;
|
|
@@ -7,7 +6,7 @@ interface VlmModel {
|
|
|
7
6
|
contextLength: number;
|
|
8
7
|
modality: string;
|
|
9
8
|
}
|
|
10
|
-
interface VlmResponse {
|
|
9
|
+
export interface VlmResponse {
|
|
11
10
|
content: string;
|
|
12
11
|
model: string;
|
|
13
12
|
promptTokens: number;
|
|
@@ -16,7 +15,7 @@ interface VlmResponse {
|
|
|
16
15
|
costUsd: number;
|
|
17
16
|
latencyMs: number;
|
|
18
17
|
}
|
|
19
|
-
interface VlmClient {
|
|
18
|
+
export interface VlmClient {
|
|
20
19
|
model: VlmModel;
|
|
21
20
|
analyzeImage(imageBase64: string, prompt: string, options?: {
|
|
22
21
|
maxTokens?: number;
|
|
@@ -36,22 +35,22 @@ interface VlmClient {
|
|
|
36
35
|
* invisible to them until restart. Named after `resetGateRegistryCache`, which exists for the
|
|
37
36
|
* same reason on the same kind of lazily-built module state.
|
|
38
37
|
*/
|
|
39
|
-
declare function resetVisionModelCache(): void;
|
|
40
|
-
declare function fetchVisionModels(): Promise<VlmModel[]>;
|
|
41
|
-
declare function listModels(options?: {
|
|
38
|
+
export declare function resetVisionModelCache(): void;
|
|
39
|
+
export declare function fetchVisionModels(): Promise<VlmModel[]>;
|
|
40
|
+
export declare function listModels(options?: {
|
|
42
41
|
maxCost?: number;
|
|
43
42
|
limit?: number;
|
|
44
43
|
includeGemini?: boolean;
|
|
45
44
|
includeClaude?: boolean;
|
|
46
45
|
}): Promise<VlmModel[]>;
|
|
47
|
-
declare function resolveModel(idOrIndex: string): Promise<VlmModel>;
|
|
48
|
-
declare function isGeminiDirectModel(id: string): boolean;
|
|
49
|
-
declare function resolveGeminiModel(id: string): VlmModel | undefined;
|
|
50
|
-
declare function listGeminiModels(): VlmModel[];
|
|
51
|
-
declare function isClaudeDirectModel(id: string): boolean;
|
|
52
|
-
declare function resolveClaudeModel(id: string): VlmModel | undefined;
|
|
53
|
-
declare function listClaudeModels(): VlmModel[];
|
|
54
|
-
interface CreateVlmClientOptions {
|
|
46
|
+
export declare function resolveModel(idOrIndex: string): Promise<VlmModel>;
|
|
47
|
+
export declare function isGeminiDirectModel(id: string): boolean;
|
|
48
|
+
export declare function resolveGeminiModel(id: string): VlmModel | undefined;
|
|
49
|
+
export declare function listGeminiModels(): VlmModel[];
|
|
50
|
+
export declare function isClaudeDirectModel(id: string): boolean;
|
|
51
|
+
export declare function resolveClaudeModel(id: string): VlmModel | undefined;
|
|
52
|
+
export declare function listClaudeModels(): VlmModel[];
|
|
53
|
+
export interface CreateVlmClientOptions {
|
|
55
54
|
/** Override `OPENROUTER_API_KEY` / `GEMINI_API_KEY` lookup. */
|
|
56
55
|
apiKey?: string;
|
|
57
56
|
/**
|
|
@@ -67,6 +66,4 @@ interface CreateVlmClientOptions {
|
|
|
67
66
|
* required API key isn't set in the environment. Pass
|
|
68
67
|
* `{ throwIfMissing: false }` for the legacy `T | null` return.
|
|
69
68
|
*/
|
|
70
|
-
declare function createVlmClient(model: VlmModel, options?: CreateVlmClientOptions): Promise<VlmClient | null>;
|
|
71
|
-
//#endregion
|
|
72
|
-
export { CreateVlmClientOptions, VlmClient, VlmModel, VlmResponse, createVlmClient, fetchVisionModels, isClaudeDirectModel, isGeminiDirectModel, listClaudeModels, listGeminiModels, listModels, resetVisionModelCache, resolveClaudeModel, resolveGeminiModel, resolveModel };
|
|
69
|
+
export declare function createVlmClient(model: VlmModel, options?: CreateVlmClientOptions): Promise<VlmClient | null>;
|
package/dist/vlm-client.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { VrtConfigError } from "./errors.mjs";
|
|
2
2
|
import { readFile } from "node:fs/promises";
|
|
3
|
-
|
|
3
|
+
// src/vlm-client.ts
|
|
4
4
|
/**
|
|
5
5
|
* VLM (Vision Language Model) client
|
|
6
6
|
*
|
|
@@ -63,7 +63,8 @@ async function resolveModel(idOrIndex) {
|
|
|
63
63
|
if (partial.length > 1) {
|
|
64
64
|
const segmentMatches = partial.filter((m) => m.id.split("/").includes(idOrIndex));
|
|
65
65
|
if (segmentMatches.length === 1) return segmentMatches[0];
|
|
66
|
-
|
|
66
|
+
const shown = (segmentMatches.length > 1 ? segmentMatches : partial).slice(0, 5).map((m) => m.id).join(", ");
|
|
67
|
+
throw new VrtConfigError("MULTIPLE_MATCHES", `Ambiguous model "${idOrIndex}". Matches: ${shown}\nTip: use more specific ID, e.g. "${(segmentMatches[0] ?? partial[0]).id}"`);
|
|
67
68
|
}
|
|
68
69
|
const idx = parseInt(idOrIndex, 10);
|
|
69
70
|
if (!isNaN(idx) && idx >= 0 && idx < models.length) return models[idx];
|
|
@@ -357,7 +358,7 @@ async function createVlmClient(model, options) {
|
|
|
357
358
|
method: "POST",
|
|
358
359
|
headers: {
|
|
359
360
|
"Content-Type": "application/json",
|
|
360
|
-
|
|
361
|
+
Authorization: `Bearer ${key}`,
|
|
361
362
|
"HTTP-Referer": "https://github.com/mizchi/vrt",
|
|
362
363
|
"X-Title": "vrt"
|
|
363
364
|
},
|
|
@@ -436,5 +437,4 @@ async function createVlmClient(model, options) {
|
|
|
436
437
|
};
|
|
437
438
|
return orClient;
|
|
438
439
|
}
|
|
439
|
-
//#endregion
|
|
440
440
|
export { createVlmClient, fetchVisionModels, isClaudeDirectModel, isGeminiDirectModel, listClaudeModels, listGeminiModels, listModels, resetVisionModelCache, resolveClaudeModel, resolveGeminiModel, resolveModel };
|
package/dist/zoom-drivers.d.mts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { VisionChatDriver, ZoomToolSpec } from "./zoom-loop.mjs";
|
|
2
|
-
|
|
3
|
-
//#region src/zoom-drivers.d.ts
|
|
4
2
|
type Fetch = typeof fetch;
|
|
5
|
-
interface OpenAiCompatibleDriverOptions {
|
|
3
|
+
export interface OpenAiCompatibleDriverOptions {
|
|
6
4
|
model: string;
|
|
7
5
|
apiKey?: string;
|
|
8
6
|
/** Chat Completions URL (default OpenRouter's). */
|
|
@@ -12,22 +10,21 @@ interface OpenAiCompatibleDriverOptions {
|
|
|
12
10
|
nativeTools?: boolean;
|
|
13
11
|
fetch?: Fetch;
|
|
14
12
|
}
|
|
15
|
-
declare function openAiCompatibleDriver(options: OpenAiCompatibleDriverOptions): VisionChatDriver;
|
|
16
|
-
interface AnthropicDriverOptions {
|
|
13
|
+
export declare function openAiCompatibleDriver(options: OpenAiCompatibleDriverOptions): VisionChatDriver;
|
|
14
|
+
export interface AnthropicDriverOptions {
|
|
17
15
|
model: string;
|
|
18
16
|
apiKey: string;
|
|
19
17
|
/** Default https://api.anthropic.com (or ANTHROPIC_BASE_URL when the caller passes it). */
|
|
20
18
|
baseUrl?: string;
|
|
21
19
|
fetch?: Fetch;
|
|
22
20
|
}
|
|
23
|
-
declare function anthropicDriver(options: AnthropicDriverOptions): VisionChatDriver;
|
|
24
|
-
interface GeminiDriverOptions {
|
|
21
|
+
export declare function anthropicDriver(options: AnthropicDriverOptions): VisionChatDriver;
|
|
22
|
+
export interface GeminiDriverOptions {
|
|
25
23
|
/** e.g. `gemini-2.5-flash` (no `gemini:` prefix). */
|
|
26
24
|
model: string;
|
|
27
25
|
apiKey: string;
|
|
28
26
|
baseUrl?: string;
|
|
29
27
|
fetch?: Fetch;
|
|
30
28
|
}
|
|
31
|
-
declare function geminiDriver(options: GeminiDriverOptions): VisionChatDriver;
|
|
32
|
-
|
|
33
|
-
export { AnthropicDriverOptions, GeminiDriverOptions, OpenAiCompatibleDriverOptions, type ZoomToolSpec, anthropicDriver, geminiDriver, openAiCompatibleDriver };
|
|
29
|
+
export declare function geminiDriver(options: GeminiDriverOptions): VisionChatDriver;
|
|
30
|
+
export type { ZoomToolSpec };
|
package/dist/zoom-drivers.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { zoomCallFromArgs } from "./zoom-loop.mjs";
|
|
2
|
-
|
|
2
|
+
// src/zoom-drivers.ts
|
|
3
3
|
async function postJson(fetcher, url, headers, body, provider) {
|
|
4
4
|
const res = await fetcher(url, {
|
|
5
5
|
method: "POST",
|
|
@@ -312,5 +312,4 @@ function withBroken(turn, broken) {
|
|
|
312
312
|
}))]
|
|
313
313
|
};
|
|
314
314
|
}
|
|
315
|
-
//#endregion
|
|
316
315
|
export { anthropicDriver, geminiDriver, openAiCompatibleDriver };
|
package/dist/zoom-geometry.d.mts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
//#region src/zoom-geometry.d.ts
|
|
2
1
|
/**
|
|
3
2
|
* The arithmetic of letting a vision model zoom: which size it sees, which pixels a box it
|
|
4
3
|
* names refers to, and how large the magnified crop comes back. Pure — no image bytes here.
|
|
@@ -14,7 +13,7 @@
|
|
|
14
13
|
* (`viewBoxToOriginal`) — the crop always comes from the original, never from the view.
|
|
15
14
|
*/
|
|
16
15
|
/** How large an image one message may carry. Providers differ; stay under all of them. */
|
|
17
|
-
interface ImageBudget {
|
|
16
|
+
export interface ImageBudget {
|
|
18
17
|
/** Longest edge, px. */
|
|
19
18
|
maxEdge: number;
|
|
20
19
|
/** Width × height, px². Tile-counting providers bill by area; this bounds the bill too. */
|
|
@@ -28,22 +27,22 @@ interface ImageBudget {
|
|
|
28
27
|
* (`coordinates: "normalized"`, 0–1000 on each axis), invariant to any resize. Pass a budget
|
|
29
28
|
* that matches the model you use; nothing here assumes this one.
|
|
30
29
|
*/
|
|
31
|
-
declare const DEFAULT_IMAGE_BUDGET: ImageBudget;
|
|
30
|
+
export declare const DEFAULT_IMAGE_BUDGET: ImageBudget;
|
|
32
31
|
/**
|
|
33
32
|
* How the model states a box. `pixels`: absolute pixels of the view it was shown (the cookbook's
|
|
34
33
|
* form; exact when the provider does not resize the view again). `normalized`: 0–1000 of the
|
|
35
34
|
* view's width and height, the form several vision models are trained to emit for boxes, and
|
|
36
35
|
* correct whatever size the provider actually showed the model.
|
|
37
36
|
*/
|
|
38
|
-
type ZoomCoordinates = "pixels" | "normalized";
|
|
37
|
+
export type ZoomCoordinates = "pixels" | "normalized";
|
|
39
38
|
/** A box as the model stated it, in the view's pixel space. */
|
|
40
|
-
declare function toViewBox(box: Box, view: Size, coordinates: ZoomCoordinates): Box;
|
|
41
|
-
interface Size {
|
|
39
|
+
export declare function toViewBox(box: Box, view: Size, coordinates: ZoomCoordinates): Box;
|
|
40
|
+
export interface Size {
|
|
42
41
|
width: number;
|
|
43
42
|
height: number;
|
|
44
43
|
}
|
|
45
44
|
/** A box in some image's pixel space, x2 > x1 and y2 > y1 (half-open: x1 <= x < x2). */
|
|
46
|
-
interface Box {
|
|
45
|
+
export interface Box {
|
|
47
46
|
x1: number;
|
|
48
47
|
y1: number;
|
|
49
48
|
x2: number;
|
|
@@ -53,15 +52,15 @@ interface Box {
|
|
|
53
52
|
* The largest aspect-preserving size within the budget, never larger than the input. An image
|
|
54
53
|
* that already fits is returned unchanged, so a small screenshot is shown at 1:1.
|
|
55
54
|
*/
|
|
56
|
-
declare function fitToBudget(size: Size, budget?: ImageBudget): Size;
|
|
55
|
+
export declare function fitToBudget(size: Size, budget?: ImageBudget): Size;
|
|
57
56
|
/**
|
|
58
57
|
* The size a crop is magnified to: the largest aspect-preserving size within the budget, even
|
|
59
58
|
* when that means enlarging it — a 60×20 region comes back filling the budget, which is the
|
|
60
59
|
* point. (Magnifying past the original's own pixels adds no detail, but it does make each
|
|
61
60
|
* original pixel several of the model's, which is what lets it read an 8px gap.)
|
|
62
61
|
*/
|
|
63
|
-
declare function zoomSize(crop: Size, budget?: ImageBudget): Size;
|
|
64
|
-
type BoxProblem = {
|
|
62
|
+
export declare function zoomSize(crop: Size, budget?: ImageBudget): Size;
|
|
63
|
+
export type BoxProblem = {
|
|
65
64
|
ok: false;
|
|
66
65
|
reason: string;
|
|
67
66
|
};
|
|
@@ -71,7 +70,7 @@ type BoxProblem = {
|
|
|
71
70
|
* reading. A box that is empty after clamping is an error the model is told about, so it can
|
|
72
71
|
* try again, rather than a crash.
|
|
73
72
|
*/
|
|
74
|
-
declare function clampBox(box: Box, view: Size): {
|
|
73
|
+
export declare function clampBox(box: Box, view: Size): {
|
|
75
74
|
ok: true;
|
|
76
75
|
box: Box;
|
|
77
76
|
} | BoxProblem;
|
|
@@ -80,6 +79,4 @@ declare function clampBox(box: Box, view: Size): {
|
|
|
80
79
|
* size is not an exact multiple of the original's), rounds outward so a 1px feature on the
|
|
81
80
|
* box's edge is kept, and never returns an empty box.
|
|
82
81
|
*/
|
|
83
|
-
declare function viewBoxToOriginal(box: Box, view: Size, original: Size): Box;
|
|
84
|
-
//#endregion
|
|
85
|
-
export { Box, BoxProblem, DEFAULT_IMAGE_BUDGET, ImageBudget, Size, ZoomCoordinates, clampBox, fitToBudget, toViewBox, viewBoxToOriginal, zoomSize };
|
|
82
|
+
export declare function viewBoxToOriginal(box: Box, view: Size, original: Size): Box;
|
package/dist/zoom-geometry.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// src/zoom-geometry.ts
|
|
2
2
|
/**
|
|
3
3
|
* 1568px on the long edge and about 1.15 megapixels: the size below which Anthropic documents
|
|
4
4
|
* that it does not resize. Other providers resize by their own rules (OpenAI's high-detail path
|
|
@@ -99,5 +99,4 @@ function viewBoxToOriginal(box, view, original) {
|
|
|
99
99
|
y2: Math.min(original.height, Math.max(y1 + 1, Math.ceil(box.y2 * sy)))
|
|
100
100
|
};
|
|
101
101
|
}
|
|
102
|
-
//#endregion
|
|
103
102
|
export { DEFAULT_IMAGE_BUDGET, clampBox, fitToBudget, toViewBox, viewBoxToOriginal, zoomSize };
|
package/dist/zoom-image.d.mts
CHANGED
|
@@ -1,32 +1,34 @@
|
|
|
1
1
|
import { Box, ImageBudget, Size } from "./zoom-geometry.mjs";
|
|
2
|
-
|
|
3
|
-
//#region src/zoom-image.d.ts
|
|
4
|
-
interface RgbaImage {
|
|
2
|
+
export interface RgbaImage {
|
|
5
3
|
width: number;
|
|
6
4
|
height: number;
|
|
7
5
|
/** RGBA, row-major, 4 bytes per pixel, alpha always 255 after decode. */
|
|
8
6
|
data: Uint8Array;
|
|
9
7
|
}
|
|
10
8
|
/** Decode a PNG and flatten it onto white. Anything else is refused with the reason. */
|
|
11
|
-
declare function decodeImage(buf: Buffer): RgbaImage;
|
|
12
|
-
declare function encodePngImage(img: RgbaImage): Buffer;
|
|
13
|
-
declare function cropImage(img: RgbaImage, box: Box): RgbaImage;
|
|
9
|
+
export declare function decodeImage(buf: Buffer): RgbaImage;
|
|
10
|
+
export declare function encodePngImage(img: RgbaImage): Buffer;
|
|
11
|
+
export declare function cropImage(img: RgbaImage, box: Box): RgbaImage;
|
|
14
12
|
/** Resize to exactly `size`: area-average on each axis that shrinks, bilinear on one that grows. */
|
|
15
|
-
declare function resample(img: RgbaImage, size: Size): RgbaImage;
|
|
13
|
+
export declare function resample(img: RgbaImage, size: Size): RgbaImage;
|
|
16
14
|
/** One image as the zoom loop holds it: the full-resolution original and the view the model sees. */
|
|
17
|
-
interface ZoomSource {
|
|
15
|
+
export interface ZoomSource {
|
|
18
16
|
original: RgbaImage;
|
|
19
17
|
view: RgbaImage;
|
|
20
18
|
/** The view, encoded — what is actually sent. */
|
|
21
19
|
viewPng: Buffer;
|
|
22
20
|
}
|
|
23
|
-
declare function prepareZoomSource(png: Buffer, budget?: ImageBudget): ZoomSource;
|
|
24
|
-
type ZoomOutcome = {
|
|
25
|
-
ok: true;
|
|
26
|
-
|
|
27
|
-
|
|
21
|
+
export declare function prepareZoomSource(png: Buffer, budget?: ImageBudget): ZoomSource;
|
|
22
|
+
export type ZoomOutcome = {
|
|
23
|
+
ok: true;
|
|
24
|
+
/** The box in view pixels after clamping. */
|
|
25
|
+
viewBox: Box;
|
|
26
|
+
/** The original's pixels that were cropped. */
|
|
27
|
+
originalBox: Box;
|
|
28
|
+
/** The magnified crop, encoded. */
|
|
28
29
|
png: Buffer;
|
|
29
|
-
size: Size;
|
|
30
|
+
size: Size;
|
|
31
|
+
/** What to tell the model alongside the image. */
|
|
30
32
|
text: string;
|
|
31
33
|
} | {
|
|
32
34
|
ok: false;
|
|
@@ -37,6 +39,4 @@ type ZoomOutcome = {
|
|
|
37
39
|
* spaces, so the model can place what it sees in the zoom back onto the view it is reasoning
|
|
38
40
|
* about ("…a 180x60px region of the original, returned at 1568x522px").
|
|
39
41
|
*/
|
|
40
|
-
declare function zoomInto(source: ZoomSource, box: Box, budget?: ImageBudget): ZoomOutcome;
|
|
41
|
-
//#endregion
|
|
42
|
-
export { RgbaImage, ZoomOutcome, ZoomSource, cropImage, decodeImage, encodePngImage, prepareZoomSource, resample, zoomInto };
|
|
42
|
+
export declare function zoomInto(source: ZoomSource, box: Box, budget?: ImageBudget): ZoomOutcome;
|
package/dist/zoom-image.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DEFAULT_IMAGE_BUDGET, clampBox, fitToBudget, viewBoxToOriginal, zoomSize } from "./zoom-geometry.mjs";
|
|
2
2
|
import { PNG } from "pngjs";
|
|
3
|
-
|
|
3
|
+
// src/zoom-image.ts
|
|
4
4
|
/**
|
|
5
5
|
* The image half of zooming: make the view the model sees, and cut and magnify a region of
|
|
6
6
|
* the original when it asks. PNG in, PNG out, through `pngjs` only, so no native image library
|
|
@@ -143,5 +143,4 @@ function zoomInto(source, box, budget = DEFAULT_IMAGE_BUDGET) {
|
|
|
143
143
|
text: `Zoomed into (${b.x1},${b.y1})-(${b.x2},${b.y2}) of the image you see at ${source.view.width}x${source.view.height}px: a ${crop.width}x${crop.height}px region of the original, returned magnified to ${size.width}x${size.height}px.`
|
|
144
144
|
};
|
|
145
145
|
}
|
|
146
|
-
//#endregion
|
|
147
146
|
export { cropImage, decodeImage, encodePngImage, prepareZoomSource, resample, zoomInto };
|