@mnemonic-ai/core 0.1.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/chunk-5Z46NSNR.js +228 -0
- package/dist/chunk-5Z46NSNR.js.map +1 -0
- package/dist/chunk-CZDK53NR.js +24 -0
- package/dist/chunk-CZDK53NR.js.map +1 -0
- package/dist/chunk-L7SCUMC3.js +53 -0
- package/dist/chunk-L7SCUMC3.js.map +1 -0
- package/dist/chunk-M3IZJTMM.js +474 -0
- package/dist/chunk-M3IZJTMM.js.map +1 -0
- package/dist/chunk-NA7L5FQN.js +1581 -0
- package/dist/chunk-NA7L5FQN.js.map +1 -0
- package/dist/chunk-OEEEWS2M.js +375 -0
- package/dist/chunk-OEEEWS2M.js.map +1 -0
- package/dist/chunk-YZW6DYUY.js +46 -0
- package/dist/chunk-YZW6DYUY.js.map +1 -0
- package/dist/cli/main.cjs +1827 -0
- package/dist/cli/main.cjs.map +1 -0
- package/dist/cli/main.d.cts +1 -0
- package/dist/cli/main.d.ts +1 -0
- package/dist/cli/main.js +84 -0
- package/dist/cli/main.js.map +1 -0
- package/dist/client-b2Xhkqdl.d.cts +409 -0
- package/dist/client-b2Xhkqdl.d.ts +409 -0
- package/dist/index.cjs +2547 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +309 -0
- package/dist/index.d.ts +309 -0
- package/dist/index.js +160 -0
- package/dist/index.js.map +1 -0
- package/dist/local-MYLINANE.js +7 -0
- package/dist/local-MYLINANE.js.map +1 -0
- package/dist/mcp/main.cjs +2775 -0
- package/dist/mcp/main.cjs.map +1 -0
- package/dist/mcp/main.d.cts +1 -0
- package/dist/mcp/main.d.ts +1 -0
- package/dist/mcp/main.js +31 -0
- package/dist/mcp/main.js.map +1 -0
- package/dist/mcp/server.cjs +2765 -0
- package/dist/mcp/server.cjs.map +1 -0
- package/dist/mcp/server.d.cts +23 -0
- package/dist/mcp/server.d.ts +23 -0
- package/dist/mcp/server.js +12 -0
- package/dist/mcp/server.js.map +1 -0
- package/dist/openai-GDIC3YVT.js +7 -0
- package/dist/openai-GDIC3YVT.js.map +1 -0
- package/dist/postgres-GQ6DZDBW.js +8 -0
- package/dist/postgres-GQ6DZDBW.js.map +1 -0
- package/package.json +117 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import {
|
|
2
|
+
buildEmbedder
|
|
3
|
+
} from "./chunk-CZDK53NR.js";
|
|
4
|
+
import {
|
|
5
|
+
BUILTIN_SALIENCE_SIGNALS,
|
|
6
|
+
BUILTIN_TIERS,
|
|
7
|
+
Mnemonic,
|
|
8
|
+
MnemonicConfig,
|
|
9
|
+
SQLiteStore,
|
|
10
|
+
SalienceSignal,
|
|
11
|
+
TRANSIENT_ERRORS,
|
|
12
|
+
applyTierChange,
|
|
13
|
+
assemble,
|
|
14
|
+
checkDemotions,
|
|
15
|
+
checkPromotions,
|
|
16
|
+
classify,
|
|
17
|
+
detectSalience,
|
|
18
|
+
findConsolidationCandidates,
|
|
19
|
+
findLinks,
|
|
20
|
+
formatContext,
|
|
21
|
+
mergeCluster,
|
|
22
|
+
registerStore,
|
|
23
|
+
score,
|
|
24
|
+
syncToAsync
|
|
25
|
+
} from "./chunk-NA7L5FQN.js";
|
|
26
|
+
import {
|
|
27
|
+
PostgresStore
|
|
28
|
+
} from "./chunk-M3IZJTMM.js";
|
|
29
|
+
import {
|
|
30
|
+
Memory,
|
|
31
|
+
MemoryTier,
|
|
32
|
+
bruteForceCosineSearch,
|
|
33
|
+
cosineSimilarity,
|
|
34
|
+
cosineSimilarityMatrix,
|
|
35
|
+
cosineSimilarityVector,
|
|
36
|
+
createEdge,
|
|
37
|
+
estimateTokens,
|
|
38
|
+
parseDuration
|
|
39
|
+
} from "./chunk-5Z46NSNR.js";
|
|
40
|
+
import {
|
|
41
|
+
OpenAIEmbedder
|
|
42
|
+
} from "./chunk-YZW6DYUY.js";
|
|
43
|
+
import {
|
|
44
|
+
LocalEmbedder
|
|
45
|
+
} from "./chunk-L7SCUMC3.js";
|
|
46
|
+
|
|
47
|
+
// src/adapters/raw.ts
|
|
48
|
+
async function recallAsPrompt(mnemonic, query, options) {
|
|
49
|
+
return mnemonic.recall(query, {
|
|
50
|
+
maxTokens: options?.maxTokens ?? 3e3,
|
|
51
|
+
header: options?.header ?? "Relevant context from memory:"
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// src/adapters/langchain.ts
|
|
56
|
+
async function createLangChainMemory(options) {
|
|
57
|
+
let BaseMemory;
|
|
58
|
+
let getInputValues;
|
|
59
|
+
let getOutputValues;
|
|
60
|
+
try {
|
|
61
|
+
const lcPath = "@langchain/core/memory";
|
|
62
|
+
const mod = await import(lcPath);
|
|
63
|
+
BaseMemory = mod.BaseMemory ?? mod.default?.BaseMemory;
|
|
64
|
+
getInputValues = mod.getInputValues ?? mod.default?.getInputValues;
|
|
65
|
+
getOutputValues = mod.getOutputValues ?? mod.default?.getOutputValues;
|
|
66
|
+
} catch (err) {
|
|
67
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
68
|
+
if (msg.includes("Cannot find") || msg.includes("MODULE_NOT_FOUND")) {
|
|
69
|
+
throw new Error(
|
|
70
|
+
"LangChain adapter requires '@langchain/core'. Install it with: npm install @langchain/core"
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
throw err;
|
|
74
|
+
}
|
|
75
|
+
const {
|
|
76
|
+
mnemonic,
|
|
77
|
+
memoryKey = "memory",
|
|
78
|
+
maxTokens = 3e3,
|
|
79
|
+
inputKey,
|
|
80
|
+
outputKey
|
|
81
|
+
} = options;
|
|
82
|
+
function extractString(record, helper, key) {
|
|
83
|
+
if (helper && key) {
|
|
84
|
+
try {
|
|
85
|
+
const vals = helper(record, key);
|
|
86
|
+
const v = vals[key];
|
|
87
|
+
return typeof v === "string" ? v : void 0;
|
|
88
|
+
} catch {
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
if (key && typeof record[key] === "string") return record[key];
|
|
92
|
+
return Object.values(record).find((v) => typeof v === "string");
|
|
93
|
+
}
|
|
94
|
+
class MnemonicLangChainMemory extends BaseMemory {
|
|
95
|
+
// BaseMemory v1.x requires `memoryKeys` (not `memoryVariables`)
|
|
96
|
+
get memoryKeys() {
|
|
97
|
+
return [memoryKey];
|
|
98
|
+
}
|
|
99
|
+
async loadMemoryVariables(inputs) {
|
|
100
|
+
const query = extractString(inputs, getInputValues, inputKey) ?? "";
|
|
101
|
+
const context = await mnemonic.recall(String(query), { maxTokens });
|
|
102
|
+
return { [memoryKey]: context };
|
|
103
|
+
}
|
|
104
|
+
async saveContext(inputs, outputs) {
|
|
105
|
+
const humanInput = extractString(inputs, getInputValues, inputKey);
|
|
106
|
+
if (humanInput) {
|
|
107
|
+
await mnemonic.add(String(humanInput), {
|
|
108
|
+
source: "langchain",
|
|
109
|
+
actor: "user"
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
const aiOutput = extractString(outputs, getOutputValues, outputKey);
|
|
113
|
+
if (aiOutput) {
|
|
114
|
+
await mnemonic.add(String(aiOutput), {
|
|
115
|
+
source: "langchain",
|
|
116
|
+
actor: "assistant"
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return new MnemonicLangChainMemory();
|
|
122
|
+
}
|
|
123
|
+
export {
|
|
124
|
+
BUILTIN_SALIENCE_SIGNALS,
|
|
125
|
+
BUILTIN_TIERS,
|
|
126
|
+
LocalEmbedder,
|
|
127
|
+
Memory,
|
|
128
|
+
MemoryTier,
|
|
129
|
+
Mnemonic,
|
|
130
|
+
MnemonicConfig,
|
|
131
|
+
OpenAIEmbedder,
|
|
132
|
+
PostgresStore,
|
|
133
|
+
SQLiteStore,
|
|
134
|
+
SalienceSignal,
|
|
135
|
+
TRANSIENT_ERRORS,
|
|
136
|
+
applyTierChange,
|
|
137
|
+
assemble,
|
|
138
|
+
bruteForceCosineSearch,
|
|
139
|
+
buildEmbedder,
|
|
140
|
+
checkDemotions,
|
|
141
|
+
checkPromotions,
|
|
142
|
+
classify,
|
|
143
|
+
cosineSimilarity,
|
|
144
|
+
cosineSimilarityMatrix,
|
|
145
|
+
cosineSimilarityVector,
|
|
146
|
+
createEdge,
|
|
147
|
+
createLangChainMemory,
|
|
148
|
+
detectSalience,
|
|
149
|
+
estimateTokens,
|
|
150
|
+
findConsolidationCandidates,
|
|
151
|
+
findLinks,
|
|
152
|
+
formatContext,
|
|
153
|
+
mergeCluster,
|
|
154
|
+
parseDuration,
|
|
155
|
+
recallAsPrompt,
|
|
156
|
+
registerStore,
|
|
157
|
+
score,
|
|
158
|
+
syncToAsync
|
|
159
|
+
};
|
|
160
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/adapters/raw.ts","../src/adapters/langchain.ts"],"sourcesContent":["/**\n * Raw API adapter — simple helper for injecting memory context into prompts.\n */\n\nimport type { Mnemonic } from \"../client.js\";\n\nexport interface RecallAsPromptOptions {\n maxTokens?: number;\n header?: string;\n}\n\n/**\n * Retrieve memory context formatted for direct inclusion in a system prompt.\n *\n * ```ts\n * const context = await recallAsPrompt(mem, userQuery);\n * const systemPrompt = `You are helpful.\\n\\n${context}`;\n * ```\n */\nexport async function recallAsPrompt(\n mnemonic: Mnemonic,\n query: string,\n options?: RecallAsPromptOptions,\n): Promise<string> {\n return mnemonic.recall(query, {\n maxTokens: options?.maxTokens ?? 3000,\n header: options?.header ?? \"Relevant context from memory:\",\n });\n}\n","/**\n * LangChain.js adapter — wraps Mnemonic as a LangChain BaseMemory.\n * Requires @langchain/core as a peer dependency.\n */\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\n\nimport type { Mnemonic } from \"../client.js\";\n\nexport interface LangChainMemoryOptions {\n /** The Mnemonic client instance. */\n mnemonic: Mnemonic;\n /** Key used in the memory variables dict (default \"memory\"). */\n memoryKey?: string;\n /** Max tokens for recall (default 3000). */\n maxTokens?: number;\n /** Input key for multi-key chains (auto-detected if single key). */\n inputKey?: string;\n /** Output key for multi-key chains (auto-detected if single key). */\n outputKey?: string;\n}\n\n/**\n * Create a LangChain-compatible memory wrapper.\n * Must be called with await since it dynamically imports @langchain/core.\n *\n * ```ts\n * const memory = await createLangChainMemory({ mnemonic: client });\n * const chain = new ConversationChain({ memory });\n * ```\n */\nexport async function createLangChainMemory(\n options: LangChainMemoryOptions,\n): Promise<any> {\n let BaseMemory: any;\n let getInputValues: ((inputs: Record<string, any>, key?: string) => any) | undefined;\n let getOutputValues: ((outputs: Record<string, any>, key?: string) => any) | undefined;\n try {\n const lcPath = \"@langchain/core/memory\";\n const mod: any = await import(lcPath);\n BaseMemory = mod.BaseMemory ?? mod.default?.BaseMemory;\n getInputValues = mod.getInputValues ?? mod.default?.getInputValues;\n getOutputValues = mod.getOutputValues ?? mod.default?.getOutputValues;\n } catch (err: unknown) {\n const msg = err instanceof Error ? err.message : String(err);\n if (msg.includes(\"Cannot find\") || msg.includes(\"MODULE_NOT_FOUND\")) {\n throw new Error(\n \"LangChain adapter requires '@langchain/core'. \" +\n \"Install it with: npm install @langchain/core\",\n );\n }\n throw err;\n }\n\n const {\n mnemonic,\n memoryKey = \"memory\",\n maxTokens = 3000,\n inputKey,\n outputKey,\n } = options;\n\n /** Extract a single string value from an inputs/outputs record. */\n function extractString(\n record: Record<string, any>,\n helper: typeof getInputValues | typeof getOutputValues,\n key?: string,\n ): string | undefined {\n // Use LangChain helpers when available (handles multi-key validation)\n if (helper && key) {\n try {\n const vals = helper(record, key);\n const v = vals[key];\n return typeof v === \"string\" ? v : undefined;\n } catch {\n // Fall through to simple extraction\n }\n }\n // Fallback: explicit key or first string value\n if (key && typeof record[key] === \"string\") return record[key];\n return Object.values(record).find((v) => typeof v === \"string\") as\n | string\n | undefined;\n }\n\n class MnemonicLangChainMemory extends BaseMemory {\n // BaseMemory v1.x requires `memoryKeys` (not `memoryVariables`)\n get memoryKeys(): string[] {\n return [memoryKey];\n }\n\n async loadMemoryVariables(\n inputs: Record<string, any>,\n ): Promise<Record<string, string>> {\n const query = extractString(inputs, getInputValues, inputKey) ?? \"\";\n const context = await mnemonic.recall(String(query), { maxTokens });\n return { [memoryKey]: context };\n }\n\n async saveContext(\n inputs: Record<string, any>,\n outputs: Record<string, any>,\n ): Promise<void> {\n const humanInput = extractString(inputs, getInputValues, inputKey);\n if (humanInput) {\n await mnemonic.add(String(humanInput), {\n source: \"langchain\",\n actor: \"user\",\n });\n }\n const aiOutput = extractString(outputs, getOutputValues, outputKey);\n if (aiOutput) {\n await mnemonic.add(String(aiOutput), {\n source: \"langchain\",\n actor: \"assistant\",\n });\n }\n }\n }\n\n return new MnemonicLangChainMemory();\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmBA,eAAsB,eACpB,UACA,OACA,SACiB;AACjB,SAAO,SAAS,OAAO,OAAO;AAAA,IAC5B,WAAW,SAAS,aAAa;AAAA,IACjC,QAAQ,SAAS,UAAU;AAAA,EAC7B,CAAC;AACH;;;ACGA,eAAsB,sBACpB,SACc;AACd,MAAI;AACJ,MAAI;AACJ,MAAI;AACJ,MAAI;AACF,UAAM,SAAS;AACf,UAAM,MAAW,MAAM,OAAO;AAC9B,iBAAa,IAAI,cAAc,IAAI,SAAS;AAC5C,qBAAiB,IAAI,kBAAkB,IAAI,SAAS;AACpD,sBAAkB,IAAI,mBAAmB,IAAI,SAAS;AAAA,EACxD,SAAS,KAAc;AACrB,UAAM,MAAM,eAAe,QAAQ,IAAI,UAAU,OAAO,GAAG;AAC3D,QAAI,IAAI,SAAS,aAAa,KAAK,IAAI,SAAS,kBAAkB,GAAG;AACnE,YAAM,IAAI;AAAA,QACR;AAAA,MAEF;AAAA,IACF;AACA,UAAM;AAAA,EACR;AAEA,QAAM;AAAA,IACJ;AAAA,IACA,YAAY;AAAA,IACZ,YAAY;AAAA,IACZ;AAAA,IACA;AAAA,EAC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