@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.
- package/.kb/agents/sessions/session-1771531145393-ws3uh6q/turns.json +42 -0
- package/.kb/agents/sessions/session-1771548930486-ui6rtvm/turns.json +33 -0
- package/.kb/agents/sessions/session-1771549691485-nibqroq/turns.json +133 -0
- package/.kb/agents/sessions/session-1771550943182-dkwqdjc/turns.json +130 -0
- package/.kb/agents/sessions/session-1771551564182-cr4bwzn/turns.json +349 -0
- package/.kb/agents/sessions/session-1771552401370-g4ztwd1/turns.json +206 -0
- package/.kb/commit/current/plan.json +248 -0
- package/.kb/commit/current/status.json +472 -0
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/commands/health.d.ts +10 -0
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/commands/health.js +215 -0
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/commands/health.js.map +1 -0
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/commands/list.d.ts +10 -0
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/commands/list.js +271 -0
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/commands/list.js.map +1 -0
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/commands/logs.d.ts +10 -0
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/commands/logs.js +230 -0
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/commands/logs.js.map +1 -0
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/commands/metrics.d.ts +10 -0
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/commands/metrics.js +228 -0
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/commands/metrics.js.map +1 -0
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/commands/run.d.ts +11 -0
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/commands/run.js +281 -0
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/commands/run.js.map +1 -0
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/commands/status.d.ts +10 -0
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/commands/status.js +266 -0
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/commands/status.js.map +1 -0
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/commands/workflow-run.d.ts +11 -0
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/commands/workflow-run.js +284 -0
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/commands/workflow-run.js.map +1 -0
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/flags-WLdpSZl4.d.ts +77 -0
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/index.d.ts +2 -0
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/index.js +441 -0
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/index.js.map +1 -0
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/manifest.d.ts +196 -0
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/manifest.js +441 -0
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/manifest.js.map +1 -0
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/cron-list-handler.d.ts +19 -0
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/cron-list-handler.js +48 -0
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/cron-list-handler.js.map +1 -0
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/index.d.ts +6 -0
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/index.js +170 -0
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/index.js.map +1 -0
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/job-cancel-handler.d.ts +12 -0
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/job-cancel-handler.js +52 -0
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/job-cancel-handler.js.map +1 -0
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/job-detail-handler.d.ts +22 -0
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/job-detail-handler.js +52 -0
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/job-detail-handler.js.map +1 -0
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/job-logs-handler.d.ts +13 -0
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/job-logs-handler.js +52 -0
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/job-logs-handler.js.map +1 -0
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/job-steps-handler.d.ts +9 -0
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/job-steps-handler.js +43 -0
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/job-steps-handler.js.map +1 -0
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/jobs-list-handler.d.ts +26 -0
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/jobs-list-handler.js +63 -0
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/jobs-list-handler.js.map +1 -0
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/pending-approvals-handler.d.ts +9 -0
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/pending-approvals-handler.js +46 -0
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/pending-approvals-handler.js.map +1 -0
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/resolve-approval-handler.d.ts +16 -0
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/resolve-approval-handler.js +58 -0
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/resolve-approval-handler.js.map +1 -0
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/run-detail-handler.d.ts +9 -0
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/run-detail-handler.js +46 -0
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/run-detail-handler.js.map +1 -0
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/runs-list-handler.d.ts +11 -0
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/runs-list-handler.js +50 -0
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/runs-list-handler.js.map +1 -0
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/stats-handler.d.ts +7 -0
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/stats-handler.js +39 -0
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/stats-handler.js.map +1 -0
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/workflow-detail-handler.d.ts +10 -0
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/workflow-detail-handler.js +46 -0
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/workflow-detail-handler.js.map +1 -0
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/workflow-run-cancel-handler.d.ts +13 -0
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/workflow-run-cancel-handler.js +47 -0
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/workflow-run-cancel-handler.js.map +1 -0
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/workflow-run-handler.d.ts +14 -0
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/workflow-run-handler.js +53 -0
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/workflow-run-handler.js.map +1 -0
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/workflow-runs-handler.d.ts +13 -0
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/workflow-runs-handler.js +54 -0
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/workflow-runs-handler.js.map +1 -0
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/workflows-list-handler.d.ts +12 -0
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/workflows-list-handler.js +51 -0
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/rest/workflows-list-handler.js.map +1 -0
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/ws/logs-channel.d.ts +17 -0
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/ws/logs-channel.js +133 -0
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/ws/logs-channel.js.map +1 -0
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/ws/progress-channel.d.ts +11 -0
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/ws/progress-channel.js +46 -0
- package/.kb/runtime/workspaces/ws_94c2deab-4cf9-49cb-94ac-3958062754a1/ws/progress-channel.js.map +1 -0
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/commands/health.d.ts +10 -0
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/commands/health.js +215 -0
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/commands/health.js.map +1 -0
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/commands/list.d.ts +10 -0
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/commands/list.js +271 -0
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/commands/list.js.map +1 -0
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/commands/logs.d.ts +10 -0
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/commands/logs.js +230 -0
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/commands/logs.js.map +1 -0
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/commands/metrics.d.ts +10 -0
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/commands/metrics.js +228 -0
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/commands/metrics.js.map +1 -0
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/commands/run.d.ts +11 -0
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/commands/run.js +281 -0
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/commands/run.js.map +1 -0
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/commands/status.d.ts +10 -0
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/commands/status.js +266 -0
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/commands/status.js.map +1 -0
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/commands/workflow-run.d.ts +11 -0
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/commands/workflow-run.js +284 -0
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/commands/workflow-run.js.map +1 -0
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/flags-WLdpSZl4.d.ts +77 -0
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/index.d.ts +2 -0
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/index.js +441 -0
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/index.js.map +1 -0
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/manifest.d.ts +196 -0
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/manifest.js +441 -0
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/manifest.js.map +1 -0
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/cron-list-handler.d.ts +19 -0
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/cron-list-handler.js +48 -0
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/cron-list-handler.js.map +1 -0
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/index.d.ts +6 -0
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/index.js +170 -0
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/index.js.map +1 -0
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/job-cancel-handler.d.ts +12 -0
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/job-cancel-handler.js +52 -0
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/job-cancel-handler.js.map +1 -0
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/job-detail-handler.d.ts +22 -0
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/job-detail-handler.js +52 -0
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/job-detail-handler.js.map +1 -0
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/job-logs-handler.d.ts +13 -0
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/job-logs-handler.js +52 -0
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/job-logs-handler.js.map +1 -0
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/job-steps-handler.d.ts +9 -0
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/job-steps-handler.js +43 -0
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/job-steps-handler.js.map +1 -0
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/jobs-list-handler.d.ts +26 -0
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/jobs-list-handler.js +63 -0
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/jobs-list-handler.js.map +1 -0
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/pending-approvals-handler.d.ts +9 -0
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/pending-approvals-handler.js +46 -0
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/pending-approvals-handler.js.map +1 -0
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/resolve-approval-handler.d.ts +16 -0
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/resolve-approval-handler.js +58 -0
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/resolve-approval-handler.js.map +1 -0
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/run-detail-handler.d.ts +9 -0
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/run-detail-handler.js +46 -0
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/run-detail-handler.js.map +1 -0
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/runs-list-handler.d.ts +11 -0
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/runs-list-handler.js +50 -0
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/runs-list-handler.js.map +1 -0
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/stats-handler.d.ts +7 -0
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/stats-handler.js +39 -0
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/stats-handler.js.map +1 -0
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/workflow-detail-handler.d.ts +10 -0
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/workflow-detail-handler.js +46 -0
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/workflow-detail-handler.js.map +1 -0
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/workflow-run-cancel-handler.d.ts +13 -0
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/workflow-run-cancel-handler.js +47 -0
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/workflow-run-cancel-handler.js.map +1 -0
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/workflow-run-handler.d.ts +14 -0
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/workflow-run-handler.js +53 -0
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/workflow-run-handler.js.map +1 -0
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/workflow-runs-handler.d.ts +13 -0
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/workflow-runs-handler.js +54 -0
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/workflow-runs-handler.js.map +1 -0
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/workflows-list-handler.d.ts +12 -0
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/workflows-list-handler.js +51 -0
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/rest/workflows-list-handler.js.map +1 -0
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/ws/logs-channel.d.ts +17 -0
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/ws/logs-channel.js +133 -0
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/ws/logs-channel.js.map +1 -0
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/ws/progress-channel.d.ts +11 -0
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/ws/progress-channel.js +46 -0
- package/.kb/runtime/workspaces/ws_f0f301b8-388d-4dc4-b301-475f2bc95f02/ws/progress-channel.js.map +1 -0
- package/README.md +54 -0
- package/eslint.config.js +23 -0
- package/package.json +72 -0
- package/src/.kb/agents/sessions/session-1773470583796-ximqnfk/kpi-baseline.json +17 -0
- package/src/.kb/memory/sessions/session-1773470583796-ximqnfk/fact-sheet.json +1 -0
- package/src/bootstrap.ts +233 -0
- package/src/diagnostics/header-debug.ts +37 -0
- package/src/events/hub.ts +60 -0
- package/src/events/index.ts +1 -0
- package/src/index.ts +13 -0
- package/src/manifest.ts +21 -0
- package/src/middleware/__tests__/cache.spec.ts +184 -0
- package/src/middleware/__tests__/envelope.spec.ts +268 -0
- package/src/middleware/__tests__/metrics.redis.spec.ts +64 -0
- package/src/middleware/__tests__/rate-limit.spec.ts +283 -0
- package/src/middleware/__tests__/request-id.spec.ts +160 -0
- package/src/middleware/cache.ts +67 -0
- package/src/middleware/envelope.ts +136 -0
- package/src/middleware/error-guard.ts +69 -0
- package/src/middleware/index.ts +37 -0
- package/src/middleware/metrics.ts +810 -0
- package/src/middleware/mock-mode.ts +44 -0
- package/src/middleware/prom-metrics.ts +284 -0
- package/src/middleware/rate-limit-routes.ts +73 -0
- package/src/middleware/rate-limit.ts +72 -0
- package/src/middleware/request-id.ts +41 -0
- package/src/middleware/request-timeout.ts +69 -0
- package/src/middleware/security-headers.ts +24 -0
- package/src/middleware/startup-guard.ts +107 -0
- package/src/observability/service-contract.ts +192 -0
- package/src/plugins/index.ts +118 -0
- package/src/routes/__tests__/adapters-date-helpers.spec.ts +332 -0
- package/src/routes/__tests__/adapters.spec.ts +680 -0
- package/src/routes/__tests__/cache.spec.ts +264 -0
- package/src/routes/__tests__/events.spec.ts +434 -0
- package/src/routes/__tests__/health.spec.ts +414 -0
- package/src/routes/__tests__/logs.spec.ts +494 -0
- package/src/routes/__tests__/observability.spec.ts +392 -0
- package/src/routes/__tests__/plugins.spec.ts +931 -0
- package/src/routes/__tests__/workflow-management.spec.ts +698 -0
- package/src/routes/__tests__/workflows.spec.ts +204 -0
- package/src/routes/adapter-call.ts +220 -0
- package/src/routes/adapters.ts +1206 -0
- package/src/routes/analytics.ts +328 -0
- package/src/routes/cache.ts +104 -0
- package/src/routes/debug-routes.ts +95 -0
- package/src/routes/events.ts +115 -0
- package/src/routes/health.ts +348 -0
- package/src/routes/hello.ts +47 -0
- package/src/routes/index.ts +395 -0
- package/src/routes/jobs.ts +253 -0
- package/src/routes/logs.ts +718 -0
- package/src/routes/metrics.ts +120 -0
- package/src/routes/observability.ts +1388 -0
- package/src/routes/openapi.ts +101 -0
- package/src/routes/platform.ts +143 -0
- package/src/routes/plugins.ts +998 -0
- package/src/routes/readiness.ts +83 -0
- package/src/routes/workflow-management.ts +469 -0
- package/src/routes/workflows.ts +256 -0
- package/src/server.ts +203 -0
- package/src/services/historical-metrics.ts +496 -0
- package/src/services/incident-analyzer.ts +289 -0
- package/src/services/incident-detector.ts +691 -0
- package/src/services/incident-schema.sql +76 -0
- package/src/services/incident-storage.ts +593 -0
- package/src/services/system-metrics-collector.ts +244 -0
- package/src/types/fastify.d.ts +58 -0
- package/src/utils/__tests__/sse-auth.spec.ts +113 -0
- package/src/utils/path-helpers.ts +15 -0
- package/src/utils/repo.ts +42 -0
- package/src/utils/schema.ts +20 -0
- package/src/utils/sse-auth.ts +81 -0
- package/test-sandbox.sh +105 -0
- package/tsconfig.build.json +15 -0
- package/tsconfig.json +9 -0
- package/tsup.config.ts +18 -0
|
@@ -0,0 +1,107 @@
|
|
|
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
|
+
|
|
@@ -0,0 +1,192 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
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
|
+
|