Skip to content

Commit 8210e12

Browse files
authored
Merge pull request #53859 from nextcloud/feat/context-chat-ocp
feat: add Context Chat OCP API
2 parents 6a013e6 + aafcbcc commit 8210e12

File tree

10 files changed

+345
-0
lines changed

10 files changed

+345
-0
lines changed

lib/composer/composer/autoload_classmap.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,11 @@
286286
'OCP\\Contacts\\ContactsMenu\\IProvider' => $baseDir . '/lib/public/Contacts/ContactsMenu/IProvider.php',
287287
'OCP\\Contacts\\Events\\ContactInteractedWithEvent' => $baseDir . '/lib/public/Contacts/Events/ContactInteractedWithEvent.php',
288288
'OCP\\Contacts\\IManager' => $baseDir . '/lib/public/Contacts/IManager.php',
289+
'OCP\\ContextChat\\ContentItem' => $baseDir . '/lib/public/ContextChat/ContentItem.php',
290+
'OCP\\ContextChat\\Events\\ContentProviderRegisterEvent' => $baseDir . '/lib/public/ContextChat/Events/ContentProviderRegisterEvent.php',
291+
'OCP\\ContextChat\\IContentManager' => $baseDir . '/lib/public/ContextChat/IContentManager.php',
292+
'OCP\\ContextChat\\IContentProvider' => $baseDir . '/lib/public/ContextChat/IContentProvider.php',
293+
'OCP\\ContextChat\\Type\\UpdateAccessOp' => $baseDir . '/lib/public/ContextChat/Type/UpdateAccessOp.php',
289294
'OCP\\DB\\Events\\AddMissingColumnsEvent' => $baseDir . '/lib/public/DB/Events/AddMissingColumnsEvent.php',
290295
'OCP\\DB\\Events\\AddMissingIndicesEvent' => $baseDir . '/lib/public/DB/Events/AddMissingIndicesEvent.php',
291296
'OCP\\DB\\Events\\AddMissingPrimaryKeyEvent' => $baseDir . '/lib/public/DB/Events/AddMissingPrimaryKeyEvent.php',
@@ -1216,6 +1221,7 @@
12161221
'OC\\Contacts\\ContactsMenu\\Providers\\EMailProvider' => $baseDir . '/lib/private/Contacts/ContactsMenu/Providers/EMailProvider.php',
12171222
'OC\\Contacts\\ContactsMenu\\Providers\\LocalTimeProvider' => $baseDir . '/lib/private/Contacts/ContactsMenu/Providers/LocalTimeProvider.php',
12181223
'OC\\Contacts\\ContactsMenu\\Providers\\ProfileProvider' => $baseDir . '/lib/private/Contacts/ContactsMenu/Providers/ProfileProvider.php',
1224+
'OC\\ContextChat\\ContentManager' => $baseDir . '/lib/private/ContextChat/ContentManager.php',
12191225
'OC\\Core\\AppInfo\\Application' => $baseDir . '/core/AppInfo/Application.php',
12201226
'OC\\Core\\BackgroundJobs\\BackgroundCleanupUpdaterBackupsJob' => $baseDir . '/core/BackgroundJobs/BackgroundCleanupUpdaterBackupsJob.php',
12211227
'OC\\Core\\BackgroundJobs\\CheckForUserCertificates' => $baseDir . '/core/BackgroundJobs/CheckForUserCertificates.php',

lib/composer/composer/autoload_static.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,11 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
327327
'OCP\\Contacts\\ContactsMenu\\IProvider' => __DIR__ . '/../../..' . '/lib/public/Contacts/ContactsMenu/IProvider.php',
328328
'OCP\\Contacts\\Events\\ContactInteractedWithEvent' => __DIR__ . '/../../..' . '/lib/public/Contacts/Events/ContactInteractedWithEvent.php',
329329
'OCP\\Contacts\\IManager' => __DIR__ . '/../../..' . '/lib/public/Contacts/IManager.php',
330+
'OCP\\ContextChat\\ContentItem' => __DIR__ . '/../../..' . '/lib/public/ContextChat/ContentItem.php',
331+
'OCP\\ContextChat\\Events\\ContentProviderRegisterEvent' => __DIR__ . '/../../..' . '/lib/public/ContextChat/Events/ContentProviderRegisterEvent.php',
332+
'OCP\\ContextChat\\IContentManager' => __DIR__ . '/../../..' . '/lib/public/ContextChat/IContentManager.php',
333+
'OCP\\ContextChat\\IContentProvider' => __DIR__ . '/../../..' . '/lib/public/ContextChat/IContentProvider.php',
334+
'OCP\\ContextChat\\Type\\UpdateAccessOp' => __DIR__ . '/../../..' . '/lib/public/ContextChat/Type/UpdateAccessOp.php',
330335
'OCP\\DB\\Events\\AddMissingColumnsEvent' => __DIR__ . '/../../..' . '/lib/public/DB/Events/AddMissingColumnsEvent.php',
331336
'OCP\\DB\\Events\\AddMissingIndicesEvent' => __DIR__ . '/../../..' . '/lib/public/DB/Events/AddMissingIndicesEvent.php',
332337
'OCP\\DB\\Events\\AddMissingPrimaryKeyEvent' => __DIR__ . '/../../..' . '/lib/public/DB/Events/AddMissingPrimaryKeyEvent.php',
@@ -1257,6 +1262,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
12571262
'OC\\Contacts\\ContactsMenu\\Providers\\EMailProvider' => __DIR__ . '/../../..' . '/lib/private/Contacts/ContactsMenu/Providers/EMailProvider.php',
12581263
'OC\\Contacts\\ContactsMenu\\Providers\\LocalTimeProvider' => __DIR__ . '/../../..' . '/lib/private/Contacts/ContactsMenu/Providers/LocalTimeProvider.php',
12591264
'OC\\Contacts\\ContactsMenu\\Providers\\ProfileProvider' => __DIR__ . '/../../..' . '/lib/private/Contacts/ContactsMenu/Providers/ProfileProvider.php',
1265+
'OC\\ContextChat\\ContentManager' => __DIR__ . '/../../..' . '/lib/private/ContextChat/ContentManager.php',
12601266
'OC\\Core\\AppInfo\\Application' => __DIR__ . '/../../..' . '/core/AppInfo/Application.php',
12611267
'OC\\Core\\BackgroundJobs\\BackgroundCleanupUpdaterBackupsJob' => __DIR__ . '/../../..' . '/core/BackgroundJobs/BackgroundCleanupUpdaterBackupsJob.php',
12621268
'OC\\Core\\BackgroundJobs\\CheckForUserCertificates' => __DIR__ . '/../../..' . '/core/BackgroundJobs/CheckForUserCertificates.php',
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* SPDX-FileCopyrightText: 2024-2025 Nextcloud GmbH and Nextcloud contributors
7+
* SPDX-License-Identifier: AGPL-3.0-or-later
8+
*/
9+
10+
namespace OC\ContextChat;
11+
12+
use OCA\ContextChat\Public\ContentManager as ContextChatContentManager;
13+
use OCP\ContextChat\IContentManager;
14+
15+
class ContentManager implements IContentManager {
16+
public function __construct(
17+
private ?ContextChatContentManager $contentManager,
18+
) {
19+
}
20+
21+
public function isContextChatAvailable(): bool {
22+
return $this->contentManager !== null;
23+
}
24+
25+
public function registerContentProvider(string $appId, string $providerId, string $providerClass): void {
26+
$this->contentManager?->registerContentProvider($appId, $providerId, $providerClass);
27+
}
28+
29+
public function collectAllContentProviders(): void {
30+
$this->contentManager?->collectAllContentProviders();
31+
}
32+
33+
public function submitContent(string $appId, array $items): void {
34+
$this->contentManager?->submitContent($appId, $items);
35+
}
36+
37+
public function updateAccess(string $appId, string $providerId, string $itemId, string $op, array $userIds): void {
38+
$this->contentManager?->updateAccess($appId, $providerId, $itemId, $op, $userIds);
39+
}
40+
41+
public function updateAccessProvider(string $appId, string $providerId, string $op, array $userIds): void {
42+
$this->contentManager?->updateAccessProvider($appId, $providerId, $op, $userIds);
43+
}
44+
45+
public function updateAccessDeclarative(string $appId, string $providerId, string $itemId, array $userIds): void {
46+
$this->contentManager?->updateAccessDeclarative($appId, $providerId, $itemId, $op, $userIds);
47+
}
48+
49+
public function deleteProvider(string $appId, string $providerId): void {
50+
$this->contentManager?->deleteProvider($appId, $providerId);
51+
}
52+
53+
public function deleteContent(string $appId, string $providerId, array $itemIds): void {
54+
$this->contentManager?->deleteContent($appId, $providerId, $itemIds);
55+
}
56+
}

lib/private/Server.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,8 @@ public function __construct($webRoot, \OC\Config $config) {
277277

278278
$this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class);
279279

280+
$this->registerAlias(\OCP\ContextChat\IContentManager::class, \OC\ContextChat\ContentManager::class);
281+
280282
$this->registerAlias(\OCP\DirectEditing\IManager::class, \OC\DirectEditing\Manager::class);
281283
$this->registerAlias(ITemplateManager::class, TemplateManager::class);
282284
$this->registerAlias(\OCP\Template\ITemplateManager::class, \OC\Template\TemplateManager::class);
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* SPDX-FileCopyrightText: 2024-2025 Nextcloud GmbH and Nextcloud contributors
7+
* SPDX-License-Identifier: AGPL-3.0-or-later
8+
*/
9+
10+
namespace OCP\ContextChat;
11+
12+
/**
13+
* @since 32.0.0
14+
*/
15+
class ContentItem {
16+
/**
17+
* @param string $itemId
18+
* @param string $providerId
19+
* @param string $title
20+
* @param string $content
21+
* @param string $documentType
22+
* @param \DateTime $lastModified
23+
* @param string[] $users
24+
* @since 32.0.0
25+
*/
26+
public function __construct(
27+
/**
28+
* @since 32.0.0
29+
*/
30+
public string $itemId,
31+
/**
32+
* @since 32.0.0
33+
*/
34+
public string $providerId,
35+
/**
36+
* @since 32.0.0
37+
*/
38+
public string $title,
39+
/**
40+
* @since 32.0.0
41+
*/
42+
public string $content,
43+
/**
44+
* @since 32.0.0
45+
*/
46+
public string $documentType,
47+
/**
48+
* @since 32.0.0
49+
*/
50+
public \DateTime $lastModified,
51+
/**
52+
* @since 32.0.0
53+
*/
54+
public array $users,
55+
) {
56+
}
57+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* SPDX-FileCopyrightText: 2024-2025 Nextcloud GmbH and Nextcloud contributors
7+
* SPDX-License-Identifier: AGPL-3.0-or-later
8+
*/
9+
10+
namespace OCP\ContextChat\Events;
11+
12+
use OCP\ContextChat\IContentManager;
13+
use OCP\ContextChat\IContentProvider;
14+
use OCP\EventDispatcher\Event;
15+
16+
/**
17+
* @since 32.0.0
18+
*/
19+
class ContentProviderRegisterEvent extends Event {
20+
public function __construct(
21+
private IContentManager $contentManager,
22+
) {
23+
}
24+
25+
/**
26+
* @param string $appId
27+
* @param string $providerId
28+
* @param class-string<IContentProvider> $providerClass
29+
* @return void
30+
* @since 32.0.0
31+
*/
32+
public function registerContentProvider(string $appId, string $providerId, string $providerClass): void {
33+
$this->contentManager->registerContentProvider($appId, $providerId, $providerClass);
34+
}
35+
}
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* SPDX-FileCopyrightText: 2024-2025 Nextcloud GmbH and Nextcloud contributors
7+
* SPDX-License-Identifier: AGPL-3.0-or-later
8+
*/
9+
10+
namespace OCP\ContextChat;
11+
12+
/**
13+
* @since 32.0.0
14+
*/
15+
interface IContentManager {
16+
/**
17+
* Checks if the context chat app is enabled or not
18+
*
19+
* @return bool
20+
* @since 32.0.0
21+
*/
22+
public function isContextChatAvailable(): bool;
23+
24+
/**
25+
* @param string $appId
26+
* @param string $providerId
27+
* @param class-string<IContentProvider> $providerClass
28+
* @return void
29+
* @since 32.0.0
30+
*/
31+
public function registerContentProvider(string $appId, string $providerId, string $providerClass): void;
32+
33+
/**
34+
* Emits an event to collect all content providers
35+
*
36+
* @return void
37+
* @since 32.0.0
38+
*/
39+
public function collectAllContentProviders(): void;
40+
41+
/**
42+
* Providers can use this to submit content for indexing in context chat
43+
*
44+
* @param string $appId
45+
* @param ContentItem[] $items
46+
* @return void
47+
* @since 32.0.0
48+
*/
49+
public function submitContent(string $appId, array $items): void;
50+
51+
/**
52+
* Update access for a content item for specified users.
53+
* This modifies the access list for the content item,
54+
* allowing or denying access to the specified users.
55+
* If no user has access to the content item, it will be removed from the knowledge base.
56+
*
57+
* @param string $appId
58+
* @param string $providerId
59+
* @param string $itemId
60+
* @param Type\UpdateAccessOp::* $op
61+
* @param array $userIds
62+
* @return void
63+
* @since 32.0.0
64+
*/
65+
public function updateAccess(string $appId, string $providerId, string $itemId, string $op, array $userIds): void;
66+
67+
/**
68+
* Update access for content items from the given provider for specified users.
69+
* If no user has access to the content item, it will be removed from the knowledge base.
70+
*
71+
* @param string $appId
72+
* @param string $providerId
73+
* @param Type\UpdateAccessOp::* $op
74+
* @param array $userIds
75+
* @return void
76+
* @since 32.0.0
77+
*/
78+
public function updateAccessProvider(string $appId, string $providerId, string $op, array $userIds): void;
79+
80+
/**
81+
* Update access for a content item for specified users declaratively.
82+
* This overwrites the access list for the content item,
83+
* allowing only the specified users access to it.
84+
*
85+
* @param string $appId
86+
* @param string $providerId
87+
* @param string $itemId
88+
* @param array $userIds
89+
* @return void
90+
* @since 32.0.0
91+
*/
92+
public function updateAccessDeclarative(string $appId, string $providerId, string $itemId, array $userIds): void;
93+
94+
/**
95+
* Delete all content items and access lists for a provider.
96+
* This does not unregister the provider itself.
97+
*
98+
* @param string $appId
99+
* @param string $providerId
100+
* @return void
101+
* @since 32.0.0
102+
*/
103+
public function deleteProvider(string $appId, string $providerId): void;
104+
105+
/**
106+
* Remove a content item from the knowledge base of context chat.
107+
*
108+
* @param string $appId
109+
* @param string $providerId
110+
* @param string[] $itemIds
111+
* @return void
112+
* @since 32.0.0
113+
*/
114+
public function deleteContent(string $appId, string $providerId, array $itemIds): void;
115+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* SPDX-FileCopyrightText: 2024-2025 Nextcloud GmbH and Nextcloud contributors
7+
* SPDX-License-Identifier: AGPL-3.0-or-later
8+
*/
9+
10+
namespace OCP\ContextChat;
11+
12+
/**
13+
* This interface defines methods to implement a content provider
14+
* @since 32.0.0
15+
*/
16+
interface IContentProvider {
17+
/**
18+
* The ID of the provider
19+
*
20+
* @return string
21+
* @since 32.0.0
22+
*/
23+
public function getId(): string;
24+
25+
/**
26+
* The ID of the app making the provider avaialble
27+
*
28+
* @return string
29+
* @since 32.0.0
30+
*/
31+
public function getAppId(): string;
32+
33+
/**
34+
* The absolute URL to the content item
35+
*
36+
* @param string $id
37+
* @return string
38+
* @since 32.0.0
39+
*/
40+
public function getItemUrl(string $id): string;
41+
42+
/**
43+
* Starts the initial import of content items into context chat
44+
*
45+
* @return void
46+
* @since 32.0.0
47+
*/
48+
public function triggerInitialImport(): void;
49+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* SPDX-FileCopyrightText: 2024-2025 Nextcloud GmbH and Nextcloud contributors
7+
* SPDX-License-Identifier: AGPL-3.0-or-later
8+
*/
9+
10+
namespace OCP\ContextChat\Type;
11+
12+
/**
13+
* @since 32.0.0
14+
*/
15+
class UpdateAccessOp {
16+
public const ALLOW = 'allow';
17+
public const DENY = 'deny';
18+
}

psalm.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@
106106
<referencedClass name="OCA\Circles\Exceptions\CircleNotFoundException"/>
107107
<referencedClass name="OCA\Circles\Model\Circle"/>
108108
<referencedClass name="OCA\Circles\Model\Member"/>
109+
<referencedClass name="OCA\ContextChat\Public\ContentManager"/>
109110
<referencedClass name="OCA\GroupFolders\Mount\GroupFolderStorage"/>
110111
<referencedClass name="OCA\TwoFactorNextcloudNotification\Controller\APIController"/>
111112
<referencedClass name="OCA\GlobalSiteSelector\Service\SlaveService"/>

0 commit comments

Comments
 (0)