From caf50b6e6c7887587c7daa8fd83ad7b9d30ef98a Mon Sep 17 00:00:00 2001 From: lloydzhou Date: Thu, 5 Sep 2024 14:46:16 +0800 Subject: [PATCH] move artifacts into mask settings --- app/components/chat.tsx | 37 ++++++++++++------------------------- app/components/markdown.tsx | 7 +------ app/components/mask.tsx | 16 ++++++++++++++++ app/constant.ts | 4 ---- app/locales/cn.ts | 5 ++++- app/locales/en.ts | 5 ++++- app/store/mask.ts | 5 +++-- 7 files changed, 40 insertions(+), 39 deletions(-) diff --git a/app/components/chat.tsx b/app/components/chat.tsx index 4011858f6..e39bc74a9 100644 --- a/app/components/chat.tsx +++ b/app/components/chat.tsx @@ -98,7 +98,6 @@ import { REQUEST_TIMEOUT_MS, UNFINISHED_INPUT, ServiceProvider, - ArtifactsPlugin, } from "../constant"; import { Avatar } from "./emoji"; import { ContextPrompts, MaskAvatar, MaskConfig } from "./mask"; @@ -727,38 +726,26 @@ export function ChatActions(props: { /> )} - setShowPluginSelector(true)} - text={Locale.Plugin.Name} - icon={} - /> - {showPluginSelector && ( + {showPlugins(currentProviderName, currentModel) && ( + setShowPluginSelector(true)} + text={Locale.Plugin.Name} + icon={} + /> + )} + {showPluginSelector && showPlugins(currentProviderName, currentModel) && ( ({ - // @ts-ignore - title: `${item?.title}@${item?.version}`, - // @ts-ignore - value: item?.id, - })) - : [], - )} + items={pluginStore.getAll().map((item) => ({ + title: `${item?.title}@${item?.version}`, + value: item?.id, + }))} onClose={() => setShowPluginSelector(false)} onSelection={(s) => { chatStore.updateCurrentSession((session) => { session.mask.plugin = s as string[]; }); - if (s.includes(ArtifactsPlugin.Artifacts)) { - showToast(ArtifactsPlugin.Artifacts); - } }} /> )} diff --git a/app/components/markdown.tsx b/app/components/markdown.tsx index 58579ab47..4b9e608c9 100644 --- a/app/components/markdown.tsx +++ b/app/components/markdown.tsx @@ -19,7 +19,6 @@ import { HTMLPreview, HTMLPreviewHander, } from "./artifacts"; -import { ArtifactsPlugin } from "../constant"; import { useChatStore } from "../store"; import { IconButton } from "./button"; @@ -77,7 +76,6 @@ export function PreCode(props: { children: any }) { const { height } = useWindowSize(); const chatStore = useChatStore(); const session = chatStore.currentSession(); - const plugins = session.mask?.plugin; const renderArtifacts = useDebouncedCallback(() => { if (!ref.current) return; @@ -94,10 +92,7 @@ export function PreCode(props: { children: any }) { } }, 600); - const enableArtifacts = useMemo( - () => plugins?.includes(ArtifactsPlugin.Artifacts), - [plugins], - ); + const enableArtifacts = session.mask?.enableArtifacts !== false; //Wrap the paragraph for plain-text useEffect(() => { diff --git a/app/components/mask.tsx b/app/components/mask.tsx index 8c17a544a..78b89f260 100644 --- a/app/components/mask.tsx +++ b/app/components/mask.tsx @@ -167,6 +167,22 @@ export function MaskConfig(props: { > + + { + props.updateMask((mask) => { + mask.enableArtifacts = e.currentTarget.checked; + }); + }} + > + + {!props.shouldSyncFromGlobal ? ( `${count} 个插件`, @@ -604,6 +603,10 @@ const cn = { Title: "隐藏预设对话", SubTitle: "隐藏后预设对话不会出现在聊天界面", }, + Artifacts: { + Title: "启用Artifacts", + SubTitle: "启用之后可以直接渲染HTML页面", + }, Share: { Title: "分享此面具", SubTitle: "生成此面具的直达链接", diff --git a/app/locales/en.ts b/app/locales/en.ts index d2b27fdcd..13b3fe5e6 100644 --- a/app/locales/en.ts +++ b/app/locales/en.ts @@ -540,7 +540,6 @@ const en: LocaleType = { }, Plugin: { Name: "Plugin", - Artifacts: "Artifacts", Page: { Title: "Plugins", SubTitle: (count: number) => `${count} plugins`, @@ -613,6 +612,10 @@ const en: LocaleType = { Title: "Hide Context Prompts", SubTitle: "Do not show in-context prompts in chat", }, + Artifacts: { + Title: "Enable Artifacts", + SubTitle: "Can render HTML page when enable artifacts.", + }, Share: { Title: "Share This Mask", SubTitle: "Generate a link to this mask", diff --git a/app/store/mask.ts b/app/store/mask.ts index 05f511b0f..083121b65 100644 --- a/app/store/mask.ts +++ b/app/store/mask.ts @@ -2,7 +2,7 @@ import { BUILTIN_MASKS } from "../masks"; import { getLang, Lang } from "../locales"; import { DEFAULT_TOPIC, ChatMessage } from "./chat"; import { ModelConfig, useAppConfig } from "./config"; -import { StoreKey, ArtifactsPlugin } from "../constant"; +import { StoreKey } from "../constant"; import { nanoid } from "nanoid"; import { createPersistStore } from "../utils/store"; @@ -18,6 +18,7 @@ export type Mask = { lang: Lang; builtin: boolean; plugin?: string[]; + enableArtifacts?: boolean; }; export const DEFAULT_MASK_STATE = { @@ -38,7 +39,7 @@ export const createEmptyMask = () => lang: getLang(), builtin: false, createdAt: Date.now(), - plugin: [ArtifactsPlugin.Artifacts as string], + plugin: [], }) as Mask; export const useMaskStore = createPersistStore(