@hasna/switcher 0.2.8 → 0.2.10
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 +4 -2
- package/dist/cli/index.js +197 -234
- package/dist/credentials.d.ts +2 -12
- package/dist/domain.d.ts +1 -1
- package/dist/index.js +16 -16
- package/dist/mcp/index.js +127 -90
- package/dist/opencode-authentication.d.ts +11 -0
- package/dist/sdk.js +16 -16
- package/dist/serve/index.js +13 -9
- package/dist/version.d.ts +1 -0
- package/hasna.contract.json +1 -1
- package/openapi.json +1 -1
- package/package.json +2 -2
package/dist/serve/index.js
CHANGED
|
@@ -67,9 +67,13 @@ var routingEventsSchema = z2.array(routingEventSchema).max(1000);
|
|
|
67
67
|
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
|
+
// package.json
|
|
71
|
+
var version = "0.2.10";
|
|
72
|
+
|
|
73
|
+
// src/version.ts
|
|
74
|
+
var VERSION = version;
|
|
70
75
|
|
|
71
76
|
// src/domain.ts
|
|
72
|
-
var VERSION = "0.2.7";
|
|
73
77
|
var harnessSchema = z3.enum(["claude", "codex", "grok", "opencode", "opencode2", "pi", "omp", "dsh", "cline", "hermes", "prime-agent", "gemini", "antigravity", "junie", "aider", "kilo"]);
|
|
74
78
|
var protocolSchema = z3.enum(["anthropic-messages", "openai-responses", "openai-chat", "gemini-generate-content"]);
|
|
75
79
|
var idSchema = z3.string().regex(/^[a-zA-Z0-9][a-zA-Z0-9._-]{0,79}$/);
|
|
@@ -379,8 +383,8 @@ class Store {
|
|
|
379
383
|
}
|
|
380
384
|
return value;
|
|
381
385
|
}
|
|
382
|
-
async remove(kind, id,
|
|
383
|
-
const rows = await db.unsafe(`DELETE FROM switcher_${kind} WHERE id = $1 AND version = $2 RETURNING id`, [id,
|
|
386
|
+
async remove(kind, id, version2, db) {
|
|
387
|
+
const rows = await db.unsafe(`DELETE FROM switcher_${kind} WHERE id = $1 AND version = $2 RETURNING id`, [id, version2]);
|
|
384
388
|
if (!rows.length)
|
|
385
389
|
throw new Fault(409, "version_conflict", "Entry changed or is missing; reload before retrying.");
|
|
386
390
|
return { deleted: id };
|
|
@@ -918,7 +922,7 @@ var openapi_default = {
|
|
|
918
922
|
openapi: "3.0.3",
|
|
919
923
|
info: {
|
|
920
924
|
title: "Switcher API",
|
|
921
|
-
version: "0.2.
|
|
925
|
+
version: "0.2.10",
|
|
922
926
|
description: "Authenticated provider/profile/catalog control plane. Launches run locally; the API never returns provider credentials."
|
|
923
927
|
},
|
|
924
928
|
security: [
|
|
@@ -5230,7 +5234,7 @@ function createHandler(store, authentication, providerEnv = process.env, resolve
|
|
|
5230
5234
|
}
|
|
5231
5235
|
}
|
|
5232
5236
|
const fingerprint = hash(JSON.stringify([request.method, route2, body, request.headers.get("if-match")])).toString("hex");
|
|
5233
|
-
const
|
|
5237
|
+
const version2 = () => {
|
|
5234
5238
|
const v = request.headers.get("if-match");
|
|
5235
5239
|
if (!v || !/^[1-9]\d*$/.test(v))
|
|
5236
5240
|
throw new Fault(428, "version_required", "Supply the current numeric version in If-Match.");
|
|
@@ -5250,7 +5254,7 @@ function createHandler(store, authentication, providerEnv = process.env, resolve
|
|
|
5250
5254
|
const result = await store.mutate(key, fingerprint, async (db) => {
|
|
5251
5255
|
if ((resource === "providers" || resource === "profiles") && parts.length <= 3) {
|
|
5252
5256
|
if (request.method === "DELETE" && id2)
|
|
5253
|
-
return store.remove(resource, id2,
|
|
5257
|
+
return store.remove(resource, id2, version2(), db);
|
|
5254
5258
|
if (request.method === "POST" && !id2 || request.method === "PUT" && id2) {
|
|
5255
5259
|
const value = resource === "providers" ? parse(providerInputSchema, body) : parse(profileInputSchema, body);
|
|
5256
5260
|
if (id2 && value.id !== id2)
|
|
@@ -5260,7 +5264,7 @@ function createHandler(store, authentication, providerEnv = process.env, resolve
|
|
|
5260
5264
|
const provider = await store.get("providers", profile.providerId, db);
|
|
5261
5265
|
validateHarnessProvider(profile.harness, provider);
|
|
5262
5266
|
}
|
|
5263
|
-
const saved = await store.put(resource, value, id2 ?
|
|
5267
|
+
const saved = await store.put(resource, value, id2 ? version2() : undefined, db);
|
|
5264
5268
|
if (resource === "providers" && id2)
|
|
5265
5269
|
await db.unsafe("DELETE FROM switcher_catalogs WHERE id = $1", [id2]);
|
|
5266
5270
|
return saved;
|
|
@@ -5287,7 +5291,7 @@ function createHandler(store, authentication, providerEnv = process.env, resolve
|
|
|
5287
5291
|
if (store.engine === "postgresql")
|
|
5288
5292
|
await db.unsafe("SELECT id FROM switcher_providers WHERE id = $1 FOR UPDATE", [id2]);
|
|
5289
5293
|
const provider = await store.get("providers", id2, db);
|
|
5290
|
-
if (provider.version !==
|
|
5294
|
+
if (provider.version !== version2())
|
|
5291
5295
|
throw new Fault(409, "provider_changed", "Provider changed during local discovery; refresh again.");
|
|
5292
5296
|
const catalog = parse(catalogSchema, body);
|
|
5293
5297
|
const expectedSource = provider.manualModels.length ? "manual" : "remote";
|
|
@@ -5367,7 +5371,7 @@ function createHandler(store, authentication, providerEnv = process.env, resolve
|
|
|
5367
5371
|
const run = await store.get("runs", id2, db);
|
|
5368
5372
|
if (run.status !== "running")
|
|
5369
5373
|
throw new Fault(409, "run_finished", "Run has already finished.");
|
|
5370
|
-
return store.put("runs", { ...run, ...input, endedAt: new Date().toISOString() },
|
|
5374
|
+
return store.put("runs", { ...run, ...input, endedAt: new Date().toISOString() }, version2(), db);
|
|
5371
5375
|
}
|
|
5372
5376
|
throw new Fault(404, "not_found", "Route was not found.");
|
|
5373
5377
|
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const VERSION: string;
|
package/hasna.contract.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"name": "switcher",
|
|
5
5
|
"class": "cli-with-store",
|
|
6
6
|
"contractVersion": "v1",
|
|
7
|
-
"kitVersion": "1.0
|
|
7
|
+
"kitVersion": "1.3.0",
|
|
8
8
|
"description": "Universal provider and model switcher with API-first local and hosted operation. CLI, MCP and SDK resolve one authenticated HTTP authority through @hasna/contracts and fail closed when hosted configuration is missing or invalid. HASNA_SWITCHER_LOCAL=1 deliberately selects an owned loopback API backed by SQLite; hosted https://api.hasna.com/switcher uses PostgreSQL and signed revocable API keys. Provider credentials remain local to the launcher and are never stored or returned by the service.",
|
|
9
9
|
"bins": [
|
|
10
10
|
"switcher",
|
package/openapi.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hasna/switcher",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.10",
|
|
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",
|
|
@@ -72,7 +72,7 @@
|
|
|
72
72
|
"@types/pg": "8.23.1"
|
|
73
73
|
},
|
|
74
74
|
"dependencies": {
|
|
75
|
-
"@hasna/contracts": "1.0
|
|
75
|
+
"@hasna/contracts": "1.3.0",
|
|
76
76
|
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
77
77
|
"jsonc-parser": "3.3.1",
|
|
78
78
|
"yaml": "2.9.0",
|