@equationalapplications/core-llm-wiki 7.7.3 → 7.7.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/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, R as ReadOptions, S as SQLiteAdapter, W as WikiOptions, c as WikiMemory } from './testing-A4Sofxyo.mjs';
2
- export { C as ChunkFailure, d as ClassifierAnswer, e as ClassifierQuestion, f as ClassifyRequest, g as ClassifyResponse, D as DegradedRecord, h as DraftPage, E as EmbedFactResult, i as EmbedFailureKind, j as EmbeddingMarkerKind, k as EntityStatus, l as ExtractedFact, m as ExtractedFactEdge, n as ExtractedFactWithOntology, o as ExtractedTask, p as GraphTraversalOptions, q as GroundingConfig, H as HEAL_BATCH_SIZE, r as HEAL_RECHECK_MS, s as HOOK_TIMEOUT_MARKER, t as HealResult, I as IngestDocumentResult, L as LLMProvider, O as ONTOLOGY_BACKFILL_BATCH_SIZE, u as ONTOLOGY_BACKFILL_MAX_PROMPT_CHARS, v as ONTOLOGY_BACKFILL_RECHECK_MS, w as OntologyBackfillResult, x as OntologyConfig, y as OntologyEdgeType, z as OntologyManifest, A as OntologyMode, B as OntologyNodeType, J as OntologyPromptContext, K as OntologyUpdates, P as PendingSourceStatus, N as PromptOverrides, Q as PromptService, T as PrunePartialFailureError, U as ReembedResult, V as VectorRanker, X as VectorRankerFallback, Y as VectorRankerRankArgs, Z as VectorRankerSemanticResult, _ as WikiBusyError, $ as WikiBusyOperation, a0 as WikiCheckpoint, a1 as WikiConfig, a2 as WikiDiagnostic, a3 as WikiDiagnosticCode, a4 as WikiDiagnosticDetail, a5 as WikiDiagnosticOperation, a6 as WikiDiagnosticSeverity, a7 as WikiDiagnosticTrigger, a8 as WikiDraftNotFound, a9 as WikiDuplicateHashError, aa as WikiEdge, ab as WikiEvent, ac as WikiFact, ad as WikiGraphNodeOwnershipConflict, ae as WikiIngestEmptyError, af as WikiInstructions, ag as WikiInvalidReadOptions, ah as WikiLintReport, ai as WikiMemoryTestAccess, aj as WikiOutboxEvent, ak as WikiParseError, al as WikiSourceRefHashCollision, am as WikiStrictOntologyViolation, an as WikiTask, ao as WikiTransactionError, ap as validateManifest } from './testing-A4Sofxyo.mjs';
1
+ import { M as MemoryBundle, F as FormatContextOptions, G as GraphNeighborhood, a as MemoryDump, b as FormattedMemoryDump, R as ReadOptions, S as SQLiteAdapter, W as WikiOptions, c as WikiMemory } from './testing-CH_Kk34-.mjs';
2
+ export { C as ChunkFailure, d as ClassifierAnswer, e as ClassifierQuestion, f as ClassifyRequest, g as ClassifyResponse, D as DegradedRecord, h as DraftPage, E as EmbedFactResult, i as EmbedFailureKind, j as EmbeddingMarkerKind, k as EntityStatus, l as ExtractedFact, m as ExtractedFactEdge, n as ExtractedFactWithOntology, o as ExtractedTask, p as GraphTraversalOptions, q as GroundingConfig, H as HEAL_BATCH_SIZE, r as HEAL_RECHECK_MS, s as HOOK_TIMEOUT_MARKER, t as HealResult, I as IngestDocumentResult, L as LLMProvider, O as ONTOLOGY_BACKFILL_BATCH_SIZE, u as ONTOLOGY_BACKFILL_MAX_PROMPT_CHARS, v as ONTOLOGY_BACKFILL_RECHECK_MS, w as OntologyBackfillResult, x as OntologyConfig, y as OntologyEdgeType, z as OntologyManifest, A as OntologyMode, B as OntologyNodeType, J as OntologyPromptContext, K as OntologyUpdates, P as PendingSourceStatus, N as PromptOverrides, Q as PromptService, T as PrunePartialFailureError, U as ReembedResult, V as VectorRanker, X as VectorRankerFallback, Y as VectorRankerRankArgs, Z as VectorRankerSemanticResult, _ as WikiBusyError, $ as WikiBusyOperation, a0 as WikiCheckpoint, a1 as WikiConfig, a2 as WikiDiagnostic, a3 as WikiDiagnosticCode, a4 as WikiDiagnosticDetail, a5 as WikiDiagnosticOperation, a6 as WikiDiagnosticSeverity, a7 as WikiDiagnosticTrigger, a8 as WikiDraftNotFound, a9 as WikiDuplicateHashError, aa as WikiEdge, ab as WikiEvent, ac as WikiFact, ad as WikiGraphNodeOwnershipConflict, ae as WikiIngestEmptyError, af as WikiInstructions, ag as WikiInvalidReadOptions, ah as WikiLintReport, ai as WikiMemoryTestAccess, aj as WikiOutboxEvent, ak as WikiParseError, al as WikiSourceRefHashCollision, am as WikiStrictOntologyViolation, an as WikiTask, ao as WikiTransactionError, ap as validateManifest } from './testing-CH_Kk34-.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, R as ReadOptions, S as SQLiteAdapter, W as WikiOptions, c as WikiMemory } from './testing-A4Sofxyo.js';
2
- export { C as ChunkFailure, d as ClassifierAnswer, e as ClassifierQuestion, f as ClassifyRequest, g as ClassifyResponse, D as DegradedRecord, h as DraftPage, E as EmbedFactResult, i as EmbedFailureKind, j as EmbeddingMarkerKind, k as EntityStatus, l as ExtractedFact, m as ExtractedFactEdge, n as ExtractedFactWithOntology, o as ExtractedTask, p as GraphTraversalOptions, q as GroundingConfig, H as HEAL_BATCH_SIZE, r as HEAL_RECHECK_MS, s as HOOK_TIMEOUT_MARKER, t as HealResult, I as IngestDocumentResult, L as LLMProvider, O as ONTOLOGY_BACKFILL_BATCH_SIZE, u as ONTOLOGY_BACKFILL_MAX_PROMPT_CHARS, v as ONTOLOGY_BACKFILL_RECHECK_MS, w as OntologyBackfillResult, x as OntologyConfig, y as OntologyEdgeType, z as OntologyManifest, A as OntologyMode, B as OntologyNodeType, J as OntologyPromptContext, K as OntologyUpdates, P as PendingSourceStatus, N as PromptOverrides, Q as PromptService, T as PrunePartialFailureError, U as ReembedResult, V as VectorRanker, X as VectorRankerFallback, Y as VectorRankerRankArgs, Z as VectorRankerSemanticResult, _ as WikiBusyError, $ as WikiBusyOperation, a0 as WikiCheckpoint, a1 as WikiConfig, a2 as WikiDiagnostic, a3 as WikiDiagnosticCode, a4 as WikiDiagnosticDetail, a5 as WikiDiagnosticOperation, a6 as WikiDiagnosticSeverity, a7 as WikiDiagnosticTrigger, a8 as WikiDraftNotFound, a9 as WikiDuplicateHashError, aa as WikiEdge, ab as WikiEvent, ac as WikiFact, ad as WikiGraphNodeOwnershipConflict, ae as WikiIngestEmptyError, af as WikiInstructions, ag as WikiInvalidReadOptions, ah as WikiLintReport, ai as WikiMemoryTestAccess, aj as WikiOutboxEvent, ak as WikiParseError, al as WikiSourceRefHashCollision, am as WikiStrictOntologyViolation, an as WikiTask, ao as WikiTransactionError, ap as validateManifest } from './testing-A4Sofxyo.js';
1
+ import { M as MemoryBundle, F as FormatContextOptions, G as GraphNeighborhood, a as MemoryDump, b as FormattedMemoryDump, R as ReadOptions, S as SQLiteAdapter, W as WikiOptions, c as WikiMemory } from './testing-CH_Kk34-.js';
2
+ export { C as ChunkFailure, d as ClassifierAnswer, e as ClassifierQuestion, f as ClassifyRequest, g as ClassifyResponse, D as DegradedRecord, h as DraftPage, E as EmbedFactResult, i as EmbedFailureKind, j as EmbeddingMarkerKind, k as EntityStatus, l as ExtractedFact, m as ExtractedFactEdge, n as ExtractedFactWithOntology, o as ExtractedTask, p as GraphTraversalOptions, q as GroundingConfig, H as HEAL_BATCH_SIZE, r as HEAL_RECHECK_MS, s as HOOK_TIMEOUT_MARKER, t as HealResult, I as IngestDocumentResult, L as LLMProvider, O as ONTOLOGY_BACKFILL_BATCH_SIZE, u as ONTOLOGY_BACKFILL_MAX_PROMPT_CHARS, v as ONTOLOGY_BACKFILL_RECHECK_MS, w as OntologyBackfillResult, x as OntologyConfig, y as OntologyEdgeType, z as OntologyManifest, A as OntologyMode, B as OntologyNodeType, J as OntologyPromptContext, K as OntologyUpdates, P as PendingSourceStatus, N as PromptOverrides, Q as PromptService, T as PrunePartialFailureError, U as ReembedResult, V as VectorRanker, X as VectorRankerFallback, Y as VectorRankerRankArgs, Z as VectorRankerSemanticResult, _ as WikiBusyError, $ as WikiBusyOperation, a0 as WikiCheckpoint, a1 as WikiConfig, a2 as WikiDiagnostic, a3 as WikiDiagnosticCode, a4 as WikiDiagnosticDetail, a5 as WikiDiagnosticOperation, a6 as WikiDiagnosticSeverity, a7 as WikiDiagnosticTrigger, a8 as WikiDraftNotFound, a9 as WikiDuplicateHashError, aa as WikiEdge, ab as WikiEvent, ac as WikiFact, ad as WikiGraphNodeOwnershipConflict, ae as WikiIngestEmptyError, af as WikiInstructions, ag as WikiInvalidReadOptions, ah as WikiLintReport, ai as WikiMemoryTestAccess, aj as WikiOutboxEvent, ak as WikiParseError, al as WikiSourceRefHashCollision, am as WikiStrictOntologyViolation, an as WikiTask, ao as WikiTransactionError, ap as validateManifest } from './testing-CH_Kk34-.js';
3
3
  import { OkfFile } from '@equationalapplications/core-okf';
4
4
  import 'minisearch';
5
5
 
package/dist/index.js CHANGED
@@ -4410,6 +4410,23 @@ var DiagnosticBuffer = class {
4410
4410
  this.items = [];
4411
4411
  for (const input of pending) emitDiagnostic(options, input);
4412
4412
  }
4413
+ /**
4414
+ * Emit only the buffered diagnostics whose code is in `codes` and discard
4415
+ * the rest. The buffer is empty afterwards either way.
4416
+ *
4417
+ * For an operation that did real work before its write was rolled back:
4418
+ * some buffered diagnostics describe that work and are still true, while
4419
+ * others describe rows that no longer exist (anything carrying a `factId`
4420
+ * minted inside the aborted transaction). `flush` would emit both and
4421
+ * `discard` would drop both; this emits the first set only.
4422
+ */
4423
+ flushOnly(options, codes) {
4424
+ const pending = this.items;
4425
+ this.items = [];
4426
+ for (const input of pending) {
4427
+ if (codes.includes(input.code)) emitDiagnostic(options, input);
4428
+ }
4429
+ }
4413
4430
  discard() {
4414
4431
  this.items = [];
4415
4432
  }
@@ -4715,6 +4732,16 @@ var DEFAULT_MAX_CHUNK_LENGTH = 12e3;
4715
4732
  var DEFAULT_CHUNK_OVERLAP = 400;
4716
4733
 
4717
4734
  // src/services/IngestionService.ts
4735
+ var LLM_PASS_DIAGNOSTIC_CODES = ["ingest_chunk_failed", "fact_rejected", "fact_deduplicated"];
4736
+ function dedupDiagnostic(entityId, sourceRef, locator) {
4737
+ return {
4738
+ entityId,
4739
+ operation: "ingest",
4740
+ trigger: "call",
4741
+ code: "fact_deduplicated",
4742
+ detail: locator ? { sourceRef, chunkIndex: locator.chunkIndex, itemIndex: locator.itemIndex, reason: "exact_title" } : { sourceRef, reason: "exact_title" }
4743
+ };
4744
+ }
4718
4745
  function zeroChunkResult(duplicateOf) {
4719
4746
  const result = {
4720
4747
  truncated: false,
@@ -4851,11 +4878,7 @@ var IngestionService = class {
4851
4878
  const diagBuffer = new DiagnosticBuffer();
4852
4879
  const diagBase = { entityId, operation: "ingest", trigger: "call" };
4853
4880
  const pushDeduplicated = (chunkIndex, itemIndex) => {
4854
- diagBuffer.push({
4855
- ...diagBase,
4856
- code: "fact_deduplicated",
4857
- detail: { sourceRef, chunkIndex, itemIndex, reason: "exact_title" }
4858
- });
4881
+ diagBuffer.push(dedupDiagnostic(entityId, sourceRef, { chunkIndex, itemIndex }));
4859
4882
  };
4860
4883
  for (const [chunkIndex, slot] of chunkResults.entries()) {
4861
4884
  if (slot.status === "failed") {
@@ -4882,7 +4905,7 @@ var IngestionService = class {
4882
4905
  });
4883
4906
  }
4884
4907
  const orderedChunkFacts = [];
4885
- const groundingLedger = /* @__PURE__ */ new Map();
4908
+ const factLedger = /* @__PURE__ */ new Map();
4886
4909
  for (const [chunkIndex, slot] of chunkResults.entries()) {
4887
4910
  if (slot.status === "failed") continue;
4888
4911
  const keptFacts = [];
@@ -4890,7 +4913,11 @@ var IngestionService = class {
4890
4913
  const winner = winners.get(normalizeTitleKey(fact.title));
4891
4914
  if (winner?.chunkIndex !== chunkIndex || winner.k !== k) return;
4892
4915
  keptFacts.push(fact);
4893
- if (ingestGrounding) groundingLedger.set(fact, { verdict: slot.verdicts[k], chunkIndex, itemIndex: winner.itemIndex });
4916
+ factLedger.set(fact, {
4917
+ verdict: ingestGrounding ? slot.verdicts[k] : null,
4918
+ chunkIndex,
4919
+ itemIndex: winner.itemIndex
4920
+ });
4894
4921
  });
4895
4922
  orderedChunkFacts.push({ facts: keptFacts, ontology_updates: slot.ontology_updates });
4896
4923
  }
@@ -4920,7 +4947,7 @@ var IngestionService = class {
4920
4947
  try {
4921
4948
  if (failedChunks === 0) {
4922
4949
  const fullResult = await this.db.withTransactionAsync(async (tx) => {
4923
- return await this.runFullUpsertGraph(entityId, sourceRef, sourceHash, orderedChunkFacts, tx, diagBuffer, groundingLedger);
4950
+ return await this.runFullUpsertGraph(entityId, sourceRef, sourceHash, orderedChunkFacts, tx, diagBuffer, factLedger);
4924
4951
  });
4925
4952
  deletedSourceFactIds.push(...fullResult.deletedSourceFactIds);
4926
4953
  insertedFacts.push(...fullResult.insertedFacts);
@@ -4928,13 +4955,14 @@ var IngestionService = class {
4928
4955
  const partialResult = await this.db.withTransactionAsync(async (tx) => {
4929
4956
  const flat = [];
4930
4957
  for (const slot of orderedChunkFacts) flat.push(...slot.facts);
4931
- return await this.appendPartialFacts(entityId, sourceRef, flat, tx, diagBuffer, groundingLedger);
4958
+ return await this.appendPartialFacts(entityId, sourceRef, flat, tx, diagBuffer, factLedger);
4932
4959
  });
4933
4960
  insertedFacts.push(...partialResult.insertedDescriptors);
4934
4961
  }
4935
4962
  } catch (err) {
4936
4963
  const sqliteCode = err instanceof WikiTransactionError ? err.sqliteErrorCode : extractSqliteCode(err);
4937
4964
  if (sqliteCode !== "SQLITE_CONSTRAINT_UNIQUE") throw err;
4965
+ diagBuffer.flushOnly(this.options, LLM_PASS_DIAGNOSTIC_CODES);
4938
4966
  const canonical = await this.sourceRefIndexRepo.findActiveByEntityAndHash(entityId, sourceHash);
4939
4967
  if (canonical === null) throw err;
4940
4968
  if (onDuplicateHash === "throw" || onDuplicateHash === "ingest") {
@@ -5162,7 +5190,7 @@ var IngestionService = class {
5162
5190
  * On the partial path the caller never invokes this method; the empty
5163
5191
  * arrays stay empty.
5164
5192
  */
5165
- async runFullUpsertGraph(entityId, sourceRef, sourceHash, orderedChunkFacts, tx, diagBuffer, groundingLedger = /* @__PURE__ */ new Map()) {
5193
+ async runFullUpsertGraph(entityId, sourceRef, sourceHash, orderedChunkFacts, tx, diagBuffer, factLedger = /* @__PURE__ */ new Map()) {
5166
5194
  const deletedSourceFactIds = [];
5167
5195
  const insertedFacts = [];
5168
5196
  const nodeTrust = /* @__PURE__ */ new Map();
@@ -5209,9 +5237,9 @@ var IngestionService = class {
5209
5237
  tags: fact.tags,
5210
5238
  confidence: fact.confidence
5211
5239
  });
5212
- const grounding = groundingLedger.get(fact);
5213
- if (grounding) {
5214
- const outcome = groundingOutcome(grounding.verdict, now);
5240
+ const locator = factLedger.get(fact);
5241
+ if (locator?.verdict) {
5242
+ const outcome = groundingOutcome(locator.verdict, now);
5215
5243
  nodeTrust.set(id, outcome.trust);
5216
5244
  if (outcome.diagnostic) {
5217
5245
  diagBuffer.push({
@@ -5219,7 +5247,7 @@ var IngestionService = class {
5219
5247
  operation: "ingest",
5220
5248
  trigger: "call",
5221
5249
  code: outcome.diagnostic.code,
5222
- detail: { factId: id, sourceRef, chunkIndex: grounding.chunkIndex, itemIndex: grounding.itemIndex, reason: outcome.diagnostic.reason }
5250
+ detail: { factId: id, sourceRef, chunkIndex: locator.chunkIndex, itemIndex: locator.itemIndex, reason: outcome.diagnostic.reason }
5223
5251
  });
5224
5252
  }
5225
5253
  }
@@ -5278,7 +5306,7 @@ var IngestionService = class {
5278
5306
  * Runs INSIDE the caller's `tx`. Does not open a nested transaction.
5279
5307
  * Returns `{ inserted, skippedDuplicate }` for observability.
5280
5308
  */
5281
- async appendPartialFacts(entityId, sourceRef, dedupedFacts, tx, diagBuffer, groundingLedger = /* @__PURE__ */ new Map()) {
5309
+ async appendPartialFacts(entityId, sourceRef, dedupedFacts, tx, diagBuffer, factLedger = /* @__PURE__ */ new Map()) {
5282
5310
  const liveIds = await this.entryRepo.findIdsBySource(entityId, sourceRef, null, tx, false);
5283
5311
  const liveFacts = liveIds.length === 0 ? [] : await this.entryRepo.findByIds(liveIds, void 0, tx);
5284
5312
  const liveTitles = new Set(liveFacts.map((f) => normalizeTitleKey(f.title)));
@@ -5288,28 +5316,22 @@ var IngestionService = class {
5288
5316
  const insertedDescriptors = [];
5289
5317
  for (const fact of dedupedFacts) {
5290
5318
  const normalizedTitle = normalizeTitleKey(fact.title);
5319
+ const locator = factLedger.get(fact);
5291
5320
  if (liveTitles.has(normalizedTitle)) {
5292
- diagBuffer.push({
5293
- entityId,
5294
- operation: "ingest",
5295
- trigger: "call",
5296
- code: "fact_deduplicated",
5297
- detail: { sourceRef, reason: "exact_title" }
5298
- });
5321
+ diagBuffer.push(dedupDiagnostic(entityId, sourceRef, locator));
5299
5322
  skippedDuplicate++;
5300
5323
  continue;
5301
5324
  }
5302
5325
  liveTitles.add(normalizedTitle);
5303
5326
  const id = generateId("fact_");
5304
- const grounding = groundingLedger.get(fact);
5305
- const outcome = grounding ? groundingOutcome(grounding.verdict, now) : null;
5306
- if (grounding && outcome?.diagnostic) {
5327
+ const outcome = locator?.verdict ? groundingOutcome(locator.verdict, now) : null;
5328
+ if (locator?.verdict && outcome?.diagnostic) {
5307
5329
  diagBuffer.push({
5308
5330
  entityId,
5309
5331
  operation: "ingest",
5310
5332
  trigger: "call",
5311
5333
  code: outcome.diagnostic.code,
5312
- detail: { factId: id, sourceRef, chunkIndex: grounding.chunkIndex, itemIndex: grounding.itemIndex, reason: outcome.diagnostic.reason }
5334
+ detail: { factId: id, sourceRef, chunkIndex: locator.chunkIndex, itemIndex: locator.itemIndex, reason: outcome.diagnostic.reason }
5313
5335
  });
5314
5336
  }
5315
5337
  const wikiFact = {