@trainheroic-unofficial/coach-mcp 2.1.0 → 2.1.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.
Files changed (2) hide show
  1. package/dist/server.mjs +44 -7
  2. package/package.json +5 -5
package/dist/server.mjs CHANGED
@@ -583,6 +583,34 @@ function confirmGate(ctx, message, confirmArg) {
583
583
  */
584
584
  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.";
585
585
  //#endregion
586
+ //#region ../js/src/http-error.ts
587
+ /**
588
+ * A final non-2xx response from TrainHeroic. The error deliberately carries only request
589
+ * metadata that is safe to send to telemetry: never the path, query string, request body,
590
+ * response body, credentials, or session token.
591
+ */
592
+ var TrainHeroicHttpError = class extends Error {
593
+ name = "TrainHeroicHttpError";
594
+ method;
595
+ status;
596
+ host;
597
+ constructor(method, url, status) {
598
+ const parsed = new URL(url);
599
+ const normalizedMethod = method.toUpperCase();
600
+ super(`TrainHeroic ${normalizedMethod} request failed with HTTP ${status}`);
601
+ this.method = normalizedMethod;
602
+ this.status = status;
603
+ this.host = parsed.host;
604
+ }
605
+ };
606
+ /** Call observability hooks without allowing them to change SDK behavior. */
607
+ function notifyHttpError(handler, method, url, status) {
608
+ if (!handler) return;
609
+ try {
610
+ Promise.resolve(handler(new TrainHeroicHttpError(method, url, status))).catch(() => {});
611
+ } catch {}
612
+ }
613
+ //#endregion
586
614
  //#region ../js/src/auth.ts
587
615
  const DEFAULT_AUTH_URL = "https://apis.trainheroic.com/auth";
588
616
  /**
@@ -604,8 +632,9 @@ function authUrl() {
604
632
  * the Phase 0 spike: no refresh_token, no api_token, no TTL). The 48-char session_id
605
633
  * is sent as the `session-token` header and works against both API hosts.
606
634
  */
607
- async function loginTrainHeroic(email, password) {
608
- const res = await fetch(authUrl(), {
635
+ async function loginTrainHeroic(email, password, options = {}) {
636
+ const url = authUrl();
637
+ const res = await fetch(url, {
609
638
  method: "POST",
610
639
  headers: {
611
640
  "content-type": "application/x-www-form-urlencoded",
@@ -616,7 +645,10 @@ async function loginTrainHeroic(email, password) {
616
645
  password
617
646
  }).toString()
618
647
  });
619
- if (!res.ok) return null;
648
+ if (!res.ok) {
649
+ notifyHttpError(options.onHttpError, "POST", url, res.status);
650
+ return null;
651
+ }
620
652
  const data = await res.json().catch(() => null);
621
653
  if (!data || typeof data.id !== "number" || !data.session_id) return null;
622
654
  return {
@@ -659,6 +691,7 @@ var TrainHeroicClient = class {
659
691
  #email;
660
692
  #password;
661
693
  #onSession;
694
+ #onHttpError;
662
695
  #sessionId;
663
696
  #loginInFlight = null;
664
697
  constructor(email, password, sessionId = null, options = {}) {
@@ -666,6 +699,7 @@ var TrainHeroicClient = class {
666
699
  this.#password = password;
667
700
  this.#sessionId = sessionId;
668
701
  this.#onSession = options.onSession;
702
+ this.#onHttpError = options.onHttpError;
669
703
  }
670
704
  get sessionId() {
671
705
  return this.#sessionId;
@@ -680,7 +714,7 @@ var TrainHeroicClient = class {
680
714
  }
681
715
  }
682
716
  async #login() {
683
- const session = await loginTrainHeroic(this.#email, this.#password);
717
+ const session = await loginTrainHeroic(this.#email, this.#password, this.#onHttpError ? { onHttpError: this.#onHttpError } : {});
684
718
  if (!session) throw new TrainHeroicAuthError("TrainHeroic login failed");
685
719
  this.#sessionId = session.sessionId;
686
720
  try {
@@ -697,6 +731,7 @@ var TrainHeroicClient = class {
697
731
  session = await this.#ensureSession();
698
732
  res = await this.#send(method, url, session, options.body);
699
733
  }
734
+ if (!res.ok) notifyHttpError(this.#onHttpError, method, url, res.status);
700
735
  const text = await res.text();
701
736
  let data = text;
702
737
  if (text.length > 0) try {
@@ -2081,8 +2116,10 @@ function unitAdvisory(blockTitle, ex, defaults) {
2081
2116
  if (ex.weight !== void 0 && ex.weight !== null) {
2082
2117
  const sentP2 = Math.trunc(Number(ex.param_2_type ?? 1));
2083
2118
  const effP2 = defaults.param2 === 0 || defaults.param2 === null ? 1 : defaults.param2;
2084
- if (sentP2 !== effP2) if (sentP2 === 2 || sentP2 === 14) warnings.push(`${label}: ${u(sentP2)} does not stick on this exercise — it renders as ${u(effP2)}. Put it in the exercise 'instr' text and leave load blank.`);
2085
- else warnings.push(`${label}: load renders as ${u(effP2)}, not ${u(sentP2)} (this exercise's secondary unit is fixed).`);
2119
+ if (sentP2 !== effP2) {
2120
+ if (sentP2 === 2 || sentP2 === 14) warnings.push(`${label}: ${u(sentP2)} does not stick on this exercise — it renders as ${u(effP2)}. Put it in the exercise 'instr' text and leave load blank.`);
2121
+ else warnings.push(`${label}: load renders as ${u(effP2)}, not ${u(sentP2)} (this exercise's secondary unit is fixed).`);
2122
+ }
2086
2123
  }
2087
2124
  return {
2088
2125
  notes,
@@ -3933,7 +3970,7 @@ var JsonFileLibraryCache = class {
3933
3970
  };
3934
3971
  //#endregion
3935
3972
  //#region package.json
3936
- var version = "2.1.0";
3973
+ var version = "2.1.1";
3937
3974
  //#endregion
3938
3975
  //#region src/server.ts
3939
3976
  function main() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trainheroic-unofficial/coach-mcp",
3
- "version": "2.1.0",
3
+ "version": "2.1.1",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -21,13 +21,13 @@
21
21
  "dependencies": {
22
22
  "@modelcontextprotocol/server": "2.0.0",
23
23
  "zod": "^4.4.3",
24
- "@trainheroic-unofficial/core": "2.1.0",
25
- "@trainheroic-unofficial/js": "2.1.0"
24
+ "@trainheroic-unofficial/core": "2.1.1",
25
+ "@trainheroic-unofficial/js": "2.1.1"
26
26
  },
27
27
  "devDependencies": {
28
- "@types/node": "^26.1.2",
28
+ "@types/node": "^26.2.0",
29
29
  "tsdown": "^0.22.14",
30
- "tsx": "^4.23.4",
30
+ "tsx": "^4.23.11",
31
31
  "typescript": "^7.0.2",
32
32
  "vitest": "^4.1.10"
33
33
  },