Skip to content

Agent Zero AI framework

fix: review refinements

Rafael Uzarowskia4ef83928f4b
diff --git a/python/api/memory_dashboard.py b/python/api/memory_dashboard.py
index 88579f09e..872bda89a 100644
--- a/python/api/memory_dashboard.py
+++ b/python/api/memory_dashboard.py
@@ -1,60 +1,269 @@
from python.helpers.api import ApiHandler, Request, Response
from python.helpers.memory import Memory
+from python.helpers import files
+from models import ModelConfig, ModelType
class MemoryDashboard(ApiHandler):
async def process(self, input: dict, request: Request) -> dict | Response:
try:
- # Get filter parameters
- area_filter = input.get("area", "") # Filter by memory area (MAIN, FRAGMENTS, SOLUTIONS, INSTRUMENTS)
- search_query = input.get("search", "") # Full-text search query
- limit = input.get("limit", 100) # Number of results to return
+ action = input.get("action", "search")
+ if action == "get_memory_subdirs":
+ return await self._get_memory_subdirs()
+ elif action == "get_current_memory_subdir":
+ return await self._get_current_memory_subdir(request)
+ elif action == "search":
+ return await self._search_memories(input)
+ elif action == "delete":
+ return await self._delete_memory(input)
+ elif action == "bulk_delete":
+ return await self._bulk_delete_memories(input)
+ else:
+ return {
+ "success": False,
+ "error": f"Unknown action: {action}",
+ "memories": [],
+ "total_count": 0
+ }
+
+ except Exception as e:
+ return {
+ "success": False,
+ "error": str(e),
+ "memories": [],
+ "total_count": 0
+ }
- # Get context and agent
- ctxid = input.get("context", "")
- context = self.get_context(ctxid)
+ async def _delete_memory(self, input: dict) -> dict:
+ """Delete a memory by ID from the specified subdirectory."""
+ try:
+ memory_subdir = input.get("memory_subdir", "default")
+ memory_id = input.get("memory_id")
- # Check if memory is already initialized to avoid triggering preload
- memory_subdir = context.agent0.config.memory_subdir or "default"
+ if not memory_id:
+ return {
+ "success": False,
+ "error": "Memory ID is required for deletion"
+ }
+
+ # Check if memory database exists
if Memory.index.get(memory_subdir) is None:
- # Memory not initialized yet, return empty results
+ return {
+ "success": False,
+ "error": f"Memory database '{memory_subdir}' not initialized"
+ }
+
+ # Get the MyFaiss database directly
+ myFaiss_db = Memory.index[memory_subdir]
+
+ # Delete the memory by ID (replicate logic from Memory.delete_documents_by_ids)
+ rem_docs = await myFaiss_db.aget_by_ids([memory_id])
+ if rem_docs:
+ rem_ids = [doc.metadata["id"] for doc in rem_docs]
+ await myFaiss_db.adelete(ids=rem_ids)
+ # Persist changes to disk
+ Memory._save_db_file(myFaiss_db, memory_subdir)
+ else:
+ return {
+ "success": False,
+ "error": f"Memory with ID '{memory_id}' not found"
+ }
+
+ return {
+ "success": True,
+ "message": f"Memory {memory_id} deleted successfully"
+ }
+
+ except Exception as e:
+ return {
+ "success": False,
+ "error": f"Failed to delete memory: {str(e)}"
+ }
+
+ async def _bulk_delete_memories(self, input: dict) -> dict:
+ """Delete multiple memories by IDs from the specified subdirectory."""
+ try:
+ memory_subdir = input.get("memory_subdir", "default")
+ memory_ids = input.get("memory_ids", [])
+
+ if not memory_ids:
+ return {
+ "success": False,
+ "error": "No memory IDs provided for bulk deletion"
+ }
+
+ if not isinstance(memory_ids, list):
+ return {
+ "success": False,
+ "error": "Memory IDs must be provided as a list"
+ }
+
+ # Check if memory database exists
+ if Memory.index.get(memory_subdir) is None:
+ return {
+ "success": False,
+ "error": f"Memory database '{memory_subdir}' not initialized"
+ }
+
+ # Get the MyFaiss database directly
+ myFaiss_db = Memory.index[memory_subdir]
+
+ # Delete memories in batch
+ deleted_count = 0
+ failed_ids = []
+
+ for memory_id in memory_ids:
+ try:
+ # Get memory to check if it exists
+ rem_docs = await myFaiss_db.aget_by_ids([memory_id])
+ if rem_docs:
+ rem_ids = [doc.metadata["id"] for doc in rem_docs]
+ await myFaiss_db.adelete(ids=rem_ids)
+ deleted_count += 1
+ else:
+ failed_ids.append(memory_id)
+ except Exception:
+ failed_ids.append(memory_id)
+
+ # Persist changes to disk if any deletions were successful
+ if deleted_count > 0:
+ Memory._save_db_file(myFaiss_db, memory_subdir)
+
+ if deleted_count == len(memory_ids):
return {
"success": True,
- "memories": [],
- "total_count": 0,
- "knowledge_count": 0,
- "conversation_count": 0,
- "areas_count": {},
- "search_query": search_query,
- "area_filter": area_filter,
- "message": "Memory database not yet initialized. Use the agent first to initialize memory."
+ "message": f"Successfully deleted {deleted_count} memories"
+ }
+ elif deleted_count > 0:
+ return {
+ "success": True,
+ "message": f"Successfully deleted {deleted_count} memories. {len(failed_ids)} failed: {failed_ids[:5]}"
+ }
+ else:
+ return {
+ "success": False,
+ "error": f"Failed to delete any memories. Not found: {failed_ids[:10]}"
+ }
+
+ except Exception as e:
+ return {
+ "success": False,
+ "error": f"Failed to bulk delete memories: {str(e)}"
+ }
+
+ async def _get_current_memory_subdir(self, request: Request) -> dict:
+ """Get the current memory subdirectory from the active context."""
+ try:
+ # Try to get the context from the request
+ context_id = getattr(request, 'context_id', None)
+ if not context_id:
+ # Fallback to default if no context available
+ return {
+ "success": True,
+ "memory_subdir": "default"
+ }
+
+ # Import AgentContext here to avoid circular imports
+ from agent import AgentContext
+
+ # Get the context and extract memory subdirectory
+ context = AgentContext.get(context_id)
+ if context and hasattr(context, 'config') and hasattr(context.config, 'memory_subdir'):
+ memory_subdir = context.config.memory_subdir or "default"
+ return {
+ "success": True,
+ "memory_subdir": memory_subdir
+ }
+ else:
+ return {
+ "success": True,
+ "memory_subdir": "default"
}
- # Get already initialized memory instance (no initialization triggered)
- db = Memory(
- agent=context.agent0,
- db=Memory.index[memory_subdir],
- memory_subdir=memory_subdir,
- )
+ except Exception:
+ return {
+ "success": True, # Still success, just fallback to default
+ "memory_subdir": "default"
+ }
+
+ async def _get_memory_subdirs(self) -> dict:
+ """Get available memory subdirectories."""
+ try:
+ # Get subdirectories from memory folder
+ subdirs = files.get_subdirectories("memory")
+
+ # Ensure 'default' is always available
+ if "default" not in subdirs:
+ subdirs.insert(0, "default")
+
+ return {
+ "success": True,
+ "subdirs": subdirs
+ }
+ except Exception as e:
+ return {
+ "success": False,
+ "error": f"Failed to get memory subdirectories: {str(e)}",
+ "subdirs": ["default"]
+ }
+
+ async def _search_memories(self, input: dict) -> dict:
+ """Search memories in the specified subdirectory."""
+ try:
+ # Get search parameters
+ memory_subdir = input.get("memory_subdir", "default")
+ area_filter = input.get("area", "") # Filter by memory area
+ search_query = input.get("search", "") # Full-text search query
+ limit = input.get("limit", 100) # Number of results to return
+
+ # Initialize memory if not already done
+ if Memory.index.get(memory_subdir) is None:
+ # Create default embeddings model config
+ embeddings_config = ModelConfig(
+ type=ModelType.EMBEDDING,
+ provider="huggingface",
+ name="sentence-transformers/all-MiniLM-L6-v2",
+ ctx_length=512,
+ limit_requests=0,
+ limit_input=0,
+ limit_output=0,
+ vision=False,
+ kwargs={}
+ )
+
+ # Initialize memory database (with log_item=None to prevent status blinking)
+ db, created = Memory.initialize(
+ log_item=None,
+ model_config=embeddings_config,
+ memory_subdir=memory_subdir,
+ in_memory=False
+ )
+
+ # Store in the Memory index
+ Memory.index[memory_subdir] = db
+
+ # Get the MyFaiss database directly
+ myFaiss_db = Memory.index[memory_subdir]
memories = []
if search_query:
# If search query provided, use similarity search
threshold = 0.6 # Lower threshold for broader search in dashboard
- filter_expr = f"area == '{area_filter}'" if area_filter else ""
+ comparator = Memory._get_comparator(f"area == '{area_filter}'") if area_filter else None
- docs = await db.search_similarity_threshold(
- query=search_query,
- limit=limit,
- threshold=threshold,
- filter=filter_expr
+ docs = await myFaiss_db.asearch(
+ search_query,
+ search_type="similarity_score_threshold",
+ k=limit,
+ score_threshold=threshold,
+ filter=comparator,
)
memories = docs
else:
# If no search query, get all memories from specified area(s)
- all_docs = db.db.get_all_docs()
+ all_docs = myFaiss_db.get_all_docs()
for doc_id, doc in all_docs.items():
# Apply area filter if specified
@@ -68,7 +277,7 @@ class MemoryDashboard(ApiHandler):
break
# Format memories for the dashboard
- formatted_memories = []
+ formatted_memories: list[dict] = []
for memory in memories:
metadata = memory.metadata
@@ -104,8 +313,8 @@ class MemoryDashboard(ApiHandler):
conversation_count = total_memories - knowledge_count
areas_count: dict[str, int] = {}
- for memory in formatted_memories:
- area = memory["area"]
+ for memory_dict in formatted_memories:
+ area = memory_dict["area"]
areas_count[area] = areas_count.get(area, 0) + 1
return {
@@ -116,7 +325,8 @@ class MemoryDashboard(ApiHandler):
"conversation_count": conversation_count,
"areas_count": areas_count,
"search_query": search_query,
- "area_filter": area_filter
+ "area_filter": area_filter,
+ "memory_subdir": memory_subdir
}
except Exception as e:
diff --git a/webui/components/settings/memory/memory-dashboard-store.js b/webui/components/settings/memory/memory-dashboard-store.js
index 1712b3c78..9763c7152 100644
--- a/webui/components/settings/memory/memory-dashboard-store.js
+++ b/webui/components/settings/memory/memory-dashboard-store.js
@@ -1,77 +1,215 @@
import { createStore } from "/js/AlpineStore.js";
import { getContext } from "/index.js";
import * as API from "/js/api.js";
+import { openModal, closeModal } from "/js/modals.js";
-const model = {
+// Memory Dashboard Store
+const memoryDashboardStore = {
+ // Data
memories: [],
- loading: true,
+ currentPage: 1,
+ itemsPerPage: 10,
+
+ // State
+ loading: false,
+ loadingSubdirs: false,
+ initializingMemory: false,
error: null,
+ message: null,
- // Filter states
- areaFilter: "",
+ // Memory subdirectories
+ memorySubdirs: [],
+ selectedMemorySubdir: "default",
+ memoryInitialized: {}, // Track which subdirs have been initialized
+
+ // Search and filters
searchQuery: "",
- currentPage: 1,
- itemsPerPage: 10,
+ areaFilter: "",
+ limit: parseInt(localStorage.getItem('memoryDashboard_limit') || '100'),
- // Statistics
+ // Stats
totalCount: 0,
knowledgeCount: 0,
conversationCount: 0,
areasCount: {},
- // UI state
- selectedMemory: null,
- showDetailModal: false,
- message: null, // For displaying initialization messages
+ // Memory detail modal (standard modal approach)
+ detailMemory: null,
+
+ // Polling
+ pollingInterval: null,
+ pollingEnabled: true,
async initialize() {
- await this.loadMemories();
+ // Reset state when opening (but keep directory from context)
+ this.currentPage = 1;
+ this.searchQuery = "";
+ this.areaFilter = "";
+
+ // Get current memory subdirectory from application context
+ await this.getCurrentMemorySubdir();
+
+ await this.loadMemorySubdirs();
+
+ // Automatically search with selected subdirectory
+ if (this.selectedMemorySubdir) {
+ await this.searchMemories();
+ }
+
+ // Start polling for live updates as soon as dashboard is open
+ this.startPolling();
},
- async loadMemories() {
- this.loading = true;
+ async getCurrentMemorySubdir() {
+ try {
+ // Try to get current memory subdirectory from the backend
+ const response = await API.callJsonApi("memory_dashboard", {
+ action: "get_current_memory_subdir"
+ });
+
+ if (response.success && response.memory_subdir) {
+ this.selectedMemorySubdir = response.memory_subdir;
+ } else {
+ // Fallback to default
+ this.selectedMemorySubdir = "default";
+ }
+ } catch (error) {
+ console.error("Failed to get current memory subdirectory:", error);
+ this.selectedMemorySubdir = "default";
+ }
+ },
+
+ async loadMemorySubdirs() {
+ this.loadingSubdirs = true;
this.error = null;
- this.message = null;
try {
const response = await API.callJsonApi("memory_dashboard", {
- context: getContext(),
+ action: "get_memory_subdirs"
+ });
+
+ if (response.success) {
+ let subdirs = response.subdirs || ["default"];
+
+ // Sort alphabetically but ensure "default" is always first
+ subdirs = subdirs.filter(dir => dir !== "default").sort();
+ if (response.subdirs && response.subdirs.includes("default")) {
+ subdirs.unshift("default");
+ } else {
+ subdirs.unshift("default");
+ }
+
+ this.memorySubdirs = subdirs;
+
+ // Ensure the currently selected subdirectory exists in the list
+ if (!this.memorySubdirs.includes(this.selectedMemorySubdir)) {
+ this.selectedMemorySubdir = "default";
+ }
+ } else {
+ this.error = response.error || "Failed to load memory subdirectories";
+ this.memorySubdirs = ["default"];
+ this.selectedMemorySubdir = "default";
+ }
+ } catch (error) {
+ this.error = error.message || "Failed to load memory subdirectories";
+ this.memorySubdirs = ["default"];
+ // Only fallback to default if current selection is not available
+ if (!this.memorySubdirs.includes(this.selectedMemorySubdir)) {
+ this.selectedMemorySubdir = "default";
+ }
+ console.error("Memory subdirectory loading error:", error);
+ } finally {
+ this.loadingSubdirs = false;
+ }
+ },
+
+ async searchMemories(silent = false) {
+ // Save limit to localStorage for persistence
+ localStorage.setItem('memoryDashboard_limit', this.limit.toString());
+
+ if (!silent) {
+ this.loading = true;
+ this.error = null;
+ this.message = null;
+
+ // Check if this memory subdirectory needs initialization
+ if (!this.memoryInitialized[this.selectedMemorySubdir]) {
+ this.initializingMemory = true;
+ }
+ }
+
+ try {
+ const response = await API.callJsonApi("memory_dashboard", {
+ action: "search",
+ memory_subdir: this.selectedMemorySubdir,
area: this.areaFilter,
search: this.searchQuery,
- limit: 500 // Get more for client-side pagination
+ limit: this.limit
});
- if (response.success) {
- this.memories = response.memories || []; // Already sorted by API
+ if (response.success) {
+ // Add selected property to each memory item for mass selection
+ this.memories = (response.memories || []).map(memory => ({
+ ...memory,
+ selected: memory.selected || false
+ }));
this.totalCount = response.total_count || 0;
this.knowledgeCount = response.knowledge_count || 0;
this.conversationCount = response.conversation_count || 0;
this.areasCount = response.areas_count || {};
- this.message = response.message || null; // Handle initialization messages
- this.currentPage = 1; // Reset to first page when loading new data
+
+ if (!silent) {
+ this.message = response.message || null;
+ this.currentPage = 1; // Reset to first page when loading new data
+ } else {
+ // For silent updates, adjust current page if it exceeds available pages
+ if (this.currentPage > this.totalPages && this.totalPages > 0) {
+ this.currentPage = this.totalPages;
+ }
+ }
+
+ // Mark this subdirectory as initialized
+ this.memoryInitialized[this.selectedMemorySubdir] = true;
} else {
- this.error = response.error || "Failed to load memories";
+ if (!silent) {
+ this.error = response.error || "Failed to search memories";
+ this.memories = [];
+ this.message = null;
+ } else {
+ // For silent updates, just log the error but don't break the UI
+ console.warn("Memory dashboard polling failed:", response.error);
+ }
+ }
+ } catch (error) {
+ if (!silent) {
+ this.error = error.message || "Failed to search memories";
this.memories = [];
this.message = null;
+ console.error("Memory search error:", error);
+ } else {
+ // For silent updates, just log the error but don't break the UI
+ console.warn("Memory dashboard polling error:", error);
}
- } catch (error) {
- this.error = error.message || "Failed to load memories";
- this.memories = [];
- this.message = null;
- console.error("Memory dashboard error:", error);
} finally {
- this.loading = false;
+ if (!silent) {
+ this.loading = false;
+ this.initializingMemory = false;
+ }
}
},
- async applyFilters() {
- await this.loadMemories();
- },
-
- clearFilters() {
+ async clearSearch() {
this.areaFilter = "";
this.searchQuery = "";
- this.applyFilters();
+ this.currentPage = 1;
+
+ // Immediately trigger a new search with cleared filters
+ await this.searchMemories();
+ },
+
+ async onMemorySubdirChange() {
+ // Clear current results when subdirectory changes
+ await this.clearSearch(); // Polling continues with new subdirectory
},
// Pagination
@@ -80,9 +218,9 @@ const model = {
},
get paginatedMemories() {
- const startIndex = (this.currentPage - 1) * this.itemsPerPage;
- const endIndex = startIndex + this.itemsPerPage;
- return this.memories.slice(startIndex, endIndex);
+ const start = (this.currentPage - 1) * this.itemsPerPage;
+ const end = start + this.itemsPerPage;
+ return this.memories.slice(start, end);
},
goToPage(page) {
@@ -103,152 +241,356 @@ const model = {
}
},
- // Memory details
- showMemoryDetails(memory) {
- this.selectedMemory = memory;
- this.showDetailModal = true;
+ // Mass selection
+ get selectedMemories() {
+ return this.memories.filter(memory => memory.selected);
},
- closeDetailModal() {
- this.showDetailModal = false;
- this.selectedMemory = null;
+ get selectedCount() {
+ return this.selectedMemories.length;
+ },
+
+ get allSelected() {
+ return this.memories.length > 0 && this.memories.every(memory => memory.selected);
+ },
+
+ get someSelected() {
+ return this.memories.some(memory => memory.selected);
+ },
+
+ toggleSelectAll() {
+ const shouldSelectAll = !this.allSelected;
+ this.memories.forEach(memory => {
+ memory.selected = shouldSelectAll;
+ });
+ },
+
+
+
+ clearSelection() {
+ this.memories.forEach(memory => {
+ memory.selected = false;
+ });
},
+ // Bulk operations
+ async bulkDeleteMemories() {
+ const selectedMemories = this.selectedMemories;
+ if (selectedMemories.length === 0) return;
+ const confirmMessage = `Are you sure you want to delete ${selectedMemories.length} selected memories? This cannot be undone.`;
+ if (!confirm(confirmMessage)) return;
- // Utility methods
- formatTimestamp(timestamp, compact = false) {
- if (!timestamp || timestamp === "unknown") return "Unknown";
try {
- // Parse timestamp - assume UTC if no timezone specified
- let date;
- if (timestamp.includes('T') || timestamp.includes('Z') || timestamp.includes('+')) {
- // ISO format with timezone info
- date = new Date(timestamp);
+ this.loading = true;
+ const response = await API.callJsonApi("memory_dashboard", {
+ action: "bulk_delete",
+ memory_subdir: this.selectedMemorySubdir,
+ memory_ids: selectedMemories.map(memory => memory.id)
+ });
+
+ if (response.success) {
+ this.showToast(`Successfully deleted ${selectedMemories.length} memories`, "success");
+
+ // Let polling refresh the data instead of manual manipulation
+ // Trigger an immediate refresh to get updated state from backend
+ await this.searchMemories(true); // silent refresh
} else {
- // Assume UTC for plain format "YYYY-MM-DD HH:MM:SS"
- date = new Date(timestamp + ' UTC');
+ this.showToast(response.error || "Failed to delete selected memories", "error");
}
+ } catch (error) {
+ this.showToast(error.message || "Failed to delete selected memories", "error");
+ } finally {
+ this.loading = false;
+ }
+ },
- // Convert to local time and format
- if (compact) {
- // Compact format for table view
- return date.toLocaleString(undefined, {
- month: '2-digit',
- day: '2-digit',
- hour: '2-digit',
- minute: '2-digit',
- hour12: false
- });
- } else {
- // Full format for detail view
- return date.toLocaleString(undefined, {
- year: 'numeric',
- month: '2-digit',
- day: '2-digit',
- hour: '2-digit',
- minute: '2-digit',
- second: '2-digit',
- hour12: false
- });
+ // Helper method to format a complete memory with all metadata
+ formatMemoryForCopy(memory) {
+ let formatted = `=== Memory ID: ${memory.id} ===
+Area: ${memory.area}
+Timestamp: ${this.formatTimestamp(memory.timestamp)}
+Source: ${memory.knowledge_source ? 'Knowledge' : 'Conversation'}
+${memory.source_file ? `File: ${memory.source_file}` : ''}
+${memory.tags && memory.tags.length > 0 ? `Tags: ${memory.tags.join(', ')}` : ''}`;
+
+ // Add custom metadata if present
+ if (memory.metadata && typeof memory.metadata === 'object' && Object.keys(memory.metadata).length > 0) {
+ formatted += '\n\nMetadata:';
+ for (const [key, value] of Object.entries(memory.metadata)) {
+ const displayValue = typeof value === 'object' ? JSON.stringify(value, null, 2) : value;
+ formatted += `\n${key}: ${displayValue}`;
}
- } catch {
- return timestamp;
+ }
+
+ formatted += `\n\nContent:
+${memory.content_full}
+
+`;
+ return formatted;
+ },
+
+ bulkCopyMemories() {
+ const selectedMemories = this.selectedMemories;
+ if (selectedMemories.length === 0) return;
+
+ const content = selectedMemories.map(memory => this.formatMemoryForCopy(memory)).join('\n');
+
+ this.copyToClipboard(content);
+ this.showToast(`Copied ${selectedMemories.length} memories with metadata to clipboard`, "success");
+ },
+
+ bulkExportMemories() {
+ const selectedMemories = this.selectedMemories;
+ if (selectedMemories.length === 0) return;
+
+ const exportData = {
+ export_timestamp: new Date().toISOString(),
+ memory_subdir: this.selectedMemorySubdir,
+ total_memories: selectedMemories.length,
+ memories: selectedMemories.map(memory => ({
+ id: memory.id,
+ area: memory.area,
+ timestamp: memory.timestamp,
+ content: memory.content_full,
+ tags: memory.tags || [],
+ knowledge_source: memory.knowledge_source,
+ source_file: memory.source_file || null,
+ metadata: memory.metadata || {}
+ }))
+ };
+
+ const jsonString = JSON.stringify(exportData, null, 2);
+ const blob = new Blob([jsonString], { type: 'application/json' });
+ const url = URL.createObjectURL(blob);
+
+ const timestamp = new Date().toISOString().split('T')[0];
+ const filename = `memories_${this.selectedMemorySubdir}_selected_${selectedMemories.length}_${timestamp}.json`;
+
+ const a = document.createElement('a');
+ a.href = url;
+ a.download = filename;
+ document.body.appendChild(a);
+ a.click();
+ document.body.removeChild(a);
+ URL.revokeObjectURL(url);
+
+ this.showToast(`Exported ${selectedMemories.length} selected memories to ${filename}`, "success");
+ },
+
+ // Memory detail modal (standard approach)
+ showMemoryDetails(memory) {
+ this.detailMemory = memory;
+ // Use global modal system
+ openModal("settings/memory/memory-detail-modal.html");
+ },
+
+ closeMemoryDetails() {
+ this.detailMemory = null;
+ },
+
+ // Utilities
+ formatTimestamp(timestamp, compact = false) {
+ if (!timestamp || timestamp === "unknown") {
+ return "Unknown";
+ }
+
+ const date = new Date(timestamp);
+ if (isNaN(date.getTime())) {
+ return "Invalid Date";
+ }
+
+ if (compact) {
+ // For table display: MM/DD HH:mm
+ return date.toLocaleDateString("en-US", {
+ month: "2-digit",
+ day: "2-digit",
+ }) + " " + date.toLocaleTimeString("en-US", {
+ hour12: false,
+ hour: "2-digit",
+ minute: "2-digit"
+ });
+ } else {
+ // For details: Full format
+ return date.toLocaleDateString("en-US", {
+ year: "numeric",
+ month: "long",
+ day: "numeric",
+ }) + " at " + date.toLocaleTimeString("en-US", {
+ hour12: true,
+ hour: "numeric",
+ minute: "2-digit"
+ });
}
},
formatTags(tags) {
- if (!Array.isArray(tags) || tags.length === 0) return "";
+ if (!Array.isArray(tags) || tags.length === 0) return "None";
return tags.join(", ");
},
- getAreaColor(area) {
- if (!area) return '#757575'; // Default color for undefined/null area
-
+ getAreaColor(area) {
const colors = {
- 'main': '#2196F3',
- 'fragments': '#4CAF50',
- 'solutions': '#FF9800',
- 'instruments': '#9C27B0'
+ "MAIN": "#3b82f6", // blue
+ "FRAGMENTS": "#10b981", // emerald
+ "SOLUTIONS": "#8b5cf6", // violet
+ "INSTRUMENTS": "#f59e0b" // amber
};
- return colors[area.toLowerCase()] || '#757575';
+ return colors[area] || "#6b7280"; // gray for unknown
},
copyToClipboard(text) {
- navigator.clipboard.writeText(text).then(() => {
- // Could show a toast notification here
- console.log("Copied to clipboard");
- }).catch(err => {
- console.error("Failed to copy: ", err);
- });
+ if (navigator.clipboard && window.isSecureContext) {
+ navigator.clipboard.writeText(text).then(() => {
+ this.showToast("Copied to clipboard!", "success");
+ }).catch(err => {
+ console.error("Clipboard copy failed:", err);
+ this.fallbackCopyToClipboard(text);
+ });
+ } else {
+ this.fallbackCopyToClipboard(text);
+ }
},
- async deleteMemory(memory) {
- // Confirm deletion
- const confirmMessage = `Are you sure you want to delete this memory?\n\nArea: ${memory.area}\nContent: ${memory.content_preview}`;
- if (!confirm(confirmMessage)) {
+ fallbackCopyToClipboard(text) {
+ const textArea = document.createElement("textarea");
+ textArea.value = text;
+ textArea.style.position = "fixed";
+ textArea.style.left = "-999999px";
+ textArea.style.top = "-999999px";
+ document.body.appendChild(textArea);
+ textArea.focus();
+ textArea.select();
+ try {
+ document.execCommand('copy');
+ this.showToast("Copied to clipboard!", "success");
+ } catch (err) {
+ console.error("Fallback clipboard copy failed:", err);
+ this.showToast("Failed to copy to clipboard", "error");
+ }
+ document.body.removeChild(textArea);
+ },
+
+ async deleteMemory(memory) {
+ if (!confirm(`Are you sure you want to delete this memory from ${memory.area}?`)) {
return;
}
try {
- const response = await API.callJsonApi("memory_delete", {
- context: getContext(),
+ // Check if this is the memory currently being viewed in detail modal
+ const isViewingThisMemory = this.detailMemory && this.detailMemory.id === memory.id;
+
+ const response = await API.callJsonApi("memory_dashboard", {
+ action: "delete",
+ memory_subdir: this.selectedMemorySubdir,
memory_id: memory.id
});
if (response.success) {
- // Close detail modal if the deleted memory is currently shown
- if (this.selectedMemory && this.selectedMemory.id === memory.id) {
- this.closeDetailModal();
- }
+ this.showToast("Memory deleted successfully", "success");
- // Remove memory from local array
- this.memories = this.memories.filter(m => m.id !== memory.id);
- this.totalCount = this.memories.length;
-
- // Update statistics
- if (memory.knowledge_source) {
- this.knowledgeCount = Math.max(0, this.knowledgeCount - 1);
- } else {
- this.conversationCount = Math.max(0, this.conversationCount - 1);
- }
-
- // Update areas count
- if (this.areasCount[memory.area]) {
- this.areasCount[memory.area] = Math.max(0, this.areasCount[memory.area] - 1);
- if (this.areasCount[memory.area] === 0) {
- delete this.areasCount[memory.area];
- }
+ // If we were viewing this memory in detail modal, close it
+ if (isViewingThisMemory) {
+ this.detailMemory = null;
+ closeModal(); // Close the detail modal
}
- // Adjust current page if needed
- if (this.paginatedMemories.length === 0 && this.currentPage > 1) {
- this.currentPage--;
- }
-
- console.log("Memory deleted successfully");
+ // Let polling refresh the data instead of manual manipulation
+ // Trigger an immediate refresh to get updated state from backend
+ await this.searchMemories(true); // silent refresh
} else {
- alert("Failed to delete memory: " + (response.error || "Unknown error"));
+ this.showToast(`Failed to delete memory: ${response.error}`, "error");
}
} catch (error) {
- console.error("Delete memory error:", error);
- alert("Failed to delete memory: " + error.message);
+ console.error("Memory deletion error:", error);
+ this.showToast("Failed to delete memory", "error");
}
},
- // Export functionality (optional)
exportMemories() {
- const dataStr = JSON.stringify(this.memories, null, 2);
- const dataBlob = new Blob([dataStr], {type: 'application/json'});
- const url = URL.createObjectURL(dataBlob);
- const link = document.createElement('a');
- link.href = url;
- link.download = `memory-export-${new Date().toISOString().split('T')[0]}.json`;
- link.click();
- URL.revokeObjectURL(url);
+ if (this.memories.length === 0) {
+ this.showToast("No memories to export", "warning");
+ return;
+ }
+
+ try {
+ const exportData = {
+ memory_subdir: this.selectedMemorySubdir,
+ export_timestamp: new Date().toISOString(),
+ total_memories: this.memories.length,
+ search_query: this.searchQuery,
+ area_filter: this.areaFilter,
+ memories: this.memories.map(memory => ({
+ id: memory.id,
+ area: memory.area,
+ timestamp: memory.timestamp,
+ content: memory.content_full,
+ metadata: memory.metadata
+ }))
+ };
+
+ const blob = new Blob([JSON.stringify(exportData, null, 2)], {
+ type: 'application/json'
+ });
+ const url = URL.createObjectURL(blob);
+ const a = document.createElement('a');
+ a.href = url;
+ a.download = `memory-export-${this.selectedMemorySubdir}-${new Date().toISOString().split('T')[0]}.json`;
+ document.body.appendChild(a);
+ a.click();
+ document.body.removeChild(a);
+ URL.revokeObjectURL(url);
+
+ this.showToast("Memory export completed", "success");
+ } catch (error) {
+ console.error("Memory export error:", error);
+ this.showToast("Failed to export memories", "error");
+ }
+ },
+
+ startPolling() {
+ if (!this.pollingEnabled || this.pollingInterval) {
+ return; // Already polling or disabled
+ }
+
+ this.pollingInterval = setInterval(async () => {
+ // Silently refresh using existing search logic
+ await this.searchMemories(true); // silent = true
+ }, 2000); // Poll every 3 seconds - reasonable for active user interactions
+ },
+
+ stopPolling() {
+ if (this.pollingInterval) {
+ clearInterval(this.pollingInterval);
+ this.pollingInterval = null;
+ }
+ },
+
+ // Call this when the dialog/component is closed or destroyed
+ cleanup() {
+ this.stopPolling();
+ // Clear data without triggering a new search (component is being destroyed)
+ this.areaFilter = "";
+ this.searchQuery = "";
+ this.memories = [];
+ this.totalCount = 0;
+ this.knowledgeCount = 0;
+ this.conversationCount = 0;
+ this.areasCount = {};
+ this.message = null;
+ this.currentPage = 1;
+ },
+
+ showToast(message, type = "info") {
+ // Use global toast function if available
+ if (typeof toast === 'function') {
+ toast(message, type);
+ } else {
+ console.log(`[${type.toUpperCase()}] ${message}`);
+ }
}
};
-const store = createStore("memoryDashboardStore", model);
+const store = createStore("memoryDashboardStore", memoryDashboardStore);
export { store };
diff --git a/webui/components/settings/memory/memory-dashboard.html b/webui/components/settings/memory/memory-dashboard.html
index fa8b01392..87761dc5e 100644
--- a/webui/components/settings/memory/memory-dashboard.html
+++ b/webui/components/settings/memory/memory-dashboard.html
@@ -1,16 +1,10 @@
-<html>
+<script type="module">
+ import { store } from "/components/settings/memory/memory-dashboard-store.js";
+</script>
-<head>
- <title>Memory Dashboard</title>
- <script type="module">
- import { store } from "/components/settings/memory/memory-dashboard-store.js";
- </script>
-</head>
-
-<body>
- <div x-data>
- <template x-if="$store.memoryDashboardStore">
- <div x-init="$store.memoryDashboardStore.initialize()" class="memory-dashboard">
+<div x-data>
+ <template x-if="$store.memoryDashboardStore">
+ <div x-init="$store.memoryDashboardStore.initialize()" class="memory-dashboard">
<!-- Header with title and statistics -->
<div class="dashboard-header">
@@ -31,32 +25,54 @@
</div>
</div>
- <!-- Filters -->
+ <!-- Search and Filters -->
<div class="filters-section">
<div class="filter-row">
+ <div class="filter-group">
+ <label for="memory-subdir-select">Memory Directory:</label>
+ <select id="memory-subdir-select"
+ x-model="$store.memoryDashboardStore.selectedMemorySubdir"
+ @change="$store.memoryDashboardStore.onMemorySubdirChange()"
+ :disabled="$store.memoryDashboardStore.loadingSubdirs">
+ <template x-for="subdir in $store.memoryDashboardStore.memorySubdirs" :key="subdir">
+ <option :value="subdir" x-text="subdir"></option>
+ </template>
+ </select>
+ <span x-show="$store.memoryDashboardStore.loadingSubdirs" class="loading-text">Loading...</span>
+ </div>
+
<div class="filter-group">
<label for="area-filter">Area:</label>
<select id="area-filter" x-model="$store.memoryDashboardStore.areaFilter">
<option value="">All Areas</option>
- <option value="main">Main</option>
- <option value="fragments">Fragments</option>
- <option value="solutions">Solutions</option>
- <option value="instruments">Instruments</option>
+ <option value="MAIN">Main</option>
+ <option value="FRAGMENTS">Fragments</option>
+ <option value="SOLUTIONS">Solutions</option>
+ <option value="INSTRUMENTS">Instruments</option>
</select>
</div>
<div class="filter-group">
<label for="search-input">Search:</label>
<input type="text" id="search-input" x-model="$store.memoryDashboardStore.searchQuery"
- placeholder="Search memory content..." />
+ placeholder="Search memory content..."
+ @keyup.enter="$store.memoryDashboardStore.searchMemories()" />
+ </div>
+
+ <div class="filter-group">
+ <label for="limit-input">Limit:</label>
+ <input type="number" id="limit-input" x-model.number="$store.memoryDashboardStore.limit"
+ min="10" max="1000" step="10"
+ style="min-width: 100px;" />
</div>
<div class="filter-actions">
- <button class="btn primary slim" @click="$store.memoryDashboardStore.applyFilters()"
- :disabled="$store.memoryDashboardStore.loading">
- Apply Filters
+ <button class="btn primary slim" @click="$store.memoryDashboardStore.searchMemories()"
+ :disabled="$store.memoryDashboardStore.loading || $store.memoryDashboardStore.loadingSubdirs">
+ <span x-show="!$store.memoryDashboardStore.initializingMemory">Search</span>
+ <span x-show="$store.memoryDashboardStore.initializingMemory">Initializing Memory...</span>
</button>
- <button class="btn slim" @click="$store.memoryDashboardStore.clearFilters()">
+ <button class="btn slim" @click="$store.memoryDashboardStore.clearSearch()">
Clear
</button>
</div>
@@ -66,7 +82,8 @@
<!-- Loading state -->
<div x-show="$store.memoryDashboardStore.loading" class="loading-state">
<div class="loading-spinner"></div>
- <span>Loading memories...</span>
+ <span x-show="!$store.memoryDashboardStore.initializingMemory">Searching memories...</span>
+ <span x-show="$store.memoryDashboardStore.initializingMemory">Initializing memory database...</span>
</div>
<!-- Error state -->
@@ -93,15 +110,13 @@
Previous
</button>
- <span class="page-numbers">
+ <select class="page-select"
+ x-model.number="$store.memoryDashboardStore.currentPage"
+ @change="$store.memoryDashboardStore.goToPage($store.memoryDashboardStore.currentPage)">
<template x-for="page in Array.from({length: $store.memoryDashboardStore.totalPages}, (_, i) => i + 1)" :key="page">
- <button class="page-btn"
- @click="$store.memoryDashboardStore.goToPage(page)"
- :class="{'active': page === $store.memoryDashboardStore.currentPage}"
- x-text="page">
- </button>
+ <option :value="page" x-text="'Page ' + page"></option>
</template>
- </span>
+ </select>
<button class="btn slim" @click="$store.memoryDashboardStore.nextPage()"
:disabled="$store.memoryDashboardStore.currentPage === $store.memoryDashboardStore.totalPages">
@@ -110,44 +125,102 @@
</div>
</div>
+ <!-- Mass action toolbar -->
+ <div x-show="$store.memoryDashboardStore.selectedCount > 0" class="mass-action-toolbar">
+ <div class="selection-info">
+ <span x-text="$store.memoryDashboardStore.selectedCount"></span> memories selected
+ </div>
+
+ <div class="mass-actions">
+ <button class="btn-mass copy" @click="$store.memoryDashboardStore.bulkCopyMemories()"
+ title="Copy Selected Content">
+ <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
+ <rect x="9" y="9" width="13" height="13" rx="2" ry="2"></rect>
+ <path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"></path>
+ </svg>
+ Copy
+ </button>
+
+ <button class="btn-mass export" @click="$store.memoryDashboardStore.bulkExportMemories()"
+ title="Export Selected Memories">
+ <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
+ <path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"></path>
+ <polyline points="7,10 12,15 17,10"></polyline>
+ <line x1="12" y1="15" x2="12" y2="3"></line>
+ </svg>
+ Export
+ </button>
+
+ <button class="btn-mass delete" @click="$store.memoryDashboardStore.bulkDeleteMemories()"
+ title="Delete Selected Memories">
+ <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
+ <polyline points="3,6 5,6 21,6"></polyline>
+ <path d="M19,6V20a2,2,0,0,1-2,2H7a2,2,0,0,1-2-2V6m3,0V4a2,2,0,0,1,2-2h4a2,2,0,0,1,2,2V6"></path>
+ <line x1="10" y1="11" x2="10" y2="17"></line>
+ <line x1="14" y1="11" x2="14" y2="17"></line>
+ </svg>
+ Delete
+ </button>
+
+ <button class="btn-mass clear" @click="$store.memoryDashboardStore.clearSelection()"
+ title="Clear Selection">
+ <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
+ <line x1="18" y1="6" x2="6" y2="18"></line>
+ <line x1="6" y1="6" x2="18" y2="18"></line>
+ </svg>
+ Clear
+ </button>
+ </div>
+ </div>
+
<div class="table-wrapper">
<table class="memory-table">
<thead>
<tr>
- <th class="col-area">Area</th>
- <th class="col-timestamp">Timestamp</th>
- <th class="col-source">Source</th>
+ <th class="col-select">
+ <input type="checkbox"
+ :checked="$store.memoryDashboardStore.allSelected"
+ :indeterminate="$store.memoryDashboardStore.someSelected && !$store.memoryDashboardStore.allSelected"
+ @change="$store.memoryDashboardStore.toggleSelectAll()"
+ title="Select/Deselect All" />
+ </th>
+ <th class="col-metadata">Metadata</th>
<th class="col-preview">Preview</th>
<th class="col-actions">Actions</th>
</tr>
</thead>
<tbody>
<template x-for="memory in $store.memoryDashboardStore.paginatedMemories" :key="memory.id">
- <tr class="memory-row">
- <!-- Area with color indicator -->
- <td class="area-cell">
- <span class="area-badge"
- :style="`background-color: ${$store.memoryDashboardStore.getAreaColor(memory.area)}`"
- x-text="memory.area.toUpperCase()"></span>
+ <tr class="memory-row" :class="{'selected': memory.selected}"
+ @click="$store.memoryDashboardStore.showMemoryDetails(memory)"
+ style="cursor: pointer;">
+ <!-- Selection checkbox -->
+ <td class="select-cell" @click.stop>
+ <input type="checkbox"
+ x-model="memory.selected" />
</td>
- <!-- Timestamp -->
- <td class="timestamp-cell">
- <span x-text="$store.memoryDashboardStore.formatTimestamp(memory.timestamp, true)"
- :title="$store.memoryDashboardStore.formatTimestamp(memory.timestamp, false)"></span>
- </td>
-
- <!-- Source -->
- <td class="source-cell">
- <template x-if="memory.knowledge_source">
- <div class="source-info">
- <span class="source-type knowledge">Knowledge</span>
- <span class="source-file" x-text="memory.source_file" x-show="memory.source_file"></span>
+ <!-- Metadata (merged Area, Timestamp, Source) -->
+ <td class="metadata-cell">
+ <div class="metadata-info">
+ <div class="metadata-row">
+ <span class="area-badge"
+ :style="`background-color: ${$store.memoryDashboardStore.getAreaColor(memory.area)}`"
+ x-text="memory.area"></span>
+ </div>
+ <div class="metadata-row metadata-timestamp">
+ <span x-text="$store.memoryDashboardStore.formatTimestamp(memory.timestamp, true)"
+ :title="$store.memoryDashboardStore.formatTimestamp(memory.timestamp, false)"></span>
</div>
- </template>
- <template x-if="!memory.knowledge_source">
- <span class="source-type conversation">Conversation</span>
- </template>
+ <div class="metadata-row">
+ <template x-if="memory.knowledge_source">
+ <span class="source-type knowledge">📚 Knowledge</span>
+ </template>
+ <template x-if="!memory.knowledge_source">
+ <span class="source-type conversation">💬 Conversation</span>
+ </template>
+ </div>
+ </div>
</td>
<!-- Content preview -->
@@ -161,21 +234,15 @@
</td>
<!-- Actions -->
- <td class="actions-cell">
- <button class="btn-action view" @click="$store.memoryDashboardStore.showMemoryDetails(memory)"
- title="View Details">
- <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
- <path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"></path>
- <circle cx="12" cy="12" r="3"></circle>
- </svg>
- </button>
- <button class="btn-action copy" @click="$store.memoryDashboardStore.copyToClipboard(memory.content_full)"
- title="Copy Content">
+ <td class="actions-cell" @click.stop>
+ <button class="btn-action copy" @click="$store.memoryDashboardStore.copyToClipboard($store.memoryDashboardStore.formatMemoryForCopy(memory))"
+ title="Copy Memory">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<rect x="9" y="9" width="13" height="13" rx="2" ry="2"></rect>
<path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"></path>
</svg>
</button>
+
<button class="btn-action delete" @click="$store.memoryDashboardStore.deleteMemory(memory)"
title="Delete Memory">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
@@ -190,6 +257,37 @@
</template>
</tbody>
</table>
+
+ <!-- Pagination controls at bottom -->
+ <div class="pagination-controls-bottom" x-show="$store.memoryDashboardStore.totalPages > 1">
+ <div class="pagination-info-inline">
+ <span>Page <span x-text="$store.memoryDashboardStore.currentPage"></span>
+ of <span x-text="$store.memoryDashboardStore.totalPages"></span>
+ (<span x-text="$store.memoryDashboardStore.memories.length"></span> total memories)
+ </span>
+ </div>
+
+ <div class="pagination-controls">
+ <button class="btn slim" @click="$store.memoryDashboardStore.prevPage()"
+ :disabled="$store.memoryDashboardStore.currentPage === 1">
+ Previous
+ </button>
+
+ <select class="page-select"
+ x-model.number="$store.memoryDashboardStore.currentPage"
+ @change="$store.memoryDashboardStore.goToPage($store.memoryDashboardStore.currentPage)">
+ <template x-for="page in Array.from({length: $store.memoryDashboardStore.totalPages}, (_, i) => i + 1)" :key="page">
+ <option :value="page" x-text="'Page ' + page"></option>
+ </template>
+ </select>
+
+ <button class="btn slim" @click="$store.memoryDashboardStore.nextPage()"
+ :disabled="$store.memoryDashboardStore.currentPage === $store.memoryDashboardStore.totalPages">
+ Next
+ </button>
+ </div>
+ </div>
+
</div>
<!-- No memories message -->
@@ -212,138 +310,7 @@
</div>
</div>
- <!-- Enhanced Detail Modal -->
- <div x-show="$store.memoryDashboardStore.showDetailModal"
- x-transition:enter="modal-enter"
- x-transition:enter-start="modal-enter-start"
- x-transition:enter-end="modal-enter-end"
- x-transition:leave="modal-leave"
- x-transition:leave-start="modal-leave-start"
- x-transition:leave-end="modal-leave-end"
- class="modal-overlay"
- @click.self="$store.memoryDashboardStore.closeDetailModal()">
- <div class="modal-content memory-detail-modal" x-show="$store.memoryDashboardStore.selectedMemory" x-cloak>
-
- <!-- Modal Header with Memory Info -->
- <div class="modal-header-enhanced">
- <div class="header-left">
- <div class="memory-title">
- <span class="area-badge-large"
- :style="`background: linear-gradient(135deg, ${$store.memoryDashboardStore.getAreaColor($store.memoryDashboardStore.selectedMemory?.area)} 0%, ${$store.memoryDashboardStore.getAreaColor($store.memoryDashboardStore.selectedMemory?.area)}cc 100%)`"
- x-text="$store.memoryDashboardStore.selectedMemory?.area?.toUpperCase() || 'UNKNOWN'"></span>
- <h3>Memory Details</h3>
- </div>
- <div class="memory-meta-quick">
- <span class="timestamp-badge" x-text="$store.memoryDashboardStore.formatTimestamp($store.memoryDashboardStore.selectedMemory?.timestamp, true)"></span>
- <span class="source-badge"
- :class="$store.memoryDashboardStore.selectedMemory?.knowledge_source ? 'knowledge' : 'conversation'"
- x-text="$store.memoryDashboardStore.selectedMemory?.knowledge_source ? 'Knowledge' : 'Conversation'"></span>
- </div>
- </div>
- <div class="header-actions">
- <button class="btn-action-header copy" @click="$store.memoryDashboardStore.copyToClipboard($store.memoryDashboardStore.selectedMemory?.content_full)"
- title="Copy Full Content">
- <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
- <rect x="9" y="9" width="13" height="13" rx="2" ry="2"></rect>
- <path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"></path>
- </svg>
- </button>
- <button class="btn-action-header delete" @click="$store.memoryDashboardStore.deleteMemory($store.memoryDashboardStore.selectedMemory)"
- title="Delete Memory">
- <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
- <polyline points="3,6 5,6 21,6"></polyline>
- <path d="M19,6V20a2,2,0,0,1-2,2H7a2,2,0,0,1-2-2V6M8,6V4a2,2,0,0,1,2-2h4a2,2,0,0,1,2,2V6"></path>
- <line x1="10" y1="11" x2="10" y2="17"></line>
- <line x1="14" y1="11" x2="14" y2="17"></line>
- </svg>
- </button>
- <button class="btn-close-enhanced" @click="$store.memoryDashboardStore.closeDetailModal()">
- <svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
- <line x1="18" y1="6" x2="6" y2="18"></line>
- <line x1="6" y1="6" x2="18" y2="18"></line>
- </svg>
- </button>
- </div>
- </div>
- <!-- Modal Body with Enhanced Layout -->
- <div class="modal-body-enhanced">
-
- <!-- Content Section -->
- <div class="content-section-main">
- <div class="section-header">
- <h4>
- <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
- <path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"></path>
- <polyline points="14,2 14,8 20,8"></polyline>
- </svg>
- Content
- </h4>
- </div>
- <div class="content-display" x-text="$store.memoryDashboardStore.selectedMemory?.content_full"></div>
- </div>
-
- <!-- Metadata Sidebar -->
- <div class="metadata-sidebar">
- <div class="section-header">
- <h4>
- <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
- <circle cx="12" cy="12" r="3"></circle>
- <path d="M12 1v6m0 6v6m11-7h-6m-6 0H1"></path>
- </svg>
- Metadata
- </h4>
- </div>
-
- <div class="metadata-grid">
- <div class="metadata-item">
- <label>Memory ID</label>
- <value class="monospace" x-text="$store.memoryDashboardStore.selectedMemory?.id"></value>
- </div>
-
- <div class="metadata-item">
- <label>Area</label>
- <value x-text="$store.memoryDashboardStore.selectedMemory?.area"></value>
- </div>
-
- <div class="metadata-item">
- <label>Created</label>
- <value x-text="$store.memoryDashboardStore.formatTimestamp($store.memoryDashboardStore.selectedMemory?.timestamp)"></value>
- </div>
-
- <div class="metadata-item">
- <label>Source Type</label>
- <value x-text="$store.memoryDashboardStore.selectedMemory?.knowledge_source ? 'Knowledge File' : 'Conversation'"></value>
- </div>
-
- <div class="metadata-item" x-show="$store.memoryDashboardStore.selectedMemory?.source_file">
- <label>Source File</label>
- <value class="monospace" x-text="$store.memoryDashboardStore.selectedMemory?.source_file"></value>
- </div>
-
- <div class="metadata-item" x-show="$store.memoryDashboardStore.selectedMemory?.file_type">
- <label>File Type</label>
- <value x-text="$store.memoryDashboardStore.selectedMemory?.file_type"></value>
- </div>
-
- <div class="metadata-item" x-show="$store.memoryDashboardStore.selectedMemory?.consolidation_action">
- <label>Consolidation</label>
- <value class="consolidation-badge" x-text="$store.memoryDashboardStore.selectedMemory?.consolidation_action"></value>
- </div>
-
- <div class="metadata-item" x-show="$store.memoryDashboardStore.selectedMemory?.tags && $store.memoryDashboardStore.selectedMemory?.tags.length > 0">
- <label>Tags</label>
- <div class="tags-display">
- <template x-for="tag in $store.memoryDashboardStore.selectedMemory?.tags" :key="tag">
- <span class="tag-pill" x-text="tag"></span>
- </template>
- </div>
- </div>
- </div>
- </div>
- </div>
- </div>
- </div>
</div>
</template>
@@ -433,6 +400,8 @@
border-radius: 6px;
font-size: 0.9rem;
min-width: 200px;
+ height: 40px;
+ box-sizing: border-box;
}
.filter-group input:focus, .filter-group select:focus {
@@ -444,6 +413,20 @@
.filter-actions {
display: flex;
gap: 0.5rem;
+ align-items: stretch;
+ }
+
+ .filter-actions .btn {
+ height: 40px;
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ }
+
+ .loading-text {
+ font-size: 0.85rem;
+ color: var(--color-secondary);
+ font-style: italic;
}
.loading-state, .error-state, .no-memories, .init-message {
@@ -502,11 +485,10 @@
}
/* Fixed column widths for proper fit */
- .col-area { width: 15%; }
- .col-timestamp { width: 18%; }
- .col-source { width: 15%; }
- .col-preview { width: 30%; }
- .col-actions { width: 22%; }
+ .col-select { width: 5%; }
+ .col-metadata { width: 25%; }
+ .col-preview { width: 55%; }
+ .col-actions { width: 15%; }
.memory-table th,
.memory-table td {
@@ -517,13 +499,137 @@
overflow: hidden;
}
- /* Allow source column to wrap properly */
- .source-cell {
+ /* Metadata cell styling */
+ .metadata-cell {
overflow: visible;
white-space: normal;
word-wrap: break-word;
}
+ .metadata-info {
+ display: flex;
+ flex-direction: column;
+ gap: 0.5rem;
+ }
+
+ .metadata-row {
+ display: flex;
+ align-items: center;
+ gap: 0.5rem;
+ }
+
+ .metadata-timestamp {
+ font-size: 0.85rem;
+ color: var(--color-text);
+ font-family: monospace;
+ }
+
+ .source-type {
+ font-size: 0.8rem;
+ color: var(--color-text);
+ font-weight: 500;
+ }
+
+ /* Selection column styling */
+ .select-cell, .col-select {
+ text-align: center;
+ padding: 0.5rem !important;
+ }
+
+ .select-cell input[type="checkbox"],
+ .col-select input[type="checkbox"] {
+ cursor: pointer;
+ transform: scale(1.2);
+ }
+
+ /* Selected row styling */
+ .memory-row.selected {
+ background: rgba(115, 122, 129, 0.1);
+ border-left: 3px solid var(--color-primary);
+ }
+
+ .light-mode .memory-row.selected {
+ background: rgba(115, 122, 129, 0.05);
+ }
+
+ /* Mass action toolbar */
+ .mass-action-toolbar {
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+ padding: 1rem;
+ background: rgba(115, 122, 129, 0.1);
+ border: 1px solid var(--color-primary);
+ border-radius: 8px;
+ margin: 1rem 0;
+ animation: slideDown 0.3s ease;
+ }
+
+ .light-mode .mass-action-toolbar {
+ background: rgba(115, 122, 129, 0.05);
+ }
+
+ .selection-info {
+ font-weight: 600;
+ color: var(--color-primary);
+ }
+
+ .mass-actions {
+ display: flex;
+ gap: 0.5rem;
+ }
+
+ .btn-mass {
+ display: flex;
+ align-items: center;
+ gap: 0.5rem;
+ padding: 0.5rem 1rem;
+ border: 1px solid var(--color-border);
+ background: var(--color-background);
+ color: var(--color-text);
+ border-radius: 6px;
+ cursor: pointer;
+ font-size: 0.9rem;
+ font-weight: 500;
+ transition: all 0.2s ease;
+ }
+
+ .btn-mass:hover {
+ border-color: var(--color-primary);
+ background: rgba(115, 122, 129, 0.1);
+ }
+
+ .btn-mass.copy:hover {
+ border-color: #4caf50;
+ color: #4caf50;
+ }
+
+ .btn-mass.export:hover {
+ border-color: #2196f3;
+ color: #2196f3;
+ }
+
+ .btn-mass.delete:hover {
+ border-color: #f44336;
+ color: #f44336;
+ }
+
+ .btn-mass.clear:hover {
+ border-color: #ff9800;
+ color: #ff9800;
+ }
+
+ @keyframes slideDown {
+ from {
+ opacity: 0;
+ transform: translateY(-10px);
+ }
+ to {
+ opacity: 1;
+ transform: translateY(0);
+ }
+ }
+
.memory-table th {
background: var(--color-panel);
font-weight: 600;
@@ -557,7 +663,6 @@
color: white;
font-size: 0.75rem;
font-weight: bold;
- text-transform: uppercase;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}
@@ -617,6 +722,7 @@
.content-preview {
line-height: 1.4;
font-size: 0.9rem;
+ color: var(--color-text);
word-wrap: break-word;
overflow-wrap: break-word;
max-width: 100%;
@@ -716,31 +822,35 @@
border-radius: 8px;
}
- .page-numbers {
- display: flex;
- gap: 0.25rem;
- }
-
- .page-btn {
+ .page-select {
background: var(--color-background);
border: 1px solid var(--color-border);
color: var(--color-text);
padding: 0.5rem 0.75rem;
- cursor: pointer;
border-radius: 6px;
font-size: 0.9rem;
- transition: all 0.2s ease;
+ cursor: pointer;
+ min-width: 120px;
}
- .page-btn:hover {
- background: rgba(255, 255, 255, 0.1);
+ .page-select:focus {
+ outline: none;
border-color: var(--color-primary);
+ box-shadow: 0 0 0 2px rgba(115, 122, 129, 0.1);
}
- .page-btn.active {
- background: var(--color-primary);
- color: white;
- border-color: var(--color-primary);
+ .pagination-controls-top, .pagination-controls-bottom {
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+ padding: 1rem;
+ background: var(--color-panel);
+ border-bottom: 1px solid var(--color-border);
+ }
+
+ .pagination-controls-bottom {
+ border-top: 1px solid var(--color-border);
+ border-bottom: none;
}
.export-section {
@@ -1164,8 +1274,258 @@
justify-content: center;
}
}
- </style>
-</body>
+ /* Memory Detail Modal Styles */
+ .modal-header-enhanced {
+ display: flex;
+ justify-content: space-between;
+ align-items: flex-start;
+ padding: 1.5rem;
+ border-bottom: 2px solid var(--color-border);
+ background: linear-gradient(135deg, var(--color-panel) 0%, var(--color-background) 100%);
+ }
+
+ .memory-title {
+ display: flex;
+ align-items: center;
+ gap: 1rem;
+ margin-bottom: 0.5rem;
+ }
+
+ .area-badge-large {
+ color: white;
+ padding: 0.5rem 1rem;
+ border-radius: 20px;
+ font-size: 0.8rem;
+ font-weight: bold;
+ box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
+ }
+
+ .memory-meta-quick {
+ display: flex;
+ gap: 1rem;
+ align-items: center;
+ }
+
+ .timestamp-badge, .source-badge {
+ padding: 0.25rem 0.75rem;
+ border-radius: 12px;
+ font-size: 0.75rem;
+ font-weight: 500;
+ background: var(--color-panel);
+ border: 1px solid var(--color-border);
+ }
+
+ .source-badge.knowledge {
+ background: rgba(115, 122, 129, 0.1);
+ color: var(--color-primary);
+ border-color: var(--color-primary);
+ }
+
+ .source-badge.conversation {
+ background: rgba(101, 101, 101, 0.1);
+ color: var(--color-secondary);
+ border-color: var(--color-secondary);
+ }
+
+ .header-actions {
+ display: flex;
+ gap: 0.5rem;
+ }
+
+ .btn-action-header {
+ background: var(--color-background);
+ border: 1px solid var(--color-border);
+ color: var(--color-text);
+ padding: 0.5rem;
+ border-radius: 8px;
+ cursor: pointer;
+ transition: all 0.2s ease;
+ }
+
+ .btn-action-header:hover {
+ border-color: var(--color-primary);
+ background: rgba(115, 122, 129, 0.1);
+ }
+
+ .modal-body-enhanced {
+ display: flex;
+ min-height: 60vh;
+ max-height: 70vh;
+ }
+
+ .content-section-main {
+ flex: 1;
+ padding: 1.5rem;
+ overflow-y: auto;
+ }
+
+ .content-block {
+ margin-bottom: 2rem;
+ }
+
+ .content-block h4 {
+ margin: 0 0 1rem 0;
+ color: var(--color-primary);
+ font-size: 1.1rem;
+ font-weight: 600;
+ border-bottom: 1px solid var(--color-border);
+ padding-bottom: 0.5rem;
+ }
+
+ .memory-content-display {
+ background: var(--color-panel);
+ border: 1px solid var(--color-border);
+ border-radius: 8px;
+ padding: 1.5rem;
+ line-height: 1.6;
+ color: var(--color-text);
+ white-space: pre-wrap;
+ word-break: break-word;
+ max-height: 300px;
+ overflow-y: auto;
+ }
+
+ .tags-display {
+ display: flex;
+ flex-wrap: wrap;
+ gap: 0.5rem;
+ }
+
+ .tag-display {
+ background: var(--color-primary);
+ color: white;
+ padding: 0.25rem 0.75rem;
+ border-radius: 12px;
+ font-size: 0.75rem;
+ font-weight: 500;
+ }
+
+ .metadata-sidebar {
+ min-width: 300px;
+ max-width: 350px;
+ background: var(--color-panel);
+ border-left: 1px solid var(--color-border);
+ padding: 1.5rem;
+ overflow-y: auto;
+ }
+
+ .metadata-sidebar h4 {
+ margin: 0 0 1rem 0;
+ color: var(--color-primary);
+ font-size: 1.1rem;
+ font-weight: 600;
+ }
+
+ .metadata-group {
+ margin-bottom: 1.5rem;
+ }
+
+ .metadata-group h5 {
+ margin: 0 0 0.75rem 0;
+ color: var(--color-secondary);
+ font-size: 0.9rem;
+ font-weight: 600;
+ text-transform: uppercase;
+ letter-spacing: 0.5px;
+ }
+
+ .metadata-item {
+ display: flex;
+ flex-direction: column;
+ gap: 0.25rem;
+ margin-bottom: 0.75rem;
+ padding: 0.5rem;
+ background: var(--color-background);
+ border: 1px solid var(--color-border);
+ border-radius: 6px;
+ }
+
+ .metadata-label {
+ font-size: 0.8rem;
+ font-weight: 600;
+ color: var(--color-secondary);
+ text-transform: uppercase;
+ letter-spacing: 0.3px;
+ }
+
+ .metadata-value {
+ font-size: 0.9rem;
+ color: var(--color-text);
+ word-break: break-all;
+ line-height: 1.4;
+ }
+
+ .source-file-display {
+ font-family: monospace;
+ background: var(--color-panel);
+ padding: 0.5rem;
+ border-radius: 4px;
+ border: 1px solid var(--color-border);
+ }
+
+ .metadata-actions {
+ display: flex;
+ flex-direction: column;
+ gap: 0.5rem;
+ }
+
+ .metadata-actions .btn {
+ display: flex;
+ align-items: center;
+ gap: 0.5rem;
+ justify-content: flex-start;
+ font-size: 0.9rem;
+ }
+
+ /* Light mode adjustments for modal */
+ .light-mode .modal-header-enhanced {
+ background: linear-gradient(135deg, rgba(240, 240, 240, 0.8) 0%, rgba(255, 255, 255, 0.9) 100%);
+ }
+
+ .light-mode .memory-content-display {
+ background: rgba(248, 248, 248, 0.8);
+ }
+
+ .light-mode .metadata-sidebar {
+ background: rgba(248, 248, 248, 0.8);
+ }
+
+ .light-mode .metadata-item {
+ background: rgba(255, 255, 255, 0.9);
+ }
+
+ /* Responsive design for modal */
+ @media (max-width: 768px) {
+ .modal-body-enhanced {
+ flex-direction: column;
+ max-height: 80vh;
+ }
-</html>
+ .metadata-sidebar {
+ min-width: unset;
+ max-width: unset;
+ border-left: none;
+ border-top: 1px solid var(--color-border);
+ }
+
+ .modal-header-enhanced {
+ padding: 1rem;
+ }
+
+ .memory-title {
+ flex-direction: column;
+ align-items: flex-start;
+ gap: 0.5rem;
+ }
+
+ .content-section-main,
+ .metadata-sidebar {
+ padding: 1rem;
+ }
+ }
+ </style>
+
+ </template>
+ </div>
+</div>
diff --git a/webui/components/settings/memory/memory-detail-modal.html b/webui/components/settings/memory/memory-detail-modal.html
new file mode 100644
index 000000000..719c12d3e
--- /dev/null
+++ b/webui/components/settings/memory/memory-detail-modal.html
@@ -0,0 +1,137 @@
+<div x-data>
+ <template x-if="$store.memoryDashboardStore && $store.memoryDashboardStore.detailMemory">
+ <div>
+ <!-- Modal Header with Memory Info -->
+ <div class="modal-header-enhanced">
+ <div class="header-left">
+ <div class="memory-title">
+ <span class="area-badge-large"
+ :style="`background: linear-gradient(135deg, ${$store.memoryDashboardStore.getAreaColor($store.memoryDashboardStore.detailMemory?.area)} 0%, ${$store.memoryDashboardStore.getAreaColor($store.memoryDashboardStore.detailMemory?.area)}cc 100%)`"
+ x-text="$store.memoryDashboardStore.detailMemory?.area?.toUpperCase() || 'UNKNOWN'"></span>
+ <h3>Memory Details</h3>
+ </div>
+ <div class="memory-meta-quick">
+ <span class="timestamp-badge" x-text="$store.memoryDashboardStore.formatTimestamp($store.memoryDashboardStore.detailMemory?.timestamp, true)"></span>
+ <span class="source-badge"
+ :class="$store.memoryDashboardStore.detailMemory?.knowledge_source ? 'knowledge' : 'conversation'"
+ x-text="$store.memoryDashboardStore.detailMemory?.knowledge_source ? 'Knowledge' : 'Conversation'"></span>
+ </div>
+ </div>
+ <div class="header-actions">
+ <button class="btn-action-header copy" @click="$store.memoryDashboardStore.copyToClipboard($store.memoryDashboardStore.formatMemoryForCopy($store.memoryDashboardStore.detailMemory))"
+ title="Copy Complete Memory with Metadata">
+ <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
+ <rect x="9" y="9" width="13" height="13" rx="2" ry="2"></rect>
+ <path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"></path>
+ </svg>
+ </button>
+ </div>
+ </div>
+
+ <!-- Modal Body -->
+ <div class="modal-body-enhanced">
+ <!-- Main Content Section -->
+ <div class="content-section-main">
+ <div class="content-block">
+ <h4>Memory Content</h4>
+ <div class="memory-content-display" x-html="$store.memoryDashboardStore.detailMemory?.content_full?.replace(/\n/g, '<br>')"></div>
+ </div>
+
+ <!-- Tags Section -->
+ <div class="content-block" x-show="$store.memoryDashboardStore.detailMemory?.tags && $store.memoryDashboardStore.detailMemory.tags.length > 0">
+ <h4>Tags</h4>
+ <div class="tags-display">
+ <template x-for="tag in $store.memoryDashboardStore.detailMemory?.tags || []" :key="tag">
+ <span class="tag-display" x-text="tag"></span>
+ </template>
+ </div>
+ </div>
+ </div>
+
+ <!-- Metadata Sidebar -->
+ <div class="metadata-sidebar">
+ <h4>Metadata</h4>
+
+ <!-- Basic Info -->
+ <div class="metadata-group">
+ <div class="metadata-item">
+ <span class="metadata-label">ID:</span>
+ <span class="metadata-value" x-text="$store.memoryDashboardStore.detailMemory?.id || 'N/A'"></span>
+ </div>
+ <div class="metadata-item">
+ <span class="metadata-label">Area:</span>
+ <span class="metadata-value" x-text="$store.memoryDashboardStore.detailMemory?.area || 'N/A'"></span>
+ </div>
+ <div class="metadata-item">
+ <span class="metadata-label">Source:</span>
+ <span class="metadata-value" x-text="$store.memoryDashboardStore.detailMemory?.knowledge_source ? 'Knowledge' : 'Conversation'"></span>
+ </div>
+ </div>
+
+ <!-- Timestamps -->
+ <div class="metadata-group">
+ <h5>Timestamps</h5>
+ <div class="metadata-item">
+ <span class="metadata-label">Created:</span>
+ <span class="metadata-value" x-text="$store.memoryDashboardStore.formatTimestamp($store.memoryDashboardStore.detailMemory?.timestamp, false)"></span>
+ </div>
+ </div>
+
+ <!-- Source Information -->
+ <div class="metadata-group" x-show="$store.memoryDashboardStore.detailMemory?.source_file">
+ <h5>Source File</h5>
+ <div class="metadata-item">
+ <span class="metadata-value source-file-display" x-text="$store.memoryDashboardStore.detailMemory?.source_file"></span>
+ </div>
+ </div>
+
+ <!-- All Custom Metadata -->
+ <div class="metadata-group" x-show="$store.memoryDashboardStore.detailMemory?.metadata && Object.keys($store.memoryDashboardStore.detailMemory.metadata).length > 0">
+ <h5>Additional Metadata</h5>
+ <template x-for="[key, value] in Object.entries($store.memoryDashboardStore.detailMemory?.metadata || {})" :key="key">
+ <div class="metadata-item">
+ <span class="metadata-label" x-text="key + ':'"></span>
+ <span class="metadata-value" x-text="typeof value === 'object' ? JSON.stringify(value) : value"></span>
+ </div>
+ </template>
+ </div>
+
+ <!-- Actions -->
+ <div class="metadata-group">
+ <h5>Actions</h5>
+ <div class="metadata-actions">
+ <button class="btn slim" @click="$store.memoryDashboardStore.copyToClipboard($store.memoryDashboardStore.formatMemoryForCopy($store.memoryDashboardStore.detailMemory))"
+ title="Copy Complete Memory with Metadata">
+ <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
+ <rect x="9" y="9" width="13" height="13" rx="2" ry="2"></rect>
+ <path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"></path>
+ </svg>
+ Copy All
+ </button>
+ <button class="btn slim" @click="$store.memoryDashboardStore.copyToClipboard($store.memoryDashboardStore.detailMemory?.content_full)"
+ title="Copy Content Only">
+ <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
+ <path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"></path>
+ <polyline points="14,2 14,8 20,8"></polyline>
+ </svg>
+ Copy Content
+ </button>
+ <button class="btn slim danger" @click="$store.memoryDashboardStore.deleteMemory($store.memoryDashboardStore.detailMemory)"
+ title="Delete Memory">
+ <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
+ <polyline points="3,6 5,6 21,6"></polyline>
+ <path d="M19,6V20a2,2,0,0,1-2,2H7a2,2,0,0,1-2-2V6m3,0V4a2,2,0,0,1,2-2h4a2,2,0,0,1,2,2V6"></path>
+ <line x1="10" y1="11" x2="10" y2="17"></line>
+ <line x1="14" y1="11" x2="14" y2="17"></line>
+ </svg>
+ Delete
+ </button>
+ </div>
+ </div>
+ </div>
+ </div>
+ </div>
+ </template>
+ </div>
+</template>
+</div>