Skip to content

Commit 969669d

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 969669d

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ protected function supportsModel(Model $model): bool
4141
*
4242
* @return array{
4343
* role: 'assistant',
44-
* content: list<array{
44+
* content: string|list<array{
4545
* type: 'tool_use',
4646
* id: string,
4747
* name: string,
@@ -53,14 +53,14 @@ public function normalize(mixed $data, ?string $format = null, array $context =
5353
{
5454
return [
5555
'role' => 'assistant',
56-
'content' => array_map(static function (ToolCall $toolCall) {
56+
'content' => $data->hasToolCalls() ? array_map(static function (ToolCall $toolCall) {
5757
return [
5858
'type' => 'tool_use',
5959
'id' => $toolCall->id,
6060
'name' => $toolCall->name,
6161
'input' => [] !== $toolCall->arguments ? $toolCall->arguments : new \stdClass(),
6262
];
63-
}, $data->toolCalls),
63+
}, $data->toolCalls) : $data->content,
6464
];
6565
}
6666
}

0 commit comments

Comments
 (0)