@atbash/sdk 0.10.13-dev.0 → 0.13.0-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
@@ -37,7 +37,7 @@ var __toESM = (mod2, isNodeMode, target) => (target = mod2 != null ? __create(__
37
37
  var define_ATBASH_CHROMIA_NODE_URLS_default;
38
38
  var init_define_ATBASH_CHROMIA_NODE_URLS = __esm({
39
39
  "<define:__ATBASH_CHROMIA_NODE_URLS__>"() {
40
- define_ATBASH_CHROMIA_NODE_URLS_default = ["https://node0.testnet.chromia.com:7740", "https://node1.testnet.chromia.com:7740", "https://node3.testnet.chromia.com:7740"];
40
+ define_ATBASH_CHROMIA_NODE_URLS_default = ["https://node0.testnet.chromia.com:7740", "https://node1.testnet.chromia.com:7740"];
41
41
  }
42
42
  });
43
43
 
@@ -45,7 +45,7 @@ var init_define_ATBASH_CHROMIA_NODE_URLS = __esm({
45
45
  var define_ATBASH_PRIVATE_NODE_URLS_default;
46
46
  var init_define_ATBASH_PRIVATE_NODE_URLS = __esm({
47
47
  "<define:__ATBASH_PRIVATE_NODE_URLS__>"() {
48
- define_ATBASH_PRIVATE_NODE_URLS_default = ["https://node0-pvn-testnet.dynamic.chromia.dev"];
48
+ define_ATBASH_PRIVATE_NODE_URLS_default = ["https://node0-pvn-testnet.dynamic.chromia.dev:7740", "https://node1-pvn-testnet.dynamic.chromia.dev:7740", "https://node2-pvn-testnet.dynamic.chromia.dev:7740"];
49
49
  }
50
50
  });
51
51
 
@@ -43478,9 +43478,10 @@ var native = {
43478
43478
  validateMemoryId: stub("validateMemoryId"),
43479
43479
  validateRollbackReason: stub("validateRollbackReason"),
43480
43480
  validateMemoryNonce: stub("validateMemoryNonce"),
43481
+ validateFilePath: stub("validateFilePath"),
43481
43482
  buildGetActiveMemoryIdQuery: stub("buildGetActiveMemoryIdQuery"),
43482
- buildGetAgentMemoryQuery: stub("buildGetAgentMemoryQuery"),
43483
- buildGetAllAgentMemoryQuery: stub("buildGetAllAgentMemoryQuery"),
43483
+ buildGetRecentAgentMemoryQuery: stub("buildGetRecentAgentMemoryQuery"),
43484
+ buildGetActiveAgentMemoryQuery: stub("buildGetActiveAgentMemoryQuery"),
43484
43485
  buildGetAgentMemoryHistoryQuery: stub("buildGetAgentMemoryHistoryQuery"),
43485
43486
  buildGetAgentMemoryRollbackHistoryQuery: stub("buildGetAgentMemoryRollbackHistoryQuery"),
43486
43487
  buildGetAgentMemoryByIdQuery: stub("buildGetAgentMemoryByIdQuery"),
@@ -43499,13 +43500,14 @@ var native = {
43499
43500
  OP_ROLLBACK_AGENT_MEMORY: "rollback_agent_memory",
43500
43501
  OP_LOG_ENCRYPTED_TOOL_CALL: "log_encrypted_tool_call",
43501
43502
  QUERY_GET_ACTIVE_MEMORY_ID: "get_active_memory_id",
43502
- QUERY_GET_AGENT_MEMORY: "get_agent_memory",
43503
- QUERY_GET_ALL_AGENT_MEMORY: "get_all_agent_memory",
43503
+ QUERY_GET_RECENT_AGENT_MEMORY: "get_recent_agent_memory",
43504
+ QUERY_GET_ACTIVE_AGENT_MEMORY: "get_active_agent_memory",
43504
43505
  QUERY_GET_AGENT_MEMORY_HISTORY: "get_agent_memory_history",
43505
43506
  QUERY_GET_AGENT_MEMORY_BY_ID: "get_agent_memory_by_id",
43506
43507
  QUERY_GET_AGENT_MEMORY_ROLLBACK_HISTORY: "get_agent_memory_rollback_history",
43507
43508
  ARG_AGENT_PUBKEY: "agent_pubkey",
43508
- ARG_ID: "id"
43509
+ ARG_ID: "id",
43510
+ ARG_FILE_PATH: "file_path"
43509
43511
  };
43510
43512
 
43511
43513
  // src-ts/client.ts
@@ -43557,6 +43559,9 @@ var PRIVATE_CHAIN = {
43557
43559
  blockchainRid: DEFAULT_PRIVATE_BLOCKCHAIN_RID,
43558
43560
  nodeUrls: DEFAULT_PRIVATE_NODE_URLS
43559
43561
  };
43562
+ function chainForNetwork(network) {
43563
+ return network === "private" ? PRIVATE_CHAIN : PUBLIC_CHAIN;
43564
+ }
43560
43565
 
43561
43566
  // src-ts/browser/encrypted-toolcall.ts
43562
43567
  init_define_ATBASH_CHROMIA_NODE_URLS();
@@ -44610,11 +44615,36 @@ function saveUserConfig(_) {
44610
44615
  function resolve(_key, flagValue) {
44611
44616
  return flagValue ?? "";
44612
44617
  }
44618
+ function forcedChainNetwork(flagValue) {
44619
+ return flagValue === "public" || flagValue === "private" ? flagValue : void 0;
44620
+ }
44621
+ function warnDeprecatedEnvVarsOnce(_log) {
44622
+ }
44613
44623
 
44614
44624
  // src-ts/client.ts
44615
44625
  function generateToolCallId() {
44616
44626
  return `tc-${Date.now()}-${randomHex(4)}`;
44617
44627
  }
44628
+ function resolveConstructorChain(options) {
44629
+ if (options.chain) return options.chain;
44630
+ const hasNodeUrls = options.nodeUrls !== void 0;
44631
+ const hasBrid = options.blockchainRid !== void 0;
44632
+ if (hasNodeUrls !== hasBrid) {
44633
+ throw new Error(
44634
+ 'nodeUrls and blockchainRid must be provided together \u2014 passing one without the other 404s every chain request. Prefer `chain: PUBLIC_CHAIN | PRIVATE_CHAIN` or `network: "public" | "private"`.'
44635
+ );
44636
+ }
44637
+ if (hasNodeUrls && hasBrid) {
44638
+ const brid = options.blockchainRid;
44639
+ const derivedNetwork = options.network ?? (brid === PUBLIC_CHAIN.blockchainRid ? "public" : brid === PRIVATE_CHAIN.blockchainRid ? "private" : "private");
44640
+ return {
44641
+ network: derivedNetwork,
44642
+ blockchainRid: brid,
44643
+ nodeUrls: options.nodeUrls
44644
+ };
44645
+ }
44646
+ return chainForNetwork(options.network ?? forcedChainNetwork() ?? "private");
44647
+ }
44618
44648
  var Atbash = class _Atbash {
44619
44649
  auth;
44620
44650
  endpoint;
@@ -44638,6 +44668,27 @@ var Atbash = class _Atbash {
44638
44668
  * calls don't re-hit the dashboard. Cleared by `clearChainCache()`.
44639
44669
  */
44640
44670
  _chainCache = /* @__PURE__ */ new Map();
44671
+ /**
44672
+ * The chain the constructor settled on. Used only where a lookup returns no
44673
+ * answer — see {@link resolveChainFromMap}.
44674
+ */
44675
+ _defaultChain;
44676
+ /**
44677
+ * True when the caller named a chain outright — `chain`, `network`, or the
44678
+ * paired `blockchainRid` + `nodeUrls`.
44679
+ *
44680
+ * Such a client is never re-pointed: not by the migration switch, and not by
44681
+ * where an org turns out to live. Naming a chain is the caller saying "talk
44682
+ * to this one", and silently routing elsewhere would make the argument a
44683
+ * suggestion. A client that names nothing is the one that follows the org.
44684
+ */
44685
+ _explicitChain;
44686
+ /**
44687
+ * The fleet-wide chain switch, read once at construction. `resolve()` hits
44688
+ * the config file on disk, so re-reading it per call would put a file read
44689
+ * on every judge.
44690
+ */
44691
+ _forcedNetwork;
44641
44692
  /**
44642
44693
  * Short-TTL cache for `/api/ai/exists`. The `registered` field is
44643
44694
  * monotonic (once true, stays true), so most calls in a burst re-fetch
@@ -44662,11 +44713,23 @@ var Atbash = class _Atbash {
44662
44713
  static environmentLogged = false;
44663
44714
  constructor(privkey, options = {}) {
44664
44715
  this.auth = native.loadAgent(privkey);
44665
- this.endpoint = (options.endpoint ?? DEFAULT_ENDPOINT).replace(/\/+$/, "") || DEFAULT_ENDPOINT;
44666
- this.nodeUrls = options.nodeUrls ? [...options.nodeUrls] : DEFAULT_CHROMIA_NODE_URLS;
44667
- this.blockchainRid = options.blockchainRid ?? native.DEFAULT_BLOCKCHAIN_RID;
44716
+ const validated = validateJudgeEndpoint(
44717
+ options.verifyPubKey ? {
44718
+ policy: "self-hosted",
44719
+ endpoint: options.endpoint ?? DEFAULT_ENDPOINT,
44720
+ verifyPubKey: options.verifyPubKey
44721
+ } : { endpoint: options.endpoint }
44722
+ );
44723
+ this.endpoint = validated.url;
44724
+ const resolvedChain = resolveConstructorChain(options);
44725
+ this.nodeUrls = [...resolvedChain.nodeUrls];
44726
+ this.blockchainRid = resolvedChain.blockchainRid;
44727
+ this._defaultChain = resolvedChain;
44728
+ this._explicitChain = options.chain !== void 0 || options.network !== void 0 || options.blockchainRid !== void 0 && options.nodeUrls !== void 0;
44729
+ this._forcedNetwork = forcedChainNetwork();
44730
+ warnDeprecatedEnvVarsOnce((msg) => options.logger?.warn?.(msg));
44668
44731
  this.orgName = options.orgName;
44669
- this.verifyPubKey = options.verifyPubKey;
44732
+ this.verifyPubKey = validated.verifyPubKey ?? void 0;
44670
44733
  this.orgEncryptionPubKey = options.orgEncryptionPubKey;
44671
44734
  this.failClosed = options.failClosed !== false;
44672
44735
  this.debug = options.debug === true;
@@ -44724,15 +44787,27 @@ var Atbash = class _Atbash {
44724
44787
  * self-hosted endpoint's `verifyPubKey` becomes the client default.
44725
44788
  */
44726
44789
  static fromConfig(options = {}) {
44790
+ const configuredEndpoint = resolve("judgeEndpoint") || void 0;
44791
+ const configuredVerifyPubKey = resolve("judgeVerifyPubKey") || void 0;
44792
+ if (!options.judge && configuredVerifyPubKey && !configuredEndpoint) {
44793
+ throw new Error(
44794
+ "judgeVerifyPubKey / ATBASH_JUDGE_VERIFY_PUBKEY is set but no judge endpoint is configured: set judgeEndpoint / ATBASH_ENDPOINT to the self-hosted judge"
44795
+ );
44796
+ }
44727
44797
  const validated = validateJudgeEndpoint(
44728
- options.judge ?? { endpoint: resolve("judgeEndpoint") || void 0 }
44798
+ options.judge ?? (configuredVerifyPubKey && configuredEndpoint ? {
44799
+ policy: "self-hosted",
44800
+ endpoint: configuredEndpoint,
44801
+ verifyPubKey: configuredVerifyPubKey
44802
+ } : { endpoint: configuredEndpoint })
44729
44803
  );
44730
44804
  const agentKey = resolve("agentKey", options.agentKey);
44731
44805
  const auth = agentKey ? native.loadAgent(agentKey) : loadAgentFromFile(options.keyPath);
44732
- const blockchainRid = resolve("blockchainRid", options.blockchainRid) || void 0;
44733
44806
  return new _Atbash(auth.privkey, {
44734
44807
  endpoint: validated.url,
44735
- blockchainRid,
44808
+ chain: options.chain,
44809
+ network: options.network,
44810
+ blockchainRid: options.blockchainRid,
44736
44811
  timeoutMs: options.timeoutMs,
44737
44812
  nodeUrls: options.nodeUrls,
44738
44813
  orgName: options.orgName,
@@ -44773,7 +44848,7 @@ var Atbash = class _Atbash {
44773
44848
  return this.track("checkAgentExists", pk, async () => {
44774
44849
  const query = { pubkey: pk };
44775
44850
  if (network) query.network = network;
44776
- const brid = this.bridFromChainOpts(network ? { network } : void 0);
44851
+ const brid = network ? this.bridFromChainOpts({ network }) : await this.defaultOrgBrid();
44777
44852
  const resp = await this.http.get(
44778
44853
  "/api/ai/exists",
44779
44854
  query,
@@ -44824,7 +44899,7 @@ var Atbash = class _Atbash {
44824
44899
  };
44825
44900
  }
44826
44901
  const toolCallId = generateToolCallId();
44827
- const brid = this.bridFromChainOpts(options.chainOpts);
44902
+ const brid = options.chainOpts?.blockchainRid || options.chainOpts?.network ? this.bridFromChainOpts(options.chainOpts) : await this.defaultOrgBrid() ?? this.blockchainRid;
44828
44903
  const orgKey = options.orgEncryptionPubKey ?? this.orgEncryptionPubKey ?? this._orgKeyFromChain;
44829
44904
  try {
44830
44905
  const signedHex = orgKey ? signEncryptedToolCall(
@@ -44875,7 +44950,11 @@ var Atbash = class _Atbash {
44875
44950
  throw new Error("action is required and cannot be empty.");
44876
44951
  }
44877
44952
  let chainOpts = options.chainOpts;
44878
- if (options.orgName) {
44953
+ if (options.orgName && this._explicitChain) {
44954
+ chainOpts = options.chainOpts ?? { network: this._defaultChain.network };
44955
+ } else if (options.orgName && this.forcedNetwork()) {
44956
+ chainOpts = { network: this.forcedNetwork() };
44957
+ } else if (options.orgName) {
44879
44958
  const cached = this._chainCache.get(options.orgName);
44880
44959
  if (cached) {
44881
44960
  chainOpts = { network: cached.network };
@@ -45109,7 +45188,7 @@ var Atbash = class _Atbash {
45109
45188
  const resp = await this.http.get(
45110
45189
  "/api/v1/judge",
45111
45190
  { tool_call_id: judgmentId, agent_pubkey: pk },
45112
- this.authHeaders()
45191
+ this.authHeaders(await this.defaultOrgBrid())
45113
45192
  );
45114
45193
  await this.raiseIfError(resp);
45115
45194
  const data = await this.json(resp) ?? {};
@@ -45129,7 +45208,11 @@ var Atbash = class _Atbash {
45129
45208
  return this.track(
45130
45209
  "getToolCalls",
45131
45210
  void 0,
45132
- () => this.riskEngineRecords("tool-calls", { limit: maxCount })
45211
+ async () => this.riskEngineRecords(
45212
+ "tool-calls",
45213
+ { limit: maxCount },
45214
+ await this.defaultOrgBrid()
45215
+ )
45133
45216
  );
45134
45217
  }
45135
45218
  async getOrgToolCalls(orgName, maxCount) {
@@ -45146,24 +45229,31 @@ var Atbash = class _Atbash {
45146
45229
  return this.track(
45147
45230
  "getAgentToolCalls",
45148
45231
  agentPubkey,
45149
- () => this.riskEngineRecords("agent-tool-calls", {
45150
- agent: agentPubkey,
45151
- limit: maxCount
45152
- })
45232
+ async () => this.riskEngineRecords(
45233
+ "agent-tool-calls",
45234
+ { agent: agentPubkey, limit: maxCount },
45235
+ await this.defaultOrgBrid()
45236
+ )
45153
45237
  );
45154
45238
  }
45155
45239
  async getToolCallCount() {
45156
45240
  return this.track("getToolCallCount", void 0, async () => {
45157
- const raw2 = await this.riskEngineGet("tool-call-count", {});
45241
+ const raw2 = await this.riskEngineGet(
45242
+ "tool-call-count",
45243
+ {},
45244
+ await this.defaultOrgBrid()
45245
+ );
45158
45246
  const n = Number(raw2);
45159
45247
  return Number.isFinite(n) ? n : 0;
45160
45248
  });
45161
45249
  }
45162
45250
  async getToolCallFull(toolCallId) {
45163
45251
  return this.track("getToolCallFull", void 0, async () => {
45164
- const raw2 = await this.riskEngineGet("tool-call-full", {
45165
- tool_call_id: toolCallId
45166
- });
45252
+ const raw2 = await this.riskEngineGet(
45253
+ "tool-call-full",
45254
+ { tool_call_id: toolCallId },
45255
+ await this.defaultOrgBrid()
45256
+ );
45167
45257
  if (!isRecord(raw2)) return null;
45168
45258
  return toToolCallFull(raw2);
45169
45259
  });
@@ -45249,7 +45339,7 @@ var Atbash = class _Atbash {
45249
45339
  const resp = await this.http.get(
45250
45340
  "/api/insurance",
45251
45341
  { action: "safety-stats" },
45252
- this.authHeaders()
45342
+ this.authHeaders(await this.defaultOrgBrid())
45253
45343
  );
45254
45344
  await this.raiseIfError(resp);
45255
45345
  const data = await this.json(resp) ?? {};
@@ -45281,21 +45371,22 @@ var Atbash = class _Atbash {
45281
45371
  * entry (caller falls back to per-chain subscription resolution).
45282
45372
  */
45283
45373
  async getActiveNetworkForOrg(orgName) {
45374
+ let resp;
45284
45375
  try {
45285
- const resp = await this.http.get(
45376
+ resp = await this.http.get(
45286
45377
  "/api/org-network",
45287
- { org: orgName },
45378
+ { org: orgName.trim() },
45288
45379
  this.authHeaders()
45289
45380
  );
45290
- if (resp.status !== 200) return null;
45291
- const data = await this.json(resp);
45292
- if (data?.network === "public" || data?.network === "private") {
45293
- return data.network;
45294
- }
45295
- return null;
45296
- } catch {
45297
- return null;
45381
+ } catch (err) {
45382
+ throw this.transportError(err);
45383
+ }
45384
+ if (resp.status !== 200) throw await this.httpError(resp);
45385
+ const data = await this.json(resp);
45386
+ if (data?.network === "public" || data?.network === "private") {
45387
+ return data.network;
45298
45388
  }
45389
+ return null;
45299
45390
  }
45300
45391
  /**
45301
45392
  * Resolve which chain an org's actions should run against. Cached
@@ -45304,13 +45395,19 @@ var Atbash = class _Atbash {
45304
45395
  * 2. Per-chain subscription fallback — public + private records
45305
45396
  * are fetched in parallel, with `is_private_blockchain` and
45306
45397
  * `assigned_at` reconciling mixed states.
45307
- * Defaults to the public chain when nothing else resolves.
45398
+ * A lookup that names exactly one chain wins outright. Where it names
45399
+ * neither (a brand-new org) or cannot choose between them, the client's
45400
+ * configured default decides.
45308
45401
  */
45309
45402
  async resolveChainForOrg(orgName) {
45310
- const cached = this._chainCache.get(orgName);
45403
+ const name2 = orgName.trim();
45404
+ if (this._explicitChain) return this._defaultChain;
45405
+ const forced = this.forcedNetwork();
45406
+ if (forced) return chainForNetwork(forced);
45407
+ const cached = this._chainCache.get(name2);
45311
45408
  if (cached) return cached;
45312
- const mapNetwork = await this.getActiveNetworkForOrg(orgName);
45313
- return this.resolveChainFromMap(orgName, mapNetwork);
45409
+ const mapNetwork = await this.getActiveNetworkForOrg(name2);
45410
+ return this.resolveChainFromMap(name2, mapNetwork);
45314
45411
  }
45315
45412
  /**
45316
45413
  * Resolve a chain given an already-fetched `org_networks` map result.
@@ -45326,32 +45423,41 @@ var Atbash = class _Atbash {
45326
45423
  this._chainCache.set(orgName, chain);
45327
45424
  return chain;
45328
45425
  }
45329
- try {
45330
- const [pubSub, privSub] = await Promise.all([
45331
- this.getOrgSubscription(orgName, "public").catch(() => null),
45332
- this.getOrgSubscription(orgName, "private").catch(() => null)
45333
- ]);
45334
- if (pubSub?.is_private_blockchain) {
45335
- this._chainCache.set(orgName, PRIVATE_CHAIN);
45336
- return PRIVATE_CHAIN;
45337
- }
45338
- if (pubSub && privSub) {
45339
- const chain = privSub.assigned_at > pubSub.assigned_at ? PRIVATE_CHAIN : PUBLIC_CHAIN;
45340
- this._chainCache.set(orgName, chain);
45341
- return chain;
45342
- }
45343
- if (pubSub) {
45344
- this._chainCache.set(orgName, PUBLIC_CHAIN);
45345
- return PUBLIC_CHAIN;
45346
- }
45347
- if (privSub?.is_private_blockchain) {
45348
- this._chainCache.set(orgName, PRIVATE_CHAIN);
45349
- return PRIVATE_CHAIN;
45350
- }
45351
- } catch {
45426
+ const [pubRes, privRes] = await Promise.allSettled([
45427
+ this.getOrgSubscription(orgName, "public"),
45428
+ this.getOrgSubscription(orgName, "private")
45429
+ ]);
45430
+ const pubSub = pubRes.status === "fulfilled" ? pubRes.value : null;
45431
+ const privSub = privRes.status === "fulfilled" ? privRes.value : null;
45432
+ const failure = pubRes.status === "rejected" ? pubRes.reason : privRes.status === "rejected" ? privRes.reason : null;
45433
+ if (pubSub?.is_private_blockchain) {
45434
+ this._chainCache.set(orgName, PRIVATE_CHAIN);
45435
+ return PRIVATE_CHAIN;
45436
+ }
45437
+ if (pubSub && privSub) {
45438
+ const chain = privSub.assigned_at === pubSub.assigned_at ? this._defaultChain : privSub.assigned_at > pubSub.assigned_at ? PRIVATE_CHAIN : PUBLIC_CHAIN;
45439
+ this._chainCache.set(orgName, chain);
45440
+ return chain;
45441
+ }
45442
+ if (pubSub) {
45443
+ this._chainCache.set(orgName, PUBLIC_CHAIN);
45444
+ return PUBLIC_CHAIN;
45445
+ }
45446
+ if (privSub?.is_private_blockchain) {
45447
+ this._chainCache.set(orgName, PRIVATE_CHAIN);
45448
+ return PRIVATE_CHAIN;
45449
+ }
45450
+ if (failure) {
45451
+ const detail = failure instanceof Error ? failure.message : String(failure);
45452
+ throw new AtbashAPIError(
45453
+ failure instanceof AtbashAPIError ? failure.status : 0,
45454
+ `could not resolve the chain for org "${orgName}": ${detail}`,
45455
+ "",
45456
+ this.endpoint
45457
+ );
45352
45458
  }
45353
- this._chainCache.set(orgName, PUBLIC_CHAIN);
45354
- return PUBLIC_CHAIN;
45459
+ this._chainCache.set(orgName, this._defaultChain);
45460
+ return this._defaultChain;
45355
45461
  }
45356
45462
  /** Drop any cached chain resolutions. Useful in tests. */
45357
45463
  clearChainCache() {
@@ -45402,6 +45508,7 @@ var Atbash = class _Atbash {
45402
45508
  async resolveAgentLookupNetwork(options) {
45403
45509
  if (options.chainOpts?.network) return options.chainOpts.network;
45404
45510
  if (options.chainOpts?.blockchainRid) return void 0;
45511
+ if (this._explicitChain) return this._defaultChain.network;
45405
45512
  const orgName = options.orgName ?? this.orgName;
45406
45513
  if (!orgName) return void 0;
45407
45514
  return (await this.resolveChainForOrg(orgName)).network;
@@ -45477,6 +45584,30 @@ var Atbash = class _Atbash {
45477
45584
  return void 0;
45478
45585
  }
45479
45586
  }
45587
+ /**
45588
+ * BRID for the client's configured default org, if it has one.
45589
+ *
45590
+ * Calls that carry no `orgName` argument are not chain-less: they still
45591
+ * belong to `this.orgName`, and that org lives on exactly one chain. Routing
45592
+ * them by the constructor's chain instead means a client configured
45593
+ * `network: "private"` reads the private chain for an org that lives on
45594
+ * public, and gets an empty answer rather than an error. So where an org is
45595
+ * known the org decides the chain, and the constructor's chain is what is
45596
+ * left when no org is known at all — the order `resolveAgentLookupNetwork`
45597
+ * already applies to agent metadata reads, and the order the dashboard
45598
+ * applies in `resolveChainForWallet`.
45599
+ *
45600
+ * Undefined when there is no default org, so callers keep falling back to
45601
+ * the client default.
45602
+ */
45603
+ /** The switch's chain, unless this client named one of its own. */
45604
+ forcedNetwork() {
45605
+ return this._explicitChain ? void 0 : this._forcedNetwork;
45606
+ }
45607
+ async defaultOrgBrid() {
45608
+ if (this._explicitChain || !this.orgName) return void 0;
45609
+ return this.bridForOrg(this.orgName);
45610
+ }
45480
45611
  async raiseIfError(resp) {
45481
45612
  if (resp.ok) return;
45482
45613
  throw await this.httpError(resp);
@@ -45842,11 +45973,11 @@ async function commitMemoryVersion(_plaintext, _auth, _opts) {
45842
45973
  async function getActiveMemoryId(_auth, _chainOpts) {
45843
45974
  throw new Error(`getActiveMemoryId ${STUB_MSG3}`);
45844
45975
  }
45845
- async function getActiveMemory(_auth, _chainOpts) {
45846
- throw new Error(`getActiveMemory ${STUB_MSG3}`);
45976
+ async function getRecentAgentMemory(_auth, _chainOpts) {
45977
+ throw new Error(`getRecentAgentMemory ${STUB_MSG3}`);
45847
45978
  }
45848
- async function getAllAgentMemory(_auth, _chainOpts) {
45849
- throw new Error(`getAllAgentMemory ${STUB_MSG3}`);
45979
+ async function getActiveAgentMemory(_auth, _chainOpts) {
45980
+ throw new Error(`getActiveAgentMemory ${STUB_MSG3}`);
45850
45981
  }
45851
45982
  async function getMemoryHistory(_auth, _chainOpts) {
45852
45983
  throw new Error(`getMemoryHistory ${STUB_MSG3}`);
@@ -45925,8 +46056,7 @@ async function guardMemoryWrite(input) {
45925
46056
  toolNames,
45926
46057
  enforce = true,
45927
46058
  debug: debug2 = false,
45928
- logger: logger2,
45929
- memoryFilePath
46059
+ logger: logger2
45930
46060
  } = input;
45931
46061
  const memEntry = classifyMemoryWrite(event, ctx, { patterns, toolNames });
45932
46062
  if (debug2) emitDebugProbe(event, ctx, memEntry, logger2);
@@ -45962,37 +46092,35 @@ async function guardMemoryWrite(input) {
45962
46092
  committed: false
45963
46093
  };
45964
46094
  }
45965
- const isManagedMemoryFile = memoryFilePath !== void 0 && path3.resolve(memEntry.key) === path3.resolve(memoryFilePath);
45966
- if (isManagedMemoryFile) {
45967
- commitMemoryVersion(memEntry.value, auth, {
45968
- score: scanResult.score,
45969
- orgName,
45970
- endpoint
45971
- }).catch((err) => {
45972
- const reason = err instanceof Error ? err.message : String(err);
45973
- logger2?.warn?.("[atbash] memory commit to chain failed", {
45974
- path: memEntry.key,
45975
- reason
45976
- });
46095
+ const filePath = path3.basename(memEntry.key);
46096
+ commitMemoryVersion(memEntry.value, auth, {
46097
+ score: scanResult.score,
46098
+ filePath,
46099
+ orgName,
46100
+ endpoint,
46101
+ verifyPubKey
46102
+ }).catch((err) => {
46103
+ const reason = err instanceof Error ? err.message : String(err);
46104
+ logger2?.warn?.("[atbash] memory commit to chain failed", {
46105
+ path: memEntry.key,
46106
+ filePath,
46107
+ reason
45977
46108
  });
45978
- } else {
45979
- logger2?.info?.(
45980
- "[atbash] scanned but not committed \u2014 not the managed memory file",
45981
- {
45982
- path: memEntry.key,
45983
- memoryFilePath: memoryFilePath ?? "(not configured)"
45984
- }
45985
- );
45986
- }
46109
+ });
45987
46110
  logger2?.info?.(
45988
46111
  scanResult.verdict === "yellow" ? "[atbash] memory HOLD" : "[atbash] memory ALLOW",
45989
- { path: memEntry.key, score: scanResult.score, reason: scanResult.reason }
46112
+ {
46113
+ path: memEntry.key,
46114
+ filePath,
46115
+ score: scanResult.score,
46116
+ reason: scanResult.reason
46117
+ }
45990
46118
  );
45991
46119
  return {
45992
46120
  handled: true,
45993
46121
  decision: { allow: true },
45994
46122
  scanResult,
45995
- committed: isManagedMemoryFile
46123
+ committed: true
45996
46124
  };
45997
46125
  }
45998
46126
 
@@ -46172,10 +46300,13 @@ export {
46172
46300
  KEY_FILENAMES,
46173
46301
  MemoryGuardManager,
46174
46302
  MemoryIntegrityError,
46303
+ PRIVATE_CHAIN,
46304
+ PUBLIC_CHAIN,
46175
46305
  PointerStore,
46176
46306
  SignatureVerificationError,
46177
46307
  bootSyncFailureLine,
46178
46308
  buildAllowedJudgeHosts,
46309
+ chainForNetwork,
46179
46310
  chooseKeyPath,
46180
46311
  claimHashHex,
46181
46312
  classifyMemoryRead,
@@ -46199,13 +46330,13 @@ export {
46199
46330
  encryptedLength,
46200
46331
  flushTelemetry,
46201
46332
  generateKeypair2 as generateKeypair,
46202
- getActiveMemory,
46333
+ getActiveAgentMemory,
46203
46334
  getActiveMemoryId,
46204
- getAllAgentMemory,
46205
46335
  getConfigDir,
46206
46336
  getConfigPath,
46207
46337
  getMemoryById,
46208
46338
  getMemoryHistory,
46339
+ getRecentAgentMemory,
46209
46340
  getRollbackHistory,
46210
46341
  guardMemoryWrite,
46211
46342
  isEnvelope,