swarmdo 1.4.8 → 1.6.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 +9 -6
- package/package.json +5 -3
- package/v3/@swarmdo/cli/dist/src/commands/compact.d.ts +16 -0
- package/v3/@swarmdo/cli/dist/src/commands/compact.js +106 -0
- package/v3/@swarmdo/cli/dist/src/commands/hooks.js +26 -24
- package/v3/@swarmdo/cli/dist/src/commands/index.js +10 -3
- 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 +241 -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/compact/compact.d.ts +60 -0
- package/v3/@swarmdo/cli/dist/src/compact/compact.js +170 -0
- package/v3/@swarmdo/cli/dist/src/config-lint/lint.js +11 -1
- package/v3/@swarmdo/cli/dist/src/index.js +4 -2
- 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
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
export { DeviceTrustLevel, getDeviceTrustLabel, } from './device-trust-level.js';
|
|
2
|
-
export type { DeviceStatus, DeviceCapability, DeviceTrustScore, VectorStoreStats, DeviceAgent, } from './device-agent.js';
|
|
3
|
-
export type { FleetTopology, DeploymentStrategy, FirmwarePolicy, TelemetryPolicy, HealthThresholds, DeviceFleet, } from './device-fleet.js';
|
|
4
|
-
export type { AnomalyType, AnomalyAction, TelemetryReading, AnomalyDetection, } from './telemetry.js';
|
|
5
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
export type AnomalyType = 'drift' | 'spike' | 'flatline' | 'oscillation' | 'pattern-break' | 'cluster-outlier';
|
|
2
|
-
export type AnomalyAction = 'log' | 'alert' | 'quarantine' | 'recalibrate' | 'rollback-firmware' | 'human-review';
|
|
3
|
-
/**
|
|
4
|
-
* A single telemetry reading from a Cognitum Seed device.
|
|
5
|
-
*/
|
|
6
|
-
export interface TelemetryReading {
|
|
7
|
-
readingId: string;
|
|
8
|
-
deviceId: string;
|
|
9
|
-
fleetId: string;
|
|
10
|
-
timestamp: Date;
|
|
11
|
-
/** Embedding vector for similarity search. */
|
|
12
|
-
vector: number[];
|
|
13
|
-
/** Raw sensor metrics keyed by metric name. */
|
|
14
|
-
rawMetrics: Record<string, number>;
|
|
15
|
-
/** Anomaly score, 0.0 (normal) - 1.0 (anomalous). */
|
|
16
|
-
anomalyScore: number;
|
|
17
|
-
metadata: Record<string, unknown>;
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Result of anomaly detection on a telemetry reading.
|
|
21
|
-
*/
|
|
22
|
-
export interface AnomalyDetection {
|
|
23
|
-
readingId: string;
|
|
24
|
-
deviceId: string;
|
|
25
|
-
/** Anomaly score, 0.0 - 1.0. */
|
|
26
|
-
score: number;
|
|
27
|
-
type: AnomalyType;
|
|
28
|
-
/** Detection confidence, 0.0 - 1.0. */
|
|
29
|
-
confidence: number;
|
|
30
|
-
/** Identifier of the baseline pattern this was compared against. */
|
|
31
|
-
baselinePattern?: string;
|
|
32
|
-
suggestedAction: AnomalyAction;
|
|
33
|
-
metadata: Record<string, unknown>;
|
|
34
|
-
}
|
|
35
|
-
//# sourceMappingURL=telemetry.d.ts.map
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { DeviceAgent } from '../entities/index.js';
|
|
2
|
-
export interface DeviceRepository {
|
|
3
|
-
save(device: DeviceAgent): Promise<void>;
|
|
4
|
-
findById(deviceId: string): Promise<DeviceAgent | null>;
|
|
5
|
-
findByFleet(fleetId: string): Promise<DeviceAgent[]>;
|
|
6
|
-
findByZone(zoneId: string): Promise<DeviceAgent[]>;
|
|
7
|
-
findAll(): Promise<DeviceAgent[]>;
|
|
8
|
-
delete(deviceId: string): Promise<boolean>;
|
|
9
|
-
count(): Promise<number>;
|
|
10
|
-
}
|
|
11
|
-
//# sourceMappingURL=device-repository.d.ts.map
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { DeviceFleet } from '../entities/index.js';
|
|
2
|
-
export interface FleetRepository {
|
|
3
|
-
save(fleet: DeviceFleet): Promise<void>;
|
|
4
|
-
findById(fleetId: string): Promise<DeviceFleet | undefined>;
|
|
5
|
-
findAll(): Promise<DeviceFleet[]>;
|
|
6
|
-
delete(fleetId: string): Promise<boolean>;
|
|
7
|
-
count(): Promise<number>;
|
|
8
|
-
}
|
|
9
|
-
//# sourceMappingURL=fleet-repository.d.ts.map
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
export type { DeviceRepository } from './device-repository.js';
|
|
2
|
-
export type { TrustHistoryEntry, TrustHistoryRepository, } from './trust-history-repository.js';
|
|
3
|
-
export type { FleetRepository } from './fleet-repository.js';
|
|
4
|
-
export type { TelemetryRepository } from './telemetry-repository.js';
|
|
5
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { TelemetryReading, AnomalyDetection } from '../entities/telemetry.js';
|
|
2
|
-
export interface TelemetryRepository {
|
|
3
|
-
store(reading: TelemetryReading): Promise<void>;
|
|
4
|
-
storeBatch(readings: TelemetryReading[]): Promise<number>;
|
|
5
|
-
findByDevice(deviceId: string, limit?: number): Promise<TelemetryReading[]>;
|
|
6
|
-
searchSimilar(vector: number[], k: number, deviceId?: string): Promise<TelemetryReading[]>;
|
|
7
|
-
storeAnomaly(anomaly: AnomalyDetection): Promise<void>;
|
|
8
|
-
findAnomalies(deviceId: string, limit?: number): Promise<AnomalyDetection[]>;
|
|
9
|
-
count(deviceId?: string): Promise<number>;
|
|
10
|
-
deleteByDevice(deviceId: string): Promise<number>;
|
|
11
|
-
}
|
|
12
|
-
//# sourceMappingURL=telemetry-repository.d.ts.map
|
package/v3/@swarmdo/plugin-iot-cognitum/dist/domain/repositories/trust-history-repository.d.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { DeviceTrustLevel } from '../entities/index.js';
|
|
2
|
-
import type { DeviceTrustScore } from '../entities/index.js';
|
|
3
|
-
export interface TrustHistoryEntry {
|
|
4
|
-
deviceId: string;
|
|
5
|
-
timestamp: Date;
|
|
6
|
-
oldLevel: DeviceTrustLevel;
|
|
7
|
-
newLevel: DeviceTrustLevel;
|
|
8
|
-
score: DeviceTrustScore;
|
|
9
|
-
/** What caused the change: 'registration', 'pair', 'unpair', 'refresh', 'probe'. */
|
|
10
|
-
trigger: string;
|
|
11
|
-
}
|
|
12
|
-
export interface TrustHistoryRepository {
|
|
13
|
-
append(entry: TrustHistoryEntry): Promise<void>;
|
|
14
|
-
findByDevice(deviceId: string, limit?: number): Promise<TrustHistoryEntry[]>;
|
|
15
|
-
findByLevel(level: DeviceTrustLevel): Promise<TrustHistoryEntry[]>;
|
|
16
|
-
deleteByDevice(deviceId: string): Promise<number>;
|
|
17
|
-
count(): Promise<number>;
|
|
18
|
-
}
|
|
19
|
-
//# sourceMappingURL=trust-history-repository.d.ts.map
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import type { TelemetryReading, AnomalyDetection } from '../entities/index.js';
|
|
2
|
-
export interface AnomalyDetectionConfig {
|
|
3
|
-
/** Score threshold above which a reading is anomalous. Default 0.7. */
|
|
4
|
-
anomalyThreshold: number;
|
|
5
|
-
/** Score threshold for quarantine action. Default 0.9. */
|
|
6
|
-
quarantineThreshold: number;
|
|
7
|
-
/** Window size for baseline computation. */
|
|
8
|
-
baselineWindowSize: number;
|
|
9
|
-
}
|
|
10
|
-
export interface TelemetryBaseline {
|
|
11
|
-
deviceId: string;
|
|
12
|
-
/** Mean vector across the baseline window. */
|
|
13
|
-
meanVector: number[];
|
|
14
|
-
/** Standard deviation per dimension. */
|
|
15
|
-
stdVector: number[];
|
|
16
|
-
/** Number of readings in the baseline. */
|
|
17
|
-
sampleCount: number;
|
|
18
|
-
/** When the baseline was last computed. */
|
|
19
|
-
computedAt: Date;
|
|
20
|
-
}
|
|
21
|
-
export declare class AnomalyDetectionService {
|
|
22
|
-
private readonly config;
|
|
23
|
-
private readonly baselines;
|
|
24
|
-
constructor(config?: Partial<AnomalyDetectionConfig>);
|
|
25
|
-
/**
|
|
26
|
-
* Compute a baseline from a window of readings for a device.
|
|
27
|
-
* Calculates mean and standard deviation per vector dimension.
|
|
28
|
-
*/
|
|
29
|
-
computeBaseline(deviceId: string, readings: TelemetryReading[]): TelemetryBaseline;
|
|
30
|
-
/** Get the current baseline for a device, if one has been computed. */
|
|
31
|
-
getBaseline(deviceId: string): TelemetryBaseline | undefined;
|
|
32
|
-
/**
|
|
33
|
-
* Detect anomalies in a reading by comparing against the device's baseline.
|
|
34
|
-
* Uses z-score based detection: how many standard deviations each dimension
|
|
35
|
-
* deviates from the baseline mean.
|
|
36
|
-
*/
|
|
37
|
-
detect(reading: TelemetryReading): AnomalyDetection;
|
|
38
|
-
/** Classify an anomaly type based on the z-score pattern. */
|
|
39
|
-
private classifyAnomaly;
|
|
40
|
-
private suggestAction;
|
|
41
|
-
/** Check whether a detection result exceeds the anomaly threshold. */
|
|
42
|
-
isAnomalous(detection: AnomalyDetection): boolean;
|
|
43
|
-
}
|
|
44
|
-
//# sourceMappingURL=anomaly-detection-service.d.ts.map
|
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
export class AnomalyDetectionService {
|
|
2
|
-
config;
|
|
3
|
-
baselines = new Map();
|
|
4
|
-
constructor(config) {
|
|
5
|
-
this.config = {
|
|
6
|
-
anomalyThreshold: config?.anomalyThreshold ?? 0.7,
|
|
7
|
-
quarantineThreshold: config?.quarantineThreshold ?? 0.9,
|
|
8
|
-
baselineWindowSize: config?.baselineWindowSize ?? 100,
|
|
9
|
-
};
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* Compute a baseline from a window of readings for a device.
|
|
13
|
-
* Calculates mean and standard deviation per vector dimension.
|
|
14
|
-
*/
|
|
15
|
-
computeBaseline(deviceId, readings) {
|
|
16
|
-
if (readings.length === 0)
|
|
17
|
-
throw new Error('Cannot compute baseline from empty readings');
|
|
18
|
-
const dim = readings[0].vector.length;
|
|
19
|
-
const n = readings.length;
|
|
20
|
-
// Compute mean
|
|
21
|
-
const mean = new Array(dim).fill(0);
|
|
22
|
-
for (const r of readings) {
|
|
23
|
-
for (let i = 0; i < dim; i++)
|
|
24
|
-
mean[i] += r.vector[i] / n;
|
|
25
|
-
}
|
|
26
|
-
// Compute standard deviation
|
|
27
|
-
const std = new Array(dim).fill(0);
|
|
28
|
-
for (const r of readings) {
|
|
29
|
-
for (let i = 0; i < dim; i++) {
|
|
30
|
-
const diff = r.vector[i] - mean[i];
|
|
31
|
-
std[i] += (diff * diff) / n;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
for (let i = 0; i < dim; i++)
|
|
35
|
-
std[i] = Math.sqrt(std[i]);
|
|
36
|
-
const baseline = {
|
|
37
|
-
deviceId,
|
|
38
|
-
meanVector: mean,
|
|
39
|
-
stdVector: std,
|
|
40
|
-
sampleCount: n,
|
|
41
|
-
computedAt: new Date(),
|
|
42
|
-
};
|
|
43
|
-
this.baselines.set(deviceId, baseline);
|
|
44
|
-
return baseline;
|
|
45
|
-
}
|
|
46
|
-
/** Get the current baseline for a device, if one has been computed. */
|
|
47
|
-
getBaseline(deviceId) {
|
|
48
|
-
return this.baselines.get(deviceId);
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Detect anomalies in a reading by comparing against the device's baseline.
|
|
52
|
-
* Uses z-score based detection: how many standard deviations each dimension
|
|
53
|
-
* deviates from the baseline mean.
|
|
54
|
-
*/
|
|
55
|
-
detect(reading) {
|
|
56
|
-
const baseline = this.baselines.get(reading.deviceId);
|
|
57
|
-
if (!baseline) {
|
|
58
|
-
return {
|
|
59
|
-
readingId: reading.readingId,
|
|
60
|
-
deviceId: reading.deviceId,
|
|
61
|
-
score: 0,
|
|
62
|
-
type: 'drift',
|
|
63
|
-
confidence: 0,
|
|
64
|
-
suggestedAction: 'log',
|
|
65
|
-
metadata: { reason: 'no-baseline' },
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
// Z-score per dimension
|
|
69
|
-
const zScores = reading.vector.map((v, i) => {
|
|
70
|
-
const s = baseline.stdVector[i];
|
|
71
|
-
return s > 0 ? Math.abs(v - baseline.meanVector[i]) / s : 0;
|
|
72
|
-
});
|
|
73
|
-
const maxZ = Math.max(...zScores);
|
|
74
|
-
const meanZ = zScores.reduce((a, b) => a + b, 0) / zScores.length;
|
|
75
|
-
// Composite anomaly score (0-1): 3 std devs maps to score 1.0
|
|
76
|
-
const score = Math.min(1, meanZ / 3);
|
|
77
|
-
const type = this.classifyAnomaly(reading, zScores, maxZ);
|
|
78
|
-
const suggestedAction = this.suggestAction(score);
|
|
79
|
-
const confidence = Math.min(1, baseline.sampleCount / this.config.baselineWindowSize);
|
|
80
|
-
return {
|
|
81
|
-
readingId: reading.readingId,
|
|
82
|
-
deviceId: reading.deviceId,
|
|
83
|
-
score,
|
|
84
|
-
type,
|
|
85
|
-
confidence,
|
|
86
|
-
baselinePattern: `baseline-${reading.deviceId}`,
|
|
87
|
-
suggestedAction,
|
|
88
|
-
metadata: { maxZ, meanZ, baselineSamples: baseline.sampleCount },
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
/** Classify an anomaly type based on the z-score pattern. */
|
|
92
|
-
classifyAnomaly(reading, zScores, maxZ) {
|
|
93
|
-
const highZCount = zScores.filter((z) => z > 2).length;
|
|
94
|
-
const allLow = zScores.every((z) => z < 0.5);
|
|
95
|
-
if (maxZ > 5)
|
|
96
|
-
return 'spike';
|
|
97
|
-
if (allLow && reading.rawMetrics && Object.values(reading.rawMetrics).every((v) => v === 0))
|
|
98
|
-
return 'flatline';
|
|
99
|
-
if (highZCount > zScores.length * 0.5)
|
|
100
|
-
return 'cluster-outlier';
|
|
101
|
-
if (highZCount > 0 && highZCount <= 2)
|
|
102
|
-
return 'drift';
|
|
103
|
-
return 'pattern-break';
|
|
104
|
-
}
|
|
105
|
-
suggestAction(score) {
|
|
106
|
-
if (score >= this.config.quarantineThreshold)
|
|
107
|
-
return 'quarantine';
|
|
108
|
-
if (score >= this.config.anomalyThreshold)
|
|
109
|
-
return 'alert';
|
|
110
|
-
return 'log';
|
|
111
|
-
}
|
|
112
|
-
/** Check whether a detection result exceeds the anomaly threshold. */
|
|
113
|
-
isAnomalous(detection) {
|
|
114
|
-
return detection.score >= this.config.anomalyThreshold;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
//# sourceMappingURL=anomaly-detection-service.js.map
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import type { DeviceAgent, DeviceTrustScore } from '../entities/index.js';
|
|
2
|
-
import { DeviceTrustLevel } from '../entities/index.js';
|
|
3
|
-
export interface DeviceLifecycleDeps {
|
|
4
|
-
getStatus: (deviceId: string) => Promise<{
|
|
5
|
-
device_id: string;
|
|
6
|
-
uptime_secs: number;
|
|
7
|
-
epoch: number;
|
|
8
|
-
total_vectors: number;
|
|
9
|
-
dimension: number;
|
|
10
|
-
paired: boolean;
|
|
11
|
-
roles: string[];
|
|
12
|
-
witness_chain_length?: number;
|
|
13
|
-
}>;
|
|
14
|
-
getIdentity: (deviceId: string) => Promise<{
|
|
15
|
-
device_id: string;
|
|
16
|
-
public_key?: string;
|
|
17
|
-
firmware_version?: string;
|
|
18
|
-
epoch?: number;
|
|
19
|
-
}>;
|
|
20
|
-
getPairStatus: (deviceId: string) => Promise<{
|
|
21
|
-
paired: boolean;
|
|
22
|
-
client_count?: number;
|
|
23
|
-
}>;
|
|
24
|
-
getWitnessChain: (deviceId: string) => Promise<{
|
|
25
|
-
depth: number;
|
|
26
|
-
epoch: number;
|
|
27
|
-
head_hash: string;
|
|
28
|
-
}>;
|
|
29
|
-
getCustodyEpoch: (deviceId: string) => Promise<{
|
|
30
|
-
epoch: number;
|
|
31
|
-
}>;
|
|
32
|
-
pairDevice: (deviceId: string, clientName: string) => Promise<{
|
|
33
|
-
paired: boolean;
|
|
34
|
-
token?: string;
|
|
35
|
-
}>;
|
|
36
|
-
unpairDevice: (deviceId: string, clientName?: string) => Promise<void>;
|
|
37
|
-
onDeviceRegistered?: (device: DeviceAgent) => void;
|
|
38
|
-
onTrustChange?: (deviceId: string, oldLevel: DeviceTrustLevel, newLevel: DeviceTrustLevel) => void;
|
|
39
|
-
}
|
|
40
|
-
export declare class DeviceLifecycleService {
|
|
41
|
-
private readonly deps;
|
|
42
|
-
constructor(deps: DeviceLifecycleDeps);
|
|
43
|
-
/**
|
|
44
|
-
* Register a new device by fetching its status and identity, then
|
|
45
|
-
* constructing a DeviceAgent entity with initial trust REGISTERED.
|
|
46
|
-
*/
|
|
47
|
-
registerDevice(endpoint: string, fleetId: string, zoneId: string): Promise<DeviceAgent>;
|
|
48
|
-
/**
|
|
49
|
-
* Pair a device using the SDK's pair.create() and promote its trust level.
|
|
50
|
-
*/
|
|
51
|
-
pairDevice(device: DeviceAgent, clientName: string): Promise<DeviceAgent>;
|
|
52
|
-
/**
|
|
53
|
-
* Unpair a device and demote its trust level.
|
|
54
|
-
*/
|
|
55
|
-
unpairDevice(device: DeviceAgent): Promise<DeviceAgent>;
|
|
56
|
-
/**
|
|
57
|
-
* Re-fetch all device state and recalculate trust.
|
|
58
|
-
*/
|
|
59
|
-
refreshDeviceState(device: DeviceAgent): Promise<DeviceAgent>;
|
|
60
|
-
/**
|
|
61
|
-
* Compute a composite trust score from device telemetry signals.
|
|
62
|
-
*/
|
|
63
|
-
computeTrustScore(device: DeviceAgent, witnessDepth: number, uptimeSecs: number, paired?: boolean): DeviceTrustScore;
|
|
64
|
-
/**
|
|
65
|
-
* Map a composite trust score to a discrete DeviceTrustLevel.
|
|
66
|
-
*/
|
|
67
|
-
evaluateTrustLevel(score: DeviceTrustScore): DeviceTrustLevel;
|
|
68
|
-
private deriveCapabilities;
|
|
69
|
-
}
|
|
70
|
-
//# sourceMappingURL=device-lifecycle-service.d.ts.map
|
|
@@ -1,194 +0,0 @@
|
|
|
1
|
-
import { DeviceTrustLevel } from '../entities/index.js';
|
|
2
|
-
// ---------------------------------------------------------------------------
|
|
3
|
-
// Service
|
|
4
|
-
// ---------------------------------------------------------------------------
|
|
5
|
-
export class DeviceLifecycleService {
|
|
6
|
-
deps;
|
|
7
|
-
constructor(deps) {
|
|
8
|
-
this.deps = deps;
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* Register a new device by fetching its status and identity, then
|
|
12
|
-
* constructing a DeviceAgent entity with initial trust REGISTERED.
|
|
13
|
-
*/
|
|
14
|
-
async registerDevice(endpoint, fleetId, zoneId) {
|
|
15
|
-
const status = await this.deps.getStatus(endpoint);
|
|
16
|
-
const identity = await this.deps.getIdentity(status.device_id);
|
|
17
|
-
const initialScore = this.computeTrustScore({}, status.witness_chain_length ?? 0, status.uptime_secs, status.paired);
|
|
18
|
-
const device = {
|
|
19
|
-
deviceId: status.device_id,
|
|
20
|
-
publicKey: identity.public_key ?? '',
|
|
21
|
-
firmwareVersion: identity.firmware_version ?? 'unknown',
|
|
22
|
-
trustLevel: DeviceTrustLevel.REGISTERED,
|
|
23
|
-
trustScore: initialScore,
|
|
24
|
-
fleetId,
|
|
25
|
-
zoneId,
|
|
26
|
-
status: 'online',
|
|
27
|
-
lastSeen: new Date(),
|
|
28
|
-
epoch: identity.epoch ?? status.epoch,
|
|
29
|
-
capabilities: this.deriveCapabilities(status.roles),
|
|
30
|
-
meshPeers: [],
|
|
31
|
-
vectorStoreStats: {
|
|
32
|
-
totalVectors: status.total_vectors,
|
|
33
|
-
deletedVectors: 0,
|
|
34
|
-
dimension: status.dimension,
|
|
35
|
-
fileSizeBytes: 0,
|
|
36
|
-
},
|
|
37
|
-
endpoint,
|
|
38
|
-
metadata: {},
|
|
39
|
-
};
|
|
40
|
-
this.deps.onDeviceRegistered?.(device);
|
|
41
|
-
return device;
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Pair a device using the SDK's pair.create() and promote its trust level.
|
|
45
|
-
*/
|
|
46
|
-
async pairDevice(device, clientName) {
|
|
47
|
-
const result = await this.deps.pairDevice(device.deviceId, clientName);
|
|
48
|
-
if (!result.paired) {
|
|
49
|
-
throw new Error(`Pairing failed for device ${device.deviceId}`);
|
|
50
|
-
}
|
|
51
|
-
const oldLevel = device.trustLevel;
|
|
52
|
-
const newLevel = device.trustLevel < DeviceTrustLevel.PROVISIONED
|
|
53
|
-
? DeviceTrustLevel.PROVISIONED
|
|
54
|
-
: device.trustLevel;
|
|
55
|
-
const updated = {
|
|
56
|
-
...device,
|
|
57
|
-
trustLevel: newLevel,
|
|
58
|
-
trustScore: {
|
|
59
|
-
...device.trustScore,
|
|
60
|
-
overall: this.computeTrustScore(device, 0, 0, true).overall,
|
|
61
|
-
components: {
|
|
62
|
-
...device.trustScore.components,
|
|
63
|
-
pairingIntegrity: 1.0,
|
|
64
|
-
},
|
|
65
|
-
},
|
|
66
|
-
};
|
|
67
|
-
if (oldLevel !== newLevel) {
|
|
68
|
-
this.deps.onTrustChange?.(device.deviceId, oldLevel, newLevel);
|
|
69
|
-
}
|
|
70
|
-
return updated;
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* Unpair a device and demote its trust level.
|
|
74
|
-
*/
|
|
75
|
-
async unpairDevice(device) {
|
|
76
|
-
await this.deps.unpairDevice(device.deviceId);
|
|
77
|
-
const oldLevel = device.trustLevel;
|
|
78
|
-
const newLevel = DeviceTrustLevel.REGISTERED;
|
|
79
|
-
const updated = {
|
|
80
|
-
...device,
|
|
81
|
-
trustLevel: newLevel,
|
|
82
|
-
trustScore: {
|
|
83
|
-
...device.trustScore,
|
|
84
|
-
overall: this.computeTrustScore(device, 0, 0, false).overall,
|
|
85
|
-
components: {
|
|
86
|
-
...device.trustScore.components,
|
|
87
|
-
pairingIntegrity: 0.0,
|
|
88
|
-
},
|
|
89
|
-
},
|
|
90
|
-
};
|
|
91
|
-
if (oldLevel !== newLevel) {
|
|
92
|
-
this.deps.onTrustChange?.(device.deviceId, oldLevel, newLevel);
|
|
93
|
-
}
|
|
94
|
-
return updated;
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* Re-fetch all device state and recalculate trust.
|
|
98
|
-
*/
|
|
99
|
-
async refreshDeviceState(device) {
|
|
100
|
-
const [status, identity, pair, witness] = await Promise.all([
|
|
101
|
-
this.deps.getStatus(device.deviceId),
|
|
102
|
-
this.deps.getIdentity(device.deviceId),
|
|
103
|
-
this.deps.getPairStatus(device.deviceId),
|
|
104
|
-
this.deps.getWitnessChain(device.deviceId),
|
|
105
|
-
]);
|
|
106
|
-
const updated = {
|
|
107
|
-
...device,
|
|
108
|
-
publicKey: identity.public_key ?? device.publicKey,
|
|
109
|
-
firmwareVersion: identity.firmware_version ?? device.firmwareVersion,
|
|
110
|
-
epoch: identity.epoch ?? status.epoch,
|
|
111
|
-
lastSeen: new Date(),
|
|
112
|
-
status: 'online',
|
|
113
|
-
vectorStoreStats: {
|
|
114
|
-
...device.vectorStoreStats,
|
|
115
|
-
totalVectors: status.total_vectors,
|
|
116
|
-
dimension: status.dimension,
|
|
117
|
-
},
|
|
118
|
-
capabilities: this.deriveCapabilities(status.roles),
|
|
119
|
-
};
|
|
120
|
-
const score = this.computeTrustScore({ ...updated, trustScore: device.trustScore }, witness.depth, status.uptime_secs, pair.paired);
|
|
121
|
-
const newLevel = this.evaluateTrustLevel(score);
|
|
122
|
-
const oldLevel = device.trustLevel;
|
|
123
|
-
updated.trustScore = score;
|
|
124
|
-
updated.trustLevel = newLevel;
|
|
125
|
-
if (oldLevel !== newLevel) {
|
|
126
|
-
this.deps.onTrustChange?.(device.deviceId, oldLevel, newLevel);
|
|
127
|
-
}
|
|
128
|
-
return updated;
|
|
129
|
-
}
|
|
130
|
-
/**
|
|
131
|
-
* Compute a composite trust score from device telemetry signals.
|
|
132
|
-
*/
|
|
133
|
-
computeTrustScore(device, witnessDepth, uptimeSecs, paired) {
|
|
134
|
-
const SEVEN_DAYS_SECS = 604_800;
|
|
135
|
-
const EXPECTED_WITNESS_DEPTH = 10_000;
|
|
136
|
-
const pairingIntegrity = paired !== undefined
|
|
137
|
-
? (paired ? 1.0 : 0.0)
|
|
138
|
-
: (device.trustScore?.components?.pairingIntegrity ?? 0.0);
|
|
139
|
-
const firmwareCurrency = 1.0; // Hardcoded — version comparison TBD
|
|
140
|
-
const uptimeStability = Math.min(1.0, uptimeSecs / SEVEN_DAYS_SECS);
|
|
141
|
-
const witnessIntegrity = Math.min(1.0, witnessDepth / EXPECTED_WITNESS_DEPTH);
|
|
142
|
-
const anomalyHistory = 1.0; // No anomaly detection yet
|
|
143
|
-
const meshParticipation = 0.5; // Single device, no mesh peers
|
|
144
|
-
const overall = 0.3 * pairingIntegrity +
|
|
145
|
-
0.15 * firmwareCurrency +
|
|
146
|
-
0.2 * uptimeStability +
|
|
147
|
-
0.15 * witnessIntegrity +
|
|
148
|
-
0.1 * anomalyHistory +
|
|
149
|
-
0.1 * meshParticipation;
|
|
150
|
-
return {
|
|
151
|
-
overall,
|
|
152
|
-
components: {
|
|
153
|
-
pairingIntegrity,
|
|
154
|
-
firmwareCurrency,
|
|
155
|
-
uptimeStability,
|
|
156
|
-
witnessIntegrity,
|
|
157
|
-
anomalyHistory,
|
|
158
|
-
meshParticipation,
|
|
159
|
-
},
|
|
160
|
-
};
|
|
161
|
-
}
|
|
162
|
-
/**
|
|
163
|
-
* Map a composite trust score to a discrete DeviceTrustLevel.
|
|
164
|
-
*/
|
|
165
|
-
evaluateTrustLevel(score) {
|
|
166
|
-
if (score.overall < 0.3)
|
|
167
|
-
return DeviceTrustLevel.UNKNOWN;
|
|
168
|
-
if (score.overall < 0.5)
|
|
169
|
-
return DeviceTrustLevel.REGISTERED;
|
|
170
|
-
if (score.overall < 0.7)
|
|
171
|
-
return DeviceTrustLevel.PROVISIONED;
|
|
172
|
-
if (score.overall < 0.85)
|
|
173
|
-
return DeviceTrustLevel.CERTIFIED;
|
|
174
|
-
return DeviceTrustLevel.FLEET_TRUSTED;
|
|
175
|
-
}
|
|
176
|
-
// ---------------------------------------------------------------------------
|
|
177
|
-
// Helpers
|
|
178
|
-
// ---------------------------------------------------------------------------
|
|
179
|
-
deriveCapabilities(roles) {
|
|
180
|
-
const CAP_MAP = {
|
|
181
|
-
'vector-store': 'vector-store',
|
|
182
|
-
ota: 'ota-update',
|
|
183
|
-
mesh: 'mesh-routing',
|
|
184
|
-
witness: 'witness-chain',
|
|
185
|
-
sensor: 'sensor-telemetry',
|
|
186
|
-
compute: 'edge-compute',
|
|
187
|
-
mcp: 'mcp-server',
|
|
188
|
-
};
|
|
189
|
-
return roles
|
|
190
|
-
.map((r) => CAP_MAP[r])
|
|
191
|
-
.filter((c) => c != null);
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
//# sourceMappingURL=device-lifecycle-service.js.map
|
package/v3/@swarmdo/plugin-iot-cognitum/dist/domain/services/firmware-orchestration-service.d.ts
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import type { DeploymentStrategy, FirmwarePolicy } from '../entities/index.js';
|
|
2
|
-
export type RolloutStage = 'pending' | 'canary' | 'rolling' | 'complete' | 'rolled-back' | 'failed';
|
|
3
|
-
export interface FirmwareRollout {
|
|
4
|
-
rolloutId: string;
|
|
5
|
-
fleetId: string;
|
|
6
|
-
firmwareVersion: string;
|
|
7
|
-
strategy: DeploymentStrategy;
|
|
8
|
-
stage: RolloutStage;
|
|
9
|
-
targetDeviceIds: string[];
|
|
10
|
-
canaryDeviceIds: string[];
|
|
11
|
-
completedDeviceIds: string[];
|
|
12
|
-
failedDeviceIds: string[];
|
|
13
|
-
anomalyThreshold: number;
|
|
14
|
-
startedAt: Date;
|
|
15
|
-
updatedAt: Date;
|
|
16
|
-
completedAt?: Date;
|
|
17
|
-
}
|
|
18
|
-
export interface FirmwareOrchestrationDeps {
|
|
19
|
-
getDeviceFirmwareVersion: (deviceId: string) => Promise<string>;
|
|
20
|
-
deployFirmware: (deviceId: string, version: string) => Promise<{
|
|
21
|
-
success: boolean;
|
|
22
|
-
error?: string;
|
|
23
|
-
}>;
|
|
24
|
-
getDeviceAnomalyScore: (deviceId: string) => Promise<number>;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* State-machine-based firmware rollout engine.
|
|
28
|
-
*
|
|
29
|
-
* Lifecycle: pending -> canary -> rolling -> complete
|
|
30
|
-
* | |
|
|
31
|
-
* rolled-back failed
|
|
32
|
-
*/
|
|
33
|
-
export declare class FirmwareOrchestrationService {
|
|
34
|
-
private readonly deps;
|
|
35
|
-
private readonly rollouts;
|
|
36
|
-
private rolloutCounter;
|
|
37
|
-
constructor(deps: FirmwareOrchestrationDeps);
|
|
38
|
-
/**
|
|
39
|
-
* Create a new rollout. Canary devices are selected as the first N%
|
|
40
|
-
* of `targetDeviceIds` based on `policy.canaryPercentage`.
|
|
41
|
-
*/
|
|
42
|
-
createRollout(fleetId: string, firmwareVersion: string, targetDeviceIds: string[], policy: FirmwarePolicy): FirmwareRollout;
|
|
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
|
-
advanceRollout(rolloutId: string): Promise<FirmwareRollout>;
|
|
51
|
-
/**
|
|
52
|
-
* Force-rollback a rollout regardless of current stage.
|
|
53
|
-
*/
|
|
54
|
-
rollbackRollout(rolloutId: string): FirmwareRollout;
|
|
55
|
-
/**
|
|
56
|
-
* Retrieve a rollout by ID. Throws if not found.
|
|
57
|
-
*/
|
|
58
|
-
getRollout(rolloutId: string): FirmwareRollout;
|
|
59
|
-
/**
|
|
60
|
-
* List rollouts, optionally filtered by fleet ID.
|
|
61
|
-
*/
|
|
62
|
-
listRollouts(fleetId?: string): FirmwareRollout[];
|
|
63
|
-
private transitionPendingToCanary;
|
|
64
|
-
private transitionCanaryToNextStage;
|
|
65
|
-
private transitionRollingToComplete;
|
|
66
|
-
private deployToDevices;
|
|
67
|
-
private getExistingRollout;
|
|
68
|
-
}
|
|
69
|
-
//# sourceMappingURL=firmware-orchestration-service.d.ts.map
|