Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
feat: filter disabled apps in task types requests
Signed-off-by: Jana Peper <[email protected]>
  • Loading branch information
janepie committed Dec 18, 2024
commit 8cac92665d78304aaeb5e9b521f371960175d3df
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 @@ -564,6 +564,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 @@ -721,12 +729,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