@equationalapplications/core-llm-wiki 9.7.0 → 9.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/{chunk-6UTHJFXH.mjs → chunk-EN37KODZ.mjs} +258 -32
- package/dist/chunk-EN37KODZ.mjs.map +1 -0
- package/dist/index.d.mts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +336 -48
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +83 -21
- package/dist/index.mjs.map +1 -1
- package/dist/{testing-T0GgG1L6.d.mts → testing-CDSfjx8j.d.mts} +46 -9
- package/dist/{testing-T0GgG1L6.d.ts → testing-CDSfjx8j.d.ts} +46 -9
- package/dist/testing.d.mts +1 -1
- package/dist/testing.d.ts +1 -1
- package/dist/testing.js +222 -15
- package/dist/testing.js.map +1 -1
- package/dist/testing.mjs +1 -1
- package/package.json +2 -2
- package/dist/chunk-6UTHJFXH.mjs.map +0 -1
package/dist/testing.js
CHANGED
|
@@ -758,7 +758,11 @@ var SEVERITY = {
|
|
|
758
758
|
source_store_budget_exceeded: "warn",
|
|
759
759
|
source_store_hash_mismatch: "warn",
|
|
760
760
|
source_store_duplicate_hash: "warn",
|
|
761
|
-
source_store_text_not_storable: "warn"
|
|
761
|
+
source_store_text_not_storable: "warn",
|
|
762
|
+
node_type_dropped: "warn",
|
|
763
|
+
node_type_folded: "info",
|
|
764
|
+
ontology_update_rejected: "warn",
|
|
765
|
+
ingest_zero_facts: "warn"
|
|
762
766
|
};
|
|
763
767
|
var MESSAGE = {
|
|
764
768
|
ingest_chunk_failed: "One or more document chunks failed to parse or generate.",
|
|
@@ -807,8 +811,48 @@ var MESSAGE = {
|
|
|
807
811
|
source_store_budget_exceeded: "Storing a source document would exceed the store UTF-16 code-unit budget and it was not stored.",
|
|
808
812
|
source_store_hash_mismatch: "A source document text did not match its recorded hash and was not stored.",
|
|
809
813
|
source_store_duplicate_hash: "A source document duplicated the hash of one already stored and was not stored.",
|
|
810
|
-
source_store_text_not_storable: "A source document text could not be stored as given."
|
|
814
|
+
source_store_text_not_storable: "A source document text could not be stored as given.",
|
|
815
|
+
node_type_dropped: "A supplied node type missed the ontology manifest and the fact was stored untyped.",
|
|
816
|
+
node_type_folded: "A supplied node type was normalized into the manifest canonical slug.",
|
|
817
|
+
ontology_update_rejected: "An emergent ontology proposal was rejected during the merge.",
|
|
818
|
+
ingest_zero_facts: "A re-ingest tombstoned prior facts and edges and then wrote zero facts."
|
|
811
819
|
};
|
|
820
|
+
function shouldEmitOntologyReceipt(mode) {
|
|
821
|
+
return mode !== "off";
|
|
822
|
+
}
|
|
823
|
+
function capReceiptSlug(slug) {
|
|
824
|
+
return typeof slug === "string" ? slug.slice(0, 64) : "";
|
|
825
|
+
}
|
|
826
|
+
function nodeTypeReceipts(base, factId, rawType, okfType, match) {
|
|
827
|
+
const out = [];
|
|
828
|
+
const supplied = typeof rawType === "string" ? rawType.trim() : "";
|
|
829
|
+
if (match && match.via === "normalize") {
|
|
830
|
+
const to = capReceiptSlug(match.canonical);
|
|
831
|
+
out.push({
|
|
832
|
+
...base,
|
|
833
|
+
code: "node_type_folded",
|
|
834
|
+
detail: {
|
|
835
|
+
factId,
|
|
836
|
+
nodeType: to,
|
|
837
|
+
from: capReceiptSlug(match.raw),
|
|
838
|
+
to,
|
|
839
|
+
via: "normalize"
|
|
840
|
+
}
|
|
841
|
+
});
|
|
842
|
+
}
|
|
843
|
+
if (!okfType && supplied) {
|
|
844
|
+
out.push({
|
|
845
|
+
...base,
|
|
846
|
+
code: "node_type_dropped",
|
|
847
|
+
detail: {
|
|
848
|
+
factId,
|
|
849
|
+
nodeType: capReceiptSlug(supplied),
|
|
850
|
+
reason: "not_in_manifest"
|
|
851
|
+
}
|
|
852
|
+
});
|
|
853
|
+
}
|
|
854
|
+
return out;
|
|
855
|
+
}
|
|
812
856
|
var warnedNonFunction = /* @__PURE__ */ new WeakSet();
|
|
813
857
|
function copyDetail(detail) {
|
|
814
858
|
const copy = { ...detail };
|
|
@@ -1270,10 +1314,27 @@ var BaseRepository = class {
|
|
|
1270
1314
|
function normalizeTitleKey(title) {
|
|
1271
1315
|
return title.trim().toLowerCase().replace(/\s+/g, " ");
|
|
1272
1316
|
}
|
|
1317
|
+
function normalizeSlug(raw) {
|
|
1318
|
+
return raw.trim().toLowerCase().replace(/[_\-\s]+/g, "");
|
|
1319
|
+
}
|
|
1273
1320
|
var ONTOLOGY_ABSTAIN_SENTINEL = "none_of_these";
|
|
1274
1321
|
function isReservedAbstainSlug(raw) {
|
|
1275
1322
|
return typeof raw === "string" && raw.trim().toLowerCase() === ONTOLOGY_ABSTAIN_SENTINEL;
|
|
1276
1323
|
}
|
|
1324
|
+
function resolveEdgeDefinitions(rawEdgeType, manifest) {
|
|
1325
|
+
const slug = typeof rawEdgeType === "string" ? rawEdgeType.trim() : "";
|
|
1326
|
+
if (!slug) return [];
|
|
1327
|
+
const lowered = slug.toLowerCase();
|
|
1328
|
+
const exact = manifest.edge_types.filter((e) => e.type.toLowerCase() === lowered);
|
|
1329
|
+
if (exact.length > 0) return exact;
|
|
1330
|
+
const normalized = normalizeSlug(slug);
|
|
1331
|
+
if (!normalized) return [];
|
|
1332
|
+
const names = new Set(
|
|
1333
|
+
manifest.edge_types.filter((e) => normalizeSlug(e.type) === normalized).map((e) => e.type.toLowerCase())
|
|
1334
|
+
);
|
|
1335
|
+
if (names.size !== 1) return [];
|
|
1336
|
+
return manifest.edge_types.filter((e) => e.type.toLowerCase() === [...names][0]);
|
|
1337
|
+
}
|
|
1277
1338
|
function typeSatisfies(declaredType, concreteType, manifest) {
|
|
1278
1339
|
const concrete = concreteType.trim().toLowerCase();
|
|
1279
1340
|
const declared = declaredType.trim().toLowerCase();
|
|
@@ -2414,7 +2475,8 @@ Return ONLY a valid JSON object matching this schema:
|
|
|
2414
2475
|
{
|
|
2415
2476
|
"facts": [{ "title": "string (max 80 chars)", "body": "string (max 800 chars)", "tags": ["string"], "confidence": "certain|inferred|tentative" }]
|
|
2416
2477
|
}
|
|
2417
|
-
Extract verbatim factual content. JSON escaping rules: every literal " character in the source must be escaped as \\" inside any JSON string body, and every literal newline as \\n. Source prose containing quotes (e.g. a worked example with "...") must still be reproduced exactly \u2014 re-escape, do not omit. Do not return markdown, just raw JSON
|
|
2478
|
+
Extract verbatim factual content. JSON escaping rules: every literal " character in the source must be escaped as \\" inside any JSON string body, and every literal newline as \\n. Source prose containing quotes (e.g. a worked example with "...") must still be reproduced exactly \u2014 re-escape, do not omit. Do not return markdown, just raw JSON.
|
|
2479
|
+
When the ontology manifest is present in your instructions, supply okf_type for each fact: use a manifest slug exactly as spelled (spelling variants like underscores, hyphens, or spaces are folded to the manifest form), or omit okf_type when no manifest type fits.`;
|
|
2418
2480
|
var ONTOLOGY_BACKFILL_SYSTEM_PROMPT = `You are a knowledge classification agent. You will receive existing memory facts that currently have no ontology type. For each input fact { "id", "title", "body", "tags" }, assign the best matching okf_type from the ontology manifest and optionally propose edges to related facts by title.
|
|
2419
2481
|
Return ONLY a valid JSON object matching this schema:
|
|
2420
2482
|
{
|
|
@@ -2422,7 +2484,7 @@ Return ONLY a valid JSON object matching this schema:
|
|
|
2422
2484
|
{ "id": "string (input fact id, copied verbatim)", "okf_type": "string (manifest node type slug)", "edges": [{ "edge_type": "string", "target_title": "string" }] }
|
|
2423
2485
|
]
|
|
2424
2486
|
}
|
|
2425
|
-
If no manifest type fits a fact, omit that fact from "classifications"
|
|
2487
|
+
If no manifest type fits a fact, assign the closest type the fact is an example of; omit that fact from "classifications" only when no type applies even broadly. Use the manifest slug EXACTLY as spelled (spelling variants are folded to the manifest form).
|
|
2426
2488
|
When echoing an existing fact's title verbatim into "target_title", preserve every JSON escape sequence (\\", \\n, \\\\, \\/) exactly as it appeared in the input body \u2014 do not strip backslashes, do not add unescaped quotes. Do not return markdown, just raw JSON.`;
|
|
2427
2489
|
var TITLE_CATALOG_MAX_ENTRIES = 200;
|
|
2428
2490
|
function buildTitleCatalogBlock(rows) {
|
|
@@ -3296,6 +3358,15 @@ var IngestionService = class {
|
|
|
3296
3358
|
});
|
|
3297
3359
|
deletedSourceFactIds.push(...fullResult.deletedSourceFactIds);
|
|
3298
3360
|
insertedFacts.push(...fullResult.insertedFacts);
|
|
3361
|
+
if (ontologyContext !== null && insertedFacts.length === 0 && deletedSourceFactIds.length > 0) {
|
|
3362
|
+
diagBuffer.push({
|
|
3363
|
+
entityId,
|
|
3364
|
+
operation: "ingest",
|
|
3365
|
+
trigger: "call",
|
|
3366
|
+
code: "ingest_zero_facts",
|
|
3367
|
+
detail: { sourceRef, chunks: chunks2.length }
|
|
3368
|
+
});
|
|
3369
|
+
}
|
|
3299
3370
|
} else {
|
|
3300
3371
|
const partialResult = await this.db.withTransactionAsync(async (tx) => {
|
|
3301
3372
|
const flat = [];
|
|
@@ -3433,6 +3504,20 @@ var IngestionService = class {
|
|
|
3433
3504
|
strict: strictEffective,
|
|
3434
3505
|
entityId
|
|
3435
3506
|
}) ?? { okf_type: null};
|
|
3507
|
+
if (shouldEmitOntologyReceipt(mode)) {
|
|
3508
|
+
for (const receipt of nodeTypeReceipts(
|
|
3509
|
+
{ entityId, operation: opts?.diag?.operation ?? "upsertGraph", trigger: "call" },
|
|
3510
|
+
node.id,
|
|
3511
|
+
node.type ?? "",
|
|
3512
|
+
normalized.okf_type,
|
|
3513
|
+
normalized.match
|
|
3514
|
+
)) {
|
|
3515
|
+
opts?.diag?.buffer.push({
|
|
3516
|
+
...receipt,
|
|
3517
|
+
detail: { ...receipt.detail, sourceRef: params.sourceRef }
|
|
3518
|
+
});
|
|
3519
|
+
}
|
|
3520
|
+
}
|
|
3436
3521
|
const wikiFact = {
|
|
3437
3522
|
id: node.id,
|
|
3438
3523
|
entity_id: entityId,
|
|
@@ -3487,8 +3572,8 @@ var IngestionService = class {
|
|
|
3487
3572
|
continue;
|
|
3488
3573
|
}
|
|
3489
3574
|
const sourceType = sourceIdToType.get(edge.sourceId);
|
|
3490
|
-
const candidates = (
|
|
3491
|
-
(d) =>
|
|
3575
|
+
const candidates = resolveEdgeDefinitions(edge.type, manifest).filter(
|
|
3576
|
+
(d) => typeSatisfies(d.source_type, sourceType ?? "", manifest)
|
|
3492
3577
|
);
|
|
3493
3578
|
const match = candidates[0];
|
|
3494
3579
|
if (!match) {
|
|
@@ -3567,9 +3652,18 @@ var IngestionService = class {
|
|
|
3567
3652
|
const now = Date.now();
|
|
3568
3653
|
for (const { facts, ontology_updates } of orderedChunkFacts) {
|
|
3569
3654
|
if (mode === "emergent" && ontology_updates && this.ontologyService) {
|
|
3570
|
-
manifest = await this.ontologyService.mergeEmergentUpdates(entityId, ontology_updates, tx);
|
|
3655
|
+
const { manifest: merged, rejected } = await this.ontologyService.mergeEmergentUpdates(entityId, ontology_updates, tx);
|
|
3656
|
+
manifest = merged;
|
|
3657
|
+
for (const reason of rejected) {
|
|
3658
|
+
diagBuffer.push({ entityId, operation: "ingest", trigger: "call", code: "ontology_update_rejected", detail: { reason } });
|
|
3659
|
+
}
|
|
3571
3660
|
ontologyState = await this.ontologyService.getEffectiveState(entityId, tx);
|
|
3572
3661
|
mode = ontologyState.mode;
|
|
3662
|
+
} else if (mode === "strict" && ontology_updates) {
|
|
3663
|
+
const proposalCount = (Array.isArray(ontology_updates.node_types) ? ontology_updates.node_types.length : 0) + (Array.isArray(ontology_updates.edge_types) ? ontology_updates.edge_types.length : 0);
|
|
3664
|
+
for (let i = 0; i < proposalCount; i++) {
|
|
3665
|
+
diagBuffer.push({ entityId, operation: "ingest", trigger: "call", code: "ontology_update_rejected", detail: { reason: "mode_strict" } });
|
|
3666
|
+
}
|
|
3573
3667
|
}
|
|
3574
3668
|
for (const fact of facts) {
|
|
3575
3669
|
const ontologyFact = fact;
|
|
@@ -3667,6 +3761,14 @@ var IngestionService = class {
|
|
|
3667
3761
|
const liveIds = await this.entryRepo.findIdsBySource(entityId, sourceRef, null, tx, false);
|
|
3668
3762
|
const liveFacts = liveIds.length === 0 ? [] : await this.entryRepo.findByIds(liveIds, void 0, tx);
|
|
3669
3763
|
const liveTitles = new Set(liveFacts.map((f) => normalizeTitleKey(f.title)));
|
|
3764
|
+
const ontologyState = await this.ontologyService?.getEffectiveState(entityId, tx) ?? { mode: "off", manifest: { node_types: [], edge_types: [] } };
|
|
3765
|
+
const { mode, manifest } = ontologyState;
|
|
3766
|
+
const titleIndex = /* @__PURE__ */ new Map();
|
|
3767
|
+
const indexedFacts = await this.entryRepo.findRecentByEntityId(entityId, 500, tx);
|
|
3768
|
+
for (const f of indexedFacts) {
|
|
3769
|
+
titleIndex.set(normalizeTitleKey(f.title), { id: f.id, okf_type: f.okf_type ?? null });
|
|
3770
|
+
}
|
|
3771
|
+
const pendingEdges = [];
|
|
3670
3772
|
let inserted = 0;
|
|
3671
3773
|
let skippedDuplicate = 0;
|
|
3672
3774
|
const now = Date.now();
|
|
@@ -3691,6 +3793,26 @@ var IngestionService = class {
|
|
|
3691
3793
|
detail: { factId: id, sourceRef, chunkIndex: locator.chunkIndex, itemIndex: locator.itemIndex, reason: outcome.diagnostic.reason }
|
|
3692
3794
|
});
|
|
3693
3795
|
}
|
|
3796
|
+
const ontologyFact = fact;
|
|
3797
|
+
const validationDrops = [];
|
|
3798
|
+
const normalized = this.ontologyService?.validateAndNormalizeFact(ontologyFact, manifest, { strict: false, drops: validationDrops }) ?? { okf_type: null, edges: [] };
|
|
3799
|
+
for (const drop of validationDrops) {
|
|
3800
|
+
diagBuffer.push(edgeDropDiagnostic(drop, { entityId, operation: "ingest", trigger: "call", sourceRef, factId: id }));
|
|
3801
|
+
}
|
|
3802
|
+
if (shouldEmitOntologyReceipt(mode)) {
|
|
3803
|
+
for (const receipt of nodeTypeReceipts(
|
|
3804
|
+
{ entityId, operation: "ingest", trigger: "call" },
|
|
3805
|
+
id,
|
|
3806
|
+
ontologyFact.okf_type ?? "",
|
|
3807
|
+
normalized.okf_type,
|
|
3808
|
+
normalized.match
|
|
3809
|
+
)) {
|
|
3810
|
+
diagBuffer.push({ ...receipt, detail: { ...receipt.detail, sourceRef } });
|
|
3811
|
+
}
|
|
3812
|
+
}
|
|
3813
|
+
if (normalized.edges.length > 0) {
|
|
3814
|
+
pendingEdges.push({ sourceId: id, sourceType: normalized.okf_type, edges: normalized.edges });
|
|
3815
|
+
}
|
|
3694
3816
|
const wikiFact = {
|
|
3695
3817
|
id,
|
|
3696
3818
|
entity_id: entityId,
|
|
@@ -3709,10 +3831,11 @@ var IngestionService = class {
|
|
|
3709
3831
|
last_accessed_at: null,
|
|
3710
3832
|
access_count: 0,
|
|
3711
3833
|
deleted_at: null,
|
|
3712
|
-
okf_type:
|
|
3834
|
+
okf_type: normalized.okf_type,
|
|
3713
3835
|
...outcome?.trust
|
|
3714
3836
|
};
|
|
3715
3837
|
await this.entryRepo.upsert(wikiFact, tx);
|
|
3838
|
+
titleIndex.set(normalizeTitleKey(fact.title), { id, okf_type: normalized.okf_type });
|
|
3716
3839
|
insertedDescriptors.push({
|
|
3717
3840
|
id,
|
|
3718
3841
|
entity_id: entityId,
|
|
@@ -3722,6 +3845,27 @@ var IngestionService = class {
|
|
|
3722
3845
|
});
|
|
3723
3846
|
inserted++;
|
|
3724
3847
|
}
|
|
3848
|
+
if (pendingEdges.length > 0) {
|
|
3849
|
+
for (const req of pendingEdges) {
|
|
3850
|
+
const resolveDrops = [];
|
|
3851
|
+
const resolved = this.ontologyService?.resolveEdges(
|
|
3852
|
+
entityId,
|
|
3853
|
+
req.sourceId,
|
|
3854
|
+
req.sourceType,
|
|
3855
|
+
req.edges,
|
|
3856
|
+
manifest,
|
|
3857
|
+
titleIndex,
|
|
3858
|
+
now,
|
|
3859
|
+
resolveDrops
|
|
3860
|
+
) ?? [];
|
|
3861
|
+
for (const drop of resolveDrops) {
|
|
3862
|
+
diagBuffer.push(edgeDropDiagnostic(drop, { entityId, operation: "ingest", trigger: "call", sourceRef }));
|
|
3863
|
+
}
|
|
3864
|
+
for (const edge of resolved) {
|
|
3865
|
+
await this.edgeRepo.addIgnoreDuplicate(edge, tx);
|
|
3866
|
+
}
|
|
3867
|
+
}
|
|
3868
|
+
}
|
|
3725
3869
|
return { inserted, skippedDuplicate, insertedDescriptors };
|
|
3726
3870
|
}
|
|
3727
3871
|
};
|
|
@@ -4870,7 +5014,16 @@ var runLegacyLibrarianPass = async (deps, ctx) => {
|
|
|
4870
5014
|
await deps.db.withTransactionAsync(async (tx) => {
|
|
4871
5015
|
let { mode, manifest } = await deps.ontologyService?.getEffectiveState(entityId, tx) ?? { mode: "off", manifest: { node_types: [], edge_types: [] } };
|
|
4872
5016
|
if (mode === "emergent" && ontologyUpdates && deps.ontologyService) {
|
|
4873
|
-
manifest = await deps.ontologyService.mergeEmergentUpdates(entityId, ontologyUpdates, tx);
|
|
5017
|
+
const { manifest: merged, rejected } = await deps.ontologyService.mergeEmergentUpdates(entityId, ontologyUpdates, tx);
|
|
5018
|
+
manifest = merged;
|
|
5019
|
+
for (const reason of rejected) {
|
|
5020
|
+
diagBuffer.push({ ...diagBase, code: "ontology_update_rejected", detail: { reason } });
|
|
5021
|
+
}
|
|
5022
|
+
} else if (mode === "strict" && ontologyUpdates) {
|
|
5023
|
+
const proposalCount = (Array.isArray(ontologyUpdates.node_types) ? ontologyUpdates.node_types.length : 0) + (Array.isArray(ontologyUpdates.edge_types) ? ontologyUpdates.edge_types.length : 0);
|
|
5024
|
+
for (let i = 0; i < proposalCount; i++) {
|
|
5025
|
+
diagBuffer.push({ ...diagBase, code: "ontology_update_rejected", detail: { reason: "mode_strict" } });
|
|
5026
|
+
}
|
|
4874
5027
|
}
|
|
4875
5028
|
const titleIndex = /* @__PURE__ */ new Map();
|
|
4876
5029
|
for (const existing of currentFactsRows) {
|
|
@@ -4905,6 +5058,17 @@ var runLegacyLibrarianPass = async (deps, ctx) => {
|
|
|
4905
5058
|
const validationDrops = [];
|
|
4906
5059
|
const normalized = deps.ontologyService?.validateAndNormalizeFact(ontologyFact, manifest, { strict: false, drops: validationDrops }) ?? { okf_type: null, edges: [] };
|
|
4907
5060
|
for (const drop of validationDrops) diagBuffer.push(edgeDropDiagnostic(drop, { ...diagBase, factId: id }));
|
|
5061
|
+
if (shouldEmitOntologyReceipt(mode)) {
|
|
5062
|
+
for (const receipt of nodeTypeReceipts(
|
|
5063
|
+
{ entityId, operation: "librarian", trigger },
|
|
5064
|
+
id,
|
|
5065
|
+
ontologyFact.okf_type ?? "",
|
|
5066
|
+
normalized.okf_type,
|
|
5067
|
+
normalized.match
|
|
5068
|
+
)) {
|
|
5069
|
+
diagBuffer.push(receipt);
|
|
5070
|
+
}
|
|
5071
|
+
}
|
|
4908
5072
|
const grounding = librarianGrounding ? groundingOutcome(checkGrounding(fact.evidence, librarianCorpus, librarianGrounding), now) : null;
|
|
4909
5073
|
if (grounding?.diagnostic) {
|
|
4910
5074
|
diagBuffer.push({ ...diagBase, code: grounding.diagnostic.code, detail: { factId: id, itemIndex: validFactItemIndexes[k], reason: grounding.diagnostic.reason } });
|
|
@@ -5451,7 +5615,16 @@ async function applyOps(deps, ctx, input) {
|
|
|
5451
5615
|
await deps.db.withTransactionAsync(async (tx) => {
|
|
5452
5616
|
let { mode, manifest } = await deps.ontologyService?.getEffectiveState(entityId, tx) ?? { mode: "off", manifest: { node_types: [], edge_types: [] } };
|
|
5453
5617
|
if (mode === "emergent" && input.ontologyUpdates && deps.ontologyService) {
|
|
5454
|
-
manifest = await deps.ontologyService.mergeEmergentUpdates(entityId, input.ontologyUpdates, tx);
|
|
5618
|
+
const { manifest: merged, rejected: rejected2 } = await deps.ontologyService.mergeEmergentUpdates(entityId, input.ontologyUpdates, tx);
|
|
5619
|
+
manifest = merged;
|
|
5620
|
+
for (const reason of rejected2) {
|
|
5621
|
+
input.diagnostics.push({ ...diagBase, code: "ontology_update_rejected", detail: { reason } });
|
|
5622
|
+
}
|
|
5623
|
+
} else if (mode === "strict" && input.ontologyUpdates) {
|
|
5624
|
+
const proposalCount = (Array.isArray(input.ontologyUpdates.node_types) ? input.ontologyUpdates.node_types.length : 0) + (Array.isArray(input.ontologyUpdates.edge_types) ? input.ontologyUpdates.edge_types.length : 0);
|
|
5625
|
+
for (let i = 0; i < proposalCount; i++) {
|
|
5626
|
+
input.diagnostics.push({ ...diagBase, code: "ontology_update_rejected", detail: { reason: "mode_strict" } });
|
|
5627
|
+
}
|
|
5455
5628
|
}
|
|
5456
5629
|
const titleIndex = /* @__PURE__ */ new Map();
|
|
5457
5630
|
for (const f of await deps.entryRepo.findRecentByEntityId(entityId, 100, tx)) {
|
|
@@ -5465,6 +5638,17 @@ async function applyOps(deps, ctx, input) {
|
|
|
5465
5638
|
const id = generateId("fact_");
|
|
5466
5639
|
const drops = [];
|
|
5467
5640
|
const normalized = deps.ontologyService?.validateAndNormalizeFact(fact, manifest, { strict: false, drops }) ?? { okf_type: null, edges: [] };
|
|
5641
|
+
if (shouldEmitOntologyReceipt(mode)) {
|
|
5642
|
+
for (const receipt of nodeTypeReceipts(
|
|
5643
|
+
{ entityId, operation: "librarian", trigger },
|
|
5644
|
+
id,
|
|
5645
|
+
typeof fact.okf_type === "string" ? fact.okf_type : "",
|
|
5646
|
+
normalized.okf_type,
|
|
5647
|
+
normalized.match
|
|
5648
|
+
)) {
|
|
5649
|
+
input.diagnostics.push(receipt);
|
|
5650
|
+
}
|
|
5651
|
+
}
|
|
5468
5652
|
for (const d of drops) input.diagnostics.push(edgeDropDiagnostic(d, { ...diagBase, factId: id }));
|
|
5469
5653
|
const gVerdict = grounding ? checkGrounding(fact.evidence, input.groundingCorpus ?? [], grounding) : null;
|
|
5470
5654
|
const g2 = gVerdict ? groundingOutcome(gVerdict, now) : null;
|
|
@@ -7173,12 +7357,15 @@ DROP TRIGGER IF EXISTS ${ad};`);
|
|
|
7173
7357
|
if (!Number.isInteger(batchSize) || batchSize < 1) {
|
|
7174
7358
|
throw new Error("Invalid batchSize: must be an integer >= 1");
|
|
7175
7359
|
}
|
|
7360
|
+
if (options?.recheckCheckedBefore !== void 0 && (!Number.isInteger(options.recheckCheckedBefore) || options.recheckCheckedBefore < 0)) {
|
|
7361
|
+
throw new Error("Invalid recheckCheckedBefore: must be an integer >= 0");
|
|
7362
|
+
}
|
|
7176
7363
|
if (options?.classifier !== void 0 && options.classifier !== "auto" && options.classifier !== "llm") {
|
|
7177
7364
|
throw new TypeError(`Invalid classifier option: ${JSON.stringify(options.classifier)} \u2014 must be 'auto' or 'llm'`);
|
|
7178
7365
|
}
|
|
7179
7366
|
const trigger = options?.trigger ?? "call";
|
|
7180
7367
|
const now = Date.now();
|
|
7181
|
-
const recheckCutoff = now - ONTOLOGY_BACKFILL_RECHECK_MS;
|
|
7368
|
+
const recheckCutoff = options?.recheckCheckedBefore ?? now - ONTOLOGY_BACKFILL_RECHECK_MS;
|
|
7182
7369
|
const zeroed = { scanned: 0, typed: 0, failedValidation: 0, edgesAdded: 0, skipped: 0, abstained: 0 };
|
|
7183
7370
|
const ontologyService = this.ontologyService;
|
|
7184
7371
|
if (!ontologyService) {
|
|
@@ -7222,7 +7409,8 @@ DROP TRIGGER IF EXISTS ${ad};`);
|
|
|
7222
7409
|
promptOverride: options?.promptOverride,
|
|
7223
7410
|
meter: options?.meter,
|
|
7224
7411
|
trigger,
|
|
7225
|
-
batchSize: escalated.length
|
|
7412
|
+
batchSize: escalated.length,
|
|
7413
|
+
recheckCutoff
|
|
7226
7414
|
});
|
|
7227
7415
|
return {
|
|
7228
7416
|
scanned: classifierRun.result.scanned,
|
|
@@ -7242,7 +7430,8 @@ DROP TRIGGER IF EXISTS ${ad};`);
|
|
|
7242
7430
|
return this._runGenerativeBackfill(entityId, candidates, {
|
|
7243
7431
|
promptOverride: options?.promptOverride,
|
|
7244
7432
|
meter: options?.meter,
|
|
7245
|
-
trigger
|
|
7433
|
+
trigger,
|
|
7434
|
+
recheckCutoff
|
|
7246
7435
|
});
|
|
7247
7436
|
}
|
|
7248
7437
|
/**
|
|
@@ -7272,7 +7461,7 @@ DROP TRIGGER IF EXISTS ${ad};`);
|
|
|
7272
7461
|
runOpts.batchSize ?? ONTOLOGY_BACKFILL_BATCH_SIZE;
|
|
7273
7462
|
const ontologyService = this.ontologyService;
|
|
7274
7463
|
const now = Date.now();
|
|
7275
|
-
const recheckCutoff =
|
|
7464
|
+
const recheckCutoff = runOpts.recheckCutoff;
|
|
7276
7465
|
const ontologyContext = await ontologyService.buildPromptContext(entityId);
|
|
7277
7466
|
const titleRows = await this.entryRepo.findTitleIndexByEntityId(entityId);
|
|
7278
7467
|
const titleCatalog = buildTitleCatalogBlock(titleRows);
|
|
@@ -7524,7 +7713,16 @@ DROP TRIGGER IF EXISTS ${ad};`);
|
|
|
7524
7713
|
return;
|
|
7525
7714
|
}
|
|
7526
7715
|
if (txMode === "emergent" && ontologyUpdates) {
|
|
7527
|
-
manifest = await ontologyService.mergeEmergentUpdates(entityId, ontologyUpdates, tx);
|
|
7716
|
+
const { manifest: merged, rejected } = await ontologyService.mergeEmergentUpdates(entityId, ontologyUpdates, tx);
|
|
7717
|
+
manifest = merged;
|
|
7718
|
+
for (const reason of rejected) {
|
|
7719
|
+
diagBuffer.push({ ...diagBase, code: "ontology_update_rejected", detail: { reason } });
|
|
7720
|
+
}
|
|
7721
|
+
} else if (txMode === "strict" && ontologyUpdates) {
|
|
7722
|
+
const proposalCount = (Array.isArray(ontologyUpdates.node_types) ? ontologyUpdates.node_types.length : 0) + (Array.isArray(ontologyUpdates.edge_types) ? ontologyUpdates.edge_types.length : 0);
|
|
7723
|
+
for (let i = 0; i < proposalCount; i++) {
|
|
7724
|
+
diagBuffer.push({ ...diagBase, code: "ontology_update_rejected", detail: { reason: "mode_strict" } });
|
|
7725
|
+
}
|
|
7528
7726
|
}
|
|
7529
7727
|
const titleRows = await this.entryRepo.findTitleIndexByEntityId(entityId, tx);
|
|
7530
7728
|
const titleIndex = /* @__PURE__ */ new Map();
|
|
@@ -7558,6 +7756,15 @@ DROP TRIGGER IF EXISTS ${ad};`);
|
|
|
7558
7756
|
for (const drop of validationDrops) {
|
|
7559
7757
|
diagBuffer.push(edgeDropDiagnostic(drop, { ...diagBase, factId: fact.id }));
|
|
7560
7758
|
}
|
|
7759
|
+
for (const receipt of nodeTypeReceipts(
|
|
7760
|
+
{ entityId, operation: "ontologyBackfill", trigger: "call" },
|
|
7761
|
+
fact.id,
|
|
7762
|
+
typeof classification.okf_type === "string" ? classification.okf_type : "",
|
|
7763
|
+
normalized.okf_type,
|
|
7764
|
+
normalized.match
|
|
7765
|
+
)) {
|
|
7766
|
+
diagBuffer.push(receipt);
|
|
7767
|
+
}
|
|
7561
7768
|
if (!normalized.okf_type) {
|
|
7562
7769
|
failedValidation++;
|
|
7563
7770
|
continue;
|