ttp-agent-sdk 2.1.12 → 2.1.13
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.
- package/README.md +2 -1
- package/dist/agent-widget.js +1 -1
- package/dist/agent-widget.js.map +1 -1
- package/dist/examples/test-agent-app.html +205 -38
- package/dist/examples/test.html +16 -0
- package/dist/index.html +1 -1
- package/examples/test-agent-app.html +205 -38
- package/examples/test.html +16 -0
- package/package.json +1 -1
|
@@ -84,6 +84,54 @@
|
|
|
84
84
|
font-size: 12px;
|
|
85
85
|
overflow-x: auto;
|
|
86
86
|
margin: 20px 0;
|
|
87
|
+
white-space: pre;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
.code-block pre {
|
|
91
|
+
margin: 0;
|
|
92
|
+
font-family: inherit;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
.code-block code {
|
|
96
|
+
font-family: inherit;
|
|
97
|
+
white-space: pre;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
.tabs {
|
|
101
|
+
display: flex;
|
|
102
|
+
gap: 10px;
|
|
103
|
+
margin-bottom: 15px;
|
|
104
|
+
border-bottom: 2px solid #E5E7EB;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
.tab {
|
|
108
|
+
background: none;
|
|
109
|
+
border: none;
|
|
110
|
+
padding: 12px 24px;
|
|
111
|
+
cursor: pointer;
|
|
112
|
+
font-size: 14px;
|
|
113
|
+
font-weight: 600;
|
|
114
|
+
color: #6B7280;
|
|
115
|
+
border-bottom: 3px solid transparent;
|
|
116
|
+
transition: all 0.2s;
|
|
117
|
+
margin-bottom: -2px;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
.tab:hover {
|
|
121
|
+
color: #4F46E5;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
.tab.active {
|
|
125
|
+
color: #4F46E5;
|
|
126
|
+
border-bottom-color: #4F46E5;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
.tab-content {
|
|
130
|
+
display: none;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
.tab-content.active {
|
|
134
|
+
display: block;
|
|
87
135
|
}
|
|
88
136
|
</style>
|
|
89
137
|
</head>
|
|
@@ -122,28 +170,157 @@
|
|
|
122
170
|
</div>
|
|
123
171
|
|
|
124
172
|
<h2>Implementation Code:</h2>
|
|
125
|
-
<div class="
|
|
126
|
-
|
|
173
|
+
<div class="tabs">
|
|
174
|
+
<button class="tab active" onclick="switchTab('simple')">Simple</button>
|
|
175
|
+
<button class="tab" onclick="switchTab('advanced')">All Options</button>
|
|
176
|
+
</div>
|
|
177
|
+
|
|
178
|
+
<div id="simple-tab" class="tab-content active">
|
|
179
|
+
<div class="code-block"><pre><code>const widget = new TTPAgentSDK.AgentWidget({
|
|
127
180
|
agentId: 'agent_87c4a55a1',
|
|
128
181
|
appId: 'app_Bc01EqMQt2Euehl4qqZSi6l3FJP42Q9vJ0pC',
|
|
129
182
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
183
|
+
primaryColor: '#10B981',
|
|
184
|
+
position: 'bottom-right'
|
|
185
|
+
});</code></pre></div>
|
|
186
|
+
</div>
|
|
187
|
+
|
|
188
|
+
<div id="advanced-tab" class="tab-content">
|
|
189
|
+
<div class="code-block"><pre><code>const widget = new TTPAgentSDK.AgentWidget({
|
|
190
|
+
// Required
|
|
191
|
+
agentId: 'agent_87c4a55a1',
|
|
192
|
+
appId: 'app_Bc01EqMQt2Euehl4qqZSi6l3FJP42Q9vJ0pC',
|
|
193
|
+
|
|
194
|
+
// Optional: getSessionUrl - only needed for signed links or custom URL logic
|
|
195
|
+
// getSessionUrl: async ({ agentId, appId, variables }) => {
|
|
196
|
+
// const response = await fetch('https://your-backend.com/api/signed-url', {
|
|
197
|
+
// method: 'POST',
|
|
198
|
+
// headers: { 'Content-Type': 'application/json' },
|
|
199
|
+
// body: JSON.stringify({ agentId, appId, variables })
|
|
200
|
+
// });
|
|
201
|
+
// const data = await response.json();
|
|
202
|
+
// return data.signedUrl;
|
|
203
|
+
// },
|
|
204
|
+
|
|
205
|
+
// Simple styling (backward compatible)
|
|
206
|
+
primaryColor: '#10B981',
|
|
207
|
+
position: 'bottom-right', // or use advanced position object below
|
|
208
|
+
|
|
209
|
+
// Advanced Icon Configuration
|
|
210
|
+
// icon: {
|
|
211
|
+
// type: 'microphone', // 'microphone', 'custom', 'emoji', 'text'
|
|
212
|
+
// customImage: 'https://example.com/icon.png', // For type: 'custom'
|
|
213
|
+
// emoji: '🎤', // For type: 'emoji'
|
|
214
|
+
// text: 'AI', // For type: 'text'
|
|
215
|
+
// size: 'medium' // 'small', 'medium', 'large', 'xl'
|
|
216
|
+
// },
|
|
217
|
+
|
|
218
|
+
// Advanced Positioning
|
|
219
|
+
// position: {
|
|
220
|
+
// vertical: 'bottom', // 'top', 'bottom', 'center'
|
|
221
|
+
// horizontal: 'right', // 'left', 'right', 'center'
|
|
222
|
+
// offset: { x: 20, y: 20 } // Custom offset in pixels
|
|
223
|
+
// },
|
|
224
|
+
|
|
225
|
+
// Button Configuration
|
|
226
|
+
// button: {
|
|
227
|
+
// size: 'medium', // 'small', 'medium', 'large', 'xl'
|
|
228
|
+
// shape: 'circle', // 'circle', 'square', 'rounded'
|
|
229
|
+
// primaryColor: '#10B981',
|
|
230
|
+
// hoverColor: '#059669',
|
|
231
|
+
// activeColor: '#EF4444',
|
|
232
|
+
// shadow: true,
|
|
233
|
+
// shadowColor: 'rgba(0,0,0,0.15)'
|
|
234
|
+
// },
|
|
235
|
+
|
|
236
|
+
// Panel Configuration
|
|
237
|
+
// panel: {
|
|
238
|
+
// width: 350,
|
|
239
|
+
// height: 500,
|
|
240
|
+
// borderRadius: 12,
|
|
241
|
+
// backgroundColor: 'rgba(255,255,255,0.95)',
|
|
242
|
+
// backdropFilter: 'blur(10px)', // Glass morphism effect
|
|
243
|
+
// border: '1px solid rgba(0,0,0,0.1)'
|
|
244
|
+
// },
|
|
245
|
+
|
|
246
|
+
// Header Configuration
|
|
247
|
+
// header: {
|
|
248
|
+
// title: 'Voice Assistant',
|
|
249
|
+
// showTitle: true,
|
|
250
|
+
// backgroundColor: null, // Uses button primaryColor if null
|
|
251
|
+
// textColor: '#FFFFFF',
|
|
252
|
+
// showCloseButton: true
|
|
253
|
+
// },
|
|
254
|
+
|
|
255
|
+
// Messages Configuration
|
|
256
|
+
// messages: {
|
|
257
|
+
// userBackgroundColor: '#E5E7EB',
|
|
258
|
+
// agentBackgroundColor: '#F3F4F6',
|
|
259
|
+
// systemBackgroundColor: '#DCFCE7',
|
|
260
|
+
// errorBackgroundColor: '#FEE2E2',
|
|
261
|
+
// textColor: '#1F2937',
|
|
262
|
+
// fontSize: '14px',
|
|
263
|
+
// borderRadius: 8
|
|
264
|
+
// },
|
|
265
|
+
|
|
266
|
+
// Animation Configuration
|
|
267
|
+
// animation: {
|
|
268
|
+
// enableHover: true,
|
|
269
|
+
// enablePulse: true,
|
|
270
|
+
// enableSlide: true,
|
|
271
|
+
// duration: 0.3
|
|
272
|
+
// },
|
|
273
|
+
|
|
274
|
+
// Behavior Configuration
|
|
275
|
+
// behavior: {
|
|
276
|
+
// autoOpen: false, // Automatically open panel on load
|
|
277
|
+
// autoConnect: false, // Automatically connect on load
|
|
278
|
+
// showWelcomeMessage: true,
|
|
279
|
+
// welcomeMessage: 'Hello! How can I help you today?'
|
|
280
|
+
// },
|
|
136
281
|
|
|
282
|
+
// Accessibility Configuration
|
|
283
|
+
// accessibility: {
|
|
284
|
+
// ariaLabel: 'Voice Assistant',
|
|
285
|
+
// ariaDescription: 'Click to open voice assistant',
|
|
286
|
+
// keyboardNavigation: true // ESC key to close
|
|
287
|
+
// },
|
|
288
|
+
|
|
289
|
+
// Custom CSS
|
|
290
|
+
// customStyles: `
|
|
291
|
+
// #agent-widget {
|
|
292
|
+
// /* Your custom CSS here */
|
|
293
|
+
// }
|
|
294
|
+
// `,
|
|
295
|
+
|
|
296
|
+
// Variables for your agent/backend
|
|
137
297
|
variables: {
|
|
138
298
|
testMode: true,
|
|
139
299
|
userName: 'Test User',
|
|
140
300
|
page: 'test-agent-app.html'
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
primaryColor: '#10B981',
|
|
144
|
-
position: 'bottom-right'
|
|
145
|
-
});
|
|
301
|
+
}
|
|
302
|
+
});</code></pre></div>
|
|
146
303
|
</div>
|
|
304
|
+
|
|
305
|
+
<script>
|
|
306
|
+
function switchTab(tabName) {
|
|
307
|
+
// Hide all tab contents
|
|
308
|
+
document.querySelectorAll('.tab-content').forEach(content => {
|
|
309
|
+
content.classList.remove('active');
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
// Remove active class from all tabs
|
|
313
|
+
document.querySelectorAll('.tab').forEach(tab => {
|
|
314
|
+
tab.classList.remove('active');
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
// Show selected tab content
|
|
318
|
+
document.getElementById(tabName + '-tab').classList.add('active');
|
|
319
|
+
|
|
320
|
+
// Add active class to clicked tab
|
|
321
|
+
event.target.classList.add('active');
|
|
322
|
+
}
|
|
323
|
+
</script>
|
|
147
324
|
|
|
148
325
|
<h2>Manual Tests:</h2>
|
|
149
326
|
<button onclick="testMicButton()">Test Mic Button Click</button>
|
|
@@ -200,34 +377,16 @@ const widget = new TTPAgentSDK.AgentWidget({
|
|
|
200
377
|
}
|
|
201
378
|
|
|
202
379
|
// Create a new AgentWidget instance with agent ID + app ID
|
|
380
|
+
// getSessionUrl is now OPTIONAL - widget will auto-construct URL from agentId/appId
|
|
203
381
|
const widget = new TTPAgentSDK.AgentWidget({
|
|
204
382
|
agentId: 'agent_87c4a55a1',
|
|
205
383
|
appId: 'app_Bc01EqMQt2Euehl4qqZSi6l3FJP42Q9vJ0pC',
|
|
206
384
|
|
|
207
|
-
//
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
console.log('App ID:', appId);
|
|
211
|
-
console.log('Variables:', variables);
|
|
212
|
-
|
|
213
|
-
updateStatus('Creating direct session URL...', 'info');
|
|
214
|
-
|
|
215
|
-
try {
|
|
216
|
-
// Direct WebSocket URL construction with demo flag
|
|
217
|
-
const wsUrl = `wss://speech.talktopc.com/ws/conv?agentId=${agentId}&appId=${appId}&demo=true`;
|
|
218
|
-
|
|
219
|
-
console.log('Generated direct session URL:', wsUrl);
|
|
220
|
-
updateStatus('Direct session URL created ✓', 'success');
|
|
221
|
-
|
|
222
|
-
return wsUrl;
|
|
223
|
-
} catch (error) {
|
|
224
|
-
console.error('Failed to create direct session URL:', error);
|
|
225
|
-
updateStatus('Failed to create direct session URL ✗', 'error');
|
|
226
|
-
throw error;
|
|
227
|
-
}
|
|
228
|
-
},
|
|
385
|
+
// getSessionUrl is OPTIONAL - omitted here, so widget auto-constructs the WebSocket URL
|
|
386
|
+
// If you need signed links or custom URL logic, you can provide it:
|
|
387
|
+
// getSessionUrl: async ({ agentId, appId, variables }) => { ... }
|
|
229
388
|
|
|
230
|
-
// Pass
|
|
389
|
+
// Optional: Pass variables for your agent/backend
|
|
231
390
|
variables: {
|
|
232
391
|
testMode: true,
|
|
233
392
|
userName: 'Test User',
|
|
@@ -235,9 +394,17 @@ const widget = new TTPAgentSDK.AgentWidget({
|
|
|
235
394
|
connectionType: 'direct'
|
|
236
395
|
},
|
|
237
396
|
|
|
238
|
-
// Customize appearance
|
|
397
|
+
// Customize appearance (using simple config - backward compatible)
|
|
239
398
|
primaryColor: '#10B981',
|
|
240
|
-
position: 'bottom-right'
|
|
399
|
+
position: 'bottom-right',
|
|
400
|
+
|
|
401
|
+
// Enhanced features are now available but using defaults
|
|
402
|
+
// You can optionally add:
|
|
403
|
+
// icon: { type: 'emoji', emoji: '🎤', size: 'large' },
|
|
404
|
+
// button: { size: 'large', shape: 'circle' },
|
|
405
|
+
// panel: { width: 400, height: 600 },
|
|
406
|
+
// header: { title: 'My Voice Assistant' },
|
|
407
|
+
// animation: { enableHover: true, enablePulse: true }
|
|
241
408
|
});
|
|
242
409
|
|
|
243
410
|
// Store widget reference for testing (like the working implementation)
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8">
|
|
5
|
+
<meta http-equiv="refresh" content="0; url=test-agent-app.html">
|
|
6
|
+
<title>Redirecting to Test Page...</title>
|
|
7
|
+
<script>
|
|
8
|
+
// Immediate redirect
|
|
9
|
+
window.location.href = 'test-agent-app.html';
|
|
10
|
+
</script>
|
|
11
|
+
</head>
|
|
12
|
+
<body>
|
|
13
|
+
<p>If you are not redirected automatically, <a href="test-agent-app.html">click here</a>.</p>
|
|
14
|
+
</body>
|
|
15
|
+
</html>
|
|
16
|
+
|
package/dist/index.html
CHANGED
|
@@ -84,6 +84,54 @@
|
|
|
84
84
|
font-size: 12px;
|
|
85
85
|
overflow-x: auto;
|
|
86
86
|
margin: 20px 0;
|
|
87
|
+
white-space: pre;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
.code-block pre {
|
|
91
|
+
margin: 0;
|
|
92
|
+
font-family: inherit;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
.code-block code {
|
|
96
|
+
font-family: inherit;
|
|
97
|
+
white-space: pre;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
.tabs {
|
|
101
|
+
display: flex;
|
|
102
|
+
gap: 10px;
|
|
103
|
+
margin-bottom: 15px;
|
|
104
|
+
border-bottom: 2px solid #E5E7EB;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
.tab {
|
|
108
|
+
background: none;
|
|
109
|
+
border: none;
|
|
110
|
+
padding: 12px 24px;
|
|
111
|
+
cursor: pointer;
|
|
112
|
+
font-size: 14px;
|
|
113
|
+
font-weight: 600;
|
|
114
|
+
color: #6B7280;
|
|
115
|
+
border-bottom: 3px solid transparent;
|
|
116
|
+
transition: all 0.2s;
|
|
117
|
+
margin-bottom: -2px;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
.tab:hover {
|
|
121
|
+
color: #4F46E5;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
.tab.active {
|
|
125
|
+
color: #4F46E5;
|
|
126
|
+
border-bottom-color: #4F46E5;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
.tab-content {
|
|
130
|
+
display: none;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
.tab-content.active {
|
|
134
|
+
display: block;
|
|
87
135
|
}
|
|
88
136
|
</style>
|
|
89
137
|
</head>
|
|
@@ -122,28 +170,157 @@
|
|
|
122
170
|
</div>
|
|
123
171
|
|
|
124
172
|
<h2>Implementation Code:</h2>
|
|
125
|
-
<div class="
|
|
126
|
-
|
|
173
|
+
<div class="tabs">
|
|
174
|
+
<button class="tab active" onclick="switchTab('simple')">Simple</button>
|
|
175
|
+
<button class="tab" onclick="switchTab('advanced')">All Options</button>
|
|
176
|
+
</div>
|
|
177
|
+
|
|
178
|
+
<div id="simple-tab" class="tab-content active">
|
|
179
|
+
<div class="code-block"><pre><code>const widget = new TTPAgentSDK.AgentWidget({
|
|
127
180
|
agentId: 'agent_87c4a55a1',
|
|
128
181
|
appId: 'app_Bc01EqMQt2Euehl4qqZSi6l3FJP42Q9vJ0pC',
|
|
129
182
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
183
|
+
primaryColor: '#10B981',
|
|
184
|
+
position: 'bottom-right'
|
|
185
|
+
});</code></pre></div>
|
|
186
|
+
</div>
|
|
187
|
+
|
|
188
|
+
<div id="advanced-tab" class="tab-content">
|
|
189
|
+
<div class="code-block"><pre><code>const widget = new TTPAgentSDK.AgentWidget({
|
|
190
|
+
// Required
|
|
191
|
+
agentId: 'agent_87c4a55a1',
|
|
192
|
+
appId: 'app_Bc01EqMQt2Euehl4qqZSi6l3FJP42Q9vJ0pC',
|
|
193
|
+
|
|
194
|
+
// Optional: getSessionUrl - only needed for signed links or custom URL logic
|
|
195
|
+
// getSessionUrl: async ({ agentId, appId, variables }) => {
|
|
196
|
+
// const response = await fetch('https://your-backend.com/api/signed-url', {
|
|
197
|
+
// method: 'POST',
|
|
198
|
+
// headers: { 'Content-Type': 'application/json' },
|
|
199
|
+
// body: JSON.stringify({ agentId, appId, variables })
|
|
200
|
+
// });
|
|
201
|
+
// const data = await response.json();
|
|
202
|
+
// return data.signedUrl;
|
|
203
|
+
// },
|
|
204
|
+
|
|
205
|
+
// Simple styling (backward compatible)
|
|
206
|
+
primaryColor: '#10B981',
|
|
207
|
+
position: 'bottom-right', // or use advanced position object below
|
|
208
|
+
|
|
209
|
+
// Advanced Icon Configuration
|
|
210
|
+
// icon: {
|
|
211
|
+
// type: 'microphone', // 'microphone', 'custom', 'emoji', 'text'
|
|
212
|
+
// customImage: 'https://example.com/icon.png', // For type: 'custom'
|
|
213
|
+
// emoji: '🎤', // For type: 'emoji'
|
|
214
|
+
// text: 'AI', // For type: 'text'
|
|
215
|
+
// size: 'medium' // 'small', 'medium', 'large', 'xl'
|
|
216
|
+
// },
|
|
217
|
+
|
|
218
|
+
// Advanced Positioning
|
|
219
|
+
// position: {
|
|
220
|
+
// vertical: 'bottom', // 'top', 'bottom', 'center'
|
|
221
|
+
// horizontal: 'right', // 'left', 'right', 'center'
|
|
222
|
+
// offset: { x: 20, y: 20 } // Custom offset in pixels
|
|
223
|
+
// },
|
|
224
|
+
|
|
225
|
+
// Button Configuration
|
|
226
|
+
// button: {
|
|
227
|
+
// size: 'medium', // 'small', 'medium', 'large', 'xl'
|
|
228
|
+
// shape: 'circle', // 'circle', 'square', 'rounded'
|
|
229
|
+
// primaryColor: '#10B981',
|
|
230
|
+
// hoverColor: '#059669',
|
|
231
|
+
// activeColor: '#EF4444',
|
|
232
|
+
// shadow: true,
|
|
233
|
+
// shadowColor: 'rgba(0,0,0,0.15)'
|
|
234
|
+
// },
|
|
235
|
+
|
|
236
|
+
// Panel Configuration
|
|
237
|
+
// panel: {
|
|
238
|
+
// width: 350,
|
|
239
|
+
// height: 500,
|
|
240
|
+
// borderRadius: 12,
|
|
241
|
+
// backgroundColor: 'rgba(255,255,255,0.95)',
|
|
242
|
+
// backdropFilter: 'blur(10px)', // Glass morphism effect
|
|
243
|
+
// border: '1px solid rgba(0,0,0,0.1)'
|
|
244
|
+
// },
|
|
245
|
+
|
|
246
|
+
// Header Configuration
|
|
247
|
+
// header: {
|
|
248
|
+
// title: 'Voice Assistant',
|
|
249
|
+
// showTitle: true,
|
|
250
|
+
// backgroundColor: null, // Uses button primaryColor if null
|
|
251
|
+
// textColor: '#FFFFFF',
|
|
252
|
+
// showCloseButton: true
|
|
253
|
+
// },
|
|
254
|
+
|
|
255
|
+
// Messages Configuration
|
|
256
|
+
// messages: {
|
|
257
|
+
// userBackgroundColor: '#E5E7EB',
|
|
258
|
+
// agentBackgroundColor: '#F3F4F6',
|
|
259
|
+
// systemBackgroundColor: '#DCFCE7',
|
|
260
|
+
// errorBackgroundColor: '#FEE2E2',
|
|
261
|
+
// textColor: '#1F2937',
|
|
262
|
+
// fontSize: '14px',
|
|
263
|
+
// borderRadius: 8
|
|
264
|
+
// },
|
|
265
|
+
|
|
266
|
+
// Animation Configuration
|
|
267
|
+
// animation: {
|
|
268
|
+
// enableHover: true,
|
|
269
|
+
// enablePulse: true,
|
|
270
|
+
// enableSlide: true,
|
|
271
|
+
// duration: 0.3
|
|
272
|
+
// },
|
|
273
|
+
|
|
274
|
+
// Behavior Configuration
|
|
275
|
+
// behavior: {
|
|
276
|
+
// autoOpen: false, // Automatically open panel on load
|
|
277
|
+
// autoConnect: false, // Automatically connect on load
|
|
278
|
+
// showWelcomeMessage: true,
|
|
279
|
+
// welcomeMessage: 'Hello! How can I help you today?'
|
|
280
|
+
// },
|
|
136
281
|
|
|
282
|
+
// Accessibility Configuration
|
|
283
|
+
// accessibility: {
|
|
284
|
+
// ariaLabel: 'Voice Assistant',
|
|
285
|
+
// ariaDescription: 'Click to open voice assistant',
|
|
286
|
+
// keyboardNavigation: true // ESC key to close
|
|
287
|
+
// },
|
|
288
|
+
|
|
289
|
+
// Custom CSS
|
|
290
|
+
// customStyles: `
|
|
291
|
+
// #agent-widget {
|
|
292
|
+
// /* Your custom CSS here */
|
|
293
|
+
// }
|
|
294
|
+
// `,
|
|
295
|
+
|
|
296
|
+
// Variables for your agent/backend
|
|
137
297
|
variables: {
|
|
138
298
|
testMode: true,
|
|
139
299
|
userName: 'Test User',
|
|
140
300
|
page: 'test-agent-app.html'
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
primaryColor: '#10B981',
|
|
144
|
-
position: 'bottom-right'
|
|
145
|
-
});
|
|
301
|
+
}
|
|
302
|
+
});</code></pre></div>
|
|
146
303
|
</div>
|
|
304
|
+
|
|
305
|
+
<script>
|
|
306
|
+
function switchTab(tabName) {
|
|
307
|
+
// Hide all tab contents
|
|
308
|
+
document.querySelectorAll('.tab-content').forEach(content => {
|
|
309
|
+
content.classList.remove('active');
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
// Remove active class from all tabs
|
|
313
|
+
document.querySelectorAll('.tab').forEach(tab => {
|
|
314
|
+
tab.classList.remove('active');
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
// Show selected tab content
|
|
318
|
+
document.getElementById(tabName + '-tab').classList.add('active');
|
|
319
|
+
|
|
320
|
+
// Add active class to clicked tab
|
|
321
|
+
event.target.classList.add('active');
|
|
322
|
+
}
|
|
323
|
+
</script>
|
|
147
324
|
|
|
148
325
|
<h2>Manual Tests:</h2>
|
|
149
326
|
<button onclick="testMicButton()">Test Mic Button Click</button>
|
|
@@ -200,34 +377,16 @@ const widget = new TTPAgentSDK.AgentWidget({
|
|
|
200
377
|
}
|
|
201
378
|
|
|
202
379
|
// Create a new AgentWidget instance with agent ID + app ID
|
|
380
|
+
// getSessionUrl is now OPTIONAL - widget will auto-construct URL from agentId/appId
|
|
203
381
|
const widget = new TTPAgentSDK.AgentWidget({
|
|
204
382
|
agentId: 'agent_87c4a55a1',
|
|
205
383
|
appId: 'app_Bc01EqMQt2Euehl4qqZSi6l3FJP42Q9vJ0pC',
|
|
206
384
|
|
|
207
|
-
//
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
console.log('App ID:', appId);
|
|
211
|
-
console.log('Variables:', variables);
|
|
212
|
-
|
|
213
|
-
updateStatus('Creating direct session URL...', 'info');
|
|
214
|
-
|
|
215
|
-
try {
|
|
216
|
-
// Direct WebSocket URL construction with demo flag
|
|
217
|
-
const wsUrl = `wss://speech.talktopc.com/ws/conv?agentId=${agentId}&appId=${appId}&demo=true`;
|
|
218
|
-
|
|
219
|
-
console.log('Generated direct session URL:', wsUrl);
|
|
220
|
-
updateStatus('Direct session URL created ✓', 'success');
|
|
221
|
-
|
|
222
|
-
return wsUrl;
|
|
223
|
-
} catch (error) {
|
|
224
|
-
console.error('Failed to create direct session URL:', error);
|
|
225
|
-
updateStatus('Failed to create direct session URL ✗', 'error');
|
|
226
|
-
throw error;
|
|
227
|
-
}
|
|
228
|
-
},
|
|
385
|
+
// getSessionUrl is OPTIONAL - omitted here, so widget auto-constructs the WebSocket URL
|
|
386
|
+
// If you need signed links or custom URL logic, you can provide it:
|
|
387
|
+
// getSessionUrl: async ({ agentId, appId, variables }) => { ... }
|
|
229
388
|
|
|
230
|
-
// Pass
|
|
389
|
+
// Optional: Pass variables for your agent/backend
|
|
231
390
|
variables: {
|
|
232
391
|
testMode: true,
|
|
233
392
|
userName: 'Test User',
|
|
@@ -235,9 +394,17 @@ const widget = new TTPAgentSDK.AgentWidget({
|
|
|
235
394
|
connectionType: 'direct'
|
|
236
395
|
},
|
|
237
396
|
|
|
238
|
-
// Customize appearance
|
|
397
|
+
// Customize appearance (using simple config - backward compatible)
|
|
239
398
|
primaryColor: '#10B981',
|
|
240
|
-
position: 'bottom-right'
|
|
399
|
+
position: 'bottom-right',
|
|
400
|
+
|
|
401
|
+
// Enhanced features are now available but using defaults
|
|
402
|
+
// You can optionally add:
|
|
403
|
+
// icon: { type: 'emoji', emoji: '🎤', size: 'large' },
|
|
404
|
+
// button: { size: 'large', shape: 'circle' },
|
|
405
|
+
// panel: { width: 400, height: 600 },
|
|
406
|
+
// header: { title: 'My Voice Assistant' },
|
|
407
|
+
// animation: { enableHover: true, enablePulse: true }
|
|
241
408
|
});
|
|
242
409
|
|
|
243
410
|
// Store widget reference for testing (like the working implementation)
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8">
|
|
5
|
+
<meta http-equiv="refresh" content="0; url=test-agent-app.html">
|
|
6
|
+
<title>Redirecting to Test Page...</title>
|
|
7
|
+
<script>
|
|
8
|
+
// Immediate redirect
|
|
9
|
+
window.location.href = 'test-agent-app.html';
|
|
10
|
+
</script>
|
|
11
|
+
</head>
|
|
12
|
+
<body>
|
|
13
|
+
<p>If you are not redirected automatically, <a href="test-agent-app.html">click here</a>.</p>
|
|
14
|
+
</body>
|
|
15
|
+
</html>
|
|
16
|
+
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ttp-agent-sdk",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.13",
|
|
4
4
|
"description": "Comprehensive Voice Agent SDK with Enhanced Customizable Widget - Real-time audio, WebSocket communication, React components, and extensive customization options",
|
|
5
5
|
"main": "dist/agent-widget.js",
|
|
6
6
|
"module": "dist/agent-widget.js",
|