@jupyterlite/kernel 0.1.0-alpha.9 → 0.1.0-beta.10

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/kernel.d.ts CHANGED
@@ -31,6 +31,10 @@ export declare abstract class BaseKernel implements IKernel {
31
31
  * Get the name of the kernel
32
32
  */
33
33
  get name(): string;
34
+ /**
35
+ * The location in the virtual filesystem from which the kernel was started.
36
+ */
37
+ get location(): string;
34
38
  /**
35
39
  * The current execution count
36
40
  */
@@ -40,7 +44,7 @@ export declare abstract class BaseKernel implements IKernel {
40
44
  */
41
45
  get parentHeader(): KernelMessage.IHeader<KernelMessage.MessageType> | undefined;
42
46
  /**
43
- * Get the last parent message (mimick ipykernel's get_parent)
47
+ * Get the last parent message (mimic ipykernel's get_parent)
44
48
  */
45
49
  get parent(): KernelMessage.IMessage | undefined;
46
50
  /**
@@ -144,7 +148,7 @@ export declare abstract class BaseKernel implements IKernel {
144
148
  * Send an `execute_result` message.
145
149
  *
146
150
  * @param parentHeader The parent header.
147
- * @param content The execut result content.
151
+ * @param content The execute result content.
148
152
  */
149
153
  protected publishExecuteResult(content: KernelMessage.IExecuteResultMsg['content'], parentHeader?: KernelMessage.IHeader<KernelMessage.MessageType> | undefined): void;
150
154
  /**
@@ -230,6 +234,7 @@ export declare abstract class BaseKernel implements IKernel {
230
234
  private _isCompleteRequest;
231
235
  private _id;
232
236
  private _name;
237
+ private _location;
233
238
  private _history;
234
239
  private _executionCount;
235
240
  private _isDisposed;
package/lib/kernel.js CHANGED
@@ -16,9 +16,10 @@ export class BaseKernel {
16
16
  this._disposed = new Signal(this);
17
17
  this._parentHeader = undefined;
18
18
  this._parent = undefined;
19
- const { id, name, sendMessage } = options;
19
+ const { id, name, location, sendMessage } = options;
20
20
  this._id = id;
21
21
  this._name = name;
22
+ this._location = location;
22
23
  this._sendMessage = sendMessage;
23
24
  }
24
25
  /**
@@ -51,6 +52,12 @@ export class BaseKernel {
51
52
  get name() {
52
53
  return this._name;
53
54
  }
55
+ /**
56
+ * The location in the virtual filesystem from which the kernel was started.
57
+ */
58
+ get location() {
59
+ return this._location;
60
+ }
54
61
  /**
55
62
  * The current execution count
56
63
  */
@@ -64,7 +71,7 @@ export class BaseKernel {
64
71
  return this._parentHeader;
65
72
  }
66
73
  /**
67
- * Get the last parent message (mimick ipykernel's get_parent)
74
+ * Get the last parent message (mimic ipykernel's get_parent)
68
75
  */
69
76
  get parent() {
70
77
  return this._parent;
@@ -139,7 +146,7 @@ export class BaseKernel {
139
146
  // TODO: better handle this
140
147
  session: (_a = parentHeaderValue === null || parentHeaderValue === void 0 ? void 0 : parentHeaderValue.session) !== null && _a !== void 0 ? _a : '',
141
148
  parentHeader: parentHeaderValue,
142
- content
149
+ content,
143
150
  });
144
151
  this._sendMessage(message);
145
152
  }
@@ -160,7 +167,7 @@ export class BaseKernel {
160
167
  // TODO: better handle this
161
168
  session: (_b = parentHeaderValue === null || parentHeaderValue === void 0 ? void 0 : parentHeaderValue.session) !== null && _b !== void 0 ? _b : '',
162
169
  parentHeader: parentHeaderValue,
163
- content
170
+ content,
164
171
  });
165
172
  this._sendMessage(message);
166
173
  }
@@ -179,7 +186,7 @@ export class BaseKernel {
179
186
  // TODO: better handle this
180
187
  session: (_a = parentHeaderValue === null || parentHeaderValue === void 0 ? void 0 : parentHeaderValue.session) !== null && _a !== void 0 ? _a : '',
181
188
  parentHeader: parentHeaderValue,
182
- content
189
+ content,
183
190
  });
184
191
  this._sendMessage(message);
185
192
  }
@@ -187,7 +194,7 @@ export class BaseKernel {
187
194
  * Send an `execute_result` message.
188
195
  *
189
196
  * @param parentHeader The parent header.
190
- * @param content The execut result content.
197
+ * @param content The execute result content.
191
198
  */
192
199
  publishExecuteResult(content, parentHeader = undefined) {
193
200
  var _a;
@@ -198,7 +205,7 @@ export class BaseKernel {
198
205
  // TODO: better handle this
199
206
  session: (_a = parentHeaderValue === null || parentHeaderValue === void 0 ? void 0 : parentHeaderValue.session) !== null && _a !== void 0 ? _a : '',
200
207
  parentHeader: parentHeaderValue,
201
- content
208
+ content,
202
209
  });
203
210
  this._sendMessage(message);
204
211
  }
@@ -217,7 +224,7 @@ export class BaseKernel {
217
224
  // TODO: better handle this
218
225
  session: (_a = parentHeaderValue === null || parentHeaderValue === void 0 ? void 0 : parentHeaderValue.session) !== null && _a !== void 0 ? _a : '',
219
226
  parentHeader: parentHeaderValue,
220
- content
227
+ content,
221
228
  });
222
229
  this._sendMessage(message);
223
230
  }
@@ -236,7 +243,7 @@ export class BaseKernel {
236
243
  // TODO: better handle this
237
244
  session: (_a = parentHeaderValue === null || parentHeaderValue === void 0 ? void 0 : parentHeaderValue.session) !== null && _a !== void 0 ? _a : '',
238
245
  parentHeader: parentHeaderValue,
239
- content
246
+ content,
240
247
  });
241
248
  this._sendMessage(message);
242
249
  }
@@ -255,7 +262,7 @@ export class BaseKernel {
255
262
  // TODO: better handle this
256
263
  session: (_a = parentHeaderValue === null || parentHeaderValue === void 0 ? void 0 : parentHeaderValue.session) !== null && _a !== void 0 ? _a : '',
257
264
  parentHeader: parentHeaderValue,
258
- content
265
+ content,
259
266
  });
260
267
  this._sendMessage(message);
261
268
  }
@@ -275,7 +282,7 @@ export class BaseKernel {
275
282
  parentHeader: parentHeaderValue,
276
283
  content,
277
284
  metadata,
278
- buffers
285
+ buffers,
279
286
  });
280
287
  this._sendMessage(message);
281
288
  }
@@ -291,8 +298,8 @@ export class BaseKernel {
291
298
  parentHeader: parent.header,
292
299
  channel: 'iopub',
293
300
  content: {
294
- execution_state: 'idle'
295
- }
301
+ execution_state: 'idle',
302
+ },
296
303
  });
297
304
  this._sendMessage(message);
298
305
  }
@@ -308,8 +315,8 @@ export class BaseKernel {
308
315
  parentHeader: parent.header,
309
316
  channel: 'iopub',
310
317
  content: {
311
- execution_state: 'busy'
312
- }
318
+ execution_state: 'busy',
319
+ },
313
320
  });
314
321
  this._sendMessage(message);
315
322
  }
@@ -325,7 +332,7 @@ export class BaseKernel {
325
332
  channel: 'shell',
326
333
  session: parent.header.session,
327
334
  parentHeader: parent.header,
328
- content
335
+ content,
329
336
  });
330
337
  this._sendMessage(message);
331
338
  }
@@ -343,8 +350,8 @@ export class BaseKernel {
343
350
  session: msg.header.session,
344
351
  content: {
345
352
  status: 'ok',
346
- history: this._history
347
- }
353
+ history: this._history,
354
+ },
348
355
  });
349
356
  this._sendMessage(message);
350
357
  }
@@ -363,8 +370,8 @@ export class BaseKernel {
363
370
  session: msg.header.session,
364
371
  content: {
365
372
  code,
366
- execution_count: this._executionCount
367
- }
373
+ execution_count: this._executionCount,
374
+ },
368
375
  });
369
376
  this._sendMessage(message);
370
377
  }
@@ -376,18 +383,22 @@ export class BaseKernel {
376
383
  async _execute(msg) {
377
384
  const executeMsg = msg;
378
385
  const content = executeMsg.content;
379
- this._executionCount++;
386
+ if (content.store_history) {
387
+ this._executionCount++;
388
+ }
380
389
  // TODO: handle differently
381
390
  this._parentHeader = executeMsg.header;
382
391
  this._executeInput(executeMsg);
383
- this._history.push([0, 0, content.code]);
392
+ if (content.store_history) {
393
+ this._history.push([0, 0, content.code]);
394
+ }
384
395
  const reply = await this.executeRequest(executeMsg.content);
385
396
  const message = KernelMessage.createMessage({
386
397
  msgType: 'execute_reply',
387
398
  channel: 'shell',
388
399
  parentHeader: executeMsg.header,
389
400
  session: msg.header.session,
390
- content: reply
401
+ content: reply,
391
402
  });
392
403
  this._sendMessage(message);
393
404
  }
@@ -404,7 +415,7 @@ export class BaseKernel {
404
415
  parentHeader: completeMsg.header,
405
416
  channel: 'shell',
406
417
  session: msg.header.session,
407
- content
418
+ content,
408
419
  });
409
420
  this._sendMessage(message);
410
421
  }
@@ -421,7 +432,7 @@ export class BaseKernel {
421
432
  parentHeader: inspectMsg.header,
422
433
  channel: 'shell',
423
434
  session: msg.header.session,
424
- content
435
+ content,
425
436
  });
426
437
  this._sendMessage(message);
427
438
  }
@@ -438,7 +449,7 @@ export class BaseKernel {
438
449
  parentHeader: isCompleteMsg.header,
439
450
  channel: 'shell',
440
451
  session: msg.header.session,
441
- content
452
+ content,
442
453
  });
443
454
  this._sendMessage(message);
444
455
  }
package/lib/kernels.d.ts CHANGED
@@ -58,6 +58,10 @@ export declare namespace Kernels {
58
58
  * The kernel name.
59
59
  */
60
60
  name: string;
61
+ /**
62
+ * The location in the virtual filesystem from which the kernel was started.
63
+ */
64
+ location: string;
61
65
  }
62
66
  /**
63
67
  * The base url for the Kernels manager
package/lib/kernels.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { ObservableMap } from '@jupyterlab/observables';
2
2
  import { deserialize, serialize } from '@jupyterlab/services/lib/kernel/serialize';
3
3
  import { UUID } from '@lumino/coreutils';
4
- import { Server as WebSocketServer, WebSocket } from 'mock-socket';
4
+ import { Server as WebSocketServer } from 'mock-socket';
5
5
  import { Mutex } from 'async-mutex';
6
6
  import { PageConfig } from '@jupyterlab/coreutils';
7
7
  /**
@@ -26,7 +26,7 @@ export class Kernels {
26
26
  * @param options The kernel start options.
27
27
  */
28
28
  async startNew(options) {
29
- const { id, name } = options;
29
+ const { id, name, location } = options;
30
30
  const factory = this._kernelspecs.factories.get(name);
31
31
  // bail if there is no factory associated with the requested kernel
32
32
  if (!factory) {
@@ -89,7 +89,7 @@ export class Kernels {
89
89
  if (runningKernel) {
90
90
  return {
91
91
  id: runningKernel.id,
92
- name: runningKernel.name
92
+ name: runningKernel.name,
93
93
  };
94
94
  }
95
95
  // start the kernel
@@ -104,7 +104,7 @@ export class Kernels {
104
104
  // process iopub messages
105
105
  if (msg.channel === 'iopub') {
106
106
  const clients = this._kernelClients.get(kernelId);
107
- clients === null || clients === void 0 ? void 0 : clients.forEach(id => {
107
+ clients === null || clients === void 0 ? void 0 : clients.forEach((id) => {
108
108
  var _a;
109
109
  (_a = this._clients.get(id)) === null || _a === void 0 ? void 0 : _a.send(message);
110
110
  });
@@ -115,7 +115,8 @@ export class Kernels {
115
115
  const kernel = await factory({
116
116
  id: kernelId,
117
117
  sendMessage,
118
- name
118
+ name,
119
+ location,
119
120
  });
120
121
  await kernel.ready;
121
122
  this._kernels.set(kernelId, kernel);
@@ -130,7 +131,7 @@ export class Kernels {
130
131
  });
131
132
  // clean up closed connection
132
133
  wsServer.on('close', () => {
133
- this._clients.keys().forEach(clientId => {
134
+ this._clients.keys().forEach((clientId) => {
134
135
  var _a;
135
136
  const socket = this._clients.get(clientId);
136
137
  if ((socket === null || socket === void 0 ? void 0 : socket.readyState) === WebSocket.CLOSED) {
@@ -147,7 +148,7 @@ export class Kernels {
147
148
  });
148
149
  return {
149
150
  id: kernel.id,
150
- name: kernel.name
151
+ name: kernel.name,
151
152
  };
152
153
  }
153
154
  /**
@@ -160,9 +161,9 @@ export class Kernels {
160
161
  if (!kernel) {
161
162
  throw Error(`Kernel ${kernelId} does not exist`);
162
163
  }
163
- const { id, name } = kernel;
164
+ const { id, name, location } = kernel;
164
165
  kernel.dispose();
165
- return this.startNew({ id, name });
166
+ return this.startNew({ id, name, location });
166
167
  }
167
168
  /**
168
169
  * Shut down a kernel.
@@ -4,12 +4,6 @@ import { IKernel, IKernelSpecs } from './tokens';
4
4
  * A class to handle requests to /api/kernelspecs
5
5
  */
6
6
  export declare class KernelSpecs implements IKernelSpecs {
7
- /**
8
- * Construct a new KernelSpecs.
9
- *
10
- * @param options The instantiation options.
11
- */
12
- constructor(options: KernelSpecs.IOptions);
13
7
  /**
14
8
  * Get the kernel specs.
15
9
  */
@@ -31,11 +25,6 @@ export declare class KernelSpecs implements IKernelSpecs {
31
25
  * A namespace for KernelSpecs statics.
32
26
  */
33
27
  export declare namespace KernelSpecs {
34
- /**
35
- * The instantiation options for a KernelSpecs
36
- */
37
- interface IOptions {
38
- }
39
28
  /**
40
29
  * Registration options for a new kernel.
41
30
  */
@@ -2,15 +2,9 @@
2
2
  * A class to handle requests to /api/kernelspecs
3
3
  */
4
4
  export class KernelSpecs {
5
- /**
6
- * Construct a new KernelSpecs.
7
- *
8
- * @param options The instantiation options.
9
- */
10
- constructor(options) {
5
+ constructor() {
11
6
  this._specs = new Map();
12
7
  this._factories = new Map();
13
- // no-op
14
8
  }
15
9
  /**
16
10
  * Get the kernel specs.
@@ -21,7 +15,7 @@ export class KernelSpecs {
21
15
  }
22
16
  return {
23
17
  default: 'python',
24
- kernelspecs: Object.fromEntries(this._specs)
18
+ kernelspecs: Object.fromEntries(this._specs),
25
19
  };
26
20
  }
27
21
  /**
package/lib/tokens.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import type { Remote } from 'comlink';
1
2
  import { Kernel, KernelMessage, KernelSpec } from '@jupyterlab/services';
2
3
  import { Token } from '@lumino/coreutils';
3
4
  import { IObservableDisposable } from '@lumino/disposable';
@@ -42,6 +43,10 @@ export interface IKernel extends IObservableDisposable {
42
43
  * The name of the server-side kernel.
43
44
  */
44
45
  readonly name: string;
46
+ /**
47
+ * The location in the virtual filesystem from which the kernel was started.
48
+ */
49
+ readonly location: string;
45
50
  /**
46
51
  * A promise that is fulfilled when the kernel is ready.
47
52
  */
@@ -52,54 +57,6 @@ export interface IKernel extends IObservableDisposable {
52
57
  * @param msg The message to handle
53
58
  */
54
59
  handleMessage(msg: KernelMessage.IMessage): Promise<void>;
55
- /**
56
- * Handle a `kernel_info_request` message.
57
- *
58
- * @returns A promise that resolves with the kernel info.
59
- */
60
- kernelInfoRequest(): Promise<KernelMessage.IInfoReplyMsg['content']>;
61
- /**
62
- * Handle an `execute_request` message.
63
- *
64
- * @param content - The content of the execute_request kernel message
65
- */
66
- executeRequest(content: KernelMessage.IExecuteRequestMsg['content']): Promise<KernelMessage.IExecuteReplyMsg['content']>;
67
- /**
68
- * Handle a `complete_request` message.
69
- *
70
- * @param content - The content of the request.
71
- */
72
- completeRequest(content: KernelMessage.ICompleteRequestMsg['content']): Promise<KernelMessage.ICompleteReplyMsg['content']>;
73
- /**
74
- * Handle an `inspect_request` message.
75
- *
76
- * @param content - The content of the request.
77
- *
78
- * @returns A promise that resolves with the response message.
79
- */
80
- inspectRequest(content: KernelMessage.IInspectRequestMsg['content']): Promise<KernelMessage.IInspectReplyMsg['content']>;
81
- /**
82
- * Handle an `is_complete_request` message.
83
- *
84
- * @param content - The content of the request.
85
- *
86
- * @returns A promise that resolves with the response message.
87
- */
88
- isCompleteRequest(content: KernelMessage.IIsCompleteRequestMsg['content']): Promise<KernelMessage.IIsCompleteReplyMsg['content']>;
89
- /**
90
- * Handle a `comm_info_request` message.
91
- *
92
- * @param content - The content of the request.
93
- *
94
- * @returns A promise that resolves with the response message.
95
- */
96
- commInfoRequest(content: KernelMessage.ICommInfoRequestMsg['content']): Promise<KernelMessage.ICommInfoReplyMsg['content']>;
97
- /**
98
- * Send an `input_reply` message.
99
- *
100
- * @param content - The content of the reply.
101
- */
102
- inputReply(content: KernelMessage.IInputReplyMsg['content']): void;
103
60
  }
104
61
  /**
105
62
  * A namespace for IKernel statics.
@@ -121,6 +78,10 @@ export declare namespace IKernel {
121
78
  * The name of the kernel.
122
79
  */
123
80
  name: string;
81
+ /**
82
+ * The location in the virtual filesystem from which the kernel was started.
83
+ */
84
+ location: string;
124
85
  /**
125
86
  * The method to send messages back to the server.
126
87
  */
@@ -150,3 +111,34 @@ export interface IKernelSpecs {
150
111
  */
151
112
  register: (options: KernelSpecs.IKernelOptions) => void;
152
113
  }
114
+ /**
115
+ * An interface for a comlink-based worker kernel
116
+ */
117
+ export interface IWorkerKernel {
118
+ /**
119
+ * Handle any lazy setup activities.
120
+ */
121
+ initialize(options: IWorkerKernel.IOptions): Promise<void>;
122
+ execute(content: KernelMessage.IExecuteRequestMsg['content'], parent: any): Promise<KernelMessage.IExecuteReplyMsg['content']>;
123
+ complete(content: KernelMessage.ICompleteRequestMsg['content'], parent: any): Promise<KernelMessage.ICompleteReplyMsg['content']>;
124
+ inspect(content: KernelMessage.IInspectRequestMsg['content'], parent: any): Promise<KernelMessage.IInspectReplyMsg['content']>;
125
+ isComplete(content: KernelMessage.IIsCompleteRequestMsg['content'], parent: any): Promise<KernelMessage.IIsCompleteReplyMsg['content']>;
126
+ commInfo(content: KernelMessage.ICommInfoRequestMsg['content'], parent: any): Promise<KernelMessage.ICommInfoReplyMsg['content']>;
127
+ commOpen(content: KernelMessage.ICommOpenMsg, parent: any): Promise<void>;
128
+ commMsg(content: KernelMessage.ICommMsgMsg, parent: any): Promise<void>;
129
+ commClose(content: KernelMessage.ICommCloseMsg, parent: any): Promise<void>;
130
+ inputReply(content: KernelMessage.IInputReplyMsg['content'], parent: any): Promise<void>;
131
+ }
132
+ /**
133
+ * A namespace for worker kernels.
134
+ **/
135
+ export declare namespace IWorkerKernel {
136
+ /**
137
+ * Common values likely to be required by all kernels.
138
+ */
139
+ interface IOptions {
140
+ baseUrl: string;
141
+ }
142
+ }
143
+ export interface IRemoteKernel extends Remote<IWorkerKernel> {
144
+ }
package/lib/tokens.js CHANGED
@@ -1,3 +1,5 @@
1
+ // Copyright (c) Jupyter Development Team.
2
+ // Distributed under the terms of the Modified BSD License.
1
3
  import { Token } from '@lumino/coreutils';
2
4
  /**
3
5
  * The token for the kernels service.
@@ -6,4 +8,4 @@ export const IKernels = new Token('@jupyterlite/kernel:IKernels');
6
8
  /**
7
9
  * The token for the kernel spec service.
8
10
  */
9
- export const IKernelSpecs = new Token('@jupyterlite/kernelspec:IKernelSpecs');
11
+ export const IKernelSpecs = new Token('@jupyterlite/kernel:IKernelSpecs');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jupyterlite/kernel",
3
- "version": "0.1.0-alpha.9",
3
+ "version": "0.1.0-beta.10",
4
4
  "description": "JupyterLite - Kernel",
5
5
  "homepage": "https://github.com/jupyterlite/jupyterlite",
6
6
  "bugs": {
@@ -42,23 +42,24 @@
42
42
  "watch": "tsc -b --watch"
43
43
  },
44
44
  "dependencies": {
45
- "@jupyterlab/observables": "~4.1.12",
46
- "@jupyterlab/services": "~6.1.12",
47
- "@lumino/coreutils": "^1.8.0",
48
- "@lumino/disposable": "^1.7.0",
49
- "@lumino/signaling": "^1.7.0",
45
+ "@jupyterlab/observables": "~4.4.3",
46
+ "@jupyterlab/services": "~6.4.3",
47
+ "@lumino/coreutils": "^1.12.0",
48
+ "@lumino/disposable": "^1.10.1",
49
+ "@lumino/signaling": "^1.10.1",
50
50
  "async-mutex": "^0.3.1",
51
- "mock-socket": "^9.0.3"
51
+ "comlink": "^4.3.1",
52
+ "mock-socket": "^9.1.0"
52
53
  },
53
54
  "devDependencies": {
54
55
  "@babel/core": "^7.11.6",
55
56
  "@babel/preset-env": "^7.12.1",
56
- "@jupyterlab/testutils": "~3.1.12",
57
+ "@jupyterlab/testutils": "~3.4.3",
57
58
  "@types/jest": "^26.0.10",
58
59
  "jest": "^26.4.2",
59
60
  "rimraf": "~3.0.0",
60
61
  "ts-jest": "^26.3.0",
61
- "typescript": "~4.2.3"
62
+ "typescript": "~4.5.2"
62
63
  },
63
64
  "publishConfig": {
64
65
  "access": "public"