@voice-ai-workforce/react
React components with 3-tier interface modes for voice-controlled workforce applications

โจ New: Mode-Aware React Components
Components automatically adapt their interface based on mode configuration:
๐ง Developer Mode - Full debug interface with technical details
๐ข Project Mode - Balanced interface for business applications
๐ค End-User Mode - Clean, simple interface for customers/employees
๐ฆ Installation
npm install @voice-ai-workforce/react @voice-ai-workforce/core @voice-ai-workforce/types
๐ Quick Start by Mode
End-User Mode (Customer-Facing)
import React from 'react';
import { VoiceButton } from '@voice-ai-workforce/react';
function CustomerApp() {
const config = {
speechToText: { provider: 'web-speech' as any },
textToSpeech: { provider: 'web-speech' as any },
aiProvider: { provider: 'openai' as any },
responseMode: 'both' as any,
interfaceMode: 'end-user' as any
};
return (
<div>
<h1>Customer Support</h1>
<VoiceButton
config={config}
customLabels={{
voiceButton: {
startText: 'Ask for Help',
stopText: 'Stop',
processingText: 'Listening...'
}
}}
onCommand={(command) => {
// Command is filtered - only essential info
console.log('Customer said:', command.rawText);
}}
onError={(error) => {
// Error is user-friendly
console.log('Simple error:', error.message); // "Voice assistant unavailable"
}}
/>
{/* User sees: Simple "Ask for Help" button, no technical details */}
</div>
);
}
Project Mode (Business Admin)
import React from 'react';
import { VoiceButton, VoiceCommandCenter } from '@voice-ai-workforce/react';
function AdminDashboard() {
const config = {
speechToText: { provider: 'web-speech' as any },
textToSpeech: { provider: 'web-speech' as any },
aiProvider: { provider: 'openai' as any },
responseMode: 'both' as any,
interfaceMode: 'project' as any
};
return (
<div>
<h1>Admin Dashboard</h1>
<VoiceButton
config={config}
showMiniCenter={true}
onCommand={(command) => {
// Command includes business-relevant info
console.log('Admin command:', {
intent: command.intent,
confidence: command.confidence, // Available in project mode
provider: command.provider // Available in project mode
});
}}
/>
<VoiceCommandCenter
config={config}
isOpen={true}
showCategories={true}
showHistory={true}
/>
{/* Admin sees: Provider info, confidence scores, settings panel */}
</div>
);
}
Developer Mode (Full Debug)
import React from 'react';
import { VoiceButton, VoiceCommandCenter } from '@voice-ai-workforce/react';
function DeveloperConsole() {
const config = {
speechToText: { provider: 'web-speech' as any },
textToSpeech: { provider: 'web-speech' as any },
aiProvider: { provider: 'openai' as any },
responseMode: 'both' as any,
interfaceMode: 'developer' as any,
visibility: {
showDebugInfo: true,
showProcessingTimes: true,
showTechnicalErrors: true
}
};
return (
<div>
<h1>Voice AI Developer Console</h1>
<VoiceButton
config={config}
showMiniCenter={true}
onCommand={(command) => {
// Full command object with debug information
console.log('Full debug command:', {
intent: command.intent,
entities: command.entities,
confidence: command.confidence,
provider: command.provider,
processingTime: '245ms'
});
}}
onError={(error) => {
// Full technical error details
console.error('Technical error:', error.details);
}}
/>
<VoiceCommandCenter
config={config}
isOpen={true}
width={400}
showCategories={true}
showHistory={true}
/>
{/* Developer sees: All debug info, processing times, full errors, analytics */}
</div>
);
}
๐งฐ Updated Components
VoiceButton with Mode Support
interface VoiceButtonProps {
config: VoiceAIConfig;
mode?: 'developer' | 'project' | 'end-user';
visibilityOverrides?: Partial<VisibilityConfig>;
customLabels?: Partial<CustomLabels>;
size?: 'sm' | 'md' | 'lg' | 'xl';
variant?: 'primary' | 'secondary' | 'ghost';
onCommand?: (command: VoiceCommand) => void;
onResponse?: (response: VoiceResponse) => void;
onError?: (error: VoiceAIError) => void;
}
Mode-Specific Features
Provider Status | โ
"OpenAI Connected" | โ
"OpenAI Connected" | โ "Voice Assistant" |
Confidence Scores | โ
85.2% | โ
85% | โ Hidden |
Error Details | โ
Stack traces | โ ๏ธ User-friendly | โ "Voice error" |
Mini Center | โ
Full featured | โ
Standard | โ
Simplified |
Debug Info | โ
Processing times | โ Hidden | โ Hidden |
VoiceCommandCenter with Mode Support
<VoiceCommandCenter
config={config}
mode="project"
visibilityOverrides={{
showAdvancedSettings: false,
showExportOptions: false
}}
customLabels={{
providers: {
generic: 'Smart Assistant'
}
}}
isOpen={true}
showCategories={true}
showHistory={true}
/>
๐ช Updated Hooks
useVoiceAI with Mode Support
import { useVoiceAI } from '@voice-ai-workforce/react';
function CustomVoiceInterface() {
const {
isListening,
startListening,
stopListening,
visibility,
labels
} = useVoiceAI({
config,
mode: 'end-user',
visibilityOverrides: {
showMiniCenter: false
},
onCommand: (command) => {
console.log(command.intent);
console.log(command.confidence);
}
});
return (
<div>
<button onClick={isListening ? stopListening : startListening}>
{isListening ? labels.voiceButton.stopText : labels.voiceButton.startText}
</button>
{/* Conditionally show features based on mode */}
{visibility.showDebugInfo && (
<div>Debug: Provider status, processing times, etc.</div>
)}
</div>
);
}
๐จ Mode-Aware Styling
Components automatically adjust their appearance based on mode:
.voice-button-developer {
border: 2px solid #3b82f6;
background: linear-gradient(45deg, #3b82f6, #1d4ed8);
}
.voice-button-project {
border: 1px solid #6b7280;
background: #f9fafb;
}
.voice-button-end-user {
border-radius: 50%;
background: linear-gradient(45deg, #10b981, #059669);
box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
}
๐ฑ Mode Examples
Multi-Mode Application
Different parts of the same app using different modes:
function StaffluentApp() {
const globalConfig = {
speechToText: { provider: 'web-speech' as any },
textToSpeech: { provider: 'web-speech' as any },
aiProvider: { provider: 'openai' as any },
responseMode: 'both' as any,
interfaceMode: 'project' as any
};
return (
<div>
<header>
<h1>Staffluent Dashboard</h1>
{/* Admin section - developer mode */}
<VoiceCommandCenter
config={globalConfig}
mode="developer" // Component override
isOpen={true}
position="right"
/>
</header>
<main>
{/* User help - end-user mode */}
<div className="help-section">
<h2>Need Help?</h2>
<VoiceButton
config={globalConfig}
mode="end-user" // Component override
customLabels={{
voiceButton: { startText: 'Ask Question' }
}}
/>
</div>
{/* Manager section - uses global project mode */}
<VoiceButton
config={globalConfig}
showMiniCenter={true}
/>
</main>
</div>
);
}
Dynamic Mode Switching
function ModeTestInterface() {
const [currentMode, setCurrentMode] = useState<'developer' | 'project' | 'end-user'>('project');
return (
<div>
<select value={currentMode} onChange={(e) => setCurrentMode(e.target.value as any)}>
<option value="developer">Developer Mode</option>
<option value="project">Project Mode</option>
<option value="end-user">End-User Mode</option>
</select>
<VoiceButton
config={baseConfig}
mode={currentMode}
onCommand={(cmd) => {
// Response varies by mode
console.log(`Mode: ${currentMode}, Command:`, cmd);
}}
/>
</div>
);
}
Custom Visibility Configuration
<VoiceButton
config={config}
mode="project"
visibilityOverrides={{
showConfidenceScores: true,
showProviders: false,
showDebugInfo: false,
showMiniCenter: true
}}
customLabels={{
providers: {
generic: 'AI Assistant'
},
errors: {
generic: 'Assistant temporarily unavailable'
}
}}
/>
โฟ Mode-Aware Accessibility
Accessibility features adapt to each mode:
<VoiceButton
config={config}
mode="end-user"
aria-label="Voice assistant for customer support"
/>
<VoiceButton
config={config}
mode="developer"
aria-label="Voice AI development console with debug information"
// Technical but comprehensive labeling
/>
๐งช Testing Mode Behavior
import { render, fireEvent } from '@testing-library/react';
import { VoiceButton } from '@voice-ai-workforce/react';
describe('VoiceButton Mode Behavior', () => {
test('end-user mode hides technical details', () => {
const { container } = render(
<VoiceButton
config={mockConfig}
mode="end-user"
onCommand={jest.fn()}
/>
);
expect(container.querySelector('[data-testid="provider-status"]')).toBeNull();
});
test('developer mode shows all debug info', () => {
const { container } = render(
<VoiceButton
config={mockConfig}
mode="developer"
onCommand={jest.fn()}
/>
);
expect(container.querySelector('[data-testid="debug-info"]')).toBeInTheDocument();
});
});
๐ง Migration Guide
From v1.x Components
<VoiceButton
config={config}
onCommand={handleCommand}
/>
<VoiceButton
config={config}
mode="end-user" // Choose appropriate mode
customLabels={{ // Customize labels if needed
voiceButton: {
startText: 'Start Voice'
}
}}
onCommand={handleCommand}
/>
๐ Key Benefits
Simplified Development
- One Component Set: Same components work for all user types
- Automatic Filtering: Information automatically filtered by mode
- Easy Customization: Override mode and visibility at component level
Better User Experience
- Appropriate Complexity: Each user sees the right level of detail
- Consistent Interface: Familiar patterns across different modes
- Flexible Configuration: Fine-tune what each user type sees
Maintainable Code
- Type-Safe: Full TypeScript support for all mode features
- Single Source: One component codebase for all interfaces
- Easy Testing: Test behavior in different modes
๐ Related Packages
๐ License
MIT ยฉ [Griseld Gerveni, CTO of VenueBoost Inc.]