@@ -18,15 +18,15 @@ import { isCardInstance } from '@cardstack/runtime-common';
18
18
19
19
import CardPill from ' @cardstack/host/components/card-pill' ;
20
20
import FilePill from ' @cardstack/host/components/file-pill' ;
21
- import CodeBlock from ' @cardstack/host/modifiers/code-block' ;
22
- import { MonacoEditorOptions } from ' @cardstack/host/modifiers/monaco' ;
23
21
24
22
import type CardService from ' @cardstack/host/services/card-service' ;
25
23
import { type MonacoSDK } from ' @cardstack/host/services/monaco-service' ;
26
24
27
25
import { type CardDef } from ' https://cardstack.com/base/card-api' ;
28
26
import { type FileDef } from ' https://cardstack.com/base/file-api' ;
29
27
28
+ import FormattedMessage from ' ../formatted-message' ;
29
+
30
30
import type { ComponentLike } from ' @glint/template' ;
31
31
32
32
function findLastTextNodeWithContent(parentNode : Node ): Text | null {
@@ -191,13 +191,6 @@ export default class AiAssistantMessage extends Component<Signature> {
191
191
is-error =@ errorMessage
192
192
}}
193
193
{{MessageScroller index =@ index registerScroller =@ registerScroller}}
194
- {{CodeBlock
195
- codeBlockSelector =' pre[data-codeblock]'
196
- languageAttr =' data-codeblock'
197
- monacoSDK =@ monacoSDK
198
- editorDisplayOptions =this . editorDisplayOptions
199
- index =@ index
200
- }}
201
194
data-test-ai-assistant-message
202
195
...attributes
203
196
>
@@ -237,11 +230,21 @@ export default class AiAssistantMessage extends Component<Signature> {
237
230
{{/if }}
238
231
239
232
<div class =' content' data-test-ai-message-content >
240
- {{if
241
- ( and @ isFromAssistant @ isStreaming)
242
- ( wrapLastTextNodeInStreamingTextSpan @ formattedMessage)
243
- @ formattedMessage
244
- }}
233
+ {{#if ( and @ isFromAssistant @ isStreaming) }}
234
+ <FormattedMessage
235
+ @ renderCodeBlocks ={{ false }}
236
+ @ monacoSDK ={{@ monacoSDK }}
237
+ @ sanitizedHtml ={{wrapLastTextNodeInStreamingTextSpan
238
+ @ formattedMessage
239
+ }}
240
+ />
241
+ {{else }}
242
+ <FormattedMessage
243
+ @ renderCodeBlocks ={{ true }}
244
+ @ monacoSDK ={{@ monacoSDK }}
245
+ @ sanitizedHtml ={{@ formattedMessage }}
246
+ />
247
+ {{/if }}
245
248
246
249
{{ yield }}
247
250
@@ -344,7 +347,17 @@ export default class AiAssistantMessage extends Component<Signature> {
344
347
letter-spacing : var (--boxel-lsp-xs );
345
348
padding : var (--ai-assistant-message-padding , var (--boxel-sp ));
346
349
}
350
+
351
+ .content :deep(.message ) {
352
+ padding : 0 ;
353
+ }
354
+
355
+ .is-from-assistant .content :deep(.message ) {
356
+ padding : var (--ai-assistant-message-padding , var (--boxel-sp ));
357
+ }
358
+
347
359
.is-from-assistant .content {
360
+ padding : 0 ;
348
361
background-color : var (--ai-bot-message-background-color );
349
362
color : var (--boxel-light );
350
363
/* the below font-smoothing options are only recommended for light-colored
@@ -437,84 +450,9 @@ export default class AiAssistantMessage extends Component<Signature> {
437
450
flex-wrap : wrap ;
438
451
gap : var (--boxel-sp-xxs );
439
452
}
440
-
441
- :deep(.preview-code ) {
442
- --spacing : var (--boxel-sp-sm );
443
- --fill-container-spacing : calc (
444
- -1 * var (--ai-assistant-message-padding )
445
- );
446
- margin : var (--boxel-sp ) var (--fill-container-spacing ) 0
447
- var (--fill-container-spacing );
448
- padding : var (--spacing ) 0 ;
449
- background-color : var (--boxel-dark );
450
- }
451
-
452
- :deep(.preview-code.code-block ) {
453
- position : relative ;
454
- padding-top : var (--boxel-sp-xxxl );
455
- }
456
-
457
- :deep(.monaco-container ) {
458
- height : var (--monaco-container-height );
459
- min-height : 7rem ;
460
- max-height : 30vh ;
461
- }
462
-
463
- /*
464
- This filter is a best-effort approximation of a good looking dark theme that is a function of the white theme that
465
- we use for code previews in the AI panel. While Monaco editor does support multiple themes, it does not support
466
- monaco instances with different themes *on the same page*. This is why we are using a filter to approximate the
467
- dark theme. More details here: https://github.com/Microsoft/monaco-editor/issues/338 (monaco uses global style tags
468
- with hardcoded colors; any instance will override the global style tag, making all code editors look the same,
469
- effectively disabling multiple themes to be used on the same page)
470
- */
471
- :global(.preview-code .monaco-editor ) {
472
- filter : invert (1 ) hue-rotate (151deg ) brightness (0.8 ) grayscale (0.1 );
473
- }
474
-
475
- /* we are cribbing the boxel-ui style here as we have a rather
476
- awkward way that we insert the copy button */
477
- :deep(.code-copy-button ) {
478
- --spacing : calc (1rem / 1.333 );
479
-
480
- position : absolute ;
481
- top : var (--boxel-sp );
482
- left : var (--boxel-sp-lg );
483
- color : var (--boxel-highlight );
484
- background : none ;
485
- border : none ;
486
- font : 600 var (--boxel-font-xs );
487
- padding : 0 ;
488
- margin-bottom : var (--spacing );
489
- display : grid ;
490
- grid-template-columns : auto 1fr ;
491
- gap : var (--spacing );
492
- letter-spacing : var (--boxel-lsp-xs );
493
- justify-content : center ;
494
- height : min-content ;
495
- align-items : center ;
496
- white-space : nowrap ;
497
- min-height : var (--boxel-button-min-height );
498
- min-width : var (--boxel-button-min-width , 5rem );
499
- }
500
- :deep(.code-copy-button .copy-text ) {
501
- color : transparent ;
502
- }
503
- :deep(.code-copy-button .copy-text :hover ) {
504
- color : var (--boxel-highlight );
505
- }
506
453
< /style >
507
454
</template >
508
455
509
- editorDisplayOptions: MonacoEditorOptions = {
510
- wordWrap: ' on' ,
511
- wrappingIndent: ' indent' ,
512
- fontWeight: ' bold' ,
513
- scrollbar: {
514
- alwaysConsumeMouseWheel: false ,
515
- },
516
- };
517
-
518
456
private get isAvatarAnimated() {
519
457
return this .args .isStreaming && ! this .args .errorMessage ;
520
458
}
0 commit comments