@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.
- package/CHANGELOG.md +48 -0
- package/COMPUTER_USE.md +117 -0
- package/README.md +344 -30
- package/dist/auth.d.ts +4 -2
- package/dist/auth.js +18 -2
- package/dist/box-tool.d.ts +4 -0
- package/dist/box-tool.js +79 -0
- package/dist/box.d.ts +32 -0
- package/dist/box.js +148 -0
- package/dist/choices.js +35 -1
- package/dist/classify.d.ts +6 -0
- package/dist/classify.js +4 -4
- package/dist/computer-use-state.d.ts +9 -0
- package/dist/computer-use-state.js +160 -0
- package/dist/computer-use-tool.d.ts +52 -0
- package/dist/computer-use-tool.js +78 -0
- package/dist/computer-use-types.d.ts +132 -0
- package/dist/computer-use-types.js +1 -0
- package/dist/computer-use.d.ts +22 -0
- package/dist/computer-use.js +223 -0
- package/dist/config.d.ts +140 -3
- package/dist/config.js +405 -20
- package/dist/cost.js +42 -4
- package/dist/durable.d.ts +34 -0
- package/dist/durable.js +237 -0
- package/dist/extension.d.ts +2 -247
- package/dist/extension.js +53 -190
- package/dist/extract.d.ts +11 -0
- package/dist/extract.js +191 -0
- package/dist/http.d.ts +6 -1
- package/dist/http.js +64 -28
- package/dist/image-content.d.ts +12 -0
- package/dist/image-content.js +90 -0
- package/dist/index.d.ts +10 -1
- package/dist/index.js +3 -0
- package/dist/inputs.d.ts +24 -2
- package/dist/inputs.js +565 -134
- package/dist/mcp-cli.d.ts +2 -0
- package/dist/mcp-cli.js +39 -0
- package/dist/mcp-server.d.ts +28 -0
- package/dist/mcp-server.js +121 -0
- package/dist/mcp-tool-definitions.d.ts +19 -0
- package/dist/mcp-tool-definitions.js +64 -0
- package/dist/providers.d.ts +1 -0
- package/dist/providers.js +1218 -124
- package/dist/tool-contracts.d.ts +785 -0
- package/dist/tool-contracts.js +530 -0
- package/dist/tree.js +1 -1
- package/dist/types.d.ts +314 -20
- package/dist/validation.js +181 -44
- package/package.json +33 -5
- package/src/auth.ts +26 -2
- package/src/box-tool.ts +110 -0
- package/src/box.ts +253 -0
- package/src/choices.ts +44 -2
- package/src/classify.ts +10 -6
- package/src/computer-use-state.ts +145 -0
- package/src/computer-use-tool.ts +76 -0
- package/src/computer-use-types.ts +127 -0
- package/src/computer-use.ts +216 -0
- package/src/config.ts +454 -23
- package/src/cost.ts +42 -4
- package/src/durable.ts +298 -0
- package/src/extension.ts +79 -265
- package/src/extract.ts +228 -0
- package/src/http.ts +63 -32
- package/src/image-content.ts +77 -0
- package/src/index.ts +25 -0
- package/src/inputs.ts +603 -184
- package/src/mcp-cli.ts +44 -0
- package/src/mcp-server.ts +179 -0
- package/src/mcp-tool-definitions.ts +104 -0
- package/src/providers.ts +1398 -144
- package/src/tool-contracts.ts +785 -0
- package/src/tree.ts +1 -1
- package/src/types.ts +248 -11
- package/src/validation.ts +169 -96
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: [
|
|
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,10 +186,28 @@ 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"] },
|
|
191
|
+
{ id: "pplx-decider-v1.2", input: ["text", "image"] },
|
|
192
|
+
{ id: "pplx-decider-flash-v1.2", input: ["text", "image"] },
|
|
193
|
+
{ id: "pplx-decider-latest", input: ["text", "image"] },
|
|
194
|
+
{ id: "pplx-decider-flash-latest", input: ["text", "image"] },
|
|
50
195
|
{ id: "pplx-decider-v1.1-27b", input: ["text", "image"] },
|
|
51
196
|
{ id: "pplx-decider-v1-27b", input: ["text", "image"] },
|
|
52
197
|
],
|
|
53
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
|
+
},
|
|
54
211
|
{
|
|
55
212
|
id: "typesafe",
|
|
56
213
|
route: "typesafe-api",
|
|
@@ -75,9 +232,19 @@ export const BUILT_INS = [
|
|
|
75
232
|
models: [
|
|
76
233
|
{ id: "@cf/cloudflare/clef", input: ["text", "image"] },
|
|
77
234
|
{ id: "@cf/cloudflare/clef-flash", input: ["text", "image"] },
|
|
235
|
+
{ id: "@cf/cloudflare/clef-omni", input: ["text", "image", "audio", "video"] },
|
|
78
236
|
{ id: "typesafe/jev" },
|
|
79
237
|
],
|
|
80
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
|
+
},
|
|
81
248
|
{
|
|
82
249
|
id: "openrouter",
|
|
83
250
|
route: "openrouter-api",
|
|
@@ -87,6 +254,30 @@ export const BUILT_INS = [
|
|
|
87
254
|
envVar: "OPENROUTER_API_KEY",
|
|
88
255
|
models: [{ id: "typesafe/jev-1.13" }, { id: "~typesafe/jev-latest" }],
|
|
89
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
|
+
},
|
|
90
281
|
] satisfies Array<{
|
|
91
282
|
id: string;
|
|
92
283
|
route: string;
|
|
@@ -97,6 +288,154 @@ export const BUILT_INS = [
|
|
|
97
288
|
models: ModelDefinition[];
|
|
98
289
|
}>;
|
|
99
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
|
+
|
|
100
439
|
export function loadClassifierSettings(
|
|
101
440
|
cwd: string,
|
|
102
441
|
projectTrusted = false,
|
|
@@ -196,6 +535,7 @@ function headers(value: unknown): Record<string, string> {
|
|
|
196
535
|
const protectedNames = [
|
|
197
536
|
"authorization",
|
|
198
537
|
"api-key",
|
|
538
|
+
"api-subscription-key",
|
|
199
539
|
"content-type",
|
|
200
540
|
"content-length",
|
|
201
541
|
"host",
|
|
@@ -254,6 +594,7 @@ export function configuredRoutes(
|
|
|
254
594
|
export function resolveModel(
|
|
255
595
|
settings: ClassifierSettings,
|
|
256
596
|
selected: ClassifierRoute = configuredDefault(settings),
|
|
597
|
+
source: CredentialSource = "pi-store",
|
|
257
598
|
): ResolvedModel {
|
|
258
599
|
choicePolicy(settings);
|
|
259
600
|
const { provider: routeId, model: modelId } = routePair(selected, "route");
|
|
@@ -265,9 +606,10 @@ export function resolveModel(
|
|
|
265
606
|
return configuration(
|
|
266
607
|
"Provider routes must be short identifiers and model IDs must be at most 256 characters without control characters.",
|
|
267
608
|
);
|
|
268
|
-
const builtIn =
|
|
269
|
-
(entry) => entry.route === routeId
|
|
270
|
-
|
|
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);
|
|
271
613
|
if (settings.providers !== undefined && !isRecord(settings.providers))
|
|
272
614
|
return configuration("providers must be an object.");
|
|
273
615
|
if (
|
|
@@ -291,9 +633,19 @@ export function resolveModel(
|
|
|
291
633
|
if (
|
|
292
634
|
![
|
|
293
635
|
"openai-decisions",
|
|
636
|
+
"openrouter-decisions",
|
|
637
|
+
"gemini-decisions",
|
|
638
|
+
"inception-decisions",
|
|
639
|
+
"parallel-decisions",
|
|
640
|
+
"local-system-one",
|
|
294
641
|
"perplexity-decisions",
|
|
642
|
+
"sarvam-system-one",
|
|
295
643
|
"system-one",
|
|
644
|
+
"liquid-system-one",
|
|
296
645
|
"cloudflare-system-one",
|
|
646
|
+
"cloudflare-clairic",
|
|
647
|
+
"openrouter-extractions",
|
|
648
|
+
"litellm-extraction",
|
|
297
649
|
"microsoft-system-one",
|
|
298
650
|
].includes(api)
|
|
299
651
|
)
|
|
@@ -309,7 +661,9 @@ export function resolveModel(
|
|
|
309
661
|
!m.id.trim() ||
|
|
310
662
|
(m.input !== undefined &&
|
|
311
663
|
(!Array.isArray(m.input) ||
|
|
312
|
-
m.input.some(
|
|
664
|
+
m.input.some(
|
|
665
|
+
(x) => x !== "text" && x !== "image" && x !== "audio" && x !== "video",
|
|
666
|
+
))) ||
|
|
313
667
|
(m.box !== undefined && typeof m.box !== "boolean"),
|
|
314
668
|
)
|
|
315
669
|
) {
|
|
@@ -323,19 +677,37 @@ export function resolveModel(
|
|
|
323
677
|
return configuration(
|
|
324
678
|
"The selected model is not declared in customProviders.<id>.models.",
|
|
325
679
|
);
|
|
326
|
-
for (const flag of ["experimentalImages", "experimentalBox"] as const) {
|
|
680
|
+
for (const flag of ["experimentalImages", "experimentalBox", "longContext"] as const) {
|
|
327
681
|
if (raw[flag] !== undefined && typeof raw[flag] !== "boolean")
|
|
328
682
|
return configuration(flag + " must be a boolean.");
|
|
329
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");
|
|
330
702
|
let baseUrl = optionalString(raw.baseUrl, "baseUrl") ?? builtIn?.baseUrl;
|
|
331
|
-
if (api === "cloudflare-system-one" && !baseUrl)
|
|
703
|
+
if ((api === "cloudflare-system-one" || api === "cloudflare-clairic") && !baseUrl)
|
|
332
704
|
baseUrl =
|
|
333
705
|
"https://api.cloudflare.com/client/v4/accounts/" +
|
|
334
|
-
cloudflareAccountId(optionalString(raw.accountId, "accountId")) +
|
|
706
|
+
cloudflareAccountId(optionalString(raw.accountId, "accountId"), source) +
|
|
335
707
|
"/ai";
|
|
336
708
|
if (!baseUrl)
|
|
337
709
|
return configuration(
|
|
338
|
-
"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.",
|
|
339
711
|
);
|
|
340
712
|
const timeout = settings.requestTimeoutMs ?? 30_000;
|
|
341
713
|
if (!Number.isInteger(timeout) || timeout < 100 || timeout > 300_000)
|
|
@@ -348,32 +720,78 @@ export function resolveModel(
|
|
|
348
720
|
return configuration(
|
|
349
721
|
"API-key references must be resolved in global settings; project settings cannot expand environment variables or execute commands.",
|
|
350
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
|
+
}
|
|
351
738
|
const isJevDirect = builtIn?.id === "typesafe";
|
|
739
|
+
const openRouter = api === "openrouter-decisions" ? openRouterDecisionCapabilities(modelId) : undefined;
|
|
352
740
|
const result: ResolvedModel = {
|
|
353
741
|
route: builtIn?.route ?? routeId,
|
|
354
742
|
provider: builtIn?.id ?? routeId,
|
|
355
743
|
model: modelId,
|
|
356
744
|
api,
|
|
745
|
+
mediaFormat: api === "system-one" ? "jev-assets" : openRouter ? "openrouter-parts" : "base64-object",
|
|
357
746
|
baseUrl: validateBaseUrl(baseUrl),
|
|
358
|
-
headers:
|
|
747
|
+
headers: resolvedHeaders,
|
|
748
|
+
...(gatewayId !== undefined ? { gatewayId } : {}),
|
|
359
749
|
credentialProvider: builtIn?.credentialProvider ?? routeId,
|
|
360
750
|
images:
|
|
361
|
-
|
|
362
|
-
?
|
|
751
|
+
openRouter
|
|
752
|
+
? openRouter.images > 0
|
|
363
753
|
: api === "system-one"
|
|
364
754
|
? Boolean(
|
|
365
755
|
raw.experimentalImages && definition?.input?.includes("image"),
|
|
366
756
|
)
|
|
367
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
|
+
),
|
|
368
775
|
box: Boolean(
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
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,
|
|
374
789
|
),
|
|
375
790
|
experimentalImages: raw.experimentalImages === true,
|
|
791
|
+
authMode: resolvedAuthMode,
|
|
792
|
+
longContext: raw.longContext === true,
|
|
376
793
|
requestTimeoutMs: timeout,
|
|
794
|
+
limits: configuredLimits(raw.limits, api, builtIn?.id, modelId),
|
|
377
795
|
};
|
|
378
796
|
const pricing = resolvePricing(
|
|
379
797
|
result.provider,
|
|
@@ -406,16 +824,25 @@ function knownMaxChoices(route: ResolvedModel): number | undefined {
|
|
|
406
824
|
route.provider === "typesafe" &&
|
|
407
825
|
route.baseUrl === "https://api.typesafe.ai/v1" &&
|
|
408
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";
|
|
409
831
|
const openai =
|
|
410
|
-
route.provider === "openai" &&
|
|
411
|
-
|
|
412
|
-
|
|
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));
|
|
413
838
|
const perplexity =
|
|
414
839
|
route.provider === "perplexity" &&
|
|
415
840
|
route.baseUrl === "https://api.perplexity.ai/v1" &&
|
|
416
841
|
[
|
|
417
842
|
"pplx-decider-v1.1-27b",
|
|
418
843
|
"pplx-decider-v1-27b",
|
|
844
|
+
"pplx-decider-v1.3",
|
|
845
|
+
"pplx-decider-flash-v1.3",
|
|
419
846
|
"pplx-decider-v1.2",
|
|
420
847
|
"pplx-decider-latest",
|
|
421
848
|
"pplx-decider-flash-v1.2",
|
|
@@ -424,8 +851,12 @@ function knownMaxChoices(route: ResolvedModel): number | undefined {
|
|
|
424
851
|
const clef =
|
|
425
852
|
route.provider === "cloudflare" &&
|
|
426
853
|
/^https:\/\/api\.cloudflare\.com\/client\/v4\/accounts\/[^/]+\/ai$/.test(route.baseUrl) &&
|
|
427
|
-
["@cf/cloudflare/clef", "@cf/cloudflare/clef-flash"].includes(route.model);
|
|
428
|
-
|
|
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;
|
|
429
860
|
}
|
|
430
861
|
|
|
431
862
|
export function listModels(settings: ClassifierSettings): string {
|