@pontix/adapter-duin 0.0.0-stage → 0.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 (60) hide show
  1. package/LICENSE +661 -0
  2. package/README.md +98 -2
  3. package/dist/auth.d.ts +30 -0
  4. package/dist/auth.d.ts.map +1 -0
  5. package/dist/auth.js +170 -0
  6. package/dist/auth.js.map +1 -0
  7. package/dist/available-plans.d.ts +10 -0
  8. package/dist/available-plans.d.ts.map +1 -0
  9. package/dist/available-plans.js +14 -0
  10. package/dist/available-plans.js.map +1 -0
  11. package/dist/index.d.ts +16 -0
  12. package/dist/index.d.ts.map +1 -0
  13. package/dist/index.js +85 -0
  14. package/dist/index.js.map +1 -0
  15. package/dist/mappers.d.ts +33 -0
  16. package/dist/mappers.d.ts.map +1 -0
  17. package/dist/mappers.js +35 -0
  18. package/dist/mappers.js.map +1 -0
  19. package/dist/plan-edit.d.ts +79 -0
  20. package/dist/plan-edit.d.ts.map +1 -0
  21. package/dist/plan-edit.js +122 -0
  22. package/dist/plan-edit.js.map +1 -0
  23. package/dist/session.d.ts +20 -0
  24. package/dist/session.d.ts.map +1 -0
  25. package/dist/session.js +59 -0
  26. package/dist/session.js.map +1 -0
  27. package/dist/shapes.d.ts +626 -0
  28. package/dist/shapes.d.ts.map +1 -0
  29. package/dist/shapes.js +219 -0
  30. package/dist/shapes.js.map +1 -0
  31. package/dist/tools/add-plan-exercise.d.ts +87 -0
  32. package/dist/tools/add-plan-exercise.d.ts.map +1 -0
  33. package/dist/tools/add-plan-exercise.js +47 -0
  34. package/dist/tools/add-plan-exercise.js.map +1 -0
  35. package/dist/tools/get-plan.d.ts +29 -0
  36. package/dist/tools/get-plan.d.ts.map +1 -0
  37. package/dist/tools/get-plan.js +150 -0
  38. package/dist/tools/get-plan.js.map +1 -0
  39. package/dist/tools/list-plans.d.ts +40 -0
  40. package/dist/tools/list-plans.d.ts.map +1 -0
  41. package/dist/tools/list-plans.js +110 -0
  42. package/dist/tools/list-plans.js.map +1 -0
  43. package/dist/tools/list-workouts.d.ts +73 -0
  44. package/dist/tools/list-workouts.d.ts.map +1 -0
  45. package/dist/tools/list-workouts.js +269 -0
  46. package/dist/tools/list-workouts.js.map +1 -0
  47. package/dist/tools/remove-plan-exercise.d.ts +23 -0
  48. package/dist/tools/remove-plan-exercise.d.ts.map +1 -0
  49. package/dist/tools/remove-plan-exercise.js +33 -0
  50. package/dist/tools/remove-plan-exercise.js.map +1 -0
  51. package/dist/tools/search-activities.d.ts +68 -0
  52. package/dist/tools/search-activities.d.ts.map +1 -0
  53. package/dist/tools/search-activities.js +136 -0
  54. package/dist/tools/search-activities.js.map +1 -0
  55. package/dist/tools/set-plan-exercise-sets.d.ts +79 -0
  56. package/dist/tools/set-plan-exercise-sets.d.ts.map +1 -0
  57. package/dist/tools/set-plan-exercise-sets.js +39 -0
  58. package/dist/tools/set-plan-exercise-sets.js.map +1 -0
  59. package/mappers.json +197 -0
  60. package/package.json +45 -3
@@ -0,0 +1,110 @@
1
+ import { applyMapper, defineTool, upstreamChanged, z } from "@pontix/core/adapter";
2
+ import { ADAPTER_ID, MAPPERS } from "../mappers.js";
3
+ import { plan, planList } from "../shapes.js";
4
+ import { fetchAvailablePlans } from "../available-plans.js";
5
+ const DEFAULT_LIMIT = 20;
6
+ const MAX_LIMIT = 100;
7
+ /**
8
+ * The member's own plans first, the gym's catalogue last.
9
+ *
10
+ * The order is the point: the brand catalogue can hold hundreds, and sorted
11
+ * any other way it would push the few plans the member made past `limit`.
12
+ */
13
+ const GROUP_ORDER = ["USER_OWN", "TRAINER_ASSIGNED", "BRAND_SPECIFIC"];
14
+ export const listPlansInput = z.object({
15
+ groupType: z
16
+ .enum(GROUP_ORDER)
17
+ .optional()
18
+ .describe("Only plans of this kind: USER_OWN (made by the member), TRAINER_ASSIGNED, or BRAND_SPECIFIC (the gym's catalogue). Omit it to get all, the member's own first."),
19
+ limit: z
20
+ .number()
21
+ .int()
22
+ .min(1)
23
+ .max(MAX_LIMIT)
24
+ .default(DEFAULT_LIMIT)
25
+ .describe(`How many plans to return. At most ${MAX_LIMIT}. The result also says how many matched and how many each group holds.`),
26
+ });
27
+ /** Position of a group in the output; anything unrecognised sorts after the three known ones. */
28
+ function rank(groupType) {
29
+ const at = GROUP_ORDER.findIndex((group) => group === groupType);
30
+ return at === -1 ? GROUP_ORDER.length : at;
31
+ }
32
+ /**
33
+ * A real boolean off a raw row, or null when the service did not send one.
34
+ *
35
+ * Read here and not in `mappers.json` because the mapper vocabulary has no
36
+ * boolean coercion: `text` drops a boolean to null, and `present` answers true
37
+ * for any key that exists, `false` included. Either would erase the one signal
38
+ * these two fields carry (the member's own plans are `true`, the gym's and the
39
+ * trainer's `false`), so they are passed to `applyMapper` as extras instead.
40
+ */
41
+ function flag(row, key) {
42
+ if (typeof row !== "object" || row === null)
43
+ return null;
44
+ const value = row[key];
45
+ return typeof value === "boolean" ? value : null;
46
+ }
47
+ /**
48
+ * Ordering, counting, filtering and truncating are computed, so they live here
49
+ * and not in `mappers.json`, as in `toWorkoutList`.
50
+ *
51
+ * **One unreadable row fails the whole call, on purpose.** `applyMapper` maps
52
+ * rows atomically (`packages/core/src/mapper.ts`) and nothing here tolerates a
53
+ * bad one. The rows come from one API through one code path, so one bad row
54
+ * among hundreds is far less likely than every row being bad — and that is
55
+ * drift, which must be loud. `upstreamChanged` already names the keys received.
56
+ * Tolerating rows would hide exactly that case behind a partial answer. This
57
+ * was weighed twice in review and decided; do not re-open it without a response
58
+ * where some rows are unreadable and others are not.
59
+ */
60
+ export function toPlanList(payload, filter, limit) {
61
+ // The response is a bare array (live capture, 2026-11-17), so there is no
62
+ // envelope to look through: anything else is drift, and says which keys came.
63
+ if (!Array.isArray(payload)) {
64
+ throw upstreamChanged(ADAPTER_ID, "The available plans response", payload);
65
+ }
66
+ const all = payload.map((row) => plan.parse(applyMapper(MAPPERS, "plan", row, ADAPTER_ID, {
67
+ editable: flag(row, "editable"),
68
+ deletable: flag(row, "deletable"),
69
+ })));
70
+ const groups = { USER_OWN: 0, TRAINER_ASSIGNED: 0, BRAND_SPECIFIC: 0, other: 0 };
71
+ for (const entry of all) {
72
+ const known = GROUP_ORDER.find((group) => group === entry.groupType);
73
+ groups[known ?? "other"] += 1;
74
+ }
75
+ const matching = filter === undefined ? all : all.filter((entry) => entry.groupType === filter);
76
+ // `Array.prototype.sort` is stable, so within a group the service's order
77
+ // survives: nothing here knows a better one.
78
+ const ordered = [...matching].sort((a, b) => rank(a.groupType) - rank(b.groupType));
79
+ const shown = ordered.slice(0, limit);
80
+ return planList.parse({
81
+ total: matching.length,
82
+ returned: shown.length,
83
+ truncated: matching.length > shown.length,
84
+ groups,
85
+ plans: shown,
86
+ });
87
+ }
88
+ export const listPlans = defineTool({
89
+ name: "list_plans",
90
+ description: "List the training plans the signed-in member can start at their gym: their own, the ones a trainer assigned and the gym's catalogue. " +
91
+ "Each has an id, a name, which kind it is (groupType), where its exercise values come from and how many exercises it holds. " +
92
+ "The member's own plans come first. `total` is how many matched and `returned` how many you got, so say when it was truncated; " +
93
+ "`groups` says how many plans each kind holds, so you can say how many are theirs without listing the catalogue. " +
94
+ "It carries no exercises or sets: use it to find a plan, not to describe one.",
95
+ descriptions: {
96
+ es: "Lista los planes de entrenamiento que el socio con la sesión iniciada puede empezar en su gimnasio: los suyos, los que le ha asignado un entrenador y el catálogo del gimnasio. " +
97
+ "Cada uno trae identificador, nombre, de qué tipo es (groupType), de dónde salen los valores de sus ejercicios y cuántos ejercicios tiene. " +
98
+ "Los planes propios van primero. `total` es cuántos coinciden y `returned` cuántos se devolvieron, así que avisa cuando se haya truncado; " +
99
+ "`groups` indica cuántos planes hay de cada tipo, para poder decir cuántos son propios sin listar el catálogo. " +
100
+ "No incluye ejercicios ni series: sirve para encontrar un plan, no para describirlo.",
101
+ },
102
+ input: listPlansInput,
103
+ readOnly: true,
104
+ // No cache: the member may create a plan and ask about it straight away.
105
+ async execute(session, input) {
106
+ const payload = await fetchAvailablePlans(session);
107
+ return toPlanList(payload, input.groupType, input.limit);
108
+ },
109
+ });
110
+ //# sourceMappingURL=list-plans.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"list-plans.js","sourceRoot":"","sources":["../../src/tools/list-plans.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,eAAe,EAAE,CAAC,EAAE,MAAM,sBAAsB,CAAC;AACnF,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAiB,MAAM,cAAc,CAAC;AAC7D,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAG5D,MAAM,aAAa,GAAG,EAAE,CAAC;AACzB,MAAM,SAAS,GAAG,GAAG,CAAC;AAEtB;;;;;GAKG;AACH,MAAM,WAAW,GAAG,CAAC,UAAU,EAAE,kBAAkB,EAAE,gBAAgB,CAAU,CAAC;AAEhF,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,CAAC,MAAM,CAAC;IACrC,SAAS,EAAE,CAAC;SACT,IAAI,CAAC,WAAW,CAAC;SACjB,QAAQ,EAAE;SACV,QAAQ,CACP,gKAAgK,CACjK;IACH,KAAK,EAAE,CAAC;SACL,MAAM,EAAE;SACR,GAAG,EAAE;SACL,GAAG,CAAC,CAAC,CAAC;SACN,GAAG,CAAC,SAAS,CAAC;SACd,OAAO,CAAC,aAAa,CAAC;SACtB,QAAQ,CAAC,qCAAqC,SAAS,wEAAwE,CAAC;CACpI,CAAC,CAAC;AAIH,iGAAiG;AACjG,SAAS,IAAI,CAAC,SAAwB;IACpC,MAAM,EAAE,GAAG,WAAW,CAAC,SAAS,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC;IACjE,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,C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,KAAK,CAAC,SAAS,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC;IAC3D,CAAC;CACF,CAAC,CAAC"}
@@ -0,0 +1,73 @@
1
+ import { z } from "@pontix/core/adapter";
2
+ import { type WorkoutList } from "../shapes.js";
3
+ import type { DuinSession } from "../session.js";
4
+ export declare const listWorkoutsInput: z.ZodObject<{
5
+ from: z.ZodOptional<z.ZodString>;
6
+ to: z.ZodOptional<z.ZodString>;
7
+ limit: z.ZodDefault<z.ZodNumber>;
8
+ }, "strip", z.ZodTypeAny, {
9
+ limit: number;
10
+ from?: string | undefined;
11
+ to?: string | undefined;
12
+ }, {
13
+ from?: string | undefined;
14
+ to?: string | undefined;
15
+ limit?: number | undefined;
16
+ }>;
17
+ type Input = z.infer<typeof listWorkoutsInput>;
18
+ /**
19
+ * The window to ask for.
20
+ *
21
+ * Refused here rather than sent: a `from` after `to` is an empty answer the
22
+ * service would give without saying why, and "no workouts" would read as "you
23
+ * did not train".
24
+ */
25
+ export declare function resolveWindow(input: Pick<Input, "from" | "to">, now: Date): {
26
+ from: Date;
27
+ to: Date;
28
+ };
29
+ /**
30
+ * Sorting, counting, filtering and truncating are computed, so they live here
31
+ * and not in `mappers.json`: a mapper says where a value comes from, not what
32
+ * we work out from it. `execute` only calls this.
33
+ *
34
+ * The window is applied here rather than trusted to the query parameters. The
35
+ * service's own filtering has never been watched — so echoing the window that was
36
+ * asked for while counting whatever came back would turn either mistake into a
37
+ * confident wrong number: a member told they trained five hundred times in
38
+ * October.
39
+ *
40
+ * Entries that cannot be dated are not dropped and not counted as inside. They
41
+ * are reported separately, because "we could not read the dates" and "you did
42
+ * not train" are different answers and only one of them is ever true here.
43
+ */
44
+ export declare function toWorkoutList(payload: unknown, window: {
45
+ from: Date;
46
+ to: Date;
47
+ }, limit: number): WorkoutList;
48
+ /**
49
+ * A window bound as the workouts route accepts it: whole seconds, `Z`.
50
+ *
51
+ * Live, 2026-11-18: the route refuses `toISOString()`'s fraction with 400
52
+ * `completedBefore-wrongFormat`, and answers the same instant without it. The
53
+ * fraction is dropped by widening outwards — `from` down, `to` up — so the end
54
+ * of a bare-date window (23:59:59.999) still reaches the last second of the
55
+ * day, where connected-app sessions are stamped. Anything the extra second lets
56
+ * in is trimmed again by `toWorkoutList`, which filters on the exact window.
57
+ */
58
+ export declare function toQueryInstant(at: Date, round: "down" | "up"): string;
59
+ export declare const listWorkouts: import("@pontix/core/adapter").ToolDefinition<DuinSession, z.ZodObject<{
60
+ from: z.ZodOptional<z.ZodString>;
61
+ to: z.ZodOptional<z.ZodString>;
62
+ limit: z.ZodDefault<z.ZodNumber>;
63
+ }, "strip", z.ZodTypeAny, {
64
+ limit: number;
65
+ from?: string | undefined;
66
+ to?: string | undefined;
67
+ }, {
68
+ from?: string | undefined;
69
+ to?: string | undefined;
70
+ limit?: number | undefined;
71
+ }>>;
72
+ export {};
73
+ //# sourceMappingURL=list-workouts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"list-workouts.d.ts","sourceRoot":"","sources":["../../src/tools/list-workouts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyD,CAAC,EAAE,MAAM,sBAAsB,CAAC;AAEhG,OAAO,EAAwB,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AACtE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAOjD,eAAO,MAAM,iBAAiB;;;;;;;;;;;;EAoB5B,CAAC;AAEH,KAAK,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAC;AA4D/C;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC,EAAE,GAAG,EAAE,IAAI,GAAG;IAAE,IAAI,EAAE,IAAI,CAAC;IAAC,EAAE,EAAE,IAAI,CAAA;CAAE,CAiBpG;AAwED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,aAAa,CAC3B,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE;IAAE,IAAI,EAAE,IAAI,CAAC;IAAC,EAAE,EAAE,IAAI,CAAA;CAAE,EAChC,KAAK,EAAE,MAAM,GACZ,WAAW,CA6Bb;AAED;;;;;;;;;GASG;AACH,wBAAgB,cAAc,CAAC,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,CAGrE;AAED,eAAO,MAAM,YAAY;;;;;;;;;;;;GA2CvB,CAAC"}
@@ -0,0 +1,269 @@
1
+ import { PontixError, applyMapper, defineTool, upstreamChanged, z } from "@pontix/core/adapter";
2
+ import { ADAPTER_ID, MAPPERS } from "../mappers.js";
3
+ import { workout, workoutList } from "../shapes.js";
4
+ const DAY_MS = 86_400_000;
5
+ const DEFAULT_WINDOW_DAYS = 30;
6
+ const DEFAULT_LIMIT = 20;
7
+ const MAX_LIMIT = 100;
8
+ export const listWorkoutsInput = z.object({
9
+ from: z
10
+ .string()
11
+ .optional()
12
+ .describe(`Start of the window, as an ISO date (2026-10-01) or a datetime that names its offset (2026-10-01T08:00:00Z). A bare date means the start of that day in UTC. Defaults to ${DEFAULT_WINDOW_DAYS} days before \`to\`.`),
13
+ to: z
14
+ .string()
15
+ .optional()
16
+ .describe("End of the window, as an ISO date or a datetime that names its offset. A bare date includes that whole day, in UTC. Defaults to now."),
17
+ limit: z
18
+ .number()
19
+ .int()
20
+ .min(1)
21
+ .max(MAX_LIMIT)
22
+ .default(DEFAULT_LIMIT)
23
+ .describe(`How many workouts to return, most recent first. At most ${MAX_LIMIT}. The result also says how many the window held.`),
24
+ });
25
+ const DATE_ONLY = /^\d{4}-\d{2}-\d{2}$/;
26
+ /**
27
+ * An ISO datetime that says which moment it means.
28
+ *
29
+ * The offset is required, not optional. `new Date("2026-10-01T08:00:00")` reads
30
+ * a zone-less time in the host's own, so the same question would answer
31
+ * differently on a laptop in Madrid and on a server in UTC — a difference
32
+ * nobody asked for and nothing would report. `Date` also accepts a good deal
33
+ * that is not ISO at all, engine by engine, so the shape is checked here
34
+ * instead of being left to it.
35
+ */
36
+ const DATETIME = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(:\d{2}(\.\d{1,9})?)?(Z|[+-]\d{2}:\d{2})$/;
37
+ /** Whether an upstream timestamp says which moment it means. `+0200` counts. */
38
+ const ZONED = /(Z|[+-]\d{2}:?\d{2})$/;
39
+ /**
40
+ * Whether the day a string starts with is one the calendar has.
41
+ *
42
+ * `Date` answers 2 March for 30 February instead of refusing it, so a shape
43
+ * check alone lets an impossible day through as a different, real one. Only the
44
+ * leading calendar day is read, so the offset is none of this check's business
45
+ * and an evening timestamp west of Greenwich is not mistaken for a rollover.
46
+ * Anything that does not start with a day is not this check's to judge.
47
+ */
48
+ function dayExists(value) {
49
+ const lead = /^(\d{4})-(\d{2})-(\d{2})/.exec(value);
50
+ if (lead === null)
51
+ return true;
52
+ const [, year, month, day] = lead.map(Number);
53
+ const calendar = new Date(Date.UTC(year, month - 1, day));
54
+ return calendar.getUTCMonth() + 1 === month && calendar.getUTCDate() === day;
55
+ }
56
+ function parseBound(value, name, endOfDay) {
57
+ const invalid = () => new PontixError("invalid_input", `"${name}" must be an ISO date (2026-10-01) or a datetime that names its ` +
58
+ `offset (2026-10-01T08:00:00Z, 2026-10-01T10:00:00+02:00). Got "${value}".`, { adapterId: ADAPTER_ID });
59
+ if (DATE_ONLY.test(value)) {
60
+ const start = new Date(`${value}T00:00:00.000Z`);
61
+ // `Date` rolls 2026-02-30 over to March instead of refusing it.
62
+ if (Number.isNaN(start.getTime()) || start.toISOString().slice(0, 10) !== value)
63
+ throw invalid();
64
+ return endOfDay ? new Date(start.getTime() + DAY_MS - 1) : start;
65
+ }
66
+ if (!DATETIME.test(value))
67
+ throw invalid();
68
+ const parsed = new Date(value);
69
+ if (Number.isNaN(parsed.getTime()))
70
+ throw invalid();
71
+ // The shape being right does not make the day real: `2026-02-30T00:00:00Z`
72
+ // matches the pattern and becomes 2 March without a word.
73
+ if (!dayExists(value))
74
+ throw invalid();
75
+ return parsed;
76
+ }
77
+ /**
78
+ * The window to ask for.
79
+ *
80
+ * Refused here rather than sent: a `from` after `to` is an empty answer the
81
+ * service would give without saying why, and "no workouts" would read as "you
82
+ * did not train".
83
+ */
84
+ export function resolveWindow(input, now) {
85
+ const to = input.to === undefined ? now : parseBound(input.to, "to", true);
86
+ // Counted back from `to`, not from now: an old `to` with no `from` would
87
+ // otherwise land the default start after its own end.
88
+ const from = input.from === undefined
89
+ ? new Date(to.getTime() - DEFAULT_WINDOW_DAYS * DAY_MS)
90
+ : parseBound(input.from, "from", false);
91
+ if (from.getTime() > to.getTime()) {
92
+ throw new PontixError("invalid_input", `"from" (${from.toISOString()}) is after "to" (${to.toISOString()}).`, { adapterId: ADAPTER_ID });
93
+ }
94
+ return { from, to };
95
+ }
96
+ /**
97
+ * The UTC offset of an IANA zone at a given instant, in milliseconds, or
98
+ * undefined when the zone name is not one this runtime knows.
99
+ */
100
+ function zoneOffsetMs(timeZone, at) {
101
+ try {
102
+ const parts = new Intl.DateTimeFormat("en-US", {
103
+ timeZone,
104
+ hourCycle: "h23",
105
+ year: "numeric",
106
+ month: "2-digit",
107
+ day: "2-digit",
108
+ hour: "2-digit",
109
+ minute: "2-digit",
110
+ second: "2-digit",
111
+ }).formatToParts(new Date(at));
112
+ const part = (type) => Number(parts.find((p) => p.type === type)?.value);
113
+ const wallAsUtc = Date.UTC(part("year"), part("month") - 1, part("day"), part("hour"), part("minute"), part("second"));
114
+ return wallAsUtc - Math.floor(at / 1000) * 1000;
115
+ }
116
+ catch {
117
+ return undefined;
118
+ }
119
+ }
120
+ /**
121
+ * The instant a gym-local wall clock means in an IANA zone, or undefined when
122
+ * the zone is unknown. Two passes, so a time on the far side of a DST change
123
+ * still lands on the right offset.
124
+ */
125
+ function wallClockMs(wallAsUtc, timeZone) {
126
+ const first = zoneOffsetMs(timeZone, wallAsUtc);
127
+ if (first === undefined)
128
+ return undefined;
129
+ const second = zoneOffsetMs(timeZone, wallAsUtc - first) ?? first;
130
+ return wallAsUtc - second;
131
+ }
132
+ /**
133
+ * When a workout says it happened, or nothing readable.
134
+ *
135
+ * The live response gives `completedAt` as a local wall clock with no offset
136
+ * (`2026-11-16T19:08:17.216`) and the IANA zone it is local to in `timezone`
137
+ * (`Europe/Madrid`), so the two are read together. Without the zone, or with
138
+ * one this runtime does not know, the wall clock is read as UTC instead: wrong
139
+ * by a fixed and nameable amount, rather than by wherever the process runs.
140
+ * A timestamp that does carry its own offset is taken as it says.
141
+ *
142
+ * This is also the one place that admits a value could come back unreadable
143
+ * instead of letting `NaN` flow into a comparison and a filter.
144
+ */
145
+ function completedMs(entry) {
146
+ if (entry.completedAt === null)
147
+ return undefined;
148
+ const raw = entry.completedAt;
149
+ // A bare day becomes midnight rather than `2026-10-31Z`, which V8 happens to
150
+ // accept and the ISO grammar does not — so the same value would be a date on
151
+ // one runtime and `undated` on another.
152
+ const wall = ZONED.test(raw) ? raw : DATE_ONLY.test(raw) ? `${raw}T00:00:00` : raw;
153
+ // An upstream day the calendar lacks is unreadable, not a different day:
154
+ // rolled over to 2 March it would be counted in a month the member may not
155
+ // have trained in, with nothing saying so. `undated` is where that shows.
156
+ if (!dayExists(raw))
157
+ return undefined;
158
+ if (ZONED.test(wall)) {
159
+ const ms = Date.parse(wall);
160
+ return Number.isNaN(ms) ? undefined : ms;
161
+ }
162
+ const asUtc = Date.parse(`${wall}Z`);
163
+ if (Number.isNaN(asUtc))
164
+ return undefined;
165
+ if (entry.timezone === null)
166
+ return asUtc;
167
+ return wallClockMs(asUtc, entry.timezone) ?? asUtc;
168
+ }
169
+ /**
170
+ * Sorting, counting, filtering and truncating are computed, so they live here
171
+ * and not in `mappers.json`: a mapper says where a value comes from, not what
172
+ * we work out from it. `execute` only calls this.
173
+ *
174
+ * The window is applied here rather than trusted to the query parameters. The
175
+ * service's own filtering has never been watched — so echoing the window that was
176
+ * asked for while counting whatever came back would turn either mistake into a
177
+ * confident wrong number: a member told they trained five hundred times in
178
+ * October.
179
+ *
180
+ * Entries that cannot be dated are not dropped and not counted as inside. They
181
+ * are reported separately, because "we could not read the dates" and "you did
182
+ * not train" are different answers and only one of them is ever true here.
183
+ */
184
+ export function toWorkoutList(payload, window, limit) {
185
+ // The response is a bare array (live capture, 2026-11-17), so there is no
186
+ // envelope to look through: anything else is drift, and says which keys came.
187
+ if (!Array.isArray(payload)) {
188
+ throw upstreamChanged(ADAPTER_ID, "The workouts response", payload);
189
+ }
190
+ const all = payload.map((row) => workout.parse(applyMapper(MAPPERS, "workout", row, ADAPTER_ID)));
191
+ const from = window.from.getTime();
192
+ const to = window.to.getTime();
193
+ const dated = [];
194
+ let undated = 0;
195
+ for (const entry of all) {
196
+ const at = completedMs(entry);
197
+ if (at === undefined)
198
+ undated += 1;
199
+ else if (at >= from && at <= to)
200
+ dated.push({ entry, at });
201
+ }
202
+ dated.sort((a, b) => b.at - a.at);
203
+ const shown = dated.slice(0, limit).map((row) => row.entry);
204
+ return workoutList.parse({
205
+ window: { from: window.from.toISOString(), to: window.to.toISOString() },
206
+ total: dated.length,
207
+ returned: shown.length,
208
+ truncated: dated.length > shown.length,
209
+ undated,
210
+ workouts: shown,
211
+ });
212
+ }
213
+ /**
214
+ * A window bound as the workouts route accepts it: whole seconds, `Z`.
215
+ *
216
+ * Live, 2026-11-18: the route refuses `toISOString()`'s fraction with 400
217
+ * `completedBefore-wrongFormat`, and answers the same instant without it. The
218
+ * fraction is dropped by widening outwards — `from` down, `to` up — so the end
219
+ * of a bare-date window (23:59:59.999) still reaches the last second of the
220
+ * day, where connected-app sessions are stamped. Anything the extra second lets
221
+ * in is trimmed again by `toWorkoutList`, which filters on the exact window.
222
+ */
223
+ export function toQueryInstant(at, round) {
224
+ const seconds = (round === "down" ? Math.floor : Math.ceil)(at.getTime() / 1000);
225
+ return `${new Date(seconds * 1000).toISOString().slice(0, 19)}Z`;
226
+ }
227
+ export const listWorkouts = defineTool({
228
+ name: "list_workouts",
229
+ description: `List the signed-in member's own gym workouts in a date range, most recent first (default: the last ${DEFAULT_WINDOW_DAYS} days). ` +
230
+ "Each has when it was completed (the gym's local clock, with its `timezone`), the name and kind of the plan it followed when there was one, and how many exercises it held. " +
231
+ "A session logged from a connected app such as Apple Health has no plan, and is often stamped 23:59:59 for its day. " +
232
+ "`total` is how many fell in the window and `returned` how many you got, so say when it was truncated. " +
233
+ "`undated` counts entries whose date could not be read at all: above zero, say some entries could not be dated instead of counting them, " +
234
+ "and when `total` is zero while `undated` is not, do not answer how often they trained — the dates were unreadable, which is not the same as a month off. " +
235
+ "Use this for how often they trained or what they did on a day; it carries no per-set detail.",
236
+ descriptions: {
237
+ es: `Lista los entrenamientos propios del gimnasio de la persona que ha iniciado sesión en un rango de fechas, del más reciente al más antiguo (por defecto, los últimos ${DEFAULT_WINDOW_DAYS} días). ` +
238
+ "Cada uno trae cuándo se completó (la hora local del gimnasio, con su `timezone`), el nombre y el tipo del plan que siguió si hubo alguno, y cuántos ejercicios tenía. " +
239
+ "Una sesión registrada desde una app conectada, como Apple Health, no tiene plan y suele llevar la hora 23:59:59 de su día. " +
240
+ "`total` es cuántos cayeron en el rango y `returned` cuántos se devolvieron, así que avisa cuando se haya truncado. " +
241
+ "`undated` cuenta las entradas cuya fecha no se pudo leer: si es mayor que cero, di que algunas no se pudieron fechar en vez de contarlas, " +
242
+ "y si `total` es cero mientras `undated` no lo es, no respondas cuántas veces entrenó — las fechas no se pudieron leer, que no es lo mismo que un mes sin ir. " +
243
+ "No incluye el detalle de cada serie.",
244
+ },
245
+ input: listWorkoutsInput,
246
+ readOnly: true,
247
+ // No cache: a member may log a session and ask about it straight away.
248
+ async execute(session, input) {
249
+ const window = resolveWindow(input, new Date());
250
+ const { gymLocationId } = await session.auth.token();
251
+ const payload = await session.egymHttp.requestJson("/mwa/api/workouts/v1.0/workouts", {
252
+ query: {
253
+ completedAfter: toQueryInstant(window.from, "down"),
254
+ completedBefore: toQueryInstant(window.to, "up"),
255
+ gymLocationId,
256
+ // Both copied from the capture, which is the only reason they are
257
+ // these values. METRIC is what a Spanish gym reports in, and the
258
+ // locale picks which translation of an activity's name comes back —
259
+ // the mapper prefers `es` for the same reason. Changing either is safe
260
+ // for this tool's shape; it changes what the member reads, so it would
261
+ // want asking rather than assuming.
262
+ measurementSystem: "METRIC",
263
+ locale: "es-ES",
264
+ },
265
+ });
266
+ return toWorkoutList(payload, window, input.limit);
267
+ },
268
+ });
269
+ //# sourceMappingURL=list-workouts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"list-workouts.js","sourceRoot":"","sources":["../../src/tools/list-workouts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,UAAU,EAAE,eAAe,EAAE,CAAC,EAAE,MAAM,sBAAsB,CAAC;AAChG,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,WAAW,EAAoB,MAAM,cAAc,CAAC;AAGtE,MAAM,MAAM,GAAG,UAAU,CAAC;AAC1B,MAAM,mBAAmB,GAAG,EAAE,CAAC;AAC/B,MAAM,aAAa,GAAG,EAAE,CAAC;AACzB,MAAM,SAAS,GAAG,GAAG,CAAC;AAEtB,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,CAAC,MAAM,CAAC;IACxC,IAAI,EAAE,CAAC;SACJ,MAAM,EAAE;SACR,QAAQ,EAAE;SACV,QAAQ,CACP,4KAA4K,mBAAmB,sBAAsB,CACtN;IACH,EAAE,EAAE,CAAC;SACF,MAAM,EAAE;SACR,QAAQ,EAAE;SACV,QAAQ,CACP,sIAAsI,CACvI;IACH,KAAK,EAAE,CAAC;SACL,MAAM,EAAE;SACR,GAAG,EAAE;SACL,GAAG,CAAC,CAAC,CAAC;SACN,GAAG,CAAC,SAAS,CAAC;SACd,OAAO,CAAC,aAAa,CAAC;SACtB,QAAQ,CAAC,2DAA2D,SAAS,kDAAkD,CAAC;CACpI,CAAC,CAAC;AAIH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CAAC,OAAO,CAAC,OAAO,EAAE,KAAK;QAC1B,MAAM,MAAM,GAAG,aAAa,CAAC,KAAK,EAAE,IAAI,IAAI,EAAE,CAAC,CAAC;QAChD,MAAM,EAAE,aAAa,EAAE,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;QACrD,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAU,iCAAiC,EAAE;YAC7F,KAAK,EAAE;gBACL,cAAc,EAAE,cAAc,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC;gBACnD,eAAe,EAAE,cAAc,CAAC,MAAM,CAAC,EAAE,EAAE,IAAI,CAAC;gBAChD,aAAa;gBACb,kEAAkE;gBAClE,iEAAiE;gBACjE,oEAAoE;gBACpE,uEAAuE;gBACvE,uEAAuE;gBACvE,oCAAoC;gBACpC,iBAAiB,EAAE,QAAQ;gBAC3B,MAAM,EAAE,OAAO;aAChB;SACF,CAAC,CAAC;QACH,OAAO,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC;IACrD,CAAC;CACF,CAAC,CAAC"}
@@ -0,0 +1,23 @@
1
+ import { z } from "@pontix/core/adapter";
2
+ import type { DuinSession } from "../session.js";
3
+ export declare const removePlanExerciseInput: z.ZodObject<{
4
+ planId: z.ZodString;
5
+ plannedExerciseId: z.ZodString;
6
+ }, "strip", z.ZodTypeAny, {
7
+ plannedExerciseId: string;
8
+ planId: string;
9
+ }, {
10
+ plannedExerciseId: string;
11
+ planId: string;
12
+ }>;
13
+ export declare const removePlanExercise: import("@pontix/core/adapter").ToolDefinition<DuinSession, z.ZodObject<{
14
+ planId: z.ZodString;
15
+ plannedExerciseId: z.ZodString;
16
+ }, "strip", z.ZodTypeAny, {
17
+ plannedExerciseId: string;
18
+ planId: string;
19
+ }, {
20
+ plannedExerciseId: string;
21
+ planId: string;
22
+ }>>;
23
+ //# sourceMappingURL=remove-plan-exercise.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"remove-plan-exercise.d.ts","sourceRoot":"","sources":["../../src/tools/remove-plan-exercise.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,CAAC,EAAE,MAAM,sBAAsB,CAAC;AAErD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAEjD,eAAO,MAAM,uBAAuB;;;;;;;;;EAMlC,CAAC;AAEH,eAAO,MAAM,kBAAkB;;;;;;;;;GAuB7B,CAAC"}
@@ -0,0 +1,33 @@
1
+ import { defineTool, z } from "@pontix/core/adapter";
2
+ import { editPlan, unknownExercise } from "../plan-edit.js";
3
+ export const removePlanExerciseInput = z.object({
4
+ planId: z.string().min(1).describe("The plan's id, from `duin_list_plans`. It must be one of your own (editable) plans."),
5
+ plannedExerciseId: z
6
+ .string()
7
+ .min(1)
8
+ .describe("The exercise's entry in this plan: `plannedExerciseId` from `duin_get_plan`, not the catalogue activity id."),
9
+ });
10
+ export const removePlanExercise = defineTool({
11
+ name: "remove_plan_exercise",
12
+ description: "WRITES to your DUIN account, and removes data: deletes one exercise, with its sets, from one of your own training plans. " +
13
+ "The service has no per-exercise call, so the whole plan is read and then REWRITTEN without that exercise; the others are sent back as they were read. " +
14
+ "Refused, with nothing sent, when the plan is not editable or has no exercise with that `plannedExerciseId`. " +
15
+ "Returns the plan as `duin_get_plan` does, read again after the change.",
16
+ descriptions: {
17
+ es: "ESCRIBE en tu cuenta de DUIN y borra datos: elimina un ejercicio, con sus series, de uno de tus planes de entrenamiento. " +
18
+ "El servicio no tiene una llamada por ejercicio, así que se lee el plan completo y se REESCRIBE sin ese ejercicio; los demás se reenvían tal como se leyeron. " +
19
+ "Se rechaza, sin enviar nada, si el plan no es editable o no tiene ningún ejercicio con ese `plannedExerciseId`. " +
20
+ "Devuelve el plan como `duin_get_plan`, leído de nuevo tras el cambio.",
21
+ },
22
+ input: removePlanExerciseInput,
23
+ readOnly: false,
24
+ async execute(session, input) {
25
+ return editPlan(session, input.planId, (body) => {
26
+ const kept = body.exercises.filter((exercise) => String(exercise.id) !== input.plannedExerciseId);
27
+ if (kept.length === body.exercises.length)
28
+ throw unknownExercise(input.plannedExerciseId, input.planId);
29
+ return { ...body, exercises: kept };
30
+ });
31
+ },
32
+ });
33
+ //# sourceMappingURL=remove-plan-exercise.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"remove-plan-exercise.js","sourceRoot":"","sources":["../../src/tools/remove-plan-exercise.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,CAAC,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAG5D,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC9C,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,qFAAqF,CAAC;IACzH,iBAAiB,EAAE,CAAC;SACjB,MAAM,EAAE;SACR,GAAG,CAAC,CAAC,CAAC;SACN,QAAQ,CAAC,6GAA6G,CAAC;CAC3H,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,kBAAkB,GAAG,UAAU,CAA8C;IACxF,IAAI,EAAE,sBAAsB;IAC5B,WAAW,EACT,2HAA2H;QAC3H,wJAAwJ;QACxJ,8GAA8G;QAC9G,wEAAwE;IAC1E,YAAY,EAAE;QACZ,EAAE,EACA,2HAA2H;YAC3H,+JAA+J;YAC/J,kHAAkH;YAClH,uEAAuE;KAC1E;IACD,KAAK,EAAE,uBAAuB;IAC9B,QAAQ,EAAE,KAAK;IACf,KAAK,CAAC,OAAO,CAAC,OAAO,EAAE,KAAK;QAC1B,OAAO,QAAQ,CAAC,OAAO,EAAE,KAAK,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE;YAC9C,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC,KAAK,KAAK,CAAC,iBAAiB,CAAC,CAAC;YAClG,IAAI,IAAI,CAAC,MAAM,KAAK,IAAI,CAAC,SAAS,CAAC,MAAM;gBAAE,MAAM,eAAe,CAAC,KAAK,CAAC,iBAAiB,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;YACxG,OAAO,EAAE,GAAG,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;QACtC,CAAC,CAAC,CAAC;IACL,CAAC;CACF,CAAC,CAAC"}
@@ -0,0 +1,68 @@
1
+ import { z } from "@pontix/core/adapter";
2
+ import { type ActivityList } from "../shapes.js";
3
+ import type { DuinSession } from "../session.js";
4
+ export declare const searchActivitiesInput: z.ZodObject<{
5
+ name: z.ZodOptional<z.ZodString>;
6
+ category: z.ZodOptional<z.ZodEnum<["STRENGTH", "COORDINATION", "MOBILITY", "FITNESS_CLASS"]>>;
7
+ page: z.ZodDefault<z.ZodNumber>;
8
+ limit: z.ZodDefault<z.ZodNumber>;
9
+ }, "strip", z.ZodTypeAny, {
10
+ page: number;
11
+ limit: number;
12
+ name?: string | undefined;
13
+ category?: "STRENGTH" | "COORDINATION" | "MOBILITY" | "FITNESS_CLASS" | undefined;
14
+ }, {
15
+ name?: string | undefined;
16
+ category?: "STRENGTH" | "COORDINATION" | "MOBILITY" | "FITNESS_CLASS" | undefined;
17
+ page?: number | undefined;
18
+ limit?: number | undefined;
19
+ }>;
20
+ type Input = z.infer<typeof searchActivitiesInput>;
21
+ /**
22
+ * Reading the envelope and the rows together is computed, so it lives here
23
+ * and not in `mappers.json`, as in `toPlanList`.
24
+ *
25
+ * **One unreadable row fails the whole call, on purpose**: the decision, and
26
+ * what it would take to re-open it, is written up on `toPlanList`.
27
+ *
28
+ * `hasMore` is the service's own `nextPageToken` and nothing else.
29
+ *
30
+ * Deriving it from `count` as well was tried and taken back out. One page is
31
+ * all that is ever in hand: nothing in a response says how many rows the pages
32
+ * behind it held, and `MAX_LIMIT` is the size one capture used rather than a
33
+ * published contract. Every arithmetic that fills that gap guesses. Measuring
34
+ * earlier pages at the size requested ends pagination early whenever the
35
+ * service hands back a short page, losing rows; measuring them at the size of
36
+ * the page in hand calls the ordinary last partial page unfinished, costing a
37
+ * request on every search whose total is not a multiple of the limit, and
38
+ * leans on the service answering an out-of-range page with no rows — which
39
+ * nothing here has observed it do.
40
+ *
41
+ * So this reports what the service said and does not invent the rest, which is
42
+ * what the rest of this connector does with a value it was not given. The cost
43
+ * is named: if that key is renamed, `hasMore` goes false and paging stops
44
+ * early. That is drift for the operator to catch — `pontix capture duin`
45
+ * reports which candidate key each field hit — and deliberately not something
46
+ * the model is asked to infer, because the comparison that would reveal it,
47
+ * `total` against the rows in hand, is equally true on the ordinary last page
48
+ * of a large result, where nothing is wrong at all.
49
+ */
50
+ export declare function toActivityList(payload: unknown, requested: Pick<Input, "page">): ActivityList;
51
+ export declare const searchActivities: import("@pontix/core/adapter").ToolDefinition<DuinSession, z.ZodObject<{
52
+ name: z.ZodOptional<z.ZodString>;
53
+ category: z.ZodOptional<z.ZodEnum<["STRENGTH", "COORDINATION", "MOBILITY", "FITNESS_CLASS"]>>;
54
+ page: z.ZodDefault<z.ZodNumber>;
55
+ limit: z.ZodDefault<z.ZodNumber>;
56
+ }, "strip", z.ZodTypeAny, {
57
+ page: number;
58
+ limit: number;
59
+ name?: string | undefined;
60
+ category?: "STRENGTH" | "COORDINATION" | "MOBILITY" | "FITNESS_CLASS" | undefined;
61
+ }, {
62
+ name?: string | undefined;
63
+ category?: "STRENGTH" | "COORDINATION" | "MOBILITY" | "FITNESS_CLASS" | undefined;
64
+ page?: number | undefined;
65
+ limit?: number | undefined;
66
+ }>>;
67
+ export {};
68
+ //# sourceMappingURL=search-activities.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"search-activities.d.ts","sourceRoot":"","sources":["../../src/tools/search-activities.ts"],"names":[],"mappings":"AAAA,OAAO,EAA2B,CAAC,EAAE,MAAM,sBAAsB,CAAC;AAElE,OAAO,EAA0B,KAAK,YAAY,EAAE,MAAM,cAAc,CAAC;AACzE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAkBjD,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;EA2BhC,CAAC;AAEH,KAAK,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAC;AAEnD;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,IAAI,CAAC,KAAK,EAAE,MAAM,CAAC,GAAG,YAAY,CAe7F;AAED,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;GAmD3B,CAAC"}