diff options
Diffstat (limited to 'lib/public/ContextChat')
-rw-r--r-- | lib/public/ContextChat/ContentItem.php | 57 | ||||
-rw-r--r-- | lib/public/ContextChat/Events/ContentProviderRegisterEvent.php | 35 | ||||
-rw-r--r-- | lib/public/ContextChat/IContentManager.php | 115 | ||||
-rw-r--r-- | lib/public/ContextChat/IContentProvider.php | 49 | ||||
-rw-r--r-- | lib/public/ContextChat/Type/UpdateAccessOp.php | 18 |
5 files changed, 274 insertions, 0 deletions
diff --git a/lib/public/ContextChat/ContentItem.php b/lib/public/ContextChat/ContentItem.php new file mode 100644 index 00000000000..2b5289ba350 --- /dev/null +++ b/lib/public/ContextChat/ContentItem.php @@ -0,0 +1,57 @@ +<?php + +declare(strict_types=1); + +/** + * SPDX-FileCopyrightText: 2024-2025 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +namespace OCP\ContextChat; + +/** + * @since 32.0.0 + */ +class ContentItem { + /** + * @param string $itemId + * @param string $providerId + * @param string $title + * @param string $content + * @param string $documentType + * @param \DateTime $lastModified + * @param string[] $users + * @since 32.0.0 + */ + public function __construct( + /** + * @since 32.0.0 + */ + public string $itemId, + /** + * @since 32.0.0 + */ + public string $providerId, + /** + * @since 32.0.0 + */ + public string $title, + /** + * @since 32.0.0 + */ + public string $content, + /** + * @since 32.0.0 + */ + public string $documentType, + /** + * @since 32.0.0 + */ + public \DateTime $lastModified, + /** + * @since 32.0.0 + */ + public array $users, + ) { + } +} diff --git a/lib/public/ContextChat/Events/ContentProviderRegisterEvent.php b/lib/public/ContextChat/Events/ContentProviderRegisterEvent.php new file mode 100644 index 00000000000..32a542a0dbf --- /dev/null +++ b/lib/public/ContextChat/Events/ContentProviderRegisterEvent.php @@ -0,0 +1,35 @@ +<?php + +declare(strict_types=1); + +/** + * SPDX-FileCopyrightText: 2024-2025 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +namespace OCP\ContextChat\Events; + +use OCP\ContextChat\IContentManager; +use OCP\ContextChat\IContentProvider; +use OCP\EventDispatcher\Event; + +/** + * @since 32.0.0 + */ +class ContentProviderRegisterEvent extends Event { + public function __construct( + private IContentManager $contentManager, + ) { + } + + /** + * @param string $appId + * @param string $providerId + * @param class-string<IContentProvider> $providerClass + * @return void + * @since 32.0.0 + */ + public function registerContentProvider(string $appId, string $providerId, string $providerClass): void { + $this->contentManager->registerContentProvider($appId, $providerId, $providerClass); + } +} diff --git a/lib/public/ContextChat/IContentManager.php b/lib/public/ContextChat/IContentManager.php new file mode 100644 index 00000000000..54e48809291 --- /dev/null +++ b/lib/public/ContextChat/IContentManager.php @@ -0,0 +1,115 @@ +<?php + +declare(strict_types=1); + +/** + * SPDX-FileCopyrightText: 2024-2025 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +namespace OCP\ContextChat; + +/** + * @since 32.0.0 + */ +interface IContentManager { + /** + * Checks if the context chat app is enabled or not + * + * @return bool + * @since 32.0.0 + */ + public function isContextChatAvailable(): bool; + + /** + * @param string $appId + * @param string $providerId + * @param class-string<IContentProvider> $providerClass + * @return void + * @since 32.0.0 + */ + public function registerContentProvider(string $appId, string $providerId, string $providerClass): void; + + /** + * Emits an event to collect all content providers + * + * @return void + * @since 32.0.0 + */ + public function collectAllContentProviders(): void; + + /** + * Providers can use this to submit content for indexing in context chat + * + * @param string $appId + * @param ContentItem[] $items + * @return void + * @since 32.0.0 + */ + public function submitContent(string $appId, array $items): void; + + /** + * Update access for a content item for specified users. + * This modifies the access list for the content item, + * allowing or denying access to the specified users. + * If no user has access to the content item, it will be removed from the knowledge base. + * + * @param string $appId + * @param string $providerId + * @param string $itemId + * @param Type\UpdateAccessOp::* $op + * @param array $userIds + * @return void + * @since 32.0.0 + */ + public function updateAccess(string $appId, string $providerId, string $itemId, string $op, array $userIds): void; + + /** + * Update access for content items from the given provider for specified users. + * If no user has access to the content item, it will be removed from the knowledge base. + * + * @param string $appId + * @param string $providerId + * @param Type\UpdateAccessOp::* $op + * @param array $userIds + * @return void + * @since 32.0.0 + */ + public function updateAccessProvider(string $appId, string $providerId, string $op, array $userIds): void; + + /** + * Update access for a content item for specified users declaratively. + * This overwrites the access list for the content item, + * allowing only the specified users access to it. + * + * @param string $appId + * @param string $providerId + * @param string $itemId + * @param array $userIds + * @return void + * @since 32.0.0 + */ + public function updateAccessDeclarative(string $appId, string $providerId, string $itemId, array $userIds): void; + + /** + * Delete all content items and access lists for a provider. + * This does not unregister the provider itself. + * + * @param string $appId + * @param string $providerId + * @return void + * @since 32.0.0 + */ + public function deleteProvider(string $appId, string $providerId): void; + + /** + * Remove a content item from the knowledge base of context chat. + * + * @param string $appId + * @param string $providerId + * @param string[] $itemIds + * @return void + * @since 32.0.0 + */ + public function deleteContent(string $appId, string $providerId, array $itemIds): void; +} diff --git a/lib/public/ContextChat/IContentProvider.php b/lib/public/ContextChat/IContentProvider.php new file mode 100644 index 00000000000..b0c736e3c88 --- /dev/null +++ b/lib/public/ContextChat/IContentProvider.php @@ -0,0 +1,49 @@ +<?php + +declare(strict_types=1); + +/** + * SPDX-FileCopyrightText: 2024-2025 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +namespace OCP\ContextChat; + +/** + * This interface defines methods to implement a content provider + * @since 32.0.0 + */ +interface IContentProvider { + /** + * The ID of the provider + * + * @return string + * @since 32.0.0 + */ + public function getId(): string; + + /** + * The ID of the app making the provider avaialble + * + * @return string + * @since 32.0.0 + */ + public function getAppId(): string; + + /** + * The absolute URL to the content item + * + * @param string $id + * @return string + * @since 32.0.0 + */ + public function getItemUrl(string $id): string; + + /** + * Starts the initial import of content items into context chat + * + * @return void + * @since 32.0.0 + */ + public function triggerInitialImport(): void; +} diff --git a/lib/public/ContextChat/Type/UpdateAccessOp.php b/lib/public/ContextChat/Type/UpdateAccessOp.php new file mode 100644 index 00000000000..65100d1ce83 --- /dev/null +++ b/lib/public/ContextChat/Type/UpdateAccessOp.php @@ -0,0 +1,18 @@ +<?php + +declare(strict_types=1); + +/** + * SPDX-FileCopyrightText: 2024-2025 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +namespace OCP\ContextChat\Type; + +/** + * @since 32.0.0 + */ +class UpdateAccessOp { + public const ALLOW = 'allow'; + public const DENY = 'deny'; +} |