@kenz1117/dsh-engram 0.9.5 → 0.9.6
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/lib/client.js +1 -1
- package/lib/index.js +49 -41
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -340,6 +340,9 @@ const zh$2 = {
|
|
|
340
340
|
"misc.exportRecordLine": "- [{status}/{kind}] {content}(id={id},importance {importance})",
|
|
341
341
|
"misc.exportEdgesHeading": "## 关系边",
|
|
342
342
|
"misc.importInvalidPayload": "导入文件结构有误:{error}",
|
|
343
|
+
"misc.bodyTooLarge": "请求体过大:超过 {limit} 上限。",
|
|
344
|
+
"misc.bodyMalformed": "请求体不是合法 JSON:{error}",
|
|
345
|
+
"misc.bodyNotObject": "请求体必须是 JSON 对象。",
|
|
343
346
|
"misc.importBodyTooLarge": "导入文件过大:超过 {limit} 上限。请拆分导出文件后重试,或改用 engram_import 工具按文件路径导入。",
|
|
344
347
|
"misc.importBodyMalformed": "导入请求体不是合法 JSON:{error}",
|
|
345
348
|
"misc.importBodyNotObject": "导入请求体必须是 JSON 对象。",
|
|
@@ -387,6 +390,9 @@ const en$2 = {
|
|
|
387
390
|
"misc.exportRecordLine": "- [{status}/{kind}] {content} (id={id}, importance {importance})",
|
|
388
391
|
"misc.exportEdgesHeading": "## Relation edges",
|
|
389
392
|
"misc.importInvalidPayload": "import file structure is invalid: {error}",
|
|
393
|
+
"misc.bodyTooLarge": "request body is too large: over the {limit} limit.",
|
|
394
|
+
"misc.bodyMalformed": "request body is not valid JSON: {error}",
|
|
395
|
+
"misc.bodyNotObject": "request body must be a JSON object.",
|
|
390
396
|
"misc.importBodyTooLarge": "import file is too large: over the {limit} limit. Split the export and retry, or use the engram_import tool with a file path.",
|
|
391
397
|
"misc.importBodyMalformed": "import request body is not valid JSON: {error}",
|
|
392
398
|
"misc.importBodyNotObject": "import request body must be a JSON object.",
|
|
@@ -434,6 +440,9 @@ const ru$2 = {
|
|
|
434
440
|
"misc.exportRecordLine": "- [{status}/{kind}] {content} (id={id}, importance {importance})",
|
|
435
441
|
"misc.exportEdgesHeading": "## Связи",
|
|
436
442
|
"misc.importInvalidPayload": "структура файла импорта некорректна: {error}",
|
|
443
|
+
"misc.bodyTooLarge": "тело запроса слишком большое: превышен предел {limit}.",
|
|
444
|
+
"misc.bodyMalformed": "тело запроса — не корректный JSON: {error}",
|
|
445
|
+
"misc.bodyNotObject": "тело запроса должно быть JSON-объектом.",
|
|
437
446
|
"misc.importBodyTooLarge": "файл импорта слишком большой: превышен предел {limit}. Разделите экспорт и повторите либо используйте инструмент engram_import с путём к файлу.",
|
|
438
447
|
"misc.importBodyMalformed": "тело запроса импорта — не корректный JSON: {error}",
|
|
439
448
|
"misc.importBodyNotObject": "тело запроса импорта должно быть JSON-объектом.",
|
|
@@ -4348,17 +4357,6 @@ async function readJsonBody(req, limit = BODY_LIMIT_BYTES) {
|
|
|
4348
4357
|
body: parsed
|
|
4349
4358
|
};
|
|
4350
4359
|
}
|
|
4351
|
-
/**
|
|
4352
|
-
* 读取 JSON body 并宽容降级:坏 body 视为空对象。
|
|
4353
|
-
*
|
|
4354
|
-
* 给「body 整体可选」的普通写接口用(补做、配置、复习等)——它们的 body 都是
|
|
4355
|
-
* 小结构,坏 body 落到字段校验上照样 400,不需要区分原因。要区分原因的路由
|
|
4356
|
-
* (导入)自己用 {@link readJsonBody}。
|
|
4357
|
-
*/
|
|
4358
|
-
async function readJsonBodyOrEmpty(req, limit = BODY_LIMIT_BYTES) {
|
|
4359
|
-
const result = await readJsonBody(req, limit);
|
|
4360
|
-
return result.ok ? result.body : {};
|
|
4361
|
-
}
|
|
4362
4360
|
//#endregion
|
|
4363
4361
|
//#region src/jev/client.ts
|
|
4364
4362
|
/**
|
|
@@ -5643,6 +5641,29 @@ function json(res, status, body) {
|
|
|
5643
5641
|
res.writeHead(status, { "content-type": "application/json; charset=utf-8" });
|
|
5644
5642
|
res.end(JSON.stringify(body));
|
|
5645
5643
|
}
|
|
5644
|
+
/**
|
|
5645
|
+
* 读 JSON body,并把失败原因说清楚:超限 413、坏 JSON 400、不是对象 400。
|
|
5646
|
+
*
|
|
5647
|
+
* 为什么不给「宽容降级成空对象」:那样超限/坏 body 会掉进字段校验,报成
|
|
5648
|
+
* 「id required」「archivePath required」——把服务端的锅甩给调用方(#34 的同款毛病)。
|
|
5649
|
+
* 机器已经能分辨三种原因,就别再合成一句话。
|
|
5650
|
+
*
|
|
5651
|
+
* @returns body;返回 null = 已写好错误响应,调用方直接 return。
|
|
5652
|
+
*/
|
|
5653
|
+
async function readBody(req, res, language) {
|
|
5654
|
+
const result = await readJsonBody(req);
|
|
5655
|
+
if (result.ok) return result.body;
|
|
5656
|
+
if (result.reason === "too-large") {
|
|
5657
|
+
json(res, 413, { error: messageIn(language, "misc.bodyTooLarge", { limit: formatBytes(result.limit) }) });
|
|
5658
|
+
return null;
|
|
5659
|
+
}
|
|
5660
|
+
if (result.reason === "malformed") {
|
|
5661
|
+
json(res, 400, { error: messageIn(language, "misc.bodyMalformed", { error: result.error }) });
|
|
5662
|
+
return null;
|
|
5663
|
+
}
|
|
5664
|
+
json(res, 400, { error: messageIn(language, "misc.bodyNotObject") });
|
|
5665
|
+
return null;
|
|
5666
|
+
}
|
|
5646
5667
|
/** 从 URL searchParams 收敛 scope(缺省 user)。 */
|
|
5647
5668
|
function scopeOf$1(raw, fallback) {
|
|
5648
5669
|
if (raw === "user" || raw === "project" || raw === "shared") return raw;
|
|
@@ -5987,7 +6008,8 @@ function registerEngramRoutes(ctx, deps) {
|
|
|
5987
6008
|
}
|
|
5988
6009
|
if (req.method === "POST" && route === "review-answer") {
|
|
5989
6010
|
if (!guardWrite(req, res)) return;
|
|
5990
|
-
const body = await
|
|
6011
|
+
const body = await readBody(req, res, deps.language);
|
|
6012
|
+
if (body === null) return;
|
|
5991
6013
|
if (typeof body.id !== "string" || body.id === "") {
|
|
5992
6014
|
json(res, 400, { error: "id required" });
|
|
5993
6015
|
return;
|
|
@@ -6050,27 +6072,6 @@ function registerEngramRoutes(ctx, deps) {
|
|
|
6050
6072
|
});
|
|
6051
6073
|
return;
|
|
6052
6074
|
}
|
|
6053
|
-
if (req.method === "POST" && route === "review-answer") {
|
|
6054
|
-
if (!guardWrite(req, res)) return;
|
|
6055
|
-
const body = await readJsonBodyOrEmpty(req);
|
|
6056
|
-
if (typeof body.id !== "string" || body.id === "") {
|
|
6057
|
-
json(res, 400, { error: "id required" });
|
|
6058
|
-
return;
|
|
6059
|
-
}
|
|
6060
|
-
const grade = Number(body.grade);
|
|
6061
|
-
if (!Number.isInteger(grade) || grade < 0 || grade > 5) {
|
|
6062
|
-
json(res, 400, { error: "grade must be an integer 0-5" });
|
|
6063
|
-
return;
|
|
6064
|
-
}
|
|
6065
|
-
adoptBodySelector(body);
|
|
6066
|
-
const record = await (await storeFor(scopeOf$1(typeof body.scope === "string" ? body.scope : null, "user"))).scheduleReview(body.id, grade);
|
|
6067
|
-
if (record === void 0) {
|
|
6068
|
-
json(res, 404, { error: messageIn(deps.language, "misc.recordNotFound", { id: body.id }) });
|
|
6069
|
-
return;
|
|
6070
|
-
}
|
|
6071
|
-
json(res, 200, { record });
|
|
6072
|
-
return;
|
|
6073
|
-
}
|
|
6074
6075
|
if (req.method === "GET" && route === "export") {
|
|
6075
6076
|
const scope = scopeOf$1(url.searchParams.get("scope"), "user");
|
|
6076
6077
|
const format = url.searchParams.get("format") === "json" ? "json" : "markdown";
|
|
@@ -6345,7 +6346,8 @@ function registerEngramRoutes(ctx, deps) {
|
|
|
6345
6346
|
}
|
|
6346
6347
|
if (req.method === "POST" && route === "history-backfill/start") {
|
|
6347
6348
|
if (!guardWrite(req, res)) return;
|
|
6348
|
-
const body = await
|
|
6349
|
+
const body = await readBody(req, res, deps.language);
|
|
6350
|
+
if (body === null) return;
|
|
6349
6351
|
const started = deps.history.start(historyRulesOf(body));
|
|
6350
6352
|
if (!started.ok) {
|
|
6351
6353
|
json(res, 409, {
|
|
@@ -6379,7 +6381,8 @@ function registerEngramRoutes(ctx, deps) {
|
|
|
6379
6381
|
}
|
|
6380
6382
|
if (req.method === "POST" && route === "jev-config") {
|
|
6381
6383
|
if (!guardWrite(req, res)) return;
|
|
6382
|
-
const body = await
|
|
6384
|
+
const body = await readBody(req, res, deps.language);
|
|
6385
|
+
if (body === null) return;
|
|
6383
6386
|
const parsed = parseJevPatch(loadJevOverride(deps.jev.dbDir), body);
|
|
6384
6387
|
if (typeof parsed === "string") {
|
|
6385
6388
|
json(res, 400, { error: parsed });
|
|
@@ -6398,7 +6401,8 @@ function registerEngramRoutes(ctx, deps) {
|
|
|
6398
6401
|
}
|
|
6399
6402
|
if (req.method === "POST" && route === "jev-test") {
|
|
6400
6403
|
if (!guardWrite(req, res)) return;
|
|
6401
|
-
const body = await
|
|
6404
|
+
const body = await readBody(req, res, deps.language);
|
|
6405
|
+
if (body === null) return;
|
|
6402
6406
|
const base = effectiveJevConfig(deps.jev.base, loadJevOverride(deps.jev.dbDir));
|
|
6403
6407
|
const provider = typeof body.provider === "string" && body.provider.trim() !== "" ? body.provider.trim() : base.provider;
|
|
6404
6408
|
const model = typeof body.model === "string" && body.model.trim() !== "" ? body.model.trim() : base.model;
|
|
@@ -6427,7 +6431,8 @@ function registerEngramRoutes(ctx, deps) {
|
|
|
6427
6431
|
}
|
|
6428
6432
|
if (req.method === "POST" && route === "jev-models") {
|
|
6429
6433
|
if (!guardWrite(req, res)) return;
|
|
6430
|
-
const body = await
|
|
6434
|
+
const body = await readBody(req, res, deps.language);
|
|
6435
|
+
if (body === null) return;
|
|
6431
6436
|
const provider = typeof body.provider === "string" ? body.provider.trim() : "";
|
|
6432
6437
|
if (provider === "") {
|
|
6433
6438
|
json(res, 200, {
|
|
@@ -6446,7 +6451,8 @@ function registerEngramRoutes(ctx, deps) {
|
|
|
6446
6451
|
}
|
|
6447
6452
|
if (req.method === "POST" && route === "consolidate") {
|
|
6448
6453
|
if (!guardWrite(req, res)) return;
|
|
6449
|
-
const body = await
|
|
6454
|
+
const body = await readBody(req, res, deps.language);
|
|
6455
|
+
if (body === null) return;
|
|
6450
6456
|
adoptBodySelector(body);
|
|
6451
6457
|
const rawScope = typeof body.scope === "string" ? body.scope : "user";
|
|
6452
6458
|
const scope = rawScope === "project" ? "project" : rawScope === "shared" ? "shared" : "user";
|
|
@@ -6470,7 +6476,8 @@ function registerEngramRoutes(ctx, deps) {
|
|
|
6470
6476
|
}
|
|
6471
6477
|
if (req.method === "POST" && route === "restore-backup") {
|
|
6472
6478
|
if (!guardWrite(req, res)) return;
|
|
6473
|
-
const body = await
|
|
6479
|
+
const body = await readBody(req, res, deps.language);
|
|
6480
|
+
if (body === null) return;
|
|
6474
6481
|
if (typeof body.archivePath !== "string" || body.archivePath === "") {
|
|
6475
6482
|
json(res, 400, { error: "archivePath required" });
|
|
6476
6483
|
return;
|
|
@@ -6496,7 +6503,8 @@ function registerEngramRoutes(ctx, deps) {
|
|
|
6496
6503
|
}
|
|
6497
6504
|
if (req.method === "POST" && (route === "update" || route === "forget" || route === "restore")) {
|
|
6498
6505
|
if (!guardWrite(req, res)) return;
|
|
6499
|
-
const body = await
|
|
6506
|
+
const body = await readBody(req, res, deps.language);
|
|
6507
|
+
if (body === null) return;
|
|
6500
6508
|
if (typeof body.id !== "string" || body.id === "") {
|
|
6501
6509
|
json(res, 400, { error: "id required" });
|
|
6502
6510
|
return;
|
|
@@ -11826,7 +11834,7 @@ function estimateTokens(text) {
|
|
|
11826
11834
|
}
|
|
11827
11835
|
//#endregion
|
|
11828
11836
|
//#region package.json
|
|
11829
|
-
var version = "0.9.
|
|
11837
|
+
var version = "0.9.6";
|
|
11830
11838
|
//#endregion
|
|
11831
11839
|
//#region src/index.ts
|
|
11832
11840
|
/**
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kenz1117/dsh-engram",
|
|
3
3
|
"description": "Cross-session long-term memory for DeepSeek Harness (memory palace · AGI Architecture Exploration on dsh-market): dual-scope SQLite memory graph, hybrid retrieval, provenance audit, and a knowledge flywheel.",
|
|
4
|
-
"version": "0.9.
|
|
4
|
+
"version": "0.9.6",
|
|
5
5
|
"icon": "icon.svg",
|
|
6
6
|
"logo": "icon-256.svg",
|
|
7
7
|
"publishConfig": {
|