Repository navigation
feat!: require laravel/ai 1.4; show admin conversations as a chat #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| @php | ||
| use Modules\AiChat\Ai\Tools\GenerateImage; | ||
| @endphp | ||
|
|
||
| @if ($messages->isEmpty()) | ||
| <x-filament::empty-state | ||
| :contained="false" | ||
| icon="heroicon-o-chat-bubble-left-right" | ||
| :heading="__('No saved messages')" | ||
| :description="__('A reply that fails isn\'t saved, and neither is its question.')" | ||
| /> | ||
| @else | ||
| <div class="flex flex-col gap-6"> | ||
| @foreach ($messages as $message) | ||
| @php | ||
| $isUser = $message->role === 'user'; | ||
| $images = collect($message->tool_results) | ||
| ->filter(fn (array $result): bool => $result['name'] === GenerateImage::NAME && empty($result['failed'])) | ||
|
Check warning on line 18 in resources/views/filament/transcript.blade.php
|
||
| ->map(fn (array $result): mixed => is_string($result['result']) ? json_decode($result['result'], true) : $result['result']) | ||
|
Check warning on line 19 in resources/views/filament/transcript.blade.php
|
||
| ->filter(fn (mixed $image): bool => is_array($image) && filled($image['url'] ?? null)); | ||
| @endphp | ||
|
|
||
| <div data-role="{{ $message->role }}" @class(['flex flex-col gap-1.5', 'items-end' => $isUser, 'items-start' => ! $isUser])> | ||
|
Check warning on line 23 in resources/views/filament/transcript.blade.php
|
||
| <div class="flex items-baseline gap-2 px-1 text-xs text-gray-500 dark:text-gray-400"> | ||
| <span class="font-medium text-gray-700 dark:text-gray-200">{{ $isUser ? $name : __('Assistant') }}</span> | ||
|
Check warning on line 25 in resources/views/filament/transcript.blade.php
|
||
| <time datetime="{{ $message->created_at->toIso8601String() }}">{{ $message->created_at->isoFormat('lll') }}</time> | ||
|
Check warning on line 26 in resources/views/filament/transcript.blade.php
|
||
| </div> | ||
|
|
||
| @foreach ($images as $image) | ||
| <img src="{{ $image['url'] }}" alt="{{ $image['prompt'] ?? '' }}" loading="lazy" class="w-full max-w-sm rounded-2xl" /> | ||
|
Check warning on line 30 in resources/views/filament/transcript.blade.php
|
||
| @endforeach | ||
|
|
||
| @if (filled($message->content)) | ||
| @if ($isUser) | ||
| <div class="max-w-[85%] rounded-2xl rounded-tr-sm bg-gray-900 px-4 py-2.5 text-sm break-words whitespace-pre-wrap text-white dark:bg-gray-200 dark:text-gray-950">{{ $message->content }}</div> | ||
|
Check warning on line 35 in resources/views/filament/transcript.blade.php
|
||
| @else | ||
| <div class="fi-prose max-w-[85%] overflow-x-auto rounded-2xl rounded-tl-sm bg-gray-100 px-4 py-2.5 text-sm break-words dark:bg-white/5"> | ||
|
Check warning on line 37 in resources/views/filament/transcript.blade.php
|
||
| {!! str($message->content)->markdown()->sanitizeHtml() !!} | ||
| </div> | ||
| @endif | ||
| @endif | ||
| </div> | ||
| @endforeach | ||
| </div> | ||
| @endif | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cleanup after a failed reply can delete another request's question.
forgetFailedTurn()pairs the latest failed assistant row with the latest user row before it. The cleanup callback receives only the conversation. It does not receive the request that failed. If two requests in one conversation overlap, the wrong question can be deleted. Two requests overlap when both send a message to the same conversation before the first reply fails. For example, a second browser tab can send a message while the first reply is still running. The framework does not serialize such requests unless the host setssession.block.Sequence:
forgetFailedTurn()deletes FA and QB. QA remains.Request B's reply can then be saved without its question. The failed question QA stays in the chat, and it still counts toward the monthly message limit. Sequential sends are not affected.
The cleanup needs the question stored by the failed request. Use that message's id, not the latest preceding user row. The controller does not currently receive that id, so this fix needs a way to pass it from the stream to the failure callback.