<commit_before>import { RecursiveProxyHandler } from 'electron-remote';
import { Observable } from 'rxjs/Observable';
import { Subject } from 'rxjs/Subject';

import { ChannelBase } from './api-shapes';

import '../standard-operators';

import 'rxjs/add/observable/dom/ajax';

export interface ApiCall {
  ok: boolean;
  error?: string;
}

export type Api = any;

export function createApi(token?: string): Api {
  const defaultParams: {token?: string} = token ? {token} : {};
  let socket: Subject<any>;
  let nextSendId = 1;

  return RecursiveProxyHandler.create('api', (names: Array<string>, params: Array<any>) => {
    if (names.length === 2 && names[1] === 'duplicate') return createApi(defaultParams.token);
    if (names.length === 2 && names[1] === 'token') return defaultParams.token;
    if (names.length === 2 && names[1] === 'setSocket') {
      socket = params[0];
      return null;
    }
    if (names.length === 2 && names[1] === 'send') {
      let toSend = params[0];
      nextSendId++;

      let currentId = nextSendId;
      let ret = socket
        .filter(x => x.reply_to === currentId)
        .flatMap(x => {
          if (x.ok) return Observable.of(x);
          return Observable.throw(new Error(`Error ${x.error.code} - ${x.error.message}`));
        })
        .take(1)
        .publishLast();

      ret.connect();

      socket.next(JSON.stringify(Object.assign({ id: nextSendId } , toSend)));
      return ret;
    }

    if (names.length === 2 && names[1] === 'recieve') {<commit_msg>I before E, except after C<commit_after>import { RecursiveProxyHandler } from 'electron-remote';
import { Observable } from 'rxjs/Observable';
import { Subject } from 'rxjs/Subject';

import { ChannelBase } from './api-shapes';

import '../standard-operators';

import 'rxjs/add/observable/dom/ajax';

export interface ApiCall {
  ok: boolean;
  error?: string;
}

export type Api = any;

export function createApi(token?: string): Api {
  const defaultParams: {token?: string} = token ? {token} : {};
  let socket: Subject<any>;
  let nextSendId = 1;

  return RecursiveProxyHandler.create('api', (names: Array<string>, params: Array<any>) => {
    if (names.length === 2 && names[1] === 'duplicate') return createApi(defaultParams.token);
    if (names.length === 2 && names[1] === 'token') return defaultParams.token;
    if (names.length === 2 && names[1] === 'setSocket') {
      socket = params[0];
      return null;
    }
    if (names.length === 2 && names[1] === 'send') {
      let toSend = params[0];
      nextSendId++;

      let currentId = nextSendId;
      let ret = socket
        .filter(x => x.reply_to === currentId)
        .flatMap(x => {
          if (x.ok) return Observable.of(x);
          return Observable.throw(new Error(`Error ${x.error.code} - ${x.error.message}`));
        })
        .take(1)
        .publishLast();

      ret.connect();

      socket.next(JSON.stringify(Object.assign({ id: nextSendId } , toSend)));
      return ret;
    }

    if (names.length === 2 && names[1] === 'receive') {
{'fraction_non_alphanumeric': 0.17261709793645594, 'fraction_numerical': 0.00917130691123485, 'mean_word_length': 3.0611702127659575, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 15, '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': '331495', 'n_tokens_mistral': 977, 'n_tokens_neox': 959, 'n_words': 243}