@moss-tools/voice-server
v1.0.0-beta.3
Published
Optimized server-side utilities for LiveKit-based Moss voice agents.
Maintainers
Readme
@moss-tools/voice-server
Optimized server-side utilities for LiveKit-based Moss voice agents. Handles secure token generation and connection management.
Features
- Token generation - Create participant tokens with optimized permissions
- Clean class-based API - Simple, intuitive interface
- Type-safe - Full TypeScript support with detailed JSDoc comments
Requirements
- Node.js 18.0.0 or higher
Install
npm install @moss-tools/voice-serverUsage
import { MossVoiceServer } from "@moss-tools/voice-server";
// Create and initialize (call once at app startup)
const voiceServer = await MossVoiceServer.create({
projectId: process.env.MOSS_PROJECT_ID!,
projectKey: process.env.MOSS_PROJECT_KEY!,
voiceAgentId: process.env.MOSS_VOICE_AGENT_ID!,
});
// Get voice agent server URL for clients
const serverUrl = voiceServer.getServerUrl();
// Create participant tokens
const token = await voiceServer.createParticipantToken(
{ identity: "user_123", name: "John Doe" },
"support_room_456"
);The MossVoiceServer class securely fetches and caches your voice agent credentials, then uses them to generate participant tokens.
API
MossVoiceServer.create(config): Promise<MossVoiceServer>
Create and initialize a MossVoiceServer instance by fetching credentials from Moss API.
Parameters:
config.projectId- Your Moss project IDconfig.projectKey- Your Moss project keyconfig.voiceAgentId- Voice agent ID to use
Returns: Initialized MossVoiceServer instance
Example:
const voiceServer = await MossVoiceServer.create({
projectId: "your-project-id",
projectKey: "your-project-key",
voiceAgentId: "your-voice-agent-id",
});voiceServer.getServerUrl(): string
Get the voice agent server URL for client connections.
Returns: Voice agent server URL (e.g., wss://your-agent.livekit.cloud)
Note: Credentials are kept secure on the server and never exposed.
voiceServer.createParticipantToken(userInfo, roomName, agentName?): Promise<string>
Create and sign a participant token for joining a voice session.
Parameters:
userInfo- User identity and nameidentity- Unique user identifiername- Display name for the participant
roomName- Room name to joinagentName- (Optional) Override default voice agent name
Returns: Signed JWT token valid for 15 minutes
Example:
const token = await voiceServer.createParticipantToken(
{ identity: "user_123", name: "John Doe" },
"support_room_456"
);voiceServer.getAgentName(): string
Get the configured voice agent name.
Returns: Voice agent name
Environment Variables
Configure using environment variables:
MOSS_PROJECT_ID=your-project-id
MOSS_PROJECT_KEY=your-project-key
MOSS_VOICE_AGENT_ID=your-voice-agent-idThen in your code:
const voiceServer = await MossVoiceServer.create({
projectId: process.env.MOSS_PROJECT_ID!,
projectKey: process.env.MOSS_PROJECT_KEY!,
voiceAgentId: process.env.MOSS_VOICE_AGENT_ID!,
});Development
npm install
npm run build
npm testBuild output is emitted to dist/.
