UNPKG

28.1 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 Server 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 Server 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 * The number of running kernels.
503 */
504 readonly runningCount: number;
505 /**
506 * Force a refresh of the running kernels.
507 *
508 * @returns A promise that resolves when the models are refreshed.
509 *
510 * #### Notes
511 * This is intended to be called only in response to a user action,
512 * since the manager maintains its internal state.
513 */
514 refreshRunning(): Promise<void>;
515 /**
516 * Start a new kernel.
517 *
518 * @param createOptions - The kernel creation options
519 *
520 * @param connectOptions - The kernel connection options
521 *
522 * @returns A promise that resolves with the kernel connection.
523 *
524 * #### Notes
525 * The manager `serverSettings` will be always be used.
526 */
527 startNew(createOptions?: IKernelOptions, connectOptions?: Omit<IKernelConnection.IOptions, 'model' | 'serverSettings'>): Promise<IKernelConnection>;
528 /**
529 * Find a kernel by id.
530 *
531 * @param id - The id of the target kernel.
532 *
533 * @returns A promise that resolves with the kernel's model, or undefined if not found.
534 */
535 findById(id: string): Promise<IModel | undefined>;
536 /**
537 * Connect to an existing kernel.
538 *
539 * @param model - The model of the target kernel.
540 *
541 * @returns A promise that resolves with the new kernel instance.
542 */
543 connectTo(options: IKernelConnection.IOptions): IKernelConnection;
544 /**
545 * Shut down a kernel by id.
546 *
547 * @param id - The id of the target kernel.
548 *
549 * @returns A promise that resolves when the operation is complete.
550 */
551 shutdown(id: string): Promise<void>;
552 /**
553 * Shut down all kernels.
554 *
555 * @returns A promise that resolves when all of the kernels are shut down.
556 */
557 shutdownAll(): Promise<void>;
558}
559/**
560 * A Future interface for responses from the kernel.
561 *
562 * When a message is sent to a kernel, a Future is created to handle any
563 * responses that may come from the kernel.
564 */
565export interface IFuture<REQUEST extends KernelMessage.IShellControlMessage, REPLY extends KernelMessage.IShellControlMessage> extends IDisposable {
566 /**
567 * The original outgoing message.
568 */
569 readonly msg: REQUEST;
570 /**
571 * A promise that resolves when the future is done.
572 *
573 * #### Notes
574 * The future is done when there are no more responses expected from the
575 * kernel.
576 *
577 * The `done` promise resolves to the reply message.
578 */
579 readonly done: Promise<REPLY>;
580 /**
581 * The reply handler for the kernel future.
582 *
583 * #### Notes
584 * If the handler returns a promise, all kernel message processing pauses
585 * until the promise is resolved. If there is a reply message, the future
586 * `done` promise also resolves to the reply message after this handler has
587 * been called.
588 */
589 onReply: (msg: REPLY) => void | PromiseLike<void>;
590 /**
591 * The iopub handler for the kernel future.
592 *
593 * #### Notes
594 * If the handler returns a promise, all kernel message processing pauses
595 * until the promise is resolved.
596 */
597 onIOPub: (msg: KernelMessage.IIOPubMessage) => void | PromiseLike<void>;
598 /**
599 * The stdin handler for the kernel future.
600 *
601 * #### Notes
602 * If the handler returns a promise, all kernel message processing pauses
603 * until the promise is resolved.
604 */
605 onStdin: (msg: KernelMessage.IStdinMessage) => void | PromiseLike<void>;
606 /**
607 * Register hook for IOPub messages.
608 *
609 * @param hook - The callback invoked for an IOPub message.
610 *
611 * #### Notes
612 * The IOPub hook system allows you to preempt the handlers for IOPub
613 * messages handled by the future.
614 *
615 * The most recently registered hook is run first. A hook can return a
616 * boolean or a promise to a boolean, in which case all kernel message
617 * processing pauses until the promise is fulfilled. If a hook return value
618 * resolves to false, any later hooks will not run and the function will
619 * return a promise resolving to false. If a hook throws an error, the error
620 * is logged to the console and the next hook is run. If a hook is
621 * registered during the hook processing, it will not run until the next
622 * message. If a hook is removed during the hook processing, it will be
623 * deactivated immediately.
624 */
625 registerMessageHook(hook: (msg: KernelMessage.IIOPubMessage) => boolean | PromiseLike<boolean>): void;
626 /**
627 * Remove a hook for IOPub messages.
628 *
629 * @param hook - The hook to remove.
630 *
631 * #### Notes
632 * If a hook is removed during the hook processing, it will be deactivated immediately.
633 */
634 removeMessageHook(hook: (msg: KernelMessage.IIOPubMessage) => boolean | PromiseLike<boolean>): void;
635 /**
636 * Send an `input_reply` message.
637 */
638 sendInputReply(content: KernelMessage.IInputReplyMsg['content'], parent_header: KernelMessage.IInputReplyMsg['parent_header']): void;
639}
640export interface IShellFuture<REQUEST extends KernelMessage.IShellMessage = KernelMessage.IShellMessage, REPLY extends KernelMessage.IShellMessage = KernelMessage.IShellMessage> extends IFuture<REQUEST, REPLY> {
641}
642export interface IControlFuture<REQUEST extends KernelMessage.IControlMessage = KernelMessage.IControlMessage, REPLY extends KernelMessage.IControlMessage = KernelMessage.IControlMessage> extends IFuture<REQUEST, REPLY> {
643}
644/**
645 * A client side Comm interface.
646 */
647export interface IComm extends IDisposable {
648 /**
649 * The unique id for the comm channel.
650 */
651 readonly commId: string;
652 /**
653 * The target name for the comm channel.
654 */
655 readonly targetName: string;
656 /**
657 * Callback for a comm close event.
658 *
659 * #### Notes
660 * This is called when the comm is closed from either the server or client.
661 * If this is called in response to a kernel message and the handler returns
662 * a promise, all kernel message processing pauses until the promise is
663 * resolved.
664 */
665 onClose: (msg: KernelMessage.ICommCloseMsg) => void | PromiseLike<void>;
666 /**
667 * Callback for a comm message received event.
668 *
669 * #### Notes
670 * If the handler returns a promise, all kernel message processing pauses
671 * until the promise is resolved.
672 */
673 onMsg: (msg: KernelMessage.ICommMsgMsg) => void | PromiseLike<void>;
674 /**
675 * Open a comm with optional data and metadata.
676 *
677 * @param data - The data to send to the server on opening.
678 *
679 * @param metadata - Additional metadata for the message.
680 *
681 * @returns A future for the generated message.
682 *
683 * #### Notes
684 * This sends a `comm_open` message to the server.
685 */
686 open(data?: JSONValue, metadata?: JSONObject, buffers?: (ArrayBuffer | ArrayBufferView)[]): IShellFuture;
687 /**
688 * Send a `comm_msg` message to the kernel.
689 *
690 * @param data - The data to send to the server on opening.
691 *
692 * @param metadata - Additional metadata for the message.
693 *
694 * @param buffers - Optional buffer data.
695 *
696 * @param disposeOnDone - Whether to dispose of the future when done.
697 *
698 * @returns A future for the generated message.
699 *
700 * #### Notes
701 * This is a no-op if the comm has been closed.
702 */
703 send(data: JSONValue, metadata?: JSONObject, buffers?: (ArrayBuffer | ArrayBufferView)[], disposeOnDone?: boolean): IShellFuture;
704 /**
705 * Close the comm.
706 *
707 * @param data - The data to send to the server on opening.
708 *
709 * @param metadata - Additional metadata for the message.
710 *
711 * @returns A future for the generated message.
712 *
713 * #### Notes
714 * This will send a `comm_close` message to the kernel, and call the
715 * `onClose` callback if set.
716 *
717 * This is a no-op if the comm is already closed.
718 */
719 close(data?: JSONValue, metadata?: JSONObject, buffers?: (ArrayBuffer | ArrayBufferView)[]): IShellFuture;
720}
721/**
722 * The valid kernel connection states.
723 *
724 * #### Notes
725 * The status states are:
726 * * `connected`: The kernel connection is live.
727 * * `connecting`: The kernel connection is not live, but we are attempting
728 * to reconnect to the kernel.
729 * * `disconnected`: The kernel connection is permanently down, we will not
730 * try to reconnect.
731 *
732 * When a kernel connection is `connected`, the kernel status should be
733 * valid. When a kernel connection is either `connecting` or `disconnected`,
734 * the kernel status will be `unknown` unless the kernel status was `dead`,
735 * in which case it stays `dead`.
736 */
737export type ConnectionStatus = 'connected' | 'connecting' | 'disconnected';
738/**
739 * Arguments interface for the anyMessage signal.
740 */
741export interface IAnyMessageArgs {
742 /**
743 * The message that is being signaled.
744 */
745 msg: Readonly<KernelMessage.IMessage>;
746 /**
747 * The direction of the message.
748 */
749 direction: 'send' | 'recv';
750}