@equationalapplications/core-llm-wiki 9.16.1 → 9.17.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.
@@ -246,6 +246,16 @@ function resolveSystemOneTypeOnWrite(config) {
246
246
  }
247
247
  return typeOnWrite ?? "llm";
248
248
  }
249
+ function resolveSystemOneTypeOnIngest(config) {
250
+ const typeOnIngest = config?.systemOne?.typeOnIngest;
251
+ if (typeOnIngest !== void 0 && !isTypingMode(typeOnIngest)) {
252
+ warnOnce(
253
+ `[core-llm-wiki] systemOne: \`systemOne.typeOnIngest\` is ${formatConfigValue(typeOnIngest)}, which is not 'auto' or 'llm'. The key is treated as unset; the default ('llm') applies.`
254
+ );
255
+ return "llm";
256
+ }
257
+ return typeOnIngest ?? "llm";
258
+ }
249
259
  function resolveHealScreenMinConfidence(config) {
250
260
  if (resolveSystemOneHealScreen(config) !== "auto") return void 0;
251
261
  const floor = config?.systemOne?.minConfidence?.healScreen;
@@ -505,13 +515,19 @@ var UsageMeter = class {
505
515
  constructor(budget) {
506
516
  this.used = 0;
507
517
  this.estimated = false;
518
+ this.heldTokens = 0;
508
519
  if (budget !== void 0 && (typeof budget !== "number" || !Number.isFinite(budget) || budget < 0)) {
509
520
  throw new TypeError("tokenBudget must be a finite number >= 0");
510
521
  }
511
522
  this.budget = budget;
512
523
  }
524
+ /** Tokens held by in-flight reservations. */
525
+ get reserved() {
526
+ return this.heldTokens;
527
+ }
528
+ /** budget - used - reserved, clamped at 0; Infinity when unbounded. */
513
529
  get remaining() {
514
- return this.budget === void 0 ? Infinity : Math.max(0, this.budget - this.used);
530
+ return this.budget === void 0 ? Infinity : Math.max(0, this.budget - this.used - this.heldTokens);
515
531
  }
516
532
  fits(estimate) {
517
533
  return estimate <= this.remaining;
@@ -520,6 +536,33 @@ var UsageMeter = class {
520
536
  this.used += r.inputTokens + r.outputTokens;
521
537
  if (r.estimated) this.estimated = true;
522
538
  }
539
+ /**
540
+ * Admit a call on `estimate` (throws WikiBudgetExhausted when it does not
541
+ * fit the unreserved remainder) and hold `max(estimate, hold)` tokens until
542
+ * settle/release.
543
+ */
544
+ reserve(estimate, hold) {
545
+ if (!this.fits(estimate)) throw new WikiBudgetExhausted(estimate, this.remaining);
546
+ const handle = { _brand: "UsageReservation", hold: Math.max(estimate, hold ?? estimate), open: true };
547
+ this.heldTokens += handle.hold;
548
+ return handle;
549
+ }
550
+ /** Free the hold, then charge the real usage. A closed handle is a no-op. */
551
+ settle(handle, actual) {
552
+ if (!this.close(handle)) return;
553
+ this.record(actual);
554
+ }
555
+ /** Free the hold and charge nothing. A closed handle is a no-op. */
556
+ release(handle) {
557
+ this.close(handle);
558
+ }
559
+ close(handle) {
560
+ const h = handle;
561
+ if (!h.open) return false;
562
+ h.open = false;
563
+ this.heldTokens -= h.hold;
564
+ return true;
565
+ }
523
566
  };
524
567
  var WikiBudgetExhausted = class _WikiBudgetExhausted extends Error {
525
568
  constructor(requiredEstimate, remaining) {
@@ -532,6 +575,7 @@ var WikiBudgetExhausted = class _WikiBudgetExhausted extends Error {
532
575
  };
533
576
 
534
577
  // src/utils/llmCall.ts
578
+ var CLASSIFY_HOLD_FACTOR = 2;
535
579
  function validUsage(u) {
536
580
  if (!u || typeof u !== "object") return false;
537
581
  const { inputTokens, outputTokens } = u;
@@ -539,25 +583,29 @@ function validUsage(u) {
539
583
  }
540
584
  async function callLlm(options, ctx, prompts) {
541
585
  const promptEstimate = estimateTokens(prompts.systemPrompt) + estimateTokens(prompts.userPrompt);
542
- if (ctx.meter && !ctx.meter.fits(promptEstimate)) {
543
- throw new WikiBudgetExhausted(promptEstimate, ctx.meter.remaining);
544
- }
545
586
  const provider = options.llmProvider;
546
587
  const params = { systemPrompt: prompts.systemPrompt, userPrompt: prompts.userPrompt };
547
588
  let text;
548
- let reported;
549
- if (typeof provider.generateTextWithUsage === "function") {
550
- const result = await provider.generateTextWithUsage(params);
551
- if (!result || typeof result.text !== "string") {
552
- throw new TypeError("generateTextWithUsage() must resolve to { text: string, usage? }");
553
- }
554
- text = result.text;
555
- reported = validUsage(result.usage) ? result.usage : void 0;
556
- } else {
557
- text = await provider.generateText(params);
589
+ let record;
590
+ const reservation = ctx.meter?.reserve(promptEstimate);
591
+ try {
592
+ let reported;
593
+ if (typeof provider.generateTextWithUsage === "function") {
594
+ const result = await provider.generateTextWithUsage(params);
595
+ if (!result || typeof result.text !== "string") {
596
+ throw new TypeError("generateTextWithUsage() must resolve to { text: string, usage? }");
597
+ }
598
+ text = result.text;
599
+ reported = validUsage(result.usage) ? result.usage : void 0;
600
+ } else {
601
+ text = await provider.generateText(params);
602
+ }
603
+ record = reported ? { inputTokens: reported.inputTokens, outputTokens: reported.outputTokens, estimated: false } : { inputTokens: promptEstimate, outputTokens: estimateTokens(text), estimated: true };
604
+ } catch (err) {
605
+ if (ctx.meter && reservation) ctx.meter.release(reservation);
606
+ throw err;
558
607
  }
559
- const record = reported ? { inputTokens: reported.inputTokens, outputTokens: reported.outputTokens, estimated: false } : { inputTokens: promptEstimate, outputTokens: estimateTokens(text), estimated: true };
560
- ctx.meter?.record(record);
608
+ if (ctx.meter && reservation) ctx.meter.settle(reservation, record);
561
609
  if (options.config?.reportLlmUsage === true) {
562
610
  emitDiagnostic(options, {
563
611
  code: "llm_usage",
@@ -571,18 +619,23 @@ async function callLlm(options, ctx, prompts) {
571
619
  }
572
620
  async function callClassify(options, ctx, request) {
573
621
  const inputEstimate = estimateTokens(request.state) + estimateTokens(JSON.stringify(request.questions));
574
- if (ctx.meter && !ctx.meter.fits(inputEstimate)) {
575
- throw new WikiBudgetExhausted(inputEstimate, ctx.meter.remaining);
576
- }
577
622
  const provider = options.llmProvider;
578
- if (typeof provider.classify !== "function") {
579
- throw new TypeError("callClassify requires a provider with classify()");
580
- }
581
- const response = await provider.classify(request);
582
- const reported = validUsage(response?.usage) ? response.usage : void 0;
583
- const outputEstimate = estimateTokens(JSON.stringify(response?.answers ?? {}));
584
- const record = reported ? { inputTokens: reported.inputTokens, outputTokens: reported.outputTokens, estimated: false } : { inputTokens: inputEstimate, outputTokens: outputEstimate, estimated: true };
585
- ctx.meter?.record(record);
623
+ let response;
624
+ let record;
625
+ const reservation = ctx.meter?.reserve(inputEstimate, inputEstimate * CLASSIFY_HOLD_FACTOR);
626
+ try {
627
+ if (typeof provider.classify !== "function") {
628
+ throw new TypeError("callClassify requires a provider with classify()");
629
+ }
630
+ response = await provider.classify(request);
631
+ const reported = validUsage(response?.usage) ? response.usage : void 0;
632
+ const outputEstimate = estimateTokens(JSON.stringify(response?.answers ?? {}));
633
+ record = reported ? { inputTokens: reported.inputTokens, outputTokens: reported.outputTokens, estimated: false } : { inputTokens: inputEstimate, outputTokens: outputEstimate, estimated: true };
634
+ } catch (err) {
635
+ if (ctx.meter && reservation) ctx.meter.release(reservation);
636
+ throw err;
637
+ }
638
+ if (ctx.meter && reservation) ctx.meter.settle(reservation, record);
586
639
  if (options.config?.reportLlmUsage === true) {
587
640
  emitDiagnostic(options, {
588
641
  code: "llm_usage",
@@ -1757,8 +1810,14 @@ function isManifestRepresentable(manifest) {
1757
1810
  const slugs = manifest.node_types.map((n) => n.type);
1758
1811
  return slugs.length > 0 && slugs.length + 1 <= CLASSIFIER_MAX_CHOICES && !slugs.some((s) => isReservedAbstainSlug(s));
1759
1812
  }
1813
+ function typingEngages(site, provider, mode, manifest) {
1814
+ return site === "auto" && typeof provider.classify === "function" && mode !== "off" && isManifestRepresentable(manifest);
1815
+ }
1760
1816
  function canEngageWriteTyping(config, provider, mode, manifest) {
1761
- return resolveSystemOneTypeOnWrite(config) === "auto" && typeof provider.classify === "function" && mode !== "off" && isManifestRepresentable(manifest);
1817
+ return typingEngages(resolveSystemOneTypeOnWrite(config), provider, mode, manifest);
1818
+ }
1819
+ function canEngageIngestTyping(config, provider, mode, manifest) {
1820
+ return typingEngages(resolveSystemOneTypeOnIngest(config), provider, mode, manifest);
1762
1821
  }
1763
1822
  function buildTypingQuestion(manifest) {
1764
1823
  return {
@@ -1771,9 +1830,9 @@ function buildTypingQuestion(manifest) {
1771
1830
  function volunteeredTypeResolves(rawOkfType, manifest) {
1772
1831
  return typeof rawOkfType === "string" && resolveNodeTypeMatch(rawOkfType, manifest) !== null;
1773
1832
  }
1774
- async function classifyFactsForWrite(options, ctx, facts, manifest, floor) {
1833
+ async function classifyFactsForWrite(options, ctx, facts, manifest, floor, opts) {
1775
1834
  const question = buildTypingQuestion(manifest);
1776
- const rawConcurrency = options.config?.chunkConcurrency ?? 1;
1835
+ const rawConcurrency = opts?.concurrency ?? options.config?.chunkConcurrency ?? 1;
1777
1836
  const concurrency = Number.isFinite(rawConcurrency) && rawConcurrency >= 1 ? Math.floor(rawConcurrency) : 1;
1778
1837
  let stopped = false;
1779
1838
  return withConcurrency(
@@ -1804,6 +1863,10 @@ async function classifyFactsForWrite(options, ctx, facts, manifest, floor) {
1804
1863
  concurrency
1805
1864
  );
1806
1865
  }
1866
+ function toIngestCounters(c) {
1867
+ const { unattempted: _unattempted, ...rest } = c;
1868
+ return rest;
1869
+ }
1807
1870
  function emptyTypingCounters() {
1808
1871
  return { asked: 0, typed: 0, abstained: 0, lowConfidence: 0, invalid: 0, skipped: 0, unattempted: 0 };
1809
1872
  }
@@ -3772,7 +3835,9 @@ var IngestionService = class {
3772
3835
  }
3773
3836
  const { chunks: chunks2, truncated } = chunkText(params.documentChunk, maxChunkLength, chunkOverlap);
3774
3837
  if (chunks2.length === 0) return zeroChunkResult();
3775
- const ontologyContext = await this.ontologyService?.buildWritePromptContext(entityId, { engaged: false }) ?? null;
3838
+ const hoistedState = await this.ontologyService?.getEffectiveState(entityId) ?? { mode: "off", manifest: { node_types: [], edge_types: [] } };
3839
+ const engaged = this.ontologyService !== void 0 && canEngageIngestTyping(this.options.config, this.options.llmProvider, hoistedState.mode, hoistedState.manifest);
3840
+ const ontologyContext = await this.ontologyService?.buildWritePromptContext(entityId, { engaged }) ?? null;
3776
3841
  const { guidance, diagnostic } = PromptService.resolveGuidance(this.options.config, entityId);
3777
3842
  if (diagnostic) {
3778
3843
  emitDiagnostic(this.options, {
@@ -3928,16 +3993,42 @@ var IngestionService = class {
3928
3993
  chunks: chunks2.length
3929
3994
  });
3930
3995
  }
3996
+ const typing = { outcomes: /* @__PURE__ */ new Map(), counters: emptyTypingCounters() };
3997
+ let hashHeldElsewhere = false;
3998
+ if (engaged && failedChunks === 0 && onDuplicateHash === "ingest") {
3999
+ const holder = await this.sourceRefIndexRepo.findActiveByEntityAndHash(entityId, sourceHash);
4000
+ hashHeldElsewhere = holder !== null && holder !== sourceRef;
4001
+ }
4002
+ if (engaged && !hashHeldElsewhere) {
4003
+ const asked = [];
4004
+ for (const slot of orderedChunkFacts) {
4005
+ for (const fact of slot.facts) {
4006
+ if (!volunteeredTypeResolves(fact.okf_type, hoistedState.manifest)) asked.push(fact);
4007
+ }
4008
+ }
4009
+ const outcomes = await classifyFactsForWrite(
4010
+ this.options,
4011
+ { entityId, trigger: "call", operation: "ingest" },
4012
+ asked,
4013
+ hoistedState.manifest,
4014
+ resolveTypingMinConfidence(this.options.config),
4015
+ { concurrency: chunkConcurrency }
4016
+ );
4017
+ asked.forEach((fact, i) => {
4018
+ typing.outcomes.set(fact, outcomes[i]);
4019
+ tallyTypingOutcome(typing.counters, outcomes[i]);
4020
+ });
4021
+ }
3931
4022
  const insertedFacts = [];
3932
4023
  const deletedSourceFactIds = [];
3933
4024
  try {
3934
4025
  if (failedChunks === 0) {
3935
4026
  const fullResult = await this.db.withTransactionAsync(async (tx) => {
3936
- return await this.runFullUpsertGraph(entityId, sourceRef, sourceHash, orderedChunkFacts, tx, diagBuffer, factLedger);
4027
+ return await this.runFullUpsertGraph(entityId, sourceRef, sourceHash, orderedChunkFacts, tx, diagBuffer, factLedger, typing);
3937
4028
  });
3938
4029
  deletedSourceFactIds.push(...fullResult.deletedSourceFactIds);
3939
4030
  insertedFacts.push(...fullResult.insertedFacts);
3940
- if (ontologyContext !== null && insertedFacts.length === 0 && deletedSourceFactIds.length > 0) {
4031
+ if (hoistedState.mode !== "off" && insertedFacts.length === 0 && deletedSourceFactIds.length > 0) {
3941
4032
  diagBuffer.push({
3942
4033
  entityId,
3943
4034
  operation: "ingest",
@@ -3950,7 +4041,7 @@ var IngestionService = class {
3950
4041
  const partialResult = await this.db.withTransactionAsync(async (tx) => {
3951
4042
  const flat = [];
3952
4043
  for (const slot of orderedChunkFacts) flat.push(...slot.facts);
3953
- return await this.appendPartialFacts(entityId, sourceRef, flat, tx, diagBuffer, factLedger);
4044
+ return await this.appendPartialFacts(entityId, sourceRef, flat, tx, diagBuffer, factLedger, typing);
3954
4045
  });
3955
4046
  insertedFacts.push(...partialResult.insertedDescriptors);
3956
4047
  }
@@ -4002,6 +4093,7 @@ var IngestionService = class {
4002
4093
  failedChunks
4003
4094
  };
4004
4095
  if (failedChunks > 0) result.parseFailures = failures;
4096
+ if (engaged) result.typing = toIngestCounters(typing.counters);
4005
4097
  return result;
4006
4098
  } finally {
4007
4099
  releaseIngestLocks();
@@ -4211,10 +4303,11 @@ var IngestionService = class {
4211
4303
  * On the partial path the caller never invokes this method; the empty
4212
4304
  * arrays stay empty.
4213
4305
  */
4214
- async runFullUpsertGraph(entityId, sourceRef, sourceHash, orderedChunkFacts, tx, diagBuffer, factLedger = /* @__PURE__ */ new Map()) {
4306
+ async runFullUpsertGraph(entityId, sourceRef, sourceHash, orderedChunkFacts, tx, diagBuffer, factLedger = /* @__PURE__ */ new Map(), typing) {
4215
4307
  const deletedSourceFactIds = [];
4216
4308
  const insertedFacts = [];
4217
4309
  const nodeTrust = /* @__PURE__ */ new Map();
4310
+ const diagBase = { entityId, operation: "ingest", trigger: "call" };
4218
4311
  deletedSourceFactIds.push(...await this.entryRepo.findIdsBySource(entityId, sourceRef, null, tx, false));
4219
4312
  const titleIndex = /* @__PURE__ */ new Map();
4220
4313
  const existingFacts = await this.entryRepo.findRecentByEntityId(entityId, 500, tx, sourceRef);
@@ -4228,6 +4321,7 @@ var IngestionService = class {
4228
4321
  let { mode, manifest } = ontologyState;
4229
4322
  const hostNodes = [];
4230
4323
  const rawEdgeRequests = [];
4324
+ const typedAtDoor = [];
4231
4325
  const now = Date.now();
4232
4326
  for (const { facts, ontology_updates } of orderedChunkFacts) {
4233
4327
  if (mode === "emergent" && ontology_updates && this.ontologyService) {
@@ -4247,14 +4341,15 @@ var IngestionService = class {
4247
4341
  for (const fact of facts) {
4248
4342
  const ontologyFact = fact;
4249
4343
  const id = generateId("fact_");
4250
- const validationDrops = [];
4251
- const normalized = this.ontologyService?.validateAndNormalizeFact(ontologyFact, manifest, { strict: false, drops: validationDrops }) ?? { okf_type: null, edges: [] };
4252
- for (const drop of validationDrops) {
4344
+ const outcome = typing?.outcomes.get(fact);
4345
+ const slot = normalizeForWrite(this.ontologyService, ontologyFact, manifest, mode, outcome, diagBase, id);
4346
+ const normalized = slot.normalized;
4347
+ for (const drop of slot.drops) {
4253
4348
  diagBuffer.push(edgeDropDiagnostic(drop, { entityId, operation: "ingest", trigger: "call", sourceRef, factId: id }));
4254
4349
  }
4255
- hostNodes.push({
4350
+ const hostNode = {
4256
4351
  id,
4257
- type: ontologyFact.okf_type ?? "",
4352
+ type: "",
4258
4353
  title: fact.title,
4259
4354
  body: fact.body,
4260
4355
  // Forward the LLM-extracted tags/confidence through the
@@ -4266,18 +4361,20 @@ var IngestionService = class {
4266
4361
  // 'certain' as documented.
4267
4362
  tags: fact.tags,
4268
4363
  confidence: fact.confidence
4269
- });
4364
+ };
4365
+ hostNodes.push(hostNode);
4366
+ typedAtDoor.push({ node: hostNode, fact: ontologyFact, id, outcome, slotType: normalized.okf_type });
4270
4367
  const locator = factLedger.get(fact);
4271
4368
  if (locator?.verdict) {
4272
- const outcome = groundingOutcome(locator.verdict, now);
4273
- nodeTrust.set(id, outcome.trust);
4274
- if (outcome.diagnostic) {
4369
+ const outcome2 = groundingOutcome(locator.verdict, now);
4370
+ nodeTrust.set(id, outcome2.trust);
4371
+ if (outcome2.diagnostic) {
4275
4372
  diagBuffer.push({
4276
4373
  entityId,
4277
4374
  operation: "ingest",
4278
4375
  trigger: "call",
4279
- code: outcome.diagnostic.code,
4280
- detail: { factId: id, sourceRef, chunkIndex: locator.chunkIndex, itemIndex: locator.itemIndex, reason: outcome.diagnostic.reason }
4376
+ code: outcome2.diagnostic.code,
4377
+ detail: { factId: id, sourceRef, chunkIndex: locator.chunkIndex, itemIndex: locator.itemIndex, reason: outcome2.diagnostic.reason }
4281
4378
  });
4282
4379
  }
4283
4380
  }
@@ -4288,6 +4385,18 @@ var IngestionService = class {
4288
4385
  }
4289
4386
  }
4290
4387
  }
4388
+ const doorReceipts = [];
4389
+ for (const { node, fact, id, outcome, slotType } of typedAtDoor) {
4390
+ const final = normalizeForWrite(this.ontologyService, fact, manifest, mode, outcome, diagBase, id);
4391
+ for (const receipt of final.receipts) {
4392
+ doorReceipts.push({ ...receipt, detail: { ...receipt.detail, sourceRef } });
4393
+ }
4394
+ node.type = final.normalized.okf_type ?? "";
4395
+ if (final.typedByClassifier && typing) typing.counters.typed++;
4396
+ if (outcome?.kind === "accepted" && final.normalized.okf_type !== slotType) {
4397
+ titleIndex.set(normalizeTitleKey(fact.title), { id, okf_type: final.normalized.okf_type });
4398
+ }
4399
+ }
4291
4400
  const hostEdges = [];
4292
4401
  for (const req of rawEdgeRequests) {
4293
4402
  const resolveDrops = [];
@@ -4308,6 +4417,7 @@ var IngestionService = class {
4308
4417
  hostEdges.push({ type: e.edge_type, sourceId: e.source_id, targetId: e.target_id });
4309
4418
  }
4310
4419
  }
4420
+ for (const receipt of doorReceipts) diagBuffer.push(receipt);
4311
4421
  await this.upsertGraphCore(
4312
4422
  entityId,
4313
4423
  { sourceRef, sourceHash, nodes: hostNodes, edges: hostEdges },
@@ -4336,7 +4446,7 @@ var IngestionService = class {
4336
4446
  * Runs INSIDE the caller's `tx`. Does not open a nested transaction.
4337
4447
  * Returns `{ inserted, skippedDuplicate }` for observability.
4338
4448
  */
4339
- async appendPartialFacts(entityId, sourceRef, dedupedFacts, tx, diagBuffer, factLedger = /* @__PURE__ */ new Map()) {
4449
+ async appendPartialFacts(entityId, sourceRef, dedupedFacts, tx, diagBuffer, factLedger = /* @__PURE__ */ new Map(), typing) {
4340
4450
  const liveIds = await this.entryRepo.findIdsBySource(entityId, sourceRef, null, tx, false);
4341
4451
  const liveFacts = liveIds.length === 0 ? [] : await this.entryRepo.findByIds(liveIds, void 0, tx);
4342
4452
  const liveTitles = new Set(liveFacts.map((f) => normalizeTitleKey(f.title)));
@@ -4347,6 +4457,7 @@ var IngestionService = class {
4347
4457
  for (const f of indexedFacts) {
4348
4458
  titleIndex.set(normalizeTitleKey(f.title), { id: f.id, okf_type: f.okf_type ?? null });
4349
4459
  }
4460
+ const diagBase = { entityId, operation: "ingest", trigger: "call" };
4350
4461
  const pendingEdges = [];
4351
4462
  let inserted = 0;
4352
4463
  let skippedDuplicate = 0;
@@ -4373,22 +4484,22 @@ var IngestionService = class {
4373
4484
  });
4374
4485
  }
4375
4486
  const ontologyFact = fact;
4376
- const validationDrops = [];
4377
- const normalized = this.ontologyService?.validateAndNormalizeFact(ontologyFact, manifest, { strict: false, drops: validationDrops }) ?? { okf_type: null, edges: [] };
4487
+ const { normalized, drops: validationDrops, receipts, typedByClassifier } = normalizeForWrite(
4488
+ this.ontologyService,
4489
+ ontologyFact,
4490
+ manifest,
4491
+ mode,
4492
+ typing?.outcomes.get(fact),
4493
+ diagBase,
4494
+ id
4495
+ );
4378
4496
  for (const drop of validationDrops) {
4379
4497
  diagBuffer.push(edgeDropDiagnostic(drop, { entityId, operation: "ingest", trigger: "call", sourceRef, factId: id }));
4380
4498
  }
4381
- if (shouldEmitOntologyReceipt(mode)) {
4382
- for (const receipt of nodeTypeReceipts(
4383
- { entityId, operation: "ingest", trigger: "call" },
4384
- id,
4385
- ontologyFact.okf_type ?? "",
4386
- normalized.okf_type,
4387
- normalized.match
4388
- )) {
4389
- diagBuffer.push({ ...receipt, detail: { ...receipt.detail, sourceRef } });
4390
- }
4499
+ for (const receipt of receipts) {
4500
+ diagBuffer.push({ ...receipt, detail: { ...receipt.detail, sourceRef } });
4391
4501
  }
4502
+ if (typedByClassifier && typing) typing.counters.typed++;
4392
4503
  if (normalized.edges.length > 0) {
4393
4504
  pendingEdges.push({ sourceId: id, sourceType: normalized.okf_type, edges: normalized.edges });
4394
4505
  }
@@ -12393,6 +12504,6 @@ var WriteService = class {
12393
12504
  }
12394
12505
  };
12395
12506
 
12396
- export { BaseRepository, CLASSIFIER_MAX_CHOICES, CURRENT_SCHEMA_VERSION, CheckpointIncompleteError, DEFAULT_CHUNK_OVERLAP, DEFAULT_MAX_CHUNK_LENGTH, DEFAULT_MAX_EMBED_CHARS, DEFAULT_TYPING_MIN_CONFIDENCE, DiagnosticBuffer, EMBED_CHARS_CEILING, EdgeRepository, EmbeddingService, EraseStepError, FTS5_DRAIN_CHUNK, FTS5_REBUILD_SNAPSHOT_KEY, FTS5_REBUILD_WM_KEY, FTS5_RECLAIM_MERGE_PAGES, FTS5_RETIRED_COUNTER_KEY, FTS5_RETIRED_TABLES_KEY, FTS5_STATE_KEY, FTS5_SWEEP_CURSOR_KEY, HEAL_ANCHORS_PER_CANDIDATE, HEAL_BATCH_SIZE, HEAL_MAX_FACT_BODY_CHARS_L3, HEAL_MAX_TASKS, HEAL_RECHECK_MS, HOOK_TIMEOUT_MARKER, ImportExportService, IngestionService, JobManager, MAX_EMBED_ATTEMPTS, MIGRATIONS, MaintenanceService, MetadataRepository, ONTOLOGY_ABSTAIN_SENTINEL, ONTOLOGY_BACKFILL_BATCH_SIZE, ONTOLOGY_BACKFILL_MAX_PROMPT_CHARS, ONTOLOGY_BACKFILL_RECHECK_MS, ONTOLOGY_BACKFILL_SYSTEM_PROMPT, PromptService, PrunePartialFailureError, RetrievalService, SearchService, SourceStoreService, TemporalService, UnavailableIndexStrategy, UsageMeter, VectorRemovalRepository, VectorRemovalService, WikiBusyError, WikiDraftNotFound, WikiDuplicateHashError, WikiExternalDeletionError, WikiGraphNodeOwnershipConflict, WikiIngestEmptyError, WikiInvalidReadOptions, WikiMigrationRequiredError, WikiParseError, WikiSearchUnavailableError, WikiSourceRefHashCollision, WikiStrictOntologyViolation, WikiSupersedeError, WikiTransactionError, WriteService, __privateAdd, __privateGet, __privateSet, assertEntityId, assertEpochMs, canEngageWriteTyping, chunkText, configureRandomSource, createEntriesDeletedIndex, createLegacySourceTypeIndex, createdAtValue, detectSchemaVersion, drainChunkSql, drainHiSql, edgeTripleAllowed, emitDiagnostic, emptyManifest, entityDrainChunkSql, entityDrainHiSql, entitySummaryMetaKey, extractSqliteCode, factTokenCost, fts5LedgerDropSql, fts5PendingIndexesDdl, fts5TablesDdl, fts5TriggerNames, fts5TriggersDdl, generateId, idDrainChunkSql, idReindexChunkSql, isLiveAt, isReservedAbstainSlug, isRetiredTableName, isUsableDate, isWikiSearchUnavailableError, liveAtSql, nodeTypeReceipts, normalizeSourceHash, normalizeSourceRef, normalizeTitleKey, packFactsByBudget, parseEmbedding, parseJsonArray, parseJsonObject, parseStoredDerivedEvents, parseStoredSourcePointer, passageFtsTablesDdl, passageFtsTriggerNames, passageFtsTriggersDdl, probePendingWork, readRebuildProgress, reanchorRebuildFingerprint, resolveContextBudget, resolveContextBudgetOrThrow, resolveDefaultChunkLength, resolveEdgeDefinitions, resolveEdgesMinConfidence, resolveGrounding, resolveHealScreenMinConfidence, resolveLibrarianStrategy, resolveMaxPromptChars, resolveNodeType, resolveNodeTypeMatch, resolveResolveMinConfidence, resolveSystemOneEdges, resolveSystemOneHealScreen, resolveSystemOneResolve, resolveSystemOneTypeOnWrite, resolveSystemOneTyping, resolveTypingMinConfidence, retiredTableName, runSourceRefNormalize, safeSlice, serializeDerivedEvents, serializeSourcePointer, setupDatabase, shouldEmitOntologyReceipt, sweepChunkSql, sweepHiSql, typeSatisfies, validUsage, validateDerivedEventsValue, validateInlineEdges, validateManifest, validateSourcePointerValue, warnChangedDefaultsOnce, warnOnce, windowChunkSql, windowHiSql, writeNormalizeStamp, writeRebuildStart };
12397
- //# sourceMappingURL=chunk-7DBDJBN3.mjs.map
12398
- //# sourceMappingURL=chunk-7DBDJBN3.mjs.map
12507
+ export { BaseRepository, CLASSIFIER_MAX_CHOICES, CURRENT_SCHEMA_VERSION, CheckpointIncompleteError, DEFAULT_CHUNK_OVERLAP, DEFAULT_MAX_CHUNK_LENGTH, DEFAULT_MAX_EMBED_CHARS, DEFAULT_TYPING_MIN_CONFIDENCE, DiagnosticBuffer, EMBED_CHARS_CEILING, EdgeRepository, EmbeddingService, EraseStepError, FTS5_DRAIN_CHUNK, FTS5_REBUILD_SNAPSHOT_KEY, FTS5_REBUILD_WM_KEY, FTS5_RECLAIM_MERGE_PAGES, FTS5_RETIRED_COUNTER_KEY, FTS5_RETIRED_TABLES_KEY, FTS5_STATE_KEY, FTS5_SWEEP_CURSOR_KEY, HEAL_ANCHORS_PER_CANDIDATE, HEAL_BATCH_SIZE, HEAL_MAX_FACT_BODY_CHARS_L3, HEAL_MAX_TASKS, HEAL_RECHECK_MS, HOOK_TIMEOUT_MARKER, ImportExportService, IngestionService, JobManager, MAX_EMBED_ATTEMPTS, MIGRATIONS, MaintenanceService, MetadataRepository, ONTOLOGY_ABSTAIN_SENTINEL, ONTOLOGY_BACKFILL_BATCH_SIZE, ONTOLOGY_BACKFILL_MAX_PROMPT_CHARS, ONTOLOGY_BACKFILL_RECHECK_MS, ONTOLOGY_BACKFILL_SYSTEM_PROMPT, PromptService, PrunePartialFailureError, RetrievalService, SearchService, SourceStoreService, TemporalService, UnavailableIndexStrategy, UsageMeter, VectorRemovalRepository, VectorRemovalService, WikiBusyError, WikiDraftNotFound, WikiDuplicateHashError, WikiExternalDeletionError, WikiGraphNodeOwnershipConflict, WikiIngestEmptyError, WikiInvalidReadOptions, WikiMigrationRequiredError, WikiParseError, WikiSearchUnavailableError, WikiSourceRefHashCollision, WikiStrictOntologyViolation, WikiSupersedeError, WikiTransactionError, WriteService, __privateAdd, __privateGet, __privateSet, assertEntityId, assertEpochMs, canEngageIngestTyping, canEngageWriteTyping, chunkText, configureRandomSource, createEntriesDeletedIndex, createLegacySourceTypeIndex, createdAtValue, detectSchemaVersion, drainChunkSql, drainHiSql, edgeTripleAllowed, emitDiagnostic, emptyManifest, entityDrainChunkSql, entityDrainHiSql, entitySummaryMetaKey, extractSqliteCode, factTokenCost, fts5LedgerDropSql, fts5PendingIndexesDdl, fts5TablesDdl, fts5TriggerNames, fts5TriggersDdl, generateId, idDrainChunkSql, idReindexChunkSql, isLiveAt, isReservedAbstainSlug, isRetiredTableName, isUsableDate, isWikiSearchUnavailableError, liveAtSql, nodeTypeReceipts, normalizeSourceHash, normalizeSourceRef, normalizeTitleKey, packFactsByBudget, parseEmbedding, parseJsonArray, parseJsonObject, parseStoredDerivedEvents, parseStoredSourcePointer, passageFtsTablesDdl, passageFtsTriggerNames, passageFtsTriggersDdl, probePendingWork, readRebuildProgress, reanchorRebuildFingerprint, resolveContextBudget, resolveContextBudgetOrThrow, resolveDefaultChunkLength, resolveEdgeDefinitions, resolveEdgesMinConfidence, resolveGrounding, resolveHealScreenMinConfidence, resolveLibrarianStrategy, resolveMaxPromptChars, resolveNodeType, resolveNodeTypeMatch, resolveResolveMinConfidence, resolveSystemOneEdges, resolveSystemOneHealScreen, resolveSystemOneResolve, resolveSystemOneTypeOnIngest, resolveSystemOneTypeOnWrite, resolveSystemOneTyping, resolveTypingMinConfidence, retiredTableName, runSourceRefNormalize, safeSlice, serializeDerivedEvents, serializeSourcePointer, setupDatabase, shouldEmitOntologyReceipt, sweepChunkSql, sweepHiSql, typeSatisfies, validUsage, validateDerivedEventsValue, validateInlineEdges, validateManifest, validateSourcePointerValue, warnChangedDefaultsOnce, warnOnce, windowChunkSql, windowHiSql, writeNormalizeStamp, writeRebuildStart };
12508
+ //# sourceMappingURL=chunk-QRGFHMFR.mjs.map
12509
+ //# sourceMappingURL=chunk-QRGFHMFR.mjs.map