add system prompt and chunks index views and edit
This commit is contained in:
35
src/Controller/Admin/SystemAgentController.php
Normal file
35
src/Controller/Admin/SystemAgentController.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
// src/Controller/Admin/SystemAgentController.php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Controller\Admin;
|
||||
|
||||
use App\Service\Admin\IndexNdjsonInspector;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
||||
|
||||
#[IsGranted('ROLE_SUPER_ADMIN')]
|
||||
final class SystemAgentController extends AbstractController
|
||||
{
|
||||
#[Route('/admin/system/agent', name: 'admin_system_agent', methods: ['GET'])]
|
||||
public function index(Request $request, IndexNdjsonInspector $inspector): Response
|
||||
{
|
||||
$page = max(1, (int) $request->query->get('page', 1));
|
||||
$limit = max(1, min(200, (int) $request->query->get('limit', 50)));
|
||||
|
||||
$paths = $inspector->getPaths();
|
||||
$meta = $inspector->readMeta();
|
||||
$ndjsonPage = $inspector->readNdjsonPage($page, $limit);
|
||||
|
||||
return $this->render('admin/system/agent_overview.html.twig', [
|
||||
'paths' => $paths,
|
||||
'meta' => $meta,
|
||||
'ndjson' => $ndjsonPage,
|
||||
'debugCount'=>count($ndjsonPage['items'])
|
||||
]);
|
||||
}
|
||||
}
|
||||
94
src/Controller/Admin/SystemPromptController.php
Normal file
94
src/Controller/Admin/SystemPromptController.php
Normal file
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Controller\Admin;
|
||||
|
||||
use App\Entity\SystemPrompt;
|
||||
use App\Repository\SystemPromptRepository;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
||||
|
||||
#[IsGranted('ROLE_SUPER_ADMIN')]
|
||||
final class SystemPromptController extends AbstractController
|
||||
{
|
||||
#[Route('/admin/system/prompt', name: 'admin_system_prompt')]
|
||||
public function index(
|
||||
Request $request,
|
||||
SystemPromptRepository $repo,
|
||||
EntityManagerInterface $em
|
||||
): Response {
|
||||
|
||||
if ($request->isMethod('POST')) {
|
||||
$content = trim($request->request->get('content', ''));
|
||||
$comment = trim($request->request->get('comment', ''));
|
||||
|
||||
if ($content !== '') {
|
||||
|
||||
$active = $repo->findActive();
|
||||
if ($active) {
|
||||
$active->deactivate();
|
||||
}
|
||||
|
||||
$new = new SystemPrompt(
|
||||
version: $repo->getNextVersion(),
|
||||
content: $content,
|
||||
comment: $comment ?: null,
|
||||
active: true
|
||||
);
|
||||
|
||||
$em->persist($new);
|
||||
$em->flush();
|
||||
|
||||
$this->addFlash('success', 'Neue Version gespeichert.');
|
||||
return $this->redirectToRoute('admin_system_prompt');
|
||||
}
|
||||
}
|
||||
|
||||
return $this->render('admin/system/prompt.html.twig', [
|
||||
'active' => $repo->findActive(),
|
||||
'all' => $repo->findBy([], ['version' => 'DESC']),
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route('/admin/system/prompt/{id}/activate', name: 'admin_system_prompt_activate', methods: ['POST'])]
|
||||
public function activate(
|
||||
SystemPrompt $prompt,
|
||||
SystemPromptRepository $repo,
|
||||
EntityManagerInterface $em
|
||||
): Response {
|
||||
|
||||
foreach ($repo->findBy(['active' => true]) as $p) {
|
||||
$p->deactivate();
|
||||
}
|
||||
|
||||
$prompt->activate();
|
||||
|
||||
$em->flush();
|
||||
|
||||
$this->addFlash('success', 'Version aktiviert.');
|
||||
return $this->redirectToRoute('admin_system_prompt');
|
||||
}
|
||||
|
||||
#[Route('/admin/system/prompt/{id}/delete', name: 'admin_system_prompt_delete', methods: ['POST'])]
|
||||
public function delete(
|
||||
SystemPrompt $prompt,
|
||||
EntityManagerInterface $em
|
||||
): Response {
|
||||
|
||||
if ($prompt->isActive()) {
|
||||
$this->addFlash('danger', 'Aktive Version kann nicht gelöscht werden.');
|
||||
return $this->redirectToRoute('admin_system_prompt');
|
||||
}
|
||||
|
||||
$em->remove($prompt);
|
||||
$em->flush();
|
||||
|
||||
$this->addFlash('success', 'Version gelöscht.');
|
||||
return $this->redirectToRoute('admin_system_prompt');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user