@mizchi/vlmkit-ai 0.7.0 → 0.8.1
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/errors.d.mts +24 -0
- package/dist/errors.mjs +11 -0
- package/dist/image-gen-client.d.mts +79 -0
- package/dist/image-gen-client.mjs +149 -0
- package/dist/index.d.mts +8 -0
- package/dist/index.mjs +8 -0
- package/dist/intent.d.mts +29 -0
- package/dist/intent.mjs +213 -0
- package/dist/llm-client.d.mts +87 -0
- package/dist/llm-client.mjs +310 -0
- package/dist/nlp.d.mts +8 -0
- package/dist/nlp.mjs +50 -0
- package/dist/reasoning-pipeline.d.mts +92 -0
- package/dist/reasoning-pipeline.mjs +256 -0
- package/dist/reasoning.d.mts +41 -0
- package/dist/reasoning.mjs +148 -0
- package/dist/vlm-client.d.mts +63 -0
- package/dist/vlm-client.mjs +430 -0
- package/package.json +18 -6
- package/src/errors.ts +0 -41
- package/src/image-gen-client.ts +0 -245
- package/src/index.ts +0 -89
- package/src/intent.ts +0 -322
- package/src/llm-client.ts +0 -421
- package/src/nlp.ts +0 -27
- package/src/reasoning-pipeline.ts +0 -407
- package/src/reasoning.ts +0 -268
- package/src/vlm-client.ts +0 -501
|
@@ -0,0 +1,430 @@
|
|
|
1
|
+
import { VrtConfigError } from "./errors.mjs";
|
|
2
|
+
import { readFile } from "node:fs/promises";
|
|
3
|
+
//#region src/vlm-client.ts
|
|
4
|
+
/**
|
|
5
|
+
* VLM (Vision Language Model) client
|
|
6
|
+
*
|
|
7
|
+
* Multi-provider support:
|
|
8
|
+
* - OpenRouter (100+ vision models)
|
|
9
|
+
* - Google AI (Gemini direct)
|
|
10
|
+
*
|
|
11
|
+
* Model list is fetched dynamically from the API.
|
|
12
|
+
*/
|
|
13
|
+
let _cachedModels = null;
|
|
14
|
+
async function fetchVisionModels() {
|
|
15
|
+
if (_cachedModels) return _cachedModels;
|
|
16
|
+
const res = await fetch("https://openrouter.ai/api/v1/models");
|
|
17
|
+
if (!res.ok) throw new Error(`OpenRouter API error: ${res.status}`);
|
|
18
|
+
_cachedModels = (await res.json()).data.filter((m) => {
|
|
19
|
+
return (m.architecture?.input_modalities ?? []).includes("image");
|
|
20
|
+
}).map((m) => ({
|
|
21
|
+
id: m.id,
|
|
22
|
+
name: m.name ?? m.id,
|
|
23
|
+
promptCostPer1k: parseFloat(m.pricing?.prompt ?? "999"),
|
|
24
|
+
completionCostPer1k: parseFloat(m.pricing?.completion ?? "999"),
|
|
25
|
+
contextLength: m.context_length ?? 0,
|
|
26
|
+
modality: m.architecture?.modality ?? ""
|
|
27
|
+
})).sort((a, b) => a.promptCostPer1k - b.promptCostPer1k);
|
|
28
|
+
return _cachedModels;
|
|
29
|
+
}
|
|
30
|
+
async function listModels(options) {
|
|
31
|
+
const openRouterModels = await fetchVisionModels();
|
|
32
|
+
const direct = [];
|
|
33
|
+
if (options?.includeGemini !== false) direct.push(...GOOGLE_MODELS);
|
|
34
|
+
if (options?.includeClaude !== false) direct.push(...CLAUDE_MODELS);
|
|
35
|
+
const models = [...direct, ...openRouterModels];
|
|
36
|
+
models.sort((a, b) => a.promptCostPer1k - b.promptCostPer1k);
|
|
37
|
+
let filtered = models;
|
|
38
|
+
if (options?.maxCost !== void 0) filtered = filtered.filter((m) => m.promptCostPer1k <= options.maxCost);
|
|
39
|
+
if (options?.limit) filtered = filtered.slice(0, options.limit);
|
|
40
|
+
return filtered;
|
|
41
|
+
}
|
|
42
|
+
async function resolveModel(idOrIndex) {
|
|
43
|
+
const geminiModel = resolveGeminiModel(idOrIndex);
|
|
44
|
+
if (geminiModel) return geminiModel;
|
|
45
|
+
const claudeModel = resolveClaudeModel(idOrIndex);
|
|
46
|
+
if (claudeModel) return claudeModel;
|
|
47
|
+
const models = await fetchVisionModels();
|
|
48
|
+
const exact = models.find((m) => m.id === idOrIndex);
|
|
49
|
+
if (exact) return exact;
|
|
50
|
+
const partial = models.filter((m) => m.id.includes(idOrIndex));
|
|
51
|
+
if (partial.length === 1) return partial[0];
|
|
52
|
+
if (partial.length > 1) {
|
|
53
|
+
const sorted = partial.sort((a, b) => a.id.length - b.id.length);
|
|
54
|
+
if (sorted[0].id.endsWith(idOrIndex) || sorted[0].id.includes(`/${idOrIndex}`)) return sorted[0];
|
|
55
|
+
throw new VrtConfigError("MULTIPLE_MATCHES", `Ambiguous model "${idOrIndex}". Matches: ${partial.slice(0, 5).map((m) => m.id).join(", ")}\nTip: use more specific ID, e.g. "${partial[0].id}"`);
|
|
56
|
+
}
|
|
57
|
+
const idx = parseInt(idOrIndex, 10);
|
|
58
|
+
if (!isNaN(idx) && idx >= 0 && idx < models.length) return models[idx];
|
|
59
|
+
throw new VrtConfigError("INVALID_MODEL", `Model not found: "${idOrIndex}". Use --list to see available models.`);
|
|
60
|
+
}
|
|
61
|
+
const GOOGLE_MODELS = [
|
|
62
|
+
{
|
|
63
|
+
id: "gemini:gemini-2.5-flash-preview-05-20",
|
|
64
|
+
name: "Gemini 2.5 Flash (direct)",
|
|
65
|
+
promptCostPer1k: 15e-8,
|
|
66
|
+
completionCostPer1k: 6e-7,
|
|
67
|
+
contextLength: 1048576,
|
|
68
|
+
modality: "text+image->text"
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
id: "gemini:gemini-2.0-flash",
|
|
72
|
+
name: "Gemini 2.0 Flash (direct)",
|
|
73
|
+
promptCostPer1k: 1e-7,
|
|
74
|
+
completionCostPer1k: 4e-7,
|
|
75
|
+
contextLength: 1048576,
|
|
76
|
+
modality: "text+image->text"
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
id: "gemini:gemini-2.0-flash-lite",
|
|
80
|
+
name: "Gemini 2.0 Flash Lite (direct)",
|
|
81
|
+
promptCostPer1k: 75e-9,
|
|
82
|
+
completionCostPer1k: 3e-7,
|
|
83
|
+
contextLength: 1048576,
|
|
84
|
+
modality: "text+image->text"
|
|
85
|
+
}
|
|
86
|
+
];
|
|
87
|
+
function isGeminiDirectModel(id) {
|
|
88
|
+
return id.startsWith("gemini:");
|
|
89
|
+
}
|
|
90
|
+
function resolveGeminiModel(id) {
|
|
91
|
+
return GOOGLE_MODELS.find((m) => m.id === id || m.id === `gemini:${id}`);
|
|
92
|
+
}
|
|
93
|
+
function listGeminiModels() {
|
|
94
|
+
return [...GOOGLE_MODELS];
|
|
95
|
+
}
|
|
96
|
+
const CLAUDE_MODELS = [
|
|
97
|
+
{
|
|
98
|
+
id: "claude:claude-haiku-4-5-20251001",
|
|
99
|
+
name: "Claude Haiku 4.5 (direct)",
|
|
100
|
+
promptCostPer1k: 1e-6,
|
|
101
|
+
completionCostPer1k: 5e-6,
|
|
102
|
+
contextLength: 2e5,
|
|
103
|
+
modality: "text+image->text"
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
id: "claude:claude-sonnet-4-6",
|
|
107
|
+
name: "Claude Sonnet 4.6 (direct)",
|
|
108
|
+
promptCostPer1k: 3e-6,
|
|
109
|
+
completionCostPer1k: 15e-6,
|
|
110
|
+
contextLength: 2e5,
|
|
111
|
+
modality: "text+image->text"
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
id: "claude:claude-opus-4-7",
|
|
115
|
+
name: "Claude Opus 4.7 (direct)",
|
|
116
|
+
promptCostPer1k: 15e-6,
|
|
117
|
+
completionCostPer1k: 75e-6,
|
|
118
|
+
contextLength: 2e5,
|
|
119
|
+
modality: "text+image->text"
|
|
120
|
+
}
|
|
121
|
+
];
|
|
122
|
+
function isClaudeDirectModel(id) {
|
|
123
|
+
return id.startsWith("claude:");
|
|
124
|
+
}
|
|
125
|
+
function resolveClaudeModel(id) {
|
|
126
|
+
return CLAUDE_MODELS.find((m) => m.id === id || m.id === `claude:${id}`);
|
|
127
|
+
}
|
|
128
|
+
function listClaudeModels() {
|
|
129
|
+
return [...CLAUDE_MODELS];
|
|
130
|
+
}
|
|
131
|
+
async function createClaudeClient(model, apiKey) {
|
|
132
|
+
const claudeModelId = model.id.replace("claude:", "");
|
|
133
|
+
async function callClaude(content, maxTokens) {
|
|
134
|
+
const start = Date.now();
|
|
135
|
+
const res = await fetch("https://api.anthropic.com/v1/messages", {
|
|
136
|
+
method: "POST",
|
|
137
|
+
headers: {
|
|
138
|
+
"Content-Type": "application/json",
|
|
139
|
+
"x-api-key": apiKey,
|
|
140
|
+
"anthropic-version": "2023-06-01"
|
|
141
|
+
},
|
|
142
|
+
body: JSON.stringify({
|
|
143
|
+
model: claudeModelId,
|
|
144
|
+
max_tokens: maxTokens,
|
|
145
|
+
messages: [{
|
|
146
|
+
role: "user",
|
|
147
|
+
content
|
|
148
|
+
}]
|
|
149
|
+
})
|
|
150
|
+
});
|
|
151
|
+
if (!res.ok) {
|
|
152
|
+
const text = await res.text();
|
|
153
|
+
throw new Error(`Anthropic API error: ${res.status} ${text.slice(0, 200)}`);
|
|
154
|
+
}
|
|
155
|
+
const data = await res.json();
|
|
156
|
+
const latencyMs = Date.now() - start;
|
|
157
|
+
const textOut = data.content.filter((b) => b.type === "text" && typeof b.text === "string").map((b) => b.text).join("");
|
|
158
|
+
const usage = data.usage ?? {
|
|
159
|
+
input_tokens: 0,
|
|
160
|
+
output_tokens: 0
|
|
161
|
+
};
|
|
162
|
+
const costUsd = usage.input_tokens / 1e3 * model.promptCostPer1k + usage.output_tokens / 1e3 * model.completionCostPer1k;
|
|
163
|
+
return {
|
|
164
|
+
content: textOut,
|
|
165
|
+
model: model.id,
|
|
166
|
+
promptTokens: usage.input_tokens,
|
|
167
|
+
completionTokens: usage.output_tokens,
|
|
168
|
+
totalTokens: usage.input_tokens + usage.output_tokens,
|
|
169
|
+
costUsd,
|
|
170
|
+
latencyMs
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
const client = {
|
|
174
|
+
model,
|
|
175
|
+
async analyzeImage(imageBase64, prompt, options) {
|
|
176
|
+
return callClaude([{
|
|
177
|
+
type: "image",
|
|
178
|
+
source: {
|
|
179
|
+
type: "base64",
|
|
180
|
+
media_type: "image/png",
|
|
181
|
+
data: imageBase64
|
|
182
|
+
}
|
|
183
|
+
}, {
|
|
184
|
+
type: "text",
|
|
185
|
+
text: prompt
|
|
186
|
+
}], options?.maxTokens ?? 1024);
|
|
187
|
+
},
|
|
188
|
+
async analyzeImageFile(imagePath, prompt, options) {
|
|
189
|
+
const buf = await readFile(imagePath);
|
|
190
|
+
return client.analyzeImage(buf.toString("base64"), prompt, options);
|
|
191
|
+
},
|
|
192
|
+
async analyzeDiff(baselineBase64, currentBase64, prompt, options) {
|
|
193
|
+
return callClaude([
|
|
194
|
+
{
|
|
195
|
+
type: "text",
|
|
196
|
+
text: "Baseline screenshot:"
|
|
197
|
+
},
|
|
198
|
+
{
|
|
199
|
+
type: "image",
|
|
200
|
+
source: {
|
|
201
|
+
type: "base64",
|
|
202
|
+
media_type: "image/png",
|
|
203
|
+
data: baselineBase64
|
|
204
|
+
}
|
|
205
|
+
},
|
|
206
|
+
{
|
|
207
|
+
type: "text",
|
|
208
|
+
text: "Current screenshot:"
|
|
209
|
+
},
|
|
210
|
+
{
|
|
211
|
+
type: "image",
|
|
212
|
+
source: {
|
|
213
|
+
type: "base64",
|
|
214
|
+
media_type: "image/png",
|
|
215
|
+
data: currentBase64
|
|
216
|
+
}
|
|
217
|
+
},
|
|
218
|
+
{
|
|
219
|
+
type: "text",
|
|
220
|
+
text: prompt
|
|
221
|
+
}
|
|
222
|
+
], options?.maxTokens ?? 1024);
|
|
223
|
+
}
|
|
224
|
+
};
|
|
225
|
+
return client;
|
|
226
|
+
}
|
|
227
|
+
async function createGeminiClient(model, apiKey) {
|
|
228
|
+
const geminiModelId = model.id.replace("gemini:", "");
|
|
229
|
+
let GoogleGenerativeAI;
|
|
230
|
+
try {
|
|
231
|
+
({GoogleGenerativeAI} = await import("@google/generative-ai"));
|
|
232
|
+
} catch (e) {
|
|
233
|
+
throw new VrtConfigError("MISSING_DEPENDENCY", `@google/generative-ai is not installed. Run: pnpm add @google/generative-ai`);
|
|
234
|
+
}
|
|
235
|
+
const genModel = new GoogleGenerativeAI(apiKey).getGenerativeModel({ model: geminiModelId });
|
|
236
|
+
async function callGemini(imageBase64, textPrompt, maxTokens) {
|
|
237
|
+
const start = Date.now();
|
|
238
|
+
const result = await genModel.generateContent({
|
|
239
|
+
contents: [{
|
|
240
|
+
role: "user",
|
|
241
|
+
parts: [{ inlineData: {
|
|
242
|
+
mimeType: "image/png",
|
|
243
|
+
data: imageBase64
|
|
244
|
+
} }, { text: textPrompt }]
|
|
245
|
+
}],
|
|
246
|
+
generationConfig: { maxOutputTokens: maxTokens }
|
|
247
|
+
});
|
|
248
|
+
const latencyMs = Date.now() - start;
|
|
249
|
+
const response = result.response;
|
|
250
|
+
const content = response.text();
|
|
251
|
+
const usage = response.usageMetadata;
|
|
252
|
+
const promptTokens = usage?.promptTokenCount ?? 0;
|
|
253
|
+
const completionTokens = usage?.candidatesTokenCount ?? 0;
|
|
254
|
+
const costUsd = promptTokens / 1e3 * model.promptCostPer1k + completionTokens / 1e3 * model.completionCostPer1k;
|
|
255
|
+
return {
|
|
256
|
+
content,
|
|
257
|
+
model: model.id,
|
|
258
|
+
promptTokens,
|
|
259
|
+
completionTokens,
|
|
260
|
+
totalTokens: promptTokens + completionTokens,
|
|
261
|
+
costUsd,
|
|
262
|
+
latencyMs
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
const client = {
|
|
266
|
+
model,
|
|
267
|
+
async analyzeImage(imageBase64, prompt, options) {
|
|
268
|
+
return callGemini(imageBase64, prompt, options?.maxTokens ?? 1024);
|
|
269
|
+
},
|
|
270
|
+
async analyzeImageFile(imagePath, prompt, options) {
|
|
271
|
+
const buf = await readFile(imagePath);
|
|
272
|
+
return client.analyzeImage(buf.toString("base64"), prompt, options);
|
|
273
|
+
},
|
|
274
|
+
async analyzeDiff(baselineBase64, currentBase64, prompt, options) {
|
|
275
|
+
const start = Date.now();
|
|
276
|
+
const result = await genModel.generateContent({
|
|
277
|
+
contents: [{
|
|
278
|
+
role: "user",
|
|
279
|
+
parts: [
|
|
280
|
+
{ text: "Baseline screenshot:" },
|
|
281
|
+
{ inlineData: {
|
|
282
|
+
mimeType: "image/png",
|
|
283
|
+
data: baselineBase64
|
|
284
|
+
} },
|
|
285
|
+
{ text: "Current screenshot:" },
|
|
286
|
+
{ inlineData: {
|
|
287
|
+
mimeType: "image/png",
|
|
288
|
+
data: currentBase64
|
|
289
|
+
} },
|
|
290
|
+
{ text: prompt }
|
|
291
|
+
]
|
|
292
|
+
}],
|
|
293
|
+
generationConfig: { maxOutputTokens: options?.maxTokens ?? 1024 }
|
|
294
|
+
});
|
|
295
|
+
const latencyMs = Date.now() - start;
|
|
296
|
+
const response = result.response;
|
|
297
|
+
const usage = response.usageMetadata;
|
|
298
|
+
const promptTokens = usage?.promptTokenCount ?? 0;
|
|
299
|
+
const completionTokens = usage?.candidatesTokenCount ?? 0;
|
|
300
|
+
return {
|
|
301
|
+
content: response.text(),
|
|
302
|
+
model: model.id,
|
|
303
|
+
promptTokens,
|
|
304
|
+
completionTokens,
|
|
305
|
+
totalTokens: promptTokens + completionTokens,
|
|
306
|
+
costUsd: promptTokens / 1e3 * model.promptCostPer1k + completionTokens / 1e3 * model.completionCostPer1k,
|
|
307
|
+
latencyMs
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
};
|
|
311
|
+
return client;
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* Construct a VLM client for the given model.
|
|
315
|
+
*
|
|
316
|
+
* Throws `VrtConfigError` (`code: "MISSING_KEY"`) when the model's
|
|
317
|
+
* required API key isn't set in the environment. Pass
|
|
318
|
+
* `{ throwIfMissing: false }` for the legacy `T | null` return.
|
|
319
|
+
*/
|
|
320
|
+
async function createVlmClient(model, options) {
|
|
321
|
+
const throwIfMissing = options?.throwIfMissing ?? true;
|
|
322
|
+
if (isGeminiDirectModel(model.id)) {
|
|
323
|
+
const key = options?.apiKey ?? process.env.GEMINI_API_KEY ?? process.env.GOOGLE_AI_API_KEY;
|
|
324
|
+
if (!key) {
|
|
325
|
+
if (throwIfMissing) throw new VrtConfigError("MISSING_KEY", `GEMINI_API_KEY (or GOOGLE_AI_API_KEY) is required for ${model.id}`);
|
|
326
|
+
return null;
|
|
327
|
+
}
|
|
328
|
+
return createGeminiClient(model, key);
|
|
329
|
+
}
|
|
330
|
+
if (isClaudeDirectModel(model.id)) {
|
|
331
|
+
const key = options?.apiKey ?? process.env.ANTHROPIC_API_KEY;
|
|
332
|
+
if (!key) {
|
|
333
|
+
if (throwIfMissing) throw new VrtConfigError("MISSING_KEY", `ANTHROPIC_API_KEY is required for ${model.id}`);
|
|
334
|
+
return null;
|
|
335
|
+
}
|
|
336
|
+
return createClaudeClient(model, key);
|
|
337
|
+
}
|
|
338
|
+
const key = options?.apiKey ?? process.env.OPENROUTER_API_KEY;
|
|
339
|
+
if (!key) {
|
|
340
|
+
if (throwIfMissing) throw new VrtConfigError("MISSING_KEY", `OPENROUTER_API_KEY is required for ${model.id}`);
|
|
341
|
+
return null;
|
|
342
|
+
}
|
|
343
|
+
async function callOpenRouter(messages, maxTokens) {
|
|
344
|
+
const start = Date.now();
|
|
345
|
+
const res = await fetch("https://openrouter.ai/api/v1/chat/completions", {
|
|
346
|
+
method: "POST",
|
|
347
|
+
headers: {
|
|
348
|
+
"Content-Type": "application/json",
|
|
349
|
+
"Authorization": `Bearer ${key}`,
|
|
350
|
+
"HTTP-Referer": "https://github.com/mizchi/vrt",
|
|
351
|
+
"X-Title": "vrt"
|
|
352
|
+
},
|
|
353
|
+
body: JSON.stringify({
|
|
354
|
+
model: model.id,
|
|
355
|
+
max_tokens: maxTokens,
|
|
356
|
+
messages
|
|
357
|
+
})
|
|
358
|
+
});
|
|
359
|
+
if (!res.ok) {
|
|
360
|
+
const text = await res.text();
|
|
361
|
+
throw new Error(`OpenRouter API error: ${res.status} ${text.slice(0, 200)}`);
|
|
362
|
+
}
|
|
363
|
+
const data = await res.json();
|
|
364
|
+
const latencyMs = Date.now() - start;
|
|
365
|
+
const usage = data.usage ?? {
|
|
366
|
+
prompt_tokens: 0,
|
|
367
|
+
completion_tokens: 0,
|
|
368
|
+
total_tokens: 0
|
|
369
|
+
};
|
|
370
|
+
const costUsd = usage.prompt_tokens / 1e3 * model.promptCostPer1k + usage.completion_tokens / 1e3 * model.completionCostPer1k;
|
|
371
|
+
return {
|
|
372
|
+
content: data.choices[0]?.message?.content ?? "",
|
|
373
|
+
model: model.id,
|
|
374
|
+
promptTokens: usage.prompt_tokens,
|
|
375
|
+
completionTokens: usage.completion_tokens,
|
|
376
|
+
totalTokens: usage.total_tokens,
|
|
377
|
+
costUsd,
|
|
378
|
+
latencyMs
|
|
379
|
+
};
|
|
380
|
+
}
|
|
381
|
+
const orClient = {
|
|
382
|
+
model,
|
|
383
|
+
async analyzeImage(imageBase64, prompt, options) {
|
|
384
|
+
return callOpenRouter([{
|
|
385
|
+
role: "user",
|
|
386
|
+
content: [{
|
|
387
|
+
type: "image_url",
|
|
388
|
+
image_url: { url: `data:image/png;base64,${imageBase64}` }
|
|
389
|
+
}, {
|
|
390
|
+
type: "text",
|
|
391
|
+
text: prompt
|
|
392
|
+
}]
|
|
393
|
+
}], options?.maxTokens ?? 1024);
|
|
394
|
+
},
|
|
395
|
+
async analyzeImageFile(imagePath, prompt, options) {
|
|
396
|
+
const buf = await readFile(imagePath);
|
|
397
|
+
return orClient.analyzeImage(buf.toString("base64"), prompt, options);
|
|
398
|
+
},
|
|
399
|
+
async analyzeDiff(baselineBase64, currentBase64, prompt, options) {
|
|
400
|
+
return callOpenRouter([{
|
|
401
|
+
role: "user",
|
|
402
|
+
content: [
|
|
403
|
+
{
|
|
404
|
+
type: "text",
|
|
405
|
+
text: "Baseline screenshot:"
|
|
406
|
+
},
|
|
407
|
+
{
|
|
408
|
+
type: "image_url",
|
|
409
|
+
image_url: { url: `data:image/png;base64,${baselineBase64}` }
|
|
410
|
+
},
|
|
411
|
+
{
|
|
412
|
+
type: "text",
|
|
413
|
+
text: "Current screenshot:"
|
|
414
|
+
},
|
|
415
|
+
{
|
|
416
|
+
type: "image_url",
|
|
417
|
+
image_url: { url: `data:image/png;base64,${currentBase64}` }
|
|
418
|
+
},
|
|
419
|
+
{
|
|
420
|
+
type: "text",
|
|
421
|
+
text: prompt
|
|
422
|
+
}
|
|
423
|
+
]
|
|
424
|
+
}], options?.maxTokens ?? 1024);
|
|
425
|
+
}
|
|
426
|
+
};
|
|
427
|
+
return orClient;
|
|
428
|
+
}
|
|
429
|
+
//#endregion
|
|
430
|
+
export { createVlmClient, fetchVisionModels, isClaudeDirectModel, isGeminiDirectModel, listClaudeModels, listGeminiModels, listModels, resolveClaudeModel, resolveGeminiModel, resolveModel };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mizchi/vlmkit-ai",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.1",
|
|
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",
|
|
@@ -14,21 +14,33 @@
|
|
|
14
14
|
"url": "https://github.com/mizchi/vlmkit/issues"
|
|
15
15
|
},
|
|
16
16
|
"type": "module",
|
|
17
|
+
"engines": {
|
|
18
|
+
"node": ">=24"
|
|
19
|
+
},
|
|
20
|
+
"publishConfig": {
|
|
21
|
+
"access": "public"
|
|
22
|
+
},
|
|
17
23
|
"files": [
|
|
18
|
-
"
|
|
19
|
-
"!src/**/*.test.ts",
|
|
24
|
+
"dist/**",
|
|
20
25
|
"README.md",
|
|
21
26
|
"LICENSE"
|
|
22
27
|
],
|
|
23
28
|
"exports": {
|
|
24
|
-
".":
|
|
25
|
-
|
|
29
|
+
".": {
|
|
30
|
+
"types": "./dist/index.d.mts",
|
|
31
|
+
"import": "./dist/index.mjs"
|
|
32
|
+
},
|
|
33
|
+
"./*.ts": {
|
|
34
|
+
"types": "./dist/*.d.mts",
|
|
35
|
+
"import": "./dist/*.mjs"
|
|
36
|
+
}
|
|
26
37
|
},
|
|
27
38
|
"dependencies": {
|
|
28
39
|
"@google/generative-ai": "^0.24.1",
|
|
29
|
-
"@mizchi/vlmkit-core": "0.
|
|
40
|
+
"@mizchi/vlmkit-core": "0.8.1"
|
|
30
41
|
},
|
|
31
42
|
"scripts": {
|
|
43
|
+
"build": "pnpm --dir ../.. exec tsdown --config tsdown.packages.config.ts --filter @mizchi/vlmkit-ai",
|
|
32
44
|
"test": "node --test 'src/**/*.test.ts'"
|
|
33
45
|
}
|
|
34
46
|
}
|
package/src/errors.ts
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tagged error class for factory functions in @mizchi/vlmkit-ai.
|
|
3
|
-
*
|
|
4
|
-
* Factories (`createVlmClient`, `createUnifiedLLMClient`,
|
|
5
|
-
* `createLLMProvider`, `createReasoningPipeline`) historically returned
|
|
6
|
-
* `null` when configuration was missing or invalid. The caller had no way
|
|
7
|
-
* to discriminate between "no API key", "invalid model id", "ambiguous
|
|
8
|
-
* model substring", or "provider value unknown" — every failure mode
|
|
9
|
-
* collapsed into one nullable.
|
|
10
|
-
*
|
|
11
|
-
* From 0.5.0 the factories throw `VrtConfigError` by default. Callers
|
|
12
|
-
* that want the legacy null behaviour pass `{ throwIfMissing: false }`.
|
|
13
|
-
*
|
|
14
|
-
* Codes are stable; new ones can only be added (never renumbered or
|
|
15
|
-
* removed) in minor versions.
|
|
16
|
-
*/
|
|
17
|
-
export type VrtConfigErrorCode =
|
|
18
|
-
/** Required env var (`OPENROUTER_API_KEY`, `GEMINI_API_KEY`, `ANTHROPIC_API_KEY`) not set. */
|
|
19
|
-
| "MISSING_KEY"
|
|
20
|
-
/** Provider/model id doesn't resolve. */
|
|
21
|
-
| "INVALID_MODEL"
|
|
22
|
-
/** Model substring matches more than one candidate. */
|
|
23
|
-
| "MULTIPLE_MATCHES"
|
|
24
|
-
/** `VRT_LLM_PROVIDER` value is not one of the known providers. */
|
|
25
|
-
| "INVALID_PROVIDER"
|
|
26
|
-
/** No provider in the fallback chain has an API key configured. */
|
|
27
|
-
| "NO_PROVIDER_AVAILABLE"
|
|
28
|
-
/** An optional runtime dependency (e.g. `@google/generative-ai`) failed to import. */
|
|
29
|
-
| "MISSING_DEPENDENCY"
|
|
30
|
-
/** Caller-supplied request parameters are malformed (empty prompt, out-of-range size, etc.). */
|
|
31
|
-
| "INVALID_REQUEST";
|
|
32
|
-
|
|
33
|
-
export class VrtConfigError extends Error {
|
|
34
|
-
readonly code: VrtConfigErrorCode;
|
|
35
|
-
|
|
36
|
-
constructor(code: VrtConfigErrorCode, message: string) {
|
|
37
|
-
super(message);
|
|
38
|
-
this.name = "VrtConfigError";
|
|
39
|
-
this.code = code;
|
|
40
|
-
}
|
|
41
|
-
}
|