@atbash/sdk 0.10.13-dev.0 → 0.13.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 +113 -20
- package/dist/browser.mjs +229 -98
- package/dist/browser.mjs.map +1 -1
- package/dist/index.d.mts +113 -20
- package/dist/index.d.ts +113 -20
- package/dist/index.js +297 -118
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +292 -116
- package/dist/index.mjs.map +1 -1
- package/index.d.ts +39 -22
- package/index.js +166 -86
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -2869,10 +2869,13 @@ __export(src_ts_exports, {
|
|
|
2869
2869
|
KEY_FILENAMES: () => KEY_FILENAMES,
|
|
2870
2870
|
MemoryGuardManager: () => MemoryGuardManager,
|
|
2871
2871
|
MemoryIntegrityError: () => MemoryIntegrityError,
|
|
2872
|
+
PRIVATE_CHAIN: () => PRIVATE_CHAIN,
|
|
2873
|
+
PUBLIC_CHAIN: () => PUBLIC_CHAIN,
|
|
2872
2874
|
PointerStore: () => PointerStore,
|
|
2873
2875
|
SignatureVerificationError: () => SignatureVerificationError,
|
|
2874
2876
|
bootSyncFailureLine: () => bootSyncFailureLine,
|
|
2875
2877
|
buildAllowedJudgeHosts: () => buildAllowedJudgeHosts,
|
|
2878
|
+
chainForNetwork: () => chainForNetwork,
|
|
2876
2879
|
chooseKeyPath: () => chooseKeyPath,
|
|
2877
2880
|
claimHashHex: () => claimHashHex,
|
|
2878
2881
|
classifyMemoryRead: () => classifyMemoryRead,
|
|
@@ -2896,13 +2899,13 @@ __export(src_ts_exports, {
|
|
|
2896
2899
|
encryptedLength: () => encryptedLength,
|
|
2897
2900
|
flushTelemetry: () => flushTelemetry,
|
|
2898
2901
|
generateKeypair: () => generateKeypair,
|
|
2899
|
-
|
|
2902
|
+
getActiveAgentMemory: () => getActiveAgentMemory,
|
|
2900
2903
|
getActiveMemoryId: () => getActiveMemoryId,
|
|
2901
|
-
getAllAgentMemory: () => getAllAgentMemory,
|
|
2902
2904
|
getConfigDir: () => getConfigDir,
|
|
2903
2905
|
getConfigPath: () => getConfigPath,
|
|
2904
2906
|
getMemoryById: () => getMemoryById,
|
|
2905
2907
|
getMemoryHistory: () => getMemoryHistory,
|
|
2908
|
+
getRecentAgentMemory: () => getRecentAgentMemory,
|
|
2906
2909
|
getRollbackHistory: () => getRollbackHistory,
|
|
2907
2910
|
guardMemoryWrite: () => guardMemoryWrite,
|
|
2908
2911
|
isEnvelope: () => isEnvelope,
|
|
@@ -3392,11 +3395,36 @@ var ENV_MAP = {
|
|
|
3392
3395
|
agentKey: "ATBASH_AGENT_KEY",
|
|
3393
3396
|
orgName: "ATBASH_ORG_NAME",
|
|
3394
3397
|
judgeEndpoint: "ATBASH_ENDPOINT",
|
|
3395
|
-
|
|
3398
|
+
// Same variable name the Hermes plugin already documents.
|
|
3399
|
+
judgeVerifyPubKey: "ATBASH_JUDGE_VERIFY_PUBKEY",
|
|
3400
|
+
defaultChainNetwork: "ATBASH_DEFAULT_CHAIN_NETWORK",
|
|
3396
3401
|
provider: "ATBASH_PROVIDER",
|
|
3397
3402
|
providerModel: "ATBASH_PROVIDER_MODEL",
|
|
3398
3403
|
debug: "ATBASH_DEBUG"
|
|
3399
3404
|
};
|
|
3405
|
+
var DEPRECATED_ENV_VARS = ["ATBASH_BLOCKCHAIN_RID"];
|
|
3406
|
+
var DEPRECATED_CONFIG_FIELDS = ["blockchainRid"];
|
|
3407
|
+
var deprecatedWarned = false;
|
|
3408
|
+
function warnDeprecatedEnvVarsOnce(log = console.warn) {
|
|
3409
|
+
if (deprecatedWarned) return;
|
|
3410
|
+
for (const name2 of DEPRECATED_ENV_VARS) {
|
|
3411
|
+
if (process.env[name2]) {
|
|
3412
|
+
deprecatedWarned = true;
|
|
3413
|
+
log(
|
|
3414
|
+
`[atbash] ${name2} is ignored \u2014 each org's chain is resolved from the dashboard; set ATBASH_DEFAULT_CHAIN_NETWORK=private only to pin everything to private`
|
|
3415
|
+
);
|
|
3416
|
+
}
|
|
3417
|
+
}
|
|
3418
|
+
const fileConfig = loadUserConfig();
|
|
3419
|
+
for (const field of DEPRECATED_CONFIG_FIELDS) {
|
|
3420
|
+
if (fileConfig[field]) {
|
|
3421
|
+
deprecatedWarned = true;
|
|
3422
|
+
log(
|
|
3423
|
+
`[atbash] "${field}" in ${getConfigPath()} is ignored \u2014 pass \`chain\` or \`network\` at construction instead`
|
|
3424
|
+
);
|
|
3425
|
+
}
|
|
3426
|
+
}
|
|
3427
|
+
}
|
|
3400
3428
|
function getConfigDir() {
|
|
3401
3429
|
const home2 = process.env.HOME || (0, import_node_os3.homedir)() || "";
|
|
3402
3430
|
return (0, import_node_path3.join)(home2, ".config", "atbash");
|
|
@@ -3438,11 +3466,41 @@ function resolve(key3, flagValue) {
|
|
|
3438
3466
|
if (fileVal != null) return String(fileVal);
|
|
3439
3467
|
return "";
|
|
3440
3468
|
}
|
|
3469
|
+
function forcedChainNetwork(flagValue) {
|
|
3470
|
+
const raw2 = resolve("defaultChainNetwork", flagValue);
|
|
3471
|
+
if (!raw2) return void 0;
|
|
3472
|
+
if (raw2 !== "public" && raw2 !== "private") {
|
|
3473
|
+
throw new Error(
|
|
3474
|
+
`ATBASH_DEFAULT_CHAIN_NETWORK / defaultChainNetwork must be "public" or "private", got ${JSON.stringify(raw2)} \u2014 unset it to let each org's chain decide.`
|
|
3475
|
+
);
|
|
3476
|
+
}
|
|
3477
|
+
return raw2;
|
|
3478
|
+
}
|
|
3441
3479
|
|
|
3442
3480
|
// src-ts/client.ts
|
|
3443
3481
|
function generateToolCallId() {
|
|
3444
3482
|
return `tc-${Date.now()}-${randomHex(4)}`;
|
|
3445
3483
|
}
|
|
3484
|
+
function resolveConstructorChain(options) {
|
|
3485
|
+
if (options.chain) return options.chain;
|
|
3486
|
+
const hasNodeUrls = options.nodeUrls !== void 0;
|
|
3487
|
+
const hasBrid = options.blockchainRid !== void 0;
|
|
3488
|
+
if (hasNodeUrls !== hasBrid) {
|
|
3489
|
+
throw new Error(
|
|
3490
|
+
'nodeUrls and blockchainRid must be provided together \u2014 passing one without the other 404s every chain request. Prefer `chain: PUBLIC_CHAIN | PRIVATE_CHAIN` or `network: "public" | "private"`.'
|
|
3491
|
+
);
|
|
3492
|
+
}
|
|
3493
|
+
if (hasNodeUrls && hasBrid) {
|
|
3494
|
+
const brid = options.blockchainRid;
|
|
3495
|
+
const derivedNetwork = options.network ?? (brid === PUBLIC_CHAIN.blockchainRid ? "public" : brid === PRIVATE_CHAIN.blockchainRid ? "private" : "private");
|
|
3496
|
+
return {
|
|
3497
|
+
network: derivedNetwork,
|
|
3498
|
+
blockchainRid: brid,
|
|
3499
|
+
nodeUrls: options.nodeUrls
|
|
3500
|
+
};
|
|
3501
|
+
}
|
|
3502
|
+
return chainForNetwork(options.network ?? forcedChainNetwork() ?? "private");
|
|
3503
|
+
}
|
|
3446
3504
|
var Atbash = class _Atbash {
|
|
3447
3505
|
auth;
|
|
3448
3506
|
endpoint;
|
|
@@ -3466,6 +3524,27 @@ var Atbash = class _Atbash {
|
|
|
3466
3524
|
* calls don't re-hit the dashboard. Cleared by `clearChainCache()`.
|
|
3467
3525
|
*/
|
|
3468
3526
|
_chainCache = /* @__PURE__ */ new Map();
|
|
3527
|
+
/**
|
|
3528
|
+
* The chain the constructor settled on. Used only where a lookup returns no
|
|
3529
|
+
* answer — see {@link resolveChainFromMap}.
|
|
3530
|
+
*/
|
|
3531
|
+
_defaultChain;
|
|
3532
|
+
/**
|
|
3533
|
+
* True when the caller named a chain outright — `chain`, `network`, or the
|
|
3534
|
+
* paired `blockchainRid` + `nodeUrls`.
|
|
3535
|
+
*
|
|
3536
|
+
* Such a client is never re-pointed: not by the migration switch, and not by
|
|
3537
|
+
* where an org turns out to live. Naming a chain is the caller saying "talk
|
|
3538
|
+
* to this one", and silently routing elsewhere would make the argument a
|
|
3539
|
+
* suggestion. A client that names nothing is the one that follows the org.
|
|
3540
|
+
*/
|
|
3541
|
+
_explicitChain;
|
|
3542
|
+
/**
|
|
3543
|
+
* The fleet-wide chain switch, read once at construction. `resolve()` hits
|
|
3544
|
+
* the config file on disk, so re-reading it per call would put a file read
|
|
3545
|
+
* on every judge.
|
|
3546
|
+
*/
|
|
3547
|
+
_forcedNetwork;
|
|
3469
3548
|
/**
|
|
3470
3549
|
* Short-TTL cache for `/api/ai/exists`. The `registered` field is
|
|
3471
3550
|
* monotonic (once true, stays true), so most calls in a burst re-fetch
|
|
@@ -3490,11 +3569,23 @@ var Atbash = class _Atbash {
|
|
|
3490
3569
|
static environmentLogged = false;
|
|
3491
3570
|
constructor(privkey, options = {}) {
|
|
3492
3571
|
this.auth = native.loadAgent(privkey);
|
|
3493
|
-
|
|
3494
|
-
|
|
3495
|
-
|
|
3572
|
+
const validated = validateJudgeEndpoint(
|
|
3573
|
+
options.verifyPubKey ? {
|
|
3574
|
+
policy: "self-hosted",
|
|
3575
|
+
endpoint: options.endpoint ?? DEFAULT_ENDPOINT,
|
|
3576
|
+
verifyPubKey: options.verifyPubKey
|
|
3577
|
+
} : { endpoint: options.endpoint }
|
|
3578
|
+
);
|
|
3579
|
+
this.endpoint = validated.url;
|
|
3580
|
+
const resolvedChain = resolveConstructorChain(options);
|
|
3581
|
+
this.nodeUrls = [...resolvedChain.nodeUrls];
|
|
3582
|
+
this.blockchainRid = resolvedChain.blockchainRid;
|
|
3583
|
+
this._defaultChain = resolvedChain;
|
|
3584
|
+
this._explicitChain = options.chain !== void 0 || options.network !== void 0 || options.blockchainRid !== void 0 && options.nodeUrls !== void 0;
|
|
3585
|
+
this._forcedNetwork = forcedChainNetwork();
|
|
3586
|
+
warnDeprecatedEnvVarsOnce((msg) => options.logger?.warn?.(msg));
|
|
3496
3587
|
this.orgName = options.orgName;
|
|
3497
|
-
this.verifyPubKey =
|
|
3588
|
+
this.verifyPubKey = validated.verifyPubKey ?? void 0;
|
|
3498
3589
|
this.orgEncryptionPubKey = options.orgEncryptionPubKey;
|
|
3499
3590
|
this.failClosed = options.failClosed !== false;
|
|
3500
3591
|
this.debug = options.debug === true;
|
|
@@ -3552,15 +3643,27 @@ var Atbash = class _Atbash {
|
|
|
3552
3643
|
* self-hosted endpoint's `verifyPubKey` becomes the client default.
|
|
3553
3644
|
*/
|
|
3554
3645
|
static fromConfig(options = {}) {
|
|
3646
|
+
const configuredEndpoint = resolve("judgeEndpoint") || void 0;
|
|
3647
|
+
const configuredVerifyPubKey = resolve("judgeVerifyPubKey") || void 0;
|
|
3648
|
+
if (!options.judge && configuredVerifyPubKey && !configuredEndpoint) {
|
|
3649
|
+
throw new Error(
|
|
3650
|
+
"judgeVerifyPubKey / ATBASH_JUDGE_VERIFY_PUBKEY is set but no judge endpoint is configured: set judgeEndpoint / ATBASH_ENDPOINT to the self-hosted judge"
|
|
3651
|
+
);
|
|
3652
|
+
}
|
|
3555
3653
|
const validated = validateJudgeEndpoint(
|
|
3556
|
-
options.judge ??
|
|
3654
|
+
options.judge ?? (configuredVerifyPubKey && configuredEndpoint ? {
|
|
3655
|
+
policy: "self-hosted",
|
|
3656
|
+
endpoint: configuredEndpoint,
|
|
3657
|
+
verifyPubKey: configuredVerifyPubKey
|
|
3658
|
+
} : { endpoint: configuredEndpoint })
|
|
3557
3659
|
);
|
|
3558
3660
|
const agentKey = resolve("agentKey", options.agentKey);
|
|
3559
3661
|
const auth = agentKey ? native.loadAgent(agentKey) : loadAgentFromFile(options.keyPath);
|
|
3560
|
-
const blockchainRid = resolve("blockchainRid", options.blockchainRid) || void 0;
|
|
3561
3662
|
return new _Atbash(auth.privkey, {
|
|
3562
3663
|
endpoint: validated.url,
|
|
3563
|
-
|
|
3664
|
+
chain: options.chain,
|
|
3665
|
+
network: options.network,
|
|
3666
|
+
blockchainRid: options.blockchainRid,
|
|
3564
3667
|
timeoutMs: options.timeoutMs,
|
|
3565
3668
|
nodeUrls: options.nodeUrls,
|
|
3566
3669
|
orgName: options.orgName,
|
|
@@ -3601,7 +3704,7 @@ var Atbash = class _Atbash {
|
|
|
3601
3704
|
return this.track("checkAgentExists", pk, async () => {
|
|
3602
3705
|
const query = { pubkey: pk };
|
|
3603
3706
|
if (network) query.network = network;
|
|
3604
|
-
const brid = this.bridFromChainOpts(
|
|
3707
|
+
const brid = network ? this.bridFromChainOpts({ network }) : await this.defaultOrgBrid();
|
|
3605
3708
|
const resp = await this.http.get(
|
|
3606
3709
|
"/api/ai/exists",
|
|
3607
3710
|
query,
|
|
@@ -3652,7 +3755,7 @@ var Atbash = class _Atbash {
|
|
|
3652
3755
|
};
|
|
3653
3756
|
}
|
|
3654
3757
|
const toolCallId = generateToolCallId();
|
|
3655
|
-
const brid = this.bridFromChainOpts(options.chainOpts);
|
|
3758
|
+
const brid = options.chainOpts?.blockchainRid || options.chainOpts?.network ? this.bridFromChainOpts(options.chainOpts) : await this.defaultOrgBrid() ?? this.blockchainRid;
|
|
3656
3759
|
const orgKey = options.orgEncryptionPubKey ?? this.orgEncryptionPubKey ?? this._orgKeyFromChain;
|
|
3657
3760
|
try {
|
|
3658
3761
|
const signedHex = orgKey ? signEncryptedToolCall(
|
|
@@ -3703,7 +3806,11 @@ var Atbash = class _Atbash {
|
|
|
3703
3806
|
throw new Error("action is required and cannot be empty.");
|
|
3704
3807
|
}
|
|
3705
3808
|
let chainOpts = options.chainOpts;
|
|
3706
|
-
if (options.orgName) {
|
|
3809
|
+
if (options.orgName && this._explicitChain) {
|
|
3810
|
+
chainOpts = options.chainOpts ?? { network: this._defaultChain.network };
|
|
3811
|
+
} else if (options.orgName && this.forcedNetwork()) {
|
|
3812
|
+
chainOpts = { network: this.forcedNetwork() };
|
|
3813
|
+
} else if (options.orgName) {
|
|
3707
3814
|
const cached = this._chainCache.get(options.orgName);
|
|
3708
3815
|
if (cached) {
|
|
3709
3816
|
chainOpts = { network: cached.network };
|
|
@@ -3937,7 +4044,7 @@ var Atbash = class _Atbash {
|
|
|
3937
4044
|
const resp = await this.http.get(
|
|
3938
4045
|
"/api/v1/judge",
|
|
3939
4046
|
{ tool_call_id: judgmentId, agent_pubkey: pk },
|
|
3940
|
-
this.authHeaders()
|
|
4047
|
+
this.authHeaders(await this.defaultOrgBrid())
|
|
3941
4048
|
);
|
|
3942
4049
|
await this.raiseIfError(resp);
|
|
3943
4050
|
const data = await this.json(resp) ?? {};
|
|
@@ -3957,7 +4064,11 @@ var Atbash = class _Atbash {
|
|
|
3957
4064
|
return this.track(
|
|
3958
4065
|
"getToolCalls",
|
|
3959
4066
|
void 0,
|
|
3960
|
-
() => this.riskEngineRecords(
|
|
4067
|
+
async () => this.riskEngineRecords(
|
|
4068
|
+
"tool-calls",
|
|
4069
|
+
{ limit: maxCount },
|
|
4070
|
+
await this.defaultOrgBrid()
|
|
4071
|
+
)
|
|
3961
4072
|
);
|
|
3962
4073
|
}
|
|
3963
4074
|
async getOrgToolCalls(orgName, maxCount) {
|
|
@@ -3974,24 +4085,31 @@ var Atbash = class _Atbash {
|
|
|
3974
4085
|
return this.track(
|
|
3975
4086
|
"getAgentToolCalls",
|
|
3976
4087
|
agentPubkey,
|
|
3977
|
-
() => this.riskEngineRecords(
|
|
3978
|
-
agent
|
|
3979
|
-
limit: maxCount
|
|
3980
|
-
|
|
4088
|
+
async () => this.riskEngineRecords(
|
|
4089
|
+
"agent-tool-calls",
|
|
4090
|
+
{ agent: agentPubkey, limit: maxCount },
|
|
4091
|
+
await this.defaultOrgBrid()
|
|
4092
|
+
)
|
|
3981
4093
|
);
|
|
3982
4094
|
}
|
|
3983
4095
|
async getToolCallCount() {
|
|
3984
4096
|
return this.track("getToolCallCount", void 0, async () => {
|
|
3985
|
-
const raw2 = await this.riskEngineGet(
|
|
4097
|
+
const raw2 = await this.riskEngineGet(
|
|
4098
|
+
"tool-call-count",
|
|
4099
|
+
{},
|
|
4100
|
+
await this.defaultOrgBrid()
|
|
4101
|
+
);
|
|
3986
4102
|
const n = Number(raw2);
|
|
3987
4103
|
return Number.isFinite(n) ? n : 0;
|
|
3988
4104
|
});
|
|
3989
4105
|
}
|
|
3990
4106
|
async getToolCallFull(toolCallId) {
|
|
3991
4107
|
return this.track("getToolCallFull", void 0, async () => {
|
|
3992
|
-
const raw2 = await this.riskEngineGet(
|
|
3993
|
-
|
|
3994
|
-
|
|
4108
|
+
const raw2 = await this.riskEngineGet(
|
|
4109
|
+
"tool-call-full",
|
|
4110
|
+
{ tool_call_id: toolCallId },
|
|
4111
|
+
await this.defaultOrgBrid()
|
|
4112
|
+
);
|
|
3995
4113
|
if (!isRecord(raw2)) return null;
|
|
3996
4114
|
return toToolCallFull(raw2);
|
|
3997
4115
|
});
|
|
@@ -4077,7 +4195,7 @@ var Atbash = class _Atbash {
|
|
|
4077
4195
|
const resp = await this.http.get(
|
|
4078
4196
|
"/api/insurance",
|
|
4079
4197
|
{ action: "safety-stats" },
|
|
4080
|
-
this.authHeaders()
|
|
4198
|
+
this.authHeaders(await this.defaultOrgBrid())
|
|
4081
4199
|
);
|
|
4082
4200
|
await this.raiseIfError(resp);
|
|
4083
4201
|
const data = await this.json(resp) ?? {};
|
|
@@ -4109,21 +4227,22 @@ var Atbash = class _Atbash {
|
|
|
4109
4227
|
* entry (caller falls back to per-chain subscription resolution).
|
|
4110
4228
|
*/
|
|
4111
4229
|
async getActiveNetworkForOrg(orgName) {
|
|
4230
|
+
let resp;
|
|
4112
4231
|
try {
|
|
4113
|
-
|
|
4232
|
+
resp = await this.http.get(
|
|
4114
4233
|
"/api/org-network",
|
|
4115
|
-
{ org: orgName },
|
|
4234
|
+
{ org: orgName.trim() },
|
|
4116
4235
|
this.authHeaders()
|
|
4117
4236
|
);
|
|
4118
|
-
|
|
4119
|
-
|
|
4120
|
-
|
|
4121
|
-
|
|
4122
|
-
|
|
4123
|
-
|
|
4124
|
-
|
|
4125
|
-
return null;
|
|
4237
|
+
} catch (err) {
|
|
4238
|
+
throw this.transportError(err);
|
|
4239
|
+
}
|
|
4240
|
+
if (resp.status !== 200) throw await this.httpError(resp);
|
|
4241
|
+
const data = await this.json(resp);
|
|
4242
|
+
if (data?.network === "public" || data?.network === "private") {
|
|
4243
|
+
return data.network;
|
|
4126
4244
|
}
|
|
4245
|
+
return null;
|
|
4127
4246
|
}
|
|
4128
4247
|
/**
|
|
4129
4248
|
* Resolve which chain an org's actions should run against. Cached
|
|
@@ -4132,13 +4251,19 @@ var Atbash = class _Atbash {
|
|
|
4132
4251
|
* 2. Per-chain subscription fallback — public + private records
|
|
4133
4252
|
* are fetched in parallel, with `is_private_blockchain` and
|
|
4134
4253
|
* `assigned_at` reconciling mixed states.
|
|
4135
|
-
*
|
|
4254
|
+
* A lookup that names exactly one chain wins outright. Where it names
|
|
4255
|
+
* neither (a brand-new org) or cannot choose between them, the client's
|
|
4256
|
+
* configured default decides.
|
|
4136
4257
|
*/
|
|
4137
4258
|
async resolveChainForOrg(orgName) {
|
|
4138
|
-
const
|
|
4259
|
+
const name2 = orgName.trim();
|
|
4260
|
+
if (this._explicitChain) return this._defaultChain;
|
|
4261
|
+
const forced = this.forcedNetwork();
|
|
4262
|
+
if (forced) return chainForNetwork(forced);
|
|
4263
|
+
const cached = this._chainCache.get(name2);
|
|
4139
4264
|
if (cached) return cached;
|
|
4140
|
-
const mapNetwork = await this.getActiveNetworkForOrg(
|
|
4141
|
-
return this.resolveChainFromMap(
|
|
4265
|
+
const mapNetwork = await this.getActiveNetworkForOrg(name2);
|
|
4266
|
+
return this.resolveChainFromMap(name2, mapNetwork);
|
|
4142
4267
|
}
|
|
4143
4268
|
/**
|
|
4144
4269
|
* Resolve a chain given an already-fetched `org_networks` map result.
|
|
@@ -4154,32 +4279,41 @@ var Atbash = class _Atbash {
|
|
|
4154
4279
|
this._chainCache.set(orgName, chain);
|
|
4155
4280
|
return chain;
|
|
4156
4281
|
}
|
|
4157
|
-
|
|
4158
|
-
|
|
4159
|
-
|
|
4160
|
-
|
|
4161
|
-
|
|
4162
|
-
|
|
4163
|
-
|
|
4164
|
-
|
|
4165
|
-
|
|
4166
|
-
|
|
4167
|
-
|
|
4168
|
-
|
|
4169
|
-
|
|
4170
|
-
|
|
4171
|
-
|
|
4172
|
-
|
|
4173
|
-
|
|
4174
|
-
|
|
4175
|
-
|
|
4176
|
-
this._chainCache.set(orgName, PRIVATE_CHAIN);
|
|
4177
|
-
return PRIVATE_CHAIN;
|
|
4178
|
-
}
|
|
4179
|
-
} catch {
|
|
4282
|
+
const [pubRes, privRes] = await Promise.allSettled([
|
|
4283
|
+
this.getOrgSubscription(orgName, "public"),
|
|
4284
|
+
this.getOrgSubscription(orgName, "private")
|
|
4285
|
+
]);
|
|
4286
|
+
const pubSub = pubRes.status === "fulfilled" ? pubRes.value : null;
|
|
4287
|
+
const privSub = privRes.status === "fulfilled" ? privRes.value : null;
|
|
4288
|
+
const failure = pubRes.status === "rejected" ? pubRes.reason : privRes.status === "rejected" ? privRes.reason : null;
|
|
4289
|
+
if (pubSub?.is_private_blockchain) {
|
|
4290
|
+
this._chainCache.set(orgName, PRIVATE_CHAIN);
|
|
4291
|
+
return PRIVATE_CHAIN;
|
|
4292
|
+
}
|
|
4293
|
+
if (pubSub && privSub) {
|
|
4294
|
+
const chain = privSub.assigned_at === pubSub.assigned_at ? this._defaultChain : privSub.assigned_at > pubSub.assigned_at ? PRIVATE_CHAIN : PUBLIC_CHAIN;
|
|
4295
|
+
this._chainCache.set(orgName, chain);
|
|
4296
|
+
return chain;
|
|
4297
|
+
}
|
|
4298
|
+
if (pubSub) {
|
|
4299
|
+
this._chainCache.set(orgName, PUBLIC_CHAIN);
|
|
4300
|
+
return PUBLIC_CHAIN;
|
|
4180
4301
|
}
|
|
4181
|
-
|
|
4182
|
-
|
|
4302
|
+
if (privSub?.is_private_blockchain) {
|
|
4303
|
+
this._chainCache.set(orgName, PRIVATE_CHAIN);
|
|
4304
|
+
return PRIVATE_CHAIN;
|
|
4305
|
+
}
|
|
4306
|
+
if (failure) {
|
|
4307
|
+
const detail = failure instanceof Error ? failure.message : String(failure);
|
|
4308
|
+
throw new AtbashAPIError(
|
|
4309
|
+
failure instanceof AtbashAPIError ? failure.status : 0,
|
|
4310
|
+
`could not resolve the chain for org "${orgName}": ${detail}`,
|
|
4311
|
+
"",
|
|
4312
|
+
this.endpoint
|
|
4313
|
+
);
|
|
4314
|
+
}
|
|
4315
|
+
this._chainCache.set(orgName, this._defaultChain);
|
|
4316
|
+
return this._defaultChain;
|
|
4183
4317
|
}
|
|
4184
4318
|
/** Drop any cached chain resolutions. Useful in tests. */
|
|
4185
4319
|
clearChainCache() {
|
|
@@ -4230,6 +4364,7 @@ var Atbash = class _Atbash {
|
|
|
4230
4364
|
async resolveAgentLookupNetwork(options) {
|
|
4231
4365
|
if (options.chainOpts?.network) return options.chainOpts.network;
|
|
4232
4366
|
if (options.chainOpts?.blockchainRid) return void 0;
|
|
4367
|
+
if (this._explicitChain) return this._defaultChain.network;
|
|
4233
4368
|
const orgName = options.orgName ?? this.orgName;
|
|
4234
4369
|
if (!orgName) return void 0;
|
|
4235
4370
|
return (await this.resolveChainForOrg(orgName)).network;
|
|
@@ -4305,6 +4440,30 @@ var Atbash = class _Atbash {
|
|
|
4305
4440
|
return void 0;
|
|
4306
4441
|
}
|
|
4307
4442
|
}
|
|
4443
|
+
/**
|
|
4444
|
+
* BRID for the client's configured default org, if it has one.
|
|
4445
|
+
*
|
|
4446
|
+
* Calls that carry no `orgName` argument are not chain-less: they still
|
|
4447
|
+
* belong to `this.orgName`, and that org lives on exactly one chain. Routing
|
|
4448
|
+
* them by the constructor's chain instead means a client configured
|
|
4449
|
+
* `network: "private"` reads the private chain for an org that lives on
|
|
4450
|
+
* public, and gets an empty answer rather than an error. So where an org is
|
|
4451
|
+
* known the org decides the chain, and the constructor's chain is what is
|
|
4452
|
+
* left when no org is known at all — the order `resolveAgentLookupNetwork`
|
|
4453
|
+
* already applies to agent metadata reads, and the order the dashboard
|
|
4454
|
+
* applies in `resolveChainForWallet`.
|
|
4455
|
+
*
|
|
4456
|
+
* Undefined when there is no default org, so callers keep falling back to
|
|
4457
|
+
* the client default.
|
|
4458
|
+
*/
|
|
4459
|
+
/** The switch's chain, unless this client named one of its own. */
|
|
4460
|
+
forcedNetwork() {
|
|
4461
|
+
return this._explicitChain ? void 0 : this._forcedNetwork;
|
|
4462
|
+
}
|
|
4463
|
+
async defaultOrgBrid() {
|
|
4464
|
+
if (this._explicitChain || !this.orgName) return void 0;
|
|
4465
|
+
return this.bridForOrg(this.orgName);
|
|
4466
|
+
}
|
|
4308
4467
|
async raiseIfError(resp) {
|
|
4309
4468
|
if (resp.ok) return;
|
|
4310
4469
|
throw await this.httpError(resp);
|
|
@@ -42745,6 +42904,7 @@ async function resolveChainOptsForOrg(opts, auth) {
|
|
|
42745
42904
|
if (opts?.orgName && !opts.chainOpts?.blockchainRid && auth) {
|
|
42746
42905
|
const atbash = new Atbash(auth.privkey, {
|
|
42747
42906
|
endpoint: opts.endpoint,
|
|
42907
|
+
verifyPubKey: opts.verifyPubKey,
|
|
42748
42908
|
orgName: opts.orgName
|
|
42749
42909
|
});
|
|
42750
42910
|
const resolved = await atbash.resolveChainForOrg(opts.orgName);
|
|
@@ -42784,13 +42944,15 @@ function buildSigner(auth) {
|
|
|
42784
42944
|
}
|
|
42785
42945
|
async function commitMemoryVersion(plaintext, auth, opts) {
|
|
42786
42946
|
const score = opts?.score ?? 5;
|
|
42947
|
+
const filePath = opts?.filePath ?? "";
|
|
42787
42948
|
const key3 = await deriveMemoryKey(auth.privkey);
|
|
42788
42949
|
const { ciphertext, nonce } = await encryptMemoryContent(plaintext, key3);
|
|
42789
42950
|
const args = native.buildAddAgentMemoryArgs(
|
|
42790
42951
|
auth.pubkey,
|
|
42791
42952
|
ciphertext,
|
|
42792
42953
|
nonce,
|
|
42793
|
-
score
|
|
42954
|
+
score,
|
|
42955
|
+
filePath
|
|
42794
42956
|
);
|
|
42795
42957
|
const chainOpts = await resolveChainOptsForOrg(opts, auth);
|
|
42796
42958
|
const client = await buildChainClient(chainOpts);
|
|
@@ -42802,7 +42964,8 @@ async function commitMemoryVersion(plaintext, auth, opts) {
|
|
|
42802
42964
|
toGtxBytes(args.agent_pubkey),
|
|
42803
42965
|
toGtxBytes(args.content_cipher),
|
|
42804
42966
|
toGtxBytes(args.nonce),
|
|
42805
|
-
args.score
|
|
42967
|
+
args.score,
|
|
42968
|
+
args.file_path
|
|
42806
42969
|
]
|
|
42807
42970
|
},
|
|
42808
42971
|
sigProvider
|
|
@@ -42824,6 +42987,7 @@ async function decryptRow(row, key3) {
|
|
|
42824
42987
|
}
|
|
42825
42988
|
return {
|
|
42826
42989
|
id: parsed.id,
|
|
42990
|
+
filePath: parsed.file_path,
|
|
42827
42991
|
content,
|
|
42828
42992
|
decryptError,
|
|
42829
42993
|
score: parsed.score,
|
|
@@ -42832,39 +42996,52 @@ async function decryptRow(row, key3) {
|
|
|
42832
42996
|
updatedAt: parsed.updated_at
|
|
42833
42997
|
};
|
|
42834
42998
|
}
|
|
42835
|
-
|
|
42999
|
+
function paramsWithOptionalFilePath(agentPubkeyHex, filePath) {
|
|
43000
|
+
const params = {
|
|
43001
|
+
[native.ARG_AGENT_PUBKEY]: agentPubkeyHex
|
|
43002
|
+
};
|
|
43003
|
+
if (filePath !== null) {
|
|
43004
|
+
params[native.ARG_FILE_PATH] = filePath;
|
|
43005
|
+
}
|
|
43006
|
+
return params;
|
|
43007
|
+
}
|
|
43008
|
+
async function getActiveMemoryId(auth, chainOpts, filePath) {
|
|
42836
43009
|
const client = await buildChainClient(chainOpts);
|
|
42837
|
-
const q = native.buildGetActiveMemoryIdQuery(auth.pubkey);
|
|
42838
|
-
const raw2 = await client.query(
|
|
42839
|
-
|
|
42840
|
-
|
|
43010
|
+
const q = native.buildGetActiveMemoryIdQuery(auth.pubkey, filePath ?? null);
|
|
43011
|
+
const raw2 = await client.query(
|
|
43012
|
+
native.QUERY_GET_ACTIVE_MEMORY_ID,
|
|
43013
|
+
paramsWithOptionalFilePath(q.agent_pubkey_hex, q.file_path)
|
|
43014
|
+
);
|
|
42841
43015
|
return native.parseActiveMemoryId(raw2);
|
|
42842
43016
|
}
|
|
42843
|
-
async function
|
|
43017
|
+
async function getRecentAgentMemory(auth, chainOpts, filePath) {
|
|
42844
43018
|
const client = await buildChainClient(chainOpts);
|
|
42845
43019
|
const key3 = await deriveMemoryKey(auth.privkey);
|
|
42846
|
-
const q = native.
|
|
42847
|
-
const rows = await client.query(
|
|
42848
|
-
|
|
42849
|
-
|
|
43020
|
+
const q = native.buildGetRecentAgentMemoryQuery(auth.pubkey, filePath ?? null);
|
|
43021
|
+
const rows = await client.query(
|
|
43022
|
+
native.QUERY_GET_RECENT_AGENT_MEMORY,
|
|
43023
|
+
paramsWithOptionalFilePath(q.agent_pubkey_hex, q.file_path)
|
|
43024
|
+
);
|
|
42850
43025
|
return Promise.all((rows ?? []).map((r2) => decryptRow(r2, key3)));
|
|
42851
43026
|
}
|
|
42852
|
-
async function
|
|
43027
|
+
async function getActiveAgentMemory(auth, chainOpts, filePath) {
|
|
42853
43028
|
const client = await buildChainClient(chainOpts);
|
|
42854
43029
|
const key3 = await deriveMemoryKey(auth.privkey);
|
|
42855
|
-
const q = native.
|
|
42856
|
-
const rows = await client.query(
|
|
42857
|
-
|
|
42858
|
-
|
|
43030
|
+
const q = native.buildGetActiveAgentMemoryQuery(auth.pubkey, filePath ?? null);
|
|
43031
|
+
const rows = await client.query(
|
|
43032
|
+
native.QUERY_GET_ACTIVE_AGENT_MEMORY,
|
|
43033
|
+
paramsWithOptionalFilePath(q.agent_pubkey_hex, q.file_path)
|
|
43034
|
+
);
|
|
42859
43035
|
return Promise.all((rows ?? []).map((r2) => decryptRow(r2, key3)));
|
|
42860
43036
|
}
|
|
42861
|
-
async function getMemoryHistory(auth, chainOpts) {
|
|
43037
|
+
async function getMemoryHistory(auth, chainOpts, filePath) {
|
|
42862
43038
|
const client = await buildChainClient(chainOpts);
|
|
42863
43039
|
const key3 = await deriveMemoryKey(auth.privkey);
|
|
42864
|
-
const q = native.buildGetAgentMemoryHistoryQuery(auth.pubkey);
|
|
42865
|
-
const rows = await client.query(
|
|
42866
|
-
|
|
42867
|
-
|
|
43040
|
+
const q = native.buildGetAgentMemoryHistoryQuery(auth.pubkey, filePath ?? null);
|
|
43041
|
+
const rows = await client.query(
|
|
43042
|
+
native.QUERY_GET_AGENT_MEMORY_HISTORY,
|
|
43043
|
+
paramsWithOptionalFilePath(q.agent_pubkey_hex, q.file_path)
|
|
43044
|
+
);
|
|
42868
43045
|
return Promise.all((rows ?? []).map((r2) => decryptRow(r2, key3)));
|
|
42869
43046
|
}
|
|
42870
43047
|
async function getMemoryById(id, auth, chainOpts) {
|
|
@@ -42877,17 +43054,21 @@ async function getMemoryById(id, auth, chainOpts) {
|
|
|
42877
43054
|
});
|
|
42878
43055
|
return decryptRow(row, key3);
|
|
42879
43056
|
}
|
|
42880
|
-
async function getRollbackHistory(auth, chainOpts) {
|
|
43057
|
+
async function getRollbackHistory(auth, chainOpts, filePath) {
|
|
42881
43058
|
const client = await buildChainClient(chainOpts);
|
|
42882
|
-
const q = native.buildGetAgentMemoryRollbackHistoryQuery(
|
|
43059
|
+
const q = native.buildGetAgentMemoryRollbackHistoryQuery(
|
|
43060
|
+
auth.pubkey,
|
|
43061
|
+
filePath ?? null
|
|
43062
|
+
);
|
|
42883
43063
|
const raw2 = await client.query(
|
|
42884
43064
|
native.QUERY_GET_AGENT_MEMORY_ROLLBACK_HISTORY,
|
|
42885
|
-
|
|
43065
|
+
paramsWithOptionalFilePath(q.agent_pubkey_hex, q.file_path)
|
|
42886
43066
|
);
|
|
42887
43067
|
const parsed = native.parseRollbackRows(raw2 ?? []);
|
|
42888
43068
|
return parsed.map((r2) => ({
|
|
42889
43069
|
fromId: r2.from_id,
|
|
42890
43070
|
toId: r2.to_id,
|
|
43071
|
+
filePath: r2.file_path,
|
|
42891
43072
|
reason: r2.reason,
|
|
42892
43073
|
signer: Buffer.from(r2.signer).toString("hex"),
|
|
42893
43074
|
createdAt: r2.created_at
|
|
@@ -42955,8 +43136,7 @@ async function guardMemoryWrite(input) {
|
|
|
42955
43136
|
toolNames,
|
|
42956
43137
|
enforce = true,
|
|
42957
43138
|
debug: debug2 = false,
|
|
42958
|
-
logger: logger2
|
|
42959
|
-
memoryFilePath
|
|
43139
|
+
logger: logger2
|
|
42960
43140
|
} = input;
|
|
42961
43141
|
const memEntry = classifyMemoryWrite(event, ctx, { patterns, toolNames });
|
|
42962
43142
|
if (debug2) emitDebugProbe(event, ctx, memEntry, logger2);
|
|
@@ -42992,37 +43172,35 @@ async function guardMemoryWrite(input) {
|
|
|
42992
43172
|
committed: false
|
|
42993
43173
|
};
|
|
42994
43174
|
}
|
|
42995
|
-
const
|
|
42996
|
-
|
|
42997
|
-
|
|
42998
|
-
|
|
42999
|
-
|
|
43000
|
-
|
|
43001
|
-
|
|
43002
|
-
|
|
43003
|
-
|
|
43004
|
-
|
|
43005
|
-
|
|
43006
|
-
|
|
43175
|
+
const filePath = import_node_path4.default.basename(memEntry.key);
|
|
43176
|
+
commitMemoryVersion(memEntry.value, auth, {
|
|
43177
|
+
score: scanResult.score,
|
|
43178
|
+
filePath,
|
|
43179
|
+
orgName,
|
|
43180
|
+
endpoint,
|
|
43181
|
+
verifyPubKey
|
|
43182
|
+
}).catch((err) => {
|
|
43183
|
+
const reason = err instanceof Error ? err.message : String(err);
|
|
43184
|
+
logger2?.warn?.("[atbash] memory commit to chain failed", {
|
|
43185
|
+
path: memEntry.key,
|
|
43186
|
+
filePath,
|
|
43187
|
+
reason
|
|
43007
43188
|
});
|
|
43008
|
-
}
|
|
43009
|
-
logger2?.info?.(
|
|
43010
|
-
"[atbash] scanned but not committed \u2014 not the managed memory file",
|
|
43011
|
-
{
|
|
43012
|
-
path: memEntry.key,
|
|
43013
|
-
memoryFilePath: memoryFilePath ?? "(not configured)"
|
|
43014
|
-
}
|
|
43015
|
-
);
|
|
43016
|
-
}
|
|
43189
|
+
});
|
|
43017
43190
|
logger2?.info?.(
|
|
43018
43191
|
scanResult.verdict === "yellow" ? "[atbash] memory HOLD" : "[atbash] memory ALLOW",
|
|
43019
|
-
{
|
|
43192
|
+
{
|
|
43193
|
+
path: memEntry.key,
|
|
43194
|
+
filePath,
|
|
43195
|
+
score: scanResult.score,
|
|
43196
|
+
reason: scanResult.reason
|
|
43197
|
+
}
|
|
43020
43198
|
);
|
|
43021
43199
|
return {
|
|
43022
43200
|
handled: true,
|
|
43023
43201
|
decision: { allow: true },
|
|
43024
43202
|
scanResult,
|
|
43025
|
-
committed:
|
|
43203
|
+
committed: true
|
|
43026
43204
|
};
|
|
43027
43205
|
}
|
|
43028
43206
|
|
|
@@ -43262,9 +43440,7 @@ var MemoryGuardManager = class {
|
|
|
43262
43440
|
toolNames: this.opts.memoryWriteToolNames,
|
|
43263
43441
|
enforce: this.enforce,
|
|
43264
43442
|
debug: this.opts.debug,
|
|
43265
|
-
logger: guardLogger
|
|
43266
|
-
// Only this file may reach the single, path-less chain memory slot.
|
|
43267
|
-
memoryFilePath: this.memoryFilePath
|
|
43443
|
+
logger: guardLogger
|
|
43268
43444
|
});
|
|
43269
43445
|
return this.mapGuardResult(guard);
|
|
43270
43446
|
}
|
|
@@ -43538,10 +43714,13 @@ function diffMemorySnapshots(before, after) {
|
|
|
43538
43714
|
KEY_FILENAMES,
|
|
43539
43715
|
MemoryGuardManager,
|
|
43540
43716
|
MemoryIntegrityError,
|
|
43717
|
+
PRIVATE_CHAIN,
|
|
43718
|
+
PUBLIC_CHAIN,
|
|
43541
43719
|
PointerStore,
|
|
43542
43720
|
SignatureVerificationError,
|
|
43543
43721
|
bootSyncFailureLine,
|
|
43544
43722
|
buildAllowedJudgeHosts,
|
|
43723
|
+
chainForNetwork,
|
|
43545
43724
|
chooseKeyPath,
|
|
43546
43725
|
claimHashHex,
|
|
43547
43726
|
classifyMemoryRead,
|
|
@@ -43565,13 +43744,13 @@ function diffMemorySnapshots(before, after) {
|
|
|
43565
43744
|
encryptedLength,
|
|
43566
43745
|
flushTelemetry,
|
|
43567
43746
|
generateKeypair,
|
|
43568
|
-
|
|
43747
|
+
getActiveAgentMemory,
|
|
43569
43748
|
getActiveMemoryId,
|
|
43570
|
-
getAllAgentMemory,
|
|
43571
43749
|
getConfigDir,
|
|
43572
43750
|
getConfigPath,
|
|
43573
43751
|
getMemoryById,
|
|
43574
43752
|
getMemoryHistory,
|
|
43753
|
+
getRecentAgentMemory,
|
|
43575
43754
|
getRollbackHistory,
|
|
43576
43755
|
guardMemoryWrite,
|
|
43577
43756
|
isEnvelope,
|