@tmcp/session-manager 0.3.0 → 0.3.1

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/package.json CHANGED
@@ -1,11 +1,13 @@
1
1
  {
2
2
  "name": "@tmcp/session-manager",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "license": "MIT",
5
5
  "description": "",
6
6
  "main": "src/index.js",
7
7
  "files": [
8
- "src/"
8
+ "src/",
9
+ "types/",
10
+ "!src/**/*.d.ts"
9
11
  ],
10
12
  "repository": {
11
13
  "type": "git",
@@ -19,10 +21,10 @@
19
21
  "session",
20
22
  "manager"
21
23
  ],
22
- "types": "./src/types/index.d.ts",
24
+ "types": "./types/index.d.ts",
23
25
  "exports": {
24
26
  ".": {
25
- "types": "./src/types/index.d.ts",
27
+ "types": "./types/index.d.ts",
26
28
  "import": "./src/index.js"
27
29
  }
28
30
  },
@@ -34,17 +36,16 @@
34
36
  "access": "public"
35
37
  },
36
38
  "devDependencies": {
37
- "dts-buddy": "^0.6.2",
38
39
  "publint": "^0.3.12",
39
40
  "vitest": "^4.0.0",
40
- "tmcp": "^1.20.0",
41
- "@tmcp/internal-ts-helpers": "^1.0.0"
41
+ "@tmcp/internal-ts-helpers": "^1.0.0",
42
+ "tmcp": "^1.20.1"
42
43
  },
43
44
  "dependencies": {
44
45
  "json-rpc-2.0": "^1.7.1"
45
46
  },
46
47
  "scripts": {
47
- "generate:types": "dts-buddy && node scripts/abstractify.js && publint",
48
+ "generate:types": "generate-types && publint",
48
49
  "prepublish": "pnpm generate:types",
49
50
  "test": "vitest --run"
50
51
  }
@@ -0,0 +1,90 @@
1
+ /**
2
+ * Determine whether a notification belongs on a subscription stream.
3
+ * Distributed managers can use this directly or maintain equivalent indexes.
4
+ */
5
+ export function matchesSubscription(filters: SubscriptionFilter, notification: JSONRPCRequest): boolean;
6
+ /**
7
+ * Routes notifications to long-lived per-request subscription streams.
8
+ * Callbacks remain local to the process serving the response stream. Brokered
9
+ * implementations can distribute notifications without persisting descriptors.
10
+ */
11
+ export abstract class SubscriptionManager {
12
+ /**
13
+ * Atomically register a subscription. Matching notifications must be
14
+ * buffered until acknowledgement completes and then delivered in order.
15
+ */
16
+ abstract create(subscription: Subscription, callbacks: SubscriptionCallbacks): boolean | Promise<boolean>;
17
+ abstract send(notification: JSONRPCRequest): void | Promise<void>;
18
+ /**
19
+ * Request closure of one subscription. Implementations must preserve the
20
+ * JSON-RPC ID type when identifying a registration.
21
+ */
22
+ abstract close(id: string | number, origin: string, reason: "closed" | "cancelled"): boolean | Promise<boolean>;
23
+ /**
24
+ * Close every subscription, optionally limited to one transport origin.
25
+ */
26
+ abstract closeAll(origin?: string, reason?: "closed" | "cancelled"): void | Promise<void>;
27
+ }
28
+ /**
29
+ * Process-local subscription manager. Distributed implementations should
30
+ * mirror its acknowledgement buffering and per-subscription ordering.
31
+ */
32
+ export class InMemorySubscriptionManager extends SubscriptionManager {
33
+ create(subscription: Subscription, callbacks: SubscriptionCallbacks): Promise<boolean>;
34
+ send(notification: JSONRPCRequest): Promise<void>;
35
+ close(id: string | number, origin: string, reason: "closed" | "cancelled"): Promise<boolean>;
36
+ closeAll(origin?: string, reason?: "closed" | "cancelled"): Promise<void>;
37
+ #private;
38
+ }
39
+ export abstract class StreamSessionManager {
40
+ abstract create(id: string, controller: ReadableStreamDefaultController): void | Promise<void>;
41
+ abstract delete(id: string): void | Promise<void>;
42
+ abstract has(id: string): boolean | Promise<boolean>;
43
+ abstract send(sessions: string[] | undefined, data: string): void | Promise<void>;
44
+ }
45
+ export class InMemoryStreamSessionManager extends StreamSessionManager {
46
+ create(id: string, controller: ReadableStreamDefaultController): void;
47
+ delete(id: string): void;
48
+ has(id: string): Promise<boolean>;
49
+ send(sessions: string[] | undefined, data: string): void;
50
+ #private;
51
+ }
52
+ export abstract class InfoSessionManager {
53
+ abstract getClientInfo(id: string): Promise<NonNullable<Context["sessionInfo"]>["clientInfo"]>;
54
+ abstract setClientInfo(id: string, client_info: NonNullable<Context["sessionInfo"]>["clientInfo"]): void;
55
+ abstract getClientCapabilities(id: string): Promise<NonNullable<Context["sessionInfo"]>["clientCapabilities"]>;
56
+ abstract setClientCapabilities(id: string, client_capabilities: NonNullable<Context["sessionInfo"]>["clientCapabilities"]): void;
57
+ abstract getLogLevel(id: string): Promise<NonNullable<Context["sessionInfo"]>["logLevel"]>;
58
+ abstract setLogLevel(id: string, log_level: NonNullable<Context["sessionInfo"]>["logLevel"]): void;
59
+ abstract getSubscriptions(uri: string): Promise<string[]>;
60
+ abstract addSubscription(id: string, uri: string): void;
61
+ abstract removeSubscription(id: string, uri: string): void;
62
+ abstract delete(id: string): void;
63
+ }
64
+ export class InMemoryInfoSessionManager extends InfoSessionManager {
65
+ getClientInfo(id: string): Promise<NonNullable<Context["sessionInfo"]>["clientInfo"]>;
66
+ setClientInfo(id: string, client_info: NonNullable<Context["sessionInfo"]>["clientInfo"]): void;
67
+ getClientCapabilities(id: string): Promise<NonNullable<Context["sessionInfo"]>["clientCapabilities"]>;
68
+ setClientCapabilities(id: string, client_capabilities: NonNullable<Context["sessionInfo"]>["clientCapabilities"]): void;
69
+ getLogLevel(id: string): Promise<NonNullable<Context["sessionInfo"]>["logLevel"]>;
70
+ setLogLevel(id: string, log_level: NonNullable<Context["sessionInfo"]>["logLevel"]): void;
71
+ getSubscriptions(uri: string): Promise<string[]>;
72
+ addSubscription(id: string, uri: string): void;
73
+ removeSubscription(id: string, uri: string): void;
74
+ delete(id: string): void;
75
+ #private;
76
+ }
77
+ export type Subscription = {
78
+ id: string | number;
79
+ origin: string;
80
+ filters: SubscriptionFilter;
81
+ };
82
+ export type SubscriptionCallbacks = {
83
+ acknowledge: () => void | Promise<void>;
84
+ send: (notification: JSONRPCRequest) => void | Promise<void>;
85
+ close: (reason: "closed" | "cancelled") => void | Promise<void>;
86
+ };
87
+ import type { SubscriptionFilter } from "tmcp";
88
+ import type { JSONRPCRequest } from "json-rpc-2.0";
89
+ import type { Context }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CAAC,CAAC,CAAC,oBAAoB,CAAC,CAAC,CAwH9E;IAKD,0BArHW,MAAM,uBACN,WAAW,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,oBAAoB,CAAC,QAsHnE;IAKD,gBAnHW,MAAM,GACJ,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAsHpE;IAKD,gBAnHW,MAAM,aACN,WAAW,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,UAAU,CAAC,QAoHzD;IAKD,sBAjHW,MAAM,GACJ,OAAO,CAAC,MAAM,EAAE,CAAC,CAkH7B;IAKD,oBA/GW,MAAM,OACN,MAAM,QAqHhB;IAKD,uBAlHW,MAAM,OACN,MAAM,QAsHhB;IAKD,WAnHW,MAAM,QA2HhB;;CACD;2BAziBY;IAAE,EAAE,EAAE,MAAM,GAAG,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,kBAAkB,CAAA;CAAE;oCACpE;IAAE,WAAW,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAAC,IAAI,EAAE,CAAC,YAAY,EAAE,cAAc,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAAC,KAAK,EAAE,CAAC,MAAM,EAAE,QAAQ,GAAG,WAAW,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;CAAE;wCANvI,MAAM;oCACnB,cAAc;6BADD,MAAM"}
@@ -1,141 +0,0 @@
1
- declare module '@tmcp/session-manager' {
2
- import type { SubscriptionFilter, Context } from 'tmcp';
3
- import type { JSONRPCRequest } from 'json-rpc-2.0';
4
- /**
5
- * @import { Context, SubscriptionFilter } from "tmcp";
6
- * @import { JSONRPCRequest } from "json-rpc-2.0";
7
- */
8
- /**
9
- * Determine whether a notification belongs on a subscription stream.
10
- * Distributed managers can use this directly or maintain equivalent indexes.
11
- * */
12
- export function matchesSubscription(filters: SubscriptionFilter, notification: JSONRPCRequest): boolean;
13
- /**
14
- * Routes notifications to long-lived per-request subscription streams.
15
- * Callbacks remain local to the process serving the response stream. Brokered
16
- * implementations can distribute notifications without persisting descriptors.
17
- * @abstract
18
- */
19
- export abstract class SubscriptionManager {
20
- /**
21
- * @abstract
22
- * Atomically register a subscription. Matching notifications must be
23
- * buffered until acknowledgement completes and then delivered in order.
24
- * */
25
- abstract create(subscription: Subscription, callbacks: SubscriptionCallbacks): boolean | Promise<boolean>;
26
- /**
27
- * @abstract
28
- * */
29
- abstract send(notification: JSONRPCRequest): void | Promise<void>;
30
- /**
31
- * @abstract
32
- * Request closure of one subscription. Implementations must preserve the
33
- * JSON-RPC ID type when identifying a registration.
34
- * */
35
- abstract close(id: string | number, origin: string, reason: "closed" | "cancelled"): boolean | Promise<boolean>;
36
- /**
37
- * @abstract
38
- * Close every subscription, optionally limited to one transport origin.
39
- * */
40
- abstract closeAll(origin?: string, reason?: "closed" | "cancelled"): void | Promise<void>;
41
- }
42
- /**
43
- * Process-local subscription manager. Distributed implementations should
44
- * mirror its acknowledgement buffering and per-subscription ordering.
45
- */
46
- export class InMemorySubscriptionManager extends SubscriptionManager {
47
- create(subscription: Subscription, callbacks: SubscriptionCallbacks): Promise<boolean>;
48
- send(notification: JSONRPCRequest): Promise<void>;
49
- close(id: string | number, origin: string, reason: "closed" | "cancelled"): Promise<boolean>;
50
- closeAll(origin?: string, reason?: "closed" | "cancelled"): Promise<void>;
51
- #private;
52
- }
53
- /**
54
- * @abstract
55
- */
56
- export abstract class StreamSessionManager {
57
- /**
58
- * @abstract
59
- * */
60
- abstract create(id: string, controller: ReadableStreamDefaultController): void | Promise<void>;
61
- /**
62
- * @abstract
63
- * */
64
- abstract delete(id: string): void | Promise<void>;
65
- /**
66
- * @abstract
67
- * */
68
- abstract has(id: string): boolean | Promise<boolean>;
69
- /**
70
- * @abstract
71
- * */
72
- abstract send(sessions: string[] | undefined, data: string): void | Promise<void>;
73
- }
74
- export class InMemoryStreamSessionManager extends StreamSessionManager {
75
- create(id: string, controller: ReadableStreamDefaultController): void;
76
- delete(id: string): void;
77
- has(id: string): Promise<boolean>;
78
- send(sessions: string[] | undefined, data: string): void;
79
- #private;
80
- }
81
- /**
82
- * @abstract
83
- */
84
- export abstract class InfoSessionManager {
85
- /**
86
- * @abstract
87
- * */
88
- abstract getClientInfo(id: string): Promise<NonNullable<Context["sessionInfo"]>["clientInfo"]>;
89
- /**
90
- * @abstract
91
- * */
92
- abstract setClientInfo(id: string, client_info: NonNullable<Context["sessionInfo"]>["clientInfo"]): void;
93
- /**
94
- * @abstract
95
- * */
96
- abstract getClientCapabilities(id: string): Promise<NonNullable<Context["sessionInfo"]>["clientCapabilities"]>;
97
- /**
98
- * @abstract
99
- * */
100
- abstract setClientCapabilities(id: string, client_capabilities: NonNullable<Context["sessionInfo"]>["clientCapabilities"]): void;
101
- /**
102
- * @abstract
103
- * */
104
- abstract getLogLevel(id: string): Promise<NonNullable<Context["sessionInfo"]>["logLevel"]>;
105
- /**
106
- * @abstract
107
- * */
108
- abstract setLogLevel(id: string, log_level: NonNullable<Context["sessionInfo"]>["logLevel"]): void;
109
- /**
110
- * @abstract
111
- * */
112
- abstract getSubscriptions(uri: string): Promise<string[]>;
113
- /**
114
- * @abstract
115
- * */
116
- abstract addSubscription(id: string, uri: string): void;
117
- /**
118
- * @abstract
119
- * */
120
- abstract removeSubscription(id: string, uri: string): void;
121
- /**
122
- * @abstract
123
- * */
124
- abstract delete(id: string): void;
125
- }
126
- export class InMemoryInfoSessionManager extends InfoSessionManager {
127
- #private;
128
- }
129
- export type Subscription = {
130
- id: string | number;
131
- origin: string;
132
- filters: SubscriptionFilter;
133
- };
134
- export type SubscriptionCallbacks = {
135
- acknowledge: () => void | Promise<void>;
136
- send: (notification: JSONRPCRequest) => void | Promise<void>;
137
- close: (reason: "closed" | "cancelled") => void | Promise<void>;
138
- };
139
- export {};
140
- }
141
- //# sourceMappingURL=index.d.ts.map
@@ -1,23 +0,0 @@
1
- {
2
- "version": 3,
3
- "file": "index.d.ts",
4
- "names": [
5
- "matchesSubscription",
6
- "SubscriptionManager",
7
- "InMemorySubscriptionManager",
8
- "StreamSessionManager",
9
- "InMemoryStreamSessionManager",
10
- "InfoSessionManager",
11
- "InMemoryInfoSessionManager",
12
- "Subscription",
13
- "SubscriptionCallbacks"
14
- ],
15
- "sources": [
16
- "../index.js"
17
- ],
18
- "sourcesContent": [
19
- null
20
- ],
21
- "mappings": ";;;;;;;;;;;;iBAkBgBA,mBAAmBA;;;;;;;cA4BtBC,mBAAmBA;;;;;;;;;;;;;;;;;;;;;;;;;;;cA2DnBC,2BAA2BA;;;;;;;;;;;;;;cAsJ3BC,oBAAoBA;;;;;;;;;;;;;;;;;;cAwCpBC,4BAA4BA;;;;;;;;;;;;;;cA0D5BC,kBAAkBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cA2FlBC,0BAA0BA;;;aApb4CC,YAAYA;;;;;aAC0FC,qBAAqBA",
22
- "ignoreList": []
23
- }