fix: handle content.thinking

This commit is contained in:
yokomotod 2025-06-19 21:00:07 +09:00
parent 7efa8b3987
commit 82ac5df92e
No known key found for this signature in database
3 changed files with 31 additions and 1 deletions

View file

@ -11,6 +11,7 @@ from ..types import (
ResultMessage,
SystemMessage,
TextBlock,
ThinkingBlock,
ToolResultBlock,
ToolUseBlock,
UserMessage,
@ -55,6 +56,13 @@ class InternalClient:
match block["type"]:
case "text":
content_blocks.append(TextBlock(text=block["text"]))
case "thinking":
content_blocks.append(
ThinkingBlock(
thinking=block["thinking"],
signature=block["signature"],
)
)
case "tool_use":
content_blocks.append(
ToolUseBlock(

View file

@ -26,6 +26,14 @@ class TextBlock:
text: str
@dataclass
class ThinkingBlock:
"""Thinking content block."""
thinking: str
signature: str
@dataclass
class ToolUseBlock:
"""Tool use content block."""

View file

@ -5,7 +5,13 @@ from claude_code_sdk import (
ClaudeCodeOptions,
ResultMessage,
)
from claude_code_sdk.types import TextBlock, ToolResultBlock, ToolUseBlock, UserMessage
from claude_code_sdk.types import (
TextBlock,
ThinkingBlock,
ToolResultBlock,
ToolUseBlock,
UserMessage,
)
class TestMessageTypes:
@ -23,6 +29,14 @@ class TestMessageTypes:
assert len(msg.content) == 1
assert msg.content[0].text == "Hello, human!"
def test_assistant_message_with_thinking(self):
"""Test creating an AssistantMessage with thinking content."""
thinking_block = ThinkingBlock(thinking="I'm thinking...", signature="sig-123")
msg = AssistantMessage(content=[thinking_block])
assert len(msg.content) == 1
assert msg.content[0].thinking == "I'm thinking..."
assert msg.content[0].signature == "sig-123"
def test_tool_use_block(self):
"""Test creating a ToolUseBlock."""
block = ToolUseBlock(