@hasna/switcher 0.2.22 → 0.2.25
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 +3 -0
- package/README.md +3 -1
- package/dist/claude-context.d.ts +12 -1
- package/dist/cli/index.js +575 -166
- package/dist/deepseek-messages.d.ts +41 -0
- package/dist/gateway-client.d.ts +1 -0
- package/dist/harness-types.d.ts +2 -0
- package/dist/index.js +176 -23
- package/dist/inference-gateway.d.ts +6 -1
- package/dist/mcp/index.js +178 -25
- package/dist/provider-error.d.ts +23 -0
- package/dist/sdk.d.ts +27 -4
- package/dist/sdk.js +176 -23
- package/dist/serve/index.js +2 -2
- package/docs/GATEWAY-SERVICE.md +36 -3
- package/openapi.json +1 -1
- package/package.json +1 -1
package/Dockerfile
CHANGED
|
@@ -14,7 +14,10 @@ RUN bun run generate \
|
|
|
14
14
|
&& bun run build
|
|
15
15
|
|
|
16
16
|
FROM --platform=linux/arm64 oven/bun:1.3.14-alpine AS runtime
|
|
17
|
+
# Bun.SQL auto-pipelining off: in Bun 1.3.14 it can match a query to another query's result
|
|
18
|
+
# (the Todos fix, #4043). Bun reads the flag only at process start, so it is set here.
|
|
17
19
|
ENV NODE_ENV=production \
|
|
20
|
+
BUN_FEATURE_FLAG_DISABLE_SQL_AUTO_PIPELINING=1 \
|
|
18
21
|
PORT=8080
|
|
19
22
|
WORKDIR /app
|
|
20
23
|
RUN apk upgrade --no-cache \
|
package/README.md
CHANGED
|
@@ -621,7 +621,7 @@ Cline uses its native ACP backend with per-launch configuration, durable session
|
|
|
621
621
|
|
|
622
622
|
## Background sessions and the persistent gateway
|
|
623
623
|
|
|
624
|
-
Launches register with one persistent gateway per user on a stable `127.0.0.1` port. A launch's token keeps working for as long as any process it started still runs, including Claude Code's detached background host and its background sessions after `switcher launch` exits. When nothing from the launch remains, the launch ends. For 30 days after that, a request with its token from a process of this user running under a current launch, such as a background session that Claude Code's background host started again, revives it; for a launch without a durable Claude route, a copied token used from anywhere else stays refused, and holding a launch that only its durable route revived does not count as running under a current launch. A Claude launch also writes its route into the session's `--settings` file (mode 0600 in the profile's private session folder), so a session the background host restores after a station restart, or opens from another folder, keeps its route without a current launch. So for 30 days after a Claude launch was last used, the gateway serves its token to any running process of this user that presents it, a shell or script included; another account's process, or a connection the gateway cannot trace, is refused when it would revive an ended launch. While any launch is current, the gateway serves its token on any loopback connection that presents it, without a process check. For the default `~/.hasna/switcher` home the gateway runs under launchd (macOS) or systemd `--user` (Linux), starts at login, and is installed automatically by the first launch of the installed `switcher`. Other homes and other copies of Switcher use a detached gateway that exits when idle.
|
|
624
|
+
Launches register with one persistent gateway per user on a stable `127.0.0.1` port. A launch's token keeps working for as long as any process it started still runs, including Claude Code's detached background host and its background sessions after `switcher launch` exits. When nothing from the launch remains, the launch ends. For 30 days after that, a request with its token from a process of this user running under a current launch, such as a background session that Claude Code's background host started again, revives it; for a launch without a durable Claude route, a copied token used from anywhere else stays refused, and holding a launch that only its durable route revived does not count as running under a current launch. A Claude launch also writes its route into the session's `--settings` file (mode 0600 in the profile's private session folder), so a session the background host restores after a station restart, or opens from another folder, keeps its route without a current launch. Since 0.2.23 that launch also gives its route to the profile's earlier picker-only settings files (`claude-settings-<digest>.json`), so sessions dispatched before 0.2.21 come back logged in when their host next starts them, and the gateway takes it back when it stops accepting the token. A launch without a route uses its own `claude-picker-<digest>.json`, which never carries another launch's route. So for 30 days after a Claude launch was last used, the gateway serves its token to any running process of this user that presents it, a shell or script included; another account's process, or a connection the gateway cannot trace, is refused when it would revive an ended launch. While any launch is current, the gateway serves its token on any loopback connection that presents it, without a process check. For the default `~/.hasna/switcher` home the gateway runs under launchd (macOS) or systemd `--user` (Linux), starts at login, and is installed automatically by the first launch of the installed `switcher`. Other homes and other copies of Switcher use a detached gateway that exits when idle.
|
|
625
625
|
|
|
626
626
|
```sh
|
|
627
627
|
switcher gateway status # running, pid, port, launches and login unit
|
|
@@ -778,6 +778,8 @@ console.log(plan.catalog.models.length);
|
|
|
778
778
|
|
|
779
779
|
The SDK supports Node and Bun. It has no database or launcher imports. Explicit credentials may be supplied as a string or a fresh resolver function; `clientFromEnv()` uses the shared contracts resolver with environment-only inputs and no disk fallback.
|
|
780
780
|
|
|
781
|
+
The SDK client retries a call at most three times, with exponential backoff (200 ms, 400 ms, 800 ms plus up to 50% jitter; no single wait exceeds 2 s, jitter included), and only for two failure shapes: any HTTP 503 (an edge in front of the API being briefly unreachable, or Switcher's own JSON `storage unavailable`, whose failed write rolled back), or a 5xx response with a non-JSON body such as the plain-text `error code: 500`. A GET is retried; a write is retried only when its idempotency key was supplied, and every attempt reuses that key, so the server replays the stored result instead of repeating the write. `createProvider`, `updateProvider`, `deleteProvider`, `refreshModels`, `saveCatalog`, `createProfile`, `updateProfile`, `deleteProfile`, `launchPlan`, `createRun` and `finishRun` mint one key per call when you pass none. A 401, a 403, any other 4xx, a 5xx other than 503 that has a JSON body, a refused connection and a non-JSON success body are never retried. Pass `retry: {retries, baseDelayMs, maxDelayMs}` to tune the policy (at most 5 retries and 10 s for any one wait; larger values are clamped) or `retry: false` to turn it off.
|
|
782
|
+
|
|
781
783
|
SDK and CLI API-error diagnostics validate code/request-ID fields, bound message length, remove terminal control characters, and redact the operator credential actually sent with that request. Redaction covers raw, JSON-string-escaped, URL-encoded and Base64/Base64url representations. Native harness stdout and terminal output remain under the native client's control.
|
|
782
784
|
|
|
783
785
|
Public lifecycle endpoints: `GET /health`, `/ready`, `/version`, `/openapi.json`, and `/v1/openapi.json`. Provider/profile CRUD, `/v1/provider-presets`, catalog list/refresh, version-checked catalog metadata commits, launch-plan validation and run metadata are under `/v1`. The SDK includes `listProviderPresets()`, `getProviderPreset()`, `health()`, `ready()`, and `version()`. SDK types are generated from that OpenAPI document. API errors include code, message and request ID.
|
package/dist/claude-context.d.ts
CHANGED
|
@@ -1,8 +1,19 @@
|
|
|
1
1
|
/** Keep enough room for Claude's next turn and compaction request on DeepSeek.
|
|
2
2
|
* https://api-docs.deepseek.com/quick_start/agent_integrations/claude_code/
|
|
3
3
|
* Inspect the original provider URL: the native URL is a loopback gateway.
|
|
4
|
+
*
|
|
5
|
+
* For any other provider, the selected model's catalog window sets the same headroom. Without
|
|
6
|
+
* CLAUDE_CODE_AUTO_COMPACT_WINDOW, Claude Code runs no auto-compaction at all for a `[1m]` model id
|
|
7
|
+
* it doesn't recognise, so the context grows until the provider refuses it (a glm session on
|
|
8
|
+
* OpenRouter grew past 1M tokens and every request failed, 04.11, SH-00074). Setting it turns
|
|
9
|
+
* proactive compaction back on: CLAUDE_CODE_AUTO_COMPACT_WINDOW (100k to 1M) compacts at three
|
|
10
|
+
* quarters of the window, DeepSeek's ratio (786432 of 1048576). Below 1M,
|
|
11
|
+
* CLAUDE_CODE_MAX_CONTEXT_TOKENS tells Claude the real window instead of its 200k assumption; at 1M
|
|
12
|
+
* and above the `[1m]` suffix does (claudeNativeModelId). Both are documented Claude Code settings:
|
|
13
|
+
* https://code.claude.com/docs/en/model-config#correct-the-window-for-a-gateway-or-custom-model-id
|
|
14
|
+
* A model without a declared window keeps Claude's own defaults; explicit settings always win.
|
|
4
15
|
*/
|
|
5
|
-
export declare function claudeContextEnvironment(providerBaseUrl: string, environment?: NodeJS.ProcessEnv): Record<string, string>;
|
|
16
|
+
export declare function claudeContextEnvironment(providerBaseUrl: string, environment?: NodeJS.ProcessEnv, contextWindow?: number): Record<string, string>;
|
|
6
17
|
/** Claude Code treats a model it doesn't know as a 200k-token one and compacts near 168k, even when
|
|
7
18
|
* the provider serves more and CLAUDE_CODE_AUTO_COMPACT_WINDOW is higher (measured on DeepSeek flash,
|
|
8
19
|
* 30.10). The `[1m]` suffix tells it the window is 1M; Claude strips it before calling the provider.
|