@@ -17,6 +17,13 @@ import { MatrixEvent, type IRoomEvent } from 'matrix-js-sdk';
17
17
import { ChatCompletionMessageToolCall } from 'openai/resources/chat/completions' ;
18
18
import * as Sentry from '@sentry/node' ;
19
19
import { logger } from '@cardstack/runtime-common' ;
20
+ import {
21
+ APP_BOXEL_CARDFRAGMENT_MSGTYPE ,
22
+ APP_BOXEL_MESSAGE_MSGTYPE ,
23
+ APP_BOXEL_COMMAND_MSGTYPE ,
24
+ APP_BOXEL_COMMAND_RESULT_MSGTYPE ,
25
+ APP_BOXEL_ROOM_SKILLS_EVENT_TYPE ,
26
+ } from '@cardstack/runtime-common/matrix-constants' ;
20
27
21
28
let log = logger ( 'ai-bot' ) ;
22
29
@@ -91,7 +98,7 @@ export function extractCardFragmentsFromEvents(
91
98
const fragments = new Map < string , CardFragmentContent > ( ) ; // eventId => fragment
92
99
for ( let event of eventList ) {
93
100
if ( event . type === 'm.room.message' ) {
94
- if ( event . content . msgtype === 'org.boxel.cardFragment' ) {
101
+ if ( event . content . msgtype === APP_BOXEL_CARDFRAGMENT_MSGTYPE ) {
95
102
fragments . set ( event . event_id , event . content as CardFragmentContent ) ;
96
103
}
97
104
}
@@ -136,10 +143,10 @@ export function constructHistory(
136
143
continue ;
137
144
}
138
145
let eventId = event . event_id ! ;
139
- if ( event . content . msgtype === 'org.boxel.cardFragment' ) {
146
+ if ( event . content . msgtype === APP_BOXEL_CARDFRAGMENT_MSGTYPE ) {
140
147
continue ;
141
148
}
142
- if ( event . content . msgtype === 'org.boxel.message' ) {
149
+ if ( event . content . msgtype === APP_BOXEL_MESSAGE_MSGTYPE ) {
143
150
let { attachedCardsEventIds } = event . content . data ;
144
151
if ( attachedCardsEventIds && attachedCardsEventIds . length > 0 ) {
145
152
event . content . data . attachedCards = attachedCardsEventIds . map ( ( id ) =>
@@ -174,7 +181,7 @@ function getEnabledSkills(
174
181
cardFragments : Map < string , CardFragmentContent > ,
175
182
) : LooseCardResource [ ] {
176
183
let skillsConfigEvent = eventlist . findLast (
177
- ( event ) => event . type === 'com.cardstack.boxel.room.skills' ,
184
+ ( event ) => event . type === APP_BOXEL_ROOM_SKILLS_EVENT_TYPE ,
178
185
) as SkillsConfigEvent ;
179
186
if ( ! skillsConfigEvent ) {
180
187
return [ ] ;
@@ -272,7 +279,7 @@ export function getRelevantCards(
272
279
}
273
280
if ( event . sender !== aiBotUserId ) {
274
281
let { content } = event ;
275
- if ( content . msgtype === 'org.boxel.message' ) {
282
+ if ( content . msgtype === APP_BOXEL_MESSAGE_MSGTYPE ) {
276
283
setRelevantCards ( attachedCardMap , content . data ?. attachedCards ) ;
277
284
if ( content . data ?. attachedCards ) {
278
285
mostRecentlyAttachedCard = getMostRecentlyAttachedCard (
@@ -310,7 +317,7 @@ export function getTools(
310
317
const lastMessage = userMessages [ userMessages . length - 1 ] ;
311
318
if (
312
319
lastMessage . type === 'm.room.message' &&
313
- lastMessage . content . msgtype === 'org.boxel.message' &&
320
+ lastMessage . content . msgtype === APP_BOXEL_MESSAGE_MSGTYPE &&
314
321
lastMessage . content . data ?. context ?. tools ?. length
315
322
) {
316
323
return lastMessage . content . data . context . tools ;
@@ -326,7 +333,7 @@ export function isCommandResultEvent(
326
333
return (
327
334
event . type === 'm.room.message' &&
328
335
typeof event . content === 'object' &&
329
- event . content . msgtype === 'org.boxel.commandResult'
336
+ event . content . msgtype === APP_BOXEL_COMMAND_RESULT_MSGTYPE
330
337
) ;
331
338
}
332
339
@@ -449,7 +456,7 @@ export function getModifyPrompt(
449
456
}
450
457
} else {
451
458
if (
452
- event . content . msgtype === 'org.boxel.message' &&
459
+ event . content . msgtype === APP_BOXEL_MESSAGE_MSGTYPE &&
453
460
event . content . data ?. context ?. openCardIds
454
461
) {
455
462
body = `User message: ${ body }
@@ -559,7 +566,7 @@ export function isCommandEvent(
559
566
return (
560
567
event . type === 'm.room.message' &&
561
568
typeof event . content === 'object' &&
562
- event . content . msgtype === 'org.boxel.command' &&
569
+ event . content . msgtype === APP_BOXEL_COMMAND_MSGTYPE &&
563
570
event . content . format === 'org.matrix.custom.html' &&
564
571
typeof event . content . data === 'object' &&
565
572
typeof event . content . data . toolCall === 'object'
0 commit comments