14
14
use OCP \Capabilities \IPublicCapability ;
15
15
use OCP \IAppConfig ;
16
16
use OCP \IConfig ;
17
+ use OCP \IL10N ;
18
+ use OCP \IURLGenerator ;
19
+ use OCP \TaskProcessing \IManager ;
20
+ use OCP \TaskProcessing \TaskTypes \AudioToText ;
21
+ use OCP \TaskProcessing \TaskTypes \TextToTextSummary ;
17
22
18
23
class Capabilities implements IPublicCapability {
19
24
20
25
public function __construct (
21
26
private IAppManager $ appManager ,
22
27
private IConfig $ config ,
23
28
private IAppConfig $ appConfig ,
29
+ private IManager $ taskProcessingManager ,
30
+ private IL10N $ l ,
31
+ private IUrlGenerator $ urlGenerator ,
24
32
private ?string $ userId ,
25
33
) {
26
34
}
@@ -30,22 +38,105 @@ public function __construct(
30
38
* assistant: array{
31
39
* version: string,
32
40
* enabled?: bool
33
- * }
41
+ * },
42
+ * declarativeui?: array{
43
+ * hooks: list<array{
44
+ * type: 'context-menu',
45
+ * endpoints: list<array{
46
+ * name: string,
47
+ * url: string,
48
+ * filter: string,
49
+ * android_icon: string,
50
+ * desktop_icon: string,
51
+ * ios_icon: string,
52
+ * }>
53
+ * }>
54
+ * },
34
55
* }
35
56
*/
36
57
public function getCapabilities (): array {
58
+ // App version
37
59
$ appVersion = $ this ->appManager ->getAppVersion (Application::APP_ID );
38
- $ capability = [
60
+ $ capabilities = [
39
61
Application::APP_ID => [
40
62
'version ' => $ appVersion ,
41
63
],
42
64
];
43
- if ($ this ->userId !== null ) {
44
- $ adminAssistantEnabled = $ this ->appConfig ->getValueString (Application::APP_ID , 'assistant_enabled ' , '1 ' ) === '1 ' ;
45
- $ userAssistantEnabled = $ this ->config ->getUserValue ($ this ->userId , Application::APP_ID , 'assistant_enabled ' , '1 ' ) === '1 ' ;
46
- $ assistantEnabled = $ adminAssistantEnabled && $ userAssistantEnabled ;
47
- $ capability [Application::APP_ID ]['enabled ' ] = $ assistantEnabled ;
65
+ if ($ this ->userId === null ) {
66
+ return $ capabilities ;
48
67
}
49
- return $ capability ;
68
+
69
+ $ adminAssistantEnabled = $ this ->appConfig ->getValueString (Application::APP_ID , 'assistant_enabled ' , '1 ' ) === '1 ' ;
70
+ $ userAssistantEnabled = $ this ->config ->getUserValue ($ this ->userId , Application::APP_ID , 'assistant_enabled ' , '1 ' ) === '1 ' ;
71
+ $ assistantEnabled = $ adminAssistantEnabled && $ userAssistantEnabled ;
72
+ $ capabilities [Application::APP_ID ]['enabled ' ] = $ assistantEnabled ;
73
+
74
+ // declarative UI
75
+ $ availableTaskTypes = $ this ->taskProcessingManager ->getAvailableTaskTypes ();
76
+ $ summarizeAvailable = array_key_exists (TextToTextSummary::ID , $ availableTaskTypes );
77
+ $ sttAvailable = array_key_exists (AudioToText::ID , $ availableTaskTypes );
78
+ $ ttsAvailable = class_exists ('OCP \\TaskProcessing \\TaskTypes \\TextToSpeech ' )
79
+ && array_key_exists (\OCP \TaskProcessing \TaskTypes \TextToSpeech::ID , $ availableTaskTypes );
80
+
81
+ if ($ summarizeAvailable || $ sttAvailable || $ ttsAvailable ) {
82
+ $ capabilities ['declarativeui ' ] = [
83
+ 'hooks ' => [
84
+ [
85
+ 'type ' => 'context-menu ' ,
86
+ 'endpoints ' => [],
87
+ ],
88
+ ],
89
+ ];
90
+
91
+ if ($ summarizeAvailable ) {
92
+ $ endpoint = [
93
+ '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/ ' ,
100
+ 'android_icon ' => 'creation ' ,
101
+ 'ios_icon ' => 'creation ' ,
102
+ 'desktop_icon ' => 'creation ' ,
103
+ ];
104
+ $ capabilities ['declarativeui ' ]['hooks ' ][0 ]['endpoints ' ][] = $ endpoint ;
105
+ }
106
+
107
+ if ($ sttAvailable ) {
108
+ $ endpoint = [
109
+ '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/ ' ,
116
+ 'android_icon ' => 'speech_to_text ' ,
117
+ 'ios_icon ' => 'speech_to_text ' ,
118
+ 'desktop_icon ' => 'speech_to_text ' ,
119
+ ];
120
+ $ capabilities ['declarativeui ' ]['hooks ' ][0 ]['endpoints ' ][] = $ endpoint ;
121
+ }
122
+
123
+ if ($ ttsAvailable ) {
124
+ $ endpoint = [
125
+ '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/ ' ,
132
+ 'android_icon ' => 'text_to_speech ' ,
133
+ 'ios_icon ' => 'text_to_speech ' ,
134
+ 'desktop_icon ' => 'text_to_speech ' ,
135
+ ];
136
+ $ capabilities ['declarativeui ' ]['hooks ' ][0 ]['endpoints ' ][] = $ endpoint ;
137
+ }
138
+ }
139
+
140
+ return $ capabilities ;
50
141
}
51
142
}
0 commit comments