@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,176 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WebSocket handler for agent connections.
|
|
3
|
+
*
|
|
4
|
+
* Agents connect to the orchestrator via WebSocket to:
|
|
5
|
+
* - Authenticate with a kat_ token (when agentAuthMode === 'token')
|
|
6
|
+
* - Register their capabilities (labels, concurrency)
|
|
7
|
+
* - Receive job dispatches
|
|
8
|
+
* - Report job execution status
|
|
9
|
+
* - Send periodic heartbeats
|
|
10
|
+
*
|
|
11
|
+
* Two-phase auth flow (when agentAuthMode === 'token'):
|
|
12
|
+
* 1. pendingAuth (5s): Agent must send auth.request with a valid kat_ token.
|
|
13
|
+
* 2. pendingRegistration (10s): After auth.success, agent must send agent.register.
|
|
14
|
+
* 3. registered: Agent is fully connected and can exchange messages.
|
|
15
|
+
*
|
|
16
|
+
* When agentAuthMode === 'none', the auth phase is skipped (legacy behavior).
|
|
17
|
+
*/
|
|
18
|
+
import type { WSEvents } from 'hono/ws';
|
|
19
|
+
import type { RateLimiterConfig } from '@kici-dev/engine';
|
|
20
|
+
import type { AgentRegistry } from '../agent/registry.js';
|
|
21
|
+
import type { Dispatcher } from '../agent/dispatcher.js';
|
|
22
|
+
import type { AgentTokenStore } from '../agent/token-store.js';
|
|
23
|
+
import type { OwnershipTracker } from '../agent/ownership-tracker.js';
|
|
24
|
+
import type { SourceCache } from '../cache/source-cache.js';
|
|
25
|
+
import type { DepCache } from '../cache/dep-cache.js';
|
|
26
|
+
import type { PendingBuildTracker } from '../cache/pending-builds.js';
|
|
27
|
+
import type { PendingInitTracker } from '../cache/pending-inits.js';
|
|
28
|
+
import type { PendingDynamicTracker } from '../cache/pending-dynamics.js';
|
|
29
|
+
import type { CacheStorage } from '../storage/types.js';
|
|
30
|
+
import type { AgentMetricsAggregator } from '../metrics/agent-metrics-aggregator.js';
|
|
31
|
+
import type { AgentApiRegistry } from './agent-api-registry.js';
|
|
32
|
+
export interface AgentWsHandlerDeps {
|
|
33
|
+
registry: AgentRegistry;
|
|
34
|
+
dispatcher: Dispatcher;
|
|
35
|
+
/** Token store for validating agent auth tokens. Undefined when auth disabled. */
|
|
36
|
+
tokenStore?: AgentTokenStore;
|
|
37
|
+
/** Agent authentication mode. 'token' requires auth.request before register. */
|
|
38
|
+
agentAuthMode: 'token' | 'none';
|
|
39
|
+
/** Optional callback to forward job status to the Platform client. */
|
|
40
|
+
onJobStatus?: (agentId: string, msg: {
|
|
41
|
+
runId: string;
|
|
42
|
+
jobId: string;
|
|
43
|
+
state: string;
|
|
44
|
+
timestamp: number;
|
|
45
|
+
data?: Record<string, unknown>;
|
|
46
|
+
}) => void;
|
|
47
|
+
/** Optional callback when agent sends log chunks. */
|
|
48
|
+
onLogChunk?: (agentId: string, msg: {
|
|
49
|
+
runId: string;
|
|
50
|
+
jobId: string;
|
|
51
|
+
stepIndex: number;
|
|
52
|
+
lines: string[];
|
|
53
|
+
timestamp: number;
|
|
54
|
+
}) => void;
|
|
55
|
+
/** Optional callback when agent sends step status updates. */
|
|
56
|
+
onStepStatus?: (agentId: string, msg: {
|
|
57
|
+
runId: string;
|
|
58
|
+
jobId: string;
|
|
59
|
+
stepIndex: number;
|
|
60
|
+
stepName: string;
|
|
61
|
+
state: string;
|
|
62
|
+
timestamp: number;
|
|
63
|
+
data?: Record<string, unknown>;
|
|
64
|
+
secretsAccessed?: string[];
|
|
65
|
+
/** Raw log bytes accumulated by this step's LogStreamer at terminal time. */
|
|
66
|
+
logBytesStreamed?: number;
|
|
67
|
+
}) => void;
|
|
68
|
+
/**
|
|
69
|
+
* Optional callback when a scaler-managed agent registers.
|
|
70
|
+
*
|
|
71
|
+
* Returns:
|
|
72
|
+
* - `boundJobId` (optional): set when the scaler bound a specific queued
|
|
73
|
+
* job to this agent at spawn time. The orchestrator eagerly dispatches
|
|
74
|
+
* that job before the agent's idle timer fires.
|
|
75
|
+
* - `mandatoryLabels` (always populated for scaler-managed agents): the
|
|
76
|
+
* spawning scaler's Kubernetes-taint-style gate. Threaded into the
|
|
77
|
+
* AgentRegistry so subsequent label matches (queue drain + eager
|
|
78
|
+
* dispatch) apply the same gate the scaler-side selector applied.
|
|
79
|
+
*
|
|
80
|
+
* Returns `null` for static agents not managed by any scaler.
|
|
81
|
+
*/
|
|
82
|
+
onScalerAgentRegistered?: (agentId: string, labels: string[]) => {
|
|
83
|
+
boundJobId?: string;
|
|
84
|
+
mandatoryLabels: string[];
|
|
85
|
+
} | null;
|
|
86
|
+
/** Optional callback when an agent disconnects (for scaler lifecycle). */
|
|
87
|
+
onScalerAgentDisconnected?: (agentId: string) => void;
|
|
88
|
+
/** Optional callback when an agent completes a job (for scaler lifecycle). */
|
|
89
|
+
onScalerJobComplete?: (agentId: string) => void;
|
|
90
|
+
/** Optional callback when agent sends per-job heartbeats. */
|
|
91
|
+
onJobHeartbeat?: (agentId: string, msg: {
|
|
92
|
+
runId: string;
|
|
93
|
+
jobId: string;
|
|
94
|
+
timestamp: number;
|
|
95
|
+
}) => void;
|
|
96
|
+
/** Optional callback when agent sends operational log lines (stateful/external agents via WS). */
|
|
97
|
+
onAgentLog?: (agentId: string, msg: {
|
|
98
|
+
lines: string[];
|
|
99
|
+
timestamp: number;
|
|
100
|
+
}) => void;
|
|
101
|
+
/** Optional callback when agent acknowledges config (for MMDS clearing in Firecracker). */
|
|
102
|
+
onConfigAck?: (agentId: string) => void;
|
|
103
|
+
/** Optional callback when agent emits a custom event via ctx.emit(). */
|
|
104
|
+
onEventEmit?: (agentId: string, msg: {
|
|
105
|
+
jobId: string;
|
|
106
|
+
requestId: string;
|
|
107
|
+
eventName: string;
|
|
108
|
+
payload: Record<string, unknown>;
|
|
109
|
+
target?: {
|
|
110
|
+
repos?: string[];
|
|
111
|
+
};
|
|
112
|
+
}) => Promise<{
|
|
113
|
+
deliveryId?: string;
|
|
114
|
+
error?: string;
|
|
115
|
+
}>;
|
|
116
|
+
/** Optional callback when agent sends a run.event for infrastructure lifecycle tracking. */
|
|
117
|
+
onRunEvent?: (agentId: string, msg: {
|
|
118
|
+
runId: string;
|
|
119
|
+
eventType: string;
|
|
120
|
+
timestampMs: number;
|
|
121
|
+
sourceService: string;
|
|
122
|
+
jobId?: string | null;
|
|
123
|
+
metadata?: Record<string, unknown>;
|
|
124
|
+
durationMs?: number | null;
|
|
125
|
+
}) => void;
|
|
126
|
+
/** Optional callback when agent sends a job.context with execution environment details. */
|
|
127
|
+
onJobContext?: (agentId: string, msg: {
|
|
128
|
+
runId: string;
|
|
129
|
+
jobId: string;
|
|
130
|
+
context: Record<string, unknown>;
|
|
131
|
+
}) => void;
|
|
132
|
+
/** Bundle cache for generating pre-signed upload URLs. */
|
|
133
|
+
sourceCache?: SourceCache;
|
|
134
|
+
/** Dep cache for generating pre-signed upload URLs. */
|
|
135
|
+
depCache?: DepCache;
|
|
136
|
+
/** Cache storage for setting metadata after upload completion. */
|
|
137
|
+
cacheStorage?: CacheStorage;
|
|
138
|
+
/** Optional rate limiter configuration. */
|
|
139
|
+
rateLimiterConfig?: RateLimiterConfig;
|
|
140
|
+
/** Optional ownership tracker for validating job-related messages. */
|
|
141
|
+
ownershipTracker?: OwnershipTracker;
|
|
142
|
+
/** Optional pending build tracker for cleanup on agent disconnect. */
|
|
143
|
+
pendingBuilds?: PendingBuildTracker;
|
|
144
|
+
/** Optional pending init tracker for cleanup on agent disconnect. */
|
|
145
|
+
pendingInits?: PendingInitTracker;
|
|
146
|
+
/** Optional pending dynamic tracker for cleanup on agent disconnect. */
|
|
147
|
+
pendingDynamics?: PendingDynamicTracker;
|
|
148
|
+
/** Optional callback when agent sends encrypted secret outputs on job success. */
|
|
149
|
+
onSecretOutputs?: (runId: string, jobId: string, secretOutputs: Record<string, {
|
|
150
|
+
agentPublicKey: string;
|
|
151
|
+
encrypted: string;
|
|
152
|
+
}>) => Promise<void>;
|
|
153
|
+
/** Agent metrics aggregator for receiving pushed metrics. */
|
|
154
|
+
agentMetricsAggregator?: AgentMetricsAggregator;
|
|
155
|
+
/** Optional callback when agent reports a job belongs to a concurrency group. */
|
|
156
|
+
onConcurrencyReport?: (agentId: string, msg: {
|
|
157
|
+
runId: string;
|
|
158
|
+
jobId: string;
|
|
159
|
+
group: string;
|
|
160
|
+
messageId: string;
|
|
161
|
+
}) => Promise<{
|
|
162
|
+
action: 'proceed' | 'wait' | 'cancel';
|
|
163
|
+
reason?: string;
|
|
164
|
+
}>;
|
|
165
|
+
/**
|
|
166
|
+
* Optional callback fired when an agent's WS connection closes, after the
|
|
167
|
+
* dispatcher's own cleanup has run. Used by the long-poll concurrency
|
|
168
|
+
* pipeline to drop the agent's queued waiters and `cancelQueued` the
|
|
169
|
+
* matching DB rows so the run is marked failed instead of dangling.
|
|
170
|
+
*/
|
|
171
|
+
onConcurrencyAgentDisconnect?: (agentId: string) => void | Promise<void>;
|
|
172
|
+
/** Agent private API registry for handling agent.api.request messages. */
|
|
173
|
+
agentApiRegistry?: AgentApiRegistry;
|
|
174
|
+
}
|
|
175
|
+
export declare function createAgentWsHandler(deps: AgentWsHandlerDeps): WSEvents;
|
|
176
|
+
//# sourceMappingURL=agent-handler.d.ts.map
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Heartbeat monitor for agent WebSocket connections.
|
|
3
|
+
*
|
|
4
|
+
* Periodically inspects all registered agents and:
|
|
5
|
+
* - Logs warnings for agents past the unhealthy threshold (90s).
|
|
6
|
+
* - Forcibly disconnects agents past the disconnect threshold (180s).
|
|
7
|
+
*
|
|
8
|
+
* Follows the same pattern as the Platform HeartbeatMonitor
|
|
9
|
+
* (packages/platform/src/ws/heartbeat.ts) for consistency across
|
|
10
|
+
* the three-tier architecture.
|
|
11
|
+
*/
|
|
12
|
+
import type { AgentRegistry } from '../agent/registry.js';
|
|
13
|
+
import type { Dispatcher } from '../agent/dispatcher.js';
|
|
14
|
+
interface AgentHeartbeatMonitorDeps {
|
|
15
|
+
registry: AgentRegistry;
|
|
16
|
+
dispatcher: Dispatcher;
|
|
17
|
+
/** Silence duration after which an agent is considered unhealthy (default 90s). */
|
|
18
|
+
unhealthyThresholdMs?: number;
|
|
19
|
+
/** Silence duration after which an agent is forcibly disconnected (default 180s). */
|
|
20
|
+
disconnectThresholdMs?: number;
|
|
21
|
+
/** How often to run the heartbeat check (default 30s). */
|
|
22
|
+
checkIntervalMs?: number;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Periodically inspects all registered agent connections and:
|
|
26
|
+
* - Marks agents as unhealthy after 90s of silence (log only).
|
|
27
|
+
* - Closes and unregisters agents after 180s of silence.
|
|
28
|
+
* - Triggers dispatcher.onAgentDisconnect for stale agents.
|
|
29
|
+
*/
|
|
30
|
+
export declare class AgentHeartbeatMonitor {
|
|
31
|
+
private readonly registry;
|
|
32
|
+
private readonly dispatcher;
|
|
33
|
+
private readonly unhealthyThresholdMs;
|
|
34
|
+
private readonly disconnectThresholdMs;
|
|
35
|
+
private readonly checkIntervalMs;
|
|
36
|
+
private interval;
|
|
37
|
+
constructor(deps: AgentHeartbeatMonitorDeps);
|
|
38
|
+
/** Start the periodic heartbeat check. */
|
|
39
|
+
start(): void;
|
|
40
|
+
/** Stop the periodic heartbeat check. */
|
|
41
|
+
stop(): void;
|
|
42
|
+
private check;
|
|
43
|
+
}
|
|
44
|
+
export {};
|
|
45
|
+
//# sourceMappingURL=agent-heartbeat.d.ts.map
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { BackendSyncManager, DashboardPlatformToOrchMessage } from '@kici-dev/engine';
|
|
2
|
+
import type { BackendRegistry } from '../secrets/backend-registry.js';
|
|
3
|
+
import type { BackendHealthChecker } from '../secrets/backend-health.js';
|
|
4
|
+
import type { AccessLogWriter } from '../audit/access-log.js';
|
|
5
|
+
interface DashboardBackendsHandlerDeps {
|
|
6
|
+
/** Send a response message back to Platform over the WS connection. */
|
|
7
|
+
send: (msg: unknown) => void;
|
|
8
|
+
registry: BackendRegistry;
|
|
9
|
+
healthChecker: BackendHealthChecker;
|
|
10
|
+
syncManager?: BackendSyncManager;
|
|
11
|
+
/** Access log writer — records one row per read / mutation with actor attribution. */
|
|
12
|
+
accessLog?: AccessLogWriter;
|
|
13
|
+
/** Org ID for access_log rows (null when the orchestrator isn't org-scoped). */
|
|
14
|
+
orgId?: string | null;
|
|
15
|
+
/** Routing key for access_log rows (null when not run-scoped). */
|
|
16
|
+
routingKey?: string | null;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Handler for all dashboard backend WS messages.
|
|
20
|
+
*
|
|
21
|
+
* Dispatches incoming messages by type and calls the appropriate backend services.
|
|
22
|
+
*/
|
|
23
|
+
export declare class DashboardBackendsHandler {
|
|
24
|
+
private readonly deps;
|
|
25
|
+
private orgId;
|
|
26
|
+
private routingKey;
|
|
27
|
+
private readonly accessLog;
|
|
28
|
+
constructor(deps: DashboardBackendsHandlerDeps);
|
|
29
|
+
/**
|
|
30
|
+
* Update the bound orgId + routingKey. Called from server.ts after resolving
|
|
31
|
+
* the single tenant org from the `sources` / `generic_webhook_sources` table.
|
|
32
|
+
*/
|
|
33
|
+
setOrgContext(orgId: string | null, routingKey: string | null): void;
|
|
34
|
+
/**
|
|
35
|
+
* Write an access_log row for a handler invocation. Best-effort; the writer
|
|
36
|
+
* swallows failures.
|
|
37
|
+
*/
|
|
38
|
+
private recordAccess;
|
|
39
|
+
/**
|
|
40
|
+
* Route a dashboard backends message to the appropriate handler.
|
|
41
|
+
* Returns true if the message was handled, false otherwise.
|
|
42
|
+
*/
|
|
43
|
+
handleMessage(msg: DashboardPlatformToOrchMessage): Promise<boolean>;
|
|
44
|
+
private handleList;
|
|
45
|
+
private handleGet;
|
|
46
|
+
private handleSyncAll;
|
|
47
|
+
private handleSyncOne;
|
|
48
|
+
private handleTest;
|
|
49
|
+
}
|
|
50
|
+
export {};
|
|
51
|
+
//# sourceMappingURL=dashboard-backends-handler.d.ts.map
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Handles dashboard.diagnostics requests from Platform.
|
|
3
|
+
*
|
|
4
|
+
* Reads the AgentRegistry for connected agent info, extracts orchestrator
|
|
5
|
+
* metadata from config, and computes label gap information from the job queue.
|
|
6
|
+
*
|
|
7
|
+
* Returns a response matching dashboardDiagnosticsResponseSchema.
|
|
8
|
+
*/
|
|
9
|
+
import type { AgentRegistry } from '../agent/registry.js';
|
|
10
|
+
import type { AppConfig } from '../config.js';
|
|
11
|
+
import type { ScalerManager } from '../scaler/manager.js';
|
|
12
|
+
import type { ScalerConfig, ScalerEntry } from '../scaler/types.js';
|
|
13
|
+
import type { DashboardDiagnosticsResponse, DashboardScalerCapacityResponse, DashboardScalerAgentsResponse } from '@kici-dev/engine';
|
|
14
|
+
import type { PeerRegistry } from '../cluster/peer-registry.js';
|
|
15
|
+
import type { RaftNode } from '../cluster/raft.js';
|
|
16
|
+
export interface DiagnosticsHandlerDeps {
|
|
17
|
+
agentRegistry: AgentRegistry;
|
|
18
|
+
config: AppConfig;
|
|
19
|
+
/** Orchestrator version string (e.g. "0.0.1"). */
|
|
20
|
+
version: string;
|
|
21
|
+
/** Unique scaler backend types (e.g. ["container", "firecracker"]). */
|
|
22
|
+
scalerBackends: string[];
|
|
23
|
+
/** Optional job queue for queued job count. */
|
|
24
|
+
jobQueue?: {
|
|
25
|
+
getDepth(): Promise<number>;
|
|
26
|
+
};
|
|
27
|
+
/** Optional scaler manager for agent-to-scaler mapping. */
|
|
28
|
+
scalerManager?: ScalerManager | null;
|
|
29
|
+
/** Optional scaler config for scaler details. */
|
|
30
|
+
scalerConfig?: ScalerConfig | null;
|
|
31
|
+
/** Optional peer registry for cluster coordinator mode. */
|
|
32
|
+
peerRegistry?: PeerRegistry | null;
|
|
33
|
+
/** Optional Raft node for cluster election state. */
|
|
34
|
+
raftNode?: RaftNode | null;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Build a safe config subset for a scaler entry (no secrets like socketPath, uid, gid, etc).
|
|
38
|
+
* Uses an explicit allowlist to prevent accidental secret leaks.
|
|
39
|
+
*/
|
|
40
|
+
export declare function buildSafeScalerConfig(entry: ScalerEntry): Record<string, unknown>;
|
|
41
|
+
/**
|
|
42
|
+
* Build a diagnostics response for the given request.
|
|
43
|
+
* When includeAgents is false (default), agents[] is empty and aggregate fields are populated.
|
|
44
|
+
*/
|
|
45
|
+
export declare function handleDiagnosticsRequest(deps: DiagnosticsHandlerDeps, requestId: string, includeAgents?: boolean): Promise<DashboardDiagnosticsResponse>;
|
|
46
|
+
/**
|
|
47
|
+
* Build a per-scaler capacity response for the given request.
|
|
48
|
+
* Reads ScalerManager status to get active/max counts per backend.
|
|
49
|
+
*/
|
|
50
|
+
export declare function handleScalerCapacityRequest(scalerManager: ScalerManager | null, requestId: string): DashboardScalerCapacityResponse;
|
|
51
|
+
/**
|
|
52
|
+
* Build a per-scaler agents response for the given request.
|
|
53
|
+
* When scalerName is null, returns agents not bound to any scaler (stateful agents).
|
|
54
|
+
*/
|
|
55
|
+
export declare function handleScalerAgentsRequest(deps: DiagnosticsHandlerDeps, requestId: string, scalerName: string | null): DashboardScalerAgentsResponse;
|
|
56
|
+
//# sourceMappingURL=dashboard-diagnostics-handler.d.ts.map
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dashboard environment handler for the orchestrator.
|
|
3
|
+
*
|
|
4
|
+
* Responds to dashboard.environments.* and dashboard.held-runs.* WS messages
|
|
5
|
+
* from Platform by calling the appropriate stores (EnvironmentStore, VariableStore,
|
|
6
|
+
* BindingStore, PgSecretStore) and sending typed responses.
|
|
7
|
+
*
|
|
8
|
+
* Each handler:
|
|
9
|
+
* 1. Extracts orgId from the dependency context
|
|
10
|
+
* 2. Calls the appropriate store method
|
|
11
|
+
* 3. Returns a response message with requestId and data (or error)
|
|
12
|
+
*/
|
|
13
|
+
import { type Kysely } from 'kysely';
|
|
14
|
+
import type { DashboardPlatformToOrchMessage } from '@kici-dev/engine';
|
|
15
|
+
import type { EnvironmentStore } from '../environments/environment-store.js';
|
|
16
|
+
import type { VariableStore } from '../environments/variable-store.js';
|
|
17
|
+
import type { BindingStore } from '../environments/binding-store.js';
|
|
18
|
+
import type { Database } from '../db/types.js';
|
|
19
|
+
import type { AccessLogWriter } from '../audit/access-log.js';
|
|
20
|
+
/** Secret store interface (subset of PgSecretStore methods used here). */
|
|
21
|
+
interface SecretStoreForDashboard {
|
|
22
|
+
listScopes(orgId: string): Promise<string[]>;
|
|
23
|
+
listKeys(orgId: string, scope: string): Promise<string[]>;
|
|
24
|
+
setSecret(orgId: string, scope: string, key: string, value: string): Promise<void>;
|
|
25
|
+
deleteSecret(orgId: string, scope: string, key: string): Promise<void>;
|
|
26
|
+
createScope?(orgId: string, scope: string): Promise<void>;
|
|
27
|
+
renameScope?(orgId: string, oldScope: string, newScope: string): Promise<void>;
|
|
28
|
+
deleteScope?(orgId: string, scope: string): Promise<void>;
|
|
29
|
+
}
|
|
30
|
+
export interface DashboardEnvHandlerDeps {
|
|
31
|
+
/** Organization ID for all operations. */
|
|
32
|
+
orgId: string;
|
|
33
|
+
/** Send a response message back to Platform over the WS connection. */
|
|
34
|
+
send: (msg: unknown) => void;
|
|
35
|
+
environmentStore: EnvironmentStore;
|
|
36
|
+
variableStore: VariableStore;
|
|
37
|
+
bindingStore: BindingStore;
|
|
38
|
+
secretStore: SecretStoreForDashboard;
|
|
39
|
+
/** Load fresh backend stores from registry (creates new store instances with current credentials). */
|
|
40
|
+
loadBackendStores?: () => Promise<Map<string, SecretStoreForDashboard>>;
|
|
41
|
+
/** Database for held_runs queries. */
|
|
42
|
+
db: Kysely<Database>;
|
|
43
|
+
/** Access log writer — records one row per read / mutation with actor attribution. */
|
|
44
|
+
accessLog?: AccessLogWriter;
|
|
45
|
+
/** Routing key for access_log rows (null when not run-scoped). */
|
|
46
|
+
routingKey?: string | null;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Handler for all dashboard environment and held run WS messages.
|
|
50
|
+
*
|
|
51
|
+
* Dispatches incoming messages by type and calls the appropriate store.
|
|
52
|
+
*/
|
|
53
|
+
export declare class DashboardEnvHandler {
|
|
54
|
+
private readonly deps;
|
|
55
|
+
private routingKey;
|
|
56
|
+
private readonly accessLog;
|
|
57
|
+
constructor(deps: DashboardEnvHandlerDeps);
|
|
58
|
+
/** Update the orgId used for all operations (called when resolved from DB). */
|
|
59
|
+
setOrgId(orgId: string): void;
|
|
60
|
+
/** Update the routing key bound to access_log rows. */
|
|
61
|
+
setRoutingKey(routingKey: string | null): void;
|
|
62
|
+
/**
|
|
63
|
+
* Write an access_log row for a handler invocation. Uses the handler's
|
|
64
|
+
* bound orgId + routingKey, the msg.actor principal, and the handler-
|
|
65
|
+
* specified action + target. Best-effort; the writer swallows failures.
|
|
66
|
+
*/
|
|
67
|
+
private recordAccess;
|
|
68
|
+
/**
|
|
69
|
+
* Route a dashboard message to the appropriate handler.
|
|
70
|
+
* Returns true if the message was handled, false otherwise.
|
|
71
|
+
*/
|
|
72
|
+
handleMessage(msg: DashboardPlatformToOrchMessage): Promise<boolean>;
|
|
73
|
+
private handleEnvList;
|
|
74
|
+
private handleEnvGet;
|
|
75
|
+
private handleEnvCreate;
|
|
76
|
+
private handleEnvUpdate;
|
|
77
|
+
private handleEnvDelete;
|
|
78
|
+
private handleVarsList;
|
|
79
|
+
private handleVarSet;
|
|
80
|
+
private handleVarDelete;
|
|
81
|
+
private handleSourceOverridesList;
|
|
82
|
+
private handleSourceOverrideSet;
|
|
83
|
+
private handleSourceOverrideDelete;
|
|
84
|
+
private handleBindingsList;
|
|
85
|
+
private handleBindingsSet;
|
|
86
|
+
/** Load fresh backend stores, falling back to single secretStore wrapped in a Map. */
|
|
87
|
+
private getBackendStores;
|
|
88
|
+
/**
|
|
89
|
+
* Resolve the correct backend store for a prefixed scope (e.g., 'vault:aws/prod').
|
|
90
|
+
* Returns the store and the scope to pass to it.
|
|
91
|
+
* All stores expect unprefixed scopes — the backend prefix is stripped.
|
|
92
|
+
*/
|
|
93
|
+
private resolveStoreForScope;
|
|
94
|
+
private handleSecretsList;
|
|
95
|
+
private handleSecretSet;
|
|
96
|
+
private handleSecretDelete;
|
|
97
|
+
private handleScopeCreate;
|
|
98
|
+
private handleScopeRename;
|
|
99
|
+
private handleScopeDelete;
|
|
100
|
+
private handleEnvHistory;
|
|
101
|
+
private handleHeldRunsList;
|
|
102
|
+
private handleHeldRunApprove;
|
|
103
|
+
private handleHeldRunReject;
|
|
104
|
+
private sendError;
|
|
105
|
+
}
|
|
106
|
+
export {};
|
|
107
|
+
//# sourceMappingURL=dashboard-env-handler.d.ts.map
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dashboard global-workflows handler for the orchestrator.
|
|
3
|
+
*
|
|
4
|
+
* Responds to `dashboard.global-workflows.*` WS messages from Platform by
|
|
5
|
+
* reading or upserting the `org_settings` row keyed by `customer_id`. The
|
|
6
|
+
* row holds the org-level global-workflow policy: master enable, plus the
|
|
7
|
+
* three repo-pattern lists (allow / deny / elevate). Each list entry is a
|
|
8
|
+
* `{routingKey?, pattern}` object that may optionally pin to one source.
|
|
9
|
+
*
|
|
10
|
+
* The handler binds a single `customerId` at construction time (via the
|
|
11
|
+
* sources / generic_webhook_sources lookup at server startup) and updates
|
|
12
|
+
* via setOrgId() when a real customer source registers.
|
|
13
|
+
*/
|
|
14
|
+
import { type Kysely } from 'kysely';
|
|
15
|
+
import type { GlobalWorkflowsGetRequest, GlobalWorkflowsUpdateRequest, GlobalWorkflowSettings, RepoPatternEntry } from '@kici-dev/engine/protocol/dashboard-global-workflows';
|
|
16
|
+
import type { Database, OrgSettings } from '../db/types.js';
|
|
17
|
+
import type { AccessLogWriter } from '../audit/access-log.js';
|
|
18
|
+
interface DashboardGlobalWorkflowsHandlerDeps {
|
|
19
|
+
/** Customer / org identifier — primary key on org_settings. */
|
|
20
|
+
customerId: string;
|
|
21
|
+
/** Send a response message back to Platform over the WS connection. */
|
|
22
|
+
send: (msg: unknown) => void;
|
|
23
|
+
db: Kysely<Database>;
|
|
24
|
+
/** Access log writer — records one row per read / mutation with actor attribution. */
|
|
25
|
+
accessLog?: AccessLogWriter;
|
|
26
|
+
}
|
|
27
|
+
type GlobalWorkflowsMessage = GlobalWorkflowsGetRequest | GlobalWorkflowsUpdateRequest;
|
|
28
|
+
/**
|
|
29
|
+
* Returns true when the message is one this handler can dispatch. Used by the
|
|
30
|
+
* server to route incoming WS messages.
|
|
31
|
+
*/
|
|
32
|
+
export declare function isDashboardGlobalWorkflowsMessage(msg: {
|
|
33
|
+
type: string;
|
|
34
|
+
} | null | undefined): msg is GlobalWorkflowsMessage;
|
|
35
|
+
export declare class DashboardGlobalWorkflowsHandler {
|
|
36
|
+
private readonly deps;
|
|
37
|
+
private readonly accessLog;
|
|
38
|
+
constructor(deps: DashboardGlobalWorkflowsHandlerDeps);
|
|
39
|
+
/** Update the customer / org id this handler operates on. */
|
|
40
|
+
setOrgId(customerId: string | null): void;
|
|
41
|
+
/**
|
|
42
|
+
* Write an access_log row for a handler invocation. Best-effort; the writer
|
|
43
|
+
* swallows failures.
|
|
44
|
+
*/
|
|
45
|
+
private recordAccess;
|
|
46
|
+
handleMessage(msg: GlobalWorkflowsMessage): Promise<boolean>;
|
|
47
|
+
private handleGet;
|
|
48
|
+
private handleUpdate;
|
|
49
|
+
private readRow;
|
|
50
|
+
private upsertRow;
|
|
51
|
+
private sendError;
|
|
52
|
+
}
|
|
53
|
+
interface NormalizedPatch {
|
|
54
|
+
enabled: boolean;
|
|
55
|
+
allowedRepos: RepoPatternEntry[] | null;
|
|
56
|
+
deniedRepos: RepoPatternEntry[] | null;
|
|
57
|
+
elevatedRepos: RepoPatternEntry[] | null;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Derive the effective storage state from an existing row (may be undefined)
|
|
61
|
+
* plus a partial update message. Unset fields fall back to the existing value;
|
|
62
|
+
* an explicit `null` clears the corresponding column.
|
|
63
|
+
*/
|
|
64
|
+
export declare function buildPatch(existing: OrgSettings | undefined, msg: GlobalWorkflowsUpdateRequest): NormalizedPatch;
|
|
65
|
+
/**
|
|
66
|
+
* Project a row into the public settings shape. Returns a defaulted "disabled"
|
|
67
|
+
* settings object when the row does not yet exist, so callers always get a
|
|
68
|
+
* renderable state.
|
|
69
|
+
*/
|
|
70
|
+
export declare function rowToSettings(customerId: string, row: OrgSettings | undefined): GlobalWorkflowSettings;
|
|
71
|
+
export {};
|
|
72
|
+
//# sourceMappingURL=dashboard-global-workflows-handler.d.ts.map
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import type { Kysely } from 'kysely';
|
|
2
|
+
import { type ActorPrincipal } from '@kici-dev/engine';
|
|
3
|
+
import type { Database } from '../db/types.js';
|
|
4
|
+
import type { RegistrationStore } from '../registration/registration-store.js';
|
|
5
|
+
import type { RegistrationIndex } from '../registration/registration-index.js';
|
|
6
|
+
import type { AccessLogWriter } from '../audit/access-log.js';
|
|
7
|
+
interface DashboardRegistrationsHandlerDeps {
|
|
8
|
+
/** Organization ID for all operations. */
|
|
9
|
+
orgId: string;
|
|
10
|
+
/** Send a response message back to Platform over the WS connection. */
|
|
11
|
+
send: (msg: unknown) => void;
|
|
12
|
+
/** Registration store for DB queries. */
|
|
13
|
+
registrationStore: RegistrationStore;
|
|
14
|
+
/** Registration index for version info. */
|
|
15
|
+
registrationIndex: RegistrationIndex;
|
|
16
|
+
/** Database for execution_runs and cron_last_fired queries. */
|
|
17
|
+
db: Kysely<Database>;
|
|
18
|
+
/** Access log writer — records one row per read / mutation with actor attribution. */
|
|
19
|
+
accessLog?: AccessLogWriter;
|
|
20
|
+
/** Routing key for access_log rows (null when not run-scoped). */
|
|
21
|
+
routingKey?: string | null;
|
|
22
|
+
}
|
|
23
|
+
interface RegistrationsListMessage {
|
|
24
|
+
type: 'dashboard.registrations.list';
|
|
25
|
+
requestId: string;
|
|
26
|
+
actor: ActorPrincipal;
|
|
27
|
+
triggerType?: string;
|
|
28
|
+
repoIdentifier?: string;
|
|
29
|
+
}
|
|
30
|
+
interface RegistrationDisableMessage {
|
|
31
|
+
type: 'dashboard.registration.disable';
|
|
32
|
+
requestId: string;
|
|
33
|
+
actor: ActorPrincipal;
|
|
34
|
+
registrationId: string;
|
|
35
|
+
disabled: boolean;
|
|
36
|
+
}
|
|
37
|
+
interface RegistrationDeleteMessage {
|
|
38
|
+
type: 'dashboard.registration.delete';
|
|
39
|
+
requestId: string;
|
|
40
|
+
actor: ActorPrincipal;
|
|
41
|
+
registrationId: string;
|
|
42
|
+
cancelActiveRuns?: boolean;
|
|
43
|
+
}
|
|
44
|
+
type RegistrationMessage = RegistrationsListMessage | RegistrationDisableMessage | RegistrationDeleteMessage;
|
|
45
|
+
/**
|
|
46
|
+
* Handler for dashboard registration WS messages (list, disable, delete).
|
|
47
|
+
*
|
|
48
|
+
* Queries registration store, enriches with last-triggered and next-fire data,
|
|
49
|
+
* and sends typed response via deps.send().
|
|
50
|
+
*/
|
|
51
|
+
export declare class DashboardRegistrationsHandler {
|
|
52
|
+
private readonly deps;
|
|
53
|
+
private routingKey;
|
|
54
|
+
private readonly accessLog;
|
|
55
|
+
constructor(deps: DashboardRegistrationsHandlerDeps);
|
|
56
|
+
/** Update the orgId used for all operations (called when resolved from DB). */
|
|
57
|
+
setOrgId(orgId: string): void;
|
|
58
|
+
/** Update the routing key bound to access_log rows. */
|
|
59
|
+
setRoutingKey(routingKey: string | null): void;
|
|
60
|
+
/**
|
|
61
|
+
* Write an access_log row for a handler invocation. Uses the handler's
|
|
62
|
+
* bound orgId + routingKey, the msg.actor principal, and the handler-
|
|
63
|
+
* specified action + target. Best-effort; the writer swallows failures.
|
|
64
|
+
*/
|
|
65
|
+
private recordAccess;
|
|
66
|
+
handle(msg: RegistrationMessage): Promise<void>;
|
|
67
|
+
private handleDisable;
|
|
68
|
+
private handleDelete;
|
|
69
|
+
/**
|
|
70
|
+
* Batch-fetch source metadata for the routing keys in the registrations,
|
|
71
|
+
* keyed on `routing_key`. The map combines rows from `sources` (native,
|
|
72
|
+
* currently always GitHub Apps) and `generic_webhook_sources` (generic /
|
|
73
|
+
* universal-git / internal). When a routing key is present in both, the
|
|
74
|
+
* native row wins.
|
|
75
|
+
*
|
|
76
|
+
* Each query is wrapped in its own try/catch so a transient failure on
|
|
77
|
+
* one table still allows enrichment from the other; rows missing in both
|
|
78
|
+
* fall through to the synthetic fallback in `buildRegistrationSource`.
|
|
79
|
+
*/
|
|
80
|
+
private loadSourceMetadata;
|
|
81
|
+
private handleList;
|
|
82
|
+
}
|
|
83
|
+
export {};
|
|
84
|
+
//# sourceMappingURL=dashboard-registrations-handler.d.ts.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { OrchestratorToPlatformMessage } from '@kici-dev/engine';
|
|
2
|
+
import { RingBuffer } from '@kici-dev/shared';
|
|
3
|
+
/**
|
|
4
|
+
* In-memory buffer for orchestrator-to-Platform messages during disconnection.
|
|
5
|
+
*
|
|
6
|
+
* Wraps the generic RingBuffer from @kici-dev/shared with the orchestrator's
|
|
7
|
+
* message type. Default maxSize is 10,000 (inherited from RingBuffer). When
|
|
8
|
+
* the orchestrator loses its WebSocket connection to Platform, outgoing messages
|
|
9
|
+
* are buffered here and flushed in order on reconnection.
|
|
10
|
+
*/
|
|
11
|
+
export declare class EventBuffer extends RingBuffer<OrchestratorToPlatformMessage> {
|
|
12
|
+
constructor(options?: {
|
|
13
|
+
maxSize?: number;
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=event-buffer.d.ts.map
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WebSocket handler for observer connections.
|
|
3
|
+
*
|
|
4
|
+
* CLI clients connect to observe a running execution in real-time.
|
|
5
|
+
* The observer channel is read-only: clients subscribe with a run ID
|
|
6
|
+
* and token, then receive log chunks, step status changes, and
|
|
7
|
+
* completion events broadcast by the ObserverRegistry.
|
|
8
|
+
*
|
|
9
|
+
* Auth flow:
|
|
10
|
+
* 1. Connection opens, 5-second auth timeout starts
|
|
11
|
+
* 2. First message must be `observe.subscribe` with valid token and runId
|
|
12
|
+
* 3. Token validated against admin_tokens (same as admin API auth)
|
|
13
|
+
* 4. Run ID validated against execution_runs table
|
|
14
|
+
* 5. If valid: registered in ObserverRegistry, initial status sent
|
|
15
|
+
* 6. Subsequent messages ignored (read-only channel)
|
|
16
|
+
* 7. On close: unregistered from ObserverRegistry
|
|
17
|
+
*/
|
|
18
|
+
import type { WSEvents } from 'hono/ws';
|
|
19
|
+
import type { Kysely } from 'kysely';
|
|
20
|
+
import type { Database } from '../db/types.js';
|
|
21
|
+
import type { ObserverRegistry } from './observer-registry.js';
|
|
22
|
+
import type { TokenManager } from '../secrets/token-manager.js';
|
|
23
|
+
export declare const WS_CLOSE_OBSERVER_AUTH_FAILED = 4001;
|
|
24
|
+
export declare const WS_CLOSE_OBSERVER_AUTH_TIMEOUT = 4002;
|
|
25
|
+
export declare const WS_CLOSE_OBSERVER_INVALID_MESSAGE = 4003;
|
|
26
|
+
export declare const WS_CLOSE_OBSERVER_RUN_NOT_FOUND = 4030;
|
|
27
|
+
export interface ObserverHandlerDeps {
|
|
28
|
+
observerRegistry: ObserverRegistry;
|
|
29
|
+
db: Kysely<Database>;
|
|
30
|
+
tokenManager: TokenManager;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Create a Hono WS event handler for observer connections.
|
|
34
|
+
*
|
|
35
|
+
* Flow:
|
|
36
|
+
* 1. onOpen: start 5-second auth timeout
|
|
37
|
+
* 2. First onMessage: must be observe.subscribe with valid token + runId
|
|
38
|
+
* 3. Subsequent messages: ignored (read-only channel)
|
|
39
|
+
* 4. onClose: cleanup from registry
|
|
40
|
+
*/
|
|
41
|
+
export declare function createObserverWsHandler(deps: ObserverHandlerDeps): WSEvents;
|
|
42
|
+
//# sourceMappingURL=observer-handler.d.ts.map
|