fix: resolve NPC chat database persistence and modal targeting

Fixed two critical bugs in NPC chat functionality:

  1. Database Persistence - Metadata serialization bug
     - Empty dict {} was falsy, preventing JSON conversion
     - Changed to unconditional serialization in ChatMessageService
     - Messages now successfully save to chat_messages collection

  2. Modal Targeting - HTMX targeting lost during polling
     - poll_job() wasn't preserving hx-target/hx-swap parameters
     - Pass targeting params through query string in polling cycle
     - Responses now correctly load in modal instead of main panel

  Files modified:
  - api/app/services/chat_message_service.py
  - public_web/templates/game/partials/job_polling.html
  - public_web/app/views/game_views.py
This commit is contained in:
2025-11-25 20:44:24 -06:00
parent 4353d112f4
commit 20cb279793
3 changed files with 18 additions and 8 deletions

View File

@@ -10,10 +10,10 @@ Shows loading state while waiting for AI response, auto-polls for completion
{% endif %}
<div class="loading-state"
hx-get="{{ url_for('game.poll_job', session_id=session_id, job_id=job_id) }}"
hx-get="{{ url_for('game.poll_job', session_id=session_id, job_id=job_id, _hx_target=hx_target, _hx_swap=hx_swap) }}"
hx-trigger="load delay:1s"
hx-swap="innerHTML"
hx-target="#narrative-content">
hx-swap="{{ hx_swap|default('innerHTML') }}"
hx-target="{{ hx_target|default('#narrative-content') }}">
<div class="loading-spinner-large"></div>
<p class="loading-text">
{% if status == 'queued' %}