wiki-graph-sdk 0.8.0 → 0.8.2
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 +46 -0
- package/dist/archives.cjs +98 -17
- package/dist/archives.cjs.map +1 -1
- package/dist/archives.d.ts +10 -2
- package/dist/archives.js +100 -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 +24 -5
- package/dist/conversions.js.map +1 -1
- package/dist/default-worker.cjs +84 -21
- package/dist/default-worker.cjs.map +1 -1
- package/dist/default-worker.d.ts +1 -0
- package/dist/default-worker.js +88 -21
- 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 +3 -1
- package/dist/embedding.js.map +1 -1
- package/dist/gc.cjs +52 -10
- package/dist/gc.cjs.map +1 -1
- package/dist/gc.d.ts +3 -0
- package/dist/gc.js +56 -10
- package/dist/gc.js.map +1 -1
- package/dist/host-pQiVAKEY.d.ts +10 -0
- package/dist/index.cjs +422 -57
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +33 -12
- package/dist/index.js +427 -59
- 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 +3 -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 +3 -1
- package/dist/maintenance.js.map +1 -1
- package/dist/node-platform.cjs +18 -4
- package/dist/node-platform.cjs.map +1 -1
- package/dist/node-platform.d.ts +12 -3
- package/dist/node-platform.js +18 -4
- package/dist/node-platform.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 +5 -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 +23 -12
- package/dist/stage.js.map +1 -1
- package/dist/worker.cjs +83 -43
- package/dist/worker.cjs.map +1 -1
- package/dist/worker.d.ts +7 -2
- package/dist/worker.js +87 -43
- package/dist/worker.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -11,6 +11,7 @@ import { Readable as Readable2 } from "stream";
|
|
|
11
11
|
import {
|
|
12
12
|
addChapter,
|
|
13
13
|
applyChapterTree,
|
|
14
|
+
assertArchiveIndexArtifactsReady,
|
|
14
15
|
assertNoActiveBuildJobConflicts,
|
|
15
16
|
assertNoActiveBuildJobs,
|
|
16
17
|
deleteArchiveSearchSessions,
|
|
@@ -141,6 +142,7 @@ import * as yauzl from "yauzl";
|
|
|
141
142
|
import * as yazl from "yazl";
|
|
142
143
|
import { Environment, Loader } from "nunjucks";
|
|
143
144
|
import {
|
|
145
|
+
getWikiGraphPlatform,
|
|
144
146
|
getWikiGraphStorage,
|
|
145
147
|
installWikiGraphPlatform,
|
|
146
148
|
installWikiGraphStorage,
|
|
@@ -763,6 +765,9 @@ var nodeWikiGraphPlatform = {
|
|
|
763
765
|
write: writeNodeZip
|
|
764
766
|
}
|
|
765
767
|
};
|
|
768
|
+
function createNodeWikiGraphPlatform(options = {}) {
|
|
769
|
+
return options.lifecycle === void 0 ? nodeWikiGraphPlatform : { ...nodeWikiGraphPlatform, lifecycle: options.lifecycle };
|
|
770
|
+
}
|
|
766
771
|
var NodeTemplateLoader = class extends Loader {
|
|
767
772
|
#dataDirectory;
|
|
768
773
|
constructor(dataDirectory) {
|
|
@@ -808,10 +813,15 @@ function resolveNodeDataDirectory() {
|
|
|
808
813
|
directory = parent;
|
|
809
814
|
}
|
|
810
815
|
}
|
|
811
|
-
function createNodeWikiGraphStorage(
|
|
816
|
+
function createNodeWikiGraphStorage(stateRootOrOptions = pathModule.join(
|
|
817
|
+
os.homedir(),
|
|
818
|
+
".wikigraph"
|
|
819
|
+
)) {
|
|
820
|
+
const libraryRoot = typeof stateRootOrOptions === "string" ? stateRootOrOptions : stateRootOrOptions.libraryRoot;
|
|
821
|
+
const documentStoreRoot = typeof stateRootOrOptions === "string" ? pathModule.join(stateRootOrOptions, "documents") : stateRootOrOptions.documentStoreRoot;
|
|
812
822
|
return {
|
|
813
|
-
library: new NodeDirectory(
|
|
814
|
-
documentStore: new NodeDirectory(
|
|
823
|
+
library: new NodeDirectory(libraryRoot),
|
|
824
|
+
documentStore: new NodeDirectory(documentStoreRoot)
|
|
815
825
|
};
|
|
816
826
|
}
|
|
817
827
|
function installNodeWikiGraphPlatform(stateRoot) {
|
|
@@ -819,7 +829,11 @@ function installNodeWikiGraphPlatform(stateRoot) {
|
|
|
819
829
|
installWikiGraphStorage(createNodeWikiGraphStorage(stateRoot));
|
|
820
830
|
}
|
|
821
831
|
function ensureNodeWikiGraphPlatform() {
|
|
822
|
-
|
|
832
|
+
try {
|
|
833
|
+
getWikiGraphPlatform();
|
|
834
|
+
} catch {
|
|
835
|
+
installWikiGraphPlatform(nodeWikiGraphPlatform);
|
|
836
|
+
}
|
|
823
837
|
try {
|
|
824
838
|
getWikiGraphStorage();
|
|
825
839
|
} catch {
|
|
@@ -865,12 +879,16 @@ function getWikiGraphSDKRuntimeContext() {
|
|
|
865
879
|
return runtimeContext.getStore() ?? {
|
|
866
880
|
cwd: process.cwd(),
|
|
867
881
|
env: process.env,
|
|
868
|
-
envPolicy: "production"
|
|
882
|
+
envPolicy: "production",
|
|
883
|
+
providers: {}
|
|
869
884
|
};
|
|
870
885
|
}
|
|
871
886
|
function getWikiGraphSDKStateDir() {
|
|
872
887
|
return getWikiGraphSDKRuntimeContext().stateDir;
|
|
873
888
|
}
|
|
889
|
+
function getWikiGraphSDKProviders() {
|
|
890
|
+
return getWikiGraphSDKRuntimeContext().providers ?? {};
|
|
891
|
+
}
|
|
874
892
|
|
|
875
893
|
// src/local-config.ts
|
|
876
894
|
import { join as join2 } from "path";
|
|
@@ -1171,8 +1189,8 @@ var inlineLLMConfigSchema = z.object({
|
|
|
1171
1189
|
});
|
|
1172
1190
|
async function loadWikiGraphRuntimeConfig(options) {
|
|
1173
1191
|
const [embedding, localLLM, concurrent, wikimedia, wikispine] = await Promise.all([
|
|
1174
|
-
readLocalConfigSection("embeddings"),
|
|
1175
|
-
readLocalConfigSection("llm"),
|
|
1192
|
+
options?.skipEmbeddingConfig === true ? Promise.resolve({}) : readLocalConfigSection("embeddings"),
|
|
1193
|
+
options?.skipLLMConfig === true ? Promise.resolve({}) : readLocalConfigSection("llm"),
|
|
1176
1194
|
readLocalConfigSection("concurrent"),
|
|
1177
1195
|
readLocalConfigSection("wikimedia"),
|
|
1178
1196
|
readLocalConfigSection("wikispine")
|
|
@@ -1368,6 +1386,14 @@ function formatError2(error) {
|
|
|
1368
1386
|
return error instanceof Error ? error.message : String(error);
|
|
1369
1387
|
}
|
|
1370
1388
|
|
|
1389
|
+
// src/providers.ts
|
|
1390
|
+
function resolveWikiGraphLLMJSON(options) {
|
|
1391
|
+
if (options.llm !== void 0 && options.llmJSON !== void 0) {
|
|
1392
|
+
throw new Error("Pass either llm or llmJSON, not both.");
|
|
1393
|
+
}
|
|
1394
|
+
return options.llm === void 0 ? options.llmJSON : JSON.stringify(options.llm);
|
|
1395
|
+
}
|
|
1396
|
+
|
|
1371
1397
|
// src/runtime-path.ts
|
|
1372
1398
|
import { homedir as homedir3 } from "os";
|
|
1373
1399
|
import { isAbsolute as isAbsolute2, resolve as resolve2 } from "path";
|
|
@@ -1601,12 +1627,18 @@ var WikiGraphConversionManager = class {
|
|
|
1601
1627
|
}
|
|
1602
1628
|
const requiresDigest = options.input.format !== "wikg";
|
|
1603
1629
|
const requiresLLM = requiresDigest && targetStage !== "planned" && targetStage !== "sourced";
|
|
1630
|
+
const llmJSON = resolveWikiGraphLLMJSON(options);
|
|
1631
|
+
const injectedLLM = llmJSON === void 0 ? getWikiGraphSDKProviders().llm : void 0;
|
|
1604
1632
|
const config = await loadWikiGraphRuntimeConfig({
|
|
1605
|
-
...
|
|
1633
|
+
...llmJSON === void 0 ? {} : { llmJSON },
|
|
1634
|
+
...injectedLLM === void 0 ? {} : { skipLLMConfig: true },
|
|
1635
|
+
...getWikiGraphSDKProviders().embedding === void 0 ? {} : { skipEmbeddingConfig: true }
|
|
1606
1636
|
});
|
|
1607
1637
|
const app = new WikiGraph({
|
|
1608
1638
|
...options.verbose === true ? { verbose: true } : {},
|
|
1609
|
-
...requiresLLM ? {
|
|
1639
|
+
...requiresLLM ? {
|
|
1640
|
+
llm: injectedLLM === void 0 ? buildWikiGraphLLMOptions(config) : { streamProvider: injectedLLM }
|
|
1641
|
+
} : {}
|
|
1610
1642
|
});
|
|
1611
1643
|
const documentDirectory = await prepareDigestDirectory(
|
|
1612
1644
|
options.digestDirectory,
|
|
@@ -1921,6 +1953,8 @@ function createOpenAICompatibleName2(baseURL) {
|
|
|
1921
1953
|
|
|
1922
1954
|
// src/query-runtime.ts
|
|
1923
1955
|
async function createConfiguredEmbeddingProvider() {
|
|
1956
|
+
const injected = getWikiGraphSDKProviders().embedding;
|
|
1957
|
+
if (injected !== void 0) return injected;
|
|
1924
1958
|
const config = await readWikiGraphEmbeddingConfig();
|
|
1925
1959
|
if (config.provider === void 0 || config.model === void 0 || config.provider === "openai-compatible" && config.baseURL === void 0 || config.provider === "openai" && config.baseURL !== void 0) {
|
|
1926
1960
|
return void 0;
|
|
@@ -2172,13 +2206,15 @@ var WikiGraphArchiveHandle = class {
|
|
|
2172
2206
|
);
|
|
2173
2207
|
}
|
|
2174
2208
|
async search(query, options = {}) {
|
|
2175
|
-
const embeddingProvider = await this.#
|
|
2176
|
-
|
|
2209
|
+
const embeddingProvider = await this.#resolveQueryEmbeddingProvider(
|
|
2210
|
+
options.queryMode,
|
|
2177
2211
|
options.signal
|
|
2178
2212
|
);
|
|
2179
2213
|
return await this.#writeDocument(
|
|
2180
2214
|
async (document) => {
|
|
2181
|
-
const chapters = await this.#resolveQueryChapters(document, options
|
|
2215
|
+
const chapters = await this.#resolveQueryChapters(document, options, {
|
|
2216
|
+
embeddingProvider
|
|
2217
|
+
});
|
|
2182
2218
|
await ensureArchiveSearchIndex(document, {
|
|
2183
2219
|
...chapters === void 0 ? {} : { chapters },
|
|
2184
2220
|
...embeddingProvider === void 0 ? {} : { embeddingProvider }
|
|
@@ -2286,6 +2322,13 @@ var WikiGraphArchiveHandle = class {
|
|
|
2286
2322
|
);
|
|
2287
2323
|
return status;
|
|
2288
2324
|
}
|
|
2325
|
+
/** Clear cached search sessions without changing the archive index. */
|
|
2326
|
+
async clearSearchSessions(options = {}) {
|
|
2327
|
+
await this.#runtime.run(
|
|
2328
|
+
async () => await deleteArchiveSearchSessions(this.path),
|
|
2329
|
+
options.signal
|
|
2330
|
+
);
|
|
2331
|
+
}
|
|
2289
2332
|
async listChapters(options = {}) {
|
|
2290
2333
|
return await this.#readDocument(
|
|
2291
2334
|
async (document) => await listChapters2(document),
|
|
@@ -2476,6 +2519,9 @@ var WikiGraphArchiveHandle = class {
|
|
|
2476
2519
|
}
|
|
2477
2520
|
async related(objectUri = this.objectUri, options = {}) {
|
|
2478
2521
|
if (options.query === void 0) {
|
|
2522
|
+
if (options.queryMode !== void 0) {
|
|
2523
|
+
throw new Error("`queryMode` requires `query`.");
|
|
2524
|
+
}
|
|
2479
2525
|
return await this.#readDocument(async (document) => {
|
|
2480
2526
|
const chapters = await this.#resolveScope(document, {});
|
|
2481
2527
|
return await listRelatedArchiveObjects(document, objectUri, {
|
|
@@ -2484,19 +2530,22 @@ var WikiGraphArchiveHandle = class {
|
|
|
2484
2530
|
});
|
|
2485
2531
|
}, options);
|
|
2486
2532
|
}
|
|
2487
|
-
const embeddingProvider = await this.#
|
|
2488
|
-
|
|
2533
|
+
const embeddingProvider = await this.#resolveQueryEmbeddingProvider(
|
|
2534
|
+
options.queryMode,
|
|
2489
2535
|
options.signal
|
|
2490
2536
|
);
|
|
2491
2537
|
return await this.#writeDocument(
|
|
2492
2538
|
async (document) => {
|
|
2493
|
-
const chapters = await this.#resolveQueryChapters(document, options
|
|
2539
|
+
const chapters = await this.#resolveQueryChapters(document, options, {
|
|
2540
|
+
embeddingProvider
|
|
2541
|
+
});
|
|
2494
2542
|
await ensureArchiveSearchIndex(document, {
|
|
2495
2543
|
...chapters === void 0 ? {} : { chapters },
|
|
2496
2544
|
...embeddingProvider === void 0 ? {} : { embeddingProvider }
|
|
2497
2545
|
});
|
|
2498
2546
|
return await listRelatedArchiveObjects(document, objectUri, {
|
|
2499
2547
|
...withoutOperation(options),
|
|
2548
|
+
...embeddingProvider === void 0 ? {} : { embeddingProvider },
|
|
2500
2549
|
...chapters === void 0 ? {} : { chapters }
|
|
2501
2550
|
});
|
|
2502
2551
|
},
|
|
@@ -2508,6 +2557,9 @@ var WikiGraphArchiveHandle = class {
|
|
|
2508
2557
|
}
|
|
2509
2558
|
async evidence(objectUri = this.objectUri, options = {}) {
|
|
2510
2559
|
if (options.query === void 0) {
|
|
2560
|
+
if (options.queryMode !== void 0) {
|
|
2561
|
+
throw new Error("`queryMode` requires `query`.");
|
|
2562
|
+
}
|
|
2511
2563
|
return await this.#readDocument(async (document) => {
|
|
2512
2564
|
const chapters = await this.#resolveScope(document, {});
|
|
2513
2565
|
return await listArchiveEvidence(document, objectUri, {
|
|
@@ -2516,19 +2568,22 @@ var WikiGraphArchiveHandle = class {
|
|
|
2516
2568
|
});
|
|
2517
2569
|
}, options);
|
|
2518
2570
|
}
|
|
2519
|
-
const embeddingProvider = await this.#
|
|
2520
|
-
|
|
2571
|
+
const embeddingProvider = await this.#resolveQueryEmbeddingProvider(
|
|
2572
|
+
options.queryMode,
|
|
2521
2573
|
options.signal
|
|
2522
2574
|
);
|
|
2523
2575
|
return await this.#writeDocument(
|
|
2524
2576
|
async (document) => {
|
|
2525
|
-
const chapters = await this.#resolveQueryChapters(document, options
|
|
2577
|
+
const chapters = await this.#resolveQueryChapters(document, options, {
|
|
2578
|
+
embeddingProvider
|
|
2579
|
+
});
|
|
2526
2580
|
await ensureArchiveSearchIndex(document, {
|
|
2527
2581
|
...chapters === void 0 ? {} : { chapters },
|
|
2528
2582
|
...embeddingProvider === void 0 ? {} : { embeddingProvider }
|
|
2529
2583
|
});
|
|
2530
2584
|
return await listArchiveEvidence(document, objectUri, {
|
|
2531
2585
|
...withoutOperation(options),
|
|
2586
|
+
...embeddingProvider === void 0 ? {} : { embeddingProvider },
|
|
2532
2587
|
...chapters === void 0 ? {} : { chapters }
|
|
2533
2588
|
});
|
|
2534
2589
|
},
|
|
@@ -2562,6 +2617,24 @@ var WikiGraphArchiveHandle = class {
|
|
|
2562
2617
|
return meta;
|
|
2563
2618
|
}, options);
|
|
2564
2619
|
}
|
|
2620
|
+
async setArchiveTitle(title, options = {}) {
|
|
2621
|
+
const normalized = title?.trim() ?? null;
|
|
2622
|
+
if (title !== null && normalized === "") {
|
|
2623
|
+
throw new Error("Archive title cannot be empty.");
|
|
2624
|
+
}
|
|
2625
|
+
return await this.#writeDocument(async (document) => {
|
|
2626
|
+
if (normalized === null) {
|
|
2627
|
+
await document.metadata.deleteKey("", "title");
|
|
2628
|
+
} else {
|
|
2629
|
+
await document.metadata.put(
|
|
2630
|
+
{ kind: ObjectMetadataKind.Archive, objectPath: "" },
|
|
2631
|
+
"title",
|
|
2632
|
+
normalized
|
|
2633
|
+
);
|
|
2634
|
+
}
|
|
2635
|
+
return normalized;
|
|
2636
|
+
}, options);
|
|
2637
|
+
}
|
|
2565
2638
|
async readCover(options = {}) {
|
|
2566
2639
|
const app = new WikiGraph2({});
|
|
2567
2640
|
return await this.#runtime.run(
|
|
@@ -2632,11 +2705,20 @@ var WikiGraphArchiveHandle = class {
|
|
|
2632
2705
|
if (options.chapters !== void 0) return options.chapters;
|
|
2633
2706
|
return (await resolveArchiveScope(document, this.objectUri, options.depth))?.chapterIds;
|
|
2634
2707
|
}
|
|
2635
|
-
async #resolveQueryChapters(document, options) {
|
|
2708
|
+
async #resolveQueryChapters(document, options, capabilities) {
|
|
2636
2709
|
const chapters = await this.#resolveScope(document, options);
|
|
2637
|
-
|
|
2710
|
+
const coverageOptions = {
|
|
2711
|
+
...chapters === void 0 ? {} : { chapters },
|
|
2712
|
+
...capabilities.embeddingProvider === void 0 ? {} : { embeddingProvider: capabilities.embeddingProvider },
|
|
2713
|
+
requireEmbeddingProvider: true,
|
|
2714
|
+
...options.queryMode === void 0 ? {} : { queryMode: options.queryMode }
|
|
2715
|
+
};
|
|
2716
|
+
if (options.skipUnindexed !== true) {
|
|
2717
|
+
await assertArchiveIndexArtifactsReady(document, coverageOptions);
|
|
2718
|
+
return chapters;
|
|
2719
|
+
}
|
|
2638
2720
|
const queryable = await listArchiveQueryableChapterIds(document, {
|
|
2639
|
-
...
|
|
2721
|
+
...coverageOptions
|
|
2640
2722
|
});
|
|
2641
2723
|
if (queryable.length === 0) {
|
|
2642
2724
|
throw new Error(
|
|
@@ -2645,6 +2727,19 @@ var WikiGraphArchiveHandle = class {
|
|
|
2645
2727
|
}
|
|
2646
2728
|
return queryable;
|
|
2647
2729
|
}
|
|
2730
|
+
async #resolveQueryEmbeddingProvider(queryMode, signal) {
|
|
2731
|
+
if (queryMode === "fts") return void 0;
|
|
2732
|
+
const provider = await this.#runtime.run(
|
|
2733
|
+
createConfiguredEmbeddingProvider,
|
|
2734
|
+
signal
|
|
2735
|
+
);
|
|
2736
|
+
if (queryMode === "embedding" && provider === void 0) {
|
|
2737
|
+
throw new Error(
|
|
2738
|
+
"Embedding query mode requires embeddings configuration at `wikg://local/config/embeddings`."
|
|
2739
|
+
);
|
|
2740
|
+
}
|
|
2741
|
+
return provider;
|
|
2742
|
+
}
|
|
2648
2743
|
};
|
|
2649
2744
|
async function ensureArchiveSearchIndex(document, options = {}) {
|
|
2650
2745
|
const scope = options.chapters === void 0 ? {} : { chapters: options.chapters };
|
|
@@ -3040,6 +3135,7 @@ var WikiGraphContinuationManager = class {
|
|
|
3040
3135
|
}
|
|
3041
3136
|
};
|
|
3042
3137
|
async function continueArchiveCursor(cursor, limit) {
|
|
3138
|
+
const embeddingProvider = cursor.kind === "evidence" || cursor.kind === "related" ? await resolveCursorEmbeddingProvider(cursor) : void 0;
|
|
3043
3139
|
const location = await resolveWikiGraphArchiveLocation(
|
|
3044
3140
|
archiveTargetFromLogicalLocator(getCursorArchivePath(cursor))
|
|
3045
3141
|
);
|
|
@@ -3069,6 +3165,8 @@ async function continueArchiveCursor(cursor, limit) {
|
|
|
3069
3165
|
limit,
|
|
3070
3166
|
order: cursor.order,
|
|
3071
3167
|
...cursor.query === void 0 ? {} : { query: cursor.query },
|
|
3168
|
+
...cursor.queryMode === void 0 ? {} : { queryMode: cursor.queryMode },
|
|
3169
|
+
...embeddingProvider === void 0 ? {} : { embeddingProvider },
|
|
3072
3170
|
...cursor.skipUnindexed === void 0 ? {} : { skipUnindexed: cursor.skipUnindexed },
|
|
3073
3171
|
...cursor.sourceContext === void 0 ? {} : { sourceContext: cursor.sourceContext }
|
|
3074
3172
|
});
|
|
@@ -3080,6 +3178,8 @@ async function continueArchiveCursor(cursor, limit) {
|
|
|
3080
3178
|
limit,
|
|
3081
3179
|
order: cursor.order,
|
|
3082
3180
|
...cursor.query === void 0 ? {} : { query: cursor.query },
|
|
3181
|
+
...cursor.queryMode === void 0 ? {} : { queryMode: cursor.queryMode },
|
|
3182
|
+
...embeddingProvider === void 0 ? {} : { embeddingProvider },
|
|
3083
3183
|
...cursor.role === void 0 ? {} : { role: cursor.role },
|
|
3084
3184
|
...cursor.skipUnindexed === void 0 ? {} : { skipUnindexed: cursor.skipUnindexed },
|
|
3085
3185
|
...cursor.sourceContext === void 0 ? {} : { sourceContext: cursor.sourceContext }
|
|
@@ -3089,6 +3189,7 @@ async function continueArchiveCursor(cursor, limit) {
|
|
|
3089
3189
|
);
|
|
3090
3190
|
}
|
|
3091
3191
|
async function continueLibraryCursor(cursor, limit) {
|
|
3192
|
+
const embeddingProvider = cursor.kind === "evidence" || cursor.kind === "related" ? await resolveCursorEmbeddingProvider(cursor) : void 0;
|
|
3092
3193
|
if (cursor.kind === "source-locators") {
|
|
3093
3194
|
throw new Error(
|
|
3094
3195
|
"Source locator cursors do not use the aggregate library index."
|
|
@@ -3125,6 +3226,8 @@ async function continueLibraryCursor(cursor, limit) {
|
|
|
3125
3226
|
limit,
|
|
3126
3227
|
order: cursor.order,
|
|
3127
3228
|
...cursor.query === void 0 ? {} : { query: cursor.query },
|
|
3229
|
+
...cursor.queryMode === void 0 ? {} : { queryMode: cursor.queryMode },
|
|
3230
|
+
...embeddingProvider === void 0 ? {} : { embeddingProvider },
|
|
3128
3231
|
...cursor.skipUnindexed === void 0 ? {} : { skipUnindexed: cursor.skipUnindexed },
|
|
3129
3232
|
...cursor.sourceContext === void 0 ? {} : { sourceContext: cursor.sourceContext }
|
|
3130
3233
|
});
|
|
@@ -3138,6 +3241,8 @@ async function continueLibraryCursor(cursor, limit) {
|
|
|
3138
3241
|
limit,
|
|
3139
3242
|
order: cursor.order,
|
|
3140
3243
|
...cursor.query === void 0 ? {} : { query: cursor.query },
|
|
3244
|
+
...cursor.queryMode === void 0 ? {} : { queryMode: cursor.queryMode },
|
|
3245
|
+
...embeddingProvider === void 0 ? {} : { embeddingProvider },
|
|
3141
3246
|
...cursor.role === void 0 ? {} : { role: cursor.role },
|
|
3142
3247
|
...cursor.skipUnindexed === void 0 ? {} : { skipUnindexed: cursor.skipUnindexed },
|
|
3143
3248
|
...cursor.sourceContext === void 0 ? {} : { sourceContext: cursor.sourceContext }
|
|
@@ -3162,7 +3267,7 @@ function createCollectionOptions(cursor, limit) {
|
|
|
3162
3267
|
};
|
|
3163
3268
|
}
|
|
3164
3269
|
async function createFindOptions(cursor, limit) {
|
|
3165
|
-
const embeddingProvider = await
|
|
3270
|
+
const embeddingProvider = await resolveCursorEmbeddingProvider(cursor);
|
|
3166
3271
|
return {
|
|
3167
3272
|
archiveKey: cursor.archiveKey,
|
|
3168
3273
|
...cursor.backlinks === void 0 ? {} : { backlinks: cursor.backlinks },
|
|
@@ -3170,6 +3275,9 @@ async function createFindOptions(cursor, limit) {
|
|
|
3170
3275
|
cursor: cursor.cursor,
|
|
3171
3276
|
...cursor.evidenceLimit === void 0 ? {} : { evidenceLimit: cursor.evidenceLimit },
|
|
3172
3277
|
limit,
|
|
3278
|
+
...cursor.match === void 0 ? {} : { match: cursor.match },
|
|
3279
|
+
...cursor.order === void 0 ? {} : { order: cursor.order },
|
|
3280
|
+
...cursor.queryMode === void 0 ? {} : { queryMode: cursor.queryMode },
|
|
3173
3281
|
...cursor.skipUnindexed === void 0 ? {} : { skipUnindexed: cursor.skipUnindexed },
|
|
3174
3282
|
...cursor.sourceContext === void 0 ? {} : { sourceContext: cursor.sourceContext },
|
|
3175
3283
|
...cursor.triplePattern === void 0 ? {} : { triplePattern: cursor.triplePattern },
|
|
@@ -3219,6 +3327,7 @@ function createContinuationPayload(context, cursor) {
|
|
|
3219
3327
|
kind: "evidence",
|
|
3220
3328
|
order: context.order ?? "doc-asc",
|
|
3221
3329
|
...context.query === void 0 ? {} : { query: context.query },
|
|
3330
|
+
...context.queryMode === void 0 ? {} : { queryMode: context.queryMode },
|
|
3222
3331
|
...context.skipUnindexed === void 0 ? {} : { skipUnindexed: context.skipUnindexed },
|
|
3223
3332
|
...context.sourceContext === void 0 ? {} : { sourceContext: context.sourceContext },
|
|
3224
3333
|
targetUri: requireTargetUri(context, "Evidence")
|
|
@@ -3235,6 +3344,7 @@ function createContinuationPayload(context, cursor) {
|
|
|
3235
3344
|
kind: "related",
|
|
3236
3345
|
order: context.order ?? "doc-asc",
|
|
3237
3346
|
...context.query === void 0 ? {} : { query: context.query },
|
|
3347
|
+
...context.queryMode === void 0 ? {} : { queryMode: context.queryMode },
|
|
3238
3348
|
...context.role === void 0 ? {} : { role: context.role },
|
|
3239
3349
|
...context.skipUnindexed === void 0 ? {} : { skipUnindexed: context.skipUnindexed },
|
|
3240
3350
|
...context.sourceContext === void 0 ? {} : { sourceContext: context.sourceContext },
|
|
@@ -3270,7 +3380,10 @@ function createContinuationPayload(context, cursor) {
|
|
|
3270
3380
|
indexScope: context.indexScope,
|
|
3271
3381
|
kind: "search",
|
|
3272
3382
|
...createLibraryQueryPayload(context),
|
|
3383
|
+
...context.match === void 0 ? {} : { match: context.match },
|
|
3384
|
+
...context.order === void 0 ? {} : { order: context.order },
|
|
3273
3385
|
...context.query === void 0 ? {} : { query: context.query },
|
|
3386
|
+
...context.queryMode === void 0 ? {} : { queryMode: context.queryMode },
|
|
3274
3387
|
...context.skipUnindexed === void 0 ? {} : { skipUnindexed: context.skipUnindexed },
|
|
3275
3388
|
...context.sourceContext === void 0 ? {} : { sourceContext: context.sourceContext },
|
|
3276
3389
|
...context.triplePattern === void 0 ? {} : { triplePattern: context.triplePattern },
|
|
@@ -3278,6 +3391,17 @@ function createContinuationPayload(context, cursor) {
|
|
|
3278
3391
|
};
|
|
3279
3392
|
}
|
|
3280
3393
|
}
|
|
3394
|
+
async function resolveCursorEmbeddingProvider(cursor) {
|
|
3395
|
+
if (cursor.kind !== "search" && cursor.query === void 0) return void 0;
|
|
3396
|
+
if (cursor.queryMode === "fts") return void 0;
|
|
3397
|
+
const provider = await createConfiguredEmbeddingProvider();
|
|
3398
|
+
if (cursor.queryMode === "embedding" && provider === void 0) {
|
|
3399
|
+
throw new Error(
|
|
3400
|
+
"Embedding query mode requires embeddings configuration at `wikg://local/config/embeddings`."
|
|
3401
|
+
);
|
|
3402
|
+
}
|
|
3403
|
+
return provider;
|
|
3404
|
+
}
|
|
3281
3405
|
function requireTargetUri(context, label) {
|
|
3282
3406
|
if (context.targetUri !== void 0) return context.targetUri;
|
|
3283
3407
|
throw new Error(`${label} continuation cursors require a target URI.`);
|
|
@@ -3318,7 +3442,10 @@ import {
|
|
|
3318
3442
|
import { createDefaultWikiGraphSampling } from "wiki-graph-core";
|
|
3319
3443
|
import { LLM } from "wiki-graph-core";
|
|
3320
3444
|
function createStageLLM(config, options) {
|
|
3321
|
-
const llmOptions = buildWikiGraphLLMOptions(config)
|
|
3445
|
+
const llmOptions = options?.provider === void 0 ? buildWikiGraphLLMOptions(config) : {
|
|
3446
|
+
...config.concurrent?.request === void 0 ? {} : { concurrent: config.concurrent.request },
|
|
3447
|
+
streamProvider: options.provider
|
|
3448
|
+
};
|
|
3322
3449
|
return new LLM({
|
|
3323
3450
|
sampling: createDefaultWikiGraphSampling({
|
|
3324
3451
|
...llmOptions.temperature === void 0 ? {} : { temperature: llmOptions.temperature },
|
|
@@ -3332,10 +3459,13 @@ function createStageLLM(config, options) {
|
|
|
3332
3459
|
});
|
|
3333
3460
|
}
|
|
3334
3461
|
async function loadRequiredStageConfig(options) {
|
|
3462
|
+
const injected = options.llmJSON === void 0 ? getWikiGraphSDKProviders().llm : void 0;
|
|
3335
3463
|
const config = await loadWikiGraphRuntimeConfig({
|
|
3336
|
-
...options.llmJSON === void 0 ? {} : { llmJSON: options.llmJSON }
|
|
3464
|
+
...options.llmJSON === void 0 ? {} : { llmJSON: options.llmJSON },
|
|
3465
|
+
...options.llmJSON === void 0 && injected !== void 0 ? { skipLLMConfig: true } : {},
|
|
3466
|
+
...getWikiGraphSDKProviders().embedding === void 0 ? {} : { skipEmbeddingConfig: true }
|
|
3337
3467
|
});
|
|
3338
|
-
if (config.llm?.provider === void 0 || config.llm.model === void 0) {
|
|
3468
|
+
if (injected === void 0 && (config.llm?.provider === void 0 || config.llm.model === void 0)) {
|
|
3339
3469
|
throw new Error(
|
|
3340
3470
|
"Missing LLM configuration. Set --llm for one run, or configure `wikg://local/config/llm` with provider and model."
|
|
3341
3471
|
);
|
|
@@ -3478,23 +3608,59 @@ import {
|
|
|
3478
3608
|
resolveChapterPathReadonly as resolveChapterPathReadonly2,
|
|
3479
3609
|
WikiGraphArchiveFile as WikiGraphArchiveFile4
|
|
3480
3610
|
} from "wiki-graph-core";
|
|
3611
|
+
|
|
3612
|
+
// src/host.ts
|
|
3613
|
+
import {
|
|
3614
|
+
installWikiGraphPlatform as installWikiGraphPlatform2,
|
|
3615
|
+
withWikiGraphStorage as withWikiGraphStorage2
|
|
3616
|
+
} from "wiki-graph-core/platform";
|
|
3617
|
+
function prepareWikiGraphSDKHost(host) {
|
|
3618
|
+
if (host?.platform === void 0) {
|
|
3619
|
+
ensureNodeWikiGraphPlatform();
|
|
3620
|
+
return;
|
|
3621
|
+
}
|
|
3622
|
+
installWikiGraphPlatform2(host.platform);
|
|
3623
|
+
}
|
|
3624
|
+
function assertWikiGraphSDKHostOptions(options) {
|
|
3625
|
+
if (options.host?.storage !== void 0 && options.stateDir !== void 0) {
|
|
3626
|
+
throw new TypeError(
|
|
3627
|
+
"Wiki Graph SDK host.storage and stateDir cannot be used together."
|
|
3628
|
+
);
|
|
3629
|
+
}
|
|
3630
|
+
}
|
|
3631
|
+
async function withWikiGraphSDKHost(options, operation) {
|
|
3632
|
+
assertWikiGraphSDKHostOptions(options);
|
|
3633
|
+
prepareWikiGraphSDKHost(options.host);
|
|
3634
|
+
if (options.host?.storage !== void 0) {
|
|
3635
|
+
return await withWikiGraphStorage2(options.host.storage, operation);
|
|
3636
|
+
}
|
|
3637
|
+
return await withNodeWikiGraphStorage(options.stateDir, operation);
|
|
3638
|
+
}
|
|
3639
|
+
|
|
3640
|
+
// src/worker.ts
|
|
3481
3641
|
import {
|
|
3482
3642
|
applyChapterJobArtifactFile as applyChapterJobArtifactFile2,
|
|
3483
3643
|
createLocalChapterJobFileExecutor,
|
|
3484
3644
|
writeChapterJobInputFile as writeChapterJobInputFile2
|
|
3485
3645
|
} from "wiki-graph-core/worker";
|
|
3486
3646
|
async function runBuildJobWorker(options) {
|
|
3487
|
-
|
|
3488
|
-
|
|
3489
|
-
|
|
3490
|
-
|
|
3647
|
+
const { host, stateDir, ...coreOptions } = options;
|
|
3648
|
+
await withWikiGraphSDKHost(
|
|
3649
|
+
{
|
|
3650
|
+
...host === void 0 ? {} : { host },
|
|
3651
|
+
...stateDir === void 0 ? {} : { stateDir }
|
|
3652
|
+
},
|
|
3491
3653
|
async () => await runCoreBuildJobWorker(coreOptions)
|
|
3492
3654
|
);
|
|
3493
3655
|
}
|
|
3494
3656
|
|
|
3495
3657
|
// src/default-worker.ts
|
|
3496
3658
|
async function runWikiGraphQueueWorker(options = {}) {
|
|
3497
|
-
const
|
|
3659
|
+
const providers = getWikiGraphSDKProviders();
|
|
3660
|
+
const config = await loadWikiGraphRuntimeConfig({
|
|
3661
|
+
...providers.embedding === void 0 ? {} : { skipEmbeddingConfig: true },
|
|
3662
|
+
...providers.llm === void 0 ? {} : { skipLLMConfig: true }
|
|
3663
|
+
});
|
|
3498
3664
|
await runBuildJobWorker({
|
|
3499
3665
|
concurrency: config.concurrent?.job ?? DEFAULT_GENERATION_JOB_CONCURRENCY,
|
|
3500
3666
|
executeJob: async (job, reporter, context) => {
|
|
@@ -3503,12 +3669,16 @@ async function runWikiGraphQueueWorker(options = {}) {
|
|
|
3503
3669
|
async () => await executeBuildJob(job, reporter, context)
|
|
3504
3670
|
);
|
|
3505
3671
|
},
|
|
3672
|
+
...options.idleTimeoutMs === void 0 ? {} : { idleTimeoutMs: options.idleTimeoutMs },
|
|
3506
3673
|
...options.signal === void 0 ? {} : { signal: options.signal }
|
|
3507
3674
|
});
|
|
3508
3675
|
}
|
|
3509
3676
|
async function executeBuildJob(job, reporter, context) {
|
|
3677
|
+
const providers = getWikiGraphSDKProviders();
|
|
3510
3678
|
const config = await loadWikiGraphRuntimeConfig({
|
|
3511
|
-
...job.llmJSON === void 0 ? {} : { llmJSON: job.llmJSON }
|
|
3679
|
+
...job.llmJSON === void 0 ? {} : { llmJSON: job.llmJSON },
|
|
3680
|
+
...providers.embedding === void 0 ? {} : { skipEmbeddingConfig: true },
|
|
3681
|
+
...job.llmJSON === void 0 && providers.llm !== void 0 ? { skipLLMConfig: true } : {}
|
|
3512
3682
|
});
|
|
3513
3683
|
const execution = await openJobExecutor(
|
|
3514
3684
|
job,
|
|
@@ -3643,12 +3813,17 @@ async function openJobExecutor(job, config, signal, reporter) {
|
|
|
3643
3813
|
const stageConfig = generation ? await loadRequiredStageConfig({
|
|
3644
3814
|
...job.llmJSON === void 0 ? {} : { llmJSON: job.llmJSON }
|
|
3645
3815
|
}) : void 0;
|
|
3816
|
+
const injectedLLM = job.llmJSON === void 0 ? getWikiGraphSDKProviders().llm : void 0;
|
|
3646
3817
|
const llm = stageConfig === void 0 ? void 0 : createStageLLM(stageConfig, {
|
|
3647
3818
|
cacheDirectory: job.cache,
|
|
3648
3819
|
logDirectory: job.log,
|
|
3649
3820
|
onTokenUsage: async (usage) => {
|
|
3650
3821
|
await reporter.addTokenUsage(usage);
|
|
3651
|
-
}
|
|
3822
|
+
},
|
|
3823
|
+
onStreamProgress: async ({ outputCharacters }) => {
|
|
3824
|
+
await reporter.addOutputCharacters(outputCharacters);
|
|
3825
|
+
},
|
|
3826
|
+
...injectedLLM === void 0 ? {} : { provider: injectedLLM }
|
|
3652
3827
|
});
|
|
3653
3828
|
const promptSource = job.prompt ?? stageConfig?.prompt;
|
|
3654
3829
|
const wikispine = job.target === "knowledge-graph" ? requireKnowledgeGraphWikispineConfig(config) : void 0;
|
|
@@ -3669,7 +3844,7 @@ async function openJobExecutor(job, config, signal, reporter) {
|
|
|
3669
3844
|
"Local Wikimedia resolution requires an LLM."
|
|
3670
3845
|
),
|
|
3671
3846
|
llmModelId: requireValue(
|
|
3672
|
-
stageConfig?.llm?.model,
|
|
3847
|
+
stageConfig?.llm?.model ?? injectedLLM?.model,
|
|
3673
3848
|
"Local Wikimedia resolution requires an LLM model."
|
|
3674
3849
|
)
|
|
3675
3850
|
} : {
|
|
@@ -3678,7 +3853,7 @@ async function openJobExecutor(job, config, signal, reporter) {
|
|
|
3678
3853
|
token: config.wikimedia.token
|
|
3679
3854
|
}
|
|
3680
3855
|
);
|
|
3681
|
-
const embeddingProvider = job.target === "index-embedding-source" || job.target === "index-embedding-summary" ? buildSearchIndexEmbeddingProvider(requireEmbeddingConfig(config)) : void 0;
|
|
3856
|
+
const embeddingProvider = job.target === "index-embedding-source" || job.target === "index-embedding-summary" ? getWikiGraphSDKProviders().embedding ?? buildSearchIndexEmbeddingProvider(requireEmbeddingConfig(config)) : void 0;
|
|
3682
3857
|
return {
|
|
3683
3858
|
async close() {
|
|
3684
3859
|
await wikimediaResolver?.close();
|
|
@@ -3888,6 +4063,12 @@ var WikiGraphJobManager = class {
|
|
|
3888
4063
|
async clean() {
|
|
3889
4064
|
return await this.#runtime.run(async () => await cleanBuildJobs());
|
|
3890
4065
|
}
|
|
4066
|
+
async runWorker(options = {}) {
|
|
4067
|
+
await this.#runtime.run(
|
|
4068
|
+
async () => await runWikiGraphQueueWorker(options),
|
|
4069
|
+
options.signal
|
|
4070
|
+
);
|
|
4071
|
+
}
|
|
3891
4072
|
async get(jobId) {
|
|
3892
4073
|
return await this.#runtime.run(
|
|
3893
4074
|
async () => await this.#createHandle(await this.#backend.get(jobId))
|
|
@@ -3963,12 +4144,13 @@ var WikiGraphJobManager = class {
|
|
|
3963
4144
|
}
|
|
3964
4145
|
async enqueue(options) {
|
|
3965
4146
|
return await this.#runtime.run(async () => {
|
|
4147
|
+
const llmJSON = resolveWikiGraphLLMJSON(options);
|
|
3966
4148
|
const location = await resolveWikiGraphArchiveLocation(options.archive);
|
|
3967
4149
|
return await withArchiveBuildJobCreationLock(
|
|
3968
4150
|
location.archiveFile,
|
|
3969
4151
|
async () => {
|
|
3970
4152
|
const target = options.target ?? "reading-summary";
|
|
3971
|
-
await validateQueueTargetConfig(target,
|
|
4153
|
+
await validateQueueTargetConfig(target, llmJSON);
|
|
3972
4154
|
const selectedExplicitly = options.chapterId !== void 0 || options.chapterIds !== void 0 || options.chapterPath !== void 0 || options.depth !== void 0;
|
|
3973
4155
|
const candidates = await new WikiGraphArchiveFile6(
|
|
3974
4156
|
location.archiveFile
|
|
@@ -4018,7 +4200,7 @@ var WikiGraphJobManager = class {
|
|
|
4018
4200
|
archive: location.archiveFile,
|
|
4019
4201
|
boost: options.boost ?? false,
|
|
4020
4202
|
chapterId: candidate.chapter.chapterId,
|
|
4021
|
-
...
|
|
4203
|
+
...llmJSON === void 0 ? {} : { llmJSON },
|
|
4022
4204
|
...options.prompt === void 0 ? {} : { prompt: options.prompt },
|
|
4023
4205
|
target
|
|
4024
4206
|
}),
|
|
@@ -4040,9 +4222,10 @@ var WikiGraphJobManager = class {
|
|
|
4040
4222
|
}
|
|
4041
4223
|
async planEnqueue(options) {
|
|
4042
4224
|
return await this.#runtime.run(async () => {
|
|
4225
|
+
const llmJSON = resolveWikiGraphLLMJSON(options);
|
|
4043
4226
|
const location = await resolveWikiGraphArchiveLocation(options.archive);
|
|
4044
4227
|
const target = options.target ?? "reading-summary";
|
|
4045
|
-
await validateQueueTargetConfig(target,
|
|
4228
|
+
await validateQueueTargetConfig(target, llmJSON);
|
|
4046
4229
|
const selectedExplicitly = options.chapterId !== void 0 || options.chapterIds !== void 0 || options.chapterPath !== void 0 || options.depth !== void 0;
|
|
4047
4230
|
const candidates = await new WikiGraphArchiveFile6(
|
|
4048
4231
|
location.archiveFile
|
|
@@ -4287,12 +4470,15 @@ async function selectQueueChapters(document, chapters, options) {
|
|
|
4287
4470
|
);
|
|
4288
4471
|
}
|
|
4289
4472
|
async function validateQueueTargetConfig(target, llmJSON) {
|
|
4473
|
+
const providers = getWikiGraphSDKProviders();
|
|
4290
4474
|
const config = target === "knowledge-graph" || target === "reading-graph" || target === "reading-summary" ? await loadRequiredStageConfig({
|
|
4291
4475
|
...llmJSON === void 0 ? {} : { llmJSON }
|
|
4292
4476
|
}) : await loadWikiGraphRuntimeConfig({
|
|
4293
|
-
...llmJSON === void 0 ? {} : { llmJSON }
|
|
4477
|
+
...llmJSON === void 0 ? {} : { llmJSON },
|
|
4478
|
+
...providers.embedding === void 0 ? {} : { skipEmbeddingConfig: true },
|
|
4479
|
+
...llmJSON === void 0 && providers.llm !== void 0 ? { skipLLMConfig: true } : {}
|
|
4294
4480
|
});
|
|
4295
|
-
if ((target === "index-embedding-source" || target === "index-embedding-summary") && config.embedding === void 0) {
|
|
4481
|
+
if ((target === "index-embedding-source" || target === "index-embedding-summary") && config.embedding === void 0 && providers.embedding === void 0) {
|
|
4296
4482
|
throw new Error(
|
|
4297
4483
|
"Missing embeddings configuration. Configure `wikg://local/config/embeddings` before queueing embedding index artifact jobs."
|
|
4298
4484
|
);
|
|
@@ -4401,9 +4587,20 @@ import {
|
|
|
4401
4587
|
replaceWikiGraphLibraryArchive,
|
|
4402
4588
|
replaceWikiGraphLibraryMetadata,
|
|
4403
4589
|
resolveWikiGraphLibrary as resolveWikiGraphLibrary2,
|
|
4404
|
-
scanWikiGraphLibrary
|
|
4590
|
+
scanWikiGraphLibrary,
|
|
4591
|
+
withWikiGraphLibraryLock
|
|
4405
4592
|
} from "wiki-graph-core";
|
|
4406
4593
|
import { mkdir as mkdir2 } from "fs/promises";
|
|
4594
|
+
async function resolveQueryEmbeddingProvider(queryMode) {
|
|
4595
|
+
if (queryMode === "fts") return void 0;
|
|
4596
|
+
const provider = await createConfiguredEmbeddingProvider();
|
|
4597
|
+
if (queryMode === "embedding" && provider === void 0) {
|
|
4598
|
+
throw new Error(
|
|
4599
|
+
"Embedding query mode requires embeddings configuration at `wikg://local/config/embeddings`."
|
|
4600
|
+
);
|
|
4601
|
+
}
|
|
4602
|
+
return provider;
|
|
4603
|
+
}
|
|
4407
4604
|
var WikiGraphLibraryManager = class {
|
|
4408
4605
|
#runtime;
|
|
4409
4606
|
constructor(runtime) {
|
|
@@ -4473,6 +4670,43 @@ var WikiGraphLibraryManager = class {
|
|
|
4473
4670
|
)
|
|
4474
4671
|
);
|
|
4475
4672
|
}
|
|
4673
|
+
async readArchive(target, consume, options = {}) {
|
|
4674
|
+
return await this.#runtime.run(async () => {
|
|
4675
|
+
const parsedTarget = requireLibraryArchiveTarget(target);
|
|
4676
|
+
const library = await resolveWikiGraphLibrary2(parsedTarget);
|
|
4677
|
+
return await withWikiGraphLibraryLock(
|
|
4678
|
+
library.id,
|
|
4679
|
+
"read",
|
|
4680
|
+
async () => {
|
|
4681
|
+
throwIfAborted(options.signal);
|
|
4682
|
+
const archive = await getWikiGraphLibraryArchive(parsedTarget);
|
|
4683
|
+
const file = requireReadableLibraryArchiveFile(archive);
|
|
4684
|
+
const reader = await file.openReader();
|
|
4685
|
+
let active = true;
|
|
4686
|
+
try {
|
|
4687
|
+
const content = {
|
|
4688
|
+
mediaType: "application/vnd.wiki-graph.archive",
|
|
4689
|
+
size: reader.size,
|
|
4690
|
+
stream: createCallbackScopedArchiveStream(
|
|
4691
|
+
reader,
|
|
4692
|
+
() => active,
|
|
4693
|
+
options.signal
|
|
4694
|
+
),
|
|
4695
|
+
uri: archive.uri
|
|
4696
|
+
};
|
|
4697
|
+
return await runAbortableCallback(
|
|
4698
|
+
async () => await consume(content),
|
|
4699
|
+
options.signal
|
|
4700
|
+
);
|
|
4701
|
+
} finally {
|
|
4702
|
+
active = false;
|
|
4703
|
+
await reader.close();
|
|
4704
|
+
}
|
|
4705
|
+
},
|
|
4706
|
+
options.signal === void 0 ? {} : { signal: options.signal }
|
|
4707
|
+
);
|
|
4708
|
+
}, options.signal);
|
|
4709
|
+
}
|
|
4476
4710
|
async moveArchive(options) {
|
|
4477
4711
|
return toArchiveSnapshot(
|
|
4478
4712
|
await this.#runtime.run(
|
|
@@ -4562,7 +4796,9 @@ var WikiGraphLibraryManager = class {
|
|
|
4562
4796
|
}
|
|
4563
4797
|
async search(target, query, options = {}) {
|
|
4564
4798
|
return await this.#runtime.run(async () => {
|
|
4565
|
-
const embeddingProvider = await
|
|
4799
|
+
const embeddingProvider = await resolveQueryEmbeddingProvider(
|
|
4800
|
+
options.queryMode
|
|
4801
|
+
);
|
|
4566
4802
|
return await findWikiGraphLibraryObjects2(
|
|
4567
4803
|
requireLibraryTarget(target),
|
|
4568
4804
|
query,
|
|
@@ -4575,7 +4811,9 @@ var WikiGraphLibraryManager = class {
|
|
|
4575
4811
|
}
|
|
4576
4812
|
async searchArchiveMembers(target, query, options = {}) {
|
|
4577
4813
|
return await this.#runtime.run(async () => {
|
|
4578
|
-
const embeddingProvider = await
|
|
4814
|
+
const embeddingProvider = await resolveQueryEmbeddingProvider(
|
|
4815
|
+
options.queryMode
|
|
4816
|
+
);
|
|
4579
4817
|
return await findWikiGraphLibraryArchiveMembers2(
|
|
4580
4818
|
requireLibraryTarget(target),
|
|
4581
4819
|
query,
|
|
@@ -4616,22 +4854,36 @@ var WikiGraphLibraryManager = class {
|
|
|
4616
4854
|
);
|
|
4617
4855
|
}
|
|
4618
4856
|
async related(target, objectUri, options = {}) {
|
|
4619
|
-
return await this.#runtime.run(
|
|
4620
|
-
|
|
4857
|
+
return await this.#runtime.run(async () => {
|
|
4858
|
+
if (options.query === void 0 && options.queryMode !== void 0) {
|
|
4859
|
+
throw new Error("`queryMode` requires `query`.");
|
|
4860
|
+
}
|
|
4861
|
+
const embeddingProvider = options.query === void 0 ? void 0 : await resolveQueryEmbeddingProvider(options.queryMode);
|
|
4862
|
+
return await listRelatedWikiGraphLibraryObjects2(
|
|
4621
4863
|
requireLibraryTarget(target),
|
|
4622
4864
|
objectUri,
|
|
4623
|
-
|
|
4624
|
-
|
|
4625
|
-
|
|
4865
|
+
{
|
|
4866
|
+
...options,
|
|
4867
|
+
...embeddingProvider === void 0 ? {} : { embeddingProvider }
|
|
4868
|
+
}
|
|
4869
|
+
);
|
|
4870
|
+
});
|
|
4626
4871
|
}
|
|
4627
4872
|
async evidence(target, objectUri, options = {}) {
|
|
4628
|
-
return await this.#runtime.run(
|
|
4629
|
-
|
|
4873
|
+
return await this.#runtime.run(async () => {
|
|
4874
|
+
if (options.query === void 0 && options.queryMode !== void 0) {
|
|
4875
|
+
throw new Error("`queryMode` requires `query`.");
|
|
4876
|
+
}
|
|
4877
|
+
const embeddingProvider = options.query === void 0 ? void 0 : await resolveQueryEmbeddingProvider(options.queryMode);
|
|
4878
|
+
return await listWikiGraphLibraryEvidence2(
|
|
4630
4879
|
requireLibraryTarget(target),
|
|
4631
4880
|
objectUri,
|
|
4632
|
-
|
|
4633
|
-
|
|
4634
|
-
|
|
4881
|
+
{
|
|
4882
|
+
...options,
|
|
4883
|
+
...embeddingProvider === void 0 ? {} : { embeddingProvider }
|
|
4884
|
+
}
|
|
4885
|
+
);
|
|
4886
|
+
});
|
|
4635
4887
|
}
|
|
4636
4888
|
async pack(target, objectUri, budget = 5e3) {
|
|
4637
4889
|
return await this.#runtime.run(
|
|
@@ -4713,6 +4965,97 @@ function requireLibraryTarget(value) {
|
|
|
4713
4965
|
}
|
|
4714
4966
|
return target;
|
|
4715
4967
|
}
|
|
4968
|
+
function requireLibraryArchiveTarget(value) {
|
|
4969
|
+
const target = requireLibraryTarget(value);
|
|
4970
|
+
if (target.kind !== "archive" || target.archivePublicId === void 0 || target.objectUri !== void 0) {
|
|
4971
|
+
throw new TypeError("Expected a Wiki Graph library archive URI.");
|
|
4972
|
+
}
|
|
4973
|
+
return target;
|
|
4974
|
+
}
|
|
4975
|
+
function requireReadableLibraryArchiveFile(archive) {
|
|
4976
|
+
if (!archive.exists || archive.status === "missing") {
|
|
4977
|
+
throw new Error(`Wiki Graph library archive is missing: ${archive.uri}`);
|
|
4978
|
+
}
|
|
4979
|
+
if (archive.status === "conflict") {
|
|
4980
|
+
throw new Error(
|
|
4981
|
+
`Wiki Graph library archive has a conflict and cannot be read: ${archive.uri}`
|
|
4982
|
+
);
|
|
4983
|
+
}
|
|
4984
|
+
if (archive.file === void 0) {
|
|
4985
|
+
throw new Error(
|
|
4986
|
+
`Wiki Graph library archive is unavailable: ${archive.uri}`
|
|
4987
|
+
);
|
|
4988
|
+
}
|
|
4989
|
+
return archive.file;
|
|
4990
|
+
}
|
|
4991
|
+
var ARCHIVE_STREAM_CHUNK_SIZE = 64 * 1024;
|
|
4992
|
+
function createCallbackScopedArchiveStream(reader, isActive, signal) {
|
|
4993
|
+
let consumed = false;
|
|
4994
|
+
return {
|
|
4995
|
+
[Symbol.asyncIterator]() {
|
|
4996
|
+
assertArchiveReadSessionActive(isActive, signal);
|
|
4997
|
+
if (consumed) {
|
|
4998
|
+
throw new Error(
|
|
4999
|
+
"The library archive stream has already been consumed."
|
|
5000
|
+
);
|
|
5001
|
+
}
|
|
5002
|
+
consumed = true;
|
|
5003
|
+
let offset = 0;
|
|
5004
|
+
let finished = false;
|
|
5005
|
+
return {
|
|
5006
|
+
async next() {
|
|
5007
|
+
if (finished) return { done: true, value: void 0 };
|
|
5008
|
+
assertArchiveReadSessionActive(isActive, signal);
|
|
5009
|
+
if (offset >= reader.size) {
|
|
5010
|
+
finished = true;
|
|
5011
|
+
return { done: true, value: void 0 };
|
|
5012
|
+
}
|
|
5013
|
+
const length = Math.min(
|
|
5014
|
+
ARCHIVE_STREAM_CHUNK_SIZE,
|
|
5015
|
+
reader.size - offset
|
|
5016
|
+
);
|
|
5017
|
+
const chunk = await reader.read(offset, length);
|
|
5018
|
+
assertArchiveReadSessionActive(isActive, signal);
|
|
5019
|
+
offset += chunk.byteLength;
|
|
5020
|
+
return { done: false, value: chunk };
|
|
5021
|
+
},
|
|
5022
|
+
return() {
|
|
5023
|
+
finished = true;
|
|
5024
|
+
return Promise.resolve({ done: true, value: void 0 });
|
|
5025
|
+
}
|
|
5026
|
+
};
|
|
5027
|
+
}
|
|
5028
|
+
};
|
|
5029
|
+
}
|
|
5030
|
+
function assertArchiveReadSessionActive(isActive, signal) {
|
|
5031
|
+
if (!isActive()) {
|
|
5032
|
+
throw new Error(
|
|
5033
|
+
"The library archive stream cannot be read after its callback has finished."
|
|
5034
|
+
);
|
|
5035
|
+
}
|
|
5036
|
+
throwIfAborted(signal);
|
|
5037
|
+
}
|
|
5038
|
+
async function runAbortableCallback(operation, signal) {
|
|
5039
|
+
if (signal === void 0) return await operation();
|
|
5040
|
+
throwIfAborted(signal);
|
|
5041
|
+
let rejectAbort;
|
|
5042
|
+
const aborted = new Promise((_resolve, reject) => {
|
|
5043
|
+
rejectAbort = reject;
|
|
5044
|
+
});
|
|
5045
|
+
const onAbort = () => rejectAbort(abortReason(signal));
|
|
5046
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
5047
|
+
try {
|
|
5048
|
+
return await Promise.race([operation(), aborted]);
|
|
5049
|
+
} finally {
|
|
5050
|
+
signal.removeEventListener("abort", onAbort);
|
|
5051
|
+
}
|
|
5052
|
+
}
|
|
5053
|
+
function throwIfAborted(signal) {
|
|
5054
|
+
if (signal?.aborted === true) throw abortReason(signal);
|
|
5055
|
+
}
|
|
5056
|
+
function abortReason(signal) {
|
|
5057
|
+
return signal.reason ?? new DOMException("The operation was aborted.", "AbortError");
|
|
5058
|
+
}
|
|
4716
5059
|
|
|
4717
5060
|
// src/maintenance.ts
|
|
4718
5061
|
import {
|
|
@@ -4786,11 +5129,14 @@ var WikiGraphSDK = class {
|
|
|
4786
5129
|
libraries;
|
|
4787
5130
|
maintenance;
|
|
4788
5131
|
constructor(options = {}) {
|
|
4789
|
-
|
|
5132
|
+
assertWikiGraphSDKHostOptions(options);
|
|
5133
|
+
prepareWikiGraphSDKHost(options.host);
|
|
4790
5134
|
this.#context = {
|
|
4791
5135
|
cwd: options.cwd ?? process.cwd(),
|
|
4792
5136
|
env: { ...process.env, ...options.env },
|
|
4793
5137
|
envPolicy: options.envPolicy ?? "production",
|
|
5138
|
+
...options.host === void 0 ? {} : { host: options.host },
|
|
5139
|
+
providers: { ...options.providers },
|
|
4794
5140
|
...options.stateDir === void 0 ? {} : { stateDir: options.stateDir }
|
|
4795
5141
|
};
|
|
4796
5142
|
this.archives = new WikiGraphArchiveManager(this);
|
|
@@ -4802,7 +5148,7 @@ var WikiGraphSDK = class {
|
|
|
4802
5148
|
this.maintenance = new WikiGraphMaintenanceManager(this);
|
|
4803
5149
|
}
|
|
4804
5150
|
async run(operation, signal, options = {}) {
|
|
4805
|
-
|
|
5151
|
+
throwIfAborted2(signal);
|
|
4806
5152
|
const runWithContext = async () => await withWikiGraphSDKRuntimeContext(this.#context, async () => {
|
|
4807
5153
|
if (options.skipHomeBootstrap !== true) {
|
|
4808
5154
|
this.#homeReady ??= ensureWikiGraphHomeSchemaCurrent().catch(
|
|
@@ -4815,18 +5161,21 @@ var WikiGraphSDK = class {
|
|
|
4815
5161
|
}
|
|
4816
5162
|
return await operation();
|
|
4817
5163
|
});
|
|
4818
|
-
const result =
|
|
4819
|
-
|
|
5164
|
+
const result = await withWikiGraphSDKHost(
|
|
5165
|
+
{
|
|
5166
|
+
...this.#context.host === void 0 ? {} : { host: this.#context.host },
|
|
5167
|
+
...this.#context.stateDir === void 0 ? {} : { stateDir: this.#context.stateDir }
|
|
5168
|
+
},
|
|
4820
5169
|
runWithContext
|
|
4821
5170
|
);
|
|
4822
|
-
|
|
5171
|
+
throwIfAborted2(signal);
|
|
4823
5172
|
return result;
|
|
4824
5173
|
}
|
|
4825
5174
|
close() {
|
|
4826
5175
|
this.jobs.close();
|
|
4827
5176
|
}
|
|
4828
5177
|
};
|
|
4829
|
-
function
|
|
5178
|
+
function throwIfAborted2(signal) {
|
|
4830
5179
|
if (signal?.aborted !== true) return;
|
|
4831
5180
|
throw signal.reason instanceof Error ? signal.reason : new Error("The Wiki Graph SDK operation was aborted.");
|
|
4832
5181
|
}
|
|
@@ -4844,8 +5193,12 @@ import {
|
|
|
4844
5193
|
formatLocatedChapterSourceCollectionUri,
|
|
4845
5194
|
formatLocatedChapterUri as formatLocatedChapterUri3,
|
|
4846
5195
|
formatLocatedWikiGraphUri as formatLocatedWikiGraphUri3,
|
|
5196
|
+
formatSourceArtifactUri,
|
|
5197
|
+
formatSourceLocatorFragment,
|
|
4847
5198
|
formatWikiGraphCommandUri,
|
|
4848
5199
|
formatWikiGraphLibraryUri as formatWikiGraphLibraryUri3,
|
|
5200
|
+
isWikiGraphJobUri,
|
|
5201
|
+
isWikiGraphUri,
|
|
4849
5202
|
isSourceLocatorScopeUri as isSourceLocatorScopeUri2,
|
|
4850
5203
|
isWikiGraphLibraryUri,
|
|
4851
5204
|
parseChapterPath,
|
|
@@ -4853,8 +5206,12 @@ import {
|
|
|
4853
5206
|
parseChapterUriPath,
|
|
4854
5207
|
parseLocatedWikiGraphUri as parseLocatedWikiGraphUri3,
|
|
4855
5208
|
parseSourceTextJsonl,
|
|
5209
|
+
parseSourceLocatorFragment,
|
|
4856
5210
|
parseWikiGraphLibraryUri as parseWikiGraphLibraryUri4,
|
|
4857
|
-
parseWikiGraphUriSyntax
|
|
5211
|
+
parseWikiGraphUriSyntax,
|
|
5212
|
+
requireArchiveUri,
|
|
5213
|
+
requireLocatedObjectOrArchiveUri,
|
|
5214
|
+
requireLocatedObjectUri
|
|
4858
5215
|
} from "wiki-graph-core";
|
|
4859
5216
|
export {
|
|
4860
5217
|
DANGEROUS_RUNTIME_ENV_NAMES,
|
|
@@ -4887,6 +5244,7 @@ export {
|
|
|
4887
5244
|
createEntryRuntimeContext,
|
|
4888
5245
|
createGenerationPerformanceHints,
|
|
4889
5246
|
createNodeTemplateEnvironment,
|
|
5247
|
+
createNodeWikiGraphPlatform,
|
|
4890
5248
|
createNodeWikiGraphStorage,
|
|
4891
5249
|
createStageLLM,
|
|
4892
5250
|
createWikiGraphSDK,
|
|
@@ -4901,15 +5259,20 @@ export {
|
|
|
4901
5259
|
formatLocatedChapterSourceCollectionUri,
|
|
4902
5260
|
formatLocatedChapterUri3 as formatLocatedChapterUri,
|
|
4903
5261
|
formatLocatedWikiGraphUri3 as formatLocatedWikiGraphUri,
|
|
5262
|
+
formatSourceArtifactUri,
|
|
5263
|
+
formatSourceLocatorFragment,
|
|
4904
5264
|
formatWikiGraphCommandUri,
|
|
4905
5265
|
formatWikiGraphLibraryUri3 as formatWikiGraphLibraryUri,
|
|
4906
5266
|
getNodeResourcePath,
|
|
5267
|
+
getWikiGraphSDKProviders,
|
|
4907
5268
|
getWikiGraphSDKRuntimeContext,
|
|
4908
5269
|
getWikiGraphSDKStateDir,
|
|
4909
5270
|
inspectWikiGraphArchive,
|
|
4910
5271
|
installNodeWikiGraphPlatform,
|
|
4911
5272
|
isSourceLocatorScopeUri2 as isSourceLocatorScopeUri,
|
|
5273
|
+
isWikiGraphJobUri,
|
|
4912
5274
|
isWikiGraphLibraryUri,
|
|
5275
|
+
isWikiGraphUri,
|
|
4913
5276
|
loadRequiredStageConfig,
|
|
4914
5277
|
loadWikiGraphRuntimeConfig,
|
|
4915
5278
|
maskLocalConfigSection,
|
|
@@ -4921,6 +5284,7 @@ export {
|
|
|
4921
5284
|
parseChapterUriPath,
|
|
4922
5285
|
parseLocalConfigSection,
|
|
4923
5286
|
parseLocatedWikiGraphUri3 as parseLocatedWikiGraphUri,
|
|
5287
|
+
parseSourceLocatorFragment,
|
|
4924
5288
|
parseSourceTextJsonl,
|
|
4925
5289
|
parseWikiGraphLibraryUri4 as parseWikiGraphLibraryUri,
|
|
4926
5290
|
parseWikiGraphUriSyntax,
|
|
@@ -4929,10 +5293,14 @@ export {
|
|
|
4929
5293
|
readLocalConfigSection,
|
|
4930
5294
|
readWikiGraphEmbeddingConfig,
|
|
4931
5295
|
replaceLocalConfigSection,
|
|
5296
|
+
requireArchiveUri,
|
|
4932
5297
|
requireKnowledgeGraphWikispineConfig,
|
|
5298
|
+
requireLocatedObjectOrArchiveUri,
|
|
5299
|
+
requireLocatedObjectUri,
|
|
4933
5300
|
resolveExtractionPrompt,
|
|
4934
5301
|
resolveHostedProviderEndpoint,
|
|
4935
5302
|
resolveKnowledgeGraphRecallPrompt,
|
|
5303
|
+
resolveWikiGraphLLMJSON,
|
|
4936
5304
|
resolveWikispineConfig,
|
|
4937
5305
|
runWikiGraphQueueWorker,
|
|
4938
5306
|
validateLocalConfigSection,
|