neoban/backend/app/Services/GeneratePostService.php
kushal-saha 20a56d4adc refactor(core): replace SocialMediaService with GeneratePostService, add message fetching and JSON:API resources
- Removed `SocialMediaService` and migrated core post generation logic to `GeneratePostService`.
- Added `GetAllChatMessagesAction` for fetching chat history.
- Introduced `MessageDto`, `MessageResource`, and `MessageCollection` for consistent backend API responses.
- Updated frontend state and services to support JSON:API-compliant chat messages and history retrieval.
- Improved typings and casting for chat message data.
2026-04-30 09:00:14 +00:00

29 lines
769 B
PHP

<?php
namespace App\Services;
use App\Ai\Agents\ContentWriterAgent;
use App\Data\Chats\MessageDto;
use App\Models\Chat;
class GeneratePostService
{
public function __construct(
private ContentWriterAgent $contentWriterAgent,
) {}
/**
* Generate a social media post with an image.
* We are not using database transactions here because we do not want to delete the user prompt
* if any of the ai agents fails.
*/
public function generate(string $prompt, Chat $chat): MessageDto
{
$socialMediaResponse = $this->contentWriterAgent
->continue($chat->id, $chat->user)
->prompt($prompt);
return MessageDto::fromAgentResponse($socialMediaResponse, ContentWriterAgent::class);
}
}