/** * PatternRecognition -- frequency, clustering, correlation, sequence and trend * analysis over event and metric data the caller supplies. * * WHAT WAS HERE: all eight published operations returned * `{ success: true, data: { result: " completed successfully" } }` * with a hard-coded `confidence: 0.85`, having read none of their input. The * tool was wired into the server and listed in tools/list with no test. * * TWO CONSEQUENCES FOR THE SHAPE OF THIS FILE, the same two that * smart-summarization now carries: * * 1. `confidence` is gone. Every operation here has a real statistic to report * instead -- a share, an r, a p-value, an inertia -- and those are numbers a * caller can recompute from their own data. A single invented number that * stands for all of them cannot be checked against anything. * * 2. An operation whose inputs are absent REFUSES, naming the missing key. * * There is no pattern library and no model: every figure is computed from the * array passed in, by analytics-core, whose own refusals name each method's * minimum sample size. */ import type { CacheEngine } from '../../core/cache-engine.js'; import type { TokenCounter } from '../../core/token-counter.js'; import type { MetricsCollector } from '../../core/metrics.js'; import { EXPORT_FORMATS, type BarRow, type ExportFormat } from './render-core.js'; /** * The operations, in one place: the TS union and the published enum are both * derived from this array, so they cannot drift apart. */ export declare const PATTERN_RECOGNITION_OPERATIONS: readonly ["detect-patterns", "cluster-events", "find-correlations", "mine-sequences", "identify-trends", "compare-patterns", "visualize", "export"]; export type PatternRecognitionOperation = (typeof PATTERN_RECOGNITION_OPERATIONS)[number]; /** The chart kinds `visualize` draws, each with its own required input. */ export declare const PATTERN_CHARTS: readonly ["sparkline", "bars"]; export type PatternChart = (typeof PATTERN_CHARTS)[number]; export { EXPORT_FORMATS, type ExportFormat }; /** * Defaults, collected so all of them are visible at once. Each is a * presentation or reproducibility choice, never a stand-in for missing data: * `seed` fixes k-means++ so two identical calls cluster identically, and * `minOccurrences` is 2 because a run seen once is not a pattern. */ export declare const PATTERN_RECOGNITION_DEFAULTS: Readonly<{ minOccurrences: 2; seed: 1; maxLag: 12; topPatterns: 20; }>; export interface PatternRecognitionOptions { operation: PatternRecognitionOperation; /** detect-patterns, mine-sequences: the event stream, in order. */ events?: string[]; /** cluster-events: one numeric feature vector per event. */ points?: number[][]; /** cluster-events: a name per point, same order; reported with its cluster. */ labels?: string[]; k?: number; seed?: number; /** find-correlations: named metric series, all of equal length. */ series?: Record; /** identify-trends: one metric series, in time order. */ values?: number[]; maxLag?: number; /** mine-sequences. */ length?: number; minOccurrences?: number; /** detect-patterns. */ topPatterns?: number; /** compare-patterns: two event streams. */ before?: string[]; after?: string[]; /** visualize. */ chart?: PatternChart; bars?: BarRow[]; /** export. */ format?: ExportFormat; payload?: unknown; useCache?: boolean; } export interface PatternRecognitionResult { success: boolean; operation: string; data: Record; metadata: { tokensUsed: number; tokensSaved: number; cacheHit: boolean; processingTime: number; }; } export declare class PatternRecognition { private cache; private tokenCounter; private metricsCollector; constructor(cache: CacheEngine, tokenCounter: TokenCounter, metricsCollector: MetricsCollector); run(options: PatternRecognitionOptions): Promise; /** * One branch per published operation, each naming the operation it performs. * No fall-through: a value added to the published enum without an * implementation here reaches the default and is refused, instead of being * silently serviced as whichever branch happened to be last. */ private compute; /** * Which events recur, and how concentrated the stream is. `repeated` is the * subset seen more than once: a value seen once is an observation, not a * pattern, and reporting it as one is what made the old `detect-patterns` * return a finding for every call. */ private detectPatterns; private clusterEvents; /** * Pearson's r for every pair of named series, strongest first. Every pair is * reported, including the weak ones: a function that returned only the * correlations above some cutoff would be answering "what correlates" with a * threshold the caller never chose. */ private findCorrelations; private mineEventSequences; /** * Two different questions, so two different tests: Mann-Kendall for "is this * trending", which is a rank test and assumes neither normality nor * linearity, and a least-squares fit for "by how much per step". A seasonal * lag is reported when the series is long enough to have one. */ private identifyTrends; /** * How the mix of events changed between two streams. Shares rather than * counts, so two streams of different length are comparable, plus the * Jaccard overlap of the two distinct-event sets. */ private comparePatterns; private visualize; private exportPayload; } export declare const PATTERNRECOGNITIONTOOL: { readonly name: "pattern-recognition"; readonly description: "Frequency, clustering, correlation, sequence and trend analysis over event and metric arrays you supply"; readonly inputSchema: { readonly type: "object"; readonly properties: { readonly operation: { readonly type: "string"; readonly enum: readonly ["detect-patterns", "cluster-events", "find-correlations", "mine-sequences", "identify-trends", "compare-patterns", "visualize", "export"]; readonly description: "Operation to perform"; }; readonly events: { readonly type: "array"; readonly items: { readonly type: "string"; }; readonly minItems: 1; readonly description: "Event stream in order, for detect-patterns and mine-sequences"; }; readonly points: { readonly type: "array"; readonly items: { readonly type: "array"; readonly items: { readonly type: "number"; }; readonly minItems: 1; }; readonly minItems: 1; readonly description: "One numeric feature vector per event, for cluster-events"; }; readonly labels: { readonly type: "array"; readonly items: { readonly type: "string"; }; readonly description: "A name per point, same order, reported with its cluster"; }; readonly k: { readonly type: "integer"; readonly minimum: 1; readonly description: "Number of clusters to seek; cannot exceed the point count"; }; readonly seed: { readonly type: "integer"; readonly default: 1; readonly description: "Seeds k-means++ so an identical call clusters identically"; }; readonly series: { readonly type: "object"; readonly additionalProperties: { readonly type: "array"; readonly items: { readonly type: "number"; }; }; readonly description: "Named metric series of equal length, for find-correlations"; }; readonly values: { readonly type: "array"; readonly items: { readonly type: "number"; }; readonly minItems: 1; readonly description: "One metric series in time order, for identify-trends and the sparkline"; }; readonly maxLag: { readonly type: "integer"; readonly minimum: 1; readonly default: 12; readonly description: "Highest lag identify-trends searches for a season"; }; readonly length: { readonly type: "integer"; readonly minimum: 1; readonly description: "Subsequence length mine-sequences counts"; }; readonly minOccurrences: { readonly type: "integer"; readonly minimum: 2; readonly default: 2; readonly description: "Occurrences before a run counts as a sequence"; }; readonly topPatterns: { readonly type: "integer"; readonly minimum: 1; readonly default: 20; readonly description: "How many frequency rows detect-patterns returns"; }; readonly before: { readonly type: "array"; readonly items: { readonly type: "string"; }; readonly minItems: 1; readonly description: "Earlier event stream, for compare-patterns"; }; readonly after: { readonly type: "array"; readonly items: { readonly type: "string"; }; readonly minItems: 1; readonly description: "Later event stream, for compare-patterns"; }; readonly chart: { readonly type: "string"; readonly enum: readonly ["sparkline", "bars"]; readonly description: "Which chart visualize draws"; }; readonly bars: { readonly type: "array"; readonly items: { readonly type: "object"; readonly properties: { readonly label: { readonly type: "string"; }; readonly value: { readonly type: "number"; }; }; readonly required: readonly ["label", "value"]; readonly additionalProperties: false; }; readonly minItems: 1; readonly description: "Rows for the bars chart"; }; readonly format: { readonly type: "string"; readonly enum: readonly ["markdown", "json", "csv"]; readonly description: "Output format for export"; }; readonly payload: { readonly description: "The document export renders"; }; readonly useCache: { readonly type: "boolean"; readonly default: true; readonly description: "Enable caching"; }; }; readonly required: readonly ["operation"]; readonly anyOf: readonly [{ readonly properties: { readonly operation: { readonly const: "detect-patterns"; }; }; readonly required: readonly ["operation", "events"]; }, { readonly properties: { readonly operation: { readonly const: "cluster-events"; }; }; readonly required: readonly ["operation", "points", "k"]; }, { readonly properties: { readonly operation: { readonly const: "find-correlations"; }; }; readonly required: readonly ["operation", "series"]; }, { readonly properties: { readonly operation: { readonly const: "mine-sequences"; }; }; readonly required: readonly ["operation", "events", "length"]; }, { readonly properties: { readonly operation: { readonly const: "identify-trends"; }; }; readonly required: readonly ["operation", "values"]; }, { readonly properties: { readonly operation: { readonly const: "compare-patterns"; }; }; readonly required: readonly ["operation", "before", "after"]; }, { readonly properties: { readonly operation: { readonly const: "visualize"; }; readonly chart: { readonly const: "sparkline"; }; }; readonly required: readonly ["operation", "chart", "values"]; }, { readonly properties: { readonly operation: { readonly const: "visualize"; }; readonly chart: { readonly const: "bars"; }; }; readonly required: readonly ["operation", "chart", "bars"]; }, { readonly properties: { readonly operation: { readonly const: "export"; }; }; readonly required: readonly ["operation", "format", "payload"]; }]; }; }; export declare function runPatternRecognition(options: PatternRecognitionOptions): Promise; //# sourceMappingURL=pattern-recognition.d.ts.map