UNPKG

28 kBTypeScriptView Raw
1import { JSONObject, JSONValue } from '@lumino/coreutils';
2import { IDisposable, IObservableDisposable } from '@lumino/disposable';
3import { ISignal } from '@lumino/signaling';
4import { ServerConnection } from '..';
5import * as KernelMessage from './messages';
6import { KernelSpec } from '../kernelspec';
7import { IManager as IBaseManager } from '../basemanager';
8import { IKernelOptions, IModel } from './restapi';
9export { Status } from './messages';
10export { IModel, IKernelOptions };
11/**
12 * Interface of a Kernel connection that is managed by a session.
13 *
14 * #### Notes
15 * The Kernel object is tied to the lifetime of the Kernel id, which is a
16 * unique id for the Kernel session on the server. The Kernel object manages
17 * a websocket connection internally, and will auto-restart if the websocket
18 * temporarily loses connection. Restarting creates a new Kernel process on
19 * the server, but preserves the Kernel id.
20 *
21 * The IKernelConnection is notably missing the full IKernel signals. This
22 * interface is for situations where a kernel may change, but we want a user
23 * to not have to worry about disconnecting and reconnecting signals when a
24 * kernel is swapped. The object that maintains an IKernel, but only provides
25 * a user with an IKernelConnection should proxy the appropriate IKernel
26 * signals for the user with its own signals. The advantage is that when the
27 * kernel is changed, the object itself can take care of disconnecting and
28 * reconnecting listeners.
29 */
30export interface IKernelConnection extends IObservableDisposable {
31 /**
32 * The id of the server-side kernel.
33 */
34 readonly id: string;
35 /**
36 * The name of the server-side kernel.
37 */
38 readonly name: string;
39 /**
40 * The kernel model, for convenience.
41 */
42 readonly model: IModel;
43 /**
44 * The client username.
45 */
46 readonly username: string;
47 /**
48 * The client unique id.
49 *
50 * #### Notes
51 * This should be unique for a particular kernel connection object.
52 */
53 readonly clientId: string;
54 /**
55 * The current status of the kernel.
56 */
57 readonly status: KernelMessage.Status;
58 /**
59 * The current connection status of the kernel.
60 */
61 readonly connectionStatus: ConnectionStatus;
62 /**
63 * The kernel info
64 *
65 * #### Notes
66 * This promise only resolves at startup, and is not refreshed on every
67 * restart.
68 */
69 readonly info: Promise<KernelMessage.IInfoReply>;
70 /**
71 * Get the kernel spec.
72 *
73 * @returns A promise that resolves with the kernel spec for this kernel.
74 *
75 * #### Notes
76 * This may make a server request to retrieve the spec.
77 */
78 readonly spec: Promise<KernelSpec.ISpecModel | undefined>;
79 /**
80 * Whether the kernel connection handles comm messages.
81 *
82 * #### Notes
83 * The comm message protocol currently has implicit assumptions that only
84 * one kernel connection is handling comm messages. This option allows a
85 * kernel connection to opt out of handling comms.
86 *
87 * See https://github.com/jupyter/jupyter_client/issues/263
88 */
89 handleComms: boolean;
90 /**
91 * Whether the kernel connection has pending input.
92 *
93 * #### Notes
94 * This is a guard to avoid deadlock is the user asks input
95 * as second time before submitting his first input
96 */
97 hasPendingInput: boolean;
98 /**
99 * Send a shell message to the kernel.
100 *
101 * @param msg - The fully-formed shell message to send.
102 *
103 * @param expectReply - Whether to expect a shell reply message.
104 *
105 * @param disposeOnDone - Whether to dispose of the future when done.
106 *
107 * #### Notes
108 * Send a message to the kernel's shell channel, yielding a future object
109 * for accepting replies.
110 *
111 * If `expectReply` is given and `true`, the future is done when both a
112 * shell reply and an idle status message are received with the appropriate
113 * parent header, in which case the `.done` promise resolves to the reply.
114 * If `expectReply` is not given or is `false`, the future is done when an
115 * idle status message with the appropriate parent header is received, in
116 * which case the `.done` promise resolves to `undefined`.
117 *
118 * If `disposeOnDone` is given and `false`, the future will not be disposed
119 * of when the future is done, instead relying on the caller to dispose of
120 * it. This allows for the handling of out-of-order output from ill-behaved
121 * kernels.
122 *
123 * All replies are validated as valid kernel messages.
124 *
125 * If the kernel status is `'dead'`, this will throw an error.
126 */
127 sendShellMessage<T extends KernelMessage.ShellMessageType>(msg: KernelMessage.IShellMessage<T>, expectReply?: boolean, disposeOnDone?: boolean): IShellFuture<KernelMessage.IShellMessage<T>>;
128 sendControlMessage<T extends KernelMessage.ControlMessageType>(msg: KernelMessage.IControlMessage<T>, expectReply?: boolean, disposeOnDone?: boolean): IControlFuture<KernelMessage.IControlMessage<T>>;
129 /**
130 * Reconnect to a disconnected kernel.
131 *
132 * @returns A promise that resolves when the kernel has reconnected.
133 *
134 * #### Notes
135 * This just refreshes the connection to an existing kernel, and does not
136 * perform an HTTP request to the server or restart the kernel.
137 */
138 reconnect(): Promise<void>;
139 /**
140 * Interrupt a kernel.
141 *
142 * @returns A promise that resolves when the kernel has interrupted.
143 *
144 * #### Notes
145 * Uses the [Jupyter Notebook API](https://petstore.swagger.io/?url=https://raw.githubusercontent.com/jupyter-server/jupyter_server/main/jupyter_server/services/api/api.yaml#!/kernels).
146 *
147 * The promise is fulfilled on a valid response and rejected otherwise.
148 *
149 * It is assumed that the API call does not mutate the kernel id or name.
150 *
151 * The promise will be rejected if the kernel status is `'dead'` or if the
152 * request fails or the response is invalid.
153 */
154 interrupt(): Promise<void>;
155 /**
156 * Restart a kernel.
157 *
158 * @returns A promise that resolves when the kernel has restarted.
159 *
160 * #### Notes
161 * Uses the [Jupyter Notebook API](https://petstore.swagger.io/?url=https://raw.githubusercontent.com/jupyter-server/jupyter_server/main/jupyter_server/services/api/api.yaml#!/kernels) and validates the response model.
162 *
163 * Any existing Future or Comm objects are cleared.
164 *
165 * It is assumed that the API call does not mutate the kernel id or name.
166 *
167 * The promise will be rejected if the kernel status is `'dead'` or if the
168 * request fails or the response is invalid.
169 */
170 restart(): Promise<void>;
171 /**
172 * Send a `kernel_info_request` message.
173 *
174 * @param content - The content of the request.
175 *
176 * @returns A promise that resolves with the response message.
177 *
178 * #### Notes
179 * See [Messaging in Jupyter](https://jupyter-client.readthedocs.io/en/latest/messaging.html#kernel-info).
180 *
181 * Fulfills with the `kernel_info_response` content when the shell reply is
182 * received and validated.
183 */
184 requestKernelInfo(): Promise<KernelMessage.IInfoReplyMsg | undefined>;
185 /**
186 * Send a `complete_request` message.
187 *
188 * @param content - The content of the request.
189 *
190 * @returns A promise that resolves with the response message.
191 *
192 * #### Notes
193 * See [Messaging in Jupyter](https://jupyter-client.readthedocs.io/en/latest/messaging.html#completion).
194 *
195 * Fulfills with the `complete_reply` content when the shell reply is
196 * received and validated.
197 */
198 requestComplete(content: KernelMessage.ICompleteRequestMsg['content']): Promise<KernelMessage.ICompleteReplyMsg>;
199 /**
200 * Send an `inspect_request` message.
201 *
202 * @param content - The content of the request.
203 *
204 * @returns A promise that resolves with the response message.
205 *
206 * #### Notes
207 * See [Messaging in Jupyter](https://jupyter-client.readthedocs.io/en/latest/messaging.html#introspection).
208 *
209 * Fulfills with the `inspect_reply` content when the shell reply is
210 * received and validated.
211 */
212 requestInspect(content: KernelMessage.IInspectRequestMsg['content']): Promise<KernelMessage.IInspectReplyMsg>;
213 /**
214 * Send a `history_request` message.
215 *
216 * @param content - The content of the request.
217 *
218 * @returns A promise that resolves with the response message.
219 *
220 * #### Notes
221 * See [Messaging in Jupyter](https://jupyter-client.readthedocs.io/en/latest/messaging.html#history).
222 *
223 * Fulfills with the `history_reply` content when the shell reply is
224 * received and validated.
225 */
226 requestHistory(content: KernelMessage.IHistoryRequestMsg['content']): Promise<KernelMessage.IHistoryReplyMsg>;
227 /**
228 * Send an `execute_request` message.
229 *
230 * @param content - The content of the request.
231 *
232 * @param disposeOnDone - Whether to dispose of the future when done.
233 *
234 * @returns A kernel future.
235 *
236 * #### Notes
237 * See [Messaging in
238 * Jupyter](https://jupyter-client.readthedocs.io/en/latest/messaging.html#execute).
239 *
240 * This method returns a kernel future, rather than a promise, since execution may
241 * have many response messages (for example, many iopub display messages).
242 *
243 * Future `onReply` is called with the `execute_reply` content when the
244 * shell reply is received and validated.
245 *
246 * **See also:** [[IExecuteReply]]
247 */
248 requestExecute(content: KernelMessage.IExecuteRequestMsg['content'], disposeOnDone?: boolean, metadata?: JSONObject): IShellFuture<KernelMessage.IExecuteRequestMsg, KernelMessage.IExecuteReplyMsg>;
249 /**
250 * Send an experimental `debug_request` message.
251 *
252 * @hidden
253 *
254 * @param content - The content of the request.
255 *
256 * @param disposeOnDone - Whether to dispose of the future when done.
257 *
258 * @returns A kernel future.
259 *
260 * #### Notes
261 * Debug messages are experimental messages that are not in the official
262 * kernel message specification. As such, this function is *NOT* considered
263 * part of the public API, and may change without notice.
264 */
265 requestDebug(content: KernelMessage.IDebugRequestMsg['content'], disposeOnDone?: boolean): IControlFuture<KernelMessage.IDebugRequestMsg, KernelMessage.IDebugReplyMsg>;
266 /**
267 * Send an `is_complete_request` message.
268 *
269 * @param content - The content of the request.
270 *
271 * @returns A promise that resolves with the response message.
272 *
273 * #### Notes
274 * See [Messaging in Jupyter](https://jupyter-client.readthedocs.io/en/latest/messaging.html#code-completeness).
275 *
276 * Fulfills with the `is_complete_response` content when the shell reply is
277 * received and validated.
278 */
279 requestIsComplete(content: KernelMessage.IIsCompleteRequestMsg['content']): Promise<KernelMessage.IIsCompleteReplyMsg>;
280 /**
281 * Send a `comm_info_request` message.
282 *
283 * @param content - The content of the request.
284 *
285 * @returns A promise that resolves with the response message.
286 *
287 * #### Notes
288 * See [Messaging in Jupyter](https://jupyter-client.readthedocs.io/en/latest/messaging.html#comm_info).
289 *
290 * Fulfills with the `comm_info_reply` content when the shell reply is
291 * received and validated.
292 */
293 requestCommInfo(content: KernelMessage.ICommInfoRequestMsg['content']): Promise<KernelMessage.ICommInfoReplyMsg>;
294 /**
295 * Send an `input_reply` message.
296 *
297 * @param content - The content of the reply.
298 *
299 * #### Notes
300 * See [Messaging in Jupyter](https://jupyter-client.readthedocs.io/en/latest/messaging.html#messages-on-the-stdin-router-dealer-sockets).
301 */
302 sendInputReply(content: KernelMessage.IInputReplyMsg['content'], parent_header: KernelMessage.IInputReplyMsg['parent_header']): void;
303 /**
304 * Create a new comm.
305 *
306 * @param targetName - The name of the comm target.
307 *
308 * @param id - The comm id.
309 *
310 * @returns A comm instance.
311 */
312 createComm(targetName: string, commId?: string): IComm;
313 /**
314 * Check if a comm exists.
315 */
316 hasComm(commId: string): boolean;
317 /**
318 * Register a comm target handler.
319 *
320 * @param targetName - The name of the comm target.
321 *
322 * @param callback - The callback invoked for a comm open message.
323 *
324 * #### Notes
325 * Only one comm target can be registered to a target name at a time, an
326 * existing callback for the same target name will be overridden. A registered
327 * comm target handler will take precedence over a comm which specifies a
328 * `target_module`.
329 *
330 * If the callback returns a promise, kernel message processing will pause
331 * until the returned promise is fulfilled.
332 */
333 registerCommTarget(targetName: string, callback: (comm: IComm, msg: KernelMessage.ICommOpenMsg) => void | PromiseLike<void>): void;
334 /**
335 * Remove a comm target handler.
336 *
337 * @param targetName - The name of the comm target to remove.
338 *
339 * @param callback - The callback to remove.
340 *
341 * #### Notes
342 * The comm target is only removed if it matches the callback argument.
343 */
344 removeCommTarget(targetName: string, callback: (comm: IComm, msg: KernelMessage.ICommOpenMsg) => void | PromiseLike<void>): void;
345 /**
346 * Register an IOPub message hook.
347 *
348 * @param msg_id - The parent_header message id in messages the hook should
349 * intercept.
350 *
351 * @param hook - The callback invoked for the message.
352 *
353 * #### Notes
354 * The IOPub hook system allows you to preempt the handlers for IOPub
355 * messages with a given parent_header message id. The most recently
356 * registered hook is run first. If a hook return value resolves to false,
357 * any later hooks and the future's onIOPub handler will not run. If a hook
358 * throws an error, the error is logged to the console and the next hook is
359 * run. If a hook is registered during the hook processing, it will not run
360 * until the next message. If a hook is disposed during the hook processing,
361 * it will be deactivated immediately.
362 *
363 * See also [[IFuture.registerMessageHook]].
364 */
365 registerMessageHook(msgId: string, hook: (msg: KernelMessage.IIOPubMessage) => boolean | PromiseLike<boolean>): void;
366 /**
367 * Remove an IOPub message hook.
368 *
369 * @param msg_id - The parent_header message id the hook intercepted.
370 *
371 * @param hook - The callback invoked for the message.
372 *
373 */
374 removeMessageHook(msgId: string, hook: (msg: KernelMessage.IIOPubMessage) => boolean | PromiseLike<boolean>): void;
375 /**
376 * Remove the input guard, if any.
377 */
378 removeInputGuard(): void;
379 /**
380 * A signal emitted when the kernel status changes.
381 */
382 statusChanged: ISignal<this, KernelMessage.Status>;
383 /**
384 * A signal emitted when the kernel connection status changes.
385 */
386 connectionStatusChanged: ISignal<this, ConnectionStatus>;
387 /**
388 * A signal emitted after an iopub kernel message is handled.
389 */
390 iopubMessage: ISignal<this, KernelMessage.IIOPubMessage>;
391 /**
392 * A signal emitted for unhandled non-iopub kernel messages that claimed to
393 * be responses for messages we sent using this kernel object.
394 */
395 unhandledMessage: ISignal<this, KernelMessage.IMessage>;
396 /**
397 * A signal emitted when any kernel message is sent or received.
398 *
399 * #### Notes
400 * This signal is emitted before any message handling has happened. The
401 * message should be treated as read-only.
402 */
403 anyMessage: ISignal<this, IAnyMessageArgs>;
404 /**
405 * A signal emitted when a kernel has pending inputs from the user.
406 */
407 pendingInput: ISignal<this, boolean>;
408 /**
409 * The server settings for the kernel.
410 */
411 readonly serverSettings: ServerConnection.ISettings;
412 /**
413 * Shutdown a kernel.
414 *
415 * @returns A promise that resolves when the kernel has shut down.
416 *
417 * #### Notes
418 * Uses the [Jupyter Notebook
419 * API](https://petstore.swagger.io/?url=https://raw.githubusercontent.com/jupyter-server/jupyter_server/main/jupyter_server/services/api/api.yaml#!/kernels).
420 *
421 * On a valid response, closes the websocket, disposes of the kernel
422 * object, and fulfills the promise.
423 *
424 * The promise will be rejected if the kernel status is `'dead'`, the
425 * request fails, or the response is invalid.
426 */
427 shutdown(): Promise<void>;
428 /**
429 * Clone the current kernel with a new clientId.
430 */
431 clone(options?: Pick<IKernelConnection.IOptions, 'clientId' | 'username' | 'handleComms'>): IKernelConnection;
432}
433/**
434 * The namespace for `IKernelConnection` statics.
435 */
436export declare namespace IKernelConnection {
437 /**
438 * The options object used to initialize a kernel.
439 */
440 interface IOptions {
441 /**
442 * The kernel model.
443 */
444 model: IModel;
445 /**
446 * The server settings for the kernel.
447 */
448 serverSettings?: ServerConnection.ISettings;
449 /**
450 * The username of the kernel client.
451 */
452 username?: string;
453 /**
454 * Whether the kernel connection should handle comm messages
455 *
456 * #### Notes
457 * The comm message protocol currently has implicit assumptions that only
458 * one kernel connection is handling comm messages. This option allows a
459 * kernel connection to opt out of handling comms.
460 *
461 * See https://github.com/jupyter/jupyter_client/issues/263
462 */
463 handleComms?: boolean;
464 /**
465 * The unique identifier for the kernel client.
466 */
467 clientId?: string;
468 }
469}
470/**
471 * Object which manages kernel instances for a given base url.
472 *
473 * #### Notes
474 * The manager is responsible for maintaining the state of running kernels
475 * through polling the server. Use a manager if you want to be notified of
476 * changes to kernels.
477 */
478export interface IManager extends IBaseManager {
479 /**
480 * A signal emitted when the running kernels change.
481 */
482 runningChanged: ISignal<IManager, IModel[]>;
483 /**
484 * A signal emitted when there is a server API connection failure.
485 */
486 connectionFailure: ISignal<IManager, ServerConnection.NetworkError>;
487 /**
488 * Whether the manager is ready.
489 */
490 readonly isReady: boolean;
491 /**
492 * A promise that resolves when the manager is initially ready.
493 */
494 readonly ready: Promise<void>;
495 /**
496 * Create an iterator over the known running kernels.
497 *
498 * @returns A new iterator over the running kernels.
499 */
500 running(): IterableIterator<IModel>;
501 /**
502 * Force a refresh of the running kernels.
503 *
504 * @returns A promise that resolves when the models are refreshed.
505 *
506 * #### Notes
507 * This is intended to be called only in response to a user action,
508 * since the manager maintains its internal state.
509 */
510 refreshRunning(): Promise<void>;
511 /**
512 * Start a new kernel.
513 *
514 * @param createOptions - The kernel creation options
515 *
516 * @param connectOptions - The kernel connection options
517 *
518 * @returns A promise that resolves with the kernel connection.
519 *
520 * #### Notes
521 * The manager `serverSettings` will be always be used.
522 */
523 startNew(createOptions?: IKernelOptions, connectOptions?: Omit<IKernelConnection.IOptions, 'model' | 'serverSettings'>): Promise<IKernelConnection>;
524 /**
525 * Find a kernel by id.
526 *
527 * @param id - The id of the target kernel.
528 *
529 * @returns A promise that resolves with the kernel's model, or undefined if not found.
530 */
531 findById(id: string): Promise<IModel | undefined>;
532 /**
533 * Connect to an existing kernel.
534 *
535 * @param model - The model of the target kernel.
536 *
537 * @returns A promise that resolves with the new kernel instance.
538 */
539 connectTo(options: IKernelConnection.IOptions): IKernelConnection;
540 /**
541 * Shut down a kernel by id.
542 *
543 * @param id - The id of the target kernel.
544 *
545 * @returns A promise that resolves when the operation is complete.
546 */
547 shutdown(id: string): Promise<void>;
548 /**
549 * Shut down all kernels.
550 *
551 * @returns A promise that resolves when all of the kernels are shut down.
552 */
553 shutdownAll(): Promise<void>;
554}
555/**
556 * A Future interface for responses from the kernel.
557 *
558 * When a message is sent to a kernel, a Future is created to handle any
559 * responses that may come from the kernel.
560 */
561export interface IFuture<REQUEST extends KernelMessage.IShellControlMessage, REPLY extends KernelMessage.IShellControlMessage> extends IDisposable {
562 /**
563 * The original outgoing message.
564 */
565 readonly msg: REQUEST;
566 /**
567 * A promise that resolves when the future is done.
568 *
569 * #### Notes
570 * The future is done when there are no more responses expected from the
571 * kernel.
572 *
573 * The `done` promise resolves to the reply message.
574 */
575 readonly done: Promise<REPLY>;
576 /**
577 * The reply handler for the kernel future.
578 *
579 * #### Notes
580 * If the handler returns a promise, all kernel message processing pauses
581 * until the promise is resolved. If there is a reply message, the future
582 * `done` promise also resolves to the reply message after this handler has
583 * been called.
584 */
585 onReply: (msg: REPLY) => void | PromiseLike<void>;
586 /**
587 * The iopub handler for the kernel future.
588 *
589 * #### Notes
590 * If the handler returns a promise, all kernel message processing pauses
591 * until the promise is resolved.
592 */
593 onIOPub: (msg: KernelMessage.IIOPubMessage) => void | PromiseLike<void>;
594 /**
595 * The stdin handler for the kernel future.
596 *
597 * #### Notes
598 * If the handler returns a promise, all kernel message processing pauses
599 * until the promise is resolved.
600 */
601 onStdin: (msg: KernelMessage.IStdinMessage) => void | PromiseLike<void>;
602 /**
603 * Register hook for IOPub messages.
604 *
605 * @param hook - The callback invoked for an IOPub message.
606 *
607 * #### Notes
608 * The IOPub hook system allows you to preempt the handlers for IOPub
609 * messages handled by the future.
610 *
611 * The most recently registered hook is run first. A hook can return a
612 * boolean or a promise to a boolean, in which case all kernel message
613 * processing pauses until the promise is fulfilled. If a hook return value
614 * resolves to false, any later hooks will not run and the function will
615 * return a promise resolving to false. If a hook throws an error, the error
616 * is logged to the console and the next hook is run. If a hook is
617 * registered during the hook processing, it will not run until the next
618 * message. If a hook is removed during the hook processing, it will be
619 * deactivated immediately.
620 */
621 registerMessageHook(hook: (msg: KernelMessage.IIOPubMessage) => boolean | PromiseLike<boolean>): void;
622 /**
623 * Remove a hook for IOPub messages.
624 *
625 * @param hook - The hook to remove.
626 *
627 * #### Notes
628 * If a hook is removed during the hook processing, it will be deactivated immediately.
629 */
630 removeMessageHook(hook: (msg: KernelMessage.IIOPubMessage) => boolean | PromiseLike<boolean>): void;
631 /**
632 * Send an `input_reply` message.
633 */
634 sendInputReply(content: KernelMessage.IInputReplyMsg['content'], parent_header: KernelMessage.IInputReplyMsg['parent_header']): void;
635}
636export interface IShellFuture<REQUEST extends KernelMessage.IShellMessage = KernelMessage.IShellMessage, REPLY extends KernelMessage.IShellMessage = KernelMessage.IShellMessage> extends IFuture<REQUEST, REPLY> {
637}
638export interface IControlFuture<REQUEST extends KernelMessage.IControlMessage = KernelMessage.IControlMessage, REPLY extends KernelMessage.IControlMessage = KernelMessage.IControlMessage> extends IFuture<REQUEST, REPLY> {
639}
640/**
641 * A client side Comm interface.
642 */
643export interface IComm extends IDisposable {
644 /**
645 * The unique id for the comm channel.
646 */
647 readonly commId: string;
648 /**
649 * The target name for the comm channel.
650 */
651 readonly targetName: string;
652 /**
653 * Callback for a comm close event.
654 *
655 * #### Notes
656 * This is called when the comm is closed from either the server or client.
657 * If this is called in response to a kernel message and the handler returns
658 * a promise, all kernel message processing pauses until the promise is
659 * resolved.
660 */
661 onClose: (msg: KernelMessage.ICommCloseMsg) => void | PromiseLike<void>;
662 /**
663 * Callback for a comm message received event.
664 *
665 * #### Notes
666 * If the handler returns a promise, all kernel message processing pauses
667 * until the promise is resolved.
668 */
669 onMsg: (msg: KernelMessage.ICommMsgMsg) => void | PromiseLike<void>;
670 /**
671 * Open a comm with optional data and metadata.
672 *
673 * @param data - The data to send to the server on opening.
674 *
675 * @param metadata - Additional metadata for the message.
676 *
677 * @returns A future for the generated message.
678 *
679 * #### Notes
680 * This sends a `comm_open` message to the server.
681 */
682 open(data?: JSONValue, metadata?: JSONObject, buffers?: (ArrayBuffer | ArrayBufferView)[]): IShellFuture;
683 /**
684 * Send a `comm_msg` message to the kernel.
685 *
686 * @param data - The data to send to the server on opening.
687 *
688 * @param metadata - Additional metadata for the message.
689 *
690 * @param buffers - Optional buffer data.
691 *
692 * @param disposeOnDone - Whether to dispose of the future when done.
693 *
694 * @returns A future for the generated message.
695 *
696 * #### Notes
697 * This is a no-op if the comm has been closed.
698 */
699 send(data: JSONValue, metadata?: JSONObject, buffers?: (ArrayBuffer | ArrayBufferView)[], disposeOnDone?: boolean): IShellFuture;
700 /**
701 * Close the comm.
702 *
703 * @param data - The data to send to the server on opening.
704 *
705 * @param metadata - Additional metadata for the message.
706 *
707 * @returns A future for the generated message.
708 *
709 * #### Notes
710 * This will send a `comm_close` message to the kernel, and call the
711 * `onClose` callback if set.
712 *
713 * This is a no-op if the comm is already closed.
714 */
715 close(data?: JSONValue, metadata?: JSONObject, buffers?: (ArrayBuffer | ArrayBufferView)[]): IShellFuture;
716}
717/**
718 * The valid kernel connection states.
719 *
720 * #### Notes
721 * The status states are:
722 * * `connected`: The kernel connection is live.
723 * * `connecting`: The kernel connection is not live, but we are attempting
724 * to reconnect to the kernel.
725 * * `disconnected`: The kernel connection is permanently down, we will not
726 * try to reconnect.
727 *
728 * When a kernel connection is `connected`, the kernel status should be
729 * valid. When a kernel connection is either `connecting` or `disconnected`,
730 * the kernel status will be `unknown` unless the kernel status was `dead`,
731 * in which case it stays `dead`.
732 */
733export type ConnectionStatus = 'connected' | 'connecting' | 'disconnected';
734/**
735 * Arguments interface for the anyMessage signal.
736 */
737export interface IAnyMessageArgs {
738 /**
739 * The message that is being signaled.
740 */
741 msg: Readonly<KernelMessage.IMessage>;
742 /**
743 * The direction of the message.
744 */
745 direction: 'send' | 'recv';
746}