@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/src/config.ts CHANGED
@@ -5,7 +5,7 @@ import {
5
5
  loadPiSettings,
6
6
  resolveConfigDir,
7
7
  } from "@amaster.ai/pi-shared/settings";
8
- import { cloudflareAccountId } from "./auth.js";
8
+ import { cloudflareAccountId, type CredentialSource } from "./auth.js";
9
9
  import { resolvePricing } from "./cost.js";
10
10
  import { choicePolicy } from "./choices.js";
11
11
  import {
@@ -17,10 +17,93 @@ import {
17
17
  type ModelDefinition,
18
18
  type ProviderSettings,
19
19
  type ResolvedModel,
20
+ type RouteLimits,
20
21
  } from "./types.js";
21
22
 
22
23
  export const SETTINGS_KEY = "pi-classifier";
23
24
  export const BUILT_INS = [
25
+ {
26
+ id: "llamacpp",
27
+ route: "llamacpp-api",
28
+ api: "local-system-one",
29
+ baseUrl: "",
30
+ credentialProvider: "llamacpp",
31
+ envVar: "",
32
+ models: [
33
+ { id: "LiquidAI/d1-2B", input: ["text", "image"] },
34
+ { id: "LiquidAI/d1-Omni-2B", input: ["text", "image", "audio", "video"] },
35
+ { id: "LiquidAI/d1-omni-600M", input: ["text", "image", "audio"] },
36
+ ],
37
+ },
38
+ {
39
+ id: "vllm",
40
+ route: "vllm-api",
41
+ api: "local-system-one",
42
+ baseUrl: "",
43
+ credentialProvider: "vllm",
44
+ envVar: "VLLM_API_KEY",
45
+ models: [
46
+ { id: "Qwen/Qwen3-0.6B", input: ["text"] },
47
+ { id: "LiquidAI/d1-3B", input: ["text", "image"] },
48
+ ],
49
+ },
50
+ {
51
+ id: "strands",
52
+ route: "strands-api",
53
+ api: "local-system-one",
54
+ baseUrl: "",
55
+ credentialProvider: "strands",
56
+ envVar: "",
57
+ models: [{ id: "StrandsAgents/strands-decider-E2B-gemma4-v1-2610", input: ["text"] }],
58
+ },
59
+ {
60
+ id: "laya",
61
+ route: "laya-api",
62
+ api: "local-system-one",
63
+ baseUrl: "",
64
+ credentialProvider: "laya",
65
+ envVar: "LAYA_API_KEY",
66
+ models: [
67
+ { id: "english", input: ["text"] },
68
+ { id: "multilingual", input: ["text"] },
69
+ { id: "typed-decisions", input: ["text"] },
70
+ ],
71
+ },
72
+ {
73
+ id: "nimble",
74
+ route: "nimble-api",
75
+ api: "local-system-one",
76
+ baseUrl: "",
77
+ credentialProvider: "nimble",
78
+ envVar: "",
79
+ models: [{ id: "nimble", input: ["text"] }],
80
+ },
81
+ {
82
+ id: "openrouter",
83
+ route: "openrouter-extractions-api",
84
+ api: "openrouter-extractions",
85
+ baseUrl: "https://openrouter.ai/api",
86
+ credentialProvider: "openrouter",
87
+ envVar: "OPENROUTER_API_KEY",
88
+ models: [
89
+ { id: "cloudflare/clairic", input: ["text", "image"] },
90
+ { id: "inception/mercury-decide", input: ["text"] },
91
+ { id: "liquid/d1.2", input: ["text", "image"] },
92
+ { id: "liquid/d1.2-ultra", input: ["text", "image"] },
93
+ { id: "perplexity/pplx-decider-v1.3", input: ["text"] },
94
+ { id: "perplexity/pplx-decider-flash-v1.3", input: ["text"] },
95
+ { id: "scaledown/extract", input: ["text", "image"] },
96
+ ],
97
+ },
98
+ {
99
+ id: "litellm",
100
+ route: "litellm-extraction-api",
101
+ api: "litellm-extraction",
102
+ baseUrl: "",
103
+ credentialProvider: "litellm",
104
+ envVar: "LITELLM_API_KEY",
105
+ models: [{ id: "clairic", input: ["text", "image"] }],
106
+ },
24
107
  {
25
108
  id: "microsoft",
26
109
  route: "microsoft-api",
@@ -28,7 +111,22 @@ export const BUILT_INS = [
28
111
  baseUrl: "",
29
112
  credentialProvider: "microsoft",
30
113
  envVar: "AZURE_API_KEY",
31
- models: [{ id: "Microsoft-Decision-1", input: ["text"] }],
114
+ models: [
115
+ { id: "Microsoft-Decision-1.1", input: ["text", "image"] },
116
+ { id: "Microsoft-Decision-1", input: ["text"] },
117
+ ],
118
+ },
119
+ {
120
+ id: "sarvam",
121
+ route: "sarvam-api",
122
+ api: "sarvam-system-one",
123
+ baseUrl: "https://api.sarvam.ai/v2",
124
+ credentialProvider: "sarvam",
125
+ envVar: "SARVAM_API_KEY",
126
+ models: [
127
+ { id: "sarvam-prism", input: ["text"] },
128
+ { id: "clef", input: ["text", "image"] },
129
+ ],
32
130
  },
33
131
  {
34
132
  id: "openai",
@@ -39,6 +137,47 @@ export const BUILT_INS = [
39
137
  envVar: "OPENAI_API_KEY",
40
138
  models: [{ id: "gpt-6-luna", input: ["text", "image"] }],
41
139
  },
140
+ {
141
+ id: "vercel",
142
+ route: "vercel-api",
143
+ api: "openai-decisions",
144
+ baseUrl: "https://ai-gateway.vercel.sh/v1",
145
+ credentialProvider: "vercel",
146
+ envVar: "VERCEL_AI_GATEWAY_API_KEY",
147
+ models: [
148
+ { id: "openai/gpt-6-luna-decisions", input: ["text", "image"] },
149
+ { id: "typesafe-ai/jev", input: ["text"] },
150
+ ],
151
+ },
152
+ {
153
+ id: "gemini",
154
+ route: "gemini-api",
155
+ api: "gemini-decisions",
156
+ baseUrl: "https://generativelanguage.googleapis.com/v1beta",
157
+ credentialProvider: "gemini",
158
+ envVar: "GEMINI_API_KEY",
159
+ models: [
160
+ { id: "gemini-decision-1", input: ["text", "image", "audio", "video"] },
161
+ ],
162
+ },
163
+ {
164
+ id: "inception",
165
+ route: "inception-api",
166
+ api: "inception-decisions",
167
+ baseUrl: "https://api.inceptionlabs.ai/v1",
168
+ credentialProvider: "inception",
169
+ envVar: "INCEPTION_API_KEY",
170
+ models: [{ id: "mercury-decide", input: ["text", "image"] }],
171
+ },
172
+ {
173
+ id: "parallel",
174
+ route: "parallel-api",
175
+ api: "parallel-decisions",
176
+ baseUrl: "https://api.parallel.ai/v1",
177
+ credentialProvider: "parallel",
178
+ envVar: "PARALLEL_API_KEY",
179
+ models: [{ id: "parallel-decisions", input: ["text"] }],
180
+ },
42
181
  {
43
182
  id: "perplexity",
44
183
  route: "perplexity-api",
@@ -47,6 +186,8 @@ export const BUILT_INS = [
47
186
  credentialProvider: "perplexity",
48
187
  envVar: "PERPLEXITY_API_KEY",
49
188
  models: [
189
+ { id: "pplx-decider-v1.3", input: ["text", "image"] },
190
+ { id: "pplx-decider-flash-v1.3", input: ["text", "image"] },
50
191
  { id: "pplx-decider-v1.2", input: ["text", "image"] },
51
192
  { id: "pplx-decider-flash-v1.2", input: ["text", "image"] },
52
193
  { id: "pplx-decider-latest", input: ["text", "image"] },
@@ -55,6 +196,18 @@ export const BUILT_INS = [
55
196
  { id: "pplx-decider-v1-27b", input: ["text", "image"] },
56
197
  ],
57
198
  },
199
+ {
200
+ id: "liquid",
201
+ route: "liquid-api",
202
+ api: "liquid-system-one",
203
+ baseUrl: "https://api.liquid.ai/decisions/v1",
204
+ credentialProvider: "liquid",
205
+ envVar: "LIQUID_API_KEY",
206
+ models: [
207
+ { id: "d1.2", input: ["text", "image", "audio"], box: true },
208
+ { id: "d1.2-ultra", input: ["text", "image", "audio"], box: true },
209
+ ],
210
+ },
58
211
  {
59
212
  id: "typesafe",
60
213
  route: "typesafe-api",
@@ -79,9 +232,19 @@ export const BUILT_INS = [
79
232
  models: [
80
233
  { id: "@cf/cloudflare/clef", input: ["text", "image"] },
81
234
  { id: "@cf/cloudflare/clef-flash", input: ["text", "image"] },
235
+ { id: "@cf/cloudflare/clef-omni", input: ["text", "image", "audio", "video"] },
82
236
  { id: "typesafe/jev" },
83
237
  ],
84
238
  },
239
+ {
240
+ id: "clairic",
241
+ route: "clairic-api",
242
+ api: "cloudflare-clairic",
243
+ baseUrl: "",
244
+ credentialProvider: "cloudflare-workers-ai",
245
+ envVar: "CLOUDFLARE_API_KEY",
246
+ models: [{ id: "@cf/cloudflare/clairic", input: ["text", "image"] }],
247
+ },
85
248
  {
86
249
  id: "openrouter",
87
250
  route: "openrouter-api",
@@ -91,6 +254,30 @@ export const BUILT_INS = [
91
254
  envVar: "OPENROUTER_API_KEY",
92
255
  models: [{ id: "typesafe/jev-1.13" }, { id: "~typesafe/jev-latest" }],
93
256
  },
257
+ {
258
+ id: "openrouter",
259
+ route: "openrouter-decisions-api",
260
+ api: "openrouter-decisions",
261
+ baseUrl: "https://openrouter.ai/api",
262
+ credentialProvider: "openrouter",
263
+ envVar: "OPENROUTER_API_KEY",
264
+ models: [
265
+ { id: "typesafe/jev-1.14", input: ["text", "image"], box: true },
266
+ { id: "~typesafe/jev-latest", input: ["text", "image"], box: true },
267
+ { id: "typesafe/jev-1.13", input: ["text", "image"] },
268
+ { id: "microsoft/microsoft-decision-1.1", input: ["text", "image"] },
269
+ { id: "cloudflare/clef-flash", input: ["text", "image"] },
270
+ { id: "cloudflare/clef-omni", input: ["text", "image", "audio", "video"] },
271
+ { id: "inception/mercury-decide", input: ["text", "image"] },
272
+ { id: "liquid/d1.2", input: ["text", "image"] },
273
+ { id: "liquid/d1.2-ultra", input: ["text", "image"] },
274
+ { id: "openai/gpt-6-luna-decisions", input: ["text", "image"] },
275
+ { id: "google/gemini-decision-1", input: ["text", "image", "audio", "video"] },
276
+ { id: "heygen/heygen-decision-1", input: ["text", "image", "audio", "video"] },
277
+ { id: "heygen/heygen-decision-1-turbo", input: ["text", "image", "audio", "video"] },
278
+ { id: "parallel/parallel-decisions", input: ["text"] },
279
+ ],
280
+ },
94
281
  ] satisfies Array<{
95
282
  id: string;
96
283
  route: string;
@@ -101,6 +288,154 @@ export const BUILT_INS = [
101
288
  models: ModelDefinition[];
102
289
  }>;
103
290
 
291
+ /** Keep legacy provider-id aliases pointed at their original classify route when one provider exposes several APIs. */
292
+ const PREFERRED_ROUTE_BY_ID: Record<string, string> = { openrouter: "openrouter-api" };
293
+
294
+ /** Largest documented envelope among built-in adapters; per-route limits narrow it before any request. */
295
+ const DEFAULT_LIMITS: RouteLimits = {
296
+ maxQuestions: 1000,
297
+ maxImages: 128,
298
+ maxAudio: 10,
299
+ maxVideo: 10,
300
+ };
301
+
302
+ export type OpenRouterExtractionCapabilities = {
303
+ fieldTypes: string[];
304
+ maxFields: number;
305
+ maxImages: number;
306
+ maxDocuments: number;
307
+ maxAssets: number;
308
+ referenceDate: boolean;
309
+ };
310
+
311
+ /** Field tiers from OpenRouter's Extractions guide; unknown models default to text-only. */
312
+ export function openRouterExtractionCapabilities(model: string): OpenRouterExtractionCapabilities {
313
+ const textOnly = { fieldTypes: ["text", "list"], maxFields: 128, maxImages: 0, maxDocuments: 0, maxAssets: 0, referenceDate: false };
314
+ if (model === "cloudflare/clairic")
315
+ return {
316
+ fieldTypes: ["text", "number", "date", "time", "datetime", "duration", "list", "estimate", "forecast"],
317
+ maxFields: 128,
318
+ maxImages: 4,
319
+ maxDocuments: 0,
320
+ maxAssets: 4,
321
+ referenceDate: true,
322
+ };
323
+ if (/^liquid\/d1\.2/.test(model))
324
+ return { fieldTypes: ["text", "number", "date", "list", "estimate"], maxFields: 128, maxImages: 8, maxDocuments: 0, maxAssets: 8, referenceDate: false };
325
+ if (model === "scaledown/extract")
326
+ return { ...textOnly, maxImages: 1, maxDocuments: 1, maxAssets: 1 };
327
+ if (/^inference-net\/schematron-v2-/.test(model))
328
+ return { ...textOnly, fieldTypes: ["text", "number", "date", "time", "datetime", "list"] };
329
+ return textOnly;
330
+ }
331
+
332
+ export type OpenRouterDecisionCapabilities = {
333
+ flexibleImagePlacement: boolean;
334
+ box: boolean;
335
+ remoteImageUrls: boolean;
336
+ images: number;
337
+ audio: number;
338
+ video: number;
339
+ };
340
+
341
+ /** Defaults come from OpenRouter's published Decisions adapter registry and multimodal limits. */
342
+ export function openRouterDecisionCapabilities(model: string): OpenRouterDecisionCapabilities {
343
+ if (/^~?typesafe\/jev-(?:1\.14|latest)$/.test(model))
344
+ return { flexibleImagePlacement: true, box: true, remoteImageUrls: false, images: 128, audio: 0, video: 0 };
345
+ if (model === "typesafe/jev-1.13")
346
+ return { flexibleImagePlacement: true, box: false, remoteImageUrls: false, images: 128, audio: 0, video: 0 };
347
+ if (model === "microsoft/microsoft-decision-1.1")
348
+ return { flexibleImagePlacement: true, box: false, remoteImageUrls: false, images: 8, audio: 0, video: 0 };
349
+ if (model === "cloudflare/clef-omni")
350
+ return { flexibleImagePlacement: false, box: false, remoteImageUrls: false, images: 4, audio: 4, video: 2 };
351
+ if (/^cloudflare\/clef(?:-flash)?$/.test(model))
352
+ return { flexibleImagePlacement: false, box: false, remoteImageUrls: false, images: 4, audio: 0, video: 0 };
353
+ if (/^heygen\/heygen-decision-1(?:-turbo)?$/.test(model))
354
+ return { flexibleImagePlacement: false, box: false, remoteImageUrls: true, images: 100, audio: 10, video: 10 };
355
+ if (model === "google/gemini-decision-1")
356
+ return { flexibleImagePlacement: false, box: false, remoteImageUrls: true, images: 128, audio: 10, video: 10 };
357
+ if (model === "inception/mercury-decide")
358
+ return { flexibleImagePlacement: false, box: false, remoteImageUrls: false, images: 16, audio: 0, video: 0 };
359
+ if (/^liquid\/d1(?:\.2(?:-ultra)?|-2B|-omni.*)?$/.test(model))
360
+ return { flexibleImagePlacement: false, box: false, remoteImageUrls: false, images: 8, audio: 0, video: 0 };
361
+ if (/^baseten\//.test(model) || /^morph\//.test(model))
362
+ return { flexibleImagePlacement: false, box: false, remoteImageUrls: false, images: 16, audio: 0, video: 0 };
363
+ if (/^deepinfra\//.test(model) || /^makora\//.test(model) || /^prime-intellect\//.test(model))
364
+ return { flexibleImagePlacement: false, box: false, remoteImageUrls: false, images: 4, audio: 0, video: 0 };
365
+ if (model === "openai/gpt-6-luna-decisions")
366
+ return { flexibleImagePlacement: false, box: false, remoteImageUrls: false, images: 128, audio: 0, video: 0 };
367
+ return { flexibleImagePlacement: false, box: false, remoteImageUrls: false, images: 0, audio: 0, video: 0 };
368
+ }
369
+
370
+ function builtInLimits(api: ApiStyle, provider: string | undefined, model: string): RouteLimits {
371
+ if (api === "openai-decisions")
372
+ return { ...DEFAULT_LIMITS, maxQuestions: 400 };
373
+ if (api === "openrouter-extractions") {
374
+ const caps = openRouterExtractionCapabilities(model);
375
+ return { ...DEFAULT_LIMITS, maxImages: caps.maxImages, maxAudio: 0, maxVideo: 0 };
376
+ }
377
+ if (api === "litellm-extraction")
378
+ return { ...DEFAULT_LIMITS, maxImages: 4, maxAudio: 0, maxVideo: 0 };
379
+ if (api === "parallel-decisions")
380
+ return { ...DEFAULT_LIMITS, maxQuestions: 100, maxImages: 0, maxAudio: 0, maxVideo: 0 };
381
+ if (api === "local-system-one") {
382
+ const maxQuestions =
383
+ provider === "vllm" ? 64 : provider === "laya" ? 32 : provider === "nimble" ? 64 : provider === "strands" ? 32 : DEFAULT_LIMITS.maxQuestions;
384
+ const maxImages = provider === "llamacpp" || provider === "vllm" || provider === "strands" ? DEFAULT_LIMITS.maxImages : 0;
385
+ return { ...DEFAULT_LIMITS, maxQuestions, maxImages };
386
+ }
387
+ if (api === "openrouter-decisions") {
388
+ const caps = openRouterDecisionCapabilities(model);
389
+ return { ...DEFAULT_LIMITS, maxImages: caps.images, maxAudio: caps.audio, maxVideo: caps.video };
390
+ }
391
+ if (api === "perplexity-decisions")
392
+ return { ...DEFAULT_LIMITS, maxQuestions: 128, maxImages: 8, maxAudio: 0, maxVideo: 0 };
393
+ if (api === "liquid-system-one")
394
+ return { ...DEFAULT_LIMITS, maxQuestions: 128, maxImages: 8, maxAudio: 8, maxVideo: 0 };
395
+ if (api === "cloudflare-system-one") {
396
+ const omni = model === "@cf/cloudflare/clef-omni";
397
+ const clef = provider === "cloudflare" && model.startsWith("@cf/cloudflare/clef");
398
+ return {
399
+ ...DEFAULT_LIMITS,
400
+ maxQuestions: clef ? 64 : DEFAULT_LIMITS.maxQuestions,
401
+ maxImages: clef ? 4 : 0,
402
+ maxAudio: omni ? 4 : 0,
403
+ maxVideo: omni ? 2 : 0,
404
+ };
405
+ }
406
+ if (api === "microsoft-system-one")
407
+ return { ...DEFAULT_LIMITS, maxAudio: 0, maxVideo: 0 };
408
+ if (api === "sarvam-system-one")
409
+ return { ...DEFAULT_LIMITS, maxImages: model === "clef" ? DEFAULT_LIMITS.maxImages : 0, maxAudio: 0, maxVideo: 0 };
410
+ return { ...DEFAULT_LIMITS };
411
+ }
412
+
413
+ function configuredLimits(
414
+ value: unknown,
415
+ api: ApiStyle,
416
+ provider: string | undefined,
417
+ model: string,
418
+ ): RouteLimits {
419
+ const base = builtInLimits(api, provider, model);
420
+ if (value === undefined) return base;
421
+ if (!isRecord(value) || Object.keys(value).some((key) => !["maxQuestions", "maxImages", "maxAudio", "maxVideo"].includes(key)))
422
+ return configuration(
423
+ "limits may only set maxQuestions, maxImages, maxAudio and maxVideo.",
424
+ );
425
+ const limits = { ...base };
426
+ for (const key of ["maxQuestions", "maxImages", "maxAudio", "maxVideo"] as const) {
427
+ const entry = value[key];
428
+ if (entry === undefined) continue;
429
+ const minimum = key === "maxQuestions" ? 1 : 0;
430
+ if (!Number.isSafeInteger(entry) || (entry as number) < minimum)
431
+ return configuration(
432
+ key + " must be a safe integer of at least " + minimum + ".",
433
+ );
434
+ limits[key] = entry as number;
435
+ }
436
+ return limits;
437
+ }
438
+
104
439
  export function loadClassifierSettings(
105
440
  cwd: string,
106
441
  projectTrusted = false,
@@ -200,6 +535,7 @@ function headers(value: unknown): Record<string, string> {
200
535
  const protectedNames = [
201
536
  "authorization",
202
537
  "api-key",
538
+ "api-subscription-key",
203
539
  "content-type",
204
540
  "content-length",
205
541
  "host",
@@ -258,6 +594,7 @@ export function configuredRoutes(
258
594
  export function resolveModel(
259
595
  settings: ClassifierSettings,
260
596
  selected: ClassifierRoute = configuredDefault(settings),
597
+ source: CredentialSource = "pi-store",
261
598
  ): ResolvedModel {
262
599
  choicePolicy(settings);
263
600
  const { provider: routeId, model: modelId } = routePair(selected, "route");
@@ -269,9 +606,10 @@ export function resolveModel(
269
606
  return configuration(
270
607
  "Provider routes must be short identifiers and model IDs must be at most 256 characters without control characters.",
271
608
  );
272
- const builtIn = BUILT_INS.find(
273
- (entry) => entry.route === routeId || entry.id === routeId,
274
- );
609
+ const builtIn =
610
+ BUILT_INS.find((entry) => entry.route === routeId) ??
611
+ BUILT_INS.find((entry) => entry.route === PREFERRED_ROUTE_BY_ID[routeId]) ??
612
+ BUILT_INS.find((entry) => entry.id === routeId);
275
613
  if (settings.providers !== undefined && !isRecord(settings.providers))
276
614
  return configuration("providers must be an object.");
277
615
  if (
@@ -295,9 +633,19 @@ export function resolveModel(
295
633
  if (
296
634
  ![
297
635
  "openai-decisions",
636
+ "openrouter-decisions",
637
+ "gemini-decisions",
638
+ "inception-decisions",
639
+ "parallel-decisions",
640
+ "local-system-one",
298
641
  "perplexity-decisions",
642
+ "sarvam-system-one",
299
643
  "system-one",
644
+ "liquid-system-one",
300
645
  "cloudflare-system-one",
646
+ "cloudflare-clairic",
647
+ "openrouter-extractions",
648
+ "litellm-extraction",
301
649
  "microsoft-system-one",
302
650
  ].includes(api)
303
651
  )
@@ -313,7 +661,9 @@ export function resolveModel(
313
661
  !m.id.trim() ||
314
662
  (m.input !== undefined &&
315
663
  (!Array.isArray(m.input) ||
316
- m.input.some((x) => x !== "text" && x !== "image"))) ||
664
+ m.input.some(
665
+ (x) => x !== "text" && x !== "image" && x !== "audio" && x !== "video",
666
+ ))) ||
317
667
  (m.box !== undefined && typeof m.box !== "boolean"),
318
668
  )
319
669
  ) {
@@ -327,19 +677,37 @@ export function resolveModel(
327
677
  return configuration(
328
678
  "The selected model is not declared in customProviders.<id>.models.",
329
679
  );
330
- for (const flag of ["experimentalImages", "experimentalBox"] as const) {
680
+ for (const flag of ["experimentalImages", "experimentalBox", "longContext"] as const) {
331
681
  if (raw[flag] !== undefined && typeof raw[flag] !== "boolean")
332
682
  return configuration(flag + " must be a boolean.");
333
683
  }
684
+ const authMode = raw.authMode;
685
+ if (authMode !== undefined && authMode !== "api-key" && authMode !== "bearer" && authMode !== "google-api-key" && authMode !== "parallel-api-key" && authMode !== "none")
686
+ return configuration("authMode must be api-key, bearer, google-api-key, parallel-api-key or none.");
687
+ if (authMode === "none" && api !== "local-system-one")
688
+ return configuration("authMode none is supported only by local System One routes.");
689
+ const resolvedAuthMode: ResolvedModel["authMode"] =
690
+ authMode ??
691
+ (api === "microsoft-system-one"
692
+ ? "api-key"
693
+ : api === "sarvam-system-one"
694
+ ? authMode ?? "subscription-key"
695
+ : api === "gemini-decisions"
696
+ ? "google-api-key"
697
+ : api === "parallel-decisions"
698
+ ? "parallel-api-key"
699
+ : api === "local-system-one"
700
+ ? "none"
701
+ : "bearer");
334
702
  let baseUrl = optionalString(raw.baseUrl, "baseUrl") ?? builtIn?.baseUrl;
335
- if (api === "cloudflare-system-one" && !baseUrl)
703
+ if ((api === "cloudflare-system-one" || api === "cloudflare-clairic") && !baseUrl)
336
704
  baseUrl =
337
705
  "https://api.cloudflare.com/client/v4/accounts/" +
338
- cloudflareAccountId(optionalString(raw.accountId, "accountId")) +
706
+ cloudflareAccountId(optionalString(raw.accountId, "accountId"), source) +
339
707
  "/ai";
340
708
  if (!baseUrl)
341
709
  return configuration(
342
- "The selected provider requires a baseUrl. Microsoft uses your Foundry resource endpoint.",
710
+ "The selected provider requires a baseUrl. Microsoft uses your Foundry resource endpoint; local runtimes use your server URL.",
343
711
  );
344
712
  const timeout = settings.requestTimeoutMs ?? 30_000;
345
713
  if (!Number.isInteger(timeout) || timeout < 100 || timeout > 300_000)
@@ -352,32 +720,78 @@ export function resolveModel(
352
720
  return configuration(
353
721
  "API-key references must be resolved in global settings; project settings cannot expand environment variables or execute commands.",
354
722
  );
723
+ const gatewayId = optionalString(raw.gatewayId, "gatewayId");
724
+ if (gatewayId !== undefined && (/[\r\n]/.test(gatewayId) || /\$\{?[A-Z_]/.test(gatewayId)))
725
+ return configuration(
726
+ "Gateway IDs must be resolved in global settings and cannot contain line breaks.",
727
+ );
728
+ const resolvedHeaders = headers(raw.headers);
729
+ if (
730
+ (api === "cloudflare-system-one" || api === "cloudflare-clairic") &&
731
+ gatewayId !== undefined
732
+ ) {
733
+ for (const key of Object.keys(resolvedHeaders))
734
+ if (key.toLowerCase() === "cf-aig-gateway-id" && key !== "cf-aig-gateway-id")
735
+ delete resolvedHeaders[key];
736
+ resolvedHeaders["cf-aig-gateway-id"] = gatewayId;
737
+ }
355
738
  const isJevDirect = builtIn?.id === "typesafe";
739
+ const openRouter = api === "openrouter-decisions" ? openRouterDecisionCapabilities(modelId) : undefined;
356
740
  const result: ResolvedModel = {
357
741
  route: builtIn?.route ?? routeId,
358
742
  provider: builtIn?.id ?? routeId,
359
743
  model: modelId,
360
744
  api,
745
+ mediaFormat: api === "system-one" ? "jev-assets" : openRouter ? "openrouter-parts" : "base64-object",
361
746
  baseUrl: validateBaseUrl(baseUrl),
362
- headers: headers(raw.headers),
747
+ headers: resolvedHeaders,
748
+ ...(gatewayId !== undefined ? { gatewayId } : {}),
363
749
  credentialProvider: builtIn?.credentialProvider ?? routeId,
364
750
  images:
365
- api === "microsoft-system-one"
366
- ? false
751
+ openRouter
752
+ ? openRouter.images > 0
367
753
  : api === "system-one"
368
754
  ? Boolean(
369
755
  raw.experimentalImages && definition?.input?.includes("image"),
370
756
  )
371
757
  : Boolean(definition?.input?.includes("image")),
758
+ audio: openRouter
759
+ ? openRouter.audio > 0
760
+ : Boolean(
761
+ (api === "liquid-system-one" ||
762
+ api === "cloudflare-system-one" ||
763
+ api === "gemini-decisions" ||
764
+ api === "local-system-one") &&
765
+ definition?.input?.includes("audio"),
766
+ ),
767
+ video: openRouter
768
+ ? openRouter.video > 0
769
+ : Boolean(
770
+ (api === "cloudflare-system-one" ||
771
+ api === "gemini-decisions" ||
772
+ api === "local-system-one") &&
773
+ definition?.input?.includes("video"),
774
+ ),
372
775
  box: Boolean(
373
- (isJevDirect || custom?.api === "system-one") &&
374
- definition?.box &&
375
- definition?.input?.includes("image") &&
376
- raw.experimentalBox &&
377
- raw.experimentalImages,
776
+ openRouter
777
+ ? openRouter.box &&
778
+ definition?.box &&
779
+ definition?.input?.includes("image") &&
780
+ raw.experimentalBox &&
781
+ raw.experimentalImages
782
+ : api === "liquid-system-one"
783
+ ? definition?.box && definition?.input?.includes("image")
784
+ : (isJevDirect || custom?.api === "system-one") &&
785
+ definition?.box &&
786
+ definition?.input?.includes("image") &&
787
+ raw.experimentalBox &&
788
+ raw.experimentalImages,
378
789
  ),
379
790
  experimentalImages: raw.experimentalImages === true,
791
+ authMode: resolvedAuthMode,
792
+ longContext: raw.longContext === true,
380
793
  requestTimeoutMs: timeout,
794
+ limits: configuredLimits(raw.limits, api, builtIn?.id, modelId),
381
795
  };
382
796
  const pricing = resolvePricing(
383
797
  result.provider,
@@ -410,16 +824,25 @@ function knownMaxChoices(route: ResolvedModel): number | undefined {
410
824
  route.provider === "typesafe" &&
411
825
  route.baseUrl === "https://api.typesafe.ai/v1" &&
412
826
  ["jev-latest", "jev-preview", "jev-1.13.0", "jev-1.14.0"].includes(route.model);
827
+ const sarvam =
828
+ route.provider === "sarvam" &&
829
+ route.baseUrl === "https://api.sarvam.ai/v2" &&
830
+ route.model === "sarvam-prism";
413
831
  const openai =
414
- route.provider === "openai" &&
415
- route.baseUrl === "https://api.openai.com/v1" &&
416
- route.model === "gpt-6-luna";
832
+ (route.provider === "openai" &&
833
+ route.baseUrl === "https://api.openai.com/v1" &&
834
+ route.model === "gpt-6-luna") ||
835
+ (route.provider === "vercel" &&
836
+ route.baseUrl === "https://ai-gateway.vercel.sh/v1" &&
837
+ ["openai/gpt-6-luna-decisions", "typesafe-ai/jev"].includes(route.model));
417
838
  const perplexity =
418
839
  route.provider === "perplexity" &&
419
840
  route.baseUrl === "https://api.perplexity.ai/v1" &&
420
841
  [
421
842
  "pplx-decider-v1.1-27b",
422
843
  "pplx-decider-v1-27b",
844
+ "pplx-decider-v1.3",
845
+ "pplx-decider-flash-v1.3",
423
846
  "pplx-decider-v1.2",
424
847
  "pplx-decider-latest",
425
848
  "pplx-decider-flash-v1.2",
@@ -428,8 +851,12 @@ function knownMaxChoices(route: ResolvedModel): number | undefined {
428
851
  const clef =
429
852
  route.provider === "cloudflare" &&
430
853
  /^https:\/\/api\.cloudflare\.com\/client\/v4\/accounts\/[^/]+\/ai$/.test(route.baseUrl) &&
431
- ["@cf/cloudflare/clef", "@cf/cloudflare/clef-flash"].includes(route.model);
432
- return directJev || openai || perplexity || clef ? 255 : undefined;
854
+ ["@cf/cloudflare/clef", "@cf/cloudflare/clef-flash", "@cf/cloudflare/clef-omni"].includes(route.model);
855
+ const liquid =
856
+ route.provider === "liquid" &&
857
+ route.baseUrl === "https://api.liquid.ai/decisions/v1" &&
858
+ ["d1.2", "d1.2-ultra"].includes(route.model);
859
+ return directJev || sarvam || openai || perplexity || clef || liquid ? 255 : undefined;
433
860
  }
434
861
 
435
862
  export function listModels(settings: ClassifierSettings): string {