Skip to content

Commit 8feaa1a

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 54e4622 commit 8feaa1a

File tree

2 files changed

+93
-33
lines changed

2 files changed

+93
-33
lines changed

lib/Capabilities.php

Lines changed: 44 additions & 33 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,
48-
* filter: string,
46+
* method: string,
47+
* mimetype_filters: 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+
'mimetype_filters' => 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-
]),
115-
'filter' => 'audio/',
121+
'url' => $url,
122+
'method' => 'POST',
123+
'mimetype_filters' => '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+
'mimetype_filters' => 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

openapi.json

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,55 @@
212212
"type": "boolean"
213213
}
214214
}
215+
},
216+
"declarativeui": {
217+
"type": "object",
218+
"additionalProperties": {
219+
"type": "object",
220+
"required": [
221+
"context-menu"
222+
],
223+
"properties": {
224+
"context-menu": {
225+
"type": "array",
226+
"items": {
227+
"type": "object",
228+
"required": [
229+
"name",
230+
"url",
231+
"method",
232+
"mimetype_filters",
233+
"android_icon",
234+
"desktop_icon",
235+
"ios_icon"
236+
],
237+
"properties": {
238+
"name": {
239+
"type": "string"
240+
},
241+
"url": {
242+
"type": "string"
243+
},
244+
"method": {
245+
"type": "string"
246+
},
247+
"mimetype_filters": {
248+
"type": "string"
249+
},
250+
"android_icon": {
251+
"type": "string"
252+
},
253+
"desktop_icon": {
254+
"type": "string"
255+
},
256+
"ios_icon": {
257+
"type": "string"
258+
}
259+
}
260+
}
261+
}
262+
}
263+
}
215264
}
216265
}
217266
},

0 commit comments

Comments
 (0)