Overview
TheloadNavaiFunctions function dynamically loads frontend function modules and registers them for use by the NAVAI voice agent. It supports functions, classes, and object exports, automatically extracting callable members and generating normalized function names.
Import
Signature
Parameters
Object mapping module paths to dynamic import loaders.Example:Note: Files ending in
.d.ts are automatically filtered out.Return Value
Registry object containing loaded functions and metadata.
NavaiFunctionDefinition
Supported Export Types
1. Default or Named Function Export
get_user_profile
Description: "Call exported function getUserProfile." or "Call exported function default."
2. Class Export
user_service_get_profileuser_service_update_profile
"Call class method UserService.getProfile().""Call class method UserService.updateProfile()."
3. Object with Methods
user_utils_format_nameuser_utils_is_active
"Call exported object member userUtils.formatName().""Call exported object member userUtils.isActive()."
Name Normalization
Function names are normalized using the following rules:- Convert camelCase to snake_case:
getUserProfile→get_user_profile - Replace non-alphanumeric characters with underscore:
get-user→get_user - Convert to lowercase:
GetUser→get_user - Strip leading/trailing underscores:
_getUser_→get_user
getUserProfile→get_user_profilesendEmailNotification→send_email_notificationUserService.getProfile→user_service_get_profileapi-client→api_client
Duplicate Name Handling
When multiple functions normalize to the same name, subsequent occurrences are suffixed with incrementing numbers:Payload Structure
Functions receive payloads with flexible argument passing:Simple Arguments
Single Value
Object Payload
If noargs, arguments, or value key exists, the entire payload is passed:
Class Methods
Context Injection
Functions can optionally receive a context object as their last parameter:Example Usage
Basic Function Loading
Integration with buildNavaiAgent
Dynamic Function Execution
Error Handling
Advanced Use Cases
Function with Context
Class with Complex Methods
Source Reference
Defined in:packages/voice-frontend/src/functions.ts:280