@@ -23,6 +23,8 @@ import {
23
23
24
24
import Pill from ' @cardstack/host/components/pill' ;
25
25
26
+ import ENV from ' @cardstack/host/config/environment' ;
27
+
26
28
import { type CardDef } from ' https://cardstack.com/base/card-api' ;
27
29
import { type FileDef } from ' https://cardstack.com/base/file-api' ;
28
30
@@ -44,36 +46,37 @@ interface Signature {
44
46
};
45
47
}
46
48
49
+ const isAttachingFilesEnabled = ENV .featureFlags ?.ENABLE_ATTACHING_FILES ;
47
50
const MAX_ITEMS_TO_DISPLAY = 4 ;
48
51
49
52
export default class AiAssistantAttachmentPicker extends Component <Signature > {
50
53
<template >
51
54
<div class =' item-picker' >
52
55
{{#each this . itemsToDisplay as | item | }}
53
- {{#if ( this.isCard item ) }}
54
- {{# if ( this.isAutoAttachedCard item ) }}
55
- <Tooltip @ placement = ' top ' >
56
- <: trigger >
57
- < Pill
58
- @ item ={{item }}
59
- @ isAutoAttached ={{ true }}
60
- @ remove = {{ this .removeItem }}
61
- / >
62
- </ : trigger >
63
-
64
- < : content >
65
- {{# if ( this.isAutoAttachedCard item ) }}
66
- Topmost card is shared automatically
67
- {{/ if }}
68
- </ : content >
69
- </Tooltip >
70
- {{ else }}
71
- < Pill
72
- @ item = {{ item }}
73
- @ isAutoAttached ={{ false }}
74
- @ remove ={{this .removeItem }}
75
- />
76
- {{/ if }}
56
+ {{#if ( this.isAutoAttached item ) }}
57
+ < Tooltip @ placement = ' top ' >
58
+ <: trigger >
59
+ <Pill
60
+ @ item = {{ item }}
61
+ @ isAutoAttached ={{ true }}
62
+ @ remove ={{this .removeItem }}
63
+ />
64
+ </ : trigger >
65
+
66
+ < : content >
67
+ {{# if ( this.isAutoAttached item ) }}
68
+ Topmost
69
+ {{ if ( this.isCard item ) ' Card ' ' File ' }}
70
+ is shared automatically
71
+ {{/ if }}
72
+ </: content >
73
+ </ Tooltip >
74
+ {{ else }}
75
+ < Pill
76
+ @ item ={{item }}
77
+ @ isAutoAttached ={{ false }}
78
+ @ remove = {{ this .removeItem }}
79
+ />
77
80
{{/if }}
78
81
{{/each }}
79
82
{{#if
@@ -91,7 +94,7 @@ export default class AiAssistantAttachmentPicker extends Component<Signature> {
91
94
</BoxelPill >
92
95
{{/if }}
93
96
{{#if this . canDisplayAddButton }}
94
- {{#if ( eq @ submode ' code' ) }}
97
+ {{#if ( and ( eq @ submode ' code' ) isAttachingFilesEnabled ) }}
95
98
<AddButton
96
99
class ={{cn ' attach-button' icon-only =this . itemsToDisplay.length}}
97
100
@ variant =' pill'
@@ -162,17 +165,30 @@ export default class AiAssistantAttachmentPicker extends Component<Signature> {
162
165
this .areAllItemsDisplayed = ! this .areAllItemsDisplayed ;
163
166
}
164
167
165
- isCard = (item : CardDef | FileDef ): item is CardDef => {
168
+ private isCard = (item : CardDef | FileDef ): item is CardDef => {
166
169
return isCardInstance (item );
167
170
};
168
171
169
- isAutoAttachedCard = (card : CardDef ) => {
172
+ private isAutoAttachedCard = (card : CardDef ) => {
170
173
if (this .args .autoAttachedCards === undefined ) {
171
174
return false ;
172
175
}
173
176
return this .args .autoAttachedCards .has (card );
174
177
};
175
178
179
+ private isAutoAttachedFile = (file : FileDef ) => {
180
+ if (this .args .autoAttachedFiles === undefined ) {
181
+ return false ;
182
+ }
183
+ return this .args .autoAttachedFiles .includes (file );
184
+ };
185
+
186
+ private isAutoAttached = (item : CardDef | FileDef ) => {
187
+ return this .isCard (item )
188
+ ? this .isAutoAttachedCard (item )
189
+ : this .isAutoAttachedFile (item );
190
+ };
191
+
176
192
private get items() {
177
193
let cards = this .args .cardsToAttach ?? [];
178
194
let files = this .args .filesToAttach ?? [];
@@ -231,7 +247,7 @@ export default class AiAssistantAttachmentPicker extends Component<Signature> {
231
247
232
248
@action
233
249
private removeItem(item : CardDef | FileDef ) {
234
- if (cardApi (item )) {
250
+ if (isCardInstance (item )) {
235
251
this .args .removeCard (item );
236
252
} else {
237
253
this .args .removeFile (item );
0 commit comments