Skip to content

Frontend API

Your frontend module must export a setup(ctx) function. It receives a SpindleFrontendContext for host DOM rendering, events, backend communication, and opt-in sandbox frames.

import type { SpindleFrontendContext } from 'lumiverse-spindle-types'

export function setup(ctx: SpindleFrontendContext) {
  // Your initialization code here

  // Return a cleanup function (optional)
  return () => {
    ctx.dom.cleanup()
  }
}

Alternatively, export a teardown() function:

export function setup(ctx: SpindleFrontendContext) {
  // init
}

export function teardown() {
  // cleanup
}

API Surface

Frontend UI can follow two supported rendering paths:

  • direct host rendering through ctx.dom.* and ctx.ui.*
  • isolated iframe rendering through ctx.dom.createSandboxFrame(...) and ctx.messages.renderWidget(...)
Category Permission Description
DOM Helper Free Inject sanitized HTML/CSS in the host DOM, target specific chat messages with virtualizer-safe replay, and create host-managed sandbox frames
UI Event Helpers Free Keyboard/Drawer/Settings state and DOM Action delegation
HTML Islands Free Auto-isolation of styled HTML in messages, and how to opt out
Events Free Subscribe to WebSocket events, emit custom events
UI Placement Varies Drawer tabs, float widgets, dock panels, modals, context menus, input bar actions
Shared Components Free Mount Lumiverse's first-party React components — model picker, form atoms, searchable selects, pagination — into extension-owned DOM
Backend Communication Free Send/receive messages to/from backend worker
Frontend Process Lifecycle Free Register backend-spawned frontend process handlers
Message Tags Free Intercept custom XML tags in chat messages
Display Resolver Free Resolve message display (macros, format, regex) in the browser for chats your extension owns
File Uploads Free Open file picker and read selected files