@atbash/sdk 0.14.1-dev.0 → 0.15.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.d.mts +24 -1
- package/dist/browser.mjs +62 -17
- package/dist/browser.mjs.map +1 -1
- package/dist/index.d.mts +24 -1
- package/dist/index.d.ts +24 -1
- package/dist/index.js +61 -18
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +59 -18
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -6
package/dist/index.mjs
CHANGED
|
@@ -3185,6 +3185,9 @@ function normalizeVerdict(raw2) {
|
|
|
3185
3185
|
if (v === "BLOCK" || v === "RED") return "BLOCK";
|
|
3186
3186
|
return "HOLD";
|
|
3187
3187
|
}
|
|
3188
|
+
function normalizeActionType(raw2) {
|
|
3189
|
+
return typeof raw2 === "string" ? raw2.trim().toLowerCase() : "";
|
|
3190
|
+
}
|
|
3188
3191
|
function normalizeStatus(raw2) {
|
|
3189
3192
|
const s2 = String(raw2 ?? "").toLowerCase();
|
|
3190
3193
|
if (s2 === "pending" || s2 === "answered" || s2 === "error") return s2;
|
|
@@ -3201,6 +3204,37 @@ function pubkeyToHex(val) {
|
|
|
3201
3204
|
return "";
|
|
3202
3205
|
}
|
|
3203
3206
|
|
|
3207
|
+
// src-ts/decision.ts
|
|
3208
|
+
function isRecord(value) {
|
|
3209
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
3210
|
+
}
|
|
3211
|
+
function allowSignalsPermit(data) {
|
|
3212
|
+
const signals = [];
|
|
3213
|
+
if (Object.hasOwn(data, "allow")) signals.push(data.allow);
|
|
3214
|
+
if (isRecord(data.decision) && Object.hasOwn(data.decision, "allow")) {
|
|
3215
|
+
signals.push(data.decision.allow);
|
|
3216
|
+
}
|
|
3217
|
+
return signals.length === 0 || signals.every((value) => value === true);
|
|
3218
|
+
}
|
|
3219
|
+
function wireActionType(data) {
|
|
3220
|
+
if (data.action_type !== void 0)
|
|
3221
|
+
return normalizeActionType(data.action_type);
|
|
3222
|
+
return normalizeActionType(data.actionType);
|
|
3223
|
+
}
|
|
3224
|
+
function isAuditTier(data) {
|
|
3225
|
+
const absentVerdict = data.verdict === null || data.verdict === void 0;
|
|
3226
|
+
return absentVerdict && data.status === "logged";
|
|
3227
|
+
}
|
|
3228
|
+
function canonicalAllow(data) {
|
|
3229
|
+
if (!allowSignalsPermit(data)) return false;
|
|
3230
|
+
const actionType = wireActionType(data);
|
|
3231
|
+
if (actionType && actionType !== "allow") return false;
|
|
3232
|
+
if (isAuditTier(data)) return true;
|
|
3233
|
+
if (typeof data.verdict !== "string") return false;
|
|
3234
|
+
const verdict = data.verdict.trim().toUpperCase();
|
|
3235
|
+
return verdict === "ALLOW" || verdict === "GREEN";
|
|
3236
|
+
}
|
|
3237
|
+
|
|
3204
3238
|
// src-ts/opentel/telemetry.ts
|
|
3205
3239
|
import { readFileSync as readFileSync2 } from "fs";
|
|
3206
3240
|
import { homedir as homedir2 } from "os";
|
|
@@ -3522,7 +3556,10 @@ var Atbash = class _Atbash {
|
|
|
3522
3556
|
getAuthHeaders: () => this.authHeaders()
|
|
3523
3557
|
});
|
|
3524
3558
|
} catch (err) {
|
|
3525
|
-
this.logger.warn?.(
|
|
3559
|
+
this.logger.warn?.(
|
|
3560
|
+
"[atbash] telemetry setup failed \u2014 continuing without metrics",
|
|
3561
|
+
{ error: String(err) }
|
|
3562
|
+
);
|
|
3526
3563
|
}
|
|
3527
3564
|
}
|
|
3528
3565
|
/**
|
|
@@ -3737,7 +3774,10 @@ var Atbash = class _Atbash {
|
|
|
3737
3774
|
this._chainCache.set(options.orgName, chain);
|
|
3738
3775
|
chainOpts = { network: mapNetwork };
|
|
3739
3776
|
} else if (!chainOpts?.blockchainRid) {
|
|
3740
|
-
const resolved = await this.resolveChainFromMap(
|
|
3777
|
+
const resolved = await this.resolveChainFromMap(
|
|
3778
|
+
options.orgName,
|
|
3779
|
+
null
|
|
3780
|
+
);
|
|
3741
3781
|
chainOpts = { ...chainOpts, network: resolved.network };
|
|
3742
3782
|
}
|
|
3743
3783
|
}
|
|
@@ -3812,7 +3852,8 @@ var Atbash = class _Atbash {
|
|
|
3812
3852
|
const score = typeof rawScore === "number" && Number.isInteger(rawScore) && rawScore >= 1 && rawScore <= 10 ? rawScore : void 0;
|
|
3813
3853
|
return {
|
|
3814
3854
|
verdict: normalizeVerdict(data.verdict),
|
|
3815
|
-
|
|
3855
|
+
allow: canonicalAllow(data),
|
|
3856
|
+
actionType: normalizeActionType(data.action_type),
|
|
3816
3857
|
reason: String(data.reason ?? ""),
|
|
3817
3858
|
confidence: Number(data.confidence ?? 0),
|
|
3818
3859
|
provider: String(data.provider ?? ""),
|
|
@@ -3978,6 +4019,7 @@ var Atbash = class _Atbash {
|
|
|
3978
4019
|
return {
|
|
3979
4020
|
status: normalizeStatus(data.status),
|
|
3980
4021
|
verdict: normalizeVerdict(data.verdict),
|
|
4022
|
+
allow: canonicalAllow(data),
|
|
3981
4023
|
reason: String(data.reason ?? ""),
|
|
3982
4024
|
judgmentId: String(data.judgmentId ?? judgmentId),
|
|
3983
4025
|
onChain: optBool(data.onChain),
|
|
@@ -4037,7 +4079,7 @@ var Atbash = class _Atbash {
|
|
|
4037
4079
|
{ tool_call_id: toolCallId },
|
|
4038
4080
|
await this.defaultOrgBrid()
|
|
4039
4081
|
);
|
|
4040
|
-
if (!
|
|
4082
|
+
if (!isRecord2(raw2)) return null;
|
|
4041
4083
|
return toToolCallFull(raw2);
|
|
4042
4084
|
});
|
|
4043
4085
|
}
|
|
@@ -4049,7 +4091,7 @@ var Atbash = class _Atbash {
|
|
|
4049
4091
|
{ org: orgName },
|
|
4050
4092
|
brid
|
|
4051
4093
|
);
|
|
4052
|
-
if (!
|
|
4094
|
+
if (!isRecord2(raw2)) return null;
|
|
4053
4095
|
return {
|
|
4054
4096
|
orgName: String(raw2.org_name ?? ""),
|
|
4055
4097
|
tier: String(raw2.tier ?? ""),
|
|
@@ -4126,7 +4168,7 @@ var Atbash = class _Atbash {
|
|
|
4126
4168
|
);
|
|
4127
4169
|
await this.raiseIfError(resp);
|
|
4128
4170
|
const data = await this.json(resp) ?? {};
|
|
4129
|
-
if (
|
|
4171
|
+
if (isRecord2(data.data)) return data.data;
|
|
4130
4172
|
return data;
|
|
4131
4173
|
});
|
|
4132
4174
|
}
|
|
@@ -4142,7 +4184,7 @@ var Atbash = class _Atbash {
|
|
|
4142
4184
|
if (network) params.network = network;
|
|
4143
4185
|
const brid = network ? this.bridFromChainOpts({ network }) : void 0;
|
|
4144
4186
|
const raw2 = await this.riskEngineGet("org-subscription", params, brid);
|
|
4145
|
-
if (!
|
|
4187
|
+
if (!isRecord2(raw2)) return null;
|
|
4146
4188
|
return coerceOrgSubscription(raw2, orgName);
|
|
4147
4189
|
});
|
|
4148
4190
|
}
|
|
@@ -4348,7 +4390,7 @@ var Atbash = class _Atbash {
|
|
|
4348
4390
|
}
|
|
4349
4391
|
if (resp.status !== 200) throw await this.httpError(resp);
|
|
4350
4392
|
const data = await this.json(resp);
|
|
4351
|
-
return
|
|
4393
|
+
return isRecord2(data) ? data : {};
|
|
4352
4394
|
}
|
|
4353
4395
|
async riskEngineRecords(action, params, brid) {
|
|
4354
4396
|
const raw2 = await this.riskEngineGet(action, params, brid);
|
|
@@ -4415,14 +4457,11 @@ var Atbash = class _Atbash {
|
|
|
4415
4457
|
transportError(err) {
|
|
4416
4458
|
if (err instanceof HttpTransportError) {
|
|
4417
4459
|
if (this.debug) {
|
|
4418
|
-
this.logger.warn?.(
|
|
4419
|
-
|
|
4420
|
-
|
|
4421
|
-
|
|
4422
|
-
|
|
4423
|
-
endpoint: this.endpoint
|
|
4424
|
-
}
|
|
4425
|
-
);
|
|
4460
|
+
this.logger.warn?.(`[atbash] transport failed \u2014 kind=${err.kind}`, {
|
|
4461
|
+
kind: err.kind,
|
|
4462
|
+
cause: err.cause instanceof Error ? err.cause.message : String(err.cause ?? ""),
|
|
4463
|
+
endpoint: this.endpoint
|
|
4464
|
+
});
|
|
4426
4465
|
}
|
|
4427
4466
|
return new AtbashAPIError(0, err.message, "", this.endpoint);
|
|
4428
4467
|
}
|
|
@@ -4520,7 +4559,7 @@ function coerceOrgSubscription(raw2, orgName) {
|
|
|
4520
4559
|
is_active: Boolean(raw2.is_active)
|
|
4521
4560
|
};
|
|
4522
4561
|
}
|
|
4523
|
-
function
|
|
4562
|
+
function isRecord2(v) {
|
|
4524
4563
|
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
4525
4564
|
}
|
|
4526
4565
|
function optString(v) {
|
|
@@ -4659,7 +4698,7 @@ async function scanMemory(entry, auth, opts) {
|
|
|
4659
4698
|
);
|
|
4660
4699
|
}
|
|
4661
4700
|
const KNOWN_ACTIONS = ["allow", "block", "hold_for_user_confirm"];
|
|
4662
|
-
const action = result.actionType
|
|
4701
|
+
const action = result.actionType;
|
|
4663
4702
|
if (result.verdict !== "No verdict" && action !== "" && !KNOWN_ACTIONS.includes(action)) {
|
|
4664
4703
|
throw new Error(
|
|
4665
4704
|
`memory scan: unrecognized action_type from judge (${result.actionType})`
|
|
@@ -43661,6 +43700,7 @@ export {
|
|
|
43661
43700
|
SignatureVerificationError,
|
|
43662
43701
|
bootSyncFailureLine,
|
|
43663
43702
|
buildAllowedJudgeHosts,
|
|
43703
|
+
canonicalAllow,
|
|
43664
43704
|
chainForNetwork,
|
|
43665
43705
|
chooseKeyPath,
|
|
43666
43706
|
claimHashHex,
|
|
@@ -43702,6 +43742,7 @@ export {
|
|
|
43702
43742
|
loadAgentFromFile,
|
|
43703
43743
|
loadUserConfig,
|
|
43704
43744
|
normalizeActionForHash,
|
|
43745
|
+
normalizeActionType,
|
|
43705
43746
|
normalizeForMatching,
|
|
43706
43747
|
normalizeStatus,
|
|
43707
43748
|
normalizeVerdict,
|