1 | import { IChangedArgs } from '@jupyterlab/coreutils';
|
2 | import { Kernel, KernelMessage, KernelSpec, Session } from '@jupyterlab/services';
|
3 | import { ISettingRegistry } from '@jupyterlab/settingregistry';
|
4 | import { ITranslator } from '@jupyterlab/translation';
|
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 kernelPreferenceChanged: ISignal<this, IChangedArgs<ISessionContext.IKernelPreference>>;
|
61 | |
62 |
|
63 |
|
64 | readonly statusChanged: ISignal<this, Kernel.Status>;
|
65 | |
66 |
|
67 |
|
68 | readonly connectionStatusChanged: ISignal<this, Kernel.ConnectionStatus>;
|
69 | |
70 |
|
71 |
|
72 | readonly pendingInput: boolean;
|
73 | |
74 |
|
75 |
|
76 | readonly iopubMessage: ISignal<this, KernelMessage.IMessage>;
|
77 | |
78 |
|
79 |
|
80 | readonly unhandledMessage: ISignal<this, KernelMessage.IMessage>;
|
81 | |
82 |
|
83 |
|
84 | readonly propertyChanged: ISignal<this, 'path' | 'name' | 'type'>;
|
85 | |
86 |
|
87 |
|
88 | kernelPreference: ISessionContext.IKernelPreference;
|
89 | |
90 |
|
91 |
|
92 |
|
93 |
|
94 |
|
95 | readonly hasNoKernel: boolean;
|
96 | |
97 |
|
98 |
|
99 |
|
100 |
|
101 |
|
102 |
|
103 | readonly kernelDisplayName: string;
|
104 | |
105 |
|
106 |
|
107 |
|
108 |
|
109 |
|
110 | readonly kernelDisplayStatus: ISessionContext.KernelDisplayStatus;
|
111 | |
112 |
|
113 |
|
114 |
|
115 |
|
116 |
|
117 |
|
118 | readonly path: string;
|
119 | |
120 |
|
121 |
|
122 |
|
123 |
|
124 |
|
125 |
|
126 | readonly type: string;
|
127 | |
128 |
|
129 |
|
130 |
|
131 |
|
132 |
|
133 |
|
134 | readonly name: string;
|
135 | |
136 |
|
137 |
|
138 | readonly prevKernelName: string;
|
139 | |
140 |
|
141 |
|
142 |
|
143 |
|
144 |
|
145 | readonly kernelManager?: Kernel.IManager;
|
146 | |
147 |
|
148 |
|
149 | readonly sessionManager: Session.IManager;
|
150 | |
151 |
|
152 |
|
153 | readonly specsManager: KernelSpec.IManager;
|
154 | |
155 |
|
156 |
|
157 |
|
158 |
|
159 | startKernel(): Promise<boolean>;
|
160 | |
161 |
|
162 |
|
163 |
|
164 |
|
165 | restartKernel(): Promise<void>;
|
166 | |
167 |
|
168 |
|
169 |
|
170 |
|
171 | shutdown(): Promise<void>;
|
172 | |
173 |
|
174 |
|
175 |
|
176 |
|
177 |
|
178 |
|
179 | changeKernel(options?: Partial<Kernel.IModel>): Promise<Kernel.IKernelConnection | null>;
|
180 | }
|
181 |
|
182 |
|
183 |
|
184 | export declare namespace ISessionContext {
|
185 | |
186 |
|
187 |
|
188 |
|
189 |
|
190 |
|
191 |
|
192 |
|
193 | interface IKernelPreference {
|
194 | |
195 |
|
196 |
|
197 | readonly name?: string;
|
198 | |
199 |
|
200 |
|
201 | readonly language?: string;
|
202 | |
203 |
|
204 |
|
205 | readonly id?: string;
|
206 | |
207 |
|
208 |
|
209 | readonly shouldStart?: boolean;
|
210 | |
211 |
|
212 |
|
213 | readonly canStart?: boolean;
|
214 | |
215 |
|
216 |
|
217 | readonly shutdownOnDispose?: boolean;
|
218 | |
219 |
|
220 |
|
221 |
|
222 | readonly autoStartDefault?: boolean;
|
223 | |
224 |
|
225 |
|
226 | readonly skipKernelRestartDialog?: boolean;
|
227 | }
|
228 | type KernelDisplayStatus = Kernel.Status | Kernel.ConnectionStatus | 'initializing' | '';
|
229 | |
230 |
|
231 |
|
232 | interface IDialogs {
|
233 | |
234 |
|
235 |
|
236 | selectKernel(session: ISessionContext): Promise<void>;
|
237 | |
238 |
|
239 |
|
240 |
|
241 |
|
242 |
|
243 |
|
244 |
|
245 |
|
246 |
|
247 |
|
248 | restart(session: ISessionContext): Promise<boolean>;
|
249 | }
|
250 | |
251 |
|
252 |
|
253 | interface IDialogsOptions {
|
254 | |
255 |
|
256 |
|
257 | translator?: ITranslator;
|
258 | |
259 |
|
260 |
|
261 | settingRegistry?: ISettingRegistry | null;
|
262 | }
|
263 | }
|
264 |
|
265 |
|
266 |
|
267 | export declare class SessionContext implements ISessionContext {
|
268 | |
269 |
|
270 |
|
271 | constructor(options: SessionContext.IOptions);
|
272 | /**
|
273 | * The current session connection.
|
274 | */
|
275 | get session(): Session.ISessionConnection | null;
|
276 | /**
|
277 | * The session path.
|
278 | *
|
279 | * #### Notes
|
280 | * Typically `.session.path` should be used. This attribute is useful if
|
281 | * there is no current session.
|
282 | */
|
283 | get path(): string;
|
284 | /**
|
285 | * The session type.
|
286 | *
|
287 | * #### Notes
|
288 | * Typically `.session.type` should be used. This attribute is useful if
|
289 | * there is no current session.
|
290 | */
|
291 | get type(): string;
|
292 | /**
|
293 | * The session name.
|
294 | *
|
295 | * #### Notes
|
296 | * Typically `.session.name` should be used. This attribute is useful if
|
297 | * there is no current session.
|
298 | */
|
299 | get name(): string;
|
300 | /**
|
301 | * A signal emitted when the kernel connection changes, proxied from the session connection.
|
302 | */
|
303 | get kernelChanged(): ISignal<this, Session.ISessionConnection.IKernelChangedArgs>;
|
304 | /**
|
305 | * A signal emitted when the session connection changes.
|
306 | */
|
307 | get sessionChanged(): ISignal<this, IChangedArgs<Session.ISessionConnection | null, Session.ISessionConnection | null, 'session'>>;
|
308 | /**
|
309 | * A signal emitted when the kernel status changes, proxied from the kernel.
|
310 | */
|
311 | get statusChanged(): ISignal<this, Kernel.Status>;
|
312 | /**
|
313 | * A flag indicating if the session has pending input, proxied from the kernel.
|
314 | */
|
315 | get pendingInput(): boolean;
|
316 | /**
|
317 | * A signal emitted when the kernel status changes, proxied from the kernel.
|
318 | */
|
319 | get connectionStatusChanged(): ISignal<this, Kernel.ConnectionStatus>;
|
320 | /**
|
321 | * A signal emitted for iopub kernel messages, proxied from the kernel.
|
322 | */
|
323 | get iopubMessage(): ISignal<this, KernelMessage.IIOPubMessage>;
|
324 | /**
|
325 | * A signal emitted for an unhandled kernel message, proxied from the kernel.
|
326 | */
|
327 | get unhandledMessage(): ISignal<this, KernelMessage.IMessage>;
|
328 | /**
|
329 | * A signal emitted when a session property changes, proxied from the current session.
|
330 | */
|
331 | get propertyChanged(): ISignal<this, 'path' | 'name' | 'type'>;
|
332 | /**
|
333 | * The kernel preference of this client session.
|
334 | *
|
335 | * This is used when selecting a new kernel, and should reflect the sort of
|
336 | * kernel the activity prefers.
|
337 | */
|
338 | get kernelPreference(): ISessionContext.IKernelPreference;
|
339 | set kernelPreference(value: ISessionContext.IKernelPreference);
|
340 | /**
|
341 | * Signal emitted if the kernel preference changes.
|
342 | */
|
343 | get kernelPreferenceChanged(): ISignal<this, IChangedArgs<ISessionContext.IKernelPreference>>;
|
344 | /**
|
345 | * Whether the context is ready.
|
346 | */
|
347 | get isReady(): boolean;
|
348 | /**
|
349 | * A promise that is fulfilled when the context is ready.
|
350 | */
|
351 | get ready(): Promise<void>;
|
352 | /**
|
353 | * Whether the context is terminating.
|
354 | */
|
355 | get isTerminating(): boolean;
|
356 | /**
|
357 | * Whether the context is restarting.
|
358 | */
|
359 | get isRestarting(): boolean;
|
360 | /**
|
361 | * The kernel manager
|
362 | */
|
363 | readonly kernelManager?: Kernel.IManager;
|
364 | /**
|
365 | * The session manager used by the session.
|
366 | */
|
367 | readonly sessionManager: Session.IManager;
|
368 | /**
|
369 | * The kernel spec manager
|
370 | */
|
371 | readonly specsManager: KernelSpec.IManager;
|
372 | /**
|
373 | * Whether the kernel is "No Kernel" or not.
|
374 | *
|
375 | * #### Notes
|
376 | * As the displayed name is translated, this can be used directly.
|
377 | */
|
378 | get hasNoKernel(): boolean;
|
379 | /**
|
380 | * The display name of the current kernel, or a sensible alternative.
|
381 | *
|
382 | * #### Notes
|
383 | * This is a convenience function to have a consistent sensible name for the
|
384 | * kernel.
|
385 | */
|
386 | get kernelDisplayName(): string;
|
387 | /**
|
388 | * A sensible status to display
|
389 | *
|
390 | * #### Notes
|
391 | * This combines the status and connection status into a single status for
|
392 | * the user.
|
393 | */
|
394 | get kernelDisplayStatus(): ISessionContext.KernelDisplayStatus;
|
395 | /**
|
396 | * The name of the previously started kernel.
|
397 | */
|
398 | get prevKernelName(): string;
|
399 | /**
|
400 | * Test whether the context is disposed.
|
401 | */
|
402 | get isDisposed(): boolean;
|
403 | /**
|
404 | * A signal emitted when the poll is disposed.
|
405 | */
|
406 | get disposed(): ISignal<this, void>;
|
407 | /**
|
408 | * Get the constant displayed name for "No Kernel"
|
409 | */
|
410 | protected get noKernelName(): string;
|
411 | /**
|
412 | * Dispose of the resources held by the context.
|
413 | */
|
414 | dispose(): void;
|
415 | /**
|
416 | * Starts new Kernel.
|
417 | *
|
418 | * @returns Whether to ask the user to pick a kernel.
|
419 | */
|
420 | startKernel(): Promise<boolean>;
|
421 | /**
|
422 | * Restart the current Kernel.
|
423 | *
|
424 | * @returns A promise that resolves when the kernel is restarted.
|
425 | */
|
426 | restartKernel(): Promise<void>;
|
427 | /**
|
428 | * Change the current kernel associated with the session.
|
429 | */
|
430 | changeKernel(options?: Partial<Kernel.IModel>): Promise<Kernel.IKernelConnection | null>;
|
431 | /**
|
432 | * Kill the kernel and shutdown the session.
|
433 | *
|
434 | * @returns A promise that resolves when the session is shut down.
|
435 | */
|
436 | shutdown(): Promise<void>;
|
437 | /**
|
438 | * Initialize the session context
|
439 | *
|
440 | * @returns A promise that resolves with whether to ask the user to select a kernel.
|
441 | *
|
442 | * #### Notes
|
443 | * If a server session exists on the current path, we will connect to it.
|
444 | * If preferences include disabling `canStart` or `shouldStart`, no
|
445 | * server session will be started.
|
446 | * If a kernel id is given, we attempt to start a session with that id.
|
447 | * If a default kernel is available, we connect to it.
|
448 | * Otherwise we ask the user to select a kernel.
|
449 | */
|
450 | initialize(): Promise<boolean>;
|
451 | /**
|
452 | * Inner initialize function that doesn't handle promises.
|
453 | * This makes it easier to consolidate promise handling logic.
|
454 | */
|
455 | _initialize(): Promise<boolean>;
|
456 | /**
|
457 | * Shut down the current session.
|
458 | */
|
459 | private _shutdownSession;
|
460 | /**
|
461 | * Start the session if necessary.
|
462 | *
|
463 | * @returns Whether to ask the user to pick a kernel.
|
464 | */
|
465 | private _startIfNecessary;
|
466 | /**
|
467 | * Change the kernel.
|
468 | */
|
469 | private _changeKernel;
|
470 | /**
|
471 | * Handle a new session object.
|
472 | */
|
473 | private _handleNewSession;
|
474 | /**
|
475 | * Handle an error in session startup.
|
476 | */
|
477 | private _handleSessionError;
|
478 | /**
|
479 | * Display kernel error
|
480 | */
|
481 | private _displayKernelError;
|
482 | /**
|
483 | * Handle a session termination.
|
484 | */
|
485 | private _onSessionDisposed;
|
486 | /**
|
487 | * Handle a change to a session property.
|
488 | */
|
489 | private _onPropertyChanged;
|
490 | /**
|
491 | * Handle a change to the kernel.
|
492 | */
|
493 | private _onKernelChanged;
|
494 | /**
|
495 | * Handle a change to the session status.
|
496 | */
|
497 | private _onStatusChanged;
|
498 | /**
|
499 | * Handle a change to the session status.
|
500 | */
|
501 | private _onConnectionStatusChanged;
|
502 | /**
|
503 | * Handle a change to the pending input.
|
504 | */
|
505 | private _onPendingInput;
|
506 | /**
|
507 | * Handle an iopub message.
|
508 | */
|
509 | private _onIopubMessage;
|
510 | /**
|
511 | * Handle an unhandled message.
|
512 | */
|
513 | private _onUnhandledMessage;
|
514 | private _path;
|
515 | private _name;
|
516 | private _type;
|
517 | private _prevKernelName;
|
518 | private _kernelPreference;
|
519 | private _isDisposed;
|
520 | private _disposed;
|
521 | private _session;
|
522 | private _ready;
|
523 | private _initializing;
|
524 | private _initStarted;
|
525 | private _initPromise;
|
526 | private _isReady;
|
527 | private _isTerminating;
|
528 | private _isRestarting;
|
529 | private _kernelChanged;
|
530 | private _preferenceChanged;
|
531 | private _sessionChanged;
|
532 | private _statusChanged;
|
533 | private _connectionStatusChanged;
|
534 | private translator;
|
535 | private _trans;
|
536 | private _pendingInput;
|
537 | private _iopubMessage;
|
538 | private _unhandledMessage;
|
539 | private _propertyChanged;
|
540 | private _dialog;
|
541 | private _setBusy;
|
542 | private _busyDisposable;
|
543 | private _pendingKernelName;
|
544 | private _pendingSessionRequest;
|
545 | }
|
546 | /**
|
547 | * A namespace for `SessionContext` statics.
|
548 | */
|
549 | export declare namespace SessionContext {
|
550 | |
551 |
|
552 |
|
553 | interface IOptions {
|
554 | |
555 |
|
556 |
|
557 |
|
558 |
|
559 |
|
560 | kernelManager?: Kernel.IManager;
|
561 | |
562 |
|
563 |
|
564 | sessionManager: Session.IManager;
|
565 | |
566 |
|
567 |
|
568 | specsManager: KernelSpec.IManager;
|
569 | |
570 |
|
571 |
|
572 | path?: string;
|
573 | |
574 |
|
575 |
|
576 | name?: string;
|
577 | |
578 |
|
579 |
|
580 | type?: string;
|
581 | |
582 |
|
583 |
|
584 | kernelPreference?: ISessionContext.IKernelPreference;
|
585 | |
586 |
|
587 |
|
588 | translator?: ITranslator;
|
589 | |
590 |
|
591 |
|
592 | setBusy?: () => IDisposable;
|
593 | }
|
594 | |
595 |
|
596 |
|
597 | interface IKernelSearch {
|
598 | |
599 |
|
600 |
|
601 | kernels?: Iterable<Kernel.IModel>;
|
602 | |
603 |
|
604 |
|
605 | specs: KernelSpec.ISpecModels | null;
|
606 | |
607 |
|
608 |
|
609 | preference: ISessionContext.IKernelPreference;
|
610 | |
611 |
|
612 |
|
613 | sessions?: Iterable<Session.IModel>;
|
614 | }
|
615 | |
616 |
|
617 |
|
618 | function getDefaultKernel(options: IKernelSearch): string | null;
|
619 | }
|
620 |
|
621 |
|
622 |
|
623 | export declare class SessionContextDialogs implements ISessionContext.IDialogs {
|
624 | constructor(options?: ISessionContext.IDialogsOptions);
|
625 | /**
|
626 | * Select a kernel for the session.
|
627 | */
|
628 | selectKernel(sessionContext: ISessionContext): Promise<void>;
|
629 | /**
|
630 | * Restart the session.
|
631 | *
|
632 | * @returns A promise that resolves with whether the kernel has restarted.
|
633 | *
|
634 | * #### Notes
|
635 | * If there is a running kernel, present a dialog.
|
636 | * If there is no kernel, we start a kernel with the last run
|
637 | * kernel name and resolves with `true`.
|
638 | */
|
639 | restart(sessionContext: ISessionContext): Promise<boolean>;
|
640 | private _translator;
|
641 | private _settingRegistry;
|
642 | }
|
643 | export declare namespace SessionContextDialogs {
|
644 | |
645 |
|
646 |
|
647 | interface IKernelOptions {
|
648 | |
649 |
|
650 |
|
651 | disabled?: boolean;
|
652 | |
653 |
|
654 |
|
655 | groups: Array<{
|
656 | |
657 |
|
658 |
|
659 | label: string;
|
660 | |
661 |
|
662 |
|
663 | options: Array<{
|
664 | |
665 |
|
666 |
|
667 | selected?: boolean;
|
668 | |
669 |
|
670 |
|
671 | text: string;
|
672 | |
673 |
|
674 |
|
675 | title?: string;
|
676 | |
677 |
|
678 |
|
679 | value: string;
|
680 | }>;
|
681 | }>;
|
682 | }
|
683 | |
684 |
|
685 |
|
686 |
|
687 |
|
688 |
|
689 |
|
690 |
|
691 |
|
692 |
|
693 |
|
694 |
|
695 |
|
696 |
|
697 |
|
698 |
|
699 |
|
700 |
|
701 |
|
702 |
|
703 |
|
704 |
|
705 |
|
706 |
|
707 |
|
708 |
|
709 |
|
710 |
|
711 |
|
712 |
|
713 |
|
714 |
|
715 | function kernelOptions(sessionContext: ISessionContext, translator?: ITranslator | null): IKernelOptions;
|
716 | }
|