mcp-event-intelligence 0.5.0 → 0.6.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 (61) hide show
  1. package/CHANGELOG.md +41 -0
  2. package/README.md +31 -38
  3. package/SECURITY.md +4 -4
  4. package/bin/mcp-event-intelligence.mjs +2 -2
  5. package/dist/src/composite/engine.d.ts +11 -7
  6. package/dist/src/composite/engine.js +150 -414
  7. package/dist/src/composite/matching.d.ts +1 -5
  8. package/dist/src/composite/matching.js +0 -54
  9. package/dist/src/composite/runtimeSupport.js +10 -6
  10. package/dist/src/composite/store.d.ts +38 -4
  11. package/dist/src/composite/temporal.d.ts +0 -17
  12. package/dist/src/composite/temporal.js +0 -266
  13. package/dist/src/intelligenceProtocol/activationSchemas.d.ts +36 -3
  14. package/dist/src/intelligenceProtocol/activationSchemas.js +4 -3
  15. package/dist/src/intelligenceProtocol/index.d.ts +8 -12
  16. package/dist/src/intelligenceProtocol/index.js +4 -7
  17. package/dist/src/intelligenceProtocol/lifecycle.js +2 -10
  18. package/dist/src/intelligenceProtocol/operatorRegistry.d.ts +3 -270
  19. package/dist/src/intelligenceProtocol/operatorRegistry.js +5 -144
  20. package/dist/src/intelligenceProtocol/schemas.d.ts +0 -189
  21. package/dist/src/intelligenceProtocol/schemas.js +1 -97
  22. package/dist/src/intelligenceProtocol/triggerPlanSchemas.d.ts +5 -102
  23. package/dist/src/intelligenceProtocol/triggerPlanSchemas.js +2 -26
  24. package/dist/src/intelligenceProtocol/triggerSchemas.d.ts +14 -215
  25. package/dist/src/intelligenceProtocol/triggerSchemas.js +18 -191
  26. package/dist/src/intelligenceProtocol/version.d.ts +2 -2
  27. package/dist/src/intelligenceProtocol/version.js +2 -2
  28. package/dist/src/patternV2/evaluator.d.ts +9 -1
  29. package/dist/src/patternV2/evaluator.js +63 -4
  30. package/dist/src/semantic/types.d.ts +6 -0
  31. package/dist/src/semantic/typesafeJevEvaluator.d.ts +1 -0
  32. package/dist/src/semantic/typesafeJevEvaluator.js +6 -0
  33. package/package.json +5 -2
  34. package/scripts/host-integration.d.mts +48 -5
  35. package/scripts/host-integration.mjs +16 -4
  36. package/scripts/lib/activation-hydrator.mjs +12 -12
  37. package/scripts/lib/composite-event-consumer.mjs +8 -28
  38. package/scripts/lib/composite-wake-coordinator.mjs +19 -19
  39. package/scripts/lib/derived-contract-registry.mjs +4 -4
  40. package/scripts/lib/derived-event-coordinator.mjs +11 -22
  41. package/scripts/lib/local-event-intelligence-runtime.mjs +35 -3
  42. package/scripts/lib/mcp-events-client.mjs +36 -32
  43. package/scripts/lib/persistent-event-store.mjs +228 -61
  44. package/scripts/lib/store-capabilities.mjs +88 -0
  45. package/scripts/lib/store-conformance.mjs +127 -0
  46. package/scripts/lib/temporal-deadline-scheduler.mjs +3 -3
  47. package/scripts/lib/trigger-control-plane.mjs +52 -57
  48. package/scripts/lib/trigger-inspector.mjs +48 -160
  49. package/scripts/lib/trigger-planner.mjs +37 -126
  50. package/scripts/lib/wake-retry-scheduler.mjs +2 -19
  51. package/scripts/mcp-stdio-server.mjs +8 -8
  52. package/scripts/service.mjs +19 -138
  53. package/server.json +3 -3
  54. package/dist/src/intelligenceProtocol/invariants.d.ts +0 -3
  55. package/dist/src/intelligenceProtocol/invariants.js +0 -36
  56. package/dist/src/intelligenceProtocol/mapper.d.ts +0 -14
  57. package/dist/src/intelligenceProtocol/mapper.js +0 -28
  58. package/dist/src/patternV2/legacyCompiler.d.ts +0 -3
  59. package/dist/src/patternV2/legacyCompiler.js +0 -184
  60. package/scripts/lib/event-processor.mjs +0 -624
  61. package/scripts/lib/http-wake-deliverer.mjs +0 -31
@@ -1,6 +1,6 @@
1
1
  import { z } from 'zod';
2
- export declare const COMPOSITE_TRIGGER_PROTOCOL_VERSION: "0.1.0";
3
- export declare const COMPOSITE_TRIGGER_SCHEMA_VERSION: "trigger.v0.1";
2
+ export declare const COMPOSITE_TRIGGER_PROTOCOL_VERSION: "0.2.0";
3
+ export declare const COMPOSITE_TRIGGER_SCHEMA_VERSION: "trigger.v0.2";
4
4
  export declare const StructuredPredicateSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
5
5
  path: z.ZodString;
6
6
  op: z.ZodLiteral<"eq">;
@@ -154,93 +154,6 @@ export declare const TriggerClauseSchema: z.ZodObject<{
154
154
  value: z.ZodNumber;
155
155
  }, z.core.$strip>], "op">>>;
156
156
  }, z.core.$strip>;
157
- export declare const CalendarTemporalConditionSchema: z.ZodObject<{
158
- id: z.ZodString;
159
- kind: z.ZodLiteral<"calendar">;
160
- ref: z.ZodString;
161
- timezone: z.ZodString;
162
- before: z.ZodOptional<z.ZodString>;
163
- after: z.ZodOptional<z.ZodString>;
164
- weekdays: z.ZodOptional<z.ZodArray<z.ZodNumber>>;
165
- dates: z.ZodOptional<z.ZodArray<z.ZodString>>;
166
- dateRange: z.ZodOptional<z.ZodObject<{
167
- start: z.ZodString;
168
- end: z.ZodString;
169
- }, z.core.$strip>>;
170
- dayOfMonth: z.ZodOptional<z.ZodArray<z.ZodNumber>>;
171
- }, z.core.$strict>;
172
- export declare const AbsenceTemporalConditionSchema: z.ZodObject<{
173
- id: z.ZodString;
174
- kind: z.ZodLiteral<"absence">;
175
- ref: z.ZodString;
176
- afterRef: z.ZodString;
177
- forMs: z.ZodOptional<z.ZodNumber>;
178
- untilLocalTime: z.ZodOptional<z.ZodString>;
179
- timezone: z.ZodOptional<z.ZodString>;
180
- }, z.core.$strip>;
181
- export declare const TemporalConditionSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
182
- id: z.ZodString;
183
- kind: z.ZodLiteral<"calendar">;
184
- ref: z.ZodString;
185
- timezone: z.ZodString;
186
- before: z.ZodOptional<z.ZodString>;
187
- after: z.ZodOptional<z.ZodString>;
188
- weekdays: z.ZodOptional<z.ZodArray<z.ZodNumber>>;
189
- dates: z.ZodOptional<z.ZodArray<z.ZodString>>;
190
- dateRange: z.ZodOptional<z.ZodObject<{
191
- start: z.ZodString;
192
- end: z.ZodString;
193
- }, z.core.$strip>>;
194
- dayOfMonth: z.ZodOptional<z.ZodArray<z.ZodNumber>>;
195
- }, z.core.$strict>, z.ZodObject<{
196
- id: z.ZodString;
197
- kind: z.ZodLiteral<"absence">;
198
- ref: z.ZodString;
199
- afterRef: z.ZodString;
200
- forMs: z.ZodOptional<z.ZodNumber>;
201
- untilLocalTime: z.ZodOptional<z.ZodString>;
202
- timezone: z.ZodOptional<z.ZodString>;
203
- }, z.core.$strip>, z.ZodObject<{
204
- id: z.ZodString;
205
- kind: z.ZodLiteral<"not">;
206
- ref: z.ZodString;
207
- }, z.core.$strip>, z.ZodObject<{
208
- id: z.ZodString;
209
- kind: z.ZodLiteral<"unless">;
210
- ref: z.ZodString;
211
- }, z.core.$strip>, z.ZodObject<{
212
- id: z.ZodString;
213
- kind: z.ZodLiteral<"after">;
214
- ref: z.ZodString;
215
- afterRef: z.ZodString;
216
- }, z.core.$strip>, z.ZodObject<{
217
- id: z.ZodString;
218
- kind: z.ZodLiteral<"until">;
219
- ref: z.ZodString;
220
- beforeRef: z.ZodString;
221
- }, z.core.$strip>, z.ZodObject<{
222
- id: z.ZodString;
223
- kind: z.ZodLiteral<"debounce">;
224
- ref: z.ZodString;
225
- forMs: z.ZodNumber;
226
- }, z.core.$strip>, z.ZodObject<{
227
- id: z.ZodString;
228
- kind: z.ZodLiteral<"threshold">;
229
- ref: z.ZodString;
230
- atLeast: z.ZodNumber;
231
- }, z.core.$strip>, z.ZodObject<{
232
- id: z.ZodString;
233
- kind: z.ZodLiteral<"rate">;
234
- ref: z.ZodString;
235
- atLeast: z.ZodNumber;
236
- perMs: z.ZodNumber;
237
- }, z.core.$strip>, z.ZodObject<{
238
- id: z.ZodString;
239
- kind: z.ZodLiteral<"distinct">;
240
- ref: z.ZodString;
241
- path: z.ZodString;
242
- atLeast: z.ZodNumber;
243
- }, z.core.$strip>], "kind">;
244
157
  export declare const DerivedEventProjectionSchema: z.ZodObject<{
245
158
  key: z.ZodString;
246
159
  ref: z.ZodString;
@@ -320,27 +233,9 @@ export declare const ContinuationContractSchema: z.ZodObject<{
320
233
  includeData: z.ZodDefault<z.ZodBoolean>;
321
234
  }, z.core.$strict>>;
322
235
  }, z.core.$strict>;
323
- export declare const DeterministicCorrelationSchema: z.ZodObject<{
324
- kind: z.ZodLiteral<"same_value">;
325
- fields: z.ZodArray<z.ZodObject<{
326
- ref: z.ZodString;
327
- path: z.ZodString;
328
- }, z.core.$strip>>;
329
- }, z.core.$strip>;
330
- export declare const SemanticCorrelationSchema: z.ZodObject<{
331
- instruction: z.ZodString;
332
- input: z.ZodArray<z.ZodString>;
333
- matchThreshold: z.ZodNumber;
334
- rejectThreshold: z.ZodNumber;
335
- uncertain: z.ZodDefault<z.ZodEnum<{
336
- match: "match";
337
- reject: "reject";
338
- escalate: "escalate";
339
- }>>;
340
- }, z.core.$strip>;
341
236
  export declare const CompositeTriggerDefinitionSchema: z.ZodObject<{
342
- protocolVersion: z.ZodDefault<z.ZodLiteral<"0.1.0">>;
343
- schemaVersion: z.ZodDefault<z.ZodLiteral<"trigger.v0.1">>;
237
+ protocolVersion: z.ZodDefault<z.ZodLiteral<"0.2.0">>;
238
+ schemaVersion: z.ZodDefault<z.ZodLiteral<"trigger.v0.2">>;
344
239
  triggerId: z.ZodString;
345
240
  version: z.ZodString;
346
241
  description: z.ZodOptional<z.ZodString>;
@@ -436,84 +331,7 @@ export declare const CompositeTriggerDefinitionSchema: z.ZodObject<{
436
331
  value: z.ZodNumber;
437
332
  }, z.core.$strip>], "op">>>;
438
333
  }, z.core.$strip>>;
439
- expression: z.ZodDiscriminatedUnion<[z.ZodObject<{
440
- kind: z.ZodLiteral<"allOf">;
441
- refs: z.ZodArray<z.ZodString>;
442
- }, z.core.$strip>, z.ZodObject<{
443
- kind: z.ZodLiteral<"anyOf">;
444
- refs: z.ZodArray<z.ZodString>;
445
- }, z.core.$strip>, z.ZodObject<{
446
- kind: z.ZodLiteral<"sequence">;
447
- refs: z.ZodArray<z.ZodString>;
448
- }, z.core.$strip>, z.ZodObject<{
449
- kind: z.ZodLiteral<"count">;
450
- ref: z.ZodString;
451
- atLeast: z.ZodNumber;
452
- }, z.core.$strip>], "kind">;
453
- temporal: z.ZodDefault<z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
454
- id: z.ZodString;
455
- kind: z.ZodLiteral<"calendar">;
456
- ref: z.ZodString;
457
- timezone: z.ZodString;
458
- before: z.ZodOptional<z.ZodString>;
459
- after: z.ZodOptional<z.ZodString>;
460
- weekdays: z.ZodOptional<z.ZodArray<z.ZodNumber>>;
461
- dates: z.ZodOptional<z.ZodArray<z.ZodString>>;
462
- dateRange: z.ZodOptional<z.ZodObject<{
463
- start: z.ZodString;
464
- end: z.ZodString;
465
- }, z.core.$strip>>;
466
- dayOfMonth: z.ZodOptional<z.ZodArray<z.ZodNumber>>;
467
- }, z.core.$strict>, z.ZodObject<{
468
- id: z.ZodString;
469
- kind: z.ZodLiteral<"absence">;
470
- ref: z.ZodString;
471
- afterRef: z.ZodString;
472
- forMs: z.ZodOptional<z.ZodNumber>;
473
- untilLocalTime: z.ZodOptional<z.ZodString>;
474
- timezone: z.ZodOptional<z.ZodString>;
475
- }, z.core.$strip>, z.ZodObject<{
476
- id: z.ZodString;
477
- kind: z.ZodLiteral<"not">;
478
- ref: z.ZodString;
479
- }, z.core.$strip>, z.ZodObject<{
480
- id: z.ZodString;
481
- kind: z.ZodLiteral<"unless">;
482
- ref: z.ZodString;
483
- }, z.core.$strip>, z.ZodObject<{
484
- id: z.ZodString;
485
- kind: z.ZodLiteral<"after">;
486
- ref: z.ZodString;
487
- afterRef: z.ZodString;
488
- }, z.core.$strip>, z.ZodObject<{
489
- id: z.ZodString;
490
- kind: z.ZodLiteral<"until">;
491
- ref: z.ZodString;
492
- beforeRef: z.ZodString;
493
- }, z.core.$strip>, z.ZodObject<{
494
- id: z.ZodString;
495
- kind: z.ZodLiteral<"debounce">;
496
- ref: z.ZodString;
497
- forMs: z.ZodNumber;
498
- }, z.core.$strip>, z.ZodObject<{
499
- id: z.ZodString;
500
- kind: z.ZodLiteral<"threshold">;
501
- ref: z.ZodString;
502
- atLeast: z.ZodNumber;
503
- }, z.core.$strip>, z.ZodObject<{
504
- id: z.ZodString;
505
- kind: z.ZodLiteral<"rate">;
506
- ref: z.ZodString;
507
- atLeast: z.ZodNumber;
508
- perMs: z.ZodNumber;
509
- }, z.core.$strip>, z.ZodObject<{
510
- id: z.ZodString;
511
- kind: z.ZodLiteral<"distinct">;
512
- ref: z.ZodString;
513
- path: z.ZodString;
514
- atLeast: z.ZodNumber;
515
- }, z.core.$strip>], "kind">>>;
516
- patternV2: z.ZodOptional<z.ZodObject<{
334
+ pattern: z.ZodObject<{
517
335
  version: z.ZodDefault<z.ZodLiteral<"2">>;
518
336
  root: z.ZodType<any, unknown, z.core.$ZodTypeInternals<any, unknown>>;
519
337
  partitionBy: z.ZodDefault<z.ZodArray<z.ZodObject<{
@@ -546,7 +364,7 @@ export declare const CompositeTriggerDefinitionSchema: z.ZodObject<{
546
364
  maxSemanticEvaluations: z.ZodDefault<z.ZodNumber>;
547
365
  maxBufferedEvents: z.ZodDefault<z.ZodNumber>;
548
366
  }, z.core.$strict>>;
549
- }, z.core.$strict>>;
367
+ }, z.core.$strict>;
550
368
  eventTime: z.ZodOptional<z.ZodObject<{
551
369
  allowedLatenessMs: z.ZodNumber;
552
370
  }, z.core.$strict>>;
@@ -559,26 +377,6 @@ export declare const CompositeTriggerDefinitionSchema: z.ZodObject<{
559
377
  completeOnGoal: z.ZodDefault<z.ZodBoolean>;
560
378
  }, z.core.$strip>>;
561
379
  withinMs: z.ZodNumber;
562
- correlation: z.ZodOptional<z.ZodObject<{
563
- deterministic: z.ZodOptional<z.ZodObject<{
564
- kind: z.ZodLiteral<"same_value">;
565
- fields: z.ZodArray<z.ZodObject<{
566
- ref: z.ZodString;
567
- path: z.ZodString;
568
- }, z.core.$strip>>;
569
- }, z.core.$strip>>;
570
- semantic: z.ZodOptional<z.ZodObject<{
571
- instruction: z.ZodString;
572
- input: z.ZodArray<z.ZodString>;
573
- matchThreshold: z.ZodNumber;
574
- rejectThreshold: z.ZodNumber;
575
- uncertain: z.ZodDefault<z.ZodEnum<{
576
- match: "match";
577
- reject: "reject";
578
- escalate: "escalate";
579
- }>>;
580
- }, z.core.$strip>>;
581
- }, z.core.$strip>>;
582
380
  target: z.ZodOptional<z.ZodObject<{
583
381
  runtime: z.ZodString;
584
382
  kind: z.ZodEnum<{
@@ -689,7 +487,7 @@ export declare const TriggerSourceEventSchema: z.ZodObject<{
689
487
  payloadHash: z.ZodOptional<z.ZodString>;
690
488
  data: z.ZodRecord<z.ZodString, z.ZodUnknown>;
691
489
  }, z.core.$strip>;
692
- export declare const CompositeCorrelationDecisionSchema: z.ZodObject<{
490
+ export declare const PatternSemanticDecisionSchema: z.ZodObject<{
693
491
  evaluator: z.ZodString;
694
492
  outcome: z.ZodEnum<{
695
493
  match: "match";
@@ -718,6 +516,7 @@ export declare const PatternMatchStateSchema: z.ZodObject<{
718
516
  }>;
719
517
  signature: z.ZodOptional<z.ZodString>;
720
518
  maxObservedOccurredAt: z.ZodOptional<z.ZodString>;
519
+ completedAt: z.ZodOptional<z.ZodString>;
721
520
  semanticDecisions: z.ZodDefault<z.ZodArray<z.ZodObject<{
722
521
  nodeId: z.ZodString;
723
522
  decision: z.ZodObject<{
@@ -737,8 +536,8 @@ export declare const PatternMatchStateSchema: z.ZodObject<{
737
536
  }, z.core.$strict>>>;
738
537
  }, z.core.$strict>;
739
538
  export declare const TriggerMatchRecordSchema: z.ZodObject<{
740
- protocolVersion: z.ZodLiteral<"0.1.0">;
741
- schemaVersion: z.ZodLiteral<"trigger.v0.1">;
539
+ protocolVersion: z.ZodLiteral<"0.2.0">;
540
+ schemaVersion: z.ZodLiteral<"trigger.v0.2">;
742
541
  matchId: z.ZodString;
743
542
  triggerId: z.ZodString;
744
543
  triggerVersion: z.ZodString;
@@ -749,7 +548,7 @@ export declare const TriggerMatchRecordSchema: z.ZodObject<{
749
548
  fired: "fired";
750
549
  expired: "expired";
751
550
  }>;
752
- correlationKey: z.ZodNullable<z.ZodString>;
551
+ partitionKey: z.ZodNullable<z.ZodString>;
753
552
  openedAt: z.ZodString;
754
553
  expiresAt: z.ZodString;
755
554
  updatedAt: z.ZodString;
@@ -766,7 +565,7 @@ export declare const TriggerMatchRecordSchema: z.ZodObject<{
766
565
  payloadHash: z.ZodOptional<z.ZodString>;
767
566
  data: z.ZodRecord<z.ZodString, z.ZodUnknown>;
768
567
  }, z.core.$strip>>;
769
- correlationDecision: z.ZodNullable<z.ZodObject<{
568
+ semanticDecision: z.ZodNullable<z.ZodObject<{
770
569
  evaluator: z.ZodString;
771
570
  outcome: z.ZodEnum<{
772
571
  match: "match";
@@ -788,6 +587,7 @@ export declare const TriggerMatchRecordSchema: z.ZodObject<{
788
587
  }>;
789
588
  signature: z.ZodOptional<z.ZodString>;
790
589
  maxObservedOccurredAt: z.ZodOptional<z.ZodString>;
590
+ completedAt: z.ZodOptional<z.ZodString>;
791
591
  semanticDecisions: z.ZodDefault<z.ZodArray<z.ZodObject<{
792
592
  nodeId: z.ZodString;
793
593
  decision: z.ZodObject<{
@@ -811,7 +611,6 @@ export declare const TriggerMatchRecordSchema: z.ZodObject<{
811
611
  }, z.core.$strip>;
812
612
  export type StructuredPredicate = z.infer<typeof StructuredPredicateSchema>;
813
613
  export type TriggerClause = z.infer<typeof TriggerClauseSchema>;
814
- export type TemporalCondition = z.infer<typeof TemporalConditionSchema>;
815
614
  export type EventTimePolicy = z.infer<typeof EventTimePolicySchema>;
816
615
  export type TriggerLifecyclePolicy = z.infer<typeof TriggerLifecyclePolicySchema>;
817
616
  export type ContinuationContextPolicy = z.infer<typeof ContinuationContextPolicySchema>;
@@ -823,7 +622,7 @@ export type CorrelatableEvent = z.infer<typeof CorrelatableEventSchema>;
823
622
  export type TriggerSourceEvent = z.infer<typeof TriggerSourceEventSchema>;
824
623
  export type PatternMatchState = z.infer<typeof PatternMatchStateSchema>;
825
624
  export type TriggerMatchRecord = z.infer<typeof TriggerMatchRecordSchema>;
826
- export type CompositeCorrelationDecision = z.infer<typeof CompositeCorrelationDecisionSchema>;
625
+ export type PatternSemanticDecision = z.infer<typeof PatternSemanticDecisionSchema>;
827
626
  export declare function parseCompositeTriggerDefinition(value: unknown): CompositeTriggerDefinition;
828
627
  export declare function parseCorrelatableEvent(value: unknown): CorrelatableEvent;
829
628
  export declare function parseTriggerMatchRecord(value: unknown): TriggerMatchRecord;
@@ -1,13 +1,11 @@
1
1
  import { z } from 'zod';
2
2
  import { RuntimeTargetSchema } from './schemas.js';
3
3
  import { PatternAstV2DefinitionSchema, PatternMeasureSchema, collectPatternDurationsMs, collectGuaranteedPatternBindings, collectPatternMeasureRefs, collectPatternRefs, } from './patternV2Schemas.js';
4
- export const COMPOSITE_TRIGGER_PROTOCOL_VERSION = '0.1.0';
5
- export const COMPOSITE_TRIGGER_SCHEMA_VERSION = 'trigger.v0.1';
4
+ export const COMPOSITE_TRIGGER_PROTOCOL_VERSION = '0.2.0';
5
+ export const COMPOSITE_TRIGGER_SCHEMA_VERSION = 'trigger.v0.2';
6
6
  const Id = z.string().min(1).max(200);
7
7
  const Timestamp = z.string().datetime({ offset: true });
8
8
  const Scalar = z.union([z.string(), z.number(), z.boolean()]);
9
- const ClockTime = z.string().regex(/^(?:[01]\d|2[0-3]):[0-5]\d$/);
10
- const CalendarDate = z.string().regex(/^\d{4}-\d{2}-\d{2}$/);
11
9
  export const StructuredPredicateSchema = z.discriminatedUnion('op', [
12
10
  z.object({ path: z.string().min(1), op: z.literal('eq'), value: Scalar }),
13
11
  z.object({ path: z.string().min(1), op: z.literal('neq'), value: Scalar }),
@@ -47,83 +45,6 @@ export const TriggerClauseSchema = z.object({
47
45
  arguments: z.record(z.string(), z.unknown()).default({}),
48
46
  where: z.array(StructuredPredicateSchema).default([]),
49
47
  });
50
- const TriggerExpressionSchema = z.discriminatedUnion('kind', [
51
- z.object({ kind: z.literal('allOf'), refs: z.array(Id).min(2) }),
52
- z.object({ kind: z.literal('anyOf'), refs: z.array(Id).min(1) }),
53
- z.object({ kind: z.literal('sequence'), refs: z.array(Id).min(2) }),
54
- z.object({ kind: z.literal('count'), ref: Id, atLeast: z.number().int().min(1) }),
55
- ]);
56
- export const CalendarTemporalConditionSchema = z.object({
57
- id: Id,
58
- kind: z.literal('calendar'),
59
- ref: Id,
60
- timezone: z.string().min(1),
61
- before: ClockTime.optional(),
62
- after: ClockTime.optional(),
63
- weekdays: z.array(z.number().int().min(1).max(7)).min(1).optional(),
64
- dates: z.array(CalendarDate).min(1).optional(),
65
- dateRange: z.object({
66
- start: CalendarDate,
67
- end: CalendarDate,
68
- }).optional(),
69
- dayOfMonth: z.array(z.number().int().min(1).max(31)).min(1).optional(),
70
- }).strict();
71
- export const AbsenceTemporalConditionSchema = z.object({
72
- id: Id,
73
- kind: z.literal('absence'),
74
- ref: Id,
75
- afterRef: Id,
76
- forMs: z.number().int().positive().optional(),
77
- untilLocalTime: ClockTime.optional(),
78
- timezone: z.string().min(1).optional(),
79
- }).superRefine((value, ctx) => {
80
- if (!value.forMs && !value.untilLocalTime) {
81
- ctx.addIssue({
82
- code: 'custom',
83
- message: 'absence requires forMs or untilLocalTime',
84
- });
85
- }
86
- if (value.untilLocalTime && !value.timezone) {
87
- ctx.addIssue({
88
- code: 'custom',
89
- message: 'absence untilLocalTime requires timezone',
90
- });
91
- }
92
- });
93
- export const TemporalConditionSchema = z.discriminatedUnion('kind', [
94
- CalendarTemporalConditionSchema,
95
- AbsenceTemporalConditionSchema,
96
- z.object({ id: Id, kind: z.literal('not'), ref: Id }),
97
- z.object({ id: Id, kind: z.literal('unless'), ref: Id }),
98
- z.object({ id: Id, kind: z.literal('after'), ref: Id, afterRef: Id }),
99
- z.object({ id: Id, kind: z.literal('until'), ref: Id, beforeRef: Id }),
100
- z.object({
101
- id: Id,
102
- kind: z.literal('debounce'),
103
- ref: Id,
104
- forMs: z.number().int().positive(),
105
- }),
106
- z.object({
107
- id: Id,
108
- kind: z.literal('threshold'),
109
- ref: Id,
110
- atLeast: z.number().int().min(1),
111
- }),
112
- z.object({
113
- id: Id,
114
- kind: z.literal('rate'),
115
- ref: Id,
116
- atLeast: z.number().int().min(1),
117
- perMs: z.number().int().positive(),
118
- }),
119
- z.object({
120
- id: Id,
121
- kind: z.literal('distinct'),
122
- ref: Id,
123
- path: z.string().min(1),
124
- atLeast: z.number().int().min(1),
125
- }),
126
- ]);
127
48
  export const DerivedEventProjectionSchema = z.object({
128
49
  key: z.string().regex(/^[A-Za-z_][A-Za-z0-9_-]{0,63}$/),
129
50
  ref: Id,
@@ -187,20 +108,6 @@ export const ContinuationContractSchema = z.object({
187
108
  includeData: true,
188
109
  }),
189
110
  }).strict();
190
- export const DeterministicCorrelationSchema = z.object({
191
- kind: z.literal('same_value'),
192
- fields: z.array(z.object({
193
- ref: Id,
194
- path: z.string().min(1),
195
- })).min(2),
196
- });
197
- export const SemanticCorrelationSchema = z.object({
198
- instruction: z.string().min(1),
199
- input: z.array(z.string().min(1)).min(1),
200
- matchThreshold: z.number().min(0).max(1),
201
- rejectThreshold: z.number().min(0).max(1),
202
- uncertain: z.enum(['escalate', 'reject', 'match']).default('escalate'),
203
- });
204
111
  export const CompositeTriggerDefinitionSchema = z.object({
205
112
  protocolVersion: z.literal(COMPOSITE_TRIGGER_PROTOCOL_VERSION)
206
113
  .default(COMPOSITE_TRIGGER_PROTOCOL_VERSION),
@@ -212,9 +119,7 @@ export const CompositeTriggerDefinitionSchema = z.object({
212
119
  conditionOnly: z.boolean().default(false),
213
120
  continuation: ContinuationContractSchema.optional(),
214
121
  clauses: z.array(TriggerClauseSchema).min(1),
215
- expression: TriggerExpressionSchema,
216
- temporal: z.array(TemporalConditionSchema).default([]),
217
- patternV2: PatternAstV2DefinitionSchema.optional(),
122
+ pattern: PatternAstV2DefinitionSchema,
218
123
  eventTime: EventTimePolicySchema.optional(),
219
124
  lifecycle: TriggerLifecyclePolicySchema.default({
220
125
  oneShot: false,
@@ -222,10 +127,6 @@ export const CompositeTriggerDefinitionSchema = z.object({
222
127
  completeOnGoal: false,
223
128
  }),
224
129
  withinMs: z.number().int().positive().max(1000 * 60 * 60 * 24 * 30),
225
- correlation: z.object({
226
- deterministic: DeterministicCorrelationSchema.optional(),
227
- semantic: SemanticCorrelationSchema.optional(),
228
- }).optional(),
229
130
  target: RuntimeTargetSchema.optional(),
230
131
  derivedEvent: DerivedEventDefinitionSchema.optional(),
231
132
  }).superRefine((value, ctx) => {
@@ -262,25 +163,6 @@ export const CompositeTriggerDefinitionSchema = z.object({
262
163
  if (ids.size !== value.clauses.length) {
263
164
  ctx.addIssue({ code: 'custom', message: 'Trigger clause ids must be unique' });
264
165
  }
265
- const refs = value.expression.kind === 'count'
266
- ? [value.expression.ref]
267
- : value.expression.refs;
268
- for (const ref of refs) {
269
- if (!ids.has(ref)) {
270
- ctx.addIssue({
271
- code: 'custom',
272
- message: `Expression references unknown clause: ${ref}`,
273
- });
274
- }
275
- }
276
- for (const field of value.correlation?.deterministic?.fields ?? []) {
277
- if (!ids.has(field.ref)) {
278
- ctx.addIssue({
279
- code: 'custom',
280
- message: `Correlation references unknown clause: ${field.ref}`,
281
- });
282
- }
283
- }
284
166
  if (value.derivedEvent) {
285
167
  const projectionKeys = new Set();
286
168
  const measureKeys = new Set();
@@ -353,17 +235,17 @@ export const CompositeTriggerDefinitionSchema = z.object({
353
235
  });
354
236
  }
355
237
  }
356
- if (value.patternV2) {
357
- const patternRefs = collectPatternRefs(value.patternV2.root);
238
+ {
239
+ const patternRefs = collectPatternRefs(value.pattern.root);
358
240
  for (const ref of patternRefs) {
359
241
  if (!ids.has(ref)) {
360
242
  ctx.addIssue({
361
243
  code: 'custom',
362
- message: `Pattern AST v2 references unknown clause: ${ref}`,
244
+ message: `Pattern AST references unknown clause: ${ref}`,
363
245
  });
364
246
  }
365
247
  }
366
- for (const dimension of value.patternV2.partitionBy) {
248
+ for (const dimension of value.pattern.partitionBy) {
367
249
  const dimensionRefs = new Set();
368
250
  for (const field of dimension.fields) {
369
251
  if (!ids.has(field.ref)) {
@@ -389,12 +271,12 @@ export const CompositeTriggerDefinitionSchema = z.object({
389
271
  }
390
272
  }
391
273
  }
392
- const guaranteedPatternRefs = collectGuaranteedPatternBindings(value.patternV2.root);
393
- if (typeof value.patternV2.selection.afterMatch === 'object' &&
394
- !guaranteedPatternRefs.includes(value.patternV2.selection.afterMatch.ref)) {
274
+ const guaranteedPatternRefs = collectGuaranteedPatternBindings(value.pattern.root);
275
+ if (typeof value.pattern.selection.afterMatch === 'object' &&
276
+ !guaranteedPatternRefs.includes(value.pattern.selection.afterMatch.ref)) {
395
277
  ctx.addIssue({
396
278
  code: 'custom',
397
- message: `Pattern afterMatch ref is not guaranteed by every match: ${value.patternV2.selection.afterMatch.ref}`,
279
+ message: `Pattern afterMatch ref is not guaranteed by every match: ${value.pattern.selection.afterMatch.ref}`,
398
280
  });
399
281
  }
400
282
  for (const measure of value.derivedEvent?.measures ?? []) {
@@ -407,71 +289,15 @@ export const CompositeTriggerDefinitionSchema = z.object({
407
289
  }
408
290
  }
409
291
  }
410
- const oversized = collectPatternDurationsMs(value.patternV2.root)
292
+ const oversized = collectPatternDurationsMs(value.pattern.root)
411
293
  .filter((duration) => duration > value.withinMs);
412
294
  if (oversized.length) {
413
295
  ctx.addIssue({
414
296
  code: 'custom',
415
- message: `Pattern AST v2 duration exceeds trigger withinMs: ${Math.max(...oversized)} > ${value.withinMs}`,
297
+ message: `Pattern AST duration exceeds trigger withinMs: ${Math.max(...oversized)} > ${value.withinMs}`,
416
298
  });
417
299
  }
418
300
  }
419
- const conditionIds = new Set();
420
- for (const condition of value.temporal) {
421
- if (conditionIds.has(condition.id)) {
422
- ctx.addIssue({
423
- code: 'custom',
424
- message: `Temporal condition id must be unique: ${condition.id}`,
425
- });
426
- }
427
- conditionIds.add(condition.id);
428
- const conditionRefs = [];
429
- if ('ref' in condition)
430
- conditionRefs.push(condition.ref);
431
- if ('afterRef' in condition)
432
- conditionRefs.push(condition.afterRef);
433
- if ('beforeRef' in condition)
434
- conditionRefs.push(condition.beforeRef);
435
- for (const ref of conditionRefs) {
436
- if (!ids.has(ref)) {
437
- ctx.addIssue({
438
- code: 'custom',
439
- message: `Temporal condition ${condition.id} references unknown clause: ${ref}`,
440
- });
441
- }
442
- }
443
- if (condition.kind === 'calendar') {
444
- try {
445
- new Intl.DateTimeFormat('en-US', { timeZone: condition.timezone });
446
- }
447
- catch {
448
- ctx.addIssue({
449
- code: 'custom',
450
- message: `Invalid IANA timezone: ${condition.timezone}`,
451
- });
452
- }
453
- if (condition.before &&
454
- condition.after &&
455
- condition.before === condition.after) {
456
- ctx.addIssue({
457
- code: 'custom',
458
- message: 'calendar before and after cannot be identical',
459
- });
460
- }
461
- }
462
- if (condition.kind === 'absence' &&
463
- condition.timezone) {
464
- try {
465
- new Intl.DateTimeFormat('en-US', { timeZone: condition.timezone });
466
- }
467
- catch {
468
- ctx.addIssue({
469
- code: 'custom',
470
- message: `Invalid IANA timezone: ${condition.timezone}`,
471
- });
472
- }
473
- }
474
- }
475
301
  });
476
302
  export const CorrelatableEventSchema = z.object({
477
303
  traceId: Id,
@@ -507,7 +333,7 @@ export const TriggerSourceEventSchema = z.object({
507
333
  payloadHash: z.string().regex(/^[a-f0-9]{64}$/).optional(),
508
334
  data: z.record(z.string(), z.unknown()),
509
335
  });
510
- export const CompositeCorrelationDecisionSchema = z.object({
336
+ export const PatternSemanticDecisionSchema = z.object({
511
337
  evaluator: z.string().min(1),
512
338
  outcome: z.enum(['match', 'reject', 'uncertain']),
513
339
  probability: z.number().min(0).max(1),
@@ -529,9 +355,10 @@ export const PatternMatchStateSchema = z.object({
529
355
  role: z.enum(['buffer', 'match']),
530
356
  signature: z.string().min(1).optional(),
531
357
  maxObservedOccurredAt: Timestamp.optional(),
358
+ completedAt: Timestamp.optional(),
532
359
  semanticDecisions: z.array(z.object({
533
360
  nodeId: Id,
534
- decision: CompositeCorrelationDecisionSchema,
361
+ decision: PatternSemanticDecisionSchema,
535
362
  }).strict()).default([]),
536
363
  }).strict();
537
364
  export const TriggerMatchRecordSchema = z.object({
@@ -541,12 +368,12 @@ export const TriggerMatchRecordSchema = z.object({
541
368
  triggerId: Id,
542
369
  triggerVersion: z.string().min(1),
543
370
  status: TriggerMatchStatusSchema,
544
- correlationKey: z.string().nullable(),
371
+ partitionKey: z.string().nullable(),
545
372
  openedAt: Timestamp,
546
373
  expiresAt: Timestamp,
547
374
  updatedAt: Timestamp,
548
375
  sourceEvents: z.array(TriggerSourceEventSchema),
549
- correlationDecision: CompositeCorrelationDecisionSchema.nullable(),
376
+ semanticDecision: PatternSemanticDecisionSchema.nullable(),
550
377
  patternState: PatternMatchStateSchema.optional(),
551
378
  firedWakeId: Id.nullable(),
552
379
  derivedEventIds: z.array(Id).default([]),
@@ -1,6 +1,6 @@
1
1
  export declare const EVENT_INTELLIGENCE_PROTOCOL: "mcp-event-intelligence";
2
- export declare const EVENT_INTELLIGENCE_PROTOCOL_VERSION: "0.1.0";
3
- export declare const EVENT_INTELLIGENCE_SCHEMA_VERSION: "ei.v0.1";
2
+ export declare const EVENT_INTELLIGENCE_PROTOCOL_VERSION: "0.2.0";
3
+ export declare const EVENT_INTELLIGENCE_SCHEMA_VERSION: "ei.v0.2";
4
4
  export declare const EVENT_INTELLIGENCE_COMPATIBILITY: {
5
5
  readonly mcpEvents: "experimental-ext-triggers-events/design-sketch";
6
6
  readonly mcpCore: "2026-07-28";
@@ -1,6 +1,6 @@
1
1
  export const EVENT_INTELLIGENCE_PROTOCOL = 'mcp-event-intelligence';
2
- export const EVENT_INTELLIGENCE_PROTOCOL_VERSION = '0.1.0';
3
- export const EVENT_INTELLIGENCE_SCHEMA_VERSION = 'ei.v0.1';
2
+ export const EVENT_INTELLIGENCE_PROTOCOL_VERSION = '0.2.0';
3
+ export const EVENT_INTELLIGENCE_SCHEMA_VERSION = 'ei.v0.2';
4
4
  export const EVENT_INTELLIGENCE_COMPATIBILITY = {
5
5
  mcpEvents: 'experimental-ext-triggers-events/design-sketch',
6
6
  mcpCore: '2026-07-28',
@@ -18,10 +18,16 @@ export interface PatternV2SemanticTrace {
18
18
  candidateSignature: string;
19
19
  decision: SemanticDecision;
20
20
  }
21
+ export interface PatternV2SemanticCache {
22
+ get(key: string): Promise<SemanticDecision | null> | SemanticDecision | null;
23
+ set(key: string, decision: SemanticDecision): Promise<void> | void;
24
+ }
21
25
  export interface PatternV2Evaluation {
22
26
  matches: PatternV2Candidate[];
23
27
  pending: PatternV2Candidate[];
24
28
  semanticEvaluations: number;
29
+ semanticCacheHits: number;
30
+ semanticCacheMisses: number;
25
31
  semanticTrace: PatternV2SemanticTrace[];
26
32
  truncated: boolean;
27
33
  }
@@ -33,11 +39,13 @@ export declare function evaluatePatternAggregate(candidate: PatternV2Candidate,
33
39
  percentile?: number;
34
40
  }): unknown;
35
41
  export declare function evaluatePatternMeasure(candidate: PatternV2Candidate, measure: PatternMeasure): unknown;
36
- export declare function evaluatePatternV2({ definition, events, evaluator, now, allowedLatenessMs, }: {
42
+ export declare function evaluatePatternV2({ definition, events, evaluator, now, allowedLatenessMs, semanticCache, semanticCacheNamespace, }: {
37
43
  definition: PatternAstV2Definition;
38
44
  events: TriggerSourceEvent[];
39
45
  evaluator?: SemanticEvaluator | null;
40
46
  now?: Date;
41
47
  allowedLatenessMs?: number;
48
+ semanticCache?: PatternV2SemanticCache | null;
49
+ semanticCacheNamespace?: string;
42
50
  }): Promise<PatternV2Evaluation>;
43
51
  export declare function patternV2CandidateSignature(candidate: PatternV2Candidate): string;