@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
|
@@ -1,29 +1,67 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
1
|
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
2
|
import type { WhoopClient } from "../../whoop/client.js";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
3
|
+
import { defineTool, respond } from "../define.js";
|
|
4
|
+
import { READ_ONLY } from "../annotations.js";
|
|
5
|
+
import { SmartAlarmOut } from "../../schemas/alarm_schedule.js";
|
|
6
|
+
import { masterSwitch, projectAlarmSchedules, projectNextAlarm } from "../../projections/alarm_schedule.js";
|
|
7
|
+
import { WhoopAuthExpiredError } from "../../whoop/errors.js";
|
|
8
|
+
import { get } from "../../whoop/bff.js";
|
|
8
9
|
|
|
10
|
+
export const SA = "/smart-alarm-service/v1";
|
|
11
|
+
export const SA_BFF = "/smart-alarm-bff/v1";
|
|
12
|
+
export const UNAVAILABLE_NOTE =
|
|
13
|
+
"WHOOP returned an error for the Smart Alarm preferences/schedule list (on some accounts they 500 permanently). Schedules above are read from the per-day rows; open Smart Alarm in the WHOOP app to check the next alarm.";
|
|
14
|
+
|
|
15
|
+
/** Optional reads that may 500: null on any failure except an expired login. */
|
|
16
|
+
export const tolerate = <T>(p: Promise<T>): Promise<T | null> =>
|
|
17
|
+
p.catch((e: unknown) => {
|
|
18
|
+
if (e instanceof WhoopAuthExpiredError) throw e;
|
|
19
|
+
return null;
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
export async function readSmartAlarm(client: WhoopClient, fresh = false) {
|
|
23
|
+
const [rows, all, prefs] = await Promise.all([
|
|
24
|
+
client.get(`${SA}/alarm-schedule`, {}, { fresh }),
|
|
25
|
+
tolerate(client.get(`${SA_BFF}/schedule/all`, {}, { fresh })),
|
|
26
|
+
tolerate(client.get(`${SA}/smartalarm/preferences`, {}, { fresh })),
|
|
27
|
+
]);
|
|
28
|
+
const { schedules, unscheduled } = projectAlarmSchedules(rows);
|
|
29
|
+
return {
|
|
30
|
+
master_switch: masterSwitch(all, prefs),
|
|
31
|
+
schedules,
|
|
32
|
+
unscheduled,
|
|
33
|
+
next_alarm: prefs === null ? ("unavailable" as const) : projectNextAlarm(prefs),
|
|
34
|
+
note: prefs === null || all === null ? UNAVAILABLE_NOTE : null,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** "07:35" minus 60 → "06:35", across midnight. */
|
|
39
|
+
export function minusMinutes(hhmm: string, minutes: number): string {
|
|
40
|
+
const [h, m] = hhmm.split(":").map(Number);
|
|
41
|
+
const t = (((h! * 60 + m! - minutes) % 1440) + 1440) % 1440;
|
|
42
|
+
return `${String(Math.floor(t / 60)).padStart(2, "0")}:${String(t % 60).padStart(2, "0")}`;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// IN_THE_GREEN and SLEEP_GOAL buzz inside a window that ends at the latest wake
|
|
46
|
+
// time. The app's schedule screen (smart-alarm-bff/v1/schedule/components) says
|
|
47
|
+
// "Alarm will vibrate between %s - %s" for those two modes only; the window is
|
|
48
|
+
// GET /smart-alarm-service/v1/user-info/default-wake-window
|
|
49
|
+
// {default_wake_window_minutes} (route from @Acetone1's Android list; 60 on the
|
|
50
|
+
// test account, 2026-11-22).
|
|
9
51
|
export function registerSmartAlarm(server: McpServer, client: WhoopClient): void {
|
|
10
|
-
server
|
|
11
|
-
"whoop_smart_alarm",
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
throw e;
|
|
26
|
-
}
|
|
27
|
-
},
|
|
28
|
-
);
|
|
52
|
+
defineTool(server, {
|
|
53
|
+
name: "whoop_smart_alarm",
|
|
54
|
+
description:
|
|
55
|
+
"Smart Alarm: recurring schedules (id, days, mode, sleep goal, latest wake time, enabled), unscheduled days, the master switch " +
|
|
56
|
+
"and the next alarm WHOOP will set. Server state only: it doesn't prove the strap has synced.",
|
|
57
|
+
input: {},
|
|
58
|
+
annotations: READ_ONLY,
|
|
59
|
+
}, async () => {
|
|
60
|
+
const [state, window] = await Promise.all([readSmartAlarm(client), tolerate(client.get(`${SA}/user-info/default-wake-window`))]);
|
|
61
|
+
const min = get(window, "default_wake_window_minutes");
|
|
62
|
+
const wakeWindow = typeof min === "number" && Number.isInteger(min) && min > 0 && min < 1440 ? min : null;
|
|
63
|
+
const schedules = wakeWindow === null ? state.schedules : state.schedules.map((sc) =>
|
|
64
|
+
sc.mode === "IN_THE_GREEN" || sc.mode === "SLEEP_GOAL" ? { ...sc, earliest: minusMinutes(sc.wake, wakeWindow) } : sc);
|
|
65
|
+
return respond("whoop_smart_alarm", SmartAlarmOut, { ...state, schedules, wake_window_min: wakeWindow });
|
|
66
|
+
});
|
|
29
67
|
}
|
|
@@ -1,103 +1,253 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
3
|
import type { WhoopClient } from "../../whoop/client.js";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
4
|
+
import { defineTool, respond } from "../define.js";
|
|
5
|
+
import { WRITE_DESTRUCTIVE } from "../annotations.js";
|
|
6
|
+
import {
|
|
7
|
+
ALARM_MODES,
|
|
8
|
+
DAYS,
|
|
9
|
+
SAFE_ALARM_GOALS,
|
|
10
|
+
SLEEP_GOALS,
|
|
11
|
+
SmartAlarmSetOut,
|
|
12
|
+
type AlarmScheduleT,
|
|
13
|
+
type Day,
|
|
14
|
+
} from "../../schemas/alarm_schedule.js";
|
|
15
|
+
import { projectAlarmSchedules, wireDay } from "../../projections/alarm_schedule.js";
|
|
16
|
+
import { previewWith, toolError, writeRejected } from "../../lib/health_plans_write.js";
|
|
17
|
+
import { normalizeClockTime } from "../../lib/clock.js";
|
|
18
|
+
import { WhoopApiError, WhoopServerError } from "../../whoop/errors.js";
|
|
19
|
+
import { todayIso } from "../../lib/dates.js";
|
|
20
|
+
import { wallClockIso } from "../../lib/timezone.js";
|
|
21
|
+
import { readSmartAlarm, SA, SA_BFF } from "./smart_alarm.js";
|
|
7
22
|
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
days_of_week: z.array(z.enum(["MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY", "SATURDAY", "SUNDAY"])),
|
|
11
|
-
latest_wake_time: z.string().regex(/^\d{2}:\d{2}:\d{2}$/),
|
|
12
|
-
alarm_mode: z.enum(["IN_THE_GREEN", "EXACT_TIME_PEAK", "EXACT_TIME_OPTIMIZE_SLEEP"]),
|
|
13
|
-
sleep_goal: z.string().default(""),
|
|
14
|
-
timezone_offset: z.string(),
|
|
15
|
-
});
|
|
23
|
+
const SYNC = "Open the WHOOP app so the strap picks up the change; totem can't push alarms to the strap.";
|
|
24
|
+
const NO_RETRY = "WHOOP answered 500. Totem never retries Smart Alarm writes (a bad one can break the account's alarm settings); the result below is what read back.";
|
|
16
25
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
+
/** The member's current UTC offset as "-0800" (required on schedule writes; not stored). */
|
|
27
|
+
export function tzOffset(): string {
|
|
28
|
+
const iso = wallClockIso(todayIso(), 12, 0);
|
|
29
|
+
return iso.slice(-6).replace(":", "");
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
type Mode = typeof ALARM_MODES[number];
|
|
33
|
+
type SleepGoal = typeof SLEEP_GOALS[number];
|
|
34
|
+
interface Target { days: Day[]; mode: Mode; sleep_goal: SleepGoal | null; wake: string; enabled: boolean }
|
|
35
|
+
|
|
36
|
+
/** The bff schedule body: all six fields, always (a missing one is a 422). */
|
|
37
|
+
export function scheduleBody(t: Target) {
|
|
38
|
+
return {
|
|
39
|
+
day_of_week_list: t.days.map(wireDay),
|
|
40
|
+
latest_wake_time: t.wake,
|
|
41
|
+
alarm_mode: t.mode,
|
|
42
|
+
time_zone_offset: tzOffset(),
|
|
43
|
+
sleep_goal: t.mode === "SLEEP_GOAL" ? t.sleep_goal! : "",
|
|
44
|
+
enabled: t.mode === "NO_ALARM" ? false : t.enabled,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** Does a schedule read back as the target? (NO_ALARM is stored as EXACT_TIME, disabled.) */
|
|
49
|
+
export function scheduleMatches(groups: AlarmScheduleT[], t: Target): boolean {
|
|
50
|
+
if (!groups.length) return false;
|
|
51
|
+
const days = [...new Set(groups.flatMap((g) => g.days))];
|
|
52
|
+
const wantMode = t.mode === "NO_ALARM" ? "EXACT_TIME" : t.mode;
|
|
53
|
+
const wantEnabled = t.mode === "NO_ALARM" ? false : t.enabled;
|
|
54
|
+
return days.length === t.days.length && t.days.every((d) => days.includes(d))
|
|
55
|
+
&& groups.every((g) => g.mode === wantMode && g.wake === t.wake.slice(0, 5) && g.enabled === wantEnabled
|
|
56
|
+
&& (t.mode === "SLEEP_GOAL" ? g.sleep_goal === t.sleep_goal : true));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const describe = (s: AlarmScheduleT): string =>
|
|
60
|
+
`${s.mode ?? s.goal}${s.sleep_goal ? ` ${s.sleep_goal}` : ""} ${s.wake}${s.enabled ? "" : " (off)"}`;
|
|
26
61
|
|
|
27
62
|
export function registerSmartAlarmSet(server: McpServer, client: WhoopClient): void {
|
|
28
|
-
server
|
|
29
|
-
"whoop_smart_alarm_set",
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
63
|
+
defineTool(server, {
|
|
64
|
+
name: "whoop_smart_alarm_set",
|
|
65
|
+
description:
|
|
66
|
+
"Change Smart Alarm. create/edit a recurring schedule (edit merges; mode NO_ALARM is off); a day belongs to one schedule, so " +
|
|
67
|
+
"claiming it moves it off another. enable/disable flip the master switch; disable also turns the next alarm off. single_alarm " +
|
|
68
|
+
"sets only the next alarm and turns recurring schedules off. Changes reach the strap only after the WHOOP app syncs. Previews " +
|
|
69
|
+
"unless confirm:true.",
|
|
70
|
+
input: {
|
|
71
|
+
action: z.enum(["create", "edit", "delete", "enable", "disable", "single_alarm"]),
|
|
72
|
+
schedule_id: z.string().regex(/^[0-9a-fA-F-]{8,64}$/).optional().describe("For edit and delete"),
|
|
73
|
+
days: z.array(z.enum(DAYS)).min(1).optional(),
|
|
74
|
+
mode: z.enum(ALARM_MODES).optional(),
|
|
75
|
+
sleep_goal: z.enum(SLEEP_GOALS).optional().describe("Only with mode SLEEP_GOAL"),
|
|
76
|
+
wake_time: z.string().optional().describe("Latest wake time, 24h, e.g. 06:45"),
|
|
77
|
+
enabled: z.boolean().optional().describe("The schedule's own on/off flag"),
|
|
78
|
+
goal: z.enum(SAFE_ALARM_GOALS).optional().describe("single_alarm only; default EXACT_TIME_PERFORM"),
|
|
36
79
|
confirm: z.boolean().default(false),
|
|
37
80
|
},
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
81
|
+
annotations: WRITE_DESTRUCTIVE,
|
|
82
|
+
}, async (args) => {
|
|
83
|
+
const { action, schedule_id, days, mode, sleep_goal, wake_time, enabled, goal, confirm } = args;
|
|
84
|
+
const scheduleAction = action === "create" || action === "edit";
|
|
85
|
+
if (!scheduleAction && (days || mode || sleep_goal)) return toolError(`action:${action} takes no days, mode or sleep_goal.`);
|
|
86
|
+
if ((action === "edit" || action === "delete") && !schedule_id) return toolError(`action:${action} needs schedule_id (from whoop_smart_alarm).`);
|
|
87
|
+
if ((action === "create" || action === "enable" || action === "disable" || action === "single_alarm") && schedule_id) {
|
|
88
|
+
return toolError(`action:${action} takes no schedule_id.`);
|
|
89
|
+
}
|
|
90
|
+
if (goal && action !== "single_alarm") return toolError("goal is only for single_alarm; schedules use mode (+ sleep_goal).");
|
|
91
|
+
if ((action === "delete" || action === "enable" || action === "disable") && (wake_time || enabled !== undefined)) {
|
|
92
|
+
return toolError(`action:${action} takes no wake_time or enabled.`);
|
|
93
|
+
}
|
|
94
|
+
if (action === "single_alarm" && enabled === false) {
|
|
95
|
+
// The only preferences body verified on a healthy account has enabled:true; the app's own
|
|
96
|
+
// turn-off form adds `default:true`, which S1 bans. alarm-schedule/disable is the verified off.
|
|
97
|
+
return toolError("single_alarm sets an alarm that is on. To turn the alarm off use action:disable.");
|
|
98
|
+
}
|
|
99
|
+
if (days && new Set(days).size !== days.length) return toolError("days has duplicates.");
|
|
100
|
+
let wake: string | null = null;
|
|
101
|
+
if (wake_time !== undefined) {
|
|
102
|
+
wake = normalizeClockTime(wake_time);
|
|
103
|
+
if (!wake) return toolError(`wake_time "${wake_time}" isn't a clock time; use 24h HH:MM, e.g. 06:45.`);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// Fresh pre-read: per-day rows (truth), master switch, next alarm.
|
|
107
|
+
const before = await readSmartAlarm(client, true);
|
|
108
|
+
const warnings: string[] = [];
|
|
109
|
+
const respondReceipt = async (schedule: string | null, verified: boolean, noChange = false, after?: Awaited<ReturnType<typeof readSmartAlarm>>) => {
|
|
110
|
+
const state = after ?? before;
|
|
111
|
+
warnings.push(SYNC);
|
|
112
|
+
return respond("whoop_smart_alarm_set", SmartAlarmSetOut, {
|
|
113
|
+
action, schedule_id: schedule, verified, no_change: noChange,
|
|
114
|
+
schedules: state.schedules, master_switch: state.master_switch, next_alarm: state.next_alarm, warnings,
|
|
115
|
+
});
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
if (scheduleAction) {
|
|
119
|
+
const current = action === "edit" ? before.schedules.filter((s) => s.id === schedule_id) : [];
|
|
120
|
+
if (action === "edit" && !current.length) {
|
|
121
|
+
return toolError(`No schedule ${schedule_id} (WHOOP's schedule PUT is an upsert and would create one). Use action:create.`);
|
|
122
|
+
}
|
|
123
|
+
const cur = current[0];
|
|
124
|
+
if (current.length > 1 && (mode === undefined || wake === null || (enabled === undefined && mode !== "NO_ALARM"))) {
|
|
125
|
+
// A half-applied write can leave one schedule's days with different settings. The PUT sets
|
|
126
|
+
// every day alike, so nothing is merged from "the current schedule": there isn't one.
|
|
127
|
+
return toolError(`Schedule ${schedule_id}'s days don't agree (${current.map((s) => `${s.days.join("+")}: ${describe(s)}`).join("; ")}). An edit sets all of them alike, so pass mode, wake_time and enabled explicitly.`);
|
|
128
|
+
}
|
|
129
|
+
const m: Mode | undefined = mode ?? (cur?.mode ?? undefined);
|
|
130
|
+
if (!m) return toolError(action === "create" ? "create needs mode." : `Schedule ${schedule_id} has goal ${cur?.goal}; pass mode explicitly.`);
|
|
131
|
+
if (sleep_goal && m !== "SLEEP_GOAL") return toolError("sleep_goal only applies to mode SLEEP_GOAL (WHOOP requires it empty otherwise).");
|
|
132
|
+
const sg = m === "SLEEP_GOAL" ? sleep_goal ?? (cur?.mode === "SLEEP_GOAL" ? cur.sleep_goal : null) : null;
|
|
133
|
+
if (m === "SLEEP_GOAL" && !sg) return toolError("mode SLEEP_GOAL needs sleep_goal.");
|
|
134
|
+
if (m === "NO_ALARM" && enabled === true) return toolError("NO_ALARM is the off state; it can't be enabled:true (WHOOP rejects it).");
|
|
135
|
+
const targetDays = days ?? [...new Set(current.flatMap((s) => s.days))];
|
|
136
|
+
const w = wake ?? (cur && /^\d{2}:\d{2}$/.test(cur.wake) ? `${cur.wake}:00` : null);
|
|
137
|
+
if (!targetDays.length) return toolError("create needs days.");
|
|
138
|
+
if (!w) return toolError(action === "create" ? "create needs wake_time." : `Schedule ${schedule_id} has no readable wake time; pass wake_time.`);
|
|
139
|
+
const target: Target = {
|
|
140
|
+
days: targetDays,
|
|
141
|
+
mode: m,
|
|
142
|
+
sleep_goal: sg,
|
|
143
|
+
wake: w,
|
|
144
|
+
enabled: m === "NO_ALARM" ? false : enabled ?? (mode ? true : cur?.enabled ?? true),
|
|
145
|
+
};
|
|
146
|
+
if (action === "edit" && scheduleMatches(current, target)) return respondReceipt(schedule_id!, true, true);
|
|
147
|
+
|
|
148
|
+
for (const d of target.days) {
|
|
149
|
+
const owner = before.schedules.find((s) => s.id !== schedule_id && s.days.includes(d));
|
|
150
|
+
if (owner) warnings.push(`${d} moves off schedule ${owner.id} (${describe(owner)}).`);
|
|
151
|
+
}
|
|
152
|
+
for (const d of current.flatMap((s) => s.days)) {
|
|
153
|
+
if (!target.days.includes(d)) warnings.push(`${d} leaves this schedule and becomes unscheduled.`);
|
|
154
|
+
}
|
|
155
|
+
if (action === "create" && before.master_switch !== true) warnings.push("Creating a schedule turns the recurring master switch on.");
|
|
156
|
+
if (before.master_switch !== false) warnings.push("With the master switch on, schedule writes also reset the next alarm from tomorrow's schedule.");
|
|
157
|
+
|
|
158
|
+
const body = scheduleBody(target);
|
|
159
|
+
const path = action === "edit" ? `${SA_BFF}/schedule/${schedule_id}` : `${SA_BFF}/schedule`;
|
|
160
|
+
const method = action === "edit" ? "PUT" : "POST";
|
|
161
|
+
if (!confirm) return respond("whoop_smart_alarm_set", SmartAlarmSetOut, previewWith(method, path, body, [...warnings, SYNC], current.length ? current : undefined));
|
|
162
|
+
|
|
163
|
+
let created: string | null = null;
|
|
164
|
+
try {
|
|
165
|
+
const res = action === "edit" ? await client.put(path, body) : await client.post(path, body);
|
|
166
|
+
if (Array.isArray(res) && typeof res[0]?.schedule_id === "string") created = res[0].schedule_id;
|
|
167
|
+
} catch (error) {
|
|
168
|
+
if (error instanceof WhoopServerError) warnings.push(NO_RETRY);
|
|
169
|
+
else if (error instanceof WhoopApiError) return writeRejected("schedule", path, error);
|
|
170
|
+
else throw error;
|
|
90
171
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
172
|
+
const after = await readSmartAlarm(client, true);
|
|
173
|
+
if (action === "create" && created === null) {
|
|
174
|
+
// No response body (WHOOP can save the rows and then answer 500): the new schedule is
|
|
175
|
+
// the one id that wasn't there before and reads back as requested.
|
|
176
|
+
const known = new Set(before.schedules.map((s) => s.id));
|
|
177
|
+
const fresh = [...new Set(after.schedules.map((s) => s.id))]
|
|
178
|
+
.filter((x) => !known.has(x) && scheduleMatches(after.schedules.filter((s) => s.id === x), target));
|
|
179
|
+
if (fresh.length === 1) created = fresh[0]!;
|
|
97
180
|
}
|
|
181
|
+
const id = action === "edit" ? schedule_id! : created;
|
|
182
|
+
const verified = id !== null && scheduleMatches(after.schedules.filter((s) => s.id === id), target);
|
|
183
|
+
if (!verified) warnings.push("The schedule didn't read back as requested; see schedules.");
|
|
184
|
+
return respondReceipt(id, verified, false, after);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
if (action === "delete") {
|
|
188
|
+
const current = before.schedules.filter((s) => s.id === schedule_id);
|
|
189
|
+
if (!current.length) return toolError(`No schedule ${schedule_id}. (WHOOP answers 204 to any delete, so totem won't send one it can't verify.)`);
|
|
190
|
+
const freed = current.flatMap((s) => s.days);
|
|
191
|
+
warnings.push(`${freed.join(", ")} become unscheduled.`);
|
|
192
|
+
const path = `${SA}/alarm-schedule/${schedule_id}`;
|
|
193
|
+
if (!confirm) return respond("whoop_smart_alarm_set", SmartAlarmSetOut, previewWith("DELETE", path, null, [...warnings, SYNC], current));
|
|
194
|
+
try {
|
|
195
|
+
await client.delete(path);
|
|
196
|
+
} catch (error) {
|
|
197
|
+
if (error instanceof WhoopServerError) warnings.push(NO_RETRY);
|
|
198
|
+
else if (error instanceof WhoopApiError) return writeRejected("schedule delete", path, error);
|
|
199
|
+
else throw error;
|
|
200
|
+
}
|
|
201
|
+
const gone = projectAlarmSchedules(await client.get(path, {}, { fresh: true })).schedules.length === 0;
|
|
202
|
+
return respondReceipt(schedule_id!, gone, false, await readSmartAlarm(client, true));
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
if (action === "enable" || action === "disable") {
|
|
206
|
+
const want = action === "enable";
|
|
207
|
+
const alarmOn = (state: typeof before): boolean => state.next_alarm !== "unavailable" && state.next_alarm.enabled === true;
|
|
208
|
+
// disable also turns the next alarm off, so it still has work to do while a single alarm is on.
|
|
209
|
+
if (before.master_switch === want && !(action === "disable" && alarmOn(before))) return respondReceipt(null, true, true);
|
|
210
|
+
warnings.push(want
|
|
211
|
+
? "Turning the master switch on resets the next alarm from tomorrow's schedule."
|
|
212
|
+
: "Turning the master switch off also turns off the next alarm; each schedule keeps its own enabled flag.");
|
|
213
|
+
const path = `${SA}/alarm-schedule/${action}`;
|
|
214
|
+
if (!confirm) return respond("whoop_smart_alarm_set", SmartAlarmSetOut, previewWith("PUT", path, null, [...warnings, SYNC], { master_switch: before.master_switch }));
|
|
215
|
+
try {
|
|
216
|
+
await client.put(path, undefined);
|
|
217
|
+
} catch (error) {
|
|
218
|
+
if (error instanceof WhoopServerError) warnings.push(NO_RETRY);
|
|
219
|
+
else if (error instanceof WhoopApiError) return writeRejected(`master ${action}`, path, error);
|
|
220
|
+
else throw error;
|
|
221
|
+
}
|
|
222
|
+
const after = await readSmartAlarm(client, true);
|
|
223
|
+
if (after.master_switch === "unavailable") warnings.push("The master switch couldn't be read back (WHOOP error).");
|
|
224
|
+
const stillOn = action === "disable" && alarmOn(after);
|
|
225
|
+
if (stillOn) warnings.push("The next alarm still reads as on.");
|
|
226
|
+
return respondReceipt(null, after.master_switch === want && !stillOn, false, after);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// single_alarm: the next alarm only, via preferences. S1: allowlisted goals only, never anything else.
|
|
230
|
+
if (!wake) return toolError("single_alarm needs wake_time.");
|
|
231
|
+
const g = goal ?? "EXACT_TIME_PERFORM";
|
|
232
|
+
if (!(SAFE_ALARM_GOALS as readonly string[]).includes(g)) return toolError(`goal ${g} isn't allowed.`);
|
|
233
|
+
const on = true;
|
|
234
|
+
const body = { upper_time_bound: wake, goal: g, time_zone_offset: tzOffset(), schedule_enabled: false, enabled: on };
|
|
235
|
+
warnings.push("This turns the recurring master switch off: schedules stop setting alarms until you enable it again.");
|
|
236
|
+
if (before.next_alarm === "unavailable") warnings.push("WHOOP can't currently read this account's alarm preferences (error); the write may fail. If so, fix Smart Alarm in the app.");
|
|
237
|
+
const path = `${SA}/smartalarm/preferences`;
|
|
238
|
+
if (!confirm) return respond("whoop_smart_alarm_set", SmartAlarmSetOut, previewWith("PUT", path, body, [...warnings, SYNC], { next_alarm: before.next_alarm, master_switch: before.master_switch }));
|
|
239
|
+
try {
|
|
98
240
|
await client.put(path, body);
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
241
|
+
} catch (error) {
|
|
242
|
+
if (error instanceof WhoopServerError) warnings.push(NO_RETRY);
|
|
243
|
+
else if (error instanceof WhoopApiError) return writeRejected("single alarm", path, error);
|
|
244
|
+
else throw error;
|
|
245
|
+
}
|
|
246
|
+
const after = await readSmartAlarm(client, true);
|
|
247
|
+
const next = after.next_alarm;
|
|
248
|
+
const verified = next !== "unavailable" && next.goal === g && next.to === wake.slice(0, 5) && next.enabled === on
|
|
249
|
+
&& after.master_switch === false;
|
|
250
|
+
if (!verified) warnings.push(next === "unavailable" ? "The next alarm couldn't be read back (WHOOP error)." : "The next alarm didn't read back as requested.");
|
|
251
|
+
return respondReceipt(null, verified, false, after);
|
|
252
|
+
});
|
|
103
253
|
}
|
package/src/tools/v2/strain.ts
CHANGED
|
@@ -1,28 +1,31 @@
|
|
|
1
|
+
// whoop_strain (v2): GET /home-service/v1/deep-dive/strain?date=.
|
|
1
2
|
import { z } from "zod";
|
|
2
3
|
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
4
|
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";
|
|
5
|
+
import { defineTool, respond } from "../define.js";
|
|
6
|
+
import { READ_ONLY } from "../annotations.js";
|
|
8
7
|
import { todayIso } from "../../lib/dates.js";
|
|
8
|
+
import { StrainV2Out } from "../../schemas/v2/strain.js";
|
|
9
|
+
import { projectStrainV2 } from "../../projections/v2/strain.js";
|
|
10
|
+
|
|
11
|
+
const NAME = "whoop_strain";
|
|
9
12
|
|
|
10
13
|
export function registerStrain(server: McpServer, client: WhoopClient): void {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
defineTool(
|
|
15
|
+
server,
|
|
16
|
+
{
|
|
17
|
+
name: NAME,
|
|
18
|
+
description:
|
|
19
|
+
"Day strain for a cycle day (default today): score (0–21), target (null while calibrating), contributors vs your 30-day baseline " +
|
|
20
|
+
"(zone minutes, strength minutes, steps) and the day's CARDIO activities. RECOVERY activities (sauna, meditation) don't count " +
|
|
21
|
+
"toward strain; see whoop_day.",
|
|
22
|
+
input: { date: z.iso.date().optional() },
|
|
23
|
+
annotations: READ_ONLY,
|
|
24
|
+
},
|
|
15
25
|
async ({ date }) => {
|
|
16
26
|
const d = date ?? todayIso();
|
|
17
27
|
const raw = await client.get("/home-service/v1/deep-dive/strain", { date: d });
|
|
18
|
-
|
|
19
|
-
try {
|
|
20
|
-
const out = StrainOut.parse(projected);
|
|
21
|
-
return { content: [{ type: "text", text: jsonOut(out) }] };
|
|
22
|
-
} catch (e) {
|
|
23
|
-
if (e instanceof z.ZodError) throw new WhoopProjectionError("whoop_strain", e);
|
|
24
|
-
throw e;
|
|
25
|
-
}
|
|
28
|
+
return respond(NAME, StrainV2Out, projectStrainV2(raw, d));
|
|
26
29
|
},
|
|
27
30
|
);
|
|
28
31
|
}
|
package/src/tools/v2/stress.ts
CHANGED
|
@@ -1,28 +1,33 @@
|
|
|
1
|
+
// whoop_stress (v2): GET /health-service/v2/stress-bff/{date}.
|
|
1
2
|
import { z } from "zod";
|
|
2
3
|
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
4
|
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";
|
|
5
|
+
import { defineTool, respond } from "../define.js";
|
|
6
|
+
import { READ_ONLY } from "../annotations.js";
|
|
8
7
|
import { todayIso } from "../../lib/dates.js";
|
|
8
|
+
import { StressV2Out } from "../../schemas/v2/stress.js";
|
|
9
|
+
import { projectStressV2 } from "../../projections/v2/stress.js";
|
|
10
|
+
|
|
11
|
+
const NAME = "whoop_stress";
|
|
9
12
|
|
|
10
13
|
export function registerStress(server: McpServer, client: WhoopClient): void {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
defineTool(
|
|
15
|
+
server,
|
|
16
|
+
{
|
|
17
|
+
name: NAME,
|
|
18
|
+
description:
|
|
19
|
+
"Stress Monitor for a day (default today): state, current level (0–3) and label, min and peak, and minutes in low/medium/high " +
|
|
20
|
+
"stress. Today's graph covers the last 24 hours. include timeline adds the mean level per 30 minutes.",
|
|
21
|
+
input: {
|
|
22
|
+
date: z.iso.date().optional(),
|
|
23
|
+
include: z.array(z.enum(["timeline"])).optional(),
|
|
24
|
+
},
|
|
25
|
+
annotations: READ_ONLY,
|
|
26
|
+
},
|
|
27
|
+
async ({ date, include }) => {
|
|
16
28
|
const d = date ?? todayIso();
|
|
17
29
|
const raw = await client.get(`/health-service/v2/stress-bff/${d}`);
|
|
18
|
-
|
|
19
|
-
try {
|
|
20
|
-
const out = StressOut.parse(projected);
|
|
21
|
-
return { content: [{ type: "text", text: jsonOut(out) }] };
|
|
22
|
-
} catch (e) {
|
|
23
|
-
if (e instanceof z.ZodError) throw new WhoopProjectionError("whoop_stress", e);
|
|
24
|
-
throw e;
|
|
25
|
-
}
|
|
30
|
+
return respond(NAME, StressV2Out, projectStressV2(raw, d, include?.includes("timeline") ?? false));
|
|
26
31
|
},
|
|
27
32
|
);
|
|
28
33
|
}
|
package/src/tools/v2/trend.ts
CHANGED
|
@@ -1,31 +1,69 @@
|
|
|
1
|
+
// whoop_trend (v2): replaces whoop_trend, whoop_trend_pack and whoop_compare.
|
|
1
2
|
import { z } from "zod";
|
|
2
3
|
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
4
|
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";
|
|
5
|
+
import { defineTool, respond } from "../define.js";
|
|
6
|
+
import { READ_ONLY } from "../annotations.js";
|
|
8
7
|
import { todayIso } from "../../lib/dates.js";
|
|
8
|
+
import { runPaced } from "../../lib/concurrency.js";
|
|
9
|
+
import { TREND_METRICS, TrendV2Out } from "../../schemas/v2/trend.js";
|
|
10
|
+
import { TREND_WINDOWS, compactWindow, compareRows, projectTrendWindow, type TrendWindow, type TrendWindowOut } from "../../projections/v2/trend.js";
|
|
11
|
+
|
|
12
|
+
const NAME = "whoop_trend";
|
|
13
|
+
type Metric = (typeof TREND_METRICS)[number];
|
|
9
14
|
|
|
10
15
|
export function registerTrend(server: McpServer, client: WhoopClient): void {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
"Trend for one metric across week / month / 6-month windows — per-day points, aggregate stats, and delta vs the prior window. metric is exactly one of: HRV, RHR, RECOVERY, DAY_STRAIN, CALORIES, STEPS, AVERAGE_HR, HOURS_V_NEED, HOURS_V_NEEDED_PERCENT, TIME_IN_BED, SLEEP_PERFORMANCE, SLEEP_EFFICIENCY, SLEEP_CONSISTENCY, SLEEP_DEBT_POST, RESTORATIVE_SLEEP, HR_ZONES_1_3, HR_ZONES_4_5, RESPIRATORY_RATE, STRENGTH_ACTIVITY_TIME, STRESS, STRESS_DURING_SLEEP, STRESS_DURING_NON_STRAIN, VO2_MAX, BODY_COMPOSITION, WEIGHT.",
|
|
16
|
+
defineTool(
|
|
17
|
+
server,
|
|
14
18
|
{
|
|
15
|
-
|
|
16
|
-
|
|
19
|
+
name: NAME,
|
|
20
|
+
description:
|
|
21
|
+
"Trends for 1–5 metrics over a window ending end_date (default today; week = 7 days, month 30, six_month 180): average, " +
|
|
22
|
+
"previous-window average, change % and direction. HR-zone and strength-time rows are weekly totals. compare_end_date adds a " +
|
|
23
|
+
"second window and the deltas.",
|
|
24
|
+
input: {
|
|
25
|
+
metrics: z.array(z.enum(TREND_METRICS)).min(1).max(5)
|
|
26
|
+
.refine((v) => new Set(v).size === v.length, "metrics must not repeat"),
|
|
27
|
+
window: z.enum(TREND_WINDOWS).default("month"),
|
|
28
|
+
end_date: z.iso.date().optional(),
|
|
29
|
+
compare_end_date: z.iso.date().optional(),
|
|
30
|
+
include_points: z.boolean().default(false).describe("One value per day or week"),
|
|
31
|
+
},
|
|
32
|
+
annotations: READ_ONLY,
|
|
17
33
|
},
|
|
18
|
-
async ({
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
34
|
+
async ({ metrics, window, end_date, compare_end_date, include_points }) => {
|
|
35
|
+
const a = end_date ?? todayIso();
|
|
36
|
+
if (compare_end_date === a) throw new Error("compare_end_date must differ from end_date.");
|
|
37
|
+
const ends = compare_end_date ? [a, compare_end_date] : [a];
|
|
38
|
+
// Up to 10 trend reads, paced ≤3 at a time with jitter rather than one burst.
|
|
39
|
+
const fetched = await runPaced(
|
|
40
|
+
metrics.flatMap((m: Metric) => ends.map((end) => async () => {
|
|
41
|
+
try {
|
|
42
|
+
const raw = await client.get(`/progression-service/v3/trends/${m}`, { endDate: end });
|
|
43
|
+
return { m, end, w: projectTrendWindow(raw, end, window as TrendWindow, include_points), error: null as string | null };
|
|
44
|
+
} catch (e) {
|
|
45
|
+
return { m, end, w: null as TrendWindowOut | null, error: e instanceof Error ? e.message : String(e) };
|
|
46
|
+
}
|
|
47
|
+
})),
|
|
48
|
+
{ concurrency: 3, jitterMaxMs: 150 },
|
|
49
|
+
);
|
|
50
|
+
const pick = (m: Metric, end: string) => fetched.find((f) => f.m === m && f.end === end)!;
|
|
51
|
+
const out = {
|
|
52
|
+
window,
|
|
53
|
+
metrics: metrics.map((m: Metric) => {
|
|
54
|
+
const ra = pick(m, a);
|
|
55
|
+
const row: Record<string, unknown> = { metric: m, a: ra.w && compactWindow(ra.w) };
|
|
56
|
+
if (ra.error) row.error = ra.error;
|
|
57
|
+
if (compare_end_date) {
|
|
58
|
+
const rb = pick(m, compare_end_date);
|
|
59
|
+
row.b = rb.w && compactWindow(rb.w);
|
|
60
|
+
if (rb.error) row.error = row.error ?? rb.error;
|
|
61
|
+
if (ra.w && rb.w) row.delta = compareRows(ra.w.rows, rb.w.rows);
|
|
62
|
+
}
|
|
63
|
+
return row;
|
|
64
|
+
}),
|
|
65
|
+
};
|
|
66
|
+
return respond(NAME, TrendV2Out, out);
|
|
29
67
|
},
|
|
30
68
|
);
|
|
31
69
|
}
|