@@ -19,6 +19,7 @@ import { baseRealm, Command } from '@cardstack/runtime-common';
19
19
import {
20
20
APP_BOXEL_COMMAND_MSGTYPE ,
21
21
APP_BOXEL_MESSAGE_MSGTYPE ,
22
+ APP_BOXEL_COMMAND_RESULT_EVENT_TYPE ,
22
23
} from ' @cardstack/runtime-common/matrix-constants' ;
23
24
24
25
import CreateAIAssistantRoomCommand from ' @cardstack/host/commands/create-ai-assistant-room' ;
@@ -362,6 +363,20 @@ module('Acceptance | Commands tests', function (hooks) {
362
363
' person.gts' : { Person , Meeting },
363
364
' pet.gts' : { Pet },
364
365
' Pet/ringo.json' : new Pet ({ name: ' Ringo' }),
366
+ ' AiCommandExample/london.json' : {
367
+ data: {
368
+ type: ' card' ,
369
+ attributes: {
370
+ location: ' London' ,
371
+ },
372
+ meta: {
373
+ adoptsFrom: {
374
+ module: ' http://localhost:4202/test/ai-command-example' ,
375
+ name: ' AiCommandExample' ,
376
+ },
377
+ },
378
+ },
379
+ },
365
380
' Person/hassan.json' : new Person ({
366
381
firstName: ' Hassan' ,
367
382
lastName: ' Abdel-Rahman' ,
@@ -867,4 +882,64 @@ module('Acceptance | Commands tests', function (hooks) {
867
882
.dom (' [data-test-message-idx="1"] [data-test-boxel-command-result]' )
868
883
.containsText (' Submode: interact' );
869
884
});
885
+
886
+ test (' command returns serialized result in room message' , async function (assert ) {
887
+ await visitOperatorMode ({
888
+ stacks: [
889
+ [
890
+ {
891
+ id: ` ${testRealmURL }AiCommandExample/london ` ,
892
+ format: ' isolated' ,
893
+ },
894
+ ],
895
+ ],
896
+ });
897
+
898
+ await click (' [data-test-get-weather]' );
899
+ await waitUntil (() => getRoomIds ().length > 0 );
900
+
901
+ let roomId = getRoomIds ().pop ()! ;
902
+ let message = getRoomEvents (roomId ).pop ()! ;
903
+ assert .strictEqual (message .content .msgtype , APP_BOXEL_MESSAGE_MSGTYPE );
904
+
905
+ let boxelMessageData = JSON .parse (message .content .data );
906
+ assert .strictEqual (boxelMessageData .context .tools .length , 1 );
907
+ assert .strictEqual (boxelMessageData .context .tools [0 ].type , ' function' );
908
+ let toolName = boxelMessageData .context .tools [0 ].function .name ;
909
+
910
+ simulateRemoteMessage (roomId , ' @aibot:localhost' , {
911
+ body: ' Getting weather information for London' ,
912
+ msgtype: APP_BOXEL_COMMAND_MSGTYPE ,
913
+ formatted_body: ' Getting weather information for London' ,
914
+ format: ' org.matrix.custom.html' ,
915
+ data: JSON .stringify ({
916
+ toolCall: {
917
+ name: toolName ,
918
+ arguments: {
919
+ attributes: {
920
+ location: ' London' ,
921
+ },
922
+ },
923
+ },
924
+ eventId: ' __EVENT_ID__' ,
925
+ }),
926
+ ' m.relates_to' : {
927
+ rel_type: ' m.replace' ,
928
+ event_id: ' __EVENT_ID__' ,
929
+ },
930
+ });
931
+
932
+ await settled ();
933
+ let commandResultEvents = await getRoomEvents (roomId ).filter (
934
+ (event ) =>
935
+ event .type === APP_BOXEL_COMMAND_RESULT_EVENT_TYPE &&
936
+ event .content [' m.relates_to' ]?.rel_type === ' m.annotation' &&
937
+ event .content [' m.relates_to' ]?.key === ' applied' ,
938
+ );
939
+ assert .equal (
940
+ commandResultEvents .length ,
941
+ 1 ,
942
+ ' command result event is dispatched' ,
943
+ );
944
+ });
870
945
});
0 commit comments