Skip to content

Commit 4d9a484

Browse files
committed
stan
1 parent 9882179 commit 4d9a484

22 files changed

+85
-8
lines changed

.cursor/commands/fix-stan.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Use `composer stan --no-progress` to see the PHPStan failures, and then fix them.
1+
Use `composer stan --no-progress` to see the PHPStan failures, and then fix them. Do not ignore failures unless they are truly impossible to fix.

phpstan.dist.neon

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,5 @@ parameters:
33
paths:
44
- src
55
excludePaths:
6-
- src/LLM/Drivers/Anthropic/AnthropicChat.php
76
- src/LLM/Streaming
87
tmpDir: .phpstan-cache

src/LLM/Drivers/Anthropic/AnthropicChat.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,9 @@ protected function buildParams(array $additionalParameters): array
207207
];
208208
}
209209

210+
/**
211+
* @param array<string, mixed> $responses
212+
*/
210213
public static function fake(
211214
array $responses,
212215
?string $apiKey = null,

src/LLM/Drivers/Anthropic/Concerns/MapStreamResponse.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ protected function mapStreamResponse(MessageStream $response): ChatStreamResult
9292
usage: $usage,
9393
),
9494
),
95-
createdAt: $meta?->createdAt ?? new DateTimeImmutable(),
95+
createdAt: $meta->createdAt ?? new DateTimeImmutable(),
9696
finishReason: $finishReason,
9797
usage: $usage,
9898
contentSoFar: $contentSoFar,

src/LLM/Drivers/Anthropic/Concerns/MapsResponse.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,11 @@ protected function mapResponse(MessageResponse $message): ChatResult
3131
$finishReason = $this->mapFinishReason($message->stopReason);
3232
$meta = $message->getMeta();
3333

34-
$toolCalls = collect($message->content)
35-
->filter(fn(object $content): bool => $content instanceof ToolUseContentBlock)
34+
/** @var \Illuminate\Support\Collection<int, \Cortex\SDK\Anthropic\Contracts\ContentBlock> $contentCollection */
35+
$contentCollection = collect($message->content);
36+
/** @var \Illuminate\Support\Collection<int, ToolUseContentBlock> $toolUseBlocks */
37+
$toolUseBlocks = $contentCollection->filter(fn(object $content): bool => $content instanceof ToolUseContentBlock);
38+
$toolCalls = $toolUseBlocks
3639
->map(function (ToolUseContentBlock $content): ToolCall {
3740
return new ToolCall(
3841
$content->id,
@@ -56,11 +59,11 @@ protected function mapResponse(MessageResponse $message): ChatResult
5659
finishReason: $finishReason,
5760
usage: $usage,
5861
processingTime: $meta?->processingTime,
59-
providerMetadata: $meta?->raw ?? [],
62+
providerMetadata: $meta->raw ?? [],
6063
),
6164
id: $message->id,
6265
),
63-
createdAt: $meta?->createdAt ?? new DateTimeImmutable(),
66+
createdAt: $meta->createdAt ?? new DateTimeImmutable(),
6467
finishReason: $finishReason,
6568
);
6669

@@ -78,6 +81,11 @@ protected function mapResponse(MessageResponse $message): ChatResult
7881
);
7982
}
8083

84+
/**
85+
* @param array<int, \Cortex\SDK\Anthropic\Contracts\ContentBlock> $content
86+
*
87+
* @return array<int, \Cortex\LLM\Data\Messages\Content\TextContent|\Cortex\LLM\Data\Messages\Content\ReasoningContent>
88+
*/
8189
protected function mapContent(array $content): array
8290
{
8391
return collect($content)

src/SDK/Anthropic/Contracts/StreamEvent.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,14 @@
88

99
interface StreamEvent
1010
{
11+
/**
12+
* @param array<string, mixed> $payload
13+
*/
1114
public static function from(array $payload): self;
1215

16+
/**
17+
* @return array<string, mixed>
18+
*/
1319
public function raw(): array;
1420

1521
public function meta(): ?Meta;

src/SDK/Anthropic/Data/Messages/ContentBlocks/ServerToolUseContentBlock.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ final class ServerToolUseContentBlock implements ContentBlock
1010
{
1111
public string $type = 'server_tool_use';
1212

13+
/**
14+
* @param array<string, mixed> $input
15+
*/
1316
public function __construct(
1417
public string $id,
1518
public string $name,

src/SDK/Anthropic/Data/Messages/ContentBlocks/ToolUseContentBlock.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ final class ToolUseContentBlock implements ContentBlock
1010
{
1111
public string $type = 'tool_use';
1212

13+
/**
14+
* @param array<string, mixed> $input
15+
*/
1316
public function __construct(
1417
public string $id,
1518
public string $name,

src/SDK/Anthropic/Data/Messages/ContentBlocks/WebSearchToolResultContentBlock.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ final class WebSearchToolResultContentBlock implements ContentBlock
1010
{
1111
public string $type = 'web_search_tool_result';
1212

13+
/**
14+
* @param array<int, mixed> $content
15+
*/
1316
public function __construct(
1417
public string $toolUseId,
1518
public array $content,

src/SDK/Anthropic/Data/Messages/Message.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ public function __construct(
3434
public ?Usage $usage = null,
3535
) {}
3636

37+
/**
38+
* @param array<string, mixed> $payload
39+
*/
3740
public static function from(array $payload): self
3841
{
3942
return new self(

0 commit comments

Comments
 (0)