@lssm/lib.observability 0.2.2 → 0.4.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.
Files changed (48) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/README.md +11 -0
  3. package/package.json +9 -6
  4. package/.turbo/turbo-build.log +0 -92
  5. package/.turbo/turbo-lint.log +0 -20
  6. package/dist/anomaly/alert-manager.d.mts.map +0 -1
  7. package/dist/anomaly/alert-manager.mjs.map +0 -1
  8. package/dist/anomaly/anomaly-detector.d.mts.map +0 -1
  9. package/dist/anomaly/anomaly-detector.mjs.map +0 -1
  10. package/dist/anomaly/baseline-calculator.d.mts.map +0 -1
  11. package/dist/anomaly/baseline-calculator.mjs.map +0 -1
  12. package/dist/anomaly/root-cause-analyzer.d.mts.map +0 -1
  13. package/dist/anomaly/root-cause-analyzer.mjs.map +0 -1
  14. package/dist/intent/aggregator.d.mts.map +0 -1
  15. package/dist/intent/aggregator.mjs.map +0 -1
  16. package/dist/intent/detector.d.mts.map +0 -1
  17. package/dist/intent/detector.mjs.map +0 -1
  18. package/dist/lifecycle/dist/types/axes.mjs.map +0 -1
  19. package/dist/lifecycle/dist/types/stages.mjs.map +0 -1
  20. package/dist/lifecycle/dist/utils/formatters.mjs.map +0 -1
  21. package/dist/logging/index.d.mts.map +0 -1
  22. package/dist/logging/index.mjs.map +0 -1
  23. package/dist/metrics/index.d.mts.map +0 -1
  24. package/dist/metrics/index.mjs.map +0 -1
  25. package/dist/pipeline/evolution-pipeline.d.mts.map +0 -1
  26. package/dist/pipeline/evolution-pipeline.mjs.map +0 -1
  27. package/dist/pipeline/lifecycle-pipeline.d.mts.map +0 -1
  28. package/dist/pipeline/lifecycle-pipeline.mjs.map +0 -1
  29. package/dist/tracing/index.d.mts.map +0 -1
  30. package/dist/tracing/index.mjs.map +0 -1
  31. package/dist/tracing/middleware.d.mts.map +0 -1
  32. package/dist/tracing/middleware.mjs.map +0 -1
  33. package/src/anomaly/alert-manager.ts +0 -31
  34. package/src/anomaly/anomaly-detector.ts +0 -94
  35. package/src/anomaly/baseline-calculator.ts +0 -54
  36. package/src/anomaly/root-cause-analyzer.ts +0 -55
  37. package/src/index.ts +0 -47
  38. package/src/intent/aggregator.ts +0 -161
  39. package/src/intent/detector.ts +0 -187
  40. package/src/logging/index.ts +0 -56
  41. package/src/metrics/index.ts +0 -53
  42. package/src/pipeline/evolution-pipeline.ts +0 -90
  43. package/src/pipeline/lifecycle-pipeline.ts +0 -105
  44. package/src/tracing/index.ts +0 -61
  45. package/src/tracing/middleware.ts +0 -111
  46. package/tsconfig.json +0 -16
  47. package/tsconfig.tsbuildinfo +0 -1
  48. package/tsdown.config.js +0 -6
@@ -1,55 +0,0 @@
1
- import type { AnomalySignal } from './anomaly-detector';
2
-
3
- export interface DeploymentEvent {
4
- id: string;
5
- operation: string;
6
- deployedAt: Date;
7
- stage?: string;
8
- status: 'in_progress' | 'completed' | 'rolled_back';
9
- }
10
-
11
- export interface RootCauseAnalysis {
12
- signal: AnomalySignal;
13
- culprit?: DeploymentEvent;
14
- notes: string[];
15
- }
16
-
17
- export class RootCauseAnalyzer {
18
- constructor(private readonly lookbackMs: number = 15 * 60 * 1000) {}
19
-
20
- analyze(
21
- signal: AnomalySignal,
22
- deployments: DeploymentEvent[]
23
- ): RootCauseAnalysis {
24
- const windowStart = new Date(
25
- signal.point.timestamp.getTime() - this.lookbackMs
26
- );
27
- const candidates = deployments
28
- .filter((deployment) => deployment.deployedAt >= windowStart)
29
- .sort((a, b) => b.deployedAt.getTime() - a.deployedAt.getTime());
30
-
31
- const notes: string[] = [];
32
- let culprit: DeploymentEvent | undefined;
33
-
34
- if (candidates.length > 0) {
35
- culprit = candidates[0]!;
36
- notes.push(
37
- `Closest deployment ${culprit.id} (${culprit.operation}) at ${culprit.deployedAt.toISOString()}`
38
- );
39
- } else {
40
- notes.push('No deployments found within lookback window.');
41
- }
42
-
43
- if (signal.type === 'latency_regression') {
44
- notes.push(
45
- 'Verify recent schema changes and external dependency latency.'
46
- );
47
- }
48
-
49
- if (signal.type === 'error_rate_spike') {
50
- notes.push('Check SLO monitor for correlated incidents.');
51
- }
52
-
53
- return { signal, culprit, notes };
54
- }
55
- }
package/src/index.ts DELETED
@@ -1,47 +0,0 @@
1
- export { getTracer, traceAsync, traceSync } from './tracing';
2
- export {
3
- getMeter,
4
- createCounter,
5
- createUpDownCounter,
6
- createHistogram,
7
- standardMetrics,
8
- } from './metrics';
9
- export { Logger, logger } from './logging';
10
- export {
11
- createTracingMiddleware,
12
- type TracingMiddlewareOptions,
13
- } from './tracing/middleware';
14
- export {
15
- IntentAggregator,
16
- type IntentAggregatorSnapshot,
17
- type TelemetrySample,
18
- } from './intent/aggregator';
19
- export {
20
- IntentDetector,
21
- type IntentSignal,
22
- type IntentSignalType,
23
- } from './intent/detector';
24
- export {
25
- EvolutionPipeline,
26
- type EvolutionPipelineEvent,
27
- type EvolutionPipelineOptions,
28
- } from './pipeline/evolution-pipeline';
29
- export {
30
- LifecycleKpiPipeline,
31
- type LifecycleKpiPipelineOptions,
32
- type LifecyclePipelineEvent,
33
- } from './pipeline/lifecycle-pipeline';
34
-
35
- export type { LogLevel, LogEntry } from './logging';
36
-
37
- export { BaselineCalculator } from './anomaly/baseline-calculator';
38
- export {
39
- AnomalyDetector,
40
- type AnomalySignal,
41
- type AnomalyThresholds,
42
- } from './anomaly/anomaly-detector';
43
- export {
44
- RootCauseAnalyzer,
45
- type RootCauseAnalysis,
46
- } from './anomaly/root-cause-analyzer';
47
- export { AlertManager } from './anomaly/alert-manager';
@@ -1,161 +0,0 @@
1
- export interface TelemetrySample {
2
- operation: { name: string; version: number };
3
- durationMs: number;
4
- success: boolean;
5
- timestamp: Date;
6
- errorCode?: string;
7
- tenantId?: string;
8
- traceId?: string;
9
- actorId?: string;
10
- metadata?: Record<string, unknown>;
11
- }
12
-
13
- export interface AggregatedOperationMetrics {
14
- operation: { name: string; version: number };
15
- totalCalls: number;
16
- successRate: number;
17
- errorRate: number;
18
- averageLatencyMs: number;
19
- p95LatencyMs: number;
20
- p99LatencyMs: number;
21
- maxLatencyMs: number;
22
- windowStart: Date;
23
- windowEnd: Date;
24
- topErrors: Record<string, number>;
25
- }
26
-
27
- export interface OperationSequence {
28
- steps: string[];
29
- tenantId?: string;
30
- count: number;
31
- }
32
-
33
- export interface IntentAggregatorSnapshot {
34
- metrics: AggregatedOperationMetrics[];
35
- sequences: OperationSequence[];
36
- sampleCount: number;
37
- windowStart?: Date;
38
- windowEnd?: Date;
39
- }
40
-
41
- export interface IntentAggregatorOptions {
42
- windowMs?: number;
43
- sequenceSampleSize?: number;
44
- }
45
-
46
- const DEFAULT_WINDOW_MS = 15 * 60 * 1000; // 15 minutes
47
-
48
- export class IntentAggregator {
49
- private readonly windowMs: number;
50
- private readonly sequenceSampleSize: number;
51
- private readonly samples: TelemetrySample[] = [];
52
-
53
- constructor(options: IntentAggregatorOptions = {}) {
54
- this.windowMs = options.windowMs ?? DEFAULT_WINDOW_MS;
55
- this.sequenceSampleSize = options.sequenceSampleSize ?? 1000;
56
- }
57
-
58
- add(sample: TelemetrySample) {
59
- this.samples.push(sample);
60
- }
61
-
62
- flush(now = new Date()): IntentAggregatorSnapshot {
63
- const minTimestamp = now.getTime() - this.windowMs;
64
- const windowSamples = this.samples.filter(
65
- (sample) => sample.timestamp.getTime() >= minTimestamp
66
- );
67
- this.samples.length = 0;
68
- const metrics = this.aggregateMetrics(windowSamples);
69
- const sequences = this.buildSequences(windowSamples);
70
- const timestamps = windowSamples.map((sample) =>
71
- sample.timestamp.getTime()
72
- );
73
- return {
74
- metrics,
75
- sequences,
76
- sampleCount: windowSamples.length,
77
- windowStart: timestamps.length
78
- ? new Date(Math.min(...timestamps))
79
- : undefined,
80
- windowEnd: timestamps.length
81
- ? new Date(Math.max(...timestamps))
82
- : undefined,
83
- };
84
- }
85
-
86
- private aggregateMetrics(samples: TelemetrySample[]) {
87
- if (!samples.length) return [] as AggregatedOperationMetrics[];
88
- const groups = new Map<string, TelemetrySample[]>();
89
- for (const sample of samples) {
90
- const key = `${sample.operation.name}.v${sample.operation.version}`;
91
- const arr = groups.get(key) ?? [];
92
- arr.push(sample);
93
- groups.set(key, arr);
94
- }
95
-
96
- return [...groups.values()].map((group) => {
97
- const durations = group.map((s) => s.durationMs).sort((a, b) => a - b);
98
- const errors = group.filter((s) => !s.success);
99
- const totalCalls = group.length;
100
- const topErrors = errors.reduce<Record<string, number>>((acc, sample) => {
101
- if (!sample.errorCode) return acc;
102
- acc[sample.errorCode] = (acc[sample.errorCode] ?? 0) + 1;
103
- return acc;
104
- }, {});
105
- const timestamps = group.map((s) => s.timestamp.getTime());
106
- return {
107
- operation: group[0]!.operation,
108
- totalCalls,
109
- successRate: (totalCalls - errors.length) / totalCalls,
110
- errorRate: errors.length / totalCalls,
111
- averageLatencyMs:
112
- durations.reduce((sum, value) => sum + value, 0) / totalCalls,
113
- p95LatencyMs: percentile(durations, 0.95),
114
- p99LatencyMs: percentile(durations, 0.99),
115
- maxLatencyMs: Math.max(...durations),
116
- windowStart: new Date(Math.min(...timestamps)),
117
- windowEnd: new Date(Math.max(...timestamps)),
118
- topErrors,
119
- } satisfies AggregatedOperationMetrics;
120
- });
121
- }
122
-
123
- private buildSequences(samples: TelemetrySample[]): OperationSequence[] {
124
- const byTrace = new Map<string, TelemetrySample[]>();
125
- for (const sample of samples.slice(-this.sequenceSampleSize)) {
126
- if (!sample.traceId) continue;
127
- const arr = byTrace.get(sample.traceId) ?? [];
128
- arr.push(sample);
129
- byTrace.set(sample.traceId, arr);
130
- }
131
-
132
- const sequences: Record<string, OperationSequence> = {};
133
- for (const [traceId, events] of byTrace.entries()) {
134
- const ordered = events.sort(
135
- (a, b) => a.timestamp.getTime() - b.timestamp.getTime()
136
- );
137
- const steps = ordered.map((event) => event.operation.name);
138
- if (steps.length < 2) continue;
139
- const key = `${steps.join('>')}@${ordered[0]?.tenantId ?? 'global'}`;
140
- const existing = sequences[key];
141
- if (existing) {
142
- existing.count += 1;
143
- } else {
144
- sequences[key] = {
145
- steps,
146
- tenantId: ordered[0]?.tenantId,
147
- count: 1,
148
- };
149
- }
150
- }
151
-
152
- return Object.values(sequences).sort((a, b) => b.count - a.count);
153
- }
154
- }
155
-
156
- function percentile(values: number[], ratio: number) {
157
- if (!values.length) return 0;
158
- if (values.length === 1) return values[0]!;
159
- const index = Math.min(values.length - 1, Math.floor(ratio * values.length));
160
- return values[index]!;
161
- }
@@ -1,187 +0,0 @@
1
- import { randomUUID } from 'node:crypto';
2
- import type {
3
- AggregatedOperationMetrics,
4
- OperationSequence,
5
- } from './aggregator';
6
-
7
- export type IntentSignalType =
8
- | 'latency-regression'
9
- | 'error-spike'
10
- | 'throughput-drop'
11
- | 'missing-workflow-step';
12
-
13
- export interface IntentSignal {
14
- id: string;
15
- type: IntentSignalType;
16
- operation?: AggregatedOperationMetrics['operation'];
17
- confidence: number;
18
- description: string;
19
- metadata?: Record<string, unknown>;
20
- evidence: {
21
- type: 'metric' | 'sequence' | 'anomaly';
22
- description: string;
23
- data?: Record<string, unknown>;
24
- }[];
25
- }
26
-
27
- export interface IntentDetectorOptions {
28
- errorRateThreshold?: number;
29
- latencyP99ThresholdMs?: number;
30
- throughputDropThreshold?: number;
31
- minSequenceLength?: number;
32
- }
33
-
34
- const DEFAULTS = {
35
- errorRateThreshold: 0.05,
36
- latencyP99ThresholdMs: 750,
37
- throughputDropThreshold: 0.3,
38
- minSequenceLength: 3,
39
- };
40
-
41
- export class IntentDetector {
42
- private readonly options: Required<IntentDetectorOptions>;
43
-
44
- constructor(options: IntentDetectorOptions = {}) {
45
- this.options = {
46
- errorRateThreshold:
47
- options.errorRateThreshold ?? DEFAULTS.errorRateThreshold,
48
- latencyP99ThresholdMs:
49
- options.latencyP99ThresholdMs ?? DEFAULTS.latencyP99ThresholdMs,
50
- throughputDropThreshold:
51
- options.throughputDropThreshold ?? DEFAULTS.throughputDropThreshold,
52
- minSequenceLength:
53
- options.minSequenceLength ?? DEFAULTS.minSequenceLength,
54
- };
55
- }
56
-
57
- detectFromMetrics(
58
- current: AggregatedOperationMetrics[],
59
- previous?: AggregatedOperationMetrics[]
60
- ): IntentSignal[] {
61
- const signals: IntentSignal[] = [];
62
- const baseline = new Map(
63
- (previous ?? []).map((metric) => [
64
- `${metric.operation.name}.v${metric.operation.version}`,
65
- metric,
66
- ])
67
- );
68
-
69
- for (const metric of current) {
70
- if (metric.errorRate >= this.options.errorRateThreshold) {
71
- signals.push({
72
- id: randomUUID(),
73
- type: 'error-spike',
74
- operation: metric.operation,
75
- confidence: Math.min(
76
- 1,
77
- metric.errorRate / this.options.errorRateThreshold
78
- ),
79
- description: `Error rate ${metric.errorRate.toFixed(2)} exceeded threshold`,
80
- metadata: {
81
- errorRate: metric.errorRate,
82
- topErrors: metric.topErrors,
83
- },
84
- evidence: [
85
- {
86
- type: 'metric',
87
- description: 'error-rate',
88
- data: {
89
- errorRate: metric.errorRate,
90
- threshold: this.options.errorRateThreshold,
91
- },
92
- },
93
- ],
94
- });
95
- continue;
96
- }
97
-
98
- if (metric.p99LatencyMs >= this.options.latencyP99ThresholdMs) {
99
- signals.push({
100
- id: randomUUID(),
101
- type: 'latency-regression',
102
- operation: metric.operation,
103
- confidence: Math.min(
104
- 1,
105
- metric.p99LatencyMs / this.options.latencyP99ThresholdMs
106
- ),
107
- description: `P99 latency ${metric.p99LatencyMs}ms exceeded threshold`,
108
- metadata: { p99LatencyMs: metric.p99LatencyMs },
109
- evidence: [
110
- {
111
- type: 'metric',
112
- description: 'p99-latency',
113
- data: {
114
- p99LatencyMs: metric.p99LatencyMs,
115
- threshold: this.options.latencyP99ThresholdMs,
116
- },
117
- },
118
- ],
119
- });
120
- continue;
121
- }
122
-
123
- const base = baseline.get(
124
- `${metric.operation.name}.v${metric.operation.version}`
125
- );
126
- if (base) {
127
- const drop =
128
- (base.totalCalls - metric.totalCalls) / Math.max(base.totalCalls, 1);
129
- if (drop >= this.options.throughputDropThreshold) {
130
- signals.push({
131
- id: randomUUID(),
132
- type: 'throughput-drop',
133
- operation: metric.operation,
134
- confidence: Math.min(
135
- 1,
136
- drop / this.options.throughputDropThreshold
137
- ),
138
- description: `Throughput dropped ${(drop * 100).toFixed(1)}% vs baseline`,
139
- metadata: {
140
- baselineCalls: base.totalCalls,
141
- currentCalls: metric.totalCalls,
142
- },
143
- evidence: [
144
- {
145
- type: 'metric',
146
- description: 'throughput-drop',
147
- data: {
148
- baselineCalls: base.totalCalls,
149
- currentCalls: metric.totalCalls,
150
- },
151
- },
152
- ],
153
- });
154
- }
155
- }
156
- }
157
-
158
- return signals;
159
- }
160
-
161
- detectSequentialIntents(sequences: OperationSequence[]): IntentSignal[] {
162
- const signals: IntentSignal[] = [];
163
- for (const sequence of sequences) {
164
- if (sequence.steps.length < this.options.minSequenceLength) continue;
165
- const description = sequence.steps.join(' → ');
166
- signals.push({
167
- id: randomUUID(),
168
- type: 'missing-workflow-step',
169
- confidence: 0.6,
170
- description: `Repeated workflow detected: ${description}`,
171
- metadata: {
172
- steps: sequence.steps,
173
- tenantId: sequence.tenantId,
174
- occurrences: sequence.count,
175
- },
176
- evidence: [
177
- {
178
- type: 'sequence',
179
- description: 'sequential-calls',
180
- data: { steps: sequence.steps, count: sequence.count },
181
- },
182
- ],
183
- });
184
- }
185
- return signals;
186
- }
187
- }
@@ -1,56 +0,0 @@
1
- import { trace, context } from '@opentelemetry/api';
2
-
3
- export type LogLevel = 'debug' | 'info' | 'warn' | 'error';
4
-
5
- export interface LogEntry {
6
- level: LogLevel;
7
- message: string;
8
- [key: string]: unknown;
9
- }
10
-
11
- export class Logger {
12
- constructor(private readonly serviceName: string) {}
13
-
14
- private log(
15
- level: LogLevel,
16
- message: string,
17
- meta: Record<string, unknown> = {}
18
- ) {
19
- const span = trace.getSpan(context.active());
20
- const traceId = span?.spanContext().traceId;
21
- const spanId = span?.spanContext().spanId;
22
-
23
- const entry: LogEntry = {
24
- timestamp: new Date().toISOString(),
25
- service: this.serviceName,
26
- level,
27
- message,
28
- traceId,
29
- spanId,
30
- ...meta,
31
- };
32
-
33
- // structured logging to stdout
34
- console.log(JSON.stringify(entry));
35
- }
36
-
37
- debug(message: string, meta?: Record<string, unknown>) {
38
- this.log('debug', message, meta);
39
- }
40
-
41
- info(message: string, meta?: Record<string, unknown>) {
42
- this.log('info', message, meta);
43
- }
44
-
45
- warn(message: string, meta?: Record<string, unknown>) {
46
- this.log('warn', message, meta);
47
- }
48
-
49
- error(message: string, meta?: Record<string, unknown>) {
50
- this.log('error', message, meta);
51
- }
52
- }
53
-
54
- export const logger = new Logger(
55
- process.env.OTEL_SERVICE_NAME || 'unknown-service'
56
- );
@@ -1,53 +0,0 @@
1
- import {
2
- metrics,
3
- type Meter,
4
- type Counter,
5
- type Histogram,
6
- type UpDownCounter,
7
- } from '@opentelemetry/api';
8
-
9
- const DEFAULT_METER_NAME = '@lssm/lib.observability';
10
-
11
- export function getMeter(name: string = DEFAULT_METER_NAME): Meter {
12
- return metrics.getMeter(name);
13
- }
14
-
15
- export function createCounter(
16
- name: string,
17
- description?: string,
18
- meterName?: string
19
- ): Counter {
20
- return getMeter(meterName).createCounter(name, { description });
21
- }
22
-
23
- export function createUpDownCounter(
24
- name: string,
25
- description?: string,
26
- meterName?: string
27
- ): UpDownCounter {
28
- return getMeter(meterName).createUpDownCounter(name, { description });
29
- }
30
-
31
- export function createHistogram(
32
- name: string,
33
- description?: string,
34
- meterName?: string
35
- ): Histogram {
36
- return getMeter(meterName).createHistogram(name, { description });
37
- }
38
-
39
- export const standardMetrics = {
40
- httpRequests: createCounter('http_requests_total', 'Total HTTP requests'),
41
- httpDuration: createHistogram(
42
- 'http_request_duration_seconds',
43
- 'HTTP request duration'
44
- ),
45
- operationErrors: createCounter(
46
- 'operation_errors_total',
47
- 'Total operation errors'
48
- ),
49
- workflowDuration: createHistogram(
50
- 'workflow_duration_seconds',
51
- 'Workflow execution duration'
52
- ),
53
- };
@@ -1,90 +0,0 @@
1
- import { EventEmitter } from 'node:events';
2
- import {
3
- IntentAggregator,
4
- type IntentAggregatorSnapshot,
5
- type TelemetrySample,
6
- } from '../intent/aggregator';
7
- import { IntentDetector, type IntentSignal } from '../intent/detector';
8
-
9
- export type EvolutionPipelineEvent =
10
- | { type: 'intent.detected'; payload: IntentSignal }
11
- | { type: 'telemetry.window'; payload: { sampleCount: number } };
12
-
13
- export interface EvolutionPipelineOptions {
14
- detector?: IntentDetector;
15
- aggregator?: IntentAggregator;
16
- emitter?: EventEmitter;
17
- onIntent?: (intent: IntentSignal) => Promise<void> | void;
18
- onSnapshot?: (snapshot: IntentAggregatorSnapshot) => Promise<void> | void;
19
- }
20
-
21
- export class EvolutionPipeline {
22
- private readonly detector: IntentDetector;
23
- private readonly aggregator: IntentAggregator;
24
- private readonly emitter: EventEmitter;
25
- private readonly onIntent?: (intent: IntentSignal) => Promise<void> | void;
26
- private readonly onSnapshot?: (
27
- snapshot: IntentAggregatorSnapshot
28
- ) => Promise<void> | void;
29
- private timer?: NodeJS.Timeout;
30
- private previousMetrics?: ReturnType<IntentAggregator['flush']>['metrics'];
31
-
32
- constructor(options: EvolutionPipelineOptions = {}) {
33
- this.detector = options.detector ?? new IntentDetector();
34
- this.aggregator = options.aggregator ?? new IntentAggregator();
35
- this.emitter = options.emitter ?? new EventEmitter();
36
- this.onIntent = options.onIntent;
37
- this.onSnapshot = options.onSnapshot;
38
- }
39
-
40
- ingest(sample: TelemetrySample) {
41
- this.aggregator.add(sample);
42
- }
43
-
44
- on(listener: (event: EvolutionPipelineEvent) => void) {
45
- this.emitter.on('event', listener);
46
- }
47
-
48
- start(intervalMs = 5 * 60 * 1000) {
49
- this.stop();
50
- this.timer = setInterval(() => {
51
- void this.run();
52
- }, intervalMs);
53
- }
54
-
55
- stop() {
56
- if (this.timer) {
57
- clearInterval(this.timer);
58
- this.timer = undefined;
59
- }
60
- }
61
-
62
- async run() {
63
- const snapshot = this.aggregator.flush();
64
- this.emit({
65
- type: 'telemetry.window',
66
- payload: { sampleCount: snapshot.sampleCount },
67
- });
68
- if (this.onSnapshot) await this.onSnapshot(snapshot);
69
- if (!snapshot.sampleCount) return;
70
-
71
- const metricSignals = this.detector.detectFromMetrics(
72
- snapshot.metrics,
73
- this.previousMetrics
74
- );
75
- const sequenceSignals = this.detector.detectSequentialIntents(
76
- snapshot.sequences
77
- );
78
- this.previousMetrics = snapshot.metrics;
79
-
80
- const signals = [...metricSignals, ...sequenceSignals];
81
- for (const signal of signals) {
82
- if (this.onIntent) await this.onIntent(signal);
83
- this.emit({ type: 'intent.detected', payload: signal });
84
- }
85
- }
86
-
87
- private emit(event: EvolutionPipelineEvent) {
88
- this.emitter.emit('event', event);
89
- }
90
- }