@abhishek944/pi-classifier 0.4.0 → 0.5.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.
Files changed (58) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/README.md +269 -31
  3. package/dist/auth.d.ts +4 -2
  4. package/dist/auth.js +18 -2
  5. package/dist/box-tool.d.ts +2 -24
  6. package/dist/box-tool.js +5 -35
  7. package/dist/choices.js +35 -1
  8. package/dist/classify.d.ts +3 -0
  9. package/dist/classify.js +3 -3
  10. package/dist/config.d.ts +140 -3
  11. package/dist/config.js +401 -20
  12. package/dist/cost.js +42 -4
  13. package/dist/durable.d.ts +34 -0
  14. package/dist/durable.js +237 -0
  15. package/dist/extension.d.ts +2 -275
  16. package/dist/extension.js +49 -211
  17. package/dist/extract.d.ts +11 -0
  18. package/dist/extract.js +191 -0
  19. package/dist/http.d.ts +6 -1
  20. package/dist/http.js +64 -28
  21. package/dist/index.d.ts +3 -1
  22. package/dist/index.js +1 -0
  23. package/dist/inputs.d.ts +16 -1
  24. package/dist/inputs.js +421 -14
  25. package/dist/mcp-cli.d.ts +2 -0
  26. package/dist/mcp-cli.js +39 -0
  27. package/dist/mcp-server.d.ts +28 -0
  28. package/dist/mcp-server.js +121 -0
  29. package/dist/mcp-tool-definitions.d.ts +19 -0
  30. package/dist/mcp-tool-definitions.js +64 -0
  31. package/dist/providers.d.ts +1 -0
  32. package/dist/providers.js +1144 -53
  33. package/dist/tool-contracts.d.ts +785 -0
  34. package/dist/tool-contracts.js +530 -0
  35. package/dist/tree.js +1 -1
  36. package/dist/types.d.ts +284 -8
  37. package/dist/validation.js +122 -10
  38. package/package.json +34 -6
  39. package/src/auth.ts +26 -2
  40. package/src/box-tool.ts +12 -47
  41. package/src/choices.ts +42 -1
  42. package/src/classify.ts +6 -4
  43. package/src/config.ts +450 -23
  44. package/src/cost.ts +42 -4
  45. package/src/durable.ts +298 -0
  46. package/src/extension.ts +75 -288
  47. package/src/extract.ts +228 -0
  48. package/src/http.ts +63 -32
  49. package/src/index.ts +15 -0
  50. package/src/inputs.ts +454 -13
  51. package/src/mcp-cli.ts +44 -0
  52. package/src/mcp-server.ts +179 -0
  53. package/src/mcp-tool-definitions.ts +104 -0
  54. package/src/providers.ts +1323 -56
  55. package/src/tool-contracts.ts +785 -0
  56. package/src/tree.ts +1 -1
  57. package/src/types.ts +231 -5
  58. package/src/validation.ts +114 -9
package/dist/config.js CHANGED
@@ -8,6 +8,88 @@ import { choicePolicy } from "./choices.js";
8
8
  import { ClassifierError, isRecord, } from "./types.js";
9
9
  export const SETTINGS_KEY = "pi-classifier";
10
10
  export const BUILT_INS = [
11
+ {
12
+ id: "llamacpp",
13
+ route: "llamacpp-api",
14
+ api: "local-system-one",
15
+ baseUrl: "",
16
+ credentialProvider: "llamacpp",
17
+ envVar: "",
18
+ models: [
19
+ { id: "LiquidAI/d1-2B", input: ["text", "image"] },
20
+ { id: "LiquidAI/d1-Omni-2B", input: ["text", "image", "audio", "video"] },
21
+ { id: "LiquidAI/d1-omni-600M", input: ["text", "image", "audio"] },
22
+ ],
23
+ },
24
+ {
25
+ id: "vllm",
26
+ route: "vllm-api",
27
+ api: "local-system-one",
28
+ baseUrl: "",
29
+ credentialProvider: "vllm",
30
+ envVar: "VLLM_API_KEY",
31
+ models: [
32
+ { id: "Qwen/Qwen3-0.6B", input: ["text"] },
33
+ { id: "LiquidAI/d1-3B", input: ["text", "image"] },
34
+ ],
35
+ },
36
+ {
37
+ id: "strands",
38
+ route: "strands-api",
39
+ api: "local-system-one",
40
+ baseUrl: "",
41
+ credentialProvider: "strands",
42
+ envVar: "",
43
+ models: [{ id: "StrandsAgents/strands-decider-E2B-gemma4-v1-2610", input: ["text"] }],
44
+ },
45
+ {
46
+ id: "laya",
47
+ route: "laya-api",
48
+ api: "local-system-one",
49
+ baseUrl: "",
50
+ credentialProvider: "laya",
51
+ envVar: "LAYA_API_KEY",
52
+ models: [
53
+ { id: "english", input: ["text"] },
54
+ { id: "multilingual", input: ["text"] },
55
+ { id: "typed-decisions", input: ["text"] },
56
+ ],
57
+ },
58
+ {
59
+ id: "nimble",
60
+ route: "nimble-api",
61
+ api: "local-system-one",
62
+ baseUrl: "",
63
+ credentialProvider: "nimble",
64
+ envVar: "",
65
+ models: [{ id: "nimble", input: ["text"] }],
66
+ },
67
+ {
68
+ id: "openrouter",
69
+ route: "openrouter-extractions-api",
70
+ api: "openrouter-extractions",
71
+ baseUrl: "https://openrouter.ai/api",
72
+ credentialProvider: "openrouter",
73
+ envVar: "OPENROUTER_API_KEY",
74
+ models: [
75
+ { id: "cloudflare/clairic", input: ["text", "image"] },
76
+ { id: "inception/mercury-decide", input: ["text"] },
77
+ { id: "liquid/d1.2", input: ["text", "image"] },
78
+ { id: "liquid/d1.2-ultra", input: ["text", "image"] },
79
+ { id: "perplexity/pplx-decider-v1.3", input: ["text"] },
80
+ { id: "perplexity/pplx-decider-flash-v1.3", input: ["text"] },
81
+ { id: "scaledown/extract", input: ["text", "image"] },
82
+ ],
83
+ },
84
+ {
85
+ id: "litellm",
86
+ route: "litellm-extraction-api",
87
+ api: "litellm-extraction",
88
+ baseUrl: "",
89
+ credentialProvider: "litellm",
90
+ envVar: "LITELLM_API_KEY",
91
+ models: [{ id: "clairic", input: ["text", "image"] }],
92
+ },
11
93
  {
12
94
  id: "microsoft",
13
95
  route: "microsoft-api",
@@ -15,7 +97,22 @@ export const BUILT_INS = [
15
97
  baseUrl: "",
16
98
  credentialProvider: "microsoft",
17
99
  envVar: "AZURE_API_KEY",
18
- models: [{ id: "Microsoft-Decision-1", input: ["text"] }],
100
+ models: [
101
+ { id: "Microsoft-Decision-1.1", input: ["text", "image"] },
102
+ { id: "Microsoft-Decision-1", input: ["text"] },
103
+ ],
104
+ },
105
+ {
106
+ id: "sarvam",
107
+ route: "sarvam-api",
108
+ api: "sarvam-system-one",
109
+ baseUrl: "https://api.sarvam.ai/v2",
110
+ credentialProvider: "sarvam",
111
+ envVar: "SARVAM_API_KEY",
112
+ models: [
113
+ { id: "sarvam-prism", input: ["text"] },
114
+ { id: "clef", input: ["text", "image"] },
115
+ ],
19
116
  },
20
117
  {
21
118
  id: "openai",
@@ -26,6 +123,47 @@ export const BUILT_INS = [
26
123
  envVar: "OPENAI_API_KEY",
27
124
  models: [{ id: "gpt-6-luna", input: ["text", "image"] }],
28
125
  },
126
+ {
127
+ id: "vercel",
128
+ route: "vercel-api",
129
+ api: "openai-decisions",
130
+ baseUrl: "https://ai-gateway.vercel.sh/v1",
131
+ credentialProvider: "vercel",
132
+ envVar: "VERCEL_AI_GATEWAY_API_KEY",
133
+ models: [
134
+ { id: "openai/gpt-6-luna-decisions", input: ["text", "image"] },
135
+ { id: "typesafe-ai/jev", input: ["text"] },
136
+ ],
137
+ },
138
+ {
139
+ id: "gemini",
140
+ route: "gemini-api",
141
+ api: "gemini-decisions",
142
+ baseUrl: "https://generativelanguage.googleapis.com/v1beta",
143
+ credentialProvider: "gemini",
144
+ envVar: "GEMINI_API_KEY",
145
+ models: [
146
+ { id: "gemini-decision-1", input: ["text", "image", "audio", "video"] },
147
+ ],
148
+ },
149
+ {
150
+ id: "inception",
151
+ route: "inception-api",
152
+ api: "inception-decisions",
153
+ baseUrl: "https://api.inceptionlabs.ai/v1",
154
+ credentialProvider: "inception",
155
+ envVar: "INCEPTION_API_KEY",
156
+ models: [{ id: "mercury-decide", input: ["text", "image"] }],
157
+ },
158
+ {
159
+ id: "parallel",
160
+ route: "parallel-api",
161
+ api: "parallel-decisions",
162
+ baseUrl: "https://api.parallel.ai/v1",
163
+ credentialProvider: "parallel",
164
+ envVar: "PARALLEL_API_KEY",
165
+ models: [{ id: "parallel-decisions", input: ["text"] }],
166
+ },
29
167
  {
30
168
  id: "perplexity",
31
169
  route: "perplexity-api",
@@ -34,6 +172,8 @@ export const BUILT_INS = [
34
172
  credentialProvider: "perplexity",
35
173
  envVar: "PERPLEXITY_API_KEY",
36
174
  models: [
175
+ { id: "pplx-decider-v1.3", input: ["text", "image"] },
176
+ { id: "pplx-decider-flash-v1.3", input: ["text", "image"] },
37
177
  { id: "pplx-decider-v1.2", input: ["text", "image"] },
38
178
  { id: "pplx-decider-flash-v1.2", input: ["text", "image"] },
39
179
  { id: "pplx-decider-latest", input: ["text", "image"] },
@@ -42,6 +182,18 @@ export const BUILT_INS = [
42
182
  { id: "pplx-decider-v1-27b", input: ["text", "image"] },
43
183
  ],
44
184
  },
185
+ {
186
+ id: "liquid",
187
+ route: "liquid-api",
188
+ api: "liquid-system-one",
189
+ baseUrl: "https://api.liquid.ai/decisions/v1",
190
+ credentialProvider: "liquid",
191
+ envVar: "LIQUID_API_KEY",
192
+ models: [
193
+ { id: "d1.2", input: ["text", "image", "audio"], box: true },
194
+ { id: "d1.2-ultra", input: ["text", "image", "audio"], box: true },
195
+ ],
196
+ },
45
197
  {
46
198
  id: "typesafe",
47
199
  route: "typesafe-api",
@@ -66,9 +218,19 @@ export const BUILT_INS = [
66
218
  models: [
67
219
  { id: "@cf/cloudflare/clef", input: ["text", "image"] },
68
220
  { id: "@cf/cloudflare/clef-flash", input: ["text", "image"] },
221
+ { id: "@cf/cloudflare/clef-omni", input: ["text", "image", "audio", "video"] },
69
222
  { id: "typesafe/jev" },
70
223
  ],
71
224
  },
225
+ {
226
+ id: "clairic",
227
+ route: "clairic-api",
228
+ api: "cloudflare-clairic",
229
+ baseUrl: "",
230
+ credentialProvider: "cloudflare-workers-ai",
231
+ envVar: "CLOUDFLARE_API_KEY",
232
+ models: [{ id: "@cf/cloudflare/clairic", input: ["text", "image"] }],
233
+ },
72
234
  {
73
235
  id: "openrouter",
74
236
  route: "openrouter-api",
@@ -78,7 +240,147 @@ export const BUILT_INS = [
78
240
  envVar: "OPENROUTER_API_KEY",
79
241
  models: [{ id: "typesafe/jev-1.13" }, { id: "~typesafe/jev-latest" }],
80
242
  },
243
+ {
244
+ id: "openrouter",
245
+ route: "openrouter-decisions-api",
246
+ api: "openrouter-decisions",
247
+ baseUrl: "https://openrouter.ai/api",
248
+ credentialProvider: "openrouter",
249
+ envVar: "OPENROUTER_API_KEY",
250
+ models: [
251
+ { id: "typesafe/jev-1.14", input: ["text", "image"], box: true },
252
+ { id: "~typesafe/jev-latest", input: ["text", "image"], box: true },
253
+ { id: "typesafe/jev-1.13", input: ["text", "image"] },
254
+ { id: "microsoft/microsoft-decision-1.1", input: ["text", "image"] },
255
+ { id: "cloudflare/clef-flash", input: ["text", "image"] },
256
+ { id: "cloudflare/clef-omni", input: ["text", "image", "audio", "video"] },
257
+ { id: "inception/mercury-decide", input: ["text", "image"] },
258
+ { id: "liquid/d1.2", input: ["text", "image"] },
259
+ { id: "liquid/d1.2-ultra", input: ["text", "image"] },
260
+ { id: "openai/gpt-6-luna-decisions", input: ["text", "image"] },
261
+ { id: "google/gemini-decision-1", input: ["text", "image", "audio", "video"] },
262
+ { id: "heygen/heygen-decision-1", input: ["text", "image", "audio", "video"] },
263
+ { id: "heygen/heygen-decision-1-turbo", input: ["text", "image", "audio", "video"] },
264
+ { id: "parallel/parallel-decisions", input: ["text"] },
265
+ ],
266
+ },
81
267
  ];
268
+ /** Keep legacy provider-id aliases pointed at their original classify route when one provider exposes several APIs. */
269
+ const PREFERRED_ROUTE_BY_ID = { openrouter: "openrouter-api" };
270
+ /** Largest documented envelope among built-in adapters; per-route limits narrow it before any request. */
271
+ const DEFAULT_LIMITS = {
272
+ maxQuestions: 1000,
273
+ maxImages: 128,
274
+ maxAudio: 10,
275
+ maxVideo: 10,
276
+ };
277
+ /** Field tiers from OpenRouter's Extractions guide; unknown models default to text-only. */
278
+ export function openRouterExtractionCapabilities(model) {
279
+ const textOnly = { fieldTypes: ["text", "list"], maxFields: 128, maxImages: 0, maxDocuments: 0, maxAssets: 0, referenceDate: false };
280
+ if (model === "cloudflare/clairic")
281
+ return {
282
+ fieldTypes: ["text", "number", "date", "time", "datetime", "duration", "list", "estimate", "forecast"],
283
+ maxFields: 128,
284
+ maxImages: 4,
285
+ maxDocuments: 0,
286
+ maxAssets: 4,
287
+ referenceDate: true,
288
+ };
289
+ if (/^liquid\/d1\.2/.test(model))
290
+ return { fieldTypes: ["text", "number", "date", "list", "estimate"], maxFields: 128, maxImages: 8, maxDocuments: 0, maxAssets: 8, referenceDate: false };
291
+ if (model === "scaledown/extract")
292
+ return { ...textOnly, maxImages: 1, maxDocuments: 1, maxAssets: 1 };
293
+ if (/^inference-net\/schematron-v2-/.test(model))
294
+ return { ...textOnly, fieldTypes: ["text", "number", "date", "time", "datetime", "list"] };
295
+ return textOnly;
296
+ }
297
+ /** Defaults come from OpenRouter's published Decisions adapter registry and multimodal limits. */
298
+ export function openRouterDecisionCapabilities(model) {
299
+ if (/^~?typesafe\/jev-(?:1\.14|latest)$/.test(model))
300
+ return { flexibleImagePlacement: true, box: true, remoteImageUrls: false, images: 128, audio: 0, video: 0 };
301
+ if (model === "typesafe/jev-1.13")
302
+ return { flexibleImagePlacement: true, box: false, remoteImageUrls: false, images: 128, audio: 0, video: 0 };
303
+ if (model === "microsoft/microsoft-decision-1.1")
304
+ return { flexibleImagePlacement: true, box: false, remoteImageUrls: false, images: 8, audio: 0, video: 0 };
305
+ if (model === "cloudflare/clef-omni")
306
+ return { flexibleImagePlacement: false, box: false, remoteImageUrls: false, images: 4, audio: 4, video: 2 };
307
+ if (/^cloudflare\/clef(?:-flash)?$/.test(model))
308
+ return { flexibleImagePlacement: false, box: false, remoteImageUrls: false, images: 4, audio: 0, video: 0 };
309
+ if (/^heygen\/heygen-decision-1(?:-turbo)?$/.test(model))
310
+ return { flexibleImagePlacement: false, box: false, remoteImageUrls: true, images: 100, audio: 10, video: 10 };
311
+ if (model === "google/gemini-decision-1")
312
+ return { flexibleImagePlacement: false, box: false, remoteImageUrls: true, images: 128, audio: 10, video: 10 };
313
+ if (model === "inception/mercury-decide")
314
+ return { flexibleImagePlacement: false, box: false, remoteImageUrls: false, images: 16, audio: 0, video: 0 };
315
+ if (/^liquid\/d1(?:\.2(?:-ultra)?|-2B|-omni.*)?$/.test(model))
316
+ return { flexibleImagePlacement: false, box: false, remoteImageUrls: false, images: 8, audio: 0, video: 0 };
317
+ if (/^baseten\//.test(model) || /^morph\//.test(model))
318
+ return { flexibleImagePlacement: false, box: false, remoteImageUrls: false, images: 16, audio: 0, video: 0 };
319
+ if (/^deepinfra\//.test(model) || /^makora\//.test(model) || /^prime-intellect\//.test(model))
320
+ return { flexibleImagePlacement: false, box: false, remoteImageUrls: false, images: 4, audio: 0, video: 0 };
321
+ if (model === "openai/gpt-6-luna-decisions")
322
+ return { flexibleImagePlacement: false, box: false, remoteImageUrls: false, images: 128, audio: 0, video: 0 };
323
+ return { flexibleImagePlacement: false, box: false, remoteImageUrls: false, images: 0, audio: 0, video: 0 };
324
+ }
325
+ function builtInLimits(api, provider, model) {
326
+ if (api === "openai-decisions")
327
+ return { ...DEFAULT_LIMITS, maxQuestions: 400 };
328
+ if (api === "openrouter-extractions") {
329
+ const caps = openRouterExtractionCapabilities(model);
330
+ return { ...DEFAULT_LIMITS, maxImages: caps.maxImages, maxAudio: 0, maxVideo: 0 };
331
+ }
332
+ if (api === "litellm-extraction")
333
+ return { ...DEFAULT_LIMITS, maxImages: 4, maxAudio: 0, maxVideo: 0 };
334
+ if (api === "parallel-decisions")
335
+ return { ...DEFAULT_LIMITS, maxQuestions: 100, maxImages: 0, maxAudio: 0, maxVideo: 0 };
336
+ if (api === "local-system-one") {
337
+ const maxQuestions = provider === "vllm" ? 64 : provider === "laya" ? 32 : provider === "nimble" ? 64 : provider === "strands" ? 32 : DEFAULT_LIMITS.maxQuestions;
338
+ const maxImages = provider === "llamacpp" || provider === "vllm" || provider === "strands" ? DEFAULT_LIMITS.maxImages : 0;
339
+ return { ...DEFAULT_LIMITS, maxQuestions, maxImages };
340
+ }
341
+ if (api === "openrouter-decisions") {
342
+ const caps = openRouterDecisionCapabilities(model);
343
+ return { ...DEFAULT_LIMITS, maxImages: caps.images, maxAudio: caps.audio, maxVideo: caps.video };
344
+ }
345
+ if (api === "perplexity-decisions")
346
+ return { ...DEFAULT_LIMITS, maxQuestions: 128, maxImages: 8, maxAudio: 0, maxVideo: 0 };
347
+ if (api === "liquid-system-one")
348
+ return { ...DEFAULT_LIMITS, maxQuestions: 128, maxImages: 8, maxAudio: 8, maxVideo: 0 };
349
+ if (api === "cloudflare-system-one") {
350
+ const omni = model === "@cf/cloudflare/clef-omni";
351
+ const clef = provider === "cloudflare" && model.startsWith("@cf/cloudflare/clef");
352
+ return {
353
+ ...DEFAULT_LIMITS,
354
+ maxQuestions: clef ? 64 : DEFAULT_LIMITS.maxQuestions,
355
+ maxImages: clef ? 4 : 0,
356
+ maxAudio: omni ? 4 : 0,
357
+ maxVideo: omni ? 2 : 0,
358
+ };
359
+ }
360
+ if (api === "microsoft-system-one")
361
+ return { ...DEFAULT_LIMITS, maxAudio: 0, maxVideo: 0 };
362
+ if (api === "sarvam-system-one")
363
+ return { ...DEFAULT_LIMITS, maxImages: model === "clef" ? DEFAULT_LIMITS.maxImages : 0, maxAudio: 0, maxVideo: 0 };
364
+ return { ...DEFAULT_LIMITS };
365
+ }
366
+ function configuredLimits(value, api, provider, model) {
367
+ const base = builtInLimits(api, provider, model);
368
+ if (value === undefined)
369
+ return base;
370
+ if (!isRecord(value) || Object.keys(value).some((key) => !["maxQuestions", "maxImages", "maxAudio", "maxVideo"].includes(key)))
371
+ return configuration("limits may only set maxQuestions, maxImages, maxAudio and maxVideo.");
372
+ const limits = { ...base };
373
+ for (const key of ["maxQuestions", "maxImages", "maxAudio", "maxVideo"]) {
374
+ const entry = value[key];
375
+ if (entry === undefined)
376
+ continue;
377
+ const minimum = key === "maxQuestions" ? 1 : 0;
378
+ if (!Number.isSafeInteger(entry) || entry < minimum)
379
+ return configuration(key + " must be a safe integer of at least " + minimum + ".");
380
+ limits[key] = entry;
381
+ }
382
+ return limits;
383
+ }
82
384
  export function loadClassifierSettings(cwd, projectTrusted = false) {
83
385
  try {
84
386
  // The shared loader is forgiving; malformed layers must not silently select a different route.
@@ -159,6 +461,7 @@ function headers(value) {
159
461
  const protectedNames = [
160
462
  "authorization",
161
463
  "api-key",
464
+ "api-subscription-key",
162
465
  "content-type",
163
466
  "content-length",
164
467
  "host",
@@ -195,14 +498,16 @@ export function configuredRoutes(settings, field) {
195
498
  return configuration(field + " must be an array of provider/model pairs.");
196
499
  return value.map((entry, index) => routePair(entry, field + "[" + index + "]"));
197
500
  }
198
- export function resolveModel(settings, selected = configuredDefault(settings)) {
501
+ export function resolveModel(settings, selected = configuredDefault(settings), source = "pi-store") {
199
502
  choicePolicy(settings);
200
503
  const { provider: routeId, model: modelId } = routePair(selected, "route");
201
504
  if (!/^[a-zA-Z0-9][a-zA-Z0-9_-]{0,63}$/.test(routeId) ||
202
505
  modelId.length > 256 ||
203
506
  /[\u0000-\u001f\u007f]/.test(modelId))
204
507
  return configuration("Provider routes must be short identifiers and model IDs must be at most 256 characters without control characters.");
205
- const builtIn = BUILT_INS.find((entry) => entry.route === routeId || entry.id === routeId);
508
+ const builtIn = BUILT_INS.find((entry) => entry.route === routeId) ??
509
+ BUILT_INS.find((entry) => entry.route === PREFERRED_ROUTE_BY_ID[routeId]) ??
510
+ BUILT_INS.find((entry) => entry.id === routeId);
206
511
  if (settings.providers !== undefined && !isRecord(settings.providers))
207
512
  return configuration("providers must be an object.");
208
513
  if (settings.customProviders !== undefined &&
@@ -223,9 +528,19 @@ export function resolveModel(settings, selected = configuredDefault(settings)) {
223
528
  const api = builtIn?.api ?? custom.api;
224
529
  if (![
225
530
  "openai-decisions",
531
+ "openrouter-decisions",
532
+ "gemini-decisions",
533
+ "inception-decisions",
534
+ "parallel-decisions",
535
+ "local-system-one",
226
536
  "perplexity-decisions",
537
+ "sarvam-system-one",
227
538
  "system-one",
539
+ "liquid-system-one",
228
540
  "cloudflare-system-one",
541
+ "cloudflare-clairic",
542
+ "openrouter-extractions",
543
+ "litellm-extraction",
229
544
  "microsoft-system-one",
230
545
  ].includes(api))
231
546
  return configuration("Unsupported classifier API protocol.");
@@ -237,7 +552,7 @@ export function resolveModel(settings, selected = configuredDefault(settings)) {
237
552
  !m.id.trim() ||
238
553
  (m.input !== undefined &&
239
554
  (!Array.isArray(m.input) ||
240
- m.input.some((x) => x !== "text" && x !== "image"))) ||
555
+ m.input.some((x) => x !== "text" && x !== "image" && x !== "audio" && x !== "video"))) ||
241
556
  (m.box !== undefined && typeof m.box !== "boolean"))) {
242
557
  return configuration("Provider models must declare an id and optional text/image input capabilities.");
243
558
  }
@@ -245,18 +560,35 @@ export function resolveModel(settings, selected = configuredDefault(settings)) {
245
560
  // Built-in API routes allow new text model IDs without a package release. Images require known capabilities.
246
561
  if (!definition && !builtIn)
247
562
  return configuration("The selected model is not declared in customProviders.<id>.models.");
248
- for (const flag of ["experimentalImages", "experimentalBox"]) {
563
+ for (const flag of ["experimentalImages", "experimentalBox", "longContext"]) {
249
564
  if (raw[flag] !== undefined && typeof raw[flag] !== "boolean")
250
565
  return configuration(flag + " must be a boolean.");
251
566
  }
567
+ const authMode = raw.authMode;
568
+ if (authMode !== undefined && authMode !== "api-key" && authMode !== "bearer" && authMode !== "google-api-key" && authMode !== "parallel-api-key" && authMode !== "none")
569
+ return configuration("authMode must be api-key, bearer, google-api-key, parallel-api-key or none.");
570
+ if (authMode === "none" && api !== "local-system-one")
571
+ return configuration("authMode none is supported only by local System One routes.");
572
+ const resolvedAuthMode = authMode ??
573
+ (api === "microsoft-system-one"
574
+ ? "api-key"
575
+ : api === "sarvam-system-one"
576
+ ? authMode ?? "subscription-key"
577
+ : api === "gemini-decisions"
578
+ ? "google-api-key"
579
+ : api === "parallel-decisions"
580
+ ? "parallel-api-key"
581
+ : api === "local-system-one"
582
+ ? "none"
583
+ : "bearer");
252
584
  let baseUrl = optionalString(raw.baseUrl, "baseUrl") ?? builtIn?.baseUrl;
253
- if (api === "cloudflare-system-one" && !baseUrl)
585
+ if ((api === "cloudflare-system-one" || api === "cloudflare-clairic") && !baseUrl)
254
586
  baseUrl =
255
587
  "https://api.cloudflare.com/client/v4/accounts/" +
256
- cloudflareAccountId(optionalString(raw.accountId, "accountId")) +
588
+ cloudflareAccountId(optionalString(raw.accountId, "accountId"), source) +
257
589
  "/ai";
258
590
  if (!baseUrl)
259
- return configuration("The selected provider requires a baseUrl. Microsoft uses your Foundry resource endpoint.");
591
+ return configuration("The selected provider requires a baseUrl. Microsoft uses your Foundry resource endpoint; local runtimes use your server URL.");
260
592
  const timeout = settings.requestTimeoutMs ?? 30_000;
261
593
  if (!Number.isInteger(timeout) || timeout < 100 || timeout > 300_000)
262
594
  return configuration("requestTimeoutMs must be between 100 and 300000.");
@@ -265,27 +597,65 @@ export function resolveModel(settings, selected = configuredDefault(settings)) {
265
597
  const configuredApiKey = typeof raw.apiKey === "string" ? raw.apiKey.trim() || undefined : undefined;
266
598
  if (configuredApiKey && /\$\{?|^!/.test(configuredApiKey))
267
599
  return configuration("API-key references must be resolved in global settings; project settings cannot expand environment variables or execute commands.");
600
+ const gatewayId = optionalString(raw.gatewayId, "gatewayId");
601
+ if (gatewayId !== undefined && (/[\r\n]/.test(gatewayId) || /\$\{?[A-Z_]/.test(gatewayId)))
602
+ return configuration("Gateway IDs must be resolved in global settings and cannot contain line breaks.");
603
+ const resolvedHeaders = headers(raw.headers);
604
+ if ((api === "cloudflare-system-one" || api === "cloudflare-clairic") &&
605
+ gatewayId !== undefined) {
606
+ for (const key of Object.keys(resolvedHeaders))
607
+ if (key.toLowerCase() === "cf-aig-gateway-id" && key !== "cf-aig-gateway-id")
608
+ delete resolvedHeaders[key];
609
+ resolvedHeaders["cf-aig-gateway-id"] = gatewayId;
610
+ }
268
611
  const isJevDirect = builtIn?.id === "typesafe";
612
+ const openRouter = api === "openrouter-decisions" ? openRouterDecisionCapabilities(modelId) : undefined;
269
613
  const result = {
270
614
  route: builtIn?.route ?? routeId,
271
615
  provider: builtIn?.id ?? routeId,
272
616
  model: modelId,
273
617
  api,
618
+ mediaFormat: api === "system-one" ? "jev-assets" : openRouter ? "openrouter-parts" : "base64-object",
274
619
  baseUrl: validateBaseUrl(baseUrl),
275
- headers: headers(raw.headers),
620
+ headers: resolvedHeaders,
621
+ ...(gatewayId !== undefined ? { gatewayId } : {}),
276
622
  credentialProvider: builtIn?.credentialProvider ?? routeId,
277
- images: api === "microsoft-system-one"
278
- ? false
623
+ images: openRouter
624
+ ? openRouter.images > 0
279
625
  : api === "system-one"
280
626
  ? Boolean(raw.experimentalImages && definition?.input?.includes("image"))
281
627
  : Boolean(definition?.input?.includes("image")),
282
- box: Boolean((isJevDirect || custom?.api === "system-one") &&
283
- definition?.box &&
284
- definition?.input?.includes("image") &&
285
- raw.experimentalBox &&
286
- raw.experimentalImages),
628
+ audio: openRouter
629
+ ? openRouter.audio > 0
630
+ : Boolean((api === "liquid-system-one" ||
631
+ api === "cloudflare-system-one" ||
632
+ api === "gemini-decisions" ||
633
+ api === "local-system-one") &&
634
+ definition?.input?.includes("audio")),
635
+ video: openRouter
636
+ ? openRouter.video > 0
637
+ : Boolean((api === "cloudflare-system-one" ||
638
+ api === "gemini-decisions" ||
639
+ api === "local-system-one") &&
640
+ definition?.input?.includes("video")),
641
+ box: Boolean(openRouter
642
+ ? openRouter.box &&
643
+ definition?.box &&
644
+ definition?.input?.includes("image") &&
645
+ raw.experimentalBox &&
646
+ raw.experimentalImages
647
+ : api === "liquid-system-one"
648
+ ? definition?.box && definition?.input?.includes("image")
649
+ : (isJevDirect || custom?.api === "system-one") &&
650
+ definition?.box &&
651
+ definition?.input?.includes("image") &&
652
+ raw.experimentalBox &&
653
+ raw.experimentalImages),
287
654
  experimentalImages: raw.experimentalImages === true,
655
+ authMode: resolvedAuthMode,
656
+ longContext: raw.longContext === true,
288
657
  requestTimeoutMs: timeout,
658
+ limits: configuredLimits(raw.limits, api, builtIn?.id, modelId),
289
659
  };
290
660
  const pricing = resolvePricing(result.provider, modelId, result.baseUrl, raw.pricing);
291
661
  if (pricing)
@@ -312,14 +682,22 @@ function knownMaxChoices(route) {
312
682
  const directJev = route.provider === "typesafe" &&
313
683
  route.baseUrl === "https://api.typesafe.ai/v1" &&
314
684
  ["jev-latest", "jev-preview", "jev-1.13.0", "jev-1.14.0"].includes(route.model);
315
- const openai = route.provider === "openai" &&
685
+ const sarvam = route.provider === "sarvam" &&
686
+ route.baseUrl === "https://api.sarvam.ai/v2" &&
687
+ route.model === "sarvam-prism";
688
+ const openai = (route.provider === "openai" &&
316
689
  route.baseUrl === "https://api.openai.com/v1" &&
317
- route.model === "gpt-6-luna";
690
+ route.model === "gpt-6-luna") ||
691
+ (route.provider === "vercel" &&
692
+ route.baseUrl === "https://ai-gateway.vercel.sh/v1" &&
693
+ ["openai/gpt-6-luna-decisions", "typesafe-ai/jev"].includes(route.model));
318
694
  const perplexity = route.provider === "perplexity" &&
319
695
  route.baseUrl === "https://api.perplexity.ai/v1" &&
320
696
  [
321
697
  "pplx-decider-v1.1-27b",
322
698
  "pplx-decider-v1-27b",
699
+ "pplx-decider-v1.3",
700
+ "pplx-decider-flash-v1.3",
323
701
  "pplx-decider-v1.2",
324
702
  "pplx-decider-latest",
325
703
  "pplx-decider-flash-v1.2",
@@ -327,8 +705,11 @@ function knownMaxChoices(route) {
327
705
  ].includes(route.model);
328
706
  const clef = route.provider === "cloudflare" &&
329
707
  /^https:\/\/api\.cloudflare\.com\/client\/v4\/accounts\/[^/]+\/ai$/.test(route.baseUrl) &&
330
- ["@cf/cloudflare/clef", "@cf/cloudflare/clef-flash"].includes(route.model);
331
- return directJev || openai || perplexity || clef ? 255 : undefined;
708
+ ["@cf/cloudflare/clef", "@cf/cloudflare/clef-flash", "@cf/cloudflare/clef-omni"].includes(route.model);
709
+ const liquid = route.provider === "liquid" &&
710
+ route.baseUrl === "https://api.liquid.ai/decisions/v1" &&
711
+ ["d1.2", "d1.2-ultra"].includes(route.model);
712
+ return directJev || sarvam || openai || perplexity || clef || liquid ? 255 : undefined;
332
713
  }
333
714
  export function listModels(settings) {
334
715
  const lines = BUILT_INS.flatMap((provider) => provider.models.map((model) => provider.route + " " + model.id));
package/dist/cost.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { ClassifierError, isRecord, } from "./types.js";
2
2
  // Standard public USD rates, not account-specific billing. Sources and caveats are in README.
3
3
  // Keep exact model matches: newer IDs and other hosts must not inherit guessed prices.
4
+ // Sarvam publishes INR rates, so it has no automatic USD entry here; use explicit pricing overrides.
4
5
  const PRICES = {
5
6
  openai: {
6
7
  "gpt-6-luna": {
@@ -15,6 +16,8 @@ const PRICES = {
15
16
  { inputPerMillion: 0.042, outputPerMillion: 0 },
16
17
  ])),
17
18
  perplexity: {
19
+ "pplx-decider-v1.3": { inputPerMillion: 0.02, outputPerMillion: 0 },
20
+ "pplx-decider-flash-v1.3": { inputPerMillion: 0.01, outputPerMillion: 0 },
18
21
  "pplx-decider-v1.1-27b": { inputPerMillion: 0.02, outputPerMillion: 0 },
19
22
  "pplx-decider-v1-27b": { inputPerMillion: 0.02, outputPerMillion: 0 },
20
23
  "pplx-decider-v1.2": { inputPerMillion: 0.02, outputPerMillion: 0 },
@@ -22,9 +25,15 @@ const PRICES = {
22
25
  "pplx-decider-flash-v1.2": { inputPerMillion: 0.01, outputPerMillion: 0 },
23
26
  "pplx-decider-flash-latest": { inputPerMillion: 0.01, outputPerMillion: 0 },
24
27
  },
28
+ liquid: {
29
+ "d1.2": { inputPerMillion: 0.02, outputPerMillion: 0 },
30
+ "d1.2-ultra": { inputPerMillion: 0.042, outputPerMillion: 0 },
31
+ },
25
32
  cloudflare: {
26
33
  "@cf/cloudflare/clef": { inputPerMillion: 0.24, outputPerMillion: 0 },
27
34
  "@cf/cloudflare/clef-flash": { inputPerMillion: 0.038, outputPerMillion: 0 },
35
+ "@cf/cloudflare/clef-omni": { inputPerMillion: 0.15, outputPerMillion: 0 },
36
+ "@cf/cloudflare/clairic": { inputPerMillion: 0.1, outputPerMillion: 0 },
28
37
  "typesafe/jev": {
29
38
  inputPerMillion: 0.042,
30
39
  outputPerMillion: 0,
@@ -65,13 +74,23 @@ export function resolvePricing(provider, model, baseUrl, overrides) {
65
74
  const official = (provider === "openai" && baseUrl === "https://api.openai.com/v1") ||
66
75
  (provider === "typesafe" && baseUrl === "https://api.typesafe.ai/v1") ||
67
76
  (provider === "perplexity" && baseUrl === "https://api.perplexity.ai/v1") ||
68
- (provider === "cloudflare" &&
77
+ (provider === "liquid" && baseUrl === "https://api.liquid.ai/decisions/v1") ||
78
+ ((provider === "cloudflare" || provider === "clairic") &&
69
79
  /^https:\/\/api\.cloudflare\.com\/client\/v4\/accounts\/[^/]+\/ai$/.test(baseUrl));
70
- const catalog = Object.hasOwn(PRICES, provider) ? PRICES[provider] : undefined;
80
+ const catalogKey = provider === "clairic" ? "cloudflare" : provider;
81
+ const catalog = Object.hasOwn(PRICES, catalogKey) ? PRICES[catalogKey] : undefined;
71
82
  const rates = official && catalog && Object.hasOwn(catalog, model)
72
83
  ? catalog[model]
73
84
  : undefined;
74
- return rates ? { rates: { ...rates }, source: "builtin" } : undefined;
85
+ if (!rates)
86
+ return undefined;
87
+ // Cloudflare announced a scheduled list-price increase for Clairic on 2026-12-01.
88
+ const scheduledClairic = (provider === "cloudflare" || provider === "clairic") &&
89
+ model === "@cf/cloudflare/clairic" &&
90
+ new Date().toISOString().slice(0, 10) >= "2026-12-01"
91
+ ? { ...rates, inputPerMillion: 0.24 }
92
+ : rates;
93
+ return { rates: { ...scheduledClairic }, source: "builtin" };
75
94
  }
76
95
  function validRate(value) {
77
96
  return typeof value === "number" && Number.isFinite(value) && value >= 0;
@@ -191,7 +210,7 @@ export function sumCost(left, right) {
191
210
  currency: "USD",
192
211
  reason: "calculation_overflow",
193
212
  };
194
- return {
213
+ const result = {
195
214
  status: "estimated",
196
215
  currency: "USD",
197
216
  source: "aggregated",
@@ -199,4 +218,23 @@ export function sumCost(left, right) {
199
218
  output,
200
219
  total,
201
220
  };
221
+ const leftNonToken = left.nonToken?.webGrounding;
222
+ const rightNonToken = right.nonToken?.webGrounding;
223
+ if (leftNonToken && rightNonToken) {
224
+ const searchFeeMaximum = leftNonToken.searchFeeMaximum + rightNonToken.searchFeeMaximum;
225
+ const fetchFee = leftNonToken.fetchFee + rightNonToken.fetchFee;
226
+ result.nonToken = {
227
+ currency: "USD",
228
+ webGrounding: {
229
+ status: "estimated_maximum",
230
+ searchesRequested: leftNonToken.searchesRequested + rightNonToken.searchesRequested,
231
+ searchFeeMaximum,
232
+ successfulFetches: leftNonToken.successfulFetches + rightNonToken.successfulFetches,
233
+ fetchFee,
234
+ totalMaximum: searchFeeMaximum + fetchFee,
235
+ note: leftNonToken.note,
236
+ },
237
+ };
238
+ }
239
+ return result;
202
240
  }