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.
Files changed (51) hide show
  1. package/CHANGELOG.md +81 -0
  2. package/README.md +123 -23
  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.d.ts +1 -1
  8. package/dist/src/composite/matching.js +66 -1
  9. package/dist/src/intelligenceProtocol/activationSchemas.d.ts +2 -0
  10. package/dist/src/intelligenceProtocol/activationSchemas.js +1 -0
  11. package/dist/src/intelligenceProtocol/index.d.ts +9 -2
  12. package/dist/src/intelligenceProtocol/index.js +5 -1
  13. package/dist/src/intelligenceProtocol/operatorRegistry.d.ts +567 -0
  14. package/dist/src/intelligenceProtocol/operatorRegistry.js +477 -0
  15. package/dist/src/intelligenceProtocol/patternV2Schemas.d.ts +188 -0
  16. package/dist/src/intelligenceProtocol/patternV2Schemas.js +801 -0
  17. package/dist/src/intelligenceProtocol/schemas.d.ts +6 -0
  18. package/dist/src/intelligenceProtocol/schemas.js +3 -0
  19. package/dist/src/intelligenceProtocol/triggerPlanSchemas.d.ts +179 -4
  20. package/dist/src/intelligenceProtocol/triggerPlanSchemas.js +38 -4
  21. package/dist/src/intelligenceProtocol/triggerSchemas.d.ts +262 -0
  22. package/dist/src/intelligenceProtocol/triggerSchemas.js +164 -2
  23. package/dist/src/mcpEvents/consumer.d.ts +2 -0
  24. package/dist/src/mcpEvents/consumer.js +2 -0
  25. package/dist/src/mcpEvents/erpnextProvider.d.ts +0 -2
  26. package/dist/src/mcpEvents/erpnextProvider.js +0 -3
  27. package/dist/src/mcpEvents/provider.d.ts +24 -10
  28. package/dist/src/mcpEvents/provider.js +124 -55
  29. package/dist/src/mcpEvents/server.d.ts +3 -1
  30. package/dist/src/mcpEvents/server.js +20 -19
  31. package/dist/src/patternV2/evaluator.d.ts +43 -0
  32. package/dist/src/patternV2/evaluator.js +927 -0
  33. package/dist/src/patternV2/legacyCompiler.d.ts +3 -0
  34. package/dist/src/patternV2/legacyCompiler.js +184 -0
  35. package/dist/src/protocol/types.d.ts +1 -0
  36. package/package.json +5 -2
  37. package/scripts/host-integration.d.mts +47 -0
  38. package/scripts/host-integration.mjs +9 -0
  39. package/scripts/lib/activation-hydrator.mjs +1 -0
  40. package/scripts/lib/composite-event-consumer.mjs +4 -0
  41. package/scripts/lib/derived-event-coordinator.mjs +75 -1
  42. package/scripts/lib/json-schema.mjs +134 -0
  43. package/scripts/lib/local-event-intelligence-runtime.mjs +1 -0
  44. package/scripts/lib/mcp-events-client.mjs +798 -253
  45. package/scripts/lib/mcp-events-compatibility.mjs +54 -0
  46. package/scripts/lib/persistent-event-store.mjs +68 -9
  47. package/scripts/lib/trigger-control-plane.mjs +180 -0
  48. package/scripts/lib/trigger-inspector.mjs +15 -0
  49. package/scripts/lib/trigger-planner.mjs +213 -12
  50. package/scripts/mcp-stdio-server.mjs +38 -52
  51. package/server.json +4 -4
@@ -128,6 +128,7 @@ export declare const McpEventOccurrenceSchema: z.ZodObject<{
128
128
  timestamp: z.ZodString;
129
129
  data: z.ZodRecord<z.ZodString, z.ZodUnknown>;
130
130
  cursor: z.ZodOptional<z.ZodNullable<z.ZodString>>;
131
+ _meta: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
131
132
  }, z.core.$strip>;
132
133
  export declare const SemanticConditionWireSchema: z.ZodObject<{
133
134
  type: z.ZodLiteral<"semantic_boolean">;
@@ -148,6 +149,7 @@ export declare const EventIngestRequestSchema: z.ZodObject<{
148
149
  timestamp: z.ZodString;
149
150
  data: z.ZodRecord<z.ZodString, z.ZodUnknown>;
150
151
  cursor: z.ZodOptional<z.ZodNullable<z.ZodString>>;
152
+ _meta: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
151
153
  }, z.core.$strip>;
152
154
  context: z.ZodObject<{
153
155
  traceId: z.ZodOptional<z.ZodString>;
@@ -205,6 +207,8 @@ export declare const AuditKindSchema: z.ZodEnum<{
205
207
  error: "error";
206
208
  "event.received": "event.received";
207
209
  "event.duplicate": "event.duplicate";
210
+ "event.late_dropped": "event.late_dropped";
211
+ "event.buffer_overflow": "event.buffer_overflow";
208
212
  "decision.evaluated": "decision.evaluated";
209
213
  "lifecycle.transition": "lifecycle.transition";
210
214
  "wake.queued": "wake.queued";
@@ -241,6 +245,8 @@ export declare const AuditRecordSchema: z.ZodObject<{
241
245
  error: "error";
242
246
  "event.received": "event.received";
243
247
  "event.duplicate": "event.duplicate";
248
+ "event.late_dropped": "event.late_dropped";
249
+ "event.buffer_overflow": "event.buffer_overflow";
244
250
  "decision.evaluated": "decision.evaluated";
245
251
  "lifecycle.transition": "lifecycle.transition";
246
252
  "wake.queued": "wake.queued";
@@ -74,6 +74,7 @@ export const McpEventOccurrenceSchema = z.object({
74
74
  timestamp: Timestamp,
75
75
  data: z.record(z.string(), z.unknown()),
76
76
  cursor: z.string().nullable().optional(),
77
+ _meta: z.record(z.string(), z.unknown()).optional(),
77
78
  });
78
79
  export const SemanticConditionWireSchema = z.object({
79
80
  type: z.literal('semantic_boolean'),
@@ -113,6 +114,8 @@ export const LifecycleStateSchema = z.enum([
113
114
  export const AuditKindSchema = z.enum([
114
115
  'event.received',
115
116
  'event.duplicate',
117
+ 'event.late_dropped',
118
+ 'event.buffer_overflow',
116
119
  'decision.evaluated',
117
120
  'lifecycle.transition',
118
121
  'wake.queued',
@@ -3,6 +3,7 @@ export declare const TriggerPlanEventSchema: z.ZodObject<{
3
3
  id: z.ZodOptional<z.ZodString>;
4
4
  event: z.ZodString;
5
5
  serverId: z.ZodOptional<z.ZodString>;
6
+ arguments: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
6
7
  where: z.ZodDefault<z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
7
8
  path: z.ZodString;
8
9
  op: z.ZodLiteral<"eq">;
@@ -15,14 +16,50 @@ export declare const TriggerPlanEventSchema: z.ZodObject<{
15
16
  path: z.ZodString;
16
17
  op: z.ZodLiteral<"contains">;
17
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>;
18
32
  }, z.core.$strip>, z.ZodObject<{
19
33
  path: z.ZodString;
20
34
  op: z.ZodLiteral<"in">;
21
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>;
22
44
  }, z.core.$strip>, z.ZodObject<{
23
45
  path: z.ZodString;
24
46
  op: z.ZodLiteral<"exists">;
25
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
+ }>;
26
63
  }, z.core.$strip>, z.ZodObject<{
27
64
  path: z.ZodString;
28
65
  op: z.ZodLiteral<"gt">;
@@ -58,6 +95,7 @@ export declare const TriggerPlanInputSchema: z.ZodObject<{
58
95
  id: z.ZodOptional<z.ZodString>;
59
96
  event: z.ZodString;
60
97
  serverId: z.ZodOptional<z.ZodString>;
98
+ arguments: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
61
99
  where: z.ZodDefault<z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
62
100
  path: z.ZodString;
63
101
  op: z.ZodLiteral<"eq">;
@@ -70,14 +108,50 @@ export declare const TriggerPlanInputSchema: z.ZodObject<{
70
108
  path: z.ZodString;
71
109
  op: z.ZodLiteral<"contains">;
72
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>;
73
124
  }, z.core.$strip>, z.ZodObject<{
74
125
  path: z.ZodString;
75
126
  op: z.ZodLiteral<"in">;
76
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>;
77
136
  }, z.core.$strip>, z.ZodObject<{
78
137
  path: z.ZodString;
79
138
  op: z.ZodLiteral<"exists">;
80
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
+ }>;
81
155
  }, z.core.$strip>, z.ZodObject<{
82
156
  path: z.ZodString;
83
157
  op: z.ZodLiteral<"gt">;
@@ -106,6 +180,106 @@ export declare const TriggerPlanInputSchema: z.ZodObject<{
106
180
  atLeast: z.ZodNumber;
107
181
  }, z.core.$strict>]>>;
108
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>>;
109
283
  lifecycle: z.ZodOptional<z.ZodObject<{
110
284
  oneShot: z.ZodOptional<z.ZodBoolean>;
111
285
  maxFirings: z.ZodOptional<z.ZodNumber>;
@@ -114,7 +288,8 @@ export declare const TriggerPlanInputSchema: z.ZodObject<{
114
288
  leaseUntil: z.ZodOptional<z.ZodString>;
115
289
  completeOnGoal: z.ZodOptional<z.ZodBoolean>;
116
290
  }, z.core.$strict>>;
117
- target: z.ZodObject<{
291
+ conditionOnly: z.ZodDefault<z.ZodBoolean>;
292
+ target: z.ZodOptional<z.ZodObject<{
118
293
  runtime: z.ZodString;
119
294
  kind: z.ZodEnum<{
120
295
  goal: "goal";
@@ -124,8 +299,8 @@ export declare const TriggerPlanInputSchema: z.ZodObject<{
124
299
  spawn_template: "spawn_template";
125
300
  }>;
126
301
  id: z.ZodString;
127
- }, z.core.$strip>;
128
- continuation: z.ZodObject<{
302
+ }, z.core.$strip>>;
303
+ continuation: z.ZodOptional<z.ZodObject<{
129
304
  instruction: z.ZodString;
130
305
  contextPolicy: z.ZodDefault<z.ZodObject<{
131
306
  evidence: z.ZodDefault<z.ZodEnum<{
@@ -135,7 +310,7 @@ export declare const TriggerPlanInputSchema: z.ZodObject<{
135
310
  maxEvents: z.ZodDefault<z.ZodNumber>;
136
311
  includeData: z.ZodDefault<z.ZodBoolean>;
137
312
  }, z.core.$strict>>;
138
- }, z.core.$strict>;
313
+ }, z.core.$strict>>;
139
314
  correlateBy: z.ZodOptional<z.ZodArray<z.ZodObject<{
140
315
  eventId: z.ZodString;
141
316
  path: z.ZodString;
@@ -1,11 +1,13 @@
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(),
7
8
  event: z.string().min(1),
8
9
  serverId: Id.optional(),
10
+ arguments: z.record(z.string(), z.unknown()).default({}),
9
11
  where: z.array(StructuredPredicateSchema).default([]),
10
12
  }).strict();
11
13
  export const TriggerPlanMatchSchema = z.union([
@@ -24,6 +26,12 @@ export const TriggerPlanInputSchema = z.object({
24
26
  match: TriggerPlanMatchSchema.default('all'),
25
27
  withinMs: z.number().int().positive().max(1000 * 60 * 60 * 24 * 30)
26
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(),
27
35
  lifecycle: z.object({
28
36
  oneShot: z.boolean().optional(),
29
37
  maxFirings: z.number().int().min(1).optional(),
@@ -32,14 +40,40 @@ export const TriggerPlanInputSchema = z.object({
32
40
  leaseUntil: z.string().datetime({ offset: true }).optional(),
33
41
  completeOnGoal: z.boolean().optional(),
34
42
  }).strict().optional(),
35
- target: RuntimeTargetSchema,
36
- continuation: ContinuationContractSchema,
43
+ conditionOnly: z.boolean().default(false),
44
+ target: RuntimeTargetSchema.optional(),
45
+ continuation: ContinuationContractSchema.optional(),
37
46
  correlateBy: z.array(z.object({
38
47
  eventId: Id,
39
48
  path: z.string().min(1),
40
49
  }).strict()).min(2).optional(),
41
50
  semanticCorrelation: SemanticCorrelationSchema.optional(),
42
- }).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
+ });
43
77
  export function parseTriggerPlanInput(value) {
44
78
  return TriggerPlanInputSchema.parse(value);
45
79
  }