wiki-graph-sdk 0.8.0 → 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 +21 -0
- package/dist/archives.cjs +91 -17
- package/dist/archives.cjs.map +1 -1
- package/dist/archives.d.ts +8 -2
- package/dist/archives.js +92 -17
- package/dist/archives.js.map +1 -1
- package/dist/conversions.cjs +23 -5
- package/dist/conversions.cjs.map +1 -1
- package/dist/conversions.d.ts +6 -1
- package/dist/conversions.js +23 -5
- package/dist/conversions.js.map +1 -1
- package/dist/default-worker.cjs +34 -11
- package/dist/default-worker.cjs.map +1 -1
- package/dist/default-worker.d.ts +1 -0
- package/dist/default-worker.js +34 -11
- 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 +336 -46
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +26 -9
- package/dist/index.js +337 -47
- package/dist/index.js.map +1 -1
- package/dist/{jobs-xIm_kshM.d.ts → jobs-CRK-DZ40.d.ts} +5 -0
- 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 +2 -1
- package/dist/maintenance.cjs.map +1 -1
- package/dist/maintenance.d.ts +4 -1
- package/dist/maintenance.js +2 -1
- 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/worker.cjs +2 -1
- package/dist/worker.cjs.map +1 -1
- package/dist/worker.js +2 -1
- package/dist/worker.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -78,6 +78,7 @@ __export(src_exports, {
|
|
|
78
78
|
formatWikiGraphCommandUri: () => import_wiki_graph_core19.formatWikiGraphCommandUri,
|
|
79
79
|
formatWikiGraphLibraryUri: () => import_wiki_graph_core19.formatWikiGraphLibraryUri,
|
|
80
80
|
getNodeResourcePath: () => getNodeResourcePath,
|
|
81
|
+
getWikiGraphSDKProviders: () => getWikiGraphSDKProviders,
|
|
81
82
|
getWikiGraphSDKRuntimeContext: () => getWikiGraphSDKRuntimeContext,
|
|
82
83
|
getWikiGraphSDKStateDir: () => getWikiGraphSDKStateDir,
|
|
83
84
|
inspectWikiGraphArchive: () => inspectWikiGraphArchive,
|
|
@@ -107,6 +108,7 @@ __export(src_exports, {
|
|
|
107
108
|
resolveExtractionPrompt: () => import_wiki_graph_core10.resolveExtractionPrompt,
|
|
108
109
|
resolveHostedProviderEndpoint: () => resolveHostedProviderEndpoint,
|
|
109
110
|
resolveKnowledgeGraphRecallPrompt: () => import_wiki_graph_core10.resolveKnowledgeGraphRecallPrompt,
|
|
111
|
+
resolveWikiGraphLLMJSON: () => resolveWikiGraphLLMJSON,
|
|
110
112
|
resolveWikispineConfig: () => resolveWikispineConfig,
|
|
111
113
|
runWikiGraphQueueWorker: () => runWikiGraphQueueWorker,
|
|
112
114
|
validateLocalConfigSection: () => validateLocalConfigSection,
|
|
@@ -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");
|
|
@@ -1663,12 +1677,18 @@ var WikiGraphConversionManager = class {
|
|
|
1663
1677
|
}
|
|
1664
1678
|
const requiresDigest = options.input.format !== "wikg";
|
|
1665
1679
|
const requiresLLM = requiresDigest && targetStage !== "planned" && targetStage !== "sourced";
|
|
1680
|
+
const llmJSON = resolveWikiGraphLLMJSON(options);
|
|
1681
|
+
const injectedLLM = llmJSON === void 0 ? getWikiGraphSDKProviders().llm : void 0;
|
|
1666
1682
|
const config = await loadWikiGraphRuntimeConfig({
|
|
1667
|
-
...
|
|
1683
|
+
...llmJSON === void 0 ? {} : { llmJSON },
|
|
1684
|
+
...injectedLLM === void 0 ? {} : { skipLLMConfig: true },
|
|
1685
|
+
...getWikiGraphSDKProviders().embedding === void 0 ? {} : { skipEmbeddingConfig: true }
|
|
1668
1686
|
});
|
|
1669
1687
|
const app = new import_wiki_graph_core3.WikiGraph({
|
|
1670
1688
|
...options.verbose === true ? { verbose: true } : {},
|
|
1671
|
-
...requiresLLM ? {
|
|
1689
|
+
...requiresLLM ? {
|
|
1690
|
+
llm: injectedLLM === void 0 ? buildWikiGraphLLMOptions(config) : { streamProvider: injectedLLM }
|
|
1691
|
+
} : {}
|
|
1672
1692
|
});
|
|
1673
1693
|
const documentDirectory = await prepareDigestDirectory(
|
|
1674
1694
|
options.digestDirectory,
|
|
@@ -1981,6 +2001,8 @@ function createOpenAICompatibleName2(baseURL) {
|
|
|
1981
2001
|
|
|
1982
2002
|
// src/query-runtime.ts
|
|
1983
2003
|
async function createConfiguredEmbeddingProvider() {
|
|
2004
|
+
const injected = getWikiGraphSDKProviders().embedding;
|
|
2005
|
+
if (injected !== void 0) return injected;
|
|
1984
2006
|
const config = await readWikiGraphEmbeddingConfig();
|
|
1985
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) {
|
|
1986
2008
|
return void 0;
|
|
@@ -2226,13 +2248,15 @@ var WikiGraphArchiveHandle = class {
|
|
|
2226
2248
|
);
|
|
2227
2249
|
}
|
|
2228
2250
|
async search(query, options = {}) {
|
|
2229
|
-
const embeddingProvider = await this.#
|
|
2230
|
-
|
|
2251
|
+
const embeddingProvider = await this.#resolveQueryEmbeddingProvider(
|
|
2252
|
+
options.queryMode,
|
|
2231
2253
|
options.signal
|
|
2232
2254
|
);
|
|
2233
2255
|
return await this.#writeDocument(
|
|
2234
2256
|
async (document) => {
|
|
2235
|
-
const chapters = await this.#resolveQueryChapters(document, options
|
|
2257
|
+
const chapters = await this.#resolveQueryChapters(document, options, {
|
|
2258
|
+
embeddingProvider
|
|
2259
|
+
});
|
|
2236
2260
|
await ensureArchiveSearchIndex(document, {
|
|
2237
2261
|
...chapters === void 0 ? {} : { chapters },
|
|
2238
2262
|
...embeddingProvider === void 0 ? {} : { embeddingProvider }
|
|
@@ -2530,6 +2554,9 @@ var WikiGraphArchiveHandle = class {
|
|
|
2530
2554
|
}
|
|
2531
2555
|
async related(objectUri = this.objectUri, options = {}) {
|
|
2532
2556
|
if (options.query === void 0) {
|
|
2557
|
+
if (options.queryMode !== void 0) {
|
|
2558
|
+
throw new Error("`queryMode` requires `query`.");
|
|
2559
|
+
}
|
|
2533
2560
|
return await this.#readDocument(async (document) => {
|
|
2534
2561
|
const chapters = await this.#resolveScope(document, {});
|
|
2535
2562
|
return await (0, import_wiki_graph_core7.listRelatedArchiveObjects)(document, objectUri, {
|
|
@@ -2538,19 +2565,22 @@ var WikiGraphArchiveHandle = class {
|
|
|
2538
2565
|
});
|
|
2539
2566
|
}, options);
|
|
2540
2567
|
}
|
|
2541
|
-
const embeddingProvider = await this.#
|
|
2542
|
-
|
|
2568
|
+
const embeddingProvider = await this.#resolveQueryEmbeddingProvider(
|
|
2569
|
+
options.queryMode,
|
|
2543
2570
|
options.signal
|
|
2544
2571
|
);
|
|
2545
2572
|
return await this.#writeDocument(
|
|
2546
2573
|
async (document) => {
|
|
2547
|
-
const chapters = await this.#resolveQueryChapters(document, options
|
|
2574
|
+
const chapters = await this.#resolveQueryChapters(document, options, {
|
|
2575
|
+
embeddingProvider
|
|
2576
|
+
});
|
|
2548
2577
|
await ensureArchiveSearchIndex(document, {
|
|
2549
2578
|
...chapters === void 0 ? {} : { chapters },
|
|
2550
2579
|
...embeddingProvider === void 0 ? {} : { embeddingProvider }
|
|
2551
2580
|
});
|
|
2552
2581
|
return await (0, import_wiki_graph_core7.listRelatedArchiveObjects)(document, objectUri, {
|
|
2553
2582
|
...withoutOperation(options),
|
|
2583
|
+
...embeddingProvider === void 0 ? {} : { embeddingProvider },
|
|
2554
2584
|
...chapters === void 0 ? {} : { chapters }
|
|
2555
2585
|
});
|
|
2556
2586
|
},
|
|
@@ -2562,6 +2592,9 @@ var WikiGraphArchiveHandle = class {
|
|
|
2562
2592
|
}
|
|
2563
2593
|
async evidence(objectUri = this.objectUri, options = {}) {
|
|
2564
2594
|
if (options.query === void 0) {
|
|
2595
|
+
if (options.queryMode !== void 0) {
|
|
2596
|
+
throw new Error("`queryMode` requires `query`.");
|
|
2597
|
+
}
|
|
2565
2598
|
return await this.#readDocument(async (document) => {
|
|
2566
2599
|
const chapters = await this.#resolveScope(document, {});
|
|
2567
2600
|
return await (0, import_wiki_graph_core7.listArchiveEvidence)(document, objectUri, {
|
|
@@ -2570,19 +2603,22 @@ var WikiGraphArchiveHandle = class {
|
|
|
2570
2603
|
});
|
|
2571
2604
|
}, options);
|
|
2572
2605
|
}
|
|
2573
|
-
const embeddingProvider = await this.#
|
|
2574
|
-
|
|
2606
|
+
const embeddingProvider = await this.#resolveQueryEmbeddingProvider(
|
|
2607
|
+
options.queryMode,
|
|
2575
2608
|
options.signal
|
|
2576
2609
|
);
|
|
2577
2610
|
return await this.#writeDocument(
|
|
2578
2611
|
async (document) => {
|
|
2579
|
-
const chapters = await this.#resolveQueryChapters(document, options
|
|
2612
|
+
const chapters = await this.#resolveQueryChapters(document, options, {
|
|
2613
|
+
embeddingProvider
|
|
2614
|
+
});
|
|
2580
2615
|
await ensureArchiveSearchIndex(document, {
|
|
2581
2616
|
...chapters === void 0 ? {} : { chapters },
|
|
2582
2617
|
...embeddingProvider === void 0 ? {} : { embeddingProvider }
|
|
2583
2618
|
});
|
|
2584
2619
|
return await (0, import_wiki_graph_core7.listArchiveEvidence)(document, objectUri, {
|
|
2585
2620
|
...withoutOperation(options),
|
|
2621
|
+
...embeddingProvider === void 0 ? {} : { embeddingProvider },
|
|
2586
2622
|
...chapters === void 0 ? {} : { chapters }
|
|
2587
2623
|
});
|
|
2588
2624
|
},
|
|
@@ -2616,6 +2652,24 @@ var WikiGraphArchiveHandle = class {
|
|
|
2616
2652
|
return meta;
|
|
2617
2653
|
}, options);
|
|
2618
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
|
+
}
|
|
2619
2673
|
async readCover(options = {}) {
|
|
2620
2674
|
const app = new import_wiki_graph_core7.WikiGraph({});
|
|
2621
2675
|
return await this.#runtime.run(
|
|
@@ -2686,11 +2740,20 @@ var WikiGraphArchiveHandle = class {
|
|
|
2686
2740
|
if (options.chapters !== void 0) return options.chapters;
|
|
2687
2741
|
return (await resolveArchiveScope(document, this.objectUri, options.depth))?.chapterIds;
|
|
2688
2742
|
}
|
|
2689
|
-
async #resolveQueryChapters(document, options) {
|
|
2743
|
+
async #resolveQueryChapters(document, options, capabilities) {
|
|
2690
2744
|
const chapters = await this.#resolveScope(document, options);
|
|
2691
|
-
|
|
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
|
+
}
|
|
2692
2755
|
const queryable = await (0, import_wiki_graph_core7.listArchiveQueryableChapterIds)(document, {
|
|
2693
|
-
...
|
|
2756
|
+
...coverageOptions
|
|
2694
2757
|
});
|
|
2695
2758
|
if (queryable.length === 0) {
|
|
2696
2759
|
throw new Error(
|
|
@@ -2699,6 +2762,19 @@ var WikiGraphArchiveHandle = class {
|
|
|
2699
2762
|
}
|
|
2700
2763
|
return queryable;
|
|
2701
2764
|
}
|
|
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`."
|
|
2774
|
+
);
|
|
2775
|
+
}
|
|
2776
|
+
return provider;
|
|
2777
|
+
}
|
|
2702
2778
|
};
|
|
2703
2779
|
async function ensureArchiveSearchIndex(document, options = {}) {
|
|
2704
2780
|
const scope = options.chapters === void 0 ? {} : { chapters: options.chapters };
|
|
@@ -3078,6 +3154,7 @@ var WikiGraphContinuationManager = class {
|
|
|
3078
3154
|
}
|
|
3079
3155
|
};
|
|
3080
3156
|
async function continueArchiveCursor(cursor, limit) {
|
|
3157
|
+
const embeddingProvider = cursor.kind === "evidence" || cursor.kind === "related" ? await resolveCursorEmbeddingProvider(cursor) : void 0;
|
|
3081
3158
|
const location = await resolveWikiGraphArchiveLocation(
|
|
3082
3159
|
archiveTargetFromLogicalLocator(getCursorArchivePath(cursor))
|
|
3083
3160
|
);
|
|
@@ -3107,6 +3184,8 @@ async function continueArchiveCursor(cursor, limit) {
|
|
|
3107
3184
|
limit,
|
|
3108
3185
|
order: cursor.order,
|
|
3109
3186
|
...cursor.query === void 0 ? {} : { query: cursor.query },
|
|
3187
|
+
...cursor.queryMode === void 0 ? {} : { queryMode: cursor.queryMode },
|
|
3188
|
+
...embeddingProvider === void 0 ? {} : { embeddingProvider },
|
|
3110
3189
|
...cursor.skipUnindexed === void 0 ? {} : { skipUnindexed: cursor.skipUnindexed },
|
|
3111
3190
|
...cursor.sourceContext === void 0 ? {} : { sourceContext: cursor.sourceContext }
|
|
3112
3191
|
});
|
|
@@ -3118,6 +3197,8 @@ async function continueArchiveCursor(cursor, limit) {
|
|
|
3118
3197
|
limit,
|
|
3119
3198
|
order: cursor.order,
|
|
3120
3199
|
...cursor.query === void 0 ? {} : { query: cursor.query },
|
|
3200
|
+
...cursor.queryMode === void 0 ? {} : { queryMode: cursor.queryMode },
|
|
3201
|
+
...embeddingProvider === void 0 ? {} : { embeddingProvider },
|
|
3121
3202
|
...cursor.role === void 0 ? {} : { role: cursor.role },
|
|
3122
3203
|
...cursor.skipUnindexed === void 0 ? {} : { skipUnindexed: cursor.skipUnindexed },
|
|
3123
3204
|
...cursor.sourceContext === void 0 ? {} : { sourceContext: cursor.sourceContext }
|
|
@@ -3127,6 +3208,7 @@ async function continueArchiveCursor(cursor, limit) {
|
|
|
3127
3208
|
);
|
|
3128
3209
|
}
|
|
3129
3210
|
async function continueLibraryCursor(cursor, limit) {
|
|
3211
|
+
const embeddingProvider = cursor.kind === "evidence" || cursor.kind === "related" ? await resolveCursorEmbeddingProvider(cursor) : void 0;
|
|
3130
3212
|
if (cursor.kind === "source-locators") {
|
|
3131
3213
|
throw new Error(
|
|
3132
3214
|
"Source locator cursors do not use the aggregate library index."
|
|
@@ -3163,6 +3245,8 @@ async function continueLibraryCursor(cursor, limit) {
|
|
|
3163
3245
|
limit,
|
|
3164
3246
|
order: cursor.order,
|
|
3165
3247
|
...cursor.query === void 0 ? {} : { query: cursor.query },
|
|
3248
|
+
...cursor.queryMode === void 0 ? {} : { queryMode: cursor.queryMode },
|
|
3249
|
+
...embeddingProvider === void 0 ? {} : { embeddingProvider },
|
|
3166
3250
|
...cursor.skipUnindexed === void 0 ? {} : { skipUnindexed: cursor.skipUnindexed },
|
|
3167
3251
|
...cursor.sourceContext === void 0 ? {} : { sourceContext: cursor.sourceContext }
|
|
3168
3252
|
});
|
|
@@ -3176,6 +3260,8 @@ async function continueLibraryCursor(cursor, limit) {
|
|
|
3176
3260
|
limit,
|
|
3177
3261
|
order: cursor.order,
|
|
3178
3262
|
...cursor.query === void 0 ? {} : { query: cursor.query },
|
|
3263
|
+
...cursor.queryMode === void 0 ? {} : { queryMode: cursor.queryMode },
|
|
3264
|
+
...embeddingProvider === void 0 ? {} : { embeddingProvider },
|
|
3179
3265
|
...cursor.role === void 0 ? {} : { role: cursor.role },
|
|
3180
3266
|
...cursor.skipUnindexed === void 0 ? {} : { skipUnindexed: cursor.skipUnindexed },
|
|
3181
3267
|
...cursor.sourceContext === void 0 ? {} : { sourceContext: cursor.sourceContext }
|
|
@@ -3200,7 +3286,7 @@ function createCollectionOptions(cursor, limit) {
|
|
|
3200
3286
|
};
|
|
3201
3287
|
}
|
|
3202
3288
|
async function createFindOptions(cursor, limit) {
|
|
3203
|
-
const embeddingProvider = await
|
|
3289
|
+
const embeddingProvider = await resolveCursorEmbeddingProvider(cursor);
|
|
3204
3290
|
return {
|
|
3205
3291
|
archiveKey: cursor.archiveKey,
|
|
3206
3292
|
...cursor.backlinks === void 0 ? {} : { backlinks: cursor.backlinks },
|
|
@@ -3208,6 +3294,7 @@ async function createFindOptions(cursor, limit) {
|
|
|
3208
3294
|
cursor: cursor.cursor,
|
|
3209
3295
|
...cursor.evidenceLimit === void 0 ? {} : { evidenceLimit: cursor.evidenceLimit },
|
|
3210
3296
|
limit,
|
|
3297
|
+
...cursor.queryMode === void 0 ? {} : { queryMode: cursor.queryMode },
|
|
3211
3298
|
...cursor.skipUnindexed === void 0 ? {} : { skipUnindexed: cursor.skipUnindexed },
|
|
3212
3299
|
...cursor.sourceContext === void 0 ? {} : { sourceContext: cursor.sourceContext },
|
|
3213
3300
|
...cursor.triplePattern === void 0 ? {} : { triplePattern: cursor.triplePattern },
|
|
@@ -3257,6 +3344,7 @@ function createContinuationPayload(context, cursor) {
|
|
|
3257
3344
|
kind: "evidence",
|
|
3258
3345
|
order: context.order ?? "doc-asc",
|
|
3259
3346
|
...context.query === void 0 ? {} : { query: context.query },
|
|
3347
|
+
...context.queryMode === void 0 ? {} : { queryMode: context.queryMode },
|
|
3260
3348
|
...context.skipUnindexed === void 0 ? {} : { skipUnindexed: context.skipUnindexed },
|
|
3261
3349
|
...context.sourceContext === void 0 ? {} : { sourceContext: context.sourceContext },
|
|
3262
3350
|
targetUri: requireTargetUri(context, "Evidence")
|
|
@@ -3273,6 +3361,7 @@ function createContinuationPayload(context, cursor) {
|
|
|
3273
3361
|
kind: "related",
|
|
3274
3362
|
order: context.order ?? "doc-asc",
|
|
3275
3363
|
...context.query === void 0 ? {} : { query: context.query },
|
|
3364
|
+
...context.queryMode === void 0 ? {} : { queryMode: context.queryMode },
|
|
3276
3365
|
...context.role === void 0 ? {} : { role: context.role },
|
|
3277
3366
|
...context.skipUnindexed === void 0 ? {} : { skipUnindexed: context.skipUnindexed },
|
|
3278
3367
|
...context.sourceContext === void 0 ? {} : { sourceContext: context.sourceContext },
|
|
@@ -3309,6 +3398,7 @@ function createContinuationPayload(context, cursor) {
|
|
|
3309
3398
|
kind: "search",
|
|
3310
3399
|
...createLibraryQueryPayload(context),
|
|
3311
3400
|
...context.query === void 0 ? {} : { query: context.query },
|
|
3401
|
+
...context.queryMode === void 0 ? {} : { queryMode: context.queryMode },
|
|
3312
3402
|
...context.skipUnindexed === void 0 ? {} : { skipUnindexed: context.skipUnindexed },
|
|
3313
3403
|
...context.sourceContext === void 0 ? {} : { sourceContext: context.sourceContext },
|
|
3314
3404
|
...context.triplePattern === void 0 ? {} : { triplePattern: context.triplePattern },
|
|
@@ -3316,6 +3406,17 @@ function createContinuationPayload(context, cursor) {
|
|
|
3316
3406
|
};
|
|
3317
3407
|
}
|
|
3318
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
|
+
}
|
|
3319
3420
|
function requireTargetUri(context, label) {
|
|
3320
3421
|
if (context.targetUri !== void 0) return context.targetUri;
|
|
3321
3422
|
throw new Error(`${label} continuation cursors require a target URI.`);
|
|
@@ -3339,7 +3440,10 @@ var import_wiki_graph_core10 = require("wiki-graph-core");
|
|
|
3339
3440
|
var import_wiki_graph_core11 = require("wiki-graph-core");
|
|
3340
3441
|
var import_wiki_graph_core12 = require("wiki-graph-core");
|
|
3341
3442
|
function createStageLLM(config, options) {
|
|
3342
|
-
const llmOptions = buildWikiGraphLLMOptions(config)
|
|
3443
|
+
const llmOptions = options?.provider === void 0 ? buildWikiGraphLLMOptions(config) : {
|
|
3444
|
+
...config.concurrent?.request === void 0 ? {} : { concurrent: config.concurrent.request },
|
|
3445
|
+
streamProvider: options.provider
|
|
3446
|
+
};
|
|
3343
3447
|
return new import_wiki_graph_core12.LLM({
|
|
3344
3448
|
sampling: (0, import_wiki_graph_core11.createDefaultWikiGraphSampling)({
|
|
3345
3449
|
...llmOptions.temperature === void 0 ? {} : { temperature: llmOptions.temperature },
|
|
@@ -3353,10 +3457,13 @@ function createStageLLM(config, options) {
|
|
|
3353
3457
|
});
|
|
3354
3458
|
}
|
|
3355
3459
|
async function loadRequiredStageConfig(options) {
|
|
3460
|
+
const injected = options.llmJSON === void 0 ? getWikiGraphSDKProviders().llm : void 0;
|
|
3356
3461
|
const config = await loadWikiGraphRuntimeConfig({
|
|
3357
|
-
...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 }
|
|
3358
3465
|
});
|
|
3359
|
-
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)) {
|
|
3360
3467
|
throw new Error(
|
|
3361
3468
|
"Missing LLM configuration. Set --llm for one run, or configure `wikg://local/config/llm` with provider and model."
|
|
3362
3469
|
);
|
|
@@ -3504,7 +3611,11 @@ async function runBuildJobWorker(options) {
|
|
|
3504
3611
|
|
|
3505
3612
|
// src/default-worker.ts
|
|
3506
3613
|
async function runWikiGraphQueueWorker(options = {}) {
|
|
3507
|
-
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
|
+
});
|
|
3508
3619
|
await runBuildJobWorker({
|
|
3509
3620
|
concurrency: config.concurrent?.job ?? DEFAULT_GENERATION_JOB_CONCURRENCY,
|
|
3510
3621
|
executeJob: async (job, reporter, context) => {
|
|
@@ -3513,12 +3624,16 @@ async function runWikiGraphQueueWorker(options = {}) {
|
|
|
3513
3624
|
async () => await executeBuildJob(job, reporter, context)
|
|
3514
3625
|
);
|
|
3515
3626
|
},
|
|
3627
|
+
...options.idleTimeoutMs === void 0 ? {} : { idleTimeoutMs: options.idleTimeoutMs },
|
|
3516
3628
|
...options.signal === void 0 ? {} : { signal: options.signal }
|
|
3517
3629
|
});
|
|
3518
3630
|
}
|
|
3519
3631
|
async function executeBuildJob(job, reporter, context) {
|
|
3632
|
+
const providers = getWikiGraphSDKProviders();
|
|
3520
3633
|
const config = await loadWikiGraphRuntimeConfig({
|
|
3521
|
-
...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 } : {}
|
|
3522
3637
|
});
|
|
3523
3638
|
const execution = await openJobExecutor(
|
|
3524
3639
|
job,
|
|
@@ -3653,12 +3768,17 @@ async function openJobExecutor(job, config, signal, reporter) {
|
|
|
3653
3768
|
const stageConfig = generation ? await loadRequiredStageConfig({
|
|
3654
3769
|
...job.llmJSON === void 0 ? {} : { llmJSON: job.llmJSON }
|
|
3655
3770
|
}) : void 0;
|
|
3771
|
+
const injectedLLM = job.llmJSON === void 0 ? getWikiGraphSDKProviders().llm : void 0;
|
|
3656
3772
|
const llm = stageConfig === void 0 ? void 0 : createStageLLM(stageConfig, {
|
|
3657
3773
|
cacheDirectory: job.cache,
|
|
3658
3774
|
logDirectory: job.log,
|
|
3659
3775
|
onTokenUsage: async (usage) => {
|
|
3660
3776
|
await reporter.addTokenUsage(usage);
|
|
3661
|
-
}
|
|
3777
|
+
},
|
|
3778
|
+
onStreamProgress: async ({ outputCharacters }) => {
|
|
3779
|
+
await reporter.addOutputCharacters(outputCharacters);
|
|
3780
|
+
},
|
|
3781
|
+
...injectedLLM === void 0 ? {} : { provider: injectedLLM }
|
|
3662
3782
|
});
|
|
3663
3783
|
const promptSource = job.prompt ?? stageConfig?.prompt;
|
|
3664
3784
|
const wikispine = job.target === "knowledge-graph" ? requireKnowledgeGraphWikispineConfig(config) : void 0;
|
|
@@ -3679,7 +3799,7 @@ async function openJobExecutor(job, config, signal, reporter) {
|
|
|
3679
3799
|
"Local Wikimedia resolution requires an LLM."
|
|
3680
3800
|
),
|
|
3681
3801
|
llmModelId: requireValue(
|
|
3682
|
-
stageConfig?.llm?.model,
|
|
3802
|
+
stageConfig?.llm?.model ?? injectedLLM?.model,
|
|
3683
3803
|
"Local Wikimedia resolution requires an LLM model."
|
|
3684
3804
|
)
|
|
3685
3805
|
} : {
|
|
@@ -3688,7 +3808,7 @@ async function openJobExecutor(job, config, signal, reporter) {
|
|
|
3688
3808
|
token: config.wikimedia.token
|
|
3689
3809
|
}
|
|
3690
3810
|
);
|
|
3691
|
-
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;
|
|
3692
3812
|
return {
|
|
3693
3813
|
async close() {
|
|
3694
3814
|
await wikimediaResolver?.close();
|
|
@@ -3881,6 +4001,12 @@ var WikiGraphJobManager = class {
|
|
|
3881
4001
|
async clean() {
|
|
3882
4002
|
return await this.#runtime.run(async () => await (0, import_wiki_graph_core15.cleanBuildJobs)());
|
|
3883
4003
|
}
|
|
4004
|
+
async runWorker(options = {}) {
|
|
4005
|
+
await this.#runtime.run(
|
|
4006
|
+
async () => await runWikiGraphQueueWorker(options),
|
|
4007
|
+
options.signal
|
|
4008
|
+
);
|
|
4009
|
+
}
|
|
3884
4010
|
async get(jobId) {
|
|
3885
4011
|
return await this.#runtime.run(
|
|
3886
4012
|
async () => await this.#createHandle(await this.#backend.get(jobId))
|
|
@@ -3956,12 +4082,13 @@ var WikiGraphJobManager = class {
|
|
|
3956
4082
|
}
|
|
3957
4083
|
async enqueue(options) {
|
|
3958
4084
|
return await this.#runtime.run(async () => {
|
|
4085
|
+
const llmJSON = resolveWikiGraphLLMJSON(options);
|
|
3959
4086
|
const location = await resolveWikiGraphArchiveLocation(options.archive);
|
|
3960
4087
|
return await (0, import_wiki_graph_core15.withArchiveBuildJobCreationLock)(
|
|
3961
4088
|
location.archiveFile,
|
|
3962
4089
|
async () => {
|
|
3963
4090
|
const target = options.target ?? "reading-summary";
|
|
3964
|
-
await validateQueueTargetConfig(target,
|
|
4091
|
+
await validateQueueTargetConfig(target, llmJSON);
|
|
3965
4092
|
const selectedExplicitly = options.chapterId !== void 0 || options.chapterIds !== void 0 || options.chapterPath !== void 0 || options.depth !== void 0;
|
|
3966
4093
|
const candidates = await new import_wiki_graph_core15.WikiGraphArchiveFile(
|
|
3967
4094
|
location.archiveFile
|
|
@@ -4011,7 +4138,7 @@ var WikiGraphJobManager = class {
|
|
|
4011
4138
|
archive: location.archiveFile,
|
|
4012
4139
|
boost: options.boost ?? false,
|
|
4013
4140
|
chapterId: candidate.chapter.chapterId,
|
|
4014
|
-
...
|
|
4141
|
+
...llmJSON === void 0 ? {} : { llmJSON },
|
|
4015
4142
|
...options.prompt === void 0 ? {} : { prompt: options.prompt },
|
|
4016
4143
|
target
|
|
4017
4144
|
}),
|
|
@@ -4033,9 +4160,10 @@ var WikiGraphJobManager = class {
|
|
|
4033
4160
|
}
|
|
4034
4161
|
async planEnqueue(options) {
|
|
4035
4162
|
return await this.#runtime.run(async () => {
|
|
4163
|
+
const llmJSON = resolveWikiGraphLLMJSON(options);
|
|
4036
4164
|
const location = await resolveWikiGraphArchiveLocation(options.archive);
|
|
4037
4165
|
const target = options.target ?? "reading-summary";
|
|
4038
|
-
await validateQueueTargetConfig(target,
|
|
4166
|
+
await validateQueueTargetConfig(target, llmJSON);
|
|
4039
4167
|
const selectedExplicitly = options.chapterId !== void 0 || options.chapterIds !== void 0 || options.chapterPath !== void 0 || options.depth !== void 0;
|
|
4040
4168
|
const candidates = await new import_wiki_graph_core15.WikiGraphArchiveFile(
|
|
4041
4169
|
location.archiveFile
|
|
@@ -4280,12 +4408,15 @@ async function selectQueueChapters(document, chapters, options) {
|
|
|
4280
4408
|
);
|
|
4281
4409
|
}
|
|
4282
4410
|
async function validateQueueTargetConfig(target, llmJSON) {
|
|
4411
|
+
const providers = getWikiGraphSDKProviders();
|
|
4283
4412
|
const config = target === "knowledge-graph" || target === "reading-graph" || target === "reading-summary" ? await loadRequiredStageConfig({
|
|
4284
4413
|
...llmJSON === void 0 ? {} : { llmJSON }
|
|
4285
4414
|
}) : await loadWikiGraphRuntimeConfig({
|
|
4286
|
-
...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 } : {}
|
|
4287
4418
|
});
|
|
4288
|
-
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) {
|
|
4289
4420
|
throw new Error(
|
|
4290
4421
|
"Missing embeddings configuration. Configure `wikg://local/config/embeddings` before queueing embedding index artifact jobs."
|
|
4291
4422
|
);
|
|
@@ -4365,6 +4496,16 @@ function forwardAbort(source, target) {
|
|
|
4365
4496
|
// src/libraries.ts
|
|
4366
4497
|
var import_wiki_graph_core16 = require("wiki-graph-core");
|
|
4367
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
|
+
}
|
|
4368
4509
|
var WikiGraphLibraryManager = class {
|
|
4369
4510
|
#runtime;
|
|
4370
4511
|
constructor(runtime) {
|
|
@@ -4434,6 +4575,43 @@ var WikiGraphLibraryManager = class {
|
|
|
4434
4575
|
)
|
|
4435
4576
|
);
|
|
4436
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
|
+
}
|
|
4437
4615
|
async moveArchive(options) {
|
|
4438
4616
|
return toArchiveSnapshot(
|
|
4439
4617
|
await this.#runtime.run(
|
|
@@ -4523,7 +4701,9 @@ var WikiGraphLibraryManager = class {
|
|
|
4523
4701
|
}
|
|
4524
4702
|
async search(target, query, options = {}) {
|
|
4525
4703
|
return await this.#runtime.run(async () => {
|
|
4526
|
-
const embeddingProvider = await
|
|
4704
|
+
const embeddingProvider = await resolveQueryEmbeddingProvider(
|
|
4705
|
+
options.queryMode
|
|
4706
|
+
);
|
|
4527
4707
|
return await (0, import_wiki_graph_core16.findWikiGraphLibraryObjects)(
|
|
4528
4708
|
requireLibraryTarget(target),
|
|
4529
4709
|
query,
|
|
@@ -4536,7 +4716,9 @@ var WikiGraphLibraryManager = class {
|
|
|
4536
4716
|
}
|
|
4537
4717
|
async searchArchiveMembers(target, query, options = {}) {
|
|
4538
4718
|
return await this.#runtime.run(async () => {
|
|
4539
|
-
const embeddingProvider = await
|
|
4719
|
+
const embeddingProvider = await resolveQueryEmbeddingProvider(
|
|
4720
|
+
options.queryMode
|
|
4721
|
+
);
|
|
4540
4722
|
return await (0, import_wiki_graph_core16.findWikiGraphLibraryArchiveMembers)(
|
|
4541
4723
|
requireLibraryTarget(target),
|
|
4542
4724
|
query,
|
|
@@ -4577,22 +4759,36 @@ var WikiGraphLibraryManager = class {
|
|
|
4577
4759
|
);
|
|
4578
4760
|
}
|
|
4579
4761
|
async related(target, objectUri, options = {}) {
|
|
4580
|
-
return await this.#runtime.run(
|
|
4581
|
-
|
|
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)(
|
|
4582
4768
|
requireLibraryTarget(target),
|
|
4583
4769
|
objectUri,
|
|
4584
|
-
|
|
4585
|
-
|
|
4586
|
-
|
|
4770
|
+
{
|
|
4771
|
+
...options,
|
|
4772
|
+
...embeddingProvider === void 0 ? {} : { embeddingProvider }
|
|
4773
|
+
}
|
|
4774
|
+
);
|
|
4775
|
+
});
|
|
4587
4776
|
}
|
|
4588
4777
|
async evidence(target, objectUri, options = {}) {
|
|
4589
|
-
return await this.#runtime.run(
|
|
4590
|
-
|
|
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)(
|
|
4591
4784
|
requireLibraryTarget(target),
|
|
4592
4785
|
objectUri,
|
|
4593
|
-
|
|
4594
|
-
|
|
4595
|
-
|
|
4786
|
+
{
|
|
4787
|
+
...options,
|
|
4788
|
+
...embeddingProvider === void 0 ? {} : { embeddingProvider }
|
|
4789
|
+
}
|
|
4790
|
+
);
|
|
4791
|
+
});
|
|
4596
4792
|
}
|
|
4597
4793
|
async pack(target, objectUri, budget = 5e3) {
|
|
4598
4794
|
return await this.#runtime.run(
|
|
@@ -4674,6 +4870,97 @@ function requireLibraryTarget(value) {
|
|
|
4674
4870
|
}
|
|
4675
4871
|
return target;
|
|
4676
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
|
+
}
|
|
4677
4964
|
|
|
4678
4965
|
// src/maintenance.ts
|
|
4679
4966
|
var import_wiki_graph_core17 = require("wiki-graph-core");
|
|
@@ -4748,6 +5035,7 @@ var WikiGraphSDK = class {
|
|
|
4748
5035
|
cwd: options.cwd ?? process.cwd(),
|
|
4749
5036
|
env: { ...process.env, ...options.env },
|
|
4750
5037
|
envPolicy: options.envPolicy ?? "production",
|
|
5038
|
+
providers: { ...options.providers },
|
|
4751
5039
|
...options.stateDir === void 0 ? {} : { stateDir: options.stateDir }
|
|
4752
5040
|
};
|
|
4753
5041
|
this.archives = new WikiGraphArchiveManager(this);
|
|
@@ -4759,7 +5047,7 @@ var WikiGraphSDK = class {
|
|
|
4759
5047
|
this.maintenance = new WikiGraphMaintenanceManager(this);
|
|
4760
5048
|
}
|
|
4761
5049
|
async run(operation, signal, options = {}) {
|
|
4762
|
-
|
|
5050
|
+
throwIfAborted2(signal);
|
|
4763
5051
|
const runWithContext = async () => await withWikiGraphSDKRuntimeContext(this.#context, async () => {
|
|
4764
5052
|
if (options.skipHomeBootstrap !== true) {
|
|
4765
5053
|
this.#homeReady ??= (0, import_wiki_graph_core18.ensureWikiGraphHomeSchemaCurrent)().catch(
|
|
@@ -4776,14 +5064,14 @@ var WikiGraphSDK = class {
|
|
|
4776
5064
|
this.#context.stateDir,
|
|
4777
5065
|
runWithContext
|
|
4778
5066
|
);
|
|
4779
|
-
|
|
5067
|
+
throwIfAborted2(signal);
|
|
4780
5068
|
return result;
|
|
4781
5069
|
}
|
|
4782
5070
|
close() {
|
|
4783
5071
|
this.jobs.close();
|
|
4784
5072
|
}
|
|
4785
5073
|
};
|
|
4786
|
-
function
|
|
5074
|
+
function throwIfAborted2(signal) {
|
|
4787
5075
|
if (signal?.aborted !== true) return;
|
|
4788
5076
|
throw signal.reason instanceof Error ? signal.reason : new Error("The Wiki Graph SDK operation was aborted.");
|
|
4789
5077
|
}
|
|
@@ -4842,6 +5130,7 @@ var import_wiki_graph_core19 = require("wiki-graph-core");
|
|
|
4842
5130
|
formatWikiGraphCommandUri,
|
|
4843
5131
|
formatWikiGraphLibraryUri,
|
|
4844
5132
|
getNodeResourcePath,
|
|
5133
|
+
getWikiGraphSDKProviders,
|
|
4845
5134
|
getWikiGraphSDKRuntimeContext,
|
|
4846
5135
|
getWikiGraphSDKStateDir,
|
|
4847
5136
|
inspectWikiGraphArchive,
|
|
@@ -4871,6 +5160,7 @@ var import_wiki_graph_core19 = require("wiki-graph-core");
|
|
|
4871
5160
|
resolveExtractionPrompt,
|
|
4872
5161
|
resolveHostedProviderEndpoint,
|
|
4873
5162
|
resolveKnowledgeGraphRecallPrompt,
|
|
5163
|
+
resolveWikiGraphLLMJSON,
|
|
4874
5164
|
resolveWikispineConfig,
|
|
4875
5165
|
runWikiGraphQueueWorker,
|
|
4876
5166
|
validateLocalConfigSection,
|