mirror of
https://github.com/home-assistant/core.git
synced 2026-12-05 21:29:58 -04:00
Include the first message in the chat log created event (#188844)
Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude
parent
1e1a563102
commit
4ecbfa925e
@@ -113,6 +113,16 @@ def async_get_chat_log(
|
||||
chat_log = ChatLog(hass, session.conversation_id)
|
||||
is_new_log = True
|
||||
all_chat_logs[session.conversation_id] = chat_log
|
||||
|
||||
chat_log.turn_start = len(chat_log.content)
|
||||
if user_input is not None:
|
||||
user_content = UserContent(content=user_input.text)
|
||||
if is_new_log:
|
||||
chat_log.content.append(user_content)
|
||||
else:
|
||||
chat_log.async_add_user_content(user_content)
|
||||
|
||||
if is_new_log:
|
||||
_async_notify_subscribers(
|
||||
hass,
|
||||
session.conversation_id,
|
||||
@@ -120,10 +130,6 @@ def async_get_chat_log(
|
||||
{"chat_log": chat_log.as_dict()},
|
||||
)
|
||||
|
||||
chat_log.turn_start = len(chat_log.content)
|
||||
if user_input is not None:
|
||||
chat_log.async_add_user_content(UserContent(content=user_input.text))
|
||||
|
||||
if chat_log_delta_listener:
|
||||
chat_log.delta_listener = chat_log_delta_listener
|
||||
|
||||
|
||||
@@ -1552,16 +1552,13 @@ async def test_chat_log_subscription(
|
||||
assert external_tool_event["tool_calls"][0].tool_name == "external_api_call"
|
||||
|
||||
# Verify we received the expected events
|
||||
# Should have: 1 CREATED event + 7 CONTENT_ADDED events
|
||||
assert len(received_events) == 8
|
||||
# Should have: 1 CREATED event + 6 CONTENT_ADDED events
|
||||
assert len(received_events) == 7
|
||||
|
||||
# Check the first event is CREATED
|
||||
# Check the first event is CREATED, with the message of the first turn
|
||||
assert received_events[0][1] == ChatLogEventType.CREATED
|
||||
assert received_events[0][2]["chat_log"]["conversation_id"] == conversation_id
|
||||
|
||||
# Check the second event is CONTENT_ADDED (from mock_conversation_input)
|
||||
assert received_events[1][1] == ChatLogEventType.CONTENT_ADDED
|
||||
assert received_events[1][0] == conversation_id
|
||||
assert received_events[0][2]["chat_log"]["content"][-1]["content"] == "Hello"
|
||||
|
||||
# Test cleanup functionality
|
||||
assert conversation_id in hass.data[chat_session.DATA_CHAT_SESSION]
|
||||
|
||||
@@ -882,7 +882,7 @@ async def test_ws_chat_log_index_subscription(
|
||||
conversation_id = session.conversation_id
|
||||
|
||||
# We should receive 2 events for this newly created chat:
|
||||
# 1. The CREATED event (fired before content is added)
|
||||
# 1. The CREATED event, with the message of the first turn
|
||||
msg = await client.receive_json()
|
||||
assert msg == {
|
||||
"type": "event",
|
||||
@@ -895,7 +895,10 @@ async def test_ws_chat_log_index_subscription(
|
||||
"conversation_id": conversation_id,
|
||||
"continue_conversation": False,
|
||||
"created": now,
|
||||
"content": [{"role": "system", "content": "", "created": now}],
|
||||
"content": [
|
||||
{"role": "system", "content": "", "created": now},
|
||||
{"role": "user", "content": "Hello", "created": now},
|
||||
],
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user