Skip to content

Commit

Permalink
feat(TaskProcessing): Implement enums and default values
Browse files Browse the repository at this point in the history
Signed-off-by: Marcel Klehr <mklehr@gmx.net>
  • Loading branch information
marcelklehr committed Jul 24, 2024
1 parent fd9de40 commit 93753c1
Show file tree
Hide file tree
Showing 9 changed files with 423 additions and 59 deletions.
48 changes: 29 additions & 19 deletions core/Controller/TaskProcessingApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
use OCP\TaskProcessing\Exception\ValidationException;
use OCP\TaskProcessing\IManager;
use OCP\TaskProcessing\ShapeDescriptor;
use OCP\TaskProcessing\ShapeEnumValue;
use OCP\TaskProcessing\Task;
use RuntimeException;

Expand Down Expand Up @@ -67,26 +68,35 @@ public function __construct(
#[PublicPage]
#[ApiRoute(verb: 'GET', url: '/tasktypes', root: '/taskprocessing')]
public function taskTypes(): DataResponse {
$taskTypes = $this->taskProcessingManager->getAvailableTaskTypes();

$serializedTaskTypes = [];
foreach ($taskTypes as $key => $taskType) {
$serializedTaskTypes[$key] = [
'name' => $taskType['name'],
'description' => $taskType['description'],
'inputShape' => array_map(fn (ShapeDescriptor $descriptor) =>
$descriptor->jsonSerialize() + ['mandatory' => true], $taskType['inputShape'])
+ array_map(fn (ShapeDescriptor $descriptor) =>
$descriptor->jsonSerialize() + ['mandatory' => false], $taskType['optionalInputShape']),
'outputShape' => array_map(fn (ShapeDescriptor $descriptor) =>
$descriptor->jsonSerialize() + ['mandatory' => true], $taskType['outputShape'])
+ array_map(fn (ShapeDescriptor $descriptor) =>
$descriptor->jsonSerialize() + ['mandatory' => false], $taskType['optionalOutputShape']),
];
}

$taskTypes = array_map(function(array $tt) {
$tt['inputShape'] = array_map(function($descriptor) {
return $descriptor->jsonSerialize();
}, $tt['inputShape']);
$tt['outputShape'] = array_map(function($descriptor) {
return $descriptor->jsonSerialize();
}, $tt['outputShape']);
$tt['optionalInputShape'] = array_map(function($descriptor) {
return $descriptor->jsonSerialize();
}, $tt['optionalInputShape']);
$tt['optionalOutputShape'] = array_map(function($descriptor) {
return $descriptor->jsonSerialize();
}, $tt['optionalOutputShape']);
$tt['inputShapeEnumValues'] = array_map(function(array $enumValues) {
return array_map(fn(ShapeEnumValue $enumValue) => $enumValue->jsonSerialize(), $enumValues);
}, $tt['inputShapeEnumValues']);
$tt['optionalInputShapeEnumValues'] = array_map(function(array $enumValues) {
return array_map(fn(ShapeEnumValue $enumValue) => $enumValue->jsonSerialize(), $enumValues);
}, $tt['optionalInputShapeEnumValues']);
$tt['outputShapeEnumValues'] = array_map(function(array $enumValues) {
return array_map(fn(ShapeEnumValue $enumValue) => $enumValue->jsonSerialize(), $enumValues);
}, $tt['outputShapeEnumValues']);
$tt['optionalOutputShapeEnumValues'] = array_map(function(array $enumValues) {
return array_map(fn(ShapeEnumValue $enumValue) => $enumValue->jsonSerialize(), $enumValues);
}, $tt['optionalOutputShapeEnumValues']);
return $tt;
}, $this->taskProcessingManager->getAvailableTaskTypes());
return new DataResponse([
'types' => $serializedTaskTypes,
'types' => $taskTypes,
]);
}

Expand Down
14 changes: 12 additions & 2 deletions core/ResponseDefinitions.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

namespace OC\Core;

use OCP\TaskProcessing\ShapeDescriptor;
use OCP\TaskProcessing\ShapeEnumValue;

/**
* @psalm-type CoreLoginFlowV2Credentials = array{
* server: string,
Expand Down Expand Up @@ -165,15 +168,22 @@
* @psalm-type CoreTaskProcessingShape = array{
* name: string,
* description: string,
* type: "Number"|"Text"|"Audio"|"Image"|"Video"|"File"|"ListOfNumbers"|"ListOfTexts"|"ListOfImages"|"ListOfAudios"|"ListOfVideos"|"ListOfFiles",
* mandatory: bool,
* type: "Number"|"Text"|"Audio"|"Image"|"Video"|"File"|"Enum"|"ListOfNumbers"|"ListOfTexts"|"ListOfImages"|"ListOfAudios"|"ListOfVideos"|"ListOfFiles",
* }
*
* @psalm-type CoreTaskProcessingTaskType = array{
* name: string,
* description: string,
* inputShape: CoreTaskProcessingShape[],
* inputShapeEnumValues: array{name: string, value: string}[][],
* inputShapeDefaults: array<array-key, numeric|string>,
* optionalInputShape: CoreTaskProcessingShape[],
* optionalInputShapeEnumValues: array{name: string, value: string}[][],
* optionalInputShapeDefaults: array<array-key, numeric|string>,
* outputShape: CoreTaskProcessingShape[],
* outputShapeEnumValues: array{name: string, value: string}[][],
* optionalOutputShape: CoreTaskProcessingShape[],
* optionalOutputShapeEnumValues: array{name: string, value: string}[][]}
* }
*
* @psalm-type CoreTaskProcessingIO = array<string, numeric|list<numeric>|string|list<string>>
Expand Down
Loading

0 comments on commit 93753c1

Please sign in to comment.