brx-node

Main BRX-AI Node interface

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
brx-node
0.6.7-development18 days ago9 months agoMinified + gzip package size for brx-node in KB

Readme

brx-node
brx-node logo

Status

!npm packagenpm-imgnpm-url !Downloadsdownloads-imgdownloads-url
BRX-NODE.js official interaction Module

brx-node is the official interaction module for BRX-NODE.js. It is used for interacting with the BRX AI API and includes functionalities such as sending requests and receiving responses.
We're currently in BETA expect package changes and improvements in the future!
You can install brx-node using the following commands:

Install

For npm:
npm install brx-node -s

For yarn:
yarn install brx-node -s

For pnpm:
pnpm install brx-node -D

Usage

Here is how you can interact with the BRX AI API using this module:
import BRX from 'brx-node';

const brx = new BRX(process.env.CUR_API_KEY!, { verbose: true });

const result = await brx.execute(query);

//=> 'Response from BRX'

CLI terminal Example for query rebuilds

import readline from 'readline';
import BRX from 'brx-node';
import { objToMap, objToMapField } from 'brx-node';

let input_fields: any[] = [];  // Initialized input_fields as an array
let outputObject:any;
let brx_schema_export:any = '';

let brx;

brx = new BRX("BRX-API-KEY", { verbose:true });

async function getUserInput(question:string) {
    const rl = readline.createInterface({
        input: process.stdin,
        output: process.stdout
    });

    return new Promise<string>((resolve) => rl.question(question, (ans) => {
        rl.close();
        resolve(ans);
    }));
}

async function update_inputs() {
  for (const input of input_fields) {
    // Get value for current input field from user 
    const value = await getUserInput(`Please enter the value for ${input.name}: `);
  
    // Update the fieldValue for current input field in the map
    let currentSchema = outputObject.userSchemaInteract.schemas.get(input.entry_key);
  
    if (currentSchema && currentSchema.schemaFields instanceof Map) {
      let currentField = currentSchema.schemaFields.get(`${input.name}`);

      if (currentField) {
        // Update the existing fieldValue
        currentField.fieldValue = value; 
      } else {
        // fieldValue not present currently, add a new one
        currentSchema.schemaFields.set(`${input.name}`, {fieldValue: value});
      }
    }
  }
}

const query_rebuilder = async () => {
  // console.log("starting rebuild: "  , input_fields)
  let json_export:any = JSON.parse(brx_schema_export)
  // let json_export:any =  brx_schema_export
  // console.log(json_export)
  outputObject = {
      userSchemaInteract: {
        mainBrxId: json_export.schemas.mainBrxId,
        schemas: objToMap(
          json_export.schemas.schemas.data.reduce((schemas:any, schemaEntry:any) => {
            const [schemaKey, schemaData] = schemaEntry;
            const newBrxName = schemaKey;

            const schemaFields = objToMapField(
              schemaData.schemaFields.data.reduce((fields:any, fieldEntry:any) => {
                const [fieldKey, fieldData] = fieldEntry;          
                input_fields.push({ type: fieldData.fieldValueDataType, name: fieldKey , entry_key: schemaKey })
                             
                fields[fieldKey] = { ...fieldData, fieldValue: fieldKey };
                return fields;
              }, {})
            );

            schemas[schemaKey] = {
              brxId: schemaData.brxId,
              brxName: newBrxName,
              schemaFields,
            };

            return schemas;
          }, {})
        ),
      },
    };
}

(async function() {
    brx_schema_export = await getUserInput("Please enter the brx_schema_export: ");

    await query_rebuilder();

    // console.log("After Rebuilder")
    // console.log(input_fields)

    await update_inputs();

    console.log(outputObject)

    const result = await brx.execute(outputObject);
    console.log("After Execution");
    console.log(result);
}());

Functions

The main class in this module is BRX. Here are the functions that you can use:

BRX.constructor(accessToken: string, options?: { usebrxkey?: boolean, verbose?: boolean, sendlocal?: boolean }): BRX

Creates an instance of the BRX class.
Parameters:
  • accessToken (string): The access token to interact with the BRX AI API.
  • options (object): An optional parameter for various options. The fields can be:
- use_brx_key (boolean): Whether to use the BRX API key for authorization. Default is true. - verbose (boolean): Whether to log additional details. Default is false. - send_local (boolean): Whether to use a local connection string. Default is false.
Example:
const brx = new BRX("your_access_token", { verbose: true, send_local: false });

```ts

BRX.execute(query: queryStreamRequest): Promise
Executes a given query and returns a promise for the response.

Parameters:
- `query` (`queryStreamRequest`): The query you want to execute.

Example:
```ts
const result = await brx.execute(query);

BRX.modify

BRX.modify(brxid: string, userInput: object , process_in:processType): Promise<any>

Under construction, check future versions for implementation

```ts

BRX.create(brkgen:brx , brxFieldData:schema): Promise
Create schema for your BRX.

Parameters:
- `brk_gen` (`brx`): BRX generation data
- `brxFieldData`(`schema`): Schema data for fields in BRX

Example:
```ts
await brx.create(brx_gen, brxFieldData);

```ts

BRX.validate(brxid: string, userInput: object): Promise ```
Under construction, check future versions for implementation

Objects

Several different objects are imported and used within the BRX class. These objects include brx, schema, userSchemaInteract and many more. See the enclosed object files 'brx.ts' and 'api.interact.ts' for detailed information on all these objects and their properties.