@oscharko-dev/keiko-server 0.2.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 (509) hide show
  1. package/dist/.tsbuildinfo +1 -0
  2. package/dist/assistant-response.d.ts +6 -0
  3. package/dist/assistant-response.d.ts.map +1 -0
  4. package/dist/assistant-response.js +12 -0
  5. package/dist/browser.d.ts +11 -0
  6. package/dist/browser.d.ts.map +1 -0
  7. package/dist/browser.js +245 -0
  8. package/dist/chat-handlers.d.ts +48 -0
  9. package/dist/chat-handlers.d.ts.map +1 -0
  10. package/dist/chat-handlers.js +821 -0
  11. package/dist/chat-stream-handlers.d.ts +4 -0
  12. package/dist/chat-stream-handlers.d.ts.map +1 -0
  13. package/dist/chat-stream-handlers.js +136 -0
  14. package/dist/conversation-prompt.d.ts +8 -0
  15. package/dist/conversation-prompt.d.ts.map +1 -0
  16. package/dist/conversation-prompt.js +36 -0
  17. package/dist/conversation-validation.d.ts +26 -0
  18. package/dist/conversation-validation.d.ts.map +1 -0
  19. package/dist/conversation-validation.js +125 -0
  20. package/dist/credentialPersistence.d.ts +23 -0
  21. package/dist/credentialPersistence.d.ts.map +1 -0
  22. package/dist/credentialPersistence.js +93 -0
  23. package/dist/credentialVault.d.ts +30 -0
  24. package/dist/credentialVault.d.ts.map +1 -0
  25. package/dist/credentialVault.js +206 -0
  26. package/dist/csp.d.ts +3 -0
  27. package/dist/csp.d.ts.map +1 -0
  28. package/dist/csp.js +75 -0
  29. package/dist/deps.d.ts +78 -0
  30. package/dist/deps.d.ts.map +1 -0
  31. package/dist/deps.js +457 -0
  32. package/dist/editor/agentRoutes.d.ts +7 -0
  33. package/dist/editor/agentRoutes.d.ts.map +1 -0
  34. package/dist/editor/agentRoutes.js +197 -0
  35. package/dist/editor/assuredGateRunner.d.ts +36 -0
  36. package/dist/editor/assuredGateRunner.d.ts.map +1 -0
  37. package/dist/editor/assuredGateRunner.js +100 -0
  38. package/dist/editor/assuredPreFilter.d.ts +34 -0
  39. package/dist/editor/assuredPreFilter.d.ts.map +1 -0
  40. package/dist/editor/assuredPreFilter.js +134 -0
  41. package/dist/editor/assuredPreFilterRunner.d.ts +31 -0
  42. package/dist/editor/assuredPreFilterRunner.d.ts.map +1 -0
  43. package/dist/editor/assuredPreFilterRunner.js +312 -0
  44. package/dist/editor/builtinLanguageProviders.d.ts +6 -0
  45. package/dist/editor/builtinLanguageProviders.d.ts.map +1 -0
  46. package/dist/editor/builtinLanguageProviders.js +221 -0
  47. package/dist/editor/codingContext.d.ts +12 -0
  48. package/dist/editor/codingContext.d.ts.map +1 -0
  49. package/dist/editor/codingContext.js +121 -0
  50. package/dist/editor/codingContextEvidence.d.ts +7 -0
  51. package/dist/editor/codingContextEvidence.d.ts.map +1 -0
  52. package/dist/editor/codingContextEvidence.js +52 -0
  53. package/dist/editor/codingContextProviders.d.ts +36 -0
  54. package/dist/editor/codingContextProviders.d.ts.map +1 -0
  55. package/dist/editor/codingContextProviders.js +348 -0
  56. package/dist/editor/completionModelEvidence.d.ts +16 -0
  57. package/dist/editor/completionModelEvidence.d.ts.map +1 -0
  58. package/dist/editor/completionModelEvidence.js +50 -0
  59. package/dist/editor/completionRoutes.d.ts +37 -0
  60. package/dist/editor/completionRoutes.d.ts.map +1 -0
  61. package/dist/editor/completionRoutes.js +411 -0
  62. package/dist/editor/contextRoutes.d.ts +6 -0
  63. package/dist/editor/contextRoutes.d.ts.map +1 -0
  64. package/dist/editor/contextRoutes.js +411 -0
  65. package/dist/editor/disposableAssuredExecution.d.ts +22 -0
  66. package/dist/editor/disposableAssuredExecution.d.ts.map +1 -0
  67. package/dist/editor/disposableAssuredExecution.js +57 -0
  68. package/dist/editor/editorCompletionModel.d.ts +47 -0
  69. package/dist/editor/editorCompletionModel.d.ts.map +1 -0
  70. package/dist/editor/editorCompletionModel.js +156 -0
  71. package/dist/editor/editorInlineCompletionModel.d.ts +34 -0
  72. package/dist/editor/editorInlineCompletionModel.d.ts.map +1 -0
  73. package/dist/editor/editorInlineCompletionModel.js +112 -0
  74. package/dist/editor/editorModelTokenBudget.d.ts +46 -0
  75. package/dist/editor/editorModelTokenBudget.d.ts.map +1 -0
  76. package/dist/editor/editorModelTokenBudget.js +121 -0
  77. package/dist/editor/inlineCompletionRateLimiter.d.ts +19 -0
  78. package/dist/editor/inlineCompletionRateLimiter.d.ts.map +1 -0
  79. package/dist/editor/inlineCompletionRateLimiter.js +46 -0
  80. package/dist/editor/inlineCompletionRoutes.d.ts +26 -0
  81. package/dist/editor/inlineCompletionRoutes.d.ts.map +1 -0
  82. package/dist/editor/inlineCompletionRoutes.js +404 -0
  83. package/dist/editor/inlineCompletionTelemetryEvidence.d.ts +5 -0
  84. package/dist/editor/inlineCompletionTelemetryEvidence.d.ts.map +1 -0
  85. package/dist/editor/inlineCompletionTelemetryEvidence.js +42 -0
  86. package/dist/editor/languageCancellation.d.ts +19 -0
  87. package/dist/editor/languageCancellation.d.ts.map +1 -0
  88. package/dist/editor/languageCancellation.js +48 -0
  89. package/dist/editor/languageProvider.d.ts +39 -0
  90. package/dist/editor/languageProvider.d.ts.map +1 -0
  91. package/dist/editor/languageProvider.js +11 -0
  92. package/dist/editor/languageRoutes.d.ts +15 -0
  93. package/dist/editor/languageRoutes.d.ts.map +1 -0
  94. package/dist/editor/languageRoutes.js +106 -0
  95. package/dist/editor/languageSanitize.d.ts +8 -0
  96. package/dist/editor/languageSanitize.d.ts.map +1 -0
  97. package/dist/editor/languageSanitize.js +101 -0
  98. package/dist/editor/languageService.d.ts +36 -0
  99. package/dist/editor/languageService.d.ts.map +1 -0
  100. package/dist/editor/languageService.js +93 -0
  101. package/dist/editor/languageServiceHost.d.ts +14 -0
  102. package/dist/editor/languageServiceHost.d.ts.map +1 -0
  103. package/dist/editor/languageServiceHost.js +242 -0
  104. package/dist/editor/localKnowledgeRetrieval.d.ts +21 -0
  105. package/dist/editor/localKnowledgeRetrieval.d.ts.map +1 -0
  106. package/dist/editor/localKnowledgeRetrieval.js +44 -0
  107. package/dist/editor/patchApplyEvidence.d.ts +21 -0
  108. package/dist/editor/patchApplyEvidence.d.ts.map +1 -0
  109. package/dist/editor/patchApplyEvidence.js +87 -0
  110. package/dist/editor/patchApplyRoutes.d.ts +16 -0
  111. package/dist/editor/patchApplyRoutes.d.ts.map +1 -0
  112. package/dist/editor/patchApplyRoutes.js +307 -0
  113. package/dist/editor/postApplyVerification.d.ts +42 -0
  114. package/dist/editor/postApplyVerification.d.ts.map +1 -0
  115. package/dist/editor/postApplyVerification.js +177 -0
  116. package/dist/editor/testGenerationEvidence.d.ts +6 -0
  117. package/dist/editor/testGenerationEvidence.d.ts.map +1 -0
  118. package/dist/editor/testGenerationEvidence.js +72 -0
  119. package/dist/editor/testGenerationPatch.d.ts +10 -0
  120. package/dist/editor/testGenerationPatch.d.ts.map +1 -0
  121. package/dist/editor/testGenerationPatch.js +66 -0
  122. package/dist/editor/testGenerationRoutes.d.ts +21 -0
  123. package/dist/editor/testGenerationRoutes.d.ts.map +1 -0
  124. package/dist/editor/testGenerationRoutes.js +254 -0
  125. package/dist/editor/testGenerationRunner.d.ts +23 -0
  126. package/dist/editor/testGenerationRunner.d.ts.map +1 -0
  127. package/dist/editor/testGenerationRunner.js +120 -0
  128. package/dist/editor/textOffsets.d.ts +6 -0
  129. package/dist/editor/textOffsets.d.ts.map +1 -0
  130. package/dist/editor/textOffsets.js +82 -0
  131. package/dist/editor/typescriptLanguageProvider.d.ts +3 -0
  132. package/dist/editor/typescriptLanguageProvider.d.ts.map +1 -0
  133. package/dist/editor/typescriptLanguageProvider.js +217 -0
  134. package/dist/evidence.d.ts +28 -0
  135. package/dist/evidence.d.ts.map +1 -0
  136. package/dist/evidence.js +145 -0
  137. package/dist/files-deny.d.ts +3 -0
  138. package/dist/files-deny.d.ts.map +1 -0
  139. package/dist/files-deny.js +12 -0
  140. package/dist/files.d.ts +97 -0
  141. package/dist/files.d.ts.map +1 -0
  142. package/dist/files.js +733 -0
  143. package/dist/gateway-setup.d.ts +10 -0
  144. package/dist/gateway-setup.d.ts.map +1 -0
  145. package/dist/gateway-setup.js +896 -0
  146. package/dist/governed-workflow.d.ts +17 -0
  147. package/dist/governed-workflow.d.ts.map +1 -0
  148. package/dist/governed-workflow.js +147 -0
  149. package/dist/grounded-answer.d.ts +12 -0
  150. package/dist/grounded-answer.d.ts.map +1 -0
  151. package/dist/grounded-answer.js +69 -0
  152. package/dist/grounded-context-index.d.ts +25 -0
  153. package/dist/grounded-context-index.d.ts.map +1 -0
  154. package/dist/grounded-context-index.js +169 -0
  155. package/dist/grounded-document-evidence.d.ts +28 -0
  156. package/dist/grounded-document-evidence.d.ts.map +1 -0
  157. package/dist/grounded-document-evidence.js +430 -0
  158. package/dist/grounded-handoff.d.ts +4 -0
  159. package/dist/grounded-handoff.d.ts.map +1 -0
  160. package/dist/grounded-handoff.js +445 -0
  161. package/dist/grounded-orchestrator.d.ts +43 -0
  162. package/dist/grounded-orchestrator.d.ts.map +1 -0
  163. package/dist/grounded-orchestrator.js +1445 -0
  164. package/dist/grounded-prompt.d.ts +2 -0
  165. package/dist/grounded-prompt.d.ts.map +1 -0
  166. package/dist/grounded-prompt.js +17 -0
  167. package/dist/grounded-qa-hybrid.d.ts +36 -0
  168. package/dist/grounded-qa-hybrid.d.ts.map +1 -0
  169. package/dist/grounded-qa-hybrid.js +762 -0
  170. package/dist/grounded-qa-multi-source.d.ts +38 -0
  171. package/dist/grounded-qa-multi-source.d.ts.map +1 -0
  172. package/dist/grounded-qa-multi-source.js +461 -0
  173. package/dist/grounded-qa.d.ts +45 -0
  174. package/dist/grounded-qa.d.ts.map +1 -0
  175. package/dist/grounded-qa.js +877 -0
  176. package/dist/grounded-rerank.d.ts +26 -0
  177. package/dist/grounded-rerank.d.ts.map +1 -0
  178. package/dist/grounded-rerank.js +72 -0
  179. package/dist/grounded-turn-registry.d.ts +23 -0
  180. package/dist/grounded-turn-registry.d.ts.map +1 -0
  181. package/dist/grounded-turn-registry.js +102 -0
  182. package/dist/headers.d.ts +3 -0
  183. package/dist/headers.d.ts.map +1 -0
  184. package/dist/headers.js +22 -0
  185. package/dist/host-check.d.ts +3 -0
  186. package/dist/host-check.d.ts.map +1 -0
  187. package/dist/host-check.js +58 -0
  188. package/dist/index.d.ts +26 -0
  189. package/dist/index.d.ts.map +1 -0
  190. package/dist/index.js +33 -0
  191. package/dist/load-csp.d.ts +3 -0
  192. package/dist/load-csp.d.ts.map +1 -0
  193. package/dist/load-csp.js +100 -0
  194. package/dist/local-knowledge-grounded-qa.d.ts +42 -0
  195. package/dist/local-knowledge-grounded-qa.d.ts.map +1 -0
  196. package/dist/local-knowledge-grounded-qa.js +678 -0
  197. package/dist/local-knowledge-handlers.d.ts +24 -0
  198. package/dist/local-knowledge-handlers.d.ts.map +1 -0
  199. package/dist/local-knowledge-handlers.js +1285 -0
  200. package/dist/local-knowledge-indexing-registry.d.ts +13 -0
  201. package/dist/local-knowledge-indexing-registry.d.ts.map +1 -0
  202. package/dist/local-knowledge-indexing-registry.js +53 -0
  203. package/dist/localKnowledgeKeyProvider.d.ts +11 -0
  204. package/dist/localKnowledgeKeyProvider.d.ts.map +1 -0
  205. package/dist/localKnowledgeKeyProvider.js +48 -0
  206. package/dist/memory-audit-event-builders.d.ts +21 -0
  207. package/dist/memory-audit-event-builders.d.ts.map +1 -0
  208. package/dist/memory-audit-event-builders.js +187 -0
  209. package/dist/memory-audit-handler.d.ts +23 -0
  210. package/dist/memory-audit-handler.d.ts.map +1 -0
  211. package/dist/memory-audit-handler.js +191 -0
  212. package/dist/memory-capture-policy.d.ts +10 -0
  213. package/dist/memory-capture-policy.d.ts.map +1 -0
  214. package/dist/memory-capture-policy.js +44 -0
  215. package/dist/memory-consolidation-handlers.d.ts +6 -0
  216. package/dist/memory-consolidation-handlers.d.ts.map +1 -0
  217. package/dist/memory-consolidation-handlers.js +491 -0
  218. package/dist/memory-consolidation-registry.d.ts +47 -0
  219. package/dist/memory-consolidation-registry.d.ts.map +1 -0
  220. package/dist/memory-consolidation-registry.js +106 -0
  221. package/dist/memory-conv-handlers.d.ts +8 -0
  222. package/dist/memory-conv-handlers.d.ts.map +1 -0
  223. package/dist/memory-conv-handlers.js +369 -0
  224. package/dist/memory-conversation-context.d.ts +13 -0
  225. package/dist/memory-conversation-context.d.ts.map +1 -0
  226. package/dist/memory-conversation-context.js +22 -0
  227. package/dist/memory-diagnostics.d.ts +29 -0
  228. package/dist/memory-diagnostics.d.ts.map +1 -0
  229. package/dist/memory-diagnostics.js +122 -0
  230. package/dist/memory-embedding.d.ts +21 -0
  231. package/dist/memory-embedding.d.ts.map +1 -0
  232. package/dist/memory-embedding.js +264 -0
  233. package/dist/memory-handlers.d.ts +19 -0
  234. package/dist/memory-handlers.d.ts.map +1 -0
  235. package/dist/memory-handlers.js +1204 -0
  236. package/dist/memory-maintenance-handlers.d.ts +35 -0
  237. package/dist/memory-maintenance-handlers.d.ts.map +1 -0
  238. package/dist/memory-maintenance-handlers.js +219 -0
  239. package/dist/memory-record-builders.d.ts +4 -0
  240. package/dist/memory-record-builders.d.ts.map +1 -0
  241. package/dist/memory-record-builders.js +19 -0
  242. package/dist/memory-retention.d.ts +31 -0
  243. package/dist/memory-retention.d.ts.map +1 -0
  244. package/dist/memory-retention.js +151 -0
  245. package/dist/memory-retrieval-signals.d.ts +12 -0
  246. package/dist/memory-retrieval-signals.d.ts.map +1 -0
  247. package/dist/memory-retrieval-signals.js +100 -0
  248. package/dist/memory-salience.d.ts +12 -0
  249. package/dist/memory-salience.d.ts.map +1 -0
  250. package/dist/memory-salience.js +154 -0
  251. package/dist/memory-scope-sanitizer.d.ts +6 -0
  252. package/dist/memory-scope-sanitizer.d.ts.map +1 -0
  253. package/dist/memory-scope-sanitizer.js +106 -0
  254. package/dist/memory-target-resolver.d.ts +4 -0
  255. package/dist/memory-target-resolver.d.ts.map +1 -0
  256. package/dist/memory-target-resolver.js +73 -0
  257. package/dist/memory-workflow-port.d.ts +14 -0
  258. package/dist/memory-workflow-port.d.ts.map +1 -0
  259. package/dist/memory-workflow-port.js +186 -0
  260. package/dist/private-json.d.ts +3 -0
  261. package/dist/private-json.d.ts.map +1 -0
  262. package/dist/private-json.js +62 -0
  263. package/dist/promptEnhancer/index.d.ts +3 -0
  264. package/dist/promptEnhancer/index.d.ts.map +1 -0
  265. package/dist/promptEnhancer/index.js +5 -0
  266. package/dist/promptEnhancer/orchestrate.d.ts +2 -0
  267. package/dist/promptEnhancer/orchestrate.d.ts.map +1 -0
  268. package/dist/promptEnhancer/orchestrate.js +5 -0
  269. package/dist/promptEnhancer/routes.d.ts +9 -0
  270. package/dist/promptEnhancer/routes.d.ts.map +1 -0
  271. package/dist/promptEnhancer/routes.js +205 -0
  272. package/dist/qualityIntelligence/capsuleAdapter.d.ts +27 -0
  273. package/dist/qualityIntelligence/capsuleAdapter.d.ts.map +1 -0
  274. package/dist/qualityIntelligence/capsuleAdapter.js +57 -0
  275. package/dist/qualityIntelligence/connectorAuthorization.d.ts +22 -0
  276. package/dist/qualityIntelligence/connectorAuthorization.d.ts.map +1 -0
  277. package/dist/qualityIntelligence/connectorAuthorization.js +35 -0
  278. package/dist/qualityIntelligence/connectorErrors.d.ts +16 -0
  279. package/dist/qualityIntelligence/connectorErrors.d.ts.map +1 -0
  280. package/dist/qualityIntelligence/connectorErrors.js +56 -0
  281. package/dist/qualityIntelligence/connectorRoutes.d.ts +7 -0
  282. package/dist/qualityIntelligence/connectorRoutes.d.ts.map +1 -0
  283. package/dist/qualityIntelligence/connectorRoutes.js +167 -0
  284. package/dist/qualityIntelligence/editRoutes.d.ts +5 -0
  285. package/dist/qualityIntelligence/editRoutes.d.ts.map +1 -0
  286. package/dist/qualityIntelligence/editRoutes.js +293 -0
  287. package/dist/qualityIntelligence/exportAssembly.d.ts +22 -0
  288. package/dist/qualityIntelligence/exportAssembly.d.ts.map +1 -0
  289. package/dist/qualityIntelligence/exportAssembly.js +352 -0
  290. package/dist/qualityIntelligence/exportRoutes.d.ts +5 -0
  291. package/dist/qualityIntelligence/exportRoutes.d.ts.map +1 -0
  292. package/dist/qualityIntelligence/exportRoutes.js +320 -0
  293. package/dist/qualityIntelligence/figma/figmaConcurrency.d.ts +8 -0
  294. package/dist/qualityIntelligence/figma/figmaConcurrency.d.ts.map +1 -0
  295. package/dist/qualityIntelligence/figma/figmaConcurrency.js +34 -0
  296. package/dist/qualityIntelligence/figma/figmaConnector.d.ts +65 -0
  297. package/dist/qualityIntelligence/figma/figmaConnector.d.ts.map +1 -0
  298. package/dist/qualityIntelligence/figma/figmaConnector.js +184 -0
  299. package/dist/qualityIntelligence/figma/figmaConnectorAudit.d.ts +52 -0
  300. package/dist/qualityIntelligence/figma/figmaConnectorAudit.d.ts.map +1 -0
  301. package/dist/qualityIntelligence/figma/figmaConnectorAudit.js +63 -0
  302. package/dist/qualityIntelligence/figma/figmaConnectorErrors.d.ts +31 -0
  303. package/dist/qualityIntelligence/figma/figmaConnectorErrors.d.ts.map +1 -0
  304. package/dist/qualityIntelligence/figma/figmaConnectorErrors.js +220 -0
  305. package/dist/qualityIntelligence/figma/figmaConnectorMetrics.d.ts +44 -0
  306. package/dist/qualityIntelligence/figma/figmaConnectorMetrics.d.ts.map +1 -0
  307. package/dist/qualityIntelligence/figma/figmaConnectorMetrics.js +49 -0
  308. package/dist/qualityIntelligence/figma/figmaConsent.d.ts +39 -0
  309. package/dist/qualityIntelligence/figma/figmaConsent.d.ts.map +1 -0
  310. package/dist/qualityIntelligence/figma/figmaConsent.js +62 -0
  311. package/dist/qualityIntelligence/figma/figmaHttpPort.d.ts +28 -0
  312. package/dist/qualityIntelligence/figma/figmaHttpPort.d.ts.map +1 -0
  313. package/dist/qualityIntelligence/figma/figmaHttpPort.js +70 -0
  314. package/dist/qualityIntelligence/figma/figmaObservedActions.d.ts +49 -0
  315. package/dist/qualityIntelligence/figma/figmaObservedActions.d.ts.map +1 -0
  316. package/dist/qualityIntelligence/figma/figmaObservedActions.js +89 -0
  317. package/dist/qualityIntelligence/figma/figmaReadiness.d.ts +32 -0
  318. package/dist/qualityIntelligence/figma/figmaReadiness.d.ts.map +1 -0
  319. package/dist/qualityIntelligence/figma/figmaReadiness.js +67 -0
  320. package/dist/qualityIntelligence/figma/figmaRenderPort.d.ts +29 -0
  321. package/dist/qualityIntelligence/figma/figmaRenderPort.d.ts.map +1 -0
  322. package/dist/qualityIntelligence/figma/figmaRenderPort.js +93 -0
  323. package/dist/qualityIntelligence/figma/figmaResnapshot.d.ts +28 -0
  324. package/dist/qualityIntelligence/figma/figmaResnapshot.d.ts.map +1 -0
  325. package/dist/qualityIntelligence/figma/figmaResnapshot.js +38 -0
  326. package/dist/qualityIntelligence/figma/figmaRetry.d.ts +31 -0
  327. package/dist/qualityIntelligence/figma/figmaRetry.d.ts.map +1 -0
  328. package/dist/qualityIntelligence/figma/figmaRetry.js +62 -0
  329. package/dist/qualityIntelligence/figma/figmaScopeRef.d.ts +9 -0
  330. package/dist/qualityIntelligence/figma/figmaScopeRef.d.ts.map +1 -0
  331. package/dist/qualityIntelligence/figma/figmaScopeRef.js +18 -0
  332. package/dist/qualityIntelligence/figma/figmaScopedPagination.d.ts +86 -0
  333. package/dist/qualityIntelligence/figma/figmaScopedPagination.d.ts.map +1 -0
  334. package/dist/qualityIntelligence/figma/figmaScopedPagination.js +308 -0
  335. package/dist/qualityIntelligence/figma/figmaSnapshotBuilder.d.ts +31 -0
  336. package/dist/qualityIntelligence/figma/figmaSnapshotBuilder.d.ts.map +1 -0
  337. package/dist/qualityIntelligence/figma/figmaSnapshotBuilder.js +314 -0
  338. package/dist/qualityIntelligence/figma/figmaSnapshotHash.d.ts +18 -0
  339. package/dist/qualityIntelligence/figma/figmaSnapshotHash.d.ts.map +1 -0
  340. package/dist/qualityIntelligence/figma/figmaSnapshotHash.js +63 -0
  341. package/dist/qualityIntelligence/figma/figmaSnapshotTypes.d.ts +65 -0
  342. package/dist/qualityIntelligence/figma/figmaSnapshotTypes.d.ts.map +1 -0
  343. package/dist/qualityIntelligence/figma/figmaSnapshotTypes.js +13 -0
  344. package/dist/qualityIntelligence/figma/figmaTokenSource.d.ts +9 -0
  345. package/dist/qualityIntelligence/figma/figmaTokenSource.d.ts.map +1 -0
  346. package/dist/qualityIntelligence/figma/figmaTokenSource.js +61 -0
  347. package/dist/qualityIntelligence/figma/figmaTokenStore.d.ts +19 -0
  348. package/dist/qualityIntelligence/figma/figmaTokenStore.d.ts.map +1 -0
  349. package/dist/qualityIntelligence/figma/figmaTokenStore.js +156 -0
  350. package/dist/qualityIntelligence/figma/figmaUrl.d.ts +6 -0
  351. package/dist/qualityIntelligence/figma/figmaUrl.d.ts.map +1 -0
  352. package/dist/qualityIntelligence/figma/figmaUrl.js +36 -0
  353. package/dist/qualityIntelligence/figma/index.d.ts +20 -0
  354. package/dist/qualityIntelligence/figma/index.d.ts.map +1 -0
  355. package/dist/qualityIntelligence/figma/index.js +26 -0
  356. package/dist/qualityIntelligence/figmaCodegenRoutes.d.ts +28 -0
  357. package/dist/qualityIntelligence/figmaCodegenRoutes.d.ts.map +1 -0
  358. package/dist/qualityIntelligence/figmaCodegenRoutes.js +165 -0
  359. package/dist/qualityIntelligence/figmaSnapshotAdapter.d.ts +55 -0
  360. package/dist/qualityIntelligence/figmaSnapshotAdapter.d.ts.map +1 -0
  361. package/dist/qualityIntelligence/figmaSnapshotAdapter.js +219 -0
  362. package/dist/qualityIntelligence/figmaSnapshotOrchestration.d.ts +64 -0
  363. package/dist/qualityIntelligence/figmaSnapshotOrchestration.d.ts.map +1 -0
  364. package/dist/qualityIntelligence/figmaSnapshotOrchestration.js +203 -0
  365. package/dist/qualityIntelligence/figmaSnapshotRoutes.d.ts +112 -0
  366. package/dist/qualityIntelligence/figmaSnapshotRoutes.d.ts.map +1 -0
  367. package/dist/qualityIntelligence/figmaSnapshotRoutes.js +1063 -0
  368. package/dist/qualityIntelligence/figmaSnapshotScreenIds.d.ts +19 -0
  369. package/dist/qualityIntelligence/figmaSnapshotScreenIds.d.ts.map +1 -0
  370. package/dist/qualityIntelligence/figmaSnapshotScreenIds.js +75 -0
  371. package/dist/qualityIntelligence/generationPort.d.ts +15 -0
  372. package/dist/qualityIntelligence/generationPort.d.ts.map +1 -0
  373. package/dist/qualityIntelligence/generationPort.js +185 -0
  374. package/dist/qualityIntelligence/handoffErrors.d.ts +9 -0
  375. package/dist/qualityIntelligence/handoffErrors.d.ts.map +1 -0
  376. package/dist/qualityIntelligence/handoffErrors.js +21 -0
  377. package/dist/qualityIntelligence/handoffRoutes.d.ts +15 -0
  378. package/dist/qualityIntelligence/handoffRoutes.d.ts.map +1 -0
  379. package/dist/qualityIntelligence/handoffRoutes.js +341 -0
  380. package/dist/qualityIntelligence/index.d.ts +17 -0
  381. package/dist/qualityIntelligence/index.d.ts.map +1 -0
  382. package/dist/qualityIntelligence/index.js +36 -0
  383. package/dist/qualityIntelligence/judgePort.d.ts +30 -0
  384. package/dist/qualityIntelligence/judgePort.d.ts.map +1 -0
  385. package/dist/qualityIntelligence/judgePort.js +326 -0
  386. package/dist/qualityIntelligence/modelSelection.d.ts +58 -0
  387. package/dist/qualityIntelligence/modelSelection.d.ts.map +1 -0
  388. package/dist/qualityIntelligence/modelSelection.js +148 -0
  389. package/dist/qualityIntelligence/reCheckRoutes.d.ts +6 -0
  390. package/dist/qualityIntelligence/reCheckRoutes.d.ts.map +1 -0
  391. package/dist/qualityIntelligence/reCheckRoutes.js +1157 -0
  392. package/dist/qualityIntelligence/retentionEnforcement.d.ts +13 -0
  393. package/dist/qualityIntelligence/retentionEnforcement.d.ts.map +1 -0
  394. package/dist/qualityIntelligence/retentionEnforcement.js +47 -0
  395. package/dist/qualityIntelligence/retentionRoutes.d.ts +8 -0
  396. package/dist/qualityIntelligence/retentionRoutes.d.ts.map +1 -0
  397. package/dist/qualityIntelligence/retentionRoutes.js +74 -0
  398. package/dist/qualityIntelligence/reviewRoutes.d.ts +5 -0
  399. package/dist/qualityIntelligence/reviewRoutes.d.ts.map +1 -0
  400. package/dist/qualityIntelligence/reviewRoutes.js +145 -0
  401. package/dist/qualityIntelligence/reviewStore.d.ts +75 -0
  402. package/dist/qualityIntelligence/reviewStore.d.ts.map +1 -0
  403. package/dist/qualityIntelligence/reviewStore.js +170 -0
  404. package/dist/qualityIntelligence/runExecution.d.ts +36 -0
  405. package/dist/qualityIntelligence/runExecution.d.ts.map +1 -0
  406. package/dist/qualityIntelligence/runExecution.js +180 -0
  407. package/dist/qualityIntelligence/runIngestion.d.ts +70 -0
  408. package/dist/qualityIntelligence/runIngestion.d.ts.map +1 -0
  409. package/dist/qualityIntelligence/runIngestion.js +1235 -0
  410. package/dist/qualityIntelligence/runRegistry.d.ts +31 -0
  411. package/dist/qualityIntelligence/runRegistry.d.ts.map +1 -0
  412. package/dist/qualityIntelligence/runRegistry.js +66 -0
  413. package/dist/qualityIntelligence/runRoutes.d.ts +16 -0
  414. package/dist/qualityIntelligence/runRoutes.d.ts.map +1 -0
  415. package/dist/qualityIntelligence/runRoutes.js +357 -0
  416. package/dist/qualityIntelligence/traceabilityRoutes.d.ts +5 -0
  417. package/dist/qualityIntelligence/traceabilityRoutes.d.ts.map +1 -0
  418. package/dist/qualityIntelligence/traceabilityRoutes.js +173 -0
  419. package/dist/qualityIntelligence/uiRoutes.d.ts +7 -0
  420. package/dist/qualityIntelligence/uiRoutes.d.ts.map +1 -0
  421. package/dist/qualityIntelligence/uiRoutes.js +336 -0
  422. package/dist/read-handlers.d.ts +9 -0
  423. package/dist/read-handlers.d.ts.map +1 -0
  424. package/dist/read-handlers.js +265 -0
  425. package/dist/relationship-handlers.d.ts +191 -0
  426. package/dist/relationship-handlers.d.ts.map +1 -0
  427. package/dist/relationship-handlers.js +0 -0
  428. package/dist/routes.d.ts +37 -0
  429. package/dist/routes.d.ts.map +1 -0
  430. package/dist/routes.js +507 -0
  431. package/dist/run-engine.d.ts +25 -0
  432. package/dist/run-engine.d.ts.map +1 -0
  433. package/dist/run-engine.js +385 -0
  434. package/dist/run-handlers.d.ts +9 -0
  435. package/dist/run-handlers.d.ts.map +1 -0
  436. package/dist/run-handlers.js +465 -0
  437. package/dist/run-request.d.ts +17 -0
  438. package/dist/run-request.d.ts.map +1 -0
  439. package/dist/run-request.js +219 -0
  440. package/dist/runs.d.ts +47 -0
  441. package/dist/runs.d.ts.map +1 -0
  442. package/dist/runs.js +100 -0
  443. package/dist/server.d.ts +13 -0
  444. package/dist/server.d.ts.map +1 -0
  445. package/dist/server.js +152 -0
  446. package/dist/sink.d.ts +28 -0
  447. package/dist/sink.d.ts.map +1 -0
  448. package/dist/sink.js +80 -0
  449. package/dist/sse-write.d.ts +9 -0
  450. package/dist/sse-write.d.ts.map +1 -0
  451. package/dist/sse-write.js +26 -0
  452. package/dist/sse.d.ts +8 -0
  453. package/dist/sse.d.ts.map +1 -0
  454. package/dist/sse.js +27 -0
  455. package/dist/static.d.ts +5 -0
  456. package/dist/static.d.ts.map +1 -0
  457. package/dist/static.js +76 -0
  458. package/dist/store/chats.d.ts +17 -0
  459. package/dist/store/chats.d.ts.map +1 -0
  460. package/dist/store/chats.js +624 -0
  461. package/dist/store/db.d.ts +11 -0
  462. package/dist/store/db.d.ts.map +1 -0
  463. package/dist/store/db.js +203 -0
  464. package/dist/store/errors.d.ts +13 -0
  465. package/dist/store/errors.d.ts.map +1 -0
  466. package/dist/store/errors.js +30 -0
  467. package/dist/store/index.d.ts +7 -0
  468. package/dist/store/index.d.ts.map +1 -0
  469. package/dist/store/index.js +6 -0
  470. package/dist/store/messages.d.ts +8 -0
  471. package/dist/store/messages.d.ts.map +1 -0
  472. package/dist/store/messages.js +149 -0
  473. package/dist/store/paths.d.ts +5 -0
  474. package/dist/store/paths.d.ts.map +1 -0
  475. package/dist/store/paths.js +84 -0
  476. package/dist/store/projects.d.ts +8 -0
  477. package/dist/store/projects.d.ts.map +1 -0
  478. package/dist/store/projects.js +59 -0
  479. package/dist/store/relationship-audit.d.ts +42 -0
  480. package/dist/store/relationship-audit.d.ts.map +1 -0
  481. package/dist/store/relationship-audit.js +155 -0
  482. package/dist/store/relationships.d.ts +191 -0
  483. package/dist/store/relationships.d.ts.map +1 -0
  484. package/dist/store/relationships.js +724 -0
  485. package/dist/store/schema.d.ts +4 -0
  486. package/dist/store/schema.d.ts.map +1 -0
  487. package/dist/store/schema.js +220 -0
  488. package/dist/store/types.d.ts +29 -0
  489. package/dist/store/types.d.ts.map +1 -0
  490. package/dist/store/types.js +8 -0
  491. package/dist/store/validation.d.ts +7 -0
  492. package/dist/store/validation.d.ts.map +1 -0
  493. package/dist/store/validation.js +117 -0
  494. package/dist/store-handlers.d.ts +17 -0
  495. package/dist/store-handlers.d.ts.map +1 -0
  496. package/dist/store-handlers.js +872 -0
  497. package/dist/terminal-errors.d.ts +22 -0
  498. package/dist/terminal-errors.d.ts.map +1 -0
  499. package/dist/terminal-errors.js +45 -0
  500. package/dist/terminal-evidence.d.ts +21 -0
  501. package/dist/terminal-evidence.d.ts.map +1 -0
  502. package/dist/terminal-evidence.js +65 -0
  503. package/dist/terminal-routes.d.ts +10 -0
  504. package/dist/terminal-routes.d.ts.map +1 -0
  505. package/dist/terminal-routes.js +219 -0
  506. package/dist/terminal.d.ts +68 -0
  507. package/dist/terminal.d.ts.map +1 -0
  508. package/dist/terminal.js +855 -0
  509. package/package.json +52 -0
package/dist/deps.js ADDED
@@ -0,0 +1,457 @@
1
+ // Wave 2 BFF handler dependencies (ADR-0011 D5/D8/D9). The Wave 1 skeleton's `UiServerDeps` carried
2
+ // only the static-serving + CSP + port fields; the JSON/SSE handlers additionally need the resolved
3
+ // gateway config (for the config inspector and for building a ModelPort), an evidence store, a live
4
+ // redactor, the process env, and the in-memory run registry. Every field here is OPTIONAL so the
5
+ // 3-arg `createUiServer({ staticRoot, csp, port })` form still compiles and the Wave 1 server tests
6
+ // pass unchanged; the handlers degrade gracefully (no config → 400 NO_MODEL on a run, null config on
7
+ // the inspector; no store → an empty evidence list).
8
+ import { createDefaultChatCapability, loadConfigFromFile, loadEgressConfigFromFile, parseGatewayConfig, resolveOutboundHttpEgressConfig, } from "@oscharko-dev/keiko-model-gateway";
9
+ import { GatewayError, Gateway } from "@oscharko-dev/keiko-model-gateway";
10
+ import { GatewayModelPort } from "@oscharko-dev/keiko-harness";
11
+ import { createAuditRedactor } from "@oscharko-dev/keiko-evidence";
12
+ import { resolveCostClass } from "@oscharko-dev/keiko-model-gateway";
13
+ import { writeSideFile } from "@oscharko-dev/keiko-evidence";
14
+ import { deepRedactStrings } from "@oscharko-dev/keiko-evidence";
15
+ import { keikoApiKeySecretValues } from "@oscharko-dev/keiko-security";
16
+ import { nodeWorkspaceFs } from "@oscharko-dev/keiko-workspace/internal/fs";
17
+ import { createNodeEvidenceStore, resolveEvidenceDir } from "@oscharko-dev/keiko-evidence";
18
+ import { dirname, join } from "node:path";
19
+ import { createRunRegistry } from "./runs.js";
20
+ import { assertUiDbOutsideProject, buildUiStoreOverDatabase, openNodeUiDatabase, resolveUiDbPath, validateProjectPath, } from "./store/index.js";
21
+ import { createTerminalExecutionManager } from "./terminal.js";
22
+ import { createBrowserSessionManager } from "@oscharko-dev/keiko-tools";
23
+ import {} from "@oscharko-dev/keiko-memory-vault";
24
+ import { createBffMemoryVault } from "./memory-handlers.js";
25
+ import { createMemoryAuditHandler } from "./memory-audit-handler.js";
26
+ import { createConsolidationJobRegistry, } from "./memory-consolidation-registry.js";
27
+ import { createRelationshipStorePort, } from "./relationship-handlers.js";
28
+ import { resolveGroundingLimits, } from "@oscharko-dev/keiko-contracts/bff-wire";
29
+ import { createProviderSecretResolver } from "./credentialVault.js";
30
+ import { createLocalKnowledgeKeyProvider } from "./localKnowledgeKeyProvider.js";
31
+ import { migrateLocalConfigCredentials } from "./credentialPersistence.js";
32
+ import { enforceQiRetentionAtStartup, } from "./qualityIntelligence/retentionEnforcement.js";
33
+ function envModelToken(modelId) {
34
+ return modelId.replace(/[^A-Za-z0-9]/g, "_").toUpperCase();
35
+ }
36
+ function envModelIdFromApiKeyName(name) {
37
+ const prefix = "KEIKO_MODEL_";
38
+ const suffix = "_API_KEY";
39
+ if (!name.startsWith(prefix) || !name.endsWith(suffix)) {
40
+ return undefined;
41
+ }
42
+ const token = name.slice(prefix.length, -suffix.length);
43
+ return token.length === 0 ? undefined : token.toLowerCase().replace(/_/g, "-");
44
+ }
45
+ function hasEnvProvider(modelId, env) {
46
+ const token = envModelToken(modelId);
47
+ const baseUrl = env[`KEIKO_MODEL_${token}_BASE_URL`];
48
+ const apiKey = env[`KEIKO_MODEL_${token}_API_KEY`];
49
+ return baseUrl !== undefined && baseUrl.length > 0 && apiKey !== undefined && apiKey.length > 0;
50
+ }
51
+ function envModelIds(env) {
52
+ const modelIds = [];
53
+ for (const key of Object.keys(env)) {
54
+ const modelId = envModelIdFromApiKeyName(key);
55
+ if (modelId !== undefined && hasEnvProvider(modelId, env)) {
56
+ modelIds.push(modelId);
57
+ }
58
+ }
59
+ return Array.from(new Set(modelIds));
60
+ }
61
+ function resolveEnvOnlyConfig(env) {
62
+ const providers = envModelIds(env).map((modelId) => ({
63
+ modelId,
64
+ baseUrl: "",
65
+ apiKey: "",
66
+ capability: createDefaultChatCapability(modelId),
67
+ }));
68
+ if (providers.length === 0) {
69
+ return undefined;
70
+ }
71
+ try {
72
+ return parseGatewayConfig({ providers }, env);
73
+ }
74
+ catch (error) {
75
+ if (error instanceof GatewayError) {
76
+ return undefined;
77
+ }
78
+ throw error;
79
+ }
80
+ }
81
+ function localGatewayConfigPath(uiDbPath) {
82
+ return join(dirname(uiDbPath), "keiko.config.json");
83
+ }
84
+ // Loads the config without leaking the path or any secret on failure: a missing/invalid config file
85
+ // falls back to KEIKO_MODEL_* env wiring when present, otherwise it is a normal "no config" state.
86
+ function resolveConfig(configPath, env, localConfigPath, secretResolver) {
87
+ if (configPath === undefined) {
88
+ let config;
89
+ try {
90
+ config = loadConfigFromFile(localConfigPath, env, { secretResolver });
91
+ }
92
+ catch (error) {
93
+ if (error instanceof GatewayError) {
94
+ config = resolveEnvOnlyConfig(env);
95
+ }
96
+ else {
97
+ throw error;
98
+ }
99
+ }
100
+ return { config, configPresent: config !== undefined };
101
+ }
102
+ try {
103
+ return { config: loadConfigFromFile(configPath, env, { secretResolver }), configPresent: true };
104
+ }
105
+ catch (error) {
106
+ if (error instanceof GatewayError) {
107
+ const config = resolveEnvOnlyConfig(env);
108
+ return { config, configPresent: config !== undefined };
109
+ }
110
+ throw error;
111
+ }
112
+ }
113
+ function resolveConfiguredEgress(configPath, env, localConfigPath) {
114
+ try {
115
+ return loadEgressConfigFromFile(configPath ?? localConfigPath, env);
116
+ }
117
+ catch (error) {
118
+ if (error instanceof GatewayError) {
119
+ return resolveOutboundHttpEgressConfig(undefined, env);
120
+ }
121
+ throw error;
122
+ }
123
+ }
124
+ function createRuntimeGatewayConfig(initial, initialPresent, storagePath) {
125
+ let config = initial;
126
+ let present = initialPresent;
127
+ return {
128
+ storagePath,
129
+ current: () => config,
130
+ present: () => present,
131
+ set(next, nextPresent) {
132
+ config = next;
133
+ present = nextPresent;
134
+ },
135
+ };
136
+ }
137
+ export function currentGatewayConfig(deps) {
138
+ return deps.gatewayConfig?.current() ?? deps.config;
139
+ }
140
+ export function currentGatewayConfigPresent(deps) {
141
+ return deps.gatewayConfig?.present() ?? deps.configPresent;
142
+ }
143
+ export function currentGatewayEgressConfig(deps) {
144
+ return (deps.gatewayConfig?.current()?.egress ??
145
+ deps.egress ??
146
+ deps.config?.egress ??
147
+ resolveOutboundHttpEgressConfig(undefined, deps.env));
148
+ }
149
+ // Module-level: read KEIKO_GROUNDING_* env overrides ONCE at load (mirrors KEIKO_MODEL_* env
150
+ // reads). Each value is parsed as a positive integer; unparseable values are silently ignored so
151
+ // misconfigured env does not prevent the server from starting.
152
+ function parseEnvPositiveInt(raw) {
153
+ if (raw === undefined)
154
+ return undefined;
155
+ // GRD-037: strict parse so a typo'd value is genuinely ignored (as the comment promises) rather
156
+ // than silently coerced — Number.parseInt("16abc")→16 and ("4.9")→4. Mirrors the loud
157
+ // config-file validator's all-digits rule, but here a bad env var falls back to the default.
158
+ const trimmed = raw.trim();
159
+ if (!/^\d+$/.test(trimmed))
160
+ return undefined;
161
+ const n = Number.parseInt(trimmed, 10);
162
+ return Number.isFinite(n) && n >= 1 ? n : undefined;
163
+ }
164
+ const ENV_GROUNDING_OVERRIDES = (() => {
165
+ const env = process.env;
166
+ const partial = {};
167
+ const maxConnectedSources = parseEnvPositiveInt(env.KEIKO_GROUNDING_MAX_CONNECTED_SOURCES);
168
+ if (maxConnectedSources !== undefined)
169
+ partial.maxConnectedSources = maxConnectedSources;
170
+ const maxLocalKnowledgeSources = parseEnvPositiveInt(env.KEIKO_GROUNDING_MAX_LOCAL_KNOWLEDGE_SOURCES);
171
+ if (maxLocalKnowledgeSources !== undefined)
172
+ partial.maxLocalKnowledgeSources = maxLocalKnowledgeSources;
173
+ const maxPromptReferences = parseEnvPositiveInt(env.KEIKO_GROUNDING_MAX_PROMPT_REFERENCES);
174
+ if (maxPromptReferences !== undefined)
175
+ partial.maxPromptReferences = maxPromptReferences;
176
+ const maxExcerptChars = parseEnvPositiveInt(env.KEIKO_GROUNDING_MAX_EXCERPT_CHARS);
177
+ if (maxExcerptChars !== undefined)
178
+ partial.maxExcerptChars = maxExcerptChars;
179
+ const referenceBudget = parseEnvPositiveInt(env.KEIKO_GROUNDING_REFERENCE_BUDGET);
180
+ if (referenceBudget !== undefined)
181
+ partial.referenceBudget = referenceBudget;
182
+ const hybridMaxCandidates = parseEnvPositiveInt(env.KEIKO_GROUNDING_HYBRID_MAX_CANDIDATES);
183
+ if (hybridMaxCandidates !== undefined)
184
+ partial.hybridMaxCandidates = hybridMaxCandidates;
185
+ const hybridMaxExcerptBytes = parseEnvPositiveInt(env.KEIKO_GROUNDING_HYBRID_MAX_EXCERPT_BYTES);
186
+ if (hybridMaxExcerptBytes !== undefined)
187
+ partial.hybridMaxExcerptBytes = hybridMaxExcerptBytes;
188
+ return partial;
189
+ })();
190
+ // Resolves the effective grounding limits at call time: file config → env overrides → ceilings.
191
+ // Env overrides win over file config. Re-reads currentGatewayConfig each call so runtime config
192
+ // updates (e.g. first-run UI onboarding) are honored immediately. Never stored as a frozen field.
193
+ export function currentGroundingLimits(deps) {
194
+ const fileGrounding = currentGatewayConfig(deps)?.grounding;
195
+ return resolveGroundingLimits({ ...fileGrounding, ...ENV_GROUNDING_OVERRIDES });
196
+ }
197
+ function configTopologyValues(config) {
198
+ // Epic #177 audit: redact provider URLs and egress settings because backend topology gives an
199
+ // attacker a place to direct probes. Credentials are collected separately as opaque secrets for
200
+ // evidence hashing.
201
+ if (config === undefined)
202
+ return [];
203
+ const out = [];
204
+ const addEgressTopology = (egress) => {
205
+ if (egress === undefined)
206
+ return;
207
+ if (egress.httpProxy !== undefined)
208
+ out.push(egress.httpProxy);
209
+ if (egress.httpsProxy !== undefined)
210
+ out.push(egress.httpsProxy);
211
+ if (egress.caBundlePath !== undefined)
212
+ out.push(egress.caBundlePath);
213
+ };
214
+ addEgressTopology(config.egress);
215
+ for (const provider of config.providers) {
216
+ out.push(provider.baseUrl);
217
+ addEgressTopology(provider.egress);
218
+ }
219
+ return out;
220
+ }
221
+ function configOpaqueSecretValues(config) {
222
+ if (config === undefined)
223
+ return [];
224
+ const out = [];
225
+ if (config.figma?.accessToken !== undefined) {
226
+ out.push(config.figma.accessToken);
227
+ }
228
+ for (const provider of config.providers) {
229
+ out.push(provider.apiKey);
230
+ }
231
+ return out;
232
+ }
233
+ function configSecretValues(config) {
234
+ return [...configTopologyValues(config), ...configOpaqueSecretValues(config)];
235
+ }
236
+ function figmaEnvSecretValues(env) {
237
+ const token = env.FIGMA_ACCESS_TOKEN;
238
+ return token !== undefined && token.length > 0 ? [token] : [];
239
+ }
240
+ function egressSecretValues(egress) {
241
+ if (egress === undefined)
242
+ return [];
243
+ return [egress.httpProxy, egress.httpsProxy, egress.caBundlePath].filter((value) => value !== undefined);
244
+ }
245
+ // The Figma PAT is redacted via its config (`config.figma.accessToken`) and env
246
+ // (`FIGMA_ACCESS_TOKEN`) literals. The decrypted ENCRYPTED-VAULT token (#758) is intentionally NOT
247
+ // added here: it never reaches a redactable payload — it is confined to the outbound `X-Figma-Token`
248
+ // request header by construction (figmaConnector.ts) and is never returned, logged, or serialized.
249
+ // Adding it would require decrypting the vault at redactor-build time, widening exposure for no gain.
250
+ function redactionSecrets(env, config, egress = config?.egress) {
251
+ return Array.from(new Set([
252
+ ...keikoApiKeySecretValues(env),
253
+ ...figmaEnvSecretValues(env),
254
+ ...configSecretValues(config),
255
+ ...egressSecretValues(egress),
256
+ ]));
257
+ }
258
+ function runtimeRedactionSecrets(env, runtimeConfig, egress) {
259
+ const config = runtimeConfig.current();
260
+ return redactionSecrets(env, config, config?.egress ?? egress);
261
+ }
262
+ function runtimeRedactString(env, runtimeConfig, egress) {
263
+ return (value) => createAuditRedactor({ additionalSecrets: runtimeRedactionSecrets(env, runtimeConfig, egress) }, env)(value);
264
+ }
265
+ // Builds the live-payload redactor from the configured redaction settings + env. No new regex: this
266
+ // reuses `createAuditRedactor` (escaped literals + audited gateway patterns) wrapped by
267
+ // `deepRedactStrings` so every string leaf of a serialized payload is scrubbed.
268
+ export function buildRedactor(env, config) {
269
+ const egress = config?.egress ?? resolveOutboundHttpEgressConfig(undefined, env);
270
+ const redactString = createAuditRedactor({
271
+ additionalSecrets: redactionSecrets(env, config, egress),
272
+ }, env);
273
+ return (value) => deepRedactStrings(value, redactString);
274
+ }
275
+ export function currentRedactionSecrets(deps) {
276
+ return redactionSecrets(deps.env, currentGatewayConfig(deps), currentGatewayEgressConfig(deps));
277
+ }
278
+ export function currentEvidenceTopologyRedactionSecrets(deps) {
279
+ return Array.from(new Set([
280
+ ...configTopologyValues(currentGatewayConfig(deps)),
281
+ ...egressSecretValues(currentGatewayEgressConfig(deps)),
282
+ ]));
283
+ }
284
+ export function currentEvidenceRequiresFullStringRedaction(deps) {
285
+ return (keikoApiKeySecretValues(deps.env).length > 0 ||
286
+ figmaEnvSecretValues(deps.env).length > 0 ||
287
+ configOpaqueSecretValues(currentGatewayConfig(deps)).length > 0);
288
+ }
289
+ // The production ModelPort factory: a GatewayModelPort over a Gateway built from the resolved
290
+ // config (mirrors the CLI's `new GatewayModelPort(new Gateway(config))`). Returns undefined when no
291
+ // config was resolved so the run route answers 400 NO_MODEL rather than constructing a broken port.
292
+ function defaultModelPortFactory(runtimeConfig) {
293
+ return () => {
294
+ const config = runtimeConfig.current();
295
+ if (config === undefined) {
296
+ return undefined;
297
+ }
298
+ return new GatewayModelPort(new Gateway(config));
299
+ };
300
+ }
301
+ function buildTerminalManager(options) {
302
+ return createTerminalExecutionManager({
303
+ store: options.store,
304
+ evidenceStore: options.evidenceStore,
305
+ processEnv: options.env,
306
+ redactor: (value) => {
307
+ const redacted = options.liveRedactor(value);
308
+ return typeof redacted === "string" ? redacted : value;
309
+ },
310
+ });
311
+ }
312
+ // ADR-0019 direction rule 3c: the tools package cannot import src/audit. The BFF injects the
313
+ // cost-class resolver and a side-file writer that closes over the resolved evidenceDir + the
314
+ // nodeWorkspaceFs realpath-containment port, so the browser session manager stays self-contained
315
+ // against contracts + security + workspace only.
316
+ function buildBrowserManager(options) {
317
+ return createBrowserSessionManager({
318
+ evidenceDir: options.evidenceDir,
319
+ evidenceStore: options.evidenceStore,
320
+ redactor: options.redactor,
321
+ costClassResolver: resolveCostClass,
322
+ sideFileWriter: (basename, bytes, runId) => writeSideFile(options.evidenceDir, runId, basename, bytes, { fs: nodeWorkspaceFs }),
323
+ });
324
+ }
325
+ function buildMemoryVault(redactString, evidenceStore, env) {
326
+ return createBffMemoryVault(redactString,
327
+ // #214 — wire every successful vault mutation into the audit ledger. The handler
328
+ // shares the same redactString closure as the live-payload redactor so audit
329
+ // summaries inherit the same secret-shape scrubbing as wire traffic.
330
+ createMemoryAuditHandler({ evidenceStore, redactString }), env);
331
+ }
332
+ // Issue #539: the relationship engine runs server-authoritative scope checks on every route.
333
+ // In the loopback `keiko ui` BFF there is exactly one workspace per process; the resolver
334
+ // returns that workspace identifier from `KEIKO_WORKSPACE_ID` (set), or a stable default
335
+ // otherwise. The constant matches the empty-but-non-zero-length contract of `scope()` so
336
+ // every route resolves a workspaceId instead of returning 403.
337
+ const DEFAULT_LOOPBACK_WORKSPACE_ID = "local";
338
+ function resolveLoopbackWorkspaceId(env) {
339
+ const explicit = env.KEIKO_WORKSPACE_ID;
340
+ if (typeof explicit === "string" && explicit.length > 0)
341
+ return explicit;
342
+ return DEFAULT_LOOPBACK_WORKSPACE_ID;
343
+ }
344
+ // When no UiStore is injected, open one DatabaseSync against the resolved UI-DB and share it
345
+ // with the relationship-engine store so V5 sibling tables share the UI-store transaction model
346
+ // (issue #539, storage.md §3.1). When tests inject a UiStore we leave `relationship` undefined;
347
+ // relationship-engine tests inject their own deps.
348
+ function composePersistence(injected, resolvedUiDbPath, redactString, env) {
349
+ if (injected !== undefined)
350
+ return { store: injected, relationship: undefined };
351
+ const db = openNodeUiDatabase(resolvedUiDbPath);
352
+ const store = buildUiStoreOverDatabase(db, { redactString });
353
+ const relationship = {
354
+ scopeResolver: () => ({
355
+ workspaceId: resolveLoopbackWorkspaceId(env),
356
+ }),
357
+ store: createRelationshipStorePort({ db, redactString }),
358
+ };
359
+ return { store, relationship };
360
+ }
361
+ function seedInitialProject(store, uiDbPath, initialProjectPath) {
362
+ if (initialProjectPath === undefined || initialProjectPath.trim().length === 0) {
363
+ return undefined;
364
+ }
365
+ const normalizedPath = validateProjectPath(initialProjectPath, { mustExist: true });
366
+ assertUiDbOutsideProject(uiDbPath, normalizedPath);
367
+ return store.createProject(normalizedPath).path;
368
+ }
369
+ function buildPeripherals(options, uiStore, evidenceStore, redactString, liveRedactor) {
370
+ return {
371
+ terminal: buildTerminalManager({
372
+ store: uiStore,
373
+ evidenceStore,
374
+ env: options.env,
375
+ liveRedactor,
376
+ }),
377
+ browser: buildBrowserManager({
378
+ evidenceDir: resolveEvidenceDir(options.evidenceDir, options.env),
379
+ evidenceStore,
380
+ redactor: liveRedactor,
381
+ }),
382
+ memoryVault: buildMemoryVault(redactString, evidenceStore, options.env),
383
+ };
384
+ }
385
+ // Assembles the handler deps for the real `keiko ui` process, mirroring the CLI config/evidence
386
+ // wiring (loadConfigFromFile / resolveEvidenceDir / createNodeEvidenceStore). The UI store is
387
+ // created at the resolved UI-DB path (explicit → KEIKO_UI_DATA_DIR → ~/.keiko/keiko-ui.db) unless
388
+ // an injected store is supplied (tests).
389
+ // One-time, idempotent migration of any pre-existing plaintext credentials in the local config
390
+ // (Issue #1320), then resolution of the (now reference-only) config through a vault-backed resolver.
391
+ // Migration is best-effort and crash-aware: it never throws into bootstrap, so a partial state simply
392
+ // re-runs next start and is surfaced by `keiko repair`. It runs before the config is read so the
393
+ // resolver turns the rewritten secret references back into live credentials.
394
+ function loadRuntimeGatewayConfig(options, runtimeConfigPath, resolvedEvidenceDir) {
395
+ const effectiveConfigPath = options.configPath ?? runtimeConfigPath;
396
+ migrateLocalConfigCredentials({
397
+ configPath: effectiveConfigPath,
398
+ env: options.env,
399
+ evidenceDir: resolvedEvidenceDir,
400
+ });
401
+ const secretResolver = createProviderSecretResolver({
402
+ configPath: effectiveConfigPath,
403
+ env: options.env,
404
+ });
405
+ const resolved = resolveConfig(options.configPath, options.env, runtimeConfigPath, secretResolver);
406
+ return { ...resolved, storagePath: effectiveConfigPath };
407
+ }
408
+ // Resolve the evidence dir AND run QI run-retention ONCE per server instance at bootstrap (Issue
409
+ // #1323 AC4). Lazy, no timer (a setInterval would race the filesystem-backed store). Best-effort:
410
+ // retention never throws into construction (mirrors migrateLocalConfigCredentials). Short-lived runs
411
+ // past their retention policy are purged deterministically rather than the policy id staying passive.
412
+ function resolveEvidenceDirAndEnforceRetention(options) {
413
+ const evidenceDir = resolveEvidenceDir(options.evidenceDir, options.env);
414
+ enforceQiRetentionAtStartup({
415
+ evidenceDir,
416
+ now: options.qiRetentionNow,
417
+ auditSink: options.qiRetentionAuditSink,
418
+ });
419
+ return evidenceDir;
420
+ }
421
+ export function buildUiHandlerDeps(options) {
422
+ const resolvedUiDbPath = resolveUiDbPath(options.uiDbPath, options.env);
423
+ const runtimeConfigPath = localGatewayConfigPath(resolvedUiDbPath);
424
+ const resolvedEvidenceDir = resolveEvidenceDirAndEnforceRetention(options);
425
+ const { config, configPresent, storagePath } = loadRuntimeGatewayConfig(options, runtimeConfigPath, resolvedEvidenceDir);
426
+ const egress = resolveConfiguredEgress(options.configPath, options.env, runtimeConfigPath);
427
+ const runtimeConfig = createRuntimeGatewayConfig(config, configPresent, storagePath);
428
+ const evidenceStore = createNodeEvidenceStore(resolvedEvidenceDir);
429
+ const redactString = runtimeRedactString(options.env, runtimeConfig, egress);
430
+ const liveRedactor = (value) => deepRedactStrings(value, redactString);
431
+ const { store: uiStore, relationship } = composePersistence(options.store, resolvedUiDbPath, redactString, options.env);
432
+ const preferredProjectPath = seedInitialProject(uiStore, resolvedUiDbPath, options.initialProjectPath);
433
+ const peripherals = buildPeripherals(options, uiStore, evidenceStore, redactString, liveRedactor);
434
+ return {
435
+ config,
436
+ configPresent,
437
+ evidenceStore,
438
+ evidenceDir: resolvedEvidenceDir,
439
+ env: options.env,
440
+ egress,
441
+ redactor: liveRedactor,
442
+ registry: options.registry ?? createRunRegistry(),
443
+ modelPortFactory: options.modelPortFactory ?? defaultModelPortFactory(runtimeConfig),
444
+ redactionSecrets: runtimeRedactionSecrets(options.env, runtimeConfig, egress),
445
+ store: uiStore,
446
+ uiDbPath: resolvedUiDbPath,
447
+ preferredProjectPath,
448
+ gatewayConfig: runtimeConfig,
449
+ gatewaySetupTester: options.gatewaySetupTester,
450
+ gatewayModelDiscovery: options.gatewayModelDiscovery,
451
+ figmaCredentialTester: options.figmaCredentialTester,
452
+ localKnowledgeKeyProvider: createLocalKnowledgeKeyProvider({ env: options.env }),
453
+ ...peripherals,
454
+ consolidationJobs: createConsolidationJobRegistry(),
455
+ ...(relationship === undefined ? {} : { relationship }),
456
+ };
457
+ }
@@ -0,0 +1,7 @@
1
+ import { type HandlerOutcome, type RouteContext, type RouteResult } from "../routes.js";
2
+ export declare function handleEditorAgentSessions(): RouteResult;
3
+ export declare function handleEditorAgentSnapshot(ctx: RouteContext): Promise<RouteResult>;
4
+ export declare function handleEditorAgentActions(ctx: RouteContext): Promise<RouteResult>;
5
+ export declare function handleEditorAgentEvents(ctx: RouteContext): HandlerOutcome;
6
+ export declare function _resetEditorAgentStateForTests(): void;
7
+ //# sourceMappingURL=agentRoutes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agentRoutes.d.ts","sourceRoot":"","sources":["../../src/editor/agentRoutes.ts"],"names":[],"mappings":"AAYA,OAAO,EAAwB,KAAK,cAAc,EAAE,KAAK,YAAY,EAAE,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AAiJ9G,wBAAgB,yBAAyB,IAAI,WAAW,CAEvD;AAED,wBAAsB,yBAAyB,CAAC,GAAG,EAAE,YAAY,GAAG,OAAO,CAAC,WAAW,CAAC,CAsBvF;AAED,wBAAsB,wBAAwB,CAAC,GAAG,EAAE,YAAY,GAAG,OAAO,CAAC,WAAW,CAAC,CAsCtF;AAED,wBAAgB,uBAAuB,CAAC,GAAG,EAAE,YAAY,GAAG,cAAc,CAMzE;AAeD,wBAAgB,8BAA8B,IAAI,IAAI,CAKrD"}
@@ -0,0 +1,197 @@
1
+ import { EDITOR_AGENT_SCHEMA_VERSION, isEditorAgentAction, parseEditorAgentActionsPostBody, parseEditorAgentSnapshotRequest, } from "@oscharko-dev/keiko-contracts";
2
+ import { errorBody, STREAMING } from "../routes.js";
3
+ import { SSE_HEADERS, readyMessage } from "../sse.js";
4
+ import { readJsonObject } from "../files.js";
5
+ const MAX_AGENT_BODY_BYTES = 1_048_576;
6
+ const DEFAULT_SNAPSHOT_TEXT_BUDGET_BYTES = 64 * 1024;
7
+ const sessions = new Map();
8
+ const idempotency = new Map();
9
+ const subscribers = new Set();
10
+ let eventSeq = 0;
11
+ function isRouteResult(value) {
12
+ return typeof value === "object" && value !== null && "status" in value && "body" in value;
13
+ }
14
+ function nextEventId() {
15
+ eventSeq += 1;
16
+ return `editor-agent-${String(eventSeq)}`;
17
+ }
18
+ function emit(event) {
19
+ const envelope = {
20
+ schemaVersion: EDITOR_AGENT_SCHEMA_VERSION,
21
+ eventId: nextEventId(),
22
+ ...event,
23
+ };
24
+ for (const subscriber of subscribers)
25
+ subscriber(envelope);
26
+ }
27
+ function utf8Prefix(text, maxBytes) {
28
+ let bytes = 0;
29
+ let end = 0;
30
+ for (const char of text) {
31
+ const nextBytes = Buffer.byteLength(char, "utf8");
32
+ if (bytes + nextBytes > maxBytes)
33
+ return { text: text.slice(0, end), truncated: true };
34
+ bytes += nextBytes;
35
+ end += char.length;
36
+ }
37
+ return { text, truncated: false };
38
+ }
39
+ function shapeSnapshot(snapshot, textMode, maxBytes) {
40
+ if (textMode === "none" || snapshot.text === undefined) {
41
+ const { text, textTruncated, ...rest } = snapshot;
42
+ void text;
43
+ void textTruncated;
44
+ return { ...rest, textMode };
45
+ }
46
+ const bounded = utf8Prefix(snapshot.text, maxBytes);
47
+ return {
48
+ ...snapshot,
49
+ textMode,
50
+ text: bounded.text,
51
+ textTruncated: snapshot.textTruncated === true || bounded.truncated,
52
+ };
53
+ }
54
+ function dirtyBufferConflict(action, snapshot) {
55
+ const file = targetFile(action, snapshot);
56
+ if (file !== null && snapshot.dirtyFiles.includes(file) && action.type !== "save") {
57
+ return conflict(action, "DIRTY", "The target buffer has unsaved changes.");
58
+ }
59
+ return null;
60
+ }
61
+ function documentVersionConflict(action, snapshot) {
62
+ if (action.expectedDocumentVersion === undefined || snapshot.documentVersion === undefined)
63
+ return null;
64
+ return action.expectedDocumentVersion.contentHash === snapshot.documentVersion.contentHash
65
+ ? null
66
+ : conflict(action, "VERSION_MISMATCH", "The active document version no longer matches.");
67
+ }
68
+ function contentHashConflict(action, snapshot) {
69
+ if (action.expectedContentHash === undefined || snapshot.activeFileContentHash === undefined)
70
+ return null;
71
+ return action.expectedContentHash === snapshot.activeFileContentHash
72
+ ? null
73
+ : conflict(action, "CONTENT_HASH_MISMATCH", "The active document content hash no longer matches.");
74
+ }
75
+ function targetFile(action, snapshot) {
76
+ return action.target?.file ?? snapshot.activeFile;
77
+ }
78
+ function writeAction(action) {
79
+ return (action.type === "format" ||
80
+ action.type === "save" ||
81
+ action.type === "applyTextEdits" ||
82
+ action.type === "applyPatch");
83
+ }
84
+ function conflict(action, code, message) {
85
+ return {
86
+ schemaVersion: EDITOR_AGENT_SCHEMA_VERSION,
87
+ actionId: action.actionId,
88
+ sessionId: action.sessionId,
89
+ status: "conflict",
90
+ message,
91
+ conflict: { code, message },
92
+ };
93
+ }
94
+ function preflight(action) {
95
+ const snapshot = sessions.get(action.sessionId);
96
+ if (snapshot === undefined) {
97
+ return conflict(action, "NO_ACTIVE_SESSION", "No active browser bridge is registered.");
98
+ }
99
+ if (!writeAction(action))
100
+ return null;
101
+ return (dirtyBufferConflict(action, snapshot) ??
102
+ documentVersionConflict(action, snapshot) ??
103
+ contentHashConflict(action, snapshot));
104
+ }
105
+ export function handleEditorAgentSessions() {
106
+ return { status: 200, body: { sessions: [...sessions.values()] } };
107
+ }
108
+ export async function handleEditorAgentSnapshot(ctx) {
109
+ const body = await readJsonObject(ctx.req, MAX_AGENT_BODY_BYTES);
110
+ if (isRouteResult(body))
111
+ return body;
112
+ const parsed = parseEditorAgentSnapshotRequest(body);
113
+ if (!parsed.ok) {
114
+ return { status: 400, body: errorBody("INVALID_REQUEST", parsed.errors.join("; ")) };
115
+ }
116
+ if ("kind" in parsed.value) {
117
+ sessions.set(parsed.value.snapshot.sessionId, parsed.value.snapshot);
118
+ emit({ type: "session", snapshot: parsed.value.snapshot });
119
+ return { status: 200, body: { snapshot: parsed.value.snapshot } };
120
+ }
121
+ const selected = parsed.value.sessionId === undefined
122
+ ? [...sessions.values()][0]
123
+ : sessions.get(parsed.value.sessionId);
124
+ if (selected === undefined)
125
+ return { status: 200, body: { snapshot: null } };
126
+ const maxBytes = parsed.value.maxBytes ?? DEFAULT_SNAPSHOT_TEXT_BUDGET_BYTES;
127
+ return {
128
+ status: 200,
129
+ body: { snapshot: shapeSnapshot(selected, parsed.value.textMode, maxBytes) },
130
+ };
131
+ }
132
+ export async function handleEditorAgentActions(ctx) {
133
+ const body = await readJsonObject(ctx.req, MAX_AGENT_BODY_BYTES);
134
+ if (isRouteResult(body))
135
+ return body;
136
+ const parsed = parseEditorAgentActionsPostBody(body);
137
+ if (!parsed.ok) {
138
+ return { status: 400, body: errorBody("INVALID_REQUEST", parsed.errors.join("; ")) };
139
+ }
140
+ if (!isEditorAgentAction(parsed.value)) {
141
+ const result = parsed.value.result;
142
+ emit({ type: "result", result });
143
+ return { status: 200, body: { result } };
144
+ }
145
+ const action = parsed.value;
146
+ const requestBody = JSON.stringify(action);
147
+ const replay = idempotency.get(action.idempotencyKey);
148
+ if (replay !== undefined) {
149
+ if (replay.requestBody !== requestBody) {
150
+ return {
151
+ status: 409,
152
+ body: errorBody("IDEMPOTENCY_CONFLICT", "Idempotency-Key was reused with a different action."),
153
+ };
154
+ }
155
+ return { status: 200, body: { result: replay.result } };
156
+ }
157
+ const failed = preflight(action);
158
+ if (failed !== null) {
159
+ idempotency.set(action.idempotencyKey, { requestBody, result: failed });
160
+ return { status: 409, body: { result: failed } };
161
+ }
162
+ const result = {
163
+ schemaVersion: EDITOR_AGENT_SCHEMA_VERSION,
164
+ actionId: action.actionId,
165
+ sessionId: action.sessionId,
166
+ status: "queued",
167
+ };
168
+ idempotency.set(action.idempotencyKey, { requestBody, result });
169
+ emit({ type: "action", action });
170
+ return { status: 202, body: { result } };
171
+ }
172
+ export function handleEditorAgentEvents(ctx) {
173
+ openAgentSseStream(ctx.res);
174
+ ctx.req.on("close", () => {
175
+ ctx.res.end();
176
+ });
177
+ return STREAMING;
178
+ }
179
+ function openAgentSseStream(res) {
180
+ res.writeHead(200, SSE_HEADERS);
181
+ const subscriber = (event) => {
182
+ const frame = `id: ${event.eventId}\nevent: editor-agent:${event.type}\ndata: ${JSON.stringify(event)}\n\n`;
183
+ if (!res.write(frame))
184
+ res.destroy();
185
+ };
186
+ subscribers.add(subscriber);
187
+ res.write(readyMessage());
188
+ res.on("close", () => {
189
+ subscribers.delete(subscriber);
190
+ });
191
+ }
192
+ export function _resetEditorAgentStateForTests() {
193
+ sessions.clear();
194
+ idempotency.clear();
195
+ subscribers.clear();
196
+ eventSeq = 0;
197
+ }