@trainheroic-unofficial/core 3.7.1 → 4.0.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 CHANGED
@@ -98,9 +98,9 @@ export declare const NOT_CONFIRMED = "Not confirmed — the user declined. Nothi
98
98
  * confirmation message ever needs data fetched first, that fetch must be idempotent.
99
99
  *
100
100
  * Written once in the 2026 `inputRequired` style: modern clients retry with `inputResponses`.
101
- * A client that cannot elicit at all never reaches the denial below — the SDK rejects the
102
- * request before the retry — so it must pass `confirm: true`, which is why the hint rides inside
103
- * the prompt text itself.
101
+ * MCP correctly rejects unsupported embedded requests with `-32021`. This application has an
102
+ * alternate `confirm: true` flow, so a modern client that does not declare form elicitation gets
103
+ * a model-readable tool error that tells it how to recover while the gate remains closed.
104
104
  */
105
105
  export declare function confirmGate(ctx: ServerContext, message: string, confirmArg: boolean | undefined): ToolHandlerResult | undefined;
106
106
  //#endregion
package/dist/index.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import { athleteExerciseCatalogOutputSchema, athleteExerciseNoteArgsSchema, athleteExerciseNoteOutputSchema, athleteInviteOutputSchema, athleteMainLiftPrsOutputSchema, athletePrefsSchema, athletePrescribeSetArgsSchema, athleteProfileOutputSchema, athleteSessionRemoveArgsSchema, athleteSessionRemovedOutputSchema, athleteWorkingMaxListSchema, athleteWorkoutNoteArgsSchema, athleteWorkoutNoteObject, athleteWorkoutNoteOutputSchema, athleteWorkoutsOutputSchema, blockSpecSchema, coachAthleteTrainingOutputSchema, coachLogSessionArgsSchema, coachLogSetArgsSchema, coachPrescribeSetArgsSchema, commentDraftSchema, dateString, exerciseCreateSchema, exerciseCreatedOutputSchema, exerciseDeletedOutputSchema, exerciseForgottenOutputSchema, exerciseGetOutputSchema, exerciseHistoryOutputSchema, exerciseResolveOutputSchema, exerciseStatsSchema, exerciseSwapOutputSchema, exerciseUpdateSchema, exerciseViewSchema, idArgSchema, logSessionArgsSchema, logSetArgsSchema, logTargetsOutputSchema, messageDeletedOutputSchema, messageDraftOutputSchema, messageSentOutputSchema, opaqueOutputSchema, parseWorkoutDate, personalRecordListSchema, personalWorkoutCreatedOutputSchema, programCreatedOutputSchema, programDeletedOutputSchema, removedSessionOutputSchema, rosterActivityOutputSchema, sessionLogOutputSchema, sessionTemplateCreateSchema, sessionTemplateCreatedOutputSchema, setLogOutputSchema, setPrescriptionOutputSchema, swapAthleteExerciseArgsSchema, teamPublishPatchObject, teamPublishPatchSchema, teamVolumeOutputSchema, toolOutputSchema, userSimpleSchema, workoutBuildOutputSchema, workoutPublishOutputSchema, workoutReadOutputSchema } from "@trainheroic-unofficial/dto";
2
- import { acceptedContent, inputRequired, inputResponse } from "@modelcontextprotocol/server";
2
+ import { CLIENT_CAPABILITIES_META_KEY, acceptedContent, inputRequired, inputResponse } from "@modelcontextprotocol/server";
3
3
  import { z } from "zod";
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, historyInRange, inviteAthletes, isRecord, logAdHocSession, logAthleteSet, logForAthlete, logSessionForAthlete, prescribeAthleteSet, prescribeForAthlete, presentAthleteWorkouts, presentCoachAthleteTraining, presentExerciseHistory, presentLogTargets, publishSession, queryAnalytics, readLive, readSession, removePersonalWorkout, removeSession, resolveBuildProgramId, searchExerciseHistory, selectWorkouts, selectWorkoutsByProgram, sendComment, setAthleteExerciseNote, setAthleteWorkoutNote, setSplitSummary, summarizeAthleteWorkouts, swapAthleteExercise, teamPublishTarget, teamVolume, toSetResults, updateTeam, updateTeamPublishSettings } from "@trainheroic-unofficial/js";
4
+ import { ANALYTICS_METRIC_KEYS, PROGRAM_KINDS, SESSION_TEMPLATES_LIST_PATH, addExercisesToWorkout, buildCommentPayload, buildSession, coerceInt, 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, historyInRange, inviteAthletes, isRecord, logAdHocSession, logAthleteSet, logForAthlete, logSessionForAthlete, prescribeAthleteSet, prescribeForAthlete, presentAthleteWorkouts, presentCoachAthleteTraining, presentExerciseHistory, presentLogTargets, publishSession, queryAnalytics, readLive, readSession, removePersonalWorkout, removeSession, resolveBuildProgramId, searchExerciseHistory, selectWorkouts, selectWorkoutsByProgram, sendComment, setAthleteExerciseNote, setAthleteWorkoutNote, setSplitSummary, 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;
@@ -226,6 +226,15 @@ async function apiCall(ctx, method, path, options, hint) {
226
226
  const NOT_CONFIRMED = "Not confirmed — the user declined. Nothing was changed.";
227
227
  /** Appended to the prompt so the fallback survives whichever way a client surfaces the request. */
228
228
  const FALLBACK_HINT = " (If you cannot show this prompt, re-run the tool with confirm:true once the user has agreed.)";
229
+ const CONFIRMATION_REQUIRED = "Ask the user to approve this action, then retry the tool with confirm:true only after they agree. Nothing was changed.";
230
+ /** `undefined` means a legacy request, whose capability check belongs to the SDK's shim. */
231
+ function modernClientSupportsFormElicitation(ctx) {
232
+ const envelope = ctx.mcpReq.envelope;
233
+ if (envelope === void 0) return void 0;
234
+ const elicitation = envelope[CLIENT_CAPABILITIES_META_KEY]?.elicitation;
235
+ if (elicitation === void 0) return false;
236
+ return elicitation.form !== void 0 || elicitation.url === void 0;
237
+ }
229
238
  /**
230
239
  * Confirm a destructive/athlete-facing action.
231
240
  *
@@ -241,14 +250,15 @@ const FALLBACK_HINT = " (If you cannot show this prompt, re-run the tool with co
241
250
  * confirmation message ever needs data fetched first, that fetch must be idempotent.
242
251
  *
243
252
  * Written once in the 2026 `inputRequired` style: modern clients retry with `inputResponses`.
244
- * A client that cannot elicit at all never reaches the denial below — the SDK rejects the
245
- * request before the retry — so it must pass `confirm: true`, which is why the hint rides inside
246
- * the prompt text itself.
253
+ * MCP correctly rejects unsupported embedded requests with `-32021`. This application has an
254
+ * alternate `confirm: true` flow, so a modern client that does not declare form elicitation gets
255
+ * a model-readable tool error that tells it how to recover while the gate remains closed.
247
256
  */
248
257
  function confirmGate(ctx, message, confirmArg) {
249
258
  if (confirmArg === true) return void 0;
250
259
  if (acceptedContent(ctx.mcpReq.inputResponses, "confirm")?.confirm === true) return void 0;
251
260
  if (inputResponse(ctx.mcpReq.inputResponses, "confirm").kind !== "missing") return errorResult(NOT_CONFIRMED);
261
+ if (modernClientSupportsFormElicitation(ctx) === false) return errorResult(`${message} ${CONFIRMATION_REQUIRED}`);
252
262
  const prompt = message + FALLBACK_HINT;
253
263
  return inputRequired({ inputRequests: { confirm: inputRequired.elicit({
254
264
  message: prompt,
@@ -1479,7 +1489,7 @@ function registerExerciseTools(server, ctx) {
1479
1489
  function registerBuild(server, ctx) {
1480
1490
  server.registerTool("workout_build", {
1481
1491
  title: "Build a workout session (draft)",
1482
- 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. Exercises above 10 sets are split into consecutive same-titled blocks and require confirmation (elicitation, or confirm:true). Review, then workout_publish.",
1492
+ 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 and a read-back. For each exercise, state primaryUnit when reps is present and secondaryUnit when weight is present; these are positional values, even when the unit is distance or time. Use exercise_resolve to check the exercise's fixed units before building. A mismatch fails before the draft is created. Exercises above 10 sets are split into consecutive same-titled blocks and require confirmation (elicitation, or confirm:true). Review, then workout_publish.",
1483
1493
  inputSchema: {
1484
1494
  programId: z.number().optional(),
1485
1495
  athleteId: idParam.optional(),
@@ -1507,20 +1517,19 @@ function registerBuild(server, ctx) {
1507
1517
  const opts = {
1508
1518
  programId: resolved,
1509
1519
  blocks: typed,
1520
+ index: ctx.index,
1510
1521
  publish: false
1511
1522
  };
1512
1523
  if (splitSummary !== null) opts.confirmSetSplit = true;
1513
1524
  if (date !== void 0) opts.date = parseWorkoutDate(date);
1514
1525
  if (timelineDay !== void 0) opts.timelineDay = timelineDay;
1515
1526
  if (instruction !== void 0) opts.instruction = instruction;
1516
- const advisories = await collectAdvisories(typed, ctx.index);
1517
1527
  const built = await buildSession(ctx.client, opts);
1518
1528
  const readback = opts.date ? await readSession(ctx.client, resolved, opts.date, built.pwId) : null;
1519
1529
  return jsonResult({
1520
1530
  ...built,
1521
1531
  programId: resolved,
1522
1532
  published: false,
1523
- advisories,
1524
1533
  readback,
1525
1534
  note: "Draft created (unpublished). Review, then call workout_publish to make it athlete-facing."
1526
1535
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trainheroic-unofficial/core",
3
- "version": "3.7.1",
3
+ "version": "4.0.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.6.3",
28
- "@trainheroic-unofficial/dto": "3.7.1",
29
- "@trainheroic-unofficial/js": "3.7.1"
28
+ "@trainheroic-unofficial/dto": "4.0.0",
29
+ "@trainheroic-unofficial/js": "4.0.0"
30
30
  },
31
31
  "devDependencies": {
32
32
  "@types/node": "^26.5.1",