Skip to content

Commit dca22c1

Browse files
provokateurinjulien-nc
authored andcommitted
core: Document text processing API
Signed-off-by: jld3103 <jld3103yt@gmail.com>
1 parent 8c846ce commit dca22c1

3 files changed

Lines changed: 519 additions & 0 deletions

File tree

core/Controller/TextProcessingApiController.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
namespace OC\Core\Controller;
2828

2929
use InvalidArgumentException;
30+
use OCA\Core\ResponseDefinitions;
3031
use OCP\AppFramework\Http;
3132
use OCP\AppFramework\Http\DataResponse;
3233
use OCP\Common\Exception\NotFoundException;
@@ -41,6 +42,9 @@
4142
use Psr\Container\NotFoundExceptionInterface;
4243
use Psr\Log\LoggerInterface;
4344

45+
/**
46+
* @psalm-import-type CoreTextProcessingTask from ResponseDefinitions
47+
*/
4448
class TextProcessingApiController extends \OCP\AppFramework\OCSController {
4549
public function __construct(
4650
string $appName,
@@ -58,10 +62,13 @@ public function __construct(
5862
* This endpoint returns all available LanguageModel task types
5963
*
6064
* @PublicPage
65+
*
66+
* @return DataResponse<Http::STATUS_OK, array{types: array{id: string, name: string, description: string}[]}, array{}>
6167
*/
6268
public function taskTypes(): DataResponse {
6369
$typeClasses = $this->languageModelManager->getAvailableTaskTypes();
6470
$types = [];
71+
/** @var string $typeClass */
6572
foreach ($typeClasses as $typeClass) {
6673
try {
6774
/** @var ITaskType $object */
@@ -88,6 +95,17 @@ public function taskTypes(): DataResponse {
8895
* @PublicPage
8996
* @UserRateThrottle(limit=20, period=120)
9097
* @AnonRateThrottle(limit=5, period=120)
98+
*
99+
* @param string $input Input text
100+
* @param string $type Type of the task
101+
* @param string $appId ID of the app that will execute the task
102+
* @param string $identifier An arbitrary identifier for the task
103+
*
104+
* @return DataResponse<Http::STATUS_OK, array{task: CoreTextProcessingTask}, array{}>|DataResponse<Http::STATUS_BAD_REQUEST|Http::STATUS_PRECONDITION_FAILED, array{message: string}, array{}>
105+
*
106+
* 200: Task scheduled successfully
107+
* 400: Scheduling task is not possible
108+
* 412: Scheduling task is not possible
91109
*/
92110
public function schedule(string $input, string $type, string $appId, string $identifier = ''): DataResponse {
93111
try {
@@ -114,6 +132,11 @@ public function schedule(string $input, string $type, string $appId, string $ide
114132
*
115133
* @PublicPage
116134
* @param int $id The id of the task
135+
*
136+
* @return DataResponse<Http::STATUS_OK, array{task: CoreTextProcessingTask}, array{}>|DataResponse<Http::STATUS_NOT_FOUND|Http::STATUS_INTERNAL_SERVER_ERROR, array{message: string}, array{}>
137+
*
138+
* 200: Task returned
139+
* 404: Task not found
117140
*/
118141
public function getTask(int $id): DataResponse {
119142
try {

core/ResponseDefinitions.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,17 @@
126126
* subline: string,
127127
* shareWithDisplayNameUnique: string,
128128
* }
129+
*
130+
* @psalm-type CoreTextProcessingTask = array{
131+
* id: ?int,
132+
* type: string,
133+
* status: 0|1|2|3|4,
134+
* userId: ?string,
135+
* appId: string,
136+
* input: string,
137+
* output: ?string,
138+
* identifier: string,
139+
* }
129140
*/
130141
class ResponseDefinitions {
131142
}

0 commit comments

Comments
 (0)