@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,164 @@
|
|
|
1
|
+
import { ACTIVITY_TYPES, ACTIVITY_TYPES_BY_INTERNAL_NAME } from "../data/sports.js";
|
|
2
|
+
import { GARMENTS, GARMENTS_BY_ID } from "../data/garments.js";
|
|
3
|
+
/** Sport ids WHOOP retired (`is_current:false`); v0 create rejects them with 400. */
|
|
4
|
+
const RETIRED_SPORT_IDS = {
|
|
5
|
+
[-1]: "Activity", 50: "Machine Workout", 54: "Jogging", 58: "Obstacle Racing", 67: "Plyometrics",
|
|
6
|
+
68: "Spinning", 69: "Sex", 72: "Pit Practice", 116: "Resonance Frequency Breathing",
|
|
7
|
+
};
|
|
8
|
+
const norm = (s) => s.toLowerCase().replace(/[^a-z0-9]+/g, "");
|
|
9
|
+
/** "ski-erg (Ski Erg)" — what a model should pass back. */
|
|
10
|
+
export function describeType(t) {
|
|
11
|
+
return `${t.internal_name.trim()} (${t.name})`;
|
|
12
|
+
}
|
|
13
|
+
function levenshtein(a, b) {
|
|
14
|
+
if (a === b)
|
|
15
|
+
return 0;
|
|
16
|
+
const prev = Array.from({ length: b.length + 1 }, (_, i) => i);
|
|
17
|
+
for (let i = 1; i <= a.length; i++) {
|
|
18
|
+
let diag = prev[0];
|
|
19
|
+
prev[0] = i;
|
|
20
|
+
for (let j = 1; j <= b.length; j++) {
|
|
21
|
+
const tmp = prev[j];
|
|
22
|
+
prev[j] = Math.min(prev[j] + 1, prev[j - 1] + 1, diag + (a[i - 1] === b[j - 1] ? 0 : 1));
|
|
23
|
+
diag = tmp;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return prev[b.length];
|
|
27
|
+
}
|
|
28
|
+
function similarity(query, field) {
|
|
29
|
+
if (!query || !field)
|
|
30
|
+
return 0;
|
|
31
|
+
if (field === query)
|
|
32
|
+
return 1;
|
|
33
|
+
if (field.startsWith(query) || query.startsWith(field))
|
|
34
|
+
return 0.9 - Math.abs(field.length - query.length) / 100;
|
|
35
|
+
if (field.includes(query) || query.includes(field))
|
|
36
|
+
return 0.8 - Math.abs(field.length - query.length) / 100;
|
|
37
|
+
return 1 - levenshtein(query, field) / Math.max(query.length, field.length);
|
|
38
|
+
}
|
|
39
|
+
/** Top-n catalog entries closest to `query`, as "internal_name (Name)". */
|
|
40
|
+
export function suggestActivityTypes(query, n = 5, catalog = ACTIVITY_TYPES) {
|
|
41
|
+
const q = norm(query);
|
|
42
|
+
const words = query.toLowerCase().split(/[^a-z0-9]+/).filter((w) => w.length > 2);
|
|
43
|
+
return catalog
|
|
44
|
+
.map((t) => {
|
|
45
|
+
let score = Math.max(similarity(q, norm(t.internal_name)), similarity(q, norm(t.name)));
|
|
46
|
+
// A whole word of the query inside the name ("bike" → "Assault Bike") beats edit distance.
|
|
47
|
+
if (words.some((w) => t.name.toLowerCase().includes(w) || t.internal_name.includes(w)))
|
|
48
|
+
score = Math.max(score, 0.75);
|
|
49
|
+
return { t, score };
|
|
50
|
+
})
|
|
51
|
+
.sort((a, b) => b.score - a.score || a.t.name.localeCompare(b.t.name))
|
|
52
|
+
.slice(0, n)
|
|
53
|
+
.map(({ t }) => describeType(t));
|
|
54
|
+
}
|
|
55
|
+
function matchIn(catalog, raw) {
|
|
56
|
+
const exact = catalog.find((t) => t.internal_name === raw);
|
|
57
|
+
if (exact)
|
|
58
|
+
return { type: exact, by: "internal_name" };
|
|
59
|
+
const lower = raw.trim().toLowerCase();
|
|
60
|
+
const byInternal = catalog.find((t) => t.internal_name.trim().toLowerCase() === lower);
|
|
61
|
+
if (byInternal)
|
|
62
|
+
return { type: byInternal, by: "internal_name" };
|
|
63
|
+
const byName = catalog.find((t) => t.name.toLowerCase() === lower);
|
|
64
|
+
if (byName)
|
|
65
|
+
return { type: byName, by: "name" };
|
|
66
|
+
const n = norm(raw);
|
|
67
|
+
const loose = n ? catalog.find((t) => norm(t.internal_name) === n || norm(t.name) === n) : undefined;
|
|
68
|
+
return loose ? { type: loose, by: "name" } : null;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Resolve an internal_name ("ski-erg"), a display name ("Strength Trainer"), or a
|
|
72
|
+
* current sport_id (339, or "339") against the bundled catalog.
|
|
73
|
+
*/
|
|
74
|
+
export function resolveActivityType(input, catalog = ACTIVITY_TYPES) {
|
|
75
|
+
const raw = typeof input === "number" ? String(input) : input;
|
|
76
|
+
if (/^-?\d+$/.test(raw.trim())) {
|
|
77
|
+
const id = Number(raw.trim());
|
|
78
|
+
const fromCatalog = catalog.find((t) => t.sport_id === id);
|
|
79
|
+
if (fromCatalog)
|
|
80
|
+
return { ok: true, type: fromCatalog, matched_by: "sport_id" };
|
|
81
|
+
const retired = RETIRED_SPORT_IDS[id];
|
|
82
|
+
if (retired) {
|
|
83
|
+
return { ok: false, error: `sport_id ${id} (${retired}) is retired; WHOOP rejects it.`, suggestions: suggestActivityTypes(retired, 5, catalog) };
|
|
84
|
+
}
|
|
85
|
+
return { ok: false, error: `Unknown sport_id ${id}.`, suggestions: [] };
|
|
86
|
+
}
|
|
87
|
+
if (!raw.trim())
|
|
88
|
+
return { ok: false, error: "Empty activity type.", suggestions: [] };
|
|
89
|
+
const hit = matchIn(catalog, raw);
|
|
90
|
+
if (hit)
|
|
91
|
+
return { ok: true, type: hit.type, matched_by: hit.by };
|
|
92
|
+
return { ok: false, error: `Unknown activity type "${raw}".`, suggestions: suggestActivityTypes(raw, 5, catalog) };
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Join WHOOP's live catalogs the way the bundled one was generated: a type's
|
|
96
|
+
* sport is the current sport whose activity_type_internal_name matches, else the
|
|
97
|
+
* one whose name equals the display name (case-insensitive).
|
|
98
|
+
*/
|
|
99
|
+
export function joinActivityCatalog(rawSports, rawTypes) {
|
|
100
|
+
const sports = (Array.isArray(rawSports) ? rawSports : []);
|
|
101
|
+
const current = sports.filter((s) => s.is_current !== false && typeof s.id === "number" && typeof s.name === "string");
|
|
102
|
+
const byInternal = new Map(current.filter((s) => typeof s.activity_type_internal_name === "string").map((s) => [s.activity_type_internal_name, s]));
|
|
103
|
+
const byName = new Map(current.map((s) => [s.name.toLowerCase(), s]));
|
|
104
|
+
const types = (Array.isArray(rawTypes) ? rawTypes : []);
|
|
105
|
+
const out = [];
|
|
106
|
+
for (const t of types) {
|
|
107
|
+
if (typeof t.internal_name !== "string" || typeof t.display_name !== "string" || t.deleted === true)
|
|
108
|
+
continue;
|
|
109
|
+
const scoreType = t.score_type === "RECOVERY" || t.score_type === "SLEEP" ? t.score_type : "CARDIO";
|
|
110
|
+
const sport = byInternal.get(t.internal_name) ?? byName.get(t.display_name.toLowerCase());
|
|
111
|
+
out.push({
|
|
112
|
+
internal_name: t.internal_name,
|
|
113
|
+
name: t.display_name,
|
|
114
|
+
sport_id: typeof sport?.id === "number" ? sport.id : null,
|
|
115
|
+
score_type: scoreType,
|
|
116
|
+
category: typeof t.category === "string" ? t.category : "",
|
|
117
|
+
msk_linkable: t.msk_linkable === true,
|
|
118
|
+
has_gps: t.has_gps === true,
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
return out;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Bundled lookup first; on a miss, re-fetch the live catalogs (new types WHOOP
|
|
125
|
+
* shipped after this build) and try again. Live failures fall back to the
|
|
126
|
+
* bundled suggestions.
|
|
127
|
+
*/
|
|
128
|
+
export async function resolveActivityTypeLive(client, input) {
|
|
129
|
+
const local = resolveActivityType(input);
|
|
130
|
+
if (local.ok)
|
|
131
|
+
return local;
|
|
132
|
+
try {
|
|
133
|
+
const [sports, types] = await Promise.all([
|
|
134
|
+
client.get("/activities-service/v1/sports"),
|
|
135
|
+
client.get("/activities-service/v2/activity-types"),
|
|
136
|
+
]);
|
|
137
|
+
const live = joinActivityCatalog(sports, types);
|
|
138
|
+
if (live.length) {
|
|
139
|
+
const hit = resolveActivityType(input, live);
|
|
140
|
+
if (hit.ok)
|
|
141
|
+
return { ok: true, type: hit.type, matched_by: "live_catalog" };
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
catch {
|
|
145
|
+
// Live catalog unavailable: the bundled answer stands.
|
|
146
|
+
}
|
|
147
|
+
return local;
|
|
148
|
+
}
|
|
149
|
+
/** Catalog entry for an internal_name seen in a WHOOP payload (tolerates trimming). */
|
|
150
|
+
export function typeForInternalName(name) {
|
|
151
|
+
if (!name)
|
|
152
|
+
return undefined;
|
|
153
|
+
return ACTIVITY_TYPES_BY_INTERNAL_NAME.get(name) ?? ACTIVITY_TYPES.find((t) => t.internal_name.trim() === name.trim());
|
|
154
|
+
}
|
|
155
|
+
export function isSleepType(internalName) {
|
|
156
|
+
return internalName === "sleep" || internalName === "nap";
|
|
157
|
+
}
|
|
158
|
+
export function resolveGarment(id) {
|
|
159
|
+
const garment = GARMENTS_BY_ID.get(id);
|
|
160
|
+
if (garment)
|
|
161
|
+
return { ok: true, garment };
|
|
162
|
+
return { ok: false, error: `Unknown garment_id ${id}. Valid: ${GARMENTS.map((g) => `${g.id} ${g.name}`).join(", ")}.` };
|
|
163
|
+
}
|
|
164
|
+
//# sourceMappingURL=activity_types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"activity_types.js","sourceRoot":"","sources":["../../src/lib/activity_types.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,cAAc,EAAE,+BAA+B,EAAqC,MAAM,mBAAmB,CAAC;AACvH,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAgB,MAAM,qBAAqB,CAAC;AAE7E,qFAAqF;AACrF,MAAM,iBAAiB,GAA2B;IAChD,CAAC,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,EAAE,EAAE,iBAAiB,EAAE,EAAE,EAAE,SAAS,EAAE,EAAE,EAAE,iBAAiB,EAAE,EAAE,EAAE,aAAa;IAChG,EAAE,EAAE,UAAU,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,cAAc,EAAE,GAAG,EAAE,+BAA+B;CACpF,CAAC;AAMF,MAAM,IAAI,GAAG,CAAC,CAAS,EAAU,EAAE,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,aAAa,EAAE,EAAE,CAAC,CAAC;AAE/E,2DAA2D;AAC3D,MAAM,UAAU,YAAY,CAAC,CAA+C;IAC1E,OAAO,GAAG,CAAC,CAAC,aAAa,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,IAAI,GAAG,CAAC;AACjD,CAAC;AAED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C;AAED,uFAAuF;AACvF,MAAM,UAAU,mBAAmB,CAAC,IAA+B;IACjE,IAAI,CAAC,IAAI;QAAE,OAAO,SAAS,CAAC;IAC5B,OAAO,+BAA+B,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,cAAc,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,aAAa,CAAC,IAAI,EAAE,KAAK,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;AACzH,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,YAAuC;IACjE,OAAO,YAAY,KAAK,OAAO,IAAI,YAAY,KAAK,KAAK,CAAC;AAC5D,CAAC;AAID,MAAM,UAAU,cAAc,CAAC,EAAU;IACvC,MAAM,OAAO,GAAG,cAAc,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IACvC,IAAI,OAAO;QAAE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;IAC1C,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,sBAAsB,EAAE,YAAY,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC;AAC1H,CAAC"}
|
|
@@ -0,0 +1,63 @@
|
|
|
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
|
+
export const BRAND = {
|
|
10
|
+
ice: "#B7D3F2",
|
|
11
|
+
ink: "#141414",
|
|
12
|
+
fold: "#7A9CC6",
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* The logo as one inline SVG string: assets/brand/totem.svg without its title,
|
|
16
|
+
* comments and ids, so it can sit in a page more than once.
|
|
17
|
+
* tests/lib/brand.test.ts keeps the two in step.
|
|
18
|
+
*/
|
|
19
|
+
export const TOTEM_LOGO_SVG = '<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>';
|
|
20
|
+
/** Where a server serves the logo as its favicon, and the tag that points there. */
|
|
21
|
+
export const FAVICON_PATH = "/favicon.svg";
|
|
22
|
+
export const FAVICON_LINK = `<link rel="icon" href="${FAVICON_PATH}" type="image/svg+xml">`;
|
|
23
|
+
/**
|
|
24
|
+
* The logo for a page header that names totem in text beside it: the same
|
|
25
|
+
* shapes in a viewBox cut to the mark (x 125–875, y 176.84–823.16), so it
|
|
26
|
+
* fills its box and lines up with the text.
|
|
27
|
+
*/
|
|
28
|
+
export const TOTEM_MARK = TOTEM_LOGO_SVG
|
|
29
|
+
.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">');
|
|
30
|
+
/**
|
|
31
|
+
* 128 px PNG of the logo on a transparent background, for MCP clients that
|
|
32
|
+
* don't draw SVG icons. Regenerate after a logo change:
|
|
33
|
+
* magick -background none -density 192 assets/brand/totem.svg -resize 128x128 -depth 8 +dither -colors 64 -strip -define png:compression-level=9 icon.png
|
|
34
|
+
*/
|
|
35
|
+
const ICON_PNG_128 = "iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAMAAAD04JH5AAAAbFBMVEWlw+WiweO30/KYt9u30/K10fG30/K30/KQsNa30/Kuy+uK" +
|
|
36
|
+
"qtK30/K30/J7ncePr9W30/J8nse30/J7nce30/J6nMZ7ncd6nMZ7ncd7ncZ7ncd8nceOrtS30/J6nMaDpM2Wtdq41POeveF/oco3" +
|
|
37
|
+
"j25FAAAAHXRSTlMAC1xQuPrFUxad+iPg6LEU1UAqkBnscdn7x4Jk/KAY6UUAAAPKSURBVHja7VttYqowEBQRQUQwRYraAmLvf8fy" +
|
|
38
|
+
"1PqAbMgm2YQ/zAHMmNnvLKvVggULFixYYARvvfbmPN/fBNU2nO34aBdXHeLdfqbbT6oXDmnm/vz1serh6NoUWCf+AMHGd3j8R3qo" +
|
|
39
|
+
"OMS7yJn42wpEkjvRIRQc/zAFZv34/dP1RLBtChkk/sgU0g+L4h8rBLa2XHJK/BGF0L34Y5ekjs6nPKmUQBudkeKPXJLOFPxx3HVr" +
|
|
40
|
+
"CpGK+KNL2FPcfqJ7PEly0BGfMCayjf7try0lXRyS/DSP6wnD0N6zF3cR3hflRcrsxV1Z/PE+y7quzwoUMn3xgQjsX+onijybQ/z0" +
|
|
41
|
+
"XL9RfiJMIdwQip/lRT3AxbcYdwXiD3FO95RJty8+V4n5aQ2hFJsCM4i7jBe/qAUQmIJu0gXjrpeXtRiQS0aptvgJL344dfzDJdPI" +
|
|
42
|
+
"YtJlfdcT6tBvo0LKpBtdixqF8q2DdyR0va+yRqJp/hznlJDFXZaij78FBzMCQNxFif/ErbN5MwKIuCvGd1y1ZgRwcVd0+/d/x5sQ" +
|
|
43
|
+
"mEq6GPHb189oEpAlXentv/+HHgE+7mZ5qSa+CYHETPyg7SupTgAYf+Bd7+c2OF6dQFttuSTmaYmvSSD+LkPtyDsQX4dAG9x+wEQe" +
|
|
44
|
+
"YcJPM759VQJtcG/gRI6xgk58OJxgCbTd7QsS+YtCqXr7agT6xz8TuYevwP7irjaBTvwGUdNFcA0Ki69AoK3uDVjT5ShTuE0WmnIC" +
|
|
45
|
+
"LXf7PR2+pKWoUHw0gfg2ZVx8mzVIChPi4whA4ktN4Z0WJ8XHEOhuv5EHGKDjfhYG35guY4LAlPiyNqvLjjLx5QQecRcHvjiKdkGL" +
|
|
46
|
+
"K6wEBOTi9y6AT0/4JgsmgL99sNNWGa/ABPDHF/ysgSl12ACBVkV833SyyREQxV2k9SsPt0YEVMQH/F9jsjkiMB13JYMmrclmn4CK" +
|
|
47
|
+
"6wE5QG+y2SfgVnyOQKMgfkQ31n4TWIUlVnxGOtZW7e5KZnGyKe9v+RLI4EUp5iebkg6/uEZWJ5uSNhcqg3eEk03ZlMco6ao9J0K1" +
|
|
48
|
+
"tWHSVX1OHA/Zz1DSJXxUAExh0HFfjJNuX/wr7jnxf8dNGHfVthqepkCTdPUe8z1WUiVd3XWGjNl9Tpz5LVljh2fjSHzy50SKtSba" +
|
|
49
|
+
"50SNv7/Vj7s023VrTQZ0y31aHpCQ7rQpJwD6BU+lvtPOXiNeB1tLvsgyyOaaMyIg2V70lpXC9lfdJ13SzYa3MC2723EHCxO3W/58" +
|
|
50
|
+
"aUaxPmdgCskMX3r0TMHmNjXCFNx+WsBHZwcb9ZOmsD6tFixYsGDBAiP8Avw8HRY2BcgBAAAAAElFTkSuQmCC";
|
|
51
|
+
/** The MCP server's icons (serverInfo.icons): the SVG, and the PNG for clients that don't draw SVG. */
|
|
52
|
+
export const SERVER_ICONS = [
|
|
53
|
+
{ src: `data:image/svg+xml;base64,${Buffer.from(TOTEM_LOGO_SVG).toString("base64")}`, mimeType: "image/svg+xml", sizes: ["any"] },
|
|
54
|
+
{ src: `data:image/png;base64,${ICON_PNG_128}`, mimeType: "image/png", sizes: ["128x128"] },
|
|
55
|
+
];
|
|
56
|
+
/** What the MCP server says it is (initialize's serverInfo), on stdio and HTTP alike. */
|
|
57
|
+
export const serverIdentity = (version) => ({
|
|
58
|
+
name: "totem",
|
|
59
|
+
version,
|
|
60
|
+
websiteUrl: "https://github.com/thebriangao/totem",
|
|
61
|
+
icons: SERVER_ICONS,
|
|
62
|
+
});
|
|
63
|
+
//# sourceMappingURL=brand.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"brand.js","sourceRoot":"","sources":["../../src/lib/brand.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,8EAA8E;AAC9E,EAAE;AACF,gFAAgF;AAChF,+EAA+E;AAC/E,2EAA2E;AAC3E,8EAA8E;AAC9E,2CAA2C;AAE3C,MAAM,CAAC,MAAM,KAAK,GAAG;IACnB,GAAG,EAAE,SAAS;IACd,GAAG,EAAE,SAAS;IACd,IAAI,EAAE,SAAS;CACP,CAAC;AAEX;;;;GAIG;AACH,MAAM,CAAC,MAAM,cAAc,GACzB,sgBAAsgB,CAAC;AAEzgB,oFAAoF;AACpF,MAAM,CAAC,MAAM,YAAY,GAAG,cAAc,CAAC;AAC3C,MAAM,CAAC,MAAM,YAAY,GAAG,0BAA0B,YAAY,yBAAyB,CAAC;AAE5F;;;;GAIG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,cAAc;KACrC,OAAO,CAAC,oEAAoE,EAAE,uFAAuF,CAAC,CAAC;AAE1K;;;;GAIG;AACH,MAAM,YAAY,GAChB,sGAAsG;IACtG,sGAAsG;IACtG,sGAAsG;IACtG,sGAAsG;IACtG,sGAAsG;IACtG,sGAAsG;IACtG,sGAAsG;IACtG,sGAAsG;IACtG,sGAAsG;IACtG,sGAAsG;IACtG,sGAAsG;IACtG,sGAAsG;IACtG,sGAAsG;IACtG,sGAAsG;IACtG,sGAAsG;IACtG,sFAAsF,CAAC;AAEzF,uGAAuG;AACvG,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,EAAE,GAAG,EAAE,6BAA6B,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,EAAE,QAAQ,EAAE,eAAe,EAAE,KAAK,EAAE,CAAC,KAAK,CAAC,EAAE;IACjI,EAAE,GAAG,EAAE,yBAAyB,YAAY,EAAE,EAAE,QAAQ,EAAE,WAAW,EAAE,KAAK,EAAE,CAAC,SAAS,CAAC,EAAE;CAC5F,CAAC;AAEF,yFAAyF;AACzF,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,OAAe,EAAE,EAAE,CAAC,CAAC;IAClD,IAAI,EAAE,OAAO;IACb,OAAO;IACP,UAAU,EAAE,sCAAsC;IAClD,KAAK,EAAE,YAAY;CACpB,CAAC,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/** Normalize common human/Whoop clock forms to the wire format HH:MM:SS. */
|
|
2
|
+
export function normalizeClockTime(value) {
|
|
3
|
+
const match = value.trim().match(/^(\d{1,2}):(\d{2})(?::(\d{2}))?\s*(AM|PM)?$/i);
|
|
4
|
+
if (!match)
|
|
5
|
+
return null;
|
|
6
|
+
let hour = Number(match[1]);
|
|
7
|
+
const minute = Number(match[2]);
|
|
8
|
+
const second = Number(match[3] ?? "0");
|
|
9
|
+
const meridiem = match[4]?.toUpperCase();
|
|
10
|
+
if (minute > 59 || second > 59)
|
|
11
|
+
return null;
|
|
12
|
+
if (meridiem) {
|
|
13
|
+
if (hour < 1 || hour > 12)
|
|
14
|
+
return null;
|
|
15
|
+
if (hour === 12)
|
|
16
|
+
hour = 0;
|
|
17
|
+
if (meridiem === "PM")
|
|
18
|
+
hour += 12;
|
|
19
|
+
}
|
|
20
|
+
else if (hour > 23)
|
|
21
|
+
return null;
|
|
22
|
+
return `${String(hour).padStart(2, "0")}:${String(minute).padStart(2, "0")}:${String(second).padStart(2, "0")}`;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=clock.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clock.js","sourceRoot":"","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int, post a turn,
|
|
2
|
+
// poll it to COMPLETE, look fingerprints up in the history list, resolve the
|
|
3
|
+
// cycle for Daily Outlook / Day in Review, and attach an image. specs/ai.md.
|
|
4
|
+
//
|
|
5
|
+
// Rules (SPEC.md §7 S23): address turns by fingerprint only; never send /seen,
|
|
6
|
+
// /end-seen or /last-viewed-turn; reopen only listed fingerprints (reopening an
|
|
7
|
+
// unlisted one creates it, and for outlooks generates the report); never cache
|
|
8
|
+
// or accept a cycle id.
|
|
9
|
+
import { randomInt, randomUUID } from "node:crypto";
|
|
10
|
+
import { WhoopApiError, WhoopServerError } from "../whoop/errors.js";
|
|
11
|
+
import { get, str } from "../whoop/bff.js";
|
|
12
|
+
import { AGENT_SOURCES, REPORT_PREFIX, assistantText, homeCycleId, projectConversationList, projectRecommendations, recommendationPath, turnActions, turnCards, turnStatus, } from "../projections/coach.js";
|
|
13
|
+
export const AI = "/ai-conversation-bff/v1";
|
|
14
|
+
const conversationPath = (fp) => `${AI}/conversation/${encodeURIComponent(fp)}`;
|
|
15
|
+
const DEFAULT_TOTAL_BUDGET_MS = 50_000;
|
|
16
|
+
/** The same timing with both waits capped by what is left of the overall budget. */
|
|
17
|
+
function withinBudget(timing) {
|
|
18
|
+
const end = timing.now() + (timing.totalBudgetMs ?? DEFAULT_TOTAL_BUDGET_MS);
|
|
19
|
+
const left = () => Math.max(0, end - timing.now());
|
|
20
|
+
return {
|
|
21
|
+
...timing,
|
|
22
|
+
get replyTimeoutMs() { return Math.min(timing.replyTimeoutMs, left()); },
|
|
23
|
+
get settleTimeoutMs() { return Math.min(timing.settleTimeoutMs, left()); },
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
export const DEFAULT_TIMING = {
|
|
27
|
+
now: Date.now,
|
|
28
|
+
sleep: (ms) => new Promise((resolve) => setTimeout(resolve, ms)),
|
|
29
|
+
pollDelayMs: () => randomInt(3_000, 4_001),
|
|
30
|
+
replyTimeoutMs: 60_000,
|
|
31
|
+
settleTimeoutMs: 30_000,
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* WHOOP's terminal failure: the turn comes back `turn_status:"FAILED"` with no
|
|
35
|
+
* messages and never changes again (seen live 2026-11-21 on an activity-agent
|
|
36
|
+
* greeting and on the user turn posted after it).
|
|
37
|
+
*/
|
|
38
|
+
export const FAILED = "FAILED";
|
|
39
|
+
/** A 5xx, a network failure or a request timeout: worth another poll. */
|
|
40
|
+
function isTransient(e) {
|
|
41
|
+
if (e instanceof WhoopServerError)
|
|
42
|
+
return true;
|
|
43
|
+
if (!(e instanceof Error))
|
|
44
|
+
return false;
|
|
45
|
+
return e.name === "AbortError" || e.name === "TimeoutError" || (e instanceof TypeError && /fetch failed|network/i.test(e.message));
|
|
46
|
+
}
|
|
47
|
+
/** Poll GET …/conversation/{fingerprint}/turn/{id} until COMPLETE, FAILED or the deadline. */
|
|
48
|
+
export async function waitForTurn(client, fingerprint, turnId, timeoutMs, timing) {
|
|
49
|
+
const deadline = timing.now() + timeoutMs;
|
|
50
|
+
let turn = null;
|
|
51
|
+
let status = "ACTIVE";
|
|
52
|
+
let polls = 0;
|
|
53
|
+
// No "text stable for N polls" shortcut: text can sit unchanged for several
|
|
54
|
+
// polls while tools run (ai §2.3). COMPLETE is the only done signal; FAILED
|
|
55
|
+
// is the only other state that ends the wait.
|
|
56
|
+
while (timing.now() < deadline) {
|
|
57
|
+
await timing.sleep(Math.min(timing.pollDelayMs(), Math.max(0, deadline - timing.now())));
|
|
58
|
+
polls++;
|
|
59
|
+
try {
|
|
60
|
+
turn = await client.get(`${conversationPath(fingerprint)}/turn/${encodeURIComponent(turnId)}`, {}, { fresh: true });
|
|
61
|
+
}
|
|
62
|
+
catch (e) {
|
|
63
|
+
// One failed poll says nothing about the turn, which keeps running on WHOOP's side.
|
|
64
|
+
if (!isTransient(e))
|
|
65
|
+
throw e;
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
status = turnStatus(turn) ?? status;
|
|
69
|
+
if (status === "COMPLETE" || status === FAILED)
|
|
70
|
+
return { turn, status, timedOut: false, polls };
|
|
71
|
+
}
|
|
72
|
+
return { turn, status, timedOut: true, polls };
|
|
73
|
+
}
|
|
74
|
+
/** POST …/conversation: creates the fingerprint, or reopens it (no side effects when it exists). */
|
|
75
|
+
export async function openConversation(client, body) {
|
|
76
|
+
const res = await client.post(`${AI}/conversation`, body);
|
|
77
|
+
return res && typeof res === "object" ? res : {};
|
|
78
|
+
}
|
|
79
|
+
function lastTurn(conversation) {
|
|
80
|
+
const turns = Array.isArray(conversation.turns) ? conversation.turns : [];
|
|
81
|
+
const last = turns[turns.length - 1];
|
|
82
|
+
return last && typeof last === "object" ? last : null;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Wait for the conversation's last turn when it is still ACTIVE: an agent's
|
|
86
|
+
* turn-0 greeting (posting before it completes gets the greeting back as the
|
|
87
|
+
* "reply", ai §2.2) or a previous user turn (a new post would 409). coach-chat's
|
|
88
|
+
* empty turn 0 counts too: posting while it is ACTIVE got a 409 live
|
|
89
|
+
* (coach-build smoke test, 2026-11-21).
|
|
90
|
+
*/
|
|
91
|
+
async function settle(client, fingerprint, conversation, timing) {
|
|
92
|
+
const last = lastTurn(conversation);
|
|
93
|
+
if (!last || turnStatus(last) !== "ACTIVE" || typeof last.id !== "string")
|
|
94
|
+
return;
|
|
95
|
+
await waitForTurn(client, fingerprint, last.id, timing.settleTimeoutMs, timing);
|
|
96
|
+
}
|
|
97
|
+
const isBusy = (e) => e instanceof WhoopApiError && e.status === 409;
|
|
98
|
+
/**
|
|
99
|
+
* POST a user turn. On 409 "Another message is currently being processed",
|
|
100
|
+
* reopen (no side effects), wait for the active turn to COMPLETE, and retry.
|
|
101
|
+
*/
|
|
102
|
+
export async function postTurn(client, fingerprint, body, reopen, timing, maxAttempts = 3) {
|
|
103
|
+
for (let attempt = 1;; attempt++) {
|
|
104
|
+
try {
|
|
105
|
+
const turn = await client.post(`${conversationPath(fingerprint)}/turn`, body);
|
|
106
|
+
const id = str(get(turn, "id"));
|
|
107
|
+
if (!id)
|
|
108
|
+
throw new Error("WHOOP accepted the message but returned no turn id; read the thread with whoop_coach_history.");
|
|
109
|
+
return { id, retries: attempt - 1 };
|
|
110
|
+
}
|
|
111
|
+
catch (e) {
|
|
112
|
+
if (!isBusy(e) || attempt >= maxAttempts) {
|
|
113
|
+
if (isBusy(e)) {
|
|
114
|
+
throw new Error(`Another message is still being processed in thread ${fingerprint}; try again in a minute.`);
|
|
115
|
+
}
|
|
116
|
+
throw e;
|
|
117
|
+
}
|
|
118
|
+
const conversation = await openConversation(client, reopen);
|
|
119
|
+
const last = lastTurn(conversation);
|
|
120
|
+
if (last && turnStatus(last) === "ACTIVE" && typeof last.id === "string") {
|
|
121
|
+
await waitForTurn(client, fingerprint, last.id, timing.settleTimeoutMs, timing);
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
await timing.sleep(timing.pollDelayMs());
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
/** One page of the history list. */
|
|
130
|
+
export async function listConversations(client, limit, cursor) {
|
|
131
|
+
const raw = await client.get(`${AI}/conversations`, { limit, next_token: cursor }, { fresh: true });
|
|
132
|
+
return projectConversationList(raw);
|
|
133
|
+
}
|
|
134
|
+
/** Look a fingerprint up in a fresh history list (newest first, a few pages). */
|
|
135
|
+
export async function findListed(client, match, maxPages = 5, pageSize = 50) {
|
|
136
|
+
let cursor;
|
|
137
|
+
for (let page = 0; page < maxPages; page++) {
|
|
138
|
+
const { conversations, next_cursor } = await listConversations(client, pageSize, cursor);
|
|
139
|
+
const hit = conversations.find(match);
|
|
140
|
+
if (hit)
|
|
141
|
+
return hit;
|
|
142
|
+
if (!next_cursor)
|
|
143
|
+
return null;
|
|
144
|
+
cursor = next_cursor;
|
|
145
|
+
}
|
|
146
|
+
return null;
|
|
147
|
+
}
|
|
148
|
+
/** The cycle id from home, read right before use (never cached: it changes under edits). */
|
|
149
|
+
export async function resolveCycleId(client, date) {
|
|
150
|
+
const home = await client.get("/home-service/v1/home", date ? { date } : {}, { fresh: true });
|
|
151
|
+
const id = homeCycleId(home);
|
|
152
|
+
if (id === null)
|
|
153
|
+
throw new Error(`WHOOP's home screen${date ? ` for ${date}` : ""} has no cycle yet, so there is no report to open.`);
|
|
154
|
+
return id;
|
|
155
|
+
}
|
|
156
|
+
export async function fetchRecommendations(client, path) {
|
|
157
|
+
if (!path)
|
|
158
|
+
return null;
|
|
159
|
+
try {
|
|
160
|
+
const url = new URL(path.startsWith("/") ? path : `/${path}`, "https://x");
|
|
161
|
+
if (!url.pathname.startsWith(`${AI}/recommendation-widget`))
|
|
162
|
+
return null;
|
|
163
|
+
const query = Object.fromEntries(url.searchParams.entries());
|
|
164
|
+
const raw = await client.get(url.pathname, query, { fresh: true });
|
|
165
|
+
return projectRecommendations(raw);
|
|
166
|
+
}
|
|
167
|
+
catch {
|
|
168
|
+
return null;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
export async function fetchSuggestions(client, fingerprint) {
|
|
172
|
+
try {
|
|
173
|
+
const raw = await client.get(`${conversationPath(fingerprint)}/suggestions`, {}, { fresh: true });
|
|
174
|
+
const list = get(raw, "suggestions");
|
|
175
|
+
return Array.isArray(list) ? list.filter((s) => typeof s === "string") : [];
|
|
176
|
+
}
|
|
177
|
+
catch {
|
|
178
|
+
return [];
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
// ─── Images ───────────────────────────────────────────────────────────────
|
|
182
|
+
export const MAX_IMAGE_BYTES = 5 * 1024 * 1024;
|
|
183
|
+
/** Decode and sniff a base64 image (optionally a data: URL). PNG and JPEG only. */
|
|
184
|
+
export function parseImage(input) {
|
|
185
|
+
const base64 = input.replace(/^data:image\/[a-z+]+;base64,/i, "").replace(/\s+/g, "");
|
|
186
|
+
if (!/^[A-Za-z0-9+/]+={0,2}$/.test(base64))
|
|
187
|
+
throw new Error("image_base64 isn't valid base64.");
|
|
188
|
+
const buf = Buffer.from(base64, "base64");
|
|
189
|
+
if (buf.length === 0)
|
|
190
|
+
throw new Error("image_base64 decodes to nothing.");
|
|
191
|
+
if (buf.length > MAX_IMAGE_BYTES)
|
|
192
|
+
throw new Error(`The image is ${buf.length} bytes; the limit is ${MAX_IMAGE_BYTES}.`);
|
|
193
|
+
const png = buf.subarray(0, 4).equals(Buffer.from([0x89, 0x50, 0x4e, 0x47]));
|
|
194
|
+
const jpeg = buf[0] === 0xff && buf[1] === 0xd8 && buf[2] === 0xff;
|
|
195
|
+
if (!png && !jpeg)
|
|
196
|
+
throw new Error("Only PNG or JPEG images can be attached.");
|
|
197
|
+
return { base64, contentType: png ? "image/png" : "image/jpeg", bytes: buf.length };
|
|
198
|
+
}
|
|
199
|
+
// ─── Fingerprints ─────────────────────────────────────────────────────────
|
|
200
|
+
/** D7: one totem thread per agent per member-local day, e.g. `totem-HOME-2026-11-21`. */
|
|
201
|
+
export function dailyFingerprint(agent, localDate, activityId) {
|
|
202
|
+
const tag = AGENT_SOURCES[agent]?.tag ?? agent.toUpperCase();
|
|
203
|
+
return activityId ? `totem-${tag}-${localDate}-${activityId}` : `totem-${tag}-${localDate}`;
|
|
204
|
+
}
|
|
205
|
+
export function freshFingerprint(agent, localDate) {
|
|
206
|
+
return `${dailyFingerprint(agent, localDate)}-${randomUUID().slice(0, 8)}`;
|
|
207
|
+
}
|
|
208
|
+
export function reportFingerprint(kind, cycleId) {
|
|
209
|
+
return `${REPORT_PREFIX[kind]}${cycleId}`;
|
|
210
|
+
}
|
|
211
|
+
function emptyReceipt(thread) {
|
|
212
|
+
return {
|
|
213
|
+
thread, text: null, actions: [], cards: [], suggestions: [], report: null, image_deleted: null,
|
|
214
|
+
verified: false, warnings: [],
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
function describeTurn(receipt, turn) {
|
|
218
|
+
receipt.text = turn ? assistantText(turn) : null;
|
|
219
|
+
receipt.actions = turn ? turnActions(turn) : [];
|
|
220
|
+
receipt.cards = turn ? turnCards(turn) : [];
|
|
221
|
+
if (receipt.actions.length) {
|
|
222
|
+
receipt.warnings.push("The coach changed your data (see actions). It returns no ids; check whoop_day or whoop_workouts.");
|
|
223
|
+
}
|
|
224
|
+
for (const card of receipt.cards) {
|
|
225
|
+
if (card.type === "workout_draft") {
|
|
226
|
+
receipt.warnings.push(`The coach created a hidden draft template${card.draft_template_key ? ` (${card.draft_template_key})` : ""}; it's not in your library until saved (whoop_lift_template).`);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
/** Local marker (never a WHOOP status): the turn was posted but could not be polled. */
|
|
231
|
+
const UNREAD = "UNREAD";
|
|
232
|
+
const notDone = (s, what, view) => `The ${what} wasn't COMPLETE after ${s} s; read it later with whoop_coach_history ${view}.`;
|
|
233
|
+
/** Generate or open the current cycle's Daily Outlook / Day in Review. */
|
|
234
|
+
async function openReport(client, kind, outerTiming) {
|
|
235
|
+
const started = outerTiming.now();
|
|
236
|
+
const timing = withinBudget(outerTiming);
|
|
237
|
+
const cycleId = await resolveCycleId(client);
|
|
238
|
+
const fingerprint = reportFingerprint(kind, cycleId);
|
|
239
|
+
const existed = (await findListed(client, (c) => c.fingerprint === fingerprint, 1)) !== null;
|
|
240
|
+
const receipt = emptyReceipt(fingerprint);
|
|
241
|
+
const conversation = await openConversation(client, { fingerprint, source_id: AGENT_SOURCES[kind].source_id, source_type: "UNKNOWN" });
|
|
242
|
+
// The report is turn 0. Later turns are the member's follow-up chat about it.
|
|
243
|
+
const turns = Array.isArray(conversation.turns) ? conversation.turns : [];
|
|
244
|
+
let turn = turns[0] && typeof turns[0] === "object" ? turns[0] : null;
|
|
245
|
+
if (turn && turnStatus(turn) !== "COMPLETE" && turnStatus(turn) !== FAILED && typeof turn.id === "string") {
|
|
246
|
+
turn = (await waitForTurn(client, fingerprint, turn.id, timing.replyTimeoutMs, timing)).turn ?? turn;
|
|
247
|
+
}
|
|
248
|
+
describeTurn(receipt, turn);
|
|
249
|
+
receipt.verified = turnStatus(turn) === "COMPLETE";
|
|
250
|
+
const recommendations = receipt.verified ? await fetchRecommendations(client, recommendationPath(turn)) : null;
|
|
251
|
+
receipt.report = { kind, generated: !existed, recommendations };
|
|
252
|
+
if (turnStatus(turn) === FAILED)
|
|
253
|
+
receipt.warnings.push("WHOOP failed to generate the report (turn FAILED); nothing more will arrive.");
|
|
254
|
+
else if (!receipt.verified)
|
|
255
|
+
receipt.warnings.push(notDone(Math.round((outerTiming.now() - started) / 1000), "report", '{view:"outlook"}'));
|
|
256
|
+
return receipt;
|
|
257
|
+
}
|
|
258
|
+
/** The whole ask: open the thread, settle, (upload), post, poll, (delete the upload), suggestions. */
|
|
259
|
+
export async function askCoach(client, plan, outerTiming = DEFAULT_TIMING) {
|
|
260
|
+
if (plan.agent === "daily_outlook" || plan.agent === "day_in_review")
|
|
261
|
+
return openReport(client, plan.agent, outerTiming);
|
|
262
|
+
const started = outerTiming.now();
|
|
263
|
+
const timing = withinBudget(outerTiming);
|
|
264
|
+
if (!plan.message)
|
|
265
|
+
throw new Error("message is required for this agent.");
|
|
266
|
+
let fingerprint;
|
|
267
|
+
let open;
|
|
268
|
+
if (plan.thread) {
|
|
269
|
+
const listed = await findListed(client, (c) => c.fingerprint === plan.thread);
|
|
270
|
+
if (!listed) {
|
|
271
|
+
throw new Error(`Thread "${plan.thread}" isn't in your coach history. Only listed threads can be continued (reopening an unlisted fingerprint would create it); omit thread to use today's thread.`);
|
|
272
|
+
}
|
|
273
|
+
fingerprint = listed.fingerprint;
|
|
274
|
+
open = { fingerprint, source_type: "UNKNOWN", ...(listed.source_id ? { source_id: listed.source_id } : {}) };
|
|
275
|
+
}
|
|
276
|
+
else {
|
|
277
|
+
const def = AGENT_SOURCES[plan.agent];
|
|
278
|
+
fingerprint = plan.newThread ? freshFingerprint(plan.agent, plan.localDate) : dailyFingerprint(plan.agent, plan.localDate, plan.activityId);
|
|
279
|
+
const args = def.context ? { context: def.context } : {};
|
|
280
|
+
if (plan.agent === "activity" && plan.activityId)
|
|
281
|
+
args.activity_id = plan.activityId;
|
|
282
|
+
open = { fingerprint, source_type: "CHAT_WITH_AGENT", source_id: def.source_id, args, chat_entrypoint_experience: "STANDARD" };
|
|
283
|
+
}
|
|
284
|
+
const receipt = emptyReceipt(fingerprint);
|
|
285
|
+
const conversation = await openConversation(client, open);
|
|
286
|
+
await settle(client, fingerprint, conversation, timing);
|
|
287
|
+
let fileId = null;
|
|
288
|
+
let status = "ACTIVE";
|
|
289
|
+
try {
|
|
290
|
+
if (plan.image) {
|
|
291
|
+
const uploaded = await client.post(`${AI}/files`, {
|
|
292
|
+
origin: "camera_roll",
|
|
293
|
+
content_type: plan.image.contentType,
|
|
294
|
+
filename: `totem-${timing.now()}.${plan.image.contentType === "image/png" ? "png" : "jpg"}`,
|
|
295
|
+
base64_content: plan.image.base64,
|
|
296
|
+
});
|
|
297
|
+
fileId = str(get(uploaded, "file_id"));
|
|
298
|
+
if (!fileId)
|
|
299
|
+
throw new Error("WHOOP accepted the image but returned no file id; nothing was sent to the coach.");
|
|
300
|
+
}
|
|
301
|
+
const turnBody = {
|
|
302
|
+
role: "user",
|
|
303
|
+
content: plan.message,
|
|
304
|
+
is_suggestion: false,
|
|
305
|
+
...(fileId ? { file_ids: [fileId] } : {}),
|
|
306
|
+
};
|
|
307
|
+
const posted = await postTurn(client, fingerprint, turnBody, open, timing);
|
|
308
|
+
if (posted.retries)
|
|
309
|
+
receipt.warnings.push("The thread was busy with another message; totem waited for it and resent.");
|
|
310
|
+
try {
|
|
311
|
+
const polled = await waitForTurn(client, fingerprint, posted.id, timing.replyTimeoutMs, timing);
|
|
312
|
+
status = polled.status;
|
|
313
|
+
describeTurn(receipt, polled.turn);
|
|
314
|
+
}
|
|
315
|
+
catch (e) {
|
|
316
|
+
// The message is already with the coach (and it may be acting on it): an
|
|
317
|
+
// error here must not read as "nothing was sent", or the caller resends.
|
|
318
|
+
status = UNREAD;
|
|
319
|
+
receipt.warnings.push(`Your message was sent, but its reply couldn't be read (${e instanceof Error ? e.message : String(e)}). Don't resend it: read the thread with whoop_coach_history {view:"transcript", fingerprint:"${fingerprint}"}.`);
|
|
320
|
+
}
|
|
321
|
+
// The client dropped its cache when the turn was POSTed, but the coach wrote
|
|
322
|
+
// the data afterwards: anything read (by another call) in between is stale.
|
|
323
|
+
if (receipt.actions.length || status === UNREAD)
|
|
324
|
+
client.invalidateAll();
|
|
325
|
+
}
|
|
326
|
+
finally {
|
|
327
|
+
if (fileId) {
|
|
328
|
+
receipt.image_deleted = await client.delete(`${AI}/files/${encodeURIComponent(fileId)}`).then(() => true, () => false);
|
|
329
|
+
if (!receipt.image_deleted)
|
|
330
|
+
receipt.warnings.push(`Couldn't delete the uploaded image ${fileId} from WHOOP.`);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
if (status === "COMPLETE") {
|
|
334
|
+
receipt.suggestions = await fetchSuggestions(client, fingerprint);
|
|
335
|
+
receipt.verified = true;
|
|
336
|
+
}
|
|
337
|
+
else if (status === FAILED) {
|
|
338
|
+
receipt.warnings.push("WHOOP reports this turn FAILED: the coach produced no reply and none will arrive. Ask again, or use new_thread:true if this thread keeps failing.");
|
|
339
|
+
}
|
|
340
|
+
else if (status !== UNREAD) {
|
|
341
|
+
receipt.warnings.push(notDone(Math.round((outerTiming.now() - started) / 1000), "reply", `{view:"transcript", fingerprint:"${fingerprint}"}`));
|
|
342
|
+
}
|
|
343
|
+
return receipt;
|
|
344
|
+
}
|
|
345
|
+
//# sourceMappingURL=coach_session.js.map
|