@atbash/sdk 0.10.7-dev.0 → 0.10.10-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/browser.mjs CHANGED
@@ -10054,8 +10054,8 @@ Reporter$3.prototype.wrapResult = function wrapResult(result) {
10054
10054
  errors: state2.errors
10055
10055
  };
10056
10056
  };
10057
- function ReporterError$1(path3, msg) {
10058
- this.path = path3;
10057
+ function ReporterError$1(path4, msg) {
10058
+ this.path = path4;
10059
10059
  this.rethrow(msg);
10060
10060
  }
10061
10061
  inherits$v(ReporterError$1, Error);
@@ -30276,8 +30276,8 @@ Reporter.prototype.wrapResult = function wrapResult2(result) {
30276
30276
  errors: state2.errors
30277
30277
  };
30278
30278
  };
30279
- function ReporterError(path3, msg) {
30280
- this.path = path3;
30279
+ function ReporterError(path4, msg) {
30280
+ this.path = path4;
30281
30281
  this.rethrow(msg);
30282
30282
  }
30283
30283
  inherits(ReporterError, Error);
@@ -33307,8 +33307,8 @@ var parseUtil = {};
33307
33307
  const errors_js_12 = errors$3;
33308
33308
  const en_js_12 = __importDefault2(en);
33309
33309
  const makeIssue = (params) => {
33310
- const { data, path: path3, errorMaps, issueData } = params;
33311
- const fullPath = [...path3, ...issueData.path || []];
33310
+ const { data, path: path4, errorMaps, issueData } = params;
33311
+ const fullPath = [...path4, ...issueData.path || []];
33312
33312
  const fullIssue = {
33313
33313
  ...issueData,
33314
33314
  path: fullPath
@@ -33445,11 +33445,11 @@ var errorUtil_js_1 = errorUtil$1;
33445
33445
  var parseUtil_js_1 = parseUtil;
33446
33446
  var util_js_1 = util;
33447
33447
  var ParseInputLazyPath = class {
33448
- constructor(parent, value, path3, key3) {
33448
+ constructor(parent, value, path4, key3) {
33449
33449
  this._cachedPath = [];
33450
33450
  this.parent = parent;
33451
33451
  this.data = value;
33452
- this._path = path3;
33452
+ this._path = path4;
33453
33453
  this._key = key3;
33454
33454
  }
33455
33455
  get path() {
@@ -40355,21 +40355,21 @@ function createTimeoutController(timeout) {
40355
40355
  const timeoutId = setTimeout(() => controller.abort(timeoutError), timeout);
40356
40356
  return { controller, timeoutId };
40357
40357
  }
40358
- function handleRequest(method, path3, endpoint, timeout, postObject) {
40358
+ function handleRequest(method, path4, endpoint, timeout, postObject) {
40359
40359
  return __awaiter$2(this, void 0, void 0, function* () {
40360
40360
  if (method == enums_1$2.Method.GET) {
40361
- return yield get(path3, endpoint, timeout);
40361
+ return yield get(path4, endpoint, timeout);
40362
40362
  } else {
40363
- return yield post(path3, endpoint, timeout, postObject);
40363
+ return yield post(path4, endpoint, timeout, postObject);
40364
40364
  }
40365
40365
  });
40366
40366
  }
40367
- function get(path3, endpoint, timeout) {
40367
+ function get(path4, endpoint, timeout) {
40368
40368
  return __awaiter$2(this, void 0, void 0, function* () {
40369
- logger.debug(`GET URL ${new URL(path3, endpoint).href}`);
40369
+ logger.debug(`GET URL ${new URL(path4, endpoint).href}`);
40370
40370
  try {
40371
40371
  const { controller, timeoutId } = createTimeoutController(timeout);
40372
- const response = yield fetch(new URL(path3, endpoint).href, {
40372
+ const response = yield fetch(new URL(path4, endpoint).href, {
40373
40373
  signal: controller === null || controller === void 0 ? void 0 : controller.signal
40374
40374
  });
40375
40375
  if (timeoutId)
@@ -40407,9 +40407,9 @@ function constructBufferResponseBody(response) {
40407
40407
  return responseText ? responseText : response.statusText;
40408
40408
  });
40409
40409
  }
40410
- function post(path3, endpoint, timeout, requestBody) {
40410
+ function post(path4, endpoint, timeout, requestBody) {
40411
40411
  return __awaiter$2(this, void 0, void 0, function* () {
40412
- logger.debug(`POST URL ${new URL(path3, endpoint).href}`);
40412
+ logger.debug(`POST URL ${new URL(path4, endpoint).href}`);
40413
40413
  logger.debug(`POST body ${JSON.stringify(requestBody)}`);
40414
40414
  if (buffer_1.Buffer.isBuffer(requestBody)) {
40415
40415
  try {
@@ -40423,7 +40423,7 @@ function post(path3, endpoint, timeout, requestBody) {
40423
40423
  },
40424
40424
  signal: controller === null || controller === void 0 ? void 0 : controller.signal
40425
40425
  };
40426
- const response = yield fetch(new URL(path3, endpoint).href, requestOptions);
40426
+ const response = yield fetch(new URL(path4, endpoint).href, requestOptions);
40427
40427
  if (timeoutId)
40428
40428
  clearTimeout(timeoutId);
40429
40429
  const transactionTimestamp = response.headers.get("X-Transaction-Timestamp");
@@ -40434,7 +40434,7 @@ function post(path3, endpoint, timeout, requestBody) {
40434
40434
  } else {
40435
40435
  try {
40436
40436
  const { controller, timeoutId } = createTimeoutController(timeout);
40437
- const response = yield fetch(new URL(path3, endpoint).href, {
40437
+ const response = yield fetch(new URL(path4, endpoint).href, {
40438
40438
  method: "post",
40439
40439
  body: JSON.stringify(requestBody),
40440
40440
  headers: {
@@ -40614,10 +40614,10 @@ function requireFailoverStrategies() {
40614
40614
  }
40615
40615
  }
40616
40616
  function abortOnError(_a2) {
40617
- return __awaiter2(this, arguments, void 0, function* ({ method, path: path3, config: config2, postObject, timeoutOverride }) {
40617
+ return __awaiter2(this, arguments, void 0, function* ({ method, path: path4, config: config2, postObject, timeoutOverride }) {
40618
40618
  return yield retryRequest({
40619
40619
  method,
40620
- path: path3,
40620
+ path: path4,
40621
40621
  config: config2,
40622
40622
  postObject,
40623
40623
  timeoutOverride,
@@ -40628,10 +40628,10 @@ function requireFailoverStrategies() {
40628
40628
  });
40629
40629
  }
40630
40630
  function tryNextOnError(_a2) {
40631
- return __awaiter2(this, arguments, void 0, function* ({ method, path: path3, config: config2, postObject, timeoutOverride }) {
40631
+ return __awaiter2(this, arguments, void 0, function* ({ method, path: path4, config: config2, postObject, timeoutOverride }) {
40632
40632
  return yield retryRequest({
40633
40633
  method,
40634
- path: path3,
40634
+ path: path4,
40635
40635
  config: config2,
40636
40636
  postObject,
40637
40637
  timeoutOverride,
@@ -40647,7 +40647,7 @@ function requireFailoverStrategies() {
40647
40647
  return endpointPoolLength - (endpointPoolLength - 1) / 3;
40648
40648
  }
40649
40649
  function queryMajority(_a2) {
40650
- return __awaiter2(this, arguments, void 0, function* ({ method, path: path3, config: config2, postObject, timeoutOverride }) {
40650
+ return __awaiter2(this, arguments, void 0, function* ({ method, path: path4, config: config2, postObject, timeoutOverride }) {
40651
40651
  var _b;
40652
40652
  const bftMajorityThreshold = calculateBftMajorityThreshold(config2.endpointPool.length);
40653
40653
  const failureThreshold = config2.endpointPool.length - bftMajorityThreshold + 1;
@@ -40658,7 +40658,7 @@ function requireFailoverStrategies() {
40658
40658
  const promises = availableNodes.map((node2) => __awaiter2(this, void 0, void 0, function* () {
40659
40659
  try {
40660
40660
  const requestTimeout = timeoutOverride !== null && timeoutOverride !== void 0 ? timeoutOverride : config2.responseTimeout;
40661
- const response = yield (0, httpUtil_1.handleRequest)(method, path3, node2.url, requestTimeout, postObject);
40661
+ const response = yield (0, httpUtil_1.handleRequest)(method, path4, node2.url, requestTimeout, postObject);
40662
40662
  const { statusCode } = response;
40663
40663
  if (statusCode && (0, http_utils_1.isSuccessfulStatusCode)(statusCode)) {
40664
40664
  outcomes.push({ type: "SUCCESS", result: response });
@@ -40705,7 +40705,7 @@ function requireFailoverStrategies() {
40705
40705
  });
40706
40706
  }
40707
40707
  function singleEndpoint(_a2) {
40708
- return __awaiter2(this, arguments, void 0, function* ({ method, path: path3, config: config2, postObject, timeoutOverride }) {
40708
+ return __awaiter2(this, arguments, void 0, function* ({ method, path: path4, config: config2, postObject, timeoutOverride }) {
40709
40709
  let statusCode = null;
40710
40710
  let rspBody = null;
40711
40711
  let error4 = null;
@@ -40716,7 +40716,7 @@ function requireFailoverStrategies() {
40716
40716
  }
40717
40717
  for (let attempt = 0; attempt < config2.attemptsPerEndpoint; attempt++) {
40718
40718
  const requestTimeout = timeoutOverride !== null && timeoutOverride !== void 0 ? timeoutOverride : config2.responseTimeout;
40719
- const response = yield (0, httpUtil_1.handleRequest)(method, path3, endpoint.url, requestTimeout, postObject);
40719
+ const response = yield (0, httpUtil_1.handleRequest)(method, path4, endpoint.url, requestTimeout, postObject);
40720
40720
  if (response) {
40721
40721
  ({ error: error4, statusCode, rspBody, transactionTimestamp } = response);
40722
40722
  }
@@ -40731,7 +40731,7 @@ function requireFailoverStrategies() {
40731
40731
  });
40732
40732
  }
40733
40733
  function retryRequest(_a2) {
40734
- return __awaiter2(this, arguments, void 0, function* ({ method, path: path3, config: config2, postObject, useNextNodeOnError, recoveryThreshold, timeoutOverride }) {
40734
+ return __awaiter2(this, arguments, void 0, function* ({ method, path: path4, config: config2, postObject, useNextNodeOnError, recoveryThreshold, timeoutOverride }) {
40735
40735
  var _b, _c, _d;
40736
40736
  let statusCode = null;
40737
40737
  let rspBody = null;
@@ -40742,7 +40742,7 @@ function requireFailoverStrategies() {
40742
40742
  for (const node2 of availableNodes) {
40743
40743
  for (let attempt = 0; attempt < config2.attemptsPerEndpoint; attempt++) {
40744
40744
  const requestTimeout = timeoutOverride !== null && timeoutOverride !== void 0 ? timeoutOverride : config2.responseTimeout;
40745
- const response = yield (0, httpUtil_1.handleRequest)(method, path3, node2.url, requestTimeout, postObject);
40745
+ const response = yield (0, httpUtil_1.handleRequest)(method, path4, node2.url, requestTimeout, postObject);
40746
40746
  error4 = (_b = response === null || response === void 0 ? void 0 : response.error) !== null && _b !== void 0 ? _b : null;
40747
40747
  statusCode = (_c = response === null || response === void 0 ? void 0 : response.statusCode) !== null && _c !== void 0 ? _c : null;
40748
40748
  rspBody = (_d = response === null || response === void 0 ? void 0 : response.rspBody) !== null && _d !== void 0 ? _d : null;
@@ -40885,19 +40885,19 @@ function requireRequestWithFailoverStrategy() {
40885
40885
  const enums_12 = enums;
40886
40886
  const failoverStrategies_1 = requireFailoverStrategies();
40887
40887
  function requestWithFailoverStrategy$1(method_1, path_1, config_1, postObject_1) {
40888
- return __awaiter2(this, arguments, void 0, function* (method, path3, config2, postObject, forceSingleEndpoint = false, timeoutOverride) {
40888
+ return __awaiter2(this, arguments, void 0, function* (method, path4, config2, postObject, forceSingleEndpoint = false, timeoutOverride) {
40889
40889
  switch (config2.failoverStrategy) {
40890
40890
  case enums_12.FailoverStrategy.AbortOnError:
40891
- return yield (0, failoverStrategies_1.abortOnError)({ method, path: path3, config: config2, postObject, timeoutOverride });
40891
+ return yield (0, failoverStrategies_1.abortOnError)({ method, path: path4, config: config2, postObject, timeoutOverride });
40892
40892
  case enums_12.FailoverStrategy.TryNextOnError:
40893
- return yield (0, failoverStrategies_1.tryNextOnError)({ method, path: path3, config: config2, postObject, timeoutOverride });
40893
+ return yield (0, failoverStrategies_1.tryNextOnError)({ method, path: path4, config: config2, postObject, timeoutOverride });
40894
40894
  case enums_12.FailoverStrategy.SingleEndpoint:
40895
- return yield (0, failoverStrategies_1.singleEndpoint)({ method, path: path3, config: config2, postObject, timeoutOverride });
40895
+ return yield (0, failoverStrategies_1.singleEndpoint)({ method, path: path4, config: config2, postObject, timeoutOverride });
40896
40896
  case enums_12.FailoverStrategy.QueryMajority:
40897
40897
  if (forceSingleEndpoint) {
40898
- return yield (0, failoverStrategies_1.singleEndpoint)({ method, path: path3, config: config2, postObject, timeoutOverride });
40898
+ return yield (0, failoverStrategies_1.singleEndpoint)({ method, path: path4, config: config2, postObject, timeoutOverride });
40899
40899
  }
40900
- return yield (0, failoverStrategies_1.queryMajority)({ method, path: path3, config: config2, postObject, timeoutOverride });
40900
+ return yield (0, failoverStrategies_1.queryMajority)({ method, path: path4, config: config2, postObject, timeoutOverride });
40901
40901
  default:
40902
40902
  throw new Error(`Unsupported failover strategy: ${config2.failoverStrategy}`);
40903
40903
  }
@@ -42096,7 +42096,7 @@ var networkSettings = {};
42096
42096
  const restNetworkSettingsValidationContext = RestNetworkSettingsSchema.safeParse(networkSettings2);
42097
42097
  if ("error" in restNetworkSettingsValidationContext) {
42098
42098
  const { error: { issues } = {} } = restNetworkSettingsValidationContext;
42099
- const errorMessage2 = issues === null || issues === void 0 ? void 0 : issues.map(({ message, path: path3 }) => `${path3[0]}: ${message}`).join(", ");
42099
+ const errorMessage2 = issues === null || issues === void 0 ? void 0 : issues.map(({ message, path: path4 }) => `${path4[0]}: ${message}`).join(", ");
42100
42100
  if (throwOnError) {
42101
42101
  throw new Error(errorMessage2);
42102
42102
  }
@@ -44453,8 +44453,8 @@ var HttpClient = class {
44453
44453
  this.baseUrl = baseUrl.replace(/\/+$/, "");
44454
44454
  this.timeoutMs = timeoutMs;
44455
44455
  }
44456
- buildUrl(path3, query) {
44457
- const url = new URL(this.baseUrl + path3);
44456
+ buildUrl(path4, query) {
44457
+ const url = new URL(this.baseUrl + path4);
44458
44458
  if (query) {
44459
44459
  for (const [k, v] of Object.entries(query)) {
44460
44460
  if (v !== void 0 && v !== null && v !== "") {
@@ -44464,23 +44464,83 @@ var HttpClient = class {
44464
44464
  }
44465
44465
  return url.toString();
44466
44466
  }
44467
- async get(path3, query, headers) {
44468
- return this.fetch(this.buildUrl(path3, query), {
44467
+ async get(path4, query, headers) {
44468
+ return this.fetch(this.buildUrl(path4, query), {
44469
44469
  method: "GET",
44470
44470
  ...headers && { headers }
44471
44471
  });
44472
44472
  }
44473
- async post(path3, body, headers) {
44474
- return this.fetch(this.buildUrl(path3), {
44473
+ async post(path4, body, headers) {
44474
+ return this.fetch(this.buildUrl(path4), {
44475
44475
  method: "POST",
44476
44476
  headers: { "Content-Type": "application/json", ...headers },
44477
44477
  body: JSON.stringify(body)
44478
44478
  });
44479
44479
  }
44480
44480
  async fetch(url, init4) {
44481
- return fetch(url, { ...init4, signal: AbortSignal.timeout(this.timeoutMs) });
44481
+ try {
44482
+ return await fetch(url, {
44483
+ ...init4,
44484
+ signal: AbortSignal.timeout(this.timeoutMs)
44485
+ });
44486
+ } catch (err) {
44487
+ throw classifyTransportError(err, url, init4.method ?? "GET", this.timeoutMs);
44488
+ }
44482
44489
  }
44483
44490
  };
44491
+ var HttpTransportError = class extends Error {
44492
+ kind;
44493
+ constructor(kind, message, options) {
44494
+ super(message, options);
44495
+ this.name = "HttpTransportError";
44496
+ this.kind = kind;
44497
+ }
44498
+ };
44499
+ function classifyTransportError(err, url, method, timeoutMs) {
44500
+ const name2 = err instanceof Error ? err.name : "";
44501
+ const cause = err instanceof Error ? err.cause : void 0;
44502
+ const code2 = cause && typeof cause === "object" && "code" in cause ? String(cause.code) : "";
44503
+ if (name2 === "TimeoutError") {
44504
+ return new HttpTransportError(
44505
+ "timeout",
44506
+ `${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`,
44507
+ { cause: err }
44508
+ );
44509
+ }
44510
+ if (name2 === "AbortError") {
44511
+ return new HttpTransportError(
44512
+ "aborted",
44513
+ `${method} ${url} was cancelled by the caller`,
44514
+ { cause: err }
44515
+ );
44516
+ }
44517
+ if (code2 === "ENOTFOUND" || code2 === "EAI_AGAIN") {
44518
+ return new HttpTransportError(
44519
+ "dns",
44520
+ `could not resolve the judge hostname (${url}) \u2014 check the endpoint and DNS`,
44521
+ { cause: err }
44522
+ );
44523
+ }
44524
+ if (code2 === "ECONNREFUSED") {
44525
+ return new HttpTransportError(
44526
+ "connect_refused",
44527
+ `judge refused the connection (${url}) \u2014 the service may be down or restarting`,
44528
+ { cause: err }
44529
+ );
44530
+ }
44531
+ if (code2 === "ECONNRESET" || code2 === "EPIPE") {
44532
+ return new HttpTransportError(
44533
+ "connection_reset",
44534
+ `judge dropped the connection mid-request (${url}) \u2014 retry once`,
44535
+ { cause: err }
44536
+ );
44537
+ }
44538
+ return new HttpTransportError(
44539
+ "unknown",
44540
+ `${method} ${url} failed: ${err instanceof Error ? err.message : String(err)}`,
44541
+ { cause: err }
44542
+ );
44543
+ }
44484
44544
 
44485
44545
  // src-ts/browser/keyLoader.ts
44486
44546
  init_define_ATBASH_CHROMIA_NODE_URLS();
@@ -44581,6 +44641,16 @@ var Atbash = class _Atbash {
44581
44641
  * calls don't re-hit the dashboard. Cleared by `clearChainCache()`.
44582
44642
  */
44583
44643
  _chainCache = /* @__PURE__ */ new Map();
44644
+ /**
44645
+ * Short-TTL cache for `/api/ai/exists`. The `registered` field is
44646
+ * monotonic (once true, stays true), so most calls in a burst re-fetch
44647
+ * data that hasn't changed. The `org_encryption_pubkey` field CAN change
44648
+ * — an org toggling encryption mid-session — so the TTL is deliberately
44649
+ * short (see `AGENT_EXISTS_TTL_MS`). Keyed by (pubkey, network) so
44650
+ * cross-agent / cross-network calls don't collide.
44651
+ */
44652
+ _agentExistsCache = null;
44653
+ static AGENT_EXISTS_TTL_MS = 5e3;
44584
44654
  /**
44585
44655
  * Cached bearer token for risk-engine / insurance read calls. Built
44586
44656
  * lazily as a signed `log_tool_call` tx and refreshed every 4 min so
@@ -44600,7 +44670,7 @@ var Atbash = class _Atbash {
44600
44670
  this.failClosed = options.failClosed !== false;
44601
44671
  this.debug = options.debug === true;
44602
44672
  this.logger = options.logger ?? {};
44603
- this.http = new HttpClient(this.endpoint, options.timeoutMs ?? 3e4);
44673
+ this.http = new HttpClient(this.endpoint, options.timeoutMs ?? 6e4);
44604
44674
  this.logEnvironmentOnce();
44605
44675
  if (this.endpoint !== DEFAULT_ENDPOINT) {
44606
44676
  this.logger.warn?.("[atbash] running on non-default judge endpoint", {
@@ -44680,9 +44750,18 @@ var Atbash = class _Atbash {
44680
44750
  */
44681
44751
  async checkAgentExists(pubkey, opts) {
44682
44752
  const pk = pubkey ?? this.auth.pubkey;
44753
+ const network = opts?.network;
44754
+ const now = Date.now();
44755
+ const cached = this._agentExistsCache;
44756
+ if (cached && cached.pubkey === pk && cached.network === network && cached.expiresAt > now) {
44757
+ if (pk === this.auth.pubkey) {
44758
+ this._orgKeyFromChain = cached.orgKey;
44759
+ }
44760
+ return cached.registered;
44761
+ }
44683
44762
  return this.track("checkAgentExists", pk, async () => {
44684
44763
  const query = { pubkey: pk };
44685
- if (opts?.network) query.network = opts.network;
44764
+ if (network) query.network = network;
44686
44765
  const resp = await this.http.get(
44687
44766
  "/api/ai/exists",
44688
44767
  query,
@@ -44690,11 +44769,21 @@ var Atbash = class _Atbash {
44690
44769
  );
44691
44770
  await this.raiseIfError(resp);
44692
44771
  const data = await this.json(resp);
44772
+ const registered = Boolean(data?.registered);
44773
+ const orgKey = typeof data?.org_encryption_pubkey === "string" && data.org_encryption_pubkey ? data.org_encryption_pubkey : null;
44774
+ if (registered) {
44775
+ this._agentExistsCache = {
44776
+ pubkey: pk,
44777
+ network,
44778
+ expiresAt: Date.now() + _Atbash.AGENT_EXISTS_TTL_MS,
44779
+ registered,
44780
+ orgKey
44781
+ };
44782
+ }
44693
44783
  if (pk === this.auth.pubkey) {
44694
- const key3 = data?.org_encryption_pubkey;
44695
- this._orgKeyFromChain = typeof key3 === "string" && key3 ? key3 : null;
44784
+ this._orgKeyFromChain = orgKey;
44696
44785
  }
44697
- return Boolean(data?.registered);
44786
+ return registered;
44698
44787
  });
44699
44788
  }
44700
44789
  /* ── log_tool_call (sign-only) ─────────────────────────────────────────── */
@@ -44775,12 +44864,19 @@ var Atbash = class _Atbash {
44775
44864
  }
44776
44865
  let chainOpts = options.chainOpts;
44777
44866
  if (options.orgName) {
44778
- const mapNetwork = await this.getActiveNetworkForOrg(options.orgName);
44779
- if (mapNetwork) {
44780
- chainOpts = { network: mapNetwork };
44781
- } else if (!chainOpts?.blockchainRid) {
44782
- const resolved = await this.resolveChainFromMap(options.orgName, null);
44783
- chainOpts = { ...chainOpts, network: resolved.network };
44867
+ const cached = this._chainCache.get(options.orgName);
44868
+ if (cached) {
44869
+ chainOpts = { network: cached.network };
44870
+ } else {
44871
+ const mapNetwork = await this.getActiveNetworkForOrg(options.orgName);
44872
+ if (mapNetwork) {
44873
+ const chain = mapNetwork === "private" ? PRIVATE_CHAIN : PUBLIC_CHAIN;
44874
+ this._chainCache.set(options.orgName, chain);
44875
+ chainOpts = { network: mapNetwork };
44876
+ } else if (!chainOpts?.blockchainRid) {
44877
+ const resolved = await this.resolveChainFromMap(options.orgName, null);
44878
+ chainOpts = { ...chainOpts, network: resolved.network };
44879
+ }
44784
44880
  }
44785
44881
  }
44786
44882
  const brid = this.bridFromChainOpts(chainOpts);
@@ -45229,6 +45325,10 @@ var Atbash = class _Atbash {
45229
45325
  clearChainCache() {
45230
45326
  this._chainCache.clear();
45231
45327
  }
45328
+ /** Drop the short-TTL `/api/ai/exists` cache. Useful in tests. */
45329
+ clearAgentExistsCache() {
45330
+ this._agentExistsCache = null;
45331
+ }
45232
45332
  /* ── internals ─────────────────────────────────────────────────────────── */
45233
45333
  /**
45234
45334
  * Wrap an SDK method body in telemetry — records the call at start
@@ -45331,8 +45431,27 @@ var Atbash = class _Atbash {
45331
45431
  this.endpoint
45332
45432
  );
45333
45433
  }
45334
- /** Wrap a *transport* failure (fetch threw, no response) as an AtbashAPIError. */
45434
+ /**
45435
+ * Wrap a transport failure (fetch threw, no response) as an AtbashAPIError.
45436
+ *
45437
+ * `HttpTransportError.kind` names the cause; the message is already
45438
+ * human-readable. `debug` echoes the original exception so operators can
45439
+ * cross-reference with node / undici logs when a class doesn't match.
45440
+ */
45335
45441
  transportError(err) {
45442
+ if (err instanceof HttpTransportError) {
45443
+ if (this.debug) {
45444
+ this.logger.warn?.(
45445
+ `[atbash] transport failed \u2014 kind=${err.kind}`,
45446
+ {
45447
+ kind: err.kind,
45448
+ cause: err.cause instanceof Error ? err.cause.message : String(err.cause ?? ""),
45449
+ endpoint: this.endpoint
45450
+ }
45451
+ );
45452
+ }
45453
+ return new AtbashAPIError(0, err.message, "", this.endpoint);
45454
+ }
45336
45455
  return new AtbashAPIError(0, errorMessage(err), "", this.endpoint);
45337
45456
  }
45338
45457
  async json(resp) {
@@ -45710,6 +45829,7 @@ function classifyMemoryWrite(_event, _ctx, _opts = {}) {
45710
45829
  // src-ts/memory/guard.ts
45711
45830
  init_define_ATBASH_CHROMIA_NODE_URLS();
45712
45831
  init_define_ATBASH_PRIVATE_NODE_URLS();
45832
+ import path3 from "path";
45713
45833
  function emitDebugProbe(event, ctx, memEntry, logger2) {
45714
45834
  if (!logger2?.info) return;
45715
45835
  const ev = event ?? {};
@@ -45746,7 +45866,8 @@ async function guardMemoryWrite(input) {
45746
45866
  toolNames,
45747
45867
  enforce = true,
45748
45868
  debug: debug2 = false,
45749
- logger: logger2
45869
+ logger: logger2,
45870
+ memoryFilePath
45750
45871
  } = input;
45751
45872
  const memEntry = classifyMemoryWrite(event, ctx, { patterns, toolNames });
45752
45873
  if (debug2) emitDebugProbe(event, ctx, memEntry, logger2);
@@ -45782,17 +45903,28 @@ async function guardMemoryWrite(input) {
45782
45903
  committed: false
45783
45904
  };
45784
45905
  }
45785
- commitMemoryVersion(memEntry.value, auth, {
45786
- score: scanResult.score,
45787
- orgName,
45788
- endpoint
45789
- }).catch((err) => {
45790
- const reason = err instanceof Error ? err.message : String(err);
45791
- logger2?.warn?.("[atbash] memory commit to chain failed", {
45792
- path: memEntry.key,
45793
- reason
45906
+ const isManagedMemoryFile = memoryFilePath !== void 0 && path3.resolve(memEntry.key) === path3.resolve(memoryFilePath);
45907
+ if (isManagedMemoryFile) {
45908
+ commitMemoryVersion(memEntry.value, auth, {
45909
+ score: scanResult.score,
45910
+ orgName,
45911
+ endpoint
45912
+ }).catch((err) => {
45913
+ const reason = err instanceof Error ? err.message : String(err);
45914
+ logger2?.warn?.("[atbash] memory commit to chain failed", {
45915
+ path: memEntry.key,
45916
+ reason
45917
+ });
45794
45918
  });
45795
- });
45919
+ } else {
45920
+ logger2?.info?.(
45921
+ "[atbash] scanned but not committed \u2014 not the managed memory file",
45922
+ {
45923
+ path: memEntry.key,
45924
+ memoryFilePath: memoryFilePath ?? "(not configured)"
45925
+ }
45926
+ );
45927
+ }
45796
45928
  logger2?.info?.(
45797
45929
  scanResult.verdict === "yellow" ? "[atbash] memory HOLD" : "[atbash] memory ALLOW",
45798
45930
  { path: memEntry.key, score: scanResult.score, reason: scanResult.reason }
@@ -45801,7 +45933,7 @@ async function guardMemoryWrite(input) {
45801
45933
  handled: true,
45802
45934
  decision: { allow: true },
45803
45935
  scanResult,
45804
- committed: true
45936
+ committed: isManagedMemoryFile
45805
45937
  };
45806
45938
  }
45807
45939
 
@@ -45822,21 +45954,21 @@ async function syncLocalMemory(auth, pointer, opts = {}) {
45822
45954
  const now = Date.now();
45823
45955
  const withinTtl = !opts.force && now - pointer.checkedAt < ttl;
45824
45956
  if (withinTtl) {
45825
- return { drifted: false, pointer };
45957
+ return { drifted: false, checked: false, pointer };
45826
45958
  }
45827
45959
  const currentId = await getActiveMemoryId(auth, opts.chainOpts);
45828
45960
  const nextPointer = { activeId: currentId, checkedAt: now };
45829
45961
  if (currentId === pointer.activeId) {
45830
- return { drifted: false, pointer: nextPointer };
45962
+ return { drifted: false, checked: true, pointer: nextPointer };
45831
45963
  }
45832
45964
  if (currentId === null) {
45833
- return { drifted: true, current: null, pointer: nextPointer };
45965
+ return { drifted: true, checked: true, current: null, pointer: nextPointer };
45834
45966
  }
45835
45967
  const row = await getMemoryById(currentId, auth, opts.chainOpts);
45836
45968
  if (row.decryptError) {
45837
45969
  throw new MemoryIntegrityError(currentId, row.decryptError);
45838
45970
  }
45839
- return { drifted: true, current: row, pointer: nextPointer };
45971
+ return { drifted: true, checked: true, current: row, pointer: nextPointer };
45840
45972
  }
45841
45973
 
45842
45974
  // src-ts/browser/memory-pointer-store.ts
@@ -45976,6 +46108,8 @@ export {
45976
46108
  DEFAULT_MEMORY_READ_TOOL_NAMES,
45977
46109
  DEFAULT_MEMORY_WRITE_TOOL_NAMES,
45978
46110
  EciesDomain,
46111
+ HttpClient,
46112
+ HttpTransportError,
45979
46113
  KEY_FILENAMES,
45980
46114
  MemoryGuardManager,
45981
46115
  MemoryIntegrityError,