Skip to content

Commit eda36f6

Browse files
authored
Merge pull request #1953 from cardstack/org-boxel-to-app-boxel
[BREAKING] Update our custom matrix identifiers from org.boxel to app.boxel
2 parents 2f4a798 + c46c43b commit eda36f6

38 files changed

+423
-236
lines changed

packages/ai-bot/helpers.ts

+16-9
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ import { MatrixEvent, type IRoomEvent } from 'matrix-js-sdk';
1717
import { ChatCompletionMessageToolCall } from 'openai/resources/chat/completions';
1818
import * as Sentry from '@sentry/node';
1919
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';
2027

2128
let log = logger('ai-bot');
2229

@@ -91,7 +98,7 @@ export function extractCardFragmentsFromEvents(
9198
const fragments = new Map<string, CardFragmentContent>(); // eventId => fragment
9299
for (let event of eventList) {
93100
if (event.type === 'm.room.message') {
94-
if (event.content.msgtype === 'org.boxel.cardFragment') {
101+
if (event.content.msgtype === APP_BOXEL_CARDFRAGMENT_MSGTYPE) {
95102
fragments.set(event.event_id, event.content as CardFragmentContent);
96103
}
97104
}
@@ -136,10 +143,10 @@ export function constructHistory(
136143
continue;
137144
}
138145
let eventId = event.event_id!;
139-
if (event.content.msgtype === 'org.boxel.cardFragment') {
146+
if (event.content.msgtype === APP_BOXEL_CARDFRAGMENT_MSGTYPE) {
140147
continue;
141148
}
142-
if (event.content.msgtype === 'org.boxel.message') {
149+
if (event.content.msgtype === APP_BOXEL_MESSAGE_MSGTYPE) {
143150
let { attachedCardsEventIds } = event.content.data;
144151
if (attachedCardsEventIds && attachedCardsEventIds.length > 0) {
145152
event.content.data.attachedCards = attachedCardsEventIds.map((id) =>
@@ -174,7 +181,7 @@ function getEnabledSkills(
174181
cardFragments: Map<string, CardFragmentContent>,
175182
): LooseCardResource[] {
176183
let skillsConfigEvent = eventlist.findLast(
177-
(event) => event.type === 'com.cardstack.boxel.room.skills',
184+
(event) => event.type === APP_BOXEL_ROOM_SKILLS_EVENT_TYPE,
178185
) as SkillsConfigEvent;
179186
if (!skillsConfigEvent) {
180187
return [];
@@ -272,7 +279,7 @@ export function getRelevantCards(
272279
}
273280
if (event.sender !== aiBotUserId) {
274281
let { content } = event;
275-
if (content.msgtype === 'org.boxel.message') {
282+
if (content.msgtype === APP_BOXEL_MESSAGE_MSGTYPE) {
276283
setRelevantCards(attachedCardMap, content.data?.attachedCards);
277284
if (content.data?.attachedCards) {
278285
mostRecentlyAttachedCard = getMostRecentlyAttachedCard(
@@ -310,7 +317,7 @@ export function getTools(
310317
const lastMessage = userMessages[userMessages.length - 1];
311318
if (
312319
lastMessage.type === 'm.room.message' &&
313-
lastMessage.content.msgtype === 'org.boxel.message' &&
320+
lastMessage.content.msgtype === APP_BOXEL_MESSAGE_MSGTYPE &&
314321
lastMessage.content.data?.context?.tools?.length
315322
) {
316323
return lastMessage.content.data.context.tools;
@@ -326,7 +333,7 @@ export function isCommandResultEvent(
326333
return (
327334
event.type === 'm.room.message' &&
328335
typeof event.content === 'object' &&
329-
event.content.msgtype === 'org.boxel.commandResult'
336+
event.content.msgtype === APP_BOXEL_COMMAND_RESULT_MSGTYPE
330337
);
331338
}
332339

@@ -449,7 +456,7 @@ export function getModifyPrompt(
449456
}
450457
} else {
451458
if (
452-
event.content.msgtype === 'org.boxel.message' &&
459+
event.content.msgtype === APP_BOXEL_MESSAGE_MSGTYPE &&
453460
event.content.data?.context?.openCardIds
454461
) {
455462
body = `User message: ${body}
@@ -559,7 +566,7 @@ export function isCommandEvent(
559566
return (
560567
event.type === 'm.room.message' &&
561568
typeof event.content === 'object' &&
562-
event.content.msgtype === 'org.boxel.command' &&
569+
event.content.msgtype === APP_BOXEL_COMMAND_MSGTYPE &&
563570
event.content.format === 'org.matrix.custom.html' &&
564571
typeof event.content.data === 'object' &&
565572
typeof event.content.data.toolCall === 'object'

packages/ai-bot/lib/matrix.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { logger } from '@cardstack/runtime-common';
33
import { OpenAIError } from 'openai/error';
44
import * as Sentry from '@sentry/node';
55
import { FunctionToolCall } from '@cardstack/runtime-common/helpers/ai';
6+
import { APP_BOXEL_COMMAND_MSGTYPE } from '@cardstack/runtime-common/matrix-constants';
67

78
let log = logger('ai-bot');
89

@@ -129,7 +130,7 @@ export const toMatrixMessageCommandContent = (
129130
const body = payload['description'] || 'Issuing command';
130131
let messageObject: IContent = {
131132
body: body,
132-
msgtype: 'org.boxel.command',
133+
msgtype: APP_BOXEL_COMMAND_MSGTYPE,
133134
formatted_body: body,
134135
format: 'org.matrix.custom.html',
135136
data: {

packages/ai-bot/main.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import {
1515
getPromptParts,
1616
extractCardFragmentsFromEvents,
1717
} from './helpers';
18+
import { APP_BOXEL_CARDFRAGMENT_MSGTYPE } from '@cardstack/runtime-common/matrix-constants';
19+
1820
import {
1921
shouldSetRoomTitle,
2022
setTitle,
@@ -167,7 +169,7 @@ Common issues are:
167169
if (event.getType() !== 'm.room.message') {
168170
return; // only print messages
169171
}
170-
if (event.getContent().msgtype === 'org.boxel.cardFragment') {
172+
if (event.getContent().msgtype === APP_BOXEL_CARDFRAGMENT_MSGTYPE) {
171173
return; // don't respond to card fragments, we just gather these in our history
172174
}
173175

packages/ai-bot/tests/chat-titling-test.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { module, test, assert } from 'qunit';
22
import { shouldSetRoomTitle } from '../lib/set-title';
33
import type { MatrixEvent as DiscreteMatrixEvent } from 'https://cardstack.com/base/matrix-event';
4+
import { APP_BOXEL_COMMAND_MSGTYPE } from '@cardstack/runtime-common/matrix-constants';
45

56
module('shouldSetRoomTitle', () => {
67
test('Do not set a title when there is no content', () => {
@@ -370,7 +371,7 @@ module('shouldSetRoomTitle', () => {
370371
event_id: '2',
371372
origin_server_ts: 1234567890,
372373
content: {
373-
msgtype: 'org.boxel.command',
374+
msgtype: APP_BOXEL_COMMAND_MSGTYPE,
374375
format: 'org.matrix.custom.html',
375376
body: 'patching card',
376377
formatted_body: 'patching card',
@@ -439,7 +440,7 @@ module('shouldSetRoomTitle', () => {
439440
event_id: '2',
440441
origin_server_ts: 1234567890,
441442
content: {
442-
msgtype: 'org.boxel.command',
443+
msgtype: APP_BOXEL_COMMAND_MSGTYPE,
443444
format: 'org.matrix.custom.html',
444445
body: 'patching card',
445446
formatted_body: 'patching card',

packages/ai-bot/tests/history-construction-test.ts

+16-10
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ import {
44
extractCardFragmentsFromEvents,
55
HistoryConstructionError,
66
} from '../helpers';
7+
import {
8+
APP_BOXEL_CARD_FORMAT,
9+
APP_BOXEL_CARDFRAGMENT_MSGTYPE,
10+
APP_BOXEL_MESSAGE_MSGTYPE,
11+
} from '@cardstack/runtime-common/matrix-constants';
12+
713
import { type IRoomEvent } from 'matrix-js-sdk';
814
import type { MatrixEvent as DiscreteMatrixEvent } from 'https://cardstack.com/base/matrix-event';
915

@@ -383,8 +389,8 @@ module('constructHistory', () => {
383389
event_id: '1',
384390
origin_server_ts: 1234567900,
385391
content: {
386-
msgtype: 'org.boxel.cardFragment',
387-
format: 'org.boxel.card',
392+
msgtype: APP_BOXEL_CARDFRAGMENT_MSGTYPE,
393+
format: APP_BOXEL_CARD_FORMAT,
388394
formatted_body: '',
389395
body: '',
390396
data: JSON.stringify({
@@ -405,8 +411,8 @@ module('constructHistory', () => {
405411
event_id: '2',
406412
origin_server_ts: 1234567890,
407413
content: {
408-
msgtype: 'org.boxel.cardFragment',
409-
format: 'org.boxel.card',
414+
msgtype: APP_BOXEL_CARDFRAGMENT_MSGTYPE,
415+
format: APP_BOXEL_CARD_FORMAT,
410416
formatted_body: '',
411417
body: '',
412418
data: JSON.stringify({
@@ -428,8 +434,8 @@ module('constructHistory', () => {
428434
event_id: '3',
429435
origin_server_ts: 1234567910,
430436
content: {
431-
msgtype: 'org.boxel.cardFragment',
432-
format: 'org.boxel.card',
437+
msgtype: APP_BOXEL_CARDFRAGMENT_MSGTYPE,
438+
format: APP_BOXEL_CARD_FORMAT,
433439
formatted_body: '',
434440
body: '',
435441
data: JSON.stringify({
@@ -450,7 +456,7 @@ module('constructHistory', () => {
450456
event_id: '4',
451457
origin_server_ts: 1234567920,
452458
content: {
453-
msgtype: 'org.boxel.message',
459+
msgtype: APP_BOXEL_MESSAGE_MSGTYPE,
454460
format: 'org.matrix.custom.html',
455461
body: 'Hey',
456462
formatted_body: 'Hey',
@@ -479,7 +485,7 @@ module('constructHistory', () => {
479485
event_id: '4',
480486
origin_server_ts: 1234567920,
481487
content: {
482-
msgtype: 'org.boxel.message',
488+
msgtype: APP_BOXEL_MESSAGE_MSGTYPE,
483489
format: 'org.matrix.custom.html',
484490
body: 'Hey',
485491
formatted_body: 'Hey',
@@ -542,8 +548,8 @@ module('constructHistory', () => {
542548
room_id: 'room1',
543549
sender: '@user:localhost',
544550
content: {
545-
msgtype: 'org.boxel.cardFragment',
546-
format: 'org.boxel.card',
551+
msgtype: APP_BOXEL_CARDFRAGMENT_MSGTYPE,
552+
format: APP_BOXEL_CARD_FORMAT,
547553
body: 'card fragment 1 of 1',
548554
formatted_body: 'card fragment 1 of 1',
549555
// data should be a JSON string

0 commit comments

Comments
 (0)