Directory Overview
Key Patterns
Plugin Entry (index.ts)
The plugin() function is the extension’s entry point. It:
- Registers all routes (one per page component).
- Injects global CSS via
injectPasturesCSS(). - Adds a sparkle button to the Rancher header that opens the AI drawer.
Sidebar Registration (product.ts)
Rancher extensions use three primitives to define sidebar structure:
| Function | Purpose |
|---|---|
virtualType() | Declares a sidebar entry pointing to a route |
basicType() | Groups entries under a section |
weightType() | Controls display order (higher weight = higher in the list) |
Tabbed Container Pages
Four pages act as containers for related sub-pages:OperationsPage
6 tabs — CIS Benchmarks, Etcd, Monitoring, Audit Log, Upgrade Risk, Backup & DR
HarvesterPage
7 tabs — VM overview, networks, images, volumes, templates, monitoring, settings
InfrastructurePage
3 tabs — Nodes, storage, networking
AIAgentsPage
3 tabs — Agent list, execution history, configuration
embedded prop to child page components to suppress their standalone headers when rendered as a tab.
API Client (lib/pasturesApi.ts)
All communication with the Pastures Engine goes through engineFetch(). This wrapper:
- Reads the Engine URL and API key from
localStorage. - Attaches the
Authorization: Bearer <key>header when configured. - Short-circuits to synthetic responses when
isGlobalDemoMode()returnstrue. - Returns responses through
safeJson()for safe parsing with fallback handling.
Demo Mode (lib/demoResponses.ts)
getDemoResponse(path) maps API paths to static response objects. Pages that use inline fetch instead of engineFetch define their own DEMO_* constants and check isGlobalDemoMode() in onMounted.