Skip to main content

Overview

The resolveNavaiBackendRuntimeConfig function scans your project directory for function modules and creates a runtime configuration with module loaders. It handles file system scanning, pattern matching, and exclusions to automatically discover callable function modules.

Function Signature

async function resolveNavaiBackendRuntimeConfig(
  options?: ResolveNavaiBackendRuntimeConfigOptions
): Promise<ResolveNavaiBackendRuntimeConfigResult>

Parameters

options
ResolveNavaiBackendRuntimeConfigOptions
Configuration options for runtime resolution.

Return Type

ResolveNavaiBackendRuntimeConfigResult
object
The resolved runtime configuration.

Pattern Matching

The functionsFolders parameter supports multiple pattern types:

1. Exact Directory Match

functionsFolders: 'src/ai/functions-modules'
Matches all files in src/ai/functions-modules/ and subdirectories.

2. Recursive Wildcard

functionsFolders: 'src/ai/...'
Matches all files in src/ai/ and all nested subdirectories.

3. Glob Patterns

functionsFolders: 'src/*/functions'
Matches:
  • src/user/functions/
  • src/admin/functions/
  • src/api/functions/

4. Multiple Patterns

functionsFolders: 'src/ai/functions,src/tools,lib/functions'
Matches files in any of the specified directories.

Example Usage

import { resolveNavaiBackendRuntimeConfig } from '@navai/voice-backend';

const config = await resolveNavaiBackendRuntimeConfig();

console.log('Found modules:', Object.keys(config.functionModuleLoaders));
console.log('Warnings:', config.warnings);

Environment Variables

The following environment variables are read when env is provided:
  • NAVAI_FUNCTIONS_FOLDERS - Comma-separated folder patterns to scan
  • NAVAI_FUNCTIONS_BASE_DIR - Base directory for scanning (overrides baseDir option)

File Scanning Rules

  1. Automatic normalization: All paths are normalized (backslashes → forward slashes)
  2. Relative path resolution: Paths starting with ./ or ../ are resolved
  3. Declaration files: TypeScript .d.ts files are automatically excluded
  4. Extension matching: Case-insensitive extension matching
  5. Exclude patterns: Applied before include patterns
  6. Sorting: Results are sorted alphabetically by path

Default Behavior

If no patterns match any modules:
  1. A warning is emitted
  2. The function falls back to defaultFunctionsFolder
  3. If the fallback also matches nothing, returns empty loaders
The function does not throw errors when no modules are found. Always check the warnings array and the size of functionModuleLoaders to detect misconfiguration.

Performance Considerations

  • File system scanning is performed only once
  • Module imports are lazy (not executed until loader is called)
  • Exclude patterns prevent scanning large directories like node_modules
  • Use specific patterns to limit the scan scope

Source Reference

Defined in: packages/voice-backend/src/runtime.ts:35

Build docs developers (and LLMs) love