@tmcp/session-manager 0.1.1 → 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 +28 -0
- package/README.md +96 -77
- package/package.json +4 -1
- package/src/index.js +202 -4
- package/src/types/index.d.ts +49 -4
- package/src/types/index.d.ts.map +5 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,33 @@
|
|
|
1
1
|
# @tmcp/session-manager
|
|
2
2
|
|
|
3
|
+
## 0.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 8a04ee2: breaking: move sessions out of core into the transports and allow for persistent mcp state
|
|
8
|
+
|
|
9
|
+
This release moves the session management out of the core package into the SSE and HTTP transport separately.
|
|
10
|
+
While technically a breaking change if you update both `tmcp` and your transport (`@tmcp/transport-http`,
|
|
11
|
+
`@tmcp/transport-sse`, or `@tmcp/transport-stdio`), you will not face a breaking change unless you were using a
|
|
12
|
+
session manager.
|
|
13
|
+
|
|
14
|
+
If you were testing your `McpServer` instance manually you might need to update them to pass the `sessionInfo`
|
|
15
|
+
in the context parameter (only if you were reading them in the tool/resource/prompt).
|
|
16
|
+
|
|
17
|
+
Sorry for the "breaking" but this was a necessary step to unlock persistent state. 🧡
|
|
18
|
+
|
|
19
|
+
### Patch Changes
|
|
20
|
+
|
|
21
|
+
- Updated dependencies [8a04ee2]
|
|
22
|
+
- Updated dependencies [a9254cb]
|
|
23
|
+
- tmcp@1.16.0
|
|
24
|
+
|
|
25
|
+
## 0.1.2
|
|
26
|
+
|
|
27
|
+
### Patch Changes
|
|
28
|
+
|
|
29
|
+
- c0f7d7f: fix: try catch closing controller in case it's already closed
|
|
30
|
+
|
|
3
31
|
## 0.1.1
|
|
4
32
|
|
|
5
33
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @tmcp/session-manager
|
|
2
2
|
|
|
3
|
-
Session management for TMCP (TypeScript Model Context Protocol) transport implementations. This package provides the base
|
|
3
|
+
Session management for TMCP (TypeScript Model Context Protocol) transport implementations. This package provides the base classes and in-memory implementations for both streaming session coordination and session metadata persistence.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -10,132 +10,151 @@ pnpm add @tmcp/session-manager
|
|
|
10
10
|
|
|
11
11
|
## Overview
|
|
12
12
|
|
|
13
|
-
Session
|
|
13
|
+
Session management is split into two concerns:
|
|
14
|
+
|
|
15
|
+
- **Stream session managers** handle the storage of long-lived streaming connections (SSE/HTTP) and the fan-out of notifications back to the right session.
|
|
16
|
+
- **Info session managers** persist metadata that MCP transports need across requests, such as client capabilities, client info, requested log level, and resource subscriptions.
|
|
17
|
+
|
|
18
|
+
Together they manage:
|
|
14
19
|
|
|
15
20
|
- **Session Creation**: Establishing new client sessions with stream controllers
|
|
16
|
-
- **Session Deletion**: Cleaning up disconnected sessions
|
|
17
|
-
- **Session Queries**: Checking
|
|
18
|
-
- **Message
|
|
21
|
+
- **Session Deletion**: Cleaning up disconnected sessions and metadata
|
|
22
|
+
- **Session Queries**: Checking whether a given session is still attached
|
|
23
|
+
- **Message Delivery**: Sending messages to specific sessions or everyone
|
|
24
|
+
- **Client Metadata**: Persisting capabilities, `clientInfo`, and log level between requests
|
|
25
|
+
- **Resource Subscriptions**: Tracking which sessions subscribed to which URIs
|
|
19
26
|
|
|
20
27
|
## Usage
|
|
21
28
|
|
|
22
|
-
### In-Memory Session
|
|
29
|
+
### In-Memory Session Managers (Default)
|
|
23
30
|
|
|
24
|
-
The `
|
|
31
|
+
The package ships with `InMemoryStreamSessionManager` and `InMemoryInfoSessionManager`. Together they are suitable for single-server deployments or tests:
|
|
25
32
|
|
|
26
33
|
```javascript
|
|
27
|
-
import {
|
|
28
|
-
|
|
29
|
-
|
|
34
|
+
import {
|
|
35
|
+
InMemoryStreamSessionManager,
|
|
36
|
+
InMemoryInfoSessionManager,
|
|
37
|
+
} from '@tmcp/session-manager';
|
|
38
|
+
|
|
39
|
+
const sessionManagers = {
|
|
40
|
+
streams: new InMemoryStreamSessionManager(),
|
|
41
|
+
info: new InMemoryInfoSessionManager(),
|
|
42
|
+
};
|
|
30
43
|
```
|
|
31
44
|
|
|
32
|
-
### Custom Session
|
|
45
|
+
### Custom Session Managers
|
|
46
|
+
|
|
47
|
+
You can implement your own managers by extending the base classes that ship with this package.
|
|
33
48
|
|
|
34
|
-
|
|
49
|
+
#### Stream session manager
|
|
35
50
|
|
|
36
51
|
```javascript
|
|
37
|
-
import {
|
|
38
|
-
|
|
39
|
-
class
|
|
40
|
-
/**
|
|
41
|
-
* Create a new session with the given ID and controller
|
|
42
|
-
* @param {string} id - Session ID
|
|
43
|
-
* @param {ReadableStreamDefaultController} controller - Stream controller
|
|
44
|
-
*/
|
|
52
|
+
import { StreamSessionManager } from '@tmcp/session-manager';
|
|
53
|
+
|
|
54
|
+
class CustomStreamSessionManager extends StreamSessionManager {
|
|
45
55
|
create(id, controller) {
|
|
46
|
-
//
|
|
56
|
+
// Persist the ReadableStream controller for later notifications
|
|
47
57
|
}
|
|
48
58
|
|
|
49
|
-
/**
|
|
50
|
-
* Delete a session by ID
|
|
51
|
-
* @param {string} id - Session ID to delete
|
|
52
|
-
*/
|
|
53
59
|
delete(id) {
|
|
54
|
-
//
|
|
60
|
+
// Clean up the controller and any associated timers
|
|
55
61
|
}
|
|
56
62
|
|
|
57
|
-
/**
|
|
58
|
-
* Check if a session exists
|
|
59
|
-
* @param {string} id - Session ID to check
|
|
60
|
-
* @returns {Promise<boolean>} - Whether the session exists
|
|
61
|
-
*/
|
|
62
63
|
async has(id) {
|
|
63
|
-
//
|
|
64
|
+
// Return whether a controller for the session exists
|
|
64
65
|
}
|
|
65
66
|
|
|
66
|
-
/**
|
|
67
|
-
* Send data to specific sessions or all sessions
|
|
68
|
-
* @param {string[] | undefined} sessions - Session IDs to send to (undefined = all sessions)
|
|
69
|
-
* @param {string} data - Data to send
|
|
70
|
-
*/
|
|
71
67
|
send(sessions, data) {
|
|
72
|
-
//
|
|
68
|
+
// Fan out the payload to the targeted sessions (or everyone if sessions is undefined)
|
|
73
69
|
}
|
|
74
70
|
}
|
|
75
71
|
```
|
|
76
72
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
### `SessionManager` (Abstract Base Class)
|
|
73
|
+
#### Info session manager
|
|
80
74
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
##### `create(id: string, controller: ReadableStreamDefaultController): void`
|
|
84
|
-
|
|
85
|
-
Creates a new session with the specified ID and associates it with a stream controller.
|
|
86
|
-
|
|
87
|
-
**Parameters:**
|
|
75
|
+
```javascript
|
|
76
|
+
import { InfoSessionManager } from '@tmcp/session-manager';
|
|
88
77
|
|
|
89
|
-
|
|
90
|
-
|
|
78
|
+
class CustomInfoSessionManager extends InfoSessionManager {
|
|
79
|
+
async getClientInfo(id) {
|
|
80
|
+
// Return the last clientInfo payload for the session
|
|
81
|
+
}
|
|
91
82
|
|
|
92
|
-
|
|
83
|
+
setClientInfo(id, info) {
|
|
84
|
+
// Persist clientInfo for later requests
|
|
85
|
+
}
|
|
93
86
|
|
|
94
|
-
|
|
87
|
+
async getClientCapabilities(id) {
|
|
88
|
+
// Retrieve cached client capabilities
|
|
89
|
+
}
|
|
95
90
|
|
|
96
|
-
|
|
91
|
+
setClientCapabilities(id, capabilities) {
|
|
92
|
+
// Persist the negotiated capabilities
|
|
93
|
+
}
|
|
97
94
|
|
|
98
|
-
|
|
95
|
+
async getLogLevel(id) {
|
|
96
|
+
// Return the log level requested by the client
|
|
97
|
+
}
|
|
99
98
|
|
|
100
|
-
|
|
99
|
+
setLogLevel(id, level) {
|
|
100
|
+
// Store the latest log level
|
|
101
|
+
}
|
|
101
102
|
|
|
102
|
-
|
|
103
|
+
async getSubscriptions(uri) {
|
|
104
|
+
// Return all session ids subscribed to the URI
|
|
105
|
+
}
|
|
103
106
|
|
|
104
|
-
|
|
107
|
+
addSubscription(id, uri) {
|
|
108
|
+
// Track that the session subscribed to the URI
|
|
109
|
+
}
|
|
105
110
|
|
|
106
|
-
|
|
111
|
+
delete(id) {
|
|
112
|
+
// Remove all metadata for the session (client info, capabilities, subscriptions, etc.)
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
```
|
|
107
116
|
|
|
108
|
-
|
|
117
|
+
## API
|
|
109
118
|
|
|
110
|
-
|
|
119
|
+
### `StreamSessionManager` (Abstract Base Class)
|
|
111
120
|
|
|
112
|
-
|
|
121
|
+
Responsible for creating and managing streaming controllers.
|
|
113
122
|
|
|
114
|
-
|
|
123
|
+
- `create(id, controller)` – register a session and associate its stream controller
|
|
124
|
+
- `delete(id)` – remove the controller and clean up resources
|
|
125
|
+
- `has(id)` – resolve to `true` when a controller for the session exists
|
|
126
|
+
- `send(sessions, data)` – push a payload to selected sessions (or everyone when `sessions` is `undefined`)
|
|
115
127
|
|
|
116
|
-
|
|
128
|
+
### `InfoSessionManager` (Abstract Base Class)
|
|
117
129
|
|
|
118
|
-
|
|
119
|
-
- `data` - String data to send (typically SSE-formatted)
|
|
130
|
+
Stores session metadata that needs to survive across HTTP requests or reconnects.
|
|
120
131
|
|
|
121
|
-
|
|
132
|
+
- `getClientInfo(id)` / `setClientInfo(id, info)`
|
|
133
|
+
- `getClientCapabilities(id)` / `setClientCapabilities(id, capabilities)`
|
|
134
|
+
- `getLogLevel(id)` / `setLogLevel(id, level)`
|
|
135
|
+
- `getSubscriptions(uri)` – return all session IDs that subscribed to a resource
|
|
136
|
+
- `addSubscription(id, uri)` – record a new resource subscription
|
|
137
|
+
- `delete(id)` – remove all metadata for a session when it disconnects
|
|
122
138
|
|
|
123
|
-
|
|
139
|
+
### `InMemoryStreamSessionManager` & `InMemoryInfoSessionManager`
|
|
124
140
|
|
|
125
|
-
|
|
141
|
+
Concrete in-memory implementations that cover both responsibilities. Combine them when configuring a transport:
|
|
126
142
|
|
|
127
143
|
```javascript
|
|
128
144
|
import { HttpTransport } from '@tmcp/transport-http';
|
|
129
145
|
import { SseTransport } from '@tmcp/transport-sse';
|
|
130
|
-
import {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
const
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
146
|
+
import {
|
|
147
|
+
InMemoryStreamSessionManager,
|
|
148
|
+
InMemoryInfoSessionManager,
|
|
149
|
+
} from '@tmcp/session-manager';
|
|
150
|
+
|
|
151
|
+
const sessionManagers = {
|
|
152
|
+
streams: new InMemoryStreamSessionManager(),
|
|
153
|
+
info: new InMemoryInfoSessionManager(),
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
const httpTransport = new HttpTransport(server, { sessionManager: sessionManagers });
|
|
157
|
+
const sseTransport = new SseTransport(server, { sessionManager: sessionManagers });
|
|
139
158
|
```
|
|
140
159
|
|
|
141
160
|
## Related Packages
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tmcp/session-manager",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"repository": {
|
|
@@ -23,6 +23,9 @@
|
|
|
23
23
|
}
|
|
24
24
|
},
|
|
25
25
|
"type": "module",
|
|
26
|
+
"peerDependencies": {
|
|
27
|
+
"tmcp": "^1.16.0"
|
|
28
|
+
},
|
|
26
29
|
"publishConfig": {
|
|
27
30
|
"access": "public"
|
|
28
31
|
},
|
package/src/index.js
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
/* eslint-disable no-unused-vars */
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* @import { Context } from "tmcp";
|
|
5
|
+
*/
|
|
6
|
+
|
|
3
7
|
/**
|
|
4
8
|
* @abstract
|
|
5
9
|
*/
|
|
6
|
-
export class
|
|
10
|
+
export class StreamSessionManager {
|
|
7
11
|
/**
|
|
8
12
|
* @abstract
|
|
9
13
|
* @param {string} id
|
|
@@ -43,7 +47,7 @@ export class SessionManager {
|
|
|
43
47
|
}
|
|
44
48
|
}
|
|
45
49
|
|
|
46
|
-
export class
|
|
50
|
+
export class InMemoryStreamSessionManager extends StreamSessionManager {
|
|
47
51
|
/**
|
|
48
52
|
* @type {Map<string, ReadableStreamDefaultController>}
|
|
49
53
|
*/
|
|
@@ -64,13 +68,16 @@ export class InMemorySessionManager extends SessionManager {
|
|
|
64
68
|
delete(id) {
|
|
65
69
|
const controller = this.#sessions.get(id);
|
|
66
70
|
if (controller) {
|
|
67
|
-
controller.close();
|
|
68
71
|
this.#sessions.delete(id);
|
|
72
|
+
try {
|
|
73
|
+
controller.close();
|
|
74
|
+
} catch {
|
|
75
|
+
// could error if the controller is already closed
|
|
76
|
+
}
|
|
69
77
|
}
|
|
70
78
|
}
|
|
71
79
|
|
|
72
80
|
/**
|
|
73
|
-
* @abstract
|
|
74
81
|
* @param {string} id
|
|
75
82
|
* @returns {Promise<boolean>}
|
|
76
83
|
*/
|
|
@@ -90,3 +97,194 @@ export class InMemorySessionManager extends SessionManager {
|
|
|
90
97
|
}
|
|
91
98
|
}
|
|
92
99
|
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* @abstract
|
|
103
|
+
*/
|
|
104
|
+
export class InfoSessionManager {
|
|
105
|
+
/**
|
|
106
|
+
* @abstract
|
|
107
|
+
* @param {string} id
|
|
108
|
+
* @returns {Promise<NonNullable<Context["sessionInfo"]>["clientInfo"]>}
|
|
109
|
+
*/
|
|
110
|
+
getClientInfo(id) {
|
|
111
|
+
throw new Error('Method not implemented.');
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* @abstract
|
|
116
|
+
* @param {string} id
|
|
117
|
+
* @param {NonNullable<Context["sessionInfo"]>["clientInfo"]} client_info
|
|
118
|
+
*/
|
|
119
|
+
setClientInfo(id, client_info) {
|
|
120
|
+
throw new Error('Method not implemented.');
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* @abstract
|
|
125
|
+
* @param {string} id
|
|
126
|
+
* @returns {Promise<NonNullable<Context["sessionInfo"]>["clientCapabilities"]>}
|
|
127
|
+
*/
|
|
128
|
+
getClientCapabilities(id) {
|
|
129
|
+
throw new Error('Method not implemented.');
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* @abstract
|
|
134
|
+
* @param {string} id
|
|
135
|
+
* @param {NonNullable<Context["sessionInfo"]>["clientCapabilities"]} client_capabilities
|
|
136
|
+
*/
|
|
137
|
+
setClientCapabilities(id, client_capabilities) {
|
|
138
|
+
throw new Error('Method not implemented.');
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* @abstract
|
|
143
|
+
* @param {string} id
|
|
144
|
+
* @returns {Promise<NonNullable<Context["sessionInfo"]>["logLevel"]>}
|
|
145
|
+
*/
|
|
146
|
+
getLogLevel(id) {
|
|
147
|
+
throw new Error('Method not implemented.');
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* @abstract
|
|
152
|
+
* @param {string} id
|
|
153
|
+
* @param {NonNullable<Context["sessionInfo"]>["logLevel"]} log_level
|
|
154
|
+
*/
|
|
155
|
+
setLogLevel(id, log_level) {
|
|
156
|
+
throw new Error('Method not implemented.');
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* @abstract
|
|
161
|
+
* @param {string} uri
|
|
162
|
+
* @returns {Promise<string[]>}
|
|
163
|
+
*/
|
|
164
|
+
getSubscriptions(uri) {
|
|
165
|
+
throw new Error('Method not implemented.');
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* @abstract
|
|
170
|
+
* @param {string} id
|
|
171
|
+
* @param {string} uri
|
|
172
|
+
*/
|
|
173
|
+
addSubscription(id, uri) {
|
|
174
|
+
throw new Error('Method not implemented.');
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* @abstract
|
|
179
|
+
* @param {string} id
|
|
180
|
+
*/
|
|
181
|
+
delete(id) {
|
|
182
|
+
throw new Error('Method not implemented.');
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
export class InMemoryInfoSessionManager extends InfoSessionManager {
|
|
187
|
+
/**
|
|
188
|
+
* @type {Map<string, NonNullable<Context["sessionInfo"]>["clientInfo"]>}
|
|
189
|
+
*/
|
|
190
|
+
#client_info = new Map();
|
|
191
|
+
/**
|
|
192
|
+
* @type {Map<string, NonNullable<Context["sessionInfo"]>["clientCapabilities"]>}
|
|
193
|
+
*/
|
|
194
|
+
#client_capabilities = new Map();
|
|
195
|
+
/**
|
|
196
|
+
* @type {Map<string, NonNullable<Context["sessionInfo"]>["logLevel"]>}
|
|
197
|
+
*/
|
|
198
|
+
#log_level = new Map();
|
|
199
|
+
/**
|
|
200
|
+
* @type {Map<string, Set<string>>}
|
|
201
|
+
*/
|
|
202
|
+
#subscriptions = new Map();
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* @param {string} session
|
|
206
|
+
* @param {string} name
|
|
207
|
+
* @returns {Promise<never>}
|
|
208
|
+
*/
|
|
209
|
+
async #invariant(session, name) {
|
|
210
|
+
throw new Error(`${name} not found for session ${session}`);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* @type {InfoSessionManager["getClientInfo"]}
|
|
215
|
+
*/
|
|
216
|
+
getClientInfo(id) {
|
|
217
|
+
return Promise.resolve(
|
|
218
|
+
this.#client_info.get(id) ?? this.#invariant(id, 'Client info'),
|
|
219
|
+
);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* @type {InfoSessionManager["setClientInfo"]}
|
|
224
|
+
*/
|
|
225
|
+
setClientInfo(id, client_info) {
|
|
226
|
+
this.#client_info.set(id, client_info);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* @type {InfoSessionManager["getClientCapabilities"]}
|
|
231
|
+
*/
|
|
232
|
+
getClientCapabilities(id) {
|
|
233
|
+
return Promise.resolve(
|
|
234
|
+
this.#client_capabilities.get(id) ??
|
|
235
|
+
this.#invariant(id, 'Client capabilities'),
|
|
236
|
+
);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* @type {InfoSessionManager["setClientCapabilities"]}
|
|
241
|
+
*/
|
|
242
|
+
setClientCapabilities(id, client_capabilities) {
|
|
243
|
+
this.#client_capabilities.set(id, client_capabilities);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* @type {InfoSessionManager["getLogLevel"]}
|
|
248
|
+
*/
|
|
249
|
+
getLogLevel(id) {
|
|
250
|
+
return Promise.resolve(
|
|
251
|
+
this.#log_level.get(id) ?? this.#invariant(id, 'Log Level'),
|
|
252
|
+
);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* @type {InfoSessionManager["setLogLevel"]}
|
|
257
|
+
*/
|
|
258
|
+
setLogLevel(id, log_level) {
|
|
259
|
+
this.#log_level.set(id, log_level);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* @type {InfoSessionManager["getSubscriptions"]}
|
|
264
|
+
*/
|
|
265
|
+
getSubscriptions(uri) {
|
|
266
|
+
return Promise.resolve([...(this.#subscriptions.get(uri) ?? [])]);
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* @type {InfoSessionManager["addSubscription"]}
|
|
271
|
+
*/
|
|
272
|
+
addSubscription(id, uri) {
|
|
273
|
+
let subscriptions = this.#subscriptions.get(uri);
|
|
274
|
+
if (!subscriptions) {
|
|
275
|
+
subscriptions = new Set();
|
|
276
|
+
this.#subscriptions.set(uri, subscriptions);
|
|
277
|
+
}
|
|
278
|
+
subscriptions.add(id);
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* @type {InfoSessionManager["delete"]}
|
|
283
|
+
*/
|
|
284
|
+
delete(id) {
|
|
285
|
+
this.#subscriptions.delete(id);
|
|
286
|
+
this.#log_level.delete(id);
|
|
287
|
+
this.#client_capabilities.delete(id);
|
|
288
|
+
this.#client_info.delete(id);
|
|
289
|
+
}
|
|
290
|
+
}
|
package/src/types/index.d.ts
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
declare module '@tmcp/session-manager' {
|
|
2
|
+
import type { Context } from 'tmcp';
|
|
3
|
+
/**
|
|
4
|
+
* @import { Context } from "tmcp";
|
|
5
|
+
*/
|
|
2
6
|
/**
|
|
3
7
|
* @abstract
|
|
4
8
|
*/
|
|
5
|
-
export abstract class
|
|
9
|
+
export abstract class StreamSessionManager {
|
|
6
10
|
/**
|
|
7
11
|
* @abstract
|
|
8
12
|
* */
|
|
@@ -20,14 +24,55 @@ declare module '@tmcp/session-manager' {
|
|
|
20
24
|
* */
|
|
21
25
|
abstract send(sessions: string[] | undefined, data: string): void | Promise<void>;
|
|
22
26
|
}
|
|
23
|
-
export class
|
|
27
|
+
export class InMemoryStreamSessionManager extends StreamSessionManager {
|
|
24
28
|
create(id: string, controller: ReadableStreamDefaultController): void;
|
|
25
29
|
delete(id: string): void;
|
|
30
|
+
has(id: string): Promise<boolean>;
|
|
31
|
+
send(sessions: string[] | undefined, data: string): void;
|
|
32
|
+
#private;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* @abstract
|
|
36
|
+
*/
|
|
37
|
+
export abstract class InfoSessionManager {
|
|
26
38
|
/**
|
|
27
39
|
* @abstract
|
|
28
40
|
* */
|
|
29
|
-
abstract
|
|
30
|
-
|
|
41
|
+
abstract getClientInfo(id: string): Promise<NonNullable<Context["sessionInfo"]>["clientInfo"]>;
|
|
42
|
+
/**
|
|
43
|
+
* @abstract
|
|
44
|
+
* */
|
|
45
|
+
abstract setClientInfo(id: string, client_info: NonNullable<Context["sessionInfo"]>["clientInfo"]): void;
|
|
46
|
+
/**
|
|
47
|
+
* @abstract
|
|
48
|
+
* */
|
|
49
|
+
abstract getClientCapabilities(id: string): Promise<NonNullable<Context["sessionInfo"]>["clientCapabilities"]>;
|
|
50
|
+
/**
|
|
51
|
+
* @abstract
|
|
52
|
+
* */
|
|
53
|
+
abstract setClientCapabilities(id: string, client_capabilities: NonNullable<Context["sessionInfo"]>["clientCapabilities"]): void;
|
|
54
|
+
/**
|
|
55
|
+
* @abstract
|
|
56
|
+
* */
|
|
57
|
+
abstract getLogLevel(id: string): Promise<NonNullable<Context["sessionInfo"]>["logLevel"]>;
|
|
58
|
+
/**
|
|
59
|
+
* @abstract
|
|
60
|
+
* */
|
|
61
|
+
abstract setLogLevel(id: string, log_level: NonNullable<Context["sessionInfo"]>["logLevel"]): void;
|
|
62
|
+
/**
|
|
63
|
+
* @abstract
|
|
64
|
+
* */
|
|
65
|
+
abstract getSubscriptions(uri: string): Promise<string[]>;
|
|
66
|
+
/**
|
|
67
|
+
* @abstract
|
|
68
|
+
* */
|
|
69
|
+
abstract addSubscription(id: string, uri: string): void;
|
|
70
|
+
/**
|
|
71
|
+
* @abstract
|
|
72
|
+
* */
|
|
73
|
+
abstract delete(id: string): void;
|
|
74
|
+
}
|
|
75
|
+
export class InMemoryInfoSessionManager extends InfoSessionManager {
|
|
31
76
|
#private;
|
|
32
77
|
}
|
|
33
78
|
export {};
|
package/src/types/index.d.ts.map
CHANGED
|
@@ -2,8 +2,10 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"file": "index.d.ts",
|
|
4
4
|
"names": [
|
|
5
|
-
"
|
|
6
|
-
"
|
|
5
|
+
"StreamSessionManager",
|
|
6
|
+
"InMemoryStreamSessionManager",
|
|
7
|
+
"InfoSessionManager",
|
|
8
|
+
"InMemoryInfoSessionManager"
|
|
7
9
|
],
|
|
8
10
|
"sources": [
|
|
9
11
|
"../index.js"
|
|
@@ -11,6 +13,6 @@
|
|
|
11
13
|
"sourcesContent": [
|
|
12
14
|
null
|
|
13
15
|
],
|
|
14
|
-
"mappings": "
|
|
16
|
+
"mappings": ";;;;;;;;cASaA,oBAAoBA;;;;;;;;;;;;;;;;;;cAwCpBC,4BAA4BA;;;;;;;;;;;;;;cAsD5BC,kBAAkBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAkFlBC,0BAA0BA",
|
|
15
17
|
"ignoreList": []
|
|
16
18
|
}
|