ttp-agent-sdk 2.1.13 → 2.2.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.
- package/dist/agent-widget.js +1 -1
- package/dist/agent-widget.js.map +1 -1
- package/dist/examples/test-agent-app.html +585 -11
- package/examples/test-agent-app.html +585 -11
- package/package.json +1 -1
|
@@ -133,6 +133,69 @@
|
|
|
133
133
|
.tab-content.active {
|
|
134
134
|
display: block;
|
|
135
135
|
}
|
|
136
|
+
|
|
137
|
+
.controls-panel {
|
|
138
|
+
background: white;
|
|
139
|
+
border: 2px solid #E5E7EB;
|
|
140
|
+
border-radius: 8px;
|
|
141
|
+
padding: 20px;
|
|
142
|
+
margin: 20px 0;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
.control-row {
|
|
146
|
+
display: grid;
|
|
147
|
+
grid-template-columns: 150px 150px 1fr auto;
|
|
148
|
+
gap: 12px;
|
|
149
|
+
align-items: center;
|
|
150
|
+
margin-bottom: 12px;
|
|
151
|
+
padding: 12px;
|
|
152
|
+
background: #F9FAFB;
|
|
153
|
+
border-radius: 6px;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
.control-row label {
|
|
157
|
+
font-weight: 600;
|
|
158
|
+
color: #374151;
|
|
159
|
+
font-size: 13px;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
.control-row select,
|
|
163
|
+
.control-row input[type="text"],
|
|
164
|
+
.control-row input[type="color"] {
|
|
165
|
+
padding: 8px 12px;
|
|
166
|
+
border: 1px solid #D1D5DB;
|
|
167
|
+
border-radius: 4px;
|
|
168
|
+
font-size: 14px;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
.control-row input[type="color"] {
|
|
172
|
+
width: 60px;
|
|
173
|
+
height: 40px;
|
|
174
|
+
cursor: pointer;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
.control-row button {
|
|
178
|
+
padding: 8px 16px;
|
|
179
|
+
background: #3B82F6;
|
|
180
|
+
color: white;
|
|
181
|
+
border: none;
|
|
182
|
+
border-radius: 4px;
|
|
183
|
+
cursor: pointer;
|
|
184
|
+
font-size: 13px;
|
|
185
|
+
margin: 0;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
.control-row button:hover {
|
|
189
|
+
background: #2563EB;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
.control-row button.remove {
|
|
193
|
+
background: #EF4444;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
.control-row button.remove:hover {
|
|
197
|
+
background: #DC2626;
|
|
198
|
+
}
|
|
136
199
|
</style>
|
|
137
200
|
</head>
|
|
138
201
|
<body>
|
|
@@ -153,7 +216,7 @@
|
|
|
153
216
|
<ol style="margin: 10px 0 0 20px; line-height: 1.8;">
|
|
154
217
|
<li>Look for the floating voice button in the bottom-right corner</li>
|
|
155
218
|
<li>Click the button to open the widget</li>
|
|
156
|
-
<li>Click the
|
|
219
|
+
<li>Click the voice button to start (will request microphone permission)</li>
|
|
157
220
|
<li>Widget will connect directly using agent ID + app ID</li>
|
|
158
221
|
<li>Check the status updates below</li>
|
|
159
222
|
</ol>
|
|
@@ -177,14 +240,67 @@
|
|
|
177
240
|
|
|
178
241
|
<div id="simple-tab" class="tab-content active">
|
|
179
242
|
<div class="code-block"><pre><code>const widget = new TTPAgentSDK.AgentWidget({
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
243
|
+
agentId: 'agent_87c4a55a1',
|
|
244
|
+
appId: 'app_Bc01EqMQt2Euehl4qqZSi6l3FJP42Q9vJ0pC',
|
|
245
|
+
|
|
246
|
+
primaryColor: '#10B981',
|
|
247
|
+
position: 'bottom-right',
|
|
248
|
+
|
|
249
|
+
// Icon configuration
|
|
250
|
+
icon: {
|
|
251
|
+
type: 'custom',
|
|
252
|
+
customImage: 'https://talktopc.com/logo192.png',
|
|
253
|
+
size: 'medium'
|
|
254
|
+
},
|
|
255
|
+
|
|
256
|
+
// Floating button (main button) colors - WHITE
|
|
257
|
+
button: {
|
|
258
|
+
backgroundColor: '#FFFFFF', // White floating button
|
|
259
|
+
hoverColor: '#E5E7EB' // Gray on hover
|
|
260
|
+
},
|
|
261
|
+
|
|
262
|
+
// Header (top of panel) colors - LIGHT PURPLE
|
|
263
|
+
header: {
|
|
264
|
+
title: 'TTP Support',
|
|
265
|
+
backgroundColor: '#A78BFA', // Light purple header
|
|
266
|
+
textColor: '#FFFFFF'
|
|
267
|
+
},
|
|
268
|
+
|
|
269
|
+
// Mic button (inside panel) colors - GRAY
|
|
270
|
+
panel: {
|
|
271
|
+
micButtonColor: '#E5E7EB', // Gray mic button
|
|
272
|
+
micButtonActiveColor: '#EF4444' // Red when active
|
|
273
|
+
}
|
|
185
274
|
});</code></pre></div>
|
|
186
275
|
</div>
|
|
187
276
|
|
|
277
|
+
<h2>🎨 Interactive Customization</h2>
|
|
278
|
+
<div class="controls-panel">
|
|
279
|
+
<div style="margin-bottom: 16px; padding-bottom: 16px; border-bottom: 1px solid #E5E7EB;">
|
|
280
|
+
<strong style="color: #374151;">Customize widget colors and properties in real-time:</strong>
|
|
281
|
+
</div>
|
|
282
|
+
|
|
283
|
+
<div id="control-rows">
|
|
284
|
+
<!-- Control rows will be added dynamically -->
|
|
285
|
+
</div>
|
|
286
|
+
|
|
287
|
+
<button id="add-control-btn" style="margin-top: 12px; padding: 10px 20px; background: #10B981;">
|
|
288
|
+
+ Add Customization
|
|
289
|
+
</button>
|
|
290
|
+
|
|
291
|
+
<div style="margin-top: 16px; padding-top: 16px; border-top: 1px solid #E5E7EB;">
|
|
292
|
+
<button id="reset-defaults-btn" style="background: #6B7280;">
|
|
293
|
+
Reset to Defaults
|
|
294
|
+
</button>
|
|
295
|
+
</div>
|
|
296
|
+
</div>
|
|
297
|
+
|
|
298
|
+
<h2>Implementation Code:</h2>
|
|
299
|
+
<div class="tabs">
|
|
300
|
+
<button class="tab active" onclick="switchTab('simple')">Simple</button>
|
|
301
|
+
<button class="tab" onclick="switchTab('advanced')">All Options</button>
|
|
302
|
+
</div>
|
|
303
|
+
|
|
188
304
|
<div id="advanced-tab" class="tab-content">
|
|
189
305
|
<div class="code-block"><pre><code>const widget = new TTPAgentSDK.AgentWidget({
|
|
190
306
|
// Required
|
|
@@ -206,13 +322,48 @@
|
|
|
206
322
|
primaryColor: '#10B981',
|
|
207
323
|
position: 'bottom-right', // or use advanced position object below
|
|
208
324
|
|
|
209
|
-
//
|
|
325
|
+
// Icon Configuration
|
|
326
|
+
icon: {
|
|
327
|
+
type: 'custom', // 'microphone', 'custom', 'emoji', 'text'
|
|
328
|
+
customImage: 'https://talktopc.com/logo192.png', // For type: 'custom'
|
|
329
|
+
size: 'medium' // 'small', 'medium', 'large', 'xl'
|
|
330
|
+
},
|
|
331
|
+
|
|
332
|
+
// Button Configuration - Floating Button (Main Button) - WHITE
|
|
333
|
+
button: {
|
|
334
|
+
size: 'medium', // 'small', 'medium', 'large', 'xl'
|
|
335
|
+
shape: 'circle', // 'circle', 'square', 'rounded'
|
|
336
|
+
backgroundColor: '#FFFFFF', // Floating button background color (WHITE)
|
|
337
|
+
hoverColor: '#E5E7EB', // Floating button hover color (gray)
|
|
338
|
+
shadow: true,
|
|
339
|
+
shadowColor: 'rgba(0,0,0,0.15)'
|
|
340
|
+
},
|
|
341
|
+
|
|
342
|
+
// Header Configuration - Top of Panel - LIGHT PURPLE
|
|
343
|
+
header: {
|
|
344
|
+
title: 'TTP Support', // Custom title for the widget header
|
|
345
|
+
showTitle: true, // Show/hide title
|
|
346
|
+
backgroundColor: '#A78BFA', // Header background color (LIGHT PURPLE)
|
|
347
|
+
textColor: '#FFFFFF', // Header text color
|
|
348
|
+
showCloseButton: true
|
|
349
|
+
},
|
|
350
|
+
|
|
351
|
+
// Panel Configuration - Includes Mic Button Colors - GRAY
|
|
352
|
+
panel: {
|
|
353
|
+
width: 350,
|
|
354
|
+
height: 500,
|
|
355
|
+
borderRadius: 12,
|
|
356
|
+
backgroundColor: 'rgba(255,255,255,0.95)', // Panel background
|
|
357
|
+
backdropFilter: null,
|
|
358
|
+
border: '1px solid rgba(0,0,0,0.1)',
|
|
359
|
+
micButtonColor: '#E5E7EB', // Mic button (inside panel) background color (GRAY)
|
|
360
|
+
micButtonActiveColor: '#EF4444' // Mic button color when active/recording (RED)
|
|
361
|
+
},
|
|
210
362
|
// icon: {
|
|
211
|
-
// type: 'microphone',
|
|
212
|
-
// customImage: 'https://example.com/icon.png', // For type: 'custom'
|
|
363
|
+
// type: 'microphone',
|
|
213
364
|
// emoji: '🎤', // For type: 'emoji'
|
|
214
365
|
// text: 'AI', // For type: 'text'
|
|
215
|
-
// size: 'medium'
|
|
366
|
+
// size: 'medium'
|
|
216
367
|
// },
|
|
217
368
|
|
|
218
369
|
// Advanced Positioning
|
|
@@ -362,6 +513,368 @@
|
|
|
362
513
|
statusDiv.className = 'status ' + type;
|
|
363
514
|
}
|
|
364
515
|
|
|
516
|
+
// ============================================
|
|
517
|
+
// CUSTOMIZATION CONTROLS - Declare early
|
|
518
|
+
// ============================================
|
|
519
|
+
// Initialize variable first - MUST be declared before any functions that use it
|
|
520
|
+
let controlRowCount = 0;
|
|
521
|
+
|
|
522
|
+
const componentOptions = {
|
|
523
|
+
'button': {
|
|
524
|
+
label: 'Floating Button',
|
|
525
|
+
properties: {
|
|
526
|
+
'backgroundColor': { type: 'color', label: 'Background Color' },
|
|
527
|
+
'hoverColor': { type: 'color', label: 'Hover Color' },
|
|
528
|
+
'size': { type: 'select', label: 'Size', options: ['small', 'medium', 'large', 'xl'] },
|
|
529
|
+
'shape': { type: 'select', label: 'Shape', options: ['circle', 'square', 'rounded'] }
|
|
530
|
+
}
|
|
531
|
+
},
|
|
532
|
+
'header': {
|
|
533
|
+
label: 'Header',
|
|
534
|
+
properties: {
|
|
535
|
+
'backgroundColor': { type: 'color', label: 'Background Color' },
|
|
536
|
+
'textColor': { type: 'color', label: 'Text Color' },
|
|
537
|
+
'title': { type: 'text', label: 'Title' }
|
|
538
|
+
}
|
|
539
|
+
},
|
|
540
|
+
'panel': {
|
|
541
|
+
label: 'Mic Button',
|
|
542
|
+
properties: {
|
|
543
|
+
'micButtonColor': { type: 'color', label: 'Background Color' },
|
|
544
|
+
'micButtonActiveColor': { type: 'color', label: 'Active Color (Recording)' }
|
|
545
|
+
}
|
|
546
|
+
},
|
|
547
|
+
'micButtonHint': {
|
|
548
|
+
label: 'Mic Button Hint',
|
|
549
|
+
properties: {
|
|
550
|
+
'micButtonHint.text': { type: 'text', label: 'Hint Text (empty to hide)' },
|
|
551
|
+
'micButtonHint.color': { type: 'color', label: 'Text Color' },
|
|
552
|
+
'micButtonHint.fontSize': { type: 'text', label: 'Font Size (e.g., 12px)' }
|
|
553
|
+
}
|
|
554
|
+
},
|
|
555
|
+
'direction': {
|
|
556
|
+
label: 'Text Direction',
|
|
557
|
+
properties: {
|
|
558
|
+
'direction': { type: 'select', label: 'Direction', options: ['ltr', 'rtl'] }
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
};
|
|
562
|
+
|
|
563
|
+
function initializeCustomizationControls() {
|
|
564
|
+
// Add one initial row
|
|
565
|
+
addControlRow();
|
|
566
|
+
|
|
567
|
+
// Set up button event listeners
|
|
568
|
+
const addBtn = document.getElementById('add-control-btn');
|
|
569
|
+
const resetBtn = document.getElementById('reset-defaults-btn');
|
|
570
|
+
if (addBtn) {
|
|
571
|
+
addBtn.addEventListener('click', addControlRow);
|
|
572
|
+
}
|
|
573
|
+
if (resetBtn) {
|
|
574
|
+
resetBtn.addEventListener('click', resetToDefaults);
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
function addControlRow() {
|
|
579
|
+
controlRowCount++;
|
|
580
|
+
const controlRows = document.getElementById('control-rows');
|
|
581
|
+
const row = document.createElement('div');
|
|
582
|
+
row.className = 'control-row';
|
|
583
|
+
row.id = `control-row-${controlRowCount}`;
|
|
584
|
+
|
|
585
|
+
// Component selector
|
|
586
|
+
const componentSelect = document.createElement('select');
|
|
587
|
+
componentSelect.id = `component-${controlRowCount}`;
|
|
588
|
+
componentSelect.innerHTML = '<option value="">Select Component</option>';
|
|
589
|
+
Object.keys(componentOptions).forEach(key => {
|
|
590
|
+
const option = document.createElement('option');
|
|
591
|
+
option.value = key;
|
|
592
|
+
option.textContent = componentOptions[key].label;
|
|
593
|
+
componentSelect.appendChild(option);
|
|
594
|
+
});
|
|
595
|
+
componentSelect.onchange = () => updatePropertySelect(controlRowCount);
|
|
596
|
+
|
|
597
|
+
// Property selector (will be populated based on component)
|
|
598
|
+
const propertySelect = document.createElement('select');
|
|
599
|
+
propertySelect.id = `property-${controlRowCount}`;
|
|
600
|
+
propertySelect.innerHTML = '<option value="">Select Property</option>';
|
|
601
|
+
|
|
602
|
+
// Value input (dynamically changes based on property type)
|
|
603
|
+
const valueContainer = document.createElement('div');
|
|
604
|
+
valueContainer.id = `value-container-${controlRowCount}`;
|
|
605
|
+
valueContainer.style.display = 'none';
|
|
606
|
+
|
|
607
|
+
// Action buttons
|
|
608
|
+
const actionContainer = document.createElement('div');
|
|
609
|
+
actionContainer.style.display = 'flex';
|
|
610
|
+
actionContainer.style.gap = '8px';
|
|
611
|
+
|
|
612
|
+
const applyBtn = document.createElement('button');
|
|
613
|
+
applyBtn.textContent = 'Apply';
|
|
614
|
+
applyBtn.onclick = () => applyChange(controlRowCount);
|
|
615
|
+
|
|
616
|
+
const removeBtn = document.createElement('button');
|
|
617
|
+
removeBtn.textContent = 'Remove';
|
|
618
|
+
removeBtn.className = 'remove';
|
|
619
|
+
removeBtn.onclick = () => removeControlRow(controlRowCount);
|
|
620
|
+
|
|
621
|
+
actionContainer.appendChild(applyBtn);
|
|
622
|
+
actionContainer.appendChild(removeBtn);
|
|
623
|
+
|
|
624
|
+
row.appendChild(componentSelect);
|
|
625
|
+
row.appendChild(propertySelect);
|
|
626
|
+
row.appendChild(valueContainer);
|
|
627
|
+
row.appendChild(actionContainer);
|
|
628
|
+
|
|
629
|
+
controlRows.appendChild(row);
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
function updatePropertySelect(rowId) {
|
|
633
|
+
const componentSelect = document.getElementById(`component-${rowId}`);
|
|
634
|
+
const propertySelect = document.getElementById(`property-${rowId}`);
|
|
635
|
+
const valueContainer = document.getElementById(`value-container-${rowId}`);
|
|
636
|
+
|
|
637
|
+
const component = componentSelect.value;
|
|
638
|
+
if (!component) {
|
|
639
|
+
propertySelect.innerHTML = '<option value="">Select Property</option>';
|
|
640
|
+
valueContainer.style.display = 'none';
|
|
641
|
+
valueContainer.innerHTML = '';
|
|
642
|
+
return;
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
// Populate properties
|
|
646
|
+
propertySelect.innerHTML = '<option value="">Select Property</option>';
|
|
647
|
+
const properties = componentOptions[component].properties;
|
|
648
|
+
Object.keys(properties).forEach(key => {
|
|
649
|
+
const option = document.createElement('option');
|
|
650
|
+
option.value = key;
|
|
651
|
+
option.textContent = properties[key].label;
|
|
652
|
+
propertySelect.appendChild(option);
|
|
653
|
+
});
|
|
654
|
+
|
|
655
|
+
propertySelect.onchange = () => updateValueInput(rowId);
|
|
656
|
+
valueContainer.style.display = 'none';
|
|
657
|
+
valueContainer.innerHTML = '';
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
function updateValueInput(rowId) {
|
|
661
|
+
const componentSelect = document.getElementById(`component-${rowId}`);
|
|
662
|
+
const propertySelect = document.getElementById(`property-${rowId}`);
|
|
663
|
+
const valueContainer = document.getElementById(`value-container-${rowId}`);
|
|
664
|
+
|
|
665
|
+
const component = componentSelect.value;
|
|
666
|
+
const property = propertySelect.value;
|
|
667
|
+
|
|
668
|
+
if (!component || !property) {
|
|
669
|
+
valueContainer.style.display = 'none';
|
|
670
|
+
valueContainer.innerHTML = '';
|
|
671
|
+
return;
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
const propConfig = componentOptions[component].properties[property];
|
|
675
|
+
valueContainer.innerHTML = '';
|
|
676
|
+
|
|
677
|
+
if (propConfig.type === 'color') {
|
|
678
|
+
const input = document.createElement('input');
|
|
679
|
+
input.type = 'color';
|
|
680
|
+
input.id = `value-${rowId}`;
|
|
681
|
+
// Set current value from widget
|
|
682
|
+
const currentValue = getCurrentValue(component, property);
|
|
683
|
+
if (currentValue) input.value = rgbToHex(currentValue) || currentValue;
|
|
684
|
+
valueContainer.appendChild(input);
|
|
685
|
+
} else if (propConfig.type === 'select') {
|
|
686
|
+
const select = document.createElement('select');
|
|
687
|
+
select.id = `value-${rowId}`;
|
|
688
|
+
propConfig.options.forEach(opt => {
|
|
689
|
+
const option = document.createElement('option');
|
|
690
|
+
option.value = opt;
|
|
691
|
+
option.textContent = opt.charAt(0).toUpperCase() + opt.slice(1);
|
|
692
|
+
select.appendChild(option);
|
|
693
|
+
});
|
|
694
|
+
// Set current value
|
|
695
|
+
const currentValue = getCurrentValue(component, property);
|
|
696
|
+
if (currentValue !== null && currentValue !== undefined) {
|
|
697
|
+
select.value = currentValue.toString();
|
|
698
|
+
}
|
|
699
|
+
valueContainer.appendChild(select);
|
|
700
|
+
} else if (propConfig.type === 'text') {
|
|
701
|
+
const input = document.createElement('input');
|
|
702
|
+
input.type = 'text';
|
|
703
|
+
input.id = `value-${rowId}`;
|
|
704
|
+
input.placeholder = 'Enter value';
|
|
705
|
+
// Set current value
|
|
706
|
+
const currentValue = getCurrentValue(component, property);
|
|
707
|
+
if (currentValue !== null && currentValue !== undefined) {
|
|
708
|
+
input.value = currentValue;
|
|
709
|
+
}
|
|
710
|
+
valueContainer.appendChild(input);
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
valueContainer.style.display = 'block';
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
function getCurrentValue(component, property) {
|
|
717
|
+
if (!window.testWidget) return null;
|
|
718
|
+
const config = window.testWidget.config;
|
|
719
|
+
|
|
720
|
+
if (component === 'button' && config.button) {
|
|
721
|
+
return config.button[property];
|
|
722
|
+
} else if (component === 'header' && config.header) {
|
|
723
|
+
return config.header[property];
|
|
724
|
+
} else if (component === 'panel' && config.panel) {
|
|
725
|
+
return config.panel[property];
|
|
726
|
+
} else if (component === 'micButtonHint' && config.panel?.micButtonHint) {
|
|
727
|
+
// Handle nested micButtonHint properties
|
|
728
|
+
const hintKey = property.split('.')[1]; // e.g., 'text', 'color', 'fontSize'
|
|
729
|
+
const value = config.panel.micButtonHint[hintKey];
|
|
730
|
+
return value;
|
|
731
|
+
} else if (component === 'direction') {
|
|
732
|
+
return config.direction;
|
|
733
|
+
}
|
|
734
|
+
return null;
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
function applyChange(rowId) {
|
|
738
|
+
const componentSelect = document.getElementById(`component-${rowId}`);
|
|
739
|
+
const propertySelect = document.getElementById(`property-${rowId}`);
|
|
740
|
+
const valueInput = document.getElementById(`value-${rowId}`);
|
|
741
|
+
|
|
742
|
+
const component = componentSelect.value;
|
|
743
|
+
const property = propertySelect.value;
|
|
744
|
+
let value = valueInput.value;
|
|
745
|
+
|
|
746
|
+
if (!component || !property) {
|
|
747
|
+
alert('Please select component and property');
|
|
748
|
+
return;
|
|
749
|
+
}
|
|
750
|
+
|
|
751
|
+
// Allow empty value for text fields (to hide hint)
|
|
752
|
+
if (value === undefined || value === null) {
|
|
753
|
+
value = '';
|
|
754
|
+
}
|
|
755
|
+
|
|
756
|
+
if (!window.testWidget) {
|
|
757
|
+
alert('Widget not initialized');
|
|
758
|
+
return;
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
// Handle boolean values (only for non-empty values)
|
|
762
|
+
if (value && value !== '') {
|
|
763
|
+
if (value === 'true') value = true;
|
|
764
|
+
if (value === 'false') value = false;
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
// Prepare update config
|
|
768
|
+
const updateConfig = {};
|
|
769
|
+
if (component === 'button') {
|
|
770
|
+
updateConfig.button = { [property]: value };
|
|
771
|
+
} else if (component === 'header') {
|
|
772
|
+
updateConfig.header = { [property]: value };
|
|
773
|
+
} else if (component === 'panel') {
|
|
774
|
+
updateConfig.panel = { [property]: value };
|
|
775
|
+
} else if (component === 'micButtonHint') {
|
|
776
|
+
// Handle nested micButtonHint properties
|
|
777
|
+
const hintKey = property.split('.')[1]; // e.g., 'text', 'color', 'fontSize', 'show'
|
|
778
|
+
if (!updateConfig.panel) updateConfig.panel = {};
|
|
779
|
+
if (!updateConfig.panel.micButtonHint) updateConfig.panel.micButtonHint = {};
|
|
780
|
+
updateConfig.panel.micButtonHint[hintKey] = value;
|
|
781
|
+
} else if (component === 'direction') {
|
|
782
|
+
updateConfig.direction = value;
|
|
783
|
+
}
|
|
784
|
+
|
|
785
|
+
// Apply update
|
|
786
|
+
console.log(`Applying change: ${component}.${property} = ${value}`);
|
|
787
|
+
window.testWidget.updateConfig(updateConfig);
|
|
788
|
+
|
|
789
|
+
// Update the displayed code blocks
|
|
790
|
+
updateCodeDisplay();
|
|
791
|
+
}
|
|
792
|
+
|
|
793
|
+
function removeControlRow(rowId) {
|
|
794
|
+
const row = document.getElementById(`control-row-${rowId}`);
|
|
795
|
+
if (row) row.remove();
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
function resetToDefaults() {
|
|
799
|
+
if (!window.testWidget || !window.defaultConfig) {
|
|
800
|
+
alert('Widget or defaults not available');
|
|
801
|
+
return;
|
|
802
|
+
}
|
|
803
|
+
|
|
804
|
+
if (confirm('Reset widget to default configuration?')) {
|
|
805
|
+
window.testWidget.updateConfig(window.defaultConfig);
|
|
806
|
+
updateCodeDisplay();
|
|
807
|
+
|
|
808
|
+
// Clear all control rows
|
|
809
|
+
const controlRows = document.getElementById('control-rows');
|
|
810
|
+
controlRows.innerHTML = '';
|
|
811
|
+
controlRowCount = 0;
|
|
812
|
+
addControlRow();
|
|
813
|
+
}
|
|
814
|
+
}
|
|
815
|
+
|
|
816
|
+
function updateCodeDisplay() {
|
|
817
|
+
if (!window.testWidget) return;
|
|
818
|
+
const config = window.testWidget.config;
|
|
819
|
+
|
|
820
|
+
// Helper to safely get position value
|
|
821
|
+
function getPositionValue() {
|
|
822
|
+
if (!config.position) return 'bottom-right';
|
|
823
|
+
if (typeof config.position === 'string') return config.position;
|
|
824
|
+
// If it's an object, extract the string representation
|
|
825
|
+
return `${config.position.vertical || 'bottom'}-${config.position.horizontal || 'right'}`;
|
|
826
|
+
}
|
|
827
|
+
|
|
828
|
+
// Update simple tab
|
|
829
|
+
const simpleCode = document.querySelector('#simple-tab code');
|
|
830
|
+
if (simpleCode) {
|
|
831
|
+
const position = getPositionValue();
|
|
832
|
+
simpleCode.textContent = `const widget = new TTPAgentSDK.AgentWidget({
|
|
833
|
+
agentId: 'agent_87c4a55a1',
|
|
834
|
+
appId: 'app_Bc01EqMQt2Euehl4qqZSi6l3FJP42Q9vJ0pC',
|
|
835
|
+
|
|
836
|
+
primaryColor: '${config.primaryColor || '#10B981'}',
|
|
837
|
+
position: '${position}',
|
|
838
|
+
|
|
839
|
+
icon: {
|
|
840
|
+
type: '${config.icon?.type || 'custom'}',
|
|
841
|
+
customImage: '${config.icon?.customImage || 'https://talktopc.com/logo192.png'}',
|
|
842
|
+
size: '${config.icon?.size || 'medium'}'
|
|
843
|
+
},
|
|
844
|
+
|
|
845
|
+
button: {
|
|
846
|
+
backgroundColor: '${config.button?.backgroundColor || '#FFFFFF'}',
|
|
847
|
+
hoverColor: '${config.button?.hoverColor || '#E5E7EB'}'
|
|
848
|
+
},
|
|
849
|
+
|
|
850
|
+
header: {
|
|
851
|
+
title: '${(config.header?.title || 'TTP Support').replace(/'/g, "\\'")}',
|
|
852
|
+
backgroundColor: '${config.header?.backgroundColor || '#A78BFA'}',
|
|
853
|
+
textColor: '${config.header?.textColor || '#FFFFFF'}'
|
|
854
|
+
},
|
|
855
|
+
|
|
856
|
+
panel: {
|
|
857
|
+
micButtonColor: '${config.panel?.micButtonColor || '#E5E7EB'}',
|
|
858
|
+
micButtonActiveColor: '${config.panel?.micButtonActiveColor || '#EF4444'}'
|
|
859
|
+
}
|
|
860
|
+
});`;
|
|
861
|
+
}
|
|
862
|
+
}
|
|
863
|
+
|
|
864
|
+
function rgbToHex(rgb) {
|
|
865
|
+
if (!rgb) return null;
|
|
866
|
+
if (rgb.startsWith('#')) return rgb;
|
|
867
|
+
// Try to parse rgb/rgba format
|
|
868
|
+
const match = rgb.match(/\d+/g);
|
|
869
|
+
if (match && match.length >= 3) {
|
|
870
|
+
return '#' + match.slice(0, 3).map(x => {
|
|
871
|
+
const hex = parseInt(x).toString(16);
|
|
872
|
+
return hex.length === 1 ? '0' + hex : hex;
|
|
873
|
+
}).join('');
|
|
874
|
+
}
|
|
875
|
+
return null;
|
|
876
|
+
}
|
|
877
|
+
|
|
365
878
|
// Initialize the widget
|
|
366
879
|
try {
|
|
367
880
|
console.log('Initializing widget with agent ID + app ID...');
|
|
@@ -398,9 +911,34 @@
|
|
|
398
911
|
primaryColor: '#10B981',
|
|
399
912
|
position: 'bottom-right',
|
|
400
913
|
|
|
914
|
+
// Set TTP icon
|
|
915
|
+
icon: {
|
|
916
|
+
type: 'custom',
|
|
917
|
+
customImage: 'https://talktopc.com/logo192.png',
|
|
918
|
+
size: 'medium'
|
|
919
|
+
},
|
|
920
|
+
|
|
921
|
+
// Button colors - Floating button (main button) - WHITE
|
|
922
|
+
button: {
|
|
923
|
+
backgroundColor: '#FFFFFF', // White background for floating button
|
|
924
|
+
hoverColor: '#E5E7EB' // Gray on hover
|
|
925
|
+
},
|
|
926
|
+
|
|
927
|
+
// Header colors - Top of panel - LIGHT PURPLE
|
|
928
|
+
header: {
|
|
929
|
+
title: 'TTP Support',
|
|
930
|
+
backgroundColor: '#A78BFA', // Light purple header background
|
|
931
|
+
textColor: '#FFFFFF' // White text
|
|
932
|
+
},
|
|
933
|
+
|
|
934
|
+
// Panel colors - Mic button inside panel - GRAY
|
|
935
|
+
panel: {
|
|
936
|
+
micButtonColor: '#E5E7EB', // Gray mic button
|
|
937
|
+
micButtonActiveColor: '#EF4444' // Red when active/recording
|
|
938
|
+
},
|
|
939
|
+
|
|
401
940
|
// Enhanced features are now available but using defaults
|
|
402
941
|
// You can optionally add:
|
|
403
|
-
// icon: { type: 'emoji', emoji: '🎤', size: 'large' },
|
|
404
942
|
// button: { size: 'large', shape: 'circle' },
|
|
405
943
|
// panel: { width: 400, height: 600 },
|
|
406
944
|
// header: { title: 'My Voice Assistant' },
|
|
@@ -410,6 +948,41 @@
|
|
|
410
948
|
// Store widget reference for testing (like the working implementation)
|
|
411
949
|
window.testWidget = widget;
|
|
412
950
|
|
|
951
|
+
// Store default config for reset functionality (matches initial widget config)
|
|
952
|
+
window.defaultConfig = JSON.parse(JSON.stringify({
|
|
953
|
+
primaryColor: '#10B981',
|
|
954
|
+
position: 'bottom-right',
|
|
955
|
+
direction: 'ltr',
|
|
956
|
+
icon: {
|
|
957
|
+
type: 'custom',
|
|
958
|
+
customImage: 'https://talktopc.com/logo192.png',
|
|
959
|
+
size: 'medium'
|
|
960
|
+
},
|
|
961
|
+
button: {
|
|
962
|
+
backgroundColor: '#FFFFFF',
|
|
963
|
+
hoverColor: '#E5E7EB',
|
|
964
|
+
size: 'medium',
|
|
965
|
+
shape: 'circle'
|
|
966
|
+
},
|
|
967
|
+
header: {
|
|
968
|
+
title: 'TTP Support',
|
|
969
|
+
backgroundColor: '#A78BFA',
|
|
970
|
+
textColor: '#FFFFFF'
|
|
971
|
+
},
|
|
972
|
+
panel: {
|
|
973
|
+
micButtonColor: '#E5E7EB',
|
|
974
|
+
micButtonActiveColor: '#EF4444',
|
|
975
|
+
micButtonHint: {
|
|
976
|
+
text: 'Click the button to start voice conversation',
|
|
977
|
+
color: '#6B7280',
|
|
978
|
+
fontSize: '12px'
|
|
979
|
+
}
|
|
980
|
+
}
|
|
981
|
+
}));
|
|
982
|
+
|
|
983
|
+
// Initialize customization controls
|
|
984
|
+
initializeCustomizationControls();
|
|
985
|
+
|
|
413
986
|
console.log('Widget initialized successfully with agent ID + app ID!');
|
|
414
987
|
console.log('Widget instance:', widget);
|
|
415
988
|
console.log('Test methods available at window.testWidget');
|
|
@@ -461,6 +1034,7 @@
|
|
|
461
1034
|
alert('Microphone access DENIED! Please allow microphone in browser settings.');
|
|
462
1035
|
}
|
|
463
1036
|
}
|
|
1037
|
+
|
|
464
1038
|
</script>
|
|
465
1039
|
</body>
|
|
466
1040
|
</html>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ttp-agent-sdk",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0",
|
|
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",
|