@trainheroic-unofficial/core 3.1.0 → 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.d.mts +8 -2
- package/dist/index.mjs +225 -17
- package/package.json +3 -3
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CallToolResult, InputRequiredResult, McpServer, ServerContext } from "@modelcontextprotocol/server";
|
|
2
|
-
import { ExerciseIndex, RequestOptions, SessionExercise, TrainHeroicClient } from "@trainheroic-unofficial/js";
|
|
2
|
+
import { ClientResult, ExerciseIndex, RequestOptions, SessionExercise, TrainHeroicClient } from "@trainheroic-unofficial/js";
|
|
3
3
|
//#region src/context.d.ts
|
|
4
4
|
/** What a tool handler may return: a finished result or an MRTR input round. */
|
|
5
5
|
type ToolHandlerResult = CallToolResult | InputRequiredResult;
|
|
@@ -66,6 +66,8 @@ type BudgetHint = {
|
|
|
66
66
|
declare function jsonResult(data: unknown, opts?: BudgetHint): CallToolResult;
|
|
67
67
|
/** A tool-level error: returned in-band (isError) so the model can self-correct. */
|
|
68
68
|
declare function errorResult(message: string): CallToolResult;
|
|
69
|
+
/** Format an already-issued TrainHeroic response as a size-bounded tool result. */
|
|
70
|
+
declare function apiResponseResult(res: ClientResult, hint?: string): CallToolResult;
|
|
69
71
|
/** Issue a TrainHeroic request and format the outcome as a tool result. */
|
|
70
72
|
declare function apiCall(ctx: ToolContext, method: string, path: string, options?: RequestOptions, hint?: string): Promise<CallToolResult>;
|
|
71
73
|
//#endregion
|
|
@@ -157,6 +159,10 @@ declare function registerAthleteTools(server: McpServer, ctx: ToolContext): void
|
|
|
157
159
|
*/
|
|
158
160
|
declare function registerTeamTools(server: McpServer, ctx: ToolContext): void;
|
|
159
161
|
//#endregion
|
|
162
|
+
//#region src/tools/programs.d.ts
|
|
163
|
+
/** Standalone program writes. Program reads live in reads.ts. */
|
|
164
|
+
declare function registerProgramTools(server: McpServer, ctx: ToolContext): void;
|
|
165
|
+
//#endregion
|
|
160
166
|
//#region src/tools/analytics.d.ts
|
|
161
167
|
/** Analytics report pulls. Read-only despite the POST verb, so ungated. */
|
|
162
168
|
declare function registerAnalyticsTools(server: McpServer, ctx: ToolContext): void;
|
|
@@ -181,4 +187,4 @@ declare function registerMessagingTools(server: McpServer, ctx: ToolContext): vo
|
|
|
181
187
|
/** Register the full coach tool surface (roster, teams, programs, exercises, messaging). */
|
|
182
188
|
declare function registerCoachTools(server: McpServer, ctx: ToolContext): void;
|
|
183
189
|
//#endregion
|
|
184
|
-
export { AthleteContext, BudgetHint, DEFAULT_RESULT_BUDGET, DESTRUCTIVE, NOT_CONFIRMED, READ, SERVER_INSTRUCTIONS, SYNC, ToolContext, ToolHandlerResult, apiCall, attempt, boundedSerialize, clipArray, confirmGate, errorResult, idParam, jsonResult, mapSessionExercises, registerAnalyticsTools, registerAthleteTools, registerAthleteTrainingTools, registerCoachTools, registerExerciseTools, registerMainLiftTools, registerMessagingTools, registerReadTools, registerTeamTools, registerWorkoutTools, resultBudget, toId };
|
|
190
|
+
export { AthleteContext, BudgetHint, DEFAULT_RESULT_BUDGET, DESTRUCTIVE, NOT_CONFIRMED, READ, SERVER_INSTRUCTIONS, SYNC, ToolContext, ToolHandlerResult, apiCall, apiResponseResult, attempt, boundedSerialize, clipArray, confirmGate, errorResult, idParam, jsonResult, mapSessionExercises, registerAnalyticsTools, registerAthleteTools, registerAthleteTrainingTools, registerCoachTools, registerExerciseTools, registerMainLiftTools, registerMessagingTools, registerProgramTools, registerReadTools, registerTeamTools, registerWorkoutTools, resultBudget, toId };
|
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, 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, 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;
|
|
@@ -160,15 +160,18 @@ function errorResult(message) {
|
|
|
160
160
|
}]
|
|
161
161
|
};
|
|
162
162
|
}
|
|
163
|
+
/** Format an already-issued TrainHeroic response as a size-bounded tool result. */
|
|
164
|
+
function apiResponseResult(res, hint) {
|
|
165
|
+
if (!res.ok) {
|
|
166
|
+
const detail = hardCap(typeof res.data === "string" ? res.data : JSON.stringify(res.data) ?? "", resultBudget());
|
|
167
|
+
return errorResult(`TrainHeroic API error (HTTP ${res.status}): ${detail}`);
|
|
168
|
+
}
|
|
169
|
+
return jsonResult(res.data, { hint });
|
|
170
|
+
}
|
|
163
171
|
/** Issue a TrainHeroic request and format the outcome as a tool result. */
|
|
164
172
|
async function apiCall(ctx, method, path, options, hint) {
|
|
165
173
|
return attempt(async () => {
|
|
166
|
-
|
|
167
|
-
if (!res.ok) {
|
|
168
|
-
const detail = hardCap(typeof res.data === "string" ? res.data : JSON.stringify(res.data) ?? "", resultBudget());
|
|
169
|
-
return errorResult(`TrainHeroic API error (HTTP ${res.status}): ${detail}`);
|
|
170
|
-
}
|
|
171
|
-
return jsonResult(res.data, { hint });
|
|
174
|
+
return apiResponseResult(await ctx.client.request(method, path, options), hint);
|
|
172
175
|
});
|
|
173
176
|
}
|
|
174
177
|
//#endregion
|
|
@@ -275,7 +278,7 @@ const SIMPLE_GETS = [
|
|
|
275
278
|
{
|
|
276
279
|
name: "list_programs",
|
|
277
280
|
title: "List programs",
|
|
278
|
-
description: "Coach programs (standalone only). This is often empty even for an active coach, because most programming lives as a team's group-program: if it returns [], call list_teams and read each team's group_program — do not conclude the coach has no programs.",
|
|
281
|
+
description: "Coach programs (standalone only). This is often empty even for an active coach, because most programming lives as a team's group-program: if it returns [], call list_teams and read each team's group_program — do not conclude the coach has no programs. Each standalone row has two ids: id is its container/calendar id; group_program is the underlying program id used by workout writes. get_program accepts either one.",
|
|
279
282
|
path: "/1.0/coach/programs"
|
|
280
283
|
},
|
|
281
284
|
{
|
|
@@ -284,11 +287,35 @@ const SIMPLE_GETS = [
|
|
|
284
287
|
description: "Unread counts including countMessagingNotViewed (cheap 'anything new?' poll).",
|
|
285
288
|
path: "/v5/notifications/counts"
|
|
286
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
|
+
},
|
|
287
308
|
{
|
|
288
309
|
name: "analytics_categories",
|
|
289
310
|
title: "Analytics categories",
|
|
290
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.",
|
|
291
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
|
|
292
319
|
}
|
|
293
320
|
];
|
|
294
321
|
/** Roster-level reads: the fixed GETs plus the filterable athlete and team lists. */
|
|
@@ -403,10 +430,29 @@ function registerEntityReads(server, ctx) {
|
|
|
403
430
|
}));
|
|
404
431
|
server.registerTool("get_program", {
|
|
405
432
|
title: "Get program detail",
|
|
406
|
-
description: "
|
|
433
|
+
description: "Program detail live from the API, by program id. Works for team calendars and athlete coach calendars (type 5 from /v5/calendars/athletes/{id}). For standalone rows from list_programs, accepts either id (the container id) or group_program (the underlying program id); container ids are resolved automatically. If neither detail endpoint is available, returns calendar metadata and next-step guidance instead.",
|
|
407
434
|
inputSchema: { programId: idParam },
|
|
408
435
|
annotations: READ
|
|
409
|
-
}, ({ programId }) =>
|
|
436
|
+
}, ({ programId }) => getProgram(ctx, toId(programId)));
|
|
437
|
+
}
|
|
438
|
+
async function getProgram(ctx, programId) {
|
|
439
|
+
return attempt(async () => {
|
|
440
|
+
const detail = await ctx.client.request("GET", `/3.0/coach/program/${enc(programId)}`, { expectedStatuses: [401, 403] });
|
|
441
|
+
if (detail.ok || detail.status !== 401 && detail.status !== 403) return apiResponseResult(detail, "This is a large, deep object. If it is truncated, fetch a narrower view (a specific session) instead.");
|
|
442
|
+
const programs = await ctx.client.request("GET", "/1.0/coach/programs");
|
|
443
|
+
const program = Array.isArray(programs.data) ? programs.data.find((item) => isRecord(item) && coerceInt(item.id) === programId) : void 0;
|
|
444
|
+
if (!programs.ok || !program) return apiResponseResult(detail);
|
|
445
|
+
const actualProgramId = coerceInt(program.group_program);
|
|
446
|
+
if (actualProgramId !== null && actualProgramId !== programId) {
|
|
447
|
+
const actualDetail = await ctx.client.request("GET", `/3.0/coach/program/${enc(actualProgramId)}`, { expectedStatuses: [401, 403] });
|
|
448
|
+
if (actualDetail.ok || actualDetail.status !== 401 && actualDetail.status !== 403) return apiResponseResult(actualDetail, "This is a large, deep object. If it is truncated, fetch a narrower view (a specific session) instead.");
|
|
449
|
+
}
|
|
450
|
+
return jsonResult({
|
|
451
|
+
program,
|
|
452
|
+
detailAvailable: false,
|
|
453
|
+
note: "TrainHeroic recognizes this as a valid standalone calendar, but its nested program-detail endpoint does not expose this calendar type. Use calendar/session reads instead; on the hosted server, programming_sync then programming_stored can read its dated sessions."
|
|
454
|
+
});
|
|
455
|
+
});
|
|
410
456
|
}
|
|
411
457
|
/** Read-only coach/athlete queries. Exercise lookups live in the exercise store tools. */
|
|
412
458
|
/** The windowed team-volume read — its own function so registerEntityReads stays under the cap. */
|
|
@@ -433,9 +479,18 @@ function registerTeamVolume(server, ctx) {
|
|
|
433
479
|
}
|
|
434
480
|
function registerReadTools(server, ctx) {
|
|
435
481
|
registerRosterReads(server, ctx);
|
|
482
|
+
registerCoachAthleteTeamCalendar(server, ctx);
|
|
436
483
|
registerEntityReads(server, ctx);
|
|
437
484
|
registerTeamVolume(server, ctx);
|
|
438
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
|
+
}
|
|
439
494
|
//#endregion
|
|
440
495
|
//#region src/tools/main-lifts.ts
|
|
441
496
|
const monthsParam = z.number().int().positive().max(36).optional();
|
|
@@ -791,6 +846,26 @@ function registerSwapTool(server, ctx) {
|
|
|
791
846
|
}));
|
|
792
847
|
}));
|
|
793
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
|
+
}
|
|
794
869
|
/**
|
|
795
870
|
* Live tools over the logged-in user's own training (history, scheduled/completed workouts,
|
|
796
871
|
* PRs, working maxes), plus a gated set-logging write. The athlete user id is
|
|
@@ -813,6 +888,7 @@ function registerAthleteTrainingTools(server, ctx) {
|
|
|
813
888
|
};
|
|
814
889
|
registerProfileTools(server, ctx, whoami, userId);
|
|
815
890
|
registerExerciseTools$1(server, ctx, userId);
|
|
891
|
+
registerCatalogReads(server, ctx);
|
|
816
892
|
registerLogTargetsTool(server, ctx);
|
|
817
893
|
registerSessionTools(server, ctx);
|
|
818
894
|
registerLogTool(server, ctx);
|
|
@@ -1011,7 +1087,7 @@ function registerAthletePrescribeTool(server, ctx) {
|
|
|
1011
1087
|
}
|
|
1012
1088
|
//#endregion
|
|
1013
1089
|
//#region src/tools/teams.ts
|
|
1014
|
-
const ADDITIVE = {
|
|
1090
|
+
const ADDITIVE$1 = {
|
|
1015
1091
|
readOnlyHint: false,
|
|
1016
1092
|
destructiveHint: false,
|
|
1017
1093
|
openWorldHint: true
|
|
@@ -1025,7 +1101,7 @@ function registerTeamTools(server, ctx) {
|
|
|
1025
1101
|
title: "Create a team",
|
|
1026
1102
|
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.",
|
|
1027
1103
|
inputSchema: { title: z.string().min(1) },
|
|
1028
|
-
annotations: ADDITIVE
|
|
1104
|
+
annotations: ADDITIVE$1
|
|
1029
1105
|
}, ({ title }) => apiCall(ctx, "POST", "/1.0/coach/team/createWithTitleAndCode", { body: { title } }));
|
|
1030
1106
|
server.registerTool("team_update", {
|
|
1031
1107
|
title: "Update a team",
|
|
@@ -1035,7 +1111,7 @@ function registerTeamTools(server, ctx) {
|
|
|
1035
1111
|
title: z.string().min(1).optional(),
|
|
1036
1112
|
groupProgram: idParam.optional()
|
|
1037
1113
|
},
|
|
1038
|
-
annotations: ADDITIVE
|
|
1114
|
+
annotations: ADDITIVE$1
|
|
1039
1115
|
}, ({ teamId, title, groupProgram }) => attempt(async () => {
|
|
1040
1116
|
const args = { teamId: toId(teamId) };
|
|
1041
1117
|
if (title !== void 0) args.title = title;
|
|
@@ -1063,7 +1139,7 @@ function registerTeamTools(server, ctx) {
|
|
|
1063
1139
|
teamId: idParam,
|
|
1064
1140
|
type: z.number().int().optional()
|
|
1065
1141
|
},
|
|
1066
|
-
annotations: ADDITIVE
|
|
1142
|
+
annotations: ADDITIVE$1
|
|
1067
1143
|
}, ({ teamId, type }) => apiCall(ctx, "POST", `/v5/teams/${toId(teamId)}/teamCodes`, { body: { type: type ?? 2 } }));
|
|
1068
1144
|
server.registerTool("team_code_delete", {
|
|
1069
1145
|
title: "Delete a team join code",
|
|
@@ -1079,6 +1155,73 @@ function registerTeamTools(server, ctx) {
|
|
|
1079
1155
|
if (blocked) return blocked;
|
|
1080
1156
|
return apiCall(ctx, "DELETE", `/v5/teamCodes/${id}`);
|
|
1081
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
|
+
}));
|
|
1189
|
+
}
|
|
1190
|
+
//#endregion
|
|
1191
|
+
//#region src/tools/programs.ts
|
|
1192
|
+
const ADDITIVE = {
|
|
1193
|
+
readOnlyHint: false,
|
|
1194
|
+
destructiveHint: false,
|
|
1195
|
+
openWorldHint: true
|
|
1196
|
+
};
|
|
1197
|
+
/** Standalone program writes. Program reads live in reads.ts. */
|
|
1198
|
+
function registerProgramTools(server, ctx) {
|
|
1199
|
+
server.registerTool("program_create", {
|
|
1200
|
+
title: "Create a standalone program",
|
|
1201
|
+
description: "Create either an ongoing calendar or a fixed-length standalone program (POST /1.0/coach/programs/create). Returns both containerId (the id shown by list_programs and used by calendar edit/sync reads) and programId (the id used by get_program and workout writes). TrainHeroic may generate a different title; inspect title and nameApplied. This write is not idempotent, so do not retry an uncertain result.",
|
|
1202
|
+
inputSchema: {
|
|
1203
|
+
kind: z.enum(PROGRAM_KINDS),
|
|
1204
|
+
name: z.string().trim().min(1)
|
|
1205
|
+
},
|
|
1206
|
+
annotations: ADDITIVE
|
|
1207
|
+
}, ({ kind, name }) => attempt(async () => jsonResult(await createProgram(ctx.client, {
|
|
1208
|
+
kind,
|
|
1209
|
+
name
|
|
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
|
+
}));
|
|
1082
1225
|
}
|
|
1083
1226
|
//#endregion
|
|
1084
1227
|
//#region src/tools/analytics.ts
|
|
@@ -1112,6 +1255,38 @@ function registerAnalyticsTools(server, ctx) {
|
|
|
1112
1255
|
}
|
|
1113
1256
|
//#endregion
|
|
1114
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
|
+
}
|
|
1115
1290
|
/**
|
|
1116
1291
|
* Exercise library tools over the ExerciseIndex — a D1 mirror on the hosted server, an
|
|
1117
1292
|
* on-disk/in-memory cache locally. The descriptions stay at the interface level so they
|
|
@@ -1163,9 +1338,11 @@ function registerExerciseTools(server, ctx) {
|
|
|
1163
1338
|
openWorldHint: true
|
|
1164
1339
|
}
|
|
1165
1340
|
}, ({ exercise }) => attempt(async () => jsonResult(await index.create(exercise))));
|
|
1341
|
+
registerExerciseUpdate(server, index);
|
|
1342
|
+
registerExerciseDelete(server, index);
|
|
1166
1343
|
server.registerTool("exercise_forget", {
|
|
1167
1344
|
title: "Forget exercise (cache only)",
|
|
1168
|
-
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.",
|
|
1169
1346
|
inputSchema: { id: idParam },
|
|
1170
1347
|
annotations: {
|
|
1171
1348
|
readOnlyHint: false,
|
|
@@ -1339,11 +1516,41 @@ function registerLifecycle(server, ctx) {
|
|
|
1339
1516
|
}
|
|
1340
1517
|
}, ({ workoutId }) => apiCall(ctx, "POST", `/2.0/coach/calendar/programWorkout/saveWorkoutAsTemplate/${workoutId}`));
|
|
1341
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
|
+
}
|
|
1342
1548
|
/** Workout building, read-back, publishing, and the session calendar lifecycle. */
|
|
1343
1549
|
function registerWorkoutTools(server, ctx) {
|
|
1344
1550
|
registerBuild(server, ctx);
|
|
1345
1551
|
registerReadPublish(server, ctx);
|
|
1346
1552
|
registerLifecycle(server, ctx);
|
|
1553
|
+
registerTemplateLibrary(server, ctx);
|
|
1347
1554
|
}
|
|
1348
1555
|
//#endregion
|
|
1349
1556
|
//#region src/tools/messaging.ts
|
|
@@ -1436,10 +1643,11 @@ function registerCoachTools(server, ctx) {
|
|
|
1436
1643
|
registerMainLiftTools(server, ctx);
|
|
1437
1644
|
registerAthleteTools(server, ctx);
|
|
1438
1645
|
registerTeamTools(server, ctx);
|
|
1646
|
+
registerProgramTools(server, ctx);
|
|
1439
1647
|
registerAnalyticsTools(server, ctx);
|
|
1440
1648
|
registerExerciseTools(server, ctx);
|
|
1441
1649
|
registerWorkoutTools(server, ctx);
|
|
1442
1650
|
registerMessagingTools(server, ctx);
|
|
1443
1651
|
}
|
|
1444
1652
|
//#endregion
|
|
1445
|
-
export { DEFAULT_RESULT_BUDGET, DESTRUCTIVE, NOT_CONFIRMED, READ, SERVER_INSTRUCTIONS, SYNC, apiCall, attempt, boundedSerialize, clipArray, confirmGate, errorResult, idParam, jsonResult, mapSessionExercises, registerAnalyticsTools, registerAthleteTools, registerAthleteTrainingTools, registerCoachTools, registerExerciseTools, registerMainLiftTools, registerMessagingTools, registerReadTools, registerTeamTools, registerWorkoutTools, resultBudget, toId };
|
|
1653
|
+
export { DEFAULT_RESULT_BUDGET, DESTRUCTIVE, NOT_CONFIRMED, READ, SERVER_INSTRUCTIONS, SYNC, apiCall, apiResponseResult, attempt, boundedSerialize, clipArray, confirmGate, errorResult, idParam, jsonResult, mapSessionExercises, registerAnalyticsTools, registerAthleteTools, registerAthleteTrainingTools, registerCoachTools, registerExerciseTools, registerMainLiftTools, registerMessagingTools, registerProgramTools, registerReadTools, registerTeamTools, registerWorkoutTools, resultBudget, toId };
|
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",
|