wiki-graph-sdk 0.7.1 → 0.8.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 +1 -1
- package/dist/archives.cjs +406 -642
- package/dist/archives.cjs.map +1 -1
- package/dist/archives.d.ts +42 -80
- package/dist/archives.js +342 -571
- package/dist/archives.js.map +1 -1
- package/dist/conversions.cjs +160 -28
- package/dist/conversions.cjs.map +1 -1
- package/dist/conversions.d.ts +3 -1
- package/dist/conversions.js +165 -24
- package/dist/conversions.js.map +1 -1
- package/dist/default-worker.cjs +289 -52
- package/dist/default-worker.cjs.map +1 -1
- package/dist/default-worker.js +303 -50
- package/dist/default-worker.js.map +1 -1
- package/dist/index.cjs +967 -911
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +36 -19
- package/dist/index.js +836 -767
- package/dist/index.js.map +1 -1
- package/dist/{jobs-Dd5PMSId.d.ts → jobs-xIm_kshM.d.ts} +22 -14
- package/dist/maintenance.cjs +138 -29
- package/dist/maintenance.cjs.map +1 -1
- package/dist/maintenance.d.ts +2 -1
- package/dist/maintenance.js +143 -25
- package/dist/maintenance.js.map +1 -1
- package/dist/target-CZ7elwmj.d.ts +14 -0
- package/dist/wikispine.cjs +14 -10
- package/dist/wikispine.cjs.map +1 -1
- package/dist/wikispine.js +14 -10
- package/dist/wikispine.js.map +1 -1
- package/dist/worker.cjs +294 -25
- package/dist/worker.cjs.map +1 -1
- package/dist/worker.d.ts +28 -5
- package/dist/worker.js +312 -28
- package/dist/worker.js.map +1 -1
- package/package.json +2 -2
package/dist/archives.cjs
CHANGED
|
@@ -34,25 +34,25 @@ __export(archive_exports, {
|
|
|
34
34
|
WikiGraphArchiveExistsError: () => WikiGraphArchiveExistsError,
|
|
35
35
|
WikiGraphArchiveHandle: () => WikiGraphArchiveHandle,
|
|
36
36
|
WikiGraphArchiveManager: () => WikiGraphArchiveManager,
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
WikiGraphArchiveOwnershipError: () => WikiGraphArchiveOwnershipError,
|
|
38
|
+
inspectWikiGraphArchive: () => inspectWikiGraphArchive
|
|
39
39
|
});
|
|
40
40
|
module.exports = __toCommonJS(archive_exports);
|
|
41
41
|
|
|
42
42
|
// src/archive/archive.ts
|
|
43
43
|
var import_crypto2 = require("crypto");
|
|
44
|
-
var
|
|
44
|
+
var import_promises4 = require("fs/promises");
|
|
45
45
|
var import_os3 = require("os");
|
|
46
|
-
var
|
|
46
|
+
var import_path5 = require("path");
|
|
47
47
|
var import_stream = require("stream");
|
|
48
|
-
var
|
|
48
|
+
var import_wiki_graph_core7 = require("wiki-graph-core");
|
|
49
49
|
|
|
50
50
|
// src/conversions.ts
|
|
51
51
|
var import_crypto = require("crypto");
|
|
52
52
|
var import_fs = require("fs");
|
|
53
|
-
var
|
|
54
|
-
var
|
|
55
|
-
var
|
|
53
|
+
var import_promises3 = require("fs/promises");
|
|
54
|
+
var import_path4 = require("path");
|
|
55
|
+
var import_wiki_graph_core3 = require("wiki-graph-core");
|
|
56
56
|
|
|
57
57
|
// src/llm.ts
|
|
58
58
|
var import_anthropic = require("@ai-sdk/anthropic");
|
|
@@ -372,42 +372,42 @@ var NodeDatabaseConnection = class {
|
|
|
372
372
|
}
|
|
373
373
|
database;
|
|
374
374
|
async close() {
|
|
375
|
-
await new Promise((
|
|
375
|
+
await new Promise((resolve4, reject) => {
|
|
376
376
|
this.database.close((error) => {
|
|
377
377
|
if (error) reject(error);
|
|
378
|
-
else
|
|
378
|
+
else resolve4();
|
|
379
379
|
});
|
|
380
380
|
});
|
|
381
381
|
}
|
|
382
382
|
async execute(sql) {
|
|
383
|
-
await new Promise((
|
|
383
|
+
await new Promise((resolve4, reject) => {
|
|
384
384
|
this.database.exec(sql, (error) => {
|
|
385
385
|
if (error) reject(error);
|
|
386
|
-
else
|
|
386
|
+
else resolve4();
|
|
387
387
|
});
|
|
388
388
|
});
|
|
389
389
|
}
|
|
390
390
|
async queryAll(sql, params = []) {
|
|
391
|
-
return await new Promise((
|
|
391
|
+
return await new Promise((resolve4, reject) => {
|
|
392
392
|
this.database.all(sql, [...params], (error, rows) => {
|
|
393
393
|
if (error) reject(error);
|
|
394
|
-
else
|
|
394
|
+
else resolve4(rows);
|
|
395
395
|
});
|
|
396
396
|
});
|
|
397
397
|
}
|
|
398
398
|
async queryOne(sql, params = []) {
|
|
399
|
-
return await new Promise((
|
|
399
|
+
return await new Promise((resolve4, reject) => {
|
|
400
400
|
this.database.get(sql, [...params], (error, row) => {
|
|
401
401
|
if (error) reject(error);
|
|
402
|
-
else
|
|
402
|
+
else resolve4(row);
|
|
403
403
|
});
|
|
404
404
|
});
|
|
405
405
|
}
|
|
406
406
|
async run(sql, params = []) {
|
|
407
|
-
await new Promise((
|
|
407
|
+
await new Promise((resolve4, reject) => {
|
|
408
408
|
this.database.run(sql, [...params], (error) => {
|
|
409
409
|
if (error) reject(error);
|
|
410
|
-
else
|
|
410
|
+
else resolve4();
|
|
411
411
|
});
|
|
412
412
|
});
|
|
413
413
|
}
|
|
@@ -421,10 +421,10 @@ async function openNativeNodeDatabase(file, flags) {
|
|
|
421
421
|
if (path === void 0) {
|
|
422
422
|
throw new TypeError("The Node database adapter requires a NodeFile");
|
|
423
423
|
}
|
|
424
|
-
return await new Promise((
|
|
424
|
+
return await new Promise((resolve4, reject) => {
|
|
425
425
|
const database = new nodeSqlite3.Database(path, flags, (error) => {
|
|
426
426
|
if (error) reject(error);
|
|
427
|
-
else
|
|
427
|
+
else resolve4(database);
|
|
428
428
|
});
|
|
429
429
|
});
|
|
430
430
|
}
|
|
@@ -433,19 +433,19 @@ async function openNodeZip(file) {
|
|
|
433
433
|
if (path === void 0) {
|
|
434
434
|
throw new TypeError("The Node ZIP adapter requires a NodeFile");
|
|
435
435
|
}
|
|
436
|
-
const zipFile = await new Promise((
|
|
436
|
+
const zipFile = await new Promise((resolve4, reject) => {
|
|
437
437
|
yauzl.open(
|
|
438
438
|
path,
|
|
439
439
|
{ autoClose: false, lazyEntries: true },
|
|
440
440
|
(error, opened) => {
|
|
441
441
|
if (error || opened === void 0)
|
|
442
442
|
reject(error ?? new Error("Cannot open ZIP"));
|
|
443
|
-
else
|
|
443
|
+
else resolve4(opened);
|
|
444
444
|
}
|
|
445
445
|
);
|
|
446
446
|
});
|
|
447
447
|
const entries = await new Promise(
|
|
448
|
-
(
|
|
448
|
+
(resolve4, reject) => {
|
|
449
449
|
const discovered = /* @__PURE__ */ new Map();
|
|
450
450
|
const rejectAndClose = (error) => {
|
|
451
451
|
zipFile.close();
|
|
@@ -455,7 +455,7 @@ async function openNodeZip(file) {
|
|
|
455
455
|
};
|
|
456
456
|
const resolveEntries = () => {
|
|
457
457
|
zipFile.off("error", rejectAndClose);
|
|
458
|
-
|
|
458
|
+
resolve4(discovered);
|
|
459
459
|
};
|
|
460
460
|
zipFile.on("entry", (entry) => {
|
|
461
461
|
if (!entry.fileName.endsWith("/")) {
|
|
@@ -565,12 +565,12 @@ async function collectDecodedNodeStreamRange(input, offset, length) {
|
|
|
565
565
|
return Buffer.concat(chunks, collected);
|
|
566
566
|
}
|
|
567
567
|
async function openNodeZipEntryStream(zipFile, entry, options) {
|
|
568
|
-
return await new Promise((
|
|
568
|
+
return await new Promise((resolve4, reject) => {
|
|
569
569
|
const callback = (error, opened) => {
|
|
570
570
|
if (error || opened === void 0) {
|
|
571
571
|
reject(error ?? new Error(`Cannot read ZIP entry: ${entry.fileName}`));
|
|
572
572
|
} else {
|
|
573
|
-
|
|
573
|
+
resolve4(opened);
|
|
574
574
|
}
|
|
575
575
|
};
|
|
576
576
|
if (options === void 0) zipFile.openReadStream(entry, callback);
|
|
@@ -701,11 +701,11 @@ async function writeNodeStream(input, writer) {
|
|
|
701
701
|
);
|
|
702
702
|
}
|
|
703
703
|
async function collectNodeStream(input) {
|
|
704
|
-
return await new Promise((
|
|
704
|
+
return await new Promise((resolve4, reject) => {
|
|
705
705
|
const chunks = [];
|
|
706
706
|
input.on("data", (chunk) => chunks.push(chunk));
|
|
707
707
|
input.once("error", reject);
|
|
708
|
-
input.once("end", () =>
|
|
708
|
+
input.once("end", () => resolve4(Buffer.concat(chunks)));
|
|
709
709
|
});
|
|
710
710
|
}
|
|
711
711
|
var nodeWikiGraphPlatform = {
|
|
@@ -1258,6 +1258,164 @@ function resolveWikiGraphRuntimePath(path) {
|
|
|
1258
1258
|
return (0, import_path2.isAbsolute)(path) ? path : (0, import_path2.resolve)(context.cwd, path);
|
|
1259
1259
|
}
|
|
1260
1260
|
|
|
1261
|
+
// src/archive/target.ts
|
|
1262
|
+
var import_promises2 = require("fs/promises");
|
|
1263
|
+
var import_path3 = require("path");
|
|
1264
|
+
var import_wiki_graph_core2 = require("wiki-graph-core");
|
|
1265
|
+
var WikiGraphArchiveOwnershipError = class extends Error {
|
|
1266
|
+
code = "WIKI_GRAPH_ARCHIVE_OWNERSHIP_MISMATCH";
|
|
1267
|
+
constructor(message) {
|
|
1268
|
+
super(message);
|
|
1269
|
+
this.name = "WikiGraphArchiveOwnershipError";
|
|
1270
|
+
}
|
|
1271
|
+
};
|
|
1272
|
+
async function resolveWikiGraphArchiveLocation(target) {
|
|
1273
|
+
if (target.kind === "standalone") {
|
|
1274
|
+
return await resolveStandaloneLocation(target);
|
|
1275
|
+
}
|
|
1276
|
+
return await resolveLibraryLocation(target);
|
|
1277
|
+
}
|
|
1278
|
+
async function assertStandaloneWikiGraphArchivePath(inputPath) {
|
|
1279
|
+
const path = resolveWikiGraphRuntimePath(inputPath);
|
|
1280
|
+
const candidate = await canonicalPath(path);
|
|
1281
|
+
const candidateIdentity = await readFileIdentity(path);
|
|
1282
|
+
const libraries = await (0, import_wiki_graph_core2.listWikiGraphLibraries)();
|
|
1283
|
+
const matches = await findMatchingMembers(
|
|
1284
|
+
libraries,
|
|
1285
|
+
candidate,
|
|
1286
|
+
candidateIdentity
|
|
1287
|
+
);
|
|
1288
|
+
if (matches.length > 0) {
|
|
1289
|
+
const match = requireUnambiguousManagedMatch(path, matches);
|
|
1290
|
+
throw new WikiGraphArchiveOwnershipError(
|
|
1291
|
+
`Standalone archive path belongs to registered library ${(0, import_wiki_graph_core2.formatWikiGraphLibraryUri)(
|
|
1292
|
+
match.library.isDefault ? void 0 : match.library.publicId
|
|
1293
|
+
)}: ${path}. Use the library UUID URI ${match.archive.uri} instead.`
|
|
1294
|
+
);
|
|
1295
|
+
}
|
|
1296
|
+
for (const library of libraries) {
|
|
1297
|
+
const rootPath = getNodeResourcePath(library.folder);
|
|
1298
|
+
const root = await canonicalPath(rootPath);
|
|
1299
|
+
if (!isWithin(root, candidate)) continue;
|
|
1300
|
+
throw new WikiGraphArchiveOwnershipError(
|
|
1301
|
+
`Standalone archive path belongs to registered library ${(0, import_wiki_graph_core2.formatWikiGraphLibraryUri)(
|
|
1302
|
+
library.isDefault ? void 0 : library.publicId
|
|
1303
|
+
)}: ${path}. Scan the library, then address the archive by its library UUID URI.`
|
|
1304
|
+
);
|
|
1305
|
+
}
|
|
1306
|
+
return path;
|
|
1307
|
+
}
|
|
1308
|
+
async function resolveStandaloneLocation(target) {
|
|
1309
|
+
if (target.path.startsWith("wikg://lib/")) {
|
|
1310
|
+
throw new WikiGraphArchiveOwnershipError(
|
|
1311
|
+
`A library archive URI cannot be used as a standalone path: ${target.path}`
|
|
1312
|
+
);
|
|
1313
|
+
}
|
|
1314
|
+
const path = await assertStandaloneWikiGraphArchivePath(target.path);
|
|
1315
|
+
const normalized = {
|
|
1316
|
+
kind: "standalone",
|
|
1317
|
+
path,
|
|
1318
|
+
...target.objectUri === void 0 ? {} : { objectUri: target.objectUri }
|
|
1319
|
+
};
|
|
1320
|
+
return {
|
|
1321
|
+
archiveFile: new NodeFile(path),
|
|
1322
|
+
archiveKey: path,
|
|
1323
|
+
archivePath: path,
|
|
1324
|
+
indexScope: { archiveKey: path, archivePath: path, kind: "archive-index" },
|
|
1325
|
+
locatedUri: (0, import_wiki_graph_core2.formatLocatedWikiGraphUri)(path, target.objectUri),
|
|
1326
|
+
target: normalized
|
|
1327
|
+
};
|
|
1328
|
+
}
|
|
1329
|
+
async function resolveLibraryLocation(target) {
|
|
1330
|
+
const parsedLocated = (0, import_wiki_graph_core2.parseLocatedWikiGraphUri)(target.uri);
|
|
1331
|
+
const archiveUri = parsedLocated.archivePath ?? target.uri;
|
|
1332
|
+
const parsed = (0, import_wiki_graph_core2.parseWikiGraphLibraryUri)(archiveUri);
|
|
1333
|
+
if (parsed?.kind !== "archive") {
|
|
1334
|
+
throw new WikiGraphArchiveOwnershipError(
|
|
1335
|
+
`Library archive target must be a UUID archive URI: ${target.uri}`
|
|
1336
|
+
);
|
|
1337
|
+
}
|
|
1338
|
+
await (0, import_wiki_graph_core2.resolveWikiGraphLibrary)(parsed);
|
|
1339
|
+
const archiveFile = await (0, import_wiki_graph_core2.resolveWikiGraphLibraryArchiveFile)(archiveUri);
|
|
1340
|
+
const normalized = {
|
|
1341
|
+
kind: "library",
|
|
1342
|
+
uri: target.uri
|
|
1343
|
+
};
|
|
1344
|
+
return {
|
|
1345
|
+
archiveFile,
|
|
1346
|
+
archiveKey: archiveUri,
|
|
1347
|
+
archivePath: archiveUri,
|
|
1348
|
+
indexScope: {
|
|
1349
|
+
archiveKey: archiveUri,
|
|
1350
|
+
archivePath: archiveUri,
|
|
1351
|
+
kind: "archive-index"
|
|
1352
|
+
},
|
|
1353
|
+
libraryArchiveTarget: parsed,
|
|
1354
|
+
locatedUri: target.uri,
|
|
1355
|
+
publicArchiveUri: archiveUri,
|
|
1356
|
+
target: normalized
|
|
1357
|
+
};
|
|
1358
|
+
}
|
|
1359
|
+
async function canonicalPath(path) {
|
|
1360
|
+
try {
|
|
1361
|
+
return await (0, import_promises2.realpath)(path);
|
|
1362
|
+
} catch {
|
|
1363
|
+
const absolute = (0, import_path3.resolve)(path);
|
|
1364
|
+
const parent = (0, import_path3.dirname)(absolute);
|
|
1365
|
+
return parent === absolute ? absolute : (0, import_path3.join)(await canonicalPath(parent), (0, import_path3.basename)(absolute));
|
|
1366
|
+
}
|
|
1367
|
+
}
|
|
1368
|
+
function isWithin(root, candidate) {
|
|
1369
|
+
const child = (0, import_path3.relative)(root, candidate);
|
|
1370
|
+
return child === "" || !child.startsWith("..") && !(0, import_path3.isAbsolute)(child);
|
|
1371
|
+
}
|
|
1372
|
+
async function findMatchingMembers(libraries, candidate, candidateIdentity) {
|
|
1373
|
+
const members = [];
|
|
1374
|
+
for (const library of libraries) {
|
|
1375
|
+
const archives = await (0, import_wiki_graph_core2.listWikiGraphLibraryArchives)({
|
|
1376
|
+
isDefault: library.isDefault,
|
|
1377
|
+
kind: "scope",
|
|
1378
|
+
...library.isDefault ? {} : { publicId: library.publicId }
|
|
1379
|
+
});
|
|
1380
|
+
for (const archive of archives) {
|
|
1381
|
+
if (archive.file === void 0) continue;
|
|
1382
|
+
members.push({
|
|
1383
|
+
archive,
|
|
1384
|
+
library,
|
|
1385
|
+
memberPath: getNodeResourcePath(archive.file)
|
|
1386
|
+
});
|
|
1387
|
+
}
|
|
1388
|
+
}
|
|
1389
|
+
const exact = [];
|
|
1390
|
+
for (const member of members) {
|
|
1391
|
+
if (await canonicalPath(member.memberPath) === candidate) {
|
|
1392
|
+
exact.push(member);
|
|
1393
|
+
}
|
|
1394
|
+
}
|
|
1395
|
+
if (exact.length > 0 || candidateIdentity === void 0) return exact;
|
|
1396
|
+
const identityMatches = [];
|
|
1397
|
+
for (const member of members) {
|
|
1398
|
+
if (await readFileIdentity(member.memberPath) === candidateIdentity) {
|
|
1399
|
+
identityMatches.push(member);
|
|
1400
|
+
}
|
|
1401
|
+
}
|
|
1402
|
+
return identityMatches;
|
|
1403
|
+
}
|
|
1404
|
+
function requireUnambiguousManagedMatch(path, matches) {
|
|
1405
|
+
if (matches.length === 1) return matches[0];
|
|
1406
|
+
throw new WikiGraphArchiveOwnershipError(
|
|
1407
|
+
`Archive file identity is ambiguous across managed archives: ${path}. Use an explicit library UUID URI (${matches.map((match) => match.archive.uri).join(", ")}).`
|
|
1408
|
+
);
|
|
1409
|
+
}
|
|
1410
|
+
async function readFileIdentity(path) {
|
|
1411
|
+
try {
|
|
1412
|
+
const value = await (0, import_promises2.stat)(path);
|
|
1413
|
+
return `${value.dev}:${value.ino}`;
|
|
1414
|
+
} catch {
|
|
1415
|
+
return void 0;
|
|
1416
|
+
}
|
|
1417
|
+
}
|
|
1418
|
+
|
|
1261
1419
|
// src/conversions.ts
|
|
1262
1420
|
var WikiGraphConversionManager = class {
|
|
1263
1421
|
#runtime;
|
|
@@ -1285,7 +1443,7 @@ var WikiGraphConversionManager = class {
|
|
|
1285
1443
|
const config = await loadWikiGraphRuntimeConfig({
|
|
1286
1444
|
...options.llmJSON === void 0 ? {} : { llmJSON: options.llmJSON }
|
|
1287
1445
|
});
|
|
1288
|
-
const app = new
|
|
1446
|
+
const app = new import_wiki_graph_core3.WikiGraph({
|
|
1289
1447
|
...options.verbose === true ? { verbose: true } : {},
|
|
1290
1448
|
...requiresLLM ? { llm: buildWikiGraphLLMOptions(config) } : {}
|
|
1291
1449
|
});
|
|
@@ -1294,11 +1452,15 @@ var WikiGraphConversionManager = class {
|
|
|
1294
1452
|
requiresDigest
|
|
1295
1453
|
);
|
|
1296
1454
|
let chapterCount;
|
|
1455
|
+
let chapterPaths;
|
|
1297
1456
|
const write = async (archive) => {
|
|
1298
1457
|
if (requiresDigest) await options.onSourceImported?.();
|
|
1299
1458
|
if (typeof archive.readToc === "function") {
|
|
1300
1459
|
const toc = await archive.readToc();
|
|
1301
1460
|
chapterCount = toc === void 0 ? void 0 : countTocChapters(toc.items);
|
|
1461
|
+
if (options.output.format === "wikg") {
|
|
1462
|
+
chapterPaths = toc === void 0 ? [] : collectTocChapterPaths(toc.items);
|
|
1463
|
+
}
|
|
1302
1464
|
}
|
|
1303
1465
|
await writeArchive(archive, options.output.path, options.output.format);
|
|
1304
1466
|
};
|
|
@@ -1307,7 +1469,9 @@ var WikiGraphConversionManager = class {
|
|
|
1307
1469
|
throw new Error("wikg input requires a file path.");
|
|
1308
1470
|
}
|
|
1309
1471
|
await app.openSession(
|
|
1310
|
-
new NodeFile(
|
|
1472
|
+
new NodeFile(
|
|
1473
|
+
await assertStandaloneWikiGraphArchivePath(options.input.path)
|
|
1474
|
+
),
|
|
1311
1475
|
write
|
|
1312
1476
|
);
|
|
1313
1477
|
} else if ("stream" in options.input) {
|
|
@@ -1350,6 +1514,7 @@ var WikiGraphConversionManager = class {
|
|
|
1350
1514
|
const sourceArtifact = await resolveSourceArtifact(options.input);
|
|
1351
1515
|
return {
|
|
1352
1516
|
...chapterCount === void 0 ? {} : { chapterCount },
|
|
1517
|
+
...chapterPaths === void 0 ? {} : { chapterPaths },
|
|
1353
1518
|
inputFormat: options.input.format,
|
|
1354
1519
|
outputFormat: options.output.format,
|
|
1355
1520
|
outputPath: options.output.path,
|
|
@@ -1362,11 +1527,12 @@ async function prepareDigestDirectory(path, required) {
|
|
|
1362
1527
|
if (!required || normalized === void 0 || normalized === "")
|
|
1363
1528
|
return void 0;
|
|
1364
1529
|
const resolved = resolveWikiGraphRuntimePath(normalized);
|
|
1365
|
-
await (0,
|
|
1530
|
+
await (0, import_promises3.rm)(resolved, { force: true, recursive: true });
|
|
1366
1531
|
return new NodeDirectory(resolved);
|
|
1367
1532
|
}
|
|
1368
1533
|
async function writeArchive(archive, path, format) {
|
|
1369
|
-
const
|
|
1534
|
+
const outputPath = format === "wikg" ? await assertStandaloneWikiGraphArchivePath(path) : resolveWikiGraphRuntimePath(path);
|
|
1535
|
+
const file = new NodeFile(outputPath);
|
|
1370
1536
|
if (format === "epub") await archive.exportEpub(file);
|
|
1371
1537
|
else if (format === "wikg") await archive.saveAs(file);
|
|
1372
1538
|
else if (format === "pcex") throw new Error("pcex output is not supported.");
|
|
@@ -1395,7 +1561,7 @@ async function resolveSourceArtifact(input) {
|
|
|
1395
1561
|
return {
|
|
1396
1562
|
digest: hash.digest("hex"),
|
|
1397
1563
|
mediaType: "application/epub+zip",
|
|
1398
|
-
name: (0,
|
|
1564
|
+
name: (0, import_path4.basename)(path)
|
|
1399
1565
|
};
|
|
1400
1566
|
}
|
|
1401
1567
|
function isNodeErrorCode(error, code) {
|
|
@@ -1411,9 +1577,24 @@ function countTocChapters(items) {
|
|
|
1411
1577
|
}
|
|
1412
1578
|
return count;
|
|
1413
1579
|
}
|
|
1580
|
+
function collectTocChapterPaths(items, ancestorKeys = []) {
|
|
1581
|
+
const paths = [];
|
|
1582
|
+
for (const item of items) {
|
|
1583
|
+
const key = item.key ?? `chapter-${item.serialId ?? "group"}`;
|
|
1584
|
+
const chapterPath = [...ancestorKeys, key];
|
|
1585
|
+
if (item.serialId !== void 0) paths.push(chapterPath.join("/"));
|
|
1586
|
+
paths.push(
|
|
1587
|
+
...collectTocChapterPaths(
|
|
1588
|
+
item.children,
|
|
1589
|
+
chapterPath
|
|
1590
|
+
)
|
|
1591
|
+
);
|
|
1592
|
+
}
|
|
1593
|
+
return paths;
|
|
1594
|
+
}
|
|
1414
1595
|
|
|
1415
1596
|
// src/query-runtime.ts
|
|
1416
|
-
var
|
|
1597
|
+
var import_wiki_graph_core4 = require("wiki-graph-core");
|
|
1417
1598
|
|
|
1418
1599
|
// src/embedding.ts
|
|
1419
1600
|
var import_ai = require("ai");
|
|
@@ -1561,7 +1742,7 @@ async function createConfiguredEmbeddingProvider() {
|
|
|
1561
1742
|
async function withConfiguredWikimediaResolver(objectUri, operation) {
|
|
1562
1743
|
if (!objectUri.endsWith("/wikipage")) return await operation({});
|
|
1563
1744
|
const config = await loadWikiGraphRuntimeConfig();
|
|
1564
|
-
const resolver = await (0,
|
|
1745
|
+
const resolver = await (0, import_wiki_graph_core4.openWikimediaResolver)(
|
|
1565
1746
|
config.wikimedia === void 0 ? { kind: "local" } : {
|
|
1566
1747
|
endpoint: config.wikimedia.endpoint,
|
|
1567
1748
|
kind: "remote",
|
|
@@ -1576,490 +1757,128 @@ async function withConfiguredWikimediaResolver(objectUri, operation) {
|
|
|
1576
1757
|
}
|
|
1577
1758
|
|
|
1578
1759
|
// src/archive/inspect.ts
|
|
1579
|
-
var
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
model,
|
|
1595
|
-
timeSeconds: {
|
|
1596
|
-
max: Math.ceil(callBatches * profile.maxSecondsPerCall + wordSeconds),
|
|
1597
|
-
min: Math.ceil(callBatches * profile.minSecondsPerCall + wordSeconds)
|
|
1598
|
-
},
|
|
1599
|
-
tokens: {
|
|
1600
|
-
cacheableInput: Math.ceil(words * profile.cacheableInputTokenPerWord),
|
|
1601
|
-
input: Math.ceil(words * profile.inputTokenPerWord),
|
|
1602
|
-
output: Math.ceil(words * profile.outputTokenPerWord)
|
|
1603
|
-
}
|
|
1760
|
+
var import_wiki_graph_core5 = require("wiki-graph-core");
|
|
1761
|
+
async function inspectWikiGraphArchive(document, options) {
|
|
1762
|
+
const [allChapters, indexCacheCurrent, summaryWords, ...coverage] = await Promise.all([
|
|
1763
|
+
(0, import_wiki_graph_core5.listChapters)(document),
|
|
1764
|
+
(0, import_wiki_graph_core5.isArchiveSearchIndexCurrent)(document),
|
|
1765
|
+
readSummaryWords(document),
|
|
1766
|
+
document.indexArtifacts.listCoverage("fts"),
|
|
1767
|
+
document.indexArtifacts.listCoverage("embedding-source"),
|
|
1768
|
+
document.indexArtifacts.listCoverage("embedding-summary")
|
|
1769
|
+
]);
|
|
1770
|
+
const chapters = selectChapters(allChapters, options.chapterId);
|
|
1771
|
+
const coverageByKind = {
|
|
1772
|
+
fts: byChapterId(coverage[0]),
|
|
1773
|
+
sourceEmbedding: byChapterId(coverage[1]),
|
|
1774
|
+
summaryEmbedding: byChapterId(coverage[2])
|
|
1604
1775
|
};
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
return [];
|
|
1609
|
-
}
|
|
1610
|
-
const hints = [];
|
|
1611
|
-
const recommendedRequest = input.concurrent.request < 4 ? DEFAULT_GENERATION_REQUEST_CONCURRENCY : input.concurrent.request < 8 ? 8 : void 0;
|
|
1612
|
-
if (input.hasRequestWork && recommendedRequest !== void 0) {
|
|
1613
|
-
hints.push({
|
|
1614
|
-
configKey: "request",
|
|
1615
|
-
configValue: recommendedRequest,
|
|
1616
|
-
current: input.concurrent.request,
|
|
1617
|
-
kind: "request",
|
|
1618
|
-
message: "LLM request concurrency can often be higher. Use at least 4; 6-8 is usually faster when the provider allows it.",
|
|
1619
|
-
recommended: recommendedRequest
|
|
1620
|
-
});
|
|
1621
|
-
}
|
|
1622
|
-
if (input.concurrent.job < 4 && input.chapters > 1) {
|
|
1623
|
-
hints.push({
|
|
1624
|
-
configKey: "job",
|
|
1625
|
-
configValue: 4,
|
|
1626
|
-
current: input.concurrent.job,
|
|
1627
|
-
kind: "job",
|
|
1628
|
-
message: "Multiple chapters need work and job concurrency is below 4. Raising it lets chapter jobs run in parallel.",
|
|
1629
|
-
recommended: 4
|
|
1630
|
-
});
|
|
1631
|
-
}
|
|
1632
|
-
return hints;
|
|
1633
|
-
}
|
|
1634
|
-
function formatGenerationPlanningModel(llm) {
|
|
1635
|
-
if (llm?.model === void 0) {
|
|
1636
|
-
return "not configured";
|
|
1637
|
-
}
|
|
1638
|
-
return llm.provider === void 0 ? llm.model : `${llm.provider}/${llm.model}`;
|
|
1639
|
-
}
|
|
1640
|
-
function getGenerationPlanningProfile(task) {
|
|
1641
|
-
switch (task) {
|
|
1642
|
-
case "index-fts":
|
|
1643
|
-
return {
|
|
1644
|
-
cacheableInputTokenPerWord: 0,
|
|
1645
|
-
inputTokenPerWord: 0,
|
|
1646
|
-
maxSecondsPerCall: 1,
|
|
1647
|
-
minSecondsPerCall: 0,
|
|
1648
|
-
outputTokenPerWord: 0,
|
|
1649
|
-
secondsPerWord: 5e-4,
|
|
1650
|
-
wordsPerCall: 1e5
|
|
1651
|
-
};
|
|
1652
|
-
case "index-embedding-source":
|
|
1653
|
-
case "index-embedding-summary":
|
|
1654
|
-
return {
|
|
1655
|
-
cacheableInputTokenPerWord: 0,
|
|
1656
|
-
inputTokenPerWord: 0,
|
|
1657
|
-
maxSecondsPerCall: 10,
|
|
1658
|
-
minSecondsPerCall: 1,
|
|
1659
|
-
outputTokenPerWord: 0,
|
|
1660
|
-
secondsPerWord: 2e-3,
|
|
1661
|
-
wordsPerCall: 1e4
|
|
1662
|
-
};
|
|
1663
|
-
case "knowledge-graph":
|
|
1664
|
-
return {
|
|
1665
|
-
cacheableInputTokenPerWord: 60,
|
|
1666
|
-
inputTokenPerWord: 80,
|
|
1667
|
-
maxSecondsPerCall: 35,
|
|
1668
|
-
minSecondsPerCall: 15,
|
|
1669
|
-
outputTokenPerWord: 25,
|
|
1670
|
-
secondsPerWord: 0.02,
|
|
1671
|
-
wordsPerCall: 35
|
|
1672
|
-
};
|
|
1673
|
-
case "reading-graph":
|
|
1674
|
-
return {
|
|
1675
|
-
cacheableInputTokenPerWord: 20,
|
|
1676
|
-
inputTokenPerWord: 25,
|
|
1677
|
-
maxSecondsPerCall: 45,
|
|
1678
|
-
minSecondsPerCall: 15,
|
|
1679
|
-
outputTokenPerWord: 4,
|
|
1680
|
-
secondsPerWord: 0.01,
|
|
1681
|
-
wordsPerCall: 160
|
|
1682
|
-
};
|
|
1683
|
-
case "reading-summary":
|
|
1776
|
+
const inspections = await Promise.all(
|
|
1777
|
+
chapters.map(async (chapter) => {
|
|
1778
|
+
const serial = await document.serials.getById(chapter.chapterId);
|
|
1684
1779
|
return {
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1780
|
+
capabilities: {
|
|
1781
|
+
knowledgeGraph: {
|
|
1782
|
+
completed: serial?.knowledgeGraphReady === true
|
|
1783
|
+
},
|
|
1784
|
+
readingGraph: { completed: serial?.topologyReady === true },
|
|
1785
|
+
readingSummary: { completed: chapter.stage === "summarized" }
|
|
1786
|
+
},
|
|
1787
|
+
chapter,
|
|
1788
|
+
indexes: {
|
|
1789
|
+
fts: inspectArtifact(
|
|
1790
|
+
"fts",
|
|
1791
|
+
coverageByKind.fts.get(chapter.chapterId)
|
|
1792
|
+
),
|
|
1793
|
+
sourceEmbedding: inspectArtifact(
|
|
1794
|
+
"embedding-source",
|
|
1795
|
+
coverageByKind.sourceEmbedding.get(chapter.chapterId)
|
|
1796
|
+
),
|
|
1797
|
+
summaryEmbedding: inspectArtifact(
|
|
1798
|
+
"embedding-summary",
|
|
1799
|
+
coverageByKind.summaryEmbedding.get(chapter.chapterId)
|
|
1800
|
+
)
|
|
1801
|
+
},
|
|
1802
|
+
revision: serial?.revision ?? 0,
|
|
1803
|
+
summaryWords: summaryWords.get(chapter.chapterId) ?? 0
|
|
1692
1804
|
};
|
|
1693
|
-
|
|
1694
|
-
}
|
|
1695
|
-
|
|
1696
|
-
// src/archive/inspect.ts
|
|
1697
|
-
async function createWikiGraphArchiveInspectReport(document, options) {
|
|
1698
|
-
const { archiveUri } = options;
|
|
1699
|
-
const [
|
|
1700
|
-
chapters,
|
|
1701
|
-
summaryWords,
|
|
1702
|
-
indexCacheCurrent,
|
|
1703
|
-
config,
|
|
1704
|
-
ftsArtifactCoverage,
|
|
1705
|
-
sourceEmbeddingArtifactCoverage,
|
|
1706
|
-
summaryEmbeddingArtifactCoverage
|
|
1707
|
-
] = await Promise.all([
|
|
1708
|
-
readInspectChapters(document, options.chapterId),
|
|
1709
|
-
readSummaryWords(document, options.chapterId),
|
|
1710
|
-
(0, import_wiki_graph_core4.isArchiveSearchIndexCurrent)(document),
|
|
1711
|
-
loadWikiGraphRuntimeConfig(),
|
|
1712
|
-
readIndexArtifactCoverage(document, "fts", options.chapterId),
|
|
1713
|
-
readIndexArtifactCoverage(document, "embedding-source", options.chapterId),
|
|
1714
|
-
readIndexArtifactCoverage(document, "embedding-summary", options.chapterId)
|
|
1715
|
-
]);
|
|
1716
|
-
const selectedChapter = options.chapterId === void 0 ? void 0 : chapters[0];
|
|
1717
|
-
const scopeUri = selectedChapter === void 0 ? archiveUri : formatInspectLocatedChapterUri(archiveUri, selectedChapter);
|
|
1718
|
-
const concurrent = {
|
|
1719
|
-
job: config.concurrent?.job ?? DEFAULT_GENERATION_JOB_CONCURRENCY,
|
|
1720
|
-
request: config.concurrent?.request ?? DEFAULT_GENERATION_REQUEST_CONCURRENCY
|
|
1721
|
-
};
|
|
1722
|
-
const planningModel = formatGenerationPlanningModel(config.llm);
|
|
1723
|
-
const contentChapters = chapters.filter(
|
|
1724
|
-
(chapter) => chapter.stage !== "planned"
|
|
1725
|
-
);
|
|
1726
|
-
const sourceWords = sumWords(contentChapters);
|
|
1727
|
-
const readingGraphCovered = contentChapters.filter(
|
|
1728
|
-
(chapter) => chapter.readingGraphReady
|
|
1729
|
-
);
|
|
1730
|
-
const knowledgeGraphCovered = contentChapters.filter(
|
|
1731
|
-
(chapter) => chapter.knowledgeGraphReady
|
|
1732
|
-
);
|
|
1733
|
-
const summaryCovered = contentChapters.filter(
|
|
1734
|
-
(chapter) => chapter.summaryReady
|
|
1735
|
-
);
|
|
1736
|
-
const ftsArtifactCovered = filterChaptersByCurrentIndexArtifact(
|
|
1737
|
-
contentChapters,
|
|
1738
|
-
ftsArtifactCoverage
|
|
1739
|
-
);
|
|
1740
|
-
const sourceEmbeddingArtifactCovered = filterChaptersByCurrentIndexArtifact(
|
|
1741
|
-
contentChapters,
|
|
1742
|
-
sourceEmbeddingArtifactCoverage
|
|
1743
|
-
);
|
|
1744
|
-
const summaryEmbeddingArtifactCovered = filterChaptersByCurrentIndexArtifact(
|
|
1745
|
-
contentChapters,
|
|
1746
|
-
summaryEmbeddingArtifactCoverage
|
|
1747
|
-
);
|
|
1748
|
-
const queryBlockedContentChapters = contentChapters.filter(
|
|
1749
|
-
(chapter) => !ftsArtifactCovered.includes(chapter) && !sourceEmbeddingArtifactCovered.includes(chapter)
|
|
1750
|
-
);
|
|
1751
|
-
const queryBlockedChapters = queryBlockedContentChapters.map(
|
|
1752
|
-
(chapter) => createInspectChapterReference(archiveUri, chapter)
|
|
1805
|
+
})
|
|
1753
1806
|
);
|
|
1754
|
-
const
|
|
1755
|
-
const improvements = createInspectImprovements({
|
|
1756
|
-
concurrent,
|
|
1757
|
-
contentChapters,
|
|
1758
|
-
indexCacheCurrent,
|
|
1759
|
-
planningModel,
|
|
1760
|
-
queryBlockedChapters: queryBlockedContentChapters,
|
|
1761
|
-
summaryCovered,
|
|
1762
|
-
knowledgeGraphCovered,
|
|
1763
|
-
readingGraphCovered
|
|
1764
|
-
});
|
|
1765
|
-
const performanceHints = createGenerationPerformanceHints({
|
|
1766
|
-
chapters: Math.max(
|
|
1767
|
-
0,
|
|
1768
|
-
...improvements.map((improvement) => improvement.missingChapters ?? 0)
|
|
1769
|
-
),
|
|
1770
|
-
concurrent,
|
|
1771
|
-
hasJobWork: improvements.some(
|
|
1772
|
-
(improvement) => improvement.planning !== void 0
|
|
1773
|
-
),
|
|
1774
|
-
hasRequestWork: improvements.some(
|
|
1775
|
-
(improvement) => improvement.planning !== void 0
|
|
1776
|
-
)
|
|
1777
|
-
});
|
|
1807
|
+
const selected = inspections[0];
|
|
1778
1808
|
return {
|
|
1779
|
-
archiveUri,
|
|
1780
|
-
|
|
1809
|
+
archiveUri: options.archiveUri,
|
|
1810
|
+
chapters: inspections,
|
|
1811
|
+
localIndexCache: { current: indexCacheCurrent },
|
|
1781
1812
|
scope: options.chapterId === void 0 ? { type: "archive" } : { chapterId: options.chapterId, type: "chapter" },
|
|
1782
|
-
|
|
1783
|
-
chapters: {
|
|
1784
|
-
content: contentChapters.length,
|
|
1785
|
-
planned: chapters.length - contentChapters.length,
|
|
1786
|
-
total: chapters.length
|
|
1787
|
-
},
|
|
1788
|
-
sourceWords,
|
|
1789
|
-
summaryWords
|
|
1790
|
-
},
|
|
1791
|
-
localIndexCache: {
|
|
1792
|
-
current: indexCacheCurrent,
|
|
1793
|
-
...!queryReady ? {
|
|
1794
|
-
blockedBy: "missing-search-artifacts",
|
|
1795
|
-
impact: "The cache cannot be built until every content chapter has a current FTS or source embedding artifact."
|
|
1796
|
-
} : indexCacheCurrent ? {} : {
|
|
1797
|
-
impact: "The next archive query may need to sync index cache first.",
|
|
1798
|
-
resource: "local CPU/disk time only; no provider calls."
|
|
1799
|
-
},
|
|
1800
|
-
status: !queryReady ? "blocked" : indexCacheCurrent ? "current" : "missing-or-outdated",
|
|
1801
|
-
syncAvailable: queryReady && !indexCacheCurrent
|
|
1802
|
-
},
|
|
1803
|
-
coverage: {
|
|
1804
|
-
ftsIndexArtifact: createInspectCoverage(
|
|
1805
|
-
ftsArtifactCovered,
|
|
1806
|
-
contentChapters
|
|
1807
|
-
),
|
|
1808
|
-
knowledgeGraph: createInspectCoverage(
|
|
1809
|
-
knowledgeGraphCovered,
|
|
1810
|
-
contentChapters
|
|
1811
|
-
),
|
|
1812
|
-
readingGraph: createInspectCoverage(readingGraphCovered, contentChapters),
|
|
1813
|
-
summary: createInspectCoverage(summaryCovered, contentChapters),
|
|
1814
|
-
sourceEmbeddingIndexArtifact: createInspectCoverage(
|
|
1815
|
-
sourceEmbeddingArtifactCovered,
|
|
1816
|
-
contentChapters
|
|
1817
|
-
),
|
|
1818
|
-
summaryEmbeddingIndexArtifact: createInspectCoverage(
|
|
1819
|
-
summaryEmbeddingArtifactCovered,
|
|
1820
|
-
contentChapters
|
|
1821
|
-
)
|
|
1822
|
-
},
|
|
1823
|
-
query: {
|
|
1824
|
-
ready: queryReady
|
|
1825
|
-
},
|
|
1826
|
-
searchArtifacts: {
|
|
1827
|
-
blockedChapters: queryBlockedChapters,
|
|
1828
|
-
...!queryReady ? {
|
|
1829
|
-
resource: "local CPU/disk time only; no provider calls."
|
|
1830
|
-
} : {},
|
|
1831
|
-
ready: queryReady,
|
|
1832
|
-
status: queryReady ? "ready" : "incomplete"
|
|
1833
|
-
},
|
|
1834
|
-
retrievalGuidance: formatRetrievalGuidance({
|
|
1835
|
-
indexCacheCurrent,
|
|
1836
|
-
knowledgeGraphCovered,
|
|
1837
|
-
readingGraphCovered,
|
|
1838
|
-
contentChapters,
|
|
1839
|
-
queryReady,
|
|
1840
|
-
sourceWords
|
|
1841
|
-
}),
|
|
1842
|
-
improvements,
|
|
1843
|
-
performanceHints,
|
|
1844
|
-
summaryCoverageNote: "Summary coverage means a current summary artifact exists for the chapter; it does not guarantee that every source topic is represented in the summary text."
|
|
1845
|
-
};
|
|
1846
|
-
}
|
|
1847
|
-
function createInspectChapterReference(archiveUri, chapter) {
|
|
1848
|
-
return {
|
|
1849
|
-
chapterId: chapter.chapterId,
|
|
1850
|
-
locatedUri: formatInspectLocatedChapterUri(archiveUri, chapter),
|
|
1851
|
-
title: chapter.title,
|
|
1852
|
-
uri: chapter.uri
|
|
1813
|
+
uri: selected === void 0 || options.chapterId === void 0 ? options.archiveUri : formatLocatedChapterUri(options.archiveUri, selected.chapter)
|
|
1853
1814
|
};
|
|
1854
1815
|
}
|
|
1855
|
-
function
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
async function readInspectChapters(document, chapterId) {
|
|
1859
|
-
const chapters = chapterId === void 0 ? await (0, import_wiki_graph_core4.listChapters)(document) : (await (0, import_wiki_graph_core4.listChapters)(document)).filter(
|
|
1816
|
+
function selectChapters(chapters, chapterId) {
|
|
1817
|
+
if (chapterId === void 0) return chapters;
|
|
1818
|
+
const selected = chapters.filter(
|
|
1860
1819
|
(chapter) => chapter.chapterId === chapterId
|
|
1861
1820
|
);
|
|
1862
|
-
if (
|
|
1821
|
+
if (selected.length === 0) {
|
|
1863
1822
|
throw new Error(`Chapter ${chapterId} does not exist.`);
|
|
1864
1823
|
}
|
|
1865
|
-
return
|
|
1866
|
-
chapters.map(async (chapter) => {
|
|
1867
|
-
const serial = await document.serials.getById(chapter.chapterId);
|
|
1868
|
-
return {
|
|
1869
|
-
...chapter,
|
|
1870
|
-
knowledgeGraphReady: serial?.knowledgeGraphReady === true,
|
|
1871
|
-
readingGraphReady: serial?.topologyReady === true,
|
|
1872
|
-
summaryReady: chapter.stage === "summarized"
|
|
1873
|
-
};
|
|
1874
|
-
})
|
|
1875
|
-
);
|
|
1824
|
+
return selected;
|
|
1876
1825
|
}
|
|
1877
|
-
|
|
1878
|
-
return
|
|
1879
|
-
async (database) => await database.queryOne(
|
|
1880
|
-
`
|
|
1881
|
-
SELECT COALESCE(SUM(words_count), 0) AS words
|
|
1882
|
-
FROM text_sentence_records
|
|
1883
|
-
WHERE kind = 2
|
|
1884
|
-
${chapterId === void 0 ? "" : "AND chapter_id = ?"}
|
|
1885
|
-
`,
|
|
1886
|
-
chapterId === void 0 ? void 0 : [chapterId],
|
|
1887
|
-
(row) => Number(row.words)
|
|
1888
|
-
) ?? 0
|
|
1889
|
-
);
|
|
1890
|
-
}
|
|
1891
|
-
async function readIndexArtifactCoverage(document, kind, chapterId) {
|
|
1892
|
-
const coverage = await document.indexArtifacts.listCoverage(kind);
|
|
1893
|
-
return chapterId === void 0 ? coverage : coverage.filter((item) => item.serialId === chapterId);
|
|
1826
|
+
function byChapterId(coverage) {
|
|
1827
|
+
return new Map(coverage.map((item) => [item.serialId, item]));
|
|
1894
1828
|
}
|
|
1895
|
-
function
|
|
1896
|
-
const currentChapterIds = new Set(
|
|
1897
|
-
coverage.filter((item) => item.current).map((item) => item.serialId)
|
|
1898
|
-
);
|
|
1899
|
-
return chapters.filter((chapter) => currentChapterIds.has(chapter.chapterId));
|
|
1900
|
-
}
|
|
1901
|
-
function createInspectCoverage(covered, total) {
|
|
1902
|
-
const coveredWords = sumWords(covered);
|
|
1903
|
-
const totalWords = sumWords(total);
|
|
1829
|
+
function inspectArtifact(kind, coverage) {
|
|
1904
1830
|
return {
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
totalWords
|
|
1831
|
+
current: coverage?.current === true,
|
|
1832
|
+
exists: coverage?.sourceRevision !== void 0,
|
|
1833
|
+
kind,
|
|
1834
|
+
...coverage?.sourceRevision === void 0 ? {} : { sourceRevision: coverage.sourceRevision }
|
|
1910
1835
|
};
|
|
1911
1836
|
}
|
|
1912
|
-
function
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
input.contentChapters
|
|
1927
|
-
)
|
|
1928
|
-
);
|
|
1929
|
-
lines.push(
|
|
1930
|
-
formatObjectSearchGuidance(
|
|
1931
|
-
"Entity/triple retrieval",
|
|
1932
|
-
input.knowledgeGraphCovered,
|
|
1933
|
-
input.contentChapters
|
|
1837
|
+
async function readSummaryWords(document) {
|
|
1838
|
+
const rows = await document.readDatabase(
|
|
1839
|
+
async (database) => await database.queryAll(
|
|
1840
|
+
`
|
|
1841
|
+
SELECT chapter_id, COALESCE(SUM(words_count), 0) AS words
|
|
1842
|
+
FROM text_sentence_records
|
|
1843
|
+
WHERE kind = 2
|
|
1844
|
+
GROUP BY chapter_id
|
|
1845
|
+
`,
|
|
1846
|
+
void 0,
|
|
1847
|
+
(row) => ({
|
|
1848
|
+
chapterId: Number(row.chapter_id),
|
|
1849
|
+
words: Number(row.words)
|
|
1850
|
+
})
|
|
1934
1851
|
)
|
|
1935
1852
|
);
|
|
1936
|
-
return
|
|
1937
|
-
}
|
|
1938
|
-
function formatObjectSearchGuidance(label, covered, total) {
|
|
1939
|
-
const coveredWords = sumWords(covered);
|
|
1940
|
-
const totalWords = sumWords(total);
|
|
1941
|
-
const ratio = totalWords === 0 ? 0 : coveredWords / totalWords;
|
|
1942
|
-
const coverage = formatPercent(coveredWords, totalWords);
|
|
1943
|
-
if (ratio >= 1) {
|
|
1944
|
-
return `${label}: covers all source content; it can represent the full scope for object retrieval.`;
|
|
1945
|
-
}
|
|
1946
|
-
if (ratio >= 0.9) {
|
|
1947
|
-
return `${label}: covers ${coverage}; use it as the main path, but source --query is needed for uncovered content.`;
|
|
1948
|
-
}
|
|
1949
|
-
if (ratio >= 0.5) {
|
|
1950
|
-
return `${label}: covers ${coverage}; use it as leads, not as a full-scope substitute for source --query.`;
|
|
1951
|
-
}
|
|
1952
|
-
return `${label}: covers ${coverage}; build missing graph coverage before relying on object retrieval.`;
|
|
1953
|
-
}
|
|
1954
|
-
function createInspectImprovements(input) {
|
|
1955
|
-
const improvements = [];
|
|
1956
|
-
if (input.contentChapters.length === 0) {
|
|
1957
|
-
improvements.push({
|
|
1958
|
-
kind: "add-source",
|
|
1959
|
-
recommendation: "No source content is available yet; add or import source text before graph or summary generation.",
|
|
1960
|
-
title: "Add source content"
|
|
1961
|
-
});
|
|
1962
|
-
return improvements;
|
|
1963
|
-
}
|
|
1964
|
-
if (input.queryBlockedChapters.length > 0) {
|
|
1965
|
-
improvements.push({
|
|
1966
|
-
kind: "build",
|
|
1967
|
-
missingChapters: input.queryBlockedChapters.length,
|
|
1968
|
-
missingWords: sumWords(input.queryBlockedChapters),
|
|
1969
|
-
recommendation: "Build local FTS artifacts to make this scope queryable. This does not call a provider.",
|
|
1970
|
-
task: "index-fts",
|
|
1971
|
-
title: "Enable query with local FTS"
|
|
1972
|
-
});
|
|
1973
|
-
} else if (!input.indexCacheCurrent) {
|
|
1974
|
-
improvements.push({
|
|
1975
|
-
kind: "sync-index",
|
|
1976
|
-
recommendation: "Sync the index cache from chapter index artifacts so query starts without a lazy cache rebuild.",
|
|
1977
|
-
title: "Sync index cache"
|
|
1978
|
-
});
|
|
1979
|
-
}
|
|
1980
|
-
improvements.push(
|
|
1981
|
-
...createGraphImprovement({
|
|
1982
|
-
concurrent: input.concurrent,
|
|
1983
|
-
covered: input.readingGraphCovered,
|
|
1984
|
-
planningModel: input.planningModel,
|
|
1985
|
-
task: "reading-graph",
|
|
1986
|
-
title: "Complete Reading Graph coverage",
|
|
1987
|
-
total: input.contentChapters
|
|
1988
|
-
})
|
|
1989
|
-
);
|
|
1990
|
-
improvements.push(
|
|
1991
|
-
...createGraphImprovement({
|
|
1992
|
-
concurrent: input.concurrent,
|
|
1993
|
-
covered: input.knowledgeGraphCovered,
|
|
1994
|
-
planningModel: input.planningModel,
|
|
1995
|
-
task: "knowledge-graph",
|
|
1996
|
-
title: "Complete Knowledge Graph coverage",
|
|
1997
|
-
total: input.contentChapters
|
|
1998
|
-
})
|
|
1999
|
-
);
|
|
2000
|
-
improvements.push(
|
|
2001
|
-
...createGraphImprovement({
|
|
2002
|
-
concurrent: input.concurrent,
|
|
2003
|
-
covered: input.summaryCovered,
|
|
2004
|
-
planningModel: input.planningModel,
|
|
2005
|
-
task: "reading-summary",
|
|
2006
|
-
title: "Complete Summary coverage",
|
|
2007
|
-
total: input.contentChapters
|
|
2008
|
-
})
|
|
2009
|
-
);
|
|
2010
|
-
return improvements;
|
|
1853
|
+
return new Map(rows.map((row) => [row.chapterId, row.words]));
|
|
2011
1854
|
}
|
|
2012
|
-
function
|
|
2013
|
-
|
|
2014
|
-
const missing = input.total.filter(
|
|
2015
|
-
(chapter) => !coveredIds.has(chapter.chapterId)
|
|
2016
|
-
);
|
|
2017
|
-
if (missing.length === 0) {
|
|
2018
|
-
return [];
|
|
2019
|
-
}
|
|
2020
|
-
const missingWords = sumWords(missing);
|
|
2021
|
-
return [
|
|
2022
|
-
{
|
|
2023
|
-
kind: "build",
|
|
2024
|
-
missingChapters: missing.length,
|
|
2025
|
-
missingWords,
|
|
2026
|
-
planning: planGenerationTask(
|
|
2027
|
-
input.task,
|
|
2028
|
-
missingWords,
|
|
2029
|
-
missing.length,
|
|
2030
|
-
input.concurrent,
|
|
2031
|
-
input.planningModel
|
|
2032
|
-
),
|
|
2033
|
-
recommendation: formatImprovementRecommendation(
|
|
2034
|
-
input.covered,
|
|
2035
|
-
input.total,
|
|
2036
|
-
missingWords
|
|
2037
|
-
),
|
|
2038
|
-
task: input.task,
|
|
2039
|
-
title: input.title
|
|
2040
|
-
}
|
|
2041
|
-
];
|
|
2042
|
-
}
|
|
2043
|
-
function formatImprovementRecommendation(covered, total, missingWords) {
|
|
2044
|
-
const totalWords = sumWords(total);
|
|
2045
|
-
const coveredWords = sumWords(covered);
|
|
2046
|
-
if (totalWords === 0) {
|
|
2047
|
-
return "No source content is available.";
|
|
2048
|
-
}
|
|
2049
|
-
if (total.length === 1 || coveredWords / totalWords >= 0.9 || missingWords <= 1e3) {
|
|
2050
|
-
return "Queue the full scope to finish the remaining gap.";
|
|
2051
|
-
}
|
|
2052
|
-
return "Queue selected chapters first if only part of the scope matters.";
|
|
2053
|
-
}
|
|
2054
|
-
function sumWords(chapters) {
|
|
2055
|
-
return chapters.reduce((total, chapter) => total + chapter.words, 0);
|
|
1855
|
+
function formatLocatedChapterUri(archiveUri, chapter) {
|
|
1856
|
+
return `${archiveUri.replace(/\/+$/u, "")}/${chapter.uri.replace(/^wikg:\/\//u, "")}`;
|
|
2056
1857
|
}
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
1858
|
+
|
|
1859
|
+
// src/archive/write.ts
|
|
1860
|
+
var import_wiki_graph_core6 = require("wiki-graph-core");
|
|
1861
|
+
async function writeWikiGraphArchiveLocation(location, operation, options = {}) {
|
|
1862
|
+
const cacheOnly = options.searchIndexWritebackPolicy === "cache";
|
|
1863
|
+
const write = async (archiveFile = location.archiveFile) => await new import_wiki_graph_core6.WikiGraphArchiveFile(archiveFile).write(operation, {
|
|
1864
|
+
...cacheOnly ? {} : { derivedStateKeys: [location.archiveKey, location.archivePath] },
|
|
1865
|
+
...options.invalidateContinuationCursors === void 0 ? {} : {
|
|
1866
|
+
invalidateContinuationCursors: options.invalidateContinuationCursors
|
|
1867
|
+
},
|
|
1868
|
+
...options.searchIndexWritebackPolicy === void 0 ? {} : { searchIndexWritebackPolicy: options.searchIndexWritebackPolicy }
|
|
1869
|
+
});
|
|
1870
|
+
if (location.libraryArchiveTarget === void 0 || cacheOnly || options.refreshLibraryIndex === false) {
|
|
1871
|
+
return await write();
|
|
2060
1872
|
}
|
|
2061
|
-
|
|
2062
|
-
|
|
1873
|
+
return await (0, import_wiki_graph_core6.writeWikiGraphLibraryArchive)({
|
|
1874
|
+
additionalDerivedStateKeys: [location.archiveKey, location.archivePath],
|
|
1875
|
+
...options.invalidateContinuationCursors === void 0 ? {} : {
|
|
1876
|
+
invalidateContinuationCursors: options.invalidateContinuationCursors
|
|
1877
|
+
},
|
|
1878
|
+
...options.onIndexSyncError === void 0 ? {} : { onIndexSyncError: options.onIndexSyncError },
|
|
1879
|
+
operation: async (archiveFile) => await write(archiveFile),
|
|
1880
|
+
target: location.libraryArchiveTarget
|
|
1881
|
+
});
|
|
2063
1882
|
}
|
|
2064
1883
|
|
|
2065
1884
|
// src/archive/archive.ts
|
|
@@ -2079,13 +1898,13 @@ var WikiGraphArchiveManager = class {
|
|
|
2079
1898
|
}
|
|
2080
1899
|
async create(options) {
|
|
2081
1900
|
return await this.#runtime.run(async () => {
|
|
2082
|
-
const path =
|
|
1901
|
+
const path = await assertStandaloneWikiGraphArchivePath(options.path);
|
|
2083
1902
|
if (options.replace !== true && await nodePathExists(path)) {
|
|
2084
1903
|
throw new WikiGraphArchiveExistsError(path);
|
|
2085
1904
|
}
|
|
2086
|
-
const outputPath = (0,
|
|
2087
|
-
(0,
|
|
2088
|
-
`.${(0,
|
|
1905
|
+
const outputPath = (0, import_path5.join)(
|
|
1906
|
+
(0, import_path5.dirname)(path),
|
|
1907
|
+
`.${(0, import_path5.basename)(path)}.${(0, import_crypto2.randomUUID)()}.tmp.wikg`
|
|
2089
1908
|
);
|
|
2090
1909
|
try {
|
|
2091
1910
|
if (options.importPath === void 0) {
|
|
@@ -2099,10 +1918,10 @@ var WikiGraphArchiveManager = class {
|
|
|
2099
1918
|
});
|
|
2100
1919
|
}
|
|
2101
1920
|
if (options.replace === true) {
|
|
2102
|
-
await (0,
|
|
1921
|
+
await (0, import_promises4.rename)(outputPath, path);
|
|
2103
1922
|
} else {
|
|
2104
1923
|
try {
|
|
2105
|
-
await (0,
|
|
1924
|
+
await (0, import_promises4.link)(outputPath, path);
|
|
2106
1925
|
} catch (error) {
|
|
2107
1926
|
if (isNodeEEXISTError(error)) {
|
|
2108
1927
|
throw new WikiGraphArchiveExistsError(path);
|
|
@@ -2110,15 +1929,15 @@ var WikiGraphArchiveManager = class {
|
|
|
2110
1929
|
throw error;
|
|
2111
1930
|
}
|
|
2112
1931
|
}
|
|
2113
|
-
return { locatedUri: (0,
|
|
1932
|
+
return { locatedUri: (0, import_wiki_graph_core7.formatLocatedWikiGraphUri)(path), path };
|
|
2114
1933
|
} finally {
|
|
2115
|
-
await (0,
|
|
1934
|
+
await (0, import_promises4.rm)(outputPath, { force: true, recursive: true });
|
|
2116
1935
|
}
|
|
2117
1936
|
}, options.signal);
|
|
2118
1937
|
}
|
|
2119
|
-
async open(
|
|
1938
|
+
async open(target, options = {}) {
|
|
2120
1939
|
const location = await this.#runtime.run(
|
|
2121
|
-
async () => await resolveWikiGraphArchiveLocation(
|
|
1940
|
+
async () => await resolveWikiGraphArchiveLocation(target),
|
|
2122
1941
|
options.signal
|
|
2123
1942
|
);
|
|
2124
1943
|
return new WikiGraphArchiveHandle(this.#runtime, location);
|
|
@@ -2141,14 +1960,17 @@ var WikiGraphArchiveHandle = class {
|
|
|
2141
1960
|
return this.#location.locatedUri;
|
|
2142
1961
|
}
|
|
2143
1962
|
get objectUri() {
|
|
2144
|
-
return (0,
|
|
1963
|
+
return (0, import_wiki_graph_core7.parseLocatedWikiGraphUri)(this.#location.locatedUri).objectUri ?? "wikg://";
|
|
2145
1964
|
}
|
|
2146
1965
|
get path() {
|
|
2147
1966
|
return this.#location.archivePath;
|
|
2148
1967
|
}
|
|
1968
|
+
get target() {
|
|
1969
|
+
return this.#location.target;
|
|
1970
|
+
}
|
|
2149
1971
|
async inspect(options = {}) {
|
|
2150
1972
|
return await this.#readDocument(
|
|
2151
|
-
async (document) => await
|
|
1973
|
+
async (document) => await inspectWikiGraphArchive(document, {
|
|
2152
1974
|
archiveUri: this.#location.publicArchiveUri ?? this.locatedUri,
|
|
2153
1975
|
...options.chapterId === void 0 ? {} : { chapterId: options.chapterId }
|
|
2154
1976
|
}),
|
|
@@ -2167,7 +1989,7 @@ var WikiGraphArchiveHandle = class {
|
|
|
2167
1989
|
...chapters === void 0 ? {} : { chapters },
|
|
2168
1990
|
...embeddingProvider === void 0 ? {} : { embeddingProvider }
|
|
2169
1991
|
});
|
|
2170
|
-
return await (0,
|
|
1992
|
+
return await (0, import_wiki_graph_core7.findArchiveObjects)(document, query, {
|
|
2171
1993
|
...withoutOperationAndScope(options),
|
|
2172
1994
|
archiveKey: this.archiveKey,
|
|
2173
1995
|
...chapters === void 0 ? {} : { chapters },
|
|
@@ -2182,14 +2004,14 @@ var WikiGraphArchiveHandle = class {
|
|
|
2182
2004
|
}
|
|
2183
2005
|
async list(options = {}) {
|
|
2184
2006
|
return await this.#readDocument(async (document) => {
|
|
2185
|
-
if ((0,
|
|
2186
|
-
return await (0,
|
|
2007
|
+
if ((0, import_wiki_graph_core7.isSourceLocatorScopeUri)(this.objectUri)) {
|
|
2008
|
+
return await (0, import_wiki_graph_core7.listArchiveSourceLocators)(document, this.objectUri, {
|
|
2187
2009
|
...options.cursor === void 0 ? {} : { cursor: options.cursor },
|
|
2188
2010
|
...options.limit === void 0 ? {} : { limit: options.limit }
|
|
2189
2011
|
});
|
|
2190
2012
|
}
|
|
2191
2013
|
const chapters = await this.#resolveScope(document, options);
|
|
2192
|
-
return await (0,
|
|
2014
|
+
return await (0, import_wiki_graph_core7.listArchiveCollection)(document, {
|
|
2193
2015
|
...withoutOperationAndScope(options),
|
|
2194
2016
|
...chapters === void 0 ? {} : { chapters }
|
|
2195
2017
|
});
|
|
@@ -2217,8 +2039,8 @@ var WikiGraphArchiveHandle = class {
|
|
|
2217
2039
|
async getSearchIndexStatus(options = {}) {
|
|
2218
2040
|
return await this.#readDocument(
|
|
2219
2041
|
async (document) => ({
|
|
2220
|
-
capabilities: await (0,
|
|
2221
|
-
current: await (0,
|
|
2042
|
+
capabilities: await (0, import_wiki_graph_core7.readSearchIndexCapabilityStatus)(document),
|
|
2043
|
+
current: await (0, import_wiki_graph_core7.isArchiveSearchIndexCurrent)(document)
|
|
2222
2044
|
}),
|
|
2223
2045
|
options
|
|
2224
2046
|
);
|
|
@@ -2226,14 +2048,14 @@ var WikiGraphArchiveHandle = class {
|
|
|
2226
2048
|
async syncSearchIndex(options = {}) {
|
|
2227
2049
|
const rebuilt = await this.#writeDocument(
|
|
2228
2050
|
async (document) => {
|
|
2229
|
-
const scope = options.skipUnindexed === true ? { chapters: await (0,
|
|
2051
|
+
const scope = options.skipUnindexed === true ? { chapters: await (0, import_wiki_graph_core7.listArchiveQueryableChapterIds)(document) } : {};
|
|
2230
2052
|
if (scope.chapters?.length === 0) {
|
|
2231
2053
|
throw new Error(
|
|
2232
2054
|
"Wiki Graph index cache is not ready. No chapters have a current FTS artifact or source embedding artifact."
|
|
2233
2055
|
);
|
|
2234
2056
|
}
|
|
2235
|
-
if (await (0,
|
|
2236
|
-
await (0,
|
|
2057
|
+
if (await (0, import_wiki_graph_core7.isArchiveSearchIndexCurrent)(document, scope)) return false;
|
|
2058
|
+
await (0, import_wiki_graph_core7.rebuildArchiveSearchIndex)(document, options.onProgress, scope);
|
|
2237
2059
|
return true;
|
|
2238
2060
|
},
|
|
2239
2061
|
{
|
|
@@ -2242,7 +2064,7 @@ var WikiGraphArchiveHandle = class {
|
|
|
2242
2064
|
}
|
|
2243
2065
|
);
|
|
2244
2066
|
await this.#runtime.run(
|
|
2245
|
-
async () => await (0,
|
|
2067
|
+
async () => await (0, import_wiki_graph_core7.deleteArchiveSearchSessions)(this.path),
|
|
2246
2068
|
options.signal
|
|
2247
2069
|
);
|
|
2248
2070
|
return { rebuilt };
|
|
@@ -2265,21 +2087,21 @@ var WikiGraphArchiveHandle = class {
|
|
|
2265
2087
|
}
|
|
2266
2088
|
);
|
|
2267
2089
|
await this.#runtime.run(
|
|
2268
|
-
async () => await (0,
|
|
2090
|
+
async () => await (0, import_wiki_graph_core7.deleteArchiveSearchSessions)(this.path),
|
|
2269
2091
|
options.signal
|
|
2270
2092
|
);
|
|
2271
2093
|
return status;
|
|
2272
2094
|
}
|
|
2273
2095
|
async listChapters(options = {}) {
|
|
2274
2096
|
return await this.#readDocument(
|
|
2275
|
-
async (document) => await (0,
|
|
2097
|
+
async (document) => await (0, import_wiki_graph_core7.listChapters)(document),
|
|
2276
2098
|
options
|
|
2277
2099
|
);
|
|
2278
2100
|
}
|
|
2279
2101
|
async getChapter(path, options = {}) {
|
|
2280
2102
|
return await this.#readDocument(async (document) => {
|
|
2281
|
-
const chapterId = await (0,
|
|
2282
|
-
return requireChapter(await (0,
|
|
2103
|
+
const chapterId = await (0, import_wiki_graph_core7.resolveChapterPathReadonly)(document, path);
|
|
2104
|
+
return requireChapter(await (0, import_wiki_graph_core7.listChapters)(document), chapterId);
|
|
2283
2105
|
}, options);
|
|
2284
2106
|
}
|
|
2285
2107
|
async addChapter(options) {
|
|
@@ -2288,17 +2110,17 @@ var WikiGraphArchiveHandle = class {
|
|
|
2288
2110
|
document,
|
|
2289
2111
|
options.parentPath
|
|
2290
2112
|
);
|
|
2291
|
-
await (0,
|
|
2113
|
+
await (0, import_wiki_graph_core7.assertNoActiveBuildJobConflicts)({
|
|
2292
2114
|
archive: this.#location.archiveFile,
|
|
2293
2115
|
operation: "Adding chapter",
|
|
2294
2116
|
scope: { kind: "archive" }
|
|
2295
2117
|
});
|
|
2296
|
-
let details = await (0,
|
|
2118
|
+
let details = await (0, import_wiki_graph_core7.addChapter)(document, {
|
|
2297
2119
|
...parentChapterId === void 0 ? {} : { parentChapterId },
|
|
2298
2120
|
...options.title === void 0 ? {} : { title: options.title }
|
|
2299
2121
|
});
|
|
2300
2122
|
if (options.source !== void 0) {
|
|
2301
|
-
details = await (0,
|
|
2123
|
+
details = await (0, import_wiki_graph_core7.setChapterSource)(
|
|
2302
2124
|
document,
|
|
2303
2125
|
details.chapterId,
|
|
2304
2126
|
asTextStream(options.source)
|
|
@@ -2309,7 +2131,7 @@ var WikiGraphArchiveHandle = class {
|
|
|
2309
2131
|
}
|
|
2310
2132
|
async getChapterArtifact(path, kind) {
|
|
2311
2133
|
return await this.#readDocument(async (document) => {
|
|
2312
|
-
const chapterId = await (0,
|
|
2134
|
+
const chapterId = await (0, import_wiki_graph_core7.resolveChapterPathReadonly)(document, path);
|
|
2313
2135
|
const [artifact, revision] = await Promise.all([
|
|
2314
2136
|
document.indexArtifacts.get(chapterId, kind),
|
|
2315
2137
|
document.serials.getRevision(chapterId)
|
|
@@ -2332,25 +2154,25 @@ var WikiGraphArchiveHandle = class {
|
|
|
2332
2154
|
}
|
|
2333
2155
|
async deleteChapterArtifact(path, kind) {
|
|
2334
2156
|
return await this.#writeDocument(async (document) => {
|
|
2335
|
-
const chapterId = await (0,
|
|
2157
|
+
const chapterId = await (0, import_wiki_graph_core7.resolveChapterPathReadonly)(document, path);
|
|
2336
2158
|
await document.indexArtifacts.delete(chapterId, kind);
|
|
2337
2159
|
return { chapterId, deleted: true, kind };
|
|
2338
2160
|
});
|
|
2339
2161
|
}
|
|
2340
2162
|
async moveChapter(path, options) {
|
|
2341
2163
|
return await this.#writeDocument(async (document) => {
|
|
2342
|
-
const chapterId = await (0,
|
|
2164
|
+
const chapterId = await (0, import_wiki_graph_core7.resolveChapterPathReadonly)(document, path);
|
|
2343
2165
|
const [afterChapterId, beforeChapterId, parentChapterId] = await Promise.all([
|
|
2344
2166
|
resolveOptionalChapterPath(document, options.afterPath),
|
|
2345
2167
|
resolveOptionalChapterPath(document, options.beforePath),
|
|
2346
2168
|
resolveOptionalChapterPath(document, options.parentPath)
|
|
2347
2169
|
]);
|
|
2348
|
-
await (0,
|
|
2170
|
+
await (0, import_wiki_graph_core7.assertNoActiveBuildJobConflicts)({
|
|
2349
2171
|
archive: this.#location.archiveFile,
|
|
2350
2172
|
operation: "Moving chapter",
|
|
2351
2173
|
scope: { kind: "archive" }
|
|
2352
2174
|
});
|
|
2353
|
-
return await (0,
|
|
2175
|
+
return await (0, import_wiki_graph_core7.moveChapter)(document, chapterId, {
|
|
2354
2176
|
...afterChapterId === void 0 ? {} : { afterChapterId },
|
|
2355
2177
|
...beforeChapterId === void 0 ? {} : { beforeChapterId },
|
|
2356
2178
|
...parentChapterId === void 0 ? {} : { parentChapterId },
|
|
@@ -2362,35 +2184,35 @@ var WikiGraphArchiveHandle = class {
|
|
|
2362
2184
|
}
|
|
2363
2185
|
async removeChapter(path, recursive = false) {
|
|
2364
2186
|
await this.#writeDocument(async (document) => {
|
|
2365
|
-
const chapterId = await (0,
|
|
2366
|
-
await (0,
|
|
2187
|
+
const chapterId = await (0, import_wiki_graph_core7.resolveChapterPathReadonly)(document, path);
|
|
2188
|
+
await (0, import_wiki_graph_core7.assertNoActiveBuildJobConflicts)({
|
|
2367
2189
|
archive: this.#location.archiveFile,
|
|
2368
2190
|
operation: "Removing chapter",
|
|
2369
2191
|
scope: { kind: "archive" }
|
|
2370
2192
|
});
|
|
2371
|
-
await (0,
|
|
2193
|
+
await (0, import_wiki_graph_core7.removeChapter)(document, chapterId, { recursive });
|
|
2372
2194
|
});
|
|
2373
2195
|
}
|
|
2374
2196
|
async resetChapter(path, stage) {
|
|
2375
2197
|
return await this.#writeDocument(async (document) => {
|
|
2376
|
-
const chapterId = await (0,
|
|
2198
|
+
const chapterId = await (0, import_wiki_graph_core7.resolveChapterPathReadonly)(document, path);
|
|
2377
2199
|
await assertChapterResetAllowed(
|
|
2378
2200
|
this.#location.archiveFile,
|
|
2379
2201
|
chapterId,
|
|
2380
2202
|
stage
|
|
2381
2203
|
);
|
|
2382
|
-
return await (0,
|
|
2204
|
+
return await (0, import_wiki_graph_core7.resetChapter)(document, chapterId, stage);
|
|
2383
2205
|
});
|
|
2384
2206
|
}
|
|
2385
2207
|
async setChapterSource(path, source, options = {}) {
|
|
2386
2208
|
return await this.#writeDocument(async (document) => {
|
|
2387
|
-
const chapterId = await (0,
|
|
2388
|
-
await (0,
|
|
2209
|
+
const chapterId = await (0, import_wiki_graph_core7.resolveChapterPathReadonly)(document, path);
|
|
2210
|
+
await (0, import_wiki_graph_core7.assertNoActiveBuildJobs)({
|
|
2389
2211
|
archive: this.#location.archiveFile,
|
|
2390
2212
|
chapterIds: [chapterId],
|
|
2391
2213
|
operation: "Setting chapter source"
|
|
2392
2214
|
});
|
|
2393
|
-
return await (0,
|
|
2215
|
+
return await (0, import_wiki_graph_core7.setChapterSource)(
|
|
2394
2216
|
document,
|
|
2395
2217
|
chapterId,
|
|
2396
2218
|
asTextStream(source),
|
|
@@ -2400,43 +2222,43 @@ var WikiGraphArchiveHandle = class {
|
|
|
2400
2222
|
}
|
|
2401
2223
|
async setChapterSummary(path, summary) {
|
|
2402
2224
|
return await this.#writeDocument(async (document) => {
|
|
2403
|
-
const chapterId = await (0,
|
|
2404
|
-
await (0,
|
|
2225
|
+
const chapterId = await (0, import_wiki_graph_core7.resolveChapterPathReadonly)(document, path);
|
|
2226
|
+
await (0, import_wiki_graph_core7.assertNoActiveBuildJobs)({
|
|
2405
2227
|
archive: this.#location.archiveFile,
|
|
2406
2228
|
chapterIds: [chapterId],
|
|
2407
2229
|
operation: "Setting chapter summary",
|
|
2408
2230
|
requiresTarget: "reading-summary"
|
|
2409
2231
|
});
|
|
2410
|
-
return await (0,
|
|
2232
|
+
return await (0, import_wiki_graph_core7.setChapterSummary)(document, chapterId, summary);
|
|
2411
2233
|
});
|
|
2412
2234
|
}
|
|
2413
2235
|
async setChapterTitle(path, title) {
|
|
2414
2236
|
return await this.#writeDocument(async (document) => {
|
|
2415
|
-
const chapterId = await (0,
|
|
2416
|
-
await (0,
|
|
2237
|
+
const chapterId = await (0, import_wiki_graph_core7.resolveChapterPathReadonly)(document, path);
|
|
2238
|
+
await (0, import_wiki_graph_core7.assertNoActiveBuildJobs)({
|
|
2417
2239
|
archive: this.#location.archiveFile,
|
|
2418
2240
|
chapterIds: [chapterId],
|
|
2419
2241
|
operation: "Setting chapter title"
|
|
2420
2242
|
});
|
|
2421
|
-
return await (0,
|
|
2243
|
+
return await (0, import_wiki_graph_core7.setChapterTitle)(document, chapterId, title);
|
|
2422
2244
|
});
|
|
2423
2245
|
}
|
|
2424
2246
|
async getChapterTree() {
|
|
2425
2247
|
return await this.#readDocument(
|
|
2426
|
-
async (document) => await (0,
|
|
2248
|
+
async (document) => await (0, import_wiki_graph_core7.getChapterTree)(document)
|
|
2427
2249
|
);
|
|
2428
2250
|
}
|
|
2429
2251
|
async applyChapterTree(tree, options = {}) {
|
|
2430
2252
|
return await this.#writeDocument(
|
|
2431
2253
|
async (document) => {
|
|
2432
2254
|
if (options.dryRun !== true) {
|
|
2433
|
-
await (0,
|
|
2255
|
+
await (0, import_wiki_graph_core7.assertNoActiveBuildJobConflicts)({
|
|
2434
2256
|
archive: this.#location.archiveFile,
|
|
2435
2257
|
operation: "Changing chapter tree",
|
|
2436
2258
|
scope: { kind: "archive" }
|
|
2437
2259
|
});
|
|
2438
2260
|
}
|
|
2439
|
-
return await (0,
|
|
2261
|
+
return await (0, import_wiki_graph_core7.applyChapterTree)(document, tree, {
|
|
2440
2262
|
dryRun: options.dryRun ?? false
|
|
2441
2263
|
});
|
|
2442
2264
|
},
|
|
@@ -2448,8 +2270,8 @@ var WikiGraphArchiveHandle = class {
|
|
|
2448
2270
|
async () => await withConfiguredWikimediaResolver(
|
|
2449
2271
|
objectUri,
|
|
2450
2272
|
async (wikimediaOptions) => await this.#readDocument(
|
|
2451
|
-
async (document) => await (0,
|
|
2452
|
-
...
|
|
2273
|
+
async (document) => await (0, import_wiki_graph_core7.readArchivePage)(document, objectUri, {
|
|
2274
|
+
...options,
|
|
2453
2275
|
...wikimediaOptions
|
|
2454
2276
|
}),
|
|
2455
2277
|
options
|
|
@@ -2462,7 +2284,7 @@ var WikiGraphArchiveHandle = class {
|
|
|
2462
2284
|
if (options.query === void 0) {
|
|
2463
2285
|
return await this.#readDocument(async (document) => {
|
|
2464
2286
|
const chapters = await this.#resolveScope(document, {});
|
|
2465
|
-
return await (0,
|
|
2287
|
+
return await (0, import_wiki_graph_core7.listRelatedArchiveObjects)(document, objectUri, {
|
|
2466
2288
|
...withoutOperation(options),
|
|
2467
2289
|
...chapters === void 0 ? {} : { chapters }
|
|
2468
2290
|
});
|
|
@@ -2479,7 +2301,7 @@ var WikiGraphArchiveHandle = class {
|
|
|
2479
2301
|
...chapters === void 0 ? {} : { chapters },
|
|
2480
2302
|
...embeddingProvider === void 0 ? {} : { embeddingProvider }
|
|
2481
2303
|
});
|
|
2482
|
-
return await (0,
|
|
2304
|
+
return await (0, import_wiki_graph_core7.listRelatedArchiveObjects)(document, objectUri, {
|
|
2483
2305
|
...withoutOperation(options),
|
|
2484
2306
|
...chapters === void 0 ? {} : { chapters }
|
|
2485
2307
|
});
|
|
@@ -2494,7 +2316,7 @@ var WikiGraphArchiveHandle = class {
|
|
|
2494
2316
|
if (options.query === void 0) {
|
|
2495
2317
|
return await this.#readDocument(async (document) => {
|
|
2496
2318
|
const chapters = await this.#resolveScope(document, {});
|
|
2497
|
-
return await (0,
|
|
2319
|
+
return await (0, import_wiki_graph_core7.listArchiveEvidence)(document, objectUri, {
|
|
2498
2320
|
...withoutOperation(options),
|
|
2499
2321
|
...chapters === void 0 ? {} : { chapters }
|
|
2500
2322
|
});
|
|
@@ -2511,7 +2333,7 @@ var WikiGraphArchiveHandle = class {
|
|
|
2511
2333
|
...chapters === void 0 ? {} : { chapters },
|
|
2512
2334
|
...embeddingProvider === void 0 ? {} : { embeddingProvider }
|
|
2513
2335
|
});
|
|
2514
|
-
return await (0,
|
|
2336
|
+
return await (0, import_wiki_graph_core7.listArchiveEvidence)(document, objectUri, {
|
|
2515
2337
|
...withoutOperation(options),
|
|
2516
2338
|
...chapters === void 0 ? {} : { chapters }
|
|
2517
2339
|
});
|
|
@@ -2524,7 +2346,7 @@ var WikiGraphArchiveHandle = class {
|
|
|
2524
2346
|
}
|
|
2525
2347
|
async pack(objectUri = this.objectUri, budget = 5e3, options = {}) {
|
|
2526
2348
|
return await this.#readDocument(
|
|
2527
|
-
async (document) => await (0,
|
|
2349
|
+
async (document) => await (0, import_wiki_graph_core7.packArchiveContext)(document, objectUri, budget),
|
|
2528
2350
|
options
|
|
2529
2351
|
);
|
|
2530
2352
|
}
|
|
@@ -2547,7 +2369,7 @@ var WikiGraphArchiveHandle = class {
|
|
|
2547
2369
|
}, options);
|
|
2548
2370
|
}
|
|
2549
2371
|
async readCover(options = {}) {
|
|
2550
|
-
const app = new
|
|
2372
|
+
const app = new import_wiki_graph_core7.WikiGraph({});
|
|
2551
2373
|
return await this.#runtime.run(
|
|
2552
2374
|
async () => await app.openSession(
|
|
2553
2375
|
this.#location.archiveFile,
|
|
@@ -2595,7 +2417,7 @@ var WikiGraphArchiveHandle = class {
|
|
|
2595
2417
|
}
|
|
2596
2418
|
async #readDocument(operation, options = {}) {
|
|
2597
2419
|
return await this.#runtime.run(
|
|
2598
|
-
async () => await new
|
|
2420
|
+
async () => await new import_wiki_graph_core7.WikiGraphArchiveFile(this.#location.archiveFile).readDocument(
|
|
2599
2421
|
operation
|
|
2600
2422
|
),
|
|
2601
2423
|
options.signal
|
|
@@ -2603,17 +2425,13 @@ var WikiGraphArchiveHandle = class {
|
|
|
2603
2425
|
}
|
|
2604
2426
|
async #writeDocument(operation, options = {}) {
|
|
2605
2427
|
return await this.#runtime.run(async () => {
|
|
2606
|
-
|
|
2607
|
-
|
|
2608
|
-
|
|
2428
|
+
return await writeWikiGraphArchiveLocation(this.#location, operation, {
|
|
2429
|
+
...options.onIndexSyncError === void 0 ? {} : { onIndexSyncError: options.onIndexSyncError },
|
|
2430
|
+
...options.refreshLibraryIndex === void 0 ? {} : { refreshLibraryIndex: options.refreshLibraryIndex },
|
|
2609
2431
|
...options.searchIndexWritebackPolicy === void 0 ? {} : {
|
|
2610
2432
|
searchIndexWritebackPolicy: options.searchIndexWritebackPolicy
|
|
2611
2433
|
}
|
|
2612
2434
|
});
|
|
2613
|
-
if (options.refreshLibraryIndex !== false) {
|
|
2614
|
-
await this.#refreshLibraryIndex(options.onIndexSyncError);
|
|
2615
|
-
}
|
|
2616
|
-
return result;
|
|
2617
2435
|
}, options.signal);
|
|
2618
2436
|
}
|
|
2619
2437
|
async #resolveScope(document, options) {
|
|
@@ -2623,7 +2441,7 @@ var WikiGraphArchiveHandle = class {
|
|
|
2623
2441
|
async #resolveQueryChapters(document, options) {
|
|
2624
2442
|
const chapters = await this.#resolveScope(document, options);
|
|
2625
2443
|
if (options.skipUnindexed !== true) return chapters;
|
|
2626
|
-
const queryable = await (0,
|
|
2444
|
+
const queryable = await (0, import_wiki_graph_core7.listArchiveQueryableChapterIds)(document, {
|
|
2627
2445
|
...chapters === void 0 ? {} : { chapters }
|
|
2628
2446
|
});
|
|
2629
2447
|
if (queryable.length === 0) {
|
|
@@ -2633,56 +2451,11 @@ var WikiGraphArchiveHandle = class {
|
|
|
2633
2451
|
}
|
|
2634
2452
|
return queryable;
|
|
2635
2453
|
}
|
|
2636
|
-
async #refreshLibraryIndex(onError) {
|
|
2637
|
-
if (this.#location.libraryDirtyTarget === void 0) return;
|
|
2638
|
-
if (this.#location.libraryArchiveTarget !== void 0) {
|
|
2639
|
-
await (0, import_wiki_graph_core5.finalizeWikiGraphLibraryArchiveWrite)({
|
|
2640
|
-
target: this.#location.libraryArchiveTarget
|
|
2641
|
-
});
|
|
2642
|
-
}
|
|
2643
|
-
try {
|
|
2644
|
-
const state = await (0, import_wiki_graph_core5.readWikiGraphLibraryIndexState)(
|
|
2645
|
-
this.#location.libraryDirtyTarget
|
|
2646
|
-
);
|
|
2647
|
-
if (state.status !== "missing") {
|
|
2648
|
-
await (0, import_wiki_graph_core5.rebuildWikiGraphLibraryIndex)(this.#location.libraryDirtyTarget);
|
|
2649
|
-
}
|
|
2650
|
-
} catch (error) {
|
|
2651
|
-
onError?.(error);
|
|
2652
|
-
}
|
|
2653
|
-
}
|
|
2654
2454
|
};
|
|
2655
|
-
async function resolveWikiGraphArchiveLocation(uriOrPath) {
|
|
2656
|
-
if (!uriOrPath.startsWith("wikg://")) {
|
|
2657
|
-
return createPathLocation(resolveWikiGraphRuntimePath(uriOrPath));
|
|
2658
|
-
}
|
|
2659
|
-
const parsed = (0, import_wiki_graph_core5.parseLocatedWikiGraphUri)(uriOrPath);
|
|
2660
|
-
const portableArchiveLocator = parsed.archivePath ?? uriOrPath;
|
|
2661
|
-
const archiveLocator = portableArchiveLocator.startsWith("wikg://lib/") ? portableArchiveLocator : resolveWikiGraphRuntimePath(portableArchiveLocator);
|
|
2662
|
-
const libraryArchiveTarget = archiveLocator.startsWith("wikg://lib/") ? (0, import_wiki_graph_core5.parseWikiGraphLibraryUri)(archiveLocator) : void 0;
|
|
2663
|
-
const archiveFile = libraryArchiveTarget?.kind === "archive" ? await (0, import_wiki_graph_core5.resolveWikiGraphLibraryArchiveFile)(archiveLocator) : new NodeFile(archiveLocator);
|
|
2664
|
-
const archivePath = getNodeResourcePath(archiveFile);
|
|
2665
|
-
return {
|
|
2666
|
-
archiveFile,
|
|
2667
|
-
archiveKey: archivePath,
|
|
2668
|
-
archivePath,
|
|
2669
|
-
indexScope: { archiveKey: archivePath, archivePath, kind: "archive-index" },
|
|
2670
|
-
...libraryArchiveTarget?.kind === "archive" ? {
|
|
2671
|
-
libraryArchiveTarget,
|
|
2672
|
-
libraryDirtyTarget: {
|
|
2673
|
-
isDefault: libraryArchiveTarget.isDefault,
|
|
2674
|
-
kind: "scope",
|
|
2675
|
-
...libraryArchiveTarget.publicId === void 0 ? {} : { publicId: libraryArchiveTarget.publicId }
|
|
2676
|
-
},
|
|
2677
|
-
publicArchiveUri: portableArchiveLocator
|
|
2678
|
-
} : {},
|
|
2679
|
-
locatedUri: (0, import_wiki_graph_core5.formatLocatedWikiGraphUri)(archivePath, parsed.objectUri)
|
|
2680
|
-
};
|
|
2681
|
-
}
|
|
2682
2455
|
async function ensureArchiveSearchIndex(document, options = {}) {
|
|
2683
2456
|
const scope = options.chapters === void 0 ? {} : { chapters: options.chapters };
|
|
2684
|
-
if (await (0,
|
|
2685
|
-
await (0,
|
|
2457
|
+
if (await (0, import_wiki_graph_core7.isArchiveSearchIndexCurrent)(document, scope)) return;
|
|
2458
|
+
await (0, import_wiki_graph_core7.rebuildArchiveSearchIndex)(document, void 0, {
|
|
2686
2459
|
...scope,
|
|
2687
2460
|
...options.embeddingProvider === void 0 ? {} : { embeddingProvider: options.embeddingProvider }
|
|
2688
2461
|
});
|
|
@@ -2692,10 +2465,10 @@ async function resolveArchiveScope(document, objectUri, depth) {
|
|
|
2692
2465
|
if (parsed === void 0 || parsed.kind === "collection" && depth === void 0) {
|
|
2693
2466
|
return void 0;
|
|
2694
2467
|
}
|
|
2695
|
-
const chapters = await (0,
|
|
2468
|
+
const chapters = await (0, import_wiki_graph_core7.listChapters)(document);
|
|
2696
2469
|
const entries = parsed.kind === "collection" ? chapters.filter((chapter) => chapter.depth <= depth) : selectChapterSubtree(
|
|
2697
2470
|
chapters,
|
|
2698
|
-
await (0,
|
|
2471
|
+
await (0, import_wiki_graph_core7.resolveChapterPathReadonly)(document, parsed.chapterPath),
|
|
2699
2472
|
depth
|
|
2700
2473
|
);
|
|
2701
2474
|
return { chapterIds: entries.map((entry) => entry.chapterId), entries };
|
|
@@ -2717,32 +2490,23 @@ function selectChapterSubtree(chapters, rootChapterId, depth) {
|
|
|
2717
2490
|
(chapter) => chapter.chapterId === root.chapterId || chapter.path.startsWith(prefix) && (depth === void 0 || chapter.depth - root.depth <= depth)
|
|
2718
2491
|
);
|
|
2719
2492
|
}
|
|
2720
|
-
function createPathLocation(path) {
|
|
2721
|
-
return {
|
|
2722
|
-
archiveFile: new NodeFile(path),
|
|
2723
|
-
archiveKey: path,
|
|
2724
|
-
archivePath: path,
|
|
2725
|
-
indexScope: { archiveKey: path, archivePath: path, kind: "archive-index" },
|
|
2726
|
-
locatedUri: (0, import_wiki_graph_core5.formatLocatedWikiGraphUri)(path)
|
|
2727
|
-
};
|
|
2728
|
-
}
|
|
2729
2493
|
async function createEmptyArchiveFile(path) {
|
|
2730
|
-
const directoryPath = await (0,
|
|
2731
|
-
(0,
|
|
2494
|
+
const directoryPath = await (0, import_promises4.mkdtemp)(
|
|
2495
|
+
(0, import_path5.join)((0, import_os3.tmpdir)(), "wikigraph-archive-write-")
|
|
2732
2496
|
);
|
|
2733
2497
|
try {
|
|
2734
2498
|
const directory = new NodeDirectory(directoryPath);
|
|
2735
|
-
const document = await
|
|
2499
|
+
const document = await import_wiki_graph_core7.DirectoryDocument.open(directory);
|
|
2736
2500
|
try {
|
|
2737
2501
|
await document.openSession(async (openedDocument) => {
|
|
2738
|
-
await openedDocument.writeToc({ items: [], version:
|
|
2502
|
+
await openedDocument.writeToc({ items: [], version: import_wiki_graph_core7.TOC_FILE_VERSION });
|
|
2739
2503
|
});
|
|
2740
2504
|
} finally {
|
|
2741
2505
|
await document.release();
|
|
2742
2506
|
}
|
|
2743
|
-
await (0,
|
|
2507
|
+
await (0, import_wiki_graph_core7.writeWikgArchive)(directory, new NodeFile(path));
|
|
2744
2508
|
} finally {
|
|
2745
|
-
await (0,
|
|
2509
|
+
await (0, import_promises4.rm)(directoryPath, { force: true, recursive: true });
|
|
2746
2510
|
}
|
|
2747
2511
|
}
|
|
2748
2512
|
function isNodeEEXISTError(error) {
|
|
@@ -2750,7 +2514,7 @@ function isNodeEEXISTError(error) {
|
|
|
2750
2514
|
}
|
|
2751
2515
|
async function nodePathExists(path) {
|
|
2752
2516
|
try {
|
|
2753
|
-
await (0,
|
|
2517
|
+
await (0, import_promises4.stat)(path);
|
|
2754
2518
|
return true;
|
|
2755
2519
|
} catch (error) {
|
|
2756
2520
|
if (isNodeENOENTError(error)) return false;
|
|
@@ -2762,13 +2526,13 @@ function isNodeENOENTError(error) {
|
|
|
2762
2526
|
}
|
|
2763
2527
|
function parseObjectMetadataTarget(objectPath) {
|
|
2764
2528
|
if (objectPath === "") {
|
|
2765
|
-
return { kind:
|
|
2529
|
+
return { kind: import_wiki_graph_core7.ObjectMetadataKind.Archive, objectPath };
|
|
2766
2530
|
}
|
|
2767
2531
|
const chapter = /^chapter\/([1-9][0-9]*)(?:\/.*)?$/u.exec(objectPath);
|
|
2768
2532
|
if (chapter?.[1] !== void 0) {
|
|
2769
2533
|
return {
|
|
2770
2534
|
chapterId: Number(chapter[1]),
|
|
2771
|
-
kind:
|
|
2535
|
+
kind: import_wiki_graph_core7.ObjectMetadataKind.Chapter,
|
|
2772
2536
|
objectPath
|
|
2773
2537
|
};
|
|
2774
2538
|
}
|
|
@@ -2776,7 +2540,7 @@ function parseObjectMetadataTarget(objectPath) {
|
|
|
2776
2540
|
if (chunk?.[1] !== void 0) {
|
|
2777
2541
|
return {
|
|
2778
2542
|
chunkId: Number(chunk[1]),
|
|
2779
|
-
kind:
|
|
2543
|
+
kind: import_wiki_graph_core7.ObjectMetadataKind.Chunk,
|
|
2780
2544
|
objectPath
|
|
2781
2545
|
};
|
|
2782
2546
|
}
|
|
@@ -2784,7 +2548,7 @@ function parseObjectMetadataTarget(objectPath) {
|
|
|
2784
2548
|
if (entity?.[1] !== void 0) {
|
|
2785
2549
|
return {
|
|
2786
2550
|
entityQid: entity[1],
|
|
2787
|
-
kind:
|
|
2551
|
+
kind: import_wiki_graph_core7.ObjectMetadataKind.Entity,
|
|
2788
2552
|
objectPath
|
|
2789
2553
|
};
|
|
2790
2554
|
}
|
|
@@ -2793,14 +2557,14 @@ function parseObjectMetadataTarget(objectPath) {
|
|
|
2793
2557
|
);
|
|
2794
2558
|
if (triple?.[1] !== void 0) {
|
|
2795
2559
|
return {
|
|
2796
|
-
kind:
|
|
2560
|
+
kind: import_wiki_graph_core7.ObjectMetadataKind.Triple,
|
|
2797
2561
|
objectPath,
|
|
2798
2562
|
tripleObjectQid: triple[3],
|
|
2799
2563
|
triplePredicate: decodeURIComponent(triple[2]),
|
|
2800
2564
|
tripleSubjectQid: triple[1]
|
|
2801
2565
|
};
|
|
2802
2566
|
}
|
|
2803
|
-
return { kind:
|
|
2567
|
+
return { kind: import_wiki_graph_core7.ObjectMetadataKind.Object, objectPath };
|
|
2804
2568
|
}
|
|
2805
2569
|
function withoutOperation(options) {
|
|
2806
2570
|
const { signal: _signal, ...rest } = options;
|
|
@@ -2816,7 +2580,7 @@ function withoutOperationAndScope(options) {
|
|
|
2816
2580
|
return rest;
|
|
2817
2581
|
}
|
|
2818
2582
|
async function resolveOptionalChapterPath(document, path) {
|
|
2819
|
-
return path === void 0 ? void 0 : await (0,
|
|
2583
|
+
return path === void 0 ? void 0 : await (0, import_wiki_graph_core7.resolveChapterPathReadonly)(document, path);
|
|
2820
2584
|
}
|
|
2821
2585
|
function requireChapter(chapters, chapterId) {
|
|
2822
2586
|
const chapter = chapters.find((entry) => entry.chapterId === chapterId);
|
|
@@ -2830,7 +2594,7 @@ function asTextStream(text) {
|
|
|
2830
2594
|
}
|
|
2831
2595
|
async function assertChapterResetAllowed(archive, chapterId, stage) {
|
|
2832
2596
|
if (stage === "planned") {
|
|
2833
|
-
await (0,
|
|
2597
|
+
await (0, import_wiki_graph_core7.assertNoActiveBuildJobs)({
|
|
2834
2598
|
archive,
|
|
2835
2599
|
chapterIds: [chapterId],
|
|
2836
2600
|
operation: "Resetting chapter to planned"
|
|
@@ -2838,14 +2602,14 @@ async function assertChapterResetAllowed(archive, chapterId, stage) {
|
|
|
2838
2602
|
return;
|
|
2839
2603
|
}
|
|
2840
2604
|
if (stage === "sourced") {
|
|
2841
|
-
await (0,
|
|
2605
|
+
await (0, import_wiki_graph_core7.assertNoActiveBuildJobs)({
|
|
2842
2606
|
archive,
|
|
2843
2607
|
chapterIds: [chapterId],
|
|
2844
2608
|
operation: "Resetting chapter graph",
|
|
2845
2609
|
requiresTarget: "reading-graph"
|
|
2846
2610
|
});
|
|
2847
2611
|
}
|
|
2848
|
-
await (0,
|
|
2612
|
+
await (0, import_wiki_graph_core7.assertNoActiveBuildJobs)({
|
|
2849
2613
|
archive,
|
|
2850
2614
|
chapterIds: [chapterId],
|
|
2851
2615
|
operation: "Resetting chapter summary",
|
|
@@ -2857,7 +2621,7 @@ async function assertChapterResetAllowed(archive, chapterId, stage) {
|
|
|
2857
2621
|
WikiGraphArchiveExistsError,
|
|
2858
2622
|
WikiGraphArchiveHandle,
|
|
2859
2623
|
WikiGraphArchiveManager,
|
|
2860
|
-
|
|
2861
|
-
|
|
2624
|
+
WikiGraphArchiveOwnershipError,
|
|
2625
|
+
inspectWikiGraphArchive
|
|
2862
2626
|
});
|
|
2863
2627
|
//# sourceMappingURL=archives.cjs.map
|