@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/browser.d.mts +7 -1
- package/dist/browser.mjs +68 -37
- package/dist/browser.mjs.map +1 -1
- package/dist/index.d.mts +7 -1
- package/dist/index.d.ts +7 -1
- package/dist/index.js +68 -37
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +68 -37
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -5
package/dist/index.d.mts
CHANGED
|
@@ -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
|
|
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/index.d.ts
CHANGED
|
@@ -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
|
|
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/index.js
CHANGED
|
@@ -3481,7 +3481,11 @@ var Atbash = class _Atbash {
|
|
|
3481
3481
|
* lazily as a signed `log_tool_call` tx and refreshed every 4 min so
|
|
3482
3482
|
* server-side replay protection windows never expire it mid-session.
|
|
3483
3483
|
*/
|
|
3484
|
-
|
|
3484
|
+
// Keyed by blockchainRid so bearers for the public and private chains can
|
|
3485
|
+
// coexist. The dashboard derives `authNetwork` from the BRID inside the
|
|
3486
|
+
// signed envelope, so a bearer signed for chain A cannot authenticate a
|
|
3487
|
+
// request routed to chain B — every chain the client talks to needs its own.
|
|
3488
|
+
_authBearers = /* @__PURE__ */ new Map();
|
|
3485
3489
|
/** Guards `logEnvironmentOnce` — hosts construct several clients. */
|
|
3486
3490
|
static environmentLogged = false;
|
|
3487
3491
|
constructor(privkey, options = {}) {
|
|
@@ -3597,10 +3601,11 @@ var Atbash = class _Atbash {
|
|
|
3597
3601
|
return this.track("checkAgentExists", pk, async () => {
|
|
3598
3602
|
const query = { pubkey: pk };
|
|
3599
3603
|
if (network) query.network = network;
|
|
3604
|
+
const brid = this.bridFromChainOpts(network ? { network } : void 0);
|
|
3600
3605
|
const resp = await this.http.get(
|
|
3601
3606
|
"/api/ai/exists",
|
|
3602
3607
|
query,
|
|
3603
|
-
this.authHeaders()
|
|
3608
|
+
this.authHeaders(brid)
|
|
3604
3609
|
);
|
|
3605
3610
|
await this.raiseIfError(resp);
|
|
3606
3611
|
const data = await this.json(resp);
|
|
@@ -3955,15 +3960,15 @@ var Atbash = class _Atbash {
|
|
|
3955
3960
|
() => this.riskEngineRecords("tool-calls", { limit: maxCount })
|
|
3956
3961
|
);
|
|
3957
3962
|
}
|
|
3958
|
-
getOrgToolCalls(orgName, maxCount) {
|
|
3959
|
-
return this.track(
|
|
3960
|
-
|
|
3961
|
-
|
|
3962
|
-
|
|
3963
|
-
org: orgName,
|
|
3964
|
-
|
|
3965
|
-
|
|
3966
|
-
);
|
|
3963
|
+
async getOrgToolCalls(orgName, maxCount) {
|
|
3964
|
+
return this.track("getOrgToolCalls", void 0, async () => {
|
|
3965
|
+
const brid = await this.bridForOrg(orgName);
|
|
3966
|
+
return this.riskEngineRecords(
|
|
3967
|
+
"org-tool-calls",
|
|
3968
|
+
{ org: orgName, limit: maxCount },
|
|
3969
|
+
brid
|
|
3970
|
+
);
|
|
3971
|
+
});
|
|
3967
3972
|
}
|
|
3968
3973
|
getAgentToolCalls(agentPubkey, maxCount) {
|
|
3969
3974
|
return this.track(
|
|
@@ -3993,7 +3998,12 @@ var Atbash = class _Atbash {
|
|
|
3993
3998
|
}
|
|
3994
3999
|
async getOrgTierInfo(orgName) {
|
|
3995
4000
|
return this.track("getOrgTierInfo", void 0, async () => {
|
|
3996
|
-
const
|
|
4001
|
+
const brid = await this.bridForOrg(orgName);
|
|
4002
|
+
const raw2 = await this.riskEngineGet(
|
|
4003
|
+
"org-tier-info",
|
|
4004
|
+
{ org: orgName },
|
|
4005
|
+
brid
|
|
4006
|
+
);
|
|
3997
4007
|
if (!isRecord(raw2)) return null;
|
|
3998
4008
|
return {
|
|
3999
4009
|
orgName: String(raw2.org_name ?? ""),
|
|
@@ -4005,20 +4015,24 @@ var Atbash = class _Atbash {
|
|
|
4005
4015
|
}
|
|
4006
4016
|
async getPendingHeldActions(orgName, maxCount) {
|
|
4007
4017
|
return this.track("getPendingHeldActions", void 0, async () => {
|
|
4008
|
-
const
|
|
4009
|
-
|
|
4010
|
-
|
|
4011
|
-
|
|
4018
|
+
const brid = await this.bridForOrg(orgName);
|
|
4019
|
+
const raw2 = await this.riskEngineGet(
|
|
4020
|
+
"pending-held-actions",
|
|
4021
|
+
{ org: orgName, limit: maxCount },
|
|
4022
|
+
brid
|
|
4023
|
+
);
|
|
4012
4024
|
if (!Array.isArray(raw2)) return [];
|
|
4013
4025
|
return raw2.map((item) => toHeldAction(item));
|
|
4014
4026
|
});
|
|
4015
4027
|
}
|
|
4016
4028
|
async getHeldActionReviews(orgName, maxCount) {
|
|
4017
4029
|
return this.track("getHeldActionReviews", void 0, async () => {
|
|
4018
|
-
const
|
|
4019
|
-
|
|
4020
|
-
|
|
4021
|
-
|
|
4030
|
+
const brid = await this.bridForOrg(orgName);
|
|
4031
|
+
const raw2 = await this.riskEngineGet(
|
|
4032
|
+
"held-action-reviews",
|
|
4033
|
+
{ org: orgName, limit: maxCount },
|
|
4034
|
+
brid
|
|
4035
|
+
);
|
|
4022
4036
|
if (!Array.isArray(raw2)) return [];
|
|
4023
4037
|
return raw2.map(
|
|
4024
4038
|
(item) => toHeldActionReview(item)
|
|
@@ -4029,21 +4043,25 @@ var Atbash = class _Atbash {
|
|
|
4029
4043
|
async getAgentDetail(agentPubkey, options = {}) {
|
|
4030
4044
|
return this.track("getAgentDetail", agentPubkey, async () => {
|
|
4031
4045
|
const network = await this.resolveAgentLookupNetwork(options);
|
|
4046
|
+
const brid = network ? this.bridFromChainOpts({ network }) : void 0;
|
|
4032
4047
|
return this.riskEnginePost(
|
|
4033
4048
|
{ action: "agent-detail-batch", agent: agentPubkey },
|
|
4034
|
-
network
|
|
4049
|
+
network,
|
|
4050
|
+
brid
|
|
4035
4051
|
);
|
|
4036
4052
|
});
|
|
4037
4053
|
}
|
|
4038
4054
|
async getAgentPolicy(agentPubkey, options = {}) {
|
|
4039
4055
|
return this.track("getAgentPolicy", agentPubkey, async () => {
|
|
4040
4056
|
const network = await this.resolveAgentLookupNetwork(options);
|
|
4057
|
+
const brid = network ? this.bridFromChainOpts({ network }) : void 0;
|
|
4041
4058
|
const raw2 = await this.riskEnginePost(
|
|
4042
4059
|
{
|
|
4043
4060
|
action: "agent-policy-batch",
|
|
4044
4061
|
agent: agentPubkey
|
|
4045
4062
|
},
|
|
4046
|
-
network
|
|
4063
|
+
network,
|
|
4064
|
+
brid
|
|
4047
4065
|
);
|
|
4048
4066
|
return {
|
|
4049
4067
|
policy: String(raw2.policy ?? ""),
|
|
@@ -4077,7 +4095,8 @@ var Atbash = class _Atbash {
|
|
|
4077
4095
|
return this.track("getOrgSubscription", void 0, async () => {
|
|
4078
4096
|
const params = { org: orgName };
|
|
4079
4097
|
if (network) params.network = network;
|
|
4080
|
-
const
|
|
4098
|
+
const brid = network ? this.bridFromChainOpts({ network }) : void 0;
|
|
4099
|
+
const raw2 = await this.riskEngineGet("org-subscription", params, brid);
|
|
4081
4100
|
if (!isRecord(raw2)) return null;
|
|
4082
4101
|
return coerceOrgSubscription(raw2, orgName);
|
|
4083
4102
|
});
|
|
@@ -4222,11 +4241,11 @@ var Atbash = class _Atbash {
|
|
|
4222
4241
|
* for 4 minutes; refreshed after that so a long-lived client never
|
|
4223
4242
|
* trips the server's replay window.
|
|
4224
4243
|
*/
|
|
4225
|
-
getAuthBearer() {
|
|
4244
|
+
getAuthBearer(brid) {
|
|
4245
|
+
const chainBrid = brid ?? this.blockchainRid;
|
|
4226
4246
|
const now = Date.now();
|
|
4227
|
-
|
|
4228
|
-
|
|
4229
|
-
}
|
|
4247
|
+
const cached = this._authBearers.get(chainBrid);
|
|
4248
|
+
if (cached && now - cached.issuedAt < 4 * 60 * 1e3) return cached.hex;
|
|
4230
4249
|
const nonce = `auth-${now.toString(36)}-${randomHex(4)}`;
|
|
4231
4250
|
const hex = native.signLogToolCall(
|
|
4232
4251
|
nonce,
|
|
@@ -4235,21 +4254,21 @@ var Atbash = class _Atbash {
|
|
|
4235
4254
|
"auth-bearer",
|
|
4236
4255
|
"",
|
|
4237
4256
|
this.auth.privkey,
|
|
4238
|
-
|
|
4257
|
+
chainBrid
|
|
4239
4258
|
);
|
|
4240
|
-
this.
|
|
4259
|
+
this._authBearers.set(chainBrid, { hex, issuedAt: now });
|
|
4241
4260
|
return hex;
|
|
4242
4261
|
}
|
|
4243
|
-
authHeaders() {
|
|
4244
|
-
return { Authorization: `Bearer ${this.getAuthBearer()}` };
|
|
4262
|
+
authHeaders(brid) {
|
|
4263
|
+
return { Authorization: `Bearer ${this.getAuthBearer(brid)}` };
|
|
4245
4264
|
}
|
|
4246
|
-
async riskEngineGet(action, params) {
|
|
4265
|
+
async riskEngineGet(action, params, brid) {
|
|
4247
4266
|
let resp;
|
|
4248
4267
|
try {
|
|
4249
4268
|
resp = await this.http.get(
|
|
4250
4269
|
"/api/risk-engine",
|
|
4251
4270
|
{ action, ...params },
|
|
4252
|
-
this.authHeaders()
|
|
4271
|
+
this.authHeaders(brid)
|
|
4253
4272
|
);
|
|
4254
4273
|
} catch (err) {
|
|
4255
4274
|
throw this.transportError(err);
|
|
@@ -4257,11 +4276,11 @@ var Atbash = class _Atbash {
|
|
|
4257
4276
|
if (resp.status !== 200) throw await this.httpError(resp);
|
|
4258
4277
|
return this.json(resp);
|
|
4259
4278
|
}
|
|
4260
|
-
async riskEnginePost(body, network) {
|
|
4279
|
+
async riskEnginePost(body, network, brid) {
|
|
4261
4280
|
let resp;
|
|
4262
4281
|
try {
|
|
4263
4282
|
const path7 = network ? `/api/risk-engine?network=${encodeURIComponent(network)}` : "/api/risk-engine";
|
|
4264
|
-
resp = await this.http.post(path7, body, this.authHeaders());
|
|
4283
|
+
resp = await this.http.post(path7, body, this.authHeaders(brid));
|
|
4265
4284
|
} catch (err) {
|
|
4266
4285
|
throw this.transportError(err);
|
|
4267
4286
|
}
|
|
@@ -4269,11 +4288,23 @@ var Atbash = class _Atbash {
|
|
|
4269
4288
|
const data = await this.json(resp);
|
|
4270
4289
|
return isRecord(data) ? data : {};
|
|
4271
4290
|
}
|
|
4272
|
-
async riskEngineRecords(action, params) {
|
|
4273
|
-
const raw2 = await this.riskEngineGet(action, params);
|
|
4291
|
+
async riskEngineRecords(action, params, brid) {
|
|
4292
|
+
const raw2 = await this.riskEngineGet(action, params, brid);
|
|
4274
4293
|
if (!Array.isArray(raw2)) return [];
|
|
4275
4294
|
return raw2.map((item) => toToolCallRecord(item));
|
|
4276
4295
|
}
|
|
4296
|
+
/**
|
|
4297
|
+
* BRID for an org — one round-trip to the map, honoring the client's chain
|
|
4298
|
+
* cache. Returns undefined when the org is unknown, so the caller falls
|
|
4299
|
+
* back to the client default (best-effort discovery).
|
|
4300
|
+
*/
|
|
4301
|
+
async bridForOrg(orgName) {
|
|
4302
|
+
try {
|
|
4303
|
+
return (await this.resolveChainForOrg(orgName)).blockchainRid;
|
|
4304
|
+
} catch {
|
|
4305
|
+
return void 0;
|
|
4306
|
+
}
|
|
4307
|
+
}
|
|
4277
4308
|
async raiseIfError(resp) {
|
|
4278
4309
|
if (resp.ok) return;
|
|
4279
4310
|
throw await this.httpError(resp);
|