dsh-data-domain-knowledge 0.1.0-alpha.9 → 0.1.1-alpha.2

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 (438) hide show
  1. package/README.md +118 -567
  2. package/cordis.patch.yml +5 -418
  3. package/eval/README.md +19 -8
  4. package/eval/benchmark-extraction-format.mjs +20 -0
  5. package/eval/evaluate-retrieval.mjs +17 -8
  6. package/eval/queries.example.jsonl +1 -0
  7. package/lib/client.js +4181 -3239
  8. package/lib/contract-envelope.d.ts +91 -0
  9. package/lib/contract-envelope.js +106 -0
  10. package/lib/contract-layout.d.ts +130 -0
  11. package/lib/contract-layout.js +138 -0
  12. package/lib/contract-refs.d.ts +39 -0
  13. package/lib/contract-refs.js +9 -0
  14. package/lib/contract-version.d.ts +311 -0
  15. package/lib/contract-version.js +270 -0
  16. package/lib/contract-wire.d.ts +147 -0
  17. package/lib/contract-wire.js +99 -0
  18. package/lib/contracts.d.ts +12 -0
  19. package/lib/contracts.js +12 -0
  20. package/lib/doc-page.js +2 -2
  21. package/lib/pages.js +3329 -1296
  22. package/lib/types/agent-behavior-rules.d.ts +10 -0
  23. package/lib/types/agent-behavior-rules.d.ts.map +1 -0
  24. package/lib/types/agent-behavior-rules.js +28 -0
  25. package/lib/types/agent-behavior-rules.js.map +1 -0
  26. package/lib/types/axis-registry.d.ts +37 -5
  27. package/lib/types/axis-registry.d.ts.map +1 -1
  28. package/lib/types/axis-registry.js +234 -26
  29. package/lib/types/axis-registry.js.map +1 -1
  30. package/lib/types/card-organize.d.ts +27 -12
  31. package/lib/types/card-organize.d.ts.map +1 -1
  32. package/lib/types/card-organize.js +58 -73
  33. package/lib/types/card-organize.js.map +1 -1
  34. package/lib/types/compiler/embedding-identity.d.ts +3 -0
  35. package/lib/types/compiler/embedding-identity.d.ts.map +1 -0
  36. package/lib/types/compiler/embedding-identity.js +24 -0
  37. package/lib/types/compiler/embedding-identity.js.map +1 -0
  38. package/lib/types/compiler/snapshot.d.ts +16 -0
  39. package/lib/types/compiler/snapshot.d.ts.map +1 -0
  40. package/lib/types/compiler/snapshot.js +2 -0
  41. package/lib/types/compiler/snapshot.js.map +1 -0
  42. package/lib/types/config-schema.d.ts +6 -3
  43. package/lib/types/config-schema.d.ts.map +1 -1
  44. package/lib/types/config-schema.js +6 -2
  45. package/lib/types/config-schema.js.map +1 -1
  46. package/lib/types/convert/host.d.ts +6 -5
  47. package/lib/types/convert/host.d.ts.map +1 -1
  48. package/lib/types/convert/host.js +58 -18
  49. package/lib/types/convert/host.js.map +1 -1
  50. package/lib/types/convert/ingest.d.ts +10 -1
  51. package/lib/types/convert/ingest.d.ts.map +1 -1
  52. package/lib/types/convert/ingest.js +68 -9
  53. package/lib/types/convert/ingest.js.map +1 -1
  54. package/lib/types/derive-contract.d.ts +3 -0
  55. package/lib/types/derive-contract.d.ts.map +1 -0
  56. package/lib/types/derive-contract.js +15 -0
  57. package/lib/types/derive-contract.js.map +1 -0
  58. package/lib/types/diagnosis/cards.d.ts +7 -3
  59. package/lib/types/diagnosis/cards.d.ts.map +1 -1
  60. package/lib/types/diagnosis/cards.js +13 -8
  61. package/lib/types/diagnosis/cards.js.map +1 -1
  62. package/lib/types/diagnosis/run.d.ts +4 -13
  63. package/lib/types/diagnosis/run.d.ts.map +1 -1
  64. package/lib/types/diagnosis/run.js +26 -16
  65. package/lib/types/diagnosis/run.js.map +1 -1
  66. package/lib/types/diagnosis/schema.js +2 -2
  67. package/lib/types/diagnosis/schema.js.map +1 -1
  68. package/lib/types/diagnosis/seed-source.d.ts +1 -1
  69. package/lib/types/diagnosis/seed-source.d.ts.map +1 -1
  70. package/lib/types/diagnosis/seed-source.js +5 -4
  71. package/lib/types/diagnosis/seed-source.js.map +1 -1
  72. package/lib/types/diagnosis/seed.d.ts +4 -4
  73. package/lib/types/diagnosis/seed.d.ts.map +1 -1
  74. package/lib/types/diagnosis/seed.js +6 -8
  75. package/lib/types/diagnosis/seed.js.map +1 -1
  76. package/lib/types/diagnosis/store.d.ts +24 -18
  77. package/lib/types/diagnosis/store.d.ts.map +1 -1
  78. package/lib/types/diagnosis/store.js +130 -65
  79. package/lib/types/diagnosis/store.js.map +1 -1
  80. package/lib/types/diagnosis/types.d.ts +47 -15
  81. package/lib/types/diagnosis/types.d.ts.map +1 -1
  82. package/lib/types/diagnosis/types.js.map +1 -1
  83. package/lib/types/environment/dsh-python.d.ts +77 -0
  84. package/lib/types/environment/dsh-python.d.ts.map +1 -0
  85. package/lib/types/environment/dsh-python.js +139 -0
  86. package/lib/types/environment/dsh-python.js.map +1 -0
  87. package/lib/types/environment/install.d.ts +15 -0
  88. package/lib/types/environment/install.d.ts.map +1 -0
  89. package/lib/types/environment/install.js +297 -0
  90. package/lib/types/environment/install.js.map +1 -0
  91. package/lib/types/environment/manifest.d.ts +208 -0
  92. package/lib/types/environment/manifest.d.ts.map +1 -0
  93. package/lib/types/environment/manifest.js +26 -0
  94. package/lib/types/environment/manifest.js.map +1 -0
  95. package/lib/types/environment/model-catalog.d.ts +223 -0
  96. package/lib/types/environment/model-catalog.d.ts.map +1 -0
  97. package/lib/types/environment/model-catalog.js +129 -0
  98. package/lib/types/environment/model-catalog.js.map +1 -0
  99. package/lib/types/environment/process.d.ts +10 -0
  100. package/lib/types/environment/process.d.ts.map +1 -0
  101. package/lib/types/environment/process.js +54 -0
  102. package/lib/types/environment/process.js.map +1 -0
  103. package/lib/types/environment/selection.d.ts +9 -0
  104. package/lib/types/environment/selection.d.ts.map +1 -0
  105. package/lib/types/environment/selection.js +29 -0
  106. package/lib/types/environment/selection.js.map +1 -0
  107. package/lib/types/environment/service.d.ts +64 -0
  108. package/lib/types/environment/service.d.ts.map +1 -0
  109. package/lib/types/environment/service.js +424 -0
  110. package/lib/types/environment/service.js.map +1 -0
  111. package/lib/types/environment/types.d.ts +56 -0
  112. package/lib/types/environment/types.d.ts.map +1 -0
  113. package/lib/types/environment/types.js +2 -0
  114. package/lib/types/environment/types.js.map +1 -0
  115. package/lib/types/events.d.ts +76 -0
  116. package/lib/types/events.d.ts.map +1 -0
  117. package/lib/types/events.js +52 -0
  118. package/lib/types/events.js.map +1 -0
  119. package/lib/types/extract-contract.d.ts +3 -0
  120. package/lib/types/extract-contract.d.ts.map +1 -0
  121. package/lib/types/extract-contract.js +41 -0
  122. package/lib/types/extract-contract.js.map +1 -0
  123. package/lib/types/extract-model.d.ts +5 -0
  124. package/lib/types/extract-model.d.ts.map +1 -1
  125. package/lib/types/extract-model.js.map +1 -1
  126. package/lib/types/extract-table-contract.d.ts +3 -0
  127. package/lib/types/extract-table-contract.d.ts.map +1 -0
  128. package/lib/types/extract-table-contract.js +27 -0
  129. package/lib/types/extract-table-contract.js.map +1 -0
  130. package/lib/types/extract-table.d.ts +8 -0
  131. package/lib/types/extract-table.d.ts.map +1 -0
  132. package/lib/types/extract-table.js +158 -0
  133. package/lib/types/extract-table.js.map +1 -0
  134. package/lib/types/extraction-runs.d.ts +30 -6
  135. package/lib/types/extraction-runs.d.ts.map +1 -1
  136. package/lib/types/extraction-runs.js +69 -8
  137. package/lib/types/extraction-runs.js.map +1 -1
  138. package/lib/types/fs-atomic.d.ts +0 -7
  139. package/lib/types/fs-atomic.d.ts.map +1 -1
  140. package/lib/types/fs-atomic.js +17 -2
  141. package/lib/types/fs-atomic.js.map +1 -1
  142. package/lib/types/images.d.ts +26 -0
  143. package/lib/types/images.d.ts.map +1 -0
  144. package/lib/types/images.js +196 -0
  145. package/lib/types/images.js.map +1 -0
  146. package/lib/types/index.d.ts +2 -2
  147. package/lib/types/index.d.ts.map +1 -1
  148. package/lib/types/index.js +598 -209
  149. package/lib/types/index.js.map +1 -1
  150. package/lib/types/intent/engine.d.ts +12 -4
  151. package/lib/types/intent/engine.d.ts.map +1 -1
  152. package/lib/types/intent/engine.js +43 -5
  153. package/lib/types/intent/engine.js.map +1 -1
  154. package/lib/types/intent/host.d.ts +5 -8
  155. package/lib/types/intent/host.d.ts.map +1 -1
  156. package/lib/types/intent/host.js +56 -11
  157. package/lib/types/intent/host.js.map +1 -1
  158. package/lib/types/intent/scope.d.ts +25 -0
  159. package/lib/types/intent/scope.d.ts.map +1 -0
  160. package/lib/types/intent/scope.js +116 -0
  161. package/lib/types/intent/scope.js.map +1 -0
  162. package/lib/types/intent/tools.d.ts +24 -20
  163. package/lib/types/intent/tools.d.ts.map +1 -1
  164. package/lib/types/intent/tools.js +65 -23
  165. package/lib/types/intent/tools.js.map +1 -1
  166. package/lib/types/intent/types.d.ts +11 -4
  167. package/lib/types/intent/types.d.ts.map +1 -1
  168. package/lib/types/knowledge-bases.d.ts +11 -5
  169. package/lib/types/knowledge-bases.d.ts.map +1 -1
  170. package/lib/types/knowledge-bases.js +52 -20
  171. package/lib/types/knowledge-bases.js.map +1 -1
  172. package/lib/types/knowledge-contract.d.ts +32 -0
  173. package/lib/types/knowledge-contract.d.ts.map +1 -0
  174. package/lib/types/knowledge-contract.js +116 -0
  175. package/lib/types/knowledge-contract.js.map +1 -0
  176. package/lib/types/knowledge.d.ts +31 -9
  177. package/lib/types/knowledge.d.ts.map +1 -1
  178. package/lib/types/knowledge.js +137 -60
  179. package/lib/types/knowledge.js.map +1 -1
  180. package/lib/types/layout.d.ts +10 -29
  181. package/lib/types/layout.d.ts.map +1 -1
  182. package/lib/types/layout.js +17 -36
  183. package/lib/types/layout.js.map +1 -1
  184. package/lib/types/materialize-snapshot.d.ts +49 -0
  185. package/lib/types/materialize-snapshot.d.ts.map +1 -0
  186. package/lib/types/materialize-snapshot.js +2 -0
  187. package/lib/types/materialize-snapshot.js.map +1 -0
  188. package/lib/types/migrate.d.ts +11 -0
  189. package/lib/types/migrate.d.ts.map +1 -1
  190. package/lib/types/migrate.js +83 -2
  191. package/lib/types/migrate.js.map +1 -1
  192. package/lib/types/model-text.d.ts +58 -1
  193. package/lib/types/model-text.d.ts.map +1 -1
  194. package/lib/types/model-text.js +85 -30
  195. package/lib/types/model-text.js.map +1 -1
  196. package/lib/types/oplog.d.ts.map +1 -1
  197. package/lib/types/oplog.js +7 -0
  198. package/lib/types/oplog.js.map +1 -1
  199. package/lib/types/organize-contract.d.ts +18 -0
  200. package/lib/types/organize-contract.d.ts.map +1 -0
  201. package/lib/types/organize-contract.js +82 -0
  202. package/lib/types/organize-contract.js.map +1 -0
  203. package/lib/types/pipeline/engine.d.ts +66 -0
  204. package/lib/types/pipeline/engine.d.ts.map +1 -0
  205. package/lib/types/pipeline/engine.js +352 -0
  206. package/lib/types/pipeline/engine.js.map +1 -0
  207. package/lib/types/pipeline/store.d.ts +73 -0
  208. package/lib/types/pipeline/store.d.ts.map +1 -0
  209. package/lib/types/pipeline/store.js +143 -0
  210. package/lib/types/pipeline/store.js.map +1 -0
  211. package/lib/types/pipeline/types.d.ts +102 -0
  212. package/lib/types/pipeline/types.d.ts.map +1 -0
  213. package/lib/types/pipeline/types.js +5 -0
  214. package/lib/types/pipeline/types.js.map +1 -0
  215. package/lib/types/present.d.ts +2 -0
  216. package/lib/types/present.d.ts.map +1 -1
  217. package/lib/types/present.js +9 -4
  218. package/lib/types/present.js.map +1 -1
  219. package/lib/types/preset-ids.d.ts +4 -0
  220. package/lib/types/preset-ids.d.ts.map +1 -0
  221. package/lib/types/preset-ids.js +6 -0
  222. package/lib/types/preset-ids.js.map +1 -0
  223. package/lib/types/query-analysis.d.ts +13 -1
  224. package/lib/types/query-analysis.d.ts.map +1 -1
  225. package/lib/types/query-analysis.js +62 -6
  226. package/lib/types/query-analysis.js.map +1 -1
  227. package/lib/types/recall-rank.d.ts +3 -3
  228. package/lib/types/recall-rank.d.ts.map +1 -1
  229. package/lib/types/recall-rank.js +4 -4
  230. package/lib/types/recall-rank.js.map +1 -1
  231. package/lib/types/retention.d.ts +39 -0
  232. package/lib/types/retention.d.ts.map +1 -0
  233. package/lib/types/retention.js +42 -0
  234. package/lib/types/retention.js.map +1 -0
  235. package/lib/types/retrieval/vector-index.d.ts +32 -0
  236. package/lib/types/retrieval/vector-index.d.ts.map +1 -0
  237. package/lib/types/retrieval/vector-index.js +15 -0
  238. package/lib/types/retrieval/vector-index.js.map +1 -0
  239. package/lib/types/retrieval/visibility.d.ts +6 -0
  240. package/lib/types/retrieval/visibility.d.ts.map +1 -0
  241. package/lib/types/retrieval/visibility.js +11 -0
  242. package/lib/types/retrieval/visibility.js.map +1 -0
  243. package/lib/types/runtime.d.ts +272 -27
  244. package/lib/types/runtime.d.ts.map +1 -1
  245. package/lib/types/runtime.js +2751 -537
  246. package/lib/types/runtime.js.map +1 -1
  247. package/lib/types/settings-schema.d.ts +17 -15
  248. package/lib/types/settings-schema.d.ts.map +1 -1
  249. package/lib/types/settings-schema.js +50 -47
  250. package/lib/types/settings-schema.js.map +1 -1
  251. package/lib/types/settings-volatile.d.ts +4 -4
  252. package/lib/types/settings-volatile.js +4 -4
  253. package/lib/types/source-evidence.d.ts +14 -0
  254. package/lib/types/source-evidence.d.ts.map +1 -0
  255. package/lib/types/source-evidence.js +36 -0
  256. package/lib/types/source-evidence.js.map +1 -0
  257. package/lib/types/store/axis-references.d.ts +5 -0
  258. package/lib/types/store/axis-references.d.ts.map +1 -0
  259. package/lib/types/store/axis-references.js +106 -0
  260. package/lib/types/store/axis-references.js.map +1 -0
  261. package/lib/types/store/derived.d.ts +12 -1
  262. package/lib/types/store/derived.d.ts.map +1 -1
  263. package/lib/types/store/derived.js +71 -12
  264. package/lib/types/store/derived.js.map +1 -1
  265. package/lib/types/store/knowledge-db.d.ts +31 -1
  266. package/lib/types/store/knowledge-db.d.ts.map +1 -1
  267. package/lib/types/store/knowledge-db.js +252 -18
  268. package/lib/types/store/knowledge-db.js.map +1 -1
  269. package/lib/types/store/migrate.d.ts.map +1 -1
  270. package/lib/types/store/migrate.js +17 -6
  271. package/lib/types/store/migrate.js.map +1 -1
  272. package/lib/types/trajectory-types.d.ts +172 -0
  273. package/lib/types/trajectory-types.d.ts.map +1 -0
  274. package/lib/types/trajectory-types.js +36 -0
  275. package/lib/types/trajectory-types.js.map +1 -0
  276. package/lib/types/types.d.ts +59 -27
  277. package/lib/types/types.d.ts.map +1 -1
  278. package/lib/types/types.js +6 -15
  279. package/lib/types/types.js.map +1 -1
  280. package/lib/types/wiki-finalize.d.ts +16 -0
  281. package/lib/types/wiki-finalize.d.ts.map +1 -1
  282. package/lib/types/wiki-finalize.js +26 -0
  283. package/lib/types/wiki-finalize.js.map +1 -1
  284. package/lib/types/wiki-materialize.d.ts +4 -0
  285. package/lib/types/wiki-materialize.d.ts.map +1 -1
  286. package/lib/types/wiki-materialize.js +21 -7
  287. package/lib/types/wiki-materialize.js.map +1 -1
  288. package/lib/types/wiki-trial-types.d.ts +87 -0
  289. package/lib/types/wiki-trial-types.d.ts.map +1 -1
  290. package/lib/types/wiki-trial-types.js +0 -16
  291. package/lib/types/wiki-trial-types.js.map +1 -1
  292. package/lib/types/wiki-trial.d.ts +40 -16
  293. package/lib/types/wiki-trial.d.ts.map +1 -1
  294. package/lib/types/wiki-trial.js +337 -224
  295. package/lib/types/wiki-trial.js.map +1 -1
  296. package/package.json +29 -20
  297. package/python/prepare-models.py +19 -0
  298. package/python/requirements.txt +8 -6
  299. package/scripts/doctor.mjs +13 -19
  300. package/scripts/environment.mjs +29 -0
  301. package/scripts/setup-embedding.sh +15 -5
  302. package/src/agent-behavior-rules.ts +37 -0
  303. package/src/axis-registry.ts +234 -27
  304. package/src/card-organize.ts +69 -75
  305. package/src/client/AgentBehaviorRulesCard.tsx +65 -0
  306. package/src/client/AttributionEventGuide.tsx +41 -39
  307. package/src/client/AxisRegistrySection.tsx +204 -164
  308. package/src/client/CompileDialogs.tsx +44 -29
  309. package/src/client/DeleteDocumentDialog.tsx +36 -5
  310. package/src/client/DirectoryPicker.tsx +0 -10
  311. package/src/client/EnvironmentSetup.tsx +243 -0
  312. package/src/client/ExpansionGraph.tsx +13 -7
  313. package/src/client/ExtractionTasksPage.tsx +578 -0
  314. package/src/client/GuideArchitectureCanvas.tsx +470 -0
  315. package/src/client/ImportFilesDialog.tsx +2 -13
  316. package/src/client/IntentLogic.tsx +2 -2
  317. package/src/client/IntentTab.tsx +118 -47
  318. package/src/client/KnowledgeBaseTab.tsx +277 -197
  319. package/src/client/KnowledgeLayerSection.tsx +24 -6
  320. package/src/client/KnowledgePanel.tsx +58 -93
  321. package/src/client/KnowledgeSettingsDrawer.tsx +90 -0
  322. package/src/client/ListPager.tsx +15 -5
  323. package/src/client/MaterializeTrajectoryView.tsx +124 -0
  324. package/src/client/NodeSettings.tsx +210 -89
  325. package/src/client/NormalizeTrajectoryView.tsx +136 -0
  326. package/src/client/PipelineNotice.tsx +26 -0
  327. package/src/client/PreviewSections.tsx +118 -51
  328. package/src/client/RecallPanel.tsx +89 -85
  329. package/src/client/TabGuide.tsx +159 -184
  330. package/src/client/TrialReportView.tsx +391 -214
  331. package/src/client/TypeDefinitionDrawer.tsx +150 -23
  332. package/src/client/WikiCardPreview.tsx +62 -16
  333. package/src/client/WikiFlowPanel.tsx +4 -4
  334. package/src/client/arch/NodeLogicPanel.tsx +3 -4
  335. package/src/client/arch/model.ts +6 -9
  336. package/src/client/architecture.tsx +23 -33
  337. package/src/client/attribution/AttributionGraph.tsx +10 -6
  338. package/src/client/attribution/AttributionTab.tsx +136 -84
  339. package/src/client/attribution/CaseView.tsx +3 -1
  340. package/src/client/attribution/EventView.tsx +108 -0
  341. package/src/client/attribution/RunView.tsx +2 -2
  342. package/src/client/attribution/StageChrome.tsx +34 -3
  343. package/src/client/attribution/ViewSwitch.tsx +20 -5
  344. package/src/client/attribution/graph-options.ts +47 -39
  345. package/src/client/attribution/model.ts +17 -10
  346. package/src/client/config-scope.ts +3 -3
  347. package/src/client/graph/palette.ts +165 -0
  348. package/src/client/index.ts +49 -42
  349. package/src/client/pages.css +459 -135
  350. package/src/client/pages.tsx +37 -9
  351. package/src/client/problem-domains.ts +1 -1
  352. package/src/client/session-remote.ts +9 -0
  353. package/src/client/styles.css +205 -62
  354. package/src/client/wiki-trial.ts +44 -3
  355. package/src/compiler/embedding-identity.ts +21 -0
  356. package/src/compiler/snapshot.ts +17 -0
  357. package/src/config-schema.ts +8 -3
  358. package/src/convert/host.ts +56 -21
  359. package/src/convert/ingest.ts +74 -10
  360. package/src/derive-contract.ts +14 -0
  361. package/src/diagnosis/cards.ts +13 -8
  362. package/src/diagnosis/run.ts +27 -17
  363. package/src/diagnosis/schema.ts +2 -2
  364. package/src/diagnosis/seed-source.ts +5 -4
  365. package/src/diagnosis/seed.ts +6 -8
  366. package/src/diagnosis/store.ts +138 -69
  367. package/src/diagnosis/types.ts +34 -15
  368. package/src/environment/dsh-python.ts +156 -0
  369. package/src/environment/install.ts +244 -0
  370. package/src/environment/manifest.ts +28 -0
  371. package/src/environment/model-catalog.ts +147 -0
  372. package/src/environment/process.ts +54 -0
  373. package/src/environment/selection.ts +29 -0
  374. package/src/environment/service.ts +348 -0
  375. package/src/environment/types.ts +45 -0
  376. package/src/events.ts +108 -0
  377. package/src/extract-contract.ts +42 -0
  378. package/src/extract-model.ts +10 -1
  379. package/src/extract-table-contract.ts +26 -0
  380. package/src/extract-table.ts +132 -0
  381. package/src/extraction-runs.ts +70 -11
  382. package/src/fs-atomic.ts +19 -2
  383. package/src/images.ts +203 -0
  384. package/src/index.ts +553 -205
  385. package/src/intent/README.md +8 -6
  386. package/src/intent/engine.ts +44 -6
  387. package/src/intent/host.ts +59 -18
  388. package/src/intent/scope.ts +125 -0
  389. package/src/intent/tools.ts +70 -28
  390. package/src/intent/types.ts +11 -4
  391. package/src/knowledge-bases.ts +56 -20
  392. package/src/knowledge-contract.ts +114 -0
  393. package/src/knowledge.ts +138 -69
  394. package/src/layout.ts +17 -37
  395. package/src/materialize-snapshot.ts +46 -0
  396. package/src/migrate.ts +75 -2
  397. package/src/model-text.ts +109 -4
  398. package/src/oplog.ts +7 -0
  399. package/src/organize-contract.ts +83 -0
  400. package/src/pipeline/engine.ts +323 -0
  401. package/src/pipeline/store.ts +147 -0
  402. package/src/pipeline/types.ts +93 -0
  403. package/src/present.ts +10 -4
  404. package/src/preset-ids.ts +6 -0
  405. package/src/python/embedding_worker.py +66 -2
  406. package/src/query-analysis.ts +68 -8
  407. package/src/recall-rank.ts +5 -5
  408. package/src/retention.ts +76 -0
  409. package/src/retrieval/vector-index.ts +45 -0
  410. package/src/retrieval/visibility.ts +14 -0
  411. package/src/runtime.ts +2708 -567
  412. package/src/settings-schema.ts +11 -8
  413. package/src/settings-volatile.ts +4 -4
  414. package/src/source-evidence.ts +37 -0
  415. package/src/store/axis-references.ts +96 -0
  416. package/src/store/derived.ts +70 -12
  417. package/src/store/knowledge-db.ts +248 -17
  418. package/src/store/migrate.ts +16 -6
  419. package/src/trajectory-types.ts +142 -0
  420. package/src/types.ts +61 -35
  421. package/src/wiki-finalize.ts +28 -0
  422. package/src/wiki-materialize.ts +25 -6
  423. package/src/wiki-trial-types.ts +83 -1
  424. package/src/wiki-trial.ts +357 -185
  425. package/lib/types/intent/preset-tools.d.ts +0 -37
  426. package/lib/types/intent/preset-tools.d.ts.map +0 -1
  427. package/lib/types/intent/preset-tools.js +0 -45
  428. package/lib/types/intent/preset-tools.js.map +0 -1
  429. package/preset/tita-data-agent/agent.cordis.yml +0 -394
  430. package/preset/tita-data-agent/preset.yml +0 -3
  431. package/scripts/install-agent-preset.mjs +0 -92
  432. package/scripts/sync-agent-preset.mjs +0 -188
  433. package/src/client/AgentPresetCard.tsx +0 -247
  434. package/src/client/agent-preset.ts +0 -121
  435. package/src/client/convert/ConvertPanel.tsx +0 -583
  436. package/src/client/convert/styles.css +0 -138
  437. package/src/client/convert/styles.ts +0 -49
  438. package/src/intent/preset-tools.ts +0 -48
@@ -30,19 +30,19 @@
30
30
 
31
31
  import { useMemo, useState, type ReactNode } from 'react'
32
32
  import {
33
- Bot, ChevronDown, Copy, FileText, Layers3, Quote, Settings2, ShieldCheck,
33
+ Bot, ChevronDown, Copy, Settings2,
34
34
  TriangleAlert, UserRound,
35
35
  } from '@tita-agent/ui/icons'
36
- import { cn } from '@tita-agent/ui/components'
36
+ import { Tabs, TabsContent, TabsList, TabsTrigger, cn } from '@tita-agent/ui/components'
37
37
  import type {
38
- TrialActor, TrialKnowledge, TrialMatrix, TrialMatrixGroup, TrialReportView, TrialSource,
38
+ TrialActor, TrialEvent, TrialEventStepKind, TrialKnowledge, TrialMatrix, TrialMatrixGroup, TrialReportView, TrialSource, TrialTokenUsage,
39
39
  } from './wiki-trial.ts'
40
40
  import { AxisMatrix, coordLabel, sceneLabel, type MatrixPick, type MatrixView } from './AxisMatrix.tsx'
41
41
  import { styles } from './styles.ts'
42
42
 
43
43
  /** 执行人 → 图标 + 说明。三档固定,不再多分。 */
44
44
  const ACTOR: Record<TrialActor, { icon: typeof Bot; hint: string }> = {
45
- 模型: { icon: Bot, hint: '抽取 Knowledge 与三个轴候选;判不动就标出来' },
45
+ 模型: { icon: Bot, hint: '抽取 Knowledge 与坐标;编译时可对候选歧义补判' },
46
46
  系统: { icon: Settings2, hint: '确定性规则,每次结果一致:归一、绑定、物化、建索引' },
47
47
  人: { icon: UserRound, hint: '只看规则与模型都覆盖不到的:同义裁决、冲突裁决、editorial' },
48
48
  }
@@ -53,6 +53,212 @@ const ITEM_CAP = 24
53
53
  /** 知识是平铺清单,给得比步骤宽一点,但也要有上限。 */
54
54
  const LIST_CAP = 60
55
55
 
56
+ function tokenCount(value: number | undefined): string {
57
+ return value === undefined ? '—' : value.toLocaleString('zh-CN')
58
+ }
59
+
60
+ function usageSummary(usage?: TrialTokenUsage): string {
61
+ if (!usage) return '用量未返回'
62
+ const hasInput = usage.inputTokens !== undefined || usage.cacheReadTokens !== undefined || usage.cacheWriteTokens !== undefined
63
+ const input = hasInput
64
+ ? (usage.inputTokens ?? 0) + (usage.cacheReadTokens ?? 0) + (usage.cacheWriteTokens ?? 0)
65
+ : undefined
66
+ const total = usage.totalTokens ?? (input !== undefined && usage.outputTokens !== undefined ? input + usage.outputTokens : undefined)
67
+ return `输入 ${tokenCount(input)} · 输出 ${tokenCount(usage.outputTokens)} · 合计 ${tokenCount(total)} tokens`
68
+ }
69
+
70
+ function totalTokensOf(usage?: TrialTokenUsage): number | undefined {
71
+ if (!usage) return undefined
72
+ if (usage.totalTokens !== undefined) return usage.totalTokens
73
+ if (usage.outputTokens === undefined) return undefined
74
+ const hasInput = usage.inputTokens !== undefined || usage.cacheReadTokens !== undefined || usage.cacheWriteTokens !== undefined
75
+ if (!hasInput) return undefined
76
+ return (usage.inputTokens ?? 0) + (usage.cacheReadTokens ?? 0) + (usage.cacheWriteTokens ?? 0) + usage.outputTokens
77
+ }
78
+
79
+ const EVENT_STEP_LABEL: Record<TrialEventStepKind, string> = {
80
+ observation: '观察', check: '核对', action: '操作', result: '结果', conclusion: '结论',
81
+ }
82
+
83
+ /**
84
+ * 区块导航。
85
+ *
86
+ * 这份报告可以有七步、几十条知识、几百 KB —— 打开它的人第一件事是「跳到我要看的那一段」,
87
+ * 而不是从上往下读。所以顶上放一条**锚点条**:它是这一页的目录,不是第二个流程说明。
88
+ *
89
+ * 用 `<a href>` 而不是按钮:这一页就是一份文档,锚点带来的是「复制链接给同事」这种
90
+ * 浏览器本来就有的能力(`#steps` 直接落到处理步骤)。
91
+ */
92
+ const SECTIONS: Array<{ id: string; label: string }> = [
93
+ { id: 'trial-overview', label: '概览' },
94
+ { id: 'trial-output', label: '抽取内容' },
95
+ { id: 'trial-steps', label: '处理步骤' },
96
+ { id: 'trial-requests', label: '模型请求' },
97
+ { id: 'trial-review', label: '核验结果' },
98
+ ]
99
+
100
+ function SectionNav({ items }: { items: typeof SECTIONS }): ReactNode {
101
+ return <nav className={styles.trialNav} aria-label="报告区块">
102
+ {items.map(section => <a key={section.id} href={`#${section.id}`}>{section.label}</a>)}
103
+ </nav>
104
+ }
105
+
106
+ function InlineDisclosure({ summary, children }: { summary: string; children: ReactNode }): ReactNode {
107
+ const [expanded, setExpanded] = useState(false)
108
+ return <>
109
+ <button type="button" className={styles.trialDetailToggle} aria-expanded={expanded}
110
+ onClick={() => setExpanded(value => !value)}>
111
+ <ChevronDown size={11} className={cn(styles.trialChevron, expanded && styles.trialChevronOpen)} />{summary}
112
+ </button>
113
+ {expanded && <div className={styles.trialDetailBody}>{children}</div>}
114
+ </>
115
+ }
116
+
117
+ function KnowledgeOutputItem({ item }: { item: TrialKnowledge }): ReactNode {
118
+ return <li className={styles.trialOutputItem}>
119
+ <div className={styles.trialCandHead}>
120
+ <span className={cn(styles.trialCandName, item.noCoordinate && styles.trialCandBad)}>{item.text}</span>
121
+ <span className={styles.trialCandMeta}>{item.id}</span>
122
+ </div>
123
+ <div className={styles.trialOutputMeta}>
124
+ {coordLabel(item.object, item.action, item.scene)} · {item.section} 第 {item.order} 位 · {item.sources.length} 处来源
125
+ {item.noCoordinate && <strong>缺少坐标</strong>}
126
+ </div>
127
+ {item.sources.length > 0 && <InlineDisclosure summary={`查看 ${item.sources.length} 处来源`}>
128
+ <ul className={styles.trialSources}>{item.sources.map((source, index) => <SourceLine key={index} source={source} />)}</ul>
129
+ </InlineDisclosure>}
130
+ </li>
131
+ }
132
+
133
+ function EventOutputItem({ event }: { event: TrialEvent }): ReactNode {
134
+ const coordinate = coordLabel(event.object, event.action, event.scene)
135
+ const sourceCount = event.sources.length + event.timeline.reduce((sum, step) => sum + step.sources.length, 0)
136
+ return <li className={styles.trialOutputItem}>
137
+ <div className={styles.trialCandHead}>
138
+ <span className={styles.trialCandName}>{event.title || '未命名 Event'}</span>
139
+ <span className={styles.trialCandMeta}>{event.occurredAt ?? '时间未记录'}</span>
140
+ </div>
141
+ <p className={styles.trialOutputText}>{event.summary || event.symptom || '没有摘要'}</p>
142
+ <div className={styles.trialOutputMeta}>
143
+ {coordinate} · {event.timeline.length} 个步骤 · {sourceCount} 处来源
144
+ {event.noCoordinate && <strong>缺少坐标</strong>}
145
+ </div>
146
+ <InlineDisclosure summary="查看事件过程与结论">
147
+ {event.symptom && <p className={styles.trialOutputText}><b>现象:</b>{event.symptom}</p>}
148
+ {event.timeline.length > 0 && <ol className={styles.trialEventTimeline}>
149
+ {event.timeline.map(step => <li key={step.id}>
150
+ <span>{EVENT_STEP_LABEL[step.type] ?? step.type}</span>
151
+ <div>{step.description}{step.result ? ` · ${step.result}` : ''}</div>
152
+ {step.sources.length > 0 && <ul className={styles.trialSources}>{step.sources.map((source, index) => <SourceLine key={index} source={source} />)}</ul>}
153
+ </li>)}
154
+ </ol>}
155
+ {event.rootCause && <p className={styles.trialOutputText}><b>原因:</b>{event.rootCause}{event.rootCauseStatus === 'suspected' ? '(待确认)' : ''}</p>}
156
+ {event.outcome && <p className={styles.trialOutputText}><b>结果:</b>{event.outcome}</p>}
157
+ {event.missing.length > 0 && <p className={styles.trialOutputMeta}>待补信息:{event.missing.join('、')}</p>}
158
+ {event.sources.length > 0 && <ul className={styles.trialSources}>{event.sources.map((source, index) => <SourceLine key={index} source={source} />)}</ul>}
159
+ </InlineDisclosure>
160
+ </li>
161
+ }
162
+
163
+ function WikiCardOutputItem({ card, report }: { card: TrialReportView['wikiCards'][number]; report: TrialReportView }): ReactNode {
164
+ const eventNames = card.events.map(id => report.events?.find(event => event.id === id)?.title ?? id)
165
+ return <li className={styles.trialOutputItem}>
166
+ <div className={styles.trialCandHead}>
167
+ <span className={styles.trialCandName}>{card.name}</span>
168
+ <span className={styles.trialCandMeta}>{card.placements.length} Knowledge · {card.events.length} Event</span>
169
+ </div>
170
+ <div className={styles.trialOutputMeta}>{coordLabel(card.object, card.action, card.scene)}</div>
171
+ {(card.placements.length > 0 || eventNames.length > 0) && <InlineDisclosure summary="查看卡片内容">
172
+ {card.placements.length > 0 && <ul className={styles.trialSources}>
173
+ {card.placements.map(placement => <li key={placement.item} className={styles.trialSource}>
174
+ <span className={styles.trialSourceQuote}>{placement.section} 第 {placement.order} 位</span>
175
+ <span className={styles.trialSourceWhere}>{report.knowledge.find(item => item.id === placement.item)?.text ?? placement.item}</span>
176
+ </li>)}
177
+ </ul>}
178
+ {eventNames.length > 0 && <ul className={styles.trialCardEvents}>{eventNames.map((name, index) => <li key={`${card.events[index]}-${index}`}>{name}</li>)}</ul>}
179
+ </InlineDisclosure>}
180
+ </li>
181
+ }
182
+
183
+ /** 一条模型请求的输入、输出和用量放在同一个默认折叠区块里。 */
184
+ function ModelRequestDisclosure({
185
+ title,
186
+ status,
187
+ request,
188
+ prompt,
189
+ response,
190
+ responseLabel,
191
+ usage,
192
+ why,
193
+ onCopy,
194
+ copied,
195
+ }: {
196
+ title: string
197
+ status: string
198
+ request?: NonNullable<TrialReportView['model']['request']>
199
+ prompt: { system: string; user: string }
200
+ response?: string
201
+ responseLabel: string
202
+ usage?: TrialTokenUsage
203
+ why?: string
204
+ onCopy?: () => void
205
+ copied?: string
206
+ }): ReactNode {
207
+ const [expanded, setExpanded] = useState(false)
208
+ const usageText = usageSummary(usage)
209
+ const usageDetails = usage ? [
210
+ usage.inputTokens !== undefined ? `普通输入 ${tokenCount(usage.inputTokens)}` : undefined,
211
+ usage.cacheReadTokens !== undefined ? `缓存读 ${tokenCount(usage.cacheReadTokens)}` : undefined,
212
+ usage.cacheWriteTokens !== undefined ? `缓存写 ${tokenCount(usage.cacheWriteTokens)}` : undefined,
213
+ usage.reasoningTokens !== undefined ? `推理 ${tokenCount(usage.reasoningTokens)}` : undefined,
214
+ ].filter(Boolean).join(' · ') : ''
215
+
216
+ return <>
217
+ <button type="button" className={cn(styles.trialToggle, styles.trialRequestToggle)} aria-expanded={expanded}
218
+ onClick={() => setExpanded(value => !value)}>
219
+ <span className={styles.trialRequestTitle}>
220
+ <ChevronDown size={12} className={cn(styles.trialChevron, expanded && styles.trialChevronOpen)} />
221
+ <strong>{title}</strong><span>{status}</span>
222
+ </span>
223
+ <span className={styles.trialRequestUsage}>{usageText}</span>
224
+ </button>
225
+ {expanded && <div className={styles.trialPrompt}>
226
+ {request && <div className={styles.trialPromptHead}>
227
+ <span>
228
+ {[request.provider, request.model].filter(Boolean).join(' / ') || '未记录模型路由'}
229
+ {request.reasoningEffort ? ` · ${request.reasoningEffort}` : ''}
230
+ {request.sessionId ? ` · ${request.sessionId}` : ''}
231
+ </span>
232
+ </div>}
233
+ {why && <div className={styles.trialCandWhy}>{why}</div>}
234
+ {usage && <div className={styles.trialPromptHead}>
235
+ <span>{usageText}{usageDetails ? `(${usageDetails})` : ''}</span>
236
+ </div>}
237
+ <div className={styles.trialPromptHead}>
238
+ <span>System 输入 · {prompt.system.length} 字</span>
239
+ {onCopy && <button type="button" className={styles.trialCopy} onClick={onCopy}>
240
+ <Copy size={11} />{copied || '复制输入'}
241
+ </button>}
242
+ </div>
243
+ <pre className={styles.trialPromptText} tabIndex={0} role="region" aria-label={`${title} system 输入`}>
244
+ {prompt.system}
245
+ </pre>
246
+ <div className={styles.trialPromptHead}>
247
+ <span>User 输入 · {prompt.user.length} 字</span>
248
+ </div>
249
+ <pre className={styles.trialPromptText} tabIndex={0} role="region" aria-label={`${title} user 输入`}>
250
+ {prompt.user}
251
+ </pre>
252
+ <div className={styles.trialPromptHead}>
253
+ <span>{responseLabel}{response === undefined ? '' : ` · ${response.length} 字`}</span>
254
+ </div>
255
+ <pre className={styles.trialPromptText} tabIndex={0} role="region" aria-label={`${title} 输出`}>
256
+ {response ?? '这次没有保存模型返回内容。'}
257
+ </pre>
258
+ </div>}
259
+ </>
260
+ }
261
+
56
262
  /** 一处出处:引文 + 定位 + 核验结果。 */
57
263
  function SourceLine({ source }: { source: TrialSource }): ReactNode {
58
264
  return <li className={cn(styles.trialSource, !source.found && styles.trialSourceBad)}>
@@ -206,12 +412,17 @@ function Matrix({ report }: { report: TrialReportView }): ReactNode {
206
412
  * 例外**。反过来读的话,人得先读完七个步骤才看得到「这次到底抽出了什么」。
207
413
  */
208
414
  export function TrialReport({ report }: { report: TrialReportView }): ReactNode {
209
- const [open, setOpen] = useState('')
210
- const [showKnowledge, setShowKnowledge] = useState(false)
211
- const [showCards, setShowCards] = useState(false)
212
- const [showPrompt, setShowPrompt] = useState(false)
213
- const [showAudit, setShowAudit] = useState(false)
415
+ const [openStep, setOpenStep] = useState('')
214
416
  const [copied, setCopied] = useState('')
417
+ const events = report.events ?? []
418
+ const recordedUsage = [report.model.usage, report.model.axisResolution?.usage]
419
+ .filter((usage): usage is TrialTokenUsage => usage !== undefined)
420
+ const totals = recordedUsage.map(totalTokensOf).filter((value): value is number => value !== undefined)
421
+ const recordedTokens = totals.length > 0 ? totals.reduce((sum, value) => sum + value, 0) : undefined
422
+ const usageLabel = recordedTokens === undefined ? '未返回' : `${recordedTokens.toLocaleString('zh-CN')} tokens`
423
+ const usageNote = recordedUsage.length === 0
424
+ ? '模型未返回用量'
425
+ : `${recordedUsage.length} 次调用有用量`
215
426
 
216
427
  const actorChip = (actor: TrialActor): ReactNode => {
217
428
  const Icon = ACTOR[actor].icon
@@ -220,12 +431,6 @@ export function TrialReport({ report }: { report: TrialReportView }): ReactNode
220
431
  </span>
221
432
  }
222
433
 
223
- /**
224
- * 复制提示词。
225
- *
226
- * 人要拿它去改文档、贴到别处试。剪贴板会被权限或非安全上下文挡住,所以失败也要出声 ——
227
- * 按钮点了没反应,比报错更难查。
228
- */
229
434
  const copyPrompt = async (): Promise<void> => {
230
435
  const text = `# system\n${report.prompt.system}\n\n# user\n${report.prompt.user}`
231
436
  let label = '已复制'
@@ -238,212 +443,184 @@ export function TrialReport({ report }: { report: TrialReportView }): ReactNode
238
443
  window.setTimeout(() => setCopied(''), 2000)
239
444
  }
240
445
 
241
- return <>
242
- {!report.model.ok && <p className={styles.trialError} role="alert">
243
- <TriangleAlert size={12} />
244
- {report.model.why ?? '模型没有参与'} —— 知识、坐标和卡片都为空,但四条核验与发出去的提示词仍然是真的。
245
- </p>}
446
+ const defaultTab = report.knowledge.length > 0 ? 'knowledge' : events.length > 0 ? 'events' : 'cards'
447
+ /**
448
+ * 「这一次什么都没抽出来」。
449
+ *
450
+ * 一次模型没跑通的运行会有五行 0、一个三个空页签的内容区、一条空列表 —— 一屏全是
451
+ * 「没有」。而这时真正有信息的只有两样:**为什么失败**,以及**发出去的提示词**。
452
+ * 所以这种记录把概览压成一行、整段跳过内容区,直接把位置让给模型请求与核验。
453
+ */
454
+ const empty = !report.model.ok && report.knowledge.length === 0 && events.length === 0 && report.wikiCards.length === 0
455
+ /** 流水线的抽取阶段落下的记录:报告里的 ②③④ 段只是试跑顺带算的预览。 */
456
+ const extractOnly = report.scope === 'extract-only'
246
457
 
247
- {/* 矩阵排在最前面。它是概览,不是明细 —— 第一眼看的就是它。
248
- 两条轴都空说明模型没给出东西,这时候画一张空表只是噪音,上面的告警已经说清了。*/}
249
- {(report.matrix.objects.length > 0 || report.matrix.actions.length > 0) && <Matrix report={report} />}
250
-
251
- {/* 四条本地核验。报出来,不阻塞 —— 它们回答"这次抽出来的东西值不值得信"。*/}
252
- <section className={styles.trialChecks}>
253
- <h4><ShieldCheck size={12} />四条本地核验</h4>
254
- <ul>
255
- {report.checks.map(check => <li key={check.name} className={cn(styles.trialCheck, check.hits > 0 && styles.trialCheckHit)}>
256
- <span className={styles.trialCheckName}>{check.name}</span>
257
- <span className={styles.trialCheckHits}>{check.hits > 0 ? `${check.hits} 条` : '通过'}</span>
258
- <span className={styles.trialCheckWhat}>{check.what}</span>
259
- <span className={styles.trialCheckNote}>{check.note}</span>
260
- </li>)}
261
- </ul>
458
+ return <div className={styles.trialReport}>
459
+ {/* 只列真的会渲染出来的区块:空运行的「抽取内容」整段被跳过,留着就是一个点了没反应的锚点。 */}
460
+ <SectionNav items={empty ? SECTIONS.filter(section => section.id !== 'trial-output') : SECTIONS} />
461
+ <section id="trial-overview" className={styles.trialOverview} aria-labelledby="trial-overview-title">
462
+ <div className={styles.trialSectionHead}>
463
+ <h2 id="trial-overview-title">结果概览</h2>
464
+ <span>{report.model.ok ? '已完成' : '需检查'}</span>
465
+ </div>
466
+ {/* 空运行不排五行 0:那五行没有一个数字是结论,而失败原因在上面那一条里。 */}
467
+ {empty
468
+ // 一行平话,不是虚线空态框:框会在红色报错上方再压一层「这里什么都没有」,
469
+ // 而真正该被读到的是下面那句失败原因。
470
+ ? <p className={styles.trialOverviewEmpty}>这一次没有形成任何 Knowledge、Event 或 WikiCard。</p>
471
+ : <dl className={styles.trialOverviewStats}>
472
+ <div><dt>Knowledge</dt><dd>{report.knowledge.length}</dd></div>
473
+ <div><dt>Event</dt><dd>{events.length}</dd></div>
474
+ <div><dt>坐标</dt><dd>{report.objects.length} / {report.actions.length} / {report.scenes.length}<small>对象 / 动作 / 场景</small></dd></div>
475
+ {!extractOnly && <div><dt>WikiCard</dt><dd>{report.wikiCards.length}</dd></div>}
476
+ <div><dt>已报告 Token</dt><dd>{usageLabel}<small>{usageNote}</small></dd></div>
477
+ </dl>}
478
+ <p className={styles.trialOverviewTitle}>
479
+ <strong>{report.title}</strong><span>{report.lines} 行 · {report.chars.toLocaleString('zh-CN')} 字</span>
480
+ </p>
481
+ {report.subject && report.subject !== report.title && <p className={styles.trialOverviewSubject}>主题:{report.subject}</p>}
262
482
  </section>
263
483
 
264
- {/* 知识层。**只有 text 是知识**,下面那行全是索引与出处 —— 这个区分是整个方案的重心。*/}
265
- {report.knowledge.length > 0 && <>
266
- <button type="button" className={styles.trialToggle} aria-expanded={showKnowledge}
267
- onClick={() => setShowKnowledge(value => !value)}>
268
- <ChevronDown size={12} className={cn(styles.trialChevron, showKnowledge && styles.trialChevronOpen)} />
269
- <Quote size={11} />知识清单({report.knowledge.length})
270
- </button>
271
- {showKnowledge && <ul className={styles.trialCandidates}>
272
- {report.knowledge.slice(0, LIST_CAP).map(item => <li key={item.id}>
273
- <div className={styles.trialCandHead}>
274
- <span className={cn(styles.trialCandName, item.noCoordinate && styles.trialCandBad)}>{item.text}</span>
275
- <span className={styles.trialCandMeta}>{item.id}</span>
276
- </div>
277
- <div className={styles.trialCandWhy}>
278
- 坐标:{coordLabel(item.object, item.action, item.scene)}
279
- {' · '}位置:{item.section} 第 {item.order} 位
280
- </div>
281
- {item.sources.length > 0
282
- ? <ul className={styles.trialSources}>{item.sources.map((source, index) => <SourceLine key={index} source={source} />)}</ul>
283
- : <div className={styles.trialCandWhy}>没有出处 —— 没有原文依据的判断不可信</div>}
284
- </li>)}
285
- {report.knowledge.length > LIST_CAP && <p className={styles.trialMore}>
286
- 另有 {report.knowledge.length - LIST_CAP} 条知识。
287
- </p>}
288
- </ul>}
289
- </>}
290
-
291
- <div className={styles.kbSubHead}><h4>四个阶段,七个动作</h4><span className={styles.trialLegend}>
292
- {(['系统', '模型', '人'] as TrialActor[]).map(actor => <span key={actor}>{actorChip(actor)}</span>)}
293
- </span></div>
294
-
295
- <ol className={styles.trialSteps}>
296
- {report.steps.map((step, index) => {
297
- const expanded = open === step.id
298
- // 前端刷新可能先于服务端重启。旧服务端不带 `items`,这里兜一下,
299
- // 免得整块面板白屏 —— 那种失败最难查。
300
- const items = step.items ?? []
301
- const phaseStart = index === 0 || report.steps[index - 1]!.phase !== step.phase
302
- return <li key={step.id} className={styles.trialStepWrap}>
303
- {/* 阶段头只在阶段变化时出现。七个动作是四段里的,不是并列的七件事。*/}
304
- {phaseStart && <p className={styles.trialPhaseHead}>{step.phase}</p>}
305
- <div className={cn(styles.trialStep, step.needsHuman && styles.trialStepWarn)}>
306
- <button
307
- type="button"
308
- className={styles.trialStepHead}
309
- onClick={() => setOpen(expanded ? '' : step.id)}
310
- aria-expanded={expanded}
311
- >
312
- <span className={styles.trialStepOrder}>{step.order}</span>
313
- <span className={styles.trialStepName}>{step.name}</span>
314
- {actorChip(step.actor)}
315
- <ChevronDown size={12} className={cn(styles.trialChevron, expanded && styles.trialChevronOpen)} />
316
- <span className={styles.trialStepSum}>{step.summary}</span>
317
- </button>
318
- {expanded && <div className={styles.trialStepBody}>
319
- {/* 产出在前,判据在后:review 时先看"判出了什么",再看"按什么判"。*/}
320
- <section className={styles.trialProduce}>
321
- <h5 className={styles.trialProduceHead}>
322
- 产出{items.length > 0 ? ` · ${items.length} 条` : ''}
323
- </h5>
324
- {items.length === 0
325
- ? <p className={styles.trialItemsNone}>
326
- {report.model.ok ? '这一步没有产出。' : '模型没参与,这一步没有判定。'}
327
- </p>
328
- : <>
329
- <ul className={styles.trialItems}>
330
- {items.slice(0, ITEM_CAP).map((entry, itemIndex) => <li
331
- key={`${step.id}-${itemIndex}`}
332
- className={cn(styles.trialItem, entry.flag === 'warn' && styles.trialItemWarn)}
333
- >
334
- <span className={styles.trialItemRef}>{entry.ref}</span>
335
- <span className={styles.trialItemArrow} aria-hidden="true">→</span>
336
- <span className={styles.trialItemValue}>{entry.value}</span>
337
- {entry.note && <span className={styles.trialItemNote}>({entry.note})</span>}
338
- </li>)}
339
- </ul>
340
- {items.length > ITEM_CAP && <p className={styles.trialItemsMore}>
341
- 另有 {items.length - ITEM_CAP} 条,是这一步的同类判定。
342
- </p>}
343
- </>}
344
- </section>
345
- {step.rows.length > 0 && <dl className={styles.trialRows}>
346
- {step.rows.map(row => <div className={styles.trialRow} key={`${step.id}-${row.label}`}>
347
- <dt>{row.label}</dt><dd>{row.value}</dd>
348
- </div>)}
349
- </dl>}
350
- </div>}
351
- </div>
352
- </li>
353
- })}
354
- </ol>
355
-
356
- {report.exceptions.length > 0 && <div className={styles.trialExceptions}>
357
- <h4><TriangleAlert size={12} />{report.exceptions.length} 处要人看</h4>
358
- <ul>
359
- {report.exceptions.slice(0, 6).map((item, index) => <li key={`${item.step}-${index}`}>
360
- <span className={styles.trialExcStep}>{item.step}</span>
361
- <span>{item.message}</span>
362
- </li>)}
363
- </ul>
364
- {report.exceptions.length > 6 && <p className={styles.trialMore}>
365
- 另有 {report.exceptions.length - 6} 处同类,规则调好之后会一起消失。
366
- </p>}
367
- </div>}
368
-
369
- <button type="button" className={styles.trialToggle} onClick={() => setShowCards(value => !value)} aria-expanded={showCards}>
370
- <ChevronDown size={12} className={cn(styles.trialChevron, showCards && styles.trialChevronOpen)} />
371
- <Layers3 size={11} />WikiCard 明细({report.wikiCards.length})—— 每张卡引用了哪些知识
372
- </button>
484
+ {!report.model.ok && <p className={styles.trialError} role="alert">
485
+ <TriangleAlert size={12} />{report.model.why ?? '模型没有参与'} · 本次没有形成有效 Knowledge 或 Event。
486
+ </p>}
373
487
 
374
- {showCards && (report.wikiCards.length > 0
375
- ? <ul className={styles.trialCandidates}>
376
- {report.wikiCards.map((card, index) => <li key={`${card.name}-${index}`}>
377
- <div className={styles.trialCandHead}>
378
- <span className={styles.trialCandName}>{card.name}</span>
379
- <span className={styles.trialCandMeta}>
380
- {coordLabel(card.object, card.action, card.scene)} · {card.placements.length} 条知识
381
- </span>
382
- </div>
383
- <div className={styles.trialCandWhy}>
384
- 标题由坐标生成,先说清对象、场景和动作;坐标是主键,模型不参与命名。
385
- </div>
386
- <ul className={styles.trialSources}>
387
- {card.placements.map(placement => <li key={placement.item} className={styles.trialSource}>
388
- <span className={styles.trialSourceQuote}>
389
- {placement.section} 第 {placement.order} 位
390
- </span>
391
- <span className={styles.trialSourceWhere}>
392
- {placement.item} · {report.knowledge.find(item => item.id === placement.item)?.text ?? '(引用了不存在的知识)'}
393
- </span>
394
- </li>)}
395
- </ul>
396
- <div className={styles.trialCandWhy}>
397
- 人写的内容进 Wiki Card Note,不进这张卡的正文 —— 卡片只由编译器生成。
398
- </div>
399
- </li>)}
400
- </ul>
401
- : <p className={styles.trialEmpty}>
402
- 没有成卡。一个坐标 + 至少一条知识才天然要建一张卡 —— 知识可能一条坐标都没挂上。
403
- </p>)}
404
-
405
- {/* 提示词摊在这里。显示的必须是**真发出去的那条** —— 文档写一套、代码跑另一套
406
- 而没人发现,是最贵的错。模型没参与时也照给:那正是"本来会发出去什么"。*/}
407
- <button type="button" className={styles.trialToggle} aria-expanded={showPrompt}
408
- onClick={() => setShowPrompt(value => !value)}>
409
- <ChevronDown size={12} className={cn(styles.trialChevron, showPrompt && styles.trialChevronOpen)} />
410
- 给模型的提示词(一次调用,system + user 全文)
411
- </button>
488
+ {!empty && <section id="trial-output" className={styles.trialSection} aria-labelledby="trial-output-title">
489
+ <div className={styles.trialSectionHead}>
490
+ <h2 id="trial-output-title">抽取内容</h2>
491
+ <span>按类型查看抽取结果</span>
492
+ </div>
493
+ <Tabs defaultValue={defaultTab} className={styles.trialOutputTabs}>
494
+ <TabsList variant="segmented" aria-label="抽取结果类型">
495
+ <TabsTrigger value="knowledge">Knowledge · {report.knowledge.length}</TabsTrigger>
496
+ <TabsTrigger value="events">Event · {events.length}</TabsTrigger>
497
+ <TabsTrigger value="cards">WikiCard · {report.wikiCards.length}</TabsTrigger>
498
+ </TabsList>
499
+ <TabsContent value="knowledge">
500
+ {(report.matrix.objects.length > 0 || report.matrix.actions.length > 0) && <Matrix report={report} />}
501
+ {report.knowledge.length > 0
502
+ ? <ul className={styles.trialOutputList}>{report.knowledge.slice(0, LIST_CAP).map(item => <KnowledgeOutputItem key={item.id} item={item} />)}</ul>
503
+ : <p className={styles.trialEmpty}>这次没有抽取到 Knowledge。</p>}
504
+ {report.knowledge.length > LIST_CAP && <p className={styles.trialMore}>另有 {report.knowledge.length - LIST_CAP} 条 Knowledge 未展开。</p>}
505
+ </TabsContent>
506
+ <TabsContent value="events">
507
+ {events.length > 0
508
+ ? <ul className={styles.trialOutputList}>{events.slice(0, LIST_CAP).map(event => <EventOutputItem key={event.id} event={event} />)}</ul>
509
+ : <p className={styles.trialEmpty}>这次没有抽取到 Event。</p>}
510
+ {events.length > LIST_CAP && <p className={styles.trialMore}>另有 {events.length - LIST_CAP} 个 Event 未展开。</p>}
511
+ </TabsContent>
512
+ <TabsContent value="cards">
513
+ {report.wikiCards.length > 0
514
+ ? <ul className={styles.trialOutputList}>{report.wikiCards.map((card, index) => <WikiCardOutputItem key={`${card.name}-${index}`} card={card} report={report} />)}</ul>
515
+ : <p className={styles.trialEmpty}>没有可物化的 WikiCard。</p>}
516
+ </TabsContent>
517
+ </Tabs>
518
+ </section>}
412
519
 
413
- {showPrompt && <div className={styles.trialPrompt}>
414
- <div className={styles.trialPromptHead}>
415
- <span>system · {report.prompt.system.length} 字 · 框里可滚动</span>
416
- <button type="button" className={styles.trialCopy} onClick={() => void copyPrompt()}>
417
- <Copy size={11} />{copied || '复制两段'}
418
- </button>
520
+ <section id="trial-steps" className={styles.trialSection} aria-labelledby="trial-steps-title">
521
+ <div className={styles.trialSectionHead}>
522
+ <h2 id="trial-steps-title">处理步骤</h2>
523
+ <span>{extractOnly ? '1 个阶段 · 抽取' : `4 个阶段 · ${report.steps.length} 步`}</span>
419
524
  </div>
420
- <pre className={styles.trialPromptText} tabIndex={0} role="region" aria-label="system 提示词">
421
- {report.prompt.system}
422
- </pre>
423
- <div className={styles.trialPromptHead}>
424
- <span>user · {report.prompt.user.length} 字 · 框里可滚动</span>
525
+ {/* 只在流水线的抽取记录上说明:旧的全链路编译里这四段是真跑过的,说了反而错。 */}
526
+ {extractOnly && <p className={styles.trialNote}>
527
+ 这里只列<b>抽取</b>这一步。② 归一、③ 物化、④ 建索引在这个库里是独立阶段,
528
+ 各有自己的轨迹与任务;下面是抽取时按机械规则顺带算的预览,不代表库里的现状。
529
+ </p>}
530
+ <ol className={styles.trialSteps}>
531
+ {(extractOnly ? report.steps.filter(step => step.id === 'extract') : report.steps).map((step, index, list) => {
532
+ const expanded = openStep === step.id
533
+ const items = step.items ?? []
534
+ const phaseStart = index === 0 || list[index - 1]!.phase !== step.phase
535
+ return <li key={step.id} className={styles.trialStepWrap}>
536
+ {phaseStart && <p className={styles.trialPhaseHead}>{step.phase}</p>}
537
+ <div className={cn(styles.trialStep, step.needsHuman && styles.trialStepWarn)}>
538
+ <button type="button" className={styles.trialStepHead}
539
+ onClick={() => setOpenStep(expanded ? '' : step.id)} aria-expanded={expanded}>
540
+ <span className={styles.trialStepOrder}>{step.order}</span>
541
+ <span className={styles.trialStepName}>{step.name}</span>
542
+ {actorChip(step.actor)}
543
+ <ChevronDown size={12} className={cn(styles.trialChevron, expanded && styles.trialChevronOpen)} />
544
+ <span className={styles.trialStepSum}>{step.summary}</span>
545
+ </button>
546
+ {expanded && <div className={styles.trialStepBody}>
547
+ <section className={styles.trialProduce}>
548
+ <h3 className={styles.trialProduceHead}>产出{items.length > 0 ? ` · ${items.length} 条` : ''}</h3>
549
+ {items.length === 0
550
+ ? <p className={styles.trialItemsNone}>{report.model.ok ? '这一步没有产出。' : '模型没有形成有效结果。'}</p>
551
+ : <ul className={styles.trialItems}>{items.slice(0, ITEM_CAP).map((entry, itemIndex) => <li
552
+ key={`${step.id}-${itemIndex}`} className={cn(styles.trialItem, entry.flag === 'warn' && styles.trialItemWarn)}>
553
+ <span className={styles.trialItemRef}>{entry.ref}</span>
554
+ <span className={styles.trialItemArrow} aria-hidden="true">→</span>
555
+ <span className={styles.trialItemValue}>{entry.value}</span>
556
+ {entry.note && <span className={styles.trialItemNote}>{entry.note}</span>}
557
+ </li>)}</ul>}
558
+ {items.length > ITEM_CAP && <p className={styles.trialItemsMore}>另有 {items.length - ITEM_CAP} 条同类产出。</p>}
559
+ </section>
560
+ {step.rows.length > 0 && <dl className={styles.trialRows}>
561
+ {step.rows.map(row => <div className={styles.trialRow} key={`${step.id}-${row.label}`}>
562
+ <dt>{row.label}</dt><dd>{row.value}</dd>
563
+ </div>)}
564
+ </dl>}
565
+ </div>}
566
+ </div>
567
+ </li>
568
+ })}
569
+ </ol>
570
+ </section>
571
+
572
+ <section id="trial-requests" className={styles.trialSection} aria-labelledby="trial-requests-title">
573
+ <div className={styles.trialSectionHead}>
574
+ <h2 id="trial-requests-title">模型请求</h2>
575
+ <span>逐次查看输入、输出和 Token 用量</span>
425
576
  </div>
426
- <pre className={styles.trialPromptText} tabIndex={0} role="region" aria-label="user 提示词">
427
- {report.prompt.user}
428
- </pre>
429
- </div>}
577
+ <ModelRequestDisclosure
578
+ title="Knowledge & Event 抽取"
579
+ status={report.model.response === undefined ? '未收到完整响应' : report.model.ok ? '有有效结果' : '无有效结果'}
580
+ request={report.model.request}
581
+ prompt={report.prompt}
582
+ response={report.model.response ?? report.model.raw}
583
+ responseLabel={report.model.response !== undefined ? '输出' : report.model.raw ? '失败摘录' : '输出'}
584
+ usage={report.model.usage}
585
+ why={report.model.why}
586
+ onCopy={() => void copyPrompt()}
587
+ copied={copied}
588
+ />
589
+ {report.model.axisResolution && <ModelRequestDisclosure
590
+ title="坐标候选补判"
591
+ status={report.model.axisResolution.ok ? '完成' : '未完成'}
592
+ request={report.model.axisResolution.request}
593
+ prompt={report.model.axisResolution.prompt}
594
+ response={report.model.axisResolution.response}
595
+ responseLabel="输出"
596
+ usage={report.model.axisResolution.usage}
597
+ why={report.model.axisResolution.why}
598
+ />}
599
+ </section>
430
600
 
431
- {/* 抽取轨迹。它是**审计**,不是知识模型的一部分(0063 §5.5)—— 所以它排在最后,
432
- 而且标题里就写明它不进模型。*/}
433
- {report.audit.dropped.length > 0 && <>
434
- <button type="button" className={styles.trialToggle} aria-expanded={showAudit}
435
- onClick={() => setShowAudit(value => !value)}>
436
- <ChevronDown size={12} className={cn(styles.trialChevron, showAudit && styles.trialChevronOpen)} />
437
- <FileText size={11} />被丢弃的片段({report.audit.dropped.length} 段)—— 审计,不进知识模型
438
- </button>
439
- {showAudit && <ul className={styles.trialCandidates}>
440
- {report.audit.dropped.map((item, index) => <li key={index}>
441
- <div className={styles.trialCandHead}>
442
- <span className={styles.trialCandName}>{item.quote}</span>
443
- </div>
444
- <div className={styles.trialCandWhy}>{item.why}</div>
601
+ <section id="trial-review" className={styles.trialSection} aria-labelledby="trial-review-title">
602
+ <div className={styles.trialSectionHead}>
603
+ <h2 id="trial-review-title">核验结果</h2>
604
+ <span>{report.exceptions.length > 0 ? `${report.exceptions.length} 项需检查` : '本地核验已完成'}</span>
605
+ </div>
606
+ <ul className={styles.trialCheckList}>
607
+ {report.checks.map(check => <li key={check.name}>
608
+ <div><strong>{check.name}</strong><span>{check.what}</span></div>
609
+ <b data-hit={check.hits > 0}>{check.hits > 0 ? `${check.hits} 项` : '通过'}</b>
610
+ {check.hits > 0 && <small>{check.note}</small>}
445
611
  </li>)}
446
- </ul>}
447
- </>}
448
- </>
612
+ </ul>
613
+ {report.exceptions.length > 0 && <div className={styles.trialReviewIssues}>
614
+ <h3><TriangleAlert size={12} />需人工检查</h3>
615
+ <ul>{report.exceptions.map((item, index) => <li key={`${item.step}-${index}`}>
616
+ <span>{item.step}</span><p>{item.message}</p>
617
+ </li>)}</ul>
618
+ </div>}
619
+ {report.audit.dropped.length > 0 && <InlineDisclosure summary={`被丢弃的片段 · ${report.audit.dropped.length}`}>
620
+ <ul className={styles.trialCandidates}>{report.audit.dropped.map((item, index) => <li key={index}>
621
+ <strong>{item.quote}</strong><span>{item.why}</span>
622
+ </li>)}</ul>
623
+ </InlineDisclosure>}
624
+ </section>
625
+ </div>
449
626
  }