wiki-graph-sdk 0.8.1 → 0.8.3

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.
Files changed (55) hide show
  1. package/README.md +30 -0
  2. package/dist/archives.cjs +25 -19
  3. package/dist/archives.cjs.map +1 -1
  4. package/dist/archives.d.ts +2 -0
  5. package/dist/archives.js +14 -7
  6. package/dist/archives.js.map +1 -1
  7. package/dist/conversions.cjs +11 -12
  8. package/dist/conversions.cjs.map +1 -1
  9. package/dist/conversions.js +7 -7
  10. package/dist/conversions.js.map +1 -1
  11. package/dist/default-worker.cjs +83 -20
  12. package/dist/default-worker.cjs.map +1 -1
  13. package/dist/default-worker.js +84 -17
  14. package/dist/default-worker.js.map +1 -1
  15. package/dist/embedding.cjs +6 -7
  16. package/dist/embedding.cjs.map +1 -1
  17. package/dist/embedding.js +7 -7
  18. package/dist/embedding.js.map +1 -1
  19. package/dist/gc.cjs +106 -12
  20. package/dist/gc.cjs.map +1 -1
  21. package/dist/gc.d.ts +3 -0
  22. package/dist/gc.js +110 -12
  23. package/dist/gc.js.map +1 -1
  24. package/dist/host-IbqJ8WSV.d.ts +18 -0
  25. package/dist/index.cjs +127 -32
  26. package/dist/index.cjs.map +1 -1
  27. package/dist/index.d.ts +8 -4
  28. package/dist/index.js +119 -21
  29. package/dist/index.js.map +1 -1
  30. package/dist/local-config.cjs +6 -7
  31. package/dist/local-config.cjs.map +1 -1
  32. package/dist/local-config.js +7 -7
  33. package/dist/local-config.js.map +1 -1
  34. package/dist/maintenance.cjs.map +1 -1
  35. package/dist/maintenance.js +1 -0
  36. package/dist/maintenance.js.map +1 -1
  37. package/dist/node-platform.cjs +18 -4
  38. package/dist/node-platform.cjs.map +1 -1
  39. package/dist/node-platform.d.ts +12 -3
  40. package/dist/node-platform.js +18 -4
  41. package/dist/node-platform.js.map +1 -1
  42. package/dist/runtime-config.cjs +6 -7
  43. package/dist/runtime-config.cjs.map +1 -1
  44. package/dist/runtime-config.js +7 -7
  45. package/dist/runtime-config.js.map +1 -1
  46. package/dist/stage.cjs +6 -7
  47. package/dist/stage.cjs.map +1 -1
  48. package/dist/stage.js +7 -7
  49. package/dist/stage.js.map +1 -1
  50. package/dist/worker.cjs +113 -50
  51. package/dist/worker.cjs.map +1 -1
  52. package/dist/worker.d.ts +7 -2
  53. package/dist/worker.js +125 -58
  54. package/dist/worker.js.map +1 -1
  55. package/package.json +2 -2
package/dist/index.d.ts CHANGED
@@ -7,25 +7,26 @@ export { LOCAL_CONFIG_SECTIONS, clearLocalConfigSection, deleteLocalConfigValue,
7
7
  import { W as WikiGraphJobRuntime, a as WikiGraphJobManager } from './jobs-CRK-DZ40.js';
8
8
  export { b as WikiGraphJob, c as WikiGraphJobBackend, d as WikiGraphJobChapterReference, e as WikiGraphJobCreateOptions, f as WikiGraphJobEnqueueOptions, g as WikiGraphJobEnqueuePlan, h as WikiGraphJobEnqueueResult, i as WikiGraphJobEventListener, j as WikiGraphJobEventsOptions, k as WikiGraphJobListOptions, l as WikiGraphJobSnapshot, m as WikiGraphJobSubscriptionOptions } from './jobs-CRK-DZ40.js';
9
9
  import { ContinuationCursor, QueryIndexScope, SearchIndexQueryMode, ArchiveSourceLocatorResult, ArchiveCollectionResult, ArchiveFindResult, ArchiveEvidence, ArchiveRelatedResult, WikiGraphLibraryRecord, WikiGraphLibraryArchiveRecord, ParsedWikiGraphLibraryUri, listWikiGraphLibraryEvidence, WikiGraphLibraryIndexState, rebuildWikiGraphLibraryIndex, ArchiveFindOptions, ArchiveCollectionOptions, readWikiGraphLibraryPage, ArchivePage, listRelatedWikiGraphLibraryObjects, ArchivePack } from 'wiki-graph-core';
10
- export { ArchiveBacklinkBucket, ArchiveBacklinks, ArchiveCollectionOptions, ArchiveCollectionResult, ArchiveEvidence, ArchiveEvidenceItem, ArchiveFindEvidencePreview, ArchiveFindHit, ArchiveFindOptions, ArchiveFindResult, ArchiveListItem, ArchivePack, ArchivePage, ArchiveRelatedResult, ArchiveSourceLocator, ArchiveSourceLocatorResult, ArchiveTriplePattern, BookMeta, BuildJobEvent, BuildJobProgressCounter, BuildJobTarget, ChapterDetails, ChapterEntry, ChapterStage, ChapterTree, ChapterTreeApplyResult, ContinuationCursor, DEFAULT_EXTRACTION_PROMPT, DEFAULT_KNOWLEDGE_GRAPH_RECALL_PROMPT, IndexArtifactKind, LLMPaymentRequiredError, LocatedWikiGraphUri, ParsedWikiGraphLibraryUri, QueryIndexScope, SearchIndexEmbeddingProvider, SourceArtifactInput, WIKI_GRAPH_URI_PREFIX, WikiGraphError, WikiGraphLLMOptions, WikiGraphLibraryIndexState, WikiGraphMaintenanceUpgradeResult, WikiGraphProgressCallback, WikiGraphProgressEvent, WikispineProvider, formatError, formatLocatedChapterResourceUri, formatLocatedChapterSourceCollectionUri, formatLocatedChapterUri, formatLocatedWikiGraphUri, formatWikiGraphCommandUri, formatWikiGraphLibraryUri, isSourceLocatorScopeUri, isWikiGraphLibraryUri, parseChapterPath, parseChapterTreeInput, parseChapterUriPath, parseLocatedWikiGraphUri, parseSourceTextJsonl, parseWikiGraphLibraryUri, parseWikiGraphUriSyntax, resolveExtractionPrompt, resolveKnowledgeGraphRecallPrompt } from 'wiki-graph-core';
10
+ export { ArchiveBacklinkBucket, ArchiveBacklinks, ArchiveCollectionOptions, ArchiveCollectionResult, ArchiveEvidence, ArchiveEvidenceItem, ArchiveFindEvidencePreview, ArchiveFindHit, ArchiveFindOptions, ArchiveFindResult, ArchiveListItem, ArchivePack, ArchivePage, ArchiveRelatedResult, ArchiveSourceLocator, ArchiveSourceLocatorResult, ArchiveTriplePattern, BookMeta, BuildJobEvent, BuildJobProgressCounter, BuildJobTarget, ChapterDetails, ChapterEntry, ChapterStage, ChapterTree, ChapterTreeApplyResult, ContinuationCursor, DEFAULT_EXTRACTION_PROMPT, DEFAULT_KNOWLEDGE_GRAPH_RECALL_PROMPT, Directory, File, FileReader, FileWriter, IndexArtifactKind, LLMPaymentRequiredError, LocatedWikiGraphUri, ParsedSourceLocatorFragment, ParsedWikiGraphLibraryUri, ParsedWikiGraphUri, QueryIndexScope, ReadonlyFile, SearchIndexEmbeddingProvider, SearchIndexQueryMode, SourceArtifactInput, WIKI_GRAPH_URI_PREFIX, WikiGraphError, WikiGraphLLMOptions, WikiGraphLibraryIndexState, WikiGraphMaintenanceUpgradeResult, WikiGraphPlatform, WikiGraphProgressCallback, WikiGraphProgressEvent, WikiGraphStorage, WikispineProvider, formatError, formatLocatedChapterResourceUri, formatLocatedChapterSourceCollectionUri, formatLocatedChapterUri, formatLocatedWikiGraphUri, formatSourceArtifactUri, formatSourceLocatorFragment, formatWikiGraphCommandUri, formatWikiGraphLibraryUri, isSourceLocatorScopeUri, isWikiGraphJobUri, isWikiGraphLibraryUri, isWikiGraphUri, parseChapterPath, parseChapterTreeInput, parseChapterUriPath, parseLocatedWikiGraphUri, parseSourceLocatorFragment, parseSourceTextJsonl, parseWikiGraphLibraryUri, parseWikiGraphUriSyntax, requireArchiveUri, requireLocatedObjectOrArchiveUri, requireLocatedObjectUri, resolveExtractionPrompt, resolveKnowledgeGraphRecallPrompt } from 'wiki-graph-core';
11
11
  import { WikiGraphConversionManager } from './conversions.js';
12
12
  export { WikiGraphConversionFormat, WikiGraphConversionInput, WikiGraphConversionOptions, WikiGraphConversionResult, WikiGraphSourceFormat } from './conversions.js';
13
13
  export { WikiGraphQueueWorkerOptions, requireKnowledgeGraphWikispineConfig, runWikiGraphQueueWorker } from './default-worker.js';
14
14
  export { DANGEROUS_RUNTIME_ENV_NAMES, WikiGraphEntryEnvPolicy, WikiGraphEntryRuntimeContext, WikiGraphEntryRuntimeOptions, createEntryRuntimeContext } from './entry-context.js';
15
15
  export { QueryEmbeddingResult, WikiGraphEmbeddingConfig, WikiGraphEmbeddingProviderName, buildSearchIndexEmbeddingProvider, embedQueryText, embedQueryTextWithLocalConfig, readWikiGraphEmbeddingConfig } from './embedding.js';
16
+ import { W as WikiGraphSDKHost } from './host-IbqJ8WSV.js';
16
17
  export { buildWikiGraphLLMOptions } from './llm.js';
17
18
  import { WikiGraphMaintenanceManager } from './maintenance.js';
18
19
  export { WikiGraphLegacyMigrationResult, WikiGraphMaintenanceTarget } from './maintenance.js';
19
- export { NodeDirectory, NodeFile, createNodeTemplateEnvironment, createNodeWikiGraphStorage, ensureNodeWikiGraphPlatform, getNodeResourcePath, installNodeWikiGraphPlatform, nodeWikiGraphPlatform, withNodeWikiGraphStorage, writeNodeFileHandle } from './node-platform.js';
20
+ export { NodeDirectory, NodeFile, NodeWikiGraphPlatformOptions, NodeWikiGraphStorageOptions, createNodeTemplateEnvironment, createNodeWikiGraphPlatform, createNodeWikiGraphStorage, ensureNodeWikiGraphPlatform, getNodeResourcePath, installNodeWikiGraphPlatform, nodeWikiGraphPlatform, withNodeWikiGraphStorage, writeNodeFileHandle } from './node-platform.js';
20
21
  export { DEFAULT_GENERATION_JOB_CONCURRENCY, DEFAULT_GENERATION_REQUEST_CONCURRENCY, GenerationConcurrency, GenerationPerformanceHint, GenerationPlanningCost, createGenerationPerformanceHints, formatGenerationPlanningDuration, formatGenerationPlanningModel, planGenerationTask } from './planning.js';
21
22
  import { W as WikiGraphSDKProviders } from './stage-BnWI3Rqt.js';
22
23
  export { a as WikiGraphEmbeddingProvider, b as WikiGraphLLMMessage, c as WikiGraphLLMProvider, d as WikiGraphLLMProviderEvent, e as WikiGraphLLMProviderOptions, f as createStageLLM, l as loadRequiredStageConfig, r as resolveWikiGraphLLMJSON } from './stage-BnWI3Rqt.js';
23
24
  export { HostedProviderScope, WikiGraphLLMConfig, WikiGraphProvider, WikiGraphRuntimeConfig, loadWikiGraphRuntimeConfig, resolveHostedProviderEndpoint, resolveWikispineConfig } from './runtime-config.js';
24
25
  export { nodeWikispineCommandRunner } from './wikispine.js';
25
26
  import 'zod';
27
+ import 'wiki-graph-core/platform';
26
28
  import 'node:fs/promises';
27
29
  import 'nunjucks';
28
- import 'wiki-graph-core/platform';
29
30
 
30
31
  interface WikiGraphProviderTestResult {
31
32
  readonly durationMs: number;
@@ -75,6 +76,7 @@ interface WikiGraphContinuationContext {
75
76
  readonly ids?: readonly string[];
76
77
  readonly indexScope: QueryIndexScope;
77
78
  readonly libraryQuery?: "archive-members" | "objects";
79
+ readonly match?: "all" | "any";
78
80
  readonly order?: "doc-asc" | "doc-desc";
79
81
  readonly query?: string;
80
82
  readonly queryMode?: SearchIndexQueryMode;
@@ -212,6 +214,7 @@ interface WikiGraphSDKRuntimeContext {
212
214
  readonly cwd: string;
213
215
  readonly env: NodeJS.ProcessEnv;
214
216
  readonly envPolicy: WikiGraphSDKEnvPolicy;
217
+ readonly host?: WikiGraphSDKHost;
215
218
  readonly providers?: WikiGraphSDKProviders;
216
219
  readonly stateDir?: string | undefined;
217
220
  }
@@ -224,6 +227,7 @@ interface WikiGraphSDKOptions {
224
227
  readonly cwd?: string;
225
228
  readonly env?: NodeJS.ProcessEnv;
226
229
  readonly envPolicy?: WikiGraphSDKEnvPolicy;
230
+ readonly host?: WikiGraphSDKHost;
227
231
  readonly providers?: WikiGraphSDKProviders;
228
232
  readonly stateDir?: string;
229
233
  }
@@ -244,4 +248,4 @@ declare class WikiGraphSDK implements WikiGraphJobRuntime {
244
248
  }
245
249
  declare function createWikiGraphSDK(options?: WikiGraphSDKOptions): WikiGraphSDK;
246
250
 
247
- export { LocalConfigObject, LocalConfigSection, WikiGraphArchiveManager, WikiGraphArchiveTarget, WikiGraphConfigManager, type WikiGraphContinuationContext, WikiGraphContinuationManager, type WikiGraphContinuationOptions, type WikiGraphContinuationPage, WikiGraphConversionManager, WikiGraphJobManager, WikiGraphJobRuntime, WikiGraphLibrary, type WikiGraphLibraryAddArchiveOptions, type WikiGraphLibraryArchiveContent, type WikiGraphLibraryArchiveReadOptions, type WikiGraphLibraryArchiveSnapshot, type WikiGraphLibraryEvidenceOptions, WikiGraphLibraryManager, type WikiGraphLibraryMoveArchiveOptions, type WikiGraphLibraryPageOptions, type WikiGraphLibraryRelatedOptions, type WikiGraphLibraryReplaceArchiveOptions, type WikiGraphLibraryScanSnapshot, type WikiGraphLibrarySearchOptions, type WikiGraphLibrarySnapshot, type WikiGraphLibraryTarget, WikiGraphMaintenanceManager, type WikiGraphProviderTestResult, WikiGraphSDK, type WikiGraphSDKEnvPolicy, type WikiGraphSDKOptions, WikiGraphSDKProviders, type WikiGraphSDKRuntimeContext, createWikiGraphSDK, getWikiGraphSDKProviders, getWikiGraphSDKRuntimeContext, getWikiGraphSDKStateDir, withWikiGraphSDKRuntimeContext };
251
+ export { LocalConfigObject, LocalConfigSection, WikiGraphArchiveManager, WikiGraphArchiveTarget, WikiGraphConfigManager, type WikiGraphContinuationContext, WikiGraphContinuationManager, type WikiGraphContinuationOptions, type WikiGraphContinuationPage, WikiGraphConversionManager, WikiGraphJobManager, WikiGraphJobRuntime, WikiGraphLibrary, type WikiGraphLibraryAddArchiveOptions, type WikiGraphLibraryArchiveContent, type WikiGraphLibraryArchiveReadOptions, type WikiGraphLibraryArchiveSnapshot, type WikiGraphLibraryEvidenceOptions, WikiGraphLibraryManager, type WikiGraphLibraryMoveArchiveOptions, type WikiGraphLibraryPageOptions, type WikiGraphLibraryRelatedOptions, type WikiGraphLibraryReplaceArchiveOptions, type WikiGraphLibraryScanSnapshot, type WikiGraphLibrarySearchOptions, type WikiGraphLibrarySnapshot, type WikiGraphLibraryTarget, WikiGraphMaintenanceManager, type WikiGraphProviderTestResult, WikiGraphSDK, type WikiGraphSDKEnvPolicy, WikiGraphSDKHost, type WikiGraphSDKOptions, WikiGraphSDKProviders, type WikiGraphSDKRuntimeContext, createWikiGraphSDK, getWikiGraphSDKProviders, getWikiGraphSDKRuntimeContext, getWikiGraphSDKStateDir, withWikiGraphSDKRuntimeContext };
package/dist/index.js CHANGED
@@ -142,6 +142,7 @@ import * as yauzl from "yauzl";
142
142
  import * as yazl from "yazl";
143
143
  import { Environment, Loader } from "nunjucks";
144
144
  import {
145
+ getWikiGraphPlatform,
145
146
  getWikiGraphStorage,
146
147
  installWikiGraphPlatform,
147
148
  installWikiGraphStorage,
@@ -764,6 +765,9 @@ var nodeWikiGraphPlatform = {
764
765
  write: writeNodeZip
765
766
  }
766
767
  };
768
+ function createNodeWikiGraphPlatform(options = {}) {
769
+ return options.lifecycle === void 0 ? nodeWikiGraphPlatform : { ...nodeWikiGraphPlatform, lifecycle: options.lifecycle };
770
+ }
767
771
  var NodeTemplateLoader = class extends Loader {
768
772
  #dataDirectory;
769
773
  constructor(dataDirectory) {
@@ -809,10 +813,15 @@ function resolveNodeDataDirectory() {
809
813
  directory = parent;
810
814
  }
811
815
  }
812
- function createNodeWikiGraphStorage(stateRoot = pathModule.join(os.homedir(), ".wikigraph")) {
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;
813
822
  return {
814
- library: new NodeDirectory(stateRoot),
815
- documentStore: new NodeDirectory(pathModule.join(stateRoot, "documents"))
823
+ library: new NodeDirectory(libraryRoot),
824
+ documentStore: new NodeDirectory(documentStoreRoot)
816
825
  };
817
826
  }
818
827
  function installNodeWikiGraphPlatform(stateRoot) {
@@ -820,7 +829,11 @@ function installNodeWikiGraphPlatform(stateRoot) {
820
829
  installWikiGraphStorage(createNodeWikiGraphStorage(stateRoot));
821
830
  }
822
831
  function ensureNodeWikiGraphPlatform() {
823
- installWikiGraphPlatform(nodeWikiGraphPlatform);
832
+ try {
833
+ getWikiGraphPlatform();
834
+ } catch {
835
+ installWikiGraphPlatform(nodeWikiGraphPlatform);
836
+ }
824
837
  try {
825
838
  getWikiGraphStorage();
826
839
  } catch {
@@ -871,13 +884,15 @@ function getWikiGraphSDKRuntimeContext() {
871
884
  };
872
885
  }
873
886
  function getWikiGraphSDKStateDir() {
874
- return getWikiGraphSDKRuntimeContext().stateDir;
887
+ const context = getWikiGraphSDKRuntimeContext();
888
+ return context.host?.stateDir ?? context.stateDir;
875
889
  }
876
890
  function getWikiGraphSDKProviders() {
877
891
  return getWikiGraphSDKRuntimeContext().providers ?? {};
878
892
  }
879
893
 
880
894
  // src/local-config.ts
895
+ import { mkdir as mkdir2 } from "fs/promises";
881
896
  import { join as join2 } from "path";
882
897
  import { homedir as homedir2 } from "os";
883
898
  var LOCAL_CONFIG_SECTIONS = [
@@ -978,13 +993,10 @@ function validateLocalConfigSection(section, value) {
978
993
  }
979
994
  }
980
995
  async function withLocalConfigDatabase(operation) {
996
+ const stateDir = getWikiGraphSDKStateDir() ?? join2(homedir2(), ".wikigraph");
997
+ await mkdir2(stateDir, { recursive: true });
981
998
  const database = await openSharedStateDatabase(
982
- new NodeFile(
983
- join2(
984
- getWikiGraphSDKStateDir() ?? join2(homedir2(), ".wikigraph"),
985
- "core.sqlite"
986
- )
987
- ),
999
+ new NodeFile(join2(stateDir, "core.sqlite")),
988
1000
  LOCAL_CONFIG_SCHEMA_SQL
989
1001
  );
990
1002
  try {
@@ -2309,6 +2321,13 @@ var WikiGraphArchiveHandle = class {
2309
2321
  );
2310
2322
  return status;
2311
2323
  }
2324
+ /** Clear cached search sessions without changing the archive index. */
2325
+ async clearSearchSessions(options = {}) {
2326
+ await this.#runtime.run(
2327
+ async () => await deleteArchiveSearchSessions(this.path),
2328
+ options.signal
2329
+ );
2330
+ }
2312
2331
  async listChapters(options = {}) {
2313
2332
  return await this.#readDocument(
2314
2333
  async (document) => await listChapters2(document),
@@ -3255,6 +3274,8 @@ async function createFindOptions(cursor, limit) {
3255
3274
  cursor: cursor.cursor,
3256
3275
  ...cursor.evidenceLimit === void 0 ? {} : { evidenceLimit: cursor.evidenceLimit },
3257
3276
  limit,
3277
+ ...cursor.match === void 0 ? {} : { match: cursor.match },
3278
+ ...cursor.order === void 0 ? {} : { order: cursor.order },
3258
3279
  ...cursor.queryMode === void 0 ? {} : { queryMode: cursor.queryMode },
3259
3280
  ...cursor.skipUnindexed === void 0 ? {} : { skipUnindexed: cursor.skipUnindexed },
3260
3281
  ...cursor.sourceContext === void 0 ? {} : { sourceContext: cursor.sourceContext },
@@ -3358,6 +3379,8 @@ function createContinuationPayload(context, cursor) {
3358
3379
  indexScope: context.indexScope,
3359
3380
  kind: "search",
3360
3381
  ...createLibraryQueryPayload(context),
3382
+ ...context.match === void 0 ? {} : { match: context.match },
3383
+ ...context.order === void 0 ? {} : { order: context.order },
3361
3384
  ...context.query === void 0 ? {} : { query: context.query },
3362
3385
  ...context.queryMode === void 0 ? {} : { queryMode: context.queryMode },
3363
3386
  ...context.skipUnindexed === void 0 ? {} : { skipUnindexed: context.skipUnindexed },
@@ -3584,16 +3607,69 @@ import {
3584
3607
  resolveChapterPathReadonly as resolveChapterPathReadonly2,
3585
3608
  WikiGraphArchiveFile as WikiGraphArchiveFile4
3586
3609
  } from "wiki-graph-core";
3610
+
3611
+ // src/host.ts
3612
+ import {
3613
+ installWikiGraphPlatform as installWikiGraphPlatform2,
3614
+ withWikiGraphStorage as withWikiGraphStorage2
3615
+ } from "wiki-graph-core/platform";
3616
+ function prepareWikiGraphSDKHost(host) {
3617
+ if (host?.platform === void 0) {
3618
+ ensureNodeWikiGraphPlatform();
3619
+ return;
3620
+ }
3621
+ installWikiGraphPlatform2(host.platform);
3622
+ }
3623
+ function assertWikiGraphSDKHostOptions(options) {
3624
+ if (options.host?.storage !== void 0 && options.host.stateDir === void 0) {
3625
+ throw new TypeError(
3626
+ "Wiki Graph SDK host.storage requires host.stateDir so SDK configuration cannot fall back to the default user state directory."
3627
+ );
3628
+ }
3629
+ if (options.stateDir !== void 0 && (options.host?.stateDir !== void 0 || options.host?.storage !== void 0)) {
3630
+ throw new TypeError(
3631
+ "Wiki Graph SDK host state/storage and top-level stateDir cannot be used together. Put the state directory in host.stateDir when providing host.storage."
3632
+ );
3633
+ }
3634
+ }
3635
+ async function withWikiGraphSDKHost(options, operation) {
3636
+ const current = getWikiGraphSDKRuntimeContext();
3637
+ const effective = {
3638
+ ...options.host === void 0 ? current.host === void 0 ? {} : { host: current.host } : { host: options.host },
3639
+ ...options.stateDir === void 0 ? current.stateDir === void 0 ? {} : { stateDir: current.stateDir } : { stateDir: options.stateDir }
3640
+ };
3641
+ assertWikiGraphSDKHostOptions(effective);
3642
+ prepareWikiGraphSDKHost(effective.host);
3643
+ const runWithContext = async () => await withWikiGraphSDKRuntimeContext(
3644
+ {
3645
+ ...current,
3646
+ ...effective.host === void 0 ? {} : { host: effective.host },
3647
+ ...effective.stateDir === void 0 ? {} : { stateDir: effective.stateDir }
3648
+ },
3649
+ operation
3650
+ );
3651
+ if (effective.host?.storage !== void 0) {
3652
+ return await withWikiGraphStorage2(effective.host.storage, runWithContext);
3653
+ }
3654
+ return await withNodeWikiGraphStorage(
3655
+ effective.host?.stateDir ?? effective.stateDir,
3656
+ runWithContext
3657
+ );
3658
+ }
3659
+
3660
+ // src/worker.ts
3587
3661
  import {
3588
3662
  applyChapterJobArtifactFile as applyChapterJobArtifactFile2,
3589
3663
  createLocalChapterJobFileExecutor,
3590
3664
  writeChapterJobInputFile as writeChapterJobInputFile2
3591
3665
  } from "wiki-graph-core/worker";
3592
3666
  async function runBuildJobWorker(options) {
3593
- installNodeWikiGraphPlatform();
3594
- const { stateDir, ...coreOptions } = options;
3595
- await withNodeWikiGraphStorage(
3596
- stateDir,
3667
+ const { host, stateDir, ...coreOptions } = options;
3668
+ await withWikiGraphSDKHost(
3669
+ {
3670
+ ...host === void 0 ? {} : { host },
3671
+ ...stateDir === void 0 ? {} : { stateDir }
3672
+ },
3597
3673
  async () => await runCoreBuildJobWorker(coreOptions)
3598
3674
  );
3599
3675
  }
@@ -4534,7 +4610,7 @@ import {
4534
4610
  scanWikiGraphLibrary,
4535
4611
  withWikiGraphLibraryLock
4536
4612
  } from "wiki-graph-core";
4537
- import { mkdir as mkdir2 } from "fs/promises";
4613
+ import { mkdir as mkdir3 } from "fs/promises";
4538
4614
  async function resolveQueryEmbeddingProvider(queryMode) {
4539
4615
  if (queryMode === "fts") return void 0;
4540
4616
  const provider = await createConfiguredEmbeddingProvider();
@@ -4553,7 +4629,7 @@ var WikiGraphLibraryManager = class {
4553
4629
  async create(folder) {
4554
4630
  const record = await this.#runtime.run(async () => {
4555
4631
  const path = resolveWikiGraphRuntimePath(folder);
4556
- await mkdir2(path);
4632
+ await mkdir3(path);
4557
4633
  return await createWikiGraphLibrary({ folder: new NodeDirectory(path) });
4558
4634
  });
4559
4635
  return new WikiGraphLibrary(this.#runtime, record);
@@ -5073,11 +5149,13 @@ var WikiGraphSDK = class {
5073
5149
  libraries;
5074
5150
  maintenance;
5075
5151
  constructor(options = {}) {
5076
- ensureNodeWikiGraphPlatform();
5152
+ assertWikiGraphSDKHostOptions(options);
5153
+ prepareWikiGraphSDKHost(options.host);
5077
5154
  this.#context = {
5078
5155
  cwd: options.cwd ?? process.cwd(),
5079
5156
  env: { ...process.env, ...options.env },
5080
5157
  envPolicy: options.envPolicy ?? "production",
5158
+ ...options.host === void 0 ? {} : { host: options.host },
5081
5159
  providers: { ...options.providers },
5082
5160
  ...options.stateDir === void 0 ? {} : { stateDir: options.stateDir }
5083
5161
  };
@@ -5103,8 +5181,11 @@ var WikiGraphSDK = class {
5103
5181
  }
5104
5182
  return await operation();
5105
5183
  });
5106
- const result = this.#context.stateDir === void 0 ? await runWithContext() : await withNodeWikiGraphStorage(
5107
- this.#context.stateDir,
5184
+ const result = await withWikiGraphSDKHost(
5185
+ {
5186
+ ...this.#context.host === void 0 ? {} : { host: this.#context.host },
5187
+ ...this.#context.stateDir === void 0 ? {} : { stateDir: this.#context.stateDir }
5188
+ },
5108
5189
  runWithContext
5109
5190
  );
5110
5191
  throwIfAborted2(signal);
@@ -5132,8 +5213,12 @@ import {
5132
5213
  formatLocatedChapterSourceCollectionUri,
5133
5214
  formatLocatedChapterUri as formatLocatedChapterUri3,
5134
5215
  formatLocatedWikiGraphUri as formatLocatedWikiGraphUri3,
5216
+ formatSourceArtifactUri,
5217
+ formatSourceLocatorFragment,
5135
5218
  formatWikiGraphCommandUri,
5136
5219
  formatWikiGraphLibraryUri as formatWikiGraphLibraryUri3,
5220
+ isWikiGraphJobUri,
5221
+ isWikiGraphUri,
5137
5222
  isSourceLocatorScopeUri as isSourceLocatorScopeUri2,
5138
5223
  isWikiGraphLibraryUri,
5139
5224
  parseChapterPath,
@@ -5141,8 +5226,12 @@ import {
5141
5226
  parseChapterUriPath,
5142
5227
  parseLocatedWikiGraphUri as parseLocatedWikiGraphUri3,
5143
5228
  parseSourceTextJsonl,
5229
+ parseSourceLocatorFragment,
5144
5230
  parseWikiGraphLibraryUri as parseWikiGraphLibraryUri4,
5145
- parseWikiGraphUriSyntax
5231
+ parseWikiGraphUriSyntax,
5232
+ requireArchiveUri,
5233
+ requireLocatedObjectOrArchiveUri,
5234
+ requireLocatedObjectUri
5146
5235
  } from "wiki-graph-core";
5147
5236
  export {
5148
5237
  DANGEROUS_RUNTIME_ENV_NAMES,
@@ -5175,6 +5264,7 @@ export {
5175
5264
  createEntryRuntimeContext,
5176
5265
  createGenerationPerformanceHints,
5177
5266
  createNodeTemplateEnvironment,
5267
+ createNodeWikiGraphPlatform,
5178
5268
  createNodeWikiGraphStorage,
5179
5269
  createStageLLM,
5180
5270
  createWikiGraphSDK,
@@ -5189,6 +5279,8 @@ export {
5189
5279
  formatLocatedChapterSourceCollectionUri,
5190
5280
  formatLocatedChapterUri3 as formatLocatedChapterUri,
5191
5281
  formatLocatedWikiGraphUri3 as formatLocatedWikiGraphUri,
5282
+ formatSourceArtifactUri,
5283
+ formatSourceLocatorFragment,
5192
5284
  formatWikiGraphCommandUri,
5193
5285
  formatWikiGraphLibraryUri3 as formatWikiGraphLibraryUri,
5194
5286
  getNodeResourcePath,
@@ -5198,7 +5290,9 @@ export {
5198
5290
  inspectWikiGraphArchive,
5199
5291
  installNodeWikiGraphPlatform,
5200
5292
  isSourceLocatorScopeUri2 as isSourceLocatorScopeUri,
5293
+ isWikiGraphJobUri,
5201
5294
  isWikiGraphLibraryUri,
5295
+ isWikiGraphUri,
5202
5296
  loadRequiredStageConfig,
5203
5297
  loadWikiGraphRuntimeConfig,
5204
5298
  maskLocalConfigSection,
@@ -5210,6 +5304,7 @@ export {
5210
5304
  parseChapterUriPath,
5211
5305
  parseLocalConfigSection,
5212
5306
  parseLocatedWikiGraphUri3 as parseLocatedWikiGraphUri,
5307
+ parseSourceLocatorFragment,
5213
5308
  parseSourceTextJsonl,
5214
5309
  parseWikiGraphLibraryUri4 as parseWikiGraphLibraryUri,
5215
5310
  parseWikiGraphUriSyntax,
@@ -5218,7 +5313,10 @@ export {
5218
5313
  readLocalConfigSection,
5219
5314
  readWikiGraphEmbeddingConfig,
5220
5315
  replaceLocalConfigSection,
5316
+ requireArchiveUri,
5221
5317
  requireKnowledgeGraphWikispineConfig,
5318
+ requireLocatedObjectOrArchiveUri,
5319
+ requireLocatedObjectUri,
5222
5320
  resolveExtractionPrompt,
5223
5321
  resolveHostedProviderEndpoint,
5224
5322
  resolveKnowledgeGraphRecallPrompt,