@equationalapplications/core-llm-wiki 9.18.1 → 9.20.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-HH2BH2HS.mjs → chunk-PLZNFRMM.mjs} +118 -8
- package/dist/chunk-PLZNFRMM.mjs.map +1 -0
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +123 -8
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +9 -4
- package/dist/index.mjs.map +1 -1
- package/dist/{testing-CI0n5qQk.d.mts → testing-CnXg2aRj.d.mts} +24 -6
- package/dist/{testing-CI0n5qQk.d.ts → testing-CnXg2aRj.d.ts} +24 -6
- package/dist/testing.d.mts +1 -1
- package/dist/testing.d.ts +1 -1
- package/dist/testing.js +34 -0
- package/dist/testing.js.map +1 -1
- package/dist/testing.mjs +1 -1
- package/package.json +2 -2
- package/dist/chunk-HH2BH2HS.mjs.map +0 -1
|
@@ -311,6 +311,8 @@ var SEVERITY = {
|
|
|
311
311
|
external_deletion_pending: "warn",
|
|
312
312
|
supersede_scheduled_end_replaced: "info",
|
|
313
313
|
external_deletion_discarded: "warn",
|
|
314
|
+
vector_removals_backlog: "warn",
|
|
315
|
+
vector_removals_trim_failed: "warn",
|
|
314
316
|
guidance_too_long: "warn",
|
|
315
317
|
guidance_resolver_failed: "warn",
|
|
316
318
|
source_pointer_unresolved: "warn",
|
|
@@ -371,6 +373,8 @@ var MESSAGE = {
|
|
|
371
373
|
supersede_scheduled_end_replaced: "A supersede replaced a scheduled end date on the old fact; the prior end is kept in prior_valid_to and reopen() can restore it.",
|
|
372
374
|
external_deletion_pending: "Removals owed to the external vector index are still pending.",
|
|
373
375
|
external_deletion_discarded: "Pending external vector removals were discarded because forceDeleteIgnoreRankerHook is set.",
|
|
376
|
+
vector_removals_backlog: "Pending external vector removals are accumulating faster than the host drains them.",
|
|
377
|
+
vector_removals_trim_failed: "The prune-time check of pending external vector removals failed; it will retry on the next prune pass.",
|
|
374
378
|
guidance_too_long: "The configured guidance exceeded the length cap and was not sent for this pass.",
|
|
375
379
|
guidance_resolver_failed: "The per-entity guidance resolver failed; its value was not used for this pass.",
|
|
376
380
|
source_pointer_unresolved: "A stored librarian fact carries no source pointer because the model answer could not yield one, or the librarian merged such an unattributed candidate into this fact in place (its derived_events list was not extended).",
|
|
@@ -4991,6 +4995,40 @@ var VectorRemovalRepository = class extends BaseRepository {
|
|
|
4991
4995
|
);
|
|
4992
4996
|
return { count: row?.c ?? 0, oldestEnqueuedAt: row?.o ?? null, maxAttempts: row?.m ?? 0 };
|
|
4993
4997
|
}
|
|
4998
|
+
/**
|
|
4999
|
+
* Trim an entity's pending rows down toward `cap`, deleting at most `chunk`
|
|
5000
|
+
* of the oldest per call. Uses the lower of the two cutoffs (cap overflow,
|
|
5001
|
+
* chunk bound); a no-op when at or under cap or when the external-index
|
|
5002
|
+
* marker is set. Without `tx` it opens its own single short transaction.
|
|
5003
|
+
* Returns the number of rows deleted.
|
|
5004
|
+
*/
|
|
5005
|
+
async trimPendingOverflow(entityId, cap, chunk, tx) {
|
|
5006
|
+
if (chunk > cap) throw new Error(`trimPendingOverflow: chunk (${chunk}) must be <= cap (${cap})`);
|
|
5007
|
+
const run = async (ex) => {
|
|
5008
|
+
const t = `${this.prefix}vector_removals`;
|
|
5009
|
+
const capRow = await ex.getFirstAsync(
|
|
5010
|
+
`SELECT seq FROM ${t} WHERE entity_id = ? AND confirmed_at IS NULL
|
|
5011
|
+
ORDER BY seq DESC LIMIT 1 OFFSET ?`,
|
|
5012
|
+
[entityId, cap]
|
|
5013
|
+
);
|
|
5014
|
+
if (!capRow) return 0;
|
|
5015
|
+
const chunkRow = await ex.getFirstAsync(
|
|
5016
|
+
`SELECT seq FROM ${t} WHERE entity_id = ? AND confirmed_at IS NULL
|
|
5017
|
+
ORDER BY seq ASC LIMIT 1 OFFSET ?`,
|
|
5018
|
+
[entityId, chunk - 1]
|
|
5019
|
+
);
|
|
5020
|
+
const cuts = [capRow.seq, chunkRow?.seq].filter((x) => x != null);
|
|
5021
|
+
const cutoff = Math.min(...cuts);
|
|
5022
|
+
const r = await ex.runAsync(
|
|
5023
|
+
`DELETE FROM ${t}
|
|
5024
|
+
WHERE entity_id = ? AND confirmed_at IS NULL AND seq <= ?
|
|
5025
|
+
AND NOT EXISTS (SELECT 1 FROM ${this.prefix}meta WHERE key = 'external_index_in_use' AND value = '1')`,
|
|
5026
|
+
[entityId, cutoff]
|
|
5027
|
+
);
|
|
5028
|
+
return r.changes;
|
|
5029
|
+
};
|
|
5030
|
+
return tx ? run(tx) : this.db.withTransactionAsync(run);
|
|
5031
|
+
}
|
|
4994
5032
|
async entitiesWithPending() {
|
|
4995
5033
|
const rows = await this.db.getAllAsync(
|
|
4996
5034
|
`SELECT DISTINCT entity_id FROM ${this.prefix}vector_removals
|
|
@@ -7707,6 +7745,9 @@ async function runLibrarianStrategy(deps, ctx) {
|
|
|
7707
7745
|
|
|
7708
7746
|
// src/services/MaintenanceService.ts
|
|
7709
7747
|
var CHAIN_TRUNCATED_NOTICE = `includeChain walk stopped at the depth cap (${HISTORY_MAX_DEPTH} links per direction); the chain is longer than the ids listed. Run forget again on a remaining chain id to continue.`;
|
|
7748
|
+
var MAX_PENDING_LEDGER_ROWS = 1e4;
|
|
7749
|
+
var WARN_PENDING_LEDGER_ROWS = 500;
|
|
7750
|
+
var TRIM_CHUNK_ROWS = 5e3;
|
|
7710
7751
|
var ONTOLOGY_BACKFILL_BATCH_SIZE = 25;
|
|
7711
7752
|
var ONTOLOGY_BACKFILL_RECHECK_MS = 7 * 24 * 60 * 60 * 1e3;
|
|
7712
7753
|
var HEAL_ANCHOR_SEARCH_OVERFETCH = 4;
|
|
@@ -7951,6 +7992,33 @@ var _MaintenanceService = class _MaintenanceService {
|
|
|
7951
7992
|
}
|
|
7952
7993
|
}
|
|
7953
7994
|
}
|
|
7995
|
+
if (gate === "none" && this.vectorRemoval && this.vectorRemovalRepo) {
|
|
7996
|
+
try {
|
|
7997
|
+
if (await this.vectorRemoval.ledgerPresent()) {
|
|
7998
|
+
if (!await this.vectorRemoval.externalIndexInUse()) {
|
|
7999
|
+
await this.vectorRemovalRepo.trimPendingOverflow(entityId, MAX_PENDING_LEDGER_ROWS, TRIM_CHUNK_ROWS);
|
|
8000
|
+
} else if (owner === "host") {
|
|
8001
|
+
const st = await this.vectorRemovalRepo.pendingStats(entityId);
|
|
8002
|
+
if (st.count > WARN_PENDING_LEDGER_ROWS) {
|
|
8003
|
+
emitDiagnostic(this.options, {
|
|
8004
|
+
code: "vector_removals_backlog",
|
|
8005
|
+
operation: "prune",
|
|
8006
|
+
trigger: "call",
|
|
8007
|
+
entityId,
|
|
8008
|
+
detail: {
|
|
8009
|
+
count: st.count,
|
|
8010
|
+
...st.oldestEnqueuedAt !== null ? { oldestEnqueuedAt: st.oldestEnqueuedAt } : {},
|
|
8011
|
+
maxAttempts: st.maxAttempts
|
|
8012
|
+
}
|
|
8013
|
+
});
|
|
8014
|
+
}
|
|
8015
|
+
}
|
|
8016
|
+
}
|
|
8017
|
+
} catch (err) {
|
|
8018
|
+
const reason = err instanceof Error ? typeof err.code === "string" ? err.code : err.name : "unknown";
|
|
8019
|
+
emitDiagnostic(this.options, { code: "vector_removals_trim_failed", operation: "prune", trigger: "call", entityId, detail: { reason } });
|
|
8020
|
+
}
|
|
8021
|
+
}
|
|
7954
8022
|
let vacuumCheckpointErr;
|
|
7955
8023
|
if (vacuum) {
|
|
7956
8024
|
try {
|
|
@@ -10236,14 +10304,17 @@ var DEFAULT_MAX_TOTAL_CHARS = 5e6;
|
|
|
10236
10304
|
function limitOr(value, fallback) {
|
|
10237
10305
|
return typeof value === "number" && Number.isFinite(value) && value >= 0 ? Math.floor(value) : fallback;
|
|
10238
10306
|
}
|
|
10239
|
-
function listStoredSourcesSql(prefix) {
|
|
10307
|
+
function listStoredSourcesSql(prefix, paging) {
|
|
10308
|
+
const cursorPredicate = paging?.hasCursor ? "\n AND d.source_ref > ?" : "";
|
|
10309
|
+
const limitClause = paging ? "\n LIMIT ?" : "";
|
|
10240
10310
|
return `SELECT d.source_ref, d.source_hash, d.char_count, d.created_at,
|
|
10241
10311
|
(SELECT COUNT(*) FROM ${prefix}source_passages p
|
|
10242
10312
|
WHERE p.document_id = d.id AND +p.entity_id = d.entity_id) AS passage_count
|
|
10243
10313
|
FROM ${prefix}source_documents d
|
|
10244
|
-
WHERE d.entity_id =
|
|
10245
|
-
ORDER BY d.source_ref COLLATE BINARY`;
|
|
10314
|
+
WHERE d.entity_id = ?${cursorPredicate}
|
|
10315
|
+
ORDER BY d.source_ref COLLATE BINARY${limitClause}`;
|
|
10246
10316
|
}
|
|
10317
|
+
var DEFAULT_LIST_PAGE_LIMIT = 200;
|
|
10247
10318
|
var SourceStoreService = class {
|
|
10248
10319
|
constructor(db, prefix, options, jobManager) {
|
|
10249
10320
|
this.db = db;
|
|
@@ -10320,9 +10391,48 @@ var SourceStoreService = class {
|
|
|
10320
10391
|
storedAt: Number(row.created_at)
|
|
10321
10392
|
};
|
|
10322
10393
|
}
|
|
10323
|
-
/** Spec §
|
|
10324
|
-
|
|
10325
|
-
|
|
10394
|
+
/** Spec source-store-paging §2: point probe — true iff the document row exists for the
|
|
10395
|
+
* normalized ref. Plain read, no write lock, hash-blind: the UNIQUE index on
|
|
10396
|
+
* (entity_id, source_ref) makes one row per pair the only possible state, so a
|
|
10397
|
+
* re-stored changed copy is still stored. Blank/non-string refs return false (no throw). */
|
|
10398
|
+
async hasStoredSource(entityId, sourceRef) {
|
|
10399
|
+
const ref = normalizeSourceRef(sourceRef);
|
|
10400
|
+
if (!ref) return false;
|
|
10401
|
+
const row = await this.db.getFirstAsync(
|
|
10402
|
+
`SELECT id FROM ${this.prefix}source_documents WHERE entity_id = ? AND source_ref = ?`,
|
|
10403
|
+
[entityId, ref]
|
|
10404
|
+
);
|
|
10405
|
+
return row !== void 0 && row !== null;
|
|
10406
|
+
}
|
|
10407
|
+
/** Spec §4/§7: full store listing, including sources stored with no ingest.
|
|
10408
|
+
* With `opts` (spec source-store §7): keyset paging in source_ref
|
|
10409
|
+
* COLLATE BINARY order; validation order opts shape → afterSourceRef →
|
|
10410
|
+
* limit, each a named throw before any query. `Number.isSafeInteger`
|
|
10411
|
+
* subsumes 0/negative/NaN/Infinity/non-number limits. */
|
|
10412
|
+
async listStoredSources(entityId, opts) {
|
|
10413
|
+
let cursor;
|
|
10414
|
+
let limit;
|
|
10415
|
+
if (opts !== void 0) {
|
|
10416
|
+
if (opts === null || typeof opts !== "object" || Array.isArray(opts)) {
|
|
10417
|
+
throw new Error("Invalid opts");
|
|
10418
|
+
}
|
|
10419
|
+
if (opts.afterSourceRef !== void 0) {
|
|
10420
|
+
const normalized = normalizeSourceRef(opts.afterSourceRef);
|
|
10421
|
+
if (!normalized) throw new Error("Invalid afterSourceRef");
|
|
10422
|
+
cursor = normalized;
|
|
10423
|
+
}
|
|
10424
|
+
if (opts.limit !== void 0) {
|
|
10425
|
+
const raw = opts.limit;
|
|
10426
|
+
if (typeof raw !== "number" || !Number.isSafeInteger(raw) || raw < 1) {
|
|
10427
|
+
throw new Error("Invalid limit");
|
|
10428
|
+
}
|
|
10429
|
+
limit = raw;
|
|
10430
|
+
}
|
|
10431
|
+
}
|
|
10432
|
+
const paging = cursor !== void 0 || limit !== void 0;
|
|
10433
|
+
const sql = listStoredSourcesSql(this.prefix, paging ? { hasCursor: cursor !== void 0 } : void 0);
|
|
10434
|
+
const bindings = paging ? cursor !== void 0 ? [entityId, cursor, limit ?? DEFAULT_LIST_PAGE_LIMIT] : [entityId, limit ?? DEFAULT_LIST_PAGE_LIMIT] : [entityId];
|
|
10435
|
+
const rows = await this.db.getAllAsync(sql, bindings);
|
|
10326
10436
|
return rows.map((r) => ({
|
|
10327
10437
|
sourceRef: r.source_ref,
|
|
10328
10438
|
sourceHash: r.source_hash,
|
|
@@ -12578,5 +12688,5 @@ var WriteService = class {
|
|
|
12578
12688
|
};
|
|
12579
12689
|
|
|
12580
12690
|
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, createEventsForgottenIndex, 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 };
|
|
12581
|
-
//# sourceMappingURL=chunk-
|
|
12582
|
-
//# sourceMappingURL=chunk-
|
|
12691
|
+
//# sourceMappingURL=chunk-PLZNFRMM.mjs.map
|
|
12692
|
+
//# sourceMappingURL=chunk-PLZNFRMM.mjs.map
|