wiki-graph-sdk 0.8.2 → 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 (49) hide show
  1. package/README.md +8 -3
  2. package/dist/archives.cjs +18 -19
  3. package/dist/archives.cjs.map +1 -1
  4. package/dist/archives.js +6 -7
  5. package/dist/archives.js.map +1 -1
  6. package/dist/conversions.cjs +11 -12
  7. package/dist/conversions.cjs.map +1 -1
  8. package/dist/conversions.js +6 -7
  9. package/dist/conversions.js.map +1 -1
  10. package/dist/default-worker.cjs +40 -17
  11. package/dist/default-worker.cjs.map +1 -1
  12. package/dist/default-worker.js +37 -14
  13. package/dist/default-worker.js.map +1 -1
  14. package/dist/embedding.cjs +6 -7
  15. package/dist/embedding.cjs.map +1 -1
  16. package/dist/embedding.js +6 -7
  17. package/dist/embedding.js.map +1 -1
  18. package/dist/gc.cjs +61 -9
  19. package/dist/gc.cjs.map +1 -1
  20. package/dist/gc.d.ts +1 -1
  21. package/dist/gc.js +61 -9
  22. package/dist/gc.js.map +1 -1
  23. package/dist/host-IbqJ8WSV.d.ts +18 -0
  24. package/dist/index.cjs +48 -28
  25. package/dist/index.cjs.map +1 -1
  26. package/dist/index.d.ts +1 -1
  27. package/dist/index.js +36 -16
  28. package/dist/index.js.map +1 -1
  29. package/dist/local-config.cjs +6 -7
  30. package/dist/local-config.cjs.map +1 -1
  31. package/dist/local-config.js +6 -7
  32. package/dist/local-config.js.map +1 -1
  33. package/dist/maintenance.cjs.map +1 -1
  34. package/dist/maintenance.js.map +1 -1
  35. package/dist/runtime-config.cjs +6 -7
  36. package/dist/runtime-config.cjs.map +1 -1
  37. package/dist/runtime-config.js +6 -7
  38. package/dist/runtime-config.js.map +1 -1
  39. package/dist/stage.cjs +6 -7
  40. package/dist/stage.cjs.map +1 -1
  41. package/dist/stage.js +6 -7
  42. package/dist/stage.js.map +1 -1
  43. package/dist/worker.cjs +55 -31
  44. package/dist/worker.cjs.map +1 -1
  45. package/dist/worker.d.ts +1 -1
  46. package/dist/worker.js +61 -37
  47. package/dist/worker.js.map +1 -1
  48. package/package.json +2 -2
  49. package/dist/host-pQiVAKEY.d.ts +0 -10
@@ -0,0 +1,18 @@
1
+ import { WikiGraphPlatform, WikiGraphStorage } from 'wiki-graph-core/platform';
2
+
3
+ interface WikiGraphSDKHostBase {
4
+ /** Process-wide runtime services. Concurrent SDKs must use one compatible platform. */
5
+ readonly platform?: WikiGraphPlatform;
6
+ }
7
+ type WikiGraphSDKHost = WikiGraphSDKHostBase & ({
8
+ /** Node state root for SDK configuration and other host-local state. */
9
+ readonly stateDir: string;
10
+ /** Storage roots scoped to this SDK instance or standalone operation. */
11
+ readonly storage: WikiGraphStorage;
12
+ } | {
13
+ /** Node state root used by the default Node storage layout. */
14
+ readonly stateDir?: string;
15
+ readonly storage?: undefined;
16
+ });
17
+
18
+ export type { WikiGraphSDKHost as W };
package/dist/index.cjs CHANGED
@@ -129,7 +129,7 @@ module.exports = __toCommonJS(src_exports);
129
129
 
130
130
  // src/archive/archive.ts
131
131
  var import_crypto2 = require("crypto");
132
- var import_promises4 = require("fs/promises");
132
+ var import_promises5 = require("fs/promises");
133
133
  var import_os3 = require("os");
134
134
  var import_path5 = require("path");
135
135
  var import_stream = require("stream");
@@ -138,7 +138,7 @@ var import_wiki_graph_core7 = require("wiki-graph-core");
138
138
  // src/conversions.ts
139
139
  var import_crypto = require("crypto");
140
140
  var import_fs = require("fs");
141
- var import_promises3 = require("fs/promises");
141
+ var import_promises4 = require("fs/promises");
142
142
  var import_path4 = require("path");
143
143
  var import_wiki_graph_core3 = require("wiki-graph-core");
144
144
 
@@ -964,13 +964,15 @@ function getWikiGraphSDKRuntimeContext() {
964
964
  };
965
965
  }
966
966
  function getWikiGraphSDKStateDir() {
967
- return getWikiGraphSDKRuntimeContext().stateDir;
967
+ const context = getWikiGraphSDKRuntimeContext();
968
+ return context.host?.stateDir ?? context.stateDir;
968
969
  }
969
970
  function getWikiGraphSDKProviders() {
970
971
  return getWikiGraphSDKRuntimeContext().providers ?? {};
971
972
  }
972
973
 
973
974
  // src/local-config.ts
975
+ var import_promises2 = require("fs/promises");
974
976
  var import_path = require("path");
975
977
  var import_os = require("os");
976
978
  var LOCAL_CONFIG_SECTIONS = [
@@ -1071,13 +1073,10 @@ function validateLocalConfigSection(section, value) {
1071
1073
  }
1072
1074
  }
1073
1075
  async function withLocalConfigDatabase(operation) {
1076
+ const stateDir = getWikiGraphSDKStateDir() ?? (0, import_path.join)((0, import_os.homedir)(), ".wikigraph");
1077
+ await (0, import_promises2.mkdir)(stateDir, { recursive: true });
1074
1078
  const database = await (0, import_wiki_graph_core.openSharedStateDatabase)(
1075
- new NodeFile(
1076
- (0, import_path.join)(
1077
- getWikiGraphSDKStateDir() ?? (0, import_path.join)((0, import_os.homedir)(), ".wikigraph"),
1078
- "core.sqlite"
1079
- )
1080
- ),
1079
+ new NodeFile((0, import_path.join)(stateDir, "core.sqlite")),
1081
1080
  LOCAL_CONFIG_SCHEMA_SQL
1082
1081
  );
1083
1082
  try {
@@ -1487,7 +1486,7 @@ function resolveWikiGraphRuntimePath(path) {
1487
1486
  }
1488
1487
 
1489
1488
  // src/archive/target.ts
1490
- var import_promises2 = require("fs/promises");
1489
+ var import_promises3 = require("fs/promises");
1491
1490
  var import_path3 = require("path");
1492
1491
  var import_wiki_graph_core2 = require("wiki-graph-core");
1493
1492
  var WikiGraphArchiveOwnershipError = class extends Error {
@@ -1616,7 +1615,7 @@ function withObjectUri(archiveLocator, objectUri) {
1616
1615
  }
1617
1616
  async function canonicalPath(path) {
1618
1617
  try {
1619
- return await (0, import_promises2.realpath)(path);
1618
+ return await (0, import_promises3.realpath)(path);
1620
1619
  } catch {
1621
1620
  const absolute = (0, import_path3.resolve)(path);
1622
1621
  const parent = (0, import_path3.dirname)(absolute);
@@ -1667,7 +1666,7 @@ function requireUnambiguousManagedMatch(path, matches) {
1667
1666
  }
1668
1667
  async function readFileIdentity(path) {
1669
1668
  try {
1670
- const value = await (0, import_promises2.stat)(path);
1669
+ const value = await (0, import_promises3.stat)(path);
1671
1670
  return `${value.dev}:${value.ino}`;
1672
1671
  } catch {
1673
1672
  return void 0;
@@ -1791,7 +1790,7 @@ async function prepareDigestDirectory(path, required) {
1791
1790
  if (!required || normalized === void 0 || normalized === "")
1792
1791
  return void 0;
1793
1792
  const resolved = resolveWikiGraphRuntimePath(normalized);
1794
- await (0, import_promises3.rm)(resolved, { force: true, recursive: true });
1793
+ await (0, import_promises4.rm)(resolved, { force: true, recursive: true });
1795
1794
  return new NodeDirectory(resolved);
1796
1795
  }
1797
1796
  async function writeArchive(archive, path, format) {
@@ -2209,10 +2208,10 @@ var WikiGraphArchiveManager = class {
2209
2208
  });
2210
2209
  }
2211
2210
  if (options.replace === true) {
2212
- await (0, import_promises4.rename)(outputPath, path);
2211
+ await (0, import_promises5.rename)(outputPath, path);
2213
2212
  } else {
2214
2213
  try {
2215
- await (0, import_promises4.link)(outputPath, path);
2214
+ await (0, import_promises5.link)(outputPath, path);
2216
2215
  } catch (error) {
2217
2216
  if (isNodeEEXISTError(error)) {
2218
2217
  throw new WikiGraphArchiveExistsError(path);
@@ -2222,7 +2221,7 @@ var WikiGraphArchiveManager = class {
2222
2221
  }
2223
2222
  return { locatedUri: (0, import_wiki_graph_core7.formatLocatedWikiGraphUri)(path), path };
2224
2223
  } finally {
2225
- await (0, import_promises4.rm)(outputPath, { force: true, recursive: true });
2224
+ await (0, import_promises5.rm)(outputPath, { force: true, recursive: true });
2226
2225
  }
2227
2226
  }, options.signal);
2228
2227
  }
@@ -2843,7 +2842,7 @@ function selectChapterSubtree(chapters, rootChapterId, depth) {
2843
2842
  );
2844
2843
  }
2845
2844
  async function createEmptyArchiveFile(path) {
2846
- const directoryPath = await (0, import_promises4.mkdtemp)(
2845
+ const directoryPath = await (0, import_promises5.mkdtemp)(
2847
2846
  (0, import_path5.join)((0, import_os3.tmpdir)(), "wikigraph-archive-write-")
2848
2847
  );
2849
2848
  try {
@@ -2858,7 +2857,7 @@ async function createEmptyArchiveFile(path) {
2858
2857
  }
2859
2858
  await (0, import_wiki_graph_core7.writeWikgArchive)(directory, new NodeFile(path));
2860
2859
  } finally {
2861
- await (0, import_promises4.rm)(directoryPath, { force: true, recursive: true });
2860
+ await (0, import_promises5.rm)(directoryPath, { force: true, recursive: true });
2862
2861
  }
2863
2862
  }
2864
2863
  function isNodeEEXISTError(error) {
@@ -2866,7 +2865,7 @@ function isNodeEEXISTError(error) {
2866
2865
  }
2867
2866
  async function nodePathExists(path) {
2868
2867
  try {
2869
- await (0, import_promises4.stat)(path);
2868
+ await (0, import_promises5.stat)(path);
2870
2869
  return true;
2871
2870
  } catch (error) {
2872
2871
  if (isNodeENOENTError(error)) return false;
@@ -3642,19 +3641,40 @@ function prepareWikiGraphSDKHost(host) {
3642
3641
  (0, import_platform2.installWikiGraphPlatform)(host.platform);
3643
3642
  }
3644
3643
  function assertWikiGraphSDKHostOptions(options) {
3645
- if (options.host?.storage !== void 0 && options.stateDir !== void 0) {
3644
+ if (options.host?.storage !== void 0 && options.host.stateDir === void 0) {
3646
3645
  throw new TypeError(
3647
- "Wiki Graph SDK host.storage and stateDir cannot be used together."
3646
+ "Wiki Graph SDK host.storage requires host.stateDir so SDK configuration cannot fall back to the default user state directory."
3647
+ );
3648
+ }
3649
+ if (options.stateDir !== void 0 && (options.host?.stateDir !== void 0 || options.host?.storage !== void 0)) {
3650
+ throw new TypeError(
3651
+ "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."
3648
3652
  );
3649
3653
  }
3650
3654
  }
3651
3655
  async function withWikiGraphSDKHost(options, operation) {
3652
- assertWikiGraphSDKHostOptions(options);
3653
- prepareWikiGraphSDKHost(options.host);
3654
- if (options.host?.storage !== void 0) {
3655
- return await (0, import_platform2.withWikiGraphStorage)(options.host.storage, operation);
3656
+ const current = getWikiGraphSDKRuntimeContext();
3657
+ const effective = {
3658
+ ...options.host === void 0 ? current.host === void 0 ? {} : { host: current.host } : { host: options.host },
3659
+ ...options.stateDir === void 0 ? current.stateDir === void 0 ? {} : { stateDir: current.stateDir } : { stateDir: options.stateDir }
3660
+ };
3661
+ assertWikiGraphSDKHostOptions(effective);
3662
+ prepareWikiGraphSDKHost(effective.host);
3663
+ const runWithContext = async () => await withWikiGraphSDKRuntimeContext(
3664
+ {
3665
+ ...current,
3666
+ ...effective.host === void 0 ? {} : { host: effective.host },
3667
+ ...effective.stateDir === void 0 ? {} : { stateDir: effective.stateDir }
3668
+ },
3669
+ operation
3670
+ );
3671
+ if (effective.host?.storage !== void 0) {
3672
+ return await (0, import_platform2.withWikiGraphStorage)(effective.host.storage, runWithContext);
3656
3673
  }
3657
- return await withNodeWikiGraphStorage(options.stateDir, operation);
3674
+ return await withNodeWikiGraphStorage(
3675
+ effective.host?.stateDir ?? effective.stateDir,
3676
+ runWithContext
3677
+ );
3658
3678
  }
3659
3679
 
3660
3680
  // src/worker.ts
@@ -4556,7 +4576,7 @@ function forwardAbort(source, target) {
4556
4576
 
4557
4577
  // src/libraries.ts
4558
4578
  var import_wiki_graph_core16 = require("wiki-graph-core");
4559
- var import_promises5 = require("fs/promises");
4579
+ var import_promises6 = require("fs/promises");
4560
4580
  async function resolveQueryEmbeddingProvider(queryMode) {
4561
4581
  if (queryMode === "fts") return void 0;
4562
4582
  const provider = await createConfiguredEmbeddingProvider();
@@ -4575,7 +4595,7 @@ var WikiGraphLibraryManager = class {
4575
4595
  async create(folder) {
4576
4596
  const record = await this.#runtime.run(async () => {
4577
4597
  const path = resolveWikiGraphRuntimePath(folder);
4578
- await (0, import_promises5.mkdir)(path);
4598
+ await (0, import_promises6.mkdir)(path);
4579
4599
  return await (0, import_wiki_graph_core16.createWikiGraphLibrary)({ folder: new NodeDirectory(path) });
4580
4600
  });
4581
4601
  return new WikiGraphLibrary(this.#runtime, record);