jeopi-mnemopi 16.2.13

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.
Files changed (135) hide show
  1. package/CHANGELOG.md +172 -0
  2. package/README.md +107 -0
  3. package/dist/types/cli.d.ts +35 -0
  4. package/dist/types/config.d.ts +108 -0
  5. package/dist/types/core/aaak.d.ts +55 -0
  6. package/dist/types/core/annotations.d.ts +75 -0
  7. package/dist/types/core/banks.d.ts +33 -0
  8. package/dist/types/core/beam/consolidate.d.ts +32 -0
  9. package/dist/types/core/beam/helpers.d.ts +69 -0
  10. package/dist/types/core/beam/index.d.ts +59 -0
  11. package/dist/types/core/beam/recall.d.ts +32 -0
  12. package/dist/types/core/beam/schema.d.ts +2 -0
  13. package/dist/types/core/beam/store.d.ts +56 -0
  14. package/dist/types/core/beam/types.d.ts +245 -0
  15. package/dist/types/core/binary-vectors.d.ts +54 -0
  16. package/dist/types/core/chat-normalize.d.ts +13 -0
  17. package/dist/types/core/content-sanitizer.d.ts +18 -0
  18. package/dist/types/core/cost-log.d.ts +13 -0
  19. package/dist/types/core/embeddings.d.ts +54 -0
  20. package/dist/types/core/entities.d.ts +9 -0
  21. package/dist/types/core/episodic-graph.d.ts +89 -0
  22. package/dist/types/core/extraction/client.d.ts +35 -0
  23. package/dist/types/core/extraction/diagnostics.d.ts +51 -0
  24. package/dist/types/core/extraction/prompts.d.ts +2 -0
  25. package/dist/types/core/extraction.d.ts +7 -0
  26. package/dist/types/core/fastembed-model-cache.d.ts +2 -0
  27. package/dist/types/core/fastembed-runtime.d.ts +14 -0
  28. package/dist/types/core/index.d.ts +6 -0
  29. package/dist/types/core/llm-backends.d.ts +23 -0
  30. package/dist/types/core/local-llm.d.ts +20 -0
  31. package/dist/types/core/memory.d.ts +178 -0
  32. package/dist/types/core/migrations/e6-triplestore-split.d.ts +17 -0
  33. package/dist/types/core/migrations/index.d.ts +1 -0
  34. package/dist/types/core/mmr.d.ts +8 -0
  35. package/dist/types/core/orchestrator.d.ts +20 -0
  36. package/dist/types/core/patterns.d.ts +61 -0
  37. package/dist/types/core/plugins.d.ts +109 -0
  38. package/dist/types/core/polyphonic-recall.d.ts +66 -0
  39. package/dist/types/core/query-cache.d.ts +45 -0
  40. package/dist/types/core/query-intent.d.ts +20 -0
  41. package/dist/types/core/recall-diagnostics.d.ts +48 -0
  42. package/dist/types/core/runtime-options.d.ts +76 -0
  43. package/dist/types/core/shmr.d.ts +62 -0
  44. package/dist/types/core/streaming.d.ts +136 -0
  45. package/dist/types/core/synonyms.d.ts +46 -0
  46. package/dist/types/core/temporal-parser.d.ts +16 -0
  47. package/dist/types/core/token-counter.d.ts +8 -0
  48. package/dist/types/core/triples.d.ts +63 -0
  49. package/dist/types/core/typed-memory.d.ts +39 -0
  50. package/dist/types/core/vector-index.d.ts +16 -0
  51. package/dist/types/core/vector-math.d.ts +1 -0
  52. package/dist/types/core/veracity-consolidation.d.ts +60 -0
  53. package/dist/types/core/weibull.d.ts +96 -0
  54. package/dist/types/db.d.ts +16 -0
  55. package/dist/types/diagnose.d.ts +24 -0
  56. package/dist/types/dr/index.d.ts +1 -0
  57. package/dist/types/dr/recovery.d.ts +68 -0
  58. package/dist/types/index.d.ts +6 -0
  59. package/dist/types/mcp-server.d.ts +40 -0
  60. package/dist/types/mcp-tools.d.ts +484 -0
  61. package/dist/types/migrations/e6-triplestore-split.d.ts +1 -0
  62. package/dist/types/migrations/index.d.ts +1 -0
  63. package/dist/types/types.d.ts +145 -0
  64. package/dist/types/util/datetime.d.ts +8 -0
  65. package/dist/types/util/env.d.ts +10 -0
  66. package/dist/types/util/ids.d.ts +3 -0
  67. package/dist/types/util/lru.d.ts +12 -0
  68. package/dist/types/util/regex.d.ts +11 -0
  69. package/package.json +108 -0
  70. package/src/cli.ts +398 -0
  71. package/src/config.ts +373 -0
  72. package/src/core/aaak.ts +142 -0
  73. package/src/core/annotations.ts +457 -0
  74. package/src/core/banks.ts +133 -0
  75. package/src/core/beam/consolidate.ts +1068 -0
  76. package/src/core/beam/helpers.ts +831 -0
  77. package/src/core/beam/index.ts +358 -0
  78. package/src/core/beam/recall.ts +1173 -0
  79. package/src/core/beam/schema.ts +423 -0
  80. package/src/core/beam/store.ts +936 -0
  81. package/src/core/beam/types.ts +280 -0
  82. package/src/core/binary-vectors.ts +317 -0
  83. package/src/core/chat-normalize.ts +160 -0
  84. package/src/core/content-sanitizer.ts +136 -0
  85. package/src/core/cost-log.ts +103 -0
  86. package/src/core/embeddings.ts +531 -0
  87. package/src/core/entities.ts +263 -0
  88. package/src/core/episodic-graph.ts +708 -0
  89. package/src/core/extraction/client.ts +187 -0
  90. package/src/core/extraction/diagnostics.ts +193 -0
  91. package/src/core/extraction/prompts.ts +31 -0
  92. package/src/core/extraction.ts +338 -0
  93. package/src/core/fastembed-model-cache.ts +39 -0
  94. package/src/core/fastembed-runtime.ts +108 -0
  95. package/src/core/index.ts +38 -0
  96. package/src/core/llm-backends.ts +54 -0
  97. package/src/core/local-llm.ts +474 -0
  98. package/src/core/memory.ts +667 -0
  99. package/src/core/migrations/e6-triplestore-split.ts +211 -0
  100. package/src/core/migrations/index.ts +1 -0
  101. package/src/core/mmr.ts +71 -0
  102. package/src/core/orchestrator.ts +62 -0
  103. package/src/core/patterns.ts +484 -0
  104. package/src/core/plugins.ts +375 -0
  105. package/src/core/polyphonic-recall.ts +563 -0
  106. package/src/core/query-cache.ts +353 -0
  107. package/src/core/query-intent.ts +139 -0
  108. package/src/core/recall-diagnostics.ts +157 -0
  109. package/src/core/runtime-options.ts +130 -0
  110. package/src/core/shmr.ts +560 -0
  111. package/src/core/streaming.ts +419 -0
  112. package/src/core/synonyms.ts +197 -0
  113. package/src/core/temporal-parser.ts +363 -0
  114. package/src/core/token-counter.ts +30 -0
  115. package/src/core/triples.ts +452 -0
  116. package/src/core/typed-memory.ts +407 -0
  117. package/src/core/vector-index.ts +84 -0
  118. package/src/core/vector-math.ts +23 -0
  119. package/src/core/veracity-consolidation.ts +477 -0
  120. package/src/core/weibull.ts +124 -0
  121. package/src/db.ts +128 -0
  122. package/src/diagnose.ts +174 -0
  123. package/src/dr/index.ts +1 -0
  124. package/src/dr/recovery.ts +405 -0
  125. package/src/index.ts +33 -0
  126. package/src/mcp-server.ts +155 -0
  127. package/src/mcp-tools.ts +970 -0
  128. package/src/migrations/e6-triplestore-split.ts +1 -0
  129. package/src/migrations/index.ts +1 -0
  130. package/src/types.ts +157 -0
  131. package/src/util/datetime.ts +69 -0
  132. package/src/util/env.ts +65 -0
  133. package/src/util/ids.ts +19 -0
  134. package/src/util/lru.ts +48 -0
  135. package/src/util/regex.ts +165 -0
@@ -0,0 +1,89 @@
1
+ import type { Database } from "bun:sqlite";
2
+ import { type DatabasePath } from "../db";
3
+ export interface Gist {
4
+ readonly id: string;
5
+ readonly text: string;
6
+ readonly timestamp: string;
7
+ readonly participants: readonly string[];
8
+ readonly location: string | null;
9
+ readonly emotion: string | null;
10
+ readonly timeScope: string | null;
11
+ }
12
+ export interface Fact {
13
+ readonly id: string;
14
+ readonly subject: string;
15
+ readonly predicate: string;
16
+ readonly object: string;
17
+ readonly timestamp: string;
18
+ readonly confidence: number;
19
+ readonly temporalQualifier?: string | null;
20
+ }
21
+ export interface GraphEdge {
22
+ readonly source: string;
23
+ readonly target: string;
24
+ readonly edgeType: string;
25
+ readonly weight: number;
26
+ readonly timestamp: string;
27
+ }
28
+ export interface RelatedMemory {
29
+ readonly memoryId: string;
30
+ readonly edgeType: string;
31
+ readonly weight: number;
32
+ readonly depth: number;
33
+ }
34
+ export interface GraphStats {
35
+ readonly gists: number;
36
+ readonly facts: number;
37
+ readonly edges: number;
38
+ readonly totalNodes: number;
39
+ }
40
+ export interface IngestOptions {
41
+ readonly sessionId?: string;
42
+ readonly linkExisting?: boolean;
43
+ readonly minLinkScore?: number;
44
+ readonly extractEntities?: boolean;
45
+ }
46
+ export interface IngestResult {
47
+ readonly memoryId: string;
48
+ readonly gist: Gist;
49
+ readonly facts: readonly Fact[];
50
+ readonly edges: readonly GraphEdge[];
51
+ }
52
+ export interface EpisodicGraphOptions {
53
+ readonly db?: Database;
54
+ readonly dbPath?: DatabasePath;
55
+ }
56
+ export declare class EpisodicGraph {
57
+ readonly db: Database;
58
+ readonly dbPath: DatabasePath;
59
+ readonly ownsConnection: boolean;
60
+ constructor(options?: EpisodicGraphOptions);
61
+ private initTables;
62
+ extractGist(content: string, memoryId: string): Gist;
63
+ extractFacts(content: string, memoryId: string): Fact[];
64
+ storeGist(gist: Gist, memoryId: string): void;
65
+ getGist(id: string): Gist | null;
66
+ storeFact(fact: Fact, memoryId: string, sessionId?: string): void;
67
+ getFact(id: string): Fact | null;
68
+ addEdge(edge: GraphEdge): void;
69
+ getEdges(source?: string | null): GraphEdge[];
70
+ findRelatedMemories(memoryId: string, depth?: number, edgeType?: string, minWeight?: number): RelatedMemory[];
71
+ findFactsBySubject(subject: string): Fact[];
72
+ findGistsByParticipant(participant: string): Gist[];
73
+ scoreMemoryLink(sourceMemoryId: string, targetMemoryId: string): number;
74
+ ingestMemory(content: string, memoryId: string, options?: IngestOptions): IngestResult;
75
+ getStats(): GraphStats;
76
+ close(): void;
77
+ private count;
78
+ private extractParticipants;
79
+ private extractTemporalScope;
80
+ private extractLocation;
81
+ private extractEmotion;
82
+ private createSummary;
83
+ private knownMemoryIds;
84
+ private memoryContent;
85
+ private entityOverlapScore;
86
+ private temporalContextScore;
87
+ private memoryFeatures;
88
+ private scoreFeatures;
89
+ }
@@ -0,0 +1,35 @@
1
+ import { type ApiKey, type FetchImpl } from "jeopi-ai";
2
+ export declare const DEFAULT_EXTRACTION_MODEL: string;
3
+ export declare const OPENROUTER_BASE_URL: string;
4
+ export declare const FALLBACK_MODELS: readonly ["google/gemini-flash-latest"];
5
+ export interface ChatMessage {
6
+ role: string;
7
+ content: string;
8
+ }
9
+ export interface ExtractedFact {
10
+ subject?: string;
11
+ predicate?: string;
12
+ object?: string;
13
+ timestamp?: string;
14
+ source?: number;
15
+ confidence?: number;
16
+ [key: string]: unknown;
17
+ }
18
+ export interface ExtractionClientOptions {
19
+ model?: string | null;
20
+ apiKey?: ApiKey | null;
21
+ baseUrl?: string | null;
22
+ fetch?: FetchImpl;
23
+ }
24
+ export declare class ExtractionClient {
25
+ model: string;
26
+ apiKey: ApiKey;
27
+ baseUrl: string;
28
+ callCount: number;
29
+ private readonly fetchImpl;
30
+ constructor(opts?: ExtractionClientOptions);
31
+ chat(messages: readonly ChatMessage[], temperature?: number, maxTokens?: number): Promise<string>;
32
+ callApi(model: string, messages: readonly ChatMessage[], temperature: number, maxTokens: number, apiKey?: string): Promise<string>;
33
+ extractFacts(messages: readonly ChatMessage[]): Promise<ExtractedFact[]>;
34
+ xtractFacts(messages: readonly ChatMessage[]): Promise<ExtractedFact[]>;
35
+ }
@@ -0,0 +1,51 @@
1
+ export declare const EXTRACTION_TIERS: readonly ["host", "remote", "local", "cloud", "wrapper"];
2
+ export type ExtractionTier = (typeof EXTRACTION_TIERS)[number];
3
+ export interface ErrorSample {
4
+ at: string;
5
+ type: string;
6
+ msg: string;
7
+ reason?: string;
8
+ }
9
+ export interface TierStatsSnapshot {
10
+ attempts: number;
11
+ successes: number;
12
+ no_output: number;
13
+ failures: number;
14
+ error_samples: ErrorSample[];
15
+ }
16
+ export interface ExtractionStatsSnapshot {
17
+ created_at: string;
18
+ snapshot_at: string;
19
+ totals: {
20
+ calls: number;
21
+ successes: number;
22
+ failures: number;
23
+ empty: number;
24
+ success_rate: number;
25
+ };
26
+ by_tier: Record<ExtractionTier, TierStatsSnapshot>;
27
+ }
28
+ export declare function safeForLog(value: unknown): string;
29
+ export declare class ExtractionDiagnostics {
30
+ private tierStats;
31
+ private totalCalls;
32
+ private totalSuccesses;
33
+ private totalFailures;
34
+ private totalEmpty;
35
+ private createdAt;
36
+ private validateTier;
37
+ recordAttempt(tier: ExtractionTier): void;
38
+ recordSuccess(tier: ExtractionTier, _factCount?: number): void;
39
+ recordNoOutput(tier: ExtractionTier): void;
40
+ recordFailure(tier: ExtractionTier, exc?: unknown, reason?: string): void;
41
+ recordCall(opts: {
42
+ succeeded: boolean;
43
+ allEmpty?: boolean;
44
+ }): void;
45
+ successRate(): number;
46
+ snapshot(): ExtractionStatsSnapshot;
47
+ reset(): void;
48
+ }
49
+ export declare function getDiagnostics(): ExtractionDiagnostics;
50
+ export declare function getExtractionStats(): ExtractionStatsSnapshot;
51
+ export declare function resetExtractionStats(): void;
@@ -0,0 +1,2 @@
1
+ export declare const EXTRACTION_SYSTEM_PROMPT = "You extract structured facts from conversation messages. For each message or group of related messages, identify:\n\n1. ENTITIES: People, projects, tools, versions, dates, numbers mentioned\n2. RELATIONSHIPS: How entities relate to each other (uses, created, set, changed, prefers)\n3. TEMPORAL ANCHORS: When something happened, deadlines, durations\n4. CONTRADICTIONS: When a fact was later changed or updated\n\nReturn ONLY a JSON array of fact objects. Each fact must have:\n- subject: the entity the fact is about (string)\n- predicate: the relationship or action (string)\n- object: the value or related entity (string)\n- timestamp: ISO timestamp when this was stated (string, from message context)\n- source: which message index this came from (integer, 0-based)\n- confidence: 0.0-1.0 how certain you are (float)\n\nRULES:\n- One fact per relationship. \"I use React 18.2 and Node.js 18\" = 2 facts.\n- Use lowercase for predicates: \"uses\", \"set\", \"changed\", \"created\", \"prefers\"\n- Include versions and numbers as objects when available\n- If a message states something changed, extract BOTH old and new facts\n- If unclear, use confidence < 0.8\n\nFormat: [{\"subject\": \"...\", \"predicate\": \"...\", \"object\": \"...\", \"timestamp\": \"...\", \"source\": 0, \"confidence\": 0.95}]\n";
2
+ export declare const EXTRACTION_USER_TEMPLATE = "Extract all structured facts from the following conversation messages. Return ONLY the JSON array, no other text.\n\nCONVERSATION:\n{conversation_text}\n\nFACTS:";
@@ -0,0 +1,7 @@
1
+ import { type RemoteLlmOptions } from "./local-llm";
2
+ export declare const EXTRACTION_PROMPT_TEMPLATE: string;
3
+ export declare function buildExtractionPrompt(text: string, detectedLang?: string): string;
4
+ export declare function parseFacts(rawOutput: string | null | undefined): string[];
5
+ export declare function heuristicExtractFacts(text: string): string[];
6
+ export declare function extractFacts(text: string | null | undefined, options?: RemoteLlmOptions): Promise<string[]>;
7
+ export declare function extractFactsSafe(text: string | null | undefined): Promise<string[]>;
@@ -0,0 +1,2 @@
1
+ /** Download missing config/tokenizer sidecars into a fastembed model cache directory. */
2
+ export declare function ensureFastembedModelSidecars(model: string, cacheDir?: string): Promise<boolean>;
@@ -0,0 +1,14 @@
1
+ import type * as Fastembed from "fastembed";
2
+ import { type RuntimeInstallSpec } from "jeopi-utils";
3
+ type FastembedModule = typeof Fastembed;
4
+ /** Runtime install inputs for the optional fastembed embedding stack. */
5
+ export interface FastembedRuntimeInstallPlan {
6
+ /** Cache directory key; changes when runtime resolution policy changes. */
7
+ versionKey: string;
8
+ /** Dependency graph written to the runtime cache package manifest. */
9
+ install: RuntimeInstallSpec;
10
+ }
11
+ /** Build the deterministic fastembed runtime install plan used by local embeddings. */
12
+ export declare function fastembedRuntimeInstallPlan(): FastembedRuntimeInstallPlan;
13
+ export declare function loadFastembed(): Promise<FastembedModule>;
14
+ export {};
@@ -0,0 +1,6 @@
1
+ export { configureRecallFeatures, type RecallFeatureFlags } from "../config";
2
+ export * from "./banks";
3
+ export * from "./beam/index";
4
+ export { type LocalEmbeddingModel, type LocalModelInitializer, type LocalModelInitOptions, type StandardEmbeddingModel, setLocalModelInitializer, } from "./embeddings";
5
+ export * from "./memory";
6
+ export { addMemory, forget, get, getBank, getContext, getDefaultInstance, getStats, Mnemopi, query, recall, recallEnhanced, remember, resetDefaultInstanceForTests, resetMemoryForTests, resetModuleStateForTests, saveMemory, scratchpadClear, scratchpadRead, scratchpadWrite, search, setBank, sleep, sleepAllSessions, storeMemory, update, } from "./memory";
@@ -0,0 +1,23 @@
1
+ import type { FetchImpl } from "jeopi-ai";
2
+ export interface CompleteOptions {
3
+ maxTokens?: number;
4
+ temperature?: number;
5
+ timeout?: number;
6
+ provider?: string | null;
7
+ model?: string | null;
8
+ fetch?: FetchImpl;
9
+ }
10
+ export interface LlmBackend {
11
+ name?: string;
12
+ complete(prompt: string, opts?: CompleteOptions): string | null | Promise<string | null>;
13
+ }
14
+ export declare function setHostLlmBackend(backend: LlmBackend | null | undefined): void;
15
+ export declare function getHostLlmBackend(): LlmBackend | null;
16
+ export declare function resetHostLlmBackendForTests(): void;
17
+ export declare function callHostLlm(prompt: string, opts?: CompleteOptions): Promise<string | null>;
18
+ export declare class CallableLlmBackend implements LlmBackend {
19
+ name: string;
20
+ private readonly fn;
21
+ constructor(name: string, fn: (prompt: string, opts?: CompleteOptions) => string | null | Promise<string | null>);
22
+ complete(prompt: string, opts?: CompleteOptions): string | null | Promise<string | null>;
23
+ }
@@ -0,0 +1,20 @@
1
+ import { type FetchImpl } from "jeopi-ai";
2
+ import { type CompleteOptions } from "./llm-backends";
3
+ import { type MnemopiLlmCompleteOptions } from "./runtime-options";
4
+ export interface RemoteLlmOptions {
5
+ fetch?: FetchImpl;
6
+ }
7
+ export declare const DEFAULT_MODEL_REPO: string;
8
+ export declare const DEFAULT_MODEL_FILE: string;
9
+ export declare function buildPrompt(memories: readonly string[], source?: string): string;
10
+ export declare function callConfiguredCompletion(prompt: string, temperature: number, opts?: MnemopiLlmCompleteOptions): Promise<string | null>;
11
+ export declare function buildHostPrompt(memories: readonly string[], source?: string): string;
12
+ export declare function configuredLlmWillHandleCall(): boolean;
13
+ export declare function cleanOutput(text: string): string;
14
+ export declare function chunkMemoriesByBudget(memories: readonly string[], source?: string): string[][];
15
+ export declare function llmAvailable(): boolean;
16
+ export declare function callRemoteLlm(prompt: string, temperature?: number, options?: RemoteLlmOptions): Promise<string | null>;
17
+ export declare function localGgufAvailable(): false;
18
+ export declare function callLocalLlm(_prompt: string): Promise<string | null>;
19
+ export declare function summarizeMemories(memories: readonly string[], source?: string, options?: RemoteLlmOptions): Promise<string | null>;
20
+ export declare function complete(prompt: string, temperature?: number, options?: CompleteOptions): Promise<string | null>;
@@ -0,0 +1,178 @@
1
+ import type { Database } from "bun:sqlite";
2
+ import type { Api, ApiKey, Model } from "jeopi-ai";
3
+ import type { MemoryInput, Metadata } from "../types";
4
+ import { BeamMemory } from "./beam/index";
5
+ import type { RecallEnhancedOptions, RecallOptions, RecallResult, SleepResult } from "./beam/types";
6
+ import { type MnemopiEmbeddingRuntimeOptions, type MnemopiLlmCompletion, type MnemopiLlmRuntimeOptions, type ResolvedMnemopiRuntimeOptions } from "./runtime-options";
7
+ export interface MnemopiOptions {
8
+ readonly db?: Database;
9
+ readonly dbPath?: string;
10
+ readonly db_path?: string;
11
+ readonly sessionId?: string;
12
+ readonly session_id?: string;
13
+ readonly bank?: string | null;
14
+ readonly authorId?: string | null;
15
+ readonly author_id?: string | null;
16
+ readonly authorType?: string | null;
17
+ readonly author_type?: string | null;
18
+ readonly channelId?: string | null;
19
+ readonly channel_id?: string | null;
20
+ readonly noEmbeddings?: boolean;
21
+ readonly embeddingModel?: string;
22
+ readonly embeddingApiUrl?: string;
23
+ readonly embeddingApiKey?: ApiKey;
24
+ readonly embeddings?: false | MnemopiEmbeddingRuntimeOptions;
25
+ readonly llmEnabled?: boolean;
26
+ readonly llmBaseUrl?: string;
27
+ readonly llmApiKey?: ApiKey;
28
+ readonly llmModel?: string | Model<Api>;
29
+ readonly llm?: false | MnemopiLlmRuntimeOptions | Model<Api> | MnemopiLlmCompletion;
30
+ readonly proactiveLinking?: boolean;
31
+ /** Escalate best-effort failure logs (embedding pipeline) from debug to warn. */
32
+ readonly debug?: boolean;
33
+ /**
34
+ * When `false`, skip the embedding-model reconcile (wipe-and-rebuild) on open.
35
+ * Read-only / ephemeral consumers (e.g. a stats snapshot) set this so an open
36
+ * never triggers a destructive migration whose background rebuild the process
37
+ * would exit before completing. Defaults to `true`.
38
+ */
39
+ readonly reconcile?: boolean;
40
+ }
41
+ export interface RememberInput extends MemoryInput {
42
+ readonly extract?: boolean;
43
+ readonly extractEntities?: boolean;
44
+ readonly extract_entities?: boolean;
45
+ readonly extractText?: string | null;
46
+ readonly extract_text?: string | null;
47
+ readonly trustTier?: string | null;
48
+ readonly trust_tier?: string | null;
49
+ readonly memoryType?: string | null;
50
+ readonly memory_type?: string | null;
51
+ }
52
+ export interface RememberFacadeOptions {
53
+ readonly source?: string | null;
54
+ readonly importance?: number;
55
+ readonly metadata?: Metadata | null;
56
+ readonly validUntil?: string | Date | null;
57
+ readonly valid_until?: string | Date | null;
58
+ readonly scope?: string | null;
59
+ readonly extractEntities?: boolean;
60
+ readonly extract_entities?: boolean;
61
+ readonly extract?: boolean;
62
+ /**
63
+ * Override the text passed to fact/entity extraction. When unset, the
64
+ * stored content is used. See {@link RememberOptions.extractText}.
65
+ */
66
+ readonly extractText?: string | null;
67
+ readonly extract_text?: string | null;
68
+ readonly trustTier?: string | null;
69
+ readonly trust_tier?: string | null;
70
+ readonly timestamp?: string | Date | null;
71
+ readonly veracity?: string | null;
72
+ readonly memoryType?: string | null;
73
+ readonly memory_type?: string | null;
74
+ }
75
+ export interface RecallFacadeOptions extends Omit<RecallOptions, "temporalHalflife" | "vecWeight" | "ftsWeight" | "importanceWeight"> {
76
+ readonly from_date?: string | null;
77
+ readonly to_date?: string | null;
78
+ readonly source?: string | null;
79
+ readonly topic?: string | null;
80
+ readonly temporalWeight?: number;
81
+ readonly temporal_weight?: number;
82
+ readonly query_time?: string | Date | null;
83
+ readonly temporalHalflife?: number | null;
84
+ readonly temporal_halflife?: number | null;
85
+ readonly vecWeight?: number | null;
86
+ readonly vec_weight?: number | null;
87
+ readonly ftsWeight?: number | null;
88
+ readonly fts_weight?: number | null;
89
+ readonly importanceWeight?: number | null;
90
+ readonly importance_weight?: number | null;
91
+ }
92
+ export interface MemoryFacadeStats {
93
+ total_memories: number;
94
+ total_sessions: number;
95
+ sources: Record<string, number>;
96
+ last_memory: string | null;
97
+ database: string;
98
+ mode: "beam";
99
+ banks: string[];
100
+ beam: {
101
+ working_memory: unknown;
102
+ episodic_memory: unknown;
103
+ triples: {
104
+ total: number;
105
+ };
106
+ };
107
+ }
108
+ type ModuleRememberOptions = RememberFacadeOptions & {
109
+ readonly bank?: string | null;
110
+ };
111
+ type ModuleRecallOptions = RecallFacadeOptions & {
112
+ readonly bank?: string | null;
113
+ };
114
+ type ModuleRecallEnhancedOptions = RecallFacadeOptions & RecallEnhancedOptions & {
115
+ readonly bank?: string | null;
116
+ };
117
+ export declare class Mnemopi {
118
+ #private;
119
+ readonly sessionId: string;
120
+ readonly bank: string;
121
+ readonly dbPath?: string;
122
+ readonly authorId: string | null;
123
+ readonly authorType: string | null;
124
+ readonly channelId: string;
125
+ readonly beam: BeamMemory;
126
+ readonly conn: Database;
127
+ readonly db: Database;
128
+ readonly runtimeOptions?: ResolvedMnemopiRuntimeOptions;
129
+ constructor(options?: MnemopiOptions);
130
+ close(): void;
131
+ flushExtractions(): Promise<void>;
132
+ remember(memory: string | RememberInput, options?: RememberFacadeOptions): string;
133
+ recall(query: string, topK?: number, options?: RecallFacadeOptions): Promise<RecallResult[]>;
134
+ recallEnhanced(query: string, topK?: number, options?: RecallFacadeOptions & RecallEnhancedOptions): Promise<RecallResult[]>;
135
+ getContext(limit?: number): unknown[];
136
+ getStats(authorId?: string | null, authorType?: string | null, channelId?: string | null): MemoryFacadeStats;
137
+ get(memoryId: string): unknown | null;
138
+ forget(memoryId: string): boolean;
139
+ update(memoryId: string, content?: string | null, importance?: number | null): boolean;
140
+ sleep(dryRun?: boolean): SleepResult;
141
+ sleepAllSessions(dryRun?: boolean): SleepResult;
142
+ scratchpadWrite(content: string): string;
143
+ scratchpadRead(): unknown[];
144
+ scratchpadClear(): void;
145
+ addMemory(memory: string | RememberInput, options?: RememberFacadeOptions): string;
146
+ saveMemory(memory: string | RememberInput, options?: RememberFacadeOptions): string;
147
+ storeMemory(memory: string | RememberInput, options?: RememberFacadeOptions): string;
148
+ search(query: string, topK?: number, options?: RecallFacadeOptions): Promise<RecallResult[]>;
149
+ query(query: string, topK?: number, options?: RecallFacadeOptions): Promise<RecallResult[]>;
150
+ consolidate(dryRun?: boolean): SleepResult;
151
+ }
152
+ export declare function setBank(bank: string): void;
153
+ export declare function getBank(): string;
154
+ export declare function getDefaultInstance(bank?: string | null): Mnemopi;
155
+ export declare function remember(content: string | RememberInput, options?: ModuleRememberOptions): string;
156
+ export declare function recall(query: string, topK?: number, options?: ModuleRecallOptions): Promise<RecallResult[]>;
157
+ export declare function recallEnhanced(query: string, topK?: number, options?: ModuleRecallEnhancedOptions): Promise<RecallResult[]>;
158
+ export declare function getContext(limit?: number, bank?: string | null): unknown[];
159
+ export declare function getStats(bank?: string | null): MemoryFacadeStats;
160
+ export declare function get(memoryId: string, bank?: string | null): unknown | null;
161
+ export declare function forget(memoryId: string, bank?: string | null): boolean;
162
+ export declare function update(memoryId: string, content?: string | null, importance?: number | null, bank?: string | null): boolean;
163
+ export declare function sleep(dryRun?: boolean, bank?: string | null): SleepResult;
164
+ export declare function sleepAllSessions(dryRun?: boolean, bank?: string | null): SleepResult;
165
+ export declare function flushExtractions(bank?: string | null): Promise<void>;
166
+ export declare function scratchpadWrite(content: string, bank?: string | null): string;
167
+ export declare function scratchpadRead(bank?: string | null): unknown[];
168
+ export declare function scratchpadClear(bank?: string | null): void;
169
+ export declare function addMemory(memory: string | RememberInput, options?: ModuleRememberOptions): string;
170
+ export declare function saveMemory(memory: string | RememberInput, options?: ModuleRememberOptions): string;
171
+ export declare function storeMemory(memory: string | RememberInput, options?: ModuleRememberOptions): string;
172
+ export declare function search(query: string, topK?: number, options?: ModuleRecallOptions): Promise<RecallResult[]>;
173
+ export declare function query(query: string, topK?: number, options?: ModuleRecallOptions): Promise<RecallResult[]>;
174
+ export declare function resetDefaultInstanceForTests(): void;
175
+ export declare function resetMemoryForTests(): void;
176
+ export declare function resetModuleStateForTests(): void;
177
+ export type { MemoryInput, MemoryStats } from "../types";
178
+ export default Mnemopi;
@@ -0,0 +1,17 @@
1
+ import type { Database } from "bun:sqlite";
2
+ import { type DatabasePath } from "../../db";
3
+ export declare const ANNOTATION_KINDS: readonly ["mentions", "fact", "occurred_on", "has_source"];
4
+ export type AnnotationKind = (typeof ANNOTATION_KINDS)[number];
5
+ export interface MigrationOptions {
6
+ readonly dbPath: DatabasePath;
7
+ readonly dryRun?: boolean;
8
+ readonly backup?: boolean;
9
+ readonly logFn?: (line: string) => void;
10
+ }
11
+ export interface PendingConnection {
12
+ query<T = unknown>(sql: string): {
13
+ get(...params: unknown[]): T | null;
14
+ };
15
+ }
16
+ export declare function hasPendingMigration(db: Database): boolean;
17
+ export declare function migrate(dbPathOrOptions: DatabasePath | MigrationOptions, dryRun?: boolean, backup?: boolean, logFn?: (line: string) => void): number;
@@ -0,0 +1 @@
1
+ export * from "./e6-triplestore-split";
@@ -0,0 +1,8 @@
1
+ export interface MmrResult {
2
+ readonly content?: string;
3
+ readonly score?: number;
4
+ readonly [key: string]: unknown;
5
+ }
6
+ export type SimilarityFn = (textA: string, textB: string) => number;
7
+ export declare function jaccardSimilarity(textA: string, textB: string): number;
8
+ export declare function mmrRerank<T extends MmrResult>(results: readonly T[], lambdaParam?: number, topK?: number, similarityFn?: SimilarityFn): T[];
@@ -0,0 +1,20 @@
1
+ import type { BeamMemoryState, RecallOptions, RecallResult } from "./beam/types";
2
+ import { type PolyphonicMemoryResult, type PolyphonicRecallOptions } from "./polyphonic-recall";
3
+ export interface OrchestratorBeam extends BeamMemoryState {
4
+ recall?: (query: string, topK?: number, options?: RecallOptions) => Promise<RecallResult[]>;
5
+ recallEnhanced?: (query: string, topK?: number, options?: RecallOptions) => Promise<RecallResult[]>;
6
+ }
7
+ export interface OrchestrateRecallOptions extends Omit<RecallOptions, "queryEmbedding">, Omit<PolyphonicRecallOptions, "queryEmbedding"> {
8
+ readonly queryEmbedding?: readonly number[] | Float32Array | null;
9
+ readonly enhanced?: boolean;
10
+ readonly forcePolyphonic?: boolean;
11
+ readonly forceLinear?: boolean;
12
+ }
13
+ export interface OrchestratedRecallResult extends Omit<RecallResult, "metadata" | "score" | "tier"> {
14
+ score?: number;
15
+ metadata?: RecallResult["metadata"];
16
+ tier?: RecallResult["tier"] | PolyphonicMemoryResult["tier"];
17
+ combined_score?: PolyphonicMemoryResult["combined_score"];
18
+ voice_scores?: PolyphonicMemoryResult["voice_scores"];
19
+ }
20
+ export declare function orchestrateRecall(beam: OrchestratorBeam, query: string, topK?: number, options?: OrchestrateRecallOptions): Promise<OrchestratedRecallResult[]>;
@@ -0,0 +1,61 @@
1
+ export interface CompressionStatsInit {
2
+ readonly originalSize?: number;
3
+ readonly compressedSize?: number;
4
+ readonly ratio?: number;
5
+ readonly method?: string;
6
+ readonly patternsFound?: number;
7
+ readonly memoriesCompressed?: number;
8
+ }
9
+ export declare class CompressionStats {
10
+ originalSize: number;
11
+ compressedSize: number;
12
+ ratio: number;
13
+ method: string;
14
+ patternsFound: number;
15
+ memoriesCompressed: number;
16
+ constructor(init?: CompressionStatsInit);
17
+ get savingsPercent(): number;
18
+ }
19
+ export type MemoryRecord = Record<string, unknown> & {
20
+ content?: string;
21
+ timestamp?: string;
22
+ created_at?: string;
23
+ source?: string;
24
+ };
25
+ export declare class MemoryCompressor {
26
+ readonly dictionary: Readonly<Record<string, string>>;
27
+ constructor(dictionary?: Readonly<Record<string, string>>);
28
+ static buildDefaultDict(): Record<string, string>;
29
+ compress(content: string, method?: string): readonly [string, CompressionStats];
30
+ private dictCompress;
31
+ private rleCompress;
32
+ private semanticCompressSingle;
33
+ compressBatch(memories: readonly MemoryRecord[], method?: string): readonly [MemoryRecord[], CompressionStats];
34
+ decompress(content: string, method?: string): string;
35
+ }
36
+ export interface DetectedPatternInit {
37
+ readonly patternType?: string;
38
+ readonly pattern_type?: string;
39
+ readonly description: string;
40
+ readonly confidence: number;
41
+ readonly samples?: readonly string[];
42
+ readonly metadata?: Record<string, unknown>;
43
+ }
44
+ export declare class DetectedPattern {
45
+ patternType: string;
46
+ description: string;
47
+ confidence: number;
48
+ samples: string[];
49
+ metadata: Record<string, unknown>;
50
+ constructor(init: DetectedPatternInit);
51
+ toDict(): Record<string, unknown>;
52
+ }
53
+ export declare class PatternDetector {
54
+ readonly minConfidence: number;
55
+ constructor(minConfidence?: number);
56
+ detectTemporal(memories: readonly MemoryRecord[]): DetectedPattern[];
57
+ detectContent(memories: readonly MemoryRecord[]): DetectedPattern[];
58
+ detectSequence(memories: readonly MemoryRecord[]): DetectedPattern[];
59
+ detectAll(memories: readonly MemoryRecord[]): DetectedPattern[];
60
+ summarizePatterns(memories: readonly MemoryRecord[]): Record<string, unknown>;
61
+ }
@@ -0,0 +1,109 @@
1
+ export declare const DEFAULT_PLUGIN_DIR: string;
2
+ export type PluginConfig = Record<string, unknown>;
3
+ export type MemoryDict = Record<string, unknown>;
4
+ export declare class MnemopiPlugin {
5
+ static readonly abstractBase = true;
6
+ name: string;
7
+ version: string;
8
+ enabled: boolean;
9
+ protected initialized: boolean;
10
+ readonly config: PluginConfig;
11
+ constructor(config?: PluginConfig);
12
+ initialize(): void;
13
+ shutdown(): void;
14
+ onRemember(_memory: MemoryDict): void;
15
+ onRecall(_memory: MemoryDict): void;
16
+ onConsolidate(_summary: MemoryDict): void;
17
+ onInvalidate(_memoryId: string): void;
18
+ toDict(): Record<string, unknown>;
19
+ }
20
+ export declare class LoggingPlugin extends MnemopiPlugin {
21
+ name: string;
22
+ version: string;
23
+ private readonly memoryLog;
24
+ private readonly maxEntries;
25
+ constructor(config?: PluginConfig);
26
+ private append;
27
+ onRemember(memory: MemoryDict): void;
28
+ onRecall(memory: MemoryDict): void;
29
+ onConsolidate(summary: MemoryDict): void;
30
+ onInvalidate(memoryId: string): void;
31
+ getLog(): MemoryDict[];
32
+ clearLog(): void;
33
+ }
34
+ export declare class MetricsPlugin extends MnemopiPlugin {
35
+ name: string;
36
+ version: string;
37
+ private readonly counters;
38
+ private readonly timings;
39
+ private readonly maxTimingSamples;
40
+ constructor(config?: PluginConfig);
41
+ onRemember(_memory: MemoryDict): void;
42
+ onRecall(_memory: MemoryDict): void;
43
+ onConsolidate(_summary: MemoryDict): void;
44
+ onInvalidate(_memoryId: string): void;
45
+ recordTiming(event: string, durationMs: number): void;
46
+ getCounters(): Record<string, number>;
47
+ getTimings(event: string): number[];
48
+ getAverageTiming(event: string): number | null;
49
+ reset(): void;
50
+ getSummary(): Record<string, unknown>;
51
+ }
52
+ export type FilterRule = (item: MemoryDict) => boolean;
53
+ export declare class FilterPlugin extends MnemopiPlugin {
54
+ name: string;
55
+ version: string;
56
+ private readonly rules;
57
+ private readonly blocked;
58
+ private readonly maxBlocked;
59
+ constructor(config?: PluginConfig);
60
+ addRule(rule: FilterRule): void;
61
+ removeRule(rule: FilterRule): void;
62
+ clearRules(): void;
63
+ onRemember(memory: MemoryDict): void;
64
+ onRecall(memory: MemoryDict): void;
65
+ onConsolidate(summary: MemoryDict): void;
66
+ onInvalidate(_memoryId: string): void;
67
+ private passes;
68
+ private block;
69
+ getBlocked(): MemoryDict[];
70
+ isBlocked(memoryId: string): boolean;
71
+ }
72
+ export declare class CompressionPlugin extends MnemopiPlugin {
73
+ name: string;
74
+ version: string;
75
+ enabled: boolean;
76
+ private readonly threshold;
77
+ constructor(config?: PluginConfig);
78
+ compressLines(lines: string[]): string[];
79
+ onRemember(_memory: MemoryDict): void;
80
+ onRecall(_memory: MemoryDict): void;
81
+ onConsolidate(_summary: MemoryDict): void;
82
+ onInvalidate(_memoryId: string): void;
83
+ }
84
+ export type PluginConstructor<T extends MnemopiPlugin = MnemopiPlugin> = new (config?: PluginConfig) => T;
85
+ export declare class PluginManager {
86
+ private readonly pluginDir;
87
+ private readonly registry;
88
+ private readonly instances;
89
+ constructor(pluginDir?: string);
90
+ registerPlugin(name: string, pluginClass: PluginConstructor): void;
91
+ loadPlugin(name: string, config?: PluginConfig): MnemopiPlugin;
92
+ unloadPlugin(name: string): void;
93
+ listPlugins(): Array<Record<string, unknown>>;
94
+ getPlugin(name: string): MnemopiPlugin | null;
95
+ isLoaded(name: string): boolean;
96
+ isRegistered(name: string): boolean;
97
+ loadAll(configs?: Record<string, PluginConfig>): MnemopiPlugin[];
98
+ unloadAll(): void;
99
+ discoverPlugins(): string[];
100
+ notifyRemember(memory: MemoryDict): void;
101
+ notifyRecall(memory: MemoryDict): void;
102
+ notifyConsolidate(summary: MemoryDict): void;
103
+ notifyInvalidate(memoryId: string): void;
104
+ }
105
+ export declare class ValueError extends Error {
106
+ name: string;
107
+ }
108
+ export declare function getManager(): PluginManager;
109
+ export declare function resetManager(): void;