@voice-ai-workforce/types
TypeScript definitions with 3-tier mode system for Voice AI Workforce

✨ New: Mode System Type Definitions
Complete TypeScript support for the 3-tier interface mode system:
🔧 Developer Mode - Full technical interface types
🏢 Project Mode - Business application types
👤 End-User Mode - Simplified interface types
📦 Installation
npm install @voice-ai-workforce/types
🎯 Mode System Types
VoiceInterfaceMode
Core mode selection type:
type VoiceInterfaceMode = 'developer' | 'project' | 'end-user';
VisibilityConfig
Controls which features and information are visible:
interface VisibilityConfig {
showProviders?: boolean;
showProviderStatus?: boolean;
showProviderErrors?: boolean;
showDebugInfo?: boolean;
showConfidenceScores?: boolean;
showProcessingTimes?: boolean;
showTechnicalErrors?: boolean;
showAdvancedSettings?: boolean;
showCommandHistory?: boolean;
showAnalytics?: boolean;
showExportOptions?: boolean;
showMiniCenter?: boolean;
showSettingsPanel?: boolean;
showHistoryPanel?: boolean;
showStatusIndicator?: boolean;
useGenericLabels?: boolean;
customLabels?: CustomLabels;
}
CustomLabels
Defines custom labeling for different interface elements:
interface CustomLabels {
voiceButton?: {
startText?: string;
stopText?: string;
processingText?: string;
errorText?: string;
};
status?: {
online?: string;
offline?: string;
listening?: string;
processing?: string;
error?: string;
};
providers?: {
generic?: string;
fallback?: string;
};
errors?: {
generic?: string;
connection?: string;
permission?: string;
};
}
Default Mode Presets
Pre-configured visibility settings for each mode:
const DEFAULT_MODE_PRESETS: ModePresets = {
developer: {
showProviders: true,
showProviderStatus: true,
showProviderErrors: true,
showDebugInfo: true,
showConfidenceScores: true,
showProcessingTimes: true,
showTechnicalErrors: true,
showAdvancedSettings: true,
showCommandHistory: true,
showAnalytics: true,
showExportOptions: true,
showMiniCenter: true,
showSettingsPanel: true,
showHistoryPanel: true,
showStatusIndicator: true,
useGenericLabels: false,
},
project: {
showProviders: true,
showProviderStatus: true,
showProviderErrors: false,
showDebugInfo: false,
showConfidenceScores: true,
showProcessingTimes: false,
showTechnicalErrors: false,
showAdvancedSettings: true,
showCommandHistory: true,
showAnalytics: true,
showExportOptions: true,
showMiniCenter: true,
showSettingsPanel: true,
showHistoryPanel: true,
showStatusIndicator: true,
useGenericLabels: false,
},
'end-user': {
showProviders: false,
showProviderStatus: false,
showProviderErrors: false,
showDebugInfo: false,
showConfidenceScores: false,
showProcessingTimes: false,
showTechnicalErrors: false,
showAdvancedSettings: false,
showCommandHistory: true,
showAnalytics: false,
showExportOptions: false,
showMiniCenter: true,
showSettingsPanel: false,
showHistoryPanel: false,
showStatusIndicator: true,
useGenericLabels: true,
customLabels: {
voiceButton: {
startText: 'Start Voice',
stopText: 'Stop Voice',
processingText: 'Processing...',
errorText: 'Voice Unavailable'
},
status: {
online: 'Voice Ready',
offline: 'Voice Unavailable',
listening: 'Listening...',
processing: 'Processing...',
error: 'Voice Error'
},
providers: {
generic: 'Voice Assistant',
fallback: 'Voice Assistant'
},
errors: {
generic: 'Voice assistant is temporarily unavailable',
connection: 'Please check your connection',
permission: 'Microphone permission required'
}
}
}
};
🔧 Updated Core Types
VoiceAIConfig with Mode Support
interface VoiceAIConfig {
apiBaseUrl?: string;
apiKey?: string;
speechToText: SpeechToTextConfig;
textToSpeech: TextToSpeechConfig;
aiProviders: {
primary: AIProviderConfig;
fallbacks?: AIProviderConfig[];
};
responseMode?: ResponseMode;
interfaceMode?: VoiceInterfaceMode;
visibility?: VisibilityConfig;
commands?: CommandConfiguration;
ui?: UIConfiguration;
context?: ContextConfiguration;
}
Mode-Filtered Response Types
Commands and responses are automatically filtered based on the current mode:
interface VoiceCommand {
intent: string;
entities: Record<string, any>;
confidence: number;
rawText: string;
timestamp: Date;
provider?: AIProvider;
}
interface VoiceResponse {
text: string;
success: boolean;
data?: any;
actions?: CommandAction[];
suggestions?: string[];
metadata?: {
provider?: AIProvider;
confidence?: number;
processingTime?: number;
cached?: boolean;
};
}
⚛️ React Component Types with Mode Support
Enhanced Component Props
interface VoiceModeProps {
mode?: VoiceInterfaceMode;
visibilityOverrides?: Partial<VisibilityConfig>;
customLabels?: Partial<CustomLabels>;
}
interface VoiceButtonProps extends VoiceModeProps {
config: VoiceAIConfig;
size?: 'sm' | 'md' | 'lg' | 'xl';
variant?: 'primary' | 'secondary' | 'ghost' | 'danger';
className?: string;
disabled?: boolean;
onCommand?: (command: VoiceCommand) => void;
onResponse?: (response: VoiceResponse) => void;
onError?: (error: VoiceAIError) => void;
children?: React.ReactNode;
listenText?: string;
stopText?: string;
'aria-label'?: string;
}
interface VoiceCommandCenterProps extends VoiceModeProps {
config: VoiceAIConfig;
isOpen: boolean;
onClose?: () => void;
position?: 'left' | 'right';
width?: number;
showCategories?: boolean;
showHistory?: boolean;
onCommand?: (command: VoiceCommand) => void;
onResponse?: (response: VoiceResponse) => void;
onError?: (error: VoiceAIError) => void;
}
Updated Hook Types
interface UseVoiceAIOptions extends VoiceModeProps {
config: VoiceAIConfig;
onCommand?: (command: VoiceCommand) => void;
onResponse?: (response: VoiceResponse) => void;
onError?: (error: VoiceAIError) => void;
autoStart?: boolean;
}
interface UseVoiceAIReturn {
isListening: boolean;
isProcessing: boolean;
isAvailable: boolean;
currentCommand?: VoiceCommand;
lastResponse?: VoiceResponse;
error?: string;
startListening: () => Promise<void>;
stopListening: () => Promise<void>;
processText: (text: string) => Promise<VoiceResponse | undefined>;
speak: (text: string) => Promise<void>;
updateConfig: (newConfig: Partial<VoiceAIConfig>) => void;
updateContext: (context: Record<string, any>) => void;
getState: () => VoiceAIState;
visibility: VisibilityConfig;
labels: CustomLabels;
}
🔧 Utility Functions
useVoiceVisibility Hook
Resolves the effective visibility configuration:
function useVoiceVisibility(
config: VoiceAIConfig,
componentMode?: VoiceInterfaceMode,
componentOverrides?: Partial<VisibilityConfig>
): { visibility: VisibilityConfig; labels: CustomLabels }
resolveVisibilityConfig Function
Manually resolve visibility configuration:
function resolveVisibilityConfig(
globalMode?: VoiceInterfaceMode,
componentMode?: VoiceInterfaceMode,
globalVisibility?: VisibilityConfig,
componentOverrides?: Partial<VisibilityConfig>
): VisibilityConfig
getEffectiveLabels Function
Get the final labels based on configuration:
function getEffectiveLabels(
visibility: VisibilityConfig,
customLabels?: Partial<CustomLabels>
): CustomLabels
📋 Usage Examples
Basic Mode Configuration
import type {
VoiceAIConfig,
VoiceInterfaceMode,
VisibilityConfig
} from '@voice-ai-workforce/types';
const endUserConfig: VoiceAIConfig = {
speechToText: { provider: 'web-speech', language: 'en-US' },
textToSpeech: { provider: 'web-speech', speed: 1.0 },
aiProvider: { provider: 'openai', model: 'gpt-3.5-turbo' },
responseMode: 'both',
interfaceMode: 'end-user',
visibility: {
useGenericLabels: true,
showProviders: false,
showDebugInfo: false,
customLabels: {
voiceButton: {
startText: 'Ask Question',
stopText: 'Stop'
}
}
}
};
const developerConfig: VoiceAIConfig = {
speechToText: { provider: 'web-speech', language: 'en-US' },
textToSpeech: { provider: 'web-speech', speed: 1.0 },
aiProvider: { provider: 'openai', model: 'gpt-3.5-turbo' },
responseMode: 'both',
interfaceMode: 'developer',
visibility: {
showDebugInfo: true,
showProviders: true,
showConfidenceScores: true,
showProcessingTimes: true,
showTechnicalErrors: true
}
};
Component-Level Mode Overrides
import type { VoiceButtonProps } from '@voice-ai-workforce/types';
const buttonProps: VoiceButtonProps = {
config: globalConfig,
mode: 'end-user',
visibilityOverrides: {
showMiniCenter: false,
showStatusIndicator: true
},
customLabels: {
voiceButton: {
startText: 'Get Help',
processingText: 'Thinking...'
}
},
size: 'lg',
variant: 'primary',
onCommand: handleCommand
};
Type Guards for Mode-Filtered Data
function hasDebugInfo(command: VoiceCommand): command is VoiceCommand & {
provider: AIProvider;
entities: Record<string, any>;
} {
return 'provider' in command && 'entities' in command;
}
function hasResponseMetadata(response: VoiceResponse): response is VoiceResponse & {
metadata: {
provider: AIProvider;
confidence: number;
processingTime: number;
};
} {
return response.metadata != null &&
'provider' in response.metadata &&
'confidence' in response.metadata &&
'processingTime' in response.metadata;
}
if (hasDebugInfo(command)) {
console.log('Provider:', command.provider);
console.log('Entities:', command.entities);
}
if (hasResponseMetadata(response)) {
console.log('Processing time:', response.metadata.processingTime);
}
Mode-Aware Error Handling
type ModeAwareError = VoiceAIError & {
userFriendlyMessage?: string;
technicalDetails?: any;
};
function createModeError(
baseError: Error,
mode: VoiceInterfaceMode
): ModeAwareError {
const baseVoiceError: VoiceAIError = {
code: 'VOICE_ERROR',
message: baseError.message
};
switch (mode) {
case 'developer':
return {
...baseVoiceError,
message: `Technical Error: ${baseError.message}`,
technicalDetails: {
stack: baseError.stack,
timestamp: new Date(),
context: 'voice processing'
}
};
case 'project':
return {
...baseVoiceError,
message: `Voice Service Error: ${baseError.message}`,
suggestions: ['Check service status', 'Try again']
};
case 'end-user':
return {
...baseVoiceError,
message: 'Voice assistant is temporarily unavailable',
userFriendlyMessage: 'Please try again in a moment'
};
default:
return baseVoiceError;
}
}
Advanced Type Definitions
type ModeVariant<T extends VoiceInterfaceMode> =
T extends 'developer' ? 'technical' :
T extends 'project' ? 'business' :
T extends 'end-user' ? 'simple' :
never;
type ModeAwareProps<T extends VoiceInterfaceMode> = {
mode: T;
variant: ModeVariant<T>;
} & (T extends 'developer' ? {
showDebugInfo: true;
onDebugEvent?: (event: DebugEvent) => void;
} : {}) & (T extends 'end-user' ? {
simpleLabels: true;
hideComplexFeatures: true;
} : {});
const developerProps: ModeAwareProps<'developer'> = {
mode: 'developer',
variant: 'technical',
showDebugInfo: true,
onDebugEvent: (event) => console.log(event)
};
const endUserProps: ModeAwareProps<'end-user'> = {
mode: 'end-user',
variant: 'simple',
simpleLabels: true,
hideComplexFeatures: true
};
🔄 Migration Types
Upgrading from v1.x
interface OldVoiceAIConfig {
speechToText: SpeechToTextConfig;
aiProvider: AIProviderConfig;
}
interface NewVoiceAIConfig extends OldVoiceAIConfig {
interfaceMode?: VoiceInterfaceMode;
visibility?: VisibilityConfig;
}
type MigrateConfig<T extends OldVoiceAIConfig> = T & {
interfaceMode: VoiceInterfaceMode;
visibility?: VisibilityConfig;
};
function migrateConfig(
oldConfig: OldVoiceAIConfig,
targetMode: VoiceInterfaceMode
): NewVoiceAIConfig {
return {
...oldConfig,
interfaceMode: targetMode,
visibility: DEFAULT_MODE_PRESETS[targetMode]
};
}
📊 Performance Types
interface ModeAwareMetrics {
responseTime: number;
success: boolean;
technicalMetrics?: {
processingTime: number;
apiLatency: number;
memoryUsage: number;
cacheHitRate: number;
};
businessMetrics?: {
userSatisfaction: number;
taskCompletion: number;
errorRate: number;
};
userMetrics?: {
taskSuccess: boolean;
helpful: boolean;
};
}
🔗 Export Structure
export type {
VoiceInterfaceMode,
VisibilityConfig,
CustomLabels,
ModePresets,
VoiceModeProps
};
export type {
VoiceAIConfig,
VoiceCommand,
VoiceResponse,
VoiceAIState
};
export type {
VoiceButtonProps,
VoiceCommandCenterProps,
UseVoiceAIOptions,
UseVoiceAIReturn
};
export {
DEFAULT_MODE_PRESETS,
resolveVisibilityConfig,
getEffectiveLabels
};
export type {
SpeechProvider,
AIProvider,
ResponseMode,
UserRole,
HTTPMethod
};
🎯 Benefits of Typed Mode System
Type Safety
- Compile-time validation of mode configurations
- IntelliSense support for mode-specific properties
- Prevents runtime errors from incorrect mode usage
Developer Experience
- Auto-completion for mode-specific options
- Type narrowing based on mode selection
- Clear documentation through types
Maintainability
- Single source of truth for mode definitions
- Consistent interfaces across all packages
- Easy refactoring with TypeScript compiler support
🔗 Related Packages
📄 License
MIT © [Griseld Gerveni, CTO of VenueBoost Inc.]