@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.
- package/LICENSE +661 -0
- package/README.md +1 -6
- package/dist/__test-helpers__/mock-db.d.ts +103 -0
- package/dist/__test-helpers__/mock-ws.d.ts +13 -0
- package/dist/agent/dispatcher.d.ts +231 -0
- package/dist/agent/ownership-tracker.d.ts +46 -0
- package/dist/agent/registry.d.ts +255 -0
- package/dist/agent/token-store.d.ts +96 -0
- package/dist/app.d.ts +234 -0
- package/dist/audit/access-log.d.ts +92 -0
- package/dist/audit/sampling-rate-limiter.d.ts +41 -0
- package/dist/cache/build-coordinator.d.ts +42 -0
- package/dist/cache/dep-cache.d.ts +51 -0
- package/dist/cache/index.d.ts +16 -0
- package/dist/cache/pending-builds.d.ts +14 -0
- package/dist/cache/pending-dynamics.d.ts +15 -0
- package/dist/cache/pending-inits.d.ts +19 -0
- package/dist/cache/pending-tracker.d.ts +65 -0
- package/dist/cache/source-cache.d.ts +30 -0
- package/dist/cli/api-client.d.ts +411 -0
- package/dist/cli/commands/access-log.d.ts +30 -0
- package/dist/cli/commands/agent-service/index.d.ts +15 -0
- package/dist/cli/commands/agent-service/install.d.ts +9 -0
- package/dist/cli/commands/agent-service/logs.d.ts +9 -0
- package/dist/cli/commands/agent-service/restart.d.ts +8 -0
- package/dist/cli/commands/agent-service/start.d.ts +8 -0
- package/dist/cli/commands/agent-service/status.d.ts +10 -0
- package/dist/cli/commands/agent-service/stop.d.ts +8 -0
- package/dist/cli/commands/agent-service/uninstall.d.ts +9 -0
- package/dist/cli/commands/agent-service/upgrade.d.ts +11 -0
- package/dist/cli/commands/agent.d.ts +10 -0
- package/dist/cli/commands/api-key.d.ts +12 -0
- package/dist/cli/commands/audit.d.ts +9 -0
- package/dist/cli/commands/backend.d.ts +17 -0
- package/dist/cli/commands/cold-store-impl.d.ts +101 -0
- package/dist/cli/commands/cold-store.d.ts +30 -0
- package/dist/cli/commands/config.d.ts +16 -0
- package/dist/cli/commands/db.d.ts +19 -0
- package/dist/cli/commands/debug-bundle.d.ts +16 -0
- package/dist/cli/commands/diagnose.d.ts +15 -0
- package/dist/cli/commands/environment.d.ts +24 -0
- package/dist/cli/commands/event-dlq.d.ts +19 -0
- package/dist/cli/commands/event-log.d.ts +27 -0
- package/dist/cli/commands/event.d.ts +4 -0
- package/dist/cli/commands/execution.d.ts +17 -0
- package/dist/cli/commands/inspect-bundle.d.ts +16 -0
- package/dist/cli/commands/maintenance.d.ts +4 -0
- package/dist/cli/commands/orchestrator-service/index.d.ts +12 -0
- package/dist/cli/commands/orchestrator-service/install.d.ts +10 -0
- package/dist/cli/commands/orchestrator-service/logs.d.ts +10 -0
- package/dist/cli/commands/orchestrator-service/restart.d.ts +8 -0
- package/dist/cli/commands/orchestrator-service/start.d.ts +8 -0
- package/dist/cli/commands/orchestrator-service/status.d.ts +10 -0
- package/dist/cli/commands/orchestrator-service/stop.d.ts +8 -0
- package/dist/cli/commands/orchestrator-service/uninstall.d.ts +9 -0
- package/dist/cli/commands/orchestrator-service/upgrade.d.ts +12 -0
- package/dist/cli/commands/org-settings.d.ts +17 -0
- package/dist/cli/commands/peer.d.ts +13 -0
- package/dist/cli/commands/queue.d.ts +16 -0
- package/dist/cli/commands/registration.d.ts +18 -0
- package/dist/cli/commands/rotate.d.ts +9 -0
- package/dist/cli/commands/runs.d.ts +34 -0
- package/dist/cli/commands/secret.d.ts +12 -0
- package/dist/cli/commands/shared/db.d.ts +16 -0
- package/dist/cli/commands/shared/versioned-upgrade.d.ts +38 -0
- package/dist/cli/commands/source.d.ts +24 -0
- package/dist/cli/commands/token.d.ts +10 -0
- package/dist/cli/commands/workflow.d.ts +31 -0
- package/dist/cli/join.d.ts +14 -0
- package/dist/cli/kici-admin.d.ts +13 -0
- package/dist/cli/lazy-deps/cache.d.ts +17 -0
- package/dist/cli/lazy-deps/downloader.d.ts +33 -0
- package/dist/cli/lazy-deps/registry.d.ts +43 -0
- package/dist/cli/service/compose.d.ts +25 -0
- package/dist/cli/service/index.d.ts +24 -0
- package/dist/cli/service/launchd.d.ts +34 -0
- package/dist/cli/service/platform-detect.d.ts +59 -0
- package/dist/cli/service/systemd.d.ts +41 -0
- package/dist/cli/service/types.d.ts +91 -0
- package/dist/cli/service/windows.d.ts +20 -0
- package/dist/cli/wizard/agent-wizard.d.ts +24 -0
- package/dist/cli/wizard/orchestrator-wizard.d.ts +38 -0
- package/dist/cli/wizard/prompts.d.ts +23 -0
- package/dist/cli.js +11435 -0
- package/dist/cluster/cluster-identity.d.ts +59 -0
- package/dist/cluster/coordinator.d.ts +204 -0
- package/dist/cluster/health-api.d.ts +30 -0
- package/dist/cluster/index.d.ts +24 -0
- package/dist/cluster/join-client.d.ts +75 -0
- package/dist/cluster/join-handler.d.ts +58 -0
- package/dist/cluster/join-token.d.ts +94 -0
- package/dist/cluster/orphan-recovery.d.ts +67 -0
- package/dist/cluster/peer-client.d.ts +190 -0
- package/dist/cluster/peer-credentials.d.ts +108 -0
- package/dist/cluster/peer-crypto.d.ts +57 -0
- package/dist/cluster/peer-handler.d.ts +97 -0
- package/dist/cluster/peer-registry.d.ts +186 -0
- package/dist/cluster/raft-state.d.ts +36 -0
- package/dist/cluster/raft.d.ts +140 -0
- package/dist/cold-store/load-access-log-range.d.ts +73 -0
- package/dist/cold-store/load-event-log-range.d.ts +62 -0
- package/dist/cold-store/load-secret-audit-log-range.d.ts +38 -0
- package/dist/cold-store/orchestrator-cold-store.d.ts +58 -0
- package/dist/cold-store/tables/access-log.d.ts +80 -0
- package/dist/cold-store/tables/event-log.d.ts +70 -0
- package/dist/cold-store/tables/execution-jobs.d.ts +63 -0
- package/dist/cold-store/tables/execution-runs.d.ts +81 -0
- package/dist/cold-store/tables/execution-steps.d.ts +65 -0
- package/dist/cold-store/tables/secret-audit-log.d.ts +77 -0
- package/dist/concurrency/dispatch-next-queued.d.ts +63 -0
- package/dist/concurrency/group-tracker.d.ts +51 -0
- package/dist/concurrency/index.d.ts +3 -0
- package/dist/concurrency/queue-manager.d.ts +68 -0
- package/dist/concurrency/waiters.d.ts +58 -0
- package/dist/config/encryption.d.ts +82 -0
- package/dist/config/env-overlay.d.ts +45 -0
- package/dist/config/index.d.ts +16 -0
- package/dist/config/loader.d.ts +26 -0
- package/dist/config/reload.d.ts +113 -0
- package/dist/config/resolver.d.ts +47 -0
- package/dist/config/schema.d.ts +210 -0
- package/dist/config/shared-store.d.ts +142 -0
- package/dist/config/types.d.ts +218 -0
- package/dist/config.d.ts +249 -0
- package/dist/cron/cron-scheduler.d.ts +78 -0
- package/dist/cron/cron-store.d.ts +38 -0
- package/dist/dashboard/handler.d.ts +243 -0
- package/dist/db/client.d.ts +13 -0
- package/dist/db/migration-provider.d.ts +9 -0
- package/dist/db/migrations/001_initial.d.ts +8 -0
- package/dist/db/migrations/002_config_versions_key_version.d.ts +16 -0
- package/dist/db/migrations/003_access_log.d.ts +26 -0
- package/dist/db/migrations/004_rename_bundle_to_source.d.ts +19 -0
- package/dist/db/migrations/005_cold_store_chunk_counter.d.ts +19 -0
- package/dist/db/migrations/006_runs_jobs_steps_archived_at.d.ts +38 -0
- package/dist/db/migrations/007_audit_logs_archived_at.d.ts +42 -0
- package/dist/db/migrations/008_event_log_archived_at.d.ts +40 -0
- package/dist/db/migrations/009_access_log_trigram.d.ts +15 -0
- package/dist/db/migrations/010_cold_store_chunks.d.ts +34 -0
- package/dist/db/migrations/011_drop_source_secrets_notify.d.ts +21 -0
- package/dist/db/migrations/012_peer_credentials_active_uniq.d.ts +28 -0
- package/dist/db/migrations/013_execution_log_bytes.d.ts +21 -0
- package/dist/db/migrations/014_kici_events_lease_retry.d.ts +36 -0
- package/dist/db/migrations/015_org_settings_customer_scoped.d.ts +30 -0
- package/dist/db/migrations/016_org_settings_allow_http_npm.d.ts +15 -0
- package/dist/db/migrations/017_org_id_widen.d.ts +4 -0
- package/dist/db/migrations/018_org_id_prefix_backfill.d.ts +4 -0
- package/dist/db/migrator.d.ts +32 -0
- package/dist/db/types.d.ts +1266 -0
- package/dist/diagnostics/bundle-reader.d.ts +48 -0
- package/dist/diagnostics/bundle-writer.d.ts +57 -0
- package/dist/diagnostics/checks/agents.d.ts +10 -0
- package/dist/diagnostics/checks/certs.d.ts +9 -0
- package/dist/diagnostics/checks/config.d.ts +10 -0
- package/dist/diagnostics/checks/db.d.ts +9 -0
- package/dist/diagnostics/checks/disk.d.ts +9 -0
- package/dist/diagnostics/checks/index.d.ts +17 -0
- package/dist/diagnostics/checks/ws.d.ts +9 -0
- package/dist/diagnostics/index.d.ts +13 -0
- package/dist/diagnostics/runner.d.ts +23 -0
- package/dist/diagnostics/types.d.ts +38 -0
- package/dist/entry-helpers.d.ts +93 -0
- package/dist/environments/binding-store.d.ts +27 -0
- package/dist/environments/environment-store.d.ts +74 -0
- package/dist/environments/held-runs.d.ts +64 -0
- package/dist/environments/index.d.ts +10 -0
- package/dist/environments/protection/branch-gate.d.ts +5 -0
- package/dist/environments/protection/concurrency-gate.d.ts +7 -0
- package/dist/environments/protection/pipeline.d.ts +18 -0
- package/dist/environments/protection/reviewer-gate.d.ts +7 -0
- package/dist/environments/protection/trust-gate.d.ts +7 -0
- package/dist/environments/protection/wait-timer-gate.d.ts +7 -0
- package/dist/environments/variable-store.d.ts +39 -0
- package/dist/events/circuit-breaker.d.ts +33 -0
- package/dist/events/event-emitter.d.ts +55 -0
- package/dist/events/event-retry-scanner.d.ts +52 -0
- package/dist/events/event-router.d.ts +183 -0
- package/dist/events/event-store.d.ts +157 -0
- package/dist/events/trust-store.d.ts +54 -0
- package/dist/events/types.d.ts +61 -0
- package/dist/helpers/ip-extraction.d.ts +29 -0
- package/dist/helpers/rate-limiter.d.ts +23 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +772 -0
- package/dist/lockfile-cache.d.ts +39 -0
- package/dist/metrics/agent-metrics-aggregator.d.ts +116 -0
- package/dist/metrics/metrics-reporter.d.ts +40 -0
- package/dist/metrics/prometheus.d.ts +261 -0
- package/dist/metrics/scheduled-jobs.d.ts +20 -0
- package/dist/orchestrator-core.d.ts +193 -0
- package/dist/pipeline/dispatch-matched-workflow.d.ts +102 -0
- package/dist/pipeline/inline-eval.d.ts +28 -0
- package/dist/pipeline/install-secrets-resolver.d.ts +73 -0
- package/dist/pipeline/manual-schedule.d.ts +21 -0
- package/dist/pipeline/needs-scheduler.d.ts +85 -0
- package/dist/pipeline/process-webhook.d.ts +38 -0
- package/dist/pipeline/processor.d.ts +326 -0
- package/dist/pipeline/rerun.d.ts +79 -0
- package/dist/pipeline/test-pipeline.d.ts +110 -0
- package/dist/provider-registry.d.ts +122 -0
- package/dist/providers/generic/index.d.ts +23 -0
- package/dist/providers/generic/normalizer.d.ts +112 -0
- package/dist/providers/generic/verification.d.ts +47 -0
- package/dist/providers/github/auth.d.ts +60 -0
- package/dist/providers/github/changed-files.d.ts +51 -0
- package/dist/providers/github/check-status-poster.d.ts +35 -0
- package/dist/providers/github/contributor-resolver.d.ts +30 -0
- package/dist/providers/github/index.d.ts +20 -0
- package/dist/providers/github/lock-file.d.ts +32 -0
- package/dist/providers/github/normalizer.d.ts +103 -0
- package/dist/providers/github/repo-url.d.ts +35 -0
- package/dist/providers/internal/index.d.ts +32 -0
- package/dist/providers/internal/lock-file-fetcher.d.ts +34 -0
- package/dist/providers/internal/normalizer.d.ts +89 -0
- package/dist/providers/internal/repo-url-builder.d.ts +42 -0
- package/dist/providers/universal-git/changed-files.d.ts +42 -0
- package/dist/providers/universal-git/clone-token.d.ts +83 -0
- package/dist/providers/universal-git/config.d.ts +192 -0
- package/dist/providers/universal-git/index.d.ts +55 -0
- package/dist/providers/universal-git/lock-file.d.ts +71 -0
- package/dist/providers/universal-git/normalizer.d.ts +90 -0
- package/dist/providers/universal-git/repo-url.d.ts +50 -0
- package/dist/providers/universal-git/ssh-auth.d.ts +94 -0
- package/dist/queue/bootstrap.d.ts +50 -0
- package/dist/queue/cleanup.d.ts +41 -0
- package/dist/queue/depth-refresher.d.ts +65 -0
- package/dist/queue/job-queue.d.ts +343 -0
- package/dist/queue/scheduled-job.d.ts +91 -0
- package/dist/registration/extractor.d.ts +44 -0
- package/dist/registration/registration-index.d.ts +162 -0
- package/dist/registration/registration-store.d.ts +111 -0
- package/dist/reporting/check-run-summary.d.ts +102 -0
- package/dist/reporting/commit-status.d.ts +382 -0
- package/dist/reporting/execution-tracker.d.ts +538 -0
- package/dist/reporting/fs-log-storage.d.ts +41 -0
- package/dist/reporting/log-pull-handler.d.ts +35 -0
- package/dist/reporting/log-storage.d.ts +70 -0
- package/dist/reporting/log-writer.d.ts +45 -0
- package/dist/reporting/s3-log-storage.d.ts +42 -0
- package/dist/reporting/step-log-buffer.d.ts +57 -0
- package/dist/routes/admin-access-log.d.ts +34 -0
- package/dist/routes/admin-backends.d.ts +28 -0
- package/dist/routes/admin-config.d.ts +57 -0
- package/dist/routes/admin-db.d.ts +20 -0
- package/dist/routes/admin-environments.d.ts +42 -0
- package/dist/routes/admin-errors.d.ts +4 -0
- package/dist/routes/admin-event-dlq.d.ts +39 -0
- package/dist/routes/admin-event-log.d.ts +42 -0
- package/dist/routes/admin-events.d.ts +46 -0
- package/dist/routes/admin-maintenance.d.ts +22 -0
- package/dist/routes/admin-org-settings.d.ts +29 -0
- package/dist/routes/admin-queue-execution.d.ts +27 -0
- package/dist/routes/admin-registrations.d.ts +37 -0
- package/dist/routes/admin-runs.d.ts +57 -0
- package/dist/routes/admin-scheduled-jobs.d.ts +36 -0
- package/dist/routes/admin-sources.d.ts +18 -0
- package/dist/routes/admin.d.ts +103 -0
- package/dist/routes/capabilities.d.ts +24 -0
- package/dist/routes/diagnostics.d.ts +16 -0
- package/dist/routes/health.d.ts +20 -0
- package/dist/routes/test-trigger.d.ts +41 -0
- package/dist/routes/uploads.d.ts +38 -0
- package/dist/routes/webhooks.d.ts +36 -0
- package/dist/scaler/bare-metal-backend.d.ts +107 -0
- package/dist/scaler/config.d.ts +303 -0
- package/dist/scaler/container-backend.d.ts +125 -0
- package/dist/scaler/file-tail.d.ts +23 -0
- package/dist/scaler/firecracker-api.d.ts +100 -0
- package/dist/scaler/firecracker-backend.d.ts +263 -0
- package/dist/scaler/index.d.ts +24 -0
- package/dist/scaler/ip-allocator.d.ts +177 -0
- package/dist/scaler/label-matcher.d.ts +73 -0
- package/dist/scaler/log-forwarder.d.ts +54 -0
- package/dist/scaler/machine-ledger.d.ts +160 -0
- package/dist/scaler/manager.d.ts +338 -0
- package/dist/scaler/nftables.d.ts +85 -0
- package/dist/scaler/types.d.ts +388 -0
- package/dist/scaler/warm-pool.d.ts +81 -0
- package/dist/secrets/audit-logger.d.ts +65 -0
- package/dist/secrets/backend-health.d.ts +60 -0
- package/dist/secrets/backend-registry.d.ts +68 -0
- package/dist/secrets/backend-sync.d.ts +40 -0
- package/dist/secrets/cleanup.d.ts +40 -0
- package/dist/secrets/config.d.ts +51 -0
- package/dist/secrets/crypto.d.ts +49 -0
- package/dist/secrets/ephemeral-keys.d.ts +49 -0
- package/dist/secrets/index.d.ts +17 -0
- package/dist/secrets/pg-secret-store.d.ts +105 -0
- package/dist/secrets/rbac.d.ts +47 -0
- package/dist/secrets/secret-output-store.d.ts +46 -0
- package/dist/secrets/secret-resolver.d.ts +137 -0
- package/dist/secrets/source-credentials.d.ts +61 -0
- package/dist/secrets/token-manager.d.ts +63 -0
- package/dist/secrets/vault-secret-store.d.ts +85 -0
- package/dist/security/comment-handler.d.ts +67 -0
- package/dist/security/contributor-cache.d.ts +75 -0
- package/dist/security/global-workflow-policy.d.ts +72 -0
- package/dist/security/lock-source.d.ts +34 -0
- package/dist/security/trust-resolver.d.ts +108 -0
- package/dist/security/workflow-diff.d.ts +26 -0
- package/dist/server.d.ts +17 -0
- package/dist/server.js +48055 -0
- package/dist/sources/index.d.ts +10 -0
- package/dist/sources/source-manager.d.ts +63 -0
- package/dist/sources/source-store.d.ts +79 -0
- package/dist/sources/source-validator.d.ts +16 -0
- package/dist/stale-detector/stale-run-detector.d.ts +109 -0
- package/dist/standalone.d.ts +20 -0
- package/dist/standalone.js +41546 -0
- package/dist/storage/blob-routes.d.ts +20 -0
- package/dist/storage/filesystem.d.ts +60 -0
- package/dist/storage/index.d.ts +20 -0
- package/dist/storage/s3.d.ts +68 -0
- package/dist/storage/sign-url.d.ts +45 -0
- package/dist/storage/types.d.ts +98 -0
- package/dist/webhook/dedup.d.ts +44 -0
- package/dist/webhook/event-log.d.ts +83 -0
- package/dist/webhook/generic-sources.d.ts +169 -0
- package/dist/webhook/handler.d.ts +23 -0
- package/dist/webhook/relay-buffer.d.ts +96 -0
- package/dist/webhook/verify-inbound.d.ts +78 -0
- package/dist/worker/in-memory-execution-tracker.d.ts +94 -0
- package/dist/worker/in-memory-job-queue.d.ts +74 -0
- package/dist/worker/static-agent-token-store.d.ts +58 -0
- package/dist/worker/worker-status.d.ts +36 -0
- package/dist/worker-core.d.ts +74 -0
- package/dist/ws/agent-api-registry.d.ts +49 -0
- package/dist/ws/agent-handler.d.ts +176 -0
- package/dist/ws/agent-heartbeat.d.ts +45 -0
- package/dist/ws/dashboard-backends-handler.d.ts +51 -0
- package/dist/ws/dashboard-diagnostics-handler.d.ts +56 -0
- package/dist/ws/dashboard-env-handler.d.ts +107 -0
- package/dist/ws/dashboard-global-workflows-handler.d.ts +72 -0
- package/dist/ws/dashboard-registrations-handler.d.ts +84 -0
- package/dist/ws/event-buffer.d.ts +16 -0
- package/dist/ws/observer-handler.d.ts +42 -0
- package/dist/ws/observer-registry.d.ts +88 -0
- package/dist/ws/platform-client.d.ts +270 -0
- package/dist/ws/server-options.d.ts +15 -0
- package/package.json +87 -7
- package/sbom.spdx.json +14370 -0
- package/index.js +0 -3
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-messageId reassembly buffer for the chunked webhook.relay protocol.
|
|
3
|
+
*
|
|
4
|
+
* Platform splits the inbound webhook body into N WS frames so a 25 MiB body
|
|
5
|
+
* can interleave with other concurrent traffic. The orchestrator must:
|
|
6
|
+
* - Allocate a buffer on `webhook.relay.start` keyed by `messageId`.
|
|
7
|
+
* - Append each `webhook.relay.chunk` in strict ascending sequence order.
|
|
8
|
+
* - Enforce the 25 MiB hard ceiling (defensively; Platform also caps).
|
|
9
|
+
* - On the chunk where `final=true`, return the assembled body + metadata so
|
|
10
|
+
* the WS handler can run verify+process and emit the ack.
|
|
11
|
+
* - Garbage-collect buffers Platform abandoned mid-stream (e.g. the originating
|
|
12
|
+
* Platform process crashed between chunks) via a per-buffer TTL.
|
|
13
|
+
*
|
|
14
|
+
* Concurrency: a single orchestrator may be receiving many concurrent inbound
|
|
15
|
+
* webhooks; the registry is a Map keyed by messageId so streams don't collide.
|
|
16
|
+
*
|
|
17
|
+
* Errors are NEVER thrown — every malformed input produces a typed `ChunkError`
|
|
18
|
+
* with a non-secret-bearing diagnostic the WS handler maps to a
|
|
19
|
+
* `rejected_misconfigured` ack. This keeps the WS handler inside its 5 s budget
|
|
20
|
+
* and prevents a malicious sender from killing the orch process via a bad frame.
|
|
21
|
+
*/
|
|
22
|
+
/** Metadata captured on the start frame and kept for the lifetime of the stream. */
|
|
23
|
+
export interface RelayStartMeta {
|
|
24
|
+
routingKey: string;
|
|
25
|
+
deliveryId: string;
|
|
26
|
+
event: string;
|
|
27
|
+
action: string | null | undefined;
|
|
28
|
+
signatureHeaderName: string | null | undefined;
|
|
29
|
+
signatureHeader: string | null | undefined;
|
|
30
|
+
clientIp: string | null | undefined;
|
|
31
|
+
headers: Record<string, string>;
|
|
32
|
+
totalSize: number;
|
|
33
|
+
chunkCount: number;
|
|
34
|
+
requestId?: string;
|
|
35
|
+
}
|
|
36
|
+
/** Outcome of a chunk apply: either still waiting, or completed with a ready body. */
|
|
37
|
+
export type ChunkApplyResult = {
|
|
38
|
+
status: 'pending';
|
|
39
|
+
} | {
|
|
40
|
+
status: 'completed';
|
|
41
|
+
meta: RelayStartMeta;
|
|
42
|
+
body: Buffer;
|
|
43
|
+
} | {
|
|
44
|
+
status: 'error';
|
|
45
|
+
reason: string;
|
|
46
|
+
};
|
|
47
|
+
/** Outcome of a start: success or rejection (e.g., duplicate messageId). */
|
|
48
|
+
export type StartResult = {
|
|
49
|
+
status: 'started';
|
|
50
|
+
} | {
|
|
51
|
+
status: 'error';
|
|
52
|
+
reason: string;
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* Per-messageId reassembly registry.
|
|
56
|
+
*
|
|
57
|
+
* Single instance per orchestrator process. Concurrent inbound webhooks share
|
|
58
|
+
* the same registry but operate on separate Map entries keyed by messageId.
|
|
59
|
+
*/
|
|
60
|
+
export declare class RelayBufferRegistry {
|
|
61
|
+
private readonly buffers;
|
|
62
|
+
private readonly bufferTtlMs;
|
|
63
|
+
constructor(options?: {
|
|
64
|
+
bufferTtlMs?: number;
|
|
65
|
+
});
|
|
66
|
+
/** Number of in-flight reassembly buffers. Useful for metrics + tests. */
|
|
67
|
+
get size(): number;
|
|
68
|
+
/**
|
|
69
|
+
* Begin a new reassembly stream. Allocates an entry keyed by `meta.messageId`
|
|
70
|
+
* (passed through the meta object's caller — actually keyed externally below).
|
|
71
|
+
*
|
|
72
|
+
* Returns an error if `messageId` is already in flight (Platform sent two
|
|
73
|
+
* `start` frames with the same id, indicates a sender bug or abuse).
|
|
74
|
+
*/
|
|
75
|
+
start(messageId: string, meta: RelayStartMeta): StartResult;
|
|
76
|
+
/**
|
|
77
|
+
* Apply one chunk. Returns `pending` if more chunks expected, `completed`
|
|
78
|
+
* with the assembled body when the final chunk closes the stream, or `error`
|
|
79
|
+
* for any malformed-stream condition.
|
|
80
|
+
*
|
|
81
|
+
* Stream errors drop the buffer — the caller MUST ack `rejected_misconfigured`
|
|
82
|
+
* and stop expecting further chunks for that messageId.
|
|
83
|
+
*/
|
|
84
|
+
chunk(messageId: string, sequence: number, dataBase64: string, final: boolean): ChunkApplyResult;
|
|
85
|
+
/**
|
|
86
|
+
* Drop an in-flight buffer (TTL fired, stream errored, or assembly completed).
|
|
87
|
+
* Idempotent: dropping a missing messageId is a no-op.
|
|
88
|
+
*/
|
|
89
|
+
drop(messageId: string): void;
|
|
90
|
+
/**
|
|
91
|
+
* Drop every in-flight buffer. Used during graceful shutdown so abandoned
|
|
92
|
+
* streams don't keep timers alive past process exit.
|
|
93
|
+
*/
|
|
94
|
+
clear(): void;
|
|
95
|
+
}
|
|
96
|
+
//# sourceMappingURL=relay-buffer.d.ts.map
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Inbound webhook verification dispatcher.
|
|
3
|
+
*
|
|
4
|
+
* Single entry point used by the orchestrator's chunked webhook.relay handler
|
|
5
|
+
* to decide whether an inbound webhook is trusted before it enters the normal
|
|
6
|
+
* processing pipeline. Dispatches by routing-key prefix to the appropriate
|
|
7
|
+
* provider verification path:
|
|
8
|
+
*
|
|
9
|
+
* - `github:*` -> reads the webhook secret from PgSecretStore at scope
|
|
10
|
+
* `__source__/<sourceId>` and runs engine `verifySignature`
|
|
11
|
+
* against the inbound `x-hub-signature-256` header (or the
|
|
12
|
+
* signature header forwarded from Platform).
|
|
13
|
+
* - `generic:*` -> looks up the source via GenericSourceManager, parses
|
|
14
|
+
* `verification_method` + `verification_config`, and runs
|
|
15
|
+
* the corresponding HMAC / bearer / IP-allowlist check via
|
|
16
|
+
* `verifyGenericWebhook`.
|
|
17
|
+
*
|
|
18
|
+
* All four `WebhookRelayResult` outcomes are produced here:
|
|
19
|
+
* - `accepted` when the source exists and the inbound signature/method passes.
|
|
20
|
+
* - `rejected_signature` when the source exists but the signature does not match
|
|
21
|
+
* any rotation secret (or method-specific check fails).
|
|
22
|
+
* - `rejected_unknown_source` when no row exists for the routing key (deleted,
|
|
23
|
+
* never created, or the prefix is for a provider that is not yet implemented).
|
|
24
|
+
* - `rejected_misconfigured` when the source exists but its server-side state
|
|
25
|
+
* prevents verification (no secret stored, malformed verification_config JSON,
|
|
26
|
+
* etc). Operators should see this in metrics and fix the source config.
|
|
27
|
+
*
|
|
28
|
+
* The `reason` string returned alongside each rejection is non-secret-bearing
|
|
29
|
+
* (no HMAC keys, bearer tokens, computed signatures); it is safe to surface in
|
|
30
|
+
* `webhook.ack` reason field and in dashboards.
|
|
31
|
+
*/
|
|
32
|
+
import type { Kysely } from 'kysely';
|
|
33
|
+
import type { WebhookRelayResult } from '@kici-dev/engine';
|
|
34
|
+
import type { Database } from '../db/types.js';
|
|
35
|
+
import type { PgSecretStore } from '../secrets/pg-secret-store.js';
|
|
36
|
+
import type { GenericSourceManager } from './generic-sources.js';
|
|
37
|
+
/** Verification result + non-secret-bearing diagnostic for the orchestrator ACK. */
|
|
38
|
+
export interface VerifyOutcome {
|
|
39
|
+
result: WebhookRelayResult;
|
|
40
|
+
reason?: string;
|
|
41
|
+
}
|
|
42
|
+
/** Inputs the orchestrator-side handler hands to the dispatcher. */
|
|
43
|
+
export interface VerifyInboundInput {
|
|
44
|
+
/** Routing key including provider prefix (`github:<appId>`, `generic:<orgId>:<sourceId>`, ...). */
|
|
45
|
+
routingKey: string;
|
|
46
|
+
/** Reassembled raw body bytes from the chunked relay stream. */
|
|
47
|
+
body: Buffer;
|
|
48
|
+
/** Lowercased headers Platform forwarded for this inbound webhook. */
|
|
49
|
+
headers: Record<string, string>;
|
|
50
|
+
/**
|
|
51
|
+
* Inbound HTTP signature header NAME (lowercased), e.g. `x-hub-signature-256`.
|
|
52
|
+
* Null when the inbound HTTP request had no signature header at all (some
|
|
53
|
+
* generic verification methods do not need it; HMAC paths reject in that case).
|
|
54
|
+
*/
|
|
55
|
+
signatureHeaderName: string | null;
|
|
56
|
+
/** Inbound HTTP signature header VALUE (the claimed signature). */
|
|
57
|
+
signatureHeader: string | null;
|
|
58
|
+
/** Inbound HTTP request client IP, for IP-allowlist verification. */
|
|
59
|
+
clientIp: string | null;
|
|
60
|
+
}
|
|
61
|
+
/** Dependencies the dispatcher reads from. */
|
|
62
|
+
export interface VerifyInboundDeps {
|
|
63
|
+
/** Kysely DB handle for `sources` table lookups (github sources). */
|
|
64
|
+
db: Kysely<Database>;
|
|
65
|
+
/** Encrypted secret store for reading webhook secrets at `__source__/<sourceId>`. */
|
|
66
|
+
secretStore: PgSecretStore;
|
|
67
|
+
/** Manager for `generic_webhook_sources` rows. */
|
|
68
|
+
genericSourceManager: GenericSourceManager;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Run inbound verification for one webhook.
|
|
72
|
+
*
|
|
73
|
+
* Pure-ish: reads from the DB + secret store, but never throws — every error
|
|
74
|
+
* path collapses into a `WebhookRelayResult`. The orchestrator handler is
|
|
75
|
+
* waiting on a 5 s ACK budget and must not block on an exception.
|
|
76
|
+
*/
|
|
77
|
+
export declare function verifyInboundWebhook(deps: VerifyInboundDeps, input: VerifyInboundInput): Promise<VerifyOutcome>;
|
|
78
|
+
//# sourceMappingURL=verify-inbound.d.ts.map
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* In-memory execution tracker for worker nodes.
|
|
3
|
+
*
|
|
4
|
+
* Workers have no database access. This lightweight implementation
|
|
5
|
+
* satisfies the same interface subset that the dispatcher and processor
|
|
6
|
+
* call (onExecutionStarted, onJobStatus, onStepStatus, getRunStatus),
|
|
7
|
+
* allowing those subsystems to work unchanged on workers.
|
|
8
|
+
*
|
|
9
|
+
* Optionally forwards status updates via a callback for coordinator relay,
|
|
10
|
+
* and maintains a ring buffer of recently completed jobs for /status.
|
|
11
|
+
*/
|
|
12
|
+
import type { ObserverRegistry } from '../ws/observer-registry.js';
|
|
13
|
+
/** A status update forwarded to the coordinator. */
|
|
14
|
+
export interface StatusUpdate {
|
|
15
|
+
type: 'job' | 'step';
|
|
16
|
+
runId: string;
|
|
17
|
+
jobId: string;
|
|
18
|
+
status: string;
|
|
19
|
+
stepIndex?: number;
|
|
20
|
+
stepName?: string;
|
|
21
|
+
timestamp: number;
|
|
22
|
+
data?: Record<string, unknown>;
|
|
23
|
+
}
|
|
24
|
+
/** A completed job entry in the ring buffer. */
|
|
25
|
+
interface CompletedJobInfo {
|
|
26
|
+
runId: string;
|
|
27
|
+
jobId: string;
|
|
28
|
+
jobName: string;
|
|
29
|
+
status: string;
|
|
30
|
+
startedAt: number;
|
|
31
|
+
completedAt: number;
|
|
32
|
+
durationMs: number;
|
|
33
|
+
}
|
|
34
|
+
interface InMemoryExecutionTrackerOptions {
|
|
35
|
+
/** Callback to forward status updates to coordinator via P2P. */
|
|
36
|
+
onStatusForward?: (update: StatusUpdate) => void;
|
|
37
|
+
/** Maximum number of recent completed jobs to keep. Default: 50. */
|
|
38
|
+
recentJobsLimit?: number;
|
|
39
|
+
/** Optional observer registry for broadcasting to CLI observers. */
|
|
40
|
+
observerRegistry?: ObserverRegistry;
|
|
41
|
+
}
|
|
42
|
+
/** In-memory state for a single job within a run. */
|
|
43
|
+
interface JobState {
|
|
44
|
+
name: string;
|
|
45
|
+
status: string;
|
|
46
|
+
startedAt?: number;
|
|
47
|
+
completedAt?: number;
|
|
48
|
+
}
|
|
49
|
+
/** In-memory state for a single execution run. */
|
|
50
|
+
interface RunState {
|
|
51
|
+
workflowName: string;
|
|
52
|
+
provider: string;
|
|
53
|
+
repoIdentifier: string;
|
|
54
|
+
sha: string;
|
|
55
|
+
ref: string;
|
|
56
|
+
startedAt: number;
|
|
57
|
+
jobs: Map<string, JobState>;
|
|
58
|
+
}
|
|
59
|
+
export declare class InMemoryExecutionTracker {
|
|
60
|
+
private readonly onStatusForward?;
|
|
61
|
+
private readonly recentJobsLimit;
|
|
62
|
+
private readonly observerRegistry?;
|
|
63
|
+
private readonly runs;
|
|
64
|
+
private readonly recentJobs;
|
|
65
|
+
constructor(options: InMemoryExecutionTrackerOptions);
|
|
66
|
+
/**
|
|
67
|
+
* Record a new execution run with its initial jobs.
|
|
68
|
+
* Signature matches ExecutionTracker.onExecutionStarted (positional args).
|
|
69
|
+
*/
|
|
70
|
+
onExecutionStarted(runId: string, workflowName: string, provider: string, repoIdentifier: string, ref: string, sha: string, _deliveryId: string | null, _providerContext: Record<string, unknown>, _triggerDecision: Record<string, unknown> | null, jobs: Array<{
|
|
71
|
+
jobId: string;
|
|
72
|
+
jobName: string;
|
|
73
|
+
matrixValues?: Record<string, unknown>;
|
|
74
|
+
}>): Promise<void>;
|
|
75
|
+
/**
|
|
76
|
+
* Update job status. Forwards to coordinator callback if configured.
|
|
77
|
+
*/
|
|
78
|
+
onJobStatus(runId: string, jobId: string, status: string, timestamp: number, agentId?: string, data?: Record<string, unknown>): Promise<void>;
|
|
79
|
+
/**
|
|
80
|
+
* Update step status. Forwards to coordinator callback if configured.
|
|
81
|
+
*/
|
|
82
|
+
onStepStatus(runId: string, jobId: string, stepIndex: number, stepName: string, status: string, timestamp: number, data?: Record<string, unknown>): Promise<void>;
|
|
83
|
+
/**
|
|
84
|
+
* Get the current status of a run.
|
|
85
|
+
*/
|
|
86
|
+
getRunStatus(runId: string): RunState | null;
|
|
87
|
+
/**
|
|
88
|
+
* Get recent completed jobs (most recent first).
|
|
89
|
+
*/
|
|
90
|
+
getRecentJobs(): CompletedJobInfo[];
|
|
91
|
+
private addToRecentJobs;
|
|
92
|
+
}
|
|
93
|
+
export {};
|
|
94
|
+
//# sourceMappingURL=in-memory-execution-tracker.d.ts.map
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* In-memory job queue for worker nodes.
|
|
3
|
+
*
|
|
4
|
+
* Workers receive jobs directly from the coordinator via P2P dispatch,
|
|
5
|
+
* not from a database queue. This implementation satisfies the JobQueue
|
|
6
|
+
* interface with ephemeral in-memory storage, allowing the dispatcher
|
|
7
|
+
* subsystem to work unchanged on workers.
|
|
8
|
+
*
|
|
9
|
+
* Jobs enqueued here (when no agent is immediately available) are stored
|
|
10
|
+
* in memory and dequeued when an agent with matching labels connects.
|
|
11
|
+
*/
|
|
12
|
+
import { DispatchQueueStatus, type QueuedJobInput, type QueuedJob } from '../queue/job-queue.js';
|
|
13
|
+
export declare class InMemoryJobQueue {
|
|
14
|
+
private readonly jobs;
|
|
15
|
+
/** Enqueue a job in memory and return its ID. */
|
|
16
|
+
enqueue(input: QueuedJobInput): Promise<string>;
|
|
17
|
+
/**
|
|
18
|
+
* Returns a generated UUID for direct-dispatch tracking, or honors the
|
|
19
|
+
* caller's pre-allocated jobId when set (cluster reroute path).
|
|
20
|
+
*/
|
|
21
|
+
insertDispatched(input: QueuedJobInput): Promise<string>;
|
|
22
|
+
/**
|
|
23
|
+
* Dequeue the first pending job matching the given labels.
|
|
24
|
+
*
|
|
25
|
+
* `agentMandatoryLabels` mirrors the DB-backed `JobQueue.dequeueForLabels`
|
|
26
|
+
* gate: a job is only dequeued when its `runsOnLabels` includes every
|
|
27
|
+
* label in the gate set. Empty (default) is a no-op for static / non-scaler
|
|
28
|
+
* agents — the gate trivially passes.
|
|
29
|
+
*/
|
|
30
|
+
dequeueForLabels(agentLabels: string[], agentMandatoryLabels?: string[]): Promise<QueuedJob | null>;
|
|
31
|
+
/**
|
|
32
|
+
* Dequeue a specific pending job by id, validating that the agent's labels
|
|
33
|
+
* still satisfy the job's runsOn / excludeLabels and the agent's
|
|
34
|
+
* `mandatoryLabels` gate. Mirrors the DB-backed `JobQueue.dequeueById`
|
|
35
|
+
* used by `Dispatcher.dispatchBoundJob()` when a scaler-managed agent
|
|
36
|
+
* registers and the scaler had bound a queued jobId to that agent at
|
|
37
|
+
* spawn time. Returns null if the job is missing, no longer Pending,
|
|
38
|
+
* labels no longer match, or the agent's gate is not satisfied.
|
|
39
|
+
*/
|
|
40
|
+
dequeueById(jobId: string, agentLabels: string[], agentMandatoryLabels?: string[]): Promise<QueuedJob | null>;
|
|
41
|
+
/** Return count of pending jobs. */
|
|
42
|
+
getDepth(): Promise<number>;
|
|
43
|
+
/** No-op — workers don't track dispatch status in a queue. */
|
|
44
|
+
markDispatched(_jobId: string, _agentId: string): Promise<void>;
|
|
45
|
+
/** No-op. */
|
|
46
|
+
markFailed(_jobId: string, _reason: string): Promise<void>;
|
|
47
|
+
/** No-op. */
|
|
48
|
+
markCompleted(_jobId: string): Promise<void>;
|
|
49
|
+
/** No-op. */
|
|
50
|
+
markRecovering(_jobId: string): Promise<void>;
|
|
51
|
+
/** Return all pending jobs. */
|
|
52
|
+
getPendingJobs(): Promise<QueuedJob[]>;
|
|
53
|
+
/** Always returns empty array. */
|
|
54
|
+
getDispatchedJobIdsByRunId(_runId: string): Promise<string[]>;
|
|
55
|
+
/** Always returns null. */
|
|
56
|
+
getJobById(_jobId: string): Promise<{
|
|
57
|
+
id: string;
|
|
58
|
+
runId: string;
|
|
59
|
+
status: DispatchQueueStatus;
|
|
60
|
+
} | null>;
|
|
61
|
+
/** Always returns false. */
|
|
62
|
+
markFailedIfRecovering(_jobId: string, _reason: string): Promise<boolean>;
|
|
63
|
+
/** Always returns false. */
|
|
64
|
+
markDispatchedIfRecovering(_jobId: string): Promise<boolean>;
|
|
65
|
+
/** Always returns empty array. */
|
|
66
|
+
getJobsByStatus(_status: DispatchQueueStatus): Promise<Array<{
|
|
67
|
+
id: string;
|
|
68
|
+
runId: string;
|
|
69
|
+
status: DispatchQueueStatus;
|
|
70
|
+
}>>;
|
|
71
|
+
/** No-op — nothing to expire. */
|
|
72
|
+
markExpired(): Promise<number>;
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=in-memory-job-queue.d.ts.map
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* In-memory agent token store for worker nodes.
|
|
3
|
+
*
|
|
4
|
+
* Workers have no database access. This implementation stores token
|
|
5
|
+
* hashes in memory and supports both static (long-lived) and ephemeral
|
|
6
|
+
* (TTL-based) tokens with the same kat_ prefix format as the DB-backed
|
|
7
|
+
* AgentTokenStore.
|
|
8
|
+
*
|
|
9
|
+
* Token format: kat_ + 64 hex chars (32 random bytes = 256 bits).
|
|
10
|
+
* Only the SHA-256 hash is stored; plaintext is returned once at creation.
|
|
11
|
+
*/
|
|
12
|
+
/** Safe token info returned from validate (matches SafeAgentTokenRow shape). */
|
|
13
|
+
interface SafeTokenInfo {
|
|
14
|
+
id: string;
|
|
15
|
+
token_prefix: string;
|
|
16
|
+
labels: string | null;
|
|
17
|
+
agent_type: string;
|
|
18
|
+
created_by: string | null;
|
|
19
|
+
expires_at: Date | null;
|
|
20
|
+
revoked_at: null;
|
|
21
|
+
}
|
|
22
|
+
export declare class StaticAgentTokenStore {
|
|
23
|
+
private readonly tokens;
|
|
24
|
+
/**
|
|
25
|
+
* Create a static (long-lived) agent token.
|
|
26
|
+
*/
|
|
27
|
+
createStatic(opts: {
|
|
28
|
+
labels?: string[];
|
|
29
|
+
createdBy?: string;
|
|
30
|
+
}): Promise<{
|
|
31
|
+
token: string;
|
|
32
|
+
id: string;
|
|
33
|
+
}>;
|
|
34
|
+
/**
|
|
35
|
+
* Create an ephemeral (short-lived) agent token.
|
|
36
|
+
*/
|
|
37
|
+
createEphemeral(agentId: string, labels: string[], ttlMs: number): Promise<string>;
|
|
38
|
+
/**
|
|
39
|
+
* Validate a plaintext token.
|
|
40
|
+
*
|
|
41
|
+
* Returns token info if valid, null if unknown/revoked/expired.
|
|
42
|
+
*/
|
|
43
|
+
validate(token: string): Promise<SafeTokenInfo | null>;
|
|
44
|
+
/**
|
|
45
|
+
* Revoke a token by ID.
|
|
46
|
+
*
|
|
47
|
+
* @returns true if newly revoked, false if not found or already revoked.
|
|
48
|
+
*/
|
|
49
|
+
revoke(id: string): Promise<boolean>;
|
|
50
|
+
/**
|
|
51
|
+
* Clean up expired ephemeral tokens.
|
|
52
|
+
*
|
|
53
|
+
* @returns Number of removed tokens.
|
|
54
|
+
*/
|
|
55
|
+
cleanupExpired(): Promise<number>;
|
|
56
|
+
}
|
|
57
|
+
export {};
|
|
58
|
+
//# sourceMappingURL=static-agent-token-store.d.ts.map
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Worker /status and /drain HTTP endpoint handlers.
|
|
3
|
+
*
|
|
4
|
+
* - GET /status -- returns worker instance info, connection state, agents, active/recent jobs
|
|
5
|
+
* - POST /drain -- sets draining flag, returns active job count
|
|
6
|
+
*
|
|
7
|
+
* These are mounted on the worker's HTTP server in worker-core.ts.
|
|
8
|
+
*/
|
|
9
|
+
import type { IncomingMessage, ServerResponse } from 'node:http';
|
|
10
|
+
import type { InMemoryExecutionTracker } from './in-memory-execution-tracker.js';
|
|
11
|
+
import type { AgentRegistry } from '../agent/registry.js';
|
|
12
|
+
import type { PeerClient } from '../cluster/peer-client.js';
|
|
13
|
+
export interface WorkerStatusDeps {
|
|
14
|
+
instanceId: string;
|
|
15
|
+
executionTracker: InMemoryExecutionTracker;
|
|
16
|
+
agentRegistry: AgentRegistry;
|
|
17
|
+
peerClient: PeerClient;
|
|
18
|
+
startedAt: number;
|
|
19
|
+
getDraining: () => boolean;
|
|
20
|
+
setDraining: (v: boolean) => void;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Create a handler for GET /status.
|
|
24
|
+
*
|
|
25
|
+
* Returns worker instance info including role, coordinator connection state,
|
|
26
|
+
* draining flag, uptime, agent counts, active jobs, and recent job history.
|
|
27
|
+
*/
|
|
28
|
+
export declare function createWorkerStatusHandler(deps: WorkerStatusDeps): (_req: IncomingMessage, res: ServerResponse) => void;
|
|
29
|
+
/**
|
|
30
|
+
* Create a handler for POST /drain.
|
|
31
|
+
*
|
|
32
|
+
* Sets the draining flag to true and returns the current active job count.
|
|
33
|
+
* Idempotent -- calling multiple times has no additional effect.
|
|
34
|
+
*/
|
|
35
|
+
export declare function createWorkerDrainHandler(deps: WorkerStatusDeps): (_req: IncomingMessage, res: ServerResponse) => void;
|
|
36
|
+
//# sourceMappingURL=worker-status.d.ts.map
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Worker mode bootstrap for the orchestrator.
|
|
3
|
+
*
|
|
4
|
+
* Workers are orchestrators in 'worker' mode. They connect to a coordinator
|
|
5
|
+
* via PeerClient, receive rerouted jobs, dispatch them to local agents,
|
|
6
|
+
* and report progress back to the coordinator.
|
|
7
|
+
*
|
|
8
|
+
* Workers do NOT have:
|
|
9
|
+
* - Database access (no PG, no Kysely, no migrations)
|
|
10
|
+
* - Platform relay connection
|
|
11
|
+
* - Raft consensus
|
|
12
|
+
* - Secrets management (secrets arrive pre-resolved in job.reroute)
|
|
13
|
+
* - Webhook handling, dedup, event routing, trust store
|
|
14
|
+
* - Registration/source management
|
|
15
|
+
* - Cache infra (bundle/dep cache, build coordinator)
|
|
16
|
+
* - Concurrency tracking, ownership tracking
|
|
17
|
+
* - Config reloader
|
|
18
|
+
*
|
|
19
|
+
* Workers DO have:
|
|
20
|
+
* - ScalerManager (local scaler backends)
|
|
21
|
+
* - AgentRegistry (in-memory agent tracking)
|
|
22
|
+
* - Dispatcher (local agent dispatch)
|
|
23
|
+
* - PeerClient (coordinator connection)
|
|
24
|
+
* - PeerRegistry (coordinator tracking)
|
|
25
|
+
* - InMemoryExecutionTracker (local state with forwarding)
|
|
26
|
+
* - InMemoryJobQueue (no-op queue)
|
|
27
|
+
* - StaticAgentTokenStore (in-memory tokens)
|
|
28
|
+
* - StepLogBuffer (log chunk buffering)
|
|
29
|
+
* - ObserverRegistry (CLI observer support)
|
|
30
|
+
* - HTTP server with /health and agent WS endpoint
|
|
31
|
+
*/
|
|
32
|
+
import type { AppConfig } from './config.js';
|
|
33
|
+
import { AgentRegistry } from './agent/registry.js';
|
|
34
|
+
import { Dispatcher } from './agent/dispatcher.js';
|
|
35
|
+
import { PeerClient, PeerRegistry } from './cluster/index.js';
|
|
36
|
+
import { InMemoryExecutionTracker } from './worker/in-memory-execution-tracker.js';
|
|
37
|
+
import { InMemoryJobQueue } from './worker/in-memory-job-queue.js';
|
|
38
|
+
import { StaticAgentTokenStore } from './worker/static-agent-token-store.js';
|
|
39
|
+
import { StepLogBuffer } from './reporting/step-log-buffer.js';
|
|
40
|
+
import { ObserverRegistry } from './ws/observer-registry.js';
|
|
41
|
+
import { ScalerManager } from './scaler/index.js';
|
|
42
|
+
import type { ScalerConfig } from './scaler/index.js';
|
|
43
|
+
/**
|
|
44
|
+
* Subsystems available in worker mode.
|
|
45
|
+
* Subset of OrchestratorSubsystems with in-memory replacements.
|
|
46
|
+
*/
|
|
47
|
+
interface WorkerSubsystems {
|
|
48
|
+
config: AppConfig;
|
|
49
|
+
agentRegistry: AgentRegistry;
|
|
50
|
+
dispatcher: Dispatcher;
|
|
51
|
+
peerRegistry: PeerRegistry;
|
|
52
|
+
/** Outbound PeerClients keyed by coord URL. Workers fan out so every coord can dispatch directly. */
|
|
53
|
+
peerClients: Map<string, PeerClient>;
|
|
54
|
+
/** Convenience: first PeerClient (deterministic insertion order) for legacy single-client APIs. */
|
|
55
|
+
peerClient: PeerClient;
|
|
56
|
+
executionTracker: InMemoryExecutionTracker;
|
|
57
|
+
jobQueue: InMemoryJobQueue;
|
|
58
|
+
tokenStore: StaticAgentTokenStore;
|
|
59
|
+
stepLogBuffer: StepLogBuffer;
|
|
60
|
+
observerRegistry: ObserverRegistry;
|
|
61
|
+
scalerManager: ScalerManager | null;
|
|
62
|
+
scalerConfig: ScalerConfig | null;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Bootstrap the orchestrator in worker mode.
|
|
66
|
+
*
|
|
67
|
+
* Initializes only worker-relevant subsystems, connects to the coordinator
|
|
68
|
+
* via PeerClient, and starts an HTTP server with agent WS and health endpoints.
|
|
69
|
+
*/
|
|
70
|
+
export declare function bootstrapWorker(config: AppConfig, _opts?: {
|
|
71
|
+
otelSdk?: unknown;
|
|
72
|
+
}): Promise<WorkerSubsystems>;
|
|
73
|
+
export {};
|
|
74
|
+
//# sourceMappingURL=worker-core.d.ts.map
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent private API registry.
|
|
3
|
+
*
|
|
4
|
+
* Provides a typed, extensible request-response API over the existing agent WS
|
|
5
|
+
* connection. Each method is registered with a role (read/write) for authorization.
|
|
6
|
+
*
|
|
7
|
+
* Adding a new API method:
|
|
8
|
+
* 1. Add the typed method + return type in @kici-dev/sdk (api-types.ts)
|
|
9
|
+
* 2. Call registry.register('namespace.method', 'read', handler) here
|
|
10
|
+
*
|
|
11
|
+
* The agent sends { type: 'agent.api.request', method, params } and receives
|
|
12
|
+
* { type: 'agent.api.response', result?, error? } back.
|
|
13
|
+
*/
|
|
14
|
+
/** Authorization roles for API methods. */
|
|
15
|
+
export type ApiRole = 'read' | 'write';
|
|
16
|
+
/** Handler function for an API method. */
|
|
17
|
+
export type ApiHandler = (agentId: string, params: Record<string, unknown>) => Promise<unknown>;
|
|
18
|
+
/**
|
|
19
|
+
* Registry for agent private API methods.
|
|
20
|
+
*
|
|
21
|
+
* Methods are dot-namespaced (e.g., 'infrastructure.list') and each has an
|
|
22
|
+
* associated role. The orchestrator checks the caller's allowed roles before
|
|
23
|
+
* invoking the handler.
|
|
24
|
+
*/
|
|
25
|
+
export declare class AgentApiRegistry {
|
|
26
|
+
private readonly methods;
|
|
27
|
+
/**
|
|
28
|
+
* Register an API method.
|
|
29
|
+
*
|
|
30
|
+
* @param method - Dot-namespaced method name (e.g., 'infrastructure.list')
|
|
31
|
+
* @param role - Required role to call this method
|
|
32
|
+
* @param handler - Async handler that receives agentId and params, returns result
|
|
33
|
+
*/
|
|
34
|
+
register(method: string, role: ApiRole, handler: ApiHandler): void;
|
|
35
|
+
/**
|
|
36
|
+
* Handle an API request.
|
|
37
|
+
*
|
|
38
|
+
* @param agentId - The calling agent's ID
|
|
39
|
+
* @param method - Requested method name
|
|
40
|
+
* @param params - Method parameters
|
|
41
|
+
* @param allowedRoles - Roles the caller is authorized for
|
|
42
|
+
* @returns The method's result
|
|
43
|
+
* @throws Error if method not found or role not authorized
|
|
44
|
+
*/
|
|
45
|
+
handle(agentId: string, method: string, params: Record<string, unknown>, allowedRoles: ApiRole[]): Promise<unknown>;
|
|
46
|
+
/** Get all registered method names (for diagnostics). */
|
|
47
|
+
getMethods(): string[];
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=agent-api-registry.d.ts.map
|