@equationalapplications/core-llm-wiki 9.14.1 → 9.15.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-JX7VMQ55.mjs → chunk-JCMA74YK.mjs} +3382 -3159
- package/dist/chunk-JCMA74YK.mjs.map +1 -0
- package/dist/index.d.mts +10 -3
- package/dist/index.d.ts +10 -3
- package/dist/index.js +1220 -949
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +53 -6
- package/dist/index.mjs.map +1 -1
- package/dist/{testing-BclOvn3q.d.mts → testing-ziEQOLjo.d.mts} +97 -29
- package/dist/{testing-BclOvn3q.d.ts → testing-ziEQOLjo.d.ts} +97 -29
- package/dist/testing.d.mts +1 -1
- package/dist/testing.d.ts +1 -1
- package/dist/testing.js +295 -61
- package/dist/testing.js.map +1 -1
- package/dist/testing.mjs +1 -1
- package/package.json +2 -2
- package/dist/chunk-JX7VMQ55.mjs.map +0 -1
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { BaseRepository, WikiGraphNodeOwnershipConflict, serializeSourcePointer, parseStoredSourcePointer, parseJsonObject, parseJsonArray, liveAtSql, reanchorRebuildFingerprint, __privateAdd, warnChangedDefaultsOnce, resolveContextBudgetOrThrow, EdgeRepository, MetadataRepository, EmbeddingService, VectorRemovalRepository, VectorRemovalService, SearchService, TemporalService, JobManager, PromptService, resolveGrounding, IngestionService, MaintenanceService, ImportExportService, RetrievalService, SourceStoreService, WriteService, __privateGet, __privateSet, createLegacySourceTypeIndex, writeNormalizeStamp, CURRENT_SCHEMA_VERSION, detectSchemaVersion, MIGRATIONS, runSourceRefNormalize, emitDiagnostic, normalizeSourceRef, normalizeSourceHash, resolveLibrarianStrategy, entitySummaryMetaKey, WikiSourceRefHashCollision, DiagnosticBuffer, validateManifest, isReservedAbstainSlug, ONTOLOGY_ABSTAIN_SENTINEL, WikiDraftNotFound, generateId, emptyManifest, resolveNodeTypeMatch, WikiStrictOntologyViolation, validateInlineEdges, resolveEdgeDefinitions, typeSatisfies, normalizeTitleKey, edgeTripleAllowed, resolveNodeType, shouldEmitOntologyReceipt, nodeTypeReceipts, MAX_EMBED_ATTEMPTS, UsageMeter, isWikiSearchUnavailableError, WikiBusyError, WikiInvalidReadOptions, isLiveAt, packFactsByBudget, factTokenCost, probePendingWork, WikiMigrationRequiredError, setupDatabase, UnavailableIndexStrategy, createdAtValue, isUsableDate, validateSourcePointerValue, assertEntityId, assertEpochMs, passageFtsTriggerNames, FTS5_STATE_KEY, fts5LedgerDropSql, passageFtsTablesDdl, passageFtsTriggersDdl, fts5TablesDdl, fts5PendingIndexesDdl, fts5TriggersDdl, writeRebuildStart, FTS5_RETIRED_COUNTER_KEY, retiredTableName, FTS5_RETIRED_TABLES_KEY, isRetiredTableName, idReindexChunkSql, readRebuildProgress, FTS5_DRAIN_CHUNK, FTS5_RECLAIM_MERGE_PAGES, windowHiSql, windowChunkSql, FTS5_REBUILD_WM_KEY, sweepHiSql, sweepChunkSql, FTS5_SWEEP_CURSOR_KEY, drainHiSql, drainChunkSql, FTS5_REBUILD_SNAPSHOT_KEY, idDrainChunkSql, entityDrainHiSql, entityDrainChunkSql, fts5TriggerNames, extractSqliteCode, WikiTransactionError } from './chunk-
|
|
2
|
-
export { CLASSIFIER_MAX_CHOICES, CheckpointIncompleteError, DEFAULT_CHUNK_OVERLAP, DEFAULT_MAX_CHUNK_LENGTH, DEFAULT_MAX_EMBED_CHARS, DEFAULT_TYPING_MIN_CONFIDENCE, EMBED_CHARS_CEILING, EraseStepError, HEAL_ANCHORS_PER_CANDIDATE, HEAL_BATCH_SIZE, HEAL_MAX_FACT_BODY_CHARS_L3, HEAL_MAX_TASKS, HEAL_RECHECK_MS, HOOK_TIMEOUT_MARKER, ONTOLOGY_ABSTAIN_SENTINEL, ONTOLOGY_BACKFILL_BATCH_SIZE, ONTOLOGY_BACKFILL_MAX_PROMPT_CHARS, ONTOLOGY_BACKFILL_RECHECK_MS, ONTOLOGY_BACKFILL_SYSTEM_PROMPT, PromptService, PrunePartialFailureError, WikiBusyError, WikiDraftNotFound, WikiDuplicateHashError, WikiExternalDeletionError, WikiGraphNodeOwnershipConflict, WikiIngestEmptyError, WikiInvalidReadOptions, WikiMigrationRequiredError, WikiParseError, WikiSearchUnavailableError, WikiSourceRefHashCollision, WikiStrictOntologyViolation, WikiSupersedeError, WikiTransactionError, chunkText, configureRandomSource, isReservedAbstainSlug, isWikiSearchUnavailableError, parseEmbedding, resolveContextBudget, resolveDefaultChunkLength, resolveEdgesMinConfidence, resolveHealScreenMinConfidence, resolveMaxPromptChars, resolveResolveMinConfidence, resolveSystemOneEdges, resolveSystemOneHealScreen, resolveSystemOneResolve, resolveSystemOneTyping, resolveTypingMinConfidence, safeSlice, validUsage, validateManifest, warnOnce } from './chunk-
|
|
1
|
+
import { BaseRepository, WikiGraphNodeOwnershipConflict, serializeSourcePointer, parseStoredSourcePointer, parseJsonObject, parseJsonArray, liveAtSql, reanchorRebuildFingerprint, __privateAdd, warnChangedDefaultsOnce, resolveContextBudgetOrThrow, EdgeRepository, MetadataRepository, EmbeddingService, VectorRemovalRepository, VectorRemovalService, SearchService, TemporalService, JobManager, PromptService, resolveGrounding, IngestionService, MaintenanceService, ImportExportService, RetrievalService, SourceStoreService, WriteService, __privateGet, __privateSet, createLegacySourceTypeIndex, writeNormalizeStamp, CURRENT_SCHEMA_VERSION, detectSchemaVersion, MIGRATIONS, runSourceRefNormalize, emitDiagnostic, normalizeSourceRef, normalizeSourceHash, canEngageWriteTyping, resolveLibrarianStrategy, entitySummaryMetaKey, WikiSourceRefHashCollision, DiagnosticBuffer, validateManifest, isReservedAbstainSlug, ONTOLOGY_ABSTAIN_SENTINEL, WikiDraftNotFound, generateId, emptyManifest, resolveNodeTypeMatch, WikiStrictOntologyViolation, validateInlineEdges, resolveEdgeDefinitions, typeSatisfies, normalizeTitleKey, edgeTripleAllowed, resolveNodeType, shouldEmitOntologyReceipt, nodeTypeReceipts, MAX_EMBED_ATTEMPTS, UsageMeter, isWikiSearchUnavailableError, WikiBusyError, WikiInvalidReadOptions, isLiveAt, packFactsByBudget, factTokenCost, probePendingWork, WikiMigrationRequiredError, setupDatabase, UnavailableIndexStrategy, createdAtValue, isUsableDate, validateSourcePointerValue, assertEntityId, assertEpochMs, passageFtsTriggerNames, FTS5_STATE_KEY, fts5LedgerDropSql, passageFtsTablesDdl, passageFtsTriggersDdl, fts5TablesDdl, fts5PendingIndexesDdl, fts5TriggersDdl, writeRebuildStart, FTS5_RETIRED_COUNTER_KEY, retiredTableName, FTS5_RETIRED_TABLES_KEY, isRetiredTableName, idReindexChunkSql, readRebuildProgress, FTS5_DRAIN_CHUNK, FTS5_RECLAIM_MERGE_PAGES, windowHiSql, windowChunkSql, FTS5_REBUILD_WM_KEY, sweepHiSql, sweepChunkSql, FTS5_SWEEP_CURSOR_KEY, drainHiSql, drainChunkSql, FTS5_REBUILD_SNAPSHOT_KEY, idDrainChunkSql, entityDrainHiSql, entityDrainChunkSql, fts5TriggerNames, extractSqliteCode, WikiTransactionError } from './chunk-JCMA74YK.mjs';
|
|
2
|
+
export { CLASSIFIER_MAX_CHOICES, CheckpointIncompleteError, DEFAULT_CHUNK_OVERLAP, DEFAULT_MAX_CHUNK_LENGTH, DEFAULT_MAX_EMBED_CHARS, DEFAULT_TYPING_MIN_CONFIDENCE, EMBED_CHARS_CEILING, EraseStepError, HEAL_ANCHORS_PER_CANDIDATE, HEAL_BATCH_SIZE, HEAL_MAX_FACT_BODY_CHARS_L3, HEAL_MAX_TASKS, HEAL_RECHECK_MS, HOOK_TIMEOUT_MARKER, ONTOLOGY_ABSTAIN_SENTINEL, ONTOLOGY_BACKFILL_BATCH_SIZE, ONTOLOGY_BACKFILL_MAX_PROMPT_CHARS, ONTOLOGY_BACKFILL_RECHECK_MS, ONTOLOGY_BACKFILL_SYSTEM_PROMPT, PromptService, PrunePartialFailureError, WikiBusyError, WikiDraftNotFound, WikiDuplicateHashError, WikiExternalDeletionError, WikiGraphNodeOwnershipConflict, WikiIngestEmptyError, WikiInvalidReadOptions, WikiMigrationRequiredError, WikiParseError, WikiSearchUnavailableError, WikiSourceRefHashCollision, WikiStrictOntologyViolation, WikiSupersedeError, WikiTransactionError, chunkText, configureRandomSource, isReservedAbstainSlug, isWikiSearchUnavailableError, parseEmbedding, resolveContextBudget, resolveDefaultChunkLength, resolveEdgesMinConfidence, resolveHealScreenMinConfidence, resolveMaxPromptChars, resolveResolveMinConfidence, resolveSystemOneEdges, resolveSystemOneHealScreen, resolveSystemOneResolve, resolveSystemOneTypeOnWrite, resolveSystemOneTyping, resolveTypingMinConfidence, safeSlice, validUsage, validateManifest, warnOnce } from './chunk-JCMA74YK.mjs';
|
|
3
3
|
import { deriveTrustTier, isStaleAfter, appendRelatedSection, buildConceptDocument, buildLogMd, buildEntityIndexMd, buildRootIndexMd, isAllowedOkfPath, parseRootIndexMd, parseEntityIndexMd, parseConcept, splitRelatedSection, extractMarkdownLinks, parseLogMd, parseEventIdComment, createEventIdDeriver, latestVerified, formatSourcesJson, appendEventIdComment, parseVerifiedFlexible, parseCitationsList } from '@equationalapplications/core-okf';
|
|
4
4
|
import MiniSearch from 'minisearch';
|
|
5
5
|
|
|
@@ -3477,8 +3477,8 @@ var MaintenanceScheduler = class {
|
|
|
3477
3477
|
* `budget_too_small` > `complete`. `budget_too_small` means a job's smallest
|
|
3478
3478
|
* unit needs more than the WHOLE budget — that job is skipped this run and
|
|
3479
3479
|
* the run continues; `budget_exhausted` means a unit needs more than what
|
|
3480
|
-
* REMAINS — the run stops. The token budget meters
|
|
3481
|
-
*
|
|
3480
|
+
* REMAINS — the run stops. The token budget meters generation and classify
|
|
3481
|
+
* calls; embeddings are never metered.
|
|
3482
3482
|
*/
|
|
3483
3483
|
async run(opts = {}) {
|
|
3484
3484
|
if (opts.deadlineMs !== void 0 && (typeof opts.deadlineMs !== "number" || !Number.isFinite(opts.deadlineMs) || opts.deadlineMs < 0)) {
|
|
@@ -3559,7 +3559,12 @@ var MaintenanceScheduler = class {
|
|
|
3559
3559
|
}
|
|
3560
3560
|
st.report.librarianPasses++;
|
|
3561
3561
|
st.report.factsWritten += r.factsWritten;
|
|
3562
|
+
if (r.typing) st.report.typedOnWrite = (st.report.typedOnWrite ?? 0) + r.typing.typed;
|
|
3562
3563
|
progressed = true;
|
|
3564
|
+
if ((r.typing?.unattempted ?? 0) > 0) {
|
|
3565
|
+
stopped = exhaustedStop();
|
|
3566
|
+
break rounds;
|
|
3567
|
+
}
|
|
3563
3568
|
const wm = await this.metadataRepo.getLibrarianWatermark(entityId, this.db);
|
|
3564
3569
|
if (await this.eventRepo.countAfter(entityId, wm) === 0) st.librarian = false;
|
|
3565
3570
|
continue;
|
|
@@ -3725,6 +3730,33 @@ function buildOntologyPromptAppendix(mode, manifestJson) {
|
|
|
3725
3730
|
].filter(Boolean).join("\n");
|
|
3726
3731
|
return { ontologyManifest: manifestJson, ontologyModeInstructions };
|
|
3727
3732
|
}
|
|
3733
|
+
var WRITE_FACT_ONTOLOGY_FIELDS = `
|
|
3734
|
+
Each fact may optionally include:
|
|
3735
|
+
- "okf_type": string \u2014 must be one of the node_types in the manifest
|
|
3736
|
+
- "edges": [{ "edge_type": string, "target_title": string }] \u2014 target_title must match another fact's title in this response or existing memory
|
|
3737
|
+
- An edge_type may appear in the manifest multiple times with different source_type/target_type; use the row whose types match your fact and target.
|
|
3738
|
+
Each node is a fact. To link two things with an edge, each must exist as its own fact, titled by the same name you use in \`target_title\`.`;
|
|
3739
|
+
var WRITE_EMERGENT_EXTRA = `
|
|
3740
|
+
You may also return "ontology_updates" to propose new types:
|
|
3741
|
+
"ontology_updates": {
|
|
3742
|
+
"node_types": [{ "type": "slug", "description": "...", "parent_type": "optional existing slug" }],
|
|
3743
|
+
"edge_types": [{ "type": "slug", "source_type": "...", "target_type": "...", "description": "..." }]
|
|
3744
|
+
}
|
|
3745
|
+
Only propose types not already in the manifest. Do not redefine existing types.`;
|
|
3746
|
+
function buildWriteOntologyAppendix(mode, manifestJson) {
|
|
3747
|
+
const strictRules = mode === "strict" ? "STRICT MODE: Use ONLY types defined in the manifest. If a fact does not fit a node_type, choose the closest type the fact is an example of; omit only when none applies even broadly." : "EMERGENT MODE: Prefer manifest types. You may propose new types via ontology_updates when necessary.";
|
|
3748
|
+
const fallback = "If okf_type or an edge is invalid, omit them rather than inventing unlisted types.";
|
|
3749
|
+
const ontologyModeInstructions = [
|
|
3750
|
+
"## Ontology constraints",
|
|
3751
|
+
strictRules,
|
|
3752
|
+
fallback,
|
|
3753
|
+
WRITE_FACT_ONTOLOGY_FIELDS,
|
|
3754
|
+
mode === "emergent" ? WRITE_EMERGENT_EXTRA : "",
|
|
3755
|
+
"Manifest:",
|
|
3756
|
+
manifestJson
|
|
3757
|
+
].filter(Boolean).join("\n");
|
|
3758
|
+
return { site: "write", ontologyManifest: manifestJson, ontologyModeInstructions };
|
|
3759
|
+
}
|
|
3728
3760
|
|
|
3729
3761
|
// src/services/OntologyService.ts
|
|
3730
3762
|
var OntologyService = class {
|
|
@@ -3773,6 +3805,17 @@ var OntologyService = class {
|
|
|
3773
3805
|
const manifestJson = JSON.stringify(manifest, null, 2);
|
|
3774
3806
|
return buildOntologyPromptAppendix(mode, manifestJson);
|
|
3775
3807
|
}
|
|
3808
|
+
/**
|
|
3809
|
+
* Ontology prompt context for the WRITE builders (specs/type-on-write §5).
|
|
3810
|
+
* `null` when the mode is `'off'` or when write-time typing is `engaged`
|
|
3811
|
+
* (the classifier types the fact, so the manifest leaves the write prompt).
|
|
3812
|
+
* Backfill keeps `buildPromptContext`.
|
|
3813
|
+
*/
|
|
3814
|
+
async buildWritePromptContext(entityId, opts) {
|
|
3815
|
+
const { mode, manifest } = await this.getEffectiveState(entityId);
|
|
3816
|
+
if (mode === "off" || opts.engaged) return null;
|
|
3817
|
+
return buildWriteOntologyAppendix(mode, JSON.stringify(manifest, null, 2));
|
|
3818
|
+
}
|
|
3776
3819
|
async mergeEmergentUpdates(entityId, updates, tx) {
|
|
3777
3820
|
const filtered = updates.node_types ? { ...updates, node_types: updates.node_types.filter((nt) => !isReservedAbstainSlug(nt.type)) } : updates;
|
|
3778
3821
|
const { manifest: merged, rejected } = await this.metadataRepo.mergeManifestUpdates(entityId, filtered, tx);
|
|
@@ -4843,7 +4886,11 @@ var WikiMemory = class {
|
|
|
4843
4886
|
*/
|
|
4844
4887
|
async getInstructions(entityId) {
|
|
4845
4888
|
assertEntityId2(entityId);
|
|
4846
|
-
const
|
|
4889
|
+
const state = await this.ontologyService.getEffectiveState(entityId);
|
|
4890
|
+
const engaged = canEngageWriteTyping(this.options.config, this.options.llmProvider, state.mode, state.manifest);
|
|
4891
|
+
const writeContext = await this.ontologyService.buildWritePromptContext(entityId, { engaged });
|
|
4892
|
+
const ingestContext = engaged ? await this.ontologyService.buildWritePromptContext(entityId, { engaged: false }) : writeContext;
|
|
4893
|
+
const backfillContext = await this.ontologyService.buildPromptContext(entityId);
|
|
4847
4894
|
const { guidance, diagnostic } = PromptService.resolveGuidance(this.options.config, entityId);
|
|
4848
4895
|
if (diagnostic) {
|
|
4849
4896
|
emitDiagnostic(this.options, {
|
|
@@ -4854,7 +4901,7 @@ var WikiMemory = class {
|
|
|
4854
4901
|
detail: diagnostic.detail
|
|
4855
4902
|
});
|
|
4856
4903
|
}
|
|
4857
|
-
return this.promptService.buildInstructionTemplates(
|
|
4904
|
+
return this.promptService.buildInstructionTemplates(writeContext, resolveLibrarianStrategy(this.options.config), guidance, backfillContext, ingestContext);
|
|
4858
4905
|
}
|
|
4859
4906
|
/**
|
|
4860
4907
|
* Returns the live source_refs for an entity, one row per ref, with the most
|