@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,27 @@
|
|
|
1
|
+
# runtime -- Runtime Detection
|
|
2
|
+
|
|
3
|
+
**Source:** `src/shared/runtime/`
|
|
4
|
+
|
|
5
|
+
## Responsibility
|
|
6
|
+
|
|
7
|
+
Detect whether the process is running on Deno or
|
|
8
|
+
Node.js, and provide cross-runtime access to CLI
|
|
9
|
+
arguments.
|
|
10
|
+
|
|
11
|
+
## Directory Layout
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
src/shared/runtime/
|
|
15
|
+
index.ts
|
|
16
|
+
functions/
|
|
17
|
+
detect-runtime.function.ts
|
|
18
|
+
get-args.function.ts
|
|
19
|
+
typings/
|
|
20
|
+
runtime.type.ts
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Exports
|
|
24
|
+
|
|
25
|
+
- [Functions](functions.md) -- `detectRuntime`,
|
|
26
|
+
`getArgs`
|
|
27
|
+
- [Typings](typings.md) -- `Runtime`
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# runtime/typings -- Runtime Type Definitions
|
|
2
|
+
|
|
3
|
+
**Source:** `src/shared/runtime/typings/`
|
|
4
|
+
|
|
5
|
+
## Runtime
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
type Runtime = 'deno' | 'node';
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Discriminant for the two supported JavaScript runtimes.
|
|
12
|
+
|
|
13
|
+
No spec -- typings are compile-time only.
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# version -- Package Version
|
|
2
|
+
|
|
3
|
+
**Source:** `src/shared/version/`
|
|
4
|
+
|
|
5
|
+
## Responsibility
|
|
6
|
+
|
|
7
|
+
Exposes the current package version as a constant.
|
|
8
|
+
Exported from the library API (`mod.ts`). Currently the
|
|
9
|
+
only public export.
|
|
10
|
+
|
|
11
|
+
## Exports
|
|
12
|
+
|
|
13
|
+
- `version` -- `'0.0.1'`
|
|
14
|
+
|
|
15
|
+
## Directory Layout
|
|
16
|
+
|
|
17
|
+
```
|
|
18
|
+
src/shared/version/
|
|
19
|
+
index.ts
|
|
20
|
+
constants/
|
|
21
|
+
version.constant.ts
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Spec
|
|
25
|
+
|
|
26
|
+
- `version.spec.ts` -- Validates the version string
|
|
27
|
+
format.
|
|
@@ -0,0 +1,391 @@
|
|
|
1
|
+
# wasm-codec/functions -- Codec Functions
|
|
2
|
+
|
|
3
|
+
*One encode or decode function per file. Encoders
|
|
4
|
+
build `Uint8Array` buffers; decoders parse them into
|
|
5
|
+
typed TypeScript values.*
|
|
6
|
+
|
|
7
|
+
## Source
|
|
8
|
+
|
|
9
|
+
`src/shared/wasm-codec/functions/`
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## Encoder Functions
|
|
14
|
+
|
|
15
|
+
### `encodeString`
|
|
16
|
+
|
|
17
|
+
**File:** `encode-string.function.ts`
|
|
18
|
+
|
|
19
|
+
Encodes a UTF-8 string as a little-endian `u32`
|
|
20
|
+
length prefix followed by the UTF-8 bytes.
|
|
21
|
+
|
|
22
|
+
```ts
|
|
23
|
+
function encodeString(value: string): Uint8Array;
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
### `encodeU32`
|
|
27
|
+
|
|
28
|
+
**File:** `encode-u32.function.ts`
|
|
29
|
+
|
|
30
|
+
Encodes an unsigned 32-bit integer as 4 bytes,
|
|
31
|
+
little-endian.
|
|
32
|
+
|
|
33
|
+
```ts
|
|
34
|
+
function encodeU32(value: number): Uint8Array;
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### `encodeOptionString`
|
|
38
|
+
|
|
39
|
+
**File:** `encode-option-string.function.ts`
|
|
40
|
+
|
|
41
|
+
Encodes an optional string. Writes `0x00` for `null`
|
|
42
|
+
or `undefined`; writes `0x01` followed by the encoded
|
|
43
|
+
string for a present value.
|
|
44
|
+
|
|
45
|
+
```ts
|
|
46
|
+
function encodeOptionString(
|
|
47
|
+
value: string | null | undefined,
|
|
48
|
+
): Uint8Array;
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### `encodeSectionType`
|
|
52
|
+
|
|
53
|
+
**File:** `encode-section-type.function.ts`
|
|
54
|
+
|
|
55
|
+
Encodes a section type discriminant. Writes `0x00`
|
|
56
|
+
for `text` (no MIME), `0x01` + MIME for `code`, or
|
|
57
|
+
`0x02` + MIME for `image`.
|
|
58
|
+
|
|
59
|
+
```ts
|
|
60
|
+
function encodeSectionType(
|
|
61
|
+
kind: 'text' | 'code' | 'image',
|
|
62
|
+
mimeType?: string,
|
|
63
|
+
): Uint8Array;
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### `encodeAddSectionParams`
|
|
67
|
+
|
|
68
|
+
**File:** `encode-add-section-params.function.ts`
|
|
69
|
+
|
|
70
|
+
Encodes parameters for the `worker_add_section` WASM
|
|
71
|
+
export: section type, content, optional title,
|
|
72
|
+
optional description, and optional docid, in that
|
|
73
|
+
order.
|
|
74
|
+
|
|
75
|
+
```ts
|
|
76
|
+
function encodeAddSectionParams(
|
|
77
|
+
params: AddSectionInput,
|
|
78
|
+
): Uint8Array;
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
```ts
|
|
82
|
+
interface AddSectionInput {
|
|
83
|
+
sectionType: 'text' | 'code' | 'image';
|
|
84
|
+
mimeType?: string;
|
|
85
|
+
content: string;
|
|
86
|
+
title?: string | null;
|
|
87
|
+
description?: string | null;
|
|
88
|
+
docid?: string | null;
|
|
89
|
+
}
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### `encodeUpdateSectionParams`
|
|
93
|
+
|
|
94
|
+
**File:** `encode-update-section-params.function.ts`
|
|
95
|
+
|
|
96
|
+
Encodes parameters for the `worker_update_section`
|
|
97
|
+
WASM export: the old KB ID as an encoded string
|
|
98
|
+
followed by the full `AddSectionInput` encoding.
|
|
99
|
+
|
|
100
|
+
```ts
|
|
101
|
+
function encodeUpdateSectionParams(
|
|
102
|
+
oldKbid: string,
|
|
103
|
+
params: AddSectionInput,
|
|
104
|
+
): Uint8Array;
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### `encodeKbidList`
|
|
108
|
+
|
|
109
|
+
**File:** `encode-kbid-list.function.ts`
|
|
110
|
+
|
|
111
|
+
Encodes a list of KB IDs as a `u32` count followed
|
|
112
|
+
by each ID encoded as a length-prefixed string.
|
|
113
|
+
Returns an empty `Uint8Array` for an empty list.
|
|
114
|
+
|
|
115
|
+
```ts
|
|
116
|
+
function encodeKbidList(kbids: string[]): Uint8Array;
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### `encodeGroupParams`
|
|
120
|
+
|
|
121
|
+
**File:** `encode-group-params.function.ts`
|
|
122
|
+
|
|
123
|
+
Encodes parameters for the `worker_group_sections`
|
|
124
|
+
WASM export: the document title followed by a
|
|
125
|
+
`encodeKbidList` encoding of the section IDs.
|
|
126
|
+
|
|
127
|
+
```ts
|
|
128
|
+
function encodeGroupParams(
|
|
129
|
+
title: string,
|
|
130
|
+
kbids: string[],
|
|
131
|
+
): Uint8Array;
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
### `encodeIdentifierList`
|
|
135
|
+
|
|
136
|
+
**File:** `encode-identifier-list.function.ts`
|
|
137
|
+
|
|
138
|
+
Encodes a list of arbitrary string identifiers (kbid
|
|
139
|
+
or docid) as a `u32` count followed by each ID as a
|
|
140
|
+
length-prefixed string. Returns an empty `Uint8Array`
|
|
141
|
+
for an empty list.
|
|
142
|
+
|
|
143
|
+
```ts
|
|
144
|
+
function encodeIdentifierList(
|
|
145
|
+
ids: string[],
|
|
146
|
+
): Uint8Array;
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
### `encodeSearchParams`
|
|
150
|
+
|
|
151
|
+
**File:** `encode-search-params.function.ts`
|
|
152
|
+
|
|
153
|
+
Encodes search parameters as a newline-delimited
|
|
154
|
+
UTF-8 string: `query\nmode\nlimit`.
|
|
155
|
+
|
|
156
|
+
```ts
|
|
157
|
+
function encodeSearchParams(
|
|
158
|
+
query: string,
|
|
159
|
+
mode?: string,
|
|
160
|
+
limit?: number,
|
|
161
|
+
): Uint8Array;
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
`mode` defaults to `'and'`; `limit` defaults to `20`.
|
|
165
|
+
|
|
166
|
+
---
|
|
167
|
+
|
|
168
|
+
## Decoder Functions
|
|
169
|
+
|
|
170
|
+
### `decodeString`
|
|
171
|
+
|
|
172
|
+
**File:** `decode-string.function.ts`
|
|
173
|
+
|
|
174
|
+
Reads a length-prefixed UTF-8 string from a byte
|
|
175
|
+
buffer at the given offset.
|
|
176
|
+
|
|
177
|
+
```ts
|
|
178
|
+
function decodeString(
|
|
179
|
+
bytes: Uint8Array,
|
|
180
|
+
offset: number,
|
|
181
|
+
): DecodeResult<string>;
|
|
182
|
+
|
|
183
|
+
interface DecodeResult<T> {
|
|
184
|
+
value: T;
|
|
185
|
+
bytesRead: number;
|
|
186
|
+
}
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
### `decodeU32`
|
|
190
|
+
|
|
191
|
+
**File:** `decode-u32.function.ts`
|
|
192
|
+
|
|
193
|
+
Reads a little-endian `u32` from a byte buffer at the
|
|
194
|
+
given offset.
|
|
195
|
+
|
|
196
|
+
```ts
|
|
197
|
+
function decodeU32(
|
|
198
|
+
bytes: Uint8Array,
|
|
199
|
+
offset: number,
|
|
200
|
+
): DecodeResult<number>;
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
### `decodeF32`
|
|
204
|
+
|
|
205
|
+
**File:** `decode-f32.function.ts`
|
|
206
|
+
|
|
207
|
+
Reads a little-endian IEEE 754 `f32` from a byte
|
|
208
|
+
buffer at the given offset.
|
|
209
|
+
|
|
210
|
+
```ts
|
|
211
|
+
function decodeF32(
|
|
212
|
+
bytes: Uint8Array,
|
|
213
|
+
offset: number,
|
|
214
|
+
): DecodeResult<number>;
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
### `decodeU64`
|
|
218
|
+
|
|
219
|
+
**File:** `decode-u64.function.ts`
|
|
220
|
+
|
|
221
|
+
Reads a little-endian `u64` from a byte buffer at the
|
|
222
|
+
given offset. Returns a `bigint`.
|
|
223
|
+
|
|
224
|
+
```ts
|
|
225
|
+
function decodeU64(
|
|
226
|
+
bytes: Uint8Array,
|
|
227
|
+
offset: number,
|
|
228
|
+
): DecodeResult<bigint>;
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
### `decodeScoredResults`
|
|
232
|
+
|
|
233
|
+
**File:** `decode-scored-results.function.ts`
|
|
234
|
+
|
|
235
|
+
Decodes the binary response from `worker_search`
|
|
236
|
+
into an array of scored results.
|
|
237
|
+
|
|
238
|
+
```ts
|
|
239
|
+
function decodeScoredResults(
|
|
240
|
+
bytes: Uint8Array,
|
|
241
|
+
): ScoredResult[];
|
|
242
|
+
|
|
243
|
+
interface ScoredResult {
|
|
244
|
+
kbid: string;
|
|
245
|
+
score: number;
|
|
246
|
+
matches: TermMatch[];
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
interface TermMatch {
|
|
250
|
+
term: string;
|
|
251
|
+
frequency: number;
|
|
252
|
+
}
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
Wire format: `u32` count, then for each result:
|
|
256
|
+
kbid (length-prefixed string), score (`f32`), match
|
|
257
|
+
count (`u32`), then for each match: term (string),
|
|
258
|
+
frequency (`f32`).
|
|
259
|
+
|
|
260
|
+
### `decodeSectionRecords`
|
|
261
|
+
|
|
262
|
+
**File:** `decode-section-records.function.ts`
|
|
263
|
+
|
|
264
|
+
Decodes the binary response from `worker_read_sections`
|
|
265
|
+
into an array of section records.
|
|
266
|
+
|
|
267
|
+
```ts
|
|
268
|
+
function decodeSectionRecords(
|
|
269
|
+
bytes: Uint8Array,
|
|
270
|
+
): SectionRecord[];
|
|
271
|
+
|
|
272
|
+
interface SectionRecord {
|
|
273
|
+
kbid: string;
|
|
274
|
+
docid: string | null;
|
|
275
|
+
sectionType: string;
|
|
276
|
+
mimeType?: string;
|
|
277
|
+
title: string | null;
|
|
278
|
+
description: string | null;
|
|
279
|
+
content: string;
|
|
280
|
+
size: number;
|
|
281
|
+
createdAt: bigint;
|
|
282
|
+
checksum: string;
|
|
283
|
+
tokenCount: number;
|
|
284
|
+
headingTokenCount: number;
|
|
285
|
+
bodyTokenCount: number;
|
|
286
|
+
codeTokenCount: number;
|
|
287
|
+
}
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
### `decodeDocumentManifest`
|
|
291
|
+
|
|
292
|
+
**File:** `decode-document-manifest.function.ts`
|
|
293
|
+
|
|
294
|
+
Decodes the binary response from `worker_retrieve_doc`
|
|
295
|
+
into a document manifest.
|
|
296
|
+
|
|
297
|
+
```ts
|
|
298
|
+
function decodeDocumentManifest(
|
|
299
|
+
bytes: Uint8Array,
|
|
300
|
+
): DocumentManifest;
|
|
301
|
+
|
|
302
|
+
interface DocumentManifest {
|
|
303
|
+
docid: string;
|
|
304
|
+
title: string;
|
|
305
|
+
createdAt: bigint;
|
|
306
|
+
sections: DocumentSection[];
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
interface DocumentSection {
|
|
310
|
+
kbid: string;
|
|
311
|
+
position: number;
|
|
312
|
+
}
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
### `decodeComposeOutput`
|
|
316
|
+
|
|
317
|
+
**File:** `decode-compose-output.function.ts`
|
|
318
|
+
|
|
319
|
+
Decodes the binary response from `worker_compose`
|
|
320
|
+
into a Markdown string and character count.
|
|
321
|
+
|
|
322
|
+
```ts
|
|
323
|
+
function decodeComposeOutput(
|
|
324
|
+
bytes: Uint8Array,
|
|
325
|
+
): ComposeOutput;
|
|
326
|
+
|
|
327
|
+
interface ComposeOutput {
|
|
328
|
+
markdown: string;
|
|
329
|
+
totalChars: bigint;
|
|
330
|
+
}
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
Wire format: length-prefixed Markdown string followed
|
|
334
|
+
by a `u64` character count.
|
|
335
|
+
|
|
336
|
+
### `decodeKeyValueText`
|
|
337
|
+
|
|
338
|
+
**File:** `decode-key-value-text.function.ts`
|
|
339
|
+
|
|
340
|
+
Parses a newline-delimited `key=value` text response
|
|
341
|
+
into a `Record<string, string>`. Used to decode
|
|
342
|
+
responses from `worker_status`, `worker_check_integrity`,
|
|
343
|
+
and `worker_garbage_collect`.
|
|
344
|
+
|
|
345
|
+
```ts
|
|
346
|
+
function decodeKeyValueText(
|
|
347
|
+
text: string,
|
|
348
|
+
): Record<string, string>;
|
|
349
|
+
```
|
|
350
|
+
|
|
351
|
+
Lines without a `=` separator are silently skipped.
|
|
352
|
+
|
|
353
|
+
### `decodeRemoveFlag`
|
|
354
|
+
|
|
355
|
+
**File:** `decode-remove-flag.function.ts`
|
|
356
|
+
|
|
357
|
+
Decodes a single-byte boolean response from
|
|
358
|
+
`worker_remove_section`. Returns `true` when the
|
|
359
|
+
first byte is `0x01`.
|
|
360
|
+
|
|
361
|
+
```ts
|
|
362
|
+
function decodeRemoveFlag(bytes: Uint8Array): boolean;
|
|
363
|
+
```
|
|
364
|
+
|
|
365
|
+
## Testing
|
|
366
|
+
|
|
367
|
+
Each function has a `.spec.ts` at the module root:
|
|
368
|
+
|
|
369
|
+
```
|
|
370
|
+
src/shared/wasm-codec/
|
|
371
|
+
├── encode-string.spec.ts
|
|
372
|
+
├── encode-u32.spec.ts
|
|
373
|
+
├── encode-option-string.spec.ts
|
|
374
|
+
├── encode-section-type.spec.ts
|
|
375
|
+
├── encode-add-section-params.spec.ts
|
|
376
|
+
├── encode-update-section-params.spec.ts
|
|
377
|
+
├── encode-kbid-list.spec.ts
|
|
378
|
+
├── encode-group-params.spec.ts
|
|
379
|
+
├── encode-identifier-list.spec.ts
|
|
380
|
+
├── encode-search-params.spec.ts
|
|
381
|
+
├── decode-string.spec.ts
|
|
382
|
+
├── decode-u32.spec.ts
|
|
383
|
+
├── decode-f32.spec.ts
|
|
384
|
+
├── decode-u64.spec.ts
|
|
385
|
+
├── decode-scored-results.spec.ts
|
|
386
|
+
├── decode-section-records.spec.ts
|
|
387
|
+
├── decode-document-manifest.spec.ts
|
|
388
|
+
├── decode-compose-output.spec.ts
|
|
389
|
+
├── decode-key-value-text.spec.ts
|
|
390
|
+
└── decode-remove-flag.spec.ts
|
|
391
|
+
```
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
# wasm-codec -- WASM Binary Codec Module
|
|
2
|
+
|
|
3
|
+
*Encodes TypeScript values into the binary wire format
|
|
4
|
+
consumed by `kb-worker.wasm` and decodes binary
|
|
5
|
+
responses back into typed TypeScript values.*
|
|
6
|
+
|
|
7
|
+
## Source
|
|
8
|
+
|
|
9
|
+
`src/shared/wasm-codec/`
|
|
10
|
+
|
|
11
|
+
## Responsibility
|
|
12
|
+
|
|
13
|
+
The wasm-codec module provides the binary serialization
|
|
14
|
+
layer between the TypeScript host and the Rust WASM
|
|
15
|
+
engine. Each function handles one specific encode or
|
|
16
|
+
decode operation -- there is no general-purpose codec
|
|
17
|
+
framework.
|
|
18
|
+
|
|
19
|
+
**Encoders** convert TypeScript values into
|
|
20
|
+
`Uint8Array` buffers that can be written into WASM
|
|
21
|
+
linear memory via the host bridge. Conventions:
|
|
22
|
+
|
|
23
|
+
- Strings are encoded as a little-endian `u32` length
|
|
24
|
+
prefix followed by UTF-8 bytes.
|
|
25
|
+
- Optional strings use a `0x00` tag byte for `null`
|
|
26
|
+
or `0x01` followed by the encoded string.
|
|
27
|
+
- Section types use a `0x00` tag for `text`, `0x01`
|
|
28
|
+
for `code`, or `0x02` for `image`, followed by the
|
|
29
|
+
MIME type string for non-text types.
|
|
30
|
+
- Lists use a little-endian `u32` count prefix
|
|
31
|
+
followed by each element in sequence.
|
|
32
|
+
|
|
33
|
+
**Decoders** parse `Uint8Array` responses from WASM
|
|
34
|
+
exports into typed TypeScript values. Each decoder
|
|
35
|
+
returns the parsed value directly (not a
|
|
36
|
+
`{ value, offset }` pair at the top level, though
|
|
37
|
+
primitive helpers do return `DecodeResult<T>` for
|
|
38
|
+
composability).
|
|
39
|
+
|
|
40
|
+
The module has no runtime dependencies on the WASM
|
|
41
|
+
binary itself -- it only manipulates `Uint8Array`
|
|
42
|
+
buffers using `DataView` and `TextEncoder`/
|
|
43
|
+
`TextDecoder`.
|
|
44
|
+
|
|
45
|
+
## Directory Layout
|
|
46
|
+
|
|
47
|
+
```
|
|
48
|
+
src/shared/wasm-codec/
|
|
49
|
+
├── index.ts
|
|
50
|
+
└── functions/
|
|
51
|
+
├── decode-compose-output.function.ts
|
|
52
|
+
├── decode-document-manifest.function.ts
|
|
53
|
+
├── decode-f32.function.ts
|
|
54
|
+
├── decode-key-value-text.function.ts
|
|
55
|
+
├── decode-remove-flag.function.ts
|
|
56
|
+
├── decode-scored-results.function.ts
|
|
57
|
+
├── decode-section-records.function.ts
|
|
58
|
+
├── decode-string.function.ts
|
|
59
|
+
├── decode-u32.function.ts
|
|
60
|
+
├── decode-u64.function.ts
|
|
61
|
+
├── encode-add-section-params.function.ts
|
|
62
|
+
├── encode-group-params.function.ts
|
|
63
|
+
├── encode-identifier-list.function.ts
|
|
64
|
+
├── encode-kbid-list.function.ts
|
|
65
|
+
├── encode-option-string.function.ts
|
|
66
|
+
├── encode-search-params.function.ts
|
|
67
|
+
├── encode-section-type.function.ts
|
|
68
|
+
├── encode-string.function.ts
|
|
69
|
+
├── encode-u32.function.ts
|
|
70
|
+
└── encode-update-section-params.function.ts
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Exports
|
|
74
|
+
|
|
75
|
+
- **[functions.md](functions.md)** -- all encode and
|
|
76
|
+
decode functions plus exported data types
|
|
77
|
+
(`AddSectionInput`, `ScoredResult`, `TermMatch`,
|
|
78
|
+
`SectionRecord`, `DocumentManifest`,
|
|
79
|
+
`DocumentSection`, `ComposeOutput`, `DecodeResult`).
|
|
80
|
+
|
|
81
|
+
## Usage
|
|
82
|
+
|
|
83
|
+
The module is used exclusively by
|
|
84
|
+
`WorkerDaemon.handleRequest` and its private dispatch
|
|
85
|
+
helpers. Callers encode parameters before calling a
|
|
86
|
+
WASM export and decode the response bytes after the
|
|
87
|
+
call returns.
|
|
88
|
+
|
|
89
|
+
```ts
|
|
90
|
+
import {
|
|
91
|
+
encodeSearchParams,
|
|
92
|
+
decodeScoredResults,
|
|
93
|
+
} from '../../wasm-codec/index.ts';
|
|
94
|
+
|
|
95
|
+
const encoded = encodeSearchParams(query, mode, limit);
|
|
96
|
+
// ... write encoded to WASM memory, call export ...
|
|
97
|
+
const results = decodeScoredResults(responseBytes);
|
|
98
|
+
```
|