# Live Agent Label Switch Plan

## Goal
Update the support bubble UI so the header/assistant label changes from "AI Assistant" to "LIVE AGENT" when the conversation enters live chat mode with a human agent.

## Requested Constraint
- No code changes in this step.
- Produce a plan only.

## Current Behavior (Observed)
- In the support bubble script, assistant messages are rendered with a static label text of "AI Assistant".
- When live chat mode is activated (`data.is_live_chat`), message transport/polling switches to agent endpoints, but the label text remains AI-branded.

## Desired Behavior
- Before live chat mode: assistant label remains "AI Assistant".
- After live chat mode starts: assistant label becomes "LIVE AGENT" for subsequent assistant/agent messages.
- Optional UX decision for implementation phase:
  - Keep historical AI messages labeled as "AI Assistant" (recommended).
  - Only new incoming agent messages after escalation should show "LIVE AGENT".

## Primary File Target
- `resources/views/vendor/support-bubble/includes/script.blade.php`

## Implementation Plan (No Code Yet)
1. Add a UI label state variable in `bootstrapSupportBubble`.
2. Refactor message rendering so assistant label text is derived from that state (instead of hardcoded "AI Assistant").
3. In `initializeLiveChat(...)`, set the label state to `LIVE AGENT` as soon as live chat mode is confirmed.
4. Ensure polling-rendered agent messages use the new label state immediately.
5. Keep user messages unchanged (`You`).
6. Confirm non-live-chat flows still render "AI Assistant".

## Edge Cases To Handle
- Page loads with existing escalated/live session history.
- Bubble reopened in same session after live mode was already enabled.
- Transition race where one AI reply and live activation occur close together.
- Docs chat mode (`ai_from_docs`) should still follow same label transition rules.

## QA / Verification Plan
1. Start new non-live conversation: assistant messages show "AI Assistant".
2. Trigger live chat activation (`data.is_live_chat === true`): next assistant/agent message shows "LIVE AGENT".
3. Verify agent-polled messages continue to show "LIVE AGENT".
4. Verify user messages still show "You".
5. Reload/reopen during active live chat session and verify label behavior remains correct.
6. Confirm no regressions in non-live support flow.

## Acceptance Criteria
- Label switches to "LIVE AGENT" once live chat mode begins.
- AI mode continues to show "AI Assistant".
- No impact on message sending, polling, escalation, or form behavior.
- No JavaScript errors introduced.

## Risk Assessment
- Low risk, UI-label only.
- Main risk is introducing inconsistent labeling for historical vs new messages; resolved by explicit rule during implementation.

## Rollback Plan
- Revert label-state change in `script.blade.php` to static assistant label if unexpected behavior appears.
