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.
- package/LICENSE +201 -0
- package/data/editor/clue_reviewer.jinja +410 -0
- package/data/editor/clue_reviewer_generator.jinja +428 -0
- package/data/editor/revision_feedback.jinja +5 -0
- package/data/editor/text_compressor.jinja +127 -0
- package/data/guaranteed/response_intent_classifier.jinja +8 -0
- package/data/help/commands/archive/next.jinja +29 -0
- package/data/help/commands/gc.jinja +38 -0
- package/data/help/commands/legacy/migrate.jinja +20 -0
- package/data/help/commands/legacy.jinja +19 -0
- package/data/help/commands/maintenance/chapter/add.jinja +41 -0
- package/data/help/commands/maintenance/chapter/list.jinja +33 -0
- package/data/help/commands/maintenance/chapter/move.jinja +36 -0
- package/data/help/commands/maintenance/chapter/remove.jinja +26 -0
- package/data/help/commands/maintenance/chapter/reset.jinja +29 -0
- package/data/help/commands/maintenance/chapter/set-source.jinja +34 -0
- package/data/help/commands/maintenance/chapter/set-summary.jinja +31 -0
- package/data/help/commands/maintenance/chapter/set-title.jinja +29 -0
- package/data/help/commands/maintenance/chapter/tree.jinja +58 -0
- package/data/help/commands/maintenance/chapter.jinja +59 -0
- package/data/help/commands/maintenance/cover.jinja +28 -0
- package/data/help/commands/maintenance/meta.jinja +55 -0
- package/data/help/commands/predicate.jinja +460 -0
- package/data/help/commands/root.jinja +83 -0
- package/data/help/commands/transform.jinja +34 -0
- package/data/help/commands/uri.jinja +274 -0
- package/data/help/topics/config.jinja +88 -0
- package/data/help/topics/format.jinja +72 -0
- package/data/help/topics/readiness.jinja +99 -0
- package/data/help/topics/recipe.jinja +151 -0
- package/data/help/topics/runtime.jinja +62 -0
- package/data/help/topics/uri.jinja +178 -0
- package/data/output/epub/cover.xhtml.jinja +13 -0
- package/data/output/epub/nav.xhtml.jinja +12 -0
- package/data/output/epub/package.opf.xml.jinja +39 -0
- package/data/output/epub/section.xhtml.jinja +12 -0
- package/data/topologization/book_coherence_extraction.jinja +223 -0
- package/data/topologization/chunk_extraction.jinja +233 -0
- package/data/topologization/evidence_choice.jinja +38 -0
- package/data/topologization/translate_chunks.jinja +138 -0
- package/data/topologization/user_focused_extraction.jinja +378 -0
- package/dist/archive/query/archive-view.d.ts +26 -0
- package/dist/archive/query/archive-view.js +4540 -0
- package/dist/archive/query/archive-view.js.map +1 -0
- package/dist/archive/query/continuation-cursor.d.ts +61 -0
- package/dist/archive/query/continuation-cursor.js +363 -0
- package/dist/archive/query/continuation-cursor.js.map +1 -0
- package/dist/archive/query/index.d.ts +29 -0
- package/dist/archive/query/index.js +63 -0
- package/dist/archive/query/index.js.map +1 -0
- package/dist/archive/query/lexical-search.d.ts +22 -0
- package/dist/archive/query/lexical-search.js +137 -0
- package/dist/archive/query/lexical-search.js.map +1 -0
- package/dist/archive/query/search-cache.d.ts +192 -0
- package/dist/archive/query/search-cache.js +1248 -0
- package/dist/archive/query/search-cache.js.map +1 -0
- package/dist/archive/search-index/index.d.ts +26 -0
- package/dist/archive/search-index/index.js +29 -0
- package/dist/archive/search-index/index.js.map +1 -0
- package/dist/archive/search-index/search-index.d.ts +26 -0
- package/dist/archive/search-index/search-index.js +555 -0
- package/dist/archive/search-index/search-index.js.map +1 -0
- package/dist/archive/search-index/search-tokenizer.d.ts +16 -0
- package/dist/archive/search-index/search-tokenizer.js +225 -0
- package/dist/archive/search-index/search-tokenizer.js.map +1 -0
- package/dist/common/cli-command.d.ts +4 -0
- package/dist/common/cli-command.js +7 -0
- package/dist/common/cli-command.js.map +1 -0
- package/dist/common/data-dir.d.ts +3 -0
- package/dist/common/data-dir.js +48 -0
- package/dist/common/data-dir.js.map +1 -0
- package/dist/common/language.d.ts +55 -0
- package/dist/common/language.js +208 -0
- package/dist/common/language.js.map +1 -0
- package/dist/common/llm-scope.d.ts +19 -0
- package/dist/common/llm-scope.js +31 -0
- package/dist/common/llm-scope.js.map +1 -0
- package/dist/common/logging.d.ts +22 -0
- package/dist/common/logging.js +141 -0
- package/dist/common/logging.js.map +1 -0
- package/dist/common/template.d.ts +8 -0
- package/dist/common/template.js +54 -0
- package/dist/common/template.js.map +1 -0
- package/dist/common/tinyld-language.d.ts +6 -0
- package/dist/common/tinyld-language.js +34 -0
- package/dist/common/tinyld-language.js.map +1 -0
- package/dist/common/wiki-graph-dir.d.ts +10 -0
- package/dist/common/wiki-graph-dir.js +41 -0
- package/dist/common/wiki-graph-dir.js.map +1 -0
- package/dist/common/wiki-graph-temp.d.ts +6 -0
- package/dist/common/wiki-graph-temp.js +21 -0
- package/dist/common/wiki-graph-temp.js.map +1 -0
- package/dist/common/wiki-graph-uri.d.ts +28 -0
- package/dist/common/wiki-graph-uri.js +171 -0
- package/dist/common/wiki-graph-uri.js.map +1 -0
- package/dist/context/index.d.ts +1 -0
- package/dist/context/index.js +13 -0
- package/dist/context/index.js.map +1 -0
- package/dist/context/task-context.d.ts +41 -0
- package/dist/context/task-context.js +111 -0
- package/dist/context/task-context.js.map +1 -0
- package/dist/document/database.d.ts +30 -0
- package/dist/document/database.js +273 -0
- package/dist/document/database.js.map +1 -0
- package/dist/document/document.d.ts +153 -0
- package/dist/document/document.js +615 -0
- package/dist/document/document.js.map +1 -0
- package/dist/document/fragments.d.ts +63 -0
- package/dist/document/fragments.js +371 -0
- package/dist/document/fragments.js.map +1 -0
- package/dist/document/index.d.ts +13 -0
- package/dist/document/index.js +62 -0
- package/dist/document/index.js.map +1 -0
- package/dist/document/schema.d.ts +8 -0
- package/dist/document/schema.js +472 -0
- package/dist/document/schema.js.map +1 -0
- package/dist/document/shared-state-database.d.ts +9 -0
- package/dist/document/shared-state-database.js +193 -0
- package/dist/document/shared-state-database.js.map +1 -0
- package/dist/document/stores.d.ts +203 -0
- package/dist/document/stores.js +1678 -0
- package/dist/document/stores.js.map +1 -0
- package/dist/document/text-streams.d.ts +86 -0
- package/dist/document/text-streams.js +515 -0
- package/dist/document/text-streams.js.map +1 -0
- package/dist/document/types.d.ts +148 -0
- package/dist/document/types.js +69 -0
- package/dist/document/types.js.map +1 -0
- package/dist/editor/clue.d.ts +27 -0
- package/dist/editor/clue.js +158 -0
- package/dist/editor/clue.js.map +1 -0
- package/dist/editor/compressor.d.ts +18 -0
- package/dist/editor/compressor.js +68 -0
- package/dist/editor/compressor.js.map +1 -0
- package/dist/editor/editor.d.ts +39 -0
- package/dist/editor/editor.js +253 -0
- package/dist/editor/editor.js.map +1 -0
- package/dist/editor/feedback.d.ts +16 -0
- package/dist/editor/feedback.js +104 -0
- package/dist/editor/feedback.js.map +1 -0
- package/dist/editor/index.d.ts +17 -0
- package/dist/editor/index.js +5 -0
- package/dist/editor/index.js.map +1 -0
- package/dist/editor/language-review.d.ts +14 -0
- package/dist/editor/language-review.js +35 -0
- package/dist/editor/language-review.js.map +1 -0
- package/dist/editor/log.d.ts +37 -0
- package/dist/editor/log.js +202 -0
- package/dist/editor/log.js.map +1 -0
- package/dist/editor/markup.d.ts +20 -0
- package/dist/editor/markup.js +294 -0
- package/dist/editor/markup.js.map +1 -0
- package/dist/editor/prompt-templates.d.ts +6 -0
- package/dist/editor/prompt-templates.js +11 -0
- package/dist/editor/prompt-templates.js.map +1 -0
- package/dist/editor/response.d.ts +5 -0
- package/dist/editor/response.js +31 -0
- package/dist/editor/response.js.map +1 -0
- package/dist/editor/review.d.ts +34 -0
- package/dist/editor/review.js +189 -0
- package/dist/editor/review.js.map +1 -0
- package/dist/editor/types.d.ts +31 -0
- package/dist/editor/types.js +21 -0
- package/dist/editor/types.js.map +1 -0
- package/dist/evidence-selection/anchor-resolver.d.ts +43 -0
- package/dist/evidence-selection/anchor-resolver.js +783 -0
- package/dist/evidence-selection/anchor-resolver.js.map +1 -0
- package/dist/evidence-selection/anchor-types.d.ts +27 -0
- package/dist/evidence-selection/anchor-types.js +1 -0
- package/dist/evidence-selection/anchor-types.js.map +1 -0
- package/dist/evidence-selection/index.d.ts +8 -0
- package/dist/evidence-selection/index.js +32 -0
- package/dist/evidence-selection/index.js.map +1 -0
- package/dist/evidence-selection/prompt.d.ts +18 -0
- package/dist/evidence-selection/prompt.js +54 -0
- package/dist/evidence-selection/prompt.js.map +1 -0
- package/dist/evidence-selection/quote-score.d.ts +29 -0
- package/dist/evidence-selection/quote-score.js +331 -0
- package/dist/evidence-selection/quote-score.js.map +1 -0
- package/dist/evidence-selection/selection-resolver.d.ts +19 -0
- package/dist/evidence-selection/selection-resolver.js +303 -0
- package/dist/evidence-selection/selection-resolver.js.map +1 -0
- package/dist/evidence-selection/text.d.ts +4 -0
- package/dist/evidence-selection/text.js +66 -0
- package/dist/evidence-selection/text.js.map +1 -0
- package/dist/evidence-selection/types.d.ts +36 -0
- package/dist/evidence-selection/types.js +1 -0
- package/dist/evidence-selection/types.js.map +1 -0
- package/dist/facade/app.d.ts +75 -0
- package/dist/facade/app.js +141 -0
- package/dist/facade/app.js.map +1 -0
- package/dist/facade/build-queue.d.ts +181 -0
- package/dist/facade/build-queue.js +1442 -0
- package/dist/facade/build-queue.js.map +1 -0
- package/dist/facade/chapter-build.d.ts +60 -0
- package/dist/facade/chapter-build.js +1020 -0
- package/dist/facade/chapter-build.js.map +1 -0
- package/dist/facade/chapter.d.ts +168 -0
- package/dist/facade/chapter.js +944 -0
- package/dist/facade/chapter.js.map +1 -0
- package/dist/facade/digest.d.ts +55 -0
- package/dist/facade/digest.js +168 -0
- package/dist/facade/digest.js.map +1 -0
- package/dist/facade/graph.d.ts +60 -0
- package/dist/facade/graph.js +203 -0
- package/dist/facade/graph.js.map +1 -0
- package/dist/facade/import.d.ts +49 -0
- package/dist/facade/import.js +262 -0
- package/dist/facade/import.js.map +1 -0
- package/dist/facade/index.d.ts +39 -0
- package/dist/facade/index.js +171 -0
- package/dist/facade/index.js.map +1 -0
- package/dist/facade/knowledge-graph-build.d.ts +75 -0
- package/dist/facade/knowledge-graph-build.js +897 -0
- package/dist/facade/knowledge-graph-build.js.map +1 -0
- package/dist/facade/llm-sampling.d.ts +11 -0
- package/dist/facade/llm-sampling.js +58 -0
- package/dist/facade/llm-sampling.js.map +1 -0
- package/dist/facade/types.d.ts +8 -0
- package/dist/facade/types.js +1 -0
- package/dist/facade/types.js.map +1 -0
- package/dist/facade/wiki-graph-archive.d.ts +41 -0
- package/dist/facade/wiki-graph-archive.js +130 -0
- package/dist/facade/wiki-graph-archive.js.map +1 -0
- package/dist/gc/files.d.ts +15 -0
- package/dist/gc/files.js +141 -0
- package/dist/gc/files.js.map +1 -0
- package/dist/gc/index.d.ts +2 -0
- package/dist/gc/index.js +5 -0
- package/dist/gc/index.js.map +1 -0
- package/dist/gc/lock.d.ts +3 -0
- package/dist/gc/lock.js +137 -0
- package/dist/gc/lock.js.map +1 -0
- package/dist/gc/runner.d.ts +9 -0
- package/dist/gc/runner.js +129 -0
- package/dist/gc/runner.js.map +1 -0
- package/dist/gc/tmp-gc.d.ts +5 -0
- package/dist/gc/tmp-gc.js +57 -0
- package/dist/gc/tmp-gc.js.map +1 -0
- package/dist/gc/types.d.ts +24 -0
- package/dist/gc/types.js +1 -0
- package/dist/gc/types.js.map +1 -0
- package/dist/gc.cjs +10041 -0
- package/dist/gc.cjs.map +1 -0
- package/dist/gc.d.cts +10 -0
- package/dist/gc.d.ts +2 -0
- package/dist/gc.js +5 -0
- package/dist/gc.js.map +1 -0
- package/dist/guaranteed/classifier.d.ts +10 -0
- package/dist/guaranteed/classifier.js +88 -0
- package/dist/guaranteed/classifier.js.map +1 -0
- package/dist/guaranteed/errors.d.ts +38 -0
- package/dist/guaranteed/errors.js +73 -0
- package/dist/guaranteed/errors.js.map +1 -0
- package/dist/guaranteed/index.d.ts +7 -0
- package/dist/guaranteed/index.js +21 -0
- package/dist/guaranteed/index.js.map +1 -0
- package/dist/guaranteed/request.d.ts +8 -0
- package/dist/guaranteed/request.js +206 -0
- package/dist/guaranteed/request.js.map +1 -0
- package/dist/guaranteed/response.d.ts +12 -0
- package/dist/guaranteed/response.js +98 -0
- package/dist/guaranteed/response.js.map +1 -0
- package/dist/guaranteed/types.d.ts +20 -0
- package/dist/guaranteed/types.js +1 -0
- package/dist/guaranteed/types.js.map +1 -0
- package/dist/index-B8NNnQ8P.d.ts +424 -0
- package/dist/index.cjs +34774 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +2462 -0
- package/dist/index.d.ts +79 -0
- package/dist/index.js +168 -0
- package/dist/index.js.map +1 -0
- package/dist/legacy-sdpub/upgrade.d.ts +7 -0
- package/dist/legacy-sdpub/upgrade.js +795 -0
- package/dist/legacy-sdpub/upgrade.js.map +1 -0
- package/dist/llm/cache.d.ts +13 -0
- package/dist/llm/cache.js +35 -0
- package/dist/llm/cache.js.map +1 -0
- package/dist/llm/client.d.ts +26 -0
- package/dist/llm/client.js +572 -0
- package/dist/llm/client.js.map +1 -0
- package/dist/llm/context.d.ts +22 -0
- package/dist/llm/context.js +78 -0
- package/dist/llm/context.js.map +1 -0
- package/dist/llm/errors.d.ts +7 -0
- package/dist/llm/errors.js +12 -0
- package/dist/llm/errors.js.map +1 -0
- package/dist/llm/index.d.ts +7 -0
- package/dist/llm/index.js +17 -0
- package/dist/llm/index.js.map +1 -0
- package/dist/llm/request-log.d.ts +9 -0
- package/dist/llm/request-log.js +35 -0
- package/dist/llm/request-log.js.map +1 -0
- package/dist/llm/sampling.d.ts +11 -0
- package/dist/llm/sampling.js +67 -0
- package/dist/llm/sampling.js.map +1 -0
- package/dist/llm/types.d.ts +50 -0
- package/dist/llm/types.js +1 -0
- package/dist/llm/types.js.map +1 -0
- package/dist/output/epub/archive.d.ts +9 -0
- package/dist/output/epub/archive.js +81 -0
- package/dist/output/epub/archive.js.map +1 -0
- package/dist/output/epub/book.d.ts +15 -0
- package/dist/output/epub/book.js +76 -0
- package/dist/output/epub/book.js.map +1 -0
- package/dist/output/epub/content.d.ts +9 -0
- package/dist/output/epub/content.js +35 -0
- package/dist/output/epub/content.js.map +1 -0
- package/dist/output/epub/index.d.ts +20 -0
- package/dist/output/epub/index.js +14 -0
- package/dist/output/epub/index.js.map +1 -0
- package/dist/output/epub/model.d.ts +24 -0
- package/dist/output/epub/model.js +1 -0
- package/dist/output/epub/model.js.map +1 -0
- package/dist/output/epub/navigation.d.ts +10 -0
- package/dist/output/epub/navigation.js +39 -0
- package/dist/output/epub/navigation.js.map +1 -0
- package/dist/output/epub/package.d.ts +17 -0
- package/dist/output/epub/package.js +29 -0
- package/dist/output/epub/package.js.map +1 -0
- package/dist/output/epub/shared.d.ts +4 -0
- package/dist/output/epub/shared.js +12 -0
- package/dist/output/epub/shared.js.map +1 -0
- package/dist/output/epub/templates.d.ts +35 -0
- package/dist/output/epub/templates.js +26 -0
- package/dist/output/epub/templates.js.map +1 -0
- package/dist/output/index.d.ts +14 -0
- package/dist/output/index.js +11 -0
- package/dist/output/index.js.map +1 -0
- package/dist/output/plain-text.d.ts +18 -0
- package/dist/output/plain-text.js +56 -0
- package/dist/output/plain-text.js.map +1 -0
- package/dist/progress/index.d.ts +3 -0
- package/dist/progress/index.js +14 -0
- package/dist/progress/index.js.map +1 -0
- package/dist/progress/reporter.d.ts +10 -0
- package/dist/progress/reporter.js +79 -0
- package/dist/progress/reporter.js.map +1 -0
- package/dist/progress/tracker.d.ts +37 -0
- package/dist/progress/tracker.js +119 -0
- package/dist/progress/tracker.js.map +1 -0
- package/dist/progress/types.d.ts +28 -0
- package/dist/progress/types.js +1 -0
- package/dist/progress/types.js.map +1 -0
- package/dist/reader/attention/attention.d.ts +39 -0
- package/dist/reader/attention/attention.js +123 -0
- package/dist/reader/attention/attention.js.map +1 -0
- package/dist/reader/attention/index.d.ts +9 -0
- package/dist/reader/attention/index.js +5 -0
- package/dist/reader/attention/index.js.map +1 -0
- package/dist/reader/attention/wave-reflection.d.ts +21 -0
- package/dist/reader/attention/wave-reflection.js +153 -0
- package/dist/reader/attention/wave-reflection.js.map +1 -0
- package/dist/reader/attention/working-memory.d.ts +28 -0
- package/dist/reader/attention/working-memory.js +62 -0
- package/dist/reader/attention/working-memory.js.map +1 -0
- package/dist/reader/chunk-batch/extract.d.ts +13 -0
- package/dist/reader/chunk-batch/extract.js +14 -0
- package/dist/reader/chunk-batch/extract.js.map +1 -0
- package/dist/reader/chunk-batch/extractor.d.ts +17 -0
- package/dist/reader/chunk-batch/extractor.js +337 -0
- package/dist/reader/chunk-batch/extractor.js.map +1 -0
- package/dist/reader/chunk-batch/fragment-projection.d.ts +34 -0
- package/dist/reader/chunk-batch/fragment-projection.js +94 -0
- package/dist/reader/chunk-batch/fragment-projection.js.map +1 -0
- package/dist/reader/chunk-batch/index.d.ts +12 -0
- package/dist/reader/chunk-batch/index.js +13 -0
- package/dist/reader/chunk-batch/index.js.map +1 -0
- package/dist/reader/chunk-batch/language.d.ts +9 -0
- package/dist/reader/chunk-batch/language.js +23 -0
- package/dist/reader/chunk-batch/language.js.map +1 -0
- package/dist/reader/chunk-batch/parser.d.ts +94 -0
- package/dist/reader/chunk-batch/parser.js +640 -0
- package/dist/reader/chunk-batch/parser.js.map +1 -0
- package/dist/reader/chunk-batch/prompt-templates.d.ts +6 -0
- package/dist/reader/chunk-batch/prompt-templates.js +11 -0
- package/dist/reader/chunk-batch/prompt-templates.js.map +1 -0
- package/dist/reader/chunk-batch/types.d.ts +85 -0
- package/dist/reader/chunk-batch/types.js +1 -0
- package/dist/reader/chunk-batch/types.js.map +1 -0
- package/dist/reader/index.d.ts +13 -0
- package/dist/reader/index.js +7 -0
- package/dist/reader/index.js.map +1 -0
- package/dist/reader/reader.d.ts +37 -0
- package/dist/reader/reader.js +82 -0
- package/dist/reader/reader.js.map +1 -0
- package/dist/reader/segment/index.d.ts +2 -0
- package/dist/reader/segment/index.js +5 -0
- package/dist/reader/segment/index.js.map +1 -0
- package/dist/reader/segment/intl-segmenter.d.ts +5 -0
- package/dist/reader/segment/intl-segmenter.js +102 -0
- package/dist/reader/segment/intl-segmenter.js.map +1 -0
- package/dist/reader/segment/segment.d.ts +5 -0
- package/dist/reader/segment/segment.js +9 -0
- package/dist/reader/segment/segment.js.map +1 -0
- package/dist/reader/segment/types.d.ts +14 -0
- package/dist/reader/segment/types.js +1 -0
- package/dist/reader/segment/types.js.map +1 -0
- package/dist/reader/types.d.ts +29 -0
- package/dist/reader/types.js +1 -0
- package/dist/reader/types.js.map +1 -0
- package/dist/serial.d.ts +89 -0
- package/dist/serial.js +476 -0
- package/dist/serial.js.map +1 -0
- package/dist/source/adapter.d.ts +15 -0
- package/dist/source/adapter.js +1 -0
- package/dist/source/adapter.js.map +1 -0
- package/dist/source/epub/archive.d.ts +27 -0
- package/dist/source/epub/archive.js +189 -0
- package/dist/source/epub/archive.js.map +1 -0
- package/dist/source/epub/content.d.ts +22 -0
- package/dist/source/epub/content.js +183 -0
- package/dist/source/epub/content.js.map +1 -0
- package/dist/source/epub/document.d.ts +55 -0
- package/dist/source/epub/document.js +179 -0
- package/dist/source/epub/document.js.map +1 -0
- package/dist/source/epub/index.d.ts +10 -0
- package/dist/source/epub/index.js +6 -0
- package/dist/source/epub/index.js.map +1 -0
- package/dist/source/epub/navigation.d.ts +16 -0
- package/dist/source/epub/navigation.js +215 -0
- package/dist/source/epub/navigation.js.map +1 -0
- package/dist/source/epub/package.d.ts +33 -0
- package/dist/source/epub/package.js +237 -0
- package/dist/source/epub/package.js.map +1 -0
- package/dist/source/epub/xml.d.ts +16 -0
- package/dist/source/epub/xml.js +111 -0
- package/dist/source/epub/xml.js.map +1 -0
- package/dist/source/index.d.ts +12 -0
- package/dist/source/index.js +32 -0
- package/dist/source/index.js.map +1 -0
- package/dist/source/meta.d.ts +30 -0
- package/dist/source/meta.js +22 -0
- package/dist/source/meta.js.map +1 -0
- package/dist/source/plain-text.d.ts +16 -0
- package/dist/source/plain-text.js +86 -0
- package/dist/source/plain-text.js.map +1 -0
- package/dist/source/toc.d.ts +16 -0
- package/dist/source/toc.js +17 -0
- package/dist/source/toc.js.map +1 -0
- package/dist/source/types.d.ts +16 -0
- package/dist/source/types.js +1 -0
- package/dist/source/types.js.map +1 -0
- package/dist/topology/grouping.d.ts +15 -0
- package/dist/topology/grouping.js +18 -0
- package/dist/topology/grouping.js.map +1 -0
- package/dist/topology/index.d.ts +21 -0
- package/dist/topology/index.js +5 -0
- package/dist/topology/index.js.map +1 -0
- package/dist/topology/resource-segmentation.d.ts +13 -0
- package/dist/topology/resource-segmentation.js +111 -0
- package/dist/topology/resource-segmentation.js.map +1 -0
- package/dist/topology/segment-incision.d.ts +18 -0
- package/dist/topology/segment-incision.js +197 -0
- package/dist/topology/segment-incision.js.map +1 -0
- package/dist/topology/snake-detector.d.ts +13 -0
- package/dist/topology/snake-detector.js +520 -0
- package/dist/topology/snake-detector.js.map +1 -0
- package/dist/topology/snake-graph-builder.d.ts +14 -0
- package/dist/topology/snake-graph-builder.js +76 -0
- package/dist/topology/snake-graph-builder.js.map +1 -0
- package/dist/topology/topology.d.ts +29 -0
- package/dist/topology/topology.js +348 -0
- package/dist/topology/topology.js.map +1 -0
- package/dist/topology/weights.d.ts +10 -0
- package/dist/topology/weights.js +84 -0
- package/dist/topology/weights.js.map +1 -0
- package/dist/types-FVIqiLC9.d.cts +24 -0
- package/dist/utils/async-semaphore.d.ts +7 -0
- package/dist/utils/async-semaphore.js +40 -0
- package/dist/utils/async-semaphore.js.map +1 -0
- package/dist/utils/enum.d.ts +5 -0
- package/dist/utils/enum.js +18 -0
- package/dist/utils/enum.js.map +1 -0
- package/dist/utils/hash.d.ts +3 -0
- package/dist/utils/hash.js +132 -0
- package/dist/utils/hash.js.map +1 -0
- package/dist/utils/node-error.d.ts +4 -0
- package/dist/utils/node-error.js +59 -0
- package/dist/utils/node-error.js.map +1 -0
- package/dist/wikg/archive-uri.d.ts +1 -0
- package/dist/wikg/archive-uri.js +37 -0
- package/dist/wikg/archive-uri.js.map +1 -0
- package/dist/wikg/archive.d.ts +28 -0
- package/dist/wikg/archive.js +496 -0
- package/dist/wikg/archive.js.map +1 -0
- package/dist/wikg/index.d.ts +31 -0
- package/dist/wikg/index.js +60 -0
- package/dist/wikg/index.js.map +1 -0
- package/dist/wikg/wikg-coordinator.d.ts +45 -0
- package/dist/wikg/wikg-coordinator.js +1687 -0
- package/dist/wikg/wikg-coordinator.js.map +1 -0
- package/dist/wikg/wiki-graph-archive-file.d.ts +42 -0
- package/dist/wikg/wiki-graph-archive-file.js +78 -0
- package/dist/wikg/wiki-graph-archive-file.js.map +1 -0
- package/dist/wikilink/index.d.ts +10 -0
- package/dist/wikilink/index.js +7 -0
- package/dist/wikilink/index.js.map +1 -0
- package/dist/wikilink/relation-discovery.d.ts +31 -0
- package/dist/wikilink/relation-discovery.js +477 -0
- package/dist/wikilink/relation-discovery.js.map +1 -0
- package/dist/wikilink/types.d.ts +23 -0
- package/dist/wikilink/types.js +1 -0
- package/dist/wikilink/types.js.map +1 -0
- package/dist/wikilink/window.d.ts +7 -0
- package/dist/wikilink/window.js +53 -0
- package/dist/wikilink/window.js.map +1 -0
- package/dist/wikimatch/enrichment.d.ts +10 -0
- package/dist/wikimatch/enrichment.js +55 -0
- package/dist/wikimatch/enrichment.js.map +1 -0
- package/dist/wikimatch/index.d.ts +16 -0
- package/dist/wikimatch/index.js +66 -0
- package/dist/wikimatch/index.js.map +1 -0
- package/dist/wikimatch/option-narrowing.d.ts +17 -0
- package/dist/wikimatch/option-narrowing.js +208 -0
- package/dist/wikimatch/option-narrowing.js.map +1 -0
- package/dist/wikimatch/options.d.ts +14 -0
- package/dist/wikimatch/options.js +155 -0
- package/dist/wikimatch/options.js.map +1 -0
- package/dist/wikimatch/policy-judge.d.ts +17 -0
- package/dist/wikimatch/policy-judge.js +430 -0
- package/dist/wikimatch/policy-judge.js.map +1 -0
- package/dist/wikimatch/range-suppression.d.ts +9 -0
- package/dist/wikimatch/range-suppression.js +27 -0
- package/dist/wikimatch/range-suppression.js.map +1 -0
- package/dist/wikimatch/surface-screening.d.ts +16 -0
- package/dist/wikimatch/surface-screening.js +168 -0
- package/dist/wikimatch/surface-screening.js.map +1 -0
- package/dist/wikimatch/surface-window.d.ts +6 -0
- package/dist/wikimatch/surface-window.js +44 -0
- package/dist/wikimatch/surface-window.js.map +1 -0
- package/dist/wikimatch/types.d.ts +151 -0
- package/dist/wikimatch/types.js +1 -0
- package/dist/wikimatch/types.js.map +1 -0
- package/dist/wikimatch/wikispine.d.ts +43 -0
- package/dist/wikimatch/wikispine.js +399 -0
- package/dist/wikimatch/wikispine.js.map +1 -0
- package/dist/wikimatch/window.d.ts +6 -0
- package/dist/wikimatch/window.js +83 -0
- package/dist/wikimatch/window.js.map +1 -0
- package/dist/wikimatch/words.d.ts +16 -0
- package/dist/wikimatch/words.js +66 -0
- package/dist/wikimatch/words.js.map +1 -0
- package/dist/wikipage/cache.d.ts +18 -0
- package/dist/wikipage/cache.js +404 -0
- package/dist/wikipage/cache.js.map +1 -0
- package/dist/wikipage/fetch-log.d.ts +17 -0
- package/dist/wikipage/fetch-log.js +143 -0
- package/dist/wikipage/fetch-log.js.map +1 -0
- package/dist/wikipage/index.d.ts +14 -0
- package/dist/wikipage/index.js +17 -0
- package/dist/wikipage/index.js.map +1 -0
- package/dist/wikipage/normalizer.d.ts +14 -0
- package/dist/wikipage/normalizer.js +147 -0
- package/dist/wikipage/normalizer.js.map +1 -0
- package/dist/wikipage/rate-limiter.d.ts +13 -0
- package/dist/wikipage/rate-limiter.js +84 -0
- package/dist/wikipage/rate-limiter.js.map +1 -0
- package/dist/wikipage/resolver.d.ts +26 -0
- package/dist/wikipage/resolver.js +325 -0
- package/dist/wikipage/resolver.js.map +1 -0
- package/dist/wikipage/types.d.ts +96 -0
- package/dist/wikipage/types.js +1 -0
- package/dist/wikipage/types.js.map +1 -0
- package/dist/wikipage/wikimedia-client.d.ts +48 -0
- package/dist/wikipage/wikimedia-client.js +397 -0
- package/dist/wikipage/wikimedia-client.js.map +1 -0
- package/dist/worker-BgQ0Xl8T.d.cts +181 -0
- package/dist/worker.cjs +5259 -0
- package/dist/worker.cjs.map +1 -0
- package/dist/worker.d.cts +2 -0
- package/dist/worker.d.ts +2 -0
- package/dist/worker.js +5 -0
- package/dist/worker.js.map +1 -0
- package/package.json +78 -0
|
@@ -0,0 +1,944 @@
|
|
|
1
|
+
import { normalizeLanguageCode } from "../common/language.js";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import {
|
|
4
|
+
SerialGeneration,
|
|
5
|
+
writeSerialSource
|
|
6
|
+
} from "../serial.js";
|
|
7
|
+
import { TOC_FILE_VERSION } from "../source/index.js";
|
|
8
|
+
const CHAPTER_STAGES = [
|
|
9
|
+
"planned",
|
|
10
|
+
"sourced",
|
|
11
|
+
"graphed",
|
|
12
|
+
"summarized"
|
|
13
|
+
];
|
|
14
|
+
const chapterTreeInputNodeSchema = z.object({
|
|
15
|
+
children: z.lazy(() => z.array(chapterTreeInputNodeSchema)),
|
|
16
|
+
id: z.number().int().nonnegative(),
|
|
17
|
+
title: z.string().nullable().optional()
|
|
18
|
+
}).strict();
|
|
19
|
+
const chapterTreeInputSchema = z.object({
|
|
20
|
+
chapters: z.array(chapterTreeInputNodeSchema)
|
|
21
|
+
}).strict();
|
|
22
|
+
function parseChapterTreeInput(input) {
|
|
23
|
+
return chapterTreeInputSchema.parse(input);
|
|
24
|
+
}
|
|
25
|
+
async function advanceChapterStages(document, options) {
|
|
26
|
+
if (options.targetStage === "planned") {
|
|
27
|
+
return {
|
|
28
|
+
advanced: [],
|
|
29
|
+
pending: await selectChapterEntries(document, options.chapterId),
|
|
30
|
+
skipped: []
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
const advancedIds = /* @__PURE__ */ new Set();
|
|
34
|
+
const entries = await selectChapterEntries(document, options.chapterId);
|
|
35
|
+
const progressState = createAdvanceProgressState(
|
|
36
|
+
entries,
|
|
37
|
+
options.targetStage
|
|
38
|
+
);
|
|
39
|
+
await emitAdvanceProgress(options, {
|
|
40
|
+
state: progressState.snapshot(),
|
|
41
|
+
targetStage: options.targetStage,
|
|
42
|
+
totalChapters: entries.length,
|
|
43
|
+
type: "selected"
|
|
44
|
+
});
|
|
45
|
+
await emitPlannedSkips(entries, options);
|
|
46
|
+
if (isStageBefore("sourced", options.targetStage)) {
|
|
47
|
+
await advanceEntriesToGraphed(document, entries, options, {
|
|
48
|
+
advancedIds,
|
|
49
|
+
progressState
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
if (isStageBefore("graphed", options.targetStage)) {
|
|
53
|
+
const graphedEntries = await selectChapterEntries(
|
|
54
|
+
document,
|
|
55
|
+
options.chapterId
|
|
56
|
+
);
|
|
57
|
+
await advanceEntriesToSummarized(document, graphedEntries, options, {
|
|
58
|
+
advancedIds,
|
|
59
|
+
progressState
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
const nextEntries = await selectChapterEntries(document, options.chapterId);
|
|
63
|
+
return {
|
|
64
|
+
advanced: nextEntries.filter((entry) => advancedIds.has(entry.chapterId)),
|
|
65
|
+
pending: nextEntries.filter(
|
|
66
|
+
(entry) => isStageBefore(entry.stage, options.targetStage)
|
|
67
|
+
),
|
|
68
|
+
skipped: nextEntries.filter((entry) => entry.stage === "planned")
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
async function addChapter(document, options) {
|
|
72
|
+
return await document.openSession(async (openedDocument) => {
|
|
73
|
+
const toc = await normalizeChapterToc(openedDocument);
|
|
74
|
+
const normalizedTitle = normalizeTitle(options.title);
|
|
75
|
+
const chapterId = await openedDocument.createSerial();
|
|
76
|
+
const chapterItem = {
|
|
77
|
+
children: [],
|
|
78
|
+
serialId: chapterId,
|
|
79
|
+
...normalizedTitle === void 0 ? {} : { title: normalizedTitle }
|
|
80
|
+
};
|
|
81
|
+
if (options.parentChapterId === void 0) {
|
|
82
|
+
toc.items = [...toc.items, chapterItem];
|
|
83
|
+
} else if (!appendChildToChapter(toc.items, options.parentChapterId, chapterItem)) {
|
|
84
|
+
throw new Error(
|
|
85
|
+
`Chapter ${options.parentChapterId} does not exist. Use \`wg <archive-uri>/chapter list\` to discover chapter ids.`
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
await openedDocument.replaceToc(toc);
|
|
89
|
+
return await getChapterDetails(openedDocument, chapterId);
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
async function generateChapterGraph(document, chapterId, options) {
|
|
93
|
+
return await document.openSession(async (openedDocument) => {
|
|
94
|
+
const details = await requireChapterDetails(openedDocument, chapterId);
|
|
95
|
+
if (details.stage !== "sourced") {
|
|
96
|
+
throw new Error(
|
|
97
|
+
`Chapter ${chapterId} is ${details.stage}. Generate a graph only for sourced chapters.`
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
const generation = new SerialGeneration({
|
|
101
|
+
document: openedDocument,
|
|
102
|
+
llm: options.llm,
|
|
103
|
+
...options.logDirPath === void 0 ? {} : { logDirPath: options.logDirPath }
|
|
104
|
+
});
|
|
105
|
+
await openedDocument.clearSerialGraph(chapterId);
|
|
106
|
+
await generation.buildTopologyInto(
|
|
107
|
+
chapterId,
|
|
108
|
+
createTopologyOptions(options),
|
|
109
|
+
options.progressTracker
|
|
110
|
+
);
|
|
111
|
+
const language = normalizeLanguageCode(options.userLanguage);
|
|
112
|
+
const parameter = await openedDocument.graphBuildParameters.save({
|
|
113
|
+
prompt: options.extractionPrompt,
|
|
114
|
+
...language === void 0 ? {} : { language }
|
|
115
|
+
});
|
|
116
|
+
await openedDocument.serials.setTopologyReady(
|
|
117
|
+
chapterId,
|
|
118
|
+
true,
|
|
119
|
+
parameter.hash
|
|
120
|
+
);
|
|
121
|
+
return await getChapterDetails(openedDocument, chapterId);
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
async function generateChapterSummary(document, chapterId, options) {
|
|
125
|
+
return await document.openSession(async (openedDocument) => {
|
|
126
|
+
const details = await requireChapterDetails(openedDocument, chapterId);
|
|
127
|
+
if (details.stage !== "graphed") {
|
|
128
|
+
throw new Error(
|
|
129
|
+
`Chapter ${chapterId} is ${details.stage}. Generate a summary only for graphed chapters.`
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
const generation = new SerialGeneration({
|
|
133
|
+
document: openedDocument,
|
|
134
|
+
llm: options.llm,
|
|
135
|
+
...options.logDirPath === void 0 ? {} : { logDirPath: options.logDirPath }
|
|
136
|
+
});
|
|
137
|
+
await generation.buildSummary(chapterId, {
|
|
138
|
+
...options.userLanguage === void 0 ? {} : { userLanguage: options.userLanguage }
|
|
139
|
+
});
|
|
140
|
+
return await getChapterDetails(openedDocument, chapterId);
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
async function getChapterDetails(document, chapterId) {
|
|
144
|
+
const toc = await readChapterToc(document);
|
|
145
|
+
const entry = await findChapterEntry(document, toc.items, chapterId);
|
|
146
|
+
if (entry === void 0) {
|
|
147
|
+
throw new Error(
|
|
148
|
+
`Chapter ${chapterId} does not exist. Use \`wg <archive-uri>/chapter list\` to discover chapter ids.`
|
|
149
|
+
);
|
|
150
|
+
}
|
|
151
|
+
const serial = await document.serials.getById(chapterId);
|
|
152
|
+
const summary = await document.readSummary(chapterId);
|
|
153
|
+
return {
|
|
154
|
+
...entry,
|
|
155
|
+
graphReady: serial?.topologyReady === true,
|
|
156
|
+
hasSummary: summary !== void 0
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
async function listChapters(document) {
|
|
160
|
+
const toc = await readChapterToc(document);
|
|
161
|
+
return await collectChapterEntries(document, toc.items);
|
|
162
|
+
}
|
|
163
|
+
async function getChapterTree(document) {
|
|
164
|
+
const toc = await readChapterToc(document);
|
|
165
|
+
return {
|
|
166
|
+
chapters: toc.items.flatMap(toChapterTreeNodes)
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
async function applyChapterTree(document, tree, options = {}) {
|
|
170
|
+
return await document.openSession(async (openedDocument) => {
|
|
171
|
+
const toc = await normalizeChapterToc(openedDocument);
|
|
172
|
+
const oldItems = toc.items.map(cloneTocItem);
|
|
173
|
+
const oldMetas = collectTocItemMetas(oldItems);
|
|
174
|
+
const { items } = createTocItemsFromChapterTree(tree, oldItems);
|
|
175
|
+
const newMetas = collectTocItemMetas(items);
|
|
176
|
+
const result = createChapterTreeApplyResult(oldMetas, newMetas);
|
|
177
|
+
if (options.dryRun !== true && result.changed) {
|
|
178
|
+
await openedDocument.replaceToc({
|
|
179
|
+
items,
|
|
180
|
+
version: toc.version
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
return result;
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
async function moveChapter(document, chapterId, options) {
|
|
187
|
+
return await document.openSession(async (openedDocument) => {
|
|
188
|
+
const toc = await normalizeChapterToc(openedDocument);
|
|
189
|
+
const originalLocation = findChapterLocation(toc.items, chapterId);
|
|
190
|
+
const extracted = extractChapterItem(toc.items, chapterId);
|
|
191
|
+
if (extracted.item === void 0) {
|
|
192
|
+
throw new Error(
|
|
193
|
+
`Chapter ${chapterId} does not exist. Use \`wg <archive-uri>/chapter list\` to discover chapter ids.`
|
|
194
|
+
);
|
|
195
|
+
}
|
|
196
|
+
rejectMoveIntoOwnSubtree(chapterId, extracted.item, options);
|
|
197
|
+
toc.items = extracted.items;
|
|
198
|
+
insertMovedChapter(toc.items, extracted.item, {
|
|
199
|
+
originalParentChapterId: originalLocation?.parentChapterId,
|
|
200
|
+
...options
|
|
201
|
+
});
|
|
202
|
+
await openedDocument.replaceToc(toc);
|
|
203
|
+
return await getChapterDetails(openedDocument, chapterId);
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
async function removeChapter(document, chapterId, options = {}) {
|
|
207
|
+
await document.openSession(async (openedDocument) => {
|
|
208
|
+
const toc = await normalizeChapterToc(openedDocument);
|
|
209
|
+
const removedChapterIds = [];
|
|
210
|
+
const result = removeChapterFromItems(toc.items, chapterId, {
|
|
211
|
+
recursive: options.recursive ?? false,
|
|
212
|
+
removedChapterIds
|
|
213
|
+
});
|
|
214
|
+
if (!result.removed) {
|
|
215
|
+
throw new Error(
|
|
216
|
+
`Chapter ${chapterId} does not exist. Use \`wg <archive-uri>/chapter list\` to discover chapter ids.`
|
|
217
|
+
);
|
|
218
|
+
}
|
|
219
|
+
toc.items = result.items;
|
|
220
|
+
await openedDocument.replaceToc(toc);
|
|
221
|
+
for (const removedChapterId of removedChapterIds) {
|
|
222
|
+
await openedDocument.deleteSerial(removedChapterId);
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
async function resetChapter(document, chapterId, stage) {
|
|
227
|
+
return await document.openSession(async (openedDocument) => {
|
|
228
|
+
await requireChapterDetails(openedDocument, chapterId);
|
|
229
|
+
switch (stage) {
|
|
230
|
+
case "planned":
|
|
231
|
+
await openedDocument.clearSerialSource(chapterId);
|
|
232
|
+
break;
|
|
233
|
+
case "sourced":
|
|
234
|
+
await openedDocument.clearSerialGraph(chapterId);
|
|
235
|
+
break;
|
|
236
|
+
case "graphed":
|
|
237
|
+
await openedDocument.deleteSummary(chapterId);
|
|
238
|
+
break;
|
|
239
|
+
}
|
|
240
|
+
return await getChapterDetails(openedDocument, chapterId);
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
async function setChapterSource(document, chapterId, stream) {
|
|
244
|
+
return await document.openSession(async (openedDocument) => {
|
|
245
|
+
const details = await requireChapterDetails(openedDocument, chapterId);
|
|
246
|
+
if (details.stage !== "planned") {
|
|
247
|
+
throw new Error(
|
|
248
|
+
`Chapter ${chapterId} is ${details.stage}. Reset it to planned before setting source.`
|
|
249
|
+
);
|
|
250
|
+
}
|
|
251
|
+
await writeSerialSource(openedDocument, chapterId, stream);
|
|
252
|
+
return await getChapterDetails(openedDocument, chapterId);
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
async function setChapterSummary(document, chapterId, summary) {
|
|
256
|
+
return await document.openSession(async (openedDocument) => {
|
|
257
|
+
const details = await requireChapterDetails(openedDocument, chapterId);
|
|
258
|
+
if (details.stage !== "graphed") {
|
|
259
|
+
throw new Error(
|
|
260
|
+
`Chapter ${chapterId} is ${details.stage}. Set a summary only for graphed chapters.`
|
|
261
|
+
);
|
|
262
|
+
}
|
|
263
|
+
await openedDocument.writeSummary(chapterId, summary);
|
|
264
|
+
return await getChapterDetails(openedDocument, chapterId);
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
async function setChapterTitle(document, chapterId, title) {
|
|
268
|
+
return await document.openSession(async (openedDocument) => {
|
|
269
|
+
const toc = await normalizeChapterToc(openedDocument);
|
|
270
|
+
const normalizedTitle = normalizeTitle(title);
|
|
271
|
+
if (!setChapterTitleInItems(toc.items, chapterId, normalizedTitle)) {
|
|
272
|
+
throw new Error(
|
|
273
|
+
`Chapter ${chapterId} does not exist. Use \`wg <archive-uri>/chapter list\` to discover chapter ids.`
|
|
274
|
+
);
|
|
275
|
+
}
|
|
276
|
+
await openedDocument.replaceToc(toc);
|
|
277
|
+
return await getChapterDetails(openedDocument, chapterId);
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
async function normalizeChapterToc(document) {
|
|
281
|
+
const existingToc = await document.readToc();
|
|
282
|
+
const toc = await readChapterToc(document);
|
|
283
|
+
let changed = false;
|
|
284
|
+
const normalizeItems = async (items) => {
|
|
285
|
+
for (const item of items) {
|
|
286
|
+
if (item.serialId === void 0) {
|
|
287
|
+
item.serialId = await document.createSerial();
|
|
288
|
+
changed = true;
|
|
289
|
+
} else {
|
|
290
|
+
await document.serials.ensure(item.serialId);
|
|
291
|
+
}
|
|
292
|
+
await normalizeItems(item.children);
|
|
293
|
+
}
|
|
294
|
+
};
|
|
295
|
+
await normalizeItems(toc.items);
|
|
296
|
+
if (existingToc === void 0 || changed) {
|
|
297
|
+
await document.replaceToc(toc);
|
|
298
|
+
}
|
|
299
|
+
return toc;
|
|
300
|
+
}
|
|
301
|
+
async function readChapterToc(document) {
|
|
302
|
+
const toc = await document.readToc();
|
|
303
|
+
return toc === void 0 ? { items: [], version: TOC_FILE_VERSION } : {
|
|
304
|
+
items: toc.items.map(cloneTocItem),
|
|
305
|
+
version: toc.version
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
async function findChapterEntry(document, items, chapterId, ancestorTitles = [], depth = 0) {
|
|
309
|
+
for (const item of items) {
|
|
310
|
+
const title = normalizeTitle(item.title) ?? null;
|
|
311
|
+
const tocPath = item.serialId === void 0 ? [...ancestorTitles, ...title === null ? [] : [title]] : [...ancestorTitles, title ?? `Chapter ${item.serialId}`];
|
|
312
|
+
if (item.serialId === chapterId) {
|
|
313
|
+
return await createChapterEntry(document, item, item.serialId, {
|
|
314
|
+
depth,
|
|
315
|
+
title,
|
|
316
|
+
tocPath
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
const childEntry = await findChapterEntry(
|
|
320
|
+
document,
|
|
321
|
+
item.children,
|
|
322
|
+
chapterId,
|
|
323
|
+
tocPath,
|
|
324
|
+
depth + 1
|
|
325
|
+
);
|
|
326
|
+
if (childEntry !== void 0) {
|
|
327
|
+
return childEntry;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
return void 0;
|
|
331
|
+
}
|
|
332
|
+
async function collectChapterEntries(document, items, ancestorTitles = [], depth = 0) {
|
|
333
|
+
const entries = [];
|
|
334
|
+
for (const item of items) {
|
|
335
|
+
const title = normalizeTitle(item.title) ?? null;
|
|
336
|
+
const tocPath = item.serialId === void 0 ? [...ancestorTitles, ...title === null ? [] : [title]] : [...ancestorTitles, title ?? `Chapter ${item.serialId}`];
|
|
337
|
+
if (item.serialId === void 0) {
|
|
338
|
+
entries.push(
|
|
339
|
+
...await collectChapterEntries(
|
|
340
|
+
document,
|
|
341
|
+
item.children,
|
|
342
|
+
tocPath,
|
|
343
|
+
depth + 1
|
|
344
|
+
)
|
|
345
|
+
);
|
|
346
|
+
continue;
|
|
347
|
+
}
|
|
348
|
+
entries.push(
|
|
349
|
+
await createChapterEntry(document, item, item.serialId, {
|
|
350
|
+
depth,
|
|
351
|
+
title,
|
|
352
|
+
tocPath
|
|
353
|
+
})
|
|
354
|
+
);
|
|
355
|
+
entries.push(
|
|
356
|
+
...await collectChapterEntries(
|
|
357
|
+
document,
|
|
358
|
+
item.children,
|
|
359
|
+
tocPath,
|
|
360
|
+
depth + 1
|
|
361
|
+
)
|
|
362
|
+
);
|
|
363
|
+
}
|
|
364
|
+
return entries;
|
|
365
|
+
}
|
|
366
|
+
async function createChapterEntry(document, item, serialId, input) {
|
|
367
|
+
const [serial, sourceSummary] = await Promise.all([
|
|
368
|
+
document.serials.getById(serialId),
|
|
369
|
+
summarizeSerialSource(document, serialId)
|
|
370
|
+
]);
|
|
371
|
+
return {
|
|
372
|
+
chapterId: serialId,
|
|
373
|
+
childCount: item.children.length,
|
|
374
|
+
depth: input.depth,
|
|
375
|
+
documentOrder: serial?.documentOrder ?? serialId,
|
|
376
|
+
fragmentCount: sourceSummary.fragmentCount,
|
|
377
|
+
stage: await resolveChapterStage(
|
|
378
|
+
document,
|
|
379
|
+
serialId,
|
|
380
|
+
sourceSummary.fragmentCount
|
|
381
|
+
),
|
|
382
|
+
title: input.title,
|
|
383
|
+
tocPath: input.tocPath,
|
|
384
|
+
words: sourceSummary.words
|
|
385
|
+
};
|
|
386
|
+
}
|
|
387
|
+
async function summarizeSerialSource(document, serialId) {
|
|
388
|
+
const sentenceWords = await document.readDatabase(
|
|
389
|
+
async (database) => await database.queryAll(
|
|
390
|
+
`
|
|
391
|
+
SELECT words_count
|
|
392
|
+
FROM text_sentence_records
|
|
393
|
+
WHERE kind = 1 AND chapter_id = ?
|
|
394
|
+
ORDER BY sentence_index
|
|
395
|
+
`,
|
|
396
|
+
[serialId],
|
|
397
|
+
(row) => Number(row.words_count)
|
|
398
|
+
)
|
|
399
|
+
);
|
|
400
|
+
let fragmentCount = 0;
|
|
401
|
+
let fragmentWords = 0;
|
|
402
|
+
let words = 0;
|
|
403
|
+
for (const sentenceWordCount of sentenceWords) {
|
|
404
|
+
if (fragmentWords > 0 && fragmentWords + sentenceWordCount > 600) {
|
|
405
|
+
fragmentCount += 1;
|
|
406
|
+
fragmentWords = 0;
|
|
407
|
+
}
|
|
408
|
+
fragmentWords += sentenceWordCount;
|
|
409
|
+
words += sentenceWordCount;
|
|
410
|
+
}
|
|
411
|
+
if (fragmentWords > 0) {
|
|
412
|
+
fragmentCount += 1;
|
|
413
|
+
}
|
|
414
|
+
return {
|
|
415
|
+
fragmentCount,
|
|
416
|
+
words
|
|
417
|
+
};
|
|
418
|
+
}
|
|
419
|
+
async function advanceEntriesToGraphed(document, entries, options, state) {
|
|
420
|
+
for (const entry of entries) {
|
|
421
|
+
if (entry.stage !== "sourced") {
|
|
422
|
+
continue;
|
|
423
|
+
}
|
|
424
|
+
await emitAdvanceProgress(options, {
|
|
425
|
+
chapter: entry,
|
|
426
|
+
step: "graph",
|
|
427
|
+
targetStage: options.targetStage,
|
|
428
|
+
type: "started"
|
|
429
|
+
});
|
|
430
|
+
await generateChapterGraph(document, entry.chapterId, {
|
|
431
|
+
extractionPrompt: options.extractionPrompt,
|
|
432
|
+
llm: options.llm,
|
|
433
|
+
...options.logDirPath === void 0 ? {} : { logDirPath: options.logDirPath },
|
|
434
|
+
...options.userLanguage === void 0 ? {} : { userLanguage: options.userLanguage },
|
|
435
|
+
progressTracker: {
|
|
436
|
+
async advance(wordsCount) {
|
|
437
|
+
state.progressState.addGraphWords(wordsCount);
|
|
438
|
+
await emitAdvanceProgress(options, {
|
|
439
|
+
state: state.progressState.snapshot(),
|
|
440
|
+
targetStage: options.targetStage,
|
|
441
|
+
type: "progress"
|
|
442
|
+
});
|
|
443
|
+
},
|
|
444
|
+
async complete() {
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
});
|
|
448
|
+
await emitAdvanceProgress(options, {
|
|
449
|
+
chapter: entry,
|
|
450
|
+
step: "graph",
|
|
451
|
+
targetStage: options.targetStage,
|
|
452
|
+
type: "completed"
|
|
453
|
+
});
|
|
454
|
+
state.advancedIds.add(entry.chapterId);
|
|
455
|
+
}
|
|
456
|
+
return await selectChapterEntries(document, options.chapterId);
|
|
457
|
+
}
|
|
458
|
+
async function advanceEntriesToSummarized(document, entries, options, state) {
|
|
459
|
+
for (const entry of entries) {
|
|
460
|
+
if (entry.stage !== "graphed") {
|
|
461
|
+
continue;
|
|
462
|
+
}
|
|
463
|
+
await emitAdvanceProgress(options, {
|
|
464
|
+
chapter: entry,
|
|
465
|
+
step: "summary",
|
|
466
|
+
targetStage: options.targetStage,
|
|
467
|
+
type: "started"
|
|
468
|
+
});
|
|
469
|
+
await generateChapterSummary(document, entry.chapterId, {
|
|
470
|
+
llm: options.llm,
|
|
471
|
+
...options.logDirPath === void 0 ? {} : { logDirPath: options.logDirPath },
|
|
472
|
+
...options.userLanguage === void 0 ? {} : { userLanguage: options.userLanguage }
|
|
473
|
+
});
|
|
474
|
+
state.progressState.addSummaryWords(entry.words);
|
|
475
|
+
await emitAdvanceProgress(options, {
|
|
476
|
+
state: state.progressState.snapshot(),
|
|
477
|
+
targetStage: options.targetStage,
|
|
478
|
+
type: "progress"
|
|
479
|
+
});
|
|
480
|
+
await emitAdvanceProgress(options, {
|
|
481
|
+
chapter: entry,
|
|
482
|
+
step: "summary",
|
|
483
|
+
targetStage: options.targetStage,
|
|
484
|
+
type: "completed"
|
|
485
|
+
});
|
|
486
|
+
state.advancedIds.add(entry.chapterId);
|
|
487
|
+
}
|
|
488
|
+
return await selectChapterEntries(document, options.chapterId);
|
|
489
|
+
}
|
|
490
|
+
async function selectChapterEntries(document, chapterId) {
|
|
491
|
+
const entries = await listChapters(document);
|
|
492
|
+
if (chapterId === void 0) {
|
|
493
|
+
return entries;
|
|
494
|
+
}
|
|
495
|
+
const selectedIds = await collectChapterSubtreeIds(document, chapterId);
|
|
496
|
+
if (selectedIds.size === 0) {
|
|
497
|
+
throw new Error(
|
|
498
|
+
`Chapter ${chapterId} does not exist. Use \`wg <archive-uri>/chapter list\` to discover chapter ids.`
|
|
499
|
+
);
|
|
500
|
+
}
|
|
501
|
+
return entries.filter((entry) => selectedIds.has(entry.chapterId));
|
|
502
|
+
}
|
|
503
|
+
function createAdvanceProgressState(entries, targetStage) {
|
|
504
|
+
const totalGraphWords = isStageBefore("sourced", targetStage) ? entries.filter((entry) => entry.stage === "sourced").reduce((sum, entry) => sum + entry.words, 0) : 0;
|
|
505
|
+
const totalSummaryWords = isStageBefore("graphed", targetStage) ? entries.filter(
|
|
506
|
+
(entry) => entry.stage === "graphed" || entry.stage === "sourced"
|
|
507
|
+
).reduce((sum, entry) => sum + entry.words, 0) : 0;
|
|
508
|
+
let graphWords = 0;
|
|
509
|
+
let summaryWords = 0;
|
|
510
|
+
return {
|
|
511
|
+
addGraphWords(words) {
|
|
512
|
+
graphWords = Math.min(totalGraphWords, graphWords + Math.max(0, words));
|
|
513
|
+
},
|
|
514
|
+
addSummaryWords(words) {
|
|
515
|
+
summaryWords = Math.min(
|
|
516
|
+
totalSummaryWords,
|
|
517
|
+
summaryWords + Math.max(0, words)
|
|
518
|
+
);
|
|
519
|
+
},
|
|
520
|
+
snapshot() {
|
|
521
|
+
return {
|
|
522
|
+
graphWords,
|
|
523
|
+
summaryWords,
|
|
524
|
+
totalGraphWords,
|
|
525
|
+
totalSummaryWords
|
|
526
|
+
};
|
|
527
|
+
}
|
|
528
|
+
};
|
|
529
|
+
}
|
|
530
|
+
async function collectChapterSubtreeIds(document, chapterId) {
|
|
531
|
+
const toc = await readChapterToc(document);
|
|
532
|
+
const selectedIds = /* @__PURE__ */ new Set();
|
|
533
|
+
for (const item of toc.items) {
|
|
534
|
+
if (collectChapterSubtreeIdsFromItem(item, chapterId, selectedIds)) {
|
|
535
|
+
break;
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
return selectedIds;
|
|
539
|
+
}
|
|
540
|
+
function collectChapterSubtreeIdsFromItem(item, chapterId, selectedIds) {
|
|
541
|
+
if (item.serialId === chapterId) {
|
|
542
|
+
collectChapterIds(item, selectedIds);
|
|
543
|
+
return true;
|
|
544
|
+
}
|
|
545
|
+
for (const child of item.children) {
|
|
546
|
+
if (collectChapterSubtreeIdsFromItem(child, chapterId, selectedIds)) {
|
|
547
|
+
return true;
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
return false;
|
|
551
|
+
}
|
|
552
|
+
function isStageBefore(stage, targetStage) {
|
|
553
|
+
return CHAPTER_STAGES.indexOf(stage) < CHAPTER_STAGES.indexOf(targetStage);
|
|
554
|
+
}
|
|
555
|
+
async function emitPlannedSkips(entries, options) {
|
|
556
|
+
for (const entry of entries) {
|
|
557
|
+
if (entry.stage !== "planned") {
|
|
558
|
+
continue;
|
|
559
|
+
}
|
|
560
|
+
await emitAdvanceProgress(options, {
|
|
561
|
+
chapter: entry,
|
|
562
|
+
reason: "planned",
|
|
563
|
+
targetStage: options.targetStage,
|
|
564
|
+
type: "skipped"
|
|
565
|
+
});
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
async function emitAdvanceProgress(options, event) {
|
|
569
|
+
try {
|
|
570
|
+
await options.onProgress?.(event);
|
|
571
|
+
} catch {
|
|
572
|
+
return;
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
async function resolveChapterStage(document, chapterId, fragmentCount) {
|
|
576
|
+
const summarySentenceCount = await document.readDatabase(
|
|
577
|
+
async (database) => await database.queryOne(
|
|
578
|
+
`
|
|
579
|
+
SELECT COUNT(*) AS count
|
|
580
|
+
FROM text_sentence_records
|
|
581
|
+
WHERE kind = 2 AND chapter_id = ?
|
|
582
|
+
`,
|
|
583
|
+
[chapterId],
|
|
584
|
+
(row) => Number(row.count)
|
|
585
|
+
) ?? 0
|
|
586
|
+
);
|
|
587
|
+
if (summarySentenceCount > 0) {
|
|
588
|
+
return "summarized";
|
|
589
|
+
}
|
|
590
|
+
const serial = await document.serials.getById(chapterId);
|
|
591
|
+
if (serial?.topologyReady === true) {
|
|
592
|
+
return "graphed";
|
|
593
|
+
}
|
|
594
|
+
if (fragmentCount > 0) {
|
|
595
|
+
return "sourced";
|
|
596
|
+
}
|
|
597
|
+
return "planned";
|
|
598
|
+
}
|
|
599
|
+
async function requireChapterDetails(document, chapterId) {
|
|
600
|
+
return await getChapterDetails(document, chapterId);
|
|
601
|
+
}
|
|
602
|
+
function appendChildToChapter(items, parentChapterId, child) {
|
|
603
|
+
for (const item of items) {
|
|
604
|
+
if (item.serialId === parentChapterId) {
|
|
605
|
+
item.children = [...item.children, child];
|
|
606
|
+
return true;
|
|
607
|
+
}
|
|
608
|
+
if (appendChildToChapter(item.children, parentChapterId, child)) {
|
|
609
|
+
return true;
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
return false;
|
|
613
|
+
}
|
|
614
|
+
function createChapterTreeApplyResult(oldMetas, newMetas) {
|
|
615
|
+
const moved = [];
|
|
616
|
+
const renamed = [];
|
|
617
|
+
let unchanged = 0;
|
|
618
|
+
for (const [chapterId, oldMeta] of oldMetas) {
|
|
619
|
+
const newMeta = newMetas.get(chapterId);
|
|
620
|
+
if (newMeta === void 0) {
|
|
621
|
+
continue;
|
|
622
|
+
}
|
|
623
|
+
const movedChapter = oldMeta.parentChapterId !== newMeta.parentChapterId || oldMeta.index !== newMeta.index;
|
|
624
|
+
const renamedChapter = oldMeta.title !== newMeta.title;
|
|
625
|
+
if (movedChapter) {
|
|
626
|
+
moved.push({
|
|
627
|
+
chapterId,
|
|
628
|
+
newIndex: newMeta.index,
|
|
629
|
+
newParentChapterId: newMeta.parentChapterId,
|
|
630
|
+
newPath: newMeta.path,
|
|
631
|
+
oldIndex: oldMeta.index,
|
|
632
|
+
oldParentChapterId: oldMeta.parentChapterId,
|
|
633
|
+
oldPath: oldMeta.path
|
|
634
|
+
});
|
|
635
|
+
}
|
|
636
|
+
if (renamedChapter) {
|
|
637
|
+
renamed.push({
|
|
638
|
+
chapterId,
|
|
639
|
+
newTitle: newMeta.title,
|
|
640
|
+
oldTitle: oldMeta.title
|
|
641
|
+
});
|
|
642
|
+
}
|
|
643
|
+
if (!movedChapter && !renamedChapter) {
|
|
644
|
+
unchanged += 1;
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
return {
|
|
648
|
+
changed: moved.length > 0 || renamed.length > 0,
|
|
649
|
+
moved,
|
|
650
|
+
renamed,
|
|
651
|
+
unchanged
|
|
652
|
+
};
|
|
653
|
+
}
|
|
654
|
+
function createTocItemsFromChapterTree(tree, oldItems) {
|
|
655
|
+
const oldItemsById = /* @__PURE__ */ new Map();
|
|
656
|
+
const oldIds = /* @__PURE__ */ new Set();
|
|
657
|
+
for (const oldItem of oldItems) {
|
|
658
|
+
collectTocItemsById(oldItem, oldItemsById, oldIds);
|
|
659
|
+
}
|
|
660
|
+
const seenIds = /* @__PURE__ */ new Set();
|
|
661
|
+
const items = tree.chapters.map(
|
|
662
|
+
(node) => createTocItemFromChapterTreeNode(node, oldItemsById, seenIds)
|
|
663
|
+
);
|
|
664
|
+
const missingIds = [...oldIds].filter((id) => !seenIds.has(id));
|
|
665
|
+
if (missingIds.length > 0) {
|
|
666
|
+
throw new Error(
|
|
667
|
+
`Chapter tree is missing chapter ids: ${missingIds.join(", ")}.`
|
|
668
|
+
);
|
|
669
|
+
}
|
|
670
|
+
return { items };
|
|
671
|
+
}
|
|
672
|
+
function createTocItemFromChapterTreeNode(node, oldItemsById, seenIds) {
|
|
673
|
+
const oldItem = oldItemsById.get(node.id);
|
|
674
|
+
if (oldItem === void 0) {
|
|
675
|
+
throw new Error(`Chapter tree references unknown chapter id: ${node.id}.`);
|
|
676
|
+
}
|
|
677
|
+
if (seenIds.has(node.id)) {
|
|
678
|
+
throw new Error(`Chapter tree repeats chapter id: ${node.id}.`);
|
|
679
|
+
}
|
|
680
|
+
seenIds.add(node.id);
|
|
681
|
+
const title = Object.prototype.hasOwnProperty.call(node, "title") ? normalizeTitle(node.title) : normalizeTitle(oldItem.title);
|
|
682
|
+
const item = {
|
|
683
|
+
children: node.children.map(
|
|
684
|
+
(child) => createTocItemFromChapterTreeNode(child, oldItemsById, seenIds)
|
|
685
|
+
),
|
|
686
|
+
serialId: node.id
|
|
687
|
+
};
|
|
688
|
+
if (title !== void 0) {
|
|
689
|
+
item.title = title;
|
|
690
|
+
}
|
|
691
|
+
return item;
|
|
692
|
+
}
|
|
693
|
+
function collectTocItemsById(item, itemsById, ids) {
|
|
694
|
+
if (item.serialId !== void 0) {
|
|
695
|
+
itemsById.set(item.serialId, item);
|
|
696
|
+
ids.add(item.serialId);
|
|
697
|
+
}
|
|
698
|
+
for (const child of item.children) {
|
|
699
|
+
collectTocItemsById(child, itemsById, ids);
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
function collectTocItemMetas(items, parentChapterId = null, parentPath = []) {
|
|
703
|
+
const metas = /* @__PURE__ */ new Map();
|
|
704
|
+
items.forEach((item, index) => {
|
|
705
|
+
if (item.serialId === void 0) {
|
|
706
|
+
return;
|
|
707
|
+
}
|
|
708
|
+
const title = normalizeTitle(item.title) ?? null;
|
|
709
|
+
const path = [...parentPath, title ?? `Chapter ${item.serialId}`];
|
|
710
|
+
metas.set(item.serialId, {
|
|
711
|
+
index,
|
|
712
|
+
parentChapterId,
|
|
713
|
+
path,
|
|
714
|
+
title
|
|
715
|
+
});
|
|
716
|
+
for (const [childId, childMeta] of collectTocItemMetas(
|
|
717
|
+
item.children,
|
|
718
|
+
item.serialId,
|
|
719
|
+
path
|
|
720
|
+
)) {
|
|
721
|
+
metas.set(childId, childMeta);
|
|
722
|
+
}
|
|
723
|
+
});
|
|
724
|
+
return metas;
|
|
725
|
+
}
|
|
726
|
+
function extractChapterItem(items, chapterId) {
|
|
727
|
+
const nextItems = [];
|
|
728
|
+
for (const item of items) {
|
|
729
|
+
if (item.serialId === chapterId) {
|
|
730
|
+
return {
|
|
731
|
+
item,
|
|
732
|
+
items: [...nextItems, ...items.slice(nextItems.length + 1)]
|
|
733
|
+
};
|
|
734
|
+
}
|
|
735
|
+
const childResult = extractChapterItem(item.children, chapterId);
|
|
736
|
+
if (childResult.item !== void 0) {
|
|
737
|
+
nextItems.push({
|
|
738
|
+
...item,
|
|
739
|
+
children: childResult.items
|
|
740
|
+
});
|
|
741
|
+
nextItems.push(...items.slice(nextItems.length));
|
|
742
|
+
return {
|
|
743
|
+
item: childResult.item,
|
|
744
|
+
items: nextItems
|
|
745
|
+
};
|
|
746
|
+
}
|
|
747
|
+
nextItems.push(item);
|
|
748
|
+
}
|
|
749
|
+
return {
|
|
750
|
+
items: [...items]
|
|
751
|
+
};
|
|
752
|
+
}
|
|
753
|
+
function findChildContainer(items, parentChapterId) {
|
|
754
|
+
if (parentChapterId === void 0) {
|
|
755
|
+
return items;
|
|
756
|
+
}
|
|
757
|
+
for (const item of items) {
|
|
758
|
+
if (item.serialId === parentChapterId) {
|
|
759
|
+
return item.children;
|
|
760
|
+
}
|
|
761
|
+
const childContainer = findChildContainer(item.children, parentChapterId);
|
|
762
|
+
if (childContainer !== void 0) {
|
|
763
|
+
return childContainer;
|
|
764
|
+
}
|
|
765
|
+
}
|
|
766
|
+
return void 0;
|
|
767
|
+
}
|
|
768
|
+
function findChapterLocation(items, chapterId) {
|
|
769
|
+
return findChapterLocationInItems(items, chapterId);
|
|
770
|
+
}
|
|
771
|
+
function findChapterLocationInItems(items, chapterId, parentChapterId) {
|
|
772
|
+
for (const [index, item] of items.entries()) {
|
|
773
|
+
if (item.serialId === chapterId) {
|
|
774
|
+
return {
|
|
775
|
+
index,
|
|
776
|
+
parentChapterId,
|
|
777
|
+
siblings: items
|
|
778
|
+
};
|
|
779
|
+
}
|
|
780
|
+
const location = findChapterLocationInItems(
|
|
781
|
+
item.children,
|
|
782
|
+
chapterId,
|
|
783
|
+
item.serialId
|
|
784
|
+
);
|
|
785
|
+
if (location !== void 0) {
|
|
786
|
+
return location;
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
return void 0;
|
|
790
|
+
}
|
|
791
|
+
function insertMovedChapter(items, item, options) {
|
|
792
|
+
if (options.beforeChapterId !== void 0 || options.afterChapterId !== void 0) {
|
|
793
|
+
const targetChapterId = options.beforeChapterId ?? options.afterChapterId;
|
|
794
|
+
const location = findChapterLocation(items, targetChapterId);
|
|
795
|
+
if (location === void 0) {
|
|
796
|
+
throw new Error(`Target chapter ${targetChapterId} does not exist.`);
|
|
797
|
+
}
|
|
798
|
+
location.siblings.splice(
|
|
799
|
+
options.beforeChapterId === void 0 ? location.index + 1 : location.index,
|
|
800
|
+
0,
|
|
801
|
+
item
|
|
802
|
+
);
|
|
803
|
+
return;
|
|
804
|
+
}
|
|
805
|
+
const parentChapterId = options.root === true ? void 0 : options.parentChapterId !== void 0 ? options.parentChapterId : options.originalParentChapterId;
|
|
806
|
+
const container = findChildContainer(items, parentChapterId);
|
|
807
|
+
if (container === void 0) {
|
|
808
|
+
throw new Error(`Chapter ${parentChapterId} does not exist.`);
|
|
809
|
+
}
|
|
810
|
+
if (options.first === true) {
|
|
811
|
+
container.splice(0, 0, item);
|
|
812
|
+
} else {
|
|
813
|
+
container.push(item);
|
|
814
|
+
}
|
|
815
|
+
}
|
|
816
|
+
function rejectMoveIntoOwnSubtree(chapterId, item, options) {
|
|
817
|
+
const targetIds = [
|
|
818
|
+
options.parentChapterId,
|
|
819
|
+
options.beforeChapterId,
|
|
820
|
+
options.afterChapterId
|
|
821
|
+
].filter((id) => id !== void 0);
|
|
822
|
+
for (const targetId of targetIds) {
|
|
823
|
+
if (targetId === chapterId || containsChapterId(item.children, targetId)) {
|
|
824
|
+
throw new Error(
|
|
825
|
+
`Cannot move chapter ${chapterId} into or next to its own descendant ${targetId}.`
|
|
826
|
+
);
|
|
827
|
+
}
|
|
828
|
+
}
|
|
829
|
+
}
|
|
830
|
+
function containsChapterId(items, chapterId) {
|
|
831
|
+
for (const item of items) {
|
|
832
|
+
if (item.serialId === chapterId || containsChapterId(item.children, chapterId)) {
|
|
833
|
+
return true;
|
|
834
|
+
}
|
|
835
|
+
}
|
|
836
|
+
return false;
|
|
837
|
+
}
|
|
838
|
+
function cloneTocItem(item) {
|
|
839
|
+
return {
|
|
840
|
+
children: item.children.map(cloneTocItem),
|
|
841
|
+
...item.serialId === void 0 ? {} : { serialId: item.serialId },
|
|
842
|
+
title: item.title
|
|
843
|
+
};
|
|
844
|
+
}
|
|
845
|
+
function toChapterTreeNode(item) {
|
|
846
|
+
if (item.serialId === void 0) {
|
|
847
|
+
throw new Error("Internal error: normalized chapter tree has no id.");
|
|
848
|
+
}
|
|
849
|
+
return {
|
|
850
|
+
children: item.children.flatMap(toChapterTreeNodes),
|
|
851
|
+
id: item.serialId,
|
|
852
|
+
title: normalizeTitle(item.title) ?? null
|
|
853
|
+
};
|
|
854
|
+
}
|
|
855
|
+
function toChapterTreeNodes(item) {
|
|
856
|
+
return item.serialId === void 0 ? item.children.flatMap(toChapterTreeNodes) : [toChapterTreeNode(item)];
|
|
857
|
+
}
|
|
858
|
+
function createTopologyOptions(options) {
|
|
859
|
+
return {
|
|
860
|
+
extractionPrompt: options.extractionPrompt,
|
|
861
|
+
...options.userLanguage === void 0 ? {} : { userLanguage: options.userLanguage }
|
|
862
|
+
};
|
|
863
|
+
}
|
|
864
|
+
function normalizeTitle(title) {
|
|
865
|
+
const normalized = title?.trim();
|
|
866
|
+
return normalized === void 0 || normalized === "" ? void 0 : normalized;
|
|
867
|
+
}
|
|
868
|
+
function removeChapterFromItems(items, chapterId, options) {
|
|
869
|
+
const nextItems = [];
|
|
870
|
+
let removed = false;
|
|
871
|
+
for (const item of items) {
|
|
872
|
+
if (item.serialId === chapterId) {
|
|
873
|
+
if (!options.recursive && item.children.length > 0) {
|
|
874
|
+
throw new Error(
|
|
875
|
+
`Chapter ${chapterId} has child chapters. Use --recursive to remove it and its descendants.`
|
|
876
|
+
);
|
|
877
|
+
}
|
|
878
|
+
collectChapterIds(item, options.removedChapterIds);
|
|
879
|
+
removed = true;
|
|
880
|
+
continue;
|
|
881
|
+
}
|
|
882
|
+
const childResult = removeChapterFromItems(
|
|
883
|
+
item.children,
|
|
884
|
+
chapterId,
|
|
885
|
+
options
|
|
886
|
+
);
|
|
887
|
+
nextItems.push({
|
|
888
|
+
...item,
|
|
889
|
+
children: childResult.items
|
|
890
|
+
});
|
|
891
|
+
removed ||= childResult.removed;
|
|
892
|
+
}
|
|
893
|
+
return {
|
|
894
|
+
items: nextItems,
|
|
895
|
+
removed
|
|
896
|
+
};
|
|
897
|
+
}
|
|
898
|
+
function setChapterTitleInItems(items, chapterId, title) {
|
|
899
|
+
for (const item of items) {
|
|
900
|
+
if (item.serialId === chapterId) {
|
|
901
|
+
if (title === void 0) {
|
|
902
|
+
delete item.title;
|
|
903
|
+
} else {
|
|
904
|
+
item.title = title;
|
|
905
|
+
}
|
|
906
|
+
return true;
|
|
907
|
+
}
|
|
908
|
+
if (setChapterTitleInItems(item.children, chapterId, title)) {
|
|
909
|
+
return true;
|
|
910
|
+
}
|
|
911
|
+
}
|
|
912
|
+
return false;
|
|
913
|
+
}
|
|
914
|
+
function collectChapterIds(item, chapterIds) {
|
|
915
|
+
if (item.serialId !== void 0) {
|
|
916
|
+
if (Array.isArray(chapterIds)) {
|
|
917
|
+
chapterIds.push(item.serialId);
|
|
918
|
+
} else {
|
|
919
|
+
chapterIds.add(item.serialId);
|
|
920
|
+
}
|
|
921
|
+
}
|
|
922
|
+
for (const child of item.children) {
|
|
923
|
+
collectChapterIds(child, chapterIds);
|
|
924
|
+
}
|
|
925
|
+
}
|
|
926
|
+
export {
|
|
927
|
+
CHAPTER_STAGES,
|
|
928
|
+
addChapter,
|
|
929
|
+
advanceChapterStages,
|
|
930
|
+
applyChapterTree,
|
|
931
|
+
generateChapterGraph,
|
|
932
|
+
generateChapterSummary,
|
|
933
|
+
getChapterDetails,
|
|
934
|
+
getChapterTree,
|
|
935
|
+
listChapters,
|
|
936
|
+
moveChapter,
|
|
937
|
+
parseChapterTreeInput,
|
|
938
|
+
removeChapter,
|
|
939
|
+
resetChapter,
|
|
940
|
+
setChapterSource,
|
|
941
|
+
setChapterSummary,
|
|
942
|
+
setChapterTitle
|
|
943
|
+
};
|
|
944
|
+
//# sourceMappingURL=chapter.js.map
|