1/** 2 * AET Blood Epigenetic Engine v0.2 3 * Dynamic ABO nutrition / stress protocols driven by live biometrics + circadian phase. 4 * Educational wellness support only â not medical advice or diagnosis. 5 */ 6(function () { 7 'use strict'; 8 9 const VERSION = '0.2'; 10 const STRESS_HIGH = 55; // stress_balance_score 0â100 â high sympathetic proxy when elevated 11 const HRV_LOW_MS = 28; // low RMSSD suggests reduced parasympathetic tone 12 13 const TYPE_META = { 14 A: { nickname: 'The Cultivator', color: '#ff6644' }, 15 B: { nickname: 'The Nomad', color: '#44aaff' }, 16 AB: { nickname: 'The Enigma', color: '#aa44ff' }, 17 O: { nickname: 'The Hunter', color: '#00dd88' }, 18 }; 19 20 /** Base educational food matrices (static seed â dynamically re-ranked). */ 21 const BASE = { 22 A: { 23 prioritize: ['Leafy greens', 'Fatty fish', 'Tofu', 'Lentils', 'Olive oil', 'Berries', 'Garlic', 'Pineapple'], 24 moderate: ['Poultry (light)', 'Eggs (limited)', 'Seeds', 'Oats'], 25 avoid: ['Red meat', 'Excess dairy', 'Kidney beans', 'Processed wheat', 'Ultra-processed snacks'], 26 amino: ['Glycine', 'Tryptophan', 'L-theanine'], 27 always_support: ['Vitamin B12', 'Folate', 'Iron (gentle)'], 28 }, 29 B: { 30 prioritize: ['Green vegetables', 'Yogurt / kefir', 'Eggs', 'Lamb (moderate)', 'Oats', 'Beets', 'Olive oil', 'Berries'], 31 moderate: ['Fish', 'Rice', 'Nuts'], 32 avoid: ['Chicken (often reactive)', 'Corn', 'Lentils (excess)', 'Peanuts', 'Ultra-processed snacks'], 33 amino: ['Lysine', 'Magnesium-bound amino blends', 'Taurine'], 34 always_support: ['Magnesium', 'Vitamin D', 'Zinc'], 35 }, 36 AB: { 37 prioritize: ['Seafood', 'Tofu', 'Dairy (cultured)', 'Leafy greens', 'Olive oil', 'Berries', 'Turkey (light)', 'Seeds'], 38 moderate: ['Lamb', 'Rice', 'Eggs'], 39 avoid: ['Excess red meat', 'Caffeine overload', 'Corn syrup foods', 'Smoked meats'], 40 amino: ['L-glutamine', 'Glycine', 'Tryptophan'], 41 always_support: ['Vitamin C', 'Vitamin B-complex', 'Probiotics'], 42 }, 43 O: { 44 prioritize: ['Lean red meat (quality)', 'Fish', 'Spinach', 'Broccoli', 'Olive oil', 'Berries', 'Walnuts', 'Sweet potato'], 45 moderate: ['Eggs', 'Nuts', 'Rice'], 46 avoid: ['Wheat excess', 'Dairy excess', 'Kidney beans', 'Cabbage family excess', 'Ultra-processed snacks'], 47 amino: ['Creatine-support foods', 'L-carnitine rich proteins', 'Tyrosine'], 48 always_support: ['Iron', 'Vitamin B12', 'Vitamin D'], 49 }, 50 }; 51 52 const STRESS_BOOST = { 53 foods: ['Dark leafy greens', 'Blueberries', 'Fatty fish (omega-3)', 'Pumpkin seeds', 'Dark chocolate (70%+)', 'Chamomile tea', 'Avocado'], 54 adaptogens: ['Ashwagandha (educational)', 'Holy basil / tulsi', 'Magnesium-rich greens', 'Lemon / vitamin C foods'], 55 nutrients: ['Magnesium', 'Vitamin C', 'Omega-3', 'Glycine', 'L-theanine'], 56 }; 57 58 const PERFORMANCE_BOOST = { 59 foods: ['Quality protein', 'Beetroot', 'Eggs / tofu', 'Berries', 'Olive oil', 'Nuts / seeds', 'Fermented foods'], 60 focus: ['Cellular recovery', 'Training adaptation', 'Longevity habits'], 61 nutrients: ['Protein amino acids', 'Polyphenols', 'Electrolytes', 'Vitamin D'], 62 }; 63 64 function clamp(v, lo, hi) { 65 return Math.max(lo, Math.min(hi, v)); 66 } 67 68 function circadianPhase(date) { 69 const d = date || new Date(); 70 const h = d.getHours() + d.getMinutes() / 60; 71 if (h >= 5 && h < 11) { 72 return { id: 'morning', label: 'Morning focus', intent: 'alertness + steady fuel' }; 73 } 74 if (h >= 11 && h < 17) { 75 return { id: 'day', label: 'Daytime sustain', intent: 'performance + metabolic balance' }; 76 } 77 if (h >= 17 && h < 21) { 78 return { id: 'evening', label: 'Evening wind-down', intent: 'cortisol downshift + digestion' }; 79 } 80 return { id: 'night', label: 'Night regeneration', intent: 'sleep depth + cellular repair' }; 81 } 82 83 function normalizeType(abo) { 84 const t = String(abo || '').toUpperCase().replace(/[^ABO]/g, ''); 85 if (t === 'A' || t === 'B' || t === 'AB' || t === 'O') return t; 86 return null; 87 } 88 89 /** 90 * Pull live biometrics: Neural Terminal IndexedDB, then live module results. 91 */ 92 async function loadBiometrics() { 93 const out = { 94 source: 'none', 95 hrv_rmssd_ms: null, 96 hrv_sdnn_ms: null, 97 stress_balance_score: null, 98 heart_rate_bpm: null, 99 quality_score: null, 100 captured_at: null, 101 }; 102 103 try {
104 if (window.AeternoLocalStore && window.AeternoLocalStore.getLatestPayload) { 105 const nt = await window.AeternoLocalStore.getLatestPayload('neural-terminal'); 106 if (nt) { 107 out.source = 'neural-terminal'; 108 out.hrv_rmssd_ms = nt.hrv_rmssd_ms != null ? nt.hrv_rmssd_ms : null; 109 out.hrv_sdnn_ms = nt.hrv_sdnn_ms != null ? nt.hrv_sdnn_ms : null; 110 out.stress_balance_score = nt.stress_balance_score != null ? nt.stress_balance_score : null; 111 out.heart_rate_bpm = nt.heart_rate_bpm != null ? nt.heart_rate_bpm : null; 112 out.quality_score = nt.quality_score != null ? nt.quality_score : null; 113 out.captured_at = nt.recorded_at || nt.captured_at || null; 114 } 115 if (out.source === 'none') { 116 const sense = await window.AeternoLocalStore.getLatestPayload('aet-sense'); 117 if (sense) { 118 out.source = 'aet-sense-store'; 119 out.hrv_rmssd_ms = sense.hrv_rmssd_ms != null ? sense.hrv_rmssd_ms : null; 120 out.hrv_sdnn_ms = sense.hrv_sdnn_ms != null ? sense.hrv_sdnn_ms : null; 121 out.heart_rate_bpm = sense.heart_rate_bpm != null ? sense.heart_rate_bpm : null; 122 out.quality_score = sense.quality_score != null ? sense.quality_score : null; 123 out.captured_at = sense.recorded_at || sense.captured_at || null; 124 } 125 } 126 if (out.stress_balance_score == null) { 127 const voice = await window.AeternoLocalStore.getLatestPayload('aet-voice'); 128 if (voice && voice.vocal_stress_proxy != null) { 129 out.stress_balance_score = Number(voice.vocal_stress_proxy); 130 if (out.source === 'none') out.source = 'aet-voice-store'; 131 } 132 } 133 } 134 } catch (_) { /* offline / empty */ } 135 136 if (window.AetSense && typeof window.AetSense.getResult === 'function') { 137 const s = window.AetSense.getResult(); 138 if (s && s.heart_rate_bpm) { 139 if (out.source === 'none') out.source = 'aet-sense-live'; 140 if (out.hrv_rmssd_ms == null && s.hrv_rmssd_ms != null) out.hrv_rmssd_ms = s.hrv_rmssd_ms; 141 if (out.hrv_sdnn_ms == null && s.hrv_sdnn_ms != null) out.hrv_sdnn_ms = s.hrv_sdnn_ms; 142 if (out.heart_rate_bpm == null) out.heart_rate_bpm = s.heart_rate_bpm; 143 if (out.quality_score == null) out.quality_score = s.quality_score; 144 } 145 } 146 147 if (window.AetVoice && typeof window.AetVoice.getResult === 'function') { 148 const v = window.AetVoice.getResult(); 149 if (v && v.vocal_stress_proxy != null && out.stress_balance_score == null) { 150 out.stress_balance_score = Number(v.vocal_stress_proxy); 151 if (out.source === 'none') out.source = 'aet-voice-live'; 152 } 153 } 154 155 // Derive stress proxy from HRV if Neural Terminal stress missing 156 if (out.stress_balance_score == null && out.hrv_rmssd_ms != null) { 157 const hrvNorm = clamp(out.hrv_rmssd_ms / 80, 0, 1); 158 out.stress_balance_score = Math.round((1 - hrvNorm) * 100); 159 if (out.source === 'none') out.source = 'hrv-derived'; 160 } 161 162 return out; 163 } 164 165 function classifyTone(bio) { 166 const stress = bio.stress_balance_score != null ? bio.stress_balance_score : 40; 167 const hrv = bio.hrv_rmssd_ms != null ? bio.hrv_rmssd_ms : 40; 168 const sympathetic = stress >= STRESS_HIGH || hrv <= HRV_LOW_MS; 169 return { 170 mode: sympathetic ? 'sympathetic' : 'parasympathetic', 171 label: sympathetic 172 ? 'Sympathetic dominance (elevated stress proxy)' 173 : 'Parasympathetic balance (stable vitals proxy)', 174 stress_score: stress, 175 hrv_rmssd_ms: hrv, 176 }; 177 } 178 179 function unique(list) { 180 const seen = {}; 181 const out = []; 182 list.forEach(function (item) { 183 const k = String(item).toLowerCase(); 184 if (!seen[k]) { 185 seen[k] = true; 186 out.push(item); 187 } 188 }); 189 return out; 190 } 191 192 function buildProtocol(abo, rh, bio, when) { 193 const type = normalizeType(abo); 194 if (!type) { 195 return { error: 'Select a valid blood type (A, B, AB, or O).' }; 196 } 197 const phase = circadianPhase(when); 198 const tone = classifyTone(bio || {}); 199 const base = BASE[type]; 200 const meta = TYPE_META[type]; 201 202 let prioritize = base.prioritize.slice();
203 let nutrients = base.always_support.slice(); 204 let amino = base.amino.slice(); 205 let modeActions = []; 206 let circadianActions = []; 207 208 if (tone.mode === 'sympathetic') { 209 prioritize = unique(STRESS_BOOST.foods.concat(prioritize)); 210 nutrients = unique(['Magnesium', 'Vitamin C'].concat(STRESS_BOOST.nutrients).concat(nutrients)); 211 amino = unique(amino.concat(['Glycine', 'Tryptophan', 'L-theanine'])); 212 modeActions = [ 213 'Prioritize anti-inflammatory foods compatible with Type ' + type + '.', 214 'Increase magnesium + vitamin C density (food-first), aligned with ABO compatibility.', 215 'Favor adaptogen-leaning botanicals (educational): ' + STRESS_BOOST.adaptogens.slice(0, 3).join(', ') + '.', 216 'Reduce stimulants and ultra-processed foods while stress proxy is elevated.', 217 ]; 218 } else { 219 prioritize = unique(PERFORMANCE_BOOST.foods.concat(prioritize)); 220 nutrients = unique(PERFORMANCE_BOOST.nutrients.concat(nutrients)); 221 modeActions = [ 222 'Vitals look relatively stable â shift toward performance + recovery protocols.', 223 'Support cellular longevity habits: protein quality, polyphenols, sleep consistency.', 224 'Keep Type ' + type + ' avoid-list as soft constraints, not rigid dogma.', 225 ]; 226 } 227 228 if (phase.id === 'morning') { 229 circadianActions = [ 230 'Morning focus: hydrate, protein + greens, light movement before heavy caffeine.', 231 'Use brighter daylight exposure; keep breakfast ABO-aligned and anti-inflammatory if stressed.', 232 ]; 233 if (tone.mode === 'parasympathetic') { 234 circadianActions.push('Optional performance window: training / deep work after fuel.'); 235 } 236 } else if (phase.id === 'day') { 237 circadianActions = [ 238 'Daytime sustain: balanced plate (protein + colorful plants + healthy fats).', 239 'Keep snack density high in micronutrients; avoid blood-sugar spikes.', 240 ]; 241 } else if (phase.id === 'evening') { 242 circadianActions = [ 243 'Evening wind-down: lighter dinner, magnesium-rich greens, reduce late caffeine.', 244 'Support cortisol downshift â no high-intensity training this late if stress proxy is high.', 245 ]; 246 prioritize = unique(['Leafy greens', 'Fatty fish', 'Chamomile tea', 'Pumpkin seeds'].concat(prioritize)); 247 } else { 248 circadianActions = [ 249 'Night regeneration: fasting window if appropriate, dark cool room, no screens last hour.', 250 'Glycine / magnesium-leaning evening foods only if hungry â prioritize sleep over late meals.', 251 ]; 252 } 253 254 const summary = [ 255 'Type ' + type + (rh || '') + ' · ' + meta.nickname + ' · ' + phase.label + '.', 256 tone.label + ' (stress proxy ' + Math.round(tone.stress_score) + '/100' 257 + (tone.hrv_rmssd_ms != null ? ', RMSSD ~' + tone.hrv_rmssd_ms + ' ms' : '') + ').', 258 'Recommendations are dynamic educational protocols â not medical prescriptions.', 259 ].join(' '); 260 261 return { 262 version: VERSION, 263 blood_type_abo: type, 264 blood_type_rh: rh || null, 265 nickname: meta.nickname, 266 color: meta.color, 267 biometrics: bio || {}, 268 nervous_tone: tone, 269 circadian: phase, 270 foods: { 271 prioritize: prioritize.slice(0, 10), 272 moderate: base.moderate, 273 avoid: base.avoid, 274 }, 275 nutrients: { 276 focus: nutrients.slice(0, 8), 277 amino_acids: amino.slice(0, 6), 278 magnesium: tone.mode === 'sympathetic' || phase.id === 'evening' || phase.id === 'night', 279 vitamin_c: tone.mode === 'sympathetic', 280 }, 281 actions: { 282 biometric: modeActions, 283 circadian: circadianActions, 284 }, 285 summary: summary, 286 disclaimer: 'Educational wellness support inspired by blood-type patterns + live signal proxies. Not medical advice, diagnosis, or treatment.', 287 generated_at: new Date().toISOString(), 288 }; 289 } 290 291 async function generate(abo, rh, when) { 292 const bio = await loadBiometrics(); 293 return buildProtocol(abo, rh, bio, when || new Date()); 294 } 295 296 window.AetBloodEpigenetic = { 297 VERSION: VERSION, 298 TYPE_META: TYPE_META, 299 BASE: BASE, 300 loadBiometrics: loadBiometrics,
301 circadianPhase: circadianPhase, 302 buildProtocol: buildProtocol, 303 generate: generate, 304 normalizeType: normalizeType, 305 }; 306})();
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.