@atbash/sdk 0.13.3-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/README.md +2 -2
- package/dist/browser.d.mts +35 -2
- package/dist/browser.mjs +76 -20
- package/dist/browser.mjs.map +1 -1
- package/dist/index.d.mts +35 -2
- package/dist/index.d.ts +35 -2
- package/dist/index.js +75 -21
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +73 -21
- 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 ?? ""),
|
|
@@ -3954,19 +3995,31 @@ var Atbash = class _Atbash {
|
|
|
3954
3995
|
return { allow: !this.failClosed, verdict: "ERROR", reason, toolCallId };
|
|
3955
3996
|
}
|
|
3956
3997
|
/* ── judgment status ───────────────────────────────────────────────────── */
|
|
3957
|
-
|
|
3998
|
+
/**
|
|
3999
|
+
* Return the current status of a previously submitted judgment.
|
|
4000
|
+
*
|
|
4001
|
+
* `chainOpts` names which chain the judgment was signed against. The
|
|
4002
|
+
* server's GET /api/v1/judge routes to that chain when the SDK sends
|
|
4003
|
+
* a `brid` query param; without it, the server falls back to public.
|
|
4004
|
+
* Callers on the private chain must pass a `chainOpts` (or configure
|
|
4005
|
+
* the client on the private chain) — otherwise polling a POSTed
|
|
4006
|
+
* judgment on the private chain 404s at the server.
|
|
4007
|
+
*/
|
|
4008
|
+
async getJudgmentStatus(judgmentId, agentPubkey, chainOpts) {
|
|
3958
4009
|
const pk = agentPubkey ?? this.auth.pubkey;
|
|
4010
|
+
const brid = this.bridFromChainOpts(chainOpts);
|
|
3959
4011
|
return this.track("getJudgmentStatus", pk, async () => {
|
|
3960
4012
|
const resp = await this.http.get(
|
|
3961
4013
|
"/api/v1/judge",
|
|
3962
|
-
{ tool_call_id: judgmentId, agent_pubkey: pk },
|
|
3963
|
-
this.authHeaders(
|
|
4014
|
+
{ tool_call_id: judgmentId, agent_pubkey: pk, brid },
|
|
4015
|
+
this.authHeaders(brid)
|
|
3964
4016
|
);
|
|
3965
4017
|
await this.raiseIfError(resp);
|
|
3966
4018
|
const data = await this.json(resp) ?? {};
|
|
3967
4019
|
return {
|
|
3968
4020
|
status: normalizeStatus(data.status),
|
|
3969
4021
|
verdict: normalizeVerdict(data.verdict),
|
|
4022
|
+
allow: canonicalAllow(data),
|
|
3970
4023
|
reason: String(data.reason ?? ""),
|
|
3971
4024
|
judgmentId: String(data.judgmentId ?? judgmentId),
|
|
3972
4025
|
onChain: optBool(data.onChain),
|
|
@@ -4026,7 +4079,7 @@ var Atbash = class _Atbash {
|
|
|
4026
4079
|
{ tool_call_id: toolCallId },
|
|
4027
4080
|
await this.defaultOrgBrid()
|
|
4028
4081
|
);
|
|
4029
|
-
if (!
|
|
4082
|
+
if (!isRecord2(raw2)) return null;
|
|
4030
4083
|
return toToolCallFull(raw2);
|
|
4031
4084
|
});
|
|
4032
4085
|
}
|
|
@@ -4038,7 +4091,7 @@ var Atbash = class _Atbash {
|
|
|
4038
4091
|
{ org: orgName },
|
|
4039
4092
|
brid
|
|
4040
4093
|
);
|
|
4041
|
-
if (!
|
|
4094
|
+
if (!isRecord2(raw2)) return null;
|
|
4042
4095
|
return {
|
|
4043
4096
|
orgName: String(raw2.org_name ?? ""),
|
|
4044
4097
|
tier: String(raw2.tier ?? ""),
|
|
@@ -4115,7 +4168,7 @@ var Atbash = class _Atbash {
|
|
|
4115
4168
|
);
|
|
4116
4169
|
await this.raiseIfError(resp);
|
|
4117
4170
|
const data = await this.json(resp) ?? {};
|
|
4118
|
-
if (
|
|
4171
|
+
if (isRecord2(data.data)) return data.data;
|
|
4119
4172
|
return data;
|
|
4120
4173
|
});
|
|
4121
4174
|
}
|
|
@@ -4131,7 +4184,7 @@ var Atbash = class _Atbash {
|
|
|
4131
4184
|
if (network) params.network = network;
|
|
4132
4185
|
const brid = network ? this.bridFromChainOpts({ network }) : void 0;
|
|
4133
4186
|
const raw2 = await this.riskEngineGet("org-subscription", params, brid);
|
|
4134
|
-
if (!
|
|
4187
|
+
if (!isRecord2(raw2)) return null;
|
|
4135
4188
|
return coerceOrgSubscription(raw2, orgName);
|
|
4136
4189
|
});
|
|
4137
4190
|
}
|
|
@@ -4337,7 +4390,7 @@ var Atbash = class _Atbash {
|
|
|
4337
4390
|
}
|
|
4338
4391
|
if (resp.status !== 200) throw await this.httpError(resp);
|
|
4339
4392
|
const data = await this.json(resp);
|
|
4340
|
-
return
|
|
4393
|
+
return isRecord2(data) ? data : {};
|
|
4341
4394
|
}
|
|
4342
4395
|
async riskEngineRecords(action, params, brid) {
|
|
4343
4396
|
const raw2 = await this.riskEngineGet(action, params, brid);
|
|
@@ -4404,14 +4457,11 @@ var Atbash = class _Atbash {
|
|
|
4404
4457
|
transportError(err) {
|
|
4405
4458
|
if (err instanceof HttpTransportError) {
|
|
4406
4459
|
if (this.debug) {
|
|
4407
|
-
this.logger.warn?.(
|
|
4408
|
-
|
|
4409
|
-
|
|
4410
|
-
|
|
4411
|
-
|
|
4412
|
-
endpoint: this.endpoint
|
|
4413
|
-
}
|
|
4414
|
-
);
|
|
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
|
+
});
|
|
4415
4465
|
}
|
|
4416
4466
|
return new AtbashAPIError(0, err.message, "", this.endpoint);
|
|
4417
4467
|
}
|
|
@@ -4509,7 +4559,7 @@ function coerceOrgSubscription(raw2, orgName) {
|
|
|
4509
4559
|
is_active: Boolean(raw2.is_active)
|
|
4510
4560
|
};
|
|
4511
4561
|
}
|
|
4512
|
-
function
|
|
4562
|
+
function isRecord2(v) {
|
|
4513
4563
|
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
4514
4564
|
}
|
|
4515
4565
|
function optString(v) {
|
|
@@ -4648,7 +4698,7 @@ async function scanMemory(entry, auth, opts) {
|
|
|
4648
4698
|
);
|
|
4649
4699
|
}
|
|
4650
4700
|
const KNOWN_ACTIONS = ["allow", "block", "hold_for_user_confirm"];
|
|
4651
|
-
const action = result.actionType
|
|
4701
|
+
const action = result.actionType;
|
|
4652
4702
|
if (result.verdict !== "No verdict" && action !== "" && !KNOWN_ACTIONS.includes(action)) {
|
|
4653
4703
|
throw new Error(
|
|
4654
4704
|
`memory scan: unrecognized action_type from judge (${result.actionType})`
|
|
@@ -43650,6 +43700,7 @@ export {
|
|
|
43650
43700
|
SignatureVerificationError,
|
|
43651
43701
|
bootSyncFailureLine,
|
|
43652
43702
|
buildAllowedJudgeHosts,
|
|
43703
|
+
canonicalAllow,
|
|
43653
43704
|
chainForNetwork,
|
|
43654
43705
|
chooseKeyPath,
|
|
43655
43706
|
claimHashHex,
|
|
@@ -43691,6 +43742,7 @@ export {
|
|
|
43691
43742
|
loadAgentFromFile,
|
|
43692
43743
|
loadUserConfig,
|
|
43693
43744
|
normalizeActionForHash,
|
|
43745
|
+
normalizeActionType,
|
|
43694
43746
|
normalizeForMatching,
|
|
43695
43747
|
normalizeStatus,
|
|
43696
43748
|
normalizeVerdict,
|