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,640 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import {
|
|
3
|
+
GuaranteedParseValidationError,
|
|
4
|
+
ParsedJsonError,
|
|
5
|
+
requestGuaranteedJson
|
|
6
|
+
} from "../../guaranteed/index.js";
|
|
7
|
+
import {
|
|
8
|
+
ChunkImportance,
|
|
9
|
+
ChunkRetention,
|
|
10
|
+
expectChunkImportance,
|
|
11
|
+
expectChunkRetention
|
|
12
|
+
} from "../../document/index.js";
|
|
13
|
+
import {
|
|
14
|
+
resolveEvidenceSelectionList,
|
|
15
|
+
EvidenceResolver
|
|
16
|
+
} from "../../evidence-selection/index.js";
|
|
17
|
+
const MAX_CHOICE_RETRIES = 3;
|
|
18
|
+
const chunkLinkSchema = z.object({
|
|
19
|
+
from: z.union([z.number().int(), z.string()]),
|
|
20
|
+
strength: z.string().optional(),
|
|
21
|
+
to: z.union([z.number().int(), z.string()])
|
|
22
|
+
});
|
|
23
|
+
const evidenceSelectionItemSchema = z.object({
|
|
24
|
+
quote: z.string().optional(),
|
|
25
|
+
sentence_id: z.string().optional()
|
|
26
|
+
}).passthrough();
|
|
27
|
+
const chunkEvidenceSchema = z.union([
|
|
28
|
+
z.record(z.string(), z.unknown()),
|
|
29
|
+
z.array(evidenceSelectionItemSchema)
|
|
30
|
+
]);
|
|
31
|
+
const userFocusedChunkSchema = z.object({
|
|
32
|
+
content: z.string(),
|
|
33
|
+
evidence: chunkEvidenceSchema.nullish(),
|
|
34
|
+
label: z.string(),
|
|
35
|
+
retention: z.enum([
|
|
36
|
+
ChunkRetention.Verbatim,
|
|
37
|
+
ChunkRetention.Detailed,
|
|
38
|
+
ChunkRetention.Focused,
|
|
39
|
+
ChunkRetention.Relevant
|
|
40
|
+
]),
|
|
41
|
+
temp_id: z.string()
|
|
42
|
+
}).passthrough();
|
|
43
|
+
const userFocusedResponseSchema = z.object({
|
|
44
|
+
chunks: z.array(userFocusedChunkSchema),
|
|
45
|
+
fragment_summary: z.string(),
|
|
46
|
+
links: z.array(chunkLinkSchema)
|
|
47
|
+
});
|
|
48
|
+
const bookCoherenceChunkSchema = z.object({
|
|
49
|
+
content: z.string(),
|
|
50
|
+
evidence: chunkEvidenceSchema.nullish(),
|
|
51
|
+
importance: z.enum([
|
|
52
|
+
ChunkImportance.Critical,
|
|
53
|
+
ChunkImportance.Important,
|
|
54
|
+
ChunkImportance.Helpful
|
|
55
|
+
]),
|
|
56
|
+
label: z.string(),
|
|
57
|
+
temp_id: z.string()
|
|
58
|
+
}).passthrough();
|
|
59
|
+
const importanceAnnotationSchema = z.object({
|
|
60
|
+
chunk_id: z.number().int(),
|
|
61
|
+
importance: z.enum([
|
|
62
|
+
ChunkImportance.Critical,
|
|
63
|
+
ChunkImportance.Important,
|
|
64
|
+
ChunkImportance.Helpful
|
|
65
|
+
])
|
|
66
|
+
});
|
|
67
|
+
const bookCoherenceResponseSchema = z.object({
|
|
68
|
+
chunks: z.array(bookCoherenceChunkSchema),
|
|
69
|
+
importance_annotations: z.array(importanceAnnotationSchema),
|
|
70
|
+
links: z.array(chunkLinkSchema)
|
|
71
|
+
});
|
|
72
|
+
const choiceResponseSchema = z.object({
|
|
73
|
+
choice: z.string()
|
|
74
|
+
});
|
|
75
|
+
var ChunkMetadataField = /* @__PURE__ */ ((ChunkMetadataField2) => {
|
|
76
|
+
ChunkMetadataField2["Retention"] = "retention";
|
|
77
|
+
ChunkMetadataField2["Importance"] = "importance";
|
|
78
|
+
return ChunkMetadataField2;
|
|
79
|
+
})(ChunkMetadataField || {});
|
|
80
|
+
class ChunkBatchParser {
|
|
81
|
+
#choiceSystemPrompt;
|
|
82
|
+
#evidenceResolver = new EvidenceResolver();
|
|
83
|
+
#metadataField;
|
|
84
|
+
#projection;
|
|
85
|
+
#responseIntentClassifierPrompt;
|
|
86
|
+
#requestChoice;
|
|
87
|
+
#sentenceTextByKey;
|
|
88
|
+
#sentenceTextSource;
|
|
89
|
+
#wordsCountByKey;
|
|
90
|
+
#validImportanceChunkIds;
|
|
91
|
+
#visibleChunkIds;
|
|
92
|
+
constructor(input) {
|
|
93
|
+
this.#choiceSystemPrompt = input.choiceSystemPrompt;
|
|
94
|
+
this.#metadataField = input.metadataField;
|
|
95
|
+
this.#projection = input.projection;
|
|
96
|
+
this.#responseIntentClassifierPrompt = input.responseIntentClassifierPrompt;
|
|
97
|
+
this.#requestChoice = input.requestChoice;
|
|
98
|
+
this.#sentenceTextSource = input.sentenceTextSource;
|
|
99
|
+
this.#visibleChunkIds = input.visibleChunkIds;
|
|
100
|
+
this.#wordsCountByKey = createWordsCountRecord(
|
|
101
|
+
input.projection.sentences.map((sentence) => ({
|
|
102
|
+
sentenceId: sentence.sentenceId,
|
|
103
|
+
wordsCount: sentence.wordsCount
|
|
104
|
+
}))
|
|
105
|
+
);
|
|
106
|
+
this.#sentenceTextByKey = createSentenceTextRecord(input.projection);
|
|
107
|
+
this.#validImportanceChunkIds = input.validImportanceChunkIds === void 0 ? void 0 : createMembershipRecord(input.validImportanceChunkIds);
|
|
108
|
+
}
|
|
109
|
+
async parse(parsedData, input) {
|
|
110
|
+
const issues = [];
|
|
111
|
+
const chunks = [];
|
|
112
|
+
const tempIds = [];
|
|
113
|
+
const importanceAnnotations = "importance_annotations" in parsedData ? this.#validateImportanceAnnotations(
|
|
114
|
+
parsedData.importance_annotations,
|
|
115
|
+
issues
|
|
116
|
+
) : void 0;
|
|
117
|
+
const fragmentSummary = "fragment_summary" in parsedData ? parsedData.fragment_summary : void 0;
|
|
118
|
+
const links = normalizeChunkLinks(parsedData.links);
|
|
119
|
+
for (const [index, data] of parsedData.chunks.entries()) {
|
|
120
|
+
const chunkIndex = index + 1;
|
|
121
|
+
const chunkIssues = [];
|
|
122
|
+
const label = data.label.trim();
|
|
123
|
+
const content = data.content.trim();
|
|
124
|
+
if (label === "") {
|
|
125
|
+
chunkIssues.push(
|
|
126
|
+
`Chunk #${chunkIndex}: Missing or empty "label" field`
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
if (content === "") {
|
|
130
|
+
chunkIssues.push(
|
|
131
|
+
`Chunk #${chunkIndex}: Missing or empty "content" field`
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
const [matchedSentenceIds, evidenceFailure] = await this.#resolveChunkEvidence({
|
|
135
|
+
chunkIndex,
|
|
136
|
+
chunkLabel: label,
|
|
137
|
+
data,
|
|
138
|
+
isLastGenerationAttempt: input.isLastGenerationAttempt
|
|
139
|
+
});
|
|
140
|
+
if (matchedSentenceIds.length === 0) {
|
|
141
|
+
if (evidenceFailure !== void 0) {
|
|
142
|
+
chunkIssues.push(
|
|
143
|
+
`Chunk #${chunkIndex} ("${label}"): ${evidenceFailure.message}`
|
|
144
|
+
);
|
|
145
|
+
} else {
|
|
146
|
+
chunkIssues.push(
|
|
147
|
+
`Chunk #${chunkIndex} ("${label}"): Missing evidence`
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
if (chunkIssues.length > 0) {
|
|
152
|
+
issues.push(...chunkIssues);
|
|
153
|
+
continue;
|
|
154
|
+
}
|
|
155
|
+
const primarySentenceId = matchedSentenceIds[0];
|
|
156
|
+
if (primarySentenceId === void 0) {
|
|
157
|
+
issues.push(
|
|
158
|
+
`Chunk #${chunkIndex} ("${label}"): Unable to resolve any sentence IDs`
|
|
159
|
+
);
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
const totalWordsCount = matchedSentenceIds.reduce((sum, sentenceId) => {
|
|
163
|
+
return sum + (this.#wordsCountByKey[createSentenceKey(sentenceId)] ?? 0);
|
|
164
|
+
}, 0);
|
|
165
|
+
if (this.#metadataField === "retention" /* Retention */) {
|
|
166
|
+
const chunkData = data;
|
|
167
|
+
chunks.push({
|
|
168
|
+
content,
|
|
169
|
+
generation: 0,
|
|
170
|
+
id: 0,
|
|
171
|
+
label,
|
|
172
|
+
links: [],
|
|
173
|
+
retention: expectChunkRetention(chunkData.retention),
|
|
174
|
+
sentenceId: primarySentenceId,
|
|
175
|
+
sentenceIds: [...matchedSentenceIds],
|
|
176
|
+
wordsCount: totalWordsCount
|
|
177
|
+
});
|
|
178
|
+
} else {
|
|
179
|
+
const chunkData = data;
|
|
180
|
+
chunks.push({
|
|
181
|
+
content,
|
|
182
|
+
generation: 0,
|
|
183
|
+
id: 0,
|
|
184
|
+
importance: expectChunkImportance(chunkData.importance),
|
|
185
|
+
label,
|
|
186
|
+
links: [],
|
|
187
|
+
sentenceId: primarySentenceId,
|
|
188
|
+
sentenceIds: [...matchedSentenceIds],
|
|
189
|
+
wordsCount: totalWordsCount
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
tempIds.push(data.temp_id);
|
|
193
|
+
}
|
|
194
|
+
const validLinks = this.#filterAndValidateLinks({
|
|
195
|
+
issues,
|
|
196
|
+
links,
|
|
197
|
+
tempIds,
|
|
198
|
+
visibleChunkIds: this.#visibleChunkIds
|
|
199
|
+
});
|
|
200
|
+
if (issues.length > 0) {
|
|
201
|
+
throw new ParsedJsonError(issues);
|
|
202
|
+
}
|
|
203
|
+
return {
|
|
204
|
+
chunkBatch: {
|
|
205
|
+
chunks,
|
|
206
|
+
links: validLinks,
|
|
207
|
+
orderCorrect: true,
|
|
208
|
+
tempIds,
|
|
209
|
+
...importanceAnnotations === void 0 ? {} : { importanceAnnotations }
|
|
210
|
+
},
|
|
211
|
+
...fragmentSummary === void 0 ? {} : { fragmentSummary }
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
async getChunkSourceSentences(chunk) {
|
|
215
|
+
const sourceSentences = [];
|
|
216
|
+
for (const sentenceId of chunk.sentenceIds) {
|
|
217
|
+
const sentenceKey = createSentenceKey(sentenceId);
|
|
218
|
+
const sentenceText = this.#sentenceTextByKey[sentenceKey];
|
|
219
|
+
if (sentenceText !== void 0) {
|
|
220
|
+
sourceSentences.push(sentenceText);
|
|
221
|
+
continue;
|
|
222
|
+
}
|
|
223
|
+
sourceSentences.push(
|
|
224
|
+
await this.#sentenceTextSource.getSentence(sentenceId)
|
|
225
|
+
);
|
|
226
|
+
}
|
|
227
|
+
return sourceSentences;
|
|
228
|
+
}
|
|
229
|
+
async #resolveChunkEvidence(input) {
|
|
230
|
+
const evidence = input.data.evidence;
|
|
231
|
+
if (evidence === void 0 || evidence === null) {
|
|
232
|
+
return [[], void 0];
|
|
233
|
+
}
|
|
234
|
+
if (!isRecord(evidence) && !Array.isArray(evidence)) {
|
|
235
|
+
return [
|
|
236
|
+
[],
|
|
237
|
+
{
|
|
238
|
+
candidates: [],
|
|
239
|
+
code: "invalid_evidence",
|
|
240
|
+
fieldName: "evidence",
|
|
241
|
+
message: `Chunk #${input.chunkIndex} ("${input.chunkLabel}"): evidence must be an object or array`
|
|
242
|
+
}
|
|
243
|
+
];
|
|
244
|
+
}
|
|
245
|
+
const projectedSentences = this.#projection.sentences;
|
|
246
|
+
const candidateSentenceIds = projectedSentences.map(
|
|
247
|
+
(sentence) => sentence.sentenceId
|
|
248
|
+
);
|
|
249
|
+
const selectionSentences = projectedSentences.map((sentence, index) => ({
|
|
250
|
+
id: `S${index + 1}`,
|
|
251
|
+
sentenceId: sentence.sentenceId,
|
|
252
|
+
text: sentence.projectedText
|
|
253
|
+
}));
|
|
254
|
+
const selectionEvidence = createEvidenceSelectionList(evidence);
|
|
255
|
+
const [selectionResolution, selectionFailure] = selectionEvidence === void 0 ? [void 0, void 0] : resolveEvidenceSelectionList({
|
|
256
|
+
evidence: selectionEvidence,
|
|
257
|
+
sentences: selectionSentences
|
|
258
|
+
});
|
|
259
|
+
if (selectionResolution !== void 0) {
|
|
260
|
+
return [selectionResolution.sentenceIds, void 0];
|
|
261
|
+
}
|
|
262
|
+
const exactMatchSentenceIds = Array.isArray(evidence) ? [] : this.#resolveExactProjectionEvidence(evidence);
|
|
263
|
+
if (exactMatchSentenceIds.length > 0) {
|
|
264
|
+
return [exactMatchSentenceIds, void 0];
|
|
265
|
+
}
|
|
266
|
+
const candidateTexts = projectedSentences.map(
|
|
267
|
+
(sentence) => sentence.projectedText
|
|
268
|
+
);
|
|
269
|
+
const [resolution, failure] = Array.isArray(evidence) ? [void 0, void 0] : this.#evidenceResolver.resolve(
|
|
270
|
+
evidence,
|
|
271
|
+
candidateSentenceIds,
|
|
272
|
+
candidateTexts
|
|
273
|
+
);
|
|
274
|
+
if (resolution !== void 0) {
|
|
275
|
+
return [resolution.sentenceIds, void 0];
|
|
276
|
+
}
|
|
277
|
+
const fallbackFailure = selectionFailure === void 0 ? failure : toEvidenceResolutionFailure(selectionFailure, "evidence");
|
|
278
|
+
if (fallbackFailure === void 0) {
|
|
279
|
+
return [[], void 0];
|
|
280
|
+
}
|
|
281
|
+
const shouldUseChoice = fallbackFailure.code.startsWith("ambiguous") || fallbackFailure.code === "low_confidence" && input.isLastGenerationAttempt && fallbackFailure.candidates.length > 0;
|
|
282
|
+
if (!shouldUseChoice) {
|
|
283
|
+
return [[], fallbackFailure];
|
|
284
|
+
}
|
|
285
|
+
const choiceFieldName = toChoiceFieldName(fallbackFailure.fieldName);
|
|
286
|
+
if (choiceFieldName === void 0) {
|
|
287
|
+
return [[], fallbackFailure];
|
|
288
|
+
}
|
|
289
|
+
const [choiceCandidate, choiceFailure] = await this.#chooseAmbiguousCandidate({
|
|
290
|
+
candidates: fallbackFailure.candidates,
|
|
291
|
+
chunkData: input.data,
|
|
292
|
+
chunkIndex: input.chunkIndex,
|
|
293
|
+
chunkLabel: input.chunkLabel,
|
|
294
|
+
fieldName: choiceFieldName
|
|
295
|
+
});
|
|
296
|
+
if (choiceFailure !== void 0) {
|
|
297
|
+
if (choiceFailure.code === "choice_parse_failed_full_fragment") {
|
|
298
|
+
return [candidateSentenceIds, void 0];
|
|
299
|
+
}
|
|
300
|
+
return [[], choiceFailure];
|
|
301
|
+
}
|
|
302
|
+
if (choiceCandidate === void 0) {
|
|
303
|
+
return [
|
|
304
|
+
[],
|
|
305
|
+
{
|
|
306
|
+
candidates: fallbackFailure.candidates,
|
|
307
|
+
code: "choice_failed",
|
|
308
|
+
fieldName: fallbackFailure.fieldName,
|
|
309
|
+
message: `Second-stage choice failed for ${fallbackFailure.fieldName}: no candidate returned.`
|
|
310
|
+
}
|
|
311
|
+
];
|
|
312
|
+
}
|
|
313
|
+
if (choiceFieldName === "evidence") {
|
|
314
|
+
return [[choiceCandidate.sentenceId], void 0];
|
|
315
|
+
}
|
|
316
|
+
if (Array.isArray(evidence)) {
|
|
317
|
+
return [[], fallbackFailure];
|
|
318
|
+
}
|
|
319
|
+
if (input.isLastGenerationAttempt) {
|
|
320
|
+
const [resolved2, resolveFailure2] = this.#evidenceResolver.resolveWithOverrides({
|
|
321
|
+
candidateSentenceIds,
|
|
322
|
+
candidateTexts,
|
|
323
|
+
evidence,
|
|
324
|
+
overrides: {
|
|
325
|
+
[choiceFieldName]: choiceCandidate
|
|
326
|
+
}
|
|
327
|
+
});
|
|
328
|
+
if (resolved2 !== void 0) {
|
|
329
|
+
return [resolved2.sentenceIds, void 0];
|
|
330
|
+
}
|
|
331
|
+
return [[], resolveFailure2];
|
|
332
|
+
}
|
|
333
|
+
const repairedEvidence = {
|
|
334
|
+
...evidence,
|
|
335
|
+
[choiceFieldName]: {
|
|
336
|
+
mode: "full",
|
|
337
|
+
text: choiceCandidate.text
|
|
338
|
+
}
|
|
339
|
+
};
|
|
340
|
+
const [resolved, resolveFailure] = this.#evidenceResolver.resolve(
|
|
341
|
+
repairedEvidence,
|
|
342
|
+
candidateSentenceIds,
|
|
343
|
+
candidateTexts
|
|
344
|
+
);
|
|
345
|
+
if (resolved !== void 0) {
|
|
346
|
+
return [resolved.sentenceIds, void 0];
|
|
347
|
+
}
|
|
348
|
+
return [[], resolveFailure];
|
|
349
|
+
}
|
|
350
|
+
#resolveExactProjectionEvidence(evidence) {
|
|
351
|
+
const startValue = evidence.start_anchor ?? evidence.start;
|
|
352
|
+
const [startAnchor, startFailure] = this.#evidenceResolver.parseAnchor(
|
|
353
|
+
startValue,
|
|
354
|
+
"start_anchor"
|
|
355
|
+
);
|
|
356
|
+
if (startFailure !== void 0 || startAnchor?.text === void 0) {
|
|
357
|
+
return [];
|
|
358
|
+
}
|
|
359
|
+
const startMatch = expectSingleSpan(
|
|
360
|
+
this.#projection.findExactMatches(startAnchor.text)
|
|
361
|
+
);
|
|
362
|
+
if (startMatch === void 0) {
|
|
363
|
+
return [];
|
|
364
|
+
}
|
|
365
|
+
const endValue = evidence.end_anchor ?? evidence.end;
|
|
366
|
+
if (endValue === void 0) {
|
|
367
|
+
return this.#projection.resolveSentenceIds(startMatch);
|
|
368
|
+
}
|
|
369
|
+
const [endAnchor, endFailure] = this.#evidenceResolver.parseAnchor(
|
|
370
|
+
endValue,
|
|
371
|
+
"end_anchor"
|
|
372
|
+
);
|
|
373
|
+
if (endFailure !== void 0 || endAnchor?.text === void 0) {
|
|
374
|
+
return [];
|
|
375
|
+
}
|
|
376
|
+
const endMatch = expectSingleSpan(
|
|
377
|
+
this.#projection.findExactMatches(endAnchor.text)
|
|
378
|
+
);
|
|
379
|
+
if (endMatch === void 0 || endMatch.offset < startMatch.offset) {
|
|
380
|
+
return [];
|
|
381
|
+
}
|
|
382
|
+
return this.#projection.resolveSentenceIds({
|
|
383
|
+
length: endMatch.offset + endMatch.length - startMatch.offset,
|
|
384
|
+
offset: startMatch.offset
|
|
385
|
+
});
|
|
386
|
+
}
|
|
387
|
+
async #chooseAmbiguousCandidate(input) {
|
|
388
|
+
const messages = this.#buildChoiceMessages(input);
|
|
389
|
+
const candidateIds = input.candidates.map(
|
|
390
|
+
(candidate) => candidate.occurrenceId
|
|
391
|
+
);
|
|
392
|
+
try {
|
|
393
|
+
const choice = await requestGuaranteedJson({
|
|
394
|
+
maxRetries: MAX_CHOICE_RETRIES,
|
|
395
|
+
messages,
|
|
396
|
+
parse: (data) => {
|
|
397
|
+
const candidate = input.candidates.find(
|
|
398
|
+
(item) => item.occurrenceId === data.choice
|
|
399
|
+
);
|
|
400
|
+
if (candidate === void 0) {
|
|
401
|
+
throw new ParsedJsonError([
|
|
402
|
+
`Invalid choice "${data.choice}". Expected one of: ${candidateIds.join(", ")}`
|
|
403
|
+
]);
|
|
404
|
+
}
|
|
405
|
+
return candidate;
|
|
406
|
+
},
|
|
407
|
+
responseIntentClassifierPrompt: this.#responseIntentClassifierPrompt,
|
|
408
|
+
request: this.#requestChoice,
|
|
409
|
+
schema: choiceResponseSchema
|
|
410
|
+
});
|
|
411
|
+
return [choice, void 0];
|
|
412
|
+
} catch (error) {
|
|
413
|
+
if (isParsedJsonValidationFailure(error)) {
|
|
414
|
+
return [
|
|
415
|
+
void 0,
|
|
416
|
+
{
|
|
417
|
+
candidates: input.candidates,
|
|
418
|
+
code: "choice_parse_failed_full_fragment",
|
|
419
|
+
fieldName: input.fieldName,
|
|
420
|
+
message: `Second-stage choice parse validation failed for ${input.fieldName}; falling back to the full fragment span.`
|
|
421
|
+
}
|
|
422
|
+
];
|
|
423
|
+
}
|
|
424
|
+
return [
|
|
425
|
+
void 0,
|
|
426
|
+
{
|
|
427
|
+
candidates: input.candidates,
|
|
428
|
+
code: "choice_failed",
|
|
429
|
+
fieldName: input.fieldName,
|
|
430
|
+
message: `Second-stage choice failed for ${input.fieldName}: ${formatError(error)}`
|
|
431
|
+
}
|
|
432
|
+
];
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
#buildChoiceMessages(input) {
|
|
436
|
+
return [
|
|
437
|
+
{
|
|
438
|
+
content: this.#choiceSystemPrompt,
|
|
439
|
+
role: "system"
|
|
440
|
+
},
|
|
441
|
+
{
|
|
442
|
+
content: `Previously generated chunk (do NOT rewrite it):
|
|
443
|
+
\`\`\`json
|
|
444
|
+
${JSON.stringify(input.chunkData, null, 2)}
|
|
445
|
+
\`\`\`
|
|
446
|
+
|
|
447
|
+
Resolve only this field: "${input.fieldName}" for chunk #${input.chunkIndex} [${input.chunkLabel}].
|
|
448
|
+
Choose exactly one candidate occurrence ID from the list below.
|
|
449
|
+
|
|
450
|
+
` + input.candidates.map(formatChoiceCandidate).join("\n"),
|
|
451
|
+
role: "user"
|
|
452
|
+
}
|
|
453
|
+
];
|
|
454
|
+
}
|
|
455
|
+
#validateImportanceAnnotations(annotations, issues) {
|
|
456
|
+
if (annotations.length === 0) {
|
|
457
|
+
return [];
|
|
458
|
+
}
|
|
459
|
+
if (this.#validImportanceChunkIds === void 0) {
|
|
460
|
+
return annotations.map((annotation) => ({
|
|
461
|
+
chunkId: annotation.chunk_id,
|
|
462
|
+
importance: expectChunkImportance(annotation.importance)
|
|
463
|
+
}));
|
|
464
|
+
}
|
|
465
|
+
const result = [];
|
|
466
|
+
for (const annotation of annotations) {
|
|
467
|
+
if (!hasMembership(this.#validImportanceChunkIds, annotation.chunk_id)) {
|
|
468
|
+
issues.push(
|
|
469
|
+
`importance_annotations references unknown chunk_id ${annotation.chunk_id}`
|
|
470
|
+
);
|
|
471
|
+
continue;
|
|
472
|
+
}
|
|
473
|
+
result.push({
|
|
474
|
+
chunkId: annotation.chunk_id,
|
|
475
|
+
importance: expectChunkImportance(annotation.importance)
|
|
476
|
+
});
|
|
477
|
+
}
|
|
478
|
+
return result;
|
|
479
|
+
}
|
|
480
|
+
#filterAndValidateLinks(input) {
|
|
481
|
+
const validTempIds = createMembershipRecord(input.tempIds);
|
|
482
|
+
const validChunkIds = createMembershipRecord(input.visibleChunkIds);
|
|
483
|
+
const retainedLinks = [];
|
|
484
|
+
for (const [index, link] of input.links.entries()) {
|
|
485
|
+
const fromValid = this.#validateLinkReference({
|
|
486
|
+
fieldName: "from",
|
|
487
|
+
index: index + 1,
|
|
488
|
+
issues: input.issues,
|
|
489
|
+
reference: link.from,
|
|
490
|
+
validChunkIds,
|
|
491
|
+
validTempIds
|
|
492
|
+
});
|
|
493
|
+
const toValid = this.#validateLinkReference({
|
|
494
|
+
fieldName: "to",
|
|
495
|
+
index: index + 1,
|
|
496
|
+
issues: input.issues,
|
|
497
|
+
reference: link.to,
|
|
498
|
+
validChunkIds,
|
|
499
|
+
validTempIds
|
|
500
|
+
});
|
|
501
|
+
if (fromValid && toValid) {
|
|
502
|
+
retainedLinks.push(link);
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
return retainedLinks;
|
|
506
|
+
}
|
|
507
|
+
#validateLinkReference(input) {
|
|
508
|
+
if (typeof input.reference === "string") {
|
|
509
|
+
return hasMembership(input.validTempIds, input.reference);
|
|
510
|
+
}
|
|
511
|
+
if (!hasMembership(input.validChunkIds, input.reference)) {
|
|
512
|
+
input.issues.push(
|
|
513
|
+
`Link #${input.index}: "${input.fieldName}" chunk_id ${input.reference} does not exist in visible chunks`
|
|
514
|
+
);
|
|
515
|
+
return false;
|
|
516
|
+
}
|
|
517
|
+
return true;
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
function createWordsCountRecord(sentences) {
|
|
521
|
+
const wordsCountByKey = createEmptyRecord();
|
|
522
|
+
for (const sentence of sentences) {
|
|
523
|
+
const sentenceKey = createSentenceKey(sentence.sentenceId);
|
|
524
|
+
wordsCountByKey[sentenceKey] = sentence.wordsCount;
|
|
525
|
+
}
|
|
526
|
+
return wordsCountByKey;
|
|
527
|
+
}
|
|
528
|
+
function createSentenceTextRecord(projection) {
|
|
529
|
+
const record = createEmptyRecord();
|
|
530
|
+
for (const sentence of projection.sentences) {
|
|
531
|
+
record[createSentenceKey(sentence.sentenceId)] = sentence.rawText;
|
|
532
|
+
}
|
|
533
|
+
return record;
|
|
534
|
+
}
|
|
535
|
+
function normalizeChunkLinks(links) {
|
|
536
|
+
return links.map((link) => {
|
|
537
|
+
if (link.strength === void 0) {
|
|
538
|
+
return {
|
|
539
|
+
from: link.from,
|
|
540
|
+
to: link.to
|
|
541
|
+
};
|
|
542
|
+
}
|
|
543
|
+
return {
|
|
544
|
+
from: link.from,
|
|
545
|
+
strength: link.strength,
|
|
546
|
+
to: link.to
|
|
547
|
+
};
|
|
548
|
+
});
|
|
549
|
+
}
|
|
550
|
+
function formatChoiceCandidate(candidate) {
|
|
551
|
+
return [
|
|
552
|
+
candidate.occurrenceId,
|
|
553
|
+
`prev: ${formatChoiceText(candidate.prevText)}`,
|
|
554
|
+
`text: ${formatChoiceText(candidate.text)}`,
|
|
555
|
+
`next: ${formatChoiceText(candidate.nextText)}`
|
|
556
|
+
].join("\n");
|
|
557
|
+
}
|
|
558
|
+
function formatChoiceText(text) {
|
|
559
|
+
const collapsed = text.replace(/\s+/gu, " ").trim();
|
|
560
|
+
return collapsed === "" ? "(none)" : collapsed;
|
|
561
|
+
}
|
|
562
|
+
function toChoiceFieldName(value) {
|
|
563
|
+
return value === "evidence" || value === "start_anchor" || value === "end_anchor" ? value : void 0;
|
|
564
|
+
}
|
|
565
|
+
function isRecord(value) {
|
|
566
|
+
return typeof value === "object" && value !== null;
|
|
567
|
+
}
|
|
568
|
+
function formatError(error) {
|
|
569
|
+
if (error instanceof Error) {
|
|
570
|
+
return error.message;
|
|
571
|
+
}
|
|
572
|
+
return String(error);
|
|
573
|
+
}
|
|
574
|
+
function isParsedJsonValidationFailure(error) {
|
|
575
|
+
return error instanceof GuaranteedParseValidationError && error.cause instanceof ParsedJsonError;
|
|
576
|
+
}
|
|
577
|
+
function createSentenceKey(sentenceId) {
|
|
578
|
+
return sentenceId.join(":");
|
|
579
|
+
}
|
|
580
|
+
function createMembershipRecord(values) {
|
|
581
|
+
const record = createEmptyRecord();
|
|
582
|
+
for (const value of values) {
|
|
583
|
+
record[String(value)] = true;
|
|
584
|
+
}
|
|
585
|
+
return record;
|
|
586
|
+
}
|
|
587
|
+
function hasMembership(record, value) {
|
|
588
|
+
return hasIndexedValue(record, String(value));
|
|
589
|
+
}
|
|
590
|
+
function hasIndexedValue(record, key) {
|
|
591
|
+
return Object.hasOwn(record, key);
|
|
592
|
+
}
|
|
593
|
+
function createEmptyRecord() {
|
|
594
|
+
return /* @__PURE__ */ Object.create(null);
|
|
595
|
+
}
|
|
596
|
+
function expectSingleSpan(spans) {
|
|
597
|
+
return spans.length === 1 ? spans[0] : void 0;
|
|
598
|
+
}
|
|
599
|
+
function createEvidenceSelectionList(evidence) {
|
|
600
|
+
if (Array.isArray(evidence)) {
|
|
601
|
+
return evidence.map(createEvidenceSelection);
|
|
602
|
+
}
|
|
603
|
+
const hasSelectionEvidence = typeof evidence.quote === "string" || typeof evidence.sentence_id === "string";
|
|
604
|
+
return hasSelectionEvidence ? createEvidenceSelection(evidence) : void 0;
|
|
605
|
+
}
|
|
606
|
+
function createEvidenceSelection(evidence) {
|
|
607
|
+
return {
|
|
608
|
+
...typeof evidence.quote === "string" ? { quote: evidence.quote } : {},
|
|
609
|
+
...typeof evidence.sentence_id === "string" ? { sentence_id: evidence.sentence_id } : {}
|
|
610
|
+
};
|
|
611
|
+
}
|
|
612
|
+
function toEvidenceResolutionFailure(failure, fieldName) {
|
|
613
|
+
return {
|
|
614
|
+
candidates: failure.candidates.map(toRankedSentenceCandidate),
|
|
615
|
+
code: failure.code,
|
|
616
|
+
fieldName,
|
|
617
|
+
message: failure.message
|
|
618
|
+
};
|
|
619
|
+
}
|
|
620
|
+
function toRankedSentenceCandidate(candidate) {
|
|
621
|
+
return {
|
|
622
|
+
exactNormalized: candidate.exactNormalized,
|
|
623
|
+
exactRaw: candidate.exactRaw,
|
|
624
|
+
exactSubstring: candidate.exactSubstring,
|
|
625
|
+
index: candidate.index,
|
|
626
|
+
nextText: candidate.nextText,
|
|
627
|
+
occurrenceId: candidate.occurrenceId,
|
|
628
|
+
prevText: candidate.prevText,
|
|
629
|
+
score: candidate.score,
|
|
630
|
+
sentenceId: candidate.sentence.sentenceId,
|
|
631
|
+
text: candidate.sentence.text
|
|
632
|
+
};
|
|
633
|
+
}
|
|
634
|
+
export {
|
|
635
|
+
ChunkBatchParser,
|
|
636
|
+
ChunkMetadataField,
|
|
637
|
+
bookCoherenceResponseSchema,
|
|
638
|
+
userFocusedResponseSchema
|
|
639
|
+
};
|
|
640
|
+
//# sourceMappingURL=parser.js.map
|