@equationalapplications/core-llm-wiki 4.12.0 → 4.13.1

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,11 +1,16 @@
1
1
  import { M as MemoryBundle, F as FormatContextOptions, a as MemoryDump, b as FormattedMemoryDump, R as ReadOptions, S as SQLiteAdapter, W as WikiOptions, c as WikiMemory } from './testing-CDIDE4Jd.mjs';
2
2
  export { E as EntityStatus, d as ExtractedFact, e as ExtractedTask, H as HOOK_TIMEOUT_MARKER, L as LLMProvider, P as PromptOverrides, f as PromptService, g as PrunePartialFailureError, V as VectorRanker, h as VectorRankerFallback, i as VectorRankerRankArgs, j as VectorRankerSemanticResult, k as WikiBusyError, l as WikiBusyOperation, m as WikiCheckpoint, n as WikiConfig, o as WikiEvent, p as WikiFact, q as WikiMemoryTestAccess, r as WikiOutboxEvent, s as WikiTask } from './testing-CDIDE4Jd.mjs';
3
+ import { OkfFile } from '@equationalapplications/core-okf';
3
4
  import 'minisearch';
4
5
 
5
6
  declare function formatContext(bundle: MemoryBundle, options?: FormatContextOptions): string;
6
7
 
7
8
  declare function formatMemoryDump(dump: MemoryDump): FormattedMemoryDump;
8
9
 
10
+ declare function formatOkfBundle(dump: MemoryDump): {
11
+ files: OkfFile[];
12
+ };
13
+
9
14
  declare function parseEmbedding(blob: Uint8Array | null | undefined, text: string | null | undefined): Float32Array | null;
10
15
 
11
16
  interface LibrarianOptions {
@@ -32,4 +37,4 @@ declare function mapLibrarianOptionsToReadOptions(options: LibrarianOptions): Pi
32
37
 
33
38
  declare function createWiki(db: SQLiteAdapter, options: WikiOptions): WikiMemory;
34
39
 
35
- export { DEFAULT_LIBRARIAN_SYNTHESIS_PROMPT, FormatContextOptions, FormattedMemoryDump, type LibrarianOptions, type LibrarianPromptVariables, MemoryBundle, MemoryDump, ReadOptions, SQLiteAdapter, WikiMemory, WikiOptions, createWiki, formatContext, formatMemoryDump, hydrateLibrarianPrompt, mapLibrarianOptionsToReadOptions, parseEmbedding, validateLibrarianPromptTemplate };
40
+ export { DEFAULT_LIBRARIAN_SYNTHESIS_PROMPT, FormatContextOptions, FormattedMemoryDump, type LibrarianOptions, type LibrarianPromptVariables, MemoryBundle, MemoryDump, ReadOptions, SQLiteAdapter, WikiMemory, WikiOptions, createWiki, formatContext, formatMemoryDump, formatOkfBundle, hydrateLibrarianPrompt, mapLibrarianOptionsToReadOptions, parseEmbedding, validateLibrarianPromptTemplate };
package/dist/index.d.ts CHANGED
@@ -1,11 +1,16 @@
1
1
  import { M as MemoryBundle, F as FormatContextOptions, a as MemoryDump, b as FormattedMemoryDump, R as ReadOptions, S as SQLiteAdapter, W as WikiOptions, c as WikiMemory } from './testing-CDIDE4Jd.js';
2
2
  export { E as EntityStatus, d as ExtractedFact, e as ExtractedTask, H as HOOK_TIMEOUT_MARKER, L as LLMProvider, P as PromptOverrides, f as PromptService, g as PrunePartialFailureError, V as VectorRanker, h as VectorRankerFallback, i as VectorRankerRankArgs, j as VectorRankerSemanticResult, k as WikiBusyError, l as WikiBusyOperation, m as WikiCheckpoint, n as WikiConfig, o as WikiEvent, p as WikiFact, q as WikiMemoryTestAccess, r as WikiOutboxEvent, s as WikiTask } from './testing-CDIDE4Jd.js';
3
+ import { OkfFile } from '@equationalapplications/core-okf';
3
4
  import 'minisearch';
4
5
 
5
6
  declare function formatContext(bundle: MemoryBundle, options?: FormatContextOptions): string;
6
7
 
7
8
  declare function formatMemoryDump(dump: MemoryDump): FormattedMemoryDump;
8
9
 
10
+ declare function formatOkfBundle(dump: MemoryDump): {
11
+ files: OkfFile[];
12
+ };
13
+
9
14
  declare function parseEmbedding(blob: Uint8Array | null | undefined, text: string | null | undefined): Float32Array | null;
10
15
 
11
16
  interface LibrarianOptions {
@@ -32,4 +37,4 @@ declare function mapLibrarianOptionsToReadOptions(options: LibrarianOptions): Pi
32
37
 
33
38
  declare function createWiki(db: SQLiteAdapter, options: WikiOptions): WikiMemory;
34
39
 
35
- export { DEFAULT_LIBRARIAN_SYNTHESIS_PROMPT, FormatContextOptions, FormattedMemoryDump, type LibrarianOptions, type LibrarianPromptVariables, MemoryBundle, MemoryDump, ReadOptions, SQLiteAdapter, WikiMemory, WikiOptions, createWiki, formatContext, formatMemoryDump, hydrateLibrarianPrompt, mapLibrarianOptionsToReadOptions, parseEmbedding, validateLibrarianPromptTemplate };
40
+ export { DEFAULT_LIBRARIAN_SYNTHESIS_PROMPT, FormatContextOptions, FormattedMemoryDump, type LibrarianOptions, type LibrarianPromptVariables, MemoryBundle, MemoryDump, ReadOptions, SQLiteAdapter, WikiMemory, WikiOptions, createWiki, formatContext, formatMemoryDump, formatOkfBundle, hydrateLibrarianPrompt, mapLibrarianOptionsToReadOptions, parseEmbedding, validateLibrarianPromptTemplate };
package/dist/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var MiniSearch = require('minisearch');
4
+ var coreOkf = require('@equationalapplications/core-okf');
4
5
 
5
6
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
6
7
 
@@ -4311,6 +4312,71 @@ function formatContext(bundle, options) {
4311
4312
  return lines.join("\n");
4312
4313
  }
4313
4314
 
4315
+ // src/utils/sanitizeForFilename.ts
4316
+ function shortHash(value) {
4317
+ let h1 = 5381;
4318
+ let h2 = 52711;
4319
+ for (let i = 0; i < value.length; i += 1) {
4320
+ const c = value.charCodeAt(i);
4321
+ h1 = Math.imul(h1, 33) ^ c;
4322
+ h2 = Math.imul(h2, 31) ^ c;
4323
+ }
4324
+ return (h1 >>> 0).toString(16).padStart(8, "0") + (h2 >>> 0).toString(16).padStart(8, "0");
4325
+ }
4326
+ var OKF_RESERVED_CONCEPT_NAMES = /* @__PURE__ */ new Set(["index", "log"]);
4327
+ var WINDOWS_RESERVED_NAMES = /* @__PURE__ */ new Set([
4328
+ "con",
4329
+ "prn",
4330
+ "aux",
4331
+ "nul",
4332
+ "com1",
4333
+ "com2",
4334
+ "com3",
4335
+ "com4",
4336
+ "com5",
4337
+ "com6",
4338
+ "com7",
4339
+ "com8",
4340
+ "com9",
4341
+ "lpt1",
4342
+ "lpt2",
4343
+ "lpt3",
4344
+ "lpt4",
4345
+ "lpt5",
4346
+ "lpt6",
4347
+ "lpt7",
4348
+ "lpt8",
4349
+ "lpt9"
4350
+ ]);
4351
+ function isWindowsReservedName(name) {
4352
+ const base = name.split(".")[0];
4353
+ return WINDOWS_RESERVED_NAMES.has(base.toLowerCase());
4354
+ }
4355
+ function sanitizeForFilename(value) {
4356
+ const normalized = value.normalize("NFKC");
4357
+ const sanitized = normalized.replace(/[^A-Za-z0-9._-]+/g, "_").replace(/^\.+/, "_").replace(/_+/g, "_").replace(/^[_-]+|[_-]+$/g, "");
4358
+ const MAX_BASE = 200;
4359
+ const trimmed = sanitized.length > MAX_BASE ? sanitized.slice(0, MAX_BASE) : sanitized;
4360
+ let baseName = trimmed && trimmed !== "." && trimmed !== ".." ? trimmed : "entity";
4361
+ const withoutTrailingDotSpace = baseName.replace(/[. ]+$/, "");
4362
+ const hadTrailingDotSpace = withoutTrailingDotSpace !== baseName;
4363
+ if (hadTrailingDotSpace) {
4364
+ baseName = withoutTrailingDotSpace || "entity";
4365
+ }
4366
+ const windowsReserved = isWindowsReservedName(baseName);
4367
+ const needsSuffix = baseName !== value || sanitized.length > MAX_BASE || hadTrailingDotSpace || windowsReserved;
4368
+ if (!needsSuffix) return baseName;
4369
+ const suffix = `-${shortHash(value)}`;
4370
+ return `${baseName}${suffix}`;
4371
+ }
4372
+ function sanitizeConceptId(id) {
4373
+ const sanitized = sanitizeForFilename(id);
4374
+ if (OKF_RESERVED_CONCEPT_NAMES.has(sanitized.toLowerCase())) {
4375
+ return `${sanitized}-${shortHash(id)}`;
4376
+ }
4377
+ return sanitized;
4378
+ }
4379
+
4314
4380
  // src/utils/formatMemoryDump.ts
4315
4381
  function renderFact(f) {
4316
4382
  const tags = (f.tags || []).join(", ");
@@ -4365,25 +4431,8 @@ function renderEntity(entityId, bundle, generatedAt) {
4365
4431
  }
4366
4432
  return lines.join("\n");
4367
4433
  }
4368
- function shortHash(value) {
4369
- let h1 = 5381;
4370
- let h2 = 52711;
4371
- for (let i = 0; i < value.length; i += 1) {
4372
- const c = value.charCodeAt(i);
4373
- h1 = Math.imul(h1, 33) ^ c;
4374
- h2 = Math.imul(h2, 31) ^ c;
4375
- }
4376
- return (h1 >>> 0).toString(16).padStart(8, "0") + (h2 >>> 0).toString(16).padStart(8, "0");
4377
- }
4378
4434
  function formatEntityFileName(entityId) {
4379
- const normalized = entityId.normalize("NFKC");
4380
- const sanitized = normalized.replace(/[^A-Za-z0-9._-]+/g, "_").replace(/^\.+/, "_").replace(/_+/g, "_").replace(/^[_-]+|[_-]+$/g, "");
4381
- const MAX_BASE = 200;
4382
- const trimmed = sanitized.length > MAX_BASE ? sanitized.slice(0, MAX_BASE) : sanitized;
4383
- const baseName = trimmed && trimmed !== "." && trimmed !== ".." ? trimmed : "entity";
4384
- const needsSuffix = baseName !== entityId || sanitized.length > MAX_BASE;
4385
- const uniqueBaseName = needsSuffix ? `${baseName}-${shortHash(entityId)}` : baseName;
4386
- return `${uniqueBaseName}.md`;
4435
+ return `${sanitizeForFilename(entityId)}.md`;
4387
4436
  }
4388
4437
  function formatMemoryDump(dump) {
4389
4438
  const files = Object.entries(dump.entities).map(([entityId, bundle]) => ({
@@ -4410,6 +4459,101 @@ function formatMemoryDump(dump) {
4410
4459
  files
4411
4460
  };
4412
4461
  }
4462
+ function factFrontmatter(f) {
4463
+ return {
4464
+ type: "fact",
4465
+ title: f.title,
4466
+ tags: f.tags,
4467
+ timestamp: new Date(f.updated_at).toISOString(),
4468
+ resource: f.source_ref ?? void 0,
4469
+ id: f.id,
4470
+ entity_id: f.entity_id,
4471
+ confidence: f.confidence,
4472
+ source_type: f.source_type,
4473
+ source_hash: f.source_hash,
4474
+ created_at: f.created_at,
4475
+ access_count: f.access_count,
4476
+ last_accessed_at: f.last_accessed_at,
4477
+ deleted_at: f.deleted_at
4478
+ };
4479
+ }
4480
+ function taskFrontmatter(t) {
4481
+ return {
4482
+ type: "task",
4483
+ title: t.description,
4484
+ timestamp: new Date(t.updated_at).toISOString(),
4485
+ id: t.id,
4486
+ entity_id: t.entity_id,
4487
+ status: t.status,
4488
+ priority: t.priority,
4489
+ created_at: t.created_at,
4490
+ resolved_at: t.resolved_at,
4491
+ deleted_at: t.deleted_at
4492
+ };
4493
+ }
4494
+ function formatLogDate(timestampMs) {
4495
+ return new Date(timestampMs).toISOString().slice(0, 10);
4496
+ }
4497
+ function buildEventLogEntries(events, factIdToFilename) {
4498
+ return events.map((e) => {
4499
+ const factFilename = e.related_entry_id ? factIdToFilename.get(e.related_entry_id) : void 0;
4500
+ const summary = e.summary.replace(/\\/g, "\\\\").replace(/\[/g, "\\[").replace(/\]/g, "\\]").replace(/\r?\n/g, " ");
4501
+ const text = factFilename ? `(${e.event_type}) [${summary}](./facts/${factFilename}.md)` : `(${e.event_type}) ${summary}`;
4502
+ return { date: formatLogDate(e.created_at), text };
4503
+ });
4504
+ }
4505
+ function formatOkfBundle(dump) {
4506
+ const files = [];
4507
+ const rootEntries = [];
4508
+ for (const [entityId, bundle] of Object.entries(dump.entities)) {
4509
+ const dir = sanitizeForFilename(entityId);
4510
+ const factIdToFilename = new Map(
4511
+ bundle.facts.map((f) => [f.id, sanitizeConceptId(f.id)])
4512
+ );
4513
+ const factEntries = bundle.facts.map((f) => ({
4514
+ path: `facts/${factIdToFilename.get(f.id)}.md`,
4515
+ title: f.title
4516
+ }));
4517
+ for (const f of bundle.facts) {
4518
+ files.push({
4519
+ path: `entities/${dir}/facts/${factIdToFilename.get(f.id)}.md`,
4520
+ content: coreOkf.buildConceptDocument(factFrontmatter(f), f.body)
4521
+ });
4522
+ }
4523
+ const taskEntries = bundle.tasks.map((t) => ({
4524
+ path: `tasks/${sanitizeConceptId(t.id)}.md`,
4525
+ title: t.description
4526
+ }));
4527
+ for (const t of bundle.tasks) {
4528
+ files.push({
4529
+ path: `entities/${dir}/tasks/${sanitizeConceptId(t.id)}.md`,
4530
+ content: coreOkf.buildConceptDocument(taskFrontmatter(t), "")
4531
+ });
4532
+ }
4533
+ files.push({
4534
+ path: `entities/${dir}/log.md`,
4535
+ content: coreOkf.buildLogMd(buildEventLogEntries(bundle.events, factIdToFilename))
4536
+ });
4537
+ const entityIndexSections = [
4538
+ { heading: "Facts", entries: factEntries },
4539
+ { heading: "Tasks", entries: taskEntries }
4540
+ ];
4541
+ files.push({
4542
+ path: `entities/${dir}/index.md`,
4543
+ content: `${coreOkf.buildIndexMd(entityIndexSections)}[Event log](./log.md)
4544
+ `
4545
+ });
4546
+ rootEntries.push({ path: `entities/${dir}/index.md`, title: entityId });
4547
+ }
4548
+ files.push({
4549
+ path: "index.md",
4550
+ content: coreOkf.buildRootIndexMd(
4551
+ "0.1",
4552
+ rootEntries.length > 0 ? [{ heading: "Entities", entries: rootEntries }] : []
4553
+ )
4554
+ });
4555
+ return { files };
4556
+ }
4413
4557
 
4414
4558
  // src/librarianPrompt.ts
4415
4559
  var DEFAULT_LIBRARIAN_SYNTHESIS_PROMPT = `You are a careful memory synthesis assistant.
@@ -4464,6 +4608,7 @@ exports.WikiMemory = WikiMemory;
4464
4608
  exports.createWiki = createWiki;
4465
4609
  exports.formatContext = formatContext;
4466
4610
  exports.formatMemoryDump = formatMemoryDump;
4611
+ exports.formatOkfBundle = formatOkfBundle;
4467
4612
  exports.hydrateLibrarianPrompt = hydrateLibrarianPrompt;
4468
4613
  exports.mapLibrarianOptionsToReadOptions = mapLibrarianOptionsToReadOptions;
4469
4614
  exports.parseEmbedding = parseEmbedding;