Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Providers/OpenAI/Handlers/Stream.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,8 @@ protected function processStream(Response $response, Request $request, int $dept
timestamp: time(),
messageId: $this->state->messageId()
);

$this->state->markTextCompleted();
}

if (data_get($data, 'type') === 'response.completed') {
Expand Down
7 changes: 7 additions & 0 deletions src/Streaming/StreamState.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,13 @@ public function markTextStarted(): self
return $this;
}

public function markTextCompleted(): self
{
$this->textStarted = false;

return $this;
}

public function markThinkingStarted(): self
{
$this->thinkingStarted = true;
Expand Down
11 changes: 11 additions & 0 deletions tests/Unit/Streaming/StreamStateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,17 @@
->and($state->hasTextStarted())->toBeTrue();
});

it('markTextCompleted returns self and resets flag', function (): void {
$state = new StreamState;
$state->markTextStarted();

$result = $state->markTextCompleted();

expect($result)->toBe($state)
->and($state->hasTextStarted())->toBeFalse()
->and($state->shouldEmitTextStart())->toBeTrue();
});

it('markThinkingStarted returns self and sets flag', function (): void {
$state = new StreamState;

Expand Down