@equationalapplications/core-llm-wiki 5.4.0 → 5.5.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.
@@ -673,6 +673,79 @@ declare class PrunePartialFailureError extends Error {
673
673
  constructor(deleted: number, failedAt: string, remaining: number, cause: Error, deletedTasks?: number, deletedEvents?: number);
674
674
  }
675
675
  declare const HOOK_TIMEOUT_MARKER: unique symbol;
676
+ /**
677
+ * Failure record for a single chunk that could not be ingested. Produced by
678
+ * `IngestionService.ingestDocument` and surfaced on the result's `parseFailures`
679
+ * array. `source === 'parse'` for `WikiParseError`-shaped failures (then `tier`
680
+ * is set); `source === 'llm'` for `generateText` rejections (no `tier`).
681
+ *
682
+ * Note: `'ontologyContext'` is reserved but NEVER produced. `buildPromptContext`
683
+ * failures are DB-systemic and propagate as raw throws, not as `parseFailures`.
684
+ */
685
+ interface ChunkFailure {
686
+ chunkIndex: number;
687
+ sourceRef: string;
688
+ source: 'parse' | 'llm';
689
+ tier?: 'strict' | 'repair' | 'all';
690
+ position: number | null;
691
+ message: string;
692
+ }
693
+ /**
694
+ * Result of `IngestionService.ingestDocument`. The shape WIDENS relative to
695
+ * earlier versions: `ingestedChunks` and `failedChunks` are always present;
696
+ * `parseFailures` is present iff at least one chunk failed.
697
+ *
698
+ * Hosts that destructure `{ truncated, chunks }` see no behavior change.
699
+ * Hosts pattern-matching the entire shape must update to the new fields.
700
+ */
701
+ interface IngestDocumentResult {
702
+ truncated: boolean;
703
+ chunks: number;
704
+ ingestedChunks: number;
705
+ failedChunks: number;
706
+ duplicateOf?: string;
707
+ parseFailures?: ChunkFailure[];
708
+ }
709
+ /**
710
+ * Thrown by `parseJsonResponse` when both the strict scanner pass and the
711
+ * container-aware repair pass fail to produce a parsable candidate.
712
+ *
713
+ * - `tier: 'strict'` — the existing scanner produced no usable slice (no
714
+ * `{`/`[` at all, or no balanced close). `slice` is the full input text;
715
+ * `position` is the offset of the first `{`/`[`, or `null` when none found.
716
+ * - `tier: 'repair'` — tier 1 found a slice but `JSON.parse` failed; tier 2
717
+ * produced no parsable candidate within `MAX_REPAIR_CANDIDATES`. `slice` is
718
+ * the largest balanced span the walker found; `position` is the offset of
719
+ * the first parse failure within that candidate when known.
720
+ * - `tier: 'all'` — generic catch-all.
721
+ */
722
+ declare class WikiParseError extends Error {
723
+ readonly tier: 'strict' | 'repair' | 'all';
724
+ readonly position: number | null;
725
+ readonly slice: string;
726
+ constructor(message: string, opts: {
727
+ tier: WikiParseError['tier'];
728
+ position?: number | null;
729
+ slice?: string;
730
+ });
731
+ }
732
+ /**
733
+ * Thrown by `IngestionService.ingestDocument` when every chunk of a document
734
+ * failed (either `parseJsonResponse` or `generateText`). A silent zero-fact
735
+ * ingest is a worse regression than a typed throw — matches existing host
736
+ * semantics (`aws-cloud-agent` Writer Lambda today sees `ingestDocument`
737
+ * throw on any failure).
738
+ */
739
+ declare class WikiIngestEmptyError extends Error {
740
+ readonly parseFailures: ChunkFailure[];
741
+ readonly sourceRef: string;
742
+ readonly chunks: number;
743
+ constructor(params: {
744
+ parseFailures: ChunkFailure[];
745
+ sourceRef: string;
746
+ chunks: number;
747
+ });
748
+ }
676
749
 
677
750
  interface WikiOutboxEvent<T = unknown> {
678
751
  id: string;
@@ -1491,11 +1564,7 @@ declare class IngestionService {
1491
1564
  promptOverride?: string;
1492
1565
  }, opts?: {
1493
1566
  onDuplicateHash?: 'ingest' | 'skip' | 'throw';
1494
- }): Promise<{
1495
- truncated: boolean;
1496
- chunks: number;
1497
- duplicateOf?: string;
1498
- }>;
1567
+ }): Promise<IngestDocumentResult>;
1499
1568
  /**
1500
1569
  * Implements spec §2 data flow steps a–j with the host-facing
1501
1570
  * `{sourceRef, sourceHash, nodes, edges}` parameter shape. Shared between
@@ -1539,6 +1608,38 @@ declare class IngestionService {
1539
1608
  edgesWritten: number;
1540
1609
  superseded: number;
1541
1610
  }>;
1611
+ /**
1612
+ * Full supersession + ownership path: identical to the pre-issue-#92 behavior
1613
+ * for the happy path. Called from the `failedChunks === 0` branch of
1614
+ * `ingestDocument`. Runs INSIDE the caller's tx.
1615
+ *
1616
+ * Returns `{ deletedSourceFactIds, insertedFacts }` so the caller can fire
1617
+ * post-commit hooks (embedding lifecycle) AFTER the transaction commits.
1618
+ * On the partial path the caller never invokes this method; the empty
1619
+ * arrays stay empty.
1620
+ */
1621
+ private runFullUpsertGraph;
1622
+ /**
1623
+ * Partial-commit path for `ingestDocument`. Inserts ONLY facts whose
1624
+ * normalized title is not already in the live set for this (entityId,
1625
+ * sourceRef). Does NOT call `entryRepo.softDeleteBySource` (no
1626
+ * supersession) and does NOT call `sourceRefIndexRepo.upsert` (no
1627
+ * ownership). Edges are NOT resolved on this path (no ontology-context
1628
+ * build, no `resolveEdges`, no `mergeEmergentUpdates`). Stale edges from
1629
+ * prior attempts are recovered on the next full run's supersession.
1630
+ *
1631
+ * Source-hash is stored as NULL on partial rows. `findLatestSourceHash`
1632
+ * reads from the most recently updated live row for the sourceRef, so
1633
+ * storing the incoming hash here would cause `hasChanged` to return
1634
+ * `false` on a same-hash retry — the failed chunks would never get a
1635
+ * second chance. With NULL, a retry sees `storedHash === null`, `hasChanged`
1636
+ * returns `true`, and the partial commit's sibling rows remain live
1637
+ * (deduped, not superseded) for the next attempt to extend.
1638
+ *
1639
+ * Runs INSIDE the caller's `tx`. Does not open a nested transaction.
1640
+ * Returns `{ inserted, skippedDuplicate }` for observability.
1641
+ */
1642
+ private appendPartialFacts;
1542
1643
  }
1543
1644
 
1544
1645
  declare class TaskRepository extends BaseRepository {
@@ -2098,11 +2199,7 @@ declare class WikiMemory {
2098
2199
  promptOverride?: string;
2099
2200
  }, opts?: {
2100
2201
  onDuplicateHash?: 'ingest' | 'skip' | 'throw';
2101
- }): Promise<{
2102
- truncated: boolean;
2103
- chunks: number;
2104
- duplicateOf?: string;
2105
- }>;
2202
+ }): Promise<IngestDocumentResult>;
2106
2203
  /**
2107
2204
  * Deterministic write path into the graph. Accepts caller-supplied
2108
2205
  * `(nodes, edges)` and writes them under `(sourceRef, sourceHash)`
@@ -2207,4 +2304,4 @@ declare class WikiMemory {
2207
2304
  setGeneratedByTask(taskId: string, entityId: string, actor: string): Promise<void>;
2208
2305
  }
2209
2306
 
2210
- export { ImportExportService as $, WikiBusyError as A, type WikiBusyOperation as B, type WikiCheckpoint as C, type WikiConfig as D, type EntityStatus as E, type FormatContextOptions as F, type GraphNeighborhood as G, HEAL_BATCH_SIZE as H, WikiDuplicateHashError as I, type WikiEdge as J, type WikiEvent as K, type LLMProvider as L, type MemoryBundle as M, type WikiFact as N, type OntologyManifest as O, type PromptOverrides as P, type WikiMemoryTestAccess as Q, type ReadOptions as R, type SQLiteAdapter as S, type WikiOutboxEvent as T, WikiSourceRefHashCollision as U, type VectorRanker as V, type WikiOptions as W, WikiStrictOntologyViolation as X, type WikiTask as Y, WikiTransactionError as Z, EmbeddingService as _, type MemoryDump as a, IngestionService as a0, JobManager as a1, MaintenanceService as a2, RetrievalService as a3, SearchService as a4, WriteService as a5, type FormattedMemoryDump as b, WikiMemory as c, type ExtractedFact as d, type ExtractedFactEdge as e, type ExtractedFactWithOntology as f, type ExtractedTask as g, type GraphTraversalOptions as h, HEAL_RECHECK_MS as i, HOOK_TIMEOUT_MARKER as j, type HealResult as k, ONTOLOGY_BACKFILL_BATCH_SIZE as l, ONTOLOGY_BACKFILL_MAX_PROMPT_CHARS as m, ONTOLOGY_BACKFILL_RECHECK_MS as n, type OntologyBackfillResult as o, type OntologyConfig as p, type OntologyEdgeType as q, type OntologyMode as r, type OntologyNodeType as s, type OntologyPromptContext as t, type OntologyUpdates as u, PromptService as v, PrunePartialFailureError as w, type VectorRankerFallback as x, type VectorRankerRankArgs as y, type VectorRankerSemanticResult as z };
2307
+ export { WikiStrictOntologyViolation as $, WikiBusyError as A, type WikiBusyOperation as B, type ChunkFailure as C, type WikiCheckpoint as D, type EntityStatus as E, type FormatContextOptions as F, type GraphNeighborhood as G, HEAL_BATCH_SIZE as H, type IngestDocumentResult as I, type WikiConfig as J, WikiDuplicateHashError as K, type LLMProvider as L, type MemoryBundle as M, type WikiEdge as N, type OntologyManifest as O, type PromptOverrides as P, type WikiEvent as Q, type ReadOptions as R, type SQLiteAdapter as S, type WikiFact as T, WikiIngestEmptyError as U, type VectorRanker as V, type WikiOptions as W, type WikiMemoryTestAccess as X, type WikiOutboxEvent as Y, WikiParseError as Z, WikiSourceRefHashCollision as _, type MemoryDump as a, type WikiTask as a0, WikiTransactionError as a1, EmbeddingService as a2, ImportExportService as a3, IngestionService as a4, JobManager as a5, MaintenanceService as a6, RetrievalService as a7, SearchService as a8, WriteService as a9, type FormattedMemoryDump as b, WikiMemory as c, type ExtractedFact as d, type ExtractedFactEdge as e, type ExtractedFactWithOntology as f, type ExtractedTask as g, type GraphTraversalOptions as h, HEAL_RECHECK_MS as i, HOOK_TIMEOUT_MARKER as j, type HealResult as k, ONTOLOGY_BACKFILL_BATCH_SIZE as l, ONTOLOGY_BACKFILL_MAX_PROMPT_CHARS as m, ONTOLOGY_BACKFILL_RECHECK_MS as n, type OntologyBackfillResult as o, type OntologyConfig as p, type OntologyEdgeType as q, type OntologyMode as r, type OntologyNodeType as s, type OntologyPromptContext as t, type OntologyUpdates as u, PromptService as v, PrunePartialFailureError as w, type VectorRankerFallback as x, type VectorRankerRankArgs as y, type VectorRankerSemanticResult as z };
@@ -673,6 +673,79 @@ declare class PrunePartialFailureError extends Error {
673
673
  constructor(deleted: number, failedAt: string, remaining: number, cause: Error, deletedTasks?: number, deletedEvents?: number);
674
674
  }
675
675
  declare const HOOK_TIMEOUT_MARKER: unique symbol;
676
+ /**
677
+ * Failure record for a single chunk that could not be ingested. Produced by
678
+ * `IngestionService.ingestDocument` and surfaced on the result's `parseFailures`
679
+ * array. `source === 'parse'` for `WikiParseError`-shaped failures (then `tier`
680
+ * is set); `source === 'llm'` for `generateText` rejections (no `tier`).
681
+ *
682
+ * Note: `'ontologyContext'` is reserved but NEVER produced. `buildPromptContext`
683
+ * failures are DB-systemic and propagate as raw throws, not as `parseFailures`.
684
+ */
685
+ interface ChunkFailure {
686
+ chunkIndex: number;
687
+ sourceRef: string;
688
+ source: 'parse' | 'llm';
689
+ tier?: 'strict' | 'repair' | 'all';
690
+ position: number | null;
691
+ message: string;
692
+ }
693
+ /**
694
+ * Result of `IngestionService.ingestDocument`. The shape WIDENS relative to
695
+ * earlier versions: `ingestedChunks` and `failedChunks` are always present;
696
+ * `parseFailures` is present iff at least one chunk failed.
697
+ *
698
+ * Hosts that destructure `{ truncated, chunks }` see no behavior change.
699
+ * Hosts pattern-matching the entire shape must update to the new fields.
700
+ */
701
+ interface IngestDocumentResult {
702
+ truncated: boolean;
703
+ chunks: number;
704
+ ingestedChunks: number;
705
+ failedChunks: number;
706
+ duplicateOf?: string;
707
+ parseFailures?: ChunkFailure[];
708
+ }
709
+ /**
710
+ * Thrown by `parseJsonResponse` when both the strict scanner pass and the
711
+ * container-aware repair pass fail to produce a parsable candidate.
712
+ *
713
+ * - `tier: 'strict'` — the existing scanner produced no usable slice (no
714
+ * `{`/`[` at all, or no balanced close). `slice` is the full input text;
715
+ * `position` is the offset of the first `{`/`[`, or `null` when none found.
716
+ * - `tier: 'repair'` — tier 1 found a slice but `JSON.parse` failed; tier 2
717
+ * produced no parsable candidate within `MAX_REPAIR_CANDIDATES`. `slice` is
718
+ * the largest balanced span the walker found; `position` is the offset of
719
+ * the first parse failure within that candidate when known.
720
+ * - `tier: 'all'` — generic catch-all.
721
+ */
722
+ declare class WikiParseError extends Error {
723
+ readonly tier: 'strict' | 'repair' | 'all';
724
+ readonly position: number | null;
725
+ readonly slice: string;
726
+ constructor(message: string, opts: {
727
+ tier: WikiParseError['tier'];
728
+ position?: number | null;
729
+ slice?: string;
730
+ });
731
+ }
732
+ /**
733
+ * Thrown by `IngestionService.ingestDocument` when every chunk of a document
734
+ * failed (either `parseJsonResponse` or `generateText`). A silent zero-fact
735
+ * ingest is a worse regression than a typed throw — matches existing host
736
+ * semantics (`aws-cloud-agent` Writer Lambda today sees `ingestDocument`
737
+ * throw on any failure).
738
+ */
739
+ declare class WikiIngestEmptyError extends Error {
740
+ readonly parseFailures: ChunkFailure[];
741
+ readonly sourceRef: string;
742
+ readonly chunks: number;
743
+ constructor(params: {
744
+ parseFailures: ChunkFailure[];
745
+ sourceRef: string;
746
+ chunks: number;
747
+ });
748
+ }
676
749
 
677
750
  interface WikiOutboxEvent<T = unknown> {
678
751
  id: string;
@@ -1491,11 +1564,7 @@ declare class IngestionService {
1491
1564
  promptOverride?: string;
1492
1565
  }, opts?: {
1493
1566
  onDuplicateHash?: 'ingest' | 'skip' | 'throw';
1494
- }): Promise<{
1495
- truncated: boolean;
1496
- chunks: number;
1497
- duplicateOf?: string;
1498
- }>;
1567
+ }): Promise<IngestDocumentResult>;
1499
1568
  /**
1500
1569
  * Implements spec §2 data flow steps a–j with the host-facing
1501
1570
  * `{sourceRef, sourceHash, nodes, edges}` parameter shape. Shared between
@@ -1539,6 +1608,38 @@ declare class IngestionService {
1539
1608
  edgesWritten: number;
1540
1609
  superseded: number;
1541
1610
  }>;
1611
+ /**
1612
+ * Full supersession + ownership path: identical to the pre-issue-#92 behavior
1613
+ * for the happy path. Called from the `failedChunks === 0` branch of
1614
+ * `ingestDocument`. Runs INSIDE the caller's tx.
1615
+ *
1616
+ * Returns `{ deletedSourceFactIds, insertedFacts }` so the caller can fire
1617
+ * post-commit hooks (embedding lifecycle) AFTER the transaction commits.
1618
+ * On the partial path the caller never invokes this method; the empty
1619
+ * arrays stay empty.
1620
+ */
1621
+ private runFullUpsertGraph;
1622
+ /**
1623
+ * Partial-commit path for `ingestDocument`. Inserts ONLY facts whose
1624
+ * normalized title is not already in the live set for this (entityId,
1625
+ * sourceRef). Does NOT call `entryRepo.softDeleteBySource` (no
1626
+ * supersession) and does NOT call `sourceRefIndexRepo.upsert` (no
1627
+ * ownership). Edges are NOT resolved on this path (no ontology-context
1628
+ * build, no `resolveEdges`, no `mergeEmergentUpdates`). Stale edges from
1629
+ * prior attempts are recovered on the next full run's supersession.
1630
+ *
1631
+ * Source-hash is stored as NULL on partial rows. `findLatestSourceHash`
1632
+ * reads from the most recently updated live row for the sourceRef, so
1633
+ * storing the incoming hash here would cause `hasChanged` to return
1634
+ * `false` on a same-hash retry — the failed chunks would never get a
1635
+ * second chance. With NULL, a retry sees `storedHash === null`, `hasChanged`
1636
+ * returns `true`, and the partial commit's sibling rows remain live
1637
+ * (deduped, not superseded) for the next attempt to extend.
1638
+ *
1639
+ * Runs INSIDE the caller's `tx`. Does not open a nested transaction.
1640
+ * Returns `{ inserted, skippedDuplicate }` for observability.
1641
+ */
1642
+ private appendPartialFacts;
1542
1643
  }
1543
1644
 
1544
1645
  declare class TaskRepository extends BaseRepository {
@@ -2098,11 +2199,7 @@ declare class WikiMemory {
2098
2199
  promptOverride?: string;
2099
2200
  }, opts?: {
2100
2201
  onDuplicateHash?: 'ingest' | 'skip' | 'throw';
2101
- }): Promise<{
2102
- truncated: boolean;
2103
- chunks: number;
2104
- duplicateOf?: string;
2105
- }>;
2202
+ }): Promise<IngestDocumentResult>;
2106
2203
  /**
2107
2204
  * Deterministic write path into the graph. Accepts caller-supplied
2108
2205
  * `(nodes, edges)` and writes them under `(sourceRef, sourceHash)`
@@ -2207,4 +2304,4 @@ declare class WikiMemory {
2207
2304
  setGeneratedByTask(taskId: string, entityId: string, actor: string): Promise<void>;
2208
2305
  }
2209
2306
 
2210
- export { ImportExportService as $, WikiBusyError as A, type WikiBusyOperation as B, type WikiCheckpoint as C, type WikiConfig as D, type EntityStatus as E, type FormatContextOptions as F, type GraphNeighborhood as G, HEAL_BATCH_SIZE as H, WikiDuplicateHashError as I, type WikiEdge as J, type WikiEvent as K, type LLMProvider as L, type MemoryBundle as M, type WikiFact as N, type OntologyManifest as O, type PromptOverrides as P, type WikiMemoryTestAccess as Q, type ReadOptions as R, type SQLiteAdapter as S, type WikiOutboxEvent as T, WikiSourceRefHashCollision as U, type VectorRanker as V, type WikiOptions as W, WikiStrictOntologyViolation as X, type WikiTask as Y, WikiTransactionError as Z, EmbeddingService as _, type MemoryDump as a, IngestionService as a0, JobManager as a1, MaintenanceService as a2, RetrievalService as a3, SearchService as a4, WriteService as a5, type FormattedMemoryDump as b, WikiMemory as c, type ExtractedFact as d, type ExtractedFactEdge as e, type ExtractedFactWithOntology as f, type ExtractedTask as g, type GraphTraversalOptions as h, HEAL_RECHECK_MS as i, HOOK_TIMEOUT_MARKER as j, type HealResult as k, ONTOLOGY_BACKFILL_BATCH_SIZE as l, ONTOLOGY_BACKFILL_MAX_PROMPT_CHARS as m, ONTOLOGY_BACKFILL_RECHECK_MS as n, type OntologyBackfillResult as o, type OntologyConfig as p, type OntologyEdgeType as q, type OntologyMode as r, type OntologyNodeType as s, type OntologyPromptContext as t, type OntologyUpdates as u, PromptService as v, PrunePartialFailureError as w, type VectorRankerFallback as x, type VectorRankerRankArgs as y, type VectorRankerSemanticResult as z };
2307
+ export { WikiStrictOntologyViolation as $, WikiBusyError as A, type WikiBusyOperation as B, type ChunkFailure as C, type WikiCheckpoint as D, type EntityStatus as E, type FormatContextOptions as F, type GraphNeighborhood as G, HEAL_BATCH_SIZE as H, type IngestDocumentResult as I, type WikiConfig as J, WikiDuplicateHashError as K, type LLMProvider as L, type MemoryBundle as M, type WikiEdge as N, type OntologyManifest as O, type PromptOverrides as P, type WikiEvent as Q, type ReadOptions as R, type SQLiteAdapter as S, type WikiFact as T, WikiIngestEmptyError as U, type VectorRanker as V, type WikiOptions as W, type WikiMemoryTestAccess as X, type WikiOutboxEvent as Y, WikiParseError as Z, WikiSourceRefHashCollision as _, type MemoryDump as a, type WikiTask as a0, WikiTransactionError as a1, EmbeddingService as a2, ImportExportService as a3, IngestionService as a4, JobManager as a5, MaintenanceService as a6, RetrievalService as a7, SearchService as a8, WriteService as a9, type FormattedMemoryDump as b, WikiMemory as c, type ExtractedFact as d, type ExtractedFactEdge as e, type ExtractedFactWithOntology as f, type ExtractedTask as g, type GraphTraversalOptions as h, HEAL_RECHECK_MS as i, HOOK_TIMEOUT_MARKER as j, type HealResult as k, ONTOLOGY_BACKFILL_BATCH_SIZE as l, ONTOLOGY_BACKFILL_MAX_PROMPT_CHARS as m, ONTOLOGY_BACKFILL_RECHECK_MS as n, type OntologyBackfillResult as o, type OntologyConfig as p, type OntologyEdgeType as q, type OntologyMode as r, type OntologyNodeType as s, type OntologyPromptContext as t, type OntologyUpdates as u, PromptService as v, PrunePartialFailureError as w, type VectorRankerFallback as x, type VectorRankerRankArgs as y, type VectorRankerSemanticResult as z };
@@ -1,3 +1,3 @@
1
- export { _ as EmbeddingService, $ as ImportExportService, a0 as IngestionService, a1 as JobManager, a1 as JobManagerType, a2 as MaintenanceService, a3 as RetrievalService, a4 as SearchService, a4 as SearchServiceType, Q as WikiMemoryTestAccess, a5 as WriteService } from './testing-C71mnMxq.mjs';
1
+ export { a2 as EmbeddingService, a3 as ImportExportService, a4 as IngestionService, a5 as JobManager, a5 as JobManagerType, a6 as MaintenanceService, a7 as RetrievalService, a8 as SearchService, a8 as SearchServiceType, X as WikiMemoryTestAccess, a9 as WriteService } from './testing-D0RnZjyW.mjs';
2
2
  import '@equationalapplications/core-okf';
3
3
  import 'minisearch';
package/dist/testing.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export { _ as EmbeddingService, $ as ImportExportService, a0 as IngestionService, a1 as JobManager, a1 as JobManagerType, a2 as MaintenanceService, a3 as RetrievalService, a4 as SearchService, a4 as SearchServiceType, Q as WikiMemoryTestAccess, a5 as WriteService } from './testing-C71mnMxq.js';
1
+ export { a2 as EmbeddingService, a3 as ImportExportService, a4 as IngestionService, a5 as JobManager, a5 as JobManagerType, a6 as MaintenanceService, a7 as RetrievalService, a8 as SearchService, a8 as SearchServiceType, X as WikiMemoryTestAccess, a9 as WriteService } from './testing-D0RnZjyW.js';
2
2
  import '@equationalapplications/core-okf';
3
3
  import 'minisearch';