@kici-dev/orchestrator 0.0.0 → 0.1.2

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 (342) hide show
  1. package/LICENSE +661 -0
  2. package/README.md +1 -6
  3. package/dist/__test-helpers__/mock-db.d.ts +103 -0
  4. package/dist/__test-helpers__/mock-ws.d.ts +13 -0
  5. package/dist/agent/dispatcher.d.ts +231 -0
  6. package/dist/agent/ownership-tracker.d.ts +46 -0
  7. package/dist/agent/registry.d.ts +255 -0
  8. package/dist/agent/token-store.d.ts +96 -0
  9. package/dist/app.d.ts +234 -0
  10. package/dist/audit/access-log.d.ts +92 -0
  11. package/dist/audit/sampling-rate-limiter.d.ts +41 -0
  12. package/dist/cache/build-coordinator.d.ts +42 -0
  13. package/dist/cache/dep-cache.d.ts +51 -0
  14. package/dist/cache/index.d.ts +16 -0
  15. package/dist/cache/pending-builds.d.ts +14 -0
  16. package/dist/cache/pending-dynamics.d.ts +15 -0
  17. package/dist/cache/pending-inits.d.ts +19 -0
  18. package/dist/cache/pending-tracker.d.ts +65 -0
  19. package/dist/cache/source-cache.d.ts +30 -0
  20. package/dist/cli/api-client.d.ts +411 -0
  21. package/dist/cli/commands/access-log.d.ts +30 -0
  22. package/dist/cli/commands/agent-service/index.d.ts +15 -0
  23. package/dist/cli/commands/agent-service/install.d.ts +9 -0
  24. package/dist/cli/commands/agent-service/logs.d.ts +9 -0
  25. package/dist/cli/commands/agent-service/restart.d.ts +8 -0
  26. package/dist/cli/commands/agent-service/start.d.ts +8 -0
  27. package/dist/cli/commands/agent-service/status.d.ts +10 -0
  28. package/dist/cli/commands/agent-service/stop.d.ts +8 -0
  29. package/dist/cli/commands/agent-service/uninstall.d.ts +9 -0
  30. package/dist/cli/commands/agent-service/upgrade.d.ts +11 -0
  31. package/dist/cli/commands/agent.d.ts +10 -0
  32. package/dist/cli/commands/api-key.d.ts +12 -0
  33. package/dist/cli/commands/audit.d.ts +9 -0
  34. package/dist/cli/commands/backend.d.ts +17 -0
  35. package/dist/cli/commands/cold-store-impl.d.ts +101 -0
  36. package/dist/cli/commands/cold-store.d.ts +30 -0
  37. package/dist/cli/commands/config.d.ts +16 -0
  38. package/dist/cli/commands/db.d.ts +19 -0
  39. package/dist/cli/commands/debug-bundle.d.ts +16 -0
  40. package/dist/cli/commands/diagnose.d.ts +15 -0
  41. package/dist/cli/commands/environment.d.ts +24 -0
  42. package/dist/cli/commands/event-dlq.d.ts +19 -0
  43. package/dist/cli/commands/event-log.d.ts +27 -0
  44. package/dist/cli/commands/event.d.ts +4 -0
  45. package/dist/cli/commands/execution.d.ts +17 -0
  46. package/dist/cli/commands/inspect-bundle.d.ts +16 -0
  47. package/dist/cli/commands/maintenance.d.ts +4 -0
  48. package/dist/cli/commands/orchestrator-service/index.d.ts +12 -0
  49. package/dist/cli/commands/orchestrator-service/install.d.ts +10 -0
  50. package/dist/cli/commands/orchestrator-service/logs.d.ts +10 -0
  51. package/dist/cli/commands/orchestrator-service/restart.d.ts +8 -0
  52. package/dist/cli/commands/orchestrator-service/start.d.ts +8 -0
  53. package/dist/cli/commands/orchestrator-service/status.d.ts +10 -0
  54. package/dist/cli/commands/orchestrator-service/stop.d.ts +8 -0
  55. package/dist/cli/commands/orchestrator-service/uninstall.d.ts +9 -0
  56. package/dist/cli/commands/orchestrator-service/upgrade.d.ts +12 -0
  57. package/dist/cli/commands/org-settings.d.ts +17 -0
  58. package/dist/cli/commands/peer.d.ts +13 -0
  59. package/dist/cli/commands/queue.d.ts +16 -0
  60. package/dist/cli/commands/registration.d.ts +18 -0
  61. package/dist/cli/commands/rotate.d.ts +9 -0
  62. package/dist/cli/commands/runs.d.ts +34 -0
  63. package/dist/cli/commands/secret.d.ts +12 -0
  64. package/dist/cli/commands/shared/db.d.ts +16 -0
  65. package/dist/cli/commands/shared/versioned-upgrade.d.ts +38 -0
  66. package/dist/cli/commands/source.d.ts +24 -0
  67. package/dist/cli/commands/token.d.ts +10 -0
  68. package/dist/cli/commands/workflow.d.ts +31 -0
  69. package/dist/cli/join.d.ts +14 -0
  70. package/dist/cli/kici-admin.d.ts +13 -0
  71. package/dist/cli/lazy-deps/cache.d.ts +17 -0
  72. package/dist/cli/lazy-deps/downloader.d.ts +33 -0
  73. package/dist/cli/lazy-deps/registry.d.ts +43 -0
  74. package/dist/cli/service/compose.d.ts +25 -0
  75. package/dist/cli/service/index.d.ts +24 -0
  76. package/dist/cli/service/launchd.d.ts +34 -0
  77. package/dist/cli/service/platform-detect.d.ts +59 -0
  78. package/dist/cli/service/systemd.d.ts +41 -0
  79. package/dist/cli/service/types.d.ts +91 -0
  80. package/dist/cli/service/windows.d.ts +20 -0
  81. package/dist/cli/wizard/agent-wizard.d.ts +24 -0
  82. package/dist/cli/wizard/orchestrator-wizard.d.ts +38 -0
  83. package/dist/cli/wizard/prompts.d.ts +23 -0
  84. package/dist/cli.js +11435 -0
  85. package/dist/cluster/cluster-identity.d.ts +59 -0
  86. package/dist/cluster/coordinator.d.ts +204 -0
  87. package/dist/cluster/health-api.d.ts +30 -0
  88. package/dist/cluster/index.d.ts +24 -0
  89. package/dist/cluster/join-client.d.ts +75 -0
  90. package/dist/cluster/join-handler.d.ts +58 -0
  91. package/dist/cluster/join-token.d.ts +94 -0
  92. package/dist/cluster/orphan-recovery.d.ts +67 -0
  93. package/dist/cluster/peer-client.d.ts +190 -0
  94. package/dist/cluster/peer-credentials.d.ts +108 -0
  95. package/dist/cluster/peer-crypto.d.ts +57 -0
  96. package/dist/cluster/peer-handler.d.ts +97 -0
  97. package/dist/cluster/peer-registry.d.ts +186 -0
  98. package/dist/cluster/raft-state.d.ts +36 -0
  99. package/dist/cluster/raft.d.ts +140 -0
  100. package/dist/cold-store/load-access-log-range.d.ts +73 -0
  101. package/dist/cold-store/load-event-log-range.d.ts +62 -0
  102. package/dist/cold-store/load-secret-audit-log-range.d.ts +38 -0
  103. package/dist/cold-store/orchestrator-cold-store.d.ts +58 -0
  104. package/dist/cold-store/tables/access-log.d.ts +80 -0
  105. package/dist/cold-store/tables/event-log.d.ts +70 -0
  106. package/dist/cold-store/tables/execution-jobs.d.ts +63 -0
  107. package/dist/cold-store/tables/execution-runs.d.ts +81 -0
  108. package/dist/cold-store/tables/execution-steps.d.ts +65 -0
  109. package/dist/cold-store/tables/secret-audit-log.d.ts +77 -0
  110. package/dist/concurrency/dispatch-next-queued.d.ts +63 -0
  111. package/dist/concurrency/group-tracker.d.ts +51 -0
  112. package/dist/concurrency/index.d.ts +3 -0
  113. package/dist/concurrency/queue-manager.d.ts +68 -0
  114. package/dist/concurrency/waiters.d.ts +58 -0
  115. package/dist/config/encryption.d.ts +82 -0
  116. package/dist/config/env-overlay.d.ts +45 -0
  117. package/dist/config/index.d.ts +16 -0
  118. package/dist/config/loader.d.ts +26 -0
  119. package/dist/config/reload.d.ts +113 -0
  120. package/dist/config/resolver.d.ts +47 -0
  121. package/dist/config/schema.d.ts +210 -0
  122. package/dist/config/shared-store.d.ts +142 -0
  123. package/dist/config/types.d.ts +218 -0
  124. package/dist/config.d.ts +249 -0
  125. package/dist/cron/cron-scheduler.d.ts +78 -0
  126. package/dist/cron/cron-store.d.ts +38 -0
  127. package/dist/dashboard/handler.d.ts +243 -0
  128. package/dist/db/client.d.ts +13 -0
  129. package/dist/db/migration-provider.d.ts +9 -0
  130. package/dist/db/migrations/001_initial.d.ts +8 -0
  131. package/dist/db/migrations/002_config_versions_key_version.d.ts +16 -0
  132. package/dist/db/migrations/003_access_log.d.ts +26 -0
  133. package/dist/db/migrations/004_rename_bundle_to_source.d.ts +19 -0
  134. package/dist/db/migrations/005_cold_store_chunk_counter.d.ts +19 -0
  135. package/dist/db/migrations/006_runs_jobs_steps_archived_at.d.ts +38 -0
  136. package/dist/db/migrations/007_audit_logs_archived_at.d.ts +42 -0
  137. package/dist/db/migrations/008_event_log_archived_at.d.ts +40 -0
  138. package/dist/db/migrations/009_access_log_trigram.d.ts +15 -0
  139. package/dist/db/migrations/010_cold_store_chunks.d.ts +34 -0
  140. package/dist/db/migrations/011_drop_source_secrets_notify.d.ts +21 -0
  141. package/dist/db/migrations/012_peer_credentials_active_uniq.d.ts +28 -0
  142. package/dist/db/migrations/013_execution_log_bytes.d.ts +21 -0
  143. package/dist/db/migrations/014_kici_events_lease_retry.d.ts +36 -0
  144. package/dist/db/migrations/015_org_settings_customer_scoped.d.ts +30 -0
  145. package/dist/db/migrations/016_org_settings_allow_http_npm.d.ts +15 -0
  146. package/dist/db/migrations/017_org_id_widen.d.ts +4 -0
  147. package/dist/db/migrations/018_org_id_prefix_backfill.d.ts +4 -0
  148. package/dist/db/migrator.d.ts +32 -0
  149. package/dist/db/types.d.ts +1266 -0
  150. package/dist/diagnostics/bundle-reader.d.ts +48 -0
  151. package/dist/diagnostics/bundle-writer.d.ts +57 -0
  152. package/dist/diagnostics/checks/agents.d.ts +10 -0
  153. package/dist/diagnostics/checks/certs.d.ts +9 -0
  154. package/dist/diagnostics/checks/config.d.ts +10 -0
  155. package/dist/diagnostics/checks/db.d.ts +9 -0
  156. package/dist/diagnostics/checks/disk.d.ts +9 -0
  157. package/dist/diagnostics/checks/index.d.ts +17 -0
  158. package/dist/diagnostics/checks/ws.d.ts +9 -0
  159. package/dist/diagnostics/index.d.ts +13 -0
  160. package/dist/diagnostics/runner.d.ts +23 -0
  161. package/dist/diagnostics/types.d.ts +38 -0
  162. package/dist/entry-helpers.d.ts +93 -0
  163. package/dist/environments/binding-store.d.ts +27 -0
  164. package/dist/environments/environment-store.d.ts +74 -0
  165. package/dist/environments/held-runs.d.ts +64 -0
  166. package/dist/environments/index.d.ts +10 -0
  167. package/dist/environments/protection/branch-gate.d.ts +5 -0
  168. package/dist/environments/protection/concurrency-gate.d.ts +7 -0
  169. package/dist/environments/protection/pipeline.d.ts +18 -0
  170. package/dist/environments/protection/reviewer-gate.d.ts +7 -0
  171. package/dist/environments/protection/trust-gate.d.ts +7 -0
  172. package/dist/environments/protection/wait-timer-gate.d.ts +7 -0
  173. package/dist/environments/variable-store.d.ts +39 -0
  174. package/dist/events/circuit-breaker.d.ts +33 -0
  175. package/dist/events/event-emitter.d.ts +55 -0
  176. package/dist/events/event-retry-scanner.d.ts +52 -0
  177. package/dist/events/event-router.d.ts +183 -0
  178. package/dist/events/event-store.d.ts +157 -0
  179. package/dist/events/trust-store.d.ts +54 -0
  180. package/dist/events/types.d.ts +61 -0
  181. package/dist/helpers/ip-extraction.d.ts +29 -0
  182. package/dist/helpers/rate-limiter.d.ts +23 -0
  183. package/dist/index.d.ts +7 -0
  184. package/dist/index.js +772 -0
  185. package/dist/lockfile-cache.d.ts +39 -0
  186. package/dist/metrics/agent-metrics-aggregator.d.ts +116 -0
  187. package/dist/metrics/metrics-reporter.d.ts +40 -0
  188. package/dist/metrics/prometheus.d.ts +261 -0
  189. package/dist/metrics/scheduled-jobs.d.ts +20 -0
  190. package/dist/orchestrator-core.d.ts +193 -0
  191. package/dist/pipeline/dispatch-matched-workflow.d.ts +102 -0
  192. package/dist/pipeline/inline-eval.d.ts +28 -0
  193. package/dist/pipeline/install-secrets-resolver.d.ts +73 -0
  194. package/dist/pipeline/manual-schedule.d.ts +21 -0
  195. package/dist/pipeline/needs-scheduler.d.ts +85 -0
  196. package/dist/pipeline/process-webhook.d.ts +38 -0
  197. package/dist/pipeline/processor.d.ts +326 -0
  198. package/dist/pipeline/rerun.d.ts +79 -0
  199. package/dist/pipeline/test-pipeline.d.ts +110 -0
  200. package/dist/provider-registry.d.ts +122 -0
  201. package/dist/providers/generic/index.d.ts +23 -0
  202. package/dist/providers/generic/normalizer.d.ts +112 -0
  203. package/dist/providers/generic/verification.d.ts +47 -0
  204. package/dist/providers/github/auth.d.ts +60 -0
  205. package/dist/providers/github/changed-files.d.ts +51 -0
  206. package/dist/providers/github/check-status-poster.d.ts +35 -0
  207. package/dist/providers/github/contributor-resolver.d.ts +30 -0
  208. package/dist/providers/github/index.d.ts +20 -0
  209. package/dist/providers/github/lock-file.d.ts +32 -0
  210. package/dist/providers/github/normalizer.d.ts +103 -0
  211. package/dist/providers/github/repo-url.d.ts +35 -0
  212. package/dist/providers/internal/index.d.ts +32 -0
  213. package/dist/providers/internal/lock-file-fetcher.d.ts +34 -0
  214. package/dist/providers/internal/normalizer.d.ts +89 -0
  215. package/dist/providers/internal/repo-url-builder.d.ts +42 -0
  216. package/dist/providers/universal-git/changed-files.d.ts +42 -0
  217. package/dist/providers/universal-git/clone-token.d.ts +83 -0
  218. package/dist/providers/universal-git/config.d.ts +192 -0
  219. package/dist/providers/universal-git/index.d.ts +55 -0
  220. package/dist/providers/universal-git/lock-file.d.ts +71 -0
  221. package/dist/providers/universal-git/normalizer.d.ts +90 -0
  222. package/dist/providers/universal-git/repo-url.d.ts +50 -0
  223. package/dist/providers/universal-git/ssh-auth.d.ts +94 -0
  224. package/dist/queue/bootstrap.d.ts +50 -0
  225. package/dist/queue/cleanup.d.ts +41 -0
  226. package/dist/queue/depth-refresher.d.ts +65 -0
  227. package/dist/queue/job-queue.d.ts +343 -0
  228. package/dist/queue/scheduled-job.d.ts +91 -0
  229. package/dist/registration/extractor.d.ts +44 -0
  230. package/dist/registration/registration-index.d.ts +162 -0
  231. package/dist/registration/registration-store.d.ts +111 -0
  232. package/dist/reporting/check-run-summary.d.ts +102 -0
  233. package/dist/reporting/commit-status.d.ts +382 -0
  234. package/dist/reporting/execution-tracker.d.ts +538 -0
  235. package/dist/reporting/fs-log-storage.d.ts +41 -0
  236. package/dist/reporting/log-pull-handler.d.ts +35 -0
  237. package/dist/reporting/log-storage.d.ts +70 -0
  238. package/dist/reporting/log-writer.d.ts +45 -0
  239. package/dist/reporting/s3-log-storage.d.ts +42 -0
  240. package/dist/reporting/step-log-buffer.d.ts +57 -0
  241. package/dist/routes/admin-access-log.d.ts +34 -0
  242. package/dist/routes/admin-backends.d.ts +28 -0
  243. package/dist/routes/admin-config.d.ts +57 -0
  244. package/dist/routes/admin-db.d.ts +20 -0
  245. package/dist/routes/admin-environments.d.ts +42 -0
  246. package/dist/routes/admin-errors.d.ts +4 -0
  247. package/dist/routes/admin-event-dlq.d.ts +39 -0
  248. package/dist/routes/admin-event-log.d.ts +42 -0
  249. package/dist/routes/admin-events.d.ts +46 -0
  250. package/dist/routes/admin-maintenance.d.ts +22 -0
  251. package/dist/routes/admin-org-settings.d.ts +29 -0
  252. package/dist/routes/admin-queue-execution.d.ts +27 -0
  253. package/dist/routes/admin-registrations.d.ts +37 -0
  254. package/dist/routes/admin-runs.d.ts +57 -0
  255. package/dist/routes/admin-scheduled-jobs.d.ts +36 -0
  256. package/dist/routes/admin-sources.d.ts +18 -0
  257. package/dist/routes/admin.d.ts +103 -0
  258. package/dist/routes/capabilities.d.ts +24 -0
  259. package/dist/routes/diagnostics.d.ts +16 -0
  260. package/dist/routes/health.d.ts +20 -0
  261. package/dist/routes/test-trigger.d.ts +41 -0
  262. package/dist/routes/uploads.d.ts +38 -0
  263. package/dist/routes/webhooks.d.ts +36 -0
  264. package/dist/scaler/bare-metal-backend.d.ts +107 -0
  265. package/dist/scaler/config.d.ts +303 -0
  266. package/dist/scaler/container-backend.d.ts +125 -0
  267. package/dist/scaler/file-tail.d.ts +23 -0
  268. package/dist/scaler/firecracker-api.d.ts +100 -0
  269. package/dist/scaler/firecracker-backend.d.ts +263 -0
  270. package/dist/scaler/index.d.ts +24 -0
  271. package/dist/scaler/ip-allocator.d.ts +177 -0
  272. package/dist/scaler/label-matcher.d.ts +73 -0
  273. package/dist/scaler/log-forwarder.d.ts +54 -0
  274. package/dist/scaler/machine-ledger.d.ts +160 -0
  275. package/dist/scaler/manager.d.ts +338 -0
  276. package/dist/scaler/nftables.d.ts +85 -0
  277. package/dist/scaler/types.d.ts +388 -0
  278. package/dist/scaler/warm-pool.d.ts +81 -0
  279. package/dist/secrets/audit-logger.d.ts +65 -0
  280. package/dist/secrets/backend-health.d.ts +60 -0
  281. package/dist/secrets/backend-registry.d.ts +68 -0
  282. package/dist/secrets/backend-sync.d.ts +40 -0
  283. package/dist/secrets/cleanup.d.ts +40 -0
  284. package/dist/secrets/config.d.ts +51 -0
  285. package/dist/secrets/crypto.d.ts +49 -0
  286. package/dist/secrets/ephemeral-keys.d.ts +49 -0
  287. package/dist/secrets/index.d.ts +17 -0
  288. package/dist/secrets/pg-secret-store.d.ts +105 -0
  289. package/dist/secrets/rbac.d.ts +47 -0
  290. package/dist/secrets/secret-output-store.d.ts +46 -0
  291. package/dist/secrets/secret-resolver.d.ts +137 -0
  292. package/dist/secrets/source-credentials.d.ts +61 -0
  293. package/dist/secrets/token-manager.d.ts +63 -0
  294. package/dist/secrets/vault-secret-store.d.ts +85 -0
  295. package/dist/security/comment-handler.d.ts +67 -0
  296. package/dist/security/contributor-cache.d.ts +75 -0
  297. package/dist/security/global-workflow-policy.d.ts +72 -0
  298. package/dist/security/lock-source.d.ts +34 -0
  299. package/dist/security/trust-resolver.d.ts +108 -0
  300. package/dist/security/workflow-diff.d.ts +26 -0
  301. package/dist/server.d.ts +17 -0
  302. package/dist/server.js +48055 -0
  303. package/dist/sources/index.d.ts +10 -0
  304. package/dist/sources/source-manager.d.ts +63 -0
  305. package/dist/sources/source-store.d.ts +79 -0
  306. package/dist/sources/source-validator.d.ts +16 -0
  307. package/dist/stale-detector/stale-run-detector.d.ts +109 -0
  308. package/dist/standalone.d.ts +20 -0
  309. package/dist/standalone.js +41546 -0
  310. package/dist/storage/blob-routes.d.ts +20 -0
  311. package/dist/storage/filesystem.d.ts +60 -0
  312. package/dist/storage/index.d.ts +20 -0
  313. package/dist/storage/s3.d.ts +68 -0
  314. package/dist/storage/sign-url.d.ts +45 -0
  315. package/dist/storage/types.d.ts +98 -0
  316. package/dist/webhook/dedup.d.ts +44 -0
  317. package/dist/webhook/event-log.d.ts +83 -0
  318. package/dist/webhook/generic-sources.d.ts +169 -0
  319. package/dist/webhook/handler.d.ts +23 -0
  320. package/dist/webhook/relay-buffer.d.ts +96 -0
  321. package/dist/webhook/verify-inbound.d.ts +78 -0
  322. package/dist/worker/in-memory-execution-tracker.d.ts +94 -0
  323. package/dist/worker/in-memory-job-queue.d.ts +74 -0
  324. package/dist/worker/static-agent-token-store.d.ts +58 -0
  325. package/dist/worker/worker-status.d.ts +36 -0
  326. package/dist/worker-core.d.ts +74 -0
  327. package/dist/ws/agent-api-registry.d.ts +49 -0
  328. package/dist/ws/agent-handler.d.ts +176 -0
  329. package/dist/ws/agent-heartbeat.d.ts +45 -0
  330. package/dist/ws/dashboard-backends-handler.d.ts +51 -0
  331. package/dist/ws/dashboard-diagnostics-handler.d.ts +56 -0
  332. package/dist/ws/dashboard-env-handler.d.ts +107 -0
  333. package/dist/ws/dashboard-global-workflows-handler.d.ts +72 -0
  334. package/dist/ws/dashboard-registrations-handler.d.ts +84 -0
  335. package/dist/ws/event-buffer.d.ts +16 -0
  336. package/dist/ws/observer-handler.d.ts +42 -0
  337. package/dist/ws/observer-registry.d.ts +88 -0
  338. package/dist/ws/platform-client.d.ts +270 -0
  339. package/dist/ws/server-options.d.ts +15 -0
  340. package/package.json +87 -7
  341. package/sbom.spdx.json +14370 -0
  342. package/index.js +0 -3
@@ -0,0 +1,20 @@
1
+ /**
2
+ * HTTP routes for the filesystem cache backend.
3
+ *
4
+ * `FilesystemCacheStorage` mints signed `http://<orch>/api/v1/cache/blob/<key>?sig=<token>`
5
+ * URLs that the agent uses to GET cached bytes or PUT new uploads. These
6
+ * routes verify the HMAC token, reject path traversal, and stream content
7
+ * to / from disk under the configured `basePath`.
8
+ *
9
+ * The S3 backend doesn't go through these routes — it uses real pre-signed
10
+ * URLs against the S3 endpoint. These routes are mounted only when the
11
+ * filesystem backend is active (`deps.fsCache` truthy in app.ts).
12
+ */
13
+ import type { Hono } from 'hono';
14
+ export interface FsCacheRouteDeps {
15
+ basePath: string;
16
+ signingSecret: string;
17
+ }
18
+ /** Mount filesystem-backend cache routes onto an existing Hono app. */
19
+ export declare function registerBlobRoutes(app: Hono, deps: FsCacheRouteDeps): void;
20
+ //# sourceMappingURL=blob-routes.d.ts.map
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Filesystem-backed cache storage.
3
+ *
4
+ * Mirrors the `CacheStorage` interface that `S3CacheStorage` provides, but
5
+ * stores blobs as files under a configured base directory. Pre-signed URLs
6
+ * are replaced by HMAC-signed `http://<orchUrl>/api/v1/cache/blob/...` URLs
7
+ * — see `sign-url.ts` for the token mechanics and `app.ts` for the route.
8
+ *
9
+ * Intended for single-host deployments and E2E sandboxes where standing up
10
+ * an S3-compatible service is overkill. Production should still use S3.
11
+ *
12
+ * Metadata is co-located as a sibling JSON file (`<key>.meta.json`) so the
13
+ * data file is byte-identical to what the agent receives over HTTP. TTL is
14
+ * enforced lazily on access — same model as the S3 backend.
15
+ */
16
+ import type { CacheStorage } from './types.js';
17
+ export interface FilesystemCacheStorageOptions {
18
+ /** Absolute path to the cache root directory. Created on first write if missing. */
19
+ basePath: string;
20
+ /** Item TTL in milliseconds. Items past TTL since lastAccessedAt are evicted. */
21
+ ttlMs: number;
22
+ /** Base URL the agent uses to reach the orchestrator (e.g., `http://orch:10143`). */
23
+ baseUrl: string;
24
+ /** Per-process HMAC secret used to sign URLs. See sign-url.ts. */
25
+ signingSecret: string;
26
+ /** Optional URL path mount point. Defaults to `/api/v1/cache/blob/`. */
27
+ routePrefix?: string;
28
+ }
29
+ export declare class FilesystemCacheStorage implements CacheStorage {
30
+ private readonly basePath;
31
+ private readonly ttlMs;
32
+ private readonly baseUrl;
33
+ private readonly signingSecret;
34
+ private readonly routePrefix;
35
+ constructor(options: FilesystemCacheStorageOptions);
36
+ /**
37
+ * Map a cache key to its on-disk path. Keys may contain `/`, which becomes a
38
+ * directory separator. Reject keys containing `..` segments or NUL bytes to
39
+ * prevent path traversal — the same defence the route layer enforces too.
40
+ */
41
+ private resolvePath;
42
+ /** Public for the HTTP route. The route validates the key before calling. */
43
+ pathFor(key: string): string;
44
+ private metaPath;
45
+ private isExpired;
46
+ private readMeta;
47
+ private writeMeta;
48
+ put(key: string, data: Buffer | string): Promise<void>;
49
+ get(key: string): Promise<Buffer | null>;
50
+ has(key: string): Promise<boolean>;
51
+ delete(key: string): Promise<boolean>;
52
+ touch(key: string): Promise<void>;
53
+ getUrl(key: string): Promise<string | null>;
54
+ getUploadUrl(key: string): Promise<string>;
55
+ getInternalUploadUrl(key: string): Promise<string>;
56
+ initMeta(key: string): Promise<void>;
57
+ private signedUrl;
58
+ private deleteFiles;
59
+ }
60
+ //# sourceMappingURL=filesystem.d.ts.map
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Cache storage module.
3
+ *
4
+ * Pluggable storage backends:
5
+ * - S3CacheStorage — production / multi-host
6
+ * - FilesystemCacheStorage — single-host / E2E sandbox
7
+ *
8
+ * Use createCacheStorage() to instantiate from a discriminated config.
9
+ */
10
+ export type { CacheStorage, CacheStorageConfig, CacheMetadata, S3CacheStorageConfig, FilesystemCacheStorageConfig, } from './types.js';
11
+ export { S3CacheStorage } from './s3.js';
12
+ export { FilesystemCacheStorage } from './filesystem.js';
13
+ export { signToken, verifyToken, generateSigningSecret } from './sign-url.js';
14
+ export type { SignedMethod, SignedToken, VerifyResult } from './sign-url.js';
15
+ import type { CacheStorage, CacheStorageConfig } from './types.js';
16
+ /**
17
+ * Create a cache storage backend from configuration.
18
+ */
19
+ export declare function createCacheStorage(config: CacheStorageConfig): CacheStorage;
20
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,68 @@
1
+ /**
2
+ * S3-backed cache storage.
3
+ *
4
+ * Stores cached items in S3 with custom metadata headers for TTL tracking.
5
+ * Uses AWS SDK v3 modular imports -- only loaded when S3 storage is configured.
6
+ *
7
+ * Metadata storage:
8
+ * x-amz-meta-created-at -- ISO timestamp of creation
9
+ * x-amz-meta-last-accessed-at -- ISO timestamp of last access
10
+ *
11
+ * TTL is enforced lazily: expired items are deleted on access.
12
+ * Pre-signed URLs are generated for getUrl() with 15-minute expiry.
13
+ */
14
+ import type { CacheStorage } from './types.js';
15
+ export interface S3CacheStorageOptions {
16
+ bucket: string;
17
+ prefix: string;
18
+ ttlMs: number;
19
+ region?: string;
20
+ /** Custom endpoint URL for S3-compatible services (e.g., SeaweedFS, LocalStack) */
21
+ endpoint?: string;
22
+ /**
23
+ * Separate endpoint for pre-signed URLs (upload and download).
24
+ * When set, pre-signed URLs use this endpoint instead of `endpoint`.
25
+ * Useful when the orchestrator accesses S3 on localhost but agents
26
+ * need a container-routable address (e.g., container DNS name).
27
+ */
28
+ externalEndpoint?: string;
29
+ /** Use path-style access instead of virtual-hosted-style (required for most S3-compatible services) */
30
+ forcePathStyle?: boolean;
31
+ }
32
+ export declare class S3CacheStorage implements CacheStorage {
33
+ private readonly client;
34
+ /** Separate client for pre-signed URL generation (uses externalEndpoint if configured). */
35
+ private readonly presignClient;
36
+ private readonly bucket;
37
+ private readonly prefix;
38
+ private readonly ttlMs;
39
+ constructor(options: S3CacheStorageOptions);
40
+ /** Build the full S3 object key from a cache key. */
41
+ private objectKey;
42
+ /** Check if metadata indicates an expired item. */
43
+ private isExpired;
44
+ /**
45
+ * Read metadata from an S3 object's custom headers.
46
+ * Returns null if the object doesn't exist (NoSuchKey/NotFound).
47
+ */
48
+ private readMeta;
49
+ /**
50
+ * Update metadata on an S3 object by copying it to itself.
51
+ * This is the standard S3 pattern for updating metadata without re-uploading data.
52
+ */
53
+ private updateMeta;
54
+ /** Check if an error is a "not found" error (NoSuchKey, NotFound, 404). */
55
+ private isNotFoundError;
56
+ put(key: string, data: Buffer | string): Promise<void>;
57
+ get(key: string): Promise<Buffer | null>;
58
+ has(key: string): Promise<boolean>;
59
+ delete(key: string): Promise<boolean>;
60
+ touch(key: string): Promise<void>;
61
+ getUrl(key: string): Promise<string | null>;
62
+ getUploadUrl(key: string): Promise<string>;
63
+ getInternalUploadUrl(key: string): Promise<string>;
64
+ initMeta(key: string): Promise<void>;
65
+ /** Delete an S3 object. Idempotent (doesn't error if missing). */
66
+ private deleteObject;
67
+ }
68
+ //# sourceMappingURL=s3.d.ts.map
@@ -0,0 +1,45 @@
1
+ /**
2
+ * HMAC-signed URL tokens for the filesystem cache backend.
3
+ *
4
+ * Pre-signed S3 URLs are not available for filesystem storage, so the
5
+ * filesystem backend mints HMAC-SHA256 tokens that the orchestrator's HTTP
6
+ * blob route verifies before serving / writing a file. Token shape:
7
+ *
8
+ * `${expiresUnixMs}.${hexSig}`
9
+ *
10
+ * Signature input: `${method}:${key}:${expiresUnixMs}` with HMAC-SHA256 keyed
11
+ * by a per-orchestrator-process secret (random 32-byte hex at boot, persists
12
+ * for the lifetime of the process). Tokens become invalid on orchestrator
13
+ * restart — fine for the filesystem backend's E2E / single-host use case.
14
+ */
15
+ /** Default URL lifetime: 1 hour (matches S3 backend's PUT-URL lifetime). */
16
+ export declare const DEFAULT_SIGN_URL_TTL_MS: number;
17
+ export type SignedMethod = 'GET' | 'PUT';
18
+ /**
19
+ * Generate a fresh per-process signing secret. Caller stores it on the
20
+ * orchestrator config object so the same value is used for sign + verify.
21
+ */
22
+ export declare function generateSigningSecret(): string;
23
+ export interface SignedToken {
24
+ /** Encoded token string (`${expiresMs}.${sig}`) ready to drop into a URL. */
25
+ token: string;
26
+ /** Expiry timestamp in unix ms — exposed for tests and logging. */
27
+ expiresMs: number;
28
+ }
29
+ /**
30
+ * Mint a signed token for the given (method, key, expiry) triple.
31
+ */
32
+ export declare function signToken(secret: string, method: SignedMethod, key: string, ttlMs?: number): SignedToken;
33
+ export type VerifyResult = {
34
+ ok: true;
35
+ expiresMs: number;
36
+ } | {
37
+ ok: false;
38
+ reason: 'malformed' | 'expired' | 'bad-signature';
39
+ };
40
+ /**
41
+ * Verify a token. Constant-time signature compare on hex digest length;
42
+ * rejects malformed shapes and expired tokens up-front.
43
+ */
44
+ export declare function verifyToken(secret: string, method: SignedMethod, key: string, token: string): VerifyResult;
45
+ //# sourceMappingURL=sign-url.d.ts.map
@@ -0,0 +1,98 @@
1
+ /**
2
+ * Cache storage abstraction for the orchestrator.
3
+ *
4
+ * Provides a pluggable backend interface for storing and retrieving
5
+ * cached data (compiled workflow bundles, etc.). Implementations
6
+ * must handle TTL-based expiry via lastAccessedAt timestamps.
7
+ *
8
+ * Backends:
9
+ * - `S3CacheStorage` for production / multi-host deployments
10
+ * - `FilesystemCacheStorage` for single-host / E2E sandboxes
11
+ */
12
+ /**
13
+ * Metadata tracked alongside each cached item.
14
+ * Used for TTL-based expiry (based on lastAccessedAt).
15
+ */
16
+ export interface CacheMetadata {
17
+ /** ISO timestamp of when the item was first stored */
18
+ createdAt: string;
19
+ /** ISO timestamp of when the item was last accessed (read or touched) */
20
+ lastAccessedAt: string;
21
+ }
22
+ /**
23
+ * Pluggable cache storage interface.
24
+ *
25
+ * All operations are async. Implementations must handle TTL-based expiry:
26
+ * an item is considered expired when (now - lastAccessedAt) > ttlMs.
27
+ * Expired items are cleaned up lazily on access.
28
+ */
29
+ export interface CacheStorage {
30
+ /** Store a value under the given key. Overwrites if key already exists. */
31
+ put(key: string, data: Buffer | string): Promise<void>;
32
+ /** Retrieve a value by key. Returns null if not found or expired. */
33
+ get(key: string): Promise<Buffer | null>;
34
+ /** Check if a key exists and is not expired, without retrieving data. */
35
+ has(key: string): Promise<boolean>;
36
+ /** Delete a key. Returns true if the key existed (even if expired). */
37
+ delete(key: string): Promise<boolean>;
38
+ /** Update lastAccessedAt to now, refreshing the TTL. No-op if key doesn't exist. */
39
+ touch(key: string): Promise<void>;
40
+ /**
41
+ * Get a pre-signed download URL for the cached item.
42
+ * Returns null if not found or expired.
43
+ */
44
+ getUrl(key: string): Promise<string | null>;
45
+ /**
46
+ * Generate a pre-signed PUT URL for direct agent upload.
47
+ * Uses the external endpoint (container-routable) when configured.
48
+ */
49
+ getUploadUrl(key: string): Promise<string>;
50
+ /**
51
+ * Generate a pre-signed PUT URL using the internal endpoint.
52
+ * Use this when the uploader is on the host (e.g., CLI uploads),
53
+ * not in a container. Falls back to getUploadUrl() when no
54
+ * external endpoint is configured.
55
+ */
56
+ getInternalUploadUrl(key: string): Promise<string>;
57
+ /**
58
+ * Set initial metadata on an object that was uploaded via pre-signed URL.
59
+ * Pre-signed PUT URLs cannot carry custom metadata, so this must be called
60
+ * after the agent confirms upload via cache.upload.complete.
61
+ * Sets created-at and last-accessed-at to now.
62
+ */
63
+ initMeta(key: string): Promise<void>;
64
+ }
65
+ import type { SharedS3Config } from '@kici-dev/shared';
66
+ /**
67
+ * S3 backend config. Extends the generic `SharedS3Config` from
68
+ * `@kici-dev/shared` with the cache-specific `ttlMs` knob.
69
+ */
70
+ export type S3CacheStorageConfig = SharedS3Config & {
71
+ type: 's3';
72
+ ttlMs: number;
73
+ };
74
+ /**
75
+ * Filesystem backend config. Stores blobs as files under `basePath` and
76
+ * mints HMAC-signed `http://baseUrl<routePrefix>...` URLs that the
77
+ * orchestrator's `/api/v1/cache/blob/*` route verifies before serving.
78
+ *
79
+ * Intended for single-host / E2E sandboxes where standing up an
80
+ * S3-compatible service is overkill.
81
+ */
82
+ export interface FilesystemCacheStorageConfig {
83
+ type: 'filesystem';
84
+ /** Absolute path to the cache root directory. */
85
+ basePath: string;
86
+ /** Item TTL in milliseconds. */
87
+ ttlMs: number;
88
+ /** Base URL the agent uses to reach the orchestrator. */
89
+ baseUrl: string;
90
+ /** Per-process HMAC secret used to sign URLs. */
91
+ signingSecret: string;
92
+ }
93
+ /**
94
+ * Configuration for creating a cache storage backend. Discriminated union
95
+ * keyed on `type` so new backends slot in without breaking consumers.
96
+ */
97
+ export type CacheStorageConfig = S3CacheStorageConfig | FilesystemCacheStorageConfig;
98
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1,44 @@
1
+ import type { Kysely } from 'kysely';
2
+ import type { Database } from '../db/types.js';
3
+ /**
4
+ * Delivery ID deduplication cache with dual-layer storage:
5
+ * 1. In-memory Set for hot-path performance (last 10,000 IDs)
6
+ * 2. Database persistence via dedup_cache table for durability
7
+ *
8
+ * In Hybrid mode, the same webhook may arrive both via WS relay and
9
+ * direct ingestion -- the dedup cache ensures each is processed once.
10
+ */
11
+ export declare class DedupCache {
12
+ private readonly db;
13
+ private readonly memoryCache;
14
+ private readonly insertionOrder;
15
+ constructor(db: Kysely<Database>);
16
+ /**
17
+ * Check if a delivery ID has already been processed.
18
+ * Checks in-memory cache first (fast path), then DB.
19
+ */
20
+ exists(deliveryId: string): Promise<boolean>;
21
+ /**
22
+ * Mark a delivery ID as processed.
23
+ * Inserts into both in-memory cache and database with 24h TTL.
24
+ * Idempotent -- duplicate marks are silently ignored.
25
+ */
26
+ mark(deliveryId: string): Promise<void>;
27
+ /**
28
+ * Remove expired entries from the database.
29
+ * Also trims the in-memory cache to MAX_MEMORY_CACHE_SIZE.
30
+ *
31
+ * @returns Number of expired entries deleted from database
32
+ */
33
+ cleanup(): Promise<number>;
34
+ /**
35
+ * Add a delivery ID to the in-memory cache, maintaining insertion order.
36
+ */
37
+ private addToMemoryCache;
38
+ /**
39
+ * Trim the in-memory cache to MAX_MEMORY_CACHE_SIZE entries,
40
+ * removing the oldest entries first.
41
+ */
42
+ private trimMemoryCache;
43
+ }
44
+ //# sourceMappingURL=dedup.d.ts.map
@@ -0,0 +1,83 @@
1
+ import { EventLogStatus, EventLogSource } from '@kici-dev/engine';
2
+ import type { Kysely } from 'kysely';
3
+ import type { Database } from '../db/types.js';
4
+ import type { LogStorage } from '../reporting/log-storage.js';
5
+ import type { WebhookInfo } from './handler.js';
6
+ /** Configuration for the writer. */
7
+ export interface EventLogWriterOptions {
8
+ /** Soft cap in bytes for payload upload (default 5 MB). */
9
+ maxPayloadBytes: number;
10
+ }
11
+ /**
12
+ * Outcome metadata recorded alongside the delivery row.
13
+ *
14
+ * Most fields are optional and default to safe values — callers in the early
15
+ * branches (duplicate, dedup) only know the routing-level metadata; later
16
+ * branches (processed, lockfile_missing, failed) carry richer outcome data.
17
+ */
18
+ export interface EventLogOutcome {
19
+ /** Resolved tenant ID. Required (the table is org-scoped). */
20
+ orgId: string;
21
+ /** Where the delivery arrived. */
22
+ source: EventLogSource;
23
+ /** Outcome status. */
24
+ status: EventLogStatus;
25
+ /** Workflows matched by trigger evaluation (default 0). */
26
+ matchedCount?: number;
27
+ /** owner/repo extracted from payload (when available). */
28
+ repoIdentifier?: string | null;
29
+ /** Best-effort ref/branch (when extractable). */
30
+ ref?: string | null;
31
+ /** First run spawned by this delivery. */
32
+ runId?: string | null;
33
+ /** Failure reason when status='failed'. */
34
+ errorMessage?: string | null;
35
+ }
36
+ /**
37
+ * Pre-computed payload representation. Letting callers serialize once and
38
+ * pass both the bytes and the JSON shape avoids double-stringify in the
39
+ * hot path. The writer hashes the bytes, gzips them, and uploads.
40
+ */
41
+ export interface PayloadBytes {
42
+ /** UTF-8 encoded raw body bytes (what Platform hashed). */
43
+ raw: Buffer;
44
+ }
45
+ /**
46
+ * Build a `PayloadBytes` from the parsed webhook payload object. Uses
47
+ * `JSON.stringify` with no formatting — same shape Platform uses to compute
48
+ * its hash on the relay path (Platform actually hashes the inbound HTTP body
49
+ * directly; for relay-replayed webhooks the orchestrator only ever sees the
50
+ * parsed object, so we re-stringify deterministically and hash that).
51
+ *
52
+ * For DIRECT ingress paths (orchestrator HTTP endpoint) callers SHOULD pass
53
+ * the raw HTTP body buffer instead — that matches Platform's hash byte-for-
54
+ * byte for the same delivery in mixed-mode setups.
55
+ */
56
+ export declare function payloadFromObject(payload: unknown): PayloadBytes;
57
+ /**
58
+ * Build a `PayloadBytes` from a raw HTTP body string (direct ingress).
59
+ */
60
+ export declare function payloadFromRawBody(body: string): PayloadBytes;
61
+ export declare class EventLogWriter {
62
+ private readonly db;
63
+ private readonly logStorage;
64
+ private readonly opts;
65
+ constructor(db: Kysely<Database>, logStorage: LogStorage, opts: EventLogWriterOptions);
66
+ /**
67
+ * Build the canonical object-storage key for a delivery's payload.
68
+ * Exposed so the cleanup job can compute keys for deletion without
69
+ * calling back into the writer instance.
70
+ */
71
+ static payloadKey(orgId: string, deliveryId: string): string;
72
+ /**
73
+ * Record a delivery outcome.
74
+ *
75
+ * Idempotent on `(org_id, delivery_id)`: if a row already exists (e.g. the
76
+ * pipeline already wrote a `received` row before this `processed` follow-up),
77
+ * the existing row is updated with the new outcome metadata. The
78
+ * payload_key / hash / size fields are NOT overwritten on update — those
79
+ * come from the original delivery's body.
80
+ */
81
+ record(info: WebhookInfo, payload: PayloadBytes, outcome: EventLogOutcome): Promise<void>;
82
+ }
83
+ //# sourceMappingURL=event-log.d.ts.map
@@ -0,0 +1,169 @@
1
+ /**
2
+ * Generic webhook source manager.
3
+ *
4
+ * Provides CRUD operations for webhook source configurations stored in
5
+ * the generic_webhook_sources table. Each source defines verification method,
6
+ * event type extraction rules, rate limits, and header filtering.
7
+ */
8
+ import { type Kysely } from 'kysely';
9
+ import type { Database, GenericWebhookSource } from '../db/types.js';
10
+ import type { VerificationMethod } from '../providers/generic/verification.js';
11
+ import { type UniversalGitConfig } from '../providers/universal-git/config.js';
12
+ /**
13
+ * Input for creating a new generic webhook source.
14
+ */
15
+ interface CreateSourceInput {
16
+ orgId: string;
17
+ name: string;
18
+ verificationMethod?: VerificationMethod;
19
+ verificationConfig?: Record<string, unknown>;
20
+ eventTypeHeader?: string;
21
+ eventTypePath?: string;
22
+ idempotencyKeyHeader?: string;
23
+ idempotencyKeyPath?: string;
24
+ dedupWindowSeconds?: number;
25
+ maxPayloadBytes?: number;
26
+ allowedEvents?: string[];
27
+ stripHeaders?: string[];
28
+ rateLimitRpm?: number;
29
+ /** Provider implementation: 'generic' (default) or 'internal' (E2E/staging
30
+ * github-shaped payload routing through InternalWebhookNormalizer). */
31
+ providerType?: 'generic' | 'internal';
32
+ /** Universal-git configuration — when set, promotes this source from a
33
+ * payload-only generic webhook to a full git-aware source that can register
34
+ * workflows, fetch lock files, and be cloned by agents. Validated against
35
+ * `UniversalGitConfigSchema`; stored as JSONB in `generic_webhook_sources.git_config`. */
36
+ gitConfig?: UniversalGitConfig;
37
+ }
38
+ /**
39
+ * Input for updating an existing generic webhook source. Use `gitConfig: null`
40
+ * to explicitly demote a universal-git source back to a plain generic webhook
41
+ * (omitting the field leaves the existing config untouched).
42
+ */
43
+ type UpdateSourceInput = Partial<Omit<CreateSourceInput, 'orgId' | 'gitConfig'>> & {
44
+ gitConfig?: UniversalGitConfig | null;
45
+ };
46
+ /**
47
+ * Generic webhook source manager.
48
+ *
49
+ * Manages CRUD operations for generic_webhook_sources table.
50
+ * Sources are identified by routing keys with format `generic:<orgId>:<sourceId>`.
51
+ */
52
+ export declare class GenericSourceManager {
53
+ private readonly db;
54
+ constructor(db: Kysely<Database>);
55
+ /**
56
+ * Create a new generic webhook source.
57
+ * Generates a routing key in format `generic:<orgId>:<sourceId>`.
58
+ */
59
+ create(input: CreateSourceInput): Promise<GenericWebhookSource>;
60
+ /**
61
+ * Get a source by ID (excludes soft-deleted sources).
62
+ */
63
+ getById(id: string): Promise<GenericWebhookSource | null>;
64
+ /**
65
+ * Get a source by routing key (excludes soft-deleted and disabled sources).
66
+ */
67
+ getByRoutingKey(routingKey: string): Promise<GenericWebhookSource | null>;
68
+ /**
69
+ * Get a source by org ID and name (unique lookup, excludes soft-deleted).
70
+ */
71
+ getByOrgAndName(orgId: string, name: string): Promise<GenericWebhookSource | null>;
72
+ /**
73
+ * List all sources for an org.
74
+ */
75
+ list(orgId: string, includeDeleted?: boolean): Promise<GenericWebhookSource[]>;
76
+ /**
77
+ * List all enabled, non-deleted sources matching a provider type.
78
+ *
79
+ * Used at orchestrator startup to register provider bundles per routing key
80
+ * (e.g. registering an InternalWebhookNormalizer bundle for every
81
+ * provider_type='internal' source so the staging stg-ha smoke test and
82
+ * other internal-bundle E2E harnesses can dispatch real runs through the
83
+ * generic endpoint without a real GitHub signature).
84
+ */
85
+ listByProviderType(providerType: 'generic' | 'internal'): Promise<GenericWebhookSource[]>;
86
+ /**
87
+ * List all enabled, non-deleted sources with a non-null `git_config`
88
+ * (universal-git sources). Used at orchestrator startup + config reload
89
+ * to register a universal-git `ProviderBundle` under each source's
90
+ * routing key.
91
+ */
92
+ listUniversalGitSources(): Promise<GenericWebhookSource[]>;
93
+ /**
94
+ * Update a source's configuration.
95
+ */
96
+ update(id: string, input: UpdateSourceInput): Promise<GenericWebhookSource | null>;
97
+ /**
98
+ * Soft delete a source (sets deleted_at timestamp).
99
+ */
100
+ softDelete(id: string): Promise<void>;
101
+ /**
102
+ * Hard delete a source (removes the row entirely).
103
+ */
104
+ hardDelete(id: string): Promise<void>;
105
+ /**
106
+ * Enable a source.
107
+ */
108
+ enable(id: string): Promise<void>;
109
+ /**
110
+ * Disable a source.
111
+ */
112
+ disable(id: string): Promise<void>;
113
+ /**
114
+ * Check if a request is a duplicate within the dedup window.
115
+ * Uses the kici_events table for idempotency checking.
116
+ *
117
+ * @param sourceId - Source ID
118
+ * @param idempotencyKey - Idempotency key from header or payload
119
+ * @returns true if this is a duplicate request
120
+ */
121
+ checkIdempotency(sourceId: string, idempotencyKey: string): Promise<boolean>;
122
+ /**
123
+ * Record an idempotency marker after successful processing.
124
+ * Inserts a `__dedup:<key>` event into kici_events so that
125
+ * checkIdempotency can detect retries within the dedup window.
126
+ *
127
+ * @param sourceId - Source ID
128
+ * @param idempotencyKey - Idempotency key from header or payload
129
+ */
130
+ markIdempotency(sourceId: string, idempotencyKey: string): Promise<void>;
131
+ /**
132
+ * Check if payload size is within the source's limit.
133
+ *
134
+ * @param sourceId - Source ID
135
+ * @param bodyLength - Length of the request body in bytes
136
+ * @returns Whether the payload is allowed and what the max is
137
+ */
138
+ checkPayloadSize(sourceId: string, bodyLength: number): Promise<{
139
+ allowed: boolean;
140
+ maxBytes: number;
141
+ }>;
142
+ }
143
+ /**
144
+ * Return the active (non-soft-deleted) generic_webhook_sources routing keys
145
+ * for Platform registration. Excluding soft-deleted rows is critical — if a
146
+ * source is recreated with the same name, Platform would otherwise see the
147
+ * orchestrator register both the stale routing key and the fresh one, and
148
+ * end up routing a subset of orchestrators to the wrong key. This matches
149
+ * every other query on this table that filters `deleted_at IS NULL` (see
150
+ * `GenericSourceManager.getById`, `.list`, `.listByProviderType`, etc.).
151
+ *
152
+ * Returns `provider_type` alongside the routing key so callers can decide
153
+ * whether the local orchestrator can actually serve each row. A peer that
154
+ * cannot serve a provider_type (e.g. an `internal` source on a peer with no
155
+ * `KICI_INTERNAL_PROVIDER_REPO_PATH`) MUST NOT advertise that routing key
156
+ * to Platform — otherwise Platform's least-loaded relay may pick that peer
157
+ * and the webhook is silently dropped on a pipeline that has no working
158
+ * lock-file fetcher.
159
+ */
160
+ export declare function loadActiveGenericRoutingKeys(db: Kysely<Database>): Promise<Array<{
161
+ routing_key: string;
162
+ customer_id: string;
163
+ provider_type: string;
164
+ name: string;
165
+ /** Whether the row has a non-null `git_config` (universal-git source). */
166
+ has_git_config: boolean;
167
+ }>>;
168
+ export {};
169
+ //# sourceMappingURL=generic-sources.d.ts.map
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Provider-agnostic webhook info.
3
+ *
4
+ * All provider-specific details are abstracted away. The routingKey
5
+ * and provider fields enable provider lookup, while the rest of the
6
+ * fields are universal across all webhook providers.
7
+ */
8
+ import type { ProviderType } from '@kici-dev/engine';
9
+ export interface WebhookInfo {
10
+ /** Routing key (e.g., "github:12345") */
11
+ routingKey: string;
12
+ /** Unique delivery ID */
13
+ deliveryId: string;
14
+ /** Provider event type (e.g., "push", "pull_request") */
15
+ event: string;
16
+ /** Action field from payload (e.g., "opened"), null if not present */
17
+ action: string | null;
18
+ /** Provider type (e.g., "github") */
19
+ provider: ProviderType;
20
+ /** Raw webhook payload */
21
+ payload: Record<string, unknown>;
22
+ }
23
+ //# sourceMappingURL=handler.d.ts.map