@@ -8,6 +8,7 @@ import { KnowledgeBaseService } from 'src/app/services/knowledge-base.service';
8
8
import { LoggerService } from 'src/chat21-core/providers/abstract/logger.service' ;
9
9
import { LoggerInstance } from 'src/chat21-core/providers/logger/loggerInstance' ;
10
10
import { AppConfigService } from 'src/app/services/app-config' ;
11
+ import { Subscription } from 'rxjs/internal/Subscription' ;
11
12
12
13
@Component ( {
13
14
selector : 'cds-action-askgpt' ,
@@ -32,7 +33,8 @@ export class CdsActionAskgptComponent implements OnInit {
32
33
isConnectedTrue : boolean = false ;
33
34
isConnectedFalse : boolean = false ;
34
35
connector : any ;
35
-
36
+ private subscriptionChangedConnector : Subscription ;
37
+
36
38
kbs_list = [ ] ;
37
39
kb_selected_id : string = null ;
38
40
status_code : number ;
@@ -60,11 +62,8 @@ export class CdsActionAskgptComponent implements OnInit {
60
62
61
63
ngOnInit ( ) : void {
62
64
this . logger . debug ( "[ACTION-ASKGPT] action detail: " , this . action ) ;
63
- console . log ( "[ACTION-ASKGPT] action detail: " , this . action ) ;
64
- console . log ( "[ACTION-ASKGPT] action kbid: " , this . action . kbid ) ;
65
- console . log ( "[ACTION-ASKGPT] action kbname: " , this . action . kbName ) ;
66
65
67
- this . intentService . isChangedConnector$ . subscribe ( ( connector : any ) => {
66
+ this . subscriptionChangedConnector = this . intentService . isChangedConnector$ . subscribe ( ( connector : any ) => {
68
67
this . logger . debug ( '[ACTION-ASKGPT] isChangedConnector -->' , connector ) ;
69
68
this . connector = connector ;
70
69
this . updateConnector ( ) ;
@@ -92,6 +91,13 @@ export class CdsActionAskgptComponent implements OnInit {
92
91
}
93
92
94
93
94
+ /** */
95
+ ngOnDestroy ( ) {
96
+ if ( this . subscriptionChangedConnector ) {
97
+ this . subscriptionChangedConnector . unsubscribe ( ) ;
98
+ }
99
+ }
100
+
95
101
initializeConnector ( ) {
96
102
this . idIntentSelected = this . intentSelected . intent_id ;
97
103
this . idConnectorTrue = this . idIntentSelected + '/' + this . action . _tdActionId + '/true' ;
@@ -114,7 +120,9 @@ export class CdsActionAskgptComponent implements OnInit {
114
120
this . action . falseIntent = null
115
121
this . isConnectedFalse = false ;
116
122
}
117
- this . updateAndSaveAction . emit ( ) ;
123
+ // if(this.connector.notify)
124
+ if ( this . connector . save ) this . updateAndSaveAction . emit ( this . connector ) ;
125
+ // this.updateAndSaveAction.emit();
118
126
} else {
119
127
// TODO: verificare quale dei due connettori è stato aggiunto (controllare il valore della action corrispondente al true/false intent)
120
128
// ADD / EDIT
@@ -124,15 +132,19 @@ export class CdsActionAskgptComponent implements OnInit {
124
132
this . isConnectedTrue = true ;
125
133
if ( this . action . trueIntent !== '#' + this . connector . toId ) {
126
134
this . action . trueIntent = '#' + this . connector . toId ;
127
- this . updateAndSaveAction . emit ( ) ;
135
+ // if(this.connector.notify)
136
+ if ( this . connector . save ) this . updateAndSaveAction . emit ( this . connector ) ;
137
+ // this.updateAndSaveAction.emit();
128
138
}
129
139
}
130
140
if ( array [ array . length - 1 ] === 'false' ) {
131
141
// this.action.falseIntent = '#'+this.connector.toId;
132
142
this . isConnectedFalse = true ;
133
143
if ( this . action . falseIntent !== '#' + this . connector . toId ) {
134
144
this . action . falseIntent = '#' + this . connector . toId ;
135
- this . updateAndSaveAction . emit ( ) ;
145
+ // if(this.connector.notify)
146
+ if ( this . connector . save ) this . updateAndSaveAction . emit ( this . connector ) ;
147
+ // this.updateAndSaveAction.emit();
136
148
}
137
149
}
138
150
}
@@ -213,17 +225,17 @@ export class CdsActionAskgptComponent implements OnInit {
213
225
onChangeBlockSelect ( event :{ name : string , value : string } , type : 'trueIntent' | 'falseIntent' ) {
214
226
if ( event ) {
215
227
this . action [ type ] = event . value
216
- }
217
228
218
- switch ( type ) {
219
- case 'trueIntent' :
220
- this . onConnectorChange . emit ( { type : 'create' , fromId : this . idConnectorTrue , toId : this . action . trueIntent } )
221
- break ;
222
- case 'falseIntent' :
223
- this . onConnectorChange . emit ( { type : 'create' , fromId : this . idConnectorFalse , toId : this . action . falseIntent } )
224
- break ;
229
+ switch ( type ) {
230
+ case 'trueIntent' :
231
+ this . onConnectorChange . emit ( { type : 'create' , fromId : this . idConnectorTrue , toId : this . action . trueIntent } )
232
+ break ;
233
+ case 'falseIntent' :
234
+ this . onConnectorChange . emit ( { type : 'create' , fromId : this . idConnectorFalse , toId : this . action . falseIntent } )
235
+ break ;
236
+ }
237
+ this . updateAndSaveAction . emit ( ) ;
225
238
}
226
- this . updateAndSaveAction . emit ( ) ;
227
239
}
228
240
229
241
onResetBlockSelect ( event :{ name : string , value : string } , type : 'trueIntent' | 'falseIntent' ) {
@@ -260,7 +272,7 @@ export class CdsActionAskgptComponent implements OnInit {
260
272
// }
261
273
262
274
goToKNB ( ) {
263
- let url = this . appConfigService . getConfig ( ) . dashboardBaseUrl + 'dashboard/#/project/' + this . project_id + '/knowledge-bases'
275
+ let url = this . appConfigService . getConfig ( ) . DASHBOARD_BASE_URL + 'dashboard/#/project/' + this . project_id + '/knowledge-bases'
264
276
window . open ( url , '_blank' )
265
277
}
266
278
@@ -271,139 +283,4 @@ export class CdsActionAskgptComponent implements OnInit {
271
283
}
272
284
}
273
285
274
-
275
- // -----------------
276
- // TO CHECK / DELETE
277
- // -----------------
278
-
279
-
280
- // getAllOpenaiKbs() {
281
- // this.openaikbService.getAllOpenaikbs().subscribe((kbs: any[]) => {
282
- // this.kbs_list = kbs.map(t => {
283
- // t.icon = "language"
284
- // return t;
285
- // })
286
- // if (this.action.kbid) {
287
- // this.kb_selected_id = this.kbs_list.find(k => k.url === this.action.kbid)._id;
288
- // this.kb_selected_name = this.kbs_list.find(k => k.url === this.action.kbid).name;
289
- // //this.checkKbStatus(this.action.kbid);
290
- // }
291
- // //this.checkLimit();
292
- // }, (error) => {
293
- // this.logger.error("[ACTION ASKGPT] ERROR get openai kbs: ", error);
294
- // }, () => {
295
- // this.logger.info("[ACTION ASKGPT] get openai kbs *COMPLETED*");
296
- // })
297
- // }
298
-
299
- // openAddKbDialog() {
300
- // const dialogRef = this.dialog.open(AddkbDialogComponent, {
301
- // panelClass: 'custom-dialog-container',
302
- // data: { name: '', url: '' }
303
- // });
304
- // dialogRef.afterClosed().subscribe(result => {
305
- // this.logger.info("[ACTION ASKGPT] Dialog result - new openai kb: ", result);
306
- // if (result && result.name && result.url) {
307
- // this.saveOpenaiKb(result);
308
- // }
309
- // });
310
- // }
311
-
312
- // saveOpenaiKb(new_kb) {
313
- // this.openaikbService.addOpenaiKb(new_kb).subscribe((savedKb) => {
314
- // this.getAllOpenaiKbs();
315
- // }, (error) => {
316
- // this.logger.error("[ACTION ASKGPT] ERROR add new kb: ", error);
317
- // }, () => {
318
- // this.logger.info("[ACTION ASKGPT] add new kb *COMPLETED*");
319
- // })
320
- // }
321
-
322
- // onDeleteSelect(id) {
323
- // this.openDeleteDialog(id);
324
- // }
325
-
326
- // openDeleteDialog(id) {
327
- // const dialogRef = this.dialog.open(DialogYesNoComponent, {
328
- // panelClass: 'custom-dialog-container',
329
- // data: { title: 'Delete Knowledge base', text: 'Are you sure you want to delete permanently this Knwoledge base?', yes: 'Delete', no: 'Cancel' }
330
- // })
331
- // dialogRef.afterClosed().subscribe(result => {
332
- // if (result && result !== undefined && result !== false) {
333
- // this.deleteKb(id);
334
- // }
335
- // })
336
- // }
337
-
338
- // deleteKb(id: string) {
339
- // if (this.kb_selected_id === id) {
340
- // this.action.kbid = null;
341
- // this.kb_selected_id = null;
342
- // this.status_code = null;
343
- // }
344
- // this.openaikbService.deleteOpenaiKb(id).subscribe((deletedKb) => {
345
- // this.logger.info("deletedKb response ", deletedKb);
346
- // this.logger.log("deletedKb response ", deletedKb);
347
- // this.getAllOpenaiKbs();
348
- // }, (error) => {
349
- // this.logger.error("[ACTION ASKGPT] ERROR delete kb: ", error);
350
- // }, () => {
351
- // this.logger.info("[ACTION ASKGPT] delete kb *COMPLETE*");
352
- // })
353
- // }
354
-
355
- // checkKbStatus(kbid) {
356
- // let data = {
357
- // full_url: kbid
358
- // }
359
- // this.gptService.checkScrapingStatus(data).subscribe((status: any) => {
360
- // this.spinner = false;
361
- // this.logger.log("[ACTION ASKGPT] Scraping status: ", status);
362
- // this.status_code = status.status_code;;
363
- // }, (error) => {
364
- // this.logger.error("[ACTION ASKGPT] error getting scraping status: ", error);
365
- // }, () => {
366
- // this.logger.log("[ACTION ASKGPT] get scraping status *COMPLETE*")
367
- // })
368
- // }
369
-
370
- // startKbIndexing() {
371
-
372
- // this.spinner = true;
373
- // if (!this.action.gptkey) {
374
- // this.indexing_hint = "Missing GPT Key"
375
- // this.spinner = false;
376
- // } else {
377
- // let data = {
378
- // full_url: this.action.kbid,
379
- // gptkey: this.action.gptkey
380
- // }
381
-
382
- // this.gptService.startScraping(data).subscribe((response: any) => {
383
- // if (response.message === 'Invalid Openai API key') {
384
- // this.indexing_hint = response.message;
385
- // }
386
- // this.checkKbStatus(this.action.kbid);
387
- // }, (error) => {
388
- // this.logger.error("[ACTION ASKGPT] error start indexing: ", error);
389
- // this.indexing_hint = error.message;
390
- // this.spinner = false;
391
- // }, () => {
392
- // this.logger.log("[ACTION ASKGPT] start indexing *COMPLETE*");
393
- // })
394
- // }
395
- // }
396
-
397
- // checkLimit() {
398
- // if (this.kbs_list.length >= 3) {
399
- // this.buttonDisabled = true;
400
- // this.buttonIcon = null;
401
- // this.buttonText = "Maximum number of Knwoledge Bases reached"
402
- // } else {
403
- // this.buttonDisabled = false;
404
- // this.buttonIcon = "add";
405
- // this.buttonText = "Add Knowledge Bases"
406
- // }
407
- // }
408
-
409
286
}
0 commit comments