diff --git a/client/src/components/Artifacts/Artifact.tsx b/client/src/components/Artifacts/Artifact.tsx index 4612e93580..45e017e207 100644 --- a/client/src/components/Artifacts/Artifact.tsx +++ b/client/src/components/Artifacts/Artifact.tsx @@ -55,7 +55,6 @@ export function Artifact({ const updateArtifact = useCallback(() => { const content = extractContent(props.children); - console.log('Content:', content); const title = props.title ?? 'Untitled Artifact'; const type = props.type ?? 'unknown'; @@ -94,8 +93,6 @@ export function Artifact({ setArtifact(currentArtifact); }); - - console.log('Artifact updated:', artifactKey); }, [props.children, props.title, props.type, props.identifier, setArtifacts, setArtifactIds]); useEffect(() => { diff --git a/client/src/components/Artifacts/Artifacts.tsx b/client/src/components/Artifacts/Artifacts.tsx index 35b0f465cf..161919fda2 100644 --- a/client/src/components/Artifacts/Artifacts.tsx +++ b/client/src/components/Artifacts/Artifacts.tsx @@ -4,8 +4,15 @@ import * as Tabs from '@radix-ui/react-tabs'; import { Sandpack } from '@codesandbox/sandpack-react'; import { removeNullishValues } from 'librechat-data-provider'; import { SandpackPreview, SandpackProvider } from '@codesandbox/sandpack-react/unstyled'; -import { sharedOptions, sharedFiles, sharedProps, getArtifactFilename } from '~/utils/artifacts'; import type { Artifact } from '~/common'; +import { + sharedFiles, + sharedProps, + sharedOptions, + getFileExtension, + getArtifactFilename, +} from '~/utils/artifacts'; +import { CodeMarkdown } from './Code'; import store from '~/store'; export function ArtifactPreview({ @@ -53,8 +60,8 @@ export function ArtifactPreview({ export default function Artifacts() { const [activeTab, setActiveTab] = useState('code'); - const artifactIds = useRecoilValue(store.artifactIdsState); const artifacts = useRecoilValue(store.artifactsState); + const artifactIds = useRecoilValue(store.artifactIdsState); const [currentArtifactIndex, setCurrentArtifactIndex] = useState(artifactIds.length - 1); @@ -82,7 +89,9 @@ export default function Artifacts() { return ( + {/* Main Parent */}
+ {/* Main Container */}
{/* Header */}
@@ -128,12 +137,13 @@ export default function Artifacts() {
- {/* Content */} - -
-              {currentArtifact.content}
-            
+ + diff --git a/client/src/components/Artifacts/Code.tsx b/client/src/components/Artifacts/Code.tsx index 9cc9c17b20..f2234101a2 100644 --- a/client/src/components/Artifacts/Code.tsx +++ b/client/src/components/Artifacts/Code.tsx @@ -1,74 +1,23 @@ -import React, { useRef, useState, RefObject, memo, useEffect } from 'react'; - -import copy from 'copy-to-clipboard'; +import React, { useRef, RefObject, memo } from 'react'; import rehypeKatex from 'rehype-katex'; import ReactMarkdown from 'react-markdown'; -import type { PluggableList } from 'unified'; import rehypeHighlight from 'rehype-highlight'; -import { useDebounceCodeBlock } from './useDebounceCodeBlock'; import { handleDoubleClick, cn, langSubset } from '~/utils'; -import Clipboard from '~/components/svg/Clipboard'; -import CheckMark from '~/components/svg/CheckMark'; -import useLocalize from '~/hooks/useLocalize'; -import CodePreview from './CodePreview'; type CodeBarProps = { lang: string; codeRef: RefObject; }; -interface CodeBlockArtifactProps { - lang: string; - codeString: string; - artifactId: string; -} type CodeBlockProps = Pick & { codeChildren: React.ReactNode; classProp?: string; }; -const CodeBar: React.FC = React.memo(({ lang, codeRef }) => { - const localize = useLocalize(); - const [isCopied, setIsCopied] = useState(false); - return ( -
- {lang} - -
- ); -}); - const CodeBlock: React.FC = ({ lang, codeChildren, classProp = '' }) => { const codeRef = useRef(null); return (
-
{codeChildren} @@ -101,17 +50,9 @@ export const code: React.ElementType = memo(({ inline, className, children }: TC const cursor = ' '; export const CodeMarkdown = memo( - ({ - content = '', - showCursor, - isLatestMessage, - }: { - content: string; - showCursor?: boolean; - isLatestMessage: boolean; - }) => { + ({ content = '', showCursor }: { content: string; showCursor?: boolean }) => { const currentContent = content; - const rehypePlugins: PluggableList = [ + const rehypePlugins = [ [rehypeKatex, { output: 'mathml' }], [ rehypeHighlight, @@ -125,11 +66,16 @@ export const CodeMarkdown = memo( return ( - {isLatestMessage && showCursor === true ? currentContent + cursor : currentContent} + {showCursor === true ? currentContent + cursor : currentContent} ); }, diff --git a/client/src/utils/artifacts.ts b/client/src/utils/artifacts.ts index 4e914039f4..d95530431e 100644 --- a/client/src/utils/artifacts.ts +++ b/client/src/utils/artifacts.ts @@ -15,20 +15,20 @@ export function getArtifactFilename(type: string): string { return artifactFilename[type] ?? 'App.tsx'; } -export function getFileExtension(language: string): string { +export function getFileExtension(language?: string): string { switch (language) { - case 'javascript': - return 'jsx'; - case 'typescript': + case 'application/vnd.react': return 'tsx'; - case 'jsx': - return 'jsx'; - case 'tsx': - return 'tsx'; - case 'html': + case 'text/html': return 'html'; - case 'css': - return 'css'; + // case 'jsx': + // return 'jsx'; + // case 'tsx': + // return 'tsx'; + // case 'html': + // return 'html'; + // case 'css': + // return 'css'; default: return 'txt'; } @@ -99,28 +99,3 @@ export const sharedFiles = { `, }; - -export const filenameMap = { - tsx: 'App', - css: 'styles', - html: 'index', - jsx: 'App', - js: 'App', - ts: 'App', - typescript: 'App', - javascript: 'App', -}; - -export const mapCodeFiles = ( - codeBlockIds: string[], - codeBlocks: Record, -) => { - return codeBlockIds.reduce((acc, id) => { - const block = codeBlocks[id]; - if (block) { - const fileName = `${filenameMap[block.language]}.${getFileExtension(block.language)}`; - acc[fileName] = typeof block.content === 'string' ? block.content : ''; - } - return acc; - }, {} as Record); -};