mcp-event-intelligence 0.1.0 → 0.2.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 +73 -0
- package/README.md +110 -5
- package/bin/mcp-event-intelligence.mjs +5 -1
- package/dist/src/composite/derivedGraph.d.ts +4 -0
- package/dist/src/composite/derivedGraph.js +46 -0
- package/dist/src/composite/engine.d.ts +3 -64
- package/dist/src/composite/engine.js +26 -343
- package/dist/src/composite/matching.d.ts +8 -0
- package/dist/src/composite/matching.js +109 -0
- package/dist/src/composite/runtimeSupport.d.ts +24 -0
- package/dist/src/composite/runtimeSupport.js +176 -0
- package/dist/src/composite/store.d.ts +59 -0
- package/dist/src/composite/store.js +1 -0
- package/dist/src/intelligenceProtocol/schemas.d.ts +9 -7
- package/dist/src/intelligenceProtocol/schemas.js +1 -0
- package/dist/src/intelligenceProtocol/triggerSchemas.d.ts +6 -6
- package/dist/src/mcpEvents/erpnextProvider.d.ts +20 -0
- package/dist/src/mcpEvents/erpnextProvider.js +80 -0
- package/dist/src/mcpEvents/provider.d.ts +48 -0
- package/dist/src/mcpEvents/provider.js +296 -0
- package/package.json +9 -1
- package/scripts/host-integration.d.mts +34 -4
- package/scripts/host-integration.mjs +44 -1
- package/scripts/lib/composite-wake-coordinator.mjs +233 -9
- package/scripts/lib/event-processor.mjs +235 -20
- package/scripts/lib/local-event-intelligence-runtime.mjs +227 -82
- package/scripts/lib/mcp-events-client.mjs +173 -66
- package/scripts/lib/persistent-event-store.mjs +308 -1
- package/scripts/lib/wake-retry-scheduler.mjs +94 -0
- package/scripts/mcp-stdio-server.mjs +1 -1
- package/scripts/service.mjs +20 -0
- package/server.json +2 -2
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
import { McpEventOccurrenceSchema, } from '../intelligenceProtocol/schemas.js';
|
|
2
|
+
export const MCP_EVENTS_CAPABILITY_KEY = 'io.modelcontextprotocol.experimental/events';
|
|
3
|
+
export const MCP_EVENTS_CAPABILITY = Object.freeze({
|
|
4
|
+
status: 'draft',
|
|
5
|
+
designDate: '2026-02-19',
|
|
6
|
+
methods: ['events/list', 'events/poll'],
|
|
7
|
+
listChanged: false,
|
|
8
|
+
});
|
|
9
|
+
const ALLOWED_DELIVERY = new Set(['poll', 'push', 'webhook']);
|
|
10
|
+
function assertRecord(value, message) {
|
|
11
|
+
if (!value || Array.isArray(value) || typeof value !== 'object') {
|
|
12
|
+
throw new Error(message);
|
|
13
|
+
}
|
|
14
|
+
return value;
|
|
15
|
+
}
|
|
16
|
+
function optionalFiniteNumber(value, name) {
|
|
17
|
+
if (value === undefined)
|
|
18
|
+
return undefined;
|
|
19
|
+
if (typeof value !== 'number' || !Number.isFinite(value) || value < 0) {
|
|
20
|
+
throw new Error(`${name} must be a non-negative finite number`);
|
|
21
|
+
}
|
|
22
|
+
return value;
|
|
23
|
+
}
|
|
24
|
+
function normalizeDescriptor(input) {
|
|
25
|
+
const raw = assertRecord(input, 'MCP event descriptor must be an object');
|
|
26
|
+
const name = String(raw.name ?? '').trim();
|
|
27
|
+
if (!name)
|
|
28
|
+
throw new Error('MCP event descriptor requires name');
|
|
29
|
+
const deliveryRaw = Array.isArray(raw.delivery) ? raw.delivery : ['poll'];
|
|
30
|
+
const delivery = deliveryRaw.map((entry) => String(entry));
|
|
31
|
+
if (delivery.length === 0 ||
|
|
32
|
+
delivery.some((entry) => !ALLOWED_DELIVERY.has(entry))) {
|
|
33
|
+
throw new Error(`MCP event descriptor ${name} has invalid delivery modes`);
|
|
34
|
+
}
|
|
35
|
+
if (!delivery.includes('poll')) {
|
|
36
|
+
throw new Error(`MCP provider event ${name} must advertise poll delivery in v0.1`);
|
|
37
|
+
}
|
|
38
|
+
const inputSchema = raw.inputSchema === undefined
|
|
39
|
+
? {}
|
|
40
|
+
: assertRecord(raw.inputSchema, `MCP event descriptor ${name} inputSchema must be an object`);
|
|
41
|
+
const payloadSchema = raw.payloadSchema === undefined
|
|
42
|
+
? {}
|
|
43
|
+
: assertRecord(raw.payloadSchema, `MCP event descriptor ${name} payloadSchema must be an object`);
|
|
44
|
+
return {
|
|
45
|
+
name,
|
|
46
|
+
description: String(raw.description ?? ''),
|
|
47
|
+
delivery: delivery,
|
|
48
|
+
inputSchema,
|
|
49
|
+
payloadSchema,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
function schemaTypes(schema) {
|
|
53
|
+
if (Array.isArray(schema.type)) {
|
|
54
|
+
return schema.type.map((entry) => String(entry));
|
|
55
|
+
}
|
|
56
|
+
return schema.type === undefined ? [] : [String(schema.type)];
|
|
57
|
+
}
|
|
58
|
+
export function assertJsonSchemaValue(schemaInput, value, path = '$') {
|
|
59
|
+
const schema = assertRecord(schemaInput, `Invalid JSON Schema at ${path}`);
|
|
60
|
+
if (Object.prototype.hasOwnProperty.call(schema, 'const') &&
|
|
61
|
+
!Object.is(schema.const, value)) {
|
|
62
|
+
throw new Error(`MCP event payload violates schema at ${path}: const mismatch`);
|
|
63
|
+
}
|
|
64
|
+
if (Array.isArray(schema.enum) &&
|
|
65
|
+
!schema.enum.some((entry) => Object.is(entry, value))) {
|
|
66
|
+
throw new Error(`MCP event payload violates schema at ${path}: value not in enum`);
|
|
67
|
+
}
|
|
68
|
+
const types = schemaTypes(schema);
|
|
69
|
+
if (types.length > 0) {
|
|
70
|
+
const matches = types.some((type) => {
|
|
71
|
+
if (type === 'null')
|
|
72
|
+
return value === null;
|
|
73
|
+
if (type === 'array')
|
|
74
|
+
return Array.isArray(value);
|
|
75
|
+
if (type === 'object') {
|
|
76
|
+
return value !== null && !Array.isArray(value) && typeof value === 'object';
|
|
77
|
+
}
|
|
78
|
+
if (type === 'integer')
|
|
79
|
+
return Number.isInteger(value);
|
|
80
|
+
if (type === 'number') {
|
|
81
|
+
return typeof value === 'number' && Number.isFinite(value);
|
|
82
|
+
}
|
|
83
|
+
if (type === 'string')
|
|
84
|
+
return typeof value === 'string';
|
|
85
|
+
if (type === 'boolean')
|
|
86
|
+
return typeof value === 'boolean';
|
|
87
|
+
return false;
|
|
88
|
+
});
|
|
89
|
+
if (!matches) {
|
|
90
|
+
throw new Error(`MCP event payload violates schema at ${path}: expected ${types.join('|')}`);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
if (typeof value === 'string') {
|
|
94
|
+
if (typeof schema.minLength === 'number' && value.length < schema.minLength) {
|
|
95
|
+
throw new Error(`MCP event payload violates schema at ${path}: string too short`);
|
|
96
|
+
}
|
|
97
|
+
if (typeof schema.maxLength === 'number' && value.length > schema.maxLength) {
|
|
98
|
+
throw new Error(`MCP event payload violates schema at ${path}: string too long`);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
if (typeof value === 'number' && Number.isFinite(value)) {
|
|
102
|
+
if (typeof schema.minimum === 'number' && value < schema.minimum) {
|
|
103
|
+
throw new Error(`MCP event payload violates schema at ${path}: below minimum`);
|
|
104
|
+
}
|
|
105
|
+
if (typeof schema.maximum === 'number' && value > schema.maximum) {
|
|
106
|
+
throw new Error(`MCP event payload violates schema at ${path}: above maximum`);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
if (value !== null && !Array.isArray(value) && typeof value === 'object') {
|
|
110
|
+
const record = value;
|
|
111
|
+
const required = Array.isArray(schema.required)
|
|
112
|
+
? schema.required.map((entry) => String(entry))
|
|
113
|
+
: [];
|
|
114
|
+
for (const key of required) {
|
|
115
|
+
if (!Object.prototype.hasOwnProperty.call(record, key)) {
|
|
116
|
+
throw new Error(`MCP event payload violates schema at ${path}: missing required property ${key}`);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
const properties = schema.properties &&
|
|
120
|
+
!Array.isArray(schema.properties) &&
|
|
121
|
+
typeof schema.properties === 'object'
|
|
122
|
+
? schema.properties
|
|
123
|
+
: {};
|
|
124
|
+
for (const [key, childSchema] of Object.entries(properties)) {
|
|
125
|
+
if (Object.prototype.hasOwnProperty.call(record, key) &&
|
|
126
|
+
childSchema &&
|
|
127
|
+
!Array.isArray(childSchema) &&
|
|
128
|
+
typeof childSchema === 'object') {
|
|
129
|
+
assertJsonSchemaValue(childSchema, record[key], `${path}.${key}`);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
if (schema.additionalProperties === false) {
|
|
133
|
+
for (const key of Object.keys(record)) {
|
|
134
|
+
if (!Object.prototype.hasOwnProperty.call(properties, key)) {
|
|
135
|
+
throw new Error(`MCP event payload violates schema at ${path}: unexpected property ${key}`);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
if (Array.isArray(value) &&
|
|
141
|
+
schema.items &&
|
|
142
|
+
!Array.isArray(schema.items) &&
|
|
143
|
+
typeof schema.items === 'object') {
|
|
144
|
+
value.forEach((entry, index) => assertJsonSchemaValue(schema.items, entry, `${path}[${index}]`));
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
function normalizePollParams(paramsInput) {
|
|
148
|
+
const params = assertRecord(paramsInput ?? {}, 'events/poll params must be an object');
|
|
149
|
+
const name = String(params.name ?? '').trim();
|
|
150
|
+
if (!name)
|
|
151
|
+
throw new Error('events/poll requires name');
|
|
152
|
+
const cursor = params.cursor === undefined || params.cursor === null
|
|
153
|
+
? null
|
|
154
|
+
: String(params.cursor);
|
|
155
|
+
const argumentsValue = params.arguments === undefined
|
|
156
|
+
? {}
|
|
157
|
+
: assertRecord(params.arguments, 'events/poll arguments must be an object');
|
|
158
|
+
const maxAgeMs = optionalFiniteNumber(params.maxAgeMs, 'maxAgeMs');
|
|
159
|
+
const maxEventsRaw = params.maxEvents ?? 50;
|
|
160
|
+
if (typeof maxEventsRaw !== 'number' ||
|
|
161
|
+
!Number.isInteger(maxEventsRaw) ||
|
|
162
|
+
maxEventsRaw < 1 ||
|
|
163
|
+
maxEventsRaw > 500) {
|
|
164
|
+
throw new Error('maxEvents must be an integer between 1 and 500');
|
|
165
|
+
}
|
|
166
|
+
return {
|
|
167
|
+
name,
|
|
168
|
+
arguments: argumentsValue,
|
|
169
|
+
cursor,
|
|
170
|
+
...(maxAgeMs === undefined ? {} : { maxAgeMs }),
|
|
171
|
+
maxEvents: maxEventsRaw,
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
export class McpEventsProvider {
|
|
175
|
+
events = new Map();
|
|
176
|
+
supportedVersions;
|
|
177
|
+
instructions;
|
|
178
|
+
constructor(options) {
|
|
179
|
+
if (!options || !Array.isArray(options.events)) {
|
|
180
|
+
throw new Error('MCP Events provider requires events[]');
|
|
181
|
+
}
|
|
182
|
+
for (const input of options.events) {
|
|
183
|
+
if (!input || typeof input.poll !== 'function') {
|
|
184
|
+
throw new Error('MCP provider event requires poll()');
|
|
185
|
+
}
|
|
186
|
+
const descriptor = normalizeDescriptor(input.descriptor);
|
|
187
|
+
if (this.events.has(descriptor.name)) {
|
|
188
|
+
throw new Error(`Duplicate MCP provider event: ${descriptor.name}`);
|
|
189
|
+
}
|
|
190
|
+
this.events.set(descriptor.name, {
|
|
191
|
+
descriptor,
|
|
192
|
+
poll: input.poll,
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
this.supportedVersions =
|
|
196
|
+
options.supportedVersions?.map(String).filter(Boolean) ?? ['2026-07-28'];
|
|
197
|
+
this.instructions =
|
|
198
|
+
options.instructions ??
|
|
199
|
+
'Experimental MCP Events provider compatibility adapter. Events follow the Triggers & Events design sketch; this is not finalized MCP conformance.';
|
|
200
|
+
}
|
|
201
|
+
canHandle(method) {
|
|
202
|
+
return (method === 'server/discover' ||
|
|
203
|
+
method === 'events/list' ||
|
|
204
|
+
method === 'events/poll');
|
|
205
|
+
}
|
|
206
|
+
listEvents() {
|
|
207
|
+
return [...this.events.values()].map(({ descriptor }) => descriptor);
|
|
208
|
+
}
|
|
209
|
+
async handleRequest(request, context) {
|
|
210
|
+
try {
|
|
211
|
+
switch (request.method) {
|
|
212
|
+
case 'server/discover':
|
|
213
|
+
return this.ok(request.id, {
|
|
214
|
+
supportedVersions: this.supportedVersions,
|
|
215
|
+
capabilities: {
|
|
216
|
+
experimental: {
|
|
217
|
+
[MCP_EVENTS_CAPABILITY_KEY]: MCP_EVENTS_CAPABILITY,
|
|
218
|
+
},
|
|
219
|
+
},
|
|
220
|
+
instructions: this.instructions,
|
|
221
|
+
});
|
|
222
|
+
case 'events/list':
|
|
223
|
+
return this.ok(request.id, {
|
|
224
|
+
events: this.listEvents(),
|
|
225
|
+
});
|
|
226
|
+
case 'events/poll':
|
|
227
|
+
return this.ok(request.id, await this.poll(request.params, context));
|
|
228
|
+
default:
|
|
229
|
+
return this.error(request.id, -32601, `Method not found: ${request.method}`);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
catch (error) {
|
|
233
|
+
return this.error(request.id, -32602, error instanceof Error ? error.message : 'Invalid params');
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
async poll(paramsInput, context) {
|
|
237
|
+
const params = normalizePollParams(paramsInput);
|
|
238
|
+
const registered = this.events.get(params.name);
|
|
239
|
+
if (!registered) {
|
|
240
|
+
throw new Error(`Unknown event: ${params.name}`);
|
|
241
|
+
}
|
|
242
|
+
const result = assertRecord(await registered.poll({
|
|
243
|
+
...params,
|
|
244
|
+
context,
|
|
245
|
+
}), `MCP provider ${params.name} returned invalid poll result`);
|
|
246
|
+
if (typeof result.cursor !== 'string') {
|
|
247
|
+
throw new Error(`MCP provider ${params.name} returned poll result without string cursor`);
|
|
248
|
+
}
|
|
249
|
+
if (!Array.isArray(result.events)) {
|
|
250
|
+
throw new Error(`MCP provider ${params.name} returned poll result without events[]`);
|
|
251
|
+
}
|
|
252
|
+
if (result.events.length > params.maxEvents) {
|
|
253
|
+
throw new Error(`MCP provider ${params.name} returned more than maxEvents=${params.maxEvents}`);
|
|
254
|
+
}
|
|
255
|
+
const events = result.events.map((raw) => {
|
|
256
|
+
const parsed = McpEventOccurrenceSchema.safeParse(raw);
|
|
257
|
+
if (!parsed.success) {
|
|
258
|
+
throw new Error(`MCP provider ${params.name} returned invalid EventOccurrence: ${parsed.error.message}`);
|
|
259
|
+
}
|
|
260
|
+
if (parsed.data.name !== params.name) {
|
|
261
|
+
throw new Error(`MCP provider event name mismatch: expected ${params.name}, got ${parsed.data.name}`);
|
|
262
|
+
}
|
|
263
|
+
assertJsonSchemaValue(registered.descriptor.payloadSchema, parsed.data.data);
|
|
264
|
+
return parsed.data;
|
|
265
|
+
});
|
|
266
|
+
const truncated = result.truncated ?? false;
|
|
267
|
+
const hasMore = result.hasMore ?? false;
|
|
268
|
+
if (typeof truncated !== 'boolean' || typeof hasMore !== 'boolean') {
|
|
269
|
+
throw new Error(`MCP provider ${params.name} returned invalid pagination flags`);
|
|
270
|
+
}
|
|
271
|
+
const nextPollMs = result.nextPollMs ?? 5000;
|
|
272
|
+
if (typeof nextPollMs !== 'number' ||
|
|
273
|
+
!Number.isInteger(nextPollMs) ||
|
|
274
|
+
nextPollMs < 0 ||
|
|
275
|
+
nextPollMs > 300000) {
|
|
276
|
+
throw new Error(`MCP provider ${params.name} returned invalid nextPollMs`);
|
|
277
|
+
}
|
|
278
|
+
return {
|
|
279
|
+
events,
|
|
280
|
+
cursor: result.cursor,
|
|
281
|
+
truncated,
|
|
282
|
+
hasMore,
|
|
283
|
+
nextPollMs,
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
ok(id, result) {
|
|
287
|
+
return { jsonrpc: '2.0', id, result };
|
|
288
|
+
}
|
|
289
|
+
error(id, code, message) {
|
|
290
|
+
return { jsonrpc: '2.0', id, error: { code, message } };
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
export function createMcpEventsProvider(options) {
|
|
294
|
+
return new McpEventsProvider(options);
|
|
295
|
+
}
|
|
296
|
+
export { ExperimentalMcpEventsServer, decodeMcpEventCursor, encodeMcpEventCursor, } from './server.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mcp-event-intelligence",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Durable temporal event intelligence for agent hosts: host-owned MCP event discovery, composite triggers, derived events, and targeted wakeups.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -14,6 +14,14 @@
|
|
|
14
14
|
"./host": {
|
|
15
15
|
"types": "./scripts/host-integration.d.mts",
|
|
16
16
|
"import": "./scripts/host-integration.mjs"
|
|
17
|
+
},
|
|
18
|
+
"./provider": {
|
|
19
|
+
"types": "./dist/src/mcpEvents/provider.d.ts",
|
|
20
|
+
"import": "./dist/src/mcpEvents/provider.js"
|
|
21
|
+
},
|
|
22
|
+
"./provider/erpnext": {
|
|
23
|
+
"types": "./dist/src/mcpEvents/erpnextProvider.d.ts",
|
|
24
|
+
"import": "./dist/src/mcpEvents/erpnextProvider.js"
|
|
17
25
|
}
|
|
18
26
|
},
|
|
19
27
|
"bin": {
|
|
@@ -14,8 +14,12 @@ export interface HostMcpConnectionOptions {
|
|
|
14
14
|
client?: HostMcpClientLike;
|
|
15
15
|
request?: (method: string, params?: unknown) => Promise<unknown>;
|
|
16
16
|
enabled?: boolean;
|
|
17
|
+
/** Isolation partition used by the shared EI host. Defaults to \"default\". */
|
|
18
|
+
scopeId?: string;
|
|
17
19
|
pollIntervalMs?: number;
|
|
18
20
|
maxEvents?: number;
|
|
21
|
+
/** Maximum number of immediately drained pages when the provider reports hasMore. */
|
|
22
|
+
maxPollBatches?: number;
|
|
19
23
|
}
|
|
20
24
|
|
|
21
25
|
export interface HostMcpRegistry {
|
|
@@ -36,8 +40,18 @@ export type HostWakeHandler = (
|
|
|
36
40
|
packet: Record<string, unknown>,
|
|
37
41
|
) => Promise<HostWakeReceipt | string> | HostWakeReceipt | string;
|
|
38
42
|
|
|
43
|
+
export interface EventIntelligenceStore {
|
|
44
|
+
init?(): Promise<unknown>;
|
|
45
|
+
/** Required when non-default scopes are used. Implementations should return an isolated store view. */
|
|
46
|
+
forScope?(scopeId: string): Promise<EventIntelligenceStore> | EventIntelligenceStore;
|
|
47
|
+
listScopeIds?(): Promise<string[]> | string[];
|
|
48
|
+
[key: string]: any;
|
|
49
|
+
}
|
|
50
|
+
|
|
39
51
|
export interface EventIntelligenceHostOptions {
|
|
40
52
|
dataDir?: string;
|
|
53
|
+
/** Optional storage backend. PersistentEventStore is used when omitted. */
|
|
54
|
+
store?: EventIntelligenceStore;
|
|
41
55
|
env?: Record<string, string | undefined>;
|
|
42
56
|
mcpRegistry?: HostMcpRegistry;
|
|
43
57
|
/** Low-level/manual fallback; prefer mcpRegistry for automatic discovery. */
|
|
@@ -49,19 +63,25 @@ export interface EventIntelligenceHostOptions {
|
|
|
49
63
|
semanticEvaluator?: unknown;
|
|
50
64
|
}
|
|
51
65
|
|
|
52
|
-
export interface
|
|
66
|
+
export interface EventIntelligenceScopedHost {
|
|
67
|
+
readonly scopeId: string;
|
|
53
68
|
readonly runtime: any;
|
|
54
|
-
readonly store:
|
|
69
|
+
readonly store: EventIntelligenceStore;
|
|
55
70
|
readonly triggerControl: any;
|
|
56
71
|
readonly triggerInspector: any;
|
|
57
72
|
readonly eventSources: any[];
|
|
58
|
-
refreshMcpRegistry(): Promise<any[]>;
|
|
59
73
|
attachMcpClient(connection: HostMcpConnectionOptions): Promise<{
|
|
60
74
|
connectionId: string;
|
|
61
75
|
events: any[];
|
|
62
76
|
}>;
|
|
63
|
-
detachMcpClient(connectionId: string): Promise<boolean>;
|
|
64
77
|
mcpStatus(): any[];
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export interface EventIntelligenceHost extends EventIntelligenceScopedHost {
|
|
81
|
+
refreshMcpRegistry(): Promise<any[]>;
|
|
82
|
+
detachMcpClient(connectionId: string): Promise<boolean>;
|
|
83
|
+
loadedScopes(): string[];
|
|
84
|
+
scope(scopeId?: string): Promise<EventIntelligenceScopedHost>;
|
|
65
85
|
close(): Promise<void>;
|
|
66
86
|
}
|
|
67
87
|
|
|
@@ -84,3 +104,13 @@ export function createHostMcpEventsConnection(
|
|
|
84
104
|
export function createEventIntelligenceHost(
|
|
85
105
|
options?: EventIntelligenceHostOptions,
|
|
86
106
|
): Promise<EventIntelligenceHost>;
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
export class PersistentEventStore implements EventIntelligenceStore {
|
|
110
|
+
constructor(dataDir: string);
|
|
111
|
+
readonly dataDir: string;
|
|
112
|
+
init(): Promise<unknown>;
|
|
113
|
+
forScope(scopeId?: string): Promise<PersistentEventStore>;
|
|
114
|
+
listScopeIds(): Promise<string[]>;
|
|
115
|
+
[key: string]: any;
|
|
116
|
+
}
|
|
@@ -4,6 +4,11 @@ import {
|
|
|
4
4
|
import {
|
|
5
5
|
createHostMcpEventsConnection,
|
|
6
6
|
} from './lib/mcp-events-client.mjs';
|
|
7
|
+
import {
|
|
8
|
+
DEFAULT_EVENT_SCOPE_ID,
|
|
9
|
+
PersistentEventStore,
|
|
10
|
+
normalizeEventScopeId,
|
|
11
|
+
} from './lib/persistent-event-store.mjs';
|
|
7
12
|
|
|
8
13
|
function normalizeMcpConnection(input) {
|
|
9
14
|
const connectionId = String(
|
|
@@ -61,6 +66,31 @@ export function createMcpRegistryAdapter({
|
|
|
61
66
|
};
|
|
62
67
|
}
|
|
63
68
|
|
|
69
|
+
function scopedHostView(runtime, context) {
|
|
70
|
+
const scopeId = context.scopeId;
|
|
71
|
+
return {
|
|
72
|
+
scopeId,
|
|
73
|
+
runtime: context,
|
|
74
|
+
store: context.store,
|
|
75
|
+
triggerControl: context.triggerControl,
|
|
76
|
+
triggerInspector: context.triggerInspector,
|
|
77
|
+
get eventSources() {
|
|
78
|
+
return context.triggerControl.listEventSources();
|
|
79
|
+
},
|
|
80
|
+
async attachMcpClient(connection) {
|
|
81
|
+
const normalized = normalizeMcpConnection({
|
|
82
|
+
...connection,
|
|
83
|
+
scopeId,
|
|
84
|
+
});
|
|
85
|
+
return runtime.mcpEventsClient.attachConnection(normalized);
|
|
86
|
+
},
|
|
87
|
+
mcpStatus() {
|
|
88
|
+
return runtime.mcpEventsClient.status()
|
|
89
|
+
.filter((entry) => entry.scopeId === scopeId);
|
|
90
|
+
},
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
|
|
64
94
|
/**
|
|
65
95
|
* Embed Event Intelligence once at the harness/host level.
|
|
66
96
|
*
|
|
@@ -70,6 +100,7 @@ export function createMcpRegistryAdapter({
|
|
|
70
100
|
*/
|
|
71
101
|
export async function createEventIntelligenceHost({
|
|
72
102
|
dataDir,
|
|
103
|
+
store,
|
|
73
104
|
env = {},
|
|
74
105
|
mcpRegistry,
|
|
75
106
|
mcpClients = [],
|
|
@@ -88,6 +119,7 @@ export async function createEventIntelligenceHost({
|
|
|
88
119
|
wake,
|
|
89
120
|
wakeHandlers,
|
|
90
121
|
semanticEvaluator,
|
|
122
|
+
store,
|
|
91
123
|
});
|
|
92
124
|
|
|
93
125
|
const registryManaged = new Set();
|
|
@@ -117,7 +149,8 @@ export async function createEventIntelligenceHost({
|
|
|
117
149
|
if (existing) {
|
|
118
150
|
if (
|
|
119
151
|
existing.identity === connection.identity &&
|
|
120
|
-
existing.serverId === connection.serverId
|
|
152
|
+
existing.serverId === connection.serverId &&
|
|
153
|
+
existing.scopeId === connection.scopeId
|
|
121
154
|
) {
|
|
122
155
|
registryManaged.add(connectionId);
|
|
123
156
|
outcomes.push({ connectionId, status: 'already_attached' });
|
|
@@ -179,6 +212,7 @@ export async function createEventIntelligenceHost({
|
|
|
179
212
|
}
|
|
180
213
|
|
|
181
214
|
return {
|
|
215
|
+
scopeId: DEFAULT_EVENT_SCOPE_ID,
|
|
182
216
|
runtime,
|
|
183
217
|
get store() {
|
|
184
218
|
return runtime.store;
|
|
@@ -204,6 +238,14 @@ export async function createEventIntelligenceHost({
|
|
|
204
238
|
mcpStatus() {
|
|
205
239
|
return runtime.mcpEventsClient.status();
|
|
206
240
|
},
|
|
241
|
+
loadedScopes() {
|
|
242
|
+
return runtime.loadedScopes();
|
|
243
|
+
},
|
|
244
|
+
async scope(scopeIdInput = DEFAULT_EVENT_SCOPE_ID) {
|
|
245
|
+
const scopeId = normalizeEventScopeId(scopeIdInput);
|
|
246
|
+
const context = await runtime.scope(scopeId);
|
|
247
|
+
return scopedHostView(runtime, context);
|
|
248
|
+
},
|
|
207
249
|
async close() {
|
|
208
250
|
unsubscribe?.();
|
|
209
251
|
await runtime.close();
|
|
@@ -213,4 +255,5 @@ export async function createEventIntelligenceHost({
|
|
|
213
255
|
|
|
214
256
|
export {
|
|
215
257
|
createHostMcpEventsConnection,
|
|
258
|
+
PersistentEventStore,
|
|
216
259
|
};
|