@mmon-co/ncept-default-theory 0.0.0-stage → 1.0.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 +73 -2
- package/dist/catalog-contract.d.ts +102 -0
- package/dist/catalog-contract.js +75 -0
- package/dist/catalog.d.ts +14 -0
- package/dist/catalog.js +164 -0
- package/dist/chat.d.ts +171 -0
- package/dist/chat.js +203 -0
- package/dist/completion.d.ts +74 -0
- package/dist/completion.js +277 -0
- package/dist/dependent-cone.d.ts +3 -0
- package/dist/dependent-cone.js +26 -0
- package/dist/diagnosis.d.ts +9 -0
- package/dist/diagnosis.js +1 -0
- package/dist/diagnostics.d.ts +25 -0
- package/dist/diagnostics.js +34 -0
- package/dist/evaluation.d.ts +33 -0
- package/dist/evaluation.js +376 -0
- package/dist/event.d.ts +7 -0
- package/dist/event.js +405 -0
- package/dist/history.d.ts +4 -0
- package/dist/history.js +61 -0
- package/dist/implementation.d.ts +170 -0
- package/dist/implementation.js +30 -0
- package/dist/index.d.ts +185 -0
- package/dist/index.js +26 -0
- package/dist/messages.d.ts +167 -0
- package/dist/messages.js +56 -0
- package/dist/outcomes.d.ts +143 -0
- package/dist/outcomes.js +323 -0
- package/dist/path.d.ts +17 -0
- package/dist/path.js +292 -0
- package/dist/reading.d.ts +12 -0
- package/dist/reading.js +75 -0
- package/dist/release.d.ts +1 -0
- package/dist/release.js +1 -0
- package/dist/roleplay.d.ts +17 -0
- package/dist/roleplay.js +2 -0
- package/dist/skills/sources.d.ts +12 -0
- package/dist/skills/sources.js +13 -0
- package/dist/skills.d.ts +12 -0
- package/dist/skills.js +70 -0
- package/dist/state.d.ts +316 -0
- package/dist/state.js +1309 -0
- package/dist/tags.d.ts +34 -0
- package/dist/tags.js +306 -0
- package/dist/timing.d.ts +21 -0
- package/dist/timing.js +79 -0
- package/dist/tools.d.ts +394 -0
- package/dist/tools.js +872 -0
- package/package.json +52 -4
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { type Grader, type Observation, type Program } from "@mmon-co/ncept-core/observations";
|
|
2
|
+
import { type NodeId, type ResolvedGraph } from "@mmon-co/ncept-core/patch";
|
|
3
|
+
import type { ChatContext, Tool } from "@mmon-co/ncept-core/theory";
|
|
4
|
+
import { type DefaultState } from "./state.js";
|
|
5
|
+
type Ctx = ChatContext<DefaultState>;
|
|
6
|
+
interface Check {
|
|
7
|
+
readonly node: NodeId;
|
|
8
|
+
readonly criteria: readonly string[];
|
|
9
|
+
}
|
|
10
|
+
interface Specification {
|
|
11
|
+
readonly task: string;
|
|
12
|
+
readonly rubric: readonly Check[];
|
|
13
|
+
readonly unaided: boolean;
|
|
14
|
+
readonly grader: Grader;
|
|
15
|
+
}
|
|
16
|
+
interface Watch {
|
|
17
|
+
readonly kind: "evaluation-watch";
|
|
18
|
+
readonly specification: Specification;
|
|
19
|
+
}
|
|
20
|
+
/** Control projection for host admission; non-controls are undefined, stop is null. */
|
|
21
|
+
export declare function evaluationControl(observation: Observation): Grader | null | undefined;
|
|
22
|
+
export declare function evaluationWatch(ctx: Ctx): Observation<Watch> | undefined;
|
|
23
|
+
export declare function evaluationContext(ctx: Ctx): string[];
|
|
24
|
+
/** Only the graded Nodes' standards, never their teaching guidance or conversation. */
|
|
25
|
+
export declare function assessmentCapabilities(graph: ResolvedGraph, nodes: readonly NodeId[]): {
|
|
26
|
+
node: `node-${string}`;
|
|
27
|
+
criterion: import("@mmon-co/ncept-core/patch").MetadataValue[];
|
|
28
|
+
assessmentGuidance: string[];
|
|
29
|
+
}[];
|
|
30
|
+
/** Called before a web tutor turn; only host-proven learner replies are passed here. */
|
|
31
|
+
export declare function evaluateWatchedReply(ctx: Ctx, message: string): Program<unknown>;
|
|
32
|
+
export declare const evaluationTools: readonly Tool<unknown, unknown, DefaultState>[];
|
|
33
|
+
export {};
|
|
@@ -0,0 +1,376 @@
|
|
|
1
|
+
import { effectiveObservations, read, write, isObservationId, } from "@mmon-co/ncept-core/observations";
|
|
2
|
+
import { ASSESSMENT_GUIDANCE_INSTRUCTIONS, isNodeId, nodeAssessmentGuidance, NODE_CRITERION_PROPERTY, metadataSetsForEntity, } from "@mmon-co/ncept-core/patch";
|
|
3
|
+
import { electedObservations, isDefaultObservation, isDemonstration, assertDefaultRetraction, } from "./state.js";
|
|
4
|
+
function object(value) {
|
|
5
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
6
|
+
}
|
|
7
|
+
function text(value) {
|
|
8
|
+
if (typeof value !== "string" || value.trim() === "")
|
|
9
|
+
throw new Error("Expected nonempty text");
|
|
10
|
+
return value;
|
|
11
|
+
}
|
|
12
|
+
function args(raw, allowed) {
|
|
13
|
+
if (!object(raw) || Object.keys(raw).some((key) => !allowed.includes(key)))
|
|
14
|
+
throw new Error("Invalid evaluation arguments");
|
|
15
|
+
return raw;
|
|
16
|
+
}
|
|
17
|
+
const specKeys = ["task", "rubric", "unaided", "grader"];
|
|
18
|
+
function specification(raw, ctx) {
|
|
19
|
+
const grader = raw.grader;
|
|
20
|
+
if (grader !== "decision" &&
|
|
21
|
+
!(object(grader) && Object.keys(grader).length === 1 && typeof grader.model === "string"))
|
|
22
|
+
throw new Error("Grader must be decision or {model: provider/model}");
|
|
23
|
+
if (typeof raw.unaided !== "boolean")
|
|
24
|
+
throw new Error("Decide unaided when posing the check");
|
|
25
|
+
if (!Array.isArray(raw.rubric) || raw.rubric.length === 0)
|
|
26
|
+
throw new Error("Supply a per-Node rubric");
|
|
27
|
+
const rubric = raw.rubric.map((entry) => {
|
|
28
|
+
if (!object(entry) ||
|
|
29
|
+
Object.keys(entry).some((key) => !["node", "criteria"].includes(key)) ||
|
|
30
|
+
!isNodeId(entry.node) ||
|
|
31
|
+
!ctx.graph.nodes.some(({ id }) => id === entry.node) ||
|
|
32
|
+
!Array.isArray(entry.criteria) ||
|
|
33
|
+
entry.criteria.length === 0)
|
|
34
|
+
throw new Error("Rubric requires an existing Node and nonempty criteria");
|
|
35
|
+
return { node: entry.node, criteria: entry.criteria.map(text) };
|
|
36
|
+
});
|
|
37
|
+
if (new Set(rubric.map(({ node }) => node)).size !== rubric.length)
|
|
38
|
+
throw new Error("Duplicate rubric Node");
|
|
39
|
+
return {
|
|
40
|
+
task: text(raw.task),
|
|
41
|
+
rubric,
|
|
42
|
+
unaided: raw.unaided,
|
|
43
|
+
grader: grader === "decision" ? grader : { model: text(grader.model) },
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
function own(ctx) {
|
|
47
|
+
return effectiveObservations(electedObservations(ctx.state.observations), ctx.now).filter((observation) => isDefaultObservation(observation) && observation.surface === ctx.surface);
|
|
48
|
+
}
|
|
49
|
+
/** Control projection for host admission; non-controls are undefined, stop is null. */
|
|
50
|
+
export function evaluationControl(observation) {
|
|
51
|
+
if (!isDefaultObservation(observation) || !object(observation.payload))
|
|
52
|
+
return undefined;
|
|
53
|
+
if (observation.payload.kind === "evaluation-stop")
|
|
54
|
+
return null;
|
|
55
|
+
if (observation.payload.kind === "evaluation-watch" && object(observation.payload.specification)) {
|
|
56
|
+
const grader = observation.payload.specification.grader;
|
|
57
|
+
if (grader === "decision")
|
|
58
|
+
return grader;
|
|
59
|
+
if (object(grader) && typeof grader.model === "string")
|
|
60
|
+
return { model: grader.model };
|
|
61
|
+
}
|
|
62
|
+
return undefined;
|
|
63
|
+
}
|
|
64
|
+
export function evaluationWatch(ctx) {
|
|
65
|
+
return own(ctx).findLast((observation) => object(observation.payload) && observation.payload.kind === "evaluation-watch");
|
|
66
|
+
}
|
|
67
|
+
function verdicts(ctx) {
|
|
68
|
+
return own(ctx).filter((observation) => object(observation.payload) && observation.payload.kind === "evaluation-verdict");
|
|
69
|
+
}
|
|
70
|
+
export function evaluationContext(ctx) {
|
|
71
|
+
const watch = evaluationWatch(ctx);
|
|
72
|
+
const latest = verdicts(ctx).slice(-5);
|
|
73
|
+
return [
|
|
74
|
+
...(watch === undefined
|
|
75
|
+
? []
|
|
76
|
+
: ["Active chat grader:\n" + JSON.stringify({ id: watch.id, ...watch.payload.specification })]),
|
|
77
|
+
...(latest.length === 0
|
|
78
|
+
? []
|
|
79
|
+
: [
|
|
80
|
+
"Delegated verdicts (already recorded by the host; use these criterion probabilities, not another judgment or record; override only a clearly wrong specific Record with a reason):\n" +
|
|
81
|
+
JSON.stringify(latest.map(({ id, payload }) => ({
|
|
82
|
+
id,
|
|
83
|
+
...payload,
|
|
84
|
+
results: payload.results.map((result) => {
|
|
85
|
+
// An unrecorded result has no Record to correct; undefined must not match every non-override.
|
|
86
|
+
const replacement = result.record === undefined
|
|
87
|
+
? undefined
|
|
88
|
+
: ctx.state.records.find(({ payload }) => isDemonstration(payload) && payload.evaluation?.override?.of === result.record);
|
|
89
|
+
return replacement !== undefined && isDemonstration(replacement.payload)
|
|
90
|
+
? {
|
|
91
|
+
...result,
|
|
92
|
+
correction: {
|
|
93
|
+
record: replacement.id,
|
|
94
|
+
outcome: replacement.payload.outcome,
|
|
95
|
+
reason: replacement.payload.evaluation?.override?.reason,
|
|
96
|
+
},
|
|
97
|
+
}
|
|
98
|
+
: result;
|
|
99
|
+
}),
|
|
100
|
+
}))),
|
|
101
|
+
]),
|
|
102
|
+
];
|
|
103
|
+
}
|
|
104
|
+
function probability(value) {
|
|
105
|
+
if (typeof value !== "number" || !Number.isFinite(value) || value < 0 || value > 1)
|
|
106
|
+
throw new Error("Grader must return every criterion probability between 0 and 1");
|
|
107
|
+
return value;
|
|
108
|
+
}
|
|
109
|
+
/** Only the graded Nodes' standards, never their teaching guidance or conversation. */
|
|
110
|
+
export function assessmentCapabilities(graph, nodes) {
|
|
111
|
+
return nodes.map((node) => ({
|
|
112
|
+
node,
|
|
113
|
+
criterion: metadataSetsForEntity(graph, { kind: "node", id: node })
|
|
114
|
+
.map((set) => set.properties[NODE_CRITERION_PROPERTY])
|
|
115
|
+
.filter((value) => value !== undefined),
|
|
116
|
+
assessmentGuidance: nodeAssessmentGuidance(graph, node).map(({ text }) => text),
|
|
117
|
+
}));
|
|
118
|
+
}
|
|
119
|
+
function* assess(ctx, spec, source, watch) {
|
|
120
|
+
if (source.message !== undefined) {
|
|
121
|
+
// A message has one delegated verdict on this surface, even across watch replacement or a retry.
|
|
122
|
+
const existing = verdicts(ctx).find(({ payload }) => payload.message === source.message);
|
|
123
|
+
if (existing !== undefined)
|
|
124
|
+
return { verdict: existing, alreadyRecorded: true };
|
|
125
|
+
}
|
|
126
|
+
const criteria = {
|
|
127
|
+
attempted: "Did the learner attempt the posed task (including an explicit I don't know), rather than ask a question, discuss it, dispute a verdict, or quit without answering?",
|
|
128
|
+
dontKnow: "Is the learner explicitly saying they do not know the answer to the posed task?",
|
|
129
|
+
};
|
|
130
|
+
let index = 0;
|
|
131
|
+
const checks = spec.rubric.map((check) => ({
|
|
132
|
+
...check,
|
|
133
|
+
questions: check.criteria.map((criterion) => {
|
|
134
|
+
const key = "criterion-" + index++;
|
|
135
|
+
criteria[key] =
|
|
136
|
+
ASSESSMENT_GUIDANCE_INSTRUCTIONS +
|
|
137
|
+
" For Node " +
|
|
138
|
+
check.node +
|
|
139
|
+
": Does the learner's response satisfy this criterion of the posed task? " +
|
|
140
|
+
criterion;
|
|
141
|
+
return key;
|
|
142
|
+
}),
|
|
143
|
+
}));
|
|
144
|
+
const request = {
|
|
145
|
+
kind: "assess",
|
|
146
|
+
grader: spec.grader,
|
|
147
|
+
input: {
|
|
148
|
+
task: spec.task,
|
|
149
|
+
...(source.response === undefined ? {} : { response: source.response }),
|
|
150
|
+
capabilities: assessmentCapabilities(ctx.graph, spec.rubric.map(({ node }) => node)),
|
|
151
|
+
},
|
|
152
|
+
criteria,
|
|
153
|
+
...(source.message === undefined ? {} : { message: source.message }),
|
|
154
|
+
};
|
|
155
|
+
const raw = yield request;
|
|
156
|
+
if (!object(raw) || typeof raw.response !== "string" || !object(raw.probabilities))
|
|
157
|
+
throw new Error("Invalid grader response");
|
|
158
|
+
const probabilities = raw.probabilities;
|
|
159
|
+
for (const key of Object.keys(criteria))
|
|
160
|
+
probability(probabilities[key]);
|
|
161
|
+
const attempted = probability(probabilities.attempted);
|
|
162
|
+
const dontKnow = probability(probabilities.dontKnow);
|
|
163
|
+
const results = [];
|
|
164
|
+
for (const check of checks) {
|
|
165
|
+
const graded = check.criteria.map((criterion, i) => ({
|
|
166
|
+
criterion,
|
|
167
|
+
probability: probability(probabilities[check.questions[i] ?? ""]),
|
|
168
|
+
}));
|
|
169
|
+
let record;
|
|
170
|
+
if (attempted > 0.5) {
|
|
171
|
+
const outcome = dontKnow > 0.5 ? "dont-know" : graded.every(({ probability }) => probability > 0.5) ? "success" : "failure";
|
|
172
|
+
const payload = {
|
|
173
|
+
kind: "demonstration",
|
|
174
|
+
node: { node: check.node, provenance: ctx.graph.terminal },
|
|
175
|
+
task: spec.task,
|
|
176
|
+
response: raw.response,
|
|
177
|
+
unaided: spec.unaided,
|
|
178
|
+
grader: spec.grader === "decision" ? "decision" : "tutor",
|
|
179
|
+
outcome,
|
|
180
|
+
evaluation: {
|
|
181
|
+
grader: spec.grader,
|
|
182
|
+
criteria: graded,
|
|
183
|
+
...(source.message === undefined ? {} : { message: source.message }),
|
|
184
|
+
...(watch === undefined ? {} : { watch }),
|
|
185
|
+
},
|
|
186
|
+
};
|
|
187
|
+
record = yield* write({
|
|
188
|
+
at: ctx.now,
|
|
189
|
+
about: ctx.about,
|
|
190
|
+
nodes: [check.node],
|
|
191
|
+
surface: ctx.surface,
|
|
192
|
+
...(watch === undefined ? {} : { cites: [watch] }),
|
|
193
|
+
payload,
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
results.push({ node: check.node, criteria: graded, ...(record === undefined ? {} : { record }) });
|
|
197
|
+
}
|
|
198
|
+
const payload = {
|
|
199
|
+
kind: "evaluation-verdict",
|
|
200
|
+
attempted,
|
|
201
|
+
dontKnow,
|
|
202
|
+
results,
|
|
203
|
+
...(source.message === undefined ? {} : { message: source.message }),
|
|
204
|
+
...(watch === undefined ? {} : { watch }),
|
|
205
|
+
};
|
|
206
|
+
const id = yield* write({
|
|
207
|
+
at: ctx.now,
|
|
208
|
+
about: ctx.about,
|
|
209
|
+
surface: ctx.surface,
|
|
210
|
+
nodes: spec.rubric.map(({ node }) => node),
|
|
211
|
+
cites: results.flatMap(({ record }) => (record === undefined ? [] : [record])),
|
|
212
|
+
payload,
|
|
213
|
+
});
|
|
214
|
+
return { verdict: { id, ...payload }, alreadyRecorded: true };
|
|
215
|
+
}
|
|
216
|
+
/** Called before a web tutor turn; only host-proven learner replies are passed here. */
|
|
217
|
+
export function* evaluateWatchedReply(ctx, message) {
|
|
218
|
+
const watch = evaluationWatch(ctx);
|
|
219
|
+
if (watch === undefined)
|
|
220
|
+
return null;
|
|
221
|
+
const spec = specification({ ...watch.payload.specification }, ctx);
|
|
222
|
+
return yield* assess(ctx, spec, { message }, watch.id);
|
|
223
|
+
}
|
|
224
|
+
const specProperties = {
|
|
225
|
+
task: { type: "string", minLength: 1 },
|
|
226
|
+
rubric: {
|
|
227
|
+
type: "array",
|
|
228
|
+
minItems: 1,
|
|
229
|
+
items: {
|
|
230
|
+
type: "object",
|
|
231
|
+
additionalProperties: false,
|
|
232
|
+
required: ["node", "criteria"],
|
|
233
|
+
properties: {
|
|
234
|
+
node: { type: "string", pattern: "^node-.+" },
|
|
235
|
+
criteria: { type: "array", minItems: 1, items: { type: "string", minLength: 1 } },
|
|
236
|
+
},
|
|
237
|
+
},
|
|
238
|
+
},
|
|
239
|
+
unaided: { type: "boolean" },
|
|
240
|
+
grader: {
|
|
241
|
+
anyOf: [
|
|
242
|
+
{ const: "decision" },
|
|
243
|
+
{
|
|
244
|
+
type: "object",
|
|
245
|
+
additionalProperties: false,
|
|
246
|
+
required: ["model"],
|
|
247
|
+
properties: { model: { type: "string", minLength: 1 } },
|
|
248
|
+
},
|
|
249
|
+
],
|
|
250
|
+
},
|
|
251
|
+
};
|
|
252
|
+
export const evaluationTools = [
|
|
253
|
+
{
|
|
254
|
+
name: "evaluation_watch",
|
|
255
|
+
description: "Start or replace a chat grader. Pin the posed task, per-Node rubric and whether it is unaided; stop or replace it when the check or assistance changes. Materials record their own outcomes.",
|
|
256
|
+
schema: { type: "object", additionalProperties: false, properties: specProperties, required: specKeys },
|
|
257
|
+
*run(raw, ctx) {
|
|
258
|
+
const spec = specification(args(raw, specKeys), ctx);
|
|
259
|
+
const previous = evaluationWatch(ctx);
|
|
260
|
+
const id = yield* write({
|
|
261
|
+
at: ctx.now,
|
|
262
|
+
about: ctx.about,
|
|
263
|
+
surface: ctx.surface,
|
|
264
|
+
...(previous === undefined ? {} : { supersedes: previous.id }),
|
|
265
|
+
payload: { kind: "evaluation-watch", specification: spec },
|
|
266
|
+
});
|
|
267
|
+
return { watch: id, ...spec };
|
|
268
|
+
},
|
|
269
|
+
},
|
|
270
|
+
{
|
|
271
|
+
name: "evaluation_stop",
|
|
272
|
+
description: "Stop this chat's grader.",
|
|
273
|
+
schema: { type: "object", additionalProperties: false, properties: {} },
|
|
274
|
+
*run(raw, ctx) {
|
|
275
|
+
args(raw, []);
|
|
276
|
+
const previous = evaluationWatch(ctx);
|
|
277
|
+
if (previous === undefined)
|
|
278
|
+
return { stopped: false };
|
|
279
|
+
const id = yield* write({
|
|
280
|
+
at: ctx.now,
|
|
281
|
+
about: ctx.about,
|
|
282
|
+
surface: ctx.surface,
|
|
283
|
+
supersedes: previous.id,
|
|
284
|
+
payload: { kind: "evaluation-stop" },
|
|
285
|
+
});
|
|
286
|
+
return { stopped: true, observation: id };
|
|
287
|
+
},
|
|
288
|
+
},
|
|
289
|
+
{
|
|
290
|
+
name: "evaluation_judge",
|
|
291
|
+
description: "Grade one response and record the verdict. Supply response text or a selected learner message identity for original media.",
|
|
292
|
+
schema: {
|
|
293
|
+
type: "object",
|
|
294
|
+
additionalProperties: false,
|
|
295
|
+
required: specKeys,
|
|
296
|
+
properties: { ...specProperties, response: { type: "string" }, message: { type: "string", minLength: 1 } },
|
|
297
|
+
oneOf: [
|
|
298
|
+
{
|
|
299
|
+
type: "object",
|
|
300
|
+
properties: { response: { type: "string" } },
|
|
301
|
+
required: ["response"],
|
|
302
|
+
additionalProperties: true,
|
|
303
|
+
},
|
|
304
|
+
{
|
|
305
|
+
type: "object",
|
|
306
|
+
properties: { message: { type: "string" } },
|
|
307
|
+
required: ["message"],
|
|
308
|
+
additionalProperties: true,
|
|
309
|
+
},
|
|
310
|
+
],
|
|
311
|
+
},
|
|
312
|
+
*run(raw, ctx) {
|
|
313
|
+
const input = args(raw, [...specKeys, "response", "message"]);
|
|
314
|
+
if ((input.message === undefined) === (input.response === undefined))
|
|
315
|
+
throw new Error("Supply response or message");
|
|
316
|
+
if (input.response !== undefined && typeof input.response !== "string")
|
|
317
|
+
throw new Error("Response must be text");
|
|
318
|
+
return yield* assess(ctx, specification(input, ctx), input.message === undefined ? { response: String(input.response) } : { message: text(input.message) });
|
|
319
|
+
},
|
|
320
|
+
},
|
|
321
|
+
{
|
|
322
|
+
name: "evaluation_override",
|
|
323
|
+
description: "Correct one clearly wrong delegated, mechanically graded or Material Record, retracting and replacing it with a reason. Learner disputes use the records Skill.",
|
|
324
|
+
schema: {
|
|
325
|
+
type: "object",
|
|
326
|
+
additionalProperties: false,
|
|
327
|
+
required: ["of", "outcome", "reason"],
|
|
328
|
+
properties: {
|
|
329
|
+
of: { type: "string", pattern: "^obs-.+" },
|
|
330
|
+
outcome: { enum: ["success", "failure", "dont-know"] },
|
|
331
|
+
reason: { type: "string", minLength: 1 },
|
|
332
|
+
},
|
|
333
|
+
},
|
|
334
|
+
*run(raw, ctx) {
|
|
335
|
+
const input = args(raw, ["of", "outcome", "reason"]);
|
|
336
|
+
if (!isObservationId(input.of))
|
|
337
|
+
throw new Error("Expected a Record identity");
|
|
338
|
+
const of = input.of;
|
|
339
|
+
const observations = yield* read.observations();
|
|
340
|
+
const active = effectiveObservations(electedObservations(observations), ctx.now);
|
|
341
|
+
assertDefaultRetraction(of, active);
|
|
342
|
+
const original = active.find(({ id }) => id === of);
|
|
343
|
+
if (original === undefined ||
|
|
344
|
+
!isDefaultObservation(original) ||
|
|
345
|
+
!isDemonstration(original.payload) ||
|
|
346
|
+
(original.payload.grader !== "mechanical" &&
|
|
347
|
+
original.payload.material === undefined &&
|
|
348
|
+
(original.payload.evaluation === undefined || !("grader" in original.payload.evaluation))))
|
|
349
|
+
throw new Error("Override requires a delegated, mechanically graded or Material demonstration");
|
|
350
|
+
if (input.outcome !== "success" && input.outcome !== "failure" && input.outcome !== "dont-know")
|
|
351
|
+
throw new Error("Invalid override outcome");
|
|
352
|
+
const reason = text(input.reason);
|
|
353
|
+
const retraction = yield* write({
|
|
354
|
+
at: ctx.now,
|
|
355
|
+
surface: ctx.surface,
|
|
356
|
+
about: ctx.about,
|
|
357
|
+
cites: [of],
|
|
358
|
+
payload: { kind: "retraction", of },
|
|
359
|
+
});
|
|
360
|
+
const id = yield* write({
|
|
361
|
+
at: original.at,
|
|
362
|
+
surface: original.surface,
|
|
363
|
+
about: original.about,
|
|
364
|
+
nodes: original.nodes,
|
|
365
|
+
cites: [of, retraction],
|
|
366
|
+
payload: {
|
|
367
|
+
...original.payload,
|
|
368
|
+
outcome: input.outcome,
|
|
369
|
+
grader: "tutor",
|
|
370
|
+
evaluation: { ...original.payload.evaluation, override: { of, reason } },
|
|
371
|
+
},
|
|
372
|
+
});
|
|
373
|
+
return { record: id, retracted: of, outcome: input.outcome, reason, alreadyRecorded: true };
|
|
374
|
+
},
|
|
375
|
+
},
|
|
376
|
+
];
|
package/dist/event.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type PlatformEvent, type Program } from "@mmon-co/ncept-core/observations";
|
|
2
|
+
import type { Context } from "@mmon-co/ncept-core/theory";
|
|
3
|
+
import { type DefaultState } from "./state.js";
|
|
4
|
+
/** Refine only pending demonstrations; also used by the tutor's refine_records tool. */
|
|
5
|
+
export declare function refinePendingHomes(ctx: Context<DefaultState>): Program<void>;
|
|
6
|
+
/** The interpreter provides read-your-writes; persistence, atomicity and execution failures are the host's. */
|
|
7
|
+
export declare function event(input: PlatformEvent, ctx: Context<DefaultState>): Program<void>;
|