@mmon-co/ncept-local 0.0.0-stage → 0.2.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/LICENSE +21 -0
- package/README.md +79 -2
- package/dist/days.d.ts +4 -0
- package/dist/days.js +47 -0
- package/dist/directory.d.ts +34 -0
- package/dist/directory.js +252 -0
- package/dist/exchange.d.ts +39 -0
- package/dist/exchange.js +219 -0
- package/dist/host-tools.d.ts +5 -0
- package/dist/host-tools.js +517 -0
- package/dist/host.d.ts +157 -0
- package/dist/host.js +1 -0
- package/dist/hub-auth.d.ts +46 -0
- package/dist/hub-auth.js +171 -0
- package/dist/hub.d.ts +4 -0
- package/dist/hub.js +333 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +5 -0
- package/dist/inputs.d.ts +12 -0
- package/dist/inputs.js +266 -0
- package/dist/learning.d.ts +110 -0
- package/dist/learning.js +834 -0
- package/dist/mechanics.d.ts +3 -0
- package/dist/mechanics.js +6 -0
- package/dist/runtime.d.ts +66 -0
- package/dist/runtime.js +338 -0
- package/dist/session-policy.d.ts +25 -0
- package/dist/session-policy.js +13 -0
- package/dist/sessions.d.ts +80 -0
- package/dist/sessions.js +125 -0
- package/dist/tar.d.ts +3 -0
- package/dist/tar.js +99 -0
- package/package.json +50 -4
package/dist/inputs.js
ADDED
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
import { isContentDigest, isMaterialMeta, isMetadataValue, isNodeId, isPatchId, validateMetadataProperties, } from "@mmon-co/ncept-core";
|
|
2
|
+
import { object } from "./sessions.js";
|
|
3
|
+
function record(value) {
|
|
4
|
+
if (!object(value))
|
|
5
|
+
throw new Error("Expected an object");
|
|
6
|
+
return value;
|
|
7
|
+
}
|
|
8
|
+
export function nonempty(value) {
|
|
9
|
+
return typeof value === "string" && value.trim().length > 0;
|
|
10
|
+
}
|
|
11
|
+
export function isSurface(value) {
|
|
12
|
+
return typeof value === "string" && /^surface-.+/.test(value);
|
|
13
|
+
}
|
|
14
|
+
export function isObjectIdentity(value) {
|
|
15
|
+
return typeof value === "string" && /^object-.+/.test(value);
|
|
16
|
+
}
|
|
17
|
+
function isEdge(value) {
|
|
18
|
+
return typeof value === "string" && /^edge-[0-9a-z-]+$/.test(value);
|
|
19
|
+
}
|
|
20
|
+
function isMetadata(value) {
|
|
21
|
+
return typeof value === "string" && /^metadata-[0-9a-z-]+$/.test(value);
|
|
22
|
+
}
|
|
23
|
+
export function nodeIds(value) {
|
|
24
|
+
if (!Array.isArray(value) || !value.every(isNodeId))
|
|
25
|
+
throw new Error("Expected Node identities");
|
|
26
|
+
return value;
|
|
27
|
+
}
|
|
28
|
+
export function exactRef(value) {
|
|
29
|
+
if (!object(value) || !isPatchId(value.identity) || !isContentDigest(value.digest))
|
|
30
|
+
throw new Error("Expected an exact Patch reference");
|
|
31
|
+
return { identity: value.identity, digest: value.digest };
|
|
32
|
+
}
|
|
33
|
+
function isExact(value) {
|
|
34
|
+
return object(value) && isPatchId(value.identity) && isContentDigest(value.digest);
|
|
35
|
+
}
|
|
36
|
+
export function metadataProperties(value) {
|
|
37
|
+
const properties = {};
|
|
38
|
+
for (const [key, item] of Object.entries(record(value))) {
|
|
39
|
+
if (!isMetadataValue(item))
|
|
40
|
+
throw new Error("Invalid metadata property: " + key);
|
|
41
|
+
properties[key] = item;
|
|
42
|
+
}
|
|
43
|
+
validateMetadataProperties(properties);
|
|
44
|
+
return properties;
|
|
45
|
+
}
|
|
46
|
+
function isProperties(value) {
|
|
47
|
+
return object(value) && Object.values(value).every(isMetadataValue);
|
|
48
|
+
}
|
|
49
|
+
export function isMaterial(value) {
|
|
50
|
+
return (object(value) &&
|
|
51
|
+
nonempty(value.playground) &&
|
|
52
|
+
nonempty(value.type) &&
|
|
53
|
+
nonempty(value.id) &&
|
|
54
|
+
Array.isArray(value.about) &&
|
|
55
|
+
value.about.every(isNodeId) &&
|
|
56
|
+
object(value.content) &&
|
|
57
|
+
value.content.kind === "blob" &&
|
|
58
|
+
isContentDigest(value.content.hash) &&
|
|
59
|
+
nonempty(value.content.mediaType) &&
|
|
60
|
+
isMaterialMeta(value.meta));
|
|
61
|
+
}
|
|
62
|
+
function isSubject(value) {
|
|
63
|
+
return (object(value) &&
|
|
64
|
+
((value.kind === "node" && isNodeId(value.id)) ||
|
|
65
|
+
(value.kind === "edge" && isEdge(value.id)) ||
|
|
66
|
+
(value.kind === "tag" && nonempty(value.name))));
|
|
67
|
+
}
|
|
68
|
+
function isOperation(value) {
|
|
69
|
+
if (!object(value))
|
|
70
|
+
return false;
|
|
71
|
+
switch (value.kind) {
|
|
72
|
+
case "add-node":
|
|
73
|
+
return object(value.node) && isNodeId(value.node.id);
|
|
74
|
+
case "add-edge":
|
|
75
|
+
return object(value.edge) && isEdge(value.edge.id) && isNodeId(value.edge.from) && isNodeId(value.edge.to);
|
|
76
|
+
case "add-metadata-set":
|
|
77
|
+
return (object(value.metadataSet) &&
|
|
78
|
+
isMetadata(value.metadataSet.id) &&
|
|
79
|
+
Array.isArray(value.metadataSet.subjects) &&
|
|
80
|
+
value.metadataSet.subjects.every(isSubject) &&
|
|
81
|
+
isProperties(value.metadataSet.properties));
|
|
82
|
+
case "add-material":
|
|
83
|
+
case "edit-material":
|
|
84
|
+
return isMaterial(value.material);
|
|
85
|
+
case "remove-material":
|
|
86
|
+
return nonempty(value.playground) && nonempty(value.id);
|
|
87
|
+
case "define-tag":
|
|
88
|
+
return (object(value.tag) &&
|
|
89
|
+
nonempty(value.tag.name) &&
|
|
90
|
+
Array.isArray(value.tag.nodes) &&
|
|
91
|
+
value.tag.nodes.every(isNodeId) &&
|
|
92
|
+
Array.isArray(value.tag.edges) &&
|
|
93
|
+
value.tag.edges.every(isEdge) &&
|
|
94
|
+
Array.isArray(value.tag.metadataSets) &&
|
|
95
|
+
value.tag.metadataSets.every(isMetadata));
|
|
96
|
+
case "mask-contribution": {
|
|
97
|
+
const mask = value.mask;
|
|
98
|
+
if (!object(mask) ||
|
|
99
|
+
!isExact(mask.source) ||
|
|
100
|
+
!Number.isSafeInteger(mask.operationIndex) ||
|
|
101
|
+
typeof mask.operationIndex !== "number" ||
|
|
102
|
+
mask.operationIndex < 0 ||
|
|
103
|
+
(mask.property !== undefined && !nonempty(mask.property)) ||
|
|
104
|
+
!object(mask.entity))
|
|
105
|
+
return false;
|
|
106
|
+
const entity = mask.entity;
|
|
107
|
+
return ((entity.kind === "node" && isNodeId(entity.id)) ||
|
|
108
|
+
(entity.kind === "edge" && isEdge(entity.id)) ||
|
|
109
|
+
(entity.kind === "metadata-set" && isMetadata(entity.id)) ||
|
|
110
|
+
(entity.kind === "material" && nonempty(entity.id) && nonempty(entity.playground)));
|
|
111
|
+
}
|
|
112
|
+
default:
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
const operationShapes = {
|
|
117
|
+
"add-node": 'node.id must look like "node-example" (lowercase letters, digits and hyphens after "node-")',
|
|
118
|
+
"add-edge": 'edge.id must look like "edge-example"; edge.from and edge.to must be Node ids like "node-example"',
|
|
119
|
+
"add-metadata-set": 'metadataSet.id must look like "metadata-example"; subjects are {kind:"node",id:"node-example"}; properties are a flat object of metadata values',
|
|
120
|
+
};
|
|
121
|
+
export function operations(value) {
|
|
122
|
+
if (!Array.isArray(value))
|
|
123
|
+
throw new Error("Graph operations must be an array");
|
|
124
|
+
const bad = value.findIndex((item) => !isOperation(item));
|
|
125
|
+
if (bad < 0)
|
|
126
|
+
return value;
|
|
127
|
+
const kind = object(value[bad]) ? value[bad].kind : undefined;
|
|
128
|
+
const shape = typeof kind === "string" ? operationShapes[kind] : undefined;
|
|
129
|
+
throw new Error("Invalid graph operation " +
|
|
130
|
+
bad +
|
|
131
|
+
(typeof kind === "string" ? " (" + kind + ")" : "") +
|
|
132
|
+
": " +
|
|
133
|
+
(shape ?? "its kind and fields do not match any Core operation; see the tool description"));
|
|
134
|
+
}
|
|
135
|
+
function mappings(value) {
|
|
136
|
+
return Array.isArray(value) && value.every((pair) => object(pair) && nonempty(pair.source) && nonempty(pair.target));
|
|
137
|
+
}
|
|
138
|
+
function isCitation(value) {
|
|
139
|
+
if (!object(value))
|
|
140
|
+
return false;
|
|
141
|
+
switch (value.kind) {
|
|
142
|
+
case "derived_from":
|
|
143
|
+
case "based_on":
|
|
144
|
+
case "inspired_by":
|
|
145
|
+
case "published_release":
|
|
146
|
+
return isExact(value.source);
|
|
147
|
+
case "external_source":
|
|
148
|
+
return nonempty(value.source);
|
|
149
|
+
case "public_attribution_unavailable":
|
|
150
|
+
return true;
|
|
151
|
+
case "reified_from":
|
|
152
|
+
return (isExact(value.source) &&
|
|
153
|
+
Array.isArray(value.formerBases) &&
|
|
154
|
+
value.formerBases.every(isExact) &&
|
|
155
|
+
object(value.entities) &&
|
|
156
|
+
mappings(value.entities.nodes) &&
|
|
157
|
+
mappings(value.entities.edges) &&
|
|
158
|
+
mappings(value.entities.metadataSets) &&
|
|
159
|
+
mappings(value.entities.materials));
|
|
160
|
+
default:
|
|
161
|
+
return false;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
export function citations(value) {
|
|
165
|
+
if (value === undefined)
|
|
166
|
+
return [];
|
|
167
|
+
if (!Array.isArray(value) || !value.every(isCitation))
|
|
168
|
+
throw new Error("Invalid citations");
|
|
169
|
+
return value;
|
|
170
|
+
}
|
|
171
|
+
export function strings(value) {
|
|
172
|
+
if (!Array.isArray(value) || !value.every((item) => typeof item === "string"))
|
|
173
|
+
throw new Error("Expected strings");
|
|
174
|
+
return value;
|
|
175
|
+
}
|
|
176
|
+
export function modeEntry(value) {
|
|
177
|
+
const input = record(value);
|
|
178
|
+
switch (input.kind) {
|
|
179
|
+
case "goal": {
|
|
180
|
+
if (!nonempty(input.text))
|
|
181
|
+
throw new Error("A goal needs text");
|
|
182
|
+
const adopted = input.adoptedPatch;
|
|
183
|
+
if (adopted !== undefined &&
|
|
184
|
+
(!object(adopted) ||
|
|
185
|
+
!nonempty(adopted.patchId) ||
|
|
186
|
+
!nonempty(adopted.digest) ||
|
|
187
|
+
!nonempty(adopted.version) ||
|
|
188
|
+
!nonempty(adopted.title) ||
|
|
189
|
+
(adopted.instanceId !== undefined && !nonempty(adopted.instanceId))))
|
|
190
|
+
throw new Error("Invalid adopted Patch");
|
|
191
|
+
if (object(adopted) &&
|
|
192
|
+
nonempty(adopted.patchId) &&
|
|
193
|
+
nonempty(adopted.digest) &&
|
|
194
|
+
nonempty(adopted.version) &&
|
|
195
|
+
nonempty(adopted.title))
|
|
196
|
+
return {
|
|
197
|
+
kind: "goal",
|
|
198
|
+
text: input.text,
|
|
199
|
+
adoptedPatch: {
|
|
200
|
+
patchId: adopted.patchId,
|
|
201
|
+
digest: adopted.digest,
|
|
202
|
+
version: adopted.version,
|
|
203
|
+
title: adopted.title,
|
|
204
|
+
...(typeof adopted.instanceId === "string" ? { instanceId: adopted.instanceId } : {}),
|
|
205
|
+
},
|
|
206
|
+
};
|
|
207
|
+
return { kind: "goal", text: input.text };
|
|
208
|
+
}
|
|
209
|
+
case "mission":
|
|
210
|
+
if (!nonempty(input.id))
|
|
211
|
+
throw new Error("A Mission entry needs an id");
|
|
212
|
+
return { kind: "mission", id: input.id };
|
|
213
|
+
case "target":
|
|
214
|
+
if (!isNodeId(input.node))
|
|
215
|
+
throw new Error("A target entry needs a Node");
|
|
216
|
+
return { kind: "target", node: input.node };
|
|
217
|
+
case "review":
|
|
218
|
+
return { kind: "review", nodes: nodeIds(input.nodes) };
|
|
219
|
+
case "lesson": {
|
|
220
|
+
const lesson = record(input.lesson);
|
|
221
|
+
const mission = record(lesson.mission);
|
|
222
|
+
const section = record(lesson.section);
|
|
223
|
+
if (!nonempty(mission.id) ||
|
|
224
|
+
!nonempty(mission.statement) ||
|
|
225
|
+
!nonempty(lesson.name) ||
|
|
226
|
+
typeof lesson.number !== "number" ||
|
|
227
|
+
!Number.isSafeInteger(lesson.number) ||
|
|
228
|
+
typeof lesson.of !== "number" ||
|
|
229
|
+
!Number.isSafeInteger(lesson.of) ||
|
|
230
|
+
typeof section.number !== "number" ||
|
|
231
|
+
!isNodeId(section.milestone) ||
|
|
232
|
+
!nonempty(section.name))
|
|
233
|
+
throw new Error("Invalid Lesson snapshot");
|
|
234
|
+
return {
|
|
235
|
+
kind: "lesson",
|
|
236
|
+
lesson: {
|
|
237
|
+
mission: {
|
|
238
|
+
id: mission.id,
|
|
239
|
+
statement: mission.statement,
|
|
240
|
+
...(typeof mission.shortName === "string" ? { shortName: mission.shortName } : {}),
|
|
241
|
+
},
|
|
242
|
+
number: lesson.number,
|
|
243
|
+
of: lesson.of,
|
|
244
|
+
name: lesson.name,
|
|
245
|
+
nodes: nodeIds(lesson.nodes),
|
|
246
|
+
section: { number: section.number, milestone: section.milestone, name: section.name },
|
|
247
|
+
},
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
case "checkpoint":
|
|
251
|
+
if (!nonempty(input.missionId) || (input.milestone !== undefined && !isNodeId(input.milestone)))
|
|
252
|
+
throw new Error("Invalid checkpoint entry");
|
|
253
|
+
return {
|
|
254
|
+
kind: "checkpoint",
|
|
255
|
+
missionId: input.missionId,
|
|
256
|
+
outcome: input.outcome,
|
|
257
|
+
...(input.final === true ? { final: true } : {}),
|
|
258
|
+
...(isNodeId(input.milestone) ? { milestone: input.milestone } : {}),
|
|
259
|
+
...(typeof input.sessionId === "string" ? { sessionId: input.sessionId } : {}),
|
|
260
|
+
...(typeof input.closedAt === "string" ? { closedAt: input.closedAt } : {}),
|
|
261
|
+
...(typeof input.closingNote === "string" ? { closingNote: input.closingNote } : {}),
|
|
262
|
+
};
|
|
263
|
+
default:
|
|
264
|
+
throw new Error("Unknown Session entry kind");
|
|
265
|
+
}
|
|
266
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { type LessonProgress, type LessonReading, type Mission, type ModeEntry, type NodeId, type PatchContent, type SessionMode, type Theory } from "@mmon-co/ncept-core";
|
|
2
|
+
import type { Host, HostChatSetup, HostConfig, HostSession, MissionReading, ModeSwitch, OpenHostOptions, SessionOpening, SessionIntent } from "./host.js";
|
|
3
|
+
import { Runtime, type LocalSession } from "./runtime.js";
|
|
4
|
+
/** Read current learning state without day processing, receipts, configuration writes or model calls. */
|
|
5
|
+
export declare function openLearningReader<S>(profileDir: string, theories: readonly Theory<S>[]): Promise<{
|
|
6
|
+
reading(): Promise<{
|
|
7
|
+
missions: readonly MissionReading[];
|
|
8
|
+
nodes: {
|
|
9
|
+
id: `node-${string}`;
|
|
10
|
+
label: string;
|
|
11
|
+
status: "open" | "done" | "tentative";
|
|
12
|
+
}[];
|
|
13
|
+
dueReview: {
|
|
14
|
+
id: `node-${string}`;
|
|
15
|
+
label: string;
|
|
16
|
+
}[];
|
|
17
|
+
sessions: {
|
|
18
|
+
title: string;
|
|
19
|
+
missionLabel: string | undefined;
|
|
20
|
+
nodes: {
|
|
21
|
+
id: `node-${string}`;
|
|
22
|
+
label: string;
|
|
23
|
+
}[];
|
|
24
|
+
surface: import("@mmon-co/ncept-core").SurfaceId;
|
|
25
|
+
about: readonly NodeId[];
|
|
26
|
+
closed: boolean;
|
|
27
|
+
mission?: string;
|
|
28
|
+
parent?: string;
|
|
29
|
+
id: import("@mmon-co/ncept-core").SessionRef;
|
|
30
|
+
mode: string;
|
|
31
|
+
entry?: ModeEntry;
|
|
32
|
+
}[];
|
|
33
|
+
}>;
|
|
34
|
+
}>;
|
|
35
|
+
/** Owns execution serialization; the front end owns pi's conversation and transcript writer. */
|
|
36
|
+
export declare class LearningHost<S> {
|
|
37
|
+
readonly runtime: Runtime<S>;
|
|
38
|
+
readonly confirm: OpenHostOptions<S>["confirm"];
|
|
39
|
+
private tail;
|
|
40
|
+
private pendingSwitch?;
|
|
41
|
+
readonly drafts: Map<string, {
|
|
42
|
+
base: string;
|
|
43
|
+
content: PatchContent;
|
|
44
|
+
}>;
|
|
45
|
+
constructor(runtime: Runtime<S>, confirm: OpenHostOptions<S>["confirm"]);
|
|
46
|
+
serial<T>(operation: () => Promise<T>): Promise<T>;
|
|
47
|
+
reload(): Promise<void>;
|
|
48
|
+
current(session: HostSession): Promise<LocalSession>;
|
|
49
|
+
mode(theory: Theory<S>, mode: string, entry?: ModeEntry): SessionMode<S> | undefined;
|
|
50
|
+
missionReadings(): Promise<readonly MissionReading[]>;
|
|
51
|
+
lessonEntry(missionId: string, number?: number): Promise<ModeEntry>;
|
|
52
|
+
reading(): Promise<{
|
|
53
|
+
missions: readonly MissionReading[];
|
|
54
|
+
dueReview: `node-${string}`[];
|
|
55
|
+
}>;
|
|
56
|
+
reviseMission(mission: Mission, create: boolean): Promise<void>;
|
|
57
|
+
private closing;
|
|
58
|
+
private closingRun;
|
|
59
|
+
close(session: HostSession): Promise<void>;
|
|
60
|
+
settle(session: HostSession): Promise<ModeSwitch | undefined>;
|
|
61
|
+
retireMission(id: string, outcome: "achieved" | "abandoned"): Promise<void>;
|
|
62
|
+
begin(intent: SessionIntent): Promise<HostSession>;
|
|
63
|
+
open(input: SessionOpening): Promise<HostSession>;
|
|
64
|
+
switchMode(session: LocalSession, to: ModeSwitch): Promise<void>;
|
|
65
|
+
context(session: LocalSession): Promise<{
|
|
66
|
+
missions: {
|
|
67
|
+
id: string;
|
|
68
|
+
statement: string;
|
|
69
|
+
change: string;
|
|
70
|
+
nodes: `node-${string}`[];
|
|
71
|
+
targets: `node-${string}`[];
|
|
72
|
+
priority: number;
|
|
73
|
+
run: {
|
|
74
|
+
next: readonly LessonReading[];
|
|
75
|
+
active: import("@mmon-co/ncept-core").SessionRef | null;
|
|
76
|
+
past: readonly import("@mmon-co/ncept-core").PastEntry[];
|
|
77
|
+
retired?: Readonly<{
|
|
78
|
+
outcome: "achieved" | "abandoned";
|
|
79
|
+
at: string;
|
|
80
|
+
}>;
|
|
81
|
+
asides: readonly import("@mmon-co/ncept-core").SessionRef[];
|
|
82
|
+
};
|
|
83
|
+
}[];
|
|
84
|
+
lesson?: LessonProgress;
|
|
85
|
+
now: string;
|
|
86
|
+
graph: import("@mmon-co/ncept-core").ResolvedGraph;
|
|
87
|
+
state: S;
|
|
88
|
+
surface: import("@mmon-co/ncept-core").SurfaceId;
|
|
89
|
+
mode: string;
|
|
90
|
+
entry?: ModeEntry;
|
|
91
|
+
about: readonly NodeId[];
|
|
92
|
+
unscopedNodes?: readonly NodeId[];
|
|
93
|
+
tutorMessages?: readonly string[];
|
|
94
|
+
opening?: Readonly<{
|
|
95
|
+
latestLearnerMessage?: string;
|
|
96
|
+
}>;
|
|
97
|
+
sessionObservations?: readonly import("@mmon-co/ncept-core").ObservationId[];
|
|
98
|
+
lessonActivities?: readonly import("@mmon-co/ncept-core").LessonActivity[];
|
|
99
|
+
sessionMinutes?: number;
|
|
100
|
+
openSurfaces?: readonly {
|
|
101
|
+
readonly surface: import("@mmon-co/ncept-core").SurfaceId;
|
|
102
|
+
readonly about: readonly NodeId[];
|
|
103
|
+
}[];
|
|
104
|
+
}>;
|
|
105
|
+
turn(input: HostSession, learnerMessage?: string): Promise<HostChatSetup>;
|
|
106
|
+
config(): Promise<HostConfig>;
|
|
107
|
+
configure(config: HostConfig): Promise<void>;
|
|
108
|
+
start(): Promise<void>;
|
|
109
|
+
}
|
|
110
|
+
export declare function openHost<S>(options: OpenHostOptions<S>): Promise<Host>;
|