소스 검색

Merge pull request #169 from blink1073/update-services

Update jupyter-js-services and associated APIs
A. Darian 8 년 전
부모
커밋
9e25c8e78f
41개의 변경된 파일185개의 추가작업 그리고 298개의 파일을 삭제
  1. 1 1
      examples/console/package.json
  2. 3 3
      examples/console/src/index.ts
  3. 1 1
      examples/filebrowser/package.json
  4. 3 4
      examples/filebrowser/src/index.ts
  5. 1 1
      examples/lab/package.json
  6. 1 1
      examples/notebook/package.json
  7. 3 3
      examples/notebook/src/index.ts
  8. 1 0
      examples/terminal/package.json
  9. 1 0
      jupyterlab/package.json
  10. 1 1
      package.json
  11. 5 5
      src/console/history.ts
  12. 2 2
      src/console/plugin.ts
  13. 17 11
      src/console/widget.ts
  14. 16 18
      src/docmanager/context.ts
  15. 9 11
      src/docmanager/manager.ts
  16. 2 2
      src/docregistry/default.ts
  17. 6 7
      src/docregistry/interfaces.ts
  18. 11 11
      src/docregistry/kernelselector.ts
  19. 2 2
      src/editorwidget/widget.ts
  20. 4 4
      src/filebrowser/buttons.ts
  21. 10 10
      src/filebrowser/dialogs.ts
  22. 22 27
      src/filebrowser/model.ts
  23. 1 1
      src/filebrowser/plugin.ts
  24. 2 2
      src/imagewidget/widget.ts
  25. 2 2
      src/notebook/common/mimetype.ts
  26. 4 3
      src/notebook/completion/model.ts
  27. 5 26
      src/notebook/notebook/default-toolbar.ts
  28. 0 1
      src/notebook/notebook/nbformat.ts
  29. 2 2
      src/notebook/notebook/panel.ts
  30. 2 2
      src/notebook/notebook/widget.ts
  31. 2 2
      src/notebook/notebook/widgetfactory.ts
  32. 13 14
      src/notebook/output-area/model.ts
  33. 2 2
      src/notebook/plugin.ts
  34. 11 11
      src/services/plugin.ts
  35. 3 3
      src/widgets/index.ts
  36. 6 20
      test/src/docmanager/mockcontext.ts
  37. 2 2
      test/src/docregistry/default.spec.ts
  38. 2 5
      test/src/notebook/notebook/actions.spec.ts
  39. 0 72
      test/src/utils.ts
  40. 1 0
      typings/codemirror/codemirror.d.ts
  41. 3 3
      typings/jupyter-js-widgets/jupyter-js-widgets.d.ts

+ 1 - 1
examples/console/package.json

@@ -9,7 +9,7 @@
     "watch": "watch 'npm run update && npm run build' ../../src src --wait 10"
   },
   "dependencies": {
-    "jupyter-js-services": "^0.10.4",
+    "jupyter-js-services": "^0.11.1",
     "jupyterlab": "file:../..",
     "phosphor-commandpalette": "^0.2.0",
     "phosphor-keymap": "^0.8.0",

+ 3 - 3
examples/console/src/index.ts

@@ -6,7 +6,7 @@ import {
 } from 'jupyterlab/lib/console';
 
 import {
-  startNewSession, INotebookSession
+  startNewSession, ISession
 } from 'jupyter-js-services';
 
 import {
@@ -44,14 +44,14 @@ let TITLE = 'Console';
 
 function main(): void {
   startNewSession({
-    notebookPath: 'fake_path',
+    path: 'fake_path',
   }).then(session => {
     startApp(session);
   });
 }
 
 
-function startApp(session: INotebookSession) {
+function startApp(session: ISession) {
   // Initialize the keymap manager with the bindings.
   let keymap = new KeymapManager();
 

+ 1 - 1
examples/filebrowser/package.json

@@ -9,7 +9,7 @@
     "watch": "watch 'npm run update && npm run build' ../../src src --wait 10"
   },
   "dependencies": {
-    "jupyter-js-services": "^0.10.4",
+    "jupyter-js-services": "^0.11.1",
     "jupyterlab": "file:../..",
     "phosphor-dockpanel": "^0.9.7",
     "phosphor-keymap": "^0.8.0",

+ 3 - 4
examples/filebrowser/src/index.ts

@@ -2,8 +2,7 @@
 // Distributed under the terms of the Modified BSD License.
 
 import {
-  ContentsManager, NotebookSessionManager,
-  IKernelSpecIds
+  ContentsManager, SessionManager, IKernel
 } from 'jupyter-js-services';
 
 import {
@@ -48,14 +47,14 @@ import 'jupyterlab/lib/theme.css';
 
 
 function main(): void {
-  let sessionsManager = new NotebookSessionManager();
+  let sessionsManager = new SessionManager();
   sessionsManager.getSpecs().then(specs => {
     createApp(sessionsManager, specs);
   });
 }
 
 
-function createApp(sessionsManager: NotebookSessionManager, specs: IKernelSpecIds): void {
+function createApp(sessionsManager: SessionManager, specs: IKernel.ISpecModels): void {
   let contentsManager = new ContentsManager();
   let widgets: DocumentWrapper[] = [];
   let activeWidget: DocumentWrapper;

+ 1 - 1
examples/lab/package.json

@@ -10,7 +10,7 @@
   },
   "dependencies": {
     "es6-promise": "^3.1.2",
-    "jupyter-js-services": "^0.10.4",
+    "jupyter-js-services": "^0.11.1",
     "jupyterlab": "file:../../",
     "phosphide": "^0.9.4"
   },

+ 1 - 1
examples/notebook/package.json

@@ -9,7 +9,7 @@
     "watch": "watch 'npm run update && npm run build' ../../src src --wait 10"
   },
   "dependencies": {
-    "jupyter-js-services": "^0.10.4",
+    "jupyter-js-services": "^0.11.1",
     "jupyterlab": "file:../..",
     "phosphor-commandpalette": "^0.2.0",
     "phosphor-dragdrop": "^0.9.1",

+ 3 - 3
examples/notebook/src/index.ts

@@ -7,7 +7,7 @@ import {
 } from 'jupyterlab/lib/notebook';
 
 import {
-  ContentsManager, IKernelSpecIds, NotebookSessionManager
+  ContentsManager, IKernel, SessionManager
 } from 'jupyter-js-services';
 
 import {
@@ -57,14 +57,14 @@ let NOTEBOOK = 'test.ipynb';
 
 
 function main(): void {
-  let sessionsManager = new NotebookSessionManager();
+  let sessionsManager = new SessionManager();
   sessionsManager.getSpecs().then(specs => {
     createApp(sessionsManager, specs);
   });
 }
 
 
-function createApp(sessionsManager: NotebookSessionManager, specs: IKernelSpecIds): void {
+function createApp(sessionsManager: SessionManager, specs: IKernel.ISpecModels): void {
   // Initialize the keymap manager with the bindings.
   let keymap = new KeymapManager();
   let useCapture = true;

+ 1 - 0
examples/terminal/package.json

@@ -9,6 +9,7 @@
     "watch": "watch 'npm run update && npm run build' ../../src src --wait 10"
   },
   "dependencies": {
+    "jupyter-js-services": "^0.11.1",
     "jupyterlab": "file:../..",
     "phosphor-dockpanel": "^0.9.7"
   },

+ 1 - 0
jupyterlab/package.json

@@ -8,6 +8,7 @@
   "dependencies": {
     "es6-promise": "^3.1.2",
     "font-awesome": "^4.6.1",
+    "jupyter-js-services": "^0.11.1",
     "jupyterlab": "file:../",
     "phosphide": "^0.9.4"
   },

+ 1 - 1
package.json

@@ -13,7 +13,7 @@
     "file-loader": "^0.8.5",
     "jquery": "^2.2.0",
     "jquery-ui": "^1.10.5",
-    "jupyter-js-services": "^0.10.5",
+    "jupyter-js-services": "^0.11.1",
     "jupyter-js-utils": "^0.4.0",
     "jupyter-js-widgets": "2.0.0-dev.0",
     "marked": "^0.3.5",

+ 5 - 5
src/console/history.ts

@@ -10,7 +10,7 @@ import {
 } from 'phosphor-signaling';
 
 import {
-  IKernel, IHistoryRequest, IHistoryReply
+  IKernel, KernelMessage
 } from 'jupyter-js-services';
 
 
@@ -81,15 +81,15 @@ class ConsoleHistory implements IConsoleHistory {
     }
     let contents = Private.initialRequest;
     this._kernel = newValue;
-    this._kernel.history(contents).then((value: IHistoryReply) => {
+    this._kernel.history(contents).then((value: KernelMessage.IHistoryReplyMsg) => {
       this._history = [];
       let last = '';
       let current = '';
-      for (let i = 0; i < value.history.length; i++) {
+      for (let i = 0; i < value.content.history.length; i++) {
         // History entries have the shape:
         // [session: number, line: number, input: string]
         // Contiguous duplicates are stripped out of the API response.
-        current = value.history[i][2];
+        current = (value.content.history[i] as string[])[2];
         if (current !== last) {
           this._history.push(last = current);
         }
@@ -175,7 +175,7 @@ class ConsoleHistory implements IConsoleHistory {
  */
 namespace Private {
   export
-  const initialRequest: IHistoryRequest = {
+  const initialRequest: KernelMessage.IHistoryRequest = {
     output: false,
     raw: true,
     hist_access_type: 'tail',

+ 2 - 2
src/console/plugin.ts

@@ -46,7 +46,7 @@ const consoleExtension = {
  */
 function activateConsole(app: Application, services: JupyterServices, rendermime: RenderMime<Widget>): Promise<void> {
 
-  let manager = services.notebookSessionManager;
+  let manager = services.sessionManager;
 
   // Add the ability to create new consoles for each kernel.
   let specs = services.kernelspecs;
@@ -65,7 +65,7 @@ function activateConsole(app: Application, services: JupyterServices, rendermime
       id,
       handler: () => {
         manager.startNew({
-          notebookPath: `Console-${count++}`,
+          path: `Console-${count++}`,
           kernelName: `${displayNameMap[displayName]}`
         }).then(session => {
           let console = new ConsolePanel(session, rendermime.clone());

+ 17 - 11
src/console/widget.ts

@@ -2,7 +2,7 @@
 // Distributed under the terms of the Modified BSD License.
 
 import {
-  IKernel, INotebookSession, KernelStatus
+  IKernel, ISession, KernelMessage
 } from 'jupyter-js-services';
 
 import {
@@ -82,14 +82,14 @@ class ConsolePanel extends Panel {
   /**
    * Create a new console widget for the panel.
    */
-  static createConsole(session: INotebookSession, rendermime: RenderMime<Widget>): ConsoleWidget {
+  static createConsole(session: ISession, rendermime: RenderMime<Widget>): ConsoleWidget {
     return new ConsoleWidget(session, rendermime);
   }
 
   /**
    * Construct a console panel.
    */
-  constructor(session: INotebookSession, rendermime: RenderMime<Widget>) {
+  constructor(session: ISession, rendermime: RenderMime<Widget>) {
     super();
     this.addClass(CONSOLE_PANEL);
     let constructor = this.constructor as typeof ConsolePanel;
@@ -231,7 +231,7 @@ class ConsoleWidget extends Widget {
   /**
    * Construct a console widget.
    */
-  constructor(session: INotebookSession, rendermime: RenderMime<Widget>) {
+  constructor(session: ISession, rendermime: RenderMime<Widget>) {
     super();
     this.addClass(CONSOLE_CLASS);
 
@@ -291,7 +291,7 @@ class ConsoleWidget extends Widget {
    * #### Notes
    * This is a read-only property.
    */
-  get session(): INotebookSession {
+  get session(): ISession {
     return this._session;
   }
 
@@ -318,7 +318,7 @@ class ConsoleWidget extends Widget {
    * Execute the current prompt.
    */
   execute(): Promise<void> {
-    if (this._session.status === KernelStatus.Dead) {
+    if (this._session.status === 'dead') {
       return;
     }
     let prompt = this.prompt;
@@ -404,7 +404,8 @@ class ConsoleWidget extends Widget {
   protected initialize(): void {
     let layout = this.layout as PanelLayout;
     let banner = layout.childAt(0) as RawCellWidget;
-    this._session.kernel.kernelInfo().then(info => {
+    this._session.kernel.kernelInfo().then(msg => {
+      let info = msg.content;
       banner.model.source = info.banner;
       this._mimetype = mimetypeForLanguage(info.language_info);
       this.prompt.mimetype = this._mimetype;
@@ -442,9 +443,14 @@ class ConsoleWidget extends Widget {
    */
   protected updateTooltip(change: ITextChange): void {
     let line = change.newValue.split('\n')[change.line];
-    let contents = { code: line, cursor_pos: change.ch, detail_level: 0 };
+    let contents: KernelMessage.IInspectRequest = {
+      code: line,
+      cursor_pos: change.ch,
+      detail_level: 0
+    };
     let pendingInspect = ++this._pendingInspect;
-    this._session.kernel.inspect(contents).then(value => {
+    this._session.kernel.inspect(contents).then(msg => {
+      let value = msg.content;
       // If widget has been disposed, bail.
       if (this.isDisposed) {
         return;
@@ -457,7 +463,7 @@ class ConsoleWidget extends Widget {
       if (value.status !== 'ok' || !value.found) {
         return;
       }
-      this.showTooltip(change, value.data);
+      this.showTooltip(change, value.data as MimeMap<string>);
     });
   }
 
@@ -554,7 +560,7 @@ class ConsoleWidget extends Widget {
   private _rendermime: RenderMime<Widget> = null;
   private _tooltip: ConsoleTooltip = null;
   private _history: IConsoleHistory = null;
-  private _session: INotebookSession = null;
+  private _session: ISession = null;
   private _pendingInspect = 0;
 }
 

+ 16 - 18
src/docmanager/context.ts

@@ -2,9 +2,7 @@
 // Distributed under the terms of the Modified BSD License.
 
 import {
-  IKernelId, IKernel, IKernelSpecIds, IContentsManager,
-  INotebookSessionManager, INotebookSession, ISessionId,
-  IContentsOpts, ISessionOptions, IContentsModel
+  IContentsManager, IContentsModel, IContentsOpts, IKernel, ISession
 } from 'jupyter-js-services';
 
 import * as utils
@@ -117,7 +115,7 @@ class Context implements IDocumentContext<IDocumentModel> {
    * #### Notes
    * This is a read-only property.
    */
-  get kernelspecs(): IKernelSpecIds {
+  get kernelspecs(): IKernel.ISpecModels {
     return this._manager.getKernelspecs();
   }
 
@@ -142,7 +140,7 @@ class Context implements IDocumentContext<IDocumentModel> {
   /**
    * Change the current kernel associated with the document.
    */
-  changeKernel(options: IKernelId): Promise<IKernel> {
+  changeKernel(options: IKernel.IModel): Promise<IKernel> {
     return this._manager.changeKernel(this._id, options);
   }
 
@@ -170,7 +168,7 @@ class Context implements IDocumentContext<IDocumentModel> {
   /**
    * Get the list of running sessions.
    */
-  listSessions(): Promise<ISessionId[]> {
+  listSessions(): Promise<ISession.IModel[]> {
     return this._manager.listSessions();
   }
 
@@ -202,7 +200,7 @@ class ContextManager implements IDisposable {
   /**
    * Construct a new context manager.
    */
-  constructor(contentsManager: IContentsManager, sessionManager: INotebookSessionManager,  kernelspecs: IKernelSpecIds, opener: (id: string, widget: Widget) => IDisposable) {
+  constructor(contentsManager: IContentsManager, sessionManager: ISession.IManager,  kernelspecs: IKernel.ISpecModels, opener: (id: string, widget: Widget) => IDisposable) {
     this._contentsManager = contentsManager;
     this._sessionManager = sessionManager;
     this._opener = opener;
@@ -335,7 +333,7 @@ class ContextManager implements IDisposable {
    * if necessary). If falsey, shut down any existing session and return
    * a void promise.
    */
-  changeKernel(id: string, options: IKernelId): Promise<IKernel> {
+  changeKernel(id: string, options: IKernel.IModel): Promise<IKernel> {
     let contextEx = this._contexts[id];
     let session = contextEx.session;
     if (options) {
@@ -343,8 +341,8 @@ class ContextManager implements IDisposable {
         return session.changeKernel(options);
       } else {
         let path = contextEx.path;
-        let sOptions = {
-          notebookPath: path,
+        let sOptions: ISession.IOptions = {
+          path: path,
           kernelName: options.name,
           kernelId: options.id
         };
@@ -382,7 +380,7 @@ class ContextManager implements IDisposable {
       if (!sessionUpdated) {
         let session = contextEx.session;
         if (session) {
-          session.renameNotebook(newPath);
+          session.rename(newPath);
           sessionUpdated = true;
         }
       }
@@ -392,7 +390,7 @@ class ContextManager implements IDisposable {
   /**
    * Get the current kernelspec information.
    */
-  getKernelspecs(): IKernelSpecIds {
+  getKernelspecs(): IKernel.ISpecModels {
     return this._kernelspecids;
   }
 
@@ -461,7 +459,7 @@ class ContextManager implements IDisposable {
   /**
    * Get the list of running sessions.
    */
-  listSessions(): Promise<ISessionId[]> {
+  listSessions(): Promise<ISession.IModel[]> {
     return this._sessionManager.listRunning();
   }
 
@@ -476,7 +474,7 @@ class ContextManager implements IDisposable {
   /**
    * Start a session and set up its signals.
    */
-  private _startSession(id: string, options: ISessionOptions): Promise<IKernel> {
+  private _startSession(id: string, options: ISession.IOptions): Promise<IKernel> {
     let contextEx = this._contexts[id];
     let context = contextEx.context;
     return this._sessionManager.startNew(options).then(session => {
@@ -485,7 +483,7 @@ class ContextManager implements IDisposable {
       }
       contextEx.session = session;
       context.kernelChanged.emit(session.kernel);
-      session.notebookPathChanged.connect((s, path) => {
+      session.pathChanged.connect((s, path) => {
         if (path !== contextEx.path) {
           contextEx.path = path;
           context.pathChanged.emit(path);
@@ -515,8 +513,8 @@ class ContextManager implements IDisposable {
   }
 
   private _contentsManager: IContentsManager = null;
-  private _sessionManager: INotebookSessionManager = null;
-  private _kernelspecids: IKernelSpecIds = null;
+  private _sessionManager: ISession.IManager = null;
+  private _kernelspecids: IKernel.ISpecModels = null;
   private _contexts: { [key: string]: Private.IContextEx } = Object.create(null);
   private _opener: (id: string, widget: Widget) => IDisposable = null;
 }
@@ -533,7 +531,7 @@ namespace Private {
   interface IContextEx {
     context: IDocumentContext<IDocumentModel>;
     model: IDocumentModel;
-    session: INotebookSession;
+    session: ISession;
     opts: IContentsOpts;
     path: string;
     contentsModel: IContentsModel;

+ 9 - 11
src/docmanager/manager.ts

@@ -2,9 +2,7 @@
 // Distributed under the terms of the Modified BSD License.
 
 import {
-  IKernelId,
-  IContentsManager, INotebookSessionManager,
-  IKernelSpecIds, ISessionId
+  IContentsManager, IKernel, ISession
 } from 'jupyter-js-services';
 
 import {
@@ -66,7 +64,7 @@ class DocumentManager implements IDisposable {
   /**
    * Construct a new document manager.
    */
-  constructor(registry: DocumentRegistry, contentsManager: IContentsManager, sessionManager: INotebookSessionManager, kernelspecs: IKernelSpecIds, opener: IWidgetOpener) {
+  constructor(registry: DocumentRegistry, contentsManager: IContentsManager, sessionManager: ISession.IManager, kernelspecs: IKernel.ISpecModels, opener: IWidgetOpener) {
     this._registry = registry;
     this._contentsManager = contentsManager;
     this._sessionManager = sessionManager;
@@ -87,7 +85,7 @@ class DocumentManager implements IDisposable {
    * #### Notes
    * This is a read-only property.
    */
-  get kernelspecs(): IKernelSpecIds {
+  get kernelspecs(): IKernel.ISpecModels {
     return this._specs;
   }
 
@@ -136,7 +134,7 @@ class DocumentManager implements IDisposable {
    *
    * @param kernel - An optional kernel name/id to override the default.
    */
-  open(path: string, widgetName='default', kernel?: IKernelId): DocumentWrapper {
+  open(path: string, widgetName='default', kernel?: IKernel.IModel): DocumentWrapper {
     let registry = this._registry;
     if (widgetName === 'default') {
       let parts = path.split('.');
@@ -180,7 +178,7 @@ class DocumentManager implements IDisposable {
    *
    * @param kernel - An optional kernel name/id to override the default.
    */
-  createNew(path: string, widgetName='default', kernel?: IKernelId): DocumentWrapper {
+  createNew(path: string, widgetName='default', kernel?: IKernel.IModel): DocumentWrapper {
     let registry = this._registry;
     if (widgetName === 'default') {
       let parts = path.split('.');
@@ -211,7 +209,7 @@ class DocumentManager implements IDisposable {
   /**
    * List the running notebook sessions.
    */
-  listSessions(): Promise<ISessionId[]> {
+  listSessions(): Promise<ISession.IModel[]> {
     return this._sessionManager.listRunning();
   }
 
@@ -307,7 +305,7 @@ class DocumentManager implements IDisposable {
   /**
    * Create a content widget and add it to the container widget.
    */
-  private _populateWidget(parent: DocumentWrapper, kernel?: IKernelId): void {
+  private _populateWidget(parent: DocumentWrapper, kernel?: IKernel.IModel): void {
     let factory = this._registry.getWidgetFactory(parent.name);
     let id = parent.context.id;
     let model = this._contextManager.getModel(id);
@@ -327,9 +325,9 @@ class DocumentManager implements IDisposable {
 
   private _widgets: { [key: string]: DocumentWrapper[] } = Object.create(null);
   private _contentsManager: IContentsManager = null;
-  private _sessionManager: INotebookSessionManager = null;
+  private _sessionManager: ISession.IManager = null;
   private _contextManager: ContextManager = null;
-  private _specs: IKernelSpecIds = null;
+  private _specs: IKernel.ISpecModels = null;
   private _registry: DocumentRegistry = null;
 }
 

+ 2 - 2
src/docregistry/default.ts

@@ -5,7 +5,7 @@ import * as CodeMirror
   from 'codemirror';
 
 import {
-  IKernelId, IContentsOpts
+  IKernel, IContentsOpts
 } from 'jupyter-js-services';
 
 import {
@@ -282,7 +282,7 @@ abstract class ABCWidgetFactory implements IWidgetFactory<Widget, IDocumentModel
   /**
    * Create a new widget given a document model and a context.
    */
-  abstract createNew(context: IDocumentContext<IDocumentModel>, kernel?: IKernelId): Widget;
+  abstract createNew(context: IDocumentContext<IDocumentModel>, kernel?: IKernel.IModel): Widget;
 
   /**
    * Take an action on a widget before closing it.

+ 6 - 7
src/docregistry/interfaces.ts

@@ -2,12 +2,11 @@
 // Distributed under the terms of the Modified BSD License.
 
 import {
-  IContentsModel, IKernelId, IContentsOpts, IKernel,
-  IKernelSpecIds, ISessionId
+  IContentsModel, IContentsOpts, IKernel, ISession
 } from 'jupyter-js-services';
 
 import {
-  IDisposable, DisposableDelegate, DisposableSet
+  IDisposable
 } from 'phosphor-disposable';
 
 import {
@@ -152,7 +151,7 @@ export interface IDocumentContext<T extends IDocumentModel> extends IDisposable
    * #### Notes
    * This is a read-only property.
    */
-  kernelspecs: IKernelSpecIds;
+  kernelspecs: IKernel.ISpecModels;
 
   /**
    * A signal emitted when the kernel changes.
@@ -170,7 +169,7 @@ export interface IDocumentContext<T extends IDocumentModel> extends IDisposable
    * #### Notes
    * If no options are given, the session is shut down.
    */
-  changeKernel(options?: IKernelId): Promise<IKernel>;
+  changeKernel(options?: IKernel.IModel): Promise<IKernel>;
 
   /**
    * Save the document contents to disk.
@@ -190,7 +189,7 @@ export interface IDocumentContext<T extends IDocumentModel> extends IDisposable
   /**
    * Get the list of running sessions.
    */
-  listSessions(): Promise<ISessionId[]>;
+  listSessions(): Promise<ISession.IModel[]>;
 
   /**
    * Add a sibling widget to the document manager.
@@ -258,7 +257,7 @@ interface IWidgetFactory<T extends Widget, U extends IDocumentModel> extends IDi
   /**
    * Create a new widget.
    */
-  createNew(context: IDocumentContext<U>, kernel?: IKernelId): T;
+  createNew(context: IDocumentContext<U>, kernel?: IKernel.IModel): T;
 
   /**
    * Take an action on a widget before closing it.

+ 11 - 11
src/docregistry/kernelselector.ts

@@ -2,7 +2,7 @@
 // Distributed under the terms of the Modified BSD License.
 
 import {
-  ISessionId, IKernelId, IKernelSpecIds
+  IKernel, ISession
 } from 'jupyter-js-services';
 
 import {
@@ -27,12 +27,12 @@ interface IKernelSelection {
   /**
    * The kernel spec information.
    */
-  specs: IKernelSpecIds;
+  specs: IKernel.ISpecModels;
 
   /**
    * The current running sessions.
    */
-  sessions: ISessionId[];
+  sessions: ISession.IModel[];
 
   /**
    * The desired kernel language.
@@ -42,7 +42,7 @@ interface IKernelSelection {
   /**
    * The optional existing kernel id.
    */
-  kernel?: IKernelId;
+  kernel?: IKernel.IModel;
 
   /**
    * The host node for the dialog.
@@ -55,7 +55,7 @@ interface IKernelSelection {
  * Bring up a dialog to select a kernel.
  */
 export
-function selectKernel(options: IKernelSelection): Promise<IKernelId> {
+function selectKernel(options: IKernelSelection): Promise<IKernel.IModel> {
   let specs = options.specs;
   let kernel = options.kernel;
 
@@ -84,7 +84,7 @@ function selectKernel(options: IKernelSelection): Promise<IKernelId> {
   }).then(result => {
     // Change the kernel if a kernel was selected.
     if (result.text === 'SELECT') {
-      return JSON.parse(selector.value) as IKernelId;
+      return JSON.parse(selector.value) as IKernel.IModel;
     }
     return void 0;
   });
@@ -116,7 +116,7 @@ function selectKernelForContext(context: IDocumentContext<IDocumentModel>, host?
  * Get the appropriate kernel name.
  */
 export
-function findKernel(kernelName: string, language: string, specs: IKernelSpecIds): string {
+function findKernel(kernelName: string, language: string, specs: IKernel.ISpecModels): string {
   if (kernelName === 'unknown') {
     return specs.default;
   }
@@ -171,7 +171,7 @@ function findKernel(kernelName: string, language: string, specs: IKernelSpecIds)
  * the explicit session information.
  */
 export
-function populateKernels(node: HTMLSelectElement, specs: IKernelSpecIds, running: ISessionId[], preferredLanguage?: string): void {
+function populateKernels(node: HTMLSelectElement, specs: IKernel.ISpecModels, running: ISession.IModel[], preferredLanguage?: string): void {
   // Clear any existing options.
   while (node.firstChild) {
     node.removeChild(node.firstChild);
@@ -228,7 +228,7 @@ function populateKernels(node: HTMLSelectElement, specs: IKernelSpecIds, running
     node.appendChild(createSeparatorOption(maxLength));
   }
   // Add the sessions using the preferred language first.
-  let matchingSessions: ISessionId[] = [];
+  let matchingSessions: ISession.IModel[] = [];
   if (preferredLanguage) {
     for (let session of running) {
       if (languages[session.kernel.name] === preferredLanguage) {
@@ -247,7 +247,7 @@ function populateKernels(node: HTMLSelectElement, specs: IKernelSpecIds, running
     }
   }
   // Add the other remaining sessions.
-  let otherSessions: ISessionId[] = [];
+  let otherSessions: ISession.IModel[] = [];
   for (let session of running) {
     if (matchingSessions.indexOf(session) === -1) {
       otherSessions.push(session);
@@ -290,7 +290,7 @@ function optionForName(name: string, displayName: string): HTMLOptionElement {
 /**
  * Create an option element for a session.
  */
-function optionForSession(session: ISessionId, displayName: string, maxLength: number): HTMLOptionElement {
+function optionForSession(session: ISession.IModel, displayName: string, maxLength: number): HTMLOptionElement {
   let option = document.createElement('option');
   let sessionName = session.notebook.path.split('/').pop();
   if (sessionName.length > maxLength) {

+ 2 - 2
src/editorwidget/widget.ts

@@ -7,7 +7,7 @@ import * as CodeMirror
 import 'codemirror/mode/meta';
 
 import {
-  IKernelId
+  IKernel
 } from 'jupyter-js-services';
 
 import {
@@ -89,7 +89,7 @@ class EditorWidgetFactory extends ABCWidgetFactory implements IWidgetFactory<Edi
   /**
    * Create a new widget given a context.
    */
-  createNew(context: IDocumentContext<IDocumentModel>, kernel?: IKernelId): EditorWidget {
+  createNew(context: IDocumentContext<IDocumentModel>, kernel?: IKernel.IModel): EditorWidget {
     if (kernel) {
       context.changeKernel(kernel);
     }

+ 4 - 4
src/filebrowser/buttons.ts

@@ -2,7 +2,7 @@
 // Distributed under the terms of the Modified BSD License.
 
 import {
-  IKernelId
+  IKernel
 } from 'jupyter-js-services';
 
 import {
@@ -144,7 +144,7 @@ class FileButtons extends Widget {
   /**
    * Open a file by path.
    */
-  open(path: string, widgetName='default', kernel?: IKernelId): void {
+  open(path: string, widgetName='default', kernel?: IKernel.IModel): void {
     let widget = this._manager.open(path, widgetName, kernel);
     let opener = this._opener;
     opener.open(widget);
@@ -155,7 +155,7 @@ class FileButtons extends Widget {
   /**
    * Create a new file by path.
    */
-  createNew(path: string, widgetName='default', kernel?: IKernelId): void {
+  createNew(path: string, widgetName='default', kernel?: IKernel.IModel): void {
     let widget = this._manager.createNew(path, widgetName, kernel);
     let opener = this._opener;
     opener.open(widget);
@@ -348,7 +348,7 @@ namespace Private {
   function createNewItem(widget: FileButtons, creator: IFileCreator): void {
     let fileType = creator.type || 'file';
     let widgetName = creator.widgetName || 'default';
-    let kernel: IKernelId;
+    let kernel: IKernel.IModel;
     if (creator.kernelName) {
       kernel = { name: creator.kernelName };
     }

+ 10 - 10
src/filebrowser/dialogs.ts

@@ -2,7 +2,7 @@
 // Distributed under the terms of the Modified BSD License.
 
 import {
-  ISessionId, IKernelSpecIds, IKernelId
+  IKernel, ISession
 } from 'jupyter-js-services';
 
 import {
@@ -96,7 +96,7 @@ class OpenWithHandler extends Widget {
   /**
    * Construct a new "open with" dialog.
    */
-  constructor(path: string, manager: DocumentManager, sessions: ISessionId[], host?: HTMLElement) {
+  constructor(path: string, manager: DocumentManager, sessions: ISession.IModel[], host?: HTMLElement) {
     super();
     this._manager = manager;
     this._host = host;
@@ -147,9 +147,9 @@ class OpenWithHandler extends Widget {
     let path = this.input.textContent;
     let widgetName = this.widgetDropdown.value;
     let kernelValue = this.kernelDropdown.value;
-    let kernelId: IKernelId;
+    let kernelId: IKernel.IModel;
     if (kernelValue !== 'null') {
-      kernelId = JSON.parse(kernelValue) as IKernelId;
+      kernelId = JSON.parse(kernelValue) as IKernel.IModel;
     }
     return this._manager.open(path, widgetName, kernelId);
   }
@@ -182,7 +182,7 @@ class OpenWithHandler extends Widget {
   private _ext = '';
   private _manager: DocumentManager = null;
   private _host: HTMLElement = null;
-  private _sessions: ISessionId[] = null;
+  private _sessions: ISession.IModel[] = null;
 }
 
 
@@ -209,7 +209,7 @@ class CreateNewHandler extends Widget {
   /**
    * Construct a new "create new" dialog.
    */
-  constructor(model: FileBrowserModel, manager: DocumentManager, sessions: ISessionId[]) {
+  constructor(model: FileBrowserModel, manager: DocumentManager, sessions: ISession.IModel[]) {
     super();
     this._model = model;
     this._manager = manager;
@@ -291,9 +291,9 @@ class CreateNewHandler extends Widget {
     let path = this.input.textContent;
     let widgetName = this.widgetDropdown.value;
     let kernelValue = this.kernelDropdown.value;
-    let kernelId: IKernelId;
+    let kernelId: IKernel.IModel;
     if (kernelValue !== 'null') {
-      kernelId = JSON.parse(kernelValue) as IKernelId;
+      kernelId = JSON.parse(kernelValue) as IKernel.IModel;
     }
     return this._manager.createNew(path, widgetName, kernelId);
   }
@@ -388,7 +388,7 @@ class CreateNewHandler extends Widget {
 
   private _model: FileBrowserModel = null;
   private _manager: DocumentManager = null;
-  private _sessions: ISessionId[] = null;
+  private _sessions: ISession.IModel[] = null;
   private _sentinal = 'UNKNOWN_EXTENSION';
   private _prevExt = '';
   private _extensions: string[] = [];
@@ -398,7 +398,7 @@ class CreateNewHandler extends Widget {
 /**
  * Update a kernel listing based on a kernel preference.
  */
-function updateKernels(preference: IKernelPreference, node: HTMLSelectElement, specs: IKernelSpecIds, running: ISessionId[]): void {
+function updateKernels(preference: IKernelPreference, node: HTMLSelectElement, specs: IKernel.ISpecModels, running: ISession.IModel[]): void {
   if (!preference.canStartKernel) {
     while (node.firstChild) {
       node.removeChild(node.firstChild);

+ 22 - 27
src/filebrowser/model.ts

@@ -2,8 +2,7 @@
 // Distributed under the terms of the Modified BSD License.
 
 import {
-  IContentsManager, IContentsModel, IContentsOpts, INotebookSessionManager,
-  INotebookSession, ISessionId, IKernelSpecIds
+  IContentsManager, IContentsModel, IContentsOpts, IKernel, ISession
 } from 'jupyter-js-services';
 
 import {
@@ -31,7 +30,7 @@ class FileBrowserModel implements IDisposable {
   /**
    * Construct a new file browser view model.
    */
-  constructor(contentsManager: IContentsManager, sessionManager: INotebookSessionManager, specs: IKernelSpecIds) {
+  constructor(contentsManager: IContentsManager, sessionManager: ISession.IManager, specs: IKernel.ISpecModels) {
     this._contentsManager = contentsManager;
     this._sessionManager = sessionManager;
     this._specs = specs;
@@ -94,14 +93,14 @@ class FileBrowserModel implements IDisposable {
    * #### Notes
    * This is a read-only property.
    */
-  get sessionIds(): ISessionId[] {
-    return this._sessionIds.slice();
+  get sessionIds(): ISession.IModel[] {
+    return this._sessions.slice();
   }
 
   /**
    * Get the kernel specs.
    */
-  get kernelspecs(): IKernelSpecIds {
+  get kernelspecs(): IKernel.ISpecModels {
     return this._specs;
   }
 
@@ -346,20 +345,20 @@ class FileBrowserModel implements IDisposable {
   }
 
   /**
-   * Shut down a notebook session by session id.
+   * Shut down a session by session id.
    */
-  shutdown(sessionId: ISessionId): Promise<void> {
+  shutdown(sessionId: ISession.IModel): Promise<void> {
     return this._sessionManager.connectTo(sessionId.id).then(session => {
       return session.shutdown();
     });
   }
 
   /**
-   * Start a new session on a notebook.
+   * Start a new session for a path.
    */
-  startSession(path: string, kernel: string): Promise<INotebookSession> {
+  startSession(path: string, kernel: string): Promise<ISession> {
     return this._sessionManager.startNew({
-      notebookPath: path,
+      path,
       kernelName: kernel
     });
   }
@@ -439,26 +438,22 @@ class FileBrowserModel implements IDisposable {
   }
 
   /**
-   * Get the notebook sessions for the current directory.
+   * Get the sessions for the current directory.
    */
   private _findSessions(): Promise<void> {
-    this._sessionIds = [];
-    let notebooks = this._model.content.filter((content: IContentsModel) => { return content.type === 'notebook'; });
-    if (!notebooks.length) {
-      return Promise.resolve(void 0);
-    }
+    this._sessions = [];
 
-    return this._sessionManager.listRunning().then(sessionIds => {
-      if (!sessionIds.length) {
+    return this._sessionManager.listRunning().then(models => {
+      if (!models.length) {
         return;
       }
-      let paths = notebooks.map((notebook: IContentsModel) => {
-        return notebook.path;
+      let paths = this._model.content.map((contents: IContentsModel) => {
+        return contents.path;
       });
-      for (let sessionId of sessionIds) {
-        let index = paths.indexOf(sessionId.notebook.path);
+      for (let model of models) {
+        let index = paths.indexOf(model.notebook.path);
         if (index !== -1) {
-          this._sessionIds.push(sessionId);
+          this._sessions.push(model);
         }
       }
     });
@@ -466,13 +461,13 @@ class FileBrowserModel implements IDisposable {
 
   private _maxUploadSizeMb = 15;
   private _contentsManager: IContentsManager = null;
-  private _sessionIds: ISessionId[] = [];
-  private _sessionManager: INotebookSessionManager = null;
+  private _sessions: ISession.IModel[] = [];
+  private _sessionManager: ISession.IManager = null;
   private _model: IContentsModel;
   private _sortKey = 'name';
   private _ascending = true;
   private _unsortedNames: string[] = [];
-  private _specs: IKernelSpecIds = null;
+  private _specs: IKernel.ISpecModels = null;
 }
 
 

+ 1 - 1
src/filebrowser/plugin.ts

@@ -50,7 +50,7 @@ const fileBrowserExtension = {
  */
 function activateFileBrowser(app: Application, provider: JupyterServices, registry: DocumentRegistry): Promise<void> {
   let contents = provider.contentsManager;
-  let sessions = provider.notebookSessionManager;
+  let sessions = provider.sessionManager;
   let widgets: DocumentWrapper[] = [];
   let activeWidget: DocumentWrapper;
   let id = 0;

+ 2 - 2
src/imagewidget/widget.ts

@@ -2,7 +2,7 @@
 // Distributed under the terms of the Modified BSD License.
 
 import {
-  IKernelId
+  IKernel
 } from 'jupyter-js-services';
 
 import {
@@ -84,7 +84,7 @@ class ImageWidgetFactory extends ABCWidgetFactory implements IWidgetFactory<Imag
   /**
    * Create a new widget given a context.
    */
-  createNew(context: IDocumentContext<IDocumentModel>, kernel?: IKernelId): ImageWidget {
+  createNew(context: IDocumentContext<IDocumentModel>, kernel?: IKernel.IModel): ImageWidget {
     return new ImageWidget(context);
   }
 }

+ 2 - 2
src/notebook/common/mimetype.ts

@@ -7,7 +7,7 @@ import * as CodeMirror
 import 'codemirror/mode/meta';
 
 import {
-  IKernelLanguageInfo
+  KernelMessage
 } from 'jupyter-js-services';
 
 
@@ -15,7 +15,7 @@ import {
  * Get the appropriate codemirror mimetype given language info.
  */
 export
-function mimetypeForLanguage(info: IKernelLanguageInfo): string {
+function mimetypeForLanguage(info: KernelMessage.ILanguageInfo): string {
   // Use the codemirror mode if given since some kernels rely on it.
   let mode = info.codemirror_mode;
   let mime = 'text/plain';

+ 4 - 3
src/notebook/completion/model.ts

@@ -2,7 +2,7 @@
 // Distributed under the terms of the Modified BSD License.
 
 import {
-  IKernel
+  IKernel, KernelMessage
 } from 'jupyter-js-services';
 
 import {
@@ -251,13 +251,14 @@ class CompletionModel implements ICompletionModel {
    * Make a request using a kernel.
    */
   makeKernelRequest(request: ICompletionRequest, kernel: IKernel): void {
-    let contents = {
+    let content: KernelMessage.ICompleteRequest = {
       // Only send the current line of code for completion.
       code: request.currentValue.split('\n')[request.line],
       cursor_pos: request.ch
     };
     let pendingComplete = ++this._pendingComplete;
-    kernel.complete(contents).then(value => {
+    kernel.complete(content).then(msg => {
+      let value = msg.content;
       // If we have been disposed, bail.
       if (this.isDisposed) {
         return;

+ 5 - 26
src/notebook/notebook/default-toolbar.ts

@@ -2,7 +2,7 @@
 // Distributed under the terms of the Modified BSD License.
 
 import {
-  IKernel, KernelStatus
+  IKernel
 } from 'jupyter-js-services';
 
 import {
@@ -354,30 +354,9 @@ class KernelIndicator extends Widget {
   /**
    * Handle a status on a kernel.
    */
-  private _handleStatus(kernel: IKernel, status: KernelStatus) {
-    this.toggleClass(TOOLBAR_BUSY, status !== KernelStatus.Idle);
-    switch (status) {
-    case KernelStatus.Idle:
-      this.node.title = 'Kernel Idle';
-      break;
-    case KernelStatus.Busy:
-      this.node.title = 'Kernel Busy';
-      break;
-    case KernelStatus.Dead:
-      this.node.title = 'Kernel Died';
-      break;
-    case KernelStatus.Reconnecting:
-      this.node.title = 'Kernel Reconnecting';
-      break;
-    case KernelStatus.Restarting:
-      this.node.title = 'Kernel Restarting';
-      break;
-    case KernelStatus.Starting:
-      this.node.title = 'Kernel Starting';
-      break;
-    default:
-      this.node.title = 'Kernel Status Unknown';
-      break;
-    }
+  private _handleStatus(kernel: IKernel, status: IKernel.Status) {
+    this.toggleClass(TOOLBAR_BUSY, status !== 'idle');
+    let title = 'Kernel ' + status[0].toUpperCase() + status.slice(1);
+    this.node.title = title;
   }
 }

+ 0 - 1
src/notebook/notebook/nbformat.ts

@@ -5,7 +5,6 @@
 // https://nbformat.readthedocs.org/en/latest/format_description.html
 // https://github.com/jupyter/nbformat/blob/master/nbformat/v4/nbformat.v4.schema.json
 
-
 /**
  * A namespace for nbformat interfaces.
  */

+ 2 - 2
src/notebook/notebook/panel.ts

@@ -290,9 +290,9 @@ class NotebookPanel extends Widget {
     if (!this.model) {
       return;
     }
-    kernel.kernelInfo().then(info => {
+    kernel.kernelInfo().then(msg => {
       let infoCursor = this.model.getMetadata('language_info');
-      infoCursor.setValue(info.language_info);
+      infoCursor.setValue(msg.content.language_info);
     });
     kernel.getKernelSpec().then(spec => {
       let specCursor = this.model.getMetadata('kernelspec');

+ 2 - 2
src/notebook/notebook/widget.ts

@@ -2,7 +2,7 @@
 // Distributed under the terms of the Modified BSD License.
 
 import {
-  IKernelLanguageInfo
+  KernelMessage
 } from 'jupyter-js-services';
 
 import {
@@ -526,7 +526,7 @@ namespace StaticNotebook {
     getCodeMimetype(model: INotebookModel): string {
       let cursor = model.getMetadata('language_info');
       let info = cursor.getValue() as nbformat.ILanguageInfoMetadata;
-      return mimetypeForLanguage(info as IKernelLanguageInfo);
+      return mimetypeForLanguage(info as KernelMessage.ILanguageInfo);
     }
   }
 

+ 2 - 2
src/notebook/notebook/widgetfactory.ts

@@ -2,7 +2,7 @@
 // Distributed under the terms of the Modified BSD License.
 
 import {
-  IKernelId
+  IKernel
 } from 'jupyter-js-services';
 
 import {
@@ -76,7 +76,7 @@ class NotebookWidgetFactory implements IWidgetFactory<NotebookPanel, INotebookMo
    * The factory will start the appropriate kernel and populate
    * the default toolbar items using `ToolbarItems.populateDefaults`.
    */
-  createNew(context: IDocumentContext<INotebookModel>, kernel?: IKernelId): NotebookPanel {
+  createNew(context: IDocumentContext<INotebookModel>, kernel?: IKernel.IModel): NotebookPanel {
     let rendermime = this._rendermime.clone();
     let model = context.model;
     if (kernel) {

+ 13 - 14
src/notebook/output-area/model.ts

@@ -2,7 +2,7 @@
 // Distributed under the terms of the Modified BSD License.
 
 import {
-  IKernel, IExecuteReply
+  IKernel, KernelMessage
 } from 'jupyter-js-services';
 
 import {
@@ -161,27 +161,26 @@ class OutputAreaModel implements IDisposable {
  * Execute code on a kernel and send outputs to an output area model.
  */
 export
-function executeCode(code: string, kernel: IKernel, outputs: OutputAreaModel): Promise<any> {
-  let exRequest = {
+function executeCode(code: string, kernel: IKernel, outputs: OutputAreaModel): Promise<KernelMessage.IExecuteReplyMsg> {
+  // Override the default for `stop_on_error`.
+  let content: KernelMessage.IExecuteRequest = {
     code,
-    silent: false,
-    store_history: true,
-    stop_on_error: true,
-    allow_stdin: true
+    stop_on_error: true
   };
   outputs.clear();
   return new Promise<any>((resolve, reject) => {
-    let future = kernel.execute(exRequest);
-    future.onIOPub = (msg => {
-      let model = msg.content;
+    let future = kernel.execute(content);
+    future.onIOPub = ((msg: KernelMessage.IIOPubMessage) => {
+      // TODO: fix when nbformat uses JSON objects
+      let model = msg.content as any;
       if (model !== void 0) {
-        model.output_type = msg.header.msg_type as nbformat.OutputType;
-        outputs.add(model);
+        model.output_type = msg.header.msg_type as any;
+        outputs.add(model as any);
       }
     });
-    future.onReply = (msg => {
+    future.onReply = (msg: KernelMessage.IExecuteReplyMsg) => {
       resolve(msg);
-    });
+    };
   });
 }
 

+ 2 - 2
src/notebook/plugin.ts

@@ -7,7 +7,7 @@ import {
 } from './index';
 
 import {
-  IKernelId
+  IKernel
 } from 'jupyter-js-services';
 
 import {
@@ -173,7 +173,7 @@ class TrackingNotebookWidgetFactory extends NotebookWidgetFactory {
   /**
    * Create a new widget.
    */
-  createNew(context: IDocumentContext<INotebookModel>, kernel?: IKernelId): NotebookPanel {
+  createNew(context: IDocumentContext<INotebookModel>, kernel?: IKernel.IModel): NotebookPanel {
     let widget = super.createNew(context, kernel);
     Private.notebookTracker.activeNotebook = widget;
     return widget;

+ 11 - 11
src/services/plugin.ts

@@ -6,9 +6,9 @@ import {
 } from 'jupyter-js-utils';
 
 import {
-  IKernelManager, INotebookSessionManager, IContentsManager,
-  ContentsManager, KernelManager, NotebookSessionManager,
-  getKernelSpecs, IKernelSpecIds, IAjaxSettings
+  IKernel, ISession, IContentsManager,
+  ContentsManager, KernelManager, SessionManager,
+  getKernelSpecs, IAjaxSettings
 } from 'jupyter-js-services';
 
 
@@ -21,18 +21,18 @@ class JupyterServices {
   /**
    * Construct a new services provider.
    */
-  constructor(baseUrl: string, ajaxSettings: IAjaxSettings, specs: IKernelSpecIds) {
+  constructor(baseUrl: string, ajaxSettings: IAjaxSettings, specs: IKernel.ISpecModels) {
     let options = { baseUrl, ajaxSettings };
     this._kernelspecs = specs;
     this._kernelManager = new KernelManager(options);
-    this._sessionManager = new NotebookSessionManager(options);
+    this._sessionManager = new SessionManager(options);
     this._contentsManager = new ContentsManager(baseUrl, ajaxSettings);
   }
 
   /**
    * Get kernel specs.
    */
-  get kernelspecs(): IKernelSpecIds {
+  get kernelspecs(): IKernel.ISpecModels {
     return this._kernelspecs;
   }
 
@@ -42,7 +42,7 @@ class JupyterServices {
    * #### Notes
    * This is a read-only property.
    */
-  get kernelManager(): IKernelManager {
+  get kernelManager(): IKernel.IManager {
     return this._kernelManager;
   }
 
@@ -52,7 +52,7 @@ class JupyterServices {
    * #### Notes
    * This is a read-only property.
    */
-  get notebookSessionManager(): INotebookSessionManager {
+  get sessionManager(): ISession.IManager {
     return this._sessionManager;
   }
 
@@ -66,10 +66,10 @@ class JupyterServices {
     return this._contentsManager;
   }
 
-  private _kernelManager: IKernelManager = null;
-  private _sessionManager: INotebookSessionManager = null;
+  private _kernelManager: IKernel.IManager = null;
+  private _sessionManager: ISession.IManager = null;
   private _contentsManager: IContentsManager = null;
-  private _kernelspecs: IKernelSpecIds = null;
+  private _kernelspecs: IKernel.ISpecModels = null;
 }
 
 

+ 3 - 3
src/widgets/index.ts

@@ -4,7 +4,7 @@
 import * as Backbone from 'backbone';
 
 import {
-  IKernelIOPubCommOpenMessage, IComm, IKernel
+  IKernel, KernelMessage
 } from 'jupyter-js-services';
 
 import {
@@ -101,7 +101,7 @@ class WidgetManager extends ManagerBase<Widget> implements IDisposable {
   /**
    * Handle when a comm is opened.
    */
-  handle_comm_open(comm: IComm, msg: IKernelIOPubCommOpenMessage) {
+  handle_comm_open(comm: IKernel.IComm, msg: KernelMessage.ICommOpenMsg) {
     // Convert jupyter-js-services comm to old comm
     // so that widget models use it compatibly
     let oldComm = new shims.services.Comm(comm);
@@ -122,7 +122,7 @@ class WidgetManager extends ManagerBase<Widget> implements IDisposable {
    */
   _get_comm_info(): Promise<any> {
     return this._context.kernel.commInfo({target: 'jupyter.widget'}).then((reply) => {
-      return reply.comms;
+      return reply.content.comms;
     })
   }
 

+ 6 - 20
test/src/docmanager/mockcontext.ts

@@ -2,11 +2,11 @@
 // Distributed under the terms of the Modified BSD License.
 
 import {
-  IKernelId, IKernel, IKernelSpecIds, ISessionId, IContentsModel
+  IContentsModel, IKernel, ISession
 } from 'jupyter-js-services';
 
 import {
-  MockKernel
+  MockKernel, KERNELSPECS
 } from 'jupyter-js-services/lib/mockkernel';
 
 import {
@@ -25,10 +25,6 @@ import {
   IDocumentContext, IDocumentModel
 } from '../../../lib/docregistry';
 
-import {
-  KERNELSPECS, getKernelInfo
-} from '../utils';
-
 
 export
 class MockContext<T extends IDocumentModel> implements IDocumentContext<T> {
@@ -69,7 +65,7 @@ class MockContext<T extends IDocumentModel> implements IDocumentContext<T> {
     return void 0;
   }
 
-  get kernelspecs(): IKernelSpecIds {
+  get kernelspecs(): IKernel.ISpecModels {
     return KERNELSPECS;
   }
 
@@ -82,18 +78,8 @@ class MockContext<T extends IDocumentModel> implements IDocumentContext<T> {
     this._model = null;
   }
 
-  changeKernel(options: IKernelId): Promise<IKernel> {
+  changeKernel(options: IKernel.IModel): Promise<IKernel> {
     this._kernel = new MockKernel(options);
-    if (options.name) {
-      let name = options.name;
-      if (!KERNELSPECS.kernelspecs[name]) {
-        name = KERNELSPECS['default'];
-      }
-      let kernel = this._kernel as MockKernel;
-      kernel.setKernelSpec(KERNELSPECS.kernelspecs[name].spec);
-      kernel.setKernelInfo(getKernelInfo(name));
-    }
-
     this.kernelChanged.emit(this._kernel);
     return Promise.resolve(this._kernel);
   }
@@ -112,8 +98,8 @@ class MockContext<T extends IDocumentModel> implements IDocumentContext<T> {
     return Promise.resolve(void 0);
   }
 
-  listSessions(): Promise<ISessionId[]> {
-    return Promise.resolve([] as ISessionId[]);
+  listSessions(): Promise<ISession.IModel[]> {
+    return Promise.resolve([] as ISession.IModel[]);
   }
 
   addSibling(widget: Widget): IDisposable {

+ 2 - 2
test/src/docregistry/default.spec.ts

@@ -4,7 +4,7 @@
 import expect = require('expect.js');
 
 import {
-  IKernelId
+  IKernel
 } from 'jupyter-js-services';
 
 import {
@@ -23,7 +23,7 @@ import {
 
 class WidgetFactory extends ABCWidgetFactory {
 
-  createNew(context: IDocumentContext<IDocumentModel>, kernel?: IKernelId): Widget {
+  createNew(context: IDocumentContext<IDocumentModel>, kernel?: IKernel.IModel): Widget {
     return new Widget();
   }
 }

+ 2 - 5
test/src/notebook/notebook/actions.spec.ts

@@ -8,7 +8,7 @@ import {
 } from 'jupyter-js-services';
 
 import {
-  MockKernel
+  MockKernel, KERNELSPECS
 } from 'jupyter-js-services/lib/mockkernel';
 
 import {
@@ -36,7 +36,7 @@ import {
 } from '../../rendermime/rendermime.spec';
 
 import {
-  acceptDialog, dismissDialog, KERNELSPECS, getKernelInfo
+  acceptDialog, dismissDialog
 } from '../../utils';
 
 import {
@@ -61,9 +61,6 @@ describe('notebook/notebook/actions', () => {
       widget.model = model;
 
       kernel = new MockKernel({ name: 'python' });
-      (kernel as MockKernel).setKernelInfo(getKernelInfo('python'));
-      let spec = KERNELSPECS.kernelspecs['python'].spec;
-      (kernel as MockKernel).setKernelSpec(spec);
       widget.activeCellIndex = 0;
     });
 

+ 0 - 72
test/src/utils.ts

@@ -1,83 +1,11 @@
 // Copyright (c) Jupyter Development Team.
 // Distributed under the terms of the Modified BSD License.
 
-import {
-  IKernelSpecIds, IKernelLanguageInfo, IKernelInfo
-} from 'jupyter-js-services';
-
 import {
   simulate
 } from 'simulate-event';
 
 
-/**
- * The default kernel spec ids.
- */
-export
-const KERNELSPECS: IKernelSpecIds = {
-  default: 'python',
-  kernelspecs: {
-    python: {
-      name: 'python',
-      spec: {
-        language: 'python',
-        argv: [],
-        display_name: 'Python',
-        env: {}
-      },
-      resources: {}
-    },
-    shell: {
-      name: 'shell',
-      spec: {
-        language: 'shell',
-        argv: [],
-        display_name: 'Shell',
-        env: {}
-      },
-      resources: {}
-    }
-  }
-};
-
-/**
- * The default language infos.
- */
-export
-function getKernelInfo(name: string): IKernelInfo {
-  return {
-    protocol_version: '1',
-    implementation: 'foo',
-    implementation_version: '1',
-    language_info: LANGUAGE_INFOS[name],
-    banner: 'Hello',
-    help_links: {}
-  };
-}
-
-
-const LANGUAGE_INFOS: { [key: string]: IKernelLanguageInfo } = {
-  python: {
-    name: 'python',
-    version: '1',
-    mimetype: 'text/x-python',
-    file_extension: '.py',
-    pygments_lexer: 'python',
-    codemirror_mode: 'python',
-    nbconverter_exporter: ''
-  },
-  shell: {
-    name: 'shell',
-    version: '1',
-    mimetype: 'text/x-sh',
-    file_extension: '.sh',
-    pygments_lexer: 'shell',
-    codemirror_mode: 'shell',
-    nbconverter_exporter: ''
-  }
-};
-
-
 /**
  * Wait for a dialog to be attached to an element.
  */

+ 1 - 0
typings/codemirror/codemirror.d.ts

@@ -16,6 +16,7 @@ declare module CodeMirror {
 
     // findMode* functions are from loading the codemirror/mode/meta module
     interface modespec {
+      [ key: string ]: string;
       name: string;
       mode: string;
       mime: string;

+ 3 - 3
typings/jupyter-js-widgets/jupyter-js-widgets.d.ts

@@ -8,9 +8,9 @@ declare module "jupyter-js-widgets" {
   import * as services from 'jupyter-js-services';
 
   export class ManagerBase<T> {
-    display_view(msg: services.IKernelMessage, view: Backbone.View<Backbone.Model>, options: any): T;
-    handle_comm_open(comm: shims.services.Comm, msg: services.IKernelIOPubCommOpenMessage): Promise<Backbone.Model>;
-    display_model(msg: services.IKernelMessage, model: Backbone.Model, options: any): Promise<T>;
+    display_view(msg: services.KernelMessage.IMessage, view: Backbone.View<Backbone.Model>, options: any): T;
+    handle_comm_open(comm: shims.services.Comm, msg: services.KernelMessage.ICommOpenMsg): Promise<Backbone.Model>;
+    display_model(msg: services.KernelMessage.IMessage, model: Backbone.Model, options: any): Promise<T>;
     get_model(id: string): Promise<Backbone.Model>;
     validateVersion(): Promise<boolean>;
     comm_target_name: string;