@trainheroic-unofficial/coach-mcp 3.0.0 → 3.0.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.
- package/dist/server.mjs +21 -68
- package/package.json +3 -3
package/dist/server.mjs
CHANGED
|
@@ -960,11 +960,6 @@ async function getJson(client, path, label) {
|
|
|
960
960
|
if (!res.ok) throw new Error(`${label} failed (HTTP ${res.status}).`);
|
|
961
961
|
return res.data;
|
|
962
962
|
}
|
|
963
|
-
async function getArray$1(client, path, label) {
|
|
964
|
-
const res = await client.request("GET", path);
|
|
965
|
-
if (!res.ok || !Array.isArray(res.data)) throw new Error(`${label} failed (HTTP ${res.status}).`);
|
|
966
|
-
return res.data;
|
|
967
|
-
}
|
|
968
963
|
/** Lifetime training totals. `use_metric` is required by the API (omitting it 400s). */
|
|
969
964
|
function fetchAthleteProfileSummary(client, userId, useMetric = false) {
|
|
970
965
|
return getJson(client, `/v5/athleteProfile/summary?user_id=${userId}&use_metric=${useMetric ? 1 : 0}`, "athlete profile summary");
|
|
@@ -994,8 +989,9 @@ function sortRosterByRecency(rows) {
|
|
|
994
989
|
async function fetchRosterActivity(client, athleteIds, useMetric = false) {
|
|
995
990
|
const rows = [];
|
|
996
991
|
const concurrency = 6;
|
|
997
|
-
|
|
998
|
-
|
|
992
|
+
const uniqueAthleteIds = [...new Set(athleteIds)];
|
|
993
|
+
for (let i = 0; i < uniqueAthleteIds.length; i += concurrency) {
|
|
994
|
+
const chunk = uniqueAthleteIds.slice(i, i + concurrency);
|
|
999
995
|
const settled = await Promise.all(chunk.map(async (id) => {
|
|
1000
996
|
try {
|
|
1001
997
|
return {
|
|
@@ -1028,10 +1024,6 @@ async function fetchRosterActivity(client, athleteIds, useMetric = false) {
|
|
|
1028
1024
|
function fetchExerciseHistoryDetail(client, exerciseId, userId) {
|
|
1029
1025
|
return getJson(client, `/v5/exercises/${exerciseId}/history?userId=${userId}`, "athlete exercise history");
|
|
1030
1026
|
}
|
|
1031
|
-
/** Scheduled + completed workouts in an inclusive YYYY-MM-DD window. */
|
|
1032
|
-
function fetchAthleteWorkouts(client, startDate, endDate) {
|
|
1033
|
-
return getArray$1(client, `/3.0/athlete/programworkout/range?startDate=${startDate}&endDate=${endDate}`, "athlete workouts");
|
|
1034
|
-
}
|
|
1035
1027
|
function nonEmpty(value) {
|
|
1036
1028
|
return value !== void 0 && value !== null && String(value).trim() !== "";
|
|
1037
1029
|
}
|
|
@@ -1643,30 +1635,6 @@ function buildSetCompletePayload(rawSet, exerciseIds, complete) {
|
|
|
1643
1635
|
};
|
|
1644
1636
|
}
|
|
1645
1637
|
/**
|
|
1646
|
-
* Record entered set results for one saved workout set.
|
|
1647
|
-
*
|
|
1648
|
-
* **Two-step write (both required for data to persist):**
|
|
1649
|
-
* 1. For each exercise in `results`:
|
|
1650
|
-
* `PUT /1.0/athlete/savedworkoutsetexercise/{savedWorkoutSetExerciseId}` with the
|
|
1651
|
-
* per-slot `param_N_data_M` values. This is the only path that actually stores reps
|
|
1652
|
-
* and weight — the `savedworkoutset` PUT accepts the same fields but silently discards
|
|
1653
|
-
* them.
|
|
1654
|
-
* 2. `PUT /1.0/athlete/savedworkoutset/{savedWorkoutSetId}` with `completed:"1"` to
|
|
1655
|
-
* mark the block done and make the entry visible as a logged set in history.
|
|
1656
|
-
*
|
|
1657
|
-
* The date is used to locate the saved workout (via the range endpoint) so we can resolve
|
|
1658
|
-
* `saved_workout_id` and `workout_set_exercise_id` for each exercise. Both are required
|
|
1659
|
-
* by the respective PUT bodies.
|
|
1660
|
-
*/
|
|
1661
|
-
async function logAthleteSet(client, args) {
|
|
1662
|
-
const r = await writeSetResults(client, { role: "athlete" }, await fetchAthleteWorkouts(client, args.date, args.date), args.savedWorkoutSetId, args.results, "log");
|
|
1663
|
-
return {
|
|
1664
|
-
savedWorkoutSetId: r.savedWorkoutSetId,
|
|
1665
|
-
exercisesLogged: r.exercisesWritten,
|
|
1666
|
-
setCompleted: r.setCompleted
|
|
1667
|
-
};
|
|
1668
|
-
}
|
|
1669
|
-
/**
|
|
1670
1638
|
* Coach "Log for Athlete": record set results for a roster athlete on their behalf, via the
|
|
1671
1639
|
* coach surface — `PUT /1.0/coach/savedworkoutsetexercise/{id}/{athleteId}` (the data write)
|
|
1672
1640
|
* then `PUT /1.0/coach/savedworkoutset/{id}/{athleteId}` (mark complete). Same two-step
|
|
@@ -1865,7 +1833,7 @@ function prescribedExerciseLabels(workouts) {
|
|
|
1865
1833
|
return labels;
|
|
1866
1834
|
}
|
|
1867
1835
|
/** Group resolved exercises by saved set and write each set via the given log target. */
|
|
1868
|
-
async function logResolvedExercises(client, target,
|
|
1836
|
+
async function logResolvedExercises(client, target, workouts, resolved) {
|
|
1869
1837
|
const bySet = /* @__PURE__ */ new Map();
|
|
1870
1838
|
for (const r of resolved) {
|
|
1871
1839
|
const list = bySet.get(r.savedWorkoutSetId) ?? [];
|
|
@@ -1877,19 +1845,10 @@ async function logResolvedExercises(client, target, date, resolved) {
|
|
|
1877
1845
|
}
|
|
1878
1846
|
const out = [];
|
|
1879
1847
|
for (const [savedWorkoutSetId, results] of bySet) {
|
|
1880
|
-
const written =
|
|
1881
|
-
athleteId: target.athleteId,
|
|
1882
|
-
date,
|
|
1883
|
-
savedWorkoutSetId,
|
|
1884
|
-
results
|
|
1885
|
-
}) : await logAthleteSet(client, {
|
|
1886
|
-
date,
|
|
1887
|
-
savedWorkoutSetId,
|
|
1888
|
-
results
|
|
1889
|
-
});
|
|
1848
|
+
const written = await writeSetResults(client, target, workouts, savedWorkoutSetId, results, "log");
|
|
1890
1849
|
out.push({
|
|
1891
1850
|
savedWorkoutSetId: written.savedWorkoutSetId,
|
|
1892
|
-
exercisesLogged: written.
|
|
1851
|
+
exercisesLogged: written.exercisesWritten
|
|
1893
1852
|
});
|
|
1894
1853
|
}
|
|
1895
1854
|
return out;
|
|
@@ -1922,7 +1881,7 @@ async function logSessionForAthlete(client, args) {
|
|
|
1922
1881
|
const sets = await logResolvedExercises(client, {
|
|
1923
1882
|
role: "coach",
|
|
1924
1883
|
athleteId: args.athleteId
|
|
1925
|
-
},
|
|
1884
|
+
}, day, resolved);
|
|
1926
1885
|
return {
|
|
1927
1886
|
date: args.date,
|
|
1928
1887
|
created: false,
|
|
@@ -2156,6 +2115,7 @@ async function collectAdvisories(blocks, index) {
|
|
|
2156
2115
|
}
|
|
2157
2116
|
//#endregion
|
|
2158
2117
|
//#region ../js/src/workout-session.ts
|
|
2118
|
+
const EXERCISE_SAVE_CONCURRENCY = 4;
|
|
2159
2119
|
/**
|
|
2160
2120
|
* Coach calendar writes (`createWorkoutForDay`, timeline create, `copyProgramWorkout`) 500/401
|
|
2161
2121
|
* on personal calendars (Coach Plan / `personal_cal`). Shared by `buildSession` and
|
|
@@ -2189,15 +2149,14 @@ async function buildSession(client, opts) {
|
|
|
2189
2149
|
const created = await req(client, "POST", "/2.0/coach/calendar/saveProgramWorkoutSets", buildBlockPayload(blocks, workoutId));
|
|
2190
2150
|
const byOrder = new Map(created.map((b) => [b.order, b.id]));
|
|
2191
2151
|
let counter = 0;
|
|
2192
|
-
|
|
2152
|
+
await mapPool(blocks.map((block, i) => {
|
|
2193
2153
|
const wsid = byOrder.get(i + 1);
|
|
2194
2154
|
if (wsid === void 0) throw new Error(`No saved block for order ${i + 1}.`);
|
|
2195
2155
|
return block.exercises.map((ex, j) => {
|
|
2196
2156
|
counter += 1;
|
|
2197
2157
|
return makeExercise(ex, wsid, j + 1, `k::${workoutId}${String(counter).padStart(3, "0")}`);
|
|
2198
2158
|
});
|
|
2199
|
-
});
|
|
2200
|
-
await Promise.all(payloads.filter((p) => p.length > 0).map((p) => req(client, "POST", "/2.0/coach/calendar/saveWorkoutSetExercises", p)));
|
|
2159
|
+
}).filter((p) => p.length > 0), EXERCISE_SAVE_CONCURRENCY, (payload) => req(client, "POST", "/2.0/coach/calendar/saveWorkoutSetExercises", payload));
|
|
2201
2160
|
if (opts.instruction !== void 0 && opts.instruction !== "") {
|
|
2202
2161
|
const blockIds = [...byOrder.entries()].sort((a, b) => a[0] - b[0]).map(([, id]) => id);
|
|
2203
2162
|
await setSessionInstruction(client, workoutId, sess, opts.instruction, blockIds);
|
|
@@ -2884,9 +2843,11 @@ async function deleteComment(client, streamId, commentId) {
|
|
|
2884
2843
|
if (!res.ok) throw new Error(`Message delete failed (HTTP ${res.status}).`);
|
|
2885
2844
|
return res.data;
|
|
2886
2845
|
}
|
|
2887
|
-
async function readLive(client, streamId, limit) {
|
|
2888
|
-
const
|
|
2846
|
+
async function readLive(client, streamId, limit, afterCommentId) {
|
|
2847
|
+
const cursor = afterCommentId === void 0 ? "" : String(afterCommentId);
|
|
2848
|
+
const res = await client.request("GET", `/v5/messaging/streams/${streamId}/comments?lastCommentId=${cursor}`);
|
|
2889
2849
|
if (!res.ok || !Array.isArray(res.data)) throw new Error(`Message read failed (HTTP ${res.status}).`);
|
|
2850
|
+
if (afterCommentId !== void 0) return limit !== void 0 && limit > 0 ? res.data.slice(0, limit) : res.data;
|
|
2890
2851
|
return limit !== void 0 && limit > 0 ? res.data.slice(-limit) : res.data;
|
|
2891
2852
|
}
|
|
2892
2853
|
//#endregion
|
|
@@ -3017,21 +2978,12 @@ var ExerciseLibrary = class {
|
|
|
3017
2978
|
}
|
|
3018
2979
|
async resolve(name) {
|
|
3019
2980
|
await this.ensureFresh();
|
|
3020
|
-
|
|
2981
|
+
const hit = this.#exact(name);
|
|
3021
2982
|
if (hit) return {
|
|
3022
2983
|
match: hit,
|
|
3023
2984
|
candidates: [hit]
|
|
3024
2985
|
};
|
|
3025
|
-
|
|
3026
|
-
if (candidates.length === 0) {
|
|
3027
|
-
await this.refresh();
|
|
3028
|
-
hit = this.#exact(name);
|
|
3029
|
-
if (hit) return {
|
|
3030
|
-
match: hit,
|
|
3031
|
-
candidates: [hit]
|
|
3032
|
-
};
|
|
3033
|
-
candidates = this.#searchOnly(name, 20);
|
|
3034
|
-
}
|
|
2986
|
+
const candidates = this.#searchOnly(name, 20);
|
|
3035
2987
|
if (candidates.length === 1) return {
|
|
3036
2988
|
match: candidates[0] ?? null,
|
|
3037
2989
|
candidates
|
|
@@ -3871,13 +3823,14 @@ function registerReads(server, ctx) {
|
|
|
3871
3823
|
}));
|
|
3872
3824
|
server.registerTool("messaging_read", {
|
|
3873
3825
|
title: "Read messages (live)",
|
|
3874
|
-
description: "
|
|
3826
|
+
description: "Comments in a stream, live from the API. Pass `afterCommentId` to fetch only newer comments upstream; cursor reads return the oldest unseen comments first, bounded by `limit`, so advance with the last returned comment ID to continue without gaps. Without it, the stream is fetched whole, then trimmed to `limit` (default 20). Each comment's `isAuthor` is true when the logged-in user sent it — to answer 'did an athlete message me', look for comments with isAuthor:false. Timestamps are Unix seconds. An empty result means the thread has no messages.",
|
|
3875
3827
|
inputSchema: {
|
|
3876
3828
|
streamId: idParam,
|
|
3877
|
-
limit: z.number().int().positive().max(200).optional()
|
|
3829
|
+
limit: z.number().int().positive().max(200).optional(),
|
|
3830
|
+
afterCommentId: idParam.optional()
|
|
3878
3831
|
},
|
|
3879
3832
|
annotations: READ
|
|
3880
|
-
}, ({ streamId, limit }) => attempt(async () => jsonResult(await readLive(ctx.client, toId(streamId), limit ?? 20))));
|
|
3833
|
+
}, ({ streamId, limit, afterCommentId }) => attempt(async () => jsonResult(await readLive(ctx.client, toId(streamId), limit ?? 20, afterCommentId === void 0 ? void 0 : toId(afterCommentId)))));
|
|
3881
3834
|
server.registerTool("message_draft", {
|
|
3882
3835
|
title: "Draft a message (preview only)",
|
|
3883
3836
|
description: "Preview the exact payload and target WITHOUT sending. Always safe.",
|
|
@@ -3973,7 +3926,7 @@ var JsonFileLibraryCache = class {
|
|
|
3973
3926
|
};
|
|
3974
3927
|
//#endregion
|
|
3975
3928
|
//#region package.json
|
|
3976
|
-
var version = "3.0.
|
|
3929
|
+
var version = "3.0.1";
|
|
3977
3930
|
//#endregion
|
|
3978
3931
|
//#region src/server.ts
|
|
3979
3932
|
function main() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trainheroic-unofficial/coach-mcp",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -21,8 +21,8 @@
|
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"@modelcontextprotocol/server": "2.0.0",
|
|
23
23
|
"zod": "^4.4.3",
|
|
24
|
-
"@trainheroic-unofficial/
|
|
25
|
-
"@trainheroic-unofficial/
|
|
24
|
+
"@trainheroic-unofficial/core": "3.0.1",
|
|
25
|
+
"@trainheroic-unofficial/js": "3.0.1"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@types/node": "^26.2.0",
|