src/kit.js
/**
 * Generate a craft ai agent configuration
 *
 * @param {String} log
 * @param {Array<Provider>} providers Array of providers that have as function extendConfiguration
 * @param {Object} [learning={}] [OPTIONAL] Object that contains parameters of the configuration. Can contain:
 *  - maxTreeDepth: positive integer, define the max depth of the decision tree. Default is 6.
 *  - maxRecords: positive integer, maximum number of events on which a single decision tree can be based. Default is 50000.
 *  - maxRecordAge: positive integer, the maximum amount of time, in seconds, that matters for an agent. Default is one year.
 *  - properties: object, context properties to add to {time: { type: 'time_of_day' }, day: { type: 'day_of_week' },
 *    month: { type: 'month_of_year' }, timezone: { type: 'timezone' }, load: { type: 'continuous' }}
 *  - advancedConfiguration: Object, advanced configuration options. Default is {}
 * @returns {Object} craft ai agent configuration
 */
Generate a craft ai agent configuration
@param {String} log
@param {Array} providers Array of providers that have as function extendConfiguration
@param {Object} [learning={}] [OPTIONAL] Object that contains parameters of the configuration. Can contain:
- maxTreeDepth: positive integer, define the max depth of the decision tree. Default is 6.
- maxRecords: positive integer, maximum number of events on which a single decision tree can be based.
Generate a craft ai agent configuration @param { String } log @param { Array } providers Array of providers that have as function extendConfiguration @param { Object } [ learning = {} ] [ OPTIONAL ] Object that contains parameters of the configuration . Can contain : - maxTreeDepth : positive integer define the max depth of the decision tree . Default is 6 . - maxRecords : positive integer maximum number of events on which a single decision tree can be based .
async function generateAgentConfiguration(log, providers, learning = {}) {
  log('generating the agent\'s configuration');
  if (learning === null || typeof learning !== 'object') {
    throw new TypeError(`The "learning" property of the endpoint's definition must be an "object". Received "${ learning === null ? 'null' : typeof learning }".`);
  }
  const maxTreeDepth = learning.maxTreeDepth;
  if (maxTreeDepth !== undefined && typeof maxTreeDepth !== 'number') {
    throw new TypeError(`The "maxTreeDepth" property of the endpoint's learning definition must be a "number". Received "${maxTreeDepth === null ? 'null' : typeof maxTreeDepth}".`);
  }
  const maxRecords = learning.maxRecords;
  if (maxRecords !== undefined && typeof maxRecords !== 'number') {
    throw new TypeError(`The "maxRecords" property of the endpoint's learning definition must be a "number". Received "${maxRecords === null ? 'null' : typeof maxRecords}".`);
  }
  const maxRecordAge = learning.maxRecordAge;
  if (maxRecordAge !== undefined && typeof maxRecordAge !== 'number') {
    throw new TypeError(`The "maxRecordAge" property of the endpoint's learning definition must be a "number". Received "${maxRecordAge === null ? 'null' : typeof maxRecordAge}".`);
  }
  const properties = learning.properties;
  if (properties !== undefined && (properties === null || typeof properties !== 'object')) {
    throw new TypeError(`The "properties" property of the endpoint's learning definition must be an "object". Received "${properties === null ? 'null' : typeof properties}".`);
  }
  const advancedConfiguration = learning.advancedConfiguration;
  if (advancedConfiguration !== undefined && (advancedConfiguration === null || typeof advancedConfiguration !== 'object')) {
    throw new TypeError(`The "options" property of the endpoint's learning definition must be an "object". Received "${advancedConfiguration === null ? 'null' : typeof advancedConfiguration}".`);
  }
  return Provider.extendConfiguration(providers, {
    time: { type: 'time_of_day' },
    day: { type: 'day_of_week' },
    month: { type: 'month_of_year' },
    ...properties,
    [TIMEZONE]: { type: 'timezone' },
    [LOAD]: { type: 'continuous' }
  })
    .then((context) => {
      return {
        context,
        output: ['load'],
        operations_as_events: true,
        tree_max_depth: maxTreeDepth || 6,
        tree_max_operations: maxRecords || 50000,
        learning_period: maxRecordAge || 365 * 24 * 60 * 60,
        ...advancedConfiguration
      };
    });
}
async function generateAgentConfiguration ( log , providers , learning = { } ) { log ( 'generating the agent\'s configuration' ) ; if ( learning === null || typeof learning !== 'object' ) { throw new TypeError ( ` ${ learning === null ? 'null' : typeof learning } ` ) ; } const maxTreeDepth = learning . maxTreeDepth ; if ( maxTreeDepth !== undefined && typeof maxTreeDepth !== 'number' ) { throw new TypeError ( ` ${ maxTreeDepth === null ? 'null' : typeof maxTreeDepth } ` ) ; } const maxRecords = learning . maxRecords ; if ( maxRecords !== undefined && typeof maxRecords !== 'number' ) { throw new TypeError ( ` ${ maxRecords === null ? 'null' : typeof maxRecords } ` ) ; } const maxRecordAge = learning . maxRecordAge ; if ( maxRecordAge !== undefined && typeof maxRecordAge !== 'number' ) { throw new TypeError ( ` ${ maxRecordAge === null ? 'null' : typeof maxRecordAge } ` ) ; } const properties = learning . properties ; if ( properties !== undefined && ( properties === null || typeof properties !== 'object' ) ) { throw new TypeError ( ` ${ properties === null ? 'null' : typeof properties } ` ) ; } const advancedConfiguration = learning . advancedConfiguration ; if ( advancedConfiguration !== undefined && ( advancedConfiguration === null || typeof advancedConfiguration !== 'object' ) ) { throw new TypeError ( ` ${ advancedConfiguration === null ? 'null' : typeof advancedConfiguration } ` ) ; } return Provider . extendConfiguration ( providers , { time : { type : 'time_of_day' } , day : { type : 'day_of_week' } , month : { type : 'month_of_year' } , ... properties , [ TIMEZONE ] : { type : 'timezone' } , [ LOAD ] : { type : 'continuous' } } ) . then ( ( context ) => { return { context , output : [ 'load' ] , operations_as_events : true , tree_max_depth : maxTreeDepth || 6 , tree_max_operations : maxRecords || 50000 , learning_period : maxRecordAge || 365 * 24 * 60 * 60 , ... advancedConfiguration } ; } ) ; }
Generate a craft ai agent configuration
 @param {String} log
 @param {Array<Provider>} providers Array of providers that have as function extendConfiguration
 @param {Object} [learning={}] [OPTIONAL] Object that contains parameters of the configuration.
Generate a craft ai agent configuration @param { String } log @param { Array<Provider > } providers Array of providers that have as function extendConfiguration @param { Object } [ learning = {} ] [ OPTIONAL ] Object that contains parameters of the configuration .