@hasna/switcher 0.1.0 → 0.1.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.
@@ -0,0 +1,178 @@
1
+ import { z } from "zod";
2
+ import { CommandInterrupted, type ProviderInput } from "./domain";
3
+ declare const keychain: z.ZodObject<{
4
+ kind: z.ZodLiteral<"keychain">;
5
+ service: z.ZodString;
6
+ account: z.ZodString;
7
+ }, "strict", z.ZodTypeAny, {
8
+ kind: "keychain";
9
+ service: string;
10
+ account: string;
11
+ }, {
12
+ kind: "keychain";
13
+ service: string;
14
+ account: string;
15
+ }>;
16
+ export declare const credentialBindingSchema: z.ZodObject<{
17
+ schema: z.ZodLiteral<1>;
18
+ credentialEnv: z.ZodString;
19
+ origins: z.ZodArray<z.ZodEffects<z.ZodString, string, string>, "many">;
20
+ source: z.ZodDiscriminatedUnion<"kind", [z.ZodObject<{
21
+ kind: z.ZodLiteral<"keychain">;
22
+ service: z.ZodString;
23
+ account: z.ZodString;
24
+ }, "strict", z.ZodTypeAny, {
25
+ kind: "keychain";
26
+ service: string;
27
+ account: string;
28
+ }, {
29
+ kind: "keychain";
30
+ service: string;
31
+ account: string;
32
+ }>, z.ZodObject<{
33
+ kind: z.ZodLiteral<"vault">;
34
+ key: z.ZodString;
35
+ url: z.ZodEffects<z.ZodString, string, string>;
36
+ executable: z.ZodEffects<z.ZodString, string, string>;
37
+ operator: z.ZodDiscriminatedUnion<"kind", [z.ZodObject<{
38
+ kind: z.ZodLiteral<"env">;
39
+ }, "strict", z.ZodTypeAny, {
40
+ kind: "env";
41
+ }, {
42
+ kind: "env";
43
+ }>, z.ZodObject<{
44
+ kind: z.ZodLiteral<"keychain">;
45
+ account: z.ZodString;
46
+ }, "strict", z.ZodTypeAny, {
47
+ kind: "keychain";
48
+ account: string;
49
+ }, {
50
+ kind: "keychain";
51
+ account: string;
52
+ }>]>;
53
+ }, "strict", z.ZodTypeAny, {
54
+ url: string;
55
+ executable: string;
56
+ key: string;
57
+ kind: "vault";
58
+ operator: {
59
+ kind: "env";
60
+ } | {
61
+ kind: "keychain";
62
+ account: string;
63
+ };
64
+ }, {
65
+ url: string;
66
+ executable: string;
67
+ key: string;
68
+ kind: "vault";
69
+ operator: {
70
+ kind: "env";
71
+ } | {
72
+ kind: "keychain";
73
+ account: string;
74
+ };
75
+ }>]>;
76
+ }, "strict", z.ZodTypeAny, {
77
+ credentialEnv: string;
78
+ source: {
79
+ kind: "keychain";
80
+ service: string;
81
+ account: string;
82
+ } | {
83
+ url: string;
84
+ executable: string;
85
+ key: string;
86
+ kind: "vault";
87
+ operator: {
88
+ kind: "env";
89
+ } | {
90
+ kind: "keychain";
91
+ account: string;
92
+ };
93
+ };
94
+ schema: 1;
95
+ origins: string[];
96
+ }, {
97
+ credentialEnv: string;
98
+ source: {
99
+ kind: "keychain";
100
+ service: string;
101
+ account: string;
102
+ } | {
103
+ url: string;
104
+ executable: string;
105
+ key: string;
106
+ kind: "vault";
107
+ operator: {
108
+ kind: "env";
109
+ } | {
110
+ kind: "keychain";
111
+ account: string;
112
+ };
113
+ };
114
+ schema: 1;
115
+ origins: string[];
116
+ }>;
117
+ export type CredentialBinding = z.infer<typeof credentialBindingSchema>;
118
+ export declare class CredentialBindings {
119
+ readonly env: NodeJS.ProcessEnv;
120
+ readonly directory: string;
121
+ constructor(env?: NodeJS.ProcessEnv);
122
+ private path;
123
+ private readableDirectory;
124
+ get(name: string): Promise<CredentialBinding | undefined>;
125
+ list(): Promise<CredentialBinding[]>;
126
+ bind(input: CredentialBinding): Promise<{
127
+ credentialEnv: string;
128
+ source: {
129
+ kind: "keychain";
130
+ service: string;
131
+ account: string;
132
+ } | {
133
+ url: string;
134
+ executable: string;
135
+ key: string;
136
+ kind: "vault";
137
+ operator: {
138
+ kind: "env";
139
+ } | {
140
+ kind: "keychain";
141
+ account: string;
142
+ };
143
+ };
144
+ schema: 1;
145
+ origins: string[];
146
+ }>;
147
+ remove(name: string): Promise<{
148
+ removed: string;
149
+ }>;
150
+ }
151
+ export declare function credentialReference(selector: string): string;
152
+ export declare function validateVaultExecutable(path: string): Promise<string>;
153
+ export declare function bindingTarget(selector: string, override?: string, allowedOrigins?: string[]): {
154
+ credentialEnv: string;
155
+ origins: string[];
156
+ };
157
+ declare function readKeychain(source: z.infer<typeof keychain>): Promise<string>;
158
+ export declare class CredentialResolver {
159
+ readonly env: NodeJS.ProcessEnv;
160
+ private readonly keychainRead;
161
+ readonly bindings: CredentialBindings;
162
+ constructor(env?: NodeJS.ProcessEnv, keychainRead?: typeof readKeychain);
163
+ resolve(provider: ProviderInput): Promise<string | undefined>;
164
+ check(name: string): Promise<{
165
+ credentialEnv: string;
166
+ source: string;
167
+ available: boolean;
168
+ length: number;
169
+ sha256: string;
170
+ providerAuthentication: string;
171
+ }>;
172
+ }
173
+ export declare class CredentialInterrupted extends CommandInterrupted {
174
+ constructor(exitCode: number);
175
+ }
176
+ /** Internal child mode: the key travels only through an authenticated loopback request. */
177
+ export declare function deliverVaultCredential(): Promise<void>;
178
+ export {};
@@ -0,0 +1,6 @@
1
+ import { SwitcherClient, type Provider, type Profile } from "./sdk";
2
+ import { type Model } from "./domain";
3
+ import { type PresetOptions } from "./presets";
4
+ export declare function resolveLaunchProvider(client: SwitcherClient, selector: string, options?: PresetOptions): Promise<Provider>;
5
+ export declare function selectModel(models: Model[], query?: string): Promise<string>;
6
+ export declare function ensureLaunchProfile(client: SwitcherClient, provider: Provider, harness: Profile["harness"], model: string): Promise<Profile>;
package/dist/domain.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { z } from "zod";
2
- export declare const VERSION = "0.1.0";
3
- export declare const harnessSchema: z.ZodEnum<["claude", "codex", "grok", "opencode2"]>;
2
+ export declare const VERSION = "0.1.1";
3
+ export declare const harnessSchema: z.ZodEnum<["claude", "codex", "grok", "opencode2", "pi"]>;
4
4
  export declare const protocolSchema: z.ZodEnum<["anthropic-messages", "openai-responses", "openai-chat"]>;
5
5
  export declare const idSchema: z.ZodString;
6
6
  export declare function endpoint(value: string): string;
@@ -8,6 +8,7 @@ export declare const modelSchema: z.ZodObject<{
8
8
  id: z.ZodString;
9
9
  name: z.ZodString;
10
10
  description: z.ZodOptional<z.ZodString>;
11
+ available: z.ZodOptional<z.ZodBoolean>;
11
12
  contextWindow: z.ZodOptional<z.ZodNumber>;
12
13
  maxOutputTokens: z.ZodOptional<z.ZodNumber>;
13
14
  inputModalities: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
@@ -17,6 +18,7 @@ export declare const modelSchema: z.ZodObject<{
17
18
  id: string;
18
19
  name: string;
19
20
  description?: string | undefined;
21
+ available?: boolean | undefined;
20
22
  contextWindow?: number | undefined;
21
23
  maxOutputTokens?: number | undefined;
22
24
  inputModalities?: string[] | undefined;
@@ -26,6 +28,7 @@ export declare const modelSchema: z.ZodObject<{
26
28
  id: string;
27
29
  name: string;
28
30
  description?: string | undefined;
31
+ available?: boolean | undefined;
29
32
  contextWindow?: number | undefined;
30
33
  maxOutputTokens?: number | undefined;
31
34
  inputModalities?: string[] | undefined;
@@ -39,11 +42,17 @@ export declare const providerInputSchema: z.ZodEffects<z.ZodObject<{
39
42
  protocol: z.ZodEnum<["anthropic-messages", "openai-responses", "openai-chat"]>;
40
43
  credentialEnv: z.ZodOptional<z.ZodString>;
41
44
  authStyle: z.ZodDefault<z.ZodEnum<["bearer", "x-api-key"]>>;
45
+ catalogBaseUrl: z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>>;
46
+ catalogFormat: z.ZodOptional<z.ZodEnum<["openai", "ollama", "mistral", "together", "fireworks", "dashscope", "none"]>>;
47
+ catalogAuthStyle: z.ZodOptional<z.ZodEnum<["bearer", "x-api-key", "none"]>>;
48
+ catalogCredentialEnv: z.ZodOptional<z.ZodString>;
49
+ catalogAccountId: z.ZodOptional<z.ZodString>;
42
50
  modelsPath: z.ZodDefault<z.ZodString>;
43
51
  manualModels: z.ZodDefault<z.ZodArray<z.ZodObject<{
44
52
  id: z.ZodString;
45
53
  name: z.ZodString;
46
54
  description: z.ZodOptional<z.ZodString>;
55
+ available: z.ZodOptional<z.ZodBoolean>;
47
56
  contextWindow: z.ZodOptional<z.ZodNumber>;
48
57
  maxOutputTokens: z.ZodOptional<z.ZodNumber>;
49
58
  inputModalities: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
@@ -53,6 +62,7 @@ export declare const providerInputSchema: z.ZodEffects<z.ZodObject<{
53
62
  id: string;
54
63
  name: string;
55
64
  description?: string | undefined;
65
+ available?: boolean | undefined;
56
66
  contextWindow?: number | undefined;
57
67
  maxOutputTokens?: number | undefined;
58
68
  inputModalities?: string[] | undefined;
@@ -62,6 +72,7 @@ export declare const providerInputSchema: z.ZodEffects<z.ZodObject<{
62
72
  id: string;
63
73
  name: string;
64
74
  description?: string | undefined;
75
+ available?: boolean | undefined;
65
76
  contextWindow?: number | undefined;
66
77
  maxOutputTokens?: number | undefined;
67
78
  inputModalities?: string[] | undefined;
@@ -79,6 +90,7 @@ export declare const providerInputSchema: z.ZodEffects<z.ZodObject<{
79
90
  id: string;
80
91
  name: string;
81
92
  description?: string | undefined;
93
+ available?: boolean | undefined;
82
94
  contextWindow?: number | undefined;
83
95
  maxOutputTokens?: number | undefined;
84
96
  inputModalities?: string[] | undefined;
@@ -86,6 +98,11 @@ export declare const providerInputSchema: z.ZodEffects<z.ZodObject<{
86
98
  supportedParameters?: string[] | undefined;
87
99
  }[];
88
100
  credentialEnv?: string | undefined;
101
+ catalogBaseUrl?: string | undefined;
102
+ catalogFormat?: "openai" | "ollama" | "mistral" | "together" | "fireworks" | "dashscope" | "none" | undefined;
103
+ catalogAuthStyle?: "bearer" | "x-api-key" | "none" | undefined;
104
+ catalogCredentialEnv?: string | undefined;
105
+ catalogAccountId?: string | undefined;
89
106
  }, {
90
107
  id: string;
91
108
  name: string;
@@ -93,11 +110,17 @@ export declare const providerInputSchema: z.ZodEffects<z.ZodObject<{
93
110
  protocol: "anthropic-messages" | "openai-responses" | "openai-chat";
94
111
  credentialEnv?: string | undefined;
95
112
  authStyle?: "bearer" | "x-api-key" | undefined;
113
+ catalogBaseUrl?: string | undefined;
114
+ catalogFormat?: "openai" | "ollama" | "mistral" | "together" | "fireworks" | "dashscope" | "none" | undefined;
115
+ catalogAuthStyle?: "bearer" | "x-api-key" | "none" | undefined;
116
+ catalogCredentialEnv?: string | undefined;
117
+ catalogAccountId?: string | undefined;
96
118
  modelsPath?: string | undefined;
97
119
  manualModels?: {
98
120
  id: string;
99
121
  name: string;
100
122
  description?: string | undefined;
123
+ available?: boolean | undefined;
101
124
  contextWindow?: number | undefined;
102
125
  maxOutputTokens?: number | undefined;
103
126
  inputModalities?: string[] | undefined;
@@ -115,6 +138,7 @@ export declare const providerInputSchema: z.ZodEffects<z.ZodObject<{
115
138
  id: string;
116
139
  name: string;
117
140
  description?: string | undefined;
141
+ available?: boolean | undefined;
118
142
  contextWindow?: number | undefined;
119
143
  maxOutputTokens?: number | undefined;
120
144
  inputModalities?: string[] | undefined;
@@ -122,6 +146,11 @@ export declare const providerInputSchema: z.ZodEffects<z.ZodObject<{
122
146
  supportedParameters?: string[] | undefined;
123
147
  }[];
124
148
  credentialEnv?: string | undefined;
149
+ catalogBaseUrl?: string | undefined;
150
+ catalogFormat?: "openai" | "ollama" | "mistral" | "together" | "fireworks" | "dashscope" | "none" | undefined;
151
+ catalogAuthStyle?: "bearer" | "x-api-key" | "none" | undefined;
152
+ catalogCredentialEnv?: string | undefined;
153
+ catalogAccountId?: string | undefined;
125
154
  }, {
126
155
  id: string;
127
156
  name: string;
@@ -129,11 +158,17 @@ export declare const providerInputSchema: z.ZodEffects<z.ZodObject<{
129
158
  protocol: "anthropic-messages" | "openai-responses" | "openai-chat";
130
159
  credentialEnv?: string | undefined;
131
160
  authStyle?: "bearer" | "x-api-key" | undefined;
161
+ catalogBaseUrl?: string | undefined;
162
+ catalogFormat?: "openai" | "ollama" | "mistral" | "together" | "fireworks" | "dashscope" | "none" | undefined;
163
+ catalogAuthStyle?: "bearer" | "x-api-key" | "none" | undefined;
164
+ catalogCredentialEnv?: string | undefined;
165
+ catalogAccountId?: string | undefined;
132
166
  modelsPath?: string | undefined;
133
167
  manualModels?: {
134
168
  id: string;
135
169
  name: string;
136
170
  description?: string | undefined;
171
+ available?: boolean | undefined;
137
172
  contextWindow?: number | undefined;
138
173
  maxOutputTokens?: number | undefined;
139
174
  inputModalities?: string[] | undefined;
@@ -141,37 +176,108 @@ export declare const providerInputSchema: z.ZodEffects<z.ZodObject<{
141
176
  supportedParameters?: string[] | undefined;
142
177
  }[] | undefined;
143
178
  }>;
179
+ export declare const providerPresetSchema: z.ZodObject<{
180
+ id: z.ZodString;
181
+ name: z.ZodString;
182
+ credentialEnv: z.ZodOptional<z.ZodString>;
183
+ credentialAliases: z.ZodArray<z.ZodString, "many">;
184
+ protocols: z.ZodArray<z.ZodObject<{
185
+ protocol: z.ZodEnum<["anthropic-messages", "openai-responses", "openai-chat"]>;
186
+ baseUrl: z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>>;
187
+ authStyle: z.ZodEnum<["bearer", "x-api-key"]>;
188
+ catalogBaseUrl: z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>>;
189
+ catalogFormat: z.ZodEnum<["openai", "ollama", "mistral", "together", "fireworks", "dashscope", "none"]>;
190
+ catalogAuthStyle: z.ZodOptional<z.ZodEnum<["bearer", "x-api-key", "none"]>>;
191
+ modelsPath: z.ZodString;
192
+ notes: z.ZodArray<z.ZodString, "many">;
193
+ }, "strict", z.ZodTypeAny, {
194
+ protocol: "anthropic-messages" | "openai-responses" | "openai-chat";
195
+ authStyle: "bearer" | "x-api-key";
196
+ catalogFormat: "openai" | "ollama" | "mistral" | "together" | "fireworks" | "dashscope" | "none";
197
+ modelsPath: string;
198
+ notes: string[];
199
+ baseUrl?: string | undefined;
200
+ catalogBaseUrl?: string | undefined;
201
+ catalogAuthStyle?: "bearer" | "x-api-key" | "none" | undefined;
202
+ }, {
203
+ protocol: "anthropic-messages" | "openai-responses" | "openai-chat";
204
+ authStyle: "bearer" | "x-api-key";
205
+ catalogFormat: "openai" | "ollama" | "mistral" | "together" | "fireworks" | "dashscope" | "none";
206
+ modelsPath: string;
207
+ notes: string[];
208
+ baseUrl?: string | undefined;
209
+ catalogBaseUrl?: string | undefined;
210
+ catalogAuthStyle?: "bearer" | "x-api-key" | "none" | undefined;
211
+ }>, "many">;
212
+ sources: z.ZodArray<z.ZodString, "many">;
213
+ verification: z.ZodLiteral<"documented">;
214
+ }, "strict", z.ZodTypeAny, {
215
+ id: string;
216
+ name: string;
217
+ credentialAliases: string[];
218
+ protocols: {
219
+ protocol: "anthropic-messages" | "openai-responses" | "openai-chat";
220
+ authStyle: "bearer" | "x-api-key";
221
+ catalogFormat: "openai" | "ollama" | "mistral" | "together" | "fireworks" | "dashscope" | "none";
222
+ modelsPath: string;
223
+ notes: string[];
224
+ baseUrl?: string | undefined;
225
+ catalogBaseUrl?: string | undefined;
226
+ catalogAuthStyle?: "bearer" | "x-api-key" | "none" | undefined;
227
+ }[];
228
+ sources: string[];
229
+ verification: "documented";
230
+ credentialEnv?: string | undefined;
231
+ }, {
232
+ id: string;
233
+ name: string;
234
+ credentialAliases: string[];
235
+ protocols: {
236
+ protocol: "anthropic-messages" | "openai-responses" | "openai-chat";
237
+ authStyle: "bearer" | "x-api-key";
238
+ catalogFormat: "openai" | "ollama" | "mistral" | "together" | "fireworks" | "dashscope" | "none";
239
+ modelsPath: string;
240
+ notes: string[];
241
+ baseUrl?: string | undefined;
242
+ catalogBaseUrl?: string | undefined;
243
+ catalogAuthStyle?: "bearer" | "x-api-key" | "none" | undefined;
244
+ }[];
245
+ sources: string[];
246
+ verification: "documented";
247
+ credentialEnv?: string | undefined;
248
+ }>;
249
+ export type ProviderPreset = z.infer<typeof providerPresetSchema>;
144
250
  export declare const profileInputSchema: z.ZodObject<{
145
251
  id: z.ZodString;
146
252
  name: z.ZodString;
147
253
  providerId: z.ZodString;
148
- harness: z.ZodEnum<["claude", "codex", "grok", "opencode2"]>;
254
+ harness: z.ZodEnum<["claude", "codex", "grok", "opencode2", "pi"]>;
149
255
  model: z.ZodString;
150
256
  }, "strict", z.ZodTypeAny, {
151
257
  id: string;
152
258
  name: string;
153
259
  providerId: string;
154
- harness: "claude" | "codex" | "grok" | "opencode2";
260
+ harness: "claude" | "codex" | "grok" | "opencode2" | "pi";
155
261
  model: string;
156
262
  }, {
157
263
  id: string;
158
264
  name: string;
159
265
  providerId: string;
160
- harness: "claude" | "codex" | "grok" | "opencode2";
266
+ harness: "claude" | "codex" | "grok" | "opencode2" | "pi";
161
267
  model: string;
162
268
  }>;
163
269
  export declare const runInputSchema: z.ZodObject<{
164
270
  profileId: z.ZodString;
165
- harness: z.ZodEnum<["claude", "codex", "grok", "opencode2"]>;
271
+ harness: z.ZodEnum<["claude", "codex", "grok", "opencode2", "pi"]>;
166
272
  model: z.ZodString;
167
273
  planToken: z.ZodString;
168
274
  }, "strict", z.ZodTypeAny, {
169
- harness: "claude" | "codex" | "grok" | "opencode2";
275
+ harness: "claude" | "codex" | "grok" | "opencode2" | "pi";
170
276
  model: string;
171
277
  profileId: string;
172
278
  planToken: string;
173
279
  }, {
174
- harness: "claude" | "codex" | "grok" | "opencode2";
280
+ harness: "claude" | "codex" | "grok" | "opencode2" | "pi";
175
281
  model: string;
176
282
  profileId: string;
177
283
  planToken: string;
@@ -226,6 +332,10 @@ export declare class Fault extends Error {
226
332
  code: string;
227
333
  constructor(status: number, code: string, message: string);
228
334
  }
335
+ export declare class CommandInterrupted extends Fault {
336
+ readonly exitCode: number;
337
+ constructor(exitCode: number, message: string);
338
+ }
229
339
  export declare function parse<T>(schema: z.ZodType<T, any, any>, value: unknown): T;
230
340
  export declare function compatible(harness: Profile["harness"], protocol: Provider["protocol"]): boolean;
231
341
  export declare function codingEligible(model: Model): boolean;