aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJana Peper <jana.peper@nextcloud.com>2024-12-08 19:16:19 +0100
committerjanepie <49834966+janepie@users.noreply.github.com>2024-12-18 18:32:34 +0100
commit8cac92665d78304aaeb5e9b521f371960175d3df (patch)
tree22fded9bbec9a6fc896cc8df3b451b4ee04572bc
parent32b57e7b4120043c1f21ba881914e61e24d8f2a5 (diff)
downloadnextcloud-server-8cac92665d78304aaeb5e9b521f371960175d3df.tar.gz
nextcloud-server-8cac92665d78304aaeb5e9b521f371960175d3df.zip
feat: filter disabled apps in task types requests
Signed-off-by: Jana Peper <jana.peper@nextcloud.com>
-rw-r--r--apps/settings/lib/Settings/Admin/ArtificialIntelligence.php2
-rw-r--r--apps/settings/src/components/AdminAI.vue4
-rw-r--r--lib/private/TaskProcessing/Manager.php14
-rw-r--r--lib/public/TaskProcessing/IManager.php3
4 files changed, 17 insertions, 6 deletions
diff --git a/apps/settings/lib/Settings/Admin/ArtificialIntelligence.php b/apps/settings/lib/Settings/Admin/ArtificialIntelligence.php
index 197ea0de283..c6069635367 100644
--- a/apps/settings/lib/Settings/Admin/ArtificialIntelligence.php
+++ b/apps/settings/lib/Settings/Admin/ArtificialIntelligence.php
@@ -114,7 +114,7 @@ class ArtificialIntelligence implements IDelegatedSettings {
}
$taskProcessingTaskTypes = [];
$taskProcessingTypeSettings = [];
- foreach ($this->taskProcessingManager->getAvailableTaskTypes() as $taskTypeId => $taskTypeDefinition) {
+ foreach ($this->taskProcessingManager->getAvailableTaskTypes(true) as $taskTypeId => $taskTypeDefinition) {
$taskProcessingTaskTypes[] = [
'id' => $taskTypeId,
'name' => $taskTypeDefinition['name'],
diff --git a/apps/settings/src/components/AdminAI.vue b/apps/settings/src/components/AdminAI.vue
index 0d6f32a9aa9..fe8044d93b5 100644
--- a/apps/settings/src/components/AdminAI.vue
+++ b/apps/settings/src/components/AdminAI.vue
@@ -18,7 +18,7 @@
<NcSelect v-model="settings['ai.taskprocessing_provider_preferences'][type.id]"
class="provider-select"
:clearable="false"
- :disabled="!type.enabled"
+ :disabled="!settings['ai.taskprocessing_type_preferences'][type.id]"
:options="taskProcessingProviders.filter(p => p.taskType === type.id).map(p => p.id)"
@input="saveChanges">
<template #option="{label}">
@@ -189,7 +189,6 @@ export default {
this.saveChanges()
},
async saveChanges() {
- console.warn(this.settings)
this.loading = true
await nextTick()
const data = { settings: this.settings }
@@ -199,7 +198,6 @@ export default {
console.error('could not save changes', err)
}
this.loading = false
- console.warn('done')
},
getTextProcessingTaskType(type) {
if (!Array.isArray(this.textProcessingTaskTypes)) {
diff --git a/lib/private/TaskProcessing/Manager.php b/lib/private/TaskProcessing/Manager.php
index ffa39912a01..f24b1b73da4 100644
--- a/lib/private/TaskProcessing/Manager.php
+++ b/lib/private/TaskProcessing/Manager.php
@@ -565,6 +565,14 @@ class Manager implements IManager {
}
/**
+ * @return array
+ */
+ private function _getTaskTypeSettings(): array {
+ $json = $this->config->getAppValue('core', 'ai.taskprocessing_type_preferences', '');
+ return json_decode($json, true);
+ }
+
+ /**
* @param ShapeDescriptor[] $spec
* @param array<array-key, string|numeric> $defaults
* @param array<array-key, ShapeEnumValue[]> $enumValues
@@ -721,12 +729,16 @@ class Manager implements IManager {
throw new \OCP\TaskProcessing\Exception\Exception('No matching provider found');
}
- public function getAvailableTaskTypes(): array {
+ public function getAvailableTaskTypes(bool $showDisabled = false): array {
if ($this->availableTaskTypes === null) {
$taskTypes = $this->_getTaskTypes();
+ $taskTypeSettings = $this->_getTaskTypeSettings();
$availableTaskTypes = [];
foreach ($taskTypes as $taskType) {
+ if ((!$showDisabled) && isset($taskTypeSettings[$taskType->getId()]) && !$taskTypeSettings[$taskType->getId()]) {
+ continue;
+ }
try {
$provider = $this->getPreferredProvider($taskType->getId());
} catch (\OCP\TaskProcessing\Exception\Exception $e) {
diff --git a/lib/public/TaskProcessing/IManager.php b/lib/public/TaskProcessing/IManager.php
index 1b59bb12ad4..a4ce9e8bbbe 100644
--- a/lib/public/TaskProcessing/IManager.php
+++ b/lib/public/TaskProcessing/IManager.php
@@ -46,10 +46,11 @@ interface IManager {
public function getPreferredProvider(string $taskTypeId);
/**
+ * @param bool $showDisabled if false, disabled task types will be filtered
* @return array<string, array{name: string, description: string, inputShape: ShapeDescriptor[], inputShapeEnumValues: ShapeEnumValue[][], inputShapeDefaults: array<array-key, numeric|string>, optionalInputShape: ShapeDescriptor[], optionalInputShapeEnumValues: ShapeEnumValue[][], optionalInputShapeDefaults: array<array-key, numeric|string>, outputShape: ShapeDescriptor[], outputShapeEnumValues: ShapeEnumValue[][], optionalOutputShape: ShapeDescriptor[], optionalOutputShapeEnumValues: ShapeEnumValue[][]}>
* @since 30.0.0
*/
- public function getAvailableTaskTypes(): array;
+ public function getAvailableTaskTypes(bool $showDisabled = false): array;
/**
* @param Task $task The task to run