<commit_before>class KodingKite_KlientKite extends KodingKite

  @constructors['klient'] = this

  @createApiMapping

    exec               : 'exec'
    ping               : 'kite.ping'

    fsReadDirectory    : 'fs.readDirectory'
    fsGlob             : 'fs.glob'
    fsReadFile         : 'fs.readFile'
    fsGetInfo          : 'fs.getInfo'
    fsSetPermissions   : 'fs.setPermissions'
    fsRemove           : 'fs.remove'

    fsUniquePath       : 'fs.uniquePath'
    fsWriteFile        : 'fs.writeFile'
    fsRename           : 'fs.rename'
    fsMove             : 'fs.move'
    fsCreateDirectory  : 'fs.createDirectory'

    webtermGetSessions : 'webterm.getSessions'
    webtermPing        : 'webterm.ping'

    klientShare        : 'klient.share'
    klientUnshare      : 'klient.unshare'
    klientShared       : 'klient.shared'


  constructor:->

    super

    @terminalSessions = []


  init: ->

    @connect()

    unless @terminalSessions.length
      @fetchTerminalSessions()

    Promise.resolve()


  # setTransport is used to override the setTransport method in KodingKite
  # prior to connection so we can have a custom URL. This is used so Klient
  # Kite can go over our internal userproxy
  setTransport: (@transport) ->

    {url} = @transport.options
    @transport.options.url = KD.utils.proxifyTransportUrl url

    # now call @connect in super, which will connect to our new URL
    super @transport


  disconnect: ->
    super

    KD.singletons.kontrol.kites?.klient?[@getOption 'correlationName'] = null


  webtermConnect: (options)->

    @tell 'webterm.connect', options

      .then (remote) =>

        unless remote.session in @terminalSessions
          @terminalSessions.push remote.session

        return remote


  webtermKillSession: (options)->

    {session} = options

    @tell 'webterm.killSession', options

      .then (state) =>

        @terminalSessions = @terminalSessions.filter (currentSession)->
          session isnt currentSession

        return state


  fetchTerminalSessions: ->

    @webtermGetSessions()

    .then (sessions)=>

      @terminalSessions = sessions

    .catch (err)=>
      # Reset current sessions if fails
      @terminalSessions = []
<commit_msg>Klient: add webtermKillSessions helper for webterm.killSessions method<commit_after>class KodingKite_KlientKite extends KodingKite

  @constructors['klient'] = this

  @createApiMapping

    exec               : 'exec'
    ping               : 'kite.ping'

    fsReadDirectory    : 'fs.readDirectory'
    fsGlob             : 'fs.glob'
    fsReadFile         : 'fs.readFile'
    fsGetInfo          : 'fs.getInfo'
    fsSetPermissions   : 'fs.setPermissions'
    fsRemove           : 'fs.remove'

    fsUniquePath       : 'fs.uniquePath'
    fsWriteFile        : 'fs.writeFile'
    fsRename           : 'fs.rename'
    fsMove             : 'fs.move'
    fsCreateDirectory  : 'fs.createDirectory'

    webtermKillSessions: 'webterm.killSessions'
    webtermGetSessions : 'webterm.getSessions'
    webtermPing        : 'webterm.ping'

    klientShare        : 'klient.share'
    klientUnshare      : 'klient.unshare'
    klientShared       : 'klient.shared'


  constructor:->

    super

    @terminalSessions = []


  init: ->

    @connect()

    unless @terminalSessions.length
      @fetchTerminalSessions()

    Promise.resolve()


  # setTransport is used to override the setTransport method in KodingKite
  # prior to connection so we can have a custom URL. This is used so Klient
  # Kite can go over our internal userproxy
  setTransport: (@transport) ->

    {url} = @transport.options
    @transport.options.url = KD.utils.proxifyTransportUrl url

    # now call @connect in super, which will connect to our new URL
    super @transport


  disconnect: ->
    super

    KD.singletons.kontrol.kites?.klient?[@getOption 'correlationName'] = null


  webtermConnect: (options)->

    @tell 'webterm.connect', options

      .then (remote) =>

        unless remote.session in @terminalSessions
          @terminalSessions.push remote.session

        return remote


  webtermKillSession: (options)->

    {session} = options

    @tell 'webterm.killSession', options

      .then (state) =>

        @terminalSessions = @terminalSessions.filter (currentSession)->
          session isnt currentSession

        return state


  fetchTerminalSessions: ->

    @webtermGetSessions()

    .then (sessions)=>

      @terminalSessions = sessions

    .catch (err)=>
      # Reset current sessions if fails
      @terminalSessions = []

{'fraction_non_alphanumeric': 0.09363377816670312, 'fraction_numerical': 0.0, 'mean_word_length': 2.374169741697417, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3501502', 'n_tokens_mistral': 1437, 'n_tokens_neox': 1319, 'n_words': 320}