You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

159 lines
4.9 KiB

  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\GenericFileException;
  25. use OCP\Files\NotPermittedException;
  26. use OCP\Lock\LockedException;
  27. use OCP\PreConditionNotMetException;
  28. use OCP\TaskProcessing\Exception\Exception;
  29. use OCP\TaskProcessing\Exception\NotFoundException;
  30. use OCP\TaskProcessing\Exception\ValidationException;
  31. /**
  32. * API surface for apps interacting with and making use of LanguageModel providers
  33. * without known which providers are installed
  34. * @since 30.0.0
  35. */
  36. interface IManager {
  37. /**
  38. * @since 30.0.0
  39. */
  40. public function hasProviders(): bool;
  41. /**
  42. * @return IProvider[]
  43. * @since 30.0.0
  44. */
  45. public function getProviders(): array;
  46. /**
  47. * @return array<string,array{name: string, description: string, inputShape: ShapeDescriptor[], optionalInputShape: array<string, ShapeDescriptor>, outputShape: array<string, ShapeDescriptor>, optionalOutputShape: array<string, ShapeDescriptor>}>
  48. * @since 30.0.0
  49. */
  50. public function getAvailableTaskTypes(): array;
  51. /**
  52. * @param Task $task The task to run
  53. * @throws PreConditionNotMetException If no or not the requested provider was registered but this method was still called
  54. * @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
  55. * @throws Exception storing the task in the database failed
  56. * @since 30.0.0
  57. */
  58. public function scheduleTask(Task $task): void;
  59. /**
  60. * Delete a task that has been scheduled before
  61. *
  62. * @param Task $task The task to delete
  63. * @throws Exception if deleting the task in the database failed
  64. * @since 30.0.0
  65. */
  66. public function deleteTask(Task $task): void;
  67. /**
  68. * @param int $id The id of the task
  69. * @return Task
  70. * @throws Exception If the query failed
  71. * @throws NotFoundException If the task could not be found
  72. * @since 30.0.0
  73. */
  74. public function getTask(int $id): Task;
  75. /**
  76. * @param int $id The id of the task
  77. * @throws Exception If the query failed
  78. * @throws NotFoundException If the task could not be found
  79. * @since 30.0.0
  80. */
  81. public function cancelTask(int $id): void;
  82. /**
  83. * @param int $id The id of the task
  84. * @param string|null $error
  85. * @param array|null $result
  86. * @throws Exception If the query failed
  87. * @throws NotFoundException If the task could not be found
  88. * @since 30.0.0
  89. */
  90. public function setTaskResult(int $id, ?string $error, ?array $result): void;
  91. /**
  92. * @param int $id
  93. * @param float $progress
  94. * @return bool `true` if the task should still be running; `false` if the task has been cancelled in the meantime
  95. * @throws ValidationException
  96. * @throws Exception
  97. * @throws NotFoundException
  98. * @since 30.0.0
  99. */
  100. public function setTaskProgress(int $id, float $progress): bool;
  101. /**
  102. * @param string|null $taskTypeId
  103. * @return Task
  104. * @throws Exception If the query failed
  105. * @throws NotFoundException If no task could not be found
  106. * @since 30.0.0
  107. */
  108. public function getNextScheduledTask(?string $taskTypeId = null): Task;
  109. /**
  110. * @param int $id The id of the task
  111. * @param string|null $userId The user id that scheduled the task
  112. * @return Task
  113. * @throws Exception If the query failed
  114. * @throws NotFoundException If the task could not be found
  115. * @since 30.0.0
  116. */
  117. public function getUserTask(int $id, ?string $userId): Task;
  118. /**
  119. * @param string|null $userId
  120. * @param string $appId
  121. * @param string|null $identifier
  122. * @return list<Task>
  123. * @throws Exception If the query failed
  124. * @throws \JsonException If parsing the task input and output failed
  125. * @since 30.0.0
  126. */
  127. public function getUserTasksByApp(?string $userId, string $appId, ?string $identifier = null): array;
  128. /**
  129. * Prepare the task's input data, so it can be processed by the provider
  130. * ie. this replaces file ids with base64 data
  131. *
  132. * @param Task $task
  133. * @return array<string, mixed>
  134. * @throws NotPermittedException
  135. * @throws GenericFileException
  136. * @throws LockedException
  137. * @throws ValidationException
  138. * @since 30.0.0
  139. */
  140. public function prepareInputData(Task $task): array;
  141. }