@atbash/sdk 0.7.0-dev.0 → 0.7.1-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.mjs +87 -296
- package/dist/browser.mjs.map +1 -1
- package/package.json +5 -5
package/dist/browser.mjs
CHANGED
|
@@ -9993,8 +9993,8 @@ Reporter$3.prototype.wrapResult = function wrapResult(result) {
|
|
|
9993
9993
|
errors: state2.errors
|
|
9994
9994
|
};
|
|
9995
9995
|
};
|
|
9996
|
-
function ReporterError$1(
|
|
9997
|
-
this.path =
|
|
9996
|
+
function ReporterError$1(path3, msg) {
|
|
9997
|
+
this.path = path3;
|
|
9998
9998
|
this.rethrow(msg);
|
|
9999
9999
|
}
|
|
10000
10000
|
inherits$v(ReporterError$1, Error);
|
|
@@ -30215,8 +30215,8 @@ Reporter.prototype.wrapResult = function wrapResult2(result) {
|
|
|
30215
30215
|
errors: state2.errors
|
|
30216
30216
|
};
|
|
30217
30217
|
};
|
|
30218
|
-
function ReporterError(
|
|
30219
|
-
this.path =
|
|
30218
|
+
function ReporterError(path3, msg) {
|
|
30219
|
+
this.path = path3;
|
|
30220
30220
|
this.rethrow(msg);
|
|
30221
30221
|
}
|
|
30222
30222
|
inherits(ReporterError, Error);
|
|
@@ -33246,8 +33246,8 @@ var parseUtil = {};
|
|
|
33246
33246
|
const errors_js_12 = errors$3;
|
|
33247
33247
|
const en_js_12 = __importDefault2(en);
|
|
33248
33248
|
const makeIssue = (params) => {
|
|
33249
|
-
const { data, path:
|
|
33250
|
-
const fullPath = [...
|
|
33249
|
+
const { data, path: path3, errorMaps, issueData } = params;
|
|
33250
|
+
const fullPath = [...path3, ...issueData.path || []];
|
|
33251
33251
|
const fullIssue = {
|
|
33252
33252
|
...issueData,
|
|
33253
33253
|
path: fullPath
|
|
@@ -33384,11 +33384,11 @@ var errorUtil_js_1 = errorUtil$1;
|
|
|
33384
33384
|
var parseUtil_js_1 = parseUtil;
|
|
33385
33385
|
var util_js_1 = util;
|
|
33386
33386
|
var ParseInputLazyPath = class {
|
|
33387
|
-
constructor(parent, value,
|
|
33387
|
+
constructor(parent, value, path3, key3) {
|
|
33388
33388
|
this._cachedPath = [];
|
|
33389
33389
|
this.parent = parent;
|
|
33390
33390
|
this.data = value;
|
|
33391
|
-
this._path =
|
|
33391
|
+
this._path = path3;
|
|
33392
33392
|
this._key = key3;
|
|
33393
33393
|
}
|
|
33394
33394
|
get path() {
|
|
@@ -40294,21 +40294,21 @@ function createTimeoutController(timeout) {
|
|
|
40294
40294
|
const timeoutId = setTimeout(() => controller.abort(timeoutError), timeout);
|
|
40295
40295
|
return { controller, timeoutId };
|
|
40296
40296
|
}
|
|
40297
|
-
function handleRequest(method,
|
|
40297
|
+
function handleRequest(method, path3, endpoint, timeout, postObject) {
|
|
40298
40298
|
return __awaiter$2(this, void 0, void 0, function* () {
|
|
40299
40299
|
if (method == enums_1$2.Method.GET) {
|
|
40300
|
-
return yield get(
|
|
40300
|
+
return yield get(path3, endpoint, timeout);
|
|
40301
40301
|
} else {
|
|
40302
|
-
return yield post(
|
|
40302
|
+
return yield post(path3, endpoint, timeout, postObject);
|
|
40303
40303
|
}
|
|
40304
40304
|
});
|
|
40305
40305
|
}
|
|
40306
|
-
function get(
|
|
40306
|
+
function get(path3, endpoint, timeout) {
|
|
40307
40307
|
return __awaiter$2(this, void 0, void 0, function* () {
|
|
40308
|
-
logger.debug(`GET URL ${new URL(
|
|
40308
|
+
logger.debug(`GET URL ${new URL(path3, endpoint).href}`);
|
|
40309
40309
|
try {
|
|
40310
40310
|
const { controller, timeoutId } = createTimeoutController(timeout);
|
|
40311
|
-
const response = yield fetch(new URL(
|
|
40311
|
+
const response = yield fetch(new URL(path3, endpoint).href, {
|
|
40312
40312
|
signal: controller === null || controller === void 0 ? void 0 : controller.signal
|
|
40313
40313
|
});
|
|
40314
40314
|
if (timeoutId)
|
|
@@ -40346,9 +40346,9 @@ function constructBufferResponseBody(response) {
|
|
|
40346
40346
|
return responseText ? responseText : response.statusText;
|
|
40347
40347
|
});
|
|
40348
40348
|
}
|
|
40349
|
-
function post(
|
|
40349
|
+
function post(path3, endpoint, timeout, requestBody) {
|
|
40350
40350
|
return __awaiter$2(this, void 0, void 0, function* () {
|
|
40351
|
-
logger.debug(`POST URL ${new URL(
|
|
40351
|
+
logger.debug(`POST URL ${new URL(path3, endpoint).href}`);
|
|
40352
40352
|
logger.debug(`POST body ${JSON.stringify(requestBody)}`);
|
|
40353
40353
|
if (buffer_1.Buffer.isBuffer(requestBody)) {
|
|
40354
40354
|
try {
|
|
@@ -40362,7 +40362,7 @@ function post(path6, endpoint, timeout, requestBody) {
|
|
|
40362
40362
|
},
|
|
40363
40363
|
signal: controller === null || controller === void 0 ? void 0 : controller.signal
|
|
40364
40364
|
};
|
|
40365
|
-
const response = yield fetch(new URL(
|
|
40365
|
+
const response = yield fetch(new URL(path3, endpoint).href, requestOptions);
|
|
40366
40366
|
if (timeoutId)
|
|
40367
40367
|
clearTimeout(timeoutId);
|
|
40368
40368
|
const transactionTimestamp = response.headers.get("X-Transaction-Timestamp");
|
|
@@ -40373,7 +40373,7 @@ function post(path6, endpoint, timeout, requestBody) {
|
|
|
40373
40373
|
} else {
|
|
40374
40374
|
try {
|
|
40375
40375
|
const { controller, timeoutId } = createTimeoutController(timeout);
|
|
40376
|
-
const response = yield fetch(new URL(
|
|
40376
|
+
const response = yield fetch(new URL(path3, endpoint).href, {
|
|
40377
40377
|
method: "post",
|
|
40378
40378
|
body: JSON.stringify(requestBody),
|
|
40379
40379
|
headers: {
|
|
@@ -40553,10 +40553,10 @@ function requireFailoverStrategies() {
|
|
|
40553
40553
|
}
|
|
40554
40554
|
}
|
|
40555
40555
|
function abortOnError(_a2) {
|
|
40556
|
-
return __awaiter2(this, arguments, void 0, function* ({ method, path:
|
|
40556
|
+
return __awaiter2(this, arguments, void 0, function* ({ method, path: path3, config: config2, postObject, timeoutOverride }) {
|
|
40557
40557
|
return yield retryRequest({
|
|
40558
40558
|
method,
|
|
40559
|
-
path:
|
|
40559
|
+
path: path3,
|
|
40560
40560
|
config: config2,
|
|
40561
40561
|
postObject,
|
|
40562
40562
|
timeoutOverride,
|
|
@@ -40567,10 +40567,10 @@ function requireFailoverStrategies() {
|
|
|
40567
40567
|
});
|
|
40568
40568
|
}
|
|
40569
40569
|
function tryNextOnError(_a2) {
|
|
40570
|
-
return __awaiter2(this, arguments, void 0, function* ({ method, path:
|
|
40570
|
+
return __awaiter2(this, arguments, void 0, function* ({ method, path: path3, config: config2, postObject, timeoutOverride }) {
|
|
40571
40571
|
return yield retryRequest({
|
|
40572
40572
|
method,
|
|
40573
|
-
path:
|
|
40573
|
+
path: path3,
|
|
40574
40574
|
config: config2,
|
|
40575
40575
|
postObject,
|
|
40576
40576
|
timeoutOverride,
|
|
@@ -40586,7 +40586,7 @@ function requireFailoverStrategies() {
|
|
|
40586
40586
|
return endpointPoolLength - (endpointPoolLength - 1) / 3;
|
|
40587
40587
|
}
|
|
40588
40588
|
function queryMajority(_a2) {
|
|
40589
|
-
return __awaiter2(this, arguments, void 0, function* ({ method, path:
|
|
40589
|
+
return __awaiter2(this, arguments, void 0, function* ({ method, path: path3, config: config2, postObject, timeoutOverride }) {
|
|
40590
40590
|
var _b;
|
|
40591
40591
|
const bftMajorityThreshold = calculateBftMajorityThreshold(config2.endpointPool.length);
|
|
40592
40592
|
const failureThreshold = config2.endpointPool.length - bftMajorityThreshold + 1;
|
|
@@ -40597,7 +40597,7 @@ function requireFailoverStrategies() {
|
|
|
40597
40597
|
const promises = availableNodes.map((node2) => __awaiter2(this, void 0, void 0, function* () {
|
|
40598
40598
|
try {
|
|
40599
40599
|
const requestTimeout = timeoutOverride !== null && timeoutOverride !== void 0 ? timeoutOverride : config2.responseTimeout;
|
|
40600
|
-
const response = yield (0, httpUtil_1.handleRequest)(method,
|
|
40600
|
+
const response = yield (0, httpUtil_1.handleRequest)(method, path3, node2.url, requestTimeout, postObject);
|
|
40601
40601
|
const { statusCode } = response;
|
|
40602
40602
|
if (statusCode && (0, http_utils_1.isSuccessfulStatusCode)(statusCode)) {
|
|
40603
40603
|
outcomes.push({ type: "SUCCESS", result: response });
|
|
@@ -40644,7 +40644,7 @@ function requireFailoverStrategies() {
|
|
|
40644
40644
|
});
|
|
40645
40645
|
}
|
|
40646
40646
|
function singleEndpoint(_a2) {
|
|
40647
|
-
return __awaiter2(this, arguments, void 0, function* ({ method, path:
|
|
40647
|
+
return __awaiter2(this, arguments, void 0, function* ({ method, path: path3, config: config2, postObject, timeoutOverride }) {
|
|
40648
40648
|
let statusCode = null;
|
|
40649
40649
|
let rspBody = null;
|
|
40650
40650
|
let error4 = null;
|
|
@@ -40655,7 +40655,7 @@ function requireFailoverStrategies() {
|
|
|
40655
40655
|
}
|
|
40656
40656
|
for (let attempt = 0; attempt < config2.attemptsPerEndpoint; attempt++) {
|
|
40657
40657
|
const requestTimeout = timeoutOverride !== null && timeoutOverride !== void 0 ? timeoutOverride : config2.responseTimeout;
|
|
40658
|
-
const response = yield (0, httpUtil_1.handleRequest)(method,
|
|
40658
|
+
const response = yield (0, httpUtil_1.handleRequest)(method, path3, endpoint.url, requestTimeout, postObject);
|
|
40659
40659
|
if (response) {
|
|
40660
40660
|
({ error: error4, statusCode, rspBody, transactionTimestamp } = response);
|
|
40661
40661
|
}
|
|
@@ -40670,7 +40670,7 @@ function requireFailoverStrategies() {
|
|
|
40670
40670
|
});
|
|
40671
40671
|
}
|
|
40672
40672
|
function retryRequest(_a2) {
|
|
40673
|
-
return __awaiter2(this, arguments, void 0, function* ({ method, path:
|
|
40673
|
+
return __awaiter2(this, arguments, void 0, function* ({ method, path: path3, config: config2, postObject, useNextNodeOnError, recoveryThreshold, timeoutOverride }) {
|
|
40674
40674
|
var _b, _c, _d;
|
|
40675
40675
|
let statusCode = null;
|
|
40676
40676
|
let rspBody = null;
|
|
@@ -40681,7 +40681,7 @@ function requireFailoverStrategies() {
|
|
|
40681
40681
|
for (const node2 of availableNodes) {
|
|
40682
40682
|
for (let attempt = 0; attempt < config2.attemptsPerEndpoint; attempt++) {
|
|
40683
40683
|
const requestTimeout = timeoutOverride !== null && timeoutOverride !== void 0 ? timeoutOverride : config2.responseTimeout;
|
|
40684
|
-
const response = yield (0, httpUtil_1.handleRequest)(method,
|
|
40684
|
+
const response = yield (0, httpUtil_1.handleRequest)(method, path3, node2.url, requestTimeout, postObject);
|
|
40685
40685
|
error4 = (_b = response === null || response === void 0 ? void 0 : response.error) !== null && _b !== void 0 ? _b : null;
|
|
40686
40686
|
statusCode = (_c = response === null || response === void 0 ? void 0 : response.statusCode) !== null && _c !== void 0 ? _c : null;
|
|
40687
40687
|
rspBody = (_d = response === null || response === void 0 ? void 0 : response.rspBody) !== null && _d !== void 0 ? _d : null;
|
|
@@ -40824,19 +40824,19 @@ function requireRequestWithFailoverStrategy() {
|
|
|
40824
40824
|
const enums_12 = enums;
|
|
40825
40825
|
const failoverStrategies_1 = requireFailoverStrategies();
|
|
40826
40826
|
function requestWithFailoverStrategy$1(method_1, path_1, config_1, postObject_1) {
|
|
40827
|
-
return __awaiter2(this, arguments, void 0, function* (method,
|
|
40827
|
+
return __awaiter2(this, arguments, void 0, function* (method, path3, config2, postObject, forceSingleEndpoint = false, timeoutOverride) {
|
|
40828
40828
|
switch (config2.failoverStrategy) {
|
|
40829
40829
|
case enums_12.FailoverStrategy.AbortOnError:
|
|
40830
|
-
return yield (0, failoverStrategies_1.abortOnError)({ method, path:
|
|
40830
|
+
return yield (0, failoverStrategies_1.abortOnError)({ method, path: path3, config: config2, postObject, timeoutOverride });
|
|
40831
40831
|
case enums_12.FailoverStrategy.TryNextOnError:
|
|
40832
|
-
return yield (0, failoverStrategies_1.tryNextOnError)({ method, path:
|
|
40832
|
+
return yield (0, failoverStrategies_1.tryNextOnError)({ method, path: path3, config: config2, postObject, timeoutOverride });
|
|
40833
40833
|
case enums_12.FailoverStrategy.SingleEndpoint:
|
|
40834
|
-
return yield (0, failoverStrategies_1.singleEndpoint)({ method, path:
|
|
40834
|
+
return yield (0, failoverStrategies_1.singleEndpoint)({ method, path: path3, config: config2, postObject, timeoutOverride });
|
|
40835
40835
|
case enums_12.FailoverStrategy.QueryMajority:
|
|
40836
40836
|
if (forceSingleEndpoint) {
|
|
40837
|
-
return yield (0, failoverStrategies_1.singleEndpoint)({ method, path:
|
|
40837
|
+
return yield (0, failoverStrategies_1.singleEndpoint)({ method, path: path3, config: config2, postObject, timeoutOverride });
|
|
40838
40838
|
}
|
|
40839
|
-
return yield (0, failoverStrategies_1.queryMajority)({ method, path:
|
|
40839
|
+
return yield (0, failoverStrategies_1.queryMajority)({ method, path: path3, config: config2, postObject, timeoutOverride });
|
|
40840
40840
|
default:
|
|
40841
40841
|
throw new Error(`Unsupported failover strategy: ${config2.failoverStrategy}`);
|
|
40842
40842
|
}
|
|
@@ -42035,7 +42035,7 @@ var networkSettings = {};
|
|
|
42035
42035
|
const restNetworkSettingsValidationContext = RestNetworkSettingsSchema.safeParse(networkSettings2);
|
|
42036
42036
|
if ("error" in restNetworkSettingsValidationContext) {
|
|
42037
42037
|
const { error: { issues } = {} } = restNetworkSettingsValidationContext;
|
|
42038
|
-
const errorMessage2 = issues === null || issues === void 0 ? void 0 : issues.map(({ message, path:
|
|
42038
|
+
const errorMessage2 = issues === null || issues === void 0 ? void 0 : issues.map(({ message, path: path3 }) => `${path3[0]}: ${message}`).join(", ");
|
|
42039
42039
|
if (throwOnError) {
|
|
42040
42040
|
throw new Error(errorMessage2);
|
|
42041
42041
|
}
|
|
@@ -43537,8 +43537,8 @@ var HttpClient = class {
|
|
|
43537
43537
|
this.baseUrl = baseUrl.replace(/\/+$/, "");
|
|
43538
43538
|
this.timeoutMs = timeoutMs;
|
|
43539
43539
|
}
|
|
43540
|
-
buildUrl(
|
|
43541
|
-
const url = new URL(this.baseUrl +
|
|
43540
|
+
buildUrl(path3, query) {
|
|
43541
|
+
const url = new URL(this.baseUrl + path3);
|
|
43542
43542
|
if (query) {
|
|
43543
43543
|
for (const [k, v] of Object.entries(query)) {
|
|
43544
43544
|
if (v !== void 0 && v !== null && v !== "") {
|
|
@@ -43548,14 +43548,14 @@ var HttpClient = class {
|
|
|
43548
43548
|
}
|
|
43549
43549
|
return url.toString();
|
|
43550
43550
|
}
|
|
43551
|
-
async get(
|
|
43552
|
-
return this.fetch(this.buildUrl(
|
|
43551
|
+
async get(path3, query, headers) {
|
|
43552
|
+
return this.fetch(this.buildUrl(path3, query), {
|
|
43553
43553
|
method: "GET",
|
|
43554
43554
|
...headers && { headers }
|
|
43555
43555
|
});
|
|
43556
43556
|
}
|
|
43557
|
-
async post(
|
|
43558
|
-
return this.fetch(this.buildUrl(
|
|
43557
|
+
async post(path3, body, headers) {
|
|
43558
|
+
return this.fetch(this.buildUrl(path3), {
|
|
43559
43559
|
method: "POST",
|
|
43560
43560
|
headers: { "Content-Type": "application/json", ...headers },
|
|
43561
43561
|
body: JSON.stringify(body)
|
|
@@ -44946,8 +44946,8 @@ function pickContent(toolName, args) {
|
|
|
44946
44946
|
}
|
|
44947
44947
|
return "";
|
|
44948
44948
|
}
|
|
44949
|
-
function matchesMemoryPath(
|
|
44950
|
-
const pLower =
|
|
44949
|
+
function matchesMemoryPath(path3, patterns) {
|
|
44950
|
+
const pLower = path3.toLowerCase();
|
|
44951
44951
|
for (const p of patterns) {
|
|
44952
44952
|
if (p && pLower.includes(p.toLowerCase())) return true;
|
|
44953
44953
|
}
|
|
@@ -44963,13 +44963,13 @@ function classifyMemoryWrite(event, ctx, opts = {}) {
|
|
|
44963
44963
|
const toolNamesLower = toolNames.map((t) => t.toLowerCase());
|
|
44964
44964
|
if (!toolNamesLower.includes(toolNameLower)) return null;
|
|
44965
44965
|
const args = ev.params ?? c.params ?? ev.args ?? c.args ?? ev.arguments ?? c.arguments;
|
|
44966
|
-
const
|
|
44967
|
-
if (!
|
|
44968
|
-
if (!matchesMemoryPath(
|
|
44966
|
+
const path3 = pickPath(args);
|
|
44967
|
+
if (!path3) return null;
|
|
44968
|
+
if (!matchesMemoryPath(path3, patterns)) return null;
|
|
44969
44969
|
const value = pickContent(toolName, args);
|
|
44970
44970
|
if (!value) return null;
|
|
44971
44971
|
return {
|
|
44972
|
-
key:
|
|
44972
|
+
key: path3,
|
|
44973
44973
|
value,
|
|
44974
44974
|
source: `plugin:${toolName}`
|
|
44975
44975
|
};
|
|
@@ -45103,95 +45103,33 @@ async function syncLocalMemory(auth, pointer, opts = {}) {
|
|
|
45103
45103
|
return { drifted: true, current: row, pointer: nextPointer };
|
|
45104
45104
|
}
|
|
45105
45105
|
|
|
45106
|
-
// src-ts/memory
|
|
45107
|
-
|
|
45108
|
-
|
|
45109
|
-
|
|
45106
|
+
// src-ts/browser/memory-pointer-store.ts
|
|
45107
|
+
var unavailable = (name2) => {
|
|
45108
|
+
throw new Error(`${name2} is not available in the browser bundle`);
|
|
45109
|
+
};
|
|
45110
45110
|
var PointerStore = class {
|
|
45111
|
-
constructor(
|
|
45112
|
-
this.filePath = filePath;
|
|
45113
|
-
}
|
|
45114
|
-
filePath;
|
|
45115
|
-
cache = null;
|
|
45116
|
-
loading = null;
|
|
45117
|
-
/** Resolves the pointer for `agentPubkeyHex`, or a zero-pointer that will force a sync on first use. */
|
|
45118
|
-
async get(agentPubkeyHex) {
|
|
45119
|
-
await this.ensureLoaded();
|
|
45120
|
-
return this.cache.agents[agentPubkeyHex] ?? { activeId: null, checkedAt: 0 };
|
|
45121
|
-
}
|
|
45122
|
-
/** Persists an updated pointer. Failures are swallowed to a logger callback (if provided) so sync never blocks the caller. */
|
|
45123
|
-
async set(agentPubkeyHex, pointer, onError) {
|
|
45124
|
-
await this.ensureLoaded();
|
|
45125
|
-
this.cache.agents[agentPubkeyHex] = pointer;
|
|
45126
|
-
try {
|
|
45127
|
-
await this.persist(this.cache);
|
|
45128
|
-
} catch (err) {
|
|
45129
|
-
onError?.(err instanceof Error ? err : new Error(String(err)));
|
|
45130
|
-
}
|
|
45111
|
+
constructor(_filePath) {
|
|
45131
45112
|
}
|
|
45132
|
-
|
|
45133
|
-
|
|
45134
|
-
if (!this.loading) this.loading = this.loadOnce();
|
|
45135
|
-
await this.loading;
|
|
45136
|
-
}
|
|
45137
|
-
async loadOnce() {
|
|
45138
|
-
try {
|
|
45139
|
-
const raw2 = await fs.readFile(this.filePath, "utf8");
|
|
45140
|
-
const parsed = JSON.parse(raw2);
|
|
45141
|
-
if (parsed && parsed.version === 1 && parsed.agents && typeof parsed.agents === "object") {
|
|
45142
|
-
this.cache = parsed;
|
|
45143
|
-
return;
|
|
45144
|
-
}
|
|
45145
|
-
} catch {
|
|
45146
|
-
}
|
|
45147
|
-
this.cache = { ...EMPTY, agents: {} };
|
|
45113
|
+
get(_pubkey) {
|
|
45114
|
+
return Promise.reject(new Error("PointerStore.get is not available in the browser bundle"));
|
|
45148
45115
|
}
|
|
45149
|
-
|
|
45150
|
-
|
|
45151
|
-
const tmp = `${this.filePath}.${process.pid}.tmp`;
|
|
45152
|
-
await fs.writeFile(tmp, JSON.stringify(file, null, 2), "utf8");
|
|
45153
|
-
await fs.rename(tmp, this.filePath);
|
|
45116
|
+
set(_pubkey, _pointer) {
|
|
45117
|
+
return Promise.reject(new Error("PointerStore.set is not available in the browser bundle"));
|
|
45154
45118
|
}
|
|
45155
45119
|
};
|
|
45156
|
-
function defaultPointerPath(
|
|
45157
|
-
return
|
|
45120
|
+
function defaultPointerPath(_workspaceDir) {
|
|
45121
|
+
return unavailable("defaultPointerPath");
|
|
45158
45122
|
}
|
|
45159
45123
|
|
|
45160
|
-
// src-ts/memory
|
|
45161
|
-
|
|
45162
|
-
|
|
45163
|
-
|
|
45164
|
-
|
|
45165
|
-
|
|
45166
|
-
return " " + JSON.stringify(meta);
|
|
45167
|
-
} catch {
|
|
45168
|
-
return "";
|
|
45169
|
-
}
|
|
45170
|
-
}
|
|
45171
|
-
function createFileLogger(filePath, upstream) {
|
|
45172
|
-
let queue = Promise.resolve();
|
|
45173
|
-
async function ensureDir() {
|
|
45174
|
-
await fs2.mkdir(path4.dirname(filePath), { recursive: true });
|
|
45175
|
-
}
|
|
45176
|
-
function append(level, message, meta) {
|
|
45177
|
-
const line = `${(/* @__PURE__ */ new Date()).toISOString()} [${level}] ${message}${formatMeta(meta)}
|
|
45178
|
-
`;
|
|
45179
|
-
queue = queue.then(ensureDir).then(() => fs2.appendFile(filePath, line, "utf8")).catch(() => {
|
|
45180
|
-
});
|
|
45181
|
-
}
|
|
45182
|
-
return {
|
|
45183
|
-
info(message, meta) {
|
|
45184
|
-
upstream?.info(message, meta ?? {});
|
|
45185
|
-
append("info", message, meta);
|
|
45186
|
-
},
|
|
45187
|
-
warn(message, meta) {
|
|
45188
|
-
upstream?.warn(message, meta ?? {});
|
|
45189
|
-
append("warn", message, meta);
|
|
45190
|
-
}
|
|
45191
|
-
};
|
|
45124
|
+
// src-ts/browser/memory-file-logger.ts
|
|
45125
|
+
var unavailable2 = (name2) => {
|
|
45126
|
+
throw new Error(`${name2} is not available in the browser bundle`);
|
|
45127
|
+
};
|
|
45128
|
+
function createFileLogger(_logFilePath, _hostLogger) {
|
|
45129
|
+
return unavailable2("createFileLogger");
|
|
45192
45130
|
}
|
|
45193
|
-
function defaultPluginLogPath(
|
|
45194
|
-
return
|
|
45131
|
+
function defaultPluginLogPath(_workspaceDir) {
|
|
45132
|
+
return unavailable2("defaultPluginLogPath");
|
|
45195
45133
|
}
|
|
45196
45134
|
|
|
45197
45135
|
// src-ts/memory/read-classifier.ts
|
|
@@ -45218,8 +45156,8 @@ function extractPath(event, ctx) {
|
|
|
45218
45156
|
}
|
|
45219
45157
|
return "";
|
|
45220
45158
|
}
|
|
45221
|
-
function matchesMemoryPath2(
|
|
45222
|
-
const p =
|
|
45159
|
+
function matchesMemoryPath2(path3, patterns) {
|
|
45160
|
+
const p = path3.toLowerCase();
|
|
45223
45161
|
for (const pat of patterns) {
|
|
45224
45162
|
if (pat && p.includes(pat.toLowerCase())) return true;
|
|
45225
45163
|
}
|
|
@@ -45236,183 +45174,36 @@ function classifyMemoryRead(event, ctx, opts = {}) {
|
|
|
45236
45174
|
(opts.genericReadToolNames ?? DEFAULT_READ_TOOL_NAMES).map((s2) => s2.toLowerCase())
|
|
45237
45175
|
);
|
|
45238
45176
|
if (genericReadTools.has(toolName)) {
|
|
45239
|
-
const
|
|
45240
|
-
if (!
|
|
45177
|
+
const path3 = extractPath(event, ctx);
|
|
45178
|
+
if (!path3) return false;
|
|
45241
45179
|
const patterns = opts.patterns ? [...DEFAULT_MEMORY_PATH_PATTERNS, ...opts.patterns] : DEFAULT_MEMORY_PATH_PATTERNS;
|
|
45242
|
-
return matchesMemoryPath2(
|
|
45180
|
+
return matchesMemoryPath2(path3, patterns);
|
|
45243
45181
|
}
|
|
45244
45182
|
return false;
|
|
45245
45183
|
}
|
|
45246
45184
|
|
|
45247
|
-
// src-ts/memory
|
|
45248
|
-
|
|
45249
|
-
|
|
45250
|
-
|
|
45185
|
+
// src-ts/browser/memory-guard-manager.ts
|
|
45186
|
+
var unavailable3 = (name2) => {
|
|
45187
|
+
throw new Error(`${name2} is not available in the browser bundle`);
|
|
45188
|
+
};
|
|
45251
45189
|
var MemoryGuardManager = class {
|
|
45252
|
-
constructor(
|
|
45253
|
-
this.opts = opts;
|
|
45254
|
-
const workspaceDir = opts.workspaceDir;
|
|
45255
|
-
this.memoryFilePath = opts.memoryFilePath ?? path5.join(workspaceDir, "MEMORY.md");
|
|
45256
|
-
this.pointerStore = new PointerStore(opts.pointerFilePath ?? defaultPointerPath(workspaceDir));
|
|
45257
|
-
this.logger = createFileLogger(
|
|
45258
|
-
opts.logFilePath ?? defaultPluginLogPath(workspaceDir),
|
|
45259
|
-
opts.hostLogger
|
|
45260
|
-
);
|
|
45261
|
-
this.ttlMs = opts.ttlMs ?? DEFAULT_SYNC_TTL_MS;
|
|
45262
|
-
this.rollbackMinScore = opts.rollbackMinScore ?? 1;
|
|
45263
|
-
this.enforce = opts.enforce !== false;
|
|
45264
|
-
this.agentPubkeyHex = opts.auth.pubkey;
|
|
45265
|
-
this.logger.info(
|
|
45266
|
-
`[atbash] guard manager ready \u2014 agent=${this.agentPubkeyHex.slice(0, 16)}\u2026 org=${opts.orgName ?? "(none)"} memoryFilePath=${this.memoryFilePath} ttl=${this.ttlMs}ms minScore=${this.rollbackMinScore}`
|
|
45267
|
-
);
|
|
45268
|
-
}
|
|
45269
|
-
opts;
|
|
45270
|
-
pointerStore;
|
|
45271
|
-
logger;
|
|
45272
|
-
memoryFilePath;
|
|
45273
|
-
ttlMs;
|
|
45274
|
-
rollbackMinScore;
|
|
45275
|
-
enforce;
|
|
45276
|
-
agentPubkeyHex;
|
|
45277
|
-
/**
|
|
45278
|
-
* One-shot chain probe at plugin registration. Refreshes MEMORY.md
|
|
45279
|
-
* from chain when drifted and score passes threshold. Fire-and-forget
|
|
45280
|
-
* — errors are logged, never thrown.
|
|
45281
|
-
*/
|
|
45282
|
-
async runBootProbe() {
|
|
45283
|
-
try {
|
|
45284
|
-
const seed = { activeId: null, checkedAt: 0 };
|
|
45285
|
-
const result = await syncLocalMemory(this.opts.auth, seed, { ttlMs: 0, force: true });
|
|
45286
|
-
if (!result.drifted && result.pointer.activeId == null) {
|
|
45287
|
-
this.logger.info(
|
|
45288
|
-
`[atbash] no active memory on chain for agent=${this.agentPubkeyHex.slice(0, 16)}\u2026 org=${this.opts.orgName ?? "(none)"} \u2014 either the agent isn't registered on this chain or hasn't written any memory. Sync will remain a no-op until a write lands.`
|
|
45289
|
-
);
|
|
45290
|
-
} else if (result.drifted && result.current) {
|
|
45291
|
-
if (result.current.score < this.rollbackMinScore) {
|
|
45292
|
-
this.logger.warn(
|
|
45293
|
-
`[atbash] boot sync REFUSED refresh \u2014 id=${result.current.id} score=${result.current.score} below threshold ${this.rollbackMinScore}. Leaving MEMORY.md and pointer untouched; next memory read will be blocked.`
|
|
45294
|
-
);
|
|
45295
|
-
return;
|
|
45296
|
-
}
|
|
45297
|
-
this.logger.info(
|
|
45298
|
-
`[atbash] boot sync: refreshing local memory \u2014 id=${result.current.id} score=${result.current.score}`
|
|
45299
|
-
);
|
|
45300
|
-
try {
|
|
45301
|
-
await this.writeMemoryAtomic(result.current.content);
|
|
45302
|
-
} catch (err) {
|
|
45303
|
-
const msg = err instanceof Error ? err.message : String(err);
|
|
45304
|
-
this.logger.warn("[atbash] boot sync write failed (serving whatever's on disk)", { error: msg });
|
|
45305
|
-
}
|
|
45306
|
-
}
|
|
45307
|
-
await this.pointerStore.set(this.agentPubkeyHex, result.pointer);
|
|
45308
|
-
} catch (err) {
|
|
45309
|
-
const msg = err instanceof Error ? err.message : String(err);
|
|
45310
|
-
this.logger.warn("[atbash] boot memory sync failed \u2014 check chain endpoint / orgName", { error: msg });
|
|
45311
|
-
}
|
|
45190
|
+
constructor(_opts) {
|
|
45312
45191
|
}
|
|
45313
|
-
|
|
45314
|
-
|
|
45315
|
-
|
|
45316
|
-
* event isn't memory-related — host falls through to its own audit.
|
|
45317
|
-
*/
|
|
45318
|
-
async handleBeforeToolCall(event, ctx) {
|
|
45319
|
-
if (classifyMemoryRead(event, ctx, this.opts.memoryReadClassifier)) {
|
|
45320
|
-
this.logger.info("[atbash] memory read intercepted \u2014 running sync check");
|
|
45321
|
-
const readDecision = await this.handleMemoryRead();
|
|
45322
|
-
return readDecision ?? { allow: true };
|
|
45323
|
-
}
|
|
45324
|
-
const guardLogger = {
|
|
45325
|
-
info: (msg, meta) => this.logger.info(msg, meta && typeof meta === "object" ? meta : void 0),
|
|
45326
|
-
warn: (msg, meta) => this.logger.warn(msg, meta && typeof meta === "object" ? meta : void 0)
|
|
45327
|
-
};
|
|
45328
|
-
const guard = await guardMemoryWrite({
|
|
45329
|
-
event,
|
|
45330
|
-
ctx,
|
|
45331
|
-
auth: this.opts.auth,
|
|
45332
|
-
endpoint: this.opts.judgeEndpoint,
|
|
45333
|
-
verifyPubKey: this.opts.judgeVerifyPubKey,
|
|
45334
|
-
orgName: this.opts.orgName,
|
|
45335
|
-
patterns: this.opts.memoryPathPatterns,
|
|
45336
|
-
toolNames: this.opts.memoryWriteToolNames,
|
|
45337
|
-
enforce: this.enforce,
|
|
45338
|
-
debug: this.opts.debug,
|
|
45339
|
-
logger: guardLogger
|
|
45340
|
-
});
|
|
45341
|
-
return this.mapGuardResult(guard);
|
|
45342
|
-
}
|
|
45343
|
-
mapGuardResult(guard) {
|
|
45344
|
-
if (!guard.handled) return null;
|
|
45345
|
-
const d = guard.decision;
|
|
45346
|
-
const sr2 = guard.scanResult;
|
|
45347
|
-
const verdict = sr2?.verdict ?? "?";
|
|
45348
|
-
const score = sr2?.score ?? "?";
|
|
45349
|
-
if (d.block) {
|
|
45350
|
-
this.logger.warn(
|
|
45351
|
-
`[atbash] guardMemoryWrite BLOCKED \u2014 verdict=${verdict} score=${score} reason=${(d.reason ?? "").slice(0, 200)}`
|
|
45352
|
-
);
|
|
45353
|
-
return {
|
|
45354
|
-
block: true,
|
|
45355
|
-
blockReason: d.reason ?? "",
|
|
45356
|
-
allow: false,
|
|
45357
|
-
reason: d.reason
|
|
45358
|
-
};
|
|
45359
|
-
}
|
|
45360
|
-
this.logger.info(
|
|
45361
|
-
`[atbash] guardMemoryWrite ALLOWED \u2014 verdict=${verdict} score=${score} committed=${guard.committed === true}`
|
|
45192
|
+
runBootProbe() {
|
|
45193
|
+
return Promise.reject(
|
|
45194
|
+
new Error("MemoryGuardManager.runBootProbe is not available in the browser bundle")
|
|
45362
45195
|
);
|
|
45363
|
-
return { allow: true };
|
|
45364
45196
|
}
|
|
45365
|
-
|
|
45366
|
-
|
|
45367
|
-
|
|
45368
|
-
|
|
45369
|
-
|
|
45370
|
-
|
|
45371
|
-
if (err instanceof MemoryIntegrityError) {
|
|
45372
|
-
const reason = `Memory integrity check failed on id ${err.id} \u2014 read blocked.`;
|
|
45373
|
-
this.logger.warn("[atbash] MEMORY INTEGRITY FAILURE", { id: err.id, error: err.message });
|
|
45374
|
-
if (!this.enforce) return null;
|
|
45375
|
-
return { block: true, blockReason: reason, allow: false, reason };
|
|
45376
|
-
}
|
|
45377
|
-
const msg = err instanceof Error ? err.message : String(err);
|
|
45378
|
-
this.logger.warn("[atbash] memory sync failed (serving local copy)", { error: msg });
|
|
45379
|
-
return null;
|
|
45380
|
-
}
|
|
45381
|
-
if (result.drifted) {
|
|
45382
|
-
const fresh = result.current;
|
|
45383
|
-
if (fresh) {
|
|
45384
|
-
if (fresh.score < this.rollbackMinScore) {
|
|
45385
|
-
const reason = `Rolled-back memory version #${fresh.id} scored ${fresh.score} (below threshold ${this.rollbackMinScore}) \u2014 read blocked.`;
|
|
45386
|
-
this.logger.warn("[atbash] blocking read on low-score rollback", { id: fresh.id, score: fresh.score });
|
|
45387
|
-
if (!this.enforce) return null;
|
|
45388
|
-
return { block: true, blockReason: reason, allow: false, reason };
|
|
45389
|
-
}
|
|
45390
|
-
this.logger.info("[atbash] memory drift detected \u2014 refreshing local file", {
|
|
45391
|
-
id: fresh.id,
|
|
45392
|
-
score: fresh.score
|
|
45393
|
-
});
|
|
45394
|
-
try {
|
|
45395
|
-
await this.writeMemoryAtomic(fresh.content);
|
|
45396
|
-
} catch (err) {
|
|
45397
|
-
const msg = err instanceof Error ? err.message : String(err);
|
|
45398
|
-
this.logger.warn("[atbash] failed to write refreshed memory (serving old)", { error: msg });
|
|
45399
|
-
}
|
|
45400
|
-
} else {
|
|
45401
|
-
this.logger.info("[atbash] active memory removed on chain", { pubkey: this.agentPubkeyHex });
|
|
45402
|
-
}
|
|
45403
|
-
}
|
|
45404
|
-
await this.pointerStore.set(this.agentPubkeyHex, result.pointer);
|
|
45405
|
-
return null;
|
|
45406
|
-
}
|
|
45407
|
-
async writeMemoryAtomic(content) {
|
|
45408
|
-
await fs3.mkdir(path5.dirname(this.memoryFilePath), { recursive: true });
|
|
45409
|
-
const tmp = `${this.memoryFilePath}.${process.pid}.tmp`;
|
|
45410
|
-
await fs3.writeFile(tmp, content, "utf8");
|
|
45411
|
-
await fs3.rename(tmp, this.memoryFilePath);
|
|
45197
|
+
handleBeforeToolCall(_event, _ctx) {
|
|
45198
|
+
return Promise.reject(
|
|
45199
|
+
new Error(
|
|
45200
|
+
"MemoryGuardManager.handleBeforeToolCall is not available in the browser bundle"
|
|
45201
|
+
)
|
|
45202
|
+
);
|
|
45412
45203
|
}
|
|
45413
45204
|
};
|
|
45414
|
-
function createMemoryGuardManager(
|
|
45415
|
-
return
|
|
45205
|
+
function createMemoryGuardManager(_opts) {
|
|
45206
|
+
return unavailable3("createMemoryGuardManager");
|
|
45416
45207
|
}
|
|
45417
45208
|
|
|
45418
45209
|
// src-ts/index.ts
|