@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.
package/dist/index.mjs CHANGED
@@ -3400,7 +3400,11 @@ var Atbash = class _Atbash {
3400
3400
  * lazily as a signed `log_tool_call` tx and refreshed every 4 min so
3401
3401
  * server-side replay protection windows never expire it mid-session.
3402
3402
  */
3403
- _authBearer = null;
3403
+ // Keyed by blockchainRid so bearers for the public and private chains can
3404
+ // coexist. The dashboard derives `authNetwork` from the BRID inside the
3405
+ // signed envelope, so a bearer signed for chain A cannot authenticate a
3406
+ // request routed to chain B — every chain the client talks to needs its own.
3407
+ _authBearers = /* @__PURE__ */ new Map();
3404
3408
  /** Guards `logEnvironmentOnce` — hosts construct several clients. */
3405
3409
  static environmentLogged = false;
3406
3410
  constructor(privkey, options = {}) {
@@ -3516,10 +3520,11 @@ var Atbash = class _Atbash {
3516
3520
  return this.track("checkAgentExists", pk, async () => {
3517
3521
  const query = { pubkey: pk };
3518
3522
  if (network) query.network = network;
3523
+ const brid = this.bridFromChainOpts(network ? { network } : void 0);
3519
3524
  const resp = await this.http.get(
3520
3525
  "/api/ai/exists",
3521
3526
  query,
3522
- this.authHeaders()
3527
+ this.authHeaders(brid)
3523
3528
  );
3524
3529
  await this.raiseIfError(resp);
3525
3530
  const data = await this.json(resp);
@@ -3874,15 +3879,15 @@ var Atbash = class _Atbash {
3874
3879
  () => this.riskEngineRecords("tool-calls", { limit: maxCount })
3875
3880
  );
3876
3881
  }
3877
- getOrgToolCalls(orgName, maxCount) {
3878
- return this.track(
3879
- "getOrgToolCalls",
3880
- void 0,
3881
- () => this.riskEngineRecords("org-tool-calls", {
3882
- org: orgName,
3883
- limit: maxCount
3884
- })
3885
- );
3882
+ async getOrgToolCalls(orgName, maxCount) {
3883
+ return this.track("getOrgToolCalls", void 0, async () => {
3884
+ const brid = await this.bridForOrg(orgName);
3885
+ return this.riskEngineRecords(
3886
+ "org-tool-calls",
3887
+ { org: orgName, limit: maxCount },
3888
+ brid
3889
+ );
3890
+ });
3886
3891
  }
3887
3892
  getAgentToolCalls(agentPubkey, maxCount) {
3888
3893
  return this.track(
@@ -3912,7 +3917,12 @@ var Atbash = class _Atbash {
3912
3917
  }
3913
3918
  async getOrgTierInfo(orgName) {
3914
3919
  return this.track("getOrgTierInfo", void 0, async () => {
3915
- const raw2 = await this.riskEngineGet("org-tier-info", { org: orgName });
3920
+ const brid = await this.bridForOrg(orgName);
3921
+ const raw2 = await this.riskEngineGet(
3922
+ "org-tier-info",
3923
+ { org: orgName },
3924
+ brid
3925
+ );
3916
3926
  if (!isRecord(raw2)) return null;
3917
3927
  return {
3918
3928
  orgName: String(raw2.org_name ?? ""),
@@ -3924,20 +3934,24 @@ var Atbash = class _Atbash {
3924
3934
  }
3925
3935
  async getPendingHeldActions(orgName, maxCount) {
3926
3936
  return this.track("getPendingHeldActions", void 0, async () => {
3927
- const raw2 = await this.riskEngineGet("pending-held-actions", {
3928
- org: orgName,
3929
- limit: maxCount
3930
- });
3937
+ const brid = await this.bridForOrg(orgName);
3938
+ const raw2 = await this.riskEngineGet(
3939
+ "pending-held-actions",
3940
+ { org: orgName, limit: maxCount },
3941
+ brid
3942
+ );
3931
3943
  if (!Array.isArray(raw2)) return [];
3932
3944
  return raw2.map((item) => toHeldAction(item));
3933
3945
  });
3934
3946
  }
3935
3947
  async getHeldActionReviews(orgName, maxCount) {
3936
3948
  return this.track("getHeldActionReviews", void 0, async () => {
3937
- const raw2 = await this.riskEngineGet("held-action-reviews", {
3938
- org: orgName,
3939
- limit: maxCount
3940
- });
3949
+ const brid = await this.bridForOrg(orgName);
3950
+ const raw2 = await this.riskEngineGet(
3951
+ "held-action-reviews",
3952
+ { org: orgName, limit: maxCount },
3953
+ brid
3954
+ );
3941
3955
  if (!Array.isArray(raw2)) return [];
3942
3956
  return raw2.map(
3943
3957
  (item) => toHeldActionReview(item)
@@ -3948,21 +3962,25 @@ var Atbash = class _Atbash {
3948
3962
  async getAgentDetail(agentPubkey, options = {}) {
3949
3963
  return this.track("getAgentDetail", agentPubkey, async () => {
3950
3964
  const network = await this.resolveAgentLookupNetwork(options);
3965
+ const brid = network ? this.bridFromChainOpts({ network }) : void 0;
3951
3966
  return this.riskEnginePost(
3952
3967
  { action: "agent-detail-batch", agent: agentPubkey },
3953
- network
3968
+ network,
3969
+ brid
3954
3970
  );
3955
3971
  });
3956
3972
  }
3957
3973
  async getAgentPolicy(agentPubkey, options = {}) {
3958
3974
  return this.track("getAgentPolicy", agentPubkey, async () => {
3959
3975
  const network = await this.resolveAgentLookupNetwork(options);
3976
+ const brid = network ? this.bridFromChainOpts({ network }) : void 0;
3960
3977
  const raw2 = await this.riskEnginePost(
3961
3978
  {
3962
3979
  action: "agent-policy-batch",
3963
3980
  agent: agentPubkey
3964
3981
  },
3965
- network
3982
+ network,
3983
+ brid
3966
3984
  );
3967
3985
  return {
3968
3986
  policy: String(raw2.policy ?? ""),
@@ -3996,7 +4014,8 @@ var Atbash = class _Atbash {
3996
4014
  return this.track("getOrgSubscription", void 0, async () => {
3997
4015
  const params = { org: orgName };
3998
4016
  if (network) params.network = network;
3999
- const raw2 = await this.riskEngineGet("org-subscription", params);
4017
+ const brid = network ? this.bridFromChainOpts({ network }) : void 0;
4018
+ const raw2 = await this.riskEngineGet("org-subscription", params, brid);
4000
4019
  if (!isRecord(raw2)) return null;
4001
4020
  return coerceOrgSubscription(raw2, orgName);
4002
4021
  });
@@ -4141,11 +4160,11 @@ var Atbash = class _Atbash {
4141
4160
  * for 4 minutes; refreshed after that so a long-lived client never
4142
4161
  * trips the server's replay window.
4143
4162
  */
4144
- getAuthBearer() {
4163
+ getAuthBearer(brid) {
4164
+ const chainBrid = brid ?? this.blockchainRid;
4145
4165
  const now = Date.now();
4146
- if (this._authBearer && now - this._authBearer.issuedAt < 4 * 60 * 1e3) {
4147
- return this._authBearer.hex;
4148
- }
4166
+ const cached = this._authBearers.get(chainBrid);
4167
+ if (cached && now - cached.issuedAt < 4 * 60 * 1e3) return cached.hex;
4149
4168
  const nonce = `auth-${now.toString(36)}-${randomHex(4)}`;
4150
4169
  const hex = native.signLogToolCall(
4151
4170
  nonce,
@@ -4154,21 +4173,21 @@ var Atbash = class _Atbash {
4154
4173
  "auth-bearer",
4155
4174
  "",
4156
4175
  this.auth.privkey,
4157
- this.blockchainRid
4176
+ chainBrid
4158
4177
  );
4159
- this._authBearer = { hex, issuedAt: now };
4178
+ this._authBearers.set(chainBrid, { hex, issuedAt: now });
4160
4179
  return hex;
4161
4180
  }
4162
- authHeaders() {
4163
- return { Authorization: `Bearer ${this.getAuthBearer()}` };
4181
+ authHeaders(brid) {
4182
+ return { Authorization: `Bearer ${this.getAuthBearer(brid)}` };
4164
4183
  }
4165
- async riskEngineGet(action, params) {
4184
+ async riskEngineGet(action, params, brid) {
4166
4185
  let resp;
4167
4186
  try {
4168
4187
  resp = await this.http.get(
4169
4188
  "/api/risk-engine",
4170
4189
  { action, ...params },
4171
- this.authHeaders()
4190
+ this.authHeaders(brid)
4172
4191
  );
4173
4192
  } catch (err) {
4174
4193
  throw this.transportError(err);
@@ -4176,11 +4195,11 @@ var Atbash = class _Atbash {
4176
4195
  if (resp.status !== 200) throw await this.httpError(resp);
4177
4196
  return this.json(resp);
4178
4197
  }
4179
- async riskEnginePost(body, network) {
4198
+ async riskEnginePost(body, network, brid) {
4180
4199
  let resp;
4181
4200
  try {
4182
4201
  const path7 = network ? `/api/risk-engine?network=${encodeURIComponent(network)}` : "/api/risk-engine";
4183
- resp = await this.http.post(path7, body, this.authHeaders());
4202
+ resp = await this.http.post(path7, body, this.authHeaders(brid));
4184
4203
  } catch (err) {
4185
4204
  throw this.transportError(err);
4186
4205
  }
@@ -4188,11 +4207,23 @@ var Atbash = class _Atbash {
4188
4207
  const data = await this.json(resp);
4189
4208
  return isRecord(data) ? data : {};
4190
4209
  }
4191
- async riskEngineRecords(action, params) {
4192
- const raw2 = await this.riskEngineGet(action, params);
4210
+ async riskEngineRecords(action, params, brid) {
4211
+ const raw2 = await this.riskEngineGet(action, params, brid);
4193
4212
  if (!Array.isArray(raw2)) return [];
4194
4213
  return raw2.map((item) => toToolCallRecord(item));
4195
4214
  }
4215
+ /**
4216
+ * BRID for an org — one round-trip to the map, honoring the client's chain
4217
+ * cache. Returns undefined when the org is unknown, so the caller falls
4218
+ * back to the client default (best-effort discovery).
4219
+ */
4220
+ async bridForOrg(orgName) {
4221
+ try {
4222
+ return (await this.resolveChainForOrg(orgName)).blockchainRid;
4223
+ } catch {
4224
+ return void 0;
4225
+ }
4226
+ }
4196
4227
  async raiseIfError(resp) {
4197
4228
  if (resp.ok) return;
4198
4229
  throw await this.httpError(resp);