wiki-graph-sdk 0.8.2 → 0.8.4

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 (51) hide show
  1. package/README.md +13 -3
  2. package/dist/archives.cjs +382 -25
  3. package/dist/archives.cjs.map +1 -1
  4. package/dist/archives.d.ts +4 -216
  5. package/dist/archives.js +372 -13
  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 +6 -7
  10. package/dist/conversions.js.map +1 -1
  11. package/dist/default-worker.cjs +40 -17
  12. package/dist/default-worker.cjs.map +1 -1
  13. package/dist/default-worker.js +37 -14
  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 +6 -7
  18. package/dist/embedding.js.map +1 -1
  19. package/dist/gc.cjs +61 -9
  20. package/dist/gc.cjs.map +1 -1
  21. package/dist/gc.d.ts +1 -1
  22. package/dist/gc.js +61 -9
  23. package/dist/gc.js.map +1 -1
  24. package/dist/host-IbqJ8WSV.d.ts +18 -0
  25. package/dist/index-DQzLAnjf.d.ts +346 -0
  26. package/dist/index.cjs +622 -40
  27. package/dist/index.cjs.map +1 -1
  28. package/dist/index.d.ts +20 -12
  29. package/dist/index.js +601 -31
  30. package/dist/index.js.map +1 -1
  31. package/dist/local-config.cjs +6 -7
  32. package/dist/local-config.cjs.map +1 -1
  33. package/dist/local-config.js +6 -7
  34. package/dist/local-config.js.map +1 -1
  35. package/dist/maintenance.cjs.map +1 -1
  36. package/dist/maintenance.js.map +1 -1
  37. package/dist/runtime-config.cjs +6 -7
  38. package/dist/runtime-config.cjs.map +1 -1
  39. package/dist/runtime-config.js +6 -7
  40. package/dist/runtime-config.js.map +1 -1
  41. package/dist/stage.cjs +6 -7
  42. package/dist/stage.cjs.map +1 -1
  43. package/dist/stage.js +6 -7
  44. package/dist/stage.js.map +1 -1
  45. package/dist/worker.cjs +55 -31
  46. package/dist/worker.cjs.map +1 -1
  47. package/dist/worker.d.ts +1 -1
  48. package/dist/worker.js +61 -37
  49. package/dist/worker.js.map +1 -1
  50. package/package.json +2 -2
  51. package/dist/host-pQiVAKEY.d.ts +0 -10
package/dist/index.js CHANGED
@@ -15,6 +15,8 @@ import {
15
15
  assertNoActiveBuildJobConflicts,
16
16
  assertNoActiveBuildJobs,
17
17
  deleteArchiveSearchSessions,
18
+ createContinuationCursor,
19
+ deleteContinuationCursor,
18
20
  DirectoryDocument,
19
21
  findArchiveObjects,
20
22
  formatLocatedWikiGraphUri as formatLocatedWikiGraphUri2,
@@ -884,13 +886,15 @@ function getWikiGraphSDKRuntimeContext() {
884
886
  };
885
887
  }
886
888
  function getWikiGraphSDKStateDir() {
887
- return getWikiGraphSDKRuntimeContext().stateDir;
889
+ const context = getWikiGraphSDKRuntimeContext();
890
+ return context.host?.stateDir ?? context.stateDir;
888
891
  }
889
892
  function getWikiGraphSDKProviders() {
890
893
  return getWikiGraphSDKRuntimeContext().providers ?? {};
891
894
  }
892
895
 
893
896
  // src/local-config.ts
897
+ import { mkdir as mkdir2 } from "fs/promises";
894
898
  import { join as join2 } from "path";
895
899
  import { homedir as homedir2 } from "os";
896
900
  var LOCAL_CONFIG_SECTIONS = [
@@ -991,13 +995,10 @@ function validateLocalConfigSection(section, value) {
991
995
  }
992
996
  }
993
997
  async function withLocalConfigDatabase(operation) {
998
+ const stateDir = getWikiGraphSDKStateDir() ?? join2(homedir2(), ".wikigraph");
999
+ await mkdir2(stateDir, { recursive: true });
994
1000
  const database = await openSharedStateDatabase(
995
- new NodeFile(
996
- join2(
997
- getWikiGraphSDKStateDir() ?? join2(homedir2(), ".wikigraph"),
998
- "core.sqlite"
999
- )
1000
- ),
1001
+ new NodeFile(join2(stateDir, "core.sqlite")),
1001
1002
  LOCAL_CONFIG_SCHEMA_SQL
1002
1003
  );
1003
1004
  try {
@@ -2109,6 +2110,294 @@ async function writeWikiGraphArchiveLocation(location, operation, options = {})
2109
2110
  });
2110
2111
  }
2111
2112
 
2113
+ // src/pages.ts
2114
+ function createCursor(implementation) {
2115
+ let released = false;
2116
+ const assertLive = () => {
2117
+ if (released) throw new Error("Cursor has been released.");
2118
+ };
2119
+ return {
2120
+ pageClass: implementation.pageClass,
2121
+ async next(options = {}) {
2122
+ assertLive();
2123
+ return await implementation.next(options);
2124
+ },
2125
+ async token() {
2126
+ assertLive();
2127
+ return await implementation.token();
2128
+ },
2129
+ async release() {
2130
+ if (released) return;
2131
+ released = true;
2132
+ await implementation.release?.();
2133
+ }
2134
+ };
2135
+ }
2136
+ function createPageCursor(implementation) {
2137
+ let token;
2138
+ return createCursor({
2139
+ pageClass: implementation.pageClass,
2140
+ next: async (options) => await implementation.next(implementation.rawCursor, options),
2141
+ token: async () => {
2142
+ token ??= await implementation.createToken(implementation.rawCursor);
2143
+ return token;
2144
+ },
2145
+ release: async () => {
2146
+ if (token !== void 0) await implementation.releaseToken?.(token);
2147
+ token = void 0;
2148
+ }
2149
+ });
2150
+ }
2151
+ async function* iteratePages(firstPage, options = {}) {
2152
+ let page = firstPage;
2153
+ while (true) {
2154
+ yield page;
2155
+ const cursor = page.nextCursor();
2156
+ if (cursor === null) return;
2157
+ try {
2158
+ const nextPage = await cursor.next(options);
2159
+ await cursor.release();
2160
+ page = nextPage;
2161
+ } catch (error) {
2162
+ await cursor.release();
2163
+ throw error;
2164
+ }
2165
+ }
2166
+ }
2167
+ async function* iterateItems(firstPage, options = {}) {
2168
+ for await (const page of iteratePages(firstPage, options)) {
2169
+ yield* page;
2170
+ }
2171
+ }
2172
+
2173
+ // src/result-pages.ts
2174
+ var ArchiveFindPage = class _ArchiveFindPage {
2175
+ result;
2176
+ chapters;
2177
+ items;
2178
+ lens;
2179
+ lensHint;
2180
+ limit;
2181
+ match;
2182
+ rawNextCursor;
2183
+ order;
2184
+ query;
2185
+ terms;
2186
+ types;
2187
+ #cursor;
2188
+ constructor(result, cursor = null) {
2189
+ this.result = result;
2190
+ this.chapters = result.chapters;
2191
+ this.items = result.items;
2192
+ this.lens = result.lens;
2193
+ this.lensHint = result.lensHint;
2194
+ this.limit = result.limit;
2195
+ this.match = result.match;
2196
+ this.rawNextCursor = result.nextCursor;
2197
+ this.order = result.order;
2198
+ this.query = result.query;
2199
+ this.terms = result.terms;
2200
+ this.types = result.types;
2201
+ this.#cursor = cursor;
2202
+ }
2203
+ static pageClass = _ArchiveFindPage;
2204
+ [Symbol.iterator]() {
2205
+ return this.items[Symbol.iterator]();
2206
+ }
2207
+ nextCursor() {
2208
+ return this.#cursor;
2209
+ }
2210
+ };
2211
+ var ArchiveCollectionPage = class _ArchiveCollectionPage {
2212
+ result;
2213
+ chapters;
2214
+ ids;
2215
+ items;
2216
+ limit;
2217
+ rawNextCursor;
2218
+ order;
2219
+ types;
2220
+ #cursor;
2221
+ constructor(result, cursor = null) {
2222
+ this.result = result;
2223
+ this.chapters = result.chapters;
2224
+ this.ids = result.ids;
2225
+ this.items = result.items;
2226
+ this.limit = result.limit;
2227
+ this.rawNextCursor = result.nextCursor;
2228
+ this.order = result.order;
2229
+ this.types = result.types;
2230
+ this.#cursor = cursor;
2231
+ }
2232
+ static pageClass = _ArchiveCollectionPage;
2233
+ [Symbol.iterator]() {
2234
+ return this.items[Symbol.iterator]();
2235
+ }
2236
+ nextCursor() {
2237
+ return this.#cursor;
2238
+ }
2239
+ };
2240
+ var ArchiveEvidencePage = class _ArchiveEvidencePage {
2241
+ result;
2242
+ items;
2243
+ limit;
2244
+ rawNextCursor;
2245
+ #cursor;
2246
+ constructor(result, cursor = null) {
2247
+ this.result = result;
2248
+ this.items = result.items;
2249
+ this.limit = result.limit;
2250
+ this.rawNextCursor = result.nextCursor;
2251
+ this.#cursor = cursor;
2252
+ }
2253
+ static pageClass = _ArchiveEvidencePage;
2254
+ [Symbol.iterator]() {
2255
+ return this.items[Symbol.iterator]();
2256
+ }
2257
+ nextCursor() {
2258
+ return this.#cursor;
2259
+ }
2260
+ };
2261
+ var ArchiveRelatedPage = class _ArchiveRelatedPage {
2262
+ result;
2263
+ items;
2264
+ limit;
2265
+ rawNextCursor;
2266
+ #cursor;
2267
+ constructor(result, cursor = null) {
2268
+ this.result = result;
2269
+ this.items = result.items;
2270
+ this.limit = result.limit;
2271
+ this.rawNextCursor = result.nextCursor;
2272
+ this.#cursor = cursor;
2273
+ }
2274
+ static pageClass = _ArchiveRelatedPage;
2275
+ [Symbol.iterator]() {
2276
+ return this.items[Symbol.iterator]();
2277
+ }
2278
+ nextCursor() {
2279
+ return this.#cursor;
2280
+ }
2281
+ };
2282
+ var ArchiveSourceLocatorPage = class _ArchiveSourceLocatorPage {
2283
+ result;
2284
+ items;
2285
+ limit;
2286
+ rawNextCursor;
2287
+ #cursor;
2288
+ constructor(result, cursor = null) {
2289
+ this.result = result;
2290
+ this.items = result.items;
2291
+ this.limit = result.limit;
2292
+ this.rawNextCursor = result.nextCursor;
2293
+ this.#cursor = cursor;
2294
+ }
2295
+ static pageClass = _ArchiveSourceLocatorPage;
2296
+ [Symbol.iterator]() {
2297
+ return this.items[Symbol.iterator]();
2298
+ }
2299
+ nextCursor() {
2300
+ return this.#cursor;
2301
+ }
2302
+ };
2303
+ function createArchiveFindPage(result, next, createToken, releaseToken) {
2304
+ return new ArchiveFindPage(
2305
+ result,
2306
+ result.nextCursor === null ? null : createPageCursor({
2307
+ pageClass: ArchiveFindPage,
2308
+ rawCursor: result.nextCursor,
2309
+ next,
2310
+ createToken,
2311
+ releaseToken
2312
+ })
2313
+ );
2314
+ }
2315
+ function createArchiveCollectionPage(result, next, createToken, releaseToken) {
2316
+ return new ArchiveCollectionPage(
2317
+ result,
2318
+ result.nextCursor === null ? null : createPageCursor({
2319
+ pageClass: ArchiveCollectionPage,
2320
+ rawCursor: result.nextCursor,
2321
+ next,
2322
+ createToken,
2323
+ releaseToken
2324
+ })
2325
+ );
2326
+ }
2327
+ function createArchiveEvidencePage(result, next, createToken, releaseToken) {
2328
+ return new ArchiveEvidencePage(
2329
+ result,
2330
+ result.nextCursor === null ? null : createPageCursor({
2331
+ pageClass: ArchiveEvidencePage,
2332
+ rawCursor: result.nextCursor,
2333
+ next,
2334
+ createToken,
2335
+ releaseToken
2336
+ })
2337
+ );
2338
+ }
2339
+ function createArchiveRelatedPage(result, next, createToken, releaseToken) {
2340
+ return new ArchiveRelatedPage(
2341
+ result,
2342
+ result.nextCursor === null ? null : createPageCursor({
2343
+ pageClass: ArchiveRelatedPage,
2344
+ rawCursor: result.nextCursor,
2345
+ next,
2346
+ createToken,
2347
+ releaseToken
2348
+ })
2349
+ );
2350
+ }
2351
+ function createArchiveSourceLocatorPage(result, next, createToken, releaseToken) {
2352
+ return new ArchiveSourceLocatorPage(
2353
+ result,
2354
+ result.nextCursor === null ? null : createPageCursor({
2355
+ pageClass: ArchiveSourceLocatorPage,
2356
+ rawCursor: result.nextCursor,
2357
+ next,
2358
+ createToken,
2359
+ releaseToken
2360
+ })
2361
+ );
2362
+ }
2363
+ var LibraryBucketPage = class _LibraryBucketPage {
2364
+ id;
2365
+ items;
2366
+ rawNextCursor;
2367
+ query;
2368
+ terms;
2369
+ types;
2370
+ #cursor;
2371
+ constructor(result, cursor = null) {
2372
+ this.id = result.id;
2373
+ this.items = result.items;
2374
+ this.rawNextCursor = result.nextCursor;
2375
+ this.query = result.query;
2376
+ this.terms = result.terms;
2377
+ this.types = result.types;
2378
+ this.#cursor = cursor;
2379
+ }
2380
+ static pageClass = _LibraryBucketPage;
2381
+ [Symbol.iterator]() {
2382
+ return this.items[Symbol.iterator]();
2383
+ }
2384
+ nextCursor() {
2385
+ return this.#cursor;
2386
+ }
2387
+ };
2388
+ function createLibraryBucketPage(result, next, createToken, releaseToken) {
2389
+ return new LibraryBucketPage(
2390
+ result,
2391
+ result.nextCursor === null ? null : createPageCursor({
2392
+ pageClass: LibraryBucketPage,
2393
+ rawCursor: result.nextCursor,
2394
+ next,
2395
+ createToken,
2396
+ releaseToken
2397
+ })
2398
+ );
2399
+ }
2400
+
2112
2401
  // src/archive/archive.ts
2113
2402
  var WikiGraphArchiveExistsError = class extends Error {
2114
2403
  code = "WIKI_GRAPH_ARCHIVE_EXISTS";
@@ -2196,6 +2485,14 @@ var WikiGraphArchiveHandle = class {
2196
2485
  get target() {
2197
2486
  return this.#location.target;
2198
2487
  }
2488
+ async #persistCursor(cursor) {
2489
+ return await this.#runtime.run(
2490
+ async () => await createContinuationCursor(cursor)
2491
+ );
2492
+ }
2493
+ async #releaseCursor(cursor) {
2494
+ await this.#runtime.run(async () => await deleteContinuationCursor(cursor));
2495
+ }
2199
2496
  async inspect(options = {}) {
2200
2497
  return await this.#readDocument(
2201
2498
  async (document) => await inspectWikiGraphArchive(document, {
@@ -2210,7 +2507,7 @@ var WikiGraphArchiveHandle = class {
2210
2507
  options.queryMode,
2211
2508
  options.signal
2212
2509
  );
2213
- return await this.#writeDocument(
2510
+ const result = await this.#writeDocument(
2214
2511
  async (document) => {
2215
2512
  const chapters = await this.#resolveQueryChapters(document, options, {
2216
2513
  embeddingProvider
@@ -2231,9 +2528,38 @@ var WikiGraphArchiveHandle = class {
2231
2528
  ...options.signal === void 0 ? {} : { signal: options.signal }
2232
2529
  }
2233
2530
  );
2531
+ return createArchiveFindPage(
2532
+ result,
2533
+ async (cursor, nextOptions) => await this.search(query, {
2534
+ ...options,
2535
+ cursor,
2536
+ ...nextOptions.limit === void 0 ? {} : { limit: nextOptions.limit },
2537
+ ...nextOptions.signal === void 0 ? {} : { signal: nextOptions.signal }
2538
+ }),
2539
+ (cursor) => this.#persistCursor({
2540
+ archiveKey: this.archiveKey,
2541
+ archivePath: this.path,
2542
+ chapters: options.chapters ?? null,
2543
+ cursor,
2544
+ format: "json",
2545
+ indexScope: this.indexScope,
2546
+ kind: "search",
2547
+ ...options.backlinks === void 0 ? {} : { backlinks: options.backlinks },
2548
+ ...options.evidenceLimit === void 0 ? {} : { evidenceLimit: options.evidenceLimit },
2549
+ ...options.match === void 0 ? {} : { match: options.match },
2550
+ ...options.order === void 0 ? {} : { order: options.order },
2551
+ query,
2552
+ ...options.queryMode === void 0 ? {} : { queryMode: options.queryMode },
2553
+ ...options.skipUnindexed === void 0 ? {} : { skipUnindexed: options.skipUnindexed },
2554
+ ...options.sourceContext === void 0 ? {} : { sourceContext: options.sourceContext },
2555
+ ...options.triplePattern === void 0 ? {} : { triplePattern: options.triplePattern },
2556
+ types: options.types ?? null
2557
+ }),
2558
+ (token) => this.#releaseCursor(token)
2559
+ );
2234
2560
  }
2235
2561
  async list(options = {}) {
2236
- return await this.#readDocument(async (document) => {
2562
+ const result = await this.#readDocument(async (document) => {
2237
2563
  if (isSourceLocatorScopeUri(this.objectUri)) {
2238
2564
  return await listArchiveSourceLocators(document, this.objectUri, {
2239
2565
  ...options.cursor === void 0 ? {} : { cursor: options.cursor },
@@ -2246,6 +2572,53 @@ var WikiGraphArchiveHandle = class {
2246
2572
  ...chapters === void 0 ? {} : { chapters }
2247
2573
  });
2248
2574
  }, options);
2575
+ if (isSourceLocatorScopeUri(this.objectUri)) {
2576
+ return createArchiveSourceLocatorPage(
2577
+ result,
2578
+ async (cursor, nextOptions) => await this.list({
2579
+ ...options,
2580
+ cursor,
2581
+ ...nextOptions.limit === void 0 ? {} : { limit: nextOptions.limit },
2582
+ ...nextOptions.signal === void 0 ? {} : { signal: nextOptions.signal }
2583
+ }),
2584
+ (cursor) => this.#persistCursor({
2585
+ archiveKey: this.archiveKey,
2586
+ archivePath: this.path,
2587
+ cursor,
2588
+ format: "json",
2589
+ indexScope: this.indexScope,
2590
+ kind: "source-locators",
2591
+ targetUri: this.objectUri
2592
+ }),
2593
+ (token) => this.#releaseCursor(token)
2594
+ );
2595
+ }
2596
+ return createArchiveCollectionPage(
2597
+ result,
2598
+ async (cursor, nextOptions) => await this.list({
2599
+ ...options,
2600
+ cursor,
2601
+ ...nextOptions.limit === void 0 ? {} : { limit: nextOptions.limit },
2602
+ ...nextOptions.signal === void 0 ? {} : { signal: nextOptions.signal }
2603
+ }),
2604
+ (cursor) => this.#persistCursor({
2605
+ archiveKey: this.archiveKey,
2606
+ archivePath: this.path,
2607
+ ...options.backlinks === void 0 ? {} : { backlinks: options.backlinks },
2608
+ chapters: options.chapters ?? null,
2609
+ cursor,
2610
+ ...options.evidenceLimit === void 0 ? {} : { evidenceLimit: options.evidenceLimit },
2611
+ format: "json",
2612
+ ids: options.ids ?? null,
2613
+ indexScope: this.indexScope,
2614
+ kind: "collection",
2615
+ order: options.order ?? "doc-asc",
2616
+ ...options.sourceContext === void 0 ? {} : { sourceContext: options.sourceContext },
2617
+ ...options.triplePattern === void 0 ? {} : { triplePattern: options.triplePattern },
2618
+ types: options.types ?? null
2619
+ }),
2620
+ (token) => this.#releaseCursor(token)
2621
+ );
2249
2622
  }
2250
2623
  async ensureSearchIndex(options = {}) {
2251
2624
  const embeddingProvider = await this.#runtime.run(
@@ -2522,19 +2895,30 @@ var WikiGraphArchiveHandle = class {
2522
2895
  if (options.queryMode !== void 0) {
2523
2896
  throw new Error("`queryMode` requires `query`.");
2524
2897
  }
2525
- return await this.#readDocument(async (document) => {
2898
+ const result2 = await this.#readDocument(async (document) => {
2526
2899
  const chapters = await this.#resolveScope(document, {});
2527
2900
  return await listRelatedArchiveObjects(document, objectUri, {
2528
2901
  ...withoutOperation(options),
2529
2902
  ...chapters === void 0 ? {} : { chapters }
2530
2903
  });
2531
2904
  }, options);
2905
+ return createArchiveRelatedPage(
2906
+ result2,
2907
+ async (cursor, nextOptions) => await this.related(objectUri, {
2908
+ ...options,
2909
+ cursor,
2910
+ ...nextOptions.limit === void 0 ? {} : { limit: nextOptions.limit },
2911
+ ...nextOptions.signal === void 0 ? {} : { signal: nextOptions.signal }
2912
+ }),
2913
+ (cursor) => Promise.resolve(cursor),
2914
+ () => Promise.resolve()
2915
+ );
2532
2916
  }
2533
2917
  const embeddingProvider = await this.#resolveQueryEmbeddingProvider(
2534
2918
  options.queryMode,
2535
2919
  options.signal
2536
2920
  );
2537
- return await this.#writeDocument(
2921
+ const result = await this.#writeDocument(
2538
2922
  async (document) => {
2539
2923
  const chapters = await this.#resolveQueryChapters(document, options, {
2540
2924
  embeddingProvider
@@ -2554,25 +2938,47 @@ var WikiGraphArchiveHandle = class {
2554
2938
  ...options.signal === void 0 ? {} : { signal: options.signal }
2555
2939
  }
2556
2940
  );
2941
+ return createArchiveRelatedPage(
2942
+ result,
2943
+ async (cursor, nextOptions) => await this.related(objectUri, {
2944
+ ...options,
2945
+ cursor,
2946
+ ...nextOptions.limit === void 0 ? {} : { limit: nextOptions.limit },
2947
+ ...nextOptions.signal === void 0 ? {} : { signal: nextOptions.signal }
2948
+ }),
2949
+ (cursor) => Promise.resolve(cursor),
2950
+ () => Promise.resolve()
2951
+ );
2557
2952
  }
2558
2953
  async evidence(objectUri = this.objectUri, options = {}) {
2559
2954
  if (options.query === void 0) {
2560
2955
  if (options.queryMode !== void 0) {
2561
2956
  throw new Error("`queryMode` requires `query`.");
2562
2957
  }
2563
- return await this.#readDocument(async (document) => {
2958
+ const result2 = await this.#readDocument(async (document) => {
2564
2959
  const chapters = await this.#resolveScope(document, {});
2565
2960
  return await listArchiveEvidence(document, objectUri, {
2566
2961
  ...withoutOperation(options),
2567
2962
  ...chapters === void 0 ? {} : { chapters }
2568
2963
  });
2569
2964
  }, options);
2965
+ return createArchiveEvidencePage(
2966
+ result2,
2967
+ async (cursor, nextOptions) => await this.evidence(objectUri, {
2968
+ ...options,
2969
+ cursor,
2970
+ ...nextOptions.limit === void 0 ? {} : { limit: nextOptions.limit },
2971
+ ...nextOptions.signal === void 0 ? {} : { signal: nextOptions.signal }
2972
+ }),
2973
+ (cursor) => Promise.resolve(cursor),
2974
+ () => Promise.resolve()
2975
+ );
2570
2976
  }
2571
2977
  const embeddingProvider = await this.#resolveQueryEmbeddingProvider(
2572
2978
  options.queryMode,
2573
2979
  options.signal
2574
2980
  );
2575
- return await this.#writeDocument(
2981
+ const result = await this.#writeDocument(
2576
2982
  async (document) => {
2577
2983
  const chapters = await this.#resolveQueryChapters(document, options, {
2578
2984
  embeddingProvider
@@ -2592,6 +2998,17 @@ var WikiGraphArchiveHandle = class {
2592
2998
  ...options.signal === void 0 ? {} : { signal: options.signal }
2593
2999
  }
2594
3000
  );
3001
+ return createArchiveEvidencePage(
3002
+ result,
3003
+ async (cursor, nextOptions) => await this.evidence(objectUri, {
3004
+ ...options,
3005
+ cursor,
3006
+ ...nextOptions.limit === void 0 ? {} : { limit: nextOptions.limit },
3007
+ ...nextOptions.signal === void 0 ? {} : { signal: nextOptions.signal }
3008
+ }),
3009
+ (cursor) => Promise.resolve(cursor),
3010
+ () => Promise.resolve()
3011
+ );
2595
3012
  }
2596
3013
  async pack(objectUri = this.objectUri, budget = 5e3, options = {}) {
2597
3014
  return await this.#readDocument(
@@ -3075,7 +3492,7 @@ function parseProvider(value) {
3075
3492
 
3076
3493
  // src/continuations.ts
3077
3494
  import {
3078
- createContinuationCursor,
3495
+ createContinuationCursor as createContinuationCursor2,
3079
3496
  findArchiveObjects as findArchiveObjects2,
3080
3497
  findWikiGraphLibraryArchiveMembers,
3081
3498
  findWikiGraphLibraryObjects,
@@ -3105,7 +3522,7 @@ var WikiGraphContinuationManager = class {
3105
3522
  async create(context, cursor) {
3106
3523
  if (cursor === null || cursor === void 0) return null;
3107
3524
  return await this.#runtime.run(
3108
- async () => await createContinuationCursor(
3525
+ async () => await createContinuationCursor2(
3109
3526
  createContinuationPayload(context, cursor)
3110
3527
  )
3111
3528
  );
@@ -3298,7 +3715,7 @@ function getCursorArchivePath(cursor) {
3298
3715
  }
3299
3716
  async function persistResultCursor(cursor, result) {
3300
3717
  if (result.nextCursor === null) return result;
3301
- const nextCursor = await createContinuationCursor({
3718
+ const nextCursor = await createContinuationCursor2({
3302
3719
  ...cursor,
3303
3720
  cursor: result.nextCursor
3304
3721
  });
@@ -3622,19 +4039,40 @@ function prepareWikiGraphSDKHost(host) {
3622
4039
  installWikiGraphPlatform2(host.platform);
3623
4040
  }
3624
4041
  function assertWikiGraphSDKHostOptions(options) {
3625
- if (options.host?.storage !== void 0 && options.stateDir !== void 0) {
4042
+ if (options.host?.storage !== void 0 && options.host.stateDir === void 0) {
4043
+ throw new TypeError(
4044
+ "Wiki Graph SDK host.storage requires host.stateDir so SDK configuration cannot fall back to the default user state directory."
4045
+ );
4046
+ }
4047
+ if (options.stateDir !== void 0 && (options.host?.stateDir !== void 0 || options.host?.storage !== void 0)) {
3626
4048
  throw new TypeError(
3627
- "Wiki Graph SDK host.storage and stateDir cannot be used together."
4049
+ "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."
3628
4050
  );
3629
4051
  }
3630
4052
  }
3631
4053
  async function withWikiGraphSDKHost(options, operation) {
3632
- assertWikiGraphSDKHostOptions(options);
3633
- prepareWikiGraphSDKHost(options.host);
3634
- if (options.host?.storage !== void 0) {
3635
- return await withWikiGraphStorage2(options.host.storage, operation);
4054
+ const current = getWikiGraphSDKRuntimeContext();
4055
+ const effective = {
4056
+ ...options.host === void 0 ? current.host === void 0 ? {} : { host: current.host } : { host: options.host },
4057
+ ...options.stateDir === void 0 ? current.stateDir === void 0 ? {} : { stateDir: current.stateDir } : { stateDir: options.stateDir }
4058
+ };
4059
+ assertWikiGraphSDKHostOptions(effective);
4060
+ prepareWikiGraphSDKHost(effective.host);
4061
+ const runWithContext = async () => await withWikiGraphSDKRuntimeContext(
4062
+ {
4063
+ ...current,
4064
+ ...effective.host === void 0 ? {} : { host: effective.host },
4065
+ ...effective.stateDir === void 0 ? {} : { stateDir: effective.stateDir }
4066
+ },
4067
+ operation
4068
+ );
4069
+ if (effective.host?.storage !== void 0) {
4070
+ return await withWikiGraphStorage2(effective.host.storage, runWithContext);
3636
4071
  }
3637
- return await withNodeWikiGraphStorage(options.stateDir, operation);
4072
+ return await withNodeWikiGraphStorage(
4073
+ effective.host?.stateDir ?? effective.stateDir,
4074
+ runWithContext
4075
+ );
3638
4076
  }
3639
4077
 
3640
4078
  // src/worker.ts
@@ -4561,9 +4999,11 @@ import {
4561
4999
  assertWikiGraphLibrarySchemaCurrent,
4562
5000
  cleanWikiGraphLibraryIndex,
4563
5001
  clearWikiGraphLibraryMetadata,
5002
+ continueWikiGraphLibraryObjectBucket,
4564
5003
  createWikiGraphLibrary,
4565
5004
  deleteWikiGraphLibraryMetadataKey,
4566
5005
  findWikiGraphLibraryObjects as findWikiGraphLibraryObjects2,
5006
+ findWikiGraphLibraryObjectBuckets,
4567
5007
  findWikiGraphLibraryArchiveMembers as findWikiGraphLibraryArchiveMembers2,
4568
5008
  formatWikiGraphLibraryUri as formatWikiGraphLibraryUri2,
4569
5009
  getWikiGraphLibraryArchive,
@@ -4590,7 +5030,7 @@ import {
4590
5030
  scanWikiGraphLibrary,
4591
5031
  withWikiGraphLibraryLock
4592
5032
  } from "wiki-graph-core";
4593
- import { mkdir as mkdir2 } from "fs/promises";
5033
+ import { mkdir as mkdir3 } from "fs/promises";
4594
5034
  async function resolveQueryEmbeddingProvider(queryMode) {
4595
5035
  if (queryMode === "fts") return void 0;
4596
5036
  const provider = await createConfiguredEmbeddingProvider();
@@ -4609,7 +5049,7 @@ var WikiGraphLibraryManager = class {
4609
5049
  async create(folder) {
4610
5050
  const record = await this.#runtime.run(async () => {
4611
5051
  const path = resolveWikiGraphRuntimePath(folder);
4612
- await mkdir2(path);
5052
+ await mkdir3(path);
4613
5053
  return await createWikiGraphLibrary({ folder: new NodeDirectory(path) });
4614
5054
  });
4615
5055
  return new WikiGraphLibrary(this.#runtime, record);
@@ -4795,7 +5235,7 @@ var WikiGraphLibraryManager = class {
4795
5235
  );
4796
5236
  }
4797
5237
  async search(target, query, options = {}) {
4798
- return await this.#runtime.run(async () => {
5238
+ const result = await this.#runtime.run(async () => {
4799
5239
  const embeddingProvider = await resolveQueryEmbeddingProvider(
4800
5240
  options.queryMode
4801
5241
  );
@@ -4808,9 +5248,70 @@ var WikiGraphLibraryManager = class {
4808
5248
  }
4809
5249
  );
4810
5250
  });
5251
+ return createArchiveFindPage(
5252
+ result,
5253
+ async (cursor, nextOptions) => await this.search(target, query, {
5254
+ ...options,
5255
+ cursor,
5256
+ ...nextOptions.limit === void 0 ? {} : { limit: nextOptions.limit },
5257
+ ...nextOptions.signal === void 0 ? {} : { signal: nextOptions.signal }
5258
+ }),
5259
+ (cursor) => Promise.resolve(cursor),
5260
+ () => Promise.resolve()
5261
+ );
5262
+ }
5263
+ async searchBuckets(target, query, options) {
5264
+ const result = await this.#runtime.run(async () => {
5265
+ const embeddingProvider = await resolveQueryEmbeddingProvider(
5266
+ options.queryMode
5267
+ );
5268
+ return await findWikiGraphLibraryObjectBuckets(
5269
+ requireLibraryTarget(target),
5270
+ query,
5271
+ {
5272
+ ...options,
5273
+ ...embeddingProvider === void 0 ? {} : { embeddingProvider }
5274
+ }
5275
+ );
5276
+ });
5277
+ return {
5278
+ buckets: result.buckets.map(
5279
+ (bucket) => createLibraryBucketPage(
5280
+ bucket,
5281
+ async (cursor, nextOptions) => await this.continueSearchBucket(target, cursor, {
5282
+ ...nextOptions.limit === void 0 ? {} : { limit: nextOptions.limit }
5283
+ }),
5284
+ (cursor) => Promise.resolve(cursor),
5285
+ () => Promise.resolve()
5286
+ )
5287
+ ),
5288
+ query: result.query
5289
+ };
5290
+ }
5291
+ async continueSearchBucket(target, cursor, options = {}) {
5292
+ const result = await this.#runtime.run(async () => {
5293
+ const embeddingProvider = await resolveQueryEmbeddingProvider(void 0);
5294
+ return await continueWikiGraphLibraryObjectBucket(
5295
+ requireLibraryTarget(target),
5296
+ cursor,
5297
+ {
5298
+ ...options,
5299
+ ...embeddingProvider === void 0 ? {} : { embeddingProvider }
5300
+ }
5301
+ );
5302
+ });
5303
+ return createLibraryBucketPage(
5304
+ result,
5305
+ async (nextCursor, nextOptions) => await this.continueSearchBucket(target, nextCursor, {
5306
+ ...options,
5307
+ ...nextOptions.limit === void 0 ? {} : { limit: nextOptions.limit }
5308
+ }),
5309
+ (cursor2) => Promise.resolve(cursor2),
5310
+ () => Promise.resolve()
5311
+ );
4811
5312
  }
4812
5313
  async searchArchiveMembers(target, query, options = {}) {
4813
- return await this.#runtime.run(async () => {
5314
+ const result = await this.#runtime.run(async () => {
4814
5315
  const embeddingProvider = await resolveQueryEmbeddingProvider(
4815
5316
  options.queryMode
4816
5317
  );
@@ -4823,22 +5324,53 @@ var WikiGraphLibraryManager = class {
4823
5324
  }
4824
5325
  );
4825
5326
  });
5327
+ return createArchiveFindPage(
5328
+ result,
5329
+ async (cursor, nextOptions) => await this.searchArchiveMembers(target, query, {
5330
+ ...options,
5331
+ cursor,
5332
+ ...nextOptions.limit === void 0 ? {} : { limit: nextOptions.limit },
5333
+ ...nextOptions.signal === void 0 ? {} : { signal: nextOptions.signal }
5334
+ }),
5335
+ (cursor) => Promise.resolve(cursor),
5336
+ () => Promise.resolve()
5337
+ );
4826
5338
  }
4827
5339
  async objects(target, options = {}) {
4828
- return await this.#runtime.run(
5340
+ const result = await this.#runtime.run(
4829
5341
  async () => await listWikiGraphLibraryObjects2(
4830
5342
  requireLibraryTarget(target),
4831
5343
  options
4832
5344
  )
4833
5345
  );
5346
+ return createArchiveCollectionPage(
5347
+ result,
5348
+ async (cursor, nextOptions) => await this.objects(target, {
5349
+ ...options,
5350
+ cursor,
5351
+ ...nextOptions.limit === void 0 ? {} : { limit: nextOptions.limit }
5352
+ }),
5353
+ (cursor) => Promise.resolve(cursor),
5354
+ () => Promise.resolve()
5355
+ );
4834
5356
  }
4835
5357
  async archiveMembers(target, options = {}) {
4836
- return await this.#runtime.run(
5358
+ const result = await this.#runtime.run(
4837
5359
  async () => await listWikiGraphLibraryArchiveMembers2(
4838
5360
  requireLibraryTarget(target),
4839
5361
  options
4840
5362
  )
4841
5363
  );
5364
+ return createArchiveCollectionPage(
5365
+ result,
5366
+ async (cursor, nextOptions) => await this.archiveMembers(target, {
5367
+ ...options,
5368
+ cursor,
5369
+ ...nextOptions.limit === void 0 ? {} : { limit: nextOptions.limit }
5370
+ }),
5371
+ (cursor) => Promise.resolve(cursor),
5372
+ () => Promise.resolve()
5373
+ );
4842
5374
  }
4843
5375
  async page(target, objectUri, options = {}) {
4844
5376
  return await this.#runtime.run(
@@ -4854,7 +5386,7 @@ var WikiGraphLibraryManager = class {
4854
5386
  );
4855
5387
  }
4856
5388
  async related(target, objectUri, options = {}) {
4857
- return await this.#runtime.run(async () => {
5389
+ const result = await this.#runtime.run(async () => {
4858
5390
  if (options.query === void 0 && options.queryMode !== void 0) {
4859
5391
  throw new Error("`queryMode` requires `query`.");
4860
5392
  }
@@ -4868,9 +5400,20 @@ var WikiGraphLibraryManager = class {
4868
5400
  }
4869
5401
  );
4870
5402
  });
5403
+ return createArchiveRelatedPage(
5404
+ result,
5405
+ async (cursor, nextOptions) => await this.related(target, objectUri, {
5406
+ ...options,
5407
+ cursor,
5408
+ ...nextOptions.limit === void 0 ? {} : { limit: nextOptions.limit },
5409
+ ...nextOptions.signal === void 0 ? {} : { signal: nextOptions.signal }
5410
+ }),
5411
+ (cursor) => Promise.resolve(cursor),
5412
+ () => Promise.resolve()
5413
+ );
4871
5414
  }
4872
5415
  async evidence(target, objectUri, options = {}) {
4873
- return await this.#runtime.run(async () => {
5416
+ const result = await this.#runtime.run(async () => {
4874
5417
  if (options.query === void 0 && options.queryMode !== void 0) {
4875
5418
  throw new Error("`queryMode` requires `query`.");
4876
5419
  }
@@ -4884,6 +5427,17 @@ var WikiGraphLibraryManager = class {
4884
5427
  }
4885
5428
  );
4886
5429
  });
5430
+ return createArchiveEvidencePage(
5431
+ result,
5432
+ async (cursor, nextOptions) => await this.evidence(target, objectUri, {
5433
+ ...options,
5434
+ cursor,
5435
+ ...nextOptions.limit === void 0 ? {} : { limit: nextOptions.limit },
5436
+ ...nextOptions.signal === void 0 ? {} : { signal: nextOptions.signal }
5437
+ }),
5438
+ (cursor) => Promise.resolve(cursor),
5439
+ () => Promise.resolve()
5440
+ );
4887
5441
  }
4888
5442
  async pack(target, objectUri, budget = 5e3) {
4889
5443
  return await this.#runtime.run(
@@ -5214,6 +5768,11 @@ import {
5214
5768
  requireLocatedObjectUri
5215
5769
  } from "wiki-graph-core";
5216
5770
  export {
5771
+ ArchiveCollectionPage,
5772
+ ArchiveEvidencePage,
5773
+ ArchiveFindPage,
5774
+ ArchiveRelatedPage,
5775
+ ArchiveSourceLocatorPage,
5217
5776
  DANGEROUS_RUNTIME_ENV_NAMES,
5218
5777
  DEFAULT_EXTRACTION_PROMPT,
5219
5778
  DEFAULT_GENERATION_JOB_CONCURRENCY,
@@ -5221,6 +5780,7 @@ export {
5221
5780
  DEFAULT_KNOWLEDGE_GRAPH_RECALL_PROMPT,
5222
5781
  LLMPaymentRequiredError,
5223
5782
  LOCAL_CONFIG_SECTIONS,
5783
+ LibraryBucketPage,
5224
5784
  NodeDirectory,
5225
5785
  NodeFile,
5226
5786
  WIKI_GRAPH_URI_PREFIX,
@@ -5241,11 +5801,19 @@ export {
5241
5801
  buildSearchIndexEmbeddingProvider,
5242
5802
  buildWikiGraphLLMOptions,
5243
5803
  clearLocalConfigSection,
5804
+ createArchiveCollectionPage,
5805
+ createArchiveEvidencePage,
5806
+ createArchiveFindPage,
5807
+ createArchiveRelatedPage,
5808
+ createArchiveSourceLocatorPage,
5809
+ createCursor,
5244
5810
  createEntryRuntimeContext,
5245
5811
  createGenerationPerformanceHints,
5812
+ createLibraryBucketPage,
5246
5813
  createNodeTemplateEnvironment,
5247
5814
  createNodeWikiGraphPlatform,
5248
5815
  createNodeWikiGraphStorage,
5816
+ createPageCursor,
5249
5817
  createStageLLM,
5250
5818
  createWikiGraphSDK,
5251
5819
  deleteLocalConfigValue,
@@ -5273,6 +5841,8 @@ export {
5273
5841
  isWikiGraphJobUri,
5274
5842
  isWikiGraphLibraryUri,
5275
5843
  isWikiGraphUri,
5844
+ iterateItems,
5845
+ iteratePages,
5276
5846
  loadRequiredStageConfig,
5277
5847
  loadWikiGraphRuntimeConfig,
5278
5848
  maskLocalConfigSection,