1 | import { IChangedArgs } from '@jupyterlab/coreutils';
|
2 | import { Kernel, KernelMessage, KernelSpec, Session } from '@jupyterlab/services';
|
3 | import { ITranslator } from '@jupyterlab/translation';
|
4 | import { IterableOrArrayLike } from '@lumino/algorithm';
|
5 | import { IDisposable, IObservableDisposable } from '@lumino/disposable';
|
6 | import { ISignal } from '@lumino/signaling';
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 | export interface ISessionContext extends IObservableDisposable {
|
20 | |
21 |
|
22 |
|
23 | session: Session.ISessionConnection | null;
|
24 | |
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 | initialize(): Promise<boolean>;
|
33 | |
34 |
|
35 |
|
36 | readonly isReady: boolean;
|
37 | |
38 |
|
39 |
|
40 | readonly isTerminating: boolean;
|
41 | |
42 |
|
43 |
|
44 | readonly isRestarting: boolean;
|
45 | |
46 |
|
47 |
|
48 | readonly ready: Promise<void>;
|
49 | |
50 |
|
51 |
|
52 | readonly sessionChanged: ISignal<this, IChangedArgs<Session.ISessionConnection | null, Session.ISessionConnection | null, 'session'>>;
|
53 | |
54 |
|
55 |
|
56 | readonly kernelChanged: ISignal<this, IChangedArgs<Kernel.IKernelConnection | null, Kernel.IKernelConnection | null, 'kernel'>>;
|
57 | |
58 |
|
59 |
|
60 | readonly statusChanged: ISignal<this, Kernel.Status>;
|
61 | |
62 |
|
63 |
|
64 | readonly connectionStatusChanged: ISignal<this, Kernel.ConnectionStatus>;
|
65 | |
66 |
|
67 |
|
68 | readonly pendingInput: boolean;
|
69 | |
70 |
|
71 |
|
72 | readonly iopubMessage: ISignal<this, KernelMessage.IMessage>;
|
73 | |
74 |
|
75 |
|
76 | readonly unhandledMessage: ISignal<this, KernelMessage.IMessage>;
|
77 | |
78 |
|
79 |
|
80 | readonly propertyChanged: ISignal<this, 'path' | 'name' | 'type'>;
|
81 | |
82 |
|
83 |
|
84 | kernelPreference: ISessionContext.IKernelPreference;
|
85 | |
86 |
|
87 |
|
88 |
|
89 |
|
90 |
|
91 | readonly hasNoKernel: boolean;
|
92 | |
93 |
|
94 |
|
95 |
|
96 |
|
97 |
|
98 |
|
99 | readonly kernelDisplayName: string;
|
100 | |
101 |
|
102 |
|
103 |
|
104 |
|
105 |
|
106 | readonly kernelDisplayStatus: ISessionContext.KernelDisplayStatus;
|
107 | |
108 |
|
109 |
|
110 |
|
111 |
|
112 |
|
113 |
|
114 | readonly path: string;
|
115 | |
116 |
|
117 |
|
118 |
|
119 |
|
120 |
|
121 |
|
122 | readonly type: string;
|
123 | |
124 |
|
125 |
|
126 |
|
127 |
|
128 |
|
129 |
|
130 | readonly name: string;
|
131 | |
132 |
|
133 |
|
134 | readonly prevKernelName: string;
|
135 | |
136 |
|
137 |
|
138 | readonly sessionManager: Session.IManager;
|
139 | |
140 |
|
141 |
|
142 | readonly specsManager: KernelSpec.IManager;
|
143 | |
144 |
|
145 |
|
146 |
|
147 |
|
148 | restartKernel(): Promise<void>;
|
149 | |
150 |
|
151 |
|
152 |
|
153 |
|
154 | shutdown(): Promise<void>;
|
155 | |
156 |
|
157 |
|
158 |
|
159 |
|
160 |
|
161 |
|
162 | changeKernel(options?: Partial<Kernel.IModel>): Promise<Kernel.IKernelConnection | null>;
|
163 | }
|
164 |
|
165 |
|
166 |
|
167 | export declare namespace ISessionContext {
|
168 | |
169 |
|
170 |
|
171 |
|
172 |
|
173 |
|
174 |
|
175 |
|
176 | interface IKernelPreference {
|
177 | |
178 |
|
179 |
|
180 | readonly name?: string;
|
181 | |
182 |
|
183 |
|
184 | readonly language?: string;
|
185 | |
186 |
|
187 |
|
188 | readonly id?: string;
|
189 | |
190 |
|
191 |
|
192 | readonly shouldStart?: boolean;
|
193 | |
194 |
|
195 |
|
196 | readonly canStart?: boolean;
|
197 | |
198 |
|
199 |
|
200 | readonly shutdownOnDispose?: boolean;
|
201 | |
202 |
|
203 |
|
204 |
|
205 | readonly autoStartDefault?: boolean;
|
206 | }
|
207 | type KernelDisplayStatus = Kernel.Status | Kernel.ConnectionStatus | 'initializing' | '';
|
208 | |
209 |
|
210 |
|
211 | interface IDialogs {
|
212 | |
213 |
|
214 |
|
215 | selectKernel(session: ISessionContext, translator?: ITranslator): Promise<void>;
|
216 | |
217 |
|
218 |
|
219 |
|
220 |
|
221 |
|
222 |
|
223 |
|
224 |
|
225 |
|
226 |
|
227 | restart(session: ISessionContext, translator?: ITranslator): Promise<boolean>;
|
228 | }
|
229 | }
|
230 |
|
231 |
|
232 |
|
233 | export declare class SessionContext implements ISessionContext {
|
234 | |
235 |
|
236 |
|
237 | constructor(options: SessionContext.IOptions);
|
238 | /**
|
239 | * The current session connection.
|
240 | */
|
241 | get session(): Session.ISessionConnection | null;
|
242 | /**
|
243 | * The session path.
|
244 | *
|
245 | * #### Notes
|
246 | * Typically `.session.path` should be used. This attribute is useful if
|
247 | * there is no current session.
|
248 | */
|
249 | get path(): string;
|
250 | /**
|
251 | * The session type.
|
252 | *
|
253 | * #### Notes
|
254 | * Typically `.session.type` should be used. This attribute is useful if
|
255 | * there is no current session.
|
256 | */
|
257 | get type(): string;
|
258 | /**
|
259 | * The session name.
|
260 | *
|
261 | * #### Notes
|
262 | * Typically `.session.name` should be used. This attribute is useful if
|
263 | * there is no current session.
|
264 | */
|
265 | get name(): string;
|
266 | /**
|
267 | * A signal emitted when the kernel connection changes, proxied from the session connection.
|
268 | */
|
269 | get kernelChanged(): ISignal<this, Session.ISessionConnection.IKernelChangedArgs>;
|
270 | /**
|
271 | * A signal emitted when the session connection changes.
|
272 | */
|
273 | get sessionChanged(): ISignal<this, IChangedArgs<Session.ISessionConnection | null, Session.ISessionConnection | null, 'session'>>;
|
274 | /**
|
275 | * A signal emitted when the kernel status changes, proxied from the kernel.
|
276 | */
|
277 | get statusChanged(): ISignal<this, Kernel.Status>;
|
278 | /**
|
279 | * A flag indicating if the session has ending input, proxied from the kernel.
|
280 | */
|
281 | get pendingInput(): boolean;
|
282 | /**
|
283 | * A signal emitted when the kernel status changes, proxied from the kernel.
|
284 | */
|
285 | get connectionStatusChanged(): ISignal<this, Kernel.ConnectionStatus>;
|
286 | /**
|
287 | * A signal emitted for iopub kernel messages, proxied from the kernel.
|
288 | */
|
289 | get iopubMessage(): ISignal<this, KernelMessage.IIOPubMessage>;
|
290 | /**
|
291 | * A signal emitted for an unhandled kernel message, proxied from the kernel.
|
292 | */
|
293 | get unhandledMessage(): ISignal<this, KernelMessage.IMessage>;
|
294 | /**
|
295 | * A signal emitted when a session property changes, proxied from the current session.
|
296 | */
|
297 | get propertyChanged(): ISignal<this, 'path' | 'name' | 'type'>;
|
298 | /**
|
299 | * The kernel preference of this client session.
|
300 | *
|
301 | * This is used when selecting a new kernel, and should reflect the sort of
|
302 | * kernel the activity prefers.
|
303 | */
|
304 | get kernelPreference(): ISessionContext.IKernelPreference;
|
305 | set kernelPreference(value: ISessionContext.IKernelPreference);
|
306 | /**
|
307 | * Whether the context is ready.
|
308 | */
|
309 | get isReady(): boolean;
|
310 | /**
|
311 | * A promise that is fulfilled when the context is ready.
|
312 | */
|
313 | get ready(): Promise<void>;
|
314 | /**
|
315 | * Whether the context is terminating.
|
316 | */
|
317 | get isTerminating(): boolean;
|
318 | /**
|
319 | * Whether the context is restarting.
|
320 | */
|
321 | get isRestarting(): boolean;
|
322 | /**
|
323 | * The session manager used by the session.
|
324 | */
|
325 | readonly sessionManager: Session.IManager;
|
326 | /**
|
327 | * The kernel spec manager
|
328 | */
|
329 | readonly specsManager: KernelSpec.IManager;
|
330 | /**
|
331 | * Whether the kernel is "No Kernel" or not.
|
332 | *
|
333 | * #### Notes
|
334 | * As the displayed name is translated, this can be used directly.
|
335 | */
|
336 | get hasNoKernel(): boolean;
|
337 | /**
|
338 | * The display name of the current kernel, or a sensible alternative.
|
339 | *
|
340 | * #### Notes
|
341 | * This is a convenience function to have a consistent sensible name for the
|
342 | * kernel.
|
343 | */
|
344 | get kernelDisplayName(): string;
|
345 | /**
|
346 | * A sensible status to display
|
347 | *
|
348 | * #### Notes
|
349 | * This combines the status and connection status into a single status for
|
350 | * the user.
|
351 | */
|
352 | get kernelDisplayStatus(): ISessionContext.KernelDisplayStatus;
|
353 | /**
|
354 | * The name of the previously started kernel.
|
355 | */
|
356 | get prevKernelName(): string;
|
357 | /**
|
358 | * Test whether the context is disposed.
|
359 | */
|
360 | get isDisposed(): boolean;
|
361 | /**
|
362 | * A signal emitted when the poll is disposed.
|
363 | */
|
364 | get disposed(): ISignal<this, void>;
|
365 | /**
|
366 | * Get the constant displayed name for "No Kernel"
|
367 | */
|
368 | protected get noKernelName(): string;
|
369 | /**
|
370 | * Dispose of the resources held by the context.
|
371 | */
|
372 | dispose(): void;
|
373 | /**
|
374 | * Restart the current Kernel.
|
375 | *
|
376 | * @returns A promise that resolves when the kernel is restarted.
|
377 | */
|
378 | restartKernel(): Promise<void>;
|
379 | /**
|
380 | * Change the current kernel associated with the session.
|
381 | */
|
382 | changeKernel(options?: Partial<Kernel.IModel>): Promise<Kernel.IKernelConnection | null>;
|
383 | /**
|
384 | * Kill the kernel and shutdown the session.
|
385 | *
|
386 | * @returns A promise that resolves when the session is shut down.
|
387 | */
|
388 | shutdown(): Promise<void>;
|
389 | /**
|
390 | * Initialize the session context
|
391 | *
|
392 | * @returns A promise that resolves with whether to ask the user to select a kernel.
|
393 | *
|
394 | * #### Notes
|
395 | * If a server session exists on the current path, we will connect to it.
|
396 | * If preferences include disabling `canStart` or `shouldStart`, no
|
397 | * server session will be started.
|
398 | * If a kernel id is given, we attempt to start a session with that id.
|
399 | * If a default kernel is available, we connect to it.
|
400 | * Otherwise we ask the user to select a kernel.
|
401 | */
|
402 | initialize(): Promise<boolean>;
|
403 | /**
|
404 | * Inner initialize function that doesn't handle promises.
|
405 | * This makes it easier to consolidate promise handling logic.
|
406 | */
|
407 | _initialize(): Promise<boolean>;
|
408 | /**
|
409 | * Shut down the current session.
|
410 | */
|
411 | private _shutdownSession;
|
412 | /**
|
413 | * Start the session if necessary.
|
414 | *
|
415 | * @returns Whether to ask the user to pick a kernel.
|
416 | */
|
417 | private _startIfNecessary;
|
418 | /**
|
419 | * Change the kernel.
|
420 | */
|
421 | private _changeKernel;
|
422 | /**
|
423 | * Handle a new session object.
|
424 | */
|
425 | private _handleNewSession;
|
426 | /**
|
427 | * Handle an error in session startup.
|
428 | */
|
429 | private _handleSessionError;
|
430 | /**
|
431 | * Display kernel error
|
432 | */
|
433 | private _displayKernelError;
|
434 | /**
|
435 | * Handle a session termination.
|
436 | */
|
437 | private _onSessionDisposed;
|
438 | /**
|
439 | * Handle a change to a session property.
|
440 | */
|
441 | private _onPropertyChanged;
|
442 | /**
|
443 | * Handle a change to the kernel.
|
444 | */
|
445 | private _onKernelChanged;
|
446 | /**
|
447 | * Handle a change to the session status.
|
448 | */
|
449 | private _onStatusChanged;
|
450 | /**
|
451 | * Handle a change to the session status.
|
452 | */
|
453 | private _onConnectionStatusChanged;
|
454 | /**
|
455 | * Handle a change to the pending input.
|
456 | */
|
457 | private _onPendingInput;
|
458 | /**
|
459 | * Handle an iopub message.
|
460 | */
|
461 | private _onIopubMessage;
|
462 | /**
|
463 | * Handle an unhandled message.
|
464 | */
|
465 | private _onUnhandledMessage;
|
466 | private _path;
|
467 | private _name;
|
468 | private _type;
|
469 | private _prevKernelName;
|
470 | private _kernelPreference;
|
471 | private _isDisposed;
|
472 | private _disposed;
|
473 | private _session;
|
474 | private _ready;
|
475 | private _initializing;
|
476 | private _initStarted;
|
477 | private _initPromise;
|
478 | private _isReady;
|
479 | private _isTerminating;
|
480 | private _isRestarting;
|
481 | private _kernelChanged;
|
482 | private _sessionChanged;
|
483 | private _statusChanged;
|
484 | private _connectionStatusChanged;
|
485 | private translator;
|
486 | private _trans;
|
487 | private _pendingInput;
|
488 | private _iopubMessage;
|
489 | private _unhandledMessage;
|
490 | private _propertyChanged;
|
491 | private _dialog;
|
492 | private _setBusy;
|
493 | private _busyDisposable;
|
494 | private _pendingKernelName;
|
495 | private _pendingSessionRequest;
|
496 | }
|
497 | /**
|
498 | * A namespace for `SessionContext` statics.
|
499 | */
|
500 | export declare namespace SessionContext {
|
501 | |
502 |
|
503 |
|
504 | interface IOptions {
|
505 | |
506 |
|
507 |
|
508 | sessionManager: Session.IManager;
|
509 | |
510 |
|
511 |
|
512 | specsManager: KernelSpec.IManager;
|
513 | |
514 |
|
515 |
|
516 | path?: string;
|
517 | |
518 |
|
519 |
|
520 | name?: string;
|
521 | |
522 |
|
523 |
|
524 | type?: string;
|
525 | |
526 |
|
527 |
|
528 | kernelPreference?: ISessionContext.IKernelPreference;
|
529 | |
530 |
|
531 |
|
532 | translator?: ITranslator;
|
533 | |
534 |
|
535 |
|
536 | setBusy?: () => IDisposable;
|
537 | }
|
538 | |
539 |
|
540 |
|
541 | interface IKernelSearch {
|
542 | |
543 |
|
544 |
|
545 | specs: KernelSpec.ISpecModels | null;
|
546 | |
547 |
|
548 |
|
549 | preference: ISessionContext.IKernelPreference;
|
550 | |
551 |
|
552 |
|
553 | sessions?: IterableOrArrayLike<Session.IModel>;
|
554 | }
|
555 | |
556 |
|
557 |
|
558 | function getDefaultKernel(options: IKernelSearch): string | null;
|
559 | }
|
560 |
|
561 |
|
562 |
|
563 | export declare const sessionContextDialogs: ISessionContext.IDialogs;
|