@hasna/switcher 0.2.2 → 0.2.4
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/Dockerfile +38 -8
- package/README.md +14 -9
- package/dist/cli/index.js +445 -151
- package/dist/credentials.d.ts +18 -62
- package/dist/direct-launch.d.ts +2 -2
- package/dist/domain.d.ts +78 -4
- package/dist/generated/api.d.ts +109 -1
- package/dist/index.js +4 -0
- package/dist/mcp/index.js +1014 -54
- package/dist/mint/index.js +136 -0
- package/dist/mint-key.d.ts +34 -0
- package/dist/provider-credential-onboarding.d.ts +73 -0
- package/dist/sdk.d.ts +21 -1
- package/dist/sdk.js +4 -0
- package/dist/serve/index.js +305 -45
- package/dist/server.d.ts +2 -1
- package/dist/service.d.ts +8 -1
- package/dist/store.d.ts +4 -0
- package/hasna.contract.json +20 -6
- package/openapi.json +135 -9
- package/package.json +6 -3
package/dist/credentials.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { type CredentialChainOptions } from "@hasna/contracts/client";
|
|
3
3
|
import { CommandInterrupted, type ProviderInput } from "./domain";
|
|
4
|
+
export declare const vaultKeySchema: z.ZodString;
|
|
4
5
|
declare const keychain: z.ZodObject<{
|
|
5
6
|
kind: z.ZodLiteral<"keychain">;
|
|
6
7
|
service: z.ZodString;
|
|
@@ -273,70 +274,25 @@ export declare class CredentialResolver {
|
|
|
273
274
|
export declare class CredentialInterrupted extends CommandInterrupted {
|
|
274
275
|
constructor(exitCode: number);
|
|
275
276
|
}
|
|
277
|
+
export type VaultOperatorResolution = {
|
|
278
|
+
environment: NodeJS.ProcessEnv;
|
|
279
|
+
source: string;
|
|
280
|
+
tier: z.infer<typeof credentialTier>;
|
|
281
|
+
url: string;
|
|
282
|
+
};
|
|
283
|
+
/** Select an operator through the shared credential seam, then pin that choice. */
|
|
284
|
+
export declare function resolveVaultOperatorEnvironment(binding: CredentialBinding, env: NodeJS.ProcessEnv, options?: Pick<CredentialChainOptions, "keychain">): Promise<VaultOperatorResolution>;
|
|
276
285
|
/** Select an operator through the shared credential seam, then pin that choice. */
|
|
277
286
|
export declare function vaultEnvironment(binding: CredentialBinding, env: NodeJS.ProcessEnv, options?: Pick<CredentialChainOptions, "keychain">): Promise<NodeJS.ProcessEnv>;
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
} | {
|
|
288
|
-
kind: "env";
|
|
289
|
-
} | {
|
|
290
|
-
kind: "keychain";
|
|
291
|
-
account: string;
|
|
292
|
-
};
|
|
293
|
-
};
|
|
294
|
-
type CredentialResolverLike = Pick<CredentialResolver, "resolve"> & {
|
|
295
|
-
bindings: Pick<CredentialBindings, "get" | "bind">;
|
|
296
|
-
};
|
|
297
|
-
export type ProviderAuthenticationResult = {
|
|
298
|
-
authenticated: boolean;
|
|
299
|
-
status?: number;
|
|
300
|
-
unsupported?: boolean;
|
|
301
|
-
};
|
|
302
|
-
export type EnsureProviderCredentialOptions = {
|
|
303
|
-
interactive?: boolean;
|
|
304
|
-
resolver?: CredentialResolverLike;
|
|
305
|
-
env?: NodeJS.ProcessEnv;
|
|
306
|
-
vaultExecutable?: string;
|
|
307
|
-
discoverVaultReferences?: (request: {
|
|
308
|
-
provider: ProviderInput;
|
|
309
|
-
credentialEnv: string;
|
|
310
|
-
}) => Promise<VaultCredentialReference[]>;
|
|
311
|
-
selectVaultReference?: (request: {
|
|
312
|
-
provider: ProviderInput;
|
|
313
|
-
matches: VaultCredentialReference[];
|
|
314
|
-
}) => Promise<VaultCredentialReference | undefined>;
|
|
315
|
-
verifyProviderAuthentication?: (request: {
|
|
316
|
-
provider: ProviderInput;
|
|
317
|
-
credential: string;
|
|
318
|
-
}) => Promise<ProviderAuthenticationResult>;
|
|
319
|
-
};
|
|
320
|
-
export type PreparedProviderCredential = {
|
|
321
|
-
source: "not-required" | "environment" | "binding";
|
|
322
|
-
configured: boolean;
|
|
323
|
-
verified: boolean;
|
|
324
|
-
providerFingerprint: string;
|
|
325
|
-
readonly resolveCredential: (provider: ProviderInput) => Promise<string | undefined>;
|
|
326
|
-
};
|
|
327
|
-
export declare const providerCredentialSetupCommand: (provider: ProviderInput) => string;
|
|
328
|
-
export declare function discoverVaultReferences(provider: ProviderInput, env?: NodeJS.ProcessEnv, vaultExecutable?: string): Promise<VaultCredentialReference[]>;
|
|
329
|
-
export declare function selectVaultReference({ provider, matches }: {
|
|
330
|
-
provider: ProviderInput;
|
|
331
|
-
matches: VaultCredentialReference[];
|
|
332
|
-
}): Promise<VaultCredentialReference | undefined>;
|
|
333
|
-
export declare function verifyProviderAuthentication({ provider, credential, fetch: fetchImpl }: {
|
|
334
|
-
provider: ProviderInput;
|
|
335
|
-
credential: string;
|
|
336
|
-
fetch?: typeof fetch;
|
|
337
|
-
}): Promise<ProviderAuthenticationResult>;
|
|
338
|
-
export declare function providerCredentialFingerprint(provider: ProviderInput): string;
|
|
339
|
-
export declare function ensureProviderCredential(provider: ProviderInput, options?: EnsureProviderCredentialOptions): Promise<PreparedProviderCredential>;
|
|
287
|
+
/** Vault children never own a harness or a TTY; their entire process group is bounded. */
|
|
288
|
+
export declare function runVaultCommand(binding: CredentialBinding, args: string[], env: NodeJS.ProcessEnv, delivery?: NodeJS.ProcessEnv, options?: {
|
|
289
|
+
captureBytes?: number;
|
|
290
|
+
oversizeCode?: string;
|
|
291
|
+
oversizeMessage?: string;
|
|
292
|
+
lookupCode?: string;
|
|
293
|
+
lookupMessage?: string;
|
|
294
|
+
operator?: VaultOperatorResolution;
|
|
295
|
+
}): Promise<string>;
|
|
340
296
|
/** Internal child mode: the key travels only through an authenticated loopback request. */
|
|
341
297
|
export declare function deliverVaultCredential(): Promise<void>;
|
|
342
298
|
export {};
|
package/dist/direct-launch.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { SwitcherClient, type Provider, type Profile } from "./sdk";
|
|
2
|
-
|
|
2
|
+
export { launchCatalog } from "./provider-credential-onboarding";
|
|
3
|
+
import { type Model, type ModelPolicy } from "./domain";
|
|
3
4
|
import { type PresetOptions } from "./presets";
|
|
4
5
|
export declare function resolveLaunchProvider(client: SwitcherClient, selector: string, options?: PresetOptions): Promise<Provider>;
|
|
5
|
-
export declare function launchCatalog(client: SwitcherClient, provider: Provider, dryRun?: boolean): Promise<Catalog>;
|
|
6
6
|
export declare function selectModel(models: Model[], query?: string, harness?: Profile["harness"]): Promise<string>;
|
|
7
7
|
export declare function ensureLaunchProfile(client: SwitcherClient, provider: Provider, harness: Profile["harness"], model: string, modelPolicy?: ModelPolicy): Promise<Profile>;
|
package/dist/domain.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { type RoutingEvent } from "./model-policy-schema";
|
|
|
3
3
|
export { modelPolicySchema, routingEventSchema, routingEventsSchema } from "./model-policy-schema";
|
|
4
4
|
export type { ModelPolicy, RoutingEvent } from "./model-policy-schema";
|
|
5
5
|
export type { AuthStyle } from "./auth";
|
|
6
|
-
export declare const VERSION = "0.2.
|
|
6
|
+
export declare const VERSION = "0.2.4";
|
|
7
7
|
export declare const harnessSchema: z.ZodEnum<["claude", "codex", "grok", "opencode", "opencode2", "pi", "omp", "dsh", "cline", "hermes", "prime-agent", "gemini", "aider", "kilo"]>;
|
|
8
8
|
export declare const protocolSchema: z.ZodEnum<["anthropic-messages", "openai-responses", "openai-chat", "gemini-generate-content"]>;
|
|
9
9
|
export declare const idSchema: z.ZodString;
|
|
@@ -767,11 +767,85 @@ export type Run = Omit<z.infer<typeof runInputSchema>, "modelPolicyVersion"> & {
|
|
|
767
767
|
version: number;
|
|
768
768
|
updatedAt: string;
|
|
769
769
|
};
|
|
770
|
-
export
|
|
771
|
-
models:
|
|
770
|
+
export declare const catalogSchema: z.ZodObject<{
|
|
771
|
+
models: z.ZodArray<z.ZodObject<{
|
|
772
|
+
id: z.ZodEffects<z.ZodString, string, string>;
|
|
773
|
+
name: z.ZodString;
|
|
774
|
+
description: z.ZodOptional<z.ZodString>;
|
|
775
|
+
available: z.ZodOptional<z.ZodBoolean>;
|
|
776
|
+
expiresOn: z.ZodOptional<z.ZodEffects<z.ZodString, string, string>>;
|
|
777
|
+
contextWindow: z.ZodOptional<z.ZodNumber>;
|
|
778
|
+
maxOutputTokens: z.ZodOptional<z.ZodNumber>;
|
|
779
|
+
inputModalities: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
780
|
+
outputModalities: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
781
|
+
supportedParameters: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
782
|
+
reasoningEfforts: z.ZodOptional<z.ZodArray<z.ZodEnum<["none", "minimal", "low", "medium", "high", "xhigh", "max", "ultra"]>, "many">>;
|
|
783
|
+
supportedGenerationMethods: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
784
|
+
}, "strict", z.ZodTypeAny, {
|
|
785
|
+
id: string;
|
|
786
|
+
name: string;
|
|
787
|
+
description?: string | undefined;
|
|
788
|
+
available?: boolean | undefined;
|
|
789
|
+
expiresOn?: string | undefined;
|
|
790
|
+
contextWindow?: number | undefined;
|
|
791
|
+
maxOutputTokens?: number | undefined;
|
|
792
|
+
inputModalities?: string[] | undefined;
|
|
793
|
+
outputModalities?: string[] | undefined;
|
|
794
|
+
supportedParameters?: string[] | undefined;
|
|
795
|
+
reasoningEfforts?: ("none" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max" | "ultra")[] | undefined;
|
|
796
|
+
supportedGenerationMethods?: string[] | undefined;
|
|
797
|
+
}, {
|
|
798
|
+
id: string;
|
|
799
|
+
name: string;
|
|
800
|
+
description?: string | undefined;
|
|
801
|
+
available?: boolean | undefined;
|
|
802
|
+
expiresOn?: string | undefined;
|
|
803
|
+
contextWindow?: number | undefined;
|
|
804
|
+
maxOutputTokens?: number | undefined;
|
|
805
|
+
inputModalities?: string[] | undefined;
|
|
806
|
+
outputModalities?: string[] | undefined;
|
|
807
|
+
supportedParameters?: string[] | undefined;
|
|
808
|
+
reasoningEfforts?: ("none" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max" | "ultra")[] | undefined;
|
|
809
|
+
supportedGenerationMethods?: string[] | undefined;
|
|
810
|
+
}>, "many">;
|
|
811
|
+
refreshedAt: z.ZodString;
|
|
812
|
+
source: z.ZodEnum<["remote", "manual"]>;
|
|
813
|
+
}, "strict", z.ZodTypeAny, {
|
|
814
|
+
models: {
|
|
815
|
+
id: string;
|
|
816
|
+
name: string;
|
|
817
|
+
description?: string | undefined;
|
|
818
|
+
available?: boolean | undefined;
|
|
819
|
+
expiresOn?: string | undefined;
|
|
820
|
+
contextWindow?: number | undefined;
|
|
821
|
+
maxOutputTokens?: number | undefined;
|
|
822
|
+
inputModalities?: string[] | undefined;
|
|
823
|
+
outputModalities?: string[] | undefined;
|
|
824
|
+
supportedParameters?: string[] | undefined;
|
|
825
|
+
reasoningEfforts?: ("none" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max" | "ultra")[] | undefined;
|
|
826
|
+
supportedGenerationMethods?: string[] | undefined;
|
|
827
|
+
}[];
|
|
772
828
|
refreshedAt: string;
|
|
773
829
|
source: "remote" | "manual";
|
|
774
|
-
}
|
|
830
|
+
}, {
|
|
831
|
+
models: {
|
|
832
|
+
id: string;
|
|
833
|
+
name: string;
|
|
834
|
+
description?: string | undefined;
|
|
835
|
+
available?: boolean | undefined;
|
|
836
|
+
expiresOn?: string | undefined;
|
|
837
|
+
contextWindow?: number | undefined;
|
|
838
|
+
maxOutputTokens?: number | undefined;
|
|
839
|
+
inputModalities?: string[] | undefined;
|
|
840
|
+
outputModalities?: string[] | undefined;
|
|
841
|
+
supportedParameters?: string[] | undefined;
|
|
842
|
+
reasoningEfforts?: ("none" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max" | "ultra")[] | undefined;
|
|
843
|
+
supportedGenerationMethods?: string[] | undefined;
|
|
844
|
+
}[];
|
|
845
|
+
refreshedAt: string;
|
|
846
|
+
source: "remote" | "manual";
|
|
847
|
+
}>;
|
|
848
|
+
export type Catalog = z.infer<typeof catalogSchema>;
|
|
775
849
|
export type LaunchPlan = {
|
|
776
850
|
planToken: string;
|
|
777
851
|
profile: Profile;
|
package/dist/generated/api.d.ts
CHANGED
|
@@ -120,6 +120,7 @@ export interface paths {
|
|
|
120
120
|
};
|
|
121
121
|
get?: never;
|
|
122
122
|
put?: never;
|
|
123
|
+
/** @description Self-hosted/local server refresh. Hosted clients discover locally and commit catalog metadata through the version-checked catalog endpoint. */
|
|
123
124
|
post: operations["refreshModels"];
|
|
124
125
|
delete?: never;
|
|
125
126
|
options?: never;
|
|
@@ -127,6 +128,22 @@ export interface paths {
|
|
|
127
128
|
patch?: never;
|
|
128
129
|
trace?: never;
|
|
129
130
|
};
|
|
131
|
+
"/v1/providers/{id}/catalog": {
|
|
132
|
+
parameters: {
|
|
133
|
+
query?: never;
|
|
134
|
+
header?: never;
|
|
135
|
+
path?: never;
|
|
136
|
+
cookie?: never;
|
|
137
|
+
};
|
|
138
|
+
get?: never;
|
|
139
|
+
put: operations["saveCatalog"];
|
|
140
|
+
post?: never;
|
|
141
|
+
delete?: never;
|
|
142
|
+
options?: never;
|
|
143
|
+
head?: never;
|
|
144
|
+
patch?: never;
|
|
145
|
+
trace?: never;
|
|
146
|
+
};
|
|
130
147
|
"/v1/launch-plans": {
|
|
131
148
|
parameters: {
|
|
132
149
|
query?: never;
|
|
@@ -224,6 +241,22 @@ export interface paths {
|
|
|
224
241
|
trace?: never;
|
|
225
242
|
};
|
|
226
243
|
"/v1/openapi.json": {
|
|
244
|
+
parameters: {
|
|
245
|
+
query?: never;
|
|
246
|
+
header?: never;
|
|
247
|
+
path?: never;
|
|
248
|
+
cookie?: never;
|
|
249
|
+
};
|
|
250
|
+
get: operations["openApiV1"];
|
|
251
|
+
put?: never;
|
|
252
|
+
post?: never;
|
|
253
|
+
delete?: never;
|
|
254
|
+
options?: never;
|
|
255
|
+
head?: never;
|
|
256
|
+
patch?: never;
|
|
257
|
+
trace?: never;
|
|
258
|
+
};
|
|
259
|
+
"/openapi.json": {
|
|
227
260
|
parameters: {
|
|
228
261
|
query?: never;
|
|
229
262
|
header?: never;
|
|
@@ -553,6 +586,7 @@ export interface components {
|
|
|
553
586
|
reasoningEfforts?: ("none" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max" | "ultra")[];
|
|
554
587
|
supportedGenerationMethods?: string[];
|
|
555
588
|
}[];
|
|
589
|
+
/** Format: date-time */
|
|
556
590
|
refreshedAt: string;
|
|
557
591
|
/** @enum {string} */
|
|
558
592
|
source: "remote" | "manual";
|
|
@@ -668,6 +702,7 @@ export interface components {
|
|
|
668
702
|
reasoningEfforts?: ("none" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max" | "ultra")[];
|
|
669
703
|
supportedGenerationMethods?: string[];
|
|
670
704
|
}[];
|
|
705
|
+
/** Format: date-time */
|
|
671
706
|
refreshedAt: string;
|
|
672
707
|
/** @enum {string} */
|
|
673
708
|
source: "remote" | "manual";
|
|
@@ -799,7 +834,11 @@ export interface components {
|
|
|
799
834
|
backend: "sqlite" | "postgresql";
|
|
800
835
|
};
|
|
801
836
|
Ready: {
|
|
802
|
-
|
|
837
|
+
/** @enum {string} */
|
|
838
|
+
status: "ready" | "unavailable";
|
|
839
|
+
version: string;
|
|
840
|
+
/** @enum {string} */
|
|
841
|
+
backend: "sqlite" | "postgresql";
|
|
803
842
|
reason?: string;
|
|
804
843
|
};
|
|
805
844
|
Version: {
|
|
@@ -1315,6 +1354,44 @@ export interface operations {
|
|
|
1315
1354
|
};
|
|
1316
1355
|
};
|
|
1317
1356
|
};
|
|
1357
|
+
saveCatalog: {
|
|
1358
|
+
parameters: {
|
|
1359
|
+
query?: never;
|
|
1360
|
+
header: {
|
|
1361
|
+
"Idempotency-Key": string;
|
|
1362
|
+
"If-Match": number;
|
|
1363
|
+
};
|
|
1364
|
+
path: {
|
|
1365
|
+
id: string;
|
|
1366
|
+
};
|
|
1367
|
+
cookie?: never;
|
|
1368
|
+
};
|
|
1369
|
+
requestBody: {
|
|
1370
|
+
content: {
|
|
1371
|
+
"application/json": components["schemas"]["Catalog"];
|
|
1372
|
+
};
|
|
1373
|
+
};
|
|
1374
|
+
responses: {
|
|
1375
|
+
/** @description Success */
|
|
1376
|
+
200: {
|
|
1377
|
+
headers: {
|
|
1378
|
+
[name: string]: unknown;
|
|
1379
|
+
};
|
|
1380
|
+
content: {
|
|
1381
|
+
"application/json": components["schemas"]["Catalog"];
|
|
1382
|
+
};
|
|
1383
|
+
};
|
|
1384
|
+
/** @description Structured error */
|
|
1385
|
+
default: {
|
|
1386
|
+
headers: {
|
|
1387
|
+
[name: string]: unknown;
|
|
1388
|
+
};
|
|
1389
|
+
content: {
|
|
1390
|
+
"application/json": components["schemas"]["Error"];
|
|
1391
|
+
};
|
|
1392
|
+
};
|
|
1393
|
+
};
|
|
1394
|
+
};
|
|
1318
1395
|
launchPlan: {
|
|
1319
1396
|
parameters: {
|
|
1320
1397
|
query?: never;
|
|
@@ -1579,6 +1656,37 @@ export interface operations {
|
|
|
1579
1656
|
};
|
|
1580
1657
|
};
|
|
1581
1658
|
};
|
|
1659
|
+
openApiV1: {
|
|
1660
|
+
parameters: {
|
|
1661
|
+
query?: never;
|
|
1662
|
+
header?: never;
|
|
1663
|
+
path?: never;
|
|
1664
|
+
cookie?: never;
|
|
1665
|
+
};
|
|
1666
|
+
requestBody?: never;
|
|
1667
|
+
responses: {
|
|
1668
|
+
/** @description Success */
|
|
1669
|
+
200: {
|
|
1670
|
+
headers: {
|
|
1671
|
+
[name: string]: unknown;
|
|
1672
|
+
};
|
|
1673
|
+
content: {
|
|
1674
|
+
"application/json": {
|
|
1675
|
+
[key: string]: unknown;
|
|
1676
|
+
};
|
|
1677
|
+
};
|
|
1678
|
+
};
|
|
1679
|
+
/** @description Structured error */
|
|
1680
|
+
default: {
|
|
1681
|
+
headers: {
|
|
1682
|
+
[name: string]: unknown;
|
|
1683
|
+
};
|
|
1684
|
+
content: {
|
|
1685
|
+
"application/json": components["schemas"]["Error"];
|
|
1686
|
+
};
|
|
1687
|
+
};
|
|
1688
|
+
};
|
|
1689
|
+
};
|
|
1582
1690
|
openApi: {
|
|
1583
1691
|
parameters: {
|
|
1584
1692
|
query?: never;
|
package/dist/index.js
CHANGED
|
@@ -153,6 +153,7 @@ var runUpdateSchema = z3.object({
|
|
|
153
153
|
routingEvents: routingEventsSchema.optional(),
|
|
154
154
|
routingEventsDropped: z3.number().int().min(0).max(1e6).optional()
|
|
155
155
|
}).strict();
|
|
156
|
+
var catalogSchema = z3.object({ models: z3.array(modelSchema).max(1e4), refreshedAt: z3.string().datetime(), source: z3.enum(["remote", "manual"]) }).strict();
|
|
156
157
|
|
|
157
158
|
class Fault extends Error {
|
|
158
159
|
status;
|
|
@@ -624,6 +625,9 @@ class SwitcherClient {
|
|
|
624
625
|
refreshModels(id, idempotencyKey) {
|
|
625
626
|
return this.request("POST", `/v1/providers/${encodeURIComponent(id)}/refresh`, {}, { idempotencyKey });
|
|
626
627
|
}
|
|
628
|
+
saveCatalog(id, providerVersion, catalog, idempotencyKey) {
|
|
629
|
+
return this.request("PUT", `/v1/providers/${encodeURIComponent(id)}/catalog`, catalog, { version: providerVersion, idempotencyKey });
|
|
630
|
+
}
|
|
627
631
|
listModels(id, options = {}) {
|
|
628
632
|
return this.request("GET", `/v1/providers/${encodeURIComponent(id)}/models?${this.query(options)}`);
|
|
629
633
|
}
|