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.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,
|
|
@@ -865,12 +866,16 @@ function getWikiGraphSDKRuntimeContext() {
|
|
|
865
866
|
return runtimeContext.getStore() ?? {
|
|
866
867
|
cwd: process.cwd(),
|
|
867
868
|
env: process.env,
|
|
868
|
-
envPolicy: "production"
|
|
869
|
+
envPolicy: "production",
|
|
870
|
+
providers: {}
|
|
869
871
|
};
|
|
870
872
|
}
|
|
871
873
|
function getWikiGraphSDKStateDir() {
|
|
872
874
|
return getWikiGraphSDKRuntimeContext().stateDir;
|
|
873
875
|
}
|
|
876
|
+
function getWikiGraphSDKProviders() {
|
|
877
|
+
return getWikiGraphSDKRuntimeContext().providers ?? {};
|
|
878
|
+
}
|
|
874
879
|
|
|
875
880
|
// src/local-config.ts
|
|
876
881
|
import { join as join2 } from "path";
|
|
@@ -1171,8 +1176,8 @@ var inlineLLMConfigSchema = z.object({
|
|
|
1171
1176
|
});
|
|
1172
1177
|
async function loadWikiGraphRuntimeConfig(options) {
|
|
1173
1178
|
const [embedding, localLLM, concurrent, wikimedia, wikispine] = await Promise.all([
|
|
1174
|
-
readLocalConfigSection("embeddings"),
|
|
1175
|
-
readLocalConfigSection("llm"),
|
|
1179
|
+
options?.skipEmbeddingConfig === true ? Promise.resolve({}) : readLocalConfigSection("embeddings"),
|
|
1180
|
+
options?.skipLLMConfig === true ? Promise.resolve({}) : readLocalConfigSection("llm"),
|
|
1176
1181
|
readLocalConfigSection("concurrent"),
|
|
1177
1182
|
readLocalConfigSection("wikimedia"),
|
|
1178
1183
|
readLocalConfigSection("wikispine")
|
|
@@ -1368,6 +1373,14 @@ function formatError2(error) {
|
|
|
1368
1373
|
return error instanceof Error ? error.message : String(error);
|
|
1369
1374
|
}
|
|
1370
1375
|
|
|
1376
|
+
// src/providers.ts
|
|
1377
|
+
function resolveWikiGraphLLMJSON(options) {
|
|
1378
|
+
if (options.llm !== void 0 && options.llmJSON !== void 0) {
|
|
1379
|
+
throw new Error("Pass either llm or llmJSON, not both.");
|
|
1380
|
+
}
|
|
1381
|
+
return options.llm === void 0 ? options.llmJSON : JSON.stringify(options.llm);
|
|
1382
|
+
}
|
|
1383
|
+
|
|
1371
1384
|
// src/runtime-path.ts
|
|
1372
1385
|
import { homedir as homedir3 } from "os";
|
|
1373
1386
|
import { isAbsolute as isAbsolute2, resolve as resolve2 } from "path";
|
|
@@ -1601,12 +1614,18 @@ var WikiGraphConversionManager = class {
|
|
|
1601
1614
|
}
|
|
1602
1615
|
const requiresDigest = options.input.format !== "wikg";
|
|
1603
1616
|
const requiresLLM = requiresDigest && targetStage !== "planned" && targetStage !== "sourced";
|
|
1617
|
+
const llmJSON = resolveWikiGraphLLMJSON(options);
|
|
1618
|
+
const injectedLLM = llmJSON === void 0 ? getWikiGraphSDKProviders().llm : void 0;
|
|
1604
1619
|
const config = await loadWikiGraphRuntimeConfig({
|
|
1605
|
-
...
|
|
1620
|
+
...llmJSON === void 0 ? {} : { llmJSON },
|
|
1621
|
+
...injectedLLM === void 0 ? {} : { skipLLMConfig: true },
|
|
1622
|
+
...getWikiGraphSDKProviders().embedding === void 0 ? {} : { skipEmbeddingConfig: true }
|
|
1606
1623
|
});
|
|
1607
1624
|
const app = new WikiGraph({
|
|
1608
1625
|
...options.verbose === true ? { verbose: true } : {},
|
|
1609
|
-
...requiresLLM ? {
|
|
1626
|
+
...requiresLLM ? {
|
|
1627
|
+
llm: injectedLLM === void 0 ? buildWikiGraphLLMOptions(config) : { streamProvider: injectedLLM }
|
|
1628
|
+
} : {}
|
|
1610
1629
|
});
|
|
1611
1630
|
const documentDirectory = await prepareDigestDirectory(
|
|
1612
1631
|
options.digestDirectory,
|
|
@@ -1921,6 +1940,8 @@ function createOpenAICompatibleName2(baseURL) {
|
|
|
1921
1940
|
|
|
1922
1941
|
// src/query-runtime.ts
|
|
1923
1942
|
async function createConfiguredEmbeddingProvider() {
|
|
1943
|
+
const injected = getWikiGraphSDKProviders().embedding;
|
|
1944
|
+
if (injected !== void 0) return injected;
|
|
1924
1945
|
const config = await readWikiGraphEmbeddingConfig();
|
|
1925
1946
|
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
1947
|
return void 0;
|
|
@@ -2172,13 +2193,15 @@ var WikiGraphArchiveHandle = class {
|
|
|
2172
2193
|
);
|
|
2173
2194
|
}
|
|
2174
2195
|
async search(query, options = {}) {
|
|
2175
|
-
const embeddingProvider = await this.#
|
|
2176
|
-
|
|
2196
|
+
const embeddingProvider = await this.#resolveQueryEmbeddingProvider(
|
|
2197
|
+
options.queryMode,
|
|
2177
2198
|
options.signal
|
|
2178
2199
|
);
|
|
2179
2200
|
return await this.#writeDocument(
|
|
2180
2201
|
async (document) => {
|
|
2181
|
-
const chapters = await this.#resolveQueryChapters(document, options
|
|
2202
|
+
const chapters = await this.#resolveQueryChapters(document, options, {
|
|
2203
|
+
embeddingProvider
|
|
2204
|
+
});
|
|
2182
2205
|
await ensureArchiveSearchIndex(document, {
|
|
2183
2206
|
...chapters === void 0 ? {} : { chapters },
|
|
2184
2207
|
...embeddingProvider === void 0 ? {} : { embeddingProvider }
|
|
@@ -2476,6 +2499,9 @@ var WikiGraphArchiveHandle = class {
|
|
|
2476
2499
|
}
|
|
2477
2500
|
async related(objectUri = this.objectUri, options = {}) {
|
|
2478
2501
|
if (options.query === void 0) {
|
|
2502
|
+
if (options.queryMode !== void 0) {
|
|
2503
|
+
throw new Error("`queryMode` requires `query`.");
|
|
2504
|
+
}
|
|
2479
2505
|
return await this.#readDocument(async (document) => {
|
|
2480
2506
|
const chapters = await this.#resolveScope(document, {});
|
|
2481
2507
|
return await listRelatedArchiveObjects(document, objectUri, {
|
|
@@ -2484,19 +2510,22 @@ var WikiGraphArchiveHandle = class {
|
|
|
2484
2510
|
});
|
|
2485
2511
|
}, options);
|
|
2486
2512
|
}
|
|
2487
|
-
const embeddingProvider = await this.#
|
|
2488
|
-
|
|
2513
|
+
const embeddingProvider = await this.#resolveQueryEmbeddingProvider(
|
|
2514
|
+
options.queryMode,
|
|
2489
2515
|
options.signal
|
|
2490
2516
|
);
|
|
2491
2517
|
return await this.#writeDocument(
|
|
2492
2518
|
async (document) => {
|
|
2493
|
-
const chapters = await this.#resolveQueryChapters(document, options
|
|
2519
|
+
const chapters = await this.#resolveQueryChapters(document, options, {
|
|
2520
|
+
embeddingProvider
|
|
2521
|
+
});
|
|
2494
2522
|
await ensureArchiveSearchIndex(document, {
|
|
2495
2523
|
...chapters === void 0 ? {} : { chapters },
|
|
2496
2524
|
...embeddingProvider === void 0 ? {} : { embeddingProvider }
|
|
2497
2525
|
});
|
|
2498
2526
|
return await listRelatedArchiveObjects(document, objectUri, {
|
|
2499
2527
|
...withoutOperation(options),
|
|
2528
|
+
...embeddingProvider === void 0 ? {} : { embeddingProvider },
|
|
2500
2529
|
...chapters === void 0 ? {} : { chapters }
|
|
2501
2530
|
});
|
|
2502
2531
|
},
|
|
@@ -2508,6 +2537,9 @@ var WikiGraphArchiveHandle = class {
|
|
|
2508
2537
|
}
|
|
2509
2538
|
async evidence(objectUri = this.objectUri, options = {}) {
|
|
2510
2539
|
if (options.query === void 0) {
|
|
2540
|
+
if (options.queryMode !== void 0) {
|
|
2541
|
+
throw new Error("`queryMode` requires `query`.");
|
|
2542
|
+
}
|
|
2511
2543
|
return await this.#readDocument(async (document) => {
|
|
2512
2544
|
const chapters = await this.#resolveScope(document, {});
|
|
2513
2545
|
return await listArchiveEvidence(document, objectUri, {
|
|
@@ -2516,19 +2548,22 @@ var WikiGraphArchiveHandle = class {
|
|
|
2516
2548
|
});
|
|
2517
2549
|
}, options);
|
|
2518
2550
|
}
|
|
2519
|
-
const embeddingProvider = await this.#
|
|
2520
|
-
|
|
2551
|
+
const embeddingProvider = await this.#resolveQueryEmbeddingProvider(
|
|
2552
|
+
options.queryMode,
|
|
2521
2553
|
options.signal
|
|
2522
2554
|
);
|
|
2523
2555
|
return await this.#writeDocument(
|
|
2524
2556
|
async (document) => {
|
|
2525
|
-
const chapters = await this.#resolveQueryChapters(document, options
|
|
2557
|
+
const chapters = await this.#resolveQueryChapters(document, options, {
|
|
2558
|
+
embeddingProvider
|
|
2559
|
+
});
|
|
2526
2560
|
await ensureArchiveSearchIndex(document, {
|
|
2527
2561
|
...chapters === void 0 ? {} : { chapters },
|
|
2528
2562
|
...embeddingProvider === void 0 ? {} : { embeddingProvider }
|
|
2529
2563
|
});
|
|
2530
2564
|
return await listArchiveEvidence(document, objectUri, {
|
|
2531
2565
|
...withoutOperation(options),
|
|
2566
|
+
...embeddingProvider === void 0 ? {} : { embeddingProvider },
|
|
2532
2567
|
...chapters === void 0 ? {} : { chapters }
|
|
2533
2568
|
});
|
|
2534
2569
|
},
|
|
@@ -2562,6 +2597,24 @@ var WikiGraphArchiveHandle = class {
|
|
|
2562
2597
|
return meta;
|
|
2563
2598
|
}, options);
|
|
2564
2599
|
}
|
|
2600
|
+
async setArchiveTitle(title, options = {}) {
|
|
2601
|
+
const normalized = title?.trim() ?? null;
|
|
2602
|
+
if (title !== null && normalized === "") {
|
|
2603
|
+
throw new Error("Archive title cannot be empty.");
|
|
2604
|
+
}
|
|
2605
|
+
return await this.#writeDocument(async (document) => {
|
|
2606
|
+
if (normalized === null) {
|
|
2607
|
+
await document.metadata.deleteKey("", "title");
|
|
2608
|
+
} else {
|
|
2609
|
+
await document.metadata.put(
|
|
2610
|
+
{ kind: ObjectMetadataKind.Archive, objectPath: "" },
|
|
2611
|
+
"title",
|
|
2612
|
+
normalized
|
|
2613
|
+
);
|
|
2614
|
+
}
|
|
2615
|
+
return normalized;
|
|
2616
|
+
}, options);
|
|
2617
|
+
}
|
|
2565
2618
|
async readCover(options = {}) {
|
|
2566
2619
|
const app = new WikiGraph2({});
|
|
2567
2620
|
return await this.#runtime.run(
|
|
@@ -2632,11 +2685,20 @@ var WikiGraphArchiveHandle = class {
|
|
|
2632
2685
|
if (options.chapters !== void 0) return options.chapters;
|
|
2633
2686
|
return (await resolveArchiveScope(document, this.objectUri, options.depth))?.chapterIds;
|
|
2634
2687
|
}
|
|
2635
|
-
async #resolveQueryChapters(document, options) {
|
|
2688
|
+
async #resolveQueryChapters(document, options, capabilities) {
|
|
2636
2689
|
const chapters = await this.#resolveScope(document, options);
|
|
2637
|
-
|
|
2690
|
+
const coverageOptions = {
|
|
2691
|
+
...chapters === void 0 ? {} : { chapters },
|
|
2692
|
+
...capabilities.embeddingProvider === void 0 ? {} : { embeddingProvider: capabilities.embeddingProvider },
|
|
2693
|
+
requireEmbeddingProvider: true,
|
|
2694
|
+
...options.queryMode === void 0 ? {} : { queryMode: options.queryMode }
|
|
2695
|
+
};
|
|
2696
|
+
if (options.skipUnindexed !== true) {
|
|
2697
|
+
await assertArchiveIndexArtifactsReady(document, coverageOptions);
|
|
2698
|
+
return chapters;
|
|
2699
|
+
}
|
|
2638
2700
|
const queryable = await listArchiveQueryableChapterIds(document, {
|
|
2639
|
-
...
|
|
2701
|
+
...coverageOptions
|
|
2640
2702
|
});
|
|
2641
2703
|
if (queryable.length === 0) {
|
|
2642
2704
|
throw new Error(
|
|
@@ -2645,6 +2707,19 @@ var WikiGraphArchiveHandle = class {
|
|
|
2645
2707
|
}
|
|
2646
2708
|
return queryable;
|
|
2647
2709
|
}
|
|
2710
|
+
async #resolveQueryEmbeddingProvider(queryMode, signal) {
|
|
2711
|
+
if (queryMode === "fts") return void 0;
|
|
2712
|
+
const provider = await this.#runtime.run(
|
|
2713
|
+
createConfiguredEmbeddingProvider,
|
|
2714
|
+
signal
|
|
2715
|
+
);
|
|
2716
|
+
if (queryMode === "embedding" && provider === void 0) {
|
|
2717
|
+
throw new Error(
|
|
2718
|
+
"Embedding query mode requires embeddings configuration at `wikg://local/config/embeddings`."
|
|
2719
|
+
);
|
|
2720
|
+
}
|
|
2721
|
+
return provider;
|
|
2722
|
+
}
|
|
2648
2723
|
};
|
|
2649
2724
|
async function ensureArchiveSearchIndex(document, options = {}) {
|
|
2650
2725
|
const scope = options.chapters === void 0 ? {} : { chapters: options.chapters };
|
|
@@ -3040,6 +3115,7 @@ var WikiGraphContinuationManager = class {
|
|
|
3040
3115
|
}
|
|
3041
3116
|
};
|
|
3042
3117
|
async function continueArchiveCursor(cursor, limit) {
|
|
3118
|
+
const embeddingProvider = cursor.kind === "evidence" || cursor.kind === "related" ? await resolveCursorEmbeddingProvider(cursor) : void 0;
|
|
3043
3119
|
const location = await resolveWikiGraphArchiveLocation(
|
|
3044
3120
|
archiveTargetFromLogicalLocator(getCursorArchivePath(cursor))
|
|
3045
3121
|
);
|
|
@@ -3069,6 +3145,8 @@ async function continueArchiveCursor(cursor, limit) {
|
|
|
3069
3145
|
limit,
|
|
3070
3146
|
order: cursor.order,
|
|
3071
3147
|
...cursor.query === void 0 ? {} : { query: cursor.query },
|
|
3148
|
+
...cursor.queryMode === void 0 ? {} : { queryMode: cursor.queryMode },
|
|
3149
|
+
...embeddingProvider === void 0 ? {} : { embeddingProvider },
|
|
3072
3150
|
...cursor.skipUnindexed === void 0 ? {} : { skipUnindexed: cursor.skipUnindexed },
|
|
3073
3151
|
...cursor.sourceContext === void 0 ? {} : { sourceContext: cursor.sourceContext }
|
|
3074
3152
|
});
|
|
@@ -3080,6 +3158,8 @@ async function continueArchiveCursor(cursor, limit) {
|
|
|
3080
3158
|
limit,
|
|
3081
3159
|
order: cursor.order,
|
|
3082
3160
|
...cursor.query === void 0 ? {} : { query: cursor.query },
|
|
3161
|
+
...cursor.queryMode === void 0 ? {} : { queryMode: cursor.queryMode },
|
|
3162
|
+
...embeddingProvider === void 0 ? {} : { embeddingProvider },
|
|
3083
3163
|
...cursor.role === void 0 ? {} : { role: cursor.role },
|
|
3084
3164
|
...cursor.skipUnindexed === void 0 ? {} : { skipUnindexed: cursor.skipUnindexed },
|
|
3085
3165
|
...cursor.sourceContext === void 0 ? {} : { sourceContext: cursor.sourceContext }
|
|
@@ -3089,6 +3169,7 @@ async function continueArchiveCursor(cursor, limit) {
|
|
|
3089
3169
|
);
|
|
3090
3170
|
}
|
|
3091
3171
|
async function continueLibraryCursor(cursor, limit) {
|
|
3172
|
+
const embeddingProvider = cursor.kind === "evidence" || cursor.kind === "related" ? await resolveCursorEmbeddingProvider(cursor) : void 0;
|
|
3092
3173
|
if (cursor.kind === "source-locators") {
|
|
3093
3174
|
throw new Error(
|
|
3094
3175
|
"Source locator cursors do not use the aggregate library index."
|
|
@@ -3125,6 +3206,8 @@ async function continueLibraryCursor(cursor, limit) {
|
|
|
3125
3206
|
limit,
|
|
3126
3207
|
order: cursor.order,
|
|
3127
3208
|
...cursor.query === void 0 ? {} : { query: cursor.query },
|
|
3209
|
+
...cursor.queryMode === void 0 ? {} : { queryMode: cursor.queryMode },
|
|
3210
|
+
...embeddingProvider === void 0 ? {} : { embeddingProvider },
|
|
3128
3211
|
...cursor.skipUnindexed === void 0 ? {} : { skipUnindexed: cursor.skipUnindexed },
|
|
3129
3212
|
...cursor.sourceContext === void 0 ? {} : { sourceContext: cursor.sourceContext }
|
|
3130
3213
|
});
|
|
@@ -3138,6 +3221,8 @@ async function continueLibraryCursor(cursor, limit) {
|
|
|
3138
3221
|
limit,
|
|
3139
3222
|
order: cursor.order,
|
|
3140
3223
|
...cursor.query === void 0 ? {} : { query: cursor.query },
|
|
3224
|
+
...cursor.queryMode === void 0 ? {} : { queryMode: cursor.queryMode },
|
|
3225
|
+
...embeddingProvider === void 0 ? {} : { embeddingProvider },
|
|
3141
3226
|
...cursor.role === void 0 ? {} : { role: cursor.role },
|
|
3142
3227
|
...cursor.skipUnindexed === void 0 ? {} : { skipUnindexed: cursor.skipUnindexed },
|
|
3143
3228
|
...cursor.sourceContext === void 0 ? {} : { sourceContext: cursor.sourceContext }
|
|
@@ -3162,7 +3247,7 @@ function createCollectionOptions(cursor, limit) {
|
|
|
3162
3247
|
};
|
|
3163
3248
|
}
|
|
3164
3249
|
async function createFindOptions(cursor, limit) {
|
|
3165
|
-
const embeddingProvider = await
|
|
3250
|
+
const embeddingProvider = await resolveCursorEmbeddingProvider(cursor);
|
|
3166
3251
|
return {
|
|
3167
3252
|
archiveKey: cursor.archiveKey,
|
|
3168
3253
|
...cursor.backlinks === void 0 ? {} : { backlinks: cursor.backlinks },
|
|
@@ -3170,6 +3255,7 @@ async function createFindOptions(cursor, limit) {
|
|
|
3170
3255
|
cursor: cursor.cursor,
|
|
3171
3256
|
...cursor.evidenceLimit === void 0 ? {} : { evidenceLimit: cursor.evidenceLimit },
|
|
3172
3257
|
limit,
|
|
3258
|
+
...cursor.queryMode === void 0 ? {} : { queryMode: cursor.queryMode },
|
|
3173
3259
|
...cursor.skipUnindexed === void 0 ? {} : { skipUnindexed: cursor.skipUnindexed },
|
|
3174
3260
|
...cursor.sourceContext === void 0 ? {} : { sourceContext: cursor.sourceContext },
|
|
3175
3261
|
...cursor.triplePattern === void 0 ? {} : { triplePattern: cursor.triplePattern },
|
|
@@ -3219,6 +3305,7 @@ function createContinuationPayload(context, cursor) {
|
|
|
3219
3305
|
kind: "evidence",
|
|
3220
3306
|
order: context.order ?? "doc-asc",
|
|
3221
3307
|
...context.query === void 0 ? {} : { query: context.query },
|
|
3308
|
+
...context.queryMode === void 0 ? {} : { queryMode: context.queryMode },
|
|
3222
3309
|
...context.skipUnindexed === void 0 ? {} : { skipUnindexed: context.skipUnindexed },
|
|
3223
3310
|
...context.sourceContext === void 0 ? {} : { sourceContext: context.sourceContext },
|
|
3224
3311
|
targetUri: requireTargetUri(context, "Evidence")
|
|
@@ -3235,6 +3322,7 @@ function createContinuationPayload(context, cursor) {
|
|
|
3235
3322
|
kind: "related",
|
|
3236
3323
|
order: context.order ?? "doc-asc",
|
|
3237
3324
|
...context.query === void 0 ? {} : { query: context.query },
|
|
3325
|
+
...context.queryMode === void 0 ? {} : { queryMode: context.queryMode },
|
|
3238
3326
|
...context.role === void 0 ? {} : { role: context.role },
|
|
3239
3327
|
...context.skipUnindexed === void 0 ? {} : { skipUnindexed: context.skipUnindexed },
|
|
3240
3328
|
...context.sourceContext === void 0 ? {} : { sourceContext: context.sourceContext },
|
|
@@ -3271,6 +3359,7 @@ function createContinuationPayload(context, cursor) {
|
|
|
3271
3359
|
kind: "search",
|
|
3272
3360
|
...createLibraryQueryPayload(context),
|
|
3273
3361
|
...context.query === void 0 ? {} : { query: context.query },
|
|
3362
|
+
...context.queryMode === void 0 ? {} : { queryMode: context.queryMode },
|
|
3274
3363
|
...context.skipUnindexed === void 0 ? {} : { skipUnindexed: context.skipUnindexed },
|
|
3275
3364
|
...context.sourceContext === void 0 ? {} : { sourceContext: context.sourceContext },
|
|
3276
3365
|
...context.triplePattern === void 0 ? {} : { triplePattern: context.triplePattern },
|
|
@@ -3278,6 +3367,17 @@ function createContinuationPayload(context, cursor) {
|
|
|
3278
3367
|
};
|
|
3279
3368
|
}
|
|
3280
3369
|
}
|
|
3370
|
+
async function resolveCursorEmbeddingProvider(cursor) {
|
|
3371
|
+
if (cursor.kind !== "search" && cursor.query === void 0) return void 0;
|
|
3372
|
+
if (cursor.queryMode === "fts") return void 0;
|
|
3373
|
+
const provider = await createConfiguredEmbeddingProvider();
|
|
3374
|
+
if (cursor.queryMode === "embedding" && provider === void 0) {
|
|
3375
|
+
throw new Error(
|
|
3376
|
+
"Embedding query mode requires embeddings configuration at `wikg://local/config/embeddings`."
|
|
3377
|
+
);
|
|
3378
|
+
}
|
|
3379
|
+
return provider;
|
|
3380
|
+
}
|
|
3281
3381
|
function requireTargetUri(context, label) {
|
|
3282
3382
|
if (context.targetUri !== void 0) return context.targetUri;
|
|
3283
3383
|
throw new Error(`${label} continuation cursors require a target URI.`);
|
|
@@ -3318,7 +3418,10 @@ import {
|
|
|
3318
3418
|
import { createDefaultWikiGraphSampling } from "wiki-graph-core";
|
|
3319
3419
|
import { LLM } from "wiki-graph-core";
|
|
3320
3420
|
function createStageLLM(config, options) {
|
|
3321
|
-
const llmOptions = buildWikiGraphLLMOptions(config)
|
|
3421
|
+
const llmOptions = options?.provider === void 0 ? buildWikiGraphLLMOptions(config) : {
|
|
3422
|
+
...config.concurrent?.request === void 0 ? {} : { concurrent: config.concurrent.request },
|
|
3423
|
+
streamProvider: options.provider
|
|
3424
|
+
};
|
|
3322
3425
|
return new LLM({
|
|
3323
3426
|
sampling: createDefaultWikiGraphSampling({
|
|
3324
3427
|
...llmOptions.temperature === void 0 ? {} : { temperature: llmOptions.temperature },
|
|
@@ -3332,10 +3435,13 @@ function createStageLLM(config, options) {
|
|
|
3332
3435
|
});
|
|
3333
3436
|
}
|
|
3334
3437
|
async function loadRequiredStageConfig(options) {
|
|
3438
|
+
const injected = options.llmJSON === void 0 ? getWikiGraphSDKProviders().llm : void 0;
|
|
3335
3439
|
const config = await loadWikiGraphRuntimeConfig({
|
|
3336
|
-
...options.llmJSON === void 0 ? {} : { llmJSON: options.llmJSON }
|
|
3440
|
+
...options.llmJSON === void 0 ? {} : { llmJSON: options.llmJSON },
|
|
3441
|
+
...options.llmJSON === void 0 && injected !== void 0 ? { skipLLMConfig: true } : {},
|
|
3442
|
+
...getWikiGraphSDKProviders().embedding === void 0 ? {} : { skipEmbeddingConfig: true }
|
|
3337
3443
|
});
|
|
3338
|
-
if (config.llm?.provider === void 0 || config.llm.model === void 0) {
|
|
3444
|
+
if (injected === void 0 && (config.llm?.provider === void 0 || config.llm.model === void 0)) {
|
|
3339
3445
|
throw new Error(
|
|
3340
3446
|
"Missing LLM configuration. Set --llm for one run, or configure `wikg://local/config/llm` with provider and model."
|
|
3341
3447
|
);
|
|
@@ -3494,7 +3600,11 @@ async function runBuildJobWorker(options) {
|
|
|
3494
3600
|
|
|
3495
3601
|
// src/default-worker.ts
|
|
3496
3602
|
async function runWikiGraphQueueWorker(options = {}) {
|
|
3497
|
-
const
|
|
3603
|
+
const providers = getWikiGraphSDKProviders();
|
|
3604
|
+
const config = await loadWikiGraphRuntimeConfig({
|
|
3605
|
+
...providers.embedding === void 0 ? {} : { skipEmbeddingConfig: true },
|
|
3606
|
+
...providers.llm === void 0 ? {} : { skipLLMConfig: true }
|
|
3607
|
+
});
|
|
3498
3608
|
await runBuildJobWorker({
|
|
3499
3609
|
concurrency: config.concurrent?.job ?? DEFAULT_GENERATION_JOB_CONCURRENCY,
|
|
3500
3610
|
executeJob: async (job, reporter, context) => {
|
|
@@ -3503,12 +3613,16 @@ async function runWikiGraphQueueWorker(options = {}) {
|
|
|
3503
3613
|
async () => await executeBuildJob(job, reporter, context)
|
|
3504
3614
|
);
|
|
3505
3615
|
},
|
|
3616
|
+
...options.idleTimeoutMs === void 0 ? {} : { idleTimeoutMs: options.idleTimeoutMs },
|
|
3506
3617
|
...options.signal === void 0 ? {} : { signal: options.signal }
|
|
3507
3618
|
});
|
|
3508
3619
|
}
|
|
3509
3620
|
async function executeBuildJob(job, reporter, context) {
|
|
3621
|
+
const providers = getWikiGraphSDKProviders();
|
|
3510
3622
|
const config = await loadWikiGraphRuntimeConfig({
|
|
3511
|
-
...job.llmJSON === void 0 ? {} : { llmJSON: job.llmJSON }
|
|
3623
|
+
...job.llmJSON === void 0 ? {} : { llmJSON: job.llmJSON },
|
|
3624
|
+
...providers.embedding === void 0 ? {} : { skipEmbeddingConfig: true },
|
|
3625
|
+
...job.llmJSON === void 0 && providers.llm !== void 0 ? { skipLLMConfig: true } : {}
|
|
3512
3626
|
});
|
|
3513
3627
|
const execution = await openJobExecutor(
|
|
3514
3628
|
job,
|
|
@@ -3643,12 +3757,17 @@ async function openJobExecutor(job, config, signal, reporter) {
|
|
|
3643
3757
|
const stageConfig = generation ? await loadRequiredStageConfig({
|
|
3644
3758
|
...job.llmJSON === void 0 ? {} : { llmJSON: job.llmJSON }
|
|
3645
3759
|
}) : void 0;
|
|
3760
|
+
const injectedLLM = job.llmJSON === void 0 ? getWikiGraphSDKProviders().llm : void 0;
|
|
3646
3761
|
const llm = stageConfig === void 0 ? void 0 : createStageLLM(stageConfig, {
|
|
3647
3762
|
cacheDirectory: job.cache,
|
|
3648
3763
|
logDirectory: job.log,
|
|
3649
3764
|
onTokenUsage: async (usage) => {
|
|
3650
3765
|
await reporter.addTokenUsage(usage);
|
|
3651
|
-
}
|
|
3766
|
+
},
|
|
3767
|
+
onStreamProgress: async ({ outputCharacters }) => {
|
|
3768
|
+
await reporter.addOutputCharacters(outputCharacters);
|
|
3769
|
+
},
|
|
3770
|
+
...injectedLLM === void 0 ? {} : { provider: injectedLLM }
|
|
3652
3771
|
});
|
|
3653
3772
|
const promptSource = job.prompt ?? stageConfig?.prompt;
|
|
3654
3773
|
const wikispine = job.target === "knowledge-graph" ? requireKnowledgeGraphWikispineConfig(config) : void 0;
|
|
@@ -3669,7 +3788,7 @@ async function openJobExecutor(job, config, signal, reporter) {
|
|
|
3669
3788
|
"Local Wikimedia resolution requires an LLM."
|
|
3670
3789
|
),
|
|
3671
3790
|
llmModelId: requireValue(
|
|
3672
|
-
stageConfig?.llm?.model,
|
|
3791
|
+
stageConfig?.llm?.model ?? injectedLLM?.model,
|
|
3673
3792
|
"Local Wikimedia resolution requires an LLM model."
|
|
3674
3793
|
)
|
|
3675
3794
|
} : {
|
|
@@ -3678,7 +3797,7 @@ async function openJobExecutor(job, config, signal, reporter) {
|
|
|
3678
3797
|
token: config.wikimedia.token
|
|
3679
3798
|
}
|
|
3680
3799
|
);
|
|
3681
|
-
const embeddingProvider = job.target === "index-embedding-source" || job.target === "index-embedding-summary" ? buildSearchIndexEmbeddingProvider(requireEmbeddingConfig(config)) : void 0;
|
|
3800
|
+
const embeddingProvider = job.target === "index-embedding-source" || job.target === "index-embedding-summary" ? getWikiGraphSDKProviders().embedding ?? buildSearchIndexEmbeddingProvider(requireEmbeddingConfig(config)) : void 0;
|
|
3682
3801
|
return {
|
|
3683
3802
|
async close() {
|
|
3684
3803
|
await wikimediaResolver?.close();
|
|
@@ -3888,6 +4007,12 @@ var WikiGraphJobManager = class {
|
|
|
3888
4007
|
async clean() {
|
|
3889
4008
|
return await this.#runtime.run(async () => await cleanBuildJobs());
|
|
3890
4009
|
}
|
|
4010
|
+
async runWorker(options = {}) {
|
|
4011
|
+
await this.#runtime.run(
|
|
4012
|
+
async () => await runWikiGraphQueueWorker(options),
|
|
4013
|
+
options.signal
|
|
4014
|
+
);
|
|
4015
|
+
}
|
|
3891
4016
|
async get(jobId) {
|
|
3892
4017
|
return await this.#runtime.run(
|
|
3893
4018
|
async () => await this.#createHandle(await this.#backend.get(jobId))
|
|
@@ -3963,12 +4088,13 @@ var WikiGraphJobManager = class {
|
|
|
3963
4088
|
}
|
|
3964
4089
|
async enqueue(options) {
|
|
3965
4090
|
return await this.#runtime.run(async () => {
|
|
4091
|
+
const llmJSON = resolveWikiGraphLLMJSON(options);
|
|
3966
4092
|
const location = await resolveWikiGraphArchiveLocation(options.archive);
|
|
3967
4093
|
return await withArchiveBuildJobCreationLock(
|
|
3968
4094
|
location.archiveFile,
|
|
3969
4095
|
async () => {
|
|
3970
4096
|
const target = options.target ?? "reading-summary";
|
|
3971
|
-
await validateQueueTargetConfig(target,
|
|
4097
|
+
await validateQueueTargetConfig(target, llmJSON);
|
|
3972
4098
|
const selectedExplicitly = options.chapterId !== void 0 || options.chapterIds !== void 0 || options.chapterPath !== void 0 || options.depth !== void 0;
|
|
3973
4099
|
const candidates = await new WikiGraphArchiveFile6(
|
|
3974
4100
|
location.archiveFile
|
|
@@ -4018,7 +4144,7 @@ var WikiGraphJobManager = class {
|
|
|
4018
4144
|
archive: location.archiveFile,
|
|
4019
4145
|
boost: options.boost ?? false,
|
|
4020
4146
|
chapterId: candidate.chapter.chapterId,
|
|
4021
|
-
...
|
|
4147
|
+
...llmJSON === void 0 ? {} : { llmJSON },
|
|
4022
4148
|
...options.prompt === void 0 ? {} : { prompt: options.prompt },
|
|
4023
4149
|
target
|
|
4024
4150
|
}),
|
|
@@ -4040,9 +4166,10 @@ var WikiGraphJobManager = class {
|
|
|
4040
4166
|
}
|
|
4041
4167
|
async planEnqueue(options) {
|
|
4042
4168
|
return await this.#runtime.run(async () => {
|
|
4169
|
+
const llmJSON = resolveWikiGraphLLMJSON(options);
|
|
4043
4170
|
const location = await resolveWikiGraphArchiveLocation(options.archive);
|
|
4044
4171
|
const target = options.target ?? "reading-summary";
|
|
4045
|
-
await validateQueueTargetConfig(target,
|
|
4172
|
+
await validateQueueTargetConfig(target, llmJSON);
|
|
4046
4173
|
const selectedExplicitly = options.chapterId !== void 0 || options.chapterIds !== void 0 || options.chapterPath !== void 0 || options.depth !== void 0;
|
|
4047
4174
|
const candidates = await new WikiGraphArchiveFile6(
|
|
4048
4175
|
location.archiveFile
|
|
@@ -4287,12 +4414,15 @@ async function selectQueueChapters(document, chapters, options) {
|
|
|
4287
4414
|
);
|
|
4288
4415
|
}
|
|
4289
4416
|
async function validateQueueTargetConfig(target, llmJSON) {
|
|
4417
|
+
const providers = getWikiGraphSDKProviders();
|
|
4290
4418
|
const config = target === "knowledge-graph" || target === "reading-graph" || target === "reading-summary" ? await loadRequiredStageConfig({
|
|
4291
4419
|
...llmJSON === void 0 ? {} : { llmJSON }
|
|
4292
4420
|
}) : await loadWikiGraphRuntimeConfig({
|
|
4293
|
-
...llmJSON === void 0 ? {} : { llmJSON }
|
|
4421
|
+
...llmJSON === void 0 ? {} : { llmJSON },
|
|
4422
|
+
...providers.embedding === void 0 ? {} : { skipEmbeddingConfig: true },
|
|
4423
|
+
...llmJSON === void 0 && providers.llm !== void 0 ? { skipLLMConfig: true } : {}
|
|
4294
4424
|
});
|
|
4295
|
-
if ((target === "index-embedding-source" || target === "index-embedding-summary") && config.embedding === void 0) {
|
|
4425
|
+
if ((target === "index-embedding-source" || target === "index-embedding-summary") && config.embedding === void 0 && providers.embedding === void 0) {
|
|
4296
4426
|
throw new Error(
|
|
4297
4427
|
"Missing embeddings configuration. Configure `wikg://local/config/embeddings` before queueing embedding index artifact jobs."
|
|
4298
4428
|
);
|
|
@@ -4401,9 +4531,20 @@ import {
|
|
|
4401
4531
|
replaceWikiGraphLibraryArchive,
|
|
4402
4532
|
replaceWikiGraphLibraryMetadata,
|
|
4403
4533
|
resolveWikiGraphLibrary as resolveWikiGraphLibrary2,
|
|
4404
|
-
scanWikiGraphLibrary
|
|
4534
|
+
scanWikiGraphLibrary,
|
|
4535
|
+
withWikiGraphLibraryLock
|
|
4405
4536
|
} from "wiki-graph-core";
|
|
4406
4537
|
import { mkdir as mkdir2 } from "fs/promises";
|
|
4538
|
+
async function resolveQueryEmbeddingProvider(queryMode) {
|
|
4539
|
+
if (queryMode === "fts") return void 0;
|
|
4540
|
+
const provider = await createConfiguredEmbeddingProvider();
|
|
4541
|
+
if (queryMode === "embedding" && provider === void 0) {
|
|
4542
|
+
throw new Error(
|
|
4543
|
+
"Embedding query mode requires embeddings configuration at `wikg://local/config/embeddings`."
|
|
4544
|
+
);
|
|
4545
|
+
}
|
|
4546
|
+
return provider;
|
|
4547
|
+
}
|
|
4407
4548
|
var WikiGraphLibraryManager = class {
|
|
4408
4549
|
#runtime;
|
|
4409
4550
|
constructor(runtime) {
|
|
@@ -4473,6 +4614,43 @@ var WikiGraphLibraryManager = class {
|
|
|
4473
4614
|
)
|
|
4474
4615
|
);
|
|
4475
4616
|
}
|
|
4617
|
+
async readArchive(target, consume, options = {}) {
|
|
4618
|
+
return await this.#runtime.run(async () => {
|
|
4619
|
+
const parsedTarget = requireLibraryArchiveTarget(target);
|
|
4620
|
+
const library = await resolveWikiGraphLibrary2(parsedTarget);
|
|
4621
|
+
return await withWikiGraphLibraryLock(
|
|
4622
|
+
library.id,
|
|
4623
|
+
"read",
|
|
4624
|
+
async () => {
|
|
4625
|
+
throwIfAborted(options.signal);
|
|
4626
|
+
const archive = await getWikiGraphLibraryArchive(parsedTarget);
|
|
4627
|
+
const file = requireReadableLibraryArchiveFile(archive);
|
|
4628
|
+
const reader = await file.openReader();
|
|
4629
|
+
let active = true;
|
|
4630
|
+
try {
|
|
4631
|
+
const content = {
|
|
4632
|
+
mediaType: "application/vnd.wiki-graph.archive",
|
|
4633
|
+
size: reader.size,
|
|
4634
|
+
stream: createCallbackScopedArchiveStream(
|
|
4635
|
+
reader,
|
|
4636
|
+
() => active,
|
|
4637
|
+
options.signal
|
|
4638
|
+
),
|
|
4639
|
+
uri: archive.uri
|
|
4640
|
+
};
|
|
4641
|
+
return await runAbortableCallback(
|
|
4642
|
+
async () => await consume(content),
|
|
4643
|
+
options.signal
|
|
4644
|
+
);
|
|
4645
|
+
} finally {
|
|
4646
|
+
active = false;
|
|
4647
|
+
await reader.close();
|
|
4648
|
+
}
|
|
4649
|
+
},
|
|
4650
|
+
options.signal === void 0 ? {} : { signal: options.signal }
|
|
4651
|
+
);
|
|
4652
|
+
}, options.signal);
|
|
4653
|
+
}
|
|
4476
4654
|
async moveArchive(options) {
|
|
4477
4655
|
return toArchiveSnapshot(
|
|
4478
4656
|
await this.#runtime.run(
|
|
@@ -4562,7 +4740,9 @@ var WikiGraphLibraryManager = class {
|
|
|
4562
4740
|
}
|
|
4563
4741
|
async search(target, query, options = {}) {
|
|
4564
4742
|
return await this.#runtime.run(async () => {
|
|
4565
|
-
const embeddingProvider = await
|
|
4743
|
+
const embeddingProvider = await resolveQueryEmbeddingProvider(
|
|
4744
|
+
options.queryMode
|
|
4745
|
+
);
|
|
4566
4746
|
return await findWikiGraphLibraryObjects2(
|
|
4567
4747
|
requireLibraryTarget(target),
|
|
4568
4748
|
query,
|
|
@@ -4575,7 +4755,9 @@ var WikiGraphLibraryManager = class {
|
|
|
4575
4755
|
}
|
|
4576
4756
|
async searchArchiveMembers(target, query, options = {}) {
|
|
4577
4757
|
return await this.#runtime.run(async () => {
|
|
4578
|
-
const embeddingProvider = await
|
|
4758
|
+
const embeddingProvider = await resolveQueryEmbeddingProvider(
|
|
4759
|
+
options.queryMode
|
|
4760
|
+
);
|
|
4579
4761
|
return await findWikiGraphLibraryArchiveMembers2(
|
|
4580
4762
|
requireLibraryTarget(target),
|
|
4581
4763
|
query,
|
|
@@ -4616,22 +4798,36 @@ var WikiGraphLibraryManager = class {
|
|
|
4616
4798
|
);
|
|
4617
4799
|
}
|
|
4618
4800
|
async related(target, objectUri, options = {}) {
|
|
4619
|
-
return await this.#runtime.run(
|
|
4620
|
-
|
|
4801
|
+
return await this.#runtime.run(async () => {
|
|
4802
|
+
if (options.query === void 0 && options.queryMode !== void 0) {
|
|
4803
|
+
throw new Error("`queryMode` requires `query`.");
|
|
4804
|
+
}
|
|
4805
|
+
const embeddingProvider = options.query === void 0 ? void 0 : await resolveQueryEmbeddingProvider(options.queryMode);
|
|
4806
|
+
return await listRelatedWikiGraphLibraryObjects2(
|
|
4621
4807
|
requireLibraryTarget(target),
|
|
4622
4808
|
objectUri,
|
|
4623
|
-
|
|
4624
|
-
|
|
4625
|
-
|
|
4809
|
+
{
|
|
4810
|
+
...options,
|
|
4811
|
+
...embeddingProvider === void 0 ? {} : { embeddingProvider }
|
|
4812
|
+
}
|
|
4813
|
+
);
|
|
4814
|
+
});
|
|
4626
4815
|
}
|
|
4627
4816
|
async evidence(target, objectUri, options = {}) {
|
|
4628
|
-
return await this.#runtime.run(
|
|
4629
|
-
|
|
4817
|
+
return await this.#runtime.run(async () => {
|
|
4818
|
+
if (options.query === void 0 && options.queryMode !== void 0) {
|
|
4819
|
+
throw new Error("`queryMode` requires `query`.");
|
|
4820
|
+
}
|
|
4821
|
+
const embeddingProvider = options.query === void 0 ? void 0 : await resolveQueryEmbeddingProvider(options.queryMode);
|
|
4822
|
+
return await listWikiGraphLibraryEvidence2(
|
|
4630
4823
|
requireLibraryTarget(target),
|
|
4631
4824
|
objectUri,
|
|
4632
|
-
|
|
4633
|
-
|
|
4634
|
-
|
|
4825
|
+
{
|
|
4826
|
+
...options,
|
|
4827
|
+
...embeddingProvider === void 0 ? {} : { embeddingProvider }
|
|
4828
|
+
}
|
|
4829
|
+
);
|
|
4830
|
+
});
|
|
4635
4831
|
}
|
|
4636
4832
|
async pack(target, objectUri, budget = 5e3) {
|
|
4637
4833
|
return await this.#runtime.run(
|
|
@@ -4713,6 +4909,97 @@ function requireLibraryTarget(value) {
|
|
|
4713
4909
|
}
|
|
4714
4910
|
return target;
|
|
4715
4911
|
}
|
|
4912
|
+
function requireLibraryArchiveTarget(value) {
|
|
4913
|
+
const target = requireLibraryTarget(value);
|
|
4914
|
+
if (target.kind !== "archive" || target.archivePublicId === void 0 || target.objectUri !== void 0) {
|
|
4915
|
+
throw new TypeError("Expected a Wiki Graph library archive URI.");
|
|
4916
|
+
}
|
|
4917
|
+
return target;
|
|
4918
|
+
}
|
|
4919
|
+
function requireReadableLibraryArchiveFile(archive) {
|
|
4920
|
+
if (!archive.exists || archive.status === "missing") {
|
|
4921
|
+
throw new Error(`Wiki Graph library archive is missing: ${archive.uri}`);
|
|
4922
|
+
}
|
|
4923
|
+
if (archive.status === "conflict") {
|
|
4924
|
+
throw new Error(
|
|
4925
|
+
`Wiki Graph library archive has a conflict and cannot be read: ${archive.uri}`
|
|
4926
|
+
);
|
|
4927
|
+
}
|
|
4928
|
+
if (archive.file === void 0) {
|
|
4929
|
+
throw new Error(
|
|
4930
|
+
`Wiki Graph library archive is unavailable: ${archive.uri}`
|
|
4931
|
+
);
|
|
4932
|
+
}
|
|
4933
|
+
return archive.file;
|
|
4934
|
+
}
|
|
4935
|
+
var ARCHIVE_STREAM_CHUNK_SIZE = 64 * 1024;
|
|
4936
|
+
function createCallbackScopedArchiveStream(reader, isActive, signal) {
|
|
4937
|
+
let consumed = false;
|
|
4938
|
+
return {
|
|
4939
|
+
[Symbol.asyncIterator]() {
|
|
4940
|
+
assertArchiveReadSessionActive(isActive, signal);
|
|
4941
|
+
if (consumed) {
|
|
4942
|
+
throw new Error(
|
|
4943
|
+
"The library archive stream has already been consumed."
|
|
4944
|
+
);
|
|
4945
|
+
}
|
|
4946
|
+
consumed = true;
|
|
4947
|
+
let offset = 0;
|
|
4948
|
+
let finished = false;
|
|
4949
|
+
return {
|
|
4950
|
+
async next() {
|
|
4951
|
+
if (finished) return { done: true, value: void 0 };
|
|
4952
|
+
assertArchiveReadSessionActive(isActive, signal);
|
|
4953
|
+
if (offset >= reader.size) {
|
|
4954
|
+
finished = true;
|
|
4955
|
+
return { done: true, value: void 0 };
|
|
4956
|
+
}
|
|
4957
|
+
const length = Math.min(
|
|
4958
|
+
ARCHIVE_STREAM_CHUNK_SIZE,
|
|
4959
|
+
reader.size - offset
|
|
4960
|
+
);
|
|
4961
|
+
const chunk = await reader.read(offset, length);
|
|
4962
|
+
assertArchiveReadSessionActive(isActive, signal);
|
|
4963
|
+
offset += chunk.byteLength;
|
|
4964
|
+
return { done: false, value: chunk };
|
|
4965
|
+
},
|
|
4966
|
+
return() {
|
|
4967
|
+
finished = true;
|
|
4968
|
+
return Promise.resolve({ done: true, value: void 0 });
|
|
4969
|
+
}
|
|
4970
|
+
};
|
|
4971
|
+
}
|
|
4972
|
+
};
|
|
4973
|
+
}
|
|
4974
|
+
function assertArchiveReadSessionActive(isActive, signal) {
|
|
4975
|
+
if (!isActive()) {
|
|
4976
|
+
throw new Error(
|
|
4977
|
+
"The library archive stream cannot be read after its callback has finished."
|
|
4978
|
+
);
|
|
4979
|
+
}
|
|
4980
|
+
throwIfAborted(signal);
|
|
4981
|
+
}
|
|
4982
|
+
async function runAbortableCallback(operation, signal) {
|
|
4983
|
+
if (signal === void 0) return await operation();
|
|
4984
|
+
throwIfAborted(signal);
|
|
4985
|
+
let rejectAbort;
|
|
4986
|
+
const aborted = new Promise((_resolve, reject) => {
|
|
4987
|
+
rejectAbort = reject;
|
|
4988
|
+
});
|
|
4989
|
+
const onAbort = () => rejectAbort(abortReason(signal));
|
|
4990
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
4991
|
+
try {
|
|
4992
|
+
return await Promise.race([operation(), aborted]);
|
|
4993
|
+
} finally {
|
|
4994
|
+
signal.removeEventListener("abort", onAbort);
|
|
4995
|
+
}
|
|
4996
|
+
}
|
|
4997
|
+
function throwIfAborted(signal) {
|
|
4998
|
+
if (signal?.aborted === true) throw abortReason(signal);
|
|
4999
|
+
}
|
|
5000
|
+
function abortReason(signal) {
|
|
5001
|
+
return signal.reason ?? new DOMException("The operation was aborted.", "AbortError");
|
|
5002
|
+
}
|
|
4716
5003
|
|
|
4717
5004
|
// src/maintenance.ts
|
|
4718
5005
|
import {
|
|
@@ -4791,6 +5078,7 @@ var WikiGraphSDK = class {
|
|
|
4791
5078
|
cwd: options.cwd ?? process.cwd(),
|
|
4792
5079
|
env: { ...process.env, ...options.env },
|
|
4793
5080
|
envPolicy: options.envPolicy ?? "production",
|
|
5081
|
+
providers: { ...options.providers },
|
|
4794
5082
|
...options.stateDir === void 0 ? {} : { stateDir: options.stateDir }
|
|
4795
5083
|
};
|
|
4796
5084
|
this.archives = new WikiGraphArchiveManager(this);
|
|
@@ -4802,7 +5090,7 @@ var WikiGraphSDK = class {
|
|
|
4802
5090
|
this.maintenance = new WikiGraphMaintenanceManager(this);
|
|
4803
5091
|
}
|
|
4804
5092
|
async run(operation, signal, options = {}) {
|
|
4805
|
-
|
|
5093
|
+
throwIfAborted2(signal);
|
|
4806
5094
|
const runWithContext = async () => await withWikiGraphSDKRuntimeContext(this.#context, async () => {
|
|
4807
5095
|
if (options.skipHomeBootstrap !== true) {
|
|
4808
5096
|
this.#homeReady ??= ensureWikiGraphHomeSchemaCurrent().catch(
|
|
@@ -4819,14 +5107,14 @@ var WikiGraphSDK = class {
|
|
|
4819
5107
|
this.#context.stateDir,
|
|
4820
5108
|
runWithContext
|
|
4821
5109
|
);
|
|
4822
|
-
|
|
5110
|
+
throwIfAborted2(signal);
|
|
4823
5111
|
return result;
|
|
4824
5112
|
}
|
|
4825
5113
|
close() {
|
|
4826
5114
|
this.jobs.close();
|
|
4827
5115
|
}
|
|
4828
5116
|
};
|
|
4829
|
-
function
|
|
5117
|
+
function throwIfAborted2(signal) {
|
|
4830
5118
|
if (signal?.aborted !== true) return;
|
|
4831
5119
|
throw signal.reason instanceof Error ? signal.reason : new Error("The Wiki Graph SDK operation was aborted.");
|
|
4832
5120
|
}
|
|
@@ -4904,6 +5192,7 @@ export {
|
|
|
4904
5192
|
formatWikiGraphCommandUri,
|
|
4905
5193
|
formatWikiGraphLibraryUri3 as formatWikiGraphLibraryUri,
|
|
4906
5194
|
getNodeResourcePath,
|
|
5195
|
+
getWikiGraphSDKProviders,
|
|
4907
5196
|
getWikiGraphSDKRuntimeContext,
|
|
4908
5197
|
getWikiGraphSDKStateDir,
|
|
4909
5198
|
inspectWikiGraphArchive,
|
|
@@ -4933,6 +5222,7 @@ export {
|
|
|
4933
5222
|
resolveExtractionPrompt,
|
|
4934
5223
|
resolveHostedProviderEndpoint,
|
|
4935
5224
|
resolveKnowledgeGraphRecallPrompt,
|
|
5225
|
+
resolveWikiGraphLLMJSON,
|
|
4936
5226
|
resolveWikispineConfig,
|
|
4937
5227
|
runWikiGraphQueueWorker,
|
|
4938
5228
|
validateLocalConfigSection,
|