1414use OCP \Capabilities \IPublicCapability ;
1515use OCP \IAppConfig ;
1616use 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 ;
1722
1823class Capabilities implements IPublicCapability {
1924
2025 public function __construct (
2126 private IAppManager $ appManager ,
2227 private IConfig $ config ,
2328 private IAppConfig $ appConfig ,
29+ private IManager $ taskProcessingManager ,
30+ private IL10N $ l ,
31+ private IUrlGenerator $ urlGenerator ,
2432 private ?string $ userId ,
2533 ) {
2634 }
@@ -30,22 +38,105 @@ public function __construct(
3038 * assistant: array{
3139 * version: string,
3240 * 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+ * },
3455 * }
3556 */
3657 public function getCapabilities (): array {
58+ // App version
3759 $ appVersion = $ this ->appManager ->getAppVersion (Application::APP_ID );
38- $ capability = [
60+ $ capabilities = [
3961 Application::APP_ID => [
4062 'version ' => $ appVersion ,
4163 ],
4264 ];
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 ;
4867 }
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 ;
50141 }
51142}
0 commit comments