@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,931 @@
1
+ import { beforeEach, describe, expect, it, vi, afterEach } from 'vitest';
2
+ import Fastify from 'fastify';
3
+ import type { IEntityRegistry, RegistrySnapshot } from '@kb-labs/core-registry';
4
+ import type { RestApiConfig } from '@kb-labs/rest-api-core';
5
+ import type { ManifestV3 } from '@kb-labs/plugin-contracts';
6
+ import {
7
+ registerPluginRoutes,
8
+ registerPluginSnapshotRoutes,
9
+ } from '../plugins';
10
+ import type { ReadinessState } from '../readiness';
11
+ import * as fs from 'node:fs/promises';
12
+ import { platform } from '@kb-labs/core-runtime';
13
+
14
+ // Mock dependencies
15
+ vi.mock('@kb-labs/plugin-execution/http', () => ({
16
+ mountRoutes: vi.fn().mockResolvedValue(undefined),
17
+ }));
18
+
19
+ vi.mock('@kb-labs/core-runtime', () => ({
20
+ platform: {
21
+ executionBackend: {
22
+ type: 'mock-backend',
23
+ },
24
+ shutdown: vi.fn().mockResolvedValue(undefined),
25
+ logger: {
26
+ trace: vi.fn(),
27
+ debug: vi.fn(),
28
+ info: vi.fn(),
29
+ warn: vi.fn(),
30
+ error: vi.fn(),
31
+ child: vi.fn().mockReturnThis(),
32
+ },
33
+ },
34
+ }));
35
+
36
+ vi.mock('@kb-labs/core-workspace', () => ({
37
+ resolveWorkspaceRoot: vi.fn().mockResolvedValue({
38
+ rootDir: '/mock/workspace',
39
+ source: 'KB_LABS_WORKSPACE_ROOT',
40
+ }),
41
+ }));
42
+
43
+ vi.mock('../../middleware/metrics', () => ({
44
+ metricsCollector: {
45
+ resetPluginRouteBudgets: vi.fn(),
46
+ beginPluginMount: vi.fn(() => ({
47
+ recordSuccess: vi.fn(),
48
+ recordFailure: vi.fn(),
49
+ })),
50
+ registerRouteBudget: vi.fn(),
51
+ completePluginMount: vi.fn(),
52
+ },
53
+ restDomainOperationMetrics: {
54
+ recordOperation: vi.fn(),
55
+ observeOperation: vi.fn(async (_operation: string, fn: () => unknown | Promise<unknown>) => fn()),
56
+ getTopOperations: vi.fn(() => []),
57
+ getMetricLines: vi.fn(() => []),
58
+ },
59
+ }));
60
+
61
+ vi.mock('node:fs/promises');
62
+
63
+ const BASE_CONFIG: RestApiConfig = {
64
+ port: 3000,
65
+ basePath: '/api/v1',
66
+ apiVersion: 'test',
67
+ cors: {
68
+ origins: [],
69
+ allowCredentials: true,
70
+ profile: 'dev',
71
+ },
72
+ plugins: [],
73
+ mockMode: false,
74
+ timeouts: {
75
+ requestTimeout: 30000,
76
+ bodyLimit: 10_485_760,
77
+ },
78
+ };
79
+
80
+ function createMockManifest(overrides: Partial<ManifestV3> = {}): ManifestV3 {
81
+ return {
82
+ schema: 'kb.plugin/3',
83
+ id: '@kb-labs/test-plugin',
84
+ version: '1.0.0',
85
+ display: {
86
+ name: 'Test Plugin',
87
+ description: 'A test plugin',
88
+ },
89
+ ...overrides,
90
+ } as ManifestV3;
91
+ }
92
+
93
+ function createMockReadinessState(): ReadinessState {
94
+ return {
95
+ cliApiInitialized: true,
96
+ registryLoaded: true,
97
+ registryPartial: false,
98
+ registryStale: false,
99
+ pluginRoutesMounted: false,
100
+ pluginMountInProgress: false,
101
+ pluginRoutesCount: 0,
102
+ pluginRouteErrors: 0,
103
+ pluginRouteFailures: [],
104
+ lastPluginMountTs: null,
105
+ pluginRoutesLastDurationMs: null,
106
+ redisEnabled: false,
107
+ redisConnected: false,
108
+ redisStates: {
109
+ publisher: null,
110
+ subscriber: null,
111
+ cache: null,
112
+ },
113
+ };
114
+ }
115
+
116
+ function createMockSnapshot(manifests: Array<{
117
+ pluginId: string;
118
+ manifest: ManifestV3;
119
+ pluginRoot: string;
120
+ source?: string;
121
+ }>, options?: {
122
+ diagnostics?: Array<{
123
+ severity: 'error' | 'warning' | 'info' | 'debug';
124
+ code: string;
125
+ message: string;
126
+ pluginId?: string;
127
+ filePath?: string;
128
+ remediation?: string;
129
+ ts?: number;
130
+ }>;
131
+ }): RegistrySnapshot {
132
+ return {
133
+ schema: 'kb.registry/1',
134
+ rev: 1,
135
+ version: '1.0.0',
136
+ generatedAt: new Date().toISOString(),
137
+ expiresAt: new Date(Date.now() + 60_000).toISOString(),
138
+ ttlMs: 60_000,
139
+ partial: false,
140
+ stale: false,
141
+ source: { platformVersion: 'test', cwd: process.cwd() },
142
+ corrupted: false,
143
+ plugins: [],
144
+ ts: Date.now(),
145
+ manifests: manifests.map((entry) => ({
146
+ pluginId: entry.pluginId,
147
+ manifest: entry.manifest,
148
+ pluginRoot: entry.pluginRoot,
149
+ source: { kind: 'local' as const, path: entry.source ?? 'test' },
150
+ })),
151
+ diagnostics: options?.diagnostics?.map((diagnostic) => ({
152
+ severity: diagnostic.severity,
153
+ code: diagnostic.code,
154
+ message: diagnostic.message,
155
+ context: diagnostic.pluginId || diagnostic.filePath ? {
156
+ pluginId: diagnostic.pluginId,
157
+ filePath: diagnostic.filePath,
158
+ } : undefined,
159
+ remediation: diagnostic.remediation,
160
+ ts: diagnostic.ts ?? Date.now(),
161
+ })),
162
+ };
163
+ }
164
+
165
+ describe('registerPluginRoutes', () => {
166
+ let app: ReturnType<typeof Fastify>;
167
+ let readiness: ReadinessState;
168
+ let fsAccessMock: any;
169
+
170
+ beforeEach(async () => {
171
+ vi.clearAllMocks();
172
+ app = Fastify({ logger: false });
173
+ readiness = createMockReadinessState();
174
+
175
+ // Mock fs.access to simulate file existence
176
+ fsAccessMock = vi.mocked(fs.access);
177
+ fsAccessMock.mockResolvedValue(undefined);
178
+ });
179
+
180
+ afterEach(async () => {
181
+ await app.close();
182
+ });
183
+
184
+ it('successfully mounts plugin routes with REST endpoints', async () => {
185
+ const manifest = createMockManifest({
186
+ rest: {
187
+ basePath: '/v1/plugins/test-plugin',
188
+ routes: [
189
+ {
190
+ method: 'GET',
191
+ path: '/hello',
192
+ description: 'Say hello',
193
+ handler: './dist/handlers/hello.js#default',
194
+ },
195
+ {
196
+ method: 'POST',
197
+ path: '/echo',
198
+ description: 'Echo input',
199
+ handler: './dist/handlers/echo.js#echoHandler',
200
+ },
201
+ ],
202
+ },
203
+ });
204
+
205
+ const snapshot = createMockSnapshot([
206
+ {
207
+ pluginId: '@kb-labs/test-plugin',
208
+ manifest,
209
+ pluginRoot: '/mock/plugins/test',
210
+ },
211
+ ]);
212
+
213
+ const cliApi = {
214
+ snapshot: vi.fn(() => snapshot),
215
+ } as unknown as IEntityRegistry;
216
+
217
+ await registerPluginRoutes(
218
+ app,
219
+ BASE_CONFIG,
220
+ '/mock/repo',
221
+ cliApi,
222
+ readiness
223
+ );
224
+
225
+ expect(readiness.pluginRoutesMounted).toBe(true);
226
+ expect(readiness.pluginRoutesCount).toBe(2);
227
+ expect(readiness.pluginRouteErrors).toBe(0);
228
+ expect(readiness.pluginRouteFailures).toEqual([]);
229
+ expect(readiness.pluginMountInProgress).toBe(false);
230
+ expect(readiness.pluginRoutesLastDurationMs).toBeGreaterThan(0);
231
+ });
232
+
233
+ it('handles plugins without REST routes', async () => {
234
+ const manifest = createMockManifest({
235
+ // No rest configuration
236
+ });
237
+
238
+ const snapshot = createMockSnapshot([
239
+ {
240
+ pluginId: '@kb-labs/cli-only',
241
+ manifest,
242
+ pluginRoot: '/mock/plugins/cli-only',
243
+ },
244
+ ]);
245
+
246
+ const cliApi = {
247
+ snapshot: vi.fn(() => snapshot),
248
+ } as unknown as IEntityRegistry;
249
+
250
+ await registerPluginRoutes(
251
+ app,
252
+ BASE_CONFIG,
253
+ '/mock/repo',
254
+ cliApi,
255
+ readiness
256
+ );
257
+
258
+ expect(readiness.pluginRoutesMounted).toBe(true);
259
+ expect(readiness.pluginRoutesCount).toBe(0);
260
+ expect(readiness.pluginRouteErrors).toBe(0);
261
+ });
262
+
263
+ it('validates handler file existence and skips missing handlers', async () => {
264
+ fsAccessMock.mockImplementation((filePath: string) => {
265
+ if (filePath.includes('missing-handler.js')) {
266
+ return Promise.reject(new Error('File not found'));
267
+ }
268
+ return Promise.resolve();
269
+ });
270
+
271
+ const manifest = createMockManifest({
272
+ rest: {
273
+ routes: [
274
+ {
275
+ method: 'GET',
276
+ path: '/valid',
277
+ handler: './dist/handlers/valid.js#default',
278
+ },
279
+ {
280
+ method: 'POST',
281
+ path: '/invalid',
282
+ handler: './dist/handlers/missing-handler.js#default',
283
+ },
284
+ ],
285
+ },
286
+ });
287
+
288
+ const snapshot = createMockSnapshot([
289
+ {
290
+ pluginId: '@kb-labs/test-plugin',
291
+ manifest,
292
+ pluginRoot: '/mock/plugins/test',
293
+ },
294
+ ]);
295
+
296
+ const cliApi = {
297
+ snapshot: vi.fn(() => snapshot),
298
+ } as unknown as IEntityRegistry;
299
+
300
+ await registerPluginRoutes(
301
+ app,
302
+ BASE_CONFIG,
303
+ '/mock/repo',
304
+ cliApi,
305
+ readiness
306
+ );
307
+
308
+ // Should mount only valid routes
309
+ expect(readiness.pluginRoutesMounted).toBe(true);
310
+ expect(readiness.pluginRoutesCount).toBe(1);
311
+ expect(readiness.pluginRouteErrors).toBe(0);
312
+ expect(platform.logger.warn).toHaveBeenCalledWith(
313
+ 'Plugin route validation failed',
314
+ expect.objectContaining({
315
+ diagnosticEvent: 'plugin.routes.validation',
316
+ reasonCode: 'handler_not_found',
317
+ pluginId: '@kb-labs/test-plugin',
318
+ }),
319
+ );
320
+ });
321
+
322
+ it('handles invalid handler references gracefully', async () => {
323
+ const manifest = createMockManifest({
324
+ rest: {
325
+ routes: [
326
+ {
327
+ method: 'GET',
328
+ path: '/broken',
329
+ handler: '', // Invalid: empty handler
330
+ },
331
+ ],
332
+ },
333
+ });
334
+
335
+ const snapshot = createMockSnapshot([
336
+ {
337
+ pluginId: '@kb-labs/broken-plugin',
338
+ manifest,
339
+ pluginRoot: '/mock/plugins/broken',
340
+ },
341
+ ]);
342
+
343
+ const cliApi = {
344
+ snapshot: vi.fn(() => snapshot),
345
+ } as unknown as IEntityRegistry;
346
+
347
+ await registerPluginRoutes(
348
+ app,
349
+ BASE_CONFIG,
350
+ '/mock/repo',
351
+ cliApi,
352
+ readiness
353
+ );
354
+
355
+ // Should skip plugin entirely due to validation errors
356
+ expect(readiness.pluginRoutesCount).toBe(0);
357
+ expect(readiness.pluginRouteErrors).toBe(1);
358
+ expect(readiness.pluginRouteFailures).toHaveLength(1);
359
+ expect(readiness.pluginRouteFailures[0]?.error).toContain('rest_validation_failed');
360
+ expect(platform.logger.error).toHaveBeenCalledWith(
361
+ 'All plugin routes failed validation; skipping plugin',
362
+ undefined,
363
+ expect.objectContaining({
364
+ diagnosticEvent: 'plugin.routes.validation',
365
+ reasonCode: 'route_validation_failed',
366
+ pluginId: '@kb-labs/test-plugin',
367
+ }),
368
+ );
369
+ });
370
+
371
+ it('mounts multiple plugins in parallel', async () => {
372
+ const plugin1 = createMockManifest({
373
+ id: '@kb-labs/plugin-1',
374
+ rest: {
375
+ routes: [
376
+ { method: 'GET', path: '/one', handler: './dist/one.js#default' },
377
+ ],
378
+ },
379
+ });
380
+
381
+ const plugin2 = createMockManifest({
382
+ id: '@kb-labs/plugin-2',
383
+ rest: {
384
+ routes: [
385
+ { method: 'POST', path: '/two', handler: './dist/two.js#default' },
386
+ { method: 'PUT', path: '/three', handler: './dist/three.js#default' },
387
+ ],
388
+ },
389
+ });
390
+
391
+ const snapshot = createMockSnapshot([
392
+ { pluginId: '@kb-labs/plugin-1', manifest: plugin1, pluginRoot: '/mock/p1' },
393
+ { pluginId: '@kb-labs/plugin-2', manifest: plugin2, pluginRoot: '/mock/p2' },
394
+ ]);
395
+
396
+ const cliApi = {
397
+ snapshot: vi.fn(() => snapshot),
398
+ } as unknown as IEntityRegistry;
399
+
400
+ await registerPluginRoutes(
401
+ app,
402
+ BASE_CONFIG,
403
+ '/mock/repo',
404
+ cliApi,
405
+ readiness
406
+ );
407
+
408
+ expect(readiness.pluginRoutesMounted).toBe(true);
409
+ expect(readiness.pluginRoutesCount).toBe(3); // 1 + 2
410
+ expect(readiness.pluginRouteErrors).toBe(0);
411
+ });
412
+
413
+ it('continues mounting other plugins when one fails', async () => {
414
+ const { mountRoutes } = await import('@kb-labs/plugin-execution/http');
415
+ const mountRoutesMock = vi.mocked(mountRoutes);
416
+
417
+ // Make first plugin fail, second succeed
418
+ mountRoutesMock
419
+ .mockRejectedValueOnce(new Error('Mount failed for plugin-1'))
420
+ .mockResolvedValueOnce(undefined);
421
+
422
+ const plugin1 = createMockManifest({
423
+ id: '@kb-labs/failing-plugin',
424
+ rest: {
425
+ routes: [{ method: 'GET', path: '/fail', handler: './dist/fail.js#default' }],
426
+ },
427
+ });
428
+
429
+ const plugin2 = createMockManifest({
430
+ id: '@kb-labs/working-plugin',
431
+ rest: {
432
+ routes: [{ method: 'GET', path: '/work', handler: './dist/work.js#default' }],
433
+ },
434
+ });
435
+
436
+ const snapshot = createMockSnapshot([
437
+ { pluginId: '@kb-labs/failing-plugin', manifest: plugin1, pluginRoot: '/mock/p1' },
438
+ { pluginId: '@kb-labs/working-plugin', manifest: plugin2, pluginRoot: '/mock/p2' },
439
+ ]);
440
+
441
+ const cliApi = {
442
+ snapshot: vi.fn(() => snapshot),
443
+ } as unknown as IEntityRegistry;
444
+
445
+ await registerPluginRoutes(
446
+ app,
447
+ BASE_CONFIG,
448
+ '/mock/repo',
449
+ cliApi,
450
+ readiness
451
+ );
452
+
453
+ expect(readiness.pluginRoutesCount).toBe(1); // Only plugin2 succeeded
454
+ expect(readiness.pluginRouteErrors).toBe(1);
455
+ expect(readiness.pluginRouteFailures).toHaveLength(1);
456
+ expect(readiness.pluginRouteFailures[0]?.id).toBe('@kb-labs/failing-plugin');
457
+ });
458
+
459
+ it('handles partial/stale registry snapshots', async () => {
460
+ const manifest = createMockManifest({
461
+ rest: {
462
+ routes: [{ method: 'GET', path: '/test', handler: './dist/test.js#default' }],
463
+ },
464
+ });
465
+
466
+ const snapshot = createMockSnapshot([
467
+ { pluginId: '@kb-labs/test', manifest, pluginRoot: '/mock/test' },
468
+ ]);
469
+ snapshot.partial = true;
470
+ snapshot.stale = true;
471
+
472
+ const cliApi = {
473
+ snapshot: vi.fn(() => snapshot),
474
+ } as unknown as IEntityRegistry;
475
+
476
+ await registerPluginRoutes(
477
+ app,
478
+ BASE_CONFIG,
479
+ '/mock/repo',
480
+ cliApi,
481
+ readiness
482
+ );
483
+
484
+ // Should still mount routes but log warnings
485
+ expect(readiness.pluginRoutesMounted).toBe(true);
486
+ expect(readiness.pluginRoutesCount).toBe(1);
487
+ expect(platform.logger.warn).toHaveBeenCalledWith(
488
+ 'Registry snapshot is partial',
489
+ expect.objectContaining({
490
+ diagnosticEvent: 'plugin.registry.snapshot',
491
+ reasonCode: 'snapshot_partial',
492
+ serviceId: 'rest',
493
+ }),
494
+ );
495
+ expect(platform.logger.warn).toHaveBeenCalledWith(
496
+ 'Registry snapshot is stale',
497
+ expect.objectContaining({
498
+ diagnosticEvent: 'plugin.registry.snapshot',
499
+ reasonCode: 'snapshot_stale',
500
+ serviceId: 'rest',
501
+ }),
502
+ );
503
+ });
504
+
505
+ it('uses custom basePath from manifest.rest.basePath', async () => {
506
+ const { mountRoutes } = await import('@kb-labs/plugin-execution/http');
507
+ const mountRoutesMock = vi.mocked(mountRoutes);
508
+
509
+ const manifest = createMockManifest({
510
+ id: '@kb-labs/custom-base',
511
+ rest: {
512
+ basePath: '/v1/plugins/custom',
513
+ routes: [{ method: 'GET', path: '/test', handler: './dist/test.js#default' }],
514
+ },
515
+ });
516
+
517
+ const snapshot = createMockSnapshot([
518
+ { pluginId: '@kb-labs/custom-base', manifest, pluginRoot: '/mock/custom' },
519
+ ]);
520
+
521
+ const cliApi = {
522
+ snapshot: vi.fn(() => snapshot),
523
+ } as unknown as IEntityRegistry;
524
+
525
+ await registerPluginRoutes(
526
+ app,
527
+ BASE_CONFIG,
528
+ '/mock/repo',
529
+ cliApi,
530
+ readiness
531
+ );
532
+
533
+ expect(mountRoutesMock).toHaveBeenCalledWith(
534
+ expect.anything(),
535
+ expect.anything(),
536
+ expect.objectContaining({
537
+ basePath: '/api/v1/plugins/custom', // Should replace /v1 with config.basePath
538
+ })
539
+ );
540
+ });
541
+
542
+ it('falls back to default basePath when manifest does not specify one', async () => {
543
+ const { mountRoutes } = await import('@kb-labs/plugin-execution/http');
544
+ const mountRoutesMock = vi.mocked(mountRoutes);
545
+
546
+ const manifest = createMockManifest({
547
+ id: '@kb-labs/default-base',
548
+ rest: {
549
+ routes: [{ method: 'GET', path: '/test', handler: './dist/test.js#default' }],
550
+ },
551
+ });
552
+
553
+ const snapshot = createMockSnapshot([
554
+ { pluginId: '@kb-labs/default-base', manifest, pluginRoot: '/mock/default' },
555
+ ]);
556
+
557
+ const cliApi = {
558
+ snapshot: vi.fn(() => snapshot),
559
+ } as unknown as IEntityRegistry;
560
+
561
+ await registerPluginRoutes(
562
+ app,
563
+ BASE_CONFIG,
564
+ '/mock/repo',
565
+ cliApi,
566
+ readiness
567
+ );
568
+
569
+ expect(mountRoutesMock).toHaveBeenCalledWith(
570
+ expect.anything(),
571
+ expect.anything(),
572
+ expect.objectContaining({
573
+ basePath: '/api/v1/plugins/@kb-labs/default-base',
574
+ })
575
+ );
576
+ });
577
+
578
+ it('handles discovery failure gracefully', async () => {
579
+ const cliApi = {
580
+ snapshot: vi.fn(() => {
581
+ throw new Error('Registry unavailable');
582
+ }),
583
+ } as unknown as IEntityRegistry;
584
+
585
+ await registerPluginRoutes(
586
+ app,
587
+ BASE_CONFIG,
588
+ '/mock/repo',
589
+ cliApi,
590
+ readiness
591
+ );
592
+
593
+ expect(readiness.pluginRoutesMounted).toBe(false);
594
+ expect(readiness.pluginRoutesCount).toBe(0);
595
+ expect(readiness.pluginRouteErrors).toBe(1);
596
+ expect(readiness.pluginRouteFailures).toHaveLength(1);
597
+ expect(readiness.pluginRouteFailures[0]?.id).toBe('discovery');
598
+ });
599
+
600
+ it('works without readiness tracking', async () => {
601
+ const manifest = createMockManifest({
602
+ rest: {
603
+ routes: [{ method: 'GET', path: '/test', handler: './dist/test.js#default' }],
604
+ },
605
+ });
606
+
607
+ const snapshot = createMockSnapshot([
608
+ { pluginId: '@kb-labs/test', manifest, pluginRoot: '/mock/test' },
609
+ ]);
610
+
611
+ const cliApi = {
612
+ snapshot: vi.fn(() => snapshot),
613
+ } as unknown as IEntityRegistry;
614
+
615
+ // No readiness object passed
616
+ await expect(
617
+ registerPluginRoutes(app, BASE_CONFIG, '/mock/repo', cliApi)
618
+ ).resolves.not.toThrow();
619
+ });
620
+
621
+ it('registers route budgets for metrics tracking', async () => {
622
+ const { metricsCollector } = await import('../../middleware/metrics');
623
+ const registerBudgetMock = vi.mocked(metricsCollector.registerRouteBudget);
624
+
625
+ const manifest = createMockManifest({
626
+ id: '@kb-labs/metrics-test',
627
+ rest: {
628
+ basePath: '/v1/plugins/metrics',
629
+ routes: [
630
+ {
631
+ method: 'GET',
632
+ path: '/fast',
633
+ handler: './dist/fast.js#default',
634
+ timeoutMs: 5000,
635
+ },
636
+ {
637
+ method: 'POST',
638
+ path: '/slow',
639
+ handler: './dist/slow.js#default',
640
+ // Uses default timeout
641
+ },
642
+ ],
643
+ },
644
+ });
645
+
646
+ const snapshot = createMockSnapshot([
647
+ { pluginId: '@kb-labs/metrics-test', manifest, pluginRoot: '/mock/metrics' },
648
+ ]);
649
+
650
+ const cliApi = {
651
+ snapshot: vi.fn(() => snapshot),
652
+ } as unknown as IEntityRegistry;
653
+
654
+ await registerPluginRoutes(
655
+ app,
656
+ BASE_CONFIG,
657
+ '/mock/repo',
658
+ cliApi,
659
+ readiness
660
+ );
661
+
662
+ expect(registerBudgetMock).toHaveBeenCalledWith(
663
+ 'GET',
664
+ '/api/v1/plugins/metrics/fast',
665
+ 5000,
666
+ '@kb-labs/metrics-test'
667
+ );
668
+
669
+ expect(registerBudgetMock).toHaveBeenCalledWith(
670
+ 'POST',
671
+ '/api/v1/plugins/metrics/slow',
672
+ 30000, // Default from config
673
+ '@kb-labs/metrics-test'
674
+ );
675
+ });
676
+ });
677
+
678
+ describe('registerPluginSnapshotRoutes', () => {
679
+ let app: ReturnType<typeof Fastify>;
680
+
681
+ beforeEach(async () => {
682
+ vi.clearAllMocks();
683
+ app = Fastify({ logger: false });
684
+ });
685
+
686
+ afterEach(async () => {
687
+ await app.close();
688
+ });
689
+
690
+ it('logs a structured diagnostic when plugin registry refresh fails', async () => {
691
+ const cliApi = {
692
+ refresh: vi.fn(async () => {
693
+ throw new Error('Refresh exploded');
694
+ }),
695
+ snapshot: vi.fn(() => createMockSnapshot([])),
696
+ } as unknown as IEntityRegistry;
697
+
698
+ await registerPluginSnapshotRoutes(app, BASE_CONFIG, cliApi);
699
+
700
+ const response = await app.inject({
701
+ method: 'POST',
702
+ url: '/api/v1/plugins/refresh',
703
+ });
704
+
705
+ expect(response.statusCode).toBe(500);
706
+ expect(platform.logger.error).toHaveBeenCalledWith(
707
+ 'Failed to refresh plugin registry',
708
+ expect.any(Error),
709
+ expect.objectContaining({
710
+ diagnosticEvent: 'plugin.registry.refresh',
711
+ reasonCode: 'registry_refresh_failed',
712
+ serviceId: 'rest',
713
+ }),
714
+ );
715
+ });
716
+
717
+ it('logs discovery diagnostics when plugin registry refresh succeeds with blocking issues', async () => {
718
+ const cliApi = {
719
+ refresh: vi.fn(async () => undefined),
720
+ snapshot: vi.fn(() => createMockSnapshot([], {
721
+ diagnostics: [{
722
+ severity: 'error',
723
+ code: 'INTEGRITY_MISMATCH',
724
+ message: 'Integrity mismatch for "@kb-labs/commit"',
725
+ pluginId: '@kb-labs/commit',
726
+ filePath: '/workspace/plugins/commit/package.json',
727
+ remediation: 'Re-install: kb marketplace install @kb-labs/commit',
728
+ }],
729
+ })),
730
+ } as unknown as IEntityRegistry;
731
+
732
+ await registerPluginSnapshotRoutes(app, BASE_CONFIG, cliApi);
733
+
734
+ const response = await app.inject({
735
+ method: 'POST',
736
+ url: '/api/v1/plugins/refresh',
737
+ });
738
+
739
+ expect(response.statusCode).toBe(200);
740
+ expect(platform.logger.error).toHaveBeenCalledWith(
741
+ 'Integrity mismatch for "@kb-labs/commit"',
742
+ undefined,
743
+ expect.objectContaining({
744
+ diagnosticEvent: 'plugin.discovery.diagnostic',
745
+ reasonCode: 'integrity_mismatch',
746
+ pluginId: '@kb-labs/commit',
747
+ serviceId: 'rest',
748
+ discoveryCode: 'INTEGRITY_MISMATCH',
749
+ }),
750
+ );
751
+ });
752
+
753
+ it('returns plugin registry from legacy endpoint', async () => {
754
+ const manifest1 = createMockManifest({
755
+ id: '@kb-labs/plugin-1',
756
+ display: { name: 'Plugin One' },
757
+ });
758
+
759
+ const manifest2 = createMockManifest({
760
+ id: '@kb-labs/plugin-2',
761
+ display: { name: 'Plugin Two' },
762
+ });
763
+
764
+ const snapshot = createMockSnapshot([
765
+ { pluginId: '@kb-labs/plugin-1', manifest: manifest1, pluginRoot: '/p1', source: 'workspace' },
766
+ { pluginId: '@kb-labs/plugin-2', manifest: manifest2, pluginRoot: '/p2', source: 'npm' },
767
+ ]);
768
+
769
+ const cliApi = {
770
+ snapshot: vi.fn(() => snapshot),
771
+ } as unknown as IEntityRegistry;
772
+
773
+ await registerPluginSnapshotRoutes(app, BASE_CONFIG, cliApi);
774
+
775
+ const response = await app.inject({
776
+ method: 'GET',
777
+ url: '/api/v1/plugins/registry',
778
+ });
779
+
780
+ expect(response.statusCode).toBe(200);
781
+ const payload = response.json() as { manifests: any[] };
782
+ expect(payload.manifests).toHaveLength(2);
783
+ expect(payload.manifests[0]).toMatchObject({
784
+ pluginId: '@kb-labs/plugin-1',
785
+ manifest: expect.objectContaining({ id: '@kb-labs/plugin-1' }),
786
+ pluginRoot: '/p1',
787
+ source: expect.objectContaining({ kind: 'local' }),
788
+ });
789
+ });
790
+
791
+ // Studio widget system is being reworked — test removed
792
+
793
+ it('handles registry errors gracefully', async () => {
794
+ const cliApi = {
795
+ snapshot: vi.fn(() => {
796
+ throw new Error('Registry service unavailable');
797
+ }),
798
+ } as unknown as IEntityRegistry;
799
+
800
+ await registerPluginSnapshotRoutes(app, BASE_CONFIG, cliApi);
801
+
802
+ const response = await app.inject({
803
+ method: 'GET',
804
+ url: '/api/v1/plugins/registry',
805
+ });
806
+
807
+ expect(response.statusCode).toBe(500);
808
+ const payload = response.json() as { error: string; message: string };
809
+ expect(payload.error).toBe('Failed to load plugin registry');
810
+ expect(payload.message).toContain('Registry service unavailable');
811
+ });
812
+
813
+ it('handles studio registry generation errors', async () => {
814
+ const cliApi = {
815
+ snapshot: vi.fn(() => {
816
+ throw new Error('Studio registry generation failed');
817
+ }),
818
+ } as unknown as IEntityRegistry;
819
+
820
+ await registerPluginSnapshotRoutes(app, BASE_CONFIG, cliApi);
821
+
822
+ const response = await app.inject({
823
+ method: 'GET',
824
+ url: '/api/v1/studio/registry',
825
+ });
826
+
827
+ expect(response.statusCode).toBe(500);
828
+ const payload = response.json() as { error: string; message: string };
829
+ expect(payload.error).toBe('Failed to generate studio registry');
830
+ expect(payload.message).toContain('Studio registry generation failed');
831
+ });
832
+
833
+ it('returns empty manifests when registry is empty', async () => {
834
+ const snapshot = createMockSnapshot([]);
835
+
836
+ const cliApi = {
837
+ snapshot: vi.fn(() => snapshot),
838
+ } as unknown as IEntityRegistry;
839
+
840
+ await registerPluginSnapshotRoutes(app, BASE_CONFIG, cliApi);
841
+
842
+ const response = await app.inject({
843
+ method: 'GET',
844
+ url: '/api/v1/plugins/registry',
845
+ });
846
+
847
+ expect(response.statusCode).toBe(200);
848
+ const payload = response.json() as { manifests: any[] };
849
+ expect(payload.manifests).toEqual([]);
850
+ });
851
+
852
+ it('returns discovery diagnostics in plugin registry payload', async () => {
853
+ const snapshot = createMockSnapshot([], {
854
+ diagnostics: [{
855
+ severity: 'error',
856
+ code: 'INTEGRITY_MISMATCH',
857
+ message: 'Integrity mismatch for "@kb-labs/commit"',
858
+ pluginId: '@kb-labs/commit',
859
+ filePath: '/workspace/plugins/commit/package.json',
860
+ remediation: 'Re-install: kb marketplace install @kb-labs/commit',
861
+ }],
862
+ });
863
+
864
+ const cliApi = {
865
+ snapshot: vi.fn(() => snapshot),
866
+ } as unknown as IEntityRegistry;
867
+
868
+ await registerPluginSnapshotRoutes(app, BASE_CONFIG, cliApi);
869
+
870
+ const response = await app.inject({
871
+ method: 'GET',
872
+ url: '/api/v1/plugins/registry',
873
+ });
874
+
875
+ expect(response.statusCode).toBe(200);
876
+ const payload = response.json() as {
877
+ diagnostics: {
878
+ total: number;
879
+ items: Array<{ code: string; reasonCode: string; pluginId?: string }>;
880
+ };
881
+ };
882
+ expect(payload.diagnostics.total).toBe(1);
883
+ expect(payload.diagnostics.items[0]).toMatchObject({
884
+ code: 'INTEGRITY_MISMATCH',
885
+ reasonCode: 'integrity_mismatch',
886
+ pluginId: '@kb-labs/commit',
887
+ });
888
+ });
889
+
890
+ it('returns discovery diagnostics in plugin health payload', async () => {
891
+ const snapshot = createMockSnapshot([], {
892
+ diagnostics: [{
893
+ severity: 'error',
894
+ code: 'INTEGRITY_MISMATCH',
895
+ message: 'Integrity mismatch for "@kb-labs/commit"',
896
+ pluginId: '@kb-labs/commit',
897
+ }],
898
+ });
899
+
900
+ const cliApi = {
901
+ snapshot: vi.fn(() => snapshot),
902
+ } as unknown as IEntityRegistry;
903
+
904
+ await registerPluginSnapshotRoutes(app, BASE_CONFIG, cliApi);
905
+
906
+ const response = await app.inject({
907
+ method: 'GET',
908
+ url: '/api/v1/plugins/health',
909
+ });
910
+
911
+ expect(response.statusCode).toBe(200);
912
+ const payload = response.json() as {
913
+ healthy: boolean;
914
+ diagnostics: {
915
+ total: number;
916
+ errors: number;
917
+ items: Array<{ code: string; reasonCode: string; pluginId?: string }>;
918
+ };
919
+ message: string;
920
+ };
921
+ expect(payload.healthy).toBe(false);
922
+ expect(payload.diagnostics.total).toBe(1);
923
+ expect(payload.diagnostics.errors).toBe(1);
924
+ expect(payload.diagnostics.items[0]).toMatchObject({
925
+ code: 'INTEGRITY_MISMATCH',
926
+ reasonCode: 'integrity_mismatch',
927
+ pluginId: '@kb-labs/commit',
928
+ });
929
+ expect(payload.message).toContain('discovery diagnostics');
930
+ });
931
+ });