Skip to content

Commit 53c0dbc

Browse files
committed
Merge branch 'cs-7853-add-ability-to-attach-code-you-are-looking-at-into-the-ai-assistant' into cs-7948-file-picker
2 parents 3db6ae3 + 38975cc commit 53c0dbc

File tree

22 files changed

+558
-377
lines changed

22 files changed

+558
-377
lines changed

Diff for: packages/boxel-icons/src/icons/file-code.gts

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const IconComponent: TemplateOnlyComponent<Signature> = <template>
88
xmlns='http://www.w3.org/2000/svg'
99
width='24'
1010
height='24'
11-
fill='none'
11+
fill='var(--icon-color, #000)'
1212
stroke='currentColor'
1313
stroke-linecap='round'
1414
stroke-linejoin='round'

Diff for: packages/boxel-ui/addon/raw-icons/code-file.svg

-9
This file was deleted.

Diff for: packages/boxel-ui/addon/src/icons/code-file.gts

-23
This file was deleted.

Diff for: packages/host/app/components/ai-assistant/attachment-picker/index.gts

+56-52
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ import {
2121
chooseFile,
2222
} from '@cardstack/runtime-common';
2323

24-
import Pill from '@cardstack/host/components/pill';
25-
24+
import CardPill from '@cardstack/host/components/card-pill';
25+
import FilePill from '@cardstack/host/components/file-pill';
2626
import ENV from '@cardstack/host/config/environment';
2727

2828
import { type CardDef } from 'https://cardstack.com/base/card-api';
@@ -34,8 +34,8 @@ interface Signature {
3434
Element: HTMLDivElement;
3535
Args: {
3636
autoAttachedCards?: TrackedSet<CardDef>;
37-
autoAttachedFiles?: FileDef[];
3837
cardsToAttach: CardDef[] | undefined;
38+
autoAttachedFile?: FileDef;
3939
filesToAttach: FileDef[] | undefined;
4040
chooseCard: (card: CardDef) => void;
4141
removeCard: (card: CardDef) => void;
@@ -53,30 +53,51 @@ export default class AiAssistantAttachmentPicker extends Component<Signature> {
5353
<template>
5454
<div class='item-picker'>
5555
{{#each this.itemsToDisplay as |item|}}
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>
56+
{{#if (this.isCard item)}}
57+
{{#if (this.isAutoAttachedCard item)}}
58+
<Tooltip @placement='top'>
59+
<:trigger>
60+
<CardPill
61+
@card={{item}}
62+
@isAutoAttachedCard={{true}}
63+
@removeCard={{@removeCard}}
64+
/>
65+
</:trigger>
6566

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>
67+
<:content>
68+
{{#if (this.isAutoAttachedCard item)}}
69+
Topmost card is shared automatically
70+
{{/if}}
71+
</:content>
72+
</Tooltip>
73+
{{else}}
74+
<CardPill
75+
@card={{item}}
76+
@isAutoAttachedCard={{false}}
77+
@removeCard={{@removeCard}}
78+
/>
79+
{{/if}}
7480
{{else}}
75-
<Pill
76-
@item={{item}}
77-
@isAutoAttached={{false}}
78-
@remove={{this.removeItem}}
79-
/>
81+
{{#if (this.isAutoAttachedFile item)}}
82+
<Tooltip @placement='top'>
83+
<:trigger>
84+
<FilePill
85+
@file={{item}}
86+
@isAutoAttachedFile={{true}}
87+
@removeFile={{@removeFile}}
88+
/>
89+
</:trigger>
90+
<:content>
91+
Currently opened file is shared automatically
92+
</:content>
93+
</Tooltip>
94+
{{else}}
95+
<FilePill
96+
@file={{item}}
97+
@isAutoAttachedFile={{false}}
98+
@removeFile={{@removeFile}}
99+
/>
100+
{{/if}}
80101
{{/if}}
81102
{{/each}}
82103
{{#if
@@ -170,37 +191,29 @@ export default class AiAssistantAttachmentPicker extends Component<Signature> {
170191
};
171192

172193
private isAutoAttachedCard = (card: CardDef) => {
173-
if (this.args.autoAttachedCards === undefined) {
174-
return false;
175-
}
176-
return this.args.autoAttachedCards.has(card);
194+
return this.args.autoAttachedCards?.has(card);
177195
};
178196

179197
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);
198+
return this.args.autoAttachedFile?.sourceUrl === file.sourceUrl;
190199
};
191200

192201
private get items() {
193202
let cards = this.args.cardsToAttach ?? [];
194-
let files = this.args.filesToAttach ?? [];
203+
195204
if (this.args.autoAttachedCards) {
196205
cards = [...new Set([...this.args.autoAttachedCards, ...cards])];
197206
}
198207

199208
cards = cards.filter((card) => card.id); // Dont show new unsaved cards
200-
201-
if (this.args.autoAttachedFiles) {
202-
files = [...new Set([...this.args.autoAttachedFiles, ...files])];
209+
let files: FileDef[] = [];
210+
if (this.args.autoAttachedFile) {
211+
files = [...new Set([this.args.autoAttachedFile])];
203212
}
213+
if (this.args.filesToAttach) {
214+
files = [...files, ...this.args.filesToAttach];
215+
}
216+
204217
return [...cards, ...files];
205218
}
206219

@@ -244,13 +257,4 @@ export default class AiAssistantAttachmentPicker extends Component<Signature> {
244257
let chosenFile: FileDef | undefined = await chooseFile();
245258
return chosenFile;
246259
});
247-
248-
@action
249-
private removeItem(item: CardDef | FileDef) {
250-
if (isCardInstance(item)) {
251-
this.args.removeCard(item);
252-
} else {
253-
this.args.removeFile(item);
254-
}
255-
}
256260
}

Diff for: packages/host/app/components/ai-assistant/attachment-picker/usage.gts

+11-6
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export default class AiAssistantCardPickerUsage extends Component {
2020
cards: TrackedArray<CardDef> = new TrackedArray([]);
2121
@tracked maxNumberOfCards: number | undefined = undefined;
2222
@tracked autoAttachedCards?: TrackedSet<CardDef> = new TrackedSet();
23-
@tracked autoAttachedFiles: TrackedArray<FileDef> = new TrackedArray([]);
23+
@tracked autoAttachedFile?: FileDef | undefined;
2424
@tracked filesToAttach: TrackedArray<FileDef> = new TrackedArray([]);
2525

2626
@action chooseCard(card: CardDef) {
@@ -62,10 +62,10 @@ export default class AiAssistantCardPickerUsage extends Component {
6262
@removeCard={{this.removeCard}}
6363
@chooseFile={{this.chooseFile}}
6464
@removeFile={{this.removeFile}}
65-
@submode={{'interact'}}
6665
@maxNumberOfItemsToAttach={{this.maxNumberOfCards}}
67-
@autoAttachedFiles={{this.autoAttachedFiles}}
66+
@autoAttachedFile={{this.autoAttachedFile}}
6867
@filesToAttach={{this.filesToAttach}}
68+
@submode={{'interact'}}
6969
/>
7070
<CardCatalogModal />
7171
</:example>
@@ -81,9 +81,9 @@ export default class AiAssistantCardPickerUsage extends Component {
8181
@value={{this.autoAttachedCards}}
8282
/>
8383
<Args.Object
84-
@name='autoAttachedFiles'
85-
@description='An array of files automatically attached to the message.'
86-
@value={{this.autoAttachedFiles}}
84+
@name='autoAttachedFile'
85+
@description='A file automatically attached to the message.'
86+
@value={{this.autoAttachedFile}}
8787
/>
8888
<Args.Object
8989
@name='filesToAttach'
@@ -100,6 +100,11 @@ export default class AiAssistantCardPickerUsage extends Component {
100100
@description='Action to be taken when a card is removed'
101101
@value={{this.removeCard}}
102102
/>
103+
<Args.Action
104+
@name='removeFile'
105+
@description='Action to be taken when a file is removed'
106+
@value={{this.removeFile}}
107+
/>
103108
<Args.Number
104109
@name='maxNumberOfCards'
105110
@description='Maximum number of cards that can be added. If a value is not provided, there is no limit.'

Diff for: packages/host/app/components/ai-assistant/message/index.gts

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { Button } from '@cardstack/boxel-ui/components';
1414
import { and, cn } from '@cardstack/boxel-ui/helpers';
1515
import { FailureBordered } from '@cardstack/boxel-ui/icons';
1616

17-
import Pill from '@cardstack/host/components/pill';
17+
import CardPill from '@cardstack/host/components/card-pill';
1818

1919
import type CardService from '@cardstack/host/services/card-service';
2020

@@ -210,7 +210,7 @@ export default class AiAssistantMessage extends Component<Signature> {
210210
{{#if @resources.cards.length}}
211211
<div class='cards' data-test-message-cards>
212212
{{#each @resources.cards as |card|}}
213-
<Pill @item={{card}} />
213+
<CardPill @card={{card}} />
214214
{{/each}}
215215
</div>
216216
{{/if}}

0 commit comments

Comments
 (0)