@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.
@@ -1,14 +1,12 @@
1
1
  import { Box, ImageBudget, ZoomCoordinates } from "./zoom-geometry.mjs";
2
-
3
- //#region src/zoom-loop.d.ts
4
- type ZoomPart = {
2
+ export type ZoomPart = {
5
3
  type: "text";
6
4
  text: string;
7
5
  } | {
8
6
  type: "image";
9
7
  png: Buffer;
10
8
  };
11
- interface ZoomCall {
9
+ export interface ZoomCall {
12
10
  /** Provider call id (native), or a synthetic one (text protocol). */
13
11
  id: string;
14
12
  imageIndex: number;
@@ -16,30 +14,32 @@ interface ZoomCall {
16
14
  /** Set when the provider's arguments did not parse; the loop answers with it. */
17
15
  error?: string;
18
16
  }
19
- interface ZoomResult {
17
+ export interface ZoomResult {
20
18
  callId: string;
21
19
  /** Text first, then the magnified crop when the zoom succeeded. */
22
20
  parts: ZoomPart[];
23
21
  isError: boolean;
24
22
  }
25
- type ZoomTurn = {
23
+ export type ZoomTurn = {
26
24
  role: "user";
27
25
  parts: ZoomPart[];
28
26
  } | {
29
27
  role: "assistant";
30
28
  text: string;
31
- calls: ZoomCall[]; /** The provider's own assistant message, so a driver can replay it verbatim. */
29
+ calls: ZoomCall[];
30
+ /** The provider's own assistant message, so a driver can replay it verbatim. */
32
31
  raw?: unknown;
33
32
  } | {
34
- role: "tool"; /** True when the results answer native function calls; false for the text protocol. */
33
+ role: "tool";
34
+ /** True when the results answer native function calls; false for the text protocol. */
35
35
  native: boolean;
36
36
  results: ZoomResult[];
37
37
  };
38
- interface ZoomUsage {
38
+ export interface ZoomUsage {
39
39
  promptTokens: number;
40
40
  completionTokens: number;
41
41
  }
42
- interface DriverTurn {
42
+ export interface DriverTurn {
43
43
  text: string;
44
44
  calls: ZoomCall[];
45
45
  raw?: unknown;
@@ -47,13 +47,13 @@ interface DriverTurn {
47
47
  /** The provider stopped for its own reason (length, refusal) — not a finished answer. */
48
48
  stop?: string;
49
49
  }
50
- interface ZoomToolSpec {
50
+ export interface ZoomToolSpec {
51
51
  name: "zoom";
52
52
  description: string;
53
53
  /** JSON Schema of the arguments. */
54
54
  parameters: Record<string, unknown>;
55
55
  }
56
- interface VisionChatDriver {
56
+ export interface VisionChatDriver {
57
57
  model: string;
58
58
  /** True when the driver maps `ZoomToolSpec` onto the provider's function calling. */
59
59
  nativeTools: boolean;
@@ -63,12 +63,12 @@ interface VisionChatDriver {
63
63
  maxTokens: number;
64
64
  }): Promise<DriverTurn>;
65
65
  }
66
- interface ZoomImageInput {
66
+ export interface ZoomImageInput {
67
67
  png: Buffer;
68
68
  /** Shown before the image, e.g. "Baseline screenshot". */
69
69
  label?: string;
70
70
  }
71
- interface ZoomLoopOptions {
71
+ export interface ZoomLoopOptions {
72
72
  /** Zoom calls allowed before the model must answer (default 6). */
73
73
  maxZooms?: number;
74
74
  maxTokens?: number;
@@ -77,7 +77,7 @@ interface ZoomLoopOptions {
77
77
  /** Force the text protocol even when the driver has native tools. */
78
78
  protocol?: "native" | "text";
79
79
  }
80
- interface ZoomLoopResult {
80
+ export interface ZoomLoopResult {
81
81
  answer: string;
82
82
  zooms: {
83
83
  imageIndex: number;
@@ -97,9 +97,9 @@ interface ZoomLoopResult {
97
97
  /** Set when the provider stopped for its own reason on the last turn. */
98
98
  stop?: string;
99
99
  }
100
- declare function zoomToolSpec(imageCount: number, coordinates: ZoomCoordinates): ZoomToolSpec;
100
+ export declare function zoomToolSpec(imageCount: number, coordinates: ZoomCoordinates): ZoomToolSpec;
101
101
  /** Arguments a native call carried, whatever shape the provider gave them in. */
102
- declare function zoomCallFromArgs(id: string, args: unknown): ZoomCall | {
102
+ export declare function zoomCallFromArgs(id: string, args: unknown): ZoomCall | {
103
103
  id: string;
104
104
  error: string;
105
105
  };
@@ -107,8 +107,8 @@ declare function zoomCallFromArgs(id: string, args: unknown): ZoomCall | {
107
107
  * Zoom requests written in a reply, one `ZOOM <image> <x1> <y1> <x2> <y2>` per line. The
108
108
  * image index is always written, even with one image, so the grammar has one shape.
109
109
  */
110
- declare function parseZoomRequests(text: string, turn: number): ZoomCall[];
111
- interface SingleLookResult {
110
+ export declare function parseZoomRequests(text: string, turn: number): ZoomCall[];
111
+ export interface SingleLookResult {
112
112
  answer: string;
113
113
  usage: ZoomUsage;
114
114
  stop?: string;
@@ -119,11 +119,9 @@ interface SingleLookResult {
119
119
  * `runZoomLoop` isolates what zooming adds; comparing against a different client would also
120
120
  * measure the difference between two request builders.
121
121
  */
122
- declare function runSingleLook(driver: VisionChatDriver, images: readonly ZoomImageInput[], question: string, options?: Pick<ZoomLoopOptions, "maxTokens" | "budget" | "coordinates">): Promise<SingleLookResult>;
122
+ export declare function runSingleLook(driver: VisionChatDriver, images: readonly ZoomImageInput[], question: string, options?: Pick<ZoomLoopOptions, "maxTokens" | "budget" | "coordinates">): Promise<SingleLookResult>;
123
123
  /**
124
124
  * Run the loop. `images` are PNGs at any size; each is shown at `budget` and labelled with its
125
125
  * index and size. The answer is the model's last reply with no zoom request.
126
126
  */
127
- declare function runZoomLoop(driver: VisionChatDriver, images: readonly ZoomImageInput[], question: string, options?: ZoomLoopOptions): Promise<ZoomLoopResult>;
128
- //#endregion
129
- export { DriverTurn, SingleLookResult, VisionChatDriver, ZoomCall, ZoomImageInput, ZoomLoopOptions, ZoomLoopResult, ZoomPart, ZoomResult, ZoomToolSpec, ZoomTurn, ZoomUsage, parseZoomRequests, runSingleLook, runZoomLoop, zoomCallFromArgs, zoomToolSpec };
127
+ export declare function runZoomLoop(driver: VisionChatDriver, images: readonly ZoomImageInput[], question: string, options?: ZoomLoopOptions): Promise<ZoomLoopResult>;
@@ -1,6 +1,6 @@
1
1
  import { DEFAULT_IMAGE_BUDGET, toViewBox } from "./zoom-geometry.mjs";
2
2
  import { prepareZoomSource, zoomInto } from "./zoom-image.mjs";
3
- //#region src/zoom-loop.ts
3
+ // src/zoom-loop.ts
4
4
  /**
5
5
  * The zoom loop, independent of any provider: show the model its images at a size we chose,
6
6
  * give it one tool — `zoom(image, x1, y1, x2, y2)` — and answer each call with a magnified crop
@@ -310,5 +310,4 @@ async function runZoomLoop(driver, images, question, options = {}) {
310
310
  }
311
311
  }
312
312
  }
313
- //#endregion
314
313
  export { parseZoomRequests, runSingleLook, runZoomLoop, zoomCallFromArgs, zoomToolSpec };
package/dist/zoom.d.mts CHANGED
@@ -1,19 +1,17 @@
1
1
  import { VlmModel, VlmResponse } from "./vlm-client.mjs";
2
- import { Box, BoxProblem, DEFAULT_IMAGE_BUDGET, ImageBudget, Size, ZoomCoordinates, clampBox, fitToBudget, toViewBox, viewBoxToOriginal, zoomSize } from "./zoom-geometry.mjs";
3
2
  import { DriverTurn, SingleLookResult, VisionChatDriver, ZoomCall, ZoomImageInput, ZoomLoopOptions, ZoomLoopResult, ZoomPart, ZoomResult, ZoomToolSpec, ZoomTurn, ZoomUsage, parseZoomRequests, runSingleLook, runZoomLoop, zoomCallFromArgs, zoomToolSpec } from "./zoom-loop.mjs";
3
+ import { Box, BoxProblem, DEFAULT_IMAGE_BUDGET, ImageBudget, Size, ZoomCoordinates, clampBox, fitToBudget, toViewBox, viewBoxToOriginal, zoomSize } from "./zoom-geometry.mjs";
4
4
  import { ZoomOutcome, ZoomSource, prepareZoomSource, zoomInto } from "./zoom-image.mjs";
5
5
  import { AnthropicDriverOptions, GeminiDriverOptions, OpenAiCompatibleDriverOptions, anthropicDriver, geminiDriver, openAiCompatibleDriver } from "./zoom-drivers.mjs";
6
-
7
- //#region src/zoom.d.ts
8
- interface ZoomDriverOptions {
6
+ export interface ZoomDriverOptions {
9
7
  /** Overrides the environment key lookup, as in `createVlmClient`. */
10
8
  apiKey?: string;
11
9
  /** OpenRouter only: false for a model without function calling (the loop then uses the text protocol). */
12
10
  nativeTools?: boolean;
13
11
  }
14
12
  /** A driver for a model id, with the same key lookup and error as `createVlmClient`. */
15
- declare function createZoomDriver(model: VlmModel, options?: ZoomDriverOptions): VisionChatDriver;
16
- interface ZoomAnalysis extends VlmResponse {
13
+ export declare function createZoomDriver(model: VlmModel, options?: ZoomDriverOptions): VisionChatDriver;
14
+ export interface ZoomAnalysis extends VlmResponse {
17
15
  zoom: Omit<ZoomLoopResult, "answer" | "usage">;
18
16
  }
19
17
  /**
@@ -21,9 +19,8 @@ interface ZoomAnalysis extends VlmResponse {
21
19
  * `VlmClient` response (content, tokens, cost, latency) plus what the model zoomed into, so a
22
20
  * bench can put it beside a single-look answer.
23
21
  */
24
- declare function analyzeWithZoom(model: VlmModel, images: readonly {
22
+ export declare function analyzeWithZoom(model: VlmModel, images: readonly {
25
23
  png: Buffer;
26
24
  label?: string;
27
25
  }[], prompt: string, options?: ZoomLoopOptions & ZoomDriverOptions): Promise<ZoomAnalysis>;
28
- //#endregion
29
- export { AnthropicDriverOptions, Box, BoxProblem, DEFAULT_IMAGE_BUDGET, DriverTurn, GeminiDriverOptions, ImageBudget, OpenAiCompatibleDriverOptions, SingleLookResult, Size, VisionChatDriver, ZoomAnalysis, ZoomCall, ZoomCoordinates, ZoomDriverOptions, ZoomImageInput, ZoomLoopOptions, ZoomLoopResult, type ZoomOutcome, ZoomPart, ZoomResult, type ZoomSource, ZoomToolSpec, ZoomTurn, ZoomUsage, analyzeWithZoom, anthropicDriver, clampBox, createZoomDriver, fitToBudget, geminiDriver, openAiCompatibleDriver, parseZoomRequests, prepareZoomSource, runSingleLook, runZoomLoop, toViewBox, viewBoxToOriginal, zoomCallFromArgs, zoomInto, zoomSize, zoomToolSpec };
26
+ export { AnthropicDriverOptions, Box, BoxProblem, DEFAULT_IMAGE_BUDGET, DriverTurn, GeminiDriverOptions, ImageBudget, OpenAiCompatibleDriverOptions, SingleLookResult, Size, VisionChatDriver, ZoomCall, ZoomCoordinates, ZoomImageInput, ZoomLoopOptions, ZoomLoopResult, type ZoomOutcome, ZoomPart, ZoomResult, type ZoomSource, ZoomToolSpec, ZoomTurn, ZoomUsage, anthropicDriver, clampBox, fitToBudget, geminiDriver, openAiCompatibleDriver, parseZoomRequests, prepareZoomSource, runSingleLook, runZoomLoop, toViewBox, viewBoxToOriginal, zoomCallFromArgs, zoomInto, zoomSize, zoomToolSpec };
package/dist/zoom.mjs CHANGED
@@ -1,10 +1,10 @@
1
1
  import { VrtConfigError } from "./errors.mjs";
2
2
  import { isClaudeDirectModel, isGeminiDirectModel } from "./vlm-client.mjs";
3
+ import { anthropicDriver, geminiDriver, openAiCompatibleDriver } from "./zoom-drivers.mjs";
4
+ import { parseZoomRequests, runSingleLook, runZoomLoop, zoomCallFromArgs, zoomToolSpec } from "./zoom-loop.mjs";
3
5
  import { DEFAULT_IMAGE_BUDGET, clampBox, fitToBudget, toViewBox, viewBoxToOriginal, zoomSize } from "./zoom-geometry.mjs";
4
6
  import { prepareZoomSource, zoomInto } from "./zoom-image.mjs";
5
- import { parseZoomRequests, runSingleLook, runZoomLoop, zoomCallFromArgs, zoomToolSpec } from "./zoom-loop.mjs";
6
- import { anthropicDriver, geminiDriver, openAiCompatibleDriver } from "./zoom-drivers.mjs";
7
- //#region src/zoom.ts
7
+ // src/zoom.ts
8
8
  /**
9
9
  * Zoom for any VLM this package already knows: the model ids `createVlmClient` takes
10
10
  * (`claude:…`, `gemini:…`, an OpenRouter id) resolve to a zoom driver with the same keys, so a
@@ -45,7 +45,8 @@ function createZoomDriver(model, options = {}) {
45
45
  */
46
46
  async function analyzeWithZoom(model, images, prompt, options = {}) {
47
47
  const start = Date.now();
48
- const { answer, usage, ...zoom } = await runZoomLoop(createZoomDriver(model, options), images, prompt, options);
48
+ const driver = createZoomDriver(model, options);
49
+ const { answer, usage, ...zoom } = await runZoomLoop(driver, images, prompt, options);
49
50
  return {
50
51
  content: answer,
51
52
  model: model.id,
@@ -57,5 +58,4 @@ async function analyzeWithZoom(model, images, prompt, options = {}) {
57
58
  zoom
58
59
  };
59
60
  }
60
- //#endregion
61
61
  export { DEFAULT_IMAGE_BUDGET, analyzeWithZoom, anthropicDriver, clampBox, createZoomDriver, fitToBudget, geminiDriver, openAiCompatibleDriver, parseZoomRequests, prepareZoomSource, runSingleLook, runZoomLoop, toViewBox, viewBoxToOriginal, zoomCallFromArgs, zoomInto, zoomSize, zoomToolSpec };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mizchi/vlmkit-ai",
3
- "version": "0.23.2",
3
+ "version": "0.28.0",
4
4
  "description": "VLM / LLM clients, reasoning pipeline, and NLP helpers used by VRT to interpret diff images and natural-language intent.",
5
5
  "license": "MIT",
6
6
  "author": "mizchi",
@@ -38,10 +38,11 @@
38
38
  "dependencies": {
39
39
  "@google/generative-ai": "^0.24.1",
40
40
  "pngjs": "^7.0.0",
41
- "@mizchi/vlmkit-core": "0.23.2"
41
+ "@mizchi/vlmkit-core": "0.28.0",
42
+ "@mizchi/vlmkit-judge": "0.28.0"
42
43
  },
43
44
  "scripts": {
44
- "build": "pnpm --dir ../.. exec tsdown --config tsdown.packages.config.ts --filter @mizchi/vlmkit-ai",
45
- "test": "pnpm --dir ../.. exec vitest run packages/vlmkit-ai/src"
45
+ "build": "pnpm --dir ../.. exec vp pack --filter @mizchi/vlmkit-ai",
46
+ "test": "pnpm --dir ../.. exec vp test run packages/vlmkit-ai/src"
46
47
  }
47
48
  }