diff --git a/packages/host/app/commands/create-ai-assistant-room.ts b/packages/host/app/commands/create-ai-assistant-room.ts index 6160f0483c..4fd5bd779e 100644 --- a/packages/host/app/commands/create-ai-assistant-room.ts +++ b/packages/host/app/commands/create-ai-assistant-room.ts @@ -2,8 +2,6 @@ import { service } from '@ember/service'; import format from 'date-fns/format'; -import { aiBotUsername } from '@cardstack/runtime-common'; - import { APP_BOXEL_ACTIVE_LLM, DEFAULT_LLM, @@ -31,14 +29,8 @@ export default class CreateAiAssistantRoomCommand extends HostBaseCommand< input: BaseCommandModule.CreateAIAssistantRoomInput, ): Promise { let { matrixService } = this; - let { userId } = matrixService; - if (!userId) { - throw new Error( - `bug: there is no userId associated with the matrix client`, - ); - } - let server = userId!.split(':')[1]; - let aiBotFullId = `@${aiBotUsername}:${server}`; + let userId = matrixService.userId; + let aiBotFullId = matrixService.aiBotUserId; let { room_id: roomId } = await matrixService.createRoom({ preset: matrixService.privateChatPreset, invite: [aiBotFullId], diff --git a/packages/host/app/services/matrix-service.ts b/packages/host/app/services/matrix-service.ts index 82d3d5ba40..8c55fcc28d 100644 --- a/packages/host/app/services/matrix-service.ts +++ b/packages/host/app/services/matrix-service.ts @@ -26,7 +26,9 @@ import { baseRealm, LooseCardResource, ResolvedCodeRef, + aiBotUsername, } from '@cardstack/runtime-common'; + import { basicMappings, generateJsonSchemaForCardType, @@ -233,6 +235,11 @@ export default class MatrixService extends Service { return this.client.getUserId(); } + get aiBotUserId() { + let server = this.userId!.split(':')[1]; + return `@${aiBotUsername}:${server}`; + } + get userName() { return this.userId ? getMatrixUsername(this.userId) : null; }