@world-engines/project-host 0.1.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (218) hide show
  1. package/LICENSE +46 -0
  2. package/assets/gui/WELogo-title.svg +11 -0
  3. package/assets/gui/app.js +1326 -0
  4. package/assets/gui/index.html +118 -0
  5. package/assets/gui/local-preview-asset-urls.js +61 -0
  6. package/assets/gui/local-preview-bridge.js +393 -0
  7. package/assets/gui/spatial-template-panel.js +233 -0
  8. package/assets/gui/styles.css +115 -0
  9. package/assets/gui/terrain-render.js +120 -0
  10. package/assets/gui/workspace-status.css +17 -0
  11. package/assets/gui/workspace-status.js +255 -0
  12. package/assets/gui/world-map-globe.js +187 -0
  13. package/assets/gui/world-map-worker.js +62 -0
  14. package/assets/gui/world-map.css +30 -0
  15. package/assets/gui/world-map.js +2466 -0
  16. package/dist/account-model-proxy.d.ts +21 -0
  17. package/dist/account-model-proxy.js +470 -0
  18. package/dist/authoring-browser-runtime.d.ts +7 -0
  19. package/dist/authoring-browser-runtime.js +110 -0
  20. package/dist/authoring-ingestion.d.ts +38 -0
  21. package/dist/authoring-ingestion.js +410 -0
  22. package/dist/authoring-model-connection.d.ts +166 -0
  23. package/dist/authoring-model-connection.js +757 -0
  24. package/dist/chinese-lexical.d.ts +152 -0
  25. package/dist/chinese-lexical.js +555 -0
  26. package/dist/chromium-preview-browser-driver.d.ts +43 -0
  27. package/dist/chromium-preview-browser-driver.js +575 -0
  28. package/dist/cli/download.d.ts +12 -0
  29. package/dist/cli/download.js +50 -0
  30. package/dist/cli/dump.d.ts +32 -0
  31. package/dist/cli/dump.js +91 -0
  32. package/dist/cli/ingest.d.ts +49 -0
  33. package/dist/cli/ingest.js +225 -0
  34. package/dist/cli/review.d.ts +10 -0
  35. package/dist/cli/review.js +44 -0
  36. package/dist/cli/upload.d.ts +57 -0
  37. package/dist/cli/upload.js +112 -0
  38. package/dist/cli-command.d.ts +60 -0
  39. package/dist/cli-command.js +613 -0
  40. package/dist/cli.d.ts +2 -0
  41. package/dist/cli.js +182 -0
  42. package/dist/desktop-authoring-runtime.d.ts +88 -0
  43. package/dist/desktop-authoring-runtime.js +1602 -0
  44. package/dist/desktop-sidecar.d.ts +11 -0
  45. package/dist/desktop-sidecar.js +143 -0
  46. package/dist/document-dump.d.ts +113 -0
  47. package/dist/document-dump.js +431 -0
  48. package/dist/document-graph-extractor.d.ts +125 -0
  49. package/dist/document-graph-extractor.js +588 -0
  50. package/dist/document-ingestion-journal.d.ts +68 -0
  51. package/dist/document-ingestion-journal.js +471 -0
  52. package/dist/document-ingestion.d.ts +183 -0
  53. package/dist/document-ingestion.js +976 -0
  54. package/dist/document-query-path-proof.d.ts +30 -0
  55. package/dist/document-query-path-proof.js +34 -0
  56. package/dist/document-query-path-renderer.d.ts +50 -0
  57. package/dist/document-query-path-renderer.js +75 -0
  58. package/dist/document-query-proof-paths.d.ts +22 -0
  59. package/dist/document-query-proof-paths.js +71 -0
  60. package/dist/document-query.d.ts +97 -0
  61. package/dist/document-query.js +1106 -0
  62. package/dist/document-relation-role.d.ts +14 -0
  63. package/dist/document-relation-role.js +86 -0
  64. package/dist/document-source.d.ts +107 -0
  65. package/dist/document-source.js +255 -0
  66. package/dist/embedding-cache.d.ts +35 -0
  67. package/dist/embedding-cache.js +317 -0
  68. package/dist/frozen-review-local-pipeline.d.ts +88 -0
  69. package/dist/frozen-review-local-pipeline.js +609 -0
  70. package/dist/frozen-review-source-capture.d.ts +15 -0
  71. package/dist/frozen-review-source-capture.js +551 -0
  72. package/dist/frozen-review-wasm-encryptor.d.ts +16 -0
  73. package/dist/frozen-review-wasm-encryptor.js +72 -0
  74. package/dist/frozen-review.d.ts +131 -0
  75. package/dist/frozen-review.js +802 -0
  76. package/dist/graph-traversal.d.ts +23 -0
  77. package/dist/graph-traversal.js +100 -0
  78. package/dist/gui/graph-layout-worker.js +1 -0
  79. package/dist/gui/graph-layout.wasm +0 -0
  80. package/dist/gui/graph.css +1 -0
  81. package/dist/gui/graph.js +76 -0
  82. package/dist/gui/plane-generation.js +112 -0
  83. package/dist/gui/plane-generator.js +310 -0
  84. package/dist/gui/plane-generator_bg.wasm +0 -0
  85. package/dist/gui/procedural-city.js +595 -0
  86. package/dist/gui/road-generation.js +129 -0
  87. package/dist/gui/road-parcels.js +1584 -0
  88. package/dist/gui/score.css +1 -0
  89. package/dist/gui/score.js +54 -0
  90. package/dist/gui/spatial-runtime.js +1231 -0
  91. package/dist/gui/spatial-templates.js +200 -0
  92. package/dist/gui/trigger.css +1 -0
  93. package/dist/gui/trigger.js +142 -0
  94. package/dist/harness-callback-transport.d.ts +17 -0
  95. package/dist/harness-callback-transport.js +128 -0
  96. package/dist/harness-document-ingestion.d.ts +77 -0
  97. package/dist/harness-document-ingestion.js +343 -0
  98. package/dist/index.d.ts +43 -0
  99. package/dist/index.js +43 -0
  100. package/dist/ingestion-source-reconciliation.d.ts +88 -0
  101. package/dist/ingestion-source-reconciliation.js +253 -0
  102. package/dist/ladybug-runtime.d.ts +117 -0
  103. package/dist/ladybug-runtime.js +886 -0
  104. package/dist/local-account-embedding.d.ts +34 -0
  105. package/dist/local-account-embedding.js +294 -0
  106. package/dist/local-gallery.d.ts +35 -0
  107. package/dist/local-gallery.js +227 -0
  108. package/dist/local-gui-auth.d.ts +96 -0
  109. package/dist/local-gui-auth.js +703 -0
  110. package/dist/local-gui-contract.d.ts +53 -0
  111. package/dist/local-gui-contract.js +5 -0
  112. package/dist/local-gui-image-assets.d.ts +17 -0
  113. package/dist/local-gui-image-assets.js +96 -0
  114. package/dist/local-gui-preview-client.d.ts +3 -0
  115. package/dist/local-gui-preview-client.js +111 -0
  116. package/dist/local-gui-score.d.ts +72 -0
  117. package/dist/local-gui-score.js +184 -0
  118. package/dist/local-gui-server.d.ts +10 -0
  119. package/dist/local-gui-server.js +987 -0
  120. package/dist/local-gui-version.d.ts +17 -0
  121. package/dist/local-gui-version.js +147 -0
  122. package/dist/local-gui-workspace.d.ts +14 -0
  123. package/dist/local-gui-workspace.js +171 -0
  124. package/dist/local-model-settings.d.ts +28 -0
  125. package/dist/local-model-settings.js +124 -0
  126. package/dist/local-preview-assets.d.ts +28 -0
  127. package/dist/local-preview-assets.js +124 -0
  128. package/dist/local-preview-bound-resources.d.ts +12 -0
  129. package/dist/local-preview-bound-resources.js +80 -0
  130. package/dist/local-preview-message-store.d.ts +63 -0
  131. package/dist/local-preview-message-store.js +214 -0
  132. package/dist/local-preview-player-read-models.d.ts +47 -0
  133. package/dist/local-preview-player-read-models.js +90 -0
  134. package/dist/local-preview-projections.d.ts +61 -0
  135. package/dist/local-preview-projections.js +117 -0
  136. package/dist/local-preview-runtime.d.ts +105 -0
  137. package/dist/local-preview-runtime.js +553 -0
  138. package/dist/local-preview-session.d.ts +73 -0
  139. package/dist/local-preview-session.js +395 -0
  140. package/dist/local-preview-source.d.ts +40 -0
  141. package/dist/local-preview-source.js +192 -0
  142. package/dist/local-preview-view-events.d.ts +101 -0
  143. package/dist/local-preview-view-events.js +179 -0
  144. package/dist/local-preview-view-state-sqlite.d.ts +24 -0
  145. package/dist/local-preview-view-state-sqlite.js +263 -0
  146. package/dist/local-preview-view-state.d.ts +93 -0
  147. package/dist/local-preview-view-state.js +108 -0
  148. package/dist/local-preview-vite-config.d.ts +6 -0
  149. package/dist/local-preview-vite-config.js +122 -0
  150. package/dist/local-preview-world-effects.d.ts +9 -0
  151. package/dist/local-preview-world-effects.js +55 -0
  152. package/dist/local-preview-worldline-store.d.ts +47 -0
  153. package/dist/local-preview-worldline-store.js +282 -0
  154. package/dist/local-preview-worldlines.d.ts +95 -0
  155. package/dist/local-preview-worldlines.js +136 -0
  156. package/dist/mcp-async-dispatcher.d.ts +3 -0
  157. package/dist/mcp-async-dispatcher.js +129 -0
  158. package/dist/mcp-line-queue.d.ts +14 -0
  159. package/dist/mcp-line-queue.js +184 -0
  160. package/dist/mcp-pipe-internal.d.ts +6 -0
  161. package/dist/mcp-pipe-internal.js +151 -0
  162. package/dist/mcp-pipe-response.d.ts +14 -0
  163. package/dist/mcp-pipe-response.js +50 -0
  164. package/dist/mcp-stdio-response.d.ts +12 -0
  165. package/dist/mcp-stdio-response.js +27 -0
  166. package/dist/mcp.d.ts +27 -0
  167. package/dist/mcp.js +194 -0
  168. package/dist/prepared-embedding-cache.d.ts +38 -0
  169. package/dist/prepared-embedding-cache.js +238 -0
  170. package/dist/preview-browser-adapter.d.ts +53 -0
  171. package/dist/preview-browser-adapter.js +171 -0
  172. package/dist/preview-runtime.d.ts +67 -0
  173. package/dist/preview-runtime.js +460 -0
  174. package/dist/project-auth-transport.d.ts +27 -0
  175. package/dist/project-auth-transport.js +121 -0
  176. package/dist/project-auth.d.ts +51 -0
  177. package/dist/project-auth.js +108 -0
  178. package/dist/project-git-capture-recovery.d.ts +16 -0
  179. package/dist/project-git-capture-recovery.js +347 -0
  180. package/dist/project-git-cli.d.ts +5 -0
  181. package/dist/project-git-cli.js +40 -0
  182. package/dist/project-git-scenario-source.d.ts +10 -0
  183. package/dist/project-git-scenario-source.js +240 -0
  184. package/dist/project-git-view-source.d.ts +13 -0
  185. package/dist/project-git-view-source.js +134 -0
  186. package/dist/project-git.d.ts +97 -0
  187. package/dist/project-git.js +656 -0
  188. package/dist/project-host.d.ts +59 -0
  189. package/dist/project-host.js +471 -0
  190. package/dist/project-writer-lease.d.ts +18 -0
  191. package/dist/project-writer-lease.js +430 -0
  192. package/dist/public-error.d.ts +7 -0
  193. package/dist/public-error.js +61 -0
  194. package/dist/retrieval-benchmark.d.ts +46 -0
  195. package/dist/retrieval-benchmark.js +58 -0
  196. package/dist/safe-project-path.d.ts +8 -0
  197. package/dist/safe-project-path.js +93 -0
  198. package/dist/scenario-writer.d.ts +32 -0
  199. package/dist/scenario-writer.js +191 -0
  200. package/dist/transfer/download.d.ts +159 -0
  201. package/dist/transfer/download.js +598 -0
  202. package/dist/transfer/transport.d.ts +26 -0
  203. package/dist/transfer/transport.js +1 -0
  204. package/dist/transfer/upload.d.ts +162 -0
  205. package/dist/transfer/upload.js +354 -0
  206. package/dist/transfer-types.d.ts +95 -0
  207. package/dist/transfer-types.js +1 -0
  208. package/dist/transfer.d.ts +18 -0
  209. package/dist/transfer.js +273 -0
  210. package/dist/trigger-runtime.d.ts +121 -0
  211. package/dist/trigger-runtime.js +153 -0
  212. package/dist/vendor/wasm-core/asset-hashes.json +5 -0
  213. package/dist/vendor/wasm-core/wasm_core.d.ts +490 -0
  214. package/dist/vendor/wasm-core/wasm_core.js +1 -0
  215. package/dist/vendor/wasm-core/wasm_core_bg.wasm +0 -0
  216. package/dist/view-watcher.d.ts +9 -0
  217. package/dist/view-watcher.js +34 -0
  218. package/package.json +110 -0
@@ -0,0 +1,30 @@
1
+ export interface DocumentQueryQuoteReference {
2
+ readonly evidence_id: string;
3
+ readonly quote_id: string;
4
+ }
5
+ export interface DocumentQueryPathProofRequirement {
6
+ readonly path_id: string;
7
+ readonly usable: boolean;
8
+ readonly hops: readonly Readonly<{
9
+ src: string;
10
+ dst: string;
11
+ kind: string;
12
+ status: "available" | "missing";
13
+ required_quotes: readonly DocumentQueryQuoteReference[];
14
+ missing_reason: string | null;
15
+ }>[];
16
+ }
17
+ export interface SelectedPathQuotesCheck {
18
+ readonly complete: boolean;
19
+ /** 所选但未闭合的路径,包含缺引文或上游判定不可用的路径。 */
20
+ readonly missingPathIds: readonly string[];
21
+ readonly missingQuotes: readonly Readonly<DocumentQueryQuoteReference & {
22
+ path_id: string;
23
+ }>[];
24
+ readonly unavailablePathIds: readonly string[];
25
+ }
26
+ /**
27
+ * 只核对本轮选择与上游已经算好的逐跳引文要求,不推断关系语义,也不重算 span/offset。
28
+ * 同一 chunk 的另一 quote、或相同 quote ID 对应的另一 evidence,都不能替代要求的精确引用对。
29
+ */
30
+ export declare function checkSelectedPathQuotes(requirements: readonly DocumentQueryPathProofRequirement[], selectedPathIds: readonly string[], selectedCitations: readonly DocumentQueryQuoteReference[]): SelectedPathQuotesCheck;
@@ -0,0 +1,34 @@
1
+ /**
2
+ * 只核对本轮选择与上游已经算好的逐跳引文要求,不推断关系语义,也不重算 span/offset。
3
+ * 同一 chunk 的另一 quote、或相同 quote ID 对应的另一 evidence,都不能替代要求的精确引用对。
4
+ */
5
+ export function checkSelectedPathQuotes(requirements, selectedPathIds, selectedCitations) {
6
+ const byId = new Map(requirements.map((requirement) => [requirement.path_id, requirement]));
7
+ const selectedIds = [...new Set(selectedPathIds)];
8
+ for (const id of selectedIds)
9
+ if (!byId.has(id))
10
+ throw new Error("document_query:selected_path_unknown");
11
+ const pairKey = (quote) => JSON.stringify([quote.evidence_id, quote.quote_id]);
12
+ const citedPairs = new Set(selectedCitations.map(pairKey));
13
+ const missingPathIds = [];
14
+ const unavailablePathIds = [];
15
+ const missingQuotes = [];
16
+ for (const pathId of selectedIds) {
17
+ const path = byId.get(pathId);
18
+ const unavailable = !path.usable || path.hops.length === 0 || path.hops.some((hop) => hop.status !== "available" || hop.required_quotes.length === 0);
19
+ const missingPairs = new Map();
20
+ for (const hop of path.hops)
21
+ for (const quote of hop.required_quotes) {
22
+ const key = pairKey(quote);
23
+ if (!citedPairs.has(key))
24
+ missingPairs.set(key, quote);
25
+ }
26
+ if (unavailable)
27
+ unavailablePathIds.push(pathId);
28
+ if (unavailable || missingPairs.size > 0)
29
+ missingPathIds.push(pathId);
30
+ for (const quote of missingPairs.values())
31
+ missingQuotes.push({ path_id: pathId, evidence_id: quote.evidence_id, quote_id: quote.quote_id });
32
+ }
33
+ return { complete: missingPathIds.length === 0, missingPathIds, missingQuotes, unavailablePathIds };
34
+ }
@@ -0,0 +1,50 @@
1
+ /** 给模型的路径展示只消费已验证物理图;不生成关系、证据或路径候选。 */
2
+ export type DocumentQueryRenderEntity = Readonly<{
3
+ id: string;
4
+ kind: string;
5
+ props: Readonly<Record<string, unknown>>;
6
+ }>;
7
+ export type DocumentQueryRenderRelation = Readonly<{
8
+ src: string;
9
+ dst: string;
10
+ kind: string;
11
+ props: Readonly<Record<string, unknown>>;
12
+ }>;
13
+ export type DocumentQueryRenderPath = Readonly<{
14
+ pathId: string;
15
+ nodeIds: readonly string[];
16
+ edges: readonly Readonly<{
17
+ src: string;
18
+ dst: string;
19
+ kind: string;
20
+ }>[];
21
+ }>;
22
+ export type DocumentQueryRenderedEndpoint = Readonly<{
23
+ ref: string;
24
+ label: string | null;
25
+ kind: string;
26
+ label_truncated?: true;
27
+ }>;
28
+ export type DocumentQueryRenderedHop = Readonly<{
29
+ /** 始终为物理边的 source → target,不能因路径逆向行走而互换。 */
30
+ source: DocumentQueryRenderedEndpoint;
31
+ target: DocumentQueryRenderedEndpoint;
32
+ kind: string;
33
+ assertion: string | null;
34
+ /** 只透传实际物理关系限定;不从 kind 前缀推断否定。 */
35
+ qualifiers?: unknown;
36
+ assertion_truncated?: true;
37
+ walk_direction: "forward" | "reverse";
38
+ }>;
39
+ export type DocumentQueryRenderedPathOption = Readonly<{
40
+ path_id: string;
41
+ hops: readonly DocumentQueryRenderedHop[];
42
+ }>;
43
+ /** 输出替换旧 nodes/edges 平行表;每一跳独立含端点与实际断言,局部 ref 按物理 ID 分配。 */
44
+ export declare function renderDocumentQueryPathOptions(input: Readonly<{
45
+ paths: readonly DocumentQueryRenderPath[];
46
+ entities: ReadonlyMap<string, DocumentQueryRenderEntity>;
47
+ relations: readonly DocumentQueryRenderRelation[];
48
+ }>): Readonly<{
49
+ path_options: readonly DocumentQueryRenderedPathOption[];
50
+ }>;
@@ -0,0 +1,75 @@
1
+ // 仅限制展示字段;候选数量、深度与 path identity 由 query owner 验证。
2
+ const LABEL_UTF16_LIMIT = 256;
3
+ const ASSERTION_UTF16_LIMIT = 512;
4
+ function fail(code) {
5
+ throw new Error(`document_query_path_renderer:${code}`);
6
+ }
7
+ function relationKey(relation) {
8
+ return JSON.stringify([relation.src, relation.dst, relation.kind]);
9
+ }
10
+ /** 保留原字符与换行,不在高低 surrogate 中间截断,也不伪造省略后的尾部事实。 */
11
+ function displayText(value, maximum) {
12
+ if (typeof value !== "string")
13
+ return { text: null, truncated: false };
14
+ let text = "";
15
+ for (const character of value) {
16
+ if (text.length + character.length > maximum)
17
+ return { text, truncated: true };
18
+ text += character;
19
+ }
20
+ return { text, truncated: false };
21
+ }
22
+ /** 输出替换旧 nodes/edges 平行表;每一跳独立含端点与实际断言,局部 ref 按物理 ID 分配。 */
23
+ export function renderDocumentQueryPathOptions(input) {
24
+ const references = new Map();
25
+ const pathIds = new Set();
26
+ for (const path of input.paths) {
27
+ if (path.pathId.length === 0 || pathIds.has(path.pathId))
28
+ fail("path_identity_invalid");
29
+ pathIds.add(path.pathId);
30
+ if (path.edges.length === 0 || path.nodeIds.length !== path.edges.length + 1)
31
+ fail("path_shape_invalid");
32
+ for (const nodeId of path.nodeIds)
33
+ if (!references.has(nodeId))
34
+ references.set(nodeId, `n${references.size}`);
35
+ }
36
+ const actualRelations = new Map();
37
+ for (const relation of input.relations) {
38
+ const key = relationKey(relation);
39
+ if (actualRelations.has(key))
40
+ fail("duplicate_physical_relation");
41
+ actualRelations.set(key, relation);
42
+ }
43
+ const endpoints = new Map();
44
+ const endpoint = (nodeId) => {
45
+ const cached = endpoints.get(nodeId);
46
+ if (cached !== undefined)
47
+ return cached;
48
+ const actual = input.entities.get(nodeId);
49
+ const ref = references.get(nodeId);
50
+ if (actual === undefined || actual.id !== nodeId || ref === undefined)
51
+ return fail("physical_endpoint_missing");
52
+ const label = displayText(actual.props.label, LABEL_UTF16_LIMIT);
53
+ const rendered = Object.freeze({ ref, label: label.text, kind: actual.kind,
54
+ ...(label.truncated ? { label_truncated: true } : {}) });
55
+ endpoints.set(nodeId, rendered);
56
+ return rendered;
57
+ };
58
+ const options = input.paths.map((path) => {
59
+ const hops = path.edges.map((edge, index) => {
60
+ const actual = actualRelations.get(relationKey(edge));
61
+ if (actual === undefined)
62
+ return fail("physical_relation_missing");
63
+ const from = path.nodeIds[index];
64
+ const to = path.nodeIds[index + 1];
65
+ const walkDirection = edge.src === from && edge.dst === to ? "forward"
66
+ : edge.dst === from && edge.src === to ? "reverse" : fail("path_physical_discontinuity");
67
+ const assertion = displayText(actual.props.assertion, ASSERTION_UTF16_LIMIT);
68
+ return Object.freeze({ source: endpoint(actual.src), target: endpoint(actual.dst), kind: actual.kind,
69
+ assertion: assertion.text, ...(actual.props.qualifiers === undefined ? {} : { qualifiers: actual.props.qualifiers }),
70
+ ...(assertion.truncated ? { assertion_truncated: true } : {}), walk_direction: walkDirection });
71
+ });
72
+ return Object.freeze({ path_id: path.pathId, hops: Object.freeze(hops) });
73
+ });
74
+ return Object.freeze({ path_options: Object.freeze(options) });
75
+ }
@@ -0,0 +1,22 @@
1
+ export interface ProofPathCandidate {
2
+ readonly pathId: string;
3
+ readonly nodeIds: readonly string[];
4
+ readonly edges: readonly Readonly<{
5
+ src: string;
6
+ dst: string;
7
+ kind: string;
8
+ }>[];
9
+ }
10
+ export interface CanonicalSelectedProofPaths {
11
+ readonly canonicalPathIds: readonly string[];
12
+ readonly canonicalPaths: readonly ProofPathCandidate[];
13
+ readonly mapping: readonly Readonly<{
14
+ selectedPathId: string;
15
+ canonicalPathIds: readonly string[];
16
+ }>[];
17
+ }
18
+ /**
19
+ * 候选已由上游绑定 source/scope、depth/path 预算及证据;这里不读图、不扩预算、不生成路径。
20
+ * 只以当前明确选中的物理边替换为候选中已有的完整路径,之后仍须重新做逐跳 quote 校验。
21
+ */
22
+ export declare function canonicalizeSelectedProofPaths(candidates: readonly ProofPathCandidate[], selectedPathIds: readonly string[]): CanonicalSelectedProofPaths;
@@ -0,0 +1,71 @@
1
+ function edgeKey(edge) {
2
+ return JSON.stringify([edge.src, edge.dst, edge.kind]);
3
+ }
4
+ function simpleConnected(path) {
5
+ return path.nodeIds.length >= 2 && path.edges.length === path.nodeIds.length - 1
6
+ && new Set(path.nodeIds).size === path.nodeIds.length
7
+ && path.edges.every((edge, index) => (edge.src === path.nodeIds[index] && edge.dst === path.nodeIds[index + 1])
8
+ || (edge.dst === path.nodeIds[index] && edge.src === path.nodeIds[index + 1]));
9
+ }
10
+ /** 可反向遍历同一片段,但绝不改写每条物理边的 src/dst/kind。 */
11
+ function containsFragment(container, fragment) {
12
+ if (fragment.nodeIds.length > container.nodeIds.length)
13
+ return false;
14
+ for (let start = 0; start <= container.nodeIds.length - fragment.nodeIds.length; start += 1) {
15
+ for (const reverse of [false, true]) {
16
+ if (!fragment.nodeIds.every((_id, index) => container.nodeIds[start + index]
17
+ === fragment.nodeIds[reverse ? fragment.nodeIds.length - 1 - index : index]))
18
+ continue;
19
+ if (fragment.edges.every((_edge, index) => edgeKey(container.edges[start + index])
20
+ === edgeKey(fragment.edges[reverse ? fragment.edges.length - 1 - index : index])))
21
+ return true;
22
+ }
23
+ }
24
+ return false;
25
+ }
26
+ /**
27
+ * 候选已由上游绑定 source/scope、depth/path 预算及证据;这里不读图、不扩预算、不生成路径。
28
+ * 只以当前明确选中的物理边替换为候选中已有的完整路径,之后仍须重新做逐跳 quote 校验。
29
+ */
30
+ export function canonicalizeSelectedProofPaths(candidates, selectedPathIds) {
31
+ const byId = new Map(candidates.map((path) => [path.pathId, path]));
32
+ if (byId.size !== candidates.length)
33
+ throw new Error("document_query:proof_path_candidates_invalid");
34
+ const selected = [...new Set(selectedPathIds)].map((id) => {
35
+ const path = byId.get(id);
36
+ if (path === undefined)
37
+ throw new Error("document_query:selected_path_unknown");
38
+ if (!simpleConnected(path))
39
+ throw new Error("document_query:selected_path_invalid");
40
+ return path;
41
+ });
42
+ const selectedEdges = new Set(selected.flatMap((path) => path.edges.map(edgeKey)));
43
+ const promotions = candidates.flatMap((path, candidateIndex) => {
44
+ if (!simpleConnected(path) || path.edges.some((edge) => !selectedEdges.has(edgeKey(edge))))
45
+ return [];
46
+ const fragments = selected.filter((fragment) => containsFragment(path, fragment));
47
+ if (!fragments.some((fragment) => fragment.edges.length < path.edges.length))
48
+ return [];
49
+ return [{ path, fragments, candidateIndex }];
50
+ }).sort((left, right) => right.path.edges.length - left.path.edges.length
51
+ || right.fragments.length - left.fragments.length || left.candidateIndex - right.candidateIndex);
52
+ const covered = new Set();
53
+ const canonicalPaths = [];
54
+ for (const promotion of promotions) {
55
+ // 每条输出必须新覆盖至少一个已选片段,故不会增加已选路径总数。
56
+ if (!promotion.fragments.some((path) => !covered.has(path.pathId)))
57
+ continue;
58
+ canonicalPaths.push(promotion.path);
59
+ for (const fragment of promotion.fragments)
60
+ covered.add(fragment.pathId);
61
+ }
62
+ for (const path of selected)
63
+ if (!covered.has(path.pathId))
64
+ canonicalPaths.push(path);
65
+ return {
66
+ canonicalPathIds: canonicalPaths.map((path) => path.pathId),
67
+ canonicalPaths,
68
+ mapping: selected.map((path) => ({ selectedPathId: path.pathId,
69
+ canonicalPathIds: canonicalPaths.filter((canonical) => containsFragment(canonical, path)).map((canonical) => canonical.pathId) })),
70
+ };
71
+ }
@@ -0,0 +1,97 @@
1
+ import type { AuthoringToolCall } from "@world-engines/authoring-bridge";
2
+ import type { AuthoringModelConnection, AuthoringModelUsage } from "./authoring-model-connection.js";
3
+ export interface DocumentQueryHost {
4
+ dispatchTool(call: AuthoringToolCall): Promise<unknown>;
5
+ }
6
+ export interface DocumentQuestionRequest {
7
+ readonly query: string;
8
+ readonly scopeId: string;
9
+ readonly maxDepth?: number;
10
+ readonly searchLimit?: number;
11
+ readonly pathLimit?: number;
12
+ readonly evidenceCharacterBudget?: number;
13
+ /** Planner 只能从此集合选择关系;缺省使用 world_schema 的实际语义关系。 */
14
+ readonly allowedRelationKinds?: readonly string[];
15
+ }
16
+ export interface DocumentCitation {
17
+ readonly evidenceId: string;
18
+ readonly documentId: string;
19
+ readonly startOffset: number;
20
+ readonly endOffset: number;
21
+ readonly contentSha256: string;
22
+ readonly quote: string;
23
+ }
24
+ export interface DocumentGraphEdge {
25
+ readonly src: string;
26
+ readonly dst: string;
27
+ readonly kind: string;
28
+ /** 原始限定词;parent_of 加 negation:true 不是正向家长事实。 */
29
+ readonly qualifiers?: Readonly<Record<string, unknown>>;
30
+ readonly evidenceIds?: readonly string[];
31
+ }
32
+ export interface DocumentGraphPath {
33
+ readonly nodeIds: readonly string[];
34
+ readonly edges: readonly DocumentGraphEdge[];
35
+ }
36
+ export interface DocumentRetrievalTraceEntry {
37
+ readonly stage: "plan" | "search" | "traverse" | "readback" | "answer" | "verify";
38
+ readonly detail: Readonly<Record<string, unknown>>;
39
+ }
40
+ export interface DocumentQuestionAnswer {
41
+ readonly answerable: boolean;
42
+ readonly answer: string | null;
43
+ readonly citations: readonly DocumentCitation[];
44
+ readonly graphPaths: readonly DocumentGraphPath[];
45
+ readonly retrievalTrace: readonly DocumentRetrievalTraceEntry[];
46
+ readonly usage: AuthoringModelUsage;
47
+ }
48
+ export interface DocumentQuestionDependencies {
49
+ readonly modelConnection: AuthoringModelConnection;
50
+ readonly signal?: AbortSignal;
51
+ }
52
+ export interface DocumentEvidenceRequest extends DocumentQuestionRequest {
53
+ /** 外部 harness 可提供自身规划结果;缺省时直接以原问题做一次 hybrid 检索。 */
54
+ readonly searchQueries?: readonly string[];
55
+ /** benchmark/离线诊断可显式选择 keyword;缺省仍是需要已准备真实向量的 hybrid。 */
56
+ readonly searchMode?: "keyword" | "hybrid";
57
+ }
58
+ export interface DocumentEvidenceBundle {
59
+ readonly query: string;
60
+ readonly scopeId: string;
61
+ readonly searchMode: "keyword" | "hybrid";
62
+ readonly candidates: readonly Readonly<{
63
+ id: string;
64
+ kind: string;
65
+ channels: readonly string[];
66
+ query: string;
67
+ rank: number;
68
+ }>[];
69
+ readonly graphPaths: readonly DocumentGraphPath[];
70
+ readonly pathOptions: readonly unknown[];
71
+ readonly evidence: readonly Readonly<Evidence>[];
72
+ readonly integrity: Readonly<{
73
+ sourceBinding: "verified" | "unavailable";
74
+ evidenceCoverage: "complete" | "partial" | "empty";
75
+ traversalTruncated: boolean;
76
+ }>;
77
+ readonly retrievalTrace: readonly DocumentRetrievalTraceEntry[];
78
+ }
79
+ type Evidence = Readonly<{
80
+ evidenceId: string;
81
+ documentId: string;
82
+ startOffset: number;
83
+ endOffset: number;
84
+ contentSha256: string;
85
+ text: string;
86
+ }>;
87
+ /**
88
+ * 外部 harness 的检索 seam:Host 只做 hybrid recall、物理图遍历、原文回读与完整性校验,
89
+ * 不调用 structured model,也不生成答案。结构理解、否定/时间推理由调用方基于 bundle 完成。
90
+ */
91
+ export declare function retrieveDocumentEvidenceBundle(host: DocumentQueryHost, request: DocumentEvidenceRequest): Promise<DocumentEvidenceBundle>;
92
+ /**
93
+ * D4F 只负责制定有界检索计划和基于回读证据回答;图路径始终来自 exact-21 Host。
94
+ * 原始 source_document、rawBase64 与 generated context 永不进入模型 evidence。
95
+ */
96
+ export declare function answerDocumentQuestion(host: DocumentQueryHost, request: DocumentQuestionRequest, dependencies: DocumentQuestionDependencies): Promise<DocumentQuestionAnswer>;
97
+ export {};