@hasna/switcher 0.2.2 → 0.2.3
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 +992 -706
- 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 +15 -11
- package/dist/mcp/index.js +1055 -95
- 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 +15 -11
- package/dist/serve/index.js +350 -90
- 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/Dockerfile
CHANGED
|
@@ -1,11 +1,41 @@
|
|
|
1
|
-
|
|
1
|
+
# syntax=docker/dockerfile:1
|
|
2
|
+
# switcher-serve — Bun runtime image for the local SQLite and hosted PostgreSQL APIs.
|
|
3
|
+
|
|
4
|
+
FROM --platform=linux/arm64 oven/bun:1.3.14-alpine AS builder
|
|
5
|
+
RUN apk upgrade --no-cache \
|
|
6
|
+
&& test "$(bun --version)" = "1.3.14"
|
|
2
7
|
WORKDIR /app
|
|
3
|
-
COPY package.json ./
|
|
4
|
-
RUN bun install --
|
|
5
|
-
COPY
|
|
6
|
-
COPY
|
|
7
|
-
|
|
8
|
+
COPY package.json bun.lock ./
|
|
9
|
+
RUN bun install --frozen-lockfile
|
|
10
|
+
COPY tsconfig.json openapi.json hasna.contract.json ./
|
|
11
|
+
COPY scripts ./scripts
|
|
12
|
+
COPY src ./src
|
|
13
|
+
RUN bun run generate \
|
|
14
|
+
&& bun run build
|
|
15
|
+
|
|
16
|
+
FROM --platform=linux/arm64 oven/bun:1.3.14-alpine AS runtime
|
|
17
|
+
ENV NODE_ENV=production \
|
|
18
|
+
PORT=8080 \
|
|
19
|
+
HOST=0.0.0.0
|
|
20
|
+
WORKDIR /app
|
|
21
|
+
RUN apk upgrade --no-cache \
|
|
22
|
+
&& apk add --no-cache ca-certificates wget \
|
|
23
|
+
&& test "$(bun --version)" = "1.3.14" \
|
|
24
|
+
&& wget -qO /app/rds-global-bundle.pem https://truststore.pki.rds.amazonaws.com/global/global-bundle.pem \
|
|
25
|
+
&& mkdir /data \
|
|
26
|
+
&& chown bun:bun /data
|
|
27
|
+
ENV NODE_EXTRA_CA_CERTS=/app/rds-global-bundle.pem \
|
|
28
|
+
PGSSLROOTCERT=/app/rds-global-bundle.pem
|
|
29
|
+
COPY package.json bun.lock ./
|
|
30
|
+
RUN bun install --frozen-lockfile --production --ignore-scripts
|
|
31
|
+
COPY --from=builder /app/dist ./dist
|
|
32
|
+
COPY --from=builder /app/openapi.json ./openapi.json
|
|
33
|
+
COPY --from=builder /app/hasna.contract.json ./hasna.contract.json
|
|
34
|
+
RUN printf '#!/bin/sh\nexec bun /app/dist/serve/index.js "$@"\n' > /usr/local/bin/switcher-serve \
|
|
35
|
+
&& printf '#!/bin/sh\nexec bun /app/dist/mint/index.js "$@"\n' > /usr/local/bin/switcher-mint-key \
|
|
36
|
+
&& chmod +x /usr/local/bin/switcher-serve /usr/local/bin/switcher-mint-key
|
|
8
37
|
USER bun
|
|
9
38
|
EXPOSE 8080
|
|
10
|
-
HEALTHCHECK --interval=20s --timeout=5s
|
|
11
|
-
CMD
|
|
39
|
+
HEALTHCHECK --interval=20s --timeout=5s --start-period=15s --retries=3 \
|
|
40
|
+
CMD bun -e 'fetch("http://127.0.0.1:8080/ready").then(r=>process.exit(r.ok?0:1)).catch(()=>process.exit(1))'
|
|
41
|
+
CMD ["switcher-serve"]
|
package/README.md
CHANGED
|
@@ -226,7 +226,7 @@ switcher launch codex --provider openrouter --model anthropic/claude-sonnet-4.6
|
|
|
226
226
|
|
|
227
227
|
An interactive terminal can choose or search the catalog when `--model` is omitted. Noninteractive launches require an explicit model. `--dry-run` resolves and saves the provider/profile and fresh catalog, then prints the launch plan without starting the harness or creating a run record. Existing `switcher launch PROFILE` commands remain supported. Direct launches create or reuse records without overwriting customized providers or profiles.
|
|
228
228
|
|
|
229
|
-
With no Switcher API credential configured, the CLI and `switcher-mcp` exit non-zero and name the sources they consulted (Keychain item `hasna.credentials.switcher.api-key`, `~/.hasna/switcher/config/credentials`, `HASNA_SWITCHER_API_KEY`); they never open local data by default. Set `HASNA_SWITCHER_LOCAL=1` (alias `SWITCHER_LOCAL=1`) to deliberately run on the box: each invocation then starts an authenticated loopback API on an allocated port, stores SQLite data in `~/.hasna/switcher`, prints one `switcher: LOCAL mode` line on stderr, and closes its own listener on completion. Its random operator key remains in memory. Under that opt-in, use `HASNA_SWITCHER_HOME` to choose another owner-only home, `HASNA_SWITCHER_SQLITE_PATH` for an explicit database, or `HASNA_SWITCHER_DATABASE_URL` for PostgreSQL. A configured API URL or key outranks the flag. API and SDK data access remains HTTP.
|
|
229
|
+
With no Switcher API credential configured, the CLI and `switcher-mcp` exit non-zero and name the sources they consulted (Keychain item `hasna.credentials.switcher.api-key`, `~/.hasna/switcher/config/credentials`, `HASNA_SWITCHER_API_KEY`); they never open local data by default. Set `HASNA_SWITCHER_LOCAL=1` (alias `SWITCHER_LOCAL=1`; affirmative values are `1`, `true`, `yes`, or `on`) to deliberately run on the box: each invocation then starts an authenticated loopback API on an allocated port, stores SQLite data in `~/.hasna/switcher`, prints one `switcher: LOCAL mode` line on stderr, and closes its own listener on completion. Its random operator key remains in memory. Under that opt-in, use `HASNA_SWITCHER_HOME` to choose another owner-only home, `HASNA_SWITCHER_SQLITE_PATH` for an explicit database, or `HASNA_SWITCHER_DATABASE_URL` for PostgreSQL. A configured API URL or key outranks the flag. API and SDK data access remains HTTP.
|
|
230
230
|
|
|
231
231
|
Remote API configuration is resolved through Contracts, including canonical credential stores and the default gateway URL. Invalid, unavailable or unauthorized remote services fail without opening local SQLite.
|
|
232
232
|
|
|
@@ -347,7 +347,7 @@ The digest is a release-artifact checksum, not a credential. Do not substitute t
|
|
|
347
347
|
|
|
348
348
|
For provider keys already stored in macOS Keychain, use `--keychain-service SERVICE --keychain-account ACCOUNT` instead of vault options. Bindings contain only references and authorized origins under `~/.hasna/switcher/config/credential-bindings`, in owner-only files. They remain local even when Switcher uses a remote API. A configured binding takes precedence over environment aliases; an unavailable binding never falls back to another account.
|
|
349
349
|
|
|
350
|
-
`credentials list` displays bindings; `credentials remove PRESET_OR_REFERENCE` removes only the locator. Replacement requires explicit removal. Custom credential references require `--origin URL` (repeatable); preset bindings authorize their documented origins by default. `credentials check` reports availability, length and hash, not successful provider authentication.
|
|
350
|
+
`credentials list` displays bindings; `credentials remove PRESET_OR_REFERENCE` removes only the locator. Replacement requires explicit removal. Custom credential references require `--origin URL` (repeatable); preset bindings authorize their documented origins by default. `credentials check` reports availability, length and hash, not successful provider authentication. When the selected Switcher API is hosted, catalog discovery still runs in the local launcher after credential authentication; only validated catalog metadata is committed to the API. Provider values are never sent to or stored by the hosted Switcher service.
|
|
351
351
|
|
|
352
352
|
Explicit `--vault-account ACCOUNT` pins one macOS Keychain account and requires `--vault-url`; it never falls back when that account is missing or locked. `--vault-operator env` preserves the per-process `HASNA_SECRETS_API_KEY` mode and also requires `--vault-url`. Existing bindings keep their original operator mode. To adopt canonical resolution for an old binding, explicitly remove and rebind its same provider key reference. A Secrets operator cannot bootstrap itself through `HASNA_SECRETS_API_KEY_REF`; use a literal operator from its canonical store or explicit override. On Linux the shared resolver reads the owner-only canonical credentials file or process environment. The binding stores only the locator and optional vault authority. Alternatively, let the authenticated `secrets` CLI inject a provider credential for one command:
|
|
353
353
|
|
|
@@ -455,19 +455,24 @@ Cline uses its native ACP backend with per-launch configuration, durable session
|
|
|
455
455
|
|
|
456
456
|
## Run a persistent service
|
|
457
457
|
|
|
458
|
-
|
|
458
|
+
For a private local/self-hosted service, inject a random operator token of at least 24 characters as `HASNA_SWITCHER_API_KEY`. For a hosted PostgreSQL service, inject `HASNA_SWITCHER_API_SIGNING_KEY` (or the shared `HASNA_API_SIGNING_KEY` / `API_KEY_SIGNING_SECRET`) and issue revocable, scoped `switcher:read` / `switcher:write` client keys through `@hasna/contracts`. Exactly one authentication mode is accepted. Provider credentials stay in each launcher process; hosted catalog refresh uploads metadata only.
|
|
459
459
|
|
|
460
460
|
```sh
|
|
461
|
-
# SQLite: persistent
|
|
461
|
+
# SQLite: private persistent API with a static operator token.
|
|
462
462
|
switcher-serve --data-dir ~/.hasna/switcher --port 8080
|
|
463
463
|
|
|
464
|
-
# PostgreSQL
|
|
464
|
+
# PostgreSQL self-hosting with the same private token:
|
|
465
465
|
switcher-serve --port 8080
|
|
466
|
+
|
|
467
|
+
# Hosted PostgreSQL: inject HASNA_SWITCHER_DATABASE_URL and
|
|
468
|
+
# HASNA_SWITCHER_API_SIGNING_KEY. Apply the terminating migration first:
|
|
469
|
+
switcher-serve migrate
|
|
470
|
+
switcher-serve --host 0.0.0.0 --port 8080
|
|
466
471
|
```
|
|
467
472
|
|
|
468
|
-
Choose exactly one backend. There is no automatic fallback.
|
|
473
|
+
Choose exactly one backend. There is no automatic fallback. SQLite HTTP hosting is an explicit switcher-specific product requirement; clients always use HTTP. Hosted signed-key mode requires PostgreSQL and refuses a SQLite path. The migration command applies the domain and API-key lifecycle schema with the owner DSN and exits. The long-running hosted service validates that exact schema with its application DSN and performs no DDL.
|
|
469
474
|
|
|
470
|
-
Set `HASNA_SWITCHER_API_URL=http://127.0.0.1:8080` for
|
|
475
|
+
Set `HASNA_SWITCHER_API_URL=http://127.0.0.1:8080` for a self-hosted client and inject its operator token. A configured client key with no URL selects `https://api.hasna.com/switcher`; remote URLs require HTTPS. A selected hosted authority that is missing, unreachable or unauthorized fails closed and never opens local SQLite. Values `0`, `false`, `no`, and `off` do not enable local mode; unknown nonblank local-flag values are rejected. The service binds loopback by default; put a TLS reverse proxy in front of an explicitly hosted listener.
|
|
471
476
|
|
|
472
477
|
For containers, build the package first, then use `docker compose --profile sqlite up --build`. For PostgreSQL, inject `SWITCHER_POSTGRES_PASSWORD` and a matching URI in `HASNA_SWITCHER_DATABASE_URL` using hostname `postgres`, database/user `switcher`; run `docker compose --profile postgres up --build`. URI-encode password characters. Choose one profile. Compose exposes only loopback port 8080 and persists named volumes.
|
|
473
478
|
|
|
@@ -489,7 +494,7 @@ The model ID is an example; choose an exact ID from the current catalog and veri
|
|
|
489
494
|
|
|
490
495
|
For Claude use `--harness claude` with `anthropic-messages`; for Grok, Hermes or OpenCode 2 use their supported protocol. Pass native arguments after `--`, such as `switcher launch coding -- exec "Reply with exactly: connected"`. `--backend direct` is the default; the optional `--backend ori` is OpenRouter-only and accepts `--ori-executable PATH`, while `--executable` remains the direct adapter option. `--cwd`, `--state-dir`, and `--timeout SECONDS` are local launcher options. Native approval and sandbox settings remain in effect. See [the Ori backend contract](https://github.com/hasna/apps/blob/main/apps/switcher/docs/ori-backend-integration.md) for its supported target and catalog boundaries.
|
|
491
496
|
|
|
492
|
-
When the API runs remotely,
|
|
497
|
+
When the API runs remotely, provider authentication and model discovery happen in the local launcher. The launcher commits the resulting validated catalog through the versioned API, then uses the same prepared credential for direct inference. The hosted service never receives or stores the provider key and refuses server-side provider refreshes; authenticated callers cannot make the hosted service contact provider URLs. An external compatible gateway can be the configured provider. Switcher does not translate between wire protocols.
|
|
493
498
|
|
|
494
499
|
## Catalog refresh and offline use
|
|
495
500
|
|
|
@@ -591,7 +596,7 @@ The SDK supports Node and Bun. It has no database or launcher imports. Explicit
|
|
|
591
596
|
|
|
592
597
|
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.
|
|
593
598
|
|
|
594
|
-
Public lifecycle endpoints: `GET /health`, `/ready`, `/version
|
|
599
|
+
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.
|
|
595
600
|
|
|
596
601
|
All mutations require `Idempotency-Key`. Reuse the same key and payload after an uncertain response; changing the payload returns 409. Updates/deletes also require the numeric record version in `If-Match`. SDK methods supply these headers and accept a caller-provided idempotency key. Run creation requires the `planToken` from a launch plan; a changed provider, profile or catalog rejects the stale plan with 409 before local execution. List endpoints accept `limit` (1–1000), `offset` and `search`. Referenced providers/profiles cannot be deleted while children exist.
|
|
597
602
|
|