@hasna/switcher 0.2.25 → 0.2.26

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/dist/cli.d.ts CHANGED
@@ -1,4 +1,15 @@
1
1
  #!/usr/bin/env bun
2
- import { type ModelPolicy } from "./domain";
2
+ import { Fault, type ModelPolicy } from "./domain";
3
+ import { type LaunchOptions } from "./launcher";
3
4
  export declare function readModelPolicy(file: string | undefined, roleValues: string[] | undefined): Promise<ModelPolicy | undefined>;
4
- export declare function main(args?: string[]): Promise<void>;
5
+ /** Launch options only `switcher resume` passes through its launch. */
6
+ type InternalLaunchOptions = Pick<LaunchOptions, "prepareOnly" | "requireDurableRoute">;
7
+ export declare function main(args?: string[], internal?: {
8
+ launchOptions?: InternalLaunchOptions;
9
+ }): Promise<void>;
10
+ /** A refusal of `switcher resume` with its documented exit code (see HELP). */
11
+ export declare class ResumeFault extends Fault {
12
+ readonly exitCode: number;
13
+ constructor(exitCode: number, status: number, code: string, message: string);
14
+ }
15
+ export {};
@@ -1,4 +1,4 @@
1
- import { type GatewayHost, type RoutingEvent } from "./inference-gateway";
1
+ import type { GatewayHost, RoutingEvent } from "./inference-gateway";
2
2
  import { type CommandRunner } from "./gateway-supervisor";
3
3
  export type GatewayStatus = {
4
4
  service: "switcher-gateway";
@@ -73,7 +73,9 @@ export type ServiceGatewayHost = GatewayHost & {
73
73
  };
74
74
  /**
75
75
  * Register each launch gateway with the persistent service. If registration fails,
76
- * the launch still runs on a per-launch gateway and says so.
76
+ * the launch still runs on a per-launch gateway, warns and records it (gateway-fallback.ts).
77
+ * requireDurableRoute: refuse instead (gateway_route_unavailable) unless the launch gets a durable
78
+ * Claude route, for a caller that starts the harness itself after this process exits.
77
79
  */
78
80
  export declare function createServiceGatewayHost(client: GatewayControlClient, context: {
79
81
  holderPid: number;
@@ -81,5 +83,6 @@ export declare function createServiceGatewayHost(client: GatewayControlClient, c
81
83
  credentialEnv?: string;
82
84
  onRoutingEvent?: (event: RoutingEvent) => void;
83
85
  warn?: (message: string) => void;
86
+ requireDurableRoute?: boolean;
84
87
  }): ServiceGatewayHost;
85
88
  export {};
@@ -0,0 +1,42 @@
1
+ import { type GatewayHost, type GatewayInput, type GatewayLease } from "./inference-gateway";
2
+ /**
3
+ * A launch that meant to use the persistent gateway but runs on its own per-launch gateway
4
+ * (the service could not start, or refused the registration). That gateway listens on a
5
+ * random loopback port and stops when `switcher launch` exits, so a session that outlives
6
+ * the launch, or is resumed later outside Switcher, finds a dead port (SH-00097). The launch
7
+ * still runs, as before, but says so loudly on stderr and leaves a record an operator can find:
8
+ * `<state>/per-launch-gateways/<launch-XXXXXX>.json`, named after the launch's state directory,
9
+ * with the port, harness, model, working directory, launcher PID and reason. It never holds the
10
+ * gateway token or a credential. `endedAt` is added when the launch ends and the port closes.
11
+ */
12
+ export declare const PER_LAUNCH_GATEWAY_DIRECTORY = "per-launch-gateways";
13
+ export type PerLaunchGatewayRecord = {
14
+ schema: 1;
15
+ launchId: string;
16
+ port: number;
17
+ harness: string;
18
+ model: string;
19
+ cwd: string;
20
+ sessionDir?: string;
21
+ launcherPid: number;
22
+ reason: string;
23
+ createdAt: string;
24
+ endedAt?: string;
25
+ };
26
+ /** Where a per-launch fallback of the launch whose state directory is `stateDir` is recorded. */
27
+ export declare function perLaunchGatewayRecordPath(stateDir: string): string;
28
+ /**
29
+ * Start a per-launch gateway in place of the persistent one, warn on stderr with the reason and
30
+ * the port, and record it under the state root (when the launch has a state directory).
31
+ */
32
+ export declare function openPerLaunchGateway(input: GatewayInput, context: {
33
+ reason: string;
34
+ stateDir?: string;
35
+ warn?: (message: string) => void;
36
+ }): Promise<GatewayLease>;
37
+ /** A gateway host that always uses a per-launch gateway, for a launch whose persistent gateway is unavailable. */
38
+ export declare function perLaunchGatewayHost(context: {
39
+ reason: string;
40
+ stateDir?: string;
41
+ warn?: (message: string) => void;
42
+ }): GatewayHost;
@@ -1,4 +1,5 @@
1
1
  import { type ProviderInput } from "./domain";
2
+ import { type RoutingEvent } from "./inference-gateway";
2
3
  import type { ProviderRequestTiming } from "./provider-request";
3
4
  import { type ConnectionPeerLookup, type EnvironmentDigestProbe, type ProcessReader } from "./process-table";
4
5
  /** Version of the control protocol between `switcher launch` and the gateway service. */
@@ -35,6 +36,11 @@ export declare function gatewaySettings(env?: NodeJS.ProcessEnv): {
35
36
  scanMs: number;
36
37
  exitIdleMs: number;
37
38
  };
39
+ /**
40
+ * The class of a request the provider or the gateway refused, or undefined for one that was served.
41
+ * Every reason the inference handler sets is a fixed code, never message or request text.
42
+ */
43
+ export declare function refusalClass(event: RoutingEvent): string | undefined;
38
44
  export type GatewayServiceOptions = {
39
45
  env?: NodeJS.ProcessEnv;
40
46
  port?: number;
@@ -12,11 +12,23 @@ export type LaunchBackend = "direct" | "ori";
12
12
  export type GatewayMode = "local" | "service";
13
13
  /** service: register with the persistent per-user gateway so detached descendants keep working. */
14
14
  /** gatewaySupervise: false keeps a non-PATH switcher (a development checkout) from installing the login service. */
15
+ /**
16
+ * requireDurableRoute: refuse (Fault gateway_route_unavailable) instead of falling back to a
17
+ * per-launch gateway, for a launch whose harness is started later by another process.
18
+ */
15
19
  export type LaunchGatewayOptions = {
16
20
  gateway?: GatewayMode;
17
21
  gatewayCommand?: string[];
18
22
  gatewaySupervise?: boolean;
19
23
  connectGateway?: () => Promise<GatewayControlClient>;
24
+ requireDurableRoute?: boolean;
25
+ };
26
+ /** What a launch would start: the native executable, its arguments, the environment it adds (values included) and its working directory. */
27
+ export type PreparedHarness = {
28
+ executable: string;
29
+ args: string[];
30
+ env: Record<string, string>;
31
+ cwd: string;
20
32
  };
21
33
  export type LaunchOptions = LaunchGatewayOptions & {
22
34
  desktop?: ChatGPTInstallation;
@@ -35,6 +47,12 @@ export type LaunchOptions = LaunchGatewayOptions & {
35
47
  credentialEnv?: NodeJS.ProcessEnv;
36
48
  credentialPreflight?: string;
37
49
  resolveCredential?: (provider: ProviderInput) => Promise<string | undefined>;
50
+ /**
51
+ * Prepare everything a launch needs (gateway lease, route and settings files, native state)
52
+ * and hand it to this callback instead of starting the harness. The lease is then released,
53
+ * not revoked, so its durable route stays usable for the process the caller starts.
54
+ */
55
+ prepareOnly?: (prepared: PreparedHarness) => Promise<void>;
38
56
  };
39
57
  type OriPreparationOptions = Pick<LaunchOptions, "oriExecutable" | "args" | "resolveCredential" | "credentialEnv"> & {
40
58
  stateDir?: string;
package/dist/mcp/index.js CHANGED
@@ -19495,7 +19495,7 @@ function canonicalPolicyJSON(value) {
19495
19495
  return JSON.stringify(value, (_key, item) => item && typeof item === "object" && !Array.isArray(item) ? Object.fromEntries(Object.entries(item).sort(([a], [b]) => a.localeCompare(b))) : item);
19496
19496
  }
19497
19497
  // package.json
19498
- var version2 = "0.2.25";
19498
+ var version2 = "0.2.26";
19499
19499
 
19500
19500
  // src/version.ts
19501
19501
  var VERSION = version2;
@@ -22732,7 +22732,7 @@ var openapi_default = {
22732
22732
  openapi: "3.0.3",
22733
22733
  info: {
22734
22734
  title: "Switcher API",
22735
- version: "0.2.25",
22735
+ version: "0.2.26",
22736
22736
  description: "Authenticated provider/profile/catalog control plane. Launches run locally; the API never returns provider credentials."
22737
22737
  },
22738
22738
  security: [
@@ -68,7 +68,7 @@ function canonicalPolicyJSON(value) {
68
68
  return JSON.stringify(value, (_key, item) => item && typeof item === "object" && !Array.isArray(item) ? Object.fromEntries(Object.entries(item).sort(([a], [b]) => a.localeCompare(b))) : item);
69
69
  }
70
70
  // package.json
71
- var version = "0.2.25";
71
+ var version = "0.2.26";
72
72
 
73
73
  // src/version.ts
74
74
  var VERSION = version;
@@ -922,7 +922,7 @@ var openapi_default = {
922
922
  openapi: "3.0.3",
923
923
  info: {
924
924
  title: "Switcher API",
925
- version: "0.2.25",
925
+ version: "0.2.26",
926
926
  description: "Authenticated provider/profile/catalog control plane. Launches run locally; the API never returns provider credentials."
927
927
  },
928
928
  security: [
package/openapi.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "openapi": "3.0.3",
3
3
  "info": {
4
4
  "title": "Switcher API",
5
- "version": "0.2.25",
5
+ "version": "0.2.26",
6
6
  "description": "Authenticated provider/profile/catalog control plane. Launches run locally; the API never returns provider credentials."
7
7
  },
8
8
  "security": [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hasna/switcher",
3
- "version": "0.2.25",
3
+ "version": "0.2.26",
4
4
  "type": "module",
5
5
  "description": "Universal provider and model switcher for coding harnesses with an API, SDK and self-hosted storage",
6
6
  "license": "Apache-2.0",