@trainheroic-unofficial/core 3.5.1 → 3.6.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 +17 -36
- package/package.json +3 -3
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, 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
2
|
import { 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, 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, 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";
|
|
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;
|
|
@@ -77,12 +77,16 @@ function resultBudget() {
|
|
|
77
77
|
function isPlainObject(value) {
|
|
78
78
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
79
79
|
}
|
|
80
|
-
/**
|
|
81
|
-
|
|
80
|
+
/**
|
|
81
|
+
* Largest count k such that the JSON of the first k elements fits. Elements are serialized one
|
|
82
|
+
* at a time and the walk stops at the first overflow, so an oversized 10k-row result costs the
|
|
83
|
+
* serialization of the rows that fit, not of every row.
|
|
84
|
+
*/
|
|
85
|
+
function largestPrefixCount(elements, charBudget) {
|
|
82
86
|
let used = 2;
|
|
83
87
|
let k = 0;
|
|
84
|
-
for (const
|
|
85
|
-
const add =
|
|
88
|
+
for (const element of elements) {
|
|
89
|
+
const add = (JSON.stringify(element) ?? "null").length + (k > 0 ? 1 : 0);
|
|
86
90
|
if (used + add > charBudget) break;
|
|
87
91
|
used += add;
|
|
88
92
|
k += 1;
|
|
@@ -97,11 +101,12 @@ function hardCap(text, budget, hint) {
|
|
|
97
101
|
return text.slice(0, keep) + note;
|
|
98
102
|
}
|
|
99
103
|
function largestArrayValuedKey(obj) {
|
|
104
|
+
const arrayKeys = Object.keys(obj).filter((key) => Array.isArray(obj[key]));
|
|
105
|
+
if (arrayKeys.length <= 1) return arrayKeys[0] ?? null;
|
|
100
106
|
let best = null;
|
|
101
107
|
let bestLen = -1;
|
|
102
|
-
for (const
|
|
103
|
-
|
|
104
|
-
const len = (JSON.stringify(value) ?? "[]").length;
|
|
108
|
+
for (const key of arrayKeys) {
|
|
109
|
+
const len = (JSON.stringify(obj[key]) ?? "[]").length;
|
|
105
110
|
if (len > bestLen) {
|
|
106
111
|
best = key;
|
|
107
112
|
bestLen = len;
|
|
@@ -109,9 +114,6 @@ function largestArrayValuedKey(obj) {
|
|
|
109
114
|
}
|
|
110
115
|
return best;
|
|
111
116
|
}
|
|
112
|
-
function jsonValue(data) {
|
|
113
|
-
return JSON.parse(JSON.stringify(data) ?? "null");
|
|
114
|
-
}
|
|
115
117
|
function previewEnvelope(source, budget, hint) {
|
|
116
118
|
const total = source.length;
|
|
117
119
|
const makeValue = (preview, markerHint) => ({
|
|
@@ -138,8 +140,8 @@ function boundedResult(data, budget, hint) {
|
|
|
138
140
|
text: data,
|
|
139
141
|
value: data
|
|
140
142
|
};
|
|
141
|
-
const
|
|
142
|
-
const
|
|
143
|
+
const compact = JSON.stringify(data) ?? "null";
|
|
144
|
+
const value = JSON.parse(compact);
|
|
143
145
|
if (compact.length <= budget) {
|
|
144
146
|
const pretty = JSON.stringify(value, null, 2);
|
|
145
147
|
return {
|
|
@@ -148,7 +150,7 @@ function boundedResult(data, budget, hint) {
|
|
|
148
150
|
};
|
|
149
151
|
}
|
|
150
152
|
if (Array.isArray(value)) {
|
|
151
|
-
const truncated = clipArray(value, largestPrefixCount(value
|
|
153
|
+
const truncated = clipArray(value, largestPrefixCount(value, budget - MARKER_RESERVE), hint);
|
|
152
154
|
const text = JSON.stringify(truncated);
|
|
153
155
|
if (text.length <= budget) return {
|
|
154
156
|
text,
|
|
@@ -158,7 +160,7 @@ function boundedResult(data, budget, hint) {
|
|
|
158
160
|
const key = largestArrayValuedKey(value);
|
|
159
161
|
if (key !== null) {
|
|
160
162
|
const array = value[key];
|
|
161
|
-
const truncated = clipArray(array, largestPrefixCount(array
|
|
163
|
+
const truncated = clipArray(array, largestPrefixCount(array, budget - MARKER_RESERVE), hint ?? DEFAULT_OBJECT_HINT, key);
|
|
162
164
|
const text = JSON.stringify(truncated);
|
|
163
165
|
if (text.length <= budget) return {
|
|
164
166
|
text,
|
|
@@ -273,27 +275,6 @@ function confirmGate(ctx, message, confirmArg) {
|
|
|
273
275
|
*/
|
|
274
276
|
const SERVER_INSTRUCTIONS = "Speak to the user in plain, everyday language about their training. Describe what you are doing in the TrainHeroic app's own terms (for example, say you are creating a workout rather than naming a tool). Do not surface internal tool names (the snake_case identifiers such as athlete_session_create), raw parameter names, or numeric ids in your replies unless the user explicitly asks for them; they are implementation details. The tool descriptions cross-reference each other by name only so you can chain them correctly. Keep that wiring to yourself.";
|
|
275
277
|
//#endregion
|
|
276
|
-
//#region src/history.ts
|
|
277
|
-
/**
|
|
278
|
-
* Trim a presented exercise history's session time-series to an inclusive YYYY-MM-DD window.
|
|
279
|
-
* The `liftPRs` board stays all-time (PRs are not a windowed concept). Dates compare as their
|
|
280
|
-
* first 10 chars so both "YYYY-MM-DD" and "YYYY-MM-DDThh:mm" values filter correctly. Shared by
|
|
281
|
-
* the athlete's own history tool and the coach's per-roster-athlete history tool.
|
|
282
|
-
*/
|
|
283
|
-
function historyInRange(presented, since, until) {
|
|
284
|
-
if (since === void 0 && until === void 0) return presented;
|
|
285
|
-
const sessions = presented.sessions.filter((s) => {
|
|
286
|
-
const d = (s.date ?? "").slice(0, 10);
|
|
287
|
-
if (since !== void 0 && d < since) return false;
|
|
288
|
-
if (until !== void 0 && d > until) return false;
|
|
289
|
-
return true;
|
|
290
|
-
});
|
|
291
|
-
return {
|
|
292
|
-
...presented,
|
|
293
|
-
sessions
|
|
294
|
-
};
|
|
295
|
-
}
|
|
296
|
-
//#endregion
|
|
297
278
|
//#region src/tools/reads.ts
|
|
298
279
|
const ATHLETE_LIFT_HISTORY_DESC = "A roster athlete's lift history for ONE exercise: the all-time PR board (liftPRs — each entry carries its rep-max label, weight, and the date it was set) plus the dated session series (sets, estimated 1RM). This is the coach-side way to answer 'show me <athlete>'s PRs / how is <athlete>'s squat trending' — pass athleteId from list_athletes and exerciseId from exercise_resolve. There is no cross-exercise PR rollup, so you query one lift at a time, but do NOT guess lift names blindly: first call athlete_training for the month(s) of interest — it lists every exercise the athlete actually performed (with the exact exercise the program used, e.g. 'Clean & Jerk' not 'Clean') — then bring those exerciseIds here. An empty result means that lift was not logged. liftPRs stay all-time; pass since/until (YYYY-MM-DD, inclusive) to window the session series. raw:true returns the untouched API object.";
|
|
299
280
|
const ROSTER_ACTIVITY_DESC = "A coach's roster ranked by actual training recency: for each athleteId you pass (from list_athletes), the all-time sessionsCount, firstLoggedDate, lastLoggedDate, totalReps and totalVolume, sorted most-recently-active first. Use lastLoggedDate — the real training signal — NOT list_athletes' daysSinceLastLogin (app-login, not training) to answer 'who is my most recently active athlete' (the top row) or 'who is falling behind' (a stale or null lastLoggedDate, or low volume). A null lastLoggedDate means the athlete has never logged a session. This fans out one lookup per athlete, so for a large org pass only the athletes you care about. Then drill into a name with athlete_training (their month) or athlete_lift_history.";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trainheroic-unofficial/core",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.6.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.6.0",
|
|
29
|
+
"@trainheroic-unofficial/js": "3.6.0"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@types/node": "^26.3.0",
|