Skip to content

Commit e08c3b1

Browse files
committed
Fix TypeError in AssistantMessageNormalizer when toolCalls is null
- Use hasToolCalls() check before array_map to prevent TypeError - Return content when no tool calls are present - Maintains backward compatibility and proper return types
1 parent 11ef98f commit e08c3b1

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

src/platform/src/Bridge/Anthropic/Contract/AssistantMessageNormalizer.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,12 @@ final class AssistantMessageNormalizer extends ModelContractNormalizer implement
2626
{
2727
use NormalizerAwareTrait;
2828

29-
protected function supportedDataClass(): string
30-
{
31-
return AssistantMessage::class;
32-
}
33-
34-
protected function supportsModel(Model $model): bool
35-
{
36-
return $model instanceof Claude;
37-
}
38-
3929
/**
4030
* @param AssistantMessage $data
4131
*
4232
* @return array{
4333
* role: 'assistant',
44-
* content: list<array{
34+
* content: string|list<array{
4535
* type: 'tool_use',
4636
* id: string,
4737
* name: string,
@@ -53,14 +43,24 @@ public function normalize(mixed $data, ?string $format = null, array $context =
5343
{
5444
return [
5545
'role' => 'assistant',
56-
'content' => array_map(static function (ToolCall $toolCall) {
46+
'content' => $data->hasToolCalls() ? array_map(static function (ToolCall $toolCall) {
5747
return [
5848
'type' => 'tool_use',
5949
'id' => $toolCall->id,
6050
'name' => $toolCall->name,
6151
'input' => [] !== $toolCall->arguments ? $toolCall->arguments : new \stdClass(),
6252
];
63-
}, $data->toolCalls),
53+
}, $data->toolCalls) : $data->content,
6454
];
6555
}
56+
57+
protected function supportedDataClass(): string
58+
{
59+
return AssistantMessage::class;
60+
}
61+
62+
protected function supportsModel(Model $model): bool
63+
{
64+
return $model instanceof Claude;
65+
}
6666
}

0 commit comments

Comments
 (0)