@equationalapplications/core-llm-wiki 4.12.0 → 4.13.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.d.mts +6 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.js +163 -18
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +163 -19
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -2
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { __privateAdd, EmbeddingService, SearchService, JobManager, PromptService, IngestionService, MaintenanceService, ImportExportService, RetrievalService, WriteService, __privateGet, __privateSet, normalizeSourceRef, normalizeSourceHash, generateId } from './chunk-6FWG2DG4.mjs';
|
|
2
2
|
export { HOOK_TIMEOUT_MARKER, PromptService, PrunePartialFailureError, WikiBusyError, parseEmbedding } from './chunk-6FWG2DG4.mjs';
|
|
3
|
+
import { buildConceptDocument, buildLogMd, buildIndexMd, buildRootIndexMd } from '@equationalapplications/core-okf';
|
|
3
4
|
|
|
4
5
|
// src/db/schema.ts
|
|
5
6
|
async function setupDatabase(db, prefix) {
|
|
@@ -1764,6 +1765,71 @@ function formatContext(bundle, options) {
|
|
|
1764
1765
|
return lines.join("\n");
|
|
1765
1766
|
}
|
|
1766
1767
|
|
|
1768
|
+
// src/utils/sanitizeForFilename.ts
|
|
1769
|
+
function shortHash(value) {
|
|
1770
|
+
let h1 = 5381;
|
|
1771
|
+
let h2 = 52711;
|
|
1772
|
+
for (let i = 0; i < value.length; i += 1) {
|
|
1773
|
+
const c = value.charCodeAt(i);
|
|
1774
|
+
h1 = Math.imul(h1, 33) ^ c;
|
|
1775
|
+
h2 = Math.imul(h2, 31) ^ c;
|
|
1776
|
+
}
|
|
1777
|
+
return (h1 >>> 0).toString(16).padStart(8, "0") + (h2 >>> 0).toString(16).padStart(8, "0");
|
|
1778
|
+
}
|
|
1779
|
+
var OKF_RESERVED_CONCEPT_NAMES = /* @__PURE__ */ new Set(["index", "log"]);
|
|
1780
|
+
var WINDOWS_RESERVED_NAMES = /* @__PURE__ */ new Set([
|
|
1781
|
+
"con",
|
|
1782
|
+
"prn",
|
|
1783
|
+
"aux",
|
|
1784
|
+
"nul",
|
|
1785
|
+
"com1",
|
|
1786
|
+
"com2",
|
|
1787
|
+
"com3",
|
|
1788
|
+
"com4",
|
|
1789
|
+
"com5",
|
|
1790
|
+
"com6",
|
|
1791
|
+
"com7",
|
|
1792
|
+
"com8",
|
|
1793
|
+
"com9",
|
|
1794
|
+
"lpt1",
|
|
1795
|
+
"lpt2",
|
|
1796
|
+
"lpt3",
|
|
1797
|
+
"lpt4",
|
|
1798
|
+
"lpt5",
|
|
1799
|
+
"lpt6",
|
|
1800
|
+
"lpt7",
|
|
1801
|
+
"lpt8",
|
|
1802
|
+
"lpt9"
|
|
1803
|
+
]);
|
|
1804
|
+
function isWindowsReservedName(name) {
|
|
1805
|
+
const base = name.split(".")[0];
|
|
1806
|
+
return WINDOWS_RESERVED_NAMES.has(base.toLowerCase());
|
|
1807
|
+
}
|
|
1808
|
+
function sanitizeForFilename(value) {
|
|
1809
|
+
const normalized = value.normalize("NFKC");
|
|
1810
|
+
const sanitized = normalized.replace(/[^A-Za-z0-9._-]+/g, "_").replace(/^\.+/, "_").replace(/_+/g, "_").replace(/^[_-]+|[_-]+$/g, "");
|
|
1811
|
+
const MAX_BASE = 200;
|
|
1812
|
+
const trimmed = sanitized.length > MAX_BASE ? sanitized.slice(0, MAX_BASE) : sanitized;
|
|
1813
|
+
let baseName = trimmed && trimmed !== "." && trimmed !== ".." ? trimmed : "entity";
|
|
1814
|
+
const withoutTrailingDotSpace = baseName.replace(/[. ]+$/, "");
|
|
1815
|
+
const hadTrailingDotSpace = withoutTrailingDotSpace !== baseName;
|
|
1816
|
+
if (hadTrailingDotSpace) {
|
|
1817
|
+
baseName = withoutTrailingDotSpace || "entity";
|
|
1818
|
+
}
|
|
1819
|
+
const windowsReserved = isWindowsReservedName(baseName);
|
|
1820
|
+
const needsSuffix = baseName !== value || sanitized.length > MAX_BASE || hadTrailingDotSpace || windowsReserved;
|
|
1821
|
+
if (!needsSuffix) return baseName;
|
|
1822
|
+
const suffix = `-${shortHash(value)}`;
|
|
1823
|
+
return `${baseName}${suffix}`;
|
|
1824
|
+
}
|
|
1825
|
+
function sanitizeConceptId(id) {
|
|
1826
|
+
const sanitized = sanitizeForFilename(id);
|
|
1827
|
+
if (OKF_RESERVED_CONCEPT_NAMES.has(sanitized.toLowerCase())) {
|
|
1828
|
+
return `${sanitized}-${shortHash(id)}`;
|
|
1829
|
+
}
|
|
1830
|
+
return sanitized;
|
|
1831
|
+
}
|
|
1832
|
+
|
|
1767
1833
|
// src/utils/formatMemoryDump.ts
|
|
1768
1834
|
function renderFact(f) {
|
|
1769
1835
|
const tags = (f.tags || []).join(", ");
|
|
@@ -1818,25 +1884,8 @@ function renderEntity(entityId, bundle, generatedAt) {
|
|
|
1818
1884
|
}
|
|
1819
1885
|
return lines.join("\n");
|
|
1820
1886
|
}
|
|
1821
|
-
function shortHash(value) {
|
|
1822
|
-
let h1 = 5381;
|
|
1823
|
-
let h2 = 52711;
|
|
1824
|
-
for (let i = 0; i < value.length; i += 1) {
|
|
1825
|
-
const c = value.charCodeAt(i);
|
|
1826
|
-
h1 = Math.imul(h1, 33) ^ c;
|
|
1827
|
-
h2 = Math.imul(h2, 31) ^ c;
|
|
1828
|
-
}
|
|
1829
|
-
return (h1 >>> 0).toString(16).padStart(8, "0") + (h2 >>> 0).toString(16).padStart(8, "0");
|
|
1830
|
-
}
|
|
1831
1887
|
function formatEntityFileName(entityId) {
|
|
1832
|
-
|
|
1833
|
-
const sanitized = normalized.replace(/[^A-Za-z0-9._-]+/g, "_").replace(/^\.+/, "_").replace(/_+/g, "_").replace(/^[_-]+|[_-]+$/g, "");
|
|
1834
|
-
const MAX_BASE = 200;
|
|
1835
|
-
const trimmed = sanitized.length > MAX_BASE ? sanitized.slice(0, MAX_BASE) : sanitized;
|
|
1836
|
-
const baseName = trimmed && trimmed !== "." && trimmed !== ".." ? trimmed : "entity";
|
|
1837
|
-
const needsSuffix = baseName !== entityId || sanitized.length > MAX_BASE;
|
|
1838
|
-
const uniqueBaseName = needsSuffix ? `${baseName}-${shortHash(entityId)}` : baseName;
|
|
1839
|
-
return `${uniqueBaseName}.md`;
|
|
1888
|
+
return `${sanitizeForFilename(entityId)}.md`;
|
|
1840
1889
|
}
|
|
1841
1890
|
function formatMemoryDump(dump) {
|
|
1842
1891
|
const files = Object.entries(dump.entities).map(([entityId, bundle]) => ({
|
|
@@ -1863,6 +1912,101 @@ function formatMemoryDump(dump) {
|
|
|
1863
1912
|
files
|
|
1864
1913
|
};
|
|
1865
1914
|
}
|
|
1915
|
+
function factFrontmatter(f) {
|
|
1916
|
+
return {
|
|
1917
|
+
type: "fact",
|
|
1918
|
+
title: f.title,
|
|
1919
|
+
tags: f.tags,
|
|
1920
|
+
timestamp: new Date(f.updated_at).toISOString(),
|
|
1921
|
+
resource: f.source_ref ?? void 0,
|
|
1922
|
+
id: f.id,
|
|
1923
|
+
entity_id: f.entity_id,
|
|
1924
|
+
confidence: f.confidence,
|
|
1925
|
+
source_type: f.source_type,
|
|
1926
|
+
source_hash: f.source_hash,
|
|
1927
|
+
created_at: f.created_at,
|
|
1928
|
+
access_count: f.access_count,
|
|
1929
|
+
last_accessed_at: f.last_accessed_at,
|
|
1930
|
+
deleted_at: f.deleted_at
|
|
1931
|
+
};
|
|
1932
|
+
}
|
|
1933
|
+
function taskFrontmatter(t) {
|
|
1934
|
+
return {
|
|
1935
|
+
type: "task",
|
|
1936
|
+
title: t.description,
|
|
1937
|
+
timestamp: new Date(t.updated_at).toISOString(),
|
|
1938
|
+
id: t.id,
|
|
1939
|
+
entity_id: t.entity_id,
|
|
1940
|
+
status: t.status,
|
|
1941
|
+
priority: t.priority,
|
|
1942
|
+
created_at: t.created_at,
|
|
1943
|
+
resolved_at: t.resolved_at,
|
|
1944
|
+
deleted_at: t.deleted_at
|
|
1945
|
+
};
|
|
1946
|
+
}
|
|
1947
|
+
function formatLogDate(timestampMs) {
|
|
1948
|
+
return new Date(timestampMs).toISOString().slice(0, 10);
|
|
1949
|
+
}
|
|
1950
|
+
function buildEventLogEntries(events, factIdToFilename) {
|
|
1951
|
+
return events.map((e) => {
|
|
1952
|
+
const factFilename = e.related_entry_id ? factIdToFilename.get(e.related_entry_id) : void 0;
|
|
1953
|
+
const summary = e.summary.replace(/\\/g, "\\\\").replace(/\[/g, "\\[").replace(/\]/g, "\\]").replace(/\r?\n/g, " ");
|
|
1954
|
+
const text = factFilename ? `(${e.event_type}) [${summary}](./facts/${factFilename}.md)` : `(${e.event_type}) ${summary}`;
|
|
1955
|
+
return { date: formatLogDate(e.created_at), text };
|
|
1956
|
+
});
|
|
1957
|
+
}
|
|
1958
|
+
function formatOkfBundle(dump) {
|
|
1959
|
+
const files = [];
|
|
1960
|
+
const rootEntries = [];
|
|
1961
|
+
for (const [entityId, bundle] of Object.entries(dump.entities)) {
|
|
1962
|
+
const dir = sanitizeForFilename(entityId);
|
|
1963
|
+
const factIdToFilename = new Map(
|
|
1964
|
+
bundle.facts.map((f) => [f.id, sanitizeConceptId(f.id)])
|
|
1965
|
+
);
|
|
1966
|
+
const factEntries = bundle.facts.map((f) => ({
|
|
1967
|
+
path: `facts/${factIdToFilename.get(f.id)}.md`,
|
|
1968
|
+
title: f.title
|
|
1969
|
+
}));
|
|
1970
|
+
for (const f of bundle.facts) {
|
|
1971
|
+
files.push({
|
|
1972
|
+
path: `entities/${dir}/facts/${factIdToFilename.get(f.id)}.md`,
|
|
1973
|
+
content: buildConceptDocument(factFrontmatter(f), f.body)
|
|
1974
|
+
});
|
|
1975
|
+
}
|
|
1976
|
+
const taskEntries = bundle.tasks.map((t) => ({
|
|
1977
|
+
path: `tasks/${sanitizeConceptId(t.id)}.md`,
|
|
1978
|
+
title: t.description
|
|
1979
|
+
}));
|
|
1980
|
+
for (const t of bundle.tasks) {
|
|
1981
|
+
files.push({
|
|
1982
|
+
path: `entities/${dir}/tasks/${sanitizeConceptId(t.id)}.md`,
|
|
1983
|
+
content: buildConceptDocument(taskFrontmatter(t), "")
|
|
1984
|
+
});
|
|
1985
|
+
}
|
|
1986
|
+
files.push({
|
|
1987
|
+
path: `entities/${dir}/log.md`,
|
|
1988
|
+
content: buildLogMd(buildEventLogEntries(bundle.events, factIdToFilename))
|
|
1989
|
+
});
|
|
1990
|
+
const entityIndexSections = [
|
|
1991
|
+
{ heading: "Facts", entries: factEntries },
|
|
1992
|
+
{ heading: "Tasks", entries: taskEntries }
|
|
1993
|
+
];
|
|
1994
|
+
files.push({
|
|
1995
|
+
path: `entities/${dir}/index.md`,
|
|
1996
|
+
content: `${buildIndexMd(entityIndexSections)}[Event log](./log.md)
|
|
1997
|
+
`
|
|
1998
|
+
});
|
|
1999
|
+
rootEntries.push({ path: `entities/${dir}/index.md`, title: entityId });
|
|
2000
|
+
}
|
|
2001
|
+
files.push({
|
|
2002
|
+
path: "index.md",
|
|
2003
|
+
content: buildRootIndexMd(
|
|
2004
|
+
"0.1",
|
|
2005
|
+
rootEntries.length > 0 ? [{ heading: "Entities", entries: rootEntries }] : []
|
|
2006
|
+
)
|
|
2007
|
+
});
|
|
2008
|
+
return { files };
|
|
2009
|
+
}
|
|
1866
2010
|
|
|
1867
2011
|
// src/librarianPrompt.ts
|
|
1868
2012
|
var DEFAULT_LIBRARIAN_SYNTHESIS_PROMPT = `You are a careful memory synthesis assistant.
|
|
@@ -1908,6 +2052,6 @@ function createWiki(db, options) {
|
|
|
1908
2052
|
return new WikiMemory(db, options);
|
|
1909
2053
|
}
|
|
1910
2054
|
|
|
1911
|
-
export { DEFAULT_LIBRARIAN_SYNTHESIS_PROMPT, WikiMemory, createWiki, formatContext, formatMemoryDump, hydrateLibrarianPrompt, mapLibrarianOptionsToReadOptions, validateLibrarianPromptTemplate };
|
|
2055
|
+
export { DEFAULT_LIBRARIAN_SYNTHESIS_PROMPT, WikiMemory, createWiki, formatContext, formatMemoryDump, formatOkfBundle, hydrateLibrarianPrompt, mapLibrarianOptionsToReadOptions, validateLibrarianPromptTemplate };
|
|
1912
2056
|
//# sourceMappingURL=index.mjs.map
|
|
1913
2057
|
//# sourceMappingURL=index.mjs.map
|