chat history with the NPC modal
This commit is contained in:
@@ -748,6 +748,40 @@ def npc_chat_modal(session_id: str, npc_id: str):
|
||||
'''
|
||||
|
||||
|
||||
@game_bp.route('/session/<session_id>/npc/<npc_id>/history')
|
||||
@require_auth
|
||||
def npc_chat_history(session_id: str, npc_id: str):
|
||||
"""Get last 5 chat messages for history sidebar."""
|
||||
client = get_api_client()
|
||||
|
||||
try:
|
||||
# Get session to find character_id
|
||||
session_response = client.get(f'/api/v1/sessions/{session_id}')
|
||||
session_data = session_response.get('result', {})
|
||||
character_id = session_data.get('character_id')
|
||||
|
||||
# Fetch last 5 messages from chat service
|
||||
# API endpoint: GET /api/v1/characters/{character_id}/chats/{npc_id}?limit=5
|
||||
history_response = client.get(
|
||||
f'/api/v1/characters/{character_id}/chats/{npc_id}',
|
||||
params={'limit': 5, 'offset': 0}
|
||||
)
|
||||
result_data = history_response.get('result', {})
|
||||
messages = result_data.get('messages', []) # Extract messages array from result
|
||||
|
||||
# Render history partial
|
||||
return render_template(
|
||||
'game/partials/npc_chat_history.html',
|
||||
messages=messages,
|
||||
session_id=session_id,
|
||||
npc_id=npc_id
|
||||
)
|
||||
|
||||
except APIError as e:
|
||||
logger.error("failed_to_load_chat_history", session_id=session_id, npc_id=npc_id, error=str(e))
|
||||
return '<div class="history-empty">Failed to load history</div>', 500
|
||||
|
||||
|
||||
@game_bp.route('/session/<session_id>/npc/<npc_id>/talk', methods=['POST'])
|
||||
@require_auth
|
||||
def talk_to_npc(session_id: str, npc_id: str):
|
||||
|
||||
Reference in New Issue
Block a user