@mmon-co/ncept-local 0.3.7 → 0.3.8
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/host-tools.d.ts +2 -2
- package/dist/host-tools.js +36 -9
- package/dist/learning.d.ts +7 -1
- package/dist/learning.js +4 -1
- package/package.json +1 -1
package/dist/host-tools.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { type HostCapability, type Skill } from "@mmon-co/ncept-core";
|
|
1
|
+
import { type GraphDraftBatch, type HostCapability, type Skill } from "@mmon-co/ncept-core";
|
|
2
2
|
import type { HostTool } from "./host.js";
|
|
3
3
|
import type { LearningHost } from "./learning.js";
|
|
4
4
|
import { type LocalSession } from "./runtime.js";
|
|
5
|
-
export declare function hostTools<S>(host: LearningHost<S>, opened: LocalSession, capabilities: readonly HostCapability[], skills: readonly Skill[], metadataKeys: readonly string[]): readonly HostTool[];
|
|
5
|
+
export declare function hostTools<S>(host: LearningHost<S>, opened: LocalSession, capabilities: readonly HostCapability[], skills: readonly Skill[], metadataKeys: readonly string[], batch?: GraphDraftBatch): readonly HostTool[];
|
package/dist/host-tools.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
2
2
|
import { join } from "node:path";
|
|
3
|
-
import { applyGraphDiff, attachmentDigest, compileGraphDiff, composePatch, isMaterialMeta, isMission, isNodeId, nodeCascadedProperty, parseGraphQuery, revisionContent, projectVisualGraph, sameExactPatchRef, selectGraph, tagIndex, } from "@mmon-co/ncept-core";
|
|
3
|
+
import { applyGraphDiff, attachmentDigest, compileGraphDiff, composePatch, graphDraftOperationKey, isMaterialMeta, isMission, isNodeId, nodeCascadedProperty, parseGraphQuery, revisionContent, projectVisualGraph, sameExactPatchRef, selectGraph, tagIndex, } from "@mmon-co/ncept-core";
|
|
4
4
|
import { localPayload, platform, sessionStates, transcript } from "./runtime.js";
|
|
5
5
|
import { mechanics } from "./mechanics.js";
|
|
6
6
|
import { object } from "./sessions.js";
|
|
@@ -60,12 +60,30 @@ async function acceptContent(host, session, from, content, about = session.about
|
|
|
60
60
|
]);
|
|
61
61
|
return to;
|
|
62
62
|
}
|
|
63
|
-
function
|
|
63
|
+
function putBatch(previous, puts) {
|
|
64
|
+
const indexed = new Map();
|
|
65
|
+
for (const [i, operation] of previous.entries())
|
|
66
|
+
indexed.set(graphDraftOperationKey(operation) ?? i, operation);
|
|
67
|
+
for (const operation of puts)
|
|
68
|
+
indexed.set(graphDraftOperationKey(operation) ?? operation, operation);
|
|
69
|
+
return [...indexed.values()];
|
|
70
|
+
}
|
|
71
|
+
function graphDiff(host, input, session, batch) {
|
|
64
72
|
return host.runtime.snapshot().then(async (view) => {
|
|
65
|
-
|
|
73
|
+
const draft = batch && host.drafts.get(session.id);
|
|
74
|
+
const previous = draft && draft.base === view.graph.terminal.digest ? draft.edits : undefined;
|
|
75
|
+
const typed = batch?.compile(input, view.graph, previous?.operations ?? []);
|
|
76
|
+
if (!typed && !Array.isArray(input.operations))
|
|
66
77
|
throw new Error("Expected graph operations");
|
|
67
|
-
const
|
|
68
|
-
|
|
78
|
+
const ordered = typed && input.operations === undefined ? [] : operations(input.operations);
|
|
79
|
+
const edits = {
|
|
80
|
+
operations: typed ? putBatch(previous?.operations ?? [], [...typed.operations, ...ordered]) : ordered,
|
|
81
|
+
targets: typed?.targets ?? (input.targets === undefined ? (previous?.targets ?? session.about) : nodes(input.targets)),
|
|
82
|
+
citations: input.citations === undefined ? (previous?.citations ?? []) : citations(input.citations),
|
|
83
|
+
retractions: input.retractions === undefined ? (previous?.retractions ?? []) : strings(input.retractions),
|
|
84
|
+
};
|
|
85
|
+
const compiled = compileGraphDiff(view.bundle, edits.operations, edits.targets, edits.citations, edits.retractions);
|
|
86
|
+
return { view, compiled, edits, content: applyGraphDiff(await host.runtime.content(), compiled) };
|
|
69
87
|
});
|
|
70
88
|
}
|
|
71
89
|
function page(items, input) {
|
|
@@ -80,7 +98,7 @@ function page(items, input) {
|
|
|
80
98
|
continueCursor: next >= items.length ? null : String(next),
|
|
81
99
|
};
|
|
82
100
|
}
|
|
83
|
-
export function hostTools(host, opened, capabilities, skills, metadataKeys) {
|
|
101
|
+
export function hostTools(host, opened, capabilities, skills, metadataKeys, batch) {
|
|
84
102
|
const tools = [];
|
|
85
103
|
function mount(name, description, definition, run) {
|
|
86
104
|
tools.push({
|
|
@@ -211,9 +229,18 @@ export function hostTools(host, opened, capabilities, skills, metadataKeys) {
|
|
|
211
229
|
});
|
|
212
230
|
}
|
|
213
231
|
if (capabilities.includes("graph-draft")) {
|
|
214
|
-
mount("edit_graph_draft",
|
|
215
|
-
|
|
216
|
-
|
|
232
|
+
mount("edit_graph_draft", (batch
|
|
233
|
+
? "Add nodes, edges, tags and targets to the unsaved graph draft; raw Core operations run after the typed fields. A call with operations alone replaces the draft. "
|
|
234
|
+
: "Compile graph operations into a draft against the personal Patch. ") +
|
|
235
|
+
"Propose graph-diff to ask the learner to accept it.", schema({ ...graphProperties, ...batch?.properties }, batch ? [] : ["operations"]), async (raw, session) => {
|
|
236
|
+
const typed = batch &&
|
|
237
|
+
Object.keys(batch.properties).some((key) => Object.hasOwn(raw, key) && (key !== "targets" || raw.operations === undefined));
|
|
238
|
+
const prepared = await graphDiff(host, raw, session, typed ? batch : undefined);
|
|
239
|
+
host.drafts.set(session.id, {
|
|
240
|
+
base: prepared.view.graph.terminal.digest,
|
|
241
|
+
content: prepared.content,
|
|
242
|
+
edits: prepared.edits,
|
|
243
|
+
});
|
|
217
244
|
return { content: { status: "draft", report: prepared.compiled.report, graph: prepared.compiled.graph } };
|
|
218
245
|
});
|
|
219
246
|
}
|
package/dist/learning.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type LessonProgress, type LessonReading, type Mission, type ModeEntry, type NodeId, type PatchContent, type SessionMode, type Theory } from "@mmon-co/ncept-core";
|
|
1
|
+
import { type LessonProgress, type LessonReading, type Mission, type ModeEntry, type NodeId, type PatchContent, type Citation, type SemanticOperation, type SessionMode, type Theory } from "@mmon-co/ncept-core";
|
|
2
2
|
import type { Host, HostChatSetup, HostConfig, HostSession, MissionReading, ModeSwitch, OpenHostOptions, SessionOpening, SessionIntent } from "./host.js";
|
|
3
3
|
import { Runtime, type LocalSession } from "./runtime.js";
|
|
4
4
|
type LearningView<S> = Awaited<ReturnType<Runtime<S>["snapshot"]>>;
|
|
@@ -53,6 +53,12 @@ export declare class LearningHost<S> {
|
|
|
53
53
|
readonly drafts: Map<string, {
|
|
54
54
|
base: string;
|
|
55
55
|
content: PatchContent;
|
|
56
|
+
edits: {
|
|
57
|
+
operations: readonly SemanticOperation[];
|
|
58
|
+
targets: readonly NodeId[];
|
|
59
|
+
citations: readonly Citation[];
|
|
60
|
+
retractions: readonly string[];
|
|
61
|
+
};
|
|
56
62
|
}>;
|
|
57
63
|
constructor(runtime: Runtime<S>, confirm: OpenHostOptions<S>["confirm"], onCloseError?: (error: unknown) => void);
|
|
58
64
|
serial<T>(operation: () => Promise<T>): Promise<T>;
|
package/dist/learning.js
CHANGED
|
@@ -761,7 +761,10 @@ export class LearningHost {
|
|
|
761
761
|
]
|
|
762
762
|
.filter(Boolean)
|
|
763
763
|
.join("\n\n"),
|
|
764
|
-
tools: [
|
|
764
|
+
tools: [
|
|
765
|
+
...tools,
|
|
766
|
+
...hostTools(this, session, capabilities, setup.skills, selected?.metadataKeys ?? [], selected?.graphDraftBatch),
|
|
767
|
+
],
|
|
765
768
|
skills: [...setup.skills, mechanics],
|
|
766
769
|
};
|
|
767
770
|
}
|