@trainheroic-unofficial/core 2.0.2 → 2.1.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/index.mjs +31 -14
- package/package.json +4 -4
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { athleteSessionRemoveArgsSchema, blockSpecSchema, coachLogSessionArgsSchema, coachLogSetArgsSchema, coachPrescribeSetArgsSchema, commentDraftSchema, dateString, exerciseCreateSchema, idArgSchema, logSessionArgsSchema, logSetArgsSchema, parseWorkoutDate, swapAthleteExerciseArgsSchema } from "@trainheroic-unofficial/dto";
|
|
2
2
|
import { acceptedContent, inputRequired, inputResponse } from "@modelcontextprotocol/server";
|
|
3
3
|
import { z } from "zod";
|
|
4
|
-
import { ANALYTICS_METRIC_KEYS, addExercisesToWorkout, buildCommentPayload, buildSession, coerceInt, collectAdvisories, copySession, createPersonalWorkout, definedProps, deleteComment, exerciseUnits, fetchAthleteMainLiftPRs, fetchAthletePrefs, fetchAthleteProfileSummary, fetchAthleteUser, fetchAthleteWorkouts, fetchCoachAthleteCalendarSummary, fetchCoachAthleteWorkouts, fetchExerciseHistoryDetail, fetchExerciseHistoryList, fetchExerciseStats, fetchLeaderboard, fetchPersonalRecords, fetchRosterActivity, fetchRosterMainLiftPRs, fetchStreams, fetchTeamAthleteIds, fetchWorkingMaxes, inviteAthletes, isRecord, logAdHocSession, logAthleteSet, logForAthlete, logSessionForAthlete, prescribeForAthlete, presentAthleteWorkouts, presentCoachAthleteTraining, presentExerciseHistory, presentLogTargets, publishSession, queryAnalytics, readLive, readSession, removePersonalWorkout, removeSession, searchExerciseHistory, selectWorkouts, selectWorkoutsByProgram, sendComment, summarizeAthleteWorkouts, swapAthleteExercise, teamVolume, toSetResults } from "@trainheroic-unofficial/js";
|
|
4
|
+
import { ANALYTICS_METRIC_KEYS, addExercisesToWorkout, buildCommentPayload, buildSession, coerceInt, collectAdvisories, copySession, createPersonalWorkout, definedProps, deleteComment, exerciseUnits, fetchAthleteMainLiftPRs, fetchAthletePrefs, fetchAthleteProfileSummary, fetchAthleteUser, fetchAthleteWorkouts, fetchCoachAthleteCalendarSummary, fetchCoachAthleteWorkouts, fetchExerciseHistoryDetail, fetchExerciseHistoryList, fetchExerciseStats, fetchLeaderboard, fetchPersonalRecords, fetchRosterActivity, fetchRosterMainLiftPRs, fetchStreams, fetchTeamAthleteIds, fetchWorkingMaxes, inviteAthletes, isRecord, logAdHocSession, logAthleteSet, logForAthlete, logSessionForAthlete, prescribeForAthlete, presentAthleteWorkouts, presentCoachAthleteTraining, presentExerciseHistory, presentLogTargets, publishSession, queryAnalytics, readLive, readSession, removePersonalWorkout, removeSession, resolveBuildProgramId, searchExerciseHistory, selectWorkouts, selectWorkoutsByProgram, sendComment, summarizeAthleteWorkouts, swapAthleteExercise, teamVolume, toSetResults, updateTeam } from "@trainheroic-unofficial/js";
|
|
5
5
|
//#region src/context.ts
|
|
6
6
|
/** A tool argument that accepts a numeric id as a number or a string of digits. */
|
|
7
7
|
const idParam = idArgSchema;
|
|
@@ -403,7 +403,7 @@ function registerEntityReads(server, ctx) {
|
|
|
403
403
|
}));
|
|
404
404
|
server.registerTool("get_program", {
|
|
405
405
|
title: "Get program detail",
|
|
406
|
-
description: "Full nested program structure (blocks + sessions) live from the API, by program id.
|
|
406
|
+
description: "Full nested program structure (blocks + sessions) live from the API, by program id. Works for team calendars and athlete coach calendars (type 5 from /v5/calendars/athletes/{id}). Some unrelated ids return HTTP 401 Cannot access program.",
|
|
407
407
|
inputSchema: { programId: idParam },
|
|
408
408
|
annotations: READ
|
|
409
409
|
}, ({ programId }) => apiCall(ctx, "GET", `/3.0/coach/program/${enc(programId)}`, void 0, "This is a large, deep object. If it is truncated, fetch a narrower view (a specific session) instead."));
|
|
@@ -1005,19 +1005,25 @@ const ADDITIVE = {
|
|
|
1005
1005
|
function registerTeamTools(server, ctx) {
|
|
1006
1006
|
server.registerTool("team_create", {
|
|
1007
1007
|
title: "Create a team",
|
|
1008
|
-
description: "Create a team (POST /1.0/coach/team/createWithTitleAndCode). Also creates the team's calendar/program. Returns the new team including its calendar id. Use the team id with athlete_invite.",
|
|
1008
|
+
description: "Create a team (POST /1.0/coach/team/createWithTitleAndCode). Also creates the team's calendar/program. Returns the new team including its calendar id. Use the team id with athlete_invite. To point a new team at an existing calendar instead of its auto-created one, follow up with team_update groupProgram.",
|
|
1009
1009
|
inputSchema: { title: z.string().min(1) },
|
|
1010
1010
|
annotations: ADDITIVE
|
|
1011
1011
|
}, ({ title }) => apiCall(ctx, "POST", "/1.0/coach/team/createWithTitleAndCode", { body: { title } }));
|
|
1012
1012
|
server.registerTool("team_update", {
|
|
1013
|
-
title: "
|
|
1014
|
-
description: "Update a team's
|
|
1013
|
+
title: "Update a team",
|
|
1014
|
+
description: "Update a team's title and/or reassign its calendar (PUT /v5/teams/{teamId}). Pass groupProgram (a program/calendar id — typically another team's group_program from list_teams, or get_team) to point this team at an existing parent program. At least one of title or groupProgram is required; when only groupProgram is set the current title is preserved.",
|
|
1015
1015
|
inputSchema: {
|
|
1016
1016
|
teamId: idParam,
|
|
1017
|
-
title: z.string().min(1)
|
|
1017
|
+
title: z.string().min(1).optional(),
|
|
1018
|
+
groupProgram: idParam.optional()
|
|
1018
1019
|
},
|
|
1019
1020
|
annotations: ADDITIVE
|
|
1020
|
-
}, ({ teamId, title }) =>
|
|
1021
|
+
}, ({ teamId, title, groupProgram }) => attempt(async () => {
|
|
1022
|
+
const args = { teamId: toId(teamId) };
|
|
1023
|
+
if (title !== void 0) args.title = title;
|
|
1024
|
+
if (groupProgram !== void 0) args.groupProgram = toId(groupProgram);
|
|
1025
|
+
return jsonResult(await updateTeam(ctx.client, args));
|
|
1026
|
+
}));
|
|
1021
1027
|
server.registerTool("team_delete", {
|
|
1022
1028
|
title: "Delete a team",
|
|
1023
1029
|
description: "Delete a team (DELETE /v5/teams/{teamId}). Removes the team and its calendar from the live account; hard to undo. Requires confirmation (elicitation, or confirm:true).",
|
|
@@ -1161,13 +1167,14 @@ function registerExerciseTools(server, ctx) {
|
|
|
1161
1167
|
}
|
|
1162
1168
|
//#endregion
|
|
1163
1169
|
//#region src/tools/workout.ts
|
|
1164
|
-
/** Build a draft
|
|
1170
|
+
/** Build a draft session (workout_build). */
|
|
1165
1171
|
function registerBuild(server, ctx) {
|
|
1166
1172
|
server.registerTool("workout_build", {
|
|
1167
1173
|
title: "Build a workout session (draft)",
|
|
1168
|
-
description: "Build an UNPUBLISHED session from a spec (program -> session -> blocks -> exercises).
|
|
1174
|
+
description: "Build an UNPUBLISHED session from a spec (program -> session -> blocks -> exercises). Pass programId for a team/group calendar (list_teams → group_program), or athleteId to write on that roster athlete's coach calendar (resolved via /v5/calendars/athletes/{id} — the same calendar the coach web app opens from My Athletes). athleteId requires date. Two exercises in one block become a superset. A block with empty exercises and a non-empty block instruction is a text-only Circuit / Conditioning block (type 1). Add a block 'leaderboard' for a Red-Zone score, or a top-level 'instruction' for the session note (Coach Instructions). Returns the draft ids, a read-back, and unit advisories. Review, then workout_publish.",
|
|
1169
1175
|
inputSchema: {
|
|
1170
|
-
programId: z.number(),
|
|
1176
|
+
programId: z.number().optional(),
|
|
1177
|
+
athleteId: idParam.optional(),
|
|
1171
1178
|
date: z.string().optional(),
|
|
1172
1179
|
timelineDay: z.number().optional(),
|
|
1173
1180
|
blocks: z.array(blockSpecSchema),
|
|
@@ -1178,11 +1185,16 @@ function registerBuild(server, ctx) {
|
|
|
1178
1185
|
destructiveHint: false,
|
|
1179
1186
|
openWorldHint: true
|
|
1180
1187
|
}
|
|
1181
|
-
}, ({ programId, date, timelineDay, blocks, instruction }) => attempt(async () => {
|
|
1188
|
+
}, ({ programId, athleteId, date, timelineDay, blocks, instruction }) => attempt(async () => {
|
|
1182
1189
|
if (date === void 0 && timelineDay === void 0) return errorResult("Provide either date (YYYY-M-D) or timelineDay.");
|
|
1190
|
+
const resolveArgs = {};
|
|
1191
|
+
if (programId !== void 0) resolveArgs.programId = programId;
|
|
1192
|
+
if (athleteId !== void 0) resolveArgs.athleteId = toId(athleteId);
|
|
1193
|
+
if (date !== void 0) resolveArgs.date = date;
|
|
1194
|
+
const resolved = await resolveBuildProgramId(ctx.client, resolveArgs);
|
|
1183
1195
|
const typed = blocks;
|
|
1184
1196
|
const opts = {
|
|
1185
|
-
programId,
|
|
1197
|
+
programId: resolved,
|
|
1186
1198
|
blocks: typed,
|
|
1187
1199
|
publish: false
|
|
1188
1200
|
};
|
|
@@ -1191,15 +1203,19 @@ function registerBuild(server, ctx) {
|
|
|
1191
1203
|
if (instruction !== void 0) opts.instruction = instruction;
|
|
1192
1204
|
const advisories = await collectAdvisories(typed, ctx.index);
|
|
1193
1205
|
const built = await buildSession(ctx.client, opts);
|
|
1194
|
-
const readback = opts.date ? await readSession(ctx.client,
|
|
1206
|
+
const readback = opts.date ? await readSession(ctx.client, resolved, opts.date, built.pwId) : null;
|
|
1195
1207
|
return jsonResult({
|
|
1196
1208
|
...built,
|
|
1209
|
+
programId: resolved,
|
|
1197
1210
|
published: false,
|
|
1198
1211
|
advisories,
|
|
1199
1212
|
readback,
|
|
1200
1213
|
note: "Draft created (unpublished). Review, then call workout_publish to make it athlete-facing."
|
|
1201
1214
|
});
|
|
1202
1215
|
}));
|
|
1216
|
+
}
|
|
1217
|
+
/** Read-back and publish for a built session. */
|
|
1218
|
+
function registerReadPublish(server, ctx) {
|
|
1203
1219
|
server.registerTool("workout_read", {
|
|
1204
1220
|
title: "Read a built session",
|
|
1205
1221
|
description: "Read-back a session by programId, date (YYYY-M-D), and programWorkout id.",
|
|
@@ -1278,7 +1294,7 @@ function registerLifecycle(server, ctx) {
|
|
|
1278
1294
|
}));
|
|
1279
1295
|
server.registerTool("session_copy", {
|
|
1280
1296
|
title: "Copy a session to a date",
|
|
1281
|
-
description: "Copy/repeat a session to a target date on a program (POST .../copyProgramWorkout). toDate is YYYY-M-D. Creates a new session; review and publish it separately.
|
|
1297
|
+
description: "Copy/repeat a session to a target date on a program (POST .../copyProgramWorkout). toDate is YYYY-M-D. Creates a new session; review and publish it separately. toProgramId may be a team group_program or an athlete calendar program id (from /v5/calendars/athletes/{athleteId}?year=&month= / workout_build athleteId).",
|
|
1282
1298
|
inputSchema: {
|
|
1283
1299
|
toProgramId: z.number(),
|
|
1284
1300
|
pwId: z.number(),
|
|
@@ -1308,6 +1324,7 @@ function registerLifecycle(server, ctx) {
|
|
|
1308
1324
|
/** Workout building, read-back, publishing, and the session calendar lifecycle. */
|
|
1309
1325
|
function registerWorkoutTools(server, ctx) {
|
|
1310
1326
|
registerBuild(server, ctx);
|
|
1327
|
+
registerReadPublish(server, ctx);
|
|
1311
1328
|
registerLifecycle(server, ctx);
|
|
1312
1329
|
}
|
|
1313
1330
|
//#endregion
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trainheroic-unofficial/core",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -25,11 +25,11 @@
|
|
|
25
25
|
"@cfworker/json-schema": "^4.1.1",
|
|
26
26
|
"@modelcontextprotocol/server": "2.0.0",
|
|
27
27
|
"zod": "^4.4.3",
|
|
28
|
-
"@trainheroic-unofficial/
|
|
29
|
-
"@trainheroic-unofficial/
|
|
28
|
+
"@trainheroic-unofficial/js": "2.1.1",
|
|
29
|
+
"@trainheroic-unofficial/dto": "2.1.1"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@types/node": "^26.
|
|
32
|
+
"@types/node": "^26.2.0",
|
|
33
33
|
"tsdown": "^0.22.14",
|
|
34
34
|
"typescript": "^7.0.2",
|
|
35
35
|
"vitest": "^4.1.10"
|