import { Button } from '@affine/admin/components/ui/button'; import { ScrollArea } from '@affine/admin/components/ui/scroll-area'; import { Separator } from '@affine/admin/components/ui/separator'; import { Textarea } from '@affine/admin/components/ui/textarea'; import { CheckIcon, XIcon } from 'lucide-react'; import { useCallback, useEffect, useMemo, useState } from 'react'; import { useRightPanel } from '../layout'; import type { Prompt } from './prompts'; import { usePrompt } from './use-prompt'; export function EditPrompt({ item }: { item: Prompt }) { const { closePanel } = useRightPanel(); const [messages, setMessages] = useState(item.messages); const { updatePrompt } = usePrompt(); const handleChange = useCallback( (e: React.ChangeEvent, index: number) => { const newMessages = [...messages]; newMessages[index] = { ...newMessages[index], content: e.target.value, }; setMessages(newMessages); }, [messages] ); const handleClose = useCallback(() => { setMessages(item.messages); closePanel(); }, [closePanel, item.messages]); const onConfirm = useCallback(() => { updatePrompt({ name: item.name, messages }); handleClose(); }, [handleClose, item.name, messages, updatePrompt]); const disableSave = useMemo( () => JSON.stringify(messages) === JSON.stringify(item.messages), [item.messages, messages] ); useEffect(() => { setMessages(item.messages); }, [item.messages]); return (
Edit Prompt
Name
{item.name}
{item.action ? (
Action
{item.action}
) : null}
Model
{item.model}
{item.config ? (
Config
{Object.entries(item.config).map(([key, value], index) => (
{index !== 0 && } {key} {value?.toString()}
))}
) : null}
Messages
{messages.map((message, index) => (
{index !== 0 && }
Role
{message.role}
{message.params ? (
Params
{Object.entries(message.params).map(([key, value], index) => (
{index !== 0 && } {key} {value.toString()}
))}
) : null}
Content