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