wiki-graph-sdk 0.7.0 → 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 +16 -0
- package/dist/archives.cjs +470 -642
- package/dist/archives.cjs.map +1 -1
- package/dist/archives.d.ts +42 -80
- package/dist/archives.js +405 -570
- package/dist/archives.js.map +1 -1
- package/dist/conversions.cjs +223 -27
- package/dist/conversions.cjs.map +1 -1
- package/dist/conversions.d.ts +16 -4
- package/dist/conversions.js +228 -23
- package/dist/conversions.js.map +1 -1
- package/dist/default-worker.cjs +293 -55
- package/dist/default-worker.cjs.map +1 -1
- package/dist/default-worker.js +309 -54
- package/dist/default-worker.js.map +1 -1
- package/dist/index.cjs +1044 -923
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +36 -19
- package/dist/index.js +915 -780
- 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 +328 -22
- package/dist/worker.cjs.map +1 -1
- package/dist/worker.d.ts +43 -4
- package/dist/worker.js +348 -27
- package/dist/worker.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -32,22 +32,23 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
32
32
|
var src_exports = {};
|
|
33
33
|
__export(src_exports, {
|
|
34
34
|
DANGEROUS_RUNTIME_ENV_NAMES: () => DANGEROUS_RUNTIME_ENV_NAMES,
|
|
35
|
-
DEFAULT_EXTRACTION_PROMPT: () =>
|
|
35
|
+
DEFAULT_EXTRACTION_PROMPT: () => import_wiki_graph_core10.DEFAULT_EXTRACTION_PROMPT,
|
|
36
36
|
DEFAULT_GENERATION_JOB_CONCURRENCY: () => DEFAULT_GENERATION_JOB_CONCURRENCY,
|
|
37
37
|
DEFAULT_GENERATION_REQUEST_CONCURRENCY: () => DEFAULT_GENERATION_REQUEST_CONCURRENCY,
|
|
38
|
-
DEFAULT_KNOWLEDGE_GRAPH_RECALL_PROMPT: () =>
|
|
39
|
-
LLMPaymentRequiredError: () =>
|
|
38
|
+
DEFAULT_KNOWLEDGE_GRAPH_RECALL_PROMPT: () => import_wiki_graph_core10.DEFAULT_KNOWLEDGE_GRAPH_RECALL_PROMPT,
|
|
39
|
+
LLMPaymentRequiredError: () => import_wiki_graph_core19.LLMPaymentRequiredError,
|
|
40
40
|
LOCAL_CONFIG_SECTIONS: () => LOCAL_CONFIG_SECTIONS,
|
|
41
41
|
NodeDirectory: () => NodeDirectory,
|
|
42
42
|
NodeFile: () => NodeFile,
|
|
43
|
-
WIKI_GRAPH_URI_PREFIX: () =>
|
|
43
|
+
WIKI_GRAPH_URI_PREFIX: () => import_wiki_graph_core19.WIKI_GRAPH_URI_PREFIX,
|
|
44
44
|
WikiGraphArchiveExistsError: () => WikiGraphArchiveExistsError,
|
|
45
45
|
WikiGraphArchiveHandle: () => WikiGraphArchiveHandle,
|
|
46
46
|
WikiGraphArchiveManager: () => WikiGraphArchiveManager,
|
|
47
|
+
WikiGraphArchiveOwnershipError: () => WikiGraphArchiveOwnershipError,
|
|
47
48
|
WikiGraphConfigManager: () => WikiGraphConfigManager,
|
|
48
49
|
WikiGraphContinuationManager: () => WikiGraphContinuationManager,
|
|
49
50
|
WikiGraphConversionManager: () => WikiGraphConversionManager,
|
|
50
|
-
WikiGraphError: () =>
|
|
51
|
+
WikiGraphError: () => import_wiki_graph_core19.WikiGraphError,
|
|
51
52
|
WikiGraphJob: () => WikiGraphJob,
|
|
52
53
|
WikiGraphJobManager: () => WikiGraphJobManager,
|
|
53
54
|
WikiGraphLibrary: () => WikiGraphLibrary,
|
|
@@ -62,51 +63,50 @@ __export(src_exports, {
|
|
|
62
63
|
createNodeTemplateEnvironment: () => createNodeTemplateEnvironment,
|
|
63
64
|
createNodeWikiGraphStorage: () => createNodeWikiGraphStorage,
|
|
64
65
|
createStageLLM: () => createStageLLM,
|
|
65
|
-
createWikiGraphArchiveInspectReport: () => createWikiGraphArchiveInspectReport,
|
|
66
66
|
createWikiGraphSDK: () => createWikiGraphSDK,
|
|
67
67
|
deleteLocalConfigValue: () => deleteLocalConfigValue,
|
|
68
68
|
embedQueryText: () => embedQueryText,
|
|
69
69
|
embedQueryTextWithLocalConfig: () => embedQueryTextWithLocalConfig,
|
|
70
70
|
ensureNodeWikiGraphPlatform: () => ensureNodeWikiGraphPlatform,
|
|
71
|
-
formatError: () =>
|
|
71
|
+
formatError: () => import_wiki_graph_core19.formatError,
|
|
72
72
|
formatGenerationPlanningDuration: () => formatGenerationPlanningDuration,
|
|
73
73
|
formatGenerationPlanningModel: () => formatGenerationPlanningModel,
|
|
74
|
-
formatLocatedChapterResourceUri: () =>
|
|
75
|
-
formatLocatedChapterSourceCollectionUri: () =>
|
|
76
|
-
formatLocatedChapterUri: () =>
|
|
77
|
-
formatLocatedWikiGraphUri: () =>
|
|
78
|
-
formatWikiGraphCommandUri: () =>
|
|
79
|
-
formatWikiGraphLibraryUri: () =>
|
|
74
|
+
formatLocatedChapterResourceUri: () => import_wiki_graph_core19.formatLocatedChapterResourceUri,
|
|
75
|
+
formatLocatedChapterSourceCollectionUri: () => import_wiki_graph_core19.formatLocatedChapterSourceCollectionUri,
|
|
76
|
+
formatLocatedChapterUri: () => import_wiki_graph_core19.formatLocatedChapterUri,
|
|
77
|
+
formatLocatedWikiGraphUri: () => import_wiki_graph_core19.formatLocatedWikiGraphUri,
|
|
78
|
+
formatWikiGraphCommandUri: () => import_wiki_graph_core19.formatWikiGraphCommandUri,
|
|
79
|
+
formatWikiGraphLibraryUri: () => import_wiki_graph_core19.formatWikiGraphLibraryUri,
|
|
80
80
|
getNodeResourcePath: () => getNodeResourcePath,
|
|
81
81
|
getWikiGraphSDKRuntimeContext: () => getWikiGraphSDKRuntimeContext,
|
|
82
82
|
getWikiGraphSDKStateDir: () => getWikiGraphSDKStateDir,
|
|
83
|
+
inspectWikiGraphArchive: () => inspectWikiGraphArchive,
|
|
83
84
|
installNodeWikiGraphPlatform: () => installNodeWikiGraphPlatform,
|
|
84
|
-
isSourceLocatorScopeUri: () =>
|
|
85
|
-
isWikiGraphLibraryUri: () =>
|
|
85
|
+
isSourceLocatorScopeUri: () => import_wiki_graph_core19.isSourceLocatorScopeUri,
|
|
86
|
+
isWikiGraphLibraryUri: () => import_wiki_graph_core19.isWikiGraphLibraryUri,
|
|
86
87
|
loadRequiredStageConfig: () => loadRequiredStageConfig,
|
|
87
88
|
loadWikiGraphRuntimeConfig: () => loadWikiGraphRuntimeConfig,
|
|
88
89
|
maskLocalConfigSection: () => maskLocalConfigSection,
|
|
89
90
|
nodeWikiGraphPlatform: () => nodeWikiGraphPlatform,
|
|
90
91
|
nodeWikispineCommandRunner: () => nodeWikispineCommandRunner,
|
|
91
92
|
normalizeLocalConfigKey: () => normalizeLocalConfigKey,
|
|
92
|
-
parseChapterPath: () =>
|
|
93
|
-
parseChapterTreeInput: () =>
|
|
94
|
-
parseChapterUriPath: () =>
|
|
93
|
+
parseChapterPath: () => import_wiki_graph_core19.parseChapterPath,
|
|
94
|
+
parseChapterTreeInput: () => import_wiki_graph_core19.parseChapterTreeInput,
|
|
95
|
+
parseChapterUriPath: () => import_wiki_graph_core19.parseChapterUriPath,
|
|
95
96
|
parseLocalConfigSection: () => parseLocalConfigSection,
|
|
96
|
-
parseLocatedWikiGraphUri: () =>
|
|
97
|
-
parseSourceTextJsonl: () =>
|
|
98
|
-
parseWikiGraphLibraryUri: () =>
|
|
99
|
-
parseWikiGraphUriSyntax: () =>
|
|
97
|
+
parseLocatedWikiGraphUri: () => import_wiki_graph_core19.parseLocatedWikiGraphUri,
|
|
98
|
+
parseSourceTextJsonl: () => import_wiki_graph_core19.parseSourceTextJsonl,
|
|
99
|
+
parseWikiGraphLibraryUri: () => import_wiki_graph_core19.parseWikiGraphLibraryUri,
|
|
100
|
+
parseWikiGraphUriSyntax: () => import_wiki_graph_core19.parseWikiGraphUriSyntax,
|
|
100
101
|
planGenerationTask: () => planGenerationTask,
|
|
101
102
|
putLocalConfigValue: () => putLocalConfigValue,
|
|
102
103
|
readLocalConfigSection: () => readLocalConfigSection,
|
|
103
104
|
readWikiGraphEmbeddingConfig: () => readWikiGraphEmbeddingConfig,
|
|
104
105
|
replaceLocalConfigSection: () => replaceLocalConfigSection,
|
|
105
106
|
requireKnowledgeGraphWikispineConfig: () => requireKnowledgeGraphWikispineConfig,
|
|
106
|
-
resolveExtractionPrompt: () =>
|
|
107
|
+
resolveExtractionPrompt: () => import_wiki_graph_core10.resolveExtractionPrompt,
|
|
107
108
|
resolveHostedProviderEndpoint: () => resolveHostedProviderEndpoint,
|
|
108
|
-
resolveKnowledgeGraphRecallPrompt: () =>
|
|
109
|
-
resolveWikiGraphArchiveLocation: () => resolveWikiGraphArchiveLocation,
|
|
109
|
+
resolveKnowledgeGraphRecallPrompt: () => import_wiki_graph_core10.resolveKnowledgeGraphRecallPrompt,
|
|
110
110
|
resolveWikispineConfig: () => resolveWikispineConfig,
|
|
111
111
|
runWikiGraphQueueWorker: () => runWikiGraphQueueWorker,
|
|
112
112
|
validateLocalConfigSection: () => validateLocalConfigSection,
|
|
@@ -117,16 +117,19 @@ __export(src_exports, {
|
|
|
117
117
|
module.exports = __toCommonJS(src_exports);
|
|
118
118
|
|
|
119
119
|
// src/archive/archive.ts
|
|
120
|
-
var
|
|
121
|
-
var
|
|
120
|
+
var import_crypto2 = require("crypto");
|
|
121
|
+
var import_promises4 = require("fs/promises");
|
|
122
122
|
var import_os3 = require("os");
|
|
123
|
-
var
|
|
123
|
+
var import_path5 = require("path");
|
|
124
124
|
var import_stream = require("stream");
|
|
125
|
-
var
|
|
125
|
+
var import_wiki_graph_core7 = require("wiki-graph-core");
|
|
126
126
|
|
|
127
127
|
// src/conversions.ts
|
|
128
|
-
var
|
|
129
|
-
var
|
|
128
|
+
var import_crypto = require("crypto");
|
|
129
|
+
var import_fs = require("fs");
|
|
130
|
+
var import_promises3 = require("fs/promises");
|
|
131
|
+
var import_path4 = require("path");
|
|
132
|
+
var import_wiki_graph_core3 = require("wiki-graph-core");
|
|
130
133
|
|
|
131
134
|
// src/llm.ts
|
|
132
135
|
var import_anthropic = require("@ai-sdk/anthropic");
|
|
@@ -446,42 +449,42 @@ var NodeDatabaseConnection = class {
|
|
|
446
449
|
}
|
|
447
450
|
database;
|
|
448
451
|
async close() {
|
|
449
|
-
await new Promise((
|
|
452
|
+
await new Promise((resolve4, reject) => {
|
|
450
453
|
this.database.close((error) => {
|
|
451
454
|
if (error) reject(error);
|
|
452
|
-
else
|
|
455
|
+
else resolve4();
|
|
453
456
|
});
|
|
454
457
|
});
|
|
455
458
|
}
|
|
456
459
|
async execute(sql) {
|
|
457
|
-
await new Promise((
|
|
460
|
+
await new Promise((resolve4, reject) => {
|
|
458
461
|
this.database.exec(sql, (error) => {
|
|
459
462
|
if (error) reject(error);
|
|
460
|
-
else
|
|
463
|
+
else resolve4();
|
|
461
464
|
});
|
|
462
465
|
});
|
|
463
466
|
}
|
|
464
467
|
async queryAll(sql, params = []) {
|
|
465
|
-
return await new Promise((
|
|
468
|
+
return await new Promise((resolve4, reject) => {
|
|
466
469
|
this.database.all(sql, [...params], (error, rows) => {
|
|
467
470
|
if (error) reject(error);
|
|
468
|
-
else
|
|
471
|
+
else resolve4(rows);
|
|
469
472
|
});
|
|
470
473
|
});
|
|
471
474
|
}
|
|
472
475
|
async queryOne(sql, params = []) {
|
|
473
|
-
return await new Promise((
|
|
476
|
+
return await new Promise((resolve4, reject) => {
|
|
474
477
|
this.database.get(sql, [...params], (error, row) => {
|
|
475
478
|
if (error) reject(error);
|
|
476
|
-
else
|
|
479
|
+
else resolve4(row);
|
|
477
480
|
});
|
|
478
481
|
});
|
|
479
482
|
}
|
|
480
483
|
async run(sql, params = []) {
|
|
481
|
-
await new Promise((
|
|
484
|
+
await new Promise((resolve4, reject) => {
|
|
482
485
|
this.database.run(sql, [...params], (error) => {
|
|
483
486
|
if (error) reject(error);
|
|
484
|
-
else
|
|
487
|
+
else resolve4();
|
|
485
488
|
});
|
|
486
489
|
});
|
|
487
490
|
}
|
|
@@ -495,10 +498,10 @@ async function openNativeNodeDatabase(file, flags) {
|
|
|
495
498
|
if (path === void 0) {
|
|
496
499
|
throw new TypeError("The Node database adapter requires a NodeFile");
|
|
497
500
|
}
|
|
498
|
-
return await new Promise((
|
|
501
|
+
return await new Promise((resolve4, reject) => {
|
|
499
502
|
const database = new nodeSqlite3.Database(path, flags, (error) => {
|
|
500
503
|
if (error) reject(error);
|
|
501
|
-
else
|
|
504
|
+
else resolve4(database);
|
|
502
505
|
});
|
|
503
506
|
});
|
|
504
507
|
}
|
|
@@ -507,19 +510,19 @@ async function openNodeZip(file) {
|
|
|
507
510
|
if (path === void 0) {
|
|
508
511
|
throw new TypeError("The Node ZIP adapter requires a NodeFile");
|
|
509
512
|
}
|
|
510
|
-
const zipFile = await new Promise((
|
|
513
|
+
const zipFile = await new Promise((resolve4, reject) => {
|
|
511
514
|
yauzl.open(
|
|
512
515
|
path,
|
|
513
516
|
{ autoClose: false, lazyEntries: true },
|
|
514
517
|
(error, opened) => {
|
|
515
518
|
if (error || opened === void 0)
|
|
516
519
|
reject(error ?? new Error("Cannot open ZIP"));
|
|
517
|
-
else
|
|
520
|
+
else resolve4(opened);
|
|
518
521
|
}
|
|
519
522
|
);
|
|
520
523
|
});
|
|
521
524
|
const entries = await new Promise(
|
|
522
|
-
(
|
|
525
|
+
(resolve4, reject) => {
|
|
523
526
|
const discovered = /* @__PURE__ */ new Map();
|
|
524
527
|
const rejectAndClose = (error) => {
|
|
525
528
|
zipFile.close();
|
|
@@ -529,7 +532,7 @@ async function openNodeZip(file) {
|
|
|
529
532
|
};
|
|
530
533
|
const resolveEntries = () => {
|
|
531
534
|
zipFile.off("error", rejectAndClose);
|
|
532
|
-
|
|
535
|
+
resolve4(discovered);
|
|
533
536
|
};
|
|
534
537
|
zipFile.on("entry", (entry) => {
|
|
535
538
|
if (!entry.fileName.endsWith("/")) {
|
|
@@ -639,12 +642,12 @@ async function collectDecodedNodeStreamRange(input, offset, length) {
|
|
|
639
642
|
return Buffer.concat(chunks, collected);
|
|
640
643
|
}
|
|
641
644
|
async function openNodeZipEntryStream(zipFile, entry, options) {
|
|
642
|
-
return await new Promise((
|
|
645
|
+
return await new Promise((resolve4, reject) => {
|
|
643
646
|
const callback = (error, opened) => {
|
|
644
647
|
if (error || opened === void 0) {
|
|
645
648
|
reject(error ?? new Error(`Cannot read ZIP entry: ${entry.fileName}`));
|
|
646
649
|
} else {
|
|
647
|
-
|
|
650
|
+
resolve4(opened);
|
|
648
651
|
}
|
|
649
652
|
};
|
|
650
653
|
if (options === void 0) zipFile.openReadStream(entry, callback);
|
|
@@ -775,11 +778,11 @@ async function writeNodeStream(input, writer) {
|
|
|
775
778
|
);
|
|
776
779
|
}
|
|
777
780
|
async function collectNodeStream(input) {
|
|
778
|
-
return await new Promise((
|
|
781
|
+
return await new Promise((resolve4, reject) => {
|
|
779
782
|
const chunks = [];
|
|
780
783
|
input.on("data", (chunk) => chunks.push(chunk));
|
|
781
784
|
input.once("error", reject);
|
|
782
|
-
input.once("end", () =>
|
|
785
|
+
input.once("end", () => resolve4(Buffer.concat(chunks)));
|
|
783
786
|
});
|
|
784
787
|
}
|
|
785
788
|
var nodeWikiGraphPlatform = {
|
|
@@ -1448,6 +1451,194 @@ function resolveWikiGraphRuntimePath(path) {
|
|
|
1448
1451
|
return (0, import_path2.isAbsolute)(path) ? path : (0, import_path2.resolve)(context.cwd, path);
|
|
1449
1452
|
}
|
|
1450
1453
|
|
|
1454
|
+
// src/archive/target.ts
|
|
1455
|
+
var import_promises2 = require("fs/promises");
|
|
1456
|
+
var import_path3 = require("path");
|
|
1457
|
+
var import_wiki_graph_core2 = require("wiki-graph-core");
|
|
1458
|
+
var WikiGraphArchiveOwnershipError = class extends Error {
|
|
1459
|
+
code = "WIKI_GRAPH_ARCHIVE_OWNERSHIP_MISMATCH";
|
|
1460
|
+
constructor(message) {
|
|
1461
|
+
super(message);
|
|
1462
|
+
this.name = "WikiGraphArchiveOwnershipError";
|
|
1463
|
+
}
|
|
1464
|
+
};
|
|
1465
|
+
async function resolveWikiGraphArchiveLocation(target) {
|
|
1466
|
+
if (target.kind === "standalone") {
|
|
1467
|
+
return await resolveStandaloneLocation(target);
|
|
1468
|
+
}
|
|
1469
|
+
return await resolveLibraryLocation(target);
|
|
1470
|
+
}
|
|
1471
|
+
async function assertStandaloneWikiGraphArchivePath(inputPath) {
|
|
1472
|
+
const path = resolveWikiGraphRuntimePath(inputPath);
|
|
1473
|
+
const candidate = await canonicalPath(path);
|
|
1474
|
+
const candidateIdentity = await readFileIdentity(path);
|
|
1475
|
+
const libraries = await (0, import_wiki_graph_core2.listWikiGraphLibraries)();
|
|
1476
|
+
const matches = await findMatchingMembers(
|
|
1477
|
+
libraries,
|
|
1478
|
+
candidate,
|
|
1479
|
+
candidateIdentity
|
|
1480
|
+
);
|
|
1481
|
+
if (matches.length > 0) {
|
|
1482
|
+
const match = requireUnambiguousManagedMatch(path, matches);
|
|
1483
|
+
throw new WikiGraphArchiveOwnershipError(
|
|
1484
|
+
`Standalone archive path belongs to registered library ${(0, import_wiki_graph_core2.formatWikiGraphLibraryUri)(
|
|
1485
|
+
match.library.isDefault ? void 0 : match.library.publicId
|
|
1486
|
+
)}: ${path}. Use the library UUID URI ${match.archive.uri} instead.`
|
|
1487
|
+
);
|
|
1488
|
+
}
|
|
1489
|
+
for (const library of libraries) {
|
|
1490
|
+
const rootPath = getNodeResourcePath(library.folder);
|
|
1491
|
+
const root = await canonicalPath(rootPath);
|
|
1492
|
+
if (!isWithin(root, candidate)) continue;
|
|
1493
|
+
throw new WikiGraphArchiveOwnershipError(
|
|
1494
|
+
`Standalone archive path belongs to registered library ${(0, import_wiki_graph_core2.formatWikiGraphLibraryUri)(
|
|
1495
|
+
library.isDefault ? void 0 : library.publicId
|
|
1496
|
+
)}: ${path}. Scan the library, then address the archive by its library UUID URI.`
|
|
1497
|
+
);
|
|
1498
|
+
}
|
|
1499
|
+
return path;
|
|
1500
|
+
}
|
|
1501
|
+
function archiveTargetFromLogicalLocator(locator, objectUri) {
|
|
1502
|
+
if (locator.startsWith("wikg://lib/")) {
|
|
1503
|
+
return { kind: "library", uri: withObjectUri(locator, objectUri) };
|
|
1504
|
+
}
|
|
1505
|
+
return {
|
|
1506
|
+
kind: "standalone",
|
|
1507
|
+
path: locator,
|
|
1508
|
+
...objectUri === void 0 ? {} : { objectUri }
|
|
1509
|
+
};
|
|
1510
|
+
}
|
|
1511
|
+
async function resolveWikiGraphArchiveTarget(file) {
|
|
1512
|
+
const path = getNodeResourcePath(file);
|
|
1513
|
+
const candidate = await canonicalPath(path);
|
|
1514
|
+
const candidateIdentity = await readFileIdentity(path);
|
|
1515
|
+
const matches = await findMatchingMembers(
|
|
1516
|
+
await (0, import_wiki_graph_core2.listWikiGraphLibraries)(),
|
|
1517
|
+
candidate,
|
|
1518
|
+
candidateIdentity
|
|
1519
|
+
);
|
|
1520
|
+
if (matches.length > 0) {
|
|
1521
|
+
const match = requireUnambiguousManagedMatch(path, matches);
|
|
1522
|
+
return { kind: "library", uri: match.archive.uri };
|
|
1523
|
+
}
|
|
1524
|
+
return { kind: "standalone", path: getNodeResourcePath(file) };
|
|
1525
|
+
}
|
|
1526
|
+
async function resolveStandaloneLocation(target) {
|
|
1527
|
+
if (target.path.startsWith("wikg://lib/")) {
|
|
1528
|
+
throw new WikiGraphArchiveOwnershipError(
|
|
1529
|
+
`A library archive URI cannot be used as a standalone path: ${target.path}`
|
|
1530
|
+
);
|
|
1531
|
+
}
|
|
1532
|
+
const path = await assertStandaloneWikiGraphArchivePath(target.path);
|
|
1533
|
+
const normalized = {
|
|
1534
|
+
kind: "standalone",
|
|
1535
|
+
path,
|
|
1536
|
+
...target.objectUri === void 0 ? {} : { objectUri: target.objectUri }
|
|
1537
|
+
};
|
|
1538
|
+
return {
|
|
1539
|
+
archiveFile: new NodeFile(path),
|
|
1540
|
+
archiveKey: path,
|
|
1541
|
+
archivePath: path,
|
|
1542
|
+
indexScope: { archiveKey: path, archivePath: path, kind: "archive-index" },
|
|
1543
|
+
locatedUri: (0, import_wiki_graph_core2.formatLocatedWikiGraphUri)(path, target.objectUri),
|
|
1544
|
+
target: normalized
|
|
1545
|
+
};
|
|
1546
|
+
}
|
|
1547
|
+
async function resolveLibraryLocation(target) {
|
|
1548
|
+
const parsedLocated = (0, import_wiki_graph_core2.parseLocatedWikiGraphUri)(target.uri);
|
|
1549
|
+
const archiveUri = parsedLocated.archivePath ?? target.uri;
|
|
1550
|
+
const parsed = (0, import_wiki_graph_core2.parseWikiGraphLibraryUri)(archiveUri);
|
|
1551
|
+
if (parsed?.kind !== "archive") {
|
|
1552
|
+
throw new WikiGraphArchiveOwnershipError(
|
|
1553
|
+
`Library archive target must be a UUID archive URI: ${target.uri}`
|
|
1554
|
+
);
|
|
1555
|
+
}
|
|
1556
|
+
await (0, import_wiki_graph_core2.resolveWikiGraphLibrary)(parsed);
|
|
1557
|
+
const archiveFile = await (0, import_wiki_graph_core2.resolveWikiGraphLibraryArchiveFile)(archiveUri);
|
|
1558
|
+
const normalized = {
|
|
1559
|
+
kind: "library",
|
|
1560
|
+
uri: target.uri
|
|
1561
|
+
};
|
|
1562
|
+
return {
|
|
1563
|
+
archiveFile,
|
|
1564
|
+
archiveKey: archiveUri,
|
|
1565
|
+
archivePath: archiveUri,
|
|
1566
|
+
indexScope: {
|
|
1567
|
+
archiveKey: archiveUri,
|
|
1568
|
+
archivePath: archiveUri,
|
|
1569
|
+
kind: "archive-index"
|
|
1570
|
+
},
|
|
1571
|
+
libraryArchiveTarget: parsed,
|
|
1572
|
+
locatedUri: target.uri,
|
|
1573
|
+
publicArchiveUri: archiveUri,
|
|
1574
|
+
target: normalized
|
|
1575
|
+
};
|
|
1576
|
+
}
|
|
1577
|
+
function withObjectUri(archiveLocator, objectUri) {
|
|
1578
|
+
if (objectUri === void 0) return archiveLocator;
|
|
1579
|
+
const path = objectUri.replace(/^wikg:\/\//u, "");
|
|
1580
|
+
return `${archiveLocator.replace(/\/$/u, "")}/${path}`;
|
|
1581
|
+
}
|
|
1582
|
+
async function canonicalPath(path) {
|
|
1583
|
+
try {
|
|
1584
|
+
return await (0, import_promises2.realpath)(path);
|
|
1585
|
+
} catch {
|
|
1586
|
+
const absolute = (0, import_path3.resolve)(path);
|
|
1587
|
+
const parent = (0, import_path3.dirname)(absolute);
|
|
1588
|
+
return parent === absolute ? absolute : (0, import_path3.join)(await canonicalPath(parent), (0, import_path3.basename)(absolute));
|
|
1589
|
+
}
|
|
1590
|
+
}
|
|
1591
|
+
function isWithin(root, candidate) {
|
|
1592
|
+
const child = (0, import_path3.relative)(root, candidate);
|
|
1593
|
+
return child === "" || !child.startsWith("..") && !(0, import_path3.isAbsolute)(child);
|
|
1594
|
+
}
|
|
1595
|
+
async function findMatchingMembers(libraries, candidate, candidateIdentity) {
|
|
1596
|
+
const members = [];
|
|
1597
|
+
for (const library of libraries) {
|
|
1598
|
+
const archives = await (0, import_wiki_graph_core2.listWikiGraphLibraryArchives)({
|
|
1599
|
+
isDefault: library.isDefault,
|
|
1600
|
+
kind: "scope",
|
|
1601
|
+
...library.isDefault ? {} : { publicId: library.publicId }
|
|
1602
|
+
});
|
|
1603
|
+
for (const archive of archives) {
|
|
1604
|
+
if (archive.file === void 0) continue;
|
|
1605
|
+
members.push({
|
|
1606
|
+
archive,
|
|
1607
|
+
library,
|
|
1608
|
+
memberPath: getNodeResourcePath(archive.file)
|
|
1609
|
+
});
|
|
1610
|
+
}
|
|
1611
|
+
}
|
|
1612
|
+
const exact = [];
|
|
1613
|
+
for (const member of members) {
|
|
1614
|
+
if (await canonicalPath(member.memberPath) === candidate) {
|
|
1615
|
+
exact.push(member);
|
|
1616
|
+
}
|
|
1617
|
+
}
|
|
1618
|
+
if (exact.length > 0 || candidateIdentity === void 0) return exact;
|
|
1619
|
+
const identityMatches = [];
|
|
1620
|
+
for (const member of members) {
|
|
1621
|
+
if (await readFileIdentity(member.memberPath) === candidateIdentity) {
|
|
1622
|
+
identityMatches.push(member);
|
|
1623
|
+
}
|
|
1624
|
+
}
|
|
1625
|
+
return identityMatches;
|
|
1626
|
+
}
|
|
1627
|
+
function requireUnambiguousManagedMatch(path, matches) {
|
|
1628
|
+
if (matches.length === 1) return matches[0];
|
|
1629
|
+
throw new WikiGraphArchiveOwnershipError(
|
|
1630
|
+
`Archive file identity is ambiguous across managed archives: ${path}. Use an explicit library UUID URI (${matches.map((match) => match.archive.uri).join(", ")}).`
|
|
1631
|
+
);
|
|
1632
|
+
}
|
|
1633
|
+
async function readFileIdentity(path) {
|
|
1634
|
+
try {
|
|
1635
|
+
const value = await (0, import_promises2.stat)(path);
|
|
1636
|
+
return `${value.dev}:${value.ino}`;
|
|
1637
|
+
} catch {
|
|
1638
|
+
return void 0;
|
|
1639
|
+
}
|
|
1640
|
+
}
|
|
1641
|
+
|
|
1451
1642
|
// src/conversions.ts
|
|
1452
1643
|
var WikiGraphConversionManager = class {
|
|
1453
1644
|
#runtime;
|
|
@@ -1462,6 +1653,9 @@ var WikiGraphConversionManager = class {
|
|
|
1462
1653
|
if (options.targetStage !== void 0 && options.output.format !== "wikg") {
|
|
1463
1654
|
throw new Error("targetStage is only supported for wikg output.");
|
|
1464
1655
|
}
|
|
1656
|
+
if (options.output.format === "pcex") {
|
|
1657
|
+
throw new Error("pcex is supported only as a conversion input.");
|
|
1658
|
+
}
|
|
1465
1659
|
if (options.targetStage !== void 0 && options.input.format === "wikg") {
|
|
1466
1660
|
throw new Error(
|
|
1467
1661
|
"targetStage is only supported when creating a wikg archive."
|
|
@@ -1472,7 +1666,7 @@ var WikiGraphConversionManager = class {
|
|
|
1472
1666
|
const config = await loadWikiGraphRuntimeConfig({
|
|
1473
1667
|
...options.llmJSON === void 0 ? {} : { llmJSON: options.llmJSON }
|
|
1474
1668
|
});
|
|
1475
|
-
const app = new
|
|
1669
|
+
const app = new import_wiki_graph_core3.WikiGraph({
|
|
1476
1670
|
...options.verbose === true ? { verbose: true } : {},
|
|
1477
1671
|
...requiresLLM ? { llm: buildWikiGraphLLMOptions(config) } : {}
|
|
1478
1672
|
});
|
|
@@ -1480,7 +1674,17 @@ var WikiGraphConversionManager = class {
|
|
|
1480
1674
|
options.digestDirectory,
|
|
1481
1675
|
requiresDigest
|
|
1482
1676
|
);
|
|
1677
|
+
let chapterCount;
|
|
1678
|
+
let chapterPaths;
|
|
1483
1679
|
const write = async (archive) => {
|
|
1680
|
+
if (requiresDigest) await options.onSourceImported?.();
|
|
1681
|
+
if (typeof archive.readToc === "function") {
|
|
1682
|
+
const toc = await archive.readToc();
|
|
1683
|
+
chapterCount = toc === void 0 ? void 0 : countTocChapters(toc.items);
|
|
1684
|
+
if (options.output.format === "wikg") {
|
|
1685
|
+
chapterPaths = toc === void 0 ? [] : collectTocChapterPaths(toc.items);
|
|
1686
|
+
}
|
|
1687
|
+
}
|
|
1484
1688
|
await writeArchive(archive, options.output.path, options.output.format);
|
|
1485
1689
|
};
|
|
1486
1690
|
if (options.input.format === "wikg") {
|
|
@@ -1488,7 +1692,9 @@ var WikiGraphConversionManager = class {
|
|
|
1488
1692
|
throw new Error("wikg input requires a file path.");
|
|
1489
1693
|
}
|
|
1490
1694
|
await app.openSession(
|
|
1491
|
-
new NodeFile(
|
|
1695
|
+
new NodeFile(
|
|
1696
|
+
await assertStandaloneWikiGraphArchivePath(options.input.path)
|
|
1697
|
+
),
|
|
1492
1698
|
write
|
|
1493
1699
|
);
|
|
1494
1700
|
} else if ("stream" in options.input) {
|
|
@@ -1513,16 +1719,29 @@ var WikiGraphConversionManager = class {
|
|
|
1513
1719
|
};
|
|
1514
1720
|
if (options.input.format === "epub") {
|
|
1515
1721
|
await app.digestEpubSession(digestOptions, write);
|
|
1722
|
+
} else if (options.input.format === "pcex") {
|
|
1723
|
+
await app.digestPcexSession(
|
|
1724
|
+
{
|
|
1725
|
+
...digestOptions,
|
|
1726
|
+
pdfDigest: options.input.sourcePdf.digest,
|
|
1727
|
+
...options.input.sourcePdf.name === void 0 ? {} : { pdfName: options.input.sourcePdf.name }
|
|
1728
|
+
},
|
|
1729
|
+
write
|
|
1730
|
+
);
|
|
1516
1731
|
} else if (options.input.format === "markdown") {
|
|
1517
1732
|
await app.digestMarkdownSession(digestOptions, write);
|
|
1518
1733
|
} else {
|
|
1519
1734
|
await app.digestTxtSession(digestOptions, write);
|
|
1520
1735
|
}
|
|
1521
1736
|
}
|
|
1737
|
+
const sourceArtifact = await resolveSourceArtifact(options.input);
|
|
1522
1738
|
return {
|
|
1739
|
+
...chapterCount === void 0 ? {} : { chapterCount },
|
|
1740
|
+
...chapterPaths === void 0 ? {} : { chapterPaths },
|
|
1523
1741
|
inputFormat: options.input.format,
|
|
1524
1742
|
outputFormat: options.output.format,
|
|
1525
|
-
outputPath: options.output.path
|
|
1743
|
+
outputPath: options.output.path,
|
|
1744
|
+
...sourceArtifact === void 0 ? {} : { sourceArtifact }
|
|
1526
1745
|
};
|
|
1527
1746
|
}
|
|
1528
1747
|
};
|
|
@@ -1531,18 +1750,74 @@ async function prepareDigestDirectory(path, required) {
|
|
|
1531
1750
|
if (!required || normalized === void 0 || normalized === "")
|
|
1532
1751
|
return void 0;
|
|
1533
1752
|
const resolved = resolveWikiGraphRuntimePath(normalized);
|
|
1534
|
-
await (0,
|
|
1753
|
+
await (0, import_promises3.rm)(resolved, { force: true, recursive: true });
|
|
1535
1754
|
return new NodeDirectory(resolved);
|
|
1536
1755
|
}
|
|
1537
1756
|
async function writeArchive(archive, path, format) {
|
|
1538
|
-
const
|
|
1757
|
+
const outputPath = format === "wikg" ? await assertStandaloneWikiGraphArchivePath(path) : resolveWikiGraphRuntimePath(path);
|
|
1758
|
+
const file = new NodeFile(outputPath);
|
|
1539
1759
|
if (format === "epub") await archive.exportEpub(file);
|
|
1540
1760
|
else if (format === "wikg") await archive.saveAs(file);
|
|
1761
|
+
else if (format === "pcex") throw new Error("pcex output is not supported.");
|
|
1541
1762
|
else await archive.exportText(file);
|
|
1542
1763
|
}
|
|
1764
|
+
async function resolveSourceArtifact(input) {
|
|
1765
|
+
if (!("path" in input) || input.format === "wikg") return void 0;
|
|
1766
|
+
if (input.format === "pcex") {
|
|
1767
|
+
return {
|
|
1768
|
+
digest: input.sourcePdf.digest.trim().toLowerCase(),
|
|
1769
|
+
mediaType: "application/pdf",
|
|
1770
|
+
...input.sourcePdf.name === void 0 ? {} : { name: input.sourcePdf.name }
|
|
1771
|
+
};
|
|
1772
|
+
}
|
|
1773
|
+
if (input.format !== "epub") return void 0;
|
|
1774
|
+
const path = resolveWikiGraphRuntimePath(input.path);
|
|
1775
|
+
const hash = (0, import_crypto.createHash)("sha256");
|
|
1776
|
+
try {
|
|
1777
|
+
for await (const chunk of (0, import_fs.createReadStream)(path)) {
|
|
1778
|
+
hash.update(chunk);
|
|
1779
|
+
}
|
|
1780
|
+
} catch (error) {
|
|
1781
|
+
if (isNodeErrorCode(error, "ENOENT")) return void 0;
|
|
1782
|
+
throw error;
|
|
1783
|
+
}
|
|
1784
|
+
return {
|
|
1785
|
+
digest: hash.digest("hex"),
|
|
1786
|
+
mediaType: "application/epub+zip",
|
|
1787
|
+
name: (0, import_path4.basename)(path)
|
|
1788
|
+
};
|
|
1789
|
+
}
|
|
1790
|
+
function isNodeErrorCode(error, code) {
|
|
1791
|
+
return typeof error === "object" && error !== null && "code" in error && error.code === code;
|
|
1792
|
+
}
|
|
1793
|
+
function countTocChapters(items) {
|
|
1794
|
+
let count = 0;
|
|
1795
|
+
for (const item of items) {
|
|
1796
|
+
if (item.serialId !== void 0) count += 1;
|
|
1797
|
+
count += countTocChapters(
|
|
1798
|
+
item.children
|
|
1799
|
+
);
|
|
1800
|
+
}
|
|
1801
|
+
return count;
|
|
1802
|
+
}
|
|
1803
|
+
function collectTocChapterPaths(items, ancestorKeys = []) {
|
|
1804
|
+
const paths = [];
|
|
1805
|
+
for (const item of items) {
|
|
1806
|
+
const key = item.key ?? `chapter-${item.serialId ?? "group"}`;
|
|
1807
|
+
const chapterPath = [...ancestorKeys, key];
|
|
1808
|
+
if (item.serialId !== void 0) paths.push(chapterPath.join("/"));
|
|
1809
|
+
paths.push(
|
|
1810
|
+
...collectTocChapterPaths(
|
|
1811
|
+
item.children,
|
|
1812
|
+
chapterPath
|
|
1813
|
+
)
|
|
1814
|
+
);
|
|
1815
|
+
}
|
|
1816
|
+
return paths;
|
|
1817
|
+
}
|
|
1543
1818
|
|
|
1544
1819
|
// src/query-runtime.ts
|
|
1545
|
-
var
|
|
1820
|
+
var import_wiki_graph_core4 = require("wiki-graph-core");
|
|
1546
1821
|
|
|
1547
1822
|
// src/embedding.ts
|
|
1548
1823
|
var import_ai = require("ai");
|
|
@@ -1715,7 +1990,7 @@ async function createConfiguredEmbeddingProvider() {
|
|
|
1715
1990
|
async function withConfiguredWikimediaResolver(objectUri, operation) {
|
|
1716
1991
|
if (!objectUri.endsWith("/wikipage")) return await operation({});
|
|
1717
1992
|
const config = await loadWikiGraphRuntimeConfig();
|
|
1718
|
-
const resolver = await (0,
|
|
1993
|
+
const resolver = await (0, import_wiki_graph_core4.openWikimediaResolver)(
|
|
1719
1994
|
config.wikimedia === void 0 ? { kind: "local" } : {
|
|
1720
1995
|
endpoint: config.wikimedia.endpoint,
|
|
1721
1996
|
kind: "remote",
|
|
@@ -1730,500 +2005,128 @@ async function withConfiguredWikimediaResolver(objectUri, operation) {
|
|
|
1730
2005
|
}
|
|
1731
2006
|
|
|
1732
2007
|
// src/archive/inspect.ts
|
|
1733
|
-
var
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
2008
|
+
var import_wiki_graph_core5 = require("wiki-graph-core");
|
|
2009
|
+
async function inspectWikiGraphArchive(document, options) {
|
|
2010
|
+
const [allChapters, indexCacheCurrent, summaryWords, ...coverage] = await Promise.all([
|
|
2011
|
+
(0, import_wiki_graph_core5.listChapters)(document),
|
|
2012
|
+
(0, import_wiki_graph_core5.isArchiveSearchIndexCurrent)(document),
|
|
2013
|
+
readSummaryWords(document),
|
|
2014
|
+
document.indexArtifacts.listCoverage("fts"),
|
|
2015
|
+
document.indexArtifacts.listCoverage("embedding-source"),
|
|
2016
|
+
document.indexArtifacts.listCoverage("embedding-summary")
|
|
2017
|
+
]);
|
|
2018
|
+
const chapters = selectChapters(allChapters, options.chapterId);
|
|
2019
|
+
const coverageByKind = {
|
|
2020
|
+
fts: byChapterId(coverage[0]),
|
|
2021
|
+
sourceEmbedding: byChapterId(coverage[1]),
|
|
2022
|
+
summaryEmbedding: byChapterId(coverage[2])
|
|
2023
|
+
};
|
|
2024
|
+
const inspections = await Promise.all(
|
|
2025
|
+
chapters.map(async (chapter) => {
|
|
2026
|
+
const serial = await document.serials.getById(chapter.chapterId);
|
|
2027
|
+
return {
|
|
2028
|
+
capabilities: {
|
|
2029
|
+
knowledgeGraph: {
|
|
2030
|
+
completed: serial?.knowledgeGraphReady === true
|
|
2031
|
+
},
|
|
2032
|
+
readingGraph: { completed: serial?.topologyReady === true },
|
|
2033
|
+
readingSummary: { completed: chapter.stage === "summarized" }
|
|
2034
|
+
},
|
|
2035
|
+
chapter,
|
|
2036
|
+
indexes: {
|
|
2037
|
+
fts: inspectArtifact(
|
|
2038
|
+
"fts",
|
|
2039
|
+
coverageByKind.fts.get(chapter.chapterId)
|
|
2040
|
+
),
|
|
2041
|
+
sourceEmbedding: inspectArtifact(
|
|
2042
|
+
"embedding-source",
|
|
2043
|
+
coverageByKind.sourceEmbedding.get(chapter.chapterId)
|
|
2044
|
+
),
|
|
2045
|
+
summaryEmbedding: inspectArtifact(
|
|
2046
|
+
"embedding-summary",
|
|
2047
|
+
coverageByKind.summaryEmbedding.get(chapter.chapterId)
|
|
2048
|
+
)
|
|
2049
|
+
},
|
|
2050
|
+
revision: serial?.revision ?? 0,
|
|
2051
|
+
summaryWords: summaryWords.get(chapter.chapterId) ?? 0
|
|
2052
|
+
};
|
|
2053
|
+
})
|
|
1744
2054
|
);
|
|
1745
|
-
const
|
|
1746
|
-
const wordSeconds = words * profile.secondsPerWord;
|
|
2055
|
+
const selected = inspections[0];
|
|
1747
2056
|
return {
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
tokens: {
|
|
1754
|
-
cacheableInput: Math.ceil(words * profile.cacheableInputTokenPerWord),
|
|
1755
|
-
input: Math.ceil(words * profile.inputTokenPerWord),
|
|
1756
|
-
output: Math.ceil(words * profile.outputTokenPerWord)
|
|
1757
|
-
}
|
|
2057
|
+
archiveUri: options.archiveUri,
|
|
2058
|
+
chapters: inspections,
|
|
2059
|
+
localIndexCache: { current: indexCacheCurrent },
|
|
2060
|
+
scope: options.chapterId === void 0 ? { type: "archive" } : { chapterId: options.chapterId, type: "chapter" },
|
|
2061
|
+
uri: selected === void 0 || options.chapterId === void 0 ? options.archiveUri : formatLocatedChapterUri(options.archiveUri, selected.chapter)
|
|
1758
2062
|
};
|
|
1759
2063
|
}
|
|
1760
|
-
function
|
|
1761
|
-
if (
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
hints.push({
|
|
1768
|
-
configKey: "request",
|
|
1769
|
-
configValue: recommendedRequest,
|
|
1770
|
-
current: input.concurrent.request,
|
|
1771
|
-
kind: "request",
|
|
1772
|
-
message: "LLM request concurrency can often be higher. Use at least 4; 6-8 is usually faster when the provider allows it.",
|
|
1773
|
-
recommended: recommendedRequest
|
|
1774
|
-
});
|
|
1775
|
-
}
|
|
1776
|
-
if (input.concurrent.job < 4 && input.chapters > 1) {
|
|
1777
|
-
hints.push({
|
|
1778
|
-
configKey: "job",
|
|
1779
|
-
configValue: 4,
|
|
1780
|
-
current: input.concurrent.job,
|
|
1781
|
-
kind: "job",
|
|
1782
|
-
message: "Multiple chapters need work and job concurrency is below 4. Raising it lets chapter jobs run in parallel.",
|
|
1783
|
-
recommended: 4
|
|
1784
|
-
});
|
|
2064
|
+
function selectChapters(chapters, chapterId) {
|
|
2065
|
+
if (chapterId === void 0) return chapters;
|
|
2066
|
+
const selected = chapters.filter(
|
|
2067
|
+
(chapter) => chapter.chapterId === chapterId
|
|
2068
|
+
);
|
|
2069
|
+
if (selected.length === 0) {
|
|
2070
|
+
throw new Error(`Chapter ${chapterId} does not exist.`);
|
|
1785
2071
|
}
|
|
1786
|
-
return
|
|
2072
|
+
return selected;
|
|
1787
2073
|
}
|
|
1788
|
-
function
|
|
1789
|
-
|
|
1790
|
-
return "not configured";
|
|
1791
|
-
}
|
|
1792
|
-
return llm.provider === void 0 ? llm.model : `${llm.provider}/${llm.model}`;
|
|
2074
|
+
function byChapterId(coverage) {
|
|
2075
|
+
return new Map(coverage.map((item) => [item.serialId, item]));
|
|
1793
2076
|
}
|
|
1794
|
-
function
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
}
|
|
1802
|
-
return `${Math.round(minutes / 60)}h`;
|
|
2077
|
+
function inspectArtifact(kind, coverage) {
|
|
2078
|
+
return {
|
|
2079
|
+
current: coverage?.current === true,
|
|
2080
|
+
exists: coverage?.sourceRevision !== void 0,
|
|
2081
|
+
kind,
|
|
2082
|
+
...coverage?.sourceRevision === void 0 ? {} : { sourceRevision: coverage.sourceRevision }
|
|
2083
|
+
};
|
|
1803
2084
|
}
|
|
1804
|
-
function
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
secondsPerWord: 2e-3,
|
|
1825
|
-
wordsPerCall: 1e4
|
|
1826
|
-
};
|
|
1827
|
-
case "knowledge-graph":
|
|
1828
|
-
return {
|
|
1829
|
-
cacheableInputTokenPerWord: 60,
|
|
1830
|
-
inputTokenPerWord: 80,
|
|
1831
|
-
maxSecondsPerCall: 35,
|
|
1832
|
-
minSecondsPerCall: 15,
|
|
1833
|
-
outputTokenPerWord: 25,
|
|
1834
|
-
secondsPerWord: 0.02,
|
|
1835
|
-
wordsPerCall: 35
|
|
1836
|
-
};
|
|
1837
|
-
case "reading-graph":
|
|
1838
|
-
return {
|
|
1839
|
-
cacheableInputTokenPerWord: 20,
|
|
1840
|
-
inputTokenPerWord: 25,
|
|
1841
|
-
maxSecondsPerCall: 45,
|
|
1842
|
-
minSecondsPerCall: 15,
|
|
1843
|
-
outputTokenPerWord: 4,
|
|
1844
|
-
secondsPerWord: 0.01,
|
|
1845
|
-
wordsPerCall: 160
|
|
1846
|
-
};
|
|
1847
|
-
case "reading-summary":
|
|
1848
|
-
return {
|
|
1849
|
-
cacheableInputTokenPerWord: 45,
|
|
1850
|
-
inputTokenPerWord: 55,
|
|
1851
|
-
maxSecondsPerCall: 25,
|
|
1852
|
-
minSecondsPerCall: 10,
|
|
1853
|
-
outputTokenPerWord: 4,
|
|
1854
|
-
secondsPerWord: 0.01,
|
|
1855
|
-
wordsPerCall: 110
|
|
1856
|
-
};
|
|
1857
|
-
}
|
|
2085
|
+
async function readSummaryWords(document) {
|
|
2086
|
+
const rows = await document.readDatabase(
|
|
2087
|
+
async (database) => await database.queryAll(
|
|
2088
|
+
`
|
|
2089
|
+
SELECT chapter_id, COALESCE(SUM(words_count), 0) AS words
|
|
2090
|
+
FROM text_sentence_records
|
|
2091
|
+
WHERE kind = 2
|
|
2092
|
+
GROUP BY chapter_id
|
|
2093
|
+
`,
|
|
2094
|
+
void 0,
|
|
2095
|
+
(row) => ({
|
|
2096
|
+
chapterId: Number(row.chapter_id),
|
|
2097
|
+
words: Number(row.words)
|
|
2098
|
+
})
|
|
2099
|
+
)
|
|
2100
|
+
);
|
|
2101
|
+
return new Map(rows.map((row) => [row.chapterId, row.words]));
|
|
2102
|
+
}
|
|
2103
|
+
function formatLocatedChapterUri(archiveUri, chapter) {
|
|
2104
|
+
return `${archiveUri.replace(/\/+$/u, "")}/${chapter.uri.replace(/^wikg:\/\//u, "")}`;
|
|
1858
2105
|
}
|
|
1859
2106
|
|
|
1860
|
-
// src/archive/
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
const
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
summaryEmbeddingArtifactCoverage
|
|
1871
|
-
] = await Promise.all([
|
|
1872
|
-
readInspectChapters(document, options.chapterId),
|
|
1873
|
-
readSummaryWords(document, options.chapterId),
|
|
1874
|
-
(0, import_wiki_graph_core4.isArchiveSearchIndexCurrent)(document),
|
|
1875
|
-
loadWikiGraphRuntimeConfig(),
|
|
1876
|
-
readIndexArtifactCoverage(document, "fts", options.chapterId),
|
|
1877
|
-
readIndexArtifactCoverage(document, "embedding-source", options.chapterId),
|
|
1878
|
-
readIndexArtifactCoverage(document, "embedding-summary", options.chapterId)
|
|
1879
|
-
]);
|
|
1880
|
-
const selectedChapter = options.chapterId === void 0 ? void 0 : chapters[0];
|
|
1881
|
-
const scopeUri = selectedChapter === void 0 ? archiveUri : formatInspectLocatedChapterUri(archiveUri, selectedChapter);
|
|
1882
|
-
const concurrent = {
|
|
1883
|
-
job: config.concurrent?.job ?? DEFAULT_GENERATION_JOB_CONCURRENCY,
|
|
1884
|
-
request: config.concurrent?.request ?? DEFAULT_GENERATION_REQUEST_CONCURRENCY
|
|
1885
|
-
};
|
|
1886
|
-
const planningModel = formatGenerationPlanningModel(config.llm);
|
|
1887
|
-
const contentChapters = chapters.filter(
|
|
1888
|
-
(chapter) => chapter.stage !== "planned"
|
|
1889
|
-
);
|
|
1890
|
-
const sourceWords = sumWords(contentChapters);
|
|
1891
|
-
const readingGraphCovered = contentChapters.filter(
|
|
1892
|
-
(chapter) => chapter.readingGraphReady
|
|
1893
|
-
);
|
|
1894
|
-
const knowledgeGraphCovered = contentChapters.filter(
|
|
1895
|
-
(chapter) => chapter.knowledgeGraphReady
|
|
1896
|
-
);
|
|
1897
|
-
const summaryCovered = contentChapters.filter(
|
|
1898
|
-
(chapter) => chapter.summaryReady
|
|
1899
|
-
);
|
|
1900
|
-
const ftsArtifactCovered = filterChaptersByCurrentIndexArtifact(
|
|
1901
|
-
contentChapters,
|
|
1902
|
-
ftsArtifactCoverage
|
|
1903
|
-
);
|
|
1904
|
-
const sourceEmbeddingArtifactCovered = filterChaptersByCurrentIndexArtifact(
|
|
1905
|
-
contentChapters,
|
|
1906
|
-
sourceEmbeddingArtifactCoverage
|
|
1907
|
-
);
|
|
1908
|
-
const summaryEmbeddingArtifactCovered = filterChaptersByCurrentIndexArtifact(
|
|
1909
|
-
contentChapters,
|
|
1910
|
-
summaryEmbeddingArtifactCoverage
|
|
1911
|
-
);
|
|
1912
|
-
const queryBlockedContentChapters = contentChapters.filter(
|
|
1913
|
-
(chapter) => !ftsArtifactCovered.includes(chapter) && !sourceEmbeddingArtifactCovered.includes(chapter)
|
|
1914
|
-
);
|
|
1915
|
-
const queryBlockedChapters = queryBlockedContentChapters.map(
|
|
1916
|
-
(chapter) => createInspectChapterReference(archiveUri, chapter)
|
|
1917
|
-
);
|
|
1918
|
-
const queryReady = queryBlockedChapters.length === 0;
|
|
1919
|
-
const improvements = createInspectImprovements({
|
|
1920
|
-
concurrent,
|
|
1921
|
-
contentChapters,
|
|
1922
|
-
indexCacheCurrent,
|
|
1923
|
-
planningModel,
|
|
1924
|
-
queryBlockedChapters: queryBlockedContentChapters,
|
|
1925
|
-
summaryCovered,
|
|
1926
|
-
knowledgeGraphCovered,
|
|
1927
|
-
readingGraphCovered
|
|
2107
|
+
// src/archive/write.ts
|
|
2108
|
+
var import_wiki_graph_core6 = require("wiki-graph-core");
|
|
2109
|
+
async function writeWikiGraphArchiveLocation(location, operation, options = {}) {
|
|
2110
|
+
const cacheOnly = options.searchIndexWritebackPolicy === "cache";
|
|
2111
|
+
const write = async (archiveFile = location.archiveFile) => await new import_wiki_graph_core6.WikiGraphArchiveFile(archiveFile).write(operation, {
|
|
2112
|
+
...cacheOnly ? {} : { derivedStateKeys: [location.archiveKey, location.archivePath] },
|
|
2113
|
+
...options.invalidateContinuationCursors === void 0 ? {} : {
|
|
2114
|
+
invalidateContinuationCursors: options.invalidateContinuationCursors
|
|
2115
|
+
},
|
|
2116
|
+
...options.searchIndexWritebackPolicy === void 0 ? {} : { searchIndexWritebackPolicy: options.searchIndexWritebackPolicy }
|
|
1928
2117
|
});
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
0,
|
|
1932
|
-
...improvements.map((improvement) => improvement.missingChapters ?? 0)
|
|
1933
|
-
),
|
|
1934
|
-
concurrent,
|
|
1935
|
-
hasJobWork: improvements.some(
|
|
1936
|
-
(improvement) => improvement.planning !== void 0
|
|
1937
|
-
),
|
|
1938
|
-
hasRequestWork: improvements.some(
|
|
1939
|
-
(improvement) => improvement.planning !== void 0
|
|
1940
|
-
)
|
|
1941
|
-
});
|
|
1942
|
-
return {
|
|
1943
|
-
archiveUri,
|
|
1944
|
-
uri: scopeUri,
|
|
1945
|
-
scope: options.chapterId === void 0 ? { type: "archive" } : { chapterId: options.chapterId, type: "chapter" },
|
|
1946
|
-
content: {
|
|
1947
|
-
chapters: {
|
|
1948
|
-
content: contentChapters.length,
|
|
1949
|
-
planned: chapters.length - contentChapters.length,
|
|
1950
|
-
total: chapters.length
|
|
1951
|
-
},
|
|
1952
|
-
sourceWords,
|
|
1953
|
-
summaryWords
|
|
1954
|
-
},
|
|
1955
|
-
localIndexCache: {
|
|
1956
|
-
current: indexCacheCurrent,
|
|
1957
|
-
...!queryReady ? {
|
|
1958
|
-
blockedBy: "missing-search-artifacts",
|
|
1959
|
-
impact: "The cache cannot be built until every content chapter has a current FTS or source embedding artifact."
|
|
1960
|
-
} : indexCacheCurrent ? {} : {
|
|
1961
|
-
impact: "The next archive query may need to sync index cache first.",
|
|
1962
|
-
resource: "local CPU/disk time only; no provider calls."
|
|
1963
|
-
},
|
|
1964
|
-
status: !queryReady ? "blocked" : indexCacheCurrent ? "current" : "missing-or-outdated",
|
|
1965
|
-
syncAvailable: queryReady && !indexCacheCurrent
|
|
1966
|
-
},
|
|
1967
|
-
coverage: {
|
|
1968
|
-
ftsIndexArtifact: createInspectCoverage(
|
|
1969
|
-
ftsArtifactCovered,
|
|
1970
|
-
contentChapters
|
|
1971
|
-
),
|
|
1972
|
-
knowledgeGraph: createInspectCoverage(
|
|
1973
|
-
knowledgeGraphCovered,
|
|
1974
|
-
contentChapters
|
|
1975
|
-
),
|
|
1976
|
-
readingGraph: createInspectCoverage(readingGraphCovered, contentChapters),
|
|
1977
|
-
summary: createInspectCoverage(summaryCovered, contentChapters),
|
|
1978
|
-
sourceEmbeddingIndexArtifact: createInspectCoverage(
|
|
1979
|
-
sourceEmbeddingArtifactCovered,
|
|
1980
|
-
contentChapters
|
|
1981
|
-
),
|
|
1982
|
-
summaryEmbeddingIndexArtifact: createInspectCoverage(
|
|
1983
|
-
summaryEmbeddingArtifactCovered,
|
|
1984
|
-
contentChapters
|
|
1985
|
-
)
|
|
1986
|
-
},
|
|
1987
|
-
query: {
|
|
1988
|
-
ready: queryReady
|
|
1989
|
-
},
|
|
1990
|
-
searchArtifacts: {
|
|
1991
|
-
blockedChapters: queryBlockedChapters,
|
|
1992
|
-
...!queryReady ? {
|
|
1993
|
-
resource: "local CPU/disk time only; no provider calls."
|
|
1994
|
-
} : {},
|
|
1995
|
-
ready: queryReady,
|
|
1996
|
-
status: queryReady ? "ready" : "incomplete"
|
|
1997
|
-
},
|
|
1998
|
-
retrievalGuidance: formatRetrievalGuidance({
|
|
1999
|
-
indexCacheCurrent,
|
|
2000
|
-
knowledgeGraphCovered,
|
|
2001
|
-
readingGraphCovered,
|
|
2002
|
-
contentChapters,
|
|
2003
|
-
queryReady,
|
|
2004
|
-
sourceWords
|
|
2005
|
-
}),
|
|
2006
|
-
improvements,
|
|
2007
|
-
performanceHints,
|
|
2008
|
-
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."
|
|
2009
|
-
};
|
|
2010
|
-
}
|
|
2011
|
-
function createInspectChapterReference(archiveUri, chapter) {
|
|
2012
|
-
return {
|
|
2013
|
-
chapterId: chapter.chapterId,
|
|
2014
|
-
locatedUri: formatInspectLocatedChapterUri(archiveUri, chapter),
|
|
2015
|
-
title: chapter.title,
|
|
2016
|
-
uri: chapter.uri
|
|
2017
|
-
};
|
|
2018
|
-
}
|
|
2019
|
-
function formatInspectLocatedChapterUri(archiveUri, chapter) {
|
|
2020
|
-
return `${archiveUri.replace(/\/+$/u, "")}/${chapter.uri.replace(/^wikg:\/\//u, "")}`;
|
|
2021
|
-
}
|
|
2022
|
-
async function readInspectChapters(document, chapterId) {
|
|
2023
|
-
const chapters = chapterId === void 0 ? await (0, import_wiki_graph_core4.listChapters)(document) : (await (0, import_wiki_graph_core4.listChapters)(document)).filter(
|
|
2024
|
-
(chapter) => chapter.chapterId === chapterId
|
|
2025
|
-
);
|
|
2026
|
-
if (chapterId !== void 0 && chapters.length === 0) {
|
|
2027
|
-
throw new Error(`Chapter ${chapterId} does not exist.`);
|
|
2118
|
+
if (location.libraryArchiveTarget === void 0 || cacheOnly || options.refreshLibraryIndex === false) {
|
|
2119
|
+
return await write();
|
|
2028
2120
|
}
|
|
2029
|
-
return await
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
})
|
|
2039
|
-
);
|
|
2040
|
-
}
|
|
2041
|
-
async function readSummaryWords(document, chapterId) {
|
|
2042
|
-
return await document.readDatabase(
|
|
2043
|
-
async (database) => await database.queryOne(
|
|
2044
|
-
`
|
|
2045
|
-
SELECT COALESCE(SUM(words_count), 0) AS words
|
|
2046
|
-
FROM text_sentence_records
|
|
2047
|
-
WHERE kind = 2
|
|
2048
|
-
${chapterId === void 0 ? "" : "AND chapter_id = ?"}
|
|
2049
|
-
`,
|
|
2050
|
-
chapterId === void 0 ? void 0 : [chapterId],
|
|
2051
|
-
(row) => Number(row.words)
|
|
2052
|
-
) ?? 0
|
|
2053
|
-
);
|
|
2054
|
-
}
|
|
2055
|
-
async function readIndexArtifactCoverage(document, kind, chapterId) {
|
|
2056
|
-
const coverage = await document.indexArtifacts.listCoverage(kind);
|
|
2057
|
-
return chapterId === void 0 ? coverage : coverage.filter((item) => item.serialId === chapterId);
|
|
2058
|
-
}
|
|
2059
|
-
function filterChaptersByCurrentIndexArtifact(chapters, coverage) {
|
|
2060
|
-
const currentChapterIds = new Set(
|
|
2061
|
-
coverage.filter((item) => item.current).map((item) => item.serialId)
|
|
2062
|
-
);
|
|
2063
|
-
return chapters.filter((chapter) => currentChapterIds.has(chapter.chapterId));
|
|
2064
|
-
}
|
|
2065
|
-
function createInspectCoverage(covered, total) {
|
|
2066
|
-
const coveredWords = sumWords(covered);
|
|
2067
|
-
const totalWords = sumWords(total);
|
|
2068
|
-
return {
|
|
2069
|
-
coveredChapters: covered.length,
|
|
2070
|
-
coveredWords,
|
|
2071
|
-
percent: formatPercent(coveredWords, totalWords),
|
|
2072
|
-
totalChapters: total.length,
|
|
2073
|
-
totalWords
|
|
2074
|
-
};
|
|
2075
|
-
}
|
|
2076
|
-
function formatRetrievalGuidance(input) {
|
|
2077
|
-
if (input.sourceWords === 0 || input.contentChapters.length === 0) {
|
|
2078
|
-
return [
|
|
2079
|
-
"Source content: empty.",
|
|
2080
|
-
"Add source text before using query coverage or graph-based retrieval."
|
|
2081
|
-
];
|
|
2082
|
-
}
|
|
2083
|
-
const lines = [
|
|
2084
|
-
input.queryReady ? `Query: available; local index cache is ${input.indexCacheCurrent ? "current" : "missing or outdated and can be synced from artifacts"}.` : "Query: unavailable until every content chapter has a current FTS or source embedding artifact."
|
|
2085
|
-
];
|
|
2086
|
-
lines.push(
|
|
2087
|
-
formatObjectSearchGuidance(
|
|
2088
|
-
"Reading Graph object retrieval",
|
|
2089
|
-
input.readingGraphCovered,
|
|
2090
|
-
input.contentChapters
|
|
2091
|
-
)
|
|
2092
|
-
);
|
|
2093
|
-
lines.push(
|
|
2094
|
-
formatObjectSearchGuidance(
|
|
2095
|
-
"Entity/triple retrieval",
|
|
2096
|
-
input.knowledgeGraphCovered,
|
|
2097
|
-
input.contentChapters
|
|
2098
|
-
)
|
|
2099
|
-
);
|
|
2100
|
-
return lines;
|
|
2101
|
-
}
|
|
2102
|
-
function formatObjectSearchGuidance(label, covered, total) {
|
|
2103
|
-
const coveredWords = sumWords(covered);
|
|
2104
|
-
const totalWords = sumWords(total);
|
|
2105
|
-
const ratio = totalWords === 0 ? 0 : coveredWords / totalWords;
|
|
2106
|
-
const coverage = formatPercent(coveredWords, totalWords);
|
|
2107
|
-
if (ratio >= 1) {
|
|
2108
|
-
return `${label}: covers all source content; it can represent the full scope for object retrieval.`;
|
|
2109
|
-
}
|
|
2110
|
-
if (ratio >= 0.9) {
|
|
2111
|
-
return `${label}: covers ${coverage}; use it as the main path, but source --query is needed for uncovered content.`;
|
|
2112
|
-
}
|
|
2113
|
-
if (ratio >= 0.5) {
|
|
2114
|
-
return `${label}: covers ${coverage}; use it as leads, not as a full-scope substitute for source --query.`;
|
|
2115
|
-
}
|
|
2116
|
-
return `${label}: covers ${coverage}; build missing graph coverage before relying on object retrieval.`;
|
|
2117
|
-
}
|
|
2118
|
-
function createInspectImprovements(input) {
|
|
2119
|
-
const improvements = [];
|
|
2120
|
-
if (input.contentChapters.length === 0) {
|
|
2121
|
-
improvements.push({
|
|
2122
|
-
kind: "add-source",
|
|
2123
|
-
recommendation: "No source content is available yet; add or import source text before graph or summary generation.",
|
|
2124
|
-
title: "Add source content"
|
|
2125
|
-
});
|
|
2126
|
-
return improvements;
|
|
2127
|
-
}
|
|
2128
|
-
if (input.queryBlockedChapters.length > 0) {
|
|
2129
|
-
improvements.push({
|
|
2130
|
-
kind: "build",
|
|
2131
|
-
missingChapters: input.queryBlockedChapters.length,
|
|
2132
|
-
missingWords: sumWords(input.queryBlockedChapters),
|
|
2133
|
-
recommendation: "Build local FTS artifacts to make this scope queryable. This does not call a provider.",
|
|
2134
|
-
task: "index-fts",
|
|
2135
|
-
title: "Enable query with local FTS"
|
|
2136
|
-
});
|
|
2137
|
-
} else if (!input.indexCacheCurrent) {
|
|
2138
|
-
improvements.push({
|
|
2139
|
-
kind: "sync-index",
|
|
2140
|
-
recommendation: "Sync the index cache from chapter index artifacts so query starts without a lazy cache rebuild.",
|
|
2141
|
-
title: "Sync index cache"
|
|
2142
|
-
});
|
|
2143
|
-
}
|
|
2144
|
-
improvements.push(
|
|
2145
|
-
...createGraphImprovement({
|
|
2146
|
-
concurrent: input.concurrent,
|
|
2147
|
-
covered: input.readingGraphCovered,
|
|
2148
|
-
planningModel: input.planningModel,
|
|
2149
|
-
task: "reading-graph",
|
|
2150
|
-
title: "Complete Reading Graph coverage",
|
|
2151
|
-
total: input.contentChapters
|
|
2152
|
-
})
|
|
2153
|
-
);
|
|
2154
|
-
improvements.push(
|
|
2155
|
-
...createGraphImprovement({
|
|
2156
|
-
concurrent: input.concurrent,
|
|
2157
|
-
covered: input.knowledgeGraphCovered,
|
|
2158
|
-
planningModel: input.planningModel,
|
|
2159
|
-
task: "knowledge-graph",
|
|
2160
|
-
title: "Complete Knowledge Graph coverage",
|
|
2161
|
-
total: input.contentChapters
|
|
2162
|
-
})
|
|
2163
|
-
);
|
|
2164
|
-
improvements.push(
|
|
2165
|
-
...createGraphImprovement({
|
|
2166
|
-
concurrent: input.concurrent,
|
|
2167
|
-
covered: input.summaryCovered,
|
|
2168
|
-
planningModel: input.planningModel,
|
|
2169
|
-
task: "reading-summary",
|
|
2170
|
-
title: "Complete Summary coverage",
|
|
2171
|
-
total: input.contentChapters
|
|
2172
|
-
})
|
|
2173
|
-
);
|
|
2174
|
-
return improvements;
|
|
2175
|
-
}
|
|
2176
|
-
function createGraphImprovement(input) {
|
|
2177
|
-
const coveredIds = new Set(input.covered.map((chapter) => chapter.chapterId));
|
|
2178
|
-
const missing = input.total.filter(
|
|
2179
|
-
(chapter) => !coveredIds.has(chapter.chapterId)
|
|
2180
|
-
);
|
|
2181
|
-
if (missing.length === 0) {
|
|
2182
|
-
return [];
|
|
2183
|
-
}
|
|
2184
|
-
const missingWords = sumWords(missing);
|
|
2185
|
-
return [
|
|
2186
|
-
{
|
|
2187
|
-
kind: "build",
|
|
2188
|
-
missingChapters: missing.length,
|
|
2189
|
-
missingWords,
|
|
2190
|
-
planning: planGenerationTask(
|
|
2191
|
-
input.task,
|
|
2192
|
-
missingWords,
|
|
2193
|
-
missing.length,
|
|
2194
|
-
input.concurrent,
|
|
2195
|
-
input.planningModel
|
|
2196
|
-
),
|
|
2197
|
-
recommendation: formatImprovementRecommendation(
|
|
2198
|
-
input.covered,
|
|
2199
|
-
input.total,
|
|
2200
|
-
missingWords
|
|
2201
|
-
),
|
|
2202
|
-
task: input.task,
|
|
2203
|
-
title: input.title
|
|
2204
|
-
}
|
|
2205
|
-
];
|
|
2206
|
-
}
|
|
2207
|
-
function formatImprovementRecommendation(covered, total, missingWords) {
|
|
2208
|
-
const totalWords = sumWords(total);
|
|
2209
|
-
const coveredWords = sumWords(covered);
|
|
2210
|
-
if (totalWords === 0) {
|
|
2211
|
-
return "No source content is available.";
|
|
2212
|
-
}
|
|
2213
|
-
if (total.length === 1 || coveredWords / totalWords >= 0.9 || missingWords <= 1e3) {
|
|
2214
|
-
return "Queue the full scope to finish the remaining gap.";
|
|
2215
|
-
}
|
|
2216
|
-
return "Queue selected chapters first if only part of the scope matters.";
|
|
2217
|
-
}
|
|
2218
|
-
function sumWords(chapters) {
|
|
2219
|
-
return chapters.reduce((total, chapter) => total + chapter.words, 0);
|
|
2220
|
-
}
|
|
2221
|
-
function formatPercent(numerator, denominator) {
|
|
2222
|
-
if (denominator === 0) {
|
|
2223
|
-
return "n/a";
|
|
2224
|
-
}
|
|
2225
|
-
const percent = numerator / denominator * 100;
|
|
2226
|
-
return `${Number.isInteger(percent) ? percent.toFixed(0) : percent.toFixed(1)}%`;
|
|
2121
|
+
return await (0, import_wiki_graph_core6.writeWikiGraphLibraryArchive)({
|
|
2122
|
+
additionalDerivedStateKeys: [location.archiveKey, location.archivePath],
|
|
2123
|
+
...options.invalidateContinuationCursors === void 0 ? {} : {
|
|
2124
|
+
invalidateContinuationCursors: options.invalidateContinuationCursors
|
|
2125
|
+
},
|
|
2126
|
+
...options.onIndexSyncError === void 0 ? {} : { onIndexSyncError: options.onIndexSyncError },
|
|
2127
|
+
operation: async (archiveFile) => await write(archiveFile),
|
|
2128
|
+
target: location.libraryArchiveTarget
|
|
2129
|
+
});
|
|
2227
2130
|
}
|
|
2228
2131
|
|
|
2229
2132
|
// src/archive/archive.ts
|
|
@@ -2243,13 +2146,13 @@ var WikiGraphArchiveManager = class {
|
|
|
2243
2146
|
}
|
|
2244
2147
|
async create(options) {
|
|
2245
2148
|
return await this.#runtime.run(async () => {
|
|
2246
|
-
const path =
|
|
2149
|
+
const path = await assertStandaloneWikiGraphArchivePath(options.path);
|
|
2247
2150
|
if (options.replace !== true && await nodePathExists(path)) {
|
|
2248
2151
|
throw new WikiGraphArchiveExistsError(path);
|
|
2249
2152
|
}
|
|
2250
|
-
const outputPath = (0,
|
|
2251
|
-
(0,
|
|
2252
|
-
`.${(0,
|
|
2153
|
+
const outputPath = (0, import_path5.join)(
|
|
2154
|
+
(0, import_path5.dirname)(path),
|
|
2155
|
+
`.${(0, import_path5.basename)(path)}.${(0, import_crypto2.randomUUID)()}.tmp.wikg`
|
|
2253
2156
|
);
|
|
2254
2157
|
try {
|
|
2255
2158
|
if (options.importPath === void 0) {
|
|
@@ -2263,10 +2166,10 @@ var WikiGraphArchiveManager = class {
|
|
|
2263
2166
|
});
|
|
2264
2167
|
}
|
|
2265
2168
|
if (options.replace === true) {
|
|
2266
|
-
await (0,
|
|
2169
|
+
await (0, import_promises4.rename)(outputPath, path);
|
|
2267
2170
|
} else {
|
|
2268
2171
|
try {
|
|
2269
|
-
await (0,
|
|
2172
|
+
await (0, import_promises4.link)(outputPath, path);
|
|
2270
2173
|
} catch (error) {
|
|
2271
2174
|
if (isNodeEEXISTError(error)) {
|
|
2272
2175
|
throw new WikiGraphArchiveExistsError(path);
|
|
@@ -2274,15 +2177,15 @@ var WikiGraphArchiveManager = class {
|
|
|
2274
2177
|
throw error;
|
|
2275
2178
|
}
|
|
2276
2179
|
}
|
|
2277
|
-
return { locatedUri: (0,
|
|
2180
|
+
return { locatedUri: (0, import_wiki_graph_core7.formatLocatedWikiGraphUri)(path), path };
|
|
2278
2181
|
} finally {
|
|
2279
|
-
await (0,
|
|
2182
|
+
await (0, import_promises4.rm)(outputPath, { force: true, recursive: true });
|
|
2280
2183
|
}
|
|
2281
2184
|
}, options.signal);
|
|
2282
2185
|
}
|
|
2283
|
-
async open(
|
|
2186
|
+
async open(target, options = {}) {
|
|
2284
2187
|
const location = await this.#runtime.run(
|
|
2285
|
-
async () => await resolveWikiGraphArchiveLocation(
|
|
2188
|
+
async () => await resolveWikiGraphArchiveLocation(target),
|
|
2286
2189
|
options.signal
|
|
2287
2190
|
);
|
|
2288
2191
|
return new WikiGraphArchiveHandle(this.#runtime, location);
|
|
@@ -2305,14 +2208,17 @@ var WikiGraphArchiveHandle = class {
|
|
|
2305
2208
|
return this.#location.locatedUri;
|
|
2306
2209
|
}
|
|
2307
2210
|
get objectUri() {
|
|
2308
|
-
return (0,
|
|
2211
|
+
return (0, import_wiki_graph_core7.parseLocatedWikiGraphUri)(this.#location.locatedUri).objectUri ?? "wikg://";
|
|
2309
2212
|
}
|
|
2310
2213
|
get path() {
|
|
2311
2214
|
return this.#location.archivePath;
|
|
2312
2215
|
}
|
|
2216
|
+
get target() {
|
|
2217
|
+
return this.#location.target;
|
|
2218
|
+
}
|
|
2313
2219
|
async inspect(options = {}) {
|
|
2314
2220
|
return await this.#readDocument(
|
|
2315
|
-
async (document) => await
|
|
2221
|
+
async (document) => await inspectWikiGraphArchive(document, {
|
|
2316
2222
|
archiveUri: this.#location.publicArchiveUri ?? this.locatedUri,
|
|
2317
2223
|
...options.chapterId === void 0 ? {} : { chapterId: options.chapterId }
|
|
2318
2224
|
}),
|
|
@@ -2331,7 +2237,7 @@ var WikiGraphArchiveHandle = class {
|
|
|
2331
2237
|
...chapters === void 0 ? {} : { chapters },
|
|
2332
2238
|
...embeddingProvider === void 0 ? {} : { embeddingProvider }
|
|
2333
2239
|
});
|
|
2334
|
-
return await (0,
|
|
2240
|
+
return await (0, import_wiki_graph_core7.findArchiveObjects)(document, query, {
|
|
2335
2241
|
...withoutOperationAndScope(options),
|
|
2336
2242
|
archiveKey: this.archiveKey,
|
|
2337
2243
|
...chapters === void 0 ? {} : { chapters },
|
|
@@ -2346,14 +2252,14 @@ var WikiGraphArchiveHandle = class {
|
|
|
2346
2252
|
}
|
|
2347
2253
|
async list(options = {}) {
|
|
2348
2254
|
return await this.#readDocument(async (document) => {
|
|
2349
|
-
if ((0,
|
|
2350
|
-
return await (0,
|
|
2255
|
+
if ((0, import_wiki_graph_core7.isSourceLocatorScopeUri)(this.objectUri)) {
|
|
2256
|
+
return await (0, import_wiki_graph_core7.listArchiveSourceLocators)(document, this.objectUri, {
|
|
2351
2257
|
...options.cursor === void 0 ? {} : { cursor: options.cursor },
|
|
2352
2258
|
...options.limit === void 0 ? {} : { limit: options.limit }
|
|
2353
2259
|
});
|
|
2354
2260
|
}
|
|
2355
2261
|
const chapters = await this.#resolveScope(document, options);
|
|
2356
|
-
return await (0,
|
|
2262
|
+
return await (0, import_wiki_graph_core7.listArchiveCollection)(document, {
|
|
2357
2263
|
...withoutOperationAndScope(options),
|
|
2358
2264
|
...chapters === void 0 ? {} : { chapters }
|
|
2359
2265
|
});
|
|
@@ -2381,8 +2287,8 @@ var WikiGraphArchiveHandle = class {
|
|
|
2381
2287
|
async getSearchIndexStatus(options = {}) {
|
|
2382
2288
|
return await this.#readDocument(
|
|
2383
2289
|
async (document) => ({
|
|
2384
|
-
capabilities: await (0,
|
|
2385
|
-
current: await (0,
|
|
2290
|
+
capabilities: await (0, import_wiki_graph_core7.readSearchIndexCapabilityStatus)(document),
|
|
2291
|
+
current: await (0, import_wiki_graph_core7.isArchiveSearchIndexCurrent)(document)
|
|
2386
2292
|
}),
|
|
2387
2293
|
options
|
|
2388
2294
|
);
|
|
@@ -2390,14 +2296,14 @@ var WikiGraphArchiveHandle = class {
|
|
|
2390
2296
|
async syncSearchIndex(options = {}) {
|
|
2391
2297
|
const rebuilt = await this.#writeDocument(
|
|
2392
2298
|
async (document) => {
|
|
2393
|
-
const scope = options.skipUnindexed === true ? { chapters: await (0,
|
|
2299
|
+
const scope = options.skipUnindexed === true ? { chapters: await (0, import_wiki_graph_core7.listArchiveQueryableChapterIds)(document) } : {};
|
|
2394
2300
|
if (scope.chapters?.length === 0) {
|
|
2395
2301
|
throw new Error(
|
|
2396
2302
|
"Wiki Graph index cache is not ready. No chapters have a current FTS artifact or source embedding artifact."
|
|
2397
2303
|
);
|
|
2398
2304
|
}
|
|
2399
|
-
if (await (0,
|
|
2400
|
-
await (0,
|
|
2305
|
+
if (await (0, import_wiki_graph_core7.isArchiveSearchIndexCurrent)(document, scope)) return false;
|
|
2306
|
+
await (0, import_wiki_graph_core7.rebuildArchiveSearchIndex)(document, options.onProgress, scope);
|
|
2401
2307
|
return true;
|
|
2402
2308
|
},
|
|
2403
2309
|
{
|
|
@@ -2406,7 +2312,7 @@ var WikiGraphArchiveHandle = class {
|
|
|
2406
2312
|
}
|
|
2407
2313
|
);
|
|
2408
2314
|
await this.#runtime.run(
|
|
2409
|
-
async () => await (0,
|
|
2315
|
+
async () => await (0, import_wiki_graph_core7.deleteArchiveSearchSessions)(this.path),
|
|
2410
2316
|
options.signal
|
|
2411
2317
|
);
|
|
2412
2318
|
return { rebuilt };
|
|
@@ -2429,21 +2335,21 @@ var WikiGraphArchiveHandle = class {
|
|
|
2429
2335
|
}
|
|
2430
2336
|
);
|
|
2431
2337
|
await this.#runtime.run(
|
|
2432
|
-
async () => await (0,
|
|
2338
|
+
async () => await (0, import_wiki_graph_core7.deleteArchiveSearchSessions)(this.path),
|
|
2433
2339
|
options.signal
|
|
2434
2340
|
);
|
|
2435
2341
|
return status;
|
|
2436
2342
|
}
|
|
2437
2343
|
async listChapters(options = {}) {
|
|
2438
2344
|
return await this.#readDocument(
|
|
2439
|
-
async (document) => await (0,
|
|
2345
|
+
async (document) => await (0, import_wiki_graph_core7.listChapters)(document),
|
|
2440
2346
|
options
|
|
2441
2347
|
);
|
|
2442
2348
|
}
|
|
2443
2349
|
async getChapter(path, options = {}) {
|
|
2444
2350
|
return await this.#readDocument(async (document) => {
|
|
2445
|
-
const chapterId = await (0,
|
|
2446
|
-
return requireChapter(await (0,
|
|
2351
|
+
const chapterId = await (0, import_wiki_graph_core7.resolveChapterPathReadonly)(document, path);
|
|
2352
|
+
return requireChapter(await (0, import_wiki_graph_core7.listChapters)(document), chapterId);
|
|
2447
2353
|
}, options);
|
|
2448
2354
|
}
|
|
2449
2355
|
async addChapter(options) {
|
|
@@ -2452,17 +2358,17 @@ var WikiGraphArchiveHandle = class {
|
|
|
2452
2358
|
document,
|
|
2453
2359
|
options.parentPath
|
|
2454
2360
|
);
|
|
2455
|
-
await (0,
|
|
2361
|
+
await (0, import_wiki_graph_core7.assertNoActiveBuildJobConflicts)({
|
|
2456
2362
|
archive: this.#location.archiveFile,
|
|
2457
2363
|
operation: "Adding chapter",
|
|
2458
2364
|
scope: { kind: "archive" }
|
|
2459
2365
|
});
|
|
2460
|
-
let details = await (0,
|
|
2366
|
+
let details = await (0, import_wiki_graph_core7.addChapter)(document, {
|
|
2461
2367
|
...parentChapterId === void 0 ? {} : { parentChapterId },
|
|
2462
2368
|
...options.title === void 0 ? {} : { title: options.title }
|
|
2463
2369
|
});
|
|
2464
2370
|
if (options.source !== void 0) {
|
|
2465
|
-
details = await (0,
|
|
2371
|
+
details = await (0, import_wiki_graph_core7.setChapterSource)(
|
|
2466
2372
|
document,
|
|
2467
2373
|
details.chapterId,
|
|
2468
2374
|
asTextStream(options.source)
|
|
@@ -2473,7 +2379,7 @@ var WikiGraphArchiveHandle = class {
|
|
|
2473
2379
|
}
|
|
2474
2380
|
async getChapterArtifact(path, kind) {
|
|
2475
2381
|
return await this.#readDocument(async (document) => {
|
|
2476
|
-
const chapterId = await (0,
|
|
2382
|
+
const chapterId = await (0, import_wiki_graph_core7.resolveChapterPathReadonly)(document, path);
|
|
2477
2383
|
const [artifact, revision] = await Promise.all([
|
|
2478
2384
|
document.indexArtifacts.get(chapterId, kind),
|
|
2479
2385
|
document.serials.getRevision(chapterId)
|
|
@@ -2496,25 +2402,25 @@ var WikiGraphArchiveHandle = class {
|
|
|
2496
2402
|
}
|
|
2497
2403
|
async deleteChapterArtifact(path, kind) {
|
|
2498
2404
|
return await this.#writeDocument(async (document) => {
|
|
2499
|
-
const chapterId = await (0,
|
|
2405
|
+
const chapterId = await (0, import_wiki_graph_core7.resolveChapterPathReadonly)(document, path);
|
|
2500
2406
|
await document.indexArtifacts.delete(chapterId, kind);
|
|
2501
2407
|
return { chapterId, deleted: true, kind };
|
|
2502
2408
|
});
|
|
2503
2409
|
}
|
|
2504
2410
|
async moveChapter(path, options) {
|
|
2505
2411
|
return await this.#writeDocument(async (document) => {
|
|
2506
|
-
const chapterId = await (0,
|
|
2412
|
+
const chapterId = await (0, import_wiki_graph_core7.resolveChapterPathReadonly)(document, path);
|
|
2507
2413
|
const [afterChapterId, beforeChapterId, parentChapterId] = await Promise.all([
|
|
2508
2414
|
resolveOptionalChapterPath(document, options.afterPath),
|
|
2509
2415
|
resolveOptionalChapterPath(document, options.beforePath),
|
|
2510
2416
|
resolveOptionalChapterPath(document, options.parentPath)
|
|
2511
2417
|
]);
|
|
2512
|
-
await (0,
|
|
2418
|
+
await (0, import_wiki_graph_core7.assertNoActiveBuildJobConflicts)({
|
|
2513
2419
|
archive: this.#location.archiveFile,
|
|
2514
2420
|
operation: "Moving chapter",
|
|
2515
2421
|
scope: { kind: "archive" }
|
|
2516
2422
|
});
|
|
2517
|
-
return await (0,
|
|
2423
|
+
return await (0, import_wiki_graph_core7.moveChapter)(document, chapterId, {
|
|
2518
2424
|
...afterChapterId === void 0 ? {} : { afterChapterId },
|
|
2519
2425
|
...beforeChapterId === void 0 ? {} : { beforeChapterId },
|
|
2520
2426
|
...parentChapterId === void 0 ? {} : { parentChapterId },
|
|
@@ -2526,35 +2432,35 @@ var WikiGraphArchiveHandle = class {
|
|
|
2526
2432
|
}
|
|
2527
2433
|
async removeChapter(path, recursive = false) {
|
|
2528
2434
|
await this.#writeDocument(async (document) => {
|
|
2529
|
-
const chapterId = await (0,
|
|
2530
|
-
await (0,
|
|
2435
|
+
const chapterId = await (0, import_wiki_graph_core7.resolveChapterPathReadonly)(document, path);
|
|
2436
|
+
await (0, import_wiki_graph_core7.assertNoActiveBuildJobConflicts)({
|
|
2531
2437
|
archive: this.#location.archiveFile,
|
|
2532
2438
|
operation: "Removing chapter",
|
|
2533
2439
|
scope: { kind: "archive" }
|
|
2534
2440
|
});
|
|
2535
|
-
await (0,
|
|
2441
|
+
await (0, import_wiki_graph_core7.removeChapter)(document, chapterId, { recursive });
|
|
2536
2442
|
});
|
|
2537
2443
|
}
|
|
2538
2444
|
async resetChapter(path, stage) {
|
|
2539
2445
|
return await this.#writeDocument(async (document) => {
|
|
2540
|
-
const chapterId = await (0,
|
|
2446
|
+
const chapterId = await (0, import_wiki_graph_core7.resolveChapterPathReadonly)(document, path);
|
|
2541
2447
|
await assertChapterResetAllowed(
|
|
2542
2448
|
this.#location.archiveFile,
|
|
2543
2449
|
chapterId,
|
|
2544
2450
|
stage
|
|
2545
2451
|
);
|
|
2546
|
-
return await (0,
|
|
2452
|
+
return await (0, import_wiki_graph_core7.resetChapter)(document, chapterId, stage);
|
|
2547
2453
|
});
|
|
2548
2454
|
}
|
|
2549
2455
|
async setChapterSource(path, source, options = {}) {
|
|
2550
2456
|
return await this.#writeDocument(async (document) => {
|
|
2551
|
-
const chapterId = await (0,
|
|
2552
|
-
await (0,
|
|
2457
|
+
const chapterId = await (0, import_wiki_graph_core7.resolveChapterPathReadonly)(document, path);
|
|
2458
|
+
await (0, import_wiki_graph_core7.assertNoActiveBuildJobs)({
|
|
2553
2459
|
archive: this.#location.archiveFile,
|
|
2554
2460
|
chapterIds: [chapterId],
|
|
2555
2461
|
operation: "Setting chapter source"
|
|
2556
2462
|
});
|
|
2557
|
-
return await (0,
|
|
2463
|
+
return await (0, import_wiki_graph_core7.setChapterSource)(
|
|
2558
2464
|
document,
|
|
2559
2465
|
chapterId,
|
|
2560
2466
|
asTextStream(source),
|
|
@@ -2564,43 +2470,43 @@ var WikiGraphArchiveHandle = class {
|
|
|
2564
2470
|
}
|
|
2565
2471
|
async setChapterSummary(path, summary) {
|
|
2566
2472
|
return await this.#writeDocument(async (document) => {
|
|
2567
|
-
const chapterId = await (0,
|
|
2568
|
-
await (0,
|
|
2473
|
+
const chapterId = await (0, import_wiki_graph_core7.resolveChapterPathReadonly)(document, path);
|
|
2474
|
+
await (0, import_wiki_graph_core7.assertNoActiveBuildJobs)({
|
|
2569
2475
|
archive: this.#location.archiveFile,
|
|
2570
2476
|
chapterIds: [chapterId],
|
|
2571
2477
|
operation: "Setting chapter summary",
|
|
2572
2478
|
requiresTarget: "reading-summary"
|
|
2573
2479
|
});
|
|
2574
|
-
return await (0,
|
|
2480
|
+
return await (0, import_wiki_graph_core7.setChapterSummary)(document, chapterId, summary);
|
|
2575
2481
|
});
|
|
2576
2482
|
}
|
|
2577
2483
|
async setChapterTitle(path, title) {
|
|
2578
2484
|
return await this.#writeDocument(async (document) => {
|
|
2579
|
-
const chapterId = await (0,
|
|
2580
|
-
await (0,
|
|
2485
|
+
const chapterId = await (0, import_wiki_graph_core7.resolveChapterPathReadonly)(document, path);
|
|
2486
|
+
await (0, import_wiki_graph_core7.assertNoActiveBuildJobs)({
|
|
2581
2487
|
archive: this.#location.archiveFile,
|
|
2582
2488
|
chapterIds: [chapterId],
|
|
2583
2489
|
operation: "Setting chapter title"
|
|
2584
2490
|
});
|
|
2585
|
-
return await (0,
|
|
2491
|
+
return await (0, import_wiki_graph_core7.setChapterTitle)(document, chapterId, title);
|
|
2586
2492
|
});
|
|
2587
2493
|
}
|
|
2588
2494
|
async getChapterTree() {
|
|
2589
2495
|
return await this.#readDocument(
|
|
2590
|
-
async (document) => await (0,
|
|
2496
|
+
async (document) => await (0, import_wiki_graph_core7.getChapterTree)(document)
|
|
2591
2497
|
);
|
|
2592
2498
|
}
|
|
2593
2499
|
async applyChapterTree(tree, options = {}) {
|
|
2594
2500
|
return await this.#writeDocument(
|
|
2595
2501
|
async (document) => {
|
|
2596
2502
|
if (options.dryRun !== true) {
|
|
2597
|
-
await (0,
|
|
2503
|
+
await (0, import_wiki_graph_core7.assertNoActiveBuildJobConflicts)({
|
|
2598
2504
|
archive: this.#location.archiveFile,
|
|
2599
2505
|
operation: "Changing chapter tree",
|
|
2600
2506
|
scope: { kind: "archive" }
|
|
2601
2507
|
});
|
|
2602
2508
|
}
|
|
2603
|
-
return await (0,
|
|
2509
|
+
return await (0, import_wiki_graph_core7.applyChapterTree)(document, tree, {
|
|
2604
2510
|
dryRun: options.dryRun ?? false
|
|
2605
2511
|
});
|
|
2606
2512
|
},
|
|
@@ -2612,8 +2518,8 @@ var WikiGraphArchiveHandle = class {
|
|
|
2612
2518
|
async () => await withConfiguredWikimediaResolver(
|
|
2613
2519
|
objectUri,
|
|
2614
2520
|
async (wikimediaOptions) => await this.#readDocument(
|
|
2615
|
-
async (document) => await (0,
|
|
2616
|
-
...
|
|
2521
|
+
async (document) => await (0, import_wiki_graph_core7.readArchivePage)(document, objectUri, {
|
|
2522
|
+
...options,
|
|
2617
2523
|
...wikimediaOptions
|
|
2618
2524
|
}),
|
|
2619
2525
|
options
|
|
@@ -2626,7 +2532,7 @@ var WikiGraphArchiveHandle = class {
|
|
|
2626
2532
|
if (options.query === void 0) {
|
|
2627
2533
|
return await this.#readDocument(async (document) => {
|
|
2628
2534
|
const chapters = await this.#resolveScope(document, {});
|
|
2629
|
-
return await (0,
|
|
2535
|
+
return await (0, import_wiki_graph_core7.listRelatedArchiveObjects)(document, objectUri, {
|
|
2630
2536
|
...withoutOperation(options),
|
|
2631
2537
|
...chapters === void 0 ? {} : { chapters }
|
|
2632
2538
|
});
|
|
@@ -2643,7 +2549,7 @@ var WikiGraphArchiveHandle = class {
|
|
|
2643
2549
|
...chapters === void 0 ? {} : { chapters },
|
|
2644
2550
|
...embeddingProvider === void 0 ? {} : { embeddingProvider }
|
|
2645
2551
|
});
|
|
2646
|
-
return await (0,
|
|
2552
|
+
return await (0, import_wiki_graph_core7.listRelatedArchiveObjects)(document, objectUri, {
|
|
2647
2553
|
...withoutOperation(options),
|
|
2648
2554
|
...chapters === void 0 ? {} : { chapters }
|
|
2649
2555
|
});
|
|
@@ -2658,7 +2564,7 @@ var WikiGraphArchiveHandle = class {
|
|
|
2658
2564
|
if (options.query === void 0) {
|
|
2659
2565
|
return await this.#readDocument(async (document) => {
|
|
2660
2566
|
const chapters = await this.#resolveScope(document, {});
|
|
2661
|
-
return await (0,
|
|
2567
|
+
return await (0, import_wiki_graph_core7.listArchiveEvidence)(document, objectUri, {
|
|
2662
2568
|
...withoutOperation(options),
|
|
2663
2569
|
...chapters === void 0 ? {} : { chapters }
|
|
2664
2570
|
});
|
|
@@ -2675,7 +2581,7 @@ var WikiGraphArchiveHandle = class {
|
|
|
2675
2581
|
...chapters === void 0 ? {} : { chapters },
|
|
2676
2582
|
...embeddingProvider === void 0 ? {} : { embeddingProvider }
|
|
2677
2583
|
});
|
|
2678
|
-
return await (0,
|
|
2584
|
+
return await (0, import_wiki_graph_core7.listArchiveEvidence)(document, objectUri, {
|
|
2679
2585
|
...withoutOperation(options),
|
|
2680
2586
|
...chapters === void 0 ? {} : { chapters }
|
|
2681
2587
|
});
|
|
@@ -2688,7 +2594,7 @@ var WikiGraphArchiveHandle = class {
|
|
|
2688
2594
|
}
|
|
2689
2595
|
async pack(objectUri = this.objectUri, budget = 5e3, options = {}) {
|
|
2690
2596
|
return await this.#readDocument(
|
|
2691
|
-
async (document) => await (0,
|
|
2597
|
+
async (document) => await (0, import_wiki_graph_core7.packArchiveContext)(document, objectUri, budget),
|
|
2692
2598
|
options
|
|
2693
2599
|
);
|
|
2694
2600
|
}
|
|
@@ -2711,7 +2617,7 @@ var WikiGraphArchiveHandle = class {
|
|
|
2711
2617
|
}, options);
|
|
2712
2618
|
}
|
|
2713
2619
|
async readCover(options = {}) {
|
|
2714
|
-
const app = new
|
|
2620
|
+
const app = new import_wiki_graph_core7.WikiGraph({});
|
|
2715
2621
|
return await this.#runtime.run(
|
|
2716
2622
|
async () => await app.openSession(
|
|
2717
2623
|
this.#location.archiveFile,
|
|
@@ -2759,7 +2665,7 @@ var WikiGraphArchiveHandle = class {
|
|
|
2759
2665
|
}
|
|
2760
2666
|
async #readDocument(operation, options = {}) {
|
|
2761
2667
|
return await this.#runtime.run(
|
|
2762
|
-
async () => await new
|
|
2668
|
+
async () => await new import_wiki_graph_core7.WikiGraphArchiveFile(this.#location.archiveFile).readDocument(
|
|
2763
2669
|
operation
|
|
2764
2670
|
),
|
|
2765
2671
|
options.signal
|
|
@@ -2767,17 +2673,13 @@ var WikiGraphArchiveHandle = class {
|
|
|
2767
2673
|
}
|
|
2768
2674
|
async #writeDocument(operation, options = {}) {
|
|
2769
2675
|
return await this.#runtime.run(async () => {
|
|
2770
|
-
|
|
2771
|
-
|
|
2772
|
-
|
|
2676
|
+
return await writeWikiGraphArchiveLocation(this.#location, operation, {
|
|
2677
|
+
...options.onIndexSyncError === void 0 ? {} : { onIndexSyncError: options.onIndexSyncError },
|
|
2678
|
+
...options.refreshLibraryIndex === void 0 ? {} : { refreshLibraryIndex: options.refreshLibraryIndex },
|
|
2773
2679
|
...options.searchIndexWritebackPolicy === void 0 ? {} : {
|
|
2774
2680
|
searchIndexWritebackPolicy: options.searchIndexWritebackPolicy
|
|
2775
2681
|
}
|
|
2776
2682
|
});
|
|
2777
|
-
if (options.refreshLibraryIndex !== false) {
|
|
2778
|
-
await this.#refreshLibraryIndex(options.onIndexSyncError);
|
|
2779
|
-
}
|
|
2780
|
-
return result;
|
|
2781
2683
|
}, options.signal);
|
|
2782
2684
|
}
|
|
2783
2685
|
async #resolveScope(document, options) {
|
|
@@ -2787,7 +2689,7 @@ var WikiGraphArchiveHandle = class {
|
|
|
2787
2689
|
async #resolveQueryChapters(document, options) {
|
|
2788
2690
|
const chapters = await this.#resolveScope(document, options);
|
|
2789
2691
|
if (options.skipUnindexed !== true) return chapters;
|
|
2790
|
-
const queryable = await (0,
|
|
2692
|
+
const queryable = await (0, import_wiki_graph_core7.listArchiveQueryableChapterIds)(document, {
|
|
2791
2693
|
...chapters === void 0 ? {} : { chapters }
|
|
2792
2694
|
});
|
|
2793
2695
|
if (queryable.length === 0) {
|
|
@@ -2797,56 +2699,11 @@ var WikiGraphArchiveHandle = class {
|
|
|
2797
2699
|
}
|
|
2798
2700
|
return queryable;
|
|
2799
2701
|
}
|
|
2800
|
-
async #refreshLibraryIndex(onError) {
|
|
2801
|
-
if (this.#location.libraryDirtyTarget === void 0) return;
|
|
2802
|
-
if (this.#location.libraryArchiveTarget !== void 0) {
|
|
2803
|
-
await (0, import_wiki_graph_core5.finalizeWikiGraphLibraryArchiveWrite)({
|
|
2804
|
-
target: this.#location.libraryArchiveTarget
|
|
2805
|
-
});
|
|
2806
|
-
}
|
|
2807
|
-
try {
|
|
2808
|
-
const state = await (0, import_wiki_graph_core5.readWikiGraphLibraryIndexState)(
|
|
2809
|
-
this.#location.libraryDirtyTarget
|
|
2810
|
-
);
|
|
2811
|
-
if (state.status !== "missing") {
|
|
2812
|
-
await (0, import_wiki_graph_core5.rebuildWikiGraphLibraryIndex)(this.#location.libraryDirtyTarget);
|
|
2813
|
-
}
|
|
2814
|
-
} catch (error) {
|
|
2815
|
-
onError?.(error);
|
|
2816
|
-
}
|
|
2817
|
-
}
|
|
2818
2702
|
};
|
|
2819
|
-
async function resolveWikiGraphArchiveLocation(uriOrPath) {
|
|
2820
|
-
if (!uriOrPath.startsWith("wikg://")) {
|
|
2821
|
-
return createPathLocation(resolveWikiGraphRuntimePath(uriOrPath));
|
|
2822
|
-
}
|
|
2823
|
-
const parsed = (0, import_wiki_graph_core5.parseLocatedWikiGraphUri)(uriOrPath);
|
|
2824
|
-
const portableArchiveLocator = parsed.archivePath ?? uriOrPath;
|
|
2825
|
-
const archiveLocator = portableArchiveLocator.startsWith("wikg://lib/") ? portableArchiveLocator : resolveWikiGraphRuntimePath(portableArchiveLocator);
|
|
2826
|
-
const libraryArchiveTarget = archiveLocator.startsWith("wikg://lib/") ? (0, import_wiki_graph_core5.parseWikiGraphLibraryUri)(archiveLocator) : void 0;
|
|
2827
|
-
const archiveFile = libraryArchiveTarget?.kind === "archive" ? await (0, import_wiki_graph_core5.resolveWikiGraphLibraryArchiveFile)(archiveLocator) : new NodeFile(archiveLocator);
|
|
2828
|
-
const archivePath = getNodeResourcePath(archiveFile);
|
|
2829
|
-
return {
|
|
2830
|
-
archiveFile,
|
|
2831
|
-
archiveKey: archivePath,
|
|
2832
|
-
archivePath,
|
|
2833
|
-
indexScope: { archiveKey: archivePath, archivePath, kind: "archive-index" },
|
|
2834
|
-
...libraryArchiveTarget?.kind === "archive" ? {
|
|
2835
|
-
libraryArchiveTarget,
|
|
2836
|
-
libraryDirtyTarget: {
|
|
2837
|
-
isDefault: libraryArchiveTarget.isDefault,
|
|
2838
|
-
kind: "scope",
|
|
2839
|
-
...libraryArchiveTarget.publicId === void 0 ? {} : { publicId: libraryArchiveTarget.publicId }
|
|
2840
|
-
},
|
|
2841
|
-
publicArchiveUri: portableArchiveLocator
|
|
2842
|
-
} : {},
|
|
2843
|
-
locatedUri: (0, import_wiki_graph_core5.formatLocatedWikiGraphUri)(archivePath, parsed.objectUri)
|
|
2844
|
-
};
|
|
2845
|
-
}
|
|
2846
2703
|
async function ensureArchiveSearchIndex(document, options = {}) {
|
|
2847
2704
|
const scope = options.chapters === void 0 ? {} : { chapters: options.chapters };
|
|
2848
|
-
if (await (0,
|
|
2849
|
-
await (0,
|
|
2705
|
+
if (await (0, import_wiki_graph_core7.isArchiveSearchIndexCurrent)(document, scope)) return;
|
|
2706
|
+
await (0, import_wiki_graph_core7.rebuildArchiveSearchIndex)(document, void 0, {
|
|
2850
2707
|
...scope,
|
|
2851
2708
|
...options.embeddingProvider === void 0 ? {} : { embeddingProvider: options.embeddingProvider }
|
|
2852
2709
|
});
|
|
@@ -2856,10 +2713,10 @@ async function resolveArchiveScope(document, objectUri, depth) {
|
|
|
2856
2713
|
if (parsed === void 0 || parsed.kind === "collection" && depth === void 0) {
|
|
2857
2714
|
return void 0;
|
|
2858
2715
|
}
|
|
2859
|
-
const chapters = await (0,
|
|
2716
|
+
const chapters = await (0, import_wiki_graph_core7.listChapters)(document);
|
|
2860
2717
|
const entries = parsed.kind === "collection" ? chapters.filter((chapter) => chapter.depth <= depth) : selectChapterSubtree(
|
|
2861
2718
|
chapters,
|
|
2862
|
-
await (0,
|
|
2719
|
+
await (0, import_wiki_graph_core7.resolveChapterPathReadonly)(document, parsed.chapterPath),
|
|
2863
2720
|
depth
|
|
2864
2721
|
);
|
|
2865
2722
|
return { chapterIds: entries.map((entry) => entry.chapterId), entries };
|
|
@@ -2881,32 +2738,23 @@ function selectChapterSubtree(chapters, rootChapterId, depth) {
|
|
|
2881
2738
|
(chapter) => chapter.chapterId === root.chapterId || chapter.path.startsWith(prefix) && (depth === void 0 || chapter.depth - root.depth <= depth)
|
|
2882
2739
|
);
|
|
2883
2740
|
}
|
|
2884
|
-
function createPathLocation(path) {
|
|
2885
|
-
return {
|
|
2886
|
-
archiveFile: new NodeFile(path),
|
|
2887
|
-
archiveKey: path,
|
|
2888
|
-
archivePath: path,
|
|
2889
|
-
indexScope: { archiveKey: path, archivePath: path, kind: "archive-index" },
|
|
2890
|
-
locatedUri: (0, import_wiki_graph_core5.formatLocatedWikiGraphUri)(path)
|
|
2891
|
-
};
|
|
2892
|
-
}
|
|
2893
2741
|
async function createEmptyArchiveFile(path) {
|
|
2894
|
-
const directoryPath = await (0,
|
|
2895
|
-
(0,
|
|
2742
|
+
const directoryPath = await (0, import_promises4.mkdtemp)(
|
|
2743
|
+
(0, import_path5.join)((0, import_os3.tmpdir)(), "wikigraph-archive-write-")
|
|
2896
2744
|
);
|
|
2897
2745
|
try {
|
|
2898
2746
|
const directory = new NodeDirectory(directoryPath);
|
|
2899
|
-
const document = await
|
|
2747
|
+
const document = await import_wiki_graph_core7.DirectoryDocument.open(directory);
|
|
2900
2748
|
try {
|
|
2901
2749
|
await document.openSession(async (openedDocument) => {
|
|
2902
|
-
await openedDocument.writeToc({ items: [], version:
|
|
2750
|
+
await openedDocument.writeToc({ items: [], version: import_wiki_graph_core7.TOC_FILE_VERSION });
|
|
2903
2751
|
});
|
|
2904
2752
|
} finally {
|
|
2905
2753
|
await document.release();
|
|
2906
2754
|
}
|
|
2907
|
-
await (0,
|
|
2755
|
+
await (0, import_wiki_graph_core7.writeWikgArchive)(directory, new NodeFile(path));
|
|
2908
2756
|
} finally {
|
|
2909
|
-
await (0,
|
|
2757
|
+
await (0, import_promises4.rm)(directoryPath, { force: true, recursive: true });
|
|
2910
2758
|
}
|
|
2911
2759
|
}
|
|
2912
2760
|
function isNodeEEXISTError(error) {
|
|
@@ -2914,7 +2762,7 @@ function isNodeEEXISTError(error) {
|
|
|
2914
2762
|
}
|
|
2915
2763
|
async function nodePathExists(path) {
|
|
2916
2764
|
try {
|
|
2917
|
-
await (0,
|
|
2765
|
+
await (0, import_promises4.stat)(path);
|
|
2918
2766
|
return true;
|
|
2919
2767
|
} catch (error) {
|
|
2920
2768
|
if (isNodeENOENTError(error)) return false;
|
|
@@ -2926,13 +2774,13 @@ function isNodeENOENTError(error) {
|
|
|
2926
2774
|
}
|
|
2927
2775
|
function parseObjectMetadataTarget(objectPath) {
|
|
2928
2776
|
if (objectPath === "") {
|
|
2929
|
-
return { kind:
|
|
2777
|
+
return { kind: import_wiki_graph_core7.ObjectMetadataKind.Archive, objectPath };
|
|
2930
2778
|
}
|
|
2931
2779
|
const chapter = /^chapter\/([1-9][0-9]*)(?:\/.*)?$/u.exec(objectPath);
|
|
2932
2780
|
if (chapter?.[1] !== void 0) {
|
|
2933
2781
|
return {
|
|
2934
2782
|
chapterId: Number(chapter[1]),
|
|
2935
|
-
kind:
|
|
2783
|
+
kind: import_wiki_graph_core7.ObjectMetadataKind.Chapter,
|
|
2936
2784
|
objectPath
|
|
2937
2785
|
};
|
|
2938
2786
|
}
|
|
@@ -2940,7 +2788,7 @@ function parseObjectMetadataTarget(objectPath) {
|
|
|
2940
2788
|
if (chunk?.[1] !== void 0) {
|
|
2941
2789
|
return {
|
|
2942
2790
|
chunkId: Number(chunk[1]),
|
|
2943
|
-
kind:
|
|
2791
|
+
kind: import_wiki_graph_core7.ObjectMetadataKind.Chunk,
|
|
2944
2792
|
objectPath
|
|
2945
2793
|
};
|
|
2946
2794
|
}
|
|
@@ -2948,7 +2796,7 @@ function parseObjectMetadataTarget(objectPath) {
|
|
|
2948
2796
|
if (entity?.[1] !== void 0) {
|
|
2949
2797
|
return {
|
|
2950
2798
|
entityQid: entity[1],
|
|
2951
|
-
kind:
|
|
2799
|
+
kind: import_wiki_graph_core7.ObjectMetadataKind.Entity,
|
|
2952
2800
|
objectPath
|
|
2953
2801
|
};
|
|
2954
2802
|
}
|
|
@@ -2957,14 +2805,14 @@ function parseObjectMetadataTarget(objectPath) {
|
|
|
2957
2805
|
);
|
|
2958
2806
|
if (triple?.[1] !== void 0) {
|
|
2959
2807
|
return {
|
|
2960
|
-
kind:
|
|
2808
|
+
kind: import_wiki_graph_core7.ObjectMetadataKind.Triple,
|
|
2961
2809
|
objectPath,
|
|
2962
2810
|
tripleObjectQid: triple[3],
|
|
2963
2811
|
triplePredicate: decodeURIComponent(triple[2]),
|
|
2964
2812
|
tripleSubjectQid: triple[1]
|
|
2965
2813
|
};
|
|
2966
2814
|
}
|
|
2967
|
-
return { kind:
|
|
2815
|
+
return { kind: import_wiki_graph_core7.ObjectMetadataKind.Object, objectPath };
|
|
2968
2816
|
}
|
|
2969
2817
|
function withoutOperation(options) {
|
|
2970
2818
|
const { signal: _signal, ...rest } = options;
|
|
@@ -2980,7 +2828,7 @@ function withoutOperationAndScope(options) {
|
|
|
2980
2828
|
return rest;
|
|
2981
2829
|
}
|
|
2982
2830
|
async function resolveOptionalChapterPath(document, path) {
|
|
2983
|
-
return path === void 0 ? void 0 : await (0,
|
|
2831
|
+
return path === void 0 ? void 0 : await (0, import_wiki_graph_core7.resolveChapterPathReadonly)(document, path);
|
|
2984
2832
|
}
|
|
2985
2833
|
function requireChapter(chapters, chapterId) {
|
|
2986
2834
|
const chapter = chapters.find((entry) => entry.chapterId === chapterId);
|
|
@@ -2994,7 +2842,7 @@ function asTextStream(text) {
|
|
|
2994
2842
|
}
|
|
2995
2843
|
async function assertChapterResetAllowed(archive, chapterId, stage) {
|
|
2996
2844
|
if (stage === "planned") {
|
|
2997
|
-
await (0,
|
|
2845
|
+
await (0, import_wiki_graph_core7.assertNoActiveBuildJobs)({
|
|
2998
2846
|
archive,
|
|
2999
2847
|
chapterIds: [chapterId],
|
|
3000
2848
|
operation: "Resetting chapter to planned"
|
|
@@ -3002,14 +2850,14 @@ async function assertChapterResetAllowed(archive, chapterId, stage) {
|
|
|
3002
2850
|
return;
|
|
3003
2851
|
}
|
|
3004
2852
|
if (stage === "sourced") {
|
|
3005
|
-
await (0,
|
|
2853
|
+
await (0, import_wiki_graph_core7.assertNoActiveBuildJobs)({
|
|
3006
2854
|
archive,
|
|
3007
2855
|
chapterIds: [chapterId],
|
|
3008
2856
|
operation: "Resetting chapter graph",
|
|
3009
2857
|
requiresTarget: "reading-graph"
|
|
3010
2858
|
});
|
|
3011
2859
|
}
|
|
3012
|
-
await (0,
|
|
2860
|
+
await (0, import_wiki_graph_core7.assertNoActiveBuildJobs)({
|
|
3013
2861
|
archive,
|
|
3014
2862
|
chapterIds: [chapterId],
|
|
3015
2863
|
operation: "Resetting chapter summary",
|
|
@@ -3020,12 +2868,13 @@ async function assertChapterResetAllowed(archive, chapterId, stage) {
|
|
|
3020
2868
|
// src/wikispine.ts
|
|
3021
2869
|
var import_child_process = require("child_process");
|
|
3022
2870
|
var nodeWikispineCommandRunner = {
|
|
3023
|
-
run: async ({ args, command, input, onStdout, signal }) => await new Promise((
|
|
2871
|
+
run: async ({ args, command, input, onStdout, signal }) => await new Promise((resolve4, reject) => {
|
|
3024
2872
|
signal?.throwIfAborted();
|
|
3025
2873
|
const child = (0, import_child_process.spawn)(command, [...args], {
|
|
3026
2874
|
stdio: ["pipe", "pipe", "pipe"]
|
|
3027
2875
|
});
|
|
3028
2876
|
const stderr = [];
|
|
2877
|
+
let stdoutQueue = Promise.resolve();
|
|
3029
2878
|
let settled = false;
|
|
3030
2879
|
const settle = (operation) => {
|
|
3031
2880
|
if (settled) return;
|
|
@@ -3041,14 +2890,15 @@ var nodeWikispineCommandRunner = {
|
|
|
3041
2890
|
child.stdout.setEncoding("utf8");
|
|
3042
2891
|
child.stdout.on("data", (chunk) => {
|
|
3043
2892
|
if (settled) return;
|
|
3044
|
-
|
|
3045
|
-
|
|
3046
|
-
|
|
2893
|
+
child.stdout.pause();
|
|
2894
|
+
stdoutQueue = stdoutQueue.then(async () => await onStdout(chunk)).then(() => {
|
|
2895
|
+
child.stdout.resume();
|
|
2896
|
+
}).catch((error) => {
|
|
3047
2897
|
child.kill();
|
|
3048
2898
|
settle(
|
|
3049
2899
|
() => reject(error instanceof Error ? error : new Error(String(error)))
|
|
3050
2900
|
);
|
|
3051
|
-
}
|
|
2901
|
+
});
|
|
3052
2902
|
});
|
|
3053
2903
|
child.stderr.on("data", (chunk) => stderr.push(chunk));
|
|
3054
2904
|
child.on("error", (error) => {
|
|
@@ -3059,12 +2909,14 @@ var nodeWikispineCommandRunner = {
|
|
|
3059
2909
|
);
|
|
3060
2910
|
});
|
|
3061
2911
|
child.on("close", (exitCode) => {
|
|
3062
|
-
|
|
3063
|
-
(
|
|
3064
|
-
|
|
3065
|
-
|
|
3066
|
-
|
|
3067
|
-
|
|
2912
|
+
void stdoutQueue.then(() => {
|
|
2913
|
+
settle(
|
|
2914
|
+
() => resolve4({
|
|
2915
|
+
exitCode,
|
|
2916
|
+
stderr: Buffer.concat(stderr).toString("utf8")
|
|
2917
|
+
})
|
|
2918
|
+
);
|
|
2919
|
+
});
|
|
3068
2920
|
});
|
|
3069
2921
|
child.stdin.end(input);
|
|
3070
2922
|
})
|
|
@@ -3075,7 +2927,7 @@ function abortError(signal) {
|
|
|
3075
2927
|
|
|
3076
2928
|
// src/config.ts
|
|
3077
2929
|
var import_ai2 = require("ai");
|
|
3078
|
-
var
|
|
2930
|
+
var import_wiki_graph_core8 = require("wiki-graph-core");
|
|
3079
2931
|
var WikiGraphConfigManager = class {
|
|
3080
2932
|
#runtime;
|
|
3081
2933
|
constructor(runtime) {
|
|
@@ -3158,7 +3010,7 @@ var WikiGraphConfigManager = class {
|
|
|
3158
3010
|
if (resolved === void 0) {
|
|
3159
3011
|
throw new Error("WikiSpine provider is not configured.");
|
|
3160
3012
|
}
|
|
3161
|
-
const result = await (0,
|
|
3013
|
+
const result = await (0, import_wiki_graph_core8.testWikispineRuntime)({
|
|
3162
3014
|
...resolved,
|
|
3163
3015
|
...resolved.provider === "cli" ? { commandRunner: nodeWikispineCommandRunner } : {}
|
|
3164
3016
|
});
|
|
@@ -3181,7 +3033,7 @@ function parseProvider(value) {
|
|
|
3181
3033
|
}
|
|
3182
3034
|
|
|
3183
3035
|
// src/continuations.ts
|
|
3184
|
-
var
|
|
3036
|
+
var import_wiki_graph_core9 = require("wiki-graph-core");
|
|
3185
3037
|
var WikiGraphContinuationManager = class {
|
|
3186
3038
|
#runtime;
|
|
3187
3039
|
constructor(runtime) {
|
|
@@ -3196,13 +3048,13 @@ var WikiGraphContinuationManager = class {
|
|
|
3196
3048
|
async create(context, cursor) {
|
|
3197
3049
|
if (cursor === null || cursor === void 0) return null;
|
|
3198
3050
|
return await this.#runtime.run(
|
|
3199
|
-
async () => await (0,
|
|
3051
|
+
async () => await (0, import_wiki_graph_core9.createContinuationCursor)(
|
|
3200
3052
|
createContinuationPayload(context, cursor)
|
|
3201
3053
|
)
|
|
3202
3054
|
);
|
|
3203
3055
|
}
|
|
3204
3056
|
async #next(options) {
|
|
3205
|
-
const cursor = await (0,
|
|
3057
|
+
const cursor = await (0, import_wiki_graph_core9.readContinuationCursor)(options.cursor);
|
|
3206
3058
|
const continuationCursor = options.format === void 0 ? cursor : { ...cursor, format: options.format };
|
|
3207
3059
|
const limit = options.limit ?? 20;
|
|
3208
3060
|
if (options.archive !== void 0) {
|
|
@@ -3227,29 +3079,29 @@ var WikiGraphContinuationManager = class {
|
|
|
3227
3079
|
};
|
|
3228
3080
|
async function continueArchiveCursor(cursor, limit) {
|
|
3229
3081
|
const location = await resolveWikiGraphArchiveLocation(
|
|
3230
|
-
getCursorArchivePath(cursor)
|
|
3082
|
+
archiveTargetFromLogicalLocator(getCursorArchivePath(cursor))
|
|
3231
3083
|
);
|
|
3232
|
-
return await new
|
|
3084
|
+
return await new import_wiki_graph_core9.WikiGraphArchiveFile(location.archiveFile).readDocument(
|
|
3233
3085
|
async (document) => {
|
|
3234
3086
|
switch (cursor.kind) {
|
|
3235
3087
|
case "source-locators":
|
|
3236
|
-
return await (0,
|
|
3088
|
+
return await (0, import_wiki_graph_core9.listArchiveSourceLocators)(document, cursor.targetUri, {
|
|
3237
3089
|
cursor: cursor.cursor,
|
|
3238
3090
|
limit
|
|
3239
3091
|
});
|
|
3240
3092
|
case "collection":
|
|
3241
|
-
return await (0,
|
|
3093
|
+
return await (0, import_wiki_graph_core9.listArchiveCollection)(
|
|
3242
3094
|
document,
|
|
3243
3095
|
createCollectionOptions(cursor, limit)
|
|
3244
3096
|
);
|
|
3245
3097
|
case "search":
|
|
3246
|
-
return await (0,
|
|
3098
|
+
return await (0, import_wiki_graph_core9.findArchiveObjects)(
|
|
3247
3099
|
document,
|
|
3248
3100
|
cursor.query ?? "",
|
|
3249
3101
|
await createFindOptions(cursor, limit)
|
|
3250
3102
|
);
|
|
3251
3103
|
case "evidence":
|
|
3252
|
-
return await (0,
|
|
3104
|
+
return await (0, import_wiki_graph_core9.listArchiveEvidence)(document, cursor.targetUri, {
|
|
3253
3105
|
...cursor.chapters === null ? {} : { chapters: cursor.chapters },
|
|
3254
3106
|
cursor: cursor.cursor,
|
|
3255
3107
|
limit,
|
|
@@ -3259,7 +3111,7 @@ async function continueArchiveCursor(cursor, limit) {
|
|
|
3259
3111
|
...cursor.sourceContext === void 0 ? {} : { sourceContext: cursor.sourceContext }
|
|
3260
3112
|
});
|
|
3261
3113
|
case "related":
|
|
3262
|
-
return await (0,
|
|
3114
|
+
return await (0, import_wiki_graph_core9.listRelatedArchiveObjects)(document, cursor.targetUri, {
|
|
3263
3115
|
...cursor.chapters === null ? {} : { chapters: cursor.chapters },
|
|
3264
3116
|
cursor: cursor.cursor,
|
|
3265
3117
|
...cursor.evidenceLimit === void 0 ? {} : { evidenceLimit: cursor.evidenceLimit },
|
|
@@ -3283,30 +3135,30 @@ async function continueLibraryCursor(cursor, limit) {
|
|
|
3283
3135
|
if (cursor.indexScope.kind !== "library-index") {
|
|
3284
3136
|
throw new Error("Internal error: expected a library index cursor.");
|
|
3285
3137
|
}
|
|
3286
|
-
const target = await (0,
|
|
3138
|
+
const target = await (0, import_wiki_graph_core9.resolveWikiGraphLibraryQueryTargetById)(
|
|
3287
3139
|
cursor.indexScope.libraryId
|
|
3288
3140
|
);
|
|
3289
3141
|
switch (cursor.kind) {
|
|
3290
3142
|
case "collection":
|
|
3291
|
-
return await (requireLibraryQuery(cursor) === "archive-members" ? (0,
|
|
3143
|
+
return await (requireLibraryQuery(cursor) === "archive-members" ? (0, import_wiki_graph_core9.listWikiGraphLibraryArchiveMembers)(
|
|
3292
3144
|
target,
|
|
3293
3145
|
createCollectionOptions(cursor, limit)
|
|
3294
|
-
) : (0,
|
|
3146
|
+
) : (0, import_wiki_graph_core9.listWikiGraphLibraryObjects)(
|
|
3295
3147
|
target,
|
|
3296
3148
|
createCollectionOptions(cursor, limit)
|
|
3297
3149
|
));
|
|
3298
3150
|
case "search":
|
|
3299
|
-
return await (requireLibraryQuery(cursor) === "archive-members" ? (0,
|
|
3151
|
+
return await (requireLibraryQuery(cursor) === "archive-members" ? (0, import_wiki_graph_core9.findWikiGraphLibraryArchiveMembers)(
|
|
3300
3152
|
target,
|
|
3301
3153
|
cursor.query ?? "",
|
|
3302
3154
|
await createFindOptions(cursor, limit)
|
|
3303
|
-
) : (0,
|
|
3155
|
+
) : (0, import_wiki_graph_core9.findWikiGraphLibraryObjects)(
|
|
3304
3156
|
target,
|
|
3305
3157
|
cursor.query ?? "",
|
|
3306
3158
|
await createFindOptions(cursor, limit)
|
|
3307
3159
|
));
|
|
3308
3160
|
case "evidence":
|
|
3309
|
-
return await (0,
|
|
3161
|
+
return await (0, import_wiki_graph_core9.listWikiGraphLibraryEvidence)(target, cursor.targetUri, {
|
|
3310
3162
|
cursor: cursor.cursor,
|
|
3311
3163
|
limit,
|
|
3312
3164
|
order: cursor.order,
|
|
@@ -3315,7 +3167,7 @@ async function continueLibraryCursor(cursor, limit) {
|
|
|
3315
3167
|
...cursor.sourceContext === void 0 ? {} : { sourceContext: cursor.sourceContext }
|
|
3316
3168
|
});
|
|
3317
3169
|
case "related":
|
|
3318
|
-
return await (0,
|
|
3170
|
+
return await (0, import_wiki_graph_core9.listRelatedWikiGraphLibraryObjects)(
|
|
3319
3171
|
target,
|
|
3320
3172
|
cursor.targetUri,
|
|
3321
3173
|
{
|
|
@@ -3376,7 +3228,7 @@ function getCursorArchivePath(cursor) {
|
|
|
3376
3228
|
}
|
|
3377
3229
|
async function persistResultCursor(cursor, result) {
|
|
3378
3230
|
if (result.nextCursor === null) return result;
|
|
3379
|
-
const nextCursor = await (0,
|
|
3231
|
+
const nextCursor = await (0, import_wiki_graph_core9.createContinuationCursor)({
|
|
3380
3232
|
...cursor,
|
|
3381
3233
|
cursor: result.nextCursor
|
|
3382
3234
|
});
|
|
@@ -3479,17 +3331,17 @@ function createLibraryQueryPayload(context) {
|
|
|
3479
3331
|
}
|
|
3480
3332
|
|
|
3481
3333
|
// src/default-worker.ts
|
|
3482
|
-
var
|
|
3334
|
+
var import_wiki_graph_core14 = require("wiki-graph-core");
|
|
3483
3335
|
var import_worker3 = require("wiki-graph-core/worker");
|
|
3484
3336
|
|
|
3485
3337
|
// src/stage.ts
|
|
3486
|
-
var import_wiki_graph_core8 = require("wiki-graph-core");
|
|
3487
|
-
var import_wiki_graph_core9 = require("wiki-graph-core");
|
|
3488
3338
|
var import_wiki_graph_core10 = require("wiki-graph-core");
|
|
3339
|
+
var import_wiki_graph_core11 = require("wiki-graph-core");
|
|
3340
|
+
var import_wiki_graph_core12 = require("wiki-graph-core");
|
|
3489
3341
|
function createStageLLM(config, options) {
|
|
3490
3342
|
const llmOptions = buildWikiGraphLLMOptions(config);
|
|
3491
|
-
return new
|
|
3492
|
-
sampling: (0,
|
|
3343
|
+
return new import_wiki_graph_core12.LLM({
|
|
3344
|
+
sampling: (0, import_wiki_graph_core11.createDefaultWikiGraphSampling)({
|
|
3493
3345
|
...llmOptions.temperature === void 0 ? {} : { temperature: llmOptions.temperature },
|
|
3494
3346
|
...llmOptions.topP === void 0 ? {} : { topP: llmOptions.topP }
|
|
3495
3347
|
}),
|
|
@@ -3512,8 +3364,134 @@ async function loadRequiredStageConfig(options) {
|
|
|
3512
3364
|
return config;
|
|
3513
3365
|
}
|
|
3514
3366
|
|
|
3367
|
+
// src/planning.ts
|
|
3368
|
+
var DEFAULT_GENERATION_JOB_CONCURRENCY = 3;
|
|
3369
|
+
var DEFAULT_GENERATION_REQUEST_CONCURRENCY = 6;
|
|
3370
|
+
function planGenerationTask(task, words, chapters, concurrent, model) {
|
|
3371
|
+
const profile = getGenerationPlanningProfile(task);
|
|
3372
|
+
const calls = Math.max(chapters, Math.ceil(words / profile.wordsPerCall));
|
|
3373
|
+
const effectiveConcurrency = Math.max(
|
|
3374
|
+
1,
|
|
3375
|
+
task === "reading-graph" ? 1 : concurrent.request
|
|
3376
|
+
);
|
|
3377
|
+
const callBatches = Math.ceil(calls / effectiveConcurrency);
|
|
3378
|
+
const wordSeconds = words * profile.secondsPerWord;
|
|
3379
|
+
return {
|
|
3380
|
+
model,
|
|
3381
|
+
timeSeconds: {
|
|
3382
|
+
max: Math.ceil(callBatches * profile.maxSecondsPerCall + wordSeconds),
|
|
3383
|
+
min: Math.ceil(callBatches * profile.minSecondsPerCall + wordSeconds)
|
|
3384
|
+
},
|
|
3385
|
+
tokens: {
|
|
3386
|
+
cacheableInput: Math.ceil(words * profile.cacheableInputTokenPerWord),
|
|
3387
|
+
input: Math.ceil(words * profile.inputTokenPerWord),
|
|
3388
|
+
output: Math.ceil(words * profile.outputTokenPerWord)
|
|
3389
|
+
}
|
|
3390
|
+
};
|
|
3391
|
+
}
|
|
3392
|
+
function createGenerationPerformanceHints(input) {
|
|
3393
|
+
if (!input.hasJobWork) {
|
|
3394
|
+
return [];
|
|
3395
|
+
}
|
|
3396
|
+
const hints = [];
|
|
3397
|
+
const recommendedRequest = input.concurrent.request < 4 ? DEFAULT_GENERATION_REQUEST_CONCURRENCY : input.concurrent.request < 8 ? 8 : void 0;
|
|
3398
|
+
if (input.hasRequestWork && recommendedRequest !== void 0) {
|
|
3399
|
+
hints.push({
|
|
3400
|
+
configKey: "request",
|
|
3401
|
+
configValue: recommendedRequest,
|
|
3402
|
+
current: input.concurrent.request,
|
|
3403
|
+
kind: "request",
|
|
3404
|
+
message: "LLM request concurrency can often be higher. Use at least 4; 6-8 is usually faster when the provider allows it.",
|
|
3405
|
+
recommended: recommendedRequest
|
|
3406
|
+
});
|
|
3407
|
+
}
|
|
3408
|
+
if (input.concurrent.job < 4 && input.chapters > 1) {
|
|
3409
|
+
hints.push({
|
|
3410
|
+
configKey: "job",
|
|
3411
|
+
configValue: 4,
|
|
3412
|
+
current: input.concurrent.job,
|
|
3413
|
+
kind: "job",
|
|
3414
|
+
message: "Multiple chapters need work and job concurrency is below 4. Raising it lets chapter jobs run in parallel.",
|
|
3415
|
+
recommended: 4
|
|
3416
|
+
});
|
|
3417
|
+
}
|
|
3418
|
+
return hints;
|
|
3419
|
+
}
|
|
3420
|
+
function formatGenerationPlanningModel(llm) {
|
|
3421
|
+
if (llm?.model === void 0) {
|
|
3422
|
+
return "not configured";
|
|
3423
|
+
}
|
|
3424
|
+
return llm.provider === void 0 ? llm.model : `${llm.provider}/${llm.model}`;
|
|
3425
|
+
}
|
|
3426
|
+
function formatGenerationPlanningDuration(seconds) {
|
|
3427
|
+
if (seconds < 60) {
|
|
3428
|
+
return `${seconds}s`;
|
|
3429
|
+
}
|
|
3430
|
+
const minutes = Math.round(seconds / 60);
|
|
3431
|
+
if (minutes < 60) {
|
|
3432
|
+
return `${minutes}m`;
|
|
3433
|
+
}
|
|
3434
|
+
return `${Math.round(minutes / 60)}h`;
|
|
3435
|
+
}
|
|
3436
|
+
function getGenerationPlanningProfile(task) {
|
|
3437
|
+
switch (task) {
|
|
3438
|
+
case "index-fts":
|
|
3439
|
+
return {
|
|
3440
|
+
cacheableInputTokenPerWord: 0,
|
|
3441
|
+
inputTokenPerWord: 0,
|
|
3442
|
+
maxSecondsPerCall: 1,
|
|
3443
|
+
minSecondsPerCall: 0,
|
|
3444
|
+
outputTokenPerWord: 0,
|
|
3445
|
+
secondsPerWord: 5e-4,
|
|
3446
|
+
wordsPerCall: 1e5
|
|
3447
|
+
};
|
|
3448
|
+
case "index-embedding-source":
|
|
3449
|
+
case "index-embedding-summary":
|
|
3450
|
+
return {
|
|
3451
|
+
cacheableInputTokenPerWord: 0,
|
|
3452
|
+
inputTokenPerWord: 0,
|
|
3453
|
+
maxSecondsPerCall: 10,
|
|
3454
|
+
minSecondsPerCall: 1,
|
|
3455
|
+
outputTokenPerWord: 0,
|
|
3456
|
+
secondsPerWord: 2e-3,
|
|
3457
|
+
wordsPerCall: 1e4
|
|
3458
|
+
};
|
|
3459
|
+
case "knowledge-graph":
|
|
3460
|
+
return {
|
|
3461
|
+
cacheableInputTokenPerWord: 60,
|
|
3462
|
+
inputTokenPerWord: 80,
|
|
3463
|
+
maxSecondsPerCall: 35,
|
|
3464
|
+
minSecondsPerCall: 15,
|
|
3465
|
+
outputTokenPerWord: 25,
|
|
3466
|
+
secondsPerWord: 0.02,
|
|
3467
|
+
wordsPerCall: 35
|
|
3468
|
+
};
|
|
3469
|
+
case "reading-graph":
|
|
3470
|
+
return {
|
|
3471
|
+
cacheableInputTokenPerWord: 20,
|
|
3472
|
+
inputTokenPerWord: 25,
|
|
3473
|
+
maxSecondsPerCall: 45,
|
|
3474
|
+
minSecondsPerCall: 15,
|
|
3475
|
+
outputTokenPerWord: 4,
|
|
3476
|
+
secondsPerWord: 0.01,
|
|
3477
|
+
wordsPerCall: 160
|
|
3478
|
+
};
|
|
3479
|
+
case "reading-summary":
|
|
3480
|
+
return {
|
|
3481
|
+
cacheableInputTokenPerWord: 45,
|
|
3482
|
+
inputTokenPerWord: 55,
|
|
3483
|
+
maxSecondsPerCall: 25,
|
|
3484
|
+
minSecondsPerCall: 10,
|
|
3485
|
+
outputTokenPerWord: 4,
|
|
3486
|
+
secondsPerWord: 0.01,
|
|
3487
|
+
wordsPerCall: 110
|
|
3488
|
+
};
|
|
3489
|
+
}
|
|
3490
|
+
}
|
|
3491
|
+
|
|
3515
3492
|
// src/worker.ts
|
|
3516
3493
|
var import_worker = require("wiki-graph-core/worker");
|
|
3494
|
+
var import_wiki_graph_core13 = require("wiki-graph-core");
|
|
3517
3495
|
var import_worker2 = require("wiki-graph-core/worker");
|
|
3518
3496
|
async function runBuildJobWorker(options) {
|
|
3519
3497
|
installNodeWikiGraphPlatform();
|
|
@@ -3530,7 +3508,7 @@ async function runWikiGraphQueueWorker(options = {}) {
|
|
|
3530
3508
|
await runBuildJobWorker({
|
|
3531
3509
|
concurrency: config.concurrent?.job ?? DEFAULT_GENERATION_JOB_CONCURRENCY,
|
|
3532
3510
|
executeJob: async (job, reporter, context) => {
|
|
3533
|
-
await (0,
|
|
3511
|
+
await (0, import_wiki_graph_core14.withLoggingContext)(
|
|
3534
3512
|
{ logDirectory: job.log, operation: "build-job" },
|
|
3535
3513
|
async () => await executeBuildJob(job, reporter, context)
|
|
3536
3514
|
);
|
|
@@ -3553,7 +3531,7 @@ async function executeBuildJob(job, reporter, context) {
|
|
|
3553
3531
|
let stage = await readChapterStage(job);
|
|
3554
3532
|
if (stage === "sourced") {
|
|
3555
3533
|
await executeStep(job, "reading-graph", execution, reporter, context, {
|
|
3556
|
-
...execution.extractionPrompt === void 0 ? {} : {
|
|
3534
|
+
...execution.extractionPrompt === void 0 ? {} : { prompt: execution.extractionPrompt }
|
|
3557
3535
|
});
|
|
3558
3536
|
stage = await readChapterStage(job);
|
|
3559
3537
|
}
|
|
@@ -3586,8 +3564,8 @@ async function executeBuildJob(job, reporter, context) {
|
|
|
3586
3564
|
}
|
|
3587
3565
|
}
|
|
3588
3566
|
await executeStep(job, job.target, execution, reporter, context, {
|
|
3589
|
-
...job.target === "reading-graph" ? {
|
|
3590
|
-
...job.target === "knowledge-graph" ? {
|
|
3567
|
+
...job.target === "reading-graph" ? { prompt: execution.extractionPrompt } : {},
|
|
3568
|
+
...job.target === "knowledge-graph" ? { prompt: execution.knowledgeGraphPrompt } : {}
|
|
3591
3569
|
});
|
|
3592
3570
|
} finally {
|
|
3593
3571
|
await execution.close();
|
|
@@ -3602,9 +3580,9 @@ async function executeStep(job, kind, execution, reporter, context, inputOptions
|
|
|
3602
3580
|
const stepWorkspace = await resetStepWorkspace(job.workspace, kind);
|
|
3603
3581
|
const inputFile = await stepWorkspace.createFile("input.jsonl");
|
|
3604
3582
|
const outputWorkspace = await stepWorkspace.createDirectory("output");
|
|
3605
|
-
const revision = await new
|
|
3583
|
+
const revision = await new import_wiki_graph_core14.WikiGraphArchiveFile(job.archive).readDocument(
|
|
3606
3584
|
async (document) => {
|
|
3607
|
-
await (0,
|
|
3585
|
+
await (0, import_wiki_graph_core14.getChapterDetails)(document, job.chapterId);
|
|
3608
3586
|
return await (0, import_worker3.writeChapterJobInputFile)(
|
|
3609
3587
|
document,
|
|
3610
3588
|
job.chapterId,
|
|
@@ -3614,7 +3592,7 @@ async function executeStep(job, kind, execution, reporter, context, inputOptions
|
|
|
3614
3592
|
);
|
|
3615
3593
|
}
|
|
3616
3594
|
);
|
|
3617
|
-
await (0,
|
|
3595
|
+
await (0, import_wiki_graph_core14.recordBuildJobInputRevision)({
|
|
3618
3596
|
currentRevision: revision,
|
|
3619
3597
|
jobId: job.jobId,
|
|
3620
3598
|
ownerId: requireRunningJobOwnerId(job)
|
|
@@ -3644,16 +3622,23 @@ async function executeStep(job, kind, execution, reporter, context, inputOptions
|
|
|
3644
3622
|
total: 1,
|
|
3645
3623
|
unit: "item"
|
|
3646
3624
|
});
|
|
3647
|
-
await
|
|
3648
|
-
|
|
3649
|
-
|
|
3650
|
-
|
|
3651
|
-
|
|
3652
|
-
|
|
3653
|
-
|
|
3654
|
-
|
|
3655
|
-
|
|
3656
|
-
|
|
3625
|
+
const target = await resolveWikiGraphArchiveTarget(job.archive);
|
|
3626
|
+
const resolvedLocation = await resolveWikiGraphArchiveLocation(target);
|
|
3627
|
+
const location = target.kind === "standalone" ? { ...resolvedLocation, archiveFile: job.archive } : resolvedLocation;
|
|
3628
|
+
await writeWikiGraphArchiveLocation(
|
|
3629
|
+
location,
|
|
3630
|
+
async (document) => {
|
|
3631
|
+
assertJobStillRunning(await (0, import_wiki_graph_core14.getBuildJob)(job.jobId));
|
|
3632
|
+
await (0, import_worker3.applyChapterJobArtifactFile)(
|
|
3633
|
+
document,
|
|
3634
|
+
job.chapterId,
|
|
3635
|
+
kind,
|
|
3636
|
+
revision,
|
|
3637
|
+
result.artifactFile
|
|
3638
|
+
);
|
|
3639
|
+
},
|
|
3640
|
+
{ invalidateContinuationCursors: true }
|
|
3641
|
+
);
|
|
3657
3642
|
await reporter.updatePhase({
|
|
3658
3643
|
done: 1,
|
|
3659
3644
|
phase: "committing",
|
|
@@ -3661,7 +3646,7 @@ async function executeStep(job, kind, execution, reporter, context, inputOptions
|
|
|
3661
3646
|
unit: "item"
|
|
3662
3647
|
});
|
|
3663
3648
|
await reporter.stepCompleted(kind);
|
|
3664
|
-
assertJobStillRunning(await (0,
|
|
3649
|
+
assertJobStillRunning(await (0, import_wiki_graph_core14.getBuildJob)(job.jobId));
|
|
3665
3650
|
}
|
|
3666
3651
|
async function openJobExecutor(job, config, signal, reporter) {
|
|
3667
3652
|
const generation = !job.target.startsWith("index-");
|
|
@@ -3680,18 +3665,22 @@ async function openJobExecutor(job, config, signal, reporter) {
|
|
|
3680
3665
|
const request = llm === void 0 ? void 0 : async (messages, index, maxRetries) => await llm.request(messages, {
|
|
3681
3666
|
retryIndex: index,
|
|
3682
3667
|
retryMax: maxRetries,
|
|
3683
|
-
scope:
|
|
3668
|
+
scope: import_wiki_graph_core14.WikiGraphScope.ReaderExtraction,
|
|
3684
3669
|
signal
|
|
3685
3670
|
});
|
|
3686
3671
|
if (request !== void 0 && llm !== void 0) {
|
|
3687
3672
|
request.lazy = async (operation) => await llm.request(async () => await operation(request));
|
|
3688
3673
|
}
|
|
3689
|
-
const wikimediaResolver = job.target !== "knowledge-graph" ? void 0 : await (0,
|
|
3674
|
+
const wikimediaResolver = job.target !== "knowledge-graph" ? void 0 : await (0, import_wiki_graph_core14.openWikimediaResolver)(
|
|
3690
3675
|
config.wikimedia === void 0 ? {
|
|
3691
3676
|
kind: "local",
|
|
3692
3677
|
llmRequest: requireValue(
|
|
3693
3678
|
request,
|
|
3694
3679
|
"Local Wikimedia resolution requires an LLM."
|
|
3680
|
+
),
|
|
3681
|
+
llmModelId: requireValue(
|
|
3682
|
+
stageConfig?.llm?.model,
|
|
3683
|
+
"Local Wikimedia resolution requires an LLM model."
|
|
3695
3684
|
)
|
|
3696
3685
|
} : {
|
|
3697
3686
|
endpoint: config.wikimedia.endpoint,
|
|
@@ -3715,9 +3704,9 @@ async function openJobExecutor(job, config, signal, reporter) {
|
|
|
3715
3704
|
}
|
|
3716
3705
|
}
|
|
3717
3706
|
}),
|
|
3718
|
-
...promptSource === void 0 ? {} : { extractionPrompt: (0,
|
|
3707
|
+
...promptSource === void 0 ? {} : { extractionPrompt: (0, import_wiki_graph_core10.resolveExtractionPrompt)(promptSource) },
|
|
3719
3708
|
...promptSource === void 0 ? {} : {
|
|
3720
|
-
knowledgeGraphPrompt: (0,
|
|
3709
|
+
knowledgeGraphPrompt: (0, import_wiki_graph_core10.resolveKnowledgeGraphRecallPrompt)(promptSource)
|
|
3721
3710
|
}
|
|
3722
3711
|
};
|
|
3723
3712
|
}
|
|
@@ -3729,12 +3718,12 @@ async function resetStepWorkspace(workspace, kind) {
|
|
|
3729
3718
|
return await workspace.createDirectory(name);
|
|
3730
3719
|
}
|
|
3731
3720
|
async function readChapterStage(job) {
|
|
3732
|
-
return await new
|
|
3733
|
-
async (document) => (await (0,
|
|
3721
|
+
return await new import_wiki_graph_core14.WikiGraphArchiveFile(job.archive).readDocument(
|
|
3722
|
+
async (document) => (await (0, import_wiki_graph_core14.getChapterDetails)(document, job.chapterId)).stage
|
|
3734
3723
|
);
|
|
3735
3724
|
}
|
|
3736
3725
|
async function assertCurrentFtsArtifact(job) {
|
|
3737
|
-
await new
|
|
3726
|
+
await new import_wiki_graph_core14.WikiGraphArchiveFile(job.archive).readDocument(async (document) => {
|
|
3738
3727
|
const revision = await document.serials.getRevision(job.chapterId);
|
|
3739
3728
|
const artifact = await document.indexArtifacts.get(job.chapterId, "fts");
|
|
3740
3729
|
if (artifact?.sourceRevision !== revision) {
|
|
@@ -3833,27 +3822,27 @@ function normalizeOptionalPath(path) {
|
|
|
3833
3822
|
}
|
|
3834
3823
|
|
|
3835
3824
|
// src/jobs.ts
|
|
3836
|
-
var
|
|
3825
|
+
var import_wiki_graph_core15 = require("wiki-graph-core");
|
|
3837
3826
|
var TERMINAL_STATES = /* @__PURE__ */ new Set(["canceled", "failed", "succeeded"]);
|
|
3838
3827
|
var TERMINAL_EVENT_GRACE_READS = 3;
|
|
3839
3828
|
var CORE_BUILD_JOB_BACKEND = {
|
|
3840
|
-
add: async (options) => await (0,
|
|
3841
|
-
boost: async (jobId) => await (0,
|
|
3842
|
-
cancel: async (jobId) => await (0,
|
|
3843
|
-
get: async (jobId) => await (0,
|
|
3844
|
-
list: async (options) => await (0,
|
|
3845
|
-
pause: async (jobId) => await (0,
|
|
3829
|
+
add: async (options) => await (0, import_wiki_graph_core15.addBuildJob)(options),
|
|
3830
|
+
boost: async (jobId) => await (0, import_wiki_graph_core15.boostBuildJob)(jobId),
|
|
3831
|
+
cancel: async (jobId) => await (0, import_wiki_graph_core15.cancelBuildJob)(jobId),
|
|
3832
|
+
get: async (jobId) => await (0, import_wiki_graph_core15.getBuildJob)(jobId),
|
|
3833
|
+
list: async (options) => await (0, import_wiki_graph_core15.listBuildJobs)(options),
|
|
3834
|
+
pause: async (jobId) => await (0, import_wiki_graph_core15.pauseBuildJob)(jobId),
|
|
3846
3835
|
readEventChunk: async (job, cursor) => await readIncrementalBuildJobEvents(job, cursor),
|
|
3847
|
-
readEvents: async (job) => await (0,
|
|
3848
|
-
resume: async (jobId) => await (0,
|
|
3849
|
-
setTarget: async (jobId, target) => await (0,
|
|
3836
|
+
readEvents: async (job) => await (0, import_wiki_graph_core15.readBuildJobEvents)(job),
|
|
3837
|
+
resume: async (jobId) => await (0, import_wiki_graph_core15.resumeBuildJob)(jobId),
|
|
3838
|
+
setTarget: async (jobId, target) => await (0, import_wiki_graph_core15.updateBuildJobTarget)(jobId, target)
|
|
3850
3839
|
};
|
|
3851
3840
|
async function readIncrementalBuildJobEvents(job, cursor) {
|
|
3852
3841
|
let reader;
|
|
3853
3842
|
try {
|
|
3854
3843
|
reader = await job.events.openReader();
|
|
3855
3844
|
} catch {
|
|
3856
|
-
return { cursor, events: await (0,
|
|
3845
|
+
return { cursor, events: await (0, import_wiki_graph_core15.readBuildJobEvents)(job) };
|
|
3857
3846
|
}
|
|
3858
3847
|
try {
|
|
3859
3848
|
const offset = cursor <= reader.size ? cursor : 0;
|
|
@@ -3877,45 +3866,51 @@ var WikiGraphJobManager = class {
|
|
|
3877
3866
|
this.#backend = backend;
|
|
3878
3867
|
}
|
|
3879
3868
|
async create(options) {
|
|
3880
|
-
const
|
|
3881
|
-
|
|
3882
|
-
|
|
3883
|
-
|
|
3884
|
-
|
|
3885
|
-
|
|
3886
|
-
|
|
3869
|
+
const resolved = await this.#runtime.run(async () => {
|
|
3870
|
+
const location = await resolveWikiGraphArchiveLocation(options.archive);
|
|
3871
|
+
return {
|
|
3872
|
+
job: await this.#backend.add({
|
|
3873
|
+
...options,
|
|
3874
|
+
archive: location.archiveFile
|
|
3875
|
+
}),
|
|
3876
|
+
target: location.target
|
|
3877
|
+
};
|
|
3878
|
+
});
|
|
3879
|
+
return await this.#createHandle(resolved.job, resolved.target);
|
|
3887
3880
|
}
|
|
3888
3881
|
async clean() {
|
|
3889
|
-
return await this.#runtime.run(async () => await (0,
|
|
3882
|
+
return await this.#runtime.run(async () => await (0, import_wiki_graph_core15.cleanBuildJobs)());
|
|
3890
3883
|
}
|
|
3891
3884
|
async get(jobId) {
|
|
3892
|
-
return this.#
|
|
3893
|
-
|
|
3885
|
+
return await this.#runtime.run(
|
|
3886
|
+
async () => await this.#createHandle(await this.#backend.get(jobId))
|
|
3894
3887
|
);
|
|
3895
3888
|
}
|
|
3896
3889
|
async resolveId(reference) {
|
|
3897
3890
|
return await this.#runtime.run(
|
|
3898
|
-
async () => await (0,
|
|
3891
|
+
async () => await (0, import_wiki_graph_core15.resolveBuildJobId)(reference)
|
|
3899
3892
|
);
|
|
3900
3893
|
}
|
|
3901
3894
|
async list(options = {}) {
|
|
3902
|
-
|
|
3895
|
+
return await this.#runtime.run(async () => {
|
|
3903
3896
|
const normalized = {
|
|
3904
3897
|
...options.activeOnly === void 0 ? {} : { activeOnly: options.activeOnly },
|
|
3905
3898
|
...options.all === void 0 ? {} : { all: options.all },
|
|
3906
3899
|
...options.archive === void 0 ? {} : {
|
|
3907
|
-
archive:
|
|
3900
|
+
archive: (await resolveWikiGraphArchiveLocation(options.archive)).archiveFile
|
|
3908
3901
|
}
|
|
3909
3902
|
};
|
|
3910
|
-
|
|
3903
|
+
const jobs = await this.#backend.list(normalized);
|
|
3904
|
+
return await Promise.all(
|
|
3905
|
+
jobs.map(async (job) => await this.#createHandle(job))
|
|
3906
|
+
);
|
|
3911
3907
|
});
|
|
3912
|
-
return jobs.map((job) => this.#createHandle(job));
|
|
3913
3908
|
}
|
|
3914
3909
|
async resolveChapters(jobs) {
|
|
3915
3910
|
return await this.#runtime.run(async () => {
|
|
3916
3911
|
const jobsByArchive = /* @__PURE__ */ new Map();
|
|
3917
3912
|
for (const job of jobs) {
|
|
3918
|
-
const archivePath =
|
|
3913
|
+
const archivePath = getJobArchiveLocator(job);
|
|
3919
3914
|
const grouped = jobsByArchive.get(archivePath) ?? [];
|
|
3920
3915
|
grouped.push(job);
|
|
3921
3916
|
jobsByArchive.set(archivePath, grouped);
|
|
@@ -3923,9 +3918,12 @@ var WikiGraphJobManager = class {
|
|
|
3923
3918
|
const entries = (await Promise.all(
|
|
3924
3919
|
[...jobsByArchive].map(async ([archivePath, archiveJobs]) => {
|
|
3925
3920
|
try {
|
|
3926
|
-
const
|
|
3927
|
-
|
|
3928
|
-
)
|
|
3921
|
+
const location = await resolveWikiGraphArchiveLocation(
|
|
3922
|
+
archiveJobs[0].archive
|
|
3923
|
+
);
|
|
3924
|
+
const chapters = await new import_wiki_graph_core15.WikiGraphArchiveFile(
|
|
3925
|
+
location.archiveFile
|
|
3926
|
+
).readDocument(async (document) => await (0, import_wiki_graph_core15.listChapters)(document));
|
|
3929
3927
|
const chaptersById = new Map(
|
|
3930
3928
|
chapters.map((chapter) => [chapter.chapterId, chapter])
|
|
3931
3929
|
);
|
|
@@ -3935,7 +3933,7 @@ var WikiGraphJobManager = class {
|
|
|
3935
3933
|
[
|
|
3936
3934
|
job.jobId,
|
|
3937
3935
|
{
|
|
3938
|
-
locatedUri: (0,
|
|
3936
|
+
locatedUri: (0, import_wiki_graph_core15.formatLocatedChapterUri)(
|
|
3939
3937
|
archivePath,
|
|
3940
3938
|
chapter.path
|
|
3941
3939
|
),
|
|
@@ -3959,62 +3957,78 @@ var WikiGraphJobManager = class {
|
|
|
3959
3957
|
async enqueue(options) {
|
|
3960
3958
|
return await this.#runtime.run(async () => {
|
|
3961
3959
|
const location = await resolveWikiGraphArchiveLocation(options.archive);
|
|
3962
|
-
|
|
3963
|
-
|
|
3964
|
-
|
|
3965
|
-
|
|
3966
|
-
|
|
3967
|
-
|
|
3968
|
-
|
|
3969
|
-
|
|
3970
|
-
|
|
3971
|
-
|
|
3972
|
-
|
|
3973
|
-
|
|
3974
|
-
|
|
3975
|
-
|
|
3976
|
-
return checked;
|
|
3977
|
-
});
|
|
3978
|
-
const created = [];
|
|
3979
|
-
const skipped = [];
|
|
3980
|
-
for (const candidate of candidates) {
|
|
3981
|
-
if (candidate.reason !== void 0) {
|
|
3982
|
-
if (selectedExplicitly && candidates.length === 1) {
|
|
3983
|
-
throw new Error(
|
|
3984
|
-
formatQueueReadinessError(
|
|
3985
|
-
candidate.chapter,
|
|
3986
|
-
target,
|
|
3987
|
-
candidate.reason
|
|
3988
|
-
)
|
|
3960
|
+
return await (0, import_wiki_graph_core15.withArchiveBuildJobCreationLock)(
|
|
3961
|
+
location.archiveFile,
|
|
3962
|
+
async () => {
|
|
3963
|
+
const target = options.target ?? "reading-summary";
|
|
3964
|
+
await validateQueueTargetConfig(target, options.llmJSON);
|
|
3965
|
+
const selectedExplicitly = options.chapterId !== void 0 || options.chapterIds !== void 0 || options.chapterPath !== void 0 || options.depth !== void 0;
|
|
3966
|
+
const candidates = await new import_wiki_graph_core15.WikiGraphArchiveFile(
|
|
3967
|
+
location.archiveFile
|
|
3968
|
+
).readDocument(async (document) => {
|
|
3969
|
+
const chapters = await (0, import_wiki_graph_core15.listChapters)(document);
|
|
3970
|
+
const selected = await selectQueueChapters(
|
|
3971
|
+
document,
|
|
3972
|
+
chapters,
|
|
3973
|
+
options
|
|
3989
3974
|
);
|
|
3990
|
-
|
|
3991
|
-
|
|
3992
|
-
|
|
3993
|
-
|
|
3994
|
-
|
|
3995
|
-
|
|
3996
|
-
|
|
3997
|
-
|
|
3998
|
-
|
|
3999
|
-
|
|
4000
|
-
|
|
4001
|
-
archive: location.archiveFile,
|
|
4002
|
-
boost: options.boost ?? false,
|
|
4003
|
-
chapterId: candidate.chapter.chapterId,
|
|
4004
|
-
...options.llmJSON === void 0 ? {} : { llmJSON: options.llmJSON },
|
|
4005
|
-
...options.prompt === void 0 ? {} : { prompt: options.prompt },
|
|
4006
|
-
target
|
|
4007
|
-
})
|
|
4008
|
-
});
|
|
4009
|
-
} catch (error) {
|
|
4010
|
-
if (selectedExplicitly && candidates.length === 1) throw error;
|
|
4011
|
-
skipped.push({
|
|
4012
|
-
chapter: candidate.chapter,
|
|
4013
|
-
reason: error instanceof Error ? error.message : String(error)
|
|
3975
|
+
const checked = await Promise.all(
|
|
3976
|
+
selected.map(async (chapter) => ({
|
|
3977
|
+
chapter,
|
|
3978
|
+
reason: await readQueueReadinessReason(
|
|
3979
|
+
document,
|
|
3980
|
+
chapter,
|
|
3981
|
+
target
|
|
3982
|
+
)
|
|
3983
|
+
}))
|
|
3984
|
+
);
|
|
3985
|
+
return checked;
|
|
4014
3986
|
});
|
|
3987
|
+
const created = [];
|
|
3988
|
+
const skipped = [];
|
|
3989
|
+
for (const candidate of candidates) {
|
|
3990
|
+
if (candidate.reason !== void 0) {
|
|
3991
|
+
if (selectedExplicitly && candidates.length === 1) {
|
|
3992
|
+
throw new Error(
|
|
3993
|
+
formatQueueReadinessError(
|
|
3994
|
+
candidate.chapter,
|
|
3995
|
+
target,
|
|
3996
|
+
candidate.reason
|
|
3997
|
+
)
|
|
3998
|
+
);
|
|
3999
|
+
}
|
|
4000
|
+
skipped.push({
|
|
4001
|
+
chapter: candidate.chapter,
|
|
4002
|
+
reason: candidate.reason
|
|
4003
|
+
});
|
|
4004
|
+
continue;
|
|
4005
|
+
}
|
|
4006
|
+
try {
|
|
4007
|
+
created.push({
|
|
4008
|
+
chapter: candidate.chapter,
|
|
4009
|
+
job: await this.#createHandle(
|
|
4010
|
+
await this.#backend.add({
|
|
4011
|
+
archive: location.archiveFile,
|
|
4012
|
+
boost: options.boost ?? false,
|
|
4013
|
+
chapterId: candidate.chapter.chapterId,
|
|
4014
|
+
...options.llmJSON === void 0 ? {} : { llmJSON: options.llmJSON },
|
|
4015
|
+
...options.prompt === void 0 ? {} : { prompt: options.prompt },
|
|
4016
|
+
target
|
|
4017
|
+
}),
|
|
4018
|
+
location.target
|
|
4019
|
+
)
|
|
4020
|
+
});
|
|
4021
|
+
} catch (error) {
|
|
4022
|
+
if (selectedExplicitly && candidates.length === 1) throw error;
|
|
4023
|
+
skipped.push({
|
|
4024
|
+
chapter: candidate.chapter,
|
|
4025
|
+
reason: error instanceof Error ? error.message : String(error)
|
|
4026
|
+
});
|
|
4027
|
+
}
|
|
4028
|
+
}
|
|
4029
|
+
return { created, skipped };
|
|
4015
4030
|
}
|
|
4016
|
-
|
|
4017
|
-
return { created, skipped };
|
|
4031
|
+
);
|
|
4018
4032
|
});
|
|
4019
4033
|
}
|
|
4020
4034
|
async planEnqueue(options) {
|
|
@@ -4023,10 +4037,10 @@ var WikiGraphJobManager = class {
|
|
|
4023
4037
|
const target = options.target ?? "reading-summary";
|
|
4024
4038
|
await validateQueueTargetConfig(target, options.llmJSON);
|
|
4025
4039
|
const selectedExplicitly = options.chapterId !== void 0 || options.chapterIds !== void 0 || options.chapterPath !== void 0 || options.depth !== void 0;
|
|
4026
|
-
const candidates = await new
|
|
4040
|
+
const candidates = await new import_wiki_graph_core15.WikiGraphArchiveFile(
|
|
4027
4041
|
location.archiveFile
|
|
4028
4042
|
).readDocument(async (document) => {
|
|
4029
|
-
const chapters = await (0,
|
|
4043
|
+
const chapters = await (0, import_wiki_graph_core15.listChapters)(document);
|
|
4030
4044
|
const selected = await selectQueueChapters(document, chapters, options);
|
|
4031
4045
|
return await Promise.all(
|
|
4032
4046
|
selected.map(async (chapter) => ({
|
|
@@ -4060,34 +4074,39 @@ var WikiGraphJobManager = class {
|
|
|
4060
4074
|
this.#subscriptions.add(controller);
|
|
4061
4075
|
return () => this.#subscriptions.delete(controller);
|
|
4062
4076
|
}
|
|
4063
|
-
#createHandle(snapshot) {
|
|
4064
|
-
|
|
4077
|
+
async #createHandle(snapshot, target) {
|
|
4078
|
+
const legacy = snapshot;
|
|
4079
|
+
const resolvedTarget = target ?? (snapshot.archive === void 0 ? archiveTargetFromLogicalLocator(legacy.archivePath ?? "unknown.wikg") : await resolveWikiGraphArchiveTarget(snapshot.archive));
|
|
4080
|
+
return new WikiGraphJob(
|
|
4081
|
+
this,
|
|
4082
|
+
this.#runtime,
|
|
4083
|
+
this.#backend,
|
|
4084
|
+
snapshot,
|
|
4085
|
+
cloneWikiGraphArchiveTarget(resolvedTarget)
|
|
4086
|
+
);
|
|
4065
4087
|
}
|
|
4066
4088
|
};
|
|
4067
|
-
function
|
|
4068
|
-
|
|
4069
|
-
if (record.archive !== void 0) {
|
|
4070
|
-
return getNodeResourcePath(record.archive);
|
|
4071
|
-
}
|
|
4072
|
-
if (typeof record.archivePath === "string") return record.archivePath;
|
|
4073
|
-
throw new TypeError("Build job is missing archive");
|
|
4089
|
+
function getJobArchiveLocator(job) {
|
|
4090
|
+
return job.archive.kind === "library" ? job.archive.uri : job.archive.path;
|
|
4074
4091
|
}
|
|
4075
4092
|
var WikiGraphJob = class {
|
|
4076
4093
|
#manager;
|
|
4077
4094
|
#runtime;
|
|
4078
4095
|
#backend;
|
|
4096
|
+
#archiveTarget;
|
|
4079
4097
|
#snapshot;
|
|
4080
|
-
constructor(manager, runtime, backend, snapshot) {
|
|
4098
|
+
constructor(manager, runtime, backend, snapshot, archiveTarget) {
|
|
4081
4099
|
this.#manager = manager;
|
|
4082
4100
|
this.#runtime = runtime;
|
|
4083
4101
|
this.#backend = backend;
|
|
4084
4102
|
this.#snapshot = snapshot;
|
|
4103
|
+
this.#archiveTarget = archiveTarget;
|
|
4085
4104
|
}
|
|
4086
4105
|
get id() {
|
|
4087
4106
|
return this.#snapshot.jobId;
|
|
4088
4107
|
}
|
|
4089
4108
|
get snapshot() {
|
|
4090
|
-
return this.#snapshot;
|
|
4109
|
+
return toPublicJobSnapshot(this.#snapshot, this.#archiveTarget);
|
|
4091
4110
|
}
|
|
4092
4111
|
async status() {
|
|
4093
4112
|
return await this.#update(async () => await this.#backend.get(this.id));
|
|
@@ -4114,7 +4133,8 @@ var WikiGraphJob = class {
|
|
|
4114
4133
|
let cursor = 0;
|
|
4115
4134
|
let job = this.#snapshot;
|
|
4116
4135
|
if (options.from === "now") {
|
|
4117
|
-
|
|
4136
|
+
await this.status();
|
|
4137
|
+
job = this.#snapshot;
|
|
4118
4138
|
const chunk = await this.#readEventChunkSafely(job, cursor);
|
|
4119
4139
|
const events = chunk.events;
|
|
4120
4140
|
cursor = chunk.cursor;
|
|
@@ -4134,7 +4154,8 @@ var WikiGraphJob = class {
|
|
|
4134
4154
|
yield event;
|
|
4135
4155
|
}
|
|
4136
4156
|
if (sawTerminalEvent) return;
|
|
4137
|
-
|
|
4157
|
+
await this.status();
|
|
4158
|
+
job = this.#snapshot;
|
|
4138
4159
|
if (isTerminalState(job.state)) {
|
|
4139
4160
|
terminalReadsWithoutEvent += 1;
|
|
4140
4161
|
if (terminalReadsWithoutEvent >= TERMINAL_EVENT_GRACE_READS) return;
|
|
@@ -4171,7 +4192,7 @@ var WikiGraphJob = class {
|
|
|
4171
4192
|
}
|
|
4172
4193
|
async #update(operation) {
|
|
4173
4194
|
this.#snapshot = await this.#runtime.run(operation);
|
|
4174
|
-
return this
|
|
4195
|
+
return this.snapshot;
|
|
4175
4196
|
}
|
|
4176
4197
|
async #readEventChunk(job, cursor) {
|
|
4177
4198
|
return await this.#runtime.run(async () => {
|
|
@@ -4190,6 +4211,54 @@ var WikiGraphJob = class {
|
|
|
4190
4211
|
}
|
|
4191
4212
|
}
|
|
4192
4213
|
};
|
|
4214
|
+
function toPublicJobSnapshot(job, archive) {
|
|
4215
|
+
const legacy = job;
|
|
4216
|
+
return {
|
|
4217
|
+
archive: cloneWikiGraphArchiveTarget(archive),
|
|
4218
|
+
archiveKey: archive.kind === "library" ? archive.uri : job.archiveKey,
|
|
4219
|
+
...getJobResourcePath(job.cache, legacy.cachePath) === void 0 ? {} : { cachePath: getJobResourcePath(job.cache, legacy.cachePath) },
|
|
4220
|
+
chapterId: job.chapterId,
|
|
4221
|
+
createdAt: job.createdAt,
|
|
4222
|
+
...job.currentStep === void 0 ? {} : { currentStep: job.currentStep },
|
|
4223
|
+
...job.errorJSON === void 0 ? {} : { errorJSON: job.errorJSON },
|
|
4224
|
+
...getJobResourcePath(job.events, legacy.eventsPath) === void 0 ? {} : { eventsPath: getJobResourcePath(job.events, legacy.eventsPath) },
|
|
4225
|
+
...job.finishedAt === void 0 ? {} : { finishedAt: job.finishedAt },
|
|
4226
|
+
jobId: job.jobId,
|
|
4227
|
+
...job.inputRevision === void 0 ? {} : { inputRevision: job.inputRevision },
|
|
4228
|
+
...getJobResourcePath(job.log, legacy.logPath) === void 0 ? {} : { logPath: getJobResourcePath(job.log, legacy.logPath) },
|
|
4229
|
+
...job.llmJSON === void 0 ? {} : { llmJSON: job.llmJSON },
|
|
4230
|
+
...job.ownerId === void 0 ? {} : { ownerId: job.ownerId },
|
|
4231
|
+
...job.prompt === void 0 ? {} : { prompt: job.prompt },
|
|
4232
|
+
queueRank: job.queueRank,
|
|
4233
|
+
...job.readingSummaryStartedAt === void 0 ? {} : { readingSummaryStartedAt: job.readingSummaryStartedAt },
|
|
4234
|
+
state: job.state,
|
|
4235
|
+
target: job.target,
|
|
4236
|
+
updatedAt: job.updatedAt,
|
|
4237
|
+
...getJobResourcePath(job.workspace, legacy.workspacePath) === void 0 ? {} : {
|
|
4238
|
+
workspacePath: getJobResourcePath(
|
|
4239
|
+
job.workspace,
|
|
4240
|
+
legacy.workspacePath
|
|
4241
|
+
)
|
|
4242
|
+
}
|
|
4243
|
+
};
|
|
4244
|
+
}
|
|
4245
|
+
function cloneWikiGraphArchiveTarget(target) {
|
|
4246
|
+
return target.kind === "library" ? Object.freeze({ kind: "library", uri: target.uri }) : Object.freeze({
|
|
4247
|
+
kind: "standalone",
|
|
4248
|
+
path: target.path,
|
|
4249
|
+
...target.objectUri === void 0 ? {} : { objectUri: target.objectUri }
|
|
4250
|
+
});
|
|
4251
|
+
}
|
|
4252
|
+
function getJobResourcePath(resource, legacy) {
|
|
4253
|
+
if (resource === void 0) return legacy;
|
|
4254
|
+
try {
|
|
4255
|
+
return getNodeResourcePath(resource);
|
|
4256
|
+
} catch {
|
|
4257
|
+
const identity = resource.identity;
|
|
4258
|
+
if (typeof identity === "string") return identity;
|
|
4259
|
+
throw new TypeError("Expected a Node File or Directory resource");
|
|
4260
|
+
}
|
|
4261
|
+
}
|
|
4193
4262
|
async function selectQueueChapters(document, chapters, options) {
|
|
4194
4263
|
const ids = options.chapterIds ?? (options.chapterId === void 0 ? void 0 : [options.chapterId]);
|
|
4195
4264
|
if (ids !== void 0) {
|
|
@@ -4200,7 +4269,7 @@ async function selectQueueChapters(document, chapters, options) {
|
|
|
4200
4269
|
if (options.chapterPath === void 0) {
|
|
4201
4270
|
return options.depth === void 0 ? chapters : chapters.filter((chapter) => chapter.depth <= options.depth);
|
|
4202
4271
|
}
|
|
4203
|
-
const rootId = await (0,
|
|
4272
|
+
const rootId = await (0, import_wiki_graph_core15.resolveChapterPathReadonly)(
|
|
4204
4273
|
document,
|
|
4205
4274
|
options.chapterPath
|
|
4206
4275
|
);
|
|
@@ -4265,14 +4334,14 @@ function formatQueueReadinessError(chapter, target, reason) {
|
|
|
4265
4334
|
}
|
|
4266
4335
|
async function wait(milliseconds, signal) {
|
|
4267
4336
|
if (signal?.aborted === true) return;
|
|
4268
|
-
await new Promise((
|
|
4337
|
+
await new Promise((resolve4) => {
|
|
4269
4338
|
let settled = false;
|
|
4270
4339
|
const complete = () => {
|
|
4271
4340
|
if (settled) return;
|
|
4272
4341
|
settled = true;
|
|
4273
4342
|
clearTimeout(timeout);
|
|
4274
4343
|
signal?.removeEventListener("abort", complete);
|
|
4275
|
-
|
|
4344
|
+
resolve4();
|
|
4276
4345
|
};
|
|
4277
4346
|
const timeout = setTimeout(complete, milliseconds);
|
|
4278
4347
|
signal?.addEventListener("abort", complete, { once: true });
|
|
@@ -4294,8 +4363,8 @@ function forwardAbort(source, target) {
|
|
|
4294
4363
|
}
|
|
4295
4364
|
|
|
4296
4365
|
// src/libraries.ts
|
|
4297
|
-
var
|
|
4298
|
-
var
|
|
4366
|
+
var import_wiki_graph_core16 = require("wiki-graph-core");
|
|
4367
|
+
var import_promises5 = require("fs/promises");
|
|
4299
4368
|
var WikiGraphLibraryManager = class {
|
|
4300
4369
|
#runtime;
|
|
4301
4370
|
constructor(runtime) {
|
|
@@ -4304,80 +4373,109 @@ var WikiGraphLibraryManager = class {
|
|
|
4304
4373
|
async create(folder) {
|
|
4305
4374
|
const record = await this.#runtime.run(async () => {
|
|
4306
4375
|
const path = resolveWikiGraphRuntimePath(folder);
|
|
4307
|
-
await (0,
|
|
4308
|
-
return await (0,
|
|
4376
|
+
await (0, import_promises5.mkdir)(path);
|
|
4377
|
+
return await (0, import_wiki_graph_core16.createWikiGraphLibrary)({ folder: new NodeDirectory(path) });
|
|
4309
4378
|
});
|
|
4310
4379
|
return new WikiGraphLibrary(this.#runtime, record);
|
|
4311
4380
|
}
|
|
4312
|
-
async get(uri = (0,
|
|
4381
|
+
async get(uri = (0, import_wiki_graph_core16.formatWikiGraphLibraryUri)()) {
|
|
4313
4382
|
const target = requireLibraryTarget(uri);
|
|
4314
4383
|
const record = await this.#runtime.run(
|
|
4315
|
-
async () => await (0,
|
|
4384
|
+
async () => await (0, import_wiki_graph_core16.resolveWikiGraphLibrary)(target)
|
|
4316
4385
|
);
|
|
4317
4386
|
return new WikiGraphLibrary(this.#runtime, record);
|
|
4318
4387
|
}
|
|
4319
4388
|
async addArchive(options) {
|
|
4320
|
-
return
|
|
4321
|
-
|
|
4322
|
-
|
|
4323
|
-
|
|
4324
|
-
|
|
4325
|
-
|
|
4326
|
-
|
|
4327
|
-
|
|
4389
|
+
return toArchiveSnapshot(
|
|
4390
|
+
await this.#runtime.run(
|
|
4391
|
+
async () => await (0, import_wiki_graph_core16.addWikiGraphLibraryArchive)({
|
|
4392
|
+
inputFile: new NodeFile(
|
|
4393
|
+
await assertStandaloneWikiGraphArchivePath(options.inputPath)
|
|
4394
|
+
),
|
|
4395
|
+
target: requireLibraryTarget(options.target),
|
|
4396
|
+
...options.to === void 0 ? {} : { to: options.to }
|
|
4397
|
+
})
|
|
4398
|
+
)
|
|
4328
4399
|
);
|
|
4329
4400
|
}
|
|
4330
4401
|
async assertCurrent(target) {
|
|
4331
4402
|
await this.#runtime.run(
|
|
4332
|
-
async () => await (0,
|
|
4403
|
+
async () => await (0, import_wiki_graph_core16.assertWikiGraphLibrarySchemaCurrent)(requireLibraryTarget(target))
|
|
4333
4404
|
);
|
|
4334
4405
|
}
|
|
4335
4406
|
async rebind(target, folder) {
|
|
4336
|
-
return
|
|
4337
|
-
|
|
4338
|
-
|
|
4339
|
-
|
|
4340
|
-
|
|
4407
|
+
return toScanSnapshot(
|
|
4408
|
+
await this.#runtime.run(
|
|
4409
|
+
async () => await (0, import_wiki_graph_core16.rebindWikiGraphLibrary)({
|
|
4410
|
+
folder: new NodeDirectory(resolveWikiGraphRuntimePath(folder)),
|
|
4411
|
+
target: requireLibraryTarget(target)
|
|
4412
|
+
})
|
|
4413
|
+
)
|
|
4341
4414
|
);
|
|
4342
4415
|
}
|
|
4343
4416
|
async remove(target) {
|
|
4344
|
-
return
|
|
4345
|
-
|
|
4417
|
+
return toLibrarySnapshot(
|
|
4418
|
+
await this.#runtime.run(
|
|
4419
|
+
async () => await (0, import_wiki_graph_core16.removeWikiGraphLibrary)(requireLibraryTarget(target))
|
|
4420
|
+
)
|
|
4346
4421
|
);
|
|
4347
4422
|
}
|
|
4348
4423
|
async scan(target) {
|
|
4349
|
-
return
|
|
4350
|
-
|
|
4424
|
+
return toScanSnapshot(
|
|
4425
|
+
await this.#runtime.run(
|
|
4426
|
+
async () => await (0, import_wiki_graph_core16.scanWikiGraphLibrary)(requireLibraryTarget(target))
|
|
4427
|
+
)
|
|
4351
4428
|
);
|
|
4352
4429
|
}
|
|
4353
4430
|
async getArchive(target) {
|
|
4354
|
-
return
|
|
4355
|
-
|
|
4431
|
+
return toArchiveSnapshot(
|
|
4432
|
+
await this.#runtime.run(
|
|
4433
|
+
async () => await (0, import_wiki_graph_core16.getWikiGraphLibraryArchive)(requireLibraryTarget(target))
|
|
4434
|
+
)
|
|
4356
4435
|
);
|
|
4357
4436
|
}
|
|
4358
4437
|
async moveArchive(options) {
|
|
4359
|
-
return
|
|
4360
|
-
|
|
4361
|
-
|
|
4362
|
-
|
|
4363
|
-
|
|
4438
|
+
return toArchiveSnapshot(
|
|
4439
|
+
await this.#runtime.run(
|
|
4440
|
+
async () => await (0, import_wiki_graph_core16.moveWikiGraphLibraryArchive)({
|
|
4441
|
+
target: requireLibraryTarget(options.target),
|
|
4442
|
+
to: options.to
|
|
4443
|
+
})
|
|
4444
|
+
)
|
|
4364
4445
|
);
|
|
4365
4446
|
}
|
|
4366
4447
|
async removeArchive(target) {
|
|
4367
|
-
return
|
|
4368
|
-
|
|
4369
|
-
|
|
4448
|
+
return toArchiveSnapshot(
|
|
4449
|
+
await this.#runtime.run(
|
|
4450
|
+
async () => await (0, import_wiki_graph_core16.removeWikiGraphLibraryArchive)({
|
|
4451
|
+
target: requireLibraryTarget(target)
|
|
4452
|
+
})
|
|
4453
|
+
)
|
|
4454
|
+
);
|
|
4455
|
+
}
|
|
4456
|
+
async replaceArchive(options) {
|
|
4457
|
+
return toArchiveSnapshot(
|
|
4458
|
+
await this.#runtime.run(async () => {
|
|
4459
|
+
const target = requireLibraryTarget(options.target);
|
|
4460
|
+
const current = await (0, import_wiki_graph_core16.getWikiGraphLibraryArchive)(target);
|
|
4461
|
+
return await (0, import_wiki_graph_core16.replaceWikiGraphLibraryArchive)({
|
|
4462
|
+
additionalDerivedStateKeys: current.file === void 0 ? [] : [getNodeResourcePath(current.file)],
|
|
4463
|
+
inputFile: new NodeFile(
|
|
4464
|
+
await assertStandaloneWikiGraphArchivePath(options.inputPath)
|
|
4465
|
+
),
|
|
4466
|
+
target
|
|
4467
|
+
});
|
|
4370
4468
|
})
|
|
4371
4469
|
);
|
|
4372
4470
|
}
|
|
4373
4471
|
async indexState(target) {
|
|
4374
4472
|
return await this.#runtime.run(
|
|
4375
|
-
async () => await (0,
|
|
4473
|
+
async () => await (0, import_wiki_graph_core16.readWikiGraphLibraryIndexState)(requireLibraryTarget(target))
|
|
4376
4474
|
);
|
|
4377
4475
|
}
|
|
4378
4476
|
async rebuildIndex(target, onProgress) {
|
|
4379
4477
|
return await this.#runtime.run(
|
|
4380
|
-
async () => await (0,
|
|
4478
|
+
async () => await (0, import_wiki_graph_core16.rebuildWikiGraphLibraryIndex)(
|
|
4381
4479
|
requireLibraryTarget(target),
|
|
4382
4480
|
onProgress
|
|
4383
4481
|
)
|
|
@@ -4385,17 +4483,17 @@ var WikiGraphLibraryManager = class {
|
|
|
4385
4483
|
}
|
|
4386
4484
|
async cleanIndex(target) {
|
|
4387
4485
|
return await this.#runtime.run(
|
|
4388
|
-
async () => await (0,
|
|
4486
|
+
async () => await (0, import_wiki_graph_core16.cleanWikiGraphLibraryIndex)(requireLibraryTarget(target))
|
|
4389
4487
|
);
|
|
4390
4488
|
}
|
|
4391
4489
|
async getMetadata(target) {
|
|
4392
4490
|
return await this.#runtime.run(
|
|
4393
|
-
async () => await (0,
|
|
4491
|
+
async () => await (0, import_wiki_graph_core16.getWikiGraphLibraryMetadata)(requireLibraryTarget(target))
|
|
4394
4492
|
);
|
|
4395
4493
|
}
|
|
4396
4494
|
async replaceMetadata(target, value) {
|
|
4397
4495
|
return await this.#runtime.run(
|
|
4398
|
-
async () => await (0,
|
|
4496
|
+
async () => await (0, import_wiki_graph_core16.replaceWikiGraphLibraryMetadata)(
|
|
4399
4497
|
requireLibraryTarget(target),
|
|
4400
4498
|
value
|
|
4401
4499
|
)
|
|
@@ -4403,7 +4501,7 @@ var WikiGraphLibraryManager = class {
|
|
|
4403
4501
|
}
|
|
4404
4502
|
async putMetadata(target, key, value) {
|
|
4405
4503
|
return await this.#runtime.run(
|
|
4406
|
-
async () => await (0,
|
|
4504
|
+
async () => await (0, import_wiki_graph_core16.putWikiGraphLibraryMetadata)(
|
|
4407
4505
|
requireLibraryTarget(target),
|
|
4408
4506
|
key,
|
|
4409
4507
|
value
|
|
@@ -4412,7 +4510,7 @@ var WikiGraphLibraryManager = class {
|
|
|
4412
4510
|
}
|
|
4413
4511
|
async deleteMetadata(target, key) {
|
|
4414
4512
|
return await this.#runtime.run(
|
|
4415
|
-
async () => await (0,
|
|
4513
|
+
async () => await (0, import_wiki_graph_core16.deleteWikiGraphLibraryMetadataKey)(
|
|
4416
4514
|
requireLibraryTarget(target),
|
|
4417
4515
|
key
|
|
4418
4516
|
)
|
|
@@ -4420,13 +4518,13 @@ var WikiGraphLibraryManager = class {
|
|
|
4420
4518
|
}
|
|
4421
4519
|
async clearMetadata(target) {
|
|
4422
4520
|
return await this.#runtime.run(
|
|
4423
|
-
async () => await (0,
|
|
4521
|
+
async () => await (0, import_wiki_graph_core16.clearWikiGraphLibraryMetadata)(requireLibraryTarget(target))
|
|
4424
4522
|
);
|
|
4425
4523
|
}
|
|
4426
4524
|
async search(target, query, options = {}) {
|
|
4427
4525
|
return await this.#runtime.run(async () => {
|
|
4428
4526
|
const embeddingProvider = await createConfiguredEmbeddingProvider();
|
|
4429
|
-
return await (0,
|
|
4527
|
+
return await (0, import_wiki_graph_core16.findWikiGraphLibraryObjects)(
|
|
4430
4528
|
requireLibraryTarget(target),
|
|
4431
4529
|
query,
|
|
4432
4530
|
{
|
|
@@ -4439,7 +4537,7 @@ var WikiGraphLibraryManager = class {
|
|
|
4439
4537
|
async searchArchiveMembers(target, query, options = {}) {
|
|
4440
4538
|
return await this.#runtime.run(async () => {
|
|
4441
4539
|
const embeddingProvider = await createConfiguredEmbeddingProvider();
|
|
4442
|
-
return await (0,
|
|
4540
|
+
return await (0, import_wiki_graph_core16.findWikiGraphLibraryArchiveMembers)(
|
|
4443
4541
|
requireLibraryTarget(target),
|
|
4444
4542
|
query,
|
|
4445
4543
|
{
|
|
@@ -4451,7 +4549,7 @@ var WikiGraphLibraryManager = class {
|
|
|
4451
4549
|
}
|
|
4452
4550
|
async objects(target, options = {}) {
|
|
4453
4551
|
return await this.#runtime.run(
|
|
4454
|
-
async () => await (0,
|
|
4552
|
+
async () => await (0, import_wiki_graph_core16.listWikiGraphLibraryObjects)(
|
|
4455
4553
|
requireLibraryTarget(target),
|
|
4456
4554
|
options
|
|
4457
4555
|
)
|
|
@@ -4459,7 +4557,7 @@ var WikiGraphLibraryManager = class {
|
|
|
4459
4557
|
}
|
|
4460
4558
|
async archiveMembers(target, options = {}) {
|
|
4461
4559
|
return await this.#runtime.run(
|
|
4462
|
-
async () => await (0,
|
|
4560
|
+
async () => await (0, import_wiki_graph_core16.listWikiGraphLibraryArchiveMembers)(
|
|
4463
4561
|
requireLibraryTarget(target),
|
|
4464
4562
|
options
|
|
4465
4563
|
)
|
|
@@ -4469,17 +4567,18 @@ var WikiGraphLibraryManager = class {
|
|
|
4469
4567
|
return await this.#runtime.run(
|
|
4470
4568
|
async () => await withConfiguredWikimediaResolver(
|
|
4471
4569
|
objectUri,
|
|
4472
|
-
async (wikimediaOptions) => await (0,
|
|
4570
|
+
async (wikimediaOptions) => await (0, import_wiki_graph_core16.readWikiGraphLibraryPage)(
|
|
4473
4571
|
requireLibraryTarget(target),
|
|
4474
4572
|
objectUri,
|
|
4475
4573
|
{ ...options, ...wikimediaOptions }
|
|
4476
4574
|
)
|
|
4477
|
-
)
|
|
4575
|
+
),
|
|
4576
|
+
options.signal
|
|
4478
4577
|
);
|
|
4479
4578
|
}
|
|
4480
4579
|
async related(target, objectUri, options = {}) {
|
|
4481
4580
|
return await this.#runtime.run(
|
|
4482
|
-
async () => await (0,
|
|
4581
|
+
async () => await (0, import_wiki_graph_core16.listRelatedWikiGraphLibraryObjects)(
|
|
4483
4582
|
requireLibraryTarget(target),
|
|
4484
4583
|
objectUri,
|
|
4485
4584
|
options
|
|
@@ -4488,7 +4587,7 @@ var WikiGraphLibraryManager = class {
|
|
|
4488
4587
|
}
|
|
4489
4588
|
async evidence(target, objectUri, options = {}) {
|
|
4490
4589
|
return await this.#runtime.run(
|
|
4491
|
-
async () => await (0,
|
|
4590
|
+
async () => await (0, import_wiki_graph_core16.listWikiGraphLibraryEvidence)(
|
|
4492
4591
|
requireLibraryTarget(target),
|
|
4493
4592
|
objectUri,
|
|
4494
4593
|
options
|
|
@@ -4497,7 +4596,7 @@ var WikiGraphLibraryManager = class {
|
|
|
4497
4596
|
}
|
|
4498
4597
|
async pack(target, objectUri, budget = 5e3) {
|
|
4499
4598
|
return await this.#runtime.run(
|
|
4500
|
-
async () => await (0,
|
|
4599
|
+
async () => await (0, import_wiki_graph_core16.packWikiGraphLibraryContext)(
|
|
4501
4600
|
requireLibraryTarget(target),
|
|
4502
4601
|
objectUri,
|
|
4503
4602
|
budget
|
|
@@ -4506,7 +4605,7 @@ var WikiGraphLibraryManager = class {
|
|
|
4506
4605
|
}
|
|
4507
4606
|
async list() {
|
|
4508
4607
|
const records = await this.#runtime.run(
|
|
4509
|
-
async () => await (0,
|
|
4608
|
+
async () => await (0, import_wiki_graph_core16.listWikiGraphLibraries)()
|
|
4510
4609
|
);
|
|
4511
4610
|
return records.map((record) => new WikiGraphLibrary(this.#runtime, record));
|
|
4512
4611
|
}
|
|
@@ -4519,35 +4618,57 @@ var WikiGraphLibrary = class {
|
|
|
4519
4618
|
this.#record = record;
|
|
4520
4619
|
}
|
|
4521
4620
|
get snapshot() {
|
|
4522
|
-
return this.#record;
|
|
4621
|
+
return toLibrarySnapshot(this.#record);
|
|
4523
4622
|
}
|
|
4524
4623
|
get uri() {
|
|
4525
|
-
return (0,
|
|
4624
|
+
return (0, import_wiki_graph_core16.formatWikiGraphLibraryUri)(
|
|
4526
4625
|
this.#record.isDefault ? void 0 : this.#record.publicId
|
|
4527
4626
|
);
|
|
4528
4627
|
}
|
|
4529
4628
|
async archives() {
|
|
4530
4629
|
const target = requireLibraryTarget(this.uri);
|
|
4531
|
-
return await this.#runtime.run(
|
|
4532
|
-
async () => await (0,
|
|
4533
|
-
);
|
|
4630
|
+
return (await this.#runtime.run(
|
|
4631
|
+
async () => await (0, import_wiki_graph_core16.listWikiGraphLibraryArchives)(target)
|
|
4632
|
+
)).map(toArchiveSnapshot);
|
|
4534
4633
|
}
|
|
4535
4634
|
async scan() {
|
|
4536
4635
|
const target = requireLibraryTarget(this.uri);
|
|
4537
|
-
return
|
|
4538
|
-
async () => await (0,
|
|
4636
|
+
return toScanSnapshot(
|
|
4637
|
+
await this.#runtime.run(async () => await (0, import_wiki_graph_core16.scanWikiGraphLibrary)(target))
|
|
4539
4638
|
);
|
|
4540
4639
|
}
|
|
4541
4640
|
async remove() {
|
|
4542
4641
|
const target = requireLibraryTarget(this.uri);
|
|
4543
|
-
return
|
|
4544
|
-
async () => await (0,
|
|
4642
|
+
return toLibrarySnapshot(
|
|
4643
|
+
await this.#runtime.run(async () => await (0, import_wiki_graph_core16.removeWikiGraphLibrary)(target))
|
|
4545
4644
|
);
|
|
4546
4645
|
}
|
|
4547
4646
|
};
|
|
4647
|
+
function toLibrarySnapshot(record) {
|
|
4648
|
+
const compatible = record;
|
|
4649
|
+
return {
|
|
4650
|
+
id: record.id,
|
|
4651
|
+
publicId: record.publicId,
|
|
4652
|
+
uri: record.uri,
|
|
4653
|
+
folderPath: compatible.folderPath ?? (record.folder === void 0 ? "" : getNodeResourcePath(record.folder)),
|
|
4654
|
+
isDefault: record.isDefault,
|
|
4655
|
+
createdAt: record.createdAt,
|
|
4656
|
+
updatedAt: record.updatedAt
|
|
4657
|
+
};
|
|
4658
|
+
}
|
|
4659
|
+
function toArchiveSnapshot(record) {
|
|
4660
|
+
const { file: _file, ...snapshot } = record;
|
|
4661
|
+
return snapshot;
|
|
4662
|
+
}
|
|
4663
|
+
function toScanSnapshot(result) {
|
|
4664
|
+
return {
|
|
4665
|
+
...result.library === void 0 ? {} : { library: toLibrarySnapshot(result.library) },
|
|
4666
|
+
archives: result.archives.map(toArchiveSnapshot)
|
|
4667
|
+
};
|
|
4668
|
+
}
|
|
4548
4669
|
function requireLibraryTarget(value) {
|
|
4549
4670
|
if (typeof value !== "string") return value;
|
|
4550
|
-
const target = (0,
|
|
4671
|
+
const target = (0, import_wiki_graph_core16.parseWikiGraphLibraryUri)(value);
|
|
4551
4672
|
if (target === void 0) {
|
|
4552
4673
|
throw new TypeError(`Invalid Wiki Graph library URI: ${value}`);
|
|
4553
4674
|
}
|
|
@@ -4555,8 +4676,8 @@ function requireLibraryTarget(value) {
|
|
|
4555
4676
|
}
|
|
4556
4677
|
|
|
4557
4678
|
// src/maintenance.ts
|
|
4558
|
-
var
|
|
4559
|
-
var
|
|
4679
|
+
var import_wiki_graph_core17 = require("wiki-graph-core");
|
|
4680
|
+
var import_path6 = require("path");
|
|
4560
4681
|
var WikiGraphMaintenanceManager = class {
|
|
4561
4682
|
#runtime;
|
|
4562
4683
|
constructor(runtime) {
|
|
@@ -4566,22 +4687,22 @@ var WikiGraphMaintenanceManager = class {
|
|
|
4566
4687
|
return await this.#runtime.run(
|
|
4567
4688
|
async () => {
|
|
4568
4689
|
if (target.kind === "home") {
|
|
4569
|
-
return await (0,
|
|
4690
|
+
return await (0, import_wiki_graph_core17.upgradeWikiGraphMaintenanceTarget)({ kind: "home" });
|
|
4570
4691
|
}
|
|
4571
4692
|
if (target.kind === "library") {
|
|
4572
|
-
const parsed = (0,
|
|
4693
|
+
const parsed = (0, import_wiki_graph_core17.parseWikiGraphLibraryUri)(target.uri);
|
|
4573
4694
|
if (parsed === void 0 || parsed.kind === "archive") {
|
|
4574
4695
|
throw new Error(
|
|
4575
4696
|
`Invalid Wiki Graph library upgrade target: ${target.uri}`
|
|
4576
4697
|
);
|
|
4577
4698
|
}
|
|
4578
|
-
return await (0,
|
|
4699
|
+
return await (0, import_wiki_graph_core17.upgradeWikiGraphMaintenanceTarget)({
|
|
4579
4700
|
kind: "library",
|
|
4580
4701
|
target: parsed
|
|
4581
4702
|
});
|
|
4582
4703
|
}
|
|
4583
|
-
const path =
|
|
4584
|
-
return await (0,
|
|
4704
|
+
const path = await assertStandaloneWikiGraphArchivePath(target.path);
|
|
4705
|
+
return await (0, import_wiki_graph_core17.upgradeWikiGraphMaintenanceTarget)({
|
|
4585
4706
|
file: new NodeFile(path),
|
|
4586
4707
|
kind: "archive"
|
|
4587
4708
|
});
|
|
@@ -4594,9 +4715,9 @@ var WikiGraphMaintenanceManager = class {
|
|
|
4594
4715
|
return await this.#runtime.run(async () => {
|
|
4595
4716
|
const resolvedInputPath = resolveWikiGraphRuntimePath(inputPath);
|
|
4596
4717
|
const resolvedOutputPath = resolveWikiGraphRuntimePath(outputPath);
|
|
4597
|
-
await (0,
|
|
4718
|
+
await (0, import_wiki_graph_core17.migrateLegacySdpubToWikg)(
|
|
4598
4719
|
new NodeFile(resolvedInputPath),
|
|
4599
|
-
new NodeFile(resolvedOutputPath, (0,
|
|
4720
|
+
new NodeFile(resolvedOutputPath, (0, import_path6.basename)(resolvedOutputPath))
|
|
4600
4721
|
);
|
|
4601
4722
|
return {
|
|
4602
4723
|
inputPath: resolvedInputPath,
|
|
@@ -4610,7 +4731,7 @@ function defaultWikgOutputPath(inputPath) {
|
|
|
4610
4731
|
}
|
|
4611
4732
|
|
|
4612
4733
|
// src/sdk.ts
|
|
4613
|
-
var
|
|
4734
|
+
var import_wiki_graph_core18 = require("wiki-graph-core");
|
|
4614
4735
|
var WikiGraphSDK = class {
|
|
4615
4736
|
#context;
|
|
4616
4737
|
#homeReady;
|
|
@@ -4641,7 +4762,7 @@ var WikiGraphSDK = class {
|
|
|
4641
4762
|
throwIfAborted(signal);
|
|
4642
4763
|
const runWithContext = async () => await withWikiGraphSDKRuntimeContext(this.#context, async () => {
|
|
4643
4764
|
if (options.skipHomeBootstrap !== true) {
|
|
4644
|
-
this.#homeReady ??= (0,
|
|
4765
|
+
this.#homeReady ??= (0, import_wiki_graph_core18.ensureWikiGraphHomeSchemaCurrent)().catch(
|
|
4645
4766
|
(error) => {
|
|
4646
4767
|
this.#homeReady = void 0;
|
|
4647
4768
|
throw error;
|
|
@@ -4671,7 +4792,7 @@ function createWikiGraphSDK(options = {}) {
|
|
|
4671
4792
|
}
|
|
4672
4793
|
|
|
4673
4794
|
// src/index.ts
|
|
4674
|
-
var
|
|
4795
|
+
var import_wiki_graph_core19 = require("wiki-graph-core");
|
|
4675
4796
|
// Annotate the CommonJS export names for ESM import in node:
|
|
4676
4797
|
0 && (module.exports = {
|
|
4677
4798
|
DANGEROUS_RUNTIME_ENV_NAMES,
|
|
@@ -4687,6 +4808,7 @@ var import_wiki_graph_core16 = require("wiki-graph-core");
|
|
|
4687
4808
|
WikiGraphArchiveExistsError,
|
|
4688
4809
|
WikiGraphArchiveHandle,
|
|
4689
4810
|
WikiGraphArchiveManager,
|
|
4811
|
+
WikiGraphArchiveOwnershipError,
|
|
4690
4812
|
WikiGraphConfigManager,
|
|
4691
4813
|
WikiGraphContinuationManager,
|
|
4692
4814
|
WikiGraphConversionManager,
|
|
@@ -4705,7 +4827,6 @@ var import_wiki_graph_core16 = require("wiki-graph-core");
|
|
|
4705
4827
|
createNodeTemplateEnvironment,
|
|
4706
4828
|
createNodeWikiGraphStorage,
|
|
4707
4829
|
createStageLLM,
|
|
4708
|
-
createWikiGraphArchiveInspectReport,
|
|
4709
4830
|
createWikiGraphSDK,
|
|
4710
4831
|
deleteLocalConfigValue,
|
|
4711
4832
|
embedQueryText,
|
|
@@ -4723,6 +4844,7 @@ var import_wiki_graph_core16 = require("wiki-graph-core");
|
|
|
4723
4844
|
getNodeResourcePath,
|
|
4724
4845
|
getWikiGraphSDKRuntimeContext,
|
|
4725
4846
|
getWikiGraphSDKStateDir,
|
|
4847
|
+
inspectWikiGraphArchive,
|
|
4726
4848
|
installNodeWikiGraphPlatform,
|
|
4727
4849
|
isSourceLocatorScopeUri,
|
|
4728
4850
|
isWikiGraphLibraryUri,
|
|
@@ -4749,7 +4871,6 @@ var import_wiki_graph_core16 = require("wiki-graph-core");
|
|
|
4749
4871
|
resolveExtractionPrompt,
|
|
4750
4872
|
resolveHostedProviderEndpoint,
|
|
4751
4873
|
resolveKnowledgeGraphRecallPrompt,
|
|
4752
|
-
resolveWikiGraphArchiveLocation,
|
|
4753
4874
|
resolveWikispineConfig,
|
|
4754
4875
|
runWikiGraphQueueWorker,
|
|
4755
4876
|
validateLocalConfigSection,
|