@ai-universe/config-utils
v1.0.1
Published
Shared configuration utilities for AI Universe ecosystem
Maintainers
Readme
@ai-universe/config-utils
Shared configuration utilities for the AI Universe ecosystem. This package provides centralized configuration management with support for environment variables, GCP Secret Manager, and Firestore-based runtime configuration.
Features
- ConfigManager: Unified configuration loading with GCP Secret Manager fallback
- SecretManager: Google Cloud Secret Manager integration with caching
- RuntimeConfigService: Dynamic configuration stored in Firestore
- Constants & Validation: Shared limits, timeouts, and validation rules
- Type Safety: Full TypeScript support with exported interfaces
Installation
npm install @ai-universe/config-utilsUsage
ConfigManager
import { ConfigManager, configManager } from '@ai-universe/config-utils';
// Load complete application configuration
const config = await configManager.loadConfig();
console.log('Server port:', config.server.port);
console.log('API keys configured:', Object.keys(config.apiKeys));SecretManager
import { SecretManager } from '@ai-universe/config-utils';
const secretManager = new SecretManager('your-gcp-project');
const apiKey = await secretManager.getSecret('claude-api-key');RuntimeConfigService
import { runtimeConfigService } from '@ai-universe/config-utils';
// Get current configuration
const runtimeConfig = await runtimeConfigService.getConfig();
console.log('Rate limits:', runtimeConfig.rateLimit);
// Update configuration
await runtimeConfigService.updateConfigValue('features', {
enableCerebras: true,
enableClaude: true
});Constants & conversation defaults
import {
MAX_QUESTION_LENGTH,
DEFAULT_TIMEOUT_MS,
MODEL_SPECIFIC_LIMITS,
DEFAULT_SECONDARY_MODELS,
MAX_CLIENT_FINGERPRINT_LENGTH,
estimateTokens
} from '@ai-universe/config-utils';
// Validate input length
if (userInput.length > MAX_QUESTION_LENGTH) {
throw new Error('Input too long');
}
// Estimate tokens
const tokenCount = estimateTokens(userInput.length);All constants from SecondOpinionConfig.ts are available through the package entry point so downstream consumers no longer need
to deep import from dist/SecondOpinionConfig.js.
Verifying the public API
After building the package, you can confirm that the published surface matches the TypeScript source by listing the exported keys from Node:
npm run build
npm run check:exportsThe check:exports script executes scripts/check-exports.mjs to import the package entry point
and print the sorted export keys. This helper is suitable as a lightweight regression check in CI to ensure the build artifact
matches the TypeScript source.
Extracted Code
This package contains 874 LOC extracted from AI Universe backend:
- ConfigManager.ts (485 LOC) - Environment/API key/Firebase configuration
- SecretManager.ts (171 LOC) - GCP Secret Manager integration
- RuntimeConfigService.ts (218 LOC) - Dynamic Firestore configuration
API Reference
Types
AppConfig- Complete application configuration interfaceRuntimeConfig- Dynamic runtime configuration interfaceConfigSource- Configuration value source trackingPrimaryModelName- Supported AI model names
Constants
- Input validation limits (MAX_QUESTION_LENGTH, etc.)
- Timeout configurations (MIN/MAX/DEFAULT_TIMEOUT_MS)
- Model-specific limits (MODEL_SPECIFIC_LIMITS)
- Error messages (ERROR_MESSAGES)
Dependencies
@google-cloud/secret-manager- GCP Secret Manager client@google-cloud/firestore- Firestore clientwinston- Logging
License
MIT
