wiki-graph-core 0.3.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 (576) hide show
  1. package/LICENSE +201 -0
  2. package/data/editor/clue_reviewer.jinja +410 -0
  3. package/data/editor/clue_reviewer_generator.jinja +428 -0
  4. package/data/editor/revision_feedback.jinja +5 -0
  5. package/data/editor/text_compressor.jinja +127 -0
  6. package/data/guaranteed/response_intent_classifier.jinja +8 -0
  7. package/data/help/commands/archive/next.jinja +29 -0
  8. package/data/help/commands/gc.jinja +38 -0
  9. package/data/help/commands/legacy/migrate.jinja +20 -0
  10. package/data/help/commands/legacy.jinja +19 -0
  11. package/data/help/commands/maintenance/chapter/add.jinja +41 -0
  12. package/data/help/commands/maintenance/chapter/list.jinja +33 -0
  13. package/data/help/commands/maintenance/chapter/move.jinja +36 -0
  14. package/data/help/commands/maintenance/chapter/remove.jinja +26 -0
  15. package/data/help/commands/maintenance/chapter/reset.jinja +29 -0
  16. package/data/help/commands/maintenance/chapter/set-source.jinja +34 -0
  17. package/data/help/commands/maintenance/chapter/set-summary.jinja +31 -0
  18. package/data/help/commands/maintenance/chapter/set-title.jinja +29 -0
  19. package/data/help/commands/maintenance/chapter/tree.jinja +58 -0
  20. package/data/help/commands/maintenance/chapter.jinja +59 -0
  21. package/data/help/commands/maintenance/cover.jinja +28 -0
  22. package/data/help/commands/maintenance/meta.jinja +55 -0
  23. package/data/help/commands/predicate.jinja +460 -0
  24. package/data/help/commands/root.jinja +83 -0
  25. package/data/help/commands/transform.jinja +34 -0
  26. package/data/help/commands/uri.jinja +274 -0
  27. package/data/help/topics/config.jinja +88 -0
  28. package/data/help/topics/format.jinja +72 -0
  29. package/data/help/topics/readiness.jinja +99 -0
  30. package/data/help/topics/recipe.jinja +151 -0
  31. package/data/help/topics/runtime.jinja +62 -0
  32. package/data/help/topics/uri.jinja +178 -0
  33. package/data/output/epub/cover.xhtml.jinja +13 -0
  34. package/data/output/epub/nav.xhtml.jinja +12 -0
  35. package/data/output/epub/package.opf.xml.jinja +39 -0
  36. package/data/output/epub/section.xhtml.jinja +12 -0
  37. package/data/topologization/book_coherence_extraction.jinja +223 -0
  38. package/data/topologization/chunk_extraction.jinja +233 -0
  39. package/data/topologization/evidence_choice.jinja +38 -0
  40. package/data/topologization/translate_chunks.jinja +138 -0
  41. package/data/topologization/user_focused_extraction.jinja +378 -0
  42. package/dist/archive/query/archive-view.d.ts +26 -0
  43. package/dist/archive/query/archive-view.js +4540 -0
  44. package/dist/archive/query/archive-view.js.map +1 -0
  45. package/dist/archive/query/continuation-cursor.d.ts +61 -0
  46. package/dist/archive/query/continuation-cursor.js +363 -0
  47. package/dist/archive/query/continuation-cursor.js.map +1 -0
  48. package/dist/archive/query/index.d.ts +29 -0
  49. package/dist/archive/query/index.js +63 -0
  50. package/dist/archive/query/index.js.map +1 -0
  51. package/dist/archive/query/lexical-search.d.ts +22 -0
  52. package/dist/archive/query/lexical-search.js +137 -0
  53. package/dist/archive/query/lexical-search.js.map +1 -0
  54. package/dist/archive/query/search-cache.d.ts +192 -0
  55. package/dist/archive/query/search-cache.js +1248 -0
  56. package/dist/archive/query/search-cache.js.map +1 -0
  57. package/dist/archive/search-index/index.d.ts +26 -0
  58. package/dist/archive/search-index/index.js +29 -0
  59. package/dist/archive/search-index/index.js.map +1 -0
  60. package/dist/archive/search-index/search-index.d.ts +26 -0
  61. package/dist/archive/search-index/search-index.js +555 -0
  62. package/dist/archive/search-index/search-index.js.map +1 -0
  63. package/dist/archive/search-index/search-tokenizer.d.ts +16 -0
  64. package/dist/archive/search-index/search-tokenizer.js +225 -0
  65. package/dist/archive/search-index/search-tokenizer.js.map +1 -0
  66. package/dist/common/cli-command.d.ts +4 -0
  67. package/dist/common/cli-command.js +7 -0
  68. package/dist/common/cli-command.js.map +1 -0
  69. package/dist/common/data-dir.d.ts +3 -0
  70. package/dist/common/data-dir.js +48 -0
  71. package/dist/common/data-dir.js.map +1 -0
  72. package/dist/common/language.d.ts +55 -0
  73. package/dist/common/language.js +208 -0
  74. package/dist/common/language.js.map +1 -0
  75. package/dist/common/llm-scope.d.ts +19 -0
  76. package/dist/common/llm-scope.js +31 -0
  77. package/dist/common/llm-scope.js.map +1 -0
  78. package/dist/common/logging.d.ts +22 -0
  79. package/dist/common/logging.js +141 -0
  80. package/dist/common/logging.js.map +1 -0
  81. package/dist/common/template.d.ts +8 -0
  82. package/dist/common/template.js +54 -0
  83. package/dist/common/template.js.map +1 -0
  84. package/dist/common/tinyld-language.d.ts +6 -0
  85. package/dist/common/tinyld-language.js +34 -0
  86. package/dist/common/tinyld-language.js.map +1 -0
  87. package/dist/common/wiki-graph-dir.d.ts +10 -0
  88. package/dist/common/wiki-graph-dir.js +41 -0
  89. package/dist/common/wiki-graph-dir.js.map +1 -0
  90. package/dist/common/wiki-graph-temp.d.ts +6 -0
  91. package/dist/common/wiki-graph-temp.js +21 -0
  92. package/dist/common/wiki-graph-temp.js.map +1 -0
  93. package/dist/common/wiki-graph-uri.d.ts +28 -0
  94. package/dist/common/wiki-graph-uri.js +171 -0
  95. package/dist/common/wiki-graph-uri.js.map +1 -0
  96. package/dist/context/index.d.ts +1 -0
  97. package/dist/context/index.js +13 -0
  98. package/dist/context/index.js.map +1 -0
  99. package/dist/context/task-context.d.ts +41 -0
  100. package/dist/context/task-context.js +111 -0
  101. package/dist/context/task-context.js.map +1 -0
  102. package/dist/document/database.d.ts +30 -0
  103. package/dist/document/database.js +273 -0
  104. package/dist/document/database.js.map +1 -0
  105. package/dist/document/document.d.ts +153 -0
  106. package/dist/document/document.js +615 -0
  107. package/dist/document/document.js.map +1 -0
  108. package/dist/document/fragments.d.ts +63 -0
  109. package/dist/document/fragments.js +371 -0
  110. package/dist/document/fragments.js.map +1 -0
  111. package/dist/document/index.d.ts +13 -0
  112. package/dist/document/index.js +62 -0
  113. package/dist/document/index.js.map +1 -0
  114. package/dist/document/schema.d.ts +8 -0
  115. package/dist/document/schema.js +472 -0
  116. package/dist/document/schema.js.map +1 -0
  117. package/dist/document/shared-state-database.d.ts +9 -0
  118. package/dist/document/shared-state-database.js +193 -0
  119. package/dist/document/shared-state-database.js.map +1 -0
  120. package/dist/document/stores.d.ts +203 -0
  121. package/dist/document/stores.js +1678 -0
  122. package/dist/document/stores.js.map +1 -0
  123. package/dist/document/text-streams.d.ts +86 -0
  124. package/dist/document/text-streams.js +515 -0
  125. package/dist/document/text-streams.js.map +1 -0
  126. package/dist/document/types.d.ts +148 -0
  127. package/dist/document/types.js +69 -0
  128. package/dist/document/types.js.map +1 -0
  129. package/dist/editor/clue.d.ts +27 -0
  130. package/dist/editor/clue.js +158 -0
  131. package/dist/editor/clue.js.map +1 -0
  132. package/dist/editor/compressor.d.ts +18 -0
  133. package/dist/editor/compressor.js +68 -0
  134. package/dist/editor/compressor.js.map +1 -0
  135. package/dist/editor/editor.d.ts +39 -0
  136. package/dist/editor/editor.js +253 -0
  137. package/dist/editor/editor.js.map +1 -0
  138. package/dist/editor/feedback.d.ts +16 -0
  139. package/dist/editor/feedback.js +104 -0
  140. package/dist/editor/feedback.js.map +1 -0
  141. package/dist/editor/index.d.ts +17 -0
  142. package/dist/editor/index.js +5 -0
  143. package/dist/editor/index.js.map +1 -0
  144. package/dist/editor/language-review.d.ts +14 -0
  145. package/dist/editor/language-review.js +35 -0
  146. package/dist/editor/language-review.js.map +1 -0
  147. package/dist/editor/log.d.ts +37 -0
  148. package/dist/editor/log.js +202 -0
  149. package/dist/editor/log.js.map +1 -0
  150. package/dist/editor/markup.d.ts +20 -0
  151. package/dist/editor/markup.js +294 -0
  152. package/dist/editor/markup.js.map +1 -0
  153. package/dist/editor/prompt-templates.d.ts +6 -0
  154. package/dist/editor/prompt-templates.js +11 -0
  155. package/dist/editor/prompt-templates.js.map +1 -0
  156. package/dist/editor/response.d.ts +5 -0
  157. package/dist/editor/response.js +31 -0
  158. package/dist/editor/response.js.map +1 -0
  159. package/dist/editor/review.d.ts +34 -0
  160. package/dist/editor/review.js +189 -0
  161. package/dist/editor/review.js.map +1 -0
  162. package/dist/editor/types.d.ts +31 -0
  163. package/dist/editor/types.js +21 -0
  164. package/dist/editor/types.js.map +1 -0
  165. package/dist/evidence-selection/anchor-resolver.d.ts +43 -0
  166. package/dist/evidence-selection/anchor-resolver.js +783 -0
  167. package/dist/evidence-selection/anchor-resolver.js.map +1 -0
  168. package/dist/evidence-selection/anchor-types.d.ts +27 -0
  169. package/dist/evidence-selection/anchor-types.js +1 -0
  170. package/dist/evidence-selection/anchor-types.js.map +1 -0
  171. package/dist/evidence-selection/index.d.ts +8 -0
  172. package/dist/evidence-selection/index.js +32 -0
  173. package/dist/evidence-selection/index.js.map +1 -0
  174. package/dist/evidence-selection/prompt.d.ts +18 -0
  175. package/dist/evidence-selection/prompt.js +54 -0
  176. package/dist/evidence-selection/prompt.js.map +1 -0
  177. package/dist/evidence-selection/quote-score.d.ts +29 -0
  178. package/dist/evidence-selection/quote-score.js +331 -0
  179. package/dist/evidence-selection/quote-score.js.map +1 -0
  180. package/dist/evidence-selection/selection-resolver.d.ts +19 -0
  181. package/dist/evidence-selection/selection-resolver.js +303 -0
  182. package/dist/evidence-selection/selection-resolver.js.map +1 -0
  183. package/dist/evidence-selection/text.d.ts +4 -0
  184. package/dist/evidence-selection/text.js +66 -0
  185. package/dist/evidence-selection/text.js.map +1 -0
  186. package/dist/evidence-selection/types.d.ts +36 -0
  187. package/dist/evidence-selection/types.js +1 -0
  188. package/dist/evidence-selection/types.js.map +1 -0
  189. package/dist/facade/app.d.ts +75 -0
  190. package/dist/facade/app.js +141 -0
  191. package/dist/facade/app.js.map +1 -0
  192. package/dist/facade/build-queue.d.ts +181 -0
  193. package/dist/facade/build-queue.js +1442 -0
  194. package/dist/facade/build-queue.js.map +1 -0
  195. package/dist/facade/chapter-build.d.ts +60 -0
  196. package/dist/facade/chapter-build.js +1020 -0
  197. package/dist/facade/chapter-build.js.map +1 -0
  198. package/dist/facade/chapter.d.ts +168 -0
  199. package/dist/facade/chapter.js +944 -0
  200. package/dist/facade/chapter.js.map +1 -0
  201. package/dist/facade/digest.d.ts +55 -0
  202. package/dist/facade/digest.js +168 -0
  203. package/dist/facade/digest.js.map +1 -0
  204. package/dist/facade/graph.d.ts +60 -0
  205. package/dist/facade/graph.js +203 -0
  206. package/dist/facade/graph.js.map +1 -0
  207. package/dist/facade/import.d.ts +49 -0
  208. package/dist/facade/import.js +262 -0
  209. package/dist/facade/import.js.map +1 -0
  210. package/dist/facade/index.d.ts +39 -0
  211. package/dist/facade/index.js +171 -0
  212. package/dist/facade/index.js.map +1 -0
  213. package/dist/facade/knowledge-graph-build.d.ts +75 -0
  214. package/dist/facade/knowledge-graph-build.js +897 -0
  215. package/dist/facade/knowledge-graph-build.js.map +1 -0
  216. package/dist/facade/llm-sampling.d.ts +11 -0
  217. package/dist/facade/llm-sampling.js +58 -0
  218. package/dist/facade/llm-sampling.js.map +1 -0
  219. package/dist/facade/types.d.ts +8 -0
  220. package/dist/facade/types.js +1 -0
  221. package/dist/facade/types.js.map +1 -0
  222. package/dist/facade/wiki-graph-archive.d.ts +41 -0
  223. package/dist/facade/wiki-graph-archive.js +130 -0
  224. package/dist/facade/wiki-graph-archive.js.map +1 -0
  225. package/dist/gc/files.d.ts +15 -0
  226. package/dist/gc/files.js +141 -0
  227. package/dist/gc/files.js.map +1 -0
  228. package/dist/gc/index.d.ts +2 -0
  229. package/dist/gc/index.js +5 -0
  230. package/dist/gc/index.js.map +1 -0
  231. package/dist/gc/lock.d.ts +3 -0
  232. package/dist/gc/lock.js +137 -0
  233. package/dist/gc/lock.js.map +1 -0
  234. package/dist/gc/runner.d.ts +9 -0
  235. package/dist/gc/runner.js +129 -0
  236. package/dist/gc/runner.js.map +1 -0
  237. package/dist/gc/tmp-gc.d.ts +5 -0
  238. package/dist/gc/tmp-gc.js +57 -0
  239. package/dist/gc/tmp-gc.js.map +1 -0
  240. package/dist/gc/types.d.ts +24 -0
  241. package/dist/gc/types.js +1 -0
  242. package/dist/gc/types.js.map +1 -0
  243. package/dist/gc.cjs +10041 -0
  244. package/dist/gc.cjs.map +1 -0
  245. package/dist/gc.d.cts +10 -0
  246. package/dist/gc.d.ts +2 -0
  247. package/dist/gc.js +5 -0
  248. package/dist/gc.js.map +1 -0
  249. package/dist/guaranteed/classifier.d.ts +10 -0
  250. package/dist/guaranteed/classifier.js +88 -0
  251. package/dist/guaranteed/classifier.js.map +1 -0
  252. package/dist/guaranteed/errors.d.ts +38 -0
  253. package/dist/guaranteed/errors.js +73 -0
  254. package/dist/guaranteed/errors.js.map +1 -0
  255. package/dist/guaranteed/index.d.ts +7 -0
  256. package/dist/guaranteed/index.js +21 -0
  257. package/dist/guaranteed/index.js.map +1 -0
  258. package/dist/guaranteed/request.d.ts +8 -0
  259. package/dist/guaranteed/request.js +206 -0
  260. package/dist/guaranteed/request.js.map +1 -0
  261. package/dist/guaranteed/response.d.ts +12 -0
  262. package/dist/guaranteed/response.js +98 -0
  263. package/dist/guaranteed/response.js.map +1 -0
  264. package/dist/guaranteed/types.d.ts +20 -0
  265. package/dist/guaranteed/types.js +1 -0
  266. package/dist/guaranteed/types.js.map +1 -0
  267. package/dist/index-B8NNnQ8P.d.ts +424 -0
  268. package/dist/index.cjs +34774 -0
  269. package/dist/index.cjs.map +1 -0
  270. package/dist/index.d.cts +2462 -0
  271. package/dist/index.d.ts +79 -0
  272. package/dist/index.js +168 -0
  273. package/dist/index.js.map +1 -0
  274. package/dist/legacy-sdpub/upgrade.d.ts +7 -0
  275. package/dist/legacy-sdpub/upgrade.js +795 -0
  276. package/dist/legacy-sdpub/upgrade.js.map +1 -0
  277. package/dist/llm/cache.d.ts +13 -0
  278. package/dist/llm/cache.js +35 -0
  279. package/dist/llm/cache.js.map +1 -0
  280. package/dist/llm/client.d.ts +26 -0
  281. package/dist/llm/client.js +572 -0
  282. package/dist/llm/client.js.map +1 -0
  283. package/dist/llm/context.d.ts +22 -0
  284. package/dist/llm/context.js +78 -0
  285. package/dist/llm/context.js.map +1 -0
  286. package/dist/llm/errors.d.ts +7 -0
  287. package/dist/llm/errors.js +12 -0
  288. package/dist/llm/errors.js.map +1 -0
  289. package/dist/llm/index.d.ts +7 -0
  290. package/dist/llm/index.js +17 -0
  291. package/dist/llm/index.js.map +1 -0
  292. package/dist/llm/request-log.d.ts +9 -0
  293. package/dist/llm/request-log.js +35 -0
  294. package/dist/llm/request-log.js.map +1 -0
  295. package/dist/llm/sampling.d.ts +11 -0
  296. package/dist/llm/sampling.js +67 -0
  297. package/dist/llm/sampling.js.map +1 -0
  298. package/dist/llm/types.d.ts +50 -0
  299. package/dist/llm/types.js +1 -0
  300. package/dist/llm/types.js.map +1 -0
  301. package/dist/output/epub/archive.d.ts +9 -0
  302. package/dist/output/epub/archive.js +81 -0
  303. package/dist/output/epub/archive.js.map +1 -0
  304. package/dist/output/epub/book.d.ts +15 -0
  305. package/dist/output/epub/book.js +76 -0
  306. package/dist/output/epub/book.js.map +1 -0
  307. package/dist/output/epub/content.d.ts +9 -0
  308. package/dist/output/epub/content.js +35 -0
  309. package/dist/output/epub/content.js.map +1 -0
  310. package/dist/output/epub/index.d.ts +20 -0
  311. package/dist/output/epub/index.js +14 -0
  312. package/dist/output/epub/index.js.map +1 -0
  313. package/dist/output/epub/model.d.ts +24 -0
  314. package/dist/output/epub/model.js +1 -0
  315. package/dist/output/epub/model.js.map +1 -0
  316. package/dist/output/epub/navigation.d.ts +10 -0
  317. package/dist/output/epub/navigation.js +39 -0
  318. package/dist/output/epub/navigation.js.map +1 -0
  319. package/dist/output/epub/package.d.ts +17 -0
  320. package/dist/output/epub/package.js +29 -0
  321. package/dist/output/epub/package.js.map +1 -0
  322. package/dist/output/epub/shared.d.ts +4 -0
  323. package/dist/output/epub/shared.js +12 -0
  324. package/dist/output/epub/shared.js.map +1 -0
  325. package/dist/output/epub/templates.d.ts +35 -0
  326. package/dist/output/epub/templates.js +26 -0
  327. package/dist/output/epub/templates.js.map +1 -0
  328. package/dist/output/index.d.ts +14 -0
  329. package/dist/output/index.js +11 -0
  330. package/dist/output/index.js.map +1 -0
  331. package/dist/output/plain-text.d.ts +18 -0
  332. package/dist/output/plain-text.js +56 -0
  333. package/dist/output/plain-text.js.map +1 -0
  334. package/dist/progress/index.d.ts +3 -0
  335. package/dist/progress/index.js +14 -0
  336. package/dist/progress/index.js.map +1 -0
  337. package/dist/progress/reporter.d.ts +10 -0
  338. package/dist/progress/reporter.js +79 -0
  339. package/dist/progress/reporter.js.map +1 -0
  340. package/dist/progress/tracker.d.ts +37 -0
  341. package/dist/progress/tracker.js +119 -0
  342. package/dist/progress/tracker.js.map +1 -0
  343. package/dist/progress/types.d.ts +28 -0
  344. package/dist/progress/types.js +1 -0
  345. package/dist/progress/types.js.map +1 -0
  346. package/dist/reader/attention/attention.d.ts +39 -0
  347. package/dist/reader/attention/attention.js +123 -0
  348. package/dist/reader/attention/attention.js.map +1 -0
  349. package/dist/reader/attention/index.d.ts +9 -0
  350. package/dist/reader/attention/index.js +5 -0
  351. package/dist/reader/attention/index.js.map +1 -0
  352. package/dist/reader/attention/wave-reflection.d.ts +21 -0
  353. package/dist/reader/attention/wave-reflection.js +153 -0
  354. package/dist/reader/attention/wave-reflection.js.map +1 -0
  355. package/dist/reader/attention/working-memory.d.ts +28 -0
  356. package/dist/reader/attention/working-memory.js +62 -0
  357. package/dist/reader/attention/working-memory.js.map +1 -0
  358. package/dist/reader/chunk-batch/extract.d.ts +13 -0
  359. package/dist/reader/chunk-batch/extract.js +14 -0
  360. package/dist/reader/chunk-batch/extract.js.map +1 -0
  361. package/dist/reader/chunk-batch/extractor.d.ts +17 -0
  362. package/dist/reader/chunk-batch/extractor.js +337 -0
  363. package/dist/reader/chunk-batch/extractor.js.map +1 -0
  364. package/dist/reader/chunk-batch/fragment-projection.d.ts +34 -0
  365. package/dist/reader/chunk-batch/fragment-projection.js +94 -0
  366. package/dist/reader/chunk-batch/fragment-projection.js.map +1 -0
  367. package/dist/reader/chunk-batch/index.d.ts +12 -0
  368. package/dist/reader/chunk-batch/index.js +13 -0
  369. package/dist/reader/chunk-batch/index.js.map +1 -0
  370. package/dist/reader/chunk-batch/language.d.ts +9 -0
  371. package/dist/reader/chunk-batch/language.js +23 -0
  372. package/dist/reader/chunk-batch/language.js.map +1 -0
  373. package/dist/reader/chunk-batch/parser.d.ts +94 -0
  374. package/dist/reader/chunk-batch/parser.js +640 -0
  375. package/dist/reader/chunk-batch/parser.js.map +1 -0
  376. package/dist/reader/chunk-batch/prompt-templates.d.ts +6 -0
  377. package/dist/reader/chunk-batch/prompt-templates.js +11 -0
  378. package/dist/reader/chunk-batch/prompt-templates.js.map +1 -0
  379. package/dist/reader/chunk-batch/types.d.ts +85 -0
  380. package/dist/reader/chunk-batch/types.js +1 -0
  381. package/dist/reader/chunk-batch/types.js.map +1 -0
  382. package/dist/reader/index.d.ts +13 -0
  383. package/dist/reader/index.js +7 -0
  384. package/dist/reader/index.js.map +1 -0
  385. package/dist/reader/reader.d.ts +37 -0
  386. package/dist/reader/reader.js +82 -0
  387. package/dist/reader/reader.js.map +1 -0
  388. package/dist/reader/segment/index.d.ts +2 -0
  389. package/dist/reader/segment/index.js +5 -0
  390. package/dist/reader/segment/index.js.map +1 -0
  391. package/dist/reader/segment/intl-segmenter.d.ts +5 -0
  392. package/dist/reader/segment/intl-segmenter.js +102 -0
  393. package/dist/reader/segment/intl-segmenter.js.map +1 -0
  394. package/dist/reader/segment/segment.d.ts +5 -0
  395. package/dist/reader/segment/segment.js +9 -0
  396. package/dist/reader/segment/segment.js.map +1 -0
  397. package/dist/reader/segment/types.d.ts +14 -0
  398. package/dist/reader/segment/types.js +1 -0
  399. package/dist/reader/segment/types.js.map +1 -0
  400. package/dist/reader/types.d.ts +29 -0
  401. package/dist/reader/types.js +1 -0
  402. package/dist/reader/types.js.map +1 -0
  403. package/dist/serial.d.ts +89 -0
  404. package/dist/serial.js +476 -0
  405. package/dist/serial.js.map +1 -0
  406. package/dist/source/adapter.d.ts +15 -0
  407. package/dist/source/adapter.js +1 -0
  408. package/dist/source/adapter.js.map +1 -0
  409. package/dist/source/epub/archive.d.ts +27 -0
  410. package/dist/source/epub/archive.js +189 -0
  411. package/dist/source/epub/archive.js.map +1 -0
  412. package/dist/source/epub/content.d.ts +22 -0
  413. package/dist/source/epub/content.js +183 -0
  414. package/dist/source/epub/content.js.map +1 -0
  415. package/dist/source/epub/document.d.ts +55 -0
  416. package/dist/source/epub/document.js +179 -0
  417. package/dist/source/epub/document.js.map +1 -0
  418. package/dist/source/epub/index.d.ts +10 -0
  419. package/dist/source/epub/index.js +6 -0
  420. package/dist/source/epub/index.js.map +1 -0
  421. package/dist/source/epub/navigation.d.ts +16 -0
  422. package/dist/source/epub/navigation.js +215 -0
  423. package/dist/source/epub/navigation.js.map +1 -0
  424. package/dist/source/epub/package.d.ts +33 -0
  425. package/dist/source/epub/package.js +237 -0
  426. package/dist/source/epub/package.js.map +1 -0
  427. package/dist/source/epub/xml.d.ts +16 -0
  428. package/dist/source/epub/xml.js +111 -0
  429. package/dist/source/epub/xml.js.map +1 -0
  430. package/dist/source/index.d.ts +12 -0
  431. package/dist/source/index.js +32 -0
  432. package/dist/source/index.js.map +1 -0
  433. package/dist/source/meta.d.ts +30 -0
  434. package/dist/source/meta.js +22 -0
  435. package/dist/source/meta.js.map +1 -0
  436. package/dist/source/plain-text.d.ts +16 -0
  437. package/dist/source/plain-text.js +86 -0
  438. package/dist/source/plain-text.js.map +1 -0
  439. package/dist/source/toc.d.ts +16 -0
  440. package/dist/source/toc.js +17 -0
  441. package/dist/source/toc.js.map +1 -0
  442. package/dist/source/types.d.ts +16 -0
  443. package/dist/source/types.js +1 -0
  444. package/dist/source/types.js.map +1 -0
  445. package/dist/topology/grouping.d.ts +15 -0
  446. package/dist/topology/grouping.js +18 -0
  447. package/dist/topology/grouping.js.map +1 -0
  448. package/dist/topology/index.d.ts +21 -0
  449. package/dist/topology/index.js +5 -0
  450. package/dist/topology/index.js.map +1 -0
  451. package/dist/topology/resource-segmentation.d.ts +13 -0
  452. package/dist/topology/resource-segmentation.js +111 -0
  453. package/dist/topology/resource-segmentation.js.map +1 -0
  454. package/dist/topology/segment-incision.d.ts +18 -0
  455. package/dist/topology/segment-incision.js +197 -0
  456. package/dist/topology/segment-incision.js.map +1 -0
  457. package/dist/topology/snake-detector.d.ts +13 -0
  458. package/dist/topology/snake-detector.js +520 -0
  459. package/dist/topology/snake-detector.js.map +1 -0
  460. package/dist/topology/snake-graph-builder.d.ts +14 -0
  461. package/dist/topology/snake-graph-builder.js +76 -0
  462. package/dist/topology/snake-graph-builder.js.map +1 -0
  463. package/dist/topology/topology.d.ts +29 -0
  464. package/dist/topology/topology.js +348 -0
  465. package/dist/topology/topology.js.map +1 -0
  466. package/dist/topology/weights.d.ts +10 -0
  467. package/dist/topology/weights.js +84 -0
  468. package/dist/topology/weights.js.map +1 -0
  469. package/dist/types-FVIqiLC9.d.cts +24 -0
  470. package/dist/utils/async-semaphore.d.ts +7 -0
  471. package/dist/utils/async-semaphore.js +40 -0
  472. package/dist/utils/async-semaphore.js.map +1 -0
  473. package/dist/utils/enum.d.ts +5 -0
  474. package/dist/utils/enum.js +18 -0
  475. package/dist/utils/enum.js.map +1 -0
  476. package/dist/utils/hash.d.ts +3 -0
  477. package/dist/utils/hash.js +132 -0
  478. package/dist/utils/hash.js.map +1 -0
  479. package/dist/utils/node-error.d.ts +4 -0
  480. package/dist/utils/node-error.js +59 -0
  481. package/dist/utils/node-error.js.map +1 -0
  482. package/dist/wikg/archive-uri.d.ts +1 -0
  483. package/dist/wikg/archive-uri.js +37 -0
  484. package/dist/wikg/archive-uri.js.map +1 -0
  485. package/dist/wikg/archive.d.ts +28 -0
  486. package/dist/wikg/archive.js +496 -0
  487. package/dist/wikg/archive.js.map +1 -0
  488. package/dist/wikg/index.d.ts +31 -0
  489. package/dist/wikg/index.js +60 -0
  490. package/dist/wikg/index.js.map +1 -0
  491. package/dist/wikg/wikg-coordinator.d.ts +45 -0
  492. package/dist/wikg/wikg-coordinator.js +1687 -0
  493. package/dist/wikg/wikg-coordinator.js.map +1 -0
  494. package/dist/wikg/wiki-graph-archive-file.d.ts +42 -0
  495. package/dist/wikg/wiki-graph-archive-file.js +78 -0
  496. package/dist/wikg/wiki-graph-archive-file.js.map +1 -0
  497. package/dist/wikilink/index.d.ts +10 -0
  498. package/dist/wikilink/index.js +7 -0
  499. package/dist/wikilink/index.js.map +1 -0
  500. package/dist/wikilink/relation-discovery.d.ts +31 -0
  501. package/dist/wikilink/relation-discovery.js +477 -0
  502. package/dist/wikilink/relation-discovery.js.map +1 -0
  503. package/dist/wikilink/types.d.ts +23 -0
  504. package/dist/wikilink/types.js +1 -0
  505. package/dist/wikilink/types.js.map +1 -0
  506. package/dist/wikilink/window.d.ts +7 -0
  507. package/dist/wikilink/window.js +53 -0
  508. package/dist/wikilink/window.js.map +1 -0
  509. package/dist/wikimatch/enrichment.d.ts +10 -0
  510. package/dist/wikimatch/enrichment.js +55 -0
  511. package/dist/wikimatch/enrichment.js.map +1 -0
  512. package/dist/wikimatch/index.d.ts +16 -0
  513. package/dist/wikimatch/index.js +66 -0
  514. package/dist/wikimatch/index.js.map +1 -0
  515. package/dist/wikimatch/option-narrowing.d.ts +17 -0
  516. package/dist/wikimatch/option-narrowing.js +208 -0
  517. package/dist/wikimatch/option-narrowing.js.map +1 -0
  518. package/dist/wikimatch/options.d.ts +14 -0
  519. package/dist/wikimatch/options.js +155 -0
  520. package/dist/wikimatch/options.js.map +1 -0
  521. package/dist/wikimatch/policy-judge.d.ts +17 -0
  522. package/dist/wikimatch/policy-judge.js +430 -0
  523. package/dist/wikimatch/policy-judge.js.map +1 -0
  524. package/dist/wikimatch/range-suppression.d.ts +9 -0
  525. package/dist/wikimatch/range-suppression.js +27 -0
  526. package/dist/wikimatch/range-suppression.js.map +1 -0
  527. package/dist/wikimatch/surface-screening.d.ts +16 -0
  528. package/dist/wikimatch/surface-screening.js +168 -0
  529. package/dist/wikimatch/surface-screening.js.map +1 -0
  530. package/dist/wikimatch/surface-window.d.ts +6 -0
  531. package/dist/wikimatch/surface-window.js +44 -0
  532. package/dist/wikimatch/surface-window.js.map +1 -0
  533. package/dist/wikimatch/types.d.ts +151 -0
  534. package/dist/wikimatch/types.js +1 -0
  535. package/dist/wikimatch/types.js.map +1 -0
  536. package/dist/wikimatch/wikispine.d.ts +43 -0
  537. package/dist/wikimatch/wikispine.js +399 -0
  538. package/dist/wikimatch/wikispine.js.map +1 -0
  539. package/dist/wikimatch/window.d.ts +6 -0
  540. package/dist/wikimatch/window.js +83 -0
  541. package/dist/wikimatch/window.js.map +1 -0
  542. package/dist/wikimatch/words.d.ts +16 -0
  543. package/dist/wikimatch/words.js +66 -0
  544. package/dist/wikimatch/words.js.map +1 -0
  545. package/dist/wikipage/cache.d.ts +18 -0
  546. package/dist/wikipage/cache.js +404 -0
  547. package/dist/wikipage/cache.js.map +1 -0
  548. package/dist/wikipage/fetch-log.d.ts +17 -0
  549. package/dist/wikipage/fetch-log.js +143 -0
  550. package/dist/wikipage/fetch-log.js.map +1 -0
  551. package/dist/wikipage/index.d.ts +14 -0
  552. package/dist/wikipage/index.js +17 -0
  553. package/dist/wikipage/index.js.map +1 -0
  554. package/dist/wikipage/normalizer.d.ts +14 -0
  555. package/dist/wikipage/normalizer.js +147 -0
  556. package/dist/wikipage/normalizer.js.map +1 -0
  557. package/dist/wikipage/rate-limiter.d.ts +13 -0
  558. package/dist/wikipage/rate-limiter.js +84 -0
  559. package/dist/wikipage/rate-limiter.js.map +1 -0
  560. package/dist/wikipage/resolver.d.ts +26 -0
  561. package/dist/wikipage/resolver.js +325 -0
  562. package/dist/wikipage/resolver.js.map +1 -0
  563. package/dist/wikipage/types.d.ts +96 -0
  564. package/dist/wikipage/types.js +1 -0
  565. package/dist/wikipage/types.js.map +1 -0
  566. package/dist/wikipage/wikimedia-client.d.ts +48 -0
  567. package/dist/wikipage/wikimedia-client.js +397 -0
  568. package/dist/wikipage/wikimedia-client.js.map +1 -0
  569. package/dist/worker-BgQ0Xl8T.d.cts +181 -0
  570. package/dist/worker.cjs +5259 -0
  571. package/dist/worker.cjs.map +1 -0
  572. package/dist/worker.d.cts +2 -0
  573. package/dist/worker.d.ts +2 -0
  574. package/dist/worker.js +5 -0
  575. package/dist/worker.js.map +1 -0
  576. package/package.json +78 -0
@@ -0,0 +1,2462 @@
1
+ import { LanguageModel, ModelMessage } from 'ai';
2
+ import { Environment } from 'nunjucks';
3
+ import * as Sqlite3Namespace from 'sqlite3';
4
+ import { z } from 'zod';
5
+ import { a as GcContext, d as GcJobResult } from './types-FVIqiLC9.cjs';
6
+ import { B as BuildJobProgressReporter } from './worker-BgQ0Xl8T.cjs';
7
+ export { A as AddBuildJobOptions, a as BuildJob, b as BuildJobConflictScope, c as BuildJobEvent, d as BuildJobExecutionContext, e as BuildJobListOptions, f as BuildJobProgressCounter, g as BuildJobState, h as BuildJobTarget, i as BuildJobWorkerOptions, j as addBuildJob, k as assertBuildJobInputRevision, l as assertNoActiveBuildJobConflicts, m as assertNoActiveBuildJobs, n as boostBuildJob, o as cancelBuildJob, p as cleanBuildJobs, q as getBuildJob, r as listBuildJobs, s as pauseBuildJob, t as readBuildJobEvents, u as recordBuildJobInputRevision, v as resolveBuildJobId, w as resumeBuildJob, x as runBuildJobWorker, y as runBuildQueueGc, z as updateBuildJobTarget } from './worker-BgQ0Xl8T.cjs';
8
+
9
+ declare enum Language {
10
+ Arabic = "Arabic",
11
+ Danish = "Danish",
12
+ Dutch = "Dutch",
13
+ English = "English",
14
+ Finnish = "Finnish",
15
+ French = "French",
16
+ German = "German",
17
+ Hindi = "Hindi",
18
+ Indonesian = "Indonesian",
19
+ Italian = "Italian",
20
+ Japanese = "Japanese",
21
+ Korean = "Korean",
22
+ Norwegian = "Norwegian",
23
+ Polish = "Polish",
24
+ Portuguese = "Portuguese",
25
+ Russian = "Russian",
26
+ SimplifiedChinese = "Simplified Chinese",
27
+ Spanish = "Spanish",
28
+ Swedish = "Swedish",
29
+ Thai = "Thai",
30
+ TraditionalChinese = "Traditional Chinese",
31
+ Turkish = "Turkish",
32
+ Vietnamese = "Vietnamese"
33
+ }
34
+ declare enum LanguageCode {
35
+ Arabic = "ar",
36
+ Chinese = "zh",
37
+ Danish = "da",
38
+ Dutch = "nl",
39
+ English = "en",
40
+ Finnish = "fi",
41
+ French = "fr",
42
+ German = "de",
43
+ Hindi = "hi",
44
+ Indonesian = "id",
45
+ Italian = "it",
46
+ Japanese = "ja",
47
+ Korean = "ko",
48
+ Norwegian = "no",
49
+ Polish = "pl",
50
+ Portuguese = "pt",
51
+ Russian = "ru",
52
+ Spanish = "es",
53
+ Swedish = "sv",
54
+ Thai = "th",
55
+ Turkish = "tr",
56
+ Vietnamese = "vi"
57
+ }
58
+ declare function getLanguageCode(language: Language): LanguageCode;
59
+ declare function formatLanguageForPrompt(code: LanguageCode): Language;
60
+ declare function normalizeLanguageCode(language: Language | string | null | undefined): LanguageCode | undefined;
61
+ declare function getWikipageLanguageCode(language: Language | string | null | undefined): "en" | "zh" | undefined;
62
+
63
+ declare const WIKI_GRAPH_CONTEXT_VERSION = 1;
64
+ declare const TASK_STATUS_VERSION = 1;
65
+ type WikiGraphTaskType = "source-to-graph" | "source-graph-to-summary";
66
+ interface WikiGraphTaskIdentity {
67
+ readonly normalizedSource: string;
68
+ readonly parameters: unknown;
69
+ readonly taskType: WikiGraphTaskType;
70
+ readonly version?: number;
71
+ }
72
+ interface WikiGraphTaskContextOptions {
73
+ readonly rootDirPath: string;
74
+ }
75
+ interface TaskStatus {
76
+ readonly completedAt?: string | undefined;
77
+ readonly startedAt: string;
78
+ readonly status: "running" | "succeeded";
79
+ readonly version: typeof TASK_STATUS_VERSION;
80
+ }
81
+ declare class WikiGraphTaskContext {
82
+ #private;
83
+ constructor(options: WikiGraphTaskContextOptions);
84
+ createTask(identity: WikiGraphTaskIdentity): WikiGraphTask;
85
+ runTask<T>(identity: WikiGraphTaskIdentity, operation: (task: WikiGraphTask) => Promise<T> | T): Promise<T>;
86
+ }
87
+ declare class WikiGraphTask {
88
+ #private;
89
+ constructor(id: string, path: string);
90
+ get artifactDirPath(): string;
91
+ get id(): string;
92
+ get path(): string;
93
+ readStatus(): Promise<TaskStatus | undefined>;
94
+ run<T>(operation: (task: WikiGraphTask) => Promise<T> | T): Promise<T>;
95
+ remove(): Promise<void>;
96
+ }
97
+ declare function createWikiGraphTaskId(identity: WikiGraphTaskIdentity): string;
98
+
99
+ interface PendingCacheEntry {
100
+ cacheKey: string;
101
+ response: string;
102
+ }
103
+ declare class LLMCache {
104
+ #private;
105
+ constructor(cacheDirPath: string);
106
+ createEntry(cacheKey: string, response: string): PendingCacheEntry;
107
+ read(cacheKey: string): Promise<string | undefined>;
108
+ write(entry: PendingCacheEntry): Promise<void>;
109
+ }
110
+
111
+ type LLMessage = ModelMessage;
112
+ type LLMModel = LanguageModel;
113
+ type TemperatureSetting = number | readonly number[];
114
+ interface SamplingProfile {
115
+ readonly temperature?: TemperatureSetting;
116
+ readonly topP?: TemperatureSetting;
117
+ }
118
+ type SamplingScopeConfig<S extends string> = {
119
+ readonly [scope in S]: SamplingProfile;
120
+ };
121
+ interface LLMRequestOptions<S extends string> {
122
+ readonly signal?: AbortSignal;
123
+ readonly temperature?: TemperatureSetting;
124
+ readonly topP?: TemperatureSetting;
125
+ readonly scope?: S;
126
+ readonly useCache?: boolean;
127
+ readonly retryIndex?: number;
128
+ readonly retryMax?: number;
129
+ }
130
+ type LLMRequestFunction<S extends string> = (messages: readonly LLMessage[], options?: LLMRequestOptions<S>) => Promise<string>;
131
+ type LLMLazyRequestOperation<S extends string, T> = (request: LLMRequestFunction<S>) => Promise<T>;
132
+ type LLMStreamProgressCallback = (event: {
133
+ readonly outputCharacters: number;
134
+ }) => void | Promise<void>;
135
+ interface LLMTokenUsage {
136
+ readonly cacheReadTokens?: number;
137
+ readonly inputTokens?: number;
138
+ readonly outputTokens?: number;
139
+ }
140
+ type LLMTokenUsageCallback = (usage: LLMTokenUsage) => void | Promise<void>;
141
+ interface LLMOptions<S extends string> {
142
+ readonly model: LLMModel;
143
+ readonly dataDirPath: string;
144
+ readonly logDirPath?: string;
145
+ readonly cacheDirPath?: string;
146
+ readonly concurrent?: number;
147
+ readonly stream?: boolean;
148
+ readonly timeout?: number;
149
+ readonly temperature?: TemperatureSetting;
150
+ readonly topP?: TemperatureSetting;
151
+ readonly sampling?: SamplingScopeConfig<S>;
152
+ readonly retryTimes?: number;
153
+ readonly retryIntervalSeconds?: number;
154
+ readonly onStreamProgress?: LLMStreamProgressCallback;
155
+ readonly onTokenUsage?: LLMTokenUsageCallback;
156
+ }
157
+
158
+ interface LLMContextRequestInput<S extends string> {
159
+ messages: readonly LLMessage[];
160
+ options: LLMRequestOptions<S>;
161
+ pendingCacheEntries?: Map<string, PendingCacheEntry>;
162
+ logFiles?: string[];
163
+ }
164
+ type LLMContextRequest<S extends string> = (input: LLMContextRequestInput<S>) => Promise<string>;
165
+ declare class LLMContext<S extends string> {
166
+ #private;
167
+ readonly sessionId: number;
168
+ constructor(sessionId: number, requestFn: LLMContextRequest<S>, cache?: LLMCache);
169
+ request(messages: readonly LLMessage[], options?: LLMRequestOptions<S>): Promise<string>;
170
+ commit(): Promise<void>;
171
+ rollback(): Promise<void>;
172
+ run<T>(operation: (context: LLMContext<S>) => Promise<T>): Promise<T>;
173
+ }
174
+
175
+ declare class LLM<S extends string> {
176
+ #private;
177
+ readonly config: Readonly<{
178
+ concurrent: number;
179
+ provider?: string;
180
+ modelId: string;
181
+ sampling?: SamplingScopeConfig<S>;
182
+ stream: boolean;
183
+ timeout: number;
184
+ temperature: TemperatureSetting;
185
+ topP: TemperatureSetting;
186
+ }>;
187
+ constructor(options: LLMOptions<S>);
188
+ context(): LLMContext<S>;
189
+ withContext<T>(operation: (context: LLMContext<S>) => Promise<T>): Promise<T>;
190
+ request(messages: readonly LLMessage[], options?: LLMRequestOptions<S>): Promise<string>;
191
+ request<T>(operation: LLMLazyRequestOperation<S, T>): Promise<T>;
192
+ loadSystemPrompt(templateName: string, templateContext?: Record<string, unknown>): string;
193
+ }
194
+
195
+ declare class LLMPaymentRequiredError extends Error {
196
+ readonly isRetryable = false;
197
+ readonly statusCode = 402;
198
+ constructor(message?: string, options?: ErrorOptions);
199
+ }
200
+
201
+ declare enum WikiGraphScope {
202
+ EditorCompress = "serial-generation/editor-compress",
203
+ EditorReview = "serial-generation/editor-review",
204
+ EditorReviewGuide = "serial-generation/editor-review-guide",
205
+ ReaderChoice = "serial-generation/reader-choice",
206
+ ReaderExtraction = "serial-generation/reader-extraction"
207
+ }
208
+ declare const WIKI_GRAPH_SCOPES: readonly [WikiGraphScope.EditorCompress, WikiGraphScope.EditorReview, WikiGraphScope.EditorReviewGuide, WikiGraphScope.ReaderChoice, WikiGraphScope.ReaderExtraction];
209
+ declare const WIKI_GRAPH_EDITOR_SCOPES: Readonly<{
210
+ compress: WikiGraphScope.EditorCompress;
211
+ review: WikiGraphScope.EditorReview;
212
+ reviewGuide: WikiGraphScope.EditorReviewGuide;
213
+ }>;
214
+ declare const WIKI_GRAPH_READER_SCOPES: Readonly<{
215
+ choice: WikiGraphScope.ReaderChoice;
216
+ extraction: WikiGraphScope.ReaderExtraction;
217
+ }>;
218
+
219
+ declare function withLoggingContext<T>(input: {
220
+ readonly operation: string;
221
+ readonly logDirPath?: string;
222
+ readonly verbose?: boolean;
223
+ }, operation: () => Promise<T>): Promise<T>;
224
+
225
+ declare const CLI_PRIMARY_COMMAND = "wg";
226
+ declare const CLI_FULL_COMMAND = "wikigraph";
227
+
228
+ declare function resolveDataDirPath(): string;
229
+
230
+ declare function createEnv(dirPath: string, options?: {
231
+ readonly autoescape?: boolean;
232
+ readonly trimBlocks?: boolean;
233
+ }): Environment;
234
+
235
+ declare function resolveWikiGraphHomeDirectoryPath(): string;
236
+ declare function resolveWikiGraphCoreDatabasePath(): string;
237
+
238
+ type WikiGraphTempCategory = "archive-open" | "archive-write" | "cli-output" | "sdpub-upgrade" | "stdin-create" | "url-create";
239
+ declare function resolveWikiGraphStateRootPath(): string;
240
+ declare function createWikiGraphTempDirectory(category: WikiGraphTempCategory): Promise<string>;
241
+
242
+ type SqliteDatabase = Sqlite3Namespace.Database;
243
+ type SqlBindValue = Buffer | Uint8Array | number | string | null;
244
+ type SqlBindParams = readonly SqlBindValue[];
245
+ type SqlRowValue = SqlBindValue;
246
+ type SqlRow = Record<string, SqlRowValue>;
247
+ declare class Database {
248
+ #private;
249
+ constructor(database: SqliteDatabase, options?: {
250
+ readonly onWrite?: () => void;
251
+ });
252
+ static open(databasePath: string, schemaSql?: string, options?: {
253
+ readonly onWrite?: () => void;
254
+ readonly readonly?: boolean;
255
+ }): Promise<Database>;
256
+ static initialize(databasePath: string, schemaSql: string): Promise<void>;
257
+ queryAll<T>(sql: string, params: SqlBindParams | undefined, mapRow: (row: SqlRow) => T): Promise<T[]>;
258
+ queryOne<T>(sql: string, params: SqlBindParams | undefined, mapRow: (row: SqlRow) => T): Promise<T | undefined>;
259
+ run(sql: string, params?: SqlBindParams): Promise<void>;
260
+ transaction<T>(operation: () => Promise<T> | T): Promise<T>;
261
+ flush(): Promise<void>;
262
+ close(): Promise<void>;
263
+ getLastInsertRowId(): Promise<number>;
264
+ }
265
+
266
+ declare function openSharedStateDatabase(databasePath: string, schemaSql: string, options?: {
267
+ readonly readonly?: boolean;
268
+ }): Promise<Database>;
269
+ declare function ensureSharedStateDatabaseInitialized(databasePath: string, schemaSql: string): Promise<void>;
270
+
271
+ declare enum ChunkRetention {
272
+ Verbatim = "verbatim",
273
+ Detailed = "detailed",
274
+ Focused = "focused",
275
+ Relevant = "relevant"
276
+ }
277
+ declare const isChunkRetention: (value: string) => value is ChunkRetention;
278
+ declare const expectChunkRetention: (value: string) => ChunkRetention;
279
+ declare enum ChunkImportance {
280
+ Critical = "critical",
281
+ Important = "important",
282
+ Helpful = "helpful"
283
+ }
284
+ declare const isChunkImportance: (value: string) => value is ChunkImportance;
285
+ declare const expectChunkImportance: (value: string) => ChunkImportance;
286
+ type SentenceId = readonly [chapterId: number, sentenceIndex: number];
287
+ interface SentenceRecord {
288
+ readonly text: string;
289
+ readonly wordsCount: number;
290
+ }
291
+ interface FragmentRecord {
292
+ readonly serialId: number;
293
+ readonly fragmentId: number;
294
+ readonly summary: string;
295
+ readonly sentences: readonly SentenceRecord[];
296
+ }
297
+ interface SerialRecord {
298
+ readonly documentOrder: number;
299
+ readonly knowledgeGraphReady: boolean;
300
+ readonly knowledgeGraphParameterHash?: string;
301
+ readonly id: number;
302
+ readonly revision: number;
303
+ readonly topologyParameterHash?: string;
304
+ readonly topologyReady: boolean;
305
+ }
306
+ interface GraphBuildParameterRecord {
307
+ readonly createdAt: string;
308
+ readonly hash: string;
309
+ readonly language?: string;
310
+ readonly prompt: string;
311
+ }
312
+ interface ChunkRecord {
313
+ readonly id: number;
314
+ readonly generation: number;
315
+ readonly sentenceId: SentenceId;
316
+ readonly label: string;
317
+ readonly content: string;
318
+ readonly sentenceIds: readonly SentenceId[];
319
+ readonly retention?: ChunkRetention;
320
+ readonly importance?: ChunkImportance;
321
+ readonly wordsCount: number;
322
+ readonly weight: number;
323
+ }
324
+ type CreateChunkRecord = Omit<ChunkRecord, "id">;
325
+ interface ReadingEdgeRecord {
326
+ readonly fromId: number;
327
+ readonly toId: number;
328
+ readonly strength?: string;
329
+ readonly weight: number;
330
+ }
331
+ interface MentionRecord {
332
+ readonly id: string;
333
+ readonly chapterId: number;
334
+ readonly fragmentId?: number;
335
+ readonly sentenceIndex?: number;
336
+ readonly rangeStart: number;
337
+ readonly rangeEnd: number;
338
+ readonly surface: string;
339
+ readonly qid: string;
340
+ readonly confidence?: number;
341
+ readonly note?: string;
342
+ }
343
+ interface MentionLinkRecord {
344
+ readonly id: string;
345
+ readonly sourceMentionId: string;
346
+ readonly targetMentionId: string;
347
+ readonly predicate: string;
348
+ readonly evidenceSentenceIds: readonly SentenceId[];
349
+ readonly confidence?: number;
350
+ readonly note?: string;
351
+ }
352
+ interface SnakeRecord {
353
+ readonly id: number;
354
+ readonly serialId: number;
355
+ readonly groupId: number;
356
+ readonly localSnakeId: number;
357
+ readonly size: number;
358
+ readonly firstLabel: string;
359
+ readonly lastLabel: string;
360
+ readonly wordsCount: number;
361
+ readonly weight: number;
362
+ }
363
+ interface CreateSnakeRecord {
364
+ readonly serialId: number;
365
+ readonly groupId: number;
366
+ readonly localSnakeId: number;
367
+ readonly size: number;
368
+ readonly firstLabel: string;
369
+ readonly lastLabel: string;
370
+ readonly wordsCount?: number;
371
+ readonly weight?: number;
372
+ }
373
+ interface SnakeChunkRecord {
374
+ readonly snakeId: number;
375
+ readonly chunkId: number;
376
+ readonly position: number;
377
+ }
378
+ interface SnakeEdgeRecord {
379
+ readonly fromSnakeId: number;
380
+ readonly toSnakeId: number;
381
+ readonly weight: number;
382
+ }
383
+ interface SentenceGroupRecord {
384
+ readonly serialId: number;
385
+ readonly groupId: number;
386
+ readonly startSentenceIndex: number;
387
+ readonly endSentenceIndex: number;
388
+ readonly fragmentId?: number;
389
+ }
390
+ declare const enum ObjectMetadataKind {
391
+ Archive = 1,
392
+ Chapter = 2,
393
+ Chunk = 3,
394
+ Entity = 4,
395
+ Triple = 5,
396
+ Object = 6
397
+ }
398
+ interface ObjectMetadataTarget {
399
+ readonly kind: ObjectMetadataKind;
400
+ readonly objectPath: string;
401
+ readonly chapterId?: number;
402
+ readonly chunkId?: number;
403
+ readonly entityQid?: string;
404
+ readonly tripleSubjectQid?: string;
405
+ readonly triplePredicate?: string;
406
+ readonly tripleObjectQid?: string;
407
+ }
408
+
409
+ declare const TEXT_STREAM_KIND: {
410
+ readonly source: 1;
411
+ readonly summary: 2;
412
+ };
413
+ type TextStreamName = keyof typeof TEXT_STREAM_KIND;
414
+ interface TextStreamFileAccess {
415
+ deleteTree(path: string): Promise<void>;
416
+ ensureDirectory(path: string): Promise<void>;
417
+ listFiles(path: string): Promise<readonly string[]>;
418
+ readFile(path: string): Promise<Uint8Array | undefined>;
419
+ writeFile(path: string, content: string | Uint8Array, options: {
420
+ readonly overwrite?: boolean;
421
+ }): Promise<void>;
422
+ }
423
+ interface TextStreamSentenceSegmenter {
424
+ pipe(stream: Iterable<string>): AsyncIterable<{
425
+ readonly offset: number;
426
+ readonly text: string;
427
+ readonly wordsCount: number;
428
+ }>;
429
+ }
430
+ interface WriteTextStreamOptions {
431
+ readonly segmenter?: TextStreamSentenceSegmenter;
432
+ }
433
+ interface ReadonlyTextStreams {
434
+ getSentence(sentenceId: SentenceId): Promise<string>;
435
+ getSerial(serialId: number): ReadonlySerialTextStream;
436
+ getSummarySerial(serialId: number): ReadonlySerialTextStream;
437
+ }
438
+ interface ReadonlySerialTextStream {
439
+ getFragment(fragmentId: number): Promise<FragmentRecord>;
440
+ getSentence?(sentenceIndex: number): Promise<SentenceRecord>;
441
+ listSentencesInRange?(startSentenceIndex: number, endSentenceIndex: number): Promise<readonly SentenceRecord[]>;
442
+ listFragmentIds(): Promise<readonly number[]>;
443
+ listSentences?(): Promise<readonly SentenceRecord[]>;
444
+ readText?(): Promise<string | undefined>;
445
+ readTextInRange?(startSentenceIndex: number, endSentenceIndex: number): Promise<string | undefined>;
446
+ readonly path: string;
447
+ readonly serialId: number;
448
+ }
449
+ declare class TextStreams implements ReadonlyTextStreams {
450
+ #private;
451
+ constructor(documentPath: string, database: Database, fileAccess?: TextStreamFileAccess);
452
+ ensureCreated(): Promise<void>;
453
+ getSentence(sentenceId: SentenceId): Promise<string>;
454
+ getSerial(serialId: number): SerialTextStream;
455
+ getSummarySerial(serialId: number): SerialTextStream;
456
+ }
457
+ declare class SerialTextStream implements ReadonlySerialTextStream {
458
+ #private;
459
+ constructor(documentPath: string, database: Database, fileAccess: TextStreamFileAccess, stream: TextStreamName, serialId: number);
460
+ createDraft(): Promise<TextStreamDraft>;
461
+ getFragment(fragmentId: number): Promise<FragmentRecord>;
462
+ getSentence(sentenceIndex: number): Promise<SentenceRecord>;
463
+ listFragmentIds(): Promise<readonly number[]>;
464
+ listSentences(): Promise<readonly SentenceRecord[]>;
465
+ listSentencesInRange(startSentenceIndex: number, endSentenceIndex: number): Promise<readonly SentenceRecord[]>;
466
+ readTextInRange(startSentenceIndex: number, endSentenceIndex: number): Promise<string | undefined>;
467
+ readText(): Promise<string | undefined>;
468
+ writeTextStream(text: string, options?: WriteTextStreamOptions): Promise<void>;
469
+ delete(): Promise<void>;
470
+ get path(): string;
471
+ get serialId(): number;
472
+ }
473
+ declare class TextStreamDraft {
474
+ #private;
475
+ constructor(serialId: number, startSentenceIndex: number, callbacks: {
476
+ readonly discard: () => void;
477
+ readonly finalize: (startSentenceIndex: number, summary: string, sentences: readonly SentenceRecord[]) => Promise<FragmentRecord | undefined>;
478
+ });
479
+ addSentence(text: string, wordsCount: number, location?: {
480
+ readonly byteOffset: number;
481
+ readonly byteLength: number;
482
+ }): SentenceId;
483
+ commit(): Promise<FragmentRecord | undefined>;
484
+ commitWithText(text: string): Promise<FragmentRecord | undefined>;
485
+ discard(): void;
486
+ setSummary(summary: string): void;
487
+ get fragmentId(): number;
488
+ }
489
+
490
+ interface FragmentWriter {
491
+ write(path: string, content: string): Promise<void>;
492
+ }
493
+ interface FragmentFileAccess {
494
+ ensureDirectory(path: string): Promise<void>;
495
+ listFileContents?(path: string): Promise<ReadonlyMap<string, Uint8Array>>;
496
+ listFiles(path: string): Promise<readonly string[]>;
497
+ readFile(path: string): Promise<Uint8Array | undefined>;
498
+ }
499
+ interface ReadonlyFragments {
500
+ getSerial(serialId: number): ReadonlySerialFragments;
501
+ getSummarySerial(serialId: number): ReadonlySerialFragments;
502
+ getSentence(sentenceId: SentenceId): Promise<string>;
503
+ getSummary(serialId: number, fragmentId: number): Promise<string>;
504
+ getWordsCount(serialId: number, fragmentId: number): Promise<number>;
505
+ readonly path: string;
506
+ }
507
+ interface TextStreamWriteOptions {
508
+ readonly maxWordsCount?: number;
509
+ }
510
+ interface ReadonlySerialFragments {
511
+ getFragment(fragmentId: number): Promise<FragmentRecord>;
512
+ listFragmentIds(): Promise<readonly number[]>;
513
+ readonly serialId: number;
514
+ readonly path: string;
515
+ }
516
+ declare class Fragments implements ReadonlyFragments {
517
+ #private;
518
+ constructor(documentPath: string, writer?: FragmentWriter, fileAccess?: FragmentFileAccess);
519
+ ensureCreated(): Promise<void>;
520
+ getSerial(serialId: number): SerialFragments;
521
+ getSummarySerial(serialId: number): SerialFragments;
522
+ getSentence(sentenceId: SentenceId): Promise<string>;
523
+ getSummary(serialId: number, fragmentId: number): Promise<string>;
524
+ getWordsCount(serialId: number, fragmentId: number): Promise<number>;
525
+ get path(): string;
526
+ }
527
+ declare class SerialFragments implements ReadonlySerialFragments {
528
+ #private;
529
+ constructor(documentPath: string, serialId: number, rootDirectoryName?: string, writer?: FragmentWriter, fileAccess?: FragmentFileAccess);
530
+ createDraft(): Promise<FragmentDraft>;
531
+ getFragment(fragmentId: number): Promise<FragmentRecord>;
532
+ listFragmentIds(): Promise<readonly number[]>;
533
+ writeTextStream(text: string, options?: TextStreamWriteOptions): Promise<void>;
534
+ get serialId(): number;
535
+ get path(): string;
536
+ }
537
+ declare class FragmentDraft {
538
+ #private;
539
+ constructor(serialId: number, fragmentId: number, startSentenceIndex: number, callbacks: {
540
+ readonly discard: () => void;
541
+ readonly finalize: (fragmentId: number, startSentenceIndex: number, summary: string, sentences: readonly SentenceRecord[]) => Promise<FragmentRecord | undefined>;
542
+ });
543
+ addSentence(text: string, wordsCount: number): SentenceId;
544
+ commit(): Promise<FragmentRecord | undefined>;
545
+ discard(): void;
546
+ setSummary(summary: string): void;
547
+ get fragmentId(): number;
548
+ }
549
+
550
+ declare const bookMetaSchema: z.ZodObject<{
551
+ version: z.ZodLiteral<1>;
552
+ sourceFormat: z.ZodEnum<{
553
+ epub: "epub";
554
+ pdf: "pdf";
555
+ txt: "txt";
556
+ markdown: "markdown";
557
+ }>;
558
+ title: z.ZodNullable<z.ZodString>;
559
+ authors: z.ZodArray<z.ZodString>;
560
+ language: z.ZodNullable<z.ZodString>;
561
+ identifier: z.ZodNullable<z.ZodString>;
562
+ publisher: z.ZodNullable<z.ZodString>;
563
+ publishedAt: z.ZodNullable<z.ZodString>;
564
+ description: z.ZodNullable<z.ZodString>;
565
+ }, z.core.$strip>;
566
+ type BookMeta = z.infer<typeof bookMetaSchema>;
567
+
568
+ declare const TOC_FILE_VERSION = 1;
569
+ interface TocItem {
570
+ readonly title?: string | null | undefined;
571
+ readonly serialId?: number | undefined;
572
+ readonly children: readonly TocItem[];
573
+ }
574
+ declare const tocFileSchema: z.ZodObject<{
575
+ version: z.ZodLiteral<1>;
576
+ items: z.ZodArray<z.ZodType<TocItem, unknown, z.core.$ZodTypeInternals<TocItem, unknown>>>;
577
+ }, z.core.$strip>;
578
+ type TocFile = z.infer<typeof tocFileSchema>;
579
+
580
+ interface SourceAsset {
581
+ readonly path: string;
582
+ readonly mediaType: string;
583
+ readonly data: Uint8Array;
584
+ }
585
+
586
+ interface ReadonlySerialStore {
587
+ getById(serialId: number): Promise<SerialRecord | undefined>;
588
+ getRevision(serialId: number): Promise<number>;
589
+ getRevisions(serialIds: readonly number[]): Promise<ReadonlyMap<number, number>>;
590
+ getMaxId(): Promise<number>;
591
+ getChaptersRevision(): Promise<number>;
592
+ listIds(): Promise<number[]>;
593
+ listDocumentOrders(): Promise<ReadonlyMap<number, number>>;
594
+ }
595
+ interface ReadonlyGraphBuildParameterStore {
596
+ getByHash(hash: string): Promise<GraphBuildParameterRecord | undefined>;
597
+ }
598
+ interface ReadonlyChunkStore {
599
+ countAll(): Promise<number>;
600
+ getById(chunkId: number): Promise<ChunkRecord | undefined>;
601
+ listAll(): Promise<ChunkRecord[]>;
602
+ listBySentenceStartIndexes(serialId: number, sentenceStartIndexes: readonly number[]): Promise<ChunkRecord[]>;
603
+ listBySentenceRange(serialId: number, startSentenceIndex: number, endSentenceIndex: number): Promise<ChunkRecord[]>;
604
+ listBySerial(serialId: number): Promise<ChunkRecord[]>;
605
+ getMaxId(): Promise<number>;
606
+ listFragmentPairs(): Promise<ReadonlyArray<readonly [number, number]>>;
607
+ }
608
+ interface ReadonlyReadingEdgeStore {
609
+ countAll(): Promise<number>;
610
+ listAll(): Promise<ReadingEdgeRecord[]>;
611
+ listBySerial(serialId: number): Promise<ReadingEdgeRecord[]>;
612
+ listIncoming(chunkId: number): Promise<ReadingEdgeRecord[]>;
613
+ listOutgoing(chunkId: number): Promise<ReadingEdgeRecord[]>;
614
+ }
615
+ interface ReadonlyMentionStore {
616
+ getById(mentionId: string): Promise<MentionRecord | undefined>;
617
+ listAll(): Promise<MentionRecord[]>;
618
+ listBySurfaceTerms(terms: readonly string[]): Promise<MentionRecord[]>;
619
+ listBySurfaces(surfaces: readonly string[]): Promise<MentionRecord[]>;
620
+ listByQid(qid: string): Promise<MentionRecord[]>;
621
+ listByChapter(chapterId: number): Promise<MentionRecord[]>;
622
+ }
623
+ interface ReadonlyMentionLinkStore {
624
+ getById(linkId: string): Promise<MentionLinkRecord | undefined>;
625
+ listByTriple(input: {
626
+ readonly objectQid: string;
627
+ readonly predicate: string;
628
+ readonly subjectQid: string;
629
+ }): Promise<MentionLinkRecord[]>;
630
+ listByChapter(chapterId: number): Promise<MentionLinkRecord[]>;
631
+ }
632
+ interface ReadonlySnakeStore {
633
+ getById(snakeId: number): Promise<SnakeRecord | undefined>;
634
+ listIdsByGroup(serialId: number, groupId: number): Promise<number[]>;
635
+ listBySerial(serialId: number): Promise<SnakeRecord[]>;
636
+ }
637
+ interface ReadonlySnakeChunkStore {
638
+ listChunkIds(snakeId: number): Promise<number[]>;
639
+ listBySnake(snakeId: number): Promise<SnakeChunkRecord[]>;
640
+ }
641
+ interface ReadonlySnakeEdgeStore {
642
+ listIncoming(snakeId: number): Promise<SnakeEdgeRecord[]>;
643
+ listOutgoing(snakeId: number): Promise<SnakeEdgeRecord[]>;
644
+ listWithin(snakeIds: readonly number[]): Promise<SnakeEdgeRecord[]>;
645
+ listBySerial(serialId: number): Promise<SnakeEdgeRecord[]>;
646
+ }
647
+ interface ReadonlyFragmentGroupStore {
648
+ listBySerial(serialId: number): Promise<SentenceGroupRecord[]>;
649
+ listSerialIds(): Promise<number[]>;
650
+ listGroupIdsForSerial(serialId: number): Promise<number[]>;
651
+ }
652
+ interface ReadonlyObjectMetadataStore {
653
+ getMap(objectPath: string): Promise<Readonly<Record<string, unknown>>>;
654
+ }
655
+ declare class ObjectMetadataStore implements ReadonlyObjectMetadataStore {
656
+ #private;
657
+ constructor(database: Database);
658
+ getMap(objectPath: string): Promise<Readonly<Record<string, unknown>>>;
659
+ replaceMap(target: ObjectMetadataTarget, map: Readonly<Record<string, unknown>>): Promise<void>;
660
+ put(target: ObjectMetadataTarget, key: string, value: unknown): Promise<void>;
661
+ deleteKey(objectPath: string, key: string): Promise<void>;
662
+ clear(objectPath: string): Promise<void>;
663
+ deleteChapterSubtree(chapterId: number): Promise<void>;
664
+ deleteDeletedChunks(): Promise<void>;
665
+ deleteDeletedEntitiesAndTriples(): Promise<void>;
666
+ }
667
+ declare class SerialStore implements ReadonlySerialStore {
668
+ #private;
669
+ constructor(database: Database);
670
+ create(): Promise<number>;
671
+ createWithId(serialId: number): Promise<void>;
672
+ ensure(serialId: number): Promise<void>;
673
+ getById(serialId: number): Promise<SerialRecord | undefined>;
674
+ getRevision(serialId: number): Promise<number>;
675
+ getRevisions(serialIds: readonly number[]): Promise<ReadonlyMap<number, number>>;
676
+ bumpRevision(serialId: number): Promise<void>;
677
+ bumpChaptersRevision(): Promise<void>;
678
+ getChaptersRevision(): Promise<number>;
679
+ getMaxId(): Promise<number>;
680
+ setTopologyReady(serialId: number, ready?: boolean, parameterHash?: string): Promise<void>;
681
+ setKnowledgeGraphReady(serialId: number, ready?: boolean, parameterHash?: string): Promise<void>;
682
+ listIds(): Promise<number[]>;
683
+ listDocumentOrders(): Promise<ReadonlyMap<number, number>>;
684
+ setDocumentOrders(entries: readonly {
685
+ readonly documentOrder: number;
686
+ readonly serialId: number;
687
+ }[]): Promise<void>;
688
+ }
689
+ declare class GraphBuildParameterStore implements ReadonlyGraphBuildParameterStore {
690
+ #private;
691
+ constructor(database: Database);
692
+ save(input: {
693
+ readonly language?: string;
694
+ readonly prompt: string;
695
+ }): Promise<GraphBuildParameterRecord>;
696
+ getByHash(hash: string): Promise<GraphBuildParameterRecord | undefined>;
697
+ deleteUnreferenced(): Promise<void>;
698
+ }
699
+ declare class ChunkStore implements ReadonlyChunkStore {
700
+ #private;
701
+ constructor(database: Database);
702
+ countAll(): Promise<number>;
703
+ create(record: CreateChunkRecord): Promise<ChunkRecord>;
704
+ save(record: ChunkRecord): Promise<void>;
705
+ getById(chunkId: number): Promise<ChunkRecord | undefined>;
706
+ listAll(): Promise<ChunkRecord[]>;
707
+ listBySentenceStartIndexes(serialId: number, sentenceStartIndexes: readonly number[]): Promise<ChunkRecord[]>;
708
+ listBySentenceRange(serialId: number, startSentenceIndex: number, endSentenceIndex: number): Promise<ChunkRecord[]>;
709
+ listBySerial(serialId: number): Promise<ChunkRecord[]>;
710
+ getMaxId(): Promise<number>;
711
+ listFragmentPairs(): Promise<ReadonlyArray<readonly [number, number]>>;
712
+ }
713
+ declare class ReadingEdgeStore implements ReadonlyReadingEdgeStore {
714
+ #private;
715
+ constructor(database: Database);
716
+ countAll(): Promise<number>;
717
+ save(record: ReadingEdgeRecord): Promise<void>;
718
+ listAll(): Promise<ReadingEdgeRecord[]>;
719
+ listBySerial(serialId: number): Promise<ReadingEdgeRecord[]>;
720
+ listIncoming(chunkId: number): Promise<ReadingEdgeRecord[]>;
721
+ listOutgoing(chunkId: number): Promise<ReadingEdgeRecord[]>;
722
+ }
723
+ declare class SnakeStore implements ReadonlySnakeStore {
724
+ #private;
725
+ constructor(database: Database);
726
+ create(record: CreateSnakeRecord): Promise<number>;
727
+ getById(snakeId: number): Promise<SnakeRecord | undefined>;
728
+ listIdsByGroup(serialId: number, groupId: number): Promise<number[]>;
729
+ listBySerial(serialId: number): Promise<SnakeRecord[]>;
730
+ }
731
+ declare class MentionStore implements ReadonlyMentionStore {
732
+ #private;
733
+ constructor(database: Database);
734
+ save(record: MentionRecord): Promise<void>;
735
+ saveMany(records: readonly MentionRecord[]): Promise<void>;
736
+ getById(mentionId: string): Promise<MentionRecord | undefined>;
737
+ listAll(): Promise<MentionRecord[]>;
738
+ listByQid(qid: string): Promise<MentionRecord[]>;
739
+ listBySurfaces(surfaces: readonly string[]): Promise<MentionRecord[]>;
740
+ listBySurfaceTerms(terms: readonly string[]): Promise<MentionRecord[]>;
741
+ listByChapter(chapterId: number): Promise<MentionRecord[]>;
742
+ deleteByChapter(chapterId: number): Promise<void>;
743
+ }
744
+ declare class MentionLinkStore implements ReadonlyMentionLinkStore {
745
+ #private;
746
+ constructor(database: Database);
747
+ save(record: MentionLinkRecord): Promise<void>;
748
+ saveMany(records: readonly MentionLinkRecord[]): Promise<void>;
749
+ getById(linkId: string): Promise<MentionLinkRecord | undefined>;
750
+ listByTriple(input: {
751
+ readonly objectQid: string;
752
+ readonly predicate: string;
753
+ readonly subjectQid: string;
754
+ }): Promise<MentionLinkRecord[]>;
755
+ listByChapter(chapterId: number): Promise<MentionLinkRecord[]>;
756
+ deleteByChapter(chapterId: number): Promise<void>;
757
+ }
758
+ declare class SnakeChunkStore implements ReadonlySnakeChunkStore {
759
+ #private;
760
+ constructor(database: Database);
761
+ save(record: SnakeChunkRecord): Promise<void>;
762
+ listChunkIds(snakeId: number): Promise<number[]>;
763
+ listBySnake(snakeId: number): Promise<SnakeChunkRecord[]>;
764
+ }
765
+ declare class SnakeEdgeStore implements ReadonlySnakeEdgeStore {
766
+ #private;
767
+ constructor(database: Database);
768
+ save(record: SnakeEdgeRecord): Promise<void>;
769
+ listIncoming(snakeId: number): Promise<SnakeEdgeRecord[]>;
770
+ listOutgoing(snakeId: number): Promise<SnakeEdgeRecord[]>;
771
+ listWithin(snakeIds: readonly number[]): Promise<SnakeEdgeRecord[]>;
772
+ listBySerial(serialId: number): Promise<SnakeEdgeRecord[]>;
773
+ }
774
+ declare class FragmentGroupStore implements ReadonlyFragmentGroupStore {
775
+ #private;
776
+ constructor(database: Database);
777
+ save(record: SentenceGroupRecord): Promise<void>;
778
+ saveMany(records: readonly SentenceGroupRecord[]): Promise<void>;
779
+ listBySerial(serialId: number): Promise<SentenceGroupRecord[]>;
780
+ listSerialIds(): Promise<number[]>;
781
+ listGroupIdsForSerial(serialId: number): Promise<number[]>;
782
+ }
783
+
784
+ interface DocumentFileStore {
785
+ close(): Promise<void>;
786
+ deleteFile(path: string): Promise<void>;
787
+ deleteTree(path: string): Promise<void>;
788
+ ensureDirectory(path: string): Promise<void>;
789
+ initializeDatabaseSchema(): boolean;
790
+ markDatabaseDirty?(): void;
791
+ markSearchIndexDatabaseDirty?(): void;
792
+ openDatabaseReadonly(): boolean;
793
+ listFileContents?(path: string): Promise<ReadonlyMap<string, Uint8Array>>;
794
+ listFiles(path: string): Promise<readonly string[]>;
795
+ readFile(path: string): Promise<Uint8Array | undefined>;
796
+ resolveDatabasePath(documentPath: string): Promise<string>;
797
+ resolveSearchIndexDatabasePath?(documentPath: string): Promise<string>;
798
+ writeFile(path: string, content: string | Uint8Array, options: {
799
+ readonly overwrite?: boolean;
800
+ }): Promise<void>;
801
+ }
802
+ interface ReadonlyDocument {
803
+ readonly chunks: ReadonlyChunkStore;
804
+ readonly fragmentGroups: ReadonlyFragmentGroupStore;
805
+ readonly graphBuildParameters: ReadonlyGraphBuildParameterStore;
806
+ readonly readingEdges: ReadonlyReadingEdgeStore;
807
+ readonly mentionLinks: ReadonlyMentionLinkStore;
808
+ readonly mentions: ReadonlyMentionStore;
809
+ readonly metadata: ReadonlyObjectMetadataStore;
810
+ readonly serials: ReadonlySerialStore;
811
+ readonly snakeChunks: ReadonlySnakeChunkStore;
812
+ readonly snakeEdges: ReadonlySnakeEdgeStore;
813
+ readonly snakes: ReadonlySnakeStore;
814
+ getSentence(sentenceId: SentenceId): Promise<string>;
815
+ getSerialFragments(serialId: number): ReadonlySerialTextStream;
816
+ getSummaryFragments(serialId: number): ReadonlySerialTextStream;
817
+ openSession<T>(operation: (document: ReadonlyDocument) => Promise<T> | T): Promise<T>;
818
+ readDatabase<T>(operation: (database: Database) => Promise<T> | T): Promise<T>;
819
+ readSearchIndexDatabase<T>(operation: (database: Database) => Promise<T> | T): Promise<T>;
820
+ readBookMeta(): Promise<BookMeta | undefined>;
821
+ readCover(): Promise<SourceAsset | undefined>;
822
+ readSummary(serialId: number): Promise<string | undefined>;
823
+ readToc(): Promise<TocFile | undefined>;
824
+ release(): Promise<void>;
825
+ }
826
+ interface DocumentContext {
827
+ complete(): void;
828
+ dispose(): Promise<void>;
829
+ ownSerial(serialId: number): void;
830
+ run<T>(operation: () => Promise<T> | T): Promise<T>;
831
+ }
832
+ interface Document extends ReadonlyDocument {
833
+ readonly chunks: ChunkStore;
834
+ readonly fragmentGroups: FragmentGroupStore;
835
+ readonly graphBuildParameters: GraphBuildParameterStore;
836
+ readonly readingEdges: ReadingEdgeStore;
837
+ readonly mentionLinks: MentionLinkStore;
838
+ readonly mentions: MentionStore;
839
+ readonly metadata: ObjectMetadataStore;
840
+ readonly serials: SerialStore;
841
+ readonly snakeChunks: SnakeChunkStore;
842
+ readonly snakeEdges: SnakeEdgeStore;
843
+ readonly snakes: SnakeStore;
844
+ createContext(): DocumentContext;
845
+ getSerialFragments(serialId: number): SerialTextStream;
846
+ getSummaryFragments(serialId: number): SerialTextStream;
847
+ createSerial(): Promise<number>;
848
+ clearSerialGraph(serialId: number): Promise<void>;
849
+ clearSerialSource(serialId: number): Promise<void>;
850
+ deleteSerial(serialId: number): Promise<void>;
851
+ deleteSearchIndexDatabase(): Promise<void>;
852
+ deleteSummary(serialId: number): Promise<void>;
853
+ flush(): Promise<void>;
854
+ openSession<T>(operation: (document: Document) => Promise<T> | T): Promise<T>;
855
+ peekNextSerialId(): Promise<number>;
856
+ replaceBookMeta(meta: BookMeta): Promise<void>;
857
+ replaceToc(toc: TocFile): Promise<void>;
858
+ writeBookMeta(meta: BookMeta): Promise<void>;
859
+ writeCover(cover: SourceAsset): Promise<void>;
860
+ writeSummary(serialId: number, summary: string): Promise<void>;
861
+ writeToc(toc: TocFile): Promise<void>;
862
+ writeSearchIndexDatabase<T>(operation: (database: Database) => Promise<T> | T): Promise<T>;
863
+ }
864
+ declare class DirectoryDocument implements Document {
865
+ #private;
866
+ readonly chunks: ChunkStore;
867
+ readonly fragmentGroups: FragmentGroupStore;
868
+ readonly graphBuildParameters: GraphBuildParameterStore;
869
+ readonly readingEdges: ReadingEdgeStore;
870
+ readonly mentionLinks: MentionLinkStore;
871
+ readonly mentions: MentionStore;
872
+ readonly metadata: ObjectMetadataStore;
873
+ readonly path: string;
874
+ readonly serials: SerialStore;
875
+ readonly snakeChunks: SnakeChunkStore;
876
+ readonly snakeEdges: SnakeEdgeStore;
877
+ readonly snakes: SnakeStore;
878
+ constructor(database: Database, textStreams: TextStreams, path: string, fileStore?: DocumentFileStore);
879
+ static open(documentPath: string, options?: {
880
+ readonly fileStore?: DocumentFileStore;
881
+ }): Promise<DirectoryDocument>;
882
+ static openSession<T>(documentPath: string, operation: (document: DirectoryDocument) => Promise<T> | T): Promise<T>;
883
+ getSerialFragments(serialId: number): SerialTextStream;
884
+ getSummaryFragments(serialId: number): SerialTextStream;
885
+ createContext(): DocumentContext;
886
+ createSerial(): Promise<number>;
887
+ clearSerialGraph(serialId: number): Promise<void>;
888
+ clearSerialSource(serialId: number): Promise<void>;
889
+ deleteSerial(serialId: number): Promise<void>;
890
+ deleteSummary(serialId: number): Promise<void>;
891
+ getSentence(sentenceId: SentenceId): Promise<string>;
892
+ openSession<T>(operation: (document: Document) => Promise<T> | T): Promise<T>;
893
+ readDatabase<T>(operation: (database: Database) => Promise<T> | T): Promise<T>;
894
+ readSearchIndexDatabase<T>(operation: (database: Database) => Promise<T> | T): Promise<T>;
895
+ writeSearchIndexDatabase<T>(operation: (database: Database) => Promise<T> | T): Promise<T>;
896
+ deleteSearchIndexDatabase(): Promise<void>;
897
+ peekNextSerialId(): Promise<number>;
898
+ readBookMeta(): Promise<BookMeta | undefined>;
899
+ readCover(): Promise<SourceAsset | undefined>;
900
+ readSummary(serialId: number): Promise<string | undefined>;
901
+ readToc(): Promise<TocFile | undefined>;
902
+ writeBookMeta(meta: BookMeta): Promise<void>;
903
+ replaceBookMeta(meta: BookMeta): Promise<void>;
904
+ writeCover(cover: SourceAsset): Promise<void>;
905
+ writeSummary(serialId: number, summary: string): Promise<void>;
906
+ writeToc(toc: TocFile): Promise<void>;
907
+ replaceToc(toc: TocFile): Promise<void>;
908
+ flush(): Promise<void>;
909
+ release(): Promise<void>;
910
+ close(): Promise<void>;
911
+ runWithContext<T>(context: DirectoryDocumentContext, operation: () => Promise<T> | T): Promise<T>;
912
+ rollbackContext(context: DirectoryDocumentContext): Promise<void>;
913
+ }
914
+ declare class DirectoryDocumentContext implements DocumentContext {
915
+ #private;
916
+ constructor(document: DirectoryDocument);
917
+ complete(): void;
918
+ dispose(): Promise<void>;
919
+ ownSerial(serialId: number): void;
920
+ run<T>(operation: () => Promise<T> | T): Promise<T>;
921
+ listCreatedFilePaths(): readonly string[];
922
+ listOwnedSerialIds(): readonly number[];
923
+ registerCreatedFile(path: string): void;
924
+ }
925
+
926
+ declare const SCHEMA_SQL = "\n CREATE TABLE IF NOT EXISTS serials (\n id INTEGER PRIMARY KEY,\n document_order INTEGER NOT NULL DEFAULT 0\n );\n\n CREATE TABLE IF NOT EXISTS serial_states (\n serial_id INTEGER PRIMARY KEY,\n revision INTEGER NOT NULL DEFAULT 0,\n topology_ready INTEGER NOT NULL DEFAULT 0,\n topology_parameter_hash TEXT,\n knowledge_graph_ready INTEGER NOT NULL DEFAULT 0,\n knowledge_graph_parameter_hash TEXT,\n FOREIGN KEY (serial_id) REFERENCES serials(id)\n );\n\n CREATE TABLE IF NOT EXISTS archive_revisions (\n key TEXT PRIMARY KEY,\n value INTEGER NOT NULL\n );\n\n CREATE TABLE IF NOT EXISTS archive_index_settings (\n id INTEGER PRIMARY KEY CHECK (id = 1),\n fts_embedded INTEGER NOT NULL DEFAULT 0\n );\n\n CREATE TABLE IF NOT EXISTS graph_build_parameters (\n hash TEXT PRIMARY KEY,\n prompt TEXT NOT NULL,\n language TEXT,\n created_at TEXT NOT NULL\n );\n\n CREATE TABLE IF NOT EXISTS chunks (\n id INTEGER PRIMARY KEY,\n generation INTEGER NOT NULL,\n serial_id INTEGER NOT NULL,\n sentence_index INTEGER NOT NULL,\n label TEXT NOT NULL,\n content TEXT NOT NULL,\n retention TEXT,\n importance TEXT,\n wordsCount INTEGER NOT NULL DEFAULT 0,\n weight REAL NOT NULL DEFAULT 0.0\n );\n\n CREATE INDEX IF NOT EXISTS idx_chunks_sentence\n ON chunks(serial_id, sentence_index);\n\n CREATE INDEX IF NOT EXISTS idx_chunks_serial_id\n ON chunks(serial_id, id);\n\n CREATE TABLE IF NOT EXISTS chunk_sentences (\n chunk_id INTEGER NOT NULL,\n serial_id INTEGER NOT NULL,\n sentence_index INTEGER NOT NULL,\n FOREIGN KEY (chunk_id) REFERENCES chunks(id),\n PRIMARY KEY (chunk_id, serial_id, sentence_index)\n );\n\n CREATE TABLE IF NOT EXISTS reading_edges (\n from_id INTEGER NOT NULL,\n to_id INTEGER NOT NULL,\n strength TEXT,\n weight REAL NOT NULL DEFAULT 0.1,\n PRIMARY KEY (from_id, to_id),\n FOREIGN KEY (from_id) REFERENCES chunks(id),\n FOREIGN KEY (to_id) REFERENCES chunks(id)\n );\n\n CREATE TABLE IF NOT EXISTS snakes (\n id INTEGER PRIMARY KEY AUTOINCREMENT,\n serial_id INTEGER NOT NULL,\n group_id INTEGER NOT NULL,\n local_snake_id INTEGER NOT NULL,\n size INTEGER NOT NULL,\n first_label TEXT NOT NULL,\n last_label TEXT NOT NULL,\n wordsCount INTEGER NOT NULL DEFAULT 0,\n weight REAL NOT NULL DEFAULT 0.0,\n UNIQUE(serial_id, group_id, local_snake_id)\n );\n\n CREATE TABLE IF NOT EXISTS snake_chunks (\n snake_id INTEGER NOT NULL,\n chunk_id INTEGER NOT NULL,\n position INTEGER NOT NULL,\n FOREIGN KEY (snake_id) REFERENCES snakes(id),\n FOREIGN KEY (chunk_id) REFERENCES chunks(id),\n PRIMARY KEY (snake_id, chunk_id)\n );\n\n CREATE TABLE IF NOT EXISTS snake_edges (\n from_snake_id INTEGER NOT NULL,\n to_snake_id INTEGER NOT NULL,\n weight REAL NOT NULL DEFAULT 0.1,\n PRIMARY KEY (from_snake_id, to_snake_id),\n FOREIGN KEY (from_snake_id) REFERENCES snakes(id),\n FOREIGN KEY (to_snake_id) REFERENCES snakes(id)\n );\n\n CREATE TABLE IF NOT EXISTS sentence_groups (\n serial_id INTEGER NOT NULL,\n group_id INTEGER NOT NULL,\n start_sentence_index INTEGER NOT NULL,\n end_sentence_index INTEGER NOT NULL,\n PRIMARY KEY (serial_id, group_id, start_sentence_index, end_sentence_index)\n );\n\n CREATE TABLE IF NOT EXISTS mentions (\n id TEXT PRIMARY KEY,\n chapter_id INTEGER NOT NULL,\n sentence_index INTEGER,\n range_start INTEGER NOT NULL,\n range_end INTEGER NOT NULL,\n surface TEXT NOT NULL,\n qid TEXT NOT NULL,\n confidence REAL,\n note TEXT,\n FOREIGN KEY (chapter_id) REFERENCES serials(id)\n );\n\n CREATE INDEX IF NOT EXISTS idx_mentions_chapter\n ON mentions(chapter_id);\n\n CREATE INDEX IF NOT EXISTS idx_mentions_chapter_position\n ON mentions(chapter_id, sentence_index, range_start, range_end, id);\n\n CREATE INDEX IF NOT EXISTS idx_mentions_chapter_qid\n ON mentions(chapter_id, qid);\n\n CREATE INDEX IF NOT EXISTS idx_mentions_qid\n ON mentions(qid);\n\n CREATE INDEX IF NOT EXISTS idx_mentions_qid_position\n ON mentions(qid, chapter_id, sentence_index, range_start, range_end, id);\n\n CREATE INDEX IF NOT EXISTS idx_mentions_surface\n ON mentions(surface);\n\n CREATE INDEX IF NOT EXISTS idx_mentions_surface_position\n ON mentions(surface, chapter_id, sentence_index, range_start, range_end, id);\n\n CREATE INDEX IF NOT EXISTS idx_mentions_sentence\n ON mentions(chapter_id, sentence_index);\n\n CREATE TABLE IF NOT EXISTS mention_links (\n id TEXT PRIMARY KEY,\n source_mention_id TEXT NOT NULL,\n target_mention_id TEXT NOT NULL,\n predicate TEXT NOT NULL,\n confidence REAL,\n note TEXT,\n FOREIGN KEY (source_mention_id) REFERENCES mentions(id),\n FOREIGN KEY (target_mention_id) REFERENCES mentions(id)\n );\n\n CREATE TABLE IF NOT EXISTS mention_link_evidence_sentences (\n link_id TEXT NOT NULL,\n chapter_id INTEGER NOT NULL,\n sentence_index INTEGER NOT NULL,\n FOREIGN KEY (link_id) REFERENCES mention_links(id),\n PRIMARY KEY (link_id, chapter_id, sentence_index)\n );\n\n CREATE INDEX IF NOT EXISTS idx_mention_link_evidence_sentences_sentence\n ON mention_link_evidence_sentences(chapter_id, sentence_index);\n\n CREATE INDEX IF NOT EXISTS idx_mention_links_source\n ON mention_links(source_mention_id);\n\n CREATE INDEX IF NOT EXISTS idx_mention_links_target\n ON mention_links(target_mention_id);\n\n CREATE INDEX IF NOT EXISTS idx_mention_links_predicate\n ON mention_links(predicate);\n\n CREATE INDEX IF NOT EXISTS idx_mention_links_predicate_source_target\n ON mention_links(predicate, source_mention_id, target_mention_id);\n\n CREATE INDEX IF NOT EXISTS idx_mention_links_predicate_target_source\n ON mention_links(predicate, target_mention_id, source_mention_id);\n\n CREATE INDEX IF NOT EXISTS idx_mention_links_source_predicate_target\n ON mention_links(source_mention_id, predicate, target_mention_id);\n\n CREATE INDEX IF NOT EXISTS idx_mention_links_target_predicate_source\n ON mention_links(target_mention_id, predicate, source_mention_id);\n\n CREATE INDEX IF NOT EXISTS idx_mention_links_source_target_predicate\n ON mention_links(source_mention_id, target_mention_id, predicate);\n\n CREATE INDEX IF NOT EXISTS idx_reading_edges_target\n ON reading_edges(to_id, from_id);\n\n CREATE INDEX IF NOT EXISTS idx_snake_edges_target\n ON snake_edges(to_snake_id, from_snake_id);\n\n CREATE VIEW IF NOT EXISTS chapter_entities AS\n SELECT\n chapter_id,\n qid,\n COUNT(*) AS mention_count\n FROM mentions\n GROUP BY chapter_id, qid;\n\n CREATE VIEW IF NOT EXISTS book_entities AS\n SELECT\n qid,\n SUM(mention_count) AS mention_count\n FROM chapter_entities\n GROUP BY qid;\n\n CREATE VIEW IF NOT EXISTS chapter_entity_relations AS\n SELECT\n source_mentions.chapter_id AS chapter_id,\n source_mentions.qid AS subject_qid,\n mention_links.predicate AS predicate,\n target_mentions.qid AS object_qid,\n COUNT(*) AS evidence_count\n FROM mention_links\n JOIN mentions AS source_mentions\n ON source_mentions.id = mention_links.source_mention_id\n JOIN mentions AS target_mentions\n ON target_mentions.id = mention_links.target_mention_id\n WHERE source_mentions.chapter_id = target_mentions.chapter_id\n GROUP BY\n source_mentions.chapter_id,\n source_mentions.qid,\n mention_links.predicate,\n target_mentions.qid;\n\n CREATE VIEW IF NOT EXISTS book_entity_relations AS\n SELECT\n subject_qid,\n predicate,\n object_qid,\n SUM(evidence_count) AS evidence_count\n FROM chapter_entity_relations\n GROUP BY subject_qid, predicate, object_qid;\n\n CREATE TABLE IF NOT EXISTS text_sentence_records (\n id INTEGER PRIMARY KEY,\n kind INTEGER NOT NULL,\n chapter_id INTEGER NOT NULL,\n sentence_index INTEGER NOT NULL,\n words_count INTEGER NOT NULL DEFAULT 0,\n byte_offset INTEGER NOT NULL DEFAULT 0,\n byte_length INTEGER NOT NULL DEFAULT 0,\n UNIQUE(kind, chapter_id, sentence_index)\n );\n\n CREATE INDEX IF NOT EXISTS idx_text_sentence_records_chapter\n ON text_sentence_records(kind, chapter_id, sentence_index);\n\n CREATE TABLE IF NOT EXISTS object_metadata (\n id INTEGER PRIMARY KEY,\n object_kind INTEGER NOT NULL,\n object_path TEXT NOT NULL,\n key TEXT NOT NULL,\n value_json TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n chapter_id INTEGER,\n chunk_id INTEGER,\n entity_qid TEXT,\n triple_subject_qid TEXT,\n triple_predicate TEXT,\n triple_object_qid TEXT,\n UNIQUE(object_path, key)\n );\n\n CREATE INDEX IF NOT EXISTS idx_object_metadata_object\n ON object_metadata(object_path);\n\n CREATE INDEX IF NOT EXISTS idx_object_metadata_chapter\n ON object_metadata(chapter_id);\n\n CREATE INDEX IF NOT EXISTS idx_object_metadata_chunk\n ON object_metadata(chunk_id);\n\n CREATE INDEX IF NOT EXISTS idx_object_metadata_entity\n ON object_metadata(entity_qid);\n\n CREATE INDEX IF NOT EXISTS idx_object_metadata_triple\n ON object_metadata(\n triple_subject_qid,\n triple_predicate,\n triple_object_qid\n );\n";
927
+
928
+ declare const EVIDENCE_SELECTION_PROMPT_FRAGMENT: string;
929
+ declare const EVIDENCE_SELECTION_JSON_SHAPE: readonly [{
930
+ readonly quote: "exact short source quote copied from the selected sentence";
931
+ readonly sentence_id: "sentence id from the source context, such as S1";
932
+ }];
933
+ declare function formatEvidenceSelectionChoicePrompt(input: {
934
+ readonly evidenceLabel: string;
935
+ readonly generatedEvidence: unknown;
936
+ readonly candidates: readonly {
937
+ readonly nextText: string;
938
+ readonly occurrenceId: string;
939
+ readonly prevText: string;
940
+ readonly score: number;
941
+ readonly text: string;
942
+ }[];
943
+ }): string;
944
+
945
+ type EvidenceQuoteMatchStrategy = "empty" | "exact" | "normalized_exact" | "normalized_substring" | "fuzzy_window";
946
+ interface EvidenceQuoteScore {
947
+ readonly exactRaw: boolean;
948
+ readonly exactNormalized: boolean;
949
+ readonly exactSubstring: boolean;
950
+ readonly matchEnd: number;
951
+ readonly matchStart: number;
952
+ readonly normalizedQuote: string;
953
+ readonly normalizedSentence: string;
954
+ readonly score: number;
955
+ readonly strategy: EvidenceQuoteMatchStrategy;
956
+ }
957
+ declare function normalizeEvidenceDisplayText(text: string): string;
958
+ declare function normalizeEvidenceText(text: string): string;
959
+ declare function scoreEvidenceQuote(input: {
960
+ readonly quote: string;
961
+ readonly sentence: string;
962
+ }): EvidenceQuoteScore;
963
+
964
+ type EvidenceSentenceId = readonly [number, number];
965
+ interface EvidenceSelectionSentence {
966
+ readonly id: string;
967
+ readonly sentenceId: EvidenceSentenceId;
968
+ readonly text: string;
969
+ }
970
+ interface EvidenceSelection {
971
+ readonly quote?: string;
972
+ readonly sentence_id?: string;
973
+ }
974
+ type EvidenceSelectionList = EvidenceSelection | readonly EvidenceSelection[];
975
+ interface EvidenceSelectionCandidate {
976
+ readonly exactNormalized: boolean;
977
+ readonly exactRaw: boolean;
978
+ readonly exactSubstring: boolean;
979
+ readonly index: number;
980
+ readonly nextText: string;
981
+ readonly occurrenceId: string;
982
+ readonly prevText: string;
983
+ readonly score: number;
984
+ readonly sentence: EvidenceSelectionSentence;
985
+ readonly strategy: string;
986
+ }
987
+ interface EvidenceSelectionResolution {
988
+ readonly candidate: EvidenceSelectionCandidate;
989
+ readonly confidence: number;
990
+ readonly sentenceIds: readonly EvidenceSentenceId[];
991
+ readonly strategy: string;
992
+ }
993
+ interface EvidenceSelectionFailure {
994
+ readonly candidates: readonly EvidenceSelectionCandidate[];
995
+ readonly code: "ambiguous" | "invalid" | "low_confidence" | "missing_sentence" | "none";
996
+ readonly message: string;
997
+ }
998
+
999
+ declare function resolveEvidenceSelection(input: {
1000
+ readonly evidence: EvidenceSelection;
1001
+ readonly sentences: readonly EvidenceSelectionSentence[];
1002
+ }): readonly [
1003
+ resolution: EvidenceSelectionResolution | undefined,
1004
+ failure: EvidenceSelectionFailure | undefined
1005
+ ];
1006
+ declare function resolveEvidenceSelectionList(input: {
1007
+ readonly evidence: EvidenceSelectionList;
1008
+ readonly sentences: readonly EvidenceSelectionSentence[];
1009
+ }): readonly [
1010
+ resolution: EvidenceSelectionResolution | undefined,
1011
+ failure: EvidenceSelectionFailure | undefined
1012
+ ];
1013
+ declare function rankEvidenceQuote(quote: string, sentences: readonly EvidenceSelectionSentence[]): EvidenceSelectionCandidate[];
1014
+
1015
+ interface WikipageResolverOptions {
1016
+ readonly cacheDatabasePath?: string;
1017
+ readonly concurrency?: number;
1018
+ readonly fetch?: typeof fetch;
1019
+ readonly language?: string;
1020
+ readonly logDirPath?: string;
1021
+ readonly maxBatchSize?: number;
1022
+ readonly minRequestIntervalMs?: number;
1023
+ readonly normalizer?: DisambiguationProfileNormalizer;
1024
+ readonly progress?: WikipageResolveProgressReporter;
1025
+ readonly retryBaseDelayMs?: number;
1026
+ readonly retryTimes?: number;
1027
+ readonly userAgent?: string;
1028
+ readonly wiki?: string;
1029
+ }
1030
+ type WikipageResolveProgressDetail = "disambiguation-page" | "entity" | "linked-page" | "page" | "qid";
1031
+ interface WikipageResolveProgress {
1032
+ readonly detail: WikipageResolveProgressDetail;
1033
+ readonly done: number;
1034
+ readonly total: number;
1035
+ }
1036
+ type WikipageResolveProgressReporter = (event: WikipageResolveProgress) => Promise<void> | void;
1037
+ interface QidResolution {
1038
+ readonly description?: string;
1039
+ readonly disambiguation?: DisambiguationExpansion;
1040
+ readonly disambiguationPages?: readonly DisambiguationPageText[];
1041
+ readonly isDisambiguation: boolean;
1042
+ readonly label?: string;
1043
+ readonly qid: string;
1044
+ readonly sitelink?: WikipageSitelink;
1045
+ readonly sitelinks?: readonly WikipageSitelink[];
1046
+ }
1047
+ interface WikipageSitelink {
1048
+ readonly title: string;
1049
+ readonly wiki: string;
1050
+ }
1051
+ interface DisambiguationExpansion {
1052
+ readonly checkedAt: string;
1053
+ readonly disambiguationQid: string;
1054
+ readonly linkedQids: readonly DisambiguationLinkedQid[];
1055
+ readonly pages: readonly DisambiguationPageText[];
1056
+ readonly profile?: DisambiguationProfile;
1057
+ }
1058
+ interface DisambiguationPageText {
1059
+ readonly linkedQids: readonly DisambiguationLinkedQid[];
1060
+ readonly pageId?: number;
1061
+ readonly text: string;
1062
+ readonly title: string;
1063
+ readonly wiki: "enwiki" | "zhwiki";
1064
+ }
1065
+ interface DisambiguationLinkedQid {
1066
+ readonly qid: string;
1067
+ readonly title: string;
1068
+ }
1069
+ interface CachedQidRecord {
1070
+ readonly checkedAt: string;
1071
+ readonly description?: string;
1072
+ readonly label?: string;
1073
+ readonly qid: string;
1074
+ readonly sitelinks: readonly CachedPageRecord[];
1075
+ readonly updatedAt: string;
1076
+ }
1077
+ interface CachedDisambiguationRecord {
1078
+ readonly checkedAt: string;
1079
+ readonly disambiguationQid: string;
1080
+ readonly pages: readonly DisambiguationPageText[];
1081
+ readonly profile?: DisambiguationProfile;
1082
+ }
1083
+ interface CachedPageRecord {
1084
+ readonly isDisambiguation: boolean;
1085
+ readonly pageId?: number;
1086
+ readonly title: string;
1087
+ readonly wiki: "enwiki" | "zhwiki";
1088
+ }
1089
+ type DisambiguationMeaningPriority = "other" | "primary" | "secondary";
1090
+ interface DisambiguationProfile {
1091
+ readonly meanings: readonly DisambiguationProfileMeaning[];
1092
+ readonly sourceQid: string;
1093
+ readonly surface?: string;
1094
+ }
1095
+ interface DisambiguationProfileMeaning {
1096
+ readonly category?: string;
1097
+ readonly information: string;
1098
+ readonly name: string;
1099
+ readonly priority: DisambiguationMeaningPriority;
1100
+ readonly qid: string;
1101
+ }
1102
+ type DisambiguationProfileNormalizer = (input: DisambiguationProfileNormalizerInput) => Promise<DisambiguationProfile>;
1103
+ interface DisambiguationProfileNormalizerInput {
1104
+ readonly pageQidLinks: readonly DisambiguationLinkedQid[];
1105
+ readonly pages: readonly DisambiguationPageText[];
1106
+ readonly sourceQid: string;
1107
+ readonly surface?: string;
1108
+ }
1109
+
1110
+ declare class WikipageCache {
1111
+ #private;
1112
+ constructor(database: Database);
1113
+ static open(path?: string): Promise<WikipageCache>;
1114
+ close(): Promise<void>;
1115
+ getQids(qids: readonly string[], language: string): Promise<ReadonlyMap<string, CachedQidRecord>>;
1116
+ putQids(records: readonly CachedQidRecord[], language: string): Promise<void>;
1117
+ getDisambiguations(qids: readonly string[], wiki: string): Promise<ReadonlyMap<string, CachedDisambiguationRecord>>;
1118
+ putDisambiguations(records: readonly CachedDisambiguationRecord[], wiki: string): Promise<void>;
1119
+ }
1120
+
1121
+ type GuaranteedRequest = (messages: readonly LLMessage[], index: number, maxRetries: number) => Promise<string | undefined>;
1122
+ type GuaranteedLazyRequest = <T>(operation: (request: GuaranteedRequest) => Promise<T>) => Promise<T>;
1123
+ type GuaranteedRequestController = GuaranteedRequest & {
1124
+ lazy?: GuaranteedLazyRequest;
1125
+ };
1126
+
1127
+ interface CreateDisambiguationProfileNormalizerOptions {
1128
+ readonly maxMeanings?: number;
1129
+ readonly maxRetries?: number;
1130
+ readonly request: GuaranteedRequest;
1131
+ }
1132
+ declare function createDisambiguationProfileNormalizer(options: CreateDisambiguationProfileNormalizerOptions): DisambiguationProfileNormalizer;
1133
+
1134
+ interface RateLimiterOptions {
1135
+ readonly concurrency: number;
1136
+ readonly minRequestIntervalMs: number;
1137
+ }
1138
+ declare class RateLimiter {
1139
+ #private;
1140
+ constructor(options: RateLimiterOptions);
1141
+ use<T>(operation: () => Promise<T>): Promise<T>;
1142
+ blockFor(ms: number): void;
1143
+ }
1144
+ declare function parseRetryAfterMs(value: string | null): number | undefined;
1145
+
1146
+ interface WikipageFetchLog {
1147
+ readonly filePath: string | undefined;
1148
+ append(entry: WikipageFetchLogEntry): Promise<void>;
1149
+ warnFailed(): void;
1150
+ }
1151
+ interface WikipageFetchLogEntry {
1152
+ readonly attempt: number;
1153
+ readonly durationMs: number;
1154
+ readonly error?: unknown;
1155
+ readonly response?: Response;
1156
+ readonly responseText?: string;
1157
+ readonly startedAt: number;
1158
+ readonly url: URL;
1159
+ }
1160
+
1161
+ type SupportedWiki = "enwiki" | "zhwiki";
1162
+ interface WikimediaClientOptions {
1163
+ readonly concurrency: number;
1164
+ readonly fetch?: typeof fetch;
1165
+ readonly language: string;
1166
+ readonly minRequestIntervalMs: number;
1167
+ readonly requestLog: WikipageFetchLog;
1168
+ readonly retryBaseDelayMs: number;
1169
+ readonly retryTimes: number;
1170
+ readonly userAgent?: string;
1171
+ readonly wiki: string;
1172
+ }
1173
+ interface WikidataEntityInfo {
1174
+ readonly description?: string;
1175
+ readonly label?: string;
1176
+ readonly qid: string;
1177
+ readonly sitelinks: readonly WikidataSitelinkInfo[];
1178
+ }
1179
+ interface WikidataSitelinkInfo {
1180
+ readonly title: string;
1181
+ readonly wiki: SupportedWiki;
1182
+ }
1183
+ interface WikiPageInfo {
1184
+ readonly isDisambiguation: boolean;
1185
+ readonly pageId?: number;
1186
+ readonly title: string;
1187
+ readonly wiki: SupportedWiki;
1188
+ readonly wikibaseItem?: string;
1189
+ }
1190
+ interface ParsedDisambiguationPage {
1191
+ readonly linkedTitles: readonly string[];
1192
+ readonly pageId?: number;
1193
+ readonly text: string;
1194
+ readonly title: string;
1195
+ readonly wiki: SupportedWiki;
1196
+ }
1197
+ declare class WikimediaClient {
1198
+ #private;
1199
+ constructor(options: WikimediaClientOptions);
1200
+ getEntities(qids: readonly string[]): Promise<ReadonlyMap<string, WikidataEntityInfo>>;
1201
+ getPagesByTitles(titles: readonly string[], wiki?: SupportedWiki): Promise<ReadonlyMap<string, WikiPageInfo>>;
1202
+ parseDisambiguationPage(title: string, wiki: SupportedWiki): Promise<ParsedDisambiguationPage>;
1203
+ }
1204
+
1205
+ declare class WikipageResolver {
1206
+ #private;
1207
+ constructor(input: {
1208
+ readonly cache: WikipageCache;
1209
+ readonly client: WikimediaClient;
1210
+ readonly language: string;
1211
+ readonly maxBatchSize: number;
1212
+ readonly normalizer: DisambiguationProfileNormalizer | undefined;
1213
+ readonly ownsCache: boolean;
1214
+ readonly progress: WikipageResolveProgressReporter | undefined;
1215
+ readonly wiki: string;
1216
+ });
1217
+ static open(options?: WikipageResolverOptions): Promise<WikipageResolver>;
1218
+ close(): Promise<void>;
1219
+ resolveQids(qids: readonly string[]): Promise<readonly QidResolution[]>;
1220
+ }
1221
+
1222
+ interface WikimatchCandidate {
1223
+ readonly hasMoreOptions?: boolean;
1224
+ readonly id: string;
1225
+ readonly qidOptions: readonly WikimatchQidOption[];
1226
+ readonly range: WikimatchTextRange;
1227
+ readonly surface: string;
1228
+ }
1229
+ interface WikimatchSentence {
1230
+ readonly id?: string;
1231
+ readonly range: WikimatchTextRange;
1232
+ readonly text: string;
1233
+ }
1234
+ interface WikimatchQidOption {
1235
+ readonly description?: string;
1236
+ readonly disambiguation?: DisambiguationExpansion;
1237
+ readonly isDisambiguation?: boolean;
1238
+ readonly label?: string;
1239
+ readonly qid: string;
1240
+ }
1241
+ interface WikimatchTextRange {
1242
+ readonly end: number;
1243
+ readonly start: number;
1244
+ }
1245
+ interface WikimatchWindow {
1246
+ readonly baseOffset: number;
1247
+ readonly candidates: readonly WikimatchCandidate[];
1248
+ readonly groups: readonly WikimatchConflictGroup[];
1249
+ readonly text: string;
1250
+ }
1251
+ interface WikimatchSurface {
1252
+ readonly id: string;
1253
+ readonly count: number;
1254
+ readonly text: string;
1255
+ }
1256
+ interface WikimatchConflictGroup {
1257
+ readonly candidateIds: readonly string[];
1258
+ readonly id: string;
1259
+ readonly range: WikimatchTextRange;
1260
+ }
1261
+ interface BuildWikimatchWindowsOptions {
1262
+ readonly candidates: readonly WikimatchCandidate[];
1263
+ readonly contextWords: number;
1264
+ readonly optionBudget: number;
1265
+ readonly text: string;
1266
+ }
1267
+ interface NarrowWikimatchCandidateOptionsInput {
1268
+ readonly candidate: WikimatchCandidate;
1269
+ readonly policyPrompt: string;
1270
+ readonly text: string;
1271
+ }
1272
+ interface WikimatchCandidateOptionNarrowingResult {
1273
+ readonly candidate: WikimatchCandidate;
1274
+ readonly fallback?: WikimatchCandidateOptionNarrowingFallback;
1275
+ }
1276
+ interface WikimatchCandidateOptionNarrowingFallback {
1277
+ readonly issues: readonly string[];
1278
+ readonly reason: "guaranteed_json_failed";
1279
+ }
1280
+ interface WikimatchCandidateOptionNarrowingResponse {
1281
+ readonly qids: readonly WikimatchCandidateOptionNarrowingItemOutput[];
1282
+ }
1283
+ interface WikimatchCandidateOptionNarrowingItemOutput {
1284
+ readonly decision: "keep" | "reject";
1285
+ readonly qid: string;
1286
+ }
1287
+ interface BuildWikimatchSurfaceProtectionInputOptions {
1288
+ readonly candidates: readonly WikimatchCandidate[];
1289
+ readonly percentile: number;
1290
+ readonly text: string;
1291
+ }
1292
+ interface WikimatchSurfaceProtectionInput {
1293
+ readonly policyPrompt: string;
1294
+ readonly suspiciousSurfaces: readonly WikimatchSurface[];
1295
+ }
1296
+ interface WikimatchSurfaceProtectionBuildResult {
1297
+ readonly candidates: readonly WikimatchCandidate[];
1298
+ readonly suppressedCandidates: readonly WikimatchCandidate[];
1299
+ readonly suspiciousSurfaces: readonly WikimatchSurface[];
1300
+ }
1301
+ interface WikimatchSurfaceProtectionResult {
1302
+ readonly fallback?: WikimatchSurfaceProtectionFallback;
1303
+ readonly protectedSurfaces: readonly WikimatchProtectedSurface[];
1304
+ }
1305
+ interface WikimatchProtectedSurface {
1306
+ readonly note?: string;
1307
+ readonly surfaceId: string;
1308
+ readonly text: string;
1309
+ }
1310
+ interface WikimatchSurfaceProtectionFallback {
1311
+ readonly issues: readonly string[];
1312
+ readonly reason: "guaranteed_json_failed";
1313
+ }
1314
+ interface WikimatchProtectedSurfaceOutput {
1315
+ readonly note?: string;
1316
+ readonly surfaceId: string;
1317
+ }
1318
+ interface WikimatchSurfaceProtectionResponse {
1319
+ readonly protectedSurfaces: readonly WikimatchProtectedSurfaceOutput[];
1320
+ }
1321
+ type WikimatchPolicyDecision = "continue" | "never_recall" | "recall" | "skip_this_time";
1322
+ interface WikimatchPolicyJudgeInput {
1323
+ readonly candidates: readonly WikimatchCandidate[];
1324
+ readonly policyPrompt: string;
1325
+ readonly window: WikimatchWindow;
1326
+ }
1327
+ interface WikimatchPolicyJudgeResult {
1328
+ readonly continuations: readonly WikimatchPolicyContinuation[];
1329
+ readonly fallback?: WikimatchPolicyFallback;
1330
+ readonly mentions: readonly WikimatchAcceptedMention[];
1331
+ readonly policyUpdates: readonly WikimatchPolicyUpdate[];
1332
+ }
1333
+ interface WikimatchAcceptedMention {
1334
+ readonly candidateId: string;
1335
+ readonly confidence?: number;
1336
+ readonly qid: string;
1337
+ readonly range: WikimatchTextRange;
1338
+ readonly note?: string;
1339
+ readonly surface: string;
1340
+ }
1341
+ interface WikimatchPolicyUpdate {
1342
+ readonly candidateId: string;
1343
+ readonly decision: Exclude<WikimatchPolicyDecision, "recall" | "continue">;
1344
+ readonly note?: string;
1345
+ readonly qid?: string;
1346
+ readonly surface: string;
1347
+ }
1348
+ interface WikimatchPolicyContinuation {
1349
+ readonly candidateIds: readonly string[];
1350
+ readonly groupId: string;
1351
+ }
1352
+ interface WikimatchPolicyFallback {
1353
+ readonly issues: readonly string[];
1354
+ readonly reason: "guaranteed_json_failed";
1355
+ }
1356
+ interface WikimatchPolicyDecisionOutput {
1357
+ readonly candidateId: string;
1358
+ readonly confidence?: number;
1359
+ readonly decision: WikimatchPolicyDecision;
1360
+ readonly qid?: string;
1361
+ }
1362
+ interface WikimatchPolicyGroupOutput {
1363
+ readonly decisions: readonly WikimatchPolicyDecisionOutput[];
1364
+ readonly groupId: string;
1365
+ }
1366
+ interface WikimatchPolicyResponse {
1367
+ readonly groups: readonly WikimatchPolicyGroupOutput[];
1368
+ }
1369
+
1370
+ interface JudgeWikimatchPolicyOptions extends WikimatchPolicyJudgeInput {
1371
+ readonly maxRetries?: number;
1372
+ readonly request: GuaranteedRequest;
1373
+ }
1374
+ declare function judgeWikimatchPolicy(options: JudgeWikimatchPolicyOptions): Promise<WikimatchPolicyJudgeResult>;
1375
+ declare function parsePolicyResponse(candidates: readonly WikimatchCandidate[], response: WikimatchPolicyResponse, groups?: readonly WikimatchConflictGroup[]): WikimatchPolicyJudgeResult;
1376
+ declare function validatePolicyResponse(candidates: readonly WikimatchCandidate[], response: WikimatchPolicyResponse, groups?: readonly WikimatchConflictGroup[]): readonly string[];
1377
+ declare function formatCandidateForPrompt(candidate: WikimatchCandidate, _group?: WikimatchConflictGroup): object;
1378
+
1379
+ interface NarrowWikimatchCandidateOptionsOptions extends NarrowWikimatchCandidateOptionsInput {
1380
+ readonly maxRetries?: number;
1381
+ readonly optionBudget: number;
1382
+ readonly request: GuaranteedRequest;
1383
+ }
1384
+ declare function narrowWikimatchCandidateOptions(options: NarrowWikimatchCandidateOptionsOptions): Promise<WikimatchCandidateOptionNarrowingResult>;
1385
+ declare function parseNarrowingResponse(candidate: WikimatchCandidate, response: WikimatchCandidateOptionNarrowingResponse): WikimatchCandidateOptionNarrowingResult;
1386
+ declare function validateNarrowingResponse(candidate: WikimatchCandidate, response: WikimatchCandidateOptionNarrowingResponse): readonly string[];
1387
+
1388
+ declare function countWikimatchCandidateOptions(candidate: WikimatchCandidate): number;
1389
+ declare function countWikimatchQidOption(option: WikimatchQidOption): number;
1390
+ declare function listCandidateSelectableQids(candidate: WikimatchCandidate): readonly string[];
1391
+ declare function filterCandidateQidOptions(candidate: WikimatchCandidate, allowedQids: ReadonlySet<string>): WikimatchCandidate;
1392
+ declare function splitCandidateByOptionBudget(candidate: WikimatchCandidate, optionBudget: number): readonly WikimatchCandidate[];
1393
+ declare function sliceCandidateByOptionBudget(candidate: WikimatchCandidate, optionBudget: number, offset: number): {
1394
+ readonly candidate: WikimatchCandidate;
1395
+ readonly nextOffset?: number;
1396
+ };
1397
+
1398
+ declare function enrichWikimatchCandidates(candidates: readonly WikimatchCandidate[], options?: {
1399
+ readonly progress?: WikipageResolveProgressReporter;
1400
+ readonly resolverOptions?: Omit<WikipageResolverOptions, "progress">;
1401
+ }): Promise<readonly WikimatchCandidate[]>;
1402
+ declare function applyQidResolutions(candidates: readonly WikimatchCandidate[], resolutions: readonly QidResolution[]): readonly WikimatchCandidate[];
1403
+
1404
+ interface JudgeWikimatchSurfaceProtectionOptions extends WikimatchSurfaceProtectionInput {
1405
+ readonly maxRetries?: number;
1406
+ readonly request: GuaranteedRequest;
1407
+ }
1408
+ declare function judgeWikimatchSurfaceProtection(options: JudgeWikimatchSurfaceProtectionOptions): Promise<WikimatchSurfaceProtectionResult>;
1409
+ declare function parseSurfaceProtectionResponse(surfaces: readonly WikimatchSurface[], response: WikimatchSurfaceProtectionResponse): WikimatchSurfaceProtectionResult;
1410
+ declare function validateSurfaceProtectionResponse(surfaces: readonly WikimatchSurface[], response: WikimatchSurfaceProtectionResponse): readonly string[];
1411
+
1412
+ declare function buildWikimatchSurfaceProtectionInput(options: BuildWikimatchSurfaceProtectionInputOptions): WikimatchSurfaceProtectionBuildResult;
1413
+
1414
+ interface SuppressContainedRangeInput {
1415
+ readonly range: {
1416
+ readonly end: number;
1417
+ readonly start: number;
1418
+ };
1419
+ }
1420
+ declare function suppressContainedRanges<T extends SuppressContainedRangeInput>(items: readonly T[]): readonly T[];
1421
+
1422
+ interface MatchWikispineSentenceCandidatesOptions {
1423
+ readonly command?: string;
1424
+ readonly dataDir?: string;
1425
+ readonly endpoint?: string;
1426
+ readonly fetch?: typeof fetch;
1427
+ readonly includeDisambiguation?: boolean;
1428
+ readonly maxCandidatesPerSurface?: number;
1429
+ readonly onProgress?: (progress: WikispineMatchProgress) => Promise<void> | void;
1430
+ readonly provider?: WikispineProvider;
1431
+ readonly sentences: readonly WikimatchSentence[];
1432
+ }
1433
+ type WikispineProvider = "cli" | "fetch";
1434
+ interface WikispineMatchProgress {
1435
+ readonly coveredRangeEnd: number;
1436
+ }
1437
+ interface TestWikispineRuntimeOptions {
1438
+ readonly command?: string;
1439
+ readonly dataDir?: string;
1440
+ readonly endpoint?: string;
1441
+ readonly fetch?: typeof fetch;
1442
+ readonly provider?: WikispineProvider;
1443
+ }
1444
+ interface WikispineRuntimeTestResult {
1445
+ readonly durationMs: number;
1446
+ readonly metadata?: WikispineMetadata;
1447
+ readonly ok: true;
1448
+ readonly provider: WikispineProvider;
1449
+ }
1450
+ interface WikispineMetadata {
1451
+ readonly automaton_shard_count: number;
1452
+ readonly format: string;
1453
+ readonly qid_count: number;
1454
+ readonly surface_count: number;
1455
+ readonly surface_normalization: string;
1456
+ }
1457
+ declare const DEFAULT_WIKISPINE_FETCH_ENDPOINT = "https://wikispi-service-cxbfjlteab.cn-hangzhou.fcapp.run";
1458
+ declare function matchWikispineSentenceCandidates(options: MatchWikispineSentenceCandidatesOptions): Promise<readonly WikimatchCandidate[]>;
1459
+ declare function testWikispineRuntime(options: TestWikispineRuntimeOptions): Promise<WikispineRuntimeTestResult>;
1460
+
1461
+ declare function buildWikimatchWindows(options: BuildWikimatchWindowsOptions): readonly WikimatchWindow[];
1462
+
1463
+ interface WordBoundary {
1464
+ readonly end: number;
1465
+ readonly start: number;
1466
+ }
1467
+ declare function listWordBoundaries(text: string): readonly WordBoundary[];
1468
+ declare function expandRangeByWords(input: {
1469
+ readonly rangeEnd: number;
1470
+ readonly rangeStart: number;
1471
+ readonly text: string;
1472
+ readonly words: number;
1473
+ }): {
1474
+ readonly end: number;
1475
+ readonly start: number;
1476
+ };
1477
+
1478
+ type WikiGraphSamplingConfig = SamplingScopeConfig<WikiGraphScope>;
1479
+ declare function createDefaultWikiGraphSampling(input?: {
1480
+ readonly temperature?: TemperatureSetting;
1481
+ readonly topP?: TemperatureSetting;
1482
+ }): WikiGraphSamplingConfig;
1483
+
1484
+ type WikiGraphOperation = "digest-epub" | "digest-markdown" | "digest-text-stream" | "digest-txt";
1485
+ interface SerialDiscoveryItem {
1486
+ readonly id: number;
1487
+ readonly fragments?: number | undefined;
1488
+ readonly title?: string | undefined;
1489
+ readonly words: number;
1490
+ }
1491
+ interface SerialsDiscoveredEvent {
1492
+ readonly type: "serials-discovered";
1493
+ readonly available: boolean;
1494
+ readonly serials: readonly SerialDiscoveryItem[];
1495
+ }
1496
+ interface SerialProgressEvent {
1497
+ readonly type: "serial-progress";
1498
+ readonly id: number;
1499
+ readonly completedWords: number;
1500
+ readonly completedFragments: number;
1501
+ }
1502
+ interface DigestProgressEvent {
1503
+ readonly type: "digest-progress";
1504
+ readonly completedWords: number;
1505
+ readonly totalWords: number;
1506
+ }
1507
+ type WikiGraphProgressEventType = WikiGraphProgressEvent["type"];
1508
+ type WikiGraphProgressEvent = SerialsDiscoveredEvent | SerialProgressEvent | DigestProgressEvent;
1509
+ type WikiGraphProgressCallback = (event: WikiGraphProgressEvent) => void | Promise<void>;
1510
+
1511
+ type TextStream = AsyncIterable<string> | Iterable<string>;
1512
+
1513
+ type ReaderTextStream = TextStream;
1514
+
1515
+ interface SerialProgressSink {
1516
+ begin?(input?: {
1517
+ readonly fragments: number;
1518
+ readonly words: number;
1519
+ }): Promise<void>;
1520
+ advance(wordsCount: number): Promise<void>;
1521
+ complete(finalWordsCount?: number): Promise<void>;
1522
+ }
1523
+
1524
+ declare const CHAPTER_STAGES: readonly ["planned", "sourced", "graphed", "summarized"];
1525
+ type ChapterStage = (typeof CHAPTER_STAGES)[number];
1526
+ interface ChapterEntry {
1527
+ readonly chapterId: number;
1528
+ readonly childCount: number;
1529
+ readonly depth: number;
1530
+ readonly documentOrder: number;
1531
+ readonly fragmentCount: number;
1532
+ readonly stage: ChapterStage;
1533
+ readonly title: string | null;
1534
+ readonly tocPath: readonly string[];
1535
+ readonly words: number;
1536
+ }
1537
+ interface ChapterDetails extends ChapterEntry {
1538
+ readonly graphReady: boolean;
1539
+ readonly hasSummary: boolean;
1540
+ readonly words: number;
1541
+ }
1542
+ interface ChapterTree {
1543
+ readonly chapters: readonly ChapterTreeNode[];
1544
+ }
1545
+ interface ChapterTreeNode {
1546
+ readonly children: readonly ChapterTreeNode[];
1547
+ readonly id: number;
1548
+ readonly title: string | null;
1549
+ }
1550
+ interface ChapterTreeInput {
1551
+ readonly chapters: readonly ChapterTreeInputNode[];
1552
+ }
1553
+ interface ChapterTreeInputNode {
1554
+ readonly children: readonly ChapterTreeInputNode[];
1555
+ readonly id: number;
1556
+ readonly title?: string | null | undefined;
1557
+ }
1558
+ interface ChapterTreeApplyResult {
1559
+ readonly changed: boolean;
1560
+ readonly moved: readonly ChapterTreeMoveChange[];
1561
+ readonly renamed: readonly ChapterTreeTitleChange[];
1562
+ readonly unchanged: number;
1563
+ }
1564
+ interface ChapterTreeMoveChange {
1565
+ readonly chapterId: number;
1566
+ readonly newIndex: number;
1567
+ readonly newParentChapterId: number | null;
1568
+ readonly newPath: readonly string[];
1569
+ readonly oldIndex: number;
1570
+ readonly oldParentChapterId: number | null;
1571
+ readonly oldPath: readonly string[];
1572
+ }
1573
+ interface ChapterTreeTitleChange {
1574
+ readonly chapterId: number;
1575
+ readonly newTitle: string | null;
1576
+ readonly oldTitle: string | null;
1577
+ }
1578
+ interface MoveChapterOptions {
1579
+ readonly afterChapterId?: number;
1580
+ readonly beforeChapterId?: number;
1581
+ readonly first?: boolean;
1582
+ readonly last?: boolean;
1583
+ readonly parentChapterId?: number;
1584
+ readonly root?: boolean;
1585
+ }
1586
+ interface AdvanceChapterStagesOptions {
1587
+ readonly chapterId?: number;
1588
+ readonly extractionPrompt: string;
1589
+ readonly llm: LLM<WikiGraphScope>;
1590
+ readonly logDirPath?: string;
1591
+ readonly onProgress?: AdvanceChapterStagesProgressCallback;
1592
+ readonly targetStage: ChapterStage;
1593
+ readonly userLanguage?: Language;
1594
+ }
1595
+ interface AdvanceChapterStagesProgressState {
1596
+ readonly graphWords: number;
1597
+ readonly summaryWords: number;
1598
+ readonly totalGraphWords: number;
1599
+ readonly totalSummaryWords: number;
1600
+ }
1601
+ type AdvanceChapterStagesProgressCallback = (event: AdvanceChapterStagesProgressEvent) => void | Promise<void>;
1602
+ type AdvanceChapterStagesProgressEvent = {
1603
+ readonly type: "selected";
1604
+ readonly state: AdvanceChapterStagesProgressState;
1605
+ readonly targetStage: ChapterStage;
1606
+ readonly totalChapters: number;
1607
+ } | {
1608
+ readonly type: "skipped";
1609
+ readonly chapter: ChapterEntry;
1610
+ readonly reason: "planned";
1611
+ readonly targetStage: ChapterStage;
1612
+ } | {
1613
+ readonly type: "progress";
1614
+ readonly state: AdvanceChapterStagesProgressState;
1615
+ readonly targetStage: ChapterStage;
1616
+ } | {
1617
+ readonly type: "started";
1618
+ readonly chapter: ChapterEntry;
1619
+ readonly step: "graph" | "summary";
1620
+ readonly targetStage: ChapterStage;
1621
+ } | {
1622
+ readonly type: "completed";
1623
+ readonly chapter: ChapterEntry;
1624
+ readonly step: "graph" | "summary";
1625
+ readonly targetStage: ChapterStage;
1626
+ };
1627
+ interface AdvanceChapterStagesResult {
1628
+ readonly advanced: readonly ChapterEntry[];
1629
+ readonly pending: readonly ChapterEntry[];
1630
+ readonly skipped: readonly ChapterEntry[];
1631
+ }
1632
+ interface AddChapterOptions {
1633
+ readonly parentChapterId?: number;
1634
+ readonly title?: string | null | undefined;
1635
+ }
1636
+ declare function parseChapterTreeInput(input: unknown): ChapterTreeInput;
1637
+ interface GenerateChapterGraphOptions {
1638
+ readonly extractionPrompt: string;
1639
+ readonly llm: LLM<WikiGraphScope>;
1640
+ readonly logDirPath?: string;
1641
+ readonly progressTracker?: SerialProgressSink;
1642
+ readonly userLanguage?: Language;
1643
+ }
1644
+ interface GenerateChapterSummaryOptions {
1645
+ readonly llm: LLM<WikiGraphScope>;
1646
+ readonly logDirPath?: string;
1647
+ readonly userLanguage?: Language;
1648
+ }
1649
+ declare function advanceChapterStages(document: Document, options: AdvanceChapterStagesOptions): Promise<AdvanceChapterStagesResult>;
1650
+ declare function addChapter(document: Document, options: AddChapterOptions): Promise<ChapterDetails>;
1651
+ declare function generateChapterGraph(document: Document, chapterId: number, options: GenerateChapterGraphOptions): Promise<ChapterDetails>;
1652
+ declare function generateChapterSummary(document: Document, chapterId: number, options: GenerateChapterSummaryOptions): Promise<ChapterDetails>;
1653
+ declare function getChapterDetails(document: ReadonlyDocument, chapterId: number): Promise<ChapterDetails>;
1654
+ declare function listChapters(document: ReadonlyDocument): Promise<readonly ChapterEntry[]>;
1655
+ declare function getChapterTree(document: ReadonlyDocument): Promise<ChapterTree>;
1656
+ declare function applyChapterTree(document: Document, tree: ChapterTreeInput, options?: {
1657
+ readonly dryRun?: boolean;
1658
+ }): Promise<ChapterTreeApplyResult>;
1659
+ declare function moveChapter(document: Document, chapterId: number, options: MoveChapterOptions): Promise<ChapterDetails>;
1660
+ declare function removeChapter(document: Document, chapterId: number, options?: {
1661
+ readonly recursive?: boolean;
1662
+ }): Promise<void>;
1663
+ declare function resetChapter(document: Document, chapterId: number, stage: Exclude<ChapterStage, "summarized">): Promise<ChapterDetails>;
1664
+ declare function setChapterSource(document: Document, chapterId: number, stream: ReaderTextStream): Promise<ChapterDetails>;
1665
+ declare function setChapterSummary(document: Document, chapterId: number, summary: string): Promise<ChapterDetails>;
1666
+ declare function setChapterTitle(document: Document, chapterId: number, title: string | null | undefined): Promise<ChapterDetails>;
1667
+
1668
+ interface WikiGraphSerialEntry {
1669
+ readonly fragmentCount: number;
1670
+ readonly serialId: number;
1671
+ readonly title: string | null;
1672
+ readonly tocPath: readonly string[];
1673
+ }
1674
+
1675
+ declare class WikiGraphArchive {
1676
+ #private;
1677
+ constructor(document: ReadonlyDocument, documentDirectoryPath: string);
1678
+ exportEpub(path: string): Promise<void>;
1679
+ exportText(path: string): Promise<void>;
1680
+ readCover(): Promise<SourceAsset | undefined>;
1681
+ readMeta(): Promise<BookMeta | undefined>;
1682
+ readToc(): Promise<TocFile | undefined>;
1683
+ readArchiveFormatVersion(): Promise<number>;
1684
+ readChapterStage(serialId: number): Promise<ChapterStage>;
1685
+ listSerials(): Promise<readonly WikiGraphSerialEntry[]>;
1686
+ readSerialSummary(serialId: number): Promise<string>;
1687
+ saveAs(path: string): Promise<void>;
1688
+ }
1689
+
1690
+ interface DigestDocumentSessionOptions {
1691
+ readonly documentDirPath?: string;
1692
+ }
1693
+
1694
+ interface WikiGraphLLMOptions {
1695
+ readonly cacheDirPath?: string;
1696
+ readonly concurrent?: number;
1697
+ readonly logDirPath?: string;
1698
+ readonly model: LanguageModel;
1699
+ readonly retryIntervalSeconds?: number;
1700
+ readonly retryTimes?: number;
1701
+ readonly stream?: boolean;
1702
+ readonly temperature?: number | readonly number[];
1703
+ readonly timeout?: number;
1704
+ readonly topP?: number | readonly number[];
1705
+ }
1706
+ interface WikiGraphOptions {
1707
+ readonly debugLogDirPath?: string;
1708
+ readonly llm?: LanguageModel | WikiGraphLLMOptions;
1709
+ readonly verbose?: boolean;
1710
+ }
1711
+ type WikiGraphOpenSessionOptions = DigestDocumentSessionOptions;
1712
+ interface WikiGraphSourceSessionOptions extends DigestDocumentSessionOptions {
1713
+ readonly extractionPrompt?: string;
1714
+ readonly onProgress?: WikiGraphProgressCallback;
1715
+ readonly path: string;
1716
+ readonly targetStage?: ChapterStage;
1717
+ readonly userLanguage?: Language;
1718
+ }
1719
+ interface WikiGraphTextStreamSessionOptions extends DigestDocumentSessionOptions {
1720
+ readonly bookLanguage?: string | null;
1721
+ readonly extractionPrompt?: string;
1722
+ readonly onProgress?: WikiGraphProgressCallback;
1723
+ readonly sourceFormat?: "markdown" | "txt";
1724
+ readonly stream: AsyncIterable<string> | Iterable<string>;
1725
+ readonly targetStage?: ChapterStage;
1726
+ readonly title?: string | null;
1727
+ readonly userLanguage?: Language;
1728
+ }
1729
+ declare class WikiGraph {
1730
+ #private;
1731
+ constructor(options: WikiGraphOptions);
1732
+ digestEpubSession<T>(options: WikiGraphSourceSessionOptions, operation: (digest: WikiGraphArchive) => Promise<T> | T): Promise<T>;
1733
+ digestMarkdownSession<T>(options: WikiGraphSourceSessionOptions, operation: (digest: WikiGraphArchive) => Promise<T> | T): Promise<T>;
1734
+ digestTextStreamSession<T>(options: WikiGraphTextStreamSessionOptions, operation: (digest: WikiGraphArchive) => Promise<T> | T): Promise<T>;
1735
+ digestTxtSession<T>(options: WikiGraphSourceSessionOptions, operation: (digest: WikiGraphArchive) => Promise<T> | T): Promise<T>;
1736
+ openSession<T>(path: string, operation: (digest: WikiGraphArchive) => Promise<T> | T, options?: WikiGraphOpenSessionOptions): Promise<T>;
1737
+ }
1738
+
1739
+ interface GraphNode {
1740
+ readonly content: string;
1741
+ readonly id: number;
1742
+ readonly importance?: ChunkImportance;
1743
+ readonly label: string;
1744
+ readonly retention?: ChunkRetention;
1745
+ readonly sentenceIds: readonly SentenceId[];
1746
+ readonly weight: number;
1747
+ readonly wordsCount: number;
1748
+ }
1749
+ interface GraphEdge {
1750
+ readonly fromId: number;
1751
+ readonly strength?: string;
1752
+ readonly toId: number;
1753
+ readonly weight: number;
1754
+ }
1755
+ interface GraphEvidenceLine {
1756
+ readonly sentenceId: SentenceId;
1757
+ readonly text: string;
1758
+ }
1759
+ interface GraphStatus {
1760
+ readonly chapterId: number;
1761
+ readonly edgeCount: number;
1762
+ readonly graphReady: boolean;
1763
+ readonly nodeCount: number;
1764
+ }
1765
+ interface GraphSearchHit {
1766
+ readonly node: GraphNode;
1767
+ readonly matchedFields: readonly GraphSearchField[];
1768
+ }
1769
+ type GraphSearchField = "content" | "evidence" | "label";
1770
+ interface GraphNeighbor {
1771
+ readonly direction: "incoming" | "outgoing";
1772
+ readonly edge: GraphEdge;
1773
+ readonly node: GraphNode;
1774
+ }
1775
+ interface GraphPathStep {
1776
+ readonly edge?: GraphEdge;
1777
+ readonly node: GraphNode;
1778
+ }
1779
+ declare function getGraphStatus(document: ReadonlyDocument, chapterId: number): Promise<GraphStatus>;
1780
+ declare function listGraphNodes(document: ReadonlyDocument, chapterId: number): Promise<readonly GraphNode[]>;
1781
+ declare function getGraphNode(document: ReadonlyDocument, chapterId: number, nodeId: number): Promise<GraphNode>;
1782
+ declare function searchGraphNodes(document: ReadonlyDocument, chapterId: number, pattern: string): Promise<readonly GraphSearchHit[]>;
1783
+ declare function listGraphNeighbors(document: ReadonlyDocument, chapterId: number, nodeId: number): Promise<readonly GraphNeighbor[]>;
1784
+ declare function getGraphEvidence(document: ReadonlyDocument, chapterId: number, nodeId: number): Promise<readonly GraphEvidenceLine[]>;
1785
+ declare function findGraphPath(document: ReadonlyDocument, chapterId: number, fromNodeId: number, toNodeId: number): Promise<readonly GraphPathStep[]>;
1786
+
1787
+ declare const TEXT_SENTENCE_KIND: {
1788
+ readonly source: 1;
1789
+ readonly summary: 2;
1790
+ };
1791
+ type TextSentenceKind = (typeof TEXT_SENTENCE_KIND)[keyof typeof TEXT_SENTENCE_KIND];
1792
+ declare const SEARCH_OBJECT_PROPERTY_OWNER_KIND: {
1793
+ readonly chapter: 1;
1794
+ readonly chunk: 2;
1795
+ readonly entity: 3;
1796
+ };
1797
+ type SearchObjectPropertyOwnerKind = (typeof SEARCH_OBJECT_PROPERTY_OWNER_KIND)[keyof typeof SEARCH_OBJECT_PROPERTY_OWNER_KIND];
1798
+ declare const SEARCH_OBJECT_PROPERTY_KIND: {
1799
+ readonly title: 1;
1800
+ readonly label: 1;
1801
+ readonly content: 2;
1802
+ readonly surface: 1;
1803
+ };
1804
+ type SearchObjectPropertyKind = (typeof SEARCH_OBJECT_PROPERTY_KIND)[keyof typeof SEARCH_OBJECT_PROPERTY_KIND];
1805
+ interface TextSentenceRecordInput {
1806
+ readonly chapterId: number;
1807
+ readonly kind: TextSentenceKind;
1808
+ readonly sentenceIndex: number;
1809
+ readonly text: string;
1810
+ readonly wordsCount: number;
1811
+ }
1812
+ interface SearchObjectPropertyRecordInput {
1813
+ readonly chapterId?: number;
1814
+ readonly ownerId: string;
1815
+ readonly ownerKind: SearchObjectPropertyOwnerKind;
1816
+ readonly propertyKind: SearchObjectPropertyKind;
1817
+ readonly text: string;
1818
+ }
1819
+ interface SearchIndexInput {
1820
+ readonly objectProperties: readonly SearchObjectPropertyRecordInput[];
1821
+ readonly textSentences: readonly TextSentenceRecordInput[];
1822
+ }
1823
+ type SearchIndexProgressPhase = "checking" | "clearing" | "collecting" | "finalizing" | "indexing-objects" | "indexing-text";
1824
+ interface SearchIndexProgressEvent {
1825
+ readonly done?: number;
1826
+ readonly phase: SearchIndexProgressPhase;
1827
+ readonly total?: number;
1828
+ readonly unit?: "chapter" | "object" | "sentence";
1829
+ }
1830
+ type SearchIndexProgressReporter = (event: SearchIndexProgressEvent) => void | Promise<void>;
1831
+ type SearchIndexStatus = "current" | "dirty" | "missing";
1832
+ interface SearchIndexTextHit {
1833
+ readonly chapterId: number;
1834
+ readonly kind: TextSentenceKind;
1835
+ readonly rank: number;
1836
+ readonly score: number;
1837
+ readonly sentenceIndex: number;
1838
+ readonly wordsCount: number;
1839
+ }
1840
+ interface SearchIndexObjectHit {
1841
+ readonly chapterId?: number;
1842
+ readonly ownerId: string;
1843
+ readonly ownerKind: SearchObjectPropertyOwnerKind;
1844
+ readonly propertyKind: SearchObjectPropertyKind;
1845
+ readonly score: number;
1846
+ }
1847
+ interface SearchIndexQueryResult {
1848
+ readonly objectHits: readonly SearchIndexObjectHit[];
1849
+ readonly terms: readonly string[];
1850
+ readonly textHits: readonly SearchIndexTextHit[];
1851
+ }
1852
+ declare const SEARCH_INDEX_FTS_HIT_LIMIT = 32000;
1853
+ interface ArchiveIndexSettings {
1854
+ readonly ftsEmbedded: boolean;
1855
+ }
1856
+ declare function readArchiveIndexSettings(document: ReadonlyDocument): Promise<ArchiveIndexSettings>;
1857
+ declare function setFtsIndexEmbedded(document: Document, embedded: boolean): Promise<void>;
1858
+ declare function isSearchIndexCurrent(document: ReadonlyDocument, input?: SearchIndexInput): Promise<boolean>;
1859
+ declare function readSearchIndexStatus(document: ReadonlyDocument, input?: SearchIndexInput): Promise<SearchIndexStatus>;
1860
+ declare function ensureSearchIndex(document: Document, input: SearchIndexInput, progress?: SearchIndexProgressReporter): Promise<void>;
1861
+ declare function querySearchIndex(document: ReadonlyDocument, query: string, options?: {
1862
+ readonly chapters?: readonly number[];
1863
+ readonly match?: ArchiveFindMatch;
1864
+ readonly objectHitLimit?: number;
1865
+ readonly textAfter?: {
1866
+ readonly chapterId: number;
1867
+ readonly kind: TextSentenceKind;
1868
+ readonly rank: number;
1869
+ readonly sentenceIndex: number;
1870
+ };
1871
+ readonly textHitLimit?: number;
1872
+ readonly types?: readonly ArchiveFindObjectType[] | null;
1873
+ }): Promise<SearchIndexQueryResult | undefined>;
1874
+ declare function createSearchIndexFingerprint(input: SearchIndexInput): string;
1875
+ declare function readSearchIndexFingerprintFromDatabase(database: Database): Promise<string | undefined>;
1876
+
1877
+ type ArchiveObjectType = "chapter" | "chapter-title" | "chapter-tree" | "edge" | "entity" | "fragment" | "meta" | "node" | "source" | "state" | "summary" | "triple";
1878
+ type ChapterStateTarget = "knowledge-graph" | "reading-graph" | "reading-summary" | "source";
1879
+ type ChapterStateValue = "missing" | "ready";
1880
+ type ChapterState = Record<ChapterStateTarget, ChapterStateValue>;
1881
+ type ArchiveCollectionType = "chapter" | "chapter-title" | "entity" | "fragment" | "meta" | "node" | "source" | "summary" | "triple";
1882
+ type ArchiveFindObjectType = "chapter" | "chapter-title" | "chapter-tree" | "entity" | "fragment" | "meta" | "node" | "source" | "summary" | "triple";
1883
+ type ArchiveFindFilterType = "chapter" | "chapter-title" | "entity" | "fragment" | "meta" | "node" | "source" | "summary" | "triple";
1884
+ interface ArchiveIndex {
1885
+ readonly chapters: readonly ChapterEntry[];
1886
+ readonly edgeCount: number;
1887
+ readonly meta: BookMeta | undefined;
1888
+ readonly nodeCount: number;
1889
+ readonly summaryCount: number;
1890
+ }
1891
+ interface ArchiveFindHit {
1892
+ readonly backlinks?: ArchiveBacklinks;
1893
+ readonly chapter?: number;
1894
+ readonly evidence?: ArchiveFindEvidencePreview;
1895
+ readonly evidenceLinks?: readonly MentionLinkRecord[];
1896
+ readonly evidenceMentions?: readonly EntityEvidenceMention[];
1897
+ readonly field: ArchiveFindField;
1898
+ readonly id: string;
1899
+ readonly matchCount?: number;
1900
+ readonly matchedTerms?: readonly string[];
1901
+ readonly missingTerms?: readonly string[];
1902
+ readonly position?: ArchiveFindPosition;
1903
+ readonly score?: number;
1904
+ readonly snippet: string;
1905
+ readonly state?: ChapterState;
1906
+ readonly title: string;
1907
+ readonly triple?: {
1908
+ readonly objectLabel: string;
1909
+ readonly predicate: string;
1910
+ readonly subjectLabel: string;
1911
+ };
1912
+ readonly type: ArchiveFindObjectType;
1913
+ }
1914
+ interface EntityEvidenceMention {
1915
+ readonly match: Pick<ArchiveFindHit, "matchCount" | "matchedTerms" | "missingTerms" | "score">;
1916
+ readonly mention: MentionRecord;
1917
+ }
1918
+ interface ArchiveFindEvidencePreview {
1919
+ readonly nextCursor: string | null;
1920
+ readonly shown: number;
1921
+ readonly sources: readonly ArchiveEvidenceItem[];
1922
+ readonly total: number;
1923
+ }
1924
+ type ArchiveFindField = "content" | "metadata" | "source" | "summary" | "title";
1925
+ interface ArchiveFindOptions {
1926
+ readonly archiveKey?: string;
1927
+ readonly backlinks?: boolean;
1928
+ readonly chapters?: readonly number[];
1929
+ readonly cursor?: string;
1930
+ readonly evidenceLimit?: number;
1931
+ readonly ids?: readonly string[];
1932
+ readonly limit?: number;
1933
+ readonly match?: ArchiveFindMatch;
1934
+ readonly order?: ArchiveFindOrder;
1935
+ readonly sourceContext?: number;
1936
+ readonly triplePattern?: ArchiveTriplePattern;
1937
+ readonly types?: readonly ArchiveFindFilterType[];
1938
+ }
1939
+ type ArchiveFindOrder = "doc-asc" | "doc-desc";
1940
+ type ArchiveFindMatch = "all" | "any";
1941
+ interface ArchiveFindPosition {
1942
+ readonly chapter: number;
1943
+ readonly documentOrder?: number;
1944
+ readonly fragment?: number;
1945
+ readonly sentence?: number;
1946
+ }
1947
+ interface ArchiveFindResult {
1948
+ readonly chapters: readonly number[] | null;
1949
+ readonly items: readonly ArchiveFindHit[];
1950
+ readonly lens: ArchiveFindLens;
1951
+ readonly lensHint: ArchiveFindLensHint | null;
1952
+ readonly limit: number;
1953
+ readonly match: ArchiveFindMatch;
1954
+ readonly nextCursor: string | null;
1955
+ readonly order: ArchiveFindOrder;
1956
+ readonly query: string;
1957
+ readonly terms: readonly string[];
1958
+ readonly types: readonly ArchiveFindFilterType[] | null;
1959
+ }
1960
+ type ArchiveFindLens = "broad" | "exact" | "typed";
1961
+ interface ArchiveFindLensHint {
1962
+ readonly lenses: {
1963
+ readonly chapter: string;
1964
+ readonly chunk: string;
1965
+ readonly entity: string;
1966
+ readonly node: string;
1967
+ readonly triple: string;
1968
+ };
1969
+ readonly message: string;
1970
+ }
1971
+ interface ArchiveCollectionOptions {
1972
+ readonly backlinks?: boolean;
1973
+ readonly chapters?: readonly number[];
1974
+ readonly cursor?: string;
1975
+ readonly evidenceLimit?: number;
1976
+ readonly ids?: readonly string[];
1977
+ readonly limit?: number;
1978
+ readonly order?: ArchiveFindOrder;
1979
+ readonly sourceContext?: number;
1980
+ readonly triplePattern?: ArchiveTriplePattern;
1981
+ readonly types?: readonly ArchiveCollectionType[];
1982
+ }
1983
+ interface ArchiveTriplePattern {
1984
+ readonly objectQid?: string;
1985
+ readonly predicate?: string;
1986
+ readonly subjectQid?: string;
1987
+ }
1988
+ interface ArchiveCollectionResult {
1989
+ readonly chapters: readonly number[] | null;
1990
+ readonly ids: readonly string[] | null;
1991
+ readonly items: readonly ArchiveFindHit[];
1992
+ readonly limit: number;
1993
+ readonly nextCursor: string | null;
1994
+ readonly order: ArchiveFindOrder;
1995
+ readonly types: readonly ArchiveCollectionType[] | null;
1996
+ }
1997
+ interface ArchiveBacklinks {
1998
+ readonly chunks: ArchiveBacklinkBucket;
1999
+ readonly entities: ArchiveBacklinkBucket;
2000
+ readonly triples: ArchiveBacklinkBucket;
2001
+ }
2002
+ interface ArchiveBacklinkBucket {
2003
+ readonly items: readonly ArchiveFindHit[];
2004
+ readonly limit: number;
2005
+ readonly nextCursor: string | null;
2006
+ }
2007
+ type ArchiveListKind = "chapters" | "edges" | "fragments" | "meta" | "nodes" | "summaries";
2008
+ type ArchiveListItem = {
2009
+ readonly evidence?: ArchiveFindEvidencePreview;
2010
+ readonly id: string;
2011
+ readonly label: string;
2012
+ readonly score?: number;
2013
+ readonly state?: ChapterState;
2014
+ readonly summary: string;
2015
+ readonly type: Exclude<ArchiveObjectType, "triple">;
2016
+ } | {
2017
+ readonly evidence?: ArchiveFindEvidencePreview;
2018
+ readonly id: string;
2019
+ readonly label: string;
2020
+ readonly evidenceLinks?: readonly MentionLinkRecord[];
2021
+ readonly objectLabel: string;
2022
+ readonly objectQid: string;
2023
+ readonly predicate: string;
2024
+ readonly score?: number;
2025
+ readonly subjectLabel: string;
2026
+ readonly subjectQid: string;
2027
+ readonly summary: string;
2028
+ readonly type: "triple";
2029
+ };
2030
+ type ArchivePage = {
2031
+ readonly id: string;
2032
+ readonly state: ChapterState;
2033
+ readonly title: string;
2034
+ readonly type: "chapter";
2035
+ } | {
2036
+ readonly id: string;
2037
+ readonly title: string;
2038
+ readonly type: "chapter-title";
2039
+ } | {
2040
+ readonly id: string;
2041
+ readonly title: string;
2042
+ readonly tree: ChapterTree;
2043
+ readonly type: "chapter-tree";
2044
+ } | {
2045
+ readonly generatedNodeSummary: string;
2046
+ readonly id: string;
2047
+ readonly incoming: readonly GraphNeighbor[];
2048
+ readonly neighbors: readonly GraphNeighbor[];
2049
+ readonly outgoing: readonly GraphNeighbor[];
2050
+ readonly position: ArchiveFindPosition | undefined;
2051
+ readonly sourceFragments: readonly ArchiveNodeSourceFragment[];
2052
+ readonly title: string;
2053
+ readonly type: "node";
2054
+ } | {
2055
+ readonly backlinks?: ArchiveBacklinks;
2056
+ readonly fragment: ArchiveSourceFragment;
2057
+ readonly id: string;
2058
+ readonly nextFragmentId: string | undefined;
2059
+ readonly nodes: readonly ArchiveNodeLabel[];
2060
+ readonly previousFragmentId: string | undefined;
2061
+ readonly title: string;
2062
+ readonly type: "fragment";
2063
+ } | {
2064
+ readonly content: string;
2065
+ readonly id: string;
2066
+ readonly title: string;
2067
+ readonly type: "summary";
2068
+ } | {
2069
+ readonly evidence: ArchiveFindEvidencePreview;
2070
+ readonly id: string;
2071
+ readonly label: string;
2072
+ readonly labels: readonly string[];
2073
+ readonly mentionCount: number;
2074
+ readonly qid: string;
2075
+ readonly type: "entity";
2076
+ } | {
2077
+ readonly en: ArchiveEntityWikipageLocale | null;
2078
+ readonly id: string;
2079
+ readonly type: "entity-wikipage";
2080
+ readonly zh: ArchiveEntityWikipageLocale | null;
2081
+ } | {
2082
+ readonly evidence: ArchiveFindEvidencePreview;
2083
+ readonly id: string;
2084
+ readonly label: string;
2085
+ readonly objectQid: string;
2086
+ readonly predicate: string;
2087
+ readonly subjectQid: string;
2088
+ readonly type: "triple";
2089
+ } | {
2090
+ readonly authors?: readonly string[];
2091
+ readonly description?: string;
2092
+ readonly id: string;
2093
+ readonly publisher?: string;
2094
+ readonly title: string;
2095
+ readonly type: "meta";
2096
+ } | {
2097
+ readonly id: string;
2098
+ readonly state: ChapterState;
2099
+ readonly type: "state";
2100
+ } | {
2101
+ readonly id: string;
2102
+ readonly target: ChapterStateTarget;
2103
+ readonly type: "state";
2104
+ readonly value: ChapterStateValue;
2105
+ };
2106
+ interface ArchiveEntityWikipageLocale {
2107
+ readonly description?: string;
2108
+ readonly title: string;
2109
+ readonly url: string;
2110
+ }
2111
+ interface ArchivePack {
2112
+ readonly anchor: ArchivePage;
2113
+ readonly budget: number;
2114
+ readonly related: readonly ArchiveListItem[];
2115
+ }
2116
+ type ArchiveRelatedRole = "any" | "object" | "self" | "subject";
2117
+ interface ArchiveRelatedOptions {
2118
+ readonly cursor?: string;
2119
+ readonly evidenceLimit?: number;
2120
+ readonly limit?: number;
2121
+ readonly order?: ArchiveFindOrder;
2122
+ readonly query?: string;
2123
+ readonly role?: ArchiveRelatedRole;
2124
+ readonly sourceContext?: number;
2125
+ }
2126
+ interface ArchiveRelatedResult {
2127
+ readonly items: readonly ArchiveListItem[];
2128
+ readonly limit: number;
2129
+ readonly nextCursor: string | null;
2130
+ }
2131
+ interface ArchiveEvidence {
2132
+ readonly items: readonly ArchiveEvidenceItem[];
2133
+ readonly limit: number;
2134
+ readonly nextCursor: string | null;
2135
+ }
2136
+ interface ArchiveEvidenceItem {
2137
+ readonly chapterId: number;
2138
+ readonly endSentenceIndex: number;
2139
+ readonly fragmentId?: number;
2140
+ readonly id: string;
2141
+ readonly score?: number;
2142
+ readonly source: string;
2143
+ readonly startSentenceIndex: number;
2144
+ readonly title: string;
2145
+ readonly type: "source";
2146
+ }
2147
+ interface ArchiveNodeLabel {
2148
+ readonly id: string;
2149
+ readonly title: string;
2150
+ }
2151
+ interface ArchiveSourceFragment {
2152
+ readonly fragmentId?: number;
2153
+ readonly id: string;
2154
+ readonly preview: string;
2155
+ readonly sentenceCount: number;
2156
+ readonly text: string;
2157
+ readonly wordsCount: number;
2158
+ }
2159
+ interface ArchiveNodeSourceFragment {
2160
+ readonly id: string;
2161
+ readonly text: string;
2162
+ readonly truncated: boolean;
2163
+ }
2164
+ interface ArchiveEvidenceOptions {
2165
+ readonly cursor?: string;
2166
+ readonly limit?: number;
2167
+ readonly order?: ArchiveFindOrder;
2168
+ readonly query?: string;
2169
+ readonly sourceContext?: number;
2170
+ }
2171
+ interface ArchivePageOptions {
2172
+ readonly backlinks?: boolean;
2173
+ readonly evidenceLimit?: number;
2174
+ readonly order?: ArchiveFindOrder;
2175
+ readonly sourceContext?: number;
2176
+ readonly wikipageResolverOptions?: WikipageResolverOptions;
2177
+ }
2178
+ declare function getArchiveIndex(document: ReadonlyDocument): Promise<ArchiveIndex>;
2179
+ declare function listArchiveObjects(document: ReadonlyDocument, kind: ArchiveListKind): Promise<readonly ArchiveListItem[]>;
2180
+ declare function listArchiveCollection(document: ReadonlyDocument, options?: ArchiveCollectionOptions): Promise<ArchiveCollectionResult>;
2181
+ declare function findArchiveObjects(document: ReadonlyDocument, query: string, options?: ArchiveFindOptions): Promise<ArchiveFindResult>;
2182
+ declare function rebuildArchiveSearchIndex(document: Document, progress?: SearchIndexProgressReporter): Promise<void>;
2183
+ declare function isArchiveSearchIndexCurrent(document: ReadonlyDocument): Promise<boolean>;
2184
+ declare function readArchiveSearchIndexStatus(document: ReadonlyDocument): Promise<"current" | "dirty" | "missing">;
2185
+ declare function clearDirtyArchiveSearchIndex(document: Document): Promise<void>;
2186
+ declare function createArchiveSearchIndexFingerprint(document: ReadonlyDocument): Promise<string>;
2187
+ declare function grepArchiveObjects(document: ReadonlyDocument, query: string, options?: ArchiveFindOptions): Promise<ArchiveFindResult>;
2188
+ declare function readArchiveText(document: ReadonlyDocument, id: string): Promise<string>;
2189
+ declare function readArchivePage(document: ReadonlyDocument, id: string, options?: ArchivePageOptions): Promise<ArchivePage>;
2190
+ declare function listArchiveLinks(document: ReadonlyDocument, id: string, direction: "backlinks" | "links"): Promise<readonly GraphNeighbor[]>;
2191
+ declare function listAllArchiveLinks(document: ReadonlyDocument, id: string): Promise<readonly GraphNeighbor[]>;
2192
+ declare function listRelatedArchiveObjects(document: ReadonlyDocument, id: string, options?: ArchiveRelatedOptions): Promise<ArchiveRelatedResult>;
2193
+ declare function listArchiveEvidence(document: ReadonlyDocument, uri: string, options?: ArchiveEvidenceOptions): Promise<ArchiveEvidence>;
2194
+ declare function packArchiveContext(document: ReadonlyDocument, id: string, budget: number): Promise<ArchivePack>;
2195
+ declare function formatChapterId(chapterId: number): string;
2196
+ declare function formatEdgeId(edge: ReadingEdgeRecord): string;
2197
+ declare function formatNodeId(nodeId: number): string;
2198
+ declare function formatSummaryId(chapterId: number): string;
2199
+
2200
+ type ContinuationCursor = {
2201
+ readonly archiveKey: string;
2202
+ readonly archivePath: string;
2203
+ readonly backlinks?: boolean;
2204
+ readonly chapters: readonly number[] | null;
2205
+ readonly cursor: string;
2206
+ readonly evidenceLimit?: number;
2207
+ readonly format: "json" | "jsonl" | "text";
2208
+ readonly ids: readonly string[] | null;
2209
+ readonly kind: "collection";
2210
+ readonly order: "doc-asc" | "doc-desc";
2211
+ readonly sourceContext?: number;
2212
+ readonly triplePattern?: {
2213
+ readonly objectQid?: string;
2214
+ readonly predicate?: string;
2215
+ readonly subjectQid?: string;
2216
+ };
2217
+ readonly types: readonly string[] | null;
2218
+ } | {
2219
+ readonly archiveKey: string;
2220
+ readonly archivePath: string;
2221
+ readonly backlinks?: boolean;
2222
+ readonly cursor: string;
2223
+ readonly evidenceLimit?: number;
2224
+ readonly format: "json" | "jsonl" | "text";
2225
+ readonly kind: "search";
2226
+ readonly query?: string;
2227
+ readonly sourceContext?: number;
2228
+ readonly triplePattern?: {
2229
+ readonly objectQid?: string;
2230
+ readonly predicate?: string;
2231
+ readonly subjectQid?: string;
2232
+ };
2233
+ readonly types: readonly string[] | null;
2234
+ } | {
2235
+ readonly archiveKey: string;
2236
+ readonly archivePath: string;
2237
+ readonly cursor: string;
2238
+ readonly format: "json" | "jsonl" | "text";
2239
+ readonly kind: "evidence";
2240
+ readonly order: "doc-asc" | "doc-desc";
2241
+ readonly query?: string;
2242
+ readonly sourceContext?: number;
2243
+ readonly targetUri: string;
2244
+ } | {
2245
+ readonly archiveKey: string;
2246
+ readonly archivePath: string;
2247
+ readonly cursor: string;
2248
+ readonly evidenceLimit?: number;
2249
+ readonly format: "json" | "jsonl" | "text";
2250
+ readonly kind: "related";
2251
+ readonly order: "doc-asc" | "doc-desc";
2252
+ readonly query?: string;
2253
+ readonly role?: "any" | "object" | "self" | "subject";
2254
+ readonly sourceContext?: number;
2255
+ readonly targetUri: string;
2256
+ };
2257
+ declare function createContinuationCursor(input: ContinuationCursor): Promise<string>;
2258
+ declare function readContinuationCursor(cursorId: string): Promise<ContinuationCursor>;
2259
+
2260
+ interface SearchSessionInput {
2261
+ readonly archiveKey: string;
2262
+ readonly chapters: readonly number[] | null;
2263
+ readonly chunkHits?: readonly SearchChunkHitInput[];
2264
+ readonly entityHits?: readonly SearchEntityHitInput[];
2265
+ readonly evidenceEvents?: readonly SearchEvidenceHitEventInput[];
2266
+ readonly items?: readonly ArchiveFindHit[];
2267
+ readonly lens: string;
2268
+ readonly match: string;
2269
+ readonly order: string;
2270
+ readonly query: string;
2271
+ readonly revisionScope: string;
2272
+ readonly terms: readonly string[];
2273
+ readonly tripleHits?: readonly SearchTripleHitInput[];
2274
+ readonly types: readonly string[] | null;
2275
+ }
2276
+ declare const SEARCH_EVIDENCE_KIND: {
2277
+ readonly mention: 1;
2278
+ readonly mentionLink: 2;
2279
+ readonly chunk: 3;
2280
+ };
2281
+ type SearchEvidenceKind = (typeof SEARCH_EVIDENCE_KIND)[keyof typeof SEARCH_EVIDENCE_KIND];
2282
+ interface SearchEvidenceHitEventInput {
2283
+ readonly chapterId: number;
2284
+ readonly evidenceId: string;
2285
+ readonly evidenceKind: SearchEvidenceKind;
2286
+ readonly score: number;
2287
+ readonly sentenceIndex: number;
2288
+ }
2289
+ interface SearchEntityHitInput {
2290
+ readonly evidenceTopScores?: readonly number[];
2291
+ readonly propertyTopScores?: readonly number[];
2292
+ readonly qid: string;
2293
+ }
2294
+ interface SearchTripleHitInput {
2295
+ readonly evidenceTopScores: readonly number[];
2296
+ readonly objectQid: string;
2297
+ readonly predicate: string;
2298
+ readonly subjectQid: string;
2299
+ }
2300
+ interface SearchChunkHitInput {
2301
+ readonly chunkId: number;
2302
+ readonly evidenceTopScores?: readonly number[];
2303
+ readonly propertyTopScores?: readonly number[];
2304
+ }
2305
+ interface SearchSessionPage {
2306
+ readonly chapters: readonly number[] | null;
2307
+ readonly items: readonly ArchiveFindHit[];
2308
+ readonly lens: string;
2309
+ readonly match: string;
2310
+ readonly nextCursor: string | null;
2311
+ readonly query: string;
2312
+ readonly sessionId: string;
2313
+ readonly terms: readonly string[];
2314
+ readonly types: readonly string[] | null;
2315
+ }
2316
+ interface SearchSessionDescriptor {
2317
+ readonly chapters: readonly number[] | null;
2318
+ readonly createdAt: number;
2319
+ readonly lens: string;
2320
+ readonly match: string;
2321
+ readonly objectCachesPopulated: boolean;
2322
+ readonly query: string;
2323
+ readonly sessionId: string;
2324
+ readonly terms: readonly string[];
2325
+ readonly types: readonly string[] | null;
2326
+ }
2327
+ type SearchSessionCacheInput = Omit<SearchSessionInput, "items">;
2328
+ declare function readCachedSearchSessionPage(input: SearchSessionCacheInput, offset: number, limit: number): Promise<SearchSessionPage | undefined>;
2329
+ declare function createSearchSession(input: SearchSessionInput): Promise<string>;
2330
+ declare function deleteArchiveSearchSessions(archiveKey: string): Promise<void>;
2331
+ declare function runSearchCacheGc(context: GcContext): Promise<GcJobResult>;
2332
+
2333
+ interface ChapterGraphBuildArtifact {
2334
+ readonly documentPath: string;
2335
+ readonly chapterId: number;
2336
+ readonly parameter: GraphBuildParameterInput$1;
2337
+ }
2338
+ interface GraphBuildParameterInput$1 {
2339
+ readonly language?: string;
2340
+ readonly prompt: string;
2341
+ }
2342
+ interface ChapterSummaryInputSnapshot {
2343
+ readonly filePath: string;
2344
+ }
2345
+ interface BuildChapterGraphArtifactOptions extends GenerateChapterGraphOptions {
2346
+ readonly sourceText: readonly string[];
2347
+ readonly workspacePath: string;
2348
+ }
2349
+ interface BuildChapterSummaryArtifactOptions extends GenerateChapterSummaryOptions {
2350
+ readonly snapshotPath?: string;
2351
+ readonly sourceDocumentPath?: string;
2352
+ readonly workspacePath: string;
2353
+ }
2354
+ declare function readChapterBuildInput(document: ReadonlyDocument, chapterId: number): Promise<{
2355
+ readonly details: ChapterDetails;
2356
+ readonly revision: number;
2357
+ readonly sourceText: readonly string[];
2358
+ }>;
2359
+ declare function buildChapterGraphArtifact(chapterId: number, options: BuildChapterGraphArtifactOptions): Promise<ChapterGraphBuildArtifact>;
2360
+ declare function commitChapterGraphArtifact(document: Document, artifact: ChapterGraphBuildArtifact): Promise<ChapterDetails>;
2361
+ declare function buildChapterSummaryArtifact(document: ReadonlyDocument, chapterId: number, options: BuildChapterSummaryArtifactOptions): Promise<string>;
2362
+ declare function buildChapterSummaryArtifactFromSnapshot(chapterId: number, options: BuildChapterSummaryArtifactOptions & {
2363
+ readonly snapshotPath: string;
2364
+ }): Promise<string>;
2365
+ declare function commitChapterSummaryArtifact(document: Document, chapterId: number, summary: string): Promise<ChapterDetails>;
2366
+ declare function snapshotChapterSummaryInput(document: ReadonlyDocument, chapterId: number, workspacePath: string): Promise<ChapterSummaryInputSnapshot>;
2367
+
2368
+ interface ChapterKnowledgeGraphBuildArtifact {
2369
+ readonly chapterId: number;
2370
+ readonly mentionLinksPath: string;
2371
+ readonly mentionsPath: string;
2372
+ readonly parameter: GraphBuildParameterInput;
2373
+ readonly workspacePath: string;
2374
+ }
2375
+ interface ChapterKnowledgeGraphInputSnapshot {
2376
+ readonly details: ChapterDetails;
2377
+ readonly fragments: readonly FragmentRecord[];
2378
+ }
2379
+ interface GraphBuildParameterInput {
2380
+ readonly language?: string;
2381
+ readonly prompt: string;
2382
+ }
2383
+ interface BuildChapterKnowledgeGraphArtifactOptions {
2384
+ readonly mentionLinks: AsyncIterable<MentionLinkRecord> | Iterable<MentionLinkRecord>;
2385
+ readonly mentions: AsyncIterable<MentionRecord> | Iterable<MentionRecord>;
2386
+ readonly parameter?: GraphBuildParameterInput;
2387
+ readonly workspacePath: string;
2388
+ }
2389
+ interface GenerateChapterKnowledgeGraphArtifactOptions {
2390
+ readonly policyPrompt: string;
2391
+ readonly progressTracker?: Pick<BuildJobProgressReporter, "throwIfStopped" | "updatePhase">;
2392
+ readonly request: GuaranteedRequestController;
2393
+ readonly resolverOptions?: Omit<WikipageResolverOptions, "progress">;
2394
+ readonly wikispine?: Pick<MatchWikispineSentenceCandidatesOptions, "command" | "dataDir" | "endpoint" | "provider">;
2395
+ readonly workspacePath: string;
2396
+ }
2397
+ declare function generateChapterKnowledgeGraphArtifact(document: ReadonlyDocument, chapterId: number, options: GenerateChapterKnowledgeGraphArtifactOptions): Promise<ChapterKnowledgeGraphBuildArtifact>;
2398
+ declare function snapshotChapterKnowledgeGraphInput(document: ReadonlyDocument, chapterId: number): Promise<ChapterKnowledgeGraphInputSnapshot>;
2399
+ declare function generateChapterKnowledgeGraphArtifactFromSnapshot(chapterId: number, snapshot: ChapterKnowledgeGraphInputSnapshot, options: GenerateChapterKnowledgeGraphArtifactOptions): Promise<ChapterKnowledgeGraphBuildArtifact>;
2400
+ declare function buildChapterKnowledgeGraphArtifact(chapterId: number, options: BuildChapterKnowledgeGraphArtifactOptions): Promise<ChapterKnowledgeGraphBuildArtifact>;
2401
+ declare function groundWikimatchCandidates(input: {
2402
+ readonly candidates: readonly WikimatchCandidate[];
2403
+ readonly policyPrompt: string;
2404
+ readonly progressTracker?: Pick<BuildJobProgressReporter, "throwIfStopped" | "updatePhase">;
2405
+ readonly request: GuaranteedRequestController;
2406
+ readonly text: string;
2407
+ }): Promise<readonly WikimatchAcceptedMention[]>;
2408
+ declare function createEnrichmentProgressReporter(progressTracker: Pick<BuildJobProgressReporter, "throwIfStopped" | "updatePhase">): (event: WikipageResolveProgress) => Promise<void>;
2409
+ declare function commitChapterKnowledgeGraphArtifact(document: Document, artifact: ChapterKnowledgeGraphBuildArtifact): Promise<void>;
2410
+ declare function clearChapterKnowledgeGraph(document: Document, chapterId: number): Promise<void>;
2411
+
2412
+ declare function writeWikgArchive(documentDirectoryPath: string, outputPath: string): Promise<void>;
2413
+ declare function readWikgArchiveFormatVersion(documentDirectoryPath: string): Promise<number>;
2414
+
2415
+ declare const WIKI_GRAPH_URI_PREFIX = "wikg://";
2416
+ declare const WIKI_GRAPH_JOB_URI_PREFIX = "wikg://local/job";
2417
+ interface LocatedWikiGraphUri {
2418
+ readonly archivePath?: string;
2419
+ readonly objectUri?: string;
2420
+ }
2421
+ declare function isWikiGraphUri(value: string | undefined): value is string;
2422
+ declare function isWikiGraphJobUri(value: string | undefined): value is string;
2423
+ declare function parseLocatedWikiGraphUri(uri: string): LocatedWikiGraphUri;
2424
+ declare function formatLocatedWikiGraphUri(archivePath: string, objectUri?: string): string;
2425
+ declare function formatWikiGraphCommandUri(archivePath: string, objectUri?: string, cwd?: string): string;
2426
+ declare function formatLocatedChapterUri(archivePath: string, chapterId: number): string;
2427
+ declare function formatLocatedChapterResourceUri(archivePath: string, chapterId: number, resource: "source" | "summary" | "title"): string;
2428
+ declare function formatLocatedChapterSourceCollectionUri(archivePath: string, chapterId: number): string;
2429
+ declare function requireArchiveUri(uri: string): string;
2430
+ declare function requireLocatedObjectUri(uri: string): {
2431
+ readonly archivePath: string;
2432
+ readonly objectUri: string;
2433
+ };
2434
+ declare function requireLocatedObjectOrArchiveUri(uri: string): {
2435
+ readonly archivePath: string;
2436
+ readonly objectUri?: string;
2437
+ };
2438
+
2439
+ declare class WikiGraphArchiveFile {
2440
+ #private;
2441
+ constructor(path: string);
2442
+ read<T>(operation: (digest: WikiGraphArchive) => Promise<T> | T, options?: {
2443
+ readonly documentDirPath?: string;
2444
+ }): Promise<T>;
2445
+ readDocument<T>(operation: (document: DirectoryDocument, directoryPath: string) => Promise<T> | T, options?: {
2446
+ readonly documentDirPath?: string;
2447
+ readonly searchIndexWritebackPolicy?: "archive" | "cache";
2448
+ }): Promise<T>;
2449
+ write<T>(operation: (document: DirectoryDocument) => Promise<T> | T, options?: {
2450
+ readonly searchIndexWritebackPolicy?: "archive" | "cache";
2451
+ }): Promise<T>;
2452
+ }
2453
+
2454
+ interface LegacySdpubMigrationResult {
2455
+ readonly inputPath: string;
2456
+ readonly outputPath: string;
2457
+ }
2458
+ declare function migrateLegacySdpubToWikg(inputPath: string, outputPath?: string): Promise<LegacySdpubMigrationResult>;
2459
+
2460
+ declare function formatError(error: unknown): string;
2461
+
2462
+ export { type AddChapterOptions, type AdvanceChapterStagesOptions, type AdvanceChapterStagesProgressCallback, type AdvanceChapterStagesProgressEvent, type AdvanceChapterStagesResult, type ArchiveBacklinkBucket, type ArchiveBacklinks, type ArchiveCollectionOptions, type ArchiveCollectionResult, type ArchiveCollectionType, type ArchiveEvidence, type ArchiveEvidenceItem, type ArchiveFindEvidencePreview, type ArchiveFindField, type ArchiveFindFilterType, type ArchiveFindHit, type ArchiveFindObjectType, type ArchiveFindOptions, type ArchiveFindOrder, type ArchiveFindPosition, type ArchiveFindResult, type ArchiveIndex, type ArchiveIndexSettings, type ArchiveListItem, type ArchiveListKind, type ArchiveNodeLabel, type ArchiveNodeSourceFragment, type ArchiveObjectType, type ArchivePack, type ArchivePage, type ArchiveRelatedResult, type ArchiveTriplePattern, type BookMeta, type BuildChapterGraphArtifactOptions, type BuildChapterKnowledgeGraphArtifactOptions, type BuildChapterSummaryArtifactOptions, BuildJobProgressReporter, type BuildWikimatchSurfaceProtectionInputOptions, type BuildWikimatchWindowsOptions, CHAPTER_STAGES, CLI_FULL_COMMAND, CLI_PRIMARY_COMMAND, type CachedDisambiguationRecord, type CachedPageRecord, type CachedQidRecord, type ChapterDetails, type ChapterEntry, type ChapterGraphBuildArtifact, type ChapterKnowledgeGraphBuildArtifact, type ChapterKnowledgeGraphInputSnapshot, type ChapterStage, type ChapterTree, type ChapterTreeApplyResult, type ChapterTreeInput, type ChapterTreeInputNode, type ChapterTreeMoveChange, type ChapterTreeNode, type ChapterTreeTitleChange, ChunkImportance, type ChunkRecord, ChunkRetention, ChunkStore, type ContinuationCursor, type CreateSnakeRecord, DEFAULT_WIKISPINE_FETCH_ENDPOINT, Database, type DigestProgressEvent, DirectoryDocument, type DisambiguationExpansion, type DisambiguationLinkedQid, type DisambiguationMeaningPriority, type DisambiguationPageText, type DisambiguationProfile, type DisambiguationProfileMeaning, type DisambiguationProfileNormalizer, type DisambiguationProfileNormalizerInput, type Document, type DocumentContext, EVIDENCE_SELECTION_JSON_SHAPE, EVIDENCE_SELECTION_PROMPT_FRAGMENT, type EvidenceQuoteMatchStrategy, type EvidenceQuoteScore, type EvidenceSelection, type EvidenceSelectionCandidate, type EvidenceSelectionFailure, type EvidenceSelectionList, type EvidenceSelectionResolution, type EvidenceSelectionSentence, type EvidenceSentenceId, FragmentDraft, FragmentGroupStore, type FragmentRecord, Fragments, type GenerateChapterGraphOptions, type GenerateChapterSummaryOptions, type GraphBuildParameterRecord, GraphBuildParameterStore, type GraphEdge, type GraphEvidenceLine, type GraphNeighbor, type GraphNode, type GraphPathStep, type GraphSearchField, type GraphSearchHit, type GraphStatus, type GuaranteedRequest, type GuaranteedRequestController, type JudgeWikimatchPolicyOptions, type JudgeWikimatchSurfaceProtectionOptions, LLM, type LLMOptions, LLMPaymentRequiredError, type LLMRequestOptions, type LLMStreamProgressCallback, type LLMTokenUsage, type LLMTokenUsageCallback, type LLMessage, Language, LanguageCode, type LocatedWikiGraphUri, type MatchWikispineSentenceCandidatesOptions, type MentionLinkRecord, MentionLinkStore, type MentionRecord, MentionStore, type MoveChapterOptions, type NarrowWikimatchCandidateOptionsInput, type NarrowWikimatchCandidateOptionsOptions, ObjectMetadataKind, ObjectMetadataStore, type ObjectMetadataTarget, type QidResolution, RateLimiter, type ReadingEdgeRecord, ReadingEdgeStore, type ReadonlyChunkStore, type ReadonlyDocument, type ReadonlyFragmentGroupStore, type ReadonlyTextStreams as ReadonlyFragments, type ReadonlyGraphBuildParameterStore, type ReadonlyMentionLinkStore, type ReadonlyMentionStore, type ReadonlyObjectMetadataStore, type ReadonlyReadingEdgeStore, type ReadonlySerialTextStream as ReadonlySerialFragments, type ReadonlySerialStore, type ReadonlySerialTextStream, type ReadonlySnakeChunkStore, type ReadonlySnakeEdgeStore, type ReadonlySnakeStore, type ReadonlyTextStreams, SCHEMA_SQL, SEARCH_INDEX_FTS_HIT_LIMIT, SEARCH_OBJECT_PROPERTY_KIND, SEARCH_OBJECT_PROPERTY_OWNER_KIND, type SearchIndexInput, type SearchIndexObjectHit, type SearchIndexProgressEvent, type SearchIndexProgressPhase, type SearchIndexProgressReporter, type SearchIndexQueryResult, type SearchIndexStatus, type SearchIndexTextHit, type SearchObjectPropertyKind, type SearchObjectPropertyOwnerKind, type SearchSessionDescriptor, type SearchSessionInput, type SearchSessionPage, type SentenceGroupRecord, type SentenceId, type SentenceRecord, type SerialDiscoveryItem, SerialFragments, type SerialProgressEvent, type SerialRecord, SerialStore, SerialTextStream, type SerialsDiscoveredEvent, type SnakeChunkRecord, SnakeChunkStore, type SnakeEdgeRecord, SnakeEdgeStore, type SnakeRecord, SnakeStore, TEXT_SENTENCE_KIND, TOC_FILE_VERSION, type TestWikispineRuntimeOptions, type TextSentenceKind, TextStreams, WIKI_GRAPH_CONTEXT_VERSION, WIKI_GRAPH_EDITOR_SCOPES, WIKI_GRAPH_JOB_URI_PREFIX, WIKI_GRAPH_READER_SCOPES, WIKI_GRAPH_SCOPES, WIKI_GRAPH_URI_PREFIX, WikiGraph, WikiGraphArchive, WikiGraphArchiveFile, type WikiGraphLLMOptions, type WikiGraphOpenSessionOptions, type WikiGraphOperation, type WikiGraphOptions, type WikiGraphProgressCallback, type WikiGraphProgressEvent, type WikiGraphProgressEventType, WikiGraphScope, type WikiGraphSerialEntry, type WikiGraphSourceSessionOptions, WikiGraphTask, WikiGraphTaskContext, type WikiGraphTaskContextOptions, type WikiGraphTaskIdentity, type WikiGraphTaskType, type WikiGraphTextStreamSessionOptions, type WikimatchAcceptedMention, type WikimatchCandidate, type WikimatchCandidateOptionNarrowingFallback, type WikimatchCandidateOptionNarrowingItemOutput, type WikimatchCandidateOptionNarrowingResponse, type WikimatchCandidateOptionNarrowingResult, type WikimatchConflictGroup, type WikimatchPolicyContinuation, type WikimatchPolicyDecision, type WikimatchPolicyDecisionOutput, type WikimatchPolicyFallback, type WikimatchPolicyJudgeInput, type WikimatchPolicyJudgeResult, type WikimatchPolicyResponse, type WikimatchPolicyUpdate, type WikimatchProtectedSurface, type WikimatchQidOption, type WikimatchSentence, type WikimatchSurface, type WikimatchSurfaceProtectionBuildResult, type WikimatchSurfaceProtectionFallback, type WikimatchSurfaceProtectionInput, type WikimatchSurfaceProtectionResponse, type WikimatchSurfaceProtectionResult, type WikimatchTextRange, type WikimatchWindow, WikimediaClient, WikipageCache, WikipageResolver, type WikipageResolverOptions, type WikipageSitelink, type WikispineProvider, type WikispineRuntimeTestResult, addChapter, advanceChapterStages, applyChapterTree, applyQidResolutions, buildChapterGraphArtifact, buildChapterKnowledgeGraphArtifact, buildChapterSummaryArtifact, buildChapterSummaryArtifactFromSnapshot, buildWikimatchSurfaceProtectionInput, buildWikimatchWindows, clearChapterKnowledgeGraph, clearDirtyArchiveSearchIndex, commitChapterGraphArtifact, commitChapterKnowledgeGraphArtifact, commitChapterSummaryArtifact, countWikimatchCandidateOptions, countWikimatchQidOption, createArchiveSearchIndexFingerprint, createContinuationCursor, createDefaultWikiGraphSampling, createDisambiguationProfileNormalizer, createEnrichmentProgressReporter, createEnv, createSearchIndexFingerprint, createSearchSession, createWikiGraphTaskId, createWikiGraphTempDirectory, deleteArchiveSearchSessions, enrichWikimatchCandidates, ensureSearchIndex, ensureSharedStateDatabaseInitialized, expandRangeByWords, expectChunkImportance, expectChunkRetention, filterCandidateQidOptions, findArchiveObjects, findGraphPath, formatCandidateForPrompt, formatChapterId, formatEdgeId, formatError, formatEvidenceSelectionChoicePrompt, formatLanguageForPrompt, formatLocatedChapterResourceUri, formatLocatedChapterSourceCollectionUri, formatLocatedChapterUri, formatLocatedWikiGraphUri, formatNodeId, formatSummaryId, formatWikiGraphCommandUri, generateChapterGraph, generateChapterKnowledgeGraphArtifact, generateChapterKnowledgeGraphArtifactFromSnapshot, generateChapterSummary, getArchiveIndex, getChapterDetails, getChapterTree, getGraphEvidence, getGraphNode, getGraphStatus, getLanguageCode, getWikipageLanguageCode, grepArchiveObjects, groundWikimatchCandidates, isArchiveSearchIndexCurrent, isChunkImportance, isChunkRetention, isSearchIndexCurrent, isWikiGraphJobUri, isWikiGraphUri, judgeWikimatchPolicy, judgeWikimatchSurfaceProtection, listAllArchiveLinks, listArchiveCollection, listArchiveEvidence, listArchiveLinks, listArchiveObjects, listCandidateSelectableQids, listChapters, listGraphNeighbors, listGraphNodes, listRelatedArchiveObjects, listWordBoundaries, matchWikispineSentenceCandidates, migrateLegacySdpubToWikg, moveChapter, narrowWikimatchCandidateOptions, normalizeEvidenceDisplayText, normalizeEvidenceText, normalizeLanguageCode, openSharedStateDatabase, packArchiveContext, parseChapterTreeInput, parseLocatedWikiGraphUri, parseNarrowingResponse, parsePolicyResponse, parseRetryAfterMs, parseSurfaceProtectionResponse, querySearchIndex, rankEvidenceQuote, readArchiveIndexSettings, readArchivePage, readArchiveSearchIndexStatus, readArchiveText, readCachedSearchSessionPage, readChapterBuildInput, readContinuationCursor, readSearchIndexFingerprintFromDatabase, readSearchIndexStatus, readWikgArchiveFormatVersion, rebuildArchiveSearchIndex, removeChapter, requireArchiveUri, requireLocatedObjectOrArchiveUri, requireLocatedObjectUri, resetChapter, resolveDataDirPath, resolveEvidenceSelection, resolveEvidenceSelectionList, resolveWikiGraphCoreDatabasePath, resolveWikiGraphHomeDirectoryPath, resolveWikiGraphStateRootPath, runSearchCacheGc, scoreEvidenceQuote, searchGraphNodes, setChapterSource, setChapterSummary, setChapterTitle, setFtsIndexEmbedded, sliceCandidateByOptionBudget, snapshotChapterKnowledgeGraphInput, snapshotChapterSummaryInput, splitCandidateByOptionBudget, suppressContainedRanges, testWikispineRuntime, validateNarrowingResponse, validatePolicyResponse, validateSurfaceProtectionResponse, withLoggingContext, writeWikgArchive };