Files
niri-ai-sidebar/aisidebar/aisidebar.py
Melvin Ragusa 58bd935af0 feat(aisidebar): implement Ollama availability handling and graceful startup
- Add comprehensive Ollama connection error handling strategy
- Implement OllamaClient with non-blocking initialization and connection checks
- Create OllamaAvailabilityMonitor for periodic Ollama connection tracking
- Update design and requirements to support graceful Ollama unavailability
- Add new project structure for AI sidebar module with initial implementation
- Enhance error handling to prevent application crashes when Ollama is not running
- Prepare for future improvements in AI sidebar interaction and resilience
2025-10-25 22:28:54 +02:00

74 lines
2.3 KiB
Python

from ignis import widgets
from ignis.window_manager import WindowManager
from ignis.services.niri import NiriService
from .chat_widget import ChatWidget
window_manager = WindowManager.get_default()
class AISidebar(widgets.RevealerWindow):
"""AI Chat Sidebar that slides in from the left side"""
def __init__(self):
# Create chat interface
self.chat_widget = ChatWidget()
# Content box - 400px wide to match QuickCenter
self.content_box = widgets.Box(
vertical=True,
spacing=0,
hexpand=False,
css_classes=["ai-sidebar"],
child=[self.chat_widget],
)
self.content_box.width_request = 400
self.content_box.set_halign("start") # Align to left side
# Revealer for slide animation
revealer = widgets.Revealer(
child=self.content_box,
transition_duration=300,
transition_type="slide_right", # Slide in from left
halign="start", # Align revealer to left
)
# Close button overlay (click outside to close)
close_button = widgets.Button(
vexpand=True,
hexpand=True,
can_focus=False,
on_click=lambda x: window_manager.close_window("AISidebar"),
)
main_overlay = widgets.Overlay(
css_classes=["popup-close"],
child=close_button,
overlays=[revealer],
)
super().__init__(
revealer=revealer,
child=main_overlay,
css_classes=["popup-close"],
hide_on_close=True,
visible=False,
namespace="AISidebar",
popup=True,
layer="overlay", # Same as QuickCenter
kb_mode="exclusive", # Same as QuickCenter
anchor=["left", "right", "top", "bottom"], # Anchor to ALL edges like QuickCenter
)
self.window_manager = window_manager
self.revealer = revealer
self.niri = NiriService.get_default()
self.connect("notify::visible", self._toggle_revealer)
def _toggle_revealer(self, *_):
"""Toggle revealer when window visibility changes"""
self.revealer.reveal_child = self.visible
if self.visible:
# Focus on input when opened
self.chat_widget.focus_input()