@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.js
CHANGED
|
@@ -2896,13 +2896,13 @@ __export(src_ts_exports, {
|
|
|
2896
2896
|
encryptedLength: () => encryptedLength,
|
|
2897
2897
|
flushTelemetry: () => flushTelemetry,
|
|
2898
2898
|
generateKeypair: () => generateKeypair,
|
|
2899
|
-
|
|
2899
|
+
getActiveAgentMemory: () => getActiveAgentMemory,
|
|
2900
2900
|
getActiveMemoryId: () => getActiveMemoryId,
|
|
2901
|
-
getAllAgentMemory: () => getAllAgentMemory,
|
|
2902
2901
|
getConfigDir: () => getConfigDir,
|
|
2903
2902
|
getConfigPath: () => getConfigPath,
|
|
2904
2903
|
getMemoryById: () => getMemoryById,
|
|
2905
2904
|
getMemoryHistory: () => getMemoryHistory,
|
|
2905
|
+
getRecentAgentMemory: () => getRecentAgentMemory,
|
|
2906
2906
|
getRollbackHistory: () => getRollbackHistory,
|
|
2907
2907
|
guardMemoryWrite: () => guardMemoryWrite,
|
|
2908
2908
|
isEnvelope: () => isEnvelope,
|
|
@@ -3392,6 +3392,8 @@ var ENV_MAP = {
|
|
|
3392
3392
|
agentKey: "ATBASH_AGENT_KEY",
|
|
3393
3393
|
orgName: "ATBASH_ORG_NAME",
|
|
3394
3394
|
judgeEndpoint: "ATBASH_ENDPOINT",
|
|
3395
|
+
// Same variable name the Hermes plugin already documents.
|
|
3396
|
+
judgeVerifyPubKey: "ATBASH_JUDGE_VERIFY_PUBKEY",
|
|
3395
3397
|
blockchainRid: "ATBASH_BLOCKCHAIN_RID",
|
|
3396
3398
|
provider: "ATBASH_PROVIDER",
|
|
3397
3399
|
providerModel: "ATBASH_PROVIDER_MODEL",
|
|
@@ -3481,16 +3483,27 @@ var Atbash = class _Atbash {
|
|
|
3481
3483
|
* lazily as a signed `log_tool_call` tx and refreshed every 4 min so
|
|
3482
3484
|
* server-side replay protection windows never expire it mid-session.
|
|
3483
3485
|
*/
|
|
3484
|
-
|
|
3486
|
+
// Keyed by blockchainRid so bearers for the public and private chains can
|
|
3487
|
+
// coexist. The dashboard derives `authNetwork` from the BRID inside the
|
|
3488
|
+
// signed envelope, so a bearer signed for chain A cannot authenticate a
|
|
3489
|
+
// request routed to chain B — every chain the client talks to needs its own.
|
|
3490
|
+
_authBearers = /* @__PURE__ */ new Map();
|
|
3485
3491
|
/** Guards `logEnvironmentOnce` — hosts construct several clients. */
|
|
3486
3492
|
static environmentLogged = false;
|
|
3487
3493
|
constructor(privkey, options = {}) {
|
|
3488
3494
|
this.auth = native.loadAgent(privkey);
|
|
3489
|
-
|
|
3495
|
+
const validated = validateJudgeEndpoint(
|
|
3496
|
+
options.verifyPubKey ? {
|
|
3497
|
+
policy: "self-hosted",
|
|
3498
|
+
endpoint: options.endpoint ?? DEFAULT_ENDPOINT,
|
|
3499
|
+
verifyPubKey: options.verifyPubKey
|
|
3500
|
+
} : { endpoint: options.endpoint }
|
|
3501
|
+
);
|
|
3502
|
+
this.endpoint = validated.url;
|
|
3490
3503
|
this.nodeUrls = options.nodeUrls ? [...options.nodeUrls] : DEFAULT_CHROMIA_NODE_URLS;
|
|
3491
3504
|
this.blockchainRid = options.blockchainRid ?? native.DEFAULT_BLOCKCHAIN_RID;
|
|
3492
3505
|
this.orgName = options.orgName;
|
|
3493
|
-
this.verifyPubKey =
|
|
3506
|
+
this.verifyPubKey = validated.verifyPubKey ?? void 0;
|
|
3494
3507
|
this.orgEncryptionPubKey = options.orgEncryptionPubKey;
|
|
3495
3508
|
this.failClosed = options.failClosed !== false;
|
|
3496
3509
|
this.debug = options.debug === true;
|
|
@@ -3548,8 +3561,19 @@ var Atbash = class _Atbash {
|
|
|
3548
3561
|
* self-hosted endpoint's `verifyPubKey` becomes the client default.
|
|
3549
3562
|
*/
|
|
3550
3563
|
static fromConfig(options = {}) {
|
|
3564
|
+
const configuredEndpoint = resolve("judgeEndpoint") || void 0;
|
|
3565
|
+
const configuredVerifyPubKey = resolve("judgeVerifyPubKey") || void 0;
|
|
3566
|
+
if (!options.judge && configuredVerifyPubKey && !configuredEndpoint) {
|
|
3567
|
+
throw new Error(
|
|
3568
|
+
"judgeVerifyPubKey / ATBASH_JUDGE_VERIFY_PUBKEY is set but no judge endpoint is configured: set judgeEndpoint / ATBASH_ENDPOINT to the self-hosted judge"
|
|
3569
|
+
);
|
|
3570
|
+
}
|
|
3551
3571
|
const validated = validateJudgeEndpoint(
|
|
3552
|
-
options.judge ??
|
|
3572
|
+
options.judge ?? (configuredVerifyPubKey && configuredEndpoint ? {
|
|
3573
|
+
policy: "self-hosted",
|
|
3574
|
+
endpoint: configuredEndpoint,
|
|
3575
|
+
verifyPubKey: configuredVerifyPubKey
|
|
3576
|
+
} : { endpoint: configuredEndpoint })
|
|
3553
3577
|
);
|
|
3554
3578
|
const agentKey = resolve("agentKey", options.agentKey);
|
|
3555
3579
|
const auth = agentKey ? native.loadAgent(agentKey) : loadAgentFromFile(options.keyPath);
|
|
@@ -3597,10 +3621,11 @@ var Atbash = class _Atbash {
|
|
|
3597
3621
|
return this.track("checkAgentExists", pk, async () => {
|
|
3598
3622
|
const query = { pubkey: pk };
|
|
3599
3623
|
if (network) query.network = network;
|
|
3624
|
+
const brid = this.bridFromChainOpts(network ? { network } : void 0);
|
|
3600
3625
|
const resp = await this.http.get(
|
|
3601
3626
|
"/api/ai/exists",
|
|
3602
3627
|
query,
|
|
3603
|
-
this.authHeaders()
|
|
3628
|
+
this.authHeaders(brid)
|
|
3604
3629
|
);
|
|
3605
3630
|
await this.raiseIfError(resp);
|
|
3606
3631
|
const data = await this.json(resp);
|
|
@@ -3955,15 +3980,15 @@ var Atbash = class _Atbash {
|
|
|
3955
3980
|
() => this.riskEngineRecords("tool-calls", { limit: maxCount })
|
|
3956
3981
|
);
|
|
3957
3982
|
}
|
|
3958
|
-
getOrgToolCalls(orgName, maxCount) {
|
|
3959
|
-
return this.track(
|
|
3960
|
-
|
|
3961
|
-
|
|
3962
|
-
|
|
3963
|
-
org: orgName,
|
|
3964
|
-
|
|
3965
|
-
|
|
3966
|
-
);
|
|
3983
|
+
async getOrgToolCalls(orgName, maxCount) {
|
|
3984
|
+
return this.track("getOrgToolCalls", void 0, async () => {
|
|
3985
|
+
const brid = await this.bridForOrg(orgName);
|
|
3986
|
+
return this.riskEngineRecords(
|
|
3987
|
+
"org-tool-calls",
|
|
3988
|
+
{ org: orgName, limit: maxCount },
|
|
3989
|
+
brid
|
|
3990
|
+
);
|
|
3991
|
+
});
|
|
3967
3992
|
}
|
|
3968
3993
|
getAgentToolCalls(agentPubkey, maxCount) {
|
|
3969
3994
|
return this.track(
|
|
@@ -3993,7 +4018,12 @@ var Atbash = class _Atbash {
|
|
|
3993
4018
|
}
|
|
3994
4019
|
async getOrgTierInfo(orgName) {
|
|
3995
4020
|
return this.track("getOrgTierInfo", void 0, async () => {
|
|
3996
|
-
const
|
|
4021
|
+
const brid = await this.bridForOrg(orgName);
|
|
4022
|
+
const raw2 = await this.riskEngineGet(
|
|
4023
|
+
"org-tier-info",
|
|
4024
|
+
{ org: orgName },
|
|
4025
|
+
brid
|
|
4026
|
+
);
|
|
3997
4027
|
if (!isRecord(raw2)) return null;
|
|
3998
4028
|
return {
|
|
3999
4029
|
orgName: String(raw2.org_name ?? ""),
|
|
@@ -4005,20 +4035,24 @@ var Atbash = class _Atbash {
|
|
|
4005
4035
|
}
|
|
4006
4036
|
async getPendingHeldActions(orgName, maxCount) {
|
|
4007
4037
|
return this.track("getPendingHeldActions", void 0, async () => {
|
|
4008
|
-
const
|
|
4009
|
-
|
|
4010
|
-
|
|
4011
|
-
|
|
4038
|
+
const brid = await this.bridForOrg(orgName);
|
|
4039
|
+
const raw2 = await this.riskEngineGet(
|
|
4040
|
+
"pending-held-actions",
|
|
4041
|
+
{ org: orgName, limit: maxCount },
|
|
4042
|
+
brid
|
|
4043
|
+
);
|
|
4012
4044
|
if (!Array.isArray(raw2)) return [];
|
|
4013
4045
|
return raw2.map((item) => toHeldAction(item));
|
|
4014
4046
|
});
|
|
4015
4047
|
}
|
|
4016
4048
|
async getHeldActionReviews(orgName, maxCount) {
|
|
4017
4049
|
return this.track("getHeldActionReviews", void 0, async () => {
|
|
4018
|
-
const
|
|
4019
|
-
|
|
4020
|
-
|
|
4021
|
-
|
|
4050
|
+
const brid = await this.bridForOrg(orgName);
|
|
4051
|
+
const raw2 = await this.riskEngineGet(
|
|
4052
|
+
"held-action-reviews",
|
|
4053
|
+
{ org: orgName, limit: maxCount },
|
|
4054
|
+
brid
|
|
4055
|
+
);
|
|
4022
4056
|
if (!Array.isArray(raw2)) return [];
|
|
4023
4057
|
return raw2.map(
|
|
4024
4058
|
(item) => toHeldActionReview(item)
|
|
@@ -4029,21 +4063,25 @@ var Atbash = class _Atbash {
|
|
|
4029
4063
|
async getAgentDetail(agentPubkey, options = {}) {
|
|
4030
4064
|
return this.track("getAgentDetail", agentPubkey, async () => {
|
|
4031
4065
|
const network = await this.resolveAgentLookupNetwork(options);
|
|
4066
|
+
const brid = network ? this.bridFromChainOpts({ network }) : void 0;
|
|
4032
4067
|
return this.riskEnginePost(
|
|
4033
4068
|
{ action: "agent-detail-batch", agent: agentPubkey },
|
|
4034
|
-
network
|
|
4069
|
+
network,
|
|
4070
|
+
brid
|
|
4035
4071
|
);
|
|
4036
4072
|
});
|
|
4037
4073
|
}
|
|
4038
4074
|
async getAgentPolicy(agentPubkey, options = {}) {
|
|
4039
4075
|
return this.track("getAgentPolicy", agentPubkey, async () => {
|
|
4040
4076
|
const network = await this.resolveAgentLookupNetwork(options);
|
|
4077
|
+
const brid = network ? this.bridFromChainOpts({ network }) : void 0;
|
|
4041
4078
|
const raw2 = await this.riskEnginePost(
|
|
4042
4079
|
{
|
|
4043
4080
|
action: "agent-policy-batch",
|
|
4044
4081
|
agent: agentPubkey
|
|
4045
4082
|
},
|
|
4046
|
-
network
|
|
4083
|
+
network,
|
|
4084
|
+
brid
|
|
4047
4085
|
);
|
|
4048
4086
|
return {
|
|
4049
4087
|
policy: String(raw2.policy ?? ""),
|
|
@@ -4077,7 +4115,8 @@ var Atbash = class _Atbash {
|
|
|
4077
4115
|
return this.track("getOrgSubscription", void 0, async () => {
|
|
4078
4116
|
const params = { org: orgName };
|
|
4079
4117
|
if (network) params.network = network;
|
|
4080
|
-
const
|
|
4118
|
+
const brid = network ? this.bridFromChainOpts({ network }) : void 0;
|
|
4119
|
+
const raw2 = await this.riskEngineGet("org-subscription", params, brid);
|
|
4081
4120
|
if (!isRecord(raw2)) return null;
|
|
4082
4121
|
return coerceOrgSubscription(raw2, orgName);
|
|
4083
4122
|
});
|
|
@@ -4090,21 +4129,22 @@ var Atbash = class _Atbash {
|
|
|
4090
4129
|
* entry (caller falls back to per-chain subscription resolution).
|
|
4091
4130
|
*/
|
|
4092
4131
|
async getActiveNetworkForOrg(orgName) {
|
|
4132
|
+
let resp;
|
|
4093
4133
|
try {
|
|
4094
|
-
|
|
4134
|
+
resp = await this.http.get(
|
|
4095
4135
|
"/api/org-network",
|
|
4096
|
-
{ org: orgName },
|
|
4136
|
+
{ org: orgName.trim() },
|
|
4097
4137
|
this.authHeaders()
|
|
4098
4138
|
);
|
|
4099
|
-
|
|
4100
|
-
|
|
4101
|
-
|
|
4102
|
-
|
|
4103
|
-
|
|
4104
|
-
|
|
4105
|
-
|
|
4106
|
-
return null;
|
|
4139
|
+
} catch (err) {
|
|
4140
|
+
throw this.transportError(err);
|
|
4141
|
+
}
|
|
4142
|
+
if (resp.status !== 200) throw await this.httpError(resp);
|
|
4143
|
+
const data = await this.json(resp);
|
|
4144
|
+
if (data?.network === "public" || data?.network === "private") {
|
|
4145
|
+
return data.network;
|
|
4107
4146
|
}
|
|
4147
|
+
return null;
|
|
4108
4148
|
}
|
|
4109
4149
|
/**
|
|
4110
4150
|
* Resolve which chain an org's actions should run against. Cached
|
|
@@ -4116,10 +4156,11 @@ var Atbash = class _Atbash {
|
|
|
4116
4156
|
* Defaults to the public chain when nothing else resolves.
|
|
4117
4157
|
*/
|
|
4118
4158
|
async resolveChainForOrg(orgName) {
|
|
4119
|
-
const
|
|
4159
|
+
const name2 = orgName.trim();
|
|
4160
|
+
const cached = this._chainCache.get(name2);
|
|
4120
4161
|
if (cached) return cached;
|
|
4121
|
-
const mapNetwork = await this.getActiveNetworkForOrg(
|
|
4122
|
-
return this.resolveChainFromMap(
|
|
4162
|
+
const mapNetwork = await this.getActiveNetworkForOrg(name2);
|
|
4163
|
+
return this.resolveChainFromMap(name2, mapNetwork);
|
|
4123
4164
|
}
|
|
4124
4165
|
/**
|
|
4125
4166
|
* Resolve a chain given an already-fetched `org_networks` map result.
|
|
@@ -4135,29 +4176,38 @@ var Atbash = class _Atbash {
|
|
|
4135
4176
|
this._chainCache.set(orgName, chain);
|
|
4136
4177
|
return chain;
|
|
4137
4178
|
}
|
|
4138
|
-
|
|
4139
|
-
|
|
4140
|
-
|
|
4141
|
-
|
|
4142
|
-
|
|
4143
|
-
|
|
4144
|
-
|
|
4145
|
-
|
|
4146
|
-
|
|
4147
|
-
|
|
4148
|
-
|
|
4149
|
-
|
|
4150
|
-
|
|
4151
|
-
|
|
4152
|
-
|
|
4153
|
-
|
|
4154
|
-
|
|
4155
|
-
|
|
4156
|
-
|
|
4157
|
-
|
|
4158
|
-
|
|
4159
|
-
|
|
4160
|
-
|
|
4179
|
+
const [pubRes, privRes] = await Promise.allSettled([
|
|
4180
|
+
this.getOrgSubscription(orgName, "public"),
|
|
4181
|
+
this.getOrgSubscription(orgName, "private")
|
|
4182
|
+
]);
|
|
4183
|
+
const pubSub = pubRes.status === "fulfilled" ? pubRes.value : null;
|
|
4184
|
+
const privSub = privRes.status === "fulfilled" ? privRes.value : null;
|
|
4185
|
+
const failure = pubRes.status === "rejected" ? pubRes.reason : privRes.status === "rejected" ? privRes.reason : null;
|
|
4186
|
+
if (pubSub?.is_private_blockchain) {
|
|
4187
|
+
this._chainCache.set(orgName, PRIVATE_CHAIN);
|
|
4188
|
+
return PRIVATE_CHAIN;
|
|
4189
|
+
}
|
|
4190
|
+
if (pubSub && privSub) {
|
|
4191
|
+
const chain = privSub.assigned_at > pubSub.assigned_at ? PRIVATE_CHAIN : PUBLIC_CHAIN;
|
|
4192
|
+
this._chainCache.set(orgName, chain);
|
|
4193
|
+
return chain;
|
|
4194
|
+
}
|
|
4195
|
+
if (pubSub) {
|
|
4196
|
+
this._chainCache.set(orgName, PUBLIC_CHAIN);
|
|
4197
|
+
return PUBLIC_CHAIN;
|
|
4198
|
+
}
|
|
4199
|
+
if (privSub?.is_private_blockchain) {
|
|
4200
|
+
this._chainCache.set(orgName, PRIVATE_CHAIN);
|
|
4201
|
+
return PRIVATE_CHAIN;
|
|
4202
|
+
}
|
|
4203
|
+
if (failure) {
|
|
4204
|
+
const detail = failure instanceof Error ? failure.message : String(failure);
|
|
4205
|
+
throw new AtbashAPIError(
|
|
4206
|
+
failure instanceof AtbashAPIError ? failure.status : 0,
|
|
4207
|
+
`could not resolve the chain for org "${orgName}": ${detail}`,
|
|
4208
|
+
"",
|
|
4209
|
+
this.endpoint
|
|
4210
|
+
);
|
|
4161
4211
|
}
|
|
4162
4212
|
this._chainCache.set(orgName, PUBLIC_CHAIN);
|
|
4163
4213
|
return PUBLIC_CHAIN;
|
|
@@ -4222,11 +4272,11 @@ var Atbash = class _Atbash {
|
|
|
4222
4272
|
* for 4 minutes; refreshed after that so a long-lived client never
|
|
4223
4273
|
* trips the server's replay window.
|
|
4224
4274
|
*/
|
|
4225
|
-
getAuthBearer() {
|
|
4275
|
+
getAuthBearer(brid) {
|
|
4276
|
+
const chainBrid = brid ?? this.blockchainRid;
|
|
4226
4277
|
const now = Date.now();
|
|
4227
|
-
|
|
4228
|
-
|
|
4229
|
-
}
|
|
4278
|
+
const cached = this._authBearers.get(chainBrid);
|
|
4279
|
+
if (cached && now - cached.issuedAt < 4 * 60 * 1e3) return cached.hex;
|
|
4230
4280
|
const nonce = `auth-${now.toString(36)}-${randomHex(4)}`;
|
|
4231
4281
|
const hex = native.signLogToolCall(
|
|
4232
4282
|
nonce,
|
|
@@ -4235,21 +4285,21 @@ var Atbash = class _Atbash {
|
|
|
4235
4285
|
"auth-bearer",
|
|
4236
4286
|
"",
|
|
4237
4287
|
this.auth.privkey,
|
|
4238
|
-
|
|
4288
|
+
chainBrid
|
|
4239
4289
|
);
|
|
4240
|
-
this.
|
|
4290
|
+
this._authBearers.set(chainBrid, { hex, issuedAt: now });
|
|
4241
4291
|
return hex;
|
|
4242
4292
|
}
|
|
4243
|
-
authHeaders() {
|
|
4244
|
-
return { Authorization: `Bearer ${this.getAuthBearer()}` };
|
|
4293
|
+
authHeaders(brid) {
|
|
4294
|
+
return { Authorization: `Bearer ${this.getAuthBearer(brid)}` };
|
|
4245
4295
|
}
|
|
4246
|
-
async riskEngineGet(action, params) {
|
|
4296
|
+
async riskEngineGet(action, params, brid) {
|
|
4247
4297
|
let resp;
|
|
4248
4298
|
try {
|
|
4249
4299
|
resp = await this.http.get(
|
|
4250
4300
|
"/api/risk-engine",
|
|
4251
4301
|
{ action, ...params },
|
|
4252
|
-
this.authHeaders()
|
|
4302
|
+
this.authHeaders(brid)
|
|
4253
4303
|
);
|
|
4254
4304
|
} catch (err) {
|
|
4255
4305
|
throw this.transportError(err);
|
|
@@ -4257,11 +4307,11 @@ var Atbash = class _Atbash {
|
|
|
4257
4307
|
if (resp.status !== 200) throw await this.httpError(resp);
|
|
4258
4308
|
return this.json(resp);
|
|
4259
4309
|
}
|
|
4260
|
-
async riskEnginePost(body, network) {
|
|
4310
|
+
async riskEnginePost(body, network, brid) {
|
|
4261
4311
|
let resp;
|
|
4262
4312
|
try {
|
|
4263
4313
|
const path7 = network ? `/api/risk-engine?network=${encodeURIComponent(network)}` : "/api/risk-engine";
|
|
4264
|
-
resp = await this.http.post(path7, body, this.authHeaders());
|
|
4314
|
+
resp = await this.http.post(path7, body, this.authHeaders(brid));
|
|
4265
4315
|
} catch (err) {
|
|
4266
4316
|
throw this.transportError(err);
|
|
4267
4317
|
}
|
|
@@ -4269,11 +4319,23 @@ var Atbash = class _Atbash {
|
|
|
4269
4319
|
const data = await this.json(resp);
|
|
4270
4320
|
return isRecord(data) ? data : {};
|
|
4271
4321
|
}
|
|
4272
|
-
async riskEngineRecords(action, params) {
|
|
4273
|
-
const raw2 = await this.riskEngineGet(action, params);
|
|
4322
|
+
async riskEngineRecords(action, params, brid) {
|
|
4323
|
+
const raw2 = await this.riskEngineGet(action, params, brid);
|
|
4274
4324
|
if (!Array.isArray(raw2)) return [];
|
|
4275
4325
|
return raw2.map((item) => toToolCallRecord(item));
|
|
4276
4326
|
}
|
|
4327
|
+
/**
|
|
4328
|
+
* BRID for an org — one round-trip to the map, honoring the client's chain
|
|
4329
|
+
* cache. Returns undefined when the org is unknown, so the caller falls
|
|
4330
|
+
* back to the client default (best-effort discovery).
|
|
4331
|
+
*/
|
|
4332
|
+
async bridForOrg(orgName) {
|
|
4333
|
+
try {
|
|
4334
|
+
return (await this.resolveChainForOrg(orgName)).blockchainRid;
|
|
4335
|
+
} catch {
|
|
4336
|
+
return void 0;
|
|
4337
|
+
}
|
|
4338
|
+
}
|
|
4277
4339
|
async raiseIfError(resp) {
|
|
4278
4340
|
if (resp.ok) return;
|
|
4279
4341
|
throw await this.httpError(resp);
|
|
@@ -42714,6 +42776,7 @@ async function resolveChainOptsForOrg(opts, auth) {
|
|
|
42714
42776
|
if (opts?.orgName && !opts.chainOpts?.blockchainRid && auth) {
|
|
42715
42777
|
const atbash = new Atbash(auth.privkey, {
|
|
42716
42778
|
endpoint: opts.endpoint,
|
|
42779
|
+
verifyPubKey: opts.verifyPubKey,
|
|
42717
42780
|
orgName: opts.orgName
|
|
42718
42781
|
});
|
|
42719
42782
|
const resolved = await atbash.resolveChainForOrg(opts.orgName);
|
|
@@ -42753,13 +42816,15 @@ function buildSigner(auth) {
|
|
|
42753
42816
|
}
|
|
42754
42817
|
async function commitMemoryVersion(plaintext, auth, opts) {
|
|
42755
42818
|
const score = opts?.score ?? 5;
|
|
42819
|
+
const filePath = opts?.filePath ?? "";
|
|
42756
42820
|
const key3 = await deriveMemoryKey(auth.privkey);
|
|
42757
42821
|
const { ciphertext, nonce } = await encryptMemoryContent(plaintext, key3);
|
|
42758
42822
|
const args = native.buildAddAgentMemoryArgs(
|
|
42759
42823
|
auth.pubkey,
|
|
42760
42824
|
ciphertext,
|
|
42761
42825
|
nonce,
|
|
42762
|
-
score
|
|
42826
|
+
score,
|
|
42827
|
+
filePath
|
|
42763
42828
|
);
|
|
42764
42829
|
const chainOpts = await resolveChainOptsForOrg(opts, auth);
|
|
42765
42830
|
const client = await buildChainClient(chainOpts);
|
|
@@ -42771,7 +42836,8 @@ async function commitMemoryVersion(plaintext, auth, opts) {
|
|
|
42771
42836
|
toGtxBytes(args.agent_pubkey),
|
|
42772
42837
|
toGtxBytes(args.content_cipher),
|
|
42773
42838
|
toGtxBytes(args.nonce),
|
|
42774
|
-
args.score
|
|
42839
|
+
args.score,
|
|
42840
|
+
args.file_path
|
|
42775
42841
|
]
|
|
42776
42842
|
},
|
|
42777
42843
|
sigProvider
|
|
@@ -42793,6 +42859,7 @@ async function decryptRow(row, key3) {
|
|
|
42793
42859
|
}
|
|
42794
42860
|
return {
|
|
42795
42861
|
id: parsed.id,
|
|
42862
|
+
filePath: parsed.file_path,
|
|
42796
42863
|
content,
|
|
42797
42864
|
decryptError,
|
|
42798
42865
|
score: parsed.score,
|
|
@@ -42801,39 +42868,52 @@ async function decryptRow(row, key3) {
|
|
|
42801
42868
|
updatedAt: parsed.updated_at
|
|
42802
42869
|
};
|
|
42803
42870
|
}
|
|
42804
|
-
|
|
42871
|
+
function paramsWithOptionalFilePath(agentPubkeyHex, filePath) {
|
|
42872
|
+
const params = {
|
|
42873
|
+
[native.ARG_AGENT_PUBKEY]: agentPubkeyHex
|
|
42874
|
+
};
|
|
42875
|
+
if (filePath !== null) {
|
|
42876
|
+
params[native.ARG_FILE_PATH] = filePath;
|
|
42877
|
+
}
|
|
42878
|
+
return params;
|
|
42879
|
+
}
|
|
42880
|
+
async function getActiveMemoryId(auth, chainOpts, filePath) {
|
|
42805
42881
|
const client = await buildChainClient(chainOpts);
|
|
42806
|
-
const q = native.buildGetActiveMemoryIdQuery(auth.pubkey);
|
|
42807
|
-
const raw2 = await client.query(
|
|
42808
|
-
|
|
42809
|
-
|
|
42882
|
+
const q = native.buildGetActiveMemoryIdQuery(auth.pubkey, filePath ?? null);
|
|
42883
|
+
const raw2 = await client.query(
|
|
42884
|
+
native.QUERY_GET_ACTIVE_MEMORY_ID,
|
|
42885
|
+
paramsWithOptionalFilePath(q.agent_pubkey_hex, q.file_path)
|
|
42886
|
+
);
|
|
42810
42887
|
return native.parseActiveMemoryId(raw2);
|
|
42811
42888
|
}
|
|
42812
|
-
async function
|
|
42889
|
+
async function getRecentAgentMemory(auth, chainOpts, filePath) {
|
|
42813
42890
|
const client = await buildChainClient(chainOpts);
|
|
42814
42891
|
const key3 = await deriveMemoryKey(auth.privkey);
|
|
42815
|
-
const q = native.
|
|
42816
|
-
const rows = await client.query(
|
|
42817
|
-
|
|
42818
|
-
|
|
42892
|
+
const q = native.buildGetRecentAgentMemoryQuery(auth.pubkey, filePath ?? null);
|
|
42893
|
+
const rows = await client.query(
|
|
42894
|
+
native.QUERY_GET_RECENT_AGENT_MEMORY,
|
|
42895
|
+
paramsWithOptionalFilePath(q.agent_pubkey_hex, q.file_path)
|
|
42896
|
+
);
|
|
42819
42897
|
return Promise.all((rows ?? []).map((r2) => decryptRow(r2, key3)));
|
|
42820
42898
|
}
|
|
42821
|
-
async function
|
|
42899
|
+
async function getActiveAgentMemory(auth, chainOpts, filePath) {
|
|
42822
42900
|
const client = await buildChainClient(chainOpts);
|
|
42823
42901
|
const key3 = await deriveMemoryKey(auth.privkey);
|
|
42824
|
-
const q = native.
|
|
42825
|
-
const rows = await client.query(
|
|
42826
|
-
|
|
42827
|
-
|
|
42902
|
+
const q = native.buildGetActiveAgentMemoryQuery(auth.pubkey, filePath ?? null);
|
|
42903
|
+
const rows = await client.query(
|
|
42904
|
+
native.QUERY_GET_ACTIVE_AGENT_MEMORY,
|
|
42905
|
+
paramsWithOptionalFilePath(q.agent_pubkey_hex, q.file_path)
|
|
42906
|
+
);
|
|
42828
42907
|
return Promise.all((rows ?? []).map((r2) => decryptRow(r2, key3)));
|
|
42829
42908
|
}
|
|
42830
|
-
async function getMemoryHistory(auth, chainOpts) {
|
|
42909
|
+
async function getMemoryHistory(auth, chainOpts, filePath) {
|
|
42831
42910
|
const client = await buildChainClient(chainOpts);
|
|
42832
42911
|
const key3 = await deriveMemoryKey(auth.privkey);
|
|
42833
|
-
const q = native.buildGetAgentMemoryHistoryQuery(auth.pubkey);
|
|
42834
|
-
const rows = await client.query(
|
|
42835
|
-
|
|
42836
|
-
|
|
42912
|
+
const q = native.buildGetAgentMemoryHistoryQuery(auth.pubkey, filePath ?? null);
|
|
42913
|
+
const rows = await client.query(
|
|
42914
|
+
native.QUERY_GET_AGENT_MEMORY_HISTORY,
|
|
42915
|
+
paramsWithOptionalFilePath(q.agent_pubkey_hex, q.file_path)
|
|
42916
|
+
);
|
|
42837
42917
|
return Promise.all((rows ?? []).map((r2) => decryptRow(r2, key3)));
|
|
42838
42918
|
}
|
|
42839
42919
|
async function getMemoryById(id, auth, chainOpts) {
|
|
@@ -42846,17 +42926,21 @@ async function getMemoryById(id, auth, chainOpts) {
|
|
|
42846
42926
|
});
|
|
42847
42927
|
return decryptRow(row, key3);
|
|
42848
42928
|
}
|
|
42849
|
-
async function getRollbackHistory(auth, chainOpts) {
|
|
42929
|
+
async function getRollbackHistory(auth, chainOpts, filePath) {
|
|
42850
42930
|
const client = await buildChainClient(chainOpts);
|
|
42851
|
-
const q = native.buildGetAgentMemoryRollbackHistoryQuery(
|
|
42931
|
+
const q = native.buildGetAgentMemoryRollbackHistoryQuery(
|
|
42932
|
+
auth.pubkey,
|
|
42933
|
+
filePath ?? null
|
|
42934
|
+
);
|
|
42852
42935
|
const raw2 = await client.query(
|
|
42853
42936
|
native.QUERY_GET_AGENT_MEMORY_ROLLBACK_HISTORY,
|
|
42854
|
-
|
|
42937
|
+
paramsWithOptionalFilePath(q.agent_pubkey_hex, q.file_path)
|
|
42855
42938
|
);
|
|
42856
42939
|
const parsed = native.parseRollbackRows(raw2 ?? []);
|
|
42857
42940
|
return parsed.map((r2) => ({
|
|
42858
42941
|
fromId: r2.from_id,
|
|
42859
42942
|
toId: r2.to_id,
|
|
42943
|
+
filePath: r2.file_path,
|
|
42860
42944
|
reason: r2.reason,
|
|
42861
42945
|
signer: Buffer.from(r2.signer).toString("hex"),
|
|
42862
42946
|
createdAt: r2.created_at
|
|
@@ -42924,8 +43008,7 @@ async function guardMemoryWrite(input) {
|
|
|
42924
43008
|
toolNames,
|
|
42925
43009
|
enforce = true,
|
|
42926
43010
|
debug: debug2 = false,
|
|
42927
|
-
logger: logger2
|
|
42928
|
-
memoryFilePath
|
|
43011
|
+
logger: logger2
|
|
42929
43012
|
} = input;
|
|
42930
43013
|
const memEntry = classifyMemoryWrite(event, ctx, { patterns, toolNames });
|
|
42931
43014
|
if (debug2) emitDebugProbe(event, ctx, memEntry, logger2);
|
|
@@ -42961,37 +43044,35 @@ async function guardMemoryWrite(input) {
|
|
|
42961
43044
|
committed: false
|
|
42962
43045
|
};
|
|
42963
43046
|
}
|
|
42964
|
-
const
|
|
42965
|
-
|
|
42966
|
-
|
|
42967
|
-
|
|
42968
|
-
|
|
42969
|
-
|
|
42970
|
-
|
|
42971
|
-
|
|
42972
|
-
|
|
42973
|
-
|
|
42974
|
-
|
|
42975
|
-
|
|
43047
|
+
const filePath = import_node_path4.default.basename(memEntry.key);
|
|
43048
|
+
commitMemoryVersion(memEntry.value, auth, {
|
|
43049
|
+
score: scanResult.score,
|
|
43050
|
+
filePath,
|
|
43051
|
+
orgName,
|
|
43052
|
+
endpoint,
|
|
43053
|
+
verifyPubKey
|
|
43054
|
+
}).catch((err) => {
|
|
43055
|
+
const reason = err instanceof Error ? err.message : String(err);
|
|
43056
|
+
logger2?.warn?.("[atbash] memory commit to chain failed", {
|
|
43057
|
+
path: memEntry.key,
|
|
43058
|
+
filePath,
|
|
43059
|
+
reason
|
|
42976
43060
|
});
|
|
42977
|
-
}
|
|
42978
|
-
logger2?.info?.(
|
|
42979
|
-
"[atbash] scanned but not committed \u2014 not the managed memory file",
|
|
42980
|
-
{
|
|
42981
|
-
path: memEntry.key,
|
|
42982
|
-
memoryFilePath: memoryFilePath ?? "(not configured)"
|
|
42983
|
-
}
|
|
42984
|
-
);
|
|
42985
|
-
}
|
|
43061
|
+
});
|
|
42986
43062
|
logger2?.info?.(
|
|
42987
43063
|
scanResult.verdict === "yellow" ? "[atbash] memory HOLD" : "[atbash] memory ALLOW",
|
|
42988
|
-
{
|
|
43064
|
+
{
|
|
43065
|
+
path: memEntry.key,
|
|
43066
|
+
filePath,
|
|
43067
|
+
score: scanResult.score,
|
|
43068
|
+
reason: scanResult.reason
|
|
43069
|
+
}
|
|
42989
43070
|
);
|
|
42990
43071
|
return {
|
|
42991
43072
|
handled: true,
|
|
42992
43073
|
decision: { allow: true },
|
|
42993
43074
|
scanResult,
|
|
42994
|
-
committed:
|
|
43075
|
+
committed: true
|
|
42995
43076
|
};
|
|
42996
43077
|
}
|
|
42997
43078
|
|
|
@@ -43231,9 +43312,7 @@ var MemoryGuardManager = class {
|
|
|
43231
43312
|
toolNames: this.opts.memoryWriteToolNames,
|
|
43232
43313
|
enforce: this.enforce,
|
|
43233
43314
|
debug: this.opts.debug,
|
|
43234
|
-
logger: guardLogger
|
|
43235
|
-
// Only this file may reach the single, path-less chain memory slot.
|
|
43236
|
-
memoryFilePath: this.memoryFilePath
|
|
43315
|
+
logger: guardLogger
|
|
43237
43316
|
});
|
|
43238
43317
|
return this.mapGuardResult(guard);
|
|
43239
43318
|
}
|
|
@@ -43534,13 +43613,13 @@ function diffMemorySnapshots(before, after) {
|
|
|
43534
43613
|
encryptedLength,
|
|
43535
43614
|
flushTelemetry,
|
|
43536
43615
|
generateKeypair,
|
|
43537
|
-
|
|
43616
|
+
getActiveAgentMemory,
|
|
43538
43617
|
getActiveMemoryId,
|
|
43539
|
-
getAllAgentMemory,
|
|
43540
43618
|
getConfigDir,
|
|
43541
43619
|
getConfigPath,
|
|
43542
43620
|
getMemoryById,
|
|
43543
43621
|
getMemoryHistory,
|
|
43622
|
+
getRecentAgentMemory,
|
|
43544
43623
|
getRollbackHistory,
|
|
43545
43624
|
guardMemoryWrite,
|
|
43546
43625
|
isEnvelope,
|