-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
feat: add Context Chat OCP API #53859
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
12b7129
feat: add Context Chat OCP API
edward-ly 42b2ca9
chore: update autoloaders
edward-ly 8653368
fix(psalm): suppress UndefinedClass error for OCA\ContextChat\Public\…
edward-ly 48406c3
feat(ContextChat): add isContextChatAvailable method to OCP API
edward-ly 9516d00
fix: add strict typing to ContextChat classes
edward-ly aafcbcc
chore(ContextChat): add docblocks to ContentItem properties
edward-ly File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| /** | ||
| * SPDX-FileCopyrightText: 2024-2025 Nextcloud GmbH and Nextcloud contributors | ||
| * SPDX-License-Identifier: AGPL-3.0-or-later | ||
| */ | ||
|
|
||
| namespace OC\ContextChat; | ||
|
|
||
| use OCA\ContextChat\Public\ContentManager as ContextChatContentManager; | ||
| use OCP\ContextChat\IContentManager; | ||
|
|
||
| class ContentManager implements IContentManager { | ||
| public function __construct( | ||
| private ?ContextChatContentManager $contentManager, | ||
nickvergessen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ) { | ||
| } | ||
|
|
||
| public function isContextChatAvailable(): bool { | ||
| return $this->contentManager !== null; | ||
| } | ||
|
|
||
| public function registerContentProvider(string $appId, string $providerId, string $providerClass): void { | ||
| $this->contentManager?->registerContentProvider($appId, $providerId, $providerClass); | ||
| } | ||
|
|
||
| public function collectAllContentProviders(): void { | ||
| $this->contentManager?->collectAllContentProviders(); | ||
| } | ||
|
|
||
| public function submitContent(string $appId, array $items): void { | ||
| $this->contentManager?->submitContent($appId, $items); | ||
| } | ||
|
|
||
| public function updateAccess(string $appId, string $providerId, string $itemId, string $op, array $userIds): void { | ||
| $this->contentManager?->updateAccess($appId, $providerId, $itemId, $op, $userIds); | ||
| } | ||
|
|
||
| public function updateAccessProvider(string $appId, string $providerId, string $op, array $userIds): void { | ||
| $this->contentManager?->updateAccessProvider($appId, $providerId, $op, $userIds); | ||
| } | ||
|
|
||
| public function updateAccessDeclarative(string $appId, string $providerId, string $itemId, array $userIds): void { | ||
| $this->contentManager?->updateAccessDeclarative($appId, $providerId, $itemId, $op, $userIds); | ||
| } | ||
|
|
||
| public function deleteProvider(string $appId, string $providerId): void { | ||
| $this->contentManager?->deleteProvider($appId, $providerId); | ||
| } | ||
|
|
||
| public function deleteContent(string $appId, string $providerId, array $itemIds): void { | ||
| $this->contentManager?->deleteContent($appId, $providerId, $itemIds); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 { | ||
marcelklehr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| /** | ||
| * @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, | ||
edward-ly marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| /** | ||
| * @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, | ||
| ) { | ||
| } | ||
| } | ||
35 changes: 35 additions & 0 deletions
35
lib/public/ContextChat/Events/ContentProviderRegisterEvent.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| <?php | ||
edward-ly marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| 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; | ||
marcelklehr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| /** | ||
| * 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; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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'; | ||
| } | ||
marcelklehr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.