@hasna/switcher 0.1.9 → 0.2.1

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.
@@ -0,0 +1,30 @@
1
+ type Wire = "messages" | "chat" | "responses" | "gemini";
2
+ type Json = Record<string, any>;
3
+ export type OpenCodeTranslationState = Map<string, string>;
4
+ /** OpenCode owns these two prefixes; custom URLs never inherit this adapter. */
5
+ export declare function openCodeLane(baseUrl: string): "zen" | "go" | undefined;
6
+ /** Native endpoint families documented by OpenCode, not a frozen model list.
7
+ * Their default OpenAI-compatible adapter serves the remaining model families.
8
+ * https://opencode.ai/docs/zen/ and https://opencode.ai/docs/go/
9
+ */
10
+ export declare function openCodeWire(model: string, lane: "zen" | "go"): Wire;
11
+ /** Forward only conversation identifiers, never arbitrary client headers.
12
+ * Switcher identifies itself honestly even when a native user agent is absent.
13
+ */
14
+ export declare function openCodeHeaders(baseUrl: string, source: Headers, body: Json, launchSession: string): Record<string, string>;
15
+ export declare function prepareOpenCodeMessages(baseUrl: string, body: Json, suffix: string, credential?: string, state?: OpenCodeTranslationState): {
16
+ path: string;
17
+ body: Json;
18
+ auth: {
19
+ "x-goog-api-key": string;
20
+ authorization?: undefined;
21
+ } | {
22
+ authorization: string;
23
+ "x-goog-api-key"?: undefined;
24
+ } | {
25
+ "x-goog-api-key"?: undefined;
26
+ authorization?: undefined;
27
+ };
28
+ response(response: Response): Promise<Response>;
29
+ } | undefined;
30
+ export {};
@@ -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>;
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.js CHANGED
@@ -234,6 +234,11 @@ var preset = (id, name, protocols, sources, alias) => parse(providerPresetSchema
234
234
  verification: "documented"
235
235
  });
236
236
  var providerPresets = [
237
+ ...["opencode", "opencode-go"].map((id) => preset(id, id === "opencode" ? "OpenCode Zen" : "OpenCode Go", ["openai-chat", "openai-responses", "anthropic-messages"].map((protocol) => route(protocol, id === "opencode" ? "https://opencode.ai/zen/v1" : "https://opencode.ai/zen/go/v1", {
238
+ authStyle: protocol === "anthropic-messages" ? "x-api-key" : "bearer",
239
+ catalogAuthStyle: "none",
240
+ notes: ["Discovers the full live catalog. Claude requests are adapted to each model's documented native endpoint. Other harnesses require models compatible with their selected protocol. Go requires an active subscription and coding-agent session headers."]
241
+ })), ["https://opencode.ai/docs/zen/", "https://opencode.ai/docs/go/"], "OPENCODE_API_KEY")),
237
242
  preset("deepseek", "DeepSeek", [
238
243
  route("openai-chat", "https://api.deepseek.com", { catalogBaseUrl: "https://api.deepseek.com" }),
239
244
  route("openai-responses", "https://api.deepseek.com", { catalogBaseUrl: "https://api.deepseek.com" }),
@@ -67,7 +67,7 @@ function canonicalPolicyJSON(value) {
67
67
  }
68
68
 
69
69
  // src/domain.ts
70
- var VERSION = "0.1.9";
70
+ var VERSION = "0.2.1";
71
71
  var harnessSchema = z3.enum(["claude", "codex", "grok", "opencode", "opencode2", "pi", "omp", "dsh", "cline", "hermes", "prime-agent", "gemini", "aider", "kilo"]);
72
72
  var protocolSchema = z3.enum(["anthropic-messages", "openai-responses", "openai-chat", "gemini-generate-content"]);
73
73
  var idSchema = z3.string().regex(/^[a-zA-Z0-9][a-zA-Z0-9._-]{0,79}$/);
@@ -486,7 +486,7 @@ async function discoverBase(provider, env = process.env, resolveCredential) {
486
486
  return { models: provider.manualModels, source: "manual", refreshedAt };
487
487
  if (provider.catalogFormat === "none")
488
488
  throw new Fault(422, "catalog_unsupported", "This provider has no documented model-list contract; configure manual models or an explicit catalog URL and parser.");
489
- const headers = { accept: "application/json" };
489
+ const headers = { accept: "application/json", "user-agent": `hasna-switcher/${VERSION}` };
490
490
  if (provider.catalogFormat === "fireworks" && !provider.catalogBaseUrl && !provider.catalogAccountId)
491
491
  throw new Fault(422, "catalog_account_required", "Fireworks model discovery requires a catalog account ID or an explicit catalog URL.");
492
492
  if (provider.catalogFormat === "fireworks" && !provider.catalogBaseUrl && new URL(provider.baseUrl).origin !== "https://api.fireworks.ai")
@@ -545,6 +545,7 @@ async function discoverBase(provider, env = process.env, resolveCredential) {
545
545
  inputModalities: strings(row.architecture?.input_modalities ?? row.input_modalities) ?? modalities(row.inference_metadata?.request_modality),
546
546
  outputModalities: strings(row.architecture?.output_modalities ?? row.output_modalities) ?? modalities(row.inference_metadata?.response_modality),
547
547
  supportedParameters: strings(row.supported_parameters),
548
+ reasoningEfforts: row.reasoning?.supported_efforts,
548
549
  ...provider.catalogFormat === "gemini" && row.supportedGenerationMethods !== undefined ? { supportedGenerationMethods: row.supportedGenerationMethods } : {}
549
550
  };
550
551
  if (provider.catalogFormat === "mistral") {
@@ -761,6 +762,11 @@ var preset = (id2, name, protocols, sources, alias) => parse(providerPresetSchem
761
762
  verification: "documented"
762
763
  });
763
764
  var providerPresets = [
765
+ ...["opencode", "opencode-go"].map((id2) => preset(id2, id2 === "opencode" ? "OpenCode Zen" : "OpenCode Go", ["openai-chat", "openai-responses", "anthropic-messages"].map((protocol) => route(protocol, id2 === "opencode" ? "https://opencode.ai/zen/v1" : "https://opencode.ai/zen/go/v1", {
766
+ authStyle: protocol === "anthropic-messages" ? "x-api-key" : "bearer",
767
+ catalogAuthStyle: "none",
768
+ notes: ["Discovers the full live catalog. Claude requests are adapted to each model's documented native endpoint. Other harnesses require models compatible with their selected protocol. Go requires an active subscription and coding-agent session headers."]
769
+ })), ["https://opencode.ai/docs/zen/", "https://opencode.ai/docs/go/"], "OPENCODE_API_KEY")),
764
770
  preset("deepseek", "DeepSeek", [
765
771
  route("openai-chat", "https://api.deepseek.com", { catalogBaseUrl: "https://api.deepseek.com" }),
766
772
  route("openai-responses", "https://api.deepseek.com", { catalogBaseUrl: "https://api.deepseek.com" }),
@@ -837,7 +843,7 @@ var openapi_default = {
837
843
  openapi: "3.0.3",
838
844
  info: {
839
845
  title: "Switcher API",
840
- version: "0.1.9",
846
+ version: "0.2.1",
841
847
  description: "Authenticated provider/profile/catalog control plane. Launches run locally; the API never returns provider credentials."
842
848
  },
843
849
  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.1.9",
5
+ "version": "0.2.1",
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.1.9",
3
+ "version": "0.2.1",
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",
@@ -60,7 +60,9 @@
60
60
  "test:native-opencode-legacy": "bun scripts/test-native-opencode-legacy.ts",
61
61
  "test:native-kilo": "bun scripts/test-native-kilo.ts",
62
62
  "test:native-kilo-lifecycle": "bun scripts/test-native-kilo-lifecycle.ts",
63
- "test:native-chatgpt-runtime": "bun scripts/test-native-chatgpt-runtime.ts"
63
+ "test:native-chatgpt-runtime": "bun scripts/test-native-chatgpt-runtime.ts",
64
+ "test:native-chatgpt-tools": "bun scripts/test-native-chatgpt-tools.ts",
65
+ "test:native-claude-providers": "bun scripts/test-native-claude-providers.ts"
64
66
  },
65
67
  "devDependencies": {
66
68
  "@types/bun": "1.3.14",
@@ -77,7 +79,7 @@
77
79
  },
78
80
  "repository": {
79
81
  "type": "git",
80
- "url": "git+https://github.com/hasna/apps.git",
82
+ "url": "https://github.com/hasna/apps.git",
81
83
  "directory": "apps/switcher"
82
84
  },
83
85
  "homepage": "https://github.com/hasna/apps/tree/main/apps/switcher",