@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.
Files changed (126) hide show
  1. package/README.md +107 -0
  2. package/dist/types/cli.d.ts +35 -0
  3. package/dist/types/config.d.ts +77 -0
  4. package/dist/types/core/aaak.d.ts +55 -0
  5. package/dist/types/core/annotations.d.ts +75 -0
  6. package/dist/types/core/banks.d.ts +33 -0
  7. package/dist/types/core/beam/consolidate.d.ts +32 -0
  8. package/dist/types/core/beam/helpers.d.ts +59 -0
  9. package/dist/types/core/beam/index.d.ts +59 -0
  10. package/dist/types/core/beam/recall.d.ts +32 -0
  11. package/dist/types/core/beam/schema.d.ts +2 -0
  12. package/dist/types/core/beam/store.d.ts +35 -0
  13. package/dist/types/core/beam/types.d.ts +233 -0
  14. package/dist/types/core/binary-vectors.d.ts +54 -0
  15. package/dist/types/core/chat-normalize.d.ts +13 -0
  16. package/dist/types/core/content-sanitizer.d.ts +18 -0
  17. package/dist/types/core/cost-log.d.ts +13 -0
  18. package/dist/types/core/embeddings.d.ts +35 -0
  19. package/dist/types/core/entities.d.ts +7 -0
  20. package/dist/types/core/episodic-graph.d.ts +89 -0
  21. package/dist/types/core/extraction/client.d.ts +31 -0
  22. package/dist/types/core/extraction/diagnostics.d.ts +51 -0
  23. package/dist/types/core/extraction/prompts.d.ts +2 -0
  24. package/dist/types/core/extraction.d.ts +6 -0
  25. package/dist/types/core/index.d.ts +4 -0
  26. package/dist/types/core/llm-backends.d.ts +21 -0
  27. package/dist/types/core/local-llm.d.ts +15 -0
  28. package/dist/types/core/memory.d.ts +160 -0
  29. package/dist/types/core/migrations/e6-triplestore-split.d.ts +17 -0
  30. package/dist/types/core/migrations/index.d.ts +1 -0
  31. package/dist/types/core/mmr.d.ts +8 -0
  32. package/dist/types/core/orchestrator.d.ts +20 -0
  33. package/dist/types/core/patterns.d.ts +61 -0
  34. package/dist/types/core/plugins.d.ts +109 -0
  35. package/dist/types/core/polyphonic-recall.d.ts +66 -0
  36. package/dist/types/core/query-cache.d.ts +47 -0
  37. package/dist/types/core/query-intent.d.ts +20 -0
  38. package/dist/types/core/recall-diagnostics.d.ts +48 -0
  39. package/dist/types/core/runtime-options.d.ts +61 -0
  40. package/dist/types/core/shmr.d.ts +56 -0
  41. package/dist/types/core/streaming.d.ts +136 -0
  42. package/dist/types/core/synonyms.d.ts +46 -0
  43. package/dist/types/core/temporal-parser.d.ts +16 -0
  44. package/dist/types/core/token-counter.d.ts +8 -0
  45. package/dist/types/core/triples.d.ts +63 -0
  46. package/dist/types/core/typed-memory.d.ts +39 -0
  47. package/dist/types/core/veracity-consolidation.d.ts +60 -0
  48. package/dist/types/core/weibull.d.ts +96 -0
  49. package/dist/types/db.d.ts +16 -0
  50. package/dist/types/diagnose.d.ts +24 -0
  51. package/dist/types/dr/index.d.ts +1 -0
  52. package/dist/types/dr/recovery.d.ts +68 -0
  53. package/dist/types/index.d.ts +5 -0
  54. package/dist/types/mcp-server.d.ts +40 -0
  55. package/dist/types/mcp-tools.d.ts +484 -0
  56. package/dist/types/migrations/e6-triplestore-split.d.ts +1 -0
  57. package/dist/types/migrations/index.d.ts +1 -0
  58. package/dist/types/types.d.ts +145 -0
  59. package/dist/types/util/datetime.d.ts +8 -0
  60. package/dist/types/util/env.d.ts +10 -0
  61. package/dist/types/util/ids.d.ts +3 -0
  62. package/dist/types/util/lru.d.ts +12 -0
  63. package/dist/types/util/regex.d.ts +10 -0
  64. package/package.json +82 -0
  65. package/src/cli.ts +390 -0
  66. package/src/config.ts +326 -0
  67. package/src/core/aaak.ts +142 -0
  68. package/src/core/annotations.ts +457 -0
  69. package/src/core/banks.ts +133 -0
  70. package/src/core/beam/consolidate.ts +963 -0
  71. package/src/core/beam/helpers.ts +920 -0
  72. package/src/core/beam/index.ts +353 -0
  73. package/src/core/beam/recall.ts +1091 -0
  74. package/src/core/beam/schema.ts +423 -0
  75. package/src/core/beam/store.ts +818 -0
  76. package/src/core/beam/types.ts +268 -0
  77. package/src/core/binary-vectors.ts +336 -0
  78. package/src/core/chat-normalize.ts +160 -0
  79. package/src/core/content-sanitizer.ts +136 -0
  80. package/src/core/cost-log.ts +103 -0
  81. package/src/core/embeddings.ts +490 -0
  82. package/src/core/entities.ts +259 -0
  83. package/src/core/episodic-graph.ts +708 -0
  84. package/src/core/extraction/client.ts +162 -0
  85. package/src/core/extraction/diagnostics.ts +193 -0
  86. package/src/core/extraction/prompts.ts +31 -0
  87. package/src/core/extraction.ts +335 -0
  88. package/src/core/index.ts +30 -0
  89. package/src/core/llm-backends.ts +51 -0
  90. package/src/core/local-llm.ts +436 -0
  91. package/src/core/memory.ts +617 -0
  92. package/src/core/migrations/e6-triplestore-split.ts +211 -0
  93. package/src/core/migrations/index.ts +1 -0
  94. package/src/core/mmr.ts +71 -0
  95. package/src/core/orchestrator.ts +53 -0
  96. package/src/core/patterns.ts +484 -0
  97. package/src/core/plugins.ts +375 -0
  98. package/src/core/polyphonic-recall.ts +563 -0
  99. package/src/core/query-cache.ts +370 -0
  100. package/src/core/query-intent.ts +139 -0
  101. package/src/core/recall-diagnostics.ts +157 -0
  102. package/src/core/runtime-options.ts +108 -0
  103. package/src/core/shmr.ts +471 -0
  104. package/src/core/streaming.ts +419 -0
  105. package/src/core/synonyms.ts +197 -0
  106. package/src/core/temporal-parser.ts +363 -0
  107. package/src/core/token-counter.ts +30 -0
  108. package/src/core/triples.ts +452 -0
  109. package/src/core/typed-memory.ts +407 -0
  110. package/src/core/veracity-consolidation.ts +477 -0
  111. package/src/core/weibull.ts +124 -0
  112. package/src/db.ts +128 -0
  113. package/src/diagnose.ts +174 -0
  114. package/src/dr/index.ts +1 -0
  115. package/src/dr/recovery.ts +405 -0
  116. package/src/index.ts +32 -0
  117. package/src/mcp-server.ts +155 -0
  118. package/src/mcp-tools.ts +961 -0
  119. package/src/migrations/e6-triplestore-split.ts +1 -0
  120. package/src/migrations/index.ts +1 -0
  121. package/src/types.ts +157 -0
  122. package/src/util/datetime.ts +69 -0
  123. package/src/util/env.ts +65 -0
  124. package/src/util/ids.ts +19 -0
  125. package/src/util/lru.ts +48 -0
  126. package/src/util/regex.ts +165 -0
@@ -0,0 +1,233 @@
1
+ import type { Database } from "bun:sqlite";
2
+ export type JsonPrimitive = string | number | boolean | null;
3
+ export type JsonValue = JsonPrimitive | JsonValue[] | {
4
+ [key: string]: JsonValue;
5
+ };
6
+ export type Metadata = Record<string, JsonValue>;
7
+ export type MemoryScope = "global" | "session" | "channel" | string;
8
+ export type TrustTier = "STATED" | "OBSERVED" | "INFERRED" | "SYSTEM" | string;
9
+ export type Veracity = "unknown" | "likely_true" | "true" | "false" | "stated" | "inferred" | "tool" | "imported" | "contested" | string;
10
+ export interface BeamPluginManager {
11
+ emit?(event: BeamEvent): void | Promise<void>;
12
+ close?(): void | Promise<void>;
13
+ }
14
+ export interface AnnotationStoreLike {
15
+ add?(memoryId: string, kind: string, value: string, options?: AnnotationWriteOptions): unknown;
16
+ addMany?(memoryId: string, kind: string, values: readonly string[], options?: AnnotationWriteOptions): unknown;
17
+ queryByMemory?(memoryId: string, kind?: string): unknown;
18
+ queryByKind?(kind: string, value?: string): unknown;
19
+ getDistinctValues?(kind: string): string[];
20
+ }
21
+ export interface TripleStoreLike {
22
+ add?(subject: string, predicate: string, object: string, options?: TripleWriteOptions): unknown;
23
+ query?(subject?: string, predicate?: string, asOf?: string): unknown;
24
+ }
25
+ export interface BeamCaches {
26
+ timestampParse: Map<string, Date>;
27
+ polyphonicEngine?: unknown;
28
+ extractionClient?: unknown;
29
+ extractionBuffer: unknown[];
30
+ [key: string]: unknown;
31
+ }
32
+ export interface BeamConfig {
33
+ workingMemoryLimit: number;
34
+ workingMemoryTtlHours: number;
35
+ recencyHalflifeHours: number;
36
+ vecWeight: number;
37
+ ftsWeight: number;
38
+ importanceWeight: number;
39
+ useCloud: boolean;
40
+ localLlmEnabled: boolean;
41
+ }
42
+ export interface BeamMemoryOptions {
43
+ sessionId?: string;
44
+ dbPath?: string;
45
+ authorId?: string | null;
46
+ authorType?: string | null;
47
+ channelId?: string | null;
48
+ useCloud?: boolean;
49
+ eventEmitter?: (event: BeamEvent) => void;
50
+ pluginManager?: BeamPluginManager | null;
51
+ annotations?: AnnotationStoreLike | null;
52
+ triples?: TripleStoreLike | null;
53
+ config?: Partial<BeamConfig>;
54
+ }
55
+ export interface BeamMemoryState {
56
+ db: Database;
57
+ dbPath?: string;
58
+ sessionId: string;
59
+ authorId: string | null;
60
+ authorType: string | null;
61
+ channelId: string;
62
+ useCloud: boolean;
63
+ eventEmitter?: (event: BeamEvent) => void;
64
+ pluginManager: BeamPluginManager | null;
65
+ annotations: AnnotationStoreLike | null;
66
+ triples: TripleStoreLike | null;
67
+ episodicGraph: unknown | null;
68
+ veracityConsolidator: unknown | null;
69
+ caches: BeamCaches;
70
+ config: BeamConfig;
71
+ /** Tracks in-flight background fact-extraction tasks scheduled by `remember(..., { extract: true })`. */
72
+ pendingExtractions?: Set<Promise<void>>;
73
+ }
74
+ export interface AnnotationWriteOptions {
75
+ source?: string;
76
+ confidence?: number;
77
+ }
78
+ export interface TripleWriteOptions {
79
+ validFrom?: string;
80
+ source?: string;
81
+ confidence?: number;
82
+ }
83
+ export interface BeamEvent {
84
+ type: string;
85
+ memoryId?: string;
86
+ content?: string;
87
+ source?: string;
88
+ importance?: number;
89
+ sessionId: string;
90
+ timestamp: string;
91
+ metadata?: Metadata;
92
+ }
93
+ export interface RememberOptions {
94
+ source?: string;
95
+ importance?: number;
96
+ metadata?: Metadata | null;
97
+ extract?: boolean;
98
+ extractEntities?: boolean;
99
+ veracity?: Veracity;
100
+ memoryType?: string;
101
+ scope?: MemoryScope;
102
+ trustTier?: TrustTier;
103
+ timestamp?: string;
104
+ }
105
+ export interface RememberBatchOptions {
106
+ extract?: boolean;
107
+ extractEntities?: boolean;
108
+ veracity?: Veracity;
109
+ memoryType?: string;
110
+ scope?: MemoryScope;
111
+ trustTier?: TrustTier;
112
+ }
113
+ export interface RememberBatchItem extends RememberOptions {
114
+ content: string;
115
+ }
116
+ export interface RecallOptions {
117
+ fromDate?: string | null;
118
+ toDate?: string | null;
119
+ authorId?: string | null;
120
+ authorType?: string | null;
121
+ channelId?: string | null;
122
+ includeWorking?: boolean;
123
+ queryTime?: string | Date | null;
124
+ temporalWeight?: number;
125
+ temporalHalflife?: number;
126
+ vecWeight?: number;
127
+ ftsWeight?: number;
128
+ importanceWeight?: number;
129
+ queryEmbedding?: readonly number[] | null;
130
+ useSynonyms?: boolean;
131
+ useIntent?: boolean;
132
+ useMmr?: boolean;
133
+ mmrLambda?: number;
134
+ }
135
+ export interface RecallEnhancedOptions extends RecallOptions {
136
+ useCache?: boolean;
137
+ includeFacts?: boolean;
138
+ }
139
+ export interface MemoryRow {
140
+ id: string;
141
+ content: string;
142
+ source: string | null;
143
+ timestamp: string | null;
144
+ session_id: string;
145
+ importance: number;
146
+ metadata_json: string | null;
147
+ veracity: Veracity;
148
+ memory_type?: string | null;
149
+ recall_count?: number;
150
+ last_recalled?: string | null;
151
+ valid_until?: string | null;
152
+ superseded_by?: string | null;
153
+ scope?: MemoryScope;
154
+ author_id?: string | null;
155
+ author_type?: string | null;
156
+ channel_id?: string | null;
157
+ trust_tier?: TrustTier;
158
+ validator?: string | null;
159
+ validated_at?: string | null;
160
+ validation_count?: number;
161
+ event_date?: string | null;
162
+ event_date_precision?: string | null;
163
+ temporal_tags?: string | null;
164
+ corrected_by?: number | null;
165
+ created_at: string;
166
+ }
167
+ export interface WorkingMemoryRow extends MemoryRow {
168
+ consolidated_at?: string | null;
169
+ }
170
+ export interface EpisodicMemoryRow extends MemoryRow {
171
+ rowid: number;
172
+ summary_of: string;
173
+ tier: number;
174
+ degraded_at?: string | null;
175
+ binary_vector?: Uint8Array | null;
176
+ }
177
+ export type RecallTierLabel = "working" | "episodic" | "fact" | string;
178
+ export interface RecallVoiceScores {
179
+ vec?: number;
180
+ fts?: number;
181
+ keyword?: number;
182
+ importance?: number;
183
+ recency_decay?: number;
184
+ temporal?: number;
185
+ [key: string]: number | undefined;
186
+ }
187
+ type RecallRowFields = Omit<Partial<EpisodicMemoryRow>, "tier"> & Partial<WorkingMemoryRow>;
188
+ export type RecallResult = RecallRowFields & {
189
+ [key: string]: unknown;
190
+ id: string;
191
+ content: string;
192
+ score?: number;
193
+ distance?: number;
194
+ rank?: number;
195
+ tier?: RecallTierLabel;
196
+ tier_label?: RecallTierLabel;
197
+ degradation_tier?: number;
198
+ keyword_score?: number;
199
+ dense_score?: number;
200
+ fts_score?: number;
201
+ importance_score?: number;
202
+ recency_score?: number;
203
+ temporal_score?: number;
204
+ explanation?: string;
205
+ voice_scores?: RecallVoiceScores;
206
+ metadata?: Metadata;
207
+ };
208
+ export interface BeamStats {
209
+ count: number;
210
+ by_source?: Record<string, number>;
211
+ by_session?: Record<string, number>;
212
+ oldest?: string | null;
213
+ newest?: string | null;
214
+ [key: string]: JsonValue | Record<string, number> | undefined;
215
+ }
216
+ export interface MemoriaRetrieveResult {
217
+ ability: string;
218
+ query: string;
219
+ results: unknown[];
220
+ }
221
+ export interface SleepResult {
222
+ dry_run: boolean;
223
+ sessions?: Record<string, unknown>;
224
+ items_consolidated?: number;
225
+ [key: string]: unknown;
226
+ }
227
+ export interface ImportStats {
228
+ working_memory: Record<string, number>;
229
+ episodic_memory: Record<string, number>;
230
+ scratchpad: Record<string, number>;
231
+ consolidation_log: Record<string, number>;
232
+ }
233
+ export {};
@@ -0,0 +1,54 @@
1
+ import type { Database } from "bun:sqlite";
2
+ import { type VecType } from "../config";
3
+ import { type DatabasePath } from "../db";
4
+ export declare const BITS_PER_BYTE = 8;
5
+ export declare const EMBEDDING_DIM: number;
6
+ export declare const BYTES_PER_VECTOR: number;
7
+ export interface BinaryVectorSearchResult {
8
+ memory_id: string;
9
+ distance: number;
10
+ score: number;
11
+ }
12
+ export interface BinaryVectorStats {
13
+ total_vectors: number;
14
+ avg_bytes_per_vector: number;
15
+ max_bytes: number;
16
+ min_bytes: number;
17
+ compression_ratio: number;
18
+ theoretical_size_mb: number;
19
+ }
20
+ export interface BinaryVectorStoreOptions {
21
+ dbPath?: DatabasePath;
22
+ tableName?: string;
23
+ conn?: Database;
24
+ }
25
+ export declare function getVecType(env?: NodeJS.ProcessEnv): VecType;
26
+ export declare const VEC_TYPE: VecType;
27
+ export declare function quantizeInt8(embedding: readonly number[]): Int8Array;
28
+ export declare function maximallyInformativeBinarization(embedding: readonly number[]): Uint8Array;
29
+ export declare function hammingDistance(binaryA: Uint8Array | ArrayBuffer, binaryB: Uint8Array | ArrayBuffer): number;
30
+ export declare function informationTheoreticScore(distance: number, dim?: number): number;
31
+ export declare function cosineSimilarity(a: readonly number[], b: readonly number[]): number;
32
+ export declare class BinaryVectorStore {
33
+ readonly conn: Database;
34
+ readonly dbPath: DatabasePath;
35
+ readonly tableName: string;
36
+ private readonly ownsConnection;
37
+ constructor(options?: BinaryVectorStoreOptions);
38
+ private initTable;
39
+ static maximallyInformativeBinarization(embedding: readonly number[]): Uint8Array;
40
+ static hammingDistance(binaryA: Uint8Array | ArrayBuffer, binaryB: Uint8Array | ArrayBuffer): number;
41
+ static informationTheoreticScore(distance: number, dim?: number): number;
42
+ storeVector(memoryId: string, embedding: readonly number[]): void;
43
+ search(queryEmbedding: readonly number[], topK?: number): BinaryVectorSearchResult[];
44
+ searchBatch(queryEmbeddings: readonly (readonly number[])[], topK?: number): BinaryVectorSearchResult[][];
45
+ deleteVector(memoryId: string): void;
46
+ getStats(): BinaryVectorStats;
47
+ close(): void;
48
+ }
49
+ export declare class FastBinarySearch {
50
+ private readonly memoryIds;
51
+ private readonly vectors;
52
+ constructor(binaryVectors: ReadonlyMap<string, Uint8Array | ArrayBuffer> | Record<string, Uint8Array | ArrayBuffer>);
53
+ search(queryBinary: Uint8Array | ArrayBuffer, topK?: number): BinaryVectorSearchResult[];
54
+ }
@@ -0,0 +1,13 @@
1
+ type ExtractionRate = {
2
+ total: number;
3
+ survived: number;
4
+ dropped: number;
5
+ rate: number;
6
+ dropped_samples: string[];
7
+ };
8
+ export declare function normalizeChat(text: string, options?: {
9
+ add_implicit_subjects?: boolean;
10
+ }): string | null;
11
+ export declare function normalizeBatch(messages: string[]): (string | null)[];
12
+ export declare function extractionRate(messages: string[]): ExtractionRate;
13
+ export {};
@@ -0,0 +1,18 @@
1
+ export declare const SIZE_HARD_CAP = 1000000;
2
+ export declare const SIZE_BASE64_CHECK = 100000;
3
+ export declare const ENTROPY_THRESHOLD = 5;
4
+ export interface BlobMetadata {
5
+ blob_ref?: string;
6
+ original_size?: number;
7
+ mime?: string;
8
+ extraction_reason?: "data_uri" | "size_cap" | "high_entropy";
9
+ entropy?: number;
10
+ }
11
+ export declare function blobRoot(env?: NodeJS.ProcessEnv): string;
12
+ export declare function computeSha256(data: Uint8Array | string): string;
13
+ export declare function isDataUri(content: string): boolean;
14
+ export declare function parseDataUri(content: string): [mimeType: string, raw: Buffer] | null;
15
+ export declare function shannonEntropy(text: string): number;
16
+ export declare function looksLikeBase64Blob(content: string): boolean;
17
+ export declare function storeBlob(rawBytes: Uint8Array): string;
18
+ export declare function sanitizeContent(content: string): [sanitizedContent: string, blobMetadata: BlobMetadata];
@@ -0,0 +1,13 @@
1
+ import { Database } from "bun:sqlite";
2
+ export declare const DEFAULT_LOG_DIR: string;
3
+ export declare const DEFAULT_LOG_DB: string;
4
+ export interface CostStats {
5
+ total_calls: number;
6
+ total_memories_injected: number;
7
+ total_tokens: number;
8
+ total_estimated_cost_usd: number;
9
+ }
10
+ export declare function getConn(dbPath?: string): Database;
11
+ export declare function initCostLog(dbPath?: string): void;
12
+ export declare function logCost(sessionId: string, memoryCount: number, tokenCount: number, estimatedCostUsd: number, model?: string, dbPath?: string): void;
13
+ export declare function getCostStats(sessionId?: string, dbPath?: string): CostStats;
@@ -0,0 +1,35 @@
1
+ import { EmbeddingModel } from "fastembed";
2
+ export type Vector = number[];
3
+ export type EmbeddingMatrix = Vector[];
4
+ export interface EmbeddingProvider {
5
+ embed(texts: readonly string[]): unknown | Promise<unknown>;
6
+ available?(): boolean | Promise<boolean>;
7
+ }
8
+ type StandardEmbeddingModel = Exclude<EmbeddingModel, EmbeddingModel.CUSTOM>;
9
+ interface LocalEmbeddingModel {
10
+ embed(texts: string[], batchSize?: number): unknown;
11
+ queryEmbed?(query: string): Promise<number[]>;
12
+ }
13
+ type LocalModelInitOptions = {
14
+ model: StandardEmbeddingModel;
15
+ cacheDir?: string;
16
+ showDownloadProgress?: boolean;
17
+ };
18
+ type LocalModelInitializer = (options: LocalModelInitOptions) => Promise<LocalEmbeddingModel>;
19
+ export declare function isApiModel(modelName: string): boolean;
20
+ export declare function embeddingDimFor(modelName: string): number;
21
+ export declare function setEmbeddingProviderForTests(provider: EmbeddingProvider | null | undefined): void;
22
+ export declare const setEmbeddingProvider: typeof setEmbeddingProviderForTests;
23
+ export declare function setLocalModelInitializerForTests(initializer: LocalModelInitializer | null | undefined): void;
24
+ export declare function resetEmbeddingProviderForTests(): void;
25
+ export declare const resetEmbeddingStateForTests: typeof resetEmbeddingProviderForTests;
26
+ export declare function available(): Promise<boolean>;
27
+ export declare function availableApi(): boolean;
28
+ export declare function embedQuery(text: string): Promise<Vector | null>;
29
+ export declare function embed(texts: readonly string[]): Promise<EmbeddingMatrix | null>;
30
+ export declare function serialize(vec: readonly number[]): string;
31
+ export declare function cosineSimilarity(a: readonly number[], b: readonly number[]): number;
32
+ export declare function getEmbeddingApiCallCountForTests(): number;
33
+ export declare const DEFAULT_MODEL: string;
34
+ export declare const EMBEDDING_DIM: number;
35
+ export {};
@@ -0,0 +1,7 @@
1
+ export declare const ENTITY_EXTRACTION_STOP_WORDS: ReadonlySet<string>;
2
+ export declare function levenshteinDistance(s1: string, s2: string): number;
3
+ export declare function similarity(s1: string, s2: string): number;
4
+ export declare function extractEntitiesRegex(text: string): string[];
5
+ export type SimilarEntity = readonly [entity: string, score: number];
6
+ export declare function findSimilarEntities(entity: string, knownEntities: readonly string[], threshold?: number): SimilarEntity[];
7
+ export declare function entityExtractionPerformance(text: string, iterations?: number): number;
@@ -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,31 @@
1
+ export declare const DEFAULT_EXTRACTION_MODEL: string;
2
+ export declare const OPENROUTER_BASE_URL: string;
3
+ export declare const FALLBACK_MODELS: readonly ["google/gemini-flash-latest"];
4
+ export interface ChatMessage {
5
+ role: string;
6
+ content: string;
7
+ }
8
+ export interface ExtractedFact {
9
+ subject?: string;
10
+ predicate?: string;
11
+ object?: string;
12
+ timestamp?: string;
13
+ source?: number;
14
+ confidence?: number;
15
+ [key: string]: unknown;
16
+ }
17
+ export declare class ExtractionClient {
18
+ model: string;
19
+ apiKey: string;
20
+ baseUrl: string;
21
+ callCount: number;
22
+ constructor(opts?: {
23
+ model?: string | null;
24
+ apiKey?: string | null;
25
+ baseUrl?: string | null;
26
+ });
27
+ chat(messages: readonly ChatMessage[], temperature?: number, maxTokens?: number): Promise<string>;
28
+ callApi(model: string, messages: readonly ChatMessage[], temperature: number, maxTokens: number): Promise<string>;
29
+ extractFacts(messages: readonly ChatMessage[]): Promise<ExtractedFact[]>;
30
+ xtractFacts(messages: readonly ChatMessage[]): Promise<ExtractedFact[]>;
31
+ }
@@ -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,6 @@
1
+ export declare const EXTRACTION_PROMPT_TEMPLATE: string;
2
+ export declare function buildExtractionPrompt(text: string, detectedLang?: string): string;
3
+ export declare function parseFacts(rawOutput: string | null | undefined): string[];
4
+ export declare function heuristicExtractFacts(text: string): string[];
5
+ export declare function extractFacts(text: string | null | undefined): Promise<string[]>;
6
+ export declare function extractFactsSafe(text: string | null | undefined): Promise<string[]>;
@@ -0,0 +1,4 @@
1
+ export * from "./banks";
2
+ export * from "./beam/index";
3
+ export * from "./memory";
4
+ export { addMemory, forget, get, getBank, getContext, getDefaultInstance, getStats, Mnemosyne, query, recall, recallEnhanced, remember, resetDefaultInstanceForTests, resetMemoryForTests, resetModuleStateForTests, saveMemory, scratchpadClear, scratchpadRead, scratchpadWrite, search, setBank, sleep, sleepAllSessions, storeMemory, update, } from "./memory";
@@ -0,0 +1,21 @@
1
+ export interface CompleteOptions {
2
+ maxTokens?: number;
3
+ temperature?: number;
4
+ timeout?: number;
5
+ provider?: string | null;
6
+ model?: string | null;
7
+ }
8
+ export interface LlmBackend {
9
+ name?: string;
10
+ complete(prompt: string, opts?: CompleteOptions): string | null | Promise<string | null>;
11
+ }
12
+ export declare function setHostLlmBackend(backend: LlmBackend | null | undefined): void;
13
+ export declare function getHostLlmBackend(): LlmBackend | null;
14
+ export declare function resetHostLlmBackendForTests(): void;
15
+ export declare function callHostLlm(prompt: string, opts?: CompleteOptions): Promise<string | null>;
16
+ export declare class CallableLlmBackend implements LlmBackend {
17
+ name: string;
18
+ private readonly fn;
19
+ constructor(name: string, fn: (prompt: string, opts?: CompleteOptions) => string | null | Promise<string | null>);
20
+ complete(prompt: string, opts?: CompleteOptions): string | null | Promise<string | null>;
21
+ }
@@ -0,0 +1,15 @@
1
+ import { type MnemosyneLlmCompleteOptions } from "./runtime-options";
2
+ export declare const DEFAULT_MODEL_REPO: string;
3
+ export declare const DEFAULT_MODEL_FILE: string;
4
+ export declare function buildPrompt(memories: readonly string[], source?: string): string;
5
+ export declare function callConfiguredCompletion(prompt: string, temperature: number, opts?: MnemosyneLlmCompleteOptions): Promise<string | null>;
6
+ export declare function buildHostPrompt(memories: readonly string[], source?: string): string;
7
+ export declare function configuredLlmWillHandleCall(): boolean;
8
+ export declare function cleanOutput(text: string): string;
9
+ export declare function chunkMemoriesByBudget(memories: readonly string[], source?: string): string[][];
10
+ export declare function llmAvailable(): boolean;
11
+ export declare function callRemoteLlm(prompt: string, temperature?: number): Promise<string | null>;
12
+ export declare function localGgufAvailable(): false;
13
+ export declare function callLocalLlm(_prompt: string): Promise<string | null>;
14
+ export declare function summarizeMemories(memories: readonly string[], source?: string): Promise<string | null>;
15
+ export declare function complete(prompt: string, temperature?: number): Promise<string | null>;