@fortemi/core 2026.6.3 → 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 +1 -1
- package/dist/index.d.ts +302 -27
- package/dist/index.js +227 -2
- 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,6 +6915,121 @@ 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
|
|
6809
7034
|
var AIWG_SCAN_REQUIRED_FIELDS = [
|
|
6810
7035
|
"schema_version",
|
|
@@ -7520,8 +7745,8 @@ function communityIdsFor(item, options) {
|
|
|
7520
7745
|
}
|
|
7521
7746
|
|
|
7522
7747
|
// src/index.ts
|
|
7523
|
-
var VERSION = "2026.6.
|
|
7748
|
+
var VERSION = "2026.6.4";
|
|
7524
7749
|
|
|
7525
|
-
export { AIWG_SCAN_REQUIRED_FIELDS, 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, buildAiwgChunkedIndex, buildNoteConditions, buildPluginCsp, captureKnowledge, chunkText, classifyError, classifyModel, collectionFromShard, collectionToShard, computeHash, computeSri, conceptTaggingHandler, cosineSimilarity, createAiwgFetchChunkLoader, createAiwgFetchDetailLoader, 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 };
|
|
7526
7751
|
//# sourceMappingURL=index.js.map
|
|
7527
7752
|
//# sourceMappingURL=index.js.map
|