@hasna/switcher 0.1.2 → 0.1.3
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/README.md +5 -2
- package/dist/cli/index.js +2634 -615
- package/dist/cli.d.ts +2 -0
- package/dist/codex-model-policy.d.ts +65 -0
- package/dist/direct-launch.d.ts +2 -2
- package/dist/domain.d.ts +259 -2
- package/dist/gemini-model-policy.d.ts +56 -0
- package/dist/generated/api.d.ts +192 -0
- package/dist/harness-types.d.ts +9 -0
- package/dist/hermes-model-policy.d.ts +30 -0
- package/dist/index.js +93 -42
- package/dist/inference-gateway.d.ts +24 -0
- package/dist/launcher.d.ts +8 -3
- package/dist/mcp/index.js +107 -55
- package/dist/model-policy-schema.d.ts +137 -0
- package/dist/model-policy.d.ts +31 -0
- package/dist/native-model-policy.d.ts +23 -0
- package/dist/opencode-model-policy.d.ts +33 -0
- package/dist/ori-model-policy.d.ts +8 -0
- package/dist/sdk.d.ts +238 -5
- package/dist/sdk.js +93 -42
- package/dist/serve/index.js +1044 -88
- package/docs/MODEL-POLICY.md +82 -0
- package/openapi.json +836 -1
- package/package.json +3 -2
package/dist/sdk.d.ts
CHANGED
|
@@ -5,6 +5,8 @@ export type ProviderInput = components["schemas"]["ProviderInput"];
|
|
|
5
5
|
export type Provider = components["schemas"]["Provider"];
|
|
6
6
|
export type ProfileInput = components["schemas"]["ProfileInput"];
|
|
7
7
|
export type Profile = components["schemas"]["Profile"];
|
|
8
|
+
export type ModelPolicy = components["schemas"]["ModelPolicy"];
|
|
9
|
+
export type RoutingEvent = components["schemas"]["RoutingEvent"];
|
|
8
10
|
export type Model = components["schemas"]["Model"];
|
|
9
11
|
export type Catalog = components["schemas"]["Catalog"];
|
|
10
12
|
export type LaunchPlan = components["schemas"]["LaunchPlan"];
|
|
@@ -226,6 +228,26 @@ export declare class SwitcherClient {
|
|
|
226
228
|
providerId: string;
|
|
227
229
|
harness: "claude" | "codex" | "grok" | "opencode" | "opencode2" | "pi" | "omp" | "dsh" | "cline" | "hermes" | "prime-agent" | "gemini" | "aider" | "kilo";
|
|
228
230
|
model: string;
|
|
231
|
+
modelPolicy?: {
|
|
232
|
+
version: 1;
|
|
233
|
+
roles?: {
|
|
234
|
+
subagent?: string;
|
|
235
|
+
fast?: string;
|
|
236
|
+
planning?: string;
|
|
237
|
+
review?: string;
|
|
238
|
+
summary?: string;
|
|
239
|
+
compaction?: string;
|
|
240
|
+
weak?: string;
|
|
241
|
+
editor?: string;
|
|
242
|
+
};
|
|
243
|
+
allowedModels?: string[];
|
|
244
|
+
aliases?: {
|
|
245
|
+
[key: string]: string;
|
|
246
|
+
};
|
|
247
|
+
fallbacks?: {
|
|
248
|
+
[key: string]: string[];
|
|
249
|
+
};
|
|
250
|
+
};
|
|
229
251
|
version: number;
|
|
230
252
|
updatedAt: string;
|
|
231
253
|
}>>;
|
|
@@ -235,6 +257,26 @@ export declare class SwitcherClient {
|
|
|
235
257
|
providerId: string;
|
|
236
258
|
harness: "claude" | "codex" | "grok" | "opencode" | "opencode2" | "pi" | "omp" | "dsh" | "cline" | "hermes" | "prime-agent" | "gemini" | "aider" | "kilo";
|
|
237
259
|
model: string;
|
|
260
|
+
modelPolicy?: {
|
|
261
|
+
version: 1;
|
|
262
|
+
roles?: {
|
|
263
|
+
subagent?: string;
|
|
264
|
+
fast?: string;
|
|
265
|
+
planning?: string;
|
|
266
|
+
review?: string;
|
|
267
|
+
summary?: string;
|
|
268
|
+
compaction?: string;
|
|
269
|
+
weak?: string;
|
|
270
|
+
editor?: string;
|
|
271
|
+
};
|
|
272
|
+
allowedModels?: string[];
|
|
273
|
+
aliases?: {
|
|
274
|
+
[key: string]: string;
|
|
275
|
+
};
|
|
276
|
+
fallbacks?: {
|
|
277
|
+
[key: string]: string[];
|
|
278
|
+
};
|
|
279
|
+
};
|
|
238
280
|
version: number;
|
|
239
281
|
updatedAt: string;
|
|
240
282
|
}>;
|
|
@@ -244,6 +286,26 @@ export declare class SwitcherClient {
|
|
|
244
286
|
providerId: string;
|
|
245
287
|
harness: "claude" | "codex" | "grok" | "opencode" | "opencode2" | "pi" | "omp" | "dsh" | "cline" | "hermes" | "prime-agent" | "gemini" | "aider" | "kilo";
|
|
246
288
|
model: string;
|
|
289
|
+
modelPolicy?: {
|
|
290
|
+
version: 1;
|
|
291
|
+
roles?: {
|
|
292
|
+
subagent?: string;
|
|
293
|
+
fast?: string;
|
|
294
|
+
planning?: string;
|
|
295
|
+
review?: string;
|
|
296
|
+
summary?: string;
|
|
297
|
+
compaction?: string;
|
|
298
|
+
weak?: string;
|
|
299
|
+
editor?: string;
|
|
300
|
+
};
|
|
301
|
+
allowedModels?: string[];
|
|
302
|
+
aliases?: {
|
|
303
|
+
[key: string]: string;
|
|
304
|
+
};
|
|
305
|
+
fallbacks?: {
|
|
306
|
+
[key: string]: string[];
|
|
307
|
+
};
|
|
308
|
+
};
|
|
247
309
|
version: number;
|
|
248
310
|
updatedAt: string;
|
|
249
311
|
}>;
|
|
@@ -253,6 +315,26 @@ export declare class SwitcherClient {
|
|
|
253
315
|
providerId: string;
|
|
254
316
|
harness: "claude" | "codex" | "grok" | "opencode" | "opencode2" | "pi" | "omp" | "dsh" | "cline" | "hermes" | "prime-agent" | "gemini" | "aider" | "kilo";
|
|
255
317
|
model: string;
|
|
318
|
+
modelPolicy?: {
|
|
319
|
+
version: 1;
|
|
320
|
+
roles?: {
|
|
321
|
+
subagent?: string;
|
|
322
|
+
fast?: string;
|
|
323
|
+
planning?: string;
|
|
324
|
+
review?: string;
|
|
325
|
+
summary?: string;
|
|
326
|
+
compaction?: string;
|
|
327
|
+
weak?: string;
|
|
328
|
+
editor?: string;
|
|
329
|
+
};
|
|
330
|
+
allowedModels?: string[];
|
|
331
|
+
aliases?: {
|
|
332
|
+
[key: string]: string;
|
|
333
|
+
};
|
|
334
|
+
fallbacks?: {
|
|
335
|
+
[key: string]: string[];
|
|
336
|
+
};
|
|
337
|
+
};
|
|
256
338
|
version: number;
|
|
257
339
|
updatedAt: string;
|
|
258
340
|
}>;
|
|
@@ -294,6 +376,26 @@ export declare class SwitcherClient {
|
|
|
294
376
|
providerId: string;
|
|
295
377
|
harness: "claude" | "codex" | "grok" | "opencode" | "opencode2" | "pi" | "omp" | "dsh" | "cline" | "hermes" | "prime-agent" | "gemini" | "aider" | "kilo";
|
|
296
378
|
model: string;
|
|
379
|
+
modelPolicy?: {
|
|
380
|
+
version: 1;
|
|
381
|
+
roles?: {
|
|
382
|
+
subagent?: string;
|
|
383
|
+
fast?: string;
|
|
384
|
+
planning?: string;
|
|
385
|
+
review?: string;
|
|
386
|
+
summary?: string;
|
|
387
|
+
compaction?: string;
|
|
388
|
+
weak?: string;
|
|
389
|
+
editor?: string;
|
|
390
|
+
};
|
|
391
|
+
allowedModels?: string[];
|
|
392
|
+
aliases?: {
|
|
393
|
+
[key: string]: string;
|
|
394
|
+
};
|
|
395
|
+
fallbacks?: {
|
|
396
|
+
[key: string]: string[];
|
|
397
|
+
};
|
|
398
|
+
};
|
|
297
399
|
version: number;
|
|
298
400
|
updatedAt: string;
|
|
299
401
|
};
|
|
@@ -317,9 +419,30 @@ export declare class SwitcherClient {
|
|
|
317
419
|
warnings: string[];
|
|
318
420
|
}>;
|
|
319
421
|
listRuns(options?: {}): Promise<Page<{
|
|
422
|
+
modelPolicyVersion?: 1;
|
|
320
423
|
profileId: string;
|
|
321
424
|
harness: "claude" | "codex" | "grok" | "opencode" | "opencode2" | "pi" | "omp" | "dsh" | "cline" | "hermes" | "prime-agent" | "gemini" | "aider" | "kilo";
|
|
322
425
|
model: string;
|
|
426
|
+
modelPolicy?: {
|
|
427
|
+
version: 1;
|
|
428
|
+
roles?: {
|
|
429
|
+
subagent?: string;
|
|
430
|
+
fast?: string;
|
|
431
|
+
planning?: string;
|
|
432
|
+
review?: string;
|
|
433
|
+
summary?: string;
|
|
434
|
+
compaction?: string;
|
|
435
|
+
weak?: string;
|
|
436
|
+
editor?: string;
|
|
437
|
+
};
|
|
438
|
+
allowedModels?: string[];
|
|
439
|
+
aliases?: {
|
|
440
|
+
[key: string]: string;
|
|
441
|
+
};
|
|
442
|
+
fallbacks?: {
|
|
443
|
+
[key: string]: string[];
|
|
444
|
+
};
|
|
445
|
+
};
|
|
323
446
|
planToken: string;
|
|
324
447
|
version: number;
|
|
325
448
|
updatedAt: string;
|
|
@@ -331,11 +454,44 @@ export declare class SwitcherClient {
|
|
|
331
454
|
startedAt: string;
|
|
332
455
|
endedAt?: string;
|
|
333
456
|
exitCode?: number;
|
|
457
|
+
routingEvents?: {
|
|
458
|
+
at: string;
|
|
459
|
+
requestId: string;
|
|
460
|
+
requestedModel: string;
|
|
461
|
+
resolvedModel?: string;
|
|
462
|
+
reportedModel?: string;
|
|
463
|
+
decision: "allow" | "alias" | "reject" | "fallback";
|
|
464
|
+
role?: "main" | "subagent" | "fast" | "planning" | "review" | "summary" | "compaction" | "weak" | "editor";
|
|
465
|
+
reason?: string;
|
|
466
|
+
upstreamStatus?: number;
|
|
467
|
+
}[];
|
|
468
|
+
routingEventsDropped?: number;
|
|
334
469
|
}>>;
|
|
335
470
|
getRun(id: string): Promise<{
|
|
471
|
+
modelPolicyVersion?: 1;
|
|
336
472
|
profileId: string;
|
|
337
473
|
harness: "claude" | "codex" | "grok" | "opencode" | "opencode2" | "pi" | "omp" | "dsh" | "cline" | "hermes" | "prime-agent" | "gemini" | "aider" | "kilo";
|
|
338
474
|
model: string;
|
|
475
|
+
modelPolicy?: {
|
|
476
|
+
version: 1;
|
|
477
|
+
roles?: {
|
|
478
|
+
subagent?: string;
|
|
479
|
+
fast?: string;
|
|
480
|
+
planning?: string;
|
|
481
|
+
review?: string;
|
|
482
|
+
summary?: string;
|
|
483
|
+
compaction?: string;
|
|
484
|
+
weak?: string;
|
|
485
|
+
editor?: string;
|
|
486
|
+
};
|
|
487
|
+
allowedModels?: string[];
|
|
488
|
+
aliases?: {
|
|
489
|
+
[key: string]: string;
|
|
490
|
+
};
|
|
491
|
+
fallbacks?: {
|
|
492
|
+
[key: string]: string[];
|
|
493
|
+
};
|
|
494
|
+
};
|
|
339
495
|
planToken: string;
|
|
340
496
|
version: number;
|
|
341
497
|
updatedAt: string;
|
|
@@ -347,11 +503,46 @@ export declare class SwitcherClient {
|
|
|
347
503
|
startedAt: string;
|
|
348
504
|
endedAt?: string;
|
|
349
505
|
exitCode?: number;
|
|
506
|
+
routingEvents?: {
|
|
507
|
+
at: string;
|
|
508
|
+
requestId: string;
|
|
509
|
+
requestedModel: string;
|
|
510
|
+
resolvedModel?: string;
|
|
511
|
+
reportedModel?: string;
|
|
512
|
+
decision: "allow" | "alias" | "reject" | "fallback";
|
|
513
|
+
role?: "main" | "subagent" | "fast" | "planning" | "review" | "summary" | "compaction" | "weak" | "editor";
|
|
514
|
+
reason?: string;
|
|
515
|
+
upstreamStatus?: number;
|
|
516
|
+
}[];
|
|
517
|
+
routingEventsDropped?: number;
|
|
350
518
|
}>;
|
|
351
|
-
createRun(input: components["schemas"]["RunInput"],
|
|
519
|
+
createRun(input: Omit<components["schemas"]["RunInput"], "modelPolicyVersion"> & {
|
|
520
|
+
modelPolicyVersion?: 1;
|
|
521
|
+
}, idempotencyKey?: string): Promise<{
|
|
522
|
+
modelPolicyVersion?: 1;
|
|
352
523
|
profileId: string;
|
|
353
524
|
harness: "claude" | "codex" | "grok" | "opencode" | "opencode2" | "pi" | "omp" | "dsh" | "cline" | "hermes" | "prime-agent" | "gemini" | "aider" | "kilo";
|
|
354
525
|
model: string;
|
|
526
|
+
modelPolicy?: {
|
|
527
|
+
version: 1;
|
|
528
|
+
roles?: {
|
|
529
|
+
subagent?: string;
|
|
530
|
+
fast?: string;
|
|
531
|
+
planning?: string;
|
|
532
|
+
review?: string;
|
|
533
|
+
summary?: string;
|
|
534
|
+
compaction?: string;
|
|
535
|
+
weak?: string;
|
|
536
|
+
editor?: string;
|
|
537
|
+
};
|
|
538
|
+
allowedModels?: string[];
|
|
539
|
+
aliases?: {
|
|
540
|
+
[key: string]: string;
|
|
541
|
+
};
|
|
542
|
+
fallbacks?: {
|
|
543
|
+
[key: string]: string[];
|
|
544
|
+
};
|
|
545
|
+
};
|
|
355
546
|
planToken: string;
|
|
356
547
|
version: number;
|
|
357
548
|
updatedAt: string;
|
|
@@ -363,14 +554,44 @@ export declare class SwitcherClient {
|
|
|
363
554
|
startedAt: string;
|
|
364
555
|
endedAt?: string;
|
|
365
556
|
exitCode?: number;
|
|
557
|
+
routingEvents?: {
|
|
558
|
+
at: string;
|
|
559
|
+
requestId: string;
|
|
560
|
+
requestedModel: string;
|
|
561
|
+
resolvedModel?: string;
|
|
562
|
+
reportedModel?: string;
|
|
563
|
+
decision: "allow" | "alias" | "reject" | "fallback";
|
|
564
|
+
role?: "main" | "subagent" | "fast" | "planning" | "review" | "summary" | "compaction" | "weak" | "editor";
|
|
565
|
+
reason?: string;
|
|
566
|
+
upstreamStatus?: number;
|
|
567
|
+
}[];
|
|
568
|
+
routingEventsDropped?: number;
|
|
366
569
|
}>;
|
|
367
|
-
finishRun(id: string, version: number, input: {
|
|
368
|
-
|
|
369
|
-
exitCode: number;
|
|
370
|
-
}, idempotencyKey?: string): Promise<{
|
|
570
|
+
finishRun(id: string, version: number, input: components["schemas"]["RunUpdate"], idempotencyKey?: string): Promise<{
|
|
571
|
+
modelPolicyVersion?: 1;
|
|
371
572
|
profileId: string;
|
|
372
573
|
harness: "claude" | "codex" | "grok" | "opencode" | "opencode2" | "pi" | "omp" | "dsh" | "cline" | "hermes" | "prime-agent" | "gemini" | "aider" | "kilo";
|
|
373
574
|
model: string;
|
|
575
|
+
modelPolicy?: {
|
|
576
|
+
version: 1;
|
|
577
|
+
roles?: {
|
|
578
|
+
subagent?: string;
|
|
579
|
+
fast?: string;
|
|
580
|
+
planning?: string;
|
|
581
|
+
review?: string;
|
|
582
|
+
summary?: string;
|
|
583
|
+
compaction?: string;
|
|
584
|
+
weak?: string;
|
|
585
|
+
editor?: string;
|
|
586
|
+
};
|
|
587
|
+
allowedModels?: string[];
|
|
588
|
+
aliases?: {
|
|
589
|
+
[key: string]: string;
|
|
590
|
+
};
|
|
591
|
+
fallbacks?: {
|
|
592
|
+
[key: string]: string[];
|
|
593
|
+
};
|
|
594
|
+
};
|
|
374
595
|
planToken: string;
|
|
375
596
|
version: number;
|
|
376
597
|
updatedAt: string;
|
|
@@ -382,6 +603,18 @@ export declare class SwitcherClient {
|
|
|
382
603
|
startedAt: string;
|
|
383
604
|
endedAt?: string;
|
|
384
605
|
exitCode?: number;
|
|
606
|
+
routingEvents?: {
|
|
607
|
+
at: string;
|
|
608
|
+
requestId: string;
|
|
609
|
+
requestedModel: string;
|
|
610
|
+
resolvedModel?: string;
|
|
611
|
+
reportedModel?: string;
|
|
612
|
+
decision: "allow" | "alias" | "reject" | "fallback";
|
|
613
|
+
role?: "main" | "subagent" | "fast" | "planning" | "review" | "summary" | "compaction" | "weak" | "editor";
|
|
614
|
+
reason?: string;
|
|
615
|
+
upstreamStatus?: number;
|
|
616
|
+
}[];
|
|
617
|
+
routingEventsDropped?: number;
|
|
385
618
|
}>;
|
|
386
619
|
}
|
|
387
620
|
export declare function clientFromEnv(env?: Record<string, string | undefined>): SwitcherClient;
|
package/dist/sdk.js
CHANGED
|
@@ -1,10 +1,56 @@
|
|
|
1
1
|
// src/domain.ts
|
|
2
|
+
import { z as z2 } from "zod";
|
|
3
|
+
|
|
4
|
+
// src/model-policy-schema.ts
|
|
2
5
|
import { z } from "zod";
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
var
|
|
6
|
+
var policyModelIdSchema = z.string().min(1).max(300).regex(/^[^\u0000-\u001f\u007f]+$/);
|
|
7
|
+
var modelPolicyRoleSchema = z.enum(["subagent", "fast", "planning", "review", "summary", "compaction", "weak", "editor"]);
|
|
8
|
+
var boundedModelList = z.array(policyModelIdSchema).max(500);
|
|
9
|
+
var aliasSchema = z.string().regex(/^[A-Za-z0-9._/-]{1,120}$/).refine((v) => !["__proto__", "prototype", "constructor"].includes(v));
|
|
10
|
+
var boundedModelMap = z.record(aliasSchema, policyModelIdSchema).superRefine((value, ctx) => {
|
|
11
|
+
if (Object.keys(value).length > 200)
|
|
12
|
+
ctx.addIssue({ code: "custom", message: "Model policy maps may contain at most 200 entries." });
|
|
13
|
+
});
|
|
14
|
+
var fallbacksSchema = z.record(policyModelIdSchema, z.array(policyModelIdSchema).max(20)).superRefine((value, ctx) => {
|
|
15
|
+
if (Object.keys(value).length > 200)
|
|
16
|
+
ctx.addIssue({ code: "custom", message: "Model policy fallback maps may contain at most 200 entries." });
|
|
17
|
+
});
|
|
18
|
+
var modelPolicySchema = z.object({
|
|
19
|
+
version: z.literal(1).default(1),
|
|
20
|
+
roles: z.object({
|
|
21
|
+
subagent: policyModelIdSchema.optional(),
|
|
22
|
+
fast: policyModelIdSchema.optional(),
|
|
23
|
+
planning: policyModelIdSchema.optional(),
|
|
24
|
+
review: policyModelIdSchema.optional(),
|
|
25
|
+
summary: policyModelIdSchema.optional(),
|
|
26
|
+
compaction: policyModelIdSchema.optional(),
|
|
27
|
+
weak: policyModelIdSchema.optional(),
|
|
28
|
+
editor: policyModelIdSchema.optional()
|
|
29
|
+
}).strict().optional(),
|
|
30
|
+
allowedModels: boundedModelList.optional(),
|
|
31
|
+
aliases: boundedModelMap.optional(),
|
|
32
|
+
fallbacks: fallbacksSchema.optional()
|
|
33
|
+
}).strict();
|
|
34
|
+
var routingDecisionSchema = z.enum(["allow", "alias", "reject", "fallback"]);
|
|
35
|
+
var routingEventRoleSchema = z.enum(["main", ...modelPolicyRoleSchema.options]);
|
|
36
|
+
var routingEventSchema = z.object({
|
|
37
|
+
at: z.string().datetime({ offset: true }),
|
|
38
|
+
requestId: z.string().regex(/^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/),
|
|
39
|
+
requestedModel: policyModelIdSchema,
|
|
40
|
+
resolvedModel: policyModelIdSchema.optional(),
|
|
41
|
+
reportedModel: policyModelIdSchema.optional(),
|
|
42
|
+
decision: routingDecisionSchema,
|
|
43
|
+
role: routingEventRoleSchema.optional(),
|
|
44
|
+
reason: z.string().regex(/^[a-z][a-z0-9_]{0,63}$/).optional(),
|
|
45
|
+
upstreamStatus: z.number().int().min(100).max(599).optional()
|
|
46
|
+
}).strict();
|
|
47
|
+
var routingEventsSchema = z.array(routingEventSchema).max(1000);
|
|
48
|
+
// src/domain.ts
|
|
49
|
+
var harnessSchema = z2.enum(["claude", "codex", "grok", "opencode", "opencode2", "pi", "omp", "dsh", "cline", "hermes", "prime-agent", "gemini", "aider", "kilo"]);
|
|
50
|
+
var protocolSchema = z2.enum(["anthropic-messages", "openai-responses", "openai-chat", "gemini-generate-content"]);
|
|
51
|
+
var idSchema = z2.string().regex(/^[a-zA-Z0-9][a-zA-Z0-9._-]{0,79}$/);
|
|
52
|
+
var label = z2.string().min(1).max(200);
|
|
53
|
+
var envRef = z2.string().regex(/^SWITCHER_PROVIDER_[A-Z0-9_]+$/);
|
|
8
54
|
function endpoint(value) {
|
|
9
55
|
let url;
|
|
10
56
|
try {
|
|
@@ -17,74 +63,79 @@ function endpoint(value) {
|
|
|
17
63
|
throw new Fault(400, "invalid_url", "URL must use HTTPS, contain no credentials/query/fragment, or use HTTP on loopback.");
|
|
18
64
|
return url.href.replace(/\/+$/, "");
|
|
19
65
|
}
|
|
20
|
-
var urlSchema =
|
|
66
|
+
var urlSchema = z2.string().max(2000).superRefine((v, ctx) => {
|
|
21
67
|
try {
|
|
22
68
|
endpoint(v);
|
|
23
69
|
} catch {
|
|
24
70
|
ctx.addIssue({ code: "custom", message: "Invalid endpoint URL" });
|
|
25
71
|
}
|
|
26
72
|
}).transform(endpoint);
|
|
27
|
-
var modelSchema =
|
|
28
|
-
id:
|
|
73
|
+
var modelSchema = z2.object({
|
|
74
|
+
id: z2.string().min(1).max(300),
|
|
29
75
|
name: label,
|
|
30
|
-
description:
|
|
31
|
-
available:
|
|
32
|
-
contextWindow:
|
|
33
|
-
maxOutputTokens:
|
|
34
|
-
inputModalities:
|
|
35
|
-
outputModalities:
|
|
36
|
-
supportedParameters:
|
|
37
|
-
supportedGenerationMethods:
|
|
76
|
+
description: z2.string().max(8000).optional(),
|
|
77
|
+
available: z2.boolean().optional(),
|
|
78
|
+
contextWindow: z2.number().int().positive().optional(),
|
|
79
|
+
maxOutputTokens: z2.number().int().positive().optional(),
|
|
80
|
+
inputModalities: z2.array(z2.string().max(50)).max(20).optional(),
|
|
81
|
+
outputModalities: z2.array(z2.string().max(50)).max(20).optional(),
|
|
82
|
+
supportedParameters: z2.array(z2.string().max(100)).max(100).optional(),
|
|
83
|
+
supportedGenerationMethods: z2.array(z2.string().min(1).max(100)).max(100).optional()
|
|
38
84
|
}).strict();
|
|
39
|
-
var providerInputSchema =
|
|
85
|
+
var providerInputSchema = z2.object({
|
|
40
86
|
id: idSchema,
|
|
41
87
|
name: label,
|
|
42
88
|
baseUrl: urlSchema,
|
|
43
89
|
protocol: protocolSchema,
|
|
44
90
|
credentialEnv: envRef.optional(),
|
|
45
|
-
authStyle:
|
|
91
|
+
authStyle: z2.enum(["bearer", "x-api-key", "api-key"]).default("bearer"),
|
|
46
92
|
catalogBaseUrl: urlSchema.optional(),
|
|
47
|
-
catalogFormat:
|
|
48
|
-
catalogAuthStyle:
|
|
93
|
+
catalogFormat: z2.enum(["openai", "ollama", "mistral", "together", "fireworks", "dashscope", "gemini", "none"]).optional(),
|
|
94
|
+
catalogAuthStyle: z2.enum(["bearer", "x-api-key", "api-key", "none"]).optional(),
|
|
49
95
|
catalogCredentialEnv: envRef.optional(),
|
|
50
|
-
catalogAccountId:
|
|
51
|
-
modelsPath:
|
|
52
|
-
manualModels:
|
|
96
|
+
catalogAccountId: z2.string().regex(/^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/).optional(),
|
|
97
|
+
modelsPath: z2.string().regex(/^[a-zA-Z0-9_/-]+$/).max(200).default("models"),
|
|
98
|
+
manualModels: z2.array(modelSchema).max(1e4).default([])
|
|
53
99
|
}).strict().refine((p) => !p.modelsPath.split("/").includes("..") && !p.modelsPath.startsWith("/"), "modelsPath must be relative");
|
|
54
|
-
var providerPresetSchema =
|
|
100
|
+
var providerPresetSchema = z2.object({
|
|
55
101
|
id: idSchema,
|
|
56
102
|
name: label,
|
|
57
103
|
credentialEnv: envRef.optional(),
|
|
58
|
-
credentialAliases:
|
|
59
|
-
protocols:
|
|
104
|
+
credentialAliases: z2.array(z2.string().regex(/^[A-Z][A-Z0-9_]+$/)),
|
|
105
|
+
protocols: z2.array(z2.object({
|
|
60
106
|
protocol: protocolSchema,
|
|
61
107
|
baseUrl: urlSchema.optional(),
|
|
62
|
-
authStyle:
|
|
108
|
+
authStyle: z2.enum(["bearer", "x-api-key", "api-key"]),
|
|
63
109
|
catalogBaseUrl: urlSchema.optional(),
|
|
64
|
-
catalogFormat:
|
|
65
|
-
catalogAuthStyle:
|
|
66
|
-
modelsPath:
|
|
67
|
-
notes:
|
|
110
|
+
catalogFormat: z2.enum(["openai", "ollama", "mistral", "together", "fireworks", "dashscope", "gemini", "none"]),
|
|
111
|
+
catalogAuthStyle: z2.enum(["bearer", "x-api-key", "api-key", "none"]).optional(),
|
|
112
|
+
modelsPath: z2.string(),
|
|
113
|
+
notes: z2.array(z2.string())
|
|
68
114
|
}).strict()).min(1),
|
|
69
|
-
sources:
|
|
70
|
-
verification:
|
|
115
|
+
sources: z2.array(z2.string().url()),
|
|
116
|
+
verification: z2.literal("documented")
|
|
71
117
|
}).strict();
|
|
72
|
-
var profileInputSchema =
|
|
118
|
+
var profileInputSchema = z2.object({
|
|
73
119
|
id: idSchema,
|
|
74
120
|
name: label,
|
|
75
121
|
providerId: idSchema,
|
|
76
122
|
harness: harnessSchema,
|
|
77
|
-
model:
|
|
123
|
+
model: z2.string().min(1).max(300),
|
|
124
|
+
modelPolicy: modelPolicySchema.optional()
|
|
78
125
|
}).strict();
|
|
79
|
-
var runInputSchema =
|
|
126
|
+
var runInputSchema = z2.object({
|
|
127
|
+
modelPolicyVersion: z2.literal(1),
|
|
80
128
|
profileId: idSchema,
|
|
81
129
|
harness: harnessSchema,
|
|
82
|
-
model:
|
|
83
|
-
|
|
130
|
+
model: z2.string().min(1).max(300),
|
|
131
|
+
modelPolicy: modelPolicySchema.optional(),
|
|
132
|
+
planToken: z2.string().regex(/^[a-f0-9]{64}$/)
|
|
84
133
|
}).strict();
|
|
85
|
-
var runUpdateSchema =
|
|
86
|
-
status:
|
|
87
|
-
exitCode:
|
|
134
|
+
var runUpdateSchema = z2.object({
|
|
135
|
+
status: z2.enum(["exited", "failed", "interrupted"]),
|
|
136
|
+
exitCode: z2.number().int().min(0).max(255),
|
|
137
|
+
routingEvents: routingEventsSchema.optional(),
|
|
138
|
+
routingEventsDropped: z2.number().int().min(0).max(1e6).optional()
|
|
88
139
|
}).strict();
|
|
89
140
|
|
|
90
141
|
class Fault extends Error {
|
|
@@ -410,7 +461,7 @@ class SwitcherClient {
|
|
|
410
461
|
return this.request("GET", `/v1/runs/${encodeURIComponent(id)}`);
|
|
411
462
|
}
|
|
412
463
|
createRun(input, idempotencyKey) {
|
|
413
|
-
return this.request("POST", "/v1/runs", input, { idempotencyKey });
|
|
464
|
+
return this.request("POST", "/v1/runs", { ...input, modelPolicyVersion: 1 }, { idempotencyKey });
|
|
414
465
|
}
|
|
415
466
|
finishRun(id, version, input, idempotencyKey) {
|
|
416
467
|
return this.request("PATCH", `/v1/runs/${encodeURIComponent(id)}`, input, { version, idempotencyKey });
|