@trainheroic-unofficial/coach-mcp 1.6.0 → 1.7.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 +132 -83
- package/package.json +4 -4
package/dist/server.mjs
CHANGED
|
@@ -742,7 +742,7 @@ function withUnits(row) {
|
|
|
742
742
|
* Present a full raw exercise object for display: drop the raw param-type codes and add the
|
|
743
743
|
* positional `units` array. Keeps every other field of the raw object intact.
|
|
744
744
|
*/
|
|
745
|
-
function presentExercise
|
|
745
|
+
function presentExercise(raw) {
|
|
746
746
|
const { param_1_type, param_2_type, ...rest } = raw;
|
|
747
747
|
return {
|
|
748
748
|
...rest,
|
|
@@ -954,66 +954,40 @@ function nonEmpty(value) {
|
|
|
954
954
|
return value !== void 0 && value !== null && String(value).trim() !== "";
|
|
955
955
|
}
|
|
956
956
|
/**
|
|
957
|
-
*
|
|
958
|
-
*
|
|
959
|
-
*
|
|
957
|
+
* Slot-indexed values for one exercise. With `requireMade`, only slots the athlete logged
|
|
958
|
+
* (`param_i_made === 1`) — the performed reader; otherwise every slot carrying data — the
|
|
959
|
+
* prescription reader. Values stay raw; the projectors format or parse them.
|
|
960
960
|
*/
|
|
961
|
-
function
|
|
962
|
-
const
|
|
961
|
+
function slotValues(ex, requireMade) {
|
|
962
|
+
const map = /* @__PURE__ */ new Map();
|
|
963
963
|
for (let i = 1; i <= 10; i += 1) {
|
|
964
|
+
if (requireMade && coerceInt(ex[`param_${i}_made`]) !== 1) continue;
|
|
964
965
|
const p1 = ex[`param_1_data_${i}`];
|
|
965
966
|
const p2 = ex[`param_2_data_${i}`];
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
else out.push(`@ ${p2}`);
|
|
967
|
+
if (!nonEmpty(p1) && !nonEmpty(p2)) continue;
|
|
968
|
+
map.set(i, {
|
|
969
|
+
p1: nonEmpty(p1) ? p1 : null,
|
|
970
|
+
p2: nonEmpty(p2) ? p2 : null
|
|
971
|
+
});
|
|
972
972
|
}
|
|
973
|
-
return
|
|
973
|
+
return map;
|
|
974
974
|
}
|
|
975
|
-
/**
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
const out = [];
|
|
984
|
-
for (let i = 1; i <= 10; i += 1) {
|
|
985
|
-
if (coerceInt(ex[`param_${i}_made`]) !== 1) continue;
|
|
986
|
-
const p1 = ex[`param_1_data_${i}`];
|
|
987
|
-
const p2 = ex[`param_2_data_${i}`];
|
|
988
|
-
const has1 = nonEmpty(p1);
|
|
989
|
-
const has2 = nonEmpty(p2);
|
|
990
|
-
if (has1 && has2) out.push(`${p1} @ ${p2}`);
|
|
991
|
-
else if (has1) out.push(String(p1));
|
|
992
|
-
else if (has2) out.push(`@ ${p2}`);
|
|
993
|
-
}
|
|
994
|
-
return out;
|
|
975
|
+
/** The joined display for a slot, kept verbatim (`"5 @ 225"`, `"AMRAP"`, `"@ 225"`). */
|
|
976
|
+
function fmtSlot(slot) {
|
|
977
|
+
const has1 = slot.p1 !== null;
|
|
978
|
+
const has2 = slot.p2 !== null;
|
|
979
|
+
if (has1 && has2) return `${slot.p1} @ ${slot.p2}`;
|
|
980
|
+
if (has1) return String(slot.p1);
|
|
981
|
+
if (has2) return `@ ${slot.p2}`;
|
|
982
|
+
return "";
|
|
995
983
|
}
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
return {
|
|
1000
|
-
exerciseId: coerceInt(ex.exercise_id),
|
|
1001
|
-
title: typeof ex.title === "string" ? ex.title : "",
|
|
1002
|
-
instruction,
|
|
1003
|
-
units: exerciseUnits(ex.param_1_type, ex.param_2_type),
|
|
1004
|
-
prescribed: prescribedSets(ex),
|
|
1005
|
-
performed: (id !== null ? performedById.get(id) : void 0) ?? []
|
|
1006
|
-
};
|
|
984
|
+
/** Every slot carrying data, joined for display (the prescription reader): `["5 @ 225", "AMRAP"]`. */
|
|
985
|
+
function prescribedStrings(ex) {
|
|
986
|
+
return [...slotValues(ex, false).values()].map(fmtSlot);
|
|
1007
987
|
}
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
return
|
|
1011
|
-
order: coerceInt(set.order) ?? 0,
|
|
1012
|
-
title: typeof set.title === "string" && set.title !== "" ? set.title : null,
|
|
1013
|
-
instruction: typeof set.instruction === "string" && set.instruction !== "" ? set.instruction : null,
|
|
1014
|
-
isTest: coerceInt(set.is_test) === 1,
|
|
1015
|
-
exercises: exercises.filter(isRecord).map((ex) => presentExercise(ex, performedById))
|
|
1016
|
-
};
|
|
988
|
+
/** The slots the athlete logged (`param_i_made === 1`), joined for display (the performed reader). */
|
|
989
|
+
function performedStrings(ex) {
|
|
990
|
+
return [...slotValues(ex, true).values()].map(fmtSlot);
|
|
1017
991
|
}
|
|
1018
992
|
/** Every logged set (programmed + athlete-added) in the saved copy, paired with its exercises. */
|
|
1019
993
|
function savedSets(saved) {
|
|
@@ -1032,54 +1006,82 @@ function savedSets(saved) {
|
|
|
1032
1006
|
return out;
|
|
1033
1007
|
}
|
|
1034
1008
|
/**
|
|
1035
|
-
* Map each prescription exercise id to the
|
|
1036
|
-
* copy
|
|
1037
|
-
* entered values live in the same `param_N_data` slots as a prescription
|
|
1038
|
-
* prescription reader works on them unchanged.
|
|
1009
|
+
* Map each prescription exercise id to the slot-indexed values the athlete logged against it. In
|
|
1010
|
+
* the saved copy `workout_set_exercise_id` points back at the prescription exercise's `id`, and the
|
|
1011
|
+
* entered values live in the same `param_N_data` slots as a prescription.
|
|
1039
1012
|
*/
|
|
1040
|
-
function
|
|
1013
|
+
function performedSlotsByExerciseId(sets) {
|
|
1041
1014
|
const map = /* @__PURE__ */ new Map();
|
|
1042
1015
|
for (const { exercises } of sets) for (const ex of exercises) {
|
|
1043
1016
|
const id = coerceInt(ex.workout_set_exercise_id);
|
|
1044
1017
|
if (id === null) continue;
|
|
1045
|
-
const
|
|
1046
|
-
if (
|
|
1018
|
+
const slots = slotValues(ex, true);
|
|
1019
|
+
if (slots.size > 0) map.set(id, slots);
|
|
1047
1020
|
}
|
|
1048
1021
|
return map;
|
|
1049
1022
|
}
|
|
1050
|
-
/**
|
|
1051
|
-
function
|
|
1023
|
+
/** Align an exercise's prescribed slots with the slots the athlete logged, per set index. */
|
|
1024
|
+
function mergeExercise(prescribed, performed, meta) {
|
|
1025
|
+
const indices = [.../* @__PURE__ */ new Set([...prescribed.keys(), ...performed.keys()])].sort((a, b) => a - b);
|
|
1026
|
+
return {
|
|
1027
|
+
...meta,
|
|
1028
|
+
sets: indices.map((i) => ({
|
|
1029
|
+
set: i,
|
|
1030
|
+
prescribed: prescribed.get(i) ?? null,
|
|
1031
|
+
performed: performed.get(i) ?? null
|
|
1032
|
+
}))
|
|
1033
|
+
};
|
|
1034
|
+
}
|
|
1035
|
+
/** A prescription block, each exercise aligned with the slots the athlete logged against it. */
|
|
1036
|
+
function mergePrescriptionBlock(set, performedById) {
|
|
1037
|
+
const exercises = Array.isArray(set.workoutSetExercises) ? set.workoutSetExercises : [];
|
|
1052
1038
|
return {
|
|
1053
1039
|
order: coerceInt(set.order) ?? 0,
|
|
1054
|
-
title:
|
|
1055
|
-
instruction:
|
|
1040
|
+
title: str$1(set.title),
|
|
1041
|
+
instruction: str$1(set.instruction),
|
|
1056
1042
|
isTest: coerceInt(set.is_test) === 1,
|
|
1057
|
-
exercises: exercises.map((ex) =>
|
|
1043
|
+
exercises: exercises.filter(isRecord).map((ex) => {
|
|
1044
|
+
const id = coerceInt(ex.id);
|
|
1045
|
+
const performed = (id !== null ? performedById.get(id) : void 0) ?? /* @__PURE__ */ new Map();
|
|
1046
|
+
return mergeExercise(slotValues(ex, false), performed, {
|
|
1047
|
+
exerciseId: coerceInt(ex.exercise_id),
|
|
1048
|
+
title: typeof ex.title === "string" ? ex.title : "",
|
|
1049
|
+
instruction: str$1(ex.instruction),
|
|
1050
|
+
units: exerciseUnits(ex.param_1_type, ex.param_2_type)
|
|
1051
|
+
});
|
|
1052
|
+
})
|
|
1053
|
+
};
|
|
1054
|
+
}
|
|
1055
|
+
/** A logged block straight from the saved copy (athlete-added or personal work; no prescription). */
|
|
1056
|
+
function mergeSavedBlock(set, exercises) {
|
|
1057
|
+
return {
|
|
1058
|
+
order: coerceInt(set.order) ?? 0,
|
|
1059
|
+
title: str$1(set.title),
|
|
1060
|
+
instruction: str$1(set.instruction),
|
|
1061
|
+
isTest: coerceInt(set.is_test) === 1,
|
|
1062
|
+
exercises: exercises.map((ex) => mergeExercise(/* @__PURE__ */ new Map(), slotValues(ex, true), {
|
|
1058
1063
|
exerciseId: coerceInt(ex.exercise_id),
|
|
1059
1064
|
title: typeof ex.exercise_title === "string" ? ex.exercise_title : "",
|
|
1060
|
-
instruction:
|
|
1061
|
-
units: exerciseUnits(ex.param_1_type, ex.param_2_type)
|
|
1062
|
-
prescribed: [],
|
|
1063
|
-
performed: performedSets(ex)
|
|
1065
|
+
instruction: str$1(ex.instruction),
|
|
1066
|
+
units: exerciseUnits(ex.param_1_type, ex.param_2_type)
|
|
1064
1067
|
}))
|
|
1065
1068
|
};
|
|
1066
1069
|
}
|
|
1067
1070
|
/**
|
|
1068
|
-
* Flatten one `/3.0/athlete/programworkout/range` item into
|
|
1071
|
+
* Flatten one `/3.0/athlete/programworkout/range` item into the canonical merged form, joining the
|
|
1069
1072
|
* prescription (`summarizedSavedWorkout.workout`) with what the athlete logged
|
|
1070
|
-
* (`summarizedSavedWorkout.saved_workout`).
|
|
1071
|
-
*
|
|
1072
|
-
* own blocks. No `raw` is needed to see logged results.
|
|
1073
|
+
* (`summarizedSavedWorkout.saved_workout`). Prescription blocks are enriched with logged slots;
|
|
1074
|
+
* athlete-added / personal work with no prescription is appended as its own block.
|
|
1073
1075
|
*/
|
|
1074
|
-
function
|
|
1076
|
+
function mergeAthleteWorkout(raw) {
|
|
1075
1077
|
const rec = raw;
|
|
1076
1078
|
const ssw = isRecord(rec.summarizedSavedWorkout) ? rec.summarizedSavedWorkout : {};
|
|
1077
1079
|
const workout = isRecord(ssw.workout) ? ssw.workout : {};
|
|
1078
1080
|
const saved = isRecord(ssw.saved_workout) ? ssw.saved_workout : {};
|
|
1079
1081
|
const prescriptionSets = (Array.isArray(workout.workoutSets) ? workout.workoutSets : []).filter(isRecord);
|
|
1080
1082
|
const logged = savedSets(saved);
|
|
1081
|
-
const performedById =
|
|
1082
|
-
const blocks = prescriptionSets.map((s) =>
|
|
1083
|
+
const performedById = performedSlotsByExerciseId(logged);
|
|
1084
|
+
const blocks = prescriptionSets.map((s) => mergePrescriptionBlock(s, performedById)).sort((a, b) => a.order - b.order);
|
|
1083
1085
|
const prescribedIds = /* @__PURE__ */ new Set();
|
|
1084
1086
|
for (const s of prescriptionSets) {
|
|
1085
1087
|
const exs = Array.isArray(s.workoutSetExercises) ? s.workoutSetExercises : [];
|
|
@@ -1091,11 +1093,11 @@ function presentAthleteWorkout(raw) {
|
|
|
1091
1093
|
}
|
|
1092
1094
|
for (const { set, exercises } of logged) {
|
|
1093
1095
|
const extra = exercises.filter((ex) => {
|
|
1094
|
-
if (
|
|
1096
|
+
if (slotValues(ex, true).size === 0) return false;
|
|
1095
1097
|
const id = coerceInt(ex.workout_set_exercise_id);
|
|
1096
1098
|
return id === null || !prescribedIds.has(id);
|
|
1097
1099
|
});
|
|
1098
|
-
if (extra.length > 0) blocks.push(
|
|
1100
|
+
if (extra.length > 0) blocks.push(mergeSavedBlock(set, extra));
|
|
1099
1101
|
}
|
|
1100
1102
|
return {
|
|
1101
1103
|
id: coerceInt(rec.id),
|
|
@@ -1104,11 +1106,58 @@ function presentAthleteWorkout(raw) {
|
|
|
1104
1106
|
program: str$1(rec.program_title),
|
|
1105
1107
|
team: str$1(rec.team_title),
|
|
1106
1108
|
instruction: str$1(workout.instruction),
|
|
1107
|
-
logged: blocks.some((b) => b.exercises.some((e) => e.
|
|
1109
|
+
logged: blocks.some((b) => b.exercises.some((e) => e.sets.some((s) => s.performed !== null))),
|
|
1108
1110
|
personal: isPersonalSession(rec),
|
|
1109
1111
|
blocks
|
|
1110
1112
|
};
|
|
1111
1113
|
}
|
|
1114
|
+
/** The per-set displays for one side (prescribed or performed), in slot order. */
|
|
1115
|
+
function sideStrings(sets, pick) {
|
|
1116
|
+
const out = [];
|
|
1117
|
+
for (const s of sets) {
|
|
1118
|
+
const slot = pick(s);
|
|
1119
|
+
if (slot) out.push(fmtSlot(slot));
|
|
1120
|
+
}
|
|
1121
|
+
return out;
|
|
1122
|
+
}
|
|
1123
|
+
function toStringExercise(ex) {
|
|
1124
|
+
return {
|
|
1125
|
+
exerciseId: ex.exerciseId,
|
|
1126
|
+
title: ex.title,
|
|
1127
|
+
instruction: ex.instruction,
|
|
1128
|
+
units: ex.units,
|
|
1129
|
+
prescribed: sideStrings(ex.sets, (s) => s.prescribed),
|
|
1130
|
+
performed: sideStrings(ex.sets, (s) => s.performed)
|
|
1131
|
+
};
|
|
1132
|
+
}
|
|
1133
|
+
function toStringBlock(b) {
|
|
1134
|
+
return {
|
|
1135
|
+
order: b.order,
|
|
1136
|
+
title: b.title,
|
|
1137
|
+
instruction: b.instruction,
|
|
1138
|
+
isTest: b.isTest,
|
|
1139
|
+
exercises: b.exercises.map(toStringExercise)
|
|
1140
|
+
};
|
|
1141
|
+
}
|
|
1142
|
+
/**
|
|
1143
|
+
* Flatten one range item into a readable workout: each exercise carries its `prescribed` and
|
|
1144
|
+
* `performed` sets as joined `"5 @ 225"` strings; athlete-added/personal work that has no
|
|
1145
|
+
* prescription is appended as its own blocks. No `raw` is needed to see logged results.
|
|
1146
|
+
*/
|
|
1147
|
+
function presentAthleteWorkout(raw) {
|
|
1148
|
+
const w = mergeAthleteWorkout(raw);
|
|
1149
|
+
return {
|
|
1150
|
+
id: w.id,
|
|
1151
|
+
date: w.date,
|
|
1152
|
+
title: w.title,
|
|
1153
|
+
program: w.program,
|
|
1154
|
+
team: w.team,
|
|
1155
|
+
instruction: w.instruction,
|
|
1156
|
+
logged: w.logged,
|
|
1157
|
+
personal: w.personal,
|
|
1158
|
+
blocks: w.blocks.map(toStringBlock)
|
|
1159
|
+
};
|
|
1160
|
+
}
|
|
1112
1161
|
function presentAthleteWorkouts(list) {
|
|
1113
1162
|
return list.map(presentAthleteWorkout);
|
|
1114
1163
|
}
|
|
@@ -1168,8 +1217,8 @@ function presentLogTargets(list) {
|
|
|
1168
1217
|
savedWorkoutSetExerciseId: id,
|
|
1169
1218
|
title: exerciseTitle(ex),
|
|
1170
1219
|
units: exerciseUnits(ex.param_1_type, ex.param_2_type),
|
|
1171
|
-
prescribed:
|
|
1172
|
-
performed:
|
|
1220
|
+
prescribed: prescribedStrings(ex),
|
|
1221
|
+
performed: performedStrings(ex)
|
|
1173
1222
|
};
|
|
1174
1223
|
}).filter((e) => e !== null);
|
|
1175
1224
|
targets.push({
|
|
@@ -2743,7 +2792,7 @@ var ExerciseLibrary = class {
|
|
|
2743
2792
|
await this.ensureFresh();
|
|
2744
2793
|
const s = this.#byId.get(id);
|
|
2745
2794
|
if (!s) return null;
|
|
2746
|
-
return presentExercise
|
|
2795
|
+
return presentExercise(s.raw);
|
|
2747
2796
|
}
|
|
2748
2797
|
async defaults(id) {
|
|
2749
2798
|
const s = this.#byId.get(id);
|
|
@@ -3680,7 +3729,7 @@ var JsonFileLibraryCache = class {
|
|
|
3680
3729
|
};
|
|
3681
3730
|
//#endregion
|
|
3682
3731
|
//#region package.json
|
|
3683
|
-
var version = "1.
|
|
3732
|
+
var version = "1.7.0";
|
|
3684
3733
|
//#endregion
|
|
3685
3734
|
//#region src/server.ts
|
|
3686
3735
|
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.7.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -21,11 +21,11 @@
|
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
23
23
|
"zod": "^4.4.3",
|
|
24
|
-
"@trainheroic-unofficial/
|
|
25
|
-
"@trainheroic-unofficial/
|
|
24
|
+
"@trainheroic-unofficial/js": "1.7.0",
|
|
25
|
+
"@trainheroic-unofficial/core": "1.7.0"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@types/node": "^26.0.
|
|
28
|
+
"@types/node": "^26.0.1",
|
|
29
29
|
"tsdown": "^0.22.3",
|
|
30
30
|
"tsx": "^4.22.4",
|
|
31
31
|
"typescript": "^6.0.3",
|