import { Button } from '@affine/admin/components/ui/button'; import { Separator } from '@affine/admin/components/ui/separator'; import type { CopilotPromptMessageRole } from '@affine/graphql'; import { useCallback, useState } from 'react'; import { useRightPanel } from '../layout'; import { DiscardChanges } from './discard-changes'; import { EditPrompt } from './edit-prompt'; import { usePrompt } from './use-prompt'; export type Prompt = { __typename?: 'CopilotPromptType'; name: string; model: string; action: string | null; config: { __typename?: 'CopilotPromptConfigType'; jsonMode: boolean | null; frequencyPenalty: number | null; presencePenalty: number | null; temperature: number | null; topP: number | null; } | null; messages: Array<{ __typename?: 'CopilotPromptMessageType'; role: CopilotPromptMessageRole; content: string; params: Record | null; }>; }; export function Prompts() { const { prompts: list } = usePrompt(); return (
Prompts
{list.map((item, index) => ( ))}
); } export const PromptRow = ({ item, index }: { item: Prompt; index: number }) => { const { setRightPanelContent, openPanel, isOpen } = useRightPanel(); const [dialogOpen, setDialogOpen] = useState(false); const handleDiscardChangesCancel = useCallback(() => { setDialogOpen(false); }, []); const handleConfirm = useCallback( (item: Prompt) => { setRightPanelContent(); if (dialogOpen) { handleDiscardChangesCancel(); } if (!isOpen) { openPanel(); } }, [ dialogOpen, handleDiscardChangesCancel, isOpen, openPanel, setRightPanelContent, ] ); const handleEdit = useCallback( (item: Prompt) => { if (isOpen) { setDialogOpen(true); } else { handleConfirm(item); } }, [handleConfirm, isOpen] ); return (
{index !== 0 && } handleConfirm(item)} />
); };