openChatWithConfig method

Future<void> openChatWithConfig(
  1. PupauConfig? newConfig
)

Called when chat is opened (via PupauChatUtils or tapping avatar) Resets conversation state and updates config if assistant changed Re-initializes the chat every time it's called (even with same config)

Implementation

Future<void> openChatWithConfig(PupauConfig? newConfig) async {
  // Prevent concurrent initializations
  if (_isInitializing) return;

  // Check if assistant changed
  bool assistantChanged =
      pupauConfig?.assistantId != newConfig?.assistantId ||
      pupauConfig?.isMarketplace != newConfig?.isMarketplace;

  if (newConfig != null) pupauConfig = newConfig;
  if (assistantChanged) resetChatState();
  _updateBootStatus(BootState.pending);

  // Initialize chat with current config (always re-initialize when chat is opened)
  _isInitializing = true;
  try {
    await initChatController();
  } finally {
    _isInitializing = false;
  }
}