@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,244 @@
1
+ /**
2
+ * @module @kb-labs/rest-api-app/services/system-metrics-collector
3
+ * System metrics collector for REST API instances.
4
+ *
5
+ * Collects CPU, memory, uptime, and load average metrics from the current instance
6
+ * and writes them to platform.cache with TTL for automatic cleanup.
7
+ */
8
+
9
+ import { platform } from '@kb-labs/core-runtime';
10
+ import * as os from 'node:os';
11
+ import * as process from 'node:process';
12
+ import { monitorEventLoopDelay } from 'node:perf_hooks';
13
+ import { updateRuntimeObservabilityMetrics } from '../middleware/prom-metrics.js';
14
+
15
+ let latestSystemMetricsSnapshot: SystemMetrics | null = null;
16
+
17
+ /**
18
+ * System metrics data structure
19
+ */
20
+ export interface SystemMetrics {
21
+ /** Instance identifier (hostname) */
22
+ instanceId: string;
23
+
24
+ /** Timestamp when metrics were collected (ms since epoch) */
25
+ timestamp: number;
26
+
27
+ /** CPU usage information */
28
+ cpu: {
29
+ /** User CPU time in microseconds */
30
+ user: number;
31
+ /** System CPU time in microseconds */
32
+ system: number;
33
+ /** CPU usage percentage (0-100) */
34
+ percentage: number;
35
+ };
36
+
37
+ /** Memory usage information */
38
+ memory: {
39
+ /** Resident Set Size (bytes) - total memory allocated */
40
+ rss: number;
41
+ /** Heap total (bytes) - allocated heap */
42
+ heapTotal: number;
43
+ /** Heap used (bytes) - actual heap used */
44
+ heapUsed: number;
45
+ /** External memory (bytes) - C++ objects bound to JS */
46
+ external: number;
47
+ /** Array buffers (bytes) */
48
+ arrayBuffers: number;
49
+ /** RSS usage percentage (0-100) */
50
+ rssPercentage: number;
51
+ /** Heap usage percentage (0-100) */
52
+ heapPercentage: number;
53
+ };
54
+
55
+ /** Process uptime (seconds) */
56
+ uptime: number;
57
+ eventLoopLagMs: number;
58
+ activeOperations: number;
59
+
60
+ /** System load average (1, 5, 15 minutes) */
61
+ loadAvg: [number, number, number];
62
+
63
+ /** Total system memory (bytes) */
64
+ totalMemory: number;
65
+
66
+ /** Free system memory (bytes) */
67
+ freeMemory: number;
68
+ }
69
+
70
+ function toFiniteNumber(value: number): number {
71
+ return Number.isFinite(value) ? value : 0;
72
+ }
73
+
74
+ /**
75
+ * System metrics collector
76
+ * Periodically collects system metrics and writes to platform.cache
77
+ */
78
+ export class SystemMetricsCollector {
79
+ private intervalId: NodeJS.Timeout | null = null;
80
+ private instanceId: string;
81
+ private lastCpuUsage = process.cpuUsage();
82
+ private lastCpuTime = Date.now();
83
+ private eventLoopDelay = monitorEventLoopDelay({ resolution: 20 });
84
+ private latestMetrics: SystemMetrics | null = null;
85
+
86
+ constructor(
87
+ private readonly serviceId: string = 'rest',
88
+ private readonly getActiveOperations: () => number = () => 0,
89
+ ) {
90
+ this.instanceId = `${os.hostname()}:${process.pid}`;
91
+ }
92
+
93
+ /**
94
+ * Calculate CPU percentage based on delta
95
+ */
96
+ private calculateCpuPercentage(): number {
97
+ const currentUsage = process.cpuUsage(this.lastCpuUsage);
98
+ const currentTime = Date.now();
99
+ const deltaTime = currentTime - this.lastCpuTime;
100
+
101
+ // Update for next calculation
102
+ this.lastCpuUsage = process.cpuUsage();
103
+ this.lastCpuTime = currentTime;
104
+
105
+ // Calculate CPU percentage
106
+ // cpuUsage() returns microseconds, convert to milliseconds and calculate percentage
107
+ const cpuTimeMs = (currentUsage.user + currentUsage.system) / 1000;
108
+ const percentage = (cpuTimeMs / deltaTime) * 100;
109
+
110
+ // Cap at 100% (can exceed on multi-core systems)
111
+ return Math.min(percentage, 100);
112
+ }
113
+
114
+ /**
115
+ * Collect current system metrics
116
+ */
117
+ private collectMetrics(): SystemMetrics {
118
+ const memoryUsage = process.memoryUsage();
119
+ const totalMemory = os.totalmem();
120
+ const heapPercentageRaw =
121
+ memoryUsage.heapTotal > 0 ? (memoryUsage.heapUsed / memoryUsage.heapTotal) * 100 : 0;
122
+ const eventLoopLagMs = toFiniteNumber(Number((this.eventLoopDelay.mean / 1_000_000).toFixed(2)));
123
+ const cpuPercentage = toFiniteNumber(this.calculateCpuPercentage());
124
+
125
+ return {
126
+ instanceId: this.instanceId,
127
+ timestamp: Date.now(),
128
+ cpu: {
129
+ user: this.lastCpuUsage.user,
130
+ system: this.lastCpuUsage.system,
131
+ percentage: cpuPercentage,
132
+ },
133
+ memory: {
134
+ rss: memoryUsage.rss,
135
+ heapTotal: memoryUsage.heapTotal,
136
+ heapUsed: memoryUsage.heapUsed,
137
+ external: memoryUsage.external,
138
+ arrayBuffers: memoryUsage.arrayBuffers,
139
+ rssPercentage: toFiniteNumber((memoryUsage.rss / totalMemory) * 100),
140
+ heapPercentage: toFiniteNumber(heapPercentageRaw),
141
+ },
142
+ uptime: process.uptime(),
143
+ eventLoopLagMs,
144
+ activeOperations: this.getActiveOperations(),
145
+ loadAvg: os.loadavg() as [number, number, number],
146
+ totalMemory,
147
+ freeMemory: os.freemem(),
148
+ };
149
+ }
150
+
151
+ /**
152
+ * Start collecting metrics at regular intervals
153
+ * @param intervalMs - Collection interval in milliseconds (default: 10000ms = 10s)
154
+ * @param ttlMs - Time-to-live for cache entries (default: 60000ms = 60s)
155
+ */
156
+ async start(intervalMs: number = 10000, ttlMs: number = 60000): Promise<void> {
157
+ if (this.intervalId) {
158
+ platform.logger.warn('SystemMetricsCollector already started');
159
+ return;
160
+ }
161
+
162
+ platform.logger.info('Starting system metrics collector', {
163
+ serviceId: this.serviceId,
164
+ instanceId: this.instanceId,
165
+ intervalMs,
166
+ ttlMs,
167
+ });
168
+
169
+ this.eventLoopDelay.enable();
170
+
171
+ // Collect immediately on start
172
+ await this.collect(ttlMs);
173
+
174
+ // Then collect at intervals
175
+ this.intervalId = setInterval(async () => {
176
+ await this.collect(ttlMs);
177
+ }, intervalMs);
178
+ }
179
+
180
+ /**
181
+ * Collect metrics and write to cache
182
+ */
183
+ private async collect(ttlMs: number): Promise<void> {
184
+ try {
185
+ const metrics = this.collectMetrics();
186
+ this.latestMetrics = metrics;
187
+ latestSystemMetricsSnapshot = metrics;
188
+
189
+ // Write to platform.cache with TTL
190
+ // Key pattern: system-metrics:{instanceId}
191
+ await platform.cache.set(
192
+ `system-metrics:${this.instanceId}`,
193
+ metrics,
194
+ ttlMs
195
+ );
196
+
197
+ updateRuntimeObservabilityMetrics({
198
+ cpuPercent: metrics.cpu.percentage,
199
+ rssBytes: metrics.memory.rss,
200
+ heapUsedBytes: metrics.memory.heapUsed,
201
+ eventLoopLagMs: metrics.eventLoopLagMs,
202
+ activeOperations: metrics.activeOperations,
203
+ });
204
+
205
+ platform.logger.debug('System metrics collected', {
206
+ serviceId: this.serviceId,
207
+ instanceId: this.instanceId,
208
+ cpu: metrics.cpu.percentage.toFixed(1) + '%',
209
+ memory: metrics.memory.rssPercentage.toFixed(1) + '%',
210
+ eventLoopLagMs: metrics.eventLoopLagMs,
211
+ activeOperations: metrics.activeOperations,
212
+ uptime: Math.floor(metrics.uptime) + 's',
213
+ });
214
+
215
+ this.eventLoopDelay.reset();
216
+ } catch (error) {
217
+ platform.logger.error('Failed to collect system metrics', error instanceof Error ? error : new Error(String(error)));
218
+ }
219
+ }
220
+
221
+ getInstanceId(): string {
222
+ return this.instanceId;
223
+ }
224
+
225
+ getLatestMetrics(): SystemMetrics | null {
226
+ return this.latestMetrics;
227
+ }
228
+
229
+ /**
230
+ * Stop collecting metrics
231
+ */
232
+ stop(): void {
233
+ if (this.intervalId) {
234
+ clearInterval(this.intervalId);
235
+ this.intervalId = null;
236
+ platform.logger.info('System metrics collector stopped');
237
+ }
238
+ this.eventLoopDelay.disable();
239
+ }
240
+ }
241
+
242
+ export function getLatestSystemMetrics(): SystemMetrics | null {
243
+ return latestSystemMetricsSnapshot;
244
+ }
@@ -0,0 +1,58 @@
1
+ /**
2
+ * @module @kb-labs/rest-api-app/types/fastify
3
+ * Fastify type extensions
4
+ */
5
+
6
+ import type { FastifyBaseLogger } from 'fastify/types/logger';
7
+ import type { FastifySchema } from 'fastify/types/schema';
8
+ import type { FastifyTypeProvider, FastifyTypeProviderDefault } from 'fastify/types/type-provider';
9
+ import type { ContextConfigDefault, RawReplyDefaultExpression, RawRequestDefaultExpression, RawServerBase, RawServerDefault } from 'fastify/types/utils';
10
+ import type { IEntityRegistry } from '@kb-labs/core-registry';
11
+ import type { ReadinessState } from '../routes/readiness';
12
+ import '@fastify/type-provider-typebox';
13
+ import type { EventHub } from '../events/hub';
14
+
15
+ declare module 'fastify/types/instance' {
16
+ interface FastifyInstance<
17
+ RawServer extends RawServerBase = RawServerDefault,
18
+ RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>,
19
+ RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>,
20
+ Logger extends FastifyBaseLogger = FastifyBaseLogger,
21
+ TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault,
22
+ SchemaCompiler extends FastifySchema = FastifySchema,
23
+ ContextConfig = ContextConfigDefault
24
+ > {
25
+ registry?: IEntityRegistry;
26
+ kbReadiness?: ReadinessState;
27
+ kbStartupGuard?: {
28
+ inFlight: number;
29
+ };
30
+ kbEventHub?: EventHub;
31
+ }
32
+ }
33
+
34
+ declare module 'fastify' {
35
+ interface FastifyInstance {
36
+ registry?: IEntityRegistry;
37
+ kbReadiness?: ReadinessState;
38
+ kbStartupGuard?: {
39
+ inFlight: number;
40
+ };
41
+ kbEventHub?: EventHub;
42
+ }
43
+ }
44
+
45
+ declare module 'fastify/types/request' {
46
+ interface FastifyRequest {
47
+ mockMode?: boolean;
48
+ kbStartupGuardActive?: boolean;
49
+ kbStartupGuardTimer?: NodeJS.Timeout;
50
+ kbMetricsStart?: number;
51
+ kbHeaderState?: {
52
+ vary: Set<string>;
53
+ sensitive: Set<string>;
54
+ rateLimitKeys: Record<string, string>;
55
+ sanitized: Record<string, string>;
56
+ };
57
+ }
58
+ }
@@ -0,0 +1,113 @@
1
+ import { describe, expect, it, vi } from 'vitest';
2
+ import type { RestApiConfig } from '@kb-labs/rest-api-core';
3
+ import { buildRegistrySseAuthHook } from '../sse-auth';
4
+
5
+ function baseConfig(overrides: Partial<RestApiConfig> = {}): RestApiConfig {
6
+ const { events, ...rest } = overrides;
7
+ const config: RestApiConfig = {
8
+ port: 5050,
9
+ basePath: '/api/v1',
10
+ apiVersion: 'test',
11
+ cors: {
12
+ origins: [],
13
+ allowCredentials: true,
14
+ profile: 'dev',
15
+ },
16
+ plugins: [],
17
+ mockMode: false,
18
+ ...rest,
19
+ events: events
20
+ ? {
21
+ registry: events.registry
22
+ ? {
23
+ token: events.registry.token,
24
+ headerName: events.registry.headerName ?? 'authorization',
25
+ queryParam: events.registry.queryParam ?? 'access_token',
26
+ }
27
+ : undefined,
28
+ }
29
+ : undefined,
30
+ };
31
+ return config;
32
+ }
33
+
34
+ describe('buildRegistrySseAuthHook', () => {
35
+ it('returns undefined when auth is not configured', () => {
36
+ const hook = buildRegistrySseAuthHook(baseConfig());
37
+ expect(hook).toBeUndefined();
38
+ });
39
+
40
+ it('allows requests with valid bearer token', () => {
41
+ const hook = buildRegistrySseAuthHook(
42
+ baseConfig({
43
+ events: {
44
+ registry: {
45
+ token: 'secret',
46
+ headerName: 'authorization',
47
+ queryParam: 'access_token',
48
+ },
49
+ },
50
+ })
51
+ );
52
+ expect(hook).toBeDefined();
53
+ const done = vi.fn();
54
+ const request = {
55
+ headers: {
56
+ authorization: 'Bearer secret',
57
+ },
58
+ query: {},
59
+ };
60
+ const reply = {
61
+ code: vi.fn().mockReturnThis(),
62
+ header: vi.fn().mockReturnThis(),
63
+ send: vi.fn(),
64
+ };
65
+ hook?.(request as any, reply as any, done as any);
66
+ expect(done).toHaveBeenCalledTimes(1);
67
+ expect(reply.send).not.toHaveBeenCalled();
68
+ });
69
+
70
+ it('rejects requests with invalid token', () => {
71
+ const hook = buildRegistrySseAuthHook(
72
+ baseConfig({
73
+ events: {
74
+ registry: {
75
+ token: 'secret',
76
+ headerName: 'x-api-token',
77
+ queryParam: 'auth',
78
+ },
79
+ },
80
+ })
81
+ );
82
+ const done = vi.fn();
83
+ const request = {
84
+ headers: {
85
+ 'x-api-token': 'wrong',
86
+ },
87
+ query: { auth: 'wrong' },
88
+ };
89
+ const reply = {
90
+ statusCode: undefined as number | undefined,
91
+ payload: undefined as unknown,
92
+ code(status: number) {
93
+ this.statusCode = status;
94
+ return this;
95
+ },
96
+ header() {
97
+ return this;
98
+ },
99
+ send(payload: unknown) {
100
+ this.payload = payload;
101
+ },
102
+ };
103
+ hook?.(request as any, reply as any, done as any);
104
+ expect(done).not.toHaveBeenCalled();
105
+ expect(reply.statusCode).toBe(401);
106
+ expect(reply.payload).toMatchObject({
107
+ status: 'unauthorized',
108
+ reason: 'invalid_token',
109
+ });
110
+ });
111
+ });
112
+
113
+
@@ -0,0 +1,15 @@
1
+ export function normalizeBasePath(basePath?: string): string {
2
+ if (!basePath || basePath === '/') {
3
+ return '';
4
+ }
5
+ return basePath.endsWith('/') ? basePath.slice(0, -1) : basePath;
6
+ }
7
+
8
+ export function resolvePaths(basePath: string, route: string): string[] {
9
+ const normalizedRoute = route.startsWith('/') ? route : `/${route}`;
10
+ if (!basePath) {
11
+ return [normalizedRoute];
12
+ }
13
+ const base = normalizeBasePath(basePath);
14
+ return Array.from(new Set([normalizedRoute, `${base}${normalizedRoute}`]));
15
+ }
@@ -0,0 +1,42 @@
1
+ /**
2
+ * @module @kb-labs/rest-api-app/utils/repo
3
+ * Repository utilities
4
+ */
5
+
6
+ import * as path from 'node:path';
7
+ import { promises as fs } from 'node:fs';
8
+
9
+ /**
10
+ * Find monorepo root (prefer pnpm-workspace.yaml or .git over package.json)
11
+ */
12
+ export async function findMonorepoRoot(startDir: string): Promise<string> {
13
+ let dir = path.resolve(startDir);
14
+ let foundRoot: string | null = null;
15
+
16
+ while (true) {
17
+ try {
18
+ const hasGit = await fs.access(path.join(dir, '.git')).then(() => true).catch(() => false);
19
+ const hasWorkspace = await fs.access(path.join(dir, 'pnpm-workspace.yaml')).then(() => true).catch(() => false);
20
+
21
+ if (hasGit && hasWorkspace) {
22
+ foundRoot = dir;
23
+ }
24
+ } catch {
25
+ // Continue
26
+ }
27
+
28
+ const parent = path.dirname(dir);
29
+ if (parent === dir) {
30
+ break;
31
+ }
32
+ dir = parent;
33
+ }
34
+
35
+ if (foundRoot) {
36
+ return foundRoot;
37
+ }
38
+
39
+ // Fallback: use startDir
40
+ return path.resolve(startDir);
41
+ }
42
+
@@ -0,0 +1,20 @@
1
+ /**
2
+ * @module @kb-labs/rest-api-app/utils/schema
3
+ * Schema utilities for Fastify routes.
4
+ * Route-level Zod schemas live in @kb-labs/rest-api-contracts/route-schemas.
5
+ */
6
+
7
+ /**
8
+ * Error response schema for Fastify's built-in error serialization.
9
+ * Used in non-Zod routes (health, metrics, internal).
10
+ */
11
+ export const errorSchema = {
12
+ type: 'object',
13
+ properties: {
14
+ statusCode: { type: 'number' },
15
+ error: { type: 'string' },
16
+ message: { type: 'string' },
17
+ code: { type: 'string' },
18
+ },
19
+ additionalProperties: true,
20
+ } as const;
@@ -0,0 +1,81 @@
1
+ /**
2
+ * @module @kb-labs/rest-api-app/utils/sse-auth
3
+ * Helpers for SSE token validation
4
+ */
5
+
6
+ import type { FastifyReply, FastifyRequest, HookHandlerDoneFunction } from 'fastify';
7
+ import type { RestApiConfig } from '@kb-labs/rest-api-core';
8
+
9
+ type RegistryAuthConfig = {
10
+ token: string;
11
+ headerName: string;
12
+ queryParam: string;
13
+ };
14
+
15
+ function extractTokenFromHeader(headerValue: unknown, headerName: string): string | undefined {
16
+ if (typeof headerValue === 'string') {
17
+ if (headerName === 'authorization') {
18
+ const match = headerValue.match(/^Bearer\s+(.+)$/i);
19
+ return match ? match[1] : undefined;
20
+ }
21
+ return headerValue;
22
+ }
23
+ if (Array.isArray(headerValue)) {
24
+ return headerValue[0];
25
+ }
26
+ return undefined;
27
+ }
28
+
29
+ function extractToken(request: FastifyRequest, config: RegistryAuthConfig): string | undefined {
30
+ const headerName = (config.headerName ?? 'authorization').toLowerCase();
31
+ const queryParam = config.queryParam ?? 'access_token';
32
+
33
+ const explicitHeader = extractTokenFromHeader(request.headers[headerName], headerName);
34
+ if (explicitHeader) {
35
+ return explicitHeader;
36
+ }
37
+
38
+ if (headerName !== 'authorization' && typeof request.headers.authorization === 'string') {
39
+ const fallback = extractTokenFromHeader(request.headers.authorization, 'authorization');
40
+ if (fallback) {
41
+ return fallback;
42
+ }
43
+ }
44
+
45
+ const query = request.query as Record<string, string | undefined>;
46
+ return query?.[queryParam] ?? query?.access_token;
47
+ }
48
+
49
+ export function buildRegistrySseAuthHook(config: RestApiConfig) {
50
+ const registryAuth = config.events?.registry;
51
+ if (!registryAuth?.token) {
52
+ return undefined;
53
+ }
54
+ const authConfig: RegistryAuthConfig = {
55
+ token: registryAuth.token,
56
+ headerName: registryAuth.headerName ?? 'authorization',
57
+ queryParam: registryAuth.queryParam ?? 'access_token',
58
+ };
59
+
60
+ return function registrySseAuthHook(
61
+ request: FastifyRequest,
62
+ reply: FastifyReply,
63
+ done: HookHandlerDoneFunction
64
+ ) {
65
+ const provided = extractToken(request, authConfig);
66
+ if (provided === authConfig.token) {
67
+ done();
68
+ return;
69
+ }
70
+
71
+ reply
72
+ .code(401)
73
+ .header('content-type', 'application/json')
74
+ .send({
75
+ status: 'unauthorized',
76
+ reason: 'invalid_token',
77
+ });
78
+ };
79
+ }
80
+
81
+
@@ -0,0 +1,105 @@
1
+ #!/bin/bash
2
+
3
+ # Test script for KB Labs REST API with sandbox execution
4
+ # Usage: ./test-sandbox.sh
5
+
6
+ set -e
7
+
8
+ echo "🧪 Testing KB Labs REST API Sandbox Execution"
9
+ echo "=============================================="
10
+ echo ""
11
+
12
+ # Colors
13
+ GREEN='\033[0;32m'
14
+ RED='\033[0;31m'
15
+ YELLOW='\033[1;33m'
16
+ NC='\033[0m' # No Color
17
+
18
+ API_URL="${API_URL:-http://localhost:3000}"
19
+ BASE_PATH="/api/v1"
20
+
21
+ echo "📡 API URL: ${API_URL}"
22
+ echo ""
23
+
24
+ # Test 1: Check if server is running
25
+ echo "1️⃣ Testing server health..."
26
+ if curl -s -f "${API_URL}${BASE_PATH}/health" > /dev/null; then
27
+ echo -e "${GREEN}✅ Server is running${NC}"
28
+ else
29
+ echo -e "${RED}❌ Server is not running. Start it with: npm run dev${NC}"
30
+ exit 1
31
+ fi
32
+
33
+ # Test 2: Check plugin registry
34
+ echo ""
35
+ echo "2️⃣ Testing plugin registry..."
36
+ REGISTRY_RESPONSE=$(curl -s "${API_URL}${BASE_PATH}/plugins/registry")
37
+ if echo "$REGISTRY_RESPONSE" | grep -q "mind"; then
38
+ echo -e "${GREEN}✅ Mind plugin found in registry${NC}"
39
+ echo " Found plugins: $(echo "$REGISTRY_RESPONSE" | jq -r '.manifests[].id' 2>/dev/null || echo 'unknown')"
40
+ else
41
+ echo -e "${YELLOW}⚠️ Mind plugin not found in registry${NC}"
42
+ echo " Response: $REGISTRY_RESPONSE"
43
+ fi
44
+
45
+ # Test 3: Test Mind query endpoint (sandbox execution)
46
+ echo ""
47
+ echo "3️⃣ Testing Mind query endpoint (sandbox execution)..."
48
+ QUERY_RESPONSE=$(curl -s -X POST "${API_URL}${BASE_PATH}/plugins/mind/query" \
49
+ -H "Content-Type: application/json" \
50
+ -d '{
51
+ "query": "meta",
52
+ "params": {},
53
+ "options": {
54
+ "cwd": ".",
55
+ "json": true
56
+ }
57
+ }')
58
+
59
+ if echo "$QUERY_RESPONSE" | grep -q "ok"; then
60
+ echo -e "${GREEN}✅ Query endpoint responded successfully${NC}"
61
+ echo " Response structure:"
62
+ echo "$QUERY_RESPONSE" | jq '.' 2>/dev/null || echo "$QUERY_RESPONSE"
63
+ else
64
+ echo -e "${RED}❌ Query endpoint failed${NC}"
65
+ echo " Response: $QUERY_RESPONSE"
66
+ fi
67
+
68
+ # Test 4: Check for sandbox execution metrics
69
+ echo ""
70
+ echo "4️⃣ Checking for execution metrics..."
71
+ if echo "$QUERY_RESPONSE" | grep -q "meta"; then
72
+ echo -e "${GREEN}✅ Execution metrics found${NC}"
73
+ METRICS=$(echo "$QUERY_RESPONSE" | jq -r '.meta.exec' 2>/dev/null || echo '{}')
74
+ echo " Metrics: $METRICS"
75
+ else
76
+ echo -e "${YELLOW}⚠️ No metrics found in response${NC}"
77
+ fi
78
+
79
+ # Test 5: Test error handling (invalid request)
80
+ echo ""
81
+ echo "5️⃣ Testing error handling..."
82
+ ERROR_RESPONSE=$(curl -s -X POST "${API_URL}${BASE_PATH}/plugins/mind/query" \
83
+ -H "Content-Type: application/json" \
84
+ -d '{
85
+ "invalid": "request"
86
+ }')
87
+
88
+ if echo "$ERROR_RESPONSE" | grep -q "error\|status.*error"; then
89
+ echo -e "${GREEN}✅ Error handling works${NC}"
90
+ echo " Error response:"
91
+ echo "$ERROR_RESPONSE" | jq '.' 2>/dev/null || echo "$ERROR_RESPONSE"
92
+ else
93
+ echo -e "${YELLOW}⚠️ Unexpected error response format${NC}"
94
+ echo " Response: $ERROR_RESPONSE"
95
+ fi
96
+
97
+ echo ""
98
+ echo "=============================================="
99
+ echo -e "${GREEN}✅ Sandbox execution test complete!${NC}"
100
+ echo ""
101
+ echo "💡 Tips:"
102
+ echo " - Set KB_PLUGIN_DEV_MODE=true for in-process execution"
103
+ echo " - Check logs for detailed execution info"
104
+ echo " - Use --json flag in plugin responses for AI agents"
105
+
@@ -0,0 +1,15 @@
1
+ {
2
+ "extends": "../../tsconfig.base.json",
3
+ "compilerOptions": {
4
+ "outDir": "dist",
5
+ "baseUrl": ".",
6
+ "paths": {}
7
+ },
8
+ "include": [
9
+ "src/**/*"
10
+ ],
11
+ "exclude": [
12
+ "dist",
13
+ "node_modules"
14
+ ]
15
+ }