ttp-agent-sdk 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,464 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>VoiceSDK - Vanilla JavaScript Example</title>
7
+ <style>
8
+ body {
9
+ font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
10
+ max-width: 1000px;
11
+ margin: 0 auto;
12
+ padding: 20px;
13
+ background: #F9FAFB;
14
+ }
15
+
16
+ .container {
17
+ background: white;
18
+ padding: 30px;
19
+ border-radius: 12px;
20
+ box-shadow: 0 1px 3px rgba(0,0,0,0.1);
21
+ margin-bottom: 20px;
22
+ }
23
+
24
+ h1 {
25
+ color: #111827;
26
+ margin-top: 0;
27
+ }
28
+
29
+ .status {
30
+ padding: 12px;
31
+ border-radius: 6px;
32
+ margin: 20px 0;
33
+ font-family: monospace;
34
+ font-size: 14px;
35
+ }
36
+
37
+ .status.connected {
38
+ background: #D1FAE5;
39
+ color: #065F46;
40
+ border: 1px solid #10B981;
41
+ }
42
+
43
+ .status.disconnected {
44
+ background: #FEE2E2;
45
+ color: #991B1B;
46
+ border: 1px solid #EF4444;
47
+ }
48
+
49
+ .status.connecting {
50
+ background: #FEF3C7;
51
+ color: #92400E;
52
+ border: 1px solid #F59E0B;
53
+ }
54
+
55
+ .controls {
56
+ display: flex;
57
+ gap: 12px;
58
+ margin: 20px 0;
59
+ flex-wrap: wrap;
60
+ }
61
+
62
+ button {
63
+ background: #4F46E5;
64
+ color: white;
65
+ border: none;
66
+ padding: 12px 24px;
67
+ border-radius: 6px;
68
+ cursor: pointer;
69
+ font-size: 16px;
70
+ transition: background-color 0.2s;
71
+ }
72
+
73
+ button:hover:not(:disabled) {
74
+ background: #4338CA;
75
+ }
76
+
77
+ button:disabled {
78
+ background: #9CA3AF;
79
+ cursor: not-allowed;
80
+ }
81
+
82
+ button.recording {
83
+ background: #EF4444;
84
+ animation: pulse 1.5s infinite;
85
+ }
86
+
87
+ button.recording:hover {
88
+ background: #DC2626;
89
+ }
90
+
91
+ @keyframes pulse {
92
+ 0%, 100% { transform: scale(1); }
93
+ 50% { transform: scale(1.05); }
94
+ }
95
+
96
+ .messages {
97
+ border: 1px solid #E5E7EB;
98
+ border-radius: 8px;
99
+ height: 300px;
100
+ overflow-y: auto;
101
+ padding: 16px;
102
+ background: #F9FAFB;
103
+ margin: 20px 0;
104
+ }
105
+
106
+ .message {
107
+ margin-bottom: 12px;
108
+ padding: 8px 12px;
109
+ border-radius: 6px;
110
+ max-width: 80%;
111
+ }
112
+
113
+ .message.user {
114
+ background: #E5E7EB;
115
+ margin-left: auto;
116
+ }
117
+
118
+ .message.agent {
119
+ background: #F3F4F6;
120
+ }
121
+
122
+ .message.system {
123
+ background: #EFF6FF;
124
+ color: #1E40AF;
125
+ }
126
+
127
+ .message.error {
128
+ background: #FEE2E2;
129
+ color: #991B1B;
130
+ }
131
+
132
+ .indicators {
133
+ display: flex;
134
+ gap: 20px;
135
+ margin-top: 20px;
136
+ font-size: 14px;
137
+ color: #6B7280;
138
+ }
139
+
140
+ .indicator {
141
+ display: flex;
142
+ align-items: center;
143
+ gap: 8px;
144
+ }
145
+
146
+ .indicator-dot {
147
+ width: 8px;
148
+ height: 8px;
149
+ border-radius: 50%;
150
+ background: #9CA3AF;
151
+ }
152
+
153
+ .indicator-dot.active {
154
+ background: #10B981;
155
+ }
156
+
157
+ .indicator-dot.recording {
158
+ background: #EF4444;
159
+ }
160
+
161
+ .code-block {
162
+ background: #1F2937;
163
+ color: #F9FAFB;
164
+ padding: 16px;
165
+ border-radius: 6px;
166
+ font-family: monospace;
167
+ font-size: 12px;
168
+ overflow-x: auto;
169
+ margin: 20px 0;
170
+ }
171
+
172
+ .voice-button-demo {
173
+ margin: 20px 0;
174
+ padding: 20px;
175
+ border: 2px dashed #D1D5DB;
176
+ border-radius: 8px;
177
+ text-align: center;
178
+ }
179
+ </style>
180
+ </head>
181
+ <body>
182
+ <div class="container">
183
+ <h1>🎤 VoiceSDK - Vanilla JavaScript Example</h1>
184
+
185
+ <div class="info">
186
+ <p>This example demonstrates how to use the VoiceSDK with vanilla JavaScript.
187
+ The SDK provides real-time voice interaction with AI agents using WebSocket communication.</p>
188
+ </div>
189
+
190
+ <!-- Connection Status -->
191
+ <div id="status" class="status disconnected">
192
+ Status: Disconnected
193
+ </div>
194
+
195
+ <!-- Controls -->
196
+ <div class="controls">
197
+ <button id="connectBtn">Connect</button>
198
+ <button id="disconnectBtn" disabled>Disconnect</button>
199
+ <button id="recordBtn" disabled>Start Recording</button>
200
+ <button id="stopBtn" disabled>Stop Recording</button>
201
+ </div>
202
+
203
+ <!-- Voice Button Demo -->
204
+ <div class="voice-button-demo">
205
+ <h3>Voice Button Component Demo:</h3>
206
+ <p>This is a pre-built voice button component:</p>
207
+ <div id="voice-button-container"></div>
208
+ </div>
209
+
210
+ <!-- Messages -->
211
+ <div class="messages" id="messages">
212
+ <div class="message system">
213
+ <strong>System:</strong> Ready to connect. Click "Connect" to start.
214
+ </div>
215
+ </div>
216
+
217
+ <!-- Status Indicators -->
218
+ <div class="indicators">
219
+ <div class="indicator">
220
+ <div id="connectionDot" class="indicator-dot"></div>
221
+ <span>Connection</span>
222
+ </div>
223
+ <div class="indicator">
224
+ <div id="recordingDot" class="indicator-dot"></div>
225
+ <span>Recording</span>
226
+ </div>
227
+ <div class="indicator">
228
+ <div id="playingDot" class="indicator-dot"></div>
229
+ <span>Playing</span>
230
+ </div>
231
+ </div>
232
+
233
+ <!-- Code Example -->
234
+ <div class="code-block">
235
+ <div>// VoiceSDK Usage Example</div>
236
+ <div>const voiceSDK = new VoiceSDK({</div>
237
+ <div> websocketUrl: 'wss://speech.bidme.co.il/ws/conv',</div>
238
+ <div> agentId: 'your_agent_id',</div>
239
+ <div> appId: 'your_app_id'</div>
240
+ <div>});</div>
241
+ <div></div>
242
+ <div>voiceSDK.on('connected', () => console.log('Connected!'));</div>
243
+ <div>voiceSDK.on('recordingStarted', () => console.log('Recording...'));</div>
244
+ <div></div>
245
+ <div>await voiceSDK.connect();</div>
246
+ <div>await voiceSDK.startRecording();</div>
247
+ </div>
248
+ </div>
249
+
250
+ <!-- Load the SDK -->
251
+ <script src="../agent-widget.js"></script>
252
+
253
+ <script>
254
+ // VoiceSDK instance
255
+ let voiceSDK = null;
256
+ let isConnected = false;
257
+ let isRecording = false;
258
+ let isPlaying = false;
259
+
260
+ // DOM elements
261
+ const statusDiv = document.getElementById('status');
262
+ const messagesDiv = document.getElementById('messages');
263
+ const connectBtn = document.getElementById('connectBtn');
264
+ const disconnectBtn = document.getElementById('disconnectBtn');
265
+ const recordBtn = document.getElementById('recordBtn');
266
+ const stopBtn = document.getElementById('stopBtn');
267
+ const connectionDot = document.getElementById('connectionDot');
268
+ const recordingDot = document.getElementById('recordingDot');
269
+ const playingDot = document.getElementById('playingDot');
270
+
271
+ // Initialize VoiceSDK
272
+ function initializeVoiceSDK() {
273
+ voiceSDK = new TTPAgentSDK.VoiceSDK({
274
+ websocketUrl: 'wss://speech.bidme.co.il/ws/conv',
275
+ agentId: 'demo_agent_123',
276
+ appId: 'demo_app_456',
277
+ voice: 'default',
278
+ language: 'en',
279
+ autoReconnect: true
280
+ });
281
+
282
+ // Set up event handlers
283
+ voiceSDK.on('connected', () => {
284
+ isConnected = true;
285
+ updateStatus('Connected', 'connected');
286
+ updateIndicators();
287
+ updateButtons();
288
+ addMessage('system', 'Connected to voice agent successfully!');
289
+ });
290
+
291
+ voiceSDK.on('disconnected', () => {
292
+ isConnected = false;
293
+ isRecording = false;
294
+ isPlaying = false;
295
+ updateStatus('Disconnected', 'disconnected');
296
+ updateIndicators();
297
+ updateButtons();
298
+ addMessage('system', 'Disconnected from voice agent');
299
+ });
300
+
301
+ voiceSDK.on('recordingStarted', () => {
302
+ isRecording = true;
303
+ updateIndicators();
304
+ updateButtons();
305
+ addMessage('user', '🎤 Recording started...');
306
+ });
307
+
308
+ voiceSDK.on('recordingStopped', () => {
309
+ isRecording = false;
310
+ updateIndicators();
311
+ updateButtons();
312
+ addMessage('user', '⏹️ Recording stopped');
313
+ });
314
+
315
+ voiceSDK.on('playbackStarted', () => {
316
+ isPlaying = true;
317
+ updateIndicators();
318
+ addMessage('agent', '🔊 Agent is speaking...');
319
+ });
320
+
321
+ voiceSDK.on('playbackStopped', () => {
322
+ isPlaying = false;
323
+ updateIndicators();
324
+ });
325
+
326
+ voiceSDK.on('message', (message) => {
327
+ if (message.type === 'agent_response') {
328
+ addMessage('agent', message.agent_response);
329
+ } else if (message.type === 'user_transcript') {
330
+ addMessage('user', message.user_transcription);
331
+ }
332
+ });
333
+
334
+ voiceSDK.on('error', (error) => {
335
+ console.error('VoiceSDK Error:', error);
336
+ addMessage('error', `Error: ${error.message}`);
337
+ });
338
+ }
339
+
340
+ // Update status display
341
+ function updateStatus(message, type) {
342
+ statusDiv.textContent = `Status: ${message}`;
343
+ statusDiv.className = `status ${type}`;
344
+ }
345
+
346
+ // Update status indicators
347
+ function updateIndicators() {
348
+ connectionDot.className = `indicator-dot ${isConnected ? 'active' : ''}`;
349
+ recordingDot.className = `indicator-dot ${isRecording ? 'recording' : ''}`;
350
+ playingDot.className = `indicator-dot ${isPlaying ? 'active' : ''}`;
351
+ }
352
+
353
+ // Update button states
354
+ function updateButtons() {
355
+ connectBtn.disabled = isConnected;
356
+ disconnectBtn.disabled = !isConnected;
357
+ recordBtn.disabled = !isConnected || isRecording;
358
+ stopBtn.disabled = !isConnected || !isRecording;
359
+
360
+ if (isRecording) {
361
+ recordBtn.classList.add('recording');
362
+ } else {
363
+ recordBtn.classList.remove('recording');
364
+ }
365
+ }
366
+
367
+ // Add message to chat
368
+ function addMessage(type, text) {
369
+ const messageDiv = document.createElement('div');
370
+ messageDiv.className = `message ${type}`;
371
+
372
+ const timestamp = new Date().toLocaleTimeString();
373
+ const typeLabel = type === 'user' ? '👤 You' :
374
+ type === 'agent' ? '🤖 Agent' :
375
+ type === 'error' ? '❌ Error' : 'ℹ️ System';
376
+
377
+ messageDiv.innerHTML = `
378
+ <div style="font-weight: bold; margin-bottom: 4px;">${typeLabel}</div>
379
+ <div>${text}</div>
380
+ <div style="font-size: 12px; color: #6B7280; margin-top: 4px;">${timestamp}</div>
381
+ `;
382
+
383
+ messagesDiv.appendChild(messageDiv);
384
+ messagesDiv.scrollTop = messagesDiv.scrollHeight;
385
+ }
386
+
387
+ // Event handlers
388
+ connectBtn.addEventListener('click', async () => {
389
+ try {
390
+ updateStatus('Connecting...', 'connecting');
391
+ await voiceSDK.connect();
392
+ } catch (error) {
393
+ console.error('Connection failed:', error);
394
+ updateStatus('Connection failed', 'disconnected');
395
+ addMessage('error', `Connection failed: ${error.message}`);
396
+ }
397
+ });
398
+
399
+ disconnectBtn.addEventListener('click', () => {
400
+ voiceSDK.disconnect();
401
+ });
402
+
403
+ recordBtn.addEventListener('click', async () => {
404
+ try {
405
+ await voiceSDK.startRecording();
406
+ } catch (error) {
407
+ console.error('Recording start failed:', error);
408
+ addMessage('error', `Recording failed: ${error.message}`);
409
+ }
410
+ });
411
+
412
+ stopBtn.addEventListener('click', async () => {
413
+ try {
414
+ await voiceSDK.stopRecording();
415
+ } catch (error) {
416
+ console.error('Recording stop failed:', error);
417
+ addMessage('error', `Stop recording failed: ${error.message}`);
418
+ }
419
+ });
420
+
421
+ // Initialize Voice Button Component
422
+ function initializeVoiceButton() {
423
+ const container = document.getElementById('voice-button-container');
424
+
425
+ // Create a simple voice button using the VanillaVoiceButton
426
+ const voiceButton = new TTPAgentSDK.VanillaVoiceButton({
427
+ container: container,
428
+ websocketUrl: 'wss://speech.bidme.co.il/ws/conv',
429
+ agentId: 'demo_agent_123',
430
+ appId: 'demo_app_456',
431
+ onConnected: () => {
432
+ console.log('Voice Button connected');
433
+ addMessage('system', 'Voice Button connected');
434
+ },
435
+ onRecordingStarted: () => {
436
+ console.log('Voice Button recording started');
437
+ addMessage('system', 'Voice Button recording started');
438
+ },
439
+ onPlaybackStarted: () => {
440
+ console.log('Voice Button playback started');
441
+ addMessage('system', 'Voice Button playback started');
442
+ }
443
+ });
444
+ }
445
+
446
+ // Initialize everything when page loads
447
+ document.addEventListener('DOMContentLoaded', () => {
448
+ console.log('Initializing VoiceSDK example...');
449
+
450
+ // Check if SDK is loaded
451
+ if (typeof TTPAgentSDK === 'undefined') {
452
+ addMessage('error', 'VoiceSDK not loaded. Make sure the script is included.');
453
+ return;
454
+ }
455
+
456
+ initializeVoiceSDK();
457
+ initializeVoiceButton();
458
+
459
+ addMessage('system', 'VoiceSDK example initialized. Click "Connect" to start.');
460
+ console.log('VoiceSDK example ready!');
461
+ });
462
+ </script>
463
+ </body>
464
+ </html>
@@ -0,0 +1,224 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>TTP Agent SDK - Voice AI Integration</title>
7
+ <style>
8
+ body {
9
+ font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
10
+ max-width: 1200px;
11
+ margin: 0 auto;
12
+ padding: 20px;
13
+ background: #f8fafc;
14
+ color: #1e293b;
15
+ }
16
+ .header {
17
+ text-align: center;
18
+ margin-bottom: 40px;
19
+ padding: 40px 20px;
20
+ background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
21
+ color: white;
22
+ border-radius: 12px;
23
+ }
24
+ .header h1 {
25
+ margin: 0 0 10px 0;
26
+ font-size: 2.5rem;
27
+ }
28
+ .header p {
29
+ margin: 0;
30
+ font-size: 1.2rem;
31
+ opacity: 0.9;
32
+ }
33
+ .content {
34
+ display: grid;
35
+ grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
36
+ gap: 30px;
37
+ margin-bottom: 40px;
38
+ }
39
+ .card {
40
+ background: white;
41
+ padding: 30px;
42
+ border-radius: 12px;
43
+ box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
44
+ border: 1px solid #e2e8f0;
45
+ }
46
+ .card h2 {
47
+ margin-top: 0;
48
+ color: #4f46e5;
49
+ display: flex;
50
+ align-items: center;
51
+ gap: 10px;
52
+ }
53
+ .card p {
54
+ line-height: 1.6;
55
+ color: #64748b;
56
+ }
57
+ .demo-button {
58
+ display: inline-block;
59
+ background: #4f46e5;
60
+ color: white;
61
+ padding: 12px 24px;
62
+ text-decoration: none;
63
+ border-radius: 8px;
64
+ font-weight: 600;
65
+ transition: background-color 0.2s;
66
+ margin-top: 15px;
67
+ }
68
+ .demo-button:hover {
69
+ background: #4338ca;
70
+ }
71
+ .code-block {
72
+ background: #1e293b;
73
+ color: #e2e8f0;
74
+ padding: 20px;
75
+ border-radius: 8px;
76
+ font-family: 'Monaco', 'Menlo', monospace;
77
+ font-size: 14px;
78
+ overflow-x: auto;
79
+ margin: 20px 0;
80
+ }
81
+ .features {
82
+ background: white;
83
+ padding: 30px;
84
+ border-radius: 12px;
85
+ box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
86
+ margin-bottom: 30px;
87
+ }
88
+ .features h2 {
89
+ margin-top: 0;
90
+ color: #4f46e5;
91
+ }
92
+ .feature-grid {
93
+ display: grid;
94
+ grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
95
+ gap: 20px;
96
+ margin-top: 20px;
97
+ }
98
+ .feature {
99
+ padding: 20px;
100
+ background: #f8fafc;
101
+ border-radius: 8px;
102
+ border-left: 4px solid #4f46e5;
103
+ }
104
+ .feature h3 {
105
+ margin: 0 0 10px 0;
106
+ color: #1e293b;
107
+ }
108
+ .feature p {
109
+ margin: 0;
110
+ color: #64748b;
111
+ font-size: 14px;
112
+ }
113
+ .footer {
114
+ text-align: center;
115
+ padding: 30px;
116
+ color: #64748b;
117
+ border-top: 1px solid #e2e8f0;
118
+ }
119
+ </style>
120
+ </head>
121
+ <body>
122
+ <div class="header">
123
+ <h1>🎤 TTP Agent SDK</h1>
124
+ <p>Comprehensive Voice AI Integration for Web Applications</p>
125
+ </div>
126
+
127
+ <div class="features">
128
+ <h2>✨ Key Features</h2>
129
+ <div class="feature-grid">
130
+ <div class="feature">
131
+ <h3>🎤 Real-time Audio</h3>
132
+ <p>High-quality audio recording and playback with AudioWorklet</p>
133
+ </div>
134
+ <div class="feature">
135
+ <h3>🔄 WebSocket Communication</h3>
136
+ <p>Real-time bidirectional communication with authentication</p>
137
+ </div>
138
+ <div class="feature">
139
+ <h3>⚛️ React Components</h3>
140
+ <p>Ready-to-use React components for modern applications</p>
141
+ </div>
142
+ <div class="feature">
143
+ <h3>🌐 Vanilla JavaScript</h3>
144
+ <p>Works with any JavaScript framework or vanilla JS</p>
145
+ </div>
146
+ <div class="feature">
147
+ <h3>🔒 Multiple Auth Methods</h3>
148
+ <p>Support for signed links and direct agent access</p>
149
+ </div>
150
+ <div class="feature">
151
+ <h3>📱 Responsive Widget</h3>
152
+ <p>Pre-built UI widget for quick integration</p>
153
+ </div>
154
+ </div>
155
+ </div>
156
+
157
+ <div class="content">
158
+ <div class="card">
159
+ <h2>🚀 Quick Start</h2>
160
+ <p>Get started with the pre-built widget in just a few lines of code.</p>
161
+ <div class="code-block">
162
+ &lt;script src="https://cdn.talktopc.com/agent-widget.js"&gt;&lt;/script&gt;
163
+ &lt;script&gt;
164
+ TTPAgentSDK.AgentWidget.init({
165
+ agentId: 'your_agent_id',
166
+ getSessionUrl: 'https://your-backend.com/api/get-session'
167
+ });
168
+ &lt;/script&gt;
169
+ </div>
170
+ <a href="examples/test.html" class="demo-button">Try Widget Demo</a>
171
+ </div>
172
+
173
+ <div class="card">
174
+ <h2>⚛️ React Integration</h2>
175
+ <p>Use the VoiceButton component in your React applications.</p>
176
+ <div class="code-block">
177
+ import { VoiceButton } from 'ttp-agent-sdk';
178
+
179
+ &lt;VoiceButton
180
+ websocketUrl="wss://speech.bidme.co.il/ws/conv"
181
+ agentId="your_agent_id"
182
+ appId="your_app_id"
183
+ /&gt;
184
+ </div>
185
+ <a href="examples/react-example.html" class="demo-button">View React Example</a>
186
+ </div>
187
+
188
+ <div class="card">
189
+ <h2>🌐 Vanilla JavaScript</h2>
190
+ <p>Integrate with any JavaScript framework or vanilla JS.</p>
191
+ <div class="code-block">
192
+ import { VoiceSDK } from 'ttp-agent-sdk';
193
+
194
+ const voiceSDK = new VoiceSDK({
195
+ websocketUrl: 'wss://speech.bidme.co.il/ws/conv',
196
+ agentId: 'your_agent_id',
197
+ appId: 'your_app_id'
198
+ });
199
+
200
+ await voiceSDK.connect();
201
+ </div>
202
+ <a href="examples/vanilla-example.html" class="demo-button">Try Vanilla Demo</a>
203
+ </div>
204
+
205
+ <div class="card">
206
+ <h2>📚 Documentation</h2>
207
+ <p>Complete documentation and API reference for all features.</p>
208
+ <ul style="color: #64748b; line-height: 1.8;">
209
+ <li>Installation & Setup</li>
210
+ <li>Authentication Methods</li>
211
+ <li>Event Handling</li>
212
+ <li>API Reference</li>
213
+ <li>Examples & Tutorials</li>
214
+ </ul>
215
+ <a href="README.md" class="demo-button">View Documentation</a>
216
+ </div>
217
+ </div>
218
+
219
+ <div class="footer">
220
+ <p>Built with ❤️ by the TTP Agent Team</p>
221
+ <p>Version 2.0.0 | <a href="https://github.com/yinon11/ttp-sdk-front" style="color: #4f46e5;">GitHub Repository</a></p>
222
+ </div>
223
+ </body>
224
+ </html>