/* BioReveal — Shen.AI bioscan step (feature-flagged). * * Activated when ?shen=1 is in the URL AND window.SHEN_API_KEY is set. * Drop the API key into bioreveal.html as window.SHEN_API_KEY before this * loads, then activate via ?shen=1 to A/B against the legacy homemade * scan. When validated, swap in main.jsx's stepDef without code change. * * Returns the same shape as the legacy bioscan but with a `shen` field * holding the full 30-metric vital-signs result for Claude to interpret. */ const ShenStep = ({ value, onChange }) => { const containerRef = React.useRef(null); const sdkRef = React.useRef(null); const [status, setStatus] = React.useState("idle"); // idle | loading | scanning | done | error const [errMsg, setErrMsg] = React.useState(""); const [progress, setProgress] = React.useState(0); const [captured, setCaptured] = React.useState(!!value?.captured); const apiKey = (typeof window !== "undefined" && window.SHEN_API_KEY) || ""; const start = async () => { setErrMsg(""); setStatus("loading"); if (!apiKey) { setErrMsg("SHEN_API_KEY not set — falling back to legacy bioscan."); setStatus("error"); return; } try { // SDK loaded dynamically from Shen's CDN. Pinned version once we have // a contract; left as 'latest' for sandbox. const mod = await import("https://cdn.jsdelivr.net/npm/@shenai/sdk/+esm"); const { CreateSDK } = mod; const sdk = await CreateSDK({}, { onRuntimeInitialized: () => {} }); sdkRef.current = sdk; await sdk.initialize(apiKey, "", { onUserFlowFinished: handleFinished, onProgressUpdate: (p) => setProgress(Math.round((p || 0) * 100)), }); sdk.attachToCanvas(containerRef.current); setStatus("scanning"); } catch (err) { console.error("Shen init failed:", err); setErrMsg(err?.message || "Failed to load Shen.AI SDK"); setStatus("error"); } }; const handleFinished = () => { try { const sdk = sdkRef.current; const results = sdk.getMeasurementResults(); onChange({ captured: true, provider: "shen", shen: results, }); setCaptured(true); setStatus("done"); } catch (err) { console.warn("Shen results unavailable:", err); setStatus("error"); setErrMsg("Scan ran but no results returned. Try again or skip."); } }; const skip = () => { try { sdkRef.current?.deinitialize?.(); } catch {} onChange({ skipped: true }); setStatus("done"); setCaptured(false); }; React.useEffect(() => () => { try { sdkRef.current?.deinitialize?.(); } catch {} }, []); return ( <>
03 / 04 · Shen.AI bioscan · 60 sec

Camera on. Hold still. We read 30 signals.

Heart rate, HRV, breathing, blood pressure, stress, cardiac age, and 24 more — from one selfie video. Raw numbers stay private. You get the read.

{status === "idle" && (
Tap "Begin Shen scan"
)} {status === "loading" && (
Loading Shen.AI SDK…
)} {status === "scanning" && ( <>
● SHEN · {progress}%
30 SIGNALS
HOLD STILL
)} {status === "done" && captured && (
SHEN BIOSCAN COMPLETE
The AI puts it all together on the next page.
)} {status === "error" && (
SHEN UNAVAILABLE
{errMsg || "Unknown error"}
)}
{status === "idle" && ( <> )} {(status === "loading" || status === "scanning") && ( )} {status === "done" && ( )} {status === "error" && ( <> )}
); }; window.BR_STEPS = window.BR_STEPS || {}; window.BR_STEPS.ShenStep = ShenStep;