@dikolab/kbdb 0.1.6 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +30 -9
- package/dist/cli.cjs +181 -50
- package/dist/cli.cjs.map +3 -3
- package/dist/cli.mjs +181 -50
- package/dist/cli.mjs.map +3 -3
- package/dist/kbdb-worker.cjs +283 -29
- package/dist/kbdb-worker.cjs.map +4 -4
- package/dist/mod.cjs +13 -2
- package/dist/mod.cjs.map +2 -2
- package/dist/mod.mjs +13 -2
- package/dist/mod.mjs.map +2 -2
- package/dist/src/shared/cli/functions/format-output.function.d.ts +7 -7
- package/dist/src/shared/cli/functions/run-search.function.d.ts +25 -16
- package/dist/src/shared/cli/index.d.ts +1 -1
- package/dist/src/shared/cli/typings/cli-options.interface.d.ts +2 -0
- package/dist/src/shared/cli/typings/search-display.model.d.ts +25 -7
- package/dist/src/shared/mcp/functions/handle-recall.function.d.ts +29 -0
- package/dist/src/shared/mcp/typings/mcp-client.interface.d.ts +30 -11
- package/dist/src/shared/version/constants/version.constant.d.ts +1 -1
- package/dist/src/shared/wasm-codec/functions/decode-recall-result.function.d.ts +28 -0
- package/dist/src/shared/wasm-codec/functions/decode-scored-results.function.d.ts +14 -7
- package/dist/src/shared/wasm-codec/functions/encode-recall-params.function.d.ts +21 -0
- package/dist/src/shared/wasm-codec/functions/encode-search-params.function.d.ts +1 -1
- package/dist/src/shared/wasm-codec/index.d.ts +5 -2
- package/dist/src/shared/worker-client/classes/worker-client.class.d.ts +13 -3
- package/dist/src/shared/worker-client/index.d.ts +2 -1
- package/dist/src/shared/worker-client/typings/recall-result.model.d.ts +94 -0
- package/dist/src/shared/worker-client/typings/search-params.model.d.ts +2 -0
- package/dist/src/shared/worker-client/typings/search-result.model.d.ts +23 -7
- package/dist/src/shared/worker-daemon/classes/worker-daemon.class.d.ts +1 -0
- package/dist/wasm/fs-database/kbdb_fs_database.d.ts +18 -0
- package/dist/wasm/fs-database/kbdb_fs_database.js +30 -0
- package/dist/wasm/fs-database/kbdb_fs_database_bg.wasm +0 -0
- package/dist/wasm/fs-database/kbdb_fs_database_bg.wasm.d.ts +2 -0
- package/dist/wasm/kb-worker/kbdb_worker.d.ts +38 -0
- package/dist/wasm/kb-worker/kbdb_worker.js +56 -0
- package/dist/wasm/kb-worker/kbdb_worker_bg.wasm +0 -0
- package/dist/wasm/kb-worker/kbdb_worker_bg.wasm.d.ts +3 -0
- package/dist/worker.mjs +283 -29
- package/dist/worker.mjs.map +4 -4
- package/docs/details/README.md +26 -0
- package/docs/details/cli.md +608 -0
- package/docs/details/library-api.md +406 -0
- package/docs/details/mcp-server.md +430 -0
- package/docs/details/search-and-ranking.md +457 -0
- package/docs/details/storage.md +529 -0
- package/docs/goals/agents.md +751 -0
- package/docs/goals/architecture.svg +198 -0
- package/docs/goals/cli.md +2308 -0
- package/docs/goals/content-composer.md +609 -0
- package/docs/goals/content-parser.md +279 -0
- package/docs/goals/database.md +1452 -0
- package/docs/goals/document.md +368 -0
- package/docs/goals/mcp.md +1467 -0
- package/docs/goals/overview.md +124 -0
- package/docs/goals/query-parser.md +271 -0
- package/docs/goals/query-result.md +693 -0
- package/docs/goals/skills.md +738 -0
- package/docs/goals/worker-client.md +944 -0
- package/docs/goals/worker-daemon.md +1447 -0
- package/docs/modules/overview.md +298 -0
- package/docs/modules/rust/fs-database/functions/document.md +48 -0
- package/docs/modules/rust/fs-database/functions/integrity.md +68 -0
- package/docs/modules/rust/fs-database/functions/io.md +87 -0
- package/docs/modules/rust/fs-database/functions/module.md +22 -0
- package/docs/modules/rust/fs-database/functions/query-exec.md +44 -0
- package/docs/modules/rust/fs-database/functions/section.md +59 -0
- package/docs/modules/rust/fs-database/indexes/btree.md +35 -0
- package/docs/modules/rust/fs-database/indexes/corpus.md +61 -0
- package/docs/modules/rust/fs-database/indexes/inverted.md +60 -0
- package/docs/modules/rust/fs-database/indexes/module.md +64 -0
- package/docs/modules/rust/fs-database/indexes/positional.md +39 -0
- package/docs/modules/rust/fs-database/module.md +149 -0
- package/docs/modules/rust/fs-database/types/catalog.md +53 -0
- package/docs/modules/rust/fs-database/types/module.md +12 -0
- package/docs/modules/rust/fs-database/types/section.md +101 -0
- package/docs/modules/rust/kb-worker/functions/compose.md +57 -0
- package/docs/modules/rust/kb-worker/functions/module.md +20 -0
- package/docs/modules/rust/kb-worker/functions/retrieve.md +194 -0
- package/docs/modules/rust/kb-worker/functions/search.md +173 -0
- package/docs/modules/rust/kb-worker/functions/write.md +172 -0
- package/docs/modules/rust/kb-worker/module.md +171 -0
- package/docs/modules/rust/kb-worker/types/cache.md +90 -0
- package/docs/modules/rust/kb-worker/types/context.md +26 -0
- package/docs/modules/rust/kb-worker/types/module.md +16 -0
- package/docs/modules/rust/kb-worker/types/status.md +29 -0
- package/docs/modules/rust/kb-worker/types/token.md +50 -0
- package/docs/modules/rust/overview.md +495 -0
- package/docs/modules/rust/query-parser/functions/extract.md +56 -0
- package/docs/modules/rust/query-parser/functions/module.md +16 -0
- package/docs/modules/rust/query-parser/functions/parse.md +33 -0
- package/docs/modules/rust/query-parser/functions/pipeline.md +103 -0
- package/docs/modules/rust/query-parser/functions/rank.md +85 -0
- package/docs/modules/rust/query-parser/module.md +136 -0
- package/docs/modules/rust/query-parser/types/cache.md +39 -0
- package/docs/modules/rust/query-parser/types/keyphrase.md +60 -0
- package/docs/modules/rust/query-parser/types/module.md +17 -0
- package/docs/modules/rust/query-parser/types/token.md +42 -0
- package/docs/modules/rust/shared/content-composer/functions.md +114 -0
- package/docs/modules/rust/shared/content-composer/module.md +147 -0
- package/docs/modules/rust/shared/content-composer/types.md +93 -0
- package/docs/modules/rust/shared/content-parser/functions.md +72 -0
- package/docs/modules/rust/shared/content-parser/module.md +99 -0
- package/docs/modules/rust/shared/content-parser/types.md +71 -0
- package/docs/modules/rust/shared/corpus/module.md +24 -0
- package/docs/modules/rust/shared/corpus/types.md +141 -0
- package/docs/modules/rust/shared/document/module.md +25 -0
- package/docs/modules/rust/shared/document/types.md +154 -0
- package/docs/modules/rust/shared/encode/module.md +22 -0
- package/docs/modules/rust/shared/encode/traits.md +304 -0
- package/docs/modules/rust/shared/error/module.md +28 -0
- package/docs/modules/rust/shared/error/types.md +302 -0
- package/docs/modules/rust/shared/kbid/module.md +24 -0
- package/docs/modules/rust/shared/kbid/types.md +147 -0
- package/docs/modules/rust/shared/memory/functions.md +209 -0
- package/docs/modules/rust/shared/memory/module.md +24 -0
- package/docs/modules/rust/shared/module.md +168 -0
- package/docs/modules/rust/shared/query/module.md +27 -0
- package/docs/modules/rust/shared/query/types.md +236 -0
- package/docs/modules/rust/shared/section/module.md +25 -0
- package/docs/modules/rust/shared/section/types.md +294 -0
- package/docs/modules/rust/shared/term/module.md +25 -0
- package/docs/modules/rust/shared/term/types.md +139 -0
- package/docs/modules/typescript/cli.md +129 -0
- package/docs/modules/typescript/kbdb-worker.md +135 -0
- package/docs/modules/typescript/overview.md +378 -0
- package/docs/modules/typescript/shared/cli/constants.md +23 -0
- package/docs/modules/typescript/shared/cli/functions.md +630 -0
- package/docs/modules/typescript/shared/cli/module.md +125 -0
- package/docs/modules/typescript/shared/cli/typings.md +172 -0
- package/docs/modules/typescript/shared/hash/functions.md +20 -0
- package/docs/modules/typescript/shared/hash/module.md +21 -0
- package/docs/modules/typescript/shared/mcp/classes.md +179 -0
- package/docs/modules/typescript/shared/mcp/functions.md +386 -0
- package/docs/modules/typescript/shared/mcp/module.md +160 -0
- package/docs/modules/typescript/shared/mcp/typings.md +522 -0
- package/docs/modules/typescript/shared/module.md +94 -0
- package/docs/modules/typescript/shared/platform/functions.md +42 -0
- package/docs/modules/typescript/shared/platform/module.md +25 -0
- package/docs/modules/typescript/shared/runtime/functions.md +26 -0
- package/docs/modules/typescript/shared/runtime/module.md +27 -0
- package/docs/modules/typescript/shared/runtime/typings.md +13 -0
- package/docs/modules/typescript/shared/version/module.md +27 -0
- package/docs/modules/typescript/shared/wasm-codec/functions.md +391 -0
- package/docs/modules/typescript/shared/wasm-codec/module.md +98 -0
- package/docs/modules/typescript/shared/worker-client/classes.md +264 -0
- package/docs/modules/typescript/shared/worker-client/functions.md +175 -0
- package/docs/modules/typescript/shared/worker-client/module.md +84 -0
- package/docs/modules/typescript/shared/worker-client/typings.md +508 -0
- package/docs/modules/typescript/shared/worker-daemon/classes.md +239 -0
- package/docs/modules/typescript/shared/worker-daemon/constants.md +37 -0
- package/docs/modules/typescript/shared/worker-daemon/functions.md +221 -0
- package/docs/modules/typescript/shared/worker-daemon/module.md +112 -0
- package/docs/modules/typescript/shared/worker-daemon/typings.md +126 -0
- package/docs/overview.md +188 -0
- package/docs/release-notes/0.1.0.md +189 -0
- package/docs/release-notes/0.1.1.md +46 -0
- package/docs/release-notes/0.1.2.md +38 -0
- package/docs/release-notes/0.1.3.md +42 -0
- package/docs/release-notes/0.2.0.md +147 -0
- package/docs/release-notes/README.md +9 -0
- package/package.json +8 -2
- package/src/shared/cli/functions/dispatch-command.function.ts +3 -3
- package/src/shared/cli/functions/format-output.function.ts +41 -34
- package/src/shared/cli/functions/parse-args.function.ts +7 -0
- package/src/shared/cli/functions/run-search.function.ts +53 -27
- package/src/shared/cli/index.ts +4 -1
- package/src/shared/cli/typings/cli-options.interface.ts +2 -0
- package/src/shared/cli/typings/search-display.model.ts +26 -7
- package/src/shared/mcp/functions/create-tool-definitions.function.ts +64 -4
- package/src/shared/mcp/functions/handle-recall.function.ts +66 -0
- package/src/shared/mcp/functions/handle-tool-call.function.ts +11 -1
- package/src/shared/mcp/typings/mcp-client.interface.ts +33 -15
- package/src/shared/version/constants/version.constant.ts +1 -1
- package/src/shared/wasm-codec/functions/decode-recall-result.function.ts +267 -0
- package/src/shared/wasm-codec/functions/decode-scored-results.function.ts +81 -27
- package/src/shared/wasm-codec/functions/encode-recall-params.function.ts +68 -0
- package/src/shared/wasm-codec/functions/encode-search-params.function.ts +4 -1
- package/src/shared/wasm-codec/index.ts +11 -3
- package/src/shared/worker-client/classes/worker-client.class.ts +24 -4
- package/src/shared/worker-client/index.ts +11 -1
- package/src/shared/worker-client/typings/recall-result.model.ts +98 -0
- package/src/shared/worker-client/typings/search-params.model.ts +2 -0
- package/src/shared/worker-client/typings/search-result.model.ts +24 -7
- package/src/shared/worker-daemon/classes/worker-daemon.class.ts +25 -4
- package/src/wasm/fs-database/kbdb_fs_database.d.ts +18 -0
- package/src/wasm/fs-database/kbdb_fs_database.js +30 -0
- package/src/wasm/fs-database/kbdb_fs_database_bg.wasm +0 -0
- package/src/wasm/fs-database/kbdb_fs_database_bg.wasm.d.ts +2 -0
- package/src/wasm/kb-worker/kbdb_worker.d.ts +38 -0
- package/src/wasm/kb-worker/kbdb_worker.js +56 -0
- package/src/wasm/kb-worker/kbdb_worker_bg.wasm +0 -0
- package/src/wasm/kb-worker/kbdb_worker_bg.wasm.d.ts +3 -0
|
@@ -0,0 +1,406 @@
|
|
|
1
|
+
# Library API Reference
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
kbdb can be used as a library in Node.js and Deno
|
|
6
|
+
projects. The main entry point is
|
|
7
|
+
`createWorkerClient()`, which connects to a
|
|
8
|
+
background worker daemon and returns a typed client
|
|
9
|
+
for all knowledge base operations.
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
npm install @dikolab/kbdb # Node.js
|
|
15
|
+
deno add @dikolab/kbdb # Deno
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Quick Start
|
|
19
|
+
|
|
20
|
+
```typescript
|
|
21
|
+
import { createWorkerClient } from '@dikolab/kbdb';
|
|
22
|
+
|
|
23
|
+
const client = await createWorkerClient({
|
|
24
|
+
contextPath: '/path/to/.kbdb',
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
const results = await client.search({
|
|
28
|
+
query: 'authentication',
|
|
29
|
+
limit: 10,
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
console.log(results);
|
|
33
|
+
client.disconnect();
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## API Reference
|
|
37
|
+
|
|
38
|
+
### Factory
|
|
39
|
+
|
|
40
|
+
#### `createWorkerClient(options?)`
|
|
41
|
+
|
|
42
|
+
Creates and connects a `WorkerClient` to the worker
|
|
43
|
+
daemon. Resolves the database path, discovers or
|
|
44
|
+
spawns the daemon, and returns a connected client.
|
|
45
|
+
|
|
46
|
+
```typescript
|
|
47
|
+
function createWorkerClient(
|
|
48
|
+
options?: WorkerClientOptions,
|
|
49
|
+
): Promise<WorkerClient>;
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
**Parameters:**
|
|
53
|
+
|
|
54
|
+
| Name | Type | Description |
|
|
55
|
+
|------|------|-------------|
|
|
56
|
+
| `options.dbPath` | `string?` | Directory containing `.kbdb`. Defaults to `cwd()`. |
|
|
57
|
+
| `options.contextPath` | `string?` | Absolute path to `.kbdb` directory. Skips discovery. |
|
|
58
|
+
| `options.autoSpawn` | `boolean?` | Auto-spawn daemon if not running. Default `true`. |
|
|
59
|
+
| `options.connectTimeoutMs` | `number?` | Max ms to wait for daemon. Default `10000`. |
|
|
60
|
+
| `options.workerScript` | `string?` | Path to worker daemon script. |
|
|
61
|
+
|
|
62
|
+
---
|
|
63
|
+
|
|
64
|
+
### Search
|
|
65
|
+
|
|
66
|
+
#### `search(params)`
|
|
67
|
+
|
|
68
|
+
Queries the knowledge base and returns ranked
|
|
69
|
+
results.
|
|
70
|
+
|
|
71
|
+
```typescript
|
|
72
|
+
search(params: SearchParams): Promise<SearchResult[]>
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
| Param | Type | Description |
|
|
76
|
+
|-------|------|-------------|
|
|
77
|
+
| `params.query` | `string` | Search query string. |
|
|
78
|
+
| `params.mode` | `'sections' \| 'documents' \| 'stats'?` | Entity type to return. Default `'sections'`. |
|
|
79
|
+
| `params.limit` | `number?` | Maximum results to return. |
|
|
80
|
+
|
|
81
|
+
---
|
|
82
|
+
|
|
83
|
+
### Sections
|
|
84
|
+
|
|
85
|
+
#### `readSections(kbids)`
|
|
86
|
+
|
|
87
|
+
Fetches sections by their knowledge-base
|
|
88
|
+
identifiers.
|
|
89
|
+
|
|
90
|
+
```typescript
|
|
91
|
+
readSections(kbids: string[]): Promise<Section[]>
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
#### `addSection(params)`
|
|
95
|
+
|
|
96
|
+
Imports content as a new section into the knowledge
|
|
97
|
+
base.
|
|
98
|
+
|
|
99
|
+
```typescript
|
|
100
|
+
addSection(
|
|
101
|
+
params: AddSectionParams,
|
|
102
|
+
): Promise<AddSectionResult>
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
| Param | Type | Description |
|
|
106
|
+
|-------|------|-------------|
|
|
107
|
+
| `params.sectionType` | `string` | Semantic type label for the section. |
|
|
108
|
+
| `params.content` | `string` | Raw text content. |
|
|
109
|
+
| `params.docid` | `string?` | Parent document to attach to. |
|
|
110
|
+
|
|
111
|
+
#### `updateSection(kbid, params)`
|
|
112
|
+
|
|
113
|
+
Replaces an existing section's content and metadata.
|
|
114
|
+
|
|
115
|
+
```typescript
|
|
116
|
+
updateSection(
|
|
117
|
+
kbid: string,
|
|
118
|
+
params: AddSectionParams,
|
|
119
|
+
): Promise<string>
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
Returns the knowledge-base identifier of the
|
|
123
|
+
updated section.
|
|
124
|
+
|
|
125
|
+
#### `removeSection(kbid)`
|
|
126
|
+
|
|
127
|
+
Deletes a section from the knowledge base.
|
|
128
|
+
|
|
129
|
+
```typescript
|
|
130
|
+
removeSection(kbid: string): Promise<RemoveSectionResult>
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
#### `listByType(sectionType)`
|
|
134
|
+
|
|
135
|
+
Retrieves all sections matching the given type name.
|
|
136
|
+
|
|
137
|
+
```typescript
|
|
138
|
+
listByType(sectionType: string): Promise<SectionRecord[]>
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
---
|
|
142
|
+
|
|
143
|
+
### Documents
|
|
144
|
+
|
|
145
|
+
#### `groupSections(title, kbids, docType?)`
|
|
146
|
+
|
|
147
|
+
Creates a document by grouping sections under a
|
|
148
|
+
title.
|
|
149
|
+
|
|
150
|
+
```typescript
|
|
151
|
+
groupSections(
|
|
152
|
+
title: string,
|
|
153
|
+
kbids: string[],
|
|
154
|
+
docType?: string,
|
|
155
|
+
): Promise<string>
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
Returns the assigned document identifier.
|
|
159
|
+
|
|
160
|
+
#### `removeGrouping(docid)`
|
|
161
|
+
|
|
162
|
+
Removes a document grouping. The sections themselves
|
|
163
|
+
are not deleted.
|
|
164
|
+
|
|
165
|
+
```typescript
|
|
166
|
+
removeGrouping(docid: string): Promise<void>
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
#### `retrieveDocument(docid)`
|
|
170
|
+
|
|
171
|
+
Fetches a full document record including its
|
|
172
|
+
sections.
|
|
173
|
+
|
|
174
|
+
```typescript
|
|
175
|
+
retrieveDocument(docid: string): Promise<unknown>
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
#### `listDocumentsByType(docType)`
|
|
179
|
+
|
|
180
|
+
Retrieves all documents matching the given type
|
|
181
|
+
name.
|
|
182
|
+
|
|
183
|
+
```typescript
|
|
184
|
+
listDocumentsByType(
|
|
185
|
+
docType: string,
|
|
186
|
+
): Promise<DocumentManifest[]>
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
---
|
|
190
|
+
|
|
191
|
+
### Content
|
|
192
|
+
|
|
193
|
+
#### `content(ids)`
|
|
194
|
+
|
|
195
|
+
Composes rendered Markdown from one or more kbid or
|
|
196
|
+
docid identifiers (may be mixed).
|
|
197
|
+
|
|
198
|
+
```typescript
|
|
199
|
+
content(ids: string[]): Promise<ContentResult>
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
Returns a `ContentResult` with the composed Markdown
|
|
203
|
+
string and character count.
|
|
204
|
+
|
|
205
|
+
---
|
|
206
|
+
|
|
207
|
+
### Maintenance
|
|
208
|
+
|
|
209
|
+
#### `integrityCheck()`
|
|
210
|
+
|
|
211
|
+
Verifies database integrity and reports all issues
|
|
212
|
+
found.
|
|
213
|
+
|
|
214
|
+
```typescript
|
|
215
|
+
integrityCheck(): Promise<IntegrityCheckResult>
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
#### `gc()`
|
|
219
|
+
|
|
220
|
+
Garbage collects unreferenced sections from the
|
|
221
|
+
database.
|
|
222
|
+
|
|
223
|
+
```typescript
|
|
224
|
+
gc(): Promise<GcResult>
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
#### `rebuildIndexes()`
|
|
228
|
+
|
|
229
|
+
Reconstructs all index files from section files and
|
|
230
|
+
document manifests on disk.
|
|
231
|
+
|
|
232
|
+
```typescript
|
|
233
|
+
rebuildIndexes(): Promise<RebuildResult>
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
#### `initDirectory(targetPath)`
|
|
237
|
+
|
|
238
|
+
Initialises a new `.kbdb` database directory at the
|
|
239
|
+
given path.
|
|
240
|
+
|
|
241
|
+
```typescript
|
|
242
|
+
initDirectory(targetPath: string): Promise<void>
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
#### `migrateDatabase(targetPath)`
|
|
246
|
+
|
|
247
|
+
Runs all pending database migrations for the
|
|
248
|
+
`.kbdb` directory at the given path.
|
|
249
|
+
|
|
250
|
+
```typescript
|
|
251
|
+
migrateDatabase(
|
|
252
|
+
targetPath: string,
|
|
253
|
+
): Promise<MigrateResult>
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
#### `checkVersion(targetPath)`
|
|
257
|
+
|
|
258
|
+
Checks format version compatibility of the `.kbdb`
|
|
259
|
+
database against the current WASM engine. Read-only.
|
|
260
|
+
|
|
261
|
+
```typescript
|
|
262
|
+
checkVersion(
|
|
263
|
+
targetPath: string,
|
|
264
|
+
): Promise<VersionStatus>
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
---
|
|
268
|
+
|
|
269
|
+
### Cache
|
|
270
|
+
|
|
271
|
+
#### `invalidate(kbid)`
|
|
272
|
+
|
|
273
|
+
Evicts a single section from the daemon's in-memory
|
|
274
|
+
cache.
|
|
275
|
+
|
|
276
|
+
```typescript
|
|
277
|
+
invalidate(kbid: string): Promise<void>
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
#### `invalidateAll()`
|
|
281
|
+
|
|
282
|
+
Clears all entries from the daemon's in-memory
|
|
283
|
+
cache.
|
|
284
|
+
|
|
285
|
+
```typescript
|
|
286
|
+
invalidateAll(): Promise<void>
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
---
|
|
290
|
+
|
|
291
|
+
### Lifecycle
|
|
292
|
+
|
|
293
|
+
#### `status()`
|
|
294
|
+
|
|
295
|
+
Returns diagnostic status including initialization
|
|
296
|
+
state and cache statistics.
|
|
297
|
+
|
|
298
|
+
```typescript
|
|
299
|
+
status(): Promise<StatusResult>
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
#### `dbStatus()`
|
|
303
|
+
|
|
304
|
+
Returns database metadata and status from the
|
|
305
|
+
daemon's cached state.
|
|
306
|
+
|
|
307
|
+
```typescript
|
|
308
|
+
dbStatus(): Promise<StatusResult>
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
#### `disconnect()`
|
|
312
|
+
|
|
313
|
+
Destroys the IPC socket and closes the connection.
|
|
314
|
+
|
|
315
|
+
```typescript
|
|
316
|
+
disconnect(): void
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
---
|
|
320
|
+
|
|
321
|
+
## Types
|
|
322
|
+
|
|
323
|
+
### `WorkerClientOptions`
|
|
324
|
+
|
|
325
|
+
```typescript
|
|
326
|
+
interface WorkerClientOptions {
|
|
327
|
+
readonly dbPath?: string;
|
|
328
|
+
readonly contextPath?: string;
|
|
329
|
+
readonly autoSpawn?: boolean;
|
|
330
|
+
readonly connectTimeoutMs?: number;
|
|
331
|
+
readonly workerScript?: string;
|
|
332
|
+
}
|
|
333
|
+
```
|
|
334
|
+
|
|
335
|
+
### `SearchParams`
|
|
336
|
+
|
|
337
|
+
```typescript
|
|
338
|
+
interface SearchParams {
|
|
339
|
+
readonly query: string;
|
|
340
|
+
readonly mode?: 'sections' | 'documents' | 'stats';
|
|
341
|
+
readonly limit?: number;
|
|
342
|
+
}
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
### `SearchResult`
|
|
346
|
+
|
|
347
|
+
```typescript
|
|
348
|
+
interface SearchResult {
|
|
349
|
+
readonly kbid: string;
|
|
350
|
+
readonly score: number;
|
|
351
|
+
readonly matches: readonly {
|
|
352
|
+
readonly term: string;
|
|
353
|
+
readonly frequency: number;
|
|
354
|
+
}[];
|
|
355
|
+
}
|
|
356
|
+
```
|
|
357
|
+
|
|
358
|
+
### `Section`
|
|
359
|
+
|
|
360
|
+
```typescript
|
|
361
|
+
interface Section {
|
|
362
|
+
readonly kbid: string;
|
|
363
|
+
readonly docid?: string;
|
|
364
|
+
readonly sectionType: string;
|
|
365
|
+
readonly content: string;
|
|
366
|
+
readonly size: number;
|
|
367
|
+
readonly createdAt: number;
|
|
368
|
+
readonly checksum: string;
|
|
369
|
+
}
|
|
370
|
+
```
|
|
371
|
+
|
|
372
|
+
### `AddSectionParams`
|
|
373
|
+
|
|
374
|
+
```typescript
|
|
375
|
+
interface AddSectionParams {
|
|
376
|
+
readonly sectionType: string;
|
|
377
|
+
readonly content: string;
|
|
378
|
+
readonly docid?: string;
|
|
379
|
+
}
|
|
380
|
+
```
|
|
381
|
+
|
|
382
|
+
### `StatusResult`
|
|
383
|
+
|
|
384
|
+
```typescript
|
|
385
|
+
interface StatusResult {
|
|
386
|
+
readonly initialized: boolean;
|
|
387
|
+
readonly contextPath: string;
|
|
388
|
+
readonly cacheStats: {
|
|
389
|
+
readonly contentCount: number;
|
|
390
|
+
readonly indexCount: number;
|
|
391
|
+
};
|
|
392
|
+
}
|
|
393
|
+
```
|
|
394
|
+
|
|
395
|
+
---
|
|
396
|
+
|
|
397
|
+
## How It Works
|
|
398
|
+
|
|
399
|
+
The client spawns a background worker daemon that
|
|
400
|
+
loads the Rust/WASM search engine. Communication
|
|
401
|
+
between the client and daemon happens over a local
|
|
402
|
+
IPC socket using JSON-RPC 2.0 with newline-delimited
|
|
403
|
+
framing. The daemon auto-starts on first use and
|
|
404
|
+
persists across invocations; if the connection drops,
|
|
405
|
+
the client automatically rediscovers or respawns the
|
|
406
|
+
daemon on the next method call.
|