Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@

/** @see Controller\UserApiController::index() */
['name' => 'UserApi#index', 'url' => '/api/v1/users', 'verb' => 'POST'],

/** @see Controller\AiController::tagFile() */
['name' => 'Ai#tagFile', 'url' => '/ai/tag/{fileId}', 'verb' => 'POST'],
],
'ocs' => [
/** @see Controller\WorkspaceController::folder() */
Expand Down
2 changes: 2 additions & 0 deletions composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
'Composer\\InstalledVersions' => $vendorDir . '/composer/InstalledVersions.php',
'OCA\\Text\\AppInfo\\Application' => $baseDir . '/../lib/AppInfo/Application.php',
'OCA\\Text\\Command\\ResetDocument' => $baseDir . '/../lib/Command/ResetDocument.php',
'OCA\\Text\\Controller\\AiController' => $baseDir . '/../lib/Controller/AiController.php',
'OCA\\Text\\Controller\\AttachmentController' => $baseDir . '/../lib/Controller/AttachmentController.php',
'OCA\\Text\\Controller\\ISessionAwareController' => $baseDir . '/../lib/Controller/ISessionAwareController.php',
'OCA\\Text\\Controller\\NavigationController' => $baseDir . '/../lib/Controller/NavigationController.php',
Expand Down Expand Up @@ -64,6 +65,7 @@
'OCA\\Text\\Migration\\Version040100Date20240611165300' => $baseDir . '/../lib/Migration/Version040100Date20240611165300.php',
'OCA\\Text\\Migration\\Version070000Date20250925110024' => $baseDir . '/../lib/Migration/Version070000Date20250925110024.php',
'OCA\\Text\\Notification\\Notifier' => $baseDir . '/../lib/Notification/Notifier.php',
'OCA\\Text\\Service\\AiTagService' => $baseDir . '/../lib/Service/AiTagService.php',
'OCA\\Text\\Service\\ApiService' => $baseDir . '/../lib/Service/ApiService.php',
'OCA\\Text\\Service\\AttachmentService' => $baseDir . '/../lib/Service/AttachmentService.php',
'OCA\\Text\\Service\\ConfigService' => $baseDir . '/../lib/Service/ConfigService.php',
Expand Down
2 changes: 2 additions & 0 deletions composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class ComposerStaticInitText
'Composer\\InstalledVersions' => __DIR__ . '/..' . '/composer/InstalledVersions.php',
'OCA\\Text\\AppInfo\\Application' => __DIR__ . '/..' . '/../lib/AppInfo/Application.php',
'OCA\\Text\\Command\\ResetDocument' => __DIR__ . '/..' . '/../lib/Command/ResetDocument.php',
'OCA\\Text\\Controller\\AiController' => __DIR__ . '/..' . '/../lib/Controller/AiController.php',
'OCA\\Text\\Controller\\AttachmentController' => __DIR__ . '/..' . '/../lib/Controller/AttachmentController.php',
'OCA\\Text\\Controller\\ISessionAwareController' => __DIR__ . '/..' . '/../lib/Controller/ISessionAwareController.php',
'OCA\\Text\\Controller\\NavigationController' => __DIR__ . '/..' . '/../lib/Controller/NavigationController.php',
Expand Down Expand Up @@ -79,6 +80,7 @@ class ComposerStaticInitText
'OCA\\Text\\Migration\\Version040100Date20240611165300' => __DIR__ . '/..' . '/../lib/Migration/Version040100Date20240611165300.php',
'OCA\\Text\\Migration\\Version070000Date20250925110024' => __DIR__ . '/..' . '/../lib/Migration/Version070000Date20250925110024.php',
'OCA\\Text\\Notification\\Notifier' => __DIR__ . '/..' . '/../lib/Notification/Notifier.php',
'OCA\\Text\\Service\\AiTagService' => __DIR__ . '/..' . '/../lib/Service/AiTagService.php',
'OCA\\Text\\Service\\ApiService' => __DIR__ . '/..' . '/../lib/Service/ApiService.php',
'OCA\\Text\\Service\\AttachmentService' => __DIR__ . '/..' . '/../lib/Service/AttachmentService.php',
'OCA\\Text\\Service\\ConfigService' => __DIR__ . '/..' . '/../lib/Service/ConfigService.php',
Expand Down
32 changes: 32 additions & 0 deletions lib/Controller/AiController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OCA\Text\Controller;

use OCA\Text\Service\AiTagService;
use OCP\AppFramework\ApiController;
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
use OCP\AppFramework\Http\DataResponse;
use OCP\IRequest;

class AiController extends ApiController {
public function __construct(
string $appName,
IRequest $request,
private AiTagService $aiTagService,
) {
parent::__construct($appName, $request);
}

#[NoAdminRequired]
public function tagFile(int $fileId): DataResponse {
$this->aiTagService->tagFileAsAiGenerated($fileId);
return new DataResponse([]);
}
}
42 changes: 42 additions & 0 deletions lib/Service/AiTagService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OCA\Text\Service;

use OCP\SystemTag\ISystemTagObjectMapper;
use Psr\Log\LoggerInterface;

class AiTagService {
public function __construct(
private ISystemTagObjectMapper $systemTagObjectMapper,
private LoggerInterface $logger,
) {
}

/**
* @param int $fileId
*
* @return void
*
* @throws \Exception
*
* @since 34.0.0 (ISystemTagObjectMapper::assignGeneratedByAITag)
*/
public function tagFileAsAiGenerated(int $fileId): void {
try {
$this->systemTagObjectMapper->assignGeneratedByAITag((string)$fileId, 'files');
} catch (\Exception $e) {
$this->logger->warning('Failed to tag file {fileId} as AI-generated: {error}', [
'fileId' => $fileId,
'error' => $e->getMessage(),
'exception' => $e,
]);
}
}
}
20 changes: 20 additions & 0 deletions src/apis/ai.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import axios from '@nextcloud/axios'
import { generateUrl } from '@nextcloud/router'

/**
* tag a file as containing AI-generated content.
*
* @param fileId id of the file to tag.
*/
export async function markFileAsAiGenerated(fileId: number): Promise<void> {
try {
await axios.post(generateUrl(`apps/text/ai/tag/${fileId}`))
} catch (e) {
console.warn('failed to tag file as AI-generated', e)
}
}
1 change: 1 addition & 0 deletions src/components/Editor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
<Translate
:show="translateModal"
:content="translateContent"
:file-id="fileId"
@insert-content="translateInsert"
@replace-content="translateReplace"
@close="hideTranslate" />
Expand Down
4 changes: 4 additions & 0 deletions src/components/Menu/AssistantAction.vue
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ import TextBoxPlusOutlineIcon from 'vue-material-design-icons/TextBoxPlusOutline
import TextShort from 'vue-material-design-icons/TextShort.vue'
import TranslateVariant from 'vue-material-design-icons/Translate.vue'
import DeleteOutlineIcon from 'vue-material-design-icons/TrashCanOutline.vue'
import { markFileAsAiGenerated } from '../../apis/ai.ts'
import { useEditor } from '../../composables/useEditor.ts'
import { useFileProps } from '../../composables/useFileProps.ts'
import markdownit from '../../markdownit/index.js'
Expand Down Expand Up @@ -373,6 +374,9 @@ export default {
? markdownit.render(task.output.output)
: task.output.output
this.editor.commands.insertContent(content)
if (this.fileId) {
await markFileAsAiGenerated(this.fileId)
}
this.showTaskList = false
},
async copyResult(task) {
Expand Down
11 changes: 11 additions & 0 deletions src/components/Modal/Translate.vue
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ import NcLoadingIcon from '@nextcloud/vue/components/NcLoadingIcon'
import NcModal from '@nextcloud/vue/components/NcModal'
import NcSelect from '@nextcloud/vue/components/NcSelect'
import NcTextArea from '@nextcloud/vue/components/NcTextArea'
import { markFileAsAiGenerated } from '../../apis/ai.ts'
import { useIsMobileMixin } from '../Editor.provider.ts'

export default {
Expand All @@ -118,6 +119,10 @@ export default {
type: String,
default: '',
},
fileId: {
type: Number,
default: null,
},
},
data() {
return {
Expand Down Expand Up @@ -231,9 +236,15 @@ export default {
}
},
async contentInsert() {
if (this.fileId) {
await markFileAsAiGenerated(this.fileId)
}
this.$emit('insert-content', this.result)
},
async contentReplace() {
if (this.fileId) {
await markFileAsAiGenerated(this.fileId)
}
this.$emit('replace-content', this.result)
},
autosize() {
Expand Down
52 changes: 52 additions & 0 deletions tests/unit/Controller/AiControllerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OCA\Text\Controller;

use OCA\Text\Service\AiTagService;
use OCP\AppFramework\Http\DataResponse;
use OCP\IRequest;
use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;

class AiControllerTest extends TestCase {
private IRequest&MockObject $request;
private AiTagService&MockObject $aiTagService;
private AiController $controller;

protected function setUp(): void {
parent::setUp();
$this->request = $this->createMock(IRequest::class);
$this->aiTagService = $this->createMock(AiTagService::class);
$this->controller = new AiController(
'text',
$this->request,
$this->aiTagService,
);
}

public function testTagFileReturnsEmptyDataResponse(): void {
$this->aiTagService->expects($this->once())
->method('tagFileAsAiGenerated')
->with(42);

$response = $this->controller->tagFile(42);

$this->assertInstanceOf(DataResponse::class, $response);
$this->assertSame([], $response->getData());
}

public function testTagFilePassesCorrectFileId(): void {
$this->aiTagService->expects($this->once())
->method('tagFileAsAiGenerated')
->with(99999);

$this->controller->tagFile(99999);
}
}
Loading