@equationalapplications/core-llm-wiki 6.0.1 → 6.2.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 CHANGED
@@ -1,5 +1,5 @@
1
- import { M as MemoryBundle, F as FormatContextOptions, G as GraphNeighborhood, a as MemoryDump, b as FormattedMemoryDump, O as OntologyManifest, R as ReadOptions, S as SQLiteAdapter, W as WikiOptions, c as WikiMemory } from './testing-DgqVB29I.mjs';
2
- export { C as ChunkFailure, D as DegradedRecord, E as EntityStatus, d as ExtractedFact, e as ExtractedFactEdge, f as ExtractedFactWithOntology, g as ExtractedTask, h as GraphTraversalOptions, H as HEAL_BATCH_SIZE, i as HEAL_RECHECK_MS, j as HOOK_TIMEOUT_MARKER, k as HealResult, I as IngestDocumentResult, L as LLMProvider, l as ONTOLOGY_BACKFILL_BATCH_SIZE, m as ONTOLOGY_BACKFILL_MAX_PROMPT_CHARS, n as ONTOLOGY_BACKFILL_RECHECK_MS, o as OntologyBackfillResult, p as OntologyConfig, q as OntologyEdgeType, r as OntologyMode, s as OntologyNodeType, t as OntologyPromptContext, u as OntologyUpdates, P as PromptOverrides, v as PromptService, w as PrunePartialFailureError, V as VectorRanker, x as VectorRankerFallback, y as VectorRankerRankArgs, z as VectorRankerSemanticResult, A as WikiBusyError, B as WikiBusyOperation, J as WikiCheckpoint, K as WikiConfig, N as WikiDuplicateHashError, Q as WikiEdge, T as WikiEvent, U as WikiFact, X as WikiIngestEmptyError, Y as WikiMemoryTestAccess, Z as WikiOutboxEvent, _ as WikiParseError, $ as WikiSourceRefHashCollision, a0 as WikiStrictOntologyViolation, a1 as WikiTask, a2 as WikiTransactionError } from './testing-DgqVB29I.mjs';
1
+ import { M as MemoryBundle, F as FormatContextOptions, G as GraphNeighborhood, a as MemoryDump, b as FormattedMemoryDump, O as OntologyManifest, R as ReadOptions, S as SQLiteAdapter, W as WikiOptions, c as WikiMemory } from './testing-D0m2V9-E.mjs';
2
+ export { C as ChunkFailure, D as DegradedRecord, E as EntityStatus, d as ExtractedFact, e as ExtractedFactEdge, f as ExtractedFactWithOntology, g as ExtractedTask, h as GraphTraversalOptions, H as HEAL_BATCH_SIZE, i as HEAL_RECHECK_MS, j as HOOK_TIMEOUT_MARKER, k as HealResult, I as IngestDocumentResult, L as LLMProvider, l as ONTOLOGY_BACKFILL_BATCH_SIZE, m as ONTOLOGY_BACKFILL_MAX_PROMPT_CHARS, n as ONTOLOGY_BACKFILL_RECHECK_MS, o as OntologyBackfillResult, p as OntologyConfig, q as OntologyEdgeType, r as OntologyMode, s as OntologyNodeType, t as OntologyPromptContext, u as OntologyUpdates, P as PromptOverrides, v as PromptService, w as PrunePartialFailureError, V as VectorRanker, x as VectorRankerFallback, y as VectorRankerRankArgs, z as VectorRankerSemanticResult, A as WikiBusyError, B as WikiBusyOperation, J as WikiCheckpoint, K as WikiConfig, N as WikiDuplicateHashError, Q as WikiEdge, T as WikiEvent, U as WikiFact, X as WikiIngestEmptyError, Y as WikiMemoryTestAccess, Z as WikiOutboxEvent, _ as WikiParseError, $ as WikiSourceRefHashCollision, a0 as WikiStrictOntologyViolation, a1 as WikiTask, a2 as WikiTransactionError } from './testing-D0m2V9-E.mjs';
3
3
  import { OkfFile } from '@equationalapplications/core-okf';
4
4
  import 'minisearch';
5
5
 
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { M as MemoryBundle, F as FormatContextOptions, G as GraphNeighborhood, a as MemoryDump, b as FormattedMemoryDump, O as OntologyManifest, R as ReadOptions, S as SQLiteAdapter, W as WikiOptions, c as WikiMemory } from './testing-DgqVB29I.js';
2
- export { C as ChunkFailure, D as DegradedRecord, E as EntityStatus, d as ExtractedFact, e as ExtractedFactEdge, f as ExtractedFactWithOntology, g as ExtractedTask, h as GraphTraversalOptions, H as HEAL_BATCH_SIZE, i as HEAL_RECHECK_MS, j as HOOK_TIMEOUT_MARKER, k as HealResult, I as IngestDocumentResult, L as LLMProvider, l as ONTOLOGY_BACKFILL_BATCH_SIZE, m as ONTOLOGY_BACKFILL_MAX_PROMPT_CHARS, n as ONTOLOGY_BACKFILL_RECHECK_MS, o as OntologyBackfillResult, p as OntologyConfig, q as OntologyEdgeType, r as OntologyMode, s as OntologyNodeType, t as OntologyPromptContext, u as OntologyUpdates, P as PromptOverrides, v as PromptService, w as PrunePartialFailureError, V as VectorRanker, x as VectorRankerFallback, y as VectorRankerRankArgs, z as VectorRankerSemanticResult, A as WikiBusyError, B as WikiBusyOperation, J as WikiCheckpoint, K as WikiConfig, N as WikiDuplicateHashError, Q as WikiEdge, T as WikiEvent, U as WikiFact, X as WikiIngestEmptyError, Y as WikiMemoryTestAccess, Z as WikiOutboxEvent, _ as WikiParseError, $ as WikiSourceRefHashCollision, a0 as WikiStrictOntologyViolation, a1 as WikiTask, a2 as WikiTransactionError } from './testing-DgqVB29I.js';
1
+ import { M as MemoryBundle, F as FormatContextOptions, G as GraphNeighborhood, a as MemoryDump, b as FormattedMemoryDump, O as OntologyManifest, R as ReadOptions, S as SQLiteAdapter, W as WikiOptions, c as WikiMemory } from './testing-D0m2V9-E.js';
2
+ export { C as ChunkFailure, D as DegradedRecord, E as EntityStatus, d as ExtractedFact, e as ExtractedFactEdge, f as ExtractedFactWithOntology, g as ExtractedTask, h as GraphTraversalOptions, H as HEAL_BATCH_SIZE, i as HEAL_RECHECK_MS, j as HOOK_TIMEOUT_MARKER, k as HealResult, I as IngestDocumentResult, L as LLMProvider, l as ONTOLOGY_BACKFILL_BATCH_SIZE, m as ONTOLOGY_BACKFILL_MAX_PROMPT_CHARS, n as ONTOLOGY_BACKFILL_RECHECK_MS, o as OntologyBackfillResult, p as OntologyConfig, q as OntologyEdgeType, r as OntologyMode, s as OntologyNodeType, t as OntologyPromptContext, u as OntologyUpdates, P as PromptOverrides, v as PromptService, w as PrunePartialFailureError, V as VectorRanker, x as VectorRankerFallback, y as VectorRankerRankArgs, z as VectorRankerSemanticResult, A as WikiBusyError, B as WikiBusyOperation, J as WikiCheckpoint, K as WikiConfig, N as WikiDuplicateHashError, Q as WikiEdge, T as WikiEvent, U as WikiFact, X as WikiIngestEmptyError, Y as WikiMemoryTestAccess, Z as WikiOutboxEvent, _ as WikiParseError, $ as WikiSourceRefHashCollision, a0 as WikiStrictOntologyViolation, a1 as WikiTask, a2 as WikiTransactionError } from './testing-D0m2V9-E.js';
3
3
  import { OkfFile } from '@equationalapplications/core-okf';
4
4
  import 'minisearch';
5
5
 
package/dist/index.js CHANGED
@@ -2505,6 +2505,17 @@ function resolveEdgeDefinitions(rawEdgeType, manifest) {
2505
2505
  function edgeTripleKey(type, sourceType, targetType) {
2506
2506
  return `${type.trim().toLowerCase()}|${sourceType.trim().toLowerCase()}|${targetType.trim().toLowerCase()}`;
2507
2507
  }
2508
+ function typeSatisfies(declaredType, concreteType, manifest) {
2509
+ const concrete = concreteType.trim().toLowerCase();
2510
+ const declared = declaredType.trim().toLowerCase();
2511
+ if (!concrete || !declared) return false;
2512
+ if (declared === concrete) return true;
2513
+ const def = (manifest.node_types ?? []).find(
2514
+ (n) => typeof n?.type === "string" && n.type.trim().toLowerCase() === concrete
2515
+ );
2516
+ const parent = typeof def?.parent_type === "string" ? def.parent_type.trim().toLowerCase() : "";
2517
+ return parent !== "" && parent === declared;
2518
+ }
2508
2519
  function validateManifest(manifest) {
2509
2520
  const nodeSlugs = /* @__PURE__ */ new Set();
2510
2521
  for (const node of manifest.node_types ?? []) {
@@ -2514,6 +2525,28 @@ function validateManifest(manifest) {
2514
2525
  if (nodeSlugs.has(key)) throw new Error(`Duplicate node type: ${type}`);
2515
2526
  nodeSlugs.add(key);
2516
2527
  }
2528
+ const parentOf = /* @__PURE__ */ new Map();
2529
+ for (const node of manifest.node_types ?? []) {
2530
+ const parent = typeof node.parent_type === "string" ? node.parent_type.trim().toLowerCase() : void 0;
2531
+ parentOf.set(node.type.trim().toLowerCase(), parent);
2532
+ }
2533
+ for (const node of manifest.node_types ?? []) {
2534
+ if (node.parent_type === void 0) continue;
2535
+ if (typeof node.parent_type !== "string" || !node.parent_type.trim()) {
2536
+ throw new Error(`Ontology parent_type must be a non-empty string when present: ${node.type}`);
2537
+ }
2538
+ const parentSlug = node.parent_type.trim().toLowerCase();
2539
+ if (parentSlug === node.type.trim().toLowerCase()) {
2540
+ throw new Error(`Self-parent: ${node.type}`);
2541
+ }
2542
+ if (!nodeSlugs.has(parentSlug)) {
2543
+ throw new Error(`Parent type not found: ${node.parent_type}`);
2544
+ }
2545
+ const grandparent = parentOf.get(parentSlug);
2546
+ if (grandparent) {
2547
+ throw new Error(`Parent chain too deep: ${node.type} \u2192 ${node.parent_type} \u2192 ${grandparent}`);
2548
+ }
2549
+ }
2517
2550
  const edgeKeys = /* @__PURE__ */ new Set();
2518
2551
  const edgeNames = /* @__PURE__ */ new Map();
2519
2552
  for (const edge of manifest.edge_types ?? []) {
@@ -2537,18 +2570,38 @@ function validateManifest(manifest) {
2537
2570
  }
2538
2571
  }
2539
2572
  }
2573
+ function buildDeclaresParentIndex(nodes) {
2574
+ const declaresParent = /* @__PURE__ */ new Map();
2575
+ for (const n of nodes) {
2576
+ const slug = typeof n?.type === "string" ? n.type.trim().toLowerCase() : "";
2577
+ if (!slug || declaresParent.has(slug)) continue;
2578
+ declaresParent.set(slug, n?.parent_type !== void 0);
2579
+ }
2580
+ return declaresParent;
2581
+ }
2540
2582
  function mergeOntologyUpdates(current, updates) {
2541
2583
  const node_types = [...current.node_types];
2542
2584
  const edge_types = [...current.edge_types];
2543
2585
  const nodeSlugs = new Set(node_types.map((n) => n.type.trim().toLowerCase()));
2544
2586
  const edgeKeys = new Set(edge_types.map((e) => edgeTripleKey(e.type, e.source_type, e.target_type)));
2545
2587
  const edgeNames = new Map(edge_types.map((e) => [e.type.trim().toLowerCase(), e.type.trim()]));
2588
+ const declaresParent = buildDeclaresParentIndex([
2589
+ ...current.node_types,
2590
+ ...updates.node_types ?? []
2591
+ ]);
2546
2592
  for (const node of updates.node_types ?? []) {
2547
2593
  const type = node?.type?.trim();
2548
2594
  if (!type) continue;
2549
2595
  const key = type.toLowerCase();
2550
2596
  if (nodeSlugs.has(key)) continue;
2551
- node_types.push({ type, description: String(node.description ?? "") });
2597
+ const rawParent = typeof node?.parent_type === "string" ? node.parent_type.trim() : "";
2598
+ const parentSlug = rawParent.toLowerCase();
2599
+ const keepParent = parentSlug !== "" && parentSlug !== key && declaresParent.get(parentSlug) === false;
2600
+ node_types.push({
2601
+ type,
2602
+ description: String(node.description ?? ""),
2603
+ ...keepParent ? { parent_type: rawParent } : {}
2604
+ });
2552
2605
  nodeSlugs.add(key);
2553
2606
  }
2554
2607
  for (const edge of updates.edge_types ?? []) {
@@ -2585,7 +2638,7 @@ function validateInlineEdges(sourceType, _targetType, edges, manifest, opts) {
2585
2638
  continue;
2586
2639
  }
2587
2640
  const defs = resolveEdgeDefinitions(edge.edge_type, manifest);
2588
- const match = defs.find((d) => d.source_type.toLowerCase() === sourceType.toLowerCase());
2641
+ const match = defs.find((d) => typeSatisfies(d.source_type, sourceType, manifest));
2589
2642
  if (!match) {
2590
2643
  if (strict) throw new WikiStrictOntologyViolation(entityId, "edge", edge.edge_type);
2591
2644
  continue;
@@ -4418,7 +4471,7 @@ var IngestionService = class {
4418
4471
  }
4419
4472
  const sourceType = sourceIdToType.get(edge.sourceId);
4420
4473
  const candidates = (manifest.edge_types ?? []).filter(
4421
- (d) => d.type.toLowerCase() === edge.type.toLowerCase() && d.source_type.toLowerCase() === (sourceType ?? "").toLowerCase()
4474
+ (d) => d.type.toLowerCase() === edge.type.toLowerCase() && typeSatisfies(d.source_type, sourceType ?? "", manifest)
4422
4475
  );
4423
4476
  const match = candidates[0];
4424
4477
  if (!match) {
@@ -6875,7 +6928,7 @@ Each fact may optionally include:
6875
6928
  var EMERGENT_EXTRA = `
6876
6929
  You may also return "ontology_updates" to propose new types:
6877
6930
  "ontology_updates": {
6878
- "node_types": [{ "type": "slug", "description": "..." }],
6931
+ "node_types": [{ "type": "slug", "description": "...", "parent_type": "optional existing slug" }],
6879
6932
  "edge_types": [{ "type": "slug", "source_type": "...", "target_type": "...", "description": "..." }]
6880
6933
  }
6881
6934
  Only propose types not already in the manifest. Do not redefine existing types.`;
@@ -6921,6 +6974,7 @@ var OntologyService = class {
6921
6974
  }
6922
6975
  const seed = this.ontologyConfig?.seedManifests?.[entityId];
6923
6976
  if (seed) {
6977
+ validateManifest(seed.manifest);
6924
6978
  const state = {
6925
6979
  mode: this.resolveMode(seed.mode),
6926
6980
  manifest: seed.manifest
@@ -6967,14 +7021,13 @@ var OntologyService = class {
6967
7021
  if (!sourceType || edges.length === 0) return [];
6968
7022
  const out = [];
6969
7023
  for (const edge of edges) {
6970
- const candidates = resolveEdgeDefinitions(edge.edge_type, manifest).filter((d) => d.source_type.toLowerCase() === sourceType.toLowerCase());
7024
+ const candidates = resolveEdgeDefinitions(edge.edge_type, manifest).filter((d) => typeSatisfies(d.source_type, sourceType, manifest));
6971
7025
  if (candidates.length === 0) continue;
6972
7026
  const targetKey = normalizeTitleKey(edge.target_title);
6973
7027
  const target = titleIndex.get(targetKey);
6974
7028
  if (!target) continue;
6975
- const def = candidates.find(
6976
- (d) => d.target_type.toLowerCase() === (target.okf_type ?? "").toLowerCase()
6977
- );
7029
+ const targetType = (target.okf_type ?? "").trim().toLowerCase();
7030
+ const def = candidates.find((d) => d.target_type.trim().toLowerCase() === targetType) ?? candidates.find((d) => typeSatisfies(d.target_type, targetType, manifest));
6978
7031
  if (!def) continue;
6979
7032
  out.push({
6980
7033
  id: generateId(),