Skip to content

Commit 8a96717

Browse files
authored
Merge pull request #1113 from cardstack/initial-room-name
Give new AI chats a default room name
2 parents 9dedf5c + f9d6925 commit 8a96717

File tree

8 files changed

+145
-109
lines changed

8 files changed

+145
-109
lines changed

packages/host/app/components/ai-assistant/panel.gts

+1-5
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import Component from '@glimmer/component';
88
//@ts-expect-error the types don't recognize the cached export
99
import { tracked, cached } from '@glimmer/tracking';
1010

11-
import format from 'date-fns/format';
1211
import { restartableTask, timeout } from 'ember-concurrency';
1312
import { Velcro } from 'ember-velcro';
1413
import { TrackedMap } from 'tracked-built-ins';
@@ -330,10 +329,7 @@ export default class AiAssistantPanel extends Component<Signature> {
330329
this.enterRoom(this.newSessionId!);
331330
return;
332331
}
333-
let newRoomName = `${format(
334-
new Date(),
335-
"yyyy-MM-dd'T'HH:mm:ss.SSSxxx",
336-
)} - ${this.matrixService.userId}`;
332+
let newRoomName = 'New AI Assistant Chat';
337333
this.doCreateRoom.perform(newRoomName, [aiBotUsername]);
338334
}
339335

packages/host/app/components/ai-assistant/past-session-item.gts

+3-3
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ interface Signature {
3838

3939
export default class PastSessionItem extends Component<Signature> {
4040
<template>
41-
<li class='session' data-test-joined-room={{@room.name}}>
41+
<li class='session' data-test-joined-room={{@room.roomId}}>
4242
<button
4343
class='view-session-button'
4444
{{on 'click' (fn @actions.open @room.roomId)}}
45-
data-test-enter-room={{@room.name}}
45+
data-test-enter-room={{@room.roomId}}
4646
>
4747
<div class='name'>{{@room.name}}</div>
4848
<div class='date' data-test-last-active={{this.lastActive}}>
@@ -59,7 +59,7 @@ export default class PastSessionItem extends Component<Signature> {
5959
@height='20px'
6060
class='menu-button'
6161
aria-label='Options'
62-
data-test-past-session-options-button={{@room.name}}
62+
data-test-past-session-options-button={{@room.roomId}}
6363
{{bindings}}
6464
/>
6565
</:trigger>

packages/host/app/components/matrix/room.gts

+3-3
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ export default class Room extends Component<Signature> {
4040
class='room'
4141
data-room-settled={{this.doWhenRoomChanges.isIdle}}
4242
data-test-room-settled={{this.doWhenRoomChanges.isIdle}}
43-
data-test-room={{this.room.name}}
44-
data-test-room-id={{this.room.roomId}}
43+
data-test-room-name={{this.room.name}}
44+
data-test-room={{this.room.roomId}}
4545
>
4646
{{#if this.room.messages}}
4747
<AiAssistantConversation>
@@ -68,7 +68,7 @@ export default class Room extends Component<Signature> {
6868
@onInput={{this.setMessage}}
6969
@onSend={{this.sendMessage}}
7070
@canSend={{this.canSend}}
71-
data-test-message-field={{this.room.name}}
71+
data-test-message-field={{this.room.roomId}}
7272
/>
7373
<AiAssistantCardPicker
7474
@autoAttachedCard={{this.autoAttachedCard}}

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

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import type RouterService from '@ember/routing/router-service';
22
import Service, { service } from '@ember/service';
3-
43
import { tracked } from '@glimmer/tracking';
54

5+
import format from 'date-fns/format';
6+
67
import { task } from 'ember-concurrency';
78
import { marked } from 'marked';
89
import {
@@ -296,7 +297,11 @@ export default class MatrixService extends Service {
296297
invite,
297298
name,
298299
topic,
299-
room_alias_name: encodeURIComponent(name),
300+
room_alias_name: encodeURIComponent(
301+
`${name} - ${format(new Date(), "yyyy-MM-dd'T'HH:mm:ss.SSSxxx")} - ${
302+
this.userId
303+
}`,
304+
),
300305
});
301306
invites.map((i) => {
302307
let fullId = i.startsWith('@') ? i : `@${i}:${userId!.split(':')[1]}`;

packages/host/tests/integration/components/operator-mode-test.gts

+14-8
Original file line numberDiff line numberDiff line change
@@ -686,8 +686,8 @@ module('Integration | operator-mode', function (hooks) {
686686
await click('[data-test-open-ai-assistant]');
687687
await waitFor('[data-test-room-settled]');
688688
let roomId = document
689-
.querySelector('[data-test-room-id]')
690-
?.getAttribute('data-test-room-id');
689+
.querySelector('[data-test-room]')
690+
?.getAttribute('data-test-room');
691691
if (!roomId) {
692692
throw new Error('Expected a room ID');
693693
}
@@ -963,28 +963,34 @@ module('Integration | operator-mode', function (hooks) {
963963
let tinyDelay = () => new Promise((resolve) => setTimeout(resolve, 1)); // Add a tiny artificial delay to ensure rooms are created in the correct order with increasing timestamps
964964
await matrixService.createAndJoinRoom('test1', 'test room 1');
965965
await tinyDelay();
966-
await matrixService.createAndJoinRoom('test2', 'test room 2');
966+
const room2Id = await matrixService.createAndJoinRoom(
967+
'test2',
968+
'test room 2',
969+
);
967970
await tinyDelay();
968-
await matrixService.createAndJoinRoom('test3', 'test room 3');
971+
const room3Id = await matrixService.createAndJoinRoom(
972+
'test3',
973+
'test room 3',
974+
);
969975

970976
await waitFor(`[data-test-open-ai-assistant]`);
971977
await click('[data-test-open-ai-assistant]');
972978
await waitFor(`[data-room-settled]`);
973979

974980
assert
975-
.dom('[data-test-room="test room 3"]')
981+
.dom(`[data-test-room="${room3Id}"]`)
976982
.exists(
977983
"test room 3 is the most recently created room and it's opened initially",
978984
);
979985

980986
await click('[data-test-past-sessions-button]');
981-
await click('[data-test-enter-room="test room 2"]');
987+
await click(`[data-test-enter-room="${room2Id}"]`);
982988

983989
await click('[data-test-close-ai-assistant]');
984990
await click('[data-test-open-ai-assistant]');
985991
await waitFor(`[data-room-settled]`);
986992
assert
987-
.dom('[data-test-room="test room 2"]')
993+
.dom(`[data-test-room="${room2Id}"]`)
988994
.exists(
989995
"test room 2 is the most recently selected room and it's opened initially",
990996
);
@@ -997,7 +1003,7 @@ module('Integration | operator-mode', function (hooks) {
9971003
await click('[data-test-open-ai-assistant]');
9981004
await waitFor(`[data-room-settled]`);
9991005
assert
1000-
.dom('[data-test-room="test room 3"]')
1006+
.dom(`[data-test-room="${room3Id}"]`)
10011007
.exists(
10021008
"test room 3 is the most recently created room and it's opened initially",
10031009
);

packages/matrix/helpers/index.ts

+26-25
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
import { registerUser } from '../docker/synapse';
1010
export const testHost = 'http://localhost:4202/test';
1111
export const mailHost = 'http://localhost:5001';
12+
export const initialRoomName = 'New AI Assistant Chat';
1213

1314
interface ProfileAssertions {
1415
userId?: string;
@@ -249,40 +250,40 @@ export async function logout(page: Page) {
249250

250251
export async function createRoom(page: Page) {
251252
await page.locator('[data-test-create-room-btn]').click();
252-
let roomName = await getRoomName(page);
253-
await isInRoom(page, roomName);
254-
return roomName;
253+
let roomId = await getRoomId(page);
254+
await isInRoom(page, roomId);
255+
return roomId;
255256
}
256257

257258
export async function createRoomWithMessage(page: Page, message?: string) {
258-
let roomName = await createRoom(page);
259-
await sendMessage(page, roomName, message ?? 'Hello, world!');
260-
return roomName;
259+
let roomId = await createRoom(page);
260+
await sendMessage(page, roomId, message ?? 'Hello, world!');
261+
return roomId;
261262
}
262263

263-
export async function getRoomName(page: Page) {
264+
export async function getRoomId(page: Page) {
264265
await page.locator(`[data-test-room-settled]`).waitFor();
265-
let name = await page
266+
let roomId = await page
266267
.locator('[data-test-room]')
267268
.getAttribute('data-test-room');
268-
if (name == null) {
269-
throw new Error('room name is not found');
269+
if (roomId == null) {
270+
throw new Error('room ID is not found');
270271
}
271-
return name;
272+
return roomId;
272273
}
273274

274-
export async function isInRoom(page: Page, roomName: string) {
275-
await page.locator(`[data-test-room="${roomName}"]`).waitFor();
275+
export async function isInRoom(page: Page, roomId: string) {
276+
await page.locator(`[data-test-room="${roomId}"]`).waitFor();
276277
await expect(page.locator(`[data-test-room-settled]`)).toHaveCount(1);
277278
}
278279

279-
export async function deleteRoom(page: Page, roomName: string) {
280+
export async function deleteRoom(page: Page, roomId: string) {
280281
await page.locator(`[data-test-past-sessions-button]`).click();
281282

282283
// Here, past sessions could be rerendered because in one case we're creating a new room when opening an AI panel, so we need to wait for the past sessions to settle
283284
await page.waitForTimeout(500);
284285
await page
285-
.locator(`[data-test-past-session-options-button="${roomName}"]`)
286+
.locator(`[data-test-past-session-options-button="${roomId}"]`)
286287
.click();
287288

288289
await page.locator(`[data-test-boxel-menu-item-text="Delete"]`).click();
@@ -293,16 +294,16 @@ export async function deleteRoom(page: Page, roomName: string) {
293294
.click();
294295
}
295296

296-
export async function openRoom(page: Page, roomName: string) {
297+
export async function openRoom(page: Page, roomId: string) {
297298
await page.locator(`[data-test-past-sessions-button]`).click(); // toggle past sessions on
298-
await page.locator(`[data-test-enter-room="${roomName}"]`).click();
299-
await isInRoom(page, roomName);
299+
await page.locator(`[data-test-enter-room="${roomId}"]`).click();
300+
await isInRoom(page, roomId);
300301
}
301302

302-
export async function openRenameMenu(page: Page, name: string) {
303+
export async function openRenameMenu(page: Page, roomId: string) {
303304
await page.locator(`[data-test-past-sessions-button]`).click();
304305
await page
305-
.locator(`[data-test-past-session-options-button="${name}"]`)
306+
.locator(`[data-test-past-session-options-button="${roomId}"]`)
306307
.click();
307308
await expect(
308309
page.locator(`[data-test-boxel-menu-item-text="Rename"]`),
@@ -313,12 +314,12 @@ export async function openRenameMenu(page: Page, name: string) {
313314

314315
export async function writeMessage(
315316
page: Page,
316-
roomName: string,
317+
roomId: string,
317318
message: string,
318319
) {
319-
await page.locator(`[data-test-message-field="${roomName}"]`).fill(message);
320+
await page.locator(`[data-test-message-field="${roomId}"]`).fill(message);
320321
await expect(
321-
page.locator(`[data-test-message-field="${roomName}"]`),
322+
page.locator(`[data-test-message-field="${roomId}"]`),
322323
).toHaveValue(message);
323324
}
324325

@@ -337,7 +338,7 @@ export async function selectCardFromCatalog(
337338

338339
export async function sendMessage(
339340
page: Page,
340-
roomName: string,
341+
roomId: string,
341342
message: string | undefined,
342343
cardIds?: string[],
343344
) {
@@ -347,7 +348,7 @@ export async function sendMessage(
347348
);
348349
}
349350
if (message != null) {
350-
await writeMessage(page, roomName, message);
351+
await writeMessage(page, roomId, message);
351352
}
352353
if (cardIds?.length) {
353354
for (let cardId of cardIds) {

0 commit comments

Comments
 (0)