@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,38 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
|
+
import type { WhoopClient } from "../../whoop/client.js";
|
|
4
|
+
import { defineTool, respond } from "../define.js";
|
|
5
|
+
import { READ_ONLY } from "../annotations.js";
|
|
6
|
+
import { WeeklyPlanOut, type WeeklyPlanOutT } from "../../schemas/weekly_plan.js";
|
|
7
|
+
import { projectWeeklyPlan } from "../../projections/weekly_plan.js";
|
|
8
|
+
import { todayIso } from "../../lib/dates.js";
|
|
9
|
+
|
|
10
|
+
export const PLAN_V1 = "/progression-service/v1/weekly-plan";
|
|
11
|
+
export const PLAN_V2 = "/progression-service/v2/weekly-plan";
|
|
12
|
+
|
|
13
|
+
/** v1 weekly plan + v2 home tile for the week containing `date`; one may fail, not both. */
|
|
14
|
+
export async function readWeeklyPlan(client: WhoopClient, date: string, fresh = false): Promise<WeeklyPlanOutT> {
|
|
15
|
+
const [v1, tile] = await Promise.allSettled([
|
|
16
|
+
client.get(PLAN_V1, { date }, { fresh }),
|
|
17
|
+
client.get(`${PLAN_V2}/home-tile/${date}`, {}, { fresh }),
|
|
18
|
+
]);
|
|
19
|
+
if (v1.status === "rejected" && tile.status === "rejected") throw v1.reason;
|
|
20
|
+
return projectWeeklyPlan(
|
|
21
|
+
v1.status === "fulfilled" ? v1.value : null,
|
|
22
|
+
tile.status === "fulfilled" ? tile.value : null,
|
|
23
|
+
date,
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function registerWeeklyPlan(server: McpServer, client: WhoopClient): void {
|
|
28
|
+
defineTool(server, {
|
|
29
|
+
name: "whoop_weekly_plan",
|
|
30
|
+
description:
|
|
31
|
+
"The Weekly Plan for the Monday–Sunday week containing a date (default today): plan name, days left, % accomplished and each " +
|
|
32
|
+
"goal's target (steps/day or minutes/week), days met and running total.",
|
|
33
|
+
input: {
|
|
34
|
+
date: z.iso.date().optional(),
|
|
35
|
+
},
|
|
36
|
+
annotations: READ_ONLY,
|
|
37
|
+
}, async ({ date }) => respond("whoop_weekly_plan", WeeklyPlanOut, await readWeeklyPlan(client, date ?? todayIso())));
|
|
38
|
+
}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
|
+
import type { WhoopClient } from "../../whoop/client.js";
|
|
4
|
+
import { defineTool, respond } from "../define.js";
|
|
5
|
+
import { WRITE_DESTRUCTIVE, idempotent } from "../annotations.js";
|
|
6
|
+
import { PLAN_GOAL_TYPES, WeeklyPlanSetOut, type WeeklyPlanOutT } from "../../schemas/weekly_plan.js";
|
|
7
|
+
import { previewWith, toolError, writeRejected } from "../../lib/health_plans_write.js";
|
|
8
|
+
import { get } from "../../whoop/bff.js";
|
|
9
|
+
import { WhoopApiError } from "../../whoop/errors.js";
|
|
10
|
+
import { todayIso } from "../../lib/dates.js";
|
|
11
|
+
import { PLAN_V2, readWeeklyPlan } from "./weekly_plan.js";
|
|
12
|
+
|
|
13
|
+
type GoalType = typeof PLAN_GOAL_TYPES[number];
|
|
14
|
+
interface Range { min: number; max: number; step: number }
|
|
15
|
+
|
|
16
|
+
// Fallbacks if the setup screen omits its slider (live: STEPS 100–10000 by 100,
|
|
17
|
+
// STRENGTH_TRAINING_TIME 10–720 minutes by 15).
|
|
18
|
+
const FALLBACK: Record<GoalType, Range> = {
|
|
19
|
+
STEPS: { min: 100, max: 50_000, step: 100 },
|
|
20
|
+
STRENGTH_TRAINING_TIME: { min: 10, max: 720, step: 15 },
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/** The slider WHOOP's setup screen offers for a goal type (usable range + increment). */
|
|
24
|
+
export function sliderRange(setup: unknown, type: GoalType): Range {
|
|
25
|
+
const screens = get(setup, "screens");
|
|
26
|
+
const screen = Array.isArray(screens) ? screens.find((s) => get(s, "goal") === type) : undefined;
|
|
27
|
+
const slider = get(screen, "slider_content");
|
|
28
|
+
const min = get(slider, "usable_range", "lower_endpoint");
|
|
29
|
+
const max = get(slider, "usable_range", "upper_endpoint");
|
|
30
|
+
const step = get(slider, "increment");
|
|
31
|
+
return typeof min === "number" && typeof max === "number" && typeof step === "number" && step > 0
|
|
32
|
+
? { min, max, step }
|
|
33
|
+
: FALLBACK[type];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Within the slider, on its increment (the slider minimum itself is also allowed: 10 min). */
|
|
37
|
+
export function targetError(type: GoalType, target: number, r: Range): string | null {
|
|
38
|
+
const unit = type === "STEPS" ? "steps/day" : "minutes/week";
|
|
39
|
+
if (target < r.min || target > r.max || (target % r.step !== 0 && target !== r.min)) {
|
|
40
|
+
return `${type} target must be ${r.min}–${r.max} ${unit} in steps of ${r.step} (WHOOP's slider); got ${target}.`;
|
|
41
|
+
}
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function registerWeeklyPlanSet(server: McpServer, client: WhoopClient): void {
|
|
46
|
+
defineTool(server, {
|
|
47
|
+
name: "whoop_weekly_plan_set",
|
|
48
|
+
description:
|
|
49
|
+
"Change Weekly Plan goals. set_goal adds or edits a goal (starting a Custom plan if there is none): STEPS target in steps/day, " +
|
|
50
|
+
"STRENGTH_TRAINING_TIME in minutes/week, within WHOOP's slider. remove_goal drops one, and removing the last ends the plan. " +
|
|
51
|
+
"end_plan removes every goal. Previews unless confirm:true.",
|
|
52
|
+
input: {
|
|
53
|
+
action: z.enum(["set_goal", "remove_goal", "end_plan"]),
|
|
54
|
+
type: z.enum(PLAN_GOAL_TYPES).optional(),
|
|
55
|
+
target: z.number().int().positive().optional(),
|
|
56
|
+
confirm: z.boolean().default(false),
|
|
57
|
+
},
|
|
58
|
+
annotations: idempotent(WRITE_DESTRUCTIVE),
|
|
59
|
+
}, async ({ action, type, target, confirm }) => {
|
|
60
|
+
if (action === "set_goal" && (!type || target === undefined)) return toolError("set_goal needs type and target.");
|
|
61
|
+
if (action === "remove_goal" && !type) return toolError("remove_goal needs type.");
|
|
62
|
+
if (action === "end_plan" && (type || target !== undefined)) return toolError("end_plan takes no type or target.");
|
|
63
|
+
if (action === "remove_goal" && target !== undefined) return toolError("remove_goal takes no target.");
|
|
64
|
+
|
|
65
|
+
// Fresh pre-reads: the current plan, and the plan id (+ slider) from setup.
|
|
66
|
+
const date = todayIso();
|
|
67
|
+
const [current, setup] = await Promise.all([
|
|
68
|
+
readWeeklyPlan(client, date, true),
|
|
69
|
+
client.get(`${PLAN_V2}/setup`, type && action === "set_goal" ? { screens: type } : {}, { fresh: true }),
|
|
70
|
+
]);
|
|
71
|
+
const planId = get(setup, "plan_id");
|
|
72
|
+
if (typeof planId !== "string" || !planId) return toolError("WHOOP's plan setup returned no plan_id; try again or use the app.");
|
|
73
|
+
if (current.plan_id && current.plan_id !== planId) {
|
|
74
|
+
return toolError(`WHOOP reports two plan ids (current ${current.plan_id}, setup ${planId}); refusing to write to the wrong plan. Edit the plan in the app.`);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const warnings: string[] = [];
|
|
78
|
+
const goalTypes = current.goals.map((g) => g.type);
|
|
79
|
+
let writes: Array<{ method: "PUT" | "DELETE"; path: string; body?: unknown }>;
|
|
80
|
+
if (action === "set_goal") {
|
|
81
|
+
const err = targetError(type!, target!, sliderRange(setup, type!));
|
|
82
|
+
if (err) return toolError(err);
|
|
83
|
+
if (!current.has_plan) warnings.push("There is no plan this week, so this starts a Custom weekly plan.");
|
|
84
|
+
writes = [{ method: "PUT", path: `${PLAN_V2}/${planId}/goal/target`, body: { type, target } }];
|
|
85
|
+
} else if (action === "remove_goal") {
|
|
86
|
+
if (!goalTypes.includes(type!)) return toolError(`${type} isn't in the current plan (goals: ${goalTypes.join(", ") || "none"}).`);
|
|
87
|
+
if (goalTypes.length === 1) warnings.push("This is the plan's last goal, so removing it ends the plan.");
|
|
88
|
+
writes = [{ method: "DELETE", path: `${PLAN_V2}/${planId}/goal/target/${type}` }];
|
|
89
|
+
} else {
|
|
90
|
+
if (!current.has_plan || !goalTypes.length) return toolError("There is no active weekly plan to end.");
|
|
91
|
+
const foreign = goalTypes.filter((g) => !(PLAN_GOAL_TYPES as readonly string[]).includes(g));
|
|
92
|
+
if (foreign.length) {
|
|
93
|
+
return toolError(`The plan has goals totem doesn't manage (${foreign.join(", ")}); end it in the WHOOP app.`);
|
|
94
|
+
}
|
|
95
|
+
writes = goalTypes.map((g) => ({ method: "DELETE" as const, path: `${PLAN_V2}/${planId}/goal/target/${g}` }));
|
|
96
|
+
warnings.push("Ending the plan removes every goal.");
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (!confirm) {
|
|
100
|
+
const body = writes.length === 1 ? writes[0]!.body ?? null : { requests: writes.map((w) => `${w.method} ${w.path}`) };
|
|
101
|
+
return respond("whoop_weekly_plan_set", WeeklyPlanSetOut, previewWith(writes[0]!.method, writes[0]!.path, body, warnings, current));
|
|
102
|
+
}
|
|
103
|
+
for (const w of writes) {
|
|
104
|
+
try {
|
|
105
|
+
if (w.method === "PUT") await client.put(w.path, w.body);
|
|
106
|
+
else await client.delete(w.path);
|
|
107
|
+
} catch (error) {
|
|
108
|
+
if (error instanceof WhoopApiError) {
|
|
109
|
+
// end_plan is several DELETEs: say which ones already went through.
|
|
110
|
+
const done = writes.slice(0, writes.indexOf(w)).map((x) => `${x.method} ${x.path}`);
|
|
111
|
+
return writeRejected("weekly plan change", w.path, error, done.length ? `Already applied before this failed: ${done.join("; ")}.` : undefined);
|
|
112
|
+
}
|
|
113
|
+
throw error;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const after: WeeklyPlanOutT = await readWeeklyPlan(client, date, true);
|
|
118
|
+
const goal = after.goals.find((g) => g.type === type);
|
|
119
|
+
// set_goal is verified only by the target itself: a goal whose target can't be read proves nothing.
|
|
120
|
+
const verified = action === "set_goal"
|
|
121
|
+
? goal?.target === target
|
|
122
|
+
: action === "remove_goal"
|
|
123
|
+
? !goal
|
|
124
|
+
: !after.has_plan || after.goals.length === 0;
|
|
125
|
+
if (!verified) {
|
|
126
|
+
warnings.push(action === "set_goal" && goal && goal.target === null
|
|
127
|
+
? "The goal is in the plan but its target couldn't be read back; check whoop_weekly_plan."
|
|
128
|
+
: "The plan read back doesn't show the change yet; check whoop_weekly_plan.");
|
|
129
|
+
}
|
|
130
|
+
return respond("whoop_weekly_plan_set", WeeklyPlanSetOut, { action, verified, plan: after, warnings });
|
|
131
|
+
});
|
|
132
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
|
+
import type { WhoopClient } from "../../whoop/client.js";
|
|
4
|
+
import { defineTool, respond } from "../define.js";
|
|
5
|
+
import { READ_ONLY } from "../annotations.js";
|
|
6
|
+
import { WeightOut } from "../../schemas/weight.js";
|
|
7
|
+
import { projectWeightReadings, WEIGHT_COLUMNS, weightRows } from "../../projections/weight_readings.js";
|
|
8
|
+
import { WEIGHT_READINGS_PATH } from "../../lib/weight_readings.js";
|
|
9
|
+
import { toolError } from "../../lib/health_plans_write.js";
|
|
10
|
+
|
|
11
|
+
/** One WHOOP page of readings: the first, or the one after `token` (an opaque next_token). */
|
|
12
|
+
export function fetchWeightPage(client: WhoopClient, token?: string, fresh = false): Promise<unknown> {
|
|
13
|
+
return token
|
|
14
|
+
? client.get(`${WEIGHT_READINGS_PATH}/paginated`, { next_token: token }, { fresh })
|
|
15
|
+
: client.get(WEIGHT_READINGS_PATH, {}, { fresh });
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// Totem's cursor = WHOOP's page token (verbatim) + an offset into that page, since
|
|
19
|
+
// a WHOOP page (~100 readings) is far more than a default answer needs.
|
|
20
|
+
interface Cursor { t?: string; o: number }
|
|
21
|
+
export function encodeCursor(c: Cursor): string {
|
|
22
|
+
return Buffer.from(JSON.stringify(c)).toString("base64url");
|
|
23
|
+
}
|
|
24
|
+
export function decodeCursor(s: string): Cursor | null {
|
|
25
|
+
try {
|
|
26
|
+
const c = JSON.parse(Buffer.from(s, "base64url").toString("utf8")) as Cursor;
|
|
27
|
+
if (typeof c.o !== "number" || c.o < 0 || (c.t !== undefined && typeof c.t !== "string")) return null;
|
|
28
|
+
return c;
|
|
29
|
+
} catch {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function registerWeight(server: McpServer, client: WhoopClient): void {
|
|
35
|
+
defineTool(server, {
|
|
36
|
+
name: "whoop_weight",
|
|
37
|
+
description:
|
|
38
|
+
"Weight and body-composition readings, newest first, in kg (display_unit is the account's unit). The newest reading is the " +
|
|
39
|
+
"profile weight. Ids feed whoop_weight_log.",
|
|
40
|
+
input: {
|
|
41
|
+
limit: z.number().int().min(1).max(100).default(10),
|
|
42
|
+
cursor: z.string().min(1).optional(),
|
|
43
|
+
},
|
|
44
|
+
annotations: READ_ONLY,
|
|
45
|
+
}, async ({ limit, cursor }) => {
|
|
46
|
+
const pos = cursor ? decodeCursor(cursor) : { o: 0 };
|
|
47
|
+
if (!pos) return toolError("Invalid cursor; pass next_cursor exactly as returned.");
|
|
48
|
+
const n = limit ?? 10;
|
|
49
|
+
const page = projectWeightReadings(await fetchWeightPage(client, pos.t));
|
|
50
|
+
const rows = page.readings.slice(pos.o, pos.o + n);
|
|
51
|
+
const next = pos.o + n < page.readings.length
|
|
52
|
+
? encodeCursor({ ...(pos.t ? { t: pos.t } : {}), o: pos.o + n })
|
|
53
|
+
: page.next_token ? encodeCursor({ t: page.next_token, o: 0 }) : null;
|
|
54
|
+
return respond("whoop_weight", WeightOut, {
|
|
55
|
+
display_unit: page.display_unit,
|
|
56
|
+
columns: [...WEIGHT_COLUMNS],
|
|
57
|
+
rows: weightRows(rows),
|
|
58
|
+
next_cursor: next,
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
}
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
|
+
import type { WhoopClient } from "../../whoop/client.js";
|
|
4
|
+
import { defineTool, respond } from "../define.js";
|
|
5
|
+
import { WRITE_DESTRUCTIVE } from "../annotations.js";
|
|
6
|
+
import { WeightLogOut, type WeightReadingT } from "../../schemas/weight.js";
|
|
7
|
+
import { projectWeightReadings } from "../../projections/weight_readings.js";
|
|
8
|
+
import { buildMeasurementBody, round, WEIGHT_READINGS_PATH, type MeasurementBody } from "../../lib/weight_readings.js";
|
|
9
|
+
import { previewWith, toolError, writeRejected } from "../../lib/health_plans_write.js";
|
|
10
|
+
import { toKg } from "../../whoop/units.js";
|
|
11
|
+
import { WhoopApiError } from "../../whoop/errors.js";
|
|
12
|
+
import { assertNotFuture, isoDay } from "../../lib/dates.js";
|
|
13
|
+
import { toLocalIso } from "../../lib/timezone.js";
|
|
14
|
+
import { fetchWeightPage } from "./weight.js";
|
|
15
|
+
import { instantInput, toInstantOpt } from "../../lib/instant.js";
|
|
16
|
+
|
|
17
|
+
const MAX_PAGES = 5;
|
|
18
|
+
|
|
19
|
+
interface Loaded {
|
|
20
|
+
readings: WeightReadingT[];
|
|
21
|
+
target: WeightReadingT | null;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** Fresh readings, following next_cursor (up to MAX_PAGES) until `match` hits. */
|
|
25
|
+
export async function loadReadings(
|
|
26
|
+
client: WhoopClient,
|
|
27
|
+
match?: (r: WeightReadingT) => boolean,
|
|
28
|
+
): Promise<Loaded> {
|
|
29
|
+
const readings: WeightReadingT[] = [];
|
|
30
|
+
let cursor: string | undefined;
|
|
31
|
+
for (let page = 0; page < MAX_PAGES; page++) {
|
|
32
|
+
const out = projectWeightReadings(await fetchWeightPage(client, cursor, true));
|
|
33
|
+
readings.push(...out.readings);
|
|
34
|
+
const target = match ? out.readings.find(match) ?? null : null;
|
|
35
|
+
if (target || !match || !out.next_token) return { readings, target };
|
|
36
|
+
cursor = out.next_token;
|
|
37
|
+
}
|
|
38
|
+
return { readings, target: null };
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async function profileWeightKg(client: WhoopClient): Promise<number | null> {
|
|
42
|
+
try {
|
|
43
|
+
const boot = await client.get<{ profile?: { weight?: unknown } }>("/users-service/v2/bootstrap", {}, { fresh: true });
|
|
44
|
+
const w = boot?.profile?.weight;
|
|
45
|
+
return typeof w === "number" ? round(w, 2) : null;
|
|
46
|
+
} catch {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const row = (r: WeightReadingT) => ({ at: r.timestamp, kg: r.weight_kg, fat_pct: r.body_fat_pct, lean_kg: r.lean_kg });
|
|
52
|
+
|
|
53
|
+
const sameInstant = (a: string, b: string): boolean => Math.abs(Date.parse(a) - Date.parse(b)) < 1000;
|
|
54
|
+
|
|
55
|
+
function matches(r: WeightReadingT, body: MeasurementBody, tsIso: string): boolean {
|
|
56
|
+
const fat = body.body_fat_percent === null ? null : round(body.body_fat_percent * 100, 1);
|
|
57
|
+
return sameInstant(r.timestamp, tsIso)
|
|
58
|
+
&& Math.abs(r.weight_kg - body.weight_kg) < 0.01
|
|
59
|
+
&& (fat === null ? r.body_fat_pct === null : r.body_fat_pct !== null && Math.abs(r.body_fat_pct - fat) < 0.15)
|
|
60
|
+
&& (body.lean_body_mass_kg === null ? r.lean_kg === null : r.lean_kg !== null && Math.abs(r.lean_kg - body.lean_body_mass_kg) < 0.01);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function registerWeightLog(server: McpServer, client: WhoopClient): void {
|
|
64
|
+
defineTool(server, {
|
|
65
|
+
name: "whoop_weight_log",
|
|
66
|
+
description:
|
|
67
|
+
"Add, edit or delete a weight or body-composition reading. weight and lean_mass need unit. add ALWAYS creates a new reading, even " +
|
|
68
|
+
"on a day that has one; to replace, edit by reading_id (from whoop_weight). The latest reading becomes the profile weight, and " +
|
|
69
|
+
"deleting a reading never reverts it. No future times. Previews unless confirm:true.",
|
|
70
|
+
input: {
|
|
71
|
+
action: z.enum(["add", "edit", "delete"]),
|
|
72
|
+
reading_id: z.string().min(1).optional().describe("For edit and delete"),
|
|
73
|
+
weight: z.number().positive().optional().describe("Required for add"),
|
|
74
|
+
unit: z.enum(["kg", "lb"]).optional(),
|
|
75
|
+
body_fat_pct: z.number().gt(0).lt(100).nullable().optional().describe("Percent, e.g. 18.5; on edit null clears body composition"),
|
|
76
|
+
lean_mass: z.number().positive().optional(),
|
|
77
|
+
at: instantInput().optional().describe("Default now; edit keeps it"),
|
|
78
|
+
confirm: z.boolean().default(false),
|
|
79
|
+
},
|
|
80
|
+
annotations: WRITE_DESTRUCTIVE,
|
|
81
|
+
}, async ({ action, reading_id, weight, unit, body_fat_pct, lean_mass, at: atIn, confirm }) => {
|
|
82
|
+
const at = toInstantOpt(atIn, "at");
|
|
83
|
+
if (action === "add" && weight === undefined) return toolError("action:add needs weight (and unit).");
|
|
84
|
+
if (action === "add" && reading_id) return toolError("action:add creates a new reading; to change an existing one use action:edit with reading_id.");
|
|
85
|
+
if (action !== "add" && !reading_id) return toolError(`action:${action} needs reading_id (from whoop_weight).`);
|
|
86
|
+
if (action === "delete" && (weight !== undefined || body_fat_pct !== undefined || lean_mass !== undefined || at !== undefined)) {
|
|
87
|
+
return toolError("action:delete takes only reading_id.");
|
|
88
|
+
}
|
|
89
|
+
if ((weight !== undefined || lean_mass !== undefined) && !unit) {
|
|
90
|
+
return toolError("Say which unit weight/lean_mass are in: unit \"kg\" or \"lb\". (WHOOP stores readings in kg.)");
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// Fresh pre-read: the target reading (edit/delete), same-day readings, and the latest timestamp.
|
|
94
|
+
const { readings, target } = await loadReadings(client, reading_id ? (r) => r.id === reading_id : undefined);
|
|
95
|
+
if (action !== "add" && !target) {
|
|
96
|
+
return toolError(`No reading with id ${reading_id} in your recent readings (searched ${MAX_PAGES} pages). WHOOP answers 204 to any delete, so totem won't send one it can't verify.`);
|
|
97
|
+
}
|
|
98
|
+
if (action === "edit" && target && !target.editable) {
|
|
99
|
+
return toolError(`Reading ${target.id} comes from ${target.source ?? "an integration"} and isn't editable in WHOOP; it can only be deleted.`);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const warnings: string[] = [];
|
|
103
|
+
const others = readings.filter((r) => r.id !== reading_id);
|
|
104
|
+
const latestOther = others[0] ?? null;
|
|
105
|
+
|
|
106
|
+
if (action === "delete") {
|
|
107
|
+
const path = `${WEIGHT_READINGS_PATH}/${encodeURIComponent(target!.id)}`;
|
|
108
|
+
warnings.push("Deleting a reading never reverts the profile weight. To change it back, add a reading at the right weight with a later time than every other reading.");
|
|
109
|
+
if (!confirm) return respond("whoop_weight_log", WeightLogOut, previewWith("DELETE", path, { reading_id: target!.id }, warnings, row(target!)));
|
|
110
|
+
try {
|
|
111
|
+
await client.delete(path);
|
|
112
|
+
} catch (error) {
|
|
113
|
+
if (error instanceof WhoopApiError) return writeRejected("deletion", path, error);
|
|
114
|
+
throw error;
|
|
115
|
+
}
|
|
116
|
+
const after = await loadReadings(client, (r) => r.id === target!.id);
|
|
117
|
+
return respond("whoop_weight_log", WeightLogOut, {
|
|
118
|
+
action, id: target!.id, verified: after.target === null, reading: null,
|
|
119
|
+
profile_kg: await profileWeightKg(client), warnings,
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// add / edit: build the full body (PUT is a full replace, so edit merges onto the current reading).
|
|
124
|
+
const tsIso = at ?? (action === "edit" ? target!.timestamp : new Date().toISOString());
|
|
125
|
+
try {
|
|
126
|
+
assertNotFuture(tsIso, "reading time");
|
|
127
|
+
} catch {
|
|
128
|
+
// assertNotFuture's own reason (an undeletable empty day) is about activities and sleeps.
|
|
129
|
+
return toolError(`The reading time ${tsIso} is in the future. A weight reading is dated when it was taken.`);
|
|
130
|
+
}
|
|
131
|
+
let fatPct: number | undefined;
|
|
132
|
+
let leanKg: number | undefined;
|
|
133
|
+
// An edit that changes neither weight nor body composition (a new time only) re-sends the
|
|
134
|
+
// stored values exactly: the PUT replaces everything, and WHOOP never ties lean to weight.
|
|
135
|
+
const verbatim = action === "edit" && weight === undefined && body_fat_pct === undefined && lean_mass === undefined;
|
|
136
|
+
if (body_fat_pct !== undefined || lean_mass !== undefined) {
|
|
137
|
+
fatPct = body_fat_pct ?? undefined;
|
|
138
|
+
leanKg = lean_mass !== undefined ? toKg(lean_mass, unit!) : undefined;
|
|
139
|
+
} else if (action === "edit" && target && !verbatim) {
|
|
140
|
+
// A new weight keeps the stored body fat (at its stored precision); lean follows the new weight.
|
|
141
|
+
if (target.fat_fraction !== null) fatPct = target.fat_fraction * 100;
|
|
142
|
+
else if (target.lean_kg !== null) leanKg = target.lean_kg;
|
|
143
|
+
}
|
|
144
|
+
let body: MeasurementBody;
|
|
145
|
+
try {
|
|
146
|
+
body = buildMeasurementBody({
|
|
147
|
+
// The app sends local wall-clock time with its offset; toLocalIso leaves offset input as given.
|
|
148
|
+
timestamp: toLocalIso(tsIso),
|
|
149
|
+
weight_kg: weight !== undefined ? toKg(weight, unit!) : target!.weight_kg,
|
|
150
|
+
body_fat_percent: fatPct,
|
|
151
|
+
lean_body_mass_kg: leanKg,
|
|
152
|
+
});
|
|
153
|
+
if (verbatim) body = { ...body, body_fat_percent: target!.fat_fraction, lean_body_mass_kg: target!.lean_kg };
|
|
154
|
+
} catch (e) {
|
|
155
|
+
return toolError((e as Error).message);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const day = isoDay(new Date(tsIso));
|
|
159
|
+
const sameDay = others.filter((r) => isoDay(new Date(r.timestamp)) === day);
|
|
160
|
+
if (action === "add" && sameDay.length) {
|
|
161
|
+
warnings.push(`${day} already has ${sameDay.length} reading(s) (${sameDay.map((r) => r.id).join(", ")}). add creates another one; to replace, use action:edit with that reading_id.`);
|
|
162
|
+
}
|
|
163
|
+
if (!latestOther || Date.parse(tsIso) >= Date.parse(latestOther.timestamp)) {
|
|
164
|
+
warnings.push(`This will be your latest reading, so WHOOP sets your profile weight to ${body.weight_kg} kg (deleting it later won't revert that).`);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const path = action === "edit" ? `${WEIGHT_READINGS_PATH}/${encodeURIComponent(target!.id)}` : WEIGHT_READINGS_PATH;
|
|
168
|
+
const method = action === "edit" ? "PUT" : "POST";
|
|
169
|
+
if (!confirm) return respond("whoop_weight_log", WeightLogOut, previewWith(method, path, body, warnings, target ? row(target) : undefined));
|
|
170
|
+
|
|
171
|
+
try {
|
|
172
|
+
if (action === "edit") await client.put(path, body);
|
|
173
|
+
else await client.post(path, body);
|
|
174
|
+
} catch (error) {
|
|
175
|
+
if (error instanceof WhoopApiError) return writeRejected(action === "edit" ? "edit" : "reading", path, error);
|
|
176
|
+
throw error;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// Read back: POST returns 204 with no id, so find the new reading by time + values.
|
|
180
|
+
const before = new Set(readings.map((r) => r.id));
|
|
181
|
+
const after = await loadReadings(client, action === "edit"
|
|
182
|
+
? (r) => r.id === target!.id
|
|
183
|
+
: (r) => !before.has(r.id) && matches(r, body, tsIso));
|
|
184
|
+
const reading = after.target;
|
|
185
|
+
const verified = reading !== null && matches(reading, body, tsIso);
|
|
186
|
+
if (!verified) warnings.push(reading ? "WHOOP stored different values than were sent; see reading." : "The reading didn't show up when re-listed.");
|
|
187
|
+
return respond("whoop_weight_log", WeightLogOut, {
|
|
188
|
+
action, id: reading?.id ?? reading_id ?? null, verified,
|
|
189
|
+
reading: reading ? row(reading) : null,
|
|
190
|
+
profile_kg: await profileWeightKg(client), warnings,
|
|
191
|
+
});
|
|
192
|
+
});
|
|
193
|
+
}
|
package/src/tools/v2/workouts.ts
CHANGED
|
@@ -1,37 +1,167 @@
|
|
|
1
|
+
// whoop_workouts: replaces v1 whoop_workouts + whoop_workout.
|
|
2
|
+
//
|
|
3
|
+
// List (SPEC.md D1): GET home?date= per cycle day, pruned by calendar/overview,
|
|
4
|
+
// ≤31 days, 3 at a time. Lists every activity WHOOP shows in the app, pending and
|
|
5
|
+
// unscored included. Detail: GET cd/v1/cardio-details, plus cd/v2/recovery-details
|
|
6
|
+
// for RECOVERY activities.
|
|
7
|
+
//
|
|
8
|
+
// Opt-in fallback: with WHOOP_DEV_V2_LISTS=1 in the server environment, ranges
|
|
9
|
+
// longer than 31 days (up to 366) come from GET /developer/v2/activity/workout
|
|
10
|
+
// instead. That list holds scored workouts only (pending/incomplete ones are
|
|
11
|
+
// missing) and the app never calls it, so it is off by default.
|
|
1
12
|
import { z } from "zod";
|
|
2
13
|
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
14
|
import type { WhoopClient } from "../../whoop/client.js";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
15
|
+
import { defineTool, respond } from "../define.js";
|
|
16
|
+
import { READ_ONLY } from "../annotations.js";
|
|
17
|
+
import { WhoopApiError } from "../../whoop/errors.js";
|
|
18
|
+
import { ActivityDetailOut, WorkoutsListOut, type ActivityListItemT } from "../../schemas/activities.js";
|
|
19
|
+
import { projectActivityDetail, projectDeveloperWorkout, projectTile, workoutRows } from "../../projections/activities.js";
|
|
20
|
+
import { daySpan, listTiles } from "../../lib/activity_list.js";
|
|
21
|
+
import { CARDIO_DETAILS_V1, RECOVERY_DETAILS_V2, activityRecordPath, badActivityIdError, recordFromActivity } from "../../lib/activity_records.js";
|
|
22
|
+
import { typeForInternalName } from "../../lib/activity_types.js";
|
|
23
|
+
import { errorResult } from "../../lib/activity_results.js";
|
|
24
|
+
import { todayIso } from "../../lib/dates.js";
|
|
25
|
+
import { wallClockIso } from "../../lib/timezone.js";
|
|
26
|
+
import { get, str } from "../../whoop/bff.js";
|
|
27
|
+
|
|
28
|
+
const MAX_APP_DAYS = 31;
|
|
29
|
+
const MAX_DEV_DAYS = 366;
|
|
30
|
+
const DEV_PATH = "/developer/v2/activity/workout";
|
|
31
|
+
|
|
32
|
+
const devListsEnabled = (): boolean => process.env.WHOOP_DEV_V2_LISTS === "1" || process.env.WHOOP_DEV_V2_LISTS === "true";
|
|
33
|
+
|
|
34
|
+
function shiftDay(day: string, delta: number): string {
|
|
35
|
+
return new Date(Date.parse(`${day}T00:00:00Z`) + delta * 86_400_000).toISOString().slice(0, 10);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async function developerList(client: WhoopClient, startDate: string, endDate: string, limit: number): Promise<{ items: ActivityListItemT[]; more: boolean }> {
|
|
39
|
+
const items: ActivityListItemT[] = [];
|
|
40
|
+
let token: string | undefined;
|
|
41
|
+
let more = false;
|
|
42
|
+
for (let page = 0; page < Math.ceil(limit / 25) + 1; page++) {
|
|
43
|
+
const raw = await client.get(DEV_PATH, {
|
|
44
|
+
start: wallClockIso(startDate, 0, 0),
|
|
45
|
+
end: wallClockIso(shiftDay(endDate, 1), 0, 0),
|
|
46
|
+
limit: 25,
|
|
47
|
+
nextToken: token,
|
|
48
|
+
});
|
|
49
|
+
for (const r of Array.isArray(get(raw, "records")) ? (get(raw, "records") as unknown[]) : []) {
|
|
50
|
+
const item = projectDeveloperWorkout(r);
|
|
51
|
+
if (item) items.push(item);
|
|
52
|
+
}
|
|
53
|
+
token = str(get(raw, "next_token")) ?? undefined;
|
|
54
|
+
if (!token) break;
|
|
55
|
+
if (items.length >= limit) { more = true; break; }
|
|
56
|
+
}
|
|
57
|
+
return { items, more };
|
|
58
|
+
}
|
|
9
59
|
|
|
10
60
|
export function registerWorkouts(server: McpServer, client: WhoopClient): void {
|
|
11
|
-
server
|
|
12
|
-
"whoop_workouts",
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
61
|
+
defineTool(server, {
|
|
62
|
+
name: "whoop_workouts",
|
|
63
|
+
description:
|
|
64
|
+
"Activities. List: one cycle day (date) or start_date–end_date (≤31 days; default the last 7), pending and " +
|
|
65
|
+
"unscored included, as rows of id, type, sport, start, minutes, status and CARDIO strain. With activity_id: strain, calories, HR, " +
|
|
66
|
+
"zones, distance and MSK summary. Sleeps and naps: whoop_sleep.",
|
|
67
|
+
input: {
|
|
68
|
+
date: z.iso.date().optional(),
|
|
69
|
+
start_date: z.iso.date().optional(),
|
|
70
|
+
end_date: z.iso.date().optional(),
|
|
71
|
+
activity_id: z.string().min(1).optional(),
|
|
72
|
+
include: z.array(z.enum(["hr"])).optional().describe("Detail only"),
|
|
73
|
+
types: z.array(z.enum(["CARDIO", "RECOVERY", "SLEEP"])).min(1).optional().describe("Default CARDIO, RECOVERY"),
|
|
74
|
+
sport: z.string().optional().describe("Substring of the sport's name"),
|
|
75
|
+
limit: z.number().int().min(1).max(200).default(50),
|
|
19
76
|
},
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
end: end ?? window.end,
|
|
25
|
-
limit: Math.min(limit + 10, 25),
|
|
26
|
-
});
|
|
27
|
-
const projected = projectWorkoutsList(raw, sport, limit);
|
|
77
|
+
annotations: READ_ONLY,
|
|
78
|
+
}, async ({ date, start_date, end_date, activity_id, include, types, sport, limit }) => {
|
|
79
|
+
if (activity_id) {
|
|
80
|
+
let cardio: unknown;
|
|
28
81
|
try {
|
|
29
|
-
|
|
30
|
-
return { content: [{ type: "text", text: jsonOut(out) }] };
|
|
82
|
+
cardio = await client.get(CARDIO_DETAILS_V1, { activityId: activity_id });
|
|
31
83
|
} catch (e) {
|
|
32
|
-
if (e instanceof
|
|
84
|
+
if (e instanceof WhoopApiError && e.status === 404) {
|
|
85
|
+
return errorResult({ error: `No activity ${activity_id} (deleted, or not an activity id).` });
|
|
86
|
+
}
|
|
87
|
+
if (e instanceof WhoopApiError && e.status === 400) {
|
|
88
|
+
// "Cannot view activity details for a pending activity": cardio-details refuses
|
|
89
|
+
// ANY activity WHOOP is still processing, a workout seconds after a log or an
|
|
90
|
+
// edit as much as a pending sleep (live 2026-11-21: a just-edited walk). The raw
|
|
91
|
+
// record answers in every state and says which it is. Calling every 400 a sleep
|
|
92
|
+
// sent a workout to whoop_sleep, which sends it straight back here.
|
|
93
|
+
const record = await client.get(activityRecordPath(activity_id), {}, { fresh: true }).then(recordFromActivity).catch(() => null);
|
|
94
|
+
if (record?.score_type === "SLEEP") {
|
|
95
|
+
return errorResult({ error: `${activity_id} is a sleep or nap that WHOOP hasn't scored yet.`, hint: "Use whoop_sleep with this activity_id." });
|
|
96
|
+
}
|
|
97
|
+
if (!record?.type) {
|
|
98
|
+
return errorResult({
|
|
99
|
+
error: `WHOOP is still processing ${activity_id}, so its details aren't readable yet.`,
|
|
100
|
+
hint: "Try again in a few seconds. If it is a sleep or nap, use whoop_sleep.",
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
return respond("whoop_workouts", ActivityDetailOut, {
|
|
104
|
+
type: record.score_type,
|
|
105
|
+
internal_name: record.type,
|
|
106
|
+
sport_id: typeForInternalName(record.type)?.sport_id ?? null,
|
|
107
|
+
start: record.start,
|
|
108
|
+
end: record.end,
|
|
109
|
+
duration_ms: record.start && record.end ? Date.parse(record.end) - Date.parse(record.start) : null,
|
|
110
|
+
strain: null, calories: null, avg_hr_bpm: null, max_hr_bpm: null, zones_min: null, distance_m: null,
|
|
111
|
+
strength_trainer_linkable: null,
|
|
112
|
+
warnings: ["WHOOP is still processing this activity (just logged or edited), so its scores and HR aren't readable yet. Try again in a few seconds."],
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
const badId = badActivityIdError(e, activity_id);
|
|
116
|
+
if (badId) return errorResult({ error: badId.message });
|
|
33
117
|
throw e;
|
|
34
118
|
}
|
|
35
|
-
|
|
36
|
-
|
|
119
|
+
const scoreType = str(get(cardio, "details_edit_components", "single_score_type"));
|
|
120
|
+
if (scoreType === "SLEEP") {
|
|
121
|
+
return errorResult({ error: `${activity_id} is a sleep or nap.`, hint: "Use whoop_sleep with this activity_id." });
|
|
122
|
+
}
|
|
123
|
+
const recovery = scoreType === "RECOVERY"
|
|
124
|
+
? await client.get(RECOVERY_DETAILS_V2, { activityId: activity_id }).catch(() => null)
|
|
125
|
+
: null;
|
|
126
|
+
return respond("whoop_workouts", ActivityDetailOut, projectActivityDetail(cardio, recovery, activity_id, { hr: include?.includes("hr") ?? false }));
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const today = todayIso();
|
|
130
|
+
const endDate = date ?? end_date ?? today;
|
|
131
|
+
const startDate = date ?? start_date ?? shiftDay(endDate, -6);
|
|
132
|
+
if (startDate > endDate) return errorResult({ error: `start_date ${startDate} is after end_date ${endDate}.` });
|
|
133
|
+
const span = daySpan(startDate, endDate);
|
|
134
|
+
const wanted = types ?? ["CARDIO", "RECOVERY"];
|
|
135
|
+
const needle = sport?.trim().toLowerCase();
|
|
136
|
+
const matches = (a: ActivityListItemT): boolean =>
|
|
137
|
+
wanted.includes(a.type as "CARDIO" | "RECOVERY" | "SLEEP") &&
|
|
138
|
+
(!needle || (a.internal_name ?? "").toLowerCase().includes(needle) || (a.name ?? "").toLowerCase().includes(needle));
|
|
139
|
+
const newestFirst = (a: ActivityListItemT, b: ActivityListItemT): number => (b.start ?? "").localeCompare(a.start ?? "");
|
|
140
|
+
const warnings: string[] = [];
|
|
141
|
+
|
|
142
|
+
if (span > MAX_APP_DAYS) {
|
|
143
|
+
if (!devListsEnabled() || span > MAX_DEV_DAYS) {
|
|
144
|
+
return errorResult({
|
|
145
|
+
error: `The range is ${span} days; whoop_workouts reads at most ${MAX_APP_DAYS} days per call.`,
|
|
146
|
+
hint: "Split the range into ≤31-day calls.",
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
const { items, more } = await developerList(client, startDate, endDate, limit);
|
|
150
|
+
const kept = items.filter(matches).sort(newestFirst);
|
|
151
|
+
warnings.push("Ranges over 31 days come from WHOOP's developer list (WHOOP_DEV_V2_LISTS): scored workouts only; pending and incomplete ones are missing.");
|
|
152
|
+
return respond("whoop_workouts", WorkoutsListOut, {
|
|
153
|
+
source: "developer", start_date: startDate, end_date: endDate, count: Math.min(kept.length, limit),
|
|
154
|
+
...(more || kept.length > limit ? { truncated: true } : {}), ...workoutRows(kept.slice(0, limit)), warnings,
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const listing = await listTiles(client, startDate, endDate);
|
|
159
|
+
if (!listing.calendar_pruned) warnings.push("The calendar couldn't be read, so every day in the range was checked.");
|
|
160
|
+
if (listing.days_failed.length) warnings.push(`Couldn't read these days: ${listing.days_failed.join(", ")}.`);
|
|
161
|
+
const kept = listing.tiles.map(projectTile).filter(matches).sort(newestFirst);
|
|
162
|
+
return respond("whoop_workouts", WorkoutsListOut, {
|
|
163
|
+
start_date: startDate, end_date: endDate, count: Math.min(kept.length, limit),
|
|
164
|
+
...(kept.length > limit ? { truncated: true } : {}), ...workoutRows(kept.slice(0, limit)), warnings,
|
|
165
|
+
});
|
|
166
|
+
});
|
|
37
167
|
}
|
package/src/version.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
// The release, as the MCP server reports it to clients (serverInfo.version).
|
|
2
|
+
// A constant rather than a read of package.json, so the Cloudflare build (no
|
|
3
|
+
// file system) reports it too. tests/packaging.test.ts keeps it equal to
|
|
4
|
+
// package.json's version.
|
|
5
|
+
export const VERSION = "2.0.0";
|