@trainheroic-unofficial/core 3.1.1 → 3.2.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/index.mjs +166 -3
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { athletePrescribeSetArgsSchema, athleteSessionRemoveArgsSchema, blockSpecSchema, coachLogSessionArgsSchema, coachLogSetArgsSchema, coachPrescribeSetArgsSchema, commentDraftSchema, dateString, exerciseCreateSchema, idArgSchema, logSessionArgsSchema, logSetArgsSchema, parseWorkoutDate, swapAthleteExerciseArgsSchema } from "@trainheroic-unofficial/dto";
|
|
1
|
+
import { athletePrescribeSetArgsSchema, athleteSessionRemoveArgsSchema, blockSpecSchema, coachLogSessionArgsSchema, coachLogSetArgsSchema, coachPrescribeSetArgsSchema, commentDraftSchema, dateString, exerciseCreateSchema, idArgSchema, logSessionArgsSchema, logSetArgsSchema, parseWorkoutDate, sessionTemplateCreateSchema, swapAthleteExerciseArgsSchema, teamPublishPatchObject, teamPublishPatchSchema } from "@trainheroic-unofficial/dto";
|
|
2
2
|
import { acceptedContent, inputRequired, inputResponse } from "@modelcontextprotocol/server";
|
|
3
3
|
import { z } from "zod";
|
|
4
|
-
import { ANALYTICS_METRIC_KEYS, PROGRAM_KINDS, addExercisesToWorkout, buildCommentPayload, buildSession, coerceInt, collectAdvisories, copySession, createPersonalWorkout, createProgram, 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, prescribeAthleteSet, 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";
|
|
4
|
+
import { ANALYTICS_METRIC_KEYS, PROGRAM_KINDS, SESSION_TEMPLATES_LIST_PATH, addExercisesToWorkout, buildCommentPayload, buildSession, coerceInt, collectAdvisories, copySession, createPersonalWorkout, createProgram, createSessionTemplate, definedProps, deleteComment, deleteProgram, exerciseUnits, fetchAthleteCircuits, fetchAthleteMainLiftPRs, fetchAthletePrefs, fetchAthleteProfileSummary, fetchAthleteProgrammingPrograms, fetchAthleteUser, fetchAthleteWorkouts, fetchCoachAthleteCalendarSummary, fetchCoachAthleteWorkouts, fetchExerciseHistoryDetail, fetchExerciseHistoryList, fetchExerciseStats, fetchLeaderboard, fetchPersonalRecords, fetchRecentExercises, fetchRosterActivity, fetchRosterMainLiftPRs, fetchStreams, fetchTeamAthleteIds, fetchWorkingMaxes, inviteAthletes, isRecord, logAdHocSession, logAthleteSet, logForAthlete, logSessionForAthlete, prescribeAthleteSet, prescribeForAthlete, presentAthleteWorkouts, presentCoachAthleteTraining, presentExerciseHistory, presentLogTargets, publishSession, queryAnalytics, readLive, readSession, removePersonalWorkout, removeSession, resolveBuildProgramId, searchExerciseHistory, selectWorkouts, selectWorkoutsByProgram, sendComment, summarizeAthleteWorkouts, swapAthleteExercise, teamPublishTarget, teamVolume, toSetResults, updateTeam, updateTeamPublishSettings } 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;
|
|
@@ -287,11 +287,35 @@ const SIMPLE_GETS = [
|
|
|
287
287
|
description: "Unread counts including countMessagingNotViewed (cheap 'anything new?' poll).",
|
|
288
288
|
path: "/v5/notifications/counts"
|
|
289
289
|
},
|
|
290
|
+
{
|
|
291
|
+
name: "list_notifications",
|
|
292
|
+
title: "Notification list",
|
|
293
|
+
description: "Full notification list (GET /v5/notifications). Distinct from `notifications`, which returns unread counts only. Empty when there are no notifications.",
|
|
294
|
+
path: "/v5/notifications"
|
|
295
|
+
},
|
|
296
|
+
{
|
|
297
|
+
name: "list_subscriptions",
|
|
298
|
+
title: "Program subscriptions",
|
|
299
|
+
description: "Program subscriptions and subscribed teams (GET /1.0/coach/subscriptions). Returns `{subscriptions, teams}`.",
|
|
300
|
+
path: "/1.0/coach/subscriptions"
|
|
301
|
+
},
|
|
302
|
+
{
|
|
303
|
+
name: "list_prescription_templates",
|
|
304
|
+
title: "Prescription templates",
|
|
305
|
+
description: "Saved sets/reps schemes (GET /2.0/coach/workoutSetExercise/template). Use when picking a named prescription like '4 x 3' rather than typing set counts by hand.",
|
|
306
|
+
path: "/2.0/coach/workoutSetExercise/template"
|
|
307
|
+
},
|
|
290
308
|
{
|
|
291
309
|
name: "analytics_categories",
|
|
292
310
|
title: "Analytics categories",
|
|
293
311
|
description: "TrainHeroic's raw analytics catalog. Its keys are the API's own names and do NOT match analytics_query's `metric` values — choose the metric straight from analytics_query's (self-describing) enum instead; you rarely need this tool.",
|
|
294
312
|
path: "/v5/analytics"
|
|
313
|
+
},
|
|
314
|
+
{
|
|
315
|
+
name: "list_session_templates",
|
|
316
|
+
title: "List session templates",
|
|
317
|
+
description: "Session templates in the coach library (GET /1.0/coach/workouts). Use a template id with session_save_as_template's inverse: this lists saved templates; session_save_as_template writes one from an existing session. Empty when the library has no templates yet.",
|
|
318
|
+
path: SESSION_TEMPLATES_LIST_PATH
|
|
295
319
|
}
|
|
296
320
|
];
|
|
297
321
|
/** Roster-level reads: the fixed GETs plus the filterable athlete and team lists. */
|
|
@@ -455,9 +479,18 @@ function registerTeamVolume(server, ctx) {
|
|
|
455
479
|
}
|
|
456
480
|
function registerReadTools(server, ctx) {
|
|
457
481
|
registerRosterReads(server, ctx);
|
|
482
|
+
registerCoachAthleteTeamCalendar(server, ctx);
|
|
458
483
|
registerEntityReads(server, ctx);
|
|
459
484
|
registerTeamVolume(server, ctx);
|
|
460
485
|
}
|
|
486
|
+
function registerCoachAthleteTeamCalendar(server, ctx) {
|
|
487
|
+
server.registerTool("coach_athlete_team_calendar", {
|
|
488
|
+
title: "Coach-athlete team calendar",
|
|
489
|
+
description: "Companion calendar for a roster athlete (GET /v5/calendars/athletes/{id}/coachAthleteTeam). Distinct from workout_build's type-5 individual calendar. Returns title, logo, id, athlete_id, owner_user_id.",
|
|
490
|
+
inputSchema: { athleteId: idParam },
|
|
491
|
+
annotations: READ
|
|
492
|
+
}, ({ athleteId }) => apiCall(ctx, "GET", `/v5/calendars/athletes/${toId(athleteId)}/coachAthleteTeam`));
|
|
493
|
+
}
|
|
461
494
|
//#endregion
|
|
462
495
|
//#region src/tools/main-lifts.ts
|
|
463
496
|
const monthsParam = z.number().int().positive().max(36).optional();
|
|
@@ -813,6 +846,26 @@ function registerSwapTool(server, ctx) {
|
|
|
813
846
|
}));
|
|
814
847
|
}));
|
|
815
848
|
}
|
|
849
|
+
function registerCatalogReads(server, ctx) {
|
|
850
|
+
server.registerTool("athlete_circuits", {
|
|
851
|
+
title: "Circuit history",
|
|
852
|
+
description: "Named circuit history for the logged-in athlete (GET /v5/users/circuits/{recent|history}). kind defaults to recent. Empty when the athlete has no saved circuits. Distinct from circuit *blocks* in workout_build (type 1).",
|
|
853
|
+
inputSchema: { kind: z.enum(["recent", "history"]).optional() },
|
|
854
|
+
annotations: READ
|
|
855
|
+
}, ({ kind }) => attempt(async () => jsonResult(await fetchAthleteCircuits(ctx.client, kind ?? "recent"))));
|
|
856
|
+
server.registerTool("athlete_programming_programs", {
|
|
857
|
+
title: "Subscribed programs",
|
|
858
|
+
description: "Programs the athlete is subscribed to (GET /1.0/athlete/programming/programs). Not the coach list_programs surface. Empty when the athlete has no subscriptions.",
|
|
859
|
+
inputSchema: {},
|
|
860
|
+
annotations: READ
|
|
861
|
+
}, () => attempt(async () => jsonResult(await fetchAthleteProgrammingPrograms(ctx.client))));
|
|
862
|
+
server.registerTool("athlete_recent_exercises", {
|
|
863
|
+
title: "Recent exercises",
|
|
864
|
+
description: "Recently used exercises (GET /v5/users/exercises/recent). Distinct from athlete_exercises (full logged catalog) and athlete_exercise_history (one lift).",
|
|
865
|
+
inputSchema: {},
|
|
866
|
+
annotations: READ
|
|
867
|
+
}, () => attempt(async () => jsonResult(await fetchRecentExercises(ctx.client))));
|
|
868
|
+
}
|
|
816
869
|
/**
|
|
817
870
|
* Live tools over the logged-in user's own training (history, scheduled/completed workouts,
|
|
818
871
|
* PRs, working maxes), plus a gated set-logging write. The athlete user id is
|
|
@@ -835,6 +888,7 @@ function registerAthleteTrainingTools(server, ctx) {
|
|
|
835
888
|
};
|
|
836
889
|
registerProfileTools(server, ctx, whoami, userId);
|
|
837
890
|
registerExerciseTools$1(server, ctx, userId);
|
|
891
|
+
registerCatalogReads(server, ctx);
|
|
838
892
|
registerLogTargetsTool(server, ctx);
|
|
839
893
|
registerSessionTools(server, ctx);
|
|
840
894
|
registerLogTool(server, ctx);
|
|
@@ -1101,6 +1155,37 @@ function registerTeamTools(server, ctx) {
|
|
|
1101
1155
|
if (blocked) return blocked;
|
|
1102
1156
|
return apiCall(ctx, "DELETE", `/v5/teamCodes/${id}`);
|
|
1103
1157
|
}));
|
|
1158
|
+
registerTeamPublishSettings(server, ctx);
|
|
1159
|
+
}
|
|
1160
|
+
function registerTeamPublishSettings(server, ctx) {
|
|
1161
|
+
server.registerTool("team_publish_settings", {
|
|
1162
|
+
title: "Update team auto-publish",
|
|
1163
|
+
description: "Update a team's auto-publish settings (POST /1.0/coach/team/updatePublishSettings). Pass teamId or programId (the team's group_program). At least one of pub_enabled, pub_days, pub_time, pub_timezone is required. Athlete-facing — requires confirmation.",
|
|
1164
|
+
inputSchema: {
|
|
1165
|
+
teamId: idParam.optional(),
|
|
1166
|
+
programId: idParam.optional(),
|
|
1167
|
+
...teamPublishPatchObject.shape,
|
|
1168
|
+
confirm: z.boolean().optional()
|
|
1169
|
+
},
|
|
1170
|
+
annotations: DESTRUCTIVE
|
|
1171
|
+
}, ({ teamId, programId, pub_enabled, pub_days, pub_time, pub_timezone, confirm }, extra) => attempt(async () => {
|
|
1172
|
+
const blocked = confirmGate(extra, "Change auto-publish settings? This controls when athletes see programmed sessions.", confirm);
|
|
1173
|
+
if (blocked) return blocked;
|
|
1174
|
+
const patch = teamPublishPatchSchema.parse(definedProps({
|
|
1175
|
+
pub_enabled,
|
|
1176
|
+
pub_days,
|
|
1177
|
+
pub_time,
|
|
1178
|
+
pub_timezone
|
|
1179
|
+
}));
|
|
1180
|
+
const target = teamPublishTarget(definedProps({
|
|
1181
|
+
programId: programId !== void 0 ? toId(programId) : void 0,
|
|
1182
|
+
teamId: teamId !== void 0 ? toId(teamId) : void 0
|
|
1183
|
+
}));
|
|
1184
|
+
return jsonResult(await updateTeamPublishSettings(ctx.client, {
|
|
1185
|
+
...target,
|
|
1186
|
+
patch
|
|
1187
|
+
}));
|
|
1188
|
+
}));
|
|
1104
1189
|
}
|
|
1105
1190
|
//#endregion
|
|
1106
1191
|
//#region src/tools/programs.ts
|
|
@@ -1123,6 +1208,20 @@ function registerProgramTools(server, ctx) {
|
|
|
1123
1208
|
kind,
|
|
1124
1209
|
name
|
|
1125
1210
|
}))));
|
|
1211
|
+
server.registerTool("program_delete", {
|
|
1212
|
+
title: "Delete a standalone program",
|
|
1213
|
+
description: "Delete a standalone calendar or fixed program (DELETE /v5/programs/{programId}). Accepts either list_programs id (container) or group_program (the underlying program id); container ids 401 if sent raw and are resolved automatically. Removes the calendar from the live account. Requires confirmation (elicitation, or confirm:true).",
|
|
1214
|
+
inputSchema: {
|
|
1215
|
+
programId: idParam,
|
|
1216
|
+
confirm: z.boolean().optional()
|
|
1217
|
+
},
|
|
1218
|
+
annotations: DESTRUCTIVE
|
|
1219
|
+
}, ({ programId, confirm }, extra) => attempt(async () => {
|
|
1220
|
+
const id = toId(programId);
|
|
1221
|
+
const blocked = confirmGate(extra, `Delete standalone program ${id}? This removes the calendar from the live account.`, confirm);
|
|
1222
|
+
if (blocked) return blocked;
|
|
1223
|
+
return jsonResult(await deleteProgram(ctx.client, id));
|
|
1224
|
+
}));
|
|
1126
1225
|
}
|
|
1127
1226
|
//#endregion
|
|
1128
1227
|
//#region src/tools/analytics.ts
|
|
@@ -1156,6 +1255,38 @@ function registerAnalyticsTools(server, ctx) {
|
|
|
1156
1255
|
}
|
|
1157
1256
|
//#endregion
|
|
1158
1257
|
//#region src/tools/exercises.ts
|
|
1258
|
+
function registerExerciseUpdate(server, index) {
|
|
1259
|
+
server.registerTool("exercise_update", {
|
|
1260
|
+
title: "Update custom exercise",
|
|
1261
|
+
description: "Update a custom exercise (POST /2.0/coach/exercise/update/{id}) and write it through to the mirror. Same body as exercise_create. Only works for exercises with can_edit:1.",
|
|
1262
|
+
inputSchema: {
|
|
1263
|
+
id: idParam,
|
|
1264
|
+
exercise: exerciseCreateSchema
|
|
1265
|
+
},
|
|
1266
|
+
annotations: {
|
|
1267
|
+
readOnlyHint: false,
|
|
1268
|
+
destructiveHint: false,
|
|
1269
|
+
openWorldHint: true
|
|
1270
|
+
}
|
|
1271
|
+
}, ({ id, exercise }) => attempt(async () => jsonResult(await index.update(toId(id), exercise))));
|
|
1272
|
+
}
|
|
1273
|
+
function registerExerciseDelete(server, index) {
|
|
1274
|
+
server.registerTool("exercise_delete", {
|
|
1275
|
+
title: "Delete custom exercise",
|
|
1276
|
+
description: "Delete a custom exercise on TrainHeroic (DELETE /v5/exercises/{id}) and drop it from the local mirror. Only works for exercises with can_edit:1. Built-in library exercises cannot be deleted. Requires confirmation (elicitation, or confirm:true). exercise_forget only clears the cache — use this to delete the live exercise.",
|
|
1277
|
+
inputSchema: {
|
|
1278
|
+
id: idParam,
|
|
1279
|
+
confirm: z.boolean().optional()
|
|
1280
|
+
},
|
|
1281
|
+
annotations: DESTRUCTIVE
|
|
1282
|
+
}, ({ id, confirm }, extra) => attempt(async () => {
|
|
1283
|
+
const exerciseId = toId(id);
|
|
1284
|
+
const blocked = confirmGate(extra, `Delete custom exercise ${exerciseId} from the live TrainHeroic library?`, confirm);
|
|
1285
|
+
if (blocked) return blocked;
|
|
1286
|
+
await index.remove(exerciseId);
|
|
1287
|
+
return jsonResult({ deleted: exerciseId });
|
|
1288
|
+
}));
|
|
1289
|
+
}
|
|
1159
1290
|
/**
|
|
1160
1291
|
* Exercise library tools over the ExerciseIndex — a D1 mirror on the hosted server, an
|
|
1161
1292
|
* on-disk/in-memory cache locally. The descriptions stay at the interface level so they
|
|
@@ -1207,9 +1338,11 @@ function registerExerciseTools(server, ctx) {
|
|
|
1207
1338
|
openWorldHint: true
|
|
1208
1339
|
}
|
|
1209
1340
|
}, ({ exercise }) => attempt(async () => jsonResult(await index.create(exercise))));
|
|
1341
|
+
registerExerciseUpdate(server, index);
|
|
1342
|
+
registerExerciseDelete(server, index);
|
|
1210
1343
|
server.registerTool("exercise_forget", {
|
|
1211
1344
|
title: "Forget exercise (cache only)",
|
|
1212
|
-
description: "Remove an exercise from the local mirror only.
|
|
1345
|
+
description: "Remove an exercise from the local mirror only. Does not call TrainHeroic — use exercise_delete to delete the live custom exercise.",
|
|
1213
1346
|
inputSchema: { id: idParam },
|
|
1214
1347
|
annotations: {
|
|
1215
1348
|
readOnlyHint: false,
|
|
@@ -1383,11 +1516,41 @@ function registerLifecycle(server, ctx) {
|
|
|
1383
1516
|
}
|
|
1384
1517
|
}, ({ workoutId }) => apiCall(ctx, "POST", `/2.0/coach/calendar/programWorkout/saveWorkoutAsTemplate/${workoutId}`));
|
|
1385
1518
|
}
|
|
1519
|
+
function registerTemplateLibrary(server, ctx) {
|
|
1520
|
+
server.registerTool("session_template_create", {
|
|
1521
|
+
title: "Create a session template",
|
|
1522
|
+
description: "Create an empty reusable session template in the library (POST /v5/sessions/template). Distinct from session_save_as_template, which copies an existing session. Pass title and optional instruction.",
|
|
1523
|
+
inputSchema: sessionTemplateCreateSchema,
|
|
1524
|
+
annotations: {
|
|
1525
|
+
readOnlyHint: false,
|
|
1526
|
+
destructiveHint: false,
|
|
1527
|
+
openWorldHint: true
|
|
1528
|
+
}
|
|
1529
|
+
}, ({ title, instruction }) => attempt(async () => jsonResult(await createSessionTemplate(ctx.client, definedProps({
|
|
1530
|
+
title,
|
|
1531
|
+
instruction
|
|
1532
|
+
})))));
|
|
1533
|
+
server.registerTool("session_template_delete", {
|
|
1534
|
+
title: "Delete a session template",
|
|
1535
|
+
description: "Delete a library session template (DELETE /v5/sessions/template/{id}). Requires confirmation (elicitation, or confirm:true).",
|
|
1536
|
+
inputSchema: {
|
|
1537
|
+
id: idParam,
|
|
1538
|
+
confirm: z.boolean().optional()
|
|
1539
|
+
},
|
|
1540
|
+
annotations: DESTRUCTIVE
|
|
1541
|
+
}, ({ id, confirm }, extra) => attempt(async () => {
|
|
1542
|
+
const templateId = toId(id);
|
|
1543
|
+
const blocked = confirmGate(extra, `Delete session template ${templateId} from the library?`, confirm);
|
|
1544
|
+
if (blocked) return blocked;
|
|
1545
|
+
return apiCall(ctx, "DELETE", `/v5/sessions/template/${templateId}`);
|
|
1546
|
+
}));
|
|
1547
|
+
}
|
|
1386
1548
|
/** Workout building, read-back, publishing, and the session calendar lifecycle. */
|
|
1387
1549
|
function registerWorkoutTools(server, ctx) {
|
|
1388
1550
|
registerBuild(server, ctx);
|
|
1389
1551
|
registerReadPublish(server, ctx);
|
|
1390
1552
|
registerLifecycle(server, ctx);
|
|
1553
|
+
registerTemplateLibrary(server, ctx);
|
|
1391
1554
|
}
|
|
1392
1555
|
//#endregion
|
|
1393
1556
|
//#region src/tools/messaging.ts
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trainheroic-unofficial/core",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.2.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
"@cfworker/json-schema": "^4.1.1",
|
|
26
26
|
"@modelcontextprotocol/server": "2.0.0",
|
|
27
27
|
"zod": "^4.4.3",
|
|
28
|
-
"@trainheroic-unofficial/dto": "3.
|
|
29
|
-
"@trainheroic-unofficial/js": "3.
|
|
28
|
+
"@trainheroic-unofficial/dto": "3.2.0",
|
|
29
|
+
"@trainheroic-unofficial/js": "3.2.0"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@types/node": "^26.2.0",
|