wiki-graph-sdk 0.7.1 → 0.8.1
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 +22 -1
- package/dist/archives.cjs +494 -656
- package/dist/archives.cjs.map +1 -1
- package/dist/archives.d.ts +48 -80
- package/dist/archives.js +431 -585
- package/dist/archives.js.map +1 -1
- package/dist/conversions.cjs +183 -33
- package/dist/conversions.cjs.map +1 -1
- package/dist/conversions.d.ts +8 -1
- package/dist/conversions.js +188 -29
- package/dist/conversions.js.map +1 -1
- package/dist/default-worker.cjs +322 -62
- package/dist/default-worker.cjs.map +1 -1
- package/dist/default-worker.d.ts +1 -0
- package/dist/default-worker.js +336 -60
- package/dist/default-worker.js.map +1 -1
- package/dist/embedding.cjs +2 -1
- package/dist/embedding.cjs.map +1 -1
- package/dist/embedding.d.ts +4 -4
- package/dist/embedding.js +2 -1
- package/dist/embedding.js.map +1 -1
- package/dist/index.cjs +1295 -949
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +58 -24
- package/dist/index.js +1164 -805
- package/dist/index.js.map +1 -1
- package/dist/{jobs-Dd5PMSId.d.ts → jobs-CRK-DZ40.d.ts} +27 -14
- package/dist/local-config.cjs +2 -1
- package/dist/local-config.cjs.map +1 -1
- package/dist/local-config.js +2 -1
- package/dist/local-config.js.map +1 -1
- package/dist/maintenance.cjs +140 -30
- package/dist/maintenance.cjs.map +1 -1
- package/dist/maintenance.d.ts +5 -1
- package/dist/maintenance.js +145 -26
- package/dist/maintenance.js.map +1 -1
- package/dist/runtime-config.cjs +4 -3
- package/dist/runtime-config.cjs.map +1 -1
- package/dist/runtime-config.d.ts +4 -1
- package/dist/runtime-config.js +4 -3
- package/dist/runtime-config.js.map +1 -1
- package/dist/stage-BnWI3Rqt.d.ts +33 -0
- package/dist/stage.cjs +22 -12
- package/dist/stage.cjs.map +1 -1
- package/dist/stage.d.ts +2 -14
- package/dist/stage.js +22 -12
- package/dist/stage.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 +295 -25
- package/dist/worker.cjs.map +1 -1
- package/dist/worker.d.ts +28 -5
- package/dist/worker.js +313 -28
- 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,52 @@ __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
|
+
getWikiGraphSDKProviders: () => getWikiGraphSDKProviders,
|
|
81
82
|
getWikiGraphSDKRuntimeContext: () => getWikiGraphSDKRuntimeContext,
|
|
82
83
|
getWikiGraphSDKStateDir: () => getWikiGraphSDKStateDir,
|
|
84
|
+
inspectWikiGraphArchive: () => inspectWikiGraphArchive,
|
|
83
85
|
installNodeWikiGraphPlatform: () => installNodeWikiGraphPlatform,
|
|
84
|
-
isSourceLocatorScopeUri: () =>
|
|
85
|
-
isWikiGraphLibraryUri: () =>
|
|
86
|
+
isSourceLocatorScopeUri: () => import_wiki_graph_core19.isSourceLocatorScopeUri,
|
|
87
|
+
isWikiGraphLibraryUri: () => import_wiki_graph_core19.isWikiGraphLibraryUri,
|
|
86
88
|
loadRequiredStageConfig: () => loadRequiredStageConfig,
|
|
87
89
|
loadWikiGraphRuntimeConfig: () => loadWikiGraphRuntimeConfig,
|
|
88
90
|
maskLocalConfigSection: () => maskLocalConfigSection,
|
|
89
91
|
nodeWikiGraphPlatform: () => nodeWikiGraphPlatform,
|
|
90
92
|
nodeWikispineCommandRunner: () => nodeWikispineCommandRunner,
|
|
91
93
|
normalizeLocalConfigKey: () => normalizeLocalConfigKey,
|
|
92
|
-
parseChapterPath: () =>
|
|
93
|
-
parseChapterTreeInput: () =>
|
|
94
|
-
parseChapterUriPath: () =>
|
|
94
|
+
parseChapterPath: () => import_wiki_graph_core19.parseChapterPath,
|
|
95
|
+
parseChapterTreeInput: () => import_wiki_graph_core19.parseChapterTreeInput,
|
|
96
|
+
parseChapterUriPath: () => import_wiki_graph_core19.parseChapterUriPath,
|
|
95
97
|
parseLocalConfigSection: () => parseLocalConfigSection,
|
|
96
|
-
parseLocatedWikiGraphUri: () =>
|
|
97
|
-
parseSourceTextJsonl: () =>
|
|
98
|
-
parseWikiGraphLibraryUri: () =>
|
|
99
|
-
parseWikiGraphUriSyntax: () =>
|
|
98
|
+
parseLocatedWikiGraphUri: () => import_wiki_graph_core19.parseLocatedWikiGraphUri,
|
|
99
|
+
parseSourceTextJsonl: () => import_wiki_graph_core19.parseSourceTextJsonl,
|
|
100
|
+
parseWikiGraphLibraryUri: () => import_wiki_graph_core19.parseWikiGraphLibraryUri,
|
|
101
|
+
parseWikiGraphUriSyntax: () => import_wiki_graph_core19.parseWikiGraphUriSyntax,
|
|
100
102
|
planGenerationTask: () => planGenerationTask,
|
|
101
103
|
putLocalConfigValue: () => putLocalConfigValue,
|
|
102
104
|
readLocalConfigSection: () => readLocalConfigSection,
|
|
103
105
|
readWikiGraphEmbeddingConfig: () => readWikiGraphEmbeddingConfig,
|
|
104
106
|
replaceLocalConfigSection: () => replaceLocalConfigSection,
|
|
105
107
|
requireKnowledgeGraphWikispineConfig: () => requireKnowledgeGraphWikispineConfig,
|
|
106
|
-
resolveExtractionPrompt: () =>
|
|
108
|
+
resolveExtractionPrompt: () => import_wiki_graph_core10.resolveExtractionPrompt,
|
|
107
109
|
resolveHostedProviderEndpoint: () => resolveHostedProviderEndpoint,
|
|
108
|
-
resolveKnowledgeGraphRecallPrompt: () =>
|
|
109
|
-
|
|
110
|
+
resolveKnowledgeGraphRecallPrompt: () => import_wiki_graph_core10.resolveKnowledgeGraphRecallPrompt,
|
|
111
|
+
resolveWikiGraphLLMJSON: () => resolveWikiGraphLLMJSON,
|
|
110
112
|
resolveWikispineConfig: () => resolveWikispineConfig,
|
|
111
113
|
runWikiGraphQueueWorker: () => runWikiGraphQueueWorker,
|
|
112
114
|
validateLocalConfigSection: () => validateLocalConfigSection,
|
|
@@ -118,18 +120,18 @@ module.exports = __toCommonJS(src_exports);
|
|
|
118
120
|
|
|
119
121
|
// src/archive/archive.ts
|
|
120
122
|
var import_crypto2 = require("crypto");
|
|
121
|
-
var
|
|
123
|
+
var import_promises4 = require("fs/promises");
|
|
122
124
|
var import_os3 = require("os");
|
|
123
|
-
var
|
|
125
|
+
var import_path5 = require("path");
|
|
124
126
|
var import_stream = require("stream");
|
|
125
|
-
var
|
|
127
|
+
var import_wiki_graph_core7 = require("wiki-graph-core");
|
|
126
128
|
|
|
127
129
|
// src/conversions.ts
|
|
128
130
|
var import_crypto = require("crypto");
|
|
129
131
|
var import_fs = require("fs");
|
|
130
|
-
var
|
|
131
|
-
var
|
|
132
|
-
var
|
|
132
|
+
var import_promises3 = require("fs/promises");
|
|
133
|
+
var import_path4 = require("path");
|
|
134
|
+
var import_wiki_graph_core3 = require("wiki-graph-core");
|
|
133
135
|
|
|
134
136
|
// src/llm.ts
|
|
135
137
|
var import_anthropic = require("@ai-sdk/anthropic");
|
|
@@ -449,42 +451,42 @@ var NodeDatabaseConnection = class {
|
|
|
449
451
|
}
|
|
450
452
|
database;
|
|
451
453
|
async close() {
|
|
452
|
-
await new Promise((
|
|
454
|
+
await new Promise((resolve4, reject) => {
|
|
453
455
|
this.database.close((error) => {
|
|
454
456
|
if (error) reject(error);
|
|
455
|
-
else
|
|
457
|
+
else resolve4();
|
|
456
458
|
});
|
|
457
459
|
});
|
|
458
460
|
}
|
|
459
461
|
async execute(sql) {
|
|
460
|
-
await new Promise((
|
|
462
|
+
await new Promise((resolve4, reject) => {
|
|
461
463
|
this.database.exec(sql, (error) => {
|
|
462
464
|
if (error) reject(error);
|
|
463
|
-
else
|
|
465
|
+
else resolve4();
|
|
464
466
|
});
|
|
465
467
|
});
|
|
466
468
|
}
|
|
467
469
|
async queryAll(sql, params = []) {
|
|
468
|
-
return await new Promise((
|
|
470
|
+
return await new Promise((resolve4, reject) => {
|
|
469
471
|
this.database.all(sql, [...params], (error, rows) => {
|
|
470
472
|
if (error) reject(error);
|
|
471
|
-
else
|
|
473
|
+
else resolve4(rows);
|
|
472
474
|
});
|
|
473
475
|
});
|
|
474
476
|
}
|
|
475
477
|
async queryOne(sql, params = []) {
|
|
476
|
-
return await new Promise((
|
|
478
|
+
return await new Promise((resolve4, reject) => {
|
|
477
479
|
this.database.get(sql, [...params], (error, row) => {
|
|
478
480
|
if (error) reject(error);
|
|
479
|
-
else
|
|
481
|
+
else resolve4(row);
|
|
480
482
|
});
|
|
481
483
|
});
|
|
482
484
|
}
|
|
483
485
|
async run(sql, params = []) {
|
|
484
|
-
await new Promise((
|
|
486
|
+
await new Promise((resolve4, reject) => {
|
|
485
487
|
this.database.run(sql, [...params], (error) => {
|
|
486
488
|
if (error) reject(error);
|
|
487
|
-
else
|
|
489
|
+
else resolve4();
|
|
488
490
|
});
|
|
489
491
|
});
|
|
490
492
|
}
|
|
@@ -498,10 +500,10 @@ async function openNativeNodeDatabase(file, flags) {
|
|
|
498
500
|
if (path === void 0) {
|
|
499
501
|
throw new TypeError("The Node database adapter requires a NodeFile");
|
|
500
502
|
}
|
|
501
|
-
return await new Promise((
|
|
503
|
+
return await new Promise((resolve4, reject) => {
|
|
502
504
|
const database = new nodeSqlite3.Database(path, flags, (error) => {
|
|
503
505
|
if (error) reject(error);
|
|
504
|
-
else
|
|
506
|
+
else resolve4(database);
|
|
505
507
|
});
|
|
506
508
|
});
|
|
507
509
|
}
|
|
@@ -510,19 +512,19 @@ async function openNodeZip(file) {
|
|
|
510
512
|
if (path === void 0) {
|
|
511
513
|
throw new TypeError("The Node ZIP adapter requires a NodeFile");
|
|
512
514
|
}
|
|
513
|
-
const zipFile = await new Promise((
|
|
515
|
+
const zipFile = await new Promise((resolve4, reject) => {
|
|
514
516
|
yauzl.open(
|
|
515
517
|
path,
|
|
516
518
|
{ autoClose: false, lazyEntries: true },
|
|
517
519
|
(error, opened) => {
|
|
518
520
|
if (error || opened === void 0)
|
|
519
521
|
reject(error ?? new Error("Cannot open ZIP"));
|
|
520
|
-
else
|
|
522
|
+
else resolve4(opened);
|
|
521
523
|
}
|
|
522
524
|
);
|
|
523
525
|
});
|
|
524
526
|
const entries = await new Promise(
|
|
525
|
-
(
|
|
527
|
+
(resolve4, reject) => {
|
|
526
528
|
const discovered = /* @__PURE__ */ new Map();
|
|
527
529
|
const rejectAndClose = (error) => {
|
|
528
530
|
zipFile.close();
|
|
@@ -532,7 +534,7 @@ async function openNodeZip(file) {
|
|
|
532
534
|
};
|
|
533
535
|
const resolveEntries = () => {
|
|
534
536
|
zipFile.off("error", rejectAndClose);
|
|
535
|
-
|
|
537
|
+
resolve4(discovered);
|
|
536
538
|
};
|
|
537
539
|
zipFile.on("entry", (entry) => {
|
|
538
540
|
if (!entry.fileName.endsWith("/")) {
|
|
@@ -642,12 +644,12 @@ async function collectDecodedNodeStreamRange(input, offset, length) {
|
|
|
642
644
|
return Buffer.concat(chunks, collected);
|
|
643
645
|
}
|
|
644
646
|
async function openNodeZipEntryStream(zipFile, entry, options) {
|
|
645
|
-
return await new Promise((
|
|
647
|
+
return await new Promise((resolve4, reject) => {
|
|
646
648
|
const callback = (error, opened) => {
|
|
647
649
|
if (error || opened === void 0) {
|
|
648
650
|
reject(error ?? new Error(`Cannot read ZIP entry: ${entry.fileName}`));
|
|
649
651
|
} else {
|
|
650
|
-
|
|
652
|
+
resolve4(opened);
|
|
651
653
|
}
|
|
652
654
|
};
|
|
653
655
|
if (options === void 0) zipFile.openReadStream(entry, callback);
|
|
@@ -778,11 +780,11 @@ async function writeNodeStream(input, writer) {
|
|
|
778
780
|
);
|
|
779
781
|
}
|
|
780
782
|
async function collectNodeStream(input) {
|
|
781
|
-
return await new Promise((
|
|
783
|
+
return await new Promise((resolve4, reject) => {
|
|
782
784
|
const chunks = [];
|
|
783
785
|
input.on("data", (chunk) => chunks.push(chunk));
|
|
784
786
|
input.once("error", reject);
|
|
785
|
-
input.once("end", () =>
|
|
787
|
+
input.once("end", () => resolve4(Buffer.concat(chunks)));
|
|
786
788
|
});
|
|
787
789
|
}
|
|
788
790
|
var nodeWikiGraphPlatform = {
|
|
@@ -936,12 +938,16 @@ function getWikiGraphSDKRuntimeContext() {
|
|
|
936
938
|
return runtimeContext.getStore() ?? {
|
|
937
939
|
cwd: process.cwd(),
|
|
938
940
|
env: process.env,
|
|
939
|
-
envPolicy: "production"
|
|
941
|
+
envPolicy: "production",
|
|
942
|
+
providers: {}
|
|
940
943
|
};
|
|
941
944
|
}
|
|
942
945
|
function getWikiGraphSDKStateDir() {
|
|
943
946
|
return getWikiGraphSDKRuntimeContext().stateDir;
|
|
944
947
|
}
|
|
948
|
+
function getWikiGraphSDKProviders() {
|
|
949
|
+
return getWikiGraphSDKRuntimeContext().providers ?? {};
|
|
950
|
+
}
|
|
945
951
|
|
|
946
952
|
// src/local-config.ts
|
|
947
953
|
var import_path = require("path");
|
|
@@ -1242,8 +1248,8 @@ var inlineLLMConfigSchema = import_zod.z.object({
|
|
|
1242
1248
|
});
|
|
1243
1249
|
async function loadWikiGraphRuntimeConfig(options) {
|
|
1244
1250
|
const [embedding, localLLM, concurrent, wikimedia, wikispine] = await Promise.all([
|
|
1245
|
-
readLocalConfigSection("embeddings"),
|
|
1246
|
-
readLocalConfigSection("llm"),
|
|
1251
|
+
options?.skipEmbeddingConfig === true ? Promise.resolve({}) : readLocalConfigSection("embeddings"),
|
|
1252
|
+
options?.skipLLMConfig === true ? Promise.resolve({}) : readLocalConfigSection("llm"),
|
|
1247
1253
|
readLocalConfigSection("concurrent"),
|
|
1248
1254
|
readLocalConfigSection("wikimedia"),
|
|
1249
1255
|
readLocalConfigSection("wikispine")
|
|
@@ -1439,6 +1445,14 @@ function formatError2(error) {
|
|
|
1439
1445
|
return error instanceof Error ? error.message : String(error);
|
|
1440
1446
|
}
|
|
1441
1447
|
|
|
1448
|
+
// src/providers.ts
|
|
1449
|
+
function resolveWikiGraphLLMJSON(options) {
|
|
1450
|
+
if (options.llm !== void 0 && options.llmJSON !== void 0) {
|
|
1451
|
+
throw new Error("Pass either llm or llmJSON, not both.");
|
|
1452
|
+
}
|
|
1453
|
+
return options.llm === void 0 ? options.llmJSON : JSON.stringify(options.llm);
|
|
1454
|
+
}
|
|
1455
|
+
|
|
1442
1456
|
// src/runtime-path.ts
|
|
1443
1457
|
var import_os2 = require("os");
|
|
1444
1458
|
var import_path2 = require("path");
|
|
@@ -1451,6 +1465,194 @@ function resolveWikiGraphRuntimePath(path) {
|
|
|
1451
1465
|
return (0, import_path2.isAbsolute)(path) ? path : (0, import_path2.resolve)(context.cwd, path);
|
|
1452
1466
|
}
|
|
1453
1467
|
|
|
1468
|
+
// src/archive/target.ts
|
|
1469
|
+
var import_promises2 = require("fs/promises");
|
|
1470
|
+
var import_path3 = require("path");
|
|
1471
|
+
var import_wiki_graph_core2 = require("wiki-graph-core");
|
|
1472
|
+
var WikiGraphArchiveOwnershipError = class extends Error {
|
|
1473
|
+
code = "WIKI_GRAPH_ARCHIVE_OWNERSHIP_MISMATCH";
|
|
1474
|
+
constructor(message) {
|
|
1475
|
+
super(message);
|
|
1476
|
+
this.name = "WikiGraphArchiveOwnershipError";
|
|
1477
|
+
}
|
|
1478
|
+
};
|
|
1479
|
+
async function resolveWikiGraphArchiveLocation(target) {
|
|
1480
|
+
if (target.kind === "standalone") {
|
|
1481
|
+
return await resolveStandaloneLocation(target);
|
|
1482
|
+
}
|
|
1483
|
+
return await resolveLibraryLocation(target);
|
|
1484
|
+
}
|
|
1485
|
+
async function assertStandaloneWikiGraphArchivePath(inputPath) {
|
|
1486
|
+
const path = resolveWikiGraphRuntimePath(inputPath);
|
|
1487
|
+
const candidate = await canonicalPath(path);
|
|
1488
|
+
const candidateIdentity = await readFileIdentity(path);
|
|
1489
|
+
const libraries = await (0, import_wiki_graph_core2.listWikiGraphLibraries)();
|
|
1490
|
+
const matches = await findMatchingMembers(
|
|
1491
|
+
libraries,
|
|
1492
|
+
candidate,
|
|
1493
|
+
candidateIdentity
|
|
1494
|
+
);
|
|
1495
|
+
if (matches.length > 0) {
|
|
1496
|
+
const match = requireUnambiguousManagedMatch(path, matches);
|
|
1497
|
+
throw new WikiGraphArchiveOwnershipError(
|
|
1498
|
+
`Standalone archive path belongs to registered library ${(0, import_wiki_graph_core2.formatWikiGraphLibraryUri)(
|
|
1499
|
+
match.library.isDefault ? void 0 : match.library.publicId
|
|
1500
|
+
)}: ${path}. Use the library UUID URI ${match.archive.uri} instead.`
|
|
1501
|
+
);
|
|
1502
|
+
}
|
|
1503
|
+
for (const library of libraries) {
|
|
1504
|
+
const rootPath = getNodeResourcePath(library.folder);
|
|
1505
|
+
const root = await canonicalPath(rootPath);
|
|
1506
|
+
if (!isWithin(root, candidate)) continue;
|
|
1507
|
+
throw new WikiGraphArchiveOwnershipError(
|
|
1508
|
+
`Standalone archive path belongs to registered library ${(0, import_wiki_graph_core2.formatWikiGraphLibraryUri)(
|
|
1509
|
+
library.isDefault ? void 0 : library.publicId
|
|
1510
|
+
)}: ${path}. Scan the library, then address the archive by its library UUID URI.`
|
|
1511
|
+
);
|
|
1512
|
+
}
|
|
1513
|
+
return path;
|
|
1514
|
+
}
|
|
1515
|
+
function archiveTargetFromLogicalLocator(locator, objectUri) {
|
|
1516
|
+
if (locator.startsWith("wikg://lib/")) {
|
|
1517
|
+
return { kind: "library", uri: withObjectUri(locator, objectUri) };
|
|
1518
|
+
}
|
|
1519
|
+
return {
|
|
1520
|
+
kind: "standalone",
|
|
1521
|
+
path: locator,
|
|
1522
|
+
...objectUri === void 0 ? {} : { objectUri }
|
|
1523
|
+
};
|
|
1524
|
+
}
|
|
1525
|
+
async function resolveWikiGraphArchiveTarget(file) {
|
|
1526
|
+
const path = getNodeResourcePath(file);
|
|
1527
|
+
const candidate = await canonicalPath(path);
|
|
1528
|
+
const candidateIdentity = await readFileIdentity(path);
|
|
1529
|
+
const matches = await findMatchingMembers(
|
|
1530
|
+
await (0, import_wiki_graph_core2.listWikiGraphLibraries)(),
|
|
1531
|
+
candidate,
|
|
1532
|
+
candidateIdentity
|
|
1533
|
+
);
|
|
1534
|
+
if (matches.length > 0) {
|
|
1535
|
+
const match = requireUnambiguousManagedMatch(path, matches);
|
|
1536
|
+
return { kind: "library", uri: match.archive.uri };
|
|
1537
|
+
}
|
|
1538
|
+
return { kind: "standalone", path: getNodeResourcePath(file) };
|
|
1539
|
+
}
|
|
1540
|
+
async function resolveStandaloneLocation(target) {
|
|
1541
|
+
if (target.path.startsWith("wikg://lib/")) {
|
|
1542
|
+
throw new WikiGraphArchiveOwnershipError(
|
|
1543
|
+
`A library archive URI cannot be used as a standalone path: ${target.path}`
|
|
1544
|
+
);
|
|
1545
|
+
}
|
|
1546
|
+
const path = await assertStandaloneWikiGraphArchivePath(target.path);
|
|
1547
|
+
const normalized = {
|
|
1548
|
+
kind: "standalone",
|
|
1549
|
+
path,
|
|
1550
|
+
...target.objectUri === void 0 ? {} : { objectUri: target.objectUri }
|
|
1551
|
+
};
|
|
1552
|
+
return {
|
|
1553
|
+
archiveFile: new NodeFile(path),
|
|
1554
|
+
archiveKey: path,
|
|
1555
|
+
archivePath: path,
|
|
1556
|
+
indexScope: { archiveKey: path, archivePath: path, kind: "archive-index" },
|
|
1557
|
+
locatedUri: (0, import_wiki_graph_core2.formatLocatedWikiGraphUri)(path, target.objectUri),
|
|
1558
|
+
target: normalized
|
|
1559
|
+
};
|
|
1560
|
+
}
|
|
1561
|
+
async function resolveLibraryLocation(target) {
|
|
1562
|
+
const parsedLocated = (0, import_wiki_graph_core2.parseLocatedWikiGraphUri)(target.uri);
|
|
1563
|
+
const archiveUri = parsedLocated.archivePath ?? target.uri;
|
|
1564
|
+
const parsed = (0, import_wiki_graph_core2.parseWikiGraphLibraryUri)(archiveUri);
|
|
1565
|
+
if (parsed?.kind !== "archive") {
|
|
1566
|
+
throw new WikiGraphArchiveOwnershipError(
|
|
1567
|
+
`Library archive target must be a UUID archive URI: ${target.uri}`
|
|
1568
|
+
);
|
|
1569
|
+
}
|
|
1570
|
+
await (0, import_wiki_graph_core2.resolveWikiGraphLibrary)(parsed);
|
|
1571
|
+
const archiveFile = await (0, import_wiki_graph_core2.resolveWikiGraphLibraryArchiveFile)(archiveUri);
|
|
1572
|
+
const normalized = {
|
|
1573
|
+
kind: "library",
|
|
1574
|
+
uri: target.uri
|
|
1575
|
+
};
|
|
1576
|
+
return {
|
|
1577
|
+
archiveFile,
|
|
1578
|
+
archiveKey: archiveUri,
|
|
1579
|
+
archivePath: archiveUri,
|
|
1580
|
+
indexScope: {
|
|
1581
|
+
archiveKey: archiveUri,
|
|
1582
|
+
archivePath: archiveUri,
|
|
1583
|
+
kind: "archive-index"
|
|
1584
|
+
},
|
|
1585
|
+
libraryArchiveTarget: parsed,
|
|
1586
|
+
locatedUri: target.uri,
|
|
1587
|
+
publicArchiveUri: archiveUri,
|
|
1588
|
+
target: normalized
|
|
1589
|
+
};
|
|
1590
|
+
}
|
|
1591
|
+
function withObjectUri(archiveLocator, objectUri) {
|
|
1592
|
+
if (objectUri === void 0) return archiveLocator;
|
|
1593
|
+
const path = objectUri.replace(/^wikg:\/\//u, "");
|
|
1594
|
+
return `${archiveLocator.replace(/\/$/u, "")}/${path}`;
|
|
1595
|
+
}
|
|
1596
|
+
async function canonicalPath(path) {
|
|
1597
|
+
try {
|
|
1598
|
+
return await (0, import_promises2.realpath)(path);
|
|
1599
|
+
} catch {
|
|
1600
|
+
const absolute = (0, import_path3.resolve)(path);
|
|
1601
|
+
const parent = (0, import_path3.dirname)(absolute);
|
|
1602
|
+
return parent === absolute ? absolute : (0, import_path3.join)(await canonicalPath(parent), (0, import_path3.basename)(absolute));
|
|
1603
|
+
}
|
|
1604
|
+
}
|
|
1605
|
+
function isWithin(root, candidate) {
|
|
1606
|
+
const child = (0, import_path3.relative)(root, candidate);
|
|
1607
|
+
return child === "" || !child.startsWith("..") && !(0, import_path3.isAbsolute)(child);
|
|
1608
|
+
}
|
|
1609
|
+
async function findMatchingMembers(libraries, candidate, candidateIdentity) {
|
|
1610
|
+
const members = [];
|
|
1611
|
+
for (const library of libraries) {
|
|
1612
|
+
const archives = await (0, import_wiki_graph_core2.listWikiGraphLibraryArchives)({
|
|
1613
|
+
isDefault: library.isDefault,
|
|
1614
|
+
kind: "scope",
|
|
1615
|
+
...library.isDefault ? {} : { publicId: library.publicId }
|
|
1616
|
+
});
|
|
1617
|
+
for (const archive of archives) {
|
|
1618
|
+
if (archive.file === void 0) continue;
|
|
1619
|
+
members.push({
|
|
1620
|
+
archive,
|
|
1621
|
+
library,
|
|
1622
|
+
memberPath: getNodeResourcePath(archive.file)
|
|
1623
|
+
});
|
|
1624
|
+
}
|
|
1625
|
+
}
|
|
1626
|
+
const exact = [];
|
|
1627
|
+
for (const member of members) {
|
|
1628
|
+
if (await canonicalPath(member.memberPath) === candidate) {
|
|
1629
|
+
exact.push(member);
|
|
1630
|
+
}
|
|
1631
|
+
}
|
|
1632
|
+
if (exact.length > 0 || candidateIdentity === void 0) return exact;
|
|
1633
|
+
const identityMatches = [];
|
|
1634
|
+
for (const member of members) {
|
|
1635
|
+
if (await readFileIdentity(member.memberPath) === candidateIdentity) {
|
|
1636
|
+
identityMatches.push(member);
|
|
1637
|
+
}
|
|
1638
|
+
}
|
|
1639
|
+
return identityMatches;
|
|
1640
|
+
}
|
|
1641
|
+
function requireUnambiguousManagedMatch(path, matches) {
|
|
1642
|
+
if (matches.length === 1) return matches[0];
|
|
1643
|
+
throw new WikiGraphArchiveOwnershipError(
|
|
1644
|
+
`Archive file identity is ambiguous across managed archives: ${path}. Use an explicit library UUID URI (${matches.map((match) => match.archive.uri).join(", ")}).`
|
|
1645
|
+
);
|
|
1646
|
+
}
|
|
1647
|
+
async function readFileIdentity(path) {
|
|
1648
|
+
try {
|
|
1649
|
+
const value = await (0, import_promises2.stat)(path);
|
|
1650
|
+
return `${value.dev}:${value.ino}`;
|
|
1651
|
+
} catch {
|
|
1652
|
+
return void 0;
|
|
1653
|
+
}
|
|
1654
|
+
}
|
|
1655
|
+
|
|
1454
1656
|
// src/conversions.ts
|
|
1455
1657
|
var WikiGraphConversionManager = class {
|
|
1456
1658
|
#runtime;
|
|
@@ -1475,23 +1677,33 @@ var WikiGraphConversionManager = class {
|
|
|
1475
1677
|
}
|
|
1476
1678
|
const requiresDigest = options.input.format !== "wikg";
|
|
1477
1679
|
const requiresLLM = requiresDigest && targetStage !== "planned" && targetStage !== "sourced";
|
|
1680
|
+
const llmJSON = resolveWikiGraphLLMJSON(options);
|
|
1681
|
+
const injectedLLM = llmJSON === void 0 ? getWikiGraphSDKProviders().llm : void 0;
|
|
1478
1682
|
const config = await loadWikiGraphRuntimeConfig({
|
|
1479
|
-
...
|
|
1683
|
+
...llmJSON === void 0 ? {} : { llmJSON },
|
|
1684
|
+
...injectedLLM === void 0 ? {} : { skipLLMConfig: true },
|
|
1685
|
+
...getWikiGraphSDKProviders().embedding === void 0 ? {} : { skipEmbeddingConfig: true }
|
|
1480
1686
|
});
|
|
1481
|
-
const app = new
|
|
1687
|
+
const app = new import_wiki_graph_core3.WikiGraph({
|
|
1482
1688
|
...options.verbose === true ? { verbose: true } : {},
|
|
1483
|
-
...requiresLLM ? {
|
|
1689
|
+
...requiresLLM ? {
|
|
1690
|
+
llm: injectedLLM === void 0 ? buildWikiGraphLLMOptions(config) : { streamProvider: injectedLLM }
|
|
1691
|
+
} : {}
|
|
1484
1692
|
});
|
|
1485
1693
|
const documentDirectory = await prepareDigestDirectory(
|
|
1486
1694
|
options.digestDirectory,
|
|
1487
1695
|
requiresDigest
|
|
1488
1696
|
);
|
|
1489
1697
|
let chapterCount;
|
|
1698
|
+
let chapterPaths;
|
|
1490
1699
|
const write = async (archive) => {
|
|
1491
1700
|
if (requiresDigest) await options.onSourceImported?.();
|
|
1492
1701
|
if (typeof archive.readToc === "function") {
|
|
1493
1702
|
const toc = await archive.readToc();
|
|
1494
1703
|
chapterCount = toc === void 0 ? void 0 : countTocChapters(toc.items);
|
|
1704
|
+
if (options.output.format === "wikg") {
|
|
1705
|
+
chapterPaths = toc === void 0 ? [] : collectTocChapterPaths(toc.items);
|
|
1706
|
+
}
|
|
1495
1707
|
}
|
|
1496
1708
|
await writeArchive(archive, options.output.path, options.output.format);
|
|
1497
1709
|
};
|
|
@@ -1500,7 +1712,9 @@ var WikiGraphConversionManager = class {
|
|
|
1500
1712
|
throw new Error("wikg input requires a file path.");
|
|
1501
1713
|
}
|
|
1502
1714
|
await app.openSession(
|
|
1503
|
-
new NodeFile(
|
|
1715
|
+
new NodeFile(
|
|
1716
|
+
await assertStandaloneWikiGraphArchivePath(options.input.path)
|
|
1717
|
+
),
|
|
1504
1718
|
write
|
|
1505
1719
|
);
|
|
1506
1720
|
} else if ("stream" in options.input) {
|
|
@@ -1543,6 +1757,7 @@ var WikiGraphConversionManager = class {
|
|
|
1543
1757
|
const sourceArtifact = await resolveSourceArtifact(options.input);
|
|
1544
1758
|
return {
|
|
1545
1759
|
...chapterCount === void 0 ? {} : { chapterCount },
|
|
1760
|
+
...chapterPaths === void 0 ? {} : { chapterPaths },
|
|
1546
1761
|
inputFormat: options.input.format,
|
|
1547
1762
|
outputFormat: options.output.format,
|
|
1548
1763
|
outputPath: options.output.path,
|
|
@@ -1555,11 +1770,12 @@ async function prepareDigestDirectory(path, required) {
|
|
|
1555
1770
|
if (!required || normalized === void 0 || normalized === "")
|
|
1556
1771
|
return void 0;
|
|
1557
1772
|
const resolved = resolveWikiGraphRuntimePath(normalized);
|
|
1558
|
-
await (0,
|
|
1773
|
+
await (0, import_promises3.rm)(resolved, { force: true, recursive: true });
|
|
1559
1774
|
return new NodeDirectory(resolved);
|
|
1560
1775
|
}
|
|
1561
1776
|
async function writeArchive(archive, path, format) {
|
|
1562
|
-
const
|
|
1777
|
+
const outputPath = format === "wikg" ? await assertStandaloneWikiGraphArchivePath(path) : resolveWikiGraphRuntimePath(path);
|
|
1778
|
+
const file = new NodeFile(outputPath);
|
|
1563
1779
|
if (format === "epub") await archive.exportEpub(file);
|
|
1564
1780
|
else if (format === "wikg") await archive.saveAs(file);
|
|
1565
1781
|
else if (format === "pcex") throw new Error("pcex output is not supported.");
|
|
@@ -1588,7 +1804,7 @@ async function resolveSourceArtifact(input) {
|
|
|
1588
1804
|
return {
|
|
1589
1805
|
digest: hash.digest("hex"),
|
|
1590
1806
|
mediaType: "application/epub+zip",
|
|
1591
|
-
name: (0,
|
|
1807
|
+
name: (0, import_path4.basename)(path)
|
|
1592
1808
|
};
|
|
1593
1809
|
}
|
|
1594
1810
|
function isNodeErrorCode(error, code) {
|
|
@@ -1604,9 +1820,24 @@ function countTocChapters(items) {
|
|
|
1604
1820
|
}
|
|
1605
1821
|
return count;
|
|
1606
1822
|
}
|
|
1823
|
+
function collectTocChapterPaths(items, ancestorKeys = []) {
|
|
1824
|
+
const paths = [];
|
|
1825
|
+
for (const item of items) {
|
|
1826
|
+
const key = item.key ?? `chapter-${item.serialId ?? "group"}`;
|
|
1827
|
+
const chapterPath = [...ancestorKeys, key];
|
|
1828
|
+
if (item.serialId !== void 0) paths.push(chapterPath.join("/"));
|
|
1829
|
+
paths.push(
|
|
1830
|
+
...collectTocChapterPaths(
|
|
1831
|
+
item.children,
|
|
1832
|
+
chapterPath
|
|
1833
|
+
)
|
|
1834
|
+
);
|
|
1835
|
+
}
|
|
1836
|
+
return paths;
|
|
1837
|
+
}
|
|
1607
1838
|
|
|
1608
1839
|
// src/query-runtime.ts
|
|
1609
|
-
var
|
|
1840
|
+
var import_wiki_graph_core4 = require("wiki-graph-core");
|
|
1610
1841
|
|
|
1611
1842
|
// src/embedding.ts
|
|
1612
1843
|
var import_ai = require("ai");
|
|
@@ -1770,6 +2001,8 @@ function createOpenAICompatibleName2(baseURL) {
|
|
|
1770
2001
|
|
|
1771
2002
|
// src/query-runtime.ts
|
|
1772
2003
|
async function createConfiguredEmbeddingProvider() {
|
|
2004
|
+
const injected = getWikiGraphSDKProviders().embedding;
|
|
2005
|
+
if (injected !== void 0) return injected;
|
|
1773
2006
|
const config = await readWikiGraphEmbeddingConfig();
|
|
1774
2007
|
if (config.provider === void 0 || config.model === void 0 || config.provider === "openai-compatible" && config.baseURL === void 0 || config.provider === "openai" && config.baseURL !== void 0) {
|
|
1775
2008
|
return void 0;
|
|
@@ -1779,7 +2012,7 @@ async function createConfiguredEmbeddingProvider() {
|
|
|
1779
2012
|
async function withConfiguredWikimediaResolver(objectUri, operation) {
|
|
1780
2013
|
if (!objectUri.endsWith("/wikipage")) return await operation({});
|
|
1781
2014
|
const config = await loadWikiGraphRuntimeConfig();
|
|
1782
|
-
const resolver = await (0,
|
|
2015
|
+
const resolver = await (0, import_wiki_graph_core4.openWikimediaResolver)(
|
|
1783
2016
|
config.wikimedia === void 0 ? { kind: "local" } : {
|
|
1784
2017
|
endpoint: config.wikimedia.endpoint,
|
|
1785
2018
|
kind: "remote",
|
|
@@ -1794,500 +2027,128 @@ async function withConfiguredWikimediaResolver(objectUri, operation) {
|
|
|
1794
2027
|
}
|
|
1795
2028
|
|
|
1796
2029
|
// src/archive/inspect.ts
|
|
1797
|
-
var
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
model,
|
|
1813
|
-
timeSeconds: {
|
|
1814
|
-
max: Math.ceil(callBatches * profile.maxSecondsPerCall + wordSeconds),
|
|
1815
|
-
min: Math.ceil(callBatches * profile.minSecondsPerCall + wordSeconds)
|
|
1816
|
-
},
|
|
1817
|
-
tokens: {
|
|
1818
|
-
cacheableInput: Math.ceil(words * profile.cacheableInputTokenPerWord),
|
|
1819
|
-
input: Math.ceil(words * profile.inputTokenPerWord),
|
|
1820
|
-
output: Math.ceil(words * profile.outputTokenPerWord)
|
|
1821
|
-
}
|
|
2030
|
+
var import_wiki_graph_core5 = require("wiki-graph-core");
|
|
2031
|
+
async function inspectWikiGraphArchive(document, options) {
|
|
2032
|
+
const [allChapters, indexCacheCurrent, summaryWords, ...coverage] = await Promise.all([
|
|
2033
|
+
(0, import_wiki_graph_core5.listChapters)(document),
|
|
2034
|
+
(0, import_wiki_graph_core5.isArchiveSearchIndexCurrent)(document),
|
|
2035
|
+
readSummaryWords(document),
|
|
2036
|
+
document.indexArtifacts.listCoverage("fts"),
|
|
2037
|
+
document.indexArtifacts.listCoverage("embedding-source"),
|
|
2038
|
+
document.indexArtifacts.listCoverage("embedding-summary")
|
|
2039
|
+
]);
|
|
2040
|
+
const chapters = selectChapters(allChapters, options.chapterId);
|
|
2041
|
+
const coverageByKind = {
|
|
2042
|
+
fts: byChapterId(coverage[0]),
|
|
2043
|
+
sourceEmbedding: byChapterId(coverage[1]),
|
|
2044
|
+
summaryEmbedding: byChapterId(coverage[2])
|
|
1822
2045
|
};
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
return [];
|
|
1827
|
-
}
|
|
1828
|
-
const hints = [];
|
|
1829
|
-
const recommendedRequest = input.concurrent.request < 4 ? DEFAULT_GENERATION_REQUEST_CONCURRENCY : input.concurrent.request < 8 ? 8 : void 0;
|
|
1830
|
-
if (input.hasRequestWork && recommendedRequest !== void 0) {
|
|
1831
|
-
hints.push({
|
|
1832
|
-
configKey: "request",
|
|
1833
|
-
configValue: recommendedRequest,
|
|
1834
|
-
current: input.concurrent.request,
|
|
1835
|
-
kind: "request",
|
|
1836
|
-
message: "LLM request concurrency can often be higher. Use at least 4; 6-8 is usually faster when the provider allows it.",
|
|
1837
|
-
recommended: recommendedRequest
|
|
1838
|
-
});
|
|
1839
|
-
}
|
|
1840
|
-
if (input.concurrent.job < 4 && input.chapters > 1) {
|
|
1841
|
-
hints.push({
|
|
1842
|
-
configKey: "job",
|
|
1843
|
-
configValue: 4,
|
|
1844
|
-
current: input.concurrent.job,
|
|
1845
|
-
kind: "job",
|
|
1846
|
-
message: "Multiple chapters need work and job concurrency is below 4. Raising it lets chapter jobs run in parallel.",
|
|
1847
|
-
recommended: 4
|
|
1848
|
-
});
|
|
1849
|
-
}
|
|
1850
|
-
return hints;
|
|
1851
|
-
}
|
|
1852
|
-
function formatGenerationPlanningModel(llm) {
|
|
1853
|
-
if (llm?.model === void 0) {
|
|
1854
|
-
return "not configured";
|
|
1855
|
-
}
|
|
1856
|
-
return llm.provider === void 0 ? llm.model : `${llm.provider}/${llm.model}`;
|
|
1857
|
-
}
|
|
1858
|
-
function formatGenerationPlanningDuration(seconds) {
|
|
1859
|
-
if (seconds < 60) {
|
|
1860
|
-
return `${seconds}s`;
|
|
1861
|
-
}
|
|
1862
|
-
const minutes = Math.round(seconds / 60);
|
|
1863
|
-
if (minutes < 60) {
|
|
1864
|
-
return `${minutes}m`;
|
|
1865
|
-
}
|
|
1866
|
-
return `${Math.round(minutes / 60)}h`;
|
|
1867
|
-
}
|
|
1868
|
-
function getGenerationPlanningProfile(task) {
|
|
1869
|
-
switch (task) {
|
|
1870
|
-
case "index-fts":
|
|
1871
|
-
return {
|
|
1872
|
-
cacheableInputTokenPerWord: 0,
|
|
1873
|
-
inputTokenPerWord: 0,
|
|
1874
|
-
maxSecondsPerCall: 1,
|
|
1875
|
-
minSecondsPerCall: 0,
|
|
1876
|
-
outputTokenPerWord: 0,
|
|
1877
|
-
secondsPerWord: 5e-4,
|
|
1878
|
-
wordsPerCall: 1e5
|
|
1879
|
-
};
|
|
1880
|
-
case "index-embedding-source":
|
|
1881
|
-
case "index-embedding-summary":
|
|
1882
|
-
return {
|
|
1883
|
-
cacheableInputTokenPerWord: 0,
|
|
1884
|
-
inputTokenPerWord: 0,
|
|
1885
|
-
maxSecondsPerCall: 10,
|
|
1886
|
-
minSecondsPerCall: 1,
|
|
1887
|
-
outputTokenPerWord: 0,
|
|
1888
|
-
secondsPerWord: 2e-3,
|
|
1889
|
-
wordsPerCall: 1e4
|
|
1890
|
-
};
|
|
1891
|
-
case "knowledge-graph":
|
|
1892
|
-
return {
|
|
1893
|
-
cacheableInputTokenPerWord: 60,
|
|
1894
|
-
inputTokenPerWord: 80,
|
|
1895
|
-
maxSecondsPerCall: 35,
|
|
1896
|
-
minSecondsPerCall: 15,
|
|
1897
|
-
outputTokenPerWord: 25,
|
|
1898
|
-
secondsPerWord: 0.02,
|
|
1899
|
-
wordsPerCall: 35
|
|
1900
|
-
};
|
|
1901
|
-
case "reading-graph":
|
|
1902
|
-
return {
|
|
1903
|
-
cacheableInputTokenPerWord: 20,
|
|
1904
|
-
inputTokenPerWord: 25,
|
|
1905
|
-
maxSecondsPerCall: 45,
|
|
1906
|
-
minSecondsPerCall: 15,
|
|
1907
|
-
outputTokenPerWord: 4,
|
|
1908
|
-
secondsPerWord: 0.01,
|
|
1909
|
-
wordsPerCall: 160
|
|
1910
|
-
};
|
|
1911
|
-
case "reading-summary":
|
|
2046
|
+
const inspections = await Promise.all(
|
|
2047
|
+
chapters.map(async (chapter) => {
|
|
2048
|
+
const serial = await document.serials.getById(chapter.chapterId);
|
|
1912
2049
|
return {
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
2050
|
+
capabilities: {
|
|
2051
|
+
knowledgeGraph: {
|
|
2052
|
+
completed: serial?.knowledgeGraphReady === true
|
|
2053
|
+
},
|
|
2054
|
+
readingGraph: { completed: serial?.topologyReady === true },
|
|
2055
|
+
readingSummary: { completed: chapter.stage === "summarized" }
|
|
2056
|
+
},
|
|
2057
|
+
chapter,
|
|
2058
|
+
indexes: {
|
|
2059
|
+
fts: inspectArtifact(
|
|
2060
|
+
"fts",
|
|
2061
|
+
coverageByKind.fts.get(chapter.chapterId)
|
|
2062
|
+
),
|
|
2063
|
+
sourceEmbedding: inspectArtifact(
|
|
2064
|
+
"embedding-source",
|
|
2065
|
+
coverageByKind.sourceEmbedding.get(chapter.chapterId)
|
|
2066
|
+
),
|
|
2067
|
+
summaryEmbedding: inspectArtifact(
|
|
2068
|
+
"embedding-summary",
|
|
2069
|
+
coverageByKind.summaryEmbedding.get(chapter.chapterId)
|
|
2070
|
+
)
|
|
2071
|
+
},
|
|
2072
|
+
revision: serial?.revision ?? 0,
|
|
2073
|
+
summaryWords: summaryWords.get(chapter.chapterId) ?? 0
|
|
1920
2074
|
};
|
|
1921
|
-
|
|
1922
|
-
}
|
|
1923
|
-
|
|
1924
|
-
// src/archive/inspect.ts
|
|
1925
|
-
async function createWikiGraphArchiveInspectReport(document, options) {
|
|
1926
|
-
const { archiveUri } = options;
|
|
1927
|
-
const [
|
|
1928
|
-
chapters,
|
|
1929
|
-
summaryWords,
|
|
1930
|
-
indexCacheCurrent,
|
|
1931
|
-
config,
|
|
1932
|
-
ftsArtifactCoverage,
|
|
1933
|
-
sourceEmbeddingArtifactCoverage,
|
|
1934
|
-
summaryEmbeddingArtifactCoverage
|
|
1935
|
-
] = await Promise.all([
|
|
1936
|
-
readInspectChapters(document, options.chapterId),
|
|
1937
|
-
readSummaryWords(document, options.chapterId),
|
|
1938
|
-
(0, import_wiki_graph_core4.isArchiveSearchIndexCurrent)(document),
|
|
1939
|
-
loadWikiGraphRuntimeConfig(),
|
|
1940
|
-
readIndexArtifactCoverage(document, "fts", options.chapterId),
|
|
1941
|
-
readIndexArtifactCoverage(document, "embedding-source", options.chapterId),
|
|
1942
|
-
readIndexArtifactCoverage(document, "embedding-summary", options.chapterId)
|
|
1943
|
-
]);
|
|
1944
|
-
const selectedChapter = options.chapterId === void 0 ? void 0 : chapters[0];
|
|
1945
|
-
const scopeUri = selectedChapter === void 0 ? archiveUri : formatInspectLocatedChapterUri(archiveUri, selectedChapter);
|
|
1946
|
-
const concurrent = {
|
|
1947
|
-
job: config.concurrent?.job ?? DEFAULT_GENERATION_JOB_CONCURRENCY,
|
|
1948
|
-
request: config.concurrent?.request ?? DEFAULT_GENERATION_REQUEST_CONCURRENCY
|
|
1949
|
-
};
|
|
1950
|
-
const planningModel = formatGenerationPlanningModel(config.llm);
|
|
1951
|
-
const contentChapters = chapters.filter(
|
|
1952
|
-
(chapter) => chapter.stage !== "planned"
|
|
1953
|
-
);
|
|
1954
|
-
const sourceWords = sumWords(contentChapters);
|
|
1955
|
-
const readingGraphCovered = contentChapters.filter(
|
|
1956
|
-
(chapter) => chapter.readingGraphReady
|
|
1957
|
-
);
|
|
1958
|
-
const knowledgeGraphCovered = contentChapters.filter(
|
|
1959
|
-
(chapter) => chapter.knowledgeGraphReady
|
|
1960
|
-
);
|
|
1961
|
-
const summaryCovered = contentChapters.filter(
|
|
1962
|
-
(chapter) => chapter.summaryReady
|
|
1963
|
-
);
|
|
1964
|
-
const ftsArtifactCovered = filterChaptersByCurrentIndexArtifact(
|
|
1965
|
-
contentChapters,
|
|
1966
|
-
ftsArtifactCoverage
|
|
1967
|
-
);
|
|
1968
|
-
const sourceEmbeddingArtifactCovered = filterChaptersByCurrentIndexArtifact(
|
|
1969
|
-
contentChapters,
|
|
1970
|
-
sourceEmbeddingArtifactCoverage
|
|
1971
|
-
);
|
|
1972
|
-
const summaryEmbeddingArtifactCovered = filterChaptersByCurrentIndexArtifact(
|
|
1973
|
-
contentChapters,
|
|
1974
|
-
summaryEmbeddingArtifactCoverage
|
|
1975
|
-
);
|
|
1976
|
-
const queryBlockedContentChapters = contentChapters.filter(
|
|
1977
|
-
(chapter) => !ftsArtifactCovered.includes(chapter) && !sourceEmbeddingArtifactCovered.includes(chapter)
|
|
1978
|
-
);
|
|
1979
|
-
const queryBlockedChapters = queryBlockedContentChapters.map(
|
|
1980
|
-
(chapter) => createInspectChapterReference(archiveUri, chapter)
|
|
2075
|
+
})
|
|
1981
2076
|
);
|
|
1982
|
-
const
|
|
1983
|
-
const improvements = createInspectImprovements({
|
|
1984
|
-
concurrent,
|
|
1985
|
-
contentChapters,
|
|
1986
|
-
indexCacheCurrent,
|
|
1987
|
-
planningModel,
|
|
1988
|
-
queryBlockedChapters: queryBlockedContentChapters,
|
|
1989
|
-
summaryCovered,
|
|
1990
|
-
knowledgeGraphCovered,
|
|
1991
|
-
readingGraphCovered
|
|
1992
|
-
});
|
|
1993
|
-
const performanceHints = createGenerationPerformanceHints({
|
|
1994
|
-
chapters: Math.max(
|
|
1995
|
-
0,
|
|
1996
|
-
...improvements.map((improvement) => improvement.missingChapters ?? 0)
|
|
1997
|
-
),
|
|
1998
|
-
concurrent,
|
|
1999
|
-
hasJobWork: improvements.some(
|
|
2000
|
-
(improvement) => improvement.planning !== void 0
|
|
2001
|
-
),
|
|
2002
|
-
hasRequestWork: improvements.some(
|
|
2003
|
-
(improvement) => improvement.planning !== void 0
|
|
2004
|
-
)
|
|
2005
|
-
});
|
|
2077
|
+
const selected = inspections[0];
|
|
2006
2078
|
return {
|
|
2007
|
-
archiveUri,
|
|
2008
|
-
|
|
2079
|
+
archiveUri: options.archiveUri,
|
|
2080
|
+
chapters: inspections,
|
|
2081
|
+
localIndexCache: { current: indexCacheCurrent },
|
|
2009
2082
|
scope: options.chapterId === void 0 ? { type: "archive" } : { chapterId: options.chapterId, type: "chapter" },
|
|
2010
|
-
|
|
2011
|
-
chapters: {
|
|
2012
|
-
content: contentChapters.length,
|
|
2013
|
-
planned: chapters.length - contentChapters.length,
|
|
2014
|
-
total: chapters.length
|
|
2015
|
-
},
|
|
2016
|
-
sourceWords,
|
|
2017
|
-
summaryWords
|
|
2018
|
-
},
|
|
2019
|
-
localIndexCache: {
|
|
2020
|
-
current: indexCacheCurrent,
|
|
2021
|
-
...!queryReady ? {
|
|
2022
|
-
blockedBy: "missing-search-artifacts",
|
|
2023
|
-
impact: "The cache cannot be built until every content chapter has a current FTS or source embedding artifact."
|
|
2024
|
-
} : indexCacheCurrent ? {} : {
|
|
2025
|
-
impact: "The next archive query may need to sync index cache first.",
|
|
2026
|
-
resource: "local CPU/disk time only; no provider calls."
|
|
2027
|
-
},
|
|
2028
|
-
status: !queryReady ? "blocked" : indexCacheCurrent ? "current" : "missing-or-outdated",
|
|
2029
|
-
syncAvailable: queryReady && !indexCacheCurrent
|
|
2030
|
-
},
|
|
2031
|
-
coverage: {
|
|
2032
|
-
ftsIndexArtifact: createInspectCoverage(
|
|
2033
|
-
ftsArtifactCovered,
|
|
2034
|
-
contentChapters
|
|
2035
|
-
),
|
|
2036
|
-
knowledgeGraph: createInspectCoverage(
|
|
2037
|
-
knowledgeGraphCovered,
|
|
2038
|
-
contentChapters
|
|
2039
|
-
),
|
|
2040
|
-
readingGraph: createInspectCoverage(readingGraphCovered, contentChapters),
|
|
2041
|
-
summary: createInspectCoverage(summaryCovered, contentChapters),
|
|
2042
|
-
sourceEmbeddingIndexArtifact: createInspectCoverage(
|
|
2043
|
-
sourceEmbeddingArtifactCovered,
|
|
2044
|
-
contentChapters
|
|
2045
|
-
),
|
|
2046
|
-
summaryEmbeddingIndexArtifact: createInspectCoverage(
|
|
2047
|
-
summaryEmbeddingArtifactCovered,
|
|
2048
|
-
contentChapters
|
|
2049
|
-
)
|
|
2050
|
-
},
|
|
2051
|
-
query: {
|
|
2052
|
-
ready: queryReady
|
|
2053
|
-
},
|
|
2054
|
-
searchArtifacts: {
|
|
2055
|
-
blockedChapters: queryBlockedChapters,
|
|
2056
|
-
...!queryReady ? {
|
|
2057
|
-
resource: "local CPU/disk time only; no provider calls."
|
|
2058
|
-
} : {},
|
|
2059
|
-
ready: queryReady,
|
|
2060
|
-
status: queryReady ? "ready" : "incomplete"
|
|
2061
|
-
},
|
|
2062
|
-
retrievalGuidance: formatRetrievalGuidance({
|
|
2063
|
-
indexCacheCurrent,
|
|
2064
|
-
knowledgeGraphCovered,
|
|
2065
|
-
readingGraphCovered,
|
|
2066
|
-
contentChapters,
|
|
2067
|
-
queryReady,
|
|
2068
|
-
sourceWords
|
|
2069
|
-
}),
|
|
2070
|
-
improvements,
|
|
2071
|
-
performanceHints,
|
|
2072
|
-
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."
|
|
2073
|
-
};
|
|
2074
|
-
}
|
|
2075
|
-
function createInspectChapterReference(archiveUri, chapter) {
|
|
2076
|
-
return {
|
|
2077
|
-
chapterId: chapter.chapterId,
|
|
2078
|
-
locatedUri: formatInspectLocatedChapterUri(archiveUri, chapter),
|
|
2079
|
-
title: chapter.title,
|
|
2080
|
-
uri: chapter.uri
|
|
2083
|
+
uri: selected === void 0 || options.chapterId === void 0 ? options.archiveUri : formatLocatedChapterUri(options.archiveUri, selected.chapter)
|
|
2081
2084
|
};
|
|
2082
2085
|
}
|
|
2083
|
-
function
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
async function readInspectChapters(document, chapterId) {
|
|
2087
|
-
const chapters = chapterId === void 0 ? await (0, import_wiki_graph_core4.listChapters)(document) : (await (0, import_wiki_graph_core4.listChapters)(document)).filter(
|
|
2086
|
+
function selectChapters(chapters, chapterId) {
|
|
2087
|
+
if (chapterId === void 0) return chapters;
|
|
2088
|
+
const selected = chapters.filter(
|
|
2088
2089
|
(chapter) => chapter.chapterId === chapterId
|
|
2089
2090
|
);
|
|
2090
|
-
if (
|
|
2091
|
+
if (selected.length === 0) {
|
|
2091
2092
|
throw new Error(`Chapter ${chapterId} does not exist.`);
|
|
2092
2093
|
}
|
|
2093
|
-
return
|
|
2094
|
-
chapters.map(async (chapter) => {
|
|
2095
|
-
const serial = await document.serials.getById(chapter.chapterId);
|
|
2096
|
-
return {
|
|
2097
|
-
...chapter,
|
|
2098
|
-
knowledgeGraphReady: serial?.knowledgeGraphReady === true,
|
|
2099
|
-
readingGraphReady: serial?.topologyReady === true,
|
|
2100
|
-
summaryReady: chapter.stage === "summarized"
|
|
2101
|
-
};
|
|
2102
|
-
})
|
|
2103
|
-
);
|
|
2094
|
+
return selected;
|
|
2104
2095
|
}
|
|
2105
|
-
|
|
2106
|
-
return
|
|
2107
|
-
async (database) => await database.queryOne(
|
|
2108
|
-
`
|
|
2109
|
-
SELECT COALESCE(SUM(words_count), 0) AS words
|
|
2110
|
-
FROM text_sentence_records
|
|
2111
|
-
WHERE kind = 2
|
|
2112
|
-
${chapterId === void 0 ? "" : "AND chapter_id = ?"}
|
|
2113
|
-
`,
|
|
2114
|
-
chapterId === void 0 ? void 0 : [chapterId],
|
|
2115
|
-
(row) => Number(row.words)
|
|
2116
|
-
) ?? 0
|
|
2117
|
-
);
|
|
2096
|
+
function byChapterId(coverage) {
|
|
2097
|
+
return new Map(coverage.map((item) => [item.serialId, item]));
|
|
2118
2098
|
}
|
|
2119
|
-
|
|
2120
|
-
const coverage = await document.indexArtifacts.listCoverage(kind);
|
|
2121
|
-
return chapterId === void 0 ? coverage : coverage.filter((item) => item.serialId === chapterId);
|
|
2122
|
-
}
|
|
2123
|
-
function filterChaptersByCurrentIndexArtifact(chapters, coverage) {
|
|
2124
|
-
const currentChapterIds = new Set(
|
|
2125
|
-
coverage.filter((item) => item.current).map((item) => item.serialId)
|
|
2126
|
-
);
|
|
2127
|
-
return chapters.filter((chapter) => currentChapterIds.has(chapter.chapterId));
|
|
2128
|
-
}
|
|
2129
|
-
function createInspectCoverage(covered, total) {
|
|
2130
|
-
const coveredWords = sumWords(covered);
|
|
2131
|
-
const totalWords = sumWords(total);
|
|
2099
|
+
function inspectArtifact(kind, coverage) {
|
|
2132
2100
|
return {
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
totalWords
|
|
2101
|
+
current: coverage?.current === true,
|
|
2102
|
+
exists: coverage?.sourceRevision !== void 0,
|
|
2103
|
+
kind,
|
|
2104
|
+
...coverage?.sourceRevision === void 0 ? {} : { sourceRevision: coverage.sourceRevision }
|
|
2138
2105
|
};
|
|
2139
2106
|
}
|
|
2140
|
-
function
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
input.contentChapters
|
|
2155
|
-
)
|
|
2156
|
-
);
|
|
2157
|
-
lines.push(
|
|
2158
|
-
formatObjectSearchGuidance(
|
|
2159
|
-
"Entity/triple retrieval",
|
|
2160
|
-
input.knowledgeGraphCovered,
|
|
2161
|
-
input.contentChapters
|
|
2107
|
+
async function readSummaryWords(document) {
|
|
2108
|
+
const rows = await document.readDatabase(
|
|
2109
|
+
async (database) => await database.queryAll(
|
|
2110
|
+
`
|
|
2111
|
+
SELECT chapter_id, COALESCE(SUM(words_count), 0) AS words
|
|
2112
|
+
FROM text_sentence_records
|
|
2113
|
+
WHERE kind = 2
|
|
2114
|
+
GROUP BY chapter_id
|
|
2115
|
+
`,
|
|
2116
|
+
void 0,
|
|
2117
|
+
(row) => ({
|
|
2118
|
+
chapterId: Number(row.chapter_id),
|
|
2119
|
+
words: Number(row.words)
|
|
2120
|
+
})
|
|
2162
2121
|
)
|
|
2163
2122
|
);
|
|
2164
|
-
return
|
|
2165
|
-
}
|
|
2166
|
-
function formatObjectSearchGuidance(label, covered, total) {
|
|
2167
|
-
const coveredWords = sumWords(covered);
|
|
2168
|
-
const totalWords = sumWords(total);
|
|
2169
|
-
const ratio = totalWords === 0 ? 0 : coveredWords / totalWords;
|
|
2170
|
-
const coverage = formatPercent(coveredWords, totalWords);
|
|
2171
|
-
if (ratio >= 1) {
|
|
2172
|
-
return `${label}: covers all source content; it can represent the full scope for object retrieval.`;
|
|
2173
|
-
}
|
|
2174
|
-
if (ratio >= 0.9) {
|
|
2175
|
-
return `${label}: covers ${coverage}; use it as the main path, but source --query is needed for uncovered content.`;
|
|
2176
|
-
}
|
|
2177
|
-
if (ratio >= 0.5) {
|
|
2178
|
-
return `${label}: covers ${coverage}; use it as leads, not as a full-scope substitute for source --query.`;
|
|
2179
|
-
}
|
|
2180
|
-
return `${label}: covers ${coverage}; build missing graph coverage before relying on object retrieval.`;
|
|
2181
|
-
}
|
|
2182
|
-
function createInspectImprovements(input) {
|
|
2183
|
-
const improvements = [];
|
|
2184
|
-
if (input.contentChapters.length === 0) {
|
|
2185
|
-
improvements.push({
|
|
2186
|
-
kind: "add-source",
|
|
2187
|
-
recommendation: "No source content is available yet; add or import source text before graph or summary generation.",
|
|
2188
|
-
title: "Add source content"
|
|
2189
|
-
});
|
|
2190
|
-
return improvements;
|
|
2191
|
-
}
|
|
2192
|
-
if (input.queryBlockedChapters.length > 0) {
|
|
2193
|
-
improvements.push({
|
|
2194
|
-
kind: "build",
|
|
2195
|
-
missingChapters: input.queryBlockedChapters.length,
|
|
2196
|
-
missingWords: sumWords(input.queryBlockedChapters),
|
|
2197
|
-
recommendation: "Build local FTS artifacts to make this scope queryable. This does not call a provider.",
|
|
2198
|
-
task: "index-fts",
|
|
2199
|
-
title: "Enable query with local FTS"
|
|
2200
|
-
});
|
|
2201
|
-
} else if (!input.indexCacheCurrent) {
|
|
2202
|
-
improvements.push({
|
|
2203
|
-
kind: "sync-index",
|
|
2204
|
-
recommendation: "Sync the index cache from chapter index artifacts so query starts without a lazy cache rebuild.",
|
|
2205
|
-
title: "Sync index cache"
|
|
2206
|
-
});
|
|
2207
|
-
}
|
|
2208
|
-
improvements.push(
|
|
2209
|
-
...createGraphImprovement({
|
|
2210
|
-
concurrent: input.concurrent,
|
|
2211
|
-
covered: input.readingGraphCovered,
|
|
2212
|
-
planningModel: input.planningModel,
|
|
2213
|
-
task: "reading-graph",
|
|
2214
|
-
title: "Complete Reading Graph coverage",
|
|
2215
|
-
total: input.contentChapters
|
|
2216
|
-
})
|
|
2217
|
-
);
|
|
2218
|
-
improvements.push(
|
|
2219
|
-
...createGraphImprovement({
|
|
2220
|
-
concurrent: input.concurrent,
|
|
2221
|
-
covered: input.knowledgeGraphCovered,
|
|
2222
|
-
planningModel: input.planningModel,
|
|
2223
|
-
task: "knowledge-graph",
|
|
2224
|
-
title: "Complete Knowledge Graph coverage",
|
|
2225
|
-
total: input.contentChapters
|
|
2226
|
-
})
|
|
2227
|
-
);
|
|
2228
|
-
improvements.push(
|
|
2229
|
-
...createGraphImprovement({
|
|
2230
|
-
concurrent: input.concurrent,
|
|
2231
|
-
covered: input.summaryCovered,
|
|
2232
|
-
planningModel: input.planningModel,
|
|
2233
|
-
task: "reading-summary",
|
|
2234
|
-
title: "Complete Summary coverage",
|
|
2235
|
-
total: input.contentChapters
|
|
2236
|
-
})
|
|
2237
|
-
);
|
|
2238
|
-
return improvements;
|
|
2239
|
-
}
|
|
2240
|
-
function createGraphImprovement(input) {
|
|
2241
|
-
const coveredIds = new Set(input.covered.map((chapter) => chapter.chapterId));
|
|
2242
|
-
const missing = input.total.filter(
|
|
2243
|
-
(chapter) => !coveredIds.has(chapter.chapterId)
|
|
2244
|
-
);
|
|
2245
|
-
if (missing.length === 0) {
|
|
2246
|
-
return [];
|
|
2247
|
-
}
|
|
2248
|
-
const missingWords = sumWords(missing);
|
|
2249
|
-
return [
|
|
2250
|
-
{
|
|
2251
|
-
kind: "build",
|
|
2252
|
-
missingChapters: missing.length,
|
|
2253
|
-
missingWords,
|
|
2254
|
-
planning: planGenerationTask(
|
|
2255
|
-
input.task,
|
|
2256
|
-
missingWords,
|
|
2257
|
-
missing.length,
|
|
2258
|
-
input.concurrent,
|
|
2259
|
-
input.planningModel
|
|
2260
|
-
),
|
|
2261
|
-
recommendation: formatImprovementRecommendation(
|
|
2262
|
-
input.covered,
|
|
2263
|
-
input.total,
|
|
2264
|
-
missingWords
|
|
2265
|
-
),
|
|
2266
|
-
task: input.task,
|
|
2267
|
-
title: input.title
|
|
2268
|
-
}
|
|
2269
|
-
];
|
|
2270
|
-
}
|
|
2271
|
-
function formatImprovementRecommendation(covered, total, missingWords) {
|
|
2272
|
-
const totalWords = sumWords(total);
|
|
2273
|
-
const coveredWords = sumWords(covered);
|
|
2274
|
-
if (totalWords === 0) {
|
|
2275
|
-
return "No source content is available.";
|
|
2276
|
-
}
|
|
2277
|
-
if (total.length === 1 || coveredWords / totalWords >= 0.9 || missingWords <= 1e3) {
|
|
2278
|
-
return "Queue the full scope to finish the remaining gap.";
|
|
2279
|
-
}
|
|
2280
|
-
return "Queue selected chapters first if only part of the scope matters.";
|
|
2123
|
+
return new Map(rows.map((row) => [row.chapterId, row.words]));
|
|
2281
2124
|
}
|
|
2282
|
-
function
|
|
2283
|
-
return
|
|
2125
|
+
function formatLocatedChapterUri(archiveUri, chapter) {
|
|
2126
|
+
return `${archiveUri.replace(/\/+$/u, "")}/${chapter.uri.replace(/^wikg:\/\//u, "")}`;
|
|
2284
2127
|
}
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
|
|
2128
|
+
|
|
2129
|
+
// src/archive/write.ts
|
|
2130
|
+
var import_wiki_graph_core6 = require("wiki-graph-core");
|
|
2131
|
+
async function writeWikiGraphArchiveLocation(location, operation, options = {}) {
|
|
2132
|
+
const cacheOnly = options.searchIndexWritebackPolicy === "cache";
|
|
2133
|
+
const write = async (archiveFile = location.archiveFile) => await new import_wiki_graph_core6.WikiGraphArchiveFile(archiveFile).write(operation, {
|
|
2134
|
+
...cacheOnly ? {} : { derivedStateKeys: [location.archiveKey, location.archivePath] },
|
|
2135
|
+
...options.invalidateContinuationCursors === void 0 ? {} : {
|
|
2136
|
+
invalidateContinuationCursors: options.invalidateContinuationCursors
|
|
2137
|
+
},
|
|
2138
|
+
...options.searchIndexWritebackPolicy === void 0 ? {} : { searchIndexWritebackPolicy: options.searchIndexWritebackPolicy }
|
|
2139
|
+
});
|
|
2140
|
+
if (location.libraryArchiveTarget === void 0 || cacheOnly || options.refreshLibraryIndex === false) {
|
|
2141
|
+
return await write();
|
|
2288
2142
|
}
|
|
2289
|
-
|
|
2290
|
-
|
|
2143
|
+
return await (0, import_wiki_graph_core6.writeWikiGraphLibraryArchive)({
|
|
2144
|
+
additionalDerivedStateKeys: [location.archiveKey, location.archivePath],
|
|
2145
|
+
...options.invalidateContinuationCursors === void 0 ? {} : {
|
|
2146
|
+
invalidateContinuationCursors: options.invalidateContinuationCursors
|
|
2147
|
+
},
|
|
2148
|
+
...options.onIndexSyncError === void 0 ? {} : { onIndexSyncError: options.onIndexSyncError },
|
|
2149
|
+
operation: async (archiveFile) => await write(archiveFile),
|
|
2150
|
+
target: location.libraryArchiveTarget
|
|
2151
|
+
});
|
|
2291
2152
|
}
|
|
2292
2153
|
|
|
2293
2154
|
// src/archive/archive.ts
|
|
@@ -2307,13 +2168,13 @@ var WikiGraphArchiveManager = class {
|
|
|
2307
2168
|
}
|
|
2308
2169
|
async create(options) {
|
|
2309
2170
|
return await this.#runtime.run(async () => {
|
|
2310
|
-
const path =
|
|
2171
|
+
const path = await assertStandaloneWikiGraphArchivePath(options.path);
|
|
2311
2172
|
if (options.replace !== true && await nodePathExists(path)) {
|
|
2312
2173
|
throw new WikiGraphArchiveExistsError(path);
|
|
2313
2174
|
}
|
|
2314
|
-
const outputPath = (0,
|
|
2315
|
-
(0,
|
|
2316
|
-
`.${(0,
|
|
2175
|
+
const outputPath = (0, import_path5.join)(
|
|
2176
|
+
(0, import_path5.dirname)(path),
|
|
2177
|
+
`.${(0, import_path5.basename)(path)}.${(0, import_crypto2.randomUUID)()}.tmp.wikg`
|
|
2317
2178
|
);
|
|
2318
2179
|
try {
|
|
2319
2180
|
if (options.importPath === void 0) {
|
|
@@ -2327,10 +2188,10 @@ var WikiGraphArchiveManager = class {
|
|
|
2327
2188
|
});
|
|
2328
2189
|
}
|
|
2329
2190
|
if (options.replace === true) {
|
|
2330
|
-
await (0,
|
|
2191
|
+
await (0, import_promises4.rename)(outputPath, path);
|
|
2331
2192
|
} else {
|
|
2332
2193
|
try {
|
|
2333
|
-
await (0,
|
|
2194
|
+
await (0, import_promises4.link)(outputPath, path);
|
|
2334
2195
|
} catch (error) {
|
|
2335
2196
|
if (isNodeEEXISTError(error)) {
|
|
2336
2197
|
throw new WikiGraphArchiveExistsError(path);
|
|
@@ -2338,15 +2199,15 @@ var WikiGraphArchiveManager = class {
|
|
|
2338
2199
|
throw error;
|
|
2339
2200
|
}
|
|
2340
2201
|
}
|
|
2341
|
-
return { locatedUri: (0,
|
|
2202
|
+
return { locatedUri: (0, import_wiki_graph_core7.formatLocatedWikiGraphUri)(path), path };
|
|
2342
2203
|
} finally {
|
|
2343
|
-
await (0,
|
|
2204
|
+
await (0, import_promises4.rm)(outputPath, { force: true, recursive: true });
|
|
2344
2205
|
}
|
|
2345
2206
|
}, options.signal);
|
|
2346
2207
|
}
|
|
2347
|
-
async open(
|
|
2208
|
+
async open(target, options = {}) {
|
|
2348
2209
|
const location = await this.#runtime.run(
|
|
2349
|
-
async () => await resolveWikiGraphArchiveLocation(
|
|
2210
|
+
async () => await resolveWikiGraphArchiveLocation(target),
|
|
2350
2211
|
options.signal
|
|
2351
2212
|
);
|
|
2352
2213
|
return new WikiGraphArchiveHandle(this.#runtime, location);
|
|
@@ -2369,14 +2230,17 @@ var WikiGraphArchiveHandle = class {
|
|
|
2369
2230
|
return this.#location.locatedUri;
|
|
2370
2231
|
}
|
|
2371
2232
|
get objectUri() {
|
|
2372
|
-
return (0,
|
|
2233
|
+
return (0, import_wiki_graph_core7.parseLocatedWikiGraphUri)(this.#location.locatedUri).objectUri ?? "wikg://";
|
|
2373
2234
|
}
|
|
2374
2235
|
get path() {
|
|
2375
2236
|
return this.#location.archivePath;
|
|
2376
2237
|
}
|
|
2238
|
+
get target() {
|
|
2239
|
+
return this.#location.target;
|
|
2240
|
+
}
|
|
2377
2241
|
async inspect(options = {}) {
|
|
2378
2242
|
return await this.#readDocument(
|
|
2379
|
-
async (document) => await
|
|
2243
|
+
async (document) => await inspectWikiGraphArchive(document, {
|
|
2380
2244
|
archiveUri: this.#location.publicArchiveUri ?? this.locatedUri,
|
|
2381
2245
|
...options.chapterId === void 0 ? {} : { chapterId: options.chapterId }
|
|
2382
2246
|
}),
|
|
@@ -2384,18 +2248,20 @@ var WikiGraphArchiveHandle = class {
|
|
|
2384
2248
|
);
|
|
2385
2249
|
}
|
|
2386
2250
|
async search(query, options = {}) {
|
|
2387
|
-
const embeddingProvider = await this.#
|
|
2388
|
-
|
|
2251
|
+
const embeddingProvider = await this.#resolveQueryEmbeddingProvider(
|
|
2252
|
+
options.queryMode,
|
|
2389
2253
|
options.signal
|
|
2390
2254
|
);
|
|
2391
2255
|
return await this.#writeDocument(
|
|
2392
2256
|
async (document) => {
|
|
2393
|
-
const chapters = await this.#resolveQueryChapters(document, options
|
|
2257
|
+
const chapters = await this.#resolveQueryChapters(document, options, {
|
|
2258
|
+
embeddingProvider
|
|
2259
|
+
});
|
|
2394
2260
|
await ensureArchiveSearchIndex(document, {
|
|
2395
2261
|
...chapters === void 0 ? {} : { chapters },
|
|
2396
2262
|
...embeddingProvider === void 0 ? {} : { embeddingProvider }
|
|
2397
2263
|
});
|
|
2398
|
-
return await (0,
|
|
2264
|
+
return await (0, import_wiki_graph_core7.findArchiveObjects)(document, query, {
|
|
2399
2265
|
...withoutOperationAndScope(options),
|
|
2400
2266
|
archiveKey: this.archiveKey,
|
|
2401
2267
|
...chapters === void 0 ? {} : { chapters },
|
|
@@ -2410,14 +2276,14 @@ var WikiGraphArchiveHandle = class {
|
|
|
2410
2276
|
}
|
|
2411
2277
|
async list(options = {}) {
|
|
2412
2278
|
return await this.#readDocument(async (document) => {
|
|
2413
|
-
if ((0,
|
|
2414
|
-
return await (0,
|
|
2279
|
+
if ((0, import_wiki_graph_core7.isSourceLocatorScopeUri)(this.objectUri)) {
|
|
2280
|
+
return await (0, import_wiki_graph_core7.listArchiveSourceLocators)(document, this.objectUri, {
|
|
2415
2281
|
...options.cursor === void 0 ? {} : { cursor: options.cursor },
|
|
2416
2282
|
...options.limit === void 0 ? {} : { limit: options.limit }
|
|
2417
2283
|
});
|
|
2418
2284
|
}
|
|
2419
2285
|
const chapters = await this.#resolveScope(document, options);
|
|
2420
|
-
return await (0,
|
|
2286
|
+
return await (0, import_wiki_graph_core7.listArchiveCollection)(document, {
|
|
2421
2287
|
...withoutOperationAndScope(options),
|
|
2422
2288
|
...chapters === void 0 ? {} : { chapters }
|
|
2423
2289
|
});
|
|
@@ -2445,8 +2311,8 @@ var WikiGraphArchiveHandle = class {
|
|
|
2445
2311
|
async getSearchIndexStatus(options = {}) {
|
|
2446
2312
|
return await this.#readDocument(
|
|
2447
2313
|
async (document) => ({
|
|
2448
|
-
capabilities: await (0,
|
|
2449
|
-
current: await (0,
|
|
2314
|
+
capabilities: await (0, import_wiki_graph_core7.readSearchIndexCapabilityStatus)(document),
|
|
2315
|
+
current: await (0, import_wiki_graph_core7.isArchiveSearchIndexCurrent)(document)
|
|
2450
2316
|
}),
|
|
2451
2317
|
options
|
|
2452
2318
|
);
|
|
@@ -2454,14 +2320,14 @@ var WikiGraphArchiveHandle = class {
|
|
|
2454
2320
|
async syncSearchIndex(options = {}) {
|
|
2455
2321
|
const rebuilt = await this.#writeDocument(
|
|
2456
2322
|
async (document) => {
|
|
2457
|
-
const scope = options.skipUnindexed === true ? { chapters: await (0,
|
|
2323
|
+
const scope = options.skipUnindexed === true ? { chapters: await (0, import_wiki_graph_core7.listArchiveQueryableChapterIds)(document) } : {};
|
|
2458
2324
|
if (scope.chapters?.length === 0) {
|
|
2459
2325
|
throw new Error(
|
|
2460
2326
|
"Wiki Graph index cache is not ready. No chapters have a current FTS artifact or source embedding artifact."
|
|
2461
2327
|
);
|
|
2462
2328
|
}
|
|
2463
|
-
if (await (0,
|
|
2464
|
-
await (0,
|
|
2329
|
+
if (await (0, import_wiki_graph_core7.isArchiveSearchIndexCurrent)(document, scope)) return false;
|
|
2330
|
+
await (0, import_wiki_graph_core7.rebuildArchiveSearchIndex)(document, options.onProgress, scope);
|
|
2465
2331
|
return true;
|
|
2466
2332
|
},
|
|
2467
2333
|
{
|
|
@@ -2470,7 +2336,7 @@ var WikiGraphArchiveHandle = class {
|
|
|
2470
2336
|
}
|
|
2471
2337
|
);
|
|
2472
2338
|
await this.#runtime.run(
|
|
2473
|
-
async () => await (0,
|
|
2339
|
+
async () => await (0, import_wiki_graph_core7.deleteArchiveSearchSessions)(this.path),
|
|
2474
2340
|
options.signal
|
|
2475
2341
|
);
|
|
2476
2342
|
return { rebuilt };
|
|
@@ -2493,21 +2359,21 @@ var WikiGraphArchiveHandle = class {
|
|
|
2493
2359
|
}
|
|
2494
2360
|
);
|
|
2495
2361
|
await this.#runtime.run(
|
|
2496
|
-
async () => await (0,
|
|
2362
|
+
async () => await (0, import_wiki_graph_core7.deleteArchiveSearchSessions)(this.path),
|
|
2497
2363
|
options.signal
|
|
2498
2364
|
);
|
|
2499
2365
|
return status;
|
|
2500
2366
|
}
|
|
2501
2367
|
async listChapters(options = {}) {
|
|
2502
2368
|
return await this.#readDocument(
|
|
2503
|
-
async (document) => await (0,
|
|
2369
|
+
async (document) => await (0, import_wiki_graph_core7.listChapters)(document),
|
|
2504
2370
|
options
|
|
2505
2371
|
);
|
|
2506
2372
|
}
|
|
2507
2373
|
async getChapter(path, options = {}) {
|
|
2508
2374
|
return await this.#readDocument(async (document) => {
|
|
2509
|
-
const chapterId = await (0,
|
|
2510
|
-
return requireChapter(await (0,
|
|
2375
|
+
const chapterId = await (0, import_wiki_graph_core7.resolveChapterPathReadonly)(document, path);
|
|
2376
|
+
return requireChapter(await (0, import_wiki_graph_core7.listChapters)(document), chapterId);
|
|
2511
2377
|
}, options);
|
|
2512
2378
|
}
|
|
2513
2379
|
async addChapter(options) {
|
|
@@ -2516,17 +2382,17 @@ var WikiGraphArchiveHandle = class {
|
|
|
2516
2382
|
document,
|
|
2517
2383
|
options.parentPath
|
|
2518
2384
|
);
|
|
2519
|
-
await (0,
|
|
2385
|
+
await (0, import_wiki_graph_core7.assertNoActiveBuildJobConflicts)({
|
|
2520
2386
|
archive: this.#location.archiveFile,
|
|
2521
2387
|
operation: "Adding chapter",
|
|
2522
2388
|
scope: { kind: "archive" }
|
|
2523
2389
|
});
|
|
2524
|
-
let details = await (0,
|
|
2390
|
+
let details = await (0, import_wiki_graph_core7.addChapter)(document, {
|
|
2525
2391
|
...parentChapterId === void 0 ? {} : { parentChapterId },
|
|
2526
2392
|
...options.title === void 0 ? {} : { title: options.title }
|
|
2527
2393
|
});
|
|
2528
2394
|
if (options.source !== void 0) {
|
|
2529
|
-
details = await (0,
|
|
2395
|
+
details = await (0, import_wiki_graph_core7.setChapterSource)(
|
|
2530
2396
|
document,
|
|
2531
2397
|
details.chapterId,
|
|
2532
2398
|
asTextStream(options.source)
|
|
@@ -2537,7 +2403,7 @@ var WikiGraphArchiveHandle = class {
|
|
|
2537
2403
|
}
|
|
2538
2404
|
async getChapterArtifact(path, kind) {
|
|
2539
2405
|
return await this.#readDocument(async (document) => {
|
|
2540
|
-
const chapterId = await (0,
|
|
2406
|
+
const chapterId = await (0, import_wiki_graph_core7.resolveChapterPathReadonly)(document, path);
|
|
2541
2407
|
const [artifact, revision] = await Promise.all([
|
|
2542
2408
|
document.indexArtifacts.get(chapterId, kind),
|
|
2543
2409
|
document.serials.getRevision(chapterId)
|
|
@@ -2560,25 +2426,25 @@ var WikiGraphArchiveHandle = class {
|
|
|
2560
2426
|
}
|
|
2561
2427
|
async deleteChapterArtifact(path, kind) {
|
|
2562
2428
|
return await this.#writeDocument(async (document) => {
|
|
2563
|
-
const chapterId = await (0,
|
|
2429
|
+
const chapterId = await (0, import_wiki_graph_core7.resolveChapterPathReadonly)(document, path);
|
|
2564
2430
|
await document.indexArtifacts.delete(chapterId, kind);
|
|
2565
2431
|
return { chapterId, deleted: true, kind };
|
|
2566
2432
|
});
|
|
2567
2433
|
}
|
|
2568
2434
|
async moveChapter(path, options) {
|
|
2569
2435
|
return await this.#writeDocument(async (document) => {
|
|
2570
|
-
const chapterId = await (0,
|
|
2436
|
+
const chapterId = await (0, import_wiki_graph_core7.resolveChapterPathReadonly)(document, path);
|
|
2571
2437
|
const [afterChapterId, beforeChapterId, parentChapterId] = await Promise.all([
|
|
2572
2438
|
resolveOptionalChapterPath(document, options.afterPath),
|
|
2573
2439
|
resolveOptionalChapterPath(document, options.beforePath),
|
|
2574
2440
|
resolveOptionalChapterPath(document, options.parentPath)
|
|
2575
2441
|
]);
|
|
2576
|
-
await (0,
|
|
2442
|
+
await (0, import_wiki_graph_core7.assertNoActiveBuildJobConflicts)({
|
|
2577
2443
|
archive: this.#location.archiveFile,
|
|
2578
2444
|
operation: "Moving chapter",
|
|
2579
2445
|
scope: { kind: "archive" }
|
|
2580
2446
|
});
|
|
2581
|
-
return await (0,
|
|
2447
|
+
return await (0, import_wiki_graph_core7.moveChapter)(document, chapterId, {
|
|
2582
2448
|
...afterChapterId === void 0 ? {} : { afterChapterId },
|
|
2583
2449
|
...beforeChapterId === void 0 ? {} : { beforeChapterId },
|
|
2584
2450
|
...parentChapterId === void 0 ? {} : { parentChapterId },
|
|
@@ -2590,35 +2456,35 @@ var WikiGraphArchiveHandle = class {
|
|
|
2590
2456
|
}
|
|
2591
2457
|
async removeChapter(path, recursive = false) {
|
|
2592
2458
|
await this.#writeDocument(async (document) => {
|
|
2593
|
-
const chapterId = await (0,
|
|
2594
|
-
await (0,
|
|
2459
|
+
const chapterId = await (0, import_wiki_graph_core7.resolveChapterPathReadonly)(document, path);
|
|
2460
|
+
await (0, import_wiki_graph_core7.assertNoActiveBuildJobConflicts)({
|
|
2595
2461
|
archive: this.#location.archiveFile,
|
|
2596
2462
|
operation: "Removing chapter",
|
|
2597
2463
|
scope: { kind: "archive" }
|
|
2598
2464
|
});
|
|
2599
|
-
await (0,
|
|
2465
|
+
await (0, import_wiki_graph_core7.removeChapter)(document, chapterId, { recursive });
|
|
2600
2466
|
});
|
|
2601
2467
|
}
|
|
2602
2468
|
async resetChapter(path, stage) {
|
|
2603
2469
|
return await this.#writeDocument(async (document) => {
|
|
2604
|
-
const chapterId = await (0,
|
|
2470
|
+
const chapterId = await (0, import_wiki_graph_core7.resolveChapterPathReadonly)(document, path);
|
|
2605
2471
|
await assertChapterResetAllowed(
|
|
2606
2472
|
this.#location.archiveFile,
|
|
2607
2473
|
chapterId,
|
|
2608
2474
|
stage
|
|
2609
2475
|
);
|
|
2610
|
-
return await (0,
|
|
2476
|
+
return await (0, import_wiki_graph_core7.resetChapter)(document, chapterId, stage);
|
|
2611
2477
|
});
|
|
2612
2478
|
}
|
|
2613
2479
|
async setChapterSource(path, source, options = {}) {
|
|
2614
2480
|
return await this.#writeDocument(async (document) => {
|
|
2615
|
-
const chapterId = await (0,
|
|
2616
|
-
await (0,
|
|
2481
|
+
const chapterId = await (0, import_wiki_graph_core7.resolveChapterPathReadonly)(document, path);
|
|
2482
|
+
await (0, import_wiki_graph_core7.assertNoActiveBuildJobs)({
|
|
2617
2483
|
archive: this.#location.archiveFile,
|
|
2618
2484
|
chapterIds: [chapterId],
|
|
2619
2485
|
operation: "Setting chapter source"
|
|
2620
2486
|
});
|
|
2621
|
-
return await (0,
|
|
2487
|
+
return await (0, import_wiki_graph_core7.setChapterSource)(
|
|
2622
2488
|
document,
|
|
2623
2489
|
chapterId,
|
|
2624
2490
|
asTextStream(source),
|
|
@@ -2628,43 +2494,43 @@ var WikiGraphArchiveHandle = class {
|
|
|
2628
2494
|
}
|
|
2629
2495
|
async setChapterSummary(path, summary) {
|
|
2630
2496
|
return await this.#writeDocument(async (document) => {
|
|
2631
|
-
const chapterId = await (0,
|
|
2632
|
-
await (0,
|
|
2497
|
+
const chapterId = await (0, import_wiki_graph_core7.resolveChapterPathReadonly)(document, path);
|
|
2498
|
+
await (0, import_wiki_graph_core7.assertNoActiveBuildJobs)({
|
|
2633
2499
|
archive: this.#location.archiveFile,
|
|
2634
2500
|
chapterIds: [chapterId],
|
|
2635
2501
|
operation: "Setting chapter summary",
|
|
2636
2502
|
requiresTarget: "reading-summary"
|
|
2637
2503
|
});
|
|
2638
|
-
return await (0,
|
|
2504
|
+
return await (0, import_wiki_graph_core7.setChapterSummary)(document, chapterId, summary);
|
|
2639
2505
|
});
|
|
2640
2506
|
}
|
|
2641
2507
|
async setChapterTitle(path, title) {
|
|
2642
2508
|
return await this.#writeDocument(async (document) => {
|
|
2643
|
-
const chapterId = await (0,
|
|
2644
|
-
await (0,
|
|
2509
|
+
const chapterId = await (0, import_wiki_graph_core7.resolveChapterPathReadonly)(document, path);
|
|
2510
|
+
await (0, import_wiki_graph_core7.assertNoActiveBuildJobs)({
|
|
2645
2511
|
archive: this.#location.archiveFile,
|
|
2646
2512
|
chapterIds: [chapterId],
|
|
2647
2513
|
operation: "Setting chapter title"
|
|
2648
2514
|
});
|
|
2649
|
-
return await (0,
|
|
2515
|
+
return await (0, import_wiki_graph_core7.setChapterTitle)(document, chapterId, title);
|
|
2650
2516
|
});
|
|
2651
2517
|
}
|
|
2652
2518
|
async getChapterTree() {
|
|
2653
2519
|
return await this.#readDocument(
|
|
2654
|
-
async (document) => await (0,
|
|
2520
|
+
async (document) => await (0, import_wiki_graph_core7.getChapterTree)(document)
|
|
2655
2521
|
);
|
|
2656
2522
|
}
|
|
2657
2523
|
async applyChapterTree(tree, options = {}) {
|
|
2658
2524
|
return await this.#writeDocument(
|
|
2659
2525
|
async (document) => {
|
|
2660
2526
|
if (options.dryRun !== true) {
|
|
2661
|
-
await (0,
|
|
2527
|
+
await (0, import_wiki_graph_core7.assertNoActiveBuildJobConflicts)({
|
|
2662
2528
|
archive: this.#location.archiveFile,
|
|
2663
2529
|
operation: "Changing chapter tree",
|
|
2664
2530
|
scope: { kind: "archive" }
|
|
2665
2531
|
});
|
|
2666
2532
|
}
|
|
2667
|
-
return await (0,
|
|
2533
|
+
return await (0, import_wiki_graph_core7.applyChapterTree)(document, tree, {
|
|
2668
2534
|
dryRun: options.dryRun ?? false
|
|
2669
2535
|
});
|
|
2670
2536
|
},
|
|
@@ -2676,8 +2542,8 @@ var WikiGraphArchiveHandle = class {
|
|
|
2676
2542
|
async () => await withConfiguredWikimediaResolver(
|
|
2677
2543
|
objectUri,
|
|
2678
2544
|
async (wikimediaOptions) => await this.#readDocument(
|
|
2679
|
-
async (document) => await (0,
|
|
2680
|
-
...
|
|
2545
|
+
async (document) => await (0, import_wiki_graph_core7.readArchivePage)(document, objectUri, {
|
|
2546
|
+
...options,
|
|
2681
2547
|
...wikimediaOptions
|
|
2682
2548
|
}),
|
|
2683
2549
|
options
|
|
@@ -2688,27 +2554,33 @@ var WikiGraphArchiveHandle = class {
|
|
|
2688
2554
|
}
|
|
2689
2555
|
async related(objectUri = this.objectUri, options = {}) {
|
|
2690
2556
|
if (options.query === void 0) {
|
|
2557
|
+
if (options.queryMode !== void 0) {
|
|
2558
|
+
throw new Error("`queryMode` requires `query`.");
|
|
2559
|
+
}
|
|
2691
2560
|
return await this.#readDocument(async (document) => {
|
|
2692
2561
|
const chapters = await this.#resolveScope(document, {});
|
|
2693
|
-
return await (0,
|
|
2562
|
+
return await (0, import_wiki_graph_core7.listRelatedArchiveObjects)(document, objectUri, {
|
|
2694
2563
|
...withoutOperation(options),
|
|
2695
2564
|
...chapters === void 0 ? {} : { chapters }
|
|
2696
2565
|
});
|
|
2697
2566
|
}, options);
|
|
2698
2567
|
}
|
|
2699
|
-
const embeddingProvider = await this.#
|
|
2700
|
-
|
|
2568
|
+
const embeddingProvider = await this.#resolveQueryEmbeddingProvider(
|
|
2569
|
+
options.queryMode,
|
|
2701
2570
|
options.signal
|
|
2702
2571
|
);
|
|
2703
2572
|
return await this.#writeDocument(
|
|
2704
2573
|
async (document) => {
|
|
2705
|
-
const chapters = await this.#resolveQueryChapters(document, options
|
|
2574
|
+
const chapters = await this.#resolveQueryChapters(document, options, {
|
|
2575
|
+
embeddingProvider
|
|
2576
|
+
});
|
|
2706
2577
|
await ensureArchiveSearchIndex(document, {
|
|
2707
2578
|
...chapters === void 0 ? {} : { chapters },
|
|
2708
2579
|
...embeddingProvider === void 0 ? {} : { embeddingProvider }
|
|
2709
2580
|
});
|
|
2710
|
-
return await (0,
|
|
2581
|
+
return await (0, import_wiki_graph_core7.listRelatedArchiveObjects)(document, objectUri, {
|
|
2711
2582
|
...withoutOperation(options),
|
|
2583
|
+
...embeddingProvider === void 0 ? {} : { embeddingProvider },
|
|
2712
2584
|
...chapters === void 0 ? {} : { chapters }
|
|
2713
2585
|
});
|
|
2714
2586
|
},
|
|
@@ -2720,27 +2592,33 @@ var WikiGraphArchiveHandle = class {
|
|
|
2720
2592
|
}
|
|
2721
2593
|
async evidence(objectUri = this.objectUri, options = {}) {
|
|
2722
2594
|
if (options.query === void 0) {
|
|
2595
|
+
if (options.queryMode !== void 0) {
|
|
2596
|
+
throw new Error("`queryMode` requires `query`.");
|
|
2597
|
+
}
|
|
2723
2598
|
return await this.#readDocument(async (document) => {
|
|
2724
2599
|
const chapters = await this.#resolveScope(document, {});
|
|
2725
|
-
return await (0,
|
|
2600
|
+
return await (0, import_wiki_graph_core7.listArchiveEvidence)(document, objectUri, {
|
|
2726
2601
|
...withoutOperation(options),
|
|
2727
2602
|
...chapters === void 0 ? {} : { chapters }
|
|
2728
2603
|
});
|
|
2729
2604
|
}, options);
|
|
2730
2605
|
}
|
|
2731
|
-
const embeddingProvider = await this.#
|
|
2732
|
-
|
|
2606
|
+
const embeddingProvider = await this.#resolveQueryEmbeddingProvider(
|
|
2607
|
+
options.queryMode,
|
|
2733
2608
|
options.signal
|
|
2734
2609
|
);
|
|
2735
2610
|
return await this.#writeDocument(
|
|
2736
2611
|
async (document) => {
|
|
2737
|
-
const chapters = await this.#resolveQueryChapters(document, options
|
|
2612
|
+
const chapters = await this.#resolveQueryChapters(document, options, {
|
|
2613
|
+
embeddingProvider
|
|
2614
|
+
});
|
|
2738
2615
|
await ensureArchiveSearchIndex(document, {
|
|
2739
2616
|
...chapters === void 0 ? {} : { chapters },
|
|
2740
2617
|
...embeddingProvider === void 0 ? {} : { embeddingProvider }
|
|
2741
2618
|
});
|
|
2742
|
-
return await (0,
|
|
2619
|
+
return await (0, import_wiki_graph_core7.listArchiveEvidence)(document, objectUri, {
|
|
2743
2620
|
...withoutOperation(options),
|
|
2621
|
+
...embeddingProvider === void 0 ? {} : { embeddingProvider },
|
|
2744
2622
|
...chapters === void 0 ? {} : { chapters }
|
|
2745
2623
|
});
|
|
2746
2624
|
},
|
|
@@ -2752,7 +2630,7 @@ var WikiGraphArchiveHandle = class {
|
|
|
2752
2630
|
}
|
|
2753
2631
|
async pack(objectUri = this.objectUri, budget = 5e3, options = {}) {
|
|
2754
2632
|
return await this.#readDocument(
|
|
2755
|
-
async (document) => await (0,
|
|
2633
|
+
async (document) => await (0, import_wiki_graph_core7.packArchiveContext)(document, objectUri, budget),
|
|
2756
2634
|
options
|
|
2757
2635
|
);
|
|
2758
2636
|
}
|
|
@@ -2774,8 +2652,26 @@ var WikiGraphArchiveHandle = class {
|
|
|
2774
2652
|
return meta;
|
|
2775
2653
|
}, options);
|
|
2776
2654
|
}
|
|
2655
|
+
async setArchiveTitle(title, options = {}) {
|
|
2656
|
+
const normalized = title?.trim() ?? null;
|
|
2657
|
+
if (title !== null && normalized === "") {
|
|
2658
|
+
throw new Error("Archive title cannot be empty.");
|
|
2659
|
+
}
|
|
2660
|
+
return await this.#writeDocument(async (document) => {
|
|
2661
|
+
if (normalized === null) {
|
|
2662
|
+
await document.metadata.deleteKey("", "title");
|
|
2663
|
+
} else {
|
|
2664
|
+
await document.metadata.put(
|
|
2665
|
+
{ kind: import_wiki_graph_core7.ObjectMetadataKind.Archive, objectPath: "" },
|
|
2666
|
+
"title",
|
|
2667
|
+
normalized
|
|
2668
|
+
);
|
|
2669
|
+
}
|
|
2670
|
+
return normalized;
|
|
2671
|
+
}, options);
|
|
2672
|
+
}
|
|
2777
2673
|
async readCover(options = {}) {
|
|
2778
|
-
const app = new
|
|
2674
|
+
const app = new import_wiki_graph_core7.WikiGraph({});
|
|
2779
2675
|
return await this.#runtime.run(
|
|
2780
2676
|
async () => await app.openSession(
|
|
2781
2677
|
this.#location.archiveFile,
|
|
@@ -2823,7 +2719,7 @@ var WikiGraphArchiveHandle = class {
|
|
|
2823
2719
|
}
|
|
2824
2720
|
async #readDocument(operation, options = {}) {
|
|
2825
2721
|
return await this.#runtime.run(
|
|
2826
|
-
async () => await new
|
|
2722
|
+
async () => await new import_wiki_graph_core7.WikiGraphArchiveFile(this.#location.archiveFile).readDocument(
|
|
2827
2723
|
operation
|
|
2828
2724
|
),
|
|
2829
2725
|
options.signal
|
|
@@ -2831,28 +2727,33 @@ var WikiGraphArchiveHandle = class {
|
|
|
2831
2727
|
}
|
|
2832
2728
|
async #writeDocument(operation, options = {}) {
|
|
2833
2729
|
return await this.#runtime.run(async () => {
|
|
2834
|
-
|
|
2835
|
-
|
|
2836
|
-
|
|
2730
|
+
return await writeWikiGraphArchiveLocation(this.#location, operation, {
|
|
2731
|
+
...options.onIndexSyncError === void 0 ? {} : { onIndexSyncError: options.onIndexSyncError },
|
|
2732
|
+
...options.refreshLibraryIndex === void 0 ? {} : { refreshLibraryIndex: options.refreshLibraryIndex },
|
|
2837
2733
|
...options.searchIndexWritebackPolicy === void 0 ? {} : {
|
|
2838
2734
|
searchIndexWritebackPolicy: options.searchIndexWritebackPolicy
|
|
2839
2735
|
}
|
|
2840
2736
|
});
|
|
2841
|
-
if (options.refreshLibraryIndex !== false) {
|
|
2842
|
-
await this.#refreshLibraryIndex(options.onIndexSyncError);
|
|
2843
|
-
}
|
|
2844
|
-
return result;
|
|
2845
2737
|
}, options.signal);
|
|
2846
2738
|
}
|
|
2847
2739
|
async #resolveScope(document, options) {
|
|
2848
2740
|
if (options.chapters !== void 0) return options.chapters;
|
|
2849
2741
|
return (await resolveArchiveScope(document, this.objectUri, options.depth))?.chapterIds;
|
|
2850
2742
|
}
|
|
2851
|
-
async #resolveQueryChapters(document, options) {
|
|
2743
|
+
async #resolveQueryChapters(document, options, capabilities) {
|
|
2852
2744
|
const chapters = await this.#resolveScope(document, options);
|
|
2853
|
-
|
|
2854
|
-
|
|
2855
|
-
...
|
|
2745
|
+
const coverageOptions = {
|
|
2746
|
+
...chapters === void 0 ? {} : { chapters },
|
|
2747
|
+
...capabilities.embeddingProvider === void 0 ? {} : { embeddingProvider: capabilities.embeddingProvider },
|
|
2748
|
+
requireEmbeddingProvider: true,
|
|
2749
|
+
...options.queryMode === void 0 ? {} : { queryMode: options.queryMode }
|
|
2750
|
+
};
|
|
2751
|
+
if (options.skipUnindexed !== true) {
|
|
2752
|
+
await (0, import_wiki_graph_core7.assertArchiveIndexArtifactsReady)(document, coverageOptions);
|
|
2753
|
+
return chapters;
|
|
2754
|
+
}
|
|
2755
|
+
const queryable = await (0, import_wiki_graph_core7.listArchiveQueryableChapterIds)(document, {
|
|
2756
|
+
...coverageOptions
|
|
2856
2757
|
});
|
|
2857
2758
|
if (queryable.length === 0) {
|
|
2858
2759
|
throw new Error(
|
|
@@ -2861,56 +2762,24 @@ var WikiGraphArchiveHandle = class {
|
|
|
2861
2762
|
}
|
|
2862
2763
|
return queryable;
|
|
2863
2764
|
}
|
|
2864
|
-
async #
|
|
2865
|
-
if (
|
|
2866
|
-
|
|
2867
|
-
|
|
2868
|
-
|
|
2869
|
-
|
|
2870
|
-
|
|
2871
|
-
|
|
2872
|
-
|
|
2873
|
-
this.#location.libraryDirtyTarget
|
|
2765
|
+
async #resolveQueryEmbeddingProvider(queryMode, signal) {
|
|
2766
|
+
if (queryMode === "fts") return void 0;
|
|
2767
|
+
const provider = await this.#runtime.run(
|
|
2768
|
+
createConfiguredEmbeddingProvider,
|
|
2769
|
+
signal
|
|
2770
|
+
);
|
|
2771
|
+
if (queryMode === "embedding" && provider === void 0) {
|
|
2772
|
+
throw new Error(
|
|
2773
|
+
"Embedding query mode requires embeddings configuration at `wikg://local/config/embeddings`."
|
|
2874
2774
|
);
|
|
2875
|
-
if (state.status !== "missing") {
|
|
2876
|
-
await (0, import_wiki_graph_core5.rebuildWikiGraphLibraryIndex)(this.#location.libraryDirtyTarget);
|
|
2877
|
-
}
|
|
2878
|
-
} catch (error) {
|
|
2879
|
-
onError?.(error);
|
|
2880
2775
|
}
|
|
2776
|
+
return provider;
|
|
2881
2777
|
}
|
|
2882
2778
|
};
|
|
2883
|
-
async function resolveWikiGraphArchiveLocation(uriOrPath) {
|
|
2884
|
-
if (!uriOrPath.startsWith("wikg://")) {
|
|
2885
|
-
return createPathLocation(resolveWikiGraphRuntimePath(uriOrPath));
|
|
2886
|
-
}
|
|
2887
|
-
const parsed = (0, import_wiki_graph_core5.parseLocatedWikiGraphUri)(uriOrPath);
|
|
2888
|
-
const portableArchiveLocator = parsed.archivePath ?? uriOrPath;
|
|
2889
|
-
const archiveLocator = portableArchiveLocator.startsWith("wikg://lib/") ? portableArchiveLocator : resolveWikiGraphRuntimePath(portableArchiveLocator);
|
|
2890
|
-
const libraryArchiveTarget = archiveLocator.startsWith("wikg://lib/") ? (0, import_wiki_graph_core5.parseWikiGraphLibraryUri)(archiveLocator) : void 0;
|
|
2891
|
-
const archiveFile = libraryArchiveTarget?.kind === "archive" ? await (0, import_wiki_graph_core5.resolveWikiGraphLibraryArchiveFile)(archiveLocator) : new NodeFile(archiveLocator);
|
|
2892
|
-
const archivePath = getNodeResourcePath(archiveFile);
|
|
2893
|
-
return {
|
|
2894
|
-
archiveFile,
|
|
2895
|
-
archiveKey: archivePath,
|
|
2896
|
-
archivePath,
|
|
2897
|
-
indexScope: { archiveKey: archivePath, archivePath, kind: "archive-index" },
|
|
2898
|
-
...libraryArchiveTarget?.kind === "archive" ? {
|
|
2899
|
-
libraryArchiveTarget,
|
|
2900
|
-
libraryDirtyTarget: {
|
|
2901
|
-
isDefault: libraryArchiveTarget.isDefault,
|
|
2902
|
-
kind: "scope",
|
|
2903
|
-
...libraryArchiveTarget.publicId === void 0 ? {} : { publicId: libraryArchiveTarget.publicId }
|
|
2904
|
-
},
|
|
2905
|
-
publicArchiveUri: portableArchiveLocator
|
|
2906
|
-
} : {},
|
|
2907
|
-
locatedUri: (0, import_wiki_graph_core5.formatLocatedWikiGraphUri)(archivePath, parsed.objectUri)
|
|
2908
|
-
};
|
|
2909
|
-
}
|
|
2910
2779
|
async function ensureArchiveSearchIndex(document, options = {}) {
|
|
2911
2780
|
const scope = options.chapters === void 0 ? {} : { chapters: options.chapters };
|
|
2912
|
-
if (await (0,
|
|
2913
|
-
await (0,
|
|
2781
|
+
if (await (0, import_wiki_graph_core7.isArchiveSearchIndexCurrent)(document, scope)) return;
|
|
2782
|
+
await (0, import_wiki_graph_core7.rebuildArchiveSearchIndex)(document, void 0, {
|
|
2914
2783
|
...scope,
|
|
2915
2784
|
...options.embeddingProvider === void 0 ? {} : { embeddingProvider: options.embeddingProvider }
|
|
2916
2785
|
});
|
|
@@ -2920,10 +2789,10 @@ async function resolveArchiveScope(document, objectUri, depth) {
|
|
|
2920
2789
|
if (parsed === void 0 || parsed.kind === "collection" && depth === void 0) {
|
|
2921
2790
|
return void 0;
|
|
2922
2791
|
}
|
|
2923
|
-
const chapters = await (0,
|
|
2792
|
+
const chapters = await (0, import_wiki_graph_core7.listChapters)(document);
|
|
2924
2793
|
const entries = parsed.kind === "collection" ? chapters.filter((chapter) => chapter.depth <= depth) : selectChapterSubtree(
|
|
2925
2794
|
chapters,
|
|
2926
|
-
await (0,
|
|
2795
|
+
await (0, import_wiki_graph_core7.resolveChapterPathReadonly)(document, parsed.chapterPath),
|
|
2927
2796
|
depth
|
|
2928
2797
|
);
|
|
2929
2798
|
return { chapterIds: entries.map((entry) => entry.chapterId), entries };
|
|
@@ -2945,32 +2814,23 @@ function selectChapterSubtree(chapters, rootChapterId, depth) {
|
|
|
2945
2814
|
(chapter) => chapter.chapterId === root.chapterId || chapter.path.startsWith(prefix) && (depth === void 0 || chapter.depth - root.depth <= depth)
|
|
2946
2815
|
);
|
|
2947
2816
|
}
|
|
2948
|
-
function createPathLocation(path) {
|
|
2949
|
-
return {
|
|
2950
|
-
archiveFile: new NodeFile(path),
|
|
2951
|
-
archiveKey: path,
|
|
2952
|
-
archivePath: path,
|
|
2953
|
-
indexScope: { archiveKey: path, archivePath: path, kind: "archive-index" },
|
|
2954
|
-
locatedUri: (0, import_wiki_graph_core5.formatLocatedWikiGraphUri)(path)
|
|
2955
|
-
};
|
|
2956
|
-
}
|
|
2957
2817
|
async function createEmptyArchiveFile(path) {
|
|
2958
|
-
const directoryPath = await (0,
|
|
2959
|
-
(0,
|
|
2818
|
+
const directoryPath = await (0, import_promises4.mkdtemp)(
|
|
2819
|
+
(0, import_path5.join)((0, import_os3.tmpdir)(), "wikigraph-archive-write-")
|
|
2960
2820
|
);
|
|
2961
2821
|
try {
|
|
2962
2822
|
const directory = new NodeDirectory(directoryPath);
|
|
2963
|
-
const document = await
|
|
2823
|
+
const document = await import_wiki_graph_core7.DirectoryDocument.open(directory);
|
|
2964
2824
|
try {
|
|
2965
2825
|
await document.openSession(async (openedDocument) => {
|
|
2966
|
-
await openedDocument.writeToc({ items: [], version:
|
|
2826
|
+
await openedDocument.writeToc({ items: [], version: import_wiki_graph_core7.TOC_FILE_VERSION });
|
|
2967
2827
|
});
|
|
2968
2828
|
} finally {
|
|
2969
2829
|
await document.release();
|
|
2970
2830
|
}
|
|
2971
|
-
await (0,
|
|
2831
|
+
await (0, import_wiki_graph_core7.writeWikgArchive)(directory, new NodeFile(path));
|
|
2972
2832
|
} finally {
|
|
2973
|
-
await (0,
|
|
2833
|
+
await (0, import_promises4.rm)(directoryPath, { force: true, recursive: true });
|
|
2974
2834
|
}
|
|
2975
2835
|
}
|
|
2976
2836
|
function isNodeEEXISTError(error) {
|
|
@@ -2978,7 +2838,7 @@ function isNodeEEXISTError(error) {
|
|
|
2978
2838
|
}
|
|
2979
2839
|
async function nodePathExists(path) {
|
|
2980
2840
|
try {
|
|
2981
|
-
await (0,
|
|
2841
|
+
await (0, import_promises4.stat)(path);
|
|
2982
2842
|
return true;
|
|
2983
2843
|
} catch (error) {
|
|
2984
2844
|
if (isNodeENOENTError(error)) return false;
|
|
@@ -2990,13 +2850,13 @@ function isNodeENOENTError(error) {
|
|
|
2990
2850
|
}
|
|
2991
2851
|
function parseObjectMetadataTarget(objectPath) {
|
|
2992
2852
|
if (objectPath === "") {
|
|
2993
|
-
return { kind:
|
|
2853
|
+
return { kind: import_wiki_graph_core7.ObjectMetadataKind.Archive, objectPath };
|
|
2994
2854
|
}
|
|
2995
2855
|
const chapter = /^chapter\/([1-9][0-9]*)(?:\/.*)?$/u.exec(objectPath);
|
|
2996
2856
|
if (chapter?.[1] !== void 0) {
|
|
2997
2857
|
return {
|
|
2998
2858
|
chapterId: Number(chapter[1]),
|
|
2999
|
-
kind:
|
|
2859
|
+
kind: import_wiki_graph_core7.ObjectMetadataKind.Chapter,
|
|
3000
2860
|
objectPath
|
|
3001
2861
|
};
|
|
3002
2862
|
}
|
|
@@ -3004,7 +2864,7 @@ function parseObjectMetadataTarget(objectPath) {
|
|
|
3004
2864
|
if (chunk?.[1] !== void 0) {
|
|
3005
2865
|
return {
|
|
3006
2866
|
chunkId: Number(chunk[1]),
|
|
3007
|
-
kind:
|
|
2867
|
+
kind: import_wiki_graph_core7.ObjectMetadataKind.Chunk,
|
|
3008
2868
|
objectPath
|
|
3009
2869
|
};
|
|
3010
2870
|
}
|
|
@@ -3012,7 +2872,7 @@ function parseObjectMetadataTarget(objectPath) {
|
|
|
3012
2872
|
if (entity?.[1] !== void 0) {
|
|
3013
2873
|
return {
|
|
3014
2874
|
entityQid: entity[1],
|
|
3015
|
-
kind:
|
|
2875
|
+
kind: import_wiki_graph_core7.ObjectMetadataKind.Entity,
|
|
3016
2876
|
objectPath
|
|
3017
2877
|
};
|
|
3018
2878
|
}
|
|
@@ -3021,14 +2881,14 @@ function parseObjectMetadataTarget(objectPath) {
|
|
|
3021
2881
|
);
|
|
3022
2882
|
if (triple?.[1] !== void 0) {
|
|
3023
2883
|
return {
|
|
3024
|
-
kind:
|
|
2884
|
+
kind: import_wiki_graph_core7.ObjectMetadataKind.Triple,
|
|
3025
2885
|
objectPath,
|
|
3026
2886
|
tripleObjectQid: triple[3],
|
|
3027
2887
|
triplePredicate: decodeURIComponent(triple[2]),
|
|
3028
2888
|
tripleSubjectQid: triple[1]
|
|
3029
2889
|
};
|
|
3030
2890
|
}
|
|
3031
|
-
return { kind:
|
|
2891
|
+
return { kind: import_wiki_graph_core7.ObjectMetadataKind.Object, objectPath };
|
|
3032
2892
|
}
|
|
3033
2893
|
function withoutOperation(options) {
|
|
3034
2894
|
const { signal: _signal, ...rest } = options;
|
|
@@ -3044,7 +2904,7 @@ function withoutOperationAndScope(options) {
|
|
|
3044
2904
|
return rest;
|
|
3045
2905
|
}
|
|
3046
2906
|
async function resolveOptionalChapterPath(document, path) {
|
|
3047
|
-
return path === void 0 ? void 0 : await (0,
|
|
2907
|
+
return path === void 0 ? void 0 : await (0, import_wiki_graph_core7.resolveChapterPathReadonly)(document, path);
|
|
3048
2908
|
}
|
|
3049
2909
|
function requireChapter(chapters, chapterId) {
|
|
3050
2910
|
const chapter = chapters.find((entry) => entry.chapterId === chapterId);
|
|
@@ -3058,7 +2918,7 @@ function asTextStream(text) {
|
|
|
3058
2918
|
}
|
|
3059
2919
|
async function assertChapterResetAllowed(archive, chapterId, stage) {
|
|
3060
2920
|
if (stage === "planned") {
|
|
3061
|
-
await (0,
|
|
2921
|
+
await (0, import_wiki_graph_core7.assertNoActiveBuildJobs)({
|
|
3062
2922
|
archive,
|
|
3063
2923
|
chapterIds: [chapterId],
|
|
3064
2924
|
operation: "Resetting chapter to planned"
|
|
@@ -3066,14 +2926,14 @@ async function assertChapterResetAllowed(archive, chapterId, stage) {
|
|
|
3066
2926
|
return;
|
|
3067
2927
|
}
|
|
3068
2928
|
if (stage === "sourced") {
|
|
3069
|
-
await (0,
|
|
2929
|
+
await (0, import_wiki_graph_core7.assertNoActiveBuildJobs)({
|
|
3070
2930
|
archive,
|
|
3071
2931
|
chapterIds: [chapterId],
|
|
3072
2932
|
operation: "Resetting chapter graph",
|
|
3073
2933
|
requiresTarget: "reading-graph"
|
|
3074
2934
|
});
|
|
3075
2935
|
}
|
|
3076
|
-
await (0,
|
|
2936
|
+
await (0, import_wiki_graph_core7.assertNoActiveBuildJobs)({
|
|
3077
2937
|
archive,
|
|
3078
2938
|
chapterIds: [chapterId],
|
|
3079
2939
|
operation: "Resetting chapter summary",
|
|
@@ -3084,12 +2944,13 @@ async function assertChapterResetAllowed(archive, chapterId, stage) {
|
|
|
3084
2944
|
// src/wikispine.ts
|
|
3085
2945
|
var import_child_process = require("child_process");
|
|
3086
2946
|
var nodeWikispineCommandRunner = {
|
|
3087
|
-
run: async ({ args, command, input, onStdout, signal }) => await new Promise((
|
|
2947
|
+
run: async ({ args, command, input, onStdout, signal }) => await new Promise((resolve4, reject) => {
|
|
3088
2948
|
signal?.throwIfAborted();
|
|
3089
2949
|
const child = (0, import_child_process.spawn)(command, [...args], {
|
|
3090
2950
|
stdio: ["pipe", "pipe", "pipe"]
|
|
3091
2951
|
});
|
|
3092
2952
|
const stderr = [];
|
|
2953
|
+
let stdoutQueue = Promise.resolve();
|
|
3093
2954
|
let settled = false;
|
|
3094
2955
|
const settle = (operation) => {
|
|
3095
2956
|
if (settled) return;
|
|
@@ -3105,14 +2966,15 @@ var nodeWikispineCommandRunner = {
|
|
|
3105
2966
|
child.stdout.setEncoding("utf8");
|
|
3106
2967
|
child.stdout.on("data", (chunk) => {
|
|
3107
2968
|
if (settled) return;
|
|
3108
|
-
|
|
3109
|
-
|
|
3110
|
-
|
|
2969
|
+
child.stdout.pause();
|
|
2970
|
+
stdoutQueue = stdoutQueue.then(async () => await onStdout(chunk)).then(() => {
|
|
2971
|
+
child.stdout.resume();
|
|
2972
|
+
}).catch((error) => {
|
|
3111
2973
|
child.kill();
|
|
3112
2974
|
settle(
|
|
3113
2975
|
() => reject(error instanceof Error ? error : new Error(String(error)))
|
|
3114
2976
|
);
|
|
3115
|
-
}
|
|
2977
|
+
});
|
|
3116
2978
|
});
|
|
3117
2979
|
child.stderr.on("data", (chunk) => stderr.push(chunk));
|
|
3118
2980
|
child.on("error", (error) => {
|
|
@@ -3123,12 +2985,14 @@ var nodeWikispineCommandRunner = {
|
|
|
3123
2985
|
);
|
|
3124
2986
|
});
|
|
3125
2987
|
child.on("close", (exitCode) => {
|
|
3126
|
-
|
|
3127
|
-
(
|
|
3128
|
-
|
|
3129
|
-
|
|
3130
|
-
|
|
3131
|
-
|
|
2988
|
+
void stdoutQueue.then(() => {
|
|
2989
|
+
settle(
|
|
2990
|
+
() => resolve4({
|
|
2991
|
+
exitCode,
|
|
2992
|
+
stderr: Buffer.concat(stderr).toString("utf8")
|
|
2993
|
+
})
|
|
2994
|
+
);
|
|
2995
|
+
});
|
|
3132
2996
|
});
|
|
3133
2997
|
child.stdin.end(input);
|
|
3134
2998
|
})
|
|
@@ -3139,7 +3003,7 @@ function abortError(signal) {
|
|
|
3139
3003
|
|
|
3140
3004
|
// src/config.ts
|
|
3141
3005
|
var import_ai2 = require("ai");
|
|
3142
|
-
var
|
|
3006
|
+
var import_wiki_graph_core8 = require("wiki-graph-core");
|
|
3143
3007
|
var WikiGraphConfigManager = class {
|
|
3144
3008
|
#runtime;
|
|
3145
3009
|
constructor(runtime) {
|
|
@@ -3222,7 +3086,7 @@ var WikiGraphConfigManager = class {
|
|
|
3222
3086
|
if (resolved === void 0) {
|
|
3223
3087
|
throw new Error("WikiSpine provider is not configured.");
|
|
3224
3088
|
}
|
|
3225
|
-
const result = await (0,
|
|
3089
|
+
const result = await (0, import_wiki_graph_core8.testWikispineRuntime)({
|
|
3226
3090
|
...resolved,
|
|
3227
3091
|
...resolved.provider === "cli" ? { commandRunner: nodeWikispineCommandRunner } : {}
|
|
3228
3092
|
});
|
|
@@ -3245,7 +3109,7 @@ function parseProvider(value) {
|
|
|
3245
3109
|
}
|
|
3246
3110
|
|
|
3247
3111
|
// src/continuations.ts
|
|
3248
|
-
var
|
|
3112
|
+
var import_wiki_graph_core9 = require("wiki-graph-core");
|
|
3249
3113
|
var WikiGraphContinuationManager = class {
|
|
3250
3114
|
#runtime;
|
|
3251
3115
|
constructor(runtime) {
|
|
@@ -3260,13 +3124,13 @@ var WikiGraphContinuationManager = class {
|
|
|
3260
3124
|
async create(context, cursor) {
|
|
3261
3125
|
if (cursor === null || cursor === void 0) return null;
|
|
3262
3126
|
return await this.#runtime.run(
|
|
3263
|
-
async () => await (0,
|
|
3127
|
+
async () => await (0, import_wiki_graph_core9.createContinuationCursor)(
|
|
3264
3128
|
createContinuationPayload(context, cursor)
|
|
3265
3129
|
)
|
|
3266
3130
|
);
|
|
3267
3131
|
}
|
|
3268
3132
|
async #next(options) {
|
|
3269
|
-
const cursor = await (0,
|
|
3133
|
+
const cursor = await (0, import_wiki_graph_core9.readContinuationCursor)(options.cursor);
|
|
3270
3134
|
const continuationCursor = options.format === void 0 ? cursor : { ...cursor, format: options.format };
|
|
3271
3135
|
const limit = options.limit ?? 20;
|
|
3272
3136
|
if (options.archive !== void 0) {
|
|
@@ -3290,46 +3154,51 @@ var WikiGraphContinuationManager = class {
|
|
|
3290
3154
|
}
|
|
3291
3155
|
};
|
|
3292
3156
|
async function continueArchiveCursor(cursor, limit) {
|
|
3157
|
+
const embeddingProvider = cursor.kind === "evidence" || cursor.kind === "related" ? await resolveCursorEmbeddingProvider(cursor) : void 0;
|
|
3293
3158
|
const location = await resolveWikiGraphArchiveLocation(
|
|
3294
|
-
getCursorArchivePath(cursor)
|
|
3159
|
+
archiveTargetFromLogicalLocator(getCursorArchivePath(cursor))
|
|
3295
3160
|
);
|
|
3296
|
-
return await new
|
|
3161
|
+
return await new import_wiki_graph_core9.WikiGraphArchiveFile(location.archiveFile).readDocument(
|
|
3297
3162
|
async (document) => {
|
|
3298
3163
|
switch (cursor.kind) {
|
|
3299
3164
|
case "source-locators":
|
|
3300
|
-
return await (0,
|
|
3165
|
+
return await (0, import_wiki_graph_core9.listArchiveSourceLocators)(document, cursor.targetUri, {
|
|
3301
3166
|
cursor: cursor.cursor,
|
|
3302
3167
|
limit
|
|
3303
3168
|
});
|
|
3304
3169
|
case "collection":
|
|
3305
|
-
return await (0,
|
|
3170
|
+
return await (0, import_wiki_graph_core9.listArchiveCollection)(
|
|
3306
3171
|
document,
|
|
3307
3172
|
createCollectionOptions(cursor, limit)
|
|
3308
3173
|
);
|
|
3309
3174
|
case "search":
|
|
3310
|
-
return await (0,
|
|
3175
|
+
return await (0, import_wiki_graph_core9.findArchiveObjects)(
|
|
3311
3176
|
document,
|
|
3312
3177
|
cursor.query ?? "",
|
|
3313
3178
|
await createFindOptions(cursor, limit)
|
|
3314
3179
|
);
|
|
3315
3180
|
case "evidence":
|
|
3316
|
-
return await (0,
|
|
3181
|
+
return await (0, import_wiki_graph_core9.listArchiveEvidence)(document, cursor.targetUri, {
|
|
3317
3182
|
...cursor.chapters === null ? {} : { chapters: cursor.chapters },
|
|
3318
3183
|
cursor: cursor.cursor,
|
|
3319
3184
|
limit,
|
|
3320
3185
|
order: cursor.order,
|
|
3321
3186
|
...cursor.query === void 0 ? {} : { query: cursor.query },
|
|
3187
|
+
...cursor.queryMode === void 0 ? {} : { queryMode: cursor.queryMode },
|
|
3188
|
+
...embeddingProvider === void 0 ? {} : { embeddingProvider },
|
|
3322
3189
|
...cursor.skipUnindexed === void 0 ? {} : { skipUnindexed: cursor.skipUnindexed },
|
|
3323
3190
|
...cursor.sourceContext === void 0 ? {} : { sourceContext: cursor.sourceContext }
|
|
3324
3191
|
});
|
|
3325
3192
|
case "related":
|
|
3326
|
-
return await (0,
|
|
3193
|
+
return await (0, import_wiki_graph_core9.listRelatedArchiveObjects)(document, cursor.targetUri, {
|
|
3327
3194
|
...cursor.chapters === null ? {} : { chapters: cursor.chapters },
|
|
3328
3195
|
cursor: cursor.cursor,
|
|
3329
3196
|
...cursor.evidenceLimit === void 0 ? {} : { evidenceLimit: cursor.evidenceLimit },
|
|
3330
3197
|
limit,
|
|
3331
3198
|
order: cursor.order,
|
|
3332
3199
|
...cursor.query === void 0 ? {} : { query: cursor.query },
|
|
3200
|
+
...cursor.queryMode === void 0 ? {} : { queryMode: cursor.queryMode },
|
|
3201
|
+
...embeddingProvider === void 0 ? {} : { embeddingProvider },
|
|
3333
3202
|
...cursor.role === void 0 ? {} : { role: cursor.role },
|
|
3334
3203
|
...cursor.skipUnindexed === void 0 ? {} : { skipUnindexed: cursor.skipUnindexed },
|
|
3335
3204
|
...cursor.sourceContext === void 0 ? {} : { sourceContext: cursor.sourceContext }
|
|
@@ -3339,6 +3208,7 @@ async function continueArchiveCursor(cursor, limit) {
|
|
|
3339
3208
|
);
|
|
3340
3209
|
}
|
|
3341
3210
|
async function continueLibraryCursor(cursor, limit) {
|
|
3211
|
+
const embeddingProvider = cursor.kind === "evidence" || cursor.kind === "related" ? await resolveCursorEmbeddingProvider(cursor) : void 0;
|
|
3342
3212
|
if (cursor.kind === "source-locators") {
|
|
3343
3213
|
throw new Error(
|
|
3344
3214
|
"Source locator cursors do not use the aggregate library index."
|
|
@@ -3347,39 +3217,41 @@ async function continueLibraryCursor(cursor, limit) {
|
|
|
3347
3217
|
if (cursor.indexScope.kind !== "library-index") {
|
|
3348
3218
|
throw new Error("Internal error: expected a library index cursor.");
|
|
3349
3219
|
}
|
|
3350
|
-
const target = await (0,
|
|
3220
|
+
const target = await (0, import_wiki_graph_core9.resolveWikiGraphLibraryQueryTargetById)(
|
|
3351
3221
|
cursor.indexScope.libraryId
|
|
3352
3222
|
);
|
|
3353
3223
|
switch (cursor.kind) {
|
|
3354
3224
|
case "collection":
|
|
3355
|
-
return await (requireLibraryQuery(cursor) === "archive-members" ? (0,
|
|
3225
|
+
return await (requireLibraryQuery(cursor) === "archive-members" ? (0, import_wiki_graph_core9.listWikiGraphLibraryArchiveMembers)(
|
|
3356
3226
|
target,
|
|
3357
3227
|
createCollectionOptions(cursor, limit)
|
|
3358
|
-
) : (0,
|
|
3228
|
+
) : (0, import_wiki_graph_core9.listWikiGraphLibraryObjects)(
|
|
3359
3229
|
target,
|
|
3360
3230
|
createCollectionOptions(cursor, limit)
|
|
3361
3231
|
));
|
|
3362
3232
|
case "search":
|
|
3363
|
-
return await (requireLibraryQuery(cursor) === "archive-members" ? (0,
|
|
3233
|
+
return await (requireLibraryQuery(cursor) === "archive-members" ? (0, import_wiki_graph_core9.findWikiGraphLibraryArchiveMembers)(
|
|
3364
3234
|
target,
|
|
3365
3235
|
cursor.query ?? "",
|
|
3366
3236
|
await createFindOptions(cursor, limit)
|
|
3367
|
-
) : (0,
|
|
3237
|
+
) : (0, import_wiki_graph_core9.findWikiGraphLibraryObjects)(
|
|
3368
3238
|
target,
|
|
3369
3239
|
cursor.query ?? "",
|
|
3370
3240
|
await createFindOptions(cursor, limit)
|
|
3371
3241
|
));
|
|
3372
3242
|
case "evidence":
|
|
3373
|
-
return await (0,
|
|
3243
|
+
return await (0, import_wiki_graph_core9.listWikiGraphLibraryEvidence)(target, cursor.targetUri, {
|
|
3374
3244
|
cursor: cursor.cursor,
|
|
3375
3245
|
limit,
|
|
3376
3246
|
order: cursor.order,
|
|
3377
3247
|
...cursor.query === void 0 ? {} : { query: cursor.query },
|
|
3248
|
+
...cursor.queryMode === void 0 ? {} : { queryMode: cursor.queryMode },
|
|
3249
|
+
...embeddingProvider === void 0 ? {} : { embeddingProvider },
|
|
3378
3250
|
...cursor.skipUnindexed === void 0 ? {} : { skipUnindexed: cursor.skipUnindexed },
|
|
3379
3251
|
...cursor.sourceContext === void 0 ? {} : { sourceContext: cursor.sourceContext }
|
|
3380
3252
|
});
|
|
3381
3253
|
case "related":
|
|
3382
|
-
return await (0,
|
|
3254
|
+
return await (0, import_wiki_graph_core9.listRelatedWikiGraphLibraryObjects)(
|
|
3383
3255
|
target,
|
|
3384
3256
|
cursor.targetUri,
|
|
3385
3257
|
{
|
|
@@ -3388,6 +3260,8 @@ async function continueLibraryCursor(cursor, limit) {
|
|
|
3388
3260
|
limit,
|
|
3389
3261
|
order: cursor.order,
|
|
3390
3262
|
...cursor.query === void 0 ? {} : { query: cursor.query },
|
|
3263
|
+
...cursor.queryMode === void 0 ? {} : { queryMode: cursor.queryMode },
|
|
3264
|
+
...embeddingProvider === void 0 ? {} : { embeddingProvider },
|
|
3391
3265
|
...cursor.role === void 0 ? {} : { role: cursor.role },
|
|
3392
3266
|
...cursor.skipUnindexed === void 0 ? {} : { skipUnindexed: cursor.skipUnindexed },
|
|
3393
3267
|
...cursor.sourceContext === void 0 ? {} : { sourceContext: cursor.sourceContext }
|
|
@@ -3412,7 +3286,7 @@ function createCollectionOptions(cursor, limit) {
|
|
|
3412
3286
|
};
|
|
3413
3287
|
}
|
|
3414
3288
|
async function createFindOptions(cursor, limit) {
|
|
3415
|
-
const embeddingProvider = await
|
|
3289
|
+
const embeddingProvider = await resolveCursorEmbeddingProvider(cursor);
|
|
3416
3290
|
return {
|
|
3417
3291
|
archiveKey: cursor.archiveKey,
|
|
3418
3292
|
...cursor.backlinks === void 0 ? {} : { backlinks: cursor.backlinks },
|
|
@@ -3420,6 +3294,7 @@ async function createFindOptions(cursor, limit) {
|
|
|
3420
3294
|
cursor: cursor.cursor,
|
|
3421
3295
|
...cursor.evidenceLimit === void 0 ? {} : { evidenceLimit: cursor.evidenceLimit },
|
|
3422
3296
|
limit,
|
|
3297
|
+
...cursor.queryMode === void 0 ? {} : { queryMode: cursor.queryMode },
|
|
3423
3298
|
...cursor.skipUnindexed === void 0 ? {} : { skipUnindexed: cursor.skipUnindexed },
|
|
3424
3299
|
...cursor.sourceContext === void 0 ? {} : { sourceContext: cursor.sourceContext },
|
|
3425
3300
|
...cursor.triplePattern === void 0 ? {} : { triplePattern: cursor.triplePattern },
|
|
@@ -3440,7 +3315,7 @@ function getCursorArchivePath(cursor) {
|
|
|
3440
3315
|
}
|
|
3441
3316
|
async function persistResultCursor(cursor, result) {
|
|
3442
3317
|
if (result.nextCursor === null) return result;
|
|
3443
|
-
const nextCursor = await (0,
|
|
3318
|
+
const nextCursor = await (0, import_wiki_graph_core9.createContinuationCursor)({
|
|
3444
3319
|
...cursor,
|
|
3445
3320
|
cursor: result.nextCursor
|
|
3446
3321
|
});
|
|
@@ -3469,6 +3344,7 @@ function createContinuationPayload(context, cursor) {
|
|
|
3469
3344
|
kind: "evidence",
|
|
3470
3345
|
order: context.order ?? "doc-asc",
|
|
3471
3346
|
...context.query === void 0 ? {} : { query: context.query },
|
|
3347
|
+
...context.queryMode === void 0 ? {} : { queryMode: context.queryMode },
|
|
3472
3348
|
...context.skipUnindexed === void 0 ? {} : { skipUnindexed: context.skipUnindexed },
|
|
3473
3349
|
...context.sourceContext === void 0 ? {} : { sourceContext: context.sourceContext },
|
|
3474
3350
|
targetUri: requireTargetUri(context, "Evidence")
|
|
@@ -3485,6 +3361,7 @@ function createContinuationPayload(context, cursor) {
|
|
|
3485
3361
|
kind: "related",
|
|
3486
3362
|
order: context.order ?? "doc-asc",
|
|
3487
3363
|
...context.query === void 0 ? {} : { query: context.query },
|
|
3364
|
+
...context.queryMode === void 0 ? {} : { queryMode: context.queryMode },
|
|
3488
3365
|
...context.role === void 0 ? {} : { role: context.role },
|
|
3489
3366
|
...context.skipUnindexed === void 0 ? {} : { skipUnindexed: context.skipUnindexed },
|
|
3490
3367
|
...context.sourceContext === void 0 ? {} : { sourceContext: context.sourceContext },
|
|
@@ -3521,6 +3398,7 @@ function createContinuationPayload(context, cursor) {
|
|
|
3521
3398
|
kind: "search",
|
|
3522
3399
|
...createLibraryQueryPayload(context),
|
|
3523
3400
|
...context.query === void 0 ? {} : { query: context.query },
|
|
3401
|
+
...context.queryMode === void 0 ? {} : { queryMode: context.queryMode },
|
|
3524
3402
|
...context.skipUnindexed === void 0 ? {} : { skipUnindexed: context.skipUnindexed },
|
|
3525
3403
|
...context.sourceContext === void 0 ? {} : { sourceContext: context.sourceContext },
|
|
3526
3404
|
...context.triplePattern === void 0 ? {} : { triplePattern: context.triplePattern },
|
|
@@ -3528,6 +3406,17 @@ function createContinuationPayload(context, cursor) {
|
|
|
3528
3406
|
};
|
|
3529
3407
|
}
|
|
3530
3408
|
}
|
|
3409
|
+
async function resolveCursorEmbeddingProvider(cursor) {
|
|
3410
|
+
if (cursor.kind !== "search" && cursor.query === void 0) return void 0;
|
|
3411
|
+
if (cursor.queryMode === "fts") return void 0;
|
|
3412
|
+
const provider = await createConfiguredEmbeddingProvider();
|
|
3413
|
+
if (cursor.queryMode === "embedding" && provider === void 0) {
|
|
3414
|
+
throw new Error(
|
|
3415
|
+
"Embedding query mode requires embeddings configuration at `wikg://local/config/embeddings`."
|
|
3416
|
+
);
|
|
3417
|
+
}
|
|
3418
|
+
return provider;
|
|
3419
|
+
}
|
|
3531
3420
|
function requireTargetUri(context, label) {
|
|
3532
3421
|
if (context.targetUri !== void 0) return context.targetUri;
|
|
3533
3422
|
throw new Error(`${label} continuation cursors require a target URI.`);
|
|
@@ -3543,17 +3432,20 @@ function createLibraryQueryPayload(context) {
|
|
|
3543
3432
|
}
|
|
3544
3433
|
|
|
3545
3434
|
// src/default-worker.ts
|
|
3546
|
-
var
|
|
3435
|
+
var import_wiki_graph_core14 = require("wiki-graph-core");
|
|
3547
3436
|
var import_worker3 = require("wiki-graph-core/worker");
|
|
3548
3437
|
|
|
3549
3438
|
// src/stage.ts
|
|
3550
|
-
var import_wiki_graph_core8 = require("wiki-graph-core");
|
|
3551
|
-
var import_wiki_graph_core9 = require("wiki-graph-core");
|
|
3552
3439
|
var import_wiki_graph_core10 = require("wiki-graph-core");
|
|
3440
|
+
var import_wiki_graph_core11 = require("wiki-graph-core");
|
|
3441
|
+
var import_wiki_graph_core12 = require("wiki-graph-core");
|
|
3553
3442
|
function createStageLLM(config, options) {
|
|
3554
|
-
const llmOptions = buildWikiGraphLLMOptions(config)
|
|
3555
|
-
|
|
3556
|
-
|
|
3443
|
+
const llmOptions = options?.provider === void 0 ? buildWikiGraphLLMOptions(config) : {
|
|
3444
|
+
...config.concurrent?.request === void 0 ? {} : { concurrent: config.concurrent.request },
|
|
3445
|
+
streamProvider: options.provider
|
|
3446
|
+
};
|
|
3447
|
+
return new import_wiki_graph_core12.LLM({
|
|
3448
|
+
sampling: (0, import_wiki_graph_core11.createDefaultWikiGraphSampling)({
|
|
3557
3449
|
...llmOptions.temperature === void 0 ? {} : { temperature: llmOptions.temperature },
|
|
3558
3450
|
...llmOptions.topP === void 0 ? {} : { topP: llmOptions.topP }
|
|
3559
3451
|
}),
|
|
@@ -3565,10 +3457,13 @@ function createStageLLM(config, options) {
|
|
|
3565
3457
|
});
|
|
3566
3458
|
}
|
|
3567
3459
|
async function loadRequiredStageConfig(options) {
|
|
3460
|
+
const injected = options.llmJSON === void 0 ? getWikiGraphSDKProviders().llm : void 0;
|
|
3568
3461
|
const config = await loadWikiGraphRuntimeConfig({
|
|
3569
|
-
...options.llmJSON === void 0 ? {} : { llmJSON: options.llmJSON }
|
|
3462
|
+
...options.llmJSON === void 0 ? {} : { llmJSON: options.llmJSON },
|
|
3463
|
+
...options.llmJSON === void 0 && injected !== void 0 ? { skipLLMConfig: true } : {},
|
|
3464
|
+
...getWikiGraphSDKProviders().embedding === void 0 ? {} : { skipEmbeddingConfig: true }
|
|
3570
3465
|
});
|
|
3571
|
-
if (config.llm?.provider === void 0 || config.llm.model === void 0) {
|
|
3466
|
+
if (injected === void 0 && (config.llm?.provider === void 0 || config.llm.model === void 0)) {
|
|
3572
3467
|
throw new Error(
|
|
3573
3468
|
"Missing LLM configuration. Set --llm for one run, or configure `wikg://local/config/llm` with provider and model."
|
|
3574
3469
|
);
|
|
@@ -3576,9 +3471,134 @@ async function loadRequiredStageConfig(options) {
|
|
|
3576
3471
|
return config;
|
|
3577
3472
|
}
|
|
3578
3473
|
|
|
3474
|
+
// src/planning.ts
|
|
3475
|
+
var DEFAULT_GENERATION_JOB_CONCURRENCY = 3;
|
|
3476
|
+
var DEFAULT_GENERATION_REQUEST_CONCURRENCY = 6;
|
|
3477
|
+
function planGenerationTask(task, words, chapters, concurrent, model) {
|
|
3478
|
+
const profile = getGenerationPlanningProfile(task);
|
|
3479
|
+
const calls = Math.max(chapters, Math.ceil(words / profile.wordsPerCall));
|
|
3480
|
+
const effectiveConcurrency = Math.max(
|
|
3481
|
+
1,
|
|
3482
|
+
task === "reading-graph" ? 1 : concurrent.request
|
|
3483
|
+
);
|
|
3484
|
+
const callBatches = Math.ceil(calls / effectiveConcurrency);
|
|
3485
|
+
const wordSeconds = words * profile.secondsPerWord;
|
|
3486
|
+
return {
|
|
3487
|
+
model,
|
|
3488
|
+
timeSeconds: {
|
|
3489
|
+
max: Math.ceil(callBatches * profile.maxSecondsPerCall + wordSeconds),
|
|
3490
|
+
min: Math.ceil(callBatches * profile.minSecondsPerCall + wordSeconds)
|
|
3491
|
+
},
|
|
3492
|
+
tokens: {
|
|
3493
|
+
cacheableInput: Math.ceil(words * profile.cacheableInputTokenPerWord),
|
|
3494
|
+
input: Math.ceil(words * profile.inputTokenPerWord),
|
|
3495
|
+
output: Math.ceil(words * profile.outputTokenPerWord)
|
|
3496
|
+
}
|
|
3497
|
+
};
|
|
3498
|
+
}
|
|
3499
|
+
function createGenerationPerformanceHints(input) {
|
|
3500
|
+
if (!input.hasJobWork) {
|
|
3501
|
+
return [];
|
|
3502
|
+
}
|
|
3503
|
+
const hints = [];
|
|
3504
|
+
const recommendedRequest = input.concurrent.request < 4 ? DEFAULT_GENERATION_REQUEST_CONCURRENCY : input.concurrent.request < 8 ? 8 : void 0;
|
|
3505
|
+
if (input.hasRequestWork && recommendedRequest !== void 0) {
|
|
3506
|
+
hints.push({
|
|
3507
|
+
configKey: "request",
|
|
3508
|
+
configValue: recommendedRequest,
|
|
3509
|
+
current: input.concurrent.request,
|
|
3510
|
+
kind: "request",
|
|
3511
|
+
message: "LLM request concurrency can often be higher. Use at least 4; 6-8 is usually faster when the provider allows it.",
|
|
3512
|
+
recommended: recommendedRequest
|
|
3513
|
+
});
|
|
3514
|
+
}
|
|
3515
|
+
if (input.concurrent.job < 4 && input.chapters > 1) {
|
|
3516
|
+
hints.push({
|
|
3517
|
+
configKey: "job",
|
|
3518
|
+
configValue: 4,
|
|
3519
|
+
current: input.concurrent.job,
|
|
3520
|
+
kind: "job",
|
|
3521
|
+
message: "Multiple chapters need work and job concurrency is below 4. Raising it lets chapter jobs run in parallel.",
|
|
3522
|
+
recommended: 4
|
|
3523
|
+
});
|
|
3524
|
+
}
|
|
3525
|
+
return hints;
|
|
3526
|
+
}
|
|
3527
|
+
function formatGenerationPlanningModel(llm) {
|
|
3528
|
+
if (llm?.model === void 0) {
|
|
3529
|
+
return "not configured";
|
|
3530
|
+
}
|
|
3531
|
+
return llm.provider === void 0 ? llm.model : `${llm.provider}/${llm.model}`;
|
|
3532
|
+
}
|
|
3533
|
+
function formatGenerationPlanningDuration(seconds) {
|
|
3534
|
+
if (seconds < 60) {
|
|
3535
|
+
return `${seconds}s`;
|
|
3536
|
+
}
|
|
3537
|
+
const minutes = Math.round(seconds / 60);
|
|
3538
|
+
if (minutes < 60) {
|
|
3539
|
+
return `${minutes}m`;
|
|
3540
|
+
}
|
|
3541
|
+
return `${Math.round(minutes / 60)}h`;
|
|
3542
|
+
}
|
|
3543
|
+
function getGenerationPlanningProfile(task) {
|
|
3544
|
+
switch (task) {
|
|
3545
|
+
case "index-fts":
|
|
3546
|
+
return {
|
|
3547
|
+
cacheableInputTokenPerWord: 0,
|
|
3548
|
+
inputTokenPerWord: 0,
|
|
3549
|
+
maxSecondsPerCall: 1,
|
|
3550
|
+
minSecondsPerCall: 0,
|
|
3551
|
+
outputTokenPerWord: 0,
|
|
3552
|
+
secondsPerWord: 5e-4,
|
|
3553
|
+
wordsPerCall: 1e5
|
|
3554
|
+
};
|
|
3555
|
+
case "index-embedding-source":
|
|
3556
|
+
case "index-embedding-summary":
|
|
3557
|
+
return {
|
|
3558
|
+
cacheableInputTokenPerWord: 0,
|
|
3559
|
+
inputTokenPerWord: 0,
|
|
3560
|
+
maxSecondsPerCall: 10,
|
|
3561
|
+
minSecondsPerCall: 1,
|
|
3562
|
+
outputTokenPerWord: 0,
|
|
3563
|
+
secondsPerWord: 2e-3,
|
|
3564
|
+
wordsPerCall: 1e4
|
|
3565
|
+
};
|
|
3566
|
+
case "knowledge-graph":
|
|
3567
|
+
return {
|
|
3568
|
+
cacheableInputTokenPerWord: 60,
|
|
3569
|
+
inputTokenPerWord: 80,
|
|
3570
|
+
maxSecondsPerCall: 35,
|
|
3571
|
+
minSecondsPerCall: 15,
|
|
3572
|
+
outputTokenPerWord: 25,
|
|
3573
|
+
secondsPerWord: 0.02,
|
|
3574
|
+
wordsPerCall: 35
|
|
3575
|
+
};
|
|
3576
|
+
case "reading-graph":
|
|
3577
|
+
return {
|
|
3578
|
+
cacheableInputTokenPerWord: 20,
|
|
3579
|
+
inputTokenPerWord: 25,
|
|
3580
|
+
maxSecondsPerCall: 45,
|
|
3581
|
+
minSecondsPerCall: 15,
|
|
3582
|
+
outputTokenPerWord: 4,
|
|
3583
|
+
secondsPerWord: 0.01,
|
|
3584
|
+
wordsPerCall: 160
|
|
3585
|
+
};
|
|
3586
|
+
case "reading-summary":
|
|
3587
|
+
return {
|
|
3588
|
+
cacheableInputTokenPerWord: 45,
|
|
3589
|
+
inputTokenPerWord: 55,
|
|
3590
|
+
maxSecondsPerCall: 25,
|
|
3591
|
+
minSecondsPerCall: 10,
|
|
3592
|
+
outputTokenPerWord: 4,
|
|
3593
|
+
secondsPerWord: 0.01,
|
|
3594
|
+
wordsPerCall: 110
|
|
3595
|
+
};
|
|
3596
|
+
}
|
|
3597
|
+
}
|
|
3598
|
+
|
|
3579
3599
|
// src/worker.ts
|
|
3580
3600
|
var import_worker = require("wiki-graph-core/worker");
|
|
3581
|
-
var
|
|
3601
|
+
var import_wiki_graph_core13 = require("wiki-graph-core");
|
|
3582
3602
|
var import_worker2 = require("wiki-graph-core/worker");
|
|
3583
3603
|
async function runBuildJobWorker(options) {
|
|
3584
3604
|
installNodeWikiGraphPlatform();
|
|
@@ -3591,21 +3611,29 @@ async function runBuildJobWorker(options) {
|
|
|
3591
3611
|
|
|
3592
3612
|
// src/default-worker.ts
|
|
3593
3613
|
async function runWikiGraphQueueWorker(options = {}) {
|
|
3594
|
-
const
|
|
3614
|
+
const providers = getWikiGraphSDKProviders();
|
|
3615
|
+
const config = await loadWikiGraphRuntimeConfig({
|
|
3616
|
+
...providers.embedding === void 0 ? {} : { skipEmbeddingConfig: true },
|
|
3617
|
+
...providers.llm === void 0 ? {} : { skipLLMConfig: true }
|
|
3618
|
+
});
|
|
3595
3619
|
await runBuildJobWorker({
|
|
3596
3620
|
concurrency: config.concurrent?.job ?? DEFAULT_GENERATION_JOB_CONCURRENCY,
|
|
3597
3621
|
executeJob: async (job, reporter, context) => {
|
|
3598
|
-
await (0,
|
|
3622
|
+
await (0, import_wiki_graph_core14.withLoggingContext)(
|
|
3599
3623
|
{ logDirectory: job.log, operation: "build-job" },
|
|
3600
3624
|
async () => await executeBuildJob(job, reporter, context)
|
|
3601
3625
|
);
|
|
3602
3626
|
},
|
|
3627
|
+
...options.idleTimeoutMs === void 0 ? {} : { idleTimeoutMs: options.idleTimeoutMs },
|
|
3603
3628
|
...options.signal === void 0 ? {} : { signal: options.signal }
|
|
3604
3629
|
});
|
|
3605
3630
|
}
|
|
3606
3631
|
async function executeBuildJob(job, reporter, context) {
|
|
3632
|
+
const providers = getWikiGraphSDKProviders();
|
|
3607
3633
|
const config = await loadWikiGraphRuntimeConfig({
|
|
3608
|
-
...job.llmJSON === void 0 ? {} : { llmJSON: job.llmJSON }
|
|
3634
|
+
...job.llmJSON === void 0 ? {} : { llmJSON: job.llmJSON },
|
|
3635
|
+
...providers.embedding === void 0 ? {} : { skipEmbeddingConfig: true },
|
|
3636
|
+
...job.llmJSON === void 0 && providers.llm !== void 0 ? { skipLLMConfig: true } : {}
|
|
3609
3637
|
});
|
|
3610
3638
|
const execution = await openJobExecutor(
|
|
3611
3639
|
job,
|
|
@@ -3667,9 +3695,9 @@ async function executeStep(job, kind, execution, reporter, context, inputOptions
|
|
|
3667
3695
|
const stepWorkspace = await resetStepWorkspace(job.workspace, kind);
|
|
3668
3696
|
const inputFile = await stepWorkspace.createFile("input.jsonl");
|
|
3669
3697
|
const outputWorkspace = await stepWorkspace.createDirectory("output");
|
|
3670
|
-
const revision = await new
|
|
3698
|
+
const revision = await new import_wiki_graph_core14.WikiGraphArchiveFile(job.archive).readDocument(
|
|
3671
3699
|
async (document) => {
|
|
3672
|
-
await (0,
|
|
3700
|
+
await (0, import_wiki_graph_core14.getChapterDetails)(document, job.chapterId);
|
|
3673
3701
|
return await (0, import_worker3.writeChapterJobInputFile)(
|
|
3674
3702
|
document,
|
|
3675
3703
|
job.chapterId,
|
|
@@ -3679,7 +3707,7 @@ async function executeStep(job, kind, execution, reporter, context, inputOptions
|
|
|
3679
3707
|
);
|
|
3680
3708
|
}
|
|
3681
3709
|
);
|
|
3682
|
-
await (0,
|
|
3710
|
+
await (0, import_wiki_graph_core14.recordBuildJobInputRevision)({
|
|
3683
3711
|
currentRevision: revision,
|
|
3684
3712
|
jobId: job.jobId,
|
|
3685
3713
|
ownerId: requireRunningJobOwnerId(job)
|
|
@@ -3709,16 +3737,23 @@ async function executeStep(job, kind, execution, reporter, context, inputOptions
|
|
|
3709
3737
|
total: 1,
|
|
3710
3738
|
unit: "item"
|
|
3711
3739
|
});
|
|
3712
|
-
await
|
|
3713
|
-
|
|
3714
|
-
|
|
3715
|
-
|
|
3716
|
-
|
|
3717
|
-
|
|
3718
|
-
|
|
3719
|
-
|
|
3720
|
-
|
|
3721
|
-
|
|
3740
|
+
const target = await resolveWikiGraphArchiveTarget(job.archive);
|
|
3741
|
+
const resolvedLocation = await resolveWikiGraphArchiveLocation(target);
|
|
3742
|
+
const location = target.kind === "standalone" ? { ...resolvedLocation, archiveFile: job.archive } : resolvedLocation;
|
|
3743
|
+
await writeWikiGraphArchiveLocation(
|
|
3744
|
+
location,
|
|
3745
|
+
async (document) => {
|
|
3746
|
+
assertJobStillRunning(await (0, import_wiki_graph_core14.getBuildJob)(job.jobId));
|
|
3747
|
+
await (0, import_worker3.applyChapterJobArtifactFile)(
|
|
3748
|
+
document,
|
|
3749
|
+
job.chapterId,
|
|
3750
|
+
kind,
|
|
3751
|
+
revision,
|
|
3752
|
+
result.artifactFile
|
|
3753
|
+
);
|
|
3754
|
+
},
|
|
3755
|
+
{ invalidateContinuationCursors: true }
|
|
3756
|
+
);
|
|
3722
3757
|
await reporter.updatePhase({
|
|
3723
3758
|
done: 1,
|
|
3724
3759
|
phase: "committing",
|
|
@@ -3726,37 +3761,46 @@ async function executeStep(job, kind, execution, reporter, context, inputOptions
|
|
|
3726
3761
|
unit: "item"
|
|
3727
3762
|
});
|
|
3728
3763
|
await reporter.stepCompleted(kind);
|
|
3729
|
-
assertJobStillRunning(await (0,
|
|
3764
|
+
assertJobStillRunning(await (0, import_wiki_graph_core14.getBuildJob)(job.jobId));
|
|
3730
3765
|
}
|
|
3731
3766
|
async function openJobExecutor(job, config, signal, reporter) {
|
|
3732
3767
|
const generation = !job.target.startsWith("index-");
|
|
3733
3768
|
const stageConfig = generation ? await loadRequiredStageConfig({
|
|
3734
3769
|
...job.llmJSON === void 0 ? {} : { llmJSON: job.llmJSON }
|
|
3735
3770
|
}) : void 0;
|
|
3771
|
+
const injectedLLM = job.llmJSON === void 0 ? getWikiGraphSDKProviders().llm : void 0;
|
|
3736
3772
|
const llm = stageConfig === void 0 ? void 0 : createStageLLM(stageConfig, {
|
|
3737
3773
|
cacheDirectory: job.cache,
|
|
3738
3774
|
logDirectory: job.log,
|
|
3739
3775
|
onTokenUsage: async (usage) => {
|
|
3740
3776
|
await reporter.addTokenUsage(usage);
|
|
3741
|
-
}
|
|
3777
|
+
},
|
|
3778
|
+
onStreamProgress: async ({ outputCharacters }) => {
|
|
3779
|
+
await reporter.addOutputCharacters(outputCharacters);
|
|
3780
|
+
},
|
|
3781
|
+
...injectedLLM === void 0 ? {} : { provider: injectedLLM }
|
|
3742
3782
|
});
|
|
3743
3783
|
const promptSource = job.prompt ?? stageConfig?.prompt;
|
|
3744
3784
|
const wikispine = job.target === "knowledge-graph" ? requireKnowledgeGraphWikispineConfig(config) : void 0;
|
|
3745
3785
|
const request = llm === void 0 ? void 0 : async (messages, index, maxRetries) => await llm.request(messages, {
|
|
3746
3786
|
retryIndex: index,
|
|
3747
3787
|
retryMax: maxRetries,
|
|
3748
|
-
scope:
|
|
3788
|
+
scope: import_wiki_graph_core14.WikiGraphScope.ReaderExtraction,
|
|
3749
3789
|
signal
|
|
3750
3790
|
});
|
|
3751
3791
|
if (request !== void 0 && llm !== void 0) {
|
|
3752
3792
|
request.lazy = async (operation) => await llm.request(async () => await operation(request));
|
|
3753
3793
|
}
|
|
3754
|
-
const wikimediaResolver = job.target !== "knowledge-graph" ? void 0 : await (0,
|
|
3794
|
+
const wikimediaResolver = job.target !== "knowledge-graph" ? void 0 : await (0, import_wiki_graph_core14.openWikimediaResolver)(
|
|
3755
3795
|
config.wikimedia === void 0 ? {
|
|
3756
3796
|
kind: "local",
|
|
3757
3797
|
llmRequest: requireValue(
|
|
3758
3798
|
request,
|
|
3759
3799
|
"Local Wikimedia resolution requires an LLM."
|
|
3800
|
+
),
|
|
3801
|
+
llmModelId: requireValue(
|
|
3802
|
+
stageConfig?.llm?.model ?? injectedLLM?.model,
|
|
3803
|
+
"Local Wikimedia resolution requires an LLM model."
|
|
3760
3804
|
)
|
|
3761
3805
|
} : {
|
|
3762
3806
|
endpoint: config.wikimedia.endpoint,
|
|
@@ -3764,7 +3808,7 @@ async function openJobExecutor(job, config, signal, reporter) {
|
|
|
3764
3808
|
token: config.wikimedia.token
|
|
3765
3809
|
}
|
|
3766
3810
|
);
|
|
3767
|
-
const embeddingProvider = job.target === "index-embedding-source" || job.target === "index-embedding-summary" ? buildSearchIndexEmbeddingProvider(requireEmbeddingConfig(config)) : void 0;
|
|
3811
|
+
const embeddingProvider = job.target === "index-embedding-source" || job.target === "index-embedding-summary" ? getWikiGraphSDKProviders().embedding ?? buildSearchIndexEmbeddingProvider(requireEmbeddingConfig(config)) : void 0;
|
|
3768
3812
|
return {
|
|
3769
3813
|
async close() {
|
|
3770
3814
|
await wikimediaResolver?.close();
|
|
@@ -3780,9 +3824,9 @@ async function openJobExecutor(job, config, signal, reporter) {
|
|
|
3780
3824
|
}
|
|
3781
3825
|
}
|
|
3782
3826
|
}),
|
|
3783
|
-
...promptSource === void 0 ? {} : { extractionPrompt: (0,
|
|
3827
|
+
...promptSource === void 0 ? {} : { extractionPrompt: (0, import_wiki_graph_core10.resolveExtractionPrompt)(promptSource) },
|
|
3784
3828
|
...promptSource === void 0 ? {} : {
|
|
3785
|
-
knowledgeGraphPrompt: (0,
|
|
3829
|
+
knowledgeGraphPrompt: (0, import_wiki_graph_core10.resolveKnowledgeGraphRecallPrompt)(promptSource)
|
|
3786
3830
|
}
|
|
3787
3831
|
};
|
|
3788
3832
|
}
|
|
@@ -3794,12 +3838,12 @@ async function resetStepWorkspace(workspace, kind) {
|
|
|
3794
3838
|
return await workspace.createDirectory(name);
|
|
3795
3839
|
}
|
|
3796
3840
|
async function readChapterStage(job) {
|
|
3797
|
-
return await new
|
|
3798
|
-
async (document) => (await (0,
|
|
3841
|
+
return await new import_wiki_graph_core14.WikiGraphArchiveFile(job.archive).readDocument(
|
|
3842
|
+
async (document) => (await (0, import_wiki_graph_core14.getChapterDetails)(document, job.chapterId)).stage
|
|
3799
3843
|
);
|
|
3800
3844
|
}
|
|
3801
3845
|
async function assertCurrentFtsArtifact(job) {
|
|
3802
|
-
await new
|
|
3846
|
+
await new import_wiki_graph_core14.WikiGraphArchiveFile(job.archive).readDocument(async (document) => {
|
|
3803
3847
|
const revision = await document.serials.getRevision(job.chapterId);
|
|
3804
3848
|
const artifact = await document.indexArtifacts.get(job.chapterId, "fts");
|
|
3805
3849
|
if (artifact?.sourceRevision !== revision) {
|
|
@@ -3898,27 +3942,27 @@ function normalizeOptionalPath(path) {
|
|
|
3898
3942
|
}
|
|
3899
3943
|
|
|
3900
3944
|
// src/jobs.ts
|
|
3901
|
-
var
|
|
3945
|
+
var import_wiki_graph_core15 = require("wiki-graph-core");
|
|
3902
3946
|
var TERMINAL_STATES = /* @__PURE__ */ new Set(["canceled", "failed", "succeeded"]);
|
|
3903
3947
|
var TERMINAL_EVENT_GRACE_READS = 3;
|
|
3904
3948
|
var CORE_BUILD_JOB_BACKEND = {
|
|
3905
|
-
add: async (options) => await (0,
|
|
3906
|
-
boost: async (jobId) => await (0,
|
|
3907
|
-
cancel: async (jobId) => await (0,
|
|
3908
|
-
get: async (jobId) => await (0,
|
|
3909
|
-
list: async (options) => await (0,
|
|
3910
|
-
pause: async (jobId) => await (0,
|
|
3949
|
+
add: async (options) => await (0, import_wiki_graph_core15.addBuildJob)(options),
|
|
3950
|
+
boost: async (jobId) => await (0, import_wiki_graph_core15.boostBuildJob)(jobId),
|
|
3951
|
+
cancel: async (jobId) => await (0, import_wiki_graph_core15.cancelBuildJob)(jobId),
|
|
3952
|
+
get: async (jobId) => await (0, import_wiki_graph_core15.getBuildJob)(jobId),
|
|
3953
|
+
list: async (options) => await (0, import_wiki_graph_core15.listBuildJobs)(options),
|
|
3954
|
+
pause: async (jobId) => await (0, import_wiki_graph_core15.pauseBuildJob)(jobId),
|
|
3911
3955
|
readEventChunk: async (job, cursor) => await readIncrementalBuildJobEvents(job, cursor),
|
|
3912
|
-
readEvents: async (job) => await (0,
|
|
3913
|
-
resume: async (jobId) => await (0,
|
|
3914
|
-
setTarget: async (jobId, target) => await (0,
|
|
3956
|
+
readEvents: async (job) => await (0, import_wiki_graph_core15.readBuildJobEvents)(job),
|
|
3957
|
+
resume: async (jobId) => await (0, import_wiki_graph_core15.resumeBuildJob)(jobId),
|
|
3958
|
+
setTarget: async (jobId, target) => await (0, import_wiki_graph_core15.updateBuildJobTarget)(jobId, target)
|
|
3915
3959
|
};
|
|
3916
3960
|
async function readIncrementalBuildJobEvents(job, cursor) {
|
|
3917
3961
|
let reader;
|
|
3918
3962
|
try {
|
|
3919
3963
|
reader = await job.events.openReader();
|
|
3920
3964
|
} catch {
|
|
3921
|
-
return { cursor, events: await (0,
|
|
3965
|
+
return { cursor, events: await (0, import_wiki_graph_core15.readBuildJobEvents)(job) };
|
|
3922
3966
|
}
|
|
3923
3967
|
try {
|
|
3924
3968
|
const offset = cursor <= reader.size ? cursor : 0;
|
|
@@ -3942,45 +3986,57 @@ var WikiGraphJobManager = class {
|
|
|
3942
3986
|
this.#backend = backend;
|
|
3943
3987
|
}
|
|
3944
3988
|
async create(options) {
|
|
3945
|
-
const
|
|
3946
|
-
|
|
3947
|
-
|
|
3948
|
-
|
|
3949
|
-
|
|
3950
|
-
|
|
3951
|
-
|
|
3989
|
+
const resolved = await this.#runtime.run(async () => {
|
|
3990
|
+
const location = await resolveWikiGraphArchiveLocation(options.archive);
|
|
3991
|
+
return {
|
|
3992
|
+
job: await this.#backend.add({
|
|
3993
|
+
...options,
|
|
3994
|
+
archive: location.archiveFile
|
|
3995
|
+
}),
|
|
3996
|
+
target: location.target
|
|
3997
|
+
};
|
|
3998
|
+
});
|
|
3999
|
+
return await this.#createHandle(resolved.job, resolved.target);
|
|
3952
4000
|
}
|
|
3953
4001
|
async clean() {
|
|
3954
|
-
return await this.#runtime.run(async () => await (0,
|
|
4002
|
+
return await this.#runtime.run(async () => await (0, import_wiki_graph_core15.cleanBuildJobs)());
|
|
4003
|
+
}
|
|
4004
|
+
async runWorker(options = {}) {
|
|
4005
|
+
await this.#runtime.run(
|
|
4006
|
+
async () => await runWikiGraphQueueWorker(options),
|
|
4007
|
+
options.signal
|
|
4008
|
+
);
|
|
3955
4009
|
}
|
|
3956
4010
|
async get(jobId) {
|
|
3957
|
-
return this.#
|
|
3958
|
-
|
|
4011
|
+
return await this.#runtime.run(
|
|
4012
|
+
async () => await this.#createHandle(await this.#backend.get(jobId))
|
|
3959
4013
|
);
|
|
3960
4014
|
}
|
|
3961
4015
|
async resolveId(reference) {
|
|
3962
4016
|
return await this.#runtime.run(
|
|
3963
|
-
async () => await (0,
|
|
4017
|
+
async () => await (0, import_wiki_graph_core15.resolveBuildJobId)(reference)
|
|
3964
4018
|
);
|
|
3965
4019
|
}
|
|
3966
4020
|
async list(options = {}) {
|
|
3967
|
-
|
|
4021
|
+
return await this.#runtime.run(async () => {
|
|
3968
4022
|
const normalized = {
|
|
3969
4023
|
...options.activeOnly === void 0 ? {} : { activeOnly: options.activeOnly },
|
|
3970
4024
|
...options.all === void 0 ? {} : { all: options.all },
|
|
3971
4025
|
...options.archive === void 0 ? {} : {
|
|
3972
|
-
archive:
|
|
4026
|
+
archive: (await resolveWikiGraphArchiveLocation(options.archive)).archiveFile
|
|
3973
4027
|
}
|
|
3974
4028
|
};
|
|
3975
|
-
|
|
4029
|
+
const jobs = await this.#backend.list(normalized);
|
|
4030
|
+
return await Promise.all(
|
|
4031
|
+
jobs.map(async (job) => await this.#createHandle(job))
|
|
4032
|
+
);
|
|
3976
4033
|
});
|
|
3977
|
-
return jobs.map((job) => this.#createHandle(job));
|
|
3978
4034
|
}
|
|
3979
4035
|
async resolveChapters(jobs) {
|
|
3980
4036
|
return await this.#runtime.run(async () => {
|
|
3981
4037
|
const jobsByArchive = /* @__PURE__ */ new Map();
|
|
3982
4038
|
for (const job of jobs) {
|
|
3983
|
-
const archivePath =
|
|
4039
|
+
const archivePath = getJobArchiveLocator(job);
|
|
3984
4040
|
const grouped = jobsByArchive.get(archivePath) ?? [];
|
|
3985
4041
|
grouped.push(job);
|
|
3986
4042
|
jobsByArchive.set(archivePath, grouped);
|
|
@@ -3988,9 +4044,12 @@ var WikiGraphJobManager = class {
|
|
|
3988
4044
|
const entries = (await Promise.all(
|
|
3989
4045
|
[...jobsByArchive].map(async ([archivePath, archiveJobs]) => {
|
|
3990
4046
|
try {
|
|
3991
|
-
const
|
|
3992
|
-
|
|
3993
|
-
)
|
|
4047
|
+
const location = await resolveWikiGraphArchiveLocation(
|
|
4048
|
+
archiveJobs[0].archive
|
|
4049
|
+
);
|
|
4050
|
+
const chapters = await new import_wiki_graph_core15.WikiGraphArchiveFile(
|
|
4051
|
+
location.archiveFile
|
|
4052
|
+
).readDocument(async (document) => await (0, import_wiki_graph_core15.listChapters)(document));
|
|
3994
4053
|
const chaptersById = new Map(
|
|
3995
4054
|
chapters.map((chapter) => [chapter.chapterId, chapter])
|
|
3996
4055
|
);
|
|
@@ -4000,7 +4059,7 @@ var WikiGraphJobManager = class {
|
|
|
4000
4059
|
[
|
|
4001
4060
|
job.jobId,
|
|
4002
4061
|
{
|
|
4003
|
-
locatedUri: (0,
|
|
4062
|
+
locatedUri: (0, import_wiki_graph_core15.formatLocatedChapterUri)(
|
|
4004
4063
|
archivePath,
|
|
4005
4064
|
chapter.path
|
|
4006
4065
|
),
|
|
@@ -4023,75 +4082,93 @@ var WikiGraphJobManager = class {
|
|
|
4023
4082
|
}
|
|
4024
4083
|
async enqueue(options) {
|
|
4025
4084
|
return await this.#runtime.run(async () => {
|
|
4085
|
+
const llmJSON = resolveWikiGraphLLMJSON(options);
|
|
4026
4086
|
const location = await resolveWikiGraphArchiveLocation(options.archive);
|
|
4027
|
-
|
|
4028
|
-
|
|
4029
|
-
|
|
4030
|
-
|
|
4031
|
-
|
|
4032
|
-
|
|
4033
|
-
|
|
4034
|
-
|
|
4035
|
-
|
|
4036
|
-
|
|
4037
|
-
|
|
4038
|
-
|
|
4039
|
-
|
|
4040
|
-
|
|
4041
|
-
return checked;
|
|
4042
|
-
});
|
|
4043
|
-
const created = [];
|
|
4044
|
-
const skipped = [];
|
|
4045
|
-
for (const candidate of candidates) {
|
|
4046
|
-
if (candidate.reason !== void 0) {
|
|
4047
|
-
if (selectedExplicitly && candidates.length === 1) {
|
|
4048
|
-
throw new Error(
|
|
4049
|
-
formatQueueReadinessError(
|
|
4050
|
-
candidate.chapter,
|
|
4051
|
-
target,
|
|
4052
|
-
candidate.reason
|
|
4053
|
-
)
|
|
4087
|
+
return await (0, import_wiki_graph_core15.withArchiveBuildJobCreationLock)(
|
|
4088
|
+
location.archiveFile,
|
|
4089
|
+
async () => {
|
|
4090
|
+
const target = options.target ?? "reading-summary";
|
|
4091
|
+
await validateQueueTargetConfig(target, llmJSON);
|
|
4092
|
+
const selectedExplicitly = options.chapterId !== void 0 || options.chapterIds !== void 0 || options.chapterPath !== void 0 || options.depth !== void 0;
|
|
4093
|
+
const candidates = await new import_wiki_graph_core15.WikiGraphArchiveFile(
|
|
4094
|
+
location.archiveFile
|
|
4095
|
+
).readDocument(async (document) => {
|
|
4096
|
+
const chapters = await (0, import_wiki_graph_core15.listChapters)(document);
|
|
4097
|
+
const selected = await selectQueueChapters(
|
|
4098
|
+
document,
|
|
4099
|
+
chapters,
|
|
4100
|
+
options
|
|
4054
4101
|
);
|
|
4055
|
-
|
|
4056
|
-
|
|
4057
|
-
|
|
4058
|
-
|
|
4059
|
-
|
|
4060
|
-
|
|
4061
|
-
|
|
4062
|
-
|
|
4063
|
-
|
|
4064
|
-
|
|
4065
|
-
|
|
4066
|
-
archive: location.archiveFile,
|
|
4067
|
-
boost: options.boost ?? false,
|
|
4068
|
-
chapterId: candidate.chapter.chapterId,
|
|
4069
|
-
...options.llmJSON === void 0 ? {} : { llmJSON: options.llmJSON },
|
|
4070
|
-
...options.prompt === void 0 ? {} : { prompt: options.prompt },
|
|
4071
|
-
target
|
|
4072
|
-
})
|
|
4073
|
-
});
|
|
4074
|
-
} catch (error) {
|
|
4075
|
-
if (selectedExplicitly && candidates.length === 1) throw error;
|
|
4076
|
-
skipped.push({
|
|
4077
|
-
chapter: candidate.chapter,
|
|
4078
|
-
reason: error instanceof Error ? error.message : String(error)
|
|
4102
|
+
const checked = await Promise.all(
|
|
4103
|
+
selected.map(async (chapter) => ({
|
|
4104
|
+
chapter,
|
|
4105
|
+
reason: await readQueueReadinessReason(
|
|
4106
|
+
document,
|
|
4107
|
+
chapter,
|
|
4108
|
+
target
|
|
4109
|
+
)
|
|
4110
|
+
}))
|
|
4111
|
+
);
|
|
4112
|
+
return checked;
|
|
4079
4113
|
});
|
|
4114
|
+
const created = [];
|
|
4115
|
+
const skipped = [];
|
|
4116
|
+
for (const candidate of candidates) {
|
|
4117
|
+
if (candidate.reason !== void 0) {
|
|
4118
|
+
if (selectedExplicitly && candidates.length === 1) {
|
|
4119
|
+
throw new Error(
|
|
4120
|
+
formatQueueReadinessError(
|
|
4121
|
+
candidate.chapter,
|
|
4122
|
+
target,
|
|
4123
|
+
candidate.reason
|
|
4124
|
+
)
|
|
4125
|
+
);
|
|
4126
|
+
}
|
|
4127
|
+
skipped.push({
|
|
4128
|
+
chapter: candidate.chapter,
|
|
4129
|
+
reason: candidate.reason
|
|
4130
|
+
});
|
|
4131
|
+
continue;
|
|
4132
|
+
}
|
|
4133
|
+
try {
|
|
4134
|
+
created.push({
|
|
4135
|
+
chapter: candidate.chapter,
|
|
4136
|
+
job: await this.#createHandle(
|
|
4137
|
+
await this.#backend.add({
|
|
4138
|
+
archive: location.archiveFile,
|
|
4139
|
+
boost: options.boost ?? false,
|
|
4140
|
+
chapterId: candidate.chapter.chapterId,
|
|
4141
|
+
...llmJSON === void 0 ? {} : { llmJSON },
|
|
4142
|
+
...options.prompt === void 0 ? {} : { prompt: options.prompt },
|
|
4143
|
+
target
|
|
4144
|
+
}),
|
|
4145
|
+
location.target
|
|
4146
|
+
)
|
|
4147
|
+
});
|
|
4148
|
+
} catch (error) {
|
|
4149
|
+
if (selectedExplicitly && candidates.length === 1) throw error;
|
|
4150
|
+
skipped.push({
|
|
4151
|
+
chapter: candidate.chapter,
|
|
4152
|
+
reason: error instanceof Error ? error.message : String(error)
|
|
4153
|
+
});
|
|
4154
|
+
}
|
|
4155
|
+
}
|
|
4156
|
+
return { created, skipped };
|
|
4080
4157
|
}
|
|
4081
|
-
|
|
4082
|
-
return { created, skipped };
|
|
4158
|
+
);
|
|
4083
4159
|
});
|
|
4084
4160
|
}
|
|
4085
4161
|
async planEnqueue(options) {
|
|
4086
4162
|
return await this.#runtime.run(async () => {
|
|
4163
|
+
const llmJSON = resolveWikiGraphLLMJSON(options);
|
|
4087
4164
|
const location = await resolveWikiGraphArchiveLocation(options.archive);
|
|
4088
4165
|
const target = options.target ?? "reading-summary";
|
|
4089
|
-
await validateQueueTargetConfig(target,
|
|
4166
|
+
await validateQueueTargetConfig(target, llmJSON);
|
|
4090
4167
|
const selectedExplicitly = options.chapterId !== void 0 || options.chapterIds !== void 0 || options.chapterPath !== void 0 || options.depth !== void 0;
|
|
4091
|
-
const candidates = await new
|
|
4168
|
+
const candidates = await new import_wiki_graph_core15.WikiGraphArchiveFile(
|
|
4092
4169
|
location.archiveFile
|
|
4093
4170
|
).readDocument(async (document) => {
|
|
4094
|
-
const chapters = await (0,
|
|
4171
|
+
const chapters = await (0, import_wiki_graph_core15.listChapters)(document);
|
|
4095
4172
|
const selected = await selectQueueChapters(document, chapters, options);
|
|
4096
4173
|
return await Promise.all(
|
|
4097
4174
|
selected.map(async (chapter) => ({
|
|
@@ -4125,34 +4202,39 @@ var WikiGraphJobManager = class {
|
|
|
4125
4202
|
this.#subscriptions.add(controller);
|
|
4126
4203
|
return () => this.#subscriptions.delete(controller);
|
|
4127
4204
|
}
|
|
4128
|
-
#createHandle(snapshot) {
|
|
4129
|
-
|
|
4205
|
+
async #createHandle(snapshot, target) {
|
|
4206
|
+
const legacy = snapshot;
|
|
4207
|
+
const resolvedTarget = target ?? (snapshot.archive === void 0 ? archiveTargetFromLogicalLocator(legacy.archivePath ?? "unknown.wikg") : await resolveWikiGraphArchiveTarget(snapshot.archive));
|
|
4208
|
+
return new WikiGraphJob(
|
|
4209
|
+
this,
|
|
4210
|
+
this.#runtime,
|
|
4211
|
+
this.#backend,
|
|
4212
|
+
snapshot,
|
|
4213
|
+
cloneWikiGraphArchiveTarget(resolvedTarget)
|
|
4214
|
+
);
|
|
4130
4215
|
}
|
|
4131
4216
|
};
|
|
4132
|
-
function
|
|
4133
|
-
|
|
4134
|
-
if (record.archive !== void 0) {
|
|
4135
|
-
return getNodeResourcePath(record.archive);
|
|
4136
|
-
}
|
|
4137
|
-
if (typeof record.archivePath === "string") return record.archivePath;
|
|
4138
|
-
throw new TypeError("Build job is missing archive");
|
|
4217
|
+
function getJobArchiveLocator(job) {
|
|
4218
|
+
return job.archive.kind === "library" ? job.archive.uri : job.archive.path;
|
|
4139
4219
|
}
|
|
4140
4220
|
var WikiGraphJob = class {
|
|
4141
4221
|
#manager;
|
|
4142
4222
|
#runtime;
|
|
4143
4223
|
#backend;
|
|
4224
|
+
#archiveTarget;
|
|
4144
4225
|
#snapshot;
|
|
4145
|
-
constructor(manager, runtime, backend, snapshot) {
|
|
4226
|
+
constructor(manager, runtime, backend, snapshot, archiveTarget) {
|
|
4146
4227
|
this.#manager = manager;
|
|
4147
4228
|
this.#runtime = runtime;
|
|
4148
4229
|
this.#backend = backend;
|
|
4149
4230
|
this.#snapshot = snapshot;
|
|
4231
|
+
this.#archiveTarget = archiveTarget;
|
|
4150
4232
|
}
|
|
4151
4233
|
get id() {
|
|
4152
4234
|
return this.#snapshot.jobId;
|
|
4153
4235
|
}
|
|
4154
4236
|
get snapshot() {
|
|
4155
|
-
return this.#snapshot;
|
|
4237
|
+
return toPublicJobSnapshot(this.#snapshot, this.#archiveTarget);
|
|
4156
4238
|
}
|
|
4157
4239
|
async status() {
|
|
4158
4240
|
return await this.#update(async () => await this.#backend.get(this.id));
|
|
@@ -4179,7 +4261,8 @@ var WikiGraphJob = class {
|
|
|
4179
4261
|
let cursor = 0;
|
|
4180
4262
|
let job = this.#snapshot;
|
|
4181
4263
|
if (options.from === "now") {
|
|
4182
|
-
|
|
4264
|
+
await this.status();
|
|
4265
|
+
job = this.#snapshot;
|
|
4183
4266
|
const chunk = await this.#readEventChunkSafely(job, cursor);
|
|
4184
4267
|
const events = chunk.events;
|
|
4185
4268
|
cursor = chunk.cursor;
|
|
@@ -4199,7 +4282,8 @@ var WikiGraphJob = class {
|
|
|
4199
4282
|
yield event;
|
|
4200
4283
|
}
|
|
4201
4284
|
if (sawTerminalEvent) return;
|
|
4202
|
-
|
|
4285
|
+
await this.status();
|
|
4286
|
+
job = this.#snapshot;
|
|
4203
4287
|
if (isTerminalState(job.state)) {
|
|
4204
4288
|
terminalReadsWithoutEvent += 1;
|
|
4205
4289
|
if (terminalReadsWithoutEvent >= TERMINAL_EVENT_GRACE_READS) return;
|
|
@@ -4236,7 +4320,7 @@ var WikiGraphJob = class {
|
|
|
4236
4320
|
}
|
|
4237
4321
|
async #update(operation) {
|
|
4238
4322
|
this.#snapshot = await this.#runtime.run(operation);
|
|
4239
|
-
return this
|
|
4323
|
+
return this.snapshot;
|
|
4240
4324
|
}
|
|
4241
4325
|
async #readEventChunk(job, cursor) {
|
|
4242
4326
|
return await this.#runtime.run(async () => {
|
|
@@ -4255,6 +4339,54 @@ var WikiGraphJob = class {
|
|
|
4255
4339
|
}
|
|
4256
4340
|
}
|
|
4257
4341
|
};
|
|
4342
|
+
function toPublicJobSnapshot(job, archive) {
|
|
4343
|
+
const legacy = job;
|
|
4344
|
+
return {
|
|
4345
|
+
archive: cloneWikiGraphArchiveTarget(archive),
|
|
4346
|
+
archiveKey: archive.kind === "library" ? archive.uri : job.archiveKey,
|
|
4347
|
+
...getJobResourcePath(job.cache, legacy.cachePath) === void 0 ? {} : { cachePath: getJobResourcePath(job.cache, legacy.cachePath) },
|
|
4348
|
+
chapterId: job.chapterId,
|
|
4349
|
+
createdAt: job.createdAt,
|
|
4350
|
+
...job.currentStep === void 0 ? {} : { currentStep: job.currentStep },
|
|
4351
|
+
...job.errorJSON === void 0 ? {} : { errorJSON: job.errorJSON },
|
|
4352
|
+
...getJobResourcePath(job.events, legacy.eventsPath) === void 0 ? {} : { eventsPath: getJobResourcePath(job.events, legacy.eventsPath) },
|
|
4353
|
+
...job.finishedAt === void 0 ? {} : { finishedAt: job.finishedAt },
|
|
4354
|
+
jobId: job.jobId,
|
|
4355
|
+
...job.inputRevision === void 0 ? {} : { inputRevision: job.inputRevision },
|
|
4356
|
+
...getJobResourcePath(job.log, legacy.logPath) === void 0 ? {} : { logPath: getJobResourcePath(job.log, legacy.logPath) },
|
|
4357
|
+
...job.llmJSON === void 0 ? {} : { llmJSON: job.llmJSON },
|
|
4358
|
+
...job.ownerId === void 0 ? {} : { ownerId: job.ownerId },
|
|
4359
|
+
...job.prompt === void 0 ? {} : { prompt: job.prompt },
|
|
4360
|
+
queueRank: job.queueRank,
|
|
4361
|
+
...job.readingSummaryStartedAt === void 0 ? {} : { readingSummaryStartedAt: job.readingSummaryStartedAt },
|
|
4362
|
+
state: job.state,
|
|
4363
|
+
target: job.target,
|
|
4364
|
+
updatedAt: job.updatedAt,
|
|
4365
|
+
...getJobResourcePath(job.workspace, legacy.workspacePath) === void 0 ? {} : {
|
|
4366
|
+
workspacePath: getJobResourcePath(
|
|
4367
|
+
job.workspace,
|
|
4368
|
+
legacy.workspacePath
|
|
4369
|
+
)
|
|
4370
|
+
}
|
|
4371
|
+
};
|
|
4372
|
+
}
|
|
4373
|
+
function cloneWikiGraphArchiveTarget(target) {
|
|
4374
|
+
return target.kind === "library" ? Object.freeze({ kind: "library", uri: target.uri }) : Object.freeze({
|
|
4375
|
+
kind: "standalone",
|
|
4376
|
+
path: target.path,
|
|
4377
|
+
...target.objectUri === void 0 ? {} : { objectUri: target.objectUri }
|
|
4378
|
+
});
|
|
4379
|
+
}
|
|
4380
|
+
function getJobResourcePath(resource, legacy) {
|
|
4381
|
+
if (resource === void 0) return legacy;
|
|
4382
|
+
try {
|
|
4383
|
+
return getNodeResourcePath(resource);
|
|
4384
|
+
} catch {
|
|
4385
|
+
const identity = resource.identity;
|
|
4386
|
+
if (typeof identity === "string") return identity;
|
|
4387
|
+
throw new TypeError("Expected a Node File or Directory resource");
|
|
4388
|
+
}
|
|
4389
|
+
}
|
|
4258
4390
|
async function selectQueueChapters(document, chapters, options) {
|
|
4259
4391
|
const ids = options.chapterIds ?? (options.chapterId === void 0 ? void 0 : [options.chapterId]);
|
|
4260
4392
|
if (ids !== void 0) {
|
|
@@ -4265,7 +4397,7 @@ async function selectQueueChapters(document, chapters, options) {
|
|
|
4265
4397
|
if (options.chapterPath === void 0) {
|
|
4266
4398
|
return options.depth === void 0 ? chapters : chapters.filter((chapter) => chapter.depth <= options.depth);
|
|
4267
4399
|
}
|
|
4268
|
-
const rootId = await (0,
|
|
4400
|
+
const rootId = await (0, import_wiki_graph_core15.resolveChapterPathReadonly)(
|
|
4269
4401
|
document,
|
|
4270
4402
|
options.chapterPath
|
|
4271
4403
|
);
|
|
@@ -4276,12 +4408,15 @@ async function selectQueueChapters(document, chapters, options) {
|
|
|
4276
4408
|
);
|
|
4277
4409
|
}
|
|
4278
4410
|
async function validateQueueTargetConfig(target, llmJSON) {
|
|
4411
|
+
const providers = getWikiGraphSDKProviders();
|
|
4279
4412
|
const config = target === "knowledge-graph" || target === "reading-graph" || target === "reading-summary" ? await loadRequiredStageConfig({
|
|
4280
4413
|
...llmJSON === void 0 ? {} : { llmJSON }
|
|
4281
4414
|
}) : await loadWikiGraphRuntimeConfig({
|
|
4282
|
-
...llmJSON === void 0 ? {} : { llmJSON }
|
|
4415
|
+
...llmJSON === void 0 ? {} : { llmJSON },
|
|
4416
|
+
...providers.embedding === void 0 ? {} : { skipEmbeddingConfig: true },
|
|
4417
|
+
...llmJSON === void 0 && providers.llm !== void 0 ? { skipLLMConfig: true } : {}
|
|
4283
4418
|
});
|
|
4284
|
-
if ((target === "index-embedding-source" || target === "index-embedding-summary") && config.embedding === void 0) {
|
|
4419
|
+
if ((target === "index-embedding-source" || target === "index-embedding-summary") && config.embedding === void 0 && providers.embedding === void 0) {
|
|
4285
4420
|
throw new Error(
|
|
4286
4421
|
"Missing embeddings configuration. Configure `wikg://local/config/embeddings` before queueing embedding index artifact jobs."
|
|
4287
4422
|
);
|
|
@@ -4330,14 +4465,14 @@ function formatQueueReadinessError(chapter, target, reason) {
|
|
|
4330
4465
|
}
|
|
4331
4466
|
async function wait(milliseconds, signal) {
|
|
4332
4467
|
if (signal?.aborted === true) return;
|
|
4333
|
-
await new Promise((
|
|
4468
|
+
await new Promise((resolve4) => {
|
|
4334
4469
|
let settled = false;
|
|
4335
4470
|
const complete = () => {
|
|
4336
4471
|
if (settled) return;
|
|
4337
4472
|
settled = true;
|
|
4338
4473
|
clearTimeout(timeout);
|
|
4339
4474
|
signal?.removeEventListener("abort", complete);
|
|
4340
|
-
|
|
4475
|
+
resolve4();
|
|
4341
4476
|
};
|
|
4342
4477
|
const timeout = setTimeout(complete, milliseconds);
|
|
4343
4478
|
signal?.addEventListener("abort", complete, { once: true });
|
|
@@ -4359,8 +4494,18 @@ function forwardAbort(source, target) {
|
|
|
4359
4494
|
}
|
|
4360
4495
|
|
|
4361
4496
|
// src/libraries.ts
|
|
4362
|
-
var
|
|
4363
|
-
var
|
|
4497
|
+
var import_wiki_graph_core16 = require("wiki-graph-core");
|
|
4498
|
+
var import_promises5 = require("fs/promises");
|
|
4499
|
+
async function resolveQueryEmbeddingProvider(queryMode) {
|
|
4500
|
+
if (queryMode === "fts") return void 0;
|
|
4501
|
+
const provider = await createConfiguredEmbeddingProvider();
|
|
4502
|
+
if (queryMode === "embedding" && provider === void 0) {
|
|
4503
|
+
throw new Error(
|
|
4504
|
+
"Embedding query mode requires embeddings configuration at `wikg://local/config/embeddings`."
|
|
4505
|
+
);
|
|
4506
|
+
}
|
|
4507
|
+
return provider;
|
|
4508
|
+
}
|
|
4364
4509
|
var WikiGraphLibraryManager = class {
|
|
4365
4510
|
#runtime;
|
|
4366
4511
|
constructor(runtime) {
|
|
@@ -4369,80 +4514,146 @@ var WikiGraphLibraryManager = class {
|
|
|
4369
4514
|
async create(folder) {
|
|
4370
4515
|
const record = await this.#runtime.run(async () => {
|
|
4371
4516
|
const path = resolveWikiGraphRuntimePath(folder);
|
|
4372
|
-
await (0,
|
|
4373
|
-
return await (0,
|
|
4517
|
+
await (0, import_promises5.mkdir)(path);
|
|
4518
|
+
return await (0, import_wiki_graph_core16.createWikiGraphLibrary)({ folder: new NodeDirectory(path) });
|
|
4374
4519
|
});
|
|
4375
4520
|
return new WikiGraphLibrary(this.#runtime, record);
|
|
4376
4521
|
}
|
|
4377
|
-
async get(uri = (0,
|
|
4522
|
+
async get(uri = (0, import_wiki_graph_core16.formatWikiGraphLibraryUri)()) {
|
|
4378
4523
|
const target = requireLibraryTarget(uri);
|
|
4379
4524
|
const record = await this.#runtime.run(
|
|
4380
|
-
async () => await (0,
|
|
4525
|
+
async () => await (0, import_wiki_graph_core16.resolveWikiGraphLibrary)(target)
|
|
4381
4526
|
);
|
|
4382
4527
|
return new WikiGraphLibrary(this.#runtime, record);
|
|
4383
4528
|
}
|
|
4384
4529
|
async addArchive(options) {
|
|
4385
|
-
return
|
|
4386
|
-
|
|
4387
|
-
|
|
4388
|
-
|
|
4389
|
-
|
|
4390
|
-
|
|
4391
|
-
|
|
4392
|
-
|
|
4530
|
+
return toArchiveSnapshot(
|
|
4531
|
+
await this.#runtime.run(
|
|
4532
|
+
async () => await (0, import_wiki_graph_core16.addWikiGraphLibraryArchive)({
|
|
4533
|
+
inputFile: new NodeFile(
|
|
4534
|
+
await assertStandaloneWikiGraphArchivePath(options.inputPath)
|
|
4535
|
+
),
|
|
4536
|
+
target: requireLibraryTarget(options.target),
|
|
4537
|
+
...options.to === void 0 ? {} : { to: options.to }
|
|
4538
|
+
})
|
|
4539
|
+
)
|
|
4393
4540
|
);
|
|
4394
4541
|
}
|
|
4395
4542
|
async assertCurrent(target) {
|
|
4396
4543
|
await this.#runtime.run(
|
|
4397
|
-
async () => await (0,
|
|
4544
|
+
async () => await (0, import_wiki_graph_core16.assertWikiGraphLibrarySchemaCurrent)(requireLibraryTarget(target))
|
|
4398
4545
|
);
|
|
4399
4546
|
}
|
|
4400
4547
|
async rebind(target, folder) {
|
|
4401
|
-
return
|
|
4402
|
-
|
|
4403
|
-
|
|
4404
|
-
|
|
4405
|
-
|
|
4548
|
+
return toScanSnapshot(
|
|
4549
|
+
await this.#runtime.run(
|
|
4550
|
+
async () => await (0, import_wiki_graph_core16.rebindWikiGraphLibrary)({
|
|
4551
|
+
folder: new NodeDirectory(resolveWikiGraphRuntimePath(folder)),
|
|
4552
|
+
target: requireLibraryTarget(target)
|
|
4553
|
+
})
|
|
4554
|
+
)
|
|
4406
4555
|
);
|
|
4407
4556
|
}
|
|
4408
4557
|
async remove(target) {
|
|
4409
|
-
return
|
|
4410
|
-
|
|
4558
|
+
return toLibrarySnapshot(
|
|
4559
|
+
await this.#runtime.run(
|
|
4560
|
+
async () => await (0, import_wiki_graph_core16.removeWikiGraphLibrary)(requireLibraryTarget(target))
|
|
4561
|
+
)
|
|
4411
4562
|
);
|
|
4412
4563
|
}
|
|
4413
4564
|
async scan(target) {
|
|
4414
|
-
return
|
|
4415
|
-
|
|
4565
|
+
return toScanSnapshot(
|
|
4566
|
+
await this.#runtime.run(
|
|
4567
|
+
async () => await (0, import_wiki_graph_core16.scanWikiGraphLibrary)(requireLibraryTarget(target))
|
|
4568
|
+
)
|
|
4416
4569
|
);
|
|
4417
4570
|
}
|
|
4418
4571
|
async getArchive(target) {
|
|
4419
|
-
return
|
|
4420
|
-
|
|
4572
|
+
return toArchiveSnapshot(
|
|
4573
|
+
await this.#runtime.run(
|
|
4574
|
+
async () => await (0, import_wiki_graph_core16.getWikiGraphLibraryArchive)(requireLibraryTarget(target))
|
|
4575
|
+
)
|
|
4421
4576
|
);
|
|
4422
4577
|
}
|
|
4578
|
+
async readArchive(target, consume, options = {}) {
|
|
4579
|
+
return await this.#runtime.run(async () => {
|
|
4580
|
+
const parsedTarget = requireLibraryArchiveTarget(target);
|
|
4581
|
+
const library = await (0, import_wiki_graph_core16.resolveWikiGraphLibrary)(parsedTarget);
|
|
4582
|
+
return await (0, import_wiki_graph_core16.withWikiGraphLibraryLock)(
|
|
4583
|
+
library.id,
|
|
4584
|
+
"read",
|
|
4585
|
+
async () => {
|
|
4586
|
+
throwIfAborted(options.signal);
|
|
4587
|
+
const archive = await (0, import_wiki_graph_core16.getWikiGraphLibraryArchive)(parsedTarget);
|
|
4588
|
+
const file = requireReadableLibraryArchiveFile(archive);
|
|
4589
|
+
const reader = await file.openReader();
|
|
4590
|
+
let active = true;
|
|
4591
|
+
try {
|
|
4592
|
+
const content = {
|
|
4593
|
+
mediaType: "application/vnd.wiki-graph.archive",
|
|
4594
|
+
size: reader.size,
|
|
4595
|
+
stream: createCallbackScopedArchiveStream(
|
|
4596
|
+
reader,
|
|
4597
|
+
() => active,
|
|
4598
|
+
options.signal
|
|
4599
|
+
),
|
|
4600
|
+
uri: archive.uri
|
|
4601
|
+
};
|
|
4602
|
+
return await runAbortableCallback(
|
|
4603
|
+
async () => await consume(content),
|
|
4604
|
+
options.signal
|
|
4605
|
+
);
|
|
4606
|
+
} finally {
|
|
4607
|
+
active = false;
|
|
4608
|
+
await reader.close();
|
|
4609
|
+
}
|
|
4610
|
+
},
|
|
4611
|
+
options.signal === void 0 ? {} : { signal: options.signal }
|
|
4612
|
+
);
|
|
4613
|
+
}, options.signal);
|
|
4614
|
+
}
|
|
4423
4615
|
async moveArchive(options) {
|
|
4424
|
-
return
|
|
4425
|
-
|
|
4426
|
-
|
|
4427
|
-
|
|
4428
|
-
|
|
4616
|
+
return toArchiveSnapshot(
|
|
4617
|
+
await this.#runtime.run(
|
|
4618
|
+
async () => await (0, import_wiki_graph_core16.moveWikiGraphLibraryArchive)({
|
|
4619
|
+
target: requireLibraryTarget(options.target),
|
|
4620
|
+
to: options.to
|
|
4621
|
+
})
|
|
4622
|
+
)
|
|
4429
4623
|
);
|
|
4430
4624
|
}
|
|
4431
4625
|
async removeArchive(target) {
|
|
4432
|
-
return
|
|
4433
|
-
|
|
4434
|
-
|
|
4626
|
+
return toArchiveSnapshot(
|
|
4627
|
+
await this.#runtime.run(
|
|
4628
|
+
async () => await (0, import_wiki_graph_core16.removeWikiGraphLibraryArchive)({
|
|
4629
|
+
target: requireLibraryTarget(target)
|
|
4630
|
+
})
|
|
4631
|
+
)
|
|
4632
|
+
);
|
|
4633
|
+
}
|
|
4634
|
+
async replaceArchive(options) {
|
|
4635
|
+
return toArchiveSnapshot(
|
|
4636
|
+
await this.#runtime.run(async () => {
|
|
4637
|
+
const target = requireLibraryTarget(options.target);
|
|
4638
|
+
const current = await (0, import_wiki_graph_core16.getWikiGraphLibraryArchive)(target);
|
|
4639
|
+
return await (0, import_wiki_graph_core16.replaceWikiGraphLibraryArchive)({
|
|
4640
|
+
additionalDerivedStateKeys: current.file === void 0 ? [] : [getNodeResourcePath(current.file)],
|
|
4641
|
+
inputFile: new NodeFile(
|
|
4642
|
+
await assertStandaloneWikiGraphArchivePath(options.inputPath)
|
|
4643
|
+
),
|
|
4644
|
+
target
|
|
4645
|
+
});
|
|
4435
4646
|
})
|
|
4436
4647
|
);
|
|
4437
4648
|
}
|
|
4438
4649
|
async indexState(target) {
|
|
4439
4650
|
return await this.#runtime.run(
|
|
4440
|
-
async () => await (0,
|
|
4651
|
+
async () => await (0, import_wiki_graph_core16.readWikiGraphLibraryIndexState)(requireLibraryTarget(target))
|
|
4441
4652
|
);
|
|
4442
4653
|
}
|
|
4443
4654
|
async rebuildIndex(target, onProgress) {
|
|
4444
4655
|
return await this.#runtime.run(
|
|
4445
|
-
async () => await (0,
|
|
4656
|
+
async () => await (0, import_wiki_graph_core16.rebuildWikiGraphLibraryIndex)(
|
|
4446
4657
|
requireLibraryTarget(target),
|
|
4447
4658
|
onProgress
|
|
4448
4659
|
)
|
|
@@ -4450,17 +4661,17 @@ var WikiGraphLibraryManager = class {
|
|
|
4450
4661
|
}
|
|
4451
4662
|
async cleanIndex(target) {
|
|
4452
4663
|
return await this.#runtime.run(
|
|
4453
|
-
async () => await (0,
|
|
4664
|
+
async () => await (0, import_wiki_graph_core16.cleanWikiGraphLibraryIndex)(requireLibraryTarget(target))
|
|
4454
4665
|
);
|
|
4455
4666
|
}
|
|
4456
4667
|
async getMetadata(target) {
|
|
4457
4668
|
return await this.#runtime.run(
|
|
4458
|
-
async () => await (0,
|
|
4669
|
+
async () => await (0, import_wiki_graph_core16.getWikiGraphLibraryMetadata)(requireLibraryTarget(target))
|
|
4459
4670
|
);
|
|
4460
4671
|
}
|
|
4461
4672
|
async replaceMetadata(target, value) {
|
|
4462
4673
|
return await this.#runtime.run(
|
|
4463
|
-
async () => await (0,
|
|
4674
|
+
async () => await (0, import_wiki_graph_core16.replaceWikiGraphLibraryMetadata)(
|
|
4464
4675
|
requireLibraryTarget(target),
|
|
4465
4676
|
value
|
|
4466
4677
|
)
|
|
@@ -4468,7 +4679,7 @@ var WikiGraphLibraryManager = class {
|
|
|
4468
4679
|
}
|
|
4469
4680
|
async putMetadata(target, key, value) {
|
|
4470
4681
|
return await this.#runtime.run(
|
|
4471
|
-
async () => await (0,
|
|
4682
|
+
async () => await (0, import_wiki_graph_core16.putWikiGraphLibraryMetadata)(
|
|
4472
4683
|
requireLibraryTarget(target),
|
|
4473
4684
|
key,
|
|
4474
4685
|
value
|
|
@@ -4477,7 +4688,7 @@ var WikiGraphLibraryManager = class {
|
|
|
4477
4688
|
}
|
|
4478
4689
|
async deleteMetadata(target, key) {
|
|
4479
4690
|
return await this.#runtime.run(
|
|
4480
|
-
async () => await (0,
|
|
4691
|
+
async () => await (0, import_wiki_graph_core16.deleteWikiGraphLibraryMetadataKey)(
|
|
4481
4692
|
requireLibraryTarget(target),
|
|
4482
4693
|
key
|
|
4483
4694
|
)
|
|
@@ -4485,13 +4696,15 @@ var WikiGraphLibraryManager = class {
|
|
|
4485
4696
|
}
|
|
4486
4697
|
async clearMetadata(target) {
|
|
4487
4698
|
return await this.#runtime.run(
|
|
4488
|
-
async () => await (0,
|
|
4699
|
+
async () => await (0, import_wiki_graph_core16.clearWikiGraphLibraryMetadata)(requireLibraryTarget(target))
|
|
4489
4700
|
);
|
|
4490
4701
|
}
|
|
4491
4702
|
async search(target, query, options = {}) {
|
|
4492
4703
|
return await this.#runtime.run(async () => {
|
|
4493
|
-
const embeddingProvider = await
|
|
4494
|
-
|
|
4704
|
+
const embeddingProvider = await resolveQueryEmbeddingProvider(
|
|
4705
|
+
options.queryMode
|
|
4706
|
+
);
|
|
4707
|
+
return await (0, import_wiki_graph_core16.findWikiGraphLibraryObjects)(
|
|
4495
4708
|
requireLibraryTarget(target),
|
|
4496
4709
|
query,
|
|
4497
4710
|
{
|
|
@@ -4503,8 +4716,10 @@ var WikiGraphLibraryManager = class {
|
|
|
4503
4716
|
}
|
|
4504
4717
|
async searchArchiveMembers(target, query, options = {}) {
|
|
4505
4718
|
return await this.#runtime.run(async () => {
|
|
4506
|
-
const embeddingProvider = await
|
|
4507
|
-
|
|
4719
|
+
const embeddingProvider = await resolveQueryEmbeddingProvider(
|
|
4720
|
+
options.queryMode
|
|
4721
|
+
);
|
|
4722
|
+
return await (0, import_wiki_graph_core16.findWikiGraphLibraryArchiveMembers)(
|
|
4508
4723
|
requireLibraryTarget(target),
|
|
4509
4724
|
query,
|
|
4510
4725
|
{
|
|
@@ -4516,7 +4731,7 @@ var WikiGraphLibraryManager = class {
|
|
|
4516
4731
|
}
|
|
4517
4732
|
async objects(target, options = {}) {
|
|
4518
4733
|
return await this.#runtime.run(
|
|
4519
|
-
async () => await (0,
|
|
4734
|
+
async () => await (0, import_wiki_graph_core16.listWikiGraphLibraryObjects)(
|
|
4520
4735
|
requireLibraryTarget(target),
|
|
4521
4736
|
options
|
|
4522
4737
|
)
|
|
@@ -4524,7 +4739,7 @@ var WikiGraphLibraryManager = class {
|
|
|
4524
4739
|
}
|
|
4525
4740
|
async archiveMembers(target, options = {}) {
|
|
4526
4741
|
return await this.#runtime.run(
|
|
4527
|
-
async () => await (0,
|
|
4742
|
+
async () => await (0, import_wiki_graph_core16.listWikiGraphLibraryArchiveMembers)(
|
|
4528
4743
|
requireLibraryTarget(target),
|
|
4529
4744
|
options
|
|
4530
4745
|
)
|
|
@@ -4534,35 +4749,50 @@ var WikiGraphLibraryManager = class {
|
|
|
4534
4749
|
return await this.#runtime.run(
|
|
4535
4750
|
async () => await withConfiguredWikimediaResolver(
|
|
4536
4751
|
objectUri,
|
|
4537
|
-
async (wikimediaOptions) => await (0,
|
|
4752
|
+
async (wikimediaOptions) => await (0, import_wiki_graph_core16.readWikiGraphLibraryPage)(
|
|
4538
4753
|
requireLibraryTarget(target),
|
|
4539
4754
|
objectUri,
|
|
4540
4755
|
{ ...options, ...wikimediaOptions }
|
|
4541
4756
|
)
|
|
4542
|
-
)
|
|
4757
|
+
),
|
|
4758
|
+
options.signal
|
|
4543
4759
|
);
|
|
4544
4760
|
}
|
|
4545
4761
|
async related(target, objectUri, options = {}) {
|
|
4546
|
-
return await this.#runtime.run(
|
|
4547
|
-
|
|
4762
|
+
return await this.#runtime.run(async () => {
|
|
4763
|
+
if (options.query === void 0 && options.queryMode !== void 0) {
|
|
4764
|
+
throw new Error("`queryMode` requires `query`.");
|
|
4765
|
+
}
|
|
4766
|
+
const embeddingProvider = options.query === void 0 ? void 0 : await resolveQueryEmbeddingProvider(options.queryMode);
|
|
4767
|
+
return await (0, import_wiki_graph_core16.listRelatedWikiGraphLibraryObjects)(
|
|
4548
4768
|
requireLibraryTarget(target),
|
|
4549
4769
|
objectUri,
|
|
4550
|
-
|
|
4551
|
-
|
|
4552
|
-
|
|
4770
|
+
{
|
|
4771
|
+
...options,
|
|
4772
|
+
...embeddingProvider === void 0 ? {} : { embeddingProvider }
|
|
4773
|
+
}
|
|
4774
|
+
);
|
|
4775
|
+
});
|
|
4553
4776
|
}
|
|
4554
4777
|
async evidence(target, objectUri, options = {}) {
|
|
4555
|
-
return await this.#runtime.run(
|
|
4556
|
-
|
|
4778
|
+
return await this.#runtime.run(async () => {
|
|
4779
|
+
if (options.query === void 0 && options.queryMode !== void 0) {
|
|
4780
|
+
throw new Error("`queryMode` requires `query`.");
|
|
4781
|
+
}
|
|
4782
|
+
const embeddingProvider = options.query === void 0 ? void 0 : await resolveQueryEmbeddingProvider(options.queryMode);
|
|
4783
|
+
return await (0, import_wiki_graph_core16.listWikiGraphLibraryEvidence)(
|
|
4557
4784
|
requireLibraryTarget(target),
|
|
4558
4785
|
objectUri,
|
|
4559
|
-
|
|
4560
|
-
|
|
4561
|
-
|
|
4786
|
+
{
|
|
4787
|
+
...options,
|
|
4788
|
+
...embeddingProvider === void 0 ? {} : { embeddingProvider }
|
|
4789
|
+
}
|
|
4790
|
+
);
|
|
4791
|
+
});
|
|
4562
4792
|
}
|
|
4563
4793
|
async pack(target, objectUri, budget = 5e3) {
|
|
4564
4794
|
return await this.#runtime.run(
|
|
4565
|
-
async () => await (0,
|
|
4795
|
+
async () => await (0, import_wiki_graph_core16.packWikiGraphLibraryContext)(
|
|
4566
4796
|
requireLibraryTarget(target),
|
|
4567
4797
|
objectUri,
|
|
4568
4798
|
budget
|
|
@@ -4571,7 +4801,7 @@ var WikiGraphLibraryManager = class {
|
|
|
4571
4801
|
}
|
|
4572
4802
|
async list() {
|
|
4573
4803
|
const records = await this.#runtime.run(
|
|
4574
|
-
async () => await (0,
|
|
4804
|
+
async () => await (0, import_wiki_graph_core16.listWikiGraphLibraries)()
|
|
4575
4805
|
);
|
|
4576
4806
|
return records.map((record) => new WikiGraphLibrary(this.#runtime, record));
|
|
4577
4807
|
}
|
|
@@ -4584,44 +4814,157 @@ var WikiGraphLibrary = class {
|
|
|
4584
4814
|
this.#record = record;
|
|
4585
4815
|
}
|
|
4586
4816
|
get snapshot() {
|
|
4587
|
-
return this.#record;
|
|
4817
|
+
return toLibrarySnapshot(this.#record);
|
|
4588
4818
|
}
|
|
4589
4819
|
get uri() {
|
|
4590
|
-
return (0,
|
|
4820
|
+
return (0, import_wiki_graph_core16.formatWikiGraphLibraryUri)(
|
|
4591
4821
|
this.#record.isDefault ? void 0 : this.#record.publicId
|
|
4592
4822
|
);
|
|
4593
4823
|
}
|
|
4594
4824
|
async archives() {
|
|
4595
4825
|
const target = requireLibraryTarget(this.uri);
|
|
4596
|
-
return await this.#runtime.run(
|
|
4597
|
-
async () => await (0,
|
|
4598
|
-
);
|
|
4826
|
+
return (await this.#runtime.run(
|
|
4827
|
+
async () => await (0, import_wiki_graph_core16.listWikiGraphLibraryArchives)(target)
|
|
4828
|
+
)).map(toArchiveSnapshot);
|
|
4599
4829
|
}
|
|
4600
4830
|
async scan() {
|
|
4601
4831
|
const target = requireLibraryTarget(this.uri);
|
|
4602
|
-
return
|
|
4603
|
-
async () => await (0,
|
|
4832
|
+
return toScanSnapshot(
|
|
4833
|
+
await this.#runtime.run(async () => await (0, import_wiki_graph_core16.scanWikiGraphLibrary)(target))
|
|
4604
4834
|
);
|
|
4605
4835
|
}
|
|
4606
4836
|
async remove() {
|
|
4607
4837
|
const target = requireLibraryTarget(this.uri);
|
|
4608
|
-
return
|
|
4609
|
-
async () => await (0,
|
|
4838
|
+
return toLibrarySnapshot(
|
|
4839
|
+
await this.#runtime.run(async () => await (0, import_wiki_graph_core16.removeWikiGraphLibrary)(target))
|
|
4610
4840
|
);
|
|
4611
4841
|
}
|
|
4612
4842
|
};
|
|
4843
|
+
function toLibrarySnapshot(record) {
|
|
4844
|
+
const compatible = record;
|
|
4845
|
+
return {
|
|
4846
|
+
id: record.id,
|
|
4847
|
+
publicId: record.publicId,
|
|
4848
|
+
uri: record.uri,
|
|
4849
|
+
folderPath: compatible.folderPath ?? (record.folder === void 0 ? "" : getNodeResourcePath(record.folder)),
|
|
4850
|
+
isDefault: record.isDefault,
|
|
4851
|
+
createdAt: record.createdAt,
|
|
4852
|
+
updatedAt: record.updatedAt
|
|
4853
|
+
};
|
|
4854
|
+
}
|
|
4855
|
+
function toArchiveSnapshot(record) {
|
|
4856
|
+
const { file: _file, ...snapshot } = record;
|
|
4857
|
+
return snapshot;
|
|
4858
|
+
}
|
|
4859
|
+
function toScanSnapshot(result) {
|
|
4860
|
+
return {
|
|
4861
|
+
...result.library === void 0 ? {} : { library: toLibrarySnapshot(result.library) },
|
|
4862
|
+
archives: result.archives.map(toArchiveSnapshot)
|
|
4863
|
+
};
|
|
4864
|
+
}
|
|
4613
4865
|
function requireLibraryTarget(value) {
|
|
4614
4866
|
if (typeof value !== "string") return value;
|
|
4615
|
-
const target = (0,
|
|
4867
|
+
const target = (0, import_wiki_graph_core16.parseWikiGraphLibraryUri)(value);
|
|
4616
4868
|
if (target === void 0) {
|
|
4617
4869
|
throw new TypeError(`Invalid Wiki Graph library URI: ${value}`);
|
|
4618
4870
|
}
|
|
4619
4871
|
return target;
|
|
4620
4872
|
}
|
|
4873
|
+
function requireLibraryArchiveTarget(value) {
|
|
4874
|
+
const target = requireLibraryTarget(value);
|
|
4875
|
+
if (target.kind !== "archive" || target.archivePublicId === void 0 || target.objectUri !== void 0) {
|
|
4876
|
+
throw new TypeError("Expected a Wiki Graph library archive URI.");
|
|
4877
|
+
}
|
|
4878
|
+
return target;
|
|
4879
|
+
}
|
|
4880
|
+
function requireReadableLibraryArchiveFile(archive) {
|
|
4881
|
+
if (!archive.exists || archive.status === "missing") {
|
|
4882
|
+
throw new Error(`Wiki Graph library archive is missing: ${archive.uri}`);
|
|
4883
|
+
}
|
|
4884
|
+
if (archive.status === "conflict") {
|
|
4885
|
+
throw new Error(
|
|
4886
|
+
`Wiki Graph library archive has a conflict and cannot be read: ${archive.uri}`
|
|
4887
|
+
);
|
|
4888
|
+
}
|
|
4889
|
+
if (archive.file === void 0) {
|
|
4890
|
+
throw new Error(
|
|
4891
|
+
`Wiki Graph library archive is unavailable: ${archive.uri}`
|
|
4892
|
+
);
|
|
4893
|
+
}
|
|
4894
|
+
return archive.file;
|
|
4895
|
+
}
|
|
4896
|
+
var ARCHIVE_STREAM_CHUNK_SIZE = 64 * 1024;
|
|
4897
|
+
function createCallbackScopedArchiveStream(reader, isActive, signal) {
|
|
4898
|
+
let consumed = false;
|
|
4899
|
+
return {
|
|
4900
|
+
[Symbol.asyncIterator]() {
|
|
4901
|
+
assertArchiveReadSessionActive(isActive, signal);
|
|
4902
|
+
if (consumed) {
|
|
4903
|
+
throw new Error(
|
|
4904
|
+
"The library archive stream has already been consumed."
|
|
4905
|
+
);
|
|
4906
|
+
}
|
|
4907
|
+
consumed = true;
|
|
4908
|
+
let offset = 0;
|
|
4909
|
+
let finished = false;
|
|
4910
|
+
return {
|
|
4911
|
+
async next() {
|
|
4912
|
+
if (finished) return { done: true, value: void 0 };
|
|
4913
|
+
assertArchiveReadSessionActive(isActive, signal);
|
|
4914
|
+
if (offset >= reader.size) {
|
|
4915
|
+
finished = true;
|
|
4916
|
+
return { done: true, value: void 0 };
|
|
4917
|
+
}
|
|
4918
|
+
const length = Math.min(
|
|
4919
|
+
ARCHIVE_STREAM_CHUNK_SIZE,
|
|
4920
|
+
reader.size - offset
|
|
4921
|
+
);
|
|
4922
|
+
const chunk = await reader.read(offset, length);
|
|
4923
|
+
assertArchiveReadSessionActive(isActive, signal);
|
|
4924
|
+
offset += chunk.byteLength;
|
|
4925
|
+
return { done: false, value: chunk };
|
|
4926
|
+
},
|
|
4927
|
+
return() {
|
|
4928
|
+
finished = true;
|
|
4929
|
+
return Promise.resolve({ done: true, value: void 0 });
|
|
4930
|
+
}
|
|
4931
|
+
};
|
|
4932
|
+
}
|
|
4933
|
+
};
|
|
4934
|
+
}
|
|
4935
|
+
function assertArchiveReadSessionActive(isActive, signal) {
|
|
4936
|
+
if (!isActive()) {
|
|
4937
|
+
throw new Error(
|
|
4938
|
+
"The library archive stream cannot be read after its callback has finished."
|
|
4939
|
+
);
|
|
4940
|
+
}
|
|
4941
|
+
throwIfAborted(signal);
|
|
4942
|
+
}
|
|
4943
|
+
async function runAbortableCallback(operation, signal) {
|
|
4944
|
+
if (signal === void 0) return await operation();
|
|
4945
|
+
throwIfAborted(signal);
|
|
4946
|
+
let rejectAbort;
|
|
4947
|
+
const aborted = new Promise((_resolve, reject) => {
|
|
4948
|
+
rejectAbort = reject;
|
|
4949
|
+
});
|
|
4950
|
+
const onAbort = () => rejectAbort(abortReason(signal));
|
|
4951
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
4952
|
+
try {
|
|
4953
|
+
return await Promise.race([operation(), aborted]);
|
|
4954
|
+
} finally {
|
|
4955
|
+
signal.removeEventListener("abort", onAbort);
|
|
4956
|
+
}
|
|
4957
|
+
}
|
|
4958
|
+
function throwIfAborted(signal) {
|
|
4959
|
+
if (signal?.aborted === true) throw abortReason(signal);
|
|
4960
|
+
}
|
|
4961
|
+
function abortReason(signal) {
|
|
4962
|
+
return signal.reason ?? new DOMException("The operation was aborted.", "AbortError");
|
|
4963
|
+
}
|
|
4621
4964
|
|
|
4622
4965
|
// src/maintenance.ts
|
|
4623
|
-
var
|
|
4624
|
-
var
|
|
4966
|
+
var import_wiki_graph_core17 = require("wiki-graph-core");
|
|
4967
|
+
var import_path6 = require("path");
|
|
4625
4968
|
var WikiGraphMaintenanceManager = class {
|
|
4626
4969
|
#runtime;
|
|
4627
4970
|
constructor(runtime) {
|
|
@@ -4631,22 +4974,22 @@ var WikiGraphMaintenanceManager = class {
|
|
|
4631
4974
|
return await this.#runtime.run(
|
|
4632
4975
|
async () => {
|
|
4633
4976
|
if (target.kind === "home") {
|
|
4634
|
-
return await (0,
|
|
4977
|
+
return await (0, import_wiki_graph_core17.upgradeWikiGraphMaintenanceTarget)({ kind: "home" });
|
|
4635
4978
|
}
|
|
4636
4979
|
if (target.kind === "library") {
|
|
4637
|
-
const parsed = (0,
|
|
4980
|
+
const parsed = (0, import_wiki_graph_core17.parseWikiGraphLibraryUri)(target.uri);
|
|
4638
4981
|
if (parsed === void 0 || parsed.kind === "archive") {
|
|
4639
4982
|
throw new Error(
|
|
4640
4983
|
`Invalid Wiki Graph library upgrade target: ${target.uri}`
|
|
4641
4984
|
);
|
|
4642
4985
|
}
|
|
4643
|
-
return await (0,
|
|
4986
|
+
return await (0, import_wiki_graph_core17.upgradeWikiGraphMaintenanceTarget)({
|
|
4644
4987
|
kind: "library",
|
|
4645
4988
|
target: parsed
|
|
4646
4989
|
});
|
|
4647
4990
|
}
|
|
4648
|
-
const path =
|
|
4649
|
-
return await (0,
|
|
4991
|
+
const path = await assertStandaloneWikiGraphArchivePath(target.path);
|
|
4992
|
+
return await (0, import_wiki_graph_core17.upgradeWikiGraphMaintenanceTarget)({
|
|
4650
4993
|
file: new NodeFile(path),
|
|
4651
4994
|
kind: "archive"
|
|
4652
4995
|
});
|
|
@@ -4659,9 +5002,9 @@ var WikiGraphMaintenanceManager = class {
|
|
|
4659
5002
|
return await this.#runtime.run(async () => {
|
|
4660
5003
|
const resolvedInputPath = resolveWikiGraphRuntimePath(inputPath);
|
|
4661
5004
|
const resolvedOutputPath = resolveWikiGraphRuntimePath(outputPath);
|
|
4662
|
-
await (0,
|
|
5005
|
+
await (0, import_wiki_graph_core17.migrateLegacySdpubToWikg)(
|
|
4663
5006
|
new NodeFile(resolvedInputPath),
|
|
4664
|
-
new NodeFile(resolvedOutputPath, (0,
|
|
5007
|
+
new NodeFile(resolvedOutputPath, (0, import_path6.basename)(resolvedOutputPath))
|
|
4665
5008
|
);
|
|
4666
5009
|
return {
|
|
4667
5010
|
inputPath: resolvedInputPath,
|
|
@@ -4675,7 +5018,7 @@ function defaultWikgOutputPath(inputPath) {
|
|
|
4675
5018
|
}
|
|
4676
5019
|
|
|
4677
5020
|
// src/sdk.ts
|
|
4678
|
-
var
|
|
5021
|
+
var import_wiki_graph_core18 = require("wiki-graph-core");
|
|
4679
5022
|
var WikiGraphSDK = class {
|
|
4680
5023
|
#context;
|
|
4681
5024
|
#homeReady;
|
|
@@ -4692,6 +5035,7 @@ var WikiGraphSDK = class {
|
|
|
4692
5035
|
cwd: options.cwd ?? process.cwd(),
|
|
4693
5036
|
env: { ...process.env, ...options.env },
|
|
4694
5037
|
envPolicy: options.envPolicy ?? "production",
|
|
5038
|
+
providers: { ...options.providers },
|
|
4695
5039
|
...options.stateDir === void 0 ? {} : { stateDir: options.stateDir }
|
|
4696
5040
|
};
|
|
4697
5041
|
this.archives = new WikiGraphArchiveManager(this);
|
|
@@ -4703,10 +5047,10 @@ var WikiGraphSDK = class {
|
|
|
4703
5047
|
this.maintenance = new WikiGraphMaintenanceManager(this);
|
|
4704
5048
|
}
|
|
4705
5049
|
async run(operation, signal, options = {}) {
|
|
4706
|
-
|
|
5050
|
+
throwIfAborted2(signal);
|
|
4707
5051
|
const runWithContext = async () => await withWikiGraphSDKRuntimeContext(this.#context, async () => {
|
|
4708
5052
|
if (options.skipHomeBootstrap !== true) {
|
|
4709
|
-
this.#homeReady ??= (0,
|
|
5053
|
+
this.#homeReady ??= (0, import_wiki_graph_core18.ensureWikiGraphHomeSchemaCurrent)().catch(
|
|
4710
5054
|
(error) => {
|
|
4711
5055
|
this.#homeReady = void 0;
|
|
4712
5056
|
throw error;
|
|
@@ -4720,14 +5064,14 @@ var WikiGraphSDK = class {
|
|
|
4720
5064
|
this.#context.stateDir,
|
|
4721
5065
|
runWithContext
|
|
4722
5066
|
);
|
|
4723
|
-
|
|
5067
|
+
throwIfAborted2(signal);
|
|
4724
5068
|
return result;
|
|
4725
5069
|
}
|
|
4726
5070
|
close() {
|
|
4727
5071
|
this.jobs.close();
|
|
4728
5072
|
}
|
|
4729
5073
|
};
|
|
4730
|
-
function
|
|
5074
|
+
function throwIfAborted2(signal) {
|
|
4731
5075
|
if (signal?.aborted !== true) return;
|
|
4732
5076
|
throw signal.reason instanceof Error ? signal.reason : new Error("The Wiki Graph SDK operation was aborted.");
|
|
4733
5077
|
}
|
|
@@ -4736,7 +5080,7 @@ function createWikiGraphSDK(options = {}) {
|
|
|
4736
5080
|
}
|
|
4737
5081
|
|
|
4738
5082
|
// src/index.ts
|
|
4739
|
-
var
|
|
5083
|
+
var import_wiki_graph_core19 = require("wiki-graph-core");
|
|
4740
5084
|
// Annotate the CommonJS export names for ESM import in node:
|
|
4741
5085
|
0 && (module.exports = {
|
|
4742
5086
|
DANGEROUS_RUNTIME_ENV_NAMES,
|
|
@@ -4752,6 +5096,7 @@ var import_wiki_graph_core17 = require("wiki-graph-core");
|
|
|
4752
5096
|
WikiGraphArchiveExistsError,
|
|
4753
5097
|
WikiGraphArchiveHandle,
|
|
4754
5098
|
WikiGraphArchiveManager,
|
|
5099
|
+
WikiGraphArchiveOwnershipError,
|
|
4755
5100
|
WikiGraphConfigManager,
|
|
4756
5101
|
WikiGraphContinuationManager,
|
|
4757
5102
|
WikiGraphConversionManager,
|
|
@@ -4770,7 +5115,6 @@ var import_wiki_graph_core17 = require("wiki-graph-core");
|
|
|
4770
5115
|
createNodeTemplateEnvironment,
|
|
4771
5116
|
createNodeWikiGraphStorage,
|
|
4772
5117
|
createStageLLM,
|
|
4773
|
-
createWikiGraphArchiveInspectReport,
|
|
4774
5118
|
createWikiGraphSDK,
|
|
4775
5119
|
deleteLocalConfigValue,
|
|
4776
5120
|
embedQueryText,
|
|
@@ -4786,8 +5130,10 @@ var import_wiki_graph_core17 = require("wiki-graph-core");
|
|
|
4786
5130
|
formatWikiGraphCommandUri,
|
|
4787
5131
|
formatWikiGraphLibraryUri,
|
|
4788
5132
|
getNodeResourcePath,
|
|
5133
|
+
getWikiGraphSDKProviders,
|
|
4789
5134
|
getWikiGraphSDKRuntimeContext,
|
|
4790
5135
|
getWikiGraphSDKStateDir,
|
|
5136
|
+
inspectWikiGraphArchive,
|
|
4791
5137
|
installNodeWikiGraphPlatform,
|
|
4792
5138
|
isSourceLocatorScopeUri,
|
|
4793
5139
|
isWikiGraphLibraryUri,
|
|
@@ -4814,7 +5160,7 @@ var import_wiki_graph_core17 = require("wiki-graph-core");
|
|
|
4814
5160
|
resolveExtractionPrompt,
|
|
4815
5161
|
resolveHostedProviderEndpoint,
|
|
4816
5162
|
resolveKnowledgeGraphRecallPrompt,
|
|
4817
|
-
|
|
5163
|
+
resolveWikiGraphLLMJSON,
|
|
4818
5164
|
resolveWikispineConfig,
|
|
4819
5165
|
runWikiGraphQueueWorker,
|
|
4820
5166
|
validateLocalConfigSection,
|