noteconnection 1.7.0 → 1.9.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 (328) hide show
  1. package/LICENSE +674 -21
  2. package/README.md +260 -1626
  3. package/dist/src/agent_workspace.contract.parity.test.js +159 -0
  4. package/dist/src/agent_workspace.frontend.test.js +10388 -0
  5. package/dist/src/agent_workspace.locale.contract.test.js +95 -0
  6. package/dist/src/agent_workspace.runtime.behavior.test.js +5072 -0
  7. package/dist/src/android.knowledgebase.picker.contract.test.js +102 -0
  8. package/dist/src/appimage.patchelf.test.js +113 -0
  9. package/dist/src/appimage.portability.test.js +156 -0
  10. package/dist/src/backend/FileLoader.js +18 -4
  11. package/dist/src/backend/FileLoader.test.js +125 -0
  12. package/dist/src/backend/GraphBuilder.identity.test.js +86 -0
  13. package/dist/src/backend/GraphBuilder.js +66 -18
  14. package/dist/src/backend/GraphBuilder.matching.test.js +127 -0
  15. package/dist/src/backend/GraphMetrics.js +0 -3
  16. package/dist/src/backend/ResourceIdentity.js +155 -0
  17. package/dist/src/backend/ResourceIdentity.test.js +113 -0
  18. package/dist/src/backend/algorithms/CycleDetection.js +0 -1
  19. package/dist/src/backend/algorithms/HybridEngine.js +0 -3
  20. package/dist/src/backend/algorithms/LayoutEngine.js +0 -1
  21. package/dist/src/backend/algorithms/StatisticalAnalyzer.js +0 -4
  22. package/dist/src/backend/algorithms/TopologicalSort.js +0 -2
  23. package/dist/src/backend/build_dag.js +0 -1
  24. package/dist/src/capacitor.bridge.serialization.contract.test.js +3 -0
  25. package/dist/src/capacitor.runtime.contract.test.js +11 -2
  26. package/dist/src/copy.assets.contract.test.js +130 -0
  27. package/dist/src/core/Graph.js +138 -42
  28. package/dist/src/core/Graph.test.js +74 -0
  29. package/dist/src/core/NoteConnection.js +2 -2
  30. package/dist/src/core/PathBridge.js +293 -5
  31. package/dist/src/core/ResourceReference.js +17 -0
  32. package/dist/src/desktop.godot.pack.test.js +142 -0
  33. package/dist/src/desktop.runtime.graph.test.js +66 -0
  34. package/dist/src/export/WorkspaceExportBundle.js +1174 -0
  35. package/dist/src/export/WorkspaceExportBundle.test.js +1541 -0
  36. package/dist/src/export/index.js +18 -0
  37. package/dist/src/export/types.js +2 -0
  38. package/dist/src/fixrisk.issue.verifier.contract.test.js +3 -1
  39. package/dist/src/foundation.ann.runtime.contract.test.js +81 -0
  40. package/dist/src/foundation.release.evidence.contract.test.js +524 -0
  41. package/dist/src/foundation.sqlite.runtime.contract.test.js +88 -0
  42. package/dist/src/frontend/README.md +260 -1626
  43. package/dist/src/frontend/agent_workspace.js +6011 -0
  44. package/dist/src/frontend/agent_workspace_runtime.js +4434 -0
  45. package/dist/src/frontend/analysis.js +31 -4
  46. package/dist/src/frontend/app.js +2178 -62
  47. package/dist/src/frontend/focus_mode_interactions.js +33 -0
  48. package/dist/src/frontend/godot_future_path_renderer.js +540 -0
  49. package/dist/src/frontend/godot_tree_interactions.js +178 -0
  50. package/dist/src/frontend/graph_state.mjs +105 -0
  51. package/dist/src/frontend/hosted_future_path_runtime.js +157 -0
  52. package/dist/src/frontend/i18n.mjs +186 -0
  53. package/dist/src/frontend/index.html +672 -268
  54. package/dist/src/frontend/knowledge_projection_contract.js +230 -0
  55. package/dist/src/frontend/knowledge_projection_store.js +214 -0
  56. package/dist/src/frontend/layout_gpu.js +12 -4
  57. package/dist/src/frontend/libs/path_core.js +158 -42
  58. package/dist/src/frontend/locales/en.json +753 -5
  59. package/dist/src/frontend/locales/zh.json +753 -5
  60. package/dist/src/frontend/main.mjs +60 -0
  61. package/dist/src/frontend/markdown_runtime.js +827 -0
  62. package/dist/src/frontend/mobile_budget_runtime.js +33 -0
  63. package/dist/src/frontend/mobile_exact_analyzer.js +393 -0
  64. package/dist/src/frontend/mobile_identity_contract.js +221 -0
  65. package/dist/src/frontend/mobile_semantic_comparator.js +264 -0
  66. package/dist/src/frontend/notemd.css +49 -0
  67. package/dist/src/frontend/notemd.html +7 -1
  68. package/dist/src/frontend/notemd.js +64 -0
  69. package/dist/src/frontend/path.html +113 -2
  70. package/dist/src/frontend/path_app.js +2108 -130
  71. package/dist/src/frontend/path_layout.mjs +143 -0
  72. package/dist/src/frontend/path_mermaid_utils.mjs +108 -0
  73. package/dist/src/frontend/path_modules_bridge.js +486 -0
  74. package/dist/src/frontend/path_state.mjs +118 -0
  75. package/dist/src/frontend/path_styles.css +146 -0
  76. package/dist/src/frontend/path_worker_bridge.mjs +85 -0
  77. package/dist/src/frontend/reader.js +393 -33
  78. package/dist/src/frontend/runtime_bridge.js +67 -54
  79. package/dist/src/frontend/runtime_bridge.mjs +279 -0
  80. package/dist/src/frontend/settings.js +130 -12
  81. package/dist/src/frontend/simulationWorker.js +1 -1
  82. package/dist/src/frontend/source_manager.js +297 -22
  83. package/dist/src/frontend/storage_provider.js +661 -71
  84. package/dist/src/frontend/styles.css +2814 -72
  85. package/dist/src/frontend/workbench_state.mjs +101 -0
  86. package/dist/src/frontend/workspace_panes.js +10272 -0
  87. package/dist/src/frontend.locale.contract.test.js +62 -0
  88. package/dist/src/frontend.runtime.assets.contract.test.js +81 -0
  89. package/dist/src/godot.sidecar.bootstrap.contract.test.js +244 -0
  90. package/dist/src/graph.answer.operator.contract.test.js +72 -0
  91. package/dist/src/index.js +6 -2
  92. package/dist/src/index.knowledge-root.test.js +118 -0
  93. package/dist/src/indexing/IndexLifecycle.js +217 -0
  94. package/dist/src/indexing/IndexLifecycle.test.js +73 -0
  95. package/dist/src/indexing/SegmentBuilder.js +64 -0
  96. package/dist/src/indexing/UnitBuilder.js +48 -0
  97. package/dist/src/indexing/types.js +2 -0
  98. package/dist/src/knowledge.api.contract.test.js +172 -0
  99. package/dist/src/knowledge_projection.contract.test.js +134 -0
  100. package/dist/src/knowledge_projection_store.test.js +200 -0
  101. package/dist/src/learning/AnswerQualityEvaluation.js +153 -0
  102. package/dist/src/learning/AnswerQualityEvaluation.test.js +118 -0
  103. package/dist/src/learning/KnowledgeLearningPlatform.js +11181 -0
  104. package/dist/src/learning/KnowledgeLearningPlatform.persistence.test.js +745 -0
  105. package/dist/src/learning/KnowledgeLearningPlatform.program-f.test.js +99 -0
  106. package/dist/src/learning/KnowledgeLearningPlatform.test.js +3208 -0
  107. package/dist/src/learning/KnowledgeWorkspaceConversationRegression.js +2998 -0
  108. package/dist/src/learning/KnowledgeWorkspaceConversationRegression.test.js +3936 -0
  109. package/dist/src/learning/MeasurementEvidenceConflicts.test.js +78 -0
  110. package/dist/src/learning/PublicAnswerContract.test.js +85 -0
  111. package/dist/src/learning/PublicEvidenceSelection.test.js +94 -0
  112. package/dist/src/learning/PublicMeasurementDisclosure.test.js +54 -0
  113. package/dist/src/learning/agentConversationExecution.js +211 -0
  114. package/dist/src/learning/agentConversationExecution.test.js +209 -0
  115. package/dist/src/learning/agentConversationSerialization.js +266 -0
  116. package/dist/src/learning/agentConversationSerialization.test.js +165 -0
  117. package/dist/src/learning/agentResponseBudget.js +179 -0
  118. package/dist/src/learning/agentResponseBudget.test.js +97 -0
  119. package/dist/src/learning/agentWorkspaceCapabilityContracts.js +65 -0
  120. package/dist/src/learning/answerReleaseReview.js +5260 -0
  121. package/dist/src/learning/answerReleaseReview.test.js +4174 -0
  122. package/dist/src/learning/answerTaskPlan.js +473 -0
  123. package/dist/src/learning/api.js +2 -0
  124. package/dist/src/learning/conversationComposer.js +1721 -0
  125. package/dist/src/learning/conversationComposer.test.js +3220 -0
  126. package/dist/src/learning/domains/ConversationManager.js +53 -0
  127. package/dist/src/learning/domains/KnowledgeIngestor.js +238 -0
  128. package/dist/src/learning/domains/KnowledgeQuerier.js +187 -0
  129. package/dist/src/learning/domains/MasteryEngine.js +387 -0
  130. package/dist/src/learning/domains/MemoryPolicyManager.js +408 -0
  131. package/dist/src/learning/domains/QualityEvaluator.js +307 -0
  132. package/dist/src/learning/domains/TutorRouter.js +313 -0
  133. package/dist/src/learning/domains/index.js +33 -0
  134. package/dist/src/learning/domains/types.js +7 -0
  135. package/dist/src/learning/errors.js +29 -0
  136. package/dist/src/learning/evidenceContextAssembler.js +1368 -0
  137. package/dist/src/learning/evidenceContextAssembler.test.js +6332 -0
  138. package/dist/src/learning/graphAnswerCoverage.js +37 -0
  139. package/dist/src/learning/graphAnswerCoverage.test.js +93 -0
  140. package/dist/src/learning/graphAnswerCoverageCalibration.js +59 -0
  141. package/dist/src/learning/graphAnswerCoverageCalibration.test.js +46 -0
  142. package/dist/src/learning/graphAnswerFacts.js +94 -0
  143. package/dist/src/learning/graphAnswerFacts.test.js +39 -0
  144. package/dist/src/learning/graphAnswerPlan.js +908 -0
  145. package/dist/src/learning/graphAnswerPlan.test.js +907 -0
  146. package/dist/src/learning/graphAnswerQualityCalibration.js +255 -0
  147. package/dist/src/learning/graphAnswerQualityCalibration.test.js +72 -0
  148. package/dist/src/learning/graphAnswerQualityPolicy.js +30 -0
  149. package/dist/src/learning/graphClaimMatcher.js +104 -0
  150. package/dist/src/learning/graphConditionedContext.js +109 -0
  151. package/dist/src/learning/graphConditionedContext.test.js +99 -0
  152. package/dist/src/learning/graphContextAssembler.js +860 -0
  153. package/dist/src/learning/graphContextAssembler.test.js +1033 -0
  154. package/dist/src/learning/graphExpansionPolicy.js +22 -0
  155. package/dist/src/learning/graphExpansionPolicy.test.js +33 -0
  156. package/dist/src/learning/identityMetadata.test.js +26 -0
  157. package/dist/src/learning/index.js +29 -0
  158. package/dist/src/learning/mobileAnswerProjection.js +104 -0
  159. package/dist/src/learning/mobileAnswerProjection.test.js +102 -0
  160. package/dist/src/learning/queryBackend.js +1922 -0
  161. package/dist/src/learning/queryBackend.test.js +976 -0
  162. package/dist/src/learning/ragContextPack.js +356 -0
  163. package/dist/src/learning/ragContextPack.test.js +311 -0
  164. package/dist/src/learning/ragEvidenceQuality.js +96 -0
  165. package/dist/src/learning/ragEvidenceQuality.test.js +29 -0
  166. package/dist/src/learning/ragPublicText.js +101 -0
  167. package/dist/src/learning/ragPublicText.test.js +57 -0
  168. package/dist/src/learning/ragSufficiencyJudge.js +171 -0
  169. package/dist/src/learning/ragSufficiencyJudge.test.js +177 -0
  170. package/dist/src/learning/ragSufficiencyProviderJudge.js +217 -0
  171. package/dist/src/learning/ragSufficiencyProviderJudge.test.js +207 -0
  172. package/dist/src/learning/requestNormalization.js +304 -0
  173. package/dist/src/learning/requestNormalization.test.js +101 -0
  174. package/dist/src/learning/runtimeCapability.js +4677 -0
  175. package/dist/src/learning/runtimeCapability.test.js +3635 -0
  176. package/dist/src/learning/store.js +1344 -0
  177. package/dist/src/learning/store.test.js +1425 -0
  178. package/dist/src/learning/tutorAdapter.js +2 -0
  179. package/dist/src/learning/types.js +2 -0
  180. package/dist/src/learning/vectorAccelerationAdapter.js +958 -0
  181. package/dist/src/learning/vectorAccelerationAdapter.test.js +412 -0
  182. package/dist/src/learning/workspaceHydration.js +168 -0
  183. package/dist/src/learning/workspaceHydration.test.js +30 -0
  184. package/dist/src/lfs.asset.policy.contract.test.js +153 -0
  185. package/dist/src/license.policy.contract.test.js +71 -0
  186. package/dist/src/markdown/MarkdownGateway.js +4 -0
  187. package/dist/src/markdown/MarkdownGateway.test.js +59 -0
  188. package/dist/src/memory/MemoryGovernance.js +74 -0
  189. package/dist/src/memory/MemoryGovernance.test.js +46 -0
  190. package/dist/src/memory/types.js +2 -0
  191. package/dist/src/mermaid.frontend.guard.contract.test.js +77 -0
  192. package/dist/src/middleware/SseResponseWriter.js +122 -0
  193. package/dist/src/middleware/SseResponseWriter.test.js +54 -0
  194. package/dist/src/middleware/auth.js +38 -0
  195. package/dist/src/middleware/auth.test.js +33 -0
  196. package/dist/src/middleware/body-parser.js +45 -0
  197. package/dist/src/middleware/cors.js +44 -0
  198. package/dist/src/middleware/index.js +22 -0
  199. package/dist/src/middleware/request-trace.js +96 -0
  200. package/dist/src/mobile.android.evidence.contract.test.js +146 -0
  201. package/dist/src/mobile.android.signing.contract.test.js +66 -0
  202. package/dist/src/mobile.artifact.contract.test.js +144 -0
  203. package/dist/src/mobile.budget.contract.test.js +90 -0
  204. package/dist/src/mobile.canonical-id.readiness.test.js +54 -0
  205. package/dist/src/mobile.graph.parity.contract.test.js +207 -0
  206. package/dist/src/mobile.identity.contract.test.js +66 -0
  207. package/dist/src/mobile.identity.corpus.manifest.test.js +72 -0
  208. package/dist/src/mobile.identity.corpus.test.js +40 -0
  209. package/dist/src/mobile.native.recovery.contract.test.js +64 -0
  210. package/dist/src/mobile.pipeline.test.js +11 -1
  211. package/dist/src/mobile.profile.contract.test.js +225 -0
  212. package/dist/src/mobile.semantic.parity.test.js +92 -0
  213. package/dist/src/mobile_exact_analyzer.test.js +113 -0
  214. package/dist/src/notemd/AppConfigToml.js +6 -4
  215. package/dist/src/notemd/ContentGenerator.js +4 -9
  216. package/dist/src/notemd/FileProcessor.js +4 -9
  217. package/dist/src/notemd/MermaidProcessor.js +400 -50
  218. package/dist/src/notemd/NotemdService.js +506 -26
  219. package/dist/src/notemd/PromptManager.js +15 -0
  220. package/dist/src/notemd/Translator.js +4 -9
  221. package/dist/src/notemd/cli/commands.js +357 -0
  222. package/dist/src/notemd/cli/dispatcher.js +225 -0
  223. package/dist/src/notemd/cli/index.js +169 -0
  224. package/dist/src/notemd/cli/parser.js +68 -0
  225. package/dist/src/notemd/cli/types.js +2 -0
  226. package/dist/src/notemd/constants.js +43 -0
  227. package/dist/src/notemd/diagram/diagramGenerationService.js +78 -0
  228. package/dist/src/notemd/diagram/diagramSpec.js +79 -0
  229. package/dist/src/notemd/diagram/diagramSpecResponseParser.js +131 -0
  230. package/dist/src/notemd/diagram/intent.js +95 -0
  231. package/dist/src/notemd/diagram/planner.js +71 -0
  232. package/dist/src/notemd/diagram/prompts/diagramSpecPrompt.js +42 -0
  233. package/dist/src/notemd/diagram/types.js +18 -0
  234. package/dist/src/notemd/index.js +26 -0
  235. package/dist/src/notemd/operations/capabilityManifest.js +23 -0
  236. package/dist/src/notemd/operations/cliContracts.js +17 -0
  237. package/dist/src/notemd/operations/configProfileCommands.js +85 -0
  238. package/dist/src/notemd/operations/registry.contract.test.js +95 -0
  239. package/dist/src/notemd/operations/registry.js +991 -0
  240. package/dist/src/notemd/operations/types.js +2 -0
  241. package/dist/src/notemd/progressReporter.js +9 -0
  242. package/dist/src/notemd/providerDiagnostics.js +220 -0
  243. package/dist/src/notemd/providerProfiles.js +42 -0
  244. package/dist/src/notemd/providerTemplates.js +231 -0
  245. package/dist/src/notemd/search/DuckDuckGoProvider.js +39 -0
  246. package/dist/src/notemd/search/SearchManager.js +13 -0
  247. package/dist/src/notemd/search/SearchProvider.js +2 -0
  248. package/dist/src/notemd/search/TavilyProvider.js +44 -0
  249. package/dist/src/notemd.agent.manifest.test.js +85 -0
  250. package/dist/src/notemd.api.contract.test.js +14 -1
  251. package/dist/src/notemd.app_config_toml.test.js +2 -1
  252. package/dist/src/notemd.batch.workflow.test.js +117 -0
  253. package/dist/src/notemd.cli.e2e.test.js +136 -0
  254. package/dist/src/notemd.core.test.js +51 -0
  255. package/dist/src/notemd.diagram.pipeline.test.js +233 -0
  256. package/dist/src/notemd.providerTemplates.test.js +34 -0
  257. package/dist/src/notemd.server.integration.test.js +262 -39
  258. package/dist/src/notemd.workflow.pipeline.test.js +162 -0
  259. package/dist/src/pathbridge.handshake.contract.test.js +45 -2
  260. package/dist/src/pathbridge.host-adapter.contract.test.js +133 -0
  261. package/dist/src/pathcore.bundle.contract.test.js +8 -0
  262. package/dist/src/pathmode.background.contract.test.js +69 -0
  263. package/dist/src/pathmode.settings.api.contract.test.js +9 -0
  264. package/dist/src/pkg.sidecar.contract.test.js +9 -3
  265. package/dist/src/platform/ExportProfile.js +86 -0
  266. package/dist/src/platform/MobileBudget.js +11 -0
  267. package/dist/src/platform/PlatformCapabilities.js +59 -0
  268. package/dist/src/platform/PlatformCapabilities.test.js +36 -0
  269. package/dist/src/platform/RenderMaterializer.js +33 -0
  270. package/dist/src/platform/RenderMaterializer.test.js +32 -0
  271. package/dist/src/query_backend.external_http.integration.test.js +410 -0
  272. package/dist/src/reader_renderer.js +404 -3
  273. package/dist/src/reader_renderer.test.js +87 -0
  274. package/dist/src/release.godot.mirror.contract.test.js +97 -0
  275. package/dist/src/resources/ResourceRegistry.js +263 -0
  276. package/dist/src/resources/ResourceRegistry.test.js +97 -0
  277. package/dist/src/resources/types.js +2 -0
  278. package/dist/src/routes/agentWorkspaceDiagnostics.js +173 -0
  279. package/dist/src/routes/index.js +19 -0
  280. package/dist/src/routes/knowledge.js +981 -0
  281. package/dist/src/routes/knowledgePayload.js +185 -0
  282. package/dist/src/routes/knowledgePayload.test.js +53 -0
  283. package/dist/src/routes/markdown.js +295 -0
  284. package/dist/src/routes/notemd.js +1321 -0
  285. package/dist/src/routes/registry.contract.test.js +133 -0
  286. package/dist/src/routes/registry.shadow.contract.test.js +22 -0
  287. package/dist/src/routes/render.js +248 -0
  288. package/dist/src/routes/runtimeRunbookRouteOps.js +149 -0
  289. package/dist/src/routes/runtimeRunbookRouteOps.test.js +194 -0
  290. package/dist/src/routes/settings.js +6 -0
  291. package/dist/src/routes/staticFiles.js +94 -0
  292. package/dist/src/routes/types.js +2 -0
  293. package/dist/src/runtime.capabilities.test.js +18 -2
  294. package/dist/src/runtime.transport.adapter.contract.test.js +81 -0
  295. package/dist/src/server.js +10342 -1325
  296. package/dist/src/server.migration.test.js +584 -10
  297. package/dist/src/server.port.fallback.contract.test.js +63 -0
  298. package/dist/src/session/SessionStateStore.js +81 -0
  299. package/dist/src/session/SessionStateStore.test.js +58 -0
  300. package/dist/src/session/types.js +2 -0
  301. package/dist/src/settings.runtime.contract.test.js +50 -0
  302. package/dist/src/shared/types.contract.test.js +107 -0
  303. package/dist/src/shared/types.js +22 -0
  304. package/dist/src/sidecar.build.lock.contract.test.js +201 -0
  305. package/dist/src/sidecar.freshness.contract.test.js +184 -0
  306. package/dist/src/sidecar.replacement.boundary.contract.test.js +131 -0
  307. package/dist/src/sidecar.supply.readiness.contract.test.js +155 -0
  308. package/dist/src/simulation.worker.offline.test.js +104 -0
  309. package/dist/src/source_manager.loadflow.test.js +46 -0
  310. package/dist/src/startup.layout.snapshot.contract.test.js +57 -0
  311. package/dist/src/storage.provider.capacitor.content.contract.test.js +4 -1
  312. package/dist/src/storage.provider.contract.test.js +152 -1
  313. package/dist/src/tauri.frontend.build.contract.test.js +68 -0
  314. package/dist/src/tauri.sidecar.cleanup.contract.test.js +21 -0
  315. package/dist/src/tauri.window.evidence.execution.test.js +68 -0
  316. package/dist/src/utils/RuntimePaths.js +10 -13
  317. package/dist/src/utils/RuntimePaths.test.js +27 -0
  318. package/dist/src/utils/platform.js +153 -0
  319. package/dist/src/windows.installer.build.test.js +109 -0
  320. package/dist/src/windows.installer.payload.test.js +76 -0
  321. package/dist/src/windows.installer.runtime.test.js +69 -0
  322. package/dist/src/workflows/WorkflowArtifactStore.js +96 -0
  323. package/dist/src/workflows/WorkflowArtifactStore.test.js +80 -0
  324. package/dist/src/workflows/types.js +2 -0
  325. package/dist/src/workspace/WorkspaceRegistry.js +135 -0
  326. package/dist/src/workspace/WorkspaceRegistry.test.js +29 -0
  327. package/dist/src/workspace/types.js +2 -0
  328. package/package.json +80 -15
@@ -0,0 +1,981 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.registerKnowledgeRoutes = registerKnowledgeRoutes;
4
+ const CrashLogger_1 = require("../backend/utils/CrashLogger");
5
+ const requestNormalization_1 = require("../learning/requestNormalization");
6
+ const knowledgePayload_1 = require("./knowledgePayload");
7
+ function registerKnowledgeRoutes(ctx) {
8
+ const { knowledgeLearningPlatform, knowledgeIngestor, knowledgeQuerier, LOOPBACK_HOST, finalPort, KNOWLEDGE_GRAPH_STORE_BACKEND, KNOWLEDGE_GRAPHDB_ADAPTER_PROVIDER, KNOWLEDGE_GRAPHDB_ADAPTER_ID, KNOWLEDGE_GRAPHDB_FALLBACK_ENABLED, KNOWLEDGE_GRAPHDB_OPERATION_MODE, runtimeRunbookOps, scheduleKnowledgeLearningPlatformWarmup, } = ctx;
9
+ const api = (path) => `/api/knowledge${path}`;
10
+ const json = (res, code, data) => {
11
+ res.writeHead(code, { 'Content-Type': 'application/json' });
12
+ res.end(JSON.stringify(data));
13
+ };
14
+ const ok = (res, data) => json(res, 200, { success: true, ...data });
15
+ const fail = (res, error, label) => {
16
+ console.error(error);
17
+ CrashLogger_1.CrashLogger.log(error, label);
18
+ if (error instanceof InvalidJsonPayloadError) {
19
+ res.setHeader?.('X-Error-Code', error.code);
20
+ json(res, 400, { error: error.message, errorCode: error.code, success: false });
21
+ return;
22
+ }
23
+ if (error instanceof knowledgePayload_1.KnowledgePayloadError) {
24
+ json(res, error.statusCode, { success: false, error: error.message, code: error.code });
25
+ return;
26
+ }
27
+ json(res, 500, { success: false, error: String(error) });
28
+ };
29
+ class InvalidJsonPayloadError extends Error {
30
+ constructor() {
31
+ super('Invalid JSON body.');
32
+ this.code = 'invalid_json';
33
+ this.name = 'InvalidJsonPayloadError';
34
+ }
35
+ }
36
+ const parseJsonBody = (body) => {
37
+ try {
38
+ return JSON.parse(body);
39
+ }
40
+ catch {
41
+ throw new InvalidJsonPayloadError();
42
+ }
43
+ };
44
+ const readBody = (req) => new Promise((resolve, reject) => {
45
+ const chunks = [];
46
+ let totalBytes = 0;
47
+ req.on('data', (c) => {
48
+ totalBytes += c.length;
49
+ if (totalBytes > 128 * 1024 * 1024) {
50
+ reject(new knowledgePayload_1.KnowledgePayloadError('Request body exceeds 128 MiB.'));
51
+ req.destroy?.();
52
+ return;
53
+ }
54
+ chunks.push(c);
55
+ });
56
+ req.on('end', () => resolve(Buffer.concat(chunks).toString('utf8')));
57
+ req.on('error', reject);
58
+ });
59
+ const parseQuery = (req) => new URL(req.url || '/', `http://${LOOPBACK_HOST}:${finalPort}`).searchParams;
60
+ return [
61
+ // --- GET routes (self-contained, no external normalize functions) ---
62
+ {
63
+ method: 'GET',
64
+ path: api('/state'),
65
+ handler: async (_req, res) => {
66
+ try {
67
+ scheduleKnowledgeLearningPlatformWarmup?.('knowledge_state_request');
68
+ const payload = await knowledgeLearningPlatform.getKnowledgeState();
69
+ ok(res, payload);
70
+ }
71
+ catch (e) {
72
+ fail(res, e, 'GET /api/knowledge/state');
73
+ }
74
+ },
75
+ },
76
+ {
77
+ method: 'GET',
78
+ path: api('/store-diagnostics'),
79
+ handler: async (_req, res) => {
80
+ try {
81
+ const store = await knowledgeLearningPlatform.getStoreDiagnostics();
82
+ ok(res, {
83
+ configuredBackend: KNOWLEDGE_GRAPH_STORE_BACKEND,
84
+ configuredGraphDbAdapterProvider: KNOWLEDGE_GRAPHDB_ADAPTER_PROVIDER,
85
+ configuredGraphDbAdapterId: KNOWLEDGE_GRAPHDB_ADAPTER_ID,
86
+ graphDbFallbackEnabled: KNOWLEDGE_GRAPHDB_FALLBACK_ENABLED,
87
+ configuredGraphDbOperationMode: KNOWLEDGE_GRAPHDB_OPERATION_MODE,
88
+ store,
89
+ });
90
+ }
91
+ catch (e) {
92
+ fail(res, e, 'GET /api/knowledge/store-diagnostics');
93
+ }
94
+ },
95
+ },
96
+ {
97
+ method: 'GET',
98
+ path: api('/tutor/catalog'),
99
+ handler: async (_req, res) => {
100
+ try {
101
+ const catalog = await knowledgeLearningPlatform.getTutorAdapterCatalog();
102
+ ok(res, { catalog });
103
+ }
104
+ catch (e) {
105
+ fail(res, e, 'GET /api/knowledge/tutor/catalog');
106
+ }
107
+ },
108
+ },
109
+ {
110
+ method: 'GET',
111
+ path: api('/tutor/telemetry'),
112
+ handler: async (_req, res) => {
113
+ try {
114
+ const result = await knowledgeLearningPlatform.getTutorAdapterTelemetry();
115
+ ok(res, { result });
116
+ }
117
+ catch (e) {
118
+ fail(res, e, 'GET /api/knowledge/tutor/telemetry');
119
+ }
120
+ },
121
+ },
122
+ {
123
+ method: 'GET',
124
+ path: api('/tutor/trace-diagnostics'),
125
+ handler: async (req, res) => {
126
+ try {
127
+ const params = parseQuery(req);
128
+ const fallbackUsedToken = String(params.get('fallbackUsed') || '').trim().toLowerCase();
129
+ const result = await knowledgeLearningPlatform.queryTutorTraceDiagnostics({
130
+ userId: String(params.get('userId') || '').trim() || undefined,
131
+ source: String(params.get('source') || '').trim() || undefined,
132
+ actionKind: String(params.get('actionKind') || '').trim() || undefined,
133
+ providerName: String(params.get('providerName') || '').trim() || undefined,
134
+ providerMode: String(params.get('providerMode') || '').trim() || undefined,
135
+ fallbackUsed: fallbackUsedToken === 'true'
136
+ ? true
137
+ : fallbackUsedToken === 'false'
138
+ ? false
139
+ : undefined,
140
+ limit: Number(params.get('limit')) || 20,
141
+ });
142
+ ok(res, { result });
143
+ }
144
+ catch (e) {
145
+ fail(res, e, 'GET /api/knowledge/tutor/trace-diagnostics');
146
+ }
147
+ },
148
+ },
149
+ {
150
+ method: 'GET',
151
+ path: api('/query-backend-diagnostics'),
152
+ handler: async (_req, res) => {
153
+ try {
154
+ const diag = await knowledgeLearningPlatform.getQueryBackendDiagnostics();
155
+ ok(res, { queryBackendDiagnostics: diag });
156
+ }
157
+ catch (e) {
158
+ fail(res, e, 'GET /api/knowledge/query-backend-diagnostics');
159
+ }
160
+ },
161
+ },
162
+ {
163
+ method: 'GET',
164
+ path: api('/query/compare-backends/history'),
165
+ handler: async (req, res) => {
166
+ try {
167
+ const params = parseQuery(req);
168
+ const result = await knowledgeLearningPlatform.queryKnowledgeQueryBackendComparisonHistory({
169
+ limit: Number(params.get('limit')) || 8,
170
+ });
171
+ ok(res, { result });
172
+ }
173
+ catch (e) {
174
+ fail(res, e, 'GET /api/knowledge/query/compare-backends/history');
175
+ }
176
+ },
177
+ },
178
+ {
179
+ method: 'GET',
180
+ path: api('/query/compare-backends/trend'),
181
+ handler: async (req, res) => {
182
+ try {
183
+ const params = parseQuery(req);
184
+ const result = await knowledgeLearningPlatform.queryKnowledgeQueryBackendComparisonTrend({
185
+ limit: Number(params.get('limit')) || 12,
186
+ windowSize: Number(params.get('windowSize')) || 2,
187
+ minSamples: Number(params.get('minSamples')) || 1,
188
+ });
189
+ ok(res, { result });
190
+ }
191
+ catch (e) {
192
+ fail(res, e, 'GET /api/knowledge/query/compare-backends/trend');
193
+ }
194
+ },
195
+ },
196
+ {
197
+ method: 'GET',
198
+ path: api('/query-backend-config'),
199
+ handler: async (_req, res) => {
200
+ try {
201
+ const config = knowledgeLearningPlatform.getQueryBackendConfig();
202
+ ok(res, { queryBackendConfig: config });
203
+ }
204
+ catch (e) {
205
+ fail(res, e, 'GET /api/knowledge/query-backend-config');
206
+ }
207
+ },
208
+ },
209
+ {
210
+ method: 'GET',
211
+ path: api('/quality/trend'),
212
+ handler: async (req, res) => {
213
+ try {
214
+ const params = parseQuery(req);
215
+ const result = await knowledgeLearningPlatform.queryLearningQualityTrend({
216
+ userId: String(params.get('userId') || '').trim() || undefined,
217
+ limit: Number(params.get('limit')) || 10,
218
+ windowSize: Number(params.get('windowSize')) || undefined,
219
+ minSamples: Number(params.get('minSamples')) || undefined,
220
+ });
221
+ ok(res, { result });
222
+ }
223
+ catch (e) {
224
+ fail(res, e, 'GET /api/knowledge/quality/trend');
225
+ }
226
+ },
227
+ },
228
+ {
229
+ method: 'GET',
230
+ path: api('/quality/history'),
231
+ handler: async (req, res) => {
232
+ try {
233
+ const params = parseQuery(req);
234
+ const result = await knowledgeLearningPlatform.queryLearningQualityHistory({
235
+ userId: String(params.get('userId') || '').trim() || undefined,
236
+ limit: Number(params.get('limit')) || 20,
237
+ });
238
+ ok(res, { result });
239
+ }
240
+ catch (e) {
241
+ fail(res, e, 'GET /api/knowledge/quality/history');
242
+ }
243
+ },
244
+ },
245
+ {
246
+ method: 'GET',
247
+ path: api('/quality/baseline'),
248
+ handler: async (req, res) => {
249
+ try {
250
+ const params = parseQuery(req);
251
+ const userId = String(params.get('userId') || '').trim();
252
+ const result = await knowledgeLearningPlatform.getLearningQualityBaseline({ userId });
253
+ ok(res, { result });
254
+ }
255
+ catch (e) {
256
+ fail(res, e, 'GET /api/knowledge/quality/baseline');
257
+ }
258
+ },
259
+ },
260
+ {
261
+ method: 'GET',
262
+ path: api('/session/history'),
263
+ handler: async (req, res) => {
264
+ try {
265
+ const params = parseQuery(req);
266
+ const result = await knowledgeLearningPlatform.queryStudySessionHistory({
267
+ userId: String(params.get('userId') || '').trim() || undefined,
268
+ limit: Number(params.get('limit')) || 20,
269
+ sinceMinutes: Number(params.get('sinceMinutes')) || undefined,
270
+ refreshSource: String(params.get('refreshSource') || '').trim() || undefined,
271
+ });
272
+ ok(res, { result });
273
+ }
274
+ catch (e) {
275
+ fail(res, e, 'GET /api/knowledge/session/history');
276
+ }
277
+ },
278
+ },
279
+ {
280
+ method: 'GET',
281
+ path: api('/workflow-artifacts'),
282
+ handler: async (req, res) => {
283
+ try {
284
+ const params = parseQuery(req);
285
+ const artifactKinds = String(params.get('artifactKinds') || '').trim()
286
+ ? String(params.get('artifactKinds') || '')
287
+ .split(',')
288
+ .map((value) => String(value || '').trim())
289
+ .filter(Boolean)
290
+ : undefined;
291
+ const result = await knowledgeLearningPlatform.queryWorkflowArtifacts?.({
292
+ workspaceId: String(params.get('workspaceId') || '').trim() || undefined,
293
+ sessionId: String(params.get('sessionId') || '').trim() || undefined,
294
+ userId: String(params.get('userId') || '').trim() || undefined,
295
+ artifactId: String(params.get('artifactId') || '').trim() || undefined,
296
+ runId: String(params.get('runId') || '').trim() || undefined,
297
+ artifactKinds,
298
+ limit: Number(params.get('limit')) || 12,
299
+ });
300
+ ok(res, { result });
301
+ }
302
+ catch (e) {
303
+ fail(res, e, 'GET /api/knowledge/workflow-artifacts');
304
+ }
305
+ },
306
+ },
307
+ {
308
+ method: 'GET',
309
+ path: api('/session/plan/quality/trend'),
310
+ handler: async (req, res) => {
311
+ try {
312
+ const params = parseQuery(req);
313
+ const result = await knowledgeLearningPlatform.queryStudySessionPlanQualityTrend({
314
+ userId: String(params.get('userId') || '').trim() || undefined,
315
+ limit: Number(params.get('limit')) || 10,
316
+ windowSize: Number(params.get('windowSize')) || undefined,
317
+ minSamples: Number(params.get('minSamples')) || undefined,
318
+ });
319
+ ok(res, { result });
320
+ }
321
+ catch (e) {
322
+ fail(res, e, 'GET /api/knowledge/session/plan/quality/trend');
323
+ }
324
+ },
325
+ },
326
+ {
327
+ method: 'GET',
328
+ path: api('/session/plan/quality/history'),
329
+ handler: async (req, res) => {
330
+ try {
331
+ const params = parseQuery(req);
332
+ const result = await knowledgeLearningPlatform.queryStudySessionPlanQualityHistory({
333
+ userId: String(params.get('userId') || '').trim() || undefined,
334
+ limit: Number(params.get('limit')) || 20,
335
+ });
336
+ ok(res, { result });
337
+ }
338
+ catch (e) {
339
+ fail(res, e, 'GET /api/knowledge/session/plan/quality/history');
340
+ }
341
+ },
342
+ },
343
+ {
344
+ method: 'GET',
345
+ path: api('/memory-policy/diagnostics'),
346
+ handler: async (req, res) => {
347
+ try {
348
+ const params = parseQuery(req);
349
+ const persistRecordToken = String(params.get('persistRecord') || '').trim().toLowerCase();
350
+ const result = await knowledgeLearningPlatform.queryMemoryPolicyDiagnostics({
351
+ limit: Number(params.get('limit')) || undefined,
352
+ sampleLimit: Number(params.get('sampleLimit')) || undefined,
353
+ staleAfterHours: Number(params.get('staleAfterHours')) || undefined,
354
+ nearExpiryHours: Number(params.get('nearExpiryHours')) || undefined,
355
+ lowConfidenceThreshold: Number(params.get('lowConfidenceThreshold')) || undefined,
356
+ now: String(params.get('now') || '').trim() || undefined,
357
+ persistRecord: persistRecordToken === 'false'
358
+ ? false
359
+ : persistRecordToken === 'true'
360
+ ? true
361
+ : undefined,
362
+ });
363
+ ok(res, { result });
364
+ }
365
+ catch (e) {
366
+ fail(res, e, 'GET /api/knowledge/memory-policy/diagnostics');
367
+ }
368
+ },
369
+ },
370
+ {
371
+ method: 'GET',
372
+ path: api('/runtime-capability-matrix'),
373
+ handler: async (_req, res) => {
374
+ try {
375
+ const matrix = await knowledgeLearningPlatform.getRuntimeCapabilityMatrix();
376
+ ok(res, { matrix });
377
+ }
378
+ catch (e) {
379
+ fail(res, e, 'GET /api/knowledge/runtime-capability-matrix');
380
+ }
381
+ },
382
+ },
383
+ {
384
+ method: 'GET',
385
+ path: api('/runtime-capability-runbook'),
386
+ handler: async (req, res) => {
387
+ try {
388
+ const params = parseQuery(req);
389
+ const runbook = runtimeRunbookOps?.getRunbook
390
+ ? await runtimeRunbookOps.getRunbook({
391
+ checkId: String(params.get('checkId') || '').trim(),
392
+ })
393
+ : await knowledgeLearningPlatform.getRuntimeCapabilityRunbook();
394
+ ok(res, { runbook });
395
+ }
396
+ catch (e) {
397
+ fail(res, e, 'GET /api/knowledge/runtime-capability-runbook');
398
+ }
399
+ },
400
+ },
401
+ {
402
+ method: 'GET',
403
+ path: api('/runtime-capability-runbook/verify'),
404
+ handler: async (req, res) => {
405
+ try {
406
+ const params = parseQuery(req);
407
+ const request = {
408
+ checkId: String(params.get('checkId') || '').trim(),
409
+ focus: String(params.get('focus') || '').trim(),
410
+ focusLimit: Number(params.get('focusLimit')) || 12,
411
+ sinceMinutes: Number(params.get('sinceMinutes')) || 1440,
412
+ status: String(params.get('status') || '').trim(),
413
+ checkQuery: String(params.get('checkQuery') || '').trim(),
414
+ limit: Number(params.get('limit')) || 20,
415
+ };
416
+ const result = runtimeRunbookOps?.verify
417
+ ? await runtimeRunbookOps.verify(request)
418
+ : await knowledgeLearningPlatform.verifyRuntimeCapabilityRunbook(request);
419
+ ok(res, { result });
420
+ }
421
+ catch (e) {
422
+ fail(res, e, 'GET /api/knowledge/runtime-capability-runbook/verify');
423
+ }
424
+ },
425
+ },
426
+ {
427
+ method: 'GET',
428
+ path: api('/runtime-capability-runbook/history'),
429
+ handler: async (req, res) => {
430
+ try {
431
+ const params = parseQuery(req);
432
+ const request = {
433
+ limit: Number(params.get('limit')) || 20,
434
+ checkId: String(params.get('checkId') || '').trim(),
435
+ sinceMinutes: Number(params.get('sinceMinutes')) || 10080,
436
+ status: String(params.get('status') || '').trim(),
437
+ };
438
+ const result = runtimeRunbookOps?.getHistory
439
+ ? await runtimeRunbookOps.getHistory(request)
440
+ : await knowledgeLearningPlatform.getRuntimeCapabilityRunbookHistory(request);
441
+ ok(res, { result });
442
+ }
443
+ catch (e) {
444
+ fail(res, e, 'GET /api/knowledge/runtime-capability-runbook/history');
445
+ }
446
+ },
447
+ },
448
+ {
449
+ method: 'GET',
450
+ path: api('/runtime-capability-runbook/history/checks'),
451
+ handler: async (req, res) => {
452
+ try {
453
+ const params = parseQuery(req);
454
+ const request = {
455
+ limit: Number(params.get('limit')) || 8,
456
+ sinceMinutes: Number(params.get('sinceMinutes')) || 10080,
457
+ status: String(params.get('status') || '').trim(),
458
+ checkQuery: String(params.get('checkQuery') || '').trim(),
459
+ };
460
+ const result = runtimeRunbookOps?.getChecks
461
+ ? await runtimeRunbookOps.getChecks(request)
462
+ : await knowledgeLearningPlatform.queryRuntimeCapabilityRunbookChecks(request);
463
+ ok(res, { result });
464
+ }
465
+ catch (e) {
466
+ fail(res, e, 'GET /api/knowledge/runtime-capability-runbook/history/checks');
467
+ }
468
+ },
469
+ },
470
+ {
471
+ method: 'GET',
472
+ path: api('/runtime-capability-runbook/history/action-queue'),
473
+ handler: async (req, res) => {
474
+ try {
475
+ const params = parseQuery(req);
476
+ const request = {
477
+ limit: Number(params.get('limit')) || 8,
478
+ sinceMinutes: Number(params.get('sinceMinutes')) || 10080,
479
+ status: String(params.get('status') || '').trim(),
480
+ checkQuery: String(params.get('checkQuery') || '').trim(),
481
+ queueLimit: Number(params.get('queueLimit')) || 12,
482
+ priority: String(params.get('priority') || '').trim(),
483
+ category: String(params.get('category') || '').trim(),
484
+ checkId: String(params.get('checkId') || '').trim(),
485
+ remediationStatus: String(params.get('remediationStatus') || '').trim(),
486
+ remediationTrend: String(params.get('remediationTrend') || '').trim(),
487
+ };
488
+ const result = runtimeRunbookOps?.getActionQueue
489
+ ? await runtimeRunbookOps.getActionQueue(request)
490
+ : await knowledgeLearningPlatform.queryRuntimeCapabilityRunbookActionQueue(request);
491
+ ok(res, { result });
492
+ }
493
+ catch (e) {
494
+ fail(res, e, 'GET /api/knowledge/runtime-capability-runbook/history/action-queue');
495
+ }
496
+ },
497
+ },
498
+ {
499
+ method: 'GET',
500
+ path: api('/runtime-capability-runbook/remediation-history'),
501
+ handler: async (req, res) => {
502
+ try {
503
+ const params = parseQuery(req);
504
+ const request = {
505
+ limit: Number(params.get('limit')) || 20,
506
+ sinceMinutes: Number(params.get('sinceMinutes')) || 10080,
507
+ status: String(params.get('status') || '').trim(),
508
+ source: String(params.get('source') || '').trim(),
509
+ checkId: String(params.get('checkId') || '').trim(),
510
+ };
511
+ const result = runtimeRunbookOps?.getRemediationHistory
512
+ ? await runtimeRunbookOps.getRemediationHistory(request)
513
+ : await knowledgeLearningPlatform.getRuntimeCapabilityRunbookRemediationHistory(request);
514
+ ok(res, { result });
515
+ }
516
+ catch (e) {
517
+ fail(res, e, 'GET /api/knowledge/runtime-capability-runbook/remediation-history');
518
+ }
519
+ },
520
+ },
521
+ {
522
+ method: 'GET',
523
+ path: api('/runtime-capability-runbook/replay-schedule'),
524
+ handler: async (_req, res) => {
525
+ try {
526
+ const schedule = runtimeRunbookOps?.getReplaySchedule
527
+ ? await runtimeRunbookOps.getReplaySchedule()
528
+ : await knowledgeLearningPlatform.getRuntimeCapabilityRunbookReplaySchedule();
529
+ ok(res, { schedule });
530
+ }
531
+ catch (e) {
532
+ fail(res, e, 'GET /api/knowledge/runtime-capability-runbook/replay-schedule');
533
+ }
534
+ },
535
+ },
536
+ // --- POST routes ---
537
+ {
538
+ method: 'POST',
539
+ path: api('/ingest'),
540
+ handler: async (req, res) => {
541
+ try {
542
+ const body = await readBody(req);
543
+ const result = await knowledgeIngestor.ingestKnowledge((0, knowledgePayload_1.parseKnowledgeIngestBody)(body));
544
+ // Preserve the legacy response shape; diagnostics remain available via runtime metrics.
545
+ ok(res, { result });
546
+ }
547
+ catch (e) {
548
+ fail(res, e, 'POST /api/knowledge/ingest');
549
+ }
550
+ },
551
+ },
552
+ {
553
+ method: 'POST',
554
+ path: api('/query'),
555
+ handler: async (req, res) => {
556
+ try {
557
+ const body = await readBody(req);
558
+ // Keep the migration boundary on the legacy platform facade so
559
+ // registry dispatch preserves the established response contract.
560
+ const result = await knowledgeLearningPlatform.queryKnowledge((0, requestNormalization_1.normalizeKnowledgeQueryRequestPayload)(parseJsonBody(body)));
561
+ ok(res, { result });
562
+ }
563
+ catch (e) {
564
+ fail(res, e, 'POST /api/knowledge/query');
565
+ }
566
+ },
567
+ },
568
+ {
569
+ method: 'POST',
570
+ path: api('/workspace-readiness'),
571
+ handler: async (req, res) => {
572
+ try {
573
+ const body = await readBody(req);
574
+ const payload = JSON.parse(body);
575
+ const result = await knowledgeLearningPlatform.inspectKnowledgeWorkspaceRequest({
576
+ query: String(payload?.query || '').trim(),
577
+ scope: payload?.scope,
578
+ queryBackend: payload?.queryBackend,
579
+ });
580
+ ok(res, { result });
581
+ }
582
+ catch (e) {
583
+ fail(res, e, 'POST /api/knowledge/workspace-readiness');
584
+ }
585
+ },
586
+ },
587
+ {
588
+ method: 'POST',
589
+ path: api('/mastery/diagnostics'),
590
+ handler: async (req, res) => {
591
+ try {
592
+ const body = await readBody(req);
593
+ const result = await knowledgeLearningPlatform.queryMasteryDiagnostics(JSON.parse(body));
594
+ ok(res, { result });
595
+ }
596
+ catch (e) {
597
+ fail(res, e, 'POST /api/knowledge/mastery/diagnostics');
598
+ }
599
+ },
600
+ },
601
+ {
602
+ method: 'POST',
603
+ path: api('/learning-path'),
604
+ handler: async (req, res) => {
605
+ try {
606
+ const body = await readBody(req);
607
+ const result = await knowledgeLearningPlatform.generateLearningPath(JSON.parse(body));
608
+ ok(res, { result });
609
+ }
610
+ catch (e) {
611
+ fail(res, e, 'POST /api/knowledge/learning-path');
612
+ }
613
+ },
614
+ },
615
+ {
616
+ method: 'POST',
617
+ path: api('/session/build'),
618
+ handler: async (req, res) => {
619
+ try {
620
+ const body = await readBody(req);
621
+ const result = await knowledgeLearningPlatform.buildStudySession(JSON.parse(body));
622
+ ok(res, { result });
623
+ }
624
+ catch (e) {
625
+ fail(res, e, 'POST /api/knowledge/session/build');
626
+ }
627
+ },
628
+ },
629
+ {
630
+ method: 'POST',
631
+ path: api('/session/execute'),
632
+ handler: async (req, res) => {
633
+ try {
634
+ const body = await readBody(req);
635
+ const result = await knowledgeLearningPlatform.executeStudySessionPlan(JSON.parse(body));
636
+ ok(res, { result });
637
+ }
638
+ catch (e) {
639
+ fail(res, e, 'POST /api/knowledge/session/execute');
640
+ }
641
+ },
642
+ },
643
+ {
644
+ method: 'POST',
645
+ path: api('/workflow-artifacts/review-follow-up'),
646
+ handler: async (req, res) => {
647
+ try {
648
+ const body = await readBody(req);
649
+ const result = await knowledgeLearningPlatform.executeWorkflowArtifactReviewFollowUp((0, requestNormalization_1.normalizeWorkflowArtifactReviewFollowUpRequestPayload)(JSON.parse(body)));
650
+ ok(res, { result });
651
+ }
652
+ catch (e) {
653
+ fail(res, e, 'POST /api/knowledge/workflow-artifacts/review-follow-up');
654
+ }
655
+ },
656
+ },
657
+ {
658
+ method: 'POST',
659
+ path: api('/session/graph-focus-diagnostics'),
660
+ handler: async (req, res) => {
661
+ try {
662
+ const body = await readBody(req);
663
+ const result = await knowledgeLearningPlatform.recordGraphFocusRenderDiagnostics(JSON.parse(body));
664
+ ok(res, { result });
665
+ }
666
+ catch (e) {
667
+ fail(res, e, 'POST /api/knowledge/session/graph-focus-diagnostics');
668
+ }
669
+ },
670
+ },
671
+ {
672
+ method: 'POST',
673
+ path: api('/export/workspace'),
674
+ handler: async (req, res) => {
675
+ try {
676
+ const body = await readBody(req);
677
+ const result = await knowledgeLearningPlatform.buildWorkspaceExportBundle(JSON.parse(body));
678
+ ok(res, { result });
679
+ }
680
+ catch (e) {
681
+ fail(res, e, 'POST /api/knowledge/export/workspace');
682
+ }
683
+ },
684
+ },
685
+ {
686
+ method: 'POST',
687
+ path: api('/quality/evaluate'),
688
+ handler: async (req, res) => {
689
+ try {
690
+ const body = await readBody(req);
691
+ const result = await knowledgeLearningPlatform.evaluateLearningQuality(JSON.parse(body));
692
+ ok(res, { result });
693
+ }
694
+ catch (e) {
695
+ fail(res, e, 'POST /api/knowledge/quality/evaluate');
696
+ }
697
+ },
698
+ },
699
+ {
700
+ method: 'POST',
701
+ path: api('/quality/snapshot'),
702
+ handler: async (req, res) => {
703
+ try {
704
+ const body = await readBody(req);
705
+ const result = await knowledgeLearningPlatform.captureLearningQualitySnapshot(JSON.parse(body));
706
+ ok(res, { result });
707
+ }
708
+ catch (e) {
709
+ fail(res, e, 'POST /api/knowledge/quality/snapshot');
710
+ }
711
+ },
712
+ },
713
+ {
714
+ method: 'POST',
715
+ path: api('/quality/baseline'),
716
+ handler: async (req, res) => {
717
+ try {
718
+ const body = await readBody(req);
719
+ const result = await knowledgeLearningPlatform.setLearningQualityBaseline(JSON.parse(body));
720
+ ok(res, { result });
721
+ }
722
+ catch (e) {
723
+ fail(res, e, 'POST /api/knowledge/quality/baseline');
724
+ }
725
+ },
726
+ },
727
+ {
728
+ method: 'POST',
729
+ path: api('/quality/baseline/clear'),
730
+ handler: async (req, res) => {
731
+ try {
732
+ const body = await readBody(req);
733
+ const result = await knowledgeLearningPlatform.clearLearningQualityBaseline(JSON.parse(body));
734
+ ok(res, { result });
735
+ }
736
+ catch (e) {
737
+ fail(res, e, 'POST /api/knowledge/quality/baseline/clear');
738
+ }
739
+ },
740
+ },
741
+ {
742
+ method: 'POST',
743
+ path: api('/quality/baseline/evaluate'),
744
+ handler: async (req, res) => {
745
+ try {
746
+ const body = await readBody(req);
747
+ const result = await knowledgeLearningPlatform.evaluateLearningQualityAgainstBaseline(JSON.parse(body));
748
+ ok(res, { result });
749
+ }
750
+ catch (e) {
751
+ fail(res, e, 'POST /api/knowledge/quality/baseline/evaluate');
752
+ }
753
+ },
754
+ },
755
+ {
756
+ method: 'POST',
757
+ path: api('/tutor/action'),
758
+ handler: async (req, res) => {
759
+ try {
760
+ const body = await readBody(req);
761
+ const result = await knowledgeLearningPlatform.executeTutorAction(JSON.parse(body));
762
+ ok(res, { result });
763
+ }
764
+ catch (e) {
765
+ fail(res, e, 'POST /api/knowledge/tutor/action');
766
+ }
767
+ },
768
+ },
769
+ {
770
+ method: 'POST',
771
+ path: api('/memory-policy'),
772
+ handler: async (req, res) => {
773
+ try {
774
+ const body = await readBody(req);
775
+ const result = await knowledgeLearningPlatform.applyMemoryPolicy(JSON.parse(body));
776
+ ok(res, { result });
777
+ }
778
+ catch (e) {
779
+ fail(res, e, 'POST /api/knowledge/memory-policy');
780
+ }
781
+ },
782
+ },
783
+ {
784
+ method: 'POST',
785
+ path: api('/query/compare-backends'),
786
+ handler: async (req, res) => {
787
+ try {
788
+ const body = await readBody(req);
789
+ const result = await knowledgeLearningPlatform.compareQueryBackends(JSON.parse(body));
790
+ ok(res, { result });
791
+ }
792
+ catch (e) {
793
+ fail(res, e, 'POST /api/knowledge/query/compare-backends');
794
+ }
795
+ },
796
+ },
797
+ {
798
+ method: 'POST',
799
+ path: api('/store/reload'),
800
+ handler: async (_req, res) => {
801
+ try {
802
+ await knowledgeLearningPlatform.reloadStore();
803
+ ok(res, { reloaded: true });
804
+ }
805
+ catch (e) {
806
+ fail(res, e, 'POST /api/knowledge/store/reload');
807
+ }
808
+ },
809
+ },
810
+ {
811
+ method: 'POST',
812
+ path: api('/query-backend-config'),
813
+ handler: async (req, res) => {
814
+ try {
815
+ const body = await readBody(req);
816
+ if (ctx.executeQueryBackendConfigUpdate) {
817
+ ok(res, await ctx.executeQueryBackendConfigUpdate(JSON.parse(body)));
818
+ return;
819
+ }
820
+ const result = await knowledgeLearningPlatform.updateQueryBackendConfig(JSON.parse(body));
821
+ ok(res, { result });
822
+ }
823
+ catch (e) {
824
+ fail(res, e, 'POST /api/knowledge/query-backend-config');
825
+ }
826
+ },
827
+ },
828
+ {
829
+ method: 'POST',
830
+ path: api('/ingest/guardrail'),
831
+ handler: async (req, res) => {
832
+ try {
833
+ const body = await readBody(req);
834
+ const result = await knowledgeLearningPlatform.evaluateIngestGuardrail(JSON.parse(body));
835
+ ok(res, { result });
836
+ }
837
+ catch (e) {
838
+ fail(res, e, 'POST /api/knowledge/ingest/guardrail');
839
+ }
840
+ },
841
+ },
842
+ {
843
+ method: 'POST',
844
+ path: api('/runtime-capability-runbook/remediation-event'),
845
+ handler: async (req, res) => {
846
+ try {
847
+ const body = await readBody(req);
848
+ const payload = JSON.parse(body);
849
+ const result = runtimeRunbookOps?.recordRemediationEvent
850
+ ? await runtimeRunbookOps.recordRemediationEvent(payload, String(req.requestId || req.headers['x-request-id'] || ''))
851
+ : await knowledgeLearningPlatform.recordRuntimeCapabilityRemediationEvent(payload);
852
+ ok(res, { result });
853
+ }
854
+ catch (e) {
855
+ fail(res, e, 'POST /api/knowledge/runtime-capability-runbook/remediation-event');
856
+ }
857
+ },
858
+ },
859
+ {
860
+ method: 'POST',
861
+ path: api('/runtime-capability-runbook/remediation-event/replay'),
862
+ handler: async (req, res) => {
863
+ try {
864
+ const body = await readBody(req);
865
+ const payload = JSON.parse(body);
866
+ const result = runtimeRunbookOps?.replayRemediationEvent
867
+ ? await runtimeRunbookOps.replayRemediationEvent(payload)
868
+ : await knowledgeLearningPlatform.replayRuntimeCapabilityRemediationEvent(payload);
869
+ ok(res, { result });
870
+ }
871
+ catch (e) {
872
+ fail(res, e, 'POST /api/knowledge/runtime-capability-runbook/remediation-event/replay');
873
+ }
874
+ },
875
+ },
876
+ {
877
+ method: 'POST',
878
+ path: api('/runtime-capability-runbook/replay-schedule'),
879
+ handler: async (req, res) => {
880
+ try {
881
+ const body = await readBody(req);
882
+ const payload = JSON.parse(body);
883
+ const result = runtimeRunbookOps?.updateReplaySchedule
884
+ ? await runtimeRunbookOps.updateReplaySchedule(payload)
885
+ : await knowledgeLearningPlatform.updateRuntimeCapabilityReplaySchedule(payload);
886
+ ok(res, { result });
887
+ }
888
+ catch (e) {
889
+ fail(res, e, 'POST /api/knowledge/runtime-capability-runbook/replay-schedule');
890
+ }
891
+ },
892
+ },
893
+ {
894
+ method: 'POST',
895
+ path: api('/runtime-capability-runbook/replay-schedule/tick'),
896
+ handler: async (req, res) => {
897
+ try {
898
+ const body = await readBody(req);
899
+ const payload = body.trim() ? JSON.parse(body) : {};
900
+ const result = runtimeRunbookOps?.tickReplaySchedule
901
+ ? await runtimeRunbookOps.tickReplaySchedule(payload)
902
+ : await knowledgeLearningPlatform.tickRuntimeCapabilityReplaySchedule();
903
+ ok(res, { result });
904
+ }
905
+ catch (e) {
906
+ fail(res, e, 'POST /api/knowledge/runtime-capability-runbook/replay-schedule/tick');
907
+ }
908
+ },
909
+ },
910
+ {
911
+ method: 'POST',
912
+ path: api('/session/orchestration/config'),
913
+ handler: async (req, res) => {
914
+ try {
915
+ const body = await readBody(req);
916
+ const result = await knowledgeLearningPlatform.updateStudySessionOrchestrationConfig(JSON.parse(body));
917
+ ok(res, { result });
918
+ }
919
+ catch (e) {
920
+ fail(res, e, 'POST /api/knowledge/session/orchestration/config');
921
+ }
922
+ },
923
+ },
924
+ {
925
+ method: 'POST',
926
+ path: api('/conversation-memory/add'),
927
+ handler: async (req, res) => {
928
+ try {
929
+ const body = await readBody(req);
930
+ const result = await knowledgeLearningPlatform.addConversationMemory(JSON.parse(body));
931
+ ok(res, { result });
932
+ }
933
+ catch (e) {
934
+ fail(res, e, 'POST /api/knowledge/conversation-memory/add');
935
+ }
936
+ },
937
+ },
938
+ {
939
+ method: 'POST',
940
+ path: api('/conversation-memory/search'),
941
+ handler: async (req, res) => {
942
+ try {
943
+ const body = await readBody(req);
944
+ const result = await knowledgeLearningPlatform.searchConversationMemory(JSON.parse(body));
945
+ ok(res, { result });
946
+ }
947
+ catch (e) {
948
+ fail(res, e, 'POST /api/knowledge/conversation-memory/search');
949
+ }
950
+ },
951
+ },
952
+ {
953
+ method: 'POST',
954
+ path: api('/conversation-memory/delete'),
955
+ handler: async (req, res) => {
956
+ try {
957
+ const body = await readBody(req);
958
+ const result = await knowledgeLearningPlatform.deleteConversationMemory(JSON.parse(body));
959
+ ok(res, { result });
960
+ }
961
+ catch (e) {
962
+ fail(res, e, 'POST /api/knowledge/conversation-memory/delete');
963
+ }
964
+ },
965
+ },
966
+ {
967
+ method: 'POST',
968
+ path: api('/conversation-memory/feedback'),
969
+ handler: async (req, res) => {
970
+ try {
971
+ const body = await readBody(req);
972
+ const result = await knowledgeLearningPlatform.feedbackConversationMemory(JSON.parse(body));
973
+ ok(res, { result });
974
+ }
975
+ catch (e) {
976
+ fail(res, e, 'POST /api/knowledge/conversation-memory/feedback');
977
+ }
978
+ },
979
+ },
980
+ ];
981
+ }