@dikolab/kbdb 0.1.6 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (199) hide show
  1. package/README.md +30 -9
  2. package/dist/cli.cjs +181 -50
  3. package/dist/cli.cjs.map +3 -3
  4. package/dist/cli.mjs +181 -50
  5. package/dist/cli.mjs.map +3 -3
  6. package/dist/kbdb-worker.cjs +283 -29
  7. package/dist/kbdb-worker.cjs.map +4 -4
  8. package/dist/mod.cjs +13 -2
  9. package/dist/mod.cjs.map +2 -2
  10. package/dist/mod.d.ts +25 -0
  11. package/dist/mod.mjs +13 -2
  12. package/dist/mod.mjs.map +2 -2
  13. package/dist/src/cli.d.ts +8 -0
  14. package/dist/src/shared/cli/functions/format-output.function.d.ts +7 -7
  15. package/dist/src/shared/cli/functions/run-search.function.d.ts +25 -16
  16. package/dist/src/shared/cli/index.d.ts +1 -1
  17. package/dist/src/shared/cli/typings/cli-options.interface.d.ts +2 -0
  18. package/dist/src/shared/cli/typings/search-display.model.d.ts +25 -7
  19. package/dist/src/shared/mcp/functions/handle-recall.function.d.ts +29 -0
  20. package/dist/src/shared/mcp/typings/mcp-client.interface.d.ts +30 -11
  21. package/dist/src/shared/version/constants/version.constant.d.ts +1 -1
  22. package/dist/src/shared/wasm-codec/functions/decode-recall-result.function.d.ts +28 -0
  23. package/dist/src/shared/wasm-codec/functions/decode-scored-results.function.d.ts +14 -7
  24. package/dist/src/shared/wasm-codec/functions/encode-recall-params.function.d.ts +21 -0
  25. package/dist/src/shared/wasm-codec/functions/encode-search-params.function.d.ts +1 -1
  26. package/dist/src/shared/wasm-codec/index.d.ts +5 -2
  27. package/dist/src/shared/worker-client/classes/worker-client.class.d.ts +13 -3
  28. package/dist/src/shared/worker-client/index.d.ts +2 -1
  29. package/dist/src/shared/worker-client/typings/recall-result.model.d.ts +94 -0
  30. package/dist/src/shared/worker-client/typings/search-params.model.d.ts +2 -0
  31. package/dist/src/shared/worker-client/typings/search-result.model.d.ts +23 -7
  32. package/dist/src/shared/worker-daemon/classes/worker-daemon.class.d.ts +1 -0
  33. package/dist/src/worker.d.ts +7 -0
  34. package/dist/wasm/fs-database/kbdb_fs_database.d.ts +18 -0
  35. package/dist/wasm/fs-database/kbdb_fs_database.js +30 -0
  36. package/dist/wasm/fs-database/kbdb_fs_database_bg.wasm +0 -0
  37. package/dist/wasm/fs-database/kbdb_fs_database_bg.wasm.d.ts +2 -0
  38. package/dist/wasm/kb-worker/kbdb_worker.d.ts +38 -0
  39. package/dist/wasm/kb-worker/kbdb_worker.js +56 -0
  40. package/dist/wasm/kb-worker/kbdb_worker_bg.wasm +0 -0
  41. package/dist/wasm/kb-worker/kbdb_worker_bg.wasm.d.ts +3 -0
  42. package/dist/worker.mjs +283 -29
  43. package/dist/worker.mjs.map +4 -4
  44. package/docs/details/README.md +26 -0
  45. package/docs/details/cli.md +608 -0
  46. package/docs/details/library-api.md +406 -0
  47. package/docs/details/mcp-server.md +430 -0
  48. package/docs/details/search-and-ranking.md +457 -0
  49. package/docs/details/storage.md +529 -0
  50. package/docs/goals/agents.md +751 -0
  51. package/docs/goals/architecture.svg +198 -0
  52. package/docs/goals/cli.md +2308 -0
  53. package/docs/goals/content-composer.md +609 -0
  54. package/docs/goals/content-parser.md +279 -0
  55. package/docs/goals/database.md +1452 -0
  56. package/docs/goals/document.md +368 -0
  57. package/docs/goals/mcp.md +1467 -0
  58. package/docs/goals/overview.md +124 -0
  59. package/docs/goals/query-parser.md +271 -0
  60. package/docs/goals/query-result.md +693 -0
  61. package/docs/goals/skills.md +738 -0
  62. package/docs/goals/worker-client.md +944 -0
  63. package/docs/goals/worker-daemon.md +1447 -0
  64. package/docs/modules/overview.md +298 -0
  65. package/docs/modules/rust/fs-database/functions/document.md +48 -0
  66. package/docs/modules/rust/fs-database/functions/integrity.md +68 -0
  67. package/docs/modules/rust/fs-database/functions/io.md +87 -0
  68. package/docs/modules/rust/fs-database/functions/module.md +22 -0
  69. package/docs/modules/rust/fs-database/functions/query-exec.md +44 -0
  70. package/docs/modules/rust/fs-database/functions/section.md +59 -0
  71. package/docs/modules/rust/fs-database/indexes/btree.md +35 -0
  72. package/docs/modules/rust/fs-database/indexes/corpus.md +61 -0
  73. package/docs/modules/rust/fs-database/indexes/inverted.md +60 -0
  74. package/docs/modules/rust/fs-database/indexes/module.md +64 -0
  75. package/docs/modules/rust/fs-database/indexes/positional.md +39 -0
  76. package/docs/modules/rust/fs-database/module.md +149 -0
  77. package/docs/modules/rust/fs-database/types/catalog.md +53 -0
  78. package/docs/modules/rust/fs-database/types/module.md +12 -0
  79. package/docs/modules/rust/fs-database/types/section.md +101 -0
  80. package/docs/modules/rust/kb-worker/functions/compose.md +57 -0
  81. package/docs/modules/rust/kb-worker/functions/module.md +20 -0
  82. package/docs/modules/rust/kb-worker/functions/retrieve.md +194 -0
  83. package/docs/modules/rust/kb-worker/functions/search.md +173 -0
  84. package/docs/modules/rust/kb-worker/functions/write.md +172 -0
  85. package/docs/modules/rust/kb-worker/module.md +171 -0
  86. package/docs/modules/rust/kb-worker/types/cache.md +90 -0
  87. package/docs/modules/rust/kb-worker/types/context.md +26 -0
  88. package/docs/modules/rust/kb-worker/types/module.md +16 -0
  89. package/docs/modules/rust/kb-worker/types/status.md +29 -0
  90. package/docs/modules/rust/kb-worker/types/token.md +50 -0
  91. package/docs/modules/rust/overview.md +495 -0
  92. package/docs/modules/rust/query-parser/functions/extract.md +56 -0
  93. package/docs/modules/rust/query-parser/functions/module.md +16 -0
  94. package/docs/modules/rust/query-parser/functions/parse.md +33 -0
  95. package/docs/modules/rust/query-parser/functions/pipeline.md +103 -0
  96. package/docs/modules/rust/query-parser/functions/rank.md +85 -0
  97. package/docs/modules/rust/query-parser/module.md +136 -0
  98. package/docs/modules/rust/query-parser/types/cache.md +39 -0
  99. package/docs/modules/rust/query-parser/types/keyphrase.md +60 -0
  100. package/docs/modules/rust/query-parser/types/module.md +17 -0
  101. package/docs/modules/rust/query-parser/types/token.md +42 -0
  102. package/docs/modules/rust/shared/content-composer/functions.md +114 -0
  103. package/docs/modules/rust/shared/content-composer/module.md +147 -0
  104. package/docs/modules/rust/shared/content-composer/types.md +93 -0
  105. package/docs/modules/rust/shared/content-parser/functions.md +72 -0
  106. package/docs/modules/rust/shared/content-parser/module.md +99 -0
  107. package/docs/modules/rust/shared/content-parser/types.md +71 -0
  108. package/docs/modules/rust/shared/corpus/module.md +24 -0
  109. package/docs/modules/rust/shared/corpus/types.md +141 -0
  110. package/docs/modules/rust/shared/document/module.md +25 -0
  111. package/docs/modules/rust/shared/document/types.md +154 -0
  112. package/docs/modules/rust/shared/encode/module.md +22 -0
  113. package/docs/modules/rust/shared/encode/traits.md +304 -0
  114. package/docs/modules/rust/shared/error/module.md +28 -0
  115. package/docs/modules/rust/shared/error/types.md +302 -0
  116. package/docs/modules/rust/shared/kbid/module.md +24 -0
  117. package/docs/modules/rust/shared/kbid/types.md +147 -0
  118. package/docs/modules/rust/shared/memory/functions.md +209 -0
  119. package/docs/modules/rust/shared/memory/module.md +24 -0
  120. package/docs/modules/rust/shared/module.md +168 -0
  121. package/docs/modules/rust/shared/query/module.md +27 -0
  122. package/docs/modules/rust/shared/query/types.md +236 -0
  123. package/docs/modules/rust/shared/section/module.md +25 -0
  124. package/docs/modules/rust/shared/section/types.md +294 -0
  125. package/docs/modules/rust/shared/term/module.md +25 -0
  126. package/docs/modules/rust/shared/term/types.md +139 -0
  127. package/docs/modules/typescript/cli.md +129 -0
  128. package/docs/modules/typescript/kbdb-worker.md +135 -0
  129. package/docs/modules/typescript/overview.md +378 -0
  130. package/docs/modules/typescript/shared/cli/constants.md +23 -0
  131. package/docs/modules/typescript/shared/cli/functions.md +630 -0
  132. package/docs/modules/typescript/shared/cli/module.md +125 -0
  133. package/docs/modules/typescript/shared/cli/typings.md +172 -0
  134. package/docs/modules/typescript/shared/hash/functions.md +20 -0
  135. package/docs/modules/typescript/shared/hash/module.md +21 -0
  136. package/docs/modules/typescript/shared/mcp/classes.md +179 -0
  137. package/docs/modules/typescript/shared/mcp/functions.md +386 -0
  138. package/docs/modules/typescript/shared/mcp/module.md +160 -0
  139. package/docs/modules/typescript/shared/mcp/typings.md +522 -0
  140. package/docs/modules/typescript/shared/module.md +94 -0
  141. package/docs/modules/typescript/shared/platform/functions.md +42 -0
  142. package/docs/modules/typescript/shared/platform/module.md +25 -0
  143. package/docs/modules/typescript/shared/runtime/functions.md +26 -0
  144. package/docs/modules/typescript/shared/runtime/module.md +27 -0
  145. package/docs/modules/typescript/shared/runtime/typings.md +13 -0
  146. package/docs/modules/typescript/shared/version/module.md +27 -0
  147. package/docs/modules/typescript/shared/wasm-codec/functions.md +391 -0
  148. package/docs/modules/typescript/shared/wasm-codec/module.md +98 -0
  149. package/docs/modules/typescript/shared/worker-client/classes.md +264 -0
  150. package/docs/modules/typescript/shared/worker-client/functions.md +175 -0
  151. package/docs/modules/typescript/shared/worker-client/module.md +84 -0
  152. package/docs/modules/typescript/shared/worker-client/typings.md +508 -0
  153. package/docs/modules/typescript/shared/worker-daemon/classes.md +239 -0
  154. package/docs/modules/typescript/shared/worker-daemon/constants.md +37 -0
  155. package/docs/modules/typescript/shared/worker-daemon/functions.md +221 -0
  156. package/docs/modules/typescript/shared/worker-daemon/module.md +112 -0
  157. package/docs/modules/typescript/shared/worker-daemon/typings.md +126 -0
  158. package/docs/overview.md +188 -0
  159. package/docs/release-notes/0.1.0.md +189 -0
  160. package/docs/release-notes/0.1.1.md +46 -0
  161. package/docs/release-notes/0.1.2.md +38 -0
  162. package/docs/release-notes/0.1.3.md +42 -0
  163. package/docs/release-notes/0.2.0.md +147 -0
  164. package/docs/release-notes/README.md +9 -0
  165. package/mod.ts +26 -0
  166. package/package.json +8 -2
  167. package/src/cli.ts +9 -0
  168. package/src/shared/cli/functions/dispatch-command.function.ts +3 -3
  169. package/src/shared/cli/functions/format-output.function.ts +41 -34
  170. package/src/shared/cli/functions/parse-args.function.ts +7 -0
  171. package/src/shared/cli/functions/run-search.function.ts +53 -27
  172. package/src/shared/cli/index.ts +4 -1
  173. package/src/shared/cli/typings/cli-options.interface.ts +2 -0
  174. package/src/shared/cli/typings/search-display.model.ts +26 -7
  175. package/src/shared/mcp/functions/create-tool-definitions.function.ts +64 -4
  176. package/src/shared/mcp/functions/handle-recall.function.ts +66 -0
  177. package/src/shared/mcp/functions/handle-tool-call.function.ts +11 -1
  178. package/src/shared/mcp/typings/mcp-client.interface.ts +33 -15
  179. package/src/shared/version/constants/version.constant.ts +1 -1
  180. package/src/shared/wasm-codec/functions/decode-recall-result.function.ts +267 -0
  181. package/src/shared/wasm-codec/functions/decode-scored-results.function.ts +81 -27
  182. package/src/shared/wasm-codec/functions/encode-recall-params.function.ts +68 -0
  183. package/src/shared/wasm-codec/functions/encode-search-params.function.ts +4 -1
  184. package/src/shared/wasm-codec/index.ts +11 -3
  185. package/src/shared/worker-client/classes/worker-client.class.ts +24 -4
  186. package/src/shared/worker-client/index.ts +11 -1
  187. package/src/shared/worker-client/typings/recall-result.model.ts +98 -0
  188. package/src/shared/worker-client/typings/search-params.model.ts +2 -0
  189. package/src/shared/worker-client/typings/search-result.model.ts +24 -7
  190. package/src/shared/worker-daemon/classes/worker-daemon.class.ts +25 -4
  191. package/src/wasm/fs-database/kbdb_fs_database.d.ts +18 -0
  192. package/src/wasm/fs-database/kbdb_fs_database.js +30 -0
  193. package/src/wasm/fs-database/kbdb_fs_database_bg.wasm +0 -0
  194. package/src/wasm/fs-database/kbdb_fs_database_bg.wasm.d.ts +2 -0
  195. package/src/wasm/kb-worker/kbdb_worker.d.ts +38 -0
  196. package/src/wasm/kb-worker/kbdb_worker.js +56 -0
  197. package/src/wasm/kb-worker/kbdb_worker_bg.wasm +0 -0
  198. package/src/wasm/kb-worker/kbdb_worker_bg.wasm.d.ts +3 -0
  199. package/src/worker.ts +8 -0
@@ -568,10 +568,13 @@ function encodeIdentifierList(ids) {
568
568
 
569
569
  // src/shared/wasm-codec/functions/encode-search-params.function.ts
570
570
  var encoder2 = new TextEncoder();
571
- function encodeSearchParams(query, mode = "and", limit = 20) {
572
- return encoder2.encode(`${query}
571
+ function encodeSearchParams(query, mode = "and", limit = 20, offset = 0) {
572
+ return encoder2.encode(
573
+ `${query}
573
574
  ${mode}
574
- ${String(limit)}`);
575
+ ${String(limit)}
576
+ ${String(offset)}`
577
+ );
575
578
  }
576
579
 
577
580
  // src/shared/wasm-codec/functions/encode-type-filter-param.function.ts
@@ -634,40 +637,75 @@ function decodeU64(bytes, offset) {
634
637
  }
635
638
 
636
639
  // src/shared/wasm-codec/functions/decode-scored-results.function.ts
637
- function decodeScoredResults(bytes) {
640
+ function decodeOptionString(bytes, offset) {
641
+ const tag = bytes[offset];
642
+ if (tag === 0) {
643
+ return { value: null, bytesRead: 1 };
644
+ }
645
+ const str = decodeString(bytes, offset + 1);
646
+ return { value: str.value, bytesRead: 1 + str.bytesRead };
647
+ }
648
+ function decodePagedSearchResult(bytes) {
638
649
  let offset = 0;
639
- const count = decodeU32(bytes, offset);
640
- offset += count.bytesRead;
641
- const results = [];
642
- for (let i = 0; i < count.value; i++) {
650
+ const total = decodeU32(bytes, offset);
651
+ offset += total.bytesRead;
652
+ const resultOffset = decodeU32(bytes, offset);
653
+ offset += resultOffset.bytesRead;
654
+ const limit = decodeU32(bytes, offset);
655
+ offset += limit.bytesRead;
656
+ const hasMore = bytes[offset] === 1;
657
+ offset += 1;
658
+ const itemCount = decodeU32(bytes, offset);
659
+ offset += itemCount.bytesRead;
660
+ const items = [];
661
+ for (let i = 0; i < itemCount.value; i++) {
643
662
  const kbid = decodeString(bytes, offset);
644
663
  offset += kbid.bytesRead;
664
+ const heading = decodeOptionString(bytes, offset);
665
+ offset += heading.bytesRead;
666
+ const sectionType = decodeString(bytes, offset);
667
+ offset += sectionType.bytesRead;
668
+ const docidCount = decodeU32(bytes, offset);
669
+ offset += docidCount.bytesRead;
670
+ const docids = [];
671
+ for (let j = 0; j < docidCount.value; j++) {
672
+ const docid = decodeString(bytes, offset);
673
+ offset += docid.bytesRead;
674
+ docids.push(docid.value);
675
+ }
645
676
  const score = decodeF32(bytes, offset);
646
677
  offset += score.bytesRead;
647
- const matchCount = decodeU32(bytes, offset);
648
- offset += matchCount.bytesRead;
649
- const matches = [];
650
- for (let j = 0; j < matchCount.value; j++) {
678
+ const snippet = decodeString(bytes, offset);
679
+ offset += snippet.bytesRead;
680
+ const termCount = decodeU32(bytes, offset);
681
+ offset += termCount.bytesRead;
682
+ const matched_terms = [];
683
+ for (let j = 0; j < termCount.value; j++) {
651
684
  const term = decodeString(bytes, offset);
652
685
  offset += term.bytesRead;
653
- const freq = decodeF32(bytes, offset);
654
- offset += freq.bytesRead;
655
- matches.push({
656
- term: term.value,
657
- frequency: freq.value
658
- });
686
+ matched_terms.push(term.value);
659
687
  }
660
- results.push({
688
+ items.push({
661
689
  kbid: kbid.value,
690
+ heading: heading.value,
691
+ type: sectionType.value,
692
+ docids,
662
693
  score: score.value,
663
- matches
694
+ snippet: snippet.value,
695
+ matched_terms
664
696
  });
665
697
  }
666
- return results;
698
+ return {
699
+ items,
700
+ total: total.value,
701
+ offset: resultOffset.value,
702
+ limit: limit.value,
703
+ has_more: hasMore
704
+ };
667
705
  }
668
706
 
669
707
  // src/shared/wasm-codec/functions/decode-section-records.function.ts
670
- function decodeOptionString(bytes, offset) {
708
+ function decodeOptionString2(bytes, offset) {
671
709
  const tag = bytes[offset];
672
710
  if (tag === 0) {
673
711
  return { value: null, bytesRead: 1 };
@@ -696,13 +734,13 @@ function decodeSectionRecords(bytes) {
696
734
  for (let i = 0; i < count.value; i++) {
697
735
  const kbid = decodeString(bytes, offset);
698
736
  offset += kbid.bytesRead;
699
- const docid = decodeOptionString(bytes, offset);
737
+ const docid = decodeOptionString2(bytes, offset);
700
738
  offset += docid.bytesRead;
701
739
  const st = decodeSectionType(bytes, offset);
702
740
  offset += st.bytesRead;
703
- const title = decodeOptionString(bytes, offset);
741
+ const title = decodeOptionString2(bytes, offset);
704
742
  offset += title.bytesRead;
705
- const description = decodeOptionString(bytes, offset);
743
+ const description = decodeOptionString2(bytes, offset);
706
744
  offset += description.bytesRead;
707
745
  const content = decodeString(bytes, offset);
708
746
  offset += content.bytesRead;
@@ -853,6 +891,209 @@ function decodeRemoveFlag(bytes) {
853
891
  return bytes.length > 0 && bytes[0] === 1;
854
892
  }
855
893
 
894
+ // src/shared/wasm-codec/functions/encode-recall-params.function.ts
895
+ function encodeRecallParams(params) {
896
+ const depth = params.depth ?? 0;
897
+ const depthBytes = encodeU32(depth);
898
+ if (params.kbids !== void 0) {
899
+ const allKbids = params.kbid !== void 0 ? [...params.kbids, params.kbid] : [...params.kbids];
900
+ const countBytes = encodeU32(allKbids.length);
901
+ const encodedKbids = allKbids.map(encodeString);
902
+ const totalLen2 = 1 + // tag
903
+ countBytes.length + encodedKbids.reduce((sum, b) => sum + b.length, 0) + depthBytes.length;
904
+ const result2 = new Uint8Array(totalLen2);
905
+ let offset2 = 0;
906
+ result2[offset2++] = 1;
907
+ result2.set(countBytes, offset2);
908
+ offset2 += countBytes.length;
909
+ for (const kbidBytes2 of encodedKbids) {
910
+ result2.set(kbidBytes2, offset2);
911
+ offset2 += kbidBytes2.length;
912
+ }
913
+ result2.set(depthBytes, offset2);
914
+ return result2;
915
+ }
916
+ const kbid = params.kbid ?? "";
917
+ const kbidBytes = encodeString(kbid);
918
+ const totalLen = 1 + kbidBytes.length + depthBytes.length;
919
+ const result = new Uint8Array(totalLen);
920
+ let offset = 0;
921
+ result[offset++] = 0;
922
+ result.set(kbidBytes, offset);
923
+ offset += kbidBytes.length;
924
+ result.set(depthBytes, offset);
925
+ return result;
926
+ }
927
+
928
+ // src/shared/wasm-codec/functions/decode-recall-result.function.ts
929
+ function decodeRecallResult(bytes) {
930
+ const tag = bytes[0];
931
+ let offset = 1;
932
+ if (tag === 1) {
933
+ const countResult = decodeU32(bytes, offset);
934
+ offset += countResult.bytesRead;
935
+ const items = [];
936
+ for (let i = 0; i < countResult.value; i++) {
937
+ const { item: item2, bytesRead } = decodeOneResult(bytes, offset);
938
+ offset += bytesRead;
939
+ items.push(item2);
940
+ }
941
+ return items;
942
+ }
943
+ const { item } = decodeOneResult(bytes, offset);
944
+ return item;
945
+ }
946
+ function decodeOptionString3(bytes, offset) {
947
+ const tag = bytes[offset];
948
+ if (tag === 0) {
949
+ return { value: null, bytesRead: 1 };
950
+ }
951
+ const str = decodeString(bytes, offset + 1);
952
+ return { value: str.value, bytesRead: 1 + str.bytesRead };
953
+ }
954
+ function decodeReference(bytes, offset) {
955
+ let pos = offset;
956
+ const kbid = decodeString(bytes, pos);
957
+ pos += kbid.bytesRead;
958
+ const heading = decodeOptionString3(bytes, pos);
959
+ pos += heading.bytesRead;
960
+ const sectionType = decodeString(bytes, pos);
961
+ pos += sectionType.bytesRead;
962
+ const markerType = decodeString(bytes, pos);
963
+ pos += markerType.bytesRead;
964
+ const contextSnippet = decodeString(bytes, pos);
965
+ pos += contextSnippet.bytesRead;
966
+ const direction = decodeString(bytes, pos);
967
+ pos += direction.bytesRead;
968
+ return {
969
+ value: {
970
+ kbid: kbid.value,
971
+ heading: heading.value,
972
+ type: sectionType.value,
973
+ marker_type: markerType.value,
974
+ context_snippet: contextSnippet.value,
975
+ direction: direction.value
976
+ },
977
+ bytesRead: pos - offset
978
+ };
979
+ }
980
+ function decodeSibling(bytes, offset) {
981
+ let pos = offset;
982
+ const kbid = decodeString(bytes, pos);
983
+ pos += kbid.bytesRead;
984
+ const heading = decodeOptionString3(bytes, pos);
985
+ pos += heading.bytesRead;
986
+ const sectionType = decodeString(bytes, pos);
987
+ pos += sectionType.bytesRead;
988
+ const content = decodeString(bytes, pos);
989
+ pos += content.bytesRead;
990
+ return {
991
+ value: {
992
+ kbid: kbid.value,
993
+ heading: heading.value,
994
+ type: sectionType.value,
995
+ content: content.value
996
+ },
997
+ bytesRead: pos - offset
998
+ };
999
+ }
1000
+ function decodeDocument(bytes, offset) {
1001
+ let pos = offset;
1002
+ const docid = decodeString(bytes, pos);
1003
+ pos += docid.bytesRead;
1004
+ const title = decodeString(bytes, pos);
1005
+ pos += title.bytesRead;
1006
+ const sectionCount = decodeU32(bytes, pos);
1007
+ pos += sectionCount.bytesRead;
1008
+ const sections = [];
1009
+ for (let i = 0; i < sectionCount.value; i++) {
1010
+ const secKbid = decodeString(bytes, pos);
1011
+ pos += secKbid.bytesRead;
1012
+ const secHeading = decodeOptionString3(bytes, pos);
1013
+ pos += secHeading.bytesRead;
1014
+ const secType = decodeString(bytes, pos);
1015
+ pos += secType.bytesRead;
1016
+ sections.push({
1017
+ kbid: secKbid.value,
1018
+ heading: secHeading.value,
1019
+ type: secType.value
1020
+ });
1021
+ }
1022
+ return {
1023
+ value: {
1024
+ docid: docid.value,
1025
+ title: title.value,
1026
+ sections
1027
+ },
1028
+ bytesRead: pos - offset
1029
+ };
1030
+ }
1031
+ function decodeOneResult(bytes, startOffset) {
1032
+ let pos = startOffset;
1033
+ const kbid = decodeString(bytes, pos);
1034
+ pos += kbid.bytesRead;
1035
+ const heading = decodeOptionString3(bytes, pos);
1036
+ pos += heading.bytesRead;
1037
+ const sectionType = decodeString(bytes, pos);
1038
+ pos += sectionType.bytesRead;
1039
+ const content = decodeString(bytes, pos);
1040
+ pos += content.bytesRead;
1041
+ const docidCount = decodeU32(bytes, pos);
1042
+ pos += docidCount.bytesRead;
1043
+ const docids = [];
1044
+ for (let i = 0; i < docidCount.value; i++) {
1045
+ const docid = decodeString(bytes, pos);
1046
+ pos += docid.bytesRead;
1047
+ docids.push(docid.value);
1048
+ }
1049
+ const docCount = decodeU32(bytes, pos);
1050
+ pos += docCount.bytesRead;
1051
+ const documents = [];
1052
+ for (let i = 0; i < docCount.value; i++) {
1053
+ const doc = decodeDocument(bytes, pos);
1054
+ pos += doc.bytesRead;
1055
+ documents.push(doc.value);
1056
+ }
1057
+ const backRefCount = decodeU32(bytes, pos);
1058
+ pos += backRefCount.bytesRead;
1059
+ const back_references = [];
1060
+ for (let i = 0; i < backRefCount.value; i++) {
1061
+ const ref = decodeReference(bytes, pos);
1062
+ pos += ref.bytesRead;
1063
+ back_references.push(ref.value);
1064
+ }
1065
+ const sibCount = decodeU32(bytes, pos);
1066
+ pos += sibCount.bytesRead;
1067
+ const siblings = [];
1068
+ for (let i = 0; i < sibCount.value; i++) {
1069
+ const sib = decodeSibling(bytes, pos);
1070
+ pos += sib.bytesRead;
1071
+ siblings.push(sib.value);
1072
+ }
1073
+ const refCount = decodeU32(bytes, pos);
1074
+ pos += refCount.bytesRead;
1075
+ const references = [];
1076
+ for (let i = 0; i < refCount.value; i++) {
1077
+ const ref = decodeReference(bytes, pos);
1078
+ pos += ref.bytesRead;
1079
+ references.push(ref.value);
1080
+ }
1081
+ return {
1082
+ item: {
1083
+ kbid: kbid.value,
1084
+ heading: heading.value,
1085
+ type: sectionType.value,
1086
+ content: content.value,
1087
+ docids,
1088
+ documents,
1089
+ back_references,
1090
+ siblings,
1091
+ references
1092
+ },
1093
+ bytesRead: pos - startOffset
1094
+ };
1095
+ }
1096
+
856
1097
  // src/shared/worker-daemon/classes/worker-daemon.class.ts
857
1098
  var WASM_METHOD_MAP = {
858
1099
  search: "worker_search",
@@ -891,7 +1132,8 @@ var WASM_METHOD_MAP = {
891
1132
  listByType: "worker_list_by_type",
892
1133
  list_by_type: "worker_list_by_type",
893
1134
  listDocumentsByType: "worker_list_docs_by_type",
894
- list_docs_by_type: "worker_list_docs_by_type"
1135
+ list_docs_by_type: "worker_list_docs_by_type",
1136
+ recall: "worker_recall"
895
1137
  };
896
1138
  var CONFIG_PREFIX = "config_";
897
1139
  var CONFIG_KEY_MAP = {
@@ -1259,6 +1501,9 @@ var WorkerDaemon = class {
1259
1501
  if (method === "listDocumentsByType" || method === "list_docs_by_type") {
1260
1502
  return this.handleListDocsByType(params);
1261
1503
  }
1504
+ if (method === "recall") {
1505
+ return this.handleRecall(params);
1506
+ }
1262
1507
  return this.invokeWasmRaw(wasmExport, new Uint8Array(0));
1263
1508
  }
1264
1509
  // -- Search/query (token-based async) --
@@ -1266,7 +1511,8 @@ var WorkerDaemon = class {
1266
1511
  const query = params["query"] ?? "";
1267
1512
  const mode = params["mode"] ?? "and";
1268
1513
  const limit = Number(params["limit"] ?? 20);
1269
- const encoded = encodeSearchParams(query, mode, limit);
1514
+ const offset = Number(params["offset"] ?? 0);
1515
+ const encoded = encodeSearchParams(query, mode, limit, offset);
1270
1516
  const searchFn = this.getExport("worker_search");
1271
1517
  const ptr = this.wasmAlloc(encoded.length);
1272
1518
  this.wasmWrite(ptr, encoded);
@@ -1288,7 +1534,7 @@ var WorkerDaemon = class {
1288
1534
  throw new IpcError(-32e3, new TextDecoder().decode(errBytes));
1289
1535
  }
1290
1536
  const resultBytes = this.readReturnSlot();
1291
- return decodeScoredResults(resultBytes);
1537
+ return decodePagedSearchResult(resultBytes);
1292
1538
  }
1293
1539
  // -- Token status/result (u32 direct params) --
1294
1540
  handleResultStatus(params) {
@@ -1306,7 +1552,7 @@ var WorkerDaemon = class {
1306
1552
  throw new IpcError(-32e3, new TextDecoder().decode(errBytes));
1307
1553
  }
1308
1554
  const bytes = this.readReturnSlot();
1309
- return decodeScoredResults(bytes);
1555
+ return decodePagedSearchResult(bytes);
1310
1556
  }
1311
1557
  // -- Binary-encoded input methods --
1312
1558
  handleAddSection(params) {
@@ -1417,6 +1663,14 @@ var WorkerDaemon = class {
1417
1663
  );
1418
1664
  return decodeDocumentManifestList(bytes);
1419
1665
  }
1666
+ handleRecall(params) {
1667
+ const kbid = typeof params["kbid"] === "string" ? params["kbid"] : void 0;
1668
+ const kbids = Array.isArray(params["kbids"]) ? params["kbids"] : void 0;
1669
+ const depth = Number(params["depth"] ?? 0);
1670
+ const encoded = encodeRecallParams({ kbid, kbids, depth });
1671
+ const bytes = this.callWasmSync("worker_recall", encoded);
1672
+ return decodeRecallResult(bytes);
1673
+ }
1420
1674
  // -- Zero-arg methods --
1421
1675
  handleInvalidateAll() {
1422
1676
  this.callWasmZeroArg("worker_invalidate_all");