recess-cli 3.19.1 → 3.19.2

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/args.js CHANGED
@@ -7,6 +7,7 @@ import { CliError } from "./errors.js";
7
7
  export const REPEATABLE_FLAGS = new Set([
8
8
  "amount",
9
9
  "bill-date",
10
+ "due-date",
10
11
  "existing-kid",
11
12
  "kid",
12
13
  "staff-note",
package/dist/cli.js CHANGED
@@ -12,6 +12,7 @@ import { runApplicationsCommand } from "./commands/applications.js";
12
12
  import { runAppsCommand } from "./commands/apps.js";
13
13
  import { runChannelsCommand } from "./commands/channels.js";
14
14
  import { runChatLogsCommand } from "./commands/chat-logs.js";
15
+ import { runLibraryBooksCommand } from "./commands/library-books.js";
15
16
  import { runDbCommand } from "./commands/db.js";
16
17
  import { runRoomsCommand } from "./commands/rooms.js";
17
18
  import { runFeedCommand } from "./commands/feed.js";
@@ -5993,6 +5994,9 @@ export async function executeRecessCommand(argv, options = {}) {
5993
5994
  if (noun === "chat-logs") {
5994
5995
  return runChatLogsCommand({ parsed, api, writeCommand });
5995
5996
  }
5997
+ if (noun === "library-books") {
5998
+ return runLibraryBooksCommand({ parsed, api, writeCommand });
5999
+ }
5996
6000
  if (noun === "db") {
5997
6001
  return runDbCommand({ parsed, api, writeCommand });
5998
6002
  }
@@ -125,8 +125,9 @@ const FAMILY_AI_COMMANDS = new Set([
125
125
  "goal-templates get",
126
126
  "goal-templates list",
127
127
  "goal-templates patch-spec",
128
- // publish: the server allows staff or the author, and only while every kid
129
- // reading the course is one the caller manages.
128
+ // publish: the server allows staff or the author. A guardian or guide author
129
+ // reaches every kid on their own uncurated course; anyone else only while
130
+ // every kid reading it is one the caller manages.
130
131
  "goal-templates publish",
131
132
  "goal-templates set-metadata",
132
133
  "goal-templates snapshot-files",
@@ -153,6 +154,10 @@ const FAMILY_AI_COMMANDS = new Set([
153
154
  "goals queue get",
154
155
  "goals queue set",
155
156
  "goals unarchive",
157
+ "library-books add",
158
+ "library-books get",
159
+ "library-books list",
160
+ "library-books search",
156
161
  "memories context",
157
162
  "memories log",
158
163
  "onboarding pairing-code",
@@ -0,0 +1,105 @@
1
+ import { unwrap } from "../api.js";
2
+ import { flagNumber, flagString } from "../args.js";
3
+ import { CliError } from "../errors.js";
4
+ import { assertChoice, positional } from "./shared.js";
5
+ const MD5 = /^[0-9a-f]{32}$/i;
6
+ async function resolveAddBody({ parsed, api }) {
7
+ const fromSearch = flagNumber(parsed, "from-search");
8
+ if (fromSearch !== undefined) {
9
+ const conflicting = [
10
+ "md5",
11
+ "title",
12
+ "author",
13
+ "extension",
14
+ "cover-url",
15
+ ].filter((name) => parsed.flags.has(name));
16
+ if (conflicting.length > 0) {
17
+ throw new CliError("invalid_arguments", `--from-search cannot be combined with ${conflicting.map((name) => `--${name}`).join(", ")}.`);
18
+ }
19
+ if (!Number.isInteger(fromSearch) || fromSearch < 1) {
20
+ throw new CliError("invalid_arguments", "--from-search must be a 1-based result number from `library-books search`.");
21
+ }
22
+ const q = flagString(parsed, "query", { required: true });
23
+ const { web } = unwrap(await api.client.GET("/library-books/search", {
24
+ params: { query: { q } },
25
+ }));
26
+ const pick = web[fromSearch - 1];
27
+ if (!pick) {
28
+ throw new CliError("invalid_arguments", `Search for "${q}" returned ${web.length} web result(s); --from-search ${fromSearch} is out of range.`);
29
+ }
30
+ return {
31
+ body: {
32
+ md5: pick.md5,
33
+ title: pick.title,
34
+ author: pick.author,
35
+ extension: pick.extension,
36
+ coverUrl: pick.coverUrl,
37
+ },
38
+ alreadyInLibrary: pick.libraryBookId,
39
+ };
40
+ }
41
+ if (parsed.flags.has("query")) {
42
+ throw new CliError("invalid_arguments", "--query is only used with --from-search.");
43
+ }
44
+ const md5 = flagString(parsed, "md5", { required: true });
45
+ if (!MD5.test(md5)) {
46
+ throw new CliError("invalid_arguments", "--md5 must be 32 hex characters.");
47
+ }
48
+ const author = flagString(parsed, "author");
49
+ const coverUrl = flagString(parsed, "cover-url");
50
+ return {
51
+ body: {
52
+ md5: md5.toLowerCase(),
53
+ title: flagString(parsed, "title", { required: true }),
54
+ extension: assertChoice(flagString(parsed, "extension", { required: true }), ["pdf", "epub"], "--extension"),
55
+ ...(author === undefined ? {} : { author }),
56
+ ...(coverUrl === undefined ? {} : { coverUrl }),
57
+ },
58
+ alreadyInLibrary: null,
59
+ };
60
+ }
61
+ export async function runLibraryBooksCommand(context) {
62
+ const { parsed, api, writeCommand } = context;
63
+ const verb = parsed.positionals[1];
64
+ if (verb === "search") {
65
+ const q = positional(parsed, 2, "search query");
66
+ const result = unwrap(await api.client.GET("/library-books/search", {
67
+ params: { query: { q } },
68
+ }));
69
+ return {
70
+ ...result,
71
+ web: result.web.map((row, index) => ({ result: index + 1, ...row })),
72
+ };
73
+ }
74
+ if (verb === "list") {
75
+ const q = flagString(parsed, "q");
76
+ return unwrap(await api.client.GET("/library-books/", {
77
+ params: { query: q === undefined ? {} : { q } },
78
+ }));
79
+ }
80
+ if (verb === "get") {
81
+ const id = positional(parsed, 2, "library book ID");
82
+ const book = unwrap(await api.client.GET("/library-books/{id}", {
83
+ params: { path: { id } },
84
+ }));
85
+ const listed = unwrap(await api.client.GET("/library-books/", {
86
+ params: { query: { q: book.title.slice(0, 200) } },
87
+ }));
88
+ const challengeId = listed.items.find((item) => item.id === book.id)?.challengeId ?? null;
89
+ return { ...book, challengeId };
90
+ }
91
+ if (verb === "add") {
92
+ const { body, alreadyInLibrary } = await resolveAddBody(context);
93
+ return writeCommand(parsed, {
94
+ action: "add a book to the shared library from the web",
95
+ target: { md5: body.md5 },
96
+ request: body,
97
+ details: {
98
+ alreadyInLibrary,
99
+ consequence: "Creates a PROCESSING library book and queues download + processing; an md5 already in the library returns the existing book unchanged.",
100
+ },
101
+ }, async () => unwrap(await api.client.POST("/library-books/from-web", { body })));
102
+ }
103
+ throw new CliError("invalid_arguments", "Use library-books search|list|get|add.");
104
+ }
105
+ //# sourceMappingURL=library-books.js.map
package/dist/help.js CHANGED
@@ -545,6 +545,12 @@ Usage:
545
545
  [--lessons-dir <dir>] [--emoji TEXT] [--grade-min N] [--grade-max N]
546
546
  [--visibility PUBLIC|STAFF] [--confirm]
547
547
  recess [--json] tutor-templates delete <slug> [--confirm]
548
+ recess [--json] library-books search <query>
549
+ recess [--json] library-books list [--q TEXT]
550
+ recess [--json] library-books get <book-id>
551
+ recess [--json] library-books add (--md5 <md5> --title TEXT [--author TEXT]
552
+ --extension pdf|epub [--cover-url <url>] | --from-search N --query TEXT)
553
+ [--confirm]
548
554
  recess [--json] goals notes list --student <goal-owner-id> --goal <goal-id>
549
555
  recess [--json] goals notes get --student <goal-owner-id> --goal <goal-id>
550
556
  [--lesson <item-key|module-ref>]
@@ -1249,6 +1255,10 @@ export const COMMAND_SUMMARIES = {
1249
1255
  "tutor-templates create": "Create a tutor template.",
1250
1256
  "tutor-templates update": "Update a tutor template.",
1251
1257
  "tutor-templates delete": "Delete a tutor template.",
1258
+ "library-books search": "Search the book library and the web for books.",
1259
+ "library-books list": "List books in the shared library.",
1260
+ "library-books get": "Read one library book: status, pages, chapters.",
1261
+ "library-books add": "Add a web search result to the book library.",
1252
1262
  "goals notes list": "List Rocky's per-kid notes on a goal.",
1253
1263
  "goals notes get": "Read the goal's or one lesson's note.",
1254
1264
  "goals notes set": "Write Rocky's note for this kid on a lesson (never the lesson itself).",
@@ -1303,6 +1313,7 @@ export const NOUN_SUMMARIES = {
1303
1313
  memories: "Kid memory files and the context Rocky sees.",
1304
1314
  rocky: "A kid's Rocky personality settings.",
1305
1315
  "tutor-templates": "Tutor templates and their assignment to kids.",
1316
+ "library-books": "Book library: search the web, add books, read status.",
1306
1317
  mastery: "Mastery graphs and the content linked to them.",
1307
1318
  };
1308
1319
  //# sourceMappingURL=help.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "recess-cli",
3
- "version": "3.19.1",
3
+ "version": "3.19.2",
4
4
  "description": "Safe Recess administration and family AI tools from the command line.",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {