Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ public function indexAction(): ResponseInterface
$this->moduleTemplate->assign('openDocumentId', $openDocumentId);
$loadChildrenUrl = $this->uriBuilder->reset()->uriFor('loadDocumentChildren', ['documentUid' => 'DOCUMENT_ID_PLACEHOLDER']);
$this->moduleTemplate->assign('loadChildrenUrl', $loadChildrenUrl);
$this->moduleTemplate->assign('semanticSearchAvailable', $this->modelAvailabilityService->isEmbeddingServerAvailable());
$this->moduleTemplate->assign('ragSearchAvailable', $this->modelAvailabilityService->isGenerationServerAvailable());
return $this->moduleTemplate->renderResponse('Backend/Index');
}

Expand Down Expand Up @@ -133,6 +131,22 @@ public function createAction(string $documentHeadline, int $parentId = 0, string
return $this->redirect('index', null, null, ['openDocumentId' => $result['documentUid']]);
}

public function ajaxCheckAvailabilityAction(ServerRequest $request): ResponseInterface
{
$service = $request->getQueryParams()['service'] ?? '';

$result = match($service) {
'semantic' => ['available' => $this->modelAvailabilityService->isEmbeddingServerAvailable()],
'rag' => ['available' => $this->modelAvailabilityService->isGenerationServerAvailable()],
default => [
'semantic' => $this->modelAvailabilityService->isEmbeddingServerAvailable(),
'rag' => $this->modelAvailabilityService->isGenerationServerAvailable(),
],
};

return $this->jsonResponse((string)json_encode($result));
}

public function ajaxLoadDocumentAction(ServerRequest $request): ResponseInterface
{
$params = $request->getQueryParams();
Expand Down
4 changes: 4 additions & 0 deletions packages/knowledge-base/Configuration/Backend/AjaxRoutes.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,8 @@
'path' => '/knowledgebase/searchDocuments',
'target' => BackendKnowledgeBaseController::class . '::ajaxSearchAction',
],
'checkAvailability' => [
'path' => '/knowledgebase/checkAvailability',
'target' => BackendKnowledgeBaseController::class . '::ajaxCheckAvailabilityAction',
],
];
10 changes: 10 additions & 0 deletions packages/knowledge-base/Resources/Public/Css/Search.css
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,16 @@
background: rgba(255, 135, 0, 0.06);
}

.kb-flyout-mode-btn:disabled {
opacity: 0.35;
cursor: not-allowed;
}

.kb-flyout-mode-btn:disabled:hover {
background: transparent;
color: #6b6b6b;
}

/* Flyout status (loading / error) */
.kb-flyout-status {
padding: 10px 12px;
Expand Down
31 changes: 31 additions & 0 deletions packages/knowledge-base/Resources/Public/JavaScript/Searchbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class KnowledgeBaseSearchBar {
this.iconBoard = document.getElementById('kb-icon-board')?.innerHTML ?? '';

this.bindEvents();
this.checkAvailability();
}

bindEvents() {
Expand Down Expand Up @@ -75,6 +76,36 @@ class KnowledgeBaseSearchBar {
this.form.addEventListener('submit', e => e.preventDefault());
}

async checkAvailability() {
const base = TYPO3?.settings?.ajaxUrls?.checkAvailability;
if (!base) return;

const check = async (service) => {
try {
const response = await fetch(`${base}&service=${service}`, {
headers: { 'X-Requested-With': 'XMLHttpRequest' },
});
if (!response.ok) return true;
const data = await response.json();
return data.available !== false;
} catch {
return true; // leave enabled if check fails
}
};

const [semanticOk, ragOk] = await Promise.all([check('semantic'), check('rag')]);

this.modeButtons.forEach(btn => {
if (btn.dataset.mode === 'semantic' && !semanticOk) {
btn.disabled = true;
btn.title = 'Semantic search server unavailable';
} else if (btn.dataset.mode === 'rag' && !ragOk) {
btn.disabled = true;
btn.title = 'RAG search server unavailable';
}
});
}

openFlyout() {
this.flyout.classList.add('is-open');
}
Expand Down