@wilm-ai/wilma-cli 2.3.2 → 2.4.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/README.md CHANGED
@@ -65,7 +65,7 @@ Starts a stdio MCP server with read-only Wilma tools (`wilma_summary`, `wilma_sc
65
65
  `wilma news <id>` lists every link in a bulletin (`resources`). Any resource can be downloaded with `wilma news <id> download <resource> [--output <directory>]` (the resource id also accepts a bare number, e.g. `1` for `resource-1`). Wilma-hosted files download through the session; external links are fetched without your Wilma login, and only from public websites. The result's `status` says what happened: `downloaded` (use the returned `path`) or `not_a_file` when the link answered with a web page (for example a sharing link that needs signing in — open it in a browser instead). `--output` defaults to the current directory; existing files are never overwritten.
66
66
 
67
67
  ## Several Wilmas
68
- Children at schools on different Wilmas need one login per Wilma. Run `wilma login` again (or press "Add another Wilma" on the login page); commands then cover every child, and each child carries the `wilma` it belongs to.
68
+ Children at schools on different Wilmas need one login per Wilma. Run `wilma login` again (or press "Add another school's Wilma" on the login page); commands then cover every child, and each child carries the `wilma` it belongs to.
69
69
  ```bash
70
70
  wilma accounts # saved logins, numbered
71
71
  wilma accounts remove <number> # or the Wilma name or username; also ends that login's Wilma session
package/dist/access.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { WilmaAccess } from "./agent-data.js";
2
+ import { type StoredProfile } from "./config.js";
2
3
  import { type ActiveAccount } from "./credentials.js";
3
4
  /**
4
5
  * Wilma access for the saved (or environment) logins — the same for CLI
@@ -24,3 +25,20 @@ export declare function logoutAccounts(accounts: ActiveAccount[]): Promise<{
24
25
  }[];
25
26
  hint: string;
26
27
  }>;
28
+ export type RemovedSession = {
29
+ session: "ended" | "none";
30
+ } | {
31
+ session: "not_ended";
32
+ message: string;
33
+ };
34
+ /**
35
+ * Remove a saved login (`wilma accounts remove`, the login page's Remove) and
36
+ * end its Wilma session; the other logins keep theirs. The login is removed
37
+ * even when Wilma can't be reached: its saved session is forgotten anyway,
38
+ * and Wilma ends the session when it expires.
39
+ */
40
+ export declare function removeLogin(id: string): Promise<{
41
+ removed: StoredProfile;
42
+ } & RemovedSession>;
43
+ /** Which of a login's children aren't read (unticked on the login page); only children the login lists count. */
44
+ export declare function setHiddenChildren(id: string, hidden: string[]): Promise<void>;
package/dist/access.js CHANGED
@@ -1,5 +1,5 @@
1
- import { WilmaAccess, logoutSession } from "./agent-data.js";
2
- import { loadConfig, saveConfig } from "./config.js";
1
+ import { WilmaAccess, WilmaAiError, forgetSession, logoutSession } from "./agent-data.js";
2
+ import { loadConfig, revealSecret, saveConfig, savedStudent } from "./config.js";
3
3
  import { mfaCallbackFor } from "./credentials.js";
4
4
  /**
5
5
  * Wilma access for the saved (or environment) logins — the same for CLI
@@ -14,12 +14,13 @@ export function createAccess(accounts, opts = {}) {
14
14
  mfa: mfaCallbackFor(index === 0 && opts.totpSecret ? opts.totpSecret : account.totpSecret),
15
15
  label: account.stored?.tenantName ?? account.profile.baseUrl,
16
16
  knownStudents: account.stored?.students,
17
+ hidden: account.stored?.hidden,
17
18
  onStudents: async (students) => {
18
19
  const stored = account.stored;
19
20
  // An empty answer from Wilma keeps the saved list (see knownStudents).
20
21
  if (!stored || !students.length)
21
22
  return;
22
- const fresh = students.map((s) => ({ studentNumber: s.studentNumber, name: s.name }));
23
+ const fresh = students.map(savedStudent);
23
24
  if (JSON.stringify(fresh) === JSON.stringify(stored.students ?? []))
24
25
  return;
25
26
  const latest = await loadConfig();
@@ -54,3 +55,47 @@ export async function logoutAccounts(accounts) {
54
55
  : "No saved Wilma login, so there was nothing to log out.",
55
56
  };
56
57
  }
58
+ /**
59
+ * Remove a saved login (`wilma accounts remove`, the login page's Remove) and
60
+ * end its Wilma session; the other logins keep theirs. The login is removed
61
+ * even when Wilma can't be reached: its saved session is forgotten anyway,
62
+ * and Wilma ends the session when it expires.
63
+ */
64
+ export async function removeLogin(id) {
65
+ const config = await loadConfig();
66
+ const removed = config.profiles.find((p) => p.id === id);
67
+ if (!removed)
68
+ throw new WilmaAiError("unknown_account", "That login isn't saved any more.");
69
+ config.profiles = config.profiles.filter((p) => p.id !== id);
70
+ if (config.lastProfileId === id)
71
+ config.lastProfileId = config.profiles[0]?.id ?? null;
72
+ await saveConfig(config);
73
+ return { removed, ...(await endSession(removed)) };
74
+ }
75
+ async function endSession(removed) {
76
+ const password = revealSecret(removed.passwordObfuscated);
77
+ if (!password)
78
+ return { session: "none" };
79
+ const profile = { baseUrl: removed.tenantUrl, username: removed.username, password };
80
+ try {
81
+ return { session: (await logoutSession(profile)) ? "ended" : "none" };
82
+ }
83
+ catch (err) {
84
+ await forgetSession(profile);
85
+ return { session: "not_ended", message: err instanceof Error ? err.message : String(err) };
86
+ }
87
+ }
88
+ /** Which of a login's children aren't read (unticked on the login page); only children the login lists count. */
89
+ export async function setHiddenChildren(id, hidden) {
90
+ const config = await loadConfig();
91
+ const target = config.profiles.find((p) => p.id === id);
92
+ if (!target)
93
+ throw new WilmaAiError("unknown_account", "That login isn't saved any more.");
94
+ const known = new Set((target.students ?? []).map((s) => s.studentNumber));
95
+ const kept = [...new Set(hidden)].filter((number) => known.has(number));
96
+ if (kept.length)
97
+ target.hidden = kept;
98
+ else
99
+ delete target.hidden;
100
+ await saveConfig(config);
101
+ }
@@ -1,4 +1,4 @@
1
- import { WilmaClient, type LessonNote, type Message, type MessageFolder, type MfaCallback, type NewsItem, type NewsResource, type OverviewData, type StudentInfo, type WilmaProfile } from "@wilm-ai/wilma-client";
1
+ import { WilmaClient, type LessonNote, type Message, type MessageFolder, type MfaCallback, type NewsItem, type NewsResource, type OverviewData, type ScheduleLesson, type StudentInfo, type WilmaProfile } from "@wilm-ai/wilma-client";
2
2
  import type { SessionStore } from "./session-store.js";
3
3
  /**
4
4
  * An error with a stable code for agents and scripts (the CLI's JSON errors
@@ -19,11 +19,22 @@ export type ScheduleDateSelection = {
19
19
  outputWhen: string;
20
20
  };
21
21
  export declare const SCHEDULE_WHEN: readonly ["today", "tomorrow", "week", "next-week"];
22
+ /** The longest period one schedule request covers. */
23
+ export declare const SCHEDULE_MAX_DAYS = 31;
24
+ /**
25
+ * An event invitation as listed: the message, plus the family's answer as
26
+ * Wilma's list shows it ("Applied" with the chosen time, "ExpiredReg"…;
27
+ * null when it shows none).
28
+ */
29
+ export type ListedMessage = Message & {
30
+ invitationStatus?: string | null;
31
+ invitationInfo?: string | null;
32
+ };
22
33
  /** Everything a daily summary is built from (see fetchSummaryInputs). */
23
34
  export interface SummaryInputs {
24
35
  overview: OverviewData;
25
36
  news: NewsItem[];
26
- messages: Message[];
37
+ messages: ListedMessage[];
27
38
  lessonNotes: LessonNote[];
28
39
  /** Parts Wilma couldn't give this time (the rest of the summary is still right). */
29
40
  unavailable: string[];
@@ -44,7 +55,10 @@ export interface AccessAccount {
44
55
  knownStudents?: {
45
56
  studentNumber: string;
46
57
  name: string;
58
+ role?: StudentInfo["role"];
47
59
  }[];
60
+ /** Student numbers unticked on the login page (a profile Wilma lists twice): not read. */
61
+ hidden?: string[];
48
62
  }
49
63
  type AccountStudent = StudentInfo & {
50
64
  account: number;
@@ -106,9 +120,17 @@ export declare function matchStudents<T extends {
106
120
  studentNumber: string;
107
121
  name: string;
108
122
  }>(students: T[], student: string): T[];
123
+ /** Whose login it is: a student's own when Wilma lists only the student themself, a guardian's when it says so. */
124
+ export declare function roleOf(students: {
125
+ role?: StudentInfo["role"];
126
+ }[]): StudentInfo["role"];
109
127
  export declare class WilmaAccess {
110
128
  private readonly accounts;
111
129
  private studentsCache;
130
+ /** The children each login lists (by login index), including those read through another login. */
131
+ private readonly listed;
132
+ /** Why a login failed (by login index), while others worked. */
133
+ private readonly failures;
112
134
  /** One logged-in session per Wilma login, shared by every child on it. */
113
135
  private readonly sessions;
114
136
  /** Logins that failed while other logins worked. */
@@ -122,8 +144,37 @@ export declare class WilmaAccess {
122
144
  private labelOf;
123
145
  private ref;
124
146
  students(): Promise<AccountStudent[]>;
125
- /** The children as tools and commands show them (with their Wilma when there are several). */
126
- studentList(): Promise<StudentRef[]>;
147
+ /**
148
+ * The children as tools and commands show them (with their Wilma when there
149
+ * are several), and whose login reads each: a guardian's, or the student's own.
150
+ */
151
+ studentList(): Promise<(StudentRef & {
152
+ role?: StudentInfo["role"];
153
+ })[]>;
154
+ /**
155
+ * Each login: its Wilma, username, whose it is (a guardian's, or a
156
+ * student's own; missing when Wilma doesn't say) and the children it lists.
157
+ * A child another login on the same Wilma also lists is read through one of
158
+ * them only; `readVia` names the other login's username. A child unticked
159
+ * on the login page has `hidden: true` and isn't read.
160
+ */
161
+ logins(): Promise<{
162
+ problem?: string | undefined;
163
+ children: ({
164
+ name: string;
165
+ studentNumber: string;
166
+ hidden: boolean;
167
+ } | {
168
+ readVia?: string | undefined;
169
+ name: string;
170
+ studentNumber: string;
171
+ hidden?: undefined;
172
+ })[];
173
+ role?: "guardian" | "student" | undefined;
174
+ wilma: string;
175
+ username: string;
176
+ }[]>;
177
+ private sameWilma;
127
178
  selectStudents(student?: string): Promise<AccountStudent[]>;
128
179
  private client;
129
180
  private perStudent;
@@ -142,8 +193,8 @@ export declare class WilmaAccess {
142
193
  unavailable?: string[] | undefined;
143
194
  today: string;
144
195
  tomorrow: string;
145
- todaySchedule: import("@wilm-ai/wilma-client").ScheduleLesson[];
146
- tomorrowSchedule: import("@wilm-ai/wilma-client").ScheduleLesson[];
196
+ todaySchedule: ScheduleLesson[];
197
+ tomorrowSchedule: ScheduleLesson[];
147
198
  upcomingExams: import("@wilm-ai/wilma-client").UpcomingExam[];
148
199
  homework: import("@wilm-ai/wilma-client").HomeworkItem[];
149
200
  lessonNotes: LessonNote[];
@@ -154,6 +205,8 @@ export declare class WilmaAccess {
154
205
  pinned: boolean;
155
206
  }[];
156
207
  messages: {
208
+ invitationStatus?: string | null | undefined;
209
+ invitationInfo?: string | null | undefined;
157
210
  wilmaId: number;
158
211
  subject: string;
159
212
  sentAt: Date;
@@ -179,8 +232,8 @@ export declare class WilmaAccess {
179
232
  unavailable?: string[] | undefined;
180
233
  today: string;
181
234
  tomorrow: string;
182
- todaySchedule: import("@wilm-ai/wilma-client").ScheduleLesson[];
183
- tomorrowSchedule: import("@wilm-ai/wilma-client").ScheduleLesson[];
235
+ todaySchedule: ScheduleLesson[];
236
+ tomorrowSchedule: ScheduleLesson[];
184
237
  upcomingExams: import("@wilm-ai/wilma-client").UpcomingExam[];
185
238
  homework: import("@wilm-ai/wilma-client").HomeworkItem[];
186
239
  lessonNotes: LessonNote[];
@@ -191,6 +244,8 @@ export declare class WilmaAccess {
191
244
  pinned: boolean;
192
245
  }[];
193
246
  messages: {
247
+ invitationStatus?: string | null | undefined;
248
+ invitationInfo?: string | null | undefined;
194
249
  wilmaId: number;
195
250
  subject: string;
196
251
  sentAt: Date;
@@ -211,17 +266,50 @@ export declare class WilmaAccess {
211
266
  when?: (typeof SCHEDULE_WHEN)[number];
212
267
  date?: string;
213
268
  weekday?: string;
269
+ from?: string;
270
+ to?: string;
214
271
  }): Promise<{
215
272
  students: ({
216
273
  student: StudentRef;
217
274
  } & {
218
- lessons: import("@wilm-ai/wilma-client").ScheduleLesson[];
275
+ lessons: ScheduleLesson[];
276
+ })[];
277
+ problems: {
278
+ wilma: string;
279
+ message: string;
280
+ }[];
281
+ from: string;
282
+ to: string;
283
+ date?: undefined;
284
+ weekStart?: undefined;
285
+ weekEnd?: undefined;
286
+ when: string;
287
+ } | {
288
+ students: ({
289
+ student: StudentRef;
290
+ } & {
291
+ lessons: ScheduleLesson[];
292
+ })[];
293
+ problems?: undefined;
294
+ from: string;
295
+ to: string;
296
+ date?: undefined;
297
+ weekStart?: undefined;
298
+ weekEnd?: undefined;
299
+ when: string;
300
+ } | {
301
+ students: ({
302
+ student: StudentRef;
303
+ } & {
304
+ lessons: ScheduleLesson[];
219
305
  })[];
220
306
  problems: {
221
307
  wilma: string;
222
308
  message: string;
223
309
  }[];
224
310
  date: string;
311
+ from?: undefined;
312
+ to?: undefined;
225
313
  weekStart?: undefined;
226
314
  weekEnd?: undefined;
227
315
  when: string;
@@ -229,10 +317,12 @@ export declare class WilmaAccess {
229
317
  students: ({
230
318
  student: StudentRef;
231
319
  } & {
232
- lessons: import("@wilm-ai/wilma-client").ScheduleLesson[];
320
+ lessons: ScheduleLesson[];
233
321
  })[];
234
322
  problems?: undefined;
235
323
  date: string;
324
+ from?: undefined;
325
+ to?: undefined;
236
326
  weekStart?: undefined;
237
327
  weekEnd?: undefined;
238
328
  when: string;
@@ -240,7 +330,7 @@ export declare class WilmaAccess {
240
330
  students: ({
241
331
  student: StudentRef;
242
332
  } & {
243
- lessons: import("@wilm-ai/wilma-client").ScheduleLesson[];
333
+ lessons: ScheduleLesson[];
244
334
  })[];
245
335
  problems: {
246
336
  wilma: string;
@@ -248,17 +338,21 @@ export declare class WilmaAccess {
248
338
  }[];
249
339
  weekStart: string;
250
340
  weekEnd: string;
341
+ from?: undefined;
342
+ to?: undefined;
251
343
  date?: undefined;
252
344
  when: string;
253
345
  } | {
254
346
  students: ({
255
347
  student: StudentRef;
256
348
  } & {
257
- lessons: import("@wilm-ai/wilma-client").ScheduleLesson[];
349
+ lessons: ScheduleLesson[];
258
350
  })[];
259
351
  problems?: undefined;
260
352
  weekStart: string;
261
353
  weekEnd: string;
354
+ from?: undefined;
355
+ to?: undefined;
262
356
  date?: undefined;
263
357
  when: string;
264
358
  }>;
@@ -304,9 +398,16 @@ export declare class WilmaAccess {
304
398
  })[];
305
399
  problems?: undefined;
306
400
  }>;
401
+ /**
402
+ * Exam grades: the newest the front page lists, or with `from` (to `to`,
403
+ * default today) Wilma's list of past exams for that period (Kokeet >
404
+ * Menneet), including exams still waiting for a grade (grade: null).
405
+ */
307
406
  grades(opts?: {
308
407
  student?: string;
309
408
  limit?: number;
409
+ from?: string;
410
+ to?: string;
310
411
  }): Promise<{
311
412
  students: ({
312
413
  student: StudentRef;
@@ -324,6 +425,27 @@ export declare class WilmaAccess {
324
425
  grades: import("@wilm-ai/wilma-client").ExamGrade[];
325
426
  })[];
326
427
  problems?: undefined;
428
+ } | {
429
+ students: ({
430
+ student: StudentRef;
431
+ } & {
432
+ grades: import("@wilm-ai/wilma-client").PastExam[];
433
+ })[];
434
+ problems: {
435
+ wilma: string;
436
+ message: string;
437
+ }[];
438
+ from: string;
439
+ to: string;
440
+ } | {
441
+ students: ({
442
+ student: StudentRef;
443
+ } & {
444
+ grades: import("@wilm-ai/wilma-client").PastExam[];
445
+ })[];
446
+ problems?: undefined;
447
+ from: string;
448
+ to: string;
327
449
  }>;
328
450
  /** Lesson notes for one day (default today), the last `days` days, or `from`–`to` (to defaults to today). */
329
451
  lessonNotes(opts?: {
@@ -416,6 +538,54 @@ export declare class WilmaAccess {
416
538
  })[];
417
539
  problems?: undefined;
418
540
  }>;
541
+ /**
542
+ * The child's class, class teacher and other supervisors (front page), and
543
+ * their own teachers (Wilma's recipient list) with what each teaches them,
544
+ * from this and next week's timetable. Parts Wilma can't give are listed in
545
+ * `unavailable`.
546
+ */
547
+ contacts(opts?: {
548
+ student?: string;
549
+ }): Promise<{
550
+ students: ({
551
+ student: StudentRef;
552
+ } & {
553
+ contacts: {
554
+ unavailable?: string[] | undefined;
555
+ className: string | null;
556
+ supervisors: {
557
+ name: string;
558
+ role: string;
559
+ }[];
560
+ teachers: {
561
+ name: string;
562
+ subjects: string[];
563
+ }[];
564
+ };
565
+ })[];
566
+ problems: {
567
+ wilma: string;
568
+ message: string;
569
+ }[];
570
+ } | {
571
+ students: ({
572
+ student: StudentRef;
573
+ } & {
574
+ contacts: {
575
+ unavailable?: string[] | undefined;
576
+ className: string | null;
577
+ supervisors: {
578
+ name: string;
579
+ role: string;
580
+ }[];
581
+ teachers: {
582
+ name: string;
583
+ subjects: string[];
584
+ }[];
585
+ };
586
+ })[];
587
+ problems?: undefined;
588
+ }>;
419
589
  printouts(opts?: {
420
590
  student?: string;
421
591
  }): Promise<{
@@ -450,7 +620,7 @@ export declare class WilmaAccess {
450
620
  students: ({
451
621
  student: StudentRef;
452
622
  } & {
453
- messages: Message[];
623
+ messages: ListedMessage[];
454
624
  })[];
455
625
  problems: {
456
626
  wilma: string;
@@ -460,7 +630,7 @@ export declare class WilmaAccess {
460
630
  students: ({
461
631
  student: StudentRef;
462
632
  } & {
463
- messages: Message[];
633
+ messages: ListedMessage[];
464
634
  })[];
465
635
  problems?: undefined;
466
636
  }>;