localfirst v0.1.0 / Hybrid AI Router

localfirst

On-device AI with dynamic hardware capability probing, in-browser model loading, confidence-aware routing, and zero-throw silent cloud fallback.

Host Hardware Probe Probing...
Compute / GPU
Checking...
CPU Cores
Checking...
Device RAM
Checking...
Wasm SIMD
Checking...
Speech API
Checking...
Network
Online
LLM: Ready STT: Ready TTS: Ready
Routing Policy Deck
Simulate Local Runtime Crash (OOM / WebGPU context lost)
Simulate Offline Environment
On-Browser Model Manager (ai.load) Status: Standby
Real-Time Routing Pipeline
INGRESS
Input Query
➔
GATE
localfirst Router
➔
ON-DEVICE
Local Provider
⇢
REMOTE
Cloud Provider
➔
RESOLVED
Output Result
Interactive AI Playground
[Command] "Turn on kitchen light" (Direct local execution)
[Summary] "Draft a 2-sentence meeting thank you" (Medium text)
[Audio STT] Voice audio buffer (Whisper-tiny on-device)
[Voice TTS] Speech synthesis prompt (SpeechT5 on-device)
[Reasoning] "Prove Riemann hypothesis & optimize Paxos" (Cloud escalation)
[Crash Test] Simulate WebGPU context loss (Silent fallback)
Live Observability Stream (.on('route') & .on('fallback'))
[INIT] Initializing localfirst hybrid engine...
System Architecture & Hybrid Dataflow

Zero-dependency hybrid orchestration topology: capability probing, confidence scoring, hardware-accelerated local execution, and silent cloud fallback.

SIMULATE ROUTE:
localfirst Hybrid AI System Architecture Clean, non-overlapping architectural dataflow showing client ingress, capability probing, hybrid decision routing, local execution, and silent cloud fallback. CLIENT ENVIRONMENT LOCALFIRST CORE ENGINE EXECUTION RUNTIMES CONVERGENCE & OUTPUT SDK CALLER Client Application ai.ask() · speak() ai.askStream() (SSE) Browser · Node · Edge HARDWARE PROBE Capability Probe detect() · WebGPU · RAM CPU Cores · Net RTT 15s TTL Cache · <2ms HYBRID ROUTER Hybrid Decision Router Confidence Gate: P ≥ 0.70 Complexity & Rules Balancer auto · prefer-local · cloud RESILIENCE Silent Fallback Guard Catches OOM / GPU Lost Zero Crash · Auto Handoff Event Bus: route · fallback TIER 1 · LOCAL Local Provider In-Browser WebGPU LLM Web Speech STT / TTS · Wasm Zero Egress · Sub-100ms Latency TIER 2 · REMOTE Cloud & Daemons OpenAI · Gemini · OpenRouter Ollama / vLLM (localhost:11434) SSE & WebSocket (WSS) Stream UNIFIED OUTPUT Resolved Result { text: string, source: 'local'|'cloud', confidence: 0.94 } Zero-throw exception guarantee Returns to Caller SDK TASK PROFILE P ≥ 0.70 ESCALATE SILENT FALLBACK (ON OOM / ERROR) GUARD LOCAL CLOUD RETURN to caller UNIFIED PAYLOAD TO CALLER LEGEND Synchronous Call / Task Ingress Decision Arbiter (Hybrid Router) Confident Route (P ≥ 0.70) Silent Fallback on Error / OOM
ACTIVE TOPOLOGY: Complete system overview. Capability detection informs hybrid router; tasks balance between local WebGPU and cloud endpoints with silent fallback. ON-DEVICE PATH: High-confidence query (P ≥ 0.70) routed directly to In-Browser WebGPU LLM / Web Speech. Zero cloud data egress, sub-100ms latency. CLOUD ESCALATION: Complex multi-step reasoning or incapable hardware escalated to remote endpoints (Gemini / OpenAI / Ollama daemon via SSE). SILENT FALLBACK CIRCUIT: Local WebGPU OOM or context loss automatically caught by Resilience Guard and re-routed to Cloud without throwing exceptions.
Node Module Specifications Production Ready · 24/24 Unit Tests Passing
Package Name
@ondevice/localfirst
Runtime Dependencies
0 Dependencies
Distribution Footprint
5.1 KB (ESM) · 6.2 KB (IIFE)
Environments
Node.js (>= 18) & Browsers
Hardware Acceleration
WebGPU, Wasm SIMD, Speech APIs
Failure Model
Zero-Throw Silent Fallback
Designed in hemanth-module-style: lightweight, functional default factory, dual ESM/CJS exports, no runtime dependencies, and seamless capability parity across server and client environments.
Installation & Usage Guide ESM & CJS Compatible
1. Install via npm:
npm install @ondevice/localfirst
2. Three-Line Quickstart:
import localfirst from '@ondevice/localfirst';

const ai = await localfirst();
const res = await ai.ask('Turn on the living room lights');
console.log(res.text, res.source); // [local] ... in 28ms
3. Multimodal: STT Audio Transcription & TTS Voice Synthesis:
// Pre-warm in-browser Whisper-tiny or SpeechT5
await ai.load('stt');
await ai.load('tts');

// Speech-to-text with automatic confidence routing & silent cloud fallback
const audio = new Uint8Array(16000);
const transcript = await ai.transcribe(audio);

// Text-to-speech synthesis (renders audio directly through device speakers)
await ai.speak('Task completed natively on-device with zero cloud latency');
4. Declarative Routing Rules & Silent Fallback Observability:
const ai = await localfirst({
  // Declarative routing constraints
  rules: [
    { match: /confidential|private|ssn/i, target: 'local', reason: 'privacy strict' },
    { if: ({ complexity }) => complexity > 0.8, target: 'cloud', reason: 'high reasoning' }
  ],
  cloud: {
    apiKey: process.env.GEMINI_API_KEY
  }
});

// Real-time event hooks for telemetry
ai.on('route', (e) => console.log(`Routed ${e.task} -> ${e.target} (${e.reason})`));
ai.on('fallback', (e) => console.warn(`Silently escalated to cloud: ${e.reason}`));