mirror of
https://github.com/anthropics/claude-code-sdk-python.git
synced 2025-12-23 09:19:52 +00:00
added uuid to userMessage type
This commit is contained in:
parent
f834ba9e15
commit
c5d7971ec9
3 changed files with 19 additions and 0 deletions
|
|
@ -48,6 +48,7 @@ def parse_message(data: dict[str, Any]) -> Message:
|
|||
case "user":
|
||||
try:
|
||||
parent_tool_use_id = data.get("parent_tool_use_id")
|
||||
uuid = data.get("uuid")
|
||||
if isinstance(data["message"]["content"], list):
|
||||
user_content_blocks: list[ContentBlock] = []
|
||||
for block in data["message"]["content"]:
|
||||
|
|
@ -74,10 +75,12 @@ def parse_message(data: dict[str, Any]) -> Message:
|
|||
)
|
||||
return UserMessage(
|
||||
content=user_content_blocks,
|
||||
uuid=uuid,
|
||||
parent_tool_use_id=parent_tool_use_id,
|
||||
)
|
||||
return UserMessage(
|
||||
content=data["message"]["content"],
|
||||
uuid=uuid,
|
||||
parent_tool_use_id=parent_tool_use_id,
|
||||
)
|
||||
except KeyError as e:
|
||||
|
|
|
|||
|
|
@ -562,6 +562,7 @@ class UserMessage:
|
|||
"""User message."""
|
||||
|
||||
content: str | list[ContentBlock]
|
||||
uuid: str | None = None
|
||||
parent_tool_use_id: str | None = None
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -31,6 +31,21 @@ class TestMessageParser:
|
|||
assert isinstance(message.content[0], TextBlock)
|
||||
assert message.content[0].text == "Hello"
|
||||
|
||||
def test_parse_user_message_with_uuid(self):
|
||||
"""Test parsing a user message with uuid field (issue #414).
|
||||
|
||||
The uuid field is needed for file checkpointing with rewind_files().
|
||||
"""
|
||||
data = {
|
||||
"type": "user",
|
||||
"uuid": "msg-abc123-def456",
|
||||
"message": {"content": [{"type": "text", "text": "Hello"}]},
|
||||
}
|
||||
message = parse_message(data)
|
||||
assert isinstance(message, UserMessage)
|
||||
assert message.uuid == "msg-abc123-def456"
|
||||
assert len(message.content) == 1
|
||||
|
||||
def test_parse_user_message_with_tool_use(self):
|
||||
"""Test parsing a user message with tool_use block."""
|
||||
data = {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue