@kb-labs/rest-api-app 1.3.0 → 1.4.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 (257) hide show
  1. package/dist/index.d.ts +2 -0
  2. package/dist/index.js +8151 -0
  3. package/dist/index.js.map +1 -0
  4. package/package.json +7 -4
  5. package/.kb/agents/sessions/session-1771531145393-ws3uh6q/turns.json +0 -42
  6. package/.kb/agents/sessions/session-1771548930486-ui6rtvm/turns.json +0 -33
  7. package/.kb/agents/sessions/session-1771549691485-nibqroq/turns.json +0 -133
  8. package/.kb/agents/sessions/session-1771550943182-dkwqdjc/turns.json +0 -130
  9. package/.kb/agents/sessions/session-1771551564182-cr4bwzn/turns.json +0 -349
  10. package/.kb/agents/sessions/session-1771552401370-g4ztwd1/turns.json +0 -206
  11. package/.kb/commit/current/plan.json +0 -248
  12. package/.kb/commit/current/status.json +0 -472
  13. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/commands/health.d.ts +0 -10
  14. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/commands/health.js +0 -215
  15. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/commands/health.js.map +0 -1
  16. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/commands/list.d.ts +0 -10
  17. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/commands/list.js +0 -271
  18. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/commands/list.js.map +0 -1
  19. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/commands/logs.d.ts +0 -10
  20. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/commands/logs.js +0 -230
  21. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/commands/logs.js.map +0 -1
  22. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/commands/metrics.d.ts +0 -10
  23. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/commands/metrics.js +0 -228
  24. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/commands/metrics.js.map +0 -1
  25. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/commands/run.d.ts +0 -11
  26. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/commands/run.js +0 -281
  27. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/commands/run.js.map +0 -1
  28. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/commands/status.d.ts +0 -10
  29. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/commands/status.js +0 -266
  30. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/commands/status.js.map +0 -1
  31. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/commands/workflow-run.d.ts +0 -11
  32. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/commands/workflow-run.js +0 -284
  33. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/commands/workflow-run.js.map +0 -1
  34. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/flags-WLdpSZl4.d.ts +0 -77
  35. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/index.d.ts +0 -2
  36. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/index.js +0 -441
  37. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/index.js.map +0 -1
  38. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/manifest.d.ts +0 -196
  39. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/manifest.js +0 -441
  40. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/manifest.js.map +0 -1
  41. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/cron-list-handler.d.ts +0 -19
  42. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/cron-list-handler.js +0 -48
  43. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/cron-list-handler.js.map +0 -1
  44. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/index.d.ts +0 -6
  45. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/index.js +0 -170
  46. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/index.js.map +0 -1
  47. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/job-cancel-handler.d.ts +0 -12
  48. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/job-cancel-handler.js +0 -52
  49. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/job-cancel-handler.js.map +0 -1
  50. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/job-detail-handler.d.ts +0 -22
  51. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/job-detail-handler.js +0 -52
  52. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/job-detail-handler.js.map +0 -1
  53. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/job-logs-handler.d.ts +0 -13
  54. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/job-logs-handler.js +0 -52
  55. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/job-logs-handler.js.map +0 -1
  56. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/job-steps-handler.d.ts +0 -9
  57. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/job-steps-handler.js +0 -43
  58. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/job-steps-handler.js.map +0 -1
  59. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/jobs-list-handler.d.ts +0 -26
  60. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/jobs-list-handler.js +0 -63
  61. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/jobs-list-handler.js.map +0 -1
  62. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/pending-approvals-handler.d.ts +0 -9
  63. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/pending-approvals-handler.js +0 -46
  64. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/pending-approvals-handler.js.map +0 -1
  65. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/resolve-approval-handler.d.ts +0 -16
  66. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/resolve-approval-handler.js +0 -58
  67. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/resolve-approval-handler.js.map +0 -1
  68. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/run-detail-handler.d.ts +0 -9
  69. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/run-detail-handler.js +0 -46
  70. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/run-detail-handler.js.map +0 -1
  71. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/runs-list-handler.d.ts +0 -11
  72. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/runs-list-handler.js +0 -50
  73. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/runs-list-handler.js.map +0 -1
  74. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/stats-handler.d.ts +0 -7
  75. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/stats-handler.js +0 -39
  76. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/stats-handler.js.map +0 -1
  77. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/workflow-detail-handler.d.ts +0 -10
  78. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/workflow-detail-handler.js +0 -46
  79. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/workflow-detail-handler.js.map +0 -1
  80. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/workflow-run-cancel-handler.d.ts +0 -13
  81. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/workflow-run-cancel-handler.js +0 -47
  82. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/workflow-run-cancel-handler.js.map +0 -1
  83. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/workflow-run-handler.d.ts +0 -14
  84. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/workflow-run-handler.js +0 -53
  85. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/workflow-run-handler.js.map +0 -1
  86. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/workflow-runs-handler.d.ts +0 -13
  87. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/workflow-runs-handler.js +0 -54
  88. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/workflow-runs-handler.js.map +0 -1
  89. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/workflows-list-handler.d.ts +0 -12
  90. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/workflows-list-handler.js +0 -51
  91. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/workflows-list-handler.js.map +0 -1
  92. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/ws/logs-channel.d.ts +0 -17
  93. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/ws/logs-channel.js +0 -133
  94. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/ws/logs-channel.js.map +0 -1
  95. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/ws/progress-channel.d.ts +0 -11
  96. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/ws/progress-channel.js +0 -46
  97. package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/ws/progress-channel.js.map +0 -1
  98. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/commands/health.d.ts +0 -10
  99. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/commands/health.js +0 -215
  100. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/commands/health.js.map +0 -1
  101. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/commands/list.d.ts +0 -10
  102. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/commands/list.js +0 -271
  103. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/commands/list.js.map +0 -1
  104. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/commands/logs.d.ts +0 -10
  105. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/commands/logs.js +0 -230
  106. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/commands/logs.js.map +0 -1
  107. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/commands/metrics.d.ts +0 -10
  108. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/commands/metrics.js +0 -228
  109. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/commands/metrics.js.map +0 -1
  110. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/commands/run.d.ts +0 -11
  111. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/commands/run.js +0 -281
  112. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/commands/run.js.map +0 -1
  113. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/commands/status.d.ts +0 -10
  114. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/commands/status.js +0 -266
  115. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/commands/status.js.map +0 -1
  116. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/commands/workflow-run.d.ts +0 -11
  117. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/commands/workflow-run.js +0 -284
  118. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/commands/workflow-run.js.map +0 -1
  119. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/flags-WLdpSZl4.d.ts +0 -77
  120. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/index.d.ts +0 -2
  121. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/index.js +0 -441
  122. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/index.js.map +0 -1
  123. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/manifest.d.ts +0 -196
  124. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/manifest.js +0 -441
  125. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/manifest.js.map +0 -1
  126. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/cron-list-handler.d.ts +0 -19
  127. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/cron-list-handler.js +0 -48
  128. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/cron-list-handler.js.map +0 -1
  129. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/index.d.ts +0 -6
  130. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/index.js +0 -170
  131. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/index.js.map +0 -1
  132. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/job-cancel-handler.d.ts +0 -12
  133. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/job-cancel-handler.js +0 -52
  134. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/job-cancel-handler.js.map +0 -1
  135. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/job-detail-handler.d.ts +0 -22
  136. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/job-detail-handler.js +0 -52
  137. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/job-detail-handler.js.map +0 -1
  138. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/job-logs-handler.d.ts +0 -13
  139. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/job-logs-handler.js +0 -52
  140. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/job-logs-handler.js.map +0 -1
  141. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/job-steps-handler.d.ts +0 -9
  142. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/job-steps-handler.js +0 -43
  143. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/job-steps-handler.js.map +0 -1
  144. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/jobs-list-handler.d.ts +0 -26
  145. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/jobs-list-handler.js +0 -63
  146. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/jobs-list-handler.js.map +0 -1
  147. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/pending-approvals-handler.d.ts +0 -9
  148. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/pending-approvals-handler.js +0 -46
  149. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/pending-approvals-handler.js.map +0 -1
  150. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/resolve-approval-handler.d.ts +0 -16
  151. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/resolve-approval-handler.js +0 -58
  152. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/resolve-approval-handler.js.map +0 -1
  153. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/run-detail-handler.d.ts +0 -9
  154. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/run-detail-handler.js +0 -46
  155. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/run-detail-handler.js.map +0 -1
  156. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/runs-list-handler.d.ts +0 -11
  157. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/runs-list-handler.js +0 -50
  158. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/runs-list-handler.js.map +0 -1
  159. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/stats-handler.d.ts +0 -7
  160. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/stats-handler.js +0 -39
  161. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/stats-handler.js.map +0 -1
  162. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/workflow-detail-handler.d.ts +0 -10
  163. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/workflow-detail-handler.js +0 -46
  164. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/workflow-detail-handler.js.map +0 -1
  165. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/workflow-run-cancel-handler.d.ts +0 -13
  166. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/workflow-run-cancel-handler.js +0 -47
  167. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/workflow-run-cancel-handler.js.map +0 -1
  168. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/workflow-run-handler.d.ts +0 -14
  169. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/workflow-run-handler.js +0 -53
  170. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/workflow-run-handler.js.map +0 -1
  171. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/workflow-runs-handler.d.ts +0 -13
  172. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/workflow-runs-handler.js +0 -54
  173. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/workflow-runs-handler.js.map +0 -1
  174. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/workflows-list-handler.d.ts +0 -12
  175. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/workflows-list-handler.js +0 -51
  176. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/workflows-list-handler.js.map +0 -1
  177. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/ws/logs-channel.d.ts +0 -17
  178. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/ws/logs-channel.js +0 -133
  179. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/ws/logs-channel.js.map +0 -1
  180. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/ws/progress-channel.d.ts +0 -11
  181. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/ws/progress-channel.js +0 -46
  182. package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/ws/progress-channel.js.map +0 -1
  183. package/eslint.config.js +0 -23
  184. package/src/.kb/agents/sessions/session-1773470583796-ximqnfk/kpi-baseline.json +0 -17
  185. package/src/.kb/memory/sessions/session-1773470583796-ximqnfk/fact-sheet.json +0 -1
  186. package/src/bootstrap.ts +0 -233
  187. package/src/diagnostics/header-debug.ts +0 -37
  188. package/src/events/hub.ts +0 -60
  189. package/src/events/index.ts +0 -1
  190. package/src/index.ts +0 -13
  191. package/src/manifest.ts +0 -21
  192. package/src/middleware/__tests__/cache.spec.ts +0 -184
  193. package/src/middleware/__tests__/envelope.spec.ts +0 -268
  194. package/src/middleware/__tests__/metrics.redis.spec.ts +0 -64
  195. package/src/middleware/__tests__/rate-limit.spec.ts +0 -283
  196. package/src/middleware/__tests__/request-id.spec.ts +0 -160
  197. package/src/middleware/cache.ts +0 -67
  198. package/src/middleware/envelope.ts +0 -136
  199. package/src/middleware/error-guard.ts +0 -69
  200. package/src/middleware/index.ts +0 -37
  201. package/src/middleware/metrics.ts +0 -810
  202. package/src/middleware/mock-mode.ts +0 -44
  203. package/src/middleware/prom-metrics.ts +0 -284
  204. package/src/middleware/rate-limit-routes.ts +0 -73
  205. package/src/middleware/rate-limit.ts +0 -72
  206. package/src/middleware/request-id.ts +0 -41
  207. package/src/middleware/request-timeout.ts +0 -69
  208. package/src/middleware/security-headers.ts +0 -24
  209. package/src/middleware/startup-guard.ts +0 -107
  210. package/src/observability/service-contract.ts +0 -192
  211. package/src/plugins/index.ts +0 -118
  212. package/src/routes/__tests__/adapters-date-helpers.spec.ts +0 -332
  213. package/src/routes/__tests__/adapters.spec.ts +0 -680
  214. package/src/routes/__tests__/cache.spec.ts +0 -264
  215. package/src/routes/__tests__/events.spec.ts +0 -434
  216. package/src/routes/__tests__/health.spec.ts +0 -414
  217. package/src/routes/__tests__/logs.spec.ts +0 -494
  218. package/src/routes/__tests__/observability.spec.ts +0 -392
  219. package/src/routes/__tests__/plugins.spec.ts +0 -931
  220. package/src/routes/__tests__/workflow-management.spec.ts +0 -698
  221. package/src/routes/__tests__/workflows.spec.ts +0 -204
  222. package/src/routes/adapter-call.ts +0 -220
  223. package/src/routes/adapters.ts +0 -1206
  224. package/src/routes/analytics.ts +0 -328
  225. package/src/routes/cache.ts +0 -104
  226. package/src/routes/debug-routes.ts +0 -95
  227. package/src/routes/events.ts +0 -115
  228. package/src/routes/health.ts +0 -348
  229. package/src/routes/hello.ts +0 -47
  230. package/src/routes/index.ts +0 -395
  231. package/src/routes/jobs.ts +0 -253
  232. package/src/routes/logs.ts +0 -718
  233. package/src/routes/metrics.ts +0 -120
  234. package/src/routes/observability.ts +0 -1388
  235. package/src/routes/openapi.ts +0 -101
  236. package/src/routes/platform.ts +0 -143
  237. package/src/routes/plugins.ts +0 -998
  238. package/src/routes/readiness.ts +0 -83
  239. package/src/routes/workflow-management.ts +0 -469
  240. package/src/routes/workflows.ts +0 -256
  241. package/src/server.ts +0 -203
  242. package/src/services/historical-metrics.ts +0 -496
  243. package/src/services/incident-analyzer.ts +0 -289
  244. package/src/services/incident-detector.ts +0 -691
  245. package/src/services/incident-schema.sql +0 -76
  246. package/src/services/incident-storage.ts +0 -593
  247. package/src/services/system-metrics-collector.ts +0 -244
  248. package/src/types/fastify.d.ts +0 -58
  249. package/src/utils/__tests__/sse-auth.spec.ts +0 -113
  250. package/src/utils/path-helpers.ts +0 -15
  251. package/src/utils/repo.ts +0 -42
  252. package/src/utils/schema.ts +0 -20
  253. package/src/utils/sse-auth.ts +0 -81
  254. package/test-sandbox.sh +0 -105
  255. package/tsconfig.build.json +0 -15
  256. package/tsconfig.json +0 -9
  257. package/tsup.config.ts +0 -18
@@ -1,718 +0,0 @@
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
- }