@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
|
@@ -10,8 +10,10 @@ export function createToolDefinitions(): McpToolDefinition[] {
|
|
|
10
10
|
{
|
|
11
11
|
name: 'search',
|
|
12
12
|
description:
|
|
13
|
-
'Search the knowledge base
|
|
14
|
-
'
|
|
13
|
+
'Search the knowledge base. Returns ranked' +
|
|
14
|
+
' results with headings and snippets for' +
|
|
15
|
+
' relevance evaluation. Use `recall` to' +
|
|
16
|
+
' get full content of specific results.',
|
|
15
17
|
inputSchema: {
|
|
16
18
|
type: 'object',
|
|
17
19
|
properties: {
|
|
@@ -28,6 +30,12 @@ export function createToolDefinitions(): McpToolDefinition[] {
|
|
|
28
30
|
type: 'number',
|
|
29
31
|
description: 'Maximum results (default: 20)',
|
|
30
32
|
},
|
|
33
|
+
offset: {
|
|
34
|
+
type: 'number',
|
|
35
|
+
description:
|
|
36
|
+
'Number of results to skip for' +
|
|
37
|
+
' pagination (default: 0)',
|
|
38
|
+
},
|
|
31
39
|
},
|
|
32
40
|
required: ['query'],
|
|
33
41
|
},
|
|
@@ -36,6 +44,7 @@ export function createToolDefinitions(): McpToolDefinition[] {
|
|
|
36
44
|
readOnlyHint: true,
|
|
37
45
|
destructiveHint: false,
|
|
38
46
|
idempotentHint: true,
|
|
47
|
+
openWorldHint: false,
|
|
39
48
|
},
|
|
40
49
|
},
|
|
41
50
|
{
|
|
@@ -75,6 +84,7 @@ export function createToolDefinitions(): McpToolDefinition[] {
|
|
|
75
84
|
readOnlyHint: false,
|
|
76
85
|
destructiveHint: false,
|
|
77
86
|
idempotentHint: true,
|
|
87
|
+
openWorldHint: false,
|
|
78
88
|
},
|
|
79
89
|
},
|
|
80
90
|
{
|
|
@@ -97,13 +107,16 @@ export function createToolDefinitions(): McpToolDefinition[] {
|
|
|
97
107
|
readOnlyHint: false,
|
|
98
108
|
destructiveHint: true,
|
|
99
109
|
idempotentHint: true,
|
|
110
|
+
openWorldHint: false,
|
|
100
111
|
},
|
|
101
112
|
},
|
|
102
113
|
{
|
|
103
114
|
name: 'retrieve',
|
|
104
115
|
description:
|
|
105
|
-
'
|
|
106
|
-
'
|
|
116
|
+
'Low-level fetch of a section or document' +
|
|
117
|
+
' by identifier. For AI agent workflows,' +
|
|
118
|
+
' prefer `recall` which includes metadata,' +
|
|
119
|
+
' context, and back-references.',
|
|
107
120
|
inputSchema: {
|
|
108
121
|
type: 'object',
|
|
109
122
|
properties: {
|
|
@@ -122,6 +135,40 @@ export function createToolDefinitions(): McpToolDefinition[] {
|
|
|
122
135
|
readOnlyHint: true,
|
|
123
136
|
destructiveHint: false,
|
|
124
137
|
idempotentHint: true,
|
|
138
|
+
openWorldHint: false,
|
|
139
|
+
},
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
name: 'recall',
|
|
143
|
+
description:
|
|
144
|
+
'Retrieve full content and context for sections' +
|
|
145
|
+
' by identifier. Use after search to read relevant' +
|
|
146
|
+
' results. Returns section text, metadata,' +
|
|
147
|
+
' references, and back-references.',
|
|
148
|
+
inputSchema: {
|
|
149
|
+
type: 'object',
|
|
150
|
+
properties: {
|
|
151
|
+
kbid: {
|
|
152
|
+
type: 'string',
|
|
153
|
+
description: 'Single section identifier',
|
|
154
|
+
},
|
|
155
|
+
kbids: {
|
|
156
|
+
type: 'array',
|
|
157
|
+
items: { type: 'string' },
|
|
158
|
+
description: 'Batch section identifiers',
|
|
159
|
+
},
|
|
160
|
+
depth: {
|
|
161
|
+
type: 'number',
|
|
162
|
+
description: 'Expansion depth (0-3, default: 0)',
|
|
163
|
+
},
|
|
164
|
+
},
|
|
165
|
+
},
|
|
166
|
+
annotations: {
|
|
167
|
+
title: 'Recall Context',
|
|
168
|
+
readOnlyHint: true,
|
|
169
|
+
destructiveHint: false,
|
|
170
|
+
idempotentHint: true,
|
|
171
|
+
openWorldHint: false,
|
|
125
172
|
},
|
|
126
173
|
},
|
|
127
174
|
{
|
|
@@ -138,6 +185,7 @@ export function createToolDefinitions(): McpToolDefinition[] {
|
|
|
138
185
|
readOnlyHint: true,
|
|
139
186
|
destructiveHint: false,
|
|
140
187
|
idempotentHint: true,
|
|
188
|
+
openWorldHint: false,
|
|
141
189
|
},
|
|
142
190
|
},
|
|
143
191
|
{
|
|
@@ -163,6 +211,7 @@ export function createToolDefinitions(): McpToolDefinition[] {
|
|
|
163
211
|
readOnlyHint: true,
|
|
164
212
|
destructiveHint: false,
|
|
165
213
|
idempotentHint: true,
|
|
214
|
+
openWorldHint: false,
|
|
166
215
|
},
|
|
167
216
|
},
|
|
168
217
|
{
|
|
@@ -180,6 +229,7 @@ export function createToolDefinitions(): McpToolDefinition[] {
|
|
|
180
229
|
readOnlyHint: true,
|
|
181
230
|
destructiveHint: false,
|
|
182
231
|
idempotentHint: true,
|
|
232
|
+
openWorldHint: false,
|
|
183
233
|
},
|
|
184
234
|
},
|
|
185
235
|
{
|
|
@@ -197,6 +247,7 @@ export function createToolDefinitions(): McpToolDefinition[] {
|
|
|
197
247
|
readOnlyHint: false,
|
|
198
248
|
destructiveHint: true,
|
|
199
249
|
idempotentHint: false,
|
|
250
|
+
openWorldHint: false,
|
|
200
251
|
},
|
|
201
252
|
},
|
|
202
253
|
{
|
|
@@ -214,6 +265,7 @@ export function createToolDefinitions(): McpToolDefinition[] {
|
|
|
214
265
|
readOnlyHint: false,
|
|
215
266
|
destructiveHint: false,
|
|
216
267
|
idempotentHint: false,
|
|
268
|
+
openWorldHint: false,
|
|
217
269
|
},
|
|
218
270
|
},
|
|
219
271
|
{
|
|
@@ -247,6 +299,7 @@ export function createToolDefinitions(): McpToolDefinition[] {
|
|
|
247
299
|
readOnlyHint: false,
|
|
248
300
|
destructiveHint: false,
|
|
249
301
|
idempotentHint: true,
|
|
302
|
+
openWorldHint: false,
|
|
250
303
|
},
|
|
251
304
|
},
|
|
252
305
|
{
|
|
@@ -261,6 +314,7 @@ export function createToolDefinitions(): McpToolDefinition[] {
|
|
|
261
314
|
readOnlyHint: true,
|
|
262
315
|
destructiveHint: false,
|
|
263
316
|
idempotentHint: true,
|
|
317
|
+
openWorldHint: false,
|
|
264
318
|
},
|
|
265
319
|
},
|
|
266
320
|
{
|
|
@@ -284,6 +338,7 @@ export function createToolDefinitions(): McpToolDefinition[] {
|
|
|
284
338
|
readOnlyHint: true,
|
|
285
339
|
destructiveHint: false,
|
|
286
340
|
idempotentHint: true,
|
|
341
|
+
openWorldHint: false,
|
|
287
342
|
},
|
|
288
343
|
},
|
|
289
344
|
{
|
|
@@ -304,6 +359,7 @@ export function createToolDefinitions(): McpToolDefinition[] {
|
|
|
304
359
|
readOnlyHint: false,
|
|
305
360
|
destructiveHint: true,
|
|
306
361
|
idempotentHint: true,
|
|
362
|
+
openWorldHint: false,
|
|
307
363
|
},
|
|
308
364
|
},
|
|
309
365
|
{
|
|
@@ -339,6 +395,7 @@ export function createToolDefinitions(): McpToolDefinition[] {
|
|
|
339
395
|
readOnlyHint: false,
|
|
340
396
|
destructiveHint: false,
|
|
341
397
|
idempotentHint: true,
|
|
398
|
+
openWorldHint: false,
|
|
342
399
|
},
|
|
343
400
|
},
|
|
344
401
|
{
|
|
@@ -353,6 +410,7 @@ export function createToolDefinitions(): McpToolDefinition[] {
|
|
|
353
410
|
readOnlyHint: true,
|
|
354
411
|
destructiveHint: false,
|
|
355
412
|
idempotentHint: true,
|
|
413
|
+
openWorldHint: false,
|
|
356
414
|
},
|
|
357
415
|
},
|
|
358
416
|
{
|
|
@@ -373,6 +431,7 @@ export function createToolDefinitions(): McpToolDefinition[] {
|
|
|
373
431
|
readOnlyHint: true,
|
|
374
432
|
destructiveHint: false,
|
|
375
433
|
idempotentHint: true,
|
|
434
|
+
openWorldHint: false,
|
|
376
435
|
},
|
|
377
436
|
},
|
|
378
437
|
{
|
|
@@ -395,6 +454,7 @@ export function createToolDefinitions(): McpToolDefinition[] {
|
|
|
395
454
|
readOnlyHint: false,
|
|
396
455
|
destructiveHint: true,
|
|
397
456
|
idempotentHint: true,
|
|
457
|
+
openWorldHint: false,
|
|
398
458
|
},
|
|
399
459
|
},
|
|
400
460
|
];
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type { McpWorkerClient } from '../typings/mcp-client.interface.ts';
|
|
2
|
+
|
|
3
|
+
/** Shape of a content item in an MCP tool call response. */
|
|
4
|
+
interface ToolContent {
|
|
5
|
+
/** Content type identifier, typically `'text'`. */
|
|
6
|
+
readonly type: string;
|
|
7
|
+
/** The text payload. */
|
|
8
|
+
readonly text: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/** Result returned by a tool call handler. */
|
|
12
|
+
interface ToolCallResult {
|
|
13
|
+
/** One or more content items describing the result. */
|
|
14
|
+
readonly content: ToolContent[];
|
|
15
|
+
/** Set to `true` when the tool encountered an error. */
|
|
16
|
+
readonly isError?: boolean;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Handles the MCP `recall` tool call.
|
|
21
|
+
*
|
|
22
|
+
* Retrieves full content and context for one or more knowledge-base
|
|
23
|
+
* sections by identifier. At least one of `kbid` or `kbids` must be
|
|
24
|
+
* present in `args`; omitting both returns an error result.
|
|
25
|
+
*
|
|
26
|
+
* @param client - the worker client used to execute the operation
|
|
27
|
+
* @param args - tool arguments from the MCP request
|
|
28
|
+
* @returns content with JSON-stringified recall result, or an error
|
|
29
|
+
* content item when required arguments are missing
|
|
30
|
+
*/
|
|
31
|
+
export async function handleRecall(
|
|
32
|
+
client: McpWorkerClient,
|
|
33
|
+
args: Record<string, unknown>,
|
|
34
|
+
): Promise<ToolCallResult> {
|
|
35
|
+
const kbid =
|
|
36
|
+
typeof args['kbid'] === 'string' ? args['kbid'] : undefined;
|
|
37
|
+
const kbids =
|
|
38
|
+
Array.isArray(args['kbids']) &&
|
|
39
|
+
args['kbids'].every((item: unknown) => typeof item === 'string')
|
|
40
|
+
? args['kbids']
|
|
41
|
+
: undefined;
|
|
42
|
+
|
|
43
|
+
if (!kbid && !kbids) {
|
|
44
|
+
return {
|
|
45
|
+
content: [
|
|
46
|
+
{
|
|
47
|
+
type: 'text',
|
|
48
|
+
text: 'Provide kbid or kbids',
|
|
49
|
+
},
|
|
50
|
+
],
|
|
51
|
+
isError: true,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const depth = typeof args['depth'] === 'number' ? args['depth'] : 0;
|
|
56
|
+
|
|
57
|
+
const result = await client.recall({ kbid, kbids, depth });
|
|
58
|
+
return {
|
|
59
|
+
content: [
|
|
60
|
+
{
|
|
61
|
+
type: 'text',
|
|
62
|
+
text: JSON.stringify(result, null, 2),
|
|
63
|
+
},
|
|
64
|
+
],
|
|
65
|
+
};
|
|
66
|
+
}
|
|
@@ -6,6 +6,7 @@ import { handleAgentCreate } from './handle-agent-create.function.ts';
|
|
|
6
6
|
import { handleAgentList } from './handle-agent-list.function.ts';
|
|
7
7
|
import { handleAgentGet } from './handle-agent-get.function.ts';
|
|
8
8
|
import { handleAgentDelete } from './handle-agent-delete.function.ts';
|
|
9
|
+
import { handleRecall } from './handle-recall.function.ts';
|
|
9
10
|
|
|
10
11
|
/** Shape of a content item in an MCP tool call response. */
|
|
11
12
|
interface ToolContent {
|
|
@@ -69,6 +70,8 @@ export async function handleToolCall(
|
|
|
69
70
|
return await handleUnlearn(client, args);
|
|
70
71
|
case 'retrieve':
|
|
71
72
|
return await handleRetrieve(client, args);
|
|
73
|
+
case 'recall':
|
|
74
|
+
return await handleRecall(client, args);
|
|
72
75
|
case 'status':
|
|
73
76
|
return await handleStatus(client);
|
|
74
77
|
case 'content':
|
|
@@ -127,12 +130,19 @@ async function handleSearch(
|
|
|
127
130
|
query: asString(args['query'], ''),
|
|
128
131
|
mode: args['mode'] as string | undefined,
|
|
129
132
|
limit: args['limit'] as number | undefined,
|
|
133
|
+
offset: args['offset'] as number | undefined,
|
|
130
134
|
});
|
|
135
|
+
|
|
136
|
+
const stripped = {
|
|
137
|
+
...results,
|
|
138
|
+
items: results.items.map(({ score: _score, ...rest }) => rest),
|
|
139
|
+
};
|
|
140
|
+
|
|
131
141
|
return {
|
|
132
142
|
content: [
|
|
133
143
|
{
|
|
134
144
|
type: 'text',
|
|
135
|
-
text: JSON.stringify(
|
|
145
|
+
text: JSON.stringify(stripped, null, 2),
|
|
136
146
|
},
|
|
137
147
|
],
|
|
138
148
|
};
|
|
@@ -85,21 +85,23 @@ export interface McpWorkerClient {
|
|
|
85
85
|
readonly mode?: string;
|
|
86
86
|
/** Maximum number of results to return. */
|
|
87
87
|
readonly limit?: number;
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
readonly
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
88
|
+
/** Number of results to skip for pagination. */
|
|
89
|
+
readonly offset?: number;
|
|
90
|
+
}): Promise<{
|
|
91
|
+
readonly items: readonly {
|
|
92
|
+
readonly kbid: string;
|
|
93
|
+
readonly heading: string | null;
|
|
94
|
+
readonly type: string;
|
|
95
|
+
readonly docids: readonly string[];
|
|
96
|
+
readonly score: number;
|
|
97
|
+
readonly snippet: string;
|
|
98
|
+
readonly matched_terms: readonly string[];
|
|
99
|
+
}[];
|
|
100
|
+
readonly total: number;
|
|
101
|
+
readonly offset: number;
|
|
102
|
+
readonly limit: number;
|
|
103
|
+
readonly has_more: boolean;
|
|
104
|
+
}>;
|
|
103
105
|
|
|
104
106
|
/**
|
|
105
107
|
* Adds a new section to the knowledge base.
|
|
@@ -245,6 +247,22 @@ export interface McpWorkerClient {
|
|
|
245
247
|
*/
|
|
246
248
|
removeGrouping(docid: string): Promise<void>;
|
|
247
249
|
|
|
250
|
+
/**
|
|
251
|
+
* Retrieves full content and context for one or more sections by
|
|
252
|
+
* their knowledge-base identifiers.
|
|
253
|
+
*
|
|
254
|
+
* @param params - section identifier(s) and optional expansion depth
|
|
255
|
+
* @returns a single result or array of results depending on input
|
|
256
|
+
*/
|
|
257
|
+
recall(params: {
|
|
258
|
+
/** Single section identifier. */
|
|
259
|
+
readonly kbid?: string;
|
|
260
|
+
/** Batch section identifiers. */
|
|
261
|
+
readonly kbids?: readonly string[];
|
|
262
|
+
/** Expansion depth (0-3, default: 0). */
|
|
263
|
+
readonly depth?: number;
|
|
264
|
+
}): Promise<unknown>;
|
|
265
|
+
|
|
248
266
|
/** Destroys the IPC socket and clears the connection state. */
|
|
249
267
|
disconnect(): void;
|
|
250
268
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/** Current package version, kept in sync with package.json. */
|
|
2
|
-
export const VERSION = '0.
|
|
2
|
+
export const VERSION = '0.2.0';
|
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
import { decodeString } from './decode-string.function.ts';
|
|
2
|
+
import { decodeU32 } from './decode-u32.function.ts';
|
|
3
|
+
import type {
|
|
4
|
+
RecallResult,
|
|
5
|
+
RecallDocument,
|
|
6
|
+
RecallSibling,
|
|
7
|
+
RecallReference,
|
|
8
|
+
} from '../../worker-client/typings/recall-result.model.ts';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Decodes recall result binary output from the `worker_recall` WASM
|
|
12
|
+
* export.
|
|
13
|
+
*
|
|
14
|
+
* Binary layout:
|
|
15
|
+
* - `u8 tag`: `0` = single result, `1` = batch
|
|
16
|
+
* - If tag=0: one RecallResult record
|
|
17
|
+
* - If tag=1: `u32 count` + `count` RecallResult records
|
|
18
|
+
*
|
|
19
|
+
* Each RecallResult:
|
|
20
|
+
* ```
|
|
21
|
+
* String kbid
|
|
22
|
+
* Option<String> heading (0x00=null, 0x01 + String)
|
|
23
|
+
* String section_type
|
|
24
|
+
* String content
|
|
25
|
+
* u32 docids_count + String[] docids
|
|
26
|
+
* u32 documents_count + RecallDocument[]
|
|
27
|
+
* u32 back_references_count + RecallReference[]
|
|
28
|
+
* u32 siblings_count + RecallSibling[]
|
|
29
|
+
* u32 references_count + RecallReference[]
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* @param bytes - raw binary output from the WASM export
|
|
33
|
+
* @returns a single `RecallResult` for tag=0, or `RecallResult[]`
|
|
34
|
+
* for tag=1
|
|
35
|
+
*/
|
|
36
|
+
export function decodeRecallResult(
|
|
37
|
+
bytes: Uint8Array,
|
|
38
|
+
): RecallResult | RecallResult[] {
|
|
39
|
+
const tag = bytes[0];
|
|
40
|
+
let offset = 1;
|
|
41
|
+
|
|
42
|
+
if (tag === 0x01) {
|
|
43
|
+
// Batch
|
|
44
|
+
const countResult = decodeU32(bytes, offset);
|
|
45
|
+
offset += countResult.bytesRead;
|
|
46
|
+
const items: RecallResult[] = [];
|
|
47
|
+
for (let i = 0; i < countResult.value; i++) {
|
|
48
|
+
const { item, bytesRead } = decodeOneResult(bytes, offset);
|
|
49
|
+
offset += bytesRead;
|
|
50
|
+
items.push(item);
|
|
51
|
+
}
|
|
52
|
+
return items;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// Single (tag=0 or any other value)
|
|
56
|
+
const { item } = decodeOneResult(bytes, offset);
|
|
57
|
+
return item;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// ---------------------------------------------------------------------------
|
|
61
|
+
// Private helpers
|
|
62
|
+
// ---------------------------------------------------------------------------
|
|
63
|
+
|
|
64
|
+
interface DecodeResultPair {
|
|
65
|
+
item: RecallResult;
|
|
66
|
+
bytesRead: number;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function decodeOptionString(
|
|
70
|
+
bytes: Uint8Array,
|
|
71
|
+
offset: number,
|
|
72
|
+
): { value: string | null; bytesRead: number } {
|
|
73
|
+
const tag = bytes[offset];
|
|
74
|
+
if (tag === 0x00) {
|
|
75
|
+
return { value: null, bytesRead: 1 };
|
|
76
|
+
}
|
|
77
|
+
const str = decodeString(bytes, offset + 1);
|
|
78
|
+
return { value: str.value, bytesRead: 1 + str.bytesRead };
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function decodeReference(
|
|
82
|
+
bytes: Uint8Array,
|
|
83
|
+
offset: number,
|
|
84
|
+
): { value: RecallReference; bytesRead: number } {
|
|
85
|
+
let pos = offset;
|
|
86
|
+
|
|
87
|
+
const kbid = decodeString(bytes, pos);
|
|
88
|
+
pos += kbid.bytesRead;
|
|
89
|
+
|
|
90
|
+
const heading = decodeOptionString(bytes, pos);
|
|
91
|
+
pos += heading.bytesRead;
|
|
92
|
+
|
|
93
|
+
const sectionType = decodeString(bytes, pos);
|
|
94
|
+
pos += sectionType.bytesRead;
|
|
95
|
+
|
|
96
|
+
const markerType = decodeString(bytes, pos);
|
|
97
|
+
pos += markerType.bytesRead;
|
|
98
|
+
|
|
99
|
+
const contextSnippet = decodeString(bytes, pos);
|
|
100
|
+
pos += contextSnippet.bytesRead;
|
|
101
|
+
|
|
102
|
+
const direction = decodeString(bytes, pos);
|
|
103
|
+
pos += direction.bytesRead;
|
|
104
|
+
|
|
105
|
+
return {
|
|
106
|
+
value: {
|
|
107
|
+
kbid: kbid.value,
|
|
108
|
+
heading: heading.value,
|
|
109
|
+
type: sectionType.value,
|
|
110
|
+
marker_type: markerType.value,
|
|
111
|
+
context_snippet: contextSnippet.value,
|
|
112
|
+
direction: direction.value as 'forward' | 'back',
|
|
113
|
+
},
|
|
114
|
+
bytesRead: pos - offset,
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function decodeSibling(
|
|
119
|
+
bytes: Uint8Array,
|
|
120
|
+
offset: number,
|
|
121
|
+
): { value: RecallSibling; bytesRead: number } {
|
|
122
|
+
let pos = offset;
|
|
123
|
+
|
|
124
|
+
const kbid = decodeString(bytes, pos);
|
|
125
|
+
pos += kbid.bytesRead;
|
|
126
|
+
|
|
127
|
+
const heading = decodeOptionString(bytes, pos);
|
|
128
|
+
pos += heading.bytesRead;
|
|
129
|
+
|
|
130
|
+
const sectionType = decodeString(bytes, pos);
|
|
131
|
+
pos += sectionType.bytesRead;
|
|
132
|
+
|
|
133
|
+
const content = decodeString(bytes, pos);
|
|
134
|
+
pos += content.bytesRead;
|
|
135
|
+
|
|
136
|
+
return {
|
|
137
|
+
value: {
|
|
138
|
+
kbid: kbid.value,
|
|
139
|
+
heading: heading.value,
|
|
140
|
+
type: sectionType.value,
|
|
141
|
+
content: content.value,
|
|
142
|
+
},
|
|
143
|
+
bytesRead: pos - offset,
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function decodeDocument(
|
|
148
|
+
bytes: Uint8Array,
|
|
149
|
+
offset: number,
|
|
150
|
+
): { value: RecallDocument; bytesRead: number } {
|
|
151
|
+
let pos = offset;
|
|
152
|
+
|
|
153
|
+
const docid = decodeString(bytes, pos);
|
|
154
|
+
pos += docid.bytesRead;
|
|
155
|
+
|
|
156
|
+
const title = decodeString(bytes, pos);
|
|
157
|
+
pos += title.bytesRead;
|
|
158
|
+
|
|
159
|
+
const sectionCount = decodeU32(bytes, pos);
|
|
160
|
+
pos += sectionCount.bytesRead;
|
|
161
|
+
|
|
162
|
+
const sections: RecallDocument['sections'][number][] = [];
|
|
163
|
+
for (let i = 0; i < sectionCount.value; i++) {
|
|
164
|
+
const secKbid = decodeString(bytes, pos);
|
|
165
|
+
pos += secKbid.bytesRead;
|
|
166
|
+
|
|
167
|
+
const secHeading = decodeOptionString(bytes, pos);
|
|
168
|
+
pos += secHeading.bytesRead;
|
|
169
|
+
|
|
170
|
+
const secType = decodeString(bytes, pos);
|
|
171
|
+
pos += secType.bytesRead;
|
|
172
|
+
|
|
173
|
+
sections.push({
|
|
174
|
+
kbid: secKbid.value,
|
|
175
|
+
heading: secHeading.value,
|
|
176
|
+
type: secType.value,
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
return {
|
|
181
|
+
value: {
|
|
182
|
+
docid: docid.value,
|
|
183
|
+
title: title.value,
|
|
184
|
+
sections,
|
|
185
|
+
},
|
|
186
|
+
bytesRead: pos - offset,
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
function decodeOneResult(
|
|
191
|
+
bytes: Uint8Array,
|
|
192
|
+
startOffset: number,
|
|
193
|
+
): DecodeResultPair {
|
|
194
|
+
let pos = startOffset;
|
|
195
|
+
|
|
196
|
+
const kbid = decodeString(bytes, pos);
|
|
197
|
+
pos += kbid.bytesRead;
|
|
198
|
+
|
|
199
|
+
const heading = decodeOptionString(bytes, pos);
|
|
200
|
+
pos += heading.bytesRead;
|
|
201
|
+
|
|
202
|
+
const sectionType = decodeString(bytes, pos);
|
|
203
|
+
pos += sectionType.bytesRead;
|
|
204
|
+
|
|
205
|
+
const content = decodeString(bytes, pos);
|
|
206
|
+
pos += content.bytesRead;
|
|
207
|
+
|
|
208
|
+
const docidCount = decodeU32(bytes, pos);
|
|
209
|
+
pos += docidCount.bytesRead;
|
|
210
|
+
const docids: string[] = [];
|
|
211
|
+
for (let i = 0; i < docidCount.value; i++) {
|
|
212
|
+
const docid = decodeString(bytes, pos);
|
|
213
|
+
pos += docid.bytesRead;
|
|
214
|
+
docids.push(docid.value);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
const docCount = decodeU32(bytes, pos);
|
|
218
|
+
pos += docCount.bytesRead;
|
|
219
|
+
const documents: RecallDocument[] = [];
|
|
220
|
+
for (let i = 0; i < docCount.value; i++) {
|
|
221
|
+
const doc = decodeDocument(bytes, pos);
|
|
222
|
+
pos += doc.bytesRead;
|
|
223
|
+
documents.push(doc.value);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
const backRefCount = decodeU32(bytes, pos);
|
|
227
|
+
pos += backRefCount.bytesRead;
|
|
228
|
+
const back_references: RecallReference[] = [];
|
|
229
|
+
for (let i = 0; i < backRefCount.value; i++) {
|
|
230
|
+
const ref = decodeReference(bytes, pos);
|
|
231
|
+
pos += ref.bytesRead;
|
|
232
|
+
back_references.push(ref.value);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
const sibCount = decodeU32(bytes, pos);
|
|
236
|
+
pos += sibCount.bytesRead;
|
|
237
|
+
const siblings: RecallSibling[] = [];
|
|
238
|
+
for (let i = 0; i < sibCount.value; i++) {
|
|
239
|
+
const sib = decodeSibling(bytes, pos);
|
|
240
|
+
pos += sib.bytesRead;
|
|
241
|
+
siblings.push(sib.value);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
const refCount = decodeU32(bytes, pos);
|
|
245
|
+
pos += refCount.bytesRead;
|
|
246
|
+
const references: RecallReference[] = [];
|
|
247
|
+
for (let i = 0; i < refCount.value; i++) {
|
|
248
|
+
const ref = decodeReference(bytes, pos);
|
|
249
|
+
pos += ref.bytesRead;
|
|
250
|
+
references.push(ref.value);
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
return {
|
|
254
|
+
item: {
|
|
255
|
+
kbid: kbid.value,
|
|
256
|
+
heading: heading.value,
|
|
257
|
+
type: sectionType.value,
|
|
258
|
+
content: content.value,
|
|
259
|
+
docids,
|
|
260
|
+
documents,
|
|
261
|
+
back_references,
|
|
262
|
+
siblings,
|
|
263
|
+
references,
|
|
264
|
+
},
|
|
265
|
+
bytesRead: pos - startOffset,
|
|
266
|
+
};
|
|
267
|
+
}
|