@amemhq/core 2.1.1 → 2.1.2
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 +23 -23
- package/dist/{chunk-3HJV3LLV.js → chunk-Z7G7KOJK.js} +71 -38
- package/dist/chunk-Z7G7KOJK.js.map +1 -0
- package/dist/cli-migrate.cjs +28 -16
- package/dist/cli-migrate.cjs.map +1 -1
- package/dist/cli-migrate.js +1 -1
- package/dist/index.cjs +58 -25
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -1
- package/package.json +2 -2
- package/dist/chunk-3HJV3LLV.js.map +0 -1
package/dist/cli-migrate.cjs
CHANGED
|
@@ -37,6 +37,15 @@ __export(cli_migrate_exports, {
|
|
|
37
37
|
});
|
|
38
38
|
module.exports = __toCommonJS(cli_migrate_exports);
|
|
39
39
|
|
|
40
|
+
// src/config.ts
|
|
41
|
+
var os = __toESM(require("os"), 1);
|
|
42
|
+
var path = __toESM(require("path"), 1);
|
|
43
|
+
var _dataDir = process.env.AMEM_DATA_DIR || path.join(os.homedir(), ".amem");
|
|
44
|
+
var _warn = (msg) => console.warn(msg);
|
|
45
|
+
function warn(msg) {
|
|
46
|
+
_warn(msg);
|
|
47
|
+
}
|
|
48
|
+
|
|
40
49
|
// src/embedding.ts
|
|
41
50
|
var pipeline = null;
|
|
42
51
|
var extractor = null;
|
|
@@ -81,6 +90,12 @@ function applyModelPaths(env) {
|
|
|
81
90
|
env.allowLocalModels = true;
|
|
82
91
|
}
|
|
83
92
|
}
|
|
93
|
+
function humanBytes(n) {
|
|
94
|
+
if (n >= 1e9) return `${(n / 1e9).toFixed(2)} GB`;
|
|
95
|
+
if (n >= 1e6) return `${(n / 1e6).toFixed(1)} MB`;
|
|
96
|
+
if (n >= 1e3) return `${Math.round(n / 1e3)} kB`;
|
|
97
|
+
return `${n} B`;
|
|
98
|
+
}
|
|
84
99
|
function makeProgressReporter() {
|
|
85
100
|
const lastPct = /* @__PURE__ */ new Map();
|
|
86
101
|
return (e) => {
|
|
@@ -89,7 +104,7 @@ function makeProgressReporter() {
|
|
|
89
104
|
const pct = Math.floor(e.progress / 10) * 10;
|
|
90
105
|
if (lastPct.get(e.file) === pct) return;
|
|
91
106
|
lastPct.set(e.file, pct);
|
|
92
|
-
const size = e.total ? ` of ${(e.total
|
|
107
|
+
const size = e.total ? ` of ${humanBytes(e.total)}` : "";
|
|
93
108
|
console.log(`[amem] downloading ${e.file}: ${pct}%${size}`);
|
|
94
109
|
};
|
|
95
110
|
}
|
|
@@ -615,7 +630,7 @@ var _warned = /* @__PURE__ */ new Set();
|
|
|
615
630
|
function warnOnce(key, message) {
|
|
616
631
|
if (_warned.has(key)) return;
|
|
617
632
|
_warned.add(key);
|
|
618
|
-
|
|
633
|
+
warn(message);
|
|
619
634
|
}
|
|
620
635
|
function resolveProvider(role = "fast") {
|
|
621
636
|
const raw = role === "strong" ? process.env.AMEM_LLM_STRONG_PROVIDER || _override.strong?.provider || void 0 : void 0;
|
|
@@ -679,9 +694,11 @@ async function llmCall(prompt, maxTokens = 500, role = "fast") {
|
|
|
679
694
|
const isThinking = model.includes("gemini") || model.includes("pro-agent");
|
|
680
695
|
const effectiveMaxTokens = isThinking ? Math.max(maxTokens * 8, 4e3) : maxTokens;
|
|
681
696
|
try {
|
|
682
|
-
|
|
697
|
+
const text = provider === "openai" ? await openaiCall(prompt, model, effectiveMaxTokens, baseURL) : await anthropicCall(prompt, model, effectiveMaxTokens, baseURL);
|
|
698
|
+
if (text === null) warn(`[amem] ${provider} answered with no text (model ${model})`);
|
|
699
|
+
return text;
|
|
683
700
|
} catch (e) {
|
|
684
|
-
|
|
701
|
+
warn(`[amem] LLM call failed: ${e.message}`);
|
|
685
702
|
return null;
|
|
686
703
|
}
|
|
687
704
|
}
|
|
@@ -780,7 +797,8 @@ confidence guide (Story 27):
|
|
|
780
797
|
|
|
781
798
|
Text: ${content}`;
|
|
782
799
|
const raw = await llmCall(prompt, 400);
|
|
783
|
-
if (!raw)
|
|
800
|
+
if (!raw) {
|
|
801
|
+
warn("[amem] note construction got nothing back; storing with no keywords, tags or context");
|
|
784
802
|
return {
|
|
785
803
|
keywords: [],
|
|
786
804
|
tags: [],
|
|
@@ -790,6 +808,7 @@ Text: ${content}`;
|
|
|
790
808
|
topics: [],
|
|
791
809
|
confidence: "medium"
|
|
792
810
|
};
|
|
811
|
+
}
|
|
793
812
|
try {
|
|
794
813
|
const data = parseJsonLoose(raw);
|
|
795
814
|
const rawCategory = typeof data.category === "string" ? data.category : "General";
|
|
@@ -808,7 +827,7 @@ Text: ${content}`;
|
|
|
808
827
|
confidence
|
|
809
828
|
};
|
|
810
829
|
} catch (e) {
|
|
811
|
-
|
|
830
|
+
warn(`[amem] Note construction parse failed: ${e.message}`);
|
|
812
831
|
return {
|
|
813
832
|
keywords: [],
|
|
814
833
|
tags: [],
|
|
@@ -823,13 +842,6 @@ Text: ${content}`;
|
|
|
823
842
|
|
|
824
843
|
// src/memory.ts
|
|
825
844
|
var import_uuid = require("uuid");
|
|
826
|
-
|
|
827
|
-
// src/config.ts
|
|
828
|
-
var os = __toESM(require("os"), 1);
|
|
829
|
-
var path = __toESM(require("path"), 1);
|
|
830
|
-
var _dataDir = process.env.AMEM_DATA_DIR || path.join(os.homedir(), ".amem");
|
|
831
|
-
|
|
832
|
-
// src/memory.ts
|
|
833
845
|
var import_jieba = require("@node-rs/jieba");
|
|
834
846
|
function buildEmbedText(note) {
|
|
835
847
|
let text = note.content;
|
|
@@ -848,7 +860,7 @@ async function migrateCollection(opts) {
|
|
|
848
860
|
const refreshFields = opts.refreshFields !== false;
|
|
849
861
|
const dryRun = opts.dryRun !== false;
|
|
850
862
|
const log = opts.logger?.info ?? ((m) => console.log(m));
|
|
851
|
-
const
|
|
863
|
+
const warn2 = opts.logger?.warn ?? warn;
|
|
852
864
|
if (from === to) throw new Error(`migrate: source and target are the same collection ("${from}")`);
|
|
853
865
|
const model = getEmbeddingModel();
|
|
854
866
|
const targetDim = await getEmbeddingDim();
|
|
@@ -916,7 +928,7 @@ async function migrateCollection(opts) {
|
|
|
916
928
|
if (!note.context) note.context = built.context;
|
|
917
929
|
refreshed++;
|
|
918
930
|
} catch (e) {
|
|
919
|
-
|
|
931
|
+
warn2(`[migrate] re-extract failed for ${note.id.slice(0, 8)} \u2014 keeping as-is: ${e.message}`);
|
|
920
932
|
}
|
|
921
933
|
}
|
|
922
934
|
const point = noteToPoint({ ...note, embedding: await encode(buildEmbedText(note)) });
|
|
@@ -929,7 +941,7 @@ async function migrateCollection(opts) {
|
|
|
929
941
|
await flush();
|
|
930
942
|
const finalCount = await countPointsRaw(to);
|
|
931
943
|
if (finalCount !== notes.length) {
|
|
932
|
-
|
|
944
|
+
warn2(`[migrate] target holds ${finalCount} point(s) but the source had ${notes.length} \u2014 check before switching`);
|
|
933
945
|
}
|
|
934
946
|
log(`[migrate] done: ${migrated} written, ${alreadyDone.size} already present, ${refreshed} re-extracted.`);
|
|
935
947
|
return {
|