mcp-event-intelligence 0.4.0 → 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.
Files changed (40) hide show
  1. package/CHANGELOG.md +59 -0
  2. package/README.md +102 -14
  3. package/SECURITY.md +4 -4
  4. package/bin/mcp-event-intelligence.mjs +3 -3
  5. package/dist/src/composite/engine.d.ts +6 -0
  6. package/dist/src/composite/engine.js +599 -10
  7. package/dist/src/composite/matching.js +45 -0
  8. package/dist/src/intelligenceProtocol/activationSchemas.d.ts +2 -0
  9. package/dist/src/intelligenceProtocol/activationSchemas.js +1 -0
  10. package/dist/src/intelligenceProtocol/index.d.ts +9 -2
  11. package/dist/src/intelligenceProtocol/index.js +5 -1
  12. package/dist/src/intelligenceProtocol/operatorRegistry.d.ts +567 -0
  13. package/dist/src/intelligenceProtocol/operatorRegistry.js +477 -0
  14. package/dist/src/intelligenceProtocol/patternV2Schemas.d.ts +188 -0
  15. package/dist/src/intelligenceProtocol/patternV2Schemas.js +801 -0
  16. package/dist/src/intelligenceProtocol/schemas.d.ts +4 -0
  17. package/dist/src/intelligenceProtocol/schemas.js +2 -0
  18. package/dist/src/intelligenceProtocol/triggerPlanSchemas.d.ts +177 -4
  19. package/dist/src/intelligenceProtocol/triggerPlanSchemas.js +37 -4
  20. package/dist/src/intelligenceProtocol/triggerSchemas.d.ts +256 -0
  21. package/dist/src/intelligenceProtocol/triggerSchemas.js +161 -2
  22. package/dist/src/mcpEvents/consumer.d.ts +1 -0
  23. package/dist/src/mcpEvents/consumer.js +1 -0
  24. package/dist/src/patternV2/evaluator.d.ts +43 -0
  25. package/dist/src/patternV2/evaluator.js +927 -0
  26. package/dist/src/patternV2/legacyCompiler.d.ts +3 -0
  27. package/dist/src/patternV2/legacyCompiler.js +184 -0
  28. package/package.json +5 -2
  29. package/scripts/host-integration.d.mts +7 -0
  30. package/scripts/host-integration.mjs +9 -0
  31. package/scripts/lib/activation-hydrator.mjs +1 -0
  32. package/scripts/lib/composite-event-consumer.mjs +2 -0
  33. package/scripts/lib/derived-event-coordinator.mjs +75 -1
  34. package/scripts/lib/mcp-events-client.mjs +62 -24
  35. package/scripts/lib/mcp-events-compatibility.mjs +54 -0
  36. package/scripts/lib/trigger-control-plane.mjs +154 -0
  37. package/scripts/lib/trigger-inspector.mjs +15 -0
  38. package/scripts/lib/trigger-planner.mjs +190 -12
  39. package/scripts/mcp-stdio-server.mjs +38 -53
  40. package/server.json +4 -4
@@ -207,6 +207,8 @@ export declare const AuditKindSchema: z.ZodEnum<{
207
207
  error: "error";
208
208
  "event.received": "event.received";
209
209
  "event.duplicate": "event.duplicate";
210
+ "event.late_dropped": "event.late_dropped";
211
+ "event.buffer_overflow": "event.buffer_overflow";
210
212
  "decision.evaluated": "decision.evaluated";
211
213
  "lifecycle.transition": "lifecycle.transition";
212
214
  "wake.queued": "wake.queued";
@@ -243,6 +245,8 @@ export declare const AuditRecordSchema: z.ZodObject<{
243
245
  error: "error";
244
246
  "event.received": "event.received";
245
247
  "event.duplicate": "event.duplicate";
248
+ "event.late_dropped": "event.late_dropped";
249
+ "event.buffer_overflow": "event.buffer_overflow";
246
250
  "decision.evaluated": "decision.evaluated";
247
251
  "lifecycle.transition": "lifecycle.transition";
248
252
  "wake.queued": "wake.queued";
@@ -114,6 +114,8 @@ export const LifecycleStateSchema = z.enum([
114
114
  export const AuditKindSchema = z.enum([
115
115
  'event.received',
116
116
  'event.duplicate',
117
+ 'event.late_dropped',
118
+ 'event.buffer_overflow',
117
119
  'decision.evaluated',
118
120
  'lifecycle.transition',
119
121
  'wake.queued',
@@ -16,14 +16,50 @@ export declare const TriggerPlanEventSchema: z.ZodObject<{
16
16
  path: z.ZodString;
17
17
  op: z.ZodLiteral<"contains">;
18
18
  value: z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>;
19
+ }, z.core.$strip>, z.ZodObject<{
20
+ path: z.ZodString;
21
+ op: z.ZodLiteral<"startsWith">;
22
+ value: z.ZodString;
23
+ }, z.core.$strip>, z.ZodObject<{
24
+ path: z.ZodString;
25
+ op: z.ZodLiteral<"endsWith">;
26
+ value: z.ZodString;
27
+ }, z.core.$strip>, z.ZodObject<{
28
+ path: z.ZodString;
29
+ op: z.ZodLiteral<"regex">;
30
+ value: z.ZodString;
31
+ flags: z.ZodOptional<z.ZodString>;
19
32
  }, z.core.$strip>, z.ZodObject<{
20
33
  path: z.ZodString;
21
34
  op: z.ZodLiteral<"in">;
22
35
  value: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>;
36
+ }, z.core.$strip>, z.ZodObject<{
37
+ path: z.ZodString;
38
+ op: z.ZodLiteral<"notIn">;
39
+ value: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>;
40
+ }, z.core.$strip>, z.ZodObject<{
41
+ path: z.ZodString;
42
+ op: z.ZodLiteral<"between">;
43
+ value: z.ZodTuple<[z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>], null>;
23
44
  }, z.core.$strip>, z.ZodObject<{
24
45
  path: z.ZodString;
25
46
  op: z.ZodLiteral<"exists">;
26
47
  value: z.ZodDefault<z.ZodBoolean>;
48
+ }, z.core.$strip>, z.ZodObject<{
49
+ path: z.ZodString;
50
+ op: z.ZodLiteral<"isNull">;
51
+ value: z.ZodDefault<z.ZodBoolean>;
52
+ }, z.core.$strip>, z.ZodObject<{
53
+ path: z.ZodString;
54
+ op: z.ZodLiteral<"type">;
55
+ value: z.ZodEnum<{
56
+ string: "string";
57
+ number: "number";
58
+ boolean: "boolean";
59
+ object: "object";
60
+ null: "null";
61
+ array: "array";
62
+ }>;
27
63
  }, z.core.$strip>, z.ZodObject<{
28
64
  path: z.ZodString;
29
65
  op: z.ZodLiteral<"gt">;
@@ -72,14 +108,50 @@ export declare const TriggerPlanInputSchema: z.ZodObject<{
72
108
  path: z.ZodString;
73
109
  op: z.ZodLiteral<"contains">;
74
110
  value: z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>;
111
+ }, z.core.$strip>, z.ZodObject<{
112
+ path: z.ZodString;
113
+ op: z.ZodLiteral<"startsWith">;
114
+ value: z.ZodString;
115
+ }, z.core.$strip>, z.ZodObject<{
116
+ path: z.ZodString;
117
+ op: z.ZodLiteral<"endsWith">;
118
+ value: z.ZodString;
119
+ }, z.core.$strip>, z.ZodObject<{
120
+ path: z.ZodString;
121
+ op: z.ZodLiteral<"regex">;
122
+ value: z.ZodString;
123
+ flags: z.ZodOptional<z.ZodString>;
75
124
  }, z.core.$strip>, z.ZodObject<{
76
125
  path: z.ZodString;
77
126
  op: z.ZodLiteral<"in">;
78
127
  value: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>;
128
+ }, z.core.$strip>, z.ZodObject<{
129
+ path: z.ZodString;
130
+ op: z.ZodLiteral<"notIn">;
131
+ value: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>;
132
+ }, z.core.$strip>, z.ZodObject<{
133
+ path: z.ZodString;
134
+ op: z.ZodLiteral<"between">;
135
+ value: z.ZodTuple<[z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>], null>;
79
136
  }, z.core.$strip>, z.ZodObject<{
80
137
  path: z.ZodString;
81
138
  op: z.ZodLiteral<"exists">;
82
139
  value: z.ZodDefault<z.ZodBoolean>;
140
+ }, z.core.$strip>, z.ZodObject<{
141
+ path: z.ZodString;
142
+ op: z.ZodLiteral<"isNull">;
143
+ value: z.ZodDefault<z.ZodBoolean>;
144
+ }, z.core.$strip>, z.ZodObject<{
145
+ path: z.ZodString;
146
+ op: z.ZodLiteral<"type">;
147
+ value: z.ZodEnum<{
148
+ string: "string";
149
+ number: "number";
150
+ boolean: "boolean";
151
+ object: "object";
152
+ null: "null";
153
+ array: "array";
154
+ }>;
83
155
  }, z.core.$strip>, z.ZodObject<{
84
156
  path: z.ZodString;
85
157
  op: z.ZodLiteral<"gt">;
@@ -108,6 +180,106 @@ export declare const TriggerPlanInputSchema: z.ZodObject<{
108
180
  atLeast: z.ZodNumber;
109
181
  }, z.core.$strict>]>>;
110
182
  withinMs: z.ZodDefault<z.ZodNumber>;
183
+ eventTime: z.ZodOptional<z.ZodObject<{
184
+ allowedLatenessMs: z.ZodNumber;
185
+ }, z.core.$strict>>;
186
+ temporal: z.ZodDefault<z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
187
+ id: z.ZodString;
188
+ kind: z.ZodLiteral<"calendar">;
189
+ ref: z.ZodString;
190
+ timezone: z.ZodString;
191
+ before: z.ZodOptional<z.ZodString>;
192
+ after: z.ZodOptional<z.ZodString>;
193
+ weekdays: z.ZodOptional<z.ZodArray<z.ZodNumber>>;
194
+ dates: z.ZodOptional<z.ZodArray<z.ZodString>>;
195
+ dateRange: z.ZodOptional<z.ZodObject<{
196
+ start: z.ZodString;
197
+ end: z.ZodString;
198
+ }, z.core.$strip>>;
199
+ dayOfMonth: z.ZodOptional<z.ZodArray<z.ZodNumber>>;
200
+ }, z.core.$strict>, z.ZodObject<{
201
+ id: z.ZodString;
202
+ kind: z.ZodLiteral<"absence">;
203
+ ref: z.ZodString;
204
+ afterRef: z.ZodString;
205
+ forMs: z.ZodOptional<z.ZodNumber>;
206
+ untilLocalTime: z.ZodOptional<z.ZodString>;
207
+ timezone: z.ZodOptional<z.ZodString>;
208
+ }, z.core.$strip>, z.ZodObject<{
209
+ id: z.ZodString;
210
+ kind: z.ZodLiteral<"not">;
211
+ ref: z.ZodString;
212
+ }, z.core.$strip>, z.ZodObject<{
213
+ id: z.ZodString;
214
+ kind: z.ZodLiteral<"unless">;
215
+ ref: z.ZodString;
216
+ }, z.core.$strip>, z.ZodObject<{
217
+ id: z.ZodString;
218
+ kind: z.ZodLiteral<"after">;
219
+ ref: z.ZodString;
220
+ afterRef: z.ZodString;
221
+ }, z.core.$strip>, z.ZodObject<{
222
+ id: z.ZodString;
223
+ kind: z.ZodLiteral<"until">;
224
+ ref: z.ZodString;
225
+ beforeRef: z.ZodString;
226
+ }, z.core.$strip>, z.ZodObject<{
227
+ id: z.ZodString;
228
+ kind: z.ZodLiteral<"debounce">;
229
+ ref: z.ZodString;
230
+ forMs: z.ZodNumber;
231
+ }, z.core.$strip>, z.ZodObject<{
232
+ id: z.ZodString;
233
+ kind: z.ZodLiteral<"threshold">;
234
+ ref: z.ZodString;
235
+ atLeast: z.ZodNumber;
236
+ }, z.core.$strip>, z.ZodObject<{
237
+ id: z.ZodString;
238
+ kind: z.ZodLiteral<"rate">;
239
+ ref: z.ZodString;
240
+ atLeast: z.ZodNumber;
241
+ perMs: z.ZodNumber;
242
+ }, z.core.$strip>, z.ZodObject<{
243
+ id: z.ZodString;
244
+ kind: z.ZodLiteral<"distinct">;
245
+ ref: z.ZodString;
246
+ path: z.ZodString;
247
+ atLeast: z.ZodNumber;
248
+ }, z.core.$strip>], "kind">>>;
249
+ patternV2: z.ZodOptional<z.ZodObject<{
250
+ version: z.ZodDefault<z.ZodLiteral<"2">>;
251
+ root: z.ZodType<any, unknown, z.core.$ZodTypeInternals<any, unknown>>;
252
+ partitionBy: z.ZodDefault<z.ZodArray<z.ZodObject<{
253
+ key: z.ZodString;
254
+ fields: z.ZodArray<z.ZodObject<{
255
+ ref: z.ZodString;
256
+ path: z.ZodString;
257
+ }, z.core.$strict>>;
258
+ }, z.core.$strict>>>;
259
+ selection: z.ZodDefault<z.ZodObject<{
260
+ overlap: z.ZodDefault<z.ZodEnum<{
261
+ allow: "allow";
262
+ disallow: "disallow";
263
+ }>>;
264
+ afterMatch: z.ZodDefault<z.ZodUnion<readonly [z.ZodEnum<{
265
+ skipPastLast: "skipPastLast";
266
+ skipToNext: "skipToNext";
267
+ keepAll: "keepAll";
268
+ }>, z.ZodObject<{
269
+ kind: z.ZodEnum<{
270
+ skipToFirst: "skipToFirst";
271
+ skipToLast: "skipToLast";
272
+ }>;
273
+ ref: z.ZodString;
274
+ }, z.core.$strict>]>>;
275
+ maxMatchesPerEvent: z.ZodDefault<z.ZodNumber>;
276
+ }, z.core.$strict>>;
277
+ execution: z.ZodDefault<z.ZodObject<{
278
+ maxCandidates: z.ZodDefault<z.ZodNumber>;
279
+ maxSemanticEvaluations: z.ZodDefault<z.ZodNumber>;
280
+ maxBufferedEvents: z.ZodDefault<z.ZodNumber>;
281
+ }, z.core.$strict>>;
282
+ }, z.core.$strict>>;
111
283
  lifecycle: z.ZodOptional<z.ZodObject<{
112
284
  oneShot: z.ZodOptional<z.ZodBoolean>;
113
285
  maxFirings: z.ZodOptional<z.ZodNumber>;
@@ -116,7 +288,8 @@ export declare const TriggerPlanInputSchema: z.ZodObject<{
116
288
  leaseUntil: z.ZodOptional<z.ZodString>;
117
289
  completeOnGoal: z.ZodOptional<z.ZodBoolean>;
118
290
  }, z.core.$strict>>;
119
- target: z.ZodObject<{
291
+ conditionOnly: z.ZodDefault<z.ZodBoolean>;
292
+ target: z.ZodOptional<z.ZodObject<{
120
293
  runtime: z.ZodString;
121
294
  kind: z.ZodEnum<{
122
295
  goal: "goal";
@@ -126,8 +299,8 @@ export declare const TriggerPlanInputSchema: z.ZodObject<{
126
299
  spawn_template: "spawn_template";
127
300
  }>;
128
301
  id: z.ZodString;
129
- }, z.core.$strip>;
130
- continuation: z.ZodObject<{
302
+ }, z.core.$strip>>;
303
+ continuation: z.ZodOptional<z.ZodObject<{
131
304
  instruction: z.ZodString;
132
305
  contextPolicy: z.ZodDefault<z.ZodObject<{
133
306
  evidence: z.ZodDefault<z.ZodEnum<{
@@ -137,7 +310,7 @@ export declare const TriggerPlanInputSchema: z.ZodObject<{
137
310
  maxEvents: z.ZodDefault<z.ZodNumber>;
138
311
  includeData: z.ZodDefault<z.ZodBoolean>;
139
312
  }, z.core.$strict>>;
140
- }, z.core.$strict>;
313
+ }, z.core.$strict>>;
141
314
  correlateBy: z.ZodOptional<z.ZodArray<z.ZodObject<{
142
315
  eventId: z.ZodString;
143
316
  path: z.ZodString;
@@ -1,6 +1,7 @@
1
1
  import { z } from 'zod';
2
2
  import { RuntimeTargetSchema } from './schemas.js';
3
- import { ContinuationContractSchema, SemanticCorrelationSchema, StructuredPredicateSchema, } from './triggerSchemas.js';
3
+ import { PatternAstV2DefinitionSchema, } from './patternV2Schemas.js';
4
+ import { ContinuationContractSchema, SemanticCorrelationSchema, StructuredPredicateSchema, TemporalConditionSchema, } from './triggerSchemas.js';
4
5
  const Id = z.string().min(1).max(200);
5
6
  export const TriggerPlanEventSchema = z.object({
6
7
  id: Id.optional(),
@@ -25,6 +26,12 @@ export const TriggerPlanInputSchema = z.object({
25
26
  match: TriggerPlanMatchSchema.default('all'),
26
27
  withinMs: z.number().int().positive().max(1000 * 60 * 60 * 24 * 30)
27
28
  .default(60 * 60 * 1000),
29
+ eventTime: z.object({
30
+ allowedLatenessMs: z.number().int().nonnegative()
31
+ .max(1000 * 60 * 60 * 24 * 30),
32
+ }).strict().optional(),
33
+ temporal: z.array(TemporalConditionSchema).default([]),
34
+ patternV2: PatternAstV2DefinitionSchema.optional(),
28
35
  lifecycle: z.object({
29
36
  oneShot: z.boolean().optional(),
30
37
  maxFirings: z.number().int().min(1).optional(),
@@ -33,14 +40,40 @@ export const TriggerPlanInputSchema = z.object({
33
40
  leaseUntil: z.string().datetime({ offset: true }).optional(),
34
41
  completeOnGoal: z.boolean().optional(),
35
42
  }).strict().optional(),
36
- target: RuntimeTargetSchema,
37
- continuation: ContinuationContractSchema,
43
+ conditionOnly: z.boolean().default(false),
44
+ target: RuntimeTargetSchema.optional(),
45
+ continuation: ContinuationContractSchema.optional(),
38
46
  correlateBy: z.array(z.object({
39
47
  eventId: Id,
40
48
  path: z.string().min(1),
41
49
  }).strict()).min(2).optional(),
42
50
  semanticCorrelation: SemanticCorrelationSchema.optional(),
43
- }).strict();
51
+ }).strict().superRefine((value, ctx) => {
52
+ if (value.patternV2 &&
53
+ (value.temporal.length > 0 ||
54
+ value.correlateBy ||
55
+ value.semanticCorrelation)) {
56
+ ctx.addIssue({
57
+ code: 'custom',
58
+ message: 'patternV2 cannot be combined with legacy temporal/correlation fields',
59
+ });
60
+ }
61
+ if (value.conditionOnly) {
62
+ if (value.target || value.continuation) {
63
+ ctx.addIssue({
64
+ code: 'custom',
65
+ message: 'conditionOnly plans cannot declare target or continuation',
66
+ });
67
+ }
68
+ return;
69
+ }
70
+ if (!value.target || !value.continuation) {
71
+ ctx.addIssue({
72
+ code: 'custom',
73
+ message: 'Agent activation plans require target and continuation',
74
+ });
75
+ }
76
+ });
44
77
  export function parseTriggerPlanInput(value) {
45
78
  return TriggerPlanInputSchema.parse(value);
46
79
  }