@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,496 @@
1
+ /**
2
+ * @module @kb-labs/rest-api-app/services/historical-metrics
3
+ * Historical metrics collection and storage service
4
+ */
5
+
6
+ import type { CacheAdapter } from '@kb-labs/plugin-contracts';
7
+ import { metricsCollector } from '../middleware/metrics.js';
8
+
9
+ /**
10
+ * Historical data point
11
+ */
12
+ export interface HistoricalDataPoint {
13
+ timestamp: number;
14
+ value: number;
15
+ }
16
+
17
+ /**
18
+ * Heatmap cell data
19
+ */
20
+ export interface HeatmapCell {
21
+ day: string; // 'Mon', 'Tue', etc.
22
+ hour: number; // 0-23
23
+ value: number;
24
+ }
25
+
26
+ /**
27
+ * Metrics snapshot for historical storage
28
+ */
29
+ interface MetricsSnapshot {
30
+ timestamp: number;
31
+ requests: {
32
+ total: number;
33
+ success: number;
34
+ clientErrors: number;
35
+ serverErrors: number;
36
+ };
37
+ latency: {
38
+ average: number;
39
+ min: number;
40
+ max: number;
41
+ p50?: number;
42
+ p95?: number;
43
+ p99?: number;
44
+ };
45
+ uptime: number; // seconds
46
+ perPlugin: Array<{
47
+ pluginId?: string;
48
+ requests: number;
49
+ errors: number;
50
+ avgLatency: number;
51
+ }>;
52
+ }
53
+
54
+ /**
55
+ * Historical metrics collector configuration
56
+ */
57
+ export interface HistoricalMetricsConfig {
58
+ /** Collection interval in milliseconds (default: 5000 = 5s) */
59
+ intervalMs?: number;
60
+ /** Maximum points to store per time range */
61
+ maxPoints?: {
62
+ /** Last 1 minute (default: 12 points at 5s intervals) */
63
+ '1m'?: number;
64
+ /** Last 5 minutes (default: 60 points) */
65
+ '5m'?: number;
66
+ /** Last 10 minutes (default: 120 points) */
67
+ '10m'?: number;
68
+ /** Last 30 minutes (default: 360 points) */
69
+ '30m'?: number;
70
+ /** Last 1 hour (default: 720 points) */
71
+ '1h'?: number;
72
+ };
73
+ /** Enable debug logging */
74
+ debug?: boolean;
75
+ }
76
+
77
+ const DEFAULT_CONFIG: Required<HistoricalMetricsConfig> = {
78
+ intervalMs: 5000,
79
+ maxPoints: {
80
+ '1m': 12,
81
+ '5m': 60,
82
+ '10m': 120,
83
+ '30m': 360,
84
+ '1h': 720,
85
+ },
86
+ debug: false,
87
+ };
88
+
89
+ /**
90
+ * Historical metrics collector service
91
+ *
92
+ * Collects and stores historical metrics data in platform.cache with TTL-based retention.
93
+ * Provides time-series data for dashboards and analytics.
94
+ */
95
+ export class HistoricalMetricsCollector {
96
+ private cache: CacheAdapter;
97
+ private config: Required<HistoricalMetricsConfig>;
98
+ private intervalHandle: NodeJS.Timeout | null = null;
99
+ private logger: Console | any;
100
+ private startTimeMs: number = Date.now();
101
+
102
+ constructor(cache: CacheAdapter, config: HistoricalMetricsConfig = {}, logger: Console | any = console) {
103
+ this.cache = cache;
104
+ this.config = { ...DEFAULT_CONFIG, ...config, maxPoints: { ...DEFAULT_CONFIG.maxPoints, ...config.maxPoints } };
105
+ this.logger = logger;
106
+ }
107
+
108
+ /**
109
+ * Start background collection
110
+ */
111
+ start(): void {
112
+ if (this.intervalHandle) {
113
+ this.log('warn', 'Historical metrics collector already started');
114
+ return;
115
+ }
116
+
117
+ this.log('info', 'Starting historical metrics collector', {
118
+ intervalMs: this.config.intervalMs,
119
+ });
120
+
121
+ // Collect immediately, then every intervalMs
122
+ this.collect().catch(err => {
123
+ this.log('error', 'Failed to collect initial metrics', { err });
124
+ });
125
+
126
+ this.intervalHandle = setInterval(() => {
127
+ this.collect().catch(err => {
128
+ this.log('error', 'Failed to collect metrics', { err });
129
+ });
130
+ }, this.config.intervalMs);
131
+ }
132
+
133
+ /**
134
+ * Stop background collection
135
+ */
136
+ stop(): void {
137
+ if (this.intervalHandle) {
138
+ clearInterval(this.intervalHandle);
139
+ this.intervalHandle = null;
140
+ this.log('info', 'Historical metrics collector stopped');
141
+ }
142
+ }
143
+
144
+ /**
145
+ * Collect current metrics snapshot and store in cache
146
+ */
147
+ private async collect(): Promise<void> {
148
+ const now = Date.now();
149
+ const metrics = metricsCollector.getMetrics();
150
+
151
+ // Build snapshot
152
+ const snapshot: MetricsSnapshot = {
153
+ timestamp: now,
154
+ requests: {
155
+ total: metrics.requests.total,
156
+ success: metrics.requests.success ?? 0,
157
+ clientErrors: metrics.requests.clientErrors ?? 0,
158
+ serverErrors: metrics.requests.serverErrors ?? 0,
159
+ },
160
+ latency: {
161
+ average: metrics.latency.average,
162
+ min: metrics.latency.min === Infinity ? 0 : metrics.latency.min,
163
+ max: metrics.latency.max,
164
+ },
165
+ uptime: (now - metrics.timestamps.startTime) / 1000,
166
+ perPlugin: metrics.perPlugin.map(p => ({
167
+ pluginId: p.pluginId,
168
+ requests: p.total,
169
+ errors: Object.values(p.statuses)
170
+ .filter((_, idx) => Object.keys(p.statuses)[idx]?.startsWith('4') || Object.keys(p.statuses)[idx]?.startsWith('5'))
171
+ .reduce((sum, count) => sum + count, 0),
172
+ avgLatency: p.total > 0 ? p.totalDuration / p.total : 0,
173
+ })),
174
+ };
175
+
176
+ // Store in each time range bucket
177
+ await Promise.all([
178
+ this.appendToTimeSeries('1m', snapshot, 2 * 60 * 1000), // TTL: 2 minutes
179
+ this.appendToTimeSeries('5m', snapshot, 10 * 60 * 1000), // TTL: 10 minutes
180
+ this.appendToTimeSeries('10m', snapshot, 20 * 60 * 1000), // TTL: 20 minutes
181
+ this.appendToTimeSeries('30m', snapshot, 60 * 60 * 1000), // TTL: 1 hour
182
+ this.appendToTimeSeries('1h', snapshot, 2 * 60 * 60 * 1000), // TTL: 2 hours
183
+ ]);
184
+
185
+ // Update heatmap aggregation (less frequently - every minute)
186
+ if (now % 60000 < this.config.intervalMs) {
187
+ await this.updateHeatmapAggregation(snapshot).catch(err => {
188
+ this.log('error', 'Failed to update heatmap', { err });
189
+ });
190
+ }
191
+
192
+ this.log('debug', 'Metrics snapshot collected', {
193
+ timestamp: new Date(now).toISOString(),
194
+ requests: snapshot.requests.total,
195
+ latency: snapshot.latency.average.toFixed(2),
196
+ });
197
+ }
198
+
199
+ /**
200
+ * Append snapshot to time series bucket
201
+ */
202
+ private async appendToTimeSeries(range: keyof typeof DEFAULT_CONFIG.maxPoints, snapshot: MetricsSnapshot, ttlMs: number): Promise<void> {
203
+ const key = `metrics:history:${range}`;
204
+ const maxPoints = this.config.maxPoints[range] ?? 120;
205
+
206
+ // Get existing time series
207
+ let timeSeries = await this.cache.get<MetricsSnapshot[]>(key);
208
+ if (!timeSeries || !Array.isArray(timeSeries)) {
209
+ timeSeries = [];
210
+ }
211
+
212
+ // Append new snapshot
213
+ timeSeries.push(snapshot);
214
+
215
+ // Trim to max points (FIFO)
216
+ if (timeSeries.length > maxPoints) {
217
+ timeSeries = timeSeries.slice(timeSeries.length - maxPoints);
218
+ }
219
+
220
+ // Store back with TTL
221
+ await this.cache.set(key, timeSeries, ttlMs);
222
+ }
223
+
224
+ /**
225
+ * Update heatmap aggregation for weekly patterns
226
+ */
227
+ private async updateHeatmapAggregation(snapshot: MetricsSnapshot): Promise<void> {
228
+ const key = 'metrics:heatmap:7d';
229
+ const ttlMs = 24 * 60 * 60 * 1000; // 24 hours
230
+
231
+ // Get existing heatmap data
232
+ let heatmapData = await this.cache.get<Record<string, HeatmapCell[]>>(key);
233
+ if (!heatmapData || typeof heatmapData !== 'object') {
234
+ heatmapData = { latency: [], errors: [], requests: [] };
235
+ }
236
+
237
+ // Calculate current day and hour
238
+ const date = new Date(snapshot.timestamp);
239
+ const day = (['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'] as const)[date.getDay() as 0|1|2|3|4|5|6];
240
+ const hour = date.getHours();
241
+
242
+ // Update each metric type
243
+ for (const metricType of ['latency', 'errors', 'requests'] as const) {
244
+ let cells = heatmapData[metricType] || [];
245
+
246
+ // Find or create cell for this day/hour
247
+ const cellIndex = cells.findIndex(c => c.day === day && c.hour === hour);
248
+
249
+ let value = 0;
250
+ if (metricType === 'latency') {
251
+ value = snapshot.latency.average;
252
+ } else if (metricType === 'errors') {
253
+ value = snapshot.requests.clientErrors + snapshot.requests.serverErrors;
254
+ } else {
255
+ value = snapshot.requests.total;
256
+ }
257
+
258
+ if (cellIndex >= 0 && cells[cellIndex]) {
259
+ // Update existing cell (exponential moving average)
260
+ cells[cellIndex]!.value = cells[cellIndex]!.value * 0.9 + value * 0.1;
261
+ } else {
262
+ // Add new cell
263
+ cells.push({ day, hour, value });
264
+ }
265
+
266
+ // Keep only last 7 days worth of unique day/hour combinations (7 * 24 = 168 cells max)
267
+ if (cells.length > 168) {
268
+ cells = cells.slice(cells.length - 168);
269
+ }
270
+
271
+ heatmapData[metricType] = cells;
272
+ }
273
+
274
+ // Store back with TTL
275
+ await this.cache.set(key, heatmapData, ttlMs);
276
+ }
277
+
278
+ /**
279
+ * Query historical time-series data
280
+ */
281
+ async queryHistory(params: {
282
+ metric: 'requests' | 'errors' | 'latency' | 'uptime';
283
+ range: '1m' | '5m' | '10m' | '30m' | '1h';
284
+ interval?: '5s' | '1m' | '5m';
285
+ }): Promise<HistoricalDataPoint[]> {
286
+ const key = `metrics:history:${params.range}`;
287
+
288
+ // Get time series from cache
289
+ const timeSeries = await this.cache.get<MetricsSnapshot[]>(key);
290
+ if (!timeSeries || !Array.isArray(timeSeries)) {
291
+ return [];
292
+ }
293
+
294
+ // Extract requested metric
295
+ const dataPoints: HistoricalDataPoint[] = timeSeries.map(snapshot => {
296
+ let value = 0;
297
+
298
+ switch (params.metric) {
299
+ case 'requests':
300
+ value = snapshot.requests.total;
301
+ break;
302
+ case 'errors':
303
+ value = snapshot.requests.clientErrors + snapshot.requests.serverErrors;
304
+ break;
305
+ case 'latency':
306
+ value = snapshot.latency.average;
307
+ break;
308
+ case 'uptime':
309
+ value = snapshot.uptime;
310
+ break;
311
+ }
312
+
313
+ return {
314
+ timestamp: snapshot.timestamp,
315
+ value,
316
+ };
317
+ });
318
+
319
+ // Apply interval aggregation if requested
320
+ if (params.interval && params.interval !== '5s') {
321
+ return this.aggregateByInterval(dataPoints, params.interval);
322
+ }
323
+
324
+ return dataPoints;
325
+ }
326
+
327
+ /**
328
+ * Query heatmap data
329
+ */
330
+ async queryHeatmap(params: {
331
+ metric: 'latency' | 'errors' | 'requests';
332
+ days?: 7 | 14 | 30;
333
+ }): Promise<HeatmapCell[]> {
334
+ const key = 'metrics:heatmap:7d';
335
+
336
+ // Get heatmap data from cache
337
+ const heatmapData = await this.cache.get<Record<string, HeatmapCell[]>>(key);
338
+ if (!heatmapData || typeof heatmapData !== 'object') {
339
+ // Return empty heatmap structure
340
+ return this.generateEmptyHeatmap();
341
+ }
342
+
343
+ const cells = heatmapData[params.metric] || [];
344
+
345
+ // If no data yet, return empty heatmap
346
+ if (cells.length === 0) {
347
+ return this.generateEmptyHeatmap();
348
+ }
349
+
350
+ // Ensure all day/hour combinations exist (fill missing with 0)
351
+ return this.fillHeatmapGaps(cells);
352
+ }
353
+
354
+ /**
355
+ * Generate empty heatmap structure (7 days × 24 hours)
356
+ */
357
+ private generateEmptyHeatmap(): HeatmapCell[] {
358
+ const days = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'];
359
+ const cells: HeatmapCell[] = [];
360
+
361
+ for (const day of days) {
362
+ for (let hour = 0; hour < 24; hour++) {
363
+ cells.push({ day, hour, value: 0 });
364
+ }
365
+ }
366
+
367
+ return cells;
368
+ }
369
+
370
+ /**
371
+ * Fill gaps in heatmap data (missing day/hour combinations)
372
+ */
373
+ private fillHeatmapGaps(cells: HeatmapCell[]): HeatmapCell[] {
374
+ const days = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'];
375
+ const cellMap = new Map<string, number>();
376
+
377
+ // Index existing cells
378
+ for (const cell of cells) {
379
+ const key = `${cell.day}:${cell.hour}`;
380
+ cellMap.set(key, cell.value);
381
+ }
382
+
383
+ // Generate complete 7×24 grid
384
+ const complete: HeatmapCell[] = [];
385
+ for (const day of days) {
386
+ for (let hour = 0; hour < 24; hour++) {
387
+ const key = `${day}:${hour}`;
388
+ complete.push({
389
+ day,
390
+ hour,
391
+ value: cellMap.get(key) ?? 0,
392
+ });
393
+ }
394
+ }
395
+
396
+ return complete;
397
+ }
398
+
399
+ /**
400
+ * Aggregate data points by interval
401
+ */
402
+ private aggregateByInterval(dataPoints: HistoricalDataPoint[], interval: '1m' | '5m'): HistoricalDataPoint[] {
403
+ if (dataPoints.length === 0) {return [];}
404
+
405
+ const intervalMs = interval === '1m' ? 60 * 1000 : 5 * 60 * 1000;
406
+ const aggregated: HistoricalDataPoint[] = [];
407
+
408
+ let bucket: HistoricalDataPoint[] = [];
409
+ let bucketStart = Math.floor(dataPoints[0]!.timestamp / intervalMs) * intervalMs;
410
+
411
+ for (const point of dataPoints) {
412
+ const pointBucket = Math.floor(point.timestamp / intervalMs) * intervalMs;
413
+
414
+ if (pointBucket === bucketStart) {
415
+ bucket.push(point);
416
+ } else {
417
+ // Finalize current bucket
418
+ if (bucket.length > 0) {
419
+ const avgValue = bucket.reduce((sum, p) => sum + p.value, 0) / bucket.length;
420
+ aggregated.push({
421
+ timestamp: bucketStart + intervalMs / 2, // midpoint
422
+ value: avgValue,
423
+ });
424
+ }
425
+
426
+ // Start new bucket
427
+ bucket = [point];
428
+ bucketStart = pointBucket;
429
+ }
430
+ }
431
+
432
+ // Finalize last bucket
433
+ if (bucket.length > 0) {
434
+ const avgValue = bucket.reduce((sum, p) => sum + p.value, 0) / bucket.length;
435
+ aggregated.push({
436
+ timestamp: bucketStart + intervalMs / 2,
437
+ value: avgValue,
438
+ });
439
+ }
440
+
441
+ return aggregated;
442
+ }
443
+
444
+ /**
445
+ * Get collector statistics
446
+ */
447
+ async getStats(): Promise<{
448
+ running: boolean;
449
+ uptimeSeconds: number;
450
+ timeSeries: Record<string, { points: number; oldestTimestamp: number | null; newestTimestamp: number | null }>;
451
+ heatmap: { cells: number; metrics: string[] };
452
+ }> {
453
+ const stats: any = {
454
+ running: this.intervalHandle !== null,
455
+ uptimeSeconds: (Date.now() - this.startTimeMs) / 1000,
456
+ timeSeries: {},
457
+ heatmap: { cells: 0, metrics: [] },
458
+ };
459
+
460
+ // Check each time range
461
+ for (const range of ['1m', '5m', '10m', '30m', '1h'] as const) {
462
+ const key = `metrics:history:${range}`;
463
+ const timeSeries = await this.cache.get<MetricsSnapshot[]>(key);
464
+
465
+ if (timeSeries && Array.isArray(timeSeries)) {
466
+ stats.timeSeries[range] = {
467
+ points: timeSeries.length,
468
+ oldestTimestamp: timeSeries[0]?.timestamp ?? null,
469
+ newestTimestamp: timeSeries[timeSeries.length - 1]?.timestamp ?? null,
470
+ };
471
+ } else {
472
+ stats.timeSeries[range] = { points: 0, oldestTimestamp: null, newestTimestamp: null };
473
+ }
474
+ }
475
+
476
+ // Check heatmap
477
+ const heatmapData = await this.cache.get<Record<string, HeatmapCell[]>>('metrics:heatmap:7d');
478
+ if (heatmapData && typeof heatmapData === 'object') {
479
+ const metrics = Object.keys(heatmapData);
480
+ const totalCells = metrics.reduce((sum, m) => sum + (heatmapData[m]?.length ?? 0), 0);
481
+ stats.heatmap = { cells: totalCells, metrics };
482
+ }
483
+
484
+ return stats;
485
+ }
486
+
487
+ private log(level: 'info' | 'warn' | 'error' | 'debug', message: string, meta?: any): void {
488
+ if (level === 'debug' && !this.config.debug) {return;}
489
+
490
+ if (this.logger[level]) {
491
+ this.logger[level](`[HistoricalMetrics] ${message}`, meta);
492
+ } else {
493
+ console.log(`[HistoricalMetrics] [${level}] ${message}`, meta);
494
+ }
495
+ }
496
+ }