Skip to content

Commit

Permalink
update composer dependencies, fix psalm issues and run cs:fix, genera…
Browse files Browse the repository at this point in the history
…te openapi specs

Signed-off-by: Julien Veyssier <[email protected]>
  • Loading branch information
julien-nc committed Dec 21, 2024
1 parent 7e0eaf4 commit b7ef307
Show file tree
Hide file tree
Showing 20 changed files with 281 additions and 146 deletions.
268 changes: 161 additions & 107 deletions composer.lock

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions lib/Controller/AssistantApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function notifyWhenReady(int $ocpTaskId): DataResponse {
*
* Get all available task types that the assistant can handle.
*
* @return DataResponse<Http::STATUS_OK, array{types: array<AssistantTaskProcessingTaskType>}, array{}>
* @return DataResponse<Http::STATUS_OK, array{types: list<AssistantTaskProcessingTaskType>}, array{}>
*
* 200: Available task types returned
*/
Expand All @@ -94,7 +94,7 @@ public function getAvailableTaskTypes(): DataResponse {
* Get a list of assistant tasks for the current user.
*
* @param string|null $taskTypeId Task type id. If null, tasks of all task types will be retrieved
* @return DataResponse<Http::STATUS_OK, array{tasks: array<AssistantTaskProcessingTask>}, array{}>|DataResponse<Http::STATUS_NOT_FOUND, '', array{}>
* @return DataResponse<Http::STATUS_OK, array{tasks: list<AssistantTaskProcessingTask>}, array{}>|DataResponse<Http::STATUS_NOT_FOUND, '', array{}>
*
* 200: User tasks returned
* 404: No tasks found
Expand Down Expand Up @@ -139,7 +139,7 @@ public function parseTextFromFile(?string $filePath = null, ?int $fileId = null)

try {
$text = $this->assistantService->parseTextFromFile($this->userId, $filePath, $fileId);
} catch (\Exception | \Throwable $e) {
} catch (\Exception|\Throwable $e) {
return new DataResponse($e->getMessage(), Http::STATUS_BAD_REQUEST);
}
return new DataResponse([
Expand Down Expand Up @@ -280,7 +280,7 @@ public function getOutputFilePreview(int $ocpTaskId, int $fileId): RedirectRespo
} elseif ($preview['type'] === 'icon') {
return new RedirectResponse($preview['icon']);
}
} catch (Exception | Throwable $e) {
} catch (Exception|Throwable $e) {
$this->logger->error('getImage error', ['exception' => $e]);
return new DataResponse('', Http::STATUS_NOT_FOUND);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Controller/AssistantController.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function getAssistantTaskResultPage(int $taskId): TemplateResponse {
$this->initialStateService->provideInitialState('task', $task->jsonSerialize());
return new TemplateResponse(Application::APP_ID, 'assistantPage');
}
} catch (Exception | \Throwable $e) {
} catch (Exception|\Throwable $e) {
}
}
return new TemplateResponse('', '403', [], TemplateResponse::RENDER_AS_ERROR, Http::STATUS_FORBIDDEN);
Expand Down
11 changes: 5 additions & 6 deletions lib/Controller/ChattyLLMController.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
use OCP\TaskProcessing\Exception\ValidationException;
use OCP\TaskProcessing\IManager as ITaskProcessingManager;
use OCP\TaskProcessing\Task;
use OCP\TaskProcessing\TaskTypes\TextToText;
use OCP\TaskProcessing\TaskTypes\TextToTextChat;
use Psr\Log\LoggerInterface;

Expand Down Expand Up @@ -90,7 +89,7 @@ public function newSession(int $timestamp, ?string $title = null): JSONResponse
return new JSONResponse([
'session' => $session,
]);
} catch (\OCP\DB\Exception | \RuntimeException $e) {
} catch (\OCP\DB\Exception|\RuntimeException $e) {
$this->logger->warning('Failed to create a chat session', ['exception' => $e]);
return new JSONResponse(['error' => $this->l10n->t('Failed to create a chat session')], Http::STATUS_INTERNAL_SERVER_ERROR);
}
Expand All @@ -112,7 +111,7 @@ public function updateSessionTitle(int $sessionId, string $title): JSONResponse
try {
$this->sessionMapper->updateSessionTitle($this->userId, $sessionId, $title);
return new JSONResponse();
} catch (\OCP\DB\Exception | \RuntimeException $e) {
} catch (\OCP\DB\Exception|\RuntimeException $e) {
$this->logger->warning('Failed to update the chat session', ['exception' => $e]);
return new JSONResponse(['error' => $this->l10n->t('Failed to update the chat session')], Http::STATUS_INTERNAL_SERVER_ERROR);
}
Expand All @@ -134,7 +133,7 @@ public function deleteSession(int $sessionId): JSONResponse {
$this->sessionMapper->deleteSession($this->userId, $sessionId);
$this->messageMapper->deleteMessagesBySession($sessionId);
return new JSONResponse();
} catch (\OCP\DB\Exception | \RuntimeException $e) {
} catch (\OCP\DB\Exception|\RuntimeException $e) {
$this->logger->warning('Failed to delete the chat session', ['exception' => $e]);
return new JSONResponse(['error' => $this->l10n->t('Failed to delete the chat session')], Http::STATUS_INTERNAL_SERVER_ERROR);
}
Expand Down Expand Up @@ -266,7 +265,7 @@ public function deleteMessage(int $messageId, int $sessionId): JSONResponse {

$this->messageMapper->deleteMessageById($messageId);
return new JSONResponse();
} catch (\OCP\DB\Exception | \RuntimeException $e) {
} catch (\OCP\DB\Exception|\RuntimeException $e) {
$this->logger->warning('Failed to delete a chat message', ['exception' => $e]);
return new JSONResponse(['error' => $this->l10n->t('Failed to delete a chat message')], Http::STATUS_INTERNAL_SERVER_ERROR);
}
Expand Down Expand Up @@ -642,7 +641,7 @@ private function checkIfSessionIsThinking(string $customId): void {
* @throws ValidationException
*/
private function scheduleLLMChatTask(
string $newPrompt, string $systemPrompt, array $history, int $sessionId, bool $isMessage = true
string $newPrompt, string $systemPrompt, array $history, int $sessionId, bool $isMessage = true,
): ?int {
$customId = ($isMessage
? 'chatty-llm:'
Expand Down
2 changes: 1 addition & 1 deletion lib/Controller/ConfigController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function __construct(
IRequest $request,
private IConfig $config,
private IAppConfig $appConfig,
private ?string $userId
private ?string $userId,
) {
parent::__construct($appName, $request);
}
Expand Down
5 changes: 3 additions & 2 deletions lib/Controller/PreviewController.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Nextcloud - Assistant
*
Expand Down Expand Up @@ -34,7 +35,7 @@ public function __construct(
IRequest $request,
private PreviewService $imageService,
private LoggerInterface $logger,
private ?string $userId
private ?string $userId,
) {
parent::__construct($appName, $request);
}
Expand Down Expand Up @@ -64,7 +65,7 @@ public function getFileImage(int $id, int $x = 100, int $y = 100): Response {
} elseif ($preview['type'] === 'icon') {
return new RedirectResponse($preview['icon']);
}
} catch (Exception | Throwable $e) {
} catch (Exception|Throwable $e) {
$this->logger->error('getImage error', ['exception' => $e]);
return new DataResponse('', Http::STATUS_NOT_FOUND);
}
Expand Down
5 changes: 3 additions & 2 deletions lib/Db/TaskNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
namespace OCA\Assistant\Db;

use OCP\AppFramework\Db\Entity;
use OCP\DB\Types;

/**
* @method \int getOcpTaskId()
Expand All @@ -22,8 +23,8 @@ class TaskNotification extends Entity implements \JsonSerializable {


public function __construct() {
$this->addType('ocp_task_id', 'int');
$this->addType('timestamp', 'int');
$this->addType('ocp_task_id', Types::INTEGER);
$this->addType('timestamp', Types::INTEGER);
}

#[\ReturnTypeWillChange]
Expand Down
4 changes: 2 additions & 2 deletions lib/Event/BeforeAssistantNotificationEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function getNotificationTarget(): ?string {

/**
* @param string|null $notificationTarget URL that will be used as target for the notification and its main action,
* null means the assistant will take care of rendering the result (in a modal or by setting a dedicated NC page showing the result)
* null means the assistant will take care of rendering the result (in a modal or by setting a dedicated NC page showing the result)
* @return void
*/
public function setNotificationTarget(?string $notificationTarget): void {
Expand All @@ -75,7 +75,7 @@ public function getNotificationActionLabel(): ?string {

/**
* @param string|null $notificationActionLabel Label of the main notification action
* null will not change the default action label
* null will not change the default action label
* @return void
*/
public function setNotificationActionLabel(?string $notificationActionLabel): void {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* @copyright Copyright (c) 2023 Anupam Kumar <[email protected]>
*
Expand Down
2 changes: 1 addition & 1 deletion lib/Notification/Notifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public function prepare(INotification $notification, string $languageCode): INot
$taskType = $availableTaskTypes[$params['taskTypeId']];
$taskTypeName = $taskType['name'];
}
} catch (\Exception | \Throwable $e) {
} catch (\Exception|\Throwable $e) {
$this->logger->debug('Impossible to get task type ' . $params['taskTypeId'], ['exception' => $e]);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Reference/FreePromptReferenceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function __construct(
private IL10N $l10n,
private IURLGenerator $urlGenerator,
private IReferenceManager $referenceManager,
private ?string $userId
private ?string $userId,
) {
}

Expand Down
3 changes: 2 additions & 1 deletion lib/Reference/SpeechToTextReferenceProvider.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* @copyright Copyright (c) 2023 Anupam Kumar <[email protected]>
*
Expand Down Expand Up @@ -35,7 +36,7 @@ public function __construct(
private IL10N $l10n,
private IURLGenerator $urlGenerator,
private IReferenceManager $referenceManager,
private ?string $userId
private ?string $userId,
) {
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Reference/Text2ImageReferenceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function __construct(
private IL10N $l10n,
private IURLGenerator $urlGenerator,
private IReferenceManager $referenceManager,
private ?string $userId
private ?string $userId,
) {
}

Expand Down
9 changes: 6 additions & 3 deletions lib/ResponseDefinitions.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,17 @@
* appId: string,
* completionExpectedAt: integer|null,
* customId: string|null,
* id: int|null,
* input: array<string, mixed>,
* id: int,
* input: array<string, list<numeric|string>|numeric|string>,
* lastUpdated: integer,
* output: array<string, mixed>,
* output: array<string, list<numeric|string>|numeric|string>|null,
* progress: float|null,
* status: string,
* type: string,
* userId: string|null,
* endedAt: int|null,
* scheduledAt: int|null,
* startedAt: int|null,
* }
*/
class ResponseDefinitions {
Expand Down
4 changes: 2 additions & 2 deletions lib/Service/AssistantService.php
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ public function parseTextFromFile(string $userId, ?string $filePath = null, ?int

try {
$userFolder = $this->rootFolder->getUserFolder($userId);
} catch (\OC\User\NoUserException | NotPermittedException $e) {
} catch (\OC\User\NoUserException|NotPermittedException $e) {
throw new \Exception('Could not access user storage.');
}

Expand All @@ -577,7 +577,7 @@ public function parseTextFromFile(string $userId, ?string $filePath = null, ?int
} else {
throw new \Exception('Provided path does not point to a file.');
}
} catch (LockedException | GenericFileException | NotPermittedException $e) {
} catch (LockedException|GenericFileException|NotPermittedException $e) {
throw new \Exception('File could not be accessed.');
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Service/NotificationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function sendNotification(Task $task, ?string $customTarget = null, ?stri
$notification->setApp(Application::APP_ID)
->setUser($task->getUserId())
->setDateTime(new DateTime())
->setObject($objectType, (string) ($task->getId() ?? 0))
->setObject($objectType, (string)($task->getId() ?? 0))
->setSubject($subject, $params);

$manager->notify($notification);
Expand Down
2 changes: 1 addition & 1 deletion lib/Settings/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function getForm(): TemplateResponse {
$speechToTextEnabled = $this->appConfig->getValueString(Application::APP_ID, 'speech_to_text_picker_enabled', '1') === '1';
$chattyLLMUserInstructions = $this->appConfig->getValueString(Application::APP_ID, 'chat_user_instructions', Application::CHAT_USER_INSTRUCTIONS);
$chattyLLMUserInstructionsTitle = $this->appConfig->getValueString(Application::APP_ID, 'chat_user_instructions_title', Application::CHAT_USER_INSTRUCTIONS_TITLE);
$chattyLLMLastNMessages = (int) $this->appConfig->getValueString(Application::APP_ID, 'chat_last_n_messages', '10');
$chattyLLMLastNMessages = (int)$this->appConfig->getValueString(Application::APP_ID, 'chat_last_n_messages', '10');

$adminConfig = [
'text_processing_available' => $taskProcessingAvailable,
Expand Down
6 changes: 3 additions & 3 deletions lib/Settings/PersonalSection.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class PersonalSection implements IIconSection {

public function __construct(
private IURLGenerator $urlGenerator,
private IL10N $l
private IL10N $l,
) {
}

Expand All @@ -35,8 +35,8 @@ public function getName(): string {

/**
* @return int whether the form should be rather on the top or bottom of
* the settings navigation. The sections are arranged in ascending order of
* the priority values. It is required to return a value between 0 and 99.
* the settings navigation. The sections are arranged in ascending order of
* the priority values. It is required to return a value between 0 and 99.
*/
public function getPriority(): int {
return 40;
Expand Down
68 changes: 63 additions & 5 deletions openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,10 @@
"progress",
"status",
"type",
"userId"
"userId",
"endedAt",
"scheduledAt",
"startedAt"
],
"properties": {
"appId": {
Expand All @@ -115,13 +118,32 @@
},
"id": {
"type": "integer",
"format": "int64",
"nullable": true
"format": "int64"
},
"input": {
"type": "object",
"additionalProperties": {
"type": "object"
"oneOf": [
{
"type": "array",
"items": {
"oneOf": [
{
"type": "number"
},
{
"type": "string"
}
]
}
},
{
"type": "number"
},
{
"type": "string"
}
]
}
},
"lastUpdated": {
Expand All @@ -130,8 +152,29 @@
},
"output": {
"type": "object",
"nullable": true,
"additionalProperties": {
"type": "object"
"oneOf": [
{
"type": "array",
"items": {
"oneOf": [
{
"type": "number"
},
{
"type": "string"
}
]
}
},
{
"type": "number"
},
{
"type": "string"
}
]
}
},
"progress": {
Expand All @@ -148,6 +191,21 @@
"userId": {
"type": "string",
"nullable": true
},
"endedAt": {
"type": "integer",
"format": "int64",
"nullable": true
},
"scheduledAt": {
"type": "integer",
"format": "int64",
"nullable": true
},
"startedAt": {
"type": "integer",
"format": "int64",
"nullable": true
}
}
},
Expand Down
Loading

0 comments on commit b7ef307

Please sign in to comment.