@thebriangao/totem 1.4.4 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.dev.vars.example +5 -0
- package/.dockerignore +5 -0
- package/.env.example +29 -20
- package/CHANGELOG.md +99 -1
- package/CONTRIBUTING.md +48 -116
- package/Dockerfile +46 -12
- package/README.md +172 -498
- package/SECURITY.md +36 -59
- package/TOOLS.md +448 -311
- package/WHOOP.md +497 -2659
- package/assets/brand/SOURCES.md +38 -0
- package/assets/brand/totem.png +0 -0
- package/assets/brand/totem.svg +13 -0
- package/assets/fonts/Manrope-OFL.txt +93 -0
- package/assets/fonts/manrope-latin.woff2 +0 -0
- package/dist/build_info.js +5 -0
- package/dist/build_info.js.map +1 -0
- package/dist/cli/app.js +675 -0
- package/dist/cli/app.js.map +1 -0
- package/dist/cli/auth.js +297 -0
- package/dist/cli/auth.js.map +1 -0
- package/dist/cli/auth_flow.js +268 -0
- package/dist/cli/auth_flow.js.map +1 -0
- package/dist/cli/browser_login.js +368 -0
- package/dist/cli/browser_login.js.map +1 -0
- package/dist/cli/clients.js +403 -0
- package/dist/cli/clients.js.map +1 -0
- package/dist/cli/deploy_record.js +96 -0
- package/dist/cli/deploy_record.js.map +1 -0
- package/dist/cli/index.js +39 -575
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/links.js +28 -0
- package/dist/cli/links.js.map +1 -0
- package/dist/cli/logo.js +63 -0
- package/dist/cli/logo.js.map +1 -0
- package/dist/cli/setup.js +1157 -1017
- package/dist/cli/setup.js.map +1 -1
- package/dist/cli/spawn.js +80 -0
- package/dist/cli/spawn.js.map +1 -0
- package/dist/cli/sys.js +219 -0
- package/dist/cli/sys.js.map +1 -0
- package/dist/cli/ui.js +712 -463
- package/dist/cli/ui.js.map +1 -1
- package/dist/cli/update.js +425 -282
- package/dist/cli/update.js.map +1 -1
- package/dist/cloudflare/token_store.js +48 -0
- package/dist/cloudflare/token_store.js.map +1 -0
- package/dist/cloudflare/worker.js +155 -0
- package/dist/cloudflare/worker.js.map +1 -0
- package/dist/data/behaviors.js +2733 -617
- package/dist/data/behaviors.js.map +1 -1
- package/dist/data/endpoint_catalog.js +2681 -0
- package/dist/data/endpoint_catalog.js.map +1 -0
- package/dist/data/exercises.js +373 -4859
- package/dist/data/exercises.js.map +1 -1
- package/dist/data/garments.js +19 -0
- package/dist/data/garments.js.map +1 -0
- package/dist/data/sports.js +219 -208
- package/dist/data/sports.js.map +1 -1
- package/dist/lib/activity_list.js +123 -0
- package/dist/lib/activity_list.js.map +1 -0
- package/dist/lib/activity_records.js +195 -0
- package/dist/lib/activity_records.js.map +1 -0
- package/dist/lib/activity_results.js +44 -0
- package/dist/lib/activity_results.js.map +1 -0
- package/dist/lib/activity_types.js +164 -0
- package/dist/lib/activity_types.js.map +1 -0
- package/dist/lib/brand.js +63 -0
- package/dist/lib/brand.js.map +1 -0
- package/dist/lib/clock.js +24 -0
- package/dist/lib/clock.js.map +1 -0
- package/dist/lib/coach_session.js +345 -0
- package/dist/lib/coach_session.js.map +1 -0
- package/dist/lib/concurrency.js.map +1 -1
- package/dist/lib/dates.js +19 -0
- package/dist/lib/dates.js.map +1 -1
- package/dist/lib/env_file.js +195 -0
- package/dist/lib/env_file.js.map +1 -0
- package/dist/lib/health_plans_write.js +44 -0
- package/dist/lib/health_plans_write.js.map +1 -0
- package/dist/lib/heart_rate.js +34 -0
- package/dist/lib/heart_rate.js.map +1 -0
- package/dist/lib/highlight.js +81 -0
- package/dist/lib/highlight.js.map +1 -0
- package/dist/lib/install_links.js +47 -0
- package/dist/lib/install_links.js.map +1 -0
- package/dist/lib/instant.js +50 -0
- package/dist/lib/instant.js.map +1 -0
- package/dist/lib/journal_behaviors.js +382 -0
- package/dist/lib/journal_behaviors.js.map +1 -0
- package/dist/lib/lift_catalog.js +218 -0
- package/dist/lib/lift_catalog.js.map +1 -0
- package/dist/lib/lift_history.js +66 -0
- package/dist/lib/lift_history.js.map +1 -0
- package/dist/lib/lift_sets.js +146 -0
- package/dist/lib/lift_sets.js.map +1 -0
- package/dist/lib/lift_tool.js +20 -0
- package/dist/lib/lift_tool.js.map +1 -0
- package/dist/lib/profile_settings.js +101 -0
- package/dist/lib/profile_settings.js.map +1 -0
- package/dist/lib/screen_content.js +44 -0
- package/dist/lib/screen_content.js.map +1 -0
- package/dist/lib/timezone.js +48 -6
- package/dist/lib/timezone.js.map +1 -1
- package/dist/lib/walk.js +6 -1
- package/dist/lib/walk.js.map +1 -1
- package/dist/lib/weight_readings.js +61 -0
- package/dist/lib/weight_readings.js.map +1 -0
- package/dist/projections/activities.js +193 -0
- package/dist/projections/activities.js.map +1 -0
- package/dist/projections/alarm_schedule.js +102 -0
- package/dist/projections/alarm_schedule.js.map +1 -0
- package/dist/projections/coach.js +203 -0
- package/dist/projections/coach.js.map +1 -0
- package/dist/projections/community.js +165 -0
- package/dist/projections/community.js.map +1 -0
- package/dist/projections/health_features.js +167 -0
- package/dist/projections/health_features.js.map +1 -0
- package/dist/projections/hormonal_insights.js +239 -0
- package/dist/projections/hormonal_insights.js.map +1 -0
- package/dist/projections/journal_v2.js +157 -0
- package/dist/projections/journal_v2.js.map +1 -0
- package/dist/projections/lift_cards.js +115 -0
- package/dist/projections/lift_cards.js.map +1 -0
- package/dist/projections/lift_exercise_v2.js +131 -0
- package/dist/projections/lift_exercise_v2.js.map +1 -0
- package/dist/projections/lift_library_v2.js +67 -0
- package/dist/projections/lift_library_v2.js.map +1 -0
- package/dist/projections/lift_sessions.js +211 -0
- package/dist/projections/lift_sessions.js.map +1 -0
- package/dist/projections/memory.js +95 -0
- package/dist/projections/memory.js.map +1 -0
- package/dist/projections/milestones.js +119 -0
- package/dist/projections/milestones.js.map +1 -0
- package/dist/projections/profile_v2.js +150 -0
- package/dist/projections/profile_v2.js.map +1 -0
- package/dist/projections/settings_v2.js +153 -0
- package/dist/projections/settings_v2.js.map +1 -0
- package/dist/projections/sleep.js +4 -21
- package/dist/projections/sleep.js.map +1 -1
- package/dist/projections/v2/calendar.js +43 -0
- package/dist/projections/v2/calendar.js.map +1 -0
- package/dist/projections/v2/core_common.js +86 -0
- package/dist/projections/v2/core_common.js.map +1 -0
- package/dist/projections/v2/core_home.js +136 -0
- package/dist/projections/v2/core_home.js.map +1 -0
- package/dist/projections/v2/core_sleep_need.js +23 -0
- package/dist/projections/v2/core_sleep_need.js.map +1 -0
- package/dist/projections/v2/day.js +92 -0
- package/dist/projections/v2/day.js.map +1 -0
- package/dist/projections/v2/heart_rate.js +54 -0
- package/dist/projections/v2/heart_rate.js.map +1 -0
- package/dist/projections/v2/history.js +140 -0
- package/dist/projections/v2/history.js.map +1 -0
- package/dist/projections/v2/now.js +39 -0
- package/dist/projections/v2/now.js.map +1 -0
- package/dist/projections/v2/recovery.js +77 -0
- package/dist/projections/v2/recovery.js.map +1 -0
- package/dist/projections/v2/sleep.js +218 -0
- package/dist/projections/v2/sleep.js.map +1 -0
- package/dist/projections/v2/strain.js +39 -0
- package/dist/projections/v2/strain.js.map +1 -0
- package/dist/projections/v2/stress.js +92 -0
- package/dist/projections/v2/stress.js.map +1 -0
- package/dist/projections/v2/trend.js +205 -0
- package/dist/projections/v2/trend.js.map +1 -0
- package/dist/projections/weekly_plan.js +66 -0
- package/dist/projections/weekly_plan.js.map +1 -0
- package/dist/projections/weight_readings.js +57 -0
- package/dist/projections/weight_readings.js.map +1 -0
- package/dist/projections/workout.js +37 -15
- package/dist/projections/workout.js.map +1 -1
- package/dist/schemas/activities.js +123 -0
- package/dist/schemas/activities.js.map +1 -0
- package/dist/schemas/alarm_schedule.js +62 -0
- package/dist/schemas/alarm_schedule.js.map +1 -0
- package/dist/schemas/coach.js +76 -8
- package/dist/schemas/coach.js.map +1 -1
- package/dist/schemas/community.js +70 -0
- package/dist/schemas/community.js.map +1 -0
- package/dist/schemas/health.js +36 -0
- package/dist/schemas/health.js.map +1 -0
- package/dist/schemas/hormonal_insights.js +90 -0
- package/dist/schemas/hormonal_insights.js.map +1 -0
- package/dist/schemas/journal.js +4 -0
- package/dist/schemas/journal.js.map +1 -1
- package/dist/schemas/journal_v2.js +106 -0
- package/dist/schemas/journal_v2.js.map +1 -0
- package/dist/schemas/memory.js +42 -0
- package/dist/schemas/memory.js.map +1 -0
- package/dist/schemas/milestones.js +39 -0
- package/dist/schemas/milestones.js.map +1 -0
- package/dist/schemas/profile_v2.js +60 -0
- package/dist/schemas/profile_v2.js.map +1 -0
- package/dist/schemas/settings_v2.js +56 -0
- package/dist/schemas/settings_v2.js.map +1 -0
- package/dist/schemas/sleep.js +8 -1
- package/dist/schemas/sleep.js.map +1 -1
- package/dist/schemas/strength.js +10 -1
- package/dist/schemas/strength.js.map +1 -1
- package/dist/schemas/strength_v2.js +190 -0
- package/dist/schemas/strength_v2.js.map +1 -0
- package/dist/schemas/v2/calendar.js +8 -0
- package/dist/schemas/v2/calendar.js.map +1 -0
- package/dist/schemas/v2/core_common.js +42 -0
- package/dist/schemas/v2/core_common.js.map +1 -0
- package/dist/schemas/v2/day.js +73 -0
- package/dist/schemas/v2/day.js.map +1 -0
- package/dist/schemas/v2/now.js +25 -0
- package/dist/schemas/v2/now.js.map +1 -0
- package/dist/schemas/v2/recovery.js +35 -0
- package/dist/schemas/v2/recovery.js.map +1 -0
- package/dist/schemas/v2/sleep.js +44 -0
- package/dist/schemas/v2/sleep.js.map +1 -0
- package/dist/schemas/v2/strain.js +16 -0
- package/dist/schemas/v2/strain.js.map +1 -0
- package/dist/schemas/v2/stress.js +20 -0
- package/dist/schemas/v2/stress.js.map +1 -0
- package/dist/schemas/v2/trend.js +42 -0
- package/dist/schemas/v2/trend.js.map +1 -0
- package/dist/schemas/weekly_plan.js +31 -0
- package/dist/schemas/weekly_plan.js.map +1 -0
- package/dist/schemas/weight.js +28 -0
- package/dist/schemas/weight.js.map +1 -0
- package/dist/scripts/build_behaviors.js +114 -0
- package/dist/scripts/build_behaviors.js.map +1 -0
- package/dist/scripts/cognito_bootstrap.js +9 -277
- package/dist/scripts/cognito_bootstrap.js.map +1 -1
- package/dist/scripts/gen_activity_catalogs.js +104 -0
- package/dist/scripts/gen_activity_catalogs.js.map +1 -0
- package/dist/server-admin.js +156 -0
- package/dist/server-admin.js.map +1 -0
- package/dist/server-http.js +270 -48
- package/dist/server-http.js.map +1 -1
- package/dist/server.js +136 -23
- package/dist/server.js.map +1 -1
- package/dist/tools/annotations.js +15 -0
- package/dist/tools/annotations.js.map +1 -0
- package/dist/tools/define.js +31 -0
- package/dist/tools/define.js.map +1 -0
- package/dist/tools/register.js +59 -94
- package/dist/tools/register.js.map +1 -1
- package/dist/tools/resources.js +70 -0
- package/dist/tools/resources.js.map +1 -0
- package/dist/tools/slim_schema.js +90 -0
- package/dist/tools/slim_schema.js.map +1 -0
- package/dist/tools/v2/activity_delete.js +63 -17
- package/dist/tools/v2/activity_delete.js.map +1 -1
- package/dist/tools/v2/activity_edit.js +396 -0
- package/dist/tools/v2/activity_edit.js.map +1 -0
- package/dist/tools/v2/activity_log.js +152 -0
- package/dist/tools/v2/activity_log.js.map +1 -0
- package/dist/tools/v2/calendar.js +19 -21
- package/dist/tools/v2/calendar.js.map +1 -1
- package/dist/tools/v2/coach_ask.js +74 -110
- package/dist/tools/v2/coach_ask.js.map +1 -1
- package/dist/tools/v2/coach_history.js +120 -0
- package/dist/tools/v2/coach_history.js.map +1 -0
- package/dist/tools/v2/community.js +124 -0
- package/dist/tools/v2/community.js.map +1 -0
- package/dist/tools/v2/cycle.js +63 -15
- package/dist/tools/v2/cycle.js.map +1 -1
- package/dist/tools/v2/cycle_log.js +289 -32
- package/dist/tools/v2/cycle_log.js.map +1 -1
- package/dist/tools/v2/day.js +126 -24
- package/dist/tools/v2/day.js.map +1 -1
- package/dist/tools/v2/health.js +116 -0
- package/dist/tools/v2/health.js.map +1 -0
- package/dist/tools/v2/hr_zones_set.js +134 -34
- package/dist/tools/v2/hr_zones_set.js.map +1 -1
- package/dist/tools/v2/journal.js +75 -17
- package/dist/tools/v2/journal.js.map +1 -1
- package/dist/tools/v2/journal_log.js +306 -65
- package/dist/tools/v2/journal_log.js.map +1 -1
- package/dist/tools/v2/lift_exercise.js +125 -22
- package/dist/tools/v2/lift_exercise.js.map +1 -1
- package/dist/tools/v2/lift_exercise_set.js +291 -0
- package/dist/tools/v2/lift_exercise_set.js.map +1 -0
- package/dist/tools/v2/lift_library.js +51 -12
- package/dist/tools/v2/lift_library.js.map +1 -1
- package/dist/tools/v2/lift_log.js +309 -72
- package/dist/tools/v2/lift_log.js.map +1 -1
- package/dist/tools/v2/lift_sessions.js +248 -0
- package/dist/tools/v2/lift_sessions.js.map +1 -0
- package/dist/tools/v2/lift_template.js +232 -0
- package/dist/tools/v2/lift_template.js.map +1 -0
- package/dist/tools/v2/memory.js +45 -0
- package/dist/tools/v2/memory.js.map +1 -0
- package/dist/tools/v2/memory_set.js +107 -0
- package/dist/tools/v2/memory_set.js.map +1 -0
- package/dist/tools/v2/milestones.js +50 -0
- package/dist/tools/v2/milestones.js.map +1 -0
- package/dist/tools/v2/now.js +49 -0
- package/dist/tools/v2/now.js.map +1 -0
- package/dist/tools/v2/preferences.js +51 -0
- package/dist/tools/v2/preferences.js.map +1 -0
- package/dist/tools/v2/preferences_set.js +388 -0
- package/dist/tools/v2/preferences_set.js.map +1 -0
- package/dist/tools/v2/profile.js +54 -22
- package/dist/tools/v2/profile.js.map +1 -1
- package/dist/tools/v2/profile_update.js +167 -55
- package/dist/tools/v2/profile_update.js.map +1 -1
- package/dist/tools/v2/raw.js +91 -34
- package/dist/tools/v2/raw.js.map +1 -1
- package/dist/tools/v2/recovery.js +37 -23
- package/dist/tools/v2/recovery.js.map +1 -1
- package/dist/tools/v2/sleep.js +52 -16
- package/dist/tools/v2/sleep.js.map +1 -1
- package/dist/tools/v2/smart_alarm.js +54 -20
- package/dist/tools/v2/smart_alarm.js.map +1 -1
- package/dist/tools/v2/smart_alarm_set.js +264 -86
- package/dist/tools/v2/smart_alarm_set.js.map +1 -1
- package/dist/tools/v2/strain.js +15 -15
- package/dist/tools/v2/strain.js.map +1 -1
- package/dist/tools/v2/stress.js +17 -15
- package/dist/tools/v2/stress.js.map +1 -1
- package/dist/tools/v2/trend.js +56 -20
- package/dist/tools/v2/trend.js.map +1 -1
- package/dist/tools/v2/weekly_plan.js +30 -0
- package/dist/tools/v2/weekly_plan.js.map +1 -0
- package/dist/tools/v2/weekly_plan_set.js +134 -0
- package/dist/tools/v2/weekly_plan_set.js.map +1 -0
- package/dist/tools/v2/weight.js +56 -0
- package/dist/tools/v2/weight.js.map +1 -0
- package/dist/tools/v2/weight_log.js +188 -0
- package/dist/tools/v2/weight_log.js.map +1 -0
- package/dist/tools/v2/workouts.js +159 -25
- package/dist/tools/v2/workouts.js.map +1 -1
- package/dist/version.js +6 -0
- package/dist/version.js.map +1 -0
- package/dist/whoop/bff.js +94 -0
- package/dist/whoop/bff.js.map +1 -0
- package/dist/whoop/client.js +392 -18
- package/dist/whoop/client.js.map +1 -1
- package/dist/whoop/cognito.js +106 -79
- package/dist/whoop/cognito.js.map +1 -1
- package/dist/whoop/connect_page.js +165 -0
- package/dist/whoop/connect_page.js.map +1 -0
- package/dist/whoop/consent_font.js +287 -0
- package/dist/whoop/consent_font.js.map +1 -0
- package/dist/whoop/consent_logos.js +22 -0
- package/dist/whoop/consent_logos.js.map +1 -0
- package/dist/whoop/consent_page.js +291 -0
- package/dist/whoop/consent_page.js.map +1 -0
- package/dist/whoop/constants.js +5 -1
- package/dist/whoop/constants.js.map +1 -1
- package/dist/whoop/device.js +4 -4
- package/dist/whoop/device.js.map +1 -1
- package/dist/whoop/errors.js +85 -4
- package/dist/whoop/errors.js.map +1 -1
- package/dist/whoop/init_timezone.js +57 -17
- package/dist/whoop/init_timezone.js.map +1 -1
- package/dist/whoop/installation.js +15 -10
- package/dist/whoop/installation.js.map +1 -1
- package/dist/whoop/json_out.js +52 -6
- package/dist/whoop/json_out.js.map +1 -1
- package/dist/whoop/oauth_provider.js +81 -78
- package/dist/whoop/oauth_provider.js.map +1 -1
- package/dist/whoop/token_lock.js +331 -0
- package/dist/whoop/token_lock.js.map +1 -0
- package/dist/whoop/token_manager.js +536 -42
- package/dist/whoop/token_manager.js.map +1 -1
- package/dist/whoop/token_store.js +303 -36
- package/dist/whoop/token_store.js.map +1 -1
- package/dist/whoop/units.js +28 -0
- package/dist/whoop/units.js.map +1 -0
- package/package.json +29 -13
- package/scripts/build-mcpb.mjs +72 -0
- package/scripts/embed-consent-font.mjs +34 -0
- package/scripts/readme-media.ts +195 -0
- package/scripts/tools-md.ts +89 -0
- package/scripts/whoop-md.ts +119 -0
- package/src/build_info.ts +4 -0
- package/src/cli/app.ts +696 -0
- package/src/cli/auth.ts +350 -0
- package/src/cli/auth_flow.ts +356 -0
- package/src/cli/browser_login.ts +402 -0
- package/src/cli/clients.ts +467 -0
- package/src/cli/deploy_record.ts +100 -0
- package/src/cli/index.ts +41 -583
- package/src/cli/links.ts +43 -0
- package/src/cli/logo.ts +64 -0
- package/src/cli/setup.ts +1147 -979
- package/src/cli/spawn.ts +88 -0
- package/src/cli/sys.ts +267 -0
- package/src/cli/ui.ts +778 -436
- package/src/cli/update.ts +436 -274
- package/src/cloudflare/runtime.d.ts +27 -0
- package/src/cloudflare/token_store.ts +57 -0
- package/src/cloudflare/worker.ts +174 -0
- package/src/data/behaviors.ts +2760 -622
- package/src/data/endpoint_catalog.ts +2695 -0
- package/src/data/exercises.ts +379 -4861
- package/src/data/garments.ts +28 -0
- package/src/data/sports.ts +239 -211
- package/src/lib/activity_list.ts +150 -0
- package/src/lib/activity_records.ts +213 -0
- package/src/lib/activity_results.ts +51 -0
- package/src/lib/activity_types.ts +176 -0
- package/src/lib/brand.ts +71 -0
- package/src/lib/clock.ts +16 -0
- package/src/lib/coach_session.ts +434 -0
- package/src/lib/dates.ts +18 -0
- package/src/lib/env_file.ts +191 -0
- package/src/lib/health_plans_write.ts +53 -0
- package/src/lib/heart_rate.ts +42 -0
- package/src/lib/highlight.ts +71 -0
- package/src/lib/install_links.ts +61 -0
- package/src/lib/instant.ts +54 -0
- package/src/lib/journal_behaviors.ts +453 -0
- package/src/lib/lift_catalog.ts +258 -0
- package/src/lib/lift_history.ts +75 -0
- package/src/lib/lift_sets.ts +164 -0
- package/src/lib/lift_tool.ts +25 -0
- package/src/lib/profile_settings.ts +102 -0
- package/src/lib/screen_content.ts +40 -0
- package/src/lib/timezone.ts +44 -8
- package/src/lib/walk.ts +4 -1
- package/src/lib/weight_readings.ts +82 -0
- package/src/projections/activities.ts +199 -0
- package/src/projections/alarm_schedule.ts +98 -0
- package/src/projections/coach.ts +218 -0
- package/src/projections/community.ts +187 -0
- package/src/projections/health_features.ts +191 -0
- package/src/projections/hormonal_insights.ts +277 -0
- package/src/projections/journal_v2.ts +173 -0
- package/src/projections/lift_cards.ts +131 -0
- package/src/projections/lift_exercise_v2.ts +147 -0
- package/src/projections/lift_library_v2.ts +77 -0
- package/src/projections/lift_sessions.ts +250 -0
- package/src/projections/memory.ts +100 -0
- package/src/projections/milestones.ts +133 -0
- package/src/projections/profile_v2.ts +166 -0
- package/src/projections/settings_v2.ts +179 -0
- package/src/projections/sleep.ts +7 -21
- package/src/projections/v2/calendar.ts +48 -0
- package/src/projections/v2/core_common.ts +95 -0
- package/src/projections/v2/core_home.ts +177 -0
- package/src/projections/v2/core_sleep_need.ts +37 -0
- package/src/projections/v2/day.ts +162 -0
- package/src/projections/v2/heart_rate.ts +73 -0
- package/src/projections/v2/history.ts +153 -0
- package/src/projections/v2/now.ts +59 -0
- package/src/projections/v2/recovery.ts +120 -0
- package/src/projections/v2/sleep.ts +281 -0
- package/src/projections/v2/strain.ts +63 -0
- package/src/projections/v2/stress.ts +111 -0
- package/src/projections/v2/trend.ts +242 -0
- package/src/projections/weekly_plan.ts +79 -0
- package/src/projections/weight_readings.ts +57 -0
- package/src/projections/workout.ts +36 -17
- package/src/schemas/activities.ts +136 -0
- package/src/schemas/alarm_schedule.ts +70 -0
- package/src/schemas/coach.ts +98 -8
- package/src/schemas/community.ts +77 -0
- package/src/schemas/health.ts +36 -0
- package/src/schemas/hormonal_insights.ts +108 -0
- package/src/schemas/journal.ts +4 -0
- package/src/schemas/journal_v2.ts +112 -0
- package/src/schemas/memory.ts +48 -0
- package/src/schemas/milestones.ts +48 -0
- package/src/schemas/profile_v2.ts +63 -0
- package/src/schemas/settings_v2.ts +63 -0
- package/src/schemas/sleep.ts +9 -1
- package/src/schemas/strength.ts +10 -1
- package/src/schemas/strength_v2.ts +210 -0
- package/src/schemas/v2/calendar.ts +8 -0
- package/src/schemas/v2/core_common.ts +50 -0
- package/src/schemas/v2/day.ts +79 -0
- package/src/schemas/v2/now.ts +25 -0
- package/src/schemas/v2/recovery.ts +38 -0
- package/src/schemas/v2/sleep.ts +46 -0
- package/src/schemas/v2/strain.ts +16 -0
- package/src/schemas/v2/stress.ts +20 -0
- package/src/schemas/v2/trend.ts +45 -0
- package/src/schemas/weekly_plan.ts +36 -0
- package/src/schemas/weight.ts +53 -0
- package/src/scripts/build_behaviors.ts +116 -0
- package/src/scripts/cognito_bootstrap.ts +10 -249
- package/src/scripts/gen_activity_catalogs.ts +121 -0
- package/src/server-admin.ts +171 -0
- package/src/server-http.ts +290 -53
- package/src/server.ts +130 -26
- package/src/tools/annotations.ts +25 -0
- package/src/tools/define.ts +53 -0
- package/src/tools/register.ts +64 -94
- package/src/tools/resources.ts +92 -0
- package/src/tools/slim_schema.ts +102 -0
- package/src/tools/v2/activity_delete.ts +61 -23
- package/src/tools/v2/activity_edit.ts +378 -0
- package/src/tools/v2/activity_log.ts +154 -0
- package/src/tools/v2/calendar.ts +22 -21
- package/src/tools/v2/coach_ask.ts +83 -119
- package/src/tools/v2/coach_history.ts +140 -0
- package/src/tools/v2/community.ts +137 -0
- package/src/tools/v2/cycle.ts +78 -20
- package/src/tools/v2/cycle_log.ts +291 -40
- package/src/tools/v2/day.ts +126 -25
- package/src/tools/v2/health.ts +114 -0
- package/src/tools/v2/hr_zones_set.ts +132 -45
- package/src/tools/v2/journal.ts +78 -23
- package/src/tools/v2/journal_log.ts +321 -69
- package/src/tools/v2/lift_exercise.ts +135 -27
- package/src/tools/v2/lift_exercise_set.ts +272 -0
- package/src/tools/v2/lift_library.ts +57 -21
- package/src/tools/v2/lift_log.ts +325 -83
- package/src/tools/v2/lift_sessions.ts +255 -0
- package/src/tools/v2/lift_template.ts +229 -0
- package/src/tools/v2/memory.ts +54 -0
- package/src/tools/v2/memory_set.ts +110 -0
- package/src/tools/v2/milestones.ts +59 -0
- package/src/tools/v2/now.ts +61 -0
- package/src/tools/v2/preferences.ts +61 -0
- package/src/tools/v2/preferences_set.ts +403 -0
- package/src/tools/v2/profile.ts +56 -26
- package/src/tools/v2/profile_update.ts +151 -60
- package/src/tools/v2/raw.ts +89 -36
- package/src/tools/v2/recovery.ts +44 -25
- package/src/tools/v2/sleep.ts +57 -18
- package/src/tools/v2/smart_alarm.ts +62 -24
- package/src/tools/v2/smart_alarm_set.ts +240 -90
- package/src/tools/v2/strain.ts +19 -16
- package/src/tools/v2/stress.ts +22 -17
- package/src/tools/v2/trend.ts +58 -20
- package/src/tools/v2/weekly_plan.ts +38 -0
- package/src/tools/v2/weekly_plan_set.ts +132 -0
- package/src/tools/v2/weight.ts +61 -0
- package/src/tools/v2/weight_log.ts +193 -0
- package/src/tools/v2/workouts.ts +156 -26
- package/src/version.ts +5 -0
- package/src/whoop/bff.ts +84 -0
- package/src/whoop/client.ts +448 -18
- package/src/whoop/cognito.ts +110 -99
- package/src/whoop/connect_page.ts +183 -0
- package/src/whoop/consent_font.ts +289 -0
- package/src/whoop/consent_logos.ts +24 -0
- package/src/whoop/consent_page.ts +326 -0
- package/src/whoop/constants.ts +5 -1
- package/src/whoop/device.ts +4 -4
- package/src/whoop/errors.ts +89 -4
- package/src/whoop/init_timezone.ts +57 -16
- package/src/whoop/installation.ts +16 -7
- package/src/whoop/json_out.ts +51 -6
- package/src/whoop/oauth_provider.ts +84 -91
- package/src/whoop/token_lock.ts +345 -0
- package/src/whoop/token_manager.ts +580 -53
- package/src/whoop/token_store.ts +341 -32
- package/src/whoop/units.ts +35 -0
- package/wrangler.jsonc +17 -0
- package/assets/banner.svg +0 -38
- package/dist/data/endpoints.js +0 -320
- package/dist/data/endpoints.js.map +0 -1
- package/dist/lib/format.js +0 -22
- package/dist/lib/format.js.map +0 -1
- package/dist/lib/stats.js +0 -32
- package/dist/lib/stats.js.map +0 -1
- package/dist/projections/calendar.js +0 -33
- package/dist/projections/calendar.js.map +0 -1
- package/dist/projections/communities.js +0 -105
- package/dist/projections/communities.js.map +0 -1
- package/dist/projections/cycle.js +0 -81
- package/dist/projections/cycle.js.map +0 -1
- package/dist/projections/hr_zones.js +0 -35
- package/dist/projections/hr_zones.js.map +0 -1
- package/dist/projections/journal.js +0 -56
- package/dist/projections/journal.js.map +0 -1
- package/dist/projections/leaderboard.js +0 -37
- package/dist/projections/leaderboard.js.map +0 -1
- package/dist/projections/lift_exercise.js +0 -22
- package/dist/projections/lift_exercise.js.map +0 -1
- package/dist/projections/lift_history.js +0 -133
- package/dist/projections/lift_history.js.map +0 -1
- package/dist/projections/lift_library.js +0 -71
- package/dist/projections/lift_library.js.map +0 -1
- package/dist/projections/lift_progression.js +0 -138
- package/dist/projections/lift_progression.js.map +0 -1
- package/dist/projections/lift_prs.js +0 -20
- package/dist/projections/lift_prs.js.map +0 -1
- package/dist/projections/live_hr.js +0 -19
- package/dist/projections/live_hr.js.map +0 -1
- package/dist/projections/live_state.js +0 -23
- package/dist/projections/live_state.js.map +0 -1
- package/dist/projections/live_stress.js +0 -11
- package/dist/projections/live_stress.js.map +0 -1
- package/dist/projections/performance_assessment.js +0 -15
- package/dist/projections/performance_assessment.js.map +0 -1
- package/dist/projections/profile.js +0 -59
- package/dist/projections/profile.js.map +0 -1
- package/dist/projections/recovery.js +0 -131
- package/dist/projections/recovery.js.map +0 -1
- package/dist/projections/sleep_need.js +0 -32
- package/dist/projections/sleep_need.js.map +0 -1
- package/dist/projections/smart_alarm.js +0 -45
- package/dist/projections/smart_alarm.js.map +0 -1
- package/dist/projections/strain.js +0 -128
- package/dist/projections/strain.js.map +0 -1
- package/dist/projections/stress.js +0 -86
- package/dist/projections/stress.js.map +0 -1
- package/dist/projections/today.js +0 -129
- package/dist/projections/today.js.map +0 -1
- package/dist/projections/trend.js +0 -149
- package/dist/projections/trend.js.map +0 -1
- package/dist/projections/workouts.js +0 -37
- package/dist/projections/workouts.js.map +0 -1
- package/dist/schemas/calendar.js +0 -12
- package/dist/schemas/calendar.js.map +0 -1
- package/dist/schemas/communities.js +0 -51
- package/dist/schemas/communities.js.map +0 -1
- package/dist/schemas/compare.js +0 -15
- package/dist/schemas/compare.js.map +0 -1
- package/dist/schemas/leaderboard.js +0 -25
- package/dist/schemas/leaderboard.js.map +0 -1
- package/dist/schemas/live.js +0 -26
- package/dist/schemas/live.js.map +0 -1
- package/dist/schemas/performance.js +0 -12
- package/dist/schemas/performance.js.map +0 -1
- package/dist/schemas/profile.js +0 -39
- package/dist/schemas/profile.js.map +0 -1
- package/dist/schemas/recovery.js +0 -27
- package/dist/schemas/recovery.js.map +0 -1
- package/dist/schemas/settings.js +0 -26
- package/dist/schemas/settings.js.map +0 -1
- package/dist/schemas/sleep_need.js +0 -15
- package/dist/schemas/sleep_need.js.map +0 -1
- package/dist/schemas/smart_alarm.js +0 -36
- package/dist/schemas/smart_alarm.js.map +0 -1
- package/dist/schemas/strain.js +0 -24
- package/dist/schemas/strain.js.map +0 -1
- package/dist/schemas/stress.js +0 -16
- package/dist/schemas/stress.js.map +0 -1
- package/dist/schemas/today.js +0 -38
- package/dist/schemas/today.js.map +0 -1
- package/dist/schemas/trend.js +0 -50
- package/dist/schemas/trend.js.map +0 -1
- package/dist/schemas/womens_health.js +0 -23
- package/dist/schemas/womens_health.js.map +0 -1
- package/dist/tools/v2/activity_create.js +0 -64
- package/dist/tools/v2/activity_create.js.map +0 -1
- package/dist/tools/v2/behavior_impact.js +0 -36
- package/dist/tools/v2/behavior_impact.js.map +0 -1
- package/dist/tools/v2/communities.js +0 -60
- package/dist/tools/v2/communities.js.map +0 -1
- package/dist/tools/v2/compare.js +0 -67
- package/dist/tools/v2/compare.js.map +0 -1
- package/dist/tools/v2/endpoints.js +0 -28
- package/dist/tools/v2/endpoints.js.map +0 -1
- package/dist/tools/v2/hidden_metric.js +0 -28
- package/dist/tools/v2/hidden_metric.js.map +0 -1
- package/dist/tools/v2/hr_zones.js +0 -24
- package/dist/tools/v2/hr_zones.js.map +0 -1
- package/dist/tools/v2/journal_autopop.js +0 -19
- package/dist/tools/v2/journal_autopop.js.map +0 -1
- package/dist/tools/v2/journal_catalog.js +0 -44
- package/dist/tools/v2/journal_catalog.js.map +0 -1
- package/dist/tools/v2/leaderboard.js +0 -79
- package/dist/tools/v2/leaderboard.js.map +0 -1
- package/dist/tools/v2/lift_catalog.js +0 -47
- package/dist/tools/v2/lift_catalog.js.map +0 -1
- package/dist/tools/v2/lift_custom_exercise.js +0 -108
- package/dist/tools/v2/lift_custom_exercise.js.map +0 -1
- package/dist/tools/v2/lift_history.js +0 -39
- package/dist/tools/v2/lift_history.js.map +0 -1
- package/dist/tools/v2/lift_progression.js +0 -30
- package/dist/tools/v2/lift_progression.js.map +0 -1
- package/dist/tools/v2/lift_prs.js +0 -21
- package/dist/tools/v2/lift_prs.js.map +0 -1
- package/dist/tools/v2/lift_template_save.js +0 -83
- package/dist/tools/v2/lift_template_save.js.map +0 -1
- package/dist/tools/v2/live_hr.js +0 -21
- package/dist/tools/v2/live_hr.js.map +0 -1
- package/dist/tools/v2/live_state.js +0 -21
- package/dist/tools/v2/live_state.js.map +0 -1
- package/dist/tools/v2/live_stress.js +0 -22
- package/dist/tools/v2/live_stress.js.map +0 -1
- package/dist/tools/v2/performance_assessment.js +0 -38
- package/dist/tools/v2/performance_assessment.js.map +0 -1
- package/dist/tools/v2/sleep_need.js +0 -21
- package/dist/tools/v2/sleep_need.js.map +0 -1
- package/dist/tools/v2/sports_catalog.js +0 -26
- package/dist/tools/v2/sports_catalog.js.map +0 -1
- package/dist/tools/v2/symptom_log.js +0 -72
- package/dist/tools/v2/symptom_log.js.map +0 -1
- package/dist/tools/v2/today.js +0 -30
- package/dist/tools/v2/today.js.map +0 -1
- package/dist/tools/v2/workout.js +0 -23
- package/dist/tools/v2/workout.js.map +0 -1
- package/dist/whoop/build_lift_body.js +0 -67
- package/dist/whoop/build_lift_body.js.map +0 -1
- package/dist/whoop/session_state.js +0 -34
- package/dist/whoop/session_state.js.map +0 -1
- package/dist/whoop/types.js +0 -82
- package/dist/whoop/types.js.map +0 -1
- package/src/data/endpoints.ts +0 -319
- package/src/lib/format.ts +0 -27
- package/src/lib/stats.ts +0 -35
- package/src/projections/calendar.ts +0 -46
- package/src/projections/communities.ts +0 -135
- package/src/projections/cycle.ts +0 -85
- package/src/projections/hr_zones.ts +0 -43
- package/src/projections/journal.ts +0 -55
- package/src/projections/leaderboard.ts +0 -49
- package/src/projections/lift_exercise.ts +0 -29
- package/src/projections/lift_history.ts +0 -140
- package/src/projections/lift_library.ts +0 -70
- package/src/projections/lift_progression.ts +0 -138
- package/src/projections/lift_prs.ts +0 -23
- package/src/projections/live_hr.ts +0 -21
- package/src/projections/live_state.ts +0 -28
- package/src/projections/live_stress.ts +0 -13
- package/src/projections/performance_assessment.ts +0 -19
- package/src/projections/profile.ts +0 -71
- package/src/projections/recovery.ts +0 -133
- package/src/projections/sleep_need.ts +0 -36
- package/src/projections/smart_alarm.ts +0 -70
- package/src/projections/strain.ts +0 -131
- package/src/projections/stress.ts +0 -95
- package/src/projections/today.ts +0 -166
- package/src/projections/trend.ts +0 -149
- package/src/projections/workouts.ts +0 -36
- package/src/schemas/calendar.ts +0 -13
- package/src/schemas/communities.ts +0 -56
- package/src/schemas/compare.ts +0 -17
- package/src/schemas/leaderboard.ts +0 -26
- package/src/schemas/live.ts +0 -31
- package/src/schemas/performance.ts +0 -13
- package/src/schemas/profile.ts +0 -40
- package/src/schemas/recovery.ts +0 -28
- package/src/schemas/settings.ts +0 -30
- package/src/schemas/sleep_need.ts +0 -16
- package/src/schemas/smart_alarm.ts +0 -40
- package/src/schemas/strain.ts +0 -25
- package/src/schemas/stress.ts +0 -17
- package/src/schemas/today.ts +0 -39
- package/src/schemas/trend.ts +0 -53
- package/src/schemas/womens_health.ts +0 -26
- package/src/tools/v2/activity_create.ts +0 -74
- package/src/tools/v2/behavior_impact.ts +0 -39
- package/src/tools/v2/communities.ts +0 -65
- package/src/tools/v2/compare.ts +0 -83
- package/src/tools/v2/endpoints.ts +0 -32
- package/src/tools/v2/hidden_metric.ts +0 -33
- package/src/tools/v2/hr_zones.ts +0 -29
- package/src/tools/v2/journal_autopop.ts +0 -26
- package/src/tools/v2/journal_catalog.ts +0 -48
- package/src/tools/v2/leaderboard.ts +0 -92
- package/src/tools/v2/lift_catalog.ts +0 -48
- package/src/tools/v2/lift_custom_exercise.ts +0 -117
- package/src/tools/v2/lift_history.ts +0 -52
- package/src/tools/v2/lift_progression.ts +0 -34
- package/src/tools/v2/lift_prs.ts +0 -26
- package/src/tools/v2/lift_template_save.ts +0 -89
- package/src/tools/v2/live_hr.ts +0 -26
- package/src/tools/v2/live_state.ts +0 -26
- package/src/tools/v2/live_stress.ts +0 -27
- package/src/tools/v2/performance_assessment.ts +0 -44
- package/src/tools/v2/sleep_need.ts +0 -26
- package/src/tools/v2/sports_catalog.ts +0 -32
- package/src/tools/v2/symptom_log.ts +0 -78
- package/src/tools/v2/today.ts +0 -35
- package/src/tools/v2/workout.ts +0 -28
- package/src/whoop/build_lift_body.ts +0 -84
- package/src/whoop/session_state.ts +0 -41
- package/src/whoop/types.ts +0 -89
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
// Pure projections over the AI coach BFF (/ai-conversation-bff/v1): turns,
|
|
2
|
+
// the history list and recommendation widgets. specs/ai.md §2.3, §2.4, §2.8.
|
|
3
|
+
import { byType, get, str, type Node } from "../whoop/bff.js";
|
|
4
|
+
import type {
|
|
5
|
+
CoachCardT,
|
|
6
|
+
CoachConversationT,
|
|
7
|
+
CoachRecommendationT,
|
|
8
|
+
CoachTranscriptTurnT,
|
|
9
|
+
} from "../schemas/coach.js";
|
|
10
|
+
|
|
11
|
+
type Obj = Record<string, unknown>;
|
|
12
|
+
const isObj = (v: unknown): v is Obj => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
13
|
+
const arr = (v: unknown): unknown[] => (Array.isArray(v) ? v : []);
|
|
14
|
+
|
|
15
|
+
/** agent name ↔ WHOOP agent (source_id) + create args. ai §2.1, §3 recipe 2. */
|
|
16
|
+
export const AGENT_SOURCES: Record<string, { source_id: string; context?: string; tag: string }> = {
|
|
17
|
+
coach: { source_id: "coach-chat", tag: "HOME" },
|
|
18
|
+
sleep: { source_id: "sleep-deep-dive-agent", context: "sleep_deepdive", tag: "SLEEP" },
|
|
19
|
+
recovery: { source_id: "recovery-deep-dive-agent", context: "recovery_deepdive", tag: "RECOVERY" },
|
|
20
|
+
strain: { source_id: "strain-deep-dive-agent", context: "strain_deepdive", tag: "STRAIN" },
|
|
21
|
+
stress: { source_id: "coach-everywhere-stress-monitor-page", context: "stress_monitor", tag: "STRESS" },
|
|
22
|
+
activity: { source_id: "coach-everywhere-cardio-activity-details", context: "cardio_activity_details", tag: "ACTIVITY" },
|
|
23
|
+
daily_outlook: { source_id: "daily-outlook", tag: "OUTLOOK" },
|
|
24
|
+
day_in_review: { source_id: "day-in-review", tag: "REVIEW" },
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/** Fingerprint prefixes of the generated reports; the cycle id follows. ai §2.7. */
|
|
28
|
+
export const REPORT_PREFIX = { daily_outlook: "daily-outlook___cycle___", day_in_review: "day-in-review___cycle___" } as const;
|
|
29
|
+
|
|
30
|
+
export function agentForSource(sourceId: string | null): string | null {
|
|
31
|
+
if (!sourceId) return null;
|
|
32
|
+
for (const [agent, def] of Object.entries(AGENT_SOURCES)) if (def.source_id === sourceId) return agent;
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function messages(turn: unknown, role: "user" | "assistant"): Obj[] {
|
|
37
|
+
return arr(get(turn, "messages")).filter((m): m is Obj => isObj(m) && m.role === role);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function items(message: Obj): Obj[] {
|
|
41
|
+
return arr(message.items).filter(isObj);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** One message's MARKDOWN_CHAT_TEXT fragments, concatenated (they carry their own newlines). */
|
|
45
|
+
function messageText(message: Obj): string {
|
|
46
|
+
return items(message)
|
|
47
|
+
.filter((it) => it.type === "MARKDOWN_CHAT_TEXT")
|
|
48
|
+
.map((it) => (typeof get(it, "content", "text") === "string" ? (get(it, "content", "text") as string) : ""))
|
|
49
|
+
.join("");
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Every assistant MARKDOWN_CHAT_TEXT in the turn, in order: the preface, the
|
|
54
|
+
* main answer's fragments and any follow-up. Empty placeholder messages are
|
|
55
|
+
* skipped. Only meaningful at COMPLETE (order shifts while streaming).
|
|
56
|
+
*/
|
|
57
|
+
export function assistantText(turn: unknown): string | null {
|
|
58
|
+
const parts = messages(turn, "assistant").map((m) => messageText(m).trim()).filter((t) => t !== "");
|
|
59
|
+
return parts.length ? parts.join("\n\n") : null;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function userText(turn: unknown): string | null {
|
|
63
|
+
const parts = messages(turn, "user").map((m) => messageText(m).trim()).filter((t) => t !== "");
|
|
64
|
+
return parts.length ? parts.join("\n\n") : null;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function userAttachmentCount(turn: unknown): number {
|
|
68
|
+
let n = 0;
|
|
69
|
+
for (const m of messages(turn, "user")) {
|
|
70
|
+
for (const it of items(m)) {
|
|
71
|
+
if (it.type === "CHAT_ATTACHMENT_CAROUSEL") n += arr(get(it, "content", "attachments")).length;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return n;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** ICON_MARKDOWN_CALLOUT badges ("Logged Walk"): the coach's receipts for real writes. Its `id` is not the activity id. */
|
|
78
|
+
export function turnActions(turn: unknown): string[] {
|
|
79
|
+
const out: string[] = [];
|
|
80
|
+
for (const m of messages(turn, "assistant")) {
|
|
81
|
+
for (const it of items(m)) {
|
|
82
|
+
if (it.type !== "ICON_MARKDOWN_CALLOUT") continue;
|
|
83
|
+
const text = str(get(it, "content", "body_text"));
|
|
84
|
+
if (text) out.push(text);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return out;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function graphBars(content: unknown): NonNullable<CoachCardT["bars"]> {
|
|
91
|
+
const out: NonNullable<CoachCardT["bars"]> = [];
|
|
92
|
+
for (const plot of arr(get(content, "graph", "plots"))) {
|
|
93
|
+
for (const group of arr(get(plot, "plot", "bar_groups"))) {
|
|
94
|
+
const a11y = str(get(group, "accessibility_label"));
|
|
95
|
+
const date = a11y?.match(/^\d{4}-\d{2}-\d{2}/)?.[0] ?? a11y;
|
|
96
|
+
out.push([date ?? null, str(get(group, "top_label", "label"))]);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return out;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** Non-text assistant items as short rows (charts, deep links, drafts). Widget paths stay internal. */
|
|
103
|
+
export function turnCards(turn: unknown): CoachCardT[] {
|
|
104
|
+
const out: CoachCardT[] = [];
|
|
105
|
+
for (const m of messages(turn, "assistant")) {
|
|
106
|
+
for (const it of items(m)) {
|
|
107
|
+
const type = typeof it.type === "string" ? it.type : "UNKNOWN";
|
|
108
|
+
const c = it.content;
|
|
109
|
+
switch (type) {
|
|
110
|
+
case "MARKDOWN_CHAT_TEXT":
|
|
111
|
+
case "ICON_MARKDOWN_CALLOUT":
|
|
112
|
+
case "MINI_ARCH_WIDGET":
|
|
113
|
+
break;
|
|
114
|
+
case "GRAPHING_CARD":
|
|
115
|
+
out.push({ type: "chart", title: str(get(c, "title")), bars: graphBars(c) });
|
|
116
|
+
break;
|
|
117
|
+
case "SECONDARY_BUTTON":
|
|
118
|
+
out.push({ type: "link", title: str(get(c, "text")) });
|
|
119
|
+
break;
|
|
120
|
+
case "AI_WEIGHTLIFTING_SUGGESTION": {
|
|
121
|
+
const key = get(c, "navigation_button", "action", "parameters", "starting_id");
|
|
122
|
+
const exercises: string[] = [];
|
|
123
|
+
for (const group of arr(get(c, "workout_list"))) {
|
|
124
|
+
for (const w of arr(get(group, "workouts"))) {
|
|
125
|
+
const t = str(get(w, "title"));
|
|
126
|
+
if (t) exercises.push(t);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
out.push({
|
|
130
|
+
type: "workout_draft",
|
|
131
|
+
title: str(get(c, "title")),
|
|
132
|
+
draft_template_key: typeof key === "number" ? key : typeof key === "string" && /^\d+$/.test(key) ? Number(key) : null,
|
|
133
|
+
exercises,
|
|
134
|
+
});
|
|
135
|
+
break;
|
|
136
|
+
}
|
|
137
|
+
default:
|
|
138
|
+
out.push({ type: type.toLowerCase(), title: str(get(c, "title")) ?? str(get(c, "text")) });
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return out;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/** The recommendation-widget path from a turn's MINI_ARCH_WIDGET, if any. */
|
|
146
|
+
export function recommendationPath(turn: unknown): string | null {
|
|
147
|
+
for (const m of messages(turn, "assistant")) {
|
|
148
|
+
for (const it of items(m)) {
|
|
149
|
+
if (it.type !== "MINI_ARCH_WIDGET") continue;
|
|
150
|
+
const p = str(get(it, "content", "path"));
|
|
151
|
+
if (p) return p;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
return null;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export function turnStatus(turn: unknown): string | null {
|
|
158
|
+
const s = get(turn, "turn_status");
|
|
159
|
+
return typeof s === "string" ? s.toUpperCase() : null;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/** Flatten `{conversations:[{title, conversation_metadata_list:[…]}]}` into rows. */
|
|
163
|
+
export function projectConversationList(raw: unknown): { conversations: CoachConversationT[]; next_cursor: string | null } {
|
|
164
|
+
const conversations: CoachConversationT[] = [];
|
|
165
|
+
for (const group of arr(get(raw, "conversations"))) {
|
|
166
|
+
const day = str(get(group, "title"));
|
|
167
|
+
for (const c of arr(get(group, "conversation_metadata_list"))) {
|
|
168
|
+
const fingerprint = str(get(c, "fingerprint"));
|
|
169
|
+
if (!fingerprint) continue;
|
|
170
|
+
const sourceId = str(get(c, "source_id"));
|
|
171
|
+
conversations.push({ fingerprint, source_id: sourceId, agent: agentForSource(sourceId), title: str(get(c, "title")), day });
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
return { conversations, next_cursor: str(get(raw, "next_token")) };
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/** RECOMMENDATION_TILEs from a recommendation-widget response. ai §2.8. */
|
|
178
|
+
export function projectRecommendations(raw: unknown): CoachRecommendationT[] {
|
|
179
|
+
return byType(raw, "RECOMMENDATION_TILE").map((tile: Node) => {
|
|
180
|
+
const c = tile.content;
|
|
181
|
+
const body = byType(c, "MARKDOWN_TEXT")
|
|
182
|
+
.map((n) => str(get(n, "content", "text")))
|
|
183
|
+
.filter((t): t is string => t !== null)
|
|
184
|
+
.join("\n");
|
|
185
|
+
return {
|
|
186
|
+
title: str(get(byType(c, "RECOMMENDATION_TILE_HEADER")[0], "content", "title")) ?? str(get(c, "header", "content", "title")),
|
|
187
|
+
status: str(get(c, "status")),
|
|
188
|
+
body: body || null,
|
|
189
|
+
};
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/** Turns of a reopened conversation as short rows, newest `limit` kept. */
|
|
194
|
+
export function projectTranscript(raw: unknown, limit: number): { total: number; turns: CoachTranscriptTurnT[] } {
|
|
195
|
+
const turns = arr(get(raw, "turns"))
|
|
196
|
+
.filter(isObj)
|
|
197
|
+
.map((t) => {
|
|
198
|
+
const status = turnStatus(t);
|
|
199
|
+
const images = userAttachmentCount(t);
|
|
200
|
+
return {
|
|
201
|
+
user: userText(t),
|
|
202
|
+
coach: assistantText(t),
|
|
203
|
+
actions: turnActions(t),
|
|
204
|
+
cards: turnCards(t),
|
|
205
|
+
images: images || null,
|
|
206
|
+
status: status === "COMPLETE" ? null : status,
|
|
207
|
+
};
|
|
208
|
+
})
|
|
209
|
+
// coach-chat's turn 0 is an empty greeting; drop turns with nothing in them.
|
|
210
|
+
.filter((t) => t.user !== null || t.coach !== null || t.cards.length > 0 || t.actions.length > 0);
|
|
211
|
+
return { total: turns.length, turns: turns.slice(-limit) };
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/** `metadata.cycle_metadata.cycle_id` from a home response, or null. */
|
|
215
|
+
export function homeCycleId(home: unknown): number | null {
|
|
216
|
+
const id = get(home, "metadata", "cycle_metadata", "cycle_id");
|
|
217
|
+
return typeof id === "number" && Number.isFinite(id) ? id : null;
|
|
218
|
+
}
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
// Pure projections for whoop_community: community memberships and leaderboards
|
|
2
|
+
// (community-service) and the WHOOP Humans views (followers-service). D9: these
|
|
3
|
+
// include other members' names and scores. Shapes from the 2026-11 captures.
|
|
4
|
+
import { byType, get, parseNumber, str, type Node } from "../whoop/bff.js";
|
|
5
|
+
import type { CommunityMembershipT, CommunityOutT, SnapshotPillarT } from "../schemas/community.js";
|
|
6
|
+
|
|
7
|
+
type Obj = Record<string, unknown>;
|
|
8
|
+
type Cell = string | number | null;
|
|
9
|
+
const isObj = (v: unknown): v is Obj => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
10
|
+
const arr = (v: unknown): unknown[] => (Array.isArray(v) ? v : []);
|
|
11
|
+
const num = (v: unknown): number | null => (typeof v === "number" && Number.isFinite(v) ? v : null);
|
|
12
|
+
const int = (v: unknown): number | null => {
|
|
13
|
+
const n = typeof v === "string" && /^\d+$/.test(v) ? Number(v) : num(v);
|
|
14
|
+
return n === null ? null : Math.trunc(n);
|
|
15
|
+
};
|
|
16
|
+
const bool = (v: unknown): boolean | null => (typeof v === "boolean" ? v : null);
|
|
17
|
+
const round = (v: number | null, digits: number): number | null => (v === null ? null : Number(v.toFixed(digits)));
|
|
18
|
+
|
|
19
|
+
function personName(o: unknown): string | null {
|
|
20
|
+
const name = str(get(o, "name"));
|
|
21
|
+
if (name) return name;
|
|
22
|
+
const parts = [str(get(o, "first_name")), str(get(o, "last_name"))].filter((p): p is string => p !== null);
|
|
23
|
+
return parts.length ? parts.join(" ") : null;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function projectRank(raw: unknown): CommunityMembershipT["your_rank"] {
|
|
27
|
+
if (typeof raw === "number") return { rank: Math.trunc(raw), score: null };
|
|
28
|
+
if (!isObj(raw)) return null;
|
|
29
|
+
const rank = int(raw.rank ?? raw.position ?? raw.place);
|
|
30
|
+
const score = round(num(raw.score ?? raw.value ?? raw.day_strain ?? raw.performance ?? raw.average), 1);
|
|
31
|
+
return rank === null && score === null ? null : { rank, score };
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** GET /community-service/v1/communities/memberships → `{total_count, offset, records[]}`. */
|
|
35
|
+
export function projectMemberships(raw: unknown): Extract<CommunityOutT, { view: "communities" }> {
|
|
36
|
+
const communities: CommunityMembershipT[] = arr(get(raw, "records")).flatMap((r) => {
|
|
37
|
+
const id = int(get(r, "id"));
|
|
38
|
+
const name = str(get(r, "name"));
|
|
39
|
+
if (id === null || name === null) return [];
|
|
40
|
+
return [{
|
|
41
|
+
id,
|
|
42
|
+
name,
|
|
43
|
+
type: str(get(r, "team_type")),
|
|
44
|
+
members: int(get(r, "metadata", "member_count") ?? get(r, "member_count")),
|
|
45
|
+
private: bool(get(r, "private")),
|
|
46
|
+
your_rank: projectRank(get(r, "user_rank")),
|
|
47
|
+
}];
|
|
48
|
+
});
|
|
49
|
+
return { view: "communities", total: int(get(raw, "total_count")) ?? communities.length, communities };
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export type LeaderboardMetric = "recovery" | "sleep" | "strain";
|
|
53
|
+
|
|
54
|
+
/** The leaderboard's stat path segment, value field and unit per metric. */
|
|
55
|
+
export const LEADERBOARD: Record<LeaderboardMetric, { stat: string; field: string; unit: string }> = {
|
|
56
|
+
recovery: { stat: "score", field: "score", unit: "recovery %" },
|
|
57
|
+
sleep: { stat: "performance", field: "performance", unit: "sleep performance %" },
|
|
58
|
+
strain: { stat: "day_strain", field: "day_strain", unit: "day strain (0–21)" },
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
export const LEADERBOARD_COLUMNS = ["rank", "name", "value"];
|
|
62
|
+
|
|
63
|
+
/** One leaderboard record as [rank, name, value]. */
|
|
64
|
+
export function leaderboardRow(r: unknown, metric: LeaderboardMetric): Cell[] | null {
|
|
65
|
+
if (!isObj(r)) return null;
|
|
66
|
+
return [int(r.rank), personName(r), round(num(r[LEADERBOARD[metric].field]), 1)];
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function projectLeaderboard(input: {
|
|
70
|
+
board: unknown;
|
|
71
|
+
userRow: unknown | null;
|
|
72
|
+
metric: LeaderboardMetric;
|
|
73
|
+
window: "day" | "week" | "month";
|
|
74
|
+
communityId: number;
|
|
75
|
+
communityName: string | null;
|
|
76
|
+
start: string;
|
|
77
|
+
end: string;
|
|
78
|
+
offset: number;
|
|
79
|
+
}): Extract<CommunityOutT, { view: "leaderboard" }> {
|
|
80
|
+
const rows = arr(get(input.board, "records"))
|
|
81
|
+
.map((r) => leaderboardRow(r, input.metric))
|
|
82
|
+
.filter((r): r is Cell[] => r !== null);
|
|
83
|
+
const total = int(get(input.board, "total_count"));
|
|
84
|
+
const seen = input.offset + rows.length;
|
|
85
|
+
return {
|
|
86
|
+
view: "leaderboard",
|
|
87
|
+
community_id: input.communityId,
|
|
88
|
+
community: input.communityName,
|
|
89
|
+
metric: input.metric,
|
|
90
|
+
window: input.window,
|
|
91
|
+
start: input.start,
|
|
92
|
+
end: input.end,
|
|
93
|
+
unit: LEADERBOARD[input.metric].unit,
|
|
94
|
+
columns: LEADERBOARD_COLUMNS,
|
|
95
|
+
rows,
|
|
96
|
+
you: input.userRow ? leaderboardRow(input.userRow, input.metric) : null,
|
|
97
|
+
members: total,
|
|
98
|
+
average: round(num(get(input.board, "average")), 1),
|
|
99
|
+
next_offset: rows.length > 0 && total !== null && seen < total ? seen : null,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export const FOLLOWING_COLUMNS = ["user_id", "name", "recovery_pct", "sleep_pct", "strain"];
|
|
104
|
+
|
|
105
|
+
/** GET /followers-service/v1/followers-home/following → COMMUNITY_FOLLOWER rows (yours is HIGHLIGHTED). */
|
|
106
|
+
export function projectFollowing(raw: unknown, ownId: number | null): Extract<CommunityOutT, { view: "following" }> {
|
|
107
|
+
const rows: Cell[][] = [];
|
|
108
|
+
let you: Cell[] | null = null;
|
|
109
|
+
for (const node of byType(raw, "COMMUNITY_FOLLOWER") as Node[]) {
|
|
110
|
+
const c = node.content;
|
|
111
|
+
const userId = int(get(c, "id"));
|
|
112
|
+
const row: Cell[] = [
|
|
113
|
+
userId,
|
|
114
|
+
str(get(c, "title")),
|
|
115
|
+
parseNumber(get(c, "recovery_score")),
|
|
116
|
+
parseNumber(get(c, "sleep_score")),
|
|
117
|
+
parseNumber(get(c, "day_strain")),
|
|
118
|
+
];
|
|
119
|
+
if ((ownId !== null && userId === ownId) || get(c, "background_style") === "HIGHLIGHTED") you = row;
|
|
120
|
+
else rows.push(row);
|
|
121
|
+
}
|
|
122
|
+
return { view: "following", period: str(get(raw, "data_period")), columns: FOLLOWING_COLUMNS, rows, you };
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const SNAPSHOT_ID = /snapshots\/([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})\/comments/i;
|
|
126
|
+
|
|
127
|
+
/** GET /followers-service/v1/snapshots/daily/{user_id}: a FLOW with one COMMUNITY_SNAPSHOT_CONTAINER per pillar. */
|
|
128
|
+
export function projectSnapshot(raw: unknown, userId: number): Extract<CommunityOutT, { view: "snapshot" }> {
|
|
129
|
+
const pillars: SnapshotPillarT[] = byType(raw, "COMMUNITY_SNAPSHOT_CONTAINER").map((node) => {
|
|
130
|
+
const c = node.content;
|
|
131
|
+
const id = str(get(c, "id")) ?? "";
|
|
132
|
+
const gauge = byType(get(c, "items"), "SCORE_GAUGE")[0];
|
|
133
|
+
const path = byType(get(c, "footer_overlay_items"), "REACTIONS_ARCH_MINI")
|
|
134
|
+
.map((n) => str(get(n, "content", "path")))
|
|
135
|
+
.find((p): p is string => p !== null);
|
|
136
|
+
const contributors = byType(get(c, "items"), "CONTRIBUTORS_TILE").flatMap((tile) =>
|
|
137
|
+
arr(get(tile, "content", "metrics")).map((m): Cell[] => [
|
|
138
|
+
str(get(m, "title")),
|
|
139
|
+
str(get(m, "status")),
|
|
140
|
+
str(get(m, "status_subtitle")),
|
|
141
|
+
str(get(m, "status_type")),
|
|
142
|
+
]),
|
|
143
|
+
);
|
|
144
|
+
return {
|
|
145
|
+
pillar: id.replace(/^everyday_stats_/, "") || (str(get(gauge, "content", "score_display_title"))?.toLowerCase() ?? "unknown"),
|
|
146
|
+
score: parseNumber(get(gauge, "content", "score_display")),
|
|
147
|
+
unit: str(get(gauge, "content", "score_display_suffix")),
|
|
148
|
+
snapshot_id: path?.match(SNAPSHOT_ID)?.[1] ?? null,
|
|
149
|
+
contributors,
|
|
150
|
+
};
|
|
151
|
+
});
|
|
152
|
+
const flowId = str(get(raw, "content", "flow_id"));
|
|
153
|
+
return {
|
|
154
|
+
view: "snapshot",
|
|
155
|
+
user_id: userId,
|
|
156
|
+
shared: true,
|
|
157
|
+
name: str(get(byType(raw, "SNAPSHOT_HEADER")[0], "content", "title")),
|
|
158
|
+
date: flowId?.match(/(\d{4}-\d{2}-\d{2})$/)?.[1] ?? null,
|
|
159
|
+
pillars,
|
|
160
|
+
note: pillars.length && pillars.every((p) => p.contributors.length === 0)
|
|
161
|
+
? "Scores only: no contributor details are shared."
|
|
162
|
+
: pillars.length ? "contributors: [title, value, usual, trend]" : null,
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
function firstString(node: unknown, keys: string[]): string | null {
|
|
167
|
+
for (const scope of [node, get(node, "content")]) {
|
|
168
|
+
for (const k of keys) {
|
|
169
|
+
const v = str(get(scope, k));
|
|
170
|
+
if (v) return v;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
return null;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/** GET /followers-service/v1/snapshots/{id}/comments. Items were empty in every capture, so read them loosely. */
|
|
177
|
+
export function projectComments(raw: unknown, snapshotId: string): Extract<CommunityOutT, { view: "comments" }> {
|
|
178
|
+
const comments = arr(get(raw, "items")).map((it): Cell[] => [
|
|
179
|
+
firstString(it, ["author_name", "user_name", "name", "title"]),
|
|
180
|
+
firstString(it, ["text", "body", "comment", "message", "subtitle"]),
|
|
181
|
+
firstString(it, ["created_at", "timestamp", "time", "time_ago", "date"]),
|
|
182
|
+
]);
|
|
183
|
+
const quick = arr(get(raw, "quick_reactions"))
|
|
184
|
+
.map((q) => str(get(q, "emoji")))
|
|
185
|
+
.filter((e): e is string => e !== null);
|
|
186
|
+
return { view: "comments", snapshot_id: snapshotId, columns: ["author", "text", "time"], comments, quick_reactions: quick };
|
|
187
|
+
}
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
// whoop_health (EXPERIMENTAL): WHOOP's paid health features. No totem test
|
|
2
|
+
// account has any of them, so only their locked, empty and not-set-up answers
|
|
3
|
+
// have been seen (live, 2026-11-22). Routes come from @Acetone1's map of the
|
|
4
|
+
// Android app:
|
|
5
|
+
// GET /healthspan-service/v1/healthspan/bff?date= {unlocked_content, locked_content}
|
|
6
|
+
// GET /sage-service/v1/sage/bff?date= blood pressure, same shape
|
|
7
|
+
// GET /arrhythmia-service/v2/afibhistory/screen 404 "No anf user" until set up;
|
|
8
|
+
// …/afibhistory/paginated?next_token=, /arrhythmia-service/v1/history/bff?historyDate=
|
|
9
|
+
// GET /advanced-labs-service/v1/advanced-labs/biomarkers/summary
|
|
10
|
+
// items[SEARCHABLE_BIOMARKERS_LIST].content.biomarkers[] {id, title, value, unit,
|
|
11
|
+
// status_type}; without results every value is "--" and status UNAVAILABLE.
|
|
12
|
+
// …/tests/history (sections[].items[], an EMPTY_TILE without tests),
|
|
13
|
+
// …/biomarkers/{id}?next_token= ({navigation_title, header{title, subtitle, pills},
|
|
14
|
+
// sections, status}; status UNAVAILABLE without results), …/tests/{id}, …/insights?testId=
|
|
15
|
+
// What is certain is exact (locked, no results, not set up, the biomarker
|
|
16
|
+
// list's fields, and Healthspan's unlocked screen, seen on a real account on
|
|
17
|
+
// 2026-11-22: projectHealthspan). Anything else is the screen passed through with
|
|
18
|
+
// its UI fields stripped and its size capped (src/lib/screen_content.ts).
|
|
19
|
+
import { get, str } from "../whoop/bff.js";
|
|
20
|
+
import { nodes } from "./v2/core_common.js";
|
|
21
|
+
import { screenContent } from "../lib/screen_content.js";
|
|
22
|
+
|
|
23
|
+
export const HEALTH_FEATURES = ["healthspan", "blood_pressure", "afib", "labs"] as const;
|
|
24
|
+
export type HealthFeatureName = (typeof HEALTH_FEATURES)[number];
|
|
25
|
+
|
|
26
|
+
export type FeatureStatus = "available" | "locked" | "not_set_up" | "no_data" | "unavailable";
|
|
27
|
+
export interface Biomarker { id: string; name: string | null; value: string | null; unit: string | null; status: string | null }
|
|
28
|
+
/** Healthspan, from its unlocked screen. Numbers as WHOOP shows them; years are signed (+ older, − younger). */
|
|
29
|
+
export interface Healthspan {
|
|
30
|
+
period: string | null;
|
|
31
|
+
calibrating: boolean;
|
|
32
|
+
whoop_age: number | null;
|
|
33
|
+
years_vs_actual_age: number | null;
|
|
34
|
+
pace_of_aging: number | null;
|
|
35
|
+
previous: { whoop_age: number | null; years_vs_actual_age: number | null; pace_of_aging: number | null } | null;
|
|
36
|
+
/** [area, contributor, long-term average, recent average, years it adds (+) or takes off (−)]. */
|
|
37
|
+
contributor_cols: ["area", "name", "long_avg", "recent_avg", "impact_years"];
|
|
38
|
+
contributors: Array<[string, string, string | null, string | null, number | null]>;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface HealthFeature {
|
|
42
|
+
status: FeatureStatus;
|
|
43
|
+
healthspan?: Healthspan;
|
|
44
|
+
message?: string | null;
|
|
45
|
+
content?: unknown;
|
|
46
|
+
truncated?: true;
|
|
47
|
+
biomarkers?: Biomarker[];
|
|
48
|
+
tests?: unknown;
|
|
49
|
+
next_cursor?: string | null;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** WHOOP's page token, wherever in the screen it sits (next_token / nextToken). */
|
|
53
|
+
export function nextToken(raw: unknown, depth = 0): string | null {
|
|
54
|
+
if (depth > 6 || typeof raw !== "object" || raw === null) return null;
|
|
55
|
+
for (const [k, v] of Object.entries(raw)) {
|
|
56
|
+
if (/^next_?token$/i.test(k) && typeof v === "string" && v) return v;
|
|
57
|
+
}
|
|
58
|
+
for (const v of Object.values(raw)) {
|
|
59
|
+
const t = nextToken(v, depth + 1);
|
|
60
|
+
if (t) return t;
|
|
61
|
+
}
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const lockedMessage = (raw: unknown): string | null => {
|
|
66
|
+
const head = str(get(raw, "locked_content", "header_text_display"));
|
|
67
|
+
const body = str(get(raw, "locked_content", "description_display"));
|
|
68
|
+
return [head, body].filter(Boolean).join(": ") || null;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
/** A screen whose filled-in shape is unknown: stripped, capped, with its page token. */
|
|
72
|
+
export function passThrough(content: unknown, maxChars = 2_500): HealthFeature {
|
|
73
|
+
const { content: c, truncated } = screenContent(content, maxChars);
|
|
74
|
+
const next = nextToken(content);
|
|
75
|
+
return { status: "available", content: c, ...(truncated ? { truncated: true as const } : {}), ...(next ? { next_cursor: next } : {}) };
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const num = (v: unknown): number | null => {
|
|
79
|
+
const m = typeof v === "string" ? v.replace(/,/g, "").match(/[-+]?\d+(?:\.\d+)?/) : null;
|
|
80
|
+
return m ? Number(m[0]) : typeof v === "number" ? v : null;
|
|
81
|
+
};
|
|
82
|
+
/** "TIME IN HR ZONES 1-3 (WEEKLY)" as "Time in HR zones 1-3 (weekly)". */
|
|
83
|
+
const sentence = (s: string | null): string => {
|
|
84
|
+
const low = (s ?? "").toLowerCase();
|
|
85
|
+
return (low.charAt(0).toUpperCase() + low.slice(1)).replace(/\brhr\b/gi, "RHR").replace(/\bhr\b/gi, "HR").replace(/^vo₂/i, "VO₂").replace(/\bvo₂ max\b/i, "VO₂ max");
|
|
86
|
+
};
|
|
87
|
+
/** "1.8 years older" as +1.8, "YOUNGER" as negative. */
|
|
88
|
+
const signedYears = (value: unknown, ...hints: unknown[]): number | null => {
|
|
89
|
+
const n = num(value);
|
|
90
|
+
if (n === null) return null;
|
|
91
|
+
if (typeof value === "string" && /^\s*[-+]/.test(value)) return n;
|
|
92
|
+
return hints.some((h) => typeof h === "string" && /younger/i.test(h)) ? -Math.abs(n) : Math.abs(n);
|
|
93
|
+
};
|
|
94
|
+
const amoeba = (a: unknown) => a && typeof a === "object" ? {
|
|
95
|
+
whoop_age: num(get(a, "age_value_display")),
|
|
96
|
+
years_vs_actual_age: signedYears(get(a, "years_difference_value_display"), get(a, "years_difference_subtitle_display"), get(a, "years_difference_value_style"), get(a, "age_subtitle_display")),
|
|
97
|
+
pace_of_aging: num(get(a, "pace_of_aging_display")),
|
|
98
|
+
} : null;
|
|
99
|
+
const reading = (r: unknown): string | null => {
|
|
100
|
+
const v = str(get(r, "value_display"));
|
|
101
|
+
// No data yet: WHOOP shows "--" (with a placeholder unit).
|
|
102
|
+
if (!v || /^[-–—\s]+$/.test(v)) return null;
|
|
103
|
+
const unit = str(get(r, "value_unit_display"));
|
|
104
|
+
return unit ? `${v} ${unit}` : v;
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Healthspan's unlocked screen (seen live, 2026-11-22): whoop_age_amoeba
|
|
109
|
+
* {age_value_display, years_difference_value_display + its OLDER/YOUNGER
|
|
110
|
+
* subtitle, pace_of_aging_display "1.1x", is_calibrating}, the same for the
|
|
111
|
+
* previous period, the period in date_picker.current_date_range_display, and
|
|
112
|
+
* items[TILE_SECTION Sleep|Strain|Fitness].content.items[CONTRIBUTORS_CONTAINER]
|
|
113
|
+
* .content.contributors[{title_display, content: {top_range_value (long-term
|
|
114
|
+
* average), expanded_bottom_range_value (recent), impact_value_display "+0.4"
|
|
115
|
+
* years, impact_value_style OLDER|YOUNGER}}]. Anything else passes through.
|
|
116
|
+
*/
|
|
117
|
+
export function projectHealthspan(unlocked: unknown): HealthFeature {
|
|
118
|
+
const now = amoeba(get(unlocked, "whoop_age_amoeba"));
|
|
119
|
+
if (!now || now.whoop_age === null) return passThrough(unlocked);
|
|
120
|
+
const contributors: Healthspan["contributors"] = [];
|
|
121
|
+
for (const section of nodes(get(unlocked, "items")).filter((i) => str(i.type) === "TILE_SECTION")) {
|
|
122
|
+
const area = str(get(section, "content", "title_display")) ?? "";
|
|
123
|
+
for (const box of nodes(get(section, "content", "items")).filter((i) => str(i.type) === "CONTRIBUTORS_CONTAINER")) {
|
|
124
|
+
for (const c of nodes(get(box, "content", "contributors"))) {
|
|
125
|
+
const body = get(c, "content");
|
|
126
|
+
contributors.push([area, sentence(str(c.title_display)), reading(get(body, "top_range_value")), reading(get(body, "expanded_bottom_range_value")),
|
|
127
|
+
signedYears(get(body, "impact_value_display"), get(body, "impact_value_style"))]);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return {
|
|
132
|
+
status: "available",
|
|
133
|
+
healthspan: {
|
|
134
|
+
period: str(get(unlocked, "date_picker", "current_date_range_display")),
|
|
135
|
+
calibrating: get(unlocked, "is_calibrating") === true || get(unlocked, "whoop_age_amoeba", "is_calibrating") === true,
|
|
136
|
+
...now,
|
|
137
|
+
previous: amoeba(get(unlocked, "previous_whoop_age_amoeba")),
|
|
138
|
+
contributor_cols: ["area", "name", "long_avg", "recent_avg", "impact_years"],
|
|
139
|
+
contributors,
|
|
140
|
+
},
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/** Healthspan and blood pressure: one locked/unlocked screen. */
|
|
145
|
+
export function projectLockable(raw: unknown, unlockedProjection: (u: unknown) => HealthFeature = passThrough): HealthFeature {
|
|
146
|
+
const unlocked = get(raw, "unlocked_content");
|
|
147
|
+
if (unlocked !== null && unlocked !== undefined) return unlockedProjection(unlocked);
|
|
148
|
+
if (get(raw, "locked_content")) return { status: "locked", message: lockedMessage(raw) };
|
|
149
|
+
return { status: "unavailable", message: "WHOOP returned neither content nor a lock." };
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/** The biomarkers that have a result, from the summary screen. */
|
|
153
|
+
export function projectLabs(raw: unknown): HealthFeature {
|
|
154
|
+
const list = nodes(get(raw, "items")).find((i) => str(i.type) === "SEARCHABLE_BIOMARKERS_LIST");
|
|
155
|
+
if (!list) return { status: "unavailable", message: "WHOOP's lab summary had no biomarker list." };
|
|
156
|
+
const withData = nodes(get(list, "content", "biomarkers")).filter((b) => str(b.status_type) !== "UNAVAILABLE" && str(b.value) !== "--");
|
|
157
|
+
if (!withData.length) return { status: "no_data", message: "No lab results (WHOOP Advanced Labs or uploaded)." };
|
|
158
|
+
return {
|
|
159
|
+
status: "available",
|
|
160
|
+
biomarkers: withData.map((b) => ({ id: str(b.id) ?? "", name: str(b.title), value: str(b.value), unit: str(b.unit), status: str(b.status_type) })),
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/** The lab tests on the Lab History screen, without its empty "upload labs" tile. */
|
|
165
|
+
export function projectLabTests(raw: unknown): unknown {
|
|
166
|
+
const items = nodes(get(raw, "paginated_records", "sections")).flatMap((s) => nodes(s.items)).filter((i) => str(i.type) !== "EMPTY_TILE");
|
|
167
|
+
return items.length ? screenContent(items, 1_500).content : null;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* A biomarker screen without results. Seen live on 2026-11-22: top-level
|
|
172
|
+
* status "UNAVAILABLE" (the summary's status_type for the same case), an
|
|
173
|
+
* EMPTY_TILE "Add Lab Results" section and a "learn more" EXPANDABLE_LIST.
|
|
174
|
+
* Without the status, a screen holding only those two kinds counts as empty.
|
|
175
|
+
*/
|
|
176
|
+
export function biomarkerEmpty(raw: unknown): boolean {
|
|
177
|
+
if (str(get(raw, "status")) === "UNAVAILABLE") return true;
|
|
178
|
+
const items = nodes(get(raw, "sections")).flatMap((s) => nodes(s.items));
|
|
179
|
+
return items.some((i) => str(i.type) === "EMPTY_TILE") && items.every((i) => ["EMPTY_TILE", "EXPANDABLE_LIST"].includes(str(i.type) ?? ""));
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/** A biomarker's screen: its results, or no_data with what the biomarker is. */
|
|
183
|
+
export function projectBiomarker(raw: unknown): HealthFeature {
|
|
184
|
+
if (!biomarkerEmpty(raw)) return passThrough(raw, 3_000);
|
|
185
|
+
const name = str(get(raw, "header", "title"));
|
|
186
|
+
return {
|
|
187
|
+
status: "no_data",
|
|
188
|
+
message: `No results${name ? ` for ${name}` : ""} yet.`,
|
|
189
|
+
content: screenContent({ name, about: str(get(raw, "header", "subtitle")), tags: get(raw, "header", "pills") }).content,
|
|
190
|
+
};
|
|
191
|
+
}
|