applyCachedAssistantIfAvailable method

void applyCachedAssistantIfAvailable()

Applies the assistant from PupauAssistantsController cache if present for the current pupauConfig assistantId. Synchronous, no network. Use so the UI shows the correct agent immediately when opening or switching chat, before getAssistant returns.

Implementation

void applyCachedAssistantIfAvailable() {
  final String? id = pupauConfig?.assistantId;
  if (id == null || id.isEmpty) return;
  if (!Get.isRegistered<PupauAssistantsController>()) return;
  final AssistantType type = pupauConfig?.isMarketplace == true
      ? AssistantType.marketplace
      : AssistantType.assistant;
  final Assistant? cached = Get.find<PupauAssistantsController>()
      .getAssistantById(id, type);
  if (cached != null) {
    assistant.value = cached;
    _preserveInitialWelcomeIfAssistantEmpty();
    assistant.refresh();
    update();
  }
}