@abhishek944/pi-classifier 0.3.0 → 0.5.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.
Files changed (77) hide show
  1. package/CHANGELOG.md +48 -0
  2. package/COMPUTER_USE.md +117 -0
  3. package/README.md +344 -30
  4. package/dist/auth.d.ts +4 -2
  5. package/dist/auth.js +18 -2
  6. package/dist/box-tool.d.ts +4 -0
  7. package/dist/box-tool.js +79 -0
  8. package/dist/box.d.ts +32 -0
  9. package/dist/box.js +148 -0
  10. package/dist/choices.js +35 -1
  11. package/dist/classify.d.ts +6 -0
  12. package/dist/classify.js +4 -4
  13. package/dist/computer-use-state.d.ts +9 -0
  14. package/dist/computer-use-state.js +160 -0
  15. package/dist/computer-use-tool.d.ts +52 -0
  16. package/dist/computer-use-tool.js +78 -0
  17. package/dist/computer-use-types.d.ts +132 -0
  18. package/dist/computer-use-types.js +1 -0
  19. package/dist/computer-use.d.ts +22 -0
  20. package/dist/computer-use.js +223 -0
  21. package/dist/config.d.ts +140 -3
  22. package/dist/config.js +405 -20
  23. package/dist/cost.js +42 -4
  24. package/dist/durable.d.ts +34 -0
  25. package/dist/durable.js +237 -0
  26. package/dist/extension.d.ts +2 -247
  27. package/dist/extension.js +53 -190
  28. package/dist/extract.d.ts +11 -0
  29. package/dist/extract.js +191 -0
  30. package/dist/http.d.ts +6 -1
  31. package/dist/http.js +64 -28
  32. package/dist/image-content.d.ts +12 -0
  33. package/dist/image-content.js +90 -0
  34. package/dist/index.d.ts +10 -1
  35. package/dist/index.js +3 -0
  36. package/dist/inputs.d.ts +24 -2
  37. package/dist/inputs.js +565 -134
  38. package/dist/mcp-cli.d.ts +2 -0
  39. package/dist/mcp-cli.js +39 -0
  40. package/dist/mcp-server.d.ts +28 -0
  41. package/dist/mcp-server.js +121 -0
  42. package/dist/mcp-tool-definitions.d.ts +19 -0
  43. package/dist/mcp-tool-definitions.js +64 -0
  44. package/dist/providers.d.ts +1 -0
  45. package/dist/providers.js +1218 -124
  46. package/dist/tool-contracts.d.ts +785 -0
  47. package/dist/tool-contracts.js +530 -0
  48. package/dist/tree.js +1 -1
  49. package/dist/types.d.ts +314 -20
  50. package/dist/validation.js +181 -44
  51. package/package.json +33 -5
  52. package/src/auth.ts +26 -2
  53. package/src/box-tool.ts +110 -0
  54. package/src/box.ts +253 -0
  55. package/src/choices.ts +44 -2
  56. package/src/classify.ts +10 -6
  57. package/src/computer-use-state.ts +145 -0
  58. package/src/computer-use-tool.ts +76 -0
  59. package/src/computer-use-types.ts +127 -0
  60. package/src/computer-use.ts +216 -0
  61. package/src/config.ts +454 -23
  62. package/src/cost.ts +42 -4
  63. package/src/durable.ts +298 -0
  64. package/src/extension.ts +79 -265
  65. package/src/extract.ts +228 -0
  66. package/src/http.ts +63 -32
  67. package/src/image-content.ts +77 -0
  68. package/src/index.ts +25 -0
  69. package/src/inputs.ts +603 -184
  70. package/src/mcp-cli.ts +44 -0
  71. package/src/mcp-server.ts +179 -0
  72. package/src/mcp-tool-definitions.ts +104 -0
  73. package/src/providers.ts +1398 -144
  74. package/src/tool-contracts.ts +785 -0
  75. package/src/tree.ts +1 -1
  76. package/src/types.ts +248 -11
  77. package/src/validation.ts +169 -96
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,10 +172,28 @@ 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"] },
177
+ { id: "pplx-decider-v1.2", input: ["text", "image"] },
178
+ { id: "pplx-decider-flash-v1.2", input: ["text", "image"] },
179
+ { id: "pplx-decider-latest", input: ["text", "image"] },
180
+ { id: "pplx-decider-flash-latest", input: ["text", "image"] },
37
181
  { id: "pplx-decider-v1.1-27b", input: ["text", "image"] },
38
182
  { id: "pplx-decider-v1-27b", input: ["text", "image"] },
39
183
  ],
40
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
+ },
41
197
  {
42
198
  id: "typesafe",
43
199
  route: "typesafe-api",
@@ -62,9 +218,19 @@ export const BUILT_INS = [
62
218
  models: [
63
219
  { id: "@cf/cloudflare/clef", input: ["text", "image"] },
64
220
  { id: "@cf/cloudflare/clef-flash", input: ["text", "image"] },
221
+ { id: "@cf/cloudflare/clef-omni", input: ["text", "image", "audio", "video"] },
65
222
  { id: "typesafe/jev" },
66
223
  ],
67
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
+ },
68
234
  {
69
235
  id: "openrouter",
70
236
  route: "openrouter-api",
@@ -74,7 +240,147 @@ export const BUILT_INS = [
74
240
  envVar: "OPENROUTER_API_KEY",
75
241
  models: [{ id: "typesafe/jev-1.13" }, { id: "~typesafe/jev-latest" }],
76
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
+ },
77
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
+ }
78
384
  export function loadClassifierSettings(cwd, projectTrusted = false) {
79
385
  try {
80
386
  // The shared loader is forgiving; malformed layers must not silently select a different route.
@@ -155,6 +461,7 @@ function headers(value) {
155
461
  const protectedNames = [
156
462
  "authorization",
157
463
  "api-key",
464
+ "api-subscription-key",
158
465
  "content-type",
159
466
  "content-length",
160
467
  "host",
@@ -191,14 +498,16 @@ export function configuredRoutes(settings, field) {
191
498
  return configuration(field + " must be an array of provider/model pairs.");
192
499
  return value.map((entry, index) => routePair(entry, field + "[" + index + "]"));
193
500
  }
194
- export function resolveModel(settings, selected = configuredDefault(settings)) {
501
+ export function resolveModel(settings, selected = configuredDefault(settings), source = "pi-store") {
195
502
  choicePolicy(settings);
196
503
  const { provider: routeId, model: modelId } = routePair(selected, "route");
197
504
  if (!/^[a-zA-Z0-9][a-zA-Z0-9_-]{0,63}$/.test(routeId) ||
198
505
  modelId.length > 256 ||
199
506
  /[\u0000-\u001f\u007f]/.test(modelId))
200
507
  return configuration("Provider routes must be short identifiers and model IDs must be at most 256 characters without control characters.");
201
- 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);
202
511
  if (settings.providers !== undefined && !isRecord(settings.providers))
203
512
  return configuration("providers must be an object.");
204
513
  if (settings.customProviders !== undefined &&
@@ -219,9 +528,19 @@ export function resolveModel(settings, selected = configuredDefault(settings)) {
219
528
  const api = builtIn?.api ?? custom.api;
220
529
  if (![
221
530
  "openai-decisions",
531
+ "openrouter-decisions",
532
+ "gemini-decisions",
533
+ "inception-decisions",
534
+ "parallel-decisions",
535
+ "local-system-one",
222
536
  "perplexity-decisions",
537
+ "sarvam-system-one",
223
538
  "system-one",
539
+ "liquid-system-one",
224
540
  "cloudflare-system-one",
541
+ "cloudflare-clairic",
542
+ "openrouter-extractions",
543
+ "litellm-extraction",
225
544
  "microsoft-system-one",
226
545
  ].includes(api))
227
546
  return configuration("Unsupported classifier API protocol.");
@@ -233,7 +552,7 @@ export function resolveModel(settings, selected = configuredDefault(settings)) {
233
552
  !m.id.trim() ||
234
553
  (m.input !== undefined &&
235
554
  (!Array.isArray(m.input) ||
236
- m.input.some((x) => x !== "text" && x !== "image"))) ||
555
+ m.input.some((x) => x !== "text" && x !== "image" && x !== "audio" && x !== "video"))) ||
237
556
  (m.box !== undefined && typeof m.box !== "boolean"))) {
238
557
  return configuration("Provider models must declare an id and optional text/image input capabilities.");
239
558
  }
@@ -241,18 +560,35 @@ export function resolveModel(settings, selected = configuredDefault(settings)) {
241
560
  // Built-in API routes allow new text model IDs without a package release. Images require known capabilities.
242
561
  if (!definition && !builtIn)
243
562
  return configuration("The selected model is not declared in customProviders.<id>.models.");
244
- for (const flag of ["experimentalImages", "experimentalBox"]) {
563
+ for (const flag of ["experimentalImages", "experimentalBox", "longContext"]) {
245
564
  if (raw[flag] !== undefined && typeof raw[flag] !== "boolean")
246
565
  return configuration(flag + " must be a boolean.");
247
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");
248
584
  let baseUrl = optionalString(raw.baseUrl, "baseUrl") ?? builtIn?.baseUrl;
249
- if (api === "cloudflare-system-one" && !baseUrl)
585
+ if ((api === "cloudflare-system-one" || api === "cloudflare-clairic") && !baseUrl)
250
586
  baseUrl =
251
587
  "https://api.cloudflare.com/client/v4/accounts/" +
252
- cloudflareAccountId(optionalString(raw.accountId, "accountId")) +
588
+ cloudflareAccountId(optionalString(raw.accountId, "accountId"), source) +
253
589
  "/ai";
254
590
  if (!baseUrl)
255
- 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.");
256
592
  const timeout = settings.requestTimeoutMs ?? 30_000;
257
593
  if (!Number.isInteger(timeout) || timeout < 100 || timeout > 300_000)
258
594
  return configuration("requestTimeoutMs must be between 100 and 300000.");
@@ -261,27 +597,65 @@ export function resolveModel(settings, selected = configuredDefault(settings)) {
261
597
  const configuredApiKey = typeof raw.apiKey === "string" ? raw.apiKey.trim() || undefined : undefined;
262
598
  if (configuredApiKey && /\$\{?|^!/.test(configuredApiKey))
263
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
+ }
264
611
  const isJevDirect = builtIn?.id === "typesafe";
612
+ const openRouter = api === "openrouter-decisions" ? openRouterDecisionCapabilities(modelId) : undefined;
265
613
  const result = {
266
614
  route: builtIn?.route ?? routeId,
267
615
  provider: builtIn?.id ?? routeId,
268
616
  model: modelId,
269
617
  api,
618
+ mediaFormat: api === "system-one" ? "jev-assets" : openRouter ? "openrouter-parts" : "base64-object",
270
619
  baseUrl: validateBaseUrl(baseUrl),
271
- headers: headers(raw.headers),
620
+ headers: resolvedHeaders,
621
+ ...(gatewayId !== undefined ? { gatewayId } : {}),
272
622
  credentialProvider: builtIn?.credentialProvider ?? routeId,
273
- images: api === "microsoft-system-one"
274
- ? false
623
+ images: openRouter
624
+ ? openRouter.images > 0
275
625
  : api === "system-one"
276
626
  ? Boolean(raw.experimentalImages && definition?.input?.includes("image"))
277
627
  : Boolean(definition?.input?.includes("image")),
278
- box: Boolean((isJevDirect || custom?.api === "system-one") &&
279
- definition?.box &&
280
- definition?.input?.includes("image") &&
281
- raw.experimentalBox &&
282
- 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),
283
654
  experimentalImages: raw.experimentalImages === true,
655
+ authMode: resolvedAuthMode,
656
+ longContext: raw.longContext === true,
284
657
  requestTimeoutMs: timeout,
658
+ limits: configuredLimits(raw.limits, api, builtIn?.id, modelId),
285
659
  };
286
660
  const pricing = resolvePricing(result.provider, modelId, result.baseUrl, raw.pricing);
287
661
  if (pricing)
@@ -308,14 +682,22 @@ function knownMaxChoices(route) {
308
682
  const directJev = route.provider === "typesafe" &&
309
683
  route.baseUrl === "https://api.typesafe.ai/v1" &&
310
684
  ["jev-latest", "jev-preview", "jev-1.13.0", "jev-1.14.0"].includes(route.model);
311
- 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" &&
312
689
  route.baseUrl === "https://api.openai.com/v1" &&
313
- 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));
314
694
  const perplexity = route.provider === "perplexity" &&
315
695
  route.baseUrl === "https://api.perplexity.ai/v1" &&
316
696
  [
317
697
  "pplx-decider-v1.1-27b",
318
698
  "pplx-decider-v1-27b",
699
+ "pplx-decider-v1.3",
700
+ "pplx-decider-flash-v1.3",
319
701
  "pplx-decider-v1.2",
320
702
  "pplx-decider-latest",
321
703
  "pplx-decider-flash-v1.2",
@@ -323,8 +705,11 @@ function knownMaxChoices(route) {
323
705
  ].includes(route.model);
324
706
  const clef = route.provider === "cloudflare" &&
325
707
  /^https:\/\/api\.cloudflare\.com\/client\/v4\/accounts\/[^/]+\/ai$/.test(route.baseUrl) &&
326
- ["@cf/cloudflare/clef", "@cf/cloudflare/clef-flash"].includes(route.model);
327
- 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;
328
713
  }
329
714
  export function listModels(settings) {
330
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
  }