@hasna/switcher 0.2.23 → 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/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.23";
19498
+ var version2 = "0.2.25";
19499
19499
 
19500
19500
  // src/version.ts
19501
19501
  var VERSION = version2;
@@ -20767,6 +20767,27 @@ class HasnaHttpError extends Error {
20767
20767
  this.credentialTier = credential?.tier ?? null;
20768
20768
  }
20769
20769
  }
20770
+ var DEFAULT_MAX_RESPONSE_BYTES = 16 * 1024 * 1024;
20771
+ var MAX_RESPONSE_BYTES_ENV_KEY = "HASNA_CONTRACTS_MAX_RESPONSE_BYTES";
20772
+
20773
+ class ContractResponseTooLargeError extends Error {
20774
+ code = "CONTRACT_RESPONSE_TOO_LARGE";
20775
+ method;
20776
+ path;
20777
+ status;
20778
+ limitBytes;
20779
+ observedBytes;
20780
+ constructor(method, path, status, limitBytes, observedBytes, refusedBy) {
20781
+ const observed = refusedBy === "content-length" ? `Content-Length declared ${observedBytes} bytes` : `received ${observedBytes} bytes`;
20782
+ super(`Hasna cloud response exceeded the transport limit: ${method} ${path} -> ${status} ` + `(${observed}; limit ${limitBytes} bytes). The response body was cancelled and not parsed.`);
20783
+ this.name = "ContractResponseTooLargeError";
20784
+ this.method = method;
20785
+ this.path = path;
20786
+ this.status = status;
20787
+ this.limitBytes = limitBytes;
20788
+ this.observedBytes = observedBytes;
20789
+ }
20790
+ }
20770
20791
  function currentCredential(name, apiKey) {
20771
20792
  if (typeof apiKey === "function") {
20772
20793
  return validateAndSealResolvedCredential(name, apiKey());
@@ -20835,12 +20856,86 @@ function appendQuery(path, query) {
20835
20856
  return `${path}${path.includes("?") ? "&" : "?"}${qs}`;
20836
20857
  }
20837
20858
  var defaultSleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
20838
- function createHasnaHttpTransportInternal(options, requestBindingProvider) {
20859
+ function invalidMaxResponseBytes(name, source) {
20860
+ return new ClientTransportConfigurationError(name, `${source} must be a positive integer number of bytes no greater than ${Number.MAX_SAFE_INTEGER}; ` + "refusing to build a client with an invalid response size cap.", source === MAX_RESPONSE_BYTES_ENV_KEY ? [MAX_RESPONSE_BYTES_ENV_KEY] : []);
20861
+ }
20862
+ function resolveMaxResponseBytes(name, explicit, env) {
20863
+ if (explicit !== undefined) {
20864
+ if (!Number.isSafeInteger(explicit) || explicit < 1) {
20865
+ throw invalidMaxResponseBytes(name, "The maxResponseBytes option");
20866
+ }
20867
+ return explicit;
20868
+ }
20869
+ const descriptor = Object.getOwnPropertyDescriptor(env, MAX_RESPONSE_BYTES_ENV_KEY);
20870
+ if (!descriptor)
20871
+ return DEFAULT_MAX_RESPONSE_BYTES;
20872
+ if (!("value" in descriptor)) {
20873
+ throw new ClientTransportConfigurationError(name, `${MAX_RESPONSE_BYTES_ENV_KEY} is accessor-backed; client configuration requires own data properties.`, [MAX_RESPONSE_BYTES_ENV_KEY]);
20874
+ }
20875
+ if (descriptor.value === undefined)
20876
+ return DEFAULT_MAX_RESPONSE_BYTES;
20877
+ if (typeof descriptor.value !== "string") {
20878
+ throw new ClientTransportConfigurationError(name, `${MAX_RESPONSE_BYTES_ENV_KEY} must be a string data property.`, [MAX_RESPONSE_BYTES_ENV_KEY]);
20879
+ }
20880
+ const raw = descriptor.value;
20881
+ if (raw.trim().length === 0) {
20882
+ throw new ClientTransportConfigurationError(name, `${MAX_RESPONSE_BYTES_ENV_KEY} is set but blank; unset it for the ${DEFAULT_MAX_RESPONSE_BYTES}-byte ` + "default or set a positive decimal byte count.", [MAX_RESPONSE_BYTES_ENV_KEY]);
20883
+ }
20884
+ const parsed = /^[1-9][0-9]*$/.test(raw) ? Number(raw) : Number.NaN;
20885
+ if (!Number.isSafeInteger(parsed)) {
20886
+ throw invalidMaxResponseBytes(name, MAX_RESPONSE_BYTES_ENV_KEY);
20887
+ }
20888
+ return parsed;
20889
+ }
20890
+ function declaredContentLength(response) {
20891
+ const raw = response.headers.get("content-length");
20892
+ if (raw === null)
20893
+ return null;
20894
+ const trimmed = raw.trim();
20895
+ if (!/^[0-9]+$/.test(trimmed))
20896
+ return null;
20897
+ const value = Number(trimmed);
20898
+ return Number.isSafeInteger(value) ? value : Number.MAX_SAFE_INTEGER;
20899
+ }
20900
+ async function cancelReader(reader) {
20901
+ try {
20902
+ await reader.cancel();
20903
+ } catch {}
20904
+ }
20905
+ async function readResponseTextWithinLimit(response, limitBytes) {
20906
+ const body = response.body;
20907
+ if (!body)
20908
+ return { ok: true, text: "" };
20909
+ const reader = body.getReader();
20910
+ const decoder = new TextDecoder;
20911
+ const parts = [];
20912
+ let received = 0;
20913
+ try {
20914
+ for (;; ) {
20915
+ const { done, value } = await reader.read();
20916
+ if (done)
20917
+ break;
20918
+ received += value.byteLength;
20919
+ if (received > limitBytes) {
20920
+ await cancelReader(reader);
20921
+ return { ok: false, observedBytes: received };
20922
+ }
20923
+ parts.push(decoder.decode(value, { stream: true }));
20924
+ }
20925
+ parts.push(decoder.decode());
20926
+ return { ok: true, text: parts.join("") };
20927
+ } catch (error62) {
20928
+ await cancelReader(reader);
20929
+ throw error62;
20930
+ }
20931
+ }
20932
+ function createHasnaHttpTransportInternal(options, requestBindingProvider, env = process.env) {
20839
20933
  const fetchImpl = options.fetchImpl ?? ((input2, init) => fetch(input2, init));
20840
20934
  const base = toV1BaseUrl(options.baseUrl);
20841
20935
  const timeoutMs = options.timeoutMs ?? 30000;
20842
20936
  const sleep = options.sleepImpl ?? defaultSleep;
20843
20937
  const defaultRetry = options.retry;
20938
+ const maxResponseBytes = resolveMaxResponseBytes(options.name, options.maxResponseBytes, env);
20844
20939
  function resolveRetry(callRetry) {
20845
20940
  const chosen = callRetry !== undefined ? callRetry : defaultRetry;
20846
20941
  if (chosen === false)
@@ -20917,12 +21012,31 @@ function createHasnaHttpTransportInternal(options, requestBindingProvider) {
20917
21012
  await response.body?.cancel();
20918
21013
  } catch {}
20919
21014
  } else {
20920
- const text = await response.text();
20921
- if (text.length > 0) {
21015
+ const streamingBody = response.body;
21016
+ const declaredBytes = streamingBody ? declaredContentLength(response) : null;
21017
+ if (declaredBytes !== null && declaredBytes > maxResponseBytes) {
21018
+ try {
21019
+ await streamingBody?.cancel();
21020
+ } catch {}
21021
+ return {
21022
+ ok: false,
21023
+ retryable: false,
21024
+ error: new ContractResponseTooLargeError(method, rel, response.status, maxResponseBytes, declaredBytes, "content-length")
21025
+ };
21026
+ }
21027
+ const bounded = await readResponseTextWithinLimit(response, maxResponseBytes);
21028
+ if (!bounded.ok) {
21029
+ return {
21030
+ ok: false,
21031
+ retryable: false,
21032
+ error: new ContractResponseTooLargeError(method, rel, response.status, maxResponseBytes, bounded.observedBytes, "stream")
21033
+ };
21034
+ }
21035
+ if (bounded.text.length > 0) {
20922
21036
  try {
20923
- parsed = JSON.parse(text);
21037
+ parsed = JSON.parse(bounded.text);
20924
21038
  } catch {
20925
- parsed = text;
21039
+ parsed = bounded.text;
20926
21040
  }
20927
21041
  }
20928
21042
  }
@@ -20995,6 +21109,7 @@ function createHasnaHttpTransportInternal(options, requestBindingProvider) {
20995
21109
  function createClientTransport(name, env = process.env, overrides) {
20996
21110
  const snapshotOptions = snapshotResolveClientTransportOptions(overrides ?? {});
20997
21111
  const resolution = resolveClientTransportSnapshot(name, env, snapshotOptions).resolution;
21112
+ const maxResponseBytes = overrides?.maxResponseBytes;
20998
21113
  const sameBinding = (left, right) => left.resolution.baseUrl === right.resolution.baseUrl && left.credential.apiKey === right.credential.apiKey && left.credential.pointerVaultKey === right.credential.pointerVaultKey && left.credential.source === right.credential.source && left.credential.tier === right.credential.tier;
20999
21114
  const unstableConfiguration = () => new ClientTransportConfigurationError(name, "The configured service authority or credential changed while a request was being prepared; no authenticated request was sent.");
21000
21115
  const assertPinnedAuthority = (snapshot) => {
@@ -21034,9 +21149,10 @@ function createClientTransport(name, env = process.env, overrides) {
21034
21149
  ...overrides?.fetchImpl ? { fetchImpl: overrides.fetchImpl } : {},
21035
21150
  ...overrides?.headers ? { headers: overrides.headers } : {},
21036
21151
  ...overrides?.timeoutMs ? { timeoutMs: overrides.timeoutMs } : {},
21152
+ ...maxResponseBytes !== undefined ? { maxResponseBytes } : {},
21037
21153
  ...overrides?.retry !== undefined ? { retry: overrides.retry } : {},
21038
21154
  ...overrides?.sleepImpl ? { sleepImpl: overrides.sleepImpl } : {}
21039
- }, requestBindingProvider),
21155
+ }, requestBindingProvider, env),
21040
21156
  resolution
21041
21157
  };
21042
21158
  }
@@ -21227,16 +21343,38 @@ function apiError(status, data, apiKey) {
21227
21343
  const message = typeof error62.message === "string" && error62.message.length <= 4096 ? redact(error62.message).replace(/[\x00-\x1f\x7f-\x9f]/g, " ").trim().slice(0, 2048) || fallback : fallback;
21228
21344
  return new SwitcherError(status, code, message, requestId);
21229
21345
  }
21346
+ var DEFAULT_RETRIES = 3;
21347
+ var DEFAULT_RETRY_BASE_MS = 200;
21348
+ var DEFAULT_RETRY_MAX_MS = 2000;
21349
+ var RETRIES_LIMIT = 5;
21350
+ var RETRY_DELAY_LIMIT_MS = 1e4;
21351
+ function retryPolicy(options) {
21352
+ if (options === false)
21353
+ return;
21354
+ const whole = (value, fallback, minimum) => value !== undefined && Number.isFinite(value) ? Math.max(minimum, Math.floor(value)) : fallback;
21355
+ return {
21356
+ retries: Math.min(whole(options?.retries, DEFAULT_RETRIES, 0), RETRIES_LIMIT),
21357
+ baseDelayMs: Math.min(whole(options?.baseDelayMs, DEFAULT_RETRY_BASE_MS, 0), RETRY_DELAY_LIMIT_MS),
21358
+ maxDelayMs: Math.min(whole(options?.maxDelayMs, DEFAULT_RETRY_MAX_MS, 0), RETRY_DELAY_LIMIT_MS),
21359
+ sleep: options?.sleep ?? ((milliseconds) => new Promise((resolve) => setTimeout(resolve, milliseconds)))
21360
+ };
21361
+ }
21362
+ function edgeFailure(error62) {
21363
+ return error62 instanceof SwitcherError && (error62.status === 503 || error62.status >= 500 && error62.code === "invalid_response");
21364
+ }
21365
+ var operationKey = (supplied) => supplied ?? crypto.randomUUID();
21230
21366
 
21231
21367
  class SwitcherClient {
21232
21368
  options;
21233
21369
  transport;
21370
+ retry;
21234
21371
  baseUrl;
21235
21372
  constructor(options) {
21236
21373
  this.baseUrl = endpoint(options.baseUrl).replace(/\/v1$/, "");
21237
21374
  if (typeof options.apiKey === "string" && (!options.apiKey || /[\r\n]/.test(options.apiKey)))
21238
21375
  throw new Error("Switcher API key is required.");
21239
21376
  this.options = { ...options };
21377
+ this.retry = retryPolicy(options.retry);
21240
21378
  }
21241
21379
  static fromEnvironment(env = process.env, options = {}) {
21242
21380
  const shared = createClientTransport("switcher", env, {
@@ -21271,15 +21409,30 @@ class SwitcherClient {
21271
21409
  throw new Error("Shared credential transport was not invoked.");
21272
21410
  } });
21273
21411
  client.transport = shared.client;
21412
+ client.retry = retryPolicy(options.retry);
21274
21413
  return client;
21275
21414
  }
21276
21415
  async request(method, path, body, options = {}) {
21277
21416
  if (!/^\/v1\/[a-zA-Z0-9/?&=._%+-]+$/.test(path) && !["/health", "/ready", "/version"].includes(path) || path.includes(".."))
21278
21417
  throw new Error("Invalid API path.");
21418
+ const key = method === "GET" ? undefined : options.idempotencyKey ?? crypto.randomUUID();
21419
+ const policy = method === "GET" || options.idempotencyKey !== undefined ? this.retry : undefined;
21420
+ for (let attempt = 0;; attempt++) {
21421
+ try {
21422
+ return await this.send(method, path, body, options.version, key);
21423
+ } catch (error62) {
21424
+ if (!policy || attempt >= policy.retries || !edgeFailure(error62))
21425
+ throw error62;
21426
+ const delay = policy.baseDelayMs * 2 ** attempt;
21427
+ await policy.sleep(Math.min(policy.maxDelayMs, delay + Math.floor(Math.random() * (delay / 2 + 1))));
21428
+ }
21429
+ }
21430
+ }
21431
+ async send(method, path, body, version3, idempotencyKey) {
21279
21432
  if (this.transport)
21280
21433
  return this.transport.request(method, path.startsWith("/v1/") ? path.slice(3) : path, body, {
21281
- idempotencyKey: method === "GET" ? undefined : options.idempotencyKey ?? crypto.randomUUID(),
21282
- headers: options.version === undefined ? undefined : { "if-match": String(options.version) },
21434
+ idempotencyKey,
21435
+ headers: version3 === undefined ? undefined : { "if-match": String(version3) },
21283
21436
  retry: false
21284
21437
  });
21285
21438
  const apiKey = typeof this.options.apiKey === "function" ? this.options.apiKey() : this.options.apiKey;
@@ -21288,10 +21441,10 @@ class SwitcherClient {
21288
21441
  const headers = { authorization: `Bearer ${apiKey}`, accept: "application/json" };
21289
21442
  if (body !== undefined)
21290
21443
  headers["content-type"] = "application/json";
21291
- if (method !== "GET")
21292
- headers["idempotency-key"] = options.idempotencyKey ?? crypto.randomUUID();
21293
- if (options.version !== undefined)
21294
- headers["if-match"] = String(options.version);
21444
+ if (idempotencyKey !== undefined)
21445
+ headers["idempotency-key"] = idempotencyKey;
21446
+ if (version3 !== undefined)
21447
+ headers["if-match"] = String(version3);
21295
21448
  let response;
21296
21449
  try {
21297
21450
  response = await (this.options.fetch ?? fetch)(`${this.baseUrl}${path}`, { method, headers, body: body === undefined ? undefined : JSON.stringify(body), redirect: "manual", signal: AbortSignal.timeout(this.options.timeoutMs ?? 120000) });
@@ -21333,13 +21486,13 @@ class SwitcherClient {
21333
21486
  return this.request("GET", `/v1/providers/${encodeURIComponent(id)}`);
21334
21487
  }
21335
21488
  createProvider(input2, idempotencyKey) {
21336
- return this.request("POST", "/v1/providers", input2, { idempotencyKey });
21489
+ return this.request("POST", "/v1/providers", input2, { idempotencyKey: operationKey(idempotencyKey) });
21337
21490
  }
21338
21491
  updateProvider(input2, version3, idempotencyKey) {
21339
- return this.request("PUT", `/v1/providers/${encodeURIComponent(input2.id)}`, input2, { version: version3, idempotencyKey });
21492
+ return this.request("PUT", `/v1/providers/${encodeURIComponent(input2.id)}`, input2, { version: version3, idempotencyKey: operationKey(idempotencyKey) });
21340
21493
  }
21341
21494
  deleteProvider(id, version3, idempotencyKey) {
21342
- return this.request("DELETE", `/v1/providers/${encodeURIComponent(id)}`, undefined, { version: version3, idempotencyKey });
21495
+ return this.request("DELETE", `/v1/providers/${encodeURIComponent(id)}`, undefined, { version: version3, idempotencyKey: operationKey(idempotencyKey) });
21343
21496
  }
21344
21497
  async editModel(providerId, operation, value) {
21345
21498
  const model = typeof value === "string" ? undefined : parse5(modelSchema, value);
@@ -21369,10 +21522,10 @@ class SwitcherClient {
21369
21522
  return this.editModel(providerId, "remove", modelId);
21370
21523
  }
21371
21524
  refreshModels(id, idempotencyKey) {
21372
- return this.request("POST", `/v1/providers/${encodeURIComponent(id)}/refresh`, {}, { idempotencyKey });
21525
+ return this.request("POST", `/v1/providers/${encodeURIComponent(id)}/refresh`, {}, { idempotencyKey: operationKey(idempotencyKey) });
21373
21526
  }
21374
21527
  saveCatalog(id, providerVersion, catalog, idempotencyKey) {
21375
- return this.request("PUT", `/v1/providers/${encodeURIComponent(id)}/catalog`, catalog, { version: providerVersion, idempotencyKey });
21528
+ return this.request("PUT", `/v1/providers/${encodeURIComponent(id)}/catalog`, catalog, { version: providerVersion, idempotencyKey: operationKey(idempotencyKey) });
21376
21529
  }
21377
21530
  listModels(id, options = {}) {
21378
21531
  return this.request("GET", `/v1/providers/${encodeURIComponent(id)}/models?${this.query(options)}`);
@@ -21384,16 +21537,16 @@ class SwitcherClient {
21384
21537
  return this.request("GET", `/v1/profiles/${encodeURIComponent(id)}`);
21385
21538
  }
21386
21539
  createProfile(input2, idempotencyKey) {
21387
- return this.request("POST", "/v1/profiles", input2, { idempotencyKey });
21540
+ return this.request("POST", "/v1/profiles", input2, { idempotencyKey: operationKey(idempotencyKey) });
21388
21541
  }
21389
21542
  updateProfile(input2, version3, idempotencyKey) {
21390
- return this.request("PUT", `/v1/profiles/${encodeURIComponent(input2.id)}`, input2, { version: version3, idempotencyKey });
21543
+ return this.request("PUT", `/v1/profiles/${encodeURIComponent(input2.id)}`, input2, { version: version3, idempotencyKey: operationKey(idempotencyKey) });
21391
21544
  }
21392
21545
  deleteProfile(id, version3, idempotencyKey) {
21393
- return this.request("DELETE", `/v1/profiles/${encodeURIComponent(id)}`, undefined, { version: version3, idempotencyKey });
21546
+ return this.request("DELETE", `/v1/profiles/${encodeURIComponent(id)}`, undefined, { version: version3, idempotencyKey: operationKey(idempotencyKey) });
21394
21547
  }
21395
21548
  launchPlan(profileId, idempotencyKey) {
21396
- return this.request("POST", "/v1/launch-plans", { profileId }, { idempotencyKey });
21549
+ return this.request("POST", "/v1/launch-plans", { profileId }, { idempotencyKey: operationKey(idempotencyKey) });
21397
21550
  }
21398
21551
  listRuns(options = {}) {
21399
21552
  return this.request("GET", `/v1/runs?${this.query(options)}`);
@@ -21402,10 +21555,10 @@ class SwitcherClient {
21402
21555
  return this.request("GET", `/v1/runs/${encodeURIComponent(id)}`);
21403
21556
  }
21404
21557
  createRun(input2, idempotencyKey) {
21405
- return this.request("POST", "/v1/runs", { ...input2, modelPolicyVersion: 1 }, { idempotencyKey });
21558
+ return this.request("POST", "/v1/runs", { ...input2, modelPolicyVersion: 1 }, { idempotencyKey: operationKey(idempotencyKey) });
21406
21559
  }
21407
21560
  finishRun(id, version3, input2, idempotencyKey) {
21408
- return this.request("PATCH", `/v1/runs/${encodeURIComponent(id)}`, input2, { version: version3, idempotencyKey });
21561
+ return this.request("PATCH", `/v1/runs/${encodeURIComponent(id)}`, input2, { version: version3, idempotencyKey: operationKey(idempotencyKey) });
21409
21562
  }
21410
21563
  }
21411
21564
  function clientFromEnv(env = process.env, options = {}) {
@@ -22579,7 +22732,7 @@ var openapi_default = {
22579
22732
  openapi: "3.0.3",
22580
22733
  info: {
22581
22734
  title: "Switcher API",
22582
- version: "0.2.23",
22735
+ version: "0.2.25",
22583
22736
  description: "Authenticated provider/profile/catalog control plane. Launches run locally; the API never returns provider credentials."
22584
22737
  },
22585
22738
  security: [
@@ -1,2 +1,25 @@
1
+ /** The most of a provider error body the gateway reads to explain a rejection. */
2
+ export declare const MAX_UPSTREAM_ERROR_BYTES: number;
3
+ /** The longest provider error message the gateway passes on or logs. */
4
+ export declare const MAX_UPSTREAM_ERROR_MESSAGE = 300;
5
+ /** What a provider said when it refused a request: redacted, bounded, never the raw body. */
6
+ export type UpstreamError = {
7
+ overflow: boolean;
8
+ type?: string;
9
+ message?: string;
10
+ };
11
+ /**
12
+ * Replace anything credential-shaped: the launch's own credential, bearer and key assignments,
13
+ * well-known key prefixes, JWTs and long mixed token runs. URLs keep only their origin and path.
14
+ */
15
+ export declare function redactCredentials(text: string, known?: readonly (string | undefined)[]): string;
16
+ /** The type every credential-shaped error type is replaced with. */
17
+ export declare const REDACTED_ERROR_TYPE = "provider_error";
18
+ /**
19
+ * Read a refused response's error once: whether it is a context overflow, and the provider's error
20
+ * type and message, redacted and bounded. Anthropic ({type:"error",error:{type,message}}), OpenAI
21
+ * ({error:{type,code,message}}), Gemini ({error:{status,message}}) and plain-text bodies are read.
22
+ */
23
+ export declare function readUpstreamError(response: Response, known?: readonly (string | undefined)[]): Promise<UpstreamError>;
1
24
  /** Only classify known structured failures. Provider text never leaves this boundary. */
2
25
  export declare function isContextOverflow(response: Response): Promise<boolean>;
package/dist/sdk.d.ts CHANGED
@@ -26,28 +26,43 @@ export declare class SwitcherError extends Error {
26
26
  requestId?: string | undefined;
27
27
  constructor(status: number, code: string, message: string, requestId?: string | undefined);
28
28
  }
29
+ /** Bounded retry for the transient failures an edge in front of the API produces. */
30
+ export type RetryOptions = {
31
+ retries?: number;
32
+ baseDelayMs?: number;
33
+ maxDelayMs?: number;
34
+ sleep?: (milliseconds: number) => Promise<void>;
35
+ };
29
36
  export type ClientOptions = {
30
37
  baseUrl: string;
31
38
  apiKey: string | (() => string);
32
39
  fetch?: typeof fetch;
33
40
  timeoutMs?: number;
41
+ retry?: RetryOptions | false;
34
42
  };
35
43
  export type EnvironmentClientOptions = {
36
44
  credentials?: CredentialChainOptions;
37
45
  fetch?: typeof fetch;
38
46
  timeoutMs?: number;
47
+ retry?: RetryOptions | false;
39
48
  };
40
49
  export declare class SwitcherClient {
41
50
  private readonly options;
42
51
  private transport?;
52
+ private retry?;
43
53
  readonly baseUrl: string;
44
54
  constructor(options: ClientOptions);
45
55
  /** Use Contracts' paired authority/credential resolution on every request. */
46
56
  static fromEnvironment(env?: Record<string, string | undefined>, options?: EnvironmentClientOptions): SwitcherClient;
57
+ /** Sends one request, retrying only the edge failure shapes above, a bounded number of times with
58
+ * exponential backoff. A GET is retried. A write is retried only when the caller supplied its
59
+ * idempotency key, and every attempt carries that same key, so the server replays the stored result
60
+ * instead of repeating the write. Calls with no supplied key get a fresh key and are sent once. */
47
61
  request<T>(method: string, path: string, body?: unknown, options?: {
48
62
  version?: number;
49
63
  idempotencyKey?: string;
50
64
  }): Promise<T>;
65
+ private send;
51
66
  private query;
52
67
  health(): Promise<{
53
68
  status: "ok" | "degraded" | "unavailable";
@@ -514,7 +529,9 @@ export declare class SwitcherClient {
514
529
  aliases?: {
515
530
  [key: string]: string;
516
531
  };
517
- fallbacks?: {
532
+ fallbacks
533
+ /** Replace all saved metadata for one model, including clearing omitted fields. */
534
+ ? /** Replace all saved metadata for one model, including clearing omitted fields. */: {
518
535
  [key: string]: string[];
519
536
  };
520
537
  };
@@ -544,7 +561,9 @@ export declare class SwitcherClient {
544
561
  aliases?: {
545
562
  [key: string]: string;
546
563
  };
547
- fallbacks?: {
564
+ fallbacks
565
+ /** Replace all saved metadata for one model, including clearing omitted fields. */
566
+ ? /** Replace all saved metadata for one model, including clearing omitted fields. */: {
548
567
  [key: string]: string[];
549
568
  };
550
569
  };
@@ -574,7 +593,9 @@ export declare class SwitcherClient {
574
593
  aliases?: {
575
594
  [key: string]: string;
576
595
  };
577
- fallbacks?: {
596
+ fallbacks
597
+ /** Replace all saved metadata for one model, including clearing omitted fields. */
598
+ ? /** Replace all saved metadata for one model, including clearing omitted fields. */: {
578
599
  [key: string]: string[];
579
600
  };
580
601
  };
@@ -604,7 +625,9 @@ export declare class SwitcherClient {
604
625
  aliases?: {
605
626
  [key: string]: string;
606
627
  };
607
- fallbacks?: {
628
+ fallbacks
629
+ /** Replace all saved metadata for one model, including clearing omitted fields. */
630
+ ? /** Replace all saved metadata for one model, including clearing omitted fields. */: {
608
631
  [key: string]: string[];
609
632
  };
610
633
  };