@thebriangao/totem 1.4.4 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.dev.vars.example +5 -0
- package/.dockerignore +5 -0
- package/.env.example +29 -20
- package/CHANGELOG.md +99 -1
- package/CONTRIBUTING.md +48 -116
- package/Dockerfile +46 -12
- package/README.md +172 -498
- package/SECURITY.md +36 -59
- package/TOOLS.md +448 -311
- package/WHOOP.md +497 -2659
- package/assets/brand/SOURCES.md +38 -0
- package/assets/brand/totem.png +0 -0
- package/assets/brand/totem.svg +13 -0
- package/assets/fonts/Manrope-OFL.txt +93 -0
- package/assets/fonts/manrope-latin.woff2 +0 -0
- package/dist/build_info.js +5 -0
- package/dist/build_info.js.map +1 -0
- package/dist/cli/app.js +675 -0
- package/dist/cli/app.js.map +1 -0
- package/dist/cli/auth.js +297 -0
- package/dist/cli/auth.js.map +1 -0
- package/dist/cli/auth_flow.js +268 -0
- package/dist/cli/auth_flow.js.map +1 -0
- package/dist/cli/browser_login.js +368 -0
- package/dist/cli/browser_login.js.map +1 -0
- package/dist/cli/clients.js +403 -0
- package/dist/cli/clients.js.map +1 -0
- package/dist/cli/deploy_record.js +96 -0
- package/dist/cli/deploy_record.js.map +1 -0
- package/dist/cli/index.js +39 -575
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/links.js +28 -0
- package/dist/cli/links.js.map +1 -0
- package/dist/cli/logo.js +63 -0
- package/dist/cli/logo.js.map +1 -0
- package/dist/cli/setup.js +1157 -1017
- package/dist/cli/setup.js.map +1 -1
- package/dist/cli/spawn.js +80 -0
- package/dist/cli/spawn.js.map +1 -0
- package/dist/cli/sys.js +219 -0
- package/dist/cli/sys.js.map +1 -0
- package/dist/cli/ui.js +712 -463
- package/dist/cli/ui.js.map +1 -1
- package/dist/cli/update.js +425 -282
- package/dist/cli/update.js.map +1 -1
- package/dist/cloudflare/token_store.js +48 -0
- package/dist/cloudflare/token_store.js.map +1 -0
- package/dist/cloudflare/worker.js +155 -0
- package/dist/cloudflare/worker.js.map +1 -0
- package/dist/data/behaviors.js +2733 -617
- package/dist/data/behaviors.js.map +1 -1
- package/dist/data/endpoint_catalog.js +2681 -0
- package/dist/data/endpoint_catalog.js.map +1 -0
- package/dist/data/exercises.js +373 -4859
- package/dist/data/exercises.js.map +1 -1
- package/dist/data/garments.js +19 -0
- package/dist/data/garments.js.map +1 -0
- package/dist/data/sports.js +219 -208
- package/dist/data/sports.js.map +1 -1
- package/dist/lib/activity_list.js +123 -0
- package/dist/lib/activity_list.js.map +1 -0
- package/dist/lib/activity_records.js +195 -0
- package/dist/lib/activity_records.js.map +1 -0
- package/dist/lib/activity_results.js +44 -0
- package/dist/lib/activity_results.js.map +1 -0
- package/dist/lib/activity_types.js +164 -0
- package/dist/lib/activity_types.js.map +1 -0
- package/dist/lib/brand.js +63 -0
- package/dist/lib/brand.js.map +1 -0
- package/dist/lib/clock.js +24 -0
- package/dist/lib/clock.js.map +1 -0
- package/dist/lib/coach_session.js +345 -0
- package/dist/lib/coach_session.js.map +1 -0
- package/dist/lib/concurrency.js.map +1 -1
- package/dist/lib/dates.js +19 -0
- package/dist/lib/dates.js.map +1 -1
- package/dist/lib/env_file.js +195 -0
- package/dist/lib/env_file.js.map +1 -0
- package/dist/lib/health_plans_write.js +44 -0
- package/dist/lib/health_plans_write.js.map +1 -0
- package/dist/lib/heart_rate.js +34 -0
- package/dist/lib/heart_rate.js.map +1 -0
- package/dist/lib/highlight.js +81 -0
- package/dist/lib/highlight.js.map +1 -0
- package/dist/lib/install_links.js +47 -0
- package/dist/lib/install_links.js.map +1 -0
- package/dist/lib/instant.js +50 -0
- package/dist/lib/instant.js.map +1 -0
- package/dist/lib/journal_behaviors.js +382 -0
- package/dist/lib/journal_behaviors.js.map +1 -0
- package/dist/lib/lift_catalog.js +218 -0
- package/dist/lib/lift_catalog.js.map +1 -0
- package/dist/lib/lift_history.js +66 -0
- package/dist/lib/lift_history.js.map +1 -0
- package/dist/lib/lift_sets.js +146 -0
- package/dist/lib/lift_sets.js.map +1 -0
- package/dist/lib/lift_tool.js +20 -0
- package/dist/lib/lift_tool.js.map +1 -0
- package/dist/lib/profile_settings.js +101 -0
- package/dist/lib/profile_settings.js.map +1 -0
- package/dist/lib/screen_content.js +44 -0
- package/dist/lib/screen_content.js.map +1 -0
- package/dist/lib/timezone.js +48 -6
- package/dist/lib/timezone.js.map +1 -1
- package/dist/lib/walk.js +6 -1
- package/dist/lib/walk.js.map +1 -1
- package/dist/lib/weight_readings.js +61 -0
- package/dist/lib/weight_readings.js.map +1 -0
- package/dist/projections/activities.js +193 -0
- package/dist/projections/activities.js.map +1 -0
- package/dist/projections/alarm_schedule.js +102 -0
- package/dist/projections/alarm_schedule.js.map +1 -0
- package/dist/projections/coach.js +203 -0
- package/dist/projections/coach.js.map +1 -0
- package/dist/projections/community.js +165 -0
- package/dist/projections/community.js.map +1 -0
- package/dist/projections/health_features.js +167 -0
- package/dist/projections/health_features.js.map +1 -0
- package/dist/projections/hormonal_insights.js +239 -0
- package/dist/projections/hormonal_insights.js.map +1 -0
- package/dist/projections/journal_v2.js +157 -0
- package/dist/projections/journal_v2.js.map +1 -0
- package/dist/projections/lift_cards.js +115 -0
- package/dist/projections/lift_cards.js.map +1 -0
- package/dist/projections/lift_exercise_v2.js +131 -0
- package/dist/projections/lift_exercise_v2.js.map +1 -0
- package/dist/projections/lift_library_v2.js +67 -0
- package/dist/projections/lift_library_v2.js.map +1 -0
- package/dist/projections/lift_sessions.js +211 -0
- package/dist/projections/lift_sessions.js.map +1 -0
- package/dist/projections/memory.js +95 -0
- package/dist/projections/memory.js.map +1 -0
- package/dist/projections/milestones.js +119 -0
- package/dist/projections/milestones.js.map +1 -0
- package/dist/projections/profile_v2.js +150 -0
- package/dist/projections/profile_v2.js.map +1 -0
- package/dist/projections/settings_v2.js +153 -0
- package/dist/projections/settings_v2.js.map +1 -0
- package/dist/projections/sleep.js +4 -21
- package/dist/projections/sleep.js.map +1 -1
- package/dist/projections/v2/calendar.js +43 -0
- package/dist/projections/v2/calendar.js.map +1 -0
- package/dist/projections/v2/core_common.js +86 -0
- package/dist/projections/v2/core_common.js.map +1 -0
- package/dist/projections/v2/core_home.js +136 -0
- package/dist/projections/v2/core_home.js.map +1 -0
- package/dist/projections/v2/core_sleep_need.js +23 -0
- package/dist/projections/v2/core_sleep_need.js.map +1 -0
- package/dist/projections/v2/day.js +92 -0
- package/dist/projections/v2/day.js.map +1 -0
- package/dist/projections/v2/heart_rate.js +54 -0
- package/dist/projections/v2/heart_rate.js.map +1 -0
- package/dist/projections/v2/history.js +140 -0
- package/dist/projections/v2/history.js.map +1 -0
- package/dist/projections/v2/now.js +39 -0
- package/dist/projections/v2/now.js.map +1 -0
- package/dist/projections/v2/recovery.js +77 -0
- package/dist/projections/v2/recovery.js.map +1 -0
- package/dist/projections/v2/sleep.js +218 -0
- package/dist/projections/v2/sleep.js.map +1 -0
- package/dist/projections/v2/strain.js +39 -0
- package/dist/projections/v2/strain.js.map +1 -0
- package/dist/projections/v2/stress.js +92 -0
- package/dist/projections/v2/stress.js.map +1 -0
- package/dist/projections/v2/trend.js +205 -0
- package/dist/projections/v2/trend.js.map +1 -0
- package/dist/projections/weekly_plan.js +66 -0
- package/dist/projections/weekly_plan.js.map +1 -0
- package/dist/projections/weight_readings.js +57 -0
- package/dist/projections/weight_readings.js.map +1 -0
- package/dist/projections/workout.js +37 -15
- package/dist/projections/workout.js.map +1 -1
- package/dist/schemas/activities.js +123 -0
- package/dist/schemas/activities.js.map +1 -0
- package/dist/schemas/alarm_schedule.js +62 -0
- package/dist/schemas/alarm_schedule.js.map +1 -0
- package/dist/schemas/coach.js +76 -8
- package/dist/schemas/coach.js.map +1 -1
- package/dist/schemas/community.js +70 -0
- package/dist/schemas/community.js.map +1 -0
- package/dist/schemas/health.js +36 -0
- package/dist/schemas/health.js.map +1 -0
- package/dist/schemas/hormonal_insights.js +90 -0
- package/dist/schemas/hormonal_insights.js.map +1 -0
- package/dist/schemas/journal.js +4 -0
- package/dist/schemas/journal.js.map +1 -1
- package/dist/schemas/journal_v2.js +106 -0
- package/dist/schemas/journal_v2.js.map +1 -0
- package/dist/schemas/memory.js +42 -0
- package/dist/schemas/memory.js.map +1 -0
- package/dist/schemas/milestones.js +39 -0
- package/dist/schemas/milestones.js.map +1 -0
- package/dist/schemas/profile_v2.js +60 -0
- package/dist/schemas/profile_v2.js.map +1 -0
- package/dist/schemas/settings_v2.js +56 -0
- package/dist/schemas/settings_v2.js.map +1 -0
- package/dist/schemas/sleep.js +8 -1
- package/dist/schemas/sleep.js.map +1 -1
- package/dist/schemas/strength.js +10 -1
- package/dist/schemas/strength.js.map +1 -1
- package/dist/schemas/strength_v2.js +190 -0
- package/dist/schemas/strength_v2.js.map +1 -0
- package/dist/schemas/v2/calendar.js +8 -0
- package/dist/schemas/v2/calendar.js.map +1 -0
- package/dist/schemas/v2/core_common.js +42 -0
- package/dist/schemas/v2/core_common.js.map +1 -0
- package/dist/schemas/v2/day.js +73 -0
- package/dist/schemas/v2/day.js.map +1 -0
- package/dist/schemas/v2/now.js +25 -0
- package/dist/schemas/v2/now.js.map +1 -0
- package/dist/schemas/v2/recovery.js +35 -0
- package/dist/schemas/v2/recovery.js.map +1 -0
- package/dist/schemas/v2/sleep.js +44 -0
- package/dist/schemas/v2/sleep.js.map +1 -0
- package/dist/schemas/v2/strain.js +16 -0
- package/dist/schemas/v2/strain.js.map +1 -0
- package/dist/schemas/v2/stress.js +20 -0
- package/dist/schemas/v2/stress.js.map +1 -0
- package/dist/schemas/v2/trend.js +42 -0
- package/dist/schemas/v2/trend.js.map +1 -0
- package/dist/schemas/weekly_plan.js +31 -0
- package/dist/schemas/weekly_plan.js.map +1 -0
- package/dist/schemas/weight.js +28 -0
- package/dist/schemas/weight.js.map +1 -0
- package/dist/scripts/build_behaviors.js +114 -0
- package/dist/scripts/build_behaviors.js.map +1 -0
- package/dist/scripts/cognito_bootstrap.js +9 -277
- package/dist/scripts/cognito_bootstrap.js.map +1 -1
- package/dist/scripts/gen_activity_catalogs.js +104 -0
- package/dist/scripts/gen_activity_catalogs.js.map +1 -0
- package/dist/server-admin.js +156 -0
- package/dist/server-admin.js.map +1 -0
- package/dist/server-http.js +270 -48
- package/dist/server-http.js.map +1 -1
- package/dist/server.js +136 -23
- package/dist/server.js.map +1 -1
- package/dist/tools/annotations.js +15 -0
- package/dist/tools/annotations.js.map +1 -0
- package/dist/tools/define.js +31 -0
- package/dist/tools/define.js.map +1 -0
- package/dist/tools/register.js +59 -94
- package/dist/tools/register.js.map +1 -1
- package/dist/tools/resources.js +70 -0
- package/dist/tools/resources.js.map +1 -0
- package/dist/tools/slim_schema.js +90 -0
- package/dist/tools/slim_schema.js.map +1 -0
- package/dist/tools/v2/activity_delete.js +63 -17
- package/dist/tools/v2/activity_delete.js.map +1 -1
- package/dist/tools/v2/activity_edit.js +396 -0
- package/dist/tools/v2/activity_edit.js.map +1 -0
- package/dist/tools/v2/activity_log.js +152 -0
- package/dist/tools/v2/activity_log.js.map +1 -0
- package/dist/tools/v2/calendar.js +19 -21
- package/dist/tools/v2/calendar.js.map +1 -1
- package/dist/tools/v2/coach_ask.js +74 -110
- package/dist/tools/v2/coach_ask.js.map +1 -1
- package/dist/tools/v2/coach_history.js +120 -0
- package/dist/tools/v2/coach_history.js.map +1 -0
- package/dist/tools/v2/community.js +124 -0
- package/dist/tools/v2/community.js.map +1 -0
- package/dist/tools/v2/cycle.js +63 -15
- package/dist/tools/v2/cycle.js.map +1 -1
- package/dist/tools/v2/cycle_log.js +289 -32
- package/dist/tools/v2/cycle_log.js.map +1 -1
- package/dist/tools/v2/day.js +126 -24
- package/dist/tools/v2/day.js.map +1 -1
- package/dist/tools/v2/health.js +116 -0
- package/dist/tools/v2/health.js.map +1 -0
- package/dist/tools/v2/hr_zones_set.js +134 -34
- package/dist/tools/v2/hr_zones_set.js.map +1 -1
- package/dist/tools/v2/journal.js +75 -17
- package/dist/tools/v2/journal.js.map +1 -1
- package/dist/tools/v2/journal_log.js +306 -65
- package/dist/tools/v2/journal_log.js.map +1 -1
- package/dist/tools/v2/lift_exercise.js +125 -22
- package/dist/tools/v2/lift_exercise.js.map +1 -1
- package/dist/tools/v2/lift_exercise_set.js +291 -0
- package/dist/tools/v2/lift_exercise_set.js.map +1 -0
- package/dist/tools/v2/lift_library.js +51 -12
- package/dist/tools/v2/lift_library.js.map +1 -1
- package/dist/tools/v2/lift_log.js +309 -72
- package/dist/tools/v2/lift_log.js.map +1 -1
- package/dist/tools/v2/lift_sessions.js +248 -0
- package/dist/tools/v2/lift_sessions.js.map +1 -0
- package/dist/tools/v2/lift_template.js +232 -0
- package/dist/tools/v2/lift_template.js.map +1 -0
- package/dist/tools/v2/memory.js +45 -0
- package/dist/tools/v2/memory.js.map +1 -0
- package/dist/tools/v2/memory_set.js +107 -0
- package/dist/tools/v2/memory_set.js.map +1 -0
- package/dist/tools/v2/milestones.js +50 -0
- package/dist/tools/v2/milestones.js.map +1 -0
- package/dist/tools/v2/now.js +49 -0
- package/dist/tools/v2/now.js.map +1 -0
- package/dist/tools/v2/preferences.js +51 -0
- package/dist/tools/v2/preferences.js.map +1 -0
- package/dist/tools/v2/preferences_set.js +388 -0
- package/dist/tools/v2/preferences_set.js.map +1 -0
- package/dist/tools/v2/profile.js +54 -22
- package/dist/tools/v2/profile.js.map +1 -1
- package/dist/tools/v2/profile_update.js +167 -55
- package/dist/tools/v2/profile_update.js.map +1 -1
- package/dist/tools/v2/raw.js +91 -34
- package/dist/tools/v2/raw.js.map +1 -1
- package/dist/tools/v2/recovery.js +37 -23
- package/dist/tools/v2/recovery.js.map +1 -1
- package/dist/tools/v2/sleep.js +52 -16
- package/dist/tools/v2/sleep.js.map +1 -1
- package/dist/tools/v2/smart_alarm.js +54 -20
- package/dist/tools/v2/smart_alarm.js.map +1 -1
- package/dist/tools/v2/smart_alarm_set.js +264 -86
- package/dist/tools/v2/smart_alarm_set.js.map +1 -1
- package/dist/tools/v2/strain.js +15 -15
- package/dist/tools/v2/strain.js.map +1 -1
- package/dist/tools/v2/stress.js +17 -15
- package/dist/tools/v2/stress.js.map +1 -1
- package/dist/tools/v2/trend.js +56 -20
- package/dist/tools/v2/trend.js.map +1 -1
- package/dist/tools/v2/weekly_plan.js +30 -0
- package/dist/tools/v2/weekly_plan.js.map +1 -0
- package/dist/tools/v2/weekly_plan_set.js +134 -0
- package/dist/tools/v2/weekly_plan_set.js.map +1 -0
- package/dist/tools/v2/weight.js +56 -0
- package/dist/tools/v2/weight.js.map +1 -0
- package/dist/tools/v2/weight_log.js +188 -0
- package/dist/tools/v2/weight_log.js.map +1 -0
- package/dist/tools/v2/workouts.js +159 -25
- package/dist/tools/v2/workouts.js.map +1 -1
- package/dist/version.js +6 -0
- package/dist/version.js.map +1 -0
- package/dist/whoop/bff.js +94 -0
- package/dist/whoop/bff.js.map +1 -0
- package/dist/whoop/client.js +392 -18
- package/dist/whoop/client.js.map +1 -1
- package/dist/whoop/cognito.js +106 -79
- package/dist/whoop/cognito.js.map +1 -1
- package/dist/whoop/connect_page.js +165 -0
- package/dist/whoop/connect_page.js.map +1 -0
- package/dist/whoop/consent_font.js +287 -0
- package/dist/whoop/consent_font.js.map +1 -0
- package/dist/whoop/consent_logos.js +22 -0
- package/dist/whoop/consent_logos.js.map +1 -0
- package/dist/whoop/consent_page.js +291 -0
- package/dist/whoop/consent_page.js.map +1 -0
- package/dist/whoop/constants.js +5 -1
- package/dist/whoop/constants.js.map +1 -1
- package/dist/whoop/device.js +4 -4
- package/dist/whoop/device.js.map +1 -1
- package/dist/whoop/errors.js +85 -4
- package/dist/whoop/errors.js.map +1 -1
- package/dist/whoop/init_timezone.js +57 -17
- package/dist/whoop/init_timezone.js.map +1 -1
- package/dist/whoop/installation.js +15 -10
- package/dist/whoop/installation.js.map +1 -1
- package/dist/whoop/json_out.js +52 -6
- package/dist/whoop/json_out.js.map +1 -1
- package/dist/whoop/oauth_provider.js +81 -78
- package/dist/whoop/oauth_provider.js.map +1 -1
- package/dist/whoop/token_lock.js +331 -0
- package/dist/whoop/token_lock.js.map +1 -0
- package/dist/whoop/token_manager.js +536 -42
- package/dist/whoop/token_manager.js.map +1 -1
- package/dist/whoop/token_store.js +303 -36
- package/dist/whoop/token_store.js.map +1 -1
- package/dist/whoop/units.js +28 -0
- package/dist/whoop/units.js.map +1 -0
- package/package.json +29 -13
- package/scripts/build-mcpb.mjs +72 -0
- package/scripts/embed-consent-font.mjs +34 -0
- package/scripts/readme-media.ts +195 -0
- package/scripts/tools-md.ts +89 -0
- package/scripts/whoop-md.ts +119 -0
- package/src/build_info.ts +4 -0
- package/src/cli/app.ts +696 -0
- package/src/cli/auth.ts +350 -0
- package/src/cli/auth_flow.ts +356 -0
- package/src/cli/browser_login.ts +402 -0
- package/src/cli/clients.ts +467 -0
- package/src/cli/deploy_record.ts +100 -0
- package/src/cli/index.ts +41 -583
- package/src/cli/links.ts +43 -0
- package/src/cli/logo.ts +64 -0
- package/src/cli/setup.ts +1147 -979
- package/src/cli/spawn.ts +88 -0
- package/src/cli/sys.ts +267 -0
- package/src/cli/ui.ts +778 -436
- package/src/cli/update.ts +436 -274
- package/src/cloudflare/runtime.d.ts +27 -0
- package/src/cloudflare/token_store.ts +57 -0
- package/src/cloudflare/worker.ts +174 -0
- package/src/data/behaviors.ts +2760 -622
- package/src/data/endpoint_catalog.ts +2695 -0
- package/src/data/exercises.ts +379 -4861
- package/src/data/garments.ts +28 -0
- package/src/data/sports.ts +239 -211
- package/src/lib/activity_list.ts +150 -0
- package/src/lib/activity_records.ts +213 -0
- package/src/lib/activity_results.ts +51 -0
- package/src/lib/activity_types.ts +176 -0
- package/src/lib/brand.ts +71 -0
- package/src/lib/clock.ts +16 -0
- package/src/lib/coach_session.ts +434 -0
- package/src/lib/dates.ts +18 -0
- package/src/lib/env_file.ts +191 -0
- package/src/lib/health_plans_write.ts +53 -0
- package/src/lib/heart_rate.ts +42 -0
- package/src/lib/highlight.ts +71 -0
- package/src/lib/install_links.ts +61 -0
- package/src/lib/instant.ts +54 -0
- package/src/lib/journal_behaviors.ts +453 -0
- package/src/lib/lift_catalog.ts +258 -0
- package/src/lib/lift_history.ts +75 -0
- package/src/lib/lift_sets.ts +164 -0
- package/src/lib/lift_tool.ts +25 -0
- package/src/lib/profile_settings.ts +102 -0
- package/src/lib/screen_content.ts +40 -0
- package/src/lib/timezone.ts +44 -8
- package/src/lib/walk.ts +4 -1
- package/src/lib/weight_readings.ts +82 -0
- package/src/projections/activities.ts +199 -0
- package/src/projections/alarm_schedule.ts +98 -0
- package/src/projections/coach.ts +218 -0
- package/src/projections/community.ts +187 -0
- package/src/projections/health_features.ts +191 -0
- package/src/projections/hormonal_insights.ts +277 -0
- package/src/projections/journal_v2.ts +173 -0
- package/src/projections/lift_cards.ts +131 -0
- package/src/projections/lift_exercise_v2.ts +147 -0
- package/src/projections/lift_library_v2.ts +77 -0
- package/src/projections/lift_sessions.ts +250 -0
- package/src/projections/memory.ts +100 -0
- package/src/projections/milestones.ts +133 -0
- package/src/projections/profile_v2.ts +166 -0
- package/src/projections/settings_v2.ts +179 -0
- package/src/projections/sleep.ts +7 -21
- package/src/projections/v2/calendar.ts +48 -0
- package/src/projections/v2/core_common.ts +95 -0
- package/src/projections/v2/core_home.ts +177 -0
- package/src/projections/v2/core_sleep_need.ts +37 -0
- package/src/projections/v2/day.ts +162 -0
- package/src/projections/v2/heart_rate.ts +73 -0
- package/src/projections/v2/history.ts +153 -0
- package/src/projections/v2/now.ts +59 -0
- package/src/projections/v2/recovery.ts +120 -0
- package/src/projections/v2/sleep.ts +281 -0
- package/src/projections/v2/strain.ts +63 -0
- package/src/projections/v2/stress.ts +111 -0
- package/src/projections/v2/trend.ts +242 -0
- package/src/projections/weekly_plan.ts +79 -0
- package/src/projections/weight_readings.ts +57 -0
- package/src/projections/workout.ts +36 -17
- package/src/schemas/activities.ts +136 -0
- package/src/schemas/alarm_schedule.ts +70 -0
- package/src/schemas/coach.ts +98 -8
- package/src/schemas/community.ts +77 -0
- package/src/schemas/health.ts +36 -0
- package/src/schemas/hormonal_insights.ts +108 -0
- package/src/schemas/journal.ts +4 -0
- package/src/schemas/journal_v2.ts +112 -0
- package/src/schemas/memory.ts +48 -0
- package/src/schemas/milestones.ts +48 -0
- package/src/schemas/profile_v2.ts +63 -0
- package/src/schemas/settings_v2.ts +63 -0
- package/src/schemas/sleep.ts +9 -1
- package/src/schemas/strength.ts +10 -1
- package/src/schemas/strength_v2.ts +210 -0
- package/src/schemas/v2/calendar.ts +8 -0
- package/src/schemas/v2/core_common.ts +50 -0
- package/src/schemas/v2/day.ts +79 -0
- package/src/schemas/v2/now.ts +25 -0
- package/src/schemas/v2/recovery.ts +38 -0
- package/src/schemas/v2/sleep.ts +46 -0
- package/src/schemas/v2/strain.ts +16 -0
- package/src/schemas/v2/stress.ts +20 -0
- package/src/schemas/v2/trend.ts +45 -0
- package/src/schemas/weekly_plan.ts +36 -0
- package/src/schemas/weight.ts +53 -0
- package/src/scripts/build_behaviors.ts +116 -0
- package/src/scripts/cognito_bootstrap.ts +10 -249
- package/src/scripts/gen_activity_catalogs.ts +121 -0
- package/src/server-admin.ts +171 -0
- package/src/server-http.ts +290 -53
- package/src/server.ts +130 -26
- package/src/tools/annotations.ts +25 -0
- package/src/tools/define.ts +53 -0
- package/src/tools/register.ts +64 -94
- package/src/tools/resources.ts +92 -0
- package/src/tools/slim_schema.ts +102 -0
- package/src/tools/v2/activity_delete.ts +61 -23
- package/src/tools/v2/activity_edit.ts +378 -0
- package/src/tools/v2/activity_log.ts +154 -0
- package/src/tools/v2/calendar.ts +22 -21
- package/src/tools/v2/coach_ask.ts +83 -119
- package/src/tools/v2/coach_history.ts +140 -0
- package/src/tools/v2/community.ts +137 -0
- package/src/tools/v2/cycle.ts +78 -20
- package/src/tools/v2/cycle_log.ts +291 -40
- package/src/tools/v2/day.ts +126 -25
- package/src/tools/v2/health.ts +114 -0
- package/src/tools/v2/hr_zones_set.ts +132 -45
- package/src/tools/v2/journal.ts +78 -23
- package/src/tools/v2/journal_log.ts +321 -69
- package/src/tools/v2/lift_exercise.ts +135 -27
- package/src/tools/v2/lift_exercise_set.ts +272 -0
- package/src/tools/v2/lift_library.ts +57 -21
- package/src/tools/v2/lift_log.ts +325 -83
- package/src/tools/v2/lift_sessions.ts +255 -0
- package/src/tools/v2/lift_template.ts +229 -0
- package/src/tools/v2/memory.ts +54 -0
- package/src/tools/v2/memory_set.ts +110 -0
- package/src/tools/v2/milestones.ts +59 -0
- package/src/tools/v2/now.ts +61 -0
- package/src/tools/v2/preferences.ts +61 -0
- package/src/tools/v2/preferences_set.ts +403 -0
- package/src/tools/v2/profile.ts +56 -26
- package/src/tools/v2/profile_update.ts +151 -60
- package/src/tools/v2/raw.ts +89 -36
- package/src/tools/v2/recovery.ts +44 -25
- package/src/tools/v2/sleep.ts +57 -18
- package/src/tools/v2/smart_alarm.ts +62 -24
- package/src/tools/v2/smart_alarm_set.ts +240 -90
- package/src/tools/v2/strain.ts +19 -16
- package/src/tools/v2/stress.ts +22 -17
- package/src/tools/v2/trend.ts +58 -20
- package/src/tools/v2/weekly_plan.ts +38 -0
- package/src/tools/v2/weekly_plan_set.ts +132 -0
- package/src/tools/v2/weight.ts +61 -0
- package/src/tools/v2/weight_log.ts +193 -0
- package/src/tools/v2/workouts.ts +156 -26
- package/src/version.ts +5 -0
- package/src/whoop/bff.ts +84 -0
- package/src/whoop/client.ts +448 -18
- package/src/whoop/cognito.ts +110 -99
- package/src/whoop/connect_page.ts +183 -0
- package/src/whoop/consent_font.ts +289 -0
- package/src/whoop/consent_logos.ts +24 -0
- package/src/whoop/consent_page.ts +326 -0
- package/src/whoop/constants.ts +5 -1
- package/src/whoop/device.ts +4 -4
- package/src/whoop/errors.ts +89 -4
- package/src/whoop/init_timezone.ts +57 -16
- package/src/whoop/installation.ts +16 -7
- package/src/whoop/json_out.ts +51 -6
- package/src/whoop/oauth_provider.ts +84 -91
- package/src/whoop/token_lock.ts +345 -0
- package/src/whoop/token_manager.ts +580 -53
- package/src/whoop/token_store.ts +341 -32
- package/src/whoop/units.ts +35 -0
- package/wrangler.jsonc +17 -0
- package/assets/banner.svg +0 -38
- package/dist/data/endpoints.js +0 -320
- package/dist/data/endpoints.js.map +0 -1
- package/dist/lib/format.js +0 -22
- package/dist/lib/format.js.map +0 -1
- package/dist/lib/stats.js +0 -32
- package/dist/lib/stats.js.map +0 -1
- package/dist/projections/calendar.js +0 -33
- package/dist/projections/calendar.js.map +0 -1
- package/dist/projections/communities.js +0 -105
- package/dist/projections/communities.js.map +0 -1
- package/dist/projections/cycle.js +0 -81
- package/dist/projections/cycle.js.map +0 -1
- package/dist/projections/hr_zones.js +0 -35
- package/dist/projections/hr_zones.js.map +0 -1
- package/dist/projections/journal.js +0 -56
- package/dist/projections/journal.js.map +0 -1
- package/dist/projections/leaderboard.js +0 -37
- package/dist/projections/leaderboard.js.map +0 -1
- package/dist/projections/lift_exercise.js +0 -22
- package/dist/projections/lift_exercise.js.map +0 -1
- package/dist/projections/lift_history.js +0 -133
- package/dist/projections/lift_history.js.map +0 -1
- package/dist/projections/lift_library.js +0 -71
- package/dist/projections/lift_library.js.map +0 -1
- package/dist/projections/lift_progression.js +0 -138
- package/dist/projections/lift_progression.js.map +0 -1
- package/dist/projections/lift_prs.js +0 -20
- package/dist/projections/lift_prs.js.map +0 -1
- package/dist/projections/live_hr.js +0 -19
- package/dist/projections/live_hr.js.map +0 -1
- package/dist/projections/live_state.js +0 -23
- package/dist/projections/live_state.js.map +0 -1
- package/dist/projections/live_stress.js +0 -11
- package/dist/projections/live_stress.js.map +0 -1
- package/dist/projections/performance_assessment.js +0 -15
- package/dist/projections/performance_assessment.js.map +0 -1
- package/dist/projections/profile.js +0 -59
- package/dist/projections/profile.js.map +0 -1
- package/dist/projections/recovery.js +0 -131
- package/dist/projections/recovery.js.map +0 -1
- package/dist/projections/sleep_need.js +0 -32
- package/dist/projections/sleep_need.js.map +0 -1
- package/dist/projections/smart_alarm.js +0 -45
- package/dist/projections/smart_alarm.js.map +0 -1
- package/dist/projections/strain.js +0 -128
- package/dist/projections/strain.js.map +0 -1
- package/dist/projections/stress.js +0 -86
- package/dist/projections/stress.js.map +0 -1
- package/dist/projections/today.js +0 -129
- package/dist/projections/today.js.map +0 -1
- package/dist/projections/trend.js +0 -149
- package/dist/projections/trend.js.map +0 -1
- package/dist/projections/workouts.js +0 -37
- package/dist/projections/workouts.js.map +0 -1
- package/dist/schemas/calendar.js +0 -12
- package/dist/schemas/calendar.js.map +0 -1
- package/dist/schemas/communities.js +0 -51
- package/dist/schemas/communities.js.map +0 -1
- package/dist/schemas/compare.js +0 -15
- package/dist/schemas/compare.js.map +0 -1
- package/dist/schemas/leaderboard.js +0 -25
- package/dist/schemas/leaderboard.js.map +0 -1
- package/dist/schemas/live.js +0 -26
- package/dist/schemas/live.js.map +0 -1
- package/dist/schemas/performance.js +0 -12
- package/dist/schemas/performance.js.map +0 -1
- package/dist/schemas/profile.js +0 -39
- package/dist/schemas/profile.js.map +0 -1
- package/dist/schemas/recovery.js +0 -27
- package/dist/schemas/recovery.js.map +0 -1
- package/dist/schemas/settings.js +0 -26
- package/dist/schemas/settings.js.map +0 -1
- package/dist/schemas/sleep_need.js +0 -15
- package/dist/schemas/sleep_need.js.map +0 -1
- package/dist/schemas/smart_alarm.js +0 -36
- package/dist/schemas/smart_alarm.js.map +0 -1
- package/dist/schemas/strain.js +0 -24
- package/dist/schemas/strain.js.map +0 -1
- package/dist/schemas/stress.js +0 -16
- package/dist/schemas/stress.js.map +0 -1
- package/dist/schemas/today.js +0 -38
- package/dist/schemas/today.js.map +0 -1
- package/dist/schemas/trend.js +0 -50
- package/dist/schemas/trend.js.map +0 -1
- package/dist/schemas/womens_health.js +0 -23
- package/dist/schemas/womens_health.js.map +0 -1
- package/dist/tools/v2/activity_create.js +0 -64
- package/dist/tools/v2/activity_create.js.map +0 -1
- package/dist/tools/v2/behavior_impact.js +0 -36
- package/dist/tools/v2/behavior_impact.js.map +0 -1
- package/dist/tools/v2/communities.js +0 -60
- package/dist/tools/v2/communities.js.map +0 -1
- package/dist/tools/v2/compare.js +0 -67
- package/dist/tools/v2/compare.js.map +0 -1
- package/dist/tools/v2/endpoints.js +0 -28
- package/dist/tools/v2/endpoints.js.map +0 -1
- package/dist/tools/v2/hidden_metric.js +0 -28
- package/dist/tools/v2/hidden_metric.js.map +0 -1
- package/dist/tools/v2/hr_zones.js +0 -24
- package/dist/tools/v2/hr_zones.js.map +0 -1
- package/dist/tools/v2/journal_autopop.js +0 -19
- package/dist/tools/v2/journal_autopop.js.map +0 -1
- package/dist/tools/v2/journal_catalog.js +0 -44
- package/dist/tools/v2/journal_catalog.js.map +0 -1
- package/dist/tools/v2/leaderboard.js +0 -79
- package/dist/tools/v2/leaderboard.js.map +0 -1
- package/dist/tools/v2/lift_catalog.js +0 -47
- package/dist/tools/v2/lift_catalog.js.map +0 -1
- package/dist/tools/v2/lift_custom_exercise.js +0 -108
- package/dist/tools/v2/lift_custom_exercise.js.map +0 -1
- package/dist/tools/v2/lift_history.js +0 -39
- package/dist/tools/v2/lift_history.js.map +0 -1
- package/dist/tools/v2/lift_progression.js +0 -30
- package/dist/tools/v2/lift_progression.js.map +0 -1
- package/dist/tools/v2/lift_prs.js +0 -21
- package/dist/tools/v2/lift_prs.js.map +0 -1
- package/dist/tools/v2/lift_template_save.js +0 -83
- package/dist/tools/v2/lift_template_save.js.map +0 -1
- package/dist/tools/v2/live_hr.js +0 -21
- package/dist/tools/v2/live_hr.js.map +0 -1
- package/dist/tools/v2/live_state.js +0 -21
- package/dist/tools/v2/live_state.js.map +0 -1
- package/dist/tools/v2/live_stress.js +0 -22
- package/dist/tools/v2/live_stress.js.map +0 -1
- package/dist/tools/v2/performance_assessment.js +0 -38
- package/dist/tools/v2/performance_assessment.js.map +0 -1
- package/dist/tools/v2/sleep_need.js +0 -21
- package/dist/tools/v2/sleep_need.js.map +0 -1
- package/dist/tools/v2/sports_catalog.js +0 -26
- package/dist/tools/v2/sports_catalog.js.map +0 -1
- package/dist/tools/v2/symptom_log.js +0 -72
- package/dist/tools/v2/symptom_log.js.map +0 -1
- package/dist/tools/v2/today.js +0 -30
- package/dist/tools/v2/today.js.map +0 -1
- package/dist/tools/v2/workout.js +0 -23
- package/dist/tools/v2/workout.js.map +0 -1
- package/dist/whoop/build_lift_body.js +0 -67
- package/dist/whoop/build_lift_body.js.map +0 -1
- package/dist/whoop/session_state.js +0 -34
- package/dist/whoop/session_state.js.map +0 -1
- package/dist/whoop/types.js +0 -82
- package/dist/whoop/types.js.map +0 -1
- package/src/data/endpoints.ts +0 -319
- package/src/lib/format.ts +0 -27
- package/src/lib/stats.ts +0 -35
- package/src/projections/calendar.ts +0 -46
- package/src/projections/communities.ts +0 -135
- package/src/projections/cycle.ts +0 -85
- package/src/projections/hr_zones.ts +0 -43
- package/src/projections/journal.ts +0 -55
- package/src/projections/leaderboard.ts +0 -49
- package/src/projections/lift_exercise.ts +0 -29
- package/src/projections/lift_history.ts +0 -140
- package/src/projections/lift_library.ts +0 -70
- package/src/projections/lift_progression.ts +0 -138
- package/src/projections/lift_prs.ts +0 -23
- package/src/projections/live_hr.ts +0 -21
- package/src/projections/live_state.ts +0 -28
- package/src/projections/live_stress.ts +0 -13
- package/src/projections/performance_assessment.ts +0 -19
- package/src/projections/profile.ts +0 -71
- package/src/projections/recovery.ts +0 -133
- package/src/projections/sleep_need.ts +0 -36
- package/src/projections/smart_alarm.ts +0 -70
- package/src/projections/strain.ts +0 -131
- package/src/projections/stress.ts +0 -95
- package/src/projections/today.ts +0 -166
- package/src/projections/trend.ts +0 -149
- package/src/projections/workouts.ts +0 -36
- package/src/schemas/calendar.ts +0 -13
- package/src/schemas/communities.ts +0 -56
- package/src/schemas/compare.ts +0 -17
- package/src/schemas/leaderboard.ts +0 -26
- package/src/schemas/live.ts +0 -31
- package/src/schemas/performance.ts +0 -13
- package/src/schemas/profile.ts +0 -40
- package/src/schemas/recovery.ts +0 -28
- package/src/schemas/settings.ts +0 -30
- package/src/schemas/sleep_need.ts +0 -16
- package/src/schemas/smart_alarm.ts +0 -40
- package/src/schemas/strain.ts +0 -25
- package/src/schemas/stress.ts +0 -17
- package/src/schemas/today.ts +0 -39
- package/src/schemas/trend.ts +0 -53
- package/src/schemas/womens_health.ts +0 -26
- package/src/tools/v2/activity_create.ts +0 -74
- package/src/tools/v2/behavior_impact.ts +0 -39
- package/src/tools/v2/communities.ts +0 -65
- package/src/tools/v2/compare.ts +0 -83
- package/src/tools/v2/endpoints.ts +0 -32
- package/src/tools/v2/hidden_metric.ts +0 -33
- package/src/tools/v2/hr_zones.ts +0 -29
- package/src/tools/v2/journal_autopop.ts +0 -26
- package/src/tools/v2/journal_catalog.ts +0 -48
- package/src/tools/v2/leaderboard.ts +0 -92
- package/src/tools/v2/lift_catalog.ts +0 -48
- package/src/tools/v2/lift_custom_exercise.ts +0 -117
- package/src/tools/v2/lift_history.ts +0 -52
- package/src/tools/v2/lift_progression.ts +0 -34
- package/src/tools/v2/lift_prs.ts +0 -26
- package/src/tools/v2/lift_template_save.ts +0 -89
- package/src/tools/v2/live_hr.ts +0 -26
- package/src/tools/v2/live_state.ts +0 -26
- package/src/tools/v2/live_stress.ts +0 -27
- package/src/tools/v2/performance_assessment.ts +0 -44
- package/src/tools/v2/sleep_need.ts +0 -26
- package/src/tools/v2/sports_catalog.ts +0 -32
- package/src/tools/v2/symptom_log.ts +0 -78
- package/src/tools/v2/today.ts +0 -35
- package/src/tools/v2/workout.ts +0 -28
- package/src/whoop/build_lift_body.ts +0 -84
- package/src/whoop/session_state.ts +0 -41
- package/src/whoop/types.ts +0 -89
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
// App-native activity listing (SPEC.md D1, §4.2, §4.3): the home screen's
|
|
2
|
+
// "Today's Activities" card for each cycle day, pruned by the calendar overview.
|
|
3
|
+
// `/developer/v2/activity/workout` hides pending and incomplete activities, so it
|
|
4
|
+
// is never used for overlap checks or read-backs.
|
|
5
|
+
import type { WhoopClient } from "../whoop/client.js";
|
|
6
|
+
import { findAll, get, str } from "../whoop/bff.js";
|
|
7
|
+
import { isoDay } from "./dates.js";
|
|
8
|
+
import { runPaced } from "./concurrency.js";
|
|
9
|
+
import { toUtc } from "./activity_records.js";
|
|
10
|
+
|
|
11
|
+
export interface ActivityTile {
|
|
12
|
+
activity_id: string;
|
|
13
|
+
/** CARDIO | RECOVERY | SLEEP (the tile's `type`). */
|
|
14
|
+
score_type: string | null;
|
|
15
|
+
internal_name: string | null;
|
|
16
|
+
title: string | null;
|
|
17
|
+
/** COMPLETE | INCOMPLETE | PENDING. */
|
|
18
|
+
status: string | null;
|
|
19
|
+
/** Strain for CARDIO ("4.6", "0.0"); h:mm duration for RECOVERY and SLEEP. */
|
|
20
|
+
score_display: string | null;
|
|
21
|
+
start: string | null;
|
|
22
|
+
end: string | null;
|
|
23
|
+
/** The cycle day whose home card listed it. */
|
|
24
|
+
cycle_day: string | null;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export const HOME_PATH = "/home-service/v1/home";
|
|
28
|
+
export const CALENDAR_OVERVIEW_PATH = "/home-service/v1/calendar/overview";
|
|
29
|
+
|
|
30
|
+
/** Every ACTIVITY tile on a home screen (walks for `activity_v2_id`; index-free). */
|
|
31
|
+
export function activityTiles(home: unknown, fallbackDay: string | null = null): ActivityTile[] {
|
|
32
|
+
const cycleDay = str(get(home, "metadata", "cycle_metadata", "cycle_day")) ?? fallbackDay;
|
|
33
|
+
const seen = new Set<string>();
|
|
34
|
+
const out: ActivityTile[] = [];
|
|
35
|
+
for (const n of findAll(home, (node) => typeof node.activity_v2_id === "string")) {
|
|
36
|
+
const id = n.activity_v2_id as string;
|
|
37
|
+
if (seen.has(id)) continue;
|
|
38
|
+
seen.add(id);
|
|
39
|
+
out.push({
|
|
40
|
+
activity_id: id,
|
|
41
|
+
score_type: str(n.type),
|
|
42
|
+
internal_name: str(n.internal_name),
|
|
43
|
+
title: str(n.title),
|
|
44
|
+
status: str(n.status),
|
|
45
|
+
score_display: str(n.score_display),
|
|
46
|
+
start: toUtc(get(n, "during", "lower_endpoint")),
|
|
47
|
+
end: toUtc(get(n, "during", "upper_endpoint")),
|
|
48
|
+
cycle_day: cycleDay,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
return out;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** Days with data in the calendar month of `monthDate` ("YYYY-MM-..."), as full dates. */
|
|
55
|
+
export function calendarDataDays(raw: unknown, monthDate: string): string[] {
|
|
56
|
+
const month = monthDate.slice(0, 7);
|
|
57
|
+
const days = get(raw, "days_of_month");
|
|
58
|
+
if (!Array.isArray(days)) return [];
|
|
59
|
+
const out: string[] = [];
|
|
60
|
+
for (const d of days) {
|
|
61
|
+
const n = Number(get(d, "date_value_display"));
|
|
62
|
+
if (get(d, "has_data") === true && Number.isInteger(n) && n >= 1 && n <= 31) out.push(`${month}-${String(n).padStart(2, "0")}`);
|
|
63
|
+
}
|
|
64
|
+
return out;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function addDays(day: string, delta: number): string {
|
|
68
|
+
return new Date(Date.parse(`${day}T00:00:00Z`) + delta * 86_400_000).toISOString().slice(0, 10);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** Inclusive list of YYYY-MM-DD from start to end. */
|
|
72
|
+
export function enumerateDays(start: string, end: string): string[] {
|
|
73
|
+
const out: string[] = [];
|
|
74
|
+
for (let d = start; d <= end && out.length < 400; d = addDays(d, 1)) out.push(d);
|
|
75
|
+
return out;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export function daySpan(start: string, end: string): number {
|
|
79
|
+
return Math.round((Date.parse(`${end}T00:00:00Z`) - Date.parse(`${start}T00:00:00Z`)) / 86_400_000) + 1;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export interface TileListing {
|
|
83
|
+
tiles: ActivityTile[];
|
|
84
|
+
days_checked: string[];
|
|
85
|
+
days_failed: string[];
|
|
86
|
+
calendar_pruned: boolean;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Walk home?date= for every day in [start, end] that the calendar overview marks
|
|
91
|
+
* as having data (every day if the calendar can't be read), 3 at a time.
|
|
92
|
+
*/
|
|
93
|
+
export async function listTiles(client: WhoopClient, start: string, end: string, opts: { fresh?: boolean } = {}): Promise<TileListing> {
|
|
94
|
+
const all = enumerateDays(start, end);
|
|
95
|
+
const months = [...new Set(all.map((d) => d.slice(0, 7)))];
|
|
96
|
+
let pruned = true;
|
|
97
|
+
const withData = new Set<string>();
|
|
98
|
+
const calendars = await runPaced(months.map((m) => () =>
|
|
99
|
+
client.get(CALENDAR_OVERVIEW_PATH, { date: `${m}-01` }).then((raw) => calendarDataDays(raw, `${m}-01`)).catch(() => null)));
|
|
100
|
+
for (const days of calendars) {
|
|
101
|
+
if (days === null) pruned = false;
|
|
102
|
+
else for (const d of days) withData.add(d);
|
|
103
|
+
}
|
|
104
|
+
const days = pruned ? all.filter((d) => withData.has(d)) : all;
|
|
105
|
+
const failed: string[] = [];
|
|
106
|
+
const homes = await runPaced(days.map((day) => () =>
|
|
107
|
+
client.get(HOME_PATH, { date: day }, opts.fresh ? { fresh: true } : {})
|
|
108
|
+
.then((raw) => activityTiles(raw, day))
|
|
109
|
+
.catch(() => { failed.push(day); return [] as ActivityTile[]; })), { concurrency: 3 });
|
|
110
|
+
const seen = new Set<string>();
|
|
111
|
+
const tiles: ActivityTile[] = [];
|
|
112
|
+
for (const list of homes) for (const t of list) {
|
|
113
|
+
if (seen.has(t.activity_id)) continue;
|
|
114
|
+
seen.add(t.activity_id);
|
|
115
|
+
tiles.push(t);
|
|
116
|
+
}
|
|
117
|
+
return { tiles, days_checked: days, days_failed: failed.sort(), calendar_pruned: pruned };
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** Half-open overlap of [aStart, aEnd) and [bStart, bEnd), as WHOOP checks it. */
|
|
121
|
+
export function overlaps(aStart: number, aEnd: number, bStart: number, bEnd: number): boolean {
|
|
122
|
+
return aStart < bEnd && bStart < aEnd;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Activities whose window overlaps [start, end), excluding `excludeId`. Reads the
|
|
127
|
+
* home card of the cycle days around the window (a nap before a main sleep sits
|
|
128
|
+
* on the previous day's card), fresh.
|
|
129
|
+
*/
|
|
130
|
+
export async function overlappingTiles(client: WhoopClient, startIso: string, endIso: string, excludeId?: string): Promise<{ tiles: ActivityTile[]; complete: boolean }> {
|
|
131
|
+
const s = Date.parse(startIso);
|
|
132
|
+
const e = Date.parse(endIso);
|
|
133
|
+
const first = addDays(isoDay(new Date(s)), -1);
|
|
134
|
+
const last = addDays(isoDay(new Date(e)), 1);
|
|
135
|
+
const days = enumerateDays(first, last);
|
|
136
|
+
let complete = true;
|
|
137
|
+
const lists = await runPaced(days.map((day) => () =>
|
|
138
|
+
client.get(HOME_PATH, { date: day }, { fresh: true }).then((raw) => activityTiles(raw, day)).catch(() => {
|
|
139
|
+
complete = false;
|
|
140
|
+
return [] as ActivityTile[];
|
|
141
|
+
})), { concurrency: 3 });
|
|
142
|
+
const seen = new Set<string>();
|
|
143
|
+
const out: ActivityTile[] = [];
|
|
144
|
+
for (const list of lists) for (const t of list) {
|
|
145
|
+
if (t.activity_id === excludeId || seen.has(t.activity_id) || !t.start || !t.end) continue;
|
|
146
|
+
seen.add(t.activity_id);
|
|
147
|
+
if (overlaps(s, e, Date.parse(t.start), Date.parse(t.end))) out.push(t);
|
|
148
|
+
}
|
|
149
|
+
return { tiles: out, complete };
|
|
150
|
+
}
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
// Reading one activity back from WHOOP, whatever its kind, for the activity
|
|
2
|
+
// write tools' pre-reads and read-backs (SPEC.md §4.3, §4.4).
|
|
3
|
+
//
|
|
4
|
+
// - The shared record (create/edit responses, GET /activities-service/v2/activities/{id})
|
|
5
|
+
// carries type, score_type, during, version and score_state.
|
|
6
|
+
// - SLEEP (sleep, nap) reads go to GET cd/v2/sleep-details/{id}: cardio-details
|
|
7
|
+
// 400s while a sleep is pending. `nap_to_sleep_available` tells nap from sleep.
|
|
8
|
+
// - CARDIO/RECOVERY reads go to GET cd/v1/cardio-details (200 in every state).
|
|
9
|
+
// Every read here is fresh: pre-reads and read-backs must never see the cache.
|
|
10
|
+
import type { WhoopClient } from "../whoop/client.js";
|
|
11
|
+
import { WhoopApiError, WhoopConflictError, WhoopServerError } from "../whoop/errors.js";
|
|
12
|
+
import { get, str } from "../whoop/bff.js";
|
|
13
|
+
import { parsePgRange } from "./dates.js";
|
|
14
|
+
import { typeForInternalName } from "./activity_types.js";
|
|
15
|
+
import type { ScoreType } from "../data/sports.js";
|
|
16
|
+
|
|
17
|
+
export const CREATE_PATH = "/core-details-bff/v2/create-activity";
|
|
18
|
+
export const CARDIO_DETAILS_V1 = "/core-details-bff/v1/cardio-details";
|
|
19
|
+
export const CARDIO_DETAILS_V2 = "/core-details-bff/v2/cardio-details";
|
|
20
|
+
export const RECOVERY_DETAILS_V2 = "/core-details-bff/v2/recovery-details";
|
|
21
|
+
export const sleepDetailsPath = (id: string): string => `/core-details-bff/v2/sleep-details/${encodeURIComponent(id)}`;
|
|
22
|
+
export const activityRecordPath = (id: string): string => `/activities-service/v2/activities/${encodeURIComponent(id)}`;
|
|
23
|
+
|
|
24
|
+
export interface ActivityRecord {
|
|
25
|
+
id: string;
|
|
26
|
+
/** internal_name ("boxing", "nap", "sleep"). */
|
|
27
|
+
type: string | null;
|
|
28
|
+
score_type: ScoreType | null;
|
|
29
|
+
start: string | null;
|
|
30
|
+
end: string | null;
|
|
31
|
+
version: number | null;
|
|
32
|
+
score_state: string | null;
|
|
33
|
+
/** Which read produced it. */
|
|
34
|
+
source: "record" | "sleep-details" | "cardio-details";
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const SCORE_TYPES = new Set(["CARDIO", "RECOVERY", "SLEEP"]);
|
|
38
|
+
const asScoreType = (v: unknown): ScoreType | null => (typeof v === "string" && SCORE_TYPES.has(v) ? (v as ScoreType) : null);
|
|
39
|
+
|
|
40
|
+
/** ISO with milliseconds in UTC, or null. Accepts WHOOP's "+0000" offsets. */
|
|
41
|
+
export function toUtc(value: unknown): string | null {
|
|
42
|
+
if (typeof value !== "string" || !value) return null;
|
|
43
|
+
const t = Date.parse(value);
|
|
44
|
+
return Number.isNaN(t) ? null : new Date(t).toISOString();
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function sameInstant(a: string | null | undefined, b: string | null | undefined): boolean {
|
|
48
|
+
if (!a || !b) return false;
|
|
49
|
+
return Date.parse(a) === Date.parse(b);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Parse the shared activity record (bare, or wrapped as `{activity:{…}}`). */
|
|
53
|
+
export function recordFromActivity(raw: unknown): ActivityRecord | null {
|
|
54
|
+
const node = (get(raw, "activity") ?? raw) as Record<string, unknown> | undefined;
|
|
55
|
+
const id = str(get(node, "id"));
|
|
56
|
+
if (!id) return null;
|
|
57
|
+
let start: string | null = null;
|
|
58
|
+
let end: string | null = null;
|
|
59
|
+
const during = str(get(node, "during"));
|
|
60
|
+
if (during) {
|
|
61
|
+
try {
|
|
62
|
+
const r = parsePgRange(during);
|
|
63
|
+
start = toUtc(r.start);
|
|
64
|
+
end = toUtc(r.end);
|
|
65
|
+
} catch {
|
|
66
|
+
// Unparseable range: leave the window unknown.
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
const type = str(get(node, "type"));
|
|
70
|
+
const version = get(node, "version");
|
|
71
|
+
return {
|
|
72
|
+
id,
|
|
73
|
+
type,
|
|
74
|
+
score_type: asScoreType(get(node, "score_type")) ?? typeForInternalName(type)?.score_type ?? null,
|
|
75
|
+
start,
|
|
76
|
+
end,
|
|
77
|
+
version: typeof version === "number" ? version : null,
|
|
78
|
+
score_state: str(get(node, "score_state")),
|
|
79
|
+
source: "record",
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** GET cd/v2/sleep-details/{id} → nap or sleep with its window. */
|
|
84
|
+
export function recordFromSleepDetails(raw: unknown, id: string): ActivityRecord {
|
|
85
|
+
const edit = get(raw, "sleep_details_edit_components");
|
|
86
|
+
const napToSleep = get(edit, "nap_to_sleep_available");
|
|
87
|
+
const title = (str(get(raw, "sleep_details_labels", "screen_title_display")) ?? "").toUpperCase();
|
|
88
|
+
const type = napToSleep === true ? "nap" : napToSleep === false ? "sleep" : title.includes("NAP") ? "nap" : title.includes("SLEEP") ? "sleep" : null;
|
|
89
|
+
return {
|
|
90
|
+
id,
|
|
91
|
+
type,
|
|
92
|
+
score_type: "SLEEP",
|
|
93
|
+
start: toUtc(get(edit, "sleep_start_time")),
|
|
94
|
+
end: toUtc(get(edit, "sleep_end_time")),
|
|
95
|
+
version: null,
|
|
96
|
+
score_state: null,
|
|
97
|
+
source: "sleep-details",
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** GET cd/v1/cardio-details → type and window from details_edit_components. */
|
|
102
|
+
export function recordFromCardioDetails(raw: unknown, id: string): ActivityRecord {
|
|
103
|
+
const edit = get(raw, "details_edit_components");
|
|
104
|
+
const type = str(get(edit, "activity_type_internal_name"));
|
|
105
|
+
return {
|
|
106
|
+
id,
|
|
107
|
+
type,
|
|
108
|
+
score_type: asScoreType(get(edit, "single_score_type")) ?? typeForInternalName(type)?.score_type ?? null,
|
|
109
|
+
start: toUtc(get(edit, "start_time_selector", "initial_time")),
|
|
110
|
+
end: toUtc(get(edit, "end_time_selector", "initial_time")),
|
|
111
|
+
version: null,
|
|
112
|
+
score_state: null,
|
|
113
|
+
source: "cardio-details",
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const isStatus = (e: unknown, ...statuses: number[]): boolean => e instanceof WhoopApiError && statuses.includes(e.status);
|
|
118
|
+
|
|
119
|
+
const UUID = /^[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$/i;
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* WHOOP's detail screens answer a bare 500 for an id that isn't a UUID (a
|
|
123
|
+
* truncated or made-up one), which reads as "usually transient, try again in
|
|
124
|
+
* 30s". Returns the error to raise for that case, or null when `e` is anything
|
|
125
|
+
* else (a real id that 500s stays a server error).
|
|
126
|
+
*/
|
|
127
|
+
export function badActivityIdError(e: unknown, id: string): Error | null {
|
|
128
|
+
if (!(e instanceof WhoopServerError) || UUID.test(id.trim())) return null;
|
|
129
|
+
return new Error(`${JSON.stringify(id)} isn't a WHOOP activity id (ids are UUIDs: 8-4-4-4-12 hex characters). Take the id from whoop_workouts, whoop_day or whoop_sleep.`);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Read an activity of unknown kind: the activities-service record first, then
|
|
134
|
+
* cardio-details (200 for CARDIO/RECOVERY in any state, 400 for a pending
|
|
135
|
+
* sleep), then sleep-details for sleeps and naps. Returns null on 404.
|
|
136
|
+
*/
|
|
137
|
+
export async function readActivity(client: WhoopClient, id: string): Promise<ActivityRecord | null> {
|
|
138
|
+
let recordFailed = false;
|
|
139
|
+
try {
|
|
140
|
+
const rec = recordFromActivity(await client.get(activityRecordPath(id), {}, { fresh: true }));
|
|
141
|
+
if (rec && rec.type) return rec;
|
|
142
|
+
} catch (e) {
|
|
143
|
+
// The record GET is the authoritative kind; the detail screens below are the fallback.
|
|
144
|
+
recordFailed = !isStatus(e, 404);
|
|
145
|
+
}
|
|
146
|
+
let cardioPending = false;
|
|
147
|
+
try {
|
|
148
|
+
const rec = recordFromCardioDetails(await client.get(CARDIO_DETAILS_V1, { activityId: id }, { fresh: true }), id);
|
|
149
|
+
if (rec.score_type !== "SLEEP" && rec.type) return rec;
|
|
150
|
+
} catch (e) {
|
|
151
|
+
if (isStatus(e, 404)) return null;
|
|
152
|
+
if (!isStatus(e, 400)) throw badActivityIdError(e, id) ?? e; // 400 = a pending sleep, or any activity right after a write
|
|
153
|
+
cardioPending = true;
|
|
154
|
+
}
|
|
155
|
+
// sleep-details answers 200 for ANY existing activity id, workouts included
|
|
156
|
+
// (seen live), so it can't tell the kind apart. If the record read failed and
|
|
157
|
+
// cardio-details is still refusing, the kind is unknown: don't guess, or an
|
|
158
|
+
// edit or delete could be routed to the sleep endpoints for a workout.
|
|
159
|
+
if (recordFailed && cardioPending) {
|
|
160
|
+
throw new Error(`WHOOP couldn't say what kind of activity ${id} is right now (its record read failed and the detail screen is still processing). Nothing was changed; try again in a few seconds.`);
|
|
161
|
+
}
|
|
162
|
+
try {
|
|
163
|
+
return recordFromSleepDetails(await client.get(sleepDetailsPath(id), {}, { fresh: true }), id);
|
|
164
|
+
} catch (e) {
|
|
165
|
+
if (isStatus(e, 404)) return null;
|
|
166
|
+
throw badActivityIdError(e, id) ?? e;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Fresh read-back of a known activity; null on 404.
|
|
172
|
+
*
|
|
173
|
+
* The raw activity record comes first: it answers in every state and for every
|
|
174
|
+
* kind (verified live for workouts, recovery sessions and naps, before and after
|
|
175
|
+
* edits). The detail screens can't be the primary read-back, because right after
|
|
176
|
+
* a create or edit WHOOP refuses them for a few seconds (cardio-details: 400
|
|
177
|
+
* "Cannot view activity details for a pending activity"; sleep-details: 400
|
|
178
|
+
* "Sleep must be processed in order to view SleepDetails"). They stay as the
|
|
179
|
+
* fallback when the record read fails, and as the second opinion when it 404s.
|
|
180
|
+
*/
|
|
181
|
+
export async function readActivityAs(client: WhoopClient, id: string, scoreType: ScoreType): Promise<ActivityRecord | null> {
|
|
182
|
+
try {
|
|
183
|
+
const rec = recordFromActivity(await client.get(activityRecordPath(id), {}, { fresh: true }));
|
|
184
|
+
if (rec && rec.type) return rec;
|
|
185
|
+
} catch {
|
|
186
|
+
// 404 or any other failure: let the kind-specific detail screen decide, so
|
|
187
|
+
// "gone" is only ever claimed when that screen 404s too.
|
|
188
|
+
}
|
|
189
|
+
try {
|
|
190
|
+
if (scoreType === "SLEEP") return recordFromSleepDetails(await client.get(sleepDetailsPath(id), {}, { fresh: true }), id);
|
|
191
|
+
return recordFromCardioDetails(await client.get(CARDIO_DETAILS_V1, { activityId: id }, { fresh: true }), id);
|
|
192
|
+
} catch (e) {
|
|
193
|
+
if (isStatus(e, 404)) return null;
|
|
194
|
+
throw badActivityIdError(e, id) ?? e;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/** True when the kind-specific detail read answers 404; null when the read failed otherwise. */
|
|
199
|
+
export async function isGone(client: WhoopClient, id: string, scoreType: ScoreType): Promise<boolean | null> {
|
|
200
|
+
try {
|
|
201
|
+
return (await readActivityAs(client, id, scoreType)) === null;
|
|
202
|
+
} catch {
|
|
203
|
+
return null;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Human-readable list of what a 409 says overlaps ("Sleep 2:15 AM – 5:45 AM").
|
|
209
|
+
* BFF creates and sleep edits list them; the cardio-details edit lists none.
|
|
210
|
+
*/
|
|
211
|
+
export function overlapDescriptions(error: WhoopConflictError): string[] {
|
|
212
|
+
return error.overlaps.map((o) => o.label).filter((l): l is string => Boolean(l));
|
|
213
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// Small result helpers shared by the activity tools.
|
|
2
|
+
import type { ToolResult } from "../tools/define.js";
|
|
3
|
+
import { jsonOut } from "../whoop/json_out.js";
|
|
4
|
+
import { WhoopApiError, WhoopConflictError } from "../whoop/errors.js";
|
|
5
|
+
import { overlapDescriptions } from "./activity_records.js";
|
|
6
|
+
|
|
7
|
+
export const MAIN_SLEEP_WARNING =
|
|
8
|
+
"Main sleep: WHOOP re-cuts the day's cycles around it (cycle boundaries and every later activity's cycle_id change), and deleting the sleep later does not undo that.";
|
|
9
|
+
export const NAP_TO_SLEEP_WARNING =
|
|
10
|
+
"Converting a nap to a main sleep re-cuts the day's cycles (cycle boundaries and later activities' cycle_id change) permanently.";
|
|
11
|
+
export const DELETE_MAIN_SLEEP_WARNING =
|
|
12
|
+
"Deleting a main sleep does not restore the cycles it created: the cycle keeps its start and goes back to 'add sleep'.";
|
|
13
|
+
|
|
14
|
+
/** A model-facing error result (isError) carrying structured fields. */
|
|
15
|
+
export function errorResult(body: { error: string } & Record<string, unknown>): ToolResult {
|
|
16
|
+
return { content: [{ type: "text", text: jsonOut(body) }], isError: true };
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Map a WHOOP write rejection to an actionable error. Returns null for anything
|
|
21
|
+
* that isn't a WhoopApiError (let it propagate). `overlapFallback` lists what a
|
|
22
|
+
* home-card check found when WHOOP's 409 names nothing (edit 409s are empty).
|
|
23
|
+
*/
|
|
24
|
+
export function writeRejection(e: unknown, endpoint: string, overlapFallback: string[] = []): ToolResult | null {
|
|
25
|
+
if (e instanceof WhoopConflictError) {
|
|
26
|
+
const listed = overlapDescriptions(e);
|
|
27
|
+
return errorResult({
|
|
28
|
+
error: "WHOOP refused: the window overlaps existing activities (409). Nothing was changed.",
|
|
29
|
+
status: 409,
|
|
30
|
+
endpoint,
|
|
31
|
+
overlapping_activities: listed.length ? listed : overlapFallback,
|
|
32
|
+
hint: "Pick a window that doesn't overlap, or move/delete the other activity first (whoop_activity_edit / whoop_activity_delete). WHOOP never merges or trims on a 409.",
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
if (e instanceof WhoopApiError) {
|
|
36
|
+
const hints: Record<number, string> = {
|
|
37
|
+
400: "WHOOP rejected the values (window, type or timestamp format).",
|
|
38
|
+
404: "WHOOP says the activity doesn't exist (deleted?). List current ones with whoop_workouts.",
|
|
39
|
+
412: "WHOOP is recomputing this day (another write is in flight). Try again in a minute.",
|
|
40
|
+
422: "WHOOP rejected the request shape (missing field).",
|
|
41
|
+
};
|
|
42
|
+
return errorResult({
|
|
43
|
+
error: `WHOOP rejected the request (${e.status}).`,
|
|
44
|
+
status: e.status,
|
|
45
|
+
endpoint,
|
|
46
|
+
reason: e.message,
|
|
47
|
+
hint: hints[e.status] ?? null,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
// Activity-type and garment lookups for the activity tools. The bundled catalog
|
|
2
|
+
// (src/data/sports.ts) answers almost everything; on a miss we re-fetch WHOOP's
|
|
3
|
+
// live catalogs once (24 h client cache) before giving up with the top-5 fuzzy
|
|
4
|
+
// suggestions. MCP resources aren't visible to every client, so tools resolve
|
|
5
|
+
// names themselves (SPEC.md §3.3, §7 S3).
|
|
6
|
+
import type { WhoopClient } from "../whoop/client.js";
|
|
7
|
+
import { ACTIVITY_TYPES, ACTIVITY_TYPES_BY_INTERNAL_NAME, type ActivityType, type ScoreType } from "../data/sports.js";
|
|
8
|
+
import { GARMENTS, GARMENTS_BY_ID, type Garment } from "../data/garments.js";
|
|
9
|
+
|
|
10
|
+
/** Sport ids WHOOP retired (`is_current:false`); v0 create rejects them with 400. */
|
|
11
|
+
const RETIRED_SPORT_IDS: Record<number, string> = {
|
|
12
|
+
[-1]: "Activity", 50: "Machine Workout", 54: "Jogging", 58: "Obstacle Racing", 67: "Plyometrics",
|
|
13
|
+
68: "Spinning", 69: "Sex", 72: "Pit Practice", 116: "Resonance Frequency Breathing",
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export type TypeResolution =
|
|
17
|
+
| { ok: true; type: ActivityType; matched_by: "internal_name" | "name" | "sport_id" | "live_catalog" }
|
|
18
|
+
| { ok: false; error: string; suggestions: string[] };
|
|
19
|
+
|
|
20
|
+
const norm = (s: string): string => s.toLowerCase().replace(/[^a-z0-9]+/g, "");
|
|
21
|
+
|
|
22
|
+
/** "ski-erg (Ski Erg)" — what a model should pass back. */
|
|
23
|
+
export function describeType(t: Pick<ActivityType, "internal_name" | "name">): string {
|
|
24
|
+
return `${t.internal_name.trim()} (${t.name})`;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function levenshtein(a: string, b: string): number {
|
|
28
|
+
if (a === b) return 0;
|
|
29
|
+
const prev = Array.from({ length: b.length + 1 }, (_, i) => i);
|
|
30
|
+
for (let i = 1; i <= a.length; i++) {
|
|
31
|
+
let diag = prev[0]!;
|
|
32
|
+
prev[0] = i;
|
|
33
|
+
for (let j = 1; j <= b.length; j++) {
|
|
34
|
+
const tmp = prev[j]!;
|
|
35
|
+
prev[j] = Math.min(prev[j]! + 1, prev[j - 1]! + 1, diag + (a[i - 1] === b[j - 1] ? 0 : 1));
|
|
36
|
+
diag = tmp;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return prev[b.length]!;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function similarity(query: string, field: string): number {
|
|
43
|
+
if (!query || !field) return 0;
|
|
44
|
+
if (field === query) return 1;
|
|
45
|
+
if (field.startsWith(query) || query.startsWith(field)) return 0.9 - Math.abs(field.length - query.length) / 100;
|
|
46
|
+
if (field.includes(query) || query.includes(field)) return 0.8 - Math.abs(field.length - query.length) / 100;
|
|
47
|
+
return 1 - levenshtein(query, field) / Math.max(query.length, field.length);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** Top-n catalog entries closest to `query`, as "internal_name (Name)". */
|
|
51
|
+
export function suggestActivityTypes(query: string, n = 5, catalog: readonly ActivityType[] = ACTIVITY_TYPES): string[] {
|
|
52
|
+
const q = norm(query);
|
|
53
|
+
const words = query.toLowerCase().split(/[^a-z0-9]+/).filter((w) => w.length > 2);
|
|
54
|
+
return catalog
|
|
55
|
+
.map((t) => {
|
|
56
|
+
let score = Math.max(similarity(q, norm(t.internal_name)), similarity(q, norm(t.name)));
|
|
57
|
+
// A whole word of the query inside the name ("bike" → "Assault Bike") beats edit distance.
|
|
58
|
+
if (words.some((w) => t.name.toLowerCase().includes(w) || t.internal_name.includes(w))) score = Math.max(score, 0.75);
|
|
59
|
+
return { t, score };
|
|
60
|
+
})
|
|
61
|
+
.sort((a, b) => b.score - a.score || a.t.name.localeCompare(b.t.name))
|
|
62
|
+
.slice(0, n)
|
|
63
|
+
.map(({ t }) => describeType(t));
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function matchIn(catalog: readonly ActivityType[], raw: string): { type: ActivityType; by: "internal_name" | "name" } | null {
|
|
67
|
+
const exact = catalog.find((t) => t.internal_name === raw);
|
|
68
|
+
if (exact) return { type: exact, by: "internal_name" };
|
|
69
|
+
const lower = raw.trim().toLowerCase();
|
|
70
|
+
const byInternal = catalog.find((t) => t.internal_name.trim().toLowerCase() === lower);
|
|
71
|
+
if (byInternal) return { type: byInternal, by: "internal_name" };
|
|
72
|
+
const byName = catalog.find((t) => t.name.toLowerCase() === lower);
|
|
73
|
+
if (byName) return { type: byName, by: "name" };
|
|
74
|
+
const n = norm(raw);
|
|
75
|
+
const loose = n ? catalog.find((t) => norm(t.internal_name) === n || norm(t.name) === n) : undefined;
|
|
76
|
+
return loose ? { type: loose, by: "name" } : null;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Resolve an internal_name ("ski-erg"), a display name ("Strength Trainer"), or a
|
|
81
|
+
* current sport_id (339, or "339") against the bundled catalog.
|
|
82
|
+
*/
|
|
83
|
+
export function resolveActivityType(input: string | number, catalog: readonly ActivityType[] = ACTIVITY_TYPES): TypeResolution {
|
|
84
|
+
const raw = typeof input === "number" ? String(input) : input;
|
|
85
|
+
if (/^-?\d+$/.test(raw.trim())) {
|
|
86
|
+
const id = Number(raw.trim());
|
|
87
|
+
const fromCatalog = catalog.find((t) => t.sport_id === id);
|
|
88
|
+
if (fromCatalog) return { ok: true, type: fromCatalog, matched_by: "sport_id" };
|
|
89
|
+
const retired = RETIRED_SPORT_IDS[id];
|
|
90
|
+
if (retired) {
|
|
91
|
+
return { ok: false, error: `sport_id ${id} (${retired}) is retired; WHOOP rejects it.`, suggestions: suggestActivityTypes(retired, 5, catalog) };
|
|
92
|
+
}
|
|
93
|
+
return { ok: false, error: `Unknown sport_id ${id}.`, suggestions: [] };
|
|
94
|
+
}
|
|
95
|
+
if (!raw.trim()) return { ok: false, error: "Empty activity type.", suggestions: [] };
|
|
96
|
+
const hit = matchIn(catalog, raw);
|
|
97
|
+
if (hit) return { ok: true, type: hit.type, matched_by: hit.by };
|
|
98
|
+
return { ok: false, error: `Unknown activity type "${raw}".`, suggestions: suggestActivityTypes(raw, 5, catalog) };
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
interface RawSport { id?: unknown; name?: unknown; activity_type_internal_name?: unknown; is_current?: unknown }
|
|
102
|
+
interface RawType {
|
|
103
|
+
internal_name?: unknown; display_name?: unknown; category?: unknown; score_type?: unknown;
|
|
104
|
+
msk_linkable?: unknown; has_gps?: unknown; deleted?: unknown;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Join WHOOP's live catalogs the way the bundled one was generated: a type's
|
|
109
|
+
* sport is the current sport whose activity_type_internal_name matches, else the
|
|
110
|
+
* one whose name equals the display name (case-insensitive).
|
|
111
|
+
*/
|
|
112
|
+
export function joinActivityCatalog(rawSports: unknown, rawTypes: unknown): ActivityType[] {
|
|
113
|
+
const sports = (Array.isArray(rawSports) ? rawSports : []) as RawSport[];
|
|
114
|
+
const current = sports.filter((s) => s.is_current !== false && typeof s.id === "number" && typeof s.name === "string");
|
|
115
|
+
const byInternal = new Map(current.filter((s) => typeof s.activity_type_internal_name === "string").map((s) => [s.activity_type_internal_name as string, s]));
|
|
116
|
+
const byName = new Map(current.map((s) => [(s.name as string).toLowerCase(), s]));
|
|
117
|
+
const types = (Array.isArray(rawTypes) ? rawTypes : []) as RawType[];
|
|
118
|
+
const out: ActivityType[] = [];
|
|
119
|
+
for (const t of types) {
|
|
120
|
+
if (typeof t.internal_name !== "string" || typeof t.display_name !== "string" || t.deleted === true) continue;
|
|
121
|
+
const scoreType = t.score_type === "RECOVERY" || t.score_type === "SLEEP" ? t.score_type : "CARDIO";
|
|
122
|
+
const sport = byInternal.get(t.internal_name) ?? byName.get(t.display_name.toLowerCase());
|
|
123
|
+
out.push({
|
|
124
|
+
internal_name: t.internal_name,
|
|
125
|
+
name: t.display_name,
|
|
126
|
+
sport_id: typeof sport?.id === "number" ? sport.id : null,
|
|
127
|
+
score_type: scoreType as ScoreType,
|
|
128
|
+
category: typeof t.category === "string" ? t.category : "",
|
|
129
|
+
msk_linkable: t.msk_linkable === true,
|
|
130
|
+
has_gps: t.has_gps === true,
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
return out;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Bundled lookup first; on a miss, re-fetch the live catalogs (new types WHOOP
|
|
138
|
+
* shipped after this build) and try again. Live failures fall back to the
|
|
139
|
+
* bundled suggestions.
|
|
140
|
+
*/
|
|
141
|
+
export async function resolveActivityTypeLive(client: WhoopClient, input: string | number): Promise<TypeResolution> {
|
|
142
|
+
const local = resolveActivityType(input);
|
|
143
|
+
if (local.ok) return local;
|
|
144
|
+
try {
|
|
145
|
+
const [sports, types] = await Promise.all([
|
|
146
|
+
client.get("/activities-service/v1/sports"),
|
|
147
|
+
client.get("/activities-service/v2/activity-types"),
|
|
148
|
+
]);
|
|
149
|
+
const live = joinActivityCatalog(sports, types);
|
|
150
|
+
if (live.length) {
|
|
151
|
+
const hit = resolveActivityType(input, live);
|
|
152
|
+
if (hit.ok) return { ok: true, type: hit.type, matched_by: "live_catalog" };
|
|
153
|
+
}
|
|
154
|
+
} catch {
|
|
155
|
+
// Live catalog unavailable: the bundled answer stands.
|
|
156
|
+
}
|
|
157
|
+
return local;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/** Catalog entry for an internal_name seen in a WHOOP payload (tolerates trimming). */
|
|
161
|
+
export function typeForInternalName(name: string | null | undefined): ActivityType | undefined {
|
|
162
|
+
if (!name) return undefined;
|
|
163
|
+
return ACTIVITY_TYPES_BY_INTERNAL_NAME.get(name) ?? ACTIVITY_TYPES.find((t) => t.internal_name.trim() === name.trim());
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export function isSleepType(internalName: string | null | undefined): boolean {
|
|
167
|
+
return internalName === "sleep" || internalName === "nap";
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export type GarmentResolution = { ok: true; garment: Garment } | { ok: false; error: string };
|
|
171
|
+
|
|
172
|
+
export function resolveGarment(id: number): GarmentResolution {
|
|
173
|
+
const garment = GARMENTS_BY_ID.get(id);
|
|
174
|
+
if (garment) return { ok: true, garment };
|
|
175
|
+
return { ok: false, error: `Unknown garment_id ${id}. Valid: ${GARMENTS.map((g) => `${g.id} ${g.name}`).join(", ")}.` };
|
|
176
|
+
}
|
package/src/lib/brand.ts
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
// totem's brand: the logo (assets/brand/totem.svg) and its colours, used by the
|
|
2
|
+
// pages a server shows (Connect, consent), the MCP server's icon and the CLI.
|
|
3
|
+
//
|
|
4
|
+
// The logo is an isometric S in a hexagon: ice, with a darker fold face, and no
|
|
5
|
+
// background anywhere it is used, so it sits on whatever is behind it. Ice and
|
|
6
|
+
// ink are the brand colours (ink is the dark page and the buttons, never a
|
|
7
|
+
// square behind the logo); fold is the mark's own shade, used where ice would
|
|
8
|
+
// be too faint (a light page or terminal).
|
|
9
|
+
|
|
10
|
+
export const BRAND = {
|
|
11
|
+
ice: "#B7D3F2",
|
|
12
|
+
ink: "#141414",
|
|
13
|
+
fold: "#7A9CC6",
|
|
14
|
+
} as const;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The logo as one inline SVG string: assets/brand/totem.svg without its title,
|
|
18
|
+
* comments and ids, so it can sit in a page more than once.
|
|
19
|
+
* tests/lib/brand.test.ts keeps the two in step.
|
|
20
|
+
*/
|
|
21
|
+
export const TOTEM_LOGO_SVG =
|
|
22
|
+
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="100 100 800 800"><polygon fill="#B7D3F2" points="125.00,393.35 500.00,176.84 684.73,283.49 376.23,461.60 509.24,538.40 258.00,683.44 125.00,606.65"/><polygon fill="#7A9CC6" points="125.00,606.65 376.23,461.60 509.24,538.40 258.00,683.44"/><polygon fill="#B7D3F2" points="875.00,606.65 500.00,823.16 315.27,716.51 623.77,538.40 490.76,461.60 742.00,316.56 875.00,393.35"/><polygon fill="#7A9CC6" points="875.00,393.35 623.77,538.40 490.76,461.60 742.00,316.56"/></svg>';
|
|
23
|
+
|
|
24
|
+
/** Where a server serves the logo as its favicon, and the tag that points there. */
|
|
25
|
+
export const FAVICON_PATH = "/favicon.svg";
|
|
26
|
+
export const FAVICON_LINK = `<link rel="icon" href="${FAVICON_PATH}" type="image/svg+xml">`;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* The logo for a page header that names totem in text beside it: the same
|
|
30
|
+
* shapes in a viewBox cut to the mark (x 125–875, y 176.84–823.16), so it
|
|
31
|
+
* fills its box and lines up with the text.
|
|
32
|
+
*/
|
|
33
|
+
export const TOTEM_MARK = TOTEM_LOGO_SVG
|
|
34
|
+
.replace('<svg xmlns="http://www.w3.org/2000/svg" viewBox="100 100 800 800">', '<svg aria-hidden="true" xmlns="http://www.w3.org/2000/svg" viewBox="125 176 750 648">');
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* 128 px PNG of the logo on a transparent background, for MCP clients that
|
|
38
|
+
* don't draw SVG icons. Regenerate after a logo change:
|
|
39
|
+
* magick -background none -density 192 assets/brand/totem.svg -resize 128x128 -depth 8 +dither -colors 64 -strip -define png:compression-level=9 icon.png
|
|
40
|
+
*/
|
|
41
|
+
const ICON_PNG_128 =
|
|
42
|
+
"iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAMAAAD04JH5AAAAbFBMVEWlw+WiweO30/KYt9u30/K10fG30/K30/KQsNa30/Kuy+uK" +
|
|
43
|
+
"qtK30/K30/J7ncePr9W30/J8nse30/J7nce30/J6nMZ7ncd6nMZ7ncd7ncZ7ncd8nceOrtS30/J6nMaDpM2Wtdq41POeveF/oco3" +
|
|
44
|
+
"j25FAAAAHXRSTlMAC1xQuPrFUxad+iPg6LEU1UAqkBnscdn7x4Jk/KAY6UUAAAPKSURBVHja7VttYqowEBQRQUQwRYraAmLvf8fy" +
|
|
45
|
+
"1PqAbMgm2YQ/zAHMmNnvLKvVggULFixYYARvvfbmPN/fBNU2nO34aBdXHeLdfqbbT6oXDmnm/vz1serh6NoUWCf+AMHGd3j8R3qo" +
|
|
46
|
+
"OMS7yJn42wpEkjvRIRQc/zAFZv34/dP1RLBtChkk/sgU0g+L4h8rBLa2XHJK/BGF0L34Y5ekjs6nPKmUQBudkeKPXJLOFPxx3HVr" +
|
|
47
|
+
"CpGK+KNL2FPcfqJ7PEly0BGfMCayjf7try0lXRyS/DSP6wnD0N6zF3cR3hflRcrsxV1Z/PE+y7quzwoUMn3xgQjsX+onijybQ/z0" +
|
|
48
|
+
"XL9RfiJMIdwQip/lRT3AxbcYdwXiD3FO95RJty8+V4n5aQ2hFJsCM4i7jBe/qAUQmIJu0gXjrpeXtRiQS0aptvgJL344dfzDJdPI" +
|
|
49
|
+
"YtJlfdcT6tBvo0LKpBtdixqF8q2DdyR0va+yRqJp/hznlJDFXZaij78FBzMCQNxFif/ErbN5MwKIuCvGd1y1ZgRwcVd0+/d/x5sQ" +
|
|
50
|
+
"mEq6GPHb189oEpAlXentv/+HHgE+7mZ5qSa+CYHETPyg7SupTgAYf+Bd7+c2OF6dQFttuSTmaYmvSSD+LkPtyDsQX4dAG9x+wEQe" +
|
|
51
|
+
"YcJPM759VQJtcG/gRI6xgk58OJxgCbTd7QsS+YtCqXr7agT6xz8TuYevwP7irjaBTvwGUdNFcA0Ki69AoK3uDVjT5ShTuE0WmnIC" +
|
|
52
|
+
"LXf7PR2+pKWoUHw0gfg2ZVx8mzVIChPi4whA4ktN4Z0WJ8XHEOhuv5EHGKDjfhYG35guY4LAlPiyNqvLjjLx5QQecRcHvjiKdkGL" +
|
|
53
|
+
"K6wEBOTi9y6AT0/4JgsmgL99sNNWGa/ABPDHF/ysgSl12ACBVkV833SyyREQxV2k9SsPt0YEVMQH/F9jsjkiMB13JYMmrclmn4CK" +
|
|
54
|
+
"6wE5QG+y2SfgVnyOQKMgfkQ31n4TWIUlVnxGOtZW7e5KZnGyKe9v+RLI4EUp5iebkg6/uEZWJ5uSNhcqg3eEk03ZlMco6ao9J0K1" +
|
|
55
|
+
"tWHSVX1OHA/Zz1DSJXxUAExh0HFfjJNuX/wr7jnxf8dNGHfVthqepkCTdPUe8z1WUiVd3XWGjNl9Tpz5LVljh2fjSHzy50SKtSba" +
|
|
56
|
+
"50SNv7/Vj7s023VrTQZ0y31aHpCQ7rQpJwD6BU+lvtPOXiNeB1tLvsgyyOaaMyIg2V70lpXC9lfdJ13SzYa3MC2723EHCxO3W/58" +
|
|
57
|
+
"aUaxPmdgCskMX3r0TMHmNjXCFNx+WsBHZwcb9ZOmsD6tFixYsGDBAiP8Avw8HRY2BcgBAAAAAElFTkSuQmCC";
|
|
58
|
+
|
|
59
|
+
/** The MCP server's icons (serverInfo.icons): the SVG, and the PNG for clients that don't draw SVG. */
|
|
60
|
+
export const SERVER_ICONS = [
|
|
61
|
+
{ src: `data:image/svg+xml;base64,${Buffer.from(TOTEM_LOGO_SVG).toString("base64")}`, mimeType: "image/svg+xml", sizes: ["any"] },
|
|
62
|
+
{ src: `data:image/png;base64,${ICON_PNG_128}`, mimeType: "image/png", sizes: ["128x128"] },
|
|
63
|
+
];
|
|
64
|
+
|
|
65
|
+
/** What the MCP server says it is (initialize's serverInfo), on stdio and HTTP alike. */
|
|
66
|
+
export const serverIdentity = (version: string) => ({
|
|
67
|
+
name: "totem",
|
|
68
|
+
version,
|
|
69
|
+
websiteUrl: "https://github.com/thebriangao/totem",
|
|
70
|
+
icons: SERVER_ICONS,
|
|
71
|
+
});
|