@trainheroic-unofficial/core 0.3.0 → 0.4.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.d.mts +17 -1
- package/dist/index.mjs +255 -59
- package/package.json +3 -3
package/dist/index.d.mts
CHANGED
|
@@ -63,6 +63,22 @@ declare function confirmGate(server: McpServer, requestId: string | number | und
|
|
|
63
63
|
/** Read-only coach/athlete queries. Exercise lookups live in the exercise store tools. */
|
|
64
64
|
declare function registerReadTools(server: McpServer, ctx: ToolContext): void;
|
|
65
65
|
//#endregion
|
|
66
|
+
//#region src/tools/athlete-training.d.ts
|
|
67
|
+
/**
|
|
68
|
+
* Athlete tools need only the client (no exercise-library index), so they take a narrower
|
|
69
|
+
* context than the coach tools. A full `ToolContext` also satisfies this, so the same ctx
|
|
70
|
+
* object can be passed.
|
|
71
|
+
*/
|
|
72
|
+
type AthleteContext = {
|
|
73
|
+
client: TrainHeroicClient;
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* Live tools over the logged-in user's own training (history, scheduled/completed workouts,
|
|
77
|
+
* PRs, working maxes), plus a gated set-logging write. The athlete user id is
|
|
78
|
+
* resolved once from /user/simple and reused across tools.
|
|
79
|
+
*/
|
|
80
|
+
declare function registerAthleteTrainingTools(server: McpServer, ctx: AthleteContext): void;
|
|
81
|
+
//#endregion
|
|
66
82
|
//#region src/tools/athletes.d.ts
|
|
67
83
|
/**
|
|
68
84
|
* Athlete management. TrainHeroic has no "create athlete" primitive: a coach invites a
|
|
@@ -100,4 +116,4 @@ declare function registerWorkoutTools(server: McpServer, ctx: ToolContext): void
|
|
|
100
116
|
/** Live messaging: list/read conversations, draft a message, and the gated send/delete. */
|
|
101
117
|
declare function registerMessagingTools(server: McpServer, ctx: ToolContext): void;
|
|
102
118
|
//#endregion
|
|
103
|
-
export { BudgetHint, DEFAULT_RESULT_BUDGET, DESTRUCTIVE, NOT_CONFIRMED, READ, SYNC, ToolContext, apiCall, attempt, boundedSerialize, confirmGate, errorResult, idParam, jsonResult, registerAnalyticsTools, registerAthleteTools, registerExerciseTools, registerMessagingTools, registerReadTools, registerTeamTools, registerWorkoutTools, resultBudget, toId };
|
|
119
|
+
export { AthleteContext, BudgetHint, DEFAULT_RESULT_BUDGET, DESTRUCTIVE, NOT_CONFIRMED, READ, SYNC, ToolContext, apiCall, attempt, boundedSerialize, confirmGate, errorResult, idParam, jsonResult, registerAnalyticsTools, registerAthleteTools, registerAthleteTrainingTools, registerExerciseTools, registerMessagingTools, registerReadTools, registerTeamTools, registerWorkoutTools, resultBudget, toId };
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { blockSpecSchema, commentDraftSchema, exerciseCreateSchema, idArgSchema, parseWorkoutDate } from "@trainheroic-unofficial/dto";
|
|
1
|
+
import { blockSpecSchema, commentDraftSchema, dateString, exerciseCreateSchema, idArgSchema, logSetArgsSchema, parseWorkoutDate } from "@trainheroic-unofficial/dto";
|
|
2
2
|
import { z } from "zod";
|
|
3
|
-
import { buildCommentPayload, buildSession, collectAdvisories, deleteComment, fetchStreams, publishSession, readLive, readSession, removeSession, sendComment } from "@trainheroic-unofficial/js";
|
|
3
|
+
import { addExercisesToWorkout, buildCommentPayload, buildSession, coerceInt, collectAdvisories, createPersonalWorkout, deleteComment, exerciseUnits, fetchAthletePrefs, fetchAthleteProfileSummary, fetchAthleteUser, fetchAthleteWorkouts, fetchExerciseHistoryDetail, fetchExerciseHistoryList, fetchExerciseStats, fetchLeaderboard, fetchPersonalRecords, fetchStreams, fetchWorkingMaxes, isRecord, logAthleteSet, presentAthleteWorkouts, presentExerciseHistory, publishSession, readLive, readSession, removeSession, searchExerciseHistory, sendComment } from "@trainheroic-unofficial/js";
|
|
4
4
|
//#region src/context.ts
|
|
5
5
|
/** A tool argument that accepts a numeric id as a number or a string of digits. */
|
|
6
6
|
const idParam = idArgSchema;
|
|
@@ -300,42 +300,211 @@ function registerEntityReads(server, ctx) {
|
|
|
300
300
|
inputSchema: { programId: idParam },
|
|
301
301
|
annotations: READ
|
|
302
302
|
}, ({ 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."));
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
303
|
+
}
|
|
304
|
+
/** Read-only coach/athlete queries. Exercise lookups live in the exercise store tools. */
|
|
305
|
+
function registerReadTools(server, ctx) {
|
|
306
|
+
registerRosterReads(server, ctx);
|
|
307
|
+
registerEntityReads(server, ctx);
|
|
308
|
+
}
|
|
309
|
+
//#endregion
|
|
310
|
+
//#region src/tools/athlete-training.ts
|
|
311
|
+
/** Identity, profile, prefs, working maxes, leaderboard. */
|
|
312
|
+
function registerProfileTools(server, ctx, whoami, userId) {
|
|
313
|
+
server.registerTool("athlete_whoami", {
|
|
314
|
+
title: "Who am I (athlete)",
|
|
315
|
+
description: "The logged-in account's identity (id, name, roles) from /user/simple.",
|
|
316
|
+
inputSchema: {},
|
|
317
|
+
annotations: READ
|
|
318
|
+
}, () => attempt(async () => jsonResult(await whoami())));
|
|
319
|
+
server.registerTool("athlete_profile", {
|
|
320
|
+
title: "Athlete profile + lifetime totals",
|
|
321
|
+
description: "Lifetime training totals (reps, volume, sessions, first/last logged) plus the profile (name, units, dob). Set useMetric for kg/metric totals.",
|
|
322
|
+
inputSchema: { useMetric: z.boolean().optional() },
|
|
323
|
+
annotations: READ
|
|
324
|
+
}, ({ useMetric }) => attempt(async () => {
|
|
325
|
+
const id = await userId();
|
|
326
|
+
const [summary, user] = await Promise.all([fetchAthleteProfileSummary(ctx.client, id, useMetric ?? false), fetchAthleteUser(ctx.client, id)]);
|
|
327
|
+
return jsonResult({
|
|
328
|
+
summary,
|
|
329
|
+
user
|
|
330
|
+
});
|
|
331
|
+
}));
|
|
332
|
+
server.registerTool("athlete_prefs", {
|
|
333
|
+
title: "Athlete preferences",
|
|
334
|
+
description: "Notification and display preference flags for the athlete account.",
|
|
335
|
+
inputSchema: {},
|
|
336
|
+
annotations: READ
|
|
337
|
+
}, () => attempt(async () => jsonResult(await fetchAthletePrefs(ctx.client))));
|
|
338
|
+
server.registerTool("athlete_working_maxes", {
|
|
339
|
+
title: "Working maxes",
|
|
340
|
+
description: "The athlete's working max per exercise (drives % prescriptions).",
|
|
341
|
+
inputSchema: {},
|
|
342
|
+
annotations: READ
|
|
343
|
+
}, () => attempt(async () => jsonResult(await fetchWorkingMaxes(ctx.client))));
|
|
344
|
+
server.registerTool("athlete_leaderboard", {
|
|
345
|
+
title: "Benchmark leaderboard",
|
|
346
|
+
description: "Leaderboard for a benchmark/test workout by its workout id.",
|
|
306
347
|
inputSchema: {
|
|
348
|
+
workoutId: idParam,
|
|
307
349
|
page: z.number().int().positive().optional(),
|
|
308
|
-
pageSize: z.number().int().positive().optional()
|
|
350
|
+
pageSize: z.number().int().positive().max(200).optional(),
|
|
351
|
+
gender: z.number().int().optional()
|
|
309
352
|
},
|
|
310
353
|
annotations: READ
|
|
311
|
-
}, ({ page, pageSize }) => {
|
|
312
|
-
const
|
|
313
|
-
if (page !== void 0)
|
|
314
|
-
if (pageSize !== void 0)
|
|
315
|
-
|
|
316
|
-
return
|
|
317
|
-
});
|
|
354
|
+
}, ({ workoutId, page, pageSize, gender }) => attempt(async () => {
|
|
355
|
+
const opts = {};
|
|
356
|
+
if (page !== void 0) opts.page = page;
|
|
357
|
+
if (pageSize !== void 0) opts.pageSize = pageSize;
|
|
358
|
+
if (gender !== void 0) opts.gender = gender;
|
|
359
|
+
return jsonResult(await fetchLeaderboard(ctx.client, toId(workoutId), opts));
|
|
360
|
+
}));
|
|
361
|
+
}
|
|
362
|
+
/** Workouts, exercise catalog, per-exercise history/PRs/stats. */
|
|
363
|
+
function registerExerciseTools$1(server, ctx, userId) {
|
|
318
364
|
server.registerTool("athlete_workouts", {
|
|
319
|
-
title: "
|
|
320
|
-
description: "
|
|
365
|
+
title: "Workouts in a date range",
|
|
366
|
+
description: "Scheduled + completed workouts in an inclusive YYYY-MM-DD window, flattened to blocks/exercises with per-set prescriptions and positional units. Set raw:true for the untouched API objects. Narrow the window if the result is truncated.",
|
|
321
367
|
inputSchema: {
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
368
|
+
startDate: dateString,
|
|
369
|
+
endDate: dateString,
|
|
370
|
+
raw: z.boolean().optional()
|
|
325
371
|
},
|
|
326
372
|
annotations: READ
|
|
327
|
-
}, ({
|
|
328
|
-
const
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
373
|
+
}, ({ startDate, endDate, raw }) => attempt(async () => {
|
|
374
|
+
const workouts = await fetchAthleteWorkouts(ctx.client, startDate, endDate);
|
|
375
|
+
return jsonResult(raw === true ? workouts : presentAthleteWorkouts(workouts), { hint: "Narrow startDate/endDate to shrink this result." });
|
|
376
|
+
}));
|
|
377
|
+
server.registerTool("athlete_exercises", {
|
|
378
|
+
title: "Search logged exercises",
|
|
379
|
+
description: "The exercises the athlete has logged (id + title + positional units). Pass q to free-text search by name; use the returned id with athlete_exercise_history / _stats.",
|
|
380
|
+
inputSchema: {
|
|
381
|
+
q: z.string().optional(),
|
|
382
|
+
limit: z.number().int().positive().max(200).optional()
|
|
383
|
+
},
|
|
384
|
+
annotations: READ
|
|
385
|
+
}, ({ q, limit }) => attempt(async () => {
|
|
386
|
+
return jsonResult((q !== void 0 && q.trim() !== "" ? await searchExerciseHistory(ctx.client, q, limit ?? 20) : await fetchExerciseHistoryList(ctx.client)).map((r) => ({
|
|
387
|
+
id: r.id,
|
|
388
|
+
title: r.title,
|
|
389
|
+
isCircuit: r.isCircuit ?? false,
|
|
390
|
+
units: exerciseUnits(r.param1Type, r.param2Type)
|
|
391
|
+
})), { hint: "Pass q to search by name, or limit to cap the list." });
|
|
392
|
+
}));
|
|
393
|
+
server.registerTool("athlete_exercise_history", {
|
|
394
|
+
title: "Exercise history + PRs",
|
|
395
|
+
description: "Per-exercise PRs and the dated session time-series (sets performed, estimated 1RM). Set raw:true for the untouched API object. Get the exercise id from athlete_exercises.",
|
|
396
|
+
inputSchema: {
|
|
397
|
+
exerciseId: idParam,
|
|
398
|
+
raw: z.boolean().optional()
|
|
399
|
+
},
|
|
400
|
+
annotations: READ
|
|
401
|
+
}, ({ exerciseId, raw }) => attempt(async () => {
|
|
402
|
+
const detail = await fetchExerciseHistoryDetail(ctx.client, toId(exerciseId), await userId());
|
|
403
|
+
return jsonResult(raw === true ? detail : presentExerciseHistory(detail));
|
|
404
|
+
}));
|
|
405
|
+
server.registerTool("athlete_personal_records", {
|
|
406
|
+
title: "Exercise personal records",
|
|
407
|
+
description: "Personal records for an exercise (reps/weight, strength-standard filters).",
|
|
408
|
+
inputSchema: { exerciseId: idParam },
|
|
409
|
+
annotations: READ
|
|
410
|
+
}, ({ exerciseId }) => attempt(async () => jsonResult(await fetchPersonalRecords(ctx.client, toId(exerciseId)))));
|
|
411
|
+
server.registerTool("athlete_exercise_stats", {
|
|
412
|
+
title: "Exercise stats (last performance + PR)",
|
|
413
|
+
description: "Last performance and PR for an exercise as of a date (YYYY-MM-DD, required by the API).",
|
|
414
|
+
inputSchema: {
|
|
415
|
+
exerciseId: idParam,
|
|
416
|
+
date: dateString
|
|
417
|
+
},
|
|
418
|
+
annotations: READ
|
|
419
|
+
}, ({ exerciseId, date }) => attempt(async () => jsonResult(await fetchExerciseStats(ctx.client, toId(exerciseId), await userId(), date))));
|
|
334
420
|
}
|
|
335
|
-
/**
|
|
336
|
-
function
|
|
337
|
-
|
|
338
|
-
|
|
421
|
+
/** Create a personal workout session and add exercises to it. */
|
|
422
|
+
function registerSessionTools(server, ctx) {
|
|
423
|
+
server.registerTool("athlete_session_create", {
|
|
424
|
+
title: "Create personal workout session",
|
|
425
|
+
description: "Create a new personal workout session for a given YYYY-MM-DD date on the athlete's personal calendar. Returns programWorkoutId, workoutId (pass to athlete_session_add_exercises), savedWorkoutId, groupId, and date.",
|
|
426
|
+
inputSchema: { date: dateString },
|
|
427
|
+
annotations: {
|
|
428
|
+
readOnlyHint: false,
|
|
429
|
+
destructiveHint: false,
|
|
430
|
+
openWorldHint: true
|
|
431
|
+
}
|
|
432
|
+
}, ({ date }) => attempt(async () => jsonResult(await createPersonalWorkout(ctx.client, date))));
|
|
433
|
+
server.registerTool("athlete_session_add_exercises", {
|
|
434
|
+
title: "Add exercises to a personal workout session",
|
|
435
|
+
description: "Add one or more exercises to a personal workout session. Get workoutId from athlete_session_create. Each item needs an exerciseId (from athlete_exercises) and a 1-based order. Returns saved workout set objects: each top-level id is a savedWorkoutSetId and savedWorkoutSetExercises[].id is a savedWorkoutSetExerciseId — both needed for athlete_log_set.",
|
|
436
|
+
inputSchema: {
|
|
437
|
+
workoutId: idParam,
|
|
438
|
+
exercises: z.array(z.object({
|
|
439
|
+
exerciseId: idParam,
|
|
440
|
+
order: z.number().int().positive()
|
|
441
|
+
})).min(1)
|
|
442
|
+
},
|
|
443
|
+
annotations: {
|
|
444
|
+
readOnlyHint: false,
|
|
445
|
+
destructiveHint: false,
|
|
446
|
+
openWorldHint: true
|
|
447
|
+
}
|
|
448
|
+
}, ({ workoutId, exercises }) => attempt(async () => {
|
|
449
|
+
const mapped = exercises.map((e) => ({
|
|
450
|
+
exerciseId: toId(e.exerciseId),
|
|
451
|
+
order: e.order
|
|
452
|
+
}));
|
|
453
|
+
return jsonResult(await addExercisesToWorkout(ctx.client, toId(workoutId), mapped), { hint: "Each top-level id is a savedWorkoutSetId; savedWorkoutSetExercises[].id is the savedWorkoutSetExerciseId for athlete_log_set." });
|
|
454
|
+
}));
|
|
455
|
+
}
|
|
456
|
+
/** The gated set-logging write. */
|
|
457
|
+
function registerLogTool(server, ctx) {
|
|
458
|
+
server.registerTool("athlete_log_set", {
|
|
459
|
+
title: "Log completed set results",
|
|
460
|
+
description: "Athlete-facing write: record entered results (reps/weight per set) for a saved workout set on a given day, marking the set completed. Writes to the athlete's (coach-visible) training log and shows in exercise history. Get savedWorkoutSetId + savedWorkoutSetExerciseId from athlete_workouts (raw:true). Requires confirmation (elicitation or confirm:true).",
|
|
461
|
+
inputSchema: {
|
|
462
|
+
...logSetArgsSchema.shape,
|
|
463
|
+
confirm: z.boolean().optional()
|
|
464
|
+
},
|
|
465
|
+
annotations: DESTRUCTIVE
|
|
466
|
+
}, ({ date, savedWorkoutSetId, results, confirm }, extra) => attempt(async () => {
|
|
467
|
+
if (!await confirmGate(server, extra.requestId, `Log results to saved workout set ${toId(savedWorkoutSetId)} on ${date}? This writes to your coach-visible training log.`, confirm)) return errorResult(NOT_CONFIRMED);
|
|
468
|
+
const mapped = results.map((r) => ({
|
|
469
|
+
savedWorkoutSetExerciseId: toId(r.savedWorkoutSetExerciseId),
|
|
470
|
+
sets: r.sets.map((s) => {
|
|
471
|
+
const slot = {};
|
|
472
|
+
if (s.param1 !== void 0) slot.param1 = s.param1;
|
|
473
|
+
if (s.param2 !== void 0) slot.param2 = s.param2;
|
|
474
|
+
return slot;
|
|
475
|
+
})
|
|
476
|
+
}));
|
|
477
|
+
return jsonResult(await logAthleteSet(ctx.client, {
|
|
478
|
+
date,
|
|
479
|
+
savedWorkoutSetId: toId(savedWorkoutSetId),
|
|
480
|
+
results: mapped
|
|
481
|
+
}));
|
|
482
|
+
}));
|
|
483
|
+
}
|
|
484
|
+
/**
|
|
485
|
+
* Live tools over the logged-in user's own training (history, scheduled/completed workouts,
|
|
486
|
+
* PRs, working maxes), plus a gated set-logging write. The athlete user id is
|
|
487
|
+
* resolved once from /user/simple and reused across tools.
|
|
488
|
+
*/
|
|
489
|
+
function registerAthleteTrainingTools(server, ctx) {
|
|
490
|
+
let whoamiCache = null;
|
|
491
|
+
const whoami = async () => {
|
|
492
|
+
if (whoamiCache === null) {
|
|
493
|
+
const res = await ctx.client.request("GET", "/user/simple");
|
|
494
|
+
if (!res.ok || !isRecord(res.data)) throw new Error("Could not load /user/simple.");
|
|
495
|
+
whoamiCache = res.data;
|
|
496
|
+
}
|
|
497
|
+
return whoamiCache;
|
|
498
|
+
};
|
|
499
|
+
const userId = async () => {
|
|
500
|
+
const id = coerceInt((await whoami()).id);
|
|
501
|
+
if (id === null || id <= 0) throw new Error("Could not resolve athlete user id from /user/simple.");
|
|
502
|
+
return id;
|
|
503
|
+
};
|
|
504
|
+
registerProfileTools(server, ctx, whoami, userId);
|
|
505
|
+
registerExerciseTools$1(server, ctx, userId);
|
|
506
|
+
registerSessionTools(server, ctx);
|
|
507
|
+
registerLogTool(server, ctx);
|
|
339
508
|
}
|
|
340
509
|
//#endregion
|
|
341
510
|
//#region src/tools/athletes.ts
|
|
@@ -486,7 +655,6 @@ const METRIC_KEYS = [
|
|
|
486
655
|
"readiness-athlete",
|
|
487
656
|
"lift-1rm-history",
|
|
488
657
|
"training-summary-athlete",
|
|
489
|
-
"training-summary-team",
|
|
490
658
|
"compliance-team",
|
|
491
659
|
"lift-progress-team",
|
|
492
660
|
"working-max-history"
|
|
@@ -495,58 +663,80 @@ const METRICS = {
|
|
|
495
663
|
"readiness-team": {
|
|
496
664
|
path: "/v5/analytics/readiness/teams",
|
|
497
665
|
scope: "team",
|
|
498
|
-
|
|
666
|
+
inputs: ["date"],
|
|
667
|
+
requires: ["date"]
|
|
499
668
|
},
|
|
500
669
|
"readiness-athlete": {
|
|
501
670
|
path: "/v5/analytics/readiness/users",
|
|
502
671
|
scope: "user",
|
|
503
|
-
|
|
672
|
+
inputs: ["dateStart", "dateEnd"],
|
|
673
|
+
requires: ["dateStart", "dateEnd"]
|
|
504
674
|
},
|
|
505
675
|
"lift-1rm-history": {
|
|
506
676
|
path: "/v5/analytics/lift-one-rep-max-history/users",
|
|
507
677
|
scope: "user",
|
|
508
|
-
|
|
509
|
-
"
|
|
510
|
-
"
|
|
511
|
-
"
|
|
512
|
-
"
|
|
678
|
+
inputs: [
|
|
679
|
+
"dateStart",
|
|
680
|
+
"dateEnd",
|
|
681
|
+
"exerciseId",
|
|
682
|
+
"useMetric"
|
|
683
|
+
],
|
|
684
|
+
requires: [
|
|
685
|
+
"dateStart",
|
|
686
|
+
"dateEnd",
|
|
687
|
+
"exerciseId"
|
|
513
688
|
]
|
|
514
689
|
},
|
|
515
690
|
"training-summary-athlete": {
|
|
516
691
|
path: "/v5/analytics/training-summary/users",
|
|
517
692
|
scope: "user",
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
"training-summary-team": {
|
|
521
|
-
path: "/v5/analytics/training-summary/teams",
|
|
522
|
-
scope: "team",
|
|
523
|
-
fields: ["date_start", "date_end"]
|
|
693
|
+
inputs: ["dateStart", "dateEnd"],
|
|
694
|
+
requires: ["dateStart", "dateEnd"]
|
|
524
695
|
},
|
|
525
696
|
"compliance-team": {
|
|
526
697
|
path: "/v5/analytics/compliance",
|
|
527
698
|
scope: "team",
|
|
528
|
-
|
|
699
|
+
inputs: ["dateStart", "dateEnd"],
|
|
700
|
+
requires: ["dateStart", "dateEnd"]
|
|
529
701
|
},
|
|
530
702
|
"lift-progress-team": {
|
|
531
703
|
path: "/v5/analytics/lift-progress/teams",
|
|
532
704
|
scope: "team",
|
|
533
|
-
|
|
534
|
-
"
|
|
535
|
-
"
|
|
536
|
-
"
|
|
705
|
+
inputs: [
|
|
706
|
+
"exerciseId",
|
|
707
|
+
"dateStart",
|
|
708
|
+
"dateEnd"
|
|
709
|
+
],
|
|
710
|
+
requires: [
|
|
711
|
+
"exerciseId",
|
|
712
|
+
"dateStart",
|
|
713
|
+
"dateEnd"
|
|
537
714
|
]
|
|
538
715
|
},
|
|
539
716
|
"working-max-history": {
|
|
540
717
|
path: "/v5/analytics/working-max-history/users",
|
|
541
718
|
scope: "user",
|
|
542
|
-
|
|
719
|
+
inputs: [
|
|
720
|
+
"exerciseId",
|
|
721
|
+
"dateStart",
|
|
722
|
+
"dateEnd",
|
|
723
|
+
"useMetric"
|
|
724
|
+
],
|
|
725
|
+
requires: ["exerciseId"]
|
|
543
726
|
}
|
|
544
727
|
};
|
|
728
|
+
const BODY_KEY = {
|
|
729
|
+
date: "date",
|
|
730
|
+
dateStart: "date_start",
|
|
731
|
+
dateEnd: "date_end",
|
|
732
|
+
exerciseId: "exercise_id",
|
|
733
|
+
useMetric: "use_metric"
|
|
734
|
+
};
|
|
545
735
|
/** Analytics report pulls. Read-only despite the POST verb, so ungated. */
|
|
546
736
|
function registerAnalyticsTools(server, ctx) {
|
|
547
737
|
server.registerTool("analytics_query", {
|
|
548
738
|
title: "Pull an analytics report",
|
|
549
|
-
description: "Read a TrainHeroic analytics report. `metric` picks the report (run analytics_categories for the catalog). Team metrics need teamId; athlete metrics need userIds.
|
|
739
|
+
description: "Read a TrainHeroic analytics report. `metric` picks the report (run analytics_categories for the catalog). Team metrics (readiness-team, compliance-team, lift-progress-team) need teamId; athlete metrics need userIds. readiness-team takes a single `date`; every other metric takes dateStart/dateEnd. lift-1rm-history, lift-progress-team, and working-max-history also need exerciseId. All dates are YYYY-MM-DD.",
|
|
550
740
|
inputSchema: {
|
|
551
741
|
metric: z.enum(METRIC_KEYS),
|
|
552
742
|
teamId: idParam.optional(),
|
|
@@ -560,6 +750,13 @@ function registerAnalyticsTools(server, ctx) {
|
|
|
560
750
|
annotations: READ
|
|
561
751
|
}, async ({ metric, teamId, userIds, exerciseId, date, dateStart, dateEnd, useMetric }) => {
|
|
562
752
|
const spec = METRICS[metric];
|
|
753
|
+
const inputs = {
|
|
754
|
+
date,
|
|
755
|
+
dateStart,
|
|
756
|
+
dateEnd,
|
|
757
|
+
exerciseId,
|
|
758
|
+
useMetric
|
|
759
|
+
};
|
|
563
760
|
const body = {};
|
|
564
761
|
if (spec.scope === "team") {
|
|
565
762
|
if (teamId === void 0) return errorResult(`${metric} needs teamId.`);
|
|
@@ -568,14 +765,13 @@ function registerAnalyticsTools(server, ctx) {
|
|
|
568
765
|
if (userIds === void 0 || userIds.length === 0) return errorResult(`${metric} needs userIds (one or more athlete ids).`);
|
|
569
766
|
body.user_ids = userIds.map((u) => String(toId(u)));
|
|
570
767
|
}
|
|
571
|
-
const
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
}
|
|
578
|
-
for (const field of spec.fields) if (provided[field] !== void 0) body[field] = provided[field];
|
|
768
|
+
const missing = spec.requires.filter((k) => inputs[k] === void 0);
|
|
769
|
+
if (missing.length > 0) return errorResult(`${metric} also needs: ${missing.join(", ")}.`);
|
|
770
|
+
for (const k of spec.inputs) {
|
|
771
|
+
const v = inputs[k];
|
|
772
|
+
if (v === void 0) continue;
|
|
773
|
+
body[BODY_KEY[k]] = k === "exerciseId" ? String(toId(v)) : v;
|
|
774
|
+
}
|
|
579
775
|
return apiCall(ctx, "POST", spec.path, { body }, "Narrow with a tighter date range or fewer athletes.");
|
|
580
776
|
});
|
|
581
777
|
}
|
|
@@ -891,4 +1087,4 @@ function registerMessagingTools(server, ctx) {
|
|
|
891
1087
|
registerWrites(server, ctx);
|
|
892
1088
|
}
|
|
893
1089
|
//#endregion
|
|
894
|
-
export { DEFAULT_RESULT_BUDGET, DESTRUCTIVE, NOT_CONFIRMED, READ, SYNC, apiCall, attempt, boundedSerialize, confirmGate, errorResult, idParam, jsonResult, registerAnalyticsTools, registerAthleteTools, registerExerciseTools, registerMessagingTools, registerReadTools, registerTeamTools, registerWorkoutTools, resultBudget, toId };
|
|
1090
|
+
export { DEFAULT_RESULT_BUDGET, DESTRUCTIVE, NOT_CONFIRMED, READ, SYNC, apiCall, attempt, boundedSerialize, confirmGate, errorResult, idParam, jsonResult, registerAnalyticsTools, registerAthleteTools, registerAthleteTrainingTools, registerExerciseTools, registerMessagingTools, registerReadTools, registerTeamTools, registerWorkoutTools, resultBudget, toId };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trainheroic-unofficial/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
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/sdk": "^1.29.0",
|
|
27
27
|
"zod": "^4.4.3",
|
|
28
|
-
"@trainheroic-unofficial/dto": "0.
|
|
29
|
-
"@trainheroic-unofficial/js": "0.
|
|
28
|
+
"@trainheroic-unofficial/dto": "0.4.1",
|
|
29
|
+
"@trainheroic-unofficial/js": "0.4.1"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@types/node": "^26.0.0",
|