mcp-event-intelligence 0.3.1 → 0.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/CHANGELOG.md +81 -0
- package/README.md +123 -23
- package/SECURITY.md +4 -4
- package/bin/mcp-event-intelligence.mjs +3 -3
- package/dist/src/composite/engine.d.ts +6 -0
- package/dist/src/composite/engine.js +599 -10
- package/dist/src/composite/matching.d.ts +1 -1
- package/dist/src/composite/matching.js +66 -1
- package/dist/src/intelligenceProtocol/activationSchemas.d.ts +2 -0
- package/dist/src/intelligenceProtocol/activationSchemas.js +1 -0
- package/dist/src/intelligenceProtocol/index.d.ts +9 -2
- package/dist/src/intelligenceProtocol/index.js +5 -1
- package/dist/src/intelligenceProtocol/operatorRegistry.d.ts +567 -0
- package/dist/src/intelligenceProtocol/operatorRegistry.js +477 -0
- package/dist/src/intelligenceProtocol/patternV2Schemas.d.ts +188 -0
- package/dist/src/intelligenceProtocol/patternV2Schemas.js +801 -0
- package/dist/src/intelligenceProtocol/schemas.d.ts +6 -0
- package/dist/src/intelligenceProtocol/schemas.js +3 -0
- package/dist/src/intelligenceProtocol/triggerPlanSchemas.d.ts +179 -4
- package/dist/src/intelligenceProtocol/triggerPlanSchemas.js +38 -4
- package/dist/src/intelligenceProtocol/triggerSchemas.d.ts +262 -0
- package/dist/src/intelligenceProtocol/triggerSchemas.js +164 -2
- package/dist/src/mcpEvents/consumer.d.ts +2 -0
- package/dist/src/mcpEvents/consumer.js +2 -0
- package/dist/src/mcpEvents/erpnextProvider.d.ts +0 -2
- package/dist/src/mcpEvents/erpnextProvider.js +0 -3
- package/dist/src/mcpEvents/provider.d.ts +24 -10
- package/dist/src/mcpEvents/provider.js +124 -55
- package/dist/src/mcpEvents/server.d.ts +3 -1
- package/dist/src/mcpEvents/server.js +20 -19
- package/dist/src/patternV2/evaluator.d.ts +43 -0
- package/dist/src/patternV2/evaluator.js +927 -0
- package/dist/src/patternV2/legacyCompiler.d.ts +3 -0
- package/dist/src/patternV2/legacyCompiler.js +184 -0
- package/dist/src/protocol/types.d.ts +1 -0
- package/package.json +5 -2
- package/scripts/host-integration.d.mts +47 -0
- package/scripts/host-integration.mjs +9 -0
- package/scripts/lib/activation-hydrator.mjs +1 -0
- package/scripts/lib/composite-event-consumer.mjs +4 -0
- package/scripts/lib/derived-event-coordinator.mjs +75 -1
- package/scripts/lib/json-schema.mjs +134 -0
- package/scripts/lib/local-event-intelligence-runtime.mjs +1 -0
- package/scripts/lib/mcp-events-client.mjs +798 -253
- package/scripts/lib/mcp-events-compatibility.mjs +54 -0
- package/scripts/lib/persistent-event-store.mjs +68 -9
- package/scripts/lib/trigger-control-plane.mjs +180 -0
- package/scripts/lib/trigger-inspector.mjs +15 -0
- package/scripts/lib/trigger-planner.mjs +213 -12
- package/scripts/mcp-stdio-server.mjs +38 -52
- package/server.json +4 -4
|
@@ -9,6 +9,23 @@ function getByPath(source, path) {
|
|
|
9
9
|
}
|
|
10
10
|
return current;
|
|
11
11
|
}
|
|
12
|
+
function stableValue(value) {
|
|
13
|
+
if (Array.isArray(value))
|
|
14
|
+
return value.map(stableValue);
|
|
15
|
+
if (value && typeof value === 'object') {
|
|
16
|
+
return Object.fromEntries(Object.keys(value)
|
|
17
|
+
.sort()
|
|
18
|
+
.map((key) => [
|
|
19
|
+
key,
|
|
20
|
+
stableValue(value[key]),
|
|
21
|
+
]));
|
|
22
|
+
}
|
|
23
|
+
return value;
|
|
24
|
+
}
|
|
25
|
+
function sameSubscriptionArguments(left, right) {
|
|
26
|
+
return JSON.stringify(stableValue(left ?? {})) ===
|
|
27
|
+
JSON.stringify(stableValue(right ?? {}));
|
|
28
|
+
}
|
|
12
29
|
function scalarKey(value) {
|
|
13
30
|
if (typeof value === 'string' ||
|
|
14
31
|
typeof value === 'number' ||
|
|
@@ -29,10 +46,54 @@ function predicateMatches(event, predicate) {
|
|
|
29
46
|
if (Array.isArray(value))
|
|
30
47
|
return value.includes(predicate.value);
|
|
31
48
|
return false;
|
|
49
|
+
case 'startsWith':
|
|
50
|
+
return typeof value === 'string' && value.startsWith(predicate.value);
|
|
51
|
+
case 'endsWith':
|
|
52
|
+
return typeof value === 'string' && value.endsWith(predicate.value);
|
|
53
|
+
case 'regex':
|
|
54
|
+
if (typeof value !== 'string')
|
|
55
|
+
return false;
|
|
56
|
+
try {
|
|
57
|
+
return new RegExp(predicate.value, predicate.flags ?? '').test(value);
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
32
62
|
case 'in':
|
|
33
63
|
return predicate.value.includes(value);
|
|
64
|
+
case 'notIn':
|
|
65
|
+
return !predicate.value.includes(value);
|
|
66
|
+
case 'between': {
|
|
67
|
+
const [lower, upper] = predicate.value;
|
|
68
|
+
if (typeof value === 'number') {
|
|
69
|
+
return (typeof lower === 'number' &&
|
|
70
|
+
typeof upper === 'number' &&
|
|
71
|
+
value >= lower &&
|
|
72
|
+
value <= upper);
|
|
73
|
+
}
|
|
74
|
+
if (typeof value === 'string') {
|
|
75
|
+
return (typeof lower === 'string' &&
|
|
76
|
+
typeof upper === 'string' &&
|
|
77
|
+
value >= lower &&
|
|
78
|
+
value <= upper);
|
|
79
|
+
}
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
34
82
|
case 'exists':
|
|
35
83
|
return predicate.value ? value !== undefined : value === undefined;
|
|
84
|
+
case 'isNull':
|
|
85
|
+
return predicate.value
|
|
86
|
+
? value === null || value === undefined
|
|
87
|
+
: value !== null && value !== undefined;
|
|
88
|
+
case 'type':
|
|
89
|
+
if (predicate.value === 'null')
|
|
90
|
+
return value === null;
|
|
91
|
+
if (predicate.value === 'array')
|
|
92
|
+
return Array.isArray(value);
|
|
93
|
+
if (predicate.value === 'object') {
|
|
94
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
95
|
+
}
|
|
96
|
+
return typeof value === predicate.value;
|
|
36
97
|
case 'gt':
|
|
37
98
|
return typeof value === 'number' && value > predicate.value;
|
|
38
99
|
case 'gte':
|
|
@@ -47,6 +108,7 @@ export function clauseMatches(clause, event) {
|
|
|
47
108
|
const contractVersion = getByPath(event.data, '_derived.contractVersion');
|
|
48
109
|
return (clause.event === event.name &&
|
|
49
110
|
(!clause.serverId || clause.serverId === event.serverId) &&
|
|
111
|
+
sameSubscriptionArguments(clause.arguments, event.subscriptionArguments) &&
|
|
50
112
|
(!clause.contractVersion ||
|
|
51
113
|
String(contractVersion ?? '') === String(clause.contractVersion)) &&
|
|
52
114
|
clause.where.every((predicate) => predicateMatches(event, predicate)));
|
|
@@ -58,8 +120,10 @@ export function asSourceEvent(clauseId, event) {
|
|
|
58
120
|
sourceEventId: event.sourceEventId,
|
|
59
121
|
eventName: event.name,
|
|
60
122
|
occurredAt: event.occurredAt,
|
|
123
|
+
...(event.receivedAt ? { receivedAt: event.receivedAt } : {}),
|
|
61
124
|
...(event.provider ? { provider: event.provider } : {}),
|
|
62
125
|
...(event.serverId ? { serverId: event.serverId } : {}),
|
|
126
|
+
subscriptionArguments: event.subscriptionArguments ?? {},
|
|
63
127
|
...(event.payloadHash ? { payloadHash: event.payloadHash } : {}),
|
|
64
128
|
data: event.data,
|
|
65
129
|
};
|
|
@@ -108,7 +172,8 @@ export function deterministicKeyForClause(definition, clauseId, event) {
|
|
|
108
172
|
}
|
|
109
173
|
export function sameEventIdentity(source, event) {
|
|
110
174
|
return (source.sourceEventId === event.sourceEventId &&
|
|
111
|
-
(source.serverId ?? null) === (event.serverId ?? null)
|
|
175
|
+
(source.serverId ?? null) === (event.serverId ?? null) &&
|
|
176
|
+
sameSubscriptionArguments(source.subscriptionArguments, event.subscriptionArguments));
|
|
112
177
|
}
|
|
113
178
|
export function matchesCorrelationKey(record, key) {
|
|
114
179
|
if (record.correlationKey === null || key === null)
|
|
@@ -6,6 +6,7 @@ export declare const ActivationEvidenceSchema: z.ZodObject<{
|
|
|
6
6
|
eventName: z.ZodString;
|
|
7
7
|
traceId: z.ZodString;
|
|
8
8
|
occurredAt: z.ZodString;
|
|
9
|
+
receivedAt: z.ZodOptional<z.ZodString>;
|
|
9
10
|
payloadHash: z.ZodNullable<z.ZodString>;
|
|
10
11
|
data: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
11
12
|
}, z.core.$strict>;
|
|
@@ -54,6 +55,7 @@ export declare const ActivationEnvelopeSchema: z.ZodObject<{
|
|
|
54
55
|
eventName: z.ZodString;
|
|
55
56
|
traceId: z.ZodString;
|
|
56
57
|
occurredAt: z.ZodString;
|
|
58
|
+
receivedAt: z.ZodOptional<z.ZodString>;
|
|
57
59
|
payloadHash: z.ZodNullable<z.ZodString>;
|
|
58
60
|
data: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
59
61
|
}, z.core.$strict>>;
|
|
@@ -9,6 +9,7 @@ export const ActivationEvidenceSchema = z.object({
|
|
|
9
9
|
eventName: z.string().min(1),
|
|
10
10
|
traceId: Id,
|
|
11
11
|
occurredAt: Timestamp,
|
|
12
|
+
receivedAt: Timestamp.optional(),
|
|
12
13
|
payloadHash: z.string().regex(/^[a-f0-9]{64}$/).nullable(),
|
|
13
14
|
data: z.record(z.string(), z.unknown()).optional(),
|
|
14
15
|
}).strict();
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
export { PATTERN_AST_VERSION, PatternValueSelectorSchema, PatternArithmeticValueSchema, PatternCompareOperatorSchema, AggregateFunctionSchema, PatternWindowSchema, PatternNodeV2Schema, PatternPartitionDimensionSchema, PatternAfterMatchSchema, PatternSelectionSchema, PatternExecutionPolicySchema, PatternMeasureSchema, PatternAstV2DefinitionSchema, collectPatternDurationsMs, collectGuaranteedPatternBindings, collectPatternMeasureRefs, collectPatternRefs, } from './patternV2Schemas.js';
|
|
2
|
+
export type { PatternValueSelector, PatternArithmeticValue, PatternWindow, PatternNodeV2, PatternAfterMatch, PatternAstV2Definition, PatternMeasure, } from './patternV2Schemas.js';
|
|
3
|
+
export { compileLegacyTriggerToPatternV2, } from '../patternV2/legacyCompiler.js';
|
|
4
|
+
export { evaluatePatternV2, evaluatePatternAggregate, evaluatePatternMeasure, patternV2CandidateSignature, } from '../patternV2/evaluator.js';
|
|
5
|
+
export type { PatternV2Candidate, PatternV2Evaluation, PatternV2SemanticDecision, PatternV2SemanticTrace, } from '../patternV2/evaluator.js';
|
|
6
|
+
export { TRIGGER_LANGUAGE_VERSION, PREDICATE_OPERATOR, COMPOSITION_OPERATOR, TEMPORAL_OPERATOR, TRIGGER_LANGUAGE_CATALOG, describeTriggerLanguage, } from './operatorRegistry.js';
|
|
7
|
+
export type { TriggerLanguageCategory, } from './operatorRegistry.js';
|
|
1
8
|
export { EVENT_INTELLIGENCE_PROTOCOL, EVENT_INTELLIGENCE_PROTOCOL_VERSION, EVENT_INTELLIGENCE_SCHEMA_VERSION, EVENT_INTELLIGENCE_COMPATIBILITY, } from './version.js';
|
|
2
9
|
export { RuntimeTargetSchema, EventSourceSchema, EventLineageSchema, McpEventOccurrenceSchema, SemanticConditionWireSchema, EventIngestRequestSchema, SemanticDecisionRecordSchema, WakeRecordSchema, LifecycleStateSchema, AuditKindSchema, AuditRecordSchema, parseEventIngestRequest, parseEventLineage, parseSemanticDecisionRecord, parseWakeRecord, parseAuditRecord, } from './schemas.js';
|
|
3
10
|
export type { RuntimeTarget, McpEventOccurrence, SemanticConditionWire, EventIngestRequest, EventLineage, SemanticDecisionRecord, WakeRecord, LifecycleState, AuditRecord, } from './schemas.js';
|
|
@@ -8,8 +15,8 @@ export type { AppendAuditInput, } from './audit.js';
|
|
|
8
15
|
export { mapMcpEventToLineage, } from './mapper.js';
|
|
9
16
|
export type { MapMcpEventInput, } from './mapper.js';
|
|
10
17
|
export { assertDecisionLineage, assertWakeLineage, } from './invariants.js';
|
|
11
|
-
export { COMPOSITE_TRIGGER_PROTOCOL_VERSION, COMPOSITE_TRIGGER_SCHEMA_VERSION, StructuredPredicateSchema, TriggerClauseSchema, ContinuationContextPolicySchema, ContinuationContractSchema, DerivedEventProjectionSchema, DerivedEventDefinitionSchema, DerivedEventEvidenceRefSchema, DerivedEventRecordSchema, DeterministicCorrelationSchema, SemanticCorrelationSchema, CompositeTriggerDefinitionSchema, CorrelatableEventSchema, TriggerSourceEventSchema, CompositeCorrelationDecisionSchema, TriggerMatchStatusSchema, TriggerMatchRecordSchema, parseCompositeTriggerDefinition, parseCorrelatableEvent, parseTriggerMatchRecord, parseDerivedEventRecord, } from './triggerSchemas.js';
|
|
12
|
-
export type { StructuredPredicate, TriggerClause, ContinuationContextPolicy, ContinuationContract, DerivedEventDefinition, DerivedEventRecord, CompositeTriggerDefinition, CorrelatableEvent, TriggerSourceEvent, TriggerMatchRecord, CompositeCorrelationDecision, } from './triggerSchemas.js';
|
|
18
|
+
export { COMPOSITE_TRIGGER_PROTOCOL_VERSION, COMPOSITE_TRIGGER_SCHEMA_VERSION, StructuredPredicateSchema, TriggerClauseSchema, TemporalConditionSchema, ContinuationContextPolicySchema, ContinuationContractSchema, EventTimePolicySchema, DerivedEventProjectionSchema, DerivedEventDefinitionSchema, DerivedEventEvidenceRefSchema, DerivedEventRecordSchema, DeterministicCorrelationSchema, SemanticCorrelationSchema, CompositeTriggerDefinitionSchema, CorrelatableEventSchema, TriggerSourceEventSchema, CompositeCorrelationDecisionSchema, TriggerMatchStatusSchema, PatternMatchStateSchema, TriggerMatchRecordSchema, parseCompositeTriggerDefinition, parseCorrelatableEvent, parseTriggerMatchRecord, parseDerivedEventRecord, } from './triggerSchemas.js';
|
|
19
|
+
export type { StructuredPredicate, TriggerClause, TemporalCondition, ContinuationContextPolicy, ContinuationContract, EventTimePolicy, DerivedEventDefinition, DerivedEventRecord, CompositeTriggerDefinition, CorrelatableEvent, TriggerSourceEvent, PatternMatchState, TriggerMatchRecord, CompositeCorrelationDecision, } from './triggerSchemas.js';
|
|
13
20
|
export { TriggerPlanEventSchema, TriggerPlanMatchSchema, TriggerPlanInputSchema, parseTriggerPlanInput, } from './triggerPlanSchemas.js';
|
|
14
21
|
export type { TriggerPlanEvent, TriggerPlanMatch, TriggerPlanInput, } from './triggerPlanSchemas.js';
|
|
15
22
|
export { ActivationEvidenceSchema, ActivationEnvelopeSchema, parseActivationEnvelope, } from './activationSchemas.js';
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
export { PATTERN_AST_VERSION, PatternValueSelectorSchema, PatternArithmeticValueSchema, PatternCompareOperatorSchema, AggregateFunctionSchema, PatternWindowSchema, PatternNodeV2Schema, PatternPartitionDimensionSchema, PatternAfterMatchSchema, PatternSelectionSchema, PatternExecutionPolicySchema, PatternMeasureSchema, PatternAstV2DefinitionSchema, collectPatternDurationsMs, collectGuaranteedPatternBindings, collectPatternMeasureRefs, collectPatternRefs, } from './patternV2Schemas.js';
|
|
2
|
+
export { compileLegacyTriggerToPatternV2, } from '../patternV2/legacyCompiler.js';
|
|
3
|
+
export { evaluatePatternV2, evaluatePatternAggregate, evaluatePatternMeasure, patternV2CandidateSignature, } from '../patternV2/evaluator.js';
|
|
4
|
+
export { TRIGGER_LANGUAGE_VERSION, PREDICATE_OPERATOR, COMPOSITION_OPERATOR, TEMPORAL_OPERATOR, TRIGGER_LANGUAGE_CATALOG, describeTriggerLanguage, } from './operatorRegistry.js';
|
|
1
5
|
export { EVENT_INTELLIGENCE_PROTOCOL, EVENT_INTELLIGENCE_PROTOCOL_VERSION, EVENT_INTELLIGENCE_SCHEMA_VERSION, EVENT_INTELLIGENCE_COMPATIBILITY, } from './version.js';
|
|
2
6
|
export { RuntimeTargetSchema, EventSourceSchema, EventLineageSchema, McpEventOccurrenceSchema, SemanticConditionWireSchema, EventIngestRequestSchema, SemanticDecisionRecordSchema, WakeRecordSchema, LifecycleStateSchema, AuditKindSchema, AuditRecordSchema, parseEventIngestRequest, parseEventLineage, parseSemanticDecisionRecord, parseWakeRecord, parseAuditRecord, } from './schemas.js';
|
|
3
7
|
export { canTransition, assertTransition, allowedTransitions, } from './lifecycle.js';
|
|
@@ -5,6 +9,6 @@ export { canonicalJson, sha256Hex, } from './canonical.js';
|
|
|
5
9
|
export { AuditChain, } from './audit.js';
|
|
6
10
|
export { mapMcpEventToLineage, } from './mapper.js';
|
|
7
11
|
export { assertDecisionLineage, assertWakeLineage, } from './invariants.js';
|
|
8
|
-
export { COMPOSITE_TRIGGER_PROTOCOL_VERSION, COMPOSITE_TRIGGER_SCHEMA_VERSION, StructuredPredicateSchema, TriggerClauseSchema, ContinuationContextPolicySchema, ContinuationContractSchema, DerivedEventProjectionSchema, DerivedEventDefinitionSchema, DerivedEventEvidenceRefSchema, DerivedEventRecordSchema, DeterministicCorrelationSchema, SemanticCorrelationSchema, CompositeTriggerDefinitionSchema, CorrelatableEventSchema, TriggerSourceEventSchema, CompositeCorrelationDecisionSchema, TriggerMatchStatusSchema, TriggerMatchRecordSchema, parseCompositeTriggerDefinition, parseCorrelatableEvent, parseTriggerMatchRecord, parseDerivedEventRecord, } from './triggerSchemas.js';
|
|
12
|
+
export { COMPOSITE_TRIGGER_PROTOCOL_VERSION, COMPOSITE_TRIGGER_SCHEMA_VERSION, StructuredPredicateSchema, TriggerClauseSchema, TemporalConditionSchema, ContinuationContextPolicySchema, ContinuationContractSchema, EventTimePolicySchema, DerivedEventProjectionSchema, DerivedEventDefinitionSchema, DerivedEventEvidenceRefSchema, DerivedEventRecordSchema, DeterministicCorrelationSchema, SemanticCorrelationSchema, CompositeTriggerDefinitionSchema, CorrelatableEventSchema, TriggerSourceEventSchema, CompositeCorrelationDecisionSchema, TriggerMatchStatusSchema, PatternMatchStateSchema, TriggerMatchRecordSchema, parseCompositeTriggerDefinition, parseCorrelatableEvent, parseTriggerMatchRecord, parseDerivedEventRecord, } from './triggerSchemas.js';
|
|
9
13
|
export { TriggerPlanEventSchema, TriggerPlanMatchSchema, TriggerPlanInputSchema, parseTriggerPlanInput, } from './triggerPlanSchemas.js';
|
|
10
14
|
export { ActivationEvidenceSchema, ActivationEnvelopeSchema, parseActivationEnvelope, } from './activationSchemas.js';
|