import React, { useState } from 'react'; import { BackgroundEntryEditor } from './BackgroundEntryEditor'; import { ParseErrorEntryEditor } from './ParseErrorEntryEditor'; import { ReadEntryEditor } from './ReadEntryEditor'; import { ReasoningEntryEditor } from './ReasoningEntryEditor'; import { RepeatEntryEditor } from './RepeatEntryEditor'; import { SingleEntryEditor } from './SingleEntryEditor'; import { WriteEntryEditor } from './WriteEntryEditor'; const EntryTypes = { BACKGROUND: 'background', PARSE_ERROR: 'parse_error', READ_STDIN: 'read_stdin', REASONING: 'reasoning', REPEAT: 'repeat', SINGLE: 'single', WRITE: 'write' }; const EntryEditors = { [EntryTypes.BACKGROUND]: BackgroundEntryEditor, [EntryTypes.PARSE_ERROR]: ParseErrorEntryEditor, [EntryTypes.READ_STDIN]: ReadEntryEditor, [EntryTypes.REASONING]: ReasoningEntryEditor, [EntryTypes.REPEAT]: RepeatEntryEditor, [EntryTypes.SINGLE]: SingleEntryEditor, [EntryTypes.WRITE]: WriteEntryEditor }; export const MemoryEditor = ({ entries = [], onCreateEntry, onSaveEntry, onDeleteEntry, onResetEntry, onUpdateEntry }) => { const [showCreateDialog, setShowCreateDialog] = useState(false); const [selectedType, setSelectedType] = useState(EntryTypes.SINGLE); const handleCreate = (_id, entry) => { onCreateEntry(entry); setShowCreateDialog(false); }; const generateId = () => { const now = new Date(); return now.getFullYear() + String(now.getMonth() + 1).padStart(2, '0') + String(now.getDate()).padStart(2, '0') + '_' + String(now.getHours()).padStart(2, '0') + String(now.getMinutes()).padStart(2, '0') + String(now.getSeconds()).padStart(2, '0') + '_' + String(now.getMilliseconds()).padStart(3, '0'); }; const getInitialEntry = (type) => { const baseEntry = { type: type, id: generateId() }; switch (type) { case EntryTypes.BACKGROUND: case EntryTypes.REPEAT: case EntryTypes.SINGLE: return { ...baseEntry, script: '', timeout: null, limit: null }; case EntryTypes.PARSE_ERROR: return { ...baseEntry, content: '', error: '' }; case EntryTypes.READ_STDIN: return { ...baseEntry, content: '', read: false }; case EntryTypes.REASONING: return { ...baseEntry, content: '' }; case EntryTypes.WRITE: return { ...baseEntry, content: '', written: false }; default: return baseEntry; } }; const renderCreateDialog = () => { const EditorComponent = EntryEditors[selectedType]; const entry = getInitialEntry(selectedType); return (

Create New Entry

setShowCreateDialog(false)} />
); }; const renderEntry = (entry) => { const EditorComponent = EntryEditors[entry.type]; if (!EditorComponent) { console.warn(`Unknown entry type: ${entry.type}`); return null; } return ( ); }; return (
{entries.map(renderEntry)}
{showCreateDialog && renderCreateDialog()}
); }; export default MemoryEditor;