-
-
Hybrid Routing Telemetry — On-Device vs Cloud share, latency ms, PII bytes shielded & cost savings
-
Firebase AI Logic v12.19 Runtime Integration, Zero-Secret BYO Config & Chrome v139+ Setup
-
Offline On-Device Mode — Layer-0 PII Shield & ESI-1 Pediatric Anaphylaxis Triage (0 bytes PII exposed)
-
Seamless Cloud Fallback — PII-Redacted Deep Polypharmacy Audit routed to Cloud gemini-3.8-flash via App Check
Inspiration
Paramedics, rural field clinicians, and disaster-response medics face a high-stakes dilemma where cloud-only LLMs fail and on-device-only LLMs hit capability limits:
- Strict Patient Privacy: Raw intake notes contain names, MRNs, dates of birth, phone numbers, and home addresses that must never leave the clinician's device.
- Offline / Spotty Connectivity: In rural ambulances, mountain clinics, and disaster zones, cell reception drops right when clinicians need rapid Emergency Severity Index (ESI) triage most.
- Complex Clinical Reasoning: Deep multi-drug polypharmacy interaction audits (CYP3A4 / P-gp / QT prolongation) and multi-turn hospital trauma handoffs exceed single-turn on-device limits and need Cloud Gemini reasoning — strictly after PII has been scrubbed locally.
What it does
FieldShield AI is an Apache-2.0 open-source Chrome Web App powered by the official Firebase AI Logic SDK ([email protected], firebase/ai + firebase/app-check):
- Layer-0 On-Device PII Shield & Offline ESI Triage (
InferenceMode.ONLY_ON_DEVICE): Deterministically redacts patient names, MRNs/IDs, DOBs, phone numbers, emails, and addresses 100% locally in Chrome (src/core/triageEngine.ts) and computes immediate ESI 1–5 resuscitation actions even with Offline Mode active (0msnetwork,$0cloud cost,0 bytesPII exposed). - Adaptive Hybrid Clinical Synthesis (
InferenceMode.PREFER_ON_DEVICE-> Cloud Fallback):- Rapid single-turn SOAP notes stay on-device via Gemini Nano 4 (initialized on user gesture via
model.initializeDeviceModel(progressCb)). - Deep Polypharmacy Interaction Audits and Multi-Turn SBAR Hospital Handoffs automatically hand off only the locally-scrubbed, PII-free clinical abstract through Firebase App Check to current Cloud Gemini (
gemini-3.5-flash-lite/gemini-3.8-flash) — zero deprecated Gemini 2.5 models.
- Rapid single-turn SOAP notes stay on-device via Gemini Nano 4 (initialized on user gesture via
- Live Hybrid Path Visualizer & Telemetry Audit Log (
HybridFlowSvg.tsx+?tab=telemetry): Visualizes the active On-Device vs Cloud branch in real time, supports all 4 Firebase AI Logic modes (PREFER_ON_DEVICE,ONLY_ON_DEVICE,PREFER_IN_CLOUD,ONLY_IN_CLOUD), includes an Offline / Airplane Mode toggle, and logsInferenceSource.ON_DEVICEvsInferenceSource.IN_CLOUD, latency (ms), PII bytes shielded, and cloud cost saved. - Zero-Secrets BYO Firebase Runtime Config (
?tab=firebase): No.envfiles, API keys, or App Check debug tokens are committed to git. Judges can test immediately on GitHub Pages or paste their own Firebase Web App config + App Check web attestation site key into browsersessionStorageto run live against their Firebase project.
How we built it
- Firebase AI Logic Web SDK (
[email protected]): Real runtime imports and calls insrc/ai/firebaseHybridClient.ts(initializeApp,initializeAppCheck,getAI(..., { backend: new GoogleAIBackend() }),getGenerativeModel(ai, { mode: InferenceMode.PREFER_ON_DEVICE, inCloudParams: { model: 'gemini-3.5-flash-lite' } }),model.initializeDeviceModel(),model.generateContent(), andresult.response.inferenceSource). - Frontend & Testing: TypeScript 5.8, React 19, Tailwind CSS v4, Vite 6, custom SVG Hybrid Routing Visualizer, and native Node 22 unit tests (
src/core/triageEngine.test.ts— 3/3 passing, verifying zero PII leakage, offline ESI-1 anaphylaxis detection, and non-deprecated Gemini 3.5/3.8 routing).
Challenges we ran into
Designing a seamless, judge-verifiable Hybrid AI experience that genuinely calls firebase/ai v12.19 + firebase/app-check at runtime while never leaking App Check debug tokens or live keys in a public Apache-2.0 repository — solved with .env.example, browser sessionStorage BYO runtime config, and transparent local offline resilience.
What's next for FieldShield AI
Multimodal on-device JPEG/PNG wound and ECG strip screening via Chrome Prompt API multimodal input, FHIR R4 export for hospital EHR handoffs, and Android/iOS Companion clients sharing the same Firebase AI Logic hybrid policy.
Built With
- app-check
- chrome-built-in-ai
- firebase
- firebase-ai-logic
- gemini
- gemini-nano
- react
- tailwindcss
- typescript
- vite