@jupyterlite/session 0.7.0-beta.0 → 0.7.0-rc.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/lib/index.d.ts +16 -1
- package/lib/index.js +17 -1
- package/lib/index.js.map +1 -1
- package/package.json +4 -8
- package/src/index.ts +18 -1
- package/lib/client.d.ts +0 -85
- package/lib/client.js +0 -200
- package/lib/client.js.map +0 -1
- package/src/client.ts +0 -251
package/lib/index.d.ts
CHANGED
|
@@ -1 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @deprecated This package is deprecated. Please import from @jupyterlite/services instead.
|
|
3
|
+
*
|
|
4
|
+
* This package now acts as a shim that re-exports session-related components from
|
|
5
|
+
* @jupyterlite/services for backward compatibility.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* // Old (deprecated):
|
|
10
|
+
* import { LiteSessionClient } from '@jupyterlite/session';
|
|
11
|
+
*
|
|
12
|
+
* // New (recommended):
|
|
13
|
+
* import { LiteSessionClient } from '@jupyterlite/services';
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export { LiteSessionClient } from '@jupyterlite/services';
|
package/lib/index.js
CHANGED
|
@@ -1,4 +1,20 @@
|
|
|
1
1
|
// Copyright (c) Jupyter Development Team.
|
|
2
2
|
// Distributed under the terms of the Modified BSD License.
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* @deprecated This package is deprecated. Please import from @jupyterlite/services instead.
|
|
5
|
+
*
|
|
6
|
+
* This package now acts as a shim that re-exports session-related components from
|
|
7
|
+
* @jupyterlite/services for backward compatibility.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* // Old (deprecated):
|
|
12
|
+
* import { LiteSessionClient } from '@jupyterlite/session';
|
|
13
|
+
*
|
|
14
|
+
* // New (recommended):
|
|
15
|
+
* import { LiteSessionClient } from '@jupyterlite/services';
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
// Re-export session-related classes
|
|
19
|
+
export { LiteSessionClient } from '@jupyterlite/services';
|
|
4
20
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,0CAA0C;AAC1C,2DAA2D;AAE3D,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,0CAA0C;AAC1C,2DAA2D;AAE3D;;;;;;;;;;;;;;GAcG;AAEH,oCAAoC;AACpC,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jupyterlite/session",
|
|
3
|
-
"version": "0.7.0-
|
|
4
|
-
"description": "JupyterLite - Session",
|
|
3
|
+
"version": "0.7.0-rc.0",
|
|
4
|
+
"description": "JupyterLite - Session (DEPRECATED: Use @jupyterlite/services instead)",
|
|
5
5
|
"homepage": "https://github.com/jupyterlite/jupyterlite",
|
|
6
6
|
"bugs": {
|
|
7
7
|
"url": "https://github.com/jupyterlite/jupyterlite/issues"
|
|
@@ -43,16 +43,12 @@
|
|
|
43
43
|
"watch": "tsc -b --watch"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@
|
|
47
|
-
"@jupyterlab/services": "~7.5.0-beta.1",
|
|
48
|
-
"@jupyterlite/kernel": "^0.7.0-beta.0",
|
|
49
|
-
"@lumino/algorithm": "^2.0.3",
|
|
50
|
-
"@lumino/coreutils": "^2.2.1"
|
|
46
|
+
"@jupyterlite/services": "^0.7.0-rc.0"
|
|
51
47
|
},
|
|
52
48
|
"devDependencies": {
|
|
53
49
|
"@babel/core": "^7.11.6",
|
|
54
50
|
"@babel/preset-env": "^7.12.1",
|
|
55
|
-
"@jupyterlab/testutils": "~4.5.0
|
|
51
|
+
"@jupyterlab/testutils": "~4.5.0",
|
|
56
52
|
"@types/jest": "^29.5.3",
|
|
57
53
|
"jest": "^29.6.2",
|
|
58
54
|
"rimraf": "~5.0.1",
|
package/src/index.ts
CHANGED
|
@@ -1,4 +1,21 @@
|
|
|
1
1
|
// Copyright (c) Jupyter Development Team.
|
|
2
2
|
// Distributed under the terms of the Modified BSD License.
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
/**
|
|
5
|
+
* @deprecated This package is deprecated. Please import from @jupyterlite/services instead.
|
|
6
|
+
*
|
|
7
|
+
* This package now acts as a shim that re-exports session-related components from
|
|
8
|
+
* @jupyterlite/services for backward compatibility.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* // Old (deprecated):
|
|
13
|
+
* import { LiteSessionClient } from '@jupyterlite/session';
|
|
14
|
+
*
|
|
15
|
+
* // New (recommended):
|
|
16
|
+
* import { LiteSessionClient } from '@jupyterlite/services';
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
// Re-export session-related classes
|
|
21
|
+
export { LiteSessionClient } from '@jupyterlite/services';
|
package/lib/client.d.ts
DELETED
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import { ServerConnection, Session } from '@jupyterlab/services';
|
|
2
|
-
import { LiteKernelClient } from '@jupyterlite/kernel';
|
|
3
|
-
import { ISessionAPIClient } from '@jupyterlab/services/lib/session/session';
|
|
4
|
-
type DeepPartial<T> = {
|
|
5
|
-
[P in keyof T]?: DeepPartial<T[P]>;
|
|
6
|
-
};
|
|
7
|
-
/**
|
|
8
|
-
* A class to handle requests to /api/sessions
|
|
9
|
-
*/
|
|
10
|
-
export declare class LiteSessionClient implements ISessionAPIClient {
|
|
11
|
-
/**
|
|
12
|
-
* Construct a new LiteSessionClient.
|
|
13
|
-
*
|
|
14
|
-
* @param options The instantiation options for a LiteSessionClient.
|
|
15
|
-
*/
|
|
16
|
-
constructor(options: LiteSessionClient.IOptions);
|
|
17
|
-
/**
|
|
18
|
-
* The server settings for the session client.
|
|
19
|
-
*/
|
|
20
|
-
get serverSettings(): ServerConnection.ISettings;
|
|
21
|
-
/**
|
|
22
|
-
* Get a session by id.
|
|
23
|
-
*
|
|
24
|
-
* @param id The id of the session.
|
|
25
|
-
*/
|
|
26
|
-
getModel(id: string): Promise<Session.IModel>;
|
|
27
|
-
/**
|
|
28
|
-
* List the running sessions
|
|
29
|
-
*/
|
|
30
|
-
listRunning(): Promise<Session.IModel[]>;
|
|
31
|
-
/**
|
|
32
|
-
* Patch an existing session.
|
|
33
|
-
* This can be used to rename a session.
|
|
34
|
-
*
|
|
35
|
-
* - path updates session to track renamed paths
|
|
36
|
-
* - kernel.name starts a new kernel with a given kernelspec
|
|
37
|
-
*
|
|
38
|
-
* @param options The options to patch the session.
|
|
39
|
-
*/
|
|
40
|
-
update(options: DeepPartial<Session.IModel>): Promise<Session.IModel>;
|
|
41
|
-
/**
|
|
42
|
-
* Start a new session
|
|
43
|
-
* TODO: read path and name
|
|
44
|
-
*
|
|
45
|
-
* @param options The options to start a new session.
|
|
46
|
-
*/
|
|
47
|
-
startNew(options: Session.ISessionOptions): Promise<Session.IModel>;
|
|
48
|
-
/**
|
|
49
|
-
* Shut down a session.
|
|
50
|
-
*
|
|
51
|
-
* @param id The id of the session to shut down.
|
|
52
|
-
*/
|
|
53
|
-
shutdown(id: string): Promise<void>;
|
|
54
|
-
/**
|
|
55
|
-
* Shut down all sessions.
|
|
56
|
-
*/
|
|
57
|
-
shutdownAll(): Promise<void>;
|
|
58
|
-
/**
|
|
59
|
-
* Handle kernel shutdown
|
|
60
|
-
*/
|
|
61
|
-
private _handleKernelShutdown;
|
|
62
|
-
private _kernelClient;
|
|
63
|
-
private _serverSettings;
|
|
64
|
-
private _sessions;
|
|
65
|
-
private _pendingRestarts;
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* A namespace for LiteSessionClient statics.
|
|
69
|
-
*/
|
|
70
|
-
export declare namespace LiteSessionClient {
|
|
71
|
-
/**
|
|
72
|
-
* The instantiation options for the session client.
|
|
73
|
-
*/
|
|
74
|
-
interface IOptions {
|
|
75
|
-
/**
|
|
76
|
-
* A reference to the kernels service.
|
|
77
|
-
*/
|
|
78
|
-
kernelClient: LiteKernelClient;
|
|
79
|
-
/**
|
|
80
|
-
* Server settings for the session client.
|
|
81
|
-
*/
|
|
82
|
-
serverSettings?: ServerConnection.ISettings;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
export {};
|
package/lib/client.js
DELETED
|
@@ -1,200 +0,0 @@
|
|
|
1
|
-
import { ServerConnection } from '@jupyterlab/services';
|
|
2
|
-
import { PathExt } from '@jupyterlab/coreutils';
|
|
3
|
-
import { ArrayExt } from '@lumino/algorithm';
|
|
4
|
-
import { UUID } from '@lumino/coreutils';
|
|
5
|
-
/**
|
|
6
|
-
* A class to handle requests to /api/sessions
|
|
7
|
-
*/
|
|
8
|
-
export class LiteSessionClient {
|
|
9
|
-
/**
|
|
10
|
-
* Construct a new LiteSessionClient.
|
|
11
|
-
*
|
|
12
|
-
* @param options The instantiation options for a LiteSessionClient.
|
|
13
|
-
*/
|
|
14
|
-
constructor(options) {
|
|
15
|
-
var _a;
|
|
16
|
-
this._sessions = [];
|
|
17
|
-
this._pendingRestarts = new Set();
|
|
18
|
-
this._kernelClient = options.kernelClient;
|
|
19
|
-
this._serverSettings = (_a = options.serverSettings) !== null && _a !== void 0 ? _a : ServerConnection.makeSettings();
|
|
20
|
-
// Listen for kernel removals
|
|
21
|
-
this._kernelClient.changed.connect((_, args) => {
|
|
22
|
-
var _a, _b;
|
|
23
|
-
switch (args.type) {
|
|
24
|
-
case 'remove': {
|
|
25
|
-
const kernelId = (_a = args.oldValue) === null || _a === void 0 ? void 0 : _a.id;
|
|
26
|
-
if (!kernelId) {
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
// find the session associated with the kernel
|
|
30
|
-
const session = this._sessions.find((s) => { var _a; return ((_a = s.kernel) === null || _a === void 0 ? void 0 : _a.id) === kernelId; });
|
|
31
|
-
if (!session) {
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
// Track the kernel ID for restart detection
|
|
35
|
-
this._pendingRestarts.add(kernelId);
|
|
36
|
-
setTimeout(async () => {
|
|
37
|
-
// If after a short delay the kernel hasn't been re-added, it was terminated
|
|
38
|
-
if (this._pendingRestarts.has(kernelId)) {
|
|
39
|
-
this._pendingRestarts.delete(kernelId);
|
|
40
|
-
await this.shutdown(session.id);
|
|
41
|
-
}
|
|
42
|
-
}, 100);
|
|
43
|
-
break;
|
|
44
|
-
}
|
|
45
|
-
case 'add': {
|
|
46
|
-
// If this was a restart, remove it from pending
|
|
47
|
-
const kernelId = (_b = args.newValue) === null || _b === void 0 ? void 0 : _b.id;
|
|
48
|
-
if (!kernelId) {
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
this._pendingRestarts.delete(kernelId);
|
|
52
|
-
break;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* The server settings for the session client.
|
|
59
|
-
*/
|
|
60
|
-
get serverSettings() {
|
|
61
|
-
return this._serverSettings;
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Get a session by id.
|
|
65
|
-
*
|
|
66
|
-
* @param id The id of the session.
|
|
67
|
-
*/
|
|
68
|
-
async getModel(id) {
|
|
69
|
-
const session = this._sessions.find((s) => s.id === id);
|
|
70
|
-
if (!session) {
|
|
71
|
-
throw Error(`Session ${id} not found`);
|
|
72
|
-
}
|
|
73
|
-
return session;
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* List the running sessions
|
|
77
|
-
*/
|
|
78
|
-
async listRunning() {
|
|
79
|
-
return this._sessions;
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Patch an existing session.
|
|
83
|
-
* This can be used to rename a session.
|
|
84
|
-
*
|
|
85
|
-
* - path updates session to track renamed paths
|
|
86
|
-
* - kernel.name starts a new kernel with a given kernelspec
|
|
87
|
-
*
|
|
88
|
-
* @param options The options to patch the session.
|
|
89
|
-
*/
|
|
90
|
-
async update(options) {
|
|
91
|
-
const { id, path, name, kernel } = options;
|
|
92
|
-
const index = this._sessions.findIndex((s) => s.id === id);
|
|
93
|
-
const session = this._sessions[index];
|
|
94
|
-
if (!session) {
|
|
95
|
-
throw Error(`Session ${id} not found`);
|
|
96
|
-
}
|
|
97
|
-
const patched = {
|
|
98
|
-
...session,
|
|
99
|
-
path: path !== null && path !== void 0 ? path : session.path,
|
|
100
|
-
name: name !== null && name !== void 0 ? name : session.name,
|
|
101
|
-
};
|
|
102
|
-
if (kernel) {
|
|
103
|
-
// Kernel id takes precedence over name.
|
|
104
|
-
if (kernel.id) {
|
|
105
|
-
const session = this._sessions.find((session) => { var _a; return ((_a = session.kernel) === null || _a === void 0 ? void 0 : _a.id) === (kernel === null || kernel === void 0 ? void 0 : kernel.id); });
|
|
106
|
-
if (session) {
|
|
107
|
-
patched.kernel = session.kernel;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
else if (kernel.name) {
|
|
111
|
-
const newKernel = await this._kernelClient.startNew({
|
|
112
|
-
id: UUID.uuid4(),
|
|
113
|
-
name: kernel.name,
|
|
114
|
-
location: PathExt.dirname(patched.path),
|
|
115
|
-
});
|
|
116
|
-
if (newKernel) {
|
|
117
|
-
patched.kernel = newKernel;
|
|
118
|
-
}
|
|
119
|
-
// clean up the session on kernel shutdown
|
|
120
|
-
void this._handleKernelShutdown({
|
|
121
|
-
kernelId: newKernel.id,
|
|
122
|
-
sessionId: session.id,
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
this._sessions[index] = patched;
|
|
127
|
-
return patched;
|
|
128
|
-
}
|
|
129
|
-
/**
|
|
130
|
-
* Start a new session
|
|
131
|
-
* TODO: read path and name
|
|
132
|
-
*
|
|
133
|
-
* @param options The options to start a new session.
|
|
134
|
-
*/
|
|
135
|
-
async startNew(options) {
|
|
136
|
-
var _a, _b, _c;
|
|
137
|
-
const { path, name } = options;
|
|
138
|
-
const running = this._sessions.find((s) => s.name === name);
|
|
139
|
-
if (running) {
|
|
140
|
-
return running;
|
|
141
|
-
}
|
|
142
|
-
const kernelName = (_b = (_a = options.kernel) === null || _a === void 0 ? void 0 : _a.name) !== null && _b !== void 0 ? _b : '';
|
|
143
|
-
const id = UUID.uuid4();
|
|
144
|
-
const nameOrPath = (_c = options.name) !== null && _c !== void 0 ? _c : options.path;
|
|
145
|
-
const dirname = PathExt.dirname(options.name) || PathExt.dirname(options.path);
|
|
146
|
-
const hasDrive = nameOrPath.includes(':');
|
|
147
|
-
const driveName = hasDrive ? nameOrPath.split(':')[0] : '';
|
|
148
|
-
// add drive name if missing (top level directory)
|
|
149
|
-
const location = dirname.includes(driveName) ? dirname : `${driveName}:${dirname}`;
|
|
150
|
-
const kernel = await this._kernelClient.startNew({
|
|
151
|
-
id,
|
|
152
|
-
name: kernelName,
|
|
153
|
-
location,
|
|
154
|
-
});
|
|
155
|
-
const session = {
|
|
156
|
-
id,
|
|
157
|
-
path,
|
|
158
|
-
name: name !== null && name !== void 0 ? name : path,
|
|
159
|
-
type: 'notebook',
|
|
160
|
-
kernel: {
|
|
161
|
-
id: kernel.id,
|
|
162
|
-
name: kernel.name,
|
|
163
|
-
},
|
|
164
|
-
};
|
|
165
|
-
this._sessions.push(session);
|
|
166
|
-
// clean up the session on kernel shutdown
|
|
167
|
-
void this._handleKernelShutdown({ kernelId: id, sessionId: session.id });
|
|
168
|
-
return session;
|
|
169
|
-
}
|
|
170
|
-
/**
|
|
171
|
-
* Shut down a session.
|
|
172
|
-
*
|
|
173
|
-
* @param id The id of the session to shut down.
|
|
174
|
-
*/
|
|
175
|
-
async shutdown(id) {
|
|
176
|
-
var _a;
|
|
177
|
-
const session = this._sessions.find((s) => s.id === id);
|
|
178
|
-
if (!session) {
|
|
179
|
-
throw Error(`Session ${id} not found`);
|
|
180
|
-
}
|
|
181
|
-
const kernelId = (_a = session.kernel) === null || _a === void 0 ? void 0 : _a.id;
|
|
182
|
-
if (kernelId) {
|
|
183
|
-
await this._kernelClient.shutdown(kernelId);
|
|
184
|
-
}
|
|
185
|
-
ArrayExt.removeFirstOf(this._sessions, session);
|
|
186
|
-
}
|
|
187
|
-
/**
|
|
188
|
-
* Shut down all sessions.
|
|
189
|
-
*/
|
|
190
|
-
async shutdownAll() {
|
|
191
|
-
await Promise.all(this._sessions.map((s) => this.shutdown(s.id)));
|
|
192
|
-
}
|
|
193
|
-
/**
|
|
194
|
-
* Handle kernel shutdown
|
|
195
|
-
*/
|
|
196
|
-
async _handleKernelShutdown({ kernelId, sessionId, }) {
|
|
197
|
-
// No need to handle kernel shutdown here anymore since we're using the changed signal
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
//# sourceMappingURL=client.js.map
|
package/lib/client.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAW,MAAM,sBAAsB,CAAC;AAEjE,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAIhD,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE7C,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAQzC;;GAEG;AACH,MAAM,OAAO,iBAAiB;IAC5B;;;;OAIG;IACH,YAAY,OAAmC;;QA2MvC,cAAS,GAAqB,EAAE,CAAC;QACjC,qBAAgB,GAAG,IAAI,GAAG,EAAU,CAAC;QA3M3C,IAAI,CAAC,aAAa,GAAG,OAAO,CAAC,YAAY,CAAC;QAC1C,IAAI,CAAC,eAAe,GAAG,MAAA,OAAO,CAAC,cAAc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upyterlab/coreutils';
|
|
4
|
-
|
|
5
|
-
import { LiteKernelClient } from '@jupyterlite/kernel';
|
|
6
|
-
|
|
7
|
-
import { ArrayExt } from '@lumino/algorithm';
|
|
8
|
-
|
|
9
|
-
import { UUID } from '@lumino/coreutils';
|
|
10
|
-
|
|
11
|
-
import { ISessionAPIClient } from '@jupyterlab/services/lib/session/session';
|
|
12
|
-
|
|
13
|
-
type DeepPartial<T> = {
|
|
14
|
-
[P in keyof T]?: DeepPartial<T[P]>;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* A class to handle requests to /api/sessions
|
|
19
|
-
*/
|
|
20
|
-
export class LiteSessionClient implements ISessionAPIClient {
|
|
21
|
-
/**
|
|
22
|
-
* Construct a new LiteSessionClient.
|
|
23
|
-
*
|
|
24
|
-
* @param options The instantiation options for a LiteSessionClient.
|
|
25
|
-
*/
|
|
26
|
-
constructor(options: LiteSessionClient.IOptions) {
|
|
27
|
-
this._kernelClient = options.kernelClient;
|
|
28
|
-
this._serverSettings = options.serverSettings ?? ServerConnection.makeSettings();
|
|
29
|
-
// Listen for kernel removals
|
|
30
|
-
this._kernelClient.changed.connect((_, args) => {
|
|
31
|
-
switch (args.type) {
|
|
32
|
-
case 'remove': {
|
|
33
|
-
const kernelId = args.oldValue?.id;
|
|
34
|
-
if (!kernelId) {
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
// find the session associated with the kernel
|
|
38
|
-
const session = this._sessions.find((s) => s.kernel?.id === kernelId);
|
|
39
|
-
if (!session) {
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
// Track the kernel ID for restart detection
|
|
43
|
-
this._pendingRestarts.add(kernelId);
|
|
44
|
-
setTimeout(async () => {
|
|
45
|
-
// If after a short delay the kernel hasn't been re-added, it was terminated
|
|
46
|
-
if (this._pendingRestarts.has(kernelId)) {
|
|
47
|
-
this._pendingRestarts.delete(kernelId);
|
|
48
|
-
await this.shutdown(session.id);
|
|
49
|
-
}
|
|
50
|
-
}, 100);
|
|
51
|
-
break;
|
|
52
|
-
}
|
|
53
|
-
case 'add': {
|
|
54
|
-
// If this was a restart, remove it from pending
|
|
55
|
-
const kernelId = args.newValue?.id;
|
|
56
|
-
if (!kernelId) {
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
this._pendingRestarts.delete(kernelId);
|
|
60
|
-
break;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* The server settings for the session client.
|
|
68
|
-
*/
|
|
69
|
-
get serverSettings(): ServerConnection.ISettings {
|
|
70
|
-
return this._serverSettings;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Get a session by id.
|
|
75
|
-
*
|
|
76
|
-
* @param id The id of the session.
|
|
77
|
-
*/
|
|
78
|
-
async getModel(id: string): Promise<Session.IModel> {
|
|
79
|
-
const session = this._sessions.find((s) => s.id === id);
|
|
80
|
-
if (!session) {
|
|
81
|
-
throw Error(`Session ${id} not found`);
|
|
82
|
-
}
|
|
83
|
-
return session;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* List the running sessions
|
|
88
|
-
*/
|
|
89
|
-
async listRunning(): Promise<Session.IModel[]> {
|
|
90
|
-
return this._sessions;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* Patch an existing session.
|
|
95
|
-
* This can be used to rename a session.
|
|
96
|
-
*
|
|
97
|
-
* - path updates session to track renamed paths
|
|
98
|
-
* - kernel.name starts a new kernel with a given kernelspec
|
|
99
|
-
*
|
|
100
|
-
* @param options The options to patch the session.
|
|
101
|
-
*/
|
|
102
|
-
async update(options: DeepPartial<Session.IModel>): Promise<Session.IModel> {
|
|
103
|
-
const { id, path, name, kernel } = options;
|
|
104
|
-
const index = this._sessions.findIndex((s) => s.id === id);
|
|
105
|
-
const session = this._sessions[index];
|
|
106
|
-
if (!session) {
|
|
107
|
-
throw Error(`Session ${id} not found`);
|
|
108
|
-
}
|
|
109
|
-
const patched = {
|
|
110
|
-
...session,
|
|
111
|
-
path: path ?? session.path,
|
|
112
|
-
name: name ?? session.name,
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
if (kernel) {
|
|
116
|
-
// Kernel id takes precedence over name.
|
|
117
|
-
if (kernel.id) {
|
|
118
|
-
const session = this._sessions.find(
|
|
119
|
-
(session) => session.kernel?.id === kernel?.id,
|
|
120
|
-
);
|
|
121
|
-
if (session) {
|
|
122
|
-
patched.kernel = session.kernel;
|
|
123
|
-
}
|
|
124
|
-
} else if (kernel.name) {
|
|
125
|
-
const newKernel = await this._kernelClient.startNew({
|
|
126
|
-
id: UUID.uuid4(),
|
|
127
|
-
name: kernel.name,
|
|
128
|
-
location: PathExt.dirname(patched.path),
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
if (newKernel) {
|
|
132
|
-
patched.kernel = newKernel;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
// clean up the session on kernel shutdown
|
|
136
|
-
void this._handleKernelShutdown({
|
|
137
|
-
kernelId: newKernel.id,
|
|
138
|
-
sessionId: session.id,
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
this._sessions[index] = patched;
|
|
144
|
-
return patched;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
/**
|
|
148
|
-
* Start a new session
|
|
149
|
-
* TODO: read path and name
|
|
150
|
-
*
|
|
151
|
-
* @param options The options to start a new session.
|
|
152
|
-
*/
|
|
153
|
-
async startNew(options: Session.ISessionOptions): Promise<Session.IModel> {
|
|
154
|
-
const { path, name } = options;
|
|
155
|
-
const running = this._sessions.find((s) => s.name === name);
|
|
156
|
-
if (running) {
|
|
157
|
-
return running;
|
|
158
|
-
}
|
|
159
|
-
const kernelName = options.kernel?.name ?? '';
|
|
160
|
-
const id = UUID.uuid4();
|
|
161
|
-
const nameOrPath = options.name ?? options.path;
|
|
162
|
-
const dirname = PathExt.dirname(options.name) || PathExt.dirname(options.path);
|
|
163
|
-
const hasDrive = nameOrPath.includes(':');
|
|
164
|
-
const driveName = hasDrive ? nameOrPath.split(':')[0] : '';
|
|
165
|
-
// add drive name if missing (top level directory)
|
|
166
|
-
const location = dirname.includes(driveName) ? dirname : `${driveName}:${dirname}`;
|
|
167
|
-
const kernel = await this._kernelClient.startNew({
|
|
168
|
-
id,
|
|
169
|
-
name: kernelName,
|
|
170
|
-
location,
|
|
171
|
-
});
|
|
172
|
-
const session: Session.IModel = {
|
|
173
|
-
id,
|
|
174
|
-
path,
|
|
175
|
-
name: name ?? path,
|
|
176
|
-
type: 'notebook',
|
|
177
|
-
kernel: {
|
|
178
|
-
id: kernel.id,
|
|
179
|
-
name: kernel.name,
|
|
180
|
-
},
|
|
181
|
-
};
|
|
182
|
-
this._sessions.push(session);
|
|
183
|
-
|
|
184
|
-
// clean up the session on kernel shutdown
|
|
185
|
-
void this._handleKernelShutdown({ kernelId: id, sessionId: session.id });
|
|
186
|
-
|
|
187
|
-
return session;
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
/**
|
|
191
|
-
* Shut down a session.
|
|
192
|
-
*
|
|
193
|
-
* @param id The id of the session to shut down.
|
|
194
|
-
*/
|
|
195
|
-
async shutdown(id: string): Promise<void> {
|
|
196
|
-
const session = this._sessions.find((s) => s.id === id);
|
|
197
|
-
if (!session) {
|
|
198
|
-
throw Error(`Session ${id} not found`);
|
|
199
|
-
}
|
|
200
|
-
const kernelId = session.kernel?.id;
|
|
201
|
-
if (kernelId) {
|
|
202
|
-
await this._kernelClient.shutdown(kernelId);
|
|
203
|
-
}
|
|
204
|
-
ArrayExt.removeFirstOf(this._sessions, session);
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
/**
|
|
208
|
-
* Shut down all sessions.
|
|
209
|
-
*/
|
|
210
|
-
async shutdownAll(): Promise<void> {
|
|
211
|
-
await Promise.all(this._sessions.map((s) => this.shutdown(s.id)));
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
/**
|
|
215
|
-
* Handle kernel shutdown
|
|
216
|
-
*/
|
|
217
|
-
private async _handleKernelShutdown({
|
|
218
|
-
kernelId,
|
|
219
|
-
sessionId,
|
|
220
|
-
}: {
|
|
221
|
-
kernelId: string;
|
|
222
|
-
sessionId: string;
|
|
223
|
-
}): Promise<void> {
|
|
224
|
-
// No need to handle kernel shutdown here anymore since we're using the changed signal
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
private _kernelClient: LiteKernelClient;
|
|
228
|
-
private _serverSettings: ServerConnection.ISettings;
|
|
229
|
-
private _sessions: Session.IModel[] = [];
|
|
230
|
-
private _pendingRestarts = new Set<string>();
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
/**
|
|
234
|
-
* A namespace for LiteSessionClient statics.
|
|
235
|
-
*/
|
|
236
|
-
export namespace LiteSessionClient {
|
|
237
|
-
/**
|
|
238
|
-
* The instantiation options for the session client.
|
|
239
|
-
*/
|
|
240
|
-
export interface IOptions {
|
|
241
|
-
/**
|
|
242
|
-
* A reference to the kernels service.
|
|
243
|
-
*/
|
|
244
|
-
kernelClient: LiteKernelClient;
|
|
245
|
-
|
|
246
|
-
/**
|
|
247
|
-
* Server settings for the session client.
|
|
248
|
-
*/
|
|
249
|
-
serverSettings?: ServerConnection.ISettings;
|
|
250
|
-
}
|
|
251
|
-
}
|