Skip to content

Commit 83865db

Browse files
committed
feat(core): workspace embedding settings
1 parent a5ed05b commit 83865db

File tree

21 files changed

+1144
-22
lines changed

21 files changed

+1144
-22
lines changed
Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
import {
2+
ImageIcon,
3+
FileIconJpegIcon,
4+
FileIconPngIcon,
5+
FileIconWebpIcon,
6+
FileIconTiffIcon,
7+
FileIconGifIcon,
8+
FileIconSvgIcon,
9+
FileIconEpsIcon,
10+
FileIconPdfIcon,
11+
FileIconDocxIcon,
12+
FileIconTxtIcon,
13+
FileIconCsvIcon,
14+
FileIconDocIcon,
15+
FileIconXlsIcon,
16+
FileIconXlsxIcon,
17+
FileIconPptIcon,
18+
FileIconPptxIcon,
19+
FileIconAiIcon,
20+
FileIconPsdIcon,
21+
FileIconInddIcon,
22+
FileIconAepIcon,
23+
FileIconFigIcon,
24+
FileIconMp3Icon,
25+
FileIconWavIcon,
26+
FileIconMpegIcon,
27+
FileIconAviIcon,
28+
FileIconMp4Icon,
29+
FileIconMkvIcon,
30+
FileIconHtmlIcon,
31+
FileIconRssIcon,
32+
FileIconSqlIcon,
33+
FileIconJsIcon,
34+
FileIconCssIcon,
35+
FileIconJavaIcon,
36+
FileIconXmlIcon,
37+
FileIconDmgIcon,
38+
FileIconZipIcon,
39+
FileIconRarIcon,
40+
FileIconExeIcon,
41+
FileIconJsonIcon,
42+
FileIconNoneIcon,
43+
} from '@blocksuite/icons/rc';
44+
45+
export function getAttachmentFileIconRC(filetype: string) {
46+
switch (filetype) {
47+
case 'img':
48+
return ImageIcon;
49+
case 'image/jpeg':
50+
case 'jpg':
51+
case 'jpeg':
52+
return FileIconJpegIcon;
53+
case 'image/png':
54+
case 'png':
55+
return FileIconPngIcon;
56+
case 'image/webp':
57+
case 'webp':
58+
return FileIconWebpIcon;
59+
case 'image/tiff':
60+
case 'tiff':
61+
return FileIconTiffIcon;
62+
case 'image/gif':
63+
case 'gif':
64+
return FileIconGifIcon;
65+
case 'image/svg':
66+
case 'svg':
67+
return FileIconSvgIcon;
68+
case 'image/eps':
69+
case 'eps':
70+
return FileIconEpsIcon;
71+
case 'application/pdf':
72+
case 'pdf':
73+
return FileIconPdfIcon;
74+
case 'application/msword':
75+
case 'application/x-iwork-pages-sffpages':
76+
case 'doc':
77+
return FileIconDocIcon;
78+
case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document':
79+
case 'docx':
80+
return FileIconDocxIcon;
81+
case 'text/plain':
82+
case 'txt':
83+
return FileIconTxtIcon;
84+
case 'csv':
85+
return FileIconCsvIcon;
86+
case 'application/vnd.ms-excel':
87+
case 'xls':
88+
return FileIconXlsIcon;
89+
case 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet':
90+
case 'application/x-iwork-numbers-sffnumbers':
91+
case 'xlsx':
92+
return FileIconXlsxIcon;
93+
case 'application/vnd.ms-powerpoint':
94+
case 'application/x-iwork-keynote-sffkeynote':
95+
case 'ppt':
96+
return FileIconPptIcon;
97+
case 'application/vnd.openxmlformats-officedocument.presentationml.presentation':
98+
case 'pptx':
99+
return FileIconPptxIcon;
100+
case 'application/illustrator':
101+
case 'fig':
102+
return FileIconFigIcon;
103+
case 'application/postscript':
104+
case 'ai':
105+
return FileIconAiIcon;
106+
case 'application/vnd.adobe.photoshop':
107+
case 'psd':
108+
return FileIconPsdIcon;
109+
case 'application/vnd.adobe.indesign':
110+
case 'indd':
111+
return FileIconInddIcon;
112+
case 'application/vnd.adobe.afterfx':
113+
case 'aep':
114+
return FileIconAepIcon;
115+
case 'audio/mpeg':
116+
case 'audio/mp3':
117+
case 'mp3':
118+
return FileIconMp3Icon;
119+
case 'audio/wav':
120+
case 'wav':
121+
return FileIconWavIcon;
122+
case 'video/mpeg':
123+
case 'video/mp4':
124+
case 'mp4':
125+
return FileIconMp4Icon;
126+
case 'video/mpeg':
127+
case 'mpeg':
128+
return FileIconMpegIcon;
129+
case 'video/avi':
130+
case 'avi':
131+
return FileIconAviIcon;
132+
case 'video/mkv':
133+
case 'mkv':
134+
return FileIconMkvIcon;
135+
case 'text/html':
136+
case 'html':
137+
return FileIconHtmlIcon;
138+
case 'text/css':
139+
case 'css':
140+
return FileIconCssIcon;
141+
case 'application/rss+xml':
142+
case 'rss':
143+
return FileIconRssIcon;
144+
case 'application/sql':
145+
case 'sql':
146+
return FileIconSqlIcon;
147+
case 'application/javascript':
148+
case 'js':
149+
return FileIconJsIcon;
150+
case 'application/json':
151+
case 'json':
152+
return FileIconJsonIcon;
153+
case 'application/java':
154+
case 'java':
155+
return FileIconJavaIcon;
156+
case 'application/xml':
157+
case 'xml':
158+
return FileIconXmlIcon;
159+
case 'application/x-msdos-program':
160+
case 'exe':
161+
return FileIconExeIcon;
162+
case 'application/x-apple-diskimage':
163+
case 'dmg':
164+
return FileIconDmgIcon;
165+
case 'application/zip':
166+
case 'zip':
167+
return FileIconZipIcon;
168+
case 'application/x-rar-compressed':
169+
case 'rar':
170+
return FileIconRarIcon;
171+
default:
172+
return FileIconNoneIcon;
173+
}
174+
}

blocksuite/affine/components/src/icons/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export * from './ai.js';
22
export * from './file-icons.js';
3+
export * from './file-icons-rc.js';
34
export * from './import-export.js';
45
export * from './list.js';
56
export * from './misc.js';

packages/frontend/component/src/components/setting-components/setting-row.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { settingRow } from './share.css';
55

66
export type SettingRowProps = PropsWithChildren<{
77
name: ReactNode;
8-
desc: ReactNode;
8+
desc?: ReactNode;
99
style?: CSSProperties;
1010
onClick?: () => void;
1111
spreadCol?: boolean;
@@ -41,7 +41,7 @@ export const SettingRow = ({
4141
>
4242
<div className="left-col">
4343
<div className="name">{name}</div>
44-
<div className="desc">{desc}</div>
44+
{desc && <div className="desc">{desc}</div>}
4545
</div>
4646
{spreadCol ? <div className="right-col">{children}</div> : children}
4747
</div>

packages/frontend/component/src/components/setting-components/wrapper.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,22 @@ interface SettingWrapperProps {
77
id?: string;
88
title?: ReactNode;
99
disabled?: boolean;
10+
testId?: string;
1011
}
1112

1213
export const SettingWrapper = ({
1314
id,
1415
title,
1516
children,
1617
disabled,
18+
testId,
1719
}: PropsWithChildren<SettingWrapperProps>) => {
1820
return (
19-
<div id={id} className={clsx(wrapper, disabled && wrapperDisabled)}>
21+
<div
22+
id={id}
23+
className={clsx(wrapper, disabled && wrapperDisabled)}
24+
data-testid={testId}
25+
>
2026
{title ? <div className="title">{title}</div> : null}
2127
{children}
2228
</div>

packages/frontend/core/src/blocksuite/ai/components/ai-chat-input/ai-chat-input.ts

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -627,9 +627,6 @@ export class AIChatInput extends SignalWatcher(WithDisposable(LitElement)) {
627627

628628
private async _getMatchedContexts(userInput: string) {
629629
const contextId = await this.getContextId();
630-
if (!contextId) {
631-
return { files: [], docs: [] };
632-
}
633630

634631
const docContexts = new Map<
635632
string,
@@ -641,7 +638,7 @@ export class AIChatInput extends SignalWatcher(WithDisposable(LitElement)) {
641638
>();
642639

643640
const { files: matchedFiles = [], docs: matchedDocs = [] } =
644-
(await AIProvider.context?.matchContext(contextId, userInput)) ?? {};
641+
(await AIProvider.context?.matchContext(userInput, contextId)) ?? {};
645642

646643
matchedDocs.forEach(doc => {
647644
docContexts.set(doc.docId, {
@@ -655,17 +652,12 @@ export class AIChatInput extends SignalWatcher(WithDisposable(LitElement)) {
655652
if (context) {
656653
context.fileContent += `\n${file.content}`;
657654
} else {
658-
const fileChip = this.chips.find(
659-
chip => isFileChip(chip) && chip.fileId === file.fileId
660-
) as FileChip | undefined;
661-
if (fileChip && fileChip.blobId) {
662-
fileContexts.set(file.fileId, {
663-
blobId: fileChip.blobId,
664-
fileName: fileChip.file.name,
665-
fileType: fileChip.file.type,
666-
fileContent: file.content,
667-
});
668-
}
655+
fileContexts.set(file.fileId, {
656+
blobId: file.blobId,
657+
fileName: file.name,
658+
fileType: file.type,
659+
fileContent: file.content,
660+
});
669661
}
670662
});
671663

packages/frontend/core/src/blocksuite/ai/provider/copilot-client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ export class CopilotClient {
333333
return res.currentUser?.copilot?.contexts?.[0];
334334
}
335335

336-
async matchContext(contextId: string, content: string, limit?: number) {
336+
async matchContext(content: string, contextId?: string, limit?: number) {
337337
const res = await this.gql({
338338
query: matchContextQuery,
339339
variables: {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const COUNT_PER_PAGE = 10;

0 commit comments

Comments
 (0)