@kb-labs/rest-api-app 1.3.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 (255) hide show
  1. package/.kb/agents/sessions/session-1771531145393-ws3uh6q/turns.json +42 -0
  2. package/.kb/agents/sessions/session-1771548930486-ui6rtvm/turns.json +33 -0
  3. package/.kb/agents/sessions/session-1771549691485-nibqroq/turns.json +133 -0
  4. package/.kb/agents/sessions/session-1771550943182-dkwqdjc/turns.json +130 -0
  5. package/.kb/agents/sessions/session-1771551564182-cr4bwzn/turns.json +349 -0
  6. package/.kb/agents/sessions/session-1771552401370-g4ztwd1/turns.json +206 -0
  7. package/.kb/commit/current/plan.json +248 -0
  8. package/.kb/commit/current/status.json +472 -0
  9. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/commands/health.d.ts +10 -0
  10. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/commands/health.js +215 -0
  11. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/commands/health.js.map +1 -0
  12. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/commands/list.d.ts +10 -0
  13. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/commands/list.js +271 -0
  14. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/commands/list.js.map +1 -0
  15. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/commands/logs.d.ts +10 -0
  16. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/commands/logs.js +230 -0
  17. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/commands/logs.js.map +1 -0
  18. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/commands/metrics.d.ts +10 -0
  19. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/commands/metrics.js +228 -0
  20. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/commands/metrics.js.map +1 -0
  21. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/commands/run.d.ts +11 -0
  22. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/commands/run.js +281 -0
  23. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/commands/run.js.map +1 -0
  24. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/commands/status.d.ts +10 -0
  25. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/commands/status.js +266 -0
  26. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/commands/status.js.map +1 -0
  27. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/commands/workflow-run.d.ts +11 -0
  28. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/commands/workflow-run.js +284 -0
  29. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/commands/workflow-run.js.map +1 -0
  30. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/flags-WLdpSZl4.d.ts +77 -0
  31. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/index.d.ts +2 -0
  32. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/index.js +441 -0
  33. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/index.js.map +1 -0
  34. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/manifest.d.ts +196 -0
  35. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/manifest.js +441 -0
  36. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/manifest.js.map +1 -0
  37. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/cron-list-handler.d.ts +19 -0
  38. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/cron-list-handler.js +48 -0
  39. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/cron-list-handler.js.map +1 -0
  40. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/index.d.ts +6 -0
  41. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/index.js +170 -0
  42. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/index.js.map +1 -0
  43. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/job-cancel-handler.d.ts +12 -0
  44. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/job-cancel-handler.js +52 -0
  45. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/job-cancel-handler.js.map +1 -0
  46. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/job-detail-handler.d.ts +22 -0
  47. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/job-detail-handler.js +52 -0
  48. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/job-detail-handler.js.map +1 -0
  49. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/job-logs-handler.d.ts +13 -0
  50. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/job-logs-handler.js +52 -0
  51. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/job-logs-handler.js.map +1 -0
  52. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/job-steps-handler.d.ts +9 -0
  53. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/job-steps-handler.js +43 -0
  54. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/job-steps-handler.js.map +1 -0
  55. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/jobs-list-handler.d.ts +26 -0
  56. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/jobs-list-handler.js +63 -0
  57. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/jobs-list-handler.js.map +1 -0
  58. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/pending-approvals-handler.d.ts +9 -0
  59. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/pending-approvals-handler.js +46 -0
  60. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/pending-approvals-handler.js.map +1 -0
  61. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/resolve-approval-handler.d.ts +16 -0
  62. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/resolve-approval-handler.js +58 -0
  63. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/resolve-approval-handler.js.map +1 -0
  64. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/run-detail-handler.d.ts +9 -0
  65. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/run-detail-handler.js +46 -0
  66. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/run-detail-handler.js.map +1 -0
  67. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/runs-list-handler.d.ts +11 -0
  68. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/runs-list-handler.js +50 -0
  69. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/runs-list-handler.js.map +1 -0
  70. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/stats-handler.d.ts +7 -0
  71. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/stats-handler.js +39 -0
  72. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/stats-handler.js.map +1 -0
  73. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/workflow-detail-handler.d.ts +10 -0
  74. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/workflow-detail-handler.js +46 -0
  75. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/workflow-detail-handler.js.map +1 -0
  76. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/workflow-run-cancel-handler.d.ts +13 -0
  77. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/workflow-run-cancel-handler.js +47 -0
  78. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/workflow-run-cancel-handler.js.map +1 -0
  79. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/workflow-run-handler.d.ts +14 -0
  80. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/workflow-run-handler.js +53 -0
  81. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/workflow-run-handler.js.map +1 -0
  82. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/workflow-runs-handler.d.ts +13 -0
  83. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/workflow-runs-handler.js +54 -0
  84. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/workflow-runs-handler.js.map +1 -0
  85. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/workflows-list-handler.d.ts +12 -0
  86. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/workflows-list-handler.js +51 -0
  87. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/workflows-list-handler.js.map +1 -0
  88. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/ws/logs-channel.d.ts +17 -0
  89. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/ws/logs-channel.js +133 -0
  90. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/ws/logs-channel.js.map +1 -0
  91. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/ws/progress-channel.d.ts +11 -0
  92. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/ws/progress-channel.js +46 -0
  93. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/ws/progress-channel.js.map +1 -0
  94. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/commands/health.d.ts +10 -0
  95. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/commands/health.js +215 -0
  96. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/commands/health.js.map +1 -0
  97. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/commands/list.d.ts +10 -0
  98. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/commands/list.js +271 -0
  99. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/commands/list.js.map +1 -0
  100. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/commands/logs.d.ts +10 -0
  101. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/commands/logs.js +230 -0
  102. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/commands/logs.js.map +1 -0
  103. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/commands/metrics.d.ts +10 -0
  104. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/commands/metrics.js +228 -0
  105. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/commands/metrics.js.map +1 -0
  106. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/commands/run.d.ts +11 -0
  107. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/commands/run.js +281 -0
  108. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/commands/run.js.map +1 -0
  109. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/commands/status.d.ts +10 -0
  110. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/commands/status.js +266 -0
  111. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/commands/status.js.map +1 -0
  112. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/commands/workflow-run.d.ts +11 -0
  113. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/commands/workflow-run.js +284 -0
  114. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/commands/workflow-run.js.map +1 -0
  115. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/flags-WLdpSZl4.d.ts +77 -0
  116. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/index.d.ts +2 -0
  117. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/index.js +441 -0
  118. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/index.js.map +1 -0
  119. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/manifest.d.ts +196 -0
  120. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/manifest.js +441 -0
  121. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/manifest.js.map +1 -0
  122. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/cron-list-handler.d.ts +19 -0
  123. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/cron-list-handler.js +48 -0
  124. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/cron-list-handler.js.map +1 -0
  125. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/index.d.ts +6 -0
  126. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/index.js +170 -0
  127. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/index.js.map +1 -0
  128. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/job-cancel-handler.d.ts +12 -0
  129. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/job-cancel-handler.js +52 -0
  130. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/job-cancel-handler.js.map +1 -0
  131. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/job-detail-handler.d.ts +22 -0
  132. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/job-detail-handler.js +52 -0
  133. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/job-detail-handler.js.map +1 -0
  134. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/job-logs-handler.d.ts +13 -0
  135. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/job-logs-handler.js +52 -0
  136. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/job-logs-handler.js.map +1 -0
  137. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/job-steps-handler.d.ts +9 -0
  138. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/job-steps-handler.js +43 -0
  139. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/job-steps-handler.js.map +1 -0
  140. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/jobs-list-handler.d.ts +26 -0
  141. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/jobs-list-handler.js +63 -0
  142. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/jobs-list-handler.js.map +1 -0
  143. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/pending-approvals-handler.d.ts +9 -0
  144. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/pending-approvals-handler.js +46 -0
  145. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/pending-approvals-handler.js.map +1 -0
  146. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/resolve-approval-handler.d.ts +16 -0
  147. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/resolve-approval-handler.js +58 -0
  148. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/resolve-approval-handler.js.map +1 -0
  149. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/run-detail-handler.d.ts +9 -0
  150. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/run-detail-handler.js +46 -0
  151. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/run-detail-handler.js.map +1 -0
  152. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/runs-list-handler.d.ts +11 -0
  153. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/runs-list-handler.js +50 -0
  154. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/runs-list-handler.js.map +1 -0
  155. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/stats-handler.d.ts +7 -0
  156. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/stats-handler.js +39 -0
  157. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/stats-handler.js.map +1 -0
  158. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/workflow-detail-handler.d.ts +10 -0
  159. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/workflow-detail-handler.js +46 -0
  160. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/workflow-detail-handler.js.map +1 -0
  161. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/workflow-run-cancel-handler.d.ts +13 -0
  162. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/workflow-run-cancel-handler.js +47 -0
  163. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/workflow-run-cancel-handler.js.map +1 -0
  164. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/workflow-run-handler.d.ts +14 -0
  165. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/workflow-run-handler.js +53 -0
  166. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/workflow-run-handler.js.map +1 -0
  167. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/workflow-runs-handler.d.ts +13 -0
  168. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/workflow-runs-handler.js +54 -0
  169. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/workflow-runs-handler.js.map +1 -0
  170. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/workflows-list-handler.d.ts +12 -0
  171. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/workflows-list-handler.js +51 -0
  172. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/workflows-list-handler.js.map +1 -0
  173. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/ws/logs-channel.d.ts +17 -0
  174. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/ws/logs-channel.js +133 -0
  175. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/ws/logs-channel.js.map +1 -0
  176. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/ws/progress-channel.d.ts +11 -0
  177. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/ws/progress-channel.js +46 -0
  178. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/ws/progress-channel.js.map +1 -0
  179. package/README.md +54 -0
  180. package/eslint.config.js +23 -0
  181. package/package.json +72 -0
  182. package/src/.kb/agents/sessions/session-1773470583796-ximqnfk/kpi-baseline.json +17 -0
  183. package/src/.kb/memory/sessions/session-1773470583796-ximqnfk/fact-sheet.json +1 -0
  184. package/src/bootstrap.ts +233 -0
  185. package/src/diagnostics/header-debug.ts +37 -0
  186. package/src/events/hub.ts +60 -0
  187. package/src/events/index.ts +1 -0
  188. package/src/index.ts +13 -0
  189. package/src/manifest.ts +21 -0
  190. package/src/middleware/__tests__/cache.spec.ts +184 -0
  191. package/src/middleware/__tests__/envelope.spec.ts +268 -0
  192. package/src/middleware/__tests__/metrics.redis.spec.ts +64 -0
  193. package/src/middleware/__tests__/rate-limit.spec.ts +283 -0
  194. package/src/middleware/__tests__/request-id.spec.ts +160 -0
  195. package/src/middleware/cache.ts +67 -0
  196. package/src/middleware/envelope.ts +136 -0
  197. package/src/middleware/error-guard.ts +69 -0
  198. package/src/middleware/index.ts +37 -0
  199. package/src/middleware/metrics.ts +810 -0
  200. package/src/middleware/mock-mode.ts +44 -0
  201. package/src/middleware/prom-metrics.ts +284 -0
  202. package/src/middleware/rate-limit-routes.ts +73 -0
  203. package/src/middleware/rate-limit.ts +72 -0
  204. package/src/middleware/request-id.ts +41 -0
  205. package/src/middleware/request-timeout.ts +69 -0
  206. package/src/middleware/security-headers.ts +24 -0
  207. package/src/middleware/startup-guard.ts +107 -0
  208. package/src/observability/service-contract.ts +192 -0
  209. package/src/plugins/index.ts +118 -0
  210. package/src/routes/__tests__/adapters-date-helpers.spec.ts +332 -0
  211. package/src/routes/__tests__/adapters.spec.ts +680 -0
  212. package/src/routes/__tests__/cache.spec.ts +264 -0
  213. package/src/routes/__tests__/events.spec.ts +434 -0
  214. package/src/routes/__tests__/health.spec.ts +414 -0
  215. package/src/routes/__tests__/logs.spec.ts +494 -0
  216. package/src/routes/__tests__/observability.spec.ts +392 -0
  217. package/src/routes/__tests__/plugins.spec.ts +931 -0
  218. package/src/routes/__tests__/workflow-management.spec.ts +698 -0
  219. package/src/routes/__tests__/workflows.spec.ts +204 -0
  220. package/src/routes/adapter-call.ts +220 -0
  221. package/src/routes/adapters.ts +1206 -0
  222. package/src/routes/analytics.ts +328 -0
  223. package/src/routes/cache.ts +104 -0
  224. package/src/routes/debug-routes.ts +95 -0
  225. package/src/routes/events.ts +115 -0
  226. package/src/routes/health.ts +348 -0
  227. package/src/routes/hello.ts +47 -0
  228. package/src/routes/index.ts +395 -0
  229. package/src/routes/jobs.ts +253 -0
  230. package/src/routes/logs.ts +718 -0
  231. package/src/routes/metrics.ts +120 -0
  232. package/src/routes/observability.ts +1388 -0
  233. package/src/routes/openapi.ts +101 -0
  234. package/src/routes/platform.ts +143 -0
  235. package/src/routes/plugins.ts +998 -0
  236. package/src/routes/readiness.ts +83 -0
  237. package/src/routes/workflow-management.ts +469 -0
  238. package/src/routes/workflows.ts +256 -0
  239. package/src/server.ts +203 -0
  240. package/src/services/historical-metrics.ts +496 -0
  241. package/src/services/incident-analyzer.ts +289 -0
  242. package/src/services/incident-detector.ts +691 -0
  243. package/src/services/incident-schema.sql +76 -0
  244. package/src/services/incident-storage.ts +593 -0
  245. package/src/services/system-metrics-collector.ts +244 -0
  246. package/src/types/fastify.d.ts +58 -0
  247. package/src/utils/__tests__/sse-auth.spec.ts +113 -0
  248. package/src/utils/path-helpers.ts +15 -0
  249. package/src/utils/repo.ts +42 -0
  250. package/src/utils/schema.ts +20 -0
  251. package/src/utils/sse-auth.ts +81 -0
  252. package/test-sandbox.sh +105 -0
  253. package/tsconfig.build.json +15 -0
  254. package/tsconfig.json +9 -0
  255. package/tsup.config.ts +18 -0
@@ -0,0 +1,328 @@
1
+ /**
2
+ * @module @kb-labs/rest-api-app/routes/analytics
3
+ * Analytics endpoints for querying events, stats, and monitoring
4
+ */
5
+
6
+ import type { FastifyInstance } from 'fastify';
7
+ import type { RestApiConfig } from '@kb-labs/rest-api-core';
8
+ import { normalizeBasePath, resolvePaths } from '../utils/path-helpers';
9
+ import { platform } from '@kb-labs/core-runtime';
10
+ import { restDomainOperationMetrics } from '../middleware/metrics.js';
11
+ import type {
12
+ EventsQuery,
13
+ EventsResponse,
14
+ EventsStats,
15
+ BufferStatus,
16
+ DlqStatus,
17
+ } from '@kb-labs/core-platform/adapters';
18
+
19
+ /**
20
+ * Register analytics routes
21
+ *
22
+ * These are system-level analytics endpoints that expose events and statistics
23
+ * from the platform's analytics adapter (if configured).
24
+ *
25
+ * Returns 501 Not Implemented if analytics adapter doesn't support read methods.
26
+ */
27
+ export async function registerAnalyticsRoutes(
28
+ fastify: FastifyInstance,
29
+ config: RestApiConfig
30
+ ): Promise<void> {
31
+ const basePath = normalizeBasePath(config.basePath);
32
+
33
+ // GET /api/v1/analytics/events
34
+ // Query analytics events with optional filters
35
+ const eventsPaths = resolvePaths(basePath, '/analytics/events');
36
+ for (const path of eventsPaths) {
37
+ fastify.get<{
38
+ Querystring: {
39
+ type?: string | string[];
40
+ source?: string;
41
+ actor?: string;
42
+ from?: string;
43
+ to?: string;
44
+ limit?: string;
45
+ offset?: string;
46
+ };
47
+ }>(path, async (request, reply) => {
48
+ try {
49
+ const analytics = platform.analytics;
50
+
51
+ // Check if analytics adapter supports read methods
52
+ const getEvents = analytics.getEvents;
53
+ if (!getEvents) {
54
+ fastify.log.debug('Analytics adapter does not implement getEvents()');
55
+ return reply.code(501).send({
56
+ ok: false,
57
+ error: {
58
+ code: 'ANALYTICS_NOT_IMPLEMENTED',
59
+ message: 'Analytics adapter does not support reading events',
60
+ },
61
+ });
62
+ }
63
+
64
+ // Build query from request params
65
+ const query: EventsQuery = {};
66
+
67
+ if (request.query.type !== undefined) {
68
+ query.type = request.query.type;
69
+ }
70
+ if (request.query.source) {
71
+ query.source = request.query.source;
72
+ }
73
+ if (request.query.actor) {
74
+ query.actor = request.query.actor;
75
+ }
76
+ if (request.query.from) {
77
+ query.from = request.query.from;
78
+ }
79
+ if (request.query.to) {
80
+ query.to = request.query.to;
81
+ }
82
+ if (request.query.limit) {
83
+ query.limit = Number.parseInt(request.query.limit, 10);
84
+ }
85
+ if (request.query.offset) {
86
+ query.offset = Number.parseInt(request.query.offset, 10);
87
+ }
88
+
89
+ fastify.log.debug({ query }, 'Fetching analytics events');
90
+
91
+ const response: EventsResponse = await restDomainOperationMetrics.observeOperation(
92
+ 'analytics.events.query',
93
+ () => getEvents.call(analytics, query),
94
+ );
95
+
96
+ fastify.log.debug(
97
+ {
98
+ total: response.total,
99
+ count: response.events.length,
100
+ hasMore: response.hasMore,
101
+ },
102
+ 'Analytics events fetched successfully'
103
+ );
104
+
105
+ return {
106
+ ok: true,
107
+ data: response,
108
+ meta: {
109
+ source: 'analytics-adapter',
110
+ },
111
+ };
112
+ } catch (error) {
113
+ platform.logger.error('Failed to fetch analytics events', error instanceof Error ? error : new Error(String(error)));
114
+
115
+ return reply.code(500).send({
116
+ ok: false,
117
+ error: {
118
+ code: 'ANALYTICS_ERROR',
119
+ message: error instanceof Error ? error.message : 'Failed to fetch analytics events',
120
+ },
121
+ });
122
+ }
123
+ });
124
+ }
125
+
126
+ // GET /api/v1/analytics/stats
127
+ // Get aggregated statistics
128
+ const statsPaths = resolvePaths(basePath, '/analytics/stats');
129
+ for (const path of statsPaths) {
130
+ fastify.get(path, async (_request, reply) => {
131
+ try {
132
+ const analytics = platform.analytics;
133
+
134
+ const getStats = analytics.getStats;
135
+ if (!getStats) {
136
+ fastify.log.debug('Analytics adapter does not implement getStats()');
137
+ return reply.code(501).send({
138
+ ok: false,
139
+ error: {
140
+ code: 'ANALYTICS_NOT_IMPLEMENTED',
141
+ message: 'Analytics adapter does not support reading stats',
142
+ },
143
+ });
144
+ }
145
+
146
+ fastify.log.debug('Fetching analytics stats');
147
+
148
+ // Cache stats for 60 seconds to avoid reprocessing 50k+ events on every request
149
+ const cacheKey = 'analytics:stats';
150
+ let stats = await platform.cache.get<EventsStats>(cacheKey);
151
+
152
+ if (!stats) {
153
+ fastify.log.debug('Cache miss, fetching stats from adapter');
154
+ stats = await restDomainOperationMetrics.observeOperation('analytics.stats.get', () => getStats.call(analytics));
155
+ await platform.cache.set(cacheKey, stats, 60 * 1000); // 60 second TTL
156
+ } else {
157
+ fastify.log.debug('Cache hit, returning cached stats');
158
+ }
159
+
160
+ fastify.log.debug(
161
+ {
162
+ totalEvents: stats.totalEvents,
163
+ timeRange: stats.timeRange,
164
+ },
165
+ 'Analytics stats fetched successfully'
166
+ );
167
+
168
+ return {
169
+ ok: true,
170
+ data: stats,
171
+ meta: {
172
+ source: 'analytics-adapter',
173
+ },
174
+ };
175
+ } catch (error) {
176
+ platform.logger.error('Failed to fetch analytics stats', error instanceof Error ? error : new Error(String(error)));
177
+
178
+ return reply.code(500).send({
179
+ ok: false,
180
+ error: {
181
+ code: 'ANALYTICS_ERROR',
182
+ message: error instanceof Error ? error.message : 'Failed to fetch analytics stats',
183
+ },
184
+ });
185
+ }
186
+ });
187
+ }
188
+
189
+ // GET /api/v1/analytics/buffer/status
190
+ // Get WAL buffer status (if applicable)
191
+ const bufferPaths = resolvePaths(basePath, '/analytics/buffer/status');
192
+ for (const path of bufferPaths) {
193
+ fastify.get(path, async (_request, reply) => {
194
+ try {
195
+ const analytics = platform.analytics;
196
+
197
+ const getBufferStatus = analytics.getBufferStatus;
198
+ if (!getBufferStatus) {
199
+ fastify.log.debug('Analytics adapter does not implement getBufferStatus()');
200
+ return reply.code(501).send({
201
+ ok: false,
202
+ error: {
203
+ code: 'ANALYTICS_NOT_IMPLEMENTED',
204
+ message: 'Analytics adapter does not support buffer status',
205
+ },
206
+ });
207
+ }
208
+
209
+ fastify.log.debug('Fetching analytics buffer status');
210
+
211
+ const status: BufferStatus | null = await restDomainOperationMetrics.observeOperation(
212
+ 'analytics.buffer.status',
213
+ () => getBufferStatus.call(analytics),
214
+ );
215
+
216
+ if (status === null) {
217
+ fastify.log.debug('Buffer status not applicable for current analytics backend');
218
+ return reply.code(501).send({
219
+ ok: false,
220
+ error: {
221
+ code: 'BUFFER_NOT_APPLICABLE',
222
+ message: 'Buffer status not applicable for current analytics backend',
223
+ },
224
+ });
225
+ }
226
+
227
+ fastify.log.debug(
228
+ {
229
+ segments: status.segments,
230
+ totalSizeBytes: status.totalSizeBytes,
231
+ },
232
+ 'Analytics buffer status fetched successfully'
233
+ );
234
+
235
+ return {
236
+ ok: true,
237
+ data: status,
238
+ meta: {
239
+ source: 'analytics-adapter',
240
+ },
241
+ };
242
+ } catch (error) {
243
+ platform.logger.error('Failed to fetch analytics buffer status', error instanceof Error ? error : new Error(String(error)));
244
+
245
+ return reply.code(500).send({
246
+ ok: false,
247
+ error: {
248
+ code: 'ANALYTICS_ERROR',
249
+ message:
250
+ error instanceof Error
251
+ ? error.message
252
+ : 'Failed to fetch analytics buffer status',
253
+ },
254
+ });
255
+ }
256
+ });
257
+ }
258
+
259
+ // GET /api/v1/analytics/dlq/status
260
+ // Get Dead-Letter Queue status (if applicable)
261
+ const dlqPaths = resolvePaths(basePath, '/analytics/dlq/status');
262
+ for (const path of dlqPaths) {
263
+ fastify.get(path, async (_request, reply) => {
264
+ try {
265
+ const analytics = platform.analytics;
266
+
267
+ const getDlqStatus = analytics.getDlqStatus;
268
+ if (!getDlqStatus) {
269
+ fastify.log.debug('Analytics adapter does not implement getDlqStatus()');
270
+ return reply.code(501).send({
271
+ ok: false,
272
+ error: {
273
+ code: 'ANALYTICS_NOT_IMPLEMENTED',
274
+ message: 'Analytics adapter does not support DLQ status',
275
+ },
276
+ });
277
+ }
278
+
279
+ fastify.log.debug('Fetching analytics DLQ status');
280
+
281
+ const status: DlqStatus | null = await restDomainOperationMetrics.observeOperation(
282
+ 'analytics.dlq.status',
283
+ () => getDlqStatus.call(analytics),
284
+ );
285
+
286
+ if (status === null) {
287
+ fastify.log.debug('DLQ status not applicable for current analytics backend');
288
+ return reply.code(501).send({
289
+ ok: false,
290
+ error: {
291
+ code: 'DLQ_NOT_APPLICABLE',
292
+ message: 'DLQ status not applicable for current analytics backend',
293
+ },
294
+ });
295
+ }
296
+
297
+ fastify.log.debug(
298
+ {
299
+ failedEvents: status.failedEvents,
300
+ oldestFailureTs: status.oldestFailureTs,
301
+ },
302
+ 'Analytics DLQ status fetched successfully'
303
+ );
304
+
305
+ return {
306
+ ok: true,
307
+ data: status,
308
+ meta: {
309
+ source: 'analytics-adapter',
310
+ },
311
+ };
312
+ } catch (error) {
313
+ platform.logger.error('Failed to fetch analytics DLQ status', error instanceof Error ? error : new Error(String(error)));
314
+
315
+ return reply.code(500).send({
316
+ ok: false,
317
+ error: {
318
+ code: 'ANALYTICS_ERROR',
319
+ message:
320
+ error instanceof Error ? error.message : 'Failed to fetch analytics DLQ status',
321
+ },
322
+ });
323
+ }
324
+ });
325
+ }
326
+
327
+ fastify.log.info('Analytics routes registered');
328
+ }
@@ -0,0 +1,104 @@
1
+ import { platform } from '@kb-labs/core-runtime';
2
+ /**
3
+ * @module @kb-labs/rest-api-app/routes/cache
4
+ * Cache management routes
5
+ */
6
+
7
+ import type { FastifyInstance } from 'fastify';
8
+ import type { RestApiConfig } from '@kb-labs/rest-api-core';
9
+ import type { IEntityRegistry } from '@kb-labs/core-registry';
10
+ import { normalizeBasePath } from '../utils/path-helpers';
11
+ import { restDomainOperationMetrics } from '../middleware/metrics.js';
12
+
13
+ /**
14
+ * Register cache management routes
15
+ */
16
+ export async function registerCacheRoutes(
17
+ server: FastifyInstance,
18
+ config: RestApiConfig,
19
+ registry: IEntityRegistry
20
+ ): Promise<void> {
21
+ const basePath = normalizeBasePath(config.basePath);
22
+
23
+ /**
24
+ * POST /api/v1/cache/invalidate
25
+ * Force cache invalidation and registry refresh
26
+ */
27
+ server.post(`${basePath}/cache/invalidate`, async (request, reply) => {
28
+ const start = Date.now();
29
+
30
+ try {
31
+ // Capture current state
32
+ const beforeSnapshot = registry.snapshot();
33
+ const previousRev = beforeSnapshot.rev;
34
+
35
+ platform.logger.info('Manual cache invalidation requested', {
36
+ requestId: request.id,
37
+ previousRev,
38
+ });
39
+ // Force cache invalidation and refresh discovery
40
+ // This will trigger re-discovery and clear stale cache
41
+ await restDomainOperationMetrics.observeOperation('cache.invalidate', async () => {
42
+ await registry.refresh();
43
+ });
44
+
45
+ // Get new state
46
+ const afterSnapshot = await restDomainOperationMetrics.observeOperation('plugin.registry.snapshot', async () =>
47
+ registry.snapshot(),
48
+ );
49
+ const plugins = await restDomainOperationMetrics.observeOperation('plugin.registry.list', async () =>
50
+ registry.listPlugins(),
51
+ );
52
+
53
+ const elapsed = Date.now() - start;
54
+
55
+ platform.logger.info('Cache invalidated successfully', {
56
+ requestId: request.id,
57
+ previousRev,
58
+ newRev: afterSnapshot.rev,
59
+ pluginsDiscovered: plugins.length,
60
+ elapsedMs: elapsed,
61
+ });
62
+
63
+ return reply.code(200).send({
64
+ ok: true,
65
+ data: {
66
+ invalidated: true,
67
+ timestamp: new Date().toISOString(),
68
+ previousRev,
69
+ newRev: afterSnapshot.rev,
70
+ pluginsDiscovered: plugins.length,
71
+ },
72
+ meta: {
73
+ requestId: request.id,
74
+ durationMs: elapsed,
75
+ apiVersion: '1.0.0',
76
+ },
77
+ });
78
+ } catch (error) {
79
+ const elapsed = Date.now() - start;
80
+
81
+ platform.logger.error(
82
+ 'Cache invalidation failed',
83
+ error instanceof Error ? error : new Error(String(error)),
84
+ {
85
+ requestId: request.id as string,
86
+ elapsedMs: elapsed,
87
+ }
88
+ );
89
+
90
+ return reply.code(500).send({
91
+ ok: false,
92
+ error: {
93
+ code: 'CACHE_INVALIDATION_FAILED',
94
+ message: error instanceof Error ? error.message : 'Cache invalidation failed',
95
+ },
96
+ meta: {
97
+ requestId: request.id,
98
+ durationMs: elapsed,
99
+ apiVersion: '1.0.0',
100
+ },
101
+ });
102
+ }
103
+ });
104
+ }
@@ -0,0 +1,95 @@
1
+ /**
2
+ * @module @kb-labs/rest-api-app/routes/debug-routes
3
+ * Debug endpoint to list all registered routes
4
+ *
5
+ * GET /api/v1/routes - List all registered routes with methods
6
+ */
7
+
8
+ import type { FastifyInstance, RouteOptions } from 'fastify';
9
+ import type { RestApiConfig } from '@kb-labs/rest-api-core';
10
+ import { normalizeBasePath, resolvePaths } from '../utils/path-helpers';
11
+
12
+ interface RouteInfo {
13
+ method: string;
14
+ url: string;
15
+ }
16
+
17
+ // Store for collected routes (populated via onRoute hook)
18
+ const collectedRoutes: RouteInfo[] = [];
19
+ const seenRoutes = new Set<string>();
20
+
21
+ /**
22
+ * Hook to collect routes as they are registered
23
+ */
24
+ function collectRoute(routeOptions: RouteOptions): void {
25
+ const methods = Array.isArray(routeOptions.method)
26
+ ? routeOptions.method
27
+ : [routeOptions.method];
28
+
29
+ for (const method of methods) {
30
+ // Skip HEAD (auto-generated for GET routes) and internal routes
31
+ if (method === 'HEAD') {continue;}
32
+
33
+ const url = routeOptions.url;
34
+ const key = `${method}:${url}`;
35
+
36
+ if (!seenRoutes.has(key)) {
37
+ seenRoutes.add(key);
38
+ collectedRoutes.push({ method, url });
39
+ }
40
+ }
41
+ }
42
+
43
+ /**
44
+ * Register the onRoute hook to collect routes
45
+ * Must be called early, before other routes are registered
46
+ */
47
+ export function registerRouteCollector(fastify: FastifyInstance): void {
48
+ fastify.addHook('onRoute', collectRoute);
49
+ }
50
+
51
+ /**
52
+ * Register debug routes endpoint
53
+ */
54
+ export async function registerDebugRoutes(
55
+ fastify: FastifyInstance,
56
+ config: RestApiConfig
57
+ ): Promise<void> {
58
+ const basePath = normalizeBasePath(config.basePath);
59
+ const routesPaths = resolvePaths(basePath, '/routes');
60
+
61
+ for (const path of routesPaths) {
62
+ fastify.get(path, async (_request, reply) => {
63
+ // Filter to only show /api/v1 routes (skip duplicates without prefix)
64
+ let routes = collectedRoutes.filter(r => r.url.startsWith('/api/'));
65
+
66
+ // If no API routes found, show all (fallback)
67
+ if (routes.length === 0) {
68
+ routes = [...collectedRoutes];
69
+ }
70
+
71
+ // Sort routes by URL, then by method
72
+ routes.sort((a, b) => {
73
+ const urlCompare = a.url.localeCompare(b.url);
74
+ if (urlCompare !== 0) {return urlCompare;}
75
+ return a.method.localeCompare(b.method);
76
+ });
77
+
78
+ // Get raw printRoutes for debugging (optional)
79
+ let raw: string | null = null;
80
+ try {
81
+ raw = fastify.printRoutes({ commonPrefix: false });
82
+ } catch {
83
+ // Ignore if not available
84
+ }
85
+
86
+ return reply.send({
87
+ schema: 'kb.routes/1',
88
+ ts: new Date().toISOString(),
89
+ count: routes.length,
90
+ routes,
91
+ raw,
92
+ });
93
+ });
94
+ }
95
+ }
@@ -0,0 +1,115 @@
1
+ import type { FastifyInstance } from 'fastify';
2
+ import type { RestApiConfig } from '@kb-labs/rest-api-core';
3
+ import type { IEntityRegistry, SystemHealthSnapshot } from '@kb-labs/core-registry';
4
+ import type { ReadinessState } from './readiness';
5
+ import { isReady, resolveReadinessReason } from './readiness';
6
+ import type { EventHub, BroadcastEvent } from '../events/hub';
7
+ import { metricsCollector } from '../middleware/metrics.js';
8
+ import { buildRegistrySseAuthHook } from '../utils/sse-auth';
9
+
10
+ export async function registerEventRoutes(
11
+ server: FastifyInstance,
12
+ basePath: string,
13
+ registry: IEntityRegistry,
14
+ readiness: ReadinessState,
15
+ eventHub: EventHub,
16
+ config: RestApiConfig
17
+ ): Promise<void> {
18
+ const endpoint = `${basePath}/events/registry`;
19
+ const authHook = buildRegistrySseAuthHook(config);
20
+
21
+ server.route({
22
+ method: 'GET',
23
+ url: endpoint,
24
+ onRequest: authHook ? [authHook] : undefined,
25
+ handler: async (request, reply) => {
26
+ // Tell Fastify we're manually managing the response
27
+ reply.hijack();
28
+
29
+ // Explicit CORS headers for EventSource (browser requires these before opening connection)
30
+ const origin = request.headers.origin;
31
+ if (origin === 'http://localhost:3000' || origin === 'http://localhost:5173') {
32
+ reply.raw.setHeader('Access-Control-Allow-Origin', origin);
33
+ reply.raw.setHeader('Access-Control-Allow-Credentials', 'true');
34
+ }
35
+
36
+ reply.raw.setHeader('Content-Type', 'text/event-stream');
37
+ reply.raw.setHeader('Cache-Control', 'no-cache, no-transform');
38
+ reply.raw.setHeader('Connection', 'keep-alive');
39
+ reply.raw.flushHeaders?.();
40
+ reply.raw.write(': connected\n\n');
41
+
42
+ const send = (event: BroadcastEvent) => {
43
+ reply.raw.write(`event: ${event.type}\n`);
44
+ reply.raw.write(`data: ${JSON.stringify(event)}\n\n`);
45
+ };
46
+
47
+ const unsubscribe = eventHub.subscribe(send);
48
+
49
+ const snapshot = registry.snapshot();
50
+ const checksumAlgorithm = snapshot.checksumAlgorithm === 'sha256' ? 'sha256' : undefined;
51
+ send({
52
+ type: 'registry',
53
+ rev: snapshot.rev,
54
+ generatedAt: snapshot.generatedAt,
55
+ partial: snapshot.partial,
56
+ stale: snapshot.stale,
57
+ expiresAt: snapshot.expiresAt ?? null,
58
+ ttlMs: snapshot.ttlMs ?? null,
59
+ checksum: snapshot.checksum ?? undefined,
60
+ checksumAlgorithm,
61
+ previousChecksum: snapshot.previousChecksum ?? null,
62
+ });
63
+
64
+ const healthPromise = registry
65
+ .getSystemHealth()
66
+ .then((health: SystemHealthSnapshot) => {
67
+ const ready = isReady(readiness);
68
+ const reason = resolveReadinessReason(readiness);
69
+ const pluginSnapshot = metricsCollector.getLastPluginMountSnapshot();
70
+ const redisStatus = (registry as any).getRedisStatus?.();
71
+ send({
72
+ type: 'health',
73
+ status: health.status,
74
+ ts: health.ts,
75
+ ready,
76
+ reason,
77
+ registryPartial: readiness.registryPartial,
78
+ registryStale: readiness.registryStale,
79
+ registryLoaded: readiness.registryLoaded,
80
+ pluginMountInProgress: readiness.pluginMountInProgress,
81
+ pluginRoutesMounted: readiness.pluginRoutesMounted,
82
+ pluginsMounted: pluginSnapshot?.succeeded ?? 0,
83
+ pluginsFailed: pluginSnapshot?.failed ?? 0,
84
+ lastPluginMountTs: readiness.lastPluginMountTs ?? null,
85
+ pluginRoutesLastDurationMs: readiness.pluginRoutesLastDurationMs ?? null,
86
+ redisEnabled: redisStatus?.enabled ?? false,
87
+ redisHealthy: redisStatus?.healthy ?? true,
88
+ redisStates: redisStatus?.roles,
89
+ });
90
+ })
91
+ .catch((error: unknown) => {
92
+ if ((request as any).kbLogger) {
93
+ (request as any).kbLogger.warn('Failed to fetch system health for SSE client', { err: error });
94
+ }
95
+ });
96
+
97
+ await new Promise<void>((resolve) => {
98
+ request.raw.on('close', () => {
99
+ unsubscribe();
100
+ reply.raw.end();
101
+ resolve();
102
+ });
103
+ // In inject/test mode, the socket is not a real TCP socket and 'close' may not fire.
104
+ // Wait for health fetch to complete before resolving so health event is included in response.
105
+ if (request.raw.socket && !(request.raw.socket as any).writable) {
106
+ void healthPromise.then(() => {
107
+ unsubscribe();
108
+ reply.raw.end();
109
+ resolve();
110
+ });
111
+ }
112
+ });
113
+ },
114
+ });
115
+ }