Spaces:
Sleeping
Sleeping
Download frontend/src/components/MemoryEditor.tsx from ilyaRozhkovA/LAMPSUI: direct link, hf CLI and curl.
- Browser
- Download file 3.22 kB
-
https://huggingface.co/spaces/ilyaRozhkovA/LAMPSUI/resolve/main/frontend/src/components/MemoryEditor.tsx
- Command line
-
hf download hf://spaces/ilyaRozhkovA/LAMPSUI/frontend/src/components/MemoryEditor.tsx
-
curl -L -o MemoryEditor.tsx https://huggingface.co/spaces/ilyaRozhkovA/LAMPSUI/resolve/main/frontend/src/components/MemoryEditor.tsx
3.22 kB
| import { useEffect, useState } from "react"; | |
| import { | |
| Modal, | |
| Stack, | |
| Textarea, | |
| Group, | |
| Button, | |
| Alert, | |
| Text, | |
| } from "@mantine/core"; | |
| import { IconAlertTriangle } from "@tabler/icons-react"; | |
| import { notifications } from "@mantine/notifications"; | |
| import { getMemory, putMemory } from "../api"; | |
| interface Props { | |
| opened: boolean; | |
| onClose: () => void; | |
| } | |
| export function MemoryEditor({ opened, onClose }: Props) { | |
| const [content, setContent] = useState(""); | |
| const [original, setOriginal] = useState(""); | |
| const [loading, setLoading] = useState(false); | |
| const [saving, setSaving] = useState(false); | |
| useEffect(() => { | |
| if (!opened) return; | |
| setLoading(true); | |
| getMemory() | |
| .then((c) => { | |
| setContent(c); | |
| setOriginal(c); | |
| }) | |
| .catch((e) => | |
| notifications.show({ | |
| title: "Could not load memory", | |
| message: String(e), | |
| color: "red", | |
| }) | |
| ) | |
| .finally(() => setLoading(false)); | |
| }, [opened]); | |
| const dirty = content !== original; | |
| async function onSave() { | |
| setSaving(true); | |
| try { | |
| await putMemory(content); | |
| setOriginal(content); | |
| notifications.show({ | |
| title: "Memory saved", | |
| message: `${content.length} characters written to /work/agent_memory.md`, | |
| color: "teal", | |
| }); | |
| } catch (e) { | |
| notifications.show({ | |
| title: "Save failed", | |
| message: String(e), | |
| color: "red", | |
| }); | |
| } finally { | |
| setSaving(false); | |
| } | |
| } | |
| return ( | |
| <Modal | |
| opened={opened} | |
| onClose={onClose} | |
| title="Agent memory" | |
| size="xl" | |
| centered | |
| > | |
| <Stack gap="sm"> | |
| <Alert | |
| variant="light" | |
| color="yellow" | |
| icon={<IconAlertTriangle size={16} />} | |
| title="Edit at your own risk" | |
| > | |
| The agent reads this file at the start of every conversation and | |
| updates it on its own when it learns something new. Hand-editing is | |
| fine — but if you delete relevant context here, the agent will not | |
| know about it next time. Avoid wiping the whole file unless you want | |
| to reset the agent's memory. | |
| </Alert> | |
| <Textarea | |
| value={content} | |
| onChange={(e) => setContent(e.currentTarget.value)} | |
| autosize | |
| minRows={20} | |
| maxRows={32} | |
| placeholder={loading ? "Loading…" : "(empty)"} | |
| styles={{ | |
| input: { | |
| fontFamily: | |
| "ui-monospace, SFMono-Regular, Menlo, Consolas, monospace", | |
| fontSize: 12, | |
| }, | |
| }} | |
| /> | |
| <Group justify="space-between"> | |
| <Text size="xs" c="dimmed"> | |
| {content.length} chars · {dirty ? "unsaved changes" : "in sync"} | |
| </Text> | |
| <Group gap="xs"> | |
| <Button | |
| variant="default" | |
| onClick={() => setContent(original)} | |
| disabled={!dirty} | |
| > | |
| Revert | |
| </Button> | |
| <Button onClick={onSave} disabled={!dirty} loading={saving}> | |
| Save | |
| </Button> | |
| </Group> | |
| </Group> | |
| </Stack> | |
| </Modal> | |
| ); | |
| } | |