@@ -41,7 +41,8 @@ import {
41
41
APP_BOXEL_CARDFRAGMENT_MSGTYPE ,
42
42
APP_BOXEL_COMMAND_MSGTYPE ,
43
43
APP_BOXEL_COMMAND_RESULT_EVENT_TYPE ,
44
- APP_BOXEL_COMMAND_RESULT_MSGTYPE ,
44
+ APP_BOXEL_COMMAND_RESULT_WITH_NO_OUTPUT_MSGTYPE ,
45
+ APP_BOXEL_COMMAND_RESULT_WITH_OUTPUT_MSGTYPE ,
45
46
APP_BOXEL_MESSAGE_MSGTYPE ,
46
47
APP_BOXEL_REALM_SERVER_EVENT_MSGTYPE ,
47
48
APP_BOXEL_REALMS_EVENT_TYPE ,
@@ -64,8 +65,9 @@ import type * as CardAPI from 'https://cardstack.com/base/card-api';
64
65
import type {
65
66
CardMessageContent ,
66
67
CardFragmentContent ,
67
- CommandResultContent ,
68
68
MatrixEvent as DiscreteMatrixEvent ,
69
+ CommandResultWithNoOutputContent ,
70
+ CommandResultWithOutputContent ,
69
71
} from 'https://cardstack.com/base/matrix-event' ;
70
72
71
73
import { SkillCard } from 'https://cardstack.com/base/skill-card' ;
@@ -501,7 +503,11 @@ export default class MatrixService extends Service {
501
503
async sendEvent (
502
504
roomId : string ,
503
505
eventType : string ,
504
- content : CardMessageContent | CardFragmentContent | CommandResultContent ,
506
+ content :
507
+ | CardMessageContent
508
+ | CardFragmentContent
509
+ | CommandResultWithNoOutputContent
510
+ | CommandResultWithOutputContent ,
505
511
) {
506
512
let roomData = await this . ensureRoomData ( roomId ) ;
507
513
return roomData . mutex . dispatch ( async ( ) => {
@@ -526,17 +532,31 @@ export default class MatrixService extends Service {
526
532
if ( resultCard ) {
527
533
[ resultCardEventId ] = await this . addCardsToRoom ( [ resultCard ] , roomId ) ;
528
534
}
529
- let content : CommandResultContent = {
530
- msgtype : APP_BOXEL_COMMAND_RESULT_MSGTYPE ,
531
- 'm.relates_to' : {
532
- event_id : invokedToolFromEventId ,
533
- key : 'applied' ,
534
- rel_type : 'm.annotation' ,
535
- } ,
536
- data : {
537
- cardEventId : resultCardEventId ?? undefined ,
538
- } ,
539
- } ;
535
+ let content :
536
+ | CommandResultWithNoOutputContent
537
+ | CommandResultWithOutputContent ;
538
+ if ( resultCardEventId === undefined ) {
539
+ content = {
540
+ msgtype : APP_BOXEL_COMMAND_RESULT_WITH_NO_OUTPUT_MSGTYPE ,
541
+ 'm.relates_to' : {
542
+ event_id : invokedToolFromEventId ,
543
+ key : 'applied' ,
544
+ rel_type : 'm.annotation' ,
545
+ } ,
546
+ } ;
547
+ } else {
548
+ content = {
549
+ msgtype : APP_BOXEL_COMMAND_RESULT_WITH_OUTPUT_MSGTYPE ,
550
+ 'm.relates_to' : {
551
+ event_id : invokedToolFromEventId ,
552
+ key : 'applied' ,
553
+ rel_type : 'm.annotation' ,
554
+ } ,
555
+ data : {
556
+ cardEventId : resultCardEventId ,
557
+ } ,
558
+ } ;
559
+ }
540
560
try {
541
561
return await this . sendEvent (
542
562
roomId ,
@@ -1279,16 +1299,14 @@ export default class MatrixService extends Service {
1279
1299
} else if (
1280
1300
roomData &&
1281
1301
event . type === APP_BOXEL_COMMAND_RESULT_EVENT_TYPE &&
1282
- event . content ?. msgtype === APP_BOXEL_COMMAND_RESULT_MSGTYPE
1302
+ event . content ?. msgtype === APP_BOXEL_COMMAND_RESULT_WITH_OUTPUT_MSGTYPE
1283
1303
) {
1284
1304
let data = (
1285
1305
typeof event . content . data === 'string'
1286
1306
? JSON . parse ( event . content . data )
1287
1307
: event . content . data
1288
- ) as CommandResultContent [ 'data' ] ;
1289
- if ( data . cardEventId ) {
1290
- this . ensureCardFragmentsLoaded ( data . cardEventId , roomData ) ;
1291
- }
1308
+ ) as CommandResultWithOutputContent [ 'data' ] ;
1309
+ this . ensureCardFragmentsLoaded ( data . cardEventId , roomData ) ;
1292
1310
} else if (
1293
1311
event . type === 'm.room.message' &&
1294
1312
event . content ?. msgtype === APP_BOXEL_REALM_SERVER_EVENT_MSGTYPE
0 commit comments