Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions plexe/core/object_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,18 +111,40 @@ def get_all(self, t: Type[T]) -> Dict[str, T]:
"""
return {name: item.item for name, item in self._items.items() if name.startswith(str(t))}

def delete(self, t: Type[T], name: str) -> None:
def delete(self, t: Type[T], name: str, confirm: bool = False) -> None:
"""
Delete an item by name.

:param t: type prefix for the item
:param name: the name of the item to delete
:param confirm: whether to show confirmation prompt (default: False for backward compatibility)
"""
uri = self._get_uri(t, name)

if uri in self._items:
item = self._items[uri]

if confirm:
print(f"About to delete: {uri}")
print(f"Item type: {type(item.item).__name__}")
print(f"Immutable: {item.immutable}")
response = input("Continue? (y/n): ")
if response.lower() != 'y':
logger.info(f"Delete cancelled for: {uri}")
return

del self._items[uri]
logger.info(f"Registry: Deleted {uri}")
else:
raise KeyError(f"Item '{uri}' not found in registry")
# Provide helpful error message with available items
similar_items = self.list_by_type(t)
if similar_items:
error_msg = f"Item '{uri}' not found. Available {t.__name__} items: {similar_items}"
else:
error_msg = f"No {t.__name__} items found in registry"

logger.warning(f"⚠️ {error_msg}")
raise KeyError(error_msg)

def clear(self) -> None:
"""
Expand Down
44 changes: 36 additions & 8 deletions plexe/ui/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -270,51 +270,74 @@
const [messages, setMessages] = useState([]);
const [input, setInput] = useState('');
const [isLoading, setIsLoading] = useState(false);
const [userScrolledUp, setUserScrolledUp] = useState(false);
const [showScrollButton, setShowScrollButton] = useState(false);
const messagesEndRef = useRef(null);
const messagesContainerRef = useRef(null);

const scrollToBottom = () => {
messagesEndRef.current?.scrollIntoView({ behavior: 'smooth' });
setShowScrollButton(false);
};

const handleScroll = (e) => {
const { scrollTop, scrollHeight, clientHeight } = e.target;
const isAtBottom = scrollHeight - scrollTop <= clientHeight + 10;
setUserScrolledUp(!isAtBottom);
};

useEffect(() => {
scrollToBottom();
}, [messages]);
if (messages.length > 0) {
const lastMessage = messages[messages.length - 1];
if (lastMessage.role === 'user') {
// User sent message - always scroll to bottom
scrollToBottom();
setShowScrollButton(false);
} else {
// AI sent message - check if user scrolled up
if (userScrolledUp) {
setShowScrollButton(true);
} else {
scrollToBottom();
}
}
}
}, [messages, userScrolledUp]);

useEffect(() => {
const unsubscribe = wsRuntime.subscribe((data) => {
if (data.type === 'status') return;

setMessages(prev => [...prev, {
id: data.id || Date.now().toString(),
role: data.role || 'assistant',
content: data.content
}]);
setIsLoading(false);
});

return unsubscribe;
}, [wsRuntime]);

const handleSubmit = (e) => {
e.preventDefault();
if (!input.trim() || isLoading) return;

const userMessage = {
id: Date.now().toString(),
role: 'user',
content: input.trim()
};

setMessages(prev => [...prev, userMessage]);
setInput('');
setIsLoading(true);

wsRuntime.send(userMessage.content);
};

return React.createElement('div', { className: 'flex flex-col h-full' },
// Messages area
React.createElement('div', { className: 'flex-1 overflow-y-auto p-4' },
React.createElement('div', {
className: 'flex-1 overflow-y-auto p-4 relative',
onScroll: handleScroll,
ref: messagesContainerRef
},
messages.length === 0 && React.createElement('div', { className: 'text-center text-gray-500 mt-8' },
React.createElement('p', { className: 'text-lg mb-2' }, '👋 Hello! I\'m your Plexe Assistant.'),
React.createElement('p', { className: 'text-sm' }, 'I help you build machine learning models through natural conversation.'),
Expand All @@ -332,6 +355,11 @@
),
React.createElement('div', { ref: messagesEndRef })
),
// Scroll to bottom button
showScrollButton && React.createElement('button', {
onClick: scrollToBottom,
className: 'fixed bottom-20 right-4 bg-blue-500 text-white rounded-full p-3 shadow-lg hover:bg-blue-600 transition-colors z-10'
}, '↓'),
// Input area
React.createElement('form', { onSubmit: handleSubmit, className: 'border-t p-4' },
React.createElement('div', { className: 'flex space-x-2' },
Expand Down
Loading