@mmon-co/ncept-default-theory 3.0.19 → 3.0.20

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.
@@ -0,0 +1,187 @@
1
+ import { contentDigest, isNodeId, NODE_CRITERION_PROPERTY, NODE_ELABORATE_PROPERTY, NODE_LABEL_PROPERTY, } from "@mmon-co/ncept-core";
2
+ import { REVIEW_PROPERTY, validateReviewSchedule } from "./schedules.js";
3
+ const string = { type: "string" };
4
+ const nodeId = { ...string, description: 'Identifier beginning with "node-".' };
5
+ const edgeId = { ...string, description: 'Identifier beginning with "edge-".' };
6
+ const priority = { type: "number", description: "Preferred order, higher first." };
7
+ const flag = { type: "boolean" };
8
+ const array = (items) => ({ type: "array", items });
9
+ const record = (properties, ...required) => ({
10
+ type: "object",
11
+ properties,
12
+ required,
13
+ additionalProperties: false,
14
+ });
15
+ const properties = {
16
+ nodes: array(record({
17
+ id: nodeId,
18
+ label: string,
19
+ criterion: string,
20
+ priority,
21
+ milestone: flag,
22
+ elaborate: flag,
23
+ review: record({
24
+ kind: { ...string, enum: ["fsrs", "never", "interval"] },
25
+ days: { type: "number", exclusiveMinimum: 0, description: "Required only for interval." },
26
+ }, "kind"),
27
+ }, "id", "label")),
28
+ edges: array(record({
29
+ from: nodeId,
30
+ to: nodeId,
31
+ id: { ...edgeId, description: edgeId.description + " Omit for a stable ID from the endpoints." },
32
+ because: string,
33
+ }, "from", "to")),
34
+ tags: array(record({
35
+ name: { ...string, description: "A lesson:<name> group or strand." },
36
+ nodes: array(nodeId),
37
+ edges: array(edgeId),
38
+ priority,
39
+ }, "name")),
40
+ targets: { ...array(nodeId), description: "Replace the draft targets; omit to keep them." },
41
+ };
42
+ function fail(path, problem) {
43
+ throw new Error(path + ": " + problem);
44
+ }
45
+ function list(value, path) {
46
+ if (value === undefined)
47
+ return [];
48
+ if (!Array.isArray(value))
49
+ fail(path, "expected an array");
50
+ return value;
51
+ }
52
+ function isRecord(value) {
53
+ return typeof value === "object" && value !== null && !Array.isArray(value);
54
+ }
55
+ function object(value, path) {
56
+ if (!isRecord(value))
57
+ fail(path, "expected an object");
58
+ return value;
59
+ }
60
+ function nonempty(value, path) {
61
+ if (typeof value !== "string" || !value.trim())
62
+ fail(path, "expected nonempty text");
63
+ return value;
64
+ }
65
+ function identifiedNode(value, path) {
66
+ if (!isNodeId(value))
67
+ fail(path, "expected a node-* ID");
68
+ return value;
69
+ }
70
+ function identifiedEdge(value, path) {
71
+ if (typeof value !== "string" || !/^edge-[0-9a-z-]+$/.test(value))
72
+ fail(path, "expected an edge-* ID");
73
+ return `edge-${value.slice(5)}`;
74
+ }
75
+ const digestSuffix = (value) => contentDigest(value).slice("sha256:".length);
76
+ const nodeMetadata = {
77
+ criterion: [NODE_CRITERION_PROPERTY, "string"],
78
+ priority: ["pedagogy:priority", "number"],
79
+ milestone: ["pedagogy:milestone", "boolean"],
80
+ elaborate: [NODE_ELABORATE_PROPERTY, "boolean"],
81
+ };
82
+ export const graphDraftBatch = {
83
+ properties,
84
+ compile(input, graph, previous) {
85
+ const operations = [];
86
+ const nodes = new Set(graph.nodes.map(({ id }) => id));
87
+ const edges = new Set(graph.edges.map(({ id }) => id));
88
+ const metadata = new Map();
89
+ for (const operation of previous) {
90
+ if (operation.kind === "add-node")
91
+ nodes.add(operation.node.id);
92
+ if (operation.kind === "add-edge")
93
+ edges.add(operation.edge.id);
94
+ if (operation.kind === "add-metadata-set")
95
+ metadata.set(operation.metadataSet.id, operation.metadataSet.properties);
96
+ }
97
+ function putMetadata(id, subject, patch) {
98
+ const properties = { ...metadata.get(id), ...patch };
99
+ metadata.set(id, properties);
100
+ operations.push({ kind: "add-metadata-set", metadataSet: { id, subjects: [subject], properties } });
101
+ }
102
+ const nodeRef = (value, path) => {
103
+ const id = identifiedNode(value, path);
104
+ if (!nodes.has(id))
105
+ fail(path, "unknown Node " + id);
106
+ return id;
107
+ };
108
+ const edgeRef = (value, path) => {
109
+ const id = identifiedEdge(value, path);
110
+ if (!edges.has(id))
111
+ fail(path, "unknown Edge " + id);
112
+ return id;
113
+ };
114
+ const optionalPriority = (value, path) => {
115
+ if (typeof value !== "number" || !Number.isFinite(value))
116
+ fail(path, "expected a finite number");
117
+ return value;
118
+ };
119
+ for (const [i, value] of list(input.nodes, "nodes").entries()) {
120
+ const path = "nodes[" + i + "]";
121
+ const node = object(value, path);
122
+ const id = identifiedNode(node.id, path + ".id");
123
+ const patch = { [NODE_LABEL_PROPERTY]: nonempty(node.label, path + ".label") };
124
+ for (const [field, [key, type]] of Object.entries(nodeMetadata)) {
125
+ const value = node[field];
126
+ if (value === undefined)
127
+ continue;
128
+ if (type === "number")
129
+ patch[key] = optionalPriority(value, path + "." + field);
130
+ else if (type === "string")
131
+ patch[key] = nonempty(value, path + "." + field);
132
+ else {
133
+ if (typeof value !== "boolean")
134
+ fail(path + "." + field, "expected a boolean");
135
+ patch[key] = value;
136
+ }
137
+ }
138
+ if (node.review !== undefined) {
139
+ try {
140
+ validateReviewSchedule(node.review);
141
+ }
142
+ catch (error) {
143
+ fail(path + ".review", error instanceof Error ? error.message : String(error));
144
+ }
145
+ patch[REVIEW_PROPERTY] = node.review;
146
+ }
147
+ nodes.add(id);
148
+ operations.push({ kind: "add-node", node: { id } });
149
+ putMetadata(`metadata-${id}`, { kind: "node", id }, patch);
150
+ }
151
+ for (const [i, value] of list(input.edges, "edges").entries()) {
152
+ const path = "edges[" + i + "]";
153
+ const edge = object(value, path);
154
+ const from = nodeRef(edge.from, path + ".from");
155
+ const to = nodeRef(edge.to, path + ".to");
156
+ const id = edge.id === undefined ? `edge-${digestSuffix([from, to])}` : identifiedEdge(edge.id, path + ".id");
157
+ edges.add(id);
158
+ operations.push({ kind: "add-edge", edge: { id, from, to } });
159
+ if (edge.because !== undefined)
160
+ putMetadata(`metadata-${id}`, { kind: "edge", id }, { "pedagogy:because": nonempty(edge.because, path + ".because") });
161
+ }
162
+ for (const [i, value] of list(input.tags, "tags").entries()) {
163
+ const path = "tags[" + i + "]";
164
+ const tag = object(value, path);
165
+ const name = nonempty(tag.name, path + ".name");
166
+ operations.push({
167
+ kind: "define-tag",
168
+ tag: {
169
+ name,
170
+ nodes: list(tag.nodes, path + ".nodes").map((id, j) => nodeRef(id, path + ".nodes[" + j + "]")),
171
+ edges: list(tag.edges, path + ".edges").map((id, j) => edgeRef(id, path + ".edges[" + j + "]")),
172
+ metadataSets: [],
173
+ },
174
+ });
175
+ if (tag.priority !== undefined)
176
+ putMetadata(`metadata-tag-${digestSuffix(name)}`, { kind: "tag", name }, { "pedagogy:priority": optionalPriority(tag.priority, path + ".priority") });
177
+ }
178
+ return {
179
+ operations,
180
+ ...(input.targets === undefined
181
+ ? {}
182
+ : {
183
+ targets: list(input.targets, "targets").map((id, i) => nodeRef(id, "targets[" + i + "]")),
184
+ }),
185
+ };
186
+ },
187
+ };
@@ -78,9 +78,128 @@ export declare const implementation: {
78
78
  }[];
79
79
  entry: {
80
80
  required: false;
81
- kinds: ("mission" | "checkpoint" | "target" | "goal")[];
81
+ kinds: ("checkpoint" | "target" | "mission" | "goal")[];
82
82
  };
83
83
  capabilities: readonly import("@mmon-co/ncept-core/theory").HostCapability[];
84
+ graphDraftBatch: {
85
+ properties: {
86
+ nodes: {
87
+ type: "array";
88
+ items: {
89
+ type: "object";
90
+ properties: {
91
+ id: {
92
+ description: string;
93
+ type: "string";
94
+ };
95
+ label: {
96
+ type: "string";
97
+ };
98
+ criterion: {
99
+ type: "string";
100
+ };
101
+ priority: {
102
+ type: "number";
103
+ description: string;
104
+ };
105
+ milestone: {
106
+ type: "boolean";
107
+ };
108
+ elaborate: {
109
+ type: "boolean";
110
+ };
111
+ review: {
112
+ type: "object";
113
+ properties: {
114
+ kind: {
115
+ enum: string[];
116
+ type: "string";
117
+ };
118
+ days: {
119
+ type: "number";
120
+ exclusiveMinimum: number;
121
+ description: string;
122
+ };
123
+ };
124
+ required: ("kind" | "days")[];
125
+ additionalProperties: false;
126
+ };
127
+ };
128
+ required: ("review" | "id" | "label" | "milestone" | "priority" | "criterion" | "elaborate")[];
129
+ additionalProperties: false;
130
+ };
131
+ };
132
+ edges: {
133
+ type: "array";
134
+ items: {
135
+ type: "object";
136
+ properties: {
137
+ from: {
138
+ description: string;
139
+ type: "string";
140
+ };
141
+ to: {
142
+ description: string;
143
+ type: "string";
144
+ };
145
+ id: {
146
+ description: string;
147
+ type: "string";
148
+ };
149
+ because: {
150
+ type: "string";
151
+ };
152
+ };
153
+ required: ("id" | "to" | "from" | "because")[];
154
+ additionalProperties: false;
155
+ };
156
+ };
157
+ tags: {
158
+ type: "array";
159
+ items: {
160
+ type: "object";
161
+ properties: {
162
+ name: {
163
+ description: string;
164
+ type: "string";
165
+ };
166
+ nodes: {
167
+ type: "array";
168
+ items: {
169
+ description: string;
170
+ type: "string";
171
+ };
172
+ };
173
+ edges: {
174
+ type: "array";
175
+ items: {
176
+ description: string;
177
+ type: "string";
178
+ };
179
+ };
180
+ priority: {
181
+ type: "number";
182
+ description: string;
183
+ };
184
+ };
185
+ required: ("nodes" | "name" | "edges" | "priority")[];
186
+ additionalProperties: false;
187
+ };
188
+ };
189
+ targets: {
190
+ description: string;
191
+ type: "array";
192
+ items: {
193
+ description: string;
194
+ type: "string";
195
+ };
196
+ };
197
+ };
198
+ compile(input: Readonly<Record<string, unknown>>, graph: Pick<import("@mmon-co/ncept-core").ResolvedGraph, "nodes" | "edges">, previous: readonly import("@mmon-co/ncept-core").SemanticOperation[]): {
199
+ targets?: `node-${string}`[] | undefined;
200
+ operations: import("@mmon-co/ncept-core").SemanticOperation[];
201
+ };
202
+ };
84
203
  switches: {
85
204
  mode: string;
86
205
  then: "next";
@@ -114,6 +233,125 @@ export declare const implementation: {
114
233
  kinds: ("mission" | "goal")[];
115
234
  };
116
235
  capabilities: readonly import("@mmon-co/ncept-core/theory").HostCapability[];
236
+ graphDraftBatch: {
237
+ properties: {
238
+ nodes: {
239
+ type: "array";
240
+ items: {
241
+ type: "object";
242
+ properties: {
243
+ id: {
244
+ description: string;
245
+ type: "string";
246
+ };
247
+ label: {
248
+ type: "string";
249
+ };
250
+ criterion: {
251
+ type: "string";
252
+ };
253
+ priority: {
254
+ type: "number";
255
+ description: string;
256
+ };
257
+ milestone: {
258
+ type: "boolean";
259
+ };
260
+ elaborate: {
261
+ type: "boolean";
262
+ };
263
+ review: {
264
+ type: "object";
265
+ properties: {
266
+ kind: {
267
+ enum: string[];
268
+ type: "string";
269
+ };
270
+ days: {
271
+ type: "number";
272
+ exclusiveMinimum: number;
273
+ description: string;
274
+ };
275
+ };
276
+ required: ("kind" | "days")[];
277
+ additionalProperties: false;
278
+ };
279
+ };
280
+ required: ("review" | "id" | "label" | "milestone" | "priority" | "criterion" | "elaborate")[];
281
+ additionalProperties: false;
282
+ };
283
+ };
284
+ edges: {
285
+ type: "array";
286
+ items: {
287
+ type: "object";
288
+ properties: {
289
+ from: {
290
+ description: string;
291
+ type: "string";
292
+ };
293
+ to: {
294
+ description: string;
295
+ type: "string";
296
+ };
297
+ id: {
298
+ description: string;
299
+ type: "string";
300
+ };
301
+ because: {
302
+ type: "string";
303
+ };
304
+ };
305
+ required: ("id" | "to" | "from" | "because")[];
306
+ additionalProperties: false;
307
+ };
308
+ };
309
+ tags: {
310
+ type: "array";
311
+ items: {
312
+ type: "object";
313
+ properties: {
314
+ name: {
315
+ description: string;
316
+ type: "string";
317
+ };
318
+ nodes: {
319
+ type: "array";
320
+ items: {
321
+ description: string;
322
+ type: "string";
323
+ };
324
+ };
325
+ edges: {
326
+ type: "array";
327
+ items: {
328
+ description: string;
329
+ type: "string";
330
+ };
331
+ };
332
+ priority: {
333
+ type: "number";
334
+ description: string;
335
+ };
336
+ };
337
+ required: ("nodes" | "name" | "edges" | "priority")[];
338
+ additionalProperties: false;
339
+ };
340
+ };
341
+ targets: {
342
+ description: string;
343
+ type: "array";
344
+ items: {
345
+ description: string;
346
+ type: "string";
347
+ };
348
+ };
349
+ };
350
+ compile(input: Readonly<Record<string, unknown>>, graph: Pick<import("@mmon-co/ncept-core").ResolvedGraph, "nodes" | "edges">, previous: readonly import("@mmon-co/ncept-core").SemanticOperation[]): {
351
+ targets?: `node-${string}`[] | undefined;
352
+ operations: import("@mmon-co/ncept-core").SemanticOperation[];
353
+ };
354
+ };
117
355
  switches: never[];
118
356
  setup: (ctx: import("@mmon-co/ncept-core/theory").ChatContext<import("./state.js").DefaultState>) => import("@mmon-co/ncept-core").Program<Readonly<{
119
357
  prompt: string;
@@ -138,9 +376,128 @@ export declare const implementation: {
138
376
  frontTab: string;
139
377
  entry: {
140
378
  required: true;
141
- kinds: ("mission" | "review" | "target")[];
379
+ kinds: ("review" | "target" | "mission")[];
142
380
  };
143
381
  capabilities: readonly import("@mmon-co/ncept-core/theory").HostCapability[];
382
+ graphDraftBatch: {
383
+ properties: {
384
+ nodes: {
385
+ type: "array";
386
+ items: {
387
+ type: "object";
388
+ properties: {
389
+ id: {
390
+ description: string;
391
+ type: "string";
392
+ };
393
+ label: {
394
+ type: "string";
395
+ };
396
+ criterion: {
397
+ type: "string";
398
+ };
399
+ priority: {
400
+ type: "number";
401
+ description: string;
402
+ };
403
+ milestone: {
404
+ type: "boolean";
405
+ };
406
+ elaborate: {
407
+ type: "boolean";
408
+ };
409
+ review: {
410
+ type: "object";
411
+ properties: {
412
+ kind: {
413
+ enum: string[];
414
+ type: "string";
415
+ };
416
+ days: {
417
+ type: "number";
418
+ exclusiveMinimum: number;
419
+ description: string;
420
+ };
421
+ };
422
+ required: ("kind" | "days")[];
423
+ additionalProperties: false;
424
+ };
425
+ };
426
+ required: ("review" | "id" | "label" | "milestone" | "priority" | "criterion" | "elaborate")[];
427
+ additionalProperties: false;
428
+ };
429
+ };
430
+ edges: {
431
+ type: "array";
432
+ items: {
433
+ type: "object";
434
+ properties: {
435
+ from: {
436
+ description: string;
437
+ type: "string";
438
+ };
439
+ to: {
440
+ description: string;
441
+ type: "string";
442
+ };
443
+ id: {
444
+ description: string;
445
+ type: "string";
446
+ };
447
+ because: {
448
+ type: "string";
449
+ };
450
+ };
451
+ required: ("id" | "to" | "from" | "because")[];
452
+ additionalProperties: false;
453
+ };
454
+ };
455
+ tags: {
456
+ type: "array";
457
+ items: {
458
+ type: "object";
459
+ properties: {
460
+ name: {
461
+ description: string;
462
+ type: "string";
463
+ };
464
+ nodes: {
465
+ type: "array";
466
+ items: {
467
+ description: string;
468
+ type: "string";
469
+ };
470
+ };
471
+ edges: {
472
+ type: "array";
473
+ items: {
474
+ description: string;
475
+ type: "string";
476
+ };
477
+ };
478
+ priority: {
479
+ type: "number";
480
+ description: string;
481
+ };
482
+ };
483
+ required: ("nodes" | "name" | "edges" | "priority")[];
484
+ additionalProperties: false;
485
+ };
486
+ };
487
+ targets: {
488
+ description: string;
489
+ type: "array";
490
+ items: {
491
+ description: string;
492
+ type: "string";
493
+ };
494
+ };
495
+ };
496
+ compile(input: Readonly<Record<string, unknown>>, graph: Pick<import("@mmon-co/ncept-core").ResolvedGraph, "nodes" | "edges">, previous: readonly import("@mmon-co/ncept-core").SemanticOperation[]): {
497
+ targets?: `node-${string}`[] | undefined;
498
+ operations: import("@mmon-co/ncept-core").SemanticOperation[];
499
+ };
500
+ };
144
501
  metadataKeys: readonly string[] | undefined;
145
502
  switches: ({
146
503
  mode: string;