@mizchi/vlmkit-ai 0.23.2 → 0.24.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 +36 -0
- package/dist/claims.mjs +67 -0
- package/dist/errors.d.mts +17 -4
- package/dist/image-gen-client.d.mts +25 -25
- package/dist/image-gen-client.mjs +4 -4
- package/dist/index.mjs +1 -1
- package/dist/intent.d.mts +7 -9
- package/dist/intent.mjs +1 -1
- package/dist/jev-client.d.mts +133 -0
- package/dist/jev-client.mjs +147 -0
- package/dist/llm-client.d.mts +12 -14
- package/dist/llm-client.mjs +8 -5
- package/dist/locate.d.mts +68 -0
- package/dist/locate.mjs +159 -0
- package/dist/motion-check.d.mts +156 -0
- package/dist/motion-check.mjs +250 -0
- package/dist/nlp.d.mts +3 -4
- package/dist/nlp.mjs +1 -1
- package/dist/reasoning-pipeline.d.mts +13 -13
- package/dist/reasoning-pipeline.mjs +2 -1
- package/dist/reasoning.d.mts +5 -7
- package/dist/reasoning.mjs +1 -1
- package/dist/region-kind.d.mts +70 -0
- package/dist/region-kind.mjs +140 -0
- package/dist/vlm-client.d.mts +16 -17
- package/dist/vlm-client.mjs +3 -2
- package/dist/zoom-drivers.d.mts +7 -8
- package/dist/zoom-geometry.d.mts +12 -13
- package/dist/zoom-image.d.mts +18 -16
- package/dist/zoom-loop.d.mts +22 -22
- package/dist/zoom.d.mts +5 -6
- package/dist/zoom.mjs +4 -3
- package/package.json +5 -4
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { JevClientOptions } from "./jev-client.mjs";
|
|
2
|
+
import { JevAsk } from "./locate.mjs";
|
|
3
|
+
//#region src/claims.d.ts
|
|
4
|
+
export type ClaimExpectation = "shown" | "absent";
|
|
5
|
+
export interface Claim {
|
|
6
|
+
/** What the screenshot shows, as a statement: "an error message", "a modal dialog open over the page". */
|
|
7
|
+
statement: string;
|
|
8
|
+
expect: ClaimExpectation;
|
|
9
|
+
}
|
|
10
|
+
export interface ClaimResult extends Claim {
|
|
11
|
+
/** Jev's probability that the screenshot shows it (0-1). */
|
|
12
|
+
noul: number;
|
|
13
|
+
pass: boolean;
|
|
14
|
+
/** Within `uncertainBand` of the threshold: look at the screenshot before acting on it. */
|
|
15
|
+
uncertain: boolean;
|
|
16
|
+
}
|
|
17
|
+
export interface ClaimsReport {
|
|
18
|
+
results: ClaimResult[];
|
|
19
|
+
passed: boolean;
|
|
20
|
+
model: string;
|
|
21
|
+
costUsd: number;
|
|
22
|
+
inputTokens: number;
|
|
23
|
+
}
|
|
24
|
+
export interface ClaimsOptions {
|
|
25
|
+
/** A claim is true at or above this (default 0.5). */
|
|
26
|
+
threshold?: number;
|
|
27
|
+
/** Distance from the threshold under which a result is `uncertain` (default 0.3). */
|
|
28
|
+
uncertainBand?: number;
|
|
29
|
+
model?: string;
|
|
30
|
+
ask?: JevAsk;
|
|
31
|
+
client?: JevClientOptions;
|
|
32
|
+
}
|
|
33
|
+
/** "an error message" → "`screenshot` shows an error message." A statement already starting with "shows" is kept. */
|
|
34
|
+
export declare function claimInstruction(statement: string): string;
|
|
35
|
+
export declare function checkClaims(png: Uint8Array, claims: readonly Claim[], options?: ClaimsOptions): Promise<ClaimsReport>;
|
|
36
|
+
//#endregion
|
package/dist/claims.mjs
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { JEV_IMAGE_LIMITS, askJev, pngImage } from "./jev-client.mjs";
|
|
2
|
+
import { decodeImage, encodePngImage, resample } from "./zoom-image.mjs";
|
|
3
|
+
import { firstLookScale } from "./locate.mjs";
|
|
4
|
+
//#region src/claims.ts
|
|
5
|
+
/**
|
|
6
|
+
* Cheap typed checks on a screenshot: statements a page must or must not make visible ("shows
|
|
7
|
+
* an error message", "shows a modal dialog open over the page"), each answered by Jev as a
|
|
8
|
+
* `noul` (the probability the statement is true), no prose to parse.
|
|
9
|
+
*
|
|
10
|
+
* All claims share one request and one image: Jev reads the image once and each further question
|
|
11
|
+
* costs about 20 tokens, so ten claims on a 1280x800 screenshot are about $0.00014 and 0.2s.
|
|
12
|
+
*
|
|
13
|
+
* Advisory, not a gate. The deterministic gates measure; this asks a model what a person would
|
|
14
|
+
* notice at a glance. Measured 2026-10-17 (`docs/reports/2026-10-17-jev-claims.md`) — read its
|
|
15
|
+
* per-claim false-alarm rates before trusting a claim worded differently.
|
|
16
|
+
*/
|
|
17
|
+
/** "an error message" → "`screenshot` shows an error message." A statement already starting with "shows" is kept. */
|
|
18
|
+
function claimInstruction(statement) {
|
|
19
|
+
const s = statement.trim().replace(/[.\s]+$/, "").replace(/^(the\s+)?(screenshot|page|screen)\s+/i, "");
|
|
20
|
+
return /^(shows|contains|has|displays)\b/i.test(s) ? `\`screenshot\` ${s}.` : `\`screenshot\` shows ${s}.`;
|
|
21
|
+
}
|
|
22
|
+
async function checkClaims(png, claims, options = {}) {
|
|
23
|
+
if (claims.length === 0) throw new Error("no claims to check");
|
|
24
|
+
const ask = options.ask ?? ((req) => askJev(req, options.client));
|
|
25
|
+
const threshold = options.threshold ?? .5;
|
|
26
|
+
const band = options.uncertainBand ?? .3;
|
|
27
|
+
const img = decodeImage(Buffer.from(png));
|
|
28
|
+
const scale = firstLookScale(img.width, img.height);
|
|
29
|
+
if (scale === null) throw new Error(`${img.width}x${img.height} cannot be shown within Jev's ${JEV_IMAGE_LIMITS.minEdge}-${JEV_IMAGE_LIMITS.maxEdge}px edges`);
|
|
30
|
+
const shown = scale === 1 ? png : encodePngImage(resample(img, {
|
|
31
|
+
width: Math.round(img.width * scale),
|
|
32
|
+
height: Math.round(img.height * scale)
|
|
33
|
+
}));
|
|
34
|
+
const questions = {};
|
|
35
|
+
claims.forEach((c, i) => {
|
|
36
|
+
questions[`c${i}`] = {
|
|
37
|
+
type: "noul",
|
|
38
|
+
instructions: claimInstruction(c.statement)
|
|
39
|
+
};
|
|
40
|
+
});
|
|
41
|
+
const r = await ask({
|
|
42
|
+
model: options.model ?? "jev-1.14.0",
|
|
43
|
+
state: { screenshot: "SHOT" },
|
|
44
|
+
assets: { SHOT: pngImage(shown) },
|
|
45
|
+
questions
|
|
46
|
+
});
|
|
47
|
+
const answers = r.answers;
|
|
48
|
+
const results = claims.map((c, i) => {
|
|
49
|
+
const noul = answers[`c${i}`].noul;
|
|
50
|
+
const pass = c.expect === "shown" ? noul >= threshold : noul < threshold;
|
|
51
|
+
return {
|
|
52
|
+
...c,
|
|
53
|
+
noul,
|
|
54
|
+
pass,
|
|
55
|
+
uncertain: Math.abs(noul - threshold) < band
|
|
56
|
+
};
|
|
57
|
+
});
|
|
58
|
+
return {
|
|
59
|
+
results,
|
|
60
|
+
passed: results.every((x) => x.pass),
|
|
61
|
+
model: r.model,
|
|
62
|
+
costUsd: r.costUsd,
|
|
63
|
+
inputTokens: r.usage.input_tokens
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
//#endregion
|
|
67
|
+
export { checkClaims, claimInstruction };
|
package/dist/errors.d.mts
CHANGED
|
@@ -15,10 +15,23 @@
|
|
|
15
15
|
* Codes are stable; new ones can only be added (never renumbered or
|
|
16
16
|
* removed) in minor versions.
|
|
17
17
|
*/
|
|
18
|
-
type VrtConfigErrorCode =
|
|
19
|
-
|
|
18
|
+
export type VrtConfigErrorCode =
|
|
19
|
+
/** Required env var (`OPENROUTER_API_KEY`, `GEMINI_API_KEY`, `ANTHROPIC_API_KEY`) not set. */
|
|
20
|
+
"MISSING_KEY" |
|
|
21
|
+
/** Provider/model id doesn't resolve. */
|
|
22
|
+
"INVALID_MODEL" |
|
|
23
|
+
/** Model substring matches more than one candidate. */
|
|
24
|
+
"MULTIPLE_MATCHES" |
|
|
25
|
+
/** `VLMKIT_LLM_PROVIDER` value is not one of the known providers. */
|
|
26
|
+
"INVALID_PROVIDER" |
|
|
27
|
+
/** No provider in the fallback chain has an API key configured. */
|
|
28
|
+
"NO_PROVIDER_AVAILABLE" |
|
|
29
|
+
/** An optional runtime dependency (e.g. `@google/generative-ai`) failed to import. */
|
|
30
|
+
"MISSING_DEPENDENCY" |
|
|
31
|
+
/** Caller-supplied request parameters are malformed (empty prompt, out-of-range size, etc.). */
|
|
32
|
+
"INVALID_REQUEST";
|
|
33
|
+
export declare class VrtConfigError extends Error {
|
|
20
34
|
readonly code: VrtConfigErrorCode;
|
|
21
35
|
constructor(code: VrtConfigErrorCode, message: string);
|
|
22
36
|
}
|
|
23
|
-
//#endregion
|
|
24
|
-
export { VrtConfigError, VrtConfigErrorCode };
|
|
37
|
+
//#endregion
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
//#region src/image-gen-client.d.ts
|
|
2
|
-
type ImageGenSize = "1024x1024" | "1024x1536" | "1536x1024" | "auto";
|
|
3
|
-
type ImageGenQuality = "low" | "medium" | "high" | "auto";
|
|
4
|
-
type ImageGenOutputFormat = "png" | "jpeg" | "webp";
|
|
5
|
-
type ImageGenBackground = "opaque" | "transparent" | "auto";
|
|
2
|
+
export type ImageGenSize = "1024x1024" | "1024x1536" | "1536x1024" | "auto";
|
|
3
|
+
export type ImageGenQuality = "low" | "medium" | "high" | "auto";
|
|
4
|
+
export type ImageGenOutputFormat = "png" | "jpeg" | "webp";
|
|
5
|
+
export type ImageGenBackground = "opaque" | "transparent" | "auto";
|
|
6
6
|
/** The figure bench's choice: 3/3 on its briefs at the lowest price measured (2026-09-30). */
|
|
7
|
-
declare const IMAGE_GEN_DEFAULT_MODEL = "openai/gpt-image-2.5-flare";
|
|
8
|
-
interface ImageGenModel {
|
|
7
|
+
export declare const IMAGE_GEN_DEFAULT_MODEL = "openai/gpt-image-2.5-flare";
|
|
8
|
+
export interface ImageGenModel {
|
|
9
9
|
id: string;
|
|
10
10
|
/** `openai`: api.openai.com + OPENAI_API_KEY. `openrouter`: openrouter.ai + OPENROUTER_API_KEY. */
|
|
11
11
|
provider: "openai" | "openrouter";
|
|
@@ -14,7 +14,7 @@ interface ImageGenModel {
|
|
|
14
14
|
costPer1MInputImageTokens: number;
|
|
15
15
|
costPer1MOutputImageTokens: number;
|
|
16
16
|
}
|
|
17
|
-
interface ImageGenRequest {
|
|
17
|
+
export interface ImageGenRequest {
|
|
18
18
|
prompt: string;
|
|
19
19
|
size?: ImageGenSize;
|
|
20
20
|
quality?: ImageGenQuality;
|
|
@@ -30,12 +30,12 @@ interface ImageGenRequest {
|
|
|
30
30
|
*/
|
|
31
31
|
inputReferences?: string[];
|
|
32
32
|
}
|
|
33
|
-
interface ImageGenUsage {
|
|
33
|
+
export interface ImageGenUsage {
|
|
34
34
|
inputTextTokens: number;
|
|
35
35
|
inputImageTokens: number;
|
|
36
36
|
outputTokens: number;
|
|
37
37
|
}
|
|
38
|
-
interface ImageGenResponse {
|
|
38
|
+
export interface ImageGenResponse {
|
|
39
39
|
model: string;
|
|
40
40
|
images: Uint8Array[];
|
|
41
41
|
/** One per image when the API names it (`image/png`, `image/svg+xml`, …). */
|
|
@@ -44,7 +44,7 @@ interface ImageGenResponse {
|
|
|
44
44
|
costUsd: number;
|
|
45
45
|
latencyMs: number;
|
|
46
46
|
}
|
|
47
|
-
interface OpenRouterImageBody {
|
|
47
|
+
export interface OpenRouterImageBody {
|
|
48
48
|
model: string;
|
|
49
49
|
prompt: string;
|
|
50
50
|
n: number;
|
|
@@ -58,7 +58,7 @@ interface OpenRouterImageBody {
|
|
|
58
58
|
};
|
|
59
59
|
}[];
|
|
60
60
|
}
|
|
61
|
-
interface ImageGenRequestBody {
|
|
61
|
+
export interface ImageGenRequestBody {
|
|
62
62
|
model: string;
|
|
63
63
|
prompt: string;
|
|
64
64
|
size: ImageGenSize;
|
|
@@ -67,16 +67,16 @@ interface ImageGenRequestBody {
|
|
|
67
67
|
output_format: ImageGenOutputFormat;
|
|
68
68
|
background: ImageGenBackground;
|
|
69
69
|
}
|
|
70
|
-
interface ImageGenClient {
|
|
70
|
+
export interface ImageGenClient {
|
|
71
71
|
model: ImageGenModel;
|
|
72
72
|
generate(req: ImageGenRequest): Promise<ImageGenResponse>;
|
|
73
73
|
}
|
|
74
|
-
declare function listImageGenModels(): ImageGenModel[];
|
|
75
|
-
declare function resolveImageGenModel(id: string): ImageGenModel;
|
|
74
|
+
export declare function listImageGenModels(): ImageGenModel[];
|
|
75
|
+
export declare function resolveImageGenModel(id: string): ImageGenModel;
|
|
76
76
|
/** `VLMKIT_IMAGE_MODEL`, else the bench's default. */
|
|
77
|
-
declare function defaultImageGenModelId(env?: Record<string, string | undefined>): string;
|
|
78
|
-
declare function buildGenerationBody(model: ImageGenModel, req: ImageGenRequest): ImageGenRequestBody;
|
|
79
|
-
declare function buildOpenRouterBody(model: ImageGenModel, req: ImageGenRequest): OpenRouterImageBody;
|
|
77
|
+
export declare function defaultImageGenModelId(env?: Record<string, string | undefined>): string;
|
|
78
|
+
export declare function buildGenerationBody(model: ImageGenModel, req: ImageGenRequest): ImageGenRequestBody;
|
|
79
|
+
export declare function buildOpenRouterBody(model: ImageGenModel, req: ImageGenRequest): OpenRouterImageBody;
|
|
80
80
|
interface RawGenerationResponse {
|
|
81
81
|
data?: Array<{
|
|
82
82
|
b64_json?: string;
|
|
@@ -84,7 +84,8 @@ interface RawGenerationResponse {
|
|
|
84
84
|
media_type?: string;
|
|
85
85
|
}>;
|
|
86
86
|
usage?: {
|
|
87
|
-
/** OpenRouter: what the call was billed, in USD. */
|
|
87
|
+
/** OpenRouter: what the call was billed, in USD. */
|
|
88
|
+
cost?: number;
|
|
88
89
|
prompt_tokens?: number;
|
|
89
90
|
completion_tokens?: number;
|
|
90
91
|
input_tokens?: number;
|
|
@@ -96,22 +97,21 @@ interface RawGenerationResponse {
|
|
|
96
97
|
};
|
|
97
98
|
};
|
|
98
99
|
}
|
|
99
|
-
interface ParsedGeneration {
|
|
100
|
+
export interface ParsedGeneration {
|
|
100
101
|
images: Uint8Array[];
|
|
101
102
|
mediaTypes: (string | null)[];
|
|
102
103
|
usage: ImageGenUsage | null;
|
|
103
104
|
/** The provider's own figure (OpenRouter `usage.cost`), when it gives one. */
|
|
104
105
|
reportedCostUsd: number | null;
|
|
105
106
|
}
|
|
106
|
-
declare function parseGenerationResponse(json: RawGenerationResponse): ParsedGeneration;
|
|
107
|
-
declare function estimateImageGenCost(model: ImageGenModel, usage: ImageGenUsage | null): number;
|
|
108
|
-
interface CreateImageGenClientOptions {
|
|
107
|
+
export declare function parseGenerationResponse(json: RawGenerationResponse): ParsedGeneration;
|
|
108
|
+
export declare function estimateImageGenCost(model: ImageGenModel, usage: ImageGenUsage | null): number;
|
|
109
|
+
export interface CreateImageGenClientOptions {
|
|
109
110
|
apiKey?: string;
|
|
110
111
|
throwIfMissing?: boolean;
|
|
111
112
|
/** Override the API base URL (for tests / proxies). */
|
|
112
113
|
baseUrl?: string;
|
|
113
114
|
}
|
|
114
115
|
/** With no model: `VLMKIT_IMAGE_MODEL`, else `IMAGE_GEN_DEFAULT_MODEL`. */
|
|
115
|
-
declare function createImageGenClient(modelOrId?: ImageGenModel | string, options?: CreateImageGenClientOptions): ImageGenClient;
|
|
116
|
-
//#endregion
|
|
117
|
-
export { CreateImageGenClientOptions, IMAGE_GEN_DEFAULT_MODEL, ImageGenBackground, ImageGenClient, ImageGenModel, ImageGenOutputFormat, ImageGenQuality, ImageGenRequest, ImageGenRequestBody, ImageGenResponse, ImageGenSize, ImageGenUsage, OpenRouterImageBody, ParsedGeneration, buildGenerationBody, buildOpenRouterBody, createImageGenClient, defaultImageGenModelId, estimateImageGenCost, listImageGenModels, parseGenerationResponse, resolveImageGenModel };
|
|
116
|
+
export declare function createImageGenClient(modelOrId?: ImageGenModel | string, options?: CreateImageGenClientOptions): ImageGenClient;
|
|
117
|
+
//#endregion
|
|
@@ -40,24 +40,24 @@ const IMAGE_GEN_MODELS = [{
|
|
|
40
40
|
costPer1MInputImageTokens: 8,
|
|
41
41
|
costPer1MOutputImageTokens: 30
|
|
42
42
|
}];
|
|
43
|
-
const VALID_SIZES = new Set([
|
|
43
|
+
const VALID_SIZES = /* @__PURE__ */ new Set([
|
|
44
44
|
"1024x1024",
|
|
45
45
|
"1024x1536",
|
|
46
46
|
"1536x1024",
|
|
47
47
|
"auto"
|
|
48
48
|
]);
|
|
49
|
-
const VALID_QUALITIES = new Set([
|
|
49
|
+
const VALID_QUALITIES = /* @__PURE__ */ new Set([
|
|
50
50
|
"low",
|
|
51
51
|
"medium",
|
|
52
52
|
"high",
|
|
53
53
|
"auto"
|
|
54
54
|
]);
|
|
55
|
-
const VALID_OUTPUT_FORMATS = new Set([
|
|
55
|
+
const VALID_OUTPUT_FORMATS = /* @__PURE__ */ new Set([
|
|
56
56
|
"png",
|
|
57
57
|
"jpeg",
|
|
58
58
|
"webp"
|
|
59
59
|
]);
|
|
60
|
-
const VALID_BACKGROUNDS = new Set([
|
|
60
|
+
const VALID_BACKGROUNDS = /* @__PURE__ */ new Set([
|
|
61
61
|
"opaque",
|
|
62
62
|
"transparent",
|
|
63
63
|
"auto"
|
package/dist/index.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { DEFAULT_IMAGE_BUDGET } from "./zoom-geometry.mjs";
|
|
1
2
|
import { VrtConfigError } from "./errors.mjs";
|
|
2
3
|
import { IMAGE_GEN_DEFAULT_MODEL, buildGenerationBody, buildOpenRouterBody, createImageGenClient, defaultImageGenModelId, estimateImageGenCost, listImageGenModels, parseGenerationResponse, resolveImageGenModel } from "./image-gen-client.mjs";
|
|
3
4
|
import { OPENAI_DEFAULT_MODEL, createLLMProvider, createUnifiedLLMClient } from "./llm-client.mjs";
|
|
@@ -5,7 +6,6 @@ import { createVlmClient, fetchVisionModels, isGeminiDirectModel, listGeminiMode
|
|
|
5
6
|
import { createReasoningPipeline } from "./reasoning-pipeline.mjs";
|
|
6
7
|
import { reasonAboutChanges } from "./reasoning.mjs";
|
|
7
8
|
import { buildIntent, buildIntentWithLLM, buildReasoningPrompt, extractDiffSemantics, parseDiff } from "./intent.mjs";
|
|
8
|
-
import { DEFAULT_IMAGE_BUDGET } from "./zoom-geometry.mjs";
|
|
9
9
|
import { parseZoomRequests, runSingleLook, runZoomLoop } from "./zoom-loop.mjs";
|
|
10
10
|
import { anthropicDriver, geminiDriver, openAiCompatibleDriver } from "./zoom-drivers.mjs";
|
|
11
11
|
import { analyzeWithZoom, createZoomDriver } from "./zoom.mjs";
|
package/dist/intent.d.mts
CHANGED
|
@@ -1,29 +1,27 @@
|
|
|
1
1
|
import { ChangeIntent, DiffSemantics, FileChange, VrtDiff } from "@mizchi/vlmkit-core/types.ts";
|
|
2
|
-
|
|
3
2
|
//#region src/intent.d.ts
|
|
4
3
|
/**
|
|
5
4
|
* Parse git diff and return structured change information.
|
|
6
5
|
*/
|
|
7
|
-
declare function extractDiffSemantics(repoDir: string, base?: string, head?: string): Promise<DiffSemantics>;
|
|
6
|
+
export declare function extractDiffSemantics(repoDir: string, base?: string, head?: string): Promise<DiffSemantics>;
|
|
8
7
|
/**
|
|
9
8
|
* Parse unified diff into FileChange[].
|
|
10
9
|
*/
|
|
11
|
-
declare function parseDiff(diffText: string): FileChange[];
|
|
10
|
+
export declare function parseDiff(diffText: string): FileChange[];
|
|
12
11
|
/**
|
|
13
12
|
* Infer change intent from files and commit message.
|
|
14
13
|
* Lightweight version without LLM. See buildIntentWithLLM for LLM version.
|
|
15
14
|
*/
|
|
16
|
-
declare function buildIntent(files: FileChange[], commitMessage: string): ChangeIntent;
|
|
17
|
-
interface LLMProvider {
|
|
15
|
+
export declare function buildIntent(files: FileChange[], commitMessage: string): ChangeIntent;
|
|
16
|
+
export interface LLMProvider {
|
|
18
17
|
complete(prompt: string): Promise<string>;
|
|
19
18
|
}
|
|
20
19
|
/**
|
|
21
20
|
* Build Intent from diff and commit message using LLM.
|
|
22
21
|
*/
|
|
23
|
-
declare function buildIntentWithLLM(files: FileChange[], commitMessage: string, llm: LLMProvider): Promise<ChangeIntent>;
|
|
22
|
+
export declare function buildIntentWithLLM(files: FileChange[], commitMessage: string, llm: LLMProvider): Promise<ChangeIntent>;
|
|
24
23
|
/**
|
|
25
24
|
* Build a reasoning prompt that validates VRT diff against Intent.
|
|
26
25
|
*/
|
|
27
|
-
declare function buildReasoningPrompt(diff: VrtDiff, intent: ChangeIntent): string;
|
|
28
|
-
//#endregion
|
|
29
|
-
export { LLMProvider, buildIntent, buildIntentWithLLM, buildReasoningPrompt, extractDiffSemantics, parseDiff };
|
|
26
|
+
export declare function buildReasoningPrompt(diff: VrtDiff, intent: ChangeIntent): string;
|
|
27
|
+
//#endregion
|
package/dist/intent.mjs
CHANGED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
//#region src/jev-client.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* TypeSafe's Jev (System One): typed questions about a state, typed answers back. No prose.
|
|
4
|
+
*
|
|
5
|
+
* Jev generates no text. A request is a `state` (text, objects, images) and a map of questions,
|
|
6
|
+
* each one of four types, and every answer is a value the caller can use as is:
|
|
7
|
+
*
|
|
8
|
+
* - `box` → one bounding box, edges as fractions of the image (0-1, top-left origin) + confidence
|
|
9
|
+
* - `noul` → the probability a statement is true (0-1)
|
|
10
|
+
* - `choice` → one option key + a probability per option + confidence
|
|
11
|
+
* - `score` → a position on an ordered rubric + a probability per level + confidence
|
|
12
|
+
*
|
|
13
|
+
* That shape is why it fits vlmkit's judges and benches: nothing here parses a reply. Images and
|
|
14
|
+
* `box` are behind `TypeSafe-Danger-Zone-Images: true` (Jev 1.14 for `box`); docs
|
|
15
|
+
* https://docs.typesafe.ai/go/images and https://docs.typesafe.ai/go/box.
|
|
16
|
+
*
|
|
17
|
+
* Images are referenced, not inlined: each asset has a key, and any string in `state`,
|
|
18
|
+
* `instructions` or `criteria` that equals (or contains) the key becomes that image. Every asset
|
|
19
|
+
* must be referenced, and each reference adds a copy to what the model reads — put a shared image
|
|
20
|
+
* in `state` once rather than in every question's instructions.
|
|
21
|
+
*/
|
|
22
|
+
export declare const JEV_ENDPOINT = "https://api.typesafe.ai/v1/systemone";
|
|
23
|
+
export declare const JEV_DEFAULT_MODEL = "jev-1.14.0";
|
|
24
|
+
/** USD per input token ($42 per billion, 2026-10). Output tokens are free. */
|
|
25
|
+
export declare const JEV_INPUT_USD_PER_TOKEN = 4.2e-8;
|
|
26
|
+
/** Images outside these are rejected by the API, not resized (docs.typesafe.ai/go/images). */
|
|
27
|
+
export declare const JEV_IMAGE_LIMITS: {
|
|
28
|
+
readonly minEdge: 280;
|
|
29
|
+
readonly maxEdge: 1568;
|
|
30
|
+
readonly minPixels: 78400;
|
|
31
|
+
readonly maxPixels: 2458624;
|
|
32
|
+
readonly maxFileBytes: number;
|
|
33
|
+
};
|
|
34
|
+
export type JevQuestion = {
|
|
35
|
+
type: "box";
|
|
36
|
+
instructions: string;
|
|
37
|
+
} | {
|
|
38
|
+
type: "noul";
|
|
39
|
+
instructions: string;
|
|
40
|
+
} | {
|
|
41
|
+
type: "choice";
|
|
42
|
+
instructions: string;
|
|
43
|
+
criteria: Record<string, string>;
|
|
44
|
+
} | {
|
|
45
|
+
type: "score";
|
|
46
|
+
instructions: string;
|
|
47
|
+
criteria: readonly string[];
|
|
48
|
+
};
|
|
49
|
+
/** Edges as fractions of the image: left/right of its width, top/bottom of its height. */
|
|
50
|
+
export interface JevBox {
|
|
51
|
+
top: number;
|
|
52
|
+
bottom: number;
|
|
53
|
+
left: number;
|
|
54
|
+
right: number;
|
|
55
|
+
}
|
|
56
|
+
export type JevAnswer = {
|
|
57
|
+
type: "box";
|
|
58
|
+
box: JevBox;
|
|
59
|
+
confidence: number;
|
|
60
|
+
} | {
|
|
61
|
+
type: "noul";
|
|
62
|
+
noul: number;
|
|
63
|
+
} | {
|
|
64
|
+
type: "choice";
|
|
65
|
+
choice: string;
|
|
66
|
+
confidence: number;
|
|
67
|
+
probabilities: Record<string, number>;
|
|
68
|
+
} | {
|
|
69
|
+
type: "score";
|
|
70
|
+
score: number;
|
|
71
|
+
confidence: number;
|
|
72
|
+
probabilities: Record<string, number>;
|
|
73
|
+
legend?: Record<string, string>;
|
|
74
|
+
};
|
|
75
|
+
export interface JevImage {
|
|
76
|
+
bytes: Uint8Array;
|
|
77
|
+
format: "png" | "jpg" | "jpeg";
|
|
78
|
+
}
|
|
79
|
+
export interface JevRequest<Q extends Record<string, JevQuestion> = Record<string, JevQuestion>> {
|
|
80
|
+
model?: string;
|
|
81
|
+
state: unknown;
|
|
82
|
+
/** Reference key → image. Every key must appear somewhere in `state` or a question. */
|
|
83
|
+
assets?: Record<string, JevImage>;
|
|
84
|
+
questions: Q;
|
|
85
|
+
}
|
|
86
|
+
export interface JevResponse<Q extends Record<string, JevQuestion> = Record<string, JevQuestion>> {
|
|
87
|
+
model: string;
|
|
88
|
+
answers: { [K in keyof Q]: Extract<JevAnswer, {
|
|
89
|
+
type: Q[K]["type"];
|
|
90
|
+
}>; };
|
|
91
|
+
usage: {
|
|
92
|
+
input_tokens: number;
|
|
93
|
+
output_tokens: number;
|
|
94
|
+
};
|
|
95
|
+
latencyMs: number;
|
|
96
|
+
costUsd: number;
|
|
97
|
+
}
|
|
98
|
+
export interface JevClientOptions {
|
|
99
|
+
apiKey?: string;
|
|
100
|
+
endpoint?: string;
|
|
101
|
+
/** Extra headers; `Danger-Zone-Long-Context` goes here when wanted. */
|
|
102
|
+
headers?: Record<string, string>;
|
|
103
|
+
fetch?: typeof fetch;
|
|
104
|
+
/** Retries on 429 / 5xx, honouring `retry-after` (default 3). */
|
|
105
|
+
retries?: number;
|
|
106
|
+
signal?: AbortSignal;
|
|
107
|
+
}
|
|
108
|
+
export declare class JevApiError extends Error {
|
|
109
|
+
readonly status: number;
|
|
110
|
+
readonly body: string;
|
|
111
|
+
constructor(status: number, body: string);
|
|
112
|
+
}
|
|
113
|
+
/** Why an image would be refused, or null. Checked locally so a bench fails before it spends. */
|
|
114
|
+
export declare function jevImageProblem(width: number, height: number, bytes?: number): string | null;
|
|
115
|
+
export declare function pngImage(bytes: Uint8Array): JevImage;
|
|
116
|
+
/** Width and height from a PNG's IHDR, without decoding it. */
|
|
117
|
+
export declare function pngSize(bytes: Uint8Array): {
|
|
118
|
+
width: number;
|
|
119
|
+
height: number;
|
|
120
|
+
};
|
|
121
|
+
/** A box answer in the pixel space of an image of `width` x `height`. */
|
|
122
|
+
export declare function jevBoxToPixels(box: JevBox, width: number, height: number): {
|
|
123
|
+
x1: number;
|
|
124
|
+
y1: number;
|
|
125
|
+
x2: number;
|
|
126
|
+
y2: number;
|
|
127
|
+
};
|
|
128
|
+
/** The multipart body: a `request` JSON part, then one file part per asset (`a0`, `a1`, …). */
|
|
129
|
+
export declare function buildJevForm(req: JevRequest): FormData;
|
|
130
|
+
export declare function askJev<Q extends Record<string, JevQuestion>>(req: JevRequest<Q>, options?: JevClientOptions): Promise<JevResponse<Q>>;
|
|
131
|
+
/** Decode-free sanity: a PNG Buffer that Jev would accept, or the reason it would not. */
|
|
132
|
+
export declare function checkPngForJev(bytes: Uint8Array): string | null;
|
|
133
|
+
//#endregion
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
//#region src/jev-client.ts
|
|
2
|
+
/**
|
|
3
|
+
* TypeSafe's Jev (System One): typed questions about a state, typed answers back. No prose.
|
|
4
|
+
*
|
|
5
|
+
* Jev generates no text. A request is a `state` (text, objects, images) and a map of questions,
|
|
6
|
+
* each one of four types, and every answer is a value the caller can use as is:
|
|
7
|
+
*
|
|
8
|
+
* - `box` → one bounding box, edges as fractions of the image (0-1, top-left origin) + confidence
|
|
9
|
+
* - `noul` → the probability a statement is true (0-1)
|
|
10
|
+
* - `choice` → one option key + a probability per option + confidence
|
|
11
|
+
* - `score` → a position on an ordered rubric + a probability per level + confidence
|
|
12
|
+
*
|
|
13
|
+
* That shape is why it fits vlmkit's judges and benches: nothing here parses a reply. Images and
|
|
14
|
+
* `box` are behind `TypeSafe-Danger-Zone-Images: true` (Jev 1.14 for `box`); docs
|
|
15
|
+
* https://docs.typesafe.ai/go/images and https://docs.typesafe.ai/go/box.
|
|
16
|
+
*
|
|
17
|
+
* Images are referenced, not inlined: each asset has a key, and any string in `state`,
|
|
18
|
+
* `instructions` or `criteria` that equals (or contains) the key becomes that image. Every asset
|
|
19
|
+
* must be referenced, and each reference adds a copy to what the model reads — put a shared image
|
|
20
|
+
* in `state` once rather than in every question's instructions.
|
|
21
|
+
*/
|
|
22
|
+
const JEV_ENDPOINT = "https://api.typesafe.ai/v1/systemone";
|
|
23
|
+
const JEV_DEFAULT_MODEL = "jev-1.14.0";
|
|
24
|
+
/** USD per input token ($42 per billion, 2026-10). Output tokens are free. */
|
|
25
|
+
const JEV_INPUT_USD_PER_TOKEN = 42e-9;
|
|
26
|
+
/** Images outside these are rejected by the API, not resized (docs.typesafe.ai/go/images). */
|
|
27
|
+
const JEV_IMAGE_LIMITS = {
|
|
28
|
+
minEdge: 280,
|
|
29
|
+
maxEdge: 1568,
|
|
30
|
+
minPixels: 78400,
|
|
31
|
+
maxPixels: 2458624,
|
|
32
|
+
maxFileBytes: 16777216
|
|
33
|
+
};
|
|
34
|
+
var JevApiError = class extends Error {
|
|
35
|
+
status;
|
|
36
|
+
body;
|
|
37
|
+
constructor(status, body) {
|
|
38
|
+
super(`Jev API ${status}: ${body.slice(0, 500)}`);
|
|
39
|
+
this.status = status;
|
|
40
|
+
this.body = body;
|
|
41
|
+
this.name = "JevApiError";
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
/** Why an image would be refused, or null. Checked locally so a bench fails before it spends. */
|
|
45
|
+
function jevImageProblem(width, height, bytes) {
|
|
46
|
+
const L = JEV_IMAGE_LIMITS;
|
|
47
|
+
if (width < L.minEdge || height < L.minEdge) return `${width}x${height}: each edge must be >= ${L.minEdge}px`;
|
|
48
|
+
if (width > L.maxEdge || height > L.maxEdge) return `${width}x${height}: each edge must be <= ${L.maxEdge}px`;
|
|
49
|
+
const px = width * height;
|
|
50
|
+
if (px < L.minPixels || px > L.maxPixels) return `${width}x${height}: ${px} pixels outside ${L.minPixels}-${L.maxPixels}`;
|
|
51
|
+
if (bytes !== void 0 && bytes > L.maxFileBytes) return `${bytes} bytes exceeds ${L.maxFileBytes}`;
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
function pngImage(bytes) {
|
|
55
|
+
return {
|
|
56
|
+
bytes,
|
|
57
|
+
format: "png"
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
/** Width and height from a PNG's IHDR, without decoding it. */
|
|
61
|
+
function pngSize(bytes) {
|
|
62
|
+
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
63
|
+
return {
|
|
64
|
+
width: view.getUint32(16),
|
|
65
|
+
height: view.getUint32(20)
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
/** A box answer in the pixel space of an image of `width` x `height`. */
|
|
69
|
+
function jevBoxToPixels(box, width, height) {
|
|
70
|
+
return {
|
|
71
|
+
x1: box.left * width,
|
|
72
|
+
y1: box.top * height,
|
|
73
|
+
x2: box.right * width,
|
|
74
|
+
y2: box.bottom * height
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
/** The multipart body: a `request` JSON part, then one file part per asset (`a0`, `a1`, …). */
|
|
78
|
+
function buildJevForm(req) {
|
|
79
|
+
const assets = {};
|
|
80
|
+
const form = new FormData();
|
|
81
|
+
const files = [];
|
|
82
|
+
Object.entries(req.assets ?? {}).forEach(([key, img], i) => {
|
|
83
|
+
const part = `a${i}`;
|
|
84
|
+
assets[key] = {
|
|
85
|
+
type: "image",
|
|
86
|
+
part
|
|
87
|
+
};
|
|
88
|
+
const mime = img.format === "png" ? "image/png" : "image/jpeg";
|
|
89
|
+
files.push([part, new Blob([img.bytes], { type: mime })]);
|
|
90
|
+
});
|
|
91
|
+
const body = {
|
|
92
|
+
model: req.model ?? "jev-1.14.0",
|
|
93
|
+
state: req.state,
|
|
94
|
+
assets,
|
|
95
|
+
questions: req.questions
|
|
96
|
+
};
|
|
97
|
+
form.append("request", new Blob([JSON.stringify(body)], { type: "application/json" }));
|
|
98
|
+
for (const [part, blob] of files) form.append(part, blob, part);
|
|
99
|
+
return form;
|
|
100
|
+
}
|
|
101
|
+
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
102
|
+
async function askJev(req, options = {}) {
|
|
103
|
+
const apiKey = options.apiKey ?? process.env.TYPESAFEAI_API_KEY ?? process.env.TYPESAFE_API_KEY;
|
|
104
|
+
if (!apiKey) throw new Error("Jev needs TYPESAFEAI_API_KEY (console.typesafe.ai/keys)");
|
|
105
|
+
const hasImages = Object.keys(req.assets ?? {}).length > 0;
|
|
106
|
+
const hasBox = Object.values(req.questions).some((q) => q.type === "box");
|
|
107
|
+
const headers = {
|
|
108
|
+
Authorization: `Bearer ${apiKey}`,
|
|
109
|
+
...options.headers
|
|
110
|
+
};
|
|
111
|
+
if (hasImages || hasBox) headers["TypeSafe-Danger-Zone-Images"] = "true";
|
|
112
|
+
const doFetch = options.fetch ?? fetch;
|
|
113
|
+
const retries = options.retries ?? 3;
|
|
114
|
+
for (let attempt = 0;; attempt++) {
|
|
115
|
+
const started = performance.now();
|
|
116
|
+
const res = await doFetch(options.endpoint ?? "https://api.typesafe.ai/v1/systemone", {
|
|
117
|
+
method: "POST",
|
|
118
|
+
headers,
|
|
119
|
+
body: buildJevForm(req),
|
|
120
|
+
signal: options.signal
|
|
121
|
+
});
|
|
122
|
+
const latencyMs = performance.now() - started;
|
|
123
|
+
if (res.ok) {
|
|
124
|
+
const json = await res.json();
|
|
125
|
+
return {
|
|
126
|
+
...json,
|
|
127
|
+
latencyMs,
|
|
128
|
+
costUsd: json.usage.input_tokens * JEV_INPUT_USD_PER_TOKEN
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
const text = await res.text();
|
|
132
|
+
if (attempt < retries && (res.status === 429 || res.status >= 500)) {
|
|
133
|
+
const after = Number(res.headers.get("retry-after"));
|
|
134
|
+
await sleep(Number.isFinite(after) && after > 0 ? after * 1e3 : 1e3 * 2 ** attempt);
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
throw new JevApiError(res.status, text);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
/** Decode-free sanity: a PNG Buffer that Jev would accept, or the reason it would not. */
|
|
141
|
+
function checkPngForJev(bytes) {
|
|
142
|
+
if (bytes.length < 24 || bytes[0] !== 137 || bytes[1] !== 80) return "not a PNG";
|
|
143
|
+
const { width, height } = pngSize(bytes);
|
|
144
|
+
return jevImageProblem(width, height, bytes.length);
|
|
145
|
+
}
|
|
146
|
+
//#endregion
|
|
147
|
+
export { JEV_DEFAULT_MODEL, JEV_ENDPOINT, JEV_IMAGE_LIMITS, JEV_INPUT_USD_PER_TOKEN, JevApiError, askJev, buildJevForm, checkPngForJev, jevBoxToPixels, jevImageProblem, pngImage, pngSize };
|