Skip to content

Commit

Permalink
fixup! add thread summary ui
Browse files Browse the repository at this point in the history
Signed-off-by: hamza221 <[email protected]>
  • Loading branch information
hamza221 committed Aug 9, 2023
1 parent 5557c34 commit 1857c59
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 22 deletions.
5 changes: 0 additions & 5 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -325,11 +325,6 @@
'url' => '/api/settings/threadsummary',
'verb' => 'PUT'
],
[
'name' => 'settings#isLlmConfigured',
'url' => '/api/settings/llmconfigured',
'verb' => 'GET'
],
[
'name' => 'trusted_senders#setTrusted',
'url' => '/api/trustedsenders/{email}',
Expand Down
8 changes: 6 additions & 2 deletions lib/Controller/PageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
use OCA\Mail\Db\SmimeCertificate;
use OCA\Mail\Db\TagMapper;
use OCA\Mail\Service\AccountService;
use OCA\Mail\Service\AiIntegrationsService;
use OCA\Mail\Service\AliasesService;
use OCA\Mail\Service\OutboxService;
use OCA\Mail\Service\SmimeService;
Expand Down Expand Up @@ -73,6 +74,7 @@ class PageController extends Controller {
private IEventDispatcher $dispatcher;
private ICredentialstore $credentialStore;
private SmimeService $smimeService;
private AiIntegrationsService $aiIntegrationsService;

public function __construct(string $appName,
IRequest $request,
Expand All @@ -90,7 +92,8 @@ public function __construct(string $appName,
OutboxService $outboxService,
IEventDispatcher $dispatcher,
ICredentialStore $credentialStore,
SmimeService $smimeService) {
SmimeService $smimeService,
AiIntegrationsService $aiIntegrationsService) {
parent::__construct($appName, $request);

$this->urlGenerator = $urlGenerator;
Expand All @@ -108,6 +111,7 @@ public function __construct(string $appName,
$this->dispatcher = $dispatcher;
$this->credentialStore = $credentialStore;
$this->smimeService = $smimeService;
$this->aiIntegrationsService = $aiIntegrationsService;
}

/**
Expand Down Expand Up @@ -246,7 +250,7 @@ public function index(): TemplateResponse {

$this->initialStateService->provideInitialState(
'enabled_thread_summary',
$this->config->getAppValue('mail', 'enabled_thread_summary', 'no') === 'yes'
$this->config->getAppValue('mail', 'enabled_thread_summary', 'no') === 'yes' && $this->aiIntegrationsService->isLlmAvailable()
);

$this->initialStateService->provideInitialState(
Expand Down
9 changes: 9 additions & 0 deletions lib/Service/AiIntegrationsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,13 @@ public function summarizeThread(string $threadId, array $messages, string $curre
throw new ServiceException('No language model available for summary');
}
}

public function isLlmAvailable() :bool {
try {
$manager = $this->container->get(IManager::class);
} catch (\Throwable $e) {
return false;
}
return in_array(SummaryTaskType::class, $manager->getAvailableTaskTypes(), true);
}
}
12 changes: 11 additions & 1 deletion lib/Settings/AdminSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
use OCA\Mail\AppInfo\Application;
use OCA\Mail\Integration\GoogleIntegration;
use OCA\Mail\Integration\MicrosoftIntegration;
use OCA\Mail\Service\AiIntegrationsService;
use OCA\Mail\Service\AntiSpamService;
use OCA\Mail\Service\Provisioning\Manager as ProvisioningManager;
use OCP\AppFramework\Http\TemplateResponse;
Expand All @@ -49,19 +50,22 @@ class AdminSettings implements ISettings {
private GoogleIntegration $googleIntegration;
private MicrosoftIntegration $microsoftIntegration;
private IConfig $config;
private AiIntegrationsService $aiIntegrationsService;

public function __construct(IInitialStateService $initialStateService,
ProvisioningManager $provisioningManager,
AntiSpamService $antiSpamService,
GoogleIntegration $googleIntegration,
MicrosoftIntegration $microsoftIntegration,
IConfig $config) {
IConfig $config,
AiIntegrationsService $aiIntegrationsService) {
$this->initialStateService = $initialStateService;
$this->provisioningManager = $provisioningManager;
$this->antiSpamService = $antiSpamService;
$this->googleIntegration = $googleIntegration;
$this->microsoftIntegration = $microsoftIntegration;
$this->config = $config;
$this->aiIntegrationsService = $aiIntegrationsService;
}

public function getForm() {
Expand Down Expand Up @@ -92,6 +96,12 @@ public function getForm() {
$this->config->getAppValue('mail', 'enabled_thread_summary', 'no') === 'yes'
);

$this->initialStateService->provideInitialState(
Application::APP_ID,
'enabled_llm_backend',
$this->aiIntegrationsService->isLlmAvailable()
);

$this->initialStateService->provideLazyInitialState(
Application::APP_ID,
'ldap_aliases_integration',
Expand Down
7 changes: 1 addition & 6 deletions src/components/settings/AdminSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,6 @@ import {
provisionAll,
updateAllowNewMailAccounts,
updateEnabledThreadSummary,
isLlmConfigured,
} from '../../service/SettingsService'
const googleOauthClientId = loadState('mail', 'google_oauth_client_id', null) ?? undefined
Expand Down Expand Up @@ -341,12 +339,9 @@ export default {
},
allowNewMailAccounts: loadState('mail', 'allow_new_mail_accounts', true),
enabledThreadSummary: loadState('mail', 'enabled_thread_summary', false),
isLlmConfigured: false,
isLlmConfigured: loadState('mail', 'enabled_llm_backend'),
}
},
async beforeMount() {
this.isLlmConfigured = await isLlmConfigured()
},
methods: {
async saveSettings(settings) {
try {
Expand Down
1 change: 1 addition & 0 deletions src/service/AiIntergrationsService.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const summarizeThread = async (threadId) => {

try {
const resp = await axios.get(url)
if (resp.status === 204) throw convertAxiosError()
return resp.data.data
} catch (e) {
throw convertAxiosError(e)
Expand Down
7 changes: 0 additions & 7 deletions src/service/SettingsService.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,3 @@ export const updateEnabledThreadSummary = async (enabled) => {
const resp = await axios.put(url, data)
return resp.data
}

export const isLlmConfigured = async () => {
const url = generateUrl('/apps/mail/api/settings/llmconfigured')

const resp = await axios.get(url)
return resp.data.data
}
6 changes: 6 additions & 0 deletions tests/Unit/Controller/PageControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
use OCA\Mail\Db\Mailbox;
use OCA\Mail\Db\TagMapper;
use OCA\Mail\Service\AccountService;
use OCA\Mail\Service\AiIntegrationsService;
use OCA\Mail\Service\AliasesService;
use OCA\Mail\Service\MailManager;
use OCA\Mail\Service\OutboxService;
Expand Down Expand Up @@ -69,6 +70,9 @@ class PageControllerTest extends TestCase {
/** @var AccountService|MockObject */
private $accountService;

/** @var AiIntegrationsService|MockObject */
private $aiIntegrationsService;

/** @var AliasesService|MockObject */
private $aliasesService;

Expand Down Expand Up @@ -113,6 +117,7 @@ protected function setUp(): void {
$this->urlGenerator = $this->createMock(IURLGenerator::class);
$this->config = $this->createMock(IConfig::class);
$this->accountService = $this->createMock(AccountService::class);
$this->aiIntegrationsService = $this->createMock(AiIntegrationsService::class);
$this->aliasesService = $this->createMock(AliasesService::class);
$this->userSession = $this->createMock(IUserSession::class);
$this->preferences = $this->createMock(IUserPreferences::class);
Expand Down Expand Up @@ -143,6 +148,7 @@ protected function setUp(): void {
$this->eventDispatcher,
$this->credentialStore,
$this->smimeService,
$this->aiIntegrationsService,
);
}

Expand Down
7 changes: 6 additions & 1 deletion tests/Unit/Settings/AdminSettingsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function testGetSection() {
}

public function testGetForm() {
$this->serviceMock->getParameter('initialStateService')->expects($this->exactly(9))
$this->serviceMock->getParameter('initialStateService')->expects($this->exactly(10))
->method('provideInitialState')
->withConsecutive(
[
Expand All @@ -76,6 +76,11 @@ public function testGetForm() {
'enabled_thread_summary',
$this->anything()
],
[
Application::APP_ID,
'enabled_llm_backend',
$this->anything()
],
[
Application::APP_ID,
'google_oauth_client_id',
Expand Down

0 comments on commit 1857c59

Please sign in to comment.