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/default-worker.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { WikiGraphRuntimeConfig } from './runtime-config.js';
|
|
|
2
2
|
import 'zod';
|
|
3
3
|
|
|
4
4
|
interface WikiGraphQueueWorkerOptions {
|
|
5
|
+
readonly idleTimeoutMs?: number;
|
|
5
6
|
readonly signal?: AbortSignal;
|
|
6
7
|
}
|
|
7
8
|
declare function runWikiGraphQueueWorker(options?: WikiGraphQueueWorkerOptions): Promise<void>;
|
package/dist/default-worker.js
CHANGED
|
@@ -49,12 +49,16 @@ function getWikiGraphSDKRuntimeContext() {
|
|
|
49
49
|
return runtimeContext.getStore() ?? {
|
|
50
50
|
cwd: process.cwd(),
|
|
51
51
|
env: process.env,
|
|
52
|
-
envPolicy: "production"
|
|
52
|
+
envPolicy: "production",
|
|
53
|
+
providers: {}
|
|
53
54
|
};
|
|
54
55
|
}
|
|
55
56
|
function getWikiGraphSDKStateDir() {
|
|
56
57
|
return getWikiGraphSDKRuntimeContext().stateDir;
|
|
57
58
|
}
|
|
59
|
+
function getWikiGraphSDKProviders() {
|
|
60
|
+
return getWikiGraphSDKRuntimeContext().providers ?? {};
|
|
61
|
+
}
|
|
58
62
|
|
|
59
63
|
// src/node-platform.ts
|
|
60
64
|
import * as asyncHooks from "async_hooks";
|
|
@@ -71,6 +75,7 @@ import * as yauzl from "yauzl";
|
|
|
71
75
|
import * as yazl from "yazl";
|
|
72
76
|
import { Environment, Loader } from "nunjucks";
|
|
73
77
|
import {
|
|
78
|
+
getWikiGraphPlatform,
|
|
74
79
|
getWikiGraphStorage,
|
|
75
80
|
installWikiGraphPlatform,
|
|
76
81
|
installWikiGraphStorage,
|
|
@@ -732,15 +737,28 @@ function resolveNodeDataDirectory() {
|
|
|
732
737
|
directory = parent;
|
|
733
738
|
}
|
|
734
739
|
}
|
|
735
|
-
function createNodeWikiGraphStorage(
|
|
740
|
+
function createNodeWikiGraphStorage(stateRootOrOptions = pathModule.join(
|
|
741
|
+
os.homedir(),
|
|
742
|
+
".wikigraph"
|
|
743
|
+
)) {
|
|
744
|
+
const libraryRoot = typeof stateRootOrOptions === "string" ? stateRootOrOptions : stateRootOrOptions.libraryRoot;
|
|
745
|
+
const documentStoreRoot = typeof stateRootOrOptions === "string" ? pathModule.join(stateRootOrOptions, "documents") : stateRootOrOptions.documentStoreRoot;
|
|
736
746
|
return {
|
|
737
|
-
library: new NodeDirectory(
|
|
738
|
-
documentStore: new NodeDirectory(
|
|
747
|
+
library: new NodeDirectory(libraryRoot),
|
|
748
|
+
documentStore: new NodeDirectory(documentStoreRoot)
|
|
739
749
|
};
|
|
740
750
|
}
|
|
741
|
-
function
|
|
742
|
-
|
|
743
|
-
|
|
751
|
+
function ensureNodeWikiGraphPlatform() {
|
|
752
|
+
try {
|
|
753
|
+
getWikiGraphPlatform();
|
|
754
|
+
} catch {
|
|
755
|
+
installWikiGraphPlatform(nodeWikiGraphPlatform);
|
|
756
|
+
}
|
|
757
|
+
try {
|
|
758
|
+
getWikiGraphStorage();
|
|
759
|
+
} catch {
|
|
760
|
+
installWikiGraphStorage(createNodeWikiGraphStorage());
|
|
761
|
+
}
|
|
744
762
|
}
|
|
745
763
|
async function withNodeWikiGraphStorage(stateRoot, operation) {
|
|
746
764
|
return await withWikiGraphStorage(
|
|
@@ -1076,8 +1094,8 @@ var inlineLLMConfigSchema = z.object({
|
|
|
1076
1094
|
});
|
|
1077
1095
|
async function loadWikiGraphRuntimeConfig(options) {
|
|
1078
1096
|
const [embedding, localLLM, concurrent, wikimedia, wikispine] = await Promise.all([
|
|
1079
|
-
readLocalConfigSection("embeddings"),
|
|
1080
|
-
readLocalConfigSection("llm"),
|
|
1097
|
+
options?.skipEmbeddingConfig === true ? Promise.resolve({}) : readLocalConfigSection("embeddings"),
|
|
1098
|
+
options?.skipLLMConfig === true ? Promise.resolve({}) : readLocalConfigSection("llm"),
|
|
1081
1099
|
readLocalConfigSection("concurrent"),
|
|
1082
1100
|
readLocalConfigSection("wikimedia"),
|
|
1083
1101
|
readLocalConfigSection("wikispine")
|
|
@@ -1357,7 +1375,10 @@ function createOpenAICompatibleName2(baseURL) {
|
|
|
1357
1375
|
|
|
1358
1376
|
// src/stage.ts
|
|
1359
1377
|
function createStageLLM(config, options) {
|
|
1360
|
-
const llmOptions = buildWikiGraphLLMOptions(config)
|
|
1378
|
+
const llmOptions = options?.provider === void 0 ? buildWikiGraphLLMOptions(config) : {
|
|
1379
|
+
...config.concurrent?.request === void 0 ? {} : { concurrent: config.concurrent.request },
|
|
1380
|
+
streamProvider: options.provider
|
|
1381
|
+
};
|
|
1361
1382
|
return new LLM({
|
|
1362
1383
|
sampling: createDefaultWikiGraphSampling({
|
|
1363
1384
|
...llmOptions.temperature === void 0 ? {} : { temperature: llmOptions.temperature },
|
|
@@ -1371,10 +1392,13 @@ function createStageLLM(config, options) {
|
|
|
1371
1392
|
});
|
|
1372
1393
|
}
|
|
1373
1394
|
async function loadRequiredStageConfig(options) {
|
|
1395
|
+
const injected = options.llmJSON === void 0 ? getWikiGraphSDKProviders().llm : void 0;
|
|
1374
1396
|
const config = await loadWikiGraphRuntimeConfig({
|
|
1375
|
-
...options.llmJSON === void 0 ? {} : { llmJSON: options.llmJSON }
|
|
1397
|
+
...options.llmJSON === void 0 ? {} : { llmJSON: options.llmJSON },
|
|
1398
|
+
...options.llmJSON === void 0 && injected !== void 0 ? { skipLLMConfig: true } : {},
|
|
1399
|
+
...getWikiGraphSDKProviders().embedding === void 0 ? {} : { skipEmbeddingConfig: true }
|
|
1376
1400
|
});
|
|
1377
|
-
if (config.llm?.provider === void 0 || config.llm.model === void 0) {
|
|
1401
|
+
if (injected === void 0 && (config.llm?.provider === void 0 || config.llm.model === void 0)) {
|
|
1378
1402
|
throw new Error(
|
|
1379
1403
|
"Missing LLM configuration. Set --llm for one run, or configure `wikg://local/config/llm` with provider and model."
|
|
1380
1404
|
);
|
|
@@ -1456,6 +1480,34 @@ import {
|
|
|
1456
1480
|
WikiGraphArchiveFile as WikiGraphArchiveFile2
|
|
1457
1481
|
} from "wiki-graph-core";
|
|
1458
1482
|
|
|
1483
|
+
// src/host.ts
|
|
1484
|
+
import {
|
|
1485
|
+
installWikiGraphPlatform as installWikiGraphPlatform2,
|
|
1486
|
+
withWikiGraphStorage as withWikiGraphStorage2
|
|
1487
|
+
} from "wiki-graph-core/platform";
|
|
1488
|
+
function prepareWikiGraphSDKHost(host) {
|
|
1489
|
+
if (host?.platform === void 0) {
|
|
1490
|
+
ensureNodeWikiGraphPlatform();
|
|
1491
|
+
return;
|
|
1492
|
+
}
|
|
1493
|
+
installWikiGraphPlatform2(host.platform);
|
|
1494
|
+
}
|
|
1495
|
+
function assertWikiGraphSDKHostOptions(options) {
|
|
1496
|
+
if (options.host?.storage !== void 0 && options.stateDir !== void 0) {
|
|
1497
|
+
throw new TypeError(
|
|
1498
|
+
"Wiki Graph SDK host.storage and stateDir cannot be used together."
|
|
1499
|
+
);
|
|
1500
|
+
}
|
|
1501
|
+
}
|
|
1502
|
+
async function withWikiGraphSDKHost(options, operation) {
|
|
1503
|
+
assertWikiGraphSDKHostOptions(options);
|
|
1504
|
+
prepareWikiGraphSDKHost(options.host);
|
|
1505
|
+
if (options.host?.storage !== void 0) {
|
|
1506
|
+
return await withWikiGraphStorage2(options.host.storage, operation);
|
|
1507
|
+
}
|
|
1508
|
+
return await withNodeWikiGraphStorage(options.stateDir, operation);
|
|
1509
|
+
}
|
|
1510
|
+
|
|
1459
1511
|
// src/archive/target.ts
|
|
1460
1512
|
import { realpath, stat as stat2 } from "fs/promises";
|
|
1461
1513
|
import { basename as basename2, dirname as dirname2, isAbsolute as isAbsolute3, join as join3, relative, resolve as resolve3 } from "path";
|
|
@@ -1687,17 +1739,23 @@ import {
|
|
|
1687
1739
|
writeChapterJobInputFile as writeChapterJobInputFile2
|
|
1688
1740
|
} from "wiki-graph-core/worker";
|
|
1689
1741
|
async function runBuildJobWorker(options) {
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1742
|
+
const { host, stateDir, ...coreOptions } = options;
|
|
1743
|
+
await withWikiGraphSDKHost(
|
|
1744
|
+
{
|
|
1745
|
+
...host === void 0 ? {} : { host },
|
|
1746
|
+
...stateDir === void 0 ? {} : { stateDir }
|
|
1747
|
+
},
|
|
1694
1748
|
async () => await runCoreBuildJobWorker(coreOptions)
|
|
1695
1749
|
);
|
|
1696
1750
|
}
|
|
1697
1751
|
|
|
1698
1752
|
// src/default-worker.ts
|
|
1699
1753
|
async function runWikiGraphQueueWorker(options = {}) {
|
|
1700
|
-
const
|
|
1754
|
+
const providers = getWikiGraphSDKProviders();
|
|
1755
|
+
const config = await loadWikiGraphRuntimeConfig({
|
|
1756
|
+
...providers.embedding === void 0 ? {} : { skipEmbeddingConfig: true },
|
|
1757
|
+
...providers.llm === void 0 ? {} : { skipLLMConfig: true }
|
|
1758
|
+
});
|
|
1701
1759
|
await runBuildJobWorker({
|
|
1702
1760
|
concurrency: config.concurrent?.job ?? DEFAULT_GENERATION_JOB_CONCURRENCY,
|
|
1703
1761
|
executeJob: async (job, reporter, context) => {
|
|
@@ -1706,12 +1764,16 @@ async function runWikiGraphQueueWorker(options = {}) {
|
|
|
1706
1764
|
async () => await executeBuildJob(job, reporter, context)
|
|
1707
1765
|
);
|
|
1708
1766
|
},
|
|
1767
|
+
...options.idleTimeoutMs === void 0 ? {} : { idleTimeoutMs: options.idleTimeoutMs },
|
|
1709
1768
|
...options.signal === void 0 ? {} : { signal: options.signal }
|
|
1710
1769
|
});
|
|
1711
1770
|
}
|
|
1712
1771
|
async function executeBuildJob(job, reporter, context) {
|
|
1772
|
+
const providers = getWikiGraphSDKProviders();
|
|
1713
1773
|
const config = await loadWikiGraphRuntimeConfig({
|
|
1714
|
-
...job.llmJSON === void 0 ? {} : { llmJSON: job.llmJSON }
|
|
1774
|
+
...job.llmJSON === void 0 ? {} : { llmJSON: job.llmJSON },
|
|
1775
|
+
...providers.embedding === void 0 ? {} : { skipEmbeddingConfig: true },
|
|
1776
|
+
...job.llmJSON === void 0 && providers.llm !== void 0 ? { skipLLMConfig: true } : {}
|
|
1715
1777
|
});
|
|
1716
1778
|
const execution = await openJobExecutor(
|
|
1717
1779
|
job,
|
|
@@ -1846,12 +1908,17 @@ async function openJobExecutor(job, config, signal, reporter) {
|
|
|
1846
1908
|
const stageConfig = generation ? await loadRequiredStageConfig({
|
|
1847
1909
|
...job.llmJSON === void 0 ? {} : { llmJSON: job.llmJSON }
|
|
1848
1910
|
}) : void 0;
|
|
1911
|
+
const injectedLLM = job.llmJSON === void 0 ? getWikiGraphSDKProviders().llm : void 0;
|
|
1849
1912
|
const llm = stageConfig === void 0 ? void 0 : createStageLLM(stageConfig, {
|
|
1850
1913
|
cacheDirectory: job.cache,
|
|
1851
1914
|
logDirectory: job.log,
|
|
1852
1915
|
onTokenUsage: async (usage) => {
|
|
1853
1916
|
await reporter.addTokenUsage(usage);
|
|
1854
|
-
}
|
|
1917
|
+
},
|
|
1918
|
+
onStreamProgress: async ({ outputCharacters }) => {
|
|
1919
|
+
await reporter.addOutputCharacters(outputCharacters);
|
|
1920
|
+
},
|
|
1921
|
+
...injectedLLM === void 0 ? {} : { provider: injectedLLM }
|
|
1855
1922
|
});
|
|
1856
1923
|
const promptSource = job.prompt ?? stageConfig?.prompt;
|
|
1857
1924
|
const wikispine = job.target === "knowledge-graph" ? requireKnowledgeGraphWikispineConfig(config) : void 0;
|
|
@@ -1872,7 +1939,7 @@ async function openJobExecutor(job, config, signal, reporter) {
|
|
|
1872
1939
|
"Local Wikimedia resolution requires an LLM."
|
|
1873
1940
|
),
|
|
1874
1941
|
llmModelId: requireValue(
|
|
1875
|
-
stageConfig?.llm?.model,
|
|
1942
|
+
stageConfig?.llm?.model ?? injectedLLM?.model,
|
|
1876
1943
|
"Local Wikimedia resolution requires an LLM model."
|
|
1877
1944
|
)
|
|
1878
1945
|
} : {
|
|
@@ -1881,7 +1948,7 @@ async function openJobExecutor(job, config, signal, reporter) {
|
|
|
1881
1948
|
token: config.wikimedia.token
|
|
1882
1949
|
}
|
|
1883
1950
|
);
|
|
1884
|
-
const embeddingProvider = job.target === "index-embedding-source" || job.target === "index-embedding-summary" ? buildSearchIndexEmbeddingProvider(requireEmbeddingConfig(config)) : void 0;
|
|
1951
|
+
const embeddingProvider = job.target === "index-embedding-source" || job.target === "index-embedding-summary" ? getWikiGraphSDKProviders().embedding ?? buildSearchIndexEmbeddingProvider(requireEmbeddingConfig(config)) : void 0;
|
|
1885
1952
|
return {
|
|
1886
1953
|
async close() {
|
|
1887
1954
|
await wikimediaResolver?.close();
|