ttp-agent-sdk 2.5.8 → 2.13.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.
@@ -392,18 +392,19 @@
392
392
  <option value="rounded">Rounded</option>
393
393
  </select>
394
394
  </label>
395
- <label>Button Color
395
+ <label>Button Color (Widget default: #FFFFFF)
396
396
  <div style="display: flex; gap: 8px; align-items: center;">
397
- <input id="buttonBgColor" type="color" value="#7C3AED" />
398
- <div id="buttonBgColorColorBox" style="width: 30px; height: 30px; border-radius: 4px; border: 2px solid #D1D5DB; background: #7C3AED; flex-shrink: 0; box-shadow: 0 1px 3px rgba(0,0,0,0.1);"></div>
399
- <span id="buttonBgColorValue" style="font-family: monospace; font-size: 12px; color: #6B7280; min-width: 70px;">#7C3AED</span>
397
+ <input id="buttonBgColor" type="color" value="#FFFFFF" />
398
+ <div id="buttonBgColorColorBox" style="width: 30px; height: 30px; border-radius: 4px; border: 2px solid #D1D5DB; background: #FFFFFF; flex-shrink: 0; box-shadow: 0 1px 3px rgba(0,0,0,0.1);"></div>
399
+ <span id="buttonBgColorValue" style="font-family: monospace; font-size: 12px; color: #6B7280; min-width: 70px;">#FFFFFF</span>
400
400
  </div>
401
401
  </label>
402
- <label>Button Hover Color
402
+ <label>Button Hover Color (Optional - leave as default for no hover color change)
403
403
  <div style="display: flex; gap: 8px; align-items: center;">
404
- <input id="buttonHoverColor" type="color" value="#059669" />
405
- <div id="buttonHoverColorColorBox" style="width: 30px; height: 30px; border-radius: 4px; border: 2px solid #D1D5DB; background: #059669; flex-shrink: 0; box-shadow: 0 1px 3px rgba(0,0,0,0.1);"></div>
406
- <span id="buttonHoverColorValue" style="font-family: monospace; font-size: 12px; color: #6B7280; min-width: 70px;">#059669</span>
404
+ <input id="buttonHoverColor" type="color" value="#F5F5F5" />
405
+ <div id="buttonHoverColorColorBox" style="width: 30px; height: 30px; border-radius: 4px; border: 2px solid #D1D5DB; background: #F5F5F5; flex-shrink: 0; box-shadow: 0 1px 3px rgba(0,0,0,0.1);"></div>
406
+ <span id="buttonHoverColorValue" style="font-family: monospace; font-size: 12px; color: #6B7280; min-width: 70px;">#F5F5F5</span>
407
+ <button type="button" onclick="clearHoverColor()" style="padding: 4px 8px; font-size: 12px; background: #E5E7EB; border: 1px solid #D1D5DB; border-radius: 4px; cursor: pointer;">Clear</button>
407
408
  </div>
408
409
  </label>
409
410
 
@@ -728,8 +729,8 @@
728
729
  </div>
729
730
  </div>
730
731
 
731
- <!-- Load the SDK from dist folder -->
732
- <script src="/dist/agent-widget.js" data-agent-id="agent_87c4a55a1" data-app-id="app_Bc01EqMQt2Euehl4qqZSi6l3FJP42Q9vJ0pC" onload="console.log('SDK script loaded successfully')" onerror="console.error('Failed to load SDK script')"></script>
732
+ <!-- Load the SDK from CDN -->
733
+ <script src="https://cdn.talktopc.com/agent-widget.js" data-agent-id="agent_87c4a55a1" data-app-id="app_Bc01EqMQt2Euehl4qqZSi6l3FJP42Q9vJ0pC" onload="console.log('SDK script loaded successfully, TTPAgentSDK:', typeof window.TTPAgentSDK)" onerror="console.error('Failed to load SDK script')"></script>
733
734
 
734
735
  <script>
735
736
  // Language selection only affects widget, not page UI
@@ -803,6 +804,18 @@
803
804
 
804
805
  // Add event listener to update value when color changes
805
806
  input.addEventListener('input', updateDisplay);
807
+
808
+ // Special handling for hover color - clear the "cleared" flag when user changes it
809
+ if (input.id === 'buttonHoverColor') {
810
+ input.addEventListener('change', function() {
811
+ // User changed the color, so enable hover color again
812
+ delete input.dataset.cleared;
813
+ const valueSpan = document.getElementById('buttonHoverColorValue');
814
+ if (valueSpan && valueSpan.textContent.includes('(disabled)')) {
815
+ valueSpan.textContent = input.value.toUpperCase();
816
+ }
817
+ });
818
+ }
806
819
  });
807
820
  }
808
821
 
@@ -836,6 +849,24 @@
836
849
  initializeUI();
837
850
  }
838
851
 
852
+ // Clear hover color (set to empty to test no hover color behavior)
853
+ function clearHoverColor() {
854
+ const hoverColorInput = document.getElementById('buttonHoverColor');
855
+ const colorBox = document.getElementById('buttonHoverColorColorBox');
856
+ const valueSpan = document.getElementById('buttonHoverColorValue');
857
+
858
+ // Set a special flag to indicate it's cleared
859
+ hoverColorInput.dataset.cleared = 'true';
860
+ hoverColorInput.value = '#F5F5F5'; // Reset to default for display
861
+ if (colorBox) colorBox.style.background = '#F5F5F5';
862
+ if (valueSpan) valueSpan.textContent = '#F5F5F5 (disabled)';
863
+
864
+ // Apply changes to widget
865
+ if (window.testWidget) {
866
+ applyChanges();
867
+ }
868
+ }
869
+
839
870
  // Toggle section collapse
840
871
  function toggleSection(sectionId) {
841
872
  const content = document.getElementById(sectionId + '-content');
@@ -866,6 +897,10 @@
866
897
  window.testWidget.destroy();
867
898
  }
868
899
 
900
+ const TTPAgentSDK = window.TTPAgentSDK;
901
+ if (!TTPAgentSDK || !TTPAgentSDK.TTPChatWidget) {
902
+ throw new Error('TTPAgentSDK.TTPChatWidget is not available');
903
+ }
869
904
  window.testWidget = new TTPAgentSDK.TTPChatWidget(config);
870
905
  widget = window.testWidget;
871
906
 
@@ -911,20 +946,19 @@
911
946
  connectionType: 'text_chat'
912
947
  },
913
948
 
914
- primaryColor: document.getElementById('buttonBgColor').value || '#7C3AED',
949
+ primaryColor: document.getElementById('buttonBgColor').value || '#FFFFFF',
915
950
 
916
951
  icon: {
917
952
  type: 'custom',
918
953
  customImage: 'https://talktopc.com/logo192.png',
919
954
  size: document.getElementById('buttonSize').value,
920
- backgroundColor: '#FFFFFF'
955
+ backgroundColor: document.getElementById('buttonBgColor').value || '#FFFFFF' // Widget default: white
921
956
  },
922
957
 
923
958
  button: {
924
959
  size: document.getElementById('buttonSize').value,
925
960
  shape: document.getElementById('buttonShape').value,
926
- backgroundColor: '#FFFFFF', // Use white to match icon background
927
- hoverColor: document.getElementById('buttonHoverColor').value
961
+ backgroundColor: document.getElementById('buttonBgColor').value || '#FFFFFF' // Widget default: white
928
962
  },
929
963
 
930
964
  panel: {
@@ -1036,6 +1070,14 @@
1036
1070
  }
1037
1071
  };
1038
1072
 
1073
+ // Only include hoverColor if user has set a custom value (not default #7C3AED)
1074
+ // If hoverColor is not included, widget will keep original color on hover
1075
+ const hoverColorInput = document.getElementById('buttonHoverColor');
1076
+ const defaultHoverColor = '#F5F5F5'; // Off-white default
1077
+ if (hoverColorInput && hoverColorInput.value !== defaultHoverColor && hoverColorInput.dataset.cleared !== 'true') {
1078
+ config.button.hoverColor = hoverColorInput.value;
1079
+ }
1080
+
1039
1081
  // If signed URL is provided, use it directly
1040
1082
  if (signedUrl) {
1041
1083
  config.signedUrl = signedUrl;
@@ -1101,29 +1143,46 @@
1101
1143
  });
1102
1144
  }
1103
1145
 
1104
- try {
1146
+ // Wait for SDK to load
1147
+ function waitForSDK() {
1148
+ return new Promise((resolve, reject) => {
1149
+ // Check if already loaded
1150
+ if (typeof window.TTPAgentSDK !== 'undefined' && window.TTPAgentSDK?.TTPChatWidget) {
1151
+ resolve(window.TTPAgentSDK);
1152
+ return;
1153
+ }
1154
+
1155
+ // Wait for script to load
1156
+ let attempts = 0;
1157
+ const maxAttempts = 50; // 5 seconds max wait
1158
+ const checkInterval = setInterval(() => {
1159
+ attempts++;
1160
+ if (typeof window.TTPAgentSDK !== 'undefined' && window.TTPAgentSDK?.TTPChatWidget) {
1161
+ clearInterval(checkInterval);
1162
+ resolve(window.TTPAgentSDK);
1163
+ } else if (attempts >= maxAttempts) {
1164
+ clearInterval(checkInterval);
1165
+ reject(new Error('TTPAgentSDK failed to load after 5 seconds'));
1166
+ }
1167
+ }, 100);
1168
+ });
1169
+ }
1170
+
1171
+ waitForSDK().then((TTPAgentSDK) => {
1105
1172
  console.log('Initializing TTP Chat Widget...');
1106
1173
  console.log('TTPAgentSDK available:', typeof TTPAgentSDK);
1107
1174
  console.log('TTPAgentSDK.TTPChatWidget available:', typeof TTPAgentSDK?.TTPChatWidget);
1108
1175
 
1109
- if (typeof TTPAgentSDK === 'undefined') {
1110
- throw new Error('TTPAgentSDK is not defined. Check if the script loaded correctly.');
1111
- }
1112
-
1113
- if (typeof TTPAgentSDK.TTPChatWidget === 'undefined') {
1114
- throw new Error('TTPAgentSDK.TTPChatWidget is not defined. Check the SDK build.');
1115
- }
1116
-
1117
1176
  // Create initial widget
1118
1177
  createWidget(getConfigFromForm());
1119
1178
 
1120
1179
  // Set up event handlers
1121
1180
  document.getElementById('resetBtn').onclick = () => window.location.reload();
1122
1181
 
1123
- } catch (error) {
1182
+ }).catch((error) => {
1124
1183
  console.error('Failed to initialize widget:', error);
1125
1184
  updateStatus('Widget failed to load: ' + error.message, 'error');
1126
- }
1185
+ });
1127
1186
  </script>
1128
1187
  </body>
1129
1188
  </html>
@@ -392,18 +392,19 @@
392
392
  <option value="rounded">Rounded</option>
393
393
  </select>
394
394
  </label>
395
- <label>Button Color
395
+ <label>Button Color (Widget default: #FFFFFF)
396
396
  <div style="display: flex; gap: 8px; align-items: center;">
397
- <input id="buttonBgColor" type="color" value="#7C3AED" />
398
- <div id="buttonBgColorColorBox" style="width: 30px; height: 30px; border-radius: 4px; border: 2px solid #D1D5DB; background: #7C3AED; flex-shrink: 0; box-shadow: 0 1px 3px rgba(0,0,0,0.1);"></div>
399
- <span id="buttonBgColorValue" style="font-family: monospace; font-size: 12px; color: #6B7280; min-width: 70px;">#7C3AED</span>
397
+ <input id="buttonBgColor" type="color" value="#FFFFFF" />
398
+ <div id="buttonBgColorColorBox" style="width: 30px; height: 30px; border-radius: 4px; border: 2px solid #D1D5DB; background: #FFFFFF; flex-shrink: 0; box-shadow: 0 1px 3px rgba(0,0,0,0.1);"></div>
399
+ <span id="buttonBgColorValue" style="font-family: monospace; font-size: 12px; color: #6B7280; min-width: 70px;">#FFFFFF</span>
400
400
  </div>
401
401
  </label>
402
- <label>Button Hover Color
402
+ <label>Button Hover Color (Optional - leave as default for no hover color change)
403
403
  <div style="display: flex; gap: 8px; align-items: center;">
404
- <input id="buttonHoverColor" type="color" value="#059669" />
405
- <div id="buttonHoverColorColorBox" style="width: 30px; height: 30px; border-radius: 4px; border: 2px solid #D1D5DB; background: #059669; flex-shrink: 0; box-shadow: 0 1px 3px rgba(0,0,0,0.1);"></div>
406
- <span id="buttonHoverColorValue" style="font-family: monospace; font-size: 12px; color: #6B7280; min-width: 70px;">#059669</span>
404
+ <input id="buttonHoverColor" type="color" value="#F5F5F5" />
405
+ <div id="buttonHoverColorColorBox" style="width: 30px; height: 30px; border-radius: 4px; border: 2px solid #D1D5DB; background: #F5F5F5; flex-shrink: 0; box-shadow: 0 1px 3px rgba(0,0,0,0.1);"></div>
406
+ <span id="buttonHoverColorValue" style="font-family: monospace; font-size: 12px; color: #6B7280; min-width: 70px;">#F5F5F5</span>
407
+ <button type="button" onclick="clearHoverColor()" style="padding: 4px 8px; font-size: 12px; background: #E5E7EB; border: 1px solid #D1D5DB; border-radius: 4px; cursor: pointer;">Clear</button>
407
408
  </div>
408
409
  </label>
409
410
 
@@ -728,8 +729,8 @@
728
729
  </div>
729
730
  </div>
730
731
 
731
- <!-- Load the SDK from dist folder -->
732
- <script src="/dist/agent-widget.js" data-agent-id="agent_87c4a55a1" data-app-id="app_Bc01EqMQt2Euehl4qqZSi6l3FJP42Q9vJ0pC" onload="console.log('SDK script loaded successfully')" onerror="console.error('Failed to load SDK script')"></script>
732
+ <!-- Load the SDK from CDN -->
733
+ <script src="https://cdn.talktopc.com/agent-widget.js" data-agent-id="agent_87c4a55a1" data-app-id="app_Bc01EqMQt2Euehl4qqZSi6l3FJP42Q9vJ0pC" onload="console.log('SDK script loaded successfully, TTPAgentSDK:', typeof window.TTPAgentSDK)" onerror="console.error('Failed to load SDK script')"></script>
733
734
 
734
735
  <script>
735
736
  // Language selection only affects widget, not page UI
@@ -803,6 +804,18 @@
803
804
 
804
805
  // Add event listener to update value when color changes
805
806
  input.addEventListener('input', updateDisplay);
807
+
808
+ // Special handling for hover color - clear the "cleared" flag when user changes it
809
+ if (input.id === 'buttonHoverColor') {
810
+ input.addEventListener('change', function() {
811
+ // User changed the color, so enable hover color again
812
+ delete input.dataset.cleared;
813
+ const valueSpan = document.getElementById('buttonHoverColorValue');
814
+ if (valueSpan && valueSpan.textContent.includes('(disabled)')) {
815
+ valueSpan.textContent = input.value.toUpperCase();
816
+ }
817
+ });
818
+ }
806
819
  });
807
820
  }
808
821
 
@@ -836,6 +849,24 @@
836
849
  initializeUI();
837
850
  }
838
851
 
852
+ // Clear hover color (set to empty to test no hover color behavior)
853
+ function clearHoverColor() {
854
+ const hoverColorInput = document.getElementById('buttonHoverColor');
855
+ const colorBox = document.getElementById('buttonHoverColorColorBox');
856
+ const valueSpan = document.getElementById('buttonHoverColorValue');
857
+
858
+ // Set a special flag to indicate it's cleared
859
+ hoverColorInput.dataset.cleared = 'true';
860
+ hoverColorInput.value = '#F5F5F5'; // Reset to default for display
861
+ if (colorBox) colorBox.style.background = '#F5F5F5';
862
+ if (valueSpan) valueSpan.textContent = '#F5F5F5 (disabled)';
863
+
864
+ // Apply changes to widget
865
+ if (window.testWidget) {
866
+ applyChanges();
867
+ }
868
+ }
869
+
839
870
  // Toggle section collapse
840
871
  function toggleSection(sectionId) {
841
872
  const content = document.getElementById(sectionId + '-content');
@@ -866,6 +897,10 @@
866
897
  window.testWidget.destroy();
867
898
  }
868
899
 
900
+ const TTPAgentSDK = window.TTPAgentSDK;
901
+ if (!TTPAgentSDK || !TTPAgentSDK.TTPChatWidget) {
902
+ throw new Error('TTPAgentSDK.TTPChatWidget is not available');
903
+ }
869
904
  window.testWidget = new TTPAgentSDK.TTPChatWidget(config);
870
905
  widget = window.testWidget;
871
906
 
@@ -911,20 +946,19 @@
911
946
  connectionType: 'text_chat'
912
947
  },
913
948
 
914
- primaryColor: document.getElementById('buttonBgColor').value || '#7C3AED',
949
+ primaryColor: document.getElementById('buttonBgColor').value || '#FFFFFF',
915
950
 
916
951
  icon: {
917
952
  type: 'custom',
918
953
  customImage: 'https://talktopc.com/logo192.png',
919
954
  size: document.getElementById('buttonSize').value,
920
- backgroundColor: '#FFFFFF'
955
+ backgroundColor: document.getElementById('buttonBgColor').value || '#FFFFFF' // Widget default: white
921
956
  },
922
957
 
923
958
  button: {
924
959
  size: document.getElementById('buttonSize').value,
925
960
  shape: document.getElementById('buttonShape').value,
926
- backgroundColor: '#FFFFFF', // Use white to match icon background
927
- hoverColor: document.getElementById('buttonHoverColor').value
961
+ backgroundColor: document.getElementById('buttonBgColor').value || '#FFFFFF' // Widget default: white
928
962
  },
929
963
 
930
964
  panel: {
@@ -1036,6 +1070,14 @@
1036
1070
  }
1037
1071
  };
1038
1072
 
1073
+ // Only include hoverColor if user has set a custom value (not default #7C3AED)
1074
+ // If hoverColor is not included, widget will keep original color on hover
1075
+ const hoverColorInput = document.getElementById('buttonHoverColor');
1076
+ const defaultHoverColor = '#F5F5F5'; // Off-white default
1077
+ if (hoverColorInput && hoverColorInput.value !== defaultHoverColor && hoverColorInput.dataset.cleared !== 'true') {
1078
+ config.button.hoverColor = hoverColorInput.value;
1079
+ }
1080
+
1039
1081
  // If signed URL is provided, use it directly
1040
1082
  if (signedUrl) {
1041
1083
  config.signedUrl = signedUrl;
@@ -1101,29 +1143,46 @@
1101
1143
  });
1102
1144
  }
1103
1145
 
1104
- try {
1146
+ // Wait for SDK to load
1147
+ function waitForSDK() {
1148
+ return new Promise((resolve, reject) => {
1149
+ // Check if already loaded
1150
+ if (typeof window.TTPAgentSDK !== 'undefined' && window.TTPAgentSDK?.TTPChatWidget) {
1151
+ resolve(window.TTPAgentSDK);
1152
+ return;
1153
+ }
1154
+
1155
+ // Wait for script to load
1156
+ let attempts = 0;
1157
+ const maxAttempts = 50; // 5 seconds max wait
1158
+ const checkInterval = setInterval(() => {
1159
+ attempts++;
1160
+ if (typeof window.TTPAgentSDK !== 'undefined' && window.TTPAgentSDK?.TTPChatWidget) {
1161
+ clearInterval(checkInterval);
1162
+ resolve(window.TTPAgentSDK);
1163
+ } else if (attempts >= maxAttempts) {
1164
+ clearInterval(checkInterval);
1165
+ reject(new Error('TTPAgentSDK failed to load after 5 seconds'));
1166
+ }
1167
+ }, 100);
1168
+ });
1169
+ }
1170
+
1171
+ waitForSDK().then((TTPAgentSDK) => {
1105
1172
  console.log('Initializing TTP Chat Widget...');
1106
1173
  console.log('TTPAgentSDK available:', typeof TTPAgentSDK);
1107
1174
  console.log('TTPAgentSDK.TTPChatWidget available:', typeof TTPAgentSDK?.TTPChatWidget);
1108
1175
 
1109
- if (typeof TTPAgentSDK === 'undefined') {
1110
- throw new Error('TTPAgentSDK is not defined. Check if the script loaded correctly.');
1111
- }
1112
-
1113
- if (typeof TTPAgentSDK.TTPChatWidget === 'undefined') {
1114
- throw new Error('TTPAgentSDK.TTPChatWidget is not defined. Check the SDK build.');
1115
- }
1116
-
1117
1176
  // Create initial widget
1118
1177
  createWidget(getConfigFromForm());
1119
1178
 
1120
1179
  // Set up event handlers
1121
1180
  document.getElementById('resetBtn').onclick = () => window.location.reload();
1122
1181
 
1123
- } catch (error) {
1182
+ }).catch((error) => {
1124
1183
  console.error('Failed to initialize widget:', error);
1125
1184
  updateStatus('Widget failed to load: ' + error.message, 'error');
1126
- }
1185
+ });
1127
1186
  </script>
1128
1187
  </body>
1129
1188
  </html>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ttp-agent-sdk",
3
- "version": "2.5.8",
3
+ "version": "2.13.0",
4
4
  "description": "Comprehensive Voice Agent SDK with 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",