mirror of
https://github.com/anthropics/claude-code-sdk-python.git
synced 2025-12-23 09:19:52 +00:00
lint and typecheck
This commit is contained in:
parent
a04d040c31
commit
a63ccd31ec
1 changed files with 7 additions and 5 deletions
|
|
@ -46,13 +46,15 @@ def parse_message(data: dict[str, Any]) -> Message:
|
|||
case "user":
|
||||
try:
|
||||
if isinstance(data["message"]["content"], list):
|
||||
content_blocks: list[ContentBlock] = []
|
||||
user_content_blocks: list[ContentBlock] = []
|
||||
for block in data["message"]["content"]:
|
||||
match block["type"]:
|
||||
case "text":
|
||||
content_blocks.append(TextBlock(text=block["text"]))
|
||||
user_content_blocks.append(
|
||||
TextBlock(text=block["text"])
|
||||
)
|
||||
case "tool_use":
|
||||
content_blocks.append(
|
||||
user_content_blocks.append(
|
||||
ToolUseBlock(
|
||||
id=block["id"],
|
||||
name=block["name"],
|
||||
|
|
@ -60,14 +62,14 @@ def parse_message(data: dict[str, Any]) -> Message:
|
|||
)
|
||||
)
|
||||
case "tool_result":
|
||||
content_blocks.append(
|
||||
user_content_blocks.append(
|
||||
ToolResultBlock(
|
||||
tool_use_id=block["tool_use_id"],
|
||||
content=block.get("content"),
|
||||
is_error=block.get("is_error"),
|
||||
)
|
||||
)
|
||||
return UserMessage(content=content_blocks)
|
||||
return UserMessage(content=user_content_blocks)
|
||||
except KeyError as e:
|
||||
raise MessageParseError(
|
||||
f"Missing required field in user message: {e}", data
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue