@mmon-co/ncept-local 0.3.12 → 0.4.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/README.md +9 -7
- package/dist/directory.d.ts +2 -1
- package/dist/directory.js +67 -32
- package/dist/exchange.d.ts +17 -10
- package/dist/exchange.js +171 -77
- package/dist/host-tools.js +11 -9
- package/dist/hub-auth.d.ts +1 -0
- package/dist/hub-auth.js +30 -3
- package/dist/hub.d.ts +4 -4
- package/dist/hub.js +120 -104
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/learning.js +1 -1
- package/dist/packed.d.ts +21 -0
- package/dist/packed.js +80 -0
- package/dist/runtime.d.ts +16 -7
- package/dist/runtime.js +28 -26
- package/package.json +1 -1
package/dist/exchange.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import { attachmentDigest,
|
|
1
|
+
import { attachmentDigest, canonicalDelta, contentDigest, contentAttachments, resolvedGraphAttachments, isObservation, sameExactPatchRef, theoryPinMigration, revisionContent, isContentDigest, isMissionRevision, isNodeId, isPatchId, isProfileLogEntry, isRunActiveChange, mergeProfileLogs, migrateTheoryProfile, resolveTheory, revisionDigest, } from "@mmon-co/ncept-core";
|
|
2
2
|
import { object, parsePiSession, relocatePiSession } from "./sessions.js";
|
|
3
3
|
import { decodeTar, encodeTar } from "./tar.js";
|
|
4
|
+
import { PackedPatches, packedFiles } from "./packed.js";
|
|
5
|
+
export { packedFiles } from "./packed.js";
|
|
6
|
+
export { encodeTar } from "./tar.js";
|
|
4
7
|
export const DEFAULT_THEORY_PACKAGES = ["@mmon-co/ncept-default-theory"];
|
|
5
8
|
export const DEFAULT_THEORY_REQUIREMENT = { theory: "default", range: "~1.0" };
|
|
6
9
|
export const utf8 = new TextEncoder();
|
|
@@ -27,7 +30,7 @@ export function sessionFilename(value) {
|
|
|
27
30
|
export function parseManifest(bytes) {
|
|
28
31
|
const value = json(bytes, "profile.json");
|
|
29
32
|
if (!object(value) ||
|
|
30
|
-
value.format !== 1 ||
|
|
33
|
+
(value.format !== 1 && value.format !== 2) ||
|
|
31
34
|
!exact(value.personal) ||
|
|
32
35
|
(value.log !== undefined && !isContentDigest(value.log)) ||
|
|
33
36
|
!object(value.theory) ||
|
|
@@ -48,7 +51,7 @@ export function parseManifest(bytes) {
|
|
|
48
51
|
if (new Set(Object.values(sessions)).size !== Object.keys(sessions).length)
|
|
49
52
|
throw new Error("A pi session file cannot belong to two surfaces");
|
|
50
53
|
return {
|
|
51
|
-
format:
|
|
54
|
+
format: value.format,
|
|
52
55
|
personal: value.personal,
|
|
53
56
|
...(value.log === undefined ? {} : { log: value.log }),
|
|
54
57
|
theory: { theory: value.theory.theory, range: value.theory.range },
|
|
@@ -96,17 +99,8 @@ export function logBytes(entries) {
|
|
|
96
99
|
const merged = mergeProfileLogs([], entries);
|
|
97
100
|
return utf8.encode(merged.length ? merged.map((entry) => JSON.stringify(entry)).join("\n") + "\n" : "");
|
|
98
101
|
}
|
|
99
|
-
function
|
|
100
|
-
|
|
101
|
-
return;
|
|
102
|
-
if (object(value) && value.kind === "blob" && isContentDigest(value.hash) && !blobs.has(value.hash))
|
|
103
|
-
throw new Error("Missing Profile blob: " + value.hash);
|
|
104
|
-
for (const child of Object.values(value))
|
|
105
|
-
requireAttachments(child, blobs);
|
|
106
|
-
}
|
|
107
|
-
/** Pure validation; safe in a Convex action. No filesystem, package loading, or provider calls. */
|
|
108
|
-
export function validate(files, theories) {
|
|
109
|
-
const profile = validateStructure(files);
|
|
102
|
+
export async function validate(files, theories) {
|
|
103
|
+
const profile = await validateStructure(files);
|
|
110
104
|
const { manifest } = profile;
|
|
111
105
|
try {
|
|
112
106
|
resolveTheory(manifest.theory, theories);
|
|
@@ -119,35 +113,32 @@ export function validate(files, theories) {
|
|
|
119
113
|
export function liveLogPath(manifest) {
|
|
120
114
|
return manifest.log === undefined ? "log.jsonl" : "log-" + manifest.log + ".jsonl";
|
|
121
115
|
}
|
|
122
|
-
function validateStructure(files) {
|
|
123
|
-
const
|
|
124
|
-
|
|
116
|
+
async function validateStructure(files) {
|
|
117
|
+
const stored = parseManifest(files.get("profile.json"));
|
|
118
|
+
if (stored.format !== 2)
|
|
119
|
+
throw new Error("Profile needs format migration");
|
|
120
|
+
const manifest = { ...stored, format: 2 };
|
|
121
|
+
const store = PackedPatches.fromFiles(files);
|
|
125
122
|
const blobs = new Map();
|
|
126
123
|
const sessionPaths = new Set(Object.values(manifest.sessions).map((filename) => "sessions/" + filename));
|
|
127
124
|
for (const [path, bytes] of files) {
|
|
128
|
-
if (path === "profile.json" ||
|
|
125
|
+
if (path === "profile.json" ||
|
|
126
|
+
path === liveLogPath(manifest) ||
|
|
127
|
+
sessionPaths.has(path) ||
|
|
128
|
+
path.startsWith("manifests/") ||
|
|
129
|
+
path.startsWith("chunks/"))
|
|
129
130
|
continue;
|
|
130
|
-
if (path.startsWith("
|
|
131
|
-
const digest = path.slice(8, -5);
|
|
132
|
-
const content = json(bytes, path);
|
|
133
|
-
if (!isContentDigest(digest) || !patchContent(content))
|
|
134
|
-
throw new Error("Invalid Patch file: " + path);
|
|
135
|
-
if (revisionDigest(content) !== digest)
|
|
136
|
-
throw new Error("Patch content digest mismatch: " + path);
|
|
137
|
-
contents.set(digest, content);
|
|
138
|
-
}
|
|
139
|
-
else if (path.startsWith("blobs/")) {
|
|
140
|
-
const digest = path.slice(6);
|
|
141
|
-
if (!isContentDigest(digest) || attachmentDigest(bytes) !== digest)
|
|
142
|
-
throw new Error("Blob digest mismatch: " + path);
|
|
143
|
-
blobs.set(digest, bytes);
|
|
144
|
-
}
|
|
145
|
-
else
|
|
131
|
+
if (!path.startsWith("blobs/"))
|
|
146
132
|
throw new Error("Unexpected Profile exchange file: " + path);
|
|
133
|
+
const digest = path.slice(6);
|
|
134
|
+
if (!isContentDigest(digest) || attachmentDigest(bytes) !== digest)
|
|
135
|
+
throw new Error("Blob digest mismatch: " + path);
|
|
136
|
+
blobs.set(digest, bytes);
|
|
147
137
|
}
|
|
148
|
-
const
|
|
149
|
-
for (const
|
|
150
|
-
|
|
138
|
+
const reading = await store.reading(manifest.personal);
|
|
139
|
+
for (const { hash } of [...resolvedGraphAttachments(reading.graph), ...contentAttachments(reading.personal)])
|
|
140
|
+
if (!blobs.has(hash))
|
|
141
|
+
throw new Error("Missing Profile blob: " + hash);
|
|
151
142
|
const sessions = new Map();
|
|
152
143
|
for (const [surface, filename] of Object.entries(manifest.sessions)) {
|
|
153
144
|
const bytes = files.get("sessions/" + filename);
|
|
@@ -160,7 +151,7 @@ function validateStructure(files) {
|
|
|
160
151
|
const log = files.get(liveLogPath(manifest));
|
|
161
152
|
if (manifest.log !== undefined && (!log || attachmentDigest(log) !== manifest.log))
|
|
162
153
|
throw new Error("Profile log digest mismatch");
|
|
163
|
-
return { manifest,
|
|
154
|
+
return { manifest, ...reading, log: parseLog(log), blobs, sessions };
|
|
164
155
|
}
|
|
165
156
|
/** Rewrite host-owned state before validating the log in its current shape. */
|
|
166
157
|
export function migrateLessonLog(files) {
|
|
@@ -251,60 +242,163 @@ export function migrateLessonLog(files) {
|
|
|
251
242
|
return next;
|
|
252
243
|
}
|
|
253
244
|
/** Migrate structurally valid live data before ordinary strict Theory resolution. */
|
|
254
|
-
export function migrateProfileFiles(files, theories) {
|
|
245
|
+
export async function migrateProfileFiles(files, theories) {
|
|
255
246
|
files = migrateLessonLog(files);
|
|
256
|
-
const
|
|
257
|
-
|
|
247
|
+
const next = new Map(files);
|
|
248
|
+
let manifest = parseManifest(files.get("profile.json"));
|
|
249
|
+
const original = manifest;
|
|
250
|
+
const bytes = files.get(liveLogPath(manifest));
|
|
251
|
+
if (manifest.log && (!bytes || attachmentDigest(bytes) !== manifest.log))
|
|
252
|
+
throw new Error("Profile log digest mismatch");
|
|
253
|
+
const originalLog = parseLog(bytes);
|
|
254
|
+
let log = originalLog;
|
|
255
|
+
const store = new PackedPatches();
|
|
256
|
+
if (manifest.format === 1) {
|
|
257
|
+
const old = new Map();
|
|
258
|
+
for (const [path, data] of files) {
|
|
259
|
+
if (path.startsWith("chunks/") || path.startsWith("manifests/"))
|
|
260
|
+
throw new Error("Unexpected Profile exchange file: " + path);
|
|
261
|
+
if (!path.startsWith("patches/"))
|
|
262
|
+
continue;
|
|
263
|
+
const digest = path.slice(8, -5);
|
|
264
|
+
const c = json(data, path);
|
|
265
|
+
if (!path.endsWith(".json") ||
|
|
266
|
+
!isContentDigest(digest) ||
|
|
267
|
+
!patchContent(c) ||
|
|
268
|
+
(revisionDigest(c) !== digest &&
|
|
269
|
+
contentDigest({ bases: c.bases, delta: canonicalDelta(c.delta), metadata: c.metadata }) !== digest))
|
|
270
|
+
throw new Error("Patch content digest mismatch: " + path);
|
|
271
|
+
old.set(digest, c);
|
|
272
|
+
next.delete(path);
|
|
273
|
+
}
|
|
274
|
+
const mapped = new Map();
|
|
275
|
+
const active = new Set();
|
|
276
|
+
function remap(r) {
|
|
277
|
+
const c = old.get(r.digest);
|
|
278
|
+
if (!c)
|
|
279
|
+
return r;
|
|
280
|
+
let digest = mapped.get(r.digest);
|
|
281
|
+
if (!digest) {
|
|
282
|
+
if (active.has(r.digest))
|
|
283
|
+
throw new Error("Cyclic legacy Patch reference");
|
|
284
|
+
active.add(r.digest);
|
|
285
|
+
digest = store.add({
|
|
286
|
+
...c,
|
|
287
|
+
bases: c.bases.map(remap),
|
|
288
|
+
delta: {
|
|
289
|
+
operations: c.delta.operations.map((op) => op.kind === "mask-contribution" ? { ...op, mask: { ...op.mask, source: remap(op.mask.source) } } : op),
|
|
290
|
+
},
|
|
291
|
+
});
|
|
292
|
+
active.delete(r.digest);
|
|
293
|
+
mapped.set(r.digest, digest);
|
|
294
|
+
}
|
|
295
|
+
return { ...r, digest };
|
|
296
|
+
}
|
|
297
|
+
for (const digest of old.keys())
|
|
298
|
+
remap({ identity: "patch-history", digest });
|
|
299
|
+
log = log.map((entry) => {
|
|
300
|
+
if ("kind" in entry && entry.kind === "mission.revised")
|
|
301
|
+
return {
|
|
302
|
+
...entry,
|
|
303
|
+
mission: {
|
|
304
|
+
...entry.mission,
|
|
305
|
+
targets: entry.mission.targets.map((t) => ({ ...t, provenance: remap(t.provenance) })),
|
|
306
|
+
},
|
|
307
|
+
};
|
|
308
|
+
return patchReceipt(entry, (from, to) => ({ from: remap(from), to: remap(to) }));
|
|
309
|
+
});
|
|
310
|
+
manifest = { ...manifest, format: 2, personal: remap(manifest.personal) };
|
|
311
|
+
}
|
|
312
|
+
const matches = theories.filter((t) => t.id === manifest.theory.theory);
|
|
258
313
|
const theory = matches[0];
|
|
259
|
-
if (matches.length !== 1 || theory
|
|
314
|
+
if (matches.length !== 1 || !theory)
|
|
260
315
|
throw new Error("Profile migration needs exactly one supplied Theory implementation");
|
|
261
|
-
const requirement =
|
|
316
|
+
const requirement = manifest.theory;
|
|
262
317
|
// Web exchanges have also used exact release pins. Extract their stored minor,
|
|
263
318
|
// not the installed minor; broad caller-supplied ranges remain ordinary strict reads.
|
|
264
319
|
const exact = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:[-+][0-9A-Za-z.+-]+)?$/.exec(requirement.range);
|
|
265
320
|
const pin = exact ? { ...requirement, range: "~" + exact[1] + "." + exact[2] } : requirement;
|
|
266
|
-
if (
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
321
|
+
if (/^~\d+\.\d+$/.test(pin.range)) {
|
|
322
|
+
try {
|
|
323
|
+
const migratedPin = theoryPinMigration(theory, pin);
|
|
324
|
+
if (migratedPin) {
|
|
325
|
+
if (migratedPin.range !== requirement.range)
|
|
326
|
+
manifest = { ...manifest, theory: migratedPin };
|
|
327
|
+
}
|
|
328
|
+
else {
|
|
329
|
+
const source = original.format === 1 ? store : PackedPatches.fromFiles(files);
|
|
330
|
+
const migrate = (ref, entries) => {
|
|
331
|
+
let patches;
|
|
332
|
+
try {
|
|
333
|
+
patches = source.dense(ref);
|
|
334
|
+
}
|
|
335
|
+
catch {
|
|
336
|
+
return undefined;
|
|
337
|
+
}
|
|
338
|
+
const result = migrateTheoryProfile(theory, pin, { patches, log: entries });
|
|
339
|
+
for (const r of result.profile.patches.revisions)
|
|
340
|
+
store.add(revisionContent(r));
|
|
341
|
+
return result;
|
|
342
|
+
};
|
|
343
|
+
const live = migrate(manifest.personal, log);
|
|
344
|
+
if (!live)
|
|
345
|
+
throw new Error("Cannot adopt Hub release; its publisher must republish for the installed Theory");
|
|
346
|
+
const head = live.profile.patches.terminal;
|
|
347
|
+
log = live.profile.log.map((entry) => patchReceipt(entry, (from, to) => {
|
|
348
|
+
if (!sameExactPatchRef(to, manifest.personal))
|
|
349
|
+
return { from, to };
|
|
350
|
+
const prior = migrate(from, []);
|
|
351
|
+
// An unchanged live digest can still match the old receipt under the new pin.
|
|
352
|
+
return prior ? { from: prior.profile.patches.terminal, to: head } : { from, to, undoUnavailable: true };
|
|
353
|
+
}));
|
|
354
|
+
manifest = { ...manifest, personal: head, theory: live.requirement };
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
catch (error) {
|
|
358
|
+
throw new Error("Profile Theory " + requirement.theory + " " + requirement.range + ": " + String(error));
|
|
359
|
+
}
|
|
273
360
|
}
|
|
274
|
-
|
|
275
|
-
|
|
361
|
+
if (log !== originalLog && JSON.stringify(log) !== JSON.stringify(originalLog)) {
|
|
362
|
+
const data = logBytes(log);
|
|
363
|
+
next.delete(liveLogPath(manifest));
|
|
364
|
+
manifest = { ...manifest, log: attachmentDigest(data) };
|
|
365
|
+
next.set(liveLogPath(manifest), data);
|
|
276
366
|
}
|
|
277
|
-
const
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
const { ref, ...content } = revision;
|
|
281
|
-
const path = "patches/" + ref.digest + ".json";
|
|
282
|
-
next.set(path, jsonBytes(content));
|
|
283
|
-
}
|
|
284
|
-
const log = logBytes(result.profile.log);
|
|
285
|
-
const manifest = {
|
|
286
|
-
...current.manifest,
|
|
287
|
-
personal: result.profile.patches.terminal,
|
|
288
|
-
theory: result.requirement,
|
|
289
|
-
log: attachmentDigest(log),
|
|
290
|
-
};
|
|
291
|
-
next.delete(liveLogPath(current.manifest));
|
|
292
|
-
next.set(liveLogPath(manifest), log);
|
|
367
|
+
for (const [path, data] of packedFiles(store))
|
|
368
|
+
next.set(path, data);
|
|
369
|
+
if (manifest !== original)
|
|
293
370
|
next.set("profile.json", jsonBytes(manifest));
|
|
294
|
-
|
|
295
|
-
validate(next, theories);
|
|
371
|
+
await validate(next, theories);
|
|
296
372
|
return next;
|
|
297
373
|
}
|
|
374
|
+
function patchReceipt(entry, map) {
|
|
375
|
+
if (!isObservation(entry) ||
|
|
376
|
+
entry.by !== "platform" ||
|
|
377
|
+
!object(entry.payload) ||
|
|
378
|
+
entry.payload.kind !== "local.patch" ||
|
|
379
|
+
!exact(entry.payload.from) ||
|
|
380
|
+
!exact(entry.payload.to))
|
|
381
|
+
return entry;
|
|
382
|
+
return { ...entry, payload: { ...entry.payload, ...map(entry.payload.from, entry.payload.to) } };
|
|
383
|
+
}
|
|
298
384
|
/** Only exchange files belong in this map. The directory adapter excludes materials and untrusted sessions. */
|
|
299
|
-
export function pack(files, theories) {
|
|
300
|
-
validate(files, theories);
|
|
301
|
-
|
|
385
|
+
export async function pack(files, theories) {
|
|
386
|
+
const { patches, graph, personal } = await validate(files, theories);
|
|
387
|
+
const archive = new Map(files);
|
|
388
|
+
const kept = new Set([
|
|
389
|
+
...patches.manifests.map(([digest]) => "manifests/" + digest + ".json"),
|
|
390
|
+
...patches.chunks.map(([digest]) => "chunks/" + digest + ".json"),
|
|
391
|
+
...[...resolvedGraphAttachments(graph), ...contentAttachments(personal)].map((a) => "blobs/" + a.hash),
|
|
392
|
+
]);
|
|
393
|
+
for (const path of files.keys())
|
|
394
|
+
if (/^(manifests|chunks|blobs)\//.test(path) && !kept.has(path))
|
|
395
|
+
archive.delete(path);
|
|
396
|
+
return encodeTar(archive);
|
|
302
397
|
}
|
|
303
|
-
export function unpack(archive, theories, options = {}) {
|
|
304
|
-
const files = migrateProfileFiles(decodeTar(archive), theories);
|
|
305
|
-
const profile = validate(files, theories);
|
|
398
|
+
export async function unpack(archive, theories, options = {}) {
|
|
399
|
+
const files = await migrateProfileFiles(decodeTar(archive), theories);
|
|
306
400
|
if (options.cwd !== undefined)
|
|
307
|
-
for (const filename of Object.values(profile.
|
|
401
|
+
for (const filename of Object.values(parseManifest(files.get("profile.json")).sessions)) {
|
|
308
402
|
const path = "sessions/" + filename;
|
|
309
403
|
const source = files.get(path);
|
|
310
404
|
if (source)
|
package/dist/host-tools.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
2
2
|
import { join } from "node:path";
|
|
3
|
-
import {
|
|
3
|
+
import { attachmentDigest, compileSparseGraphDiff, composePatch, graphDraftOperationKey, isMaterialMeta, isMission, isNodeId, nodeCascadedProperty, parseGraphQuery, projectVisualGraph, sameExactPatchRef, selectGraph, tagIndex, } from "@mmon-co/ncept-core";
|
|
4
|
+
import { PackedPatches } from "./packed.js";
|
|
4
5
|
import { localPayload, platform, sessionStates, transcript } from "./runtime.js";
|
|
5
6
|
import { mechanics } from "./mechanics.js";
|
|
6
7
|
import { object } from "./sessions.js";
|
|
@@ -82,8 +83,8 @@ function graphDiff(host, input, session, batch) {
|
|
|
82
83
|
citations: input.citations === undefined ? (previous?.citations ?? []) : citations(input.citations),
|
|
83
84
|
retractions: input.retractions === undefined ? (previous?.retractions ?? []) : strings(input.retractions),
|
|
84
85
|
};
|
|
85
|
-
const compiled =
|
|
86
|
-
return { view, compiled, edits, content:
|
|
86
|
+
const compiled = await compileSparseGraphDiff({ terminal: view.bundle.terminal, store: PackedPatches.fromFiles(await host.runtime.profile.files()) }, edits.operations, edits.targets, edits.citations, edits.retractions, new Map(view.personal.bases.map((ref) => [ref.identity, ref])));
|
|
87
|
+
return { view, compiled, edits, content: compiled.content };
|
|
87
88
|
});
|
|
88
89
|
}
|
|
89
90
|
function page(items, input) {
|
|
@@ -192,7 +193,7 @@ export function hostTools(host, opened, capabilities, skills, metadataKeys, batc
|
|
|
192
193
|
};
|
|
193
194
|
}
|
|
194
195
|
case "patch": {
|
|
195
|
-
const patch = input.ref === undefined ? view : await host.runtime.
|
|
196
|
+
const patch = input.ref === undefined ? view : await host.runtime.readPatch(exactRef(input.ref), view.profile);
|
|
196
197
|
return { content: patch.bundle };
|
|
197
198
|
}
|
|
198
199
|
case "session": {
|
|
@@ -487,16 +488,17 @@ export function hostTools(host, opened, capabilities, skills, metadataKeys, batc
|
|
|
487
488
|
.map((entry) => localPayload(entry, "local.patch"))
|
|
488
489
|
.filter((entry) => entry !== undefined)
|
|
489
490
|
.at(-1);
|
|
490
|
-
if (!entry ||
|
|
491
|
+
if (!entry ||
|
|
492
|
+
entry.undoUnavailable ||
|
|
493
|
+
!object(entry.from) ||
|
|
494
|
+
!object(entry.to) ||
|
|
495
|
+
entry.to.digest !== view.graph.terminal.digest)
|
|
491
496
|
throw new Error("No current Session edit to undo");
|
|
492
497
|
const before = await host.runtime.snapshot(exactRef(entry.from));
|
|
493
|
-
const revision = before.bundle.revisions.find(({ ref }) => sameExactPatchRef(ref, before.bundle.terminal));
|
|
494
|
-
if (!revision)
|
|
495
|
-
throw new Error("Undo revision is missing");
|
|
496
498
|
return {
|
|
497
499
|
content: {
|
|
498
500
|
status: "restored",
|
|
499
|
-
patch: await acceptContent(host, session, view.graph.terminal,
|
|
501
|
+
patch: await acceptContent(host, session, view.graph.terminal, before.personal),
|
|
500
502
|
},
|
|
501
503
|
};
|
|
502
504
|
});
|
package/dist/hub-auth.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { type OAuthClientProvider, type OAuthDiscoveryState } from "@modelcontex
|
|
|
2
2
|
import type { OAuthClientInformationMixed, OAuthTokens } from "@modelcontextprotocol/sdk/shared/auth.js";
|
|
3
3
|
import type { HubOptions } from "./host.js";
|
|
4
4
|
export declare function hubBaseUrl(value?: string): string;
|
|
5
|
+
export declare function clearHubCredentials(credentialsFile?: string): Promise<void>;
|
|
5
6
|
export declare function hasHubCredentials(options: HubOptions): Promise<boolean>;
|
|
6
7
|
export declare function beginHubBrowserSignIn(options: HubOptions): Promise<HubBrowserSignIn>;
|
|
7
8
|
export declare class HubSignInRequired extends Error {
|
package/dist/hub-auth.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createServer } from "node:http";
|
|
2
|
-
import { mkdir, readFile, rename, writeFile } from "node:fs/promises";
|
|
3
|
-
import {
|
|
2
|
+
import { link, mkdir, readFile, rename, rm, writeFile } from "node:fs/promises";
|
|
3
|
+
import { homedir } from "node:os";
|
|
4
|
+
import { dirname, join } from "node:path";
|
|
4
5
|
import { createHash, randomBytes, randomUUID } from "node:crypto";
|
|
5
6
|
import { execFile } from "node:child_process";
|
|
6
7
|
import { auth, UnauthorizedError, } from "@modelcontextprotocol/sdk/client/auth.js";
|
|
@@ -18,6 +19,32 @@ export function hubBaseUrl(value = defaultHub) {
|
|
|
18
19
|
throw new Error("Hub URL must use HTTPS (or loopback HTTP)");
|
|
19
20
|
return url.href.replace(/\/$/, "");
|
|
20
21
|
}
|
|
22
|
+
async function prepareCredentialsPath() {
|
|
23
|
+
const home = homedir();
|
|
24
|
+
const current = credentialsPath(home);
|
|
25
|
+
const previous = join(home, ".config", "ncept", "credentials.json");
|
|
26
|
+
try {
|
|
27
|
+
await mkdir(dirname(current), { recursive: true, mode: 0o700 });
|
|
28
|
+
await link(previous, current);
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
if (error instanceof Error && "code" in error) {
|
|
32
|
+
if (error.code === "ENOENT")
|
|
33
|
+
return current;
|
|
34
|
+
if (error.code !== "EEXIST")
|
|
35
|
+
throw error;
|
|
36
|
+
}
|
|
37
|
+
else
|
|
38
|
+
throw error;
|
|
39
|
+
}
|
|
40
|
+
// A new-format sign-in wins if both files exist. Retire the old file so it
|
|
41
|
+
// cannot be restored by a later lookup after sign-out.
|
|
42
|
+
await rm(previous, { force: true });
|
|
43
|
+
return current;
|
|
44
|
+
}
|
|
45
|
+
export async function clearHubCredentials(credentialsFile) {
|
|
46
|
+
await rm(credentialsFile ?? (await prepareCredentialsPath()), { force: true });
|
|
47
|
+
}
|
|
21
48
|
export async function hasHubCredentials(options) {
|
|
22
49
|
return Boolean((await HubAuth.open(hubBaseUrl(options.url) + "/mcp", options)).tokens());
|
|
23
50
|
}
|
|
@@ -65,7 +92,7 @@ export class HubAuth {
|
|
|
65
92
|
this.clientMetadataUrl = clientMetadataUrl;
|
|
66
93
|
}
|
|
67
94
|
static async open(resource, options) {
|
|
68
|
-
const provider = new HubAuth(resource, options.credentialsFile ??
|
|
95
|
+
const provider = new HubAuth(resource, options.credentialsFile ?? (await prepareCredentialsPath()), options.openUrl ?? browser, options.clientMetadataUrl);
|
|
69
96
|
provider.credentials = (await load(provider.path))[resource] ?? {};
|
|
70
97
|
return provider;
|
|
71
98
|
}
|
package/dist/hub.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type Mission, type ResolvedGraph, type SparsePatchBundle, type ReifiedMissionOrigin } from "@mmon-co/ncept-core";
|
|
2
2
|
import { type ProfileDirectory } from "./directory.js";
|
|
3
3
|
import { type ConfiguredTheory } from "./exchange.js";
|
|
4
4
|
import type { Confirm, Host, HubOptions } from "./host.js";
|
|
@@ -7,8 +7,8 @@ import type { Confirm, Host, HubOptions } from "./host.js";
|
|
|
7
7
|
* the release carries that map alone whatever Patches it was learnt from, and offering the
|
|
8
8
|
* Mission to whoever opens it.
|
|
9
9
|
*/
|
|
10
|
-
export declare function missionBundle(
|
|
11
|
-
bundle:
|
|
10
|
+
export declare function missionBundle(graph: ResolvedGraph, mission: Mission, title: string, origin?: ReifiedMissionOrigin): Promise<{
|
|
11
|
+
bundle: SparsePatchBundle;
|
|
12
12
|
skills: number;
|
|
13
|
-
}
|
|
13
|
+
}>;
|
|
14
14
|
export declare function connectHub(profile: ProfileDirectory, theories: readonly ConfiguredTheory[], confirm: Confirm, createMission: Host["missions"]["create"], options?: HubOptions): Host["hub"];
|