@hasna/switcher 0.1.8 → 0.2.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/README.md +161 -3
- package/dist/chatgpt-launch.d.ts +5 -0
- package/dist/claude-desktop-launch.d.ts +11 -0
- package/dist/cli/index.js +1232 -403
- package/dist/codex-delegation.d.ts +7 -0
- package/dist/credentials.d.ts +7 -7
- package/dist/desktop-apps.d.ts +25 -0
- package/dist/desktop-state.d.ts +3 -0
- package/dist/domain.d.ts +23 -1
- package/dist/gemini-bridge.d.ts +2 -1
- package/dist/generated/api.d.ts +16 -0
- package/dist/harness-process.d.ts +1 -0
- package/dist/harness-types.d.ts +3 -0
- package/dist/harnesses.d.ts +13 -3
- package/dist/hermes-backend.d.ts +2 -1
- package/dist/index.js +164 -64
- package/dist/inference-gateway.d.ts +4 -1
- package/dist/launcher.d.ts +6 -0
- package/dist/lib/local-opt-in.d.ts +30 -0
- package/dist/mcp/index.js +4960 -89
- package/dist/model-policy-schema.d.ts +6 -0
- package/dist/presets.d.ts +2 -0
- package/dist/provider-request.d.ts +15 -0
- package/dist/provider-stream.d.ts +3 -1
- package/dist/reasoning.d.ts +10 -0
- package/dist/runtime.d.ts +2 -0
- package/dist/sdk.d.ts +25 -0
- package/dist/sdk.js +164 -64
- package/dist/serve/index.js +288 -73
- package/openapi.json +210 -1
- package/package.json +5 -3
|
@@ -76,6 +76,7 @@ export declare const routingEventSchema: z.ZodObject<{
|
|
|
76
76
|
requestedModel: z.ZodString;
|
|
77
77
|
resolvedModel: z.ZodOptional<z.ZodString>;
|
|
78
78
|
reportedModel: z.ZodOptional<z.ZodString>;
|
|
79
|
+
reasoningEffort: z.ZodOptional<z.ZodEnum<["none", "minimal", "low", "medium", "high", "xhigh", "max", "ultra"]>>;
|
|
79
80
|
decision: z.ZodEnum<["allow", "alias", "reject", "fallback"]>;
|
|
80
81
|
role: z.ZodOptional<z.ZodEnum<["main", "subagent", "fast", "planning", "review", "summary", "compaction", "weak", "editor"]>>;
|
|
81
82
|
reason: z.ZodOptional<z.ZodString>;
|
|
@@ -87,6 +88,7 @@ export declare const routingEventSchema: z.ZodObject<{
|
|
|
87
88
|
decision: "allow" | "alias" | "reject" | "fallback";
|
|
88
89
|
resolvedModel?: string | undefined;
|
|
89
90
|
reportedModel?: string | undefined;
|
|
91
|
+
reasoningEffort?: "none" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max" | "ultra" | undefined;
|
|
90
92
|
role?: "main" | "subagent" | "fast" | "planning" | "review" | "summary" | "compaction" | "weak" | "editor" | undefined;
|
|
91
93
|
reason?: string | undefined;
|
|
92
94
|
upstreamStatus?: number | undefined;
|
|
@@ -97,6 +99,7 @@ export declare const routingEventSchema: z.ZodObject<{
|
|
|
97
99
|
decision: "allow" | "alias" | "reject" | "fallback";
|
|
98
100
|
resolvedModel?: string | undefined;
|
|
99
101
|
reportedModel?: string | undefined;
|
|
102
|
+
reasoningEffort?: "none" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max" | "ultra" | undefined;
|
|
100
103
|
role?: "main" | "subagent" | "fast" | "planning" | "review" | "summary" | "compaction" | "weak" | "editor" | undefined;
|
|
101
104
|
reason?: string | undefined;
|
|
102
105
|
upstreamStatus?: number | undefined;
|
|
@@ -108,6 +111,7 @@ export declare const routingEventsSchema: z.ZodArray<z.ZodObject<{
|
|
|
108
111
|
requestedModel: z.ZodString;
|
|
109
112
|
resolvedModel: z.ZodOptional<z.ZodString>;
|
|
110
113
|
reportedModel: z.ZodOptional<z.ZodString>;
|
|
114
|
+
reasoningEffort: z.ZodOptional<z.ZodEnum<["none", "minimal", "low", "medium", "high", "xhigh", "max", "ultra"]>>;
|
|
111
115
|
decision: z.ZodEnum<["allow", "alias", "reject", "fallback"]>;
|
|
112
116
|
role: z.ZodOptional<z.ZodEnum<["main", "subagent", "fast", "planning", "review", "summary", "compaction", "weak", "editor"]>>;
|
|
113
117
|
reason: z.ZodOptional<z.ZodString>;
|
|
@@ -119,6 +123,7 @@ export declare const routingEventsSchema: z.ZodArray<z.ZodObject<{
|
|
|
119
123
|
decision: "allow" | "alias" | "reject" | "fallback";
|
|
120
124
|
resolvedModel?: string | undefined;
|
|
121
125
|
reportedModel?: string | undefined;
|
|
126
|
+
reasoningEffort?: "none" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max" | "ultra" | undefined;
|
|
122
127
|
role?: "main" | "subagent" | "fast" | "planning" | "review" | "summary" | "compaction" | "weak" | "editor" | undefined;
|
|
123
128
|
reason?: string | undefined;
|
|
124
129
|
upstreamStatus?: number | undefined;
|
|
@@ -129,6 +134,7 @@ export declare const routingEventsSchema: z.ZodArray<z.ZodObject<{
|
|
|
129
134
|
decision: "allow" | "alias" | "reject" | "fallback";
|
|
130
135
|
resolvedModel?: string | undefined;
|
|
131
136
|
reportedModel?: string | undefined;
|
|
137
|
+
reasoningEffort?: "none" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max" | "ultra" | undefined;
|
|
132
138
|
role?: "main" | "subagent" | "fast" | "planning" | "review" | "summary" | "compaction" | "weak" | "editor" | undefined;
|
|
133
139
|
reason?: string | undefined;
|
|
134
140
|
upstreamStatus?: number | undefined;
|
package/dist/presets.d.ts
CHANGED
|
@@ -51,6 +51,7 @@ export declare function providerFromPreset(presetId: string, options?: PresetOpt
|
|
|
51
51
|
inputModalities?: string[] | undefined;
|
|
52
52
|
outputModalities?: string[] | undefined;
|
|
53
53
|
supportedParameters?: string[] | undefined;
|
|
54
|
+
reasoningEfforts?: ("none" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max" | "ultra")[] | undefined;
|
|
54
55
|
supportedGenerationMethods?: string[] | undefined;
|
|
55
56
|
}[];
|
|
56
57
|
credentialEnv?: string | undefined;
|
|
@@ -70,6 +71,7 @@ export declare function providerFromPreset(presetId: string, options?: PresetOpt
|
|
|
70
71
|
inputModalities?: string[] | undefined;
|
|
71
72
|
outputModalities?: string[] | undefined;
|
|
72
73
|
supportedParameters?: string[] | undefined;
|
|
74
|
+
reasoningEfforts?: ("none" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max" | "ultra")[] | undefined;
|
|
73
75
|
supportedGenerationMethods?: string[] | undefined;
|
|
74
76
|
}[] | undefined;
|
|
75
77
|
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** Internal timing injection keeps streaming regressions fast without CLI knobs. */
|
|
2
|
+
export type ProviderRequestTiming = {
|
|
3
|
+
idleTimeoutMs?: number;
|
|
4
|
+
};
|
|
5
|
+
/** Bound upstream inactivity, without charging downstream backpressure as idle. */
|
|
6
|
+
export declare function createProviderRequest(requestSignal: AbortSignal, abortSignal: AbortSignal, timing?: ProviderRequestTiming): {
|
|
7
|
+
fetchOptions: {
|
|
8
|
+
signal: AbortSignal;
|
|
9
|
+
timeout: false;
|
|
10
|
+
};
|
|
11
|
+
run: <T>(operation: () => Promise<T>) => Promise<T>;
|
|
12
|
+
finish: () => void;
|
|
13
|
+
timedOut: () => boolean;
|
|
14
|
+
};
|
|
15
|
+
export type ProviderRequest = ReturnType<typeof createProviderRequest>;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { HarnessLaunchInput } from "./harness-types";
|
|
2
|
+
import type { ProviderRequest } from "./provider-request";
|
|
2
3
|
/** Recognize whole SSE terminal events, never marker text inside a delta. */
|
|
3
4
|
export declare function terminalEventObserver(protocol: HarnessLaunchInput["protocol"], contentType: string | null): (chunk: Uint8Array) => boolean;
|
|
4
5
|
/** One lifecycle for all bridges: terminal SSE, caller cancellation, and real failure. */
|
|
@@ -9,8 +10,9 @@ export declare function proxyProviderStream(input: {
|
|
|
9
10
|
abort: AbortController;
|
|
10
11
|
closing: () => boolean;
|
|
11
12
|
release: () => void;
|
|
13
|
+
activity?: ProviderRequest;
|
|
12
14
|
inspect?: (chunk: Uint8Array, done?: boolean) => void;
|
|
13
|
-
interrupted?: () => void;
|
|
15
|
+
interrupted?: (reason: "stream_interrupted" | "provider_idle_timeout") => void;
|
|
14
16
|
}): {
|
|
15
17
|
stream: ReadableStream<Uint8Array>;
|
|
16
18
|
cancel: () => Promise<void>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { Model } from "./domain";
|
|
3
|
+
export declare const reasoningEffortSchema: z.ZodEnum<["none", "minimal", "low", "medium", "high", "xhigh", "max", "ultra"]>;
|
|
4
|
+
export type ReasoningEffort = z.infer<typeof reasoningEffortSchema>;
|
|
5
|
+
/** Advertise declared capabilities, documented DeepSeek levels, or an explicit
|
|
6
|
+
* operator selection. Do not invent a complete effort menu for arbitrary models. */
|
|
7
|
+
export declare function codexReasoning(model: Model, baseUrl: string, selected?: ReasoningEffort): {
|
|
8
|
+
levels: ("none" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max" | "ultra")[];
|
|
9
|
+
defaultEffort: "none" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max" | "ultra";
|
|
10
|
+
};
|
package/dist/runtime.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { SwitcherClient } from "./sdk";
|
|
2
2
|
import type { CatalogCredentialResolver } from "./catalog";
|
|
3
|
+
/** The refusal code when no Switcher API credential is configured and the local opt-in is not set. */
|
|
4
|
+
export declare const REMOTE_API_CONFIG_MISSING = "remote_api_config_missing";
|
|
3
5
|
export declare function switcherHome(env?: NodeJS.ProcessEnv): string;
|
|
4
6
|
export declare function privateDirectory(path: string): Promise<void>;
|
|
5
7
|
/** Data access always uses HTTP, including the per-command owned local service. */
|
package/dist/sdk.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { components } from "./generated/api";
|
|
2
2
|
import { type CredentialChainOptions } from "@hasna/contracts/client";
|
|
3
3
|
export { providerFromPreset } from "./presets";
|
|
4
|
+
export { detectChatGPTApp, detectClaudeDesktopApp } from "./desktop-apps";
|
|
5
|
+
export type { ChatGPTInstallation, ClaudeDesktopInstallation } from "./desktop-apps";
|
|
4
6
|
export type ProviderPreset = components["schemas"]["ProviderPreset"];
|
|
5
7
|
export type ProviderInput = components["schemas"]["ProviderInput"];
|
|
6
8
|
export type Provider = components["schemas"]["Provider"];
|
|
@@ -104,6 +106,7 @@ export declare class SwitcherClient {
|
|
|
104
106
|
inputModalities?: string[];
|
|
105
107
|
outputModalities?: string[];
|
|
106
108
|
supportedParameters?: string[];
|
|
109
|
+
reasoningEfforts?: ("none" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max" | "ultra")[];
|
|
107
110
|
supportedGenerationMethods?: string[];
|
|
108
111
|
}[];
|
|
109
112
|
additionalModels?: {
|
|
@@ -117,6 +120,7 @@ export declare class SwitcherClient {
|
|
|
117
120
|
inputModalities?: string[];
|
|
118
121
|
outputModalities?: string[];
|
|
119
122
|
supportedParameters?: string[];
|
|
123
|
+
reasoningEfforts?: ("none" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max" | "ultra")[];
|
|
120
124
|
supportedGenerationMethods?: string[];
|
|
121
125
|
}[];
|
|
122
126
|
version: number;
|
|
@@ -146,6 +150,7 @@ export declare class SwitcherClient {
|
|
|
146
150
|
inputModalities?: string[];
|
|
147
151
|
outputModalities?: string[];
|
|
148
152
|
supportedParameters?: string[];
|
|
153
|
+
reasoningEfforts?: ("none" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max" | "ultra")[];
|
|
149
154
|
supportedGenerationMethods?: string[];
|
|
150
155
|
}[];
|
|
151
156
|
additionalModels?: {
|
|
@@ -159,6 +164,7 @@ export declare class SwitcherClient {
|
|
|
159
164
|
inputModalities?: string[];
|
|
160
165
|
outputModalities?: string[];
|
|
161
166
|
supportedParameters?: string[];
|
|
167
|
+
reasoningEfforts?: ("none" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max" | "ultra")[];
|
|
162
168
|
supportedGenerationMethods?: string[];
|
|
163
169
|
}[];
|
|
164
170
|
version: number;
|
|
@@ -188,6 +194,7 @@ export declare class SwitcherClient {
|
|
|
188
194
|
inputModalities?: string[];
|
|
189
195
|
outputModalities?: string[];
|
|
190
196
|
supportedParameters?: string[];
|
|
197
|
+
reasoningEfforts?: ("none" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max" | "ultra")[];
|
|
191
198
|
supportedGenerationMethods?: string[];
|
|
192
199
|
}[];
|
|
193
200
|
additionalModels?: {
|
|
@@ -201,6 +208,7 @@ export declare class SwitcherClient {
|
|
|
201
208
|
inputModalities?: string[];
|
|
202
209
|
outputModalities?: string[];
|
|
203
210
|
supportedParameters?: string[];
|
|
211
|
+
reasoningEfforts?: ("none" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max" | "ultra")[];
|
|
204
212
|
supportedGenerationMethods?: string[];
|
|
205
213
|
}[];
|
|
206
214
|
version: number;
|
|
@@ -230,6 +238,7 @@ export declare class SwitcherClient {
|
|
|
230
238
|
inputModalities?: string[];
|
|
231
239
|
outputModalities?: string[];
|
|
232
240
|
supportedParameters?: string[];
|
|
241
|
+
reasoningEfforts?: ("none" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max" | "ultra")[];
|
|
233
242
|
supportedGenerationMethods?: string[];
|
|
234
243
|
}[];
|
|
235
244
|
additionalModels?: {
|
|
@@ -243,6 +252,7 @@ export declare class SwitcherClient {
|
|
|
243
252
|
inputModalities?: string[];
|
|
244
253
|
outputModalities?: string[];
|
|
245
254
|
supportedParameters?: string[];
|
|
255
|
+
reasoningEfforts?: ("none" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max" | "ultra")[];
|
|
246
256
|
supportedGenerationMethods?: string[];
|
|
247
257
|
}[];
|
|
248
258
|
version: number;
|
|
@@ -279,6 +289,7 @@ export declare class SwitcherClient {
|
|
|
279
289
|
inputModalities?: string[];
|
|
280
290
|
outputModalities?: string[];
|
|
281
291
|
supportedParameters?: string[];
|
|
292
|
+
reasoningEfforts?: ("none" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max" | "ultra")[];
|
|
282
293
|
supportedGenerationMethods?: string[];
|
|
283
294
|
}[];
|
|
284
295
|
additionalModels?: {
|
|
@@ -292,6 +303,7 @@ export declare class SwitcherClient {
|
|
|
292
303
|
inputModalities?: string[];
|
|
293
304
|
outputModalities?: string[];
|
|
294
305
|
supportedParameters?: string[];
|
|
306
|
+
reasoningEfforts?: ("none" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max" | "ultra")[];
|
|
295
307
|
supportedGenerationMethods?: string[];
|
|
296
308
|
}[];
|
|
297
309
|
version: number;
|
|
@@ -322,6 +334,7 @@ export declare class SwitcherClient {
|
|
|
322
334
|
inputModalities?: string[];
|
|
323
335
|
outputModalities?: string[];
|
|
324
336
|
supportedParameters?: string[];
|
|
337
|
+
reasoningEfforts?: ("none" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max" | "ultra")[];
|
|
325
338
|
supportedGenerationMethods?: string[];
|
|
326
339
|
}[];
|
|
327
340
|
additionalModels?: {
|
|
@@ -335,6 +348,7 @@ export declare class SwitcherClient {
|
|
|
335
348
|
inputModalities?: string[];
|
|
336
349
|
outputModalities?: string[];
|
|
337
350
|
supportedParameters?: string[];
|
|
351
|
+
reasoningEfforts?: ("none" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max" | "ultra")[];
|
|
338
352
|
supportedGenerationMethods?: string[];
|
|
339
353
|
}[];
|
|
340
354
|
version: number;
|
|
@@ -364,6 +378,7 @@ export declare class SwitcherClient {
|
|
|
364
378
|
inputModalities?: string[];
|
|
365
379
|
outputModalities?: string[];
|
|
366
380
|
supportedParameters?: string[];
|
|
381
|
+
reasoningEfforts?: ("none" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max" | "ultra")[];
|
|
367
382
|
supportedGenerationMethods?: string[];
|
|
368
383
|
}[];
|
|
369
384
|
additionalModels?: {
|
|
@@ -377,6 +392,7 @@ export declare class SwitcherClient {
|
|
|
377
392
|
inputModalities?: string[];
|
|
378
393
|
outputModalities?: string[];
|
|
379
394
|
supportedParameters?: string[];
|
|
395
|
+
reasoningEfforts?: ("none" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max" | "ultra")[];
|
|
380
396
|
supportedGenerationMethods?: string[];
|
|
381
397
|
}[];
|
|
382
398
|
version: number;
|
|
@@ -394,6 +410,7 @@ export declare class SwitcherClient {
|
|
|
394
410
|
inputModalities?: string[];
|
|
395
411
|
outputModalities?: string[];
|
|
396
412
|
supportedParameters?: string[];
|
|
413
|
+
reasoningEfforts?: ("none" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max" | "ultra")[];
|
|
397
414
|
supportedGenerationMethods?: string[];
|
|
398
415
|
}[];
|
|
399
416
|
refreshedAt: string;
|
|
@@ -411,6 +428,7 @@ export declare class SwitcherClient {
|
|
|
411
428
|
inputModalities?: string[];
|
|
412
429
|
outputModalities?: string[];
|
|
413
430
|
supportedParameters?: string[];
|
|
431
|
+
reasoningEfforts?: ("none" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max" | "ultra")[];
|
|
414
432
|
supportedGenerationMethods?: string[];
|
|
415
433
|
codingEligible: boolean;
|
|
416
434
|
expired: boolean;
|
|
@@ -565,6 +583,7 @@ export declare class SwitcherClient {
|
|
|
565
583
|
inputModalities?: string[];
|
|
566
584
|
outputModalities?: string[];
|
|
567
585
|
supportedParameters?: string[];
|
|
586
|
+
reasoningEfforts?: ("none" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max" | "ultra")[];
|
|
568
587
|
supportedGenerationMethods?: string[];
|
|
569
588
|
}[];
|
|
570
589
|
additionalModels?: {
|
|
@@ -578,6 +597,7 @@ export declare class SwitcherClient {
|
|
|
578
597
|
inputModalities?: string[];
|
|
579
598
|
outputModalities?: string[];
|
|
580
599
|
supportedParameters?: string[];
|
|
600
|
+
reasoningEfforts?: ("none" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max" | "ultra")[];
|
|
581
601
|
supportedGenerationMethods?: string[];
|
|
582
602
|
}[];
|
|
583
603
|
version: number;
|
|
@@ -624,6 +644,7 @@ export declare class SwitcherClient {
|
|
|
624
644
|
inputModalities?: string[];
|
|
625
645
|
outputModalities?: string[];
|
|
626
646
|
supportedParameters?: string[];
|
|
647
|
+
reasoningEfforts?: ("none" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max" | "ultra")[];
|
|
627
648
|
supportedGenerationMethods?: string[];
|
|
628
649
|
}[];
|
|
629
650
|
refreshedAt: string;
|
|
@@ -674,6 +695,7 @@ export declare class SwitcherClient {
|
|
|
674
695
|
requestedModel: string;
|
|
675
696
|
resolvedModel?: string;
|
|
676
697
|
reportedModel?: string;
|
|
698
|
+
reasoningEffort?: "none" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max" | "ultra";
|
|
677
699
|
decision: "allow" | "alias" | "reject" | "fallback";
|
|
678
700
|
role?: "main" | "subagent" | "fast" | "planning" | "review" | "summary" | "compaction" | "weak" | "editor";
|
|
679
701
|
reason?: string;
|
|
@@ -723,6 +745,7 @@ export declare class SwitcherClient {
|
|
|
723
745
|
requestedModel: string;
|
|
724
746
|
resolvedModel?: string;
|
|
725
747
|
reportedModel?: string;
|
|
748
|
+
reasoningEffort?: "none" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max" | "ultra";
|
|
726
749
|
decision: "allow" | "alias" | "reject" | "fallback";
|
|
727
750
|
role?: "main" | "subagent" | "fast" | "planning" | "review" | "summary" | "compaction" | "weak" | "editor";
|
|
728
751
|
reason?: string;
|
|
@@ -774,6 +797,7 @@ export declare class SwitcherClient {
|
|
|
774
797
|
requestedModel: string;
|
|
775
798
|
resolvedModel?: string;
|
|
776
799
|
reportedModel?: string;
|
|
800
|
+
reasoningEffort?: "none" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max" | "ultra";
|
|
777
801
|
decision: "allow" | "alias" | "reject" | "fallback";
|
|
778
802
|
role?: "main" | "subagent" | "fast" | "planning" | "review" | "summary" | "compaction" | "weak" | "editor";
|
|
779
803
|
reason?: string;
|
|
@@ -823,6 +847,7 @@ export declare class SwitcherClient {
|
|
|
823
847
|
requestedModel: string;
|
|
824
848
|
resolvedModel?: string;
|
|
825
849
|
reportedModel?: string;
|
|
850
|
+
reasoningEffort?: "none" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max" | "ultra";
|
|
826
851
|
decision: "allow" | "alias" | "reject" | "fallback";
|
|
827
852
|
role?: "main" | "subagent" | "fast" | "planning" | "review" | "summary" | "compaction" | "weak" | "editor";
|
|
828
853
|
reason?: string;
|
package/dist/sdk.js
CHANGED
|
@@ -1,23 +1,27 @@
|
|
|
1
1
|
// src/domain.ts
|
|
2
|
-
import { z as
|
|
2
|
+
import { z as z3 } from "zod";
|
|
3
3
|
|
|
4
|
-
// src/
|
|
4
|
+
// src/reasoning.ts
|
|
5
5
|
import { z } from "zod";
|
|
6
|
-
var
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
var
|
|
6
|
+
var reasoningEffortSchema = z.enum(["none", "minimal", "low", "medium", "high", "xhigh", "max", "ultra"]);
|
|
7
|
+
|
|
8
|
+
// src/model-policy-schema.ts
|
|
9
|
+
import { z as z2 } from "zod";
|
|
10
|
+
var policyModelIdSchema = z2.string().min(1).max(300).regex(/^[^\u0000-\u001f\u007f]+$/);
|
|
11
|
+
var modelPolicyRoleSchema = z2.enum(["subagent", "fast", "planning", "review", "summary", "compaction", "weak", "editor"]);
|
|
12
|
+
var boundedModelList = z2.array(policyModelIdSchema).max(500);
|
|
13
|
+
var aliasSchema = z2.string().regex(/^[A-Za-z0-9._/-]{1,120}$/).refine((v) => !["__proto__", "prototype", "constructor"].includes(v));
|
|
14
|
+
var boundedModelMap = z2.record(aliasSchema, policyModelIdSchema).superRefine((value, ctx) => {
|
|
11
15
|
if (Object.keys(value).length > 200)
|
|
12
16
|
ctx.addIssue({ code: "custom", message: "Model policy maps may contain at most 200 entries." });
|
|
13
17
|
});
|
|
14
|
-
var fallbacksSchema =
|
|
18
|
+
var fallbacksSchema = z2.record(policyModelIdSchema, z2.array(policyModelIdSchema).max(20)).superRefine((value, ctx) => {
|
|
15
19
|
if (Object.keys(value).length > 200)
|
|
16
20
|
ctx.addIssue({ code: "custom", message: "Model policy fallback maps may contain at most 200 entries." });
|
|
17
21
|
});
|
|
18
|
-
var modelPolicySchema =
|
|
19
|
-
version:
|
|
20
|
-
roles:
|
|
22
|
+
var modelPolicySchema = z2.object({
|
|
23
|
+
version: z2.literal(1).default(1),
|
|
24
|
+
roles: z2.object({
|
|
21
25
|
subagent: policyModelIdSchema.optional(),
|
|
22
26
|
fast: policyModelIdSchema.optional(),
|
|
23
27
|
planning: policyModelIdSchema.optional(),
|
|
@@ -31,26 +35,27 @@ var modelPolicySchema = z.object({
|
|
|
31
35
|
aliases: boundedModelMap.optional(),
|
|
32
36
|
fallbacks: fallbacksSchema.optional()
|
|
33
37
|
}).strict();
|
|
34
|
-
var routingDecisionSchema =
|
|
35
|
-
var routingEventRoleSchema =
|
|
36
|
-
var routingEventSchema =
|
|
37
|
-
at:
|
|
38
|
-
requestId:
|
|
38
|
+
var routingDecisionSchema = z2.enum(["allow", "alias", "reject", "fallback"]);
|
|
39
|
+
var routingEventRoleSchema = z2.enum(["main", ...modelPolicyRoleSchema.options]);
|
|
40
|
+
var routingEventSchema = z2.object({
|
|
41
|
+
at: z2.string().datetime({ offset: true }),
|
|
42
|
+
requestId: z2.string().regex(/^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/),
|
|
39
43
|
requestedModel: policyModelIdSchema,
|
|
40
44
|
resolvedModel: policyModelIdSchema.optional(),
|
|
41
45
|
reportedModel: policyModelIdSchema.optional(),
|
|
46
|
+
reasoningEffort: reasoningEffortSchema.optional(),
|
|
42
47
|
decision: routingDecisionSchema,
|
|
43
48
|
role: routingEventRoleSchema.optional(),
|
|
44
|
-
reason:
|
|
45
|
-
upstreamStatus:
|
|
49
|
+
reason: z2.string().regex(/^[a-z][a-z0-9_]{0,63}$/).optional(),
|
|
50
|
+
upstreamStatus: z2.number().int().min(100).max(599).optional()
|
|
46
51
|
}).strict();
|
|
47
|
-
var routingEventsSchema =
|
|
52
|
+
var routingEventsSchema = z2.array(routingEventSchema).max(1000);
|
|
48
53
|
// src/domain.ts
|
|
49
|
-
var harnessSchema =
|
|
50
|
-
var protocolSchema =
|
|
51
|
-
var idSchema =
|
|
52
|
-
var label =
|
|
53
|
-
var envRef =
|
|
54
|
+
var harnessSchema = z3.enum(["claude", "codex", "grok", "opencode", "opencode2", "pi", "omp", "dsh", "cline", "hermes", "prime-agent", "gemini", "aider", "kilo"]);
|
|
55
|
+
var protocolSchema = z3.enum(["anthropic-messages", "openai-responses", "openai-chat", "gemini-generate-content"]);
|
|
56
|
+
var idSchema = z3.string().regex(/^[a-zA-Z0-9][a-zA-Z0-9._-]{0,79}$/);
|
|
57
|
+
var label = z3.string().min(1).max(200);
|
|
58
|
+
var envRef = z3.string().regex(/^SWITCHER_PROVIDER_[A-Z0-9_]+$/);
|
|
54
59
|
function endpoint(value) {
|
|
55
60
|
let url;
|
|
56
61
|
try {
|
|
@@ -63,85 +68,86 @@ function endpoint(value) {
|
|
|
63
68
|
throw new Fault(400, "invalid_url", "URL must use HTTPS, contain no credentials/query/fragment, or use HTTP on loopback.");
|
|
64
69
|
return url.href.replace(/\/+$/, "");
|
|
65
70
|
}
|
|
66
|
-
var urlSchema =
|
|
71
|
+
var urlSchema = z3.string().max(2000).superRefine((v, ctx) => {
|
|
67
72
|
try {
|
|
68
73
|
endpoint(v);
|
|
69
74
|
} catch {
|
|
70
75
|
ctx.addIssue({ code: "custom", message: "Invalid endpoint URL" });
|
|
71
76
|
}
|
|
72
77
|
}).transform(endpoint);
|
|
73
|
-
var expiresOnSchema =
|
|
78
|
+
var expiresOnSchema = z3.string().regex(/^\d{4}-\d{2}-\d{2}$/).refine((value) => {
|
|
74
79
|
const day = new Date(`${value}T00:00:00.000Z`);
|
|
75
80
|
return Number.isFinite(day.getTime()) && day.toISOString().slice(0, 10) === value;
|
|
76
81
|
}, "Use a real calendar date in YYYY-MM-DD format.");
|
|
77
|
-
var modelSchema =
|
|
78
|
-
id:
|
|
82
|
+
var modelSchema = z3.object({
|
|
83
|
+
id: z3.string().min(1).max(300).refine((value) => value === value.trim() && !/[\x00-\x1f\x7f-\x9f]/.test(value), "Use a nonblank model ID without surrounding whitespace or control characters."),
|
|
79
84
|
name: label,
|
|
80
|
-
description:
|
|
81
|
-
available:
|
|
85
|
+
description: z3.string().max(8000).optional(),
|
|
86
|
+
available: z3.boolean().optional(),
|
|
82
87
|
expiresOn: expiresOnSchema.optional(),
|
|
83
|
-
contextWindow:
|
|
84
|
-
maxOutputTokens:
|
|
85
|
-
inputModalities:
|
|
86
|
-
outputModalities:
|
|
87
|
-
supportedParameters:
|
|
88
|
-
|
|
88
|
+
contextWindow: z3.number().int().positive().optional(),
|
|
89
|
+
maxOutputTokens: z3.number().int().positive().optional(),
|
|
90
|
+
inputModalities: z3.array(z3.string().max(50)).max(20).optional(),
|
|
91
|
+
outputModalities: z3.array(z3.string().max(50)).max(20).optional(),
|
|
92
|
+
supportedParameters: z3.array(z3.string().max(100)).max(100).optional(),
|
|
93
|
+
reasoningEfforts: z3.array(reasoningEffortSchema).max(8).optional(),
|
|
94
|
+
supportedGenerationMethods: z3.array(z3.string().min(1).max(100)).max(100).optional()
|
|
89
95
|
}).strict();
|
|
90
|
-
var providerInputSchema =
|
|
96
|
+
var providerInputSchema = z3.object({
|
|
91
97
|
id: idSchema,
|
|
92
98
|
name: label,
|
|
93
99
|
baseUrl: urlSchema,
|
|
94
100
|
protocol: protocolSchema,
|
|
95
101
|
credentialEnv: envRef.optional(),
|
|
96
|
-
authStyle:
|
|
102
|
+
authStyle: z3.enum(["bearer", "x-api-key", "api-key"]).default("bearer"),
|
|
97
103
|
catalogBaseUrl: urlSchema.optional(),
|
|
98
|
-
catalogFormat:
|
|
99
|
-
catalogAuthStyle:
|
|
104
|
+
catalogFormat: z3.enum(["openai", "ollama", "mistral", "together", "fireworks", "dashscope", "gemini", "none"]).optional(),
|
|
105
|
+
catalogAuthStyle: z3.enum(["bearer", "x-api-key", "api-key", "none"]).optional(),
|
|
100
106
|
catalogCredentialEnv: envRef.optional(),
|
|
101
|
-
catalogAccountId:
|
|
102
|
-
modelsPath:
|
|
103
|
-
manualModels:
|
|
104
|
-
additionalModels:
|
|
107
|
+
catalogAccountId: z3.string().regex(/^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/).optional(),
|
|
108
|
+
modelsPath: z3.string().regex(/^[a-zA-Z0-9_/-]+$/).max(200).default("models"),
|
|
109
|
+
manualModels: z3.array(modelSchema).max(1e4).default([]),
|
|
110
|
+
additionalModels: z3.array(modelSchema).max(1e4).optional()
|
|
105
111
|
}).strict().refine((p) => !p.modelsPath.split("/").includes("..") && !p.modelsPath.startsWith("/"), "modelsPath must be relative");
|
|
106
|
-
var providerPresetSchema =
|
|
112
|
+
var providerPresetSchema = z3.object({
|
|
107
113
|
id: idSchema,
|
|
108
114
|
name: label,
|
|
109
115
|
credentialEnv: envRef.optional(),
|
|
110
|
-
credentialAliases:
|
|
111
|
-
protocols:
|
|
116
|
+
credentialAliases: z3.array(z3.string().regex(/^[A-Z][A-Z0-9_]+$/)),
|
|
117
|
+
protocols: z3.array(z3.object({
|
|
112
118
|
protocol: protocolSchema,
|
|
113
119
|
baseUrl: urlSchema.optional(),
|
|
114
|
-
authStyle:
|
|
120
|
+
authStyle: z3.enum(["bearer", "x-api-key", "api-key"]),
|
|
115
121
|
catalogBaseUrl: urlSchema.optional(),
|
|
116
|
-
catalogFormat:
|
|
117
|
-
catalogAuthStyle:
|
|
118
|
-
modelsPath:
|
|
119
|
-
notes:
|
|
122
|
+
catalogFormat: z3.enum(["openai", "ollama", "mistral", "together", "fireworks", "dashscope", "gemini", "none"]),
|
|
123
|
+
catalogAuthStyle: z3.enum(["bearer", "x-api-key", "api-key", "none"]).optional(),
|
|
124
|
+
modelsPath: z3.string(),
|
|
125
|
+
notes: z3.array(z3.string())
|
|
120
126
|
}).strict()).min(1),
|
|
121
|
-
sources:
|
|
122
|
-
verification:
|
|
127
|
+
sources: z3.array(z3.string().url()),
|
|
128
|
+
verification: z3.literal("documented")
|
|
123
129
|
}).strict();
|
|
124
|
-
var profileInputSchema =
|
|
130
|
+
var profileInputSchema = z3.object({
|
|
125
131
|
id: idSchema,
|
|
126
132
|
name: label,
|
|
127
133
|
providerId: idSchema,
|
|
128
134
|
harness: harnessSchema,
|
|
129
|
-
model:
|
|
135
|
+
model: z3.string().min(1).max(300),
|
|
130
136
|
modelPolicy: modelPolicySchema.optional()
|
|
131
137
|
}).strict();
|
|
132
|
-
var runInputSchema =
|
|
133
|
-
modelPolicyVersion:
|
|
138
|
+
var runInputSchema = z3.object({
|
|
139
|
+
modelPolicyVersion: z3.literal(1),
|
|
134
140
|
profileId: idSchema,
|
|
135
141
|
harness: harnessSchema,
|
|
136
|
-
model:
|
|
142
|
+
model: z3.string().min(1).max(300),
|
|
137
143
|
modelPolicy: modelPolicySchema.optional(),
|
|
138
|
-
planToken:
|
|
144
|
+
planToken: z3.string().regex(/^[a-f0-9]{64}$/)
|
|
139
145
|
}).strict();
|
|
140
|
-
var runUpdateSchema =
|
|
141
|
-
status:
|
|
142
|
-
exitCode:
|
|
146
|
+
var runUpdateSchema = z3.object({
|
|
147
|
+
status: z3.enum(["exited", "failed", "interrupted"]),
|
|
148
|
+
exitCode: z3.number().int().min(0).max(255),
|
|
143
149
|
routingEvents: routingEventsSchema.optional(),
|
|
144
|
-
routingEventsDropped:
|
|
150
|
+
routingEventsDropped: z3.number().int().min(0).max(1e6).optional()
|
|
145
151
|
}).strict();
|
|
146
152
|
|
|
147
153
|
class Fault extends Error {
|
|
@@ -339,6 +345,98 @@ function providerFromPreset(presetId, options = {}) {
|
|
|
339
345
|
}] : []
|
|
340
346
|
});
|
|
341
347
|
}
|
|
348
|
+
// src/desktop-apps.ts
|
|
349
|
+
import { execFile } from "node:child_process";
|
|
350
|
+
import { access, stat } from "node:fs/promises";
|
|
351
|
+
import { constants } from "node:fs";
|
|
352
|
+
import { homedir } from "node:os";
|
|
353
|
+
import { isAbsolute, join } from "node:path";
|
|
354
|
+
import { promisify } from "node:util";
|
|
355
|
+
var execute = promisify(execFile);
|
|
356
|
+
var host = {
|
|
357
|
+
platform: process.platform,
|
|
358
|
+
home: homedir(),
|
|
359
|
+
async run(command, args) {
|
|
360
|
+
const { stdout } = await execute(command, args, { encoding: "utf8", timeout: 8000, maxBuffer: 64 * 1024, env: { PATH: "/usr/bin:/bin", HOME: homedir() } });
|
|
361
|
+
return stdout.trim();
|
|
362
|
+
},
|
|
363
|
+
async executable(path) {
|
|
364
|
+
try {
|
|
365
|
+
await access(path, constants.X_OK);
|
|
366
|
+
return (await stat(path)).isFile();
|
|
367
|
+
} catch {
|
|
368
|
+
return false;
|
|
369
|
+
}
|
|
370
|
+
},
|
|
371
|
+
async isDirectory(path) {
|
|
372
|
+
try {
|
|
373
|
+
return (await stat(path)).isDirectory();
|
|
374
|
+
} catch {
|
|
375
|
+
return false;
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
};
|
|
379
|
+
async function detectChatGPTApp(appPath, system = host) {
|
|
380
|
+
if (system.platform !== "darwin")
|
|
381
|
+
throw new Fault(422, "unsupported_platform", "ChatGPT provider launches currently require the macOS desktop app.");
|
|
382
|
+
let candidates;
|
|
383
|
+
if (appPath !== undefined)
|
|
384
|
+
candidates = [appPath];
|
|
385
|
+
else {
|
|
386
|
+
candidates = ["ChatGPT.app", "Codex.app"].flatMap((name) => [join(system.home, "Applications", name), join("/Applications", name)]);
|
|
387
|
+
try {
|
|
388
|
+
const found = await system.run("/usr/bin/osascript", ["-l", "JavaScript", "-e", 'ObjC.import("AppKit"); const url = $.NSWorkspace.sharedWorkspace.URLForApplicationWithBundleIdentifier("com.openai.codex"); url.isNil() ? "" : ObjC.unwrap(url.path);']);
|
|
389
|
+
if (found)
|
|
390
|
+
candidates.push(found);
|
|
391
|
+
} catch {}
|
|
392
|
+
}
|
|
393
|
+
for (const path of new Set(candidates)) {
|
|
394
|
+
if (!isAbsolute(path) || !path.endsWith(".app") || !await system.isDirectory(path))
|
|
395
|
+
continue;
|
|
396
|
+
const plist = join(path, "Contents/Info.plist");
|
|
397
|
+
const field = (name) => system.run("/usr/bin/plutil", ["-extract", name, "raw", "-o", "-", plist]);
|
|
398
|
+
try {
|
|
399
|
+
const bundleId = await field("CFBundleIdentifier");
|
|
400
|
+
if (bundleId !== "com.openai.codex")
|
|
401
|
+
continue;
|
|
402
|
+
const name = await field("CFBundleExecutable"), version = await field("CFBundleShortVersionString");
|
|
403
|
+
if (!/^[A-Za-z0-9 _-]+$/.test(name))
|
|
404
|
+
continue;
|
|
405
|
+
const executable = join(path, "Contents/MacOS", name), codexExecutable = join(path, "Contents/Resources/codex");
|
|
406
|
+
if (await system.executable(executable) && await system.executable(codexExecutable))
|
|
407
|
+
return { path, executable, codexExecutable, bundleId, version };
|
|
408
|
+
} catch {}
|
|
409
|
+
}
|
|
410
|
+
throw new Fault(404, "app_not_installed", "Install the current ChatGPT/Codex macOS app or use --app-path with its absolute .app path. Legacy ChatGPT Classic cannot run custom Codex providers.");
|
|
411
|
+
}
|
|
412
|
+
async function detectClaudeDesktopApp(appPath, system = host) {
|
|
413
|
+
if (system.platform !== "darwin")
|
|
414
|
+
throw new Fault(422, "unsupported_platform", "Claude desktop provider launches currently require macOS.");
|
|
415
|
+
const candidates = appPath === undefined ? [join(system.home, "Applications/Claude.app"), "/Applications/Claude.app"] : [appPath];
|
|
416
|
+
if (appPath === undefined)
|
|
417
|
+
try {
|
|
418
|
+
const found = await system.run("/usr/bin/osascript", ["-l", "JavaScript", "-e", 'ObjC.import("AppKit"); const url = $.NSWorkspace.sharedWorkspace.URLForApplicationWithBundleIdentifier("com.anthropic.claudefordesktop"); url.isNil() ? "" : ObjC.unwrap(url.path);']);
|
|
419
|
+
if (found)
|
|
420
|
+
candidates.push(found);
|
|
421
|
+
} catch {}
|
|
422
|
+
for (const path of new Set(candidates)) {
|
|
423
|
+
if (!isAbsolute(path) || !path.endsWith(".app") || !await system.isDirectory(path))
|
|
424
|
+
continue;
|
|
425
|
+
const field = (name) => system.run("/usr/bin/plutil", ["-extract", name, "raw", "-o", "-", join(path, "Contents/Info.plist")]);
|
|
426
|
+
try {
|
|
427
|
+
const bundleId = await field("CFBundleIdentifier");
|
|
428
|
+
if (bundleId !== "com.anthropic.claudefordesktop")
|
|
429
|
+
continue;
|
|
430
|
+
const name = await field("CFBundleExecutable"), version = await field("CFBundleShortVersionString");
|
|
431
|
+
if (!/^[A-Za-z0-9 _-]+$/.test(name))
|
|
432
|
+
continue;
|
|
433
|
+
const executable = join(path, "Contents/MacOS", name);
|
|
434
|
+
if (await system.executable(executable))
|
|
435
|
+
return { path, executable, bundleId, version };
|
|
436
|
+
} catch {}
|
|
437
|
+
}
|
|
438
|
+
throw new Fault(404, "app_not_installed", "Install the current Claude macOS desktop app or supply its absolute .app path with --app-path.");
|
|
439
|
+
}
|
|
342
440
|
|
|
343
441
|
// src/sdk.ts
|
|
344
442
|
class SwitcherError extends Error {
|
|
@@ -555,6 +653,8 @@ function clientFromEnv(env = process.env, options = {}) {
|
|
|
555
653
|
}
|
|
556
654
|
export {
|
|
557
655
|
providerFromPreset,
|
|
656
|
+
detectClaudeDesktopApp,
|
|
657
|
+
detectChatGPTApp,
|
|
558
658
|
clientFromEnv,
|
|
559
659
|
SwitcherError,
|
|
560
660
|
SwitcherClient
|