IManager.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2023 Marcel Klehr <mklehr@gmx.net>
  5. *
  6. * @author Marcel Klehr <mklehr@gmx.net>
  7. *
  8. * @license GNU AGPL version 3 or any later version
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License as
  12. * published by the Free Software Foundation, either version 3 of the
  13. * License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. */
  23. namespace OCP\TaskProcessing;
  24. use OCP\Files\File;
  25. use OCP\Files\GenericFileException;
  26. use OCP\Files\NotPermittedException;
  27. use OCP\Lock\LockedException;
  28. use OCP\TaskProcessing\Exception\Exception;
  29. use OCP\TaskProcessing\Exception\NotFoundException;
  30. use OCP\TaskProcessing\Exception\PreConditionNotMetException;
  31. use OCP\TaskProcessing\Exception\UnauthorizedException;
  32. use OCP\TaskProcessing\Exception\ValidationException;
  33. /**
  34. * API surface for apps interacting with and making use of LanguageModel providers
  35. * without known which providers are installed
  36. * @since 30.0.0
  37. */
  38. interface IManager {
  39. /**
  40. * @since 30.0.0
  41. */
  42. public function hasProviders(): bool;
  43. /**
  44. * @return IProvider[]
  45. * @since 30.0.0
  46. */
  47. public function getProviders(): array;
  48. /**
  49. * @return array<string,array{name: string, description: string, inputShape: ShapeDescriptor[], optionalInputShape: ShapeDescriptor[], outputShape: ShapeDescriptor[], optionalOutputShape: ShapeDescriptor[]}>
  50. * @since 30.0.0
  51. */
  52. public function getAvailableTaskTypes(): array;
  53. /**
  54. * @param Task $task The task to run
  55. * @throws PreConditionNotMetException If no or not the requested provider was registered but this method was still called
  56. * @throws ValidationException the given task input didn't pass validation against the task type's input shape and/or the providers optional input shape specs
  57. * @throws Exception storing the task in the database failed
  58. * @throws UnauthorizedException the user scheduling the task does not have access to the files used in the input
  59. * @since 30.0.0
  60. */
  61. public function scheduleTask(Task $task): void;
  62. /**
  63. * Delete a task that has been scheduled before
  64. *
  65. * @param Task $task The task to delete
  66. * @throws Exception if deleting the task in the database failed
  67. * @since 30.0.0
  68. */
  69. public function deleteTask(Task $task): void;
  70. /**
  71. * @param int $id The id of the task
  72. * @return Task
  73. * @throws Exception If the query failed
  74. * @throws NotFoundException If the task could not be found
  75. * @since 30.0.0
  76. */
  77. public function getTask(int $id): Task;
  78. /**
  79. * @param int $id The id of the task
  80. * @throws Exception If the query failed
  81. * @throws NotFoundException If the task could not be found
  82. * @since 30.0.0
  83. */
  84. public function cancelTask(int $id): void;
  85. /**
  86. * @param int $id The id of the task
  87. * @param string|null $error
  88. * @param array|null $result
  89. * @throws Exception If the query failed
  90. * @throws NotFoundException If the task could not be found
  91. * @since 30.0.0
  92. */
  93. public function setTaskResult(int $id, ?string $error, ?array $result): void;
  94. /**
  95. * @param int $id
  96. * @param float $progress
  97. * @return bool `true` if the task should still be running; `false` if the task has been cancelled in the meantime
  98. * @throws ValidationException
  99. * @throws Exception
  100. * @throws NotFoundException
  101. * @since 30.0.0
  102. */
  103. public function setTaskProgress(int $id, float $progress): bool;
  104. /**
  105. * @param string|null $taskTypeId
  106. * @return Task
  107. * @throws Exception If the query failed
  108. * @throws NotFoundException If no task could not be found
  109. * @since 30.0.0
  110. */
  111. public function getNextScheduledTask(?string $taskTypeId = null): Task;
  112. /**
  113. * @param int $id The id of the task
  114. * @param string|null $userId The user id that scheduled the task
  115. * @return Task
  116. * @throws Exception If the query failed
  117. * @throws NotFoundException If the task could not be found
  118. * @since 30.0.0
  119. */
  120. public function getUserTask(int $id, ?string $userId): Task;
  121. /**
  122. * @param string|null $userId The user id that scheduled the task
  123. * @param string|null $taskTypeId The task type id to filter by
  124. * @param string|null $customId
  125. * @return list<Task>
  126. * @throws Exception If the query failed
  127. * @throws NotFoundException If the task could not be found
  128. * @since 30.0.0
  129. */
  130. public function getUserTasks(?string $userId, ?string $taskTypeId = null, ?string $customId = null): array;
  131. /**
  132. * @param string|null $userId
  133. * @param string $appId
  134. * @param string|null $customId
  135. * @return list<Task>
  136. * @throws Exception If the query failed
  137. * @throws \JsonException If parsing the task input and output failed
  138. * @since 30.0.0
  139. */
  140. public function getUserTasksByApp(?string $userId, string $appId, ?string $customId = null): array;
  141. /**
  142. * Prepare the task's input data, so it can be processed by the provider
  143. * ie. this replaces file ids with base64 data
  144. *
  145. * @param Task $task
  146. * @return array<array-key, list<numeric|string|File>|numeric|string|File>
  147. * @throws NotPermittedException
  148. * @throws GenericFileException
  149. * @throws LockedException
  150. * @throws ValidationException
  151. * @since 30.0.0
  152. */
  153. public function prepareInputData(Task $task): array;
  154. }