wiki-graph-sdk 0.8.3 → 0.9.0

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/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,
@@ -41,6 +43,7 @@ import {
41
43
  getChapterTree,
42
44
  WikiGraph as WikiGraph2,
43
45
  WikiGraphArchiveFile as WikiGraphArchiveFile2,
46
+ WikiGraphDirectoryFile as WikiGraphDirectoryFile2,
44
47
  TOC_FILE_VERSION,
45
48
  writeWikgArchive,
46
49
  ObjectMetadataKind
@@ -1418,6 +1421,9 @@ import {
1418
1421
  resolveWikiGraphLibrary,
1419
1422
  resolveWikiGraphLibraryArchiveFile
1420
1423
  } from "wiki-graph-core";
1424
+ function requireWikiGraphArchiveFile(location) {
1425
+ return location.archiveFile;
1426
+ }
1421
1427
  var WikiGraphArchiveOwnershipError = class extends Error {
1422
1428
  code = "WIKI_GRAPH_ARCHIVE_OWNERSHIP_MISMATCH";
1423
1429
  constructor(message) {
@@ -1564,11 +1570,12 @@ async function findMatchingMembers(libraries, candidate, candidateIdentity) {
1564
1570
  ...library.isDefault ? {} : { publicId: library.publicId }
1565
1571
  });
1566
1572
  for (const archive of archives) {
1567
- if (archive.file === void 0) continue;
1573
+ const physical = archive.file ?? archive.directory;
1574
+ if (physical === void 0) continue;
1568
1575
  members.push({
1569
1576
  archive,
1570
1577
  library,
1571
- memberPath: getNodeResourcePath(archive.file)
1578
+ memberPath: getNodeResourcePath(physical)
1572
1579
  });
1573
1580
  }
1574
1581
  }
@@ -2083,17 +2090,30 @@ function formatLocatedChapterUri(archiveUri, chapter) {
2083
2090
  // src/archive/write.ts
2084
2091
  import {
2085
2092
  WikiGraphArchiveFile,
2093
+ WikiGraphDirectoryFile,
2086
2094
  writeWikiGraphLibraryArchive
2087
2095
  } from "wiki-graph-core";
2088
2096
  async function writeWikiGraphArchiveLocation(location, operation, options = {}) {
2089
2097
  const cacheOnly = options.searchIndexWritebackPolicy === "cache";
2090
- const write = async (archiveFile = location.archiveFile) => await new WikiGraphArchiveFile(archiveFile).write(operation, {
2091
- ...cacheOnly ? {} : { derivedStateKeys: [location.archiveKey, location.archivePath] },
2092
- ...options.invalidateContinuationCursors === void 0 ? {} : {
2093
- invalidateContinuationCursors: options.invalidateContinuationCursors
2094
- },
2095
- ...options.searchIndexWritebackPolicy === void 0 ? {} : { searchIndexWritebackPolicy: options.searchIndexWritebackPolicy }
2096
- });
2098
+ const write = async (archiveFile = location.archiveFile) => {
2099
+ const writeOptions = {
2100
+ ...cacheOnly ? {} : { derivedStateKeys: [location.archiveKey, location.archivePath] },
2101
+ ...options.invalidateContinuationCursors === void 0 ? {} : {
2102
+ invalidateContinuationCursors: options.invalidateContinuationCursors
2103
+ },
2104
+ ...options.searchIndexWritebackPolicy === void 0 ? {} : { searchIndexWritebackPolicy: options.searchIndexWritebackPolicy }
2105
+ };
2106
+ if (archiveFile.kind === "directory") {
2107
+ return await new WikiGraphDirectoryFile(archiveFile).write(
2108
+ operation,
2109
+ writeOptions
2110
+ );
2111
+ }
2112
+ return await new WikiGraphArchiveFile(archiveFile).write(
2113
+ operation,
2114
+ writeOptions
2115
+ );
2116
+ };
2097
2117
  if (location.libraryArchiveTarget === void 0 || cacheOnly || options.refreshLibraryIndex === false) {
2098
2118
  return await write();
2099
2119
  }
@@ -2108,6 +2128,294 @@ async function writeWikiGraphArchiveLocation(location, operation, options = {})
2108
2128
  });
2109
2129
  }
2110
2130
 
2131
+ // src/pages.ts
2132
+ function createCursor(implementation) {
2133
+ let released = false;
2134
+ const assertLive = () => {
2135
+ if (released) throw new Error("Cursor has been released.");
2136
+ };
2137
+ return {
2138
+ pageClass: implementation.pageClass,
2139
+ async next(options = {}) {
2140
+ assertLive();
2141
+ return await implementation.next(options);
2142
+ },
2143
+ async token() {
2144
+ assertLive();
2145
+ return await implementation.token();
2146
+ },
2147
+ async release() {
2148
+ if (released) return;
2149
+ released = true;
2150
+ await implementation.release?.();
2151
+ }
2152
+ };
2153
+ }
2154
+ function createPageCursor(implementation) {
2155
+ let token;
2156
+ return createCursor({
2157
+ pageClass: implementation.pageClass,
2158
+ next: async (options) => await implementation.next(implementation.rawCursor, options),
2159
+ token: async () => {
2160
+ token ??= await implementation.createToken(implementation.rawCursor);
2161
+ return token;
2162
+ },
2163
+ release: async () => {
2164
+ if (token !== void 0) await implementation.releaseToken?.(token);
2165
+ token = void 0;
2166
+ }
2167
+ });
2168
+ }
2169
+ async function* iteratePages(firstPage, options = {}) {
2170
+ let page = firstPage;
2171
+ while (true) {
2172
+ yield page;
2173
+ const cursor = page.nextCursor();
2174
+ if (cursor === null) return;
2175
+ try {
2176
+ const nextPage = await cursor.next(options);
2177
+ await cursor.release();
2178
+ page = nextPage;
2179
+ } catch (error) {
2180
+ await cursor.release();
2181
+ throw error;
2182
+ }
2183
+ }
2184
+ }
2185
+ async function* iterateItems(firstPage, options = {}) {
2186
+ for await (const page of iteratePages(firstPage, options)) {
2187
+ yield* page;
2188
+ }
2189
+ }
2190
+
2191
+ // src/result-pages.ts
2192
+ var ArchiveFindPage = class _ArchiveFindPage {
2193
+ result;
2194
+ chapters;
2195
+ items;
2196
+ lens;
2197
+ lensHint;
2198
+ limit;
2199
+ match;
2200
+ rawNextCursor;
2201
+ order;
2202
+ query;
2203
+ terms;
2204
+ types;
2205
+ #cursor;
2206
+ constructor(result, cursor = null) {
2207
+ this.result = result;
2208
+ this.chapters = result.chapters;
2209
+ this.items = result.items;
2210
+ this.lens = result.lens;
2211
+ this.lensHint = result.lensHint;
2212
+ this.limit = result.limit;
2213
+ this.match = result.match;
2214
+ this.rawNextCursor = result.nextCursor;
2215
+ this.order = result.order;
2216
+ this.query = result.query;
2217
+ this.terms = result.terms;
2218
+ this.types = result.types;
2219
+ this.#cursor = cursor;
2220
+ }
2221
+ static pageClass = _ArchiveFindPage;
2222
+ [Symbol.iterator]() {
2223
+ return this.items[Symbol.iterator]();
2224
+ }
2225
+ nextCursor() {
2226
+ return this.#cursor;
2227
+ }
2228
+ };
2229
+ var ArchiveCollectionPage = class _ArchiveCollectionPage {
2230
+ result;
2231
+ chapters;
2232
+ ids;
2233
+ items;
2234
+ limit;
2235
+ rawNextCursor;
2236
+ order;
2237
+ types;
2238
+ #cursor;
2239
+ constructor(result, cursor = null) {
2240
+ this.result = result;
2241
+ this.chapters = result.chapters;
2242
+ this.ids = result.ids;
2243
+ this.items = result.items;
2244
+ this.limit = result.limit;
2245
+ this.rawNextCursor = result.nextCursor;
2246
+ this.order = result.order;
2247
+ this.types = result.types;
2248
+ this.#cursor = cursor;
2249
+ }
2250
+ static pageClass = _ArchiveCollectionPage;
2251
+ [Symbol.iterator]() {
2252
+ return this.items[Symbol.iterator]();
2253
+ }
2254
+ nextCursor() {
2255
+ return this.#cursor;
2256
+ }
2257
+ };
2258
+ var ArchiveEvidencePage = class _ArchiveEvidencePage {
2259
+ result;
2260
+ items;
2261
+ limit;
2262
+ rawNextCursor;
2263
+ #cursor;
2264
+ constructor(result, cursor = null) {
2265
+ this.result = result;
2266
+ this.items = result.items;
2267
+ this.limit = result.limit;
2268
+ this.rawNextCursor = result.nextCursor;
2269
+ this.#cursor = cursor;
2270
+ }
2271
+ static pageClass = _ArchiveEvidencePage;
2272
+ [Symbol.iterator]() {
2273
+ return this.items[Symbol.iterator]();
2274
+ }
2275
+ nextCursor() {
2276
+ return this.#cursor;
2277
+ }
2278
+ };
2279
+ var ArchiveRelatedPage = class _ArchiveRelatedPage {
2280
+ result;
2281
+ items;
2282
+ limit;
2283
+ rawNextCursor;
2284
+ #cursor;
2285
+ constructor(result, cursor = null) {
2286
+ this.result = result;
2287
+ this.items = result.items;
2288
+ this.limit = result.limit;
2289
+ this.rawNextCursor = result.nextCursor;
2290
+ this.#cursor = cursor;
2291
+ }
2292
+ static pageClass = _ArchiveRelatedPage;
2293
+ [Symbol.iterator]() {
2294
+ return this.items[Symbol.iterator]();
2295
+ }
2296
+ nextCursor() {
2297
+ return this.#cursor;
2298
+ }
2299
+ };
2300
+ var ArchiveSourceLocatorPage = class _ArchiveSourceLocatorPage {
2301
+ result;
2302
+ items;
2303
+ limit;
2304
+ rawNextCursor;
2305
+ #cursor;
2306
+ constructor(result, cursor = null) {
2307
+ this.result = result;
2308
+ this.items = result.items;
2309
+ this.limit = result.limit;
2310
+ this.rawNextCursor = result.nextCursor;
2311
+ this.#cursor = cursor;
2312
+ }
2313
+ static pageClass = _ArchiveSourceLocatorPage;
2314
+ [Symbol.iterator]() {
2315
+ return this.items[Symbol.iterator]();
2316
+ }
2317
+ nextCursor() {
2318
+ return this.#cursor;
2319
+ }
2320
+ };
2321
+ function createArchiveFindPage(result, next, createToken, releaseToken) {
2322
+ return new ArchiveFindPage(
2323
+ result,
2324
+ result.nextCursor === null ? null : createPageCursor({
2325
+ pageClass: ArchiveFindPage,
2326
+ rawCursor: result.nextCursor,
2327
+ next,
2328
+ createToken,
2329
+ releaseToken
2330
+ })
2331
+ );
2332
+ }
2333
+ function createArchiveCollectionPage(result, next, createToken, releaseToken) {
2334
+ return new ArchiveCollectionPage(
2335
+ result,
2336
+ result.nextCursor === null ? null : createPageCursor({
2337
+ pageClass: ArchiveCollectionPage,
2338
+ rawCursor: result.nextCursor,
2339
+ next,
2340
+ createToken,
2341
+ releaseToken
2342
+ })
2343
+ );
2344
+ }
2345
+ function createArchiveEvidencePage(result, next, createToken, releaseToken) {
2346
+ return new ArchiveEvidencePage(
2347
+ result,
2348
+ result.nextCursor === null ? null : createPageCursor({
2349
+ pageClass: ArchiveEvidencePage,
2350
+ rawCursor: result.nextCursor,
2351
+ next,
2352
+ createToken,
2353
+ releaseToken
2354
+ })
2355
+ );
2356
+ }
2357
+ function createArchiveRelatedPage(result, next, createToken, releaseToken) {
2358
+ return new ArchiveRelatedPage(
2359
+ result,
2360
+ result.nextCursor === null ? null : createPageCursor({
2361
+ pageClass: ArchiveRelatedPage,
2362
+ rawCursor: result.nextCursor,
2363
+ next,
2364
+ createToken,
2365
+ releaseToken
2366
+ })
2367
+ );
2368
+ }
2369
+ function createArchiveSourceLocatorPage(result, next, createToken, releaseToken) {
2370
+ return new ArchiveSourceLocatorPage(
2371
+ result,
2372
+ result.nextCursor === null ? null : createPageCursor({
2373
+ pageClass: ArchiveSourceLocatorPage,
2374
+ rawCursor: result.nextCursor,
2375
+ next,
2376
+ createToken,
2377
+ releaseToken
2378
+ })
2379
+ );
2380
+ }
2381
+ var LibraryBucketPage = class _LibraryBucketPage {
2382
+ id;
2383
+ items;
2384
+ rawNextCursor;
2385
+ query;
2386
+ terms;
2387
+ types;
2388
+ #cursor;
2389
+ constructor(result, cursor = null) {
2390
+ this.id = result.id;
2391
+ this.items = result.items;
2392
+ this.rawNextCursor = result.nextCursor;
2393
+ this.query = result.query;
2394
+ this.terms = result.terms;
2395
+ this.types = result.types;
2396
+ this.#cursor = cursor;
2397
+ }
2398
+ static pageClass = _LibraryBucketPage;
2399
+ [Symbol.iterator]() {
2400
+ return this.items[Symbol.iterator]();
2401
+ }
2402
+ nextCursor() {
2403
+ return this.#cursor;
2404
+ }
2405
+ };
2406
+ function createLibraryBucketPage(result, next, createToken, releaseToken) {
2407
+ return new LibraryBucketPage(
2408
+ result,
2409
+ result.nextCursor === null ? null : createPageCursor({
2410
+ pageClass: LibraryBucketPage,
2411
+ rawCursor: result.nextCursor,
2412
+ next,
2413
+ createToken,
2414
+ releaseToken
2415
+ })
2416
+ );
2417
+ }
2418
+
2111
2419
  // src/archive/archive.ts
2112
2420
  var WikiGraphArchiveExistsError = class extends Error {
2113
2421
  code = "WIKI_GRAPH_ARCHIVE_EXISTS";
@@ -2195,6 +2503,14 @@ var WikiGraphArchiveHandle = class {
2195
2503
  get target() {
2196
2504
  return this.#location.target;
2197
2505
  }
2506
+ async #persistCursor(cursor) {
2507
+ return await this.#runtime.run(
2508
+ async () => await createContinuationCursor(cursor)
2509
+ );
2510
+ }
2511
+ async #releaseCursor(cursor) {
2512
+ await this.#runtime.run(async () => await deleteContinuationCursor(cursor));
2513
+ }
2198
2514
  async inspect(options = {}) {
2199
2515
  return await this.#readDocument(
2200
2516
  async (document) => await inspectWikiGraphArchive(document, {
@@ -2209,7 +2525,7 @@ var WikiGraphArchiveHandle = class {
2209
2525
  options.queryMode,
2210
2526
  options.signal
2211
2527
  );
2212
- return await this.#writeDocument(
2528
+ const result = await this.#writeDocument(
2213
2529
  async (document) => {
2214
2530
  const chapters = await this.#resolveQueryChapters(document, options, {
2215
2531
  embeddingProvider
@@ -2230,9 +2546,38 @@ var WikiGraphArchiveHandle = class {
2230
2546
  ...options.signal === void 0 ? {} : { signal: options.signal }
2231
2547
  }
2232
2548
  );
2549
+ return createArchiveFindPage(
2550
+ result,
2551
+ async (cursor, nextOptions) => await this.search(query, {
2552
+ ...options,
2553
+ cursor,
2554
+ ...nextOptions.limit === void 0 ? {} : { limit: nextOptions.limit },
2555
+ ...nextOptions.signal === void 0 ? {} : { signal: nextOptions.signal }
2556
+ }),
2557
+ (cursor) => this.#persistCursor({
2558
+ archiveKey: this.archiveKey,
2559
+ archivePath: this.path,
2560
+ chapters: options.chapters ?? null,
2561
+ cursor,
2562
+ format: "json",
2563
+ indexScope: this.indexScope,
2564
+ kind: "search",
2565
+ ...options.backlinks === void 0 ? {} : { backlinks: options.backlinks },
2566
+ ...options.evidenceLimit === void 0 ? {} : { evidenceLimit: options.evidenceLimit },
2567
+ ...options.match === void 0 ? {} : { match: options.match },
2568
+ ...options.order === void 0 ? {} : { order: options.order },
2569
+ query,
2570
+ ...options.queryMode === void 0 ? {} : { queryMode: options.queryMode },
2571
+ ...options.skipUnindexed === void 0 ? {} : { skipUnindexed: options.skipUnindexed },
2572
+ ...options.sourceContext === void 0 ? {} : { sourceContext: options.sourceContext },
2573
+ ...options.triplePattern === void 0 ? {} : { triplePattern: options.triplePattern },
2574
+ types: options.types ?? null
2575
+ }),
2576
+ (token) => this.#releaseCursor(token)
2577
+ );
2233
2578
  }
2234
2579
  async list(options = {}) {
2235
- return await this.#readDocument(async (document) => {
2580
+ const result = await this.#readDocument(async (document) => {
2236
2581
  if (isSourceLocatorScopeUri(this.objectUri)) {
2237
2582
  return await listArchiveSourceLocators(document, this.objectUri, {
2238
2583
  ...options.cursor === void 0 ? {} : { cursor: options.cursor },
@@ -2245,6 +2590,53 @@ var WikiGraphArchiveHandle = class {
2245
2590
  ...chapters === void 0 ? {} : { chapters }
2246
2591
  });
2247
2592
  }, options);
2593
+ if (isSourceLocatorScopeUri(this.objectUri)) {
2594
+ return createArchiveSourceLocatorPage(
2595
+ result,
2596
+ async (cursor, nextOptions) => await this.list({
2597
+ ...options,
2598
+ cursor,
2599
+ ...nextOptions.limit === void 0 ? {} : { limit: nextOptions.limit },
2600
+ ...nextOptions.signal === void 0 ? {} : { signal: nextOptions.signal }
2601
+ }),
2602
+ (cursor) => this.#persistCursor({
2603
+ archiveKey: this.archiveKey,
2604
+ archivePath: this.path,
2605
+ cursor,
2606
+ format: "json",
2607
+ indexScope: this.indexScope,
2608
+ kind: "source-locators",
2609
+ targetUri: this.objectUri
2610
+ }),
2611
+ (token) => this.#releaseCursor(token)
2612
+ );
2613
+ }
2614
+ return createArchiveCollectionPage(
2615
+ result,
2616
+ async (cursor, nextOptions) => await this.list({
2617
+ ...options,
2618
+ cursor,
2619
+ ...nextOptions.limit === void 0 ? {} : { limit: nextOptions.limit },
2620
+ ...nextOptions.signal === void 0 ? {} : { signal: nextOptions.signal }
2621
+ }),
2622
+ (cursor) => this.#persistCursor({
2623
+ archiveKey: this.archiveKey,
2624
+ archivePath: this.path,
2625
+ ...options.backlinks === void 0 ? {} : { backlinks: options.backlinks },
2626
+ chapters: options.chapters ?? null,
2627
+ cursor,
2628
+ ...options.evidenceLimit === void 0 ? {} : { evidenceLimit: options.evidenceLimit },
2629
+ format: "json",
2630
+ ids: options.ids ?? null,
2631
+ indexScope: this.indexScope,
2632
+ kind: "collection",
2633
+ order: options.order ?? "doc-asc",
2634
+ ...options.sourceContext === void 0 ? {} : { sourceContext: options.sourceContext },
2635
+ ...options.triplePattern === void 0 ? {} : { triplePattern: options.triplePattern },
2636
+ types: options.types ?? null
2637
+ }),
2638
+ (token) => this.#releaseCursor(token)
2639
+ );
2248
2640
  }
2249
2641
  async ensureSearchIndex(options = {}) {
2250
2642
  const embeddingProvider = await this.#runtime.run(
@@ -2433,7 +2825,7 @@ var WikiGraphArchiveHandle = class {
2433
2825
  return await this.#writeDocument(async (document) => {
2434
2826
  const chapterId = await resolveChapterPathReadonly(document, path);
2435
2827
  await assertChapterResetAllowed(
2436
- this.#location.archiveFile,
2828
+ requireWikiGraphArchiveFile(this.#location),
2437
2829
  chapterId,
2438
2830
  stage
2439
2831
  );
@@ -2521,19 +2913,30 @@ var WikiGraphArchiveHandle = class {
2521
2913
  if (options.queryMode !== void 0) {
2522
2914
  throw new Error("`queryMode` requires `query`.");
2523
2915
  }
2524
- return await this.#readDocument(async (document) => {
2916
+ const result2 = await this.#readDocument(async (document) => {
2525
2917
  const chapters = await this.#resolveScope(document, {});
2526
2918
  return await listRelatedArchiveObjects(document, objectUri, {
2527
2919
  ...withoutOperation(options),
2528
2920
  ...chapters === void 0 ? {} : { chapters }
2529
2921
  });
2530
2922
  }, options);
2923
+ return createArchiveRelatedPage(
2924
+ result2,
2925
+ async (cursor, nextOptions) => await this.related(objectUri, {
2926
+ ...options,
2927
+ cursor,
2928
+ ...nextOptions.limit === void 0 ? {} : { limit: nextOptions.limit },
2929
+ ...nextOptions.signal === void 0 ? {} : { signal: nextOptions.signal }
2930
+ }),
2931
+ (cursor) => Promise.resolve(cursor),
2932
+ () => Promise.resolve()
2933
+ );
2531
2934
  }
2532
2935
  const embeddingProvider = await this.#resolveQueryEmbeddingProvider(
2533
2936
  options.queryMode,
2534
2937
  options.signal
2535
2938
  );
2536
- return await this.#writeDocument(
2939
+ const result = await this.#writeDocument(
2537
2940
  async (document) => {
2538
2941
  const chapters = await this.#resolveQueryChapters(document, options, {
2539
2942
  embeddingProvider
@@ -2553,25 +2956,47 @@ var WikiGraphArchiveHandle = class {
2553
2956
  ...options.signal === void 0 ? {} : { signal: options.signal }
2554
2957
  }
2555
2958
  );
2959
+ return createArchiveRelatedPage(
2960
+ result,
2961
+ async (cursor, nextOptions) => await this.related(objectUri, {
2962
+ ...options,
2963
+ cursor,
2964
+ ...nextOptions.limit === void 0 ? {} : { limit: nextOptions.limit },
2965
+ ...nextOptions.signal === void 0 ? {} : { signal: nextOptions.signal }
2966
+ }),
2967
+ (cursor) => Promise.resolve(cursor),
2968
+ () => Promise.resolve()
2969
+ );
2556
2970
  }
2557
2971
  async evidence(objectUri = this.objectUri, options = {}) {
2558
2972
  if (options.query === void 0) {
2559
2973
  if (options.queryMode !== void 0) {
2560
2974
  throw new Error("`queryMode` requires `query`.");
2561
2975
  }
2562
- return await this.#readDocument(async (document) => {
2976
+ const result2 = await this.#readDocument(async (document) => {
2563
2977
  const chapters = await this.#resolveScope(document, {});
2564
2978
  return await listArchiveEvidence(document, objectUri, {
2565
2979
  ...withoutOperation(options),
2566
2980
  ...chapters === void 0 ? {} : { chapters }
2567
2981
  });
2568
2982
  }, options);
2983
+ return createArchiveEvidencePage(
2984
+ result2,
2985
+ async (cursor, nextOptions) => await this.evidence(objectUri, {
2986
+ ...options,
2987
+ cursor,
2988
+ ...nextOptions.limit === void 0 ? {} : { limit: nextOptions.limit },
2989
+ ...nextOptions.signal === void 0 ? {} : { signal: nextOptions.signal }
2990
+ }),
2991
+ (cursor) => Promise.resolve(cursor),
2992
+ () => Promise.resolve()
2993
+ );
2569
2994
  }
2570
2995
  const embeddingProvider = await this.#resolveQueryEmbeddingProvider(
2571
2996
  options.queryMode,
2572
2997
  options.signal
2573
2998
  );
2574
- return await this.#writeDocument(
2999
+ const result = await this.#writeDocument(
2575
3000
  async (document) => {
2576
3001
  const chapters = await this.#resolveQueryChapters(document, options, {
2577
3002
  embeddingProvider
@@ -2591,6 +3016,17 @@ var WikiGraphArchiveHandle = class {
2591
3016
  ...options.signal === void 0 ? {} : { signal: options.signal }
2592
3017
  }
2593
3018
  );
3019
+ return createArchiveEvidencePage(
3020
+ result,
3021
+ async (cursor, nextOptions) => await this.evidence(objectUri, {
3022
+ ...options,
3023
+ cursor,
3024
+ ...nextOptions.limit === void 0 ? {} : { limit: nextOptions.limit },
3025
+ ...nextOptions.signal === void 0 ? {} : { signal: nextOptions.signal }
3026
+ }),
3027
+ (cursor) => Promise.resolve(cursor),
3028
+ () => Promise.resolve()
3029
+ );
2594
3030
  }
2595
3031
  async pack(objectUri = this.objectUri, budget = 5e3, options = {}) {
2596
3032
  return await this.#readDocument(
@@ -2635,14 +3071,18 @@ var WikiGraphArchiveHandle = class {
2635
3071
  }, options);
2636
3072
  }
2637
3073
  async readCover(options = {}) {
2638
- const app = new WikiGraph2({});
2639
- return await this.#runtime.run(
2640
- async () => await app.openSession(
3074
+ return await this.#runtime.run(async () => {
3075
+ if (this.#location.archiveFile.kind === "directory") {
3076
+ return await this.#readDocument(
3077
+ async (document) => await document.readCover()
3078
+ );
3079
+ }
3080
+ const app = new WikiGraph2({});
3081
+ return await app.openSession(
2641
3082
  this.#location.archiveFile,
2642
3083
  async (archive) => await archive.readCover()
2643
- ),
2644
- options.signal
2645
- );
3084
+ );
3085
+ }, options.signal);
2646
3086
  }
2647
3087
  async replaceMetadata(objectPath, value, options = {}) {
2648
3088
  return await this.#writeDocument(async (document) => {
@@ -2683,9 +3123,11 @@ var WikiGraphArchiveHandle = class {
2683
3123
  }
2684
3124
  async #readDocument(operation, options = {}) {
2685
3125
  return await this.#runtime.run(
2686
- async () => await new WikiGraphArchiveFile2(this.#location.archiveFile).readDocument(
2687
- operation
2688
- ),
3126
+ async () => this.#location.archiveFile.kind === "directory" ? await new WikiGraphDirectoryFile2(
3127
+ this.#location.archiveFile
3128
+ ).readDocument(operation) : await new WikiGraphArchiveFile2(
3129
+ this.#location.archiveFile
3130
+ ).readDocument(operation),
2689
3131
  options.signal
2690
3132
  );
2691
3133
  }
@@ -3074,7 +3516,7 @@ function parseProvider(value) {
3074
3516
 
3075
3517
  // src/continuations.ts
3076
3518
  import {
3077
- createContinuationCursor,
3519
+ createContinuationCursor as createContinuationCursor2,
3078
3520
  findArchiveObjects as findArchiveObjects2,
3079
3521
  findWikiGraphLibraryArchiveMembers,
3080
3522
  findWikiGraphLibraryObjects,
@@ -3088,7 +3530,8 @@ import {
3088
3530
  listWikiGraphLibraryObjects,
3089
3531
  readContinuationCursor,
3090
3532
  resolveWikiGraphLibraryQueryTargetById,
3091
- WikiGraphArchiveFile as WikiGraphArchiveFile3
3533
+ WikiGraphArchiveFile as WikiGraphArchiveFile3,
3534
+ WikiGraphDirectoryFile as WikiGraphDirectoryFile3
3092
3535
  } from "wiki-graph-core";
3093
3536
  var WikiGraphContinuationManager = class {
3094
3537
  #runtime;
@@ -3104,7 +3547,7 @@ var WikiGraphContinuationManager = class {
3104
3547
  async create(context, cursor) {
3105
3548
  if (cursor === null || cursor === void 0) return null;
3106
3549
  return await this.#runtime.run(
3107
- async () => await createContinuationCursor(
3550
+ async () => await createContinuationCursor2(
3108
3551
  createContinuationPayload(context, cursor)
3109
3552
  )
3110
3553
  );
@@ -3138,54 +3581,53 @@ async function continueArchiveCursor(cursor, limit) {
3138
3581
  const location = await resolveWikiGraphArchiveLocation(
3139
3582
  archiveTargetFromLogicalLocator(getCursorArchivePath(cursor))
3140
3583
  );
3141
- return await new WikiGraphArchiveFile3(location.archiveFile).readDocument(
3142
- async (document) => {
3143
- switch (cursor.kind) {
3144
- case "source-locators":
3145
- return await listArchiveSourceLocators2(document, cursor.targetUri, {
3146
- cursor: cursor.cursor,
3147
- limit
3148
- });
3149
- case "collection":
3150
- return await listArchiveCollection2(
3151
- document,
3152
- createCollectionOptions(cursor, limit)
3153
- );
3154
- case "search":
3155
- return await findArchiveObjects2(
3156
- document,
3157
- cursor.query ?? "",
3158
- await createFindOptions(cursor, limit)
3159
- );
3160
- case "evidence":
3161
- return await listArchiveEvidence2(document, cursor.targetUri, {
3162
- ...cursor.chapters === null ? {} : { chapters: cursor.chapters },
3163
- cursor: cursor.cursor,
3164
- limit,
3165
- order: cursor.order,
3166
- ...cursor.query === void 0 ? {} : { query: cursor.query },
3167
- ...cursor.queryMode === void 0 ? {} : { queryMode: cursor.queryMode },
3168
- ...embeddingProvider === void 0 ? {} : { embeddingProvider },
3169
- ...cursor.skipUnindexed === void 0 ? {} : { skipUnindexed: cursor.skipUnindexed },
3170
- ...cursor.sourceContext === void 0 ? {} : { sourceContext: cursor.sourceContext }
3171
- });
3172
- case "related":
3173
- return await listRelatedArchiveObjects2(document, cursor.targetUri, {
3174
- ...cursor.chapters === null ? {} : { chapters: cursor.chapters },
3175
- cursor: cursor.cursor,
3176
- ...cursor.evidenceLimit === void 0 ? {} : { evidenceLimit: cursor.evidenceLimit },
3177
- limit,
3178
- order: cursor.order,
3179
- ...cursor.query === void 0 ? {} : { query: cursor.query },
3180
- ...cursor.queryMode === void 0 ? {} : { queryMode: cursor.queryMode },
3181
- ...embeddingProvider === void 0 ? {} : { embeddingProvider },
3182
- ...cursor.role === void 0 ? {} : { role: cursor.role },
3183
- ...cursor.skipUnindexed === void 0 ? {} : { skipUnindexed: cursor.skipUnindexed },
3184
- ...cursor.sourceContext === void 0 ? {} : { sourceContext: cursor.sourceContext }
3185
- });
3186
- }
3584
+ const read = async (document) => {
3585
+ switch (cursor.kind) {
3586
+ case "source-locators":
3587
+ return await listArchiveSourceLocators2(document, cursor.targetUri, {
3588
+ cursor: cursor.cursor,
3589
+ limit
3590
+ });
3591
+ case "collection":
3592
+ return await listArchiveCollection2(
3593
+ document,
3594
+ createCollectionOptions(cursor, limit)
3595
+ );
3596
+ case "search":
3597
+ return await findArchiveObjects2(
3598
+ document,
3599
+ cursor.query ?? "",
3600
+ await createFindOptions(cursor, limit)
3601
+ );
3602
+ case "evidence":
3603
+ return await listArchiveEvidence2(document, cursor.targetUri, {
3604
+ ...cursor.chapters === null ? {} : { chapters: cursor.chapters },
3605
+ cursor: cursor.cursor,
3606
+ limit,
3607
+ order: cursor.order,
3608
+ ...cursor.query === void 0 ? {} : { query: cursor.query },
3609
+ ...cursor.queryMode === void 0 ? {} : { queryMode: cursor.queryMode },
3610
+ ...embeddingProvider === void 0 ? {} : { embeddingProvider },
3611
+ ...cursor.skipUnindexed === void 0 ? {} : { skipUnindexed: cursor.skipUnindexed },
3612
+ ...cursor.sourceContext === void 0 ? {} : { sourceContext: cursor.sourceContext }
3613
+ });
3614
+ case "related":
3615
+ return await listRelatedArchiveObjects2(document, cursor.targetUri, {
3616
+ ...cursor.chapters === null ? {} : { chapters: cursor.chapters },
3617
+ cursor: cursor.cursor,
3618
+ ...cursor.evidenceLimit === void 0 ? {} : { evidenceLimit: cursor.evidenceLimit },
3619
+ limit,
3620
+ order: cursor.order,
3621
+ ...cursor.query === void 0 ? {} : { query: cursor.query },
3622
+ ...cursor.queryMode === void 0 ? {} : { queryMode: cursor.queryMode },
3623
+ ...embeddingProvider === void 0 ? {} : { embeddingProvider },
3624
+ ...cursor.role === void 0 ? {} : { role: cursor.role },
3625
+ ...cursor.skipUnindexed === void 0 ? {} : { skipUnindexed: cursor.skipUnindexed },
3626
+ ...cursor.sourceContext === void 0 ? {} : { sourceContext: cursor.sourceContext }
3627
+ });
3187
3628
  }
3188
- );
3629
+ };
3630
+ return location.archiveFile.kind === "directory" ? await new WikiGraphDirectoryFile3(location.archiveFile).readDocument(read) : await new WikiGraphArchiveFile3(location.archiveFile).readDocument(read);
3189
3631
  }
3190
3632
  async function continueLibraryCursor(cursor, limit) {
3191
3633
  const embeddingProvider = cursor.kind === "evidence" || cursor.kind === "related" ? await resolveCursorEmbeddingProvider(cursor) : void 0;
@@ -3297,7 +3739,7 @@ function getCursorArchivePath(cursor) {
3297
3739
  }
3298
3740
  async function persistResultCursor(cursor, result) {
3299
3741
  if (result.nextCursor === null) return result;
3300
- const nextCursor = await createContinuationCursor({
3742
+ const nextCursor = await createContinuationCursor2({
3301
3743
  ...cursor,
3302
3744
  cursor: result.nextCursor
3303
3745
  });
@@ -4073,7 +4515,7 @@ var WikiGraphJobManager = class {
4073
4515
  return {
4074
4516
  job: await this.#backend.add({
4075
4517
  ...options,
4076
- archive: location.archiveFile
4518
+ archive: requireWikiGraphArchiveFile(location)
4077
4519
  }),
4078
4520
  target: location.target
4079
4521
  };
@@ -4105,7 +4547,9 @@ var WikiGraphJobManager = class {
4105
4547
  ...options.activeOnly === void 0 ? {} : { activeOnly: options.activeOnly },
4106
4548
  ...options.all === void 0 ? {} : { all: options.all },
4107
4549
  ...options.archive === void 0 ? {} : {
4108
- archive: (await resolveWikiGraphArchiveLocation(options.archive)).archiveFile
4550
+ archive: requireWikiGraphArchiveFile(
4551
+ await resolveWikiGraphArchiveLocation(options.archive)
4552
+ )
4109
4553
  }
4110
4554
  };
4111
4555
  const jobs = await this.#backend.list(normalized);
@@ -4130,7 +4574,7 @@ var WikiGraphJobManager = class {
4130
4574
  archiveJobs[0].archive
4131
4575
  );
4132
4576
  const chapters = await new WikiGraphArchiveFile6(
4133
- location.archiveFile
4577
+ requireWikiGraphArchiveFile(location)
4134
4578
  ).readDocument(async (document) => await listChapters3(document));
4135
4579
  const chaptersById = new Map(
4136
4580
  chapters.map((chapter) => [chapter.chapterId, chapter])
@@ -4173,7 +4617,7 @@ var WikiGraphJobManager = class {
4173
4617
  await validateQueueTargetConfig(target, llmJSON);
4174
4618
  const selectedExplicitly = options.chapterId !== void 0 || options.chapterIds !== void 0 || options.chapterPath !== void 0 || options.depth !== void 0;
4175
4619
  const candidates = await new WikiGraphArchiveFile6(
4176
- location.archiveFile
4620
+ requireWikiGraphArchiveFile(location)
4177
4621
  ).readDocument(async (document) => {
4178
4622
  const chapters = await listChapters3(document);
4179
4623
  const selected = await selectQueueChapters(
@@ -4217,7 +4661,7 @@ var WikiGraphJobManager = class {
4217
4661
  chapter: candidate.chapter,
4218
4662
  job: await this.#createHandle(
4219
4663
  await this.#backend.add({
4220
- archive: location.archiveFile,
4664
+ archive: requireWikiGraphArchiveFile(location),
4221
4665
  boost: options.boost ?? false,
4222
4666
  chapterId: candidate.chapter.chapterId,
4223
4667
  ...llmJSON === void 0 ? {} : { llmJSON },
@@ -4248,7 +4692,7 @@ var WikiGraphJobManager = class {
4248
4692
  await validateQueueTargetConfig(target, llmJSON);
4249
4693
  const selectedExplicitly = options.chapterId !== void 0 || options.chapterIds !== void 0 || options.chapterPath !== void 0 || options.depth !== void 0;
4250
4694
  const candidates = await new WikiGraphArchiveFile6(
4251
- location.archiveFile
4695
+ requireWikiGraphArchiveFile(location)
4252
4696
  ).readDocument(async (document) => {
4253
4697
  const chapters = await listChapters3(document);
4254
4698
  const selected = await selectQueueChapters(document, chapters, options);
@@ -4581,9 +5025,11 @@ import {
4581
5025
  assertWikiGraphLibrarySchemaCurrent,
4582
5026
  cleanWikiGraphLibraryIndex,
4583
5027
  clearWikiGraphLibraryMetadata,
5028
+ continueWikiGraphLibraryObjectBucket,
4584
5029
  createWikiGraphLibrary,
4585
5030
  deleteWikiGraphLibraryMetadataKey,
4586
5031
  findWikiGraphLibraryObjects as findWikiGraphLibraryObjects2,
5032
+ findWikiGraphLibraryObjectBuckets,
4587
5033
  findWikiGraphLibraryArchiveMembers as findWikiGraphLibraryArchiveMembers2,
4588
5034
  formatWikiGraphLibraryUri as formatWikiGraphLibraryUri2,
4589
5035
  getWikiGraphLibraryArchive,
@@ -4608,9 +5054,12 @@ import {
4608
5054
  replaceWikiGraphLibraryMetadata,
4609
5055
  resolveWikiGraphLibrary as resolveWikiGraphLibrary2,
4610
5056
  scanWikiGraphLibrary,
4611
- withWikiGraphLibraryLock
5057
+ withWikiGraphLibraryLock,
5058
+ writeWikgArchive as writeWikgArchive2
4612
5059
  } from "wiki-graph-core";
4613
- import { mkdir as mkdir3 } from "fs/promises";
5060
+ import { mkdir as mkdir3, mkdtemp as mkdtemp2, rm as rm4 } from "fs/promises";
5061
+ import { tmpdir as tmpdir2 } from "os";
5062
+ import { join as join5 } from "path";
4614
5063
  async function resolveQueryEmbeddingProvider(queryMode) {
4615
5064
  if (queryMode === "fts") return void 0;
4616
5065
  const provider = await createConfiguredEmbeddingProvider();
@@ -4700,7 +5149,18 @@ var WikiGraphLibraryManager = class {
4700
5149
  async () => {
4701
5150
  throwIfAborted(options.signal);
4702
5151
  const archive = await getWikiGraphLibraryArchive(parsedTarget);
4703
- const file = requireReadableLibraryArchiveFile(archive);
5152
+ const source = requireReadableLibraryArchiveFile(archive);
5153
+ let temporaryDirectory;
5154
+ const file = source.kind === "directory" ? await (async () => {
5155
+ temporaryDirectory = await mkdtemp2(
5156
+ join5(tmpdir2(), "wikigraph-library-read-")
5157
+ );
5158
+ const output = new NodeFile(
5159
+ join5(temporaryDirectory, "archive.wikg")
5160
+ );
5161
+ await writeWikgArchive2(source, output);
5162
+ return output;
5163
+ })() : source;
4704
5164
  const reader = await file.openReader();
4705
5165
  let active = true;
4706
5166
  try {
@@ -4721,6 +5181,8 @@ var WikiGraphLibraryManager = class {
4721
5181
  } finally {
4722
5182
  active = false;
4723
5183
  await reader.close();
5184
+ if (temporaryDirectory !== void 0)
5185
+ await rm4(temporaryDirectory, { force: true, recursive: true });
4724
5186
  }
4725
5187
  },
4726
5188
  options.signal === void 0 ? {} : { signal: options.signal }
@@ -4815,7 +5277,7 @@ var WikiGraphLibraryManager = class {
4815
5277
  );
4816
5278
  }
4817
5279
  async search(target, query, options = {}) {
4818
- return await this.#runtime.run(async () => {
5280
+ const result = await this.#runtime.run(async () => {
4819
5281
  const embeddingProvider = await resolveQueryEmbeddingProvider(
4820
5282
  options.queryMode
4821
5283
  );
@@ -4828,9 +5290,70 @@ var WikiGraphLibraryManager = class {
4828
5290
  }
4829
5291
  );
4830
5292
  });
5293
+ return createArchiveFindPage(
5294
+ result,
5295
+ async (cursor, nextOptions) => await this.search(target, query, {
5296
+ ...options,
5297
+ cursor,
5298
+ ...nextOptions.limit === void 0 ? {} : { limit: nextOptions.limit },
5299
+ ...nextOptions.signal === void 0 ? {} : { signal: nextOptions.signal }
5300
+ }),
5301
+ (cursor) => Promise.resolve(cursor),
5302
+ () => Promise.resolve()
5303
+ );
5304
+ }
5305
+ async searchBuckets(target, query, options) {
5306
+ const result = await this.#runtime.run(async () => {
5307
+ const embeddingProvider = await resolveQueryEmbeddingProvider(
5308
+ options.queryMode
5309
+ );
5310
+ return await findWikiGraphLibraryObjectBuckets(
5311
+ requireLibraryTarget(target),
5312
+ query,
5313
+ {
5314
+ ...options,
5315
+ ...embeddingProvider === void 0 ? {} : { embeddingProvider }
5316
+ }
5317
+ );
5318
+ });
5319
+ return {
5320
+ buckets: result.buckets.map(
5321
+ (bucket) => createLibraryBucketPage(
5322
+ bucket,
5323
+ async (cursor, nextOptions) => await this.continueSearchBucket(target, cursor, {
5324
+ ...nextOptions.limit === void 0 ? {} : { limit: nextOptions.limit }
5325
+ }),
5326
+ (cursor) => Promise.resolve(cursor),
5327
+ () => Promise.resolve()
5328
+ )
5329
+ ),
5330
+ query: result.query
5331
+ };
5332
+ }
5333
+ async continueSearchBucket(target, cursor, options = {}) {
5334
+ const result = await this.#runtime.run(async () => {
5335
+ const embeddingProvider = await resolveQueryEmbeddingProvider(void 0);
5336
+ return await continueWikiGraphLibraryObjectBucket(
5337
+ requireLibraryTarget(target),
5338
+ cursor,
5339
+ {
5340
+ ...options,
5341
+ ...embeddingProvider === void 0 ? {} : { embeddingProvider }
5342
+ }
5343
+ );
5344
+ });
5345
+ return createLibraryBucketPage(
5346
+ result,
5347
+ async (nextCursor, nextOptions) => await this.continueSearchBucket(target, nextCursor, {
5348
+ ...options,
5349
+ ...nextOptions.limit === void 0 ? {} : { limit: nextOptions.limit }
5350
+ }),
5351
+ (cursor2) => Promise.resolve(cursor2),
5352
+ () => Promise.resolve()
5353
+ );
4831
5354
  }
4832
5355
  async searchArchiveMembers(target, query, options = {}) {
4833
- return await this.#runtime.run(async () => {
5356
+ const result = await this.#runtime.run(async () => {
4834
5357
  const embeddingProvider = await resolveQueryEmbeddingProvider(
4835
5358
  options.queryMode
4836
5359
  );
@@ -4843,22 +5366,53 @@ var WikiGraphLibraryManager = class {
4843
5366
  }
4844
5367
  );
4845
5368
  });
5369
+ return createArchiveFindPage(
5370
+ result,
5371
+ async (cursor, nextOptions) => await this.searchArchiveMembers(target, query, {
5372
+ ...options,
5373
+ cursor,
5374
+ ...nextOptions.limit === void 0 ? {} : { limit: nextOptions.limit },
5375
+ ...nextOptions.signal === void 0 ? {} : { signal: nextOptions.signal }
5376
+ }),
5377
+ (cursor) => Promise.resolve(cursor),
5378
+ () => Promise.resolve()
5379
+ );
4846
5380
  }
4847
5381
  async objects(target, options = {}) {
4848
- return await this.#runtime.run(
5382
+ const result = await this.#runtime.run(
4849
5383
  async () => await listWikiGraphLibraryObjects2(
4850
5384
  requireLibraryTarget(target),
4851
5385
  options
4852
5386
  )
4853
5387
  );
5388
+ return createArchiveCollectionPage(
5389
+ result,
5390
+ async (cursor, nextOptions) => await this.objects(target, {
5391
+ ...options,
5392
+ cursor,
5393
+ ...nextOptions.limit === void 0 ? {} : { limit: nextOptions.limit }
5394
+ }),
5395
+ (cursor) => Promise.resolve(cursor),
5396
+ () => Promise.resolve()
5397
+ );
4854
5398
  }
4855
5399
  async archiveMembers(target, options = {}) {
4856
- return await this.#runtime.run(
5400
+ const result = await this.#runtime.run(
4857
5401
  async () => await listWikiGraphLibraryArchiveMembers2(
4858
5402
  requireLibraryTarget(target),
4859
5403
  options
4860
5404
  )
4861
5405
  );
5406
+ return createArchiveCollectionPage(
5407
+ result,
5408
+ async (cursor, nextOptions) => await this.archiveMembers(target, {
5409
+ ...options,
5410
+ cursor,
5411
+ ...nextOptions.limit === void 0 ? {} : { limit: nextOptions.limit }
5412
+ }),
5413
+ (cursor) => Promise.resolve(cursor),
5414
+ () => Promise.resolve()
5415
+ );
4862
5416
  }
4863
5417
  async page(target, objectUri, options = {}) {
4864
5418
  return await this.#runtime.run(
@@ -4874,7 +5428,7 @@ var WikiGraphLibraryManager = class {
4874
5428
  );
4875
5429
  }
4876
5430
  async related(target, objectUri, options = {}) {
4877
- return await this.#runtime.run(async () => {
5431
+ const result = await this.#runtime.run(async () => {
4878
5432
  if (options.query === void 0 && options.queryMode !== void 0) {
4879
5433
  throw new Error("`queryMode` requires `query`.");
4880
5434
  }
@@ -4888,9 +5442,20 @@ var WikiGraphLibraryManager = class {
4888
5442
  }
4889
5443
  );
4890
5444
  });
5445
+ return createArchiveRelatedPage(
5446
+ result,
5447
+ async (cursor, nextOptions) => await this.related(target, objectUri, {
5448
+ ...options,
5449
+ cursor,
5450
+ ...nextOptions.limit === void 0 ? {} : { limit: nextOptions.limit },
5451
+ ...nextOptions.signal === void 0 ? {} : { signal: nextOptions.signal }
5452
+ }),
5453
+ (cursor) => Promise.resolve(cursor),
5454
+ () => Promise.resolve()
5455
+ );
4891
5456
  }
4892
5457
  async evidence(target, objectUri, options = {}) {
4893
- return await this.#runtime.run(async () => {
5458
+ const result = await this.#runtime.run(async () => {
4894
5459
  if (options.query === void 0 && options.queryMode !== void 0) {
4895
5460
  throw new Error("`queryMode` requires `query`.");
4896
5461
  }
@@ -4904,6 +5469,17 @@ var WikiGraphLibraryManager = class {
4904
5469
  }
4905
5470
  );
4906
5471
  });
5472
+ return createArchiveEvidencePage(
5473
+ result,
5474
+ async (cursor, nextOptions) => await this.evidence(target, objectUri, {
5475
+ ...options,
5476
+ cursor,
5477
+ ...nextOptions.limit === void 0 ? {} : { limit: nextOptions.limit },
5478
+ ...nextOptions.signal === void 0 ? {} : { signal: nextOptions.signal }
5479
+ }),
5480
+ (cursor) => Promise.resolve(cursor),
5481
+ () => Promise.resolve()
5482
+ );
4907
5483
  }
4908
5484
  async pack(target, objectUri, budget = 5e3) {
4909
5485
  return await this.#runtime.run(
@@ -4968,7 +5544,7 @@ function toLibrarySnapshot(record) {
4968
5544
  };
4969
5545
  }
4970
5546
  function toArchiveSnapshot(record) {
4971
- const { file: _file, ...snapshot } = record;
5547
+ const { file: _file, directory: _directory, ...snapshot } = record;
4972
5548
  return snapshot;
4973
5549
  }
4974
5550
  function toScanSnapshot(result) {
@@ -5001,12 +5577,12 @@ function requireReadableLibraryArchiveFile(archive) {
5001
5577
  `Wiki Graph library archive has a conflict and cannot be read: ${archive.uri}`
5002
5578
  );
5003
5579
  }
5004
- if (archive.file === void 0) {
5580
+ if (archive.file === void 0 && archive.directory === void 0) {
5005
5581
  throw new Error(
5006
5582
  `Wiki Graph library archive is unavailable: ${archive.uri}`
5007
5583
  );
5008
5584
  }
5009
- return archive.file;
5585
+ return archive.file ?? archive.directory;
5010
5586
  }
5011
5587
  var ARCHIVE_STREAM_CHUNK_SIZE = 64 * 1024;
5012
5588
  function createCallbackScopedArchiveStream(reader, isActive, signal) {
@@ -5234,6 +5810,11 @@ import {
5234
5810
  requireLocatedObjectUri
5235
5811
  } from "wiki-graph-core";
5236
5812
  export {
5813
+ ArchiveCollectionPage,
5814
+ ArchiveEvidencePage,
5815
+ ArchiveFindPage,
5816
+ ArchiveRelatedPage,
5817
+ ArchiveSourceLocatorPage,
5237
5818
  DANGEROUS_RUNTIME_ENV_NAMES,
5238
5819
  DEFAULT_EXTRACTION_PROMPT,
5239
5820
  DEFAULT_GENERATION_JOB_CONCURRENCY,
@@ -5241,6 +5822,7 @@ export {
5241
5822
  DEFAULT_KNOWLEDGE_GRAPH_RECALL_PROMPT,
5242
5823
  LLMPaymentRequiredError,
5243
5824
  LOCAL_CONFIG_SECTIONS,
5825
+ LibraryBucketPage,
5244
5826
  NodeDirectory,
5245
5827
  NodeFile,
5246
5828
  WIKI_GRAPH_URI_PREFIX,
@@ -5261,11 +5843,19 @@ export {
5261
5843
  buildSearchIndexEmbeddingProvider,
5262
5844
  buildWikiGraphLLMOptions,
5263
5845
  clearLocalConfigSection,
5846
+ createArchiveCollectionPage,
5847
+ createArchiveEvidencePage,
5848
+ createArchiveFindPage,
5849
+ createArchiveRelatedPage,
5850
+ createArchiveSourceLocatorPage,
5851
+ createCursor,
5264
5852
  createEntryRuntimeContext,
5265
5853
  createGenerationPerformanceHints,
5854
+ createLibraryBucketPage,
5266
5855
  createNodeTemplateEnvironment,
5267
5856
  createNodeWikiGraphPlatform,
5268
5857
  createNodeWikiGraphStorage,
5858
+ createPageCursor,
5269
5859
  createStageLLM,
5270
5860
  createWikiGraphSDK,
5271
5861
  deleteLocalConfigValue,
@@ -5293,6 +5883,8 @@ export {
5293
5883
  isWikiGraphJobUri,
5294
5884
  isWikiGraphLibraryUri,
5295
5885
  isWikiGraphUri,
5886
+ iterateItems,
5887
+ iteratePages,
5296
5888
  loadRequiredStageConfig,
5297
5889
  loadWikiGraphRuntimeConfig,
5298
5890
  maskLocalConfigSection,