@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
package/src/tools/v2/profile.ts
CHANGED
|
@@ -1,33 +1,63 @@
|
|
|
1
|
+
// whoop_profile (R): profile, body data, visibility settings, and on request HR
|
|
2
|
+
// zones, entitlements, integrations and community privacy. Absorbs
|
|
3
|
+
// whoop_hr_zones (SPEC.md §3.1, D15).
|
|
1
4
|
import { z } from "zod";
|
|
2
5
|
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
6
|
import type { WhoopClient } from "../../whoop/client.js";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
7
|
+
import { defineTool, respond } from "../define.js";
|
|
8
|
+
import { READ_ONLY } from "../annotations.js";
|
|
9
|
+
import { ProfileV2Out } from "../../schemas/profile_v2.js";
|
|
10
|
+
import { projectEntitlements, projectIntegrations, projectPrivacy, projectProfileV2 } from "../../projections/profile_v2.js";
|
|
11
|
+
import { hrZonesOut, parseHrZones } from "../../projections/settings_v2.js";
|
|
12
|
+
import { HIDDEN_METRICS } from "../../lib/profile_settings.js";
|
|
13
|
+
|
|
14
|
+
const NAME = "whoop_profile";
|
|
15
|
+
const INCLUDES = ["hr_zones", "entitlements", "integrations", "privacy"] as const;
|
|
8
16
|
|
|
9
17
|
export function registerProfile(server: McpServer, client: WhoopClient): void {
|
|
10
|
-
server
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
client.get("/users-service/v2/bootstrap", bootstrapQuery),
|
|
19
|
-
client.get("/users-service/v1/hidden-metrics/BODY_COMP").catch(() => null),
|
|
20
|
-
client.get("/users-service/v1/hidden-metrics/HEALTHSPAN").catch(() => null),
|
|
21
|
-
client.get("/users-service/v1/stealth-mode").catch(() => null),
|
|
22
|
-
]);
|
|
23
|
-
try {
|
|
24
|
-
const projected = projectProfile({ bootstrap, hidden_body_comp, hidden_healthspan, stealth });
|
|
25
|
-
const out = ProfileOut.parse(projected);
|
|
26
|
-
return { content: [{ type: "text", text: jsonOut(out) }] };
|
|
27
|
-
} catch (e) {
|
|
28
|
-
if (e instanceof z.ZodError) throw new WhoopProjectionError("whoop_profile", e);
|
|
29
|
-
throw e;
|
|
30
|
-
}
|
|
18
|
+
defineTool(server, {
|
|
19
|
+
name: NAME,
|
|
20
|
+
description:
|
|
21
|
+
"Your profile: name, email, birthday, gender, physiological baseline, height (m), weight (kg), unit system, location, max and " +
|
|
22
|
+
"resting HR, membership, hidden metrics and stealth mode. include adds hr_zones (bpm), entitlements (features that are off, and " +
|
|
23
|
+
"why), integrations and community privacy.",
|
|
24
|
+
input: {
|
|
25
|
+
include: z.array(z.enum(INCLUDES)).optional(),
|
|
31
26
|
},
|
|
32
|
-
|
|
27
|
+
annotations: READ_ONLY,
|
|
28
|
+
}, async ({ include }) => {
|
|
29
|
+
const wants = new Set(include ?? []);
|
|
30
|
+
const warnings: string[] = [];
|
|
31
|
+
const soft = <T>(label: string, p: Promise<T>): Promise<T | null> =>
|
|
32
|
+
p.catch((e: unknown) => {
|
|
33
|
+
warnings.push(`${label} unavailable: ${(e as Error).message}`);
|
|
34
|
+
return null;
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
const [bootstrap, edit, stealth, hidden, zones, settings, entitlements, integrations, privacy] = await Promise.all([
|
|
38
|
+
client.get("/users-service/v2/bootstrap"),
|
|
39
|
+
soft("Profile details", client.get("/profile-service/v1/profile/bff/edit")),
|
|
40
|
+
soft("Stealth mode", client.get("/users-service/v1/stealth-mode")),
|
|
41
|
+
// A failed read must not look like "not hidden": say so.
|
|
42
|
+
Promise.all(HIDDEN_METRICS.map((m) => soft(`Hidden-metric state for ${m}`, client.get(`/users-service/v1/hidden-metrics/${m}`)))),
|
|
43
|
+
wants.has("hr_zones") ? soft("HR zones", client.get("/hr-zones-service/v1/bff/zones")) : null,
|
|
44
|
+
wants.has("hr_zones") ? soft("HR zone settings", client.get("/hr-zones-service/v1/bff/settings")) : null,
|
|
45
|
+
wants.has("entitlements") ? soft("Entitlements", client.get("/entitlement-service/v1/entitlements")) : null,
|
|
46
|
+
wants.has("integrations") ? soft("Integrations", client.get("/integrations-bff/v1/integrations/discovery")) : null,
|
|
47
|
+
wants.has("privacy") ? soft("Privacy settings", client.get("/privacy-service/v1/community/privacy/settings")) : null,
|
|
48
|
+
]);
|
|
49
|
+
|
|
50
|
+
const out: Record<string, unknown> = projectProfileV2({
|
|
51
|
+
bootstrap,
|
|
52
|
+
edit,
|
|
53
|
+
stealth,
|
|
54
|
+
hidden: Object.fromEntries(HIDDEN_METRICS.map((m, i) => [m, hidden[i]])),
|
|
55
|
+
});
|
|
56
|
+
if (wants.has("hr_zones")) out.hr_zones = zones === null && settings === null ? null : hrZonesOut(parseHrZones({ zones, settings }));
|
|
57
|
+
if (wants.has("entitlements")) out.entitlements = entitlements === null ? null : projectEntitlements(entitlements);
|
|
58
|
+
if (wants.has("integrations")) out.integrations = integrations === null ? null : projectIntegrations(integrations);
|
|
59
|
+
if (wants.has("privacy")) out.privacy = privacy === null ? null : projectPrivacy(privacy);
|
|
60
|
+
out.warnings = warnings;
|
|
61
|
+
return respond(NAME, ProfileV2Out, out);
|
|
62
|
+
});
|
|
33
63
|
}
|
|
@@ -1,76 +1,167 @@
|
|
|
1
|
+
// whoop_profile_update (W!): change profile fields (SPEC.md §4.8, §7 S6).
|
|
2
|
+
//
|
|
3
|
+
// PUT /profile-service/v1/profile is a full replace, so the body is merged from
|
|
4
|
+
// a fresh read of the profile-edit screen (bootstrap's gender is a display
|
|
5
|
+
// string and its baseline is always null). Omitting `city` clears it, so it's
|
|
6
|
+
// always carried; omitting `physiological_baseline` keeps it, so it's only sent
|
|
7
|
+
// when asked. WHOOP answers `false` (HTTP 200) when it refuses the values.
|
|
1
8
|
import { z } from "zod";
|
|
2
9
|
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
10
|
import type { WhoopClient } from "../../whoop/client.js";
|
|
4
|
-
import {
|
|
11
|
+
import { defineTool, respond, type ToolResult } from "../define.js";
|
|
12
|
+
import { WRITE_DESTRUCTIVE } from "../annotations.js";
|
|
13
|
+
import { ProfileUpdateV2Out } from "../../schemas/profile_v2.js";
|
|
14
|
+
import { parseProfileEdit, type EditableProfile } from "../../projections/profile_v2.js";
|
|
5
15
|
import { preview } from "../../whoop/write_safety.js";
|
|
6
16
|
import { jsonOut } from "../../whoop/json_out.js";
|
|
7
|
-
import {
|
|
17
|
+
import { toKg } from "../../whoop/units.js";
|
|
18
|
+
import { todayIso } from "../../lib/dates.js";
|
|
19
|
+
import { BASELINES, GENDERS, HEIGHT_M, UNIT_SYSTEMS, WEIGHT_KG } from "../../lib/profile_settings.js";
|
|
8
20
|
|
|
21
|
+
const NAME = "whoop_profile_update";
|
|
9
22
|
const PATH = "/profile-service/v1/profile";
|
|
23
|
+
const EDIT = "/profile-service/v1/profile/bff/edit";
|
|
24
|
+
|
|
25
|
+
function fail(error: string, extra: Record<string, unknown> = {}): ToolResult {
|
|
26
|
+
return { content: [{ type: "text", text: jsonOut({ error, ...extra }) }], isError: true };
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
type Field = "first_name" | "last_name" | "birthday" | "gender" | "physiological_baseline" | "weight" | "height" | "city" | "state" | "country" | "unit_system";
|
|
30
|
+
type Value = string | number | null;
|
|
31
|
+
|
|
32
|
+
const same = (a: Value, b: Value) =>
|
|
33
|
+
typeof a === "number" && typeof b === "number" ? Math.abs(a - b) < 0.005 : a === b;
|
|
10
34
|
|
|
11
35
|
export function registerProfileUpdate(server: McpServer, client: WhoopClient): void {
|
|
12
|
-
server
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
36
|
+
defineTool(server, {
|
|
37
|
+
name: NAME,
|
|
38
|
+
description:
|
|
39
|
+
"Change profile fields; pass only what changes and the rest is kept. Weight is kg or lb (24–272 kg), height m, cm or in " +
|
|
40
|
+
"(0.91–2.72 m). Changing birthday or country makes WHOOP end the session; totem refreshes the token on the next call. Email " +
|
|
41
|
+
"can't be changed here. Previews unless confirm:true.",
|
|
42
|
+
input: {
|
|
43
|
+
first_name: z.string().trim().min(1).optional(),
|
|
44
|
+
last_name: z.string().trim().min(1).optional(),
|
|
45
|
+
birthday: z.iso.date().optional(),
|
|
46
|
+
gender: z.enum(GENDERS).optional(),
|
|
47
|
+
physiological_baseline: z.enum(BASELINES).optional().describe("Sex used for physiology baselines"),
|
|
48
|
+
weight: z.number().positive().optional(),
|
|
49
|
+
weight_unit: z.enum(["kg", "lb"]).optional().describe("Default kg"),
|
|
50
|
+
height: z.number().positive().optional(),
|
|
51
|
+
height_unit: z.enum(["m", "cm", "in"]).optional().describe("Default m"),
|
|
52
|
+
city: z.string().trim().optional(),
|
|
53
|
+
state: z.string().trim().min(1).optional().describe("Region code, e.g. CA; required for US"),
|
|
54
|
+
country: z.string().regex(/^[A-Za-z]{2}$/).optional(),
|
|
55
|
+
unit_system: z.enum(UNIT_SYSTEMS).optional().describe("Display units; also how WHOOP reads lift weights"),
|
|
28
56
|
confirm: z.boolean().default(false),
|
|
29
57
|
},
|
|
30
|
-
|
|
31
|
-
|
|
58
|
+
annotations: WRITE_DESTRUCTIVE,
|
|
59
|
+
}, async (args) => {
|
|
60
|
+
// 1. Validate before reading anything.
|
|
61
|
+
const wanted: Partial<Record<Field, Value>> = {};
|
|
62
|
+
if (args.first_name !== undefined) wanted.first_name = args.first_name;
|
|
63
|
+
if (args.last_name !== undefined) wanted.last_name = args.last_name;
|
|
64
|
+
if (args.birthday !== undefined) {
|
|
65
|
+
if (args.birthday > todayIso()) return fail("Birthday can't be in the future.");
|
|
66
|
+
wanted.birthday = args.birthday;
|
|
67
|
+
}
|
|
68
|
+
if (args.gender !== undefined) wanted.gender = args.gender;
|
|
69
|
+
if (args.physiological_baseline !== undefined) wanted.physiological_baseline = args.physiological_baseline;
|
|
70
|
+
if (args.weight_unit !== undefined && args.weight === undefined) return fail("weight_unit needs weight.");
|
|
71
|
+
if (args.height_unit !== undefined && args.height === undefined) return fail("height_unit needs height.");
|
|
72
|
+
if (args.weight !== undefined) {
|
|
73
|
+
const kg = Math.round(toKg(args.weight, args.weight_unit ?? "kg") * 100) / 100;
|
|
74
|
+
if (kg < WEIGHT_KG.min || kg > WEIGHT_KG.max) return fail(`Weight must be ${WEIGHT_KG.min}–${WEIGHT_KG.max} kg; got ${kg} kg.`);
|
|
75
|
+
wanted.weight = kg;
|
|
76
|
+
}
|
|
77
|
+
if (args.height !== undefined) {
|
|
78
|
+
const factor = { m: 1, cm: 0.01, in: 0.0254 }[args.height_unit ?? "m"];
|
|
79
|
+
const m = Math.round(args.height * factor * 1000) / 1000;
|
|
80
|
+
if (m < HEIGHT_M.min || m > HEIGHT_M.max) return fail(`Height must be ${HEIGHT_M.min}–${HEIGHT_M.max} m; got ${m} m.`);
|
|
81
|
+
wanted.height = m;
|
|
82
|
+
}
|
|
83
|
+
if (args.city !== undefined) wanted.city = args.city === "" ? null : args.city;
|
|
84
|
+
if (args.state !== undefined) wanted.state = args.state.toUpperCase();
|
|
85
|
+
if (args.country !== undefined) wanted.country = args.country.toUpperCase();
|
|
86
|
+
if (args.unit_system !== undefined) wanted.unit_system = args.unit_system;
|
|
87
|
+
if (Object.keys(wanted).length === 0) return fail("Pass at least one profile field to change.");
|
|
32
88
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
const u = isObject(boot.user) ? boot.user : {};
|
|
37
|
-
const p = isObject(boot.profile) ? boot.profile : {};
|
|
38
|
-
const acc = isObject(boot.account) ? boot.account : {};
|
|
39
|
-
const curGender = typeof p.gender === "string" ? p.gender.toUpperCase() : undefined;
|
|
40
|
-
// Birthday is stored as midnight-local (e.g. "...T17:00:00-07:00" == next-day
|
|
41
|
-
// midnight UTC); the UTC calendar date is the actual birthday.
|
|
42
|
-
const curBirthday = typeof p.birthday === "string" ? new Date(p.birthday).toISOString().slice(0, 10) : undefined;
|
|
43
|
-
const curBaseline = typeof p.physiological_baseline === "string" ? p.physiological_baseline.toUpperCase() : undefined;
|
|
89
|
+
// 2. Fresh merge base: the profile-edit screen (never bootstrap).
|
|
90
|
+
const current = parseProfileEdit(await client.get(EDIT, {}, { fresh: true }));
|
|
91
|
+
if (!current) return fail("Couldn't read your current profile, so nothing was sent (WHOOP's PUT replaces the whole profile).");
|
|
44
92
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
birthday: (birthday ? birthday.slice(0, 10) : undefined) ?? curBirthday,
|
|
50
|
-
gender: args.gender ?? curGender,
|
|
51
|
-
physiological_baseline: args.physiological_baseline ?? curBaseline ?? (curGender === "FEMALE" ? "FEMALE" : "MALE"),
|
|
52
|
-
weight: weight_kg ?? (typeof p.weight === "number" ? p.weight : undefined),
|
|
53
|
-
height: height_m ?? (typeof p.height === "number" ? p.height : undefined),
|
|
54
|
-
city: args.city ?? u.city,
|
|
55
|
-
state: args.state ?? u.admin_division,
|
|
56
|
-
country: args.country ?? u.country,
|
|
57
|
-
unit_system: args.unit_system ?? p.unit_system,
|
|
58
|
-
};
|
|
59
|
-
for (const k of Object.keys(merged)) if (merged[k] === undefined || merged[k] === null) delete merged[k];
|
|
93
|
+
// A state from the old country doesn't belong to a new one.
|
|
94
|
+
if (wanted.country !== undefined && wanted.country !== current.country && wanted.state === undefined) wanted.state = null;
|
|
95
|
+
const next: EditableProfile = { ...current };
|
|
96
|
+
for (const [k, v] of Object.entries(wanted) as Array<[Field, Value]>) (next as unknown as Record<string, Value>)[k] = v;
|
|
60
97
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
98
|
+
const missing = (["first_name", "last_name", "gender", "unit_system", "height", "weight"] as const).filter((k) => next[k] === null);
|
|
99
|
+
if (missing.length > 0) return fail(`Your WHOOP profile has no ${missing.join(", ")}; pass ${missing.length > 1 ? "them" : "it"} too (WHOOP requires the full profile).`);
|
|
100
|
+
// The PUT replaces the whole profile, and email, birthday and country have
|
|
101
|
+
// only ever been sent unchanged, never omitted. Don't find out what omitting does.
|
|
102
|
+
const absent = (["email", "birthday", "country"] as const).filter((k) => !next[k]);
|
|
103
|
+
if (absent.length > 0) {
|
|
104
|
+
return fail(`WHOOP's profile screen came back without ${absent.join(", ")}, and its PUT replaces the whole profile, so nothing was sent. Try again later.`);
|
|
105
|
+
}
|
|
106
|
+
if (next.country === "US" && !next.state) return fail("WHOOP requires a state for US profiles; pass state.");
|
|
65
107
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
108
|
+
const changes: Partial<Record<Field, [Value, Value]>> = {};
|
|
109
|
+
for (const [k, v] of Object.entries(wanted) as Array<[Field, Value]>) {
|
|
110
|
+
const before = current[k] as Value;
|
|
111
|
+
if (!same(before, v)) changes[k] = [before, v];
|
|
112
|
+
}
|
|
113
|
+
if (Object.keys(changes).length === 0) {
|
|
114
|
+
return respond(NAME, ProfileUpdateV2Out, { updated: false, no_change: true, changed: {}, verified: true, mismatches: [], warnings: [] });
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const warnings: string[] = [];
|
|
118
|
+
if (changes.birthday || changes.country) {
|
|
119
|
+
warnings.push("WHOOP ends the current session after a birthday or country change; totem refreshes the token automatically on the next request (one retry).");
|
|
120
|
+
}
|
|
121
|
+
if (changes.weight) warnings.push("A newer weight reading (whoop_weight_log) replaces the profile weight.");
|
|
122
|
+
if (changes.unit_system) warnings.push("WHOOP reads lift, template and 1RM weights in the display unit, so this also changes how those writes are interpreted.");
|
|
123
|
+
|
|
124
|
+
const body: Record<string, unknown> = {
|
|
125
|
+
first_name: next.first_name,
|
|
126
|
+
last_name: next.last_name,
|
|
127
|
+
email: next.email,
|
|
128
|
+
birthday: next.birthday,
|
|
129
|
+
gender: next.gender,
|
|
130
|
+
weight: next.weight,
|
|
131
|
+
height: next.height,
|
|
132
|
+
country: next.country,
|
|
133
|
+
unit_system: next.unit_system,
|
|
134
|
+
};
|
|
135
|
+
if (next.city !== null) body.city = next.city; // omitting city clears it, so carry it whenever it's set
|
|
136
|
+
if (next.state !== null) body.state = next.state;
|
|
137
|
+
if (wanted.physiological_baseline !== undefined) body.physiological_baseline = next.physiological_baseline; // omitted = kept
|
|
138
|
+
for (const k of Object.keys(body)) if (body[k] === null) delete body[k];
|
|
139
|
+
|
|
140
|
+
if (!args.confirm) {
|
|
141
|
+
return respond(NAME, ProfileUpdateV2Out, preview("PUT", PATH, { changes, ...(warnings.length > 0 ? { warnings } : {}) }));
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// 3. Send. `false` means WHOOP rejected the values and saved nothing.
|
|
145
|
+
const result = await client.put(PATH, body);
|
|
146
|
+
if (result === false) return fail("WHOOP refused these values (it answered false); nothing was saved.", { changes });
|
|
147
|
+
|
|
148
|
+
// 4. Fresh read-back (a 401 here after a birthday/country change is refreshed and retried by the client).
|
|
149
|
+
const after = parseProfileEdit(await client.get(EDIT, {}, { fresh: true }).catch(() => null));
|
|
150
|
+
const changed: Record<string, [Value, Value]> = {};
|
|
151
|
+
const mismatches: string[] = [];
|
|
152
|
+
for (const [k, [before, to]] of Object.entries(changes) as Array<[Field, [Value, Value]]>) {
|
|
153
|
+
const got = after ? (after[k] as Value) : to;
|
|
154
|
+
changed[k] = [before, got];
|
|
155
|
+
if (after && !same(got, to)) mismatches.push(`${k}: sent ${String(to)}, WHOOP shows ${String(got)}`);
|
|
156
|
+
}
|
|
157
|
+
if (!after) warnings.push("Couldn't read the profile back to verify.");
|
|
158
|
+
return respond(NAME, ProfileUpdateV2Out, {
|
|
159
|
+
updated: true,
|
|
160
|
+
no_change: false,
|
|
161
|
+
changed,
|
|
162
|
+
verified: after !== null && mismatches.length === 0,
|
|
163
|
+
mismatches,
|
|
164
|
+
warnings,
|
|
165
|
+
});
|
|
166
|
+
});
|
|
76
167
|
}
|
package/src/tools/v2/raw.ts
CHANGED
|
@@ -3,48 +3,101 @@ import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
|
3
3
|
import type { WhoopClient } from "../../whoop/client.js";
|
|
4
4
|
import { RawOut } from "../../schemas/escape.js";
|
|
5
5
|
import { preview } from "../../whoop/write_safety.js";
|
|
6
|
-
import {
|
|
6
|
+
import { defineTool, respond } from "../define.js";
|
|
7
|
+
import { WRITE_DESTRUCTIVE, openWorld } from "../annotations.js";
|
|
8
|
+
|
|
9
|
+
/** Smart-alarm goals WHOOP can read back. Others it accepts, then 500s on forever (SPEC.md §7). */
|
|
10
|
+
export const SAFE_ALARM_GOALS = [
|
|
11
|
+
"EXACT_TIME_PERFORM", "EXACT_TIME_PEAK", "EXACT_TIME_OPTIMIZE_SLEEP", "IN_THE_GREEN",
|
|
12
|
+
"SLEEP_HEALTH_PEAK", "SLEEP_HEALTH_PERFORM", "SLEEP_HEALTH_GET_BY",
|
|
13
|
+
] as const;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Writes whoop_raw refuses even with allow_write (D14). Same categories as the
|
|
17
|
+
* probe blocklist minus social (D9: social writes are allowed here, explicitly).
|
|
18
|
+
*/
|
|
19
|
+
const WRITE_DENYLIST: ReadonlyArray<[RegExp, string]> = [
|
|
20
|
+
[/^\/auth-service\//, "auth is handled by totem itself"],
|
|
21
|
+
[/(password|e-?mail|mfa|\/phone|verif|otp|logout|log-out|sign-?out|revoke|\/sessions?\b|deactivat|delete-account|account-deletion|close-account)/i, "could lock you out of your account"],
|
|
22
|
+
[/^\/users-service\/v\d+\/users\/?$/, "account deletion"],
|
|
23
|
+
[/^\/(commerce-service|order-service|rma-service|referral-service|membership-service|advanced-labs-service|growth-content-service|payment-service|checkout-service|billing-service)\//, "purchases, membership or orders"],
|
|
24
|
+
[/(consent|\/terms|agreement|clinical|research|access_care|access_product)/i, "consents and legal agreements"],
|
|
25
|
+
[/^\/(integrations-bff|integrations-service|social-service)\//, "third-party account connections"],
|
|
26
|
+
[/(strap|garment|pairing|firmware|\/device)/i, "the strap or device"],
|
|
27
|
+
[/^\/(messaging-service)\//, "sends SMS or email"],
|
|
28
|
+
[/^\/(sentry-proxy-service|metrics-service|mobile-metric-service|log-service|pip-metrics-service)\//, "telemetry"],
|
|
29
|
+
];
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* The path WHOOP will route, for matching against the denylist: query and
|
|
33
|
+
* fragment dropped, percent-decoded, duplicate slashes collapsed, lower-cased.
|
|
34
|
+
* Null when the text doesn't say where the request lands (still-encoded
|
|
35
|
+
* characters, "." or ".." segments, ";" path parameters, backslashes,
|
|
36
|
+
* whitespace or control characters) — every one of those let a denylisted
|
|
37
|
+
* endpoint through while the denylist matched the literal string.
|
|
38
|
+
*/
|
|
39
|
+
function routedPath(path: string): string | null {
|
|
40
|
+
let routed = path.split(/[?#]/)[0]!;
|
|
41
|
+
try {
|
|
42
|
+
routed = decodeURIComponent(routed);
|
|
43
|
+
} catch {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
if (/[%;\\\u0000- \u007f]/.test(routed)) return null;
|
|
47
|
+
routed = routed.replace(/\/{2,}/g, "/");
|
|
48
|
+
if (routed.split("/").some((segment) => segment === "." || segment === "..")) return null;
|
|
49
|
+
return routed.toLowerCase();
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function rawWriteRefusal(rawPath: string, body: unknown): string | null {
|
|
53
|
+
const path = routedPath(rawPath);
|
|
54
|
+
if (path === null) {
|
|
55
|
+
return `whoop_raw won't write to ${JSON.stringify(rawPath)}: write paths must be plain (no percent-encoding, "." or ".." segments, ";", backslashes or whitespace) so they can be checked. Put parameters in \`query\`.`;
|
|
56
|
+
}
|
|
57
|
+
for (const [re, why] of WRITE_DENYLIST) if (re.test(path)) return `whoop_raw won't write to ${rawPath}: ${why}.`;
|
|
58
|
+
if (path.startsWith("/smart-alarm-service/v1/smartalarm/preferences")) {
|
|
59
|
+
const goal = (body as { goal?: unknown } | null)?.goal;
|
|
60
|
+
if (goal !== undefined && !(SAFE_ALARM_GOALS as readonly unknown[]).includes(goal)) {
|
|
61
|
+
return `whoop_raw won't set Smart Alarm goal ${JSON.stringify(goal)}: WHOOP accepts some goals it can't read back, which breaks the alarm permanently. Allowed: ${SAFE_ALARM_GOALS.join(", ")}.`;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
7
66
|
|
|
8
67
|
export function registerRaw(server: McpServer, client: WhoopClient): void {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
"ESCAPE HATCH: call any Whoop endpoint directly — use only when no specific tool fits, and look up the exact path with whoop_endpoints first. Mutating methods (POST/PUT/DELETE) require confirm:true.",
|
|
68
|
+
defineTool(
|
|
69
|
+
server,
|
|
12
70
|
{
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
71
|
+
name: "whoop_raw",
|
|
72
|
+
description:
|
|
73
|
+
"Escape hatch: call any WHOOP endpoint when no tool fits (the whoop://catalog/endpoints resource lists verified paths). " +
|
|
74
|
+
"Writes need allow_write:true and confirm:true; some paths are refused outright (auth, account, purchases, consents, " +
|
|
75
|
+
"strap, telemetry). Social writes (follow, comment) are only available here.",
|
|
76
|
+
input: {
|
|
77
|
+
path: z.string().describe("e.g. /home-service/v1/home"),
|
|
78
|
+
method: z.enum(["GET", "POST", "PUT", "PATCH", "DELETE"]).default("GET"),
|
|
79
|
+
query: z.record(z.string(), z.union([z.string(), z.number(), z.boolean()])).optional(),
|
|
80
|
+
body: z.unknown().optional(),
|
|
81
|
+
allow_write: z.boolean().default(false),
|
|
82
|
+
confirm: z.boolean().default(false),
|
|
83
|
+
},
|
|
84
|
+
annotations: openWorld(WRITE_DESTRUCTIVE),
|
|
18
85
|
},
|
|
19
|
-
async ({ path, method, query, body, confirm }) => {
|
|
86
|
+
async ({ path, method, query, body, allow_write, confirm }) => {
|
|
20
87
|
const safePath = path.startsWith("/") ? path : `/${path}`;
|
|
21
|
-
const
|
|
22
|
-
if (
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
{ type: "text", text: jsonOut(preview(method, safePath, { query: query ?? {}, body })) },
|
|
26
|
-
],
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
let response: unknown;
|
|
30
|
-
switch (method) {
|
|
31
|
-
case "GET":
|
|
32
|
-
response = await client.get(safePath, query ?? {});
|
|
33
|
-
break;
|
|
34
|
-
case "POST":
|
|
35
|
-
response = await client.post(safePath, body, query ?? {});
|
|
36
|
-
break;
|
|
37
|
-
case "PUT":
|
|
38
|
-
response = await client.put(safePath, body, query ?? {});
|
|
39
|
-
break;
|
|
40
|
-
case "DELETE":
|
|
41
|
-
response = await client.delete(safePath, query ?? {});
|
|
42
|
-
break;
|
|
88
|
+
const q = query ?? {};
|
|
89
|
+
if (method === "GET") {
|
|
90
|
+
const response = await client.get(safePath, q);
|
|
91
|
+
return respond("whoop_raw", RawOut, { path: safePath, method, status: 200, response }, { compact: false });
|
|
43
92
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
return
|
|
93
|
+
if (!allow_write) throw new Error("whoop_raw writes need allow_write:true (and confirm:true). Prefer a specific whoop_* tool if one fits.");
|
|
94
|
+
const refusal = rawWriteRefusal(safePath, body);
|
|
95
|
+
if (refusal) throw new Error(refusal);
|
|
96
|
+
if (!confirm) return respond("whoop_raw", RawOut, preview(method, safePath, { query: q, body }));
|
|
97
|
+
// The client invalidates dependent cache tags itself (everything for unknown paths).
|
|
98
|
+
// The status is WHOOP's own (a delete usually answers 204 with no body), not an assumed 200.
|
|
99
|
+
const { status, body: response } = await client.write(method, safePath, body, q);
|
|
100
|
+
return respond("whoop_raw", RawOut, { path: safePath, method, status, response }, { compact: false });
|
|
48
101
|
},
|
|
49
102
|
);
|
|
50
103
|
}
|
package/src/tools/v2/recovery.ts
CHANGED
|
@@ -1,36 +1,55 @@
|
|
|
1
|
+
// whoop_recovery (v2): deep-dive recovery + today's health monitor, and the
|
|
2
|
+
// performance assessment merged in via include (D15).
|
|
1
3
|
import { z } from "zod";
|
|
2
4
|
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
5
|
import type { WhoopClient } from "../../whoop/client.js";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { WhoopProjectionError } from "../../whoop/errors.js";
|
|
7
|
-
import { jsonOut } from "../../whoop/json_out.js";
|
|
6
|
+
import { defineTool, respond } from "../define.js";
|
|
7
|
+
import { READ_ONLY } from "../annotations.js";
|
|
8
8
|
import { todayIso } from "../../lib/dates.js";
|
|
9
|
+
import { wallClockIso } from "../../lib/timezone.js";
|
|
10
|
+
import { RecoveryV2Out } from "../../schemas/v2/recovery.js";
|
|
11
|
+
import {
|
|
12
|
+
projectAssessment, projectHealthMonitor, projectRecoveryDeepDive, type RecoveryV2,
|
|
13
|
+
} from "../../projections/v2/recovery.js";
|
|
14
|
+
|
|
15
|
+
const NAME = "whoop_recovery";
|
|
16
|
+
|
|
17
|
+
/** The assessment endpoint wants a timestamp (a plain date 404s); UTC with ms works. */
|
|
18
|
+
export function assessmentTimestamp(date: string, isToday: boolean, now: Date = new Date()): string {
|
|
19
|
+
return isToday ? now.toISOString() : new Date(wallClockIso(date, 12, 0)).toISOString();
|
|
20
|
+
}
|
|
9
21
|
|
|
10
22
|
export function registerRecovery(server: McpServer, client: WhoopClient): void {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
+
defineTool(
|
|
24
|
+
server,
|
|
25
|
+
{
|
|
26
|
+
name: NAME,
|
|
27
|
+
description:
|
|
28
|
+
"Recovery for a cycle day (default today): score, state and contributors (HRV, RHR, respiratory rate, sleep performance) vs " +
|
|
29
|
+
"baseline. Today only: Health Monitor (SpO2, skin temperature as a °F deviation from baseline, RR, RHR, HRV). include assessment " +
|
|
30
|
+
"adds the weekly and monthly performance assessment.",
|
|
31
|
+
input: {
|
|
32
|
+
date: z.iso.date().optional(),
|
|
33
|
+
include: z.array(z.enum(["assessment"])).optional(),
|
|
34
|
+
},
|
|
35
|
+
annotations: READ_ONLY,
|
|
36
|
+
},
|
|
37
|
+
async ({ date, include }) => {
|
|
38
|
+
const today = todayIso();
|
|
39
|
+
const d = date ?? today;
|
|
40
|
+
const isToday = d === today;
|
|
41
|
+
const ts = assessmentTimestamp(d, isToday);
|
|
42
|
+
const withAssessment = include?.includes("assessment") ?? false;
|
|
43
|
+
const [deepDive, monitor, week, month] = await Promise.all([
|
|
23
44
|
client.get("/home-service/v1/deep-dive/recovery", { date: d }),
|
|
24
|
-
|
|
45
|
+
// The monitor has no date parameter: it is today's cycle only.
|
|
46
|
+
isToday ? client.get("/coaching-service/v1/health/bff/monitor").catch(() => null) : null,
|
|
47
|
+
withAssessment ? client.get(`/coaching-service/v1/performance-assessment/WEEK/data/${ts}`).catch(() => null) : null,
|
|
48
|
+
withAssessment ? client.get(`/coaching-service/v1/performance-assessment/MONTH/data/${ts}`).catch(() => null) : null,
|
|
25
49
|
]);
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
return { content: [{ type: "text", text: jsonOut(out) }] };
|
|
30
|
-
} catch (e) {
|
|
31
|
-
if (e instanceof z.ZodError) throw new WhoopProjectionError("whoop_recovery", e);
|
|
32
|
-
throw e;
|
|
33
|
-
}
|
|
50
|
+
const out: RecoveryV2 = { ...projectRecoveryDeepDive(deepDive, d), monitor: projectHealthMonitor(monitor) };
|
|
51
|
+
if (withAssessment) out.assessment = { week: projectAssessment(week), month: projectAssessment(month) };
|
|
52
|
+
return respond(NAME, RecoveryV2Out, out);
|
|
34
53
|
},
|
|
35
54
|
);
|
|
36
55
|
}
|
package/src/tools/v2/sleep.ts
CHANGED
|
@@ -1,28 +1,67 @@
|
|
|
1
|
+
// whoop_sleep (v2): replaces whoop_sleep and whoop_sleep_need, and covers the
|
|
2
|
+
// proposed sleep_details (any past sleep or nap by id). App-native only (D1).
|
|
1
3
|
import { z } from "zod";
|
|
2
4
|
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
5
|
import type { WhoopClient } from "../../whoop/client.js";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { WhoopProjectionError } from "../../whoop/errors.js";
|
|
7
|
-
import { jsonOut } from "../../whoop/json_out.js";
|
|
6
|
+
import { defineTool, respond } from "../define.js";
|
|
7
|
+
import { READ_ONLY } from "../annotations.js";
|
|
8
8
|
import { todayIso } from "../../lib/dates.js";
|
|
9
|
+
import { SleepV2Out } from "../../schemas/v2/sleep.js";
|
|
10
|
+
import { mainSleepId, projectSleepV2, type SleepInclude } from "../../projections/v2/sleep.js";
|
|
11
|
+
import { projectSleepNeedV2 } from "../../projections/v2/core_sleep_need.js";
|
|
12
|
+
import { activityRecordPath, recordFromActivity } from "../../lib/activity_records.js";
|
|
13
|
+
|
|
14
|
+
const NAME = "whoop_sleep";
|
|
15
|
+
const INCLUDES = ["hypnogram", "need", "naps"] as const;
|
|
9
16
|
|
|
10
17
|
export function registerSleep(server: McpServer, client: WhoopClient): void {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
18
|
+
defineTool(
|
|
19
|
+
server,
|
|
20
|
+
{
|
|
21
|
+
name: NAME,
|
|
22
|
+
description:
|
|
23
|
+
"Sleep for a cycle day (default today = last night's main sleep) or one sleep or nap by activity_id: window, minutes asleep and " +
|
|
24
|
+
"in bed, efficiency, stages, disturbances, HR and performance, plus the day's naps (with ids) and tonight's sleep need (today " +
|
|
25
|
+
"only).",
|
|
26
|
+
input: {
|
|
27
|
+
date: z.iso.date().optional(),
|
|
28
|
+
activity_id: z.string().uuid().optional(),
|
|
29
|
+
include: z.array(z.enum(INCLUDES)).optional().describe("Default naps, need"),
|
|
30
|
+
},
|
|
31
|
+
annotations: READ_ONLY,
|
|
32
|
+
},
|
|
33
|
+
async ({ date, activity_id, include }) => {
|
|
34
|
+
const inc = new Set<SleepInclude>(include ?? ["naps", "need"]);
|
|
35
|
+
const baseline = client.get("/sleep-service/v1/heart-rate/baseline").catch(() => null);
|
|
36
|
+
if (activity_id) {
|
|
37
|
+
// One sleep or nap by id: no date context, so no naps list or sleep need.
|
|
38
|
+
inc.delete("naps");
|
|
39
|
+
inc.delete("need");
|
|
40
|
+
// WHOOP's sleep-details answers 200 for ANY activity id: a workout comes back as an
|
|
41
|
+
// empty "SLEEP" screen. The activity record says what the id really is.
|
|
42
|
+
const [details, record] = await Promise.all([
|
|
43
|
+
client.get(`/core-details-bff/v2/sleep-details/${activity_id}`),
|
|
44
|
+
client.get(activityRecordPath(activity_id)).then(recordFromActivity).catch(() => null),
|
|
45
|
+
]);
|
|
46
|
+
if (record?.score_type && record.score_type !== "SLEEP") {
|
|
47
|
+
throw new Error(`Activity ${activity_id} is a ${record.type ?? record.score_type} activity, not a sleep or nap. Use whoop_workouts for it.`);
|
|
48
|
+
}
|
|
49
|
+
return respond(NAME, SleepV2Out, projectSleepV2({ date: null, activityId: activity_id, include: inc, details, baseline: await baseline }));
|
|
25
50
|
}
|
|
51
|
+
const today = todayIso();
|
|
52
|
+
const d = date ?? today;
|
|
53
|
+
const [home, lastNight, need] = await Promise.all([
|
|
54
|
+
client.get("/home-service/v1/home", { date: d }),
|
|
55
|
+
client.get("/home-service/v1/deep-dive/sleep/last-night", { date: d }).catch(() => null),
|
|
56
|
+
// sleepneed is tonight's plan and 500s when Smart Alarm preferences are broken: degrade to null.
|
|
57
|
+
inc.has("need") && d === today
|
|
58
|
+
? client.get("/coaching-service/v2/sleepneed").then(projectSleepNeedV2).catch(() => null)
|
|
59
|
+
: null,
|
|
60
|
+
]);
|
|
61
|
+
const id = mainSleepId(lastNight, home);
|
|
62
|
+
// A pending sleep's details 400; the projection falls back to the tile/last-night window.
|
|
63
|
+
const details = id ? await client.get(`/core-details-bff/v2/sleep-details/${id}`).catch(() => null) : null;
|
|
64
|
+
return respond(NAME, SleepV2Out, projectSleepV2({ date: d, include: inc, details, lastNight, home, need, baseline: await baseline }));
|
|
26
65
|
},
|
|
27
66
|
);
|
|
28
67
|
}
|