@fortemi/core 2026.6.2 → 2026.6.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 +2 -1
- package/dist/aiwg-index.d.ts +31 -1
- package/dist/aiwg-index.js +177 -10
- package/dist/aiwg-index.js.map +1 -1
- package/dist/index.d.ts +303 -28
- package/dist/index.js +403 -11
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -4700,16 +4700,126 @@ function suggestTags(noteEmbedding, tagEmbeddings, threshold = 0.6, maxTags = 5)
|
|
|
4700
4700
|
return Array.from(tagEmbeddings.entries()).map(([tag, emb]) => ({ tag, score: cosineSimilarity(noteEmbedding, emb) })).filter(({ score }) => score > threshold).sort((a, b) => b.score - a.score).slice(0, maxTags).map(({ tag }) => tag);
|
|
4701
4701
|
}
|
|
4702
4702
|
|
|
4703
|
+
// src/capabilities/embed-worker-transport.ts
|
|
4704
|
+
var EMBED_REQUEST_KIND = "fortemi:embed:request";
|
|
4705
|
+
var EMBED_RESPONSE_KIND = "fortemi:embed:response";
|
|
4706
|
+
var DEFAULT_TIMEOUT_MS = 3e4;
|
|
4707
|
+
function isEmbedResponse(data) {
|
|
4708
|
+
return typeof data === "object" && data !== null && data.kind === EMBED_RESPONSE_KIND && typeof data.id === "number";
|
|
4709
|
+
}
|
|
4710
|
+
function isEmbedRequest(data) {
|
|
4711
|
+
return typeof data === "object" && data !== null && data.kind === EMBED_REQUEST_KIND && typeof data.id === "number" && Array.isArray(data.texts);
|
|
4712
|
+
}
|
|
4713
|
+
function createWorkerEmbedFunction(port, options) {
|
|
4714
|
+
const timeoutMs = options?.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
4715
|
+
const pending = /* @__PURE__ */ new Map();
|
|
4716
|
+
let nextId = 1;
|
|
4717
|
+
let disposed = false;
|
|
4718
|
+
const onMessage = (event) => {
|
|
4719
|
+
const data = event.data;
|
|
4720
|
+
if (!isEmbedResponse(data)) return;
|
|
4721
|
+
const entry = pending.get(data.id);
|
|
4722
|
+
if (!entry) return;
|
|
4723
|
+
pending.delete(data.id);
|
|
4724
|
+
if (entry.timer !== null) clearTimeout(entry.timer);
|
|
4725
|
+
if (data.error !== void 0) {
|
|
4726
|
+
entry.reject(new Error(data.error));
|
|
4727
|
+
} else if (Array.isArray(data.vectors)) {
|
|
4728
|
+
entry.resolve(data.vectors);
|
|
4729
|
+
} else {
|
|
4730
|
+
entry.reject(new Error("Embed worker returned a malformed response (no vectors, no error)"));
|
|
4731
|
+
}
|
|
4732
|
+
};
|
|
4733
|
+
port.addEventListener("message", onMessage);
|
|
4734
|
+
port.start?.();
|
|
4735
|
+
const embed = (texts) => {
|
|
4736
|
+
if (disposed) {
|
|
4737
|
+
return Promise.reject(new Error("Embed worker transport has been disposed"));
|
|
4738
|
+
}
|
|
4739
|
+
return new Promise((resolve, reject) => {
|
|
4740
|
+
const id = nextId++;
|
|
4741
|
+
let timer = null;
|
|
4742
|
+
if (timeoutMs > 0) {
|
|
4743
|
+
timer = setTimeout(() => {
|
|
4744
|
+
if (pending.delete(id)) {
|
|
4745
|
+
reject(new Error(`Embed worker request timed out after ${timeoutMs}ms`));
|
|
4746
|
+
}
|
|
4747
|
+
}, timeoutMs);
|
|
4748
|
+
}
|
|
4749
|
+
pending.set(id, { resolve, reject, timer });
|
|
4750
|
+
try {
|
|
4751
|
+
const message = { kind: EMBED_REQUEST_KIND, id, texts };
|
|
4752
|
+
port.postMessage(message);
|
|
4753
|
+
} catch (err) {
|
|
4754
|
+
pending.delete(id);
|
|
4755
|
+
if (timer !== null) clearTimeout(timer);
|
|
4756
|
+
reject(err instanceof Error ? err : new Error(String(err)));
|
|
4757
|
+
}
|
|
4758
|
+
});
|
|
4759
|
+
};
|
|
4760
|
+
const dispose = () => {
|
|
4761
|
+
if (disposed) return;
|
|
4762
|
+
disposed = true;
|
|
4763
|
+
port.removeEventListener("message", onMessage);
|
|
4764
|
+
for (const [, entry] of pending) {
|
|
4765
|
+
if (entry.timer !== null) clearTimeout(entry.timer);
|
|
4766
|
+
entry.reject(new Error("Embed worker transport has been disposed"));
|
|
4767
|
+
}
|
|
4768
|
+
pending.clear();
|
|
4769
|
+
};
|
|
4770
|
+
return { embed, dispose };
|
|
4771
|
+
}
|
|
4772
|
+
function handleEmbedRequests(port, embed) {
|
|
4773
|
+
const onMessage = (event) => {
|
|
4774
|
+
const data = event.data;
|
|
4775
|
+
if (!isEmbedRequest(data)) return;
|
|
4776
|
+
const { id, texts } = data;
|
|
4777
|
+
void Promise.resolve().then(() => embed(texts)).then((vectors) => {
|
|
4778
|
+
const reply = { kind: EMBED_RESPONSE_KIND, id, vectors };
|
|
4779
|
+
port.postMessage(reply);
|
|
4780
|
+
}).catch((err) => {
|
|
4781
|
+
const reply = {
|
|
4782
|
+
kind: EMBED_RESPONSE_KIND,
|
|
4783
|
+
id,
|
|
4784
|
+
error: err instanceof Error ? err.message : String(err)
|
|
4785
|
+
};
|
|
4786
|
+
port.postMessage(reply);
|
|
4787
|
+
});
|
|
4788
|
+
};
|
|
4789
|
+
port.addEventListener("message", onMessage);
|
|
4790
|
+
port.start?.();
|
|
4791
|
+
return () => {
|
|
4792
|
+
port.removeEventListener("message", onMessage);
|
|
4793
|
+
};
|
|
4794
|
+
}
|
|
4795
|
+
|
|
4703
4796
|
// src/capabilities/semantic-loader.ts
|
|
4797
|
+
var activeTransportDispose = null;
|
|
4798
|
+
function clearActiveTransport() {
|
|
4799
|
+
if (activeTransportDispose) {
|
|
4800
|
+
activeTransportDispose();
|
|
4801
|
+
activeTransportDispose = null;
|
|
4802
|
+
}
|
|
4803
|
+
}
|
|
4704
4804
|
function registerSemanticCapability(manager, embedFn2, onProgress) {
|
|
4705
4805
|
manager.registerLoader("semantic", async () => {
|
|
4706
4806
|
if (onProgress) onProgress(0);
|
|
4807
|
+
clearActiveTransport();
|
|
4707
4808
|
setEmbedFunction(embedFn2);
|
|
4708
4809
|
if (onProgress) onProgress(100);
|
|
4709
4810
|
});
|
|
4710
4811
|
}
|
|
4812
|
+
function registerSemanticCapabilityWorker(manager, port, options) {
|
|
4813
|
+
manager.registerLoader("semantic", async () => {
|
|
4814
|
+
clearActiveTransport();
|
|
4815
|
+
const { embed, dispose } = createWorkerEmbedFunction(port, options);
|
|
4816
|
+
activeTransportDispose = dispose;
|
|
4817
|
+
setEmbedFunction(embed);
|
|
4818
|
+
});
|
|
4819
|
+
}
|
|
4711
4820
|
function unregisterSemanticCapability() {
|
|
4712
4821
|
setEmbedFunction(null);
|
|
4822
|
+
clearActiveTransport();
|
|
4713
4823
|
}
|
|
4714
4824
|
|
|
4715
4825
|
// src/capabilities/llm-loader.ts
|
|
@@ -6805,7 +6915,133 @@ function parseJsonArray(data) {
|
|
|
6805
6915
|
return JSON.parse(decoder.decode(data));
|
|
6806
6916
|
}
|
|
6807
6917
|
|
|
6918
|
+
// src/shard/prefetch.ts
|
|
6919
|
+
var DEFAULT_CACHE_NAME = "fortemi-shards";
|
|
6920
|
+
var warmStore = /* @__PURE__ */ new Map();
|
|
6921
|
+
var inFlight = /* @__PURE__ */ new Map();
|
|
6922
|
+
function toUint8(data) {
|
|
6923
|
+
return data instanceof Uint8Array ? data : new Uint8Array(data);
|
|
6924
|
+
}
|
|
6925
|
+
function getCacheStorage() {
|
|
6926
|
+
return globalThis.caches;
|
|
6927
|
+
}
|
|
6928
|
+
async function readFromCacheStorage(url, cacheName) {
|
|
6929
|
+
const caches = getCacheStorage();
|
|
6930
|
+
if (!caches) return null;
|
|
6931
|
+
try {
|
|
6932
|
+
const cache = await caches.open(cacheName);
|
|
6933
|
+
const res = await cache.match(url);
|
|
6934
|
+
if (!res) return null;
|
|
6935
|
+
return new Uint8Array(await res.arrayBuffer());
|
|
6936
|
+
} catch {
|
|
6937
|
+
return null;
|
|
6938
|
+
}
|
|
6939
|
+
}
|
|
6940
|
+
async function writeToCacheStorage(url, bytes, cacheName) {
|
|
6941
|
+
const caches = getCacheStorage();
|
|
6942
|
+
if (!caches) return;
|
|
6943
|
+
try {
|
|
6944
|
+
const cache = await caches.open(cacheName);
|
|
6945
|
+
const body = bytes.slice().buffer;
|
|
6946
|
+
await cache.put(url, new Response(body));
|
|
6947
|
+
} catch {
|
|
6948
|
+
}
|
|
6949
|
+
}
|
|
6950
|
+
async function maybeHash(bytes, options) {
|
|
6951
|
+
const expected = options?.expectedSha256;
|
|
6952
|
+
if (expected !== void 0) {
|
|
6953
|
+
const actual = await sha256Hex(bytes);
|
|
6954
|
+
if (actual.toLowerCase() !== expected.toLowerCase()) {
|
|
6955
|
+
throw new Error(
|
|
6956
|
+
`Shard SHA-256 mismatch: expected ${expected.toLowerCase()}, got ${actual}`
|
|
6957
|
+
);
|
|
6958
|
+
}
|
|
6959
|
+
return actual;
|
|
6960
|
+
}
|
|
6961
|
+
if (options?.verify) {
|
|
6962
|
+
return sha256Hex(bytes);
|
|
6963
|
+
}
|
|
6964
|
+
return void 0;
|
|
6965
|
+
}
|
|
6966
|
+
function prefetchShard(url, options) {
|
|
6967
|
+
if (options?.bytes !== void 0) {
|
|
6968
|
+
const bytes = toUint8(options.bytes);
|
|
6969
|
+
return (async () => {
|
|
6970
|
+
const sha2562 = await maybeHash(bytes, options);
|
|
6971
|
+
warmStore.set(url, { bytes, sha256: sha2562 });
|
|
6972
|
+
if (options.useCacheStorage) {
|
|
6973
|
+
await writeToCacheStorage(url, bytes, options.cacheName ?? DEFAULT_CACHE_NAME);
|
|
6974
|
+
}
|
|
6975
|
+
return { url, bytes, byteLength: bytes.byteLength, sha256: sha2562, fromCache: false };
|
|
6976
|
+
})();
|
|
6977
|
+
}
|
|
6978
|
+
const existing = inFlight.get(url);
|
|
6979
|
+
if (existing) return existing;
|
|
6980
|
+
const cacheName = options?.cacheName ?? DEFAULT_CACHE_NAME;
|
|
6981
|
+
const fetchImpl = options?.fetchImpl ?? globalThis.fetch;
|
|
6982
|
+
const work = (async () => {
|
|
6983
|
+
let bytes = null;
|
|
6984
|
+
let fromCache = false;
|
|
6985
|
+
if (options?.useCacheStorage) {
|
|
6986
|
+
bytes = await readFromCacheStorage(url, cacheName);
|
|
6987
|
+
fromCache = bytes !== null;
|
|
6988
|
+
}
|
|
6989
|
+
if (!bytes) {
|
|
6990
|
+
if (typeof fetchImpl !== "function") {
|
|
6991
|
+
throw new Error("prefetchShard: no fetch implementation available (pass options.fetchImpl)");
|
|
6992
|
+
}
|
|
6993
|
+
const res = await fetchImpl(url, options?.signal ? { signal: options.signal } : void 0);
|
|
6994
|
+
if (!res.ok) {
|
|
6995
|
+
throw new Error(`Failed to prefetch shard ${url}: HTTP ${res.status} ${res.statusText}`);
|
|
6996
|
+
}
|
|
6997
|
+
bytes = new Uint8Array(await res.arrayBuffer());
|
|
6998
|
+
}
|
|
6999
|
+
const sha2562 = await maybeHash(bytes, options);
|
|
7000
|
+
warmStore.set(url, { bytes, sha256: sha2562 });
|
|
7001
|
+
if (options?.useCacheStorage && !fromCache) {
|
|
7002
|
+
await writeToCacheStorage(url, bytes, cacheName);
|
|
7003
|
+
}
|
|
7004
|
+
return { url, bytes, byteLength: bytes.byteLength, sha256: sha2562, fromCache };
|
|
7005
|
+
})();
|
|
7006
|
+
const tracked = work.finally(() => {
|
|
7007
|
+
inFlight.delete(url);
|
|
7008
|
+
});
|
|
7009
|
+
inFlight.set(url, tracked);
|
|
7010
|
+
return tracked;
|
|
7011
|
+
}
|
|
7012
|
+
function fromPrefetched(url) {
|
|
7013
|
+
const entry = warmStore.get(url);
|
|
7014
|
+
if (!entry) {
|
|
7015
|
+
throw new Error(`Shard not prefetched: ${url}. Call prefetchShard(url) first.`);
|
|
7016
|
+
}
|
|
7017
|
+
return entry.bytes;
|
|
7018
|
+
}
|
|
7019
|
+
function isShardPrefetched(url) {
|
|
7020
|
+
return warmStore.has(url);
|
|
7021
|
+
}
|
|
7022
|
+
function getPrefetchedSha256(url) {
|
|
7023
|
+
return warmStore.get(url)?.sha256;
|
|
7024
|
+
}
|
|
7025
|
+
function clearPrefetchedShard(url) {
|
|
7026
|
+
if (url === void 0) {
|
|
7027
|
+
warmStore.clear();
|
|
7028
|
+
return;
|
|
7029
|
+
}
|
|
7030
|
+
warmStore.delete(url);
|
|
7031
|
+
}
|
|
7032
|
+
|
|
6808
7033
|
// src/aiwg-index.ts
|
|
7034
|
+
var AIWG_SCAN_REQUIRED_FIELDS = [
|
|
7035
|
+
"schema_version",
|
|
7036
|
+
"id",
|
|
7037
|
+
"type",
|
|
7038
|
+
"title",
|
|
7039
|
+
"text",
|
|
7040
|
+
"facets",
|
|
7041
|
+
"tags",
|
|
7042
|
+
"concepts",
|
|
7043
|
+
"privacy"
|
|
7044
|
+
];
|
|
6809
7045
|
var REQUIRED_RECORD_FIELDS = [
|
|
6810
7046
|
"schema_version",
|
|
6811
7047
|
"id",
|
|
@@ -6917,6 +7153,20 @@ function validateAiwgFortemiChunkManifest(value) {
|
|
|
6917
7153
|
if (data.facets !== void 0 && !isFacetCounts(data.facets)) {
|
|
6918
7154
|
errors.push("facets must be a nested string-to-number count object");
|
|
6919
7155
|
}
|
|
7156
|
+
if (data.projection !== void 0) {
|
|
7157
|
+
if (!Array.isArray(data.projection) || !data.projection.every((field) => typeof field === "string")) {
|
|
7158
|
+
errors.push("projection must be an array of field names");
|
|
7159
|
+
} else {
|
|
7160
|
+
const present = new Set(data.projection);
|
|
7161
|
+
for (const field of AIWG_SCAN_REQUIRED_FIELDS) {
|
|
7162
|
+
if (!present.has(field)) errors.push("projection must include scan-required field " + field);
|
|
7163
|
+
}
|
|
7164
|
+
}
|
|
7165
|
+
}
|
|
7166
|
+
if (data.detail !== void 0) {
|
|
7167
|
+
if (!hasString(data.detail.href)) errors.push("detail.href is required");
|
|
7168
|
+
else if (!data.detail.href.includes("{id}")) errors.push("detail.href must contain the {id} placeholder");
|
|
7169
|
+
}
|
|
6920
7170
|
if (!Array.isArray(data?.parts)) errors.push("parts must be an array");
|
|
6921
7171
|
let expectedOffset = 0;
|
|
6922
7172
|
const parts = Array.isArray(data?.parts) ? data.parts : [];
|
|
@@ -6941,6 +7191,35 @@ function assertAiwgFortemiChunkManifest(value) {
|
|
|
6941
7191
|
}
|
|
6942
7192
|
return value;
|
|
6943
7193
|
}
|
|
7194
|
+
function validateProjectedRecords(items) {
|
|
7195
|
+
const errors = [];
|
|
7196
|
+
const ids = /* @__PURE__ */ new Set();
|
|
7197
|
+
let previousId = "";
|
|
7198
|
+
for (const [index, item] of items.entries()) {
|
|
7199
|
+
if (item.schema_version !== "aiwg.fortemi.index.record.v1") {
|
|
7200
|
+
errors.push("items[" + index + "].schema_version must be aiwg.fortemi.index.record.v1");
|
|
7201
|
+
}
|
|
7202
|
+
if (!hasString(item.id)) errors.push("items[" + index + "].id is required");
|
|
7203
|
+
if (hasString(item.id) && ids.has(item.id)) errors.push("duplicate id: " + item.id);
|
|
7204
|
+
if (hasString(item.id)) ids.add(item.id);
|
|
7205
|
+
if (previousId && hasString(item.id) && previousId.localeCompare(item.id) > 0) {
|
|
7206
|
+
errors.push("items must be sorted by id: " + previousId + " before " + item.id);
|
|
7207
|
+
}
|
|
7208
|
+
if (hasString(item.id)) previousId = item.id;
|
|
7209
|
+
if (!item.type || !VALID_TYPES.has(item.type)) errors.push("items[" + index + "].type is invalid");
|
|
7210
|
+
if (!hasString(item.title)) errors.push("items[" + index + "].title is required");
|
|
7211
|
+
if (typeof item.text !== "string") errors.push("items[" + index + "].text is required");
|
|
7212
|
+
if (!item.facets || typeof item.facets !== "object" || Array.isArray(item.facets)) {
|
|
7213
|
+
errors.push("items[" + index + "].facets must be an object");
|
|
7214
|
+
}
|
|
7215
|
+
if (!Array.isArray(item.tags)) errors.push("items[" + index + "].tags must be an array");
|
|
7216
|
+
if (!Array.isArray(item.concepts)) errors.push("items[" + index + "].concepts must be an array");
|
|
7217
|
+
if (!item.privacy || !hasString(item.privacy.classification)) {
|
|
7218
|
+
errors.push("items[" + index + "].privacy.classification is required");
|
|
7219
|
+
}
|
|
7220
|
+
}
|
|
7221
|
+
return errors;
|
|
7222
|
+
}
|
|
6944
7223
|
function validateAiwgFortemiChunkPart(value, partRef, manifest) {
|
|
6945
7224
|
const errors = [];
|
|
6946
7225
|
const data = value;
|
|
@@ -6959,13 +7238,17 @@ function validateAiwgFortemiChunkPart(value, partRef, manifest) {
|
|
|
6959
7238
|
errors.push("items length must match manifest part count " + partRef.count);
|
|
6960
7239
|
}
|
|
6961
7240
|
if (Array.isArray(data?.items)) {
|
|
6962
|
-
|
|
6963
|
-
|
|
6964
|
-
|
|
6965
|
-
|
|
6966
|
-
|
|
6967
|
-
|
|
6968
|
-
|
|
7241
|
+
if (manifest?.projection) {
|
|
7242
|
+
errors.push(...validateProjectedRecords(data.items).map((error) => "items." + error));
|
|
7243
|
+
} else {
|
|
7244
|
+
const validation = validateAiwgFortemiIndexExport({
|
|
7245
|
+
schema_version: "aiwg.fortemi.index.export.v1",
|
|
7246
|
+
generated_at: manifest?.generated_at ?? "1970-01-01T00:00:00.000Z",
|
|
7247
|
+
source: manifest?.source ?? { repo: "chunk", privacy: "public" },
|
|
7248
|
+
items: data.items
|
|
7249
|
+
});
|
|
7250
|
+
errors.push(...validation.errors.map((error) => "items." + error));
|
|
7251
|
+
}
|
|
6969
7252
|
}
|
|
6970
7253
|
return { valid: errors.length === 0, errors };
|
|
6971
7254
|
}
|
|
@@ -6984,6 +7267,16 @@ function createAiwgFetchChunkLoader(baseUrl) {
|
|
|
6984
7267
|
return response.json();
|
|
6985
7268
|
};
|
|
6986
7269
|
}
|
|
7270
|
+
function createAiwgFetchDetailLoader(baseUrl) {
|
|
7271
|
+
return async (id, manifest) => {
|
|
7272
|
+
if (!manifest.detail?.href) throw new Error("Manifest has no detail.href for record resolution");
|
|
7273
|
+
const relative = manifest.detail.href.replace("{id}", encodeURIComponent(id));
|
|
7274
|
+
const href = baseUrl ? new URL(relative, baseUrl).toString() : relative;
|
|
7275
|
+
const response = await fetch(href);
|
|
7276
|
+
if (!response.ok) throw new Error("Failed to fetch AIWG index detail " + href + ": " + response.status);
|
|
7277
|
+
return response.json();
|
|
7278
|
+
};
|
|
7279
|
+
}
|
|
6987
7280
|
function getAiwgFortemiFacets(items) {
|
|
6988
7281
|
const result = {};
|
|
6989
7282
|
for (const item of items) {
|
|
@@ -6997,6 +7290,49 @@ function getAiwgFortemiFacets(items) {
|
|
|
6997
7290
|
}
|
|
6998
7291
|
return result;
|
|
6999
7292
|
}
|
|
7293
|
+
function buildAiwgChunkedIndex(index, options = {}) {
|
|
7294
|
+
const partSize = hasPositiveInteger(options.partSize) ? options.partSize : 500;
|
|
7295
|
+
const projection = options.projection;
|
|
7296
|
+
const items = index.items;
|
|
7297
|
+
const pad = (value) => String(value).padStart(4, "0");
|
|
7298
|
+
const project = (record) => {
|
|
7299
|
+
if (!projection) return record;
|
|
7300
|
+
const slim = {};
|
|
7301
|
+
for (const field of projection) slim[field] = record[field];
|
|
7302
|
+
return slim;
|
|
7303
|
+
};
|
|
7304
|
+
const parts = [];
|
|
7305
|
+
const partRefs = [];
|
|
7306
|
+
for (let offset = 0, partIndex = 0; offset < items.length; offset += partSize, partIndex += 1) {
|
|
7307
|
+
const slice = items.slice(offset, offset + partSize);
|
|
7308
|
+
const href = "part-" + pad(partIndex) + ".json";
|
|
7309
|
+
parts.push({
|
|
7310
|
+
href,
|
|
7311
|
+
part: {
|
|
7312
|
+
schema_version: "aiwg.fortemi.index.chunk.v1",
|
|
7313
|
+
manifest_schema_version: "aiwg.fortemi.index.chunk-manifest.v1",
|
|
7314
|
+
offset,
|
|
7315
|
+
items: slice.map(project)
|
|
7316
|
+
}
|
|
7317
|
+
});
|
|
7318
|
+
partRefs.push({ href, offset, count: slice.length });
|
|
7319
|
+
}
|
|
7320
|
+
const manifest = {
|
|
7321
|
+
schema_version: "aiwg.fortemi.index.chunk-manifest.v1",
|
|
7322
|
+
generated_at: options.generatedAt ?? index.generated_at,
|
|
7323
|
+
source: index.source,
|
|
7324
|
+
total: items.length,
|
|
7325
|
+
part_size: partSize,
|
|
7326
|
+
facets: getAiwgFortemiFacets(items),
|
|
7327
|
+
parts: partRefs,
|
|
7328
|
+
...projection ? { projection, detail: { href: options.detailHref ?? "detail/{id}.json" } } : {}
|
|
7329
|
+
};
|
|
7330
|
+
return {
|
|
7331
|
+
manifest,
|
|
7332
|
+
parts,
|
|
7333
|
+
details: projection ? items.map((record) => ({ id: record.id, record })) : []
|
|
7334
|
+
};
|
|
7335
|
+
}
|
|
7000
7336
|
function includesAll(actual, expected) {
|
|
7001
7337
|
if (!expected || expected.length === 0) return true;
|
|
7002
7338
|
const actualSet = new Set(actual);
|
|
@@ -7051,7 +7387,7 @@ function createRankedEntries(items, q, options, ordinalBase = 0) {
|
|
|
7051
7387
|
if (!includesAll(item.tags, options.tags)) return false;
|
|
7052
7388
|
if (!includesAll(item.concepts, options.concepts)) return false;
|
|
7053
7389
|
if (!matchesFacetFilters(item, options.facets)) return false;
|
|
7054
|
-
if (options.relationshipTargetId && !item.relationships.some((rel) => rel.target_id === options.relationshipTargetId)) {
|
|
7390
|
+
if (options.relationshipTargetId && !(item.relationships ?? []).some((rel) => rel.target_id === options.relationshipTargetId)) {
|
|
7055
7391
|
return false;
|
|
7056
7392
|
}
|
|
7057
7393
|
return true;
|
|
@@ -7100,6 +7436,10 @@ function clampMaxCachedParts(value) {
|
|
|
7100
7436
|
if (!hasPositiveInteger(value)) return 3;
|
|
7101
7437
|
return value;
|
|
7102
7438
|
}
|
|
7439
|
+
function clampMaxCachedDetails(value) {
|
|
7440
|
+
if (!hasPositiveInteger(value)) return 32;
|
|
7441
|
+
return value;
|
|
7442
|
+
}
|
|
7103
7443
|
function isDirectChunkBrowse(query, options) {
|
|
7104
7444
|
return query.trim() === "" && !options.rank && !options.snippets && !options.includeMatches && !options.types && !options.facets && !options.tags && !options.concepts && !options.privacy && !options.relationshipTargetId;
|
|
7105
7445
|
}
|
|
@@ -7124,6 +7464,40 @@ async function loadChunkPart(runtime, part) {
|
|
|
7124
7464
|
}
|
|
7125
7465
|
return { part: parsed, fetched: true };
|
|
7126
7466
|
}
|
|
7467
|
+
async function getChunkRecord(runtime, id) {
|
|
7468
|
+
const cached = runtime.detailCache.get(id);
|
|
7469
|
+
if (cached) {
|
|
7470
|
+
runtime.detailCache.delete(id);
|
|
7471
|
+
runtime.detailCache.set(id, cached);
|
|
7472
|
+
return cached;
|
|
7473
|
+
}
|
|
7474
|
+
if (!runtime.manifest.projection) {
|
|
7475
|
+
for (const part of runtime.partCache.values()) {
|
|
7476
|
+
const found = part.items.find((item) => item.id === id);
|
|
7477
|
+
if (found) return found;
|
|
7478
|
+
}
|
|
7479
|
+
}
|
|
7480
|
+
if (!runtime.detailLoader) {
|
|
7481
|
+
throw new Error("No detailLoader configured to resolve record " + id);
|
|
7482
|
+
}
|
|
7483
|
+
const raw = await runtime.detailLoader(id, runtime.manifest);
|
|
7484
|
+
const record = assertAiwgFortemiIndexExport({
|
|
7485
|
+
schema_version: "aiwg.fortemi.index.export.v1",
|
|
7486
|
+
generated_at: runtime.manifest.generated_at,
|
|
7487
|
+
source: runtime.manifest.source,
|
|
7488
|
+
items: [raw]
|
|
7489
|
+
}).items[0];
|
|
7490
|
+
if (record.id !== id) {
|
|
7491
|
+
throw new Error("Detail record id mismatch: expected " + id + ", got " + record.id);
|
|
7492
|
+
}
|
|
7493
|
+
runtime.detailCache.set(id, record);
|
|
7494
|
+
while (runtime.detailCache.size > runtime.maxCachedDetails) {
|
|
7495
|
+
const oldest = runtime.detailCache.keys().next().value;
|
|
7496
|
+
if (oldest === void 0) break;
|
|
7497
|
+
runtime.detailCache.delete(oldest);
|
|
7498
|
+
}
|
|
7499
|
+
return record;
|
|
7500
|
+
}
|
|
7127
7501
|
async function queryChunkedAiwgFortemiIndex(runtime, query = "", options = {}) {
|
|
7128
7502
|
const q = query.trim().toLowerCase();
|
|
7129
7503
|
let scannedParts = 0;
|
|
@@ -7228,7 +7602,10 @@ function createAiwgIndexController(initialIndex) {
|
|
|
7228
7602
|
manifest: parsed,
|
|
7229
7603
|
loader,
|
|
7230
7604
|
maxCachedParts: clampMaxCachedParts(options.maxCachedParts),
|
|
7231
|
-
partCache: /* @__PURE__ */ new Map()
|
|
7605
|
+
partCache: /* @__PURE__ */ new Map(),
|
|
7606
|
+
detailLoader: options.detailLoader,
|
|
7607
|
+
maxCachedDetails: clampMaxCachedDetails(options.maxCachedDetails),
|
|
7608
|
+
detailCache: /* @__PURE__ */ new Map()
|
|
7232
7609
|
};
|
|
7233
7610
|
data = null;
|
|
7234
7611
|
reviewDecisions = [];
|
|
@@ -7271,8 +7648,23 @@ function createAiwgIndexController(initialIndex) {
|
|
|
7271
7648
|
throw error;
|
|
7272
7649
|
}
|
|
7273
7650
|
},
|
|
7651
|
+
async getRecord(id) {
|
|
7652
|
+
if (chunked) {
|
|
7653
|
+
try {
|
|
7654
|
+
return await getChunkRecord(chunked, id);
|
|
7655
|
+
} catch (err) {
|
|
7656
|
+
error = err instanceof Error ? err : new Error(String(err));
|
|
7657
|
+
notify();
|
|
7658
|
+
throw error;
|
|
7659
|
+
}
|
|
7660
|
+
}
|
|
7661
|
+
const found = requireIndex().items.find((item) => item.id === id);
|
|
7662
|
+
if (!found) throw new Error("Record not found: " + id);
|
|
7663
|
+
return found;
|
|
7664
|
+
},
|
|
7274
7665
|
clearChunkCache() {
|
|
7275
7666
|
chunked?.partCache.clear();
|
|
7667
|
+
chunked?.detailCache.clear();
|
|
7276
7668
|
error = null;
|
|
7277
7669
|
notify();
|
|
7278
7670
|
},
|
|
@@ -7353,8 +7745,8 @@ function communityIdsFor(item, options) {
|
|
|
7353
7745
|
}
|
|
7354
7746
|
|
|
7355
7747
|
// src/index.ts
|
|
7356
|
-
var VERSION = "2026.6.
|
|
7748
|
+
var VERSION = "2026.6.4";
|
|
7357
7749
|
|
|
7358
|
-
export { ArchiveManager, AttachmentsRepository, CURRENT_SHARD_VERSION, CapabilityManager, CaptureKnowledgeInputSchema, CollectionsRepository, CommunitiesRepository, EmbeddingSetsRepository, FallbackRouter, FortemiToolManifest, GetNoteInputSchema, GraphRepository, JOB_CAPABILITIES, JOB_PRIORITIES, JobQueueWorker, LOCAL_ENDPOINTS, LinksRepository, ListNotesInputSchema, ManageArchiveInputSchema, ManageAttachmentsInputSchema, ManageCapabilitiesInputSchema, ManageCollectionsInputSchema, ManageLinksInputSchema, ManageNoteInputSchema, ManageTagsInputSchema, MemoryBlobStore, MigrationRunner, NotesRepository, OpenAICompatibleProvider, PGliteStorageBackend, PGliteStorageBackendFactory, PGliteWorkerClient, PGliteWorkerStorageBackend, PGliteWorkerStorageBackendFactory, ProviderRegistry, SHARD_FORMAT, SearchInputSchema, SearchRepository, SkosRepository, TagsRepository, TransactionProxy, TypedEventBus, VERSION, aiRevisionHandler, aiwgFortemiIndexToCommunityGraph, allMigrations, appendPluginScript, assertAiwgFortemiChunkManifest, assertAiwgFortemiChunkPart, assertAiwgFortemiIndexExport, buildNoteConditions, buildPluginCsp, captureKnowledge, chunkText, classifyError, classifyModel, collectionFromShard, collectionToShard, computeHash, computeSri, conceptTaggingHandler, cosineSimilarity, createAiwgFetchChunkLoader, createAiwgIndexController, createAiwgReviewDecisionExport, createBlobStore, createCspReportHandler, createFortemi, createLegacyProvider, createPGliteInstance, createRoutes, defaultStorageBackendFactory, detectCommunities, detectGpuCapabilities, detectInferenceCapabilities, discoverLocalProviders, embeddingFromShard, embeddingGenerationHandler, embeddingSetFromShard, embeddingSetMemberToShard, embeddingSetToShard, embeddingToShard, enqueueFullWorkflow, enqueueJob, enqueueNoteCreationJobs, estimateModelFit, estimateVramMB, estimateVramTier, exportShard, fetchPluginScript, fortemiManifest, generateId, getAiwgFortemiFacets, getEmbedFunction, getFortemiBridge, getFortemiSecretStore, getJobQueueStatus, getLlmFunction, getNote, hasFortemiSecureSecrets, importShard, isPluginScriptAllowed, linkFromShard, linkToShard, linkingHandler, listNotes, manageArchive, manageAttachments, manageCapabilities, manageCollections, manageLinks, manageNote, manageTags, matchRoute, noteFromShard, noteSkosTagToShard, noteToShard, packTarGz, parseCspReport, provenanceEdgeToShard, queryAiwgFortemiIndex, registerLlmCapability, registerSemanticCapability, registerServiceWorker, searchTool, selectLlmModel, setEmbedFunction, setLlmFunction, sha256Hex, skosConceptToShard, skosRelationToShard, skosSchemeToShard, suggestTags, tagsFromShard, tagsToShard, titleGenerationHandler, unpackTarGz, unregisterLlmCapability, unregisterSemanticCapability, validateAiwgFortemiChunkManifest, validateAiwgFortemiChunkPart, validateAiwgFortemiIndexExport, validateChecksums, verifySri };
|
|
7750
|
+
export { AIWG_SCAN_REQUIRED_FIELDS, ArchiveManager, AttachmentsRepository, CURRENT_SHARD_VERSION, CapabilityManager, CaptureKnowledgeInputSchema, CollectionsRepository, CommunitiesRepository, EMBED_REQUEST_KIND, EMBED_RESPONSE_KIND, EmbeddingSetsRepository, FallbackRouter, FortemiToolManifest, GetNoteInputSchema, GraphRepository, JOB_CAPABILITIES, JOB_PRIORITIES, JobQueueWorker, LOCAL_ENDPOINTS, LinksRepository, ListNotesInputSchema, ManageArchiveInputSchema, ManageAttachmentsInputSchema, ManageCapabilitiesInputSchema, ManageCollectionsInputSchema, ManageLinksInputSchema, ManageNoteInputSchema, ManageTagsInputSchema, MemoryBlobStore, MigrationRunner, NotesRepository, OpenAICompatibleProvider, PGliteStorageBackend, PGliteStorageBackendFactory, PGliteWorkerClient, PGliteWorkerStorageBackend, PGliteWorkerStorageBackendFactory, ProviderRegistry, SHARD_FORMAT, SearchInputSchema, SearchRepository, SkosRepository, TagsRepository, TransactionProxy, TypedEventBus, VERSION, aiRevisionHandler, aiwgFortemiIndexToCommunityGraph, allMigrations, appendPluginScript, assertAiwgFortemiChunkManifest, assertAiwgFortemiChunkPart, assertAiwgFortemiIndexExport, buildAiwgChunkedIndex, buildNoteConditions, buildPluginCsp, captureKnowledge, chunkText, classifyError, classifyModel, clearPrefetchedShard, collectionFromShard, collectionToShard, computeHash, computeSri, conceptTaggingHandler, cosineSimilarity, createAiwgFetchChunkLoader, createAiwgFetchDetailLoader, createAiwgIndexController, createAiwgReviewDecisionExport, createBlobStore, createCspReportHandler, createFortemi, createLegacyProvider, createPGliteInstance, createRoutes, createWorkerEmbedFunction, defaultStorageBackendFactory, detectCommunities, detectGpuCapabilities, detectInferenceCapabilities, discoverLocalProviders, embeddingFromShard, embeddingGenerationHandler, embeddingSetFromShard, embeddingSetMemberToShard, embeddingSetToShard, embeddingToShard, enqueueFullWorkflow, enqueueJob, enqueueNoteCreationJobs, estimateModelFit, estimateVramMB, estimateVramTier, exportShard, fetchPluginScript, fortemiManifest, fromPrefetched, generateId, getAiwgFortemiFacets, getEmbedFunction, getFortemiBridge, getFortemiSecretStore, getJobQueueStatus, getLlmFunction, getNote, getPrefetchedSha256, handleEmbedRequests, hasFortemiSecureSecrets, importShard, isPluginScriptAllowed, isShardPrefetched, linkFromShard, linkToShard, linkingHandler, listNotes, manageArchive, manageAttachments, manageCapabilities, manageCollections, manageLinks, manageNote, manageTags, matchRoute, noteFromShard, noteSkosTagToShard, noteToShard, packTarGz, parseCspReport, prefetchShard, provenanceEdgeToShard, queryAiwgFortemiIndex, registerLlmCapability, registerSemanticCapability, registerSemanticCapabilityWorker, registerServiceWorker, searchTool, selectLlmModel, setEmbedFunction, setLlmFunction, sha256Hex, skosConceptToShard, skosRelationToShard, skosSchemeToShard, suggestTags, tagsFromShard, tagsToShard, titleGenerationHandler, unpackTarGz, unregisterLlmCapability, unregisterSemanticCapability, validateAiwgFortemiChunkManifest, validateAiwgFortemiChunkPart, validateAiwgFortemiIndexExport, validateChecksums, verifySri };
|
|
7359
7751
|
//# sourceMappingURL=index.js.map
|
|
7360
7752
|
//# sourceMappingURL=index.js.map
|