@sctg/openclaw-coach 2.2.0 → 2.2.1

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.
@@ -17,6 +17,8 @@ export interface NativeGarmin {
17
17
  activity(id: string, view?: ActivityView): Promise<unknown>;
18
18
  metric(name: "training-readiness" | "training-status", date: string): Promise<unknown>;
19
19
  lactateThreshold(): Promise<unknown>;
20
+ /** Lactate-threshold heart rate, FTP and VO2 max (`gc metrics anchors`). Absent in older versions of the package. */
21
+ anchors?(): Promise<unknown>;
20
22
  }
21
23
  export type ActivityView = "splits" | "hr-zones" | "weather" | "exercise-sets";
22
24
  /** True when the native backend implements the command (writes, such as `workouts create`, stay on gc). */
@@ -34,7 +34,7 @@ export function isNativeCommand(args) {
34
34
  const [command, sub] = args;
35
35
  if (command === "daily" || command === "activities")
36
36
  return command === "daily" || !sub || sub.startsWith("--") || ACTIVITY_VIEWS.includes(sub);
37
- return command === "metrics" && (sub === "training-readiness" || sub === "training-status" || sub === "lactate-threshold");
37
+ return command === "metrics" && (sub === "training-readiness" || sub === "training-status" || sub === "lactate-threshold" || sub === "anchors");
38
38
  }
39
39
  function code(error) {
40
40
  const value = error?.code;
@@ -70,6 +70,11 @@ export function nativeRunner(api) {
70
70
  else if (positional[0] === "lactate-threshold") {
71
71
  data = await api.lactateThreshold();
72
72
  }
73
+ else if (positional[0] === "anchors") {
74
+ if (!api.anchors)
75
+ return gcFailure("unsupported");
76
+ data = await api.anchors();
77
+ }
73
78
  else {
74
79
  const date = positional[1];
75
80
  if (!date || !DATE.test(date))
@@ -106,5 +111,6 @@ export async function loadNative(tokenFile, moduleName = "@sctg/garmin-ts-client
106
111
  activity: (id, view) => call(view === undefined ? "getActivity" : { splits: "activitySplits", "hr-zones": "activityHrZones", weather: "activityWeather", "exercise-sets": "activityExerciseSets" }[view], id),
107
112
  metric: (name, date) => call(name === "training-readiness" ? "trainingReadiness" : "trainingStatus", date),
108
113
  lactateThreshold: () => call("lactateThreshold"),
114
+ ...(typeof mod.anchors === "function" ? { anchors: () => call("anchors") } : {}),
109
115
  };
110
116
  }
@@ -13,7 +13,7 @@ export declare function normalizeActivity(raw: unknown): Activity | null;
13
13
  export declare function normalizeActivities(payload: unknown): Activity[];
14
14
  /** Laps of `gc activities splits ID` (the `lapDTOs` list). */
15
15
  export declare function normalizeSplits(payload: unknown): Split[];
16
- /** Lactate-threshold heart rate from `gc metrics lactate-threshold`. */
16
+ /** Lactate-threshold heart rate from `gc metrics lactate-threshold` or `gc metrics anchors`. */
17
17
  export declare function lthrFromPayload(payload: unknown): number | null;
18
18
  /** Garmin's own readiness, status and load figures for the day, reduced to a few fields. */
19
19
  export declare function garminDaySignals(readiness: unknown, status: unknown): Json;
@@ -92,11 +92,11 @@ export function normalizeSplits(payload) {
92
92
  }
93
93
  return out;
94
94
  }
95
- /** Lactate-threshold heart rate from `gc metrics lactate-threshold`. */
95
+ /** Lactate-threshold heart rate from `gc metrics lactate-threshold` or `gc metrics anchors`. */
96
96
  export function lthrFromPayload(payload) {
97
97
  const root = obj(payload);
98
- const block = obj(root?.speed_and_heart_rate) ?? root;
99
- const value = positive(block, "heartRate", "lactateThresholdHeartRate");
98
+ const block = obj(root?.speed_and_heart_rate) ?? obj(root?.lactateThreshold) ?? root;
99
+ const value = positive(block, "heartRate", "heartRateBpm", "lactateThresholdHeartRate");
100
100
  return value !== null && value >= 100 && value <= 210 ? Math.round(value) : null;
101
101
  }
102
102
  /** Garmin's own readiness, status and load figures for the day, reduced to a few fields. */
package/dist/sync.js CHANGED
@@ -117,7 +117,12 @@ export async function syncStore(store, gc, config, today, now = new Date()) {
117
117
  }
118
118
  if (config.lthr === null && (store.lthr === null || daysBetween(store.lthr.at.slice(0, 10), today) >= LTHR_REFRESH_DAYS)) {
119
119
  const result = await gc(["metrics", "lactate-threshold"]);
120
- const value = result.ok ? lthrFromPayload(result.data) : null;
120
+ let value = result.ok ? lthrFromPayload(result.data) : null;
121
+ if (value === null && result.ok) {
122
+ // The latest-threshold endpoint can be empty while the current biometric profile has the value.
123
+ const anchors = await gc(["metrics", "anchors"]);
124
+ value = anchors.ok ? lthrFromPayload(anchors.data) : null;
125
+ }
121
126
  if (value !== null)
122
127
  store.lthr = { value, at: stamp };
123
128
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sctg/openclaw-coach",
3
- "version": "2.2.0",
3
+ "version": "2.2.1",
4
4
  "description": "AI endurance and recovery coach plugin for OpenClaw: documented physiological models (HRV baseline, recovery, sleep, training load, early warning) computed on Garmin Connect data via garmin-cli, with a coaching skill.",
5
5
  "icon": "assets/logo.png",
6
6
  "type": "module",
@@ -31,10 +31,10 @@
31
31
  },
32
32
  "dependencies": {
33
33
  "@resvg/resvg-js": "2.6.2",
34
- "typebox": "1.3.17"
34
+ "typebox": "1.3.17",
35
+ "@sctg/garmin-ts-client": "^0.2.0"
35
36
  },
36
37
  "optionalDependencies": {
37
- "@sctg/garmin-ts-client": "^0.1.0"
38
38
  },
39
39
  "devDependencies": {
40
40
  "@types/node": "^22.20.3",