@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,84 +1,336 @@
|
|
|
1
|
+
// whoop_journal_log (W!): write journal answers (SPEC.md §4.6, D3, §7 S10).
|
|
2
|
+
//
|
|
3
|
+
// Default path: PUT /journal-service/v2/journal/entry/partial. It merges across
|
|
4
|
+
// rows, never touches notes, and takes several dates at once. The full PUT
|
|
5
|
+
// (/journals/entries/user/date/{date}) replaces the whole day and nulls notes
|
|
6
|
+
// it isn't sent, so it's used only for replace_day or notes, and then always
|
|
7
|
+
// carries the current notes and answers from a fresh draft read (PR #44's
|
|
8
|
+
// guard: no draft, no full PUT; a 404 counts as no draft). Every write is read
|
|
9
|
+
// back: one 204 was seen not to land while cycles were being reshuffled.
|
|
1
10
|
import { z } from "zod";
|
|
2
11
|
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
12
|
import type { WhoopClient } from "../../whoop/client.js";
|
|
4
|
-
import {
|
|
13
|
+
import { defineTool, respond, type ToolResult } from "../define.js";
|
|
14
|
+
import { WRITE_DESTRUCTIVE } from "../annotations.js";
|
|
15
|
+
import { JournalLogV2Out } from "../../schemas/journal_v2.js";
|
|
5
16
|
import { preview } from "../../whoop/write_safety.js";
|
|
6
17
|
import { jsonOut } from "../../whoop/json_out.js";
|
|
7
18
|
import { todayIso } from "../../lib/dates.js";
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
19
|
+
import { runPaced } from "../../lib/concurrency.js";
|
|
20
|
+
import { projectBehaviorToggles } from "../../projections/settings_v2.js";
|
|
21
|
+
import {
|
|
22
|
+
answeredById,
|
|
23
|
+
buildRow,
|
|
24
|
+
carryRow,
|
|
25
|
+
isAnswered,
|
|
26
|
+
isDraftBody,
|
|
27
|
+
loadBehaviorCatalog,
|
|
28
|
+
parseDraft,
|
|
29
|
+
resolveBehavior,
|
|
30
|
+
splitMenstruationOvulation,
|
|
31
|
+
type BehaviorSpec,
|
|
32
|
+
type DraftDay,
|
|
33
|
+
type TrackerRow,
|
|
34
|
+
} from "../../lib/journal_behaviors.js";
|
|
35
|
+
|
|
36
|
+
const NAME = "whoop_journal_log";
|
|
37
|
+
const DRAFT = (d: string) => `/journal-service/v3/journals/drafts/mobile/${d}`;
|
|
38
|
+
const PARTIAL = "/journal-service/v2/journal/entry/partial";
|
|
39
|
+
const FULL = (d: string) => `/journal-service/v2/journals/entries/user/date/${d}`;
|
|
40
|
+
const CUSTOMIZE = "/journal-service/v3/journals/behaviors";
|
|
41
|
+
|
|
42
|
+
function fail(error: string, extra: Record<string, unknown> = {}): ToolResult {
|
|
43
|
+
return { content: [{ type: "text", text: jsonOut({ error, ...extra }) }], isError: true };
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const BehaviorInput = z.object({
|
|
47
|
+
id: z.number().int().optional().describe("From whoop_journal include catalog"),
|
|
48
|
+
name: z.string().optional().describe("Exact title, e.g. Caffeine"),
|
|
49
|
+
answered_yes: z.boolean().optional().describe("Default true"),
|
|
50
|
+
magnitude: z.number().nullable().optional().describe("A number in range, or the step choice value; null clears"),
|
|
51
|
+
magnitude_label: z.string().optional().describe("Step choice label (e.g. Moderate) instead of magnitude"),
|
|
52
|
+
time: z.union([z.string(), z.number()]).nullable().optional().describe("ISO datetime with offset or epoch seconds; null clears"),
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
interface PlannedRow {
|
|
56
|
+
date: string;
|
|
57
|
+
spec: BehaviorSpec;
|
|
58
|
+
row: TrackerRow;
|
|
59
|
+
action: "set" | "unset";
|
|
60
|
+
carried: string[];
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const iso = (secs: number | undefined) => (secs === undefined ? null : new Date(secs * 1000).toISOString());
|
|
64
|
+
|
|
65
|
+
/** Drop null/empty fields (previews go out as-is). */
|
|
66
|
+
function compact<T extends Record<string, unknown>>(o: T): Partial<T> {
|
|
67
|
+
return Object.fromEntries(Object.entries(o).filter(([, v]) => v !== null && !(Array.isArray(v) && v.length === 0))) as Partial<T>;
|
|
68
|
+
}
|
|
10
69
|
|
|
11
70
|
export function registerJournalLog(server: McpServer, client: WhoopClient): void {
|
|
12
|
-
server
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
notes: z.string().optional(),
|
|
71
|
+
defineTool(server, {
|
|
72
|
+
name: NAME,
|
|
73
|
+
description:
|
|
74
|
+
"Log journal answers. Default is a merge: only the listed behaviours change, and a yes row keeps its stored magnitude and time " +
|
|
75
|
+
"unless you pass new ones (null clears). notes or replace_day:true rewrite the whole day (one date only), keeping current notes " +
|
|
76
|
+
"and answers unless replaced. Behaviours go by id or name, custom ones included. Previews unless confirm:true.",
|
|
77
|
+
input: {
|
|
78
|
+
date: z.iso.date().optional().describe("Default today"),
|
|
79
|
+
dates: z.array(z.iso.date()).min(1).max(7).optional().describe("Several dates; merge writes only"),
|
|
80
|
+
behaviors: z.array(BehaviorInput).default([]),
|
|
81
|
+
unset: z.array(z.union([z.number().int(), z.string()])).optional().describe("Ids or names whose answer to clear"),
|
|
82
|
+
notes: z.string().optional().describe("Replaces the day's notes; \"\" clears them"),
|
|
83
|
+
replace_day: z.boolean().optional().describe("Drops every answer not listed here"),
|
|
24
84
|
confirm: z.boolean().default(false),
|
|
25
85
|
},
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
86
|
+
annotations: WRITE_DESTRUCTIVE,
|
|
87
|
+
}, async ({ date, dates, behaviors, unset, notes, replace_day, confirm }) => {
|
|
88
|
+
// 1. Validate the request shape before touching WHOOP.
|
|
89
|
+
if (date !== undefined && dates !== undefined) return fail("Pass date or dates, not both.");
|
|
90
|
+
const today = todayIso();
|
|
91
|
+
const dateList = [...new Set(dates ?? [date ?? today])].sort();
|
|
92
|
+
const future = dateList.filter((d) => d > today);
|
|
93
|
+
if (future.length > 0) return fail(`Journal dates can't be in the future (today is ${today}): ${future.join(", ")}.`);
|
|
94
|
+
const full = replace_day === true || notes !== undefined;
|
|
95
|
+
if (full && dateList.length > 1) return fail("notes and replace_day rewrite one day at a time; pass a single date.");
|
|
96
|
+
const unsetRefs = unset ?? [];
|
|
97
|
+
if (behaviors.length === 0 && unsetRefs.length === 0 && notes === undefined && replace_day !== true) {
|
|
98
|
+
return fail("Nothing to write: pass behaviors, unset, notes or replace_day.");
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// 2. Resolve every behaviour against the live catalog (171 and customs included).
|
|
102
|
+
const catalog = await loadBehaviorCatalog(client, dateList[0]!, { fresh: true });
|
|
103
|
+
const warnings: string[] = catalog.warning ? [catalog.warning] : [];
|
|
104
|
+
const errors: Array<{ error: string; suggestions?: Array<{ id: number; title: string }> }> = [];
|
|
105
|
+
const resolved: Array<{ spec: BehaviorSpec; input: z.infer<typeof BehaviorInput> }> = [];
|
|
106
|
+
for (const b of behaviors) {
|
|
107
|
+
const r = resolveBehavior({ id: b.id, name: b.name }, catalog);
|
|
108
|
+
if (r.ok) resolved.push({ spec: r.spec, input: b });
|
|
109
|
+
else errors.push({ error: r.error, suggestions: r.suggestions });
|
|
110
|
+
}
|
|
111
|
+
const unsetSpecs: BehaviorSpec[] = [];
|
|
112
|
+
for (const ref of unsetRefs) {
|
|
113
|
+
const asId = typeof ref === "number" ? ref : /^\d+$/.test(ref.trim()) ? Number(ref) : undefined;
|
|
114
|
+
const r = resolveBehavior(asId !== undefined ? { id: asId } : { name: String(ref) }, catalog);
|
|
115
|
+
if (r.ok) unsetSpecs.push(r.spec);
|
|
116
|
+
else errors.push({ error: r.error, suggestions: r.suggestions });
|
|
117
|
+
}
|
|
118
|
+
if (errors.length > 0) return fail("Some behaviours couldn't be resolved; nothing was written.", { problems: errors });
|
|
119
|
+
const ids = resolved.map((r) => r.spec.id);
|
|
120
|
+
const dupes = ids.filter((id, i) => ids.indexOf(id) !== i);
|
|
121
|
+
if (dupes.length > 0) return fail(`Behaviour listed twice: ${[...new Set(dupes)].join(", ")}.`);
|
|
122
|
+
const clash = unsetSpecs.filter((s) => ids.includes(s.id));
|
|
123
|
+
if (clash.length > 0) return fail(`Can't both set and unset: ${clash.map((s) => s.title).join(", ")}.`);
|
|
124
|
+
for (const { spec } of resolved) {
|
|
125
|
+
if (spec.tracked === false) {
|
|
126
|
+
warnings.push(`${spec.title} isn't in your tracked behaviours, so the app won't show it until you track it (whoop_preferences_set setting:tracked_behaviors).`);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// 3. Fresh draft pre-read: "before" values for the preview, stored magnitude/time
|
|
131
|
+
// to carry, and (full PUT) the notes and answers that must be re-sent.
|
|
132
|
+
// WHOOP answers 200 for every date (an empty day is `tracked_behaviors: []`),
|
|
133
|
+
// so a 404 or a body without the journal is a failed read, never "empty day".
|
|
134
|
+
const drafts = new Map<string, DraftDay | null>();
|
|
135
|
+
const readErrors: string[] = [];
|
|
136
|
+
await runPaced(dateList.map((d) => async () => {
|
|
137
|
+
try {
|
|
138
|
+
const raw = await client.get(DRAFT(d), {}, { fresh: true });
|
|
139
|
+
if (!isDraftBody(raw)) throw new Error("unexpected journal response");
|
|
140
|
+
drafts.set(d, parseDraft(raw, d));
|
|
141
|
+
} catch (e) {
|
|
142
|
+
drafts.set(d, null);
|
|
143
|
+
readErrors.push(`${d}: ${(e as Error).message}`);
|
|
144
|
+
}
|
|
145
|
+
}), { concurrency: 3 });
|
|
146
|
+
if (full && drafts.get(dateList[0]!) === null) {
|
|
147
|
+
return fail(
|
|
148
|
+
`Couldn't read the current journal for ${dateList[0]}, so a full-day write could erase its notes or other answers. Nothing was written. Retry, or drop notes/replace_day to merge instead.`,
|
|
149
|
+
{ detail: readErrors.join("; ") },
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
if (readErrors.length > 0) {
|
|
153
|
+
// A merge replaces each listed row whole. Without the draft, a stored
|
|
154
|
+
// magnitude or time the caller didn't spell out would be erased.
|
|
155
|
+
const atRisk = resolved.filter(({ spec, input }) =>
|
|
156
|
+
(input.answered_yes ?? true) && (
|
|
157
|
+
(spec.magnitude !== null && input.magnitude === undefined && input.magnitude_label === undefined) ||
|
|
158
|
+
(spec.time_label !== null && input.time === undefined)
|
|
159
|
+
));
|
|
160
|
+
if (atRisk.length > 0) {
|
|
161
|
+
return fail(
|
|
162
|
+
`Couldn't read the current journal, and WHOOP replaces a row whole: a stored magnitude or time for ${atRisk.map((r) => r.spec.title).join(", ")} would be erased. Nothing was written. Retry, or pass magnitude and time explicitly (null clears them).`,
|
|
163
|
+
{ detail: readErrors.join("; ") },
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
warnings.push(`Couldn't read the current journal first (${readErrors.join("; ")}), so there are no before-values.`);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// 4. Build rows per date.
|
|
170
|
+
const planned: PlannedRow[] = [];
|
|
171
|
+
const rowErrors = new Set<string>();
|
|
172
|
+
for (const d of dateList) {
|
|
173
|
+
const stored = drafts.get(d) ? answeredById(drafts.get(d)!) : new Map();
|
|
174
|
+
for (const { spec, input } of resolved) {
|
|
175
|
+
const built = buildRow(spec, input, stored.get(spec.id)?.input ?? null);
|
|
176
|
+
if ("error" in built) rowErrors.add(built.error);
|
|
177
|
+
else planned.push({ date: d, spec, row: built.row, action: "set", carried: built.carried });
|
|
47
178
|
}
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
179
|
+
for (const spec of unsetSpecs) {
|
|
180
|
+
planned.push({ date: d, spec, row: { behavior_tracker_id: spec.id }, action: "unset", carried: [] });
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
if (rowErrors.size > 0) return fail("Some answers don't fit their behaviour; nothing was written.", { problems: [...rowErrors] });
|
|
184
|
+
|
|
185
|
+
// 5. Compose the request(s).
|
|
186
|
+
type Req = { path: string; body: unknown };
|
|
187
|
+
const requests: Req[] = [];
|
|
188
|
+
let notesPlan: { before: string | null; send: string | null } | null = null;
|
|
189
|
+
const removed: Array<{ date: string; id: number; title: string }> = [];
|
|
190
|
+
let keptCount = 0;
|
|
191
|
+
if (!full) {
|
|
192
|
+
const byDate = new Map<string, TrackerRow[]>();
|
|
193
|
+
for (const p of planned) byDate.set(p.date, [...(byDate.get(p.date) ?? []), p.row]);
|
|
194
|
+
const split = splitMenstruationOvulation(byDate);
|
|
195
|
+
for (const part of split) {
|
|
196
|
+
const tracker_inputs: Record<string, { tracker_input_eggs: TrackerRow[] }> = {};
|
|
197
|
+
for (const [d, rows] of part) if (rows.length > 0) tracker_inputs[d] = { tracker_input_eggs: rows };
|
|
198
|
+
if (Object.keys(tracker_inputs).length > 0) requests.push({ path: PARTIAL, body: { tracker_inputs } });
|
|
199
|
+
}
|
|
200
|
+
if (requests.length > 1) warnings.push("Menstruation and ovulation went in separate requests: WHOOP refuses both as yes in one request.");
|
|
201
|
+
} else {
|
|
202
|
+
const d = dateList[0]!;
|
|
203
|
+
const day = drafts.get(d) ?? parseDraft({}, d);
|
|
204
|
+
const touched = new Set(planned.map((p) => p.spec.id));
|
|
205
|
+
const stored = answeredById(day);
|
|
206
|
+
const kept: TrackerRow[] = [];
|
|
207
|
+
for (const [id, row] of stored) {
|
|
208
|
+
if (touched.has(id)) continue;
|
|
209
|
+
if (replace_day) removed.push({ date: d, id, title: row.spec.title });
|
|
210
|
+
else kept.push(carryRow(row));
|
|
211
|
+
}
|
|
212
|
+
keptCount = kept.length;
|
|
213
|
+
// Unset rows are simply left out: the full PUT deletes what it isn't sent.
|
|
214
|
+
const tracker_inputs = [...kept, ...planned.filter((p) => p.action === "set").map((p) => p.row)];
|
|
215
|
+
const send = notes !== undefined ? notes : day.notes;
|
|
216
|
+
notesPlan = { before: day.notes, send };
|
|
217
|
+
requests.push({ path: FULL(d), body: send === null ? { tracker_inputs } : { tracker_inputs, notes: send } });
|
|
218
|
+
// WHOOP leaves an untracked custom behaviour's answers out of the draft, so
|
|
219
|
+
// they can't be re-sent, and the full PUT deletes what it isn't sent
|
|
220
|
+
// (verified live: gone after re-tracking; kept when no full PUT ran).
|
|
221
|
+
const hidden = await client.get(CUSTOMIZE, {}, { fresh: true })
|
|
222
|
+
.then((raw) => projectBehaviorToggles(raw).toggles.filter((t) => t.custom && !t.selected).map((t) => t.title ?? `#${t.id}`))
|
|
223
|
+
.catch(() => [] as string[]);
|
|
224
|
+
if (hidden.length > 0) {
|
|
225
|
+
warnings.push(`You have untracked custom behaviours (${hidden.join(", ")}). WHOOP hides their answers from the day, so a full-day write can't keep them: any answer they have on ${d} will be deleted. Track them first to keep those answers.`);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
const multi = dateList.length > 1;
|
|
230
|
+
const rowsOut = planned.map((p) => ({
|
|
231
|
+
date: multi ? p.date : null,
|
|
232
|
+
id: p.spec.id,
|
|
233
|
+
name: p.spec.title,
|
|
234
|
+
yes: p.action === "unset" ? null : p.row.answered_yes ?? null,
|
|
235
|
+
value: p.row.magnitude_input_value ?? null,
|
|
236
|
+
label: p.spec.magnitude?.type === "step" ? p.row.magnitude_input_label ?? null : null,
|
|
237
|
+
time: iso(p.row.time_input_value),
|
|
238
|
+
unset: p.action === "unset" ? true as const : null,
|
|
239
|
+
carried: p.carried,
|
|
240
|
+
}));
|
|
241
|
+
|
|
242
|
+
// 6. Preview: what changes, against what is stored now.
|
|
243
|
+
if (!confirm) {
|
|
244
|
+
const before = (p: PlannedRow) => {
|
|
245
|
+
const s = drafts.get(p.date) ? answeredById(drafts.get(p.date)!).get(p.spec.id)?.input : undefined;
|
|
246
|
+
if (!s) return null;
|
|
247
|
+
return [s.answered_yes, s.magnitude_input_value, iso(s.time_input_value ?? undefined)].filter((v) => v !== null);
|
|
248
|
+
};
|
|
249
|
+
return respond(NAME, JournalLogV2Out, preview("PUT", requests[0]!.path, {
|
|
250
|
+
method: full ? "full: replaces the whole day" : "partial: merge",
|
|
251
|
+
...(requests.length > 1 ? { requests: requests.length } : {}),
|
|
252
|
+
dates: dateList,
|
|
253
|
+
changes: planned.map((p, i) => ({ ...compact(rowsOut[i]!), before: before(p) })),
|
|
254
|
+
...(full
|
|
255
|
+
? { notes: { before: notesPlan!.before, after: notesPlan!.send === "" ? null : notesPlan!.send }, other_answers_kept: keptCount, removes: removed.map((r) => r.title) }
|
|
256
|
+
: {}),
|
|
257
|
+
...(warnings.length > 0 ? { warnings } : {}),
|
|
258
|
+
}));
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
// 7. Send. A failure after the first request leaves a partial write: say so.
|
|
262
|
+
let sent = 0;
|
|
263
|
+
for (const req of requests) {
|
|
264
|
+
try {
|
|
265
|
+
await client.put(req.path, req.body);
|
|
266
|
+
sent++;
|
|
267
|
+
} catch (e) {
|
|
268
|
+
if (sent === 0) throw e;
|
|
269
|
+
return fail(`Request ${sent + 1} of ${requests.length} failed after the first was applied; re-read the journal before retrying.`, {
|
|
270
|
+
detail: (e as Error).message,
|
|
271
|
+
rows: rowsOut,
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
// 8. Fresh read-back: report what actually stuck, not the 204.
|
|
277
|
+
const mismatches: Array<{ date: string; id: number | null; field: string; expected: string | number | boolean | null; actual: string | number | boolean | null }> = [];
|
|
278
|
+
const after = new Map<string, DraftDay | null>();
|
|
279
|
+
await runPaced(dateList.map((d) => async () => {
|
|
280
|
+
after.set(d, await client.get(DRAFT(d), {}, { fresh: true }).then((raw) => parseDraft(raw, d)).catch(() => null));
|
|
281
|
+
}), { concurrency: 3 });
|
|
282
|
+
let verified = true;
|
|
283
|
+
for (const d of dateList) {
|
|
284
|
+
const day = after.get(d);
|
|
285
|
+
if (!day) {
|
|
286
|
+
verified = false;
|
|
287
|
+
warnings.push(`Couldn't read ${d} back to verify the write.`);
|
|
288
|
+
continue;
|
|
289
|
+
}
|
|
290
|
+
const back = answeredById(day);
|
|
291
|
+
for (const p of planned.filter((x) => x.date === d)) {
|
|
292
|
+
const got = back.get(p.spec.id)?.input;
|
|
293
|
+
if (p.action === "unset") {
|
|
294
|
+
if (isAnswered(got ?? null)) mismatches.push({ date: d, id: p.spec.id, field: "answered_yes", expected: null, actual: got!.answered_yes });
|
|
295
|
+
continue;
|
|
54
296
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
if (notes !== undefined) body.notes = notes;
|
|
59
|
-
const path = `/journal-service/v2/journals/entries/user/date/${d}`;
|
|
60
|
-
if (!confirm) {
|
|
61
|
-
const sampleTitles = behaviors
|
|
62
|
-
.slice(0, 5)
|
|
63
|
-
.map((b) => BEHAVIORS_BY_ID.get(b.behavior_tracker_id)?.title ?? `#${b.behavior_tracker_id}`);
|
|
64
|
-
return {
|
|
65
|
-
content: [
|
|
66
|
-
{
|
|
67
|
-
type: "text",
|
|
68
|
-
text: jsonOut(
|
|
69
|
-
preview("PUT", path, {
|
|
70
|
-
date: d,
|
|
71
|
-
behaviors_count: behaviors.length,
|
|
72
|
-
sample_titles: sampleTitles,
|
|
73
|
-
}),
|
|
74
|
-
),
|
|
75
|
-
},
|
|
76
|
-
],
|
|
297
|
+
const check = (field: string, expected: number | boolean | null, actual: number | boolean | null) => {
|
|
298
|
+
const same = typeof expected === "number" && typeof actual === "number" ? Math.abs(expected - actual) < 1e-6 : expected === actual;
|
|
299
|
+
if (!same) mismatches.push({ date: d, id: p.spec.id, field, expected, actual });
|
|
77
300
|
};
|
|
301
|
+
check("answered_yes", p.row.answered_yes ?? null, got?.answered_yes ?? null);
|
|
302
|
+
// WHOOP replaces a row whole, so a field that wasn't sent (cleared with
|
|
303
|
+
// null, or dropped by answered_yes:false) must read back empty too.
|
|
304
|
+
check("magnitude", p.row.magnitude_input_value ?? null, got?.magnitude_input_value ?? null);
|
|
305
|
+
check("time", p.row.time_input_value ?? null, got?.time_input_value ?? null);
|
|
78
306
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
307
|
+
if (full) {
|
|
308
|
+
const expectNotes = notesPlan!.send === "" ? null : notesPlan!.send;
|
|
309
|
+
if (day.notes !== expectNotes) mismatches.push({ date: d, id: null, field: "notes", expected: expectNotes, actual: day.notes });
|
|
310
|
+
for (const r of removed) {
|
|
311
|
+
if (back.has(r.id)) mismatches.push({ date: d, id: r.id, field: "answered_yes", expected: null, actual: back.get(r.id)!.input.answered_yes });
|
|
312
|
+
}
|
|
313
|
+
const missingKept = [...answeredById(drafts.get(d) ?? parseDraft({}, d)).keys()]
|
|
314
|
+
.filter((id) => !replace_day && !planned.some((p) => p.spec.id === id) && !back.has(id));
|
|
315
|
+
for (const id of missingKept) mismatches.push({ date: d, id, field: "kept_answer", expected: true, actual: false });
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
if (mismatches.length > 0) {
|
|
319
|
+
verified = false;
|
|
320
|
+
warnings.push("WHOOP accepted the write, but the read-back doesn't match everywhere (see mismatches). A write can be dropped while WHOOP reshuffles the day's cycle; retry in a minute.");
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
return respond(NAME, JournalLogV2Out, {
|
|
324
|
+
written: true,
|
|
325
|
+
method: full ? "full" : "partial",
|
|
326
|
+
requests: requests.length > 1 ? requests.length : null,
|
|
327
|
+
dates: dateList,
|
|
328
|
+
rows: rowsOut,
|
|
329
|
+
notes: full ? { before: notesPlan!.before, after: after.get(dateList[0]!)?.notes ?? null } : null,
|
|
330
|
+
removed: removed.map((r) => r.title),
|
|
331
|
+
verified,
|
|
332
|
+
mismatches,
|
|
333
|
+
warnings,
|
|
334
|
+
});
|
|
335
|
+
});
|
|
84
336
|
}
|
|
@@ -1,35 +1,143 @@
|
|
|
1
|
+
// whoop_lift_exercise (R): replaces whoop_lift_exercise, whoop_lift_progression and
|
|
2
|
+
// whoop_lift_prs (+ the proposed one-rep-max read).
|
|
1
3
|
import { z } from "zod";
|
|
2
4
|
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
5
|
import type { WhoopClient } from "../../whoop/client.js";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
|
|
6
|
+
import { defineTool, respond } from "../define.js";
|
|
7
|
+
import { READ_ONLY } from "../annotations.js";
|
|
8
|
+
import { LiftExerciseOutV2 } from "../../schemas/strength_v2.js";
|
|
9
|
+
import {
|
|
10
|
+
PR_COLS,
|
|
11
|
+
cardsUnit,
|
|
12
|
+
exerciseMeta,
|
|
13
|
+
historySession,
|
|
14
|
+
oneRepMaxCard,
|
|
15
|
+
oneRepMaxEntries,
|
|
16
|
+
oneRepMaxRows,
|
|
17
|
+
prRows,
|
|
18
|
+
progressionRows,
|
|
19
|
+
} from "../../projections/lift_exercise_v2.js";
|
|
20
|
+
import { parseLiftCards } from "../../projections/lift_cards.js";
|
|
21
|
+
import { ExerciseResolver } from "../../lib/lift_catalog.js";
|
|
22
|
+
import { get } from "../../whoop/bff.js";
|
|
23
|
+
import { runPaced } from "../../lib/concurrency.js";
|
|
24
|
+
import { todayIso } from "../../lib/dates.js";
|
|
25
|
+
import { errorMessage, liftError } from "../../lib/lift_tool.js";
|
|
26
|
+
|
|
27
|
+
const TOOL = "whoop_lift_exercise";
|
|
28
|
+
const PR_PAGES = 3; // 30 rows (about 1.7 KB) per call; `next` continues
|
|
29
|
+
const INCLUDES = ["history", "records", "one_rep_max", "progression", "instructions"] as const;
|
|
30
|
+
type Include = (typeof INCLUDES)[number];
|
|
31
|
+
|
|
32
|
+
async function prList(client: WhoopClient, cursor: string | undefined) {
|
|
33
|
+
const start = cursor ? Number(cursor) : 0;
|
|
34
|
+
if (!Number.isInteger(start) || start < 0) throw new Error(`cursor "${cursor}" isn't a PR offset; pass a returned next.`);
|
|
35
|
+
const pages: unknown[] = [];
|
|
36
|
+
let offset = start;
|
|
37
|
+
let more = true;
|
|
38
|
+
for (let i = 0; i < PR_PAGES && more; i++) {
|
|
39
|
+
const page = await client.get("/weightlifting-service/v3/prs", offset ? { offset } : {});
|
|
40
|
+
pages.push(page);
|
|
41
|
+
more = get(page, "show_more") === true;
|
|
42
|
+
const next = Number(get(page, "next_exercise_offset"));
|
|
43
|
+
offset = Number.isFinite(next) && next > offset ? next : offset + 10;
|
|
44
|
+
}
|
|
45
|
+
return { mode: "prs" as const, cols: PR_COLS, prs: prRows(pages), next: more ? String(offset) : null, warnings: [] };
|
|
46
|
+
}
|
|
9
47
|
|
|
10
48
|
export function registerLiftExercise(server: McpServer, client: WhoopClient): void {
|
|
11
|
-
server
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
49
|
+
defineTool(server, {
|
|
50
|
+
name: TOOL,
|
|
51
|
+
description:
|
|
52
|
+
"One exercise by exercise_id or name: metadata, workout history, medal records and 1RM (manual entries carry the entry_id " +
|
|
53
|
+
"whoop_lift_exercise_set takes). With neither: your PR list. Weights are in unit. cursor takes a returned next.",
|
|
54
|
+
input: {
|
|
55
|
+
exercise_id: z.string().optional().describe("e.g. BENCHPRESS_BARBELL"),
|
|
56
|
+
name: z.string().optional().describe("Exact name"),
|
|
57
|
+
include: z.array(z.enum(INCLUDES)).optional().describe("Default history, records, one_rep_max"),
|
|
58
|
+
cursor: z.string().optional(),
|
|
59
|
+
end_date: z.iso.date().optional().describe("For progression"),
|
|
16
60
|
},
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
61
|
+
annotations: READ_ONLY,
|
|
62
|
+
}, async ({ exercise_id, name, include, cursor, end_date }) => {
|
|
63
|
+
if (!exercise_id && !name) return respond(TOOL, LiftExerciseOutV2, await prList(client, cursor));
|
|
64
|
+
|
|
65
|
+
const warnings: string[] = [];
|
|
66
|
+
const wanted = new Set<Include>(include ?? ["history", "records", "one_rep_max"]);
|
|
67
|
+
const resolver = new ExerciseResolver(client);
|
|
68
|
+
let id = exercise_id?.trim();
|
|
69
|
+
let catalogRow: unknown = null;
|
|
70
|
+
if (!id) {
|
|
71
|
+
const r = await resolver.resolve({ name });
|
|
72
|
+
if (!r.ok) return liftError({ error: r.error, suggestions: r.suggestions });
|
|
73
|
+
id = r.exercise.exercise_id;
|
|
74
|
+
catalogRow = r.exercise.row;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
let meta;
|
|
78
|
+
try {
|
|
79
|
+
// v1 answers for catalog ids, custom UUIDs and soft-deleted customs.
|
|
80
|
+
meta = exerciseMeta(await client.get(`/weightlifting-service/v1/exercise/${encodeURIComponent(id)}`), wanted.has("instructions"));
|
|
81
|
+
} catch (e) {
|
|
82
|
+
if (!catalogRow) {
|
|
83
|
+
const r = await resolver.resolve({ exercise_id: id });
|
|
84
|
+
if (!r.ok) return liftError({ error: r.error, suggestions: r.suggestions });
|
|
85
|
+
catalogRow = r.exercise.row;
|
|
32
86
|
}
|
|
33
|
-
|
|
34
|
-
|
|
87
|
+
meta = exerciseMeta(catalogRow, wanted.has("instructions"));
|
|
88
|
+
warnings.push(`Exercise detail failed (${errorMessage(e)}); metadata from the catalog.`);
|
|
89
|
+
}
|
|
90
|
+
if (meta.deleted) warnings.push("This custom exercise is deleted.");
|
|
91
|
+
|
|
92
|
+
const enc = encodeURIComponent(id);
|
|
93
|
+
const base = `/weightlifting-service/v3/exercise/${enc}`;
|
|
94
|
+
const orm = `/weightlifting-service/v3/one-rep-max/${enc}`;
|
|
95
|
+
const tasks: Array<[string, () => Promise<unknown>]> = [];
|
|
96
|
+
if (wanted.has("history")) tasks.push(["history", () => client.get(`${base}/exercise_history`, cursor ? { startDate: cursor } : {})]);
|
|
97
|
+
if (wanted.has("records")) tasks.push(["records", () => client.get(`${base}/personal_records`)]);
|
|
98
|
+
if (wanted.has("one_rep_max")) {
|
|
99
|
+
tasks.push(["1rm", () => client.get(orm)]);
|
|
100
|
+
tasks.push(["1rm history", () => client.get(`${orm}/history`)]);
|
|
101
|
+
}
|
|
102
|
+
if (wanted.has("progression")) tasks.push(["progression", () => client.get(`/progression-service/v3/exercise/${enc}`, { endDate: end_date ?? todayIso() })]);
|
|
103
|
+
const results = new Map(
|
|
104
|
+
(await runPaced(tasks.map(([key, load]) => async () => {
|
|
105
|
+
try {
|
|
106
|
+
return [key, await load()] as const;
|
|
107
|
+
} catch (e) {
|
|
108
|
+
warnings.push(`${key} failed: ${errorMessage(e)}`);
|
|
109
|
+
return [key, undefined] as const;
|
|
110
|
+
}
|
|
111
|
+
}), { concurrency: 3, jitterMaxMs: 80 })),
|
|
112
|
+
);
|
|
113
|
+
const got = (key: string) => results.get(key);
|
|
114
|
+
|
|
115
|
+
let unit: "kg" | "lb" | null = null;
|
|
116
|
+
const out: Record<string, unknown> = { mode: "exercise", exercise: meta };
|
|
117
|
+
if (got("history") !== undefined) {
|
|
118
|
+
const { cards, next_cursor } = parseLiftCards(got("history"));
|
|
119
|
+
unit = cardsUnit(cards);
|
|
120
|
+
out.history = { sessions: cards.map(historySession), next: next_cursor };
|
|
121
|
+
}
|
|
122
|
+
if (got("records") !== undefined) {
|
|
123
|
+
const { cards } = parseLiftCards(got("records"));
|
|
124
|
+
unit = unit ?? cardsUnit(cards);
|
|
125
|
+
out.records = cards.map((c) => ({ medal: c.medal, date: c.date, value: c.record.value }));
|
|
126
|
+
out.record_unit = cards[0]?.record.unit ?? null;
|
|
127
|
+
}
|
|
128
|
+
if (wanted.has("one_rep_max")) {
|
|
129
|
+
if (got("1rm") === undefined) out.one_rep_max = null;
|
|
130
|
+
else {
|
|
131
|
+
const { unit: ormUnit, ...card } = oneRepMaxCard(got("1rm"));
|
|
132
|
+
unit = unit ?? ormUnit;
|
|
133
|
+
const history = got("1rm history") === undefined ? undefined : oneRepMaxRows(oneRepMaxEntries(got("1rm history")));
|
|
134
|
+
out.one_rep_max = history ? { ...card, history } : card;
|
|
135
|
+
if (meta.e1rm === false) warnings.push("Not e1RM-eligible: WHOOP shows only manual 1RM entries.");
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
if (wanted.has("progression")) out.progression = got("progression") === undefined ? null : progressionRows(got("progression"));
|
|
139
|
+
out.unit = unit;
|
|
140
|
+
out.warnings = warnings;
|
|
141
|
+
return respond(TOOL, LiftExerciseOutV2, out);
|
|
142
|
+
});
|
|
35
143
|
}
|