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

import {
  JupyterFrontEnd,
  JupyterFrontEndPlugin
} from '@jupyterlab/application';

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

import {
  CodeConsole,
  ConsolePanel,
  IConsoleTracker,
  ForeignHandler
} from '@jupyterlab/console';

import { AttachedProperty } from '@lumino/properties';

import { ReadonlyPartialJSONObject } from '@lumino/coreutils';

/**
 * The console widget tracker provider.
 */
export const foreign: JupyterFrontEndPlugin<void> = {
  id: '@jupyterlab/console-extension:foreign',
  requires: [IConsoleTracker],
  optional: [ICommandPalette],
  activate: activateForeign,
  autoStart: true
};

export default foreign;

function activateForeign(
  app: JupyterFrontEnd,
  tracker: IConsoleTracker,
  palette: ICommandPalette | null
) {
  const { shell } = app;
  tracker.widgetAdded.connect((sender, widget) => {
    const console = widget.console;

    const handler = new ForeignHandler({
      sessionContext: console.sessionContext,
      parent: console
    });
    Private.foreignHandlerProperty.set(console, handler);<commit_msg>use new setting registry value to set handler enabled on startup<commit_after>// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.

import {
  JupyterFrontEnd,
  JupyterFrontEndPlugin
} from '@jupyterlab/application';

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

import {
  CodeConsole,
  ConsolePanel,
  IConsoleTracker,
  ForeignHandler
} from '@jupyterlab/console';

import { ISettingRegistry } from '@jupyterlab/settingregistry';

import { AttachedProperty } from '@lumino/properties';

import { ReadonlyPartialJSONObject } from '@lumino/coreutils';

/**
 * The console widget tracker provider.
 */
export const foreign: JupyterFrontEndPlugin<void> = {
  id: '@jupyterlab/console-extension:foreign',
  requires: [IConsoleTracker, ISettingRegistry],
  optional: [ICommandPalette],
  activate: activateForeign,
  autoStart: true
};

export default foreign;

function activateForeign(
  app: JupyterFrontEnd,
  tracker: IConsoleTracker,
  settingRegistry: ISettingRegistry,
  palette: ICommandPalette | null
) {
  const { shell } = app;
  tracker.widgetAdded.connect((sender, widget) => {
    const console = widget.console;

    const handler = new ForeignHandler({
      sessionContext: console.sessionContext,
      parent: console
    });
    Private.foreignHandlerProperty.set(console, handler);

    settingRegistry
      .get('@jupyterlab/console-extension:tracker', 'kernelActivity')
      .then(({ composite }) => {
        let kernelActivity = composite as string;
        handler.enabled = kernelActivity === 'all';
      });

{'fraction_non_alphanumeric': 0.10522548317823908, 'fraction_numerical': 0.0, 'mean_word_length': 4.534653465346534, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 8, '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': '5383519', 'n_tokens_mistral': 839, 'n_tokens_neox': 825, 'n_words': 205}