Skip to content

Commit 8795782

Browse files
committed
Adopt custom rel_type for command results
1 parent c5ec57a commit 8795782

15 files changed

+26
-56
lines changed

packages/ai-bot/helpers.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
APP_BOXEL_COMMAND_REQUESTS_KEY,
2424
APP_BOXEL_COMMAND_DEFINITIONS_MSGTYPE,
2525
APP_BOXEL_COMMAND_RESULT_EVENT_TYPE,
26+
APP_BOXEL_COMMAND_RESULT_REL_TYPE,
2627
APP_BOXEL_COMMAND_RESULT_WITH_OUTPUT_MSGTYPE,
2728
} from '../runtime-common/matrix-constants';
2829
import {
@@ -794,7 +795,8 @@ export function isCommandResultEvent(
794795
}
795796
return (
796797
event.type === APP_BOXEL_COMMAND_RESULT_EVENT_TYPE &&
797-
event.content['m.relates_to']?.rel_type === 'm.annotation'
798+
event.content['m.relates_to']?.rel_type ===
799+
APP_BOXEL_COMMAND_RESULT_REL_TYPE
798800
);
799801
}
800802

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ module('shouldSetRoomTitle', () => {
416416
'm.relates_to': {
417417
event_id: '1',
418418
key: 'applied',
419-
rel_type: 'm.annotation',
419+
rel_type: APP_BOXEL_COMMAND_RESULT_REL_TYPE,
420420
},
421421
msgtype: APP_BOXEL_COMMAND_RESULT_WITH_NO_OUTPUT_MSGTYPE,
422422
},

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1678,7 +1678,7 @@ test('Return host result of tool call back to open ai', async () => {
16781678
content: {
16791679
'm.relates_to': {
16801680
event_id: 'command-event-id-1',
1681-
rel_type: 'm.annotation',
1681+
rel_type: APP_BOXEL_COMMAND_RESULT_REL_TYPE,
16821682
key: 'applied',
16831683
},
16841684
msgtype: APP_BOXEL_COMMAND_RESULT_WITH_OUTPUT_MSGTYPE,

packages/ai-bot/tests/resources/chats/connect-tool-calls-to-results.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@
420420
"m.relates_to": {
421421
"event_id": "$VyCYG0DAuudwMGN8hStuSVfXrjMVZu2ZcJgIs9sIwLE",
422422
"key": "applied",
423-
"rel_type": "m.annotation"
423+
"rel_type": "app.boxel.commandAnnotation"
424424
},
425425
"commandRequestId": "call_or0qFTa8y9Ef8ZVyRDNR2P1T",
426426
"data": "{\"cardEventId\":\"$dKXYGWZLmS42Yib6sDHwP1surO2PiGCr5t2XHFIGFmc\"}"

packages/ai-bot/tests/resources/chats/required-tools-multiple-messages.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@
355355
"m.relates_to": {
356356
"event_id": "$pZ5t1hj93dVwVcrh60-XFNeSL4ztErK6J0wAYr9hI_0",
357357
"key": "applied",
358-
"rel_type": "m.annotation"
358+
"rel_type": "app.boxel.commandAnnotation"
359359
}
360360
},
361361
"origin_server_ts": 1734900014044,
@@ -674,7 +674,7 @@
674674
"m.relates_to": {
675675
"event_id": "$BQ3wE7TxtE38oid1xynRFTglU2_2P5jJ8k01uXrHj1U",
676676
"key": "applied",
677-
"rel_type": "m.annotation"
677+
"rel_type": "app.boxel.commandAnnotation"
678678
}
679679
},
680680
"origin_server_ts": 1734900100494,

packages/ai-bot/tests/resources/chats/two-tool-calls-one-result.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@
428428
"m.relates_to": {
429429
"event_id": "$VyCYG0DAuudwMGN8hStuSVfXrjMVZu2ZcJgIs9sIwLE",
430430
"key": "applied",
431-
"rel_type": "m.annotation"
431+
"rel_type": "app.boxel.commandAnnotation"
432432
},
433433
"commandRequestId": "call_or0qFTa8y9Ef8ZVyRDNR2P1T",
434434
"data": "{\"cardEventId\":\"$dKXYGWZLmS42Yib6sDHwP1surO2PiGCr5t2XHFIGFmc\"}"

packages/ai-bot/tests/resources/chats/two-tool-calls-two-results.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@
428428
"m.relates_to": {
429429
"event_id": "$VyCYG0DAuudwMGN8hStuSVfXrjMVZu2ZcJgIs9sIwLE",
430430
"key": "applied",
431-
"rel_type": "m.annotation"
431+
"rel_type": "app.boxel.commandAnnotation"
432432
},
433433
"commandRequestId": "call_or0qFTa8y9Ef8ZVyRDNR2P1T",
434434
"data": "{\"cardEventId\":\"$dKXYGWZLmS42Yib6sDHwP1surO2PiGCr5t2XHFIGFmc\"}"
@@ -469,7 +469,7 @@
469469
"m.relates_to": {
470470
"event_id": "$VyCYG0DAuudwMGN8hStuSVfXrjMVZu2ZcJgIs9sIwLE",
471471
"key": "applied",
472-
"rel_type": "m.annotation"
472+
"rel_type": "app.boxel.commandAnnotation"
473473
},
474474
"commandRequestId": "call_or1e5Ta8y9Ef8ZVyRDNRabcd",
475475
"data": "{\"cardEventId\":\"$aBcYGWZLmS42Yib6sDHwP1surO2PiGCr5t2XHFIGF12\"}"

packages/base/matrix-event.gts

+2-2
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ export interface CommandDefinitionsContent {
250250
}
251251
export interface CommandResultWithOutputContent {
252252
'm.relates_to': {
253-
rel_type: 'm.annotation';
253+
rel_type: APP_BOXEL_COMMAND_RESULT_REL_TYPE;
254254
key: string;
255255
event_id: string;
256256
};
@@ -265,7 +265,7 @@ export interface CommandResultWithOutputContent {
265265

266266
export interface CommandResultWithNoOutputContent {
267267
'm.relates_to': {
268-
rel_type: 'm.annotation';
268+
rel_type: APP_BOXEL_COMMAND_RESULT_REL_TYPE;
269269
key: string;
270270
event_id: string;
271271
};

packages/host/app/lib/matrix-classes/message-builder.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ export default class MessageBuilder {
227227
let r = e.content['m.relates_to'];
228228
return (
229229
e.type === APP_BOXEL_COMMAND_RESULT_EVENT_TYPE &&
230-
r.rel_type === 'm.annotation' &&
230+
r.rel_type === APP_BOXEL_COMMAND_RESULT_REL_TYPE &&
231231
(r.event_id === this.event.event_id ||
232232
r.event_id === this.builderContext.effectiveEventId) &&
233233
e.content.commandRequestId === commandRequest.id

packages/host/app/resources/room.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,8 @@ export class RoomResource extends Resource<Args> {
452452
event: MessageEvent | CardMessageEvent | CommandResultEvent,
453453
) {
454454
return event.content['m.relates_to']?.rel_type === 'm.replace' ||
455-
event.content['m.relates_to']?.rel_type === 'm.annotation'
455+
event.content['m.relates_to']?.rel_type ===
456+
APP_BOXEL_COMMAND_RESULT_REL_TYPE
456457
? event.content['m.relates_to'].event_id
457458
: event.event_id;
458459
}

packages/host/app/services/matrix-service.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ export default class MatrixService extends Service {
559559
'm.relates_to': {
560560
event_id: invokedToolFromEventId,
561561
key: 'applied',
562-
rel_type: 'm.annotation',
562+
rel_type: APP_BOXEL_COMMAND_RESULT_REL_TYPE,
563563
},
564564
};
565565
} else {
@@ -568,7 +568,7 @@ export default class MatrixService extends Service {
568568
'm.relates_to': {
569569
event_id: invokedToolFromEventId,
570570
key: 'applied',
571-
rel_type: 'm.annotation',
571+
rel_type: APP_BOXEL_COMMAND_RESULT_REL_TYPE,
572572
},
573573
commandRequestId: toolCallId,
574574
data: {

packages/host/tests/acceptance/commands-test.gts

+3-2
Original file line numberDiff line numberDiff line change
@@ -938,7 +938,7 @@ module('Acceptance | Commands tests', function (hooks) {
938938
);
939939
assert.strictEqual(
940940
message.content['m.relates_to']?.rel_type,
941-
'm.annotation',
941+
APP_BOXEL_COMMAND_RESULT_REL_TYPE,
942942
);
943943
assert.strictEqual(message.content['m.relates_to']?.key, 'applied');
944944
assert.strictEqual(message.content.commandRequestId, 'abc123');
@@ -1125,7 +1125,8 @@ module('Acceptance | Commands tests', function (hooks) {
11251125
let commandResultEvents = await getRoomEvents(roomId).filter(
11261126
(event) =>
11271127
event.type === APP_BOXEL_COMMAND_RESULT_EVENT_TYPE &&
1128-
event.content['m.relates_to']?.rel_type === 'm.annotation' &&
1128+
event.content['m.relates_to']?.rel_type ===
1129+
APP_BOXEL_COMMAND_RESULT_REL_TYPE &&
11291130
event.content['m.relates_to']?.key === 'applied',
11301131
);
11311132
assert.equal(

packages/host/tests/helpers/mock-matrix/_server-state.ts

-37
Original file line numberDiff line numberDiff line change
@@ -230,43 +230,6 @@ export class ServerState {
230230
return matrixEvent.event_id;
231231
}
232232

233-
addReactionEvent(
234-
sender: string,
235-
roomId: string,
236-
eventId: string,
237-
status: string,
238-
) {
239-
let room = this.#rooms.get(roomId);
240-
if (!room) {
241-
throw new Error(`room ${roomId} does not exist`);
242-
}
243-
244-
let content = {
245-
'm.relates_to': {
246-
event_id: eventId,
247-
key: status,
248-
rel_type: 'm.annotation' as MatrixSDK.RelationType.Annotation,
249-
},
250-
};
251-
252-
let reactionEvent = {
253-
event_id: this.eventId(),
254-
origin_server_ts: this.#now(),
255-
room_id: roomId,
256-
type: 'm.reaction' as MatrixSDK.EventType.Reaction,
257-
sender,
258-
content,
259-
state_key: '',
260-
unsigned: { age: 0 },
261-
status: 'sent' as MatrixSDK.EventStatus.SENT,
262-
};
263-
264-
room.events.push(reactionEvent);
265-
this.#listeners.forEach((listener) => listener(reactionEvent));
266-
267-
return reactionEvent;
268-
}
269-
270233
addReceiptEvent(
271234
roomId: string,
272235
eventId: string,

packages/host/tests/integration/components/ai-assistant-panel-test.gts

+4-2
Original file line numberDiff line numberDiff line change
@@ -2258,7 +2258,8 @@ module('Integration | ai-assistant-panel', function (hooks) {
22582258
let commandResultEvents = getRoomEvents(roomId).filter(
22592259
(event) =>
22602260
event.type === APP_BOXEL_COMMAND_RESULT_EVENT_TYPE &&
2261-
event.content['m.relates_to']?.rel_type === 'm.annotation' &&
2261+
event.content['m.relates_to']?.rel_type ===
2262+
APP_BOXEL_COMMAND_RESULT_REL_TYPE &&
22622263
event.content['m.relates_to']?.key === 'applied',
22632264
);
22642265
assert.equal(
@@ -2282,7 +2283,8 @@ module('Integration | ai-assistant-panel', function (hooks) {
22822283
commandResultEvents = await getRoomEvents(roomId).filter(
22832284
(event) =>
22842285
event.type === APP_BOXEL_COMMAND_RESULT_EVENT_TYPE &&
2285-
event.content['m.relates_to']?.rel_type === 'm.annotation' &&
2286+
event.content['m.relates_to']?.rel_type ===
2287+
APP_BOXEL_COMMAND_RESULT_REL_TYPE &&
22862288
event.content['m.relates_to']?.key === 'applied',
22872289
);
22882290
assert.equal(

packages/runtime-common/matrix-constants.ts

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export const APP_BOXEL_MESSAGE_MSGTYPE = 'app.boxel.message';
33
export const APP_BOXEL_CARD_FORMAT = 'app.boxel.card';
44
export const APP_BOXEL_COMMAND_REQUESTS_KEY = 'app.boxel.commandRequests';
55
export const APP_BOXEL_COMMAND_RESULT_EVENT_TYPE = 'app.boxel.commandResult';
6+
export const APP_BOXEL_COMMAND_RESULT_REL_TYPE = 'app.boxel.commandAnnotation';
67
export const APP_BOXEL_COMMAND_DEFINITIONS_MSGTYPE =
78
'app.boxel.commandDefinitions';
89
export const APP_BOXEL_COMMAND_RESULT_WITH_OUTPUT_MSGTYPE =

0 commit comments

Comments
 (0)