@trainheroic-unofficial/coach-mcp 1.4.0 → 1.6.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/dist/server.mjs +191 -83
- package/package.json +3 -3
package/dist/server.mjs
CHANGED
|
@@ -163,32 +163,45 @@ const loggedSetSchema = z.object({
|
|
|
163
163
|
param2: z.union([z.number(), z.string()]).optional()
|
|
164
164
|
});
|
|
165
165
|
/**
|
|
166
|
-
*
|
|
167
|
-
*
|
|
168
|
-
*
|
|
166
|
+
* A logged set that can name the prescribed position it fills. `slot` is the 1-based set
|
|
167
|
+
* index in the prescription (10 max) the result should land in; omit it to fill the next
|
|
168
|
+
* sequential position (the first entry is set 1, the second set 2, and so on). Targeting a
|
|
169
|
+
* slot lets a partial log land in the right positions of a multi-set prescription — e.g.
|
|
170
|
+
* three top singles into the 4th/5th/6th positions of an `8,5,3,1,1,1` ramp. Used by the
|
|
171
|
+
* by-set logging write (not the by-exercise session log, where each exercise's sets are
|
|
172
|
+
* always sequential).
|
|
169
173
|
*/
|
|
170
|
-
const
|
|
174
|
+
const loggedSetWithSlotSchema = loggedSetSchema.extend({ slot: z.number().int().min(1).max(10).optional() });
|
|
175
|
+
/**
|
|
176
|
+
* Args for the coach "log for athlete" write — the same shape as logSetArgsSchema plus the
|
|
177
|
+
* roster `athleteId` whose set is being logged on their behalf.
|
|
178
|
+
*/
|
|
179
|
+
const coachLogSetArgsSchema = z.object({
|
|
171
180
|
date: dateString,
|
|
172
181
|
savedWorkoutSetId: idArgSchema,
|
|
173
182
|
results: z.array(z.object({
|
|
174
183
|
savedWorkoutSetExerciseId: idArgSchema,
|
|
175
|
-
sets: z.array(
|
|
184
|
+
sets: z.array(loggedSetWithSlotSchema).min(1)
|
|
176
185
|
})).min(1)
|
|
177
|
-
});
|
|
178
|
-
/**
|
|
179
|
-
* Args for the coach "log for athlete" write — the same shape as logSetArgsSchema plus the
|
|
180
|
-
* roster `athleteId` whose set is being logged on their behalf.
|
|
181
|
-
*/
|
|
182
|
-
const coachLogSetArgsSchema = logSetArgsSchema.extend({ athleteId: idArgSchema });
|
|
186
|
+
}).extend({ athleteId: idArgSchema });
|
|
183
187
|
/**
|
|
184
|
-
* Args for the coach prescription-override write.
|
|
185
|
-
*
|
|
186
|
-
*
|
|
187
|
-
*
|
|
188
|
-
*
|
|
189
|
-
*
|
|
188
|
+
* Args for the coach prescription-override write. Like {@link coachLogSetArgsSchema}
|
|
189
|
+
* (athleteId + date + savedWorkoutSetId + per-exercise `sets`), but the values are prescribed
|
|
190
|
+
* targets (param1 = reps, param2 = weight) written to the athlete's plan without marking the set
|
|
191
|
+
* performed. The write replaces this athlete's whole prescription for the set, so its sets are
|
|
192
|
+
* positional and sequential by definition: it deliberately omits the log path's `slot` field (a
|
|
193
|
+
* sparse, slot-targeted prescription has no meaning here) by building its results off
|
|
194
|
+
* {@link loggedSetSchema} rather than {@link loggedSetWithSlotSchema}.
|
|
190
195
|
*/
|
|
191
|
-
const coachPrescribeSetArgsSchema =
|
|
196
|
+
const coachPrescribeSetArgsSchema = z.object({
|
|
197
|
+
date: dateString,
|
|
198
|
+
savedWorkoutSetId: idArgSchema,
|
|
199
|
+
athleteId: idArgSchema,
|
|
200
|
+
results: z.array(z.object({
|
|
201
|
+
savedWorkoutSetExerciseId: idArgSchema,
|
|
202
|
+
sets: z.array(loggedSetSchema).min(1)
|
|
203
|
+
})).min(1)
|
|
204
|
+
});
|
|
192
205
|
/**
|
|
193
206
|
* Args for the coach per-athlete exercise swap: replace the exercise prescribed in one of a
|
|
194
207
|
* roster athlete's saved-workout slots with a different exercise, the API equivalent of the
|
|
@@ -212,6 +225,10 @@ const coachLogSessionArgsSchema = z.object({
|
|
|
212
225
|
sets: z.array(loggedSetSchema).min(1)
|
|
213
226
|
})).min(1)
|
|
214
227
|
}).extend({ athleteId: idArgSchema });
|
|
228
|
+
z.object({
|
|
229
|
+
programWorkoutId: idArgSchema,
|
|
230
|
+
date: dateString
|
|
231
|
+
});
|
|
215
232
|
//#endregion
|
|
216
233
|
//#region ../dto/src/exercise.ts
|
|
217
234
|
/** Body for creating a custom exercise; extra fields the API accepts are preserved. */
|
|
@@ -776,6 +793,26 @@ function asExerciseList(body) {
|
|
|
776
793
|
function isRecord(x) {
|
|
777
794
|
return typeof x === "object" && x !== null && !Array.isArray(x);
|
|
778
795
|
}
|
|
796
|
+
/** A non-empty string, or null. Narrows a loosely-typed API field to a usable string. */
|
|
797
|
+
function str$1(v) {
|
|
798
|
+
return typeof v === "string" && v !== "" ? v : null;
|
|
799
|
+
}
|
|
800
|
+
/**
|
|
801
|
+
* The display title of a saved-copy exercise row, preferring `exercise_title`, then `title`, then
|
|
802
|
+
* the given fallback. The saved-workout shape carries the title under either key depending on the
|
|
803
|
+
* endpoint, so this is the one place that reconciles them.
|
|
804
|
+
*/
|
|
805
|
+
function exerciseTitle(ex, fallback = "") {
|
|
806
|
+
return typeof ex.exercise_title === "string" && ex.exercise_title || typeof ex.title === "string" && ex.title || fallback;
|
|
807
|
+
}
|
|
808
|
+
/**
|
|
809
|
+
* True when a program-workout range item is a personal (athlete-created) session rather than a
|
|
810
|
+
* coach-scheduled one. The API marks these with `personal_cal === true`; this is the single
|
|
811
|
+
* definition every consumer (presenter, find-or-create, the remove guard) reads through.
|
|
812
|
+
*/
|
|
813
|
+
function isPersonalSession(pw) {
|
|
814
|
+
return isRecord(pw) && pw.personal_cal === true;
|
|
815
|
+
}
|
|
779
816
|
/**
|
|
780
817
|
* Rank candidate rows for a free-text query (FTS5 replacement). Higher is better:
|
|
781
818
|
* exact title, then prefix, then count of matched tokens, with shorter titles and
|
|
@@ -913,7 +950,6 @@ function fetchCoachAthleteWorkouts(client, athleteId, startDate, endDate) {
|
|
|
913
950
|
function fetchCoachAthleteCalendarSummary(client, athleteId, year, month) {
|
|
914
951
|
return getArray(client, `/2.0/coach/athlete/calendar/summary/${athleteId}/${year}/${month}/7`, "coach athlete calendar summary");
|
|
915
952
|
}
|
|
916
|
-
const SLOTS = 10;
|
|
917
953
|
function nonEmpty(value) {
|
|
918
954
|
return value !== void 0 && value !== null && String(value).trim() !== "";
|
|
919
955
|
}
|
|
@@ -924,7 +960,7 @@ function nonEmpty(value) {
|
|
|
924
960
|
*/
|
|
925
961
|
function prescribedSets(ex) {
|
|
926
962
|
const out = [];
|
|
927
|
-
for (let i = 1; i <=
|
|
963
|
+
for (let i = 1; i <= 10; i += 1) {
|
|
928
964
|
const p1 = ex[`param_1_data_${i}`];
|
|
929
965
|
const p2 = ex[`param_2_data_${i}`];
|
|
930
966
|
const has1 = nonEmpty(p1);
|
|
@@ -945,7 +981,7 @@ function prescribedSets(ex) {
|
|
|
945
981
|
*/
|
|
946
982
|
function performedSets(ex) {
|
|
947
983
|
const out = [];
|
|
948
|
-
for (let i = 1; i <=
|
|
984
|
+
for (let i = 1; i <= 10; i += 1) {
|
|
949
985
|
if (coerceInt(ex[`param_${i}_made`]) !== 1) continue;
|
|
950
986
|
const p1 = ex[`param_1_data_${i}`];
|
|
951
987
|
const p2 = ex[`param_2_data_${i}`];
|
|
@@ -979,9 +1015,6 @@ function presentBlock(set, performedById) {
|
|
|
979
1015
|
exercises: exercises.filter(isRecord).map((ex) => presentExercise(ex, performedById))
|
|
980
1016
|
};
|
|
981
1017
|
}
|
|
982
|
-
function str$1(v) {
|
|
983
|
-
return typeof v === "string" && v !== "" ? v : null;
|
|
984
|
-
}
|
|
985
1018
|
/** Every logged set (programmed + athlete-added) in the saved copy, paired with its exercises. */
|
|
986
1019
|
function savedSets(saved) {
|
|
987
1020
|
const out = [];
|
|
@@ -1072,6 +1105,7 @@ function presentAthleteWorkout(raw) {
|
|
|
1072
1105
|
team: str$1(rec.team_title),
|
|
1073
1106
|
instruction: str$1(workout.instruction),
|
|
1074
1107
|
logged: blocks.some((b) => b.exercises.some((e) => e.performed.length > 0)),
|
|
1108
|
+
personal: isPersonalSession(rec),
|
|
1075
1109
|
blocks
|
|
1076
1110
|
};
|
|
1077
1111
|
}
|
|
@@ -1132,7 +1166,7 @@ function presentLogTargets(list) {
|
|
|
1132
1166
|
if (id === null) return null;
|
|
1133
1167
|
return {
|
|
1134
1168
|
savedWorkoutSetExerciseId: id,
|
|
1135
|
-
title:
|
|
1169
|
+
title: exerciseTitle(ex),
|
|
1136
1170
|
units: exerciseUnits(ex.param_1_type, ex.param_2_type),
|
|
1137
1171
|
prescribed: prescribedSets(ex),
|
|
1138
1172
|
performed: performedSets(ex)
|
|
@@ -1201,7 +1235,29 @@ function presentCoachAthleteTraining(raw, athleteId, year, month) {
|
|
|
1201
1235
|
sessions
|
|
1202
1236
|
};
|
|
1203
1237
|
}
|
|
1204
|
-
|
|
1238
|
+
/** Flatten `/v5/exercises/{id}/history` into PRs + a session time-series. */
|
|
1239
|
+
function presentExerciseHistory(detail) {
|
|
1240
|
+
return {
|
|
1241
|
+
liftPRs: (detail.liftPRs ?? []).map((p) => ({
|
|
1242
|
+
description: p.description ?? null,
|
|
1243
|
+
reps: p.reps ?? null,
|
|
1244
|
+
weight: p.weight ?? null,
|
|
1245
|
+
units: p.units ?? null,
|
|
1246
|
+
date: p.dateCompleted ?? null
|
|
1247
|
+
})),
|
|
1248
|
+
sessions: (detail.history ?? []).map((h) => ({
|
|
1249
|
+
date: h.dateCompleted,
|
|
1250
|
+
abr: h.abr ?? null,
|
|
1251
|
+
estimated1RM: h.bestEstimated1RM ?? null,
|
|
1252
|
+
sets: (h.sets ?? []).map((s) => ({
|
|
1253
|
+
setNumber: s.setNumber,
|
|
1254
|
+
value: s.formattedValue ?? null
|
|
1255
|
+
}))
|
|
1256
|
+
}))
|
|
1257
|
+
};
|
|
1258
|
+
}
|
|
1259
|
+
//#endregion
|
|
1260
|
+
//#region ../js/src/athlete-set-write.ts
|
|
1205
1261
|
/**
|
|
1206
1262
|
* Coerce the loosely-typed `results` from a validated log/prescribe args object into the SDK's
|
|
1207
1263
|
* {@link SetResult}[]. The dto schemas validate ids as a number or a numeric string and leave
|
|
@@ -1216,10 +1272,11 @@ function toSetResults(results) {
|
|
|
1216
1272
|
return {
|
|
1217
1273
|
savedWorkoutSetExerciseId: id,
|
|
1218
1274
|
sets: r.sets.map((s) => {
|
|
1219
|
-
const
|
|
1220
|
-
if (s.param1 !== void 0)
|
|
1221
|
-
if (s.param2 !== void 0)
|
|
1222
|
-
|
|
1275
|
+
const set = {};
|
|
1276
|
+
if (s.param1 !== void 0) set.param1 = s.param1;
|
|
1277
|
+
if (s.param2 !== void 0) set.param2 = s.param2;
|
|
1278
|
+
if (s.slot !== void 0) set.slot = s.slot;
|
|
1279
|
+
return set;
|
|
1223
1280
|
})
|
|
1224
1281
|
};
|
|
1225
1282
|
});
|
|
@@ -1231,36 +1288,96 @@ function toSetResults(results) {
|
|
|
1231
1288
|
*
|
|
1232
1289
|
* `mode` selects which write this is — the same endpoint serves both:
|
|
1233
1290
|
* - `"log"`: the values ARE a performed result, so `param_N_made` is 1 where the slot has data
|
|
1234
|
-
* and the exercise `completed` flag is 1 when any set has data.
|
|
1291
|
+
* and the exercise `completed` flag is 1 when any set has logged data.
|
|
1235
1292
|
* - `"prescribe"`: the values are prescribed targets, written with every `param_N_made` and
|
|
1236
1293
|
* `completed` left at 0 so the set is not marked done. This matches what the app sends when a
|
|
1237
1294
|
* coach edits an athlete's prescribed reps/weight.
|
|
1238
1295
|
*
|
|
1296
|
+
* Each set fills a 1-based slot: its explicit `slot`, or its sequential position in `results`
|
|
1297
|
+
* when `slot` is omitted. A `log` carrying the live exercise record in `existing` keeps the slots
|
|
1298
|
+
* it does not write that were ALREADY performed (`param_N_made === 1`), so logging a second part of
|
|
1299
|
+
* a set does not wipe the earlier-logged sets. A slot holding only un-logged prescription pre-fill
|
|
1300
|
+
* (`param_N_made === 0`) is left blank rather than carried over: marking the set completed makes
|
|
1301
|
+
* the server flag every data-bearing slot performed, so preserving that pre-fill would fabricate
|
|
1302
|
+
* sets the athlete never did. The prescription is unaffected (it lives in the separate `workout`
|
|
1303
|
+
* copy, not this saved copy). A `prescribe` ignores `existing` and replaces the whole prescription.
|
|
1304
|
+
*
|
|
1239
1305
|
* Only `savedWorkoutSetExerciseId`, `savedWorkoutSetId`, and `workoutSetExerciseId` are
|
|
1240
|
-
* required from the live exercise record; everything else is derived from `results
|
|
1306
|
+
* required from the live exercise record; everything else is derived from `results` and the
|
|
1307
|
+
* preserved slots of `existing`.
|
|
1241
1308
|
*
|
|
1242
1309
|
* Exported for unit testing — callers should use `logAthleteSet` / `prescribeForAthlete` instead.
|
|
1243
1310
|
*/
|
|
1244
|
-
function buildExerciseSetPayload(savedWorkoutSetExerciseId, savedWorkoutSetId, workoutSetExerciseId, results, mode) {
|
|
1245
|
-
if (results.length >
|
|
1311
|
+
function buildExerciseSetPayload(savedWorkoutSetExerciseId, savedWorkoutSetId, workoutSetExerciseId, results, mode, existing) {
|
|
1312
|
+
if (results.length > 10) throw new Error(`At most 10 sets are supported per exercise; got ${results.length}.`);
|
|
1313
|
+
const bySlot = /* @__PURE__ */ new Map();
|
|
1314
|
+
results.forEach((set, i) => {
|
|
1315
|
+
const slot = set.slot ?? i + 1;
|
|
1316
|
+
if (slot < 1 || slot > 10) throw new Error(`Set slot ${slot} is out of range; slots are 1–10.`);
|
|
1317
|
+
if (bySlot.has(slot)) throw new Error(`Two sets target slot ${slot}; each slot can be written once.`);
|
|
1318
|
+
bySlot.set(slot, set);
|
|
1319
|
+
});
|
|
1246
1320
|
const performed = mode === "log";
|
|
1247
|
-
const
|
|
1321
|
+
const carryOver = performed && existing !== void 0;
|
|
1248
1322
|
const body = {
|
|
1249
1323
|
id: savedWorkoutSetExerciseId,
|
|
1250
1324
|
saved_workout_set_id: savedWorkoutSetId,
|
|
1251
|
-
workout_set_exercise_id: workoutSetExerciseId
|
|
1252
|
-
completed: performed && hasData ? 1 : 0
|
|
1325
|
+
workout_set_exercise_id: workoutSetExerciseId
|
|
1253
1326
|
};
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
const
|
|
1257
|
-
|
|
1258
|
-
|
|
1327
|
+
let anyMade = false;
|
|
1328
|
+
for (let i = 1; i <= 10; i += 1) {
|
|
1329
|
+
const target = bySlot.get(i);
|
|
1330
|
+
let p1;
|
|
1331
|
+
let p2;
|
|
1332
|
+
let made;
|
|
1333
|
+
if (target) {
|
|
1334
|
+
p1 = target.param1 !== void 0 ? String(target.param1) : "";
|
|
1335
|
+
p2 = target.param2 !== void 0 ? String(target.param2) : "";
|
|
1336
|
+
made = performed && (p1 !== "" || p2 !== "") ? 1 : 0;
|
|
1337
|
+
} else if (carryOver && coerceInt(existing?.[`param_${i}_made`]) === 1) {
|
|
1338
|
+
p1 = existingSlotData(existing, `param_1_data_${i}`);
|
|
1339
|
+
p2 = existingSlotData(existing, `param_2_data_${i}`);
|
|
1340
|
+
made = 1;
|
|
1341
|
+
} else {
|
|
1342
|
+
p1 = "";
|
|
1343
|
+
p2 = "";
|
|
1344
|
+
made = 0;
|
|
1345
|
+
}
|
|
1346
|
+
if (made === 1) anyMade = true;
|
|
1347
|
+
body[`param_${i}_made`] = made;
|
|
1259
1348
|
body[`param_1_data_${i}`] = p1;
|
|
1260
1349
|
body[`param_2_data_${i}`] = p2;
|
|
1261
1350
|
}
|
|
1351
|
+
body.completed = performed && anyMade ? 1 : 0;
|
|
1262
1352
|
return body;
|
|
1263
1353
|
}
|
|
1354
|
+
/** Read a saved-copy slot value (`param_1_data_N` / `param_2_data_N`) as the string the body uses. */
|
|
1355
|
+
function existingSlotData(existing, key) {
|
|
1356
|
+
const v = existing?.[key];
|
|
1357
|
+
return v === void 0 || v === null ? "" : String(v);
|
|
1358
|
+
}
|
|
1359
|
+
/** True when a saved-copy exercise already carries a performed slot (any `param_N_made` === 1). */
|
|
1360
|
+
function exerciseHasLoggedData(ex) {
|
|
1361
|
+
for (let i = 1; i <= 10; i += 1) if (coerceInt(ex[`param_${i}_made`]) === 1) return true;
|
|
1362
|
+
return false;
|
|
1363
|
+
}
|
|
1364
|
+
/** True when a result carries at least one non-empty param value (so it produces a performed slot). */
|
|
1365
|
+
function resultHasData(result) {
|
|
1366
|
+
return result.sets.some((s) => s.param1 !== void 0 && String(s.param1) !== "" || s.param2 !== void 0 && String(s.param2) !== "");
|
|
1367
|
+
}
|
|
1368
|
+
/**
|
|
1369
|
+
* Whether every exercise in a saved workout set now has logged data — either written with data in
|
|
1370
|
+
* this call (`loggedIds`) or already carrying a performed slot. Gates the set-completion PUT: a
|
|
1371
|
+
* superset/circuit stays open until the last exercise is logged, so completing it on a partial log
|
|
1372
|
+
* does not flip its still-empty siblings to "done". An exercise written with only empty values does
|
|
1373
|
+
* not count (it would not be marked performed), so an all-empty log never completes the set.
|
|
1374
|
+
*/
|
|
1375
|
+
function isSetFullyLogged(exercises, loggedIds) {
|
|
1376
|
+
return exercises.every((ex) => {
|
|
1377
|
+
const id = coerceInt(ex.id);
|
|
1378
|
+
return id !== null && loggedIds.has(id) || exerciseHasLoggedData(ex);
|
|
1379
|
+
});
|
|
1380
|
+
}
|
|
1264
1381
|
/**
|
|
1265
1382
|
* Locate the target saved workout set across all program workouts on the given day.
|
|
1266
1383
|
* Returns the `savedWorkoutId`, the matching set's `workoutSetExercises` array so callers
|
|
@@ -1291,8 +1408,7 @@ function findSavedWorkoutSet(workouts, savedWorkoutSetId) {
|
|
|
1291
1408
|
if (setId !== null) {
|
|
1292
1409
|
const exLabels = exercises.map((ex) => {
|
|
1293
1410
|
const exId = coerceInt(ex.id);
|
|
1294
|
-
|
|
1295
|
-
return exId === null ? null : `${exId} (${title})`;
|
|
1411
|
+
return exId === null ? null : `${exId} (${exerciseTitle(ex, "exercise")})`;
|
|
1296
1412
|
}).filter((x) => x !== null);
|
|
1297
1413
|
available.push(`set ${setId} → exercise ids: ${exLabels.join(", ") || "none"}`);
|
|
1298
1414
|
}
|
|
@@ -1359,7 +1475,8 @@ async function logAthleteSet(client, args) {
|
|
|
1359
1475
|
const r = await writeSetResults(client, { role: "athlete" }, await fetchAthleteWorkouts(client, args.date, args.date), args.savedWorkoutSetId, args.results, "log");
|
|
1360
1476
|
return {
|
|
1361
1477
|
savedWorkoutSetId: r.savedWorkoutSetId,
|
|
1362
|
-
exercisesLogged: r.exercisesWritten
|
|
1478
|
+
exercisesLogged: r.exercisesWritten,
|
|
1479
|
+
setCompleted: r.setCompleted
|
|
1363
1480
|
};
|
|
1364
1481
|
}
|
|
1365
1482
|
/**
|
|
@@ -1380,7 +1497,8 @@ async function logForAthlete(client, args) {
|
|
|
1380
1497
|
}, workouts, args.savedWorkoutSetId, args.results, "log");
|
|
1381
1498
|
return {
|
|
1382
1499
|
savedWorkoutSetId: r.savedWorkoutSetId,
|
|
1383
|
-
exercisesLogged: r.exercisesWritten
|
|
1500
|
+
exercisesLogged: r.exercisesWritten,
|
|
1501
|
+
setCompleted: r.setCompleted
|
|
1384
1502
|
};
|
|
1385
1503
|
}
|
|
1386
1504
|
/**
|
|
@@ -1467,15 +1585,14 @@ async function writeSetResults(client, target, workouts, savedWorkoutSetId, resu
|
|
|
1467
1585
|
if (!ex) {
|
|
1468
1586
|
const valid = exercises.map((e) => {
|
|
1469
1587
|
const id = coerceInt(e.id);
|
|
1470
|
-
|
|
1471
|
-
return id === null ? null : `${id} (${title})`;
|
|
1588
|
+
return id === null ? null : `${id} (${exerciseTitle(e, "exercise")})`;
|
|
1472
1589
|
}).filter((x) => x !== null);
|
|
1473
1590
|
throw new Error(`savedWorkoutSetExerciseId ${result.savedWorkoutSetExerciseId} not found in saved workout set ${savedWorkoutSetId}. Exercises in this set: ${valid.join(", ") || "none"}.`);
|
|
1474
1591
|
}
|
|
1475
1592
|
const workoutSetExerciseId = coerceInt(ex.workout_set_exercise_id);
|
|
1476
1593
|
if (!workoutSetExerciseId) throw new Error(`savedWorkoutSetExercise ${result.savedWorkoutSetExerciseId} is missing its workout_set_exercise_id (the prescription-template pointer the write needs). This is the savedWorkoutSetExerciseId, not an exercise_id — re-read the ids from athlete_saved_workouts.`);
|
|
1477
1594
|
const body = {
|
|
1478
|
-
...buildExerciseSetPayload(result.savedWorkoutSetExerciseId, savedWorkoutSetId, workoutSetExerciseId, result.sets, mode),
|
|
1595
|
+
...buildExerciseSetPayload(result.savedWorkoutSetExerciseId, savedWorkoutSetId, workoutSetExerciseId, result.sets, mode, ex),
|
|
1479
1596
|
...extra
|
|
1480
1597
|
};
|
|
1481
1598
|
const res = await client.request("PUT", `/1.0/${target.role}/savedworkoutsetexercise/${result.savedWorkoutSetExerciseId}${suffix}`, { body });
|
|
@@ -1485,20 +1602,29 @@ async function writeSetResults(client, target, workouts, savedWorkoutSetId, resu
|
|
|
1485
1602
|
}
|
|
1486
1603
|
exercisesWritten += 1;
|
|
1487
1604
|
}
|
|
1605
|
+
let setCompleted = false;
|
|
1488
1606
|
if (mode === "log") {
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1607
|
+
if (isSetFullyLogged(exercises, new Set(results.filter(resultHasData).map((r) => r.savedWorkoutSetExerciseId)))) {
|
|
1608
|
+
const setBody = {
|
|
1609
|
+
...buildSetCompletePayload(rawSet, exercises.map((e) => coerceInt(e.id)).filter((n) => n !== null), true),
|
|
1610
|
+
...extra
|
|
1611
|
+
};
|
|
1612
|
+
const setRes = await client.request("PUT", `/1.0/${target.role}/savedworkoutset/${savedWorkoutSetId}${suffix}`, { body: setBody });
|
|
1613
|
+
if (!setRes.ok) throw new Error(`Failed to mark workout set ${savedWorkoutSetId} completed (HTTP ${setRes.status}).`);
|
|
1614
|
+
setCompleted = true;
|
|
1615
|
+
}
|
|
1495
1616
|
}
|
|
1496
1617
|
return {
|
|
1497
1618
|
savedWorkoutSetId,
|
|
1498
|
-
exercisesWritten
|
|
1619
|
+
exercisesWritten,
|
|
1620
|
+
setCompleted
|
|
1499
1621
|
};
|
|
1500
1622
|
}
|
|
1501
|
-
/**
|
|
1623
|
+
/**
|
|
1624
|
+
* Flatten a day's saved sets into `{ pw, savedWorkoutSetId, ex }` rows (both saved-set keys),
|
|
1625
|
+
* carrying the parent program-workout so a caller can read its identity (`personal_cal`, program
|
|
1626
|
+
* title) without re-walking. The one saved-copy traversal the by-exercise paths share.
|
|
1627
|
+
*/
|
|
1502
1628
|
function eachPrescribedExercise(workouts) {
|
|
1503
1629
|
const rows = [];
|
|
1504
1630
|
for (const pw of workouts) {
|
|
@@ -1513,6 +1639,7 @@ function eachPrescribedExercise(workouts) {
|
|
|
1513
1639
|
if (savedWorkoutSetId === null) continue;
|
|
1514
1640
|
const exercises = Array.isArray(s.workoutSetExercises) ? s.workoutSetExercises : [];
|
|
1515
1641
|
for (const ex of exercises) if (isRecord(ex)) rows.push({
|
|
1642
|
+
pw: rec,
|
|
1516
1643
|
savedWorkoutSetId,
|
|
1517
1644
|
ex
|
|
1518
1645
|
});
|
|
@@ -1543,8 +1670,7 @@ function prescribedExerciseLabels(workouts) {
|
|
|
1543
1670
|
for (const { ex } of eachPrescribedExercise(workouts)) {
|
|
1544
1671
|
const id = coerceInt(ex.exercise_id);
|
|
1545
1672
|
if (id === null) continue;
|
|
1546
|
-
|
|
1547
|
-
labels.push(`${id} (${title})`);
|
|
1673
|
+
labels.push(`${id} (${exerciseTitle(ex, "exercise")})`);
|
|
1548
1674
|
}
|
|
1549
1675
|
return labels;
|
|
1550
1676
|
}
|
|
@@ -1571,7 +1697,10 @@ async function logResolvedExercises(client, target, date, resolved) {
|
|
|
1571
1697
|
savedWorkoutSetId,
|
|
1572
1698
|
results
|
|
1573
1699
|
});
|
|
1574
|
-
out.push(
|
|
1700
|
+
out.push({
|
|
1701
|
+
savedWorkoutSetId: written.savedWorkoutSetId,
|
|
1702
|
+
exercisesLogged: written.exercisesLogged
|
|
1703
|
+
});
|
|
1575
1704
|
}
|
|
1576
1705
|
return out;
|
|
1577
1706
|
}
|
|
@@ -1610,27 +1739,6 @@ async function logSessionForAthlete(client, args) {
|
|
|
1610
1739
|
sets
|
|
1611
1740
|
};
|
|
1612
1741
|
}
|
|
1613
|
-
/** Flatten `/v5/exercises/{id}/history` into PRs + a session time-series. */
|
|
1614
|
-
function presentExerciseHistory(detail) {
|
|
1615
|
-
return {
|
|
1616
|
-
liftPRs: (detail.liftPRs ?? []).map((p) => ({
|
|
1617
|
-
description: p.description ?? null,
|
|
1618
|
-
reps: p.reps ?? null,
|
|
1619
|
-
weight: p.weight ?? null,
|
|
1620
|
-
units: p.units ?? null,
|
|
1621
|
-
date: p.dateCompleted ?? null
|
|
1622
|
-
})),
|
|
1623
|
-
sessions: (detail.history ?? []).map((h) => ({
|
|
1624
|
-
date: h.dateCompleted,
|
|
1625
|
-
abr: h.abr ?? null,
|
|
1626
|
-
estimated1RM: h.bestEstimated1RM ?? null,
|
|
1627
|
-
sets: (h.sets ?? []).map((s) => ({
|
|
1628
|
-
setNumber: s.setNumber,
|
|
1629
|
-
value: s.formattedValue ?? null
|
|
1630
|
-
}))
|
|
1631
|
-
}))
|
|
1632
|
-
};
|
|
1633
|
-
}
|
|
1634
1742
|
/** Normalize one-or-many emails into a deduped, trimmed list. */
|
|
1635
1743
|
function emailList(emails) {
|
|
1636
1744
|
return [...new Set(emails.map((e) => e.trim()).filter((e) => e.length > 0))];
|
|
@@ -3071,7 +3179,7 @@ function registerAthleteLogTools(server, ctx) {
|
|
|
3071
3179
|
registerAthleteSavedWorkouts(server, ctx);
|
|
3072
3180
|
server.registerTool("log_athlete_set", {
|
|
3073
3181
|
title: "Log set results for a roster athlete",
|
|
3074
|
-
description: "Coach-facing write: record entered results (reps/weight per set) for one of a roster athlete's saved workout sets on a given day
|
|
3182
|
+
description: "Coach-facing write: record entered results (reps/weight per set) for one of a roster athlete's saved workout sets on a given day — the API equivalent of the app's \"Log for Athlete\". Writes to that athlete's training log and shows in their history. Each set fills the next position in order; give a set a 1-based `slot` to place it at a specific position. A partial log records only the positions you send (plus any logged earlier) and leaves the rest unlogged. In a superset/circuit the block is marked done only once every exercise in it has logged results (the response's `setCompleted` reports whether it was). Get athleteId from list_athletes; get savedWorkoutSetId + savedWorkoutSetExerciseId from athlete_saved_workouts for that athlete/day (its default view carries both — pass programId there if the athlete is on several programs). Seeded demo athletes are read-only and will fail; use a real (invited) athlete. Requires confirmation (elicitation or confirm:true).",
|
|
3075
3183
|
inputSchema: {
|
|
3076
3184
|
...coachLogSetArgsSchema.shape,
|
|
3077
3185
|
confirm: z.boolean().optional()
|
|
@@ -3572,7 +3680,7 @@ var JsonFileLibraryCache = class {
|
|
|
3572
3680
|
};
|
|
3573
3681
|
//#endregion
|
|
3574
3682
|
//#region package.json
|
|
3575
|
-
var version = "1.
|
|
3683
|
+
var version = "1.6.0";
|
|
3576
3684
|
//#endregion
|
|
3577
3685
|
//#region src/server.ts
|
|
3578
3686
|
async function main() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trainheroic-unofficial/coach-mcp",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -21,8 +21,8 @@
|
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
23
23
|
"zod": "^4.4.3",
|
|
24
|
-
"@trainheroic-unofficial/core": "1.
|
|
25
|
-
"@trainheroic-unofficial/js": "1.
|
|
24
|
+
"@trainheroic-unofficial/core": "1.6.0",
|
|
25
|
+
"@trainheroic-unofficial/js": "1.6.0"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@types/node": "^26.0.0",
|