<commit_before>import Context from './Context'

/**
 * A HTTP client for a remote `Context`
 *
 * Implements the `Context` API by remote procedure calls (RPC) to a remote
 * context (e.g. a `RContext` running in a different process)
 *
 * @extends Context
 */
export default class ContextHttpClient extends Context {

  constructor(host, url, name) {
    super()
    this._host = host
    this._peer = url
    this._name = name
  }

  /**
   * Get a list of libraries
   */
  libraries () {
    return this._host._put(this._peer, '/' + this._name + '!libraries')
  }

  /**
   * Analyse code
   *
   * @override
   */
  _analyseCode (code, exprOnly = false) {
    let pre = {
      type: 'cell',
      source: {
        type: 'text',
        data: code
      },
      expr: exprOnly
    }
    return this._host._put(this._peer, '/' + this._name + '!compile', pre).then(post => {
      return {
        inputs: post.inputs && post.inputs.map(input => input.name),
        output: post.outputs && post.outputs[0] && post.outputs[0].name,
        messages: post.messages
      }      
    })
  }

  /**
   * Execute code
   *
   * @override
   */
  _executeCode (code, inputs, exprOnly = false) {
    let pre = {
      type: 'cell',
      source: {
        type: 'text',
        data: code
      },
      expr: exprOnly,
      inputs: Object.entries(inputs).map(([name, value]) => {
        return {name, value}
      })
    }
    return this._host._put(this._peer, '/' + this._name + '!execute', pre).then(post => {
      let output = post.outputs && post.outputs[0] && post.outputs[0].name
      let value = post.outputs && post.outputs[0] && post.outputs[0].value
      if (value) {
        if (value.type === 'library') {
          this._host._functionManager.importLibrary(this, value)
        } else if (value.type === 'function') {
          this._host._functionManager.importFunction(this, value)
          value = { type: 'object', data: value }
        }
      }
      return {
        inputs: post.inputs && post.inputs.map(input => input.name),
        output: output,
        value: value,
        messages: post.messages
      }
    })
  }

  callFunction (library, name, args, namedArgs) {
    let call = {
      type: 'call',
      func: {type: 'get', name: name},<commit_msg>Don't pack function (should be done by the execution context)<commit_after>import Context from './Context'

/**
 * A HTTP client for a remote `Context`
 *
 * Implements the `Context` API by remote procedure calls (RPC) to a remote
 * context (e.g. a `RContext` running in a different process)
 *
 * @extends Context
 */
export default class ContextHttpClient extends Context {

  constructor(host, url, name) {
    super()
    this._host = host
    this._peer = url
    this._name = name
  }

  /**
   * Get a list of libraries
   */
  libraries () {
    return this._host._put(this._peer, '/' + this._name + '!libraries')
  }

  /**
   * Analyse code
   *
   * @override
   */
  _analyseCode (code, exprOnly = false) {
    let pre = {
      type: 'cell',
      source: {
        type: 'text',
        data: code
      },
      expr: exprOnly
    }
    return this._host._put(this._peer, '/' + this._name + '!compile', pre).then(post => {
      return {
        inputs: post.inputs && post.inputs.map(input => input.name),
        output: post.outputs && post.outputs[0] && post.outputs[0].name,
        messages: post.messages
      }      
    })
  }

  /**
   * Execute code
   *
   * @override
   */
  _executeCode (code, inputs, exprOnly = false) {
    let pre = {
      type: 'cell',
      source: {
        type: 'text',
        data: code
      },
      expr: exprOnly,
      inputs: Object.entries(inputs).map(([name, value]) => {
        return {name, value}
      })
    }
    return this._host._put(this._peer, '/' + this._name + '!execute', pre).then(post => {
      let output = post.outputs && post.outputs[0] && post.outputs[0].name
      let value = post.outputs && post.outputs[0] && post.outputs[0].value
      if (value) {
        if (value.type === 'library') {
          this._host._functionManager.importLibrary(this, value)
        } else if (value.type === 'function') {
          this._host._functionManager.importFunction(this, value)
        }
      }
      return {
        inputs: post.inputs && post.inputs.map(input => input.name),
        output: output,
        value: value,
        messages: post.messages
      }
    })
  }

  callFunction (library, name, args, namedArgs) {
    let call = {
      type: 'call',
      func: {type: 'get', name: name},
{'fraction_non_alphanumeric': 0.14881993006993008, 'fraction_numerical': 0.0026223776223776225, 'mean_word_length': 2.1392318244170094, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '4803233', 'n_tokens_mistral': 1434, 'n_tokens_neox': 1421, 'n_words': 357}