# Quickstart: Conversaciones múltiples del asistente con contexto

**Feature**: `004-chat-conversations`

## Prerequisites

- Laravel 12 + `ia_agent` running locally
- Angular `ChatFront` dev server
- LLM configured (`LLM_PROVIDER`, API keys)
- JWT login operativo
- Features `001` (chat baseline) y `003` (streaming) desplegados o en branch integrada

## Environment

```env
AGENT_MAX_HISTORY_MESSAGES=24
AGENT_CONVERSATION_TITLE_MAX=60
AGENT_STREAMING_ENABLED=true
LLM_PROVIDER=openai
```

## Database setup

```powershell
php artisan migrate
php artisan chat:migrate-legacy-sessions
```

Verify existing users retain one «Conversación anterior» with prior messages (SC-006).

## Start services

```powershell
php artisan serve
cd ChatFront; npm start
```

## Manual test — multiple conversations (US1)

1. Login → `/assistant`
2. Sidebar shows conversation list (or empty state)
3. Send message in default thread → title updates from first line
4. Click **Nueva conversación** → empty chat; previous thread still in list
5. Send different message in new thread
6. Switch between threads → distinct histories (SC-001)

## Manual test — context follow-up (US2)

In **one** conversation:

1. Ask: «¿Cuántos clientes tenemos?»
2. Wait for complete answer
3. Ask: «¿Y cuántos contratos?» (without repeating client context)
4. Expect coherent follow-up using thread context (SC-002 target 80% in UAT)

Switch to another conversation and repeat step 3 — answer MUST NOT use prior thread data (FR-005).

## Manual test — reload (US3)

1. Active conversation with messages
2. Reload `/assistant`
3. Same conversation and full history visible (SC-003)

## Manual test — delete (US4)

1. Create 3 conversations with messages
2. Delete one from sidebar/menu
3. Other two unchanged (FR-008)

## Manual test — streaming + attachment (US5)

1. Text message → progressive stream in active conversation
2. PDF attach → sync response in same conversation
3. During stream, switching conversation blocked or cancels stream

## curl examples

```powershell
$token = "YOUR_JWT"

# List
curl -H "Authorization: Bearer $token" http://127.0.0.1:8000/api/v1/chat/conversations

# Create
curl -X POST -H "Authorization: Bearer $token" -H "Content-Type: application/json" `
  -d "{}" http://127.0.0.1:8000/api/v1/chat/conversations

# Stream
$convId = 12
curl -N -X POST "http://127.0.0.1:8000/api/v1/chat/conversations/$convId/message/stream" `
  -H "Authorization: Bearer $token" `
  -H "Content-Type: application/json" `
  -H "Accept: text/event-stream" `
  -d '{"message":"Hola"}'
```

## Authorization test (SC-004)

Attempt `GET /chat/conversations/{otherUserConvId}/messages` with your JWT → expect `404`.

## Run tests

```powershell
php artisan test --filter=ChatConversation
php artisan test --filter=ConversationHistory
cd ChatFront; npx ng build
```

## Next steps

1. `/speckit-tasks` — generate `tasks.md`
2. `/speckit-implement` — migration, backend, frontend
