Skip to content

Commit 044116c

Browse files
committed
add plugin selector on chat
1 parent b4bf11d commit 044116c

6 files changed

Lines changed: 43 additions & 3 deletions

File tree

app/components/chat.tsx

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import AutoIcon from "../icons/auto.svg";
3737
import BottomIcon from "../icons/bottom.svg";
3838
import StopIcon from "../icons/pause.svg";
3939
import RobotIcon from "../icons/robot.svg";
40+
import PluginIcon from "../icons/plugin.svg";
4041

4142
import {
4243
ChatMessage,
@@ -89,6 +90,7 @@ import {
8990
REQUEST_TIMEOUT_MS,
9091
UNFINISHED_INPUT,
9192
ServiceProvider,
93+
Plugin,
9294
} from "../constant";
9395
import { Avatar } from "./emoji";
9496
import { ContextPrompts, MaskAvatar, MaskConfig } from "./mask";
@@ -476,6 +478,7 @@ export function ChatActions(props: {
476478
return model?.displayName ?? "";
477479
}, [models, currentModel, currentProviderName]);
478480
const [showModelSelector, setShowModelSelector] = useState(false);
481+
const [showPluginSelector, setShowPluginSelector] = useState(false);
479482
const [showUploadImage, setShowUploadImage] = useState(false);
480483

481484
useEffect(() => {
@@ -620,6 +623,33 @@ export function ChatActions(props: {
620623
}}
621624
/>
622625
)}
626+
627+
<ChatAction
628+
onClick={() => setShowPluginSelector(true)}
629+
text={Locale.Plugin.Name}
630+
icon={<PluginIcon />}
631+
/>
632+
{showPluginSelector && (
633+
<Selector
634+
multiple
635+
defaultSelectedValue={chatStore.currentSession().mask?.plugin}
636+
items={[
637+
{
638+
title: Locale.Plugin.Artifact,
639+
value: Plugin.Artifact,
640+
},
641+
]}
642+
onClose={() => setShowPluginSelector(false)}
643+
onSelection={(s) => {
644+
if (s.length === 0) return;
645+
const plugin = s[0];
646+
chatStore.updateCurrentSession((session) => {
647+
session.mask.plugin = s;
648+
});
649+
showToast(plugin);
650+
}}
651+
/>
652+
)}
623653
</div>
624654
);
625655
}

app/components/ui-lib.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ export function Selector<T>(props: {
443443
subTitle?: string;
444444
value: T;
445445
}>;
446-
defaultSelectedValue?: T;
446+
defaultSelectedValue?: T[] | T;
447447
onSelection?: (selection: T[]) => void;
448448
onClose?: () => void;
449449
multiple?: boolean;
@@ -453,7 +453,10 @@ export function Selector<T>(props: {
453453
<div className={styles["selector-content"]}>
454454
<List>
455455
{props.items.map((item, i) => {
456-
const selected = props.defaultSelectedValue === item.value;
456+
// @ts-ignore
457+
const selected = props.multiple
458+
? props.defaultSelectedValue?.includes(item.value)
459+
: props.defaultSelectedValue === item.value;
457460
return (
458461
<ListItem
459462
className={styles["selector-item"]}

app/constant.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ export enum FileName {
5757
Prompts = "prompts.json",
5858
}
5959

60+
export enum Plugin {
61+
Artifact = "artifact",
62+
}
63+
6064
export enum StoreKey {
6165
Chat = "chat-next-web-store",
6266
Access = "access-control",

app/locales/cn.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,7 @@ const cn = {
450450
},
451451
Plugin: {
452452
Name: "插件",
453+
Artifact: "Artifact",
453454
},
454455
FineTuned: {
455456
Sysmessage: "你是一个助手",

app/locales/en.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,7 @@ const en: LocaleType = {
457457
},
458458
Plugin: {
459459
Name: "Plugin",
460+
Artifact: "Artifact",
460461
},
461462
FineTuned: {
462463
Sysmessage: "You are an assistant that",

app/store/mask.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { BUILTIN_MASKS } from "../masks";
22
import { getLang, Lang } from "../locales";
33
import { DEFAULT_TOPIC, ChatMessage } from "./chat";
44
import { ModelConfig, useAppConfig } from "./config";
5-
import { StoreKey } from "../constant";
5+
import { StoreKey, Plugin } from "../constant";
66
import { nanoid } from "nanoid";
77
import { createPersistStore } from "../utils/store";
88

@@ -17,6 +17,7 @@ export type Mask = {
1717
modelConfig: ModelConfig;
1818
lang: Lang;
1919
builtin: boolean;
20+
plugin?: Plugin[];
2021
};
2122

2223
export const DEFAULT_MASK_STATE = {

0 commit comments

Comments
 (0)