Lib (react_ui/src/lib/)
Non-React utility modules — native bridge, AI integration, theme system, and shared helpers.
Structure
Modules
native/ — Native Bridge Bootstrap
Bootstraps the window.__SONGBIRD__ global that the sync engine’s transports depend on.
| File | Purpose |
|---|---|
window.d.ts | TypeScript declarations for window.__SONGBIRD__ global — backend event system, native function dispatch. |
check_native_interop.js | Bootstraps window.__SONGBIRD__ at import time. Warns in dev mode when running outside the backend bridge. |
native.js and native.d.ts have been deleted. All command dispatch now goes through send() from @/sync/api or invoke() from @/sync/transports/promiseHandler.
ai/ — AI Copilot (Multi-Provider)
Modular AI copilot with intent-driven speed optimization and multi-provider abstraction.
Architecture
Request Pipeline
Speed Optimizations
| Optimization | File | Impact |
|---|---|---|
| Slash commands (skip LLM) | shortcuts.ts | 100% faster for /bpm, /vol, etc. |
| Dynamic tool subset | tools.ts | 30-50% TTFT — 2 tools instead of 9 |
| Disable thinking for simple tasks | copilot.ts | 20-40% — skip reasoning tokens |
| Smart model routing | router.ts | 40-60% — Flash Lite for trivial |
| Modular prompt (smaller) | prompts.ts | 10-20% TTFT — 2KB vs 8KB |
| Plugin param cache | param-cache.ts | Eliminates 1 round-trip (~2-4s) |
| Conversation compaction | copilot.ts | 10-30% TTFT for long threads |
| Context caching | providers/gemini.ts | 30-60% TTFT on repeated calls |
Provider Interface
Specialized Agents
The AI copilot uses a multi-agent architecture where different agents handle different types of requests:| Agent | File | Specialization |
|---|---|---|
| Composer | agents/composer.ts | Writing .bird patterns, melodies, chord progressions, arrangements |
| Mix Engineer | agents/mix-engineer.ts | Adjusting levels, panning, EQ, compression, spatial effects |
| Sound Designer | agents/sound-designer.ts | Tweaking synth parameters, creating presets, macro mapping |
| Audio Creator | agents/audio-creator.ts | Generating audio via Lyria (text-to-music, style transfer) |
ml.generate_lyria3 sync command (Lyria 3 Pro in Rust), MIDI → clip.create_midi_clip + ml.chat with intentOverride: bird_edit so the composer role fills the empty clip.
theme/ — Theme System
| File | Purpose |
|---|---|
index.ts | Theme detection and application. Supports auto (follows system), dark, and light modes. Injects CSS variables. |
dark.css | Dark theme CSS custom properties (colors, shadows, surfaces). |
light.css | Light theme CSS custom properties. |
Conventions
isPlugin— Boolean flag (truewhen running inside the native WebView,falsein browser dev mode). Guards all native function calls.cn()— Class name merging utility (wrapsclsx+tailwind-merge). Use this instead of raw template literals for conditional Tailwind classes.- No React in
lib/— This layer should remain framework-agnostic. No hooks, no JSX. Components that need these utilities import from@/lib.