Skip to content

Commit a5b2673

Browse files
committed
feat(declarativeui): simplify declarative UI capabilities structure, add multi filters, add method
Signed-off-by: Julien Veyssier <julien-nc@posteo.net>
1 parent b5cb9eb commit a5b2673

File tree

1 file changed

+42
-31
lines changed

1 file changed

+42
-31
lines changed

lib/Capabilities.php

Lines changed: 42 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,17 @@ public function __construct(
3939
* version: string,
4040
* enabled?: bool
4141
* },
42-
* declarativeui?: array{
43-
* hooks: list<array{
44-
* type: 'context-menu',
45-
* endpoints: list<array{
42+
* declarativeui?: array<string, array{
43+
* context-menu: list<array{
4644
* name: string,
4745
* url: string,
46+
* method: string,
4847
* filter: string,
4948
* android_icon: string,
5049
* desktop_icon: string,
5150
* ios_icon: string,
52-
* }>
5351
* }>
54-
* },
52+
* }>,
5553
* }
5654
*/
5755
public function getCapabilities(): array {
@@ -80,60 +78,73 @@ public function getCapabilities(): array {
8078

8179
if ($summarizeAvailable || $sttAvailable || $ttsAvailable) {
8280
$capabilities['declarativeui'] = [
83-
'hooks' => [
84-
[
85-
'type' => 'context-menu',
86-
'endpoints' => [],
87-
],
81+
Application::APP_ID => [
82+
'context-menu' => [],
8883
],
8984
];
9085

86+
$textMimeTypes = [
87+
'text/',
88+
'application/msword',
89+
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
90+
'application/vnd.oasis.opendocument.text',
91+
'application/pdf',
92+
];
9193
if ($summarizeAvailable) {
94+
$url = $this->urlGenerator->linkToOCSRouteAbsolute(Application::APP_ID . '.assistantApi.runFileAction', [
95+
'apiVersion' => 'v1',
96+
'fileId' => '123456789',
97+
'taskTypeId' => TextToTextSummary::ID,
98+
]);
99+
$url = str_replace('123456789', '{fileId}', $url);
92100
$endpoint = [
93101
'name' => $this->l->t('Summarize'),
94-
'url' => $this->urlGenerator->linkToOCSRouteAbsolute(Application::APP_ID . '.assistantApi.runFileAction', [
95-
'apiVersion' => 'v1',
96-
'fileId' => '{s}',
97-
'taskTypeId' => TextToTextSummary::ID,
98-
]),
99-
'filter' => 'text/',
102+
'url' => $url,
103+
'method' => 'POST',
104+
'filter' => implode(', ', $textMimeTypes),
100105
'android_icon' => 'creation',
101106
'ios_icon' => 'creation',
102107
'desktop_icon' => 'creation',
103108
];
104-
$capabilities['declarativeui']['hooks'][0]['endpoints'][] = $endpoint;
109+
$capabilities['declarativeui'][Application::APP_ID]['context-menu'][] = $endpoint;
105110
}
106111

107112
if ($sttAvailable) {
113+
$url = $this->urlGenerator->linkToOCSRouteAbsolute(Application::APP_ID . '.assistantApi.runFileAction', [
114+
'apiVersion' => 'v1',
115+
'fileId' => '123456789',
116+
'taskTypeId' => \OCP\TaskProcessing\TaskTypes\TextToSpeech::ID,
117+
]);
118+
$url = str_replace('123456789', '{fileId}', $url);
108119
$endpoint = [
109120
'name' => $this->l->t('Transcribe audio'),
110-
'url' => $this->urlGenerator->linkToOCSRouteAbsolute(Application::APP_ID . '.assistantApi.runFileAction', [
111-
'apiVersion' => 'v1',
112-
'fileId' => '{s}',
113-
'taskTypeId' => \OCP\TaskProcessing\TaskTypes\TextToSpeech::ID,
114-
]),
121+
'url' => $url,
122+
'method' => 'POST',
115123
'filter' => 'audio/',
116124
'android_icon' => 'speech_to_text',
117125
'ios_icon' => 'speech_to_text',
118126
'desktop_icon' => 'speech_to_text',
119127
];
120-
$capabilities['declarativeui']['hooks'][0]['endpoints'][] = $endpoint;
128+
$capabilities['declarativeui'][Application::APP_ID]['context-menu'][] = $endpoint;
121129
}
122130

123131
if ($ttsAvailable) {
132+
$url = $this->urlGenerator->linkToOCSRouteAbsolute(Application::APP_ID . '.assistantApi.runFileAction', [
133+
'apiVersion' => 'v1',
134+
'fileId' => '123456789',
135+
'taskTypeId' => AudioToText::ID,
136+
]);
137+
$url = str_replace('123456789', '{fileId}', $url);
124138
$endpoint = [
125139
'name' => $this->l->t('Text to speech'),
126-
'url' => $this->urlGenerator->linkToOCSRouteAbsolute(Application::APP_ID . '.assistantApi.runFileAction', [
127-
'apiVersion' => 'v1',
128-
'fileId' => '{s}',
129-
'taskTypeId' => AudioToText::ID,
130-
]),
131-
'filter' => 'text/',
140+
'url' => $url,
141+
'method' => 'POST',
142+
'filter' => implode(', ', $textMimeTypes),
132143
'android_icon' => 'text_to_speech',
133144
'ios_icon' => 'text_to_speech',
134145
'desktop_icon' => 'text_to_speech',
135146
];
136-
$capabilities['declarativeui']['hooks'][0]['endpoints'][] = $endpoint;
147+
$capabilities['declarativeui'][Application::APP_ID]['context-menu'][] = $endpoint;
137148
}
138149
}
139150

0 commit comments

Comments
 (0)