@atbash/sdk 0.10.9-dev.0 → 0.10.10-dev.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser.d.mts +83 -17
- package/dist/browser.mjs +120 -67
- package/dist/browser.mjs.map +1 -1
- package/dist/index.d.mts +83 -17
- package/dist/index.d.ts +83 -17
- package/dist/index.js +234 -105
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +234 -105
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -5
package/dist/browser.d.mts
CHANGED
|
@@ -430,6 +430,16 @@ declare class Atbash {
|
|
|
430
430
|
* calls don't re-hit the dashboard. Cleared by `clearChainCache()`.
|
|
431
431
|
*/
|
|
432
432
|
private readonly _chainCache;
|
|
433
|
+
/**
|
|
434
|
+
* Short-TTL cache for `/api/ai/exists`. The `registered` field is
|
|
435
|
+
* monotonic (once true, stays true), so most calls in a burst re-fetch
|
|
436
|
+
* data that hasn't changed. The `org_encryption_pubkey` field CAN change
|
|
437
|
+
* — an org toggling encryption mid-session — so the TTL is deliberately
|
|
438
|
+
* short (see `AGENT_EXISTS_TTL_MS`). Keyed by (pubkey, network) so
|
|
439
|
+
* cross-agent / cross-network calls don't collide.
|
|
440
|
+
*/
|
|
441
|
+
private _agentExistsCache;
|
|
442
|
+
private static readonly AGENT_EXISTS_TTL_MS;
|
|
433
443
|
/**
|
|
434
444
|
* Cached bearer token for risk-engine / insurance read calls. Built
|
|
435
445
|
* lazily as a signed `log_tool_call` tx and refreshed every 4 min so
|
|
@@ -547,6 +557,8 @@ declare class Atbash {
|
|
|
547
557
|
private resolveChainFromMap;
|
|
548
558
|
/** Drop any cached chain resolutions. Useful in tests. */
|
|
549
559
|
clearChainCache(): void;
|
|
560
|
+
/** Drop the short-TTL `/api/ai/exists` cache. Useful in tests. */
|
|
561
|
+
clearAgentExistsCache(): void;
|
|
550
562
|
/**
|
|
551
563
|
* Wrap an SDK method body in telemetry — records the call at start
|
|
552
564
|
* and a success/error duration at end. Re-throws on failure so the
|
|
@@ -893,19 +905,6 @@ interface ClassifyMemoryWriteOptions {
|
|
|
893
905
|
*/
|
|
894
906
|
declare function classifyMemoryWrite(event: unknown, ctx: unknown, opts?: ClassifyMemoryWriteOptions): MemoryEntry | null;
|
|
895
907
|
|
|
896
|
-
/**
|
|
897
|
-
* Plugin-agnostic memory-write guard.
|
|
898
|
-
*
|
|
899
|
-
* A single call that replaces the plugin's usual memory-write branch:
|
|
900
|
-
* classify → scan (Layer 1 regex + Layer 2 LLM) → gate on verdict →
|
|
901
|
-
* persist to chain (fire-and-forget when allowed) → return decision.
|
|
902
|
-
*
|
|
903
|
-
* Plugins call this from their `before_tool_call` hook. When it returns
|
|
904
|
-
* `{ handled: false }` the call wasn't a memory write and the plugin
|
|
905
|
-
* should fall through to its regular tool-call audit. When
|
|
906
|
-
* `{ handled: true }` the plugin returns `decision` directly.
|
|
907
|
-
*/
|
|
908
|
-
|
|
909
908
|
/**
|
|
910
909
|
* Minimal logger accepted by `guardMemoryWrite`. Plugins pass their
|
|
911
910
|
* host runtime's logger (openclaw's `api.logger`, MCP's console, etc.).
|
|
@@ -936,6 +935,8 @@ interface GuardMemoryWriteInput extends ClassifyMemoryWriteOptions {
|
|
|
936
935
|
debug?: boolean;
|
|
937
936
|
/** Optional logger for debug probe + persist-failure warnings. */
|
|
938
937
|
logger?: GuardLogger;
|
|
938
|
+
/** Absolute path of the agent's managed memory file. Required for chain commits — omitted skips them. */
|
|
939
|
+
memoryFilePath?: string;
|
|
939
940
|
}
|
|
940
941
|
/** Plugin-facing decision. Shape mirrors what plugins return from `before_tool_call`. */
|
|
941
942
|
interface GuardMemoryDecision {
|
|
@@ -1000,12 +1001,19 @@ interface SyncMemoryOptions {
|
|
|
1000
1001
|
* `drifted: false` — pointer is still valid; caller can keep serving the local copy.
|
|
1001
1002
|
* `drifted: true` — active id changed on chain; `current` is the fresh decrypted row
|
|
1002
1003
|
* (or `null` if active memory was removed entirely).
|
|
1004
|
+
*
|
|
1005
|
+
* `checked` — whether this call actually queried chain. `false` means the TTL
|
|
1006
|
+
* window was still open and the pointer was trusted without contacting chain, so
|
|
1007
|
+
* `drifted: false` carries no evidence about the current state. Callers that
|
|
1008
|
+
* vouch for content to a third party must not treat an unchecked result as proof.
|
|
1003
1009
|
*/
|
|
1004
1010
|
type SyncMemoryResult = {
|
|
1005
1011
|
drifted: false;
|
|
1012
|
+
checked: boolean;
|
|
1006
1013
|
pointer: MemoryPointer;
|
|
1007
1014
|
} | {
|
|
1008
1015
|
drifted: true;
|
|
1016
|
+
checked: true;
|
|
1009
1017
|
current: AgentMemoryEntry | null;
|
|
1010
1018
|
pointer: MemoryPointer;
|
|
1011
1019
|
};
|
|
@@ -1067,12 +1075,42 @@ interface ClassifyMemoryReadOptions {
|
|
|
1067
1075
|
*/
|
|
1068
1076
|
declare function classifyMemoryRead(event: unknown, ctx: unknown, opts?: ClassifyMemoryReadOptions): boolean;
|
|
1069
1077
|
|
|
1070
|
-
/**
|
|
1078
|
+
/**
|
|
1079
|
+
* Decision the manager returns to the plugin's `before_tool_call` handler.
|
|
1080
|
+
*
|
|
1081
|
+
* `allow: true` alone is NOT evidence that anything was checked. Read `audited`
|
|
1082
|
+
* to tell the two apart, and route un-audited calls to your own judge — see the
|
|
1083
|
+
* field docs below.
|
|
1084
|
+
*/
|
|
1071
1085
|
interface HookDecision {
|
|
1072
1086
|
allow?: boolean;
|
|
1073
1087
|
block?: boolean;
|
|
1074
1088
|
blockReason?: string;
|
|
1075
1089
|
reason?: string;
|
|
1090
|
+
/**
|
|
1091
|
+
* Whether the guard reached an enforcement decision about *this* call.
|
|
1092
|
+
*
|
|
1093
|
+
* Note this describes whether the guard **decided**, not whether it allowed.
|
|
1094
|
+
* Every `block` is `audited: true` — a blocked call is the most thoroughly
|
|
1095
|
+
* checked outcome the guard produces (a red scan, a ciphertext integrity
|
|
1096
|
+
* failure, a rolled-back version), and a host must never re-judge its way past
|
|
1097
|
+
* one.
|
|
1098
|
+
*
|
|
1099
|
+
* Absent or false means the guard reached no decision — it was inside its cache
|
|
1100
|
+
* window, chain was unreachable, the scan never ran, the file it can vouch for
|
|
1101
|
+
* is not the file being read, or it is in observe mode. Those calls are
|
|
1102
|
+
* unaudited: fall through to your own judge exactly as for a `null` return.
|
|
1103
|
+
*
|
|
1104
|
+
* So the host rule is:
|
|
1105
|
+
* `if (d.block) deny; else if (d.audited) allow; else judge it yourself;`
|
|
1106
|
+
*
|
|
1107
|
+
* Treating a bare `allow: true` as a completed audit is what this field exists
|
|
1108
|
+
* to prevent. A host that ignores it and returns the decision verbatim will
|
|
1109
|
+
* execute unaudited tool calls.
|
|
1110
|
+
*/
|
|
1111
|
+
audited?: boolean;
|
|
1112
|
+
/** Scan verdict when one was produced (`green` | `yellow` | `red`). Absent when no scan ran. */
|
|
1113
|
+
verdict?: string;
|
|
1076
1114
|
}
|
|
1077
1115
|
interface MemoryGuardManagerOptions {
|
|
1078
1116
|
auth: AgentAuth;
|
|
@@ -1095,6 +1133,13 @@ interface MemoryGuardManagerOptions {
|
|
|
1095
1133
|
rollbackMinScore?: number;
|
|
1096
1134
|
/** True → return `{block:true}` on defense triggers. False → log and return `null` (audit-only). Default true. */
|
|
1097
1135
|
enforce?: boolean;
|
|
1136
|
+
/**
|
|
1137
|
+
* Chain targeting for the pointer sync (network, blockchainRid, nodeUrls).
|
|
1138
|
+
* Defaults to the SDK's configured chain. Without this the manager could only
|
|
1139
|
+
* ever talk to the default chain, which left the whole memory-read path
|
|
1140
|
+
* untestable — `syncLocalMemory` already accepted these options.
|
|
1141
|
+
*/
|
|
1142
|
+
chainOpts?: ChainOpts;
|
|
1098
1143
|
/** Host-specific tuning of what counts as a memory read. */
|
|
1099
1144
|
memoryReadClassifier?: ClassifyMemoryReadOptions;
|
|
1100
1145
|
/** Passed through to `guardMemoryWrite`. Host memory-write tool names override. */
|
|
@@ -1131,12 +1176,33 @@ declare class MemoryGuardManager {
|
|
|
1131
1176
|
*/
|
|
1132
1177
|
runBootProbe(): Promise<void>;
|
|
1133
1178
|
/**
|
|
1134
|
-
* Returns a `HookDecision` when the
|
|
1135
|
-
*
|
|
1136
|
-
*
|
|
1179
|
+
* Returns a `HookDecision` when the guard reached a decision about this event.
|
|
1180
|
+
* Returns `null` when it did not — either the event isn't memory-related, or it
|
|
1181
|
+
* is but the guard could not check it. In both cases the host falls through to
|
|
1182
|
+
* its own audit.
|
|
1183
|
+
*
|
|
1184
|
+
* A returned decision carries `audited` (see `HookDecision`). Only
|
|
1185
|
+
* `{ allow: true, audited: true }` means "checked and cleared"; anything else
|
|
1186
|
+
* that allows is a call the host still needs to judge.
|
|
1137
1187
|
*/
|
|
1138
1188
|
handleBeforeToolCall(event: unknown, ctx: unknown): Promise<HookDecision | null>;
|
|
1139
1189
|
private mapGuardResult;
|
|
1190
|
+
/**
|
|
1191
|
+
* Whether the pointer state this manager tracks actually describes the file
|
|
1192
|
+
* this call is about to read.
|
|
1193
|
+
*
|
|
1194
|
+
* The classifier fires on nine patterns — including the bare tokens
|
|
1195
|
+
* `"memory/"`, `"CLAUDE.md"` and `"AGENTS.md"` — but the sync path only ever
|
|
1196
|
+
* reads, refreshes, or vouches for `this.memoryFilePath`. Without this check a
|
|
1197
|
+
* read of `/repo/CLAUDE.md` (or any path merely containing `memory/`) would
|
|
1198
|
+
* receive an `audited: true` for a file the guard never opened.
|
|
1199
|
+
*
|
|
1200
|
+
* Conservative on purpose: every path-shaped value found must resolve to the
|
|
1201
|
+
* managed file. If none is found, or any one differs, the answer is no. That
|
|
1202
|
+
* also covers events carrying two different path keys, where the classifier
|
|
1203
|
+
* and the host could otherwise disagree about which one is authoritative.
|
|
1204
|
+
*/
|
|
1205
|
+
private vouchesForTarget;
|
|
1140
1206
|
private handleMemoryRead;
|
|
1141
1207
|
private writeMemoryAtomic;
|
|
1142
1208
|
}
|
package/dist/browser.mjs
CHANGED
|
@@ -10054,8 +10054,8 @@ Reporter$3.prototype.wrapResult = function wrapResult(result) {
|
|
|
10054
10054
|
errors: state2.errors
|
|
10055
10055
|
};
|
|
10056
10056
|
};
|
|
10057
|
-
function ReporterError$1(
|
|
10058
|
-
this.path =
|
|
10057
|
+
function ReporterError$1(path4, msg) {
|
|
10058
|
+
this.path = path4;
|
|
10059
10059
|
this.rethrow(msg);
|
|
10060
10060
|
}
|
|
10061
10061
|
inherits$v(ReporterError$1, Error);
|
|
@@ -30276,8 +30276,8 @@ Reporter.prototype.wrapResult = function wrapResult2(result) {
|
|
|
30276
30276
|
errors: state2.errors
|
|
30277
30277
|
};
|
|
30278
30278
|
};
|
|
30279
|
-
function ReporterError(
|
|
30280
|
-
this.path =
|
|
30279
|
+
function ReporterError(path4, msg) {
|
|
30280
|
+
this.path = path4;
|
|
30281
30281
|
this.rethrow(msg);
|
|
30282
30282
|
}
|
|
30283
30283
|
inherits(ReporterError, Error);
|
|
@@ -33307,8 +33307,8 @@ var parseUtil = {};
|
|
|
33307
33307
|
const errors_js_12 = errors$3;
|
|
33308
33308
|
const en_js_12 = __importDefault2(en);
|
|
33309
33309
|
const makeIssue = (params) => {
|
|
33310
|
-
const { data, path:
|
|
33311
|
-
const fullPath = [...
|
|
33310
|
+
const { data, path: path4, errorMaps, issueData } = params;
|
|
33311
|
+
const fullPath = [...path4, ...issueData.path || []];
|
|
33312
33312
|
const fullIssue = {
|
|
33313
33313
|
...issueData,
|
|
33314
33314
|
path: fullPath
|
|
@@ -33445,11 +33445,11 @@ var errorUtil_js_1 = errorUtil$1;
|
|
|
33445
33445
|
var parseUtil_js_1 = parseUtil;
|
|
33446
33446
|
var util_js_1 = util;
|
|
33447
33447
|
var ParseInputLazyPath = class {
|
|
33448
|
-
constructor(parent, value,
|
|
33448
|
+
constructor(parent, value, path4, key3) {
|
|
33449
33449
|
this._cachedPath = [];
|
|
33450
33450
|
this.parent = parent;
|
|
33451
33451
|
this.data = value;
|
|
33452
|
-
this._path =
|
|
33452
|
+
this._path = path4;
|
|
33453
33453
|
this._key = key3;
|
|
33454
33454
|
}
|
|
33455
33455
|
get path() {
|
|
@@ -40355,21 +40355,21 @@ function createTimeoutController(timeout) {
|
|
|
40355
40355
|
const timeoutId = setTimeout(() => controller.abort(timeoutError), timeout);
|
|
40356
40356
|
return { controller, timeoutId };
|
|
40357
40357
|
}
|
|
40358
|
-
function handleRequest(method,
|
|
40358
|
+
function handleRequest(method, path4, endpoint, timeout, postObject) {
|
|
40359
40359
|
return __awaiter$2(this, void 0, void 0, function* () {
|
|
40360
40360
|
if (method == enums_1$2.Method.GET) {
|
|
40361
|
-
return yield get(
|
|
40361
|
+
return yield get(path4, endpoint, timeout);
|
|
40362
40362
|
} else {
|
|
40363
|
-
return yield post(
|
|
40363
|
+
return yield post(path4, endpoint, timeout, postObject);
|
|
40364
40364
|
}
|
|
40365
40365
|
});
|
|
40366
40366
|
}
|
|
40367
|
-
function get(
|
|
40367
|
+
function get(path4, endpoint, timeout) {
|
|
40368
40368
|
return __awaiter$2(this, void 0, void 0, function* () {
|
|
40369
|
-
logger.debug(`GET URL ${new URL(
|
|
40369
|
+
logger.debug(`GET URL ${new URL(path4, endpoint).href}`);
|
|
40370
40370
|
try {
|
|
40371
40371
|
const { controller, timeoutId } = createTimeoutController(timeout);
|
|
40372
|
-
const response = yield fetch(new URL(
|
|
40372
|
+
const response = yield fetch(new URL(path4, endpoint).href, {
|
|
40373
40373
|
signal: controller === null || controller === void 0 ? void 0 : controller.signal
|
|
40374
40374
|
});
|
|
40375
40375
|
if (timeoutId)
|
|
@@ -40407,9 +40407,9 @@ function constructBufferResponseBody(response) {
|
|
|
40407
40407
|
return responseText ? responseText : response.statusText;
|
|
40408
40408
|
});
|
|
40409
40409
|
}
|
|
40410
|
-
function post(
|
|
40410
|
+
function post(path4, endpoint, timeout, requestBody) {
|
|
40411
40411
|
return __awaiter$2(this, void 0, void 0, function* () {
|
|
40412
|
-
logger.debug(`POST URL ${new URL(
|
|
40412
|
+
logger.debug(`POST URL ${new URL(path4, endpoint).href}`);
|
|
40413
40413
|
logger.debug(`POST body ${JSON.stringify(requestBody)}`);
|
|
40414
40414
|
if (buffer_1.Buffer.isBuffer(requestBody)) {
|
|
40415
40415
|
try {
|
|
@@ -40423,7 +40423,7 @@ function post(path3, endpoint, timeout, requestBody) {
|
|
|
40423
40423
|
},
|
|
40424
40424
|
signal: controller === null || controller === void 0 ? void 0 : controller.signal
|
|
40425
40425
|
};
|
|
40426
|
-
const response = yield fetch(new URL(
|
|
40426
|
+
const response = yield fetch(new URL(path4, endpoint).href, requestOptions);
|
|
40427
40427
|
if (timeoutId)
|
|
40428
40428
|
clearTimeout(timeoutId);
|
|
40429
40429
|
const transactionTimestamp = response.headers.get("X-Transaction-Timestamp");
|
|
@@ -40434,7 +40434,7 @@ function post(path3, endpoint, timeout, requestBody) {
|
|
|
40434
40434
|
} else {
|
|
40435
40435
|
try {
|
|
40436
40436
|
const { controller, timeoutId } = createTimeoutController(timeout);
|
|
40437
|
-
const response = yield fetch(new URL(
|
|
40437
|
+
const response = yield fetch(new URL(path4, endpoint).href, {
|
|
40438
40438
|
method: "post",
|
|
40439
40439
|
body: JSON.stringify(requestBody),
|
|
40440
40440
|
headers: {
|
|
@@ -40614,10 +40614,10 @@ function requireFailoverStrategies() {
|
|
|
40614
40614
|
}
|
|
40615
40615
|
}
|
|
40616
40616
|
function abortOnError(_a2) {
|
|
40617
|
-
return __awaiter2(this, arguments, void 0, function* ({ method, path:
|
|
40617
|
+
return __awaiter2(this, arguments, void 0, function* ({ method, path: path4, config: config2, postObject, timeoutOverride }) {
|
|
40618
40618
|
return yield retryRequest({
|
|
40619
40619
|
method,
|
|
40620
|
-
path:
|
|
40620
|
+
path: path4,
|
|
40621
40621
|
config: config2,
|
|
40622
40622
|
postObject,
|
|
40623
40623
|
timeoutOverride,
|
|
@@ -40628,10 +40628,10 @@ function requireFailoverStrategies() {
|
|
|
40628
40628
|
});
|
|
40629
40629
|
}
|
|
40630
40630
|
function tryNextOnError(_a2) {
|
|
40631
|
-
return __awaiter2(this, arguments, void 0, function* ({ method, path:
|
|
40631
|
+
return __awaiter2(this, arguments, void 0, function* ({ method, path: path4, config: config2, postObject, timeoutOverride }) {
|
|
40632
40632
|
return yield retryRequest({
|
|
40633
40633
|
method,
|
|
40634
|
-
path:
|
|
40634
|
+
path: path4,
|
|
40635
40635
|
config: config2,
|
|
40636
40636
|
postObject,
|
|
40637
40637
|
timeoutOverride,
|
|
@@ -40647,7 +40647,7 @@ function requireFailoverStrategies() {
|
|
|
40647
40647
|
return endpointPoolLength - (endpointPoolLength - 1) / 3;
|
|
40648
40648
|
}
|
|
40649
40649
|
function queryMajority(_a2) {
|
|
40650
|
-
return __awaiter2(this, arguments, void 0, function* ({ method, path:
|
|
40650
|
+
return __awaiter2(this, arguments, void 0, function* ({ method, path: path4, config: config2, postObject, timeoutOverride }) {
|
|
40651
40651
|
var _b;
|
|
40652
40652
|
const bftMajorityThreshold = calculateBftMajorityThreshold(config2.endpointPool.length);
|
|
40653
40653
|
const failureThreshold = config2.endpointPool.length - bftMajorityThreshold + 1;
|
|
@@ -40658,7 +40658,7 @@ function requireFailoverStrategies() {
|
|
|
40658
40658
|
const promises = availableNodes.map((node2) => __awaiter2(this, void 0, void 0, function* () {
|
|
40659
40659
|
try {
|
|
40660
40660
|
const requestTimeout = timeoutOverride !== null && timeoutOverride !== void 0 ? timeoutOverride : config2.responseTimeout;
|
|
40661
|
-
const response = yield (0, httpUtil_1.handleRequest)(method,
|
|
40661
|
+
const response = yield (0, httpUtil_1.handleRequest)(method, path4, node2.url, requestTimeout, postObject);
|
|
40662
40662
|
const { statusCode } = response;
|
|
40663
40663
|
if (statusCode && (0, http_utils_1.isSuccessfulStatusCode)(statusCode)) {
|
|
40664
40664
|
outcomes.push({ type: "SUCCESS", result: response });
|
|
@@ -40705,7 +40705,7 @@ function requireFailoverStrategies() {
|
|
|
40705
40705
|
});
|
|
40706
40706
|
}
|
|
40707
40707
|
function singleEndpoint(_a2) {
|
|
40708
|
-
return __awaiter2(this, arguments, void 0, function* ({ method, path:
|
|
40708
|
+
return __awaiter2(this, arguments, void 0, function* ({ method, path: path4, config: config2, postObject, timeoutOverride }) {
|
|
40709
40709
|
let statusCode = null;
|
|
40710
40710
|
let rspBody = null;
|
|
40711
40711
|
let error4 = null;
|
|
@@ -40716,7 +40716,7 @@ function requireFailoverStrategies() {
|
|
|
40716
40716
|
}
|
|
40717
40717
|
for (let attempt = 0; attempt < config2.attemptsPerEndpoint; attempt++) {
|
|
40718
40718
|
const requestTimeout = timeoutOverride !== null && timeoutOverride !== void 0 ? timeoutOverride : config2.responseTimeout;
|
|
40719
|
-
const response = yield (0, httpUtil_1.handleRequest)(method,
|
|
40719
|
+
const response = yield (0, httpUtil_1.handleRequest)(method, path4, endpoint.url, requestTimeout, postObject);
|
|
40720
40720
|
if (response) {
|
|
40721
40721
|
({ error: error4, statusCode, rspBody, transactionTimestamp } = response);
|
|
40722
40722
|
}
|
|
@@ -40731,7 +40731,7 @@ function requireFailoverStrategies() {
|
|
|
40731
40731
|
});
|
|
40732
40732
|
}
|
|
40733
40733
|
function retryRequest(_a2) {
|
|
40734
|
-
return __awaiter2(this, arguments, void 0, function* ({ method, path:
|
|
40734
|
+
return __awaiter2(this, arguments, void 0, function* ({ method, path: path4, config: config2, postObject, useNextNodeOnError, recoveryThreshold, timeoutOverride }) {
|
|
40735
40735
|
var _b, _c, _d;
|
|
40736
40736
|
let statusCode = null;
|
|
40737
40737
|
let rspBody = null;
|
|
@@ -40742,7 +40742,7 @@ function requireFailoverStrategies() {
|
|
|
40742
40742
|
for (const node2 of availableNodes) {
|
|
40743
40743
|
for (let attempt = 0; attempt < config2.attemptsPerEndpoint; attempt++) {
|
|
40744
40744
|
const requestTimeout = timeoutOverride !== null && timeoutOverride !== void 0 ? timeoutOverride : config2.responseTimeout;
|
|
40745
|
-
const response = yield (0, httpUtil_1.handleRequest)(method,
|
|
40745
|
+
const response = yield (0, httpUtil_1.handleRequest)(method, path4, node2.url, requestTimeout, postObject);
|
|
40746
40746
|
error4 = (_b = response === null || response === void 0 ? void 0 : response.error) !== null && _b !== void 0 ? _b : null;
|
|
40747
40747
|
statusCode = (_c = response === null || response === void 0 ? void 0 : response.statusCode) !== null && _c !== void 0 ? _c : null;
|
|
40748
40748
|
rspBody = (_d = response === null || response === void 0 ? void 0 : response.rspBody) !== null && _d !== void 0 ? _d : null;
|
|
@@ -40885,19 +40885,19 @@ function requireRequestWithFailoverStrategy() {
|
|
|
40885
40885
|
const enums_12 = enums;
|
|
40886
40886
|
const failoverStrategies_1 = requireFailoverStrategies();
|
|
40887
40887
|
function requestWithFailoverStrategy$1(method_1, path_1, config_1, postObject_1) {
|
|
40888
|
-
return __awaiter2(this, arguments, void 0, function* (method,
|
|
40888
|
+
return __awaiter2(this, arguments, void 0, function* (method, path4, config2, postObject, forceSingleEndpoint = false, timeoutOverride) {
|
|
40889
40889
|
switch (config2.failoverStrategy) {
|
|
40890
40890
|
case enums_12.FailoverStrategy.AbortOnError:
|
|
40891
|
-
return yield (0, failoverStrategies_1.abortOnError)({ method, path:
|
|
40891
|
+
return yield (0, failoverStrategies_1.abortOnError)({ method, path: path4, config: config2, postObject, timeoutOverride });
|
|
40892
40892
|
case enums_12.FailoverStrategy.TryNextOnError:
|
|
40893
|
-
return yield (0, failoverStrategies_1.tryNextOnError)({ method, path:
|
|
40893
|
+
return yield (0, failoverStrategies_1.tryNextOnError)({ method, path: path4, config: config2, postObject, timeoutOverride });
|
|
40894
40894
|
case enums_12.FailoverStrategy.SingleEndpoint:
|
|
40895
|
-
return yield (0, failoverStrategies_1.singleEndpoint)({ method, path:
|
|
40895
|
+
return yield (0, failoverStrategies_1.singleEndpoint)({ method, path: path4, config: config2, postObject, timeoutOverride });
|
|
40896
40896
|
case enums_12.FailoverStrategy.QueryMajority:
|
|
40897
40897
|
if (forceSingleEndpoint) {
|
|
40898
|
-
return yield (0, failoverStrategies_1.singleEndpoint)({ method, path:
|
|
40898
|
+
return yield (0, failoverStrategies_1.singleEndpoint)({ method, path: path4, config: config2, postObject, timeoutOverride });
|
|
40899
40899
|
}
|
|
40900
|
-
return yield (0, failoverStrategies_1.queryMajority)({ method, path:
|
|
40900
|
+
return yield (0, failoverStrategies_1.queryMajority)({ method, path: path4, config: config2, postObject, timeoutOverride });
|
|
40901
40901
|
default:
|
|
40902
40902
|
throw new Error(`Unsupported failover strategy: ${config2.failoverStrategy}`);
|
|
40903
40903
|
}
|
|
@@ -42096,7 +42096,7 @@ var networkSettings = {};
|
|
|
42096
42096
|
const restNetworkSettingsValidationContext = RestNetworkSettingsSchema.safeParse(networkSettings2);
|
|
42097
42097
|
if ("error" in restNetworkSettingsValidationContext) {
|
|
42098
42098
|
const { error: { issues } = {} } = restNetworkSettingsValidationContext;
|
|
42099
|
-
const errorMessage2 = issues === null || issues === void 0 ? void 0 : issues.map(({ message, path:
|
|
42099
|
+
const errorMessage2 = issues === null || issues === void 0 ? void 0 : issues.map(({ message, path: path4 }) => `${path4[0]}: ${message}`).join(", ");
|
|
42100
42100
|
if (throwOnError) {
|
|
42101
42101
|
throw new Error(errorMessage2);
|
|
42102
42102
|
}
|
|
@@ -44453,8 +44453,8 @@ var HttpClient = class {
|
|
|
44453
44453
|
this.baseUrl = baseUrl.replace(/\/+$/, "");
|
|
44454
44454
|
this.timeoutMs = timeoutMs;
|
|
44455
44455
|
}
|
|
44456
|
-
buildUrl(
|
|
44457
|
-
const url = new URL(this.baseUrl +
|
|
44456
|
+
buildUrl(path4, query) {
|
|
44457
|
+
const url = new URL(this.baseUrl + path4);
|
|
44458
44458
|
if (query) {
|
|
44459
44459
|
for (const [k, v] of Object.entries(query)) {
|
|
44460
44460
|
if (v !== void 0 && v !== null && v !== "") {
|
|
@@ -44464,14 +44464,14 @@ var HttpClient = class {
|
|
|
44464
44464
|
}
|
|
44465
44465
|
return url.toString();
|
|
44466
44466
|
}
|
|
44467
|
-
async get(
|
|
44468
|
-
return this.fetch(this.buildUrl(
|
|
44467
|
+
async get(path4, query, headers) {
|
|
44468
|
+
return this.fetch(this.buildUrl(path4, query), {
|
|
44469
44469
|
method: "GET",
|
|
44470
44470
|
...headers && { headers }
|
|
44471
44471
|
});
|
|
44472
44472
|
}
|
|
44473
|
-
async post(
|
|
44474
|
-
return this.fetch(this.buildUrl(
|
|
44473
|
+
async post(path4, body, headers) {
|
|
44474
|
+
return this.fetch(this.buildUrl(path4), {
|
|
44475
44475
|
method: "POST",
|
|
44476
44476
|
headers: { "Content-Type": "application/json", ...headers },
|
|
44477
44477
|
body: JSON.stringify(body)
|
|
@@ -44641,6 +44641,16 @@ var Atbash = class _Atbash {
|
|
|
44641
44641
|
* calls don't re-hit the dashboard. Cleared by `clearChainCache()`.
|
|
44642
44642
|
*/
|
|
44643
44643
|
_chainCache = /* @__PURE__ */ new Map();
|
|
44644
|
+
/**
|
|
44645
|
+
* Short-TTL cache for `/api/ai/exists`. The `registered` field is
|
|
44646
|
+
* monotonic (once true, stays true), so most calls in a burst re-fetch
|
|
44647
|
+
* data that hasn't changed. The `org_encryption_pubkey` field CAN change
|
|
44648
|
+
* — an org toggling encryption mid-session — so the TTL is deliberately
|
|
44649
|
+
* short (see `AGENT_EXISTS_TTL_MS`). Keyed by (pubkey, network) so
|
|
44650
|
+
* cross-agent / cross-network calls don't collide.
|
|
44651
|
+
*/
|
|
44652
|
+
_agentExistsCache = null;
|
|
44653
|
+
static AGENT_EXISTS_TTL_MS = 5e3;
|
|
44644
44654
|
/**
|
|
44645
44655
|
* Cached bearer token for risk-engine / insurance read calls. Built
|
|
44646
44656
|
* lazily as a signed `log_tool_call` tx and refreshed every 4 min so
|
|
@@ -44740,9 +44750,18 @@ var Atbash = class _Atbash {
|
|
|
44740
44750
|
*/
|
|
44741
44751
|
async checkAgentExists(pubkey, opts) {
|
|
44742
44752
|
const pk = pubkey ?? this.auth.pubkey;
|
|
44753
|
+
const network = opts?.network;
|
|
44754
|
+
const now = Date.now();
|
|
44755
|
+
const cached = this._agentExistsCache;
|
|
44756
|
+
if (cached && cached.pubkey === pk && cached.network === network && cached.expiresAt > now) {
|
|
44757
|
+
if (pk === this.auth.pubkey) {
|
|
44758
|
+
this._orgKeyFromChain = cached.orgKey;
|
|
44759
|
+
}
|
|
44760
|
+
return cached.registered;
|
|
44761
|
+
}
|
|
44743
44762
|
return this.track("checkAgentExists", pk, async () => {
|
|
44744
44763
|
const query = { pubkey: pk };
|
|
44745
|
-
if (
|
|
44764
|
+
if (network) query.network = network;
|
|
44746
44765
|
const resp = await this.http.get(
|
|
44747
44766
|
"/api/ai/exists",
|
|
44748
44767
|
query,
|
|
@@ -44750,11 +44769,21 @@ var Atbash = class _Atbash {
|
|
|
44750
44769
|
);
|
|
44751
44770
|
await this.raiseIfError(resp);
|
|
44752
44771
|
const data = await this.json(resp);
|
|
44772
|
+
const registered = Boolean(data?.registered);
|
|
44773
|
+
const orgKey = typeof data?.org_encryption_pubkey === "string" && data.org_encryption_pubkey ? data.org_encryption_pubkey : null;
|
|
44774
|
+
if (registered) {
|
|
44775
|
+
this._agentExistsCache = {
|
|
44776
|
+
pubkey: pk,
|
|
44777
|
+
network,
|
|
44778
|
+
expiresAt: Date.now() + _Atbash.AGENT_EXISTS_TTL_MS,
|
|
44779
|
+
registered,
|
|
44780
|
+
orgKey
|
|
44781
|
+
};
|
|
44782
|
+
}
|
|
44753
44783
|
if (pk === this.auth.pubkey) {
|
|
44754
|
-
|
|
44755
|
-
this._orgKeyFromChain = typeof key3 === "string" && key3 ? key3 : null;
|
|
44784
|
+
this._orgKeyFromChain = orgKey;
|
|
44756
44785
|
}
|
|
44757
|
-
return
|
|
44786
|
+
return registered;
|
|
44758
44787
|
});
|
|
44759
44788
|
}
|
|
44760
44789
|
/* ── log_tool_call (sign-only) ─────────────────────────────────────────── */
|
|
@@ -44835,12 +44864,19 @@ var Atbash = class _Atbash {
|
|
|
44835
44864
|
}
|
|
44836
44865
|
let chainOpts = options.chainOpts;
|
|
44837
44866
|
if (options.orgName) {
|
|
44838
|
-
const
|
|
44839
|
-
if (
|
|
44840
|
-
chainOpts = { network:
|
|
44841
|
-
} else
|
|
44842
|
-
const
|
|
44843
|
-
|
|
44867
|
+
const cached = this._chainCache.get(options.orgName);
|
|
44868
|
+
if (cached) {
|
|
44869
|
+
chainOpts = { network: cached.network };
|
|
44870
|
+
} else {
|
|
44871
|
+
const mapNetwork = await this.getActiveNetworkForOrg(options.orgName);
|
|
44872
|
+
if (mapNetwork) {
|
|
44873
|
+
const chain = mapNetwork === "private" ? PRIVATE_CHAIN : PUBLIC_CHAIN;
|
|
44874
|
+
this._chainCache.set(options.orgName, chain);
|
|
44875
|
+
chainOpts = { network: mapNetwork };
|
|
44876
|
+
} else if (!chainOpts?.blockchainRid) {
|
|
44877
|
+
const resolved = await this.resolveChainFromMap(options.orgName, null);
|
|
44878
|
+
chainOpts = { ...chainOpts, network: resolved.network };
|
|
44879
|
+
}
|
|
44844
44880
|
}
|
|
44845
44881
|
}
|
|
44846
44882
|
const brid = this.bridFromChainOpts(chainOpts);
|
|
@@ -45289,6 +45325,10 @@ var Atbash = class _Atbash {
|
|
|
45289
45325
|
clearChainCache() {
|
|
45290
45326
|
this._chainCache.clear();
|
|
45291
45327
|
}
|
|
45328
|
+
/** Drop the short-TTL `/api/ai/exists` cache. Useful in tests. */
|
|
45329
|
+
clearAgentExistsCache() {
|
|
45330
|
+
this._agentExistsCache = null;
|
|
45331
|
+
}
|
|
45292
45332
|
/* ── internals ─────────────────────────────────────────────────────────── */
|
|
45293
45333
|
/**
|
|
45294
45334
|
* Wrap an SDK method body in telemetry — records the call at start
|
|
@@ -45789,6 +45829,7 @@ function classifyMemoryWrite(_event, _ctx, _opts = {}) {
|
|
|
45789
45829
|
// src-ts/memory/guard.ts
|
|
45790
45830
|
init_define_ATBASH_CHROMIA_NODE_URLS();
|
|
45791
45831
|
init_define_ATBASH_PRIVATE_NODE_URLS();
|
|
45832
|
+
import path3 from "path";
|
|
45792
45833
|
function emitDebugProbe(event, ctx, memEntry, logger2) {
|
|
45793
45834
|
if (!logger2?.info) return;
|
|
45794
45835
|
const ev = event ?? {};
|
|
@@ -45825,7 +45866,8 @@ async function guardMemoryWrite(input) {
|
|
|
45825
45866
|
toolNames,
|
|
45826
45867
|
enforce = true,
|
|
45827
45868
|
debug: debug2 = false,
|
|
45828
|
-
logger: logger2
|
|
45869
|
+
logger: logger2,
|
|
45870
|
+
memoryFilePath
|
|
45829
45871
|
} = input;
|
|
45830
45872
|
const memEntry = classifyMemoryWrite(event, ctx, { patterns, toolNames });
|
|
45831
45873
|
if (debug2) emitDebugProbe(event, ctx, memEntry, logger2);
|
|
@@ -45861,17 +45903,28 @@ async function guardMemoryWrite(input) {
|
|
|
45861
45903
|
committed: false
|
|
45862
45904
|
};
|
|
45863
45905
|
}
|
|
45864
|
-
|
|
45865
|
-
|
|
45866
|
-
|
|
45867
|
-
|
|
45868
|
-
|
|
45869
|
-
|
|
45870
|
-
|
|
45871
|
-
|
|
45872
|
-
|
|
45906
|
+
const isManagedMemoryFile = memoryFilePath !== void 0 && path3.resolve(memEntry.key) === path3.resolve(memoryFilePath);
|
|
45907
|
+
if (isManagedMemoryFile) {
|
|
45908
|
+
commitMemoryVersion(memEntry.value, auth, {
|
|
45909
|
+
score: scanResult.score,
|
|
45910
|
+
orgName,
|
|
45911
|
+
endpoint
|
|
45912
|
+
}).catch((err) => {
|
|
45913
|
+
const reason = err instanceof Error ? err.message : String(err);
|
|
45914
|
+
logger2?.warn?.("[atbash] memory commit to chain failed", {
|
|
45915
|
+
path: memEntry.key,
|
|
45916
|
+
reason
|
|
45917
|
+
});
|
|
45873
45918
|
});
|
|
45874
|
-
}
|
|
45919
|
+
} else {
|
|
45920
|
+
logger2?.info?.(
|
|
45921
|
+
"[atbash] scanned but not committed \u2014 not the managed memory file",
|
|
45922
|
+
{
|
|
45923
|
+
path: memEntry.key,
|
|
45924
|
+
memoryFilePath: memoryFilePath ?? "(not configured)"
|
|
45925
|
+
}
|
|
45926
|
+
);
|
|
45927
|
+
}
|
|
45875
45928
|
logger2?.info?.(
|
|
45876
45929
|
scanResult.verdict === "yellow" ? "[atbash] memory HOLD" : "[atbash] memory ALLOW",
|
|
45877
45930
|
{ path: memEntry.key, score: scanResult.score, reason: scanResult.reason }
|
|
@@ -45880,7 +45933,7 @@ async function guardMemoryWrite(input) {
|
|
|
45880
45933
|
handled: true,
|
|
45881
45934
|
decision: { allow: true },
|
|
45882
45935
|
scanResult,
|
|
45883
|
-
committed:
|
|
45936
|
+
committed: isManagedMemoryFile
|
|
45884
45937
|
};
|
|
45885
45938
|
}
|
|
45886
45939
|
|
|
@@ -45901,21 +45954,21 @@ async function syncLocalMemory(auth, pointer, opts = {}) {
|
|
|
45901
45954
|
const now = Date.now();
|
|
45902
45955
|
const withinTtl = !opts.force && now - pointer.checkedAt < ttl;
|
|
45903
45956
|
if (withinTtl) {
|
|
45904
|
-
return { drifted: false, pointer };
|
|
45957
|
+
return { drifted: false, checked: false, pointer };
|
|
45905
45958
|
}
|
|
45906
45959
|
const currentId = await getActiveMemoryId(auth, opts.chainOpts);
|
|
45907
45960
|
const nextPointer = { activeId: currentId, checkedAt: now };
|
|
45908
45961
|
if (currentId === pointer.activeId) {
|
|
45909
|
-
return { drifted: false, pointer: nextPointer };
|
|
45962
|
+
return { drifted: false, checked: true, pointer: nextPointer };
|
|
45910
45963
|
}
|
|
45911
45964
|
if (currentId === null) {
|
|
45912
|
-
return { drifted: true, current: null, pointer: nextPointer };
|
|
45965
|
+
return { drifted: true, checked: true, current: null, pointer: nextPointer };
|
|
45913
45966
|
}
|
|
45914
45967
|
const row = await getMemoryById(currentId, auth, opts.chainOpts);
|
|
45915
45968
|
if (row.decryptError) {
|
|
45916
45969
|
throw new MemoryIntegrityError(currentId, row.decryptError);
|
|
45917
45970
|
}
|
|
45918
|
-
return { drifted: true, current: row, pointer: nextPointer };
|
|
45971
|
+
return { drifted: true, checked: true, current: row, pointer: nextPointer };
|
|
45919
45972
|
}
|
|
45920
45973
|
|
|
45921
45974
|
// src-ts/browser/memory-pointer-store.ts
|