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/README.md CHANGED
@@ -23,6 +23,36 @@ for (const job of jobs) {
23
23
  wikiGraph.close();
24
24
  ```
25
25
 
26
+ Electron and other Node hosts may provide their own lifecycle identity and
27
+ storage layout without importing `wiki-graph-core`:
28
+
29
+ ```ts
30
+ import {
31
+ createNodeWikiGraphPlatform,
32
+ createNodeWikiGraphStorage,
33
+ createWikiGraphSDK,
34
+ } from "wiki-graph-sdk";
35
+
36
+ const wikiGraph = createWikiGraphSDK({
37
+ host: {
38
+ platform: createNodeWikiGraphPlatform({ lifecycle }),
39
+ storage: createNodeWikiGraphStorage({
40
+ libraryRoot: "/path/to/home",
41
+ documentStoreRoot: "/path/to/documents",
42
+ }),
43
+ stateDir: "/path/to/state",
44
+ },
45
+ });
46
+ ```
47
+
48
+ Storage and SDK configuration state are scoped to the SDK instance. Platform
49
+ services, including lifecycle, are process-wide; SDK instances in one process
50
+ must use one compatible platform. The top-level `stateDir` remains a shorthand
51
+ for the default Node host. When supplying `host.storage`, put the independent
52
+ configuration root in the required `host.stateDir` field instead. A custom
53
+ `host.storage` without `host.stateDir` is rejected rather than falling back to
54
+ the current user's `~/.wikigraph` directory.
55
+
26
56
  Applications may replace the configured LLM and embedding implementations for
27
57
  one SDK instance:
28
58
 
package/dist/archives.cjs CHANGED
@@ -41,7 +41,7 @@ module.exports = __toCommonJS(archive_exports);
41
41
 
42
42
  // src/archive/archive.ts
43
43
  var import_crypto2 = require("crypto");
44
- var import_promises4 = require("fs/promises");
44
+ var import_promises5 = require("fs/promises");
45
45
  var import_os3 = require("os");
46
46
  var import_path5 = require("path");
47
47
  var import_stream = require("stream");
@@ -50,7 +50,7 @@ var import_wiki_graph_core7 = require("wiki-graph-core");
50
50
  // src/conversions.ts
51
51
  var import_crypto = require("crypto");
52
52
  var import_fs = require("fs");
53
- var import_promises3 = require("fs/promises");
53
+ var import_promises4 = require("fs/promises");
54
54
  var import_path4 = require("path");
55
55
  var import_wiki_graph_core3 = require("wiki-graph-core");
56
56
 
@@ -831,13 +831,15 @@ function getWikiGraphSDKRuntimeContext() {
831
831
  };
832
832
  }
833
833
  function getWikiGraphSDKStateDir() {
834
- return getWikiGraphSDKRuntimeContext().stateDir;
834
+ const context = getWikiGraphSDKRuntimeContext();
835
+ return context.host?.stateDir ?? context.stateDir;
835
836
  }
836
837
  function getWikiGraphSDKProviders() {
837
838
  return getWikiGraphSDKRuntimeContext().providers ?? {};
838
839
  }
839
840
 
840
841
  // src/local-config.ts
842
+ var import_promises2 = require("fs/promises");
841
843
  var import_path = require("path");
842
844
  var import_os = require("os");
843
845
  var LOCAL_CONFIG_SCHEMA_SQL = `
@@ -867,13 +869,10 @@ function validateLocalConfigSection(section, value) {
867
869
  }
868
870
  }
869
871
  async function withLocalConfigDatabase(operation) {
872
+ const stateDir = getWikiGraphSDKStateDir() ?? (0, import_path.join)((0, import_os.homedir)(), ".wikigraph");
873
+ await (0, import_promises2.mkdir)(stateDir, { recursive: true });
870
874
  const database = await (0, import_wiki_graph_core.openSharedStateDatabase)(
871
- new NodeFile(
872
- (0, import_path.join)(
873
- getWikiGraphSDKStateDir() ?? (0, import_path.join)((0, import_os.homedir)(), ".wikigraph"),
874
- "core.sqlite"
875
- )
876
- ),
875
+ new NodeFile((0, import_path.join)(stateDir, "core.sqlite")),
877
876
  LOCAL_CONFIG_SCHEMA_SQL
878
877
  );
879
878
  try {
@@ -1271,7 +1270,7 @@ function resolveWikiGraphRuntimePath(path) {
1271
1270
  }
1272
1271
 
1273
1272
  // src/archive/target.ts
1274
- var import_promises2 = require("fs/promises");
1273
+ var import_promises3 = require("fs/promises");
1275
1274
  var import_path3 = require("path");
1276
1275
  var import_wiki_graph_core2 = require("wiki-graph-core");
1277
1276
  var WikiGraphArchiveOwnershipError = class extends Error {
@@ -1370,7 +1369,7 @@ async function resolveLibraryLocation(target) {
1370
1369
  }
1371
1370
  async function canonicalPath(path) {
1372
1371
  try {
1373
- return await (0, import_promises2.realpath)(path);
1372
+ return await (0, import_promises3.realpath)(path);
1374
1373
  } catch {
1375
1374
  const absolute = (0, import_path3.resolve)(path);
1376
1375
  const parent = (0, import_path3.dirname)(absolute);
@@ -1421,7 +1420,7 @@ function requireUnambiguousManagedMatch(path, matches) {
1421
1420
  }
1422
1421
  async function readFileIdentity(path) {
1423
1422
  try {
1424
- const value = await (0, import_promises2.stat)(path);
1423
+ const value = await (0, import_promises3.stat)(path);
1425
1424
  return `${value.dev}:${value.ino}`;
1426
1425
  } catch {
1427
1426
  return void 0;
@@ -1545,7 +1544,7 @@ async function prepareDigestDirectory(path, required) {
1545
1544
  if (!required || normalized === void 0 || normalized === "")
1546
1545
  return void 0;
1547
1546
  const resolved = resolveWikiGraphRuntimePath(normalized);
1548
- await (0, import_promises3.rm)(resolved, { force: true, recursive: true });
1547
+ await (0, import_promises4.rm)(resolved, { force: true, recursive: true });
1549
1548
  return new NodeDirectory(resolved);
1550
1549
  }
1551
1550
  async function writeArchive(archive, path, format) {
@@ -1938,10 +1937,10 @@ var WikiGraphArchiveManager = class {
1938
1937
  });
1939
1938
  }
1940
1939
  if (options.replace === true) {
1941
- await (0, import_promises4.rename)(outputPath, path);
1940
+ await (0, import_promises5.rename)(outputPath, path);
1942
1941
  } else {
1943
1942
  try {
1944
- await (0, import_promises4.link)(outputPath, path);
1943
+ await (0, import_promises5.link)(outputPath, path);
1945
1944
  } catch (error) {
1946
1945
  if (isNodeEEXISTError(error)) {
1947
1946
  throw new WikiGraphArchiveExistsError(path);
@@ -1951,7 +1950,7 @@ var WikiGraphArchiveManager = class {
1951
1950
  }
1952
1951
  return { locatedUri: (0, import_wiki_graph_core7.formatLocatedWikiGraphUri)(path), path };
1953
1952
  } finally {
1954
- await (0, import_promises4.rm)(outputPath, { force: true, recursive: true });
1953
+ await (0, import_promises5.rm)(outputPath, { force: true, recursive: true });
1955
1954
  }
1956
1955
  }, options.signal);
1957
1956
  }
@@ -2114,6 +2113,13 @@ var WikiGraphArchiveHandle = class {
2114
2113
  );
2115
2114
  return status;
2116
2115
  }
2116
+ /** Clear cached search sessions without changing the archive index. */
2117
+ async clearSearchSessions(options = {}) {
2118
+ await this.#runtime.run(
2119
+ async () => await (0, import_wiki_graph_core7.deleteArchiveSearchSessions)(this.path),
2120
+ options.signal
2121
+ );
2122
+ }
2117
2123
  async listChapters(options = {}) {
2118
2124
  return await this.#readDocument(
2119
2125
  async (document) => await (0, import_wiki_graph_core7.listChapters)(document),
@@ -2565,7 +2571,7 @@ function selectChapterSubtree(chapters, rootChapterId, depth) {
2565
2571
  );
2566
2572
  }
2567
2573
  async function createEmptyArchiveFile(path) {
2568
- const directoryPath = await (0, import_promises4.mkdtemp)(
2574
+ const directoryPath = await (0, import_promises5.mkdtemp)(
2569
2575
  (0, import_path5.join)((0, import_os3.tmpdir)(), "wikigraph-archive-write-")
2570
2576
  );
2571
2577
  try {
@@ -2580,7 +2586,7 @@ async function createEmptyArchiveFile(path) {
2580
2586
  }
2581
2587
  await (0, import_wiki_graph_core7.writeWikgArchive)(directory, new NodeFile(path));
2582
2588
  } finally {
2583
- await (0, import_promises4.rm)(directoryPath, { force: true, recursive: true });
2589
+ await (0, import_promises5.rm)(directoryPath, { force: true, recursive: true });
2584
2590
  }
2585
2591
  }
2586
2592
  function isNodeEEXISTError(error) {
@@ -2588,7 +2594,7 @@ function isNodeEEXISTError(error) {
2588
2594
  }
2589
2595
  async function nodePathExists(path) {
2590
2596
  try {
2591
- await (0, import_promises4.stat)(path);
2597
+ await (0, import_promises5.stat)(path);
2592
2598
  return true;
2593
2599
  } catch (error) {
2594
2600
  if (isNodeENOENTError(error)) return false;