@@ -6,6 +6,8 @@ import { tracked } from '@glimmer/tracking';
6
6
7
7
import { enqueueTask , restartableTask , timeout , all } from ' ember-concurrency' ;
8
8
9
+ import { v4 as uuidv4 } from ' uuid' ;
10
+
9
11
import { getAutoAttachment } from ' @cardstack/host/resources/auto-attached-card' ;
10
12
import { getRoom } from ' @cardstack/host/resources/room' ;
11
13
@@ -41,12 +43,13 @@ export default class Room extends Component<Signature> {
41
43
data-test-room-name ={{this .room.name }}
42
44
data-test-room ={{this .room.roomId }}
43
45
>
44
- {{#if this . hasMessagesOrPending }}
46
+ {{#if this . room.messages }}
45
47
<AiAssistantConversation >
46
48
{{#each this . room.messages as | message i | }}
47
49
<RoomMessage
48
50
@ message ={{message }}
49
51
@ index ={{i }}
52
+ @ isPending ={{this .isPendingMessage message }}
50
53
@ monacoSDK ={{@ monacoSDK }}
51
54
@ isStreaming ={{this .isMessageStreaming message i }}
52
55
@ currentEditor ={{this .currentMonacoContainer }}
@@ -55,17 +58,6 @@ export default class Room extends Component<Signature> {
55
58
data-test-message-idx ={{i }}
56
59
/>
57
60
{{/each }}
58
- {{#if this . pendingMessage }}
59
- <RoomMessage
60
- @ message ={{this .pendingMessage }}
61
- @ monacoSDK ={{@ monacoSDK }}
62
- @ isStreaming ={{ false }}
63
- @ isPending ={{ true }}
64
- @ currentEditor ={{this .currentMonacoContainer }}
65
- @ setCurrentEditor ={{this .setCurrentMonacoContainer }}
66
- data-test-message-idx ={{this .room.messages.length }}
67
- />
68
- {{/if }}
69
61
</AiAssistantConversation >
70
62
{{else }}
71
63
<NewSession @ sendPrompt ={{this .sendPrompt }} />
@@ -157,12 +149,9 @@ export default class Room extends Component<Signature> {
157
149
await this .roomResource .loading ;
158
150
});
159
151
160
- private get hasMessagesOrPending() {
161
- return (this .room && this .room .messages .length > 0 ) || this .pendingMessage ;
162
- }
163
-
164
152
private get room() {
165
- return this .roomResource .room ;
153
+ let room = this .roomResource .room ;
154
+ return room ;
166
155
}
167
156
168
157
private doWhenRoomChanges = restartableTask (async () => {
@@ -177,10 +166,6 @@ export default class Room extends Component<Signature> {
177
166
return this .matrixService .cardsToSend .get (this .args .roomId );
178
167
}
179
168
180
- private get pendingMessage() {
181
- return this .matrixService .pendingMessages .get (this .args .roomId );
182
- }
183
-
184
169
@action resendLastMessage() {
185
170
if (! this .room ) {
186
171
throw new Error (
@@ -202,7 +187,11 @@ export default class Room extends Component<Signature> {
202
187
.map ((resource ) => resource .card )
203
188
.filter ((card ) => card !== undefined ) as CardDef [];
204
189
205
- this .doSendMessage .perform (myLastMessage .message , attachedCards );
190
+ this .doSendMessage .perform (
191
+ myLastMessage .message ,
192
+ attachedCards ,
193
+ myLastMessage .clientGeneratedId ,
194
+ );
206
195
}
207
196
208
197
@action sendPrompt(prompt : string ) {
@@ -253,7 +242,11 @@ export default class Room extends Component<Signature> {
253
242
}
254
243
}
255
244
private doSendMessage = enqueueTask (
256
- async (message : string | undefined , cards ? : CardDef []) => {
245
+ async (
246
+ message : string | undefined ,
247
+ cards ?: CardDef [],
248
+ clientGeneratedId : string = uuidv4 (),
249
+ ) => {
257
250
this .matrixService .messagesToSend .set (this .args .roomId , undefined );
258
251
this .matrixService .cardsToSend .set (this .args .roomId , undefined );
259
252
let context = {
@@ -267,6 +260,7 @@ export default class Room extends Component<Signature> {
267
260
this .args .roomId ,
268
261
message ,
269
262
cards ,
263
+ clientGeneratedId ,
270
264
context ,
271
265
);
272
266
},
@@ -306,7 +300,9 @@ export default class Room extends Component<Signature> {
306
300
this .messageToSend ||
307
301
this .cardsToAttach ?.length ||
308
302
this .autoAttachedCard ,
309
- )
303
+ ) &&
304
+ !! this .room &&
305
+ ! this .room .messages .some ((m ) => this .isPendingMessage (m ))
310
306
);
311
307
}
312
308
@@ -320,6 +316,10 @@ export default class Room extends Component<Signature> {
320
316
@action private setCurrentMonacoContainer(index : number | undefined ) {
321
317
this .currentMonacoContainer = index ;
322
318
}
319
+
320
+ private isPendingMessage(message : MessageField ) {
321
+ return message .status === ' sending' || message .status === ' queued' ;
322
+ }
323
323
}
324
324
325
325
declare module ' @glint/environment-ember-loose/registry' {
0 commit comments