Skip to content

Commit

Permalink
feat: filter disabled apps in task types requests
Browse files Browse the repository at this point in the history
Signed-off-by: Jana Peper <[email protected]>
  • Loading branch information
janepie committed Dec 8, 2024
1 parent 5e999b2 commit 3ef601c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public function getForm() {
}
$taskProcessingTaskTypes = [];
$taskProcessingTypeSettings = [];
foreach ($this->taskProcessingManager->getAvailableTaskTypes() as $taskTypeId => $taskTypeDefinition) {
foreach ($this->taskProcessingManager->getAvailableTaskTypes(true) as $taskTypeId => $taskTypeDefinition) {
$taskProcessingTaskTypes[] = [
'id' => $taskTypeId,
'name' => $taskTypeDefinition['name'],
Expand Down
4 changes: 1 addition & 3 deletions apps/settings/src/components/AdminAI.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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}">
Expand Down Expand Up @@ -189,7 +189,6 @@ export default {
this.saveChanges()
},
async saveChanges() {
console.warn(this.settings)
this.loading = true
await nextTick()
const data = { settings: this.settings }
Expand All @@ -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)) {
Expand Down
14 changes: 13 additions & 1 deletion lib/private/TaskProcessing/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,14 @@ private function _getTaskTypes(): array {
return $taskTypes;
}

/**
* @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
Expand Down Expand Up @@ -718,12 +726,16 @@ public function getPreferredProvider(string $taskTypeId) {
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) {
Expand Down
3 changes: 2 additions & 1 deletion lib/public/TaskProcessing/IManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,11 @@ public function getProviders(): array;
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
Expand Down

0 comments on commit 3ef601c

Please sign in to comment.