import { IDisposable } from 'phosphor/lib/core/disposable'; import { ISignal } from 'phosphor/lib/core/signaling'; import { IKernel, Kernel } from './kernel'; import { KernelMessage } from './messages'; import { IAjaxSettings } from '../utils'; /** * Implementation of the Kernel object */ export declare class DefaultKernel implements IKernel { /** * Construct a kernel object. */ constructor(options: Kernel.IOptions, id: string); /** * A signal emitted when the kernel status changes. */ statusChanged: ISignal; /** * A signal emitted for iopub kernel messages. */ iopubMessage: ISignal; /** * A signal emitted for unhandled kernel message. */ unhandledMessage: ISignal; /** * The id of the server-side kernel. */ readonly id: string; /** * The name of the server-side kernel. */ readonly name: string; /** * Get the model associated with the kernel. */ readonly model: Kernel.IModel; /** * The client username. */ readonly username: string; /** * The client unique id. */ readonly clientId: string; /** * The current status of the kernel. */ readonly status: Kernel.Status; /** * The cached info for the kernel. * * #### Notes * If `null`, call [[kernelInfo]] to get the value, * which will populate this value. */ readonly info: KernelMessage.IInfoReply; /** * The cached specs for the kernel. * * #### Notes * If `null`, call [[Kernel.getSpecs]] to get the value, * which will populate this value. */ readonly spec: Kernel.ISpec; /** * Get a copy of the default ajax settings for the kernel. */ /** * Set the default ajax settings for the kernel. */ ajaxSettings: IAjaxSettings; /** * Test whether the kernel has been disposed. */ readonly isDisposed: boolean; /** * Clone the current kernel with a new clientId. */ clone(): IKernel; /** * Dispose of the resources held by the kernel. */ dispose(): void; /** * Send a shell message to the kernel. * * #### Notes * Send a message to the kernel's shell channel, yielding a future object * for accepting replies. * * If `expectReply` is given and `true`, the future is disposed when both a * shell reply and an idle status message are received. If `expectReply` * is not given or is `false`, the future is resolved when an idle status * message is received. * If `disposeOnDone` is not given or is `true`, the Future is disposed at this point. * If `disposeOnDone` is given and `false`, it is up to the caller to dispose of the Future. * * All replies are validated as valid kernel messages. * * If the kernel status is `dead`, this will throw an error. */ sendShellMessage(msg: KernelMessage.IShellMessage, expectReply?: boolean, disposeOnDone?: boolean): Kernel.IFuture; /** * Interrupt a kernel. * * #### Notes * Uses the [Jupyter Notebook API](http://petstore.swagger.io/?url=https://raw.githubusercontent.com/jupyter/notebook/master/notebook/services/api/api.yaml#!/kernels). * * The promise is fulfilled on a valid response and rejected otherwise. * * It is assumed that the API call does not mutate the kernel id or name. * * The promise will be rejected if the kernel status is `Dead` or if the * request fails or the response is invalid. */ interrupt(): Promise; /** * Restart a kernel. * * #### Notes * Uses the [Jupyter Notebook API](http://petstore.swagger.io/?url=https://raw.githubusercontent.com/jupyter/notebook/master/notebook/services/api/api.yaml#!/kernels) and validates the response model. * * Any existing Future or Comm objects are cleared. * * The promise is fulfilled on a valid response and rejected otherwise. * * It is assumed that the API call does not mutate the kernel id or name. * * The promise will be rejected if the request fails or the response is * invalid. */ restart(): Promise; /** * Reconnect to a disconnected kernel. * * #### Notes * Used when the websocket connection to the kernel is lost. */ reconnect(): Promise; /** * Shutdown a kernel. * * #### Notes * Uses the [Jupyter Notebook API](http://petstore.swagger.io/?url=https://raw.githubusercontent.com/jupyter/notebook/master/notebook/services/api/api.yaml#!/kernels). * * The promise is fulfilled on a valid response and rejected otherwise. * * On a valid response, closes the websocket and disposes of the kernel * object, and fulfills the promise. * * The promise will be rejected if the kernel status is `Dead` or if the * request fails or the response is invalid. */ shutdown(): Promise; /** * Send a `kernel_info_request` message. * * #### Notes * See [Messaging in Jupyter](https://jupyter-client.readthedocs.io/en/latest/messaging.html#kernel-info). * * Fulfills with the `kernel_info_response` content when the shell reply is * received and validated. */ kernelInfo(): Promise; /** * Send a `complete_request` message. * * #### Notes * See [Messaging in Jupyter](https://jupyter-client.readthedocs.io/en/latest/messaging.html#completion). * * Fulfills with the `complete_reply` content when the shell reply is * received and validated. */ complete(content: KernelMessage.ICompleteRequest): Promise; /** * Send an `inspect_request` message. * * #### Notes * See [Messaging in Jupyter](https://jupyter-client.readthedocs.io/en/latest/messaging.html#introspection). * * Fulfills with the `inspect_reply` content when the shell reply is * received and validated. */ inspect(content: KernelMessage.IInspectRequest): Promise; /** * Send a `history_request` message. * * #### Notes * See [Messaging in Jupyter](https://jupyter-client.readthedocs.io/en/latest/messaging.html#history). * * Fulfills with the `history_reply` content when the shell reply is * received and validated. */ history(content: KernelMessage.IHistoryRequest): Promise; /** * Send an `execute_request` message. * * #### Notes * See [Messaging in Jupyter](https://jupyter-client.readthedocs.io/en/latest/messaging.html#execute). * * Future `onReply` is called with the `execute_reply` content when the * shell reply is received and validated. The future will resolve when * this message is received and the `idle` iopub status is received. * The future will also be disposed at this point unless `disposeOnDone` * is specified and `false`, in which case it is up to the caller to dispose * of the future. * * **See also:** [[IExecuteReply]] */ execute(content: KernelMessage.IExecuteRequest, disposeOnDone?: boolean): Kernel.IFuture; /** * Send an `is_complete_request` message. * * #### Notes * See [Messaging in Jupyter](https://jupyter-client.readthedocs.io/en/latest/messaging.html#code-completeness). * * Fulfills with the `is_complete_response` content when the shell reply is * received and validated. */ isComplete(content: KernelMessage.IIsCompleteRequest): Promise; /** * Send a `comm_info_request` message. * * #### Notes * Fulfills with the `comm_info_reply` content when the shell reply is * received and validated. */ commInfo(content: KernelMessage.ICommInfoRequest): Promise; /** * Send an `input_reply` message. * * #### Notes * See [Messaging in Jupyter](https://jupyter-client.readthedocs.io/en/latest/messaging.html#messages-on-the-stdin-router-dealer-sockets). */ sendInputReply(content: KernelMessage.IInputReply): void; /** * Register an IOPub message hook. * * @param msg_id - The parent_header message id the hook will intercept. * * @param hook - The callback invoked for the message. * * @returns A disposable used to unregister the message hook. * * #### Notes * The IOPub hook system allows you to preempt the handlers for IOPub messages with a * given parent_header message id. The most recently registered hook is run first. * If the hook returns false, any later hooks and the future's onIOPub handler will not run. * If a hook throws an error, the error is logged to the console and the next hook is run. * If a hook is registered during the hook processing, it won't run until the next message. * If a hook is disposed during the hook processing, it will be deactivated immediately. * * See also [[IFuture.registerMessageHook]]. */ registerMessageHook(msgId: string, hook: (msg: KernelMessage.IIOPubMessage) => boolean): IDisposable; /** * Register a comm target handler. * * @param targetName - The name of the comm target. * * @param callback - The callback invoked for a comm open message. * * @returns A disposable used to unregister the comm target. * * #### Notes * Only one comm target can be registered at a time, an existing * callback will be overidden. A registered comm target handler will take * precedence over a comm which specifies a `target_module`. */ registerCommTarget(targetName: string, callback: (comm: Kernel.IComm, msg: KernelMessage.ICommOpenMsg) => void): IDisposable; /** * Connect to a comm, or create a new one. * * #### Notes * If a client-side comm already exists, it is returned. */ connectToComm(targetName: string, commId?: string): Kernel.IComm; /** * Get the kernel spec associated with the kernel. * * #### Notes * This value is cached and only fetched the first time it is requested. */ getSpec(): Promise; /** * Create the kernel websocket connection and add socket status handlers. */ private _createSocket(); /** * Handle a websocket open event. */ private _onWSOpen(evt); /** * Handle a websocket message, validating and routing appropriately. */ private _onWSMessage(evt); /** * Handle a websocket close event. */ private _onWSClose(evt); /** * Handle status iopub messages from the kernel. */ private _updateStatus(status); /** * Send pending messages to the kernel. */ private _sendPending(); /** * Clear the internal state. */ private _clearState(); /** * Handle a `comm_open` kernel message. */ private _handleCommOpen(msg); /** * Handle 'comm_close' kernel message. */ private _handleCommClose(msg); /** * Handle a 'comm_msg' kernel message. */ private _handleCommMsg(msg); /** * Unregister a comm instance. */ private _unregisterComm(commId); private _id; private _name; private _baseUrl; private _wsUrl; private _status; private _clientId; private _ws; private _username; private _ajaxSettings; private _reconnectLimit; private _reconnectAttempt; private _isReady; private _futures; private _commPromises; private _comms; private _targetRegistry; private _spec; private _info; private _pendingMessages; private _connectionPromise; } /** * The namespace for `DefaultKernel` statics. */ export declare namespace DefaultKernel { /** * Find a kernel by id. * * #### Notes * If the kernel was already started via `startNewKernel`, we return its * `Kernel.IModel`. * * Otherwise, if `options` are given, we attempt to find the existing * kernel. * The promise is fulfilled when the kernel is found, * otherwise the promise is rejected. */ function findById(id: string, options?: Kernel.IOptions): Promise; /** * Fetch all of the kernel specs. * * #### Notes * Uses the [Jupyter Notebook API](http://petstore.swagger.io/?url=https://raw.githubusercontent.com/jupyter/notebook/master/notebook/services/api/api.yaml#!/kernelspecs). */ function getSpecs(options?: Kernel.IOptions): Promise; /** * Fetch the running kernels. * * #### Notes * Uses the [Jupyter Notebook API](http://petstore.swagger.io/?url=https://raw.githubusercontent.com/jupyter/notebook/master/notebook/services/api/api.yaml#!/kernels) and validates the response model. * * The promise is fulfilled on a valid response and rejected otherwise. */ function listRunning(options?: Kernel.IOptions): Promise; /** * Start a new kernel. * * #### Notes * Uses the [Jupyter Notebook API](http://petstore.swagger.io/?url=https://raw.githubusercontent.com/jupyter/notebook/master/notebook/services/api/api.yaml#!/kernels) and validates the response model. * * If no options are given or the kernel name is not given, the * default kernel will by started by the server. * * Wraps the result in a Kernel object. The promise is fulfilled * when the kernel is started by the server, otherwise the promise is rejected. */ function startNew(options?: Kernel.IOptions): Promise; /** * Connect to a running kernel. * * #### Notes * If the kernel was already started via `startNewKernel`, the existing * Kernel object info is used to create another instance. * * Otherwise, if `options` are given, we attempt to connect to the existing * kernel found by calling `listRunningKernels`. * The promise is fulfilled when the kernel is running on the server, * otherwise the promise is rejected. * * If the kernel was not already started and no `options` are given, * the promise is rejected. */ function connectTo(id: string, options?: Kernel.IOptions): Promise; /** * Shut down a kernel by id. */ function shutdown(id: string, options?: Kernel.IOptions): Promise; }