1- import BaseAIComponent from '../../vendor/ibexa/connector-ai/src/bundle/Resources/public/js/core/base.ai.component' ;
1+ import BaseAIAssistantComponent from '@ibexa-connector-ai/src/bundle/Resources/public/js/core/base.ai.assistant.component' ;
2+ import Textarea from '@ibexa-connector-ai-modules/ai-assistant/fields/textarea/textarea.js' ;
23
3- export default class TranscribeAudio extends BaseAIComponent {
4- constructor ( mainElement , config ) {
5- super ( mainElement , config ) ;
4+ export default class TranscribeAudio extends BaseAIAssistantComponent {
5+
6+ constructor ( mainElement , extraConfig ) {
7+ super ( mainElement , extraConfig ) ;
68
79 this . requestHeaders = {
810 Accept : 'application/vnd.ibexa.api.ai.AudioText+json' ,
911 'Content-Type' : 'application/vnd.ibexa.api.ai.TranscribeAudio+json' ,
1012 } ;
13+
14+ this . getRequestBody = this . getRequestBody . bind ( this ) ;
15+ this . getResponseValue = this . getResponseValue . bind ( this ) ;
16+
17+ this . replacedField = Textarea ;
1118 }
1219
1320 getAudioInBase64 ( ) {
@@ -18,16 +25,15 @@ export default class TranscribeAudio extends BaseAIComponent {
1825
1926 if ( request . status === 200 ) {
2027 return this . convertToBase64 ( request . responseText ) ;
21- } else {
22- this . processError ( 'Error occured when decoding the file.' ) ;
2328 }
2429 }
2530
2631 getRequestBody ( ) {
32+ const inputValue = this . getInputValue ( ) ;
2733 const body = {
2834 TranscribeAudio : {
2935 Audio : {
30- base64 : this . getAudioInBase64 ( ) ,
36+ base64 : inputValue ,
3137 } ,
3238 RuntimeContext : { } ,
3339 } ,
@@ -40,20 +46,6 @@ export default class TranscribeAudio extends BaseAIComponent {
4046 return JSON . stringify ( body ) ;
4147 }
4248
43- afterFetchData ( response ) {
44- super . afterFetchData ( ) ;
45-
46- if ( response ) {
47- this . outputElement . value = response . AudioText . Text . text [ 0 ] ;
48- }
49- }
50-
51- toggle ( forceEnabled ) {
52- super . toggle ( forceEnabled ) ;
53-
54- this . outputElement . disabled = ! forceEnabled || ! this . outputElement . disabled ;
55- }
56-
5749 convertToBase64 ( data ) {
5850 let binary = '' ;
5951
@@ -63,4 +55,15 @@ export default class TranscribeAudio extends BaseAIComponent {
6355
6456 return btoa ( binary ) ;
6557 }
58+
59+ getResponseValue ( response ) {
60+ return response . AudioText . Text . text [ 0 ] ;
61+ }
62+
63+ handleAIDialogConfirm ( responseText ) {
64+ this . outputElement . value = responseText ;
65+ this . outputElement . dispatchEvent ( new Event ( 'input' ) ) ;
66+
67+ super . handleAIDialogClose ( responseText ) ;
68+ }
6669}
0 commit comments