@thebriangao/totem 1.4.4 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.dev.vars.example +5 -0
- package/.dockerignore +5 -0
- package/.env.example +29 -20
- package/CHANGELOG.md +99 -1
- package/CONTRIBUTING.md +48 -116
- package/Dockerfile +46 -12
- package/README.md +172 -498
- package/SECURITY.md +36 -59
- package/TOOLS.md +448 -311
- package/WHOOP.md +497 -2659
- package/assets/brand/SOURCES.md +38 -0
- package/assets/brand/totem.png +0 -0
- package/assets/brand/totem.svg +13 -0
- package/assets/fonts/Manrope-OFL.txt +93 -0
- package/assets/fonts/manrope-latin.woff2 +0 -0
- package/dist/build_info.js +5 -0
- package/dist/build_info.js.map +1 -0
- package/dist/cli/app.js +675 -0
- package/dist/cli/app.js.map +1 -0
- package/dist/cli/auth.js +297 -0
- package/dist/cli/auth.js.map +1 -0
- package/dist/cli/auth_flow.js +268 -0
- package/dist/cli/auth_flow.js.map +1 -0
- package/dist/cli/browser_login.js +368 -0
- package/dist/cli/browser_login.js.map +1 -0
- package/dist/cli/clients.js +403 -0
- package/dist/cli/clients.js.map +1 -0
- package/dist/cli/deploy_record.js +96 -0
- package/dist/cli/deploy_record.js.map +1 -0
- package/dist/cli/index.js +39 -575
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/links.js +28 -0
- package/dist/cli/links.js.map +1 -0
- package/dist/cli/logo.js +63 -0
- package/dist/cli/logo.js.map +1 -0
- package/dist/cli/setup.js +1157 -1017
- package/dist/cli/setup.js.map +1 -1
- package/dist/cli/spawn.js +80 -0
- package/dist/cli/spawn.js.map +1 -0
- package/dist/cli/sys.js +219 -0
- package/dist/cli/sys.js.map +1 -0
- package/dist/cli/ui.js +712 -463
- package/dist/cli/ui.js.map +1 -1
- package/dist/cli/update.js +425 -282
- package/dist/cli/update.js.map +1 -1
- package/dist/cloudflare/token_store.js +48 -0
- package/dist/cloudflare/token_store.js.map +1 -0
- package/dist/cloudflare/worker.js +155 -0
- package/dist/cloudflare/worker.js.map +1 -0
- package/dist/data/behaviors.js +2733 -617
- package/dist/data/behaviors.js.map +1 -1
- package/dist/data/endpoint_catalog.js +2681 -0
- package/dist/data/endpoint_catalog.js.map +1 -0
- package/dist/data/exercises.js +373 -4859
- package/dist/data/exercises.js.map +1 -1
- package/dist/data/garments.js +19 -0
- package/dist/data/garments.js.map +1 -0
- package/dist/data/sports.js +219 -208
- package/dist/data/sports.js.map +1 -1
- package/dist/lib/activity_list.js +123 -0
- package/dist/lib/activity_list.js.map +1 -0
- package/dist/lib/activity_records.js +195 -0
- package/dist/lib/activity_records.js.map +1 -0
- package/dist/lib/activity_results.js +44 -0
- package/dist/lib/activity_results.js.map +1 -0
- package/dist/lib/activity_types.js +164 -0
- package/dist/lib/activity_types.js.map +1 -0
- package/dist/lib/brand.js +63 -0
- package/dist/lib/brand.js.map +1 -0
- package/dist/lib/clock.js +24 -0
- package/dist/lib/clock.js.map +1 -0
- package/dist/lib/coach_session.js +345 -0
- package/dist/lib/coach_session.js.map +1 -0
- package/dist/lib/concurrency.js.map +1 -1
- package/dist/lib/dates.js +19 -0
- package/dist/lib/dates.js.map +1 -1
- package/dist/lib/env_file.js +195 -0
- package/dist/lib/env_file.js.map +1 -0
- package/dist/lib/health_plans_write.js +44 -0
- package/dist/lib/health_plans_write.js.map +1 -0
- package/dist/lib/heart_rate.js +34 -0
- package/dist/lib/heart_rate.js.map +1 -0
- package/dist/lib/highlight.js +81 -0
- package/dist/lib/highlight.js.map +1 -0
- package/dist/lib/install_links.js +47 -0
- package/dist/lib/install_links.js.map +1 -0
- package/dist/lib/instant.js +50 -0
- package/dist/lib/instant.js.map +1 -0
- package/dist/lib/journal_behaviors.js +382 -0
- package/dist/lib/journal_behaviors.js.map +1 -0
- package/dist/lib/lift_catalog.js +218 -0
- package/dist/lib/lift_catalog.js.map +1 -0
- package/dist/lib/lift_history.js +66 -0
- package/dist/lib/lift_history.js.map +1 -0
- package/dist/lib/lift_sets.js +146 -0
- package/dist/lib/lift_sets.js.map +1 -0
- package/dist/lib/lift_tool.js +20 -0
- package/dist/lib/lift_tool.js.map +1 -0
- package/dist/lib/profile_settings.js +101 -0
- package/dist/lib/profile_settings.js.map +1 -0
- package/dist/lib/screen_content.js +44 -0
- package/dist/lib/screen_content.js.map +1 -0
- package/dist/lib/timezone.js +48 -6
- package/dist/lib/timezone.js.map +1 -1
- package/dist/lib/walk.js +6 -1
- package/dist/lib/walk.js.map +1 -1
- package/dist/lib/weight_readings.js +61 -0
- package/dist/lib/weight_readings.js.map +1 -0
- package/dist/projections/activities.js +193 -0
- package/dist/projections/activities.js.map +1 -0
- package/dist/projections/alarm_schedule.js +102 -0
- package/dist/projections/alarm_schedule.js.map +1 -0
- package/dist/projections/coach.js +203 -0
- package/dist/projections/coach.js.map +1 -0
- package/dist/projections/community.js +165 -0
- package/dist/projections/community.js.map +1 -0
- package/dist/projections/health_features.js +167 -0
- package/dist/projections/health_features.js.map +1 -0
- package/dist/projections/hormonal_insights.js +239 -0
- package/dist/projections/hormonal_insights.js.map +1 -0
- package/dist/projections/journal_v2.js +157 -0
- package/dist/projections/journal_v2.js.map +1 -0
- package/dist/projections/lift_cards.js +115 -0
- package/dist/projections/lift_cards.js.map +1 -0
- package/dist/projections/lift_exercise_v2.js +131 -0
- package/dist/projections/lift_exercise_v2.js.map +1 -0
- package/dist/projections/lift_library_v2.js +67 -0
- package/dist/projections/lift_library_v2.js.map +1 -0
- package/dist/projections/lift_sessions.js +211 -0
- package/dist/projections/lift_sessions.js.map +1 -0
- package/dist/projections/memory.js +95 -0
- package/dist/projections/memory.js.map +1 -0
- package/dist/projections/milestones.js +119 -0
- package/dist/projections/milestones.js.map +1 -0
- package/dist/projections/profile_v2.js +150 -0
- package/dist/projections/profile_v2.js.map +1 -0
- package/dist/projections/settings_v2.js +153 -0
- package/dist/projections/settings_v2.js.map +1 -0
- package/dist/projections/sleep.js +4 -21
- package/dist/projections/sleep.js.map +1 -1
- package/dist/projections/v2/calendar.js +43 -0
- package/dist/projections/v2/calendar.js.map +1 -0
- package/dist/projections/v2/core_common.js +86 -0
- package/dist/projections/v2/core_common.js.map +1 -0
- package/dist/projections/v2/core_home.js +136 -0
- package/dist/projections/v2/core_home.js.map +1 -0
- package/dist/projections/v2/core_sleep_need.js +23 -0
- package/dist/projections/v2/core_sleep_need.js.map +1 -0
- package/dist/projections/v2/day.js +92 -0
- package/dist/projections/v2/day.js.map +1 -0
- package/dist/projections/v2/heart_rate.js +54 -0
- package/dist/projections/v2/heart_rate.js.map +1 -0
- package/dist/projections/v2/history.js +140 -0
- package/dist/projections/v2/history.js.map +1 -0
- package/dist/projections/v2/now.js +39 -0
- package/dist/projections/v2/now.js.map +1 -0
- package/dist/projections/v2/recovery.js +77 -0
- package/dist/projections/v2/recovery.js.map +1 -0
- package/dist/projections/v2/sleep.js +218 -0
- package/dist/projections/v2/sleep.js.map +1 -0
- package/dist/projections/v2/strain.js +39 -0
- package/dist/projections/v2/strain.js.map +1 -0
- package/dist/projections/v2/stress.js +92 -0
- package/dist/projections/v2/stress.js.map +1 -0
- package/dist/projections/v2/trend.js +205 -0
- package/dist/projections/v2/trend.js.map +1 -0
- package/dist/projections/weekly_plan.js +66 -0
- package/dist/projections/weekly_plan.js.map +1 -0
- package/dist/projections/weight_readings.js +57 -0
- package/dist/projections/weight_readings.js.map +1 -0
- package/dist/projections/workout.js +37 -15
- package/dist/projections/workout.js.map +1 -1
- package/dist/schemas/activities.js +123 -0
- package/dist/schemas/activities.js.map +1 -0
- package/dist/schemas/alarm_schedule.js +62 -0
- package/dist/schemas/alarm_schedule.js.map +1 -0
- package/dist/schemas/coach.js +76 -8
- package/dist/schemas/coach.js.map +1 -1
- package/dist/schemas/community.js +70 -0
- package/dist/schemas/community.js.map +1 -0
- package/dist/schemas/health.js +36 -0
- package/dist/schemas/health.js.map +1 -0
- package/dist/schemas/hormonal_insights.js +90 -0
- package/dist/schemas/hormonal_insights.js.map +1 -0
- package/dist/schemas/journal.js +4 -0
- package/dist/schemas/journal.js.map +1 -1
- package/dist/schemas/journal_v2.js +106 -0
- package/dist/schemas/journal_v2.js.map +1 -0
- package/dist/schemas/memory.js +42 -0
- package/dist/schemas/memory.js.map +1 -0
- package/dist/schemas/milestones.js +39 -0
- package/dist/schemas/milestones.js.map +1 -0
- package/dist/schemas/profile_v2.js +60 -0
- package/dist/schemas/profile_v2.js.map +1 -0
- package/dist/schemas/settings_v2.js +56 -0
- package/dist/schemas/settings_v2.js.map +1 -0
- package/dist/schemas/sleep.js +8 -1
- package/dist/schemas/sleep.js.map +1 -1
- package/dist/schemas/strength.js +10 -1
- package/dist/schemas/strength.js.map +1 -1
- package/dist/schemas/strength_v2.js +190 -0
- package/dist/schemas/strength_v2.js.map +1 -0
- package/dist/schemas/v2/calendar.js +8 -0
- package/dist/schemas/v2/calendar.js.map +1 -0
- package/dist/schemas/v2/core_common.js +42 -0
- package/dist/schemas/v2/core_common.js.map +1 -0
- package/dist/schemas/v2/day.js +73 -0
- package/dist/schemas/v2/day.js.map +1 -0
- package/dist/schemas/v2/now.js +25 -0
- package/dist/schemas/v2/now.js.map +1 -0
- package/dist/schemas/v2/recovery.js +35 -0
- package/dist/schemas/v2/recovery.js.map +1 -0
- package/dist/schemas/v2/sleep.js +44 -0
- package/dist/schemas/v2/sleep.js.map +1 -0
- package/dist/schemas/v2/strain.js +16 -0
- package/dist/schemas/v2/strain.js.map +1 -0
- package/dist/schemas/v2/stress.js +20 -0
- package/dist/schemas/v2/stress.js.map +1 -0
- package/dist/schemas/v2/trend.js +42 -0
- package/dist/schemas/v2/trend.js.map +1 -0
- package/dist/schemas/weekly_plan.js +31 -0
- package/dist/schemas/weekly_plan.js.map +1 -0
- package/dist/schemas/weight.js +28 -0
- package/dist/schemas/weight.js.map +1 -0
- package/dist/scripts/build_behaviors.js +114 -0
- package/dist/scripts/build_behaviors.js.map +1 -0
- package/dist/scripts/cognito_bootstrap.js +9 -277
- package/dist/scripts/cognito_bootstrap.js.map +1 -1
- package/dist/scripts/gen_activity_catalogs.js +104 -0
- package/dist/scripts/gen_activity_catalogs.js.map +1 -0
- package/dist/server-admin.js +156 -0
- package/dist/server-admin.js.map +1 -0
- package/dist/server-http.js +270 -48
- package/dist/server-http.js.map +1 -1
- package/dist/server.js +136 -23
- package/dist/server.js.map +1 -1
- package/dist/tools/annotations.js +15 -0
- package/dist/tools/annotations.js.map +1 -0
- package/dist/tools/define.js +31 -0
- package/dist/tools/define.js.map +1 -0
- package/dist/tools/register.js +59 -94
- package/dist/tools/register.js.map +1 -1
- package/dist/tools/resources.js +70 -0
- package/dist/tools/resources.js.map +1 -0
- package/dist/tools/slim_schema.js +90 -0
- package/dist/tools/slim_schema.js.map +1 -0
- package/dist/tools/v2/activity_delete.js +63 -17
- package/dist/tools/v2/activity_delete.js.map +1 -1
- package/dist/tools/v2/activity_edit.js +396 -0
- package/dist/tools/v2/activity_edit.js.map +1 -0
- package/dist/tools/v2/activity_log.js +152 -0
- package/dist/tools/v2/activity_log.js.map +1 -0
- package/dist/tools/v2/calendar.js +19 -21
- package/dist/tools/v2/calendar.js.map +1 -1
- package/dist/tools/v2/coach_ask.js +74 -110
- package/dist/tools/v2/coach_ask.js.map +1 -1
- package/dist/tools/v2/coach_history.js +120 -0
- package/dist/tools/v2/coach_history.js.map +1 -0
- package/dist/tools/v2/community.js +124 -0
- package/dist/tools/v2/community.js.map +1 -0
- package/dist/tools/v2/cycle.js +63 -15
- package/dist/tools/v2/cycle.js.map +1 -1
- package/dist/tools/v2/cycle_log.js +289 -32
- package/dist/tools/v2/cycle_log.js.map +1 -1
- package/dist/tools/v2/day.js +126 -24
- package/dist/tools/v2/day.js.map +1 -1
- package/dist/tools/v2/health.js +116 -0
- package/dist/tools/v2/health.js.map +1 -0
- package/dist/tools/v2/hr_zones_set.js +134 -34
- package/dist/tools/v2/hr_zones_set.js.map +1 -1
- package/dist/tools/v2/journal.js +75 -17
- package/dist/tools/v2/journal.js.map +1 -1
- package/dist/tools/v2/journal_log.js +306 -65
- package/dist/tools/v2/journal_log.js.map +1 -1
- package/dist/tools/v2/lift_exercise.js +125 -22
- package/dist/tools/v2/lift_exercise.js.map +1 -1
- package/dist/tools/v2/lift_exercise_set.js +291 -0
- package/dist/tools/v2/lift_exercise_set.js.map +1 -0
- package/dist/tools/v2/lift_library.js +51 -12
- package/dist/tools/v2/lift_library.js.map +1 -1
- package/dist/tools/v2/lift_log.js +309 -72
- package/dist/tools/v2/lift_log.js.map +1 -1
- package/dist/tools/v2/lift_sessions.js +248 -0
- package/dist/tools/v2/lift_sessions.js.map +1 -0
- package/dist/tools/v2/lift_template.js +232 -0
- package/dist/tools/v2/lift_template.js.map +1 -0
- package/dist/tools/v2/memory.js +45 -0
- package/dist/tools/v2/memory.js.map +1 -0
- package/dist/tools/v2/memory_set.js +107 -0
- package/dist/tools/v2/memory_set.js.map +1 -0
- package/dist/tools/v2/milestones.js +50 -0
- package/dist/tools/v2/milestones.js.map +1 -0
- package/dist/tools/v2/now.js +49 -0
- package/dist/tools/v2/now.js.map +1 -0
- package/dist/tools/v2/preferences.js +51 -0
- package/dist/tools/v2/preferences.js.map +1 -0
- package/dist/tools/v2/preferences_set.js +388 -0
- package/dist/tools/v2/preferences_set.js.map +1 -0
- package/dist/tools/v2/profile.js +54 -22
- package/dist/tools/v2/profile.js.map +1 -1
- package/dist/tools/v2/profile_update.js +167 -55
- package/dist/tools/v2/profile_update.js.map +1 -1
- package/dist/tools/v2/raw.js +91 -34
- package/dist/tools/v2/raw.js.map +1 -1
- package/dist/tools/v2/recovery.js +37 -23
- package/dist/tools/v2/recovery.js.map +1 -1
- package/dist/tools/v2/sleep.js +52 -16
- package/dist/tools/v2/sleep.js.map +1 -1
- package/dist/tools/v2/smart_alarm.js +54 -20
- package/dist/tools/v2/smart_alarm.js.map +1 -1
- package/dist/tools/v2/smart_alarm_set.js +264 -86
- package/dist/tools/v2/smart_alarm_set.js.map +1 -1
- package/dist/tools/v2/strain.js +15 -15
- package/dist/tools/v2/strain.js.map +1 -1
- package/dist/tools/v2/stress.js +17 -15
- package/dist/tools/v2/stress.js.map +1 -1
- package/dist/tools/v2/trend.js +56 -20
- package/dist/tools/v2/trend.js.map +1 -1
- package/dist/tools/v2/weekly_plan.js +30 -0
- package/dist/tools/v2/weekly_plan.js.map +1 -0
- package/dist/tools/v2/weekly_plan_set.js +134 -0
- package/dist/tools/v2/weekly_plan_set.js.map +1 -0
- package/dist/tools/v2/weight.js +56 -0
- package/dist/tools/v2/weight.js.map +1 -0
- package/dist/tools/v2/weight_log.js +188 -0
- package/dist/tools/v2/weight_log.js.map +1 -0
- package/dist/tools/v2/workouts.js +159 -25
- package/dist/tools/v2/workouts.js.map +1 -1
- package/dist/version.js +6 -0
- package/dist/version.js.map +1 -0
- package/dist/whoop/bff.js +94 -0
- package/dist/whoop/bff.js.map +1 -0
- package/dist/whoop/client.js +392 -18
- package/dist/whoop/client.js.map +1 -1
- package/dist/whoop/cognito.js +106 -79
- package/dist/whoop/cognito.js.map +1 -1
- package/dist/whoop/connect_page.js +165 -0
- package/dist/whoop/connect_page.js.map +1 -0
- package/dist/whoop/consent_font.js +287 -0
- package/dist/whoop/consent_font.js.map +1 -0
- package/dist/whoop/consent_logos.js +22 -0
- package/dist/whoop/consent_logos.js.map +1 -0
- package/dist/whoop/consent_page.js +291 -0
- package/dist/whoop/consent_page.js.map +1 -0
- package/dist/whoop/constants.js +5 -1
- package/dist/whoop/constants.js.map +1 -1
- package/dist/whoop/device.js +4 -4
- package/dist/whoop/device.js.map +1 -1
- package/dist/whoop/errors.js +85 -4
- package/dist/whoop/errors.js.map +1 -1
- package/dist/whoop/init_timezone.js +57 -17
- package/dist/whoop/init_timezone.js.map +1 -1
- package/dist/whoop/installation.js +15 -10
- package/dist/whoop/installation.js.map +1 -1
- package/dist/whoop/json_out.js +52 -6
- package/dist/whoop/json_out.js.map +1 -1
- package/dist/whoop/oauth_provider.js +81 -78
- package/dist/whoop/oauth_provider.js.map +1 -1
- package/dist/whoop/token_lock.js +331 -0
- package/dist/whoop/token_lock.js.map +1 -0
- package/dist/whoop/token_manager.js +536 -42
- package/dist/whoop/token_manager.js.map +1 -1
- package/dist/whoop/token_store.js +303 -36
- package/dist/whoop/token_store.js.map +1 -1
- package/dist/whoop/units.js +28 -0
- package/dist/whoop/units.js.map +1 -0
- package/package.json +29 -13
- package/scripts/build-mcpb.mjs +72 -0
- package/scripts/embed-consent-font.mjs +34 -0
- package/scripts/readme-media.ts +195 -0
- package/scripts/tools-md.ts +89 -0
- package/scripts/whoop-md.ts +119 -0
- package/src/build_info.ts +4 -0
- package/src/cli/app.ts +696 -0
- package/src/cli/auth.ts +350 -0
- package/src/cli/auth_flow.ts +356 -0
- package/src/cli/browser_login.ts +402 -0
- package/src/cli/clients.ts +467 -0
- package/src/cli/deploy_record.ts +100 -0
- package/src/cli/index.ts +41 -583
- package/src/cli/links.ts +43 -0
- package/src/cli/logo.ts +64 -0
- package/src/cli/setup.ts +1147 -979
- package/src/cli/spawn.ts +88 -0
- package/src/cli/sys.ts +267 -0
- package/src/cli/ui.ts +778 -436
- package/src/cli/update.ts +436 -274
- package/src/cloudflare/runtime.d.ts +27 -0
- package/src/cloudflare/token_store.ts +57 -0
- package/src/cloudflare/worker.ts +174 -0
- package/src/data/behaviors.ts +2760 -622
- package/src/data/endpoint_catalog.ts +2695 -0
- package/src/data/exercises.ts +379 -4861
- package/src/data/garments.ts +28 -0
- package/src/data/sports.ts +239 -211
- package/src/lib/activity_list.ts +150 -0
- package/src/lib/activity_records.ts +213 -0
- package/src/lib/activity_results.ts +51 -0
- package/src/lib/activity_types.ts +176 -0
- package/src/lib/brand.ts +71 -0
- package/src/lib/clock.ts +16 -0
- package/src/lib/coach_session.ts +434 -0
- package/src/lib/dates.ts +18 -0
- package/src/lib/env_file.ts +191 -0
- package/src/lib/health_plans_write.ts +53 -0
- package/src/lib/heart_rate.ts +42 -0
- package/src/lib/highlight.ts +71 -0
- package/src/lib/install_links.ts +61 -0
- package/src/lib/instant.ts +54 -0
- package/src/lib/journal_behaviors.ts +453 -0
- package/src/lib/lift_catalog.ts +258 -0
- package/src/lib/lift_history.ts +75 -0
- package/src/lib/lift_sets.ts +164 -0
- package/src/lib/lift_tool.ts +25 -0
- package/src/lib/profile_settings.ts +102 -0
- package/src/lib/screen_content.ts +40 -0
- package/src/lib/timezone.ts +44 -8
- package/src/lib/walk.ts +4 -1
- package/src/lib/weight_readings.ts +82 -0
- package/src/projections/activities.ts +199 -0
- package/src/projections/alarm_schedule.ts +98 -0
- package/src/projections/coach.ts +218 -0
- package/src/projections/community.ts +187 -0
- package/src/projections/health_features.ts +191 -0
- package/src/projections/hormonal_insights.ts +277 -0
- package/src/projections/journal_v2.ts +173 -0
- package/src/projections/lift_cards.ts +131 -0
- package/src/projections/lift_exercise_v2.ts +147 -0
- package/src/projections/lift_library_v2.ts +77 -0
- package/src/projections/lift_sessions.ts +250 -0
- package/src/projections/memory.ts +100 -0
- package/src/projections/milestones.ts +133 -0
- package/src/projections/profile_v2.ts +166 -0
- package/src/projections/settings_v2.ts +179 -0
- package/src/projections/sleep.ts +7 -21
- package/src/projections/v2/calendar.ts +48 -0
- package/src/projections/v2/core_common.ts +95 -0
- package/src/projections/v2/core_home.ts +177 -0
- package/src/projections/v2/core_sleep_need.ts +37 -0
- package/src/projections/v2/day.ts +162 -0
- package/src/projections/v2/heart_rate.ts +73 -0
- package/src/projections/v2/history.ts +153 -0
- package/src/projections/v2/now.ts +59 -0
- package/src/projections/v2/recovery.ts +120 -0
- package/src/projections/v2/sleep.ts +281 -0
- package/src/projections/v2/strain.ts +63 -0
- package/src/projections/v2/stress.ts +111 -0
- package/src/projections/v2/trend.ts +242 -0
- package/src/projections/weekly_plan.ts +79 -0
- package/src/projections/weight_readings.ts +57 -0
- package/src/projections/workout.ts +36 -17
- package/src/schemas/activities.ts +136 -0
- package/src/schemas/alarm_schedule.ts +70 -0
- package/src/schemas/coach.ts +98 -8
- package/src/schemas/community.ts +77 -0
- package/src/schemas/health.ts +36 -0
- package/src/schemas/hormonal_insights.ts +108 -0
- package/src/schemas/journal.ts +4 -0
- package/src/schemas/journal_v2.ts +112 -0
- package/src/schemas/memory.ts +48 -0
- package/src/schemas/milestones.ts +48 -0
- package/src/schemas/profile_v2.ts +63 -0
- package/src/schemas/settings_v2.ts +63 -0
- package/src/schemas/sleep.ts +9 -1
- package/src/schemas/strength.ts +10 -1
- package/src/schemas/strength_v2.ts +210 -0
- package/src/schemas/v2/calendar.ts +8 -0
- package/src/schemas/v2/core_common.ts +50 -0
- package/src/schemas/v2/day.ts +79 -0
- package/src/schemas/v2/now.ts +25 -0
- package/src/schemas/v2/recovery.ts +38 -0
- package/src/schemas/v2/sleep.ts +46 -0
- package/src/schemas/v2/strain.ts +16 -0
- package/src/schemas/v2/stress.ts +20 -0
- package/src/schemas/v2/trend.ts +45 -0
- package/src/schemas/weekly_plan.ts +36 -0
- package/src/schemas/weight.ts +53 -0
- package/src/scripts/build_behaviors.ts +116 -0
- package/src/scripts/cognito_bootstrap.ts +10 -249
- package/src/scripts/gen_activity_catalogs.ts +121 -0
- package/src/server-admin.ts +171 -0
- package/src/server-http.ts +290 -53
- package/src/server.ts +130 -26
- package/src/tools/annotations.ts +25 -0
- package/src/tools/define.ts +53 -0
- package/src/tools/register.ts +64 -94
- package/src/tools/resources.ts +92 -0
- package/src/tools/slim_schema.ts +102 -0
- package/src/tools/v2/activity_delete.ts +61 -23
- package/src/tools/v2/activity_edit.ts +378 -0
- package/src/tools/v2/activity_log.ts +154 -0
- package/src/tools/v2/calendar.ts +22 -21
- package/src/tools/v2/coach_ask.ts +83 -119
- package/src/tools/v2/coach_history.ts +140 -0
- package/src/tools/v2/community.ts +137 -0
- package/src/tools/v2/cycle.ts +78 -20
- package/src/tools/v2/cycle_log.ts +291 -40
- package/src/tools/v2/day.ts +126 -25
- package/src/tools/v2/health.ts +114 -0
- package/src/tools/v2/hr_zones_set.ts +132 -45
- package/src/tools/v2/journal.ts +78 -23
- package/src/tools/v2/journal_log.ts +321 -69
- package/src/tools/v2/lift_exercise.ts +135 -27
- package/src/tools/v2/lift_exercise_set.ts +272 -0
- package/src/tools/v2/lift_library.ts +57 -21
- package/src/tools/v2/lift_log.ts +325 -83
- package/src/tools/v2/lift_sessions.ts +255 -0
- package/src/tools/v2/lift_template.ts +229 -0
- package/src/tools/v2/memory.ts +54 -0
- package/src/tools/v2/memory_set.ts +110 -0
- package/src/tools/v2/milestones.ts +59 -0
- package/src/tools/v2/now.ts +61 -0
- package/src/tools/v2/preferences.ts +61 -0
- package/src/tools/v2/preferences_set.ts +403 -0
- package/src/tools/v2/profile.ts +56 -26
- package/src/tools/v2/profile_update.ts +151 -60
- package/src/tools/v2/raw.ts +89 -36
- package/src/tools/v2/recovery.ts +44 -25
- package/src/tools/v2/sleep.ts +57 -18
- package/src/tools/v2/smart_alarm.ts +62 -24
- package/src/tools/v2/smart_alarm_set.ts +240 -90
- package/src/tools/v2/strain.ts +19 -16
- package/src/tools/v2/stress.ts +22 -17
- package/src/tools/v2/trend.ts +58 -20
- package/src/tools/v2/weekly_plan.ts +38 -0
- package/src/tools/v2/weekly_plan_set.ts +132 -0
- package/src/tools/v2/weight.ts +61 -0
- package/src/tools/v2/weight_log.ts +193 -0
- package/src/tools/v2/workouts.ts +156 -26
- package/src/version.ts +5 -0
- package/src/whoop/bff.ts +84 -0
- package/src/whoop/client.ts +448 -18
- package/src/whoop/cognito.ts +110 -99
- package/src/whoop/connect_page.ts +183 -0
- package/src/whoop/consent_font.ts +289 -0
- package/src/whoop/consent_logos.ts +24 -0
- package/src/whoop/consent_page.ts +326 -0
- package/src/whoop/constants.ts +5 -1
- package/src/whoop/device.ts +4 -4
- package/src/whoop/errors.ts +89 -4
- package/src/whoop/init_timezone.ts +57 -16
- package/src/whoop/installation.ts +16 -7
- package/src/whoop/json_out.ts +51 -6
- package/src/whoop/oauth_provider.ts +84 -91
- package/src/whoop/token_lock.ts +345 -0
- package/src/whoop/token_manager.ts +580 -53
- package/src/whoop/token_store.ts +341 -32
- package/src/whoop/units.ts +35 -0
- package/wrangler.jsonc +17 -0
- package/assets/banner.svg +0 -38
- package/dist/data/endpoints.js +0 -320
- package/dist/data/endpoints.js.map +0 -1
- package/dist/lib/format.js +0 -22
- package/dist/lib/format.js.map +0 -1
- package/dist/lib/stats.js +0 -32
- package/dist/lib/stats.js.map +0 -1
- package/dist/projections/calendar.js +0 -33
- package/dist/projections/calendar.js.map +0 -1
- package/dist/projections/communities.js +0 -105
- package/dist/projections/communities.js.map +0 -1
- package/dist/projections/cycle.js +0 -81
- package/dist/projections/cycle.js.map +0 -1
- package/dist/projections/hr_zones.js +0 -35
- package/dist/projections/hr_zones.js.map +0 -1
- package/dist/projections/journal.js +0 -56
- package/dist/projections/journal.js.map +0 -1
- package/dist/projections/leaderboard.js +0 -37
- package/dist/projections/leaderboard.js.map +0 -1
- package/dist/projections/lift_exercise.js +0 -22
- package/dist/projections/lift_exercise.js.map +0 -1
- package/dist/projections/lift_history.js +0 -133
- package/dist/projections/lift_history.js.map +0 -1
- package/dist/projections/lift_library.js +0 -71
- package/dist/projections/lift_library.js.map +0 -1
- package/dist/projections/lift_progression.js +0 -138
- package/dist/projections/lift_progression.js.map +0 -1
- package/dist/projections/lift_prs.js +0 -20
- package/dist/projections/lift_prs.js.map +0 -1
- package/dist/projections/live_hr.js +0 -19
- package/dist/projections/live_hr.js.map +0 -1
- package/dist/projections/live_state.js +0 -23
- package/dist/projections/live_state.js.map +0 -1
- package/dist/projections/live_stress.js +0 -11
- package/dist/projections/live_stress.js.map +0 -1
- package/dist/projections/performance_assessment.js +0 -15
- package/dist/projections/performance_assessment.js.map +0 -1
- package/dist/projections/profile.js +0 -59
- package/dist/projections/profile.js.map +0 -1
- package/dist/projections/recovery.js +0 -131
- package/dist/projections/recovery.js.map +0 -1
- package/dist/projections/sleep_need.js +0 -32
- package/dist/projections/sleep_need.js.map +0 -1
- package/dist/projections/smart_alarm.js +0 -45
- package/dist/projections/smart_alarm.js.map +0 -1
- package/dist/projections/strain.js +0 -128
- package/dist/projections/strain.js.map +0 -1
- package/dist/projections/stress.js +0 -86
- package/dist/projections/stress.js.map +0 -1
- package/dist/projections/today.js +0 -129
- package/dist/projections/today.js.map +0 -1
- package/dist/projections/trend.js +0 -149
- package/dist/projections/trend.js.map +0 -1
- package/dist/projections/workouts.js +0 -37
- package/dist/projections/workouts.js.map +0 -1
- package/dist/schemas/calendar.js +0 -12
- package/dist/schemas/calendar.js.map +0 -1
- package/dist/schemas/communities.js +0 -51
- package/dist/schemas/communities.js.map +0 -1
- package/dist/schemas/compare.js +0 -15
- package/dist/schemas/compare.js.map +0 -1
- package/dist/schemas/leaderboard.js +0 -25
- package/dist/schemas/leaderboard.js.map +0 -1
- package/dist/schemas/live.js +0 -26
- package/dist/schemas/live.js.map +0 -1
- package/dist/schemas/performance.js +0 -12
- package/dist/schemas/performance.js.map +0 -1
- package/dist/schemas/profile.js +0 -39
- package/dist/schemas/profile.js.map +0 -1
- package/dist/schemas/recovery.js +0 -27
- package/dist/schemas/recovery.js.map +0 -1
- package/dist/schemas/settings.js +0 -26
- package/dist/schemas/settings.js.map +0 -1
- package/dist/schemas/sleep_need.js +0 -15
- package/dist/schemas/sleep_need.js.map +0 -1
- package/dist/schemas/smart_alarm.js +0 -36
- package/dist/schemas/smart_alarm.js.map +0 -1
- package/dist/schemas/strain.js +0 -24
- package/dist/schemas/strain.js.map +0 -1
- package/dist/schemas/stress.js +0 -16
- package/dist/schemas/stress.js.map +0 -1
- package/dist/schemas/today.js +0 -38
- package/dist/schemas/today.js.map +0 -1
- package/dist/schemas/trend.js +0 -50
- package/dist/schemas/trend.js.map +0 -1
- package/dist/schemas/womens_health.js +0 -23
- package/dist/schemas/womens_health.js.map +0 -1
- package/dist/tools/v2/activity_create.js +0 -64
- package/dist/tools/v2/activity_create.js.map +0 -1
- package/dist/tools/v2/behavior_impact.js +0 -36
- package/dist/tools/v2/behavior_impact.js.map +0 -1
- package/dist/tools/v2/communities.js +0 -60
- package/dist/tools/v2/communities.js.map +0 -1
- package/dist/tools/v2/compare.js +0 -67
- package/dist/tools/v2/compare.js.map +0 -1
- package/dist/tools/v2/endpoints.js +0 -28
- package/dist/tools/v2/endpoints.js.map +0 -1
- package/dist/tools/v2/hidden_metric.js +0 -28
- package/dist/tools/v2/hidden_metric.js.map +0 -1
- package/dist/tools/v2/hr_zones.js +0 -24
- package/dist/tools/v2/hr_zones.js.map +0 -1
- package/dist/tools/v2/journal_autopop.js +0 -19
- package/dist/tools/v2/journal_autopop.js.map +0 -1
- package/dist/tools/v2/journal_catalog.js +0 -44
- package/dist/tools/v2/journal_catalog.js.map +0 -1
- package/dist/tools/v2/leaderboard.js +0 -79
- package/dist/tools/v2/leaderboard.js.map +0 -1
- package/dist/tools/v2/lift_catalog.js +0 -47
- package/dist/tools/v2/lift_catalog.js.map +0 -1
- package/dist/tools/v2/lift_custom_exercise.js +0 -108
- package/dist/tools/v2/lift_custom_exercise.js.map +0 -1
- package/dist/tools/v2/lift_history.js +0 -39
- package/dist/tools/v2/lift_history.js.map +0 -1
- package/dist/tools/v2/lift_progression.js +0 -30
- package/dist/tools/v2/lift_progression.js.map +0 -1
- package/dist/tools/v2/lift_prs.js +0 -21
- package/dist/tools/v2/lift_prs.js.map +0 -1
- package/dist/tools/v2/lift_template_save.js +0 -83
- package/dist/tools/v2/lift_template_save.js.map +0 -1
- package/dist/tools/v2/live_hr.js +0 -21
- package/dist/tools/v2/live_hr.js.map +0 -1
- package/dist/tools/v2/live_state.js +0 -21
- package/dist/tools/v2/live_state.js.map +0 -1
- package/dist/tools/v2/live_stress.js +0 -22
- package/dist/tools/v2/live_stress.js.map +0 -1
- package/dist/tools/v2/performance_assessment.js +0 -38
- package/dist/tools/v2/performance_assessment.js.map +0 -1
- package/dist/tools/v2/sleep_need.js +0 -21
- package/dist/tools/v2/sleep_need.js.map +0 -1
- package/dist/tools/v2/sports_catalog.js +0 -26
- package/dist/tools/v2/sports_catalog.js.map +0 -1
- package/dist/tools/v2/symptom_log.js +0 -72
- package/dist/tools/v2/symptom_log.js.map +0 -1
- package/dist/tools/v2/today.js +0 -30
- package/dist/tools/v2/today.js.map +0 -1
- package/dist/tools/v2/workout.js +0 -23
- package/dist/tools/v2/workout.js.map +0 -1
- package/dist/whoop/build_lift_body.js +0 -67
- package/dist/whoop/build_lift_body.js.map +0 -1
- package/dist/whoop/session_state.js +0 -34
- package/dist/whoop/session_state.js.map +0 -1
- package/dist/whoop/types.js +0 -82
- package/dist/whoop/types.js.map +0 -1
- package/src/data/endpoints.ts +0 -319
- package/src/lib/format.ts +0 -27
- package/src/lib/stats.ts +0 -35
- package/src/projections/calendar.ts +0 -46
- package/src/projections/communities.ts +0 -135
- package/src/projections/cycle.ts +0 -85
- package/src/projections/hr_zones.ts +0 -43
- package/src/projections/journal.ts +0 -55
- package/src/projections/leaderboard.ts +0 -49
- package/src/projections/lift_exercise.ts +0 -29
- package/src/projections/lift_history.ts +0 -140
- package/src/projections/lift_library.ts +0 -70
- package/src/projections/lift_progression.ts +0 -138
- package/src/projections/lift_prs.ts +0 -23
- package/src/projections/live_hr.ts +0 -21
- package/src/projections/live_state.ts +0 -28
- package/src/projections/live_stress.ts +0 -13
- package/src/projections/performance_assessment.ts +0 -19
- package/src/projections/profile.ts +0 -71
- package/src/projections/recovery.ts +0 -133
- package/src/projections/sleep_need.ts +0 -36
- package/src/projections/smart_alarm.ts +0 -70
- package/src/projections/strain.ts +0 -131
- package/src/projections/stress.ts +0 -95
- package/src/projections/today.ts +0 -166
- package/src/projections/trend.ts +0 -149
- package/src/projections/workouts.ts +0 -36
- package/src/schemas/calendar.ts +0 -13
- package/src/schemas/communities.ts +0 -56
- package/src/schemas/compare.ts +0 -17
- package/src/schemas/leaderboard.ts +0 -26
- package/src/schemas/live.ts +0 -31
- package/src/schemas/performance.ts +0 -13
- package/src/schemas/profile.ts +0 -40
- package/src/schemas/recovery.ts +0 -28
- package/src/schemas/settings.ts +0 -30
- package/src/schemas/sleep_need.ts +0 -16
- package/src/schemas/smart_alarm.ts +0 -40
- package/src/schemas/strain.ts +0 -25
- package/src/schemas/stress.ts +0 -17
- package/src/schemas/today.ts +0 -39
- package/src/schemas/trend.ts +0 -53
- package/src/schemas/womens_health.ts +0 -26
- package/src/tools/v2/activity_create.ts +0 -74
- package/src/tools/v2/behavior_impact.ts +0 -39
- package/src/tools/v2/communities.ts +0 -65
- package/src/tools/v2/compare.ts +0 -83
- package/src/tools/v2/endpoints.ts +0 -32
- package/src/tools/v2/hidden_metric.ts +0 -33
- package/src/tools/v2/hr_zones.ts +0 -29
- package/src/tools/v2/journal_autopop.ts +0 -26
- package/src/tools/v2/journal_catalog.ts +0 -48
- package/src/tools/v2/leaderboard.ts +0 -92
- package/src/tools/v2/lift_catalog.ts +0 -48
- package/src/tools/v2/lift_custom_exercise.ts +0 -117
- package/src/tools/v2/lift_history.ts +0 -52
- package/src/tools/v2/lift_progression.ts +0 -34
- package/src/tools/v2/lift_prs.ts +0 -26
- package/src/tools/v2/lift_template_save.ts +0 -89
- package/src/tools/v2/live_hr.ts +0 -26
- package/src/tools/v2/live_state.ts +0 -26
- package/src/tools/v2/live_stress.ts +0 -27
- package/src/tools/v2/performance_assessment.ts +0 -44
- package/src/tools/v2/sleep_need.ts +0 -26
- package/src/tools/v2/sports_catalog.ts +0 -32
- package/src/tools/v2/symptom_log.ts +0 -78
- package/src/tools/v2/today.ts +0 -35
- package/src/tools/v2/workout.ts +0 -28
- package/src/whoop/build_lift_body.ts +0 -84
- package/src/whoop/session_state.ts +0 -41
- package/src/whoop/types.ts +0 -89
package/src/tools/v2/day.ts
CHANGED
|
@@ -1,37 +1,138 @@
|
|
|
1
|
+
// whoop_day (v2): replaces whoop_today, whoop_day and whoop_daily_brief.
|
|
2
|
+
//
|
|
3
|
+
// Three shapes behind one tool:
|
|
4
|
+
// - one cycle day (the default): the app's home screen and deep dives;
|
|
5
|
+
// - the same plus a heart-rate series (include hr, or a hr_from..hr_to window);
|
|
6
|
+
// - with end_date, a table of days from WHOOP's bulk cycle history.
|
|
1
7
|
import { z } from "zod";
|
|
2
8
|
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
9
|
import type { WhoopClient } from "../../whoop/client.js";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
10
|
+
import { defineTool, respond } from "../define.js";
|
|
11
|
+
import { READ_ONLY } from "../annotations.js";
|
|
12
|
+
import { isoDay, todayIso } from "../../lib/dates.js";
|
|
13
|
+
import { wallClockIso } from "../../lib/timezone.js";
|
|
14
|
+
import { daySpan } from "../../lib/activity_list.js";
|
|
15
|
+
import { MAX_HR_WINDOW_MS, accountUserId, hrStepFor, readHeartRate } from "../../lib/heart_rate.js";
|
|
16
|
+
import { DayOut, DayRangeOut } from "../../schemas/v2/day.js";
|
|
17
|
+
import { DAY_SECTIONS, projectDay, type DaySection } from "../../projections/v2/day.js";
|
|
18
|
+
import { activityTiles, type HomeCycle } from "../../projections/v2/core_home.js";
|
|
19
|
+
import { mainSleepTile } from "../../projections/v2/sleep.js";
|
|
20
|
+
import { projectSleepNeedV2 } from "../../projections/v2/core_sleep_need.js";
|
|
21
|
+
import { hrWindow } from "../../projections/v2/heart_rate.js";
|
|
22
|
+
import { projectHistory } from "../../projections/v2/history.js";
|
|
23
|
+
import { instantInput, toInstantOpt } from "../../lib/instant.js";
|
|
24
|
+
|
|
25
|
+
const NAME = "whoop_day";
|
|
26
|
+
const DEFAULT_SECTIONS: DaySection[] = ["scores", "sleep", "strain", "activities"];
|
|
27
|
+
/** WHOOP refuses windows over 200 days; 180 leaves room for DST and matches whoop_trend's six_month. */
|
|
28
|
+
const MAX_RANGE_DAYS = 180;
|
|
29
|
+
const DEFAULT_RANGE_DAYS = 30;
|
|
30
|
+
const CYCLES_PATH = "/core-details-bff/v0/cycles/details";
|
|
31
|
+
|
|
32
|
+
function shiftDay(day: string, delta: number): string {
|
|
33
|
+
return new Date(Date.parse(`${day}T00:00:00Z`) + delta * 86_400_000).toISOString().slice(0, 10);
|
|
34
|
+
}
|
|
35
|
+
const localMidnight = (day: string): number => Date.parse(wallClockIso(day, 0, 0));
|
|
36
|
+
|
|
37
|
+
/** The window `include: ["hr"]` reads: the cycle itself, else the calendar day; never past now, never over the cap. */
|
|
38
|
+
export function dayHrSpan(cycle: HomeCycle, day: string, now: number): [number, number] {
|
|
39
|
+
const cycleStart = cycle.start ? Date.parse(cycle.start) : NaN;
|
|
40
|
+
const start = Number.isFinite(cycleStart) ? cycleStart : localMidnight(day);
|
|
41
|
+
const cycleEnd = cycle.end ? Date.parse(cycle.end) : NaN;
|
|
42
|
+
// An open cycle has no end (or a predicted one in the future): read up to now.
|
|
43
|
+
const end = Math.min(Number.isFinite(cycleEnd) ? cycleEnd : Number.isFinite(cycleStart) ? now : localMidnight(shiftDay(day, 1)), now);
|
|
44
|
+
return [Math.max(start, end - MAX_HR_WINDOW_MS), end];
|
|
45
|
+
}
|
|
8
46
|
|
|
9
47
|
export function registerDay(server: McpServer, client: WhoopClient): void {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
"Composite snapshot for any past date: recovery, sleep + stages, day strain, workouts count. Same shape as whoop_today but current_state is always null (not relevant for historical days).",
|
|
48
|
+
defineTool(
|
|
49
|
+
server,
|
|
13
50
|
{
|
|
14
|
-
|
|
51
|
+
name: NAME,
|
|
52
|
+
description:
|
|
53
|
+
"One cycle day (default today): scores, main sleep, strain, calories, steps, activities and, today, the live state. sleep_plan " +
|
|
54
|
+
"is today only. hr: heart rate every 10 min, or a window via hr_from/hr_to (1-min steps up to 5 h, 6 s up to 30 min). " +
|
|
55
|
+
"end_date: a table of daily recovery, HRV, RHR, sleep, strain, calories and HR instead. Scores are null while calibrating. " +
|
|
56
|
+
"Never reuse the cycle id: sleep edits change it.",
|
|
57
|
+
input: {
|
|
58
|
+
date: z.iso.date().optional(),
|
|
59
|
+
end_date: z.iso.date().optional().describe("Table from date: default 30 days, max 180"),
|
|
60
|
+
include: z.array(z.enum(DAY_SECTIONS)).min(1).optional()
|
|
61
|
+
.describe("Default scores, sleep, strain, activities"),
|
|
62
|
+
hr_from: instantInput().optional().describe("With hr_to, max 48 h"),
|
|
63
|
+
hr_to: instantInput().optional(),
|
|
64
|
+
},
|
|
65
|
+
annotations: READ_ONLY,
|
|
15
66
|
},
|
|
16
|
-
async ({ date }) => {
|
|
17
|
-
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
67
|
+
async ({ date, end_date, include, hr_from: hrFromIn, hr_to: hrToIn }) => {
|
|
68
|
+
const hr_from = toInstantOpt(hrFromIn, "hr_from");
|
|
69
|
+
const hr_to = toInstantOpt(hrToIn, "hr_to");
|
|
70
|
+
const today = todayIso();
|
|
71
|
+
const now = Date.now();
|
|
72
|
+
|
|
73
|
+
if (end_date !== undefined) {
|
|
74
|
+
if (include || hr_from || hr_to) throw new Error("end_date returns the day table only: drop include, hr_from and hr_to, or drop end_date.");
|
|
75
|
+
const end = end_date > today ? today : end_date;
|
|
76
|
+
const start = date ?? shiftDay(end, 1 - DEFAULT_RANGE_DAYS);
|
|
77
|
+
if (start > end) throw new Error(`date ${start} is after end_date ${end_date}${end === end_date ? "" : " (today is the last day with data)"}.`);
|
|
78
|
+
const span = daySpan(start, end);
|
|
79
|
+
if (span > MAX_RANGE_DAYS) throw new Error(`The range is ${span} days; whoop_day reads at most ${MAX_RANGE_DAYS} per call. Split it.`);
|
|
80
|
+
const limit = span + 20;
|
|
81
|
+
const raw = await client.get(CYCLES_PATH, {
|
|
82
|
+
id: await accountUserId(client),
|
|
83
|
+
startTime: new Date(localMidnight(start)).toISOString(),
|
|
84
|
+
endTime: new Date(localMidnight(shiftDay(end, 1))).toISOString(),
|
|
85
|
+
limit,
|
|
86
|
+
});
|
|
87
|
+
const records = (raw as { records?: unknown })?.records;
|
|
88
|
+
const warnings = Array.isArray(records) && records.length >= limit
|
|
89
|
+
? ["WHOOP returned as many cycles as were asked for, so the oldest days may be missing. Ask for a shorter range."]
|
|
90
|
+
: [];
|
|
91
|
+
return respond(NAME, DayRangeOut, { start_date: start, end_date: end, ...projectHistory(raw, start, end), warnings });
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if ((hr_from === undefined) !== (hr_to === undefined)) throw new Error("hr_from and hr_to go together.");
|
|
95
|
+
const d = date ?? (hr_from ? isoDay(new Date(hr_from)) : today);
|
|
96
|
+
const isToday = d === today;
|
|
97
|
+
// A window on its own is a heart-rate question: answer it without the day's default sections.
|
|
98
|
+
const inc = new Set<DaySection>(include ?? (hr_from ? [] : DEFAULT_SECTIONS));
|
|
99
|
+
if (hr_from) inc.add("hr");
|
|
100
|
+
let explicit: [number, number] | undefined;
|
|
101
|
+
if (hr_from && hr_to) {
|
|
102
|
+
const from = Date.parse(hr_from);
|
|
103
|
+
const to = Math.min(Date.parse(hr_to), now);
|
|
104
|
+
if (!(from < to)) throw new Error(from >= now ? "hr_from is in the future." : "hr_from must be before hr_to.");
|
|
105
|
+
if (to - from > MAX_HR_WINDOW_MS) throw new Error("The heart-rate window is at most 48 hours. Split it, or use whoop_trend for longer spans.");
|
|
106
|
+
explicit = [from, to];
|
|
107
|
+
}
|
|
108
|
+
// Started now so it overlaps the day's own reads; awaited (and allowed to fail) below.
|
|
109
|
+
const explicitHr = explicit ? readHeartRate(client, explicit[0], explicit[1], hrStepFor(explicit[1] - explicit[0])) : undefined;
|
|
110
|
+
explicitHr?.catch(() => undefined);
|
|
111
|
+
|
|
112
|
+
const [home, recovery, strain, sleepNeed, userState] = await Promise.all([
|
|
113
|
+
client.get("/home-service/v1/home", { date: d }),
|
|
114
|
+
inc.has("scores") ? client.get("/home-service/v1/deep-dive/recovery", { date: d }).catch(() => null) : undefined,
|
|
115
|
+
inc.has("strain") ? client.get("/home-service/v1/deep-dive/strain", { date: d }).catch(() => null) : undefined,
|
|
116
|
+
// sleepneed 500s when Smart Alarm preferences are broken (SPEC.md §8): degrade to null.
|
|
117
|
+
inc.has("sleep_plan") && isToday
|
|
118
|
+
? client.get("/coaching-service/v2/sleepneed").then(projectSleepNeedV2).catch(() => null)
|
|
119
|
+
: undefined,
|
|
120
|
+
isToday ? client.get("/activities-service/v1/user-state").catch(() => null) : undefined,
|
|
26
121
|
]);
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
|
|
122
|
+
let sleepDetails: unknown;
|
|
123
|
+
if (inc.has("sleep")) {
|
|
124
|
+
const main = mainSleepTile(activityTiles(home));
|
|
125
|
+
if (main) sleepDetails = await client.get(`/core-details-bff/v2/sleep-details/${main.id}`).catch(() => null);
|
|
126
|
+
}
|
|
127
|
+
const projected = projectDay({ date: d, isToday, include: inc, home, recovery, strain, sleepDetails, sleepNeed, userState });
|
|
128
|
+
if (inc.has("hr")) {
|
|
129
|
+
// Asked for by name, so a failed read is an error here, not a silently missing section.
|
|
130
|
+
const [from, to] = explicit ?? dayHrSpan(projected.cycle, d, now);
|
|
131
|
+
if (!(from < to)) throw new Error(`${d} hasn't started yet, so there is no heart rate to read.`);
|
|
132
|
+
const step = hrStepFor(to - from);
|
|
133
|
+
projected.hr = hrWindow(await (explicitHr ?? readHeartRate(client, from, to, step)), from, to, step);
|
|
34
134
|
}
|
|
135
|
+
return respond(NAME, DayOut, projected);
|
|
35
136
|
},
|
|
36
137
|
);
|
|
37
138
|
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
// whoop_health (R, EXPERIMENTAL): Healthspan, blood pressure insights, AFib
|
|
2
|
+
// history and Advanced Labs. See src/projections/health_features.ts for the
|
|
3
|
+
// routes and what is and isn't verified. Read-only on purpose: the writes these
|
|
4
|
+
// features have (deleting AFib history, editing lab results) can't
|
|
5
|
+
// be tried without an account that has them, and some can't be undone.
|
|
6
|
+
import { z } from "zod";
|
|
7
|
+
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
8
|
+
import type { WhoopClient } from "../../whoop/client.js";
|
|
9
|
+
import { defineTool, respond } from "../define.js";
|
|
10
|
+
import { READ_ONLY } from "../annotations.js";
|
|
11
|
+
import { HealthOut } from "../../schemas/health.js";
|
|
12
|
+
import {
|
|
13
|
+
HEALTH_FEATURES, passThrough, projectBiomarker, projectHealthspan, projectLabs, projectLabTests, projectLockable, type HealthFeature,
|
|
14
|
+
} from "../../projections/health_features.js";
|
|
15
|
+
import { WhoopApiError, WhoopAuthExpiredError } from "../../whoop/errors.js";
|
|
16
|
+
import { todayIso } from "../../lib/dates.js";
|
|
17
|
+
|
|
18
|
+
const NAME = "whoop_health";
|
|
19
|
+
const LABS = "/advanced-labs-service/v1/advanced-labs";
|
|
20
|
+
|
|
21
|
+
const isStatus = (e: unknown, ...codes: number[]): boolean => e instanceof WhoopApiError && codes.includes(e.status);
|
|
22
|
+
|
|
23
|
+
/** One read: its projection, or why it couldn't be read. A 404 means the feature isn't set up. */
|
|
24
|
+
async function feature(read: Promise<unknown>, project: (raw: unknown) => HealthFeature, notSetUp: string): Promise<HealthFeature> {
|
|
25
|
+
try {
|
|
26
|
+
return project(await read);
|
|
27
|
+
} catch (e) {
|
|
28
|
+
if (e instanceof WhoopAuthExpiredError) throw e;
|
|
29
|
+
if (isStatus(e, 404)) return { status: "not_set_up", message: notSetUp };
|
|
30
|
+
return { status: "unavailable", message: (e as Error).message };
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** labs with an id: a biomarker's history, else a test's results and insights (id formats are unseen, so both are tried). */
|
|
35
|
+
async function labDetail(client: WhoopClient, id: string, cursor: string | undefined, warnings: string[]): Promise<HealthFeature> {
|
|
36
|
+
const enc = encodeURIComponent(id);
|
|
37
|
+
try {
|
|
38
|
+
return projectBiomarker(await client.get(`${LABS}/biomarkers/${enc}`, cursor ? { next_token: cursor } : {}));
|
|
39
|
+
} catch (e) {
|
|
40
|
+
if (e instanceof WhoopAuthExpiredError || !isStatus(e, 400, 404)) throw e;
|
|
41
|
+
}
|
|
42
|
+
try {
|
|
43
|
+
const [test, insights] = await Promise.all([
|
|
44
|
+
client.get(`${LABS}/tests/${enc}`),
|
|
45
|
+
client.get(`${LABS}/insights`, { testId: id }).catch((e: unknown) => {
|
|
46
|
+
if (e instanceof WhoopAuthExpiredError) throw e;
|
|
47
|
+
warnings.push(`Insights unavailable: ${(e as Error).message}`);
|
|
48
|
+
return null;
|
|
49
|
+
}),
|
|
50
|
+
]);
|
|
51
|
+
return passThrough({ test, insights }, 3_000);
|
|
52
|
+
} catch (e) {
|
|
53
|
+
if (e instanceof WhoopAuthExpiredError || !isStatus(e, 400, 404)) throw e;
|
|
54
|
+
return { status: "no_data", message: `No biomarker or lab test ${id}. Ids come from labs without an id.` };
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function registerHealth(server: McpServer, client: WhoopClient): void {
|
|
59
|
+
defineTool(server, {
|
|
60
|
+
name: NAME,
|
|
61
|
+
description:
|
|
62
|
+
"healthspan for a date: WHOOP Age, pace of aging, contributors. EXPERIMENTAL, untested (fields may be missing or misnamed): " +
|
|
63
|
+
"blood_pressure for a date; afib history (date: a day; cursor: next page); labs: biomarkers and tests (id: one of them).",
|
|
64
|
+
input: {
|
|
65
|
+
feature: z.enum(HEALTH_FEATURES),
|
|
66
|
+
date: z.iso.date().optional(),
|
|
67
|
+
id: z.string().min(1).optional(),
|
|
68
|
+
cursor: z.string().min(1).optional(),
|
|
69
|
+
},
|
|
70
|
+
annotations: READ_ONLY,
|
|
71
|
+
}, async ({ feature: name, date, id, cursor }) => {
|
|
72
|
+
const warnings: string[] = [];
|
|
73
|
+
const day = date ?? todayIso();
|
|
74
|
+
let out: HealthFeature;
|
|
75
|
+
let shown: { date?: string; id?: string } = {};
|
|
76
|
+
switch (name) {
|
|
77
|
+
case "healthspan":
|
|
78
|
+
out = await feature(client.get("/healthspan-service/v1/healthspan/bff", { date: day }), (raw) => projectLockable(raw, projectHealthspan), "Healthspan isn't available on this account.");
|
|
79
|
+
shown = { date: day };
|
|
80
|
+
break;
|
|
81
|
+
case "blood_pressure":
|
|
82
|
+
out = await feature(client.get("/sage-service/v1/sage/bff", { date: day }), (raw) => projectLockable(raw), "Blood pressure insights aren't available on this account.");
|
|
83
|
+
shown = { date: day };
|
|
84
|
+
break;
|
|
85
|
+
case "afib": {
|
|
86
|
+
const read = cursor ? client.get("/arrhythmia-service/v2/afibhistory/paginated", { next_token: cursor })
|
|
87
|
+
: date ? client.get("/arrhythmia-service/v1/history/bff", { historyDate: date })
|
|
88
|
+
: client.get("/arrhythmia-service/v2/afibhistory/screen");
|
|
89
|
+
out = await feature(read, (raw) => passThrough(raw), "Irregular rhythm notifications aren't set up on this account.");
|
|
90
|
+
if (date && !cursor) shown = { date };
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
case "labs":
|
|
94
|
+
if (id) {
|
|
95
|
+
out = await labDetail(client, id, cursor, warnings);
|
|
96
|
+
shown = { id };
|
|
97
|
+
} else {
|
|
98
|
+
const [summary, tests] = await Promise.all([
|
|
99
|
+
feature(client.get(`${LABS}/biomarkers/summary`), projectLabs, "Advanced Labs isn't available on this account."),
|
|
100
|
+
client.get(`${LABS}/tests/history`).then(projectLabTests).catch((e: unknown) => {
|
|
101
|
+
if (e instanceof WhoopAuthExpiredError) throw e;
|
|
102
|
+
warnings.push(`Lab history unavailable: ${(e as Error).message}`);
|
|
103
|
+
return null;
|
|
104
|
+
}),
|
|
105
|
+
]);
|
|
106
|
+
out = tests ? { ...summary, ...(summary.status === "no_data" ? { status: "available" as const, message: null } : {}), tests } : summary;
|
|
107
|
+
}
|
|
108
|
+
break;
|
|
109
|
+
}
|
|
110
|
+
// Healthspan's unlocked screen was checked on a real account; everything else is still unverified.
|
|
111
|
+
const experimental = !out.healthspan;
|
|
112
|
+
return respond(NAME, HealthOut, { feature: name, experimental, ...shown, ...out, warnings });
|
|
113
|
+
});
|
|
114
|
+
}
|
|
@@ -1,57 +1,144 @@
|
|
|
1
|
+
// whoop_hr_zones_set (W!): max HR, custom zones, or reset to WHOOP's defaults
|
|
2
|
+
// (SPEC.md §4.8 HR zones, §7 S7). Read back from bff/settings: the maxhr
|
|
3
|
+
// response shows heart-rate-reserve zones even while custom zones stay in force.
|
|
1
4
|
import { z } from "zod";
|
|
2
5
|
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
6
|
import type { WhoopClient } from "../../whoop/client.js";
|
|
4
|
-
import {
|
|
7
|
+
import { defineTool, respond, type ToolResult } from "../define.js";
|
|
8
|
+
import { WRITE_DESTRUCTIVE } from "../annotations.js";
|
|
9
|
+
import { HrZonesSetV2Out } from "../../schemas/settings_v2.js";
|
|
10
|
+
import { hrZonesOut, parseHrZones, type HrZonesState, type ZoneId, type ZoneRow } from "../../projections/settings_v2.js";
|
|
5
11
|
import { preview } from "../../whoop/write_safety.js";
|
|
6
12
|
import { jsonOut } from "../../whoop/json_out.js";
|
|
7
13
|
|
|
14
|
+
const NAME = "whoop_hr_zones_set";
|
|
15
|
+
const ZONES = "/hr-zones-service/v1/bff/zones";
|
|
16
|
+
const SETTINGS = "/hr-zones-service/v1/bff/settings";
|
|
17
|
+
const MAXHR = "/hr-zones-service/v1/maxhr";
|
|
18
|
+
const CUSTOM = "/hr-zones-service/v1/bff/custom";
|
|
19
|
+
const IDS: ZoneId[] = ["ZONE_1", "ZONE_2", "ZONE_3", "ZONE_4", "ZONE_5"];
|
|
20
|
+
|
|
21
|
+
function fail(error: string): ToolResult {
|
|
22
|
+
return { content: [{ type: "text", text: jsonOut({ error }) }], isError: true };
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Rows Z1..Z5 → the [min,max] pairs. */
|
|
26
|
+
const pairs = (rows: ZoneRow[]) => IDS.map((id) => rows.find((r) => r.id === id)).map((r) => (r ? [r.min, r.max] : null));
|
|
27
|
+
const sameZones = (a: ZoneRow[], b: ZoneRow[]) => JSON.stringify(pairs(a)) === JSON.stringify(pairs(b));
|
|
28
|
+
|
|
29
|
+
/** S7: five zones, each min < max, contiguous (min = previous max + 1). */
|
|
30
|
+
export function validateCustomZones(zones: Array<[number, number]>, maxHr: number | null): string | null {
|
|
31
|
+
if (zones.length !== 5) return "Pass exactly 5 zones, Z1..Z5.";
|
|
32
|
+
for (let i = 0; i < 5; i++) {
|
|
33
|
+
const [min, max] = zones[i]!;
|
|
34
|
+
if (min >= max) return `Z${i + 1} needs min below max.`;
|
|
35
|
+
if (i > 0 && min !== zones[i - 1]![1] + 1) {
|
|
36
|
+
return `Zones must be contiguous: Z${i + 1} has to start at ${zones[i - 1]![1] + 1} (Z${i} max + 1); WHOOP rejects gaps and overlaps.`;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
if (maxHr !== null && zones[4]![1] > maxHr) return `Z5 max ${zones[4]![1]} is above your max HR ${maxHr}; set max HR first (action max_hr) or lower Z5.`;
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
|
|
8
43
|
export function registerHrZonesSet(server: McpServer, client: WhoopClient): void {
|
|
9
|
-
server
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
.describe("Required for mode=custom. Must be 5 entries."),
|
|
44
|
+
defineTool(server, {
|
|
45
|
+
name: NAME,
|
|
46
|
+
description:
|
|
47
|
+
"Set heart-rate zones. max_hr: set max_heart_rate (WHOOP recomputes its default zones; custom zones stay in force). custom: zones " +
|
|
48
|
+
"as 5 [min, max] bpm pairs Z1..Z5, contiguous (each min = previous max + 1), Z5 max at most your max HR. reset: back to WHOOP's " +
|
|
49
|
+
"defaults. Previews unless confirm:true.",
|
|
50
|
+
input: {
|
|
51
|
+
action: z.enum(["max_hr", "custom", "reset"]),
|
|
52
|
+
max_heart_rate: z.number().int().min(101).max(220).optional(),
|
|
53
|
+
// Each zone is a plain two-number array, not a z.tuple: the SDK writes a tuple
|
|
54
|
+
// in draft-07 form ("items": [...]), which the Anthropic API rejects, and
|
|
55
|
+
// Claude then drops the whole tool. validateCustomZones checks min < max.
|
|
56
|
+
zones: z.array(z.array(z.number().int().min(0)).length(2)).optional(),
|
|
23
57
|
confirm: z.boolean().default(false),
|
|
24
58
|
},
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
59
|
+
annotations: WRITE_DESTRUCTIVE,
|
|
60
|
+
}, async ({ action, max_heart_rate, zones: zonesIn, confirm }) => {
|
|
61
|
+
const zones = zonesIn?.map((pair) => [pair[0]!, pair[1]!] as [number, number]);
|
|
62
|
+
if (action === "max_hr" && max_heart_rate === undefined) return fail("action max_hr needs max_heart_rate.");
|
|
63
|
+
if (action === "custom" && zones === undefined) return fail("action custom needs zones.");
|
|
64
|
+
if (action !== "custom" && zones !== undefined) return fail("zones only go with action custom.");
|
|
65
|
+
if (action !== "max_hr" && max_heart_rate !== undefined) return fail("max_heart_rate only goes with action max_hr.");
|
|
66
|
+
if (action === "custom") {
|
|
67
|
+
const err = validateCustomZones(zones!, null);
|
|
68
|
+
if (err) return fail(err);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// Fresh pre-read: the defaults (reset), max HR (Z5 rule) and the before-state.
|
|
72
|
+
const warnings: string[] = [];
|
|
73
|
+
const read = async (): Promise<HrZonesState | null> => {
|
|
74
|
+
const [z1, s1] = await Promise.all([
|
|
75
|
+
client.get(ZONES, {}, { fresh: true }).catch(() => null),
|
|
76
|
+
client.get(SETTINGS, {}, { fresh: true }).catch(() => null),
|
|
77
|
+
]);
|
|
78
|
+
return s1 === null ? null : parseHrZones({ zones: z1, settings: s1 });
|
|
79
|
+
};
|
|
80
|
+
const before = await read();
|
|
81
|
+
if (!before) {
|
|
82
|
+
if (action === "reset") return fail("Couldn't read WHOOP's default zones, so reset can't be built. Nothing was sent.");
|
|
83
|
+
warnings.push("Couldn't read the current zones first; no before-state.");
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
let path: string;
|
|
87
|
+
let body: unknown;
|
|
88
|
+
let target: ZoneRow[] | null = null;
|
|
89
|
+
if (action === "max_hr") {
|
|
90
|
+
if (before?.max_hr === max_heart_rate) {
|
|
91
|
+
return respond(NAME, HrZonesSetV2Out, { action, updated: false, no_change: true, before: hrZonesOut(before!), after: null, verified: true, warnings });
|
|
46
92
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
93
|
+
path = MAXHR;
|
|
94
|
+
body = { max_heart_rate };
|
|
95
|
+
if (before?.is_custom) warnings.push("Your zones are custom, so they stay in force; only the default zones are recomputed (use reset to switch to them).");
|
|
96
|
+
} else if (action === "custom") {
|
|
97
|
+
const err = validateCustomZones(zones!, before?.max_hr ?? null);
|
|
98
|
+
if (err) return fail(err);
|
|
99
|
+
target = IDS.map((id, i) => ({ id, min: zones![i]![0], max: zones![i]![1] }));
|
|
100
|
+
if (before?.is_custom && sameZones(before.zones, target)) {
|
|
101
|
+
return respond(NAME, HrZonesSetV2Out, { action, updated: false, no_change: true, before: hrZonesOut(before), after: null, verified: true, warnings });
|
|
51
102
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
103
|
+
path = CUSTOM;
|
|
104
|
+
body = { zones: target, is_custom: true };
|
|
105
|
+
} else {
|
|
106
|
+
target = IDS.map((id) => before!.default_zones.find((z) => z.id === id)).filter((z): z is ZoneRow => z !== undefined);
|
|
107
|
+
if (target.length !== 5) return fail("WHOOP's default zones are incomplete, so reset can't be built. Nothing was sent.");
|
|
108
|
+
// Not flagged custom doesn't prove the defaults are in force: WHOOP stores
|
|
109
|
+
// whatever zones arrive with is_custom:false, so compare the zones too.
|
|
110
|
+
if (before!.is_custom === false && sameZones(before!.zones, target)) {
|
|
111
|
+
return respond(NAME, HrZonesSetV2Out, { action, updated: false, no_change: true, before: hrZonesOut(before!), after: null, verified: true, warnings });
|
|
112
|
+
}
|
|
113
|
+
path = CUSTOM;
|
|
114
|
+
body = { zones: target.map(({ id, min, max }) => ({ id, min, max })), is_custom: false };
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
if (!confirm) {
|
|
118
|
+
return respond(NAME, HrZonesSetV2Out, preview("POST", path, {
|
|
119
|
+
before: before ? hrZonesOut(before) : null,
|
|
120
|
+
...(target ? { zones: pairs(target) } : { max_heart_rate }),
|
|
121
|
+
...(warnings.length > 0 ? { warnings } : {}),
|
|
122
|
+
}));
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
await client.post(path, body);
|
|
126
|
+
|
|
127
|
+
const after = await read();
|
|
128
|
+
let verified = after !== null;
|
|
129
|
+
if (!after) warnings.push("Couldn't read the zones back to verify.");
|
|
130
|
+
else if (action === "max_hr") verified = after.max_hr === max_heart_rate;
|
|
131
|
+
else if (action === "custom") verified = after.is_custom === true && sameZones(after.zones, target!);
|
|
132
|
+
else verified = after.is_custom === false && sameZones(after.zones, target!);
|
|
133
|
+
if (after && !verified) warnings.push("WHOOP accepted the write but the zones read back differently; check after/before.");
|
|
134
|
+
return respond(NAME, HrZonesSetV2Out, {
|
|
135
|
+
action,
|
|
136
|
+
updated: true,
|
|
137
|
+
no_change: false,
|
|
138
|
+
before: before ? hrZonesOut(before) : null,
|
|
139
|
+
after: after ? hrZonesOut(after) : null,
|
|
140
|
+
verified,
|
|
141
|
+
warnings,
|
|
142
|
+
});
|
|
143
|
+
});
|
|
57
144
|
}
|
package/src/tools/v2/journal.ts
CHANGED
|
@@ -1,31 +1,86 @@
|
|
|
1
|
+
// whoop_journal (R): the day's journal answers, plus the live behaviour catalog
|
|
2
|
+
// and behaviour impact on request. Replaces whoop_journal, whoop_journal_catalog
|
|
3
|
+
// and whoop_behavior_impact (SPEC.md §3.1, D15).
|
|
1
4
|
import { z } from "zod";
|
|
2
5
|
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
6
|
import type { WhoopClient } from "../../whoop/client.js";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
7
|
+
import { defineTool, respond } from "../define.js";
|
|
8
|
+
import { READ_ONLY } from "../annotations.js";
|
|
9
|
+
import { JournalV2Out } from "../../schemas/journal_v2.js";
|
|
10
|
+
import { isDraftBody, loadBehaviorCatalog, parseDraft } from "../../lib/journal_behaviors.js";
|
|
11
|
+
import { projectBehaviorCatalog, projectBehaviorImpacts, projectJournalDay } from "../../projections/journal_v2.js";
|
|
12
|
+
import { projectBehaviorImpact } from "../../projections/behavior_impact.js";
|
|
8
13
|
import { todayIso } from "../../lib/dates.js";
|
|
14
|
+
import { WhoopApiError } from "../../whoop/errors.js";
|
|
15
|
+
|
|
16
|
+
const NAME = "whoop_journal";
|
|
9
17
|
|
|
10
18
|
export function registerJournal(server: McpServer, client: WhoopClient): void {
|
|
11
|
-
server
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const out = JournalOut.parse(projected);
|
|
24
|
-
return { content: [{ type: "text", text: jsonOut(out) }] };
|
|
25
|
-
} catch (e) {
|
|
26
|
-
if (e instanceof z.ZodError) throw new WhoopProjectionError("whoop_journal", e);
|
|
27
|
-
throw e;
|
|
28
|
-
}
|
|
19
|
+
defineTool(server, {
|
|
20
|
+
name: NAME,
|
|
21
|
+
description:
|
|
22
|
+
"Journal for a date (default today): answered behaviours (yes/no, value, time) and notes. include: unanswered; catalog (your " +
|
|
23
|
+
"behaviour ids and names, custom too; filter with search or category); magnitudes (ranges and step choices on catalog rows); " +
|
|
24
|
+
"impact (how behaviours move your recovery). impact_id: one personal impact's detail.",
|
|
25
|
+
input: {
|
|
26
|
+
date: z.iso.date().optional(),
|
|
27
|
+
include: z.array(z.enum(["unanswered", "catalog", "magnitudes", "impact"])).optional(),
|
|
28
|
+
search: z.string().optional(),
|
|
29
|
+
category: z.string().optional().describe("e.g. Supplements"),
|
|
30
|
+
impact_id: z.string().optional(),
|
|
29
31
|
},
|
|
30
|
-
|
|
32
|
+
annotations: READ_ONLY,
|
|
33
|
+
}, async ({ date, include, search, category, impact_id }) => {
|
|
34
|
+
const d = date ?? todayIso();
|
|
35
|
+
const wants = new Set<string>(include ?? []);
|
|
36
|
+
if (search !== undefined || category !== undefined || wants.has("magnitudes")) wants.add("catalog");
|
|
37
|
+
if (impact_id !== undefined) wants.add("impact");
|
|
38
|
+
const warnings: string[] = [];
|
|
39
|
+
|
|
40
|
+
const [rawDraft, catalog, rawImpact] = await Promise.all([
|
|
41
|
+
client.get(`/journal-service/v3/journals/drafts/mobile/${d}`),
|
|
42
|
+
wants.has("catalog") ? loadBehaviorCatalog(client, d) : Promise.resolve(null),
|
|
43
|
+
wants.has("impact")
|
|
44
|
+
? client.get("/behavior-impact-service/v1/impact").catch((e: unknown) => {
|
|
45
|
+
warnings.push(`Behaviour impact unavailable: ${(e as Error).message}`);
|
|
46
|
+
return null;
|
|
47
|
+
})
|
|
48
|
+
: Promise.resolve(null),
|
|
49
|
+
]);
|
|
50
|
+
|
|
51
|
+
// An empty day still has `journal.tracked_behaviors: []`; a body without it isn't an empty day.
|
|
52
|
+
if (!isDraftBody(rawDraft)) warnings.push("WHOOP's journal response had an unexpected shape, so this day may not really be empty.");
|
|
53
|
+
const out: Record<string, unknown> = { ...projectJournalDay(parseDraft(rawDraft, d), { includeUnanswered: wants.has("unanswered") }) };
|
|
54
|
+
|
|
55
|
+
if (catalog) {
|
|
56
|
+
if (catalog.warning) warnings.push(catalog.warning);
|
|
57
|
+
out.catalog = projectBehaviorCatalog(catalog, { search, category, detail: wants.has("magnitudes") });
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (wants.has("impact")) {
|
|
61
|
+
const impacts = rawImpact === null ? { personal: 0, rows: [] } : projectBehaviorImpacts(rawImpact);
|
|
62
|
+
let detail = null;
|
|
63
|
+
if (impact_id !== undefined) {
|
|
64
|
+
const card = impacts.rows.find((i) => i.uuid === impact_id);
|
|
65
|
+
if (card?.rec) {
|
|
66
|
+
warnings.push(`"${card.name}" is a member-average card, not your data; WHOOP has no detail for it.`);
|
|
67
|
+
} else {
|
|
68
|
+
try {
|
|
69
|
+
detail = projectBehaviorImpact(await client.get(`/behavior-impact-service/v2/impact/details/${encodeURIComponent(impact_id)}`), impact_id);
|
|
70
|
+
} catch (e) {
|
|
71
|
+
// 400 for an unknown impact uuid; 404 for an id that isn't a uuid at all (live 2026-11-21).
|
|
72
|
+
if (!(e instanceof WhoopApiError && (e.status === 400 || e.status === 404))) throw e;
|
|
73
|
+
warnings.push(`WHOOP has no personal impact ${impact_id}; only your own impacts have detail (their id is on the impact rows).`);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
if (rawImpact !== null && impacts.personal === 0) {
|
|
78
|
+
warnings.push("No personal impacts yet (WHOOP needs weeks of journal answers); rec:true rows are member averages.");
|
|
79
|
+
}
|
|
80
|
+
out.impact = { personal: impacts.personal, rows: impacts.rows.map(({ uuid: _uuid, ...row }) => row), detail };
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
out.warnings = warnings;
|
|
84
|
+
return respond(NAME, JournalV2Out, out);
|
|
85
|
+
});
|
|
31
86
|
}
|