swarmdo 1.4.8 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/helpers/statusline.cjs +7 -7
- package/README.md +3 -1
- package/package.json +5 -3
- package/v3/@swarmdo/cli/dist/src/commands/hooks.js +26 -24
- package/v3/@swarmdo/cli/dist/src/commands/index.js +4 -0
- package/v3/@swarmdo/cli/dist/src/commands/integrations.d.ts +14 -0
- package/v3/@swarmdo/cli/dist/src/commands/integrations.js +158 -0
- package/v3/@swarmdo/cli/dist/src/commands/memory.js +50 -1
- package/v3/@swarmdo/cli/dist/src/commands/providers.js +3 -0
- package/v3/@swarmdo/cli/dist/src/commands/release.d.ts +15 -0
- package/v3/@swarmdo/cli/dist/src/commands/release.js +224 -0
- package/v3/@swarmdo/cli/dist/src/commands/security.js +14 -0
- package/v3/@swarmdo/cli/dist/src/commands/transcript.js +82 -1
- package/v3/@swarmdo/cli/dist/src/commands/usage.js +80 -1
- package/v3/@swarmdo/cli/dist/src/config-lint/lint.js +11 -1
- package/v3/@swarmdo/cli/dist/src/init/statusline-generator.js +6 -6
- package/v3/@swarmdo/cli/dist/src/integrations/integrations.d.ts +54 -0
- package/v3/@swarmdo/cli/dist/src/integrations/integrations.js +162 -0
- package/v3/@swarmdo/cli/dist/src/mcp-tools/agent-execute-core.js +25 -3
- package/v3/@swarmdo/cli/dist/src/mcp-tools/agentdb-tools.js +8 -8
- package/v3/@swarmdo/cli/dist/src/memory/graph-edge-writer.d.ts +12 -0
- package/v3/@swarmdo/cli/dist/src/memory/graph-edge-writer.js +32 -1
- package/v3/@swarmdo/cli/dist/src/memory-vault/watch.d.ts +32 -0
- package/v3/@swarmdo/cli/dist/src/memory-vault/watch.js +66 -0
- package/v3/@swarmdo/cli/dist/src/providers/openrouter-config.d.ts +91 -0
- package/v3/@swarmdo/cli/dist/src/providers/openrouter-config.js +186 -0
- package/v3/@swarmdo/cli/dist/src/release/release.d.ts +72 -0
- package/v3/@swarmdo/cli/dist/src/release/release.js +86 -0
- package/v3/@swarmdo/cli/dist/src/resilience/backoff.d.ts +23 -0
- package/v3/@swarmdo/cli/dist/src/resilience/backoff.js +30 -0
- package/v3/@swarmdo/cli/dist/src/swarmvector/model-router.js +14 -0
- package/v3/@swarmdo/cli/dist/src/transcript/search.d.ts +39 -0
- package/v3/@swarmdo/cli/dist/src/transcript/search.js +67 -0
- package/v3/@swarmdo/cli/dist/src/usage/diff.d.ts +69 -0
- package/v3/@swarmdo/cli/dist/src/usage/diff.js +112 -0
- package/v3/@swarmdo/cli/package.json +4 -4
- package/v3/@swarmdo/cli-core/dist/src/index.js +1 -1
- package/v3/@swarmdo/codex/dist/cli.js +0 -0
- package/v3/@swarmdo/hooks/dist/cli/guidance-cli.js +0 -0
- package/v3/@swarmdo/hooks/dist/statusline/index.d.ts +3 -3
- package/v3/@swarmdo/hooks/dist/statusline/index.js +3 -3
- package/v3/@swarmdo/integration/dist/__tests__/agentic-flow-agent.test.js +4 -1
- package/v3/@swarmdo/neural/dist/flash-attention.d.ts +1 -1
- package/v3/@swarmdo/neural/dist/flash-attention.js +1 -1
- package/v3/@swarmdo/plugin-agent-federation/dist/plugin.js +1 -1
- package/v3/@swarmdo/plugin-agent-federation/dist/transport/midstream-aware-loader.js +2 -2
- package/v3/@swarmdo/providers/dist/swarmvector-provider.d.ts +1 -1
- package/v3/@swarmdo/providers/dist/swarmvector-provider.js +1 -1
- package/v3/@swarmdo/security/dist/input-validator.d.ts +6 -6
- package/v3/@swarmdo/shared/dist/hooks/safety/git-commit.js +1 -1
- package/v3/@swarmdo/shared/dist/mcp/transport/http.js +8 -1
- package/v3/vendor/agentdb/package.json +0 -1
- package/v3/vendor/agentic-flow/package.json +0 -1
- package/.claude/scheduled_tasks.lock +0 -1
- package/.claude/skills/sdo-caveman-compress/scripts/__pycache__/__init__.cpython-314.pyc +0 -0
- package/.claude/skills/sdo-caveman-compress/scripts/__pycache__/__main__.cpython-314.pyc +0 -0
- package/.claude/skills/sdo-caveman-compress/scripts/__pycache__/cli.cpython-314.pyc +0 -0
- package/.claude/skills/sdo-caveman-compress/scripts/__pycache__/compress.cpython-314.pyc +0 -0
- package/.claude/skills/sdo-caveman-compress/scripts/__pycache__/detect.cpython-314.pyc +0 -0
- package/.claude/skills/sdo-caveman-compress/scripts/__pycache__/validate.cpython-314.pyc +0 -0
- package/v3/@swarmdo/plugin-iot-cognitum/dist/application/index.d.ts +0 -2
- package/v3/@swarmdo/plugin-iot-cognitum/dist/application/index.js +0 -2
- package/v3/@swarmdo/plugin-iot-cognitum/dist/application/iot-coordinator.d.ts +0 -138
- package/v3/@swarmdo/plugin-iot-cognitum/dist/application/iot-coordinator.js +0 -418
- package/v3/@swarmdo/plugin-iot-cognitum/dist/bin.d.ts +0 -15
- package/v3/@swarmdo/plugin-iot-cognitum/dist/bin.js +0 -240
- package/v3/@swarmdo/plugin-iot-cognitum/dist/cli-commands.d.ts +0 -7
- package/v3/@swarmdo/plugin-iot-cognitum/dist/cli-commands.js +0 -508
- package/v3/@swarmdo/plugin-iot-cognitum/dist/domain/entities/device-agent.d.ts +0 -54
- package/v3/@swarmdo/plugin-iot-cognitum/dist/domain/entities/device-agent.js +0 -2
- package/v3/@swarmdo/plugin-iot-cognitum/dist/domain/entities/device-fleet.d.ts +0 -46
- package/v3/@swarmdo/plugin-iot-cognitum/dist/domain/entities/device-fleet.js +0 -2
- package/v3/@swarmdo/plugin-iot-cognitum/dist/domain/entities/device-trust-level.d.ts +0 -18
- package/v3/@swarmdo/plugin-iot-cognitum/dist/domain/entities/device-trust-level.js +0 -28
- package/v3/@swarmdo/plugin-iot-cognitum/dist/domain/entities/index.d.ts +0 -5
- package/v3/@swarmdo/plugin-iot-cognitum/dist/domain/entities/index.js +0 -2
- package/v3/@swarmdo/plugin-iot-cognitum/dist/domain/entities/telemetry.d.ts +0 -35
- package/v3/@swarmdo/plugin-iot-cognitum/dist/domain/entities/telemetry.js +0 -2
- package/v3/@swarmdo/plugin-iot-cognitum/dist/domain/repositories/device-repository.d.ts +0 -11
- package/v3/@swarmdo/plugin-iot-cognitum/dist/domain/repositories/device-repository.js +0 -2
- package/v3/@swarmdo/plugin-iot-cognitum/dist/domain/repositories/fleet-repository.d.ts +0 -9
- package/v3/@swarmdo/plugin-iot-cognitum/dist/domain/repositories/fleet-repository.js +0 -2
- package/v3/@swarmdo/plugin-iot-cognitum/dist/domain/repositories/index.d.ts +0 -5
- package/v3/@swarmdo/plugin-iot-cognitum/dist/domain/repositories/index.js +0 -2
- package/v3/@swarmdo/plugin-iot-cognitum/dist/domain/repositories/telemetry-repository.d.ts +0 -12
- package/v3/@swarmdo/plugin-iot-cognitum/dist/domain/repositories/telemetry-repository.js +0 -2
- package/v3/@swarmdo/plugin-iot-cognitum/dist/domain/repositories/trust-history-repository.d.ts +0 -19
- package/v3/@swarmdo/plugin-iot-cognitum/dist/domain/repositories/trust-history-repository.js +0 -2
- package/v3/@swarmdo/plugin-iot-cognitum/dist/domain/services/anomaly-detection-service.d.ts +0 -44
- package/v3/@swarmdo/plugin-iot-cognitum/dist/domain/services/anomaly-detection-service.js +0 -117
- package/v3/@swarmdo/plugin-iot-cognitum/dist/domain/services/device-lifecycle-service.d.ts +0 -70
- package/v3/@swarmdo/plugin-iot-cognitum/dist/domain/services/device-lifecycle-service.js +0 -194
- package/v3/@swarmdo/plugin-iot-cognitum/dist/domain/services/firmware-orchestration-service.d.ts +0 -69
- package/v3/@swarmdo/plugin-iot-cognitum/dist/domain/services/firmware-orchestration-service.js +0 -139
- package/v3/@swarmdo/plugin-iot-cognitum/dist/domain/services/fleet-topology-service.d.ts +0 -34
- package/v3/@swarmdo/plugin-iot-cognitum/dist/domain/services/fleet-topology-service.js +0 -101
- package/v3/@swarmdo/plugin-iot-cognitum/dist/domain/services/index.d.ts +0 -10
- package/v3/@swarmdo/plugin-iot-cognitum/dist/domain/services/index.js +0 -10
- package/v3/@swarmdo/plugin-iot-cognitum/dist/domain/services/mesh-service.d.ts +0 -64
- package/v3/@swarmdo/plugin-iot-cognitum/dist/domain/services/mesh-service.js +0 -70
- package/v3/@swarmdo/plugin-iot-cognitum/dist/domain/services/sona-integration-service.d.ts +0 -44
- package/v3/@swarmdo/plugin-iot-cognitum/dist/domain/services/sona-integration-service.js +0 -79
- package/v3/@swarmdo/plugin-iot-cognitum/dist/domain/services/telemetry-ingestion-service.d.ts +0 -37
- package/v3/@swarmdo/plugin-iot-cognitum/dist/domain/services/telemetry-ingestion-service.js +0 -39
- package/v3/@swarmdo/plugin-iot-cognitum/dist/domain/services/telemetry-service.d.ts +0 -67
- package/v3/@swarmdo/plugin-iot-cognitum/dist/domain/services/telemetry-service.js +0 -58
- package/v3/@swarmdo/plugin-iot-cognitum/dist/domain/services/witness-verification-service.d.ts +0 -45
- package/v3/@swarmdo/plugin-iot-cognitum/dist/domain/services/witness-verification-service.js +0 -63
- package/v3/@swarmdo/plugin-iot-cognitum/dist/index.d.ts +0 -26
- package/v3/@swarmdo/plugin-iot-cognitum/dist/index.js +0 -17
- package/v3/@swarmdo/plugin-iot-cognitum/dist/infrastructure/agentdb-telemetry-repository.d.ts +0 -51
- package/v3/@swarmdo/plugin-iot-cognitum/dist/infrastructure/agentdb-telemetry-repository.js +0 -110
- package/v3/@swarmdo/plugin-iot-cognitum/dist/infrastructure/in-memory-device-repository.d.ts +0 -13
- package/v3/@swarmdo/plugin-iot-cognitum/dist/infrastructure/in-memory-device-repository.js +0 -25
- package/v3/@swarmdo/plugin-iot-cognitum/dist/infrastructure/in-memory-fleet-repository.d.ts +0 -11
- package/v3/@swarmdo/plugin-iot-cognitum/dist/infrastructure/in-memory-fleet-repository.js +0 -19
- package/v3/@swarmdo/plugin-iot-cognitum/dist/infrastructure/in-memory-trust-history-repository.d.ts +0 -11
- package/v3/@swarmdo/plugin-iot-cognitum/dist/infrastructure/in-memory-trust-history-repository.js +0 -27
- package/v3/@swarmdo/plugin-iot-cognitum/dist/infrastructure/index.d.ts +0 -6
- package/v3/@swarmdo/plugin-iot-cognitum/dist/infrastructure/index.js +0 -6
- package/v3/@swarmdo/plugin-iot-cognitum/dist/infrastructure/seed-client-factory.d.ts +0 -41
- package/v3/@swarmdo/plugin-iot-cognitum/dist/infrastructure/seed-client-factory.js +0 -64
- package/v3/@swarmdo/plugin-iot-cognitum/dist/mcp-tools.d.ts +0 -8
- package/v3/@swarmdo/plugin-iot-cognitum/dist/mcp-tools.js +0 -703
- package/v3/@swarmdo/plugin-iot-cognitum/dist/plugin.d.ts +0 -23
- package/v3/@swarmdo/plugin-iot-cognitum/dist/plugin.js +0 -239
- package/v3/@swarmdo/plugin-iot-cognitum/dist/workers/anomaly-scan-worker.d.ts +0 -17
- package/v3/@swarmdo/plugin-iot-cognitum/dist/workers/anomaly-scan-worker.js +0 -42
- package/v3/@swarmdo/plugin-iot-cognitum/dist/workers/firmware-watch-worker.d.ts +0 -18
- package/v3/@swarmdo/plugin-iot-cognitum/dist/workers/firmware-watch-worker.js +0 -45
- package/v3/@swarmdo/plugin-iot-cognitum/dist/workers/health-probe-worker.d.ts +0 -19
- package/v3/@swarmdo/plugin-iot-cognitum/dist/workers/health-probe-worker.js +0 -50
- package/v3/@swarmdo/plugin-iot-cognitum/dist/workers/mesh-sync-worker.d.ts +0 -19
- package/v3/@swarmdo/plugin-iot-cognitum/dist/workers/mesh-sync-worker.js +0 -47
- package/v3/@swarmdo/plugin-iot-cognitum/dist/workers/telemetry-ingest-worker.d.ts +0 -17
- package/v3/@swarmdo/plugin-iot-cognitum/dist/workers/telemetry-ingest-worker.js +0 -40
- package/v3/@swarmdo/plugin-iot-cognitum/dist/workers/witness-audit-worker.d.ts +0 -18
- package/v3/@swarmdo/plugin-iot-cognitum/dist/workers/witness-audit-worker.js +0 -51
- package/v3/@swarmdo/testing/dist/fixtures/agent-fixtures.d.ts +0 -214
- package/v3/@swarmdo/testing/dist/fixtures/agent-fixtures.js +0 -595
- package/v3/@swarmdo/testing/dist/fixtures/agents.d.ts +0 -76
- package/v3/@swarmdo/testing/dist/fixtures/agents.js +0 -158
- package/v3/@swarmdo/testing/dist/fixtures/configurations.d.ts +0 -157
- package/v3/@swarmdo/testing/dist/fixtures/configurations.js +0 -337
- package/v3/@swarmdo/testing/dist/fixtures/index.d.ts +0 -10
- package/v3/@swarmdo/testing/dist/fixtures/index.js +0 -17
- package/v3/@swarmdo/testing/dist/fixtures/mcp-fixtures.d.ts +0 -329
- package/v3/@swarmdo/testing/dist/fixtures/mcp-fixtures.js +0 -714
- package/v3/@swarmdo/testing/dist/fixtures/memory-entries.d.ts +0 -159
- package/v3/@swarmdo/testing/dist/fixtures/memory-entries.js +0 -262
- package/v3/@swarmdo/testing/dist/fixtures/memory-fixtures.d.ts +0 -290
- package/v3/@swarmdo/testing/dist/fixtures/memory-fixtures.js +0 -547
- package/v3/@swarmdo/testing/dist/fixtures/swarm-fixtures.d.ts +0 -289
- package/v3/@swarmdo/testing/dist/fixtures/swarm-fixtures.js +0 -534
- package/v3/@swarmdo/testing/dist/fixtures/tasks.d.ts +0 -106
- package/v3/@swarmdo/testing/dist/fixtures/tasks.js +0 -229
- package/v3/@swarmdo/testing/dist/helpers/assertion-helpers.d.ts +0 -213
- package/v3/@swarmdo/testing/dist/helpers/assertion-helpers.js +0 -435
- package/v3/@swarmdo/testing/dist/helpers/assertions.d.ts +0 -135
- package/v3/@swarmdo/testing/dist/helpers/assertions.js +0 -217
- package/v3/@swarmdo/testing/dist/helpers/create-mock.d.ts +0 -96
- package/v3/@swarmdo/testing/dist/helpers/create-mock.js +0 -164
- package/v3/@swarmdo/testing/dist/helpers/index.d.ts +0 -14
- package/v3/@swarmdo/testing/dist/helpers/index.js +0 -22
- package/v3/@swarmdo/testing/dist/helpers/mock-factory.d.ts +0 -323
- package/v3/@swarmdo/testing/dist/helpers/mock-factory.js +0 -350
- package/v3/@swarmdo/testing/dist/helpers/setup-teardown.d.ts +0 -271
- package/v3/@swarmdo/testing/dist/helpers/setup-teardown.js +0 -446
- package/v3/@swarmdo/testing/dist/helpers/swarm-instance.d.ts +0 -142
- package/v3/@swarmdo/testing/dist/helpers/swarm-instance.js +0 -205
- package/v3/@swarmdo/testing/dist/helpers/test-application.d.ts +0 -190
- package/v3/@swarmdo/testing/dist/helpers/test-application.js +0 -138
- package/v3/@swarmdo/testing/dist/helpers/test-utils.d.ts +0 -274
- package/v3/@swarmdo/testing/dist/helpers/test-utils.js +0 -456
- package/v3/@swarmdo/testing/dist/index.d.ts +0 -42
- package/v3/@swarmdo/testing/dist/index.js +0 -66
- package/v3/@swarmdo/testing/dist/mocks/index.d.ts +0 -8
- package/v3/@swarmdo/testing/dist/mocks/index.js +0 -10
- package/v3/@swarmdo/testing/dist/mocks/mock-mcp-client.d.ts +0 -206
- package/v3/@swarmdo/testing/dist/mocks/mock-mcp-client.js +0 -575
- package/v3/@swarmdo/testing/dist/mocks/mock-services.d.ts +0 -287
- package/v3/@swarmdo/testing/dist/mocks/mock-services.js +0 -563
- package/v3/@swarmdo/testing/dist/regression/api-contract.d.ts +0 -109
- package/v3/@swarmdo/testing/dist/regression/api-contract.js +0 -374
- package/v3/@swarmdo/testing/dist/regression/index.d.ts +0 -18
- package/v3/@swarmdo/testing/dist/regression/index.js +0 -18
- package/v3/@swarmdo/testing/dist/regression/integration-regression.d.ts +0 -67
- package/v3/@swarmdo/testing/dist/regression/integration-regression.js +0 -334
- package/v3/@swarmdo/testing/dist/regression/performance-baseline.d.ts +0 -106
- package/v3/@swarmdo/testing/dist/regression/performance-baseline.js +0 -268
- package/v3/@swarmdo/testing/dist/regression/regression-runner.d.ts +0 -124
- package/v3/@swarmdo/testing/dist/regression/regression-runner.js +0 -227
- package/v3/@swarmdo/testing/dist/regression/security-regression.d.ts +0 -73
- package/v3/@swarmdo/testing/dist/regression/security-regression.js +0 -258
- package/v3/@swarmdo/testing/dist/setup.d.ts +0 -43
- package/v3/@swarmdo/testing/dist/setup.js +0 -91
- package/v3/@swarmdo/testing/dist/v2-compat/api-compat.test.d.ts +0 -10
- package/v3/@swarmdo/testing/dist/v2-compat/api-compat.test.js +0 -433
- package/v3/@swarmdo/testing/dist/v2-compat/cli-compat.test.d.ts +0 -10
- package/v3/@swarmdo/testing/dist/v2-compat/cli-compat.test.js +0 -352
- package/v3/@swarmdo/testing/dist/v2-compat/compatibility-validator.d.ts +0 -206
- package/v3/@swarmdo/testing/dist/v2-compat/compatibility-validator.js +0 -839
- package/v3/@swarmdo/testing/dist/v2-compat/hooks-compat.test.d.ts +0 -10
- package/v3/@swarmdo/testing/dist/v2-compat/hooks-compat.test.js +0 -428
- package/v3/@swarmdo/testing/dist/v2-compat/index.d.ts +0 -38
- package/v3/@swarmdo/testing/dist/v2-compat/index.js +0 -41
- package/v3/@swarmdo/testing/dist/v2-compat/mcp-compat.test.d.ts +0 -10
- package/v3/@swarmdo/testing/dist/v2-compat/mcp-compat.test.js +0 -419
- package/v3/@swarmdo/testing/dist/v2-compat/report-generator.d.ts +0 -34
- package/v3/@swarmdo/testing/dist/v2-compat/report-generator.js +0 -372
package/v3/@swarmdo/plugin-iot-cognitum/dist/domain/services/firmware-orchestration-service.js
DELETED
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
// ---------------------------------------------------------------------------
|
|
2
|
-
// Service
|
|
3
|
-
// ---------------------------------------------------------------------------
|
|
4
|
-
/**
|
|
5
|
-
* State-machine-based firmware rollout engine.
|
|
6
|
-
*
|
|
7
|
-
* Lifecycle: pending -> canary -> rolling -> complete
|
|
8
|
-
* | |
|
|
9
|
-
* rolled-back failed
|
|
10
|
-
*/
|
|
11
|
-
export class FirmwareOrchestrationService {
|
|
12
|
-
deps;
|
|
13
|
-
rollouts = new Map();
|
|
14
|
-
rolloutCounter = 0;
|
|
15
|
-
constructor(deps) {
|
|
16
|
-
this.deps = deps;
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Create a new rollout. Canary devices are selected as the first N%
|
|
20
|
-
* of `targetDeviceIds` based on `policy.canaryPercentage`.
|
|
21
|
-
*/
|
|
22
|
-
createRollout(fleetId, firmwareVersion, targetDeviceIds, policy) {
|
|
23
|
-
const rolloutId = `rollout-${fleetId}-${Date.now()}-${this.rolloutCounter++}`;
|
|
24
|
-
const canaryCount = Math.max(1, Math.ceil(targetDeviceIds.length * (policy.canaryPercentage / 100)));
|
|
25
|
-
const canaryDeviceIds = targetDeviceIds.slice(0, canaryCount);
|
|
26
|
-
const rollout = {
|
|
27
|
-
rolloutId,
|
|
28
|
-
fleetId,
|
|
29
|
-
firmwareVersion,
|
|
30
|
-
strategy: 'canary',
|
|
31
|
-
stage: 'pending',
|
|
32
|
-
targetDeviceIds,
|
|
33
|
-
canaryDeviceIds,
|
|
34
|
-
completedDeviceIds: [],
|
|
35
|
-
failedDeviceIds: [],
|
|
36
|
-
anomalyThreshold: policy.rollbackOnAnomalyThreshold,
|
|
37
|
-
startedAt: new Date(),
|
|
38
|
-
updatedAt: new Date(),
|
|
39
|
-
};
|
|
40
|
-
this.rollouts.set(rolloutId, rollout);
|
|
41
|
-
return rollout;
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Advance the rollout through its state machine:
|
|
45
|
-
* pending -> canary (deploy to canary devices)
|
|
46
|
-
* canary -> rolling (anomaly check passes)
|
|
47
|
-
* canary -> rolled-back (anomaly check fails)
|
|
48
|
-
* rolling -> complete (deploy to remaining devices)
|
|
49
|
-
*/
|
|
50
|
-
async advanceRollout(rolloutId) {
|
|
51
|
-
const rollout = this.getExistingRollout(rolloutId);
|
|
52
|
-
switch (rollout.stage) {
|
|
53
|
-
case 'pending':
|
|
54
|
-
return this.transitionPendingToCanary(rollout);
|
|
55
|
-
case 'canary':
|
|
56
|
-
return this.transitionCanaryToNextStage(rollout);
|
|
57
|
-
case 'rolling':
|
|
58
|
-
return this.transitionRollingToComplete(rollout);
|
|
59
|
-
default:
|
|
60
|
-
return rollout;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Force-rollback a rollout regardless of current stage.
|
|
65
|
-
*/
|
|
66
|
-
rollbackRollout(rolloutId) {
|
|
67
|
-
const rollout = this.getExistingRollout(rolloutId);
|
|
68
|
-
rollout.stage = 'rolled-back';
|
|
69
|
-
rollout.updatedAt = new Date();
|
|
70
|
-
return rollout;
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* Retrieve a rollout by ID. Throws if not found.
|
|
74
|
-
*/
|
|
75
|
-
getRollout(rolloutId) {
|
|
76
|
-
return this.getExistingRollout(rolloutId);
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* List rollouts, optionally filtered by fleet ID.
|
|
80
|
-
*/
|
|
81
|
-
listRollouts(fleetId) {
|
|
82
|
-
const all = Array.from(this.rollouts.values());
|
|
83
|
-
if (fleetId === undefined)
|
|
84
|
-
return all;
|
|
85
|
-
return all.filter((r) => r.fleetId === fleetId);
|
|
86
|
-
}
|
|
87
|
-
// ---------------------------------------------------------------------------
|
|
88
|
-
// State-machine transitions
|
|
89
|
-
// ---------------------------------------------------------------------------
|
|
90
|
-
async transitionPendingToCanary(rollout) {
|
|
91
|
-
await this.deployToDevices(rollout, rollout.canaryDeviceIds, rollout.firmwareVersion);
|
|
92
|
-
rollout.stage = 'canary';
|
|
93
|
-
rollout.updatedAt = new Date();
|
|
94
|
-
return rollout;
|
|
95
|
-
}
|
|
96
|
-
async transitionCanaryToNextStage(rollout) {
|
|
97
|
-
for (const deviceId of rollout.canaryDeviceIds) {
|
|
98
|
-
const score = await this.deps.getDeviceAnomalyScore(deviceId);
|
|
99
|
-
if (score > rollout.anomalyThreshold) {
|
|
100
|
-
rollout.stage = 'rolled-back';
|
|
101
|
-
rollout.updatedAt = new Date();
|
|
102
|
-
return rollout;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
rollout.stage = 'rolling';
|
|
106
|
-
rollout.updatedAt = new Date();
|
|
107
|
-
return rollout;
|
|
108
|
-
}
|
|
109
|
-
async transitionRollingToComplete(rollout) {
|
|
110
|
-
const remainingDeviceIds = rollout.targetDeviceIds.filter((id) => !rollout.canaryDeviceIds.includes(id));
|
|
111
|
-
await this.deployToDevices(rollout, remainingDeviceIds, rollout.firmwareVersion);
|
|
112
|
-
rollout.stage = 'complete';
|
|
113
|
-
rollout.updatedAt = new Date();
|
|
114
|
-
rollout.completedAt = new Date();
|
|
115
|
-
return rollout;
|
|
116
|
-
}
|
|
117
|
-
// ---------------------------------------------------------------------------
|
|
118
|
-
// Helpers
|
|
119
|
-
// ---------------------------------------------------------------------------
|
|
120
|
-
async deployToDevices(rollout, deviceIds, version) {
|
|
121
|
-
for (const deviceId of deviceIds) {
|
|
122
|
-
const result = await this.deps.deployFirmware(deviceId, version);
|
|
123
|
-
if (result.success) {
|
|
124
|
-
rollout.completedDeviceIds.push(deviceId);
|
|
125
|
-
}
|
|
126
|
-
else {
|
|
127
|
-
rollout.failedDeviceIds.push(deviceId);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
getExistingRollout(rolloutId) {
|
|
132
|
-
const rollout = this.rollouts.get(rolloutId);
|
|
133
|
-
if (!rollout) {
|
|
134
|
-
throw new Error(`Rollout ${rolloutId} not found`);
|
|
135
|
-
}
|
|
136
|
-
return rollout;
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
//# sourceMappingURL=firmware-orchestration-service.js.map
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import type { DeviceFleet, FleetTopology, FirmwarePolicy, TelemetryPolicy, HealthThresholds } from '../entities/index.js';
|
|
2
|
-
import type { FleetRepository } from '../repositories/index.js';
|
|
3
|
-
export interface CreateFleetOptions {
|
|
4
|
-
fleetId: string;
|
|
5
|
-
name: string;
|
|
6
|
-
description?: string;
|
|
7
|
-
zoneId: string;
|
|
8
|
-
topology?: FleetTopology;
|
|
9
|
-
firmwarePolicy?: Partial<FirmwarePolicy>;
|
|
10
|
-
telemetryPolicy?: Partial<TelemetryPolicy>;
|
|
11
|
-
healthThresholds?: Partial<HealthThresholds>;
|
|
12
|
-
}
|
|
13
|
-
export interface FleetSummary {
|
|
14
|
-
fleetId: string;
|
|
15
|
-
name: string;
|
|
16
|
-
zoneId: string;
|
|
17
|
-
deviceCount: number;
|
|
18
|
-
topology: FleetTopology;
|
|
19
|
-
createdAt: Date;
|
|
20
|
-
}
|
|
21
|
-
export declare class FleetTopologyService {
|
|
22
|
-
private readonly repo;
|
|
23
|
-
constructor(repo: FleetRepository);
|
|
24
|
-
createFleet(options: CreateFleetOptions): Promise<DeviceFleet>;
|
|
25
|
-
getFleet(fleetId: string): Promise<DeviceFleet>;
|
|
26
|
-
listFleets(): Promise<FleetSummary[]>;
|
|
27
|
-
addDeviceToFleet(fleetId: string, deviceId: string): Promise<DeviceFleet>;
|
|
28
|
-
removeDeviceFromFleet(fleetId: string, deviceId: string): Promise<DeviceFleet>;
|
|
29
|
-
updateTopology(fleetId: string, topology: FleetTopology): Promise<DeviceFleet>;
|
|
30
|
-
updateFirmwarePolicy(fleetId: string, policy: Partial<FirmwarePolicy>): Promise<DeviceFleet>;
|
|
31
|
-
deleteFleet(fleetId: string): Promise<void>;
|
|
32
|
-
getFleetDeviceCount(fleetId: string): Promise<number>;
|
|
33
|
-
}
|
|
34
|
-
//# sourceMappingURL=fleet-topology-service.d.ts.map
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
const DEFAULT_FIRMWARE_POLICY = {
|
|
2
|
-
channel: 'stable',
|
|
3
|
-
autoUpdate: false,
|
|
4
|
-
approvalRequired: true,
|
|
5
|
-
canaryPercentage: 10,
|
|
6
|
-
canaryDurationMinutes: 30,
|
|
7
|
-
rollbackOnAnomalyThreshold: 0.8,
|
|
8
|
-
};
|
|
9
|
-
const DEFAULT_TELEMETRY_POLICY = {
|
|
10
|
-
ingestionIntervalSeconds: 60,
|
|
11
|
-
retentionDays: 30,
|
|
12
|
-
anomalyDetectionEnabled: true,
|
|
13
|
-
anomalyThreshold: 0.7,
|
|
14
|
-
vectorDimension: 128,
|
|
15
|
-
};
|
|
16
|
-
const DEFAULT_HEALTH_THRESHOLDS = {
|
|
17
|
-
maxOfflineMinutes: 10,
|
|
18
|
-
minUptimeRatio: 0.95,
|
|
19
|
-
maxConsecutiveAnomalies: 3,
|
|
20
|
-
minFirmwareCurrency: 0.8,
|
|
21
|
-
};
|
|
22
|
-
export class FleetTopologyService {
|
|
23
|
-
repo;
|
|
24
|
-
constructor(repo) {
|
|
25
|
-
this.repo = repo;
|
|
26
|
-
}
|
|
27
|
-
async createFleet(options) {
|
|
28
|
-
const existing = await this.repo.findById(options.fleetId);
|
|
29
|
-
if (existing)
|
|
30
|
-
throw new Error(`Fleet ${options.fleetId} already exists`);
|
|
31
|
-
const fleet = {
|
|
32
|
-
fleetId: options.fleetId,
|
|
33
|
-
name: options.name,
|
|
34
|
-
description: options.description ?? '',
|
|
35
|
-
zoneId: options.zoneId,
|
|
36
|
-
deviceIds: [],
|
|
37
|
-
topology: options.topology ?? 'star',
|
|
38
|
-
firmwarePolicy: { ...DEFAULT_FIRMWARE_POLICY, ...options.firmwarePolicy },
|
|
39
|
-
telemetryPolicy: { ...DEFAULT_TELEMETRY_POLICY, ...options.telemetryPolicy },
|
|
40
|
-
healthThresholds: { ...DEFAULT_HEALTH_THRESHOLDS, ...options.healthThresholds },
|
|
41
|
-
createdAt: new Date(),
|
|
42
|
-
updatedAt: new Date(),
|
|
43
|
-
};
|
|
44
|
-
await this.repo.save(fleet);
|
|
45
|
-
return fleet;
|
|
46
|
-
}
|
|
47
|
-
async getFleet(fleetId) {
|
|
48
|
-
const fleet = await this.repo.findById(fleetId);
|
|
49
|
-
if (!fleet)
|
|
50
|
-
throw new Error(`Fleet ${fleetId} not found`);
|
|
51
|
-
return fleet;
|
|
52
|
-
}
|
|
53
|
-
async listFleets() {
|
|
54
|
-
const fleets = await this.repo.findAll();
|
|
55
|
-
return fleets.map((f) => ({
|
|
56
|
-
fleetId: f.fleetId,
|
|
57
|
-
name: f.name,
|
|
58
|
-
zoneId: f.zoneId,
|
|
59
|
-
deviceCount: f.deviceIds.length,
|
|
60
|
-
topology: f.topology,
|
|
61
|
-
createdAt: f.createdAt,
|
|
62
|
-
}));
|
|
63
|
-
}
|
|
64
|
-
async addDeviceToFleet(fleetId, deviceId) {
|
|
65
|
-
const fleet = await this.getFleet(fleetId);
|
|
66
|
-
if (fleet.deviceIds.includes(deviceId)) {
|
|
67
|
-
return fleet;
|
|
68
|
-
}
|
|
69
|
-
fleet.deviceIds.push(deviceId);
|
|
70
|
-
await this.repo.save(fleet);
|
|
71
|
-
return fleet;
|
|
72
|
-
}
|
|
73
|
-
async removeDeviceFromFleet(fleetId, deviceId) {
|
|
74
|
-
const fleet = await this.getFleet(fleetId);
|
|
75
|
-
fleet.deviceIds = fleet.deviceIds.filter((id) => id !== deviceId);
|
|
76
|
-
await this.repo.save(fleet);
|
|
77
|
-
return fleet;
|
|
78
|
-
}
|
|
79
|
-
async updateTopology(fleetId, topology) {
|
|
80
|
-
const fleet = await this.getFleet(fleetId);
|
|
81
|
-
fleet.topology = topology;
|
|
82
|
-
await this.repo.save(fleet);
|
|
83
|
-
return fleet;
|
|
84
|
-
}
|
|
85
|
-
async updateFirmwarePolicy(fleetId, policy) {
|
|
86
|
-
const fleet = await this.getFleet(fleetId);
|
|
87
|
-
fleet.firmwarePolicy = { ...fleet.firmwarePolicy, ...policy };
|
|
88
|
-
await this.repo.save(fleet);
|
|
89
|
-
return fleet;
|
|
90
|
-
}
|
|
91
|
-
async deleteFleet(fleetId) {
|
|
92
|
-
const deleted = await this.repo.delete(fleetId);
|
|
93
|
-
if (!deleted)
|
|
94
|
-
throw new Error(`Fleet ${fleetId} not found`);
|
|
95
|
-
}
|
|
96
|
-
async getFleetDeviceCount(fleetId) {
|
|
97
|
-
const fleet = await this.getFleet(fleetId);
|
|
98
|
-
return fleet.deviceIds.length;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
//# sourceMappingURL=fleet-topology-service.js.map
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export { DeviceLifecycleService, type DeviceLifecycleDeps, } from './device-lifecycle-service.js';
|
|
2
|
-
export { TelemetryService, type TelemetryServiceDeps, type StoreQueryResult, type IngestResult, type StoreHealthStatus, } from './telemetry-service.js';
|
|
3
|
-
export { MeshService, type MeshServiceDeps, type MeshPeer, type MeshTopology, } from './mesh-service.js';
|
|
4
|
-
export { AnomalyDetectionService, type AnomalyDetectionConfig, type TelemetryBaseline, } from './anomaly-detection-service.js';
|
|
5
|
-
export { TelemetryIngestionService, type TelemetryIngestionDeps, type IngestionResult, } from './telemetry-ingestion-service.js';
|
|
6
|
-
export { FleetTopologyService, type CreateFleetOptions, type FleetSummary, } from './fleet-topology-service.js';
|
|
7
|
-
export { FirmwareOrchestrationService, type FirmwareOrchestrationDeps, type FirmwareRollout, type RolloutStage, } from './firmware-orchestration-service.js';
|
|
8
|
-
export { WitnessVerificationService, type WitnessVerificationDeps, type WitnessVerificationResult, type WitnessEntry, type WitnessGap, } from './witness-verification-service.js';
|
|
9
|
-
export { SONAIntegrationService, type SONAClient, type SONAIntegrationConfig, } from './sona-integration-service.js';
|
|
10
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export { DeviceLifecycleService, } from './device-lifecycle-service.js';
|
|
2
|
-
export { TelemetryService, } from './telemetry-service.js';
|
|
3
|
-
export { MeshService, } from './mesh-service.js';
|
|
4
|
-
export { AnomalyDetectionService, } from './anomaly-detection-service.js';
|
|
5
|
-
export { TelemetryIngestionService, } from './telemetry-ingestion-service.js';
|
|
6
|
-
export { FleetTopologyService, } from './fleet-topology-service.js';
|
|
7
|
-
export { FirmwareOrchestrationService, } from './firmware-orchestration-service.js';
|
|
8
|
-
export { WitnessVerificationService, } from './witness-verification-service.js';
|
|
9
|
-
export { SONAIntegrationService, } from './sona-integration-service.js';
|
|
10
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
export interface MeshServiceDeps {
|
|
2
|
-
getMeshStatus: (deviceId: string) => Promise<{
|
|
3
|
-
ap_active?: boolean;
|
|
4
|
-
auto_mesh?: boolean;
|
|
5
|
-
peer_count?: number;
|
|
6
|
-
peers?: Array<{
|
|
7
|
-
device_id?: string;
|
|
8
|
-
address?: string;
|
|
9
|
-
}>;
|
|
10
|
-
}>;
|
|
11
|
-
getPeers: (deviceId: string) => Promise<{
|
|
12
|
-
count?: number;
|
|
13
|
-
peers?: Array<{
|
|
14
|
-
device_id?: string;
|
|
15
|
-
address?: string;
|
|
16
|
-
}>;
|
|
17
|
-
}>;
|
|
18
|
-
getSwarmStatus: (deviceId: string) => Promise<{
|
|
19
|
-
device_id?: string;
|
|
20
|
-
epoch?: number;
|
|
21
|
-
peer_count?: number;
|
|
22
|
-
total_vectors?: number;
|
|
23
|
-
uptime_secs?: number;
|
|
24
|
-
}>;
|
|
25
|
-
getClusterHealth: (deviceId: string) => Promise<{
|
|
26
|
-
cluster_enabled?: boolean;
|
|
27
|
-
peer_count?: number;
|
|
28
|
-
auto_sync_interval_secs?: number;
|
|
29
|
-
}>;
|
|
30
|
-
}
|
|
31
|
-
export interface MeshPeer {
|
|
32
|
-
deviceId: string;
|
|
33
|
-
address?: string;
|
|
34
|
-
}
|
|
35
|
-
export interface MeshTopology {
|
|
36
|
-
deviceId: string;
|
|
37
|
-
apActive: boolean;
|
|
38
|
-
autoMesh: boolean;
|
|
39
|
-
clusterEnabled: boolean;
|
|
40
|
-
autoSyncIntervalSecs: number;
|
|
41
|
-
peerCount: number;
|
|
42
|
-
peers: MeshPeer[];
|
|
43
|
-
swarmEpoch?: number;
|
|
44
|
-
swarmTotalVectors?: number;
|
|
45
|
-
swarmUptimeSecs?: number;
|
|
46
|
-
}
|
|
47
|
-
export declare class MeshService {
|
|
48
|
-
private readonly deps;
|
|
49
|
-
constructor(deps: MeshServiceDeps);
|
|
50
|
-
/**
|
|
51
|
-
* Aggregate all mesh endpoints into a single topology snapshot.
|
|
52
|
-
*/
|
|
53
|
-
getTopology(deviceId: string): Promise<MeshTopology>;
|
|
54
|
-
/**
|
|
55
|
-
* Discover and return the device IDs of all known mesh peers.
|
|
56
|
-
*/
|
|
57
|
-
discoverPeers(deviceId: string): Promise<string[]>;
|
|
58
|
-
/**
|
|
59
|
-
* De-duplicate peers from multiple sources, preferring entries that carry
|
|
60
|
-
* both a device_id and an address.
|
|
61
|
-
*/
|
|
62
|
-
private mergePeers;
|
|
63
|
-
}
|
|
64
|
-
//# sourceMappingURL=mesh-service.d.ts.map
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
// ---------------------------------------------------------------------------
|
|
2
|
-
// Dependency contract
|
|
3
|
-
// ---------------------------------------------------------------------------
|
|
4
|
-
// ---------------------------------------------------------------------------
|
|
5
|
-
// Service
|
|
6
|
-
// ---------------------------------------------------------------------------
|
|
7
|
-
export class MeshService {
|
|
8
|
-
deps;
|
|
9
|
-
constructor(deps) {
|
|
10
|
-
this.deps = deps;
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Aggregate all mesh endpoints into a single topology snapshot.
|
|
14
|
-
*/
|
|
15
|
-
async getTopology(deviceId) {
|
|
16
|
-
const [mesh, peers, swarm, cluster] = await Promise.all([
|
|
17
|
-
this.deps.getMeshStatus(deviceId),
|
|
18
|
-
this.deps.getPeers(deviceId),
|
|
19
|
-
this.deps.getSwarmStatus(deviceId),
|
|
20
|
-
this.deps.getClusterHealth(deviceId),
|
|
21
|
-
]);
|
|
22
|
-
const mergedPeers = this.mergePeers(mesh.peers ?? [], peers.peers ?? []);
|
|
23
|
-
return {
|
|
24
|
-
deviceId,
|
|
25
|
-
apActive: mesh.ap_active ?? false,
|
|
26
|
-
autoMesh: mesh.auto_mesh ?? false,
|
|
27
|
-
clusterEnabled: cluster.cluster_enabled ?? false,
|
|
28
|
-
autoSyncIntervalSecs: cluster.auto_sync_interval_secs ?? 0,
|
|
29
|
-
peerCount: mergedPeers.length,
|
|
30
|
-
peers: mergedPeers,
|
|
31
|
-
swarmEpoch: swarm.epoch,
|
|
32
|
-
swarmTotalVectors: swarm.total_vectors,
|
|
33
|
-
swarmUptimeSecs: swarm.uptime_secs,
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Discover and return the device IDs of all known mesh peers.
|
|
38
|
-
*/
|
|
39
|
-
async discoverPeers(deviceId) {
|
|
40
|
-
const [mesh, peers] = await Promise.all([
|
|
41
|
-
this.deps.getMeshStatus(deviceId),
|
|
42
|
-
this.deps.getPeers(deviceId),
|
|
43
|
-
]);
|
|
44
|
-
const merged = this.mergePeers(mesh.peers ?? [], peers.peers ?? []);
|
|
45
|
-
return merged.map((p) => p.deviceId);
|
|
46
|
-
}
|
|
47
|
-
// ---------------------------------------------------------------------------
|
|
48
|
-
// Helpers
|
|
49
|
-
// ---------------------------------------------------------------------------
|
|
50
|
-
/**
|
|
51
|
-
* De-duplicate peers from multiple sources, preferring entries that carry
|
|
52
|
-
* both a device_id and an address.
|
|
53
|
-
*/
|
|
54
|
-
mergePeers(...sources) {
|
|
55
|
-
const seen = new Map();
|
|
56
|
-
for (const list of sources) {
|
|
57
|
-
for (const raw of list) {
|
|
58
|
-
const id = raw.device_id;
|
|
59
|
-
if (!id)
|
|
60
|
-
continue;
|
|
61
|
-
const existing = seen.get(id);
|
|
62
|
-
if (!existing || (!existing.address && raw.address)) {
|
|
63
|
-
seen.set(id, { deviceId: id, address: raw.address });
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
return [...seen.values()];
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
//# sourceMappingURL=mesh-service.js.map
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import type { AnomalyDetection, TelemetryReading } from '../entities/telemetry.js';
|
|
2
|
-
import type { TelemetryBaseline } from './anomaly-detection-service.js';
|
|
3
|
-
export interface SONAClient {
|
|
4
|
-
storePattern(key: string, pattern: Record<string, unknown>): Promise<void>;
|
|
5
|
-
searchPatterns(query: string, limit?: number): Promise<Array<{
|
|
6
|
-
key: string;
|
|
7
|
-
pattern: Record<string, unknown>;
|
|
8
|
-
score: number;
|
|
9
|
-
}>>;
|
|
10
|
-
trainTrajectory(trajectoryId: string, steps: Array<{
|
|
11
|
-
action: string;
|
|
12
|
-
reward: number;
|
|
13
|
-
state: Record<string, unknown>;
|
|
14
|
-
}>): Promise<void>;
|
|
15
|
-
predict(input: Record<string, unknown>): Promise<{
|
|
16
|
-
prediction: string;
|
|
17
|
-
confidence: number;
|
|
18
|
-
}>;
|
|
19
|
-
}
|
|
20
|
-
export interface SONAIntegrationConfig {
|
|
21
|
-
enabled: boolean;
|
|
22
|
-
trajectoryNamespace: string;
|
|
23
|
-
patternNamespace: string;
|
|
24
|
-
minConfidence: number;
|
|
25
|
-
}
|
|
26
|
-
export declare class SONAIntegrationService {
|
|
27
|
-
private readonly config;
|
|
28
|
-
private readonly client;
|
|
29
|
-
constructor(client: SONAClient | null, config?: Partial<SONAIntegrationConfig>);
|
|
30
|
-
get isEnabled(): boolean;
|
|
31
|
-
learnAnomalyPattern(anomaly: AnomalyDetection, baseline: TelemetryBaseline | undefined): Promise<void>;
|
|
32
|
-
learnBaselineShift(deviceId: string, oldBaseline: TelemetryBaseline | undefined, newBaseline: TelemetryBaseline): Promise<void>;
|
|
33
|
-
recordTelemetryTrajectory(deviceId: string, readings: TelemetryReading[], anomalies: AnomalyDetection[]): Promise<void>;
|
|
34
|
-
predictAnomalyRisk(reading: TelemetryReading): Promise<{
|
|
35
|
-
risk: string;
|
|
36
|
-
confidence: number;
|
|
37
|
-
} | null>;
|
|
38
|
-
findSimilarAnomalyPatterns(anomaly: AnomalyDetection, limit?: number): Promise<Array<{
|
|
39
|
-
key: string;
|
|
40
|
-
pattern: Record<string, unknown>;
|
|
41
|
-
score: number;
|
|
42
|
-
}>>;
|
|
43
|
-
}
|
|
44
|
-
//# sourceMappingURL=sona-integration-service.d.ts.map
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
export class SONAIntegrationService {
|
|
2
|
-
config;
|
|
3
|
-
client;
|
|
4
|
-
constructor(client, config) {
|
|
5
|
-
this.client = client;
|
|
6
|
-
this.config = {
|
|
7
|
-
enabled: config?.enabled ?? (client !== null),
|
|
8
|
-
trajectoryNamespace: config?.trajectoryNamespace ?? 'iot-trajectories',
|
|
9
|
-
patternNamespace: config?.patternNamespace ?? 'iot-patterns',
|
|
10
|
-
minConfidence: config?.minConfidence ?? 0.6,
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
get isEnabled() {
|
|
14
|
-
return this.config.enabled && this.client !== null;
|
|
15
|
-
}
|
|
16
|
-
async learnAnomalyPattern(anomaly, baseline) {
|
|
17
|
-
if (!this.isEnabled || !this.client)
|
|
18
|
-
return;
|
|
19
|
-
await this.client.storePattern(`anomaly:${anomaly.type}:${anomaly.deviceId}`, {
|
|
20
|
-
type: anomaly.type,
|
|
21
|
-
score: anomaly.score,
|
|
22
|
-
action: anomaly.suggestedAction,
|
|
23
|
-
deviceId: anomaly.deviceId,
|
|
24
|
-
baselineSamples: baseline?.sampleCount ?? 0,
|
|
25
|
-
timestamp: new Date().toISOString(),
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
async learnBaselineShift(deviceId, oldBaseline, newBaseline) {
|
|
29
|
-
if (!this.isEnabled || !this.client)
|
|
30
|
-
return;
|
|
31
|
-
const drift = oldBaseline
|
|
32
|
-
? newBaseline.meanVector.map((v, i) => Math.abs(v - oldBaseline.meanVector[i]))
|
|
33
|
-
: newBaseline.meanVector.map(() => 0);
|
|
34
|
-
await this.client.storePattern(`baseline-shift:${deviceId}`, {
|
|
35
|
-
deviceId,
|
|
36
|
-
driftVector: drift,
|
|
37
|
-
maxDrift: Math.max(...drift),
|
|
38
|
-
oldSamples: oldBaseline?.sampleCount ?? 0,
|
|
39
|
-
newSamples: newBaseline.sampleCount,
|
|
40
|
-
timestamp: new Date().toISOString(),
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
async recordTelemetryTrajectory(deviceId, readings, anomalies) {
|
|
44
|
-
if (!this.isEnabled || !this.client)
|
|
45
|
-
return;
|
|
46
|
-
const steps = readings.map((r) => {
|
|
47
|
-
const anomaly = anomalies.find((a) => a.readingId === r.readingId);
|
|
48
|
-
return {
|
|
49
|
-
action: anomaly ? `anomaly:${anomaly.type}` : 'normal',
|
|
50
|
-
reward: anomaly ? -anomaly.score : 1.0,
|
|
51
|
-
state: {
|
|
52
|
-
vector: r.vector,
|
|
53
|
-
anomalyScore: r.anomalyScore,
|
|
54
|
-
deviceId: r.deviceId,
|
|
55
|
-
},
|
|
56
|
-
};
|
|
57
|
-
});
|
|
58
|
-
const trajectoryId = `${this.config.trajectoryNamespace}:${deviceId}:${Date.now()}`;
|
|
59
|
-
await this.client.trainTrajectory(trajectoryId, steps);
|
|
60
|
-
}
|
|
61
|
-
async predictAnomalyRisk(reading) {
|
|
62
|
-
if (!this.isEnabled || !this.client)
|
|
63
|
-
return null;
|
|
64
|
-
const result = await this.client.predict({
|
|
65
|
-
vector: reading.vector,
|
|
66
|
-
deviceId: reading.deviceId,
|
|
67
|
-
anomalyScore: reading.anomalyScore,
|
|
68
|
-
});
|
|
69
|
-
if (result.confidence < this.config.minConfidence)
|
|
70
|
-
return null;
|
|
71
|
-
return { risk: result.prediction, confidence: result.confidence };
|
|
72
|
-
}
|
|
73
|
-
async findSimilarAnomalyPatterns(anomaly, limit = 5) {
|
|
74
|
-
if (!this.isEnabled || !this.client)
|
|
75
|
-
return [];
|
|
76
|
-
return this.client.searchPatterns(`anomaly:${anomaly.type} score:${anomaly.score.toFixed(2)}`, limit);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
//# sourceMappingURL=sona-integration-service.js.map
|
package/v3/@swarmdo/plugin-iot-cognitum/dist/domain/services/telemetry-ingestion-service.d.ts
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import type { TelemetryReading, AnomalyDetection } from '../entities/index.js';
|
|
2
|
-
import type { AnomalyDetectionService, TelemetryBaseline } from './anomaly-detection-service.js';
|
|
3
|
-
export interface TelemetryIngestionDeps {
|
|
4
|
-
queryDeviceStore: (deviceId: string, vector: number[], k: number) => Promise<Array<{
|
|
5
|
-
id: number | string;
|
|
6
|
-
distance: number;
|
|
7
|
-
metadata?: Record<string, unknown>;
|
|
8
|
-
}>>;
|
|
9
|
-
getStoreStatus: (deviceId: string) => Promise<{
|
|
10
|
-
total_vectors: number;
|
|
11
|
-
dimension: number;
|
|
12
|
-
}>;
|
|
13
|
-
}
|
|
14
|
-
export interface IngestionResult {
|
|
15
|
-
deviceId: string;
|
|
16
|
-
readingsProcessed: number;
|
|
17
|
-
anomaliesDetected: number;
|
|
18
|
-
anomalies: AnomalyDetection[];
|
|
19
|
-
baseline?: TelemetryBaseline;
|
|
20
|
-
}
|
|
21
|
-
export declare class TelemetryIngestionService {
|
|
22
|
-
private readonly deps;
|
|
23
|
-
private readonly anomalyDetector;
|
|
24
|
-
constructor(deps: TelemetryIngestionDeps, anomalyDetector: AnomalyDetectionService);
|
|
25
|
-
/**
|
|
26
|
-
* Process a batch of telemetry readings: run anomaly detection on each,
|
|
27
|
-
* and return the results.
|
|
28
|
-
*/
|
|
29
|
-
processBatch(deviceId: string, readings: TelemetryReading[]): IngestionResult;
|
|
30
|
-
/**
|
|
31
|
-
* Compute or refresh the baseline for a device from its recent readings.
|
|
32
|
-
*/
|
|
33
|
-
refreshBaseline(deviceId: string, readings: TelemetryReading[]): TelemetryBaseline;
|
|
34
|
-
/** Get the current baseline for a device. */
|
|
35
|
-
getBaseline(deviceId: string): TelemetryBaseline | undefined;
|
|
36
|
-
}
|
|
37
|
-
//# sourceMappingURL=telemetry-ingestion-service.d.ts.map
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
export class TelemetryIngestionService {
|
|
2
|
-
deps;
|
|
3
|
-
anomalyDetector;
|
|
4
|
-
constructor(deps, anomalyDetector) {
|
|
5
|
-
this.deps = deps;
|
|
6
|
-
this.anomalyDetector = anomalyDetector;
|
|
7
|
-
}
|
|
8
|
-
/**
|
|
9
|
-
* Process a batch of telemetry readings: run anomaly detection on each,
|
|
10
|
-
* and return the results.
|
|
11
|
-
*/
|
|
12
|
-
processBatch(deviceId, readings) {
|
|
13
|
-
const anomalies = [];
|
|
14
|
-
for (const reading of readings) {
|
|
15
|
-
const detection = this.anomalyDetector.detect(reading);
|
|
16
|
-
if (this.anomalyDetector.isAnomalous(detection)) {
|
|
17
|
-
anomalies.push(detection);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
return {
|
|
21
|
-
deviceId,
|
|
22
|
-
readingsProcessed: readings.length,
|
|
23
|
-
anomaliesDetected: anomalies.length,
|
|
24
|
-
anomalies,
|
|
25
|
-
baseline: this.anomalyDetector.getBaseline(deviceId),
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Compute or refresh the baseline for a device from its recent readings.
|
|
30
|
-
*/
|
|
31
|
-
refreshBaseline(deviceId, readings) {
|
|
32
|
-
return this.anomalyDetector.computeBaseline(deviceId, readings);
|
|
33
|
-
}
|
|
34
|
-
/** Get the current baseline for a device. */
|
|
35
|
-
getBaseline(deviceId) {
|
|
36
|
-
return this.anomalyDetector.getBaseline(deviceId);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
//# sourceMappingURL=telemetry-ingestion-service.js.map
|