@atbash/sdk 0.10.7-dev.0 → 0.10.9-dev.0

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/index.mjs CHANGED
@@ -3046,9 +3046,69 @@ var HttpClient = class {
3046
3046
  });
3047
3047
  }
3048
3048
  async fetch(url, init4) {
3049
- return fetch(url, { ...init4, signal: AbortSignal.timeout(this.timeoutMs) });
3049
+ try {
3050
+ return await fetch(url, {
3051
+ ...init4,
3052
+ signal: AbortSignal.timeout(this.timeoutMs)
3053
+ });
3054
+ } catch (err) {
3055
+ throw classifyTransportError(err, url, init4.method ?? "GET", this.timeoutMs);
3056
+ }
3050
3057
  }
3051
3058
  };
3059
+ var HttpTransportError = class extends Error {
3060
+ kind;
3061
+ constructor(kind, message, options) {
3062
+ super(message, options);
3063
+ this.name = "HttpTransportError";
3064
+ this.kind = kind;
3065
+ }
3066
+ };
3067
+ function classifyTransportError(err, url, method, timeoutMs) {
3068
+ const name2 = err instanceof Error ? err.name : "";
3069
+ const cause = err instanceof Error ? err.cause : void 0;
3070
+ const code2 = cause && typeof cause === "object" && "code" in cause ? String(cause.code) : "";
3071
+ if (name2 === "TimeoutError") {
3072
+ return new HttpTransportError(
3073
+ "timeout",
3074
+ `${method} ${url} did not respond within ${timeoutMs} ms \u2014 the judge may be slow to boot or the LLM is under load; retry in a moment`,
3075
+ { cause: err }
3076
+ );
3077
+ }
3078
+ if (name2 === "AbortError") {
3079
+ return new HttpTransportError(
3080
+ "aborted",
3081
+ `${method} ${url} was cancelled by the caller`,
3082
+ { cause: err }
3083
+ );
3084
+ }
3085
+ if (code2 === "ENOTFOUND" || code2 === "EAI_AGAIN") {
3086
+ return new HttpTransportError(
3087
+ "dns",
3088
+ `could not resolve the judge hostname (${url}) \u2014 check the endpoint and DNS`,
3089
+ { cause: err }
3090
+ );
3091
+ }
3092
+ if (code2 === "ECONNREFUSED") {
3093
+ return new HttpTransportError(
3094
+ "connect_refused",
3095
+ `judge refused the connection (${url}) \u2014 the service may be down or restarting`,
3096
+ { cause: err }
3097
+ );
3098
+ }
3099
+ if (code2 === "ECONNRESET" || code2 === "EPIPE") {
3100
+ return new HttpTransportError(
3101
+ "connection_reset",
3102
+ `judge dropped the connection mid-request (${url}) \u2014 retry once`,
3103
+ { cause: err }
3104
+ );
3105
+ }
3106
+ return new HttpTransportError(
3107
+ "unknown",
3108
+ `${method} ${url} failed: ${err instanceof Error ? err.message : String(err)}`,
3109
+ { cause: err }
3110
+ );
3111
+ }
3052
3112
 
3053
3113
  // src-ts/keyLoader.ts
3054
3114
  import { existsSync, readFileSync } from "fs";
@@ -3340,7 +3400,7 @@ var Atbash = class _Atbash {
3340
3400
  this.failClosed = options.failClosed !== false;
3341
3401
  this.debug = options.debug === true;
3342
3402
  this.logger = options.logger ?? {};
3343
- this.http = new HttpClient(this.endpoint, options.timeoutMs ?? 3e4);
3403
+ this.http = new HttpClient(this.endpoint, options.timeoutMs ?? 6e4);
3344
3404
  this.logEnvironmentOnce();
3345
3405
  if (this.endpoint !== DEFAULT_ENDPOINT) {
3346
3406
  this.logger.warn?.("[atbash] running on non-default judge endpoint", {
@@ -4071,8 +4131,27 @@ var Atbash = class _Atbash {
4071
4131
  this.endpoint
4072
4132
  );
4073
4133
  }
4074
- /** Wrap a *transport* failure (fetch threw, no response) as an AtbashAPIError. */
4134
+ /**
4135
+ * Wrap a transport failure (fetch threw, no response) as an AtbashAPIError.
4136
+ *
4137
+ * `HttpTransportError.kind` names the cause; the message is already
4138
+ * human-readable. `debug` echoes the original exception so operators can
4139
+ * cross-reference with node / undici logs when a class doesn't match.
4140
+ */
4075
4141
  transportError(err) {
4142
+ if (err instanceof HttpTransportError) {
4143
+ if (this.debug) {
4144
+ this.logger.warn?.(
4145
+ `[atbash] transport failed \u2014 kind=${err.kind}`,
4146
+ {
4147
+ kind: err.kind,
4148
+ cause: err.cause instanceof Error ? err.cause.message : String(err.cause ?? ""),
4149
+ endpoint: this.endpoint
4150
+ }
4151
+ );
4152
+ }
4153
+ return new AtbashAPIError(0, err.message, "", this.endpoint);
4154
+ }
4076
4155
  return new AtbashAPIError(0, errorMessage(err), "", this.endpoint);
4077
4156
  }
4078
4157
  async json(resp) {
@@ -43176,6 +43255,8 @@ export {
43176
43255
  DEFAULT_MEMORY_READ_TOOL_NAMES,
43177
43256
  DEFAULT_MEMORY_WRITE_TOOL_NAMES,
43178
43257
  EciesDomain,
43258
+ HttpClient,
43259
+ HttpTransportError,
43179
43260
  KEY_FILENAMES,
43180
43261
  MemoryGuardManager,
43181
43262
  MemoryIntegrityError,