mcp-event-intelligence 0.1.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 +80 -0
- package/LICENSE +201 -0
- package/README.md +298 -0
- package/SECURITY.md +42 -0
- package/bin/mcp-event-intelligence.mjs +52 -0
- package/dist/src/composite/engine.d.ts +87 -0
- package/dist/src/composite/engine.js +667 -0
- package/dist/src/composite/temporal.d.ts +32 -0
- package/dist/src/composite/temporal.js +317 -0
- package/dist/src/intelligenceProtocol/audit.d.ts +19 -0
- package/dist/src/intelligenceProtocol/audit.js +56 -0
- package/dist/src/intelligenceProtocol/canonical.d.ts +2 -0
- package/dist/src/intelligenceProtocol/canonical.js +21 -0
- package/dist/src/intelligenceProtocol/index.d.ts +12 -0
- package/dist/src/intelligenceProtocol/index.js +8 -0
- package/dist/src/intelligenceProtocol/invariants.d.ts +3 -0
- package/dist/src/intelligenceProtocol/invariants.js +36 -0
- package/dist/src/intelligenceProtocol/lifecycle.d.ts +4 -0
- package/dist/src/intelligenceProtocol/lifecycle.js +24 -0
- package/dist/src/intelligenceProtocol/mapper.d.ts +14 -0
- package/dist/src/intelligenceProtocol/mapper.js +28 -0
- package/dist/src/intelligenceProtocol/schemas.d.ts +325 -0
- package/dist/src/intelligenceProtocol/schemas.js +182 -0
- package/dist/src/intelligenceProtocol/triggerSchemas.d.ts +488 -0
- package/dist/src/intelligenceProtocol/triggerSchemas.js +379 -0
- package/dist/src/intelligenceProtocol/version.d.ts +7 -0
- package/dist/src/intelligenceProtocol/version.js +7 -0
- package/dist/src/mcpEvents/consumer.d.ts +7 -0
- package/dist/src/mcpEvents/consumer.js +14 -0
- package/dist/src/mcpEvents/server.d.ts +41 -0
- package/dist/src/mcpEvents/server.js +122 -0
- package/dist/src/protocol/types.d.ts +37 -0
- package/dist/src/protocol/types.js +1 -0
- package/dist/src/semantic/conditionEngine.d.ts +7 -0
- package/dist/src/semantic/conditionEngine.js +65 -0
- package/dist/src/semantic/types.d.ts +31 -0
- package/dist/src/semantic/types.js +1 -0
- package/dist/src/semantic/typesafeJevEvaluator.d.ts +23 -0
- package/dist/src/semantic/typesafeJevEvaluator.js +95 -0
- package/package.json +85 -0
- package/scripts/host-integration.d.mts +86 -0
- package/scripts/host-integration.mjs +216 -0
- package/scripts/lib/composite-event-consumer.mjs +172 -0
- package/scripts/lib/composite-wake-coordinator.mjs +185 -0
- package/scripts/lib/derived-contract-registry.mjs +210 -0
- package/scripts/lib/derived-event-coordinator.mjs +242 -0
- package/scripts/lib/event-processor.mjs +409 -0
- package/scripts/lib/generic-runtime-wake.mjs +76 -0
- package/scripts/lib/github-mcp-events-adapter.mjs +66 -0
- package/scripts/lib/github-webhook.mjs +88 -0
- package/scripts/lib/http-wake-deliverer.mjs +31 -0
- package/scripts/lib/local-event-intelligence-runtime.mjs +193 -0
- package/scripts/lib/mcp-events-client.mjs +519 -0
- package/scripts/lib/persistent-event-store.mjs +769 -0
- package/scripts/lib/temporal-deadline-scheduler.mjs +111 -0
- package/scripts/lib/trigger-control-plane.mjs +939 -0
- package/scripts/lib/trigger-inspector.mjs +631 -0
- package/scripts/lib/wake-signature.mjs +10 -0
- package/scripts/mcp-stdio-server.mjs +380 -0
- package/scripts/mcp-stdio.mjs +3 -0
- package/scripts/run-tests.mjs +51 -0
- package/scripts/service.mjs +756 -0
- package/server.json +68 -0
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
export class TemporalDeadlineScheduler {
|
|
2
|
+
constructor({
|
|
3
|
+
store,
|
|
4
|
+
compositeEventConsumer,
|
|
5
|
+
now = () => new Date(),
|
|
6
|
+
intervalMs = 1000,
|
|
7
|
+
}) {
|
|
8
|
+
this.store = store;
|
|
9
|
+
this.compositeEventConsumer = compositeEventConsumer;
|
|
10
|
+
this.now = now;
|
|
11
|
+
this.intervalMs = Math.max(250, Number(intervalMs) || 1000);
|
|
12
|
+
this.timer = null;
|
|
13
|
+
this.running = false;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
async runDue() {
|
|
17
|
+
if (this.running) return [];
|
|
18
|
+
this.running = true;
|
|
19
|
+
|
|
20
|
+
try {
|
|
21
|
+
const now = this.now();
|
|
22
|
+
const due = this.store.listDueTemporalDeadlines(now.toISOString());
|
|
23
|
+
const outcomes = [];
|
|
24
|
+
|
|
25
|
+
for (const deadline of due) {
|
|
26
|
+
const latest = this.store.getTemporalDeadline(deadline.deadlineId);
|
|
27
|
+
if (!latest || latest.status !== 'pending') continue;
|
|
28
|
+
|
|
29
|
+
const match = this.store.listTriggerMatches(deadline.triggerId)
|
|
30
|
+
.filter((record) => record.matchId === deadline.matchId)
|
|
31
|
+
.sort((a, b) => Date.parse(b.updatedAt) - Date.parse(a.updatedAt))[0];
|
|
32
|
+
|
|
33
|
+
if (
|
|
34
|
+
!match ||
|
|
35
|
+
match.status === 'expired' ||
|
|
36
|
+
match.status === 'matched' ||
|
|
37
|
+
match.status === 'emitted' ||
|
|
38
|
+
match.status === 'fired'
|
|
39
|
+
) {
|
|
40
|
+
await this.store.setTemporalDeadlineStatus(
|
|
41
|
+
deadline.deadlineId,
|
|
42
|
+
'cancelled',
|
|
43
|
+
);
|
|
44
|
+
outcomes.push({
|
|
45
|
+
deadlineId: deadline.deadlineId,
|
|
46
|
+
status: 'cancelled_terminal_match',
|
|
47
|
+
});
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const result = await this.compositeEventConsumer.ingestCorrelatable({
|
|
52
|
+
traceId: `timer:${deadline.deadlineId}`,
|
|
53
|
+
sourceEventId: `timer:${deadline.deadlineId}`,
|
|
54
|
+
name: 'event-intelligence.timer.reached',
|
|
55
|
+
serverId: 'event-intelligence:timer',
|
|
56
|
+
provider: 'event-intelligence',
|
|
57
|
+
occurredAt: now.toISOString(),
|
|
58
|
+
data: {
|
|
59
|
+
deadlineId: deadline.deadlineId,
|
|
60
|
+
triggerId: deadline.triggerId,
|
|
61
|
+
triggerVersion: deadline.triggerVersion,
|
|
62
|
+
matchId: deadline.matchId,
|
|
63
|
+
conditionId: deadline.conditionId,
|
|
64
|
+
dueAt: deadline.dueAt,
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
if (result.results.length > 0) {
|
|
69
|
+
await this.store.setTemporalDeadlineStatus(
|
|
70
|
+
deadline.deadlineId,
|
|
71
|
+
'fired',
|
|
72
|
+
);
|
|
73
|
+
outcomes.push({
|
|
74
|
+
deadlineId: deadline.deadlineId,
|
|
75
|
+
status: 'fired',
|
|
76
|
+
results: result.results,
|
|
77
|
+
deliveries: result.deliveries,
|
|
78
|
+
});
|
|
79
|
+
} else {
|
|
80
|
+
outcomes.push({
|
|
81
|
+
deadlineId: deadline.deadlineId,
|
|
82
|
+
status: 'deferred',
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return outcomes;
|
|
88
|
+
} finally {
|
|
89
|
+
this.running = false;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
start() {
|
|
94
|
+
if (this.timer) return;
|
|
95
|
+
this.timer = setInterval(() => {
|
|
96
|
+
this.runDue().catch((error) => {
|
|
97
|
+
console.error(JSON.stringify({
|
|
98
|
+
message: 'temporal_deadline_scheduler_error',
|
|
99
|
+
error: error instanceof Error ? error.message : String(error),
|
|
100
|
+
}));
|
|
101
|
+
});
|
|
102
|
+
}, this.intervalMs);
|
|
103
|
+
this.timer.unref?.();
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
stop() {
|
|
107
|
+
if (!this.timer) return;
|
|
108
|
+
clearInterval(this.timer);
|
|
109
|
+
this.timer = null;
|
|
110
|
+
}
|
|
111
|
+
}
|