@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,258 @@
|
|
|
1
|
+
// Exercise lookup for the v2 strength tools. Writes send WHOOP's own exercise row
|
|
2
|
+
// verbatim as `exercise_details` (a bare {exercise_id} is a 422), so rows come
|
|
3
|
+
// from the live catalog (GET /weightlifting-service/v2/exercise: 371 base rows plus
|
|
4
|
+
// this account's custom exercises; 24 h client cache), then GET
|
|
5
|
+
// /weightlifting-service/v1/exercise/{id} for ids it doesn't list, then the bundled
|
|
6
|
+
// catalog when WHOOP can't be read. Names resolve only on an exact (normalized)
|
|
7
|
+
// match; a miss returns the top-5 suggestions instead of guessing.
|
|
8
|
+
import type { WhoopClient } from "../whoop/client.js";
|
|
9
|
+
import { EXERCISES, EXERCISES_BY_ID } from "../data/exercises.js";
|
|
10
|
+
import type { OfficialExercise } from "../schemas/strength.js";
|
|
11
|
+
|
|
12
|
+
const CATALOG_PATH = "/weightlifting-service/v2/exercise";
|
|
13
|
+
|
|
14
|
+
export type ExerciseRow = Record<string, unknown> & { exercise_id: string; name: string };
|
|
15
|
+
|
|
16
|
+
export interface ExerciseRef {
|
|
17
|
+
exercise_id?: string | undefined;
|
|
18
|
+
name?: string | undefined;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface ResolvedExercise {
|
|
22
|
+
exercise_id: string;
|
|
23
|
+
name: string;
|
|
24
|
+
/** The row sent as exercise_details. */
|
|
25
|
+
row: ExerciseRow;
|
|
26
|
+
custom: boolean;
|
|
27
|
+
volume_input_format: string | null;
|
|
28
|
+
e1rm_eligible: boolean | null;
|
|
29
|
+
source: "live" | "v1" | "bundled";
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface Suggestion {
|
|
33
|
+
exercise_id: string;
|
|
34
|
+
name: string;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export type ResolveResult =
|
|
38
|
+
| { ok: true; exercise: ResolvedExercise }
|
|
39
|
+
| { ok: false; input: string; error: string; suggestions: Suggestion[] };
|
|
40
|
+
|
|
41
|
+
// Fixed timestamps for a rebuilt row: WHOOP requires non-empty ISO strings and
|
|
42
|
+
// ignores the values (totem's v1 body, accepted live 2026-11-21).
|
|
43
|
+
const FALLBACK_CREATED_AT = "2022-03-03T19:45:51.740Z";
|
|
44
|
+
const FALLBACK_UPDATED_AT = "2026-09-02T15:57:09.962Z";
|
|
45
|
+
|
|
46
|
+
/** Rebuild WHOOP's exercise row from a bundled catalog entry (no instructions or media URLs). */
|
|
47
|
+
export function bundledExerciseRow(e: OfficialExercise): ExerciseRow {
|
|
48
|
+
return {
|
|
49
|
+
training_types: e.training_types ?? [],
|
|
50
|
+
instructions: [],
|
|
51
|
+
muscle_groups: [...e.muscle_groups],
|
|
52
|
+
translated_muscle_groups: e.primary_muscle,
|
|
53
|
+
created_at: FALLBACK_CREATED_AT,
|
|
54
|
+
updated_at: FALLBACK_UPDATED_AT,
|
|
55
|
+
custom_exercise_info: null,
|
|
56
|
+
volume_input_value: null,
|
|
57
|
+
volume_input_units: null,
|
|
58
|
+
exercise_id: e.exercise_id,
|
|
59
|
+
name: e.name,
|
|
60
|
+
push_core_name: e.push_core_name,
|
|
61
|
+
trackable: e.trackable,
|
|
62
|
+
equipment: e.raw_equipment,
|
|
63
|
+
translated_equipment: e.equipment,
|
|
64
|
+
exercise_type: e.exercise_type,
|
|
65
|
+
laterality: e.laterality,
|
|
66
|
+
movement_pattern: e.raw_movement_pattern,
|
|
67
|
+
translated_movement_pattern: e.movement_pattern,
|
|
68
|
+
deleted: false,
|
|
69
|
+
volume_input_format: e.volume_input_format,
|
|
70
|
+
e1rm_eligible: e.e1rm_eligible,
|
|
71
|
+
custom_exercise: false,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** Lower-case alphanumerics only: "Bench Press - Barbell" and "BENCHPRESS_BARBELL" both → "benchpressbarbell". */
|
|
76
|
+
export function normalizeName(s: string): string {
|
|
77
|
+
return s.toLowerCase().replace(/[^a-z0-9]/g, "");
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function tokens(s: string): string[] {
|
|
81
|
+
return s.toLowerCase().split(/[^a-z0-9]+/).filter(Boolean);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
type Searchable = { exercise_id: string; name: string; muscle_groups?: unknown; raw_equipment?: unknown; equipment?: unknown };
|
|
85
|
+
|
|
86
|
+
/** Muscle groups and equipment as search words ("legs", "full body", "kettlebell"). */
|
|
87
|
+
function tagWords(row: Searchable): string[] {
|
|
88
|
+
const tags = [
|
|
89
|
+
...(Array.isArray(row.muscle_groups) ? row.muscle_groups : []),
|
|
90
|
+
typeof row.raw_equipment === "string" ? row.raw_equipment : row.equipment,
|
|
91
|
+
];
|
|
92
|
+
return tags.flatMap((t) => (typeof t === "string" ? tokens(t.replace(/_/g, " ")) : []));
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Relevance of a row to a free-text query: whole-word hits (name, id, muscle
|
|
97
|
+
* group, equipment), then prefix hits, then substring. 0 = no match.
|
|
98
|
+
*/
|
|
99
|
+
export function matchScore(query: string, row: Searchable): number {
|
|
100
|
+
const q = tokens(query);
|
|
101
|
+
if (q.length === 0) return 0;
|
|
102
|
+
const words = [...tokens(row.name), ...tokens(row.exercise_id.replace(/_/g, " ")), ...tagWords(row)];
|
|
103
|
+
let score = 0;
|
|
104
|
+
for (const t of q) {
|
|
105
|
+
if (words.includes(t)) score += 3;
|
|
106
|
+
else if (words.some((w) => w.startsWith(t))) score += 2;
|
|
107
|
+
else if (normalizeName(row.name).includes(t) || normalizeName(row.exercise_id).includes(t)) score += 1;
|
|
108
|
+
else return 0; // every query word must appear somewhere
|
|
109
|
+
}
|
|
110
|
+
if (normalizeName(row.name) === normalizeName(query)) score += 10;
|
|
111
|
+
return score;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** Ranked matches for a free-text query (ties: shorter name first). */
|
|
115
|
+
export function rankMatches<T extends Searchable>(query: string, rows: readonly T[]): T[] {
|
|
116
|
+
return rows
|
|
117
|
+
.map((row) => ({ row, score: matchScore(query, row) }))
|
|
118
|
+
.filter((x) => x.score > 0)
|
|
119
|
+
.sort((a, b) => b.score - a.score || a.row.name.length - b.row.name.length)
|
|
120
|
+
.map((x) => x.row);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** Up to 5 catalog suggestions for a missed name or id; falls back to any-word matches. */
|
|
124
|
+
export function suggestExercises(query: string, rows: readonly { exercise_id: string; name: string }[]): Suggestion[] {
|
|
125
|
+
let ranked = rankMatches(query, rows);
|
|
126
|
+
if (ranked.length === 0) {
|
|
127
|
+
const words = tokens(query).filter((w) => w.length >= 3);
|
|
128
|
+
ranked = rows
|
|
129
|
+
.map((row) => ({ row, hits: words.filter((w) => normalizeName(row.name).includes(w)).length }))
|
|
130
|
+
.filter((x) => x.hits > 0)
|
|
131
|
+
.sort((a, b) => b.hits - a.hits || a.row.name.length - b.row.name.length)
|
|
132
|
+
.map((x) => x.row);
|
|
133
|
+
}
|
|
134
|
+
return ranked.slice(0, 5).map((r) => ({ exercise_id: r.exercise_id, name: r.name }));
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function isRow(v: unknown): v is ExerciseRow {
|
|
138
|
+
return typeof v === "object" && v !== null && typeof (v as ExerciseRow).exercise_id === "string" && typeof (v as ExerciseRow).name === "string";
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/** Live catalog rows (base + this account's customs), or null if WHOOP can't be read. */
|
|
142
|
+
export async function liveCatalog(client: WhoopClient, fresh = false): Promise<ExerciseRow[] | null> {
|
|
143
|
+
try {
|
|
144
|
+
const raw = await client.get<{ exercises?: unknown[] }>(CATALOG_PATH, {}, { fresh });
|
|
145
|
+
const rows = Array.isArray(raw?.exercises) ? raw.exercises.filter(isRow) : [];
|
|
146
|
+
return rows.length > 0 ? rows : null;
|
|
147
|
+
} catch {
|
|
148
|
+
return null;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function resolved(row: ExerciseRow, source: ResolvedExercise["source"]): ResolvedExercise {
|
|
153
|
+
return {
|
|
154
|
+
exercise_id: row.exercise_id,
|
|
155
|
+
name: row.name,
|
|
156
|
+
row,
|
|
157
|
+
custom: row.custom_exercise === true,
|
|
158
|
+
volume_input_format: typeof row.volume_input_format === "string" ? row.volume_input_format : null,
|
|
159
|
+
e1rm_eligible: typeof row.e1rm_eligible === "boolean" ? row.e1rm_eligible : null,
|
|
160
|
+
source,
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Resolves several exercise refs against one lazily loaded catalog. A miss on
|
|
166
|
+
* the cached catalog re-reads it fresh once (a custom exercise created since the
|
|
167
|
+
* cache filled), then tries v1/exercise/{id} for ids.
|
|
168
|
+
*/
|
|
169
|
+
export class ExerciseResolver {
|
|
170
|
+
private live: ExerciseRow[] | null | undefined;
|
|
171
|
+
private refreshed = false;
|
|
172
|
+
|
|
173
|
+
constructor(private readonly client: WhoopClient) {}
|
|
174
|
+
|
|
175
|
+
private async rows(): Promise<ExerciseRow[] | null> {
|
|
176
|
+
if (this.live === undefined) this.live = await liveCatalog(this.client);
|
|
177
|
+
return this.live;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
private async refresh(): Promise<ExerciseRow[] | null> {
|
|
181
|
+
if (!this.refreshed) {
|
|
182
|
+
this.refreshed = true;
|
|
183
|
+
this.live = (await liveCatalog(this.client, true)) ?? this.live ?? null;
|
|
184
|
+
}
|
|
185
|
+
return this.live ?? null;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
private suggestionPool(): readonly { exercise_id: string; name: string }[] {
|
|
189
|
+
const customs = (this.live ?? []).filter((r) => r.custom_exercise === true && r.deleted !== true);
|
|
190
|
+
return [...EXERCISES, ...customs];
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
async resolve(ref: ExerciseRef): Promise<ResolveResult> {
|
|
194
|
+
const id = ref.exercise_id?.trim();
|
|
195
|
+
const name = ref.name?.trim();
|
|
196
|
+
if (!id && !name) return { ok: false, input: "", error: "Give exercise_id or name.", suggestions: [] };
|
|
197
|
+
|
|
198
|
+
if (id) {
|
|
199
|
+
const findId = (rows: ExerciseRow[] | null) =>
|
|
200
|
+
rows?.find((r) => r.exercise_id === id || r.exercise_id.toUpperCase() === id.toUpperCase());
|
|
201
|
+
const hit = findId(await this.rows()) ?? findId(await this.refresh());
|
|
202
|
+
if (hit) {
|
|
203
|
+
if (hit.deleted === true) return { ok: false, input: id, error: `Exercise ${id} is deleted.`, suggestions: [] };
|
|
204
|
+
return { ok: true, exercise: resolved(hit, "live") };
|
|
205
|
+
}
|
|
206
|
+
// Not listed: a catalog id while WHOOP's list is unreadable, or an id the list omits.
|
|
207
|
+
try {
|
|
208
|
+
const row = await this.client.get<unknown>(`/weightlifting-service/v1/exercise/${encodeURIComponent(id)}`);
|
|
209
|
+
if (isRow(row)) {
|
|
210
|
+
if (row.deleted === true) return { ok: false, input: id, error: `Exercise ${id} is deleted.`, suggestions: [] };
|
|
211
|
+
return { ok: true, exercise: resolved(row, "v1") };
|
|
212
|
+
}
|
|
213
|
+
} catch {
|
|
214
|
+
// fall through to the bundle
|
|
215
|
+
}
|
|
216
|
+
const bundled = EXERCISES_BY_ID.get(id) ?? EXERCISES_BY_ID.get(id.toUpperCase());
|
|
217
|
+
if (bundled) return { ok: true, exercise: resolved(bundledExerciseRow(bundled), "bundled") };
|
|
218
|
+
return { ok: false, input: id, error: `Unknown exercise_id "${id}".`, suggestions: suggestExercises(id.replace(/_/g, " "), this.suggestionPool()) };
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
const wanted = normalizeName(name!);
|
|
222
|
+
const findName = (rows: readonly ExerciseRow[] | null) =>
|
|
223
|
+
rows?.filter((r) => r.deleted !== true && (normalizeName(r.name) === wanted || normalizeName(r.exercise_id) === wanted)) ?? [];
|
|
224
|
+
let hits = findName(await this.rows());
|
|
225
|
+
if (hits.length === 0) hits = findName(await this.refresh());
|
|
226
|
+
if (hits.length === 0 && !this.live) {
|
|
227
|
+
const bundled = EXERCISES.filter((e) => normalizeName(e.name) === wanted || normalizeName(e.exercise_id) === wanted);
|
|
228
|
+
if (bundled.length === 1) return { ok: true, exercise: resolved(bundledExerciseRow(bundled[0]!), "bundled") };
|
|
229
|
+
}
|
|
230
|
+
if (hits.length === 1) return { ok: true, exercise: resolved(hits[0]!, "live") };
|
|
231
|
+
if (hits.length > 1) {
|
|
232
|
+
return {
|
|
233
|
+
ok: false,
|
|
234
|
+
input: name!,
|
|
235
|
+
error: `"${name}" matches ${hits.length} exercises; pass exercise_id.`,
|
|
236
|
+
suggestions: hits.slice(0, 5).map((r) => ({ exercise_id: r.exercise_id, name: r.name })),
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
return { ok: false, input: name!, error: `No exercise named "${name}".`, suggestions: suggestExercises(name!, this.suggestionPool()) };
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/** Resolve all refs; any miss fails the batch with every miss listed. */
|
|
243
|
+
async resolveAll(refs: ExerciseRef[]): Promise<{ ok: true; exercises: ResolvedExercise[] } | { ok: false; misses: Array<{ index: number; input: string; error: string; suggestions: Suggestion[] }> }> {
|
|
244
|
+
const out: ResolvedExercise[] = [];
|
|
245
|
+
const misses: Array<{ index: number; input: string; error: string; suggestions: Suggestion[] }> = [];
|
|
246
|
+
for (const [index, ref] of refs.entries()) {
|
|
247
|
+
const r = await this.resolve(ref);
|
|
248
|
+
if (r.ok) out.push(r.exercise);
|
|
249
|
+
else misses.push({ index, input: r.input, error: r.error, suggestions: r.suggestions });
|
|
250
|
+
}
|
|
251
|
+
return misses.length > 0 ? { ok: false, misses } : { ok: true, exercises: out };
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/** Custom exercises from the live catalog (empty when unreadable). */
|
|
255
|
+
async customs(): Promise<ExerciseRow[]> {
|
|
256
|
+
return ((await this.rows()) ?? []).filter((r) => r.custom_exercise === true && r.deleted !== true);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// Reading GET /weightlifting-service/v3/exercise/{id}/exercise_history across pages.
|
|
2
|
+
// Live (2026-11-21): a page holds 5 workout cards, newest workout first, and
|
|
3
|
+
// `show_more.next_start_date` is an exclusive upper-bound timestamp for the next
|
|
4
|
+
// page. A newly logged or linked workout can take ~30 s to appear.
|
|
5
|
+
import type { WhoopClient } from "../whoop/client.js";
|
|
6
|
+
import { convertWeight, type WeightUnit } from "../whoop/units.js";
|
|
7
|
+
import { parseLiftCards, type LiftCard } from "../projections/lift_cards.js";
|
|
8
|
+
|
|
9
|
+
export const historyPath = (exerciseId: string) => `/weightlifting-service/v3/exercise/${encodeURIComponent(exerciseId)}/exercise_history`;
|
|
10
|
+
|
|
11
|
+
/** History shows weights as whole numbers in the display unit (44.09 lb reads "44", 49.6 reads "50"). */
|
|
12
|
+
const SHOWN_WEIGHT_TOLERANCE = 0.6;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Compare the weights a history card shows with the weights that were sent, in
|
|
16
|
+
* the unit the card shows them in. A unit mix-up is a factor of 2.2, far outside
|
|
17
|
+
* the display rounding. Returns null when they agree or can't be compared (set
|
|
18
|
+
* count differs, or the card shows no weight unit); else both lists, per set.
|
|
19
|
+
*/
|
|
20
|
+
export function weightMismatch(card: LiftCard, sent: number[], sentUnit: WeightUnit): { shown: Array<number | null>; expected: number[]; unit: WeightUnit } | null {
|
|
21
|
+
if (card.sets.length !== sent.length) return null;
|
|
22
|
+
const unit = card.sets.find((s) => s.unit)?.unit;
|
|
23
|
+
if (!unit) return null;
|
|
24
|
+
const expected = sent.map((w) => convertWeight(w, sentUnit, unit));
|
|
25
|
+
const shown = card.sets.map((s) => s.weight);
|
|
26
|
+
const off = shown.some((w, i) => w !== null && Math.abs(w - expected[i]!) > SHOWN_WEIGHT_TOLERANCE);
|
|
27
|
+
return off ? { shown, expected, unit } : null;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Read-back pacing; tests set this to zeros. */
|
|
31
|
+
export const liftReadback = { delaysMs: [0, 4_000, 8_000] as number[] };
|
|
32
|
+
|
|
33
|
+
const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms));
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Page through an exercise's history, newest first, until `notBefore` (ISO) is
|
|
37
|
+
* passed, `maxPages` is reached, or `visit` returns true. Errors end the walk.
|
|
38
|
+
*/
|
|
39
|
+
export async function walkHistory(
|
|
40
|
+
client: WhoopClient,
|
|
41
|
+
exerciseId: string,
|
|
42
|
+
opts: { notBefore?: string | undefined; maxPages: number; fresh?: boolean },
|
|
43
|
+
visit: (cards: LiftCard[]) => boolean | void,
|
|
44
|
+
): Promise<void> {
|
|
45
|
+
let cursor: string | null = null;
|
|
46
|
+
for (let page = 0; page < opts.maxPages; page++) {
|
|
47
|
+
let raw: unknown;
|
|
48
|
+
try {
|
|
49
|
+
raw = await client.get(historyPath(exerciseId), cursor ? { startDate: cursor } : {}, opts.fresh ? { fresh: true } : {});
|
|
50
|
+
} catch {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
const { cards, next_cursor } = parseLiftCards(raw);
|
|
54
|
+
if (visit(cards) === true) return;
|
|
55
|
+
if (!next_cursor || (opts.notBefore && next_cursor < opts.notBefore)) return;
|
|
56
|
+
cursor = next_cursor;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* The history card for one activity, read fresh, retried while WHOOP catches up.
|
|
62
|
+
* `notBefore` (the workout's start) bounds the paging.
|
|
63
|
+
*/
|
|
64
|
+
export async function findHistoryCard(client: WhoopClient, exerciseId: string, activityId: string, notBefore: string | undefined): Promise<LiftCard | null> {
|
|
65
|
+
for (const delay of liftReadback.delaysMs) {
|
|
66
|
+
if (delay > 0) await sleep(delay);
|
|
67
|
+
let found: LiftCard | null = null;
|
|
68
|
+
await walkHistory(client, exerciseId, { notBefore, maxPages: 6, fresh: true }, (cards) => {
|
|
69
|
+
found = cards.find((c) => c.activity_id === activityId) ?? null;
|
|
70
|
+
return found !== null;
|
|
71
|
+
});
|
|
72
|
+
if (found) return found;
|
|
73
|
+
}
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
// Set building for the v2 lift writes (whoop_lift_log, whoop_lift_template).
|
|
2
|
+
// Set timing, the 0-rep guard and the requested/saved window come from PR #40 by
|
|
3
|
+
// @chaotix345; units follow SPEC.md D2 (weights are read in the account's display
|
|
4
|
+
// unit at write time).
|
|
5
|
+
import { randomUUID } from "node:crypto";
|
|
6
|
+
import { canonicalUtc, parsePgRange } from "./dates.js";
|
|
7
|
+
import { convertWeight, type WeightUnit } from "../whoop/units.js";
|
|
8
|
+
import type { ResolvedExercise } from "./lift_catalog.js";
|
|
9
|
+
|
|
10
|
+
export interface SetInput {
|
|
11
|
+
reps?: number | undefined;
|
|
12
|
+
weight?: number | undefined;
|
|
13
|
+
time_seconds?: number | undefined;
|
|
14
|
+
performed?: boolean | undefined;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface ExerciseSets {
|
|
18
|
+
exercise: ResolvedExercise;
|
|
19
|
+
sets: SetInput[];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Split [start, end) into n back-to-back set slots, the last ending exactly at
|
|
24
|
+
* `end`, so the saved window (WHOOP keeps the union of `during` and every set's
|
|
25
|
+
* `during`) is exactly the requested one.
|
|
26
|
+
*/
|
|
27
|
+
export function setSlots(startMs: number, endMs: number, n: number): Array<[number, number]> {
|
|
28
|
+
if (n <= 0) return [];
|
|
29
|
+
const slot = Math.floor((endMs - startMs) / n);
|
|
30
|
+
return Array.from({ length: n }, (_, i) => [startMs + i * slot, i === n - 1 ? endMs : startMs + (i + 1) * slot]);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function duringLiteral(startMs: number, endMs: number): string {
|
|
34
|
+
return `['${canonicalUtc(startMs)}','${canonicalUtc(endMs)}')`;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** "['a','b')" → [ms, ms], or null. */
|
|
38
|
+
export function parseDuring(during: unknown): [number, number] | null {
|
|
39
|
+
if (typeof during !== "string") return null;
|
|
40
|
+
try {
|
|
41
|
+
const r = parsePgRange(during);
|
|
42
|
+
const a = Date.parse(r.start);
|
|
43
|
+
const b = r.end ? Date.parse(r.end) : NaN;
|
|
44
|
+
return Number.isNaN(a) || Number.isNaN(b) ? null : [a, b];
|
|
45
|
+
} catch {
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Sets with weight but 0 reps. WHOOP awards a weight PR for them (a 0×300 set
|
|
52
|
+
* won a permanent gold PR, and `v3/prs` tiles survive deleting the activity), so
|
|
53
|
+
* they are refused. Only a timed exercise may carry weight with no reps (a
|
|
54
|
+
* weighted hold): pass `timed` once the exercise is resolved. While it is
|
|
55
|
+
* unknown, a set with time_seconds gets the benefit of the doubt.
|
|
56
|
+
*/
|
|
57
|
+
export function zeroRepWeightedSets(items: Array<{ label: string; sets: SetInput[]; timed?: boolean }>): Array<{ exercise: string; set_number: number; weight: number }> {
|
|
58
|
+
const bad: Array<{ exercise: string; set_number: number; weight: number }> = [];
|
|
59
|
+
for (const it of items) {
|
|
60
|
+
it.sets.forEach((s, i) => {
|
|
61
|
+
const timedSet = it.timed !== false && Boolean(s.time_seconds);
|
|
62
|
+
if ((s.reps ?? 0) === 0 && (s.weight ?? 0) > 0 && !timedSet) bad.push({ exercise: it.label, set_number: i + 1, weight: s.weight! });
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
return bad;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** Shape problems a model can fix: TIME exercises need time_seconds, the others need reps. */
|
|
69
|
+
export function setShapeProblems(items: ExerciseSets[]): string[] {
|
|
70
|
+
const problems: string[] = [];
|
|
71
|
+
for (const { exercise, sets } of items) {
|
|
72
|
+
const time = exercise.volume_input_format === "TIME";
|
|
73
|
+
sets.forEach((s, i) => {
|
|
74
|
+
if (time && !(s.time_seconds && s.time_seconds > 0)) problems.push(`${exercise.name} is timed: set ${i + 1} needs time_seconds.`);
|
|
75
|
+
if (!time && s.reps === undefined) problems.push(`${exercise.name}: set ${i + 1} needs reps.`);
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
return problems;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** Weight in the input unit → the account's display unit (WHOOP reads it that way). */
|
|
82
|
+
export function sentWeight(weight: number | undefined, input: WeightUnit, account: WeightUnit): number {
|
|
83
|
+
return weight === undefined ? 0 : convertWeight(weight, input, account);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* workout_groups for POST /weightlifting-service/v2/weightlifting-workout/activity.
|
|
88
|
+
* Performed sets get a slot of the window; `performed:false` sets carry no
|
|
89
|
+
* `during` (WHOOP's "not performed": no volume, absent from history).
|
|
90
|
+
*/
|
|
91
|
+
export function buildActivityGroups(
|
|
92
|
+
items: ExerciseSets[],
|
|
93
|
+
window: { startMs: number; endMs: number },
|
|
94
|
+
units: { input: WeightUnit; account: WeightUnit },
|
|
95
|
+
uuid: () => string = () => randomUUID().toUpperCase(),
|
|
96
|
+
): { workout_groups: unknown[]; performed_sets: number; slots: Array<[number, number]> } {
|
|
97
|
+
const performed = items.reduce((n, it) => n + it.sets.filter((s) => s.performed !== false).length, 0);
|
|
98
|
+
const slots = setSlots(window.startMs, window.endMs, performed);
|
|
99
|
+
let k = 0;
|
|
100
|
+
const workout_groups = items.map(({ exercise, sets }) => ({
|
|
101
|
+
workout_exercises: [{
|
|
102
|
+
exercise_details: exercise.row,
|
|
103
|
+
sets: sets.map((s) => {
|
|
104
|
+
const set: Record<string, unknown> = {
|
|
105
|
+
weightlifting_workout_set_id: uuid(),
|
|
106
|
+
number_of_reps: s.reps ?? 0,
|
|
107
|
+
weight: sentWeight(s.weight, units.input, units.account),
|
|
108
|
+
};
|
|
109
|
+
if (s.time_seconds !== undefined) set.time_in_seconds = s.time_seconds;
|
|
110
|
+
if (s.performed !== false) {
|
|
111
|
+
const [a, b] = slots[k++]!;
|
|
112
|
+
set.during = duringLiteral(a, b);
|
|
113
|
+
}
|
|
114
|
+
return set;
|
|
115
|
+
}),
|
|
116
|
+
}],
|
|
117
|
+
}));
|
|
118
|
+
return { workout_groups, performed_sets: performed, slots };
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* workout_groups for templates and link-cardio-workout: sets carry only
|
|
123
|
+
* {number_of_reps, weight, time_in_seconds} (WHOOP drops anything else).
|
|
124
|
+
*/
|
|
125
|
+
export function buildTemplateGroups(items: ExerciseSets[], units: { input: WeightUnit; account: WeightUnit }): unknown[] {
|
|
126
|
+
return items.map(({ exercise, sets }) => ({
|
|
127
|
+
workout_exercises: [{
|
|
128
|
+
exercise_details: exercise.row,
|
|
129
|
+
sets: sets.map((s) => {
|
|
130
|
+
const set: Record<string, unknown> = {
|
|
131
|
+
number_of_reps: s.reps ?? 0,
|
|
132
|
+
weight: sentWeight(s.weight, units.input, units.account),
|
|
133
|
+
};
|
|
134
|
+
if (s.time_seconds !== undefined) set.time_in_seconds = s.time_seconds;
|
|
135
|
+
return set;
|
|
136
|
+
}),
|
|
137
|
+
}],
|
|
138
|
+
}));
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function isIana(tz: string): boolean {
|
|
142
|
+
try {
|
|
143
|
+
new Intl.DateTimeFormat("en-US", { timeZone: tz }).format();
|
|
144
|
+
return true;
|
|
145
|
+
} catch {
|
|
146
|
+
return false;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* The IANA zone sent with a lift. WHOOP_TIMEZONE when it is an IANA name (cloud
|
|
152
|
+
* hosts run in UTC), else the system zone, else UTC. Never a bare offset.
|
|
153
|
+
*/
|
|
154
|
+
export function liftTimezone(): string {
|
|
155
|
+
const env = process.env.WHOOP_TIMEZONE;
|
|
156
|
+
if (env && env.includes("/") && isIana(env)) return env;
|
|
157
|
+
const system = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
158
|
+
return isIana(system) ? system : "UTC";
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/** "2026-11-21 09:00:00" in the given zone. */
|
|
162
|
+
export function localTime(ms: number, timezone: string): string {
|
|
163
|
+
return new Date(ms).toLocaleString("sv-SE", { timeZone: timezone });
|
|
164
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// Small shared pieces of the v2 strength tool handlers.
|
|
2
|
+
import type { ToolResult } from "../tools/define.js";
|
|
3
|
+
import { jsonOut } from "../whoop/json_out.js";
|
|
4
|
+
import type { WhoopClient } from "../whoop/client.js";
|
|
5
|
+
import type { WeightUnit } from "../whoop/units.js";
|
|
6
|
+
|
|
7
|
+
/** A tool error the model can act on (suggestions, the fix), as isError output. */
|
|
8
|
+
export function liftError(payload: Record<string, unknown>): ToolResult {
|
|
9
|
+
return { content: [{ type: "text", text: jsonOut(payload) }], isError: true };
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/** The display unit for labelling reads (cached bootstrap); null if it can't be read. */
|
|
13
|
+
export async function displayUnitForReads(client: WhoopClient): Promise<WeightUnit | null> {
|
|
14
|
+
try {
|
|
15
|
+
const boot = await client.get<{ profile?: { unit_system?: string } }>("/users-service/v2/bootstrap");
|
|
16
|
+
const system = boot?.profile?.unit_system;
|
|
17
|
+
return system === "metric" ? "kg" : system === "imperial" ? "lb" : null;
|
|
18
|
+
} catch {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function errorMessage(e: unknown): string {
|
|
24
|
+
return e instanceof Error ? e.message : String(e);
|
|
25
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
// Closed enums and small helpers for the profile and settings tools
|
|
2
|
+
// (SPEC.md §4.8, §7 S6–S8). WHOOP accepts junk on several of these endpoints
|
|
3
|
+
// (any hidden-metric string, any dashboard count), so totem enforces its own.
|
|
4
|
+
|
|
5
|
+
export const HIDDEN_METRICS = ["BODY_COMP", "HEALTHSPAN"] as const;
|
|
6
|
+
|
|
7
|
+
/** Push namespaces, case-sensitive (a lowercase one is a 400 or a silent no-op). */
|
|
8
|
+
export const NOTIFICATION_NAMESPACES = ["StressSummary", "GPS", "ConversationalCheckIn", "CheckIn"] as const;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* The two clock formats that were written and read back live. WHOOP's enum has
|
|
12
|
+
* a third, TWELVE_HOUR_FORMAT_NO_PERIOD, known only from a 400's enum list:
|
|
13
|
+
* never sent by the app, never returned. Values copied from an error message
|
|
14
|
+
* are what broke Smart Alarm preferences (SPEC §7 S1), so it stays out.
|
|
15
|
+
*/
|
|
16
|
+
export const CLOCK_FORMATS = ["TWELVE_HOUR_FORMAT", "TWENTY_FOUR_HOUR_FORMAT"] as const;
|
|
17
|
+
|
|
18
|
+
/** The server's KeyMetric enum (settings §2.15). */
|
|
19
|
+
export const KEY_METRICS = [
|
|
20
|
+
"REM_SLEEP_DURATION", "CALORIES", "STEPS", "SLEEP_PERFORMANCE", "IN_SLEEP_EFFICIENCY", "AVERAGE_HR",
|
|
21
|
+
"TOTAL_VOLUME_LOAD", "RECOVERY", "DAY_STRAIN", "RHR", "HR_ZONES_4_5", "VO2_MAX", "PREGNANCY_WEEK",
|
|
22
|
+
"STRAIN_AND_RECOVERY", "CGM", "RESTORATIVE_SLEEP_PERCENT", "MENSTRUAL_CYCLE_INSIGHTS", "STRESS_MONITOR",
|
|
23
|
+
"SLEEP_CONSISTENCY", "HR_ZONES_ALL", "WEIGHT", "TIME_IN_BED", "STRENGTH_ACTIVITY_TIME", "HRV",
|
|
24
|
+
"RESPIRATORY_RATE", "HR_ZONES_1_3", "SLEEP_NEED", "SLEEP_HOURS", "SLEEP_NEED_FROM_SLEEP_DEBT_POST",
|
|
25
|
+
"BODY_COMPOSITION_LEAN",
|
|
26
|
+
] as const;
|
|
27
|
+
/** Dashboard gauge slots 0 and 2 are always these; only slots 1 and 3 are the user's. */
|
|
28
|
+
export const FIXED_GAUGES = ["RECOVERY", "DAY_STRAIN"] as const;
|
|
29
|
+
export const GAUGE_METRICS = KEY_METRICS.filter((m) => !(FIXED_GAUGES as readonly string[]).includes(m)) as unknown as readonly [string, ...string[]];
|
|
30
|
+
|
|
31
|
+
export const GENDERS = ["MALE", "FEMALE", "NON_BINARY", "PREFER_NOT"] as const;
|
|
32
|
+
export const BASELINES = ["MALE", "FEMALE"] as const;
|
|
33
|
+
export const UNIT_SYSTEMS = ["metric", "imperial"] as const;
|
|
34
|
+
|
|
35
|
+
/** Profile PUT bounds: WHOOP's UI limits (it doesn't bound height itself, and answers `false` above 272 kg). */
|
|
36
|
+
export const WEIGHT_KG = { min: 24, max: 272 } as const;
|
|
37
|
+
export const HEIGHT_M = { min: 0.91, max: 2.72 } as const;
|
|
38
|
+
|
|
39
|
+
/** "-08:00" / "-0800" / "GMT-08:00" → "-0800". */
|
|
40
|
+
export function normalizeOffset(raw: string | null | undefined): string | null {
|
|
41
|
+
if (!raw) return null;
|
|
42
|
+
if (/^(GMT|UTC)$/i.test(raw.trim())) return "+0000";
|
|
43
|
+
const m = raw.trim().match(/([+-])(\d{1,2}):?(\d{2})?$/);
|
|
44
|
+
if (!m) return null;
|
|
45
|
+
return `${m[1]}${m[2]!.padStart(2, "0")}${m[3] ?? "00"}`;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** The UTC offset an IANA zone has at `at`, as "-0800"; null for an unknown zone. */
|
|
49
|
+
export function zoneOffset(timeZone: string, at: Date = new Date()): string | null {
|
|
50
|
+
try {
|
|
51
|
+
const part = new Intl.DateTimeFormat("en-US", { timeZone, timeZoneName: "longOffset" })
|
|
52
|
+
.formatToParts(at).find((p) => p.type === "timeZoneName")?.value;
|
|
53
|
+
return normalizeOffset(part ?? null);
|
|
54
|
+
} catch {
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* The IANA zone totem would send WHOOP: WHOOP_TIMEZONE when it is a zone name,
|
|
61
|
+
* else this host's zone. Same source as the x-whoop-time-zone header.
|
|
62
|
+
*/
|
|
63
|
+
export function candidateTimeZone(): string | null {
|
|
64
|
+
const env = process.env.WHOOP_TIMEZONE;
|
|
65
|
+
if (env && env.includes("/")) return env;
|
|
66
|
+
const sys = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
67
|
+
return sys && sys.includes("/") ? sys : null;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Community privacy pillars (sleep, recovery, strain) come back as composite
|
|
72
|
+
* strings: `<audience>[_no_daily_stats|_no_trends|_score_only]`.
|
|
73
|
+
*/
|
|
74
|
+
export function decodePrivacyPillar(raw: string | null): { audience: string; trends: boolean; daily_stats: boolean } | null {
|
|
75
|
+
if (!raw) return null;
|
|
76
|
+
const m = raw.match(/^(everyone|friends|no_one)(_no_daily_stats|_no_trends|_score_only)?$/);
|
|
77
|
+
if (!m) return null;
|
|
78
|
+
const suffix = m[2] ?? "";
|
|
79
|
+
return {
|
|
80
|
+
audience: m[1]!,
|
|
81
|
+
trends: suffix === "" || suffix === "_no_daily_stats",
|
|
82
|
+
daily_stats: suffix === "" || suffix === "_no_trends",
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** Keys that carry live OAuth URLs with a `state` nonce and the user id (S24). */
|
|
87
|
+
const OAUTH_KEYS = /^(connection_url|cta_connection_url|web_authorization_url|app_authorization_url)$|authorization_url|oauth/i;
|
|
88
|
+
|
|
89
|
+
/** Deep copy without OAuth URLs or `state` nonces. */
|
|
90
|
+
export function stripOAuth(value: unknown): unknown {
|
|
91
|
+
if (Array.isArray(value)) return value.map(stripOAuth);
|
|
92
|
+
if (value !== null && typeof value === "object") {
|
|
93
|
+
const out: Record<string, unknown> = {};
|
|
94
|
+
for (const [k, v] of Object.entries(value)) {
|
|
95
|
+
if (OAUTH_KEYS.test(k)) continue;
|
|
96
|
+
if (typeof v === "string" && /[?&]state=/.test(v)) continue;
|
|
97
|
+
out[k] = stripOAuth(v);
|
|
98
|
+
}
|
|
99
|
+
return out;
|
|
100
|
+
}
|
|
101
|
+
return value;
|
|
102
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// A WHOOP app screen whose shape totem has never seen filled in (a feature no
|
|
2
|
+
// test account has unlocked), reduced to its content: UI plumbing dropped, text
|
|
3
|
+
// and numbers kept, size capped. Callers label the result unverified.
|
|
4
|
+
|
|
5
|
+
/** Keys that only drive the app's UI. */
|
|
6
|
+
const UI_KEY =
|
|
7
|
+
/(icon|image|url|color|colour|style|tint|gradient|background|font|typography|animation|lottie|corner|radius|analytics|destination|navigation|interaction|bindings|dismiss|deeplink|feature_flag|template|haptic|orientation|accessibility)/i;
|
|
8
|
+
|
|
9
|
+
const MAX_STRING = 300;
|
|
10
|
+
const MAX_DEPTH = 8;
|
|
11
|
+
|
|
12
|
+
function strip(node: unknown, depth: number, maxItems: number): unknown {
|
|
13
|
+
if (typeof node === "string") return node.length > MAX_STRING ? `${node.slice(0, MAX_STRING)}…` : node;
|
|
14
|
+
if (typeof node !== "object" || node === null) return node;
|
|
15
|
+
if (depth >= MAX_DEPTH) return undefined;
|
|
16
|
+
if (Array.isArray(node)) {
|
|
17
|
+
const kept = node.slice(0, maxItems).map((x) => strip(x, depth + 1, maxItems)).filter((x) => x !== undefined && x !== null && x !== "");
|
|
18
|
+
return kept.length ? kept : undefined;
|
|
19
|
+
}
|
|
20
|
+
const out: Record<string, unknown> = {};
|
|
21
|
+
for (const [k, v] of Object.entries(node)) {
|
|
22
|
+
if (UI_KEY.test(k)) continue;
|
|
23
|
+
const s = strip(v, depth + 1, maxItems);
|
|
24
|
+
if (s === undefined || s === null || s === "") continue;
|
|
25
|
+
if (typeof s === "object" && !Array.isArray(s) && Object.keys(s).length === 0) continue;
|
|
26
|
+
out[k] = s;
|
|
27
|
+
}
|
|
28
|
+
return Object.keys(out).length ? out : undefined;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** The screen's content within maxChars of JSON; truncated when lists were cut to fit. */
|
|
32
|
+
export function screenContent(node: unknown, maxChars = 2_000): { content: unknown; truncated: boolean } {
|
|
33
|
+
const full = strip(node, 0, Infinity) ?? null;
|
|
34
|
+
if (JSON.stringify(full).length <= maxChars) return { content: full, truncated: false };
|
|
35
|
+
for (const items of [20, 8, 3, 1]) {
|
|
36
|
+
const cut = strip(node, 0, items) ?? null;
|
|
37
|
+
if (JSON.stringify(cut).length <= maxChars) return { content: cut, truncated: true };
|
|
38
|
+
}
|
|
39
|
+
return { content: null, truncated: true };
|
|
40
|
+
}
|