import type { Message } from 'ai'; import React, { type RefCallback, useState } from 'react'; import { ClientOnly } from 'remix-utils/client-only'; import { Menu } from '~/components/sidebar/Menu.client'; import { IconButton } from '~/components/ui/IconButton'; import { Workbench } from '~/components/workbench/Workbench.client'; import { classNames } from '~/utils/classNames'; import { Messages } from './Messages.client'; import { SendButton } from './SendButton.client'; import { TemplateSelector } from '~/components/workbench/TemplateSelector'; import { type TemplateName } from '~/utils/templates'; import styles from './BaseChat.module.scss'; interface BaseChatProps { textareaRef?: React.RefObject | undefined; messageRef?: RefCallback | undefined; scrollRef?: RefCallback | undefined; showChat?: boolean; chatStarted?: boolean; isStreaming?: boolean; messages?: Message[]; enhancingPrompt?: boolean; promptEnhanced?: boolean; input?: string; handleStop?: () => void; sendMessage?: (event: React.UIEvent, messageInput?: string) => void; handleInputChange?: (event: React.ChangeEvent) => void; enhancePrompt?: () => void; } const EXAMPLE_PROMPTS = [ { text: '使用 React 和 Tailwind 构建一个待办事项应用' }, { text: '使用 Astro 构建一个简单的博客' }, { text: '使用 Material UI 创建一个 cookie 同意表单' }, { text: '制作一个太空入侵者游戏' }, { text: '如何让一个 div 居中?' }, ]; const TEXTAREA_MIN_HEIGHT = 76; export const BaseChat = React.forwardRef( ( { textareaRef, messageRef, scrollRef, showChat = true, chatStarted = false, isStreaming = false, enhancingPrompt = false, promptEnhanced = false, messages, input = '', sendMessage, handleInputChange, enhancePrompt, handleStop, }, ref, ) => { const TEXTAREA_MAX_HEIGHT = chatStarted ? 400 : 200; const [selectedTemplate, setSelectedTemplate] = useState('basic'); const handleTemplateChange = async (templateName: TemplateName) => { setSelectedTemplate(templateName); try { console.log('templateName', templateName); // await workbenchStore.changeTemplate(templateName); } catch (error) { console.error('Failed to change template:', error); // 可以在这里添加错误处理,比如显示一个错误提示 } }; return (
{() => }
{!chatStarted && (

创意的起点

在几秒钟内将想法变为现实,或获取现有项目的帮助。

{/* */}
)}
{() => { return chatStarted ? ( ) : null; }}