@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,718 @@
1
+ /**
2
+ * @module @kb-labs/rest-api-app/routes/logs
3
+ * Live log streaming and querying endpoints
4
+ */
5
+
6
+ import type { FastifyInstance } from 'fastify';
7
+ import type { RestApiConfig } from '@kb-labs/rest-api-core';
8
+ import { platform } from '@kb-labs/core-runtime';
9
+ import type { LogQuery, LogRecord } from '@kb-labs/core-platform';
10
+ import type { EventHub } from '../events/hub';
11
+
12
+ /**
13
+ * Map Pino numeric level to string level
14
+ */
15
+ function mapPinoLevelToString(level: any): string {
16
+ if (typeof level === 'string') {return level;}
17
+
18
+ // Pino levels: 10=trace, 20=debug, 30=info, 40=warn, 50=error, 60=fatal
19
+ if (level <= 10) {return 'trace';}
20
+ if (level <= 20) {return 'debug';}
21
+ if (level <= 30) {return 'info';}
22
+ if (level <= 40) {return 'warn';}
23
+ if (level <= 50) {return 'error';}
24
+ return 'fatal';
25
+ }
26
+
27
+ /**
28
+ * Convert internal LogRecord to frontend LogRecord format
29
+ */
30
+ function toFrontendLogRecord(record: LogRecord): any {
31
+ // Extract level from fields if it's a Pino log (numeric level)
32
+ const pinoLevel = record.fields.level;
33
+ const levelStr = typeof pinoLevel === 'number'
34
+ ? mapPinoLevelToString(pinoLevel)
35
+ : record.level;
36
+
37
+ // Ensure message is a string
38
+ const messageStr = typeof record.message === 'string'
39
+ ? record.message
40
+ : JSON.stringify(record.message);
41
+
42
+ // Remove 'level' and 'time' from fields to avoid overwriting our converted values
43
+ const { level: _level, time: _time, ...restFields } = record.fields;
44
+
45
+ return {
46
+ id: record.id, // Include ID for navigation to detail page
47
+ time: new Date(record.timestamp).toISOString(),
48
+ level: levelStr,
49
+ msg: messageStr,
50
+ plugin: record.source,
51
+ ...restFields,
52
+ };
53
+ }
54
+
55
+ /**
56
+ * Build LLM prompt for log summarization
57
+ */
58
+ function buildLogSummaryPrompt(
59
+ question: string,
60
+ logs: any[],
61
+ stats: any,
62
+ includeContext: { errors?: boolean; warnings?: boolean; info?: boolean; metadata?: boolean; stackTraces?: boolean }
63
+ ): string {
64
+ let prompt = `You are analyzing application logs. User question: "${question}"\n\n`;
65
+
66
+ // Add statistics
67
+ prompt += `Statistics:\n`;
68
+ prompt += `Total logs: ${stats.total}\n`;
69
+ prompt += `Errors: ${stats.byLevel.error || 0}\n`;
70
+ prompt += `Warnings: ${stats.byLevel.warn || 0}\n`;
71
+ prompt += `Info: ${stats.byLevel.info || 0}\n`;
72
+
73
+ if (stats.timeRange.from && stats.timeRange.to) {
74
+ prompt += `Time range: ${stats.timeRange.from} to ${stats.timeRange.to}\n`;
75
+ }
76
+
77
+ if (stats.topErrors.length > 0) {
78
+ prompt += `\nTop Errors:\n`;
79
+ stats.topErrors.slice(0, 5).forEach((err: any, idx: number) => {
80
+ prompt += `${idx + 1}. "${err.message}" (${err.count} occurrences)\n`;
81
+ });
82
+ }
83
+
84
+ // Filter logs based on includeContext
85
+ const relevantLogs = logs.filter(log => {
86
+ if (!includeContext.errors && log.level === 'error') {return false;}
87
+ if (!includeContext.warnings && log.level === 'warn') {return false;}
88
+ if (!includeContext.info && log.level === 'info') {return false;}
89
+ return true;
90
+ });
91
+
92
+ // Add log entries (limit to 100 most recent)
93
+ prompt += `\nLog Entries (${Math.min(relevantLogs.length, 100)} most recent):\n`;
94
+ relevantLogs.slice(-100).forEach(log => {
95
+ prompt += `[${log.time}] ${log.level.toUpperCase()}`;
96
+
97
+ if (includeContext.metadata && log.plugin) {
98
+ prompt += ` [${log.plugin}]`;
99
+ }
100
+
101
+ prompt += `: ${log.msg || '(no message)'}\n`;
102
+
103
+ if (includeContext.metadata && (log.traceId || log.executionId)) {
104
+ if (log.traceId) {prompt += ` traceId: ${log.traceId}\n`;}
105
+ if (log.executionId) {prompt += ` executionId: ${log.executionId}\n`;}
106
+ }
107
+
108
+ if (includeContext.stackTraces && log.err?.stack) {
109
+ prompt += ` stack: ${log.err.stack.split('\n').slice(0, 5).join('\n ')}\n`;
110
+ }
111
+ });
112
+
113
+ // Add instructions
114
+ prompt += `\nInstructions:\n`;
115
+ prompt += `Provide a clear, concise summary answering the user's question as plain text. Focus on:\n`;
116
+ prompt += `1. What happened (timeline of events)\n`;
117
+ prompt += `2. Root causes if errors are present\n`;
118
+ prompt += `3. Patterns or trends you notice\n`;
119
+ prompt += `4. Actionable recommendations if applicable\n`;
120
+ prompt += `\nKeep the summary under 300 words. Use simple paragraphs separated by double newlines. Do not use markdown formatting (no **, ##, -, or other markdown syntax). Write in clear, professional language.\n`;
121
+
122
+ return prompt;
123
+ }
124
+
125
+ /**
126
+ * Extract correlation keys from log for finding related logs
127
+ */
128
+ function extractCorrelationKeys(log: LogRecord): {
129
+ requestId?: string;
130
+ traceId?: string;
131
+ executionId?: string;
132
+ sessionId?: string;
133
+ } {
134
+ return {
135
+ requestId: log.fields.requestId as string | undefined ??
136
+ log.fields.reqId as string | undefined,
137
+ traceId: log.fields.traceId as string | undefined,
138
+ executionId: log.fields.executionId as string | undefined,
139
+ sessionId: log.fields.sessionId as string | undefined,
140
+ };
141
+ }
142
+
143
+ /**
144
+ * Find logs related to the given log
145
+ * Strategy:
146
+ * 1. Try requestId/traceId/executionId (most specific)
147
+ * 2. Fallback to time window + same source
148
+ */
149
+ async function findRelatedLogs(targetLog: LogRecord): Promise<any[]> {
150
+ const correlationKeys = extractCorrelationKeys(targetLog);
151
+ const timeWindow = 60000; // 1 minute before/after
152
+
153
+ // Strategy 1: Find by correlation IDs (most precise)
154
+ if (correlationKeys.requestId || correlationKeys.traceId || correlationKeys.executionId) {
155
+ const relatedLogs: LogRecord[] = [];
156
+
157
+ // Query all logs in time window
158
+ const result = await platform.logs.query({
159
+ from: targetLog.timestamp - timeWindow,
160
+ to: targetLog.timestamp + timeWindow,
161
+ }, {
162
+ limit: 1000,
163
+ });
164
+
165
+ // Filter in-memory by correlation keys
166
+ for (const log of result.logs) {
167
+ if (log.id === targetLog.id) {continue;} // Skip self
168
+
169
+ const logKeys = extractCorrelationKeys(log);
170
+
171
+ // Match any correlation key
172
+ if (
173
+ (correlationKeys.requestId && logKeys.requestId === correlationKeys.requestId) ||
174
+ (correlationKeys.traceId && logKeys.traceId === correlationKeys.traceId) ||
175
+ (correlationKeys.executionId && logKeys.executionId === correlationKeys.executionId) ||
176
+ (correlationKeys.sessionId && logKeys.sessionId === correlationKeys.sessionId)
177
+ ) {
178
+ relatedLogs.push(log);
179
+ }
180
+ }
181
+
182
+ if (relatedLogs.length > 0) {
183
+ return relatedLogs
184
+ .sort((a, b) => a.timestamp - b.timestamp)
185
+ .map(toFrontendLogRecord);
186
+ }
187
+ }
188
+
189
+ // Strategy 2: Fallback to time window + same source
190
+ const result = await platform.logs.query({
191
+ source: targetLog.source,
192
+ from: targetLog.timestamp - timeWindow,
193
+ to: targetLog.timestamp + timeWindow,
194
+ }, {
195
+ limit: 50,
196
+ });
197
+
198
+ return result.logs
199
+ .filter(log => log.id !== targetLog.id)
200
+ .sort((a, b) => a.timestamp - b.timestamp)
201
+ .map(toFrontendLogRecord);
202
+ }
203
+
204
+ /**
205
+ * Generate fallback summary when LLM is unavailable
206
+ */
207
+ function generateFallbackSummary(stats: any, logs: any[]): string {
208
+ let summary = `Log Summary\n\n`;
209
+
210
+ summary += `Total Logs: ${stats.total}\n\n`;
211
+
212
+ // Level breakdown
213
+ summary += `By Level:\n`;
214
+ Object.entries(stats.byLevel).forEach(([level, count]) => {
215
+ summary += `${level}: ${count}\n`;
216
+ });
217
+ summary += `\n`;
218
+
219
+ // Plugin breakdown
220
+ if (Object.keys(stats.byPlugin).length > 0) {
221
+ summary += `By Plugin:\n`;
222
+ Object.entries(stats.byPlugin)
223
+ .sort((a: any, b: any) => b[1] - a[1])
224
+ .slice(0, 5)
225
+ .forEach(([plugin, count]) => {
226
+ summary += `${plugin}: ${count}\n`;
227
+ });
228
+ summary += `\n`;
229
+ }
230
+
231
+ // Top errors
232
+ if (stats.topErrors.length > 0) {
233
+ summary += `Top Errors:\n`;
234
+ stats.topErrors.slice(0, 5).forEach((err: any, idx: number) => {
235
+ summary += `${idx + 1}. "${err.message}" (${err.count} times)\n`;
236
+ });
237
+ summary += `\n`;
238
+ }
239
+
240
+ // Time range
241
+ if (stats.timeRange.from && stats.timeRange.to) {
242
+ summary += `Time Range: ${stats.timeRange.from} to ${stats.timeRange.to}\n\n`;
243
+ }
244
+
245
+ summary += `Note: LLM summarization is not available. This is a basic statistical summary.`;
246
+
247
+ return summary;
248
+ }
249
+
250
+ /**
251
+ * Register log observability routes
252
+ */
253
+ export async function registerLogRoutes(
254
+ server: FastifyInstance,
255
+ config: RestApiConfig,
256
+ eventHub: EventHub
257
+ ): Promise<void> {
258
+ /**
259
+ * GET /api/v1/logs
260
+ * Query logs with filters
261
+ */
262
+ server.get<{
263
+ Querystring: {
264
+ from?: string;
265
+ to?: string;
266
+ level?: string;
267
+ plugin?: string;
268
+ executionId?: string;
269
+ tenantId?: string;
270
+ search?: string;
271
+ limit?: string;
272
+ offset?: string;
273
+ };
274
+ }>('/api/v1/logs', async (request, reply) => {
275
+ try {
276
+ // Parse numeric query params (Fastify doesn't parse them automatically)
277
+ const limit = request.query.limit ? parseInt(request.query.limit, 10) : 100;
278
+ const offset = request.query.offset ? parseInt(request.query.offset, 10) : 0;
279
+
280
+ // Build query from request params
281
+ const query: LogQuery = {
282
+ level: request.query.level as any,
283
+ source: request.query.plugin,
284
+ from: request.query.from ? new Date(request.query.from).getTime() : undefined,
285
+ to: request.query.to ? new Date(request.query.to).getTime() : undefined,
286
+ };
287
+
288
+ // Query logs using unified service
289
+ let result;
290
+ if (request.query.search) {
291
+ // Use full-text search if search query provided
292
+ result = await platform.logs.search(request.query.search, {
293
+ limit,
294
+ offset,
295
+ });
296
+ } else {
297
+ // Regular query with filters
298
+ result = await platform.logs.query(query, {
299
+ limit,
300
+ offset,
301
+ });
302
+ }
303
+
304
+ // Convert to frontend format
305
+ const frontendLogs = result.logs.map(toFrontendLogRecord);
306
+
307
+ // Get stats for response metadata
308
+ const stats = await platform.logs.getStats();
309
+
310
+ return {
311
+ ok: true,
312
+ data: {
313
+ logs: frontendLogs,
314
+ total: result.total,
315
+ hasMore: result.hasMore,
316
+ filters: request.query,
317
+ source: 'source' in result ? result.source : undefined,
318
+ stats: {
319
+ buffer: stats.buffer ? {
320
+ size: stats.buffer.size,
321
+ maxSize: stats.buffer.maxSize,
322
+ oldest: stats.buffer.oldestTimestamp ? new Date(stats.buffer.oldestTimestamp).toISOString() : undefined,
323
+ newest: stats.buffer.newestTimestamp ? new Date(stats.buffer.newestTimestamp).toISOString() : undefined,
324
+ } : undefined,
325
+ persistence: stats.persistence ? {
326
+ totalLogs: stats.persistence.totalLogs,
327
+ oldestTimestamp: stats.persistence.oldestTimestamp ? new Date(stats.persistence.oldestTimestamp).toISOString() : undefined,
328
+ newestTimestamp: stats.persistence.newestTimestamp ? new Date(stats.persistence.newestTimestamp).toISOString() : undefined,
329
+ sizeBytes: stats.persistence.sizeBytes,
330
+ } : undefined,
331
+ },
332
+ },
333
+ };
334
+ } catch (error: any) {
335
+ return reply.code(503).send({
336
+ ok: false,
337
+ error: 'Log query failed',
338
+ message: error?.message ?? 'Unknown error',
339
+ });
340
+ }
341
+ });
342
+
343
+ /**
344
+ * GET /api/v1/logs/:id
345
+ * Get single log by ID with related logs
346
+ */
347
+ server.get<{
348
+ Params: { id: string };
349
+ Querystring: { includeRelated?: string };
350
+ }>(
351
+ '/api/v1/logs/:id',
352
+ async (request, reply) => {
353
+ try {
354
+ const log = await platform.logs.getById(request.params.id);
355
+
356
+ if (!log) {
357
+ return reply.code(404).send({
358
+ ok: false,
359
+ error: 'Log not found',
360
+ message: `Log with ID '${request.params.id}' does not exist`,
361
+ });
362
+ }
363
+
364
+ const frontendLog = toFrontendLogRecord(log);
365
+
366
+ // Optionally include related logs
367
+ let relatedLogs: any[] = [];
368
+ if (request.query.includeRelated === 'true') {
369
+ relatedLogs = await findRelatedLogs(log);
370
+ }
371
+
372
+ return {
373
+ ok: true,
374
+ data: {
375
+ log: frontendLog,
376
+ related: relatedLogs.length > 0 ? relatedLogs : undefined,
377
+ },
378
+ };
379
+ } catch (error: any) {
380
+ return reply.code(500).send({
381
+ ok: false,
382
+ error: 'Failed to fetch log',
383
+ message: error?.message ?? 'Unknown error',
384
+ });
385
+ }
386
+ }
387
+ );
388
+
389
+ /**
390
+ * GET /api/v1/logs/:id/related
391
+ * Get logs related to a specific log (same trace/execution/request)
392
+ */
393
+ server.get<{ Params: { id: string } }>(
394
+ '/api/v1/logs/:id/related',
395
+ async (request, reply) => {
396
+ try {
397
+ const log = await platform.logs.getById(request.params.id);
398
+
399
+ if (!log) {
400
+ return reply.code(404).send({
401
+ ok: false,
402
+ error: 'Log not found',
403
+ message: `Log with ID '${request.params.id}' does not exist`,
404
+ });
405
+ }
406
+
407
+ const relatedLogs = await findRelatedLogs(log);
408
+
409
+ return {
410
+ ok: true,
411
+ data: {
412
+ total: relatedLogs.length,
413
+ logs: relatedLogs,
414
+ correlationKeys: extractCorrelationKeys(log),
415
+ },
416
+ };
417
+ } catch (error: any) {
418
+ return reply.code(500).send({
419
+ ok: false,
420
+ error: 'Failed to fetch related logs',
421
+ message: error?.message ?? 'Unknown error',
422
+ });
423
+ }
424
+ }
425
+ );
426
+
427
+ /**
428
+ * GET /api/v1/logs/stream
429
+ * Server-Sent Events stream for real-time logs
430
+ */
431
+ server.get('/api/v1/logs/stream', async (request, reply) => {
432
+ // Check if streaming is supported
433
+ const caps = platform.logs.getCapabilities();
434
+ if (!caps.hasStreaming) {
435
+ return reply.code(503).send({
436
+ error: 'Log streaming not enabled',
437
+ message: 'Logger adapter does not support streaming. Enable logRingBuffer in kb.config.json',
438
+ });
439
+ }
440
+
441
+ // Tell Fastify we're manually managing the response
442
+ reply.hijack();
443
+
444
+ // Track if stream is closed to prevent double-end
445
+ let streamClosed = false;
446
+
447
+ // Explicit CORS headers for EventSource
448
+ const origin = request.headers.origin;
449
+ if (origin === 'http://localhost:3000' || origin === 'http://localhost:5173') {
450
+ reply.raw.setHeader('Access-Control-Allow-Origin', origin);
451
+ reply.raw.setHeader('Access-Control-Allow-Credentials', 'true');
452
+ } else {
453
+ reply.raw.setHeader('Access-Control-Allow-Origin', '*');
454
+ }
455
+
456
+ // Setup SSE headers
457
+ reply.raw.setHeader('Content-Type', 'text/event-stream');
458
+ reply.raw.setHeader('Cache-Control', 'no-cache, no-transform');
459
+ reply.raw.setHeader('Connection', 'keep-alive');
460
+
461
+ try {
462
+ reply.raw.flushHeaders?.();
463
+ reply.raw.write(': connected\n\n');
464
+ } catch (err) {
465
+ // Headers already sent or connection closed
466
+ streamClosed = true;
467
+ return;
468
+ }
469
+
470
+ // Subscribe to log stream using unified service
471
+ const unsubscribe = platform.logs.subscribe((log) => {
472
+ // Check if connection is still alive before writing
473
+ if (!streamClosed && !reply.raw.writableEnded && !reply.raw.destroyed) {
474
+ try {
475
+ // Frontend expects event name 'log'
476
+ const frontendLog = toFrontendLogRecord(log);
477
+ reply.raw.write(`event: log\n`);
478
+ reply.raw.write(`data: ${JSON.stringify(frontendLog)}\n\n`);
479
+ } catch (err) {
480
+ // Connection closed while writing - ignore
481
+ streamClosed = true;
482
+ }
483
+ }
484
+ });
485
+
486
+ // Cleanup on disconnect
487
+ const cleanup = () => {
488
+ if (!streamClosed) {
489
+ streamClosed = true;
490
+ unsubscribe();
491
+ try {
492
+ if (!reply.raw.writableEnded && !reply.raw.destroyed) {
493
+ reply.raw.end();
494
+ }
495
+ } catch (err) {
496
+ // Already closed - ignore
497
+ }
498
+ }
499
+ };
500
+
501
+ request.raw.on('close', cleanup);
502
+ request.raw.on('error', cleanup);
503
+
504
+ // Keep connection alive indefinitely
505
+ await new Promise<void>(() => {});
506
+ });
507
+
508
+ /**
509
+ * GET /api/v1/logs/stats
510
+ * Get combined log statistics from all backends
511
+ */
512
+ server.get('/api/v1/logs/stats', async (request, reply) => {
513
+ try {
514
+ const stats = await platform.logs.getStats();
515
+ const caps = platform.logs.getCapabilities();
516
+
517
+ return {
518
+ ok: true,
519
+ data: {
520
+ capabilities: caps,
521
+ buffer: stats.buffer ? {
522
+ size: stats.buffer.size,
523
+ maxSize: stats.buffer.maxSize,
524
+ oldest: stats.buffer.oldestTimestamp ? new Date(stats.buffer.oldestTimestamp).toISOString() : undefined,
525
+ newest: stats.buffer.newestTimestamp ? new Date(stats.buffer.newestTimestamp).toISOString() : undefined,
526
+ } : undefined,
527
+ persistence: stats.persistence ? {
528
+ totalLogs: stats.persistence.totalLogs,
529
+ oldest: stats.persistence.oldestTimestamp ? new Date(stats.persistence.oldestTimestamp).toISOString() : undefined,
530
+ newest: stats.persistence.newestTimestamp ? new Date(stats.persistence.newestTimestamp).toISOString() : undefined,
531
+ sizeBytes: stats.persistence.sizeBytes,
532
+ } : undefined,
533
+ },
534
+ };
535
+ } catch (error: any) {
536
+ return reply.code(500).send({
537
+ ok: false,
538
+ error: 'Failed to fetch stats',
539
+ message: error?.message ?? 'Unknown error',
540
+ });
541
+ }
542
+ });
543
+
544
+ /**
545
+ * POST /api/v1/logs/summarize
546
+ * AI-powered log summarization (placeholder for future implementation)
547
+ *
548
+ * Expected request body:
549
+ * {
550
+ * "timeRange": { "from": "ISO timestamp", "to": "ISO timestamp" },
551
+ * "filters": { "level": "error", "plugin": "rest", "traceId": "..." },
552
+ * "groupBy": "trace" | "execution" | "plugin",
553
+ * "question": "What happened in the last 5 minutes?" (optional)
554
+ * }
555
+ */
556
+ server.post<{
557
+ Body: {
558
+ timeRange?: { from?: string; to?: string };
559
+ filters?: {
560
+ level?: string;
561
+ plugin?: string;
562
+ traceId?: string;
563
+ executionId?: string;
564
+ };
565
+ groupBy?: 'trace' | 'execution' | 'plugin';
566
+ question?: string;
567
+ includeContext?: {
568
+ errors?: boolean;
569
+ warnings?: boolean;
570
+ info?: boolean;
571
+ metadata?: boolean;
572
+ stackTraces?: boolean;
573
+ };
574
+ };
575
+ }>('/api/v1/logs/summarize', async (request, reply) => {
576
+ const { timeRange, filters, groupBy, question, includeContext } = request.body;
577
+
578
+ try {
579
+ // Build query from request
580
+ const query: LogQuery = {
581
+ level: filters?.level as any,
582
+ source: filters?.plugin,
583
+ from: timeRange?.from ? new Date(timeRange.from).getTime() : undefined,
584
+ to: timeRange?.to ? new Date(timeRange.to).getTime() : undefined,
585
+ };
586
+
587
+ // Query logs using unified service
588
+ const result = await platform.logs.query(query, { limit: 1000 });
589
+ const frontendLogs = result.logs.map(toFrontendLogRecord);
590
+
591
+ // Additional filters (traceId, executionId)
592
+ let filteredLogs = frontendLogs;
593
+ if (filters?.traceId) {
594
+ filteredLogs = filteredLogs.filter((log) => log.traceId === filters.traceId);
595
+ }
596
+ if (filters?.executionId) {
597
+ filteredLogs = filteredLogs.filter((log) => log.executionId === filters.executionId);
598
+ }
599
+
600
+ // Calculate aggregated statistics
601
+ const stats = {
602
+ total: filteredLogs.length,
603
+ byLevel: {} as Record<string, number>,
604
+ byPlugin: {} as Record<string, number>,
605
+ topErrors: [] as Array<{ message: string; count: number }>,
606
+ timeRange: {
607
+ from: filteredLogs.length > 0 ? filteredLogs[0]!.time : null,
608
+ to: filteredLogs.length > 0 ? filteredLogs[filteredLogs.length - 1]!.time : null,
609
+ },
610
+ };
611
+
612
+ const errorMessages = new Map<string, number>();
613
+
614
+ for (const log of filteredLogs) {
615
+ // Count by level
616
+ stats.byLevel[log.level] = (stats.byLevel[log.level] || 0) + 1;
617
+
618
+ // Count by plugin
619
+ if (log.plugin) {
620
+ stats.byPlugin[log.plugin] = (stats.byPlugin[log.plugin] || 0) + 1;
621
+ }
622
+
623
+ // Track error messages
624
+ if (log.level === 'error' && log.msg) {
625
+ errorMessages.set(log.msg, (errorMessages.get(log.msg) || 0) + 1);
626
+ }
627
+ }
628
+
629
+ // Top 10 errors
630
+ stats.topErrors = Array.from(errorMessages.entries())
631
+ .map(([message, count]) => ({ message, count }))
632
+ .sort((a, b) => b.count - a.count)
633
+ .slice(0, 10);
634
+
635
+ // Group logs if requested
636
+ let groups: Record<string, any[]> | null = null;
637
+ if (groupBy) {
638
+ // Map frontend groupBy values to actual log field names
639
+ const fieldMap: Record<string, string> = {
640
+ trace: 'traceId',
641
+ execution: 'executionId',
642
+ plugin: 'plugin',
643
+ };
644
+
645
+ const groupMap = new Map<string, any[]>();
646
+ for (const log of filteredLogs) {
647
+ const fieldName = fieldMap[groupBy] || groupBy;
648
+ const key = String(log[fieldName] || 'unknown');
649
+ if (!groupMap.has(key)) {
650
+ groupMap.set(key, []);
651
+ }
652
+ groupMap.get(key)!.push(log);
653
+ }
654
+ groups = Object.fromEntries(groupMap.entries());
655
+ }
656
+
657
+ // AI Summarization
658
+ let aiSummary: string | null = null;
659
+ let message: string | null = null;
660
+
661
+ if (platform.llm && question) {
662
+ try {
663
+ const context = includeContext || {
664
+ errors: true,
665
+ warnings: true,
666
+ info: false,
667
+ metadata: true,
668
+ stackTraces: true,
669
+ };
670
+
671
+ const prompt = buildLogSummaryPrompt(question, filteredLogs, stats, context);
672
+
673
+ const response = await platform.llm.complete(prompt, {
674
+ temperature: 0.7,
675
+ maxTokens: 1000,
676
+ systemPrompt: 'You are a technical log analysis assistant. Provide clear, actionable insights based on application logs.',
677
+ });
678
+
679
+ aiSummary = response.content.trim();
680
+
681
+ } catch (error) {
682
+ // Graceful degradation
683
+ platform.logger.warn('LLM summarization failed, using fallback', {
684
+ error: error instanceof Error ? error.message : String(error),
685
+ });
686
+ aiSummary = generateFallbackSummary(stats, filteredLogs);
687
+ message = 'AI summarization unavailable, showing statistical summary';
688
+ }
689
+ } else {
690
+ // No LLM or no question - return fallback
691
+ aiSummary = generateFallbackSummary(stats, filteredLogs);
692
+ message = platform.llm ? 'No question provided' : 'LLM not configured';
693
+ }
694
+
695
+ // Return structured data with AI summary
696
+ return {
697
+ ok: true,
698
+ data: {
699
+ summary: {
700
+ question: question || 'General log summary',
701
+ timeRange: stats.timeRange,
702
+ total: stats.total,
703
+ stats,
704
+ groups,
705
+ },
706
+ aiSummary,
707
+ message,
708
+ },
709
+ };
710
+ } catch (error: any) {
711
+ return reply.code(500).send({
712
+ ok: false,
713
+ error: 'Log summarization failed',
714
+ message: error?.message ?? 'Unknown error',
715
+ });
716
+ }
717
+ });
718
+ }