<commit_before>// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.

import {
  JupyterLab, JupyterLabPlugin
} from '@jupyterlab/application';

import {
  ICommandPalette, ILayoutRestorer
} from '@jupyterlab/apputils';

import {
  IDocumentManager
} from '@jupyterlab/docmanager';

import {
  IEditorServices
} from '@jupyterlab/codeeditor';

import {
  ChatboxPanel
} from '@jupyterlab/chatbox';

import {
  IRenderMime
} from '@jupyterlab/rendermime';


/**
 * The command IDs used by the chatbox plugin.
 */
namespace CommandIDs {
  export
  const create = 'chatbox:create';

  export
  const clear = 'chatbox:clear';

  export
  const run = 'chatbox:post';

  export
  const linebreak = 'chatbox:linebreak';
};

/**
 * The chatbox widget content factory.
 */
export
const chatboxPlugin: JupyterLabPlugin<void> = {
  id: 'jupyter.extensions.chatbox',
  requires: [IRenderMime, ICommandPalette, IEditorServices, IDocumentManager, ILayoutRestorer],
  autoStart: true,
  activate: activateChatbox
}


/**
 * Export the plugin as the default.
 */
export default chatboxPlugin;


/**
 * Activate the chatbox extension.
 */
function activateChatbox(app: JupyterLab, rendermime: IRenderMime, palette: ICommandPalette, editorServices: IEditorServices, docManager: IDocumentManager, restorer: ILayoutRestorer): void {
  let { commands, shell } = app;
  let category = 'Chatbox';
  let command: string;

  /**
   * Create a chatbox for a given path.
   */
  let editorFactory = editorServices.factoryService.newInlineEditor.bind(
    editorServices.factoryService);
  let contentFactory = new ChatboxPanel.ContentFactory({ editorFactory });
  let panel = new ChatboxPanel({
    rendermime: rendermime.clone(),
    contentFactory,
    mimeTypeService: editorServices.mimeTypeService
  });

  // Add the chatbox panel to the tracker.
  panel.title.label = 'Chat';
  shell.addToLeftArea(panel);


  command = CommandIDs.clear;
  commands.addCommand(command, {
    label: 'Clear Chat',
    execute: args => {
      panel.chatbox.clear();
    }
  });
  palette.addItem({ command, category });

  command = CommandIDs.run;
  commands.addCommand(command, {
    label: 'Post Chat Entry',
    execute: args => {
      return panel.chatbox.post();
    }
  });
  palette.addItem({ command, category });

  let updateDocumentModel = function (): void {
    let context = docManager.contextForWidget(shell.currentWidget);
    if (context && context.model !== panel.chatbox.model) {
      panel.chatbox.model = context.model;
    }
  }
  shell.currentChanged.connect(updateDocumentModel);
}<commit_msg>Add layout restoration to chatbox.<commit_after>// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.

import {
  JupyterLab, JupyterLabPlugin
} from '@jupyterlab/application';

import {
  ICommandPalette, ILayoutRestorer
} from '@jupyterlab/apputils';

import {
  IDocumentManager
} from '@jupyterlab/docmanager';

import {
  IEditorServices
} from '@jupyterlab/codeeditor';

import {
  ChatboxPanel
} from '@jupyterlab/chatbox';

import {
  IRenderMime
} from '@jupyterlab/rendermime';


/**
 * The command IDs used by the chatbox plugin.
 */
namespace CommandIDs {
  export
  const create = 'chatbox:create';

  export
  const clear = 'chatbox:clear';

  export
  const run = 'chatbox:post';

  export
  const linebreak = 'chatbox:linebreak';
};

/**
 * The chatbox widget content factory.
 */
export
const chatboxPlugin: JupyterLabPlugin<void> = {
  id: 'jupyter.extensions.chatbox',
  requires: [IRenderMime, ICommandPalette, IEditorServices, IDocumentManager, ILayoutRestorer],
  autoStart: true,
  activate: activateChatbox
}


/**
 * Export the plugin as the default.
 */
export default chatboxPlugin;


/**
 * Activate the chatbox extension.
 */
function activateChatbox(app: JupyterLab, rendermime: IRenderMime, palette: ICommandPalette, editorServices: IEditorServices, docManager: IDocumentManager, restorer: ILayoutRestorer): void {
  const id = 'chatbox';
  let { commands, shell } = app;
  let category = 'Chatbox';
  let command: string;

  /**
   * Create a chatbox for a given path.
   */
  let editorFactory = editorServices.factoryService.newInlineEditor.bind(
    editorServices.factoryService);
  let contentFactory = new ChatboxPanel.ContentFactory({ editorFactory });
  let panel = new ChatboxPanel({
    rendermime: rendermime.clone(),
    contentFactory,
    mimeTypeService: editorServices.mimeTypeService
  });

  // Add the chatbox panel to the tracker.
  panel.title.label = 'Chat';
  panel.id = id;

  restorer.add(panel, 'chatbox');

  command = CommandIDs.clear;
  commands.addCommand(command, {
    label: 'Clear Chat',
    execute: args => {
      panel.chatbox.clear();
    }
  });
  palette.addItem({ command, category });

  command = CommandIDs.run;
  commands.addCommand(command, {
    label: 'Post Chat Entry',
    execute: args => {
      return panel.chatbox.post();
    }
  });
  palette.addItem({ command, category });

  let updateDocumentModel = function (): void {
    let context = docManager.contextForWidget(shell.currentWidget);
    if (context && context.model !== panel.chatbox.model) {
      if(!panel.isAttached) {
        shell.addToLeftArea(panel);
      }
      panel.chatbox.model = context.model;
    }
  }

  app.restored.then(() => {
    updateDocumentModel();
  });
  shell.currentChanged.connect(updateDocumentModel);
}
{'fraction_non_alphanumeric': 0.11694729136163982, 'fraction_numerical': 0.0, 'mean_word_length': 3.954669084315503, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7645657', 'n_tokens_mistral': 1745, 'n_tokens_neox': 1688, 'n_words': 414}