@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.
- package/dist/index.d.ts +2 -0
- package/dist/index.js +8151 -0
- package/dist/index.js.map +1 -0
- package/package.json +7 -4
- package/.kb/agents/sessions/session-1771531145393-ws3uh6q/turns.json +0 -42
- package/.kb/agents/sessions/session-1771548930486-ui6rtvm/turns.json +0 -33
- package/.kb/agents/sessions/session-1771549691485-nibqroq/turns.json +0 -133
- package/.kb/agents/sessions/session-1771550943182-dkwqdjc/turns.json +0 -130
- package/.kb/agents/sessions/session-1771551564182-cr4bwzn/turns.json +0 -349
- package/.kb/agents/sessions/session-1771552401370-g4ztwd1/turns.json +0 -206
- package/.kb/commit/current/plan.json +0 -248
- package/.kb/commit/current/status.json +0 -472
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/commands/health.d.ts +0 -10
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/commands/health.js +0 -215
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/commands/health.js.map +0 -1
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/commands/list.d.ts +0 -10
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/commands/list.js +0 -271
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/commands/list.js.map +0 -1
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/commands/logs.d.ts +0 -10
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/commands/logs.js +0 -230
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/commands/logs.js.map +0 -1
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/commands/metrics.d.ts +0 -10
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/commands/metrics.js +0 -228
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/commands/metrics.js.map +0 -1
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/commands/run.d.ts +0 -11
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/commands/run.js +0 -281
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/commands/run.js.map +0 -1
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/commands/status.d.ts +0 -10
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/commands/status.js +0 -266
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/commands/status.js.map +0 -1
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/commands/workflow-run.d.ts +0 -11
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/commands/workflow-run.js +0 -284
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/commands/workflow-run.js.map +0 -1
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/flags-WLdpSZl4.d.ts +0 -77
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/index.d.ts +0 -2
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/index.js +0 -441
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/index.js.map +0 -1
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/manifest.d.ts +0 -196
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/manifest.js +0 -441
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/manifest.js.map +0 -1
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/cron-list-handler.d.ts +0 -19
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/cron-list-handler.js +0 -48
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/cron-list-handler.js.map +0 -1
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/index.d.ts +0 -6
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/index.js +0 -170
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/index.js.map +0 -1
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/job-cancel-handler.d.ts +0 -12
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/job-cancel-handler.js +0 -52
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/job-cancel-handler.js.map +0 -1
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/job-detail-handler.d.ts +0 -22
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/job-detail-handler.js +0 -52
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/job-detail-handler.js.map +0 -1
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/job-logs-handler.d.ts +0 -13
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/job-logs-handler.js +0 -52
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/job-logs-handler.js.map +0 -1
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/job-steps-handler.d.ts +0 -9
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/job-steps-handler.js +0 -43
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/job-steps-handler.js.map +0 -1
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/jobs-list-handler.d.ts +0 -26
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/jobs-list-handler.js +0 -63
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/jobs-list-handler.js.map +0 -1
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/pending-approvals-handler.d.ts +0 -9
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/pending-approvals-handler.js +0 -46
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/pending-approvals-handler.js.map +0 -1
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/resolve-approval-handler.d.ts +0 -16
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/resolve-approval-handler.js +0 -58
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/resolve-approval-handler.js.map +0 -1
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/run-detail-handler.d.ts +0 -9
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/run-detail-handler.js +0 -46
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/run-detail-handler.js.map +0 -1
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/runs-list-handler.d.ts +0 -11
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/runs-list-handler.js +0 -50
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/runs-list-handler.js.map +0 -1
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/stats-handler.d.ts +0 -7
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/stats-handler.js +0 -39
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/stats-handler.js.map +0 -1
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/workflow-detail-handler.d.ts +0 -10
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/workflow-detail-handler.js +0 -46
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/workflow-detail-handler.js.map +0 -1
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/workflow-run-cancel-handler.d.ts +0 -13
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/workflow-run-cancel-handler.js +0 -47
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/workflow-run-cancel-handler.js.map +0 -1
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/workflow-run-handler.d.ts +0 -14
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/workflow-run-handler.js +0 -53
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/workflow-run-handler.js.map +0 -1
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/workflow-runs-handler.d.ts +0 -13
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/workflow-runs-handler.js +0 -54
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/workflow-runs-handler.js.map +0 -1
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/workflows-list-handler.d.ts +0 -12
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/workflows-list-handler.js +0 -51
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/workflows-list-handler.js.map +0 -1
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/ws/logs-channel.d.ts +0 -17
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/ws/logs-channel.js +0 -133
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/ws/logs-channel.js.map +0 -1
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/ws/progress-channel.d.ts +0 -11
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/ws/progress-channel.js +0 -46
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/ws/progress-channel.js.map +0 -1
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/commands/health.d.ts +0 -10
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/commands/health.js +0 -215
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/commands/health.js.map +0 -1
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/commands/list.d.ts +0 -10
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/commands/list.js +0 -271
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/commands/list.js.map +0 -1
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/commands/logs.d.ts +0 -10
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/commands/logs.js +0 -230
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/commands/logs.js.map +0 -1
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/commands/metrics.d.ts +0 -10
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/commands/metrics.js +0 -228
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/commands/metrics.js.map +0 -1
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/commands/run.d.ts +0 -11
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/commands/run.js +0 -281
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/commands/run.js.map +0 -1
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/commands/status.d.ts +0 -10
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/commands/status.js +0 -266
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/commands/status.js.map +0 -1
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/commands/workflow-run.d.ts +0 -11
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/commands/workflow-run.js +0 -284
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/commands/workflow-run.js.map +0 -1
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/flags-WLdpSZl4.d.ts +0 -77
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/index.d.ts +0 -2
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/index.js +0 -441
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/index.js.map +0 -1
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/manifest.d.ts +0 -196
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/manifest.js +0 -441
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/manifest.js.map +0 -1
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/cron-list-handler.d.ts +0 -19
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/cron-list-handler.js +0 -48
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/cron-list-handler.js.map +0 -1
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/index.d.ts +0 -6
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/index.js +0 -170
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/index.js.map +0 -1
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/job-cancel-handler.d.ts +0 -12
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/job-cancel-handler.js +0 -52
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/job-cancel-handler.js.map +0 -1
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/job-detail-handler.d.ts +0 -22
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/job-detail-handler.js +0 -52
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/job-detail-handler.js.map +0 -1
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/job-logs-handler.d.ts +0 -13
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/job-logs-handler.js +0 -52
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/job-logs-handler.js.map +0 -1
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/job-steps-handler.d.ts +0 -9
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/job-steps-handler.js +0 -43
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/job-steps-handler.js.map +0 -1
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/jobs-list-handler.d.ts +0 -26
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/jobs-list-handler.js +0 -63
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/jobs-list-handler.js.map +0 -1
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/pending-approvals-handler.d.ts +0 -9
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/pending-approvals-handler.js +0 -46
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/pending-approvals-handler.js.map +0 -1
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/resolve-approval-handler.d.ts +0 -16
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/resolve-approval-handler.js +0 -58
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/resolve-approval-handler.js.map +0 -1
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/run-detail-handler.d.ts +0 -9
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/run-detail-handler.js +0 -46
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/run-detail-handler.js.map +0 -1
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/runs-list-handler.d.ts +0 -11
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/runs-list-handler.js +0 -50
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/runs-list-handler.js.map +0 -1
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/stats-handler.d.ts +0 -7
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/stats-handler.js +0 -39
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/stats-handler.js.map +0 -1
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/workflow-detail-handler.d.ts +0 -10
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/workflow-detail-handler.js +0 -46
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/workflow-detail-handler.js.map +0 -1
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/workflow-run-cancel-handler.d.ts +0 -13
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/workflow-run-cancel-handler.js +0 -47
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/workflow-run-cancel-handler.js.map +0 -1
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/workflow-run-handler.d.ts +0 -14
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/workflow-run-handler.js +0 -53
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/workflow-run-handler.js.map +0 -1
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/workflow-runs-handler.d.ts +0 -13
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/workflow-runs-handler.js +0 -54
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/workflow-runs-handler.js.map +0 -1
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/workflows-list-handler.d.ts +0 -12
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/workflows-list-handler.js +0 -51
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/workflows-list-handler.js.map +0 -1
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/ws/logs-channel.d.ts +0 -17
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/ws/logs-channel.js +0 -133
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/ws/logs-channel.js.map +0 -1
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/ws/progress-channel.d.ts +0 -11
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/ws/progress-channel.js +0 -46
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/ws/progress-channel.js.map +0 -1
- package/eslint.config.js +0 -23
- package/src/.kb/agents/sessions/session-1773470583796-ximqnfk/kpi-baseline.json +0 -17
- package/src/.kb/memory/sessions/session-1773470583796-ximqnfk/fact-sheet.json +0 -1
- package/src/bootstrap.ts +0 -233
- package/src/diagnostics/header-debug.ts +0 -37
- package/src/events/hub.ts +0 -60
- package/src/events/index.ts +0 -1
- package/src/index.ts +0 -13
- package/src/manifest.ts +0 -21
- package/src/middleware/__tests__/cache.spec.ts +0 -184
- package/src/middleware/__tests__/envelope.spec.ts +0 -268
- package/src/middleware/__tests__/metrics.redis.spec.ts +0 -64
- package/src/middleware/__tests__/rate-limit.spec.ts +0 -283
- package/src/middleware/__tests__/request-id.spec.ts +0 -160
- package/src/middleware/cache.ts +0 -67
- package/src/middleware/envelope.ts +0 -136
- package/src/middleware/error-guard.ts +0 -69
- package/src/middleware/index.ts +0 -37
- package/src/middleware/metrics.ts +0 -810
- package/src/middleware/mock-mode.ts +0 -44
- package/src/middleware/prom-metrics.ts +0 -284
- package/src/middleware/rate-limit-routes.ts +0 -73
- package/src/middleware/rate-limit.ts +0 -72
- package/src/middleware/request-id.ts +0 -41
- package/src/middleware/request-timeout.ts +0 -69
- package/src/middleware/security-headers.ts +0 -24
- package/src/middleware/startup-guard.ts +0 -107
- package/src/observability/service-contract.ts +0 -192
- package/src/plugins/index.ts +0 -118
- package/src/routes/__tests__/adapters-date-helpers.spec.ts +0 -332
- package/src/routes/__tests__/adapters.spec.ts +0 -680
- package/src/routes/__tests__/cache.spec.ts +0 -264
- package/src/routes/__tests__/events.spec.ts +0 -434
- package/src/routes/__tests__/health.spec.ts +0 -414
- package/src/routes/__tests__/logs.spec.ts +0 -494
- package/src/routes/__tests__/observability.spec.ts +0 -392
- package/src/routes/__tests__/plugins.spec.ts +0 -931
- package/src/routes/__tests__/workflow-management.spec.ts +0 -698
- package/src/routes/__tests__/workflows.spec.ts +0 -204
- package/src/routes/adapter-call.ts +0 -220
- package/src/routes/adapters.ts +0 -1206
- package/src/routes/analytics.ts +0 -328
- package/src/routes/cache.ts +0 -104
- package/src/routes/debug-routes.ts +0 -95
- package/src/routes/events.ts +0 -115
- package/src/routes/health.ts +0 -348
- package/src/routes/hello.ts +0 -47
- package/src/routes/index.ts +0 -395
- package/src/routes/jobs.ts +0 -253
- package/src/routes/logs.ts +0 -718
- package/src/routes/metrics.ts +0 -120
- package/src/routes/observability.ts +0 -1388
- package/src/routes/openapi.ts +0 -101
- package/src/routes/platform.ts +0 -143
- package/src/routes/plugins.ts +0 -998
- package/src/routes/readiness.ts +0 -83
- package/src/routes/workflow-management.ts +0 -469
- package/src/routes/workflows.ts +0 -256
- package/src/server.ts +0 -203
- package/src/services/historical-metrics.ts +0 -496
- package/src/services/incident-analyzer.ts +0 -289
- package/src/services/incident-detector.ts +0 -691
- package/src/services/incident-schema.sql +0 -76
- package/src/services/incident-storage.ts +0 -593
- package/src/services/system-metrics-collector.ts +0 -244
- package/src/types/fastify.d.ts +0 -58
- package/src/utils/__tests__/sse-auth.spec.ts +0 -113
- package/src/utils/path-helpers.ts +0 -15
- package/src/utils/repo.ts +0 -42
- package/src/utils/schema.ts +0 -20
- package/src/utils/sse-auth.ts +0 -81
- package/test-sandbox.sh +0 -105
- package/tsconfig.build.json +0 -15
- package/tsconfig.json +0 -9
- package/tsup.config.ts +0 -18
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module @kb-labs/rest-api-app/middleware/startup-guard
|
|
3
|
-
* Guard to prevent request storms during startup
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import type { FastifyInstance } from 'fastify';
|
|
7
|
-
import type { RestApiConfig } from '@kb-labs/rest-api-core';
|
|
8
|
-
import { isReady } from '../routes/readiness';
|
|
9
|
-
|
|
10
|
-
type StartupCounters = {
|
|
11
|
-
inFlight: number;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
type StartupConfig = {
|
|
15
|
-
maxConcurrent?: number;
|
|
16
|
-
queueLimit?: number;
|
|
17
|
-
timeoutMs?: number;
|
|
18
|
-
retryAfterSeconds?: number;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
export function registerStartupGuard(
|
|
22
|
-
server: FastifyInstance,
|
|
23
|
-
config: RestApiConfig
|
|
24
|
-
): void {
|
|
25
|
-
const startupConfig = (config as RestApiConfig & { startup?: StartupConfig }).startup;
|
|
26
|
-
if (!startupConfig) {
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const counters: StartupCounters = {
|
|
31
|
-
inFlight: 0,
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
server.kbStartupGuard = counters;
|
|
35
|
-
|
|
36
|
-
const maxConcurrent = startupConfig.maxConcurrent ?? 32;
|
|
37
|
-
const queueLimit = startupConfig.queueLimit ?? 128;
|
|
38
|
-
const timeoutMs = startupConfig.timeoutMs ?? 5000;
|
|
39
|
-
const retryAfterSeconds = startupConfig.retryAfterSeconds ?? 2;
|
|
40
|
-
|
|
41
|
-
server.addHook('onRequest', (request, reply, done) => {
|
|
42
|
-
const readiness = server.kbReadiness;
|
|
43
|
-
const infraReady = readiness ? isReady(readiness) : false;
|
|
44
|
-
|
|
45
|
-
if (infraReady) {
|
|
46
|
-
done();
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
if (counters.inFlight >= queueLimit) {
|
|
51
|
-
reply
|
|
52
|
-
.code(503)
|
|
53
|
-
.header('Retry-After', retryAfterSeconds.toString())
|
|
54
|
-
.send({
|
|
55
|
-
schema: 'kb.startup/1',
|
|
56
|
-
status: 'initializing',
|
|
57
|
-
reason: 'startup_queue_limit',
|
|
58
|
-
maxConcurrent,
|
|
59
|
-
queueLimit,
|
|
60
|
-
});
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
counters.inFlight += 1;
|
|
65
|
-
request.kbStartupGuardActive = true;
|
|
66
|
-
|
|
67
|
-
const timer = setTimeout(() => {
|
|
68
|
-
if (!reply.sent) {
|
|
69
|
-
reply
|
|
70
|
-
.code(504)
|
|
71
|
-
.header('Retry-After', retryAfterSeconds.toString())
|
|
72
|
-
.send({
|
|
73
|
-
schema: 'kb.startup/1',
|
|
74
|
-
status: 'timeout',
|
|
75
|
-
reason: 'startup_timeout',
|
|
76
|
-
timeoutMs,
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
}, timeoutMs);
|
|
80
|
-
timer.unref();
|
|
81
|
-
request.kbStartupGuardTimer = timer;
|
|
82
|
-
|
|
83
|
-
if (counters.inFlight > maxConcurrent) {
|
|
84
|
-
if ((request as any).kbLogger) {
|
|
85
|
-
(request as any).kbLogger.warn('Startup guard concurrency threshold exceeded', {
|
|
86
|
-
inFlight: counters.inFlight,
|
|
87
|
-
maxConcurrent,
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
done();
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
server.addHook('onResponse', (request, _reply, done) => {
|
|
96
|
-
if (request.kbStartupGuardActive) {
|
|
97
|
-
counters.inFlight = Math.max(0, counters.inFlight - 1);
|
|
98
|
-
if (request.kbStartupGuardTimer) {
|
|
99
|
-
clearTimeout(request.kbStartupGuardTimer);
|
|
100
|
-
request.kbStartupGuardTimer = undefined;
|
|
101
|
-
}
|
|
102
|
-
request.kbStartupGuardActive = false;
|
|
103
|
-
}
|
|
104
|
-
done();
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
|
|
@@ -1,192 +0,0 @@
|
|
|
1
|
-
import { hostname } from 'node:os';
|
|
2
|
-
import {
|
|
3
|
-
OBSERVABILITY_CONTRACT_VERSION,
|
|
4
|
-
OBSERVABILITY_SCHEMA,
|
|
5
|
-
CANONICAL_OBSERVABILITY_METRICS,
|
|
6
|
-
type ObservabilityCheck,
|
|
7
|
-
} from '@kb-labs/core-contracts';
|
|
8
|
-
import type {
|
|
9
|
-
ServiceObservabilityDescribe,
|
|
10
|
-
ServiceObservabilityHealth,
|
|
11
|
-
ServiceOperationSample,
|
|
12
|
-
} from '@kb-labs/core-contracts';
|
|
13
|
-
import {
|
|
14
|
-
createServiceObservabilityDescribe,
|
|
15
|
-
createServiceObservabilityHealth,
|
|
16
|
-
} from '@kb-labs/shared-http';
|
|
17
|
-
import type { SystemHealthSnapshot } from '@kb-labs/core-registry';
|
|
18
|
-
import type { ReadinessState } from '../routes/readiness.js';
|
|
19
|
-
import { restDomainOperationMetrics, type MetricsSnapshot } from '../middleware/metrics.js';
|
|
20
|
-
import { getLatestSystemMetrics } from '../services/system-metrics-collector.js';
|
|
21
|
-
|
|
22
|
-
declare const __REST_API_VERSION__: string;
|
|
23
|
-
const REST_VERSION = typeof __REST_API_VERSION__ !== 'undefined' ? __REST_API_VERSION__ : '0.0.0';
|
|
24
|
-
|
|
25
|
-
function resolveInstanceId(): string {
|
|
26
|
-
return `${hostname()}:${process.pid}`;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function mergeTopOperations(
|
|
30
|
-
httpOperations: ServiceOperationSample[],
|
|
31
|
-
domainOperations: ServiceOperationSample[],
|
|
32
|
-
limit = 5,
|
|
33
|
-
): ServiceOperationSample[] {
|
|
34
|
-
const merged = new Map<string, ServiceOperationSample>();
|
|
35
|
-
|
|
36
|
-
for (const item of [...httpOperations, ...domainOperations]) {
|
|
37
|
-
const existing = merged.get(item.operation);
|
|
38
|
-
if (!existing) {
|
|
39
|
-
merged.set(item.operation, { ...item });
|
|
40
|
-
continue;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const count = (existing.count ?? 0) + (item.count ?? 0);
|
|
44
|
-
const totalDurationMs =
|
|
45
|
-
(existing.avgDurationMs ?? 0) * (existing.count ?? 0) +
|
|
46
|
-
(item.avgDurationMs ?? 0) * (item.count ?? 0);
|
|
47
|
-
|
|
48
|
-
merged.set(item.operation, {
|
|
49
|
-
operation: item.operation,
|
|
50
|
-
count,
|
|
51
|
-
avgDurationMs: count > 0 ? totalDurationMs / count : 0,
|
|
52
|
-
maxDurationMs: Math.max(existing.maxDurationMs ?? 0, item.maxDurationMs ?? 0),
|
|
53
|
-
errorCount: (existing.errorCount ?? 0) + (item.errorCount ?? 0),
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const ranked = Array.from(merged.values())
|
|
58
|
-
.sort((a, b) => (b.count ?? 0) - (a.count ?? 0) || (b.maxDurationMs ?? 0) - (a.maxDurationMs ?? 0))
|
|
59
|
-
const sliced = ranked.slice(0, limit);
|
|
60
|
-
|
|
61
|
-
if (domainOperations.length === 0 || sliced.some((item) => !item.operation.startsWith('http.'))) {
|
|
62
|
-
return sliced;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
const firstDomainOperation = ranked.find((item) => !item.operation.startsWith('http.'));
|
|
66
|
-
if (!firstDomainOperation) {
|
|
67
|
-
return sliced;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
return [...sliced.slice(0, Math.max(0, limit - 1)), firstDomainOperation];
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
function finiteNumberOrUndefined(value: number | null | undefined): number | undefined {
|
|
74
|
-
return typeof value === 'number' && Number.isFinite(value) ? value : undefined;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
export function buildRestObservabilityDescribe(basePath: string): ServiceObservabilityDescribe {
|
|
78
|
-
return createServiceObservabilityDescribe({
|
|
79
|
-
schema: OBSERVABILITY_SCHEMA,
|
|
80
|
-
contractVersion: OBSERVABILITY_CONTRACT_VERSION,
|
|
81
|
-
serviceId: 'rest',
|
|
82
|
-
instanceId: resolveInstanceId(),
|
|
83
|
-
serviceType: 'http-api',
|
|
84
|
-
version: REST_VERSION,
|
|
85
|
-
environment: process.env.NODE_ENV ?? 'development',
|
|
86
|
-
startedAt: new Date(Date.now() - process.uptime() * 1000).toISOString(),
|
|
87
|
-
dependencies: [
|
|
88
|
-
{
|
|
89
|
-
serviceId: 'workflow',
|
|
90
|
-
required: true,
|
|
91
|
-
description: 'Workflow daemon for workflow and jobs APIs',
|
|
92
|
-
},
|
|
93
|
-
{
|
|
94
|
-
serviceId: 'state-daemon',
|
|
95
|
-
required: false,
|
|
96
|
-
description: 'State broker and cache-backed storage',
|
|
97
|
-
},
|
|
98
|
-
],
|
|
99
|
-
metricsEndpoint: `${basePath}/metrics`,
|
|
100
|
-
healthEndpoint: `${basePath}/observability/health`,
|
|
101
|
-
logsSource: 'rest',
|
|
102
|
-
capabilities: ['httpMetrics', 'eventLoopMetrics', 'operationMetrics', 'logCorrelation'],
|
|
103
|
-
metricFamilies: [...CANONICAL_OBSERVABILITY_METRICS],
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
export function buildRestObservabilityHealth(
|
|
108
|
-
basePath: string,
|
|
109
|
-
healthSnapshot: SystemHealthSnapshot,
|
|
110
|
-
readiness: ReadinessState,
|
|
111
|
-
metrics: MetricsSnapshot,
|
|
112
|
-
): ServiceObservabilityHealth {
|
|
113
|
-
const runtimeMetrics = getLatestSystemMetrics();
|
|
114
|
-
const checks: ObservabilityCheck[] = [
|
|
115
|
-
{
|
|
116
|
-
id: 'registry',
|
|
117
|
-
status: readiness.registryLoaded && !readiness.registryPartial && !readiness.registryStale
|
|
118
|
-
? 'ok'
|
|
119
|
-
: readiness.registryLoaded ? 'warn' : 'error',
|
|
120
|
-
message: readiness.registryLoaded ? 'Registry snapshot loaded' : 'Registry snapshot incomplete',
|
|
121
|
-
},
|
|
122
|
-
{
|
|
123
|
-
id: 'plugin-routes',
|
|
124
|
-
status: readiness.pluginRouteErrors > 0 ? 'warn' : readiness.pluginRoutesMounted ? 'ok' : 'warn',
|
|
125
|
-
message: readiness.pluginRoutesMounted
|
|
126
|
-
? `${readiness.pluginRoutesCount} plugin routes mounted`
|
|
127
|
-
: 'Plugin routes are still mounting',
|
|
128
|
-
},
|
|
129
|
-
{
|
|
130
|
-
id: 'redis',
|
|
131
|
-
status: !readiness.redisEnabled ? 'ok' : readiness.redisConnected ? 'ok' : 'warn',
|
|
132
|
-
message: !readiness.redisEnabled
|
|
133
|
-
? 'Redis integration disabled'
|
|
134
|
-
: readiness.redisConnected
|
|
135
|
-
? 'Redis healthy'
|
|
136
|
-
: 'Redis unavailable',
|
|
137
|
-
},
|
|
138
|
-
];
|
|
139
|
-
|
|
140
|
-
const httpTopOperations = metrics.latency.histogram
|
|
141
|
-
.slice()
|
|
142
|
-
.sort((a, b) => b.count - a.count || b.max - a.max)
|
|
143
|
-
.slice(0, 5)
|
|
144
|
-
.map((entry) => ({
|
|
145
|
-
operation: `http.${entry.route}`,
|
|
146
|
-
count: entry.count,
|
|
147
|
-
avgDurationMs: entry.count > 0 ? entry.total / entry.count : 0,
|
|
148
|
-
maxDurationMs: entry.max,
|
|
149
|
-
errorCount: Object.entries(entry.byStatus)
|
|
150
|
-
.filter(([status]) => Number(status) >= 400)
|
|
151
|
-
.reduce((sum, [, count]) => sum + count, 0),
|
|
152
|
-
}));
|
|
153
|
-
const topOperations = mergeTopOperations(httpTopOperations, restDomainOperationMetrics.getTopOperations(5));
|
|
154
|
-
|
|
155
|
-
const latestOperation = topOperations[0];
|
|
156
|
-
const state = healthSnapshot.status === 'healthy'
|
|
157
|
-
? 'active'
|
|
158
|
-
: runtimeMetrics || latestOperation
|
|
159
|
-
? 'partial_observability'
|
|
160
|
-
: 'insufficient_data';
|
|
161
|
-
|
|
162
|
-
return createServiceObservabilityHealth({
|
|
163
|
-
schema: OBSERVABILITY_SCHEMA,
|
|
164
|
-
contractVersion: OBSERVABILITY_CONTRACT_VERSION,
|
|
165
|
-
serviceId: 'rest',
|
|
166
|
-
instanceId: resolveInstanceId(),
|
|
167
|
-
observedAt: healthSnapshot.ts,
|
|
168
|
-
status: healthSnapshot.status === 'healthy' ? 'healthy' : healthSnapshot.status === 'degraded' ? 'degraded' : 'unhealthy',
|
|
169
|
-
uptimeSec: healthSnapshot.uptimeSec,
|
|
170
|
-
metricsEndpoint: `${basePath}/metrics`,
|
|
171
|
-
logsSource: 'rest',
|
|
172
|
-
capabilities: ['httpMetrics', 'eventLoopMetrics', 'operationMetrics', 'logCorrelation'],
|
|
173
|
-
checks,
|
|
174
|
-
snapshot: {
|
|
175
|
-
cpuPercent: finiteNumberOrUndefined(runtimeMetrics?.cpu.percentage),
|
|
176
|
-
rssBytes: finiteNumberOrUndefined(runtimeMetrics?.memory.rss),
|
|
177
|
-
heapUsedBytes: finiteNumberOrUndefined(runtimeMetrics?.memory.heapUsed),
|
|
178
|
-
eventLoopLagMs: finiteNumberOrUndefined(runtimeMetrics?.eventLoopLagMs),
|
|
179
|
-
activeOperations: runtimeMetrics?.activeOperations ?? metrics.requests.active,
|
|
180
|
-
},
|
|
181
|
-
topOperations,
|
|
182
|
-
state,
|
|
183
|
-
meta: {
|
|
184
|
-
serviceHealthEndpoint: `${basePath}/health`,
|
|
185
|
-
readyEndpoint: `${basePath}/ready`,
|
|
186
|
-
runtimeMetricsCollectedAt: runtimeMetrics ? new Date(runtimeMetrics.timestamp).toISOString() : null,
|
|
187
|
-
lastRequestAt: metrics.timestamps.lastRequest
|
|
188
|
-
? new Date(metrics.timestamps.lastRequest).toISOString()
|
|
189
|
-
: null,
|
|
190
|
-
},
|
|
191
|
-
});
|
|
192
|
-
}
|
package/src/plugins/index.ts
DELETED
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module @kb-labs/rest-api-app/plugins
|
|
3
|
-
* Fastify plugins registration
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import type {
|
|
7
|
-
FastifyInstance,
|
|
8
|
-
FastifyPluginCallback,
|
|
9
|
-
FastifyBaseLogger,
|
|
10
|
-
RawServerDefault,
|
|
11
|
-
FastifyTypeProviderDefault,
|
|
12
|
-
} from 'fastify';
|
|
13
|
-
import type { RestApiConfig } from '@kb-labs/rest-api-core';
|
|
14
|
-
import fastifyCors, { type FastifyCorsOptions } from '@fastify/cors';
|
|
15
|
-
import fastifyRateLimit, { type RateLimitPluginOptions } from '@fastify/rate-limit';
|
|
16
|
-
import { registerOpenAPI } from '@kb-labs/shared-http';
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Register all Fastify plugins
|
|
20
|
-
*/
|
|
21
|
-
export async function registerPlugins(
|
|
22
|
-
server: FastifyInstance,
|
|
23
|
-
config: RestApiConfig
|
|
24
|
-
): Promise<void> {
|
|
25
|
-
// CORS plugin with profile support
|
|
26
|
-
const corsProfile = config.cors.profile || 'dev';
|
|
27
|
-
let corsOrigins: string[] | boolean = config.cors.origins;
|
|
28
|
-
|
|
29
|
-
if (corsProfile === 'dev') {
|
|
30
|
-
// Dev: allow localhost origins
|
|
31
|
-
corsOrigins = config.cors.origins.length > 0
|
|
32
|
-
? config.cors.origins
|
|
33
|
-
: ['http://localhost:3000', 'http://localhost:5173']; // Vite default + Studio
|
|
34
|
-
} else if (corsProfile === 'preview') {
|
|
35
|
-
// Preview: specific staging domains
|
|
36
|
-
corsOrigins = config.cors.origins.length > 0
|
|
37
|
-
? config.cors.origins
|
|
38
|
-
: false; // Disable if not configured
|
|
39
|
-
} else if (corsProfile === 'prod') {
|
|
40
|
-
// Prod: strict whitelist
|
|
41
|
-
corsOrigins = config.cors.origins.length > 0
|
|
42
|
-
? config.cors.origins
|
|
43
|
-
: false; // Disable if not configured
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const corsOptions: FastifyCorsOptions = {
|
|
47
|
-
origin: corsOrigins,
|
|
48
|
-
credentials: config.cors.allowCredentials,
|
|
49
|
-
methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS', 'HEAD'],
|
|
50
|
-
allowedHeaders: [
|
|
51
|
-
'Content-Type',
|
|
52
|
-
'Authorization',
|
|
53
|
-
'X-Request-Id',
|
|
54
|
-
'X-Trace-Id', // Added for Studio widget tracing
|
|
55
|
-
'Idempotency-Key',
|
|
56
|
-
'X-Client-Version'
|
|
57
|
-
],
|
|
58
|
-
exposedHeaders: ['X-Request-Id', 'X-Schema-Version', 'X-RateLimit-Limit', 'X-RateLimit-Remaining', 'Retry-After'],
|
|
59
|
-
preflightContinue: false,
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
const corsPlugin: FastifyPluginCallback<
|
|
63
|
-
FastifyCorsOptions,
|
|
64
|
-
RawServerDefault,
|
|
65
|
-
FastifyTypeProviderDefault,
|
|
66
|
-
FastifyBaseLogger
|
|
67
|
-
> = fastifyCors;
|
|
68
|
-
|
|
69
|
-
await server.register(corsPlugin, corsOptions);
|
|
70
|
-
|
|
71
|
-
// Add Vary: Origin header for CORS caching
|
|
72
|
-
server.addHook('onSend', async (request, reply) => {
|
|
73
|
-
if (corsProfile !== 'prod') {
|
|
74
|
-
try {
|
|
75
|
-
if (!reply.raw.headersSent) {
|
|
76
|
-
reply.header('Vary', 'Origin');
|
|
77
|
-
}
|
|
78
|
-
} catch (err) {
|
|
79
|
-
// Headers already sent, ignore
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
// Rate limit plugin
|
|
85
|
-
if (config.rateLimit) {
|
|
86
|
-
const rateLimitOpts: RateLimitPluginOptions = {
|
|
87
|
-
max: config.rateLimit.max,
|
|
88
|
-
timeWindow: config.rateLimit.timeWindow,
|
|
89
|
-
addHeaders: {
|
|
90
|
-
'x-ratelimit-limit': true,
|
|
91
|
-
'x-ratelimit-remaining': true,
|
|
92
|
-
'x-ratelimit-reset': true,
|
|
93
|
-
},
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
const rateLimitPlugin: FastifyPluginCallback<
|
|
97
|
-
RateLimitPluginOptions,
|
|
98
|
-
RawServerDefault,
|
|
99
|
-
FastifyTypeProviderDefault,
|
|
100
|
-
FastifyBaseLogger
|
|
101
|
-
> = fastifyRateLimit;
|
|
102
|
-
|
|
103
|
-
await server.register(rateLimitPlugin, rateLimitOpts);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
// OpenAPI / Swagger UI
|
|
107
|
-
// Must be registered after other plugins and before routes.
|
|
108
|
-
// Spec is at /openapi.json — canonical across all services.
|
|
109
|
-
// UI is disabled in production (hideUntagged: true keeps internal routes invisible).
|
|
110
|
-
await registerOpenAPI(server, {
|
|
111
|
-
title: 'KB Labs REST API',
|
|
112
|
-
description: 'Main platform REST API — jobs, workflows, plugins, adapters',
|
|
113
|
-
version: '1.0.0',
|
|
114
|
-
servers: [{ url: 'http://localhost:5050', description: 'Local dev' }],
|
|
115
|
-
ui: corsProfile !== 'prod',
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
|