
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
targetai-client-js-sdk
Advanced tools
A JavaScript SDK for connecting to TargetAI voice agents via WebRTC, similar to the Retell client SDK.
npm install targetai-client-js-sdk
import { TargetAIWebClient } from 'targetai-client-js-sdk';
// Create client instance with token authentication
const client = new TargetAIWebClient({
serverUrl: 'https://your-runtime-server.com', // Runtime server (/run/voice/offer)
tokenServerUrl: 'https://your-token-server.com', // Token server (/token)
});
// Set up event listeners
client.on('call_started', () => {
console.log('Call started');
});
client.on('call_ended', () => {
console.log('Call ended');
});
client.on('update', (message) => {
console.log('Received message:', message);
});
client.on('error', (error) => {
console.error('Error:', error);
});
// Start a call (automatically gets token and authenticates)
await client.startCall({
agentUuid: 'your-agent-uuid',
allowedResponses: ['text', 'voice']
});
// Send a message
client.sendMessage('Hello, agent!');
// Stop the call
client.stopCall();
The SDK uses token-based authentication similar to the frontend negotiation pattern:
/token) → Get Token/run/voice/offer) with Token → WebRTC Connectionconst client = new TargetAIWebClient(config);
Config Options:
serverUrl (string, required): Your TargetAI runtime server URL (where /run/voice/offer endpoint is)tokenServerUrl (string, optional): Token server URL (where /token endpoint is). Defaults to serverUrlapiKey (string, optional): API key for token generationiceServers (RTCIceServer[], optional): Custom ICE servers for WebRTCaudioConstraints (object, optional): Audio input constraintsstartCall(options)Starts a voice call with the agent.
Options:
agentUuid (string, required): The UUID of the agent to connect todataInput (object, optional): Initial data to pass to the agentmessages (Message[], optional): Initial conversation messagesallowedResponses (string[], optional): Array of allowed response types: ['text', 'voice']sampleRate (number, optional): Audio sample rate (default: 24000)captureDeviceId (string, optional): Microphone device IDplaybackDeviceId (string, optional): Speaker device IDemitRawAudioSamples (boolean, optional): Whether to emit raw audio dataawait client.startCall({
agentUuid: 'agent-123',
allowedResponses: ['text', 'voice'],
sampleRate: 24000,
emitRawAudioSamples: true
});
stopCall()Stops the current call and cleans up resources.
sendMessage(message)Sends a text message to the agent.
Parameters:
message (string): The message to sendReturns: boolean - True if message was sent successfully
destroy()Completely destroys the client instance and cleans up all resources.
call_startedFired when the call begins successfully.
call_endedFired when the call ends.
agent_start_talkingFired when the agent starts speaking.
agent_stop_talkingFired when the agent stops speaking.
updateFired when a new message is received from the agent.
Parameters:
message (Message): The processed message objectaudioFired when raw audio data is available (if emitRawAudioSamples is enabled).
Parameters:
audioData (Float32Array): Raw PCM audio dataerrorFired when an error occurs.
Parameters:
error (Error): The error objectconnection_state_changeFired when the WebRTC connection state changes.
Parameters:
state (RTCPeerConnectionState): The new connection stateThe SDK handles various message types from the agent:
user: Messages from the user (speech recognition)assistant: Agent responsestool: Tool/function callstool_response: Tool/function responsessystem: System messageserror: Error messagescompletion: Task completion notificationsThe SDK includes audio utility functions:
import {
convertUnsigned8ToFloat32,
convertFloat32ToUnsigned8,
getAudioInputDevices,
getAudioOutputDevices
} from 'targetai-client-js-sdk';
// Get available audio devices
const inputDevices = await getAudioInputDevices();
const outputDevices = await getAudioOutputDevices();
// Convert audio formats
const float32Audio = convertUnsigned8ToFloat32(uint8Array);
const uint8Audio = convertFloat32ToUnsigned8(float32Array);
Requires WebRTC support and microphone permissions.
client.on('error', (error) => {
console.error('SDK Error:', error.message);
// Handle specific error types
if (error.message.includes('microphone')) {
// Handle microphone permission error
} else if (error.message.includes('negotiation')) {
// Handle WebRTC negotiation error
}
});
<!DOCTYPE html>
<html>
<head>
<title>TargetAI Voice Chat</title>
</head>
<body>
<button id="startCall">Start Call</button>
<button id="stopCall" disabled>Stop Call</button>
<input type="text" id="messageInput" placeholder="Type a message..." disabled>
<button id="sendMessage" disabled>Send</button>
<div id="messages"></div>
<script type="module">
import { TargetAIWebClient } from './dist/index.esm.js';
const client = new TargetAIWebClient({
serverUrl: 'https://your-server.com'
});
const startBtn = document.getElementById('startCall');
const stopBtn = document.getElementById('stopCall');
const messageInput = document.getElementById('messageInput');
const sendBtn = document.getElementById('sendMessage');
const messagesDiv = document.getElementById('messages');
// Event listeners
client.on('call_started', () => {
startBtn.disabled = true;
stopBtn.disabled = false;
messageInput.disabled = false;
sendBtn.disabled = false;
addMessage('System: Call started');
});
client.on('call_ended', () => {
startBtn.disabled = false;
stopBtn.disabled = true;
messageInput.disabled = true;
sendBtn.disabled = true;
addMessage('System: Call ended');
});
client.on('update', (message) => {
addMessage(`${message.type}: ${message.content || JSON.stringify(message)}`);
});
client.on('error', (error) => {
addMessage(`Error: ${error.message}`);
});
// UI event handlers
startBtn.onclick = async () => {
try {
await client.startCall({
agentUuid: 'your-agent-uuid',
allowedResponses: ['text', 'voice']
});
} catch (error) {
alert('Failed to start call: ' + error.message);
}
};
stopBtn.onclick = () => {
client.stopCall();
};
sendBtn.onclick = () => {
const message = messageInput.value.trim();
if (message) {
client.sendMessage(message);
addMessage(`You: ${message}`);
messageInput.value = '';
}
};
messageInput.onkeypress = (e) => {
if (e.key === 'Enter') {
sendBtn.click();
}
};
function addMessage(text) {
const div = document.createElement('div');
div.textContent = `${new Date().toLocaleTimeString()}: ${text}`;
messagesDiv.appendChild(div);
messagesDiv.scrollTop = messagesDiv.scrollHeight;
}
</script>
</body>
</html>
# Install dependencies
npm install
# Build the SDK
npm run build
# Run tests
npm test
ISC
FAQs
JavaScript SDK for TargetAI WebRTC voice agent communication
We found that targetai-client-js-sdk demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.