@mmon-co/ncept-default-theory 3.0.19 → 3.0.21
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 +1 -1
- package/dist/catalog-contract.d.ts +19 -11
- package/dist/catalog-contract.js +18 -4
- package/dist/chat.d.ts +359 -2
- package/dist/chat.js +43 -14
- package/dist/graph-draft-batch.d.ts +145 -0
- package/dist/graph-draft-batch.js +187 -0
- package/dist/implementation.d.ts +359 -2
- package/dist/index.d.ts +360 -2
- package/dist/index.js +1 -0
- package/dist/opening.js +1 -1
- package/dist/path.d.ts +3 -3
- package/dist/path.js +17 -121
- package/dist/reading.js +3 -7
- package/dist/release.d.ts +1 -1
- package/dist/release.js +1 -1
- package/dist/schedules.d.ts +1 -2
- package/dist/schedules.js +0 -10
- package/dist/skills/sources.d.ts +8 -8
- package/dist/skills/sources.js +8 -8
- package/dist/timing.d.ts +0 -3
- package/dist/timing.js +3 -25
- package/dist/tools.d.ts +1 -1
- package/dist/tools.js +3 -22
- package/package.json +1 -1
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { type EdgeId, type NodeId, type SemanticOperation } from "@mmon-co/ncept-core";
|
|
2
|
+
import { type ReviewSchedule } from "./schedules.js";
|
|
3
|
+
export type GraphDraftBatchInput = {
|
|
4
|
+
nodes?: {
|
|
5
|
+
id: NodeId;
|
|
6
|
+
label: string;
|
|
7
|
+
criterion?: string;
|
|
8
|
+
priority?: number;
|
|
9
|
+
milestone?: boolean;
|
|
10
|
+
elaborate?: boolean;
|
|
11
|
+
review?: ReviewSchedule;
|
|
12
|
+
}[];
|
|
13
|
+
edges?: {
|
|
14
|
+
from: NodeId;
|
|
15
|
+
to: NodeId;
|
|
16
|
+
id?: EdgeId;
|
|
17
|
+
because?: string;
|
|
18
|
+
}[];
|
|
19
|
+
tags?: {
|
|
20
|
+
name: string;
|
|
21
|
+
nodes?: NodeId[];
|
|
22
|
+
edges?: EdgeId[];
|
|
23
|
+
priority?: number;
|
|
24
|
+
}[];
|
|
25
|
+
targets?: NodeId[];
|
|
26
|
+
};
|
|
27
|
+
export declare const graphDraftBatch: {
|
|
28
|
+
properties: {
|
|
29
|
+
nodes: {
|
|
30
|
+
type: "array";
|
|
31
|
+
items: {
|
|
32
|
+
type: "object";
|
|
33
|
+
properties: {
|
|
34
|
+
id: {
|
|
35
|
+
description: string;
|
|
36
|
+
type: "string";
|
|
37
|
+
};
|
|
38
|
+
label: {
|
|
39
|
+
type: "string";
|
|
40
|
+
};
|
|
41
|
+
criterion: {
|
|
42
|
+
type: "string";
|
|
43
|
+
};
|
|
44
|
+
priority: {
|
|
45
|
+
type: "number";
|
|
46
|
+
description: string;
|
|
47
|
+
};
|
|
48
|
+
milestone: {
|
|
49
|
+
type: "boolean";
|
|
50
|
+
};
|
|
51
|
+
elaborate: {
|
|
52
|
+
type: "boolean";
|
|
53
|
+
};
|
|
54
|
+
review: {
|
|
55
|
+
type: "object";
|
|
56
|
+
properties: {
|
|
57
|
+
kind: {
|
|
58
|
+
enum: string[];
|
|
59
|
+
type: "string";
|
|
60
|
+
};
|
|
61
|
+
days: {
|
|
62
|
+
type: "number";
|
|
63
|
+
exclusiveMinimum: number;
|
|
64
|
+
description: string;
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
required: ("kind" | "days")[];
|
|
68
|
+
additionalProperties: false;
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
required: ("id" | "label" | "milestone" | "priority" | "review" | "criterion" | "elaborate")[];
|
|
72
|
+
additionalProperties: false;
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
edges: {
|
|
76
|
+
type: "array";
|
|
77
|
+
items: {
|
|
78
|
+
type: "object";
|
|
79
|
+
properties: {
|
|
80
|
+
from: {
|
|
81
|
+
description: string;
|
|
82
|
+
type: "string";
|
|
83
|
+
};
|
|
84
|
+
to: {
|
|
85
|
+
description: string;
|
|
86
|
+
type: "string";
|
|
87
|
+
};
|
|
88
|
+
id: {
|
|
89
|
+
description: string;
|
|
90
|
+
type: "string";
|
|
91
|
+
};
|
|
92
|
+
because: {
|
|
93
|
+
type: "string";
|
|
94
|
+
};
|
|
95
|
+
};
|
|
96
|
+
required: ("id" | "to" | "from" | "because")[];
|
|
97
|
+
additionalProperties: false;
|
|
98
|
+
};
|
|
99
|
+
};
|
|
100
|
+
tags: {
|
|
101
|
+
type: "array";
|
|
102
|
+
items: {
|
|
103
|
+
type: "object";
|
|
104
|
+
properties: {
|
|
105
|
+
name: {
|
|
106
|
+
description: string;
|
|
107
|
+
type: "string";
|
|
108
|
+
};
|
|
109
|
+
nodes: {
|
|
110
|
+
type: "array";
|
|
111
|
+
items: {
|
|
112
|
+
description: string;
|
|
113
|
+
type: "string";
|
|
114
|
+
};
|
|
115
|
+
};
|
|
116
|
+
edges: {
|
|
117
|
+
type: "array";
|
|
118
|
+
items: {
|
|
119
|
+
description: string;
|
|
120
|
+
type: "string";
|
|
121
|
+
};
|
|
122
|
+
};
|
|
123
|
+
priority: {
|
|
124
|
+
type: "number";
|
|
125
|
+
description: string;
|
|
126
|
+
};
|
|
127
|
+
};
|
|
128
|
+
required: ("nodes" | "name" | "edges" | "priority")[];
|
|
129
|
+
additionalProperties: false;
|
|
130
|
+
};
|
|
131
|
+
};
|
|
132
|
+
targets: {
|
|
133
|
+
description: string;
|
|
134
|
+
type: "array";
|
|
135
|
+
items: {
|
|
136
|
+
description: string;
|
|
137
|
+
type: "string";
|
|
138
|
+
};
|
|
139
|
+
};
|
|
140
|
+
};
|
|
141
|
+
compile(input: Readonly<Record<string, unknown>>, graph: Pick<import("@mmon-co/ncept-core").ResolvedGraph, "nodes" | "edges">, previous: readonly SemanticOperation[]): {
|
|
142
|
+
targets?: `node-${string}`[] | undefined;
|
|
143
|
+
operations: SemanticOperation[];
|
|
144
|
+
};
|
|
145
|
+
};
|
|
@@ -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
|
+
};
|