@equationalapplications/core-llm-wiki 2.4.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/LICENSE +21 -0
- package/README.md +133 -0
- package/dist/index.d.mts +212 -0
- package/dist/index.d.ts +212 -0
- package/dist/index.js +1383 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +1377 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +42 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Equational Applications
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
# @equationalapplications/core-llm-wiki
|
|
2
|
+
|
|
3
|
+
Pure TypeScript business logic for LLM Wiki Memory.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Platform-agnostic** — Zero runtime dependencies; works with any SQLite driver via the `SQLiteAdapter` interface
|
|
8
|
+
- **Full-featured memory** — Facts, tasks, events, semantic search, maintenance jobs
|
|
9
|
+
- **Type-safe** — Built with TypeScript, full type exports
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm install @equationalapplications/core-llm-wiki
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
```typescript
|
|
20
|
+
import { WikiMemory, type SQLiteAdapter } from '@equationalapplications/core-llm-wiki';
|
|
21
|
+
|
|
22
|
+
// Provide any SQLiteAdapter-compatible driver
|
|
23
|
+
const wikiMemory = new WikiMemory(db, {
|
|
24
|
+
llmProvider: {
|
|
25
|
+
generateText: async ({ systemPrompt, userPrompt }) => {
|
|
26
|
+
// Your LLM call here
|
|
27
|
+
return 'Model output';
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
// Initialize schema and run migrations
|
|
33
|
+
await wikiMemory.setup();
|
|
34
|
+
|
|
35
|
+
// Store facts
|
|
36
|
+
await wikiMemory.write('user-123', {
|
|
37
|
+
event_type: 'observation',
|
|
38
|
+
summary: 'User prefers async/await over promises',
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
// Query memory
|
|
42
|
+
const memory = await wikiMemory.read('user-123', 'coding style preferences');
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Adapter Interface
|
|
46
|
+
|
|
47
|
+
Implement `SQLiteAdapter` to use your platform's SQLite driver:
|
|
48
|
+
|
|
49
|
+
```typescript
|
|
50
|
+
export interface SQLiteAdapter {
|
|
51
|
+
execAsync(sql: string): Promise<void>;
|
|
52
|
+
runAsync(sql: string, params?: unknown[]): Promise<{ changes: number; lastInsertRowId: number }>;
|
|
53
|
+
getAllAsync<T>(sql: string, params?: unknown[]): Promise<T[]>;
|
|
54
|
+
getFirstAsync<T>(sql: string, params?: unknown[]): Promise<T | null>;
|
|
55
|
+
withTransactionAsync<T>(fn: () => Promise<T>): Promise<T>;
|
|
56
|
+
closeAsync(): Promise<void>;
|
|
57
|
+
}
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
`@equationalapplications/expo-llm-wiki` provides a pre-built adapter for Expo/React Native. For web and Node.js, implement the interface yourself — examples below.
|
|
61
|
+
|
|
62
|
+
**Browser (sql.js):**
|
|
63
|
+
|
|
64
|
+
```typescript
|
|
65
|
+
import initSqlJs from 'sql.js';
|
|
66
|
+
import type { SQLiteAdapter } from '@equationalapplications/core-llm-wiki';
|
|
67
|
+
|
|
68
|
+
const SQL = await initSqlJs({ locateFile: (f) => `/wasm/${f}` });
|
|
69
|
+
const sqlDb = new SQL.Database();
|
|
70
|
+
|
|
71
|
+
const adapter: SQLiteAdapter = {
|
|
72
|
+
async execAsync(sql) { sqlDb.run(sql); },
|
|
73
|
+
async runAsync(sql, params = []) {
|
|
74
|
+
sqlDb.run(sql, params as any[]);
|
|
75
|
+
// sql.js doesn't expose lastInsertRowId; hardcode 0 since WikiMemory uses internal ID generation
|
|
76
|
+
return { changes: sqlDb.getRowsModified(), lastInsertRowId: 0 };
|
|
77
|
+
},
|
|
78
|
+
async getAllAsync<T>(sql, params = []) {
|
|
79
|
+
const stmt = sqlDb.prepare(sql);
|
|
80
|
+
stmt.bind(params as any[]);
|
|
81
|
+
const rows: T[] = [];
|
|
82
|
+
while (stmt.step()) rows.push(stmt.getAsObject() as T);
|
|
83
|
+
stmt.free();
|
|
84
|
+
return rows;
|
|
85
|
+
},
|
|
86
|
+
async getFirstAsync<T>(sql, params = []) {
|
|
87
|
+
const stmt = sqlDb.prepare(sql);
|
|
88
|
+
stmt.bind(params as any[]);
|
|
89
|
+
const row = stmt.step() ? stmt.getAsObject() as T : null;
|
|
90
|
+
stmt.free();
|
|
91
|
+
return row;
|
|
92
|
+
},
|
|
93
|
+
async withTransactionAsync(fn) {
|
|
94
|
+
sqlDb.run('BEGIN');
|
|
95
|
+
try { const r = await fn(); sqlDb.run('COMMIT'); return r; }
|
|
96
|
+
catch (e) { sqlDb.run('ROLLBACK'); throw e; }
|
|
97
|
+
},
|
|
98
|
+
async closeAsync() { sqlDb.close(); },
|
|
99
|
+
};
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
**Node.js (better-sqlite3):**
|
|
103
|
+
|
|
104
|
+
```typescript
|
|
105
|
+
import Database from 'better-sqlite3';
|
|
106
|
+
import type { SQLiteAdapter } from '@equationalapplications/core-llm-wiki';
|
|
107
|
+
|
|
108
|
+
const db = new Database('wiki.db');
|
|
109
|
+
|
|
110
|
+
const adapter: SQLiteAdapter = {
|
|
111
|
+
async execAsync(sql) { db.exec(sql); },
|
|
112
|
+
async runAsync(sql, params = []) {
|
|
113
|
+
const info = db.prepare(sql).run(...(params as any[]));
|
|
114
|
+
return { changes: info.changes, lastInsertRowId: Number(info.lastInsertRowid) };
|
|
115
|
+
},
|
|
116
|
+
async getAllAsync<T>(sql, params = []) {
|
|
117
|
+
return db.prepare(sql).all(...(params as any[])) as T[];
|
|
118
|
+
},
|
|
119
|
+
async getFirstAsync<T>(sql, params = []) {
|
|
120
|
+
return (db.prepare(sql).get(...(params as any[])) ?? null) as T | null;
|
|
121
|
+
},
|
|
122
|
+
async withTransactionAsync(fn) {
|
|
123
|
+
db.exec('BEGIN');
|
|
124
|
+
try { const r = await fn(); db.exec('COMMIT'); return r; }
|
|
125
|
+
catch (e) { db.exec('ROLLBACK'); throw e; }
|
|
126
|
+
},
|
|
127
|
+
async closeAsync() { db.close(); },
|
|
128
|
+
};
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
## License
|
|
132
|
+
|
|
133
|
+
MIT
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Platform-agnostic SQLite driver interface.
|
|
3
|
+
* Each platform package (wiki-expo, wiki-react) provides an adapter
|
|
4
|
+
* that wraps its native driver behind this interface.
|
|
5
|
+
*/
|
|
6
|
+
interface SQLiteAdapter {
|
|
7
|
+
execAsync(sql: string): Promise<void>;
|
|
8
|
+
runAsync(sql: string, params?: unknown[]): Promise<{
|
|
9
|
+
changes: number;
|
|
10
|
+
lastInsertRowId: number;
|
|
11
|
+
}>;
|
|
12
|
+
getAllAsync<T>(sql: string, params?: unknown[]): Promise<T[]>;
|
|
13
|
+
getFirstAsync<T>(sql: string, params?: unknown[]): Promise<T | null>;
|
|
14
|
+
withTransactionAsync<T>(fn: () => Promise<T>): Promise<T>;
|
|
15
|
+
closeAsync(): Promise<void>;
|
|
16
|
+
}
|
|
17
|
+
interface WikiConfig {
|
|
18
|
+
tablePrefix?: string;
|
|
19
|
+
maxFtsResults?: number;
|
|
20
|
+
pruneEventsAfter?: number;
|
|
21
|
+
pruneRetainSoftDeletedFor?: number;
|
|
22
|
+
autoLibrarianThreshold?: number;
|
|
23
|
+
autoHealThreshold?: number;
|
|
24
|
+
orphanAfterDays?: number | null;
|
|
25
|
+
staleInferredAfterDays?: number | null;
|
|
26
|
+
maxChunkLength?: number;
|
|
27
|
+
chunkOverlap?: number;
|
|
28
|
+
chunkConcurrency?: number;
|
|
29
|
+
/**
|
|
30
|
+
* Static caller-supplied synonym expansions applied at query time.
|
|
31
|
+
* Keys must match the same normalization pipeline used by query formatting:
|
|
32
|
+
* the query is lowercased, stripped to `[a-z0-9 ]`, split into tokens, and
|
|
33
|
+
* only tokens with length >= 3 are considered for synonym lookup.
|
|
34
|
+
* Values are appended to the FTS5 query token list (multi-word values are
|
|
35
|
+
* split into tokens), then deduped and sliced to 12.
|
|
36
|
+
*/
|
|
37
|
+
synonymMap?: Record<string, string[]>;
|
|
38
|
+
}
|
|
39
|
+
interface WikiFact {
|
|
40
|
+
id: string;
|
|
41
|
+
entity_id: string;
|
|
42
|
+
title: string;
|
|
43
|
+
body: string;
|
|
44
|
+
tags: string[];
|
|
45
|
+
confidence: 'certain' | 'inferred' | 'tentative';
|
|
46
|
+
source_type: 'user_stated' | 'agent_inferred' | 'user_confirmed' | 'user_document';
|
|
47
|
+
source_hash: string | null;
|
|
48
|
+
source_ref: string | null;
|
|
49
|
+
created_at: number;
|
|
50
|
+
updated_at: number;
|
|
51
|
+
last_accessed_at: number | null;
|
|
52
|
+
access_count: number;
|
|
53
|
+
deleted_at: number | null;
|
|
54
|
+
}
|
|
55
|
+
interface WikiTask {
|
|
56
|
+
id: string;
|
|
57
|
+
entity_id: string;
|
|
58
|
+
description: string;
|
|
59
|
+
status: 'pending' | 'in_progress' | 'done' | 'abandoned';
|
|
60
|
+
priority: number;
|
|
61
|
+
created_at: number;
|
|
62
|
+
updated_at: number;
|
|
63
|
+
resolved_at: number | null;
|
|
64
|
+
deleted_at: number | null;
|
|
65
|
+
}
|
|
66
|
+
interface WikiEvent {
|
|
67
|
+
id: string;
|
|
68
|
+
entity_id: string;
|
|
69
|
+
event_type: 'observation' | 'decision' | 'action' | 'outcome';
|
|
70
|
+
summary: string;
|
|
71
|
+
related_entry_id?: string | null;
|
|
72
|
+
created_at: number;
|
|
73
|
+
}
|
|
74
|
+
interface WikiCheckpoint {
|
|
75
|
+
entity_id: string;
|
|
76
|
+
heal_checkpoint: number;
|
|
77
|
+
memory_checkpoint: number;
|
|
78
|
+
}
|
|
79
|
+
interface ExtractedFact {
|
|
80
|
+
title: string;
|
|
81
|
+
body: string;
|
|
82
|
+
tags: string[];
|
|
83
|
+
confidence: 'certain' | 'inferred' | 'tentative';
|
|
84
|
+
}
|
|
85
|
+
interface ExtractedTask {
|
|
86
|
+
description: string;
|
|
87
|
+
priority: number;
|
|
88
|
+
}
|
|
89
|
+
interface LLMProvider {
|
|
90
|
+
/**
|
|
91
|
+
* Generates text using the developer's LLM of choice.
|
|
92
|
+
* Expected to return the raw text response (typically a JSON string).
|
|
93
|
+
*/
|
|
94
|
+
generateText: (params: {
|
|
95
|
+
systemPrompt: string;
|
|
96
|
+
userPrompt: string;
|
|
97
|
+
}) => Promise<string>;
|
|
98
|
+
}
|
|
99
|
+
interface WikiOptions {
|
|
100
|
+
config?: WikiConfig;
|
|
101
|
+
llmProvider: LLMProvider;
|
|
102
|
+
}
|
|
103
|
+
interface MemoryBundle {
|
|
104
|
+
facts: WikiFact[];
|
|
105
|
+
tasks: WikiTask[];
|
|
106
|
+
events: WikiEvent[];
|
|
107
|
+
}
|
|
108
|
+
interface MemoryDump {
|
|
109
|
+
generatedAt: number;
|
|
110
|
+
entities: Record<string, MemoryBundle>;
|
|
111
|
+
}
|
|
112
|
+
interface FormattedMemoryDump {
|
|
113
|
+
manifest: string;
|
|
114
|
+
files: Array<{
|
|
115
|
+
name: string;
|
|
116
|
+
content: string;
|
|
117
|
+
}>;
|
|
118
|
+
}
|
|
119
|
+
interface FormatContextOptions {
|
|
120
|
+
format?: 'markdown' | 'plain';
|
|
121
|
+
maxFacts?: number;
|
|
122
|
+
maxTasks?: number;
|
|
123
|
+
maxEvents?: number;
|
|
124
|
+
includeConfidence?: boolean;
|
|
125
|
+
includeTags?: boolean;
|
|
126
|
+
factWeights?: {
|
|
127
|
+
confidence?: number;
|
|
128
|
+
accessCount?: number;
|
|
129
|
+
recency?: number;
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
interface EntityStatus {
|
|
133
|
+
ingesting: boolean;
|
|
134
|
+
librarian: boolean;
|
|
135
|
+
heal: boolean;
|
|
136
|
+
}
|
|
137
|
+
declare class WikiBusyError extends Error {
|
|
138
|
+
readonly operation: 'ingest' | 'librarian' | 'heal' | 'prune';
|
|
139
|
+
readonly entityId: string;
|
|
140
|
+
constructor(operation: 'ingest' | 'librarian' | 'heal' | 'prune', entityId: string);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
declare class WikiMemory {
|
|
144
|
+
private db;
|
|
145
|
+
private prefix;
|
|
146
|
+
private options;
|
|
147
|
+
private activeMaintenanceJobs;
|
|
148
|
+
private activeIngestJobs;
|
|
149
|
+
private _librarianKey;
|
|
150
|
+
private _healKey;
|
|
151
|
+
private _warnCrossEntityCollision;
|
|
152
|
+
constructor(db: SQLiteAdapter, options: WikiOptions);
|
|
153
|
+
setup(): Promise<void>;
|
|
154
|
+
hasChanged(entityId: string, sourceRef: string, sourceHash: string): Promise<boolean>;
|
|
155
|
+
private _pruneKey;
|
|
156
|
+
private _validatePruneDuration;
|
|
157
|
+
runPrune(entityId: string, options?: {
|
|
158
|
+
retainSoftDeletedFor?: number | null;
|
|
159
|
+
retainEventsFor?: number | null;
|
|
160
|
+
vacuum?: boolean;
|
|
161
|
+
}): Promise<{
|
|
162
|
+
entries: number;
|
|
163
|
+
tasks: number;
|
|
164
|
+
events: number;
|
|
165
|
+
}>;
|
|
166
|
+
private formatSearchQuery;
|
|
167
|
+
read(entityId: string, query: string): Promise<MemoryBundle>;
|
|
168
|
+
getMemoryBundle(entityId: string): Promise<MemoryBundle>;
|
|
169
|
+
write(entityId: string, event: Omit<WikiEvent, 'id' | 'entity_id' | 'created_at'>): Promise<void>;
|
|
170
|
+
private runLibrarianThenMaybeHeal;
|
|
171
|
+
private _doRunLibrarian;
|
|
172
|
+
private _doRunHeal;
|
|
173
|
+
runLibrarian(entityId: string): Promise<void>;
|
|
174
|
+
runHeal(entityId: string): Promise<void>;
|
|
175
|
+
getEntityStatus(entityId: string): EntityStatus;
|
|
176
|
+
private _getFullBundle;
|
|
177
|
+
exportDump(entityIds?: string[]): Promise<MemoryDump>;
|
|
178
|
+
importDump(dump: MemoryDump, opts?: {
|
|
179
|
+
merge?: boolean;
|
|
180
|
+
}): Promise<void>;
|
|
181
|
+
forget(entityId: string, params: {
|
|
182
|
+
entryId?: string;
|
|
183
|
+
taskId?: string;
|
|
184
|
+
sourceRef?: string;
|
|
185
|
+
sourceHash?: string;
|
|
186
|
+
clearAll?: boolean;
|
|
187
|
+
}): Promise<{
|
|
188
|
+
deleted: {
|
|
189
|
+
entries: number;
|
|
190
|
+
tasks: number;
|
|
191
|
+
};
|
|
192
|
+
}>;
|
|
193
|
+
ingestDocument(entityId: string, params: {
|
|
194
|
+
sourceRef: string;
|
|
195
|
+
sourceHash: string;
|
|
196
|
+
documentChunk: string;
|
|
197
|
+
maxChunkLength?: number;
|
|
198
|
+
chunkOverlap?: number;
|
|
199
|
+
chunkConcurrency?: number;
|
|
200
|
+
}): Promise<{
|
|
201
|
+
truncated: boolean;
|
|
202
|
+
chunks: number;
|
|
203
|
+
}>;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
declare function formatContext(bundle: MemoryBundle, options?: FormatContextOptions): string;
|
|
207
|
+
|
|
208
|
+
declare function formatMemoryDump(dump: MemoryDump): FormattedMemoryDump;
|
|
209
|
+
|
|
210
|
+
declare function createWiki(db: SQLiteAdapter, options: WikiOptions): WikiMemory;
|
|
211
|
+
|
|
212
|
+
export { type EntityStatus, type ExtractedFact, type ExtractedTask, type FormatContextOptions, type FormattedMemoryDump, type LLMProvider, type MemoryBundle, type MemoryDump, type SQLiteAdapter, WikiBusyError, type WikiCheckpoint, type WikiConfig, type WikiEvent, type WikiFact, WikiMemory, type WikiOptions, type WikiTask, createWiki, formatContext, formatMemoryDump };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Platform-agnostic SQLite driver interface.
|
|
3
|
+
* Each platform package (wiki-expo, wiki-react) provides an adapter
|
|
4
|
+
* that wraps its native driver behind this interface.
|
|
5
|
+
*/
|
|
6
|
+
interface SQLiteAdapter {
|
|
7
|
+
execAsync(sql: string): Promise<void>;
|
|
8
|
+
runAsync(sql: string, params?: unknown[]): Promise<{
|
|
9
|
+
changes: number;
|
|
10
|
+
lastInsertRowId: number;
|
|
11
|
+
}>;
|
|
12
|
+
getAllAsync<T>(sql: string, params?: unknown[]): Promise<T[]>;
|
|
13
|
+
getFirstAsync<T>(sql: string, params?: unknown[]): Promise<T | null>;
|
|
14
|
+
withTransactionAsync<T>(fn: () => Promise<T>): Promise<T>;
|
|
15
|
+
closeAsync(): Promise<void>;
|
|
16
|
+
}
|
|
17
|
+
interface WikiConfig {
|
|
18
|
+
tablePrefix?: string;
|
|
19
|
+
maxFtsResults?: number;
|
|
20
|
+
pruneEventsAfter?: number;
|
|
21
|
+
pruneRetainSoftDeletedFor?: number;
|
|
22
|
+
autoLibrarianThreshold?: number;
|
|
23
|
+
autoHealThreshold?: number;
|
|
24
|
+
orphanAfterDays?: number | null;
|
|
25
|
+
staleInferredAfterDays?: number | null;
|
|
26
|
+
maxChunkLength?: number;
|
|
27
|
+
chunkOverlap?: number;
|
|
28
|
+
chunkConcurrency?: number;
|
|
29
|
+
/**
|
|
30
|
+
* Static caller-supplied synonym expansions applied at query time.
|
|
31
|
+
* Keys must match the same normalization pipeline used by query formatting:
|
|
32
|
+
* the query is lowercased, stripped to `[a-z0-9 ]`, split into tokens, and
|
|
33
|
+
* only tokens with length >= 3 are considered for synonym lookup.
|
|
34
|
+
* Values are appended to the FTS5 query token list (multi-word values are
|
|
35
|
+
* split into tokens), then deduped and sliced to 12.
|
|
36
|
+
*/
|
|
37
|
+
synonymMap?: Record<string, string[]>;
|
|
38
|
+
}
|
|
39
|
+
interface WikiFact {
|
|
40
|
+
id: string;
|
|
41
|
+
entity_id: string;
|
|
42
|
+
title: string;
|
|
43
|
+
body: string;
|
|
44
|
+
tags: string[];
|
|
45
|
+
confidence: 'certain' | 'inferred' | 'tentative';
|
|
46
|
+
source_type: 'user_stated' | 'agent_inferred' | 'user_confirmed' | 'user_document';
|
|
47
|
+
source_hash: string | null;
|
|
48
|
+
source_ref: string | null;
|
|
49
|
+
created_at: number;
|
|
50
|
+
updated_at: number;
|
|
51
|
+
last_accessed_at: number | null;
|
|
52
|
+
access_count: number;
|
|
53
|
+
deleted_at: number | null;
|
|
54
|
+
}
|
|
55
|
+
interface WikiTask {
|
|
56
|
+
id: string;
|
|
57
|
+
entity_id: string;
|
|
58
|
+
description: string;
|
|
59
|
+
status: 'pending' | 'in_progress' | 'done' | 'abandoned';
|
|
60
|
+
priority: number;
|
|
61
|
+
created_at: number;
|
|
62
|
+
updated_at: number;
|
|
63
|
+
resolved_at: number | null;
|
|
64
|
+
deleted_at: number | null;
|
|
65
|
+
}
|
|
66
|
+
interface WikiEvent {
|
|
67
|
+
id: string;
|
|
68
|
+
entity_id: string;
|
|
69
|
+
event_type: 'observation' | 'decision' | 'action' | 'outcome';
|
|
70
|
+
summary: string;
|
|
71
|
+
related_entry_id?: string | null;
|
|
72
|
+
created_at: number;
|
|
73
|
+
}
|
|
74
|
+
interface WikiCheckpoint {
|
|
75
|
+
entity_id: string;
|
|
76
|
+
heal_checkpoint: number;
|
|
77
|
+
memory_checkpoint: number;
|
|
78
|
+
}
|
|
79
|
+
interface ExtractedFact {
|
|
80
|
+
title: string;
|
|
81
|
+
body: string;
|
|
82
|
+
tags: string[];
|
|
83
|
+
confidence: 'certain' | 'inferred' | 'tentative';
|
|
84
|
+
}
|
|
85
|
+
interface ExtractedTask {
|
|
86
|
+
description: string;
|
|
87
|
+
priority: number;
|
|
88
|
+
}
|
|
89
|
+
interface LLMProvider {
|
|
90
|
+
/**
|
|
91
|
+
* Generates text using the developer's LLM of choice.
|
|
92
|
+
* Expected to return the raw text response (typically a JSON string).
|
|
93
|
+
*/
|
|
94
|
+
generateText: (params: {
|
|
95
|
+
systemPrompt: string;
|
|
96
|
+
userPrompt: string;
|
|
97
|
+
}) => Promise<string>;
|
|
98
|
+
}
|
|
99
|
+
interface WikiOptions {
|
|
100
|
+
config?: WikiConfig;
|
|
101
|
+
llmProvider: LLMProvider;
|
|
102
|
+
}
|
|
103
|
+
interface MemoryBundle {
|
|
104
|
+
facts: WikiFact[];
|
|
105
|
+
tasks: WikiTask[];
|
|
106
|
+
events: WikiEvent[];
|
|
107
|
+
}
|
|
108
|
+
interface MemoryDump {
|
|
109
|
+
generatedAt: number;
|
|
110
|
+
entities: Record<string, MemoryBundle>;
|
|
111
|
+
}
|
|
112
|
+
interface FormattedMemoryDump {
|
|
113
|
+
manifest: string;
|
|
114
|
+
files: Array<{
|
|
115
|
+
name: string;
|
|
116
|
+
content: string;
|
|
117
|
+
}>;
|
|
118
|
+
}
|
|
119
|
+
interface FormatContextOptions {
|
|
120
|
+
format?: 'markdown' | 'plain';
|
|
121
|
+
maxFacts?: number;
|
|
122
|
+
maxTasks?: number;
|
|
123
|
+
maxEvents?: number;
|
|
124
|
+
includeConfidence?: boolean;
|
|
125
|
+
includeTags?: boolean;
|
|
126
|
+
factWeights?: {
|
|
127
|
+
confidence?: number;
|
|
128
|
+
accessCount?: number;
|
|
129
|
+
recency?: number;
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
interface EntityStatus {
|
|
133
|
+
ingesting: boolean;
|
|
134
|
+
librarian: boolean;
|
|
135
|
+
heal: boolean;
|
|
136
|
+
}
|
|
137
|
+
declare class WikiBusyError extends Error {
|
|
138
|
+
readonly operation: 'ingest' | 'librarian' | 'heal' | 'prune';
|
|
139
|
+
readonly entityId: string;
|
|
140
|
+
constructor(operation: 'ingest' | 'librarian' | 'heal' | 'prune', entityId: string);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
declare class WikiMemory {
|
|
144
|
+
private db;
|
|
145
|
+
private prefix;
|
|
146
|
+
private options;
|
|
147
|
+
private activeMaintenanceJobs;
|
|
148
|
+
private activeIngestJobs;
|
|
149
|
+
private _librarianKey;
|
|
150
|
+
private _healKey;
|
|
151
|
+
private _warnCrossEntityCollision;
|
|
152
|
+
constructor(db: SQLiteAdapter, options: WikiOptions);
|
|
153
|
+
setup(): Promise<void>;
|
|
154
|
+
hasChanged(entityId: string, sourceRef: string, sourceHash: string): Promise<boolean>;
|
|
155
|
+
private _pruneKey;
|
|
156
|
+
private _validatePruneDuration;
|
|
157
|
+
runPrune(entityId: string, options?: {
|
|
158
|
+
retainSoftDeletedFor?: number | null;
|
|
159
|
+
retainEventsFor?: number | null;
|
|
160
|
+
vacuum?: boolean;
|
|
161
|
+
}): Promise<{
|
|
162
|
+
entries: number;
|
|
163
|
+
tasks: number;
|
|
164
|
+
events: number;
|
|
165
|
+
}>;
|
|
166
|
+
private formatSearchQuery;
|
|
167
|
+
read(entityId: string, query: string): Promise<MemoryBundle>;
|
|
168
|
+
getMemoryBundle(entityId: string): Promise<MemoryBundle>;
|
|
169
|
+
write(entityId: string, event: Omit<WikiEvent, 'id' | 'entity_id' | 'created_at'>): Promise<void>;
|
|
170
|
+
private runLibrarianThenMaybeHeal;
|
|
171
|
+
private _doRunLibrarian;
|
|
172
|
+
private _doRunHeal;
|
|
173
|
+
runLibrarian(entityId: string): Promise<void>;
|
|
174
|
+
runHeal(entityId: string): Promise<void>;
|
|
175
|
+
getEntityStatus(entityId: string): EntityStatus;
|
|
176
|
+
private _getFullBundle;
|
|
177
|
+
exportDump(entityIds?: string[]): Promise<MemoryDump>;
|
|
178
|
+
importDump(dump: MemoryDump, opts?: {
|
|
179
|
+
merge?: boolean;
|
|
180
|
+
}): Promise<void>;
|
|
181
|
+
forget(entityId: string, params: {
|
|
182
|
+
entryId?: string;
|
|
183
|
+
taskId?: string;
|
|
184
|
+
sourceRef?: string;
|
|
185
|
+
sourceHash?: string;
|
|
186
|
+
clearAll?: boolean;
|
|
187
|
+
}): Promise<{
|
|
188
|
+
deleted: {
|
|
189
|
+
entries: number;
|
|
190
|
+
tasks: number;
|
|
191
|
+
};
|
|
192
|
+
}>;
|
|
193
|
+
ingestDocument(entityId: string, params: {
|
|
194
|
+
sourceRef: string;
|
|
195
|
+
sourceHash: string;
|
|
196
|
+
documentChunk: string;
|
|
197
|
+
maxChunkLength?: number;
|
|
198
|
+
chunkOverlap?: number;
|
|
199
|
+
chunkConcurrency?: number;
|
|
200
|
+
}): Promise<{
|
|
201
|
+
truncated: boolean;
|
|
202
|
+
chunks: number;
|
|
203
|
+
}>;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
declare function formatContext(bundle: MemoryBundle, options?: FormatContextOptions): string;
|
|
207
|
+
|
|
208
|
+
declare function formatMemoryDump(dump: MemoryDump): FormattedMemoryDump;
|
|
209
|
+
|
|
210
|
+
declare function createWiki(db: SQLiteAdapter, options: WikiOptions): WikiMemory;
|
|
211
|
+
|
|
212
|
+
export { type EntityStatus, type ExtractedFact, type ExtractedTask, type FormatContextOptions, type FormattedMemoryDump, type LLMProvider, type MemoryBundle, type MemoryDump, type SQLiteAdapter, WikiBusyError, type WikiCheckpoint, type WikiConfig, type WikiEvent, type WikiFact, WikiMemory, type WikiOptions, type WikiTask, createWiki, formatContext, formatMemoryDump };
|