@atbash/sdk 0.10.12-dev.0 → 0.10.13-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.
@@ -452,7 +452,7 @@ declare class Atbash {
452
452
  * lazily as a signed `log_tool_call` tx and refreshed every 4 min so
453
453
  * server-side replay protection windows never expire it mid-session.
454
454
  */
455
- private _authBearer;
455
+ private _authBearers;
456
456
  /** Guards `logEnvironmentOnce` — hosts construct several clients. */
457
457
  private static environmentLogged;
458
458
  constructor(privkey: string, options?: AtbashOptions);
@@ -600,6 +600,12 @@ declare class Atbash {
600
600
  private riskEngineGet;
601
601
  private riskEnginePost;
602
602
  private riskEngineRecords;
603
+ /**
604
+ * BRID for an org — one round-trip to the map, honoring the client's chain
605
+ * cache. Returns undefined when the org is unknown, so the caller falls
606
+ * back to the client default (best-effort discovery).
607
+ */
608
+ private bridForOrg;
603
609
  private raiseIfError;
604
610
  /** Wrap a failed HTTP *response* (non-2xx / non-200) as an AtbashAPIError. */
605
611
  private httpError;
package/dist/browser.mjs CHANGED
@@ -44653,7 +44653,11 @@ var Atbash = class _Atbash {
44653
44653
  * lazily as a signed `log_tool_call` tx and refreshed every 4 min so
44654
44654
  * server-side replay protection windows never expire it mid-session.
44655
44655
  */
44656
- _authBearer = null;
44656
+ // Keyed by blockchainRid so bearers for the public and private chains can
44657
+ // coexist. The dashboard derives `authNetwork` from the BRID inside the
44658
+ // signed envelope, so a bearer signed for chain A cannot authenticate a
44659
+ // request routed to chain B — every chain the client talks to needs its own.
44660
+ _authBearers = /* @__PURE__ */ new Map();
44657
44661
  /** Guards `logEnvironmentOnce` — hosts construct several clients. */
44658
44662
  static environmentLogged = false;
44659
44663
  constructor(privkey, options = {}) {
@@ -44769,10 +44773,11 @@ var Atbash = class _Atbash {
44769
44773
  return this.track("checkAgentExists", pk, async () => {
44770
44774
  const query = { pubkey: pk };
44771
44775
  if (network) query.network = network;
44776
+ const brid = this.bridFromChainOpts(network ? { network } : void 0);
44772
44777
  const resp = await this.http.get(
44773
44778
  "/api/ai/exists",
44774
44779
  query,
44775
- this.authHeaders()
44780
+ this.authHeaders(brid)
44776
44781
  );
44777
44782
  await this.raiseIfError(resp);
44778
44783
  const data = await this.json(resp);
@@ -45127,15 +45132,15 @@ var Atbash = class _Atbash {
45127
45132
  () => this.riskEngineRecords("tool-calls", { limit: maxCount })
45128
45133
  );
45129
45134
  }
45130
- getOrgToolCalls(orgName, maxCount) {
45131
- return this.track(
45132
- "getOrgToolCalls",
45133
- void 0,
45134
- () => this.riskEngineRecords("org-tool-calls", {
45135
- org: orgName,
45136
- limit: maxCount
45137
- })
45138
- );
45135
+ async getOrgToolCalls(orgName, maxCount) {
45136
+ return this.track("getOrgToolCalls", void 0, async () => {
45137
+ const brid = await this.bridForOrg(orgName);
45138
+ return this.riskEngineRecords(
45139
+ "org-tool-calls",
45140
+ { org: orgName, limit: maxCount },
45141
+ brid
45142
+ );
45143
+ });
45139
45144
  }
45140
45145
  getAgentToolCalls(agentPubkey, maxCount) {
45141
45146
  return this.track(
@@ -45165,7 +45170,12 @@ var Atbash = class _Atbash {
45165
45170
  }
45166
45171
  async getOrgTierInfo(orgName) {
45167
45172
  return this.track("getOrgTierInfo", void 0, async () => {
45168
- const raw2 = await this.riskEngineGet("org-tier-info", { org: orgName });
45173
+ const brid = await this.bridForOrg(orgName);
45174
+ const raw2 = await this.riskEngineGet(
45175
+ "org-tier-info",
45176
+ { org: orgName },
45177
+ brid
45178
+ );
45169
45179
  if (!isRecord(raw2)) return null;
45170
45180
  return {
45171
45181
  orgName: String(raw2.org_name ?? ""),
@@ -45177,20 +45187,24 @@ var Atbash = class _Atbash {
45177
45187
  }
45178
45188
  async getPendingHeldActions(orgName, maxCount) {
45179
45189
  return this.track("getPendingHeldActions", void 0, async () => {
45180
- const raw2 = await this.riskEngineGet("pending-held-actions", {
45181
- org: orgName,
45182
- limit: maxCount
45183
- });
45190
+ const brid = await this.bridForOrg(orgName);
45191
+ const raw2 = await this.riskEngineGet(
45192
+ "pending-held-actions",
45193
+ { org: orgName, limit: maxCount },
45194
+ brid
45195
+ );
45184
45196
  if (!Array.isArray(raw2)) return [];
45185
45197
  return raw2.map((item) => toHeldAction(item));
45186
45198
  });
45187
45199
  }
45188
45200
  async getHeldActionReviews(orgName, maxCount) {
45189
45201
  return this.track("getHeldActionReviews", void 0, async () => {
45190
- const raw2 = await this.riskEngineGet("held-action-reviews", {
45191
- org: orgName,
45192
- limit: maxCount
45193
- });
45202
+ const brid = await this.bridForOrg(orgName);
45203
+ const raw2 = await this.riskEngineGet(
45204
+ "held-action-reviews",
45205
+ { org: orgName, limit: maxCount },
45206
+ brid
45207
+ );
45194
45208
  if (!Array.isArray(raw2)) return [];
45195
45209
  return raw2.map(
45196
45210
  (item) => toHeldActionReview(item)
@@ -45201,21 +45215,25 @@ var Atbash = class _Atbash {
45201
45215
  async getAgentDetail(agentPubkey, options = {}) {
45202
45216
  return this.track("getAgentDetail", agentPubkey, async () => {
45203
45217
  const network = await this.resolveAgentLookupNetwork(options);
45218
+ const brid = network ? this.bridFromChainOpts({ network }) : void 0;
45204
45219
  return this.riskEnginePost(
45205
45220
  { action: "agent-detail-batch", agent: agentPubkey },
45206
- network
45221
+ network,
45222
+ brid
45207
45223
  );
45208
45224
  });
45209
45225
  }
45210
45226
  async getAgentPolicy(agentPubkey, options = {}) {
45211
45227
  return this.track("getAgentPolicy", agentPubkey, async () => {
45212
45228
  const network = await this.resolveAgentLookupNetwork(options);
45229
+ const brid = network ? this.bridFromChainOpts({ network }) : void 0;
45213
45230
  const raw2 = await this.riskEnginePost(
45214
45231
  {
45215
45232
  action: "agent-policy-batch",
45216
45233
  agent: agentPubkey
45217
45234
  },
45218
- network
45235
+ network,
45236
+ brid
45219
45237
  );
45220
45238
  return {
45221
45239
  policy: String(raw2.policy ?? ""),
@@ -45249,7 +45267,8 @@ var Atbash = class _Atbash {
45249
45267
  return this.track("getOrgSubscription", void 0, async () => {
45250
45268
  const params = { org: orgName };
45251
45269
  if (network) params.network = network;
45252
- const raw2 = await this.riskEngineGet("org-subscription", params);
45270
+ const brid = network ? this.bridFromChainOpts({ network }) : void 0;
45271
+ const raw2 = await this.riskEngineGet("org-subscription", params, brid);
45253
45272
  if (!isRecord(raw2)) return null;
45254
45273
  return coerceOrgSubscription(raw2, orgName);
45255
45274
  });
@@ -45394,11 +45413,11 @@ var Atbash = class _Atbash {
45394
45413
  * for 4 minutes; refreshed after that so a long-lived client never
45395
45414
  * trips the server's replay window.
45396
45415
  */
45397
- getAuthBearer() {
45416
+ getAuthBearer(brid) {
45417
+ const chainBrid = brid ?? this.blockchainRid;
45398
45418
  const now = Date.now();
45399
- if (this._authBearer && now - this._authBearer.issuedAt < 4 * 60 * 1e3) {
45400
- return this._authBearer.hex;
45401
- }
45419
+ const cached = this._authBearers.get(chainBrid);
45420
+ if (cached && now - cached.issuedAt < 4 * 60 * 1e3) return cached.hex;
45402
45421
  const nonce = `auth-${now.toString(36)}-${randomHex(4)}`;
45403
45422
  const hex = native.signLogToolCall(
45404
45423
  nonce,
@@ -45407,21 +45426,21 @@ var Atbash = class _Atbash {
45407
45426
  "auth-bearer",
45408
45427
  "",
45409
45428
  this.auth.privkey,
45410
- this.blockchainRid
45429
+ chainBrid
45411
45430
  );
45412
- this._authBearer = { hex, issuedAt: now };
45431
+ this._authBearers.set(chainBrid, { hex, issuedAt: now });
45413
45432
  return hex;
45414
45433
  }
45415
- authHeaders() {
45416
- return { Authorization: `Bearer ${this.getAuthBearer()}` };
45434
+ authHeaders(brid) {
45435
+ return { Authorization: `Bearer ${this.getAuthBearer(brid)}` };
45417
45436
  }
45418
- async riskEngineGet(action, params) {
45437
+ async riskEngineGet(action, params, brid) {
45419
45438
  let resp;
45420
45439
  try {
45421
45440
  resp = await this.http.get(
45422
45441
  "/api/risk-engine",
45423
45442
  { action, ...params },
45424
- this.authHeaders()
45443
+ this.authHeaders(brid)
45425
45444
  );
45426
45445
  } catch (err) {
45427
45446
  throw this.transportError(err);
@@ -45429,11 +45448,11 @@ var Atbash = class _Atbash {
45429
45448
  if (resp.status !== 200) throw await this.httpError(resp);
45430
45449
  return this.json(resp);
45431
45450
  }
45432
- async riskEnginePost(body, network) {
45451
+ async riskEnginePost(body, network, brid) {
45433
45452
  let resp;
45434
45453
  try {
45435
45454
  const path4 = network ? `/api/risk-engine?network=${encodeURIComponent(network)}` : "/api/risk-engine";
45436
- resp = await this.http.post(path4, body, this.authHeaders());
45455
+ resp = await this.http.post(path4, body, this.authHeaders(brid));
45437
45456
  } catch (err) {
45438
45457
  throw this.transportError(err);
45439
45458
  }
@@ -45441,11 +45460,23 @@ var Atbash = class _Atbash {
45441
45460
  const data = await this.json(resp);
45442
45461
  return isRecord(data) ? data : {};
45443
45462
  }
45444
- async riskEngineRecords(action, params) {
45445
- const raw2 = await this.riskEngineGet(action, params);
45463
+ async riskEngineRecords(action, params, brid) {
45464
+ const raw2 = await this.riskEngineGet(action, params, brid);
45446
45465
  if (!Array.isArray(raw2)) return [];
45447
45466
  return raw2.map((item) => toToolCallRecord(item));
45448
45467
  }
45468
+ /**
45469
+ * BRID for an org — one round-trip to the map, honoring the client's chain
45470
+ * cache. Returns undefined when the org is unknown, so the caller falls
45471
+ * back to the client default (best-effort discovery).
45472
+ */
45473
+ async bridForOrg(orgName) {
45474
+ try {
45475
+ return (await this.resolveChainForOrg(orgName)).blockchainRid;
45476
+ } catch {
45477
+ return void 0;
45478
+ }
45479
+ }
45449
45480
  async raiseIfError(resp) {
45450
45481
  if (resp.ok) return;
45451
45482
  throw await this.httpError(resp);