Global

Methods

add(a, b) → {number}

Adds two numbers together.

Parameters:
Name Type Description
a number

The first number.

b number

The second number.

Source:
Returns:

The sum of the two numbers.

Type
number

collection_instance_name_from(class_name) → {string}

Converts a class name to its corresponding collection instance name.

This function performs the following transformations:

  1. Converts camelCase to snake_case
  2. Makes the name plural (with special handling for words ending in 'y')
  3. Handles the special case of names ending with 'Item'
Parameters:
Name Type Description
class_name string

The class name to convert (e.g., 'SmartEntity', 'CollectionItem')

Source:
Returns:

The converted collection instance name (e.g., 'smart_entities', 'collection')

Type
string
Example
collection_instance_name_from('SmartEntity') // Returns 'smart_entities'
collection_instance_name_from('CollectionItem') // Returns 'collection'

cos_sim(vector1, vector2) → {number}

Calculates the cosine similarity between two vectors.

Parameters:
Name Type Description
vector1 Array.<number>

The first vector.

vector2 Array.<number>

The second vector.

Source:
Returns:

The cosine similarity between the two vectors.

Type
number

create_uid(data) → {string}

Creates a unique identifier for the given data without using cryptographic methods.

Parameters:
Name Type Description
data Object

The data object to create a UID for.

Source:
Returns:

A unique identifier based on the input data.

Type
string

deep_equal(obj1, obj2, visitedopt) → {boolean}

Compares two values deeply to determine if they are equal.

Parameters:
Name Type Attributes Default Description
obj1 *

The first value to compare.

obj2 *

The second value to compare.

visited WeakMap <optional>
new WeakMap()

WeakMap of visited objects to handle circular references.

Source:
Returns:

True if the values are deeply equal, false otherwise.

Type
boolean

deep_merge(target, source) → {Object}

Deeply merges two objects, giving precedence to the properties of the source object.

Parameters:
Name Type Description
target Object

The target object to merge properties into.

source Object

The source object from which properties are sourced.

Source:
Returns:

The merged object.

Type
Object

is_valid_tool_call(tool, tool_call_content) → {boolean}

Validates a tool call against its specification to ensure all parameters are correct. This function checks if all provided keys in the tool call content match the expected types, handles type coercion for numeric values, validates against enums, and ensures all required parameters are present.

Parameters:
Name Type Description
tool Object

The tool object containing the function specification.

tool_call_content Object

The actual parameters passed to the tool function.

Source:
Throws:
  • Throws an error if any validation fails.
Type
Error
Returns:
  • Returns true if the tool call is valid.
Type
boolean

sequential_async_processor(funcs, initial_value, opts) → {*}

Sequentially executes an array of asynchronous functions, passing the result of each function as the input to the next, along with an optional options object.

Parameters:
Name Type Description
funcs Array.<function()>

An array of functions to execute sequentially (may be async functions).

initial_value *

The initial value to pass to the first function in the array.

opts Object

Optional parameters to pass to each function.

Source:
Throws:

Throws an error if any function in the array is not actually a function or if an async function throws an error.

Type
Error
Returns:

The final value after all functions have been executed.

Type
*

sleep(ms) → {Promise}

Delays the execution of the next line in the code by a specified number of milliseconds.

Parameters:
Name Type Description
ms number

The number of milliseconds to delay.

Source:
Returns:

A promise that resolves after the specified delay.

Type
Promise

subtract(a, b) → {number}

Subtracts the second number from the first.

Parameters:
Name Type Description
a number

The first number.

b number

The second number.

Source:
Returns:

The difference of the two numbers.

Type
number