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.
- package/README.md +13 -3
- package/dist/archives.cjs +382 -25
- package/dist/archives.cjs.map +1 -1
- package/dist/archives.d.ts +4 -216
- package/dist/archives.js +372 -13
- package/dist/archives.js.map +1 -1
- package/dist/conversions.cjs +11 -12
- package/dist/conversions.cjs.map +1 -1
- package/dist/conversions.js +6 -7
- package/dist/conversions.js.map +1 -1
- package/dist/default-worker.cjs +40 -17
- package/dist/default-worker.cjs.map +1 -1
- package/dist/default-worker.js +37 -14
- package/dist/default-worker.js.map +1 -1
- package/dist/embedding.cjs +6 -7
- package/dist/embedding.cjs.map +1 -1
- package/dist/embedding.js +6 -7
- package/dist/embedding.js.map +1 -1
- package/dist/gc.cjs +61 -9
- package/dist/gc.cjs.map +1 -1
- package/dist/gc.d.ts +1 -1
- package/dist/gc.js +61 -9
- package/dist/gc.js.map +1 -1
- package/dist/host-IbqJ8WSV.d.ts +18 -0
- package/dist/index-DQzLAnjf.d.ts +346 -0
- package/dist/index.cjs +622 -40
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +20 -12
- package/dist/index.js +601 -31
- package/dist/index.js.map +1 -1
- package/dist/local-config.cjs +6 -7
- package/dist/local-config.cjs.map +1 -1
- package/dist/local-config.js +6 -7
- package/dist/local-config.js.map +1 -1
- package/dist/maintenance.cjs.map +1 -1
- package/dist/maintenance.js.map +1 -1
- package/dist/runtime-config.cjs +6 -7
- package/dist/runtime-config.cjs.map +1 -1
- package/dist/runtime-config.js +6 -7
- package/dist/runtime-config.js.map +1 -1
- package/dist/stage.cjs +6 -7
- package/dist/stage.cjs.map +1 -1
- package/dist/stage.js +6 -7
- package/dist/stage.js.map +1 -1
- package/dist/worker.cjs +55 -31
- package/dist/worker.cjs.map +1 -1
- package/dist/worker.d.ts +1 -1
- package/dist/worker.js +61 -37
- package/dist/worker.js.map +1 -1
- package/package.json +2 -2
- package/dist/host-pQiVAKEY.d.ts +0 -10
package/README.md
CHANGED
|
@@ -40,13 +40,18 @@ const wikiGraph = createWikiGraphSDK({
|
|
|
40
40
|
libraryRoot: "/path/to/home",
|
|
41
41
|
documentStoreRoot: "/path/to/documents",
|
|
42
42
|
}),
|
|
43
|
+
stateDir: "/path/to/state",
|
|
43
44
|
},
|
|
44
45
|
});
|
|
45
46
|
```
|
|
46
47
|
|
|
47
|
-
Storage
|
|
48
|
-
are process-wide; SDK instances in one process
|
|
49
|
-
platform.
|
|
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.
|
|
50
55
|
|
|
51
56
|
Applications may replace the configured LLM and embedding implementations for
|
|
52
57
|
one SDK instance:
|
|
@@ -73,6 +78,11 @@ Job event subscriptions observe durable work without coupling observation to
|
|
|
73
78
|
cancellation. Call `job.cancel()` explicitly to cancel a job; unsubscribing
|
|
74
79
|
only stops the current listener.
|
|
75
80
|
|
|
81
|
+
`libraries.searchBuckets()` projects one shared search session into typed,
|
|
82
|
+
independently paginated buckets. Continue one bucket with
|
|
83
|
+
`libraries.continueSearchBucket()`; sibling cursors remain unchanged. The
|
|
84
|
+
existing `libraries.search()` API keeps its sequential single-cursor result.
|
|
85
|
+
|
|
76
86
|
Services that receive chapter job artifacts as files can apply an ordered,
|
|
77
87
|
lazy sequence through the Node delivery boundary without importing Core:
|
|
78
88
|
|
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
|
|
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
|
|
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
|
-
|
|
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
|
|
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,
|
|
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,
|
|
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,
|
|
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) {
|
|
@@ -1901,6 +1900,236 @@ async function writeWikiGraphArchiveLocation(location, operation, options = {})
|
|
|
1901
1900
|
});
|
|
1902
1901
|
}
|
|
1903
1902
|
|
|
1903
|
+
// src/pages.ts
|
|
1904
|
+
function createCursor(implementation) {
|
|
1905
|
+
let released = false;
|
|
1906
|
+
const assertLive = () => {
|
|
1907
|
+
if (released) throw new Error("Cursor has been released.");
|
|
1908
|
+
};
|
|
1909
|
+
return {
|
|
1910
|
+
pageClass: implementation.pageClass,
|
|
1911
|
+
async next(options = {}) {
|
|
1912
|
+
assertLive();
|
|
1913
|
+
return await implementation.next(options);
|
|
1914
|
+
},
|
|
1915
|
+
async token() {
|
|
1916
|
+
assertLive();
|
|
1917
|
+
return await implementation.token();
|
|
1918
|
+
},
|
|
1919
|
+
async release() {
|
|
1920
|
+
if (released) return;
|
|
1921
|
+
released = true;
|
|
1922
|
+
await implementation.release?.();
|
|
1923
|
+
}
|
|
1924
|
+
};
|
|
1925
|
+
}
|
|
1926
|
+
function createPageCursor(implementation) {
|
|
1927
|
+
let token;
|
|
1928
|
+
return createCursor({
|
|
1929
|
+
pageClass: implementation.pageClass,
|
|
1930
|
+
next: async (options) => await implementation.next(implementation.rawCursor, options),
|
|
1931
|
+
token: async () => {
|
|
1932
|
+
token ??= await implementation.createToken(implementation.rawCursor);
|
|
1933
|
+
return token;
|
|
1934
|
+
},
|
|
1935
|
+
release: async () => {
|
|
1936
|
+
if (token !== void 0) await implementation.releaseToken?.(token);
|
|
1937
|
+
token = void 0;
|
|
1938
|
+
}
|
|
1939
|
+
});
|
|
1940
|
+
}
|
|
1941
|
+
|
|
1942
|
+
// src/result-pages.ts
|
|
1943
|
+
var ArchiveFindPage = class _ArchiveFindPage {
|
|
1944
|
+
result;
|
|
1945
|
+
chapters;
|
|
1946
|
+
items;
|
|
1947
|
+
lens;
|
|
1948
|
+
lensHint;
|
|
1949
|
+
limit;
|
|
1950
|
+
match;
|
|
1951
|
+
rawNextCursor;
|
|
1952
|
+
order;
|
|
1953
|
+
query;
|
|
1954
|
+
terms;
|
|
1955
|
+
types;
|
|
1956
|
+
#cursor;
|
|
1957
|
+
constructor(result, cursor = null) {
|
|
1958
|
+
this.result = result;
|
|
1959
|
+
this.chapters = result.chapters;
|
|
1960
|
+
this.items = result.items;
|
|
1961
|
+
this.lens = result.lens;
|
|
1962
|
+
this.lensHint = result.lensHint;
|
|
1963
|
+
this.limit = result.limit;
|
|
1964
|
+
this.match = result.match;
|
|
1965
|
+
this.rawNextCursor = result.nextCursor;
|
|
1966
|
+
this.order = result.order;
|
|
1967
|
+
this.query = result.query;
|
|
1968
|
+
this.terms = result.terms;
|
|
1969
|
+
this.types = result.types;
|
|
1970
|
+
this.#cursor = cursor;
|
|
1971
|
+
}
|
|
1972
|
+
static pageClass = _ArchiveFindPage;
|
|
1973
|
+
[Symbol.iterator]() {
|
|
1974
|
+
return this.items[Symbol.iterator]();
|
|
1975
|
+
}
|
|
1976
|
+
nextCursor() {
|
|
1977
|
+
return this.#cursor;
|
|
1978
|
+
}
|
|
1979
|
+
};
|
|
1980
|
+
var ArchiveCollectionPage = class _ArchiveCollectionPage {
|
|
1981
|
+
result;
|
|
1982
|
+
chapters;
|
|
1983
|
+
ids;
|
|
1984
|
+
items;
|
|
1985
|
+
limit;
|
|
1986
|
+
rawNextCursor;
|
|
1987
|
+
order;
|
|
1988
|
+
types;
|
|
1989
|
+
#cursor;
|
|
1990
|
+
constructor(result, cursor = null) {
|
|
1991
|
+
this.result = result;
|
|
1992
|
+
this.chapters = result.chapters;
|
|
1993
|
+
this.ids = result.ids;
|
|
1994
|
+
this.items = result.items;
|
|
1995
|
+
this.limit = result.limit;
|
|
1996
|
+
this.rawNextCursor = result.nextCursor;
|
|
1997
|
+
this.order = result.order;
|
|
1998
|
+
this.types = result.types;
|
|
1999
|
+
this.#cursor = cursor;
|
|
2000
|
+
}
|
|
2001
|
+
static pageClass = _ArchiveCollectionPage;
|
|
2002
|
+
[Symbol.iterator]() {
|
|
2003
|
+
return this.items[Symbol.iterator]();
|
|
2004
|
+
}
|
|
2005
|
+
nextCursor() {
|
|
2006
|
+
return this.#cursor;
|
|
2007
|
+
}
|
|
2008
|
+
};
|
|
2009
|
+
var ArchiveEvidencePage = class _ArchiveEvidencePage {
|
|
2010
|
+
result;
|
|
2011
|
+
items;
|
|
2012
|
+
limit;
|
|
2013
|
+
rawNextCursor;
|
|
2014
|
+
#cursor;
|
|
2015
|
+
constructor(result, cursor = null) {
|
|
2016
|
+
this.result = result;
|
|
2017
|
+
this.items = result.items;
|
|
2018
|
+
this.limit = result.limit;
|
|
2019
|
+
this.rawNextCursor = result.nextCursor;
|
|
2020
|
+
this.#cursor = cursor;
|
|
2021
|
+
}
|
|
2022
|
+
static pageClass = _ArchiveEvidencePage;
|
|
2023
|
+
[Symbol.iterator]() {
|
|
2024
|
+
return this.items[Symbol.iterator]();
|
|
2025
|
+
}
|
|
2026
|
+
nextCursor() {
|
|
2027
|
+
return this.#cursor;
|
|
2028
|
+
}
|
|
2029
|
+
};
|
|
2030
|
+
var ArchiveRelatedPage = class _ArchiveRelatedPage {
|
|
2031
|
+
result;
|
|
2032
|
+
items;
|
|
2033
|
+
limit;
|
|
2034
|
+
rawNextCursor;
|
|
2035
|
+
#cursor;
|
|
2036
|
+
constructor(result, cursor = null) {
|
|
2037
|
+
this.result = result;
|
|
2038
|
+
this.items = result.items;
|
|
2039
|
+
this.limit = result.limit;
|
|
2040
|
+
this.rawNextCursor = result.nextCursor;
|
|
2041
|
+
this.#cursor = cursor;
|
|
2042
|
+
}
|
|
2043
|
+
static pageClass = _ArchiveRelatedPage;
|
|
2044
|
+
[Symbol.iterator]() {
|
|
2045
|
+
return this.items[Symbol.iterator]();
|
|
2046
|
+
}
|
|
2047
|
+
nextCursor() {
|
|
2048
|
+
return this.#cursor;
|
|
2049
|
+
}
|
|
2050
|
+
};
|
|
2051
|
+
var ArchiveSourceLocatorPage = class _ArchiveSourceLocatorPage {
|
|
2052
|
+
result;
|
|
2053
|
+
items;
|
|
2054
|
+
limit;
|
|
2055
|
+
rawNextCursor;
|
|
2056
|
+
#cursor;
|
|
2057
|
+
constructor(result, cursor = null) {
|
|
2058
|
+
this.result = result;
|
|
2059
|
+
this.items = result.items;
|
|
2060
|
+
this.limit = result.limit;
|
|
2061
|
+
this.rawNextCursor = result.nextCursor;
|
|
2062
|
+
this.#cursor = cursor;
|
|
2063
|
+
}
|
|
2064
|
+
static pageClass = _ArchiveSourceLocatorPage;
|
|
2065
|
+
[Symbol.iterator]() {
|
|
2066
|
+
return this.items[Symbol.iterator]();
|
|
2067
|
+
}
|
|
2068
|
+
nextCursor() {
|
|
2069
|
+
return this.#cursor;
|
|
2070
|
+
}
|
|
2071
|
+
};
|
|
2072
|
+
function createArchiveFindPage(result, next, createToken, releaseToken) {
|
|
2073
|
+
return new ArchiveFindPage(
|
|
2074
|
+
result,
|
|
2075
|
+
result.nextCursor === null ? null : createPageCursor({
|
|
2076
|
+
pageClass: ArchiveFindPage,
|
|
2077
|
+
rawCursor: result.nextCursor,
|
|
2078
|
+
next,
|
|
2079
|
+
createToken,
|
|
2080
|
+
releaseToken
|
|
2081
|
+
})
|
|
2082
|
+
);
|
|
2083
|
+
}
|
|
2084
|
+
function createArchiveCollectionPage(result, next, createToken, releaseToken) {
|
|
2085
|
+
return new ArchiveCollectionPage(
|
|
2086
|
+
result,
|
|
2087
|
+
result.nextCursor === null ? null : createPageCursor({
|
|
2088
|
+
pageClass: ArchiveCollectionPage,
|
|
2089
|
+
rawCursor: result.nextCursor,
|
|
2090
|
+
next,
|
|
2091
|
+
createToken,
|
|
2092
|
+
releaseToken
|
|
2093
|
+
})
|
|
2094
|
+
);
|
|
2095
|
+
}
|
|
2096
|
+
function createArchiveEvidencePage(result, next, createToken, releaseToken) {
|
|
2097
|
+
return new ArchiveEvidencePage(
|
|
2098
|
+
result,
|
|
2099
|
+
result.nextCursor === null ? null : createPageCursor({
|
|
2100
|
+
pageClass: ArchiveEvidencePage,
|
|
2101
|
+
rawCursor: result.nextCursor,
|
|
2102
|
+
next,
|
|
2103
|
+
createToken,
|
|
2104
|
+
releaseToken
|
|
2105
|
+
})
|
|
2106
|
+
);
|
|
2107
|
+
}
|
|
2108
|
+
function createArchiveRelatedPage(result, next, createToken, releaseToken) {
|
|
2109
|
+
return new ArchiveRelatedPage(
|
|
2110
|
+
result,
|
|
2111
|
+
result.nextCursor === null ? null : createPageCursor({
|
|
2112
|
+
pageClass: ArchiveRelatedPage,
|
|
2113
|
+
rawCursor: result.nextCursor,
|
|
2114
|
+
next,
|
|
2115
|
+
createToken,
|
|
2116
|
+
releaseToken
|
|
2117
|
+
})
|
|
2118
|
+
);
|
|
2119
|
+
}
|
|
2120
|
+
function createArchiveSourceLocatorPage(result, next, createToken, releaseToken) {
|
|
2121
|
+
return new ArchiveSourceLocatorPage(
|
|
2122
|
+
result,
|
|
2123
|
+
result.nextCursor === null ? null : createPageCursor({
|
|
2124
|
+
pageClass: ArchiveSourceLocatorPage,
|
|
2125
|
+
rawCursor: result.nextCursor,
|
|
2126
|
+
next,
|
|
2127
|
+
createToken,
|
|
2128
|
+
releaseToken
|
|
2129
|
+
})
|
|
2130
|
+
);
|
|
2131
|
+
}
|
|
2132
|
+
|
|
1904
2133
|
// src/archive/archive.ts
|
|
1905
2134
|
var WikiGraphArchiveExistsError = class extends Error {
|
|
1906
2135
|
code = "WIKI_GRAPH_ARCHIVE_EXISTS";
|
|
@@ -1938,10 +2167,10 @@ var WikiGraphArchiveManager = class {
|
|
|
1938
2167
|
});
|
|
1939
2168
|
}
|
|
1940
2169
|
if (options.replace === true) {
|
|
1941
|
-
await (0,
|
|
2170
|
+
await (0, import_promises5.rename)(outputPath, path);
|
|
1942
2171
|
} else {
|
|
1943
2172
|
try {
|
|
1944
|
-
await (0,
|
|
2173
|
+
await (0, import_promises5.link)(outputPath, path);
|
|
1945
2174
|
} catch (error) {
|
|
1946
2175
|
if (isNodeEEXISTError(error)) {
|
|
1947
2176
|
throw new WikiGraphArchiveExistsError(path);
|
|
@@ -1951,7 +2180,7 @@ var WikiGraphArchiveManager = class {
|
|
|
1951
2180
|
}
|
|
1952
2181
|
return { locatedUri: (0, import_wiki_graph_core7.formatLocatedWikiGraphUri)(path), path };
|
|
1953
2182
|
} finally {
|
|
1954
|
-
await (0,
|
|
2183
|
+
await (0, import_promises5.rm)(outputPath, { force: true, recursive: true });
|
|
1955
2184
|
}
|
|
1956
2185
|
}, options.signal);
|
|
1957
2186
|
}
|
|
@@ -1988,6 +2217,14 @@ var WikiGraphArchiveHandle = class {
|
|
|
1988
2217
|
get target() {
|
|
1989
2218
|
return this.#location.target;
|
|
1990
2219
|
}
|
|
2220
|
+
async #persistCursor(cursor) {
|
|
2221
|
+
return await this.#runtime.run(
|
|
2222
|
+
async () => await (0, import_wiki_graph_core7.createContinuationCursor)(cursor)
|
|
2223
|
+
);
|
|
2224
|
+
}
|
|
2225
|
+
async #releaseCursor(cursor) {
|
|
2226
|
+
await this.#runtime.run(async () => await (0, import_wiki_graph_core7.deleteContinuationCursor)(cursor));
|
|
2227
|
+
}
|
|
1991
2228
|
async inspect(options = {}) {
|
|
1992
2229
|
return await this.#readDocument(
|
|
1993
2230
|
async (document) => await inspectWikiGraphArchive(document, {
|
|
@@ -2002,7 +2239,7 @@ var WikiGraphArchiveHandle = class {
|
|
|
2002
2239
|
options.queryMode,
|
|
2003
2240
|
options.signal
|
|
2004
2241
|
);
|
|
2005
|
-
|
|
2242
|
+
const result = await this.#writeDocument(
|
|
2006
2243
|
async (document) => {
|
|
2007
2244
|
const chapters = await this.#resolveQueryChapters(document, options, {
|
|
2008
2245
|
embeddingProvider
|
|
@@ -2023,9 +2260,38 @@ var WikiGraphArchiveHandle = class {
|
|
|
2023
2260
|
...options.signal === void 0 ? {} : { signal: options.signal }
|
|
2024
2261
|
}
|
|
2025
2262
|
);
|
|
2263
|
+
return createArchiveFindPage(
|
|
2264
|
+
result,
|
|
2265
|
+
async (cursor, nextOptions) => await this.search(query, {
|
|
2266
|
+
...options,
|
|
2267
|
+
cursor,
|
|
2268
|
+
...nextOptions.limit === void 0 ? {} : { limit: nextOptions.limit },
|
|
2269
|
+
...nextOptions.signal === void 0 ? {} : { signal: nextOptions.signal }
|
|
2270
|
+
}),
|
|
2271
|
+
(cursor) => this.#persistCursor({
|
|
2272
|
+
archiveKey: this.archiveKey,
|
|
2273
|
+
archivePath: this.path,
|
|
2274
|
+
chapters: options.chapters ?? null,
|
|
2275
|
+
cursor,
|
|
2276
|
+
format: "json",
|
|
2277
|
+
indexScope: this.indexScope,
|
|
2278
|
+
kind: "search",
|
|
2279
|
+
...options.backlinks === void 0 ? {} : { backlinks: options.backlinks },
|
|
2280
|
+
...options.evidenceLimit === void 0 ? {} : { evidenceLimit: options.evidenceLimit },
|
|
2281
|
+
...options.match === void 0 ? {} : { match: options.match },
|
|
2282
|
+
...options.order === void 0 ? {} : { order: options.order },
|
|
2283
|
+
query,
|
|
2284
|
+
...options.queryMode === void 0 ? {} : { queryMode: options.queryMode },
|
|
2285
|
+
...options.skipUnindexed === void 0 ? {} : { skipUnindexed: options.skipUnindexed },
|
|
2286
|
+
...options.sourceContext === void 0 ? {} : { sourceContext: options.sourceContext },
|
|
2287
|
+
...options.triplePattern === void 0 ? {} : { triplePattern: options.triplePattern },
|
|
2288
|
+
types: options.types ?? null
|
|
2289
|
+
}),
|
|
2290
|
+
(token) => this.#releaseCursor(token)
|
|
2291
|
+
);
|
|
2026
2292
|
}
|
|
2027
2293
|
async list(options = {}) {
|
|
2028
|
-
|
|
2294
|
+
const result = await this.#readDocument(async (document) => {
|
|
2029
2295
|
if ((0, import_wiki_graph_core7.isSourceLocatorScopeUri)(this.objectUri)) {
|
|
2030
2296
|
return await (0, import_wiki_graph_core7.listArchiveSourceLocators)(document, this.objectUri, {
|
|
2031
2297
|
...options.cursor === void 0 ? {} : { cursor: options.cursor },
|
|
@@ -2038,6 +2304,53 @@ var WikiGraphArchiveHandle = class {
|
|
|
2038
2304
|
...chapters === void 0 ? {} : { chapters }
|
|
2039
2305
|
});
|
|
2040
2306
|
}, options);
|
|
2307
|
+
if ((0, import_wiki_graph_core7.isSourceLocatorScopeUri)(this.objectUri)) {
|
|
2308
|
+
return createArchiveSourceLocatorPage(
|
|
2309
|
+
result,
|
|
2310
|
+
async (cursor, nextOptions) => await this.list({
|
|
2311
|
+
...options,
|
|
2312
|
+
cursor,
|
|
2313
|
+
...nextOptions.limit === void 0 ? {} : { limit: nextOptions.limit },
|
|
2314
|
+
...nextOptions.signal === void 0 ? {} : { signal: nextOptions.signal }
|
|
2315
|
+
}),
|
|
2316
|
+
(cursor) => this.#persistCursor({
|
|
2317
|
+
archiveKey: this.archiveKey,
|
|
2318
|
+
archivePath: this.path,
|
|
2319
|
+
cursor,
|
|
2320
|
+
format: "json",
|
|
2321
|
+
indexScope: this.indexScope,
|
|
2322
|
+
kind: "source-locators",
|
|
2323
|
+
targetUri: this.objectUri
|
|
2324
|
+
}),
|
|
2325
|
+
(token) => this.#releaseCursor(token)
|
|
2326
|
+
);
|
|
2327
|
+
}
|
|
2328
|
+
return createArchiveCollectionPage(
|
|
2329
|
+
result,
|
|
2330
|
+
async (cursor, nextOptions) => await this.list({
|
|
2331
|
+
...options,
|
|
2332
|
+
cursor,
|
|
2333
|
+
...nextOptions.limit === void 0 ? {} : { limit: nextOptions.limit },
|
|
2334
|
+
...nextOptions.signal === void 0 ? {} : { signal: nextOptions.signal }
|
|
2335
|
+
}),
|
|
2336
|
+
(cursor) => this.#persistCursor({
|
|
2337
|
+
archiveKey: this.archiveKey,
|
|
2338
|
+
archivePath: this.path,
|
|
2339
|
+
...options.backlinks === void 0 ? {} : { backlinks: options.backlinks },
|
|
2340
|
+
chapters: options.chapters ?? null,
|
|
2341
|
+
cursor,
|
|
2342
|
+
...options.evidenceLimit === void 0 ? {} : { evidenceLimit: options.evidenceLimit },
|
|
2343
|
+
format: "json",
|
|
2344
|
+
ids: options.ids ?? null,
|
|
2345
|
+
indexScope: this.indexScope,
|
|
2346
|
+
kind: "collection",
|
|
2347
|
+
order: options.order ?? "doc-asc",
|
|
2348
|
+
...options.sourceContext === void 0 ? {} : { sourceContext: options.sourceContext },
|
|
2349
|
+
...options.triplePattern === void 0 ? {} : { triplePattern: options.triplePattern },
|
|
2350
|
+
types: options.types ?? null
|
|
2351
|
+
}),
|
|
2352
|
+
(token) => this.#releaseCursor(token)
|
|
2353
|
+
);
|
|
2041
2354
|
}
|
|
2042
2355
|
async ensureSearchIndex(options = {}) {
|
|
2043
2356
|
const embeddingProvider = await this.#runtime.run(
|
|
@@ -2314,19 +2627,30 @@ var WikiGraphArchiveHandle = class {
|
|
|
2314
2627
|
if (options.queryMode !== void 0) {
|
|
2315
2628
|
throw new Error("`queryMode` requires `query`.");
|
|
2316
2629
|
}
|
|
2317
|
-
|
|
2630
|
+
const result2 = await this.#readDocument(async (document) => {
|
|
2318
2631
|
const chapters = await this.#resolveScope(document, {});
|
|
2319
2632
|
return await (0, import_wiki_graph_core7.listRelatedArchiveObjects)(document, objectUri, {
|
|
2320
2633
|
...withoutOperation(options),
|
|
2321
2634
|
...chapters === void 0 ? {} : { chapters }
|
|
2322
2635
|
});
|
|
2323
2636
|
}, options);
|
|
2637
|
+
return createArchiveRelatedPage(
|
|
2638
|
+
result2,
|
|
2639
|
+
async (cursor, nextOptions) => await this.related(objectUri, {
|
|
2640
|
+
...options,
|
|
2641
|
+
cursor,
|
|
2642
|
+
...nextOptions.limit === void 0 ? {} : { limit: nextOptions.limit },
|
|
2643
|
+
...nextOptions.signal === void 0 ? {} : { signal: nextOptions.signal }
|
|
2644
|
+
}),
|
|
2645
|
+
(cursor) => Promise.resolve(cursor),
|
|
2646
|
+
() => Promise.resolve()
|
|
2647
|
+
);
|
|
2324
2648
|
}
|
|
2325
2649
|
const embeddingProvider = await this.#resolveQueryEmbeddingProvider(
|
|
2326
2650
|
options.queryMode,
|
|
2327
2651
|
options.signal
|
|
2328
2652
|
);
|
|
2329
|
-
|
|
2653
|
+
const result = await this.#writeDocument(
|
|
2330
2654
|
async (document) => {
|
|
2331
2655
|
const chapters = await this.#resolveQueryChapters(document, options, {
|
|
2332
2656
|
embeddingProvider
|
|
@@ -2346,25 +2670,47 @@ var WikiGraphArchiveHandle = class {
|
|
|
2346
2670
|
...options.signal === void 0 ? {} : { signal: options.signal }
|
|
2347
2671
|
}
|
|
2348
2672
|
);
|
|
2673
|
+
return createArchiveRelatedPage(
|
|
2674
|
+
result,
|
|
2675
|
+
async (cursor, nextOptions) => await this.related(objectUri, {
|
|
2676
|
+
...options,
|
|
2677
|
+
cursor,
|
|
2678
|
+
...nextOptions.limit === void 0 ? {} : { limit: nextOptions.limit },
|
|
2679
|
+
...nextOptions.signal === void 0 ? {} : { signal: nextOptions.signal }
|
|
2680
|
+
}),
|
|
2681
|
+
(cursor) => Promise.resolve(cursor),
|
|
2682
|
+
() => Promise.resolve()
|
|
2683
|
+
);
|
|
2349
2684
|
}
|
|
2350
2685
|
async evidence(objectUri = this.objectUri, options = {}) {
|
|
2351
2686
|
if (options.query === void 0) {
|
|
2352
2687
|
if (options.queryMode !== void 0) {
|
|
2353
2688
|
throw new Error("`queryMode` requires `query`.");
|
|
2354
2689
|
}
|
|
2355
|
-
|
|
2690
|
+
const result2 = await this.#readDocument(async (document) => {
|
|
2356
2691
|
const chapters = await this.#resolveScope(document, {});
|
|
2357
2692
|
return await (0, import_wiki_graph_core7.listArchiveEvidence)(document, objectUri, {
|
|
2358
2693
|
...withoutOperation(options),
|
|
2359
2694
|
...chapters === void 0 ? {} : { chapters }
|
|
2360
2695
|
});
|
|
2361
2696
|
}, options);
|
|
2697
|
+
return createArchiveEvidencePage(
|
|
2698
|
+
result2,
|
|
2699
|
+
async (cursor, nextOptions) => await this.evidence(objectUri, {
|
|
2700
|
+
...options,
|
|
2701
|
+
cursor,
|
|
2702
|
+
...nextOptions.limit === void 0 ? {} : { limit: nextOptions.limit },
|
|
2703
|
+
...nextOptions.signal === void 0 ? {} : { signal: nextOptions.signal }
|
|
2704
|
+
}),
|
|
2705
|
+
(cursor) => Promise.resolve(cursor),
|
|
2706
|
+
() => Promise.resolve()
|
|
2707
|
+
);
|
|
2362
2708
|
}
|
|
2363
2709
|
const embeddingProvider = await this.#resolveQueryEmbeddingProvider(
|
|
2364
2710
|
options.queryMode,
|
|
2365
2711
|
options.signal
|
|
2366
2712
|
);
|
|
2367
|
-
|
|
2713
|
+
const result = await this.#writeDocument(
|
|
2368
2714
|
async (document) => {
|
|
2369
2715
|
const chapters = await this.#resolveQueryChapters(document, options, {
|
|
2370
2716
|
embeddingProvider
|
|
@@ -2384,6 +2730,17 @@ var WikiGraphArchiveHandle = class {
|
|
|
2384
2730
|
...options.signal === void 0 ? {} : { signal: options.signal }
|
|
2385
2731
|
}
|
|
2386
2732
|
);
|
|
2733
|
+
return createArchiveEvidencePage(
|
|
2734
|
+
result,
|
|
2735
|
+
async (cursor, nextOptions) => await this.evidence(objectUri, {
|
|
2736
|
+
...options,
|
|
2737
|
+
cursor,
|
|
2738
|
+
...nextOptions.limit === void 0 ? {} : { limit: nextOptions.limit },
|
|
2739
|
+
...nextOptions.signal === void 0 ? {} : { signal: nextOptions.signal }
|
|
2740
|
+
}),
|
|
2741
|
+
(cursor) => Promise.resolve(cursor),
|
|
2742
|
+
() => Promise.resolve()
|
|
2743
|
+
);
|
|
2387
2744
|
}
|
|
2388
2745
|
async pack(objectUri = this.objectUri, budget = 5e3, options = {}) {
|
|
2389
2746
|
return await this.#readDocument(
|
|
@@ -2572,7 +2929,7 @@ function selectChapterSubtree(chapters, rootChapterId, depth) {
|
|
|
2572
2929
|
);
|
|
2573
2930
|
}
|
|
2574
2931
|
async function createEmptyArchiveFile(path) {
|
|
2575
|
-
const directoryPath = await (0,
|
|
2932
|
+
const directoryPath = await (0, import_promises5.mkdtemp)(
|
|
2576
2933
|
(0, import_path5.join)((0, import_os3.tmpdir)(), "wikigraph-archive-write-")
|
|
2577
2934
|
);
|
|
2578
2935
|
try {
|
|
@@ -2587,7 +2944,7 @@ async function createEmptyArchiveFile(path) {
|
|
|
2587
2944
|
}
|
|
2588
2945
|
await (0, import_wiki_graph_core7.writeWikgArchive)(directory, new NodeFile(path));
|
|
2589
2946
|
} finally {
|
|
2590
|
-
await (0,
|
|
2947
|
+
await (0, import_promises5.rm)(directoryPath, { force: true, recursive: true });
|
|
2591
2948
|
}
|
|
2592
2949
|
}
|
|
2593
2950
|
function isNodeEEXISTError(error) {
|
|
@@ -2595,7 +2952,7 @@ function isNodeEEXISTError(error) {
|
|
|
2595
2952
|
}
|
|
2596
2953
|
async function nodePathExists(path) {
|
|
2597
2954
|
try {
|
|
2598
|
-
await (0,
|
|
2955
|
+
await (0, import_promises5.stat)(path);
|
|
2599
2956
|
return true;
|
|
2600
2957
|
} catch (error) {
|
|
2601
2958
|
if (isNodeENOENTError(error)) return false;
|