@mastra/mcp 2.5.0-alpha.2 → 2.5.0-alpha.3
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/dist/client/actions/events.d.ts +66 -0
- package/dist/client/actions/events.d.ts.map +1 -0
- package/dist/client/client.d.ts +63 -1
- package/dist/client/client.d.ts.map +1 -1
- package/dist/client/configuration.d.ts +49 -0
- package/dist/client/configuration.d.ts.map +1 -1
- package/dist/client/events/errors.d.ts +13 -0
- package/dist/client/events/errors.d.ts.map +1 -0
- package/dist/client/events/index.d.ts +3 -0
- package/dist/client/events/index.d.ts.map +1 -0
- package/dist/client/events/mode.d.ts +58 -0
- package/dist/client/events/mode.d.ts.map +1 -0
- package/dist/client/events/poll-driver.d.ts +6 -0
- package/dist/client/events/poll-driver.d.ts.map +1 -0
- package/dist/client/events/push-driver.d.ts +7 -0
- package/dist/client/events/push-driver.d.ts.map +1 -0
- package/dist/client/events/stream-router.d.ts +42 -0
- package/dist/client/events/stream-router.d.ts.map +1 -0
- package/dist/client/events/subscription.d.ts +118 -0
- package/dist/client/events/subscription.d.ts.map +1 -0
- package/dist/client/events/types.d.ts +181 -0
- package/dist/client/events/types.d.ts.map +1 -0
- package/dist/client/events/webhook-driver.d.ts +10 -0
- package/dist/client/events/webhook-driver.d.ts.map +1 -0
- package/dist/client/events/webhook-receiver.d.ts +41 -0
- package/dist/client/events/webhook-receiver.d.ts.map +1 -0
- package/dist/client/index.d.ts +1 -0
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/types.d.ts +3 -0
- package/dist/client/types.d.ts.map +1 -1
- package/dist/docs/SKILL.md +2 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/docs/references/docs-guides-mcp-events.md +306 -0
- package/dist/docs/references/reference-tools-mcp-client.md +236 -0
- package/dist/docs/references/reference-tools-mcp-server.md +170 -0
- package/dist/index.cjs +4094 -197
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4032 -142
- package/dist/index.js.map +1 -1
- package/dist/integrations/events-cursor-store.d.ts +25 -0
- package/dist/integrations/events-cursor-store.d.ts.map +1 -0
- package/dist/integrations/events-signals.d.ts +99 -0
- package/dist/integrations/events-signals.d.ts.map +1 -0
- package/dist/integrations/events-tools.d.ts +24 -0
- package/dist/integrations/events-tools.d.ts.map +1 -0
- package/dist/integrations/events-utils.d.ts +18 -0
- package/dist/integrations/events-utils.d.ts.map +1 -0
- package/dist/integrations/index.d.ts +5 -0
- package/dist/integrations/index.d.ts.map +1 -0
- package/dist/server/events/actions.d.ts +35 -0
- package/dist/server/events/actions.d.ts.map +1 -0
- package/dist/server/events/define-event.d.ts +19 -0
- package/dist/server/events/define-event.d.ts.map +1 -0
- package/dist/server/events/handlers.d.ts +49 -0
- package/dist/server/events/handlers.d.ts.map +1 -0
- package/dist/server/events/index.d.ts +7 -0
- package/dist/server/events/index.d.ts.map +1 -0
- package/dist/server/events/inspector.d.ts +14 -0
- package/dist/server/events/inspector.d.ts.map +1 -0
- package/dist/server/events/registry.d.ts +59 -0
- package/dist/server/events/registry.d.ts.map +1 -0
- package/dist/server/events/ring-buffer.d.ts +56 -0
- package/dist/server/events/ring-buffer.d.ts.map +1 -0
- package/dist/server/events/stream.d.ts +56 -0
- package/dist/server/events/stream.d.ts.map +1 -0
- package/dist/server/events/types.d.ts +203 -0
- package/dist/server/events/types.d.ts.map +1 -0
- package/dist/server/events/webhook-dispatcher.d.ts +98 -0
- package/dist/server/events/webhook-dispatcher.d.ts.map +1 -0
- package/dist/server/events/webhook-store.d.ts +60 -0
- package/dist/server/events/webhook-store.d.ts.map +1 -0
- package/dist/server/events/webhook-transport.d.ts +44 -0
- package/dist/server/events/webhook-transport.d.ts.map +1 -0
- package/dist/server/index.d.ts +1 -0
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/server.d.ts +53 -1
- package/dist/server/server.d.ts.map +1 -1
- package/dist/shared/events/index.d.ts +2 -0
- package/dist/shared/events/index.d.ts.map +1 -1
- package/dist/shared/events/webhook-url.d.ts +59 -0
- package/dist/shared/events/webhook-url.d.ts.map +1 -0
- package/dist/shared/events/webhook.d.ts +60 -0
- package/dist/shared/events/webhook.d.ts.map +1 -0
- package/package.json +4 -4
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Persists the resume cursor of each MCP Events subscription, keyed by
|
|
3
|
+
* {@link MCPEventsSignalProvider.key}. Implement it over durable storage to resume after a restart.
|
|
4
|
+
* `set` is only ever called with non-null cursors.
|
|
5
|
+
*
|
|
6
|
+
* @experimental SEP-3415 is a draft; this API may change.
|
|
7
|
+
*/
|
|
8
|
+
export interface MCPEventCursorStore {
|
|
9
|
+
get(key: string): Promise<string | undefined> | string | undefined;
|
|
10
|
+
set(key: string, cursor: string): Promise<void> | void;
|
|
11
|
+
delete(key: string): Promise<void> | void;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Process-local {@link MCPEventCursorStore}. Cursors survive a provider restart within the same
|
|
15
|
+
* process, not a process restart.
|
|
16
|
+
*
|
|
17
|
+
* @experimental SEP-3415 is a draft; this API may change.
|
|
18
|
+
*/
|
|
19
|
+
export declare class InMemoryMCPEventCursorStore implements MCPEventCursorStore {
|
|
20
|
+
#private;
|
|
21
|
+
get(key: string): string | undefined;
|
|
22
|
+
set(key: string, cursor: string): void;
|
|
23
|
+
delete(key: string): void;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=events-cursor-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"events-cursor-store.d.ts","sourceRoot":"","sources":["../../src/integrations/events-cursor-store.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,WAAW,mBAAmB;IAClC,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,GAAG,MAAM,GAAG,SAAS,CAAC;IACnE,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;IACvD,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;CAC3C;AAED;;;;;GAKG;AACH,qBAAa,2BAA4B,YAAW,mBAAmB;;IAGrE,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAEnC;IAED,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAErC;IAED,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAExB;CACF"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import type { NotificationPriority } from '@mastra/core/notifications';
|
|
2
|
+
import { SignalProvider } from '@mastra/core/signals';
|
|
3
|
+
import type { SignalProviderTarget, SignalSubscription } from '@mastra/core/signals';
|
|
4
|
+
import type { MCPClient } from '../client/configuration.js';
|
|
5
|
+
import type { MCPEventSubscribeOptions } from '../client/events/index.js';
|
|
6
|
+
import type { MCPEventCursorStore } from './events-cursor-store.js';
|
|
7
|
+
/**
|
|
8
|
+
* An event type on a server plus the subscription arguments that select its occurrences.
|
|
9
|
+
*
|
|
10
|
+
* @experimental SEP-3415 is a draft; this API may change.
|
|
11
|
+
*/
|
|
12
|
+
export interface MCPEventTarget {
|
|
13
|
+
server: string;
|
|
14
|
+
event: string;
|
|
15
|
+
args?: Record<string, unknown>;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Options for {@link MCPEventsSignalProvider}.
|
|
19
|
+
*
|
|
20
|
+
* @experimental SEP-3415 is a draft; this API may change.
|
|
21
|
+
*/
|
|
22
|
+
export interface MCPEventsSignalProviderOptions {
|
|
23
|
+
/** The client whose servers are subscribed to. Usually an `MCPClient`. */
|
|
24
|
+
client: Pick<MCPClient, 'events'>;
|
|
25
|
+
/** Default `'mcp-events'`. Also used as the notification `source`. */
|
|
26
|
+
id?: string;
|
|
27
|
+
/** Default `'MCP Events'`. */
|
|
28
|
+
name?: string;
|
|
29
|
+
/** Where resume cursors are kept. Default: an {@link InMemoryMCPEventCursorStore}. */
|
|
30
|
+
cursorStore?: MCPEventCursorStore;
|
|
31
|
+
/** Passed to every `events.subscribe()` call, e.g. `maxAgeMs` to bound the replay backlog. */
|
|
32
|
+
subscribeOptions?: Omit<MCPEventSubscribeOptions, 'cursor' | 'signal'>;
|
|
33
|
+
/** Priority of event notifications. Default `'medium'`. */
|
|
34
|
+
priority?: NotificationPriority;
|
|
35
|
+
/**
|
|
36
|
+
* Coalesce pending notifications per subscription key (`coalesceKey: 'mcp-events:<key>'`, regardless of `id`).
|
|
37
|
+
* When on, a burst of occurrences that arrives before the agent reads its inbox keeps only the latest
|
|
38
|
+
* occurrence's summary and payload. Default `false`: every occurrence is its own notification.
|
|
39
|
+
*/
|
|
40
|
+
coalesce?: boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Expose `mcp_events_list`, `mcp_events_subscribe` and `mcp_events_unsubscribe` to the agent,
|
|
43
|
+
* optionally limited to the listed servers. Default `false`: letting a model subscribe a thread
|
|
44
|
+
* to server events is opt-in.
|
|
45
|
+
*/
|
|
46
|
+
tools?: boolean | {
|
|
47
|
+
servers: string[];
|
|
48
|
+
};
|
|
49
|
+
/** Called for failures that do not reach a caller: notification delivery, cursor storage, subscription end. */
|
|
50
|
+
onError?: (error: unknown, info: {
|
|
51
|
+
server: string;
|
|
52
|
+
event: string;
|
|
53
|
+
key: string;
|
|
54
|
+
}) => void;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Delivers MCP Events (SEP-3415) occurrences into agent threads as notification signals.
|
|
58
|
+
*
|
|
59
|
+
* Each `(server, event, arguments)` key holds one MCP subscription, shared by every thread
|
|
60
|
+
* subscribed to it. Occurrences are wrapped as untrusted data before the model sees them, and the
|
|
61
|
+
* subscription cursor is persisted after each occurrence so a new provider resumes where this one
|
|
62
|
+
* stopped.
|
|
63
|
+
*
|
|
64
|
+
* @experimental SEP-3415 is a draft; this API may change.
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```ts
|
|
68
|
+
* const mcpEvents = new MCPEventsSignalProvider({ client: mcp });
|
|
69
|
+
* const agent = new Agent({ ..., signals: [mcpEvents] });
|
|
70
|
+
* await mcpEvents.subscribeThread(
|
|
71
|
+
* { resourceId: 'user-1', threadId: 'thread-1' },
|
|
72
|
+
* { server: 'github', event: 'repo.push', args: { repo: 'mastra-ai/mastra' } },
|
|
73
|
+
* );
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
export declare class MCPEventsSignalProvider extends SignalProvider {
|
|
77
|
+
#private;
|
|
78
|
+
readonly id: string;
|
|
79
|
+
readonly name: string;
|
|
80
|
+
constructor(options: MCPEventsSignalProviderOptions);
|
|
81
|
+
/** The subscription key, `<server>:<event>:<hash of arguments>`, also used as the cursor store key. */
|
|
82
|
+
static key(target: MCPEventTarget): string;
|
|
83
|
+
/**
|
|
84
|
+
* Subscribes a thread to an event. Resolves once the MCP subscription is established, and
|
|
85
|
+
* rejects (without subscribing the thread) when the server refuses it.
|
|
86
|
+
*/
|
|
87
|
+
subscribeThread(thread: SignalProviderTarget, target: MCPEventTarget): Promise<SignalSubscription>;
|
|
88
|
+
/**
|
|
89
|
+
* Unsubscribes a thread. When it was the last thread on the key, the MCP subscription is
|
|
90
|
+
* cancelled and its stored cursor deleted.
|
|
91
|
+
*
|
|
92
|
+
* @returns `true` if the thread was subscribed.
|
|
93
|
+
*/
|
|
94
|
+
unsubscribeThread(thread: SignalProviderTarget, target: MCPEventTarget): Promise<boolean>;
|
|
95
|
+
getTools(): {};
|
|
96
|
+
/** Cancels every MCP subscription. Stored cursors are kept so a new provider resumes from them. */
|
|
97
|
+
stop(): void;
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=events-signals.d.ts.map
|
|
@@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/G,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAC;CAC1F;AAcD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,qBAAa,uBAAwB,SAAQ,cAAc;;IACzD,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAMtB,YAAY,OAAO,EAAE,8BAA8B,EAMlD;IAED,uGAAuG;IACvG,MAAM,CAAC,GAAG,CAAC,MAAM,EAAE,cAAc,GAAG,MAAM,CAEzC;IAED;;;OAGG;IACG,eAAe,CAAC,MAAM,EAAE,oBAAoB,EAAE,MAAM,EAAE,cAAc,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAgBvG;IAED;;;;;OAKG;IACG,iBAAiB,CAAC,MAAM,EAAE,oBAAoB,EAAE,MAAM,EAAE,cAAc,GAAG,OAAO,CAAC,OAAO,CAAC,CAe9F;IAED,QAAQ,OAQP;IAED,mGAAmG;IACnG,IAAI,IAAI,IAAI,CAUX;CAoIF"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { ToolExecutionContext } from '@mastra/core/tools';
|
|
2
|
+
import type { MCPClient } from '../client/configuration.js';
|
|
3
|
+
import type { MCPEventsSignalProvider } from './events-signals.js';
|
|
4
|
+
/** Builds the model-facing MCP Events tools for a provider. */
|
|
5
|
+
export declare function createMCPEventsTools({ provider, client, servers, }: {
|
|
6
|
+
provider: MCPEventsSignalProvider;
|
|
7
|
+
client: Pick<MCPClient, 'events'>;
|
|
8
|
+
servers?: string[];
|
|
9
|
+
}): {
|
|
10
|
+
mcp_events_list: import("@mastra/core/tools").Tool<{
|
|
11
|
+
server: string;
|
|
12
|
+
}, unknown, unknown, unknown, ToolExecutionContext<unknown, unknown, unknown>, "mcp_events_list", unknown>;
|
|
13
|
+
mcp_events_subscribe: import("@mastra/core/tools").Tool<{
|
|
14
|
+
server: string;
|
|
15
|
+
event: string;
|
|
16
|
+
arguments?: string | undefined;
|
|
17
|
+
}, unknown, unknown, unknown, ToolExecutionContext<unknown, unknown, unknown>, "mcp_events_subscribe", unknown>;
|
|
18
|
+
mcp_events_unsubscribe: import("@mastra/core/tools").Tool<{
|
|
19
|
+
server: string;
|
|
20
|
+
event: string;
|
|
21
|
+
arguments?: string | undefined;
|
|
22
|
+
}, unknown, unknown, unknown, ToolExecutionContext<unknown, unknown, unknown>, "mcp_events_unsubscribe", unknown>;
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=events-tools.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"events-tools.d.ts","sourceRoot":"","sources":["../../src/integrations/events-tools.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAE/D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACzD,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AAiDhE,+DAA+D;AAC/D,wBAAgB,oBAAoB,CAAC,EACnC,QAAQ,EACR,MAAM,EACN,OAAO,GACR,EAAE;IACD,QAAQ,EAAE,uBAAuB,CAAC;IAClC,MAAM,EAAE,IAAI,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;IAClC,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;CACpB;IAOG,eAAe;;;IAyBf,oBAAoB;;;;;IAsBpB,sBAAsB;;;;;EAuBzB"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hashes subscription arguments so that equal arguments give the same key regardless of key
|
|
3
|
+
* order. `undefined` and `{}` hash the same.
|
|
4
|
+
*
|
|
5
|
+
* @experimental SEP-3415 is a draft; this API may change.
|
|
6
|
+
*/
|
|
7
|
+
export declare function stableArgsHash(args: Record<string, unknown> | undefined): string;
|
|
8
|
+
export declare const UNTRUSTED_EVENT_TAG = "untrusted-mcp-event-data";
|
|
9
|
+
/**
|
|
10
|
+
* Formats server-provided event content for a model: a fixed header, a warning, and the data as
|
|
11
|
+
* escaped JSON inside an `<untrusted-mcp-event-data>` block that the data cannot break out of.
|
|
12
|
+
*/
|
|
13
|
+
export declare function formatUntrustedEvent({ header, data, footer, }: {
|
|
14
|
+
header: string;
|
|
15
|
+
data: unknown;
|
|
16
|
+
footer?: string;
|
|
17
|
+
}): string;
|
|
18
|
+
//# sourceMappingURL=events-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"events-utils.d.ts","sourceRoot":"","sources":["../../src/integrations/events-utils.ts"],"names":[],"mappings":"AAeA;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,GAAG,MAAM,CAGhF;AAUD,eAAO,MAAM,mBAAmB,6BAA6B,CAAC;AAK9D;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,EACnC,MAAM,EACN,IAAI,EACJ,MAAM,GACP,EAAE;IACD,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,OAAO,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,GAAG,MAAM,CAST"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { MCPEventsSignalProvider } from './events-signals.js';
|
|
2
|
+
export type { MCPEventTarget, MCPEventsSignalProviderOptions } from './events-signals.js';
|
|
3
|
+
export { InMemoryMCPEventCursorStore } from './events-cursor-store.js';
|
|
4
|
+
export type { MCPEventCursorStore } from './events-cursor-store.js';
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/integrations/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AAC3D,YAAY,EAAE,cAAc,EAAE,8BAA8B,EAAE,MAAM,kBAAkB,CAAC;AACvF,OAAO,EAAE,2BAA2B,EAAE,MAAM,uBAAuB,CAAC;AACpE,YAAY,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { EventDescriptor, EventOccurrence } from '../../shared/events/index.js';
|
|
2
|
+
import type { ServerEventRegistry } from './registry.js';
|
|
3
|
+
import type { MCPServerEmitOptions, MCPServerEventData } from './types.js';
|
|
4
|
+
/**
|
|
5
|
+
* `server.events`: publishes occurrences of the event types configured in `MCPServer`'s `events`.
|
|
6
|
+
*
|
|
7
|
+
* Emitted events are delivered to this process's open `events/stream` subscriptions, POSTed to
|
|
8
|
+
* its webhook subscriptions (when `eventsOptions.webhook` is set), and kept in the type's
|
|
9
|
+
* in-memory ring buffer for `events/poll`. They do not reach other server processes.
|
|
10
|
+
*
|
|
11
|
+
* @experimental SEP-3415 is a draft; this API may change.
|
|
12
|
+
*/
|
|
13
|
+
export declare class ServerEventActions {
|
|
14
|
+
private readonly registry;
|
|
15
|
+
private readonly describe;
|
|
16
|
+
constructor(registry: ServerEventRegistry, describe: () => EventDescriptor[]);
|
|
17
|
+
/**
|
|
18
|
+
* Records an occurrence of `name` and delivers it to every matching push and webhook subscription.
|
|
19
|
+
* `data` is validated against the type's `payloadSchema` when one is set.
|
|
20
|
+
*
|
|
21
|
+
* @throws MastraError `MCP_SERVER_UNKNOWN_EVENT` for an unconfigured name,
|
|
22
|
+
* `MCP_SERVER_EVENT_INVALID_PAYLOAD` when `data` fails `payloadSchema`, and
|
|
23
|
+
* `MCP_SERVER_EVENT_NOT_EMITTABLE` for a type with a `poll` source, which can't be pushed.
|
|
24
|
+
*
|
|
25
|
+
* @experimental SEP-3415 is a draft; this API may change.
|
|
26
|
+
*/
|
|
27
|
+
emit(name: string, data: MCPServerEventData, options?: MCPServerEmitOptions): Promise<EventOccurrence>;
|
|
28
|
+
/**
|
|
29
|
+
* The descriptors `events/list` returns, in definition order.
|
|
30
|
+
*
|
|
31
|
+
* @experimental SEP-3415 is a draft; this API may change.
|
|
32
|
+
*/
|
|
33
|
+
list(): EventDescriptor[];
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=actions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../../../src/server/events/actions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAC5E,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AACtD,OAAO,KAAK,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAExE;;;;;;;;GAQG;AACH,qBAAa,kBAAkB;IAE3B,OAAO,CAAC,QAAQ,CAAC,QAAQ;IACzB,OAAO,CAAC,QAAQ,CAAC,QAAQ;IAF3B,YACmB,QAAQ,EAAE,mBAAmB,EAC7B,QAAQ,EAAE,MAAM,eAAe,EAAE,EAChD;IAEJ;;;;;;;;;OASG;IACH,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,kBAAkB,EAAE,OAAO,CAAC,EAAE,oBAAoB,GAAG,OAAO,CAAC,eAAe,CAAC,CAErG;IAED;;;;OAIG;IACH,IAAI,IAAI,eAAe,EAAE,CAExB;CACF"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { MCPServerEventArgs, MCPServerEventData, MCPServerEventDefinition } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Declares an event type for `MCPServer`'s `events` option. An identity helper: it types `match`
|
|
4
|
+
* and `poll` from `inputSchema` and `payloadSchema`.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```typescript
|
|
8
|
+
* const ticketCreated = defineEvent({
|
|
9
|
+
* description: 'A ticket was created',
|
|
10
|
+
* inputSchema: z.object({ project: z.string().optional() }),
|
|
11
|
+
* payloadSchema: z.object({ id: z.string(), project: z.string() }),
|
|
12
|
+
* match: (args, data) => !args.project || data.project === args.project,
|
|
13
|
+
* });
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* @experimental SEP-3415 is a draft; this API may change.
|
|
17
|
+
*/
|
|
18
|
+
export declare function defineEvent<TArgs extends MCPServerEventArgs = MCPServerEventArgs, TData extends MCPServerEventData = MCPServerEventData>(definition: MCPServerEventDefinition<TArgs, TData>): MCPServerEventDefinition<TArgs, TData>;
|
|
19
|
+
//# sourceMappingURL=define-event.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"define-event.d.ts","sourceRoot":"","sources":["../../../src/server/events/define-event.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAC;AAEhG;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,WAAW,CACzB,KAAK,SAAS,kBAAkB,GAAG,kBAAkB,EACrD,KAAK,SAAS,kBAAkB,GAAG,kBAAkB,EACrD,UAAU,EAAE,wBAAwB,CAAC,KAAK,EAAE,KAAK,CAAC,GAAG,wBAAwB,CAAC,KAAK,EAAE,KAAK,CAAC,CAE5F"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { IMastraLogger } from '@mastra/core/logger';
|
|
2
|
+
import type { RequestContext } from '@mastra/core/request-context';
|
|
3
|
+
import type { Server, ServerContext } from '@modelcontextprotocol/server';
|
|
4
|
+
import type { EventDeliveryMode, PollEventsRequestParams, PollEventsResult, StreamEventsRequestParams } from '../../shared/events/index.js';
|
|
5
|
+
import type { RegisteredEvent, ServerEventRegistry } from './registry.js';
|
|
6
|
+
import { EventStream } from './stream.js';
|
|
7
|
+
import type { EventStreamOptions } from './stream.js';
|
|
8
|
+
import type { WebhookDispatcher } from './webhook-dispatcher.js';
|
|
9
|
+
export declare const DEFAULT_EVENTS_MAX_STREAMS = 1024;
|
|
10
|
+
export interface EventHandlerDeps {
|
|
11
|
+
registry: ServerEventRegistry;
|
|
12
|
+
heartbeatIntervalMs: number;
|
|
13
|
+
listPageSize?: number;
|
|
14
|
+
maxStreams?: number;
|
|
15
|
+
getLogger: () => IMastraLogger;
|
|
16
|
+
/** Serves `events/subscribe` and `events/unsubscribe` when webhook delivery is configured. */
|
|
17
|
+
webhooks?: WebhookDispatcher;
|
|
18
|
+
jsonSchema: (schema: unknown, options: {
|
|
19
|
+
io: 'input' | 'output';
|
|
20
|
+
}) => Record<string, unknown> | undefined;
|
|
21
|
+
/** Runs one request under the server's request span with its resolved request context. */
|
|
22
|
+
trace: <T>(server: Server, method: string, params: Record<string, unknown>, ctx: ServerContext, fn: (requestContext: RequestContext) => Promise<T>) => Promise<T>;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Registers `events/list`, `events/poll` and `events/stream` on one protocol instance, plus
|
|
26
|
+
* `events/subscribe` and `events/unsubscribe` when webhook delivery is configured.
|
|
27
|
+
*/
|
|
28
|
+
export declare function registerEventHandlers(server: Server, deps: EventHandlerDeps): void;
|
|
29
|
+
type PollDeps = Pick<EventHandlerDeps, 'registry' | 'getLogger'>;
|
|
30
|
+
type StreamDeps = Pick<EventHandlerDeps, 'registry' | 'getLogger' | 'heartbeatIntervalMs' | 'maxStreams'>;
|
|
31
|
+
/** Serves one `events/poll` request: the event's `poll` source, or its ring buffer. */
|
|
32
|
+
export declare function pollEvent(deps: PollDeps, params: PollEventsRequestParams, { requestContext, signal }: {
|
|
33
|
+
requestContext: RequestContext;
|
|
34
|
+
signal: AbortSignal;
|
|
35
|
+
}): Promise<PollEventsResult>;
|
|
36
|
+
/**
|
|
37
|
+
* Opens one `events/stream` subscription: replays from `cursor`, then delivers live events
|
|
38
|
+
* until the stream closes or `signal` aborts. Resolves once `active` is queued.
|
|
39
|
+
*/
|
|
40
|
+
export declare function openEventStream(deps: StreamDeps, params: StreamEventsRequestParams, { subscriptionId, requestContext, notify, signal, }: {
|
|
41
|
+
subscriptionId: string | number;
|
|
42
|
+
requestContext: RequestContext;
|
|
43
|
+
notify: EventStreamOptions['notify'];
|
|
44
|
+
signal: AbortSignal;
|
|
45
|
+
}): Promise<EventStream>;
|
|
46
|
+
/** Runs the definition's `authorize`; rejects with -32024 when it denies the caller. */
|
|
47
|
+
export declare function authorizeOrThrow(event: RegisteredEvent, args: Record<string, unknown>, requestContext: RequestContext, delivery: EventDeliveryMode, deps: Pick<EventHandlerDeps, 'getLogger'>): Promise<void>;
|
|
48
|
+
export {};
|
|
49
|
+
//# sourceMappingURL=handlers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handlers.d.ts","sourceRoot":"","sources":["../../../src/server/events/handlers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAEnE,OAAO,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAiB1E,OAAO,KAAK,EACV,iBAAiB,EAGjB,uBAAuB,EACvB,gBAAgB,EAChB,yBAAyB,EAG1B,MAAM,qBAAqB,CAAC;AAG7B,OAAO,KAAK,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AACvE,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AACnD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAI9D,eAAO,MAAM,0BAA0B,OAAO,CAAC;AAE/C,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,mBAAmB,CAAC;IAC9B,mBAAmB,EAAE,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AM,EAAE,yBAAyB,EACjC,EACE,cAAc,EACd,cAAc,EACd,MAAM,EACN,MAAM,GACP,EAAE;IACD,cAAc,EAAE,MAAM,GAAG,MAAM,CAAC;IAChC,cAAc,EAAE,cAAc,CAAC;IAC/B,MAAM,EAAE,kBAAkB,CAAC,QAAQ,CAAC,CAAC;IACrC,MAAM,EAAE,WAAW,CAAC;CACrB,GACA,OAAO,CAAC,WAAW,CAAC,CA2CtB;AAUD,wFAAwF;AACxF,wBAAsB,gBAAgB,CACpC,KAAK,EAAE,eAAe,EACtB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,cAAc,EAAE,cAAc,EAC9B,QAAQ,EAAE,iBAAiB,EAC3B,IAAI,EAAE,IAAI,CAAC,gBAAgB,EAAE,WAAW,CAAC,GACxC,OAAO,CAAC,IAAI,CAAC,CAaf"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { defineEvent } from './define-event.js';
|
|
2
|
+
export { ServerEventActions } from './actions.js';
|
|
3
|
+
export type * from './types.js';
|
|
4
|
+
export { InMemoryWebhookSubscriptionStore } from './webhook-store.js';
|
|
5
|
+
export type { WebhookSubscriptionRecord, WebhookSubscriptionStore } from './webhook-store.js';
|
|
6
|
+
export type { WebhookTransport, WebhookTransportRequest, WebhookTransportResult } from './webhook-transport.js';
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/server/events/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAC/C,mBAAmB,SAAS,CAAC;AAC7B,OAAO,EAAE,gCAAgC,EAAE,MAAM,iBAAiB,CAAC;AACnE,YAAY,EAAE,yBAAyB,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAC;AAC3F,YAAY,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { MCPServerEventInfo, MCPServerEventsInspector } from '@mastra/core/mcp';
|
|
2
|
+
import type { EventHandlerDeps } from './handlers.js';
|
|
3
|
+
/** Prefix of the `eventId` of occurrences sent with the inspector's `emit`. */
|
|
4
|
+
export declare const TEST_EMIT_EVENT_ID_PREFIX = "mastra-test-";
|
|
5
|
+
type InspectorDeps = Pick<EventHandlerDeps, 'registry' | 'getLogger' | 'heartbeatIntervalMs' | 'maxStreams' | 'jsonSchema'>;
|
|
6
|
+
/** Studio's view of the declared event types: the `events/list` descriptors plus `emittable`. */
|
|
7
|
+
export declare function listEventsInfo(deps: Pick<InspectorDeps, 'registry' | 'jsonSchema'>): MCPServerEventInfo[];
|
|
8
|
+
/**
|
|
9
|
+
* Serves `events/poll` and `events/stream` in-process through the protocol handlers' code
|
|
10
|
+
* paths, translating protocol errors into `MastraError`s with {@link MCP_SERVER_EVENT_ERROR_IDS}.
|
|
11
|
+
*/
|
|
12
|
+
export declare function createEventsInspector(deps: InspectorDeps): MCPServerEventsInspector;
|
|
13
|
+
export {};
|
|
14
|
+
//# sourceMappingURL=inspector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inspector.d.ts","sourceRoot":"","sources":["../../../src/server/events/inspector.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,kBAAkB,EAElB,wBAAwB,EAEzB,MAAM,kBAAkB,CAAC;AAO1B,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAInD,+EAA+E;AAC/E,eAAO,MAAM,yBAAyB,iBAAiB,CAAC;AAExD,KAAK,aAAa,GAAG,IAAI,CACvB,gBAAgB,EAChB,UAAU,GAAG,WAAW,GAAG,qBAAqB,GAAG,YAAY,GAAG,YAAY,CAC/E,CAAC;AAIF,iGAAiG;AACjG,wBAAgB,cAAc,CAAC,IAAI,EAAE,IAAI,CAAC,aAAa,EAAE,UAAU,GAAG,YAAY,CAAC,GAAG,kBAAkB,EAAE,CAMzG;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,aAAa,GAAG,wBAAwB,CA0CnF"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { StandardSchemaWithJSON } from '@mastra/core/schema';
|
|
2
|
+
import type { EventDeliveryMode, EventDescriptor, EventOccurrence } from '../../shared/events/index.js';
|
|
3
|
+
import { EventRingBuffer } from './ring-buffer.js';
|
|
4
|
+
import type { BufferedEvent } from './ring-buffer.js';
|
|
5
|
+
import type { EventStream } from './stream.js';
|
|
6
|
+
import type { MCPServerEmitOptions, MCPServerEventData, MCPServerEventDefinition } from './types.js';
|
|
7
|
+
export type EventListener = (entry: BufferedEvent) => void;
|
|
8
|
+
/** One configured event type. */
|
|
9
|
+
export interface RegisteredEvent {
|
|
10
|
+
name: string;
|
|
11
|
+
definition: MCPServerEventDefinition;
|
|
12
|
+
delivery: EventDeliveryMode[];
|
|
13
|
+
inputSchema?: StandardSchemaWithJSON;
|
|
14
|
+
payloadSchema?: StandardSchemaWithJSON;
|
|
15
|
+
/** Present when the type has no `poll` source, i.e. when it accepts `emit()`. */
|
|
16
|
+
buffer?: EventRingBuffer;
|
|
17
|
+
listeners: Set<EventListener>;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Delivery modes advertised for a definition. They are fixed at construction because clients
|
|
21
|
+
* only learn them from `events/list` (no `listChanged` yet). Without a `poll` source the type
|
|
22
|
+
* is fed by `emit()` and served over push and poll; with one it is served over poll only. An
|
|
23
|
+
* explicit `delivery` only narrows that set. `extraModes` lets other delivery mechanisms
|
|
24
|
+
* (webhooks) add themselves.
|
|
25
|
+
*/
|
|
26
|
+
export declare function deriveDelivery(name: string, definition: Pick<MCPServerEventDefinition, 'poll' | 'delivery'>, extraModes?: EventDeliveryMode[]): EventDeliveryMode[];
|
|
27
|
+
/** Event types, their buffers and live subscriptions. Shared by every protocol instance of one `MCPServer`. */
|
|
28
|
+
export declare class ServerEventRegistry {
|
|
29
|
+
readonly bootId: `${string}-${string}-${string}-${string}-${string}`;
|
|
30
|
+
readonly openStreams: Set<EventStream>;
|
|
31
|
+
private readonly events;
|
|
32
|
+
/** `webhook`: the server serves webhook delivery, which emit-fed types (no `poll` source) then advertise. */
|
|
33
|
+
constructor(definitions: Record<string, MCPServerEventDefinition> | undefined, options?: {
|
|
34
|
+
webhook?: boolean;
|
|
35
|
+
});
|
|
36
|
+
get size(): number;
|
|
37
|
+
list(): RegisteredEvent[];
|
|
38
|
+
/**
|
|
39
|
+
* The event type a poll or stream request names, if it supports `mode`.
|
|
40
|
+
* @throws ProtocolError -32023 for an unknown name, -32026 for an unsupported mode.
|
|
41
|
+
*/
|
|
42
|
+
resolve(name: string, mode: EventDeliveryMode): RegisteredEvent;
|
|
43
|
+
/**
|
|
44
|
+
* Validates subscription arguments against the type's `inputSchema`.
|
|
45
|
+
* @throws ProtocolError -32602 when they do not match.
|
|
46
|
+
*/
|
|
47
|
+
validateArguments(event: RegisteredEvent, args: Record<string, unknown>): Promise<Record<string, unknown>>;
|
|
48
|
+
/** Records an occurrence and hands it to every live subscription of the type. */
|
|
49
|
+
emit(name: string, data: MCPServerEventData, options?: MCPServerEmitOptions): Promise<EventOccurrence>;
|
|
50
|
+
/** Registers a live listener for a type's emitted events. Returns the unsubscribe function. */
|
|
51
|
+
subscribe(event: RegisteredEvent, listener: EventListener): () => void;
|
|
52
|
+
listenerCount(): number;
|
|
53
|
+
closeStreams(): void;
|
|
54
|
+
}
|
|
55
|
+
export declare function toTimestamp(value: string | Date | undefined): string;
|
|
56
|
+
export declare function toDescriptor(event: RegisteredEvent, convert: (schema: unknown, options: {
|
|
57
|
+
io: 'input' | 'output';
|
|
58
|
+
}) => Record<string, unknown> | undefined): EventDescriptor;
|
|
59
|
+
//# sourceMappingURL=registry.d.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|
|
3
|
+
export interface StoredOccurrence {
|
|
4
|
+
eventId: string;
|
|
5
|
+
name: string;
|
|
6
|
+
timestamp: string;
|
|
7
|
+
data: Record<string, unknown>;
|
|
8
|
+
}
|
|
9
|
+
/** An emitted event as retained by the buffer. */
|
|
10
|
+
export interface BufferedEvent {
|
|
11
|
+
seq: number;
|
|
12
|
+
/** Position after this event. */
|
|
13
|
+
cursor: string;
|
|
14
|
+
/** Parsed `occurrence.timestamp`, for `maxAgeMs`. */
|
|
15
|
+
timestampMs: number;
|
|
16
|
+
occurrence: StoredOccurrence;
|
|
17
|
+
}
|
|
18
|
+
export interface RingBufferReadOptions {
|
|
19
|
+
maxEvents: number;
|
|
20
|
+
maxAgeMs?: number;
|
|
21
|
+
match?: (data: Record<string, unknown>) => boolean;
|
|
22
|
+
now?: number;
|
|
23
|
+
}
|
|
24
|
+
export interface RingBufferReadResult {
|
|
25
|
+
/** Position the read started from, after any gap adjustment. */
|
|
26
|
+
from: string;
|
|
27
|
+
events: EventOccurrence[];
|
|
28
|
+
/** Position after the last scanned event, including events `match` rejected. */
|
|
29
|
+
cursor: string;
|
|
30
|
+
truncated: boolean;
|
|
31
|
+
hasMore: boolean;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Bounded, in-memory history of one event type's emitted occurrences.
|
|
35
|
+
*
|
|
36
|
+
* Cursors are opaque `base64url("<bootId>:<seq>")`. `bootId` is random per server instance, so a
|
|
37
|
+
* cursor minted by a previous process is recognised as foreign and read as a gap.
|
|
38
|
+
*/
|
|
39
|
+
export declare class EventRingBuffer {
|
|
40
|
+
private readonly bootId;
|
|
41
|
+
private readonly capacity;
|
|
42
|
+
private readonly entries;
|
|
43
|
+
private seq;
|
|
44
|
+
constructor(bootId: string, capacity: number);
|
|
45
|
+
get head(): string;
|
|
46
|
+
/** Sequence number of the latest pushed event (0 before the first). */
|
|
47
|
+
get lastSeq(): number;
|
|
48
|
+
push(occurrence: StoredOccurrence): BufferedEvent;
|
|
49
|
+
/** `cursor` absent or `null` starts from now: nothing is replayed and `maxAgeMs` is ignored. */
|
|
50
|
+
read(cursor: string | null | undefined, options: RingBufferReadOptions): RingBufferReadResult;
|
|
51
|
+
/** Cursor for the position after event `seq` (`seq - 1` is the position before it). */
|
|
52
|
+
cursorFor(seq: number): string;
|
|
53
|
+
/** Sequence number of a cursor this buffer minted, or `undefined` if it is foreign or malformed. */
|
|
54
|
+
private decode;
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=ring-buffer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ring-buffer.d.ts","sourceRoot":"","sources":["../../../src/server/events/ring-buffer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAE3D,uDAAuD;AACvD,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC/B;AAED,kDAAkD;AAClD,MAAM,WAAW,aAAa;IAC5B,GAAG,EAAE,MAAM,CAAC;IACZ,iCAAiC;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,qDAAqD;IACrD,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,gBAAgB,CAAC;CAC9B;AAED,MAAM,WAAW,qBAAqB;IACpC,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,OAAO,CAAC;IACnD,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,oBAAoB;IACnC,gEAAgE;IAChE,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,eAAe,EAAE,CAAC;IAC1B,gFAAgF;IAChF,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,OAAO,CAAC;IACnB,OAAO,EAAE,OAAO,CAAC;CAClB;AAED;;;;;GAKG;AACH,qBAAa,eAAe;IAKxB,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,QAAQ;IAL3B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAuB;IAC/C,OAAO,CAAC,GAAG,CAAK;IAEhB,YACmB,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,EAC/B;IAEJ,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED,uEAAuE;IACvE,IAAI,OAAO,IAAI,MAAM,CAEpB;IAED,IAAI,CAAC,UAAU,EAAE,gBAAgB,GAAG,aAAa,CAYhD;IAED,gGAAgG;IAChG,IAAI,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EAAE,OAAO,EAAE,qBAAqB,GAAG,oBAAoB,CAsC5F;IAED,uFAAuF;IACvF,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE7B;IAED,oGAAoG;IACpG,OAAO,CAAC,MAAM;CASf"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { EventOccurrence } from '../../shared/events/index.js';
|
|
2
|
+
import type { BufferedEvent } from './ring-buffer.js';
|
|
3
|
+
type SubscriptionId = string | number;
|
|
4
|
+
export interface StreamNotification {
|
|
5
|
+
method: string;
|
|
6
|
+
params: Record<string, unknown>;
|
|
7
|
+
}
|
|
8
|
+
export interface EventStreamOptions {
|
|
9
|
+
subscriptionId: SubscriptionId;
|
|
10
|
+
/** Sends a notification related to the `events/stream` request. */
|
|
11
|
+
notify: (notification: StreamNotification) => Promise<void>;
|
|
12
|
+
heartbeatIntervalMs: number;
|
|
13
|
+
/** Subscription filter, already bound to the subscription's arguments. */
|
|
14
|
+
match?: (data: Record<string, unknown>) => boolean;
|
|
15
|
+
onError?: (error: unknown) => void;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Server side of one push subscription (`events/stream`).
|
|
19
|
+
*
|
|
20
|
+
* Every notification goes through one promise chain, so `active` is always first and events
|
|
21
|
+
* arrive in emit order. A heartbeat is sent whenever `heartbeatIntervalMs` passes without
|
|
22
|
+
* another message.
|
|
23
|
+
*/
|
|
24
|
+
export declare class EventStream {
|
|
25
|
+
private readonly options;
|
|
26
|
+
/** Resolves once the stream is closed. */
|
|
27
|
+
readonly closed: Promise<void>;
|
|
28
|
+
private queue;
|
|
29
|
+
private timer;
|
|
30
|
+
private cursor;
|
|
31
|
+
private isClosed;
|
|
32
|
+
private started;
|
|
33
|
+
private readonly pending;
|
|
34
|
+
private readonly cleanups;
|
|
35
|
+
private resolveClosed;
|
|
36
|
+
constructor(options: EventStreamOptions);
|
|
37
|
+
get subscriptionId(): SubscriptionId;
|
|
38
|
+
/** Runs `cleanup` when the stream closes. */
|
|
39
|
+
onClose(cleanup: () => void): void;
|
|
40
|
+
/** Sends `active`, then the replayed events, and starts the heartbeat. */
|
|
41
|
+
start(start: {
|
|
42
|
+
cursor: string | null;
|
|
43
|
+
truncated: boolean;
|
|
44
|
+
replay?: EventOccurrence[];
|
|
45
|
+
}): void;
|
|
46
|
+
/** Live listener: forwards an emitted event if it matches the subscription. */
|
|
47
|
+
deliver(entry: BufferedEvent): void;
|
|
48
|
+
/** `match` for replay and live delivery. A throwing `match` is reported on the stream as a recoverable error; the details go only to `onError`. */
|
|
49
|
+
matches(data: Record<string, unknown>): boolean;
|
|
50
|
+
close(): void;
|
|
51
|
+
private sendEvent;
|
|
52
|
+
private send;
|
|
53
|
+
private armHeartbeat;
|
|
54
|
+
}
|
|
55
|
+
export {};
|
|
56
|
+
//# sourceMappingURL=stream.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../../../src/server/events/stream.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,e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