import { useStore } from '@nanostores/react'; import { AnimatePresence, motion } from 'framer-motion'; import { computed } from 'nanostores'; import { memo, useEffect, useRef, useState } from 'react'; import { createHighlighter, type BundledLanguage, type BundledTheme, type HighlighterGeneric } from 'shiki'; import type { ActionState } from '~/lib/runtime/action-runner'; import { workbenchStore } from '~/lib/stores/workbench'; import { classNames } from '~/utils/classNames'; import { cubicEasingFn } from '~/utils/easings'; import { WORK_DIR } from '~/utils/constants'; const highlighterOptions = { langs: ['shell'], themes: ['light-plus', 'dark-plus'], }; const shellHighlighter: HighlighterGeneric = import.meta.hot?.data.shellHighlighter ?? (await createHighlighter(highlighterOptions)); if (import.meta.hot) { import.meta.hot.data.shellHighlighter = shellHighlighter; } interface ArtifactProps { messageId: string; } export const Artifact = memo(({ messageId }: ArtifactProps) => { const userToggledActions = useRef(false); const [showActions, setShowActions] = useState(false); const artifacts = useStore(workbenchStore.artifacts); const artifact = artifacts[messageId]; const actions = useStore( computed(artifact.runner.actions, (actions) => { return Object.values(actions); }), ); const toggleActions = () => { userToggledActions.current = true; setShowActions(!showActions); }; useEffect(() => { if (actions.length && !showActions && !userToggledActions.current) { setShowActions(true); } }, [actions]); return (
{actions.length && (
)}
{showActions && actions.length > 0 && (
)}
); }); interface ShellCodeBlockProps { classsName?: string; code: string; } function ShellCodeBlock({ classsName, code }: ShellCodeBlockProps) { return (
); } interface ActionListProps { actions: ActionState[]; } const actionVariants = { hidden: { opacity: 0, y: 20 }, visible: { opacity: 1, y: 0 }, }; function openArtifactInWorkbench(filePath: any) { if (workbenchStore.currentView.get() !== 'code') { workbenchStore.currentView.set('code'); } workbenchStore.setSelectedFile(`${WORK_DIR}/${filePath}`); } const ActionList = memo(({ actions }: ActionListProps) => { return ( ); }); function getIconColor(status: ActionState['status']) { switch (status) { case 'pending': { return 'text-bolt-elements-textTertiary'; } case 'running': { return 'text-bolt-elements-loader-progress'; } case 'complete': { return 'text-bolt-elements-icon-success'; } case 'aborted': { return 'text-bolt-elements-textSecondary'; } case 'failed': { return 'text-bolt-elements-icon-error'; } default: { return undefined; } } }