emanate-ai-chat-lib 0.1.7 → 0.1.8

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.
@@ -2006,23 +2006,42 @@
2006
2006
  if (hasMessages) {
2007
2007
  console.log('Starting new conversation (current has', this.messages.length, 'messages)');
2008
2008
  }
2009
+ // Clear messages IMMEDIATELY for instant feedback
2010
+ this.messages = [];
2011
+ this.addWelcomeMessage();
2009
2012
  this.updateStatus('Starting new conversation...');
2010
2013
  this.conversationStateService.startNewConversationExplicit(this.userId, this.userName)
2011
- .pipe(operators.takeUntil(this.destroy$))
2014
+ .pipe(operators.timeout(10000), // 10 second timeout
2015
+ operators.retry(1), // Retry once on failure
2016
+ operators.takeUntil(this.destroy$))
2012
2017
  .subscribe({
2013
2018
  next: function (conversationId) {
2014
2019
  _this.conversationId = conversationId;
2015
2020
  _this.conversationInitialized = true;
2016
2021
  _this.conversationStarted.emit(conversationId); // Emit event
2017
2022
  _this.updateStatus('Ready');
2018
- // Clear existing messages and start fresh
2019
- _this.messages = [];
2020
- _this.addWelcomeMessage();
2021
- console.log('Explicitly started new conversation:', conversationId);
2023
+ console.log('✓ New conversation started:', conversationId);
2022
2024
  },
2023
2025
  error: function (error) {
2024
2026
  console.error('Failed to start new conversation:', error);
2025
- _this.updateStatus('Failed to start new conversation');
2027
+ // Provide actionable error messages
2028
+ if (error.name === 'TimeoutError') {
2029
+ _this.updateStatus('Connection timeout - Please check your network');
2030
+ console.warn('⚠ New conversation API timed out after 10s');
2031
+ }
2032
+ else if (error.status === 0 || !navigator.onLine) {
2033
+ _this.updateStatus('No connection - Working offline');
2034
+ console.warn('⚠ Network unavailable');
2035
+ }
2036
+ else if (error.status >= 500) {
2037
+ _this.updateStatus('Server error - Please try again');
2038
+ console.error('⚠ Server error:', error.status);
2039
+ }
2040
+ else {
2041
+ _this.updateStatus('Unable to start conversation - Try again');
2042
+ }
2043
+ // Messages already cleared - keep welcome message showing
2044
+ // UI remains functional even if API fails
2026
2045
  }
2027
2046
  });
2028
2047
  };