@oh-my-pi/pi-mnemosyne 15.6.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/README.md +107 -0
- package/dist/types/cli.d.ts +35 -0
- package/dist/types/config.d.ts +77 -0
- package/dist/types/core/aaak.d.ts +55 -0
- package/dist/types/core/annotations.d.ts +75 -0
- package/dist/types/core/banks.d.ts +33 -0
- package/dist/types/core/beam/consolidate.d.ts +32 -0
- package/dist/types/core/beam/helpers.d.ts +59 -0
- package/dist/types/core/beam/index.d.ts +59 -0
- package/dist/types/core/beam/recall.d.ts +32 -0
- package/dist/types/core/beam/schema.d.ts +2 -0
- package/dist/types/core/beam/store.d.ts +35 -0
- package/dist/types/core/beam/types.d.ts +233 -0
- package/dist/types/core/binary-vectors.d.ts +54 -0
- package/dist/types/core/chat-normalize.d.ts +13 -0
- package/dist/types/core/content-sanitizer.d.ts +18 -0
- package/dist/types/core/cost-log.d.ts +13 -0
- package/dist/types/core/embeddings.d.ts +35 -0
- package/dist/types/core/entities.d.ts +7 -0
- package/dist/types/core/episodic-graph.d.ts +89 -0
- package/dist/types/core/extraction/client.d.ts +31 -0
- package/dist/types/core/extraction/diagnostics.d.ts +51 -0
- package/dist/types/core/extraction/prompts.d.ts +2 -0
- package/dist/types/core/extraction.d.ts +6 -0
- package/dist/types/core/index.d.ts +4 -0
- package/dist/types/core/llm-backends.d.ts +21 -0
- package/dist/types/core/local-llm.d.ts +15 -0
- package/dist/types/core/memory.d.ts +160 -0
- package/dist/types/core/migrations/e6-triplestore-split.d.ts +17 -0
- package/dist/types/core/migrations/index.d.ts +1 -0
- package/dist/types/core/mmr.d.ts +8 -0
- package/dist/types/core/orchestrator.d.ts +20 -0
- package/dist/types/core/patterns.d.ts +61 -0
- package/dist/types/core/plugins.d.ts +109 -0
- package/dist/types/core/polyphonic-recall.d.ts +66 -0
- package/dist/types/core/query-cache.d.ts +47 -0
- package/dist/types/core/query-intent.d.ts +20 -0
- package/dist/types/core/recall-diagnostics.d.ts +48 -0
- package/dist/types/core/runtime-options.d.ts +61 -0
- package/dist/types/core/shmr.d.ts +56 -0
- package/dist/types/core/streaming.d.ts +136 -0
- package/dist/types/core/synonyms.d.ts +46 -0
- package/dist/types/core/temporal-parser.d.ts +16 -0
- package/dist/types/core/token-counter.d.ts +8 -0
- package/dist/types/core/triples.d.ts +63 -0
- package/dist/types/core/typed-memory.d.ts +39 -0
- package/dist/types/core/veracity-consolidation.d.ts +60 -0
- package/dist/types/core/weibull.d.ts +96 -0
- package/dist/types/db.d.ts +16 -0
- package/dist/types/diagnose.d.ts +24 -0
- package/dist/types/dr/index.d.ts +1 -0
- package/dist/types/dr/recovery.d.ts +68 -0
- package/dist/types/index.d.ts +5 -0
- package/dist/types/mcp-server.d.ts +40 -0
- package/dist/types/mcp-tools.d.ts +484 -0
- package/dist/types/migrations/e6-triplestore-split.d.ts +1 -0
- package/dist/types/migrations/index.d.ts +1 -0
- package/dist/types/types.d.ts +145 -0
- package/dist/types/util/datetime.d.ts +8 -0
- package/dist/types/util/env.d.ts +10 -0
- package/dist/types/util/ids.d.ts +3 -0
- package/dist/types/util/lru.d.ts +12 -0
- package/dist/types/util/regex.d.ts +10 -0
- package/package.json +82 -0
- package/src/cli.ts +390 -0
- package/src/config.ts +326 -0
- package/src/core/aaak.ts +142 -0
- package/src/core/annotations.ts +457 -0
- package/src/core/banks.ts +133 -0
- package/src/core/beam/consolidate.ts +963 -0
- package/src/core/beam/helpers.ts +920 -0
- package/src/core/beam/index.ts +353 -0
- package/src/core/beam/recall.ts +1091 -0
- package/src/core/beam/schema.ts +423 -0
- package/src/core/beam/store.ts +818 -0
- package/src/core/beam/types.ts +268 -0
- package/src/core/binary-vectors.ts +336 -0
- package/src/core/chat-normalize.ts +160 -0
- package/src/core/content-sanitizer.ts +136 -0
- package/src/core/cost-log.ts +103 -0
- package/src/core/embeddings.ts +490 -0
- package/src/core/entities.ts +259 -0
- package/src/core/episodic-graph.ts +708 -0
- package/src/core/extraction/client.ts +162 -0
- package/src/core/extraction/diagnostics.ts +193 -0
- package/src/core/extraction/prompts.ts +31 -0
- package/src/core/extraction.ts +335 -0
- package/src/core/index.ts +30 -0
- package/src/core/llm-backends.ts +51 -0
- package/src/core/local-llm.ts +436 -0
- package/src/core/memory.ts +617 -0
- package/src/core/migrations/e6-triplestore-split.ts +211 -0
- package/src/core/migrations/index.ts +1 -0
- package/src/core/mmr.ts +71 -0
- package/src/core/orchestrator.ts +53 -0
- package/src/core/patterns.ts +484 -0
- package/src/core/plugins.ts +375 -0
- package/src/core/polyphonic-recall.ts +563 -0
- package/src/core/query-cache.ts +370 -0
- package/src/core/query-intent.ts +139 -0
- package/src/core/recall-diagnostics.ts +157 -0
- package/src/core/runtime-options.ts +108 -0
- package/src/core/shmr.ts +471 -0
- package/src/core/streaming.ts +419 -0
- package/src/core/synonyms.ts +197 -0
- package/src/core/temporal-parser.ts +363 -0
- package/src/core/token-counter.ts +30 -0
- package/src/core/triples.ts +452 -0
- package/src/core/typed-memory.ts +407 -0
- package/src/core/veracity-consolidation.ts +477 -0
- package/src/core/weibull.ts +124 -0
- package/src/db.ts +128 -0
- package/src/diagnose.ts +174 -0
- package/src/dr/index.ts +1 -0
- package/src/dr/recovery.ts +405 -0
- package/src/index.ts +32 -0
- package/src/mcp-server.ts +155 -0
- package/src/mcp-tools.ts +961 -0
- package/src/migrations/e6-triplestore-split.ts +1 -0
- package/src/migrations/index.ts +1 -0
- package/src/types.ts +157 -0
- package/src/util/datetime.ts +69 -0
- package/src/util/env.ts +65 -0
- package/src/util/ids.ts +19 -0
- package/src/util/lru.ts +48 -0
- package/src/util/regex.ts +165 -0
package/src/config.ts
ADDED
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
import { homedir } from "node:os";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import {
|
|
4
|
+
type Env,
|
|
5
|
+
envBool,
|
|
6
|
+
envDisabled,
|
|
7
|
+
envFloat,
|
|
8
|
+
envInt,
|
|
9
|
+
envOneOf,
|
|
10
|
+
envOptionalString,
|
|
11
|
+
envString,
|
|
12
|
+
envTruthy,
|
|
13
|
+
} from "./util/env";
|
|
14
|
+
|
|
15
|
+
export type { Env };
|
|
16
|
+
export { envBool, envDisabled, envFloat, envInt, envOneOf, envOptionalString, envString, envTruthy };
|
|
17
|
+
|
|
18
|
+
export const DEFAULT_DATA_DIR = join(homedir(), ".hermes", "mnemosyne", "data");
|
|
19
|
+
export const DEFAULT_DB_FILENAME = "mnemosyne.db";
|
|
20
|
+
export const FASTEMBED_CACHE_DIR = join(homedir(), ".hermes", "cache", "fastembed");
|
|
21
|
+
export const MODEL_CACHE_DIR = join(homedir(), ".hermes", "mnemosyne", "models");
|
|
22
|
+
|
|
23
|
+
export const DEFAULT_EMBEDDING_MODEL = "BAAI/bge-small-en-v1.5";
|
|
24
|
+
export const DEFAULT_EMBEDDING_API_URL = "https://openrouter.ai/api/v1";
|
|
25
|
+
export const DEFAULT_LLM_MODEL_REPO = "TheBloke/TinyLlama-1.1B-Chat-v1.0-GGUF";
|
|
26
|
+
export const DEFAULT_LLM_MODEL_FILE = "tinyllama-1.1b-chat-v1.0.Q4_K_M.gguf";
|
|
27
|
+
export const HOST_LLM_TIMEOUT_SECONDS = 15.0;
|
|
28
|
+
|
|
29
|
+
export type VecType = "float32" | "int8" | "bit";
|
|
30
|
+
|
|
31
|
+
export const EMBEDDING_DIMS: Readonly<Record<string, number>> = {
|
|
32
|
+
"BAAI/bge-small-en-v1.5": 384,
|
|
33
|
+
"BAAI/bge-base-en-v1.5": 768,
|
|
34
|
+
"BAAI/bge-large-en-v1.5": 1024,
|
|
35
|
+
"BAAI/bge-small-zh-v1.5": 512,
|
|
36
|
+
"BAAI/bge-base-zh-v1.5": 768,
|
|
37
|
+
"BAAI/bge-large-zh-v1.5": 1024,
|
|
38
|
+
"intfloat/multilingual-e5-small": 384,
|
|
39
|
+
"intfloat/multilingual-e5-base": 768,
|
|
40
|
+
"intfloat/multilingual-e5-large": 1024,
|
|
41
|
+
"BAAI/bge-m3": 1024,
|
|
42
|
+
"BAAI/bge-multilingual-gemma2": 3584,
|
|
43
|
+
"openai/text-embedding-3-small": 1536,
|
|
44
|
+
"openai/text-embedding-3-large": 3072,
|
|
45
|
+
"text-embedding-3-small": 1536,
|
|
46
|
+
"text-embedding-3-large": 3072,
|
|
47
|
+
"jina-embeddings-v5-omni-nano": 768,
|
|
48
|
+
"jina-embeddings-v5-omni-small": 1024,
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export const VERACITY_WEIGHT_DEFAULTS = {
|
|
52
|
+
stated: 1.0,
|
|
53
|
+
inferred: 0.7,
|
|
54
|
+
tool: 0.5,
|
|
55
|
+
imported: 0.6,
|
|
56
|
+
unknown: 0.8,
|
|
57
|
+
} as const;
|
|
58
|
+
|
|
59
|
+
export function dataDir(env: Env = process.env): string {
|
|
60
|
+
return envOptionalString("MNEMOSYNE_DATA_DIR", env) ?? DEFAULT_DATA_DIR;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function dbPath(env: Env = process.env): string {
|
|
64
|
+
return join(dataDir(env), DEFAULT_DB_FILENAME);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function beamOptimizationsEnabled(env: Env = process.env): boolean {
|
|
68
|
+
return envTruthy("MNEMOSYNE_BEAM_OPTIMIZATIONS", env);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function embeddingModel(env: Env = process.env): string {
|
|
72
|
+
return envString("MNEMOSYNE_EMBEDDING_MODEL", DEFAULT_EMBEDDING_MODEL, env);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export function embeddingDim(env: Env = process.env): number {
|
|
76
|
+
const explicit = envInt("MNEMOSYNE_EMBEDDING_DIM", NaN, env);
|
|
77
|
+
if (Number.isFinite(explicit)) return explicit;
|
|
78
|
+
return EMBEDDING_DIMS[embeddingModel(env)] ?? 384;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export function embeddingApiKey(env: Env = process.env): string {
|
|
82
|
+
return envString(
|
|
83
|
+
"MNEMOSYNE_EMBEDDING_API_KEY",
|
|
84
|
+
envString("OPENROUTER_API_KEY", envString("OPENAI_API_KEY", "", env), env),
|
|
85
|
+
env,
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export function embeddingApiUrl(env: Env = process.env): string {
|
|
90
|
+
return envString(
|
|
91
|
+
"MNEMOSYNE_EMBEDDING_API_URL",
|
|
92
|
+
envString("OPENROUTER_BASE_URL", DEFAULT_EMBEDDING_API_URL, env),
|
|
93
|
+
env,
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export function embeddingsViaApi(env: Env = process.env): boolean {
|
|
98
|
+
return envTruthy("MNEMOSYNE_EMBEDDINGS_VIA_API", env);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export function embeddingsDisabled(env: Env = process.env): boolean {
|
|
102
|
+
return envString("MNEMOSYNE_NO_EMBEDDINGS", "", env) !== "";
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export function isApiEmbeddingModel(model = embeddingModel(), env: Env = process.env): boolean {
|
|
106
|
+
if (model.startsWith("openai/") || model.includes("text-embedding") || model.startsWith("text-embedding"))
|
|
107
|
+
return true;
|
|
108
|
+
const baseUrl = envString("MNEMOSYNE_EMBEDDING_API_URL", envString("OPENROUTER_BASE_URL", "", env), env);
|
|
109
|
+
if (baseUrl && !baseUrl.includes("openrouter.ai")) return true;
|
|
110
|
+
return embeddingsViaApi(env);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export function apiEmbeddingsAvailable(env: Env = process.env): boolean {
|
|
114
|
+
if (embeddingsDisabled(env)) return false;
|
|
115
|
+
if (!isApiEmbeddingModel(embeddingModel(env), env)) return false;
|
|
116
|
+
const baseUrl = envString("MNEMOSYNE_EMBEDDING_API_URL", envString("OPENROUTER_BASE_URL", "", env), env);
|
|
117
|
+
return Boolean(baseUrl && !baseUrl.includes("openrouter.ai")) || Boolean(embeddingApiKey(env));
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export function workingMemoryMaxItems(env: Env = process.env): number {
|
|
121
|
+
return envInt("MNEMOSYNE_WM_MAX_ITEMS", 10000, env);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export function workingMemoryTtlHours(env: Env = process.env): number {
|
|
125
|
+
return envInt("MNEMOSYNE_WM_TTL_HOURS", 24, env);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export function episodicRecallLimit(env: Env = process.env): number {
|
|
129
|
+
return envInt("MNEMOSYNE_EP_LIMIT", 50000, env);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export function sleepBatchSize(env: Env = process.env): number {
|
|
133
|
+
return envInt("MNEMOSYNE_SLEEP_BATCH", 5000, env);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export function scratchpadMaxItems(env: Env = process.env): number {
|
|
137
|
+
return envInt("MNEMOSYNE_SP_MAX", 1000, env);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export function recencyHalflifeHours(env: Env = process.env): number {
|
|
141
|
+
return envFloat("MNEMOSYNE_RECENCY_HALFLIFE", 168, env);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export function tier2Days(env: Env = process.env): number {
|
|
145
|
+
return envInt("MNEMOSYNE_TIER2_DAYS", 30, env);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export function tier3Days(env: Env = process.env): number {
|
|
149
|
+
return envInt("MNEMOSYNE_TIER3_DAYS", 180, env);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export function tier1Weight(env: Env = process.env): number {
|
|
153
|
+
return envFloat("MNEMOSYNE_TIER1_WEIGHT", 1.0, env);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export function tier2Weight(env: Env = process.env): number {
|
|
157
|
+
return envFloat("MNEMOSYNE_TIER2_WEIGHT", 0.5, env);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export function tier3Weight(env: Env = process.env): number {
|
|
161
|
+
return envFloat("MNEMOSYNE_TIER3_WEIGHT", 0.25, env);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
export function degradeBatchSize(env: Env = process.env): number {
|
|
165
|
+
return envInt("MNEMOSYNE_DEGRADE_BATCH", 100, env);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export function smartCompressEnabled(env: Env = process.env): boolean {
|
|
169
|
+
return !envDisabled("MNEMOSYNE_SMART_COMPRESS", env);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export function tier3MaxChars(env: Env = process.env): number {
|
|
173
|
+
return envInt("MNEMOSYNE_TIER3_MAX_CHARS", 300, env);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export function statedWeight(env: Env = process.env): number {
|
|
177
|
+
return envFloat("MNEMOSYNE_STATED_WEIGHT", VERACITY_WEIGHT_DEFAULTS.stated, env);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
export function inferredWeight(env: Env = process.env): number {
|
|
181
|
+
return envFloat("MNEMOSYNE_INFERRED_WEIGHT", VERACITY_WEIGHT_DEFAULTS.inferred, env);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
export function toolWeight(env: Env = process.env): number {
|
|
185
|
+
return envFloat("MNEMOSYNE_TOOL_WEIGHT", VERACITY_WEIGHT_DEFAULTS.tool, env);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
export function importedWeight(env: Env = process.env): number {
|
|
189
|
+
return envFloat("MNEMOSYNE_IMPORTED_WEIGHT", VERACITY_WEIGHT_DEFAULTS.imported, env);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
export function unknownWeight(env: Env = process.env): number {
|
|
193
|
+
return envFloat("MNEMOSYNE_UNKNOWN_WEIGHT", VERACITY_WEIGHT_DEFAULTS.unknown, env);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
export function veracityWeightOverrides(env: Env = process.env): string[] {
|
|
197
|
+
const names = [
|
|
198
|
+
"MNEMOSYNE_STATED_WEIGHT",
|
|
199
|
+
"MNEMOSYNE_INFERRED_WEIGHT",
|
|
200
|
+
"MNEMOSYNE_TOOL_WEIGHT",
|
|
201
|
+
"MNEMOSYNE_IMPORTED_WEIGHT",
|
|
202
|
+
"MNEMOSYNE_UNKNOWN_WEIGHT",
|
|
203
|
+
];
|
|
204
|
+
const overrides: string[] = [];
|
|
205
|
+
for (const name of names) {
|
|
206
|
+
if (env[name]?.trim()) overrides.push(name);
|
|
207
|
+
}
|
|
208
|
+
return overrides;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
export function vecType(env: Env = process.env): VecType {
|
|
212
|
+
return envOneOf("MNEMOSYNE_VEC_TYPE", ["float32", "int8", "bit"] as const, "int8", env);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
export function vectorWeight(env: Env = process.env): number {
|
|
216
|
+
return envFloat("MNEMOSYNE_VEC_WEIGHT", 0.5, env);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
export function ftsWeight(env: Env = process.env): number {
|
|
220
|
+
return envFloat("MNEMOSYNE_FTS_WEIGHT", 0.3, env);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
export function importanceWeight(env: Env = process.env): number {
|
|
224
|
+
return envFloat("MNEMOSYNE_IMPORTANCE_WEIGHT", 0.2, env);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
export function normalizedRecallWeights(
|
|
228
|
+
vec = vectorWeight(),
|
|
229
|
+
fts = ftsWeight(),
|
|
230
|
+
importance = importanceWeight(),
|
|
231
|
+
): readonly [number, number, number] {
|
|
232
|
+
const vw = Math.max(0, vec);
|
|
233
|
+
const fw = Math.max(0, fts);
|
|
234
|
+
const iw = Math.max(0, importance);
|
|
235
|
+
const total = vw + fw + iw;
|
|
236
|
+
if (total === 0) {
|
|
237
|
+
return [0.5, 0.3, 0.2];
|
|
238
|
+
}
|
|
239
|
+
const epsilon = 1e-10;
|
|
240
|
+
if (Math.abs(total - 1) < epsilon) {
|
|
241
|
+
return [vw, fw, iw];
|
|
242
|
+
}
|
|
243
|
+
return [vw / total, fw / total, iw / total];
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
export function autoMigrateEnabled(env: Env = process.env): boolean {
|
|
247
|
+
return envString("MNEMOSYNE_AUTO_MIGRATE", "1", env) !== "0";
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
export function proactiveLinkingEnabled(env: Env = process.env): boolean {
|
|
251
|
+
return envString("MNEMOSYNE_PROACTIVE_LINKING", "0", env) === "1";
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
export function polyphonicRecallEnabled(env: Env = process.env): boolean {
|
|
255
|
+
return envString("MNEMOSYNE_POLYPHONIC_RECALL", "0", env) === "1";
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
export function temporalHalflifeHours(env: Env = process.env): number {
|
|
259
|
+
return envFloat("MNEMOSYNE_TEMPORAL_HALFLIFE_HOURS", 24, env);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
export function enhancedRecallEnabled(env: Env = process.env): boolean {
|
|
263
|
+
return envString("MNEMOSYNE_ENHANCED_RECALL", "0", env) === "1";
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
export function llmEnabled(env: Env = process.env): boolean {
|
|
267
|
+
return envBool("MNEMOSYNE_LLM_ENABLED", true, env);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
export function llmMaxTokens(env: Env = process.env): number {
|
|
271
|
+
return envInt("MNEMOSYNE_LLM_MAX_TOKENS", 2048, env);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
export function llmThreads(env: Env = process.env): number {
|
|
275
|
+
return envInt("MNEMOSYNE_LLM_N_THREADS", 4, env);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
export function llmContext(env: Env = process.env): number {
|
|
279
|
+
return envInt("MNEMOSYNE_LLM_N_CTX", 2048, env);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
export function llmRepo(env: Env = process.env): string {
|
|
283
|
+
return envString("MNEMOSYNE_LLM_REPO", DEFAULT_LLM_MODEL_REPO, env);
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
export function llmFile(env: Env = process.env): string {
|
|
287
|
+
return envString("MNEMOSYNE_LLM_FILE", DEFAULT_LLM_MODEL_FILE, env);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
export function llmModelFiles(env: Env = process.env): readonly [repo: string, file: string] {
|
|
291
|
+
const repo = envOptionalString("MNEMOSYNE_LLM_REPO", env);
|
|
292
|
+
const file = envOptionalString("MNEMOSYNE_LLM_FILE", env);
|
|
293
|
+
return repo && file ? [repo, file] : [DEFAULT_LLM_MODEL_REPO, DEFAULT_LLM_MODEL_FILE];
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
export function llmBaseUrl(env: Env = process.env): string {
|
|
297
|
+
return envString("MNEMOSYNE_LLM_BASE_URL", "", env).replace(/\/+$/, "");
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
export function llmApiKey(env: Env = process.env): string {
|
|
301
|
+
return envString("MNEMOSYNE_LLM_API_KEY", "", env);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
export function llmModel(env: Env = process.env): string {
|
|
305
|
+
return envString("MNEMOSYNE_LLM_MODEL", "", env);
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
export function hostLlmEnabled(env: Env = process.env): boolean {
|
|
309
|
+
return envBool("MNEMOSYNE_HOST_LLM_ENABLED", false, env);
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
export function hostLlmProvider(env: Env = process.env): string | undefined {
|
|
313
|
+
return envOptionalString("MNEMOSYNE_HOST_LLM_PROVIDER", env);
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
export function hostLlmModel(env: Env = process.env): string | undefined {
|
|
317
|
+
return envOptionalString("MNEMOSYNE_HOST_LLM_MODEL", env);
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
export function hostLlmContext(env: Env = process.env): number {
|
|
321
|
+
return envInt("MNEMOSYNE_HOST_LLM_N_CTX", 32000, env);
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
export function sleepPrompt(env: Env = process.env): string {
|
|
325
|
+
return envString("MNEMOSYNE_SLEEP_PROMPT", "", env).trim();
|
|
326
|
+
}
|
package/src/core/aaak.ts
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
export const CATEGORY_MAP = {
|
|
2
|
+
PREFERENCE: "PREF",
|
|
3
|
+
TRAIT: "TRAIT",
|
|
4
|
+
STATUS: "STAT",
|
|
5
|
+
INSTRUCTION: "INST",
|
|
6
|
+
PROJECT: "PROJ",
|
|
7
|
+
LOCATION: "LOC",
|
|
8
|
+
FAMILY: "FAM",
|
|
9
|
+
OCCUPATION: "OCC",
|
|
10
|
+
DECISION: "DEC",
|
|
11
|
+
EVENT: "EVT",
|
|
12
|
+
TOOL: "TOOL",
|
|
13
|
+
FACT: "FACT",
|
|
14
|
+
OPINION: "OPN",
|
|
15
|
+
} as const;
|
|
16
|
+
|
|
17
|
+
export const PHRASE_MAP = {
|
|
18
|
+
"User asked ": "ASK ",
|
|
19
|
+
"User wants ": "WANT ",
|
|
20
|
+
"User prefers ": "PREF ",
|
|
21
|
+
"User likes ": "LIKE ",
|
|
22
|
+
"User dislikes ": "DISLIKE ",
|
|
23
|
+
"User is ": "IS ",
|
|
24
|
+
"User has ": "HAS ",
|
|
25
|
+
"User built ": "BUILT ",
|
|
26
|
+
"User asked for ": "ASK ",
|
|
27
|
+
"User requested ": "REQ ",
|
|
28
|
+
"Married to ": "MARRIED→",
|
|
29
|
+
"Email: ": "@",
|
|
30
|
+
"GitHub: ": "GH:",
|
|
31
|
+
"Location: ": "LOC:",
|
|
32
|
+
"Phone: ": "PH:",
|
|
33
|
+
"User email is ": "@",
|
|
34
|
+
"User voice message ": "VM ",
|
|
35
|
+
"User stack: ": "STACK|",
|
|
36
|
+
"Full-stack developer": "FSDEV",
|
|
37
|
+
"Software Developer": "SDEV",
|
|
38
|
+
"AI Systems Engineer": "AIENG",
|
|
39
|
+
"real-time": "RT",
|
|
40
|
+
"Real-time": "RT",
|
|
41
|
+
bilingual: "bi",
|
|
42
|
+
Bilingual: "bi",
|
|
43
|
+
"self-hosted": "selfhost",
|
|
44
|
+
automation: "auto",
|
|
45
|
+
transcription: "transc",
|
|
46
|
+
translation: "transl",
|
|
47
|
+
} as const;
|
|
48
|
+
|
|
49
|
+
export const STRUCTURAL_REPLACEMENTS: readonly (readonly [pattern: string, replacement: string])[] = [
|
|
50
|
+
[" - ", " | "],
|
|
51
|
+
[" -- ", " | "],
|
|
52
|
+
[" | ", " | "],
|
|
53
|
+
[", ", " | "],
|
|
54
|
+
[" and ", "+"],
|
|
55
|
+
[" or ", "/"],
|
|
56
|
+
[" for ", "→"],
|
|
57
|
+
[" to ", "→"],
|
|
58
|
+
[" with ", " w/ "],
|
|
59
|
+
[" over ", ">"],
|
|
60
|
+
[" instead of ", "!>"],
|
|
61
|
+
[" because of ", "∵"],
|
|
62
|
+
[" due to ", "∵"],
|
|
63
|
+
[" using ", "→"],
|
|
64
|
+
[" built ", "→"],
|
|
65
|
+
[" in ", ":"],
|
|
66
|
+
[" at ", "@"],
|
|
67
|
+
[" on ", "@"],
|
|
68
|
+
[" from ", "<-"],
|
|
69
|
+
];
|
|
70
|
+
|
|
71
|
+
function reverseMap<const T extends Readonly<Record<string, string>>>(source: T): Record<T[keyof T], keyof T & string> {
|
|
72
|
+
const reversed = Object.create(null) as Record<T[keyof T], keyof T & string>;
|
|
73
|
+
for (const rawKey in source) {
|
|
74
|
+
const key = rawKey as keyof T & string;
|
|
75
|
+
const value = source[key];
|
|
76
|
+
reversed[value] = key;
|
|
77
|
+
}
|
|
78
|
+
return reversed;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export const REV_CATEGORY = reverseMap(CATEGORY_MAP);
|
|
82
|
+
|
|
83
|
+
const SORTED_PHRASES = Object.entries(PHRASE_MAP).sort(([left], [right]) => right.length - left.length);
|
|
84
|
+
export const REV_PHRASE = reverseMap(PHRASE_MAP);
|
|
85
|
+
|
|
86
|
+
function replaceAllLiteral(text: string, pattern: string, replacement: string): string {
|
|
87
|
+
return text.replaceAll(pattern, replacement);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export function applyCategoryPrefixes(text: string): string {
|
|
91
|
+
for (const rawFull in CATEGORY_MAP) {
|
|
92
|
+
const full = rawFull as keyof typeof CATEGORY_MAP;
|
|
93
|
+
const prefix = `${full}: `;
|
|
94
|
+
if (text.startsWith(prefix)) {
|
|
95
|
+
return text.replace(prefix, `${CATEGORY_MAP[full]}|`);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return text;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export function applyPhrases(text: string): string {
|
|
102
|
+
let result = text;
|
|
103
|
+
for (const [phrase, shorthand] of SORTED_PHRASES) {
|
|
104
|
+
result = replaceAllLiteral(result, phrase, shorthand);
|
|
105
|
+
}
|
|
106
|
+
return result;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export function applyStructural(text: string): string {
|
|
110
|
+
let result = text;
|
|
111
|
+
for (const [pattern, replacement] of STRUCTURAL_REPLACEMENTS) {
|
|
112
|
+
result = replaceAllLiteral(result, pattern, replacement);
|
|
113
|
+
}
|
|
114
|
+
return result;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export function compactParens(text: string): string {
|
|
118
|
+
return text.replace(/\(\s*/g, "(").replaceAll(" )", ")");
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export function encode(text: string): string {
|
|
122
|
+
if (text.length === 0) {
|
|
123
|
+
return text;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (text.includes("|") && text.trim().split(/\s+/).length <= 3) {
|
|
127
|
+
return text;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
let result = text.trim();
|
|
131
|
+
result = applyCategoryPrefixes(result);
|
|
132
|
+
result = applyPhrases(result);
|
|
133
|
+
result = applyStructural(result);
|
|
134
|
+
result = compactParens(result);
|
|
135
|
+
result = result.replaceAll("working correctly", "OK");
|
|
136
|
+
result = result.replaceAll("working", "OK");
|
|
137
|
+
result = result.replaceAll("complete", "DONE");
|
|
138
|
+
result = result.replaceAll("completed", "DONE");
|
|
139
|
+
return result.trim();
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export const aaakEncode = encode;
|