@atbash/sdk 0.10.9-dev.0 → 0.10.11-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/README.md +12 -2
- package/dist/browser.d.mts +116 -24
- package/dist/browser.mjs +164 -83
- package/dist/browser.mjs.map +1 -1
- package/dist/index.d.mts +116 -24
- package/dist/index.d.ts +116 -24
- package/dist/index.js +288 -124
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +288 -124
- package/dist/index.mjs.map +1 -1
- package/index.d.ts +0 -2
- package/index.js +0 -1
- package/package.json +5 -5
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(
|
|
10058
|
-
this.path =
|
|
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(
|
|
30280
|
-
this.path =
|
|
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:
|
|
33311
|
-
const fullPath = [...
|
|
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,
|
|
33448
|
+
constructor(parent, value, path4, key3) {
|
|
33449
33449
|
this._cachedPath = [];
|
|
33450
33450
|
this.parent = parent;
|
|
33451
33451
|
this.data = value;
|
|
33452
|
-
this._path =
|
|
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,
|
|
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(
|
|
40361
|
+
return yield get(path4, endpoint, timeout);
|
|
40362
40362
|
} else {
|
|
40363
|
-
return yield post(
|
|
40363
|
+
return yield post(path4, endpoint, timeout, postObject);
|
|
40364
40364
|
}
|
|
40365
40365
|
});
|
|
40366
40366
|
}
|
|
40367
|
-
function get(
|
|
40367
|
+
function get(path4, endpoint, timeout) {
|
|
40368
40368
|
return __awaiter$2(this, void 0, void 0, function* () {
|
|
40369
|
-
logger.debug(`GET URL ${new URL(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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,
|
|
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:
|
|
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,
|
|
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:
|
|
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,
|
|
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,
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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
|
}
|
|
@@ -43452,9 +43452,6 @@ var native = {
|
|
|
43452
43452
|
DEFAULT_BLOCKCHAIN_RID: ATBASH_BLOCKCHAIN_RID,
|
|
43453
43453
|
DEFAULT_PRIVATE_BLOCKCHAIN_RID: ATBASH_PRIVATE_BLOCKCHAIN_RID,
|
|
43454
43454
|
DEFAULT_ENDPOINT: ATBASH_ENDPOINT,
|
|
43455
|
-
// Browser has no NAPI channel to Rust's HONEYCOMB_KEY — telemetry
|
|
43456
|
-
// silently no-ops. `HONEYCOMB_API_KEY` env var still overrides at runtime.
|
|
43457
|
-
HONEYCOMB_KEY: "",
|
|
43458
43455
|
defaultChromiaNodeUrls: () => [...DEFAULT_CHROMIA_NODE_URLS_ARR],
|
|
43459
43456
|
defaultPrivateNodeUrls: () => [...DEFAULT_PRIVATE_NODE_URLS_ARR],
|
|
43460
43457
|
// Server-only surfaces — throw at runtime, keep types satisfied.
|
|
@@ -44453,8 +44450,8 @@ var HttpClient = class {
|
|
|
44453
44450
|
this.baseUrl = baseUrl.replace(/\/+$/, "");
|
|
44454
44451
|
this.timeoutMs = timeoutMs;
|
|
44455
44452
|
}
|
|
44456
|
-
buildUrl(
|
|
44457
|
-
const url = new URL(this.baseUrl +
|
|
44453
|
+
buildUrl(path4, query) {
|
|
44454
|
+
const url = new URL(this.baseUrl + path4);
|
|
44458
44455
|
if (query) {
|
|
44459
44456
|
for (const [k, v] of Object.entries(query)) {
|
|
44460
44457
|
if (v !== void 0 && v !== null && v !== "") {
|
|
@@ -44464,14 +44461,14 @@ var HttpClient = class {
|
|
|
44464
44461
|
}
|
|
44465
44462
|
return url.toString();
|
|
44466
44463
|
}
|
|
44467
|
-
async get(
|
|
44468
|
-
return this.fetch(this.buildUrl(
|
|
44464
|
+
async get(path4, query, headers) {
|
|
44465
|
+
return this.fetch(this.buildUrl(path4, query), {
|
|
44469
44466
|
method: "GET",
|
|
44470
44467
|
...headers && { headers }
|
|
44471
44468
|
});
|
|
44472
44469
|
}
|
|
44473
|
-
async post(
|
|
44474
|
-
return this.fetch(this.buildUrl(
|
|
44470
|
+
async post(path4, body, headers) {
|
|
44471
|
+
return this.fetch(this.buildUrl(path4), {
|
|
44475
44472
|
method: "POST",
|
|
44476
44473
|
headers: { "Content-Type": "application/json", ...headers },
|
|
44477
44474
|
body: JSON.stringify(body)
|
|
@@ -44641,6 +44638,16 @@ var Atbash = class _Atbash {
|
|
|
44641
44638
|
* calls don't re-hit the dashboard. Cleared by `clearChainCache()`.
|
|
44642
44639
|
*/
|
|
44643
44640
|
_chainCache = /* @__PURE__ */ new Map();
|
|
44641
|
+
/**
|
|
44642
|
+
* Short-TTL cache for `/api/ai/exists`. The `registered` field is
|
|
44643
|
+
* monotonic (once true, stays true), so most calls in a burst re-fetch
|
|
44644
|
+
* data that hasn't changed. The `org_encryption_pubkey` field CAN change
|
|
44645
|
+
* — an org toggling encryption mid-session — so the TTL is deliberately
|
|
44646
|
+
* short (see `AGENT_EXISTS_TTL_MS`). Keyed by (pubkey, network) so
|
|
44647
|
+
* cross-agent / cross-network calls don't collide.
|
|
44648
|
+
*/
|
|
44649
|
+
_agentExistsCache = null;
|
|
44650
|
+
static AGENT_EXISTS_TTL_MS = 5e3;
|
|
44644
44651
|
/**
|
|
44645
44652
|
* Cached bearer token for risk-engine / insurance read calls. Built
|
|
44646
44653
|
* lazily as a signed `log_tool_call` tx and refreshed every 4 min so
|
|
@@ -44668,6 +44675,16 @@ var Atbash = class _Atbash {
|
|
|
44668
44675
|
verifying: this.verifyPubKey ? "with response-signature pubkey configured" : "without signature verification"
|
|
44669
44676
|
});
|
|
44670
44677
|
}
|
|
44678
|
+
try {
|
|
44679
|
+
setupTelemetry({
|
|
44680
|
+
enabled: true,
|
|
44681
|
+
source: "sdk",
|
|
44682
|
+
endpoint: this.endpoint,
|
|
44683
|
+
getAuthHeaders: () => this.authHeaders()
|
|
44684
|
+
});
|
|
44685
|
+
} catch (err) {
|
|
44686
|
+
this.logger.warn?.("[atbash] telemetry setup failed \u2014 continuing without metrics", { error: String(err) });
|
|
44687
|
+
}
|
|
44671
44688
|
}
|
|
44672
44689
|
/**
|
|
44673
44690
|
* Say which environment this build talks to, once per process.
|
|
@@ -44740,9 +44757,18 @@ var Atbash = class _Atbash {
|
|
|
44740
44757
|
*/
|
|
44741
44758
|
async checkAgentExists(pubkey, opts) {
|
|
44742
44759
|
const pk = pubkey ?? this.auth.pubkey;
|
|
44760
|
+
const network = opts?.network;
|
|
44761
|
+
const now = Date.now();
|
|
44762
|
+
const cached = this._agentExistsCache;
|
|
44763
|
+
if (cached && cached.pubkey === pk && cached.network === network && cached.expiresAt > now) {
|
|
44764
|
+
if (pk === this.auth.pubkey) {
|
|
44765
|
+
this._orgKeyFromChain = cached.orgKey;
|
|
44766
|
+
}
|
|
44767
|
+
return cached.registered;
|
|
44768
|
+
}
|
|
44743
44769
|
return this.track("checkAgentExists", pk, async () => {
|
|
44744
44770
|
const query = { pubkey: pk };
|
|
44745
|
-
if (
|
|
44771
|
+
if (network) query.network = network;
|
|
44746
44772
|
const resp = await this.http.get(
|
|
44747
44773
|
"/api/ai/exists",
|
|
44748
44774
|
query,
|
|
@@ -44750,11 +44776,21 @@ var Atbash = class _Atbash {
|
|
|
44750
44776
|
);
|
|
44751
44777
|
await this.raiseIfError(resp);
|
|
44752
44778
|
const data = await this.json(resp);
|
|
44779
|
+
const registered = Boolean(data?.registered);
|
|
44780
|
+
const orgKey = typeof data?.org_encryption_pubkey === "string" && data.org_encryption_pubkey ? data.org_encryption_pubkey : null;
|
|
44781
|
+
if (registered) {
|
|
44782
|
+
this._agentExistsCache = {
|
|
44783
|
+
pubkey: pk,
|
|
44784
|
+
network,
|
|
44785
|
+
expiresAt: Date.now() + _Atbash.AGENT_EXISTS_TTL_MS,
|
|
44786
|
+
registered,
|
|
44787
|
+
orgKey
|
|
44788
|
+
};
|
|
44789
|
+
}
|
|
44753
44790
|
if (pk === this.auth.pubkey) {
|
|
44754
|
-
|
|
44755
|
-
this._orgKeyFromChain = typeof key3 === "string" && key3 ? key3 : null;
|
|
44791
|
+
this._orgKeyFromChain = orgKey;
|
|
44756
44792
|
}
|
|
44757
|
-
return
|
|
44793
|
+
return registered;
|
|
44758
44794
|
});
|
|
44759
44795
|
}
|
|
44760
44796
|
/* ── log_tool_call (sign-only) ─────────────────────────────────────────── */
|
|
@@ -44835,12 +44871,19 @@ var Atbash = class _Atbash {
|
|
|
44835
44871
|
}
|
|
44836
44872
|
let chainOpts = options.chainOpts;
|
|
44837
44873
|
if (options.orgName) {
|
|
44838
|
-
const
|
|
44839
|
-
if (
|
|
44840
|
-
chainOpts = { network:
|
|
44841
|
-
} else
|
|
44842
|
-
const
|
|
44843
|
-
|
|
44874
|
+
const cached = this._chainCache.get(options.orgName);
|
|
44875
|
+
if (cached) {
|
|
44876
|
+
chainOpts = { network: cached.network };
|
|
44877
|
+
} else {
|
|
44878
|
+
const mapNetwork = await this.getActiveNetworkForOrg(options.orgName);
|
|
44879
|
+
if (mapNetwork) {
|
|
44880
|
+
const chain = mapNetwork === "private" ? PRIVATE_CHAIN : PUBLIC_CHAIN;
|
|
44881
|
+
this._chainCache.set(options.orgName, chain);
|
|
44882
|
+
chainOpts = { network: mapNetwork };
|
|
44883
|
+
} else if (!chainOpts?.blockchainRid) {
|
|
44884
|
+
const resolved = await this.resolveChainFromMap(options.orgName, null);
|
|
44885
|
+
chainOpts = { ...chainOpts, network: resolved.network };
|
|
44886
|
+
}
|
|
44844
44887
|
}
|
|
44845
44888
|
}
|
|
44846
44889
|
const brid = this.bridFromChainOpts(chainOpts);
|
|
@@ -45155,19 +45198,25 @@ var Atbash = class _Atbash {
|
|
|
45155
45198
|
});
|
|
45156
45199
|
}
|
|
45157
45200
|
/* ── risk-engine batched (action-dispatched POST) ──────────────────────── */
|
|
45158
|
-
getAgentDetail(agentPubkey) {
|
|
45159
|
-
return this.track(
|
|
45160
|
-
|
|
45161
|
-
|
|
45162
|
-
|
|
45163
|
-
|
|
45201
|
+
async getAgentDetail(agentPubkey, options = {}) {
|
|
45202
|
+
return this.track("getAgentDetail", agentPubkey, async () => {
|
|
45203
|
+
const network = await this.resolveAgentLookupNetwork(options);
|
|
45204
|
+
return this.riskEnginePost(
|
|
45205
|
+
{ action: "agent-detail-batch", agent: agentPubkey },
|
|
45206
|
+
network
|
|
45207
|
+
);
|
|
45208
|
+
});
|
|
45164
45209
|
}
|
|
45165
|
-
async getAgentPolicy(agentPubkey) {
|
|
45210
|
+
async getAgentPolicy(agentPubkey, options = {}) {
|
|
45166
45211
|
return this.track("getAgentPolicy", agentPubkey, async () => {
|
|
45167
|
-
const
|
|
45168
|
-
|
|
45169
|
-
|
|
45170
|
-
|
|
45212
|
+
const network = await this.resolveAgentLookupNetwork(options);
|
|
45213
|
+
const raw2 = await this.riskEnginePost(
|
|
45214
|
+
{
|
|
45215
|
+
action: "agent-policy-batch",
|
|
45216
|
+
agent: agentPubkey
|
|
45217
|
+
},
|
|
45218
|
+
network
|
|
45219
|
+
);
|
|
45171
45220
|
return {
|
|
45172
45221
|
policy: String(raw2.policy ?? ""),
|
|
45173
45222
|
isJailed: Boolean(raw2.is_jailed),
|
|
@@ -45289,6 +45338,10 @@ var Atbash = class _Atbash {
|
|
|
45289
45338
|
clearChainCache() {
|
|
45290
45339
|
this._chainCache.clear();
|
|
45291
45340
|
}
|
|
45341
|
+
/** Drop the short-TTL `/api/ai/exists` cache. Useful in tests. */
|
|
45342
|
+
clearAgentExistsCache() {
|
|
45343
|
+
this._agentExistsCache = null;
|
|
45344
|
+
}
|
|
45292
45345
|
/* ── internals ─────────────────────────────────────────────────────────── */
|
|
45293
45346
|
/**
|
|
45294
45347
|
* Wrap an SDK method body in telemetry — records the call at start
|
|
@@ -45320,6 +45373,20 @@ var Atbash = class _Atbash {
|
|
|
45320
45373
|
if (chainOpts?.network === "public") return PUBLIC_CHAIN.blockchainRid;
|
|
45321
45374
|
return this.blockchainRid;
|
|
45322
45375
|
}
|
|
45376
|
+
/**
|
|
45377
|
+
* Resolve the dashboard chain used by agent metadata/policy reads.
|
|
45378
|
+
* Explicit per-call network overrides win; otherwise use the supplied org
|
|
45379
|
+
* or the client's configured default org. A custom BRID is intentionally
|
|
45380
|
+
* left untouched because it cannot be represented by the dashboard's
|
|
45381
|
+
* public/private query selector.
|
|
45382
|
+
*/
|
|
45383
|
+
async resolveAgentLookupNetwork(options) {
|
|
45384
|
+
if (options.chainOpts?.network) return options.chainOpts.network;
|
|
45385
|
+
if (options.chainOpts?.blockchainRid) return void 0;
|
|
45386
|
+
const orgName = options.orgName ?? this.orgName;
|
|
45387
|
+
if (!orgName) return void 0;
|
|
45388
|
+
return (await this.resolveChainForOrg(orgName)).network;
|
|
45389
|
+
}
|
|
45323
45390
|
/**
|
|
45324
45391
|
* Get-or-create a Bearer token for dashboard reads. The token is a
|
|
45325
45392
|
* signed `log_tool_call` op (locally signed, never submitted) — the
|
|
@@ -45362,10 +45429,11 @@ var Atbash = class _Atbash {
|
|
|
45362
45429
|
if (resp.status !== 200) throw await this.httpError(resp);
|
|
45363
45430
|
return this.json(resp);
|
|
45364
45431
|
}
|
|
45365
|
-
async riskEnginePost(body) {
|
|
45432
|
+
async riskEnginePost(body, network) {
|
|
45366
45433
|
let resp;
|
|
45367
45434
|
try {
|
|
45368
|
-
|
|
45435
|
+
const path4 = network ? `/api/risk-engine?network=${encodeURIComponent(network)}` : "/api/risk-engine";
|
|
45436
|
+
resp = await this.http.post(path4, body, this.authHeaders());
|
|
45369
45437
|
} catch (err) {
|
|
45370
45438
|
throw this.transportError(err);
|
|
45371
45439
|
}
|
|
@@ -45789,6 +45857,7 @@ function classifyMemoryWrite(_event, _ctx, _opts = {}) {
|
|
|
45789
45857
|
// src-ts/memory/guard.ts
|
|
45790
45858
|
init_define_ATBASH_CHROMIA_NODE_URLS();
|
|
45791
45859
|
init_define_ATBASH_PRIVATE_NODE_URLS();
|
|
45860
|
+
import path3 from "path";
|
|
45792
45861
|
function emitDebugProbe(event, ctx, memEntry, logger2) {
|
|
45793
45862
|
if (!logger2?.info) return;
|
|
45794
45863
|
const ev = event ?? {};
|
|
@@ -45825,7 +45894,8 @@ async function guardMemoryWrite(input) {
|
|
|
45825
45894
|
toolNames,
|
|
45826
45895
|
enforce = true,
|
|
45827
45896
|
debug: debug2 = false,
|
|
45828
|
-
logger: logger2
|
|
45897
|
+
logger: logger2,
|
|
45898
|
+
memoryFilePath
|
|
45829
45899
|
} = input;
|
|
45830
45900
|
const memEntry = classifyMemoryWrite(event, ctx, { patterns, toolNames });
|
|
45831
45901
|
if (debug2) emitDebugProbe(event, ctx, memEntry, logger2);
|
|
@@ -45861,17 +45931,28 @@ async function guardMemoryWrite(input) {
|
|
|
45861
45931
|
committed: false
|
|
45862
45932
|
};
|
|
45863
45933
|
}
|
|
45864
|
-
|
|
45865
|
-
|
|
45866
|
-
|
|
45867
|
-
|
|
45868
|
-
|
|
45869
|
-
|
|
45870
|
-
|
|
45871
|
-
|
|
45872
|
-
|
|
45934
|
+
const isManagedMemoryFile = memoryFilePath !== void 0 && path3.resolve(memEntry.key) === path3.resolve(memoryFilePath);
|
|
45935
|
+
if (isManagedMemoryFile) {
|
|
45936
|
+
commitMemoryVersion(memEntry.value, auth, {
|
|
45937
|
+
score: scanResult.score,
|
|
45938
|
+
orgName,
|
|
45939
|
+
endpoint
|
|
45940
|
+
}).catch((err) => {
|
|
45941
|
+
const reason = err instanceof Error ? err.message : String(err);
|
|
45942
|
+
logger2?.warn?.("[atbash] memory commit to chain failed", {
|
|
45943
|
+
path: memEntry.key,
|
|
45944
|
+
reason
|
|
45945
|
+
});
|
|
45873
45946
|
});
|
|
45874
|
-
}
|
|
45947
|
+
} else {
|
|
45948
|
+
logger2?.info?.(
|
|
45949
|
+
"[atbash] scanned but not committed \u2014 not the managed memory file",
|
|
45950
|
+
{
|
|
45951
|
+
path: memEntry.key,
|
|
45952
|
+
memoryFilePath: memoryFilePath ?? "(not configured)"
|
|
45953
|
+
}
|
|
45954
|
+
);
|
|
45955
|
+
}
|
|
45875
45956
|
logger2?.info?.(
|
|
45876
45957
|
scanResult.verdict === "yellow" ? "[atbash] memory HOLD" : "[atbash] memory ALLOW",
|
|
45877
45958
|
{ path: memEntry.key, score: scanResult.score, reason: scanResult.reason }
|
|
@@ -45880,7 +45961,7 @@ async function guardMemoryWrite(input) {
|
|
|
45880
45961
|
handled: true,
|
|
45881
45962
|
decision: { allow: true },
|
|
45882
45963
|
scanResult,
|
|
45883
|
-
committed:
|
|
45964
|
+
committed: isManagedMemoryFile
|
|
45884
45965
|
};
|
|
45885
45966
|
}
|
|
45886
45967
|
|
|
@@ -45901,21 +45982,21 @@ async function syncLocalMemory(auth, pointer, opts = {}) {
|
|
|
45901
45982
|
const now = Date.now();
|
|
45902
45983
|
const withinTtl = !opts.force && now - pointer.checkedAt < ttl;
|
|
45903
45984
|
if (withinTtl) {
|
|
45904
|
-
return { drifted: false, pointer };
|
|
45985
|
+
return { drifted: false, checked: false, pointer };
|
|
45905
45986
|
}
|
|
45906
45987
|
const currentId = await getActiveMemoryId(auth, opts.chainOpts);
|
|
45907
45988
|
const nextPointer = { activeId: currentId, checkedAt: now };
|
|
45908
45989
|
if (currentId === pointer.activeId) {
|
|
45909
|
-
return { drifted: false, pointer: nextPointer };
|
|
45990
|
+
return { drifted: false, checked: true, pointer: nextPointer };
|
|
45910
45991
|
}
|
|
45911
45992
|
if (currentId === null) {
|
|
45912
|
-
return { drifted: true, current: null, pointer: nextPointer };
|
|
45993
|
+
return { drifted: true, checked: true, current: null, pointer: nextPointer };
|
|
45913
45994
|
}
|
|
45914
45995
|
const row = await getMemoryById(currentId, auth, opts.chainOpts);
|
|
45915
45996
|
if (row.decryptError) {
|
|
45916
45997
|
throw new MemoryIntegrityError(currentId, row.decryptError);
|
|
45917
45998
|
}
|
|
45918
|
-
return { drifted: true, current: row, pointer: nextPointer };
|
|
45999
|
+
return { drifted: true, checked: true, current: row, pointer: nextPointer };
|
|
45919
46000
|
}
|
|
45920
46001
|
|
|
45921
46002
|
// src-ts/browser/memory-pointer-store.ts
|