@atbash/sdk 0.10.12-dev.0 → 0.12.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 +5 -0
- package/dist/browser.d.mts +39 -13
- package/dist/browser.mjs +173 -114
- package/dist/browser.mjs.map +1 -1
- package/dist/index.d.mts +39 -13
- package/dist/index.d.ts +39 -13
- package/dist/index.js +212 -133
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +210 -131
- package/dist/index.mjs.map +1 -1
- package/index.d.ts +18 -10
- package/index.js +85 -196
- package/package.json +5 -5
package/dist/index.mjs
CHANGED
|
@@ -3311,6 +3311,8 @@ var ENV_MAP = {
|
|
|
3311
3311
|
agentKey: "ATBASH_AGENT_KEY",
|
|
3312
3312
|
orgName: "ATBASH_ORG_NAME",
|
|
3313
3313
|
judgeEndpoint: "ATBASH_ENDPOINT",
|
|
3314
|
+
// Same variable name the Hermes plugin already documents.
|
|
3315
|
+
judgeVerifyPubKey: "ATBASH_JUDGE_VERIFY_PUBKEY",
|
|
3314
3316
|
blockchainRid: "ATBASH_BLOCKCHAIN_RID",
|
|
3315
3317
|
provider: "ATBASH_PROVIDER",
|
|
3316
3318
|
providerModel: "ATBASH_PROVIDER_MODEL",
|
|
@@ -3400,16 +3402,27 @@ var Atbash = class _Atbash {
|
|
|
3400
3402
|
* lazily as a signed `log_tool_call` tx and refreshed every 4 min so
|
|
3401
3403
|
* server-side replay protection windows never expire it mid-session.
|
|
3402
3404
|
*/
|
|
3403
|
-
|
|
3405
|
+
// Keyed by blockchainRid so bearers for the public and private chains can
|
|
3406
|
+
// coexist. The dashboard derives `authNetwork` from the BRID inside the
|
|
3407
|
+
// signed envelope, so a bearer signed for chain A cannot authenticate a
|
|
3408
|
+
// request routed to chain B — every chain the client talks to needs its own.
|
|
3409
|
+
_authBearers = /* @__PURE__ */ new Map();
|
|
3404
3410
|
/** Guards `logEnvironmentOnce` — hosts construct several clients. */
|
|
3405
3411
|
static environmentLogged = false;
|
|
3406
3412
|
constructor(privkey, options = {}) {
|
|
3407
3413
|
this.auth = native.loadAgent(privkey);
|
|
3408
|
-
|
|
3414
|
+
const validated = validateJudgeEndpoint(
|
|
3415
|
+
options.verifyPubKey ? {
|
|
3416
|
+
policy: "self-hosted",
|
|
3417
|
+
endpoint: options.endpoint ?? DEFAULT_ENDPOINT,
|
|
3418
|
+
verifyPubKey: options.verifyPubKey
|
|
3419
|
+
} : { endpoint: options.endpoint }
|
|
3420
|
+
);
|
|
3421
|
+
this.endpoint = validated.url;
|
|
3409
3422
|
this.nodeUrls = options.nodeUrls ? [...options.nodeUrls] : DEFAULT_CHROMIA_NODE_URLS;
|
|
3410
3423
|
this.blockchainRid = options.blockchainRid ?? native.DEFAULT_BLOCKCHAIN_RID;
|
|
3411
3424
|
this.orgName = options.orgName;
|
|
3412
|
-
this.verifyPubKey =
|
|
3425
|
+
this.verifyPubKey = validated.verifyPubKey ?? void 0;
|
|
3413
3426
|
this.orgEncryptionPubKey = options.orgEncryptionPubKey;
|
|
3414
3427
|
this.failClosed = options.failClosed !== false;
|
|
3415
3428
|
this.debug = options.debug === true;
|
|
@@ -3467,8 +3480,19 @@ var Atbash = class _Atbash {
|
|
|
3467
3480
|
* self-hosted endpoint's `verifyPubKey` becomes the client default.
|
|
3468
3481
|
*/
|
|
3469
3482
|
static fromConfig(options = {}) {
|
|
3483
|
+
const configuredEndpoint = resolve("judgeEndpoint") || void 0;
|
|
3484
|
+
const configuredVerifyPubKey = resolve("judgeVerifyPubKey") || void 0;
|
|
3485
|
+
if (!options.judge && configuredVerifyPubKey && !configuredEndpoint) {
|
|
3486
|
+
throw new Error(
|
|
3487
|
+
"judgeVerifyPubKey / ATBASH_JUDGE_VERIFY_PUBKEY is set but no judge endpoint is configured: set judgeEndpoint / ATBASH_ENDPOINT to the self-hosted judge"
|
|
3488
|
+
);
|
|
3489
|
+
}
|
|
3470
3490
|
const validated = validateJudgeEndpoint(
|
|
3471
|
-
options.judge ??
|
|
3491
|
+
options.judge ?? (configuredVerifyPubKey && configuredEndpoint ? {
|
|
3492
|
+
policy: "self-hosted",
|
|
3493
|
+
endpoint: configuredEndpoint,
|
|
3494
|
+
verifyPubKey: configuredVerifyPubKey
|
|
3495
|
+
} : { endpoint: configuredEndpoint })
|
|
3472
3496
|
);
|
|
3473
3497
|
const agentKey = resolve("agentKey", options.agentKey);
|
|
3474
3498
|
const auth = agentKey ? native.loadAgent(agentKey) : loadAgentFromFile(options.keyPath);
|
|
@@ -3516,10 +3540,11 @@ var Atbash = class _Atbash {
|
|
|
3516
3540
|
return this.track("checkAgentExists", pk, async () => {
|
|
3517
3541
|
const query = { pubkey: pk };
|
|
3518
3542
|
if (network) query.network = network;
|
|
3543
|
+
const brid = this.bridFromChainOpts(network ? { network } : void 0);
|
|
3519
3544
|
const resp = await this.http.get(
|
|
3520
3545
|
"/api/ai/exists",
|
|
3521
3546
|
query,
|
|
3522
|
-
this.authHeaders()
|
|
3547
|
+
this.authHeaders(brid)
|
|
3523
3548
|
);
|
|
3524
3549
|
await this.raiseIfError(resp);
|
|
3525
3550
|
const data = await this.json(resp);
|
|
@@ -3874,15 +3899,15 @@ var Atbash = class _Atbash {
|
|
|
3874
3899
|
() => this.riskEngineRecords("tool-calls", { limit: maxCount })
|
|
3875
3900
|
);
|
|
3876
3901
|
}
|
|
3877
|
-
getOrgToolCalls(orgName, maxCount) {
|
|
3878
|
-
return this.track(
|
|
3879
|
-
|
|
3880
|
-
|
|
3881
|
-
|
|
3882
|
-
org: orgName,
|
|
3883
|
-
|
|
3884
|
-
|
|
3885
|
-
);
|
|
3902
|
+
async getOrgToolCalls(orgName, maxCount) {
|
|
3903
|
+
return this.track("getOrgToolCalls", void 0, async () => {
|
|
3904
|
+
const brid = await this.bridForOrg(orgName);
|
|
3905
|
+
return this.riskEngineRecords(
|
|
3906
|
+
"org-tool-calls",
|
|
3907
|
+
{ org: orgName, limit: maxCount },
|
|
3908
|
+
brid
|
|
3909
|
+
);
|
|
3910
|
+
});
|
|
3886
3911
|
}
|
|
3887
3912
|
getAgentToolCalls(agentPubkey, maxCount) {
|
|
3888
3913
|
return this.track(
|
|
@@ -3912,7 +3937,12 @@ var Atbash = class _Atbash {
|
|
|
3912
3937
|
}
|
|
3913
3938
|
async getOrgTierInfo(orgName) {
|
|
3914
3939
|
return this.track("getOrgTierInfo", void 0, async () => {
|
|
3915
|
-
const
|
|
3940
|
+
const brid = await this.bridForOrg(orgName);
|
|
3941
|
+
const raw2 = await this.riskEngineGet(
|
|
3942
|
+
"org-tier-info",
|
|
3943
|
+
{ org: orgName },
|
|
3944
|
+
brid
|
|
3945
|
+
);
|
|
3916
3946
|
if (!isRecord(raw2)) return null;
|
|
3917
3947
|
return {
|
|
3918
3948
|
orgName: String(raw2.org_name ?? ""),
|
|
@@ -3924,20 +3954,24 @@ var Atbash = class _Atbash {
|
|
|
3924
3954
|
}
|
|
3925
3955
|
async getPendingHeldActions(orgName, maxCount) {
|
|
3926
3956
|
return this.track("getPendingHeldActions", void 0, async () => {
|
|
3927
|
-
const
|
|
3928
|
-
|
|
3929
|
-
|
|
3930
|
-
|
|
3957
|
+
const brid = await this.bridForOrg(orgName);
|
|
3958
|
+
const raw2 = await this.riskEngineGet(
|
|
3959
|
+
"pending-held-actions",
|
|
3960
|
+
{ org: orgName, limit: maxCount },
|
|
3961
|
+
brid
|
|
3962
|
+
);
|
|
3931
3963
|
if (!Array.isArray(raw2)) return [];
|
|
3932
3964
|
return raw2.map((item) => toHeldAction(item));
|
|
3933
3965
|
});
|
|
3934
3966
|
}
|
|
3935
3967
|
async getHeldActionReviews(orgName, maxCount) {
|
|
3936
3968
|
return this.track("getHeldActionReviews", void 0, async () => {
|
|
3937
|
-
const
|
|
3938
|
-
|
|
3939
|
-
|
|
3940
|
-
|
|
3969
|
+
const brid = await this.bridForOrg(orgName);
|
|
3970
|
+
const raw2 = await this.riskEngineGet(
|
|
3971
|
+
"held-action-reviews",
|
|
3972
|
+
{ org: orgName, limit: maxCount },
|
|
3973
|
+
brid
|
|
3974
|
+
);
|
|
3941
3975
|
if (!Array.isArray(raw2)) return [];
|
|
3942
3976
|
return raw2.map(
|
|
3943
3977
|
(item) => toHeldActionReview(item)
|
|
@@ -3948,21 +3982,25 @@ var Atbash = class _Atbash {
|
|
|
3948
3982
|
async getAgentDetail(agentPubkey, options = {}) {
|
|
3949
3983
|
return this.track("getAgentDetail", agentPubkey, async () => {
|
|
3950
3984
|
const network = await this.resolveAgentLookupNetwork(options);
|
|
3985
|
+
const brid = network ? this.bridFromChainOpts({ network }) : void 0;
|
|
3951
3986
|
return this.riskEnginePost(
|
|
3952
3987
|
{ action: "agent-detail-batch", agent: agentPubkey },
|
|
3953
|
-
network
|
|
3988
|
+
network,
|
|
3989
|
+
brid
|
|
3954
3990
|
);
|
|
3955
3991
|
});
|
|
3956
3992
|
}
|
|
3957
3993
|
async getAgentPolicy(agentPubkey, options = {}) {
|
|
3958
3994
|
return this.track("getAgentPolicy", agentPubkey, async () => {
|
|
3959
3995
|
const network = await this.resolveAgentLookupNetwork(options);
|
|
3996
|
+
const brid = network ? this.bridFromChainOpts({ network }) : void 0;
|
|
3960
3997
|
const raw2 = await this.riskEnginePost(
|
|
3961
3998
|
{
|
|
3962
3999
|
action: "agent-policy-batch",
|
|
3963
4000
|
agent: agentPubkey
|
|
3964
4001
|
},
|
|
3965
|
-
network
|
|
4002
|
+
network,
|
|
4003
|
+
brid
|
|
3966
4004
|
);
|
|
3967
4005
|
return {
|
|
3968
4006
|
policy: String(raw2.policy ?? ""),
|
|
@@ -3996,7 +4034,8 @@ var Atbash = class _Atbash {
|
|
|
3996
4034
|
return this.track("getOrgSubscription", void 0, async () => {
|
|
3997
4035
|
const params = { org: orgName };
|
|
3998
4036
|
if (network) params.network = network;
|
|
3999
|
-
const
|
|
4037
|
+
const brid = network ? this.bridFromChainOpts({ network }) : void 0;
|
|
4038
|
+
const raw2 = await this.riskEngineGet("org-subscription", params, brid);
|
|
4000
4039
|
if (!isRecord(raw2)) return null;
|
|
4001
4040
|
return coerceOrgSubscription(raw2, orgName);
|
|
4002
4041
|
});
|
|
@@ -4009,21 +4048,22 @@ var Atbash = class _Atbash {
|
|
|
4009
4048
|
* entry (caller falls back to per-chain subscription resolution).
|
|
4010
4049
|
*/
|
|
4011
4050
|
async getActiveNetworkForOrg(orgName) {
|
|
4051
|
+
let resp;
|
|
4012
4052
|
try {
|
|
4013
|
-
|
|
4053
|
+
resp = await this.http.get(
|
|
4014
4054
|
"/api/org-network",
|
|
4015
|
-
{ org: orgName },
|
|
4055
|
+
{ org: orgName.trim() },
|
|
4016
4056
|
this.authHeaders()
|
|
4017
4057
|
);
|
|
4018
|
-
|
|
4019
|
-
|
|
4020
|
-
|
|
4021
|
-
|
|
4022
|
-
|
|
4023
|
-
|
|
4024
|
-
|
|
4025
|
-
return null;
|
|
4058
|
+
} catch (err) {
|
|
4059
|
+
throw this.transportError(err);
|
|
4060
|
+
}
|
|
4061
|
+
if (resp.status !== 200) throw await this.httpError(resp);
|
|
4062
|
+
const data = await this.json(resp);
|
|
4063
|
+
if (data?.network === "public" || data?.network === "private") {
|
|
4064
|
+
return data.network;
|
|
4026
4065
|
}
|
|
4066
|
+
return null;
|
|
4027
4067
|
}
|
|
4028
4068
|
/**
|
|
4029
4069
|
* Resolve which chain an org's actions should run against. Cached
|
|
@@ -4035,10 +4075,11 @@ var Atbash = class _Atbash {
|
|
|
4035
4075
|
* Defaults to the public chain when nothing else resolves.
|
|
4036
4076
|
*/
|
|
4037
4077
|
async resolveChainForOrg(orgName) {
|
|
4038
|
-
const
|
|
4078
|
+
const name2 = orgName.trim();
|
|
4079
|
+
const cached = this._chainCache.get(name2);
|
|
4039
4080
|
if (cached) return cached;
|
|
4040
|
-
const mapNetwork = await this.getActiveNetworkForOrg(
|
|
4041
|
-
return this.resolveChainFromMap(
|
|
4081
|
+
const mapNetwork = await this.getActiveNetworkForOrg(name2);
|
|
4082
|
+
return this.resolveChainFromMap(name2, mapNetwork);
|
|
4042
4083
|
}
|
|
4043
4084
|
/**
|
|
4044
4085
|
* Resolve a chain given an already-fetched `org_networks` map result.
|
|
@@ -4054,29 +4095,38 @@ var Atbash = class _Atbash {
|
|
|
4054
4095
|
this._chainCache.set(orgName, chain);
|
|
4055
4096
|
return chain;
|
|
4056
4097
|
}
|
|
4057
|
-
|
|
4058
|
-
|
|
4059
|
-
|
|
4060
|
-
|
|
4061
|
-
|
|
4062
|
-
|
|
4063
|
-
|
|
4064
|
-
|
|
4065
|
-
|
|
4066
|
-
|
|
4067
|
-
|
|
4068
|
-
|
|
4069
|
-
|
|
4070
|
-
|
|
4071
|
-
|
|
4072
|
-
|
|
4073
|
-
|
|
4074
|
-
|
|
4075
|
-
|
|
4076
|
-
|
|
4077
|
-
|
|
4078
|
-
|
|
4079
|
-
|
|
4098
|
+
const [pubRes, privRes] = await Promise.allSettled([
|
|
4099
|
+
this.getOrgSubscription(orgName, "public"),
|
|
4100
|
+
this.getOrgSubscription(orgName, "private")
|
|
4101
|
+
]);
|
|
4102
|
+
const pubSub = pubRes.status === "fulfilled" ? pubRes.value : null;
|
|
4103
|
+
const privSub = privRes.status === "fulfilled" ? privRes.value : null;
|
|
4104
|
+
const failure = pubRes.status === "rejected" ? pubRes.reason : privRes.status === "rejected" ? privRes.reason : null;
|
|
4105
|
+
if (pubSub?.is_private_blockchain) {
|
|
4106
|
+
this._chainCache.set(orgName, PRIVATE_CHAIN);
|
|
4107
|
+
return PRIVATE_CHAIN;
|
|
4108
|
+
}
|
|
4109
|
+
if (pubSub && privSub) {
|
|
4110
|
+
const chain = privSub.assigned_at > pubSub.assigned_at ? PRIVATE_CHAIN : PUBLIC_CHAIN;
|
|
4111
|
+
this._chainCache.set(orgName, chain);
|
|
4112
|
+
return chain;
|
|
4113
|
+
}
|
|
4114
|
+
if (pubSub) {
|
|
4115
|
+
this._chainCache.set(orgName, PUBLIC_CHAIN);
|
|
4116
|
+
return PUBLIC_CHAIN;
|
|
4117
|
+
}
|
|
4118
|
+
if (privSub?.is_private_blockchain) {
|
|
4119
|
+
this._chainCache.set(orgName, PRIVATE_CHAIN);
|
|
4120
|
+
return PRIVATE_CHAIN;
|
|
4121
|
+
}
|
|
4122
|
+
if (failure) {
|
|
4123
|
+
const detail = failure instanceof Error ? failure.message : String(failure);
|
|
4124
|
+
throw new AtbashAPIError(
|
|
4125
|
+
failure instanceof AtbashAPIError ? failure.status : 0,
|
|
4126
|
+
`could not resolve the chain for org "${orgName}": ${detail}`,
|
|
4127
|
+
"",
|
|
4128
|
+
this.endpoint
|
|
4129
|
+
);
|
|
4080
4130
|
}
|
|
4081
4131
|
this._chainCache.set(orgName, PUBLIC_CHAIN);
|
|
4082
4132
|
return PUBLIC_CHAIN;
|
|
@@ -4141,11 +4191,11 @@ var Atbash = class _Atbash {
|
|
|
4141
4191
|
* for 4 minutes; refreshed after that so a long-lived client never
|
|
4142
4192
|
* trips the server's replay window.
|
|
4143
4193
|
*/
|
|
4144
|
-
getAuthBearer() {
|
|
4194
|
+
getAuthBearer(brid) {
|
|
4195
|
+
const chainBrid = brid ?? this.blockchainRid;
|
|
4145
4196
|
const now = Date.now();
|
|
4146
|
-
|
|
4147
|
-
|
|
4148
|
-
}
|
|
4197
|
+
const cached = this._authBearers.get(chainBrid);
|
|
4198
|
+
if (cached && now - cached.issuedAt < 4 * 60 * 1e3) return cached.hex;
|
|
4149
4199
|
const nonce = `auth-${now.toString(36)}-${randomHex(4)}`;
|
|
4150
4200
|
const hex = native.signLogToolCall(
|
|
4151
4201
|
nonce,
|
|
@@ -4154,21 +4204,21 @@ var Atbash = class _Atbash {
|
|
|
4154
4204
|
"auth-bearer",
|
|
4155
4205
|
"",
|
|
4156
4206
|
this.auth.privkey,
|
|
4157
|
-
|
|
4207
|
+
chainBrid
|
|
4158
4208
|
);
|
|
4159
|
-
this.
|
|
4209
|
+
this._authBearers.set(chainBrid, { hex, issuedAt: now });
|
|
4160
4210
|
return hex;
|
|
4161
4211
|
}
|
|
4162
|
-
authHeaders() {
|
|
4163
|
-
return { Authorization: `Bearer ${this.getAuthBearer()}` };
|
|
4212
|
+
authHeaders(brid) {
|
|
4213
|
+
return { Authorization: `Bearer ${this.getAuthBearer(brid)}` };
|
|
4164
4214
|
}
|
|
4165
|
-
async riskEngineGet(action, params) {
|
|
4215
|
+
async riskEngineGet(action, params, brid) {
|
|
4166
4216
|
let resp;
|
|
4167
4217
|
try {
|
|
4168
4218
|
resp = await this.http.get(
|
|
4169
4219
|
"/api/risk-engine",
|
|
4170
4220
|
{ action, ...params },
|
|
4171
|
-
this.authHeaders()
|
|
4221
|
+
this.authHeaders(brid)
|
|
4172
4222
|
);
|
|
4173
4223
|
} catch (err) {
|
|
4174
4224
|
throw this.transportError(err);
|
|
@@ -4176,11 +4226,11 @@ var Atbash = class _Atbash {
|
|
|
4176
4226
|
if (resp.status !== 200) throw await this.httpError(resp);
|
|
4177
4227
|
return this.json(resp);
|
|
4178
4228
|
}
|
|
4179
|
-
async riskEnginePost(body, network) {
|
|
4229
|
+
async riskEnginePost(body, network, brid) {
|
|
4180
4230
|
let resp;
|
|
4181
4231
|
try {
|
|
4182
4232
|
const path7 = network ? `/api/risk-engine?network=${encodeURIComponent(network)}` : "/api/risk-engine";
|
|
4183
|
-
resp = await this.http.post(path7, body, this.authHeaders());
|
|
4233
|
+
resp = await this.http.post(path7, body, this.authHeaders(brid));
|
|
4184
4234
|
} catch (err) {
|
|
4185
4235
|
throw this.transportError(err);
|
|
4186
4236
|
}
|
|
@@ -4188,11 +4238,23 @@ var Atbash = class _Atbash {
|
|
|
4188
4238
|
const data = await this.json(resp);
|
|
4189
4239
|
return isRecord(data) ? data : {};
|
|
4190
4240
|
}
|
|
4191
|
-
async riskEngineRecords(action, params) {
|
|
4192
|
-
const raw2 = await this.riskEngineGet(action, params);
|
|
4241
|
+
async riskEngineRecords(action, params, brid) {
|
|
4242
|
+
const raw2 = await this.riskEngineGet(action, params, brid);
|
|
4193
4243
|
if (!Array.isArray(raw2)) return [];
|
|
4194
4244
|
return raw2.map((item) => toToolCallRecord(item));
|
|
4195
4245
|
}
|
|
4246
|
+
/**
|
|
4247
|
+
* BRID for an org — one round-trip to the map, honoring the client's chain
|
|
4248
|
+
* cache. Returns undefined when the org is unknown, so the caller falls
|
|
4249
|
+
* back to the client default (best-effort discovery).
|
|
4250
|
+
*/
|
|
4251
|
+
async bridForOrg(orgName) {
|
|
4252
|
+
try {
|
|
4253
|
+
return (await this.resolveChainForOrg(orgName)).blockchainRid;
|
|
4254
|
+
} catch {
|
|
4255
|
+
return void 0;
|
|
4256
|
+
}
|
|
4257
|
+
}
|
|
4196
4258
|
async raiseIfError(resp) {
|
|
4197
4259
|
if (resp.ok) return;
|
|
4198
4260
|
throw await this.httpError(resp);
|
|
@@ -42633,6 +42695,7 @@ async function resolveChainOptsForOrg(opts, auth) {
|
|
|
42633
42695
|
if (opts?.orgName && !opts.chainOpts?.blockchainRid && auth) {
|
|
42634
42696
|
const atbash = new Atbash(auth.privkey, {
|
|
42635
42697
|
endpoint: opts.endpoint,
|
|
42698
|
+
verifyPubKey: opts.verifyPubKey,
|
|
42636
42699
|
orgName: opts.orgName
|
|
42637
42700
|
});
|
|
42638
42701
|
const resolved = await atbash.resolveChainForOrg(opts.orgName);
|
|
@@ -42672,13 +42735,15 @@ function buildSigner(auth) {
|
|
|
42672
42735
|
}
|
|
42673
42736
|
async function commitMemoryVersion(plaintext, auth, opts) {
|
|
42674
42737
|
const score = opts?.score ?? 5;
|
|
42738
|
+
const filePath = opts?.filePath ?? "";
|
|
42675
42739
|
const key3 = await deriveMemoryKey(auth.privkey);
|
|
42676
42740
|
const { ciphertext, nonce } = await encryptMemoryContent(plaintext, key3);
|
|
42677
42741
|
const args = native.buildAddAgentMemoryArgs(
|
|
42678
42742
|
auth.pubkey,
|
|
42679
42743
|
ciphertext,
|
|
42680
42744
|
nonce,
|
|
42681
|
-
score
|
|
42745
|
+
score,
|
|
42746
|
+
filePath
|
|
42682
42747
|
);
|
|
42683
42748
|
const chainOpts = await resolveChainOptsForOrg(opts, auth);
|
|
42684
42749
|
const client = await buildChainClient(chainOpts);
|
|
@@ -42690,7 +42755,8 @@ async function commitMemoryVersion(plaintext, auth, opts) {
|
|
|
42690
42755
|
toGtxBytes(args.agent_pubkey),
|
|
42691
42756
|
toGtxBytes(args.content_cipher),
|
|
42692
42757
|
toGtxBytes(args.nonce),
|
|
42693
|
-
args.score
|
|
42758
|
+
args.score,
|
|
42759
|
+
args.file_path
|
|
42694
42760
|
]
|
|
42695
42761
|
},
|
|
42696
42762
|
sigProvider
|
|
@@ -42712,6 +42778,7 @@ async function decryptRow(row, key3) {
|
|
|
42712
42778
|
}
|
|
42713
42779
|
return {
|
|
42714
42780
|
id: parsed.id,
|
|
42781
|
+
filePath: parsed.file_path,
|
|
42715
42782
|
content,
|
|
42716
42783
|
decryptError,
|
|
42717
42784
|
score: parsed.score,
|
|
@@ -42720,39 +42787,52 @@ async function decryptRow(row, key3) {
|
|
|
42720
42787
|
updatedAt: parsed.updated_at
|
|
42721
42788
|
};
|
|
42722
42789
|
}
|
|
42723
|
-
|
|
42790
|
+
function paramsWithOptionalFilePath(agentPubkeyHex, filePath) {
|
|
42791
|
+
const params = {
|
|
42792
|
+
[native.ARG_AGENT_PUBKEY]: agentPubkeyHex
|
|
42793
|
+
};
|
|
42794
|
+
if (filePath !== null) {
|
|
42795
|
+
params[native.ARG_FILE_PATH] = filePath;
|
|
42796
|
+
}
|
|
42797
|
+
return params;
|
|
42798
|
+
}
|
|
42799
|
+
async function getActiveMemoryId(auth, chainOpts, filePath) {
|
|
42724
42800
|
const client = await buildChainClient(chainOpts);
|
|
42725
|
-
const q = native.buildGetActiveMemoryIdQuery(auth.pubkey);
|
|
42726
|
-
const raw2 = await client.query(
|
|
42727
|
-
|
|
42728
|
-
|
|
42801
|
+
const q = native.buildGetActiveMemoryIdQuery(auth.pubkey, filePath ?? null);
|
|
42802
|
+
const raw2 = await client.query(
|
|
42803
|
+
native.QUERY_GET_ACTIVE_MEMORY_ID,
|
|
42804
|
+
paramsWithOptionalFilePath(q.agent_pubkey_hex, q.file_path)
|
|
42805
|
+
);
|
|
42729
42806
|
return native.parseActiveMemoryId(raw2);
|
|
42730
42807
|
}
|
|
42731
|
-
async function
|
|
42808
|
+
async function getRecentAgentMemory(auth, chainOpts, filePath) {
|
|
42732
42809
|
const client = await buildChainClient(chainOpts);
|
|
42733
42810
|
const key3 = await deriveMemoryKey(auth.privkey);
|
|
42734
|
-
const q = native.
|
|
42735
|
-
const rows = await client.query(
|
|
42736
|
-
|
|
42737
|
-
|
|
42811
|
+
const q = native.buildGetRecentAgentMemoryQuery(auth.pubkey, filePath ?? null);
|
|
42812
|
+
const rows = await client.query(
|
|
42813
|
+
native.QUERY_GET_RECENT_AGENT_MEMORY,
|
|
42814
|
+
paramsWithOptionalFilePath(q.agent_pubkey_hex, q.file_path)
|
|
42815
|
+
);
|
|
42738
42816
|
return Promise.all((rows ?? []).map((r2) => decryptRow(r2, key3)));
|
|
42739
42817
|
}
|
|
42740
|
-
async function
|
|
42818
|
+
async function getActiveAgentMemory(auth, chainOpts, filePath) {
|
|
42741
42819
|
const client = await buildChainClient(chainOpts);
|
|
42742
42820
|
const key3 = await deriveMemoryKey(auth.privkey);
|
|
42743
|
-
const q = native.
|
|
42744
|
-
const rows = await client.query(
|
|
42745
|
-
|
|
42746
|
-
|
|
42821
|
+
const q = native.buildGetActiveAgentMemoryQuery(auth.pubkey, filePath ?? null);
|
|
42822
|
+
const rows = await client.query(
|
|
42823
|
+
native.QUERY_GET_ACTIVE_AGENT_MEMORY,
|
|
42824
|
+
paramsWithOptionalFilePath(q.agent_pubkey_hex, q.file_path)
|
|
42825
|
+
);
|
|
42747
42826
|
return Promise.all((rows ?? []).map((r2) => decryptRow(r2, key3)));
|
|
42748
42827
|
}
|
|
42749
|
-
async function getMemoryHistory(auth, chainOpts) {
|
|
42828
|
+
async function getMemoryHistory(auth, chainOpts, filePath) {
|
|
42750
42829
|
const client = await buildChainClient(chainOpts);
|
|
42751
42830
|
const key3 = await deriveMemoryKey(auth.privkey);
|
|
42752
|
-
const q = native.buildGetAgentMemoryHistoryQuery(auth.pubkey);
|
|
42753
|
-
const rows = await client.query(
|
|
42754
|
-
|
|
42755
|
-
|
|
42831
|
+
const q = native.buildGetAgentMemoryHistoryQuery(auth.pubkey, filePath ?? null);
|
|
42832
|
+
const rows = await client.query(
|
|
42833
|
+
native.QUERY_GET_AGENT_MEMORY_HISTORY,
|
|
42834
|
+
paramsWithOptionalFilePath(q.agent_pubkey_hex, q.file_path)
|
|
42835
|
+
);
|
|
42756
42836
|
return Promise.all((rows ?? []).map((r2) => decryptRow(r2, key3)));
|
|
42757
42837
|
}
|
|
42758
42838
|
async function getMemoryById(id, auth, chainOpts) {
|
|
@@ -42765,17 +42845,21 @@ async function getMemoryById(id, auth, chainOpts) {
|
|
|
42765
42845
|
});
|
|
42766
42846
|
return decryptRow(row, key3);
|
|
42767
42847
|
}
|
|
42768
|
-
async function getRollbackHistory(auth, chainOpts) {
|
|
42848
|
+
async function getRollbackHistory(auth, chainOpts, filePath) {
|
|
42769
42849
|
const client = await buildChainClient(chainOpts);
|
|
42770
|
-
const q = native.buildGetAgentMemoryRollbackHistoryQuery(
|
|
42850
|
+
const q = native.buildGetAgentMemoryRollbackHistoryQuery(
|
|
42851
|
+
auth.pubkey,
|
|
42852
|
+
filePath ?? null
|
|
42853
|
+
);
|
|
42771
42854
|
const raw2 = await client.query(
|
|
42772
42855
|
native.QUERY_GET_AGENT_MEMORY_ROLLBACK_HISTORY,
|
|
42773
|
-
|
|
42856
|
+
paramsWithOptionalFilePath(q.agent_pubkey_hex, q.file_path)
|
|
42774
42857
|
);
|
|
42775
42858
|
const parsed = native.parseRollbackRows(raw2 ?? []);
|
|
42776
42859
|
return parsed.map((r2) => ({
|
|
42777
42860
|
fromId: r2.from_id,
|
|
42778
42861
|
toId: r2.to_id,
|
|
42862
|
+
filePath: r2.file_path,
|
|
42779
42863
|
reason: r2.reason,
|
|
42780
42864
|
signer: Buffer.from(r2.signer).toString("hex"),
|
|
42781
42865
|
createdAt: r2.created_at
|
|
@@ -42843,8 +42927,7 @@ async function guardMemoryWrite(input) {
|
|
|
42843
42927
|
toolNames,
|
|
42844
42928
|
enforce = true,
|
|
42845
42929
|
debug: debug2 = false,
|
|
42846
|
-
logger: logger2
|
|
42847
|
-
memoryFilePath
|
|
42930
|
+
logger: logger2
|
|
42848
42931
|
} = input;
|
|
42849
42932
|
const memEntry = classifyMemoryWrite(event, ctx, { patterns, toolNames });
|
|
42850
42933
|
if (debug2) emitDebugProbe(event, ctx, memEntry, logger2);
|
|
@@ -42880,37 +42963,35 @@ async function guardMemoryWrite(input) {
|
|
|
42880
42963
|
committed: false
|
|
42881
42964
|
};
|
|
42882
42965
|
}
|
|
42883
|
-
const
|
|
42884
|
-
|
|
42885
|
-
|
|
42886
|
-
|
|
42887
|
-
|
|
42888
|
-
|
|
42889
|
-
|
|
42890
|
-
|
|
42891
|
-
|
|
42892
|
-
|
|
42893
|
-
|
|
42894
|
-
|
|
42966
|
+
const filePath = path3.basename(memEntry.key);
|
|
42967
|
+
commitMemoryVersion(memEntry.value, auth, {
|
|
42968
|
+
score: scanResult.score,
|
|
42969
|
+
filePath,
|
|
42970
|
+
orgName,
|
|
42971
|
+
endpoint,
|
|
42972
|
+
verifyPubKey
|
|
42973
|
+
}).catch((err) => {
|
|
42974
|
+
const reason = err instanceof Error ? err.message : String(err);
|
|
42975
|
+
logger2?.warn?.("[atbash] memory commit to chain failed", {
|
|
42976
|
+
path: memEntry.key,
|
|
42977
|
+
filePath,
|
|
42978
|
+
reason
|
|
42895
42979
|
});
|
|
42896
|
-
}
|
|
42897
|
-
logger2?.info?.(
|
|
42898
|
-
"[atbash] scanned but not committed \u2014 not the managed memory file",
|
|
42899
|
-
{
|
|
42900
|
-
path: memEntry.key,
|
|
42901
|
-
memoryFilePath: memoryFilePath ?? "(not configured)"
|
|
42902
|
-
}
|
|
42903
|
-
);
|
|
42904
|
-
}
|
|
42980
|
+
});
|
|
42905
42981
|
logger2?.info?.(
|
|
42906
42982
|
scanResult.verdict === "yellow" ? "[atbash] memory HOLD" : "[atbash] memory ALLOW",
|
|
42907
|
-
{
|
|
42983
|
+
{
|
|
42984
|
+
path: memEntry.key,
|
|
42985
|
+
filePath,
|
|
42986
|
+
score: scanResult.score,
|
|
42987
|
+
reason: scanResult.reason
|
|
42988
|
+
}
|
|
42908
42989
|
);
|
|
42909
42990
|
return {
|
|
42910
42991
|
handled: true,
|
|
42911
42992
|
decision: { allow: true },
|
|
42912
42993
|
scanResult,
|
|
42913
|
-
committed:
|
|
42994
|
+
committed: true
|
|
42914
42995
|
};
|
|
42915
42996
|
}
|
|
42916
42997
|
|
|
@@ -43150,9 +43231,7 @@ var MemoryGuardManager = class {
|
|
|
43150
43231
|
toolNames: this.opts.memoryWriteToolNames,
|
|
43151
43232
|
enforce: this.enforce,
|
|
43152
43233
|
debug: this.opts.debug,
|
|
43153
|
-
logger: guardLogger
|
|
43154
|
-
// Only this file may reach the single, path-less chain memory slot.
|
|
43155
|
-
memoryFilePath: this.memoryFilePath
|
|
43234
|
+
logger: guardLogger
|
|
43156
43235
|
});
|
|
43157
43236
|
return this.mapGuardResult(guard);
|
|
43158
43237
|
}
|
|
@@ -43452,13 +43531,13 @@ export {
|
|
|
43452
43531
|
encryptedLength,
|
|
43453
43532
|
flushTelemetry,
|
|
43454
43533
|
generateKeypair,
|
|
43455
|
-
|
|
43534
|
+
getActiveAgentMemory,
|
|
43456
43535
|
getActiveMemoryId,
|
|
43457
|
-
getAllAgentMemory,
|
|
43458
43536
|
getConfigDir,
|
|
43459
43537
|
getConfigPath,
|
|
43460
43538
|
getMemoryById,
|
|
43461
43539
|
getMemoryHistory,
|
|
43540
|
+
getRecentAgentMemory,
|
|
43462
43541
|
getRollbackHistory,
|
|
43463
43542
|
guardMemoryWrite,
|
|
43464
43543
|
isEnvelope,
|