Skip to content

Commit

Permalink
move artifacts into mask settings
Browse files Browse the repository at this point in the history
  • Loading branch information
lloydzhou committed Sep 5, 2024
1 parent b590d08 commit caf50b6
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 39 deletions.
37 changes: 12 additions & 25 deletions app/components/chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ import {
REQUEST_TIMEOUT_MS,
UNFINISHED_INPUT,
ServiceProvider,
ArtifactsPlugin,
} from "../constant";
import { Avatar } from "./emoji";
import { ContextPrompts, MaskAvatar, MaskConfig } from "./mask";
Expand Down Expand Up @@ -727,38 +726,26 @@ export function ChatActions(props: {
/>
)}

<ChatAction
onClick={() => setShowPluginSelector(true)}
text={Locale.Plugin.Name}
icon={<PluginIcon />}
/>
{showPluginSelector && (
{showPlugins(currentProviderName, currentModel) && (
<ChatAction
onClick={() => setShowPluginSelector(true)}
text={Locale.Plugin.Name}
icon={<PluginIcon />}
/>
)}
{showPluginSelector && showPlugins(currentProviderName, currentModel) && (
<Selector
multiple
defaultSelectedValue={chatStore.currentSession().mask?.plugin}
items={[
{
title: Locale.Plugin.Artifacts,
value: ArtifactsPlugin.Artifacts as string,
},
].concat(
showPlugins(currentProviderName, currentModel)
? pluginStore.getAll().map((item) => ({
// @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);
}
}}
/>
)}
Expand Down
7 changes: 1 addition & 6 deletions app/components/markdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import {
HTMLPreview,
HTMLPreviewHander,
} from "./artifacts";
import { ArtifactsPlugin } from "../constant";
import { useChatStore } from "../store";
import { IconButton } from "./button";

Expand Down Expand Up @@ -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;
Expand All @@ -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(() => {
Expand Down
16 changes: 16 additions & 0 deletions app/components/mask.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,22 @@ export function MaskConfig(props: {
></input>
</ListItem>

<ListItem
title={Locale.Mask.Config.Artifacts.Title}
subTitle={Locale.Mask.Config.Artifacts.SubTitle}
>
<input
aria-label={Locale.Mask.Config.Artifacts.Title}
type="checkbox"
checked={props.mask.enableArtifacts}
onChange={(e) => {
props.updateMask((mask) => {
mask.enableArtifacts = e.currentTarget.checked;
});
}}
></input>
</ListItem>

{!props.shouldSyncFromGlobal ? (
<ListItem
title={Locale.Mask.Config.Share.Title}
Expand Down
4 changes: 0 additions & 4 deletions app/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,6 @@ export enum FileName {
Prompts = "prompts.json",
}

export enum ArtifactsPlugin {
Artifacts = "artifacts",
}

export enum StoreKey {
Chat = "chat-next-web-store",
Plugin = "chat-next-web-plugin",
Expand Down
5 changes: 4 additions & 1 deletion app/locales/cn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,6 @@ const cn = {
},
Plugin: {
Name: "插件",
Artifacts: "Artifacts",
Page: {
Title: "插件",
SubTitle: (count: number) => `${count} 个插件`,
Expand Down Expand Up @@ -604,6 +603,10 @@ const cn = {
Title: "隐藏预设对话",
SubTitle: "隐藏后预设对话不会出现在聊天界面",
},
Artifacts: {
Title: "启用Artifacts",
SubTitle: "启用之后可以直接渲染HTML页面",
},
Share: {
Title: "分享此面具",
SubTitle: "生成此面具的直达链接",
Expand Down
5 changes: 4 additions & 1 deletion app/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,6 @@ const en: LocaleType = {
},
Plugin: {
Name: "Plugin",
Artifacts: "Artifacts",
Page: {
Title: "Plugins",
SubTitle: (count: number) => `${count} plugins`,
Expand Down Expand Up @@ -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",
Expand Down
5 changes: 3 additions & 2 deletions app/store/mask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -18,6 +18,7 @@ export type Mask = {
lang: Lang;
builtin: boolean;
plugin?: string[];
enableArtifacts?: boolean;
};

export const DEFAULT_MASK_STATE = {
Expand All @@ -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(
Expand Down

0 comments on commit caf50b6

Please sign in to comment.