@difizen/libro-kernel 0.0.2-alpha.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/LICENSE +21 -0
- package/README.md +1 -0
- package/es/basemanager.d.ts +94 -0
- package/es/basemanager.d.ts.map +1 -0
- package/es/basemanager.js +110 -0
- package/es/contents/contents-drive.d.ts +189 -0
- package/es/contents/contents-drive.d.ts.map +1 -0
- package/es/contents/contents-drive.js +792 -0
- package/es/contents/contents-manager.d.ts +229 -0
- package/es/contents/contents-manager.d.ts.map +1 -0
- package/es/contents/contents-manager.js +551 -0
- package/es/contents/contents-module.d.ts +3 -0
- package/es/contents/contents-module.d.ts.map +1 -0
- package/es/contents/contents-module.js +4 -0
- package/es/contents/contents-protocol.d.ts +487 -0
- package/es/contents/contents-protocol.d.ts.map +1 -0
- package/es/contents/contents-protocol.js +1 -0
- package/es/contents/index.d.ts +6 -0
- package/es/contents/index.d.ts.map +1 -0
- package/es/contents/index.js +5 -0
- package/es/contents/validate.d.ts +10 -0
- package/es/contents/validate.d.ts.map +1 -0
- package/es/contents/validate.js +22 -0
- package/es/index.d.ts +10 -0
- package/es/index.d.ts.map +1 -0
- package/es/index.js +9 -0
- package/es/index.less +0 -0
- package/es/kernel/comm.d.ts +92 -0
- package/es/kernel/comm.d.ts.map +1 -0
- package/es/kernel/comm.js +216 -0
- package/es/kernel/future.d.ts +178 -0
- package/es/kernel/future.d.ts.map +1 -0
- package/es/kernel/future.js +587 -0
- package/es/kernel/index.d.ts +8 -0
- package/es/kernel/index.d.ts.map +1 -0
- package/es/kernel/index.js +8 -0
- package/es/kernel/kernel-connection.d.ts +550 -0
- package/es/kernel/kernel-connection.d.ts.map +1 -0
- package/es/kernel/kernel-connection.js +1957 -0
- package/es/kernel/kernel-module.d.ts +3 -0
- package/es/kernel/kernel-module.d.ts.map +1 -0
- package/es/kernel/kernel-module.js +32 -0
- package/es/kernel/libro-kernel-manager.d.ts +69 -0
- package/es/kernel/libro-kernel-manager.d.ts.map +1 -0
- package/es/kernel/libro-kernel-manager.js +349 -0
- package/es/kernel/libro-kernel-protocol.d.ts +675 -0
- package/es/kernel/libro-kernel-protocol.d.ts.map +1 -0
- package/es/kernel/libro-kernel-protocol.js +60 -0
- package/es/kernel/libro-kernel-utils.d.ts +95 -0
- package/es/kernel/libro-kernel-utils.d.ts.map +1 -0
- package/es/kernel/libro-kernel-utils.js +130 -0
- package/es/kernel/libro-kernel.d.ts +14 -0
- package/es/kernel/libro-kernel.d.ts.map +1 -0
- package/es/kernel/libro-kernel.js +54 -0
- package/es/kernel/messages.d.ts +845 -0
- package/es/kernel/messages.d.ts.map +1 -0
- package/es/kernel/messages.js +457 -0
- package/es/kernel/restapi.d.ts +78 -0
- package/es/kernel/restapi.d.ts.map +1 -0
- package/es/kernel/restapi.js +367 -0
- package/es/kernel/serialize.d.ts +10 -0
- package/es/kernel/serialize.d.ts.map +1 -0
- package/es/kernel/serialize.js +214 -0
- package/es/kernel/validate.d.ts +15 -0
- package/es/kernel/validate.d.ts.map +1 -0
- package/es/kernel/validate.js +125 -0
- package/es/kernelspec/index.d.ts +5 -0
- package/es/kernelspec/index.d.ts.map +1 -0
- package/es/kernelspec/index.js +4 -0
- package/es/kernelspec/kernelspec-module.d.ts +3 -0
- package/es/kernelspec/kernelspec-module.d.ts.map +1 -0
- package/es/kernelspec/kernelspec-module.js +4 -0
- package/es/kernelspec/kernelspec.d.ts +33 -0
- package/es/kernelspec/kernelspec.d.ts.map +1 -0
- package/es/kernelspec/kernelspec.js +1 -0
- package/es/kernelspec/manager.d.ts +81 -0
- package/es/kernelspec/manager.d.ts.map +1 -0
- package/es/kernelspec/manager.js +248 -0
- package/es/kernelspec/restapi.d.ts +71 -0
- package/es/kernelspec/restapi.d.ts.map +1 -0
- package/es/kernelspec/restapi.js +107 -0
- package/es/kernelspec/validate.d.ts +10 -0
- package/es/kernelspec/validate.d.ts.map +1 -0
- package/es/kernelspec/validate.js +69 -0
- package/es/libro-kernel-connection-manager.d.ts +19 -0
- package/es/libro-kernel-connection-manager.d.ts.map +1 -0
- package/es/libro-kernel-connection-manager.js +142 -0
- package/es/module.d.ts +3 -0
- package/es/module.d.ts.map +1 -0
- package/es/module.js +9 -0
- package/es/page-config.d.ts +36 -0
- package/es/page-config.d.ts.map +1 -0
- package/es/page-config.js +129 -0
- package/es/protocol.d.ts +13 -0
- package/es/protocol.d.ts.map +1 -0
- package/es/protocol.js +8 -0
- package/es/server/connection-error.d.ts +36 -0
- package/es/server/connection-error.d.ts.map +1 -0
- package/es/server/connection-error.js +109 -0
- package/es/server/index.d.ts +6 -0
- package/es/server/index.d.ts.map +1 -0
- package/es/server/index.js +5 -0
- package/es/server/server-connection-protocol.d.ts +49 -0
- package/es/server/server-connection-protocol.d.ts.map +1 -0
- package/es/server/server-connection-protocol.js +0 -0
- package/es/server/server-connection.d.ts +25 -0
- package/es/server/server-connection.d.ts.map +1 -0
- package/es/server/server-connection.js +159 -0
- package/es/server/server-manager.d.ts +22 -0
- package/es/server/server-manager.d.ts.map +1 -0
- package/es/server/server-manager.js +163 -0
- package/es/server/server-module.d.ts +3 -0
- package/es/server/server-module.d.ts.map +1 -0
- package/es/server/server-module.js +4 -0
- package/es/session/index.d.ts +5 -0
- package/es/session/index.d.ts.map +1 -0
- package/es/session/index.js +4 -0
- package/es/session/libro-session-manager.d.ts +71 -0
- package/es/session/libro-session-manager.d.ts.map +1 -0
- package/es/session/libro-session-manager.js +539 -0
- package/es/session/libro-session-protocol.d.ts +50 -0
- package/es/session/libro-session-protocol.d.ts.map +1 -0
- package/es/session/libro-session-protocol.js +21 -0
- package/es/session/libro-session.d.ts +12 -0
- package/es/session/libro-session.d.ts.map +1 -0
- package/es/session/libro-session.js +19 -0
- package/es/session/restapi.d.ts +28 -0
- package/es/session/restapi.d.ts.map +1 -0
- package/es/session/restapi.js +214 -0
- package/es/session/session-module.d.ts +3 -0
- package/es/session/session-module.d.ts.map +1 -0
- package/es/session/session-module.js +18 -0
- package/es/session/validate.d.ts +14 -0
- package/es/session/validate.d.ts.map +1 -0
- package/es/session/validate.js +37 -0
- package/es/utils.d.ts +4 -0
- package/es/utils.d.ts.map +1 -0
- package/es/utils.js +29 -0
- package/es/validate-property.d.ts +2 -0
- package/es/validate-property.d.ts.map +1 -0
- package/es/validate-property.js +35 -0
- package/package.json +62 -0
- package/src/basemanager.ts +133 -0
- package/src/contents/contents-drive.ts +495 -0
- package/src/contents/contents-manager.ts +465 -0
- package/src/contents/contents-module.ts +6 -0
- package/src/contents/contents-protocol.ts +604 -0
- package/src/contents/index.ts +5 -0
- package/src/contents/validate.ts +29 -0
- package/src/index.tsx +9 -0
- package/src/kernel/comm.ts +220 -0
- package/src/kernel/future.ts +474 -0
- package/src/kernel/index.ts +7 -0
- package/src/kernel/kernel-connection.ts +1770 -0
- package/src/kernel/kernel-module.ts +50 -0
- package/src/kernel/libro-kernel-manager.ts +199 -0
- package/src/kernel/libro-kernel-protocol.ts +858 -0
- package/src/kernel/libro-kernel-utils.ts +152 -0
- package/src/kernel/libro-kernel.ts +39 -0
- package/src/kernel/messages.ts +1104 -0
- package/src/kernel/restapi.ts +183 -0
- package/src/kernel/serialize.ts +262 -0
- package/src/kernel/validate.ts +101 -0
- package/src/kernelspec/index.ts +5 -0
- package/src/kernelspec/kernelspec-module.ts +9 -0
- package/src/kernelspec/kernelspec.ts +37 -0
- package/src/kernelspec/manager.ts +173 -0
- package/src/kernelspec/restapi.ts +104 -0
- package/src/kernelspec/validate.ts +80 -0
- package/src/libro-kernel-connection-manager.ts +73 -0
- package/src/module.ts +19 -0
- package/src/page-config.ts +106 -0
- package/src/protocol.ts +24 -0
- package/src/server/connection-error.ts +60 -0
- package/src/server/index.ts +5 -0
- package/src/server/server-connection-protocol.ts +57 -0
- package/src/server/server-connection.ts +144 -0
- package/src/server/server-manager.ts +76 -0
- package/src/server/server-module.ts +9 -0
- package/src/session/index.ts +4 -0
- package/src/session/libro-session-manager.ts +377 -0
- package/src/session/libro-session-protocol.ts +61 -0
- package/src/session/libro-session.ts +33 -0
- package/src/session/restapi.ts +126 -0
- package/src/session/session-module.ts +26 -0
- package/src/session/validate.ts +39 -0
- package/src/utils.ts +28 -0
- package/src/validate-property.ts +38 -0
|
@@ -0,0 +1,858 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-namespace */
|
|
2
|
+
import type { JSONObject } from '@difizen/libro-common';
|
|
3
|
+
import type { Event, Disposable } from '@difizen/mana-app';
|
|
4
|
+
|
|
5
|
+
import type { ISpecModel } from '../kernelspec/index.js';
|
|
6
|
+
import type { ISettings } from '../server/index.js';
|
|
7
|
+
|
|
8
|
+
import type { LibroKernel } from './libro-kernel.js';
|
|
9
|
+
import type * as KernelMessage from './messages.js';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* A disposable object with an observable `disposed` signal.
|
|
13
|
+
*/
|
|
14
|
+
export interface ObservableDisposable extends Disposable {
|
|
15
|
+
/**
|
|
16
|
+
* A signal emitted when the object is disposed.
|
|
17
|
+
*/
|
|
18
|
+
readonly onDisposed: Event<void>;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export type KernelStatus =
|
|
22
|
+
| 'unknown'
|
|
23
|
+
| 'starting'
|
|
24
|
+
| 'idle'
|
|
25
|
+
| 'busy'
|
|
26
|
+
| 'terminating'
|
|
27
|
+
| 'restarting'
|
|
28
|
+
| 'autorestarting'
|
|
29
|
+
| 'dead';
|
|
30
|
+
|
|
31
|
+
export interface KernelMeta {
|
|
32
|
+
id: KernelId;
|
|
33
|
+
name: string;
|
|
34
|
+
last_activity: string;
|
|
35
|
+
execution_state: KernelStatus;
|
|
36
|
+
connections: number;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export const KernelMetaOption = Symbol('KernelMetaOption');
|
|
40
|
+
|
|
41
|
+
export const KernelId = Symbol('LibroKernelId');
|
|
42
|
+
export type KernelId = string;
|
|
43
|
+
|
|
44
|
+
export const LibroKernelFactory = Symbol('LibroKernelFactory');
|
|
45
|
+
export type LibroKernelFactory = (kernel: KernelMeta) => LibroKernel;
|
|
46
|
+
|
|
47
|
+
export const LibroKernelConnectionFactory = Symbol('LibroKernelConnectionFactory');
|
|
48
|
+
export type LibroKernelConnectionFactory = (
|
|
49
|
+
option: KernelConnectionOptions,
|
|
50
|
+
) => IKernelConnection;
|
|
51
|
+
|
|
52
|
+
export type ConnectionStatus = 'connected' | 'connecting' | 'disconnected';
|
|
53
|
+
|
|
54
|
+
export class KernelError extends Error {
|
|
55
|
+
/**
|
|
56
|
+
* Exception name
|
|
57
|
+
*/
|
|
58
|
+
readonly errorName: string;
|
|
59
|
+
/**
|
|
60
|
+
* Exception value
|
|
61
|
+
*/
|
|
62
|
+
readonly errorValue: string;
|
|
63
|
+
/**
|
|
64
|
+
* Traceback
|
|
65
|
+
*/
|
|
66
|
+
readonly traceback: string[];
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Construct the kernel error.
|
|
70
|
+
*/
|
|
71
|
+
constructor(content: KernelMessage.IExecuteReplyMsg['content']) {
|
|
72
|
+
const errorContent = content as KernelMessage.IReplyErrorContent;
|
|
73
|
+
const errorName = errorContent.ename;
|
|
74
|
+
const errorValue = errorContent.evalue;
|
|
75
|
+
super(`KernelReplyNotOK: ${errorName} ${errorValue}`);
|
|
76
|
+
|
|
77
|
+
this.errorName = errorName;
|
|
78
|
+
this.errorValue = errorValue;
|
|
79
|
+
this.traceback = errorContent.traceback;
|
|
80
|
+
Object.setPrototypeOf(this, KernelError.prototype);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export interface IFuture<
|
|
85
|
+
REQUEST extends KernelMessage.IShellControlMessage,
|
|
86
|
+
REPLY extends KernelMessage.IShellControlMessage,
|
|
87
|
+
> extends Disposable {
|
|
88
|
+
/**
|
|
89
|
+
* The original outgoing message.
|
|
90
|
+
*/
|
|
91
|
+
readonly msg: REQUEST;
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* A promise that resolves when the future is done.
|
|
95
|
+
*
|
|
96
|
+
* #### Notes
|
|
97
|
+
* The future is done when there are no more responses expected from the
|
|
98
|
+
* kernel.
|
|
99
|
+
*
|
|
100
|
+
* The `done` promise resolves to the reply message.
|
|
101
|
+
*/
|
|
102
|
+
readonly done: Promise<REPLY>;
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* The reply handler for the kernel future.
|
|
106
|
+
*
|
|
107
|
+
* #### Notes
|
|
108
|
+
* If the handler returns a promise, all kernel message processing pauses
|
|
109
|
+
* until the promise is resolved. If there is a reply message, the future
|
|
110
|
+
* `done` promise also resolves to the reply message after this handler has
|
|
111
|
+
* been called.
|
|
112
|
+
*/
|
|
113
|
+
onReply: (msg: REPLY) => void | PromiseLike<void>;
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* The iopub handler for the kernel future.
|
|
117
|
+
*
|
|
118
|
+
* #### Notes
|
|
119
|
+
* If the handler returns a promise, all kernel message processing pauses
|
|
120
|
+
* until the promise is resolved.
|
|
121
|
+
*/
|
|
122
|
+
onIOPub: (msg: KernelMessage.IIOPubMessage) => void | PromiseLike<void>;
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* The stdin handler for the kernel future.
|
|
126
|
+
*
|
|
127
|
+
* #### Notes
|
|
128
|
+
* If the handler returns a promise, all kernel message processing pauses
|
|
129
|
+
* until the promise is resolved.
|
|
130
|
+
*/
|
|
131
|
+
onStdin: (msg: KernelMessage.IStdinMessage) => void | PromiseLike<void>;
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Register hook for IOPub messages.
|
|
135
|
+
*
|
|
136
|
+
* @param hook - The callback invoked for an IOPub message.
|
|
137
|
+
*
|
|
138
|
+
* #### Notes
|
|
139
|
+
* The IOPub hook system allows you to preempt the handlers for IOPub
|
|
140
|
+
* messages handled by the future.
|
|
141
|
+
*
|
|
142
|
+
* The most recently registered hook is run first. A hook can return a
|
|
143
|
+
* boolean or a promise to a boolean, in which case all kernel message
|
|
144
|
+
* processing pauses until the promise is fulfilled. If a hook return value
|
|
145
|
+
* resolves to false, any later hooks will not run and the function will
|
|
146
|
+
* return a promise resolving to false. If a hook throws an error, the error
|
|
147
|
+
* is logged to the console and the next hook is run. If a hook is
|
|
148
|
+
* registered during the hook processing, it will not run until the next
|
|
149
|
+
* message. If a hook is removed during the hook processing, it will be
|
|
150
|
+
* deactivated immediately.
|
|
151
|
+
*/
|
|
152
|
+
registerMessageHook: (
|
|
153
|
+
hook: (msg: KernelMessage.IIOPubMessage) => boolean | PromiseLike<boolean>,
|
|
154
|
+
) => void;
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Remove a hook for IOPub messages.
|
|
158
|
+
*
|
|
159
|
+
* @param hook - The hook to remove.
|
|
160
|
+
*
|
|
161
|
+
* #### Notes
|
|
162
|
+
* If a hook is removed during the hook processing, it will be deactivated immediately.
|
|
163
|
+
*/
|
|
164
|
+
removeMessageHook: (
|
|
165
|
+
hook: (msg: KernelMessage.IIOPubMessage) => boolean | PromiseLike<boolean>,
|
|
166
|
+
) => void;
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Send an `input_reply` message.
|
|
170
|
+
*/
|
|
171
|
+
sendInputReply: (
|
|
172
|
+
content: KernelMessage.IInputReplyMsg['content'],
|
|
173
|
+
parent_header: KernelMessage.IInputReplyMsg['parent_header'],
|
|
174
|
+
) => void;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
export type IShellFuture<
|
|
178
|
+
REQUEST extends KernelMessage.IShellMessage = KernelMessage.IShellMessage,
|
|
179
|
+
REPLY extends KernelMessage.IShellMessage = KernelMessage.IShellMessage,
|
|
180
|
+
> = IFuture<REQUEST, REPLY>;
|
|
181
|
+
|
|
182
|
+
export type IControlFuture<
|
|
183
|
+
REQUEST extends KernelMessage.IControlMessage = KernelMessage.IControlMessage,
|
|
184
|
+
REPLY extends KernelMessage.IControlMessage = KernelMessage.IControlMessage,
|
|
185
|
+
> = IFuture<REQUEST, REPLY>;
|
|
186
|
+
|
|
187
|
+
export interface IComm extends Disposable {
|
|
188
|
+
/**
|
|
189
|
+
* The unique id for the comm channel.
|
|
190
|
+
*/
|
|
191
|
+
readonly commId: string;
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* The target name for the comm channel.
|
|
195
|
+
*/
|
|
196
|
+
readonly targetName: string;
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Callback for a comm close event.
|
|
200
|
+
*
|
|
201
|
+
* #### Notes
|
|
202
|
+
* This is called when the comm is closed from either the server or client.
|
|
203
|
+
* If this is called in response to a kernel message and the handler returns
|
|
204
|
+
* a promise, all kernel message processing pauses until the promise is
|
|
205
|
+
* resolved.
|
|
206
|
+
*/
|
|
207
|
+
onClose: (msg: KernelMessage.ICommCloseMsg) => void | PromiseLike<void>;
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Callback for a comm message received event.
|
|
211
|
+
*
|
|
212
|
+
* #### Notes
|
|
213
|
+
* If the handler returns a promise, all kernel message processing pauses
|
|
214
|
+
* until the promise is resolved.
|
|
215
|
+
*/
|
|
216
|
+
onMsg: (msg: KernelMessage.ICommMsgMsg) => void | PromiseLike<void>;
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Open a comm with optional data and metadata.
|
|
220
|
+
*
|
|
221
|
+
* @param data - The data to send to the server on opening.
|
|
222
|
+
*
|
|
223
|
+
* @param metadata - Additional metadata for the message.
|
|
224
|
+
*
|
|
225
|
+
* @returns A future for the generated message.
|
|
226
|
+
*
|
|
227
|
+
* #### Notes
|
|
228
|
+
* This sends a `comm_open` message to the server.
|
|
229
|
+
*/
|
|
230
|
+
open: (
|
|
231
|
+
data?: JSONObject,
|
|
232
|
+
metadata?: JSONObject,
|
|
233
|
+
buffers?: (ArrayBuffer | ArrayBufferView)[],
|
|
234
|
+
) => IShellFuture;
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Send a `comm_msg` message to the kernel.
|
|
238
|
+
*
|
|
239
|
+
* @param data - The data to send to the server on opening.
|
|
240
|
+
*
|
|
241
|
+
* @param metadata - Additional metadata for the message.
|
|
242
|
+
*
|
|
243
|
+
* @param buffers - Optional buffer data.
|
|
244
|
+
*
|
|
245
|
+
* @param disposeOnDone - Whether to dispose of the future when done.
|
|
246
|
+
*
|
|
247
|
+
* @returns A future for the generated message.
|
|
248
|
+
*
|
|
249
|
+
* #### Notes
|
|
250
|
+
* This is a no-op if the comm has been closed.
|
|
251
|
+
*/
|
|
252
|
+
send: (
|
|
253
|
+
data: JSONObject,
|
|
254
|
+
metadata?: JSONObject,
|
|
255
|
+
buffers?: (ArrayBuffer | ArrayBufferView)[],
|
|
256
|
+
disposeOnDone?: boolean,
|
|
257
|
+
) => IShellFuture;
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* Close the comm.
|
|
261
|
+
*
|
|
262
|
+
* @param data - The data to send to the server on opening.
|
|
263
|
+
*
|
|
264
|
+
* @param metadata - Additional metadata for the message.
|
|
265
|
+
*
|
|
266
|
+
* @returns A future for the generated message.
|
|
267
|
+
*
|
|
268
|
+
* #### Notes
|
|
269
|
+
* This will send a `comm_close` message to the kernel, and call the
|
|
270
|
+
* `onClose` callback if set.
|
|
271
|
+
*
|
|
272
|
+
* This is a no-op if the comm is already closed.
|
|
273
|
+
*/
|
|
274
|
+
close: (
|
|
275
|
+
data?: JSONObject,
|
|
276
|
+
metadata?: JSONObject,
|
|
277
|
+
buffers?: (ArrayBuffer | ArrayBufferView)[],
|
|
278
|
+
) => IShellFuture;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
export interface IAnyMessageArgs {
|
|
282
|
+
/**
|
|
283
|
+
* The message that is being signaled.
|
|
284
|
+
*/
|
|
285
|
+
msg: Readonly<KernelMessage.IMessage>;
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* The direction of the message.
|
|
289
|
+
*/
|
|
290
|
+
direction: 'send' | 'recv';
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
export interface IKernelModel {
|
|
294
|
+
/**
|
|
295
|
+
* Unique identifier of the kernel on the server.
|
|
296
|
+
*/
|
|
297
|
+
readonly id: string;
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* The name of the kernel.
|
|
301
|
+
*/
|
|
302
|
+
readonly name: string;
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* The kernel execution state.
|
|
306
|
+
*/
|
|
307
|
+
readonly execution_state?: string;
|
|
308
|
+
|
|
309
|
+
/**
|
|
310
|
+
* The timestamp of the last activity on the kernel.
|
|
311
|
+
*/
|
|
312
|
+
// eslint-disable-next-line camelcase
|
|
313
|
+
readonly last_activity?: string;
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* The number of active connections to the kernel.
|
|
317
|
+
*/
|
|
318
|
+
readonly connections?: number;
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* The reason the kernel died, if applicable.
|
|
322
|
+
*/
|
|
323
|
+
readonly reason?: string;
|
|
324
|
+
|
|
325
|
+
/**
|
|
326
|
+
* The traceback for a dead kernel, if applicable.
|
|
327
|
+
*/
|
|
328
|
+
readonly traceback?: string;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
export interface IKernelConnection extends ObservableDisposable {
|
|
332
|
+
/**
|
|
333
|
+
* The id of the server-side kernel.
|
|
334
|
+
*/
|
|
335
|
+
readonly id: string;
|
|
336
|
+
|
|
337
|
+
/**
|
|
338
|
+
* The name of the server-side kernel.
|
|
339
|
+
*/
|
|
340
|
+
readonly name: string;
|
|
341
|
+
|
|
342
|
+
/**
|
|
343
|
+
* The kernel model, for convenience.
|
|
344
|
+
*/
|
|
345
|
+
readonly model: IKernelModel;
|
|
346
|
+
|
|
347
|
+
/**
|
|
348
|
+
* The client username.
|
|
349
|
+
*/
|
|
350
|
+
readonly username: string;
|
|
351
|
+
|
|
352
|
+
/**
|
|
353
|
+
* The client unique id.
|
|
354
|
+
*
|
|
355
|
+
* #### Notes
|
|
356
|
+
* This should be unique for a particular kernel connection object.
|
|
357
|
+
*/
|
|
358
|
+
readonly clientId: string;
|
|
359
|
+
|
|
360
|
+
/**
|
|
361
|
+
* The current status of the kernel.
|
|
362
|
+
*/
|
|
363
|
+
readonly status: KernelMessage.Status;
|
|
364
|
+
|
|
365
|
+
/**
|
|
366
|
+
* The current connection status of the kernel.
|
|
367
|
+
*/
|
|
368
|
+
readonly connectionStatus: ConnectionStatus;
|
|
369
|
+
|
|
370
|
+
readonly isDisposed: boolean;
|
|
371
|
+
|
|
372
|
+
/**
|
|
373
|
+
* The kernel info
|
|
374
|
+
*
|
|
375
|
+
* #### Notes
|
|
376
|
+
* This promise only resolves at startup, and is not refreshed on every
|
|
377
|
+
* restart.
|
|
378
|
+
*/
|
|
379
|
+
readonly info: Promise<KernelMessage.IInfoReply>;
|
|
380
|
+
|
|
381
|
+
/**
|
|
382
|
+
* Get the kernel spec.
|
|
383
|
+
*
|
|
384
|
+
* @returns A promise that resolves with the kernel spec for this kernel.
|
|
385
|
+
*
|
|
386
|
+
* #### Notes
|
|
387
|
+
* This may make a server request to retrieve the spec.
|
|
388
|
+
*/
|
|
389
|
+
readonly spec?: Promise<ISpecModel | undefined>;
|
|
390
|
+
|
|
391
|
+
/**
|
|
392
|
+
* Whether the kernel connection handles comm messages.
|
|
393
|
+
*
|
|
394
|
+
* #### Notes
|
|
395
|
+
* The comm message protocol currently has implicit assumptions that only
|
|
396
|
+
* one kernel connection is handling comm messages. This option allows a
|
|
397
|
+
* kernel connection to opt out of handling comms.
|
|
398
|
+
*
|
|
399
|
+
* See https://github.com/jupyter/jupyter_client/issues/263
|
|
400
|
+
*/
|
|
401
|
+
handleComms: boolean;
|
|
402
|
+
|
|
403
|
+
/**
|
|
404
|
+
* Whether the kernel connection has pending input.
|
|
405
|
+
*
|
|
406
|
+
* #### Notes
|
|
407
|
+
* This is a guard to avoid deadlock is the user asks input
|
|
408
|
+
* as second time before submitting his first input
|
|
409
|
+
*/
|
|
410
|
+
hasPendingInput: boolean;
|
|
411
|
+
|
|
412
|
+
/**
|
|
413
|
+
* Send a shell message to the kernel.
|
|
414
|
+
*
|
|
415
|
+
* @param msg - The fully-formed shell message to send.
|
|
416
|
+
*
|
|
417
|
+
* @param expectReply - Whether to expect a shell reply message.
|
|
418
|
+
*
|
|
419
|
+
* @param disposeOnDone - Whether to dispose of the future when done.
|
|
420
|
+
*
|
|
421
|
+
* #### Notes
|
|
422
|
+
* Send a message to the kernel's shell channel, yielding a future object
|
|
423
|
+
* for accepting replies.
|
|
424
|
+
*
|
|
425
|
+
* If `expectReply` is given and `true`, the future is done when both a
|
|
426
|
+
* shell reply and an idle status message are received with the appropriate
|
|
427
|
+
* parent header, in which case the `.done` promise resolves to the reply.
|
|
428
|
+
* If `expectReply` is not given or is `false`, the future is done when an
|
|
429
|
+
* idle status message with the appropriate parent header is received, in
|
|
430
|
+
* which case the `.done` promise resolves to `undefined`.
|
|
431
|
+
*
|
|
432
|
+
* If `disposeOnDone` is given and `false`, the future will not be disposed
|
|
433
|
+
* of when the future is done, instead relying on the caller to dispose of
|
|
434
|
+
* it. This allows for the handling of out-of-order output from ill-behaved
|
|
435
|
+
* kernels.
|
|
436
|
+
*
|
|
437
|
+
* All replies are validated as valid kernel messages.
|
|
438
|
+
*
|
|
439
|
+
* If the kernel status is `'dead'`, this will throw an error.
|
|
440
|
+
*/
|
|
441
|
+
sendShellMessage: <T extends KernelMessage.ShellMessageType>(
|
|
442
|
+
msg: KernelMessage.IShellMessage<T>,
|
|
443
|
+
expectReply?: boolean,
|
|
444
|
+
disposeOnDone?: boolean,
|
|
445
|
+
) => IShellFuture<KernelMessage.IShellMessage<T>>;
|
|
446
|
+
|
|
447
|
+
sendControlMessage: <T extends KernelMessage.ControlMessageType>(
|
|
448
|
+
msg: KernelMessage.IControlMessage<T>,
|
|
449
|
+
expectReply?: boolean,
|
|
450
|
+
disposeOnDone?: boolean,
|
|
451
|
+
) => IControlFuture<KernelMessage.IControlMessage<T>>;
|
|
452
|
+
|
|
453
|
+
/**
|
|
454
|
+
* Reconnect to a disconnected kernel.
|
|
455
|
+
*
|
|
456
|
+
* @returns A promise that resolves when the kernel has reconnected.
|
|
457
|
+
*
|
|
458
|
+
* #### Notes
|
|
459
|
+
* This just refreshes the connection to an existing kernel, and does not
|
|
460
|
+
* perform an HTTP request to the server or restart the kernel.
|
|
461
|
+
*/
|
|
462
|
+
reconnect: () => Promise<void>;
|
|
463
|
+
|
|
464
|
+
/**
|
|
465
|
+
* Interrupt a kernel.
|
|
466
|
+
*
|
|
467
|
+
* @returns A promise that resolves when the kernel has interrupted.
|
|
468
|
+
*
|
|
469
|
+
* #### Notes
|
|
470
|
+
* Uses the [Jupyter Notebook API](http://petstore.swagger.io/?url=https://raw.githubusercontent.com/jupyter/notebook/master/notebook/services/api/api.yaml#!/kernels).
|
|
471
|
+
*
|
|
472
|
+
* The promise is fulfilled on a valid response and rejected otherwise.
|
|
473
|
+
*
|
|
474
|
+
* It is assumed that the API call does not mutate the kernel id or name.
|
|
475
|
+
*
|
|
476
|
+
* The promise will be rejected if the kernel status is `'dead'` or if the
|
|
477
|
+
* request fails or the response is invalid.
|
|
478
|
+
*/
|
|
479
|
+
interrupt: () => Promise<void>;
|
|
480
|
+
|
|
481
|
+
/**
|
|
482
|
+
* Restart a kernel.
|
|
483
|
+
*
|
|
484
|
+
* @returns A promise that resolves when the kernel has restarted.
|
|
485
|
+
*
|
|
486
|
+
* #### Notes
|
|
487
|
+
* Uses the [Jupyter Notebook API](http://petstore.swagger.io/?url=https://raw.githubusercontent.com/jupyter/notebook/master/notebook/services/api/api.yaml#!/kernels) and validates the response model.
|
|
488
|
+
*
|
|
489
|
+
* Any existing Future or Comm objects are cleared.
|
|
490
|
+
*
|
|
491
|
+
* It is assumed that the API call does not mutate the kernel id or name.
|
|
492
|
+
*
|
|
493
|
+
* The promise will be rejected if the kernel status is `'dead'` or if the
|
|
494
|
+
* request fails or the response is invalid.
|
|
495
|
+
*/
|
|
496
|
+
restart: () => Promise<void>;
|
|
497
|
+
|
|
498
|
+
/**
|
|
499
|
+
* Send a `kernel_info_request` message.
|
|
500
|
+
*
|
|
501
|
+
* @param content - The content of the request.
|
|
502
|
+
*
|
|
503
|
+
* @returns A promise that resolves with the response message.
|
|
504
|
+
*
|
|
505
|
+
* #### Notes
|
|
506
|
+
* See [Messaging in Jupyter](https://jupyter-client.readthedocs.io/en/latest/messaging.html#kernel-info).
|
|
507
|
+
*
|
|
508
|
+
* Fulfills with the `kernel_info_response` content when the shell reply is
|
|
509
|
+
* received and validated.
|
|
510
|
+
*/
|
|
511
|
+
requestKernelInfo?: () => Promise<KernelMessage.IInfoReplyMsg | undefined>;
|
|
512
|
+
|
|
513
|
+
/**
|
|
514
|
+
* Send a `complete_request` message.
|
|
515
|
+
*
|
|
516
|
+
* @param content - The content of the request.
|
|
517
|
+
*
|
|
518
|
+
* @returns A promise that resolves with the response message.
|
|
519
|
+
*
|
|
520
|
+
* #### Notes
|
|
521
|
+
* See [Messaging in Jupyter](https://jupyter-client.readthedocs.io/en/latest/messaging.html#completion).
|
|
522
|
+
*
|
|
523
|
+
* Fulfills with the `complete_reply` content when the shell reply is
|
|
524
|
+
* received and validated.
|
|
525
|
+
*/
|
|
526
|
+
requestComplete: (
|
|
527
|
+
content: KernelMessage.ICompleteRequestMsg['content'],
|
|
528
|
+
) => Promise<KernelMessage.ICompleteReplyMsg>;
|
|
529
|
+
|
|
530
|
+
/**
|
|
531
|
+
* Send an `inspect_request` message.
|
|
532
|
+
*
|
|
533
|
+
* @param content - The content of the request.
|
|
534
|
+
*
|
|
535
|
+
* @returns A promise that resolves with the response message.
|
|
536
|
+
*
|
|
537
|
+
* #### Notes
|
|
538
|
+
* See [Messaging in Jupyter](https://jupyter-client.readthedocs.io/en/latest/messaging.html#introspection).
|
|
539
|
+
*
|
|
540
|
+
* Fulfills with the `inspect_reply` content when the shell reply is
|
|
541
|
+
* received and validated.
|
|
542
|
+
*/
|
|
543
|
+
requestInspect: (
|
|
544
|
+
content: KernelMessage.IInspectRequestMsg['content'],
|
|
545
|
+
) => Promise<KernelMessage.IInspectReplyMsg>;
|
|
546
|
+
|
|
547
|
+
/**
|
|
548
|
+
* Send a `history_request` message.
|
|
549
|
+
*
|
|
550
|
+
* @param content - The content of the request.
|
|
551
|
+
*
|
|
552
|
+
* @returns A promise that resolves with the response message.
|
|
553
|
+
*
|
|
554
|
+
* #### Notes
|
|
555
|
+
* See [Messaging in Jupyter](https://jupyter-client.readthedocs.io/en/latest/messaging.html#history).
|
|
556
|
+
*
|
|
557
|
+
* Fulfills with the `history_reply` content when the shell reply is
|
|
558
|
+
* received and validated.
|
|
559
|
+
*/
|
|
560
|
+
requestHistory: (
|
|
561
|
+
content: KernelMessage.IHistoryRequestMsg['content'],
|
|
562
|
+
) => Promise<KernelMessage.IHistoryReplyMsg>;
|
|
563
|
+
|
|
564
|
+
/**
|
|
565
|
+
* Send an `execute_request` message.
|
|
566
|
+
*
|
|
567
|
+
* @param content - The content of the request.
|
|
568
|
+
*
|
|
569
|
+
* @param disposeOnDone - Whether to dispose of the future when done.
|
|
570
|
+
*
|
|
571
|
+
* @returns A kernel future.
|
|
572
|
+
*
|
|
573
|
+
* #### Notes
|
|
574
|
+
* See [Messaging in
|
|
575
|
+
* Jupyter](https://jupyter-client.readthedocs.io/en/latest/messaging.html#execute).
|
|
576
|
+
*
|
|
577
|
+
* This method returns a kernel future, rather than a promise, since execution may
|
|
578
|
+
* have many response messages (for example, many iopub display messages).
|
|
579
|
+
*
|
|
580
|
+
* Future `onReply` is called with the `execute_reply` content when the
|
|
581
|
+
* shell reply is received and validated.
|
|
582
|
+
*
|
|
583
|
+
* **See also:** [[IExecuteReply]]
|
|
584
|
+
*/
|
|
585
|
+
requestExecute: (
|
|
586
|
+
content: KernelMessage.IExecuteRequestMsg['content'],
|
|
587
|
+
disposeOnDone?: boolean,
|
|
588
|
+
metadata?: JSONObject,
|
|
589
|
+
) => IShellFuture<KernelMessage.IExecuteRequestMsg, KernelMessage.IExecuteReplyMsg>;
|
|
590
|
+
|
|
591
|
+
/**
|
|
592
|
+
* Send an experimental `debug_request` message.
|
|
593
|
+
*
|
|
594
|
+
* @hidden
|
|
595
|
+
*
|
|
596
|
+
* @param content - The content of the request.
|
|
597
|
+
*
|
|
598
|
+
* @param disposeOnDone - Whether to dispose of the future when done.
|
|
599
|
+
*
|
|
600
|
+
* @returns A kernel future.
|
|
601
|
+
*
|
|
602
|
+
* #### Notes
|
|
603
|
+
* Debug messages are experimental messages that are not in the official
|
|
604
|
+
* kernel message specification. As such, this function is *NOT* considered
|
|
605
|
+
* part of the public API, and may change without notice.
|
|
606
|
+
*/
|
|
607
|
+
requestDebug: (
|
|
608
|
+
content: KernelMessage.IDebugRequestMsg['content'],
|
|
609
|
+
disposeOnDone?: boolean,
|
|
610
|
+
) => IControlFuture<KernelMessage.IDebugRequestMsg, KernelMessage.IDebugReplyMsg>;
|
|
611
|
+
|
|
612
|
+
/**
|
|
613
|
+
* Send an `is_complete_request` message.
|
|
614
|
+
*
|
|
615
|
+
* @param content - The content of the request.
|
|
616
|
+
*
|
|
617
|
+
* @returns A promise that resolves with the response message.
|
|
618
|
+
*
|
|
619
|
+
* #### Notes
|
|
620
|
+
* See [Messaging in Jupyter](https://jupyter-client.readthedocs.io/en/latest/messaging.html#code-completeness).
|
|
621
|
+
*
|
|
622
|
+
* Fulfills with the `is_complete_response` content when the shell reply is
|
|
623
|
+
* received and validated.
|
|
624
|
+
*/
|
|
625
|
+
requestIsComplete: (
|
|
626
|
+
content: KernelMessage.IIsCompleteRequestMsg['content'],
|
|
627
|
+
) => Promise<KernelMessage.IIsCompleteReplyMsg>;
|
|
628
|
+
|
|
629
|
+
/**
|
|
630
|
+
* Send a `comm_info_request` message.
|
|
631
|
+
*
|
|
632
|
+
* @param content - The content of the request.
|
|
633
|
+
*
|
|
634
|
+
* @returns A promise that resolves with the response message.
|
|
635
|
+
*
|
|
636
|
+
* #### Notes
|
|
637
|
+
* See [Messaging in Jupyter](https://jupyter-client.readthedocs.io/en/latest/messaging.html#comm_info).
|
|
638
|
+
*
|
|
639
|
+
* Fulfills with the `comm_info_reply` content when the shell reply is
|
|
640
|
+
* received and validated.
|
|
641
|
+
*/
|
|
642
|
+
requestCommInfo: (
|
|
643
|
+
content: KernelMessage.ICommInfoRequestMsg['content'],
|
|
644
|
+
) => Promise<KernelMessage.ICommInfoReplyMsg>;
|
|
645
|
+
|
|
646
|
+
/**
|
|
647
|
+
* Send an `input_reply` message.
|
|
648
|
+
*
|
|
649
|
+
* @param content - The content of the reply.
|
|
650
|
+
*
|
|
651
|
+
* #### Notes
|
|
652
|
+
* See [Messaging in Jupyter](https://jupyter-client.readthedocs.io/en/latest/messaging.html#messages-on-the-stdin-router-dealer-sockets).
|
|
653
|
+
*/
|
|
654
|
+
sendInputReply: (
|
|
655
|
+
content: KernelMessage.IInputReplyMsg['content'],
|
|
656
|
+
parent_header: KernelMessage.IInputReplyMsg['parent_header'],
|
|
657
|
+
) => void;
|
|
658
|
+
|
|
659
|
+
/**
|
|
660
|
+
* Create a new comm.
|
|
661
|
+
*
|
|
662
|
+
* @param targetName - The name of the comm target.
|
|
663
|
+
*
|
|
664
|
+
* @param id - The comm id.
|
|
665
|
+
*
|
|
666
|
+
* @returns A comm instance.
|
|
667
|
+
*/
|
|
668
|
+
createComm: (targetName: string, commId?: string) => IComm;
|
|
669
|
+
|
|
670
|
+
/**
|
|
671
|
+
* Check if a comm exists.
|
|
672
|
+
*/
|
|
673
|
+
hasComm: (commId: string) => boolean;
|
|
674
|
+
|
|
675
|
+
/**
|
|
676
|
+
* Register a comm target handler.
|
|
677
|
+
*
|
|
678
|
+
* @param targetName - The name of the comm target.
|
|
679
|
+
*
|
|
680
|
+
* @param callback - The callback invoked for a comm open message.
|
|
681
|
+
*
|
|
682
|
+
* #### Notes
|
|
683
|
+
* Only one comm target can be registered to a target name at a time, an
|
|
684
|
+
* existing callback for the same target name will be overridden. A registered
|
|
685
|
+
* comm target handler will take precedence over a comm which specifies a
|
|
686
|
+
* `target_module`.
|
|
687
|
+
*
|
|
688
|
+
* If the callback returns a promise, kernel message processing will pause
|
|
689
|
+
* until the returned promise is fulfilled.
|
|
690
|
+
*/
|
|
691
|
+
registerCommTarget: (
|
|
692
|
+
targetName: string,
|
|
693
|
+
callback: (
|
|
694
|
+
comm: IComm,
|
|
695
|
+
msg: KernelMessage.ICommOpenMsg,
|
|
696
|
+
) => void | PromiseLike<void>,
|
|
697
|
+
) => void;
|
|
698
|
+
|
|
699
|
+
/**
|
|
700
|
+
* Remove a comm target handler.
|
|
701
|
+
*
|
|
702
|
+
* @param targetName - The name of the comm target to remove.
|
|
703
|
+
*
|
|
704
|
+
* @param callback - The callback to remove.
|
|
705
|
+
*
|
|
706
|
+
* #### Notes
|
|
707
|
+
* The comm target is only removed if it matches the callback argument.
|
|
708
|
+
*/
|
|
709
|
+
removeCommTarget: (
|
|
710
|
+
targetName: string,
|
|
711
|
+
callback: (
|
|
712
|
+
comm: IComm,
|
|
713
|
+
msg: KernelMessage.ICommOpenMsg,
|
|
714
|
+
) => void | PromiseLike<void>,
|
|
715
|
+
) => void;
|
|
716
|
+
|
|
717
|
+
/**
|
|
718
|
+
* Register an IOPub message hook.
|
|
719
|
+
*
|
|
720
|
+
* @param msg_id - The parent_header message id in messages the hook should
|
|
721
|
+
* intercept.
|
|
722
|
+
*
|
|
723
|
+
* @param hook - The callback invoked for the message.
|
|
724
|
+
*
|
|
725
|
+
* #### Notes
|
|
726
|
+
* The IOPub hook system allows you to preempt the handlers for IOPub
|
|
727
|
+
* messages with a given parent_header message id. The most recently
|
|
728
|
+
* registered hook is run first. If a hook return value resolves to false,
|
|
729
|
+
* any later hooks and the future's onIOPub handler will not run. If a hook
|
|
730
|
+
* throws an error, the error is logged to the console and the next hook is
|
|
731
|
+
* run. If a hook is registered during the hook processing, it will not run
|
|
732
|
+
* until the next message. If a hook is disposed during the hook processing,
|
|
733
|
+
* it will be deactivated immediately.
|
|
734
|
+
*
|
|
735
|
+
* See also [[IFuture.registerMessageHook]].
|
|
736
|
+
*/
|
|
737
|
+
registerMessageHook: (
|
|
738
|
+
msgId: string,
|
|
739
|
+
hook: (msg: KernelMessage.IIOPubMessage) => boolean | PromiseLike<boolean>,
|
|
740
|
+
) => void;
|
|
741
|
+
|
|
742
|
+
/**
|
|
743
|
+
* Remove an IOPub message hook.
|
|
744
|
+
*
|
|
745
|
+
* @param msg_id - The parent_header message id the hook intercepted.
|
|
746
|
+
*
|
|
747
|
+
* @param hook - The callback invoked for the message.
|
|
748
|
+
*
|
|
749
|
+
*/
|
|
750
|
+
removeMessageHook: (
|
|
751
|
+
msgId: string,
|
|
752
|
+
hook: (msg: KernelMessage.IIOPubMessage) => boolean | PromiseLike<boolean>,
|
|
753
|
+
) => void;
|
|
754
|
+
|
|
755
|
+
/**
|
|
756
|
+
* Remove the input guard, if any.
|
|
757
|
+
*/
|
|
758
|
+
removeInputGuard: () => void;
|
|
759
|
+
|
|
760
|
+
/**
|
|
761
|
+
* A signal emitted when the kernel status changes.
|
|
762
|
+
*/
|
|
763
|
+
statusChanged: Event<KernelMessage.Status>;
|
|
764
|
+
|
|
765
|
+
/**
|
|
766
|
+
* A signal emitted when the kernel connection status changes.
|
|
767
|
+
*/
|
|
768
|
+
connectionStatusChanged: Event<ConnectionStatus>;
|
|
769
|
+
|
|
770
|
+
/**
|
|
771
|
+
* A signal emitted after an iopub kernel message is handled.
|
|
772
|
+
*/
|
|
773
|
+
iopubMessage: Event<KernelMessage.IIOPubMessage>;
|
|
774
|
+
|
|
775
|
+
/**
|
|
776
|
+
* A signal emitted for unhandled non-iopub kernel messages that claimed to
|
|
777
|
+
* be responses for messages we sent using this kernel object.
|
|
778
|
+
*/
|
|
779
|
+
unhandledMessage: Event<KernelMessage.IMessage>;
|
|
780
|
+
|
|
781
|
+
/**
|
|
782
|
+
* A signal emitted when any kernel message is sent or received.
|
|
783
|
+
*
|
|
784
|
+
* #### Notes
|
|
785
|
+
* This signal is emitted before any message handling has happened. The
|
|
786
|
+
* message should be treated as read-only.
|
|
787
|
+
*/
|
|
788
|
+
anyMessage: Event<IAnyMessageArgs>;
|
|
789
|
+
|
|
790
|
+
/**
|
|
791
|
+
* A signal emitted when a kernel has pending inputs from the user.
|
|
792
|
+
*/
|
|
793
|
+
pendingInput: Event<boolean>;
|
|
794
|
+
|
|
795
|
+
/**
|
|
796
|
+
* The server settings for the kernel.
|
|
797
|
+
*/
|
|
798
|
+
readonly serverSettings: ISettings;
|
|
799
|
+
|
|
800
|
+
/**
|
|
801
|
+
* Shutdown a kernel.
|
|
802
|
+
*
|
|
803
|
+
* @returns A promise that resolves when the kernel has shut down.
|
|
804
|
+
*
|
|
805
|
+
* #### Notes
|
|
806
|
+
* Uses the [Jupyter Notebook
|
|
807
|
+
* API](http://petstore.swagger.io/?url=https://raw.githubusercontent.com/jupyter/notebook/master/notebook/services/api/api.yaml#!/kernels).
|
|
808
|
+
*
|
|
809
|
+
* On a valid response, closes the websocket, disposes of the kernel
|
|
810
|
+
* object, and fulfills the promise.
|
|
811
|
+
*
|
|
812
|
+
* The promise will be rejected if the kernel status is `'dead'`, the
|
|
813
|
+
* request fails, or the response is invalid.
|
|
814
|
+
*/
|
|
815
|
+
shutdown: () => Promise<void>;
|
|
816
|
+
|
|
817
|
+
/**
|
|
818
|
+
* Clone the current kernel with a new clientId.
|
|
819
|
+
*/
|
|
820
|
+
clone: (
|
|
821
|
+
options?: Pick<KernelConnectionOptions, 'clientId' | 'username' | 'handleComms'>,
|
|
822
|
+
) => IKernelConnection;
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
export const KernelConnectionOptions = Symbol('IOptions');
|
|
826
|
+
export interface KernelConnectionOptions {
|
|
827
|
+
/**
|
|
828
|
+
* The kernel model.
|
|
829
|
+
*/
|
|
830
|
+
model: IKernelModel;
|
|
831
|
+
|
|
832
|
+
/**
|
|
833
|
+
* The server settings for the kernel.
|
|
834
|
+
*/
|
|
835
|
+
serverSettings?: Partial<ISettings>;
|
|
836
|
+
|
|
837
|
+
/**
|
|
838
|
+
* The username of the kernel client.
|
|
839
|
+
*/
|
|
840
|
+
username?: string;
|
|
841
|
+
|
|
842
|
+
/**
|
|
843
|
+
* Whether the kernel connection should handle comm messages
|
|
844
|
+
*
|
|
845
|
+
* #### Notes
|
|
846
|
+
* The comm message protocol currently has implicit assumptions that only
|
|
847
|
+
* one kernel connection is handling comm messages. This option allows a
|
|
848
|
+
* kernel connection to opt out of handling comms.
|
|
849
|
+
*
|
|
850
|
+
* See https://github.com/jupyter/jupyter_client/issues/263
|
|
851
|
+
*/
|
|
852
|
+
handleComms?: boolean;
|
|
853
|
+
|
|
854
|
+
/**
|
|
855
|
+
* The unique identifier for the kernel client.
|
|
856
|
+
*/
|
|
857
|
+
clientId?: string;
|
|
858
|
+
}
|