31
31
32
32
#[OpenAPI(scope: OpenAPI::SCOPE_IGNORE )]
33
33
class ChattyLLMController extends Controller {
34
+ private array $ agencyActionNames ;
34
35
35
36
public function __construct (
36
37
string $ appName ,
@@ -45,6 +46,22 @@ public function __construct(
45
46
private ?string $ userId ,
46
47
) {
47
48
parent ::__construct ($ appName , $ request );
49
+ $ this ->agencyActionNames = [
50
+ 'send_message_to_conversation ' => $ this ->l10n ->t ('Send a message to a Talk conversation ' ),
51
+ 'list_talk_conversations ' => $ this ->l10n ->t ('List Talk conversations ' ),
52
+ 'list_messages_in_conversation ' => $ this ->l10n ->t ('List messages in a Talk conversation ' ),
53
+ 'schedule_event ' => $ this ->l10n ->t ('Schedule a calendar event ' ),
54
+ 'list_calendars ' => $ this ->l10n ->t ('List calendars ' ),
55
+ ];
56
+ }
57
+
58
+ private function improveAgencyActionNames (array $ actions ): array {
59
+ return array_map (function ($ action ) {
60
+ if (isset ($ action ->name ) && isset ($ this ->agencyActionNames [$ action ->name ])) {
61
+ $ action ->name = $ this ->agencyActionNames [$ action ->name ];
62
+ }
63
+ return $ action ;
64
+ }, $ actions );
48
65
}
49
66
50
67
/**
@@ -408,6 +425,7 @@ public function checkMessageGenerationTask(int $taskId, int $sessionId): JSONRes
408
425
$ jsonMessage ['sessionAgencyPendingActions ' ] = $ session ->getAgencyPendingActions ();
409
426
if ($ jsonMessage ['sessionAgencyPendingActions ' ] !== null ) {
410
427
$ jsonMessage ['sessionAgencyPendingActions ' ] = json_decode ($ jsonMessage ['sessionAgencyPendingActions ' ]);
428
+ $ jsonMessage ['sessionAgencyPendingActions ' ] = $ this ->improveAgencyActionNames ($ jsonMessage ['sessionAgencyPendingActions ' ]);
411
429
}
412
430
// do not insert here, it is done by the listener
413
431
return new JSONResponse ($ jsonMessage );
@@ -462,6 +480,7 @@ public function checkSession(int $sessionId): JSONResponse {
462
480
$ pendingActions = $ session ->getAgencyPendingActions ();
463
481
if ($ pendingActions !== null ) {
464
482
$ pendingActions = json_decode ($ pendingActions );
483
+ $ pendingActions = $ this ->improveAgencyActionNames ($ pendingActions );
465
484
}
466
485
$ responseData = [
467
486
'messageTaskId ' => null ,
0 commit comments