Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 25 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,29 @@
"name": "@corbits/memory",
"version": "0.1.3",
"description": "Mountable memory add/search/list SDK for Interchange hubs — includes resident distiller",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
".": "./src/index.ts",
"./migrations": "./src/migrations.ts",
"./config": "./src/mount-config.ts",
"./sidecar-bundle": "./src/sidecar-bundle.ts",
"./distiller": "./src/distiller/index.ts"
".": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
},
"./migrations": {
"types": "./dist/migrations.d.ts",
"default": "./dist/migrations.js"
},
"./config": {
"types": "./dist/mount-config.d.ts",
"default": "./dist/mount-config.js"
},
"./sidecar-bundle": {
"types": "./dist/sidecar-bundle.d.ts",
"default": "./dist/sidecar-bundle.js"
},
"./distiller": {
"types": "./dist/distiller/index.d.ts",
"default": "./dist/distiller/index.js"
}
},
"interchange": {
"grantRequirements": [
Expand Down Expand Up @@ -39,14 +56,15 @@
},
"license": "LGPL-2.1-only",
"type": "module",
"module": "src/index.ts",
"engines": {
"bun": ">=1.2.0",
"node": ">=24"
},
"scripts": {
"db:setup": "bun run scripts/db-setup.ts",
"typecheck": "tsc --noEmit",
"build": "tsc -p tsconfig.build.json",
"prepack": "npm run build",
"test": "bun test ./src",
"test:coverage": "bun test --coverage --coverage-reporter=lcov --coverage-reporter=text ./src"
},
Expand Down Expand Up @@ -85,8 +103,7 @@
"hono"
],
"files": [
"src",
"!src/**/*.test.ts",
"dist",
"migrations",
"README.md",
"LICENSE"
Expand Down
2 changes: 1 addition & 1 deletion scripts/db-setup.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { runMemoryMigrations } from "../src/migrations.ts";
import { runMemoryMigrations } from "../src/migrations.js";

const url =
process.env["DATABASE_URL"];
Expand Down
4 changes: 2 additions & 2 deletions src/core/adapt-and-plan.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, it } from "bun:test";
import { adaptAndPlan, InvalidAdaptedDocumentError } from "./adapt-and-plan.ts";
import type { AdaptedDocument } from "./schemas/adapted-document.ts";
import { adaptAndPlan, InvalidAdaptedDocumentError } from "./adapt-and-plan.js";
import type { AdaptedDocument } from "./schemas/adapted-document.js";

function validAdaptedDocument(
overrides: Partial<AdaptedDocument> = {},
Expand Down
12 changes: 6 additions & 6 deletions src/core/adapt-and-plan.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { DEFAULT_CHUNK_CAPS } from "./chunk/types.ts";
import { chunkTokenRecursive } from "./chunk/token-recursive.ts";
import type { Chunker } from "./chunk/types.ts";
import { contentHash } from "./hash.ts";
import { DEFAULT_CHUNK_CAPS } from "./chunk/types.js";
import { chunkTokenRecursive } from "./chunk/token-recursive.js";
import type { Chunker } from "./chunk/types.js";
import { contentHash } from "./hash.js";
import type {
AdaptedDocument,
AdaptedDocumentChunk,
EntityHint,
} from "./schemas/adapted-document.ts";
import type { MemoryEdgeHint } from "./schemas/entity-edge.ts";
} from "./schemas/adapted-document.js";
import type { MemoryEdgeHint } from "./schemas/entity-edge.js";

/**
* Thrown when an AdaptedDocument fails adaptAndPlan's own defensive checks
Expand Down
2 changes: 1 addition & 1 deletion src/core/authority.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, expect, it } from "bun:test";
import { computeAuthority, type AuthoritySignals } from "./authority.ts";
import { computeAuthority, type AuthoritySignals } from "./authority.js";

function signals(overrides: Partial<AuthoritySignals> = {}): AuthoritySignals {
return {
Expand Down
2 changes: 1 addition & 1 deletion src/core/authority.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { type } from "arktype";
import { CreatedByKindSchema, type CreatedByKind } from "./schemas/document.ts";
import { CreatedByKindSchema, type CreatedByKind } from "./schemas/document.js";

// Corroboration-based authority weighting: retrieval ranks by how corroborated
// a source is, not lexical relevance alone. `source_class` is the coarse bucket
Expand Down
2 changes: 1 addition & 1 deletion src/core/chunk/token-recursive.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, expect, it } from "bun:test";
import { chunkTokenRecursive } from "./token-recursive.ts";
import { chunkTokenRecursive } from "./token-recursive.js";

function sentences(count: number): string {
const parts: string[] = [];
Expand Down
2 changes: 1 addition & 1 deletion src/core/chunk/token-recursive.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DEFAULT_CHUNK_CAPS, type ChunkCaps, type TokenChunk } from "./types.ts";
import { DEFAULT_CHUNK_CAPS, type ChunkCaps, type TokenChunk } from "./types.js";

// Separator ladder tried in order before falling back to a hard character
// cut. Word/whitespace-based token counting
Expand Down
4 changes: 2 additions & 2 deletions src/core/corroboration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import {
CORROBORATION_STRONG_FLOOR,
effectiveAuthority,
meetsStrongEvidenceGate,
} from "./corroboration.ts";
} from "./corroboration.js";
import {
BOOST_MULTIPLIER_MAX,
BOOST_MULTIPLIER_MIN,
} from "./hybrid-search.ts";
} from "./hybrid-search.js";

describe("corroborationFactor", () => {
it("is neutral with no edges", () => {
Expand Down
2 changes: 1 addition & 1 deletion src/core/corroboration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
BOOST_MULTIPLIER_MAX,
BOOST_MULTIPLIER_MIN,
clampBoostMultiplier,
} from "./hybrid-search.ts";
} from "./hybrid-search.js";

/** Independent supports needed for evidence:strong (with authority floor). */
export const CORROBORATION_STRONG_FLOOR = 2;
Expand Down
4 changes: 2 additions & 2 deletions src/core/degrade-metrics.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import {
getDegradeMetricsSnapshot,
recordDegrade,
resetDegradeMetrics,
} from "./degrade-metrics.ts";
import { log } from "../log.ts";
} from "./degrade-metrics.js";
import { log } from "../log.js";

function captureLogs() {
const calls: Array<{ level: "info" | "warn" | "error"; message: string; payload: unknown }> = [];
Expand Down
4 changes: 2 additions & 2 deletions src/core/degrade-metrics.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { log } from "../log.ts";
import type { DegradeFlag } from "./hybrid-search.ts";
import { log } from "../log.js";
import type { DegradeFlag } from "./hybrid-search.js";

// There is no metrics facility anywhere in this repo — no statsd,
// prometheus, or otel dependency, and `@intx/log` exports no counter. This
Expand Down
4 changes: 2 additions & 2 deletions src/core/embed-client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import {
EmbedTimeoutError,
embedTexts,
probeEmbedDims,
} from "./embed-client.ts";
import type { EmbedClientConfig } from "./embed-client.ts";
} from "./embed-client.js";
import type { EmbedClientConfig } from "./embed-client.js";

function jsonResponse(body: unknown, status = 200): Response {
return new Response(JSON.stringify(body), {
Expand Down
4 changes: 2 additions & 2 deletions src/core/embed-model-registry.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, expect, it, mock } from "bun:test";
import type { EmbedClientConfig } from "./embed-client.ts";
import type { EmbedClientConfig } from "./embed-client.js";
import {
activateEmbedModel,
activateEmbedModelByKey,
Expand All @@ -16,7 +16,7 @@ import {
resolveActiveEmbedTable,
resolveEmbedTableByModelKey,
VECTOR_INDEX_MAX_DIMS,
} from "./embed-model-registry.ts";
} from "./embed-model-registry.js";

function jsonResponse(body: unknown): Response {
return new Response(JSON.stringify(body), {
Expand Down
4 changes: 2 additions & 2 deletions src/core/embed-model-registry.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createHash, randomUUID } from "node:crypto";
import { type EmbedClientConfig, probeEmbedDims } from "./embed-client.ts";
import { formatCaughtError, log } from "../log.ts";
import { type EmbedClientConfig, probeEmbedDims } from "./embed-client.js";
import { formatCaughtError, log } from "../log.js";

// pgvector's hnsw/ivfflat indexes on the `vector` type cap at 2000 dims; an
// expression index over `halfvec` (half-precision) raises the cap to 4000.
Expand Down
2 changes: 1 addition & 1 deletion src/core/embed-sql.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type postgres from "postgres";
import type { EmbedRegistrySqlClient } from "./embed-model-registry.ts";
import type { EmbedRegistrySqlClient } from "./embed-model-registry.js";

// Generic bridge from the engine's postgres-js handle to the minimal
// `{ query(sql, params) }` seam several core modules take instead of a
Expand Down
4 changes: 2 additions & 2 deletions src/core/embed-worker.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { embedTexts, type EmbedClientConfig } from "./embed-client.ts";
import { embedTexts, type EmbedClientConfig } from "./embed-client.js";
import {
EMBED_TABLE_NAME_PATTERN,
type ActiveEmbedTable,
type EmbedRegistrySqlClient,
} from "./embed-model-registry.ts";
} from "./embed-model-registry.js";

export interface EmbeddableChunk {
id: string;
Expand Down
6 changes: 3 additions & 3 deletions src/core/engine-client-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
* future caller) must go through these functions so operator overrides like
* EMBED_TIMEOUT_MS / RERANK_TIMEOUT_MS reach every code path uniformly.
*/
import type { EngineConfig } from "../config.ts";
import type { EmbedClientConfig } from "./embed-client.ts";
import type { RerankClientConfig } from "./rerank-client.ts";
import type { EngineConfig } from "../config.js";
import type { EmbedClientConfig } from "./embed-client.js";
import type { RerankClientConfig } from "./rerank-client.js";

const VALID_EMBED_API_STYLES = new Set(["openai", "tei", "ollama"]);

Expand Down
6 changes: 3 additions & 3 deletions src/core/enums.lockstep.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import {
PROVENANCE_MODES,
RETENTION_CLASSES,
TEMPORAL_CLASSES,
} from "./enums.ts";
import { MemoryEdgeRelSchema, MemoryEdgeRefTypeSchema } from "./schemas/entity-edge.ts";
} from "./enums.js";
import { MemoryEdgeRelSchema, MemoryEdgeRefTypeSchema } from "./schemas/entity-edge.js";
import {
LineageClassSchema,
ProvenanceModeSchema,
RetentionClassSchema,
TemporalClassSchema,
} from "./schemas/document.ts";
} from "./schemas/document.js";
import { type } from "arktype";

const MIGRATIONS_DIR = join(import.meta.dir, "../../migrations");
Expand Down
4 changes: 2 additions & 2 deletions src/core/fts-language.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
FTS_LANGUAGE_TOKEN,
parseFtsLanguage,
verifyFtsLanguage,
} from "./fts-language.ts";
} from "./fts-language.js";

describe("parseFtsLanguage", () => {
it("defaults when unset or empty", () => {
Expand Down Expand Up @@ -46,7 +46,7 @@ describe("runMemoryMigrations language boundary", () => {
it("falls back to the FTS_LANGUAGE env var when no option is passed", async () => {
// Pin the boundary contract without a live database: the runner must
// resolve exactly like the config loader, from the same env var.
const { runMemoryMigrations } = await import("../migrations.ts");
const { runMemoryMigrations } = await import("../migrations.js");
process.env["FTS_LANGUAGE"] = "not a valid name";
try {
await expect(runMemoryMigrations("postgres://unused")).rejects.toThrow(
Expand Down
2 changes: 1 addition & 1 deletion src/core/hash.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, expect, it } from "bun:test";
import { contentHash, stableStringify } from "./hash.ts";
import { contentHash, stableStringify } from "./hash.js";

describe("stableStringify", () => {
it("produces identical output regardless of key insertion order", () => {
Expand Down
2 changes: 1 addition & 1 deletion src/core/hybrid-search.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
recencyBoostMultiplier,
temporalRecencyMultiplier,
toRankedCandidates,
} from "./hybrid-search.ts";
} from "./hybrid-search.js";

describe("toRankedCandidates", () => {
test("assigns 1-based rank in list order", () => {
Expand Down
2 changes: 1 addition & 1 deletion src/core/merge-local-live.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
recencyPrior,
withTimeout,
type MergeChannelItem,
} from "./merge-local-live.ts";
} from "./merge-local-live.js";

const NOW = Date.parse("2026-03-08T12:00:00.000Z");

Expand Down
2 changes: 1 addition & 1 deletion src/core/merge-local-live.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* - Live timeout + allSettled fan-out are applied by the caller; this module
* is pure merge over already-collected channel results
*/
import type { SearchHitCitation } from "./schemas/search.ts";
import type { SearchHitCitation } from "./schemas/search.js";

export const LIVE_TIMEOUT_MS = 800;

Expand Down
2 changes: 1 addition & 1 deletion src/core/mmr.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, expect, it } from "bun:test";
import { mmrRerank } from "./mmr.ts";
import { mmrRerank } from "./mmr.js";

describe("mmrRerank", () => {
it("keeps the top-scoring item, then prefers a diverse item over a near-duplicate one", () => {
Expand Down
4 changes: 2 additions & 2 deletions src/core/rerank-client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import {
defaultMaxDocCharsForModel,
rerankDocuments,
validateRerankConfig,
} from "./rerank-client.ts";
import type { RerankClientConfig } from "./rerank-client.ts";
} from "./rerank-client.js";
import type { RerankClientConfig } from "./rerank-client.js";

// The default env in .env.example ships RERANK_MODEL=bge-reranker-base with
// RERANK_MAX_DOC_CHARS unset (-> defaultMaxDocCharsForModel's per-model
Expand Down
4 changes: 2 additions & 2 deletions src/core/schemas/adapted-document.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { describe, expect, it } from "bun:test";
import { type } from "arktype";
import { AdaptedDocumentSchema } from "./adapted-document.ts";
import type { AdaptedDocument } from "./adapted-document.ts";
import { AdaptedDocumentSchema } from "./adapted-document.js";
import type { AdaptedDocument } from "./adapted-document.js";

// T2 — a full AdaptedDocument fixture must parse with no errors.
describe("AdaptedDocumentSchema", () => {
Expand Down
6 changes: 3 additions & 3 deletions src/core/schemas/adapted-document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import {
LineageClassSchema,
ProvenanceModeSchema,
TemporalClassSchema,
} from "./document.ts";
import { MemoryEdgeHintSchema } from "./entity-edge.ts";
import { AuthoritySourceClassSchema } from "../authority.ts";
} from "./document.js";
import { MemoryEdgeHintSchema } from "./entity-edge.js";
import { AuthoritySourceClassSchema } from "../authority.js";

// A hint that a chunk/document mentions a real-world entity; the ingestion
// engine resolves this against memory_entity, creating a row if none
Expand Down
2 changes: 1 addition & 1 deletion src/core/schemas/chunk.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, it } from "bun:test";
import { type } from "arktype";
import { MemoryChunkSchema } from "./chunk.ts";
import { MemoryChunkSchema } from "./chunk.js";

describe("MemoryChunkSchema", () => {
it("round-trips a full fixture", () => {
Expand Down
6 changes: 3 additions & 3 deletions src/core/schemas/claim-bearing.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { describe, expect, it } from "bun:test";
import { type } from "arktype";
import { AdaptedDocumentSchema } from "./adapted-document.ts";
import { MemoryEdgeHintSchema } from "./entity-edge.ts";
import type { AdaptedDocument } from "./adapted-document.ts";
import { AdaptedDocumentSchema } from "./adapted-document.js";
import { MemoryEdgeHintSchema } from "./entity-edge.js";
import type { AdaptedDocument } from "./adapted-document.js";

/**
* Claim-bearing write shape: a distilled claim is a normal AdaptedDocument
Expand Down
4 changes: 2 additions & 2 deletions src/core/schemas/document.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { type } from "arktype";
import {
MemoryDocumentSchema,
MemoryVersionSchema,
} from "./document.ts";
import type { MemoryDocument, MemoryVersion } from "./document.ts";
} from "./document.js";
import type { MemoryDocument, MemoryVersion } from "./document.js";

describe("MemoryDocumentSchema", () => {
it("round-trips a full fixture", () => {
Expand Down
2 changes: 1 addition & 1 deletion src/core/schemas/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
RETENTION_CLASSES,
TEMPORAL_CLASSES,
arktypeStringUnion,
} from "../enums.ts";
} from "../enums.js";

export const MemoryVersionStatusSchema = type(
"'active'|'superseded'|'deprecated'|'archived'|'tombstoned'",
Expand Down
4 changes: 2 additions & 2 deletions src/core/schemas/entity-edge.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import {
MemoryEdgeHintSchema,
MemoryEdgeSchema,
MemoryEntitySchema,
} from "./entity-edge.ts";
import type { MemoryEdge } from "./entity-edge.ts";
} from "./entity-edge.js";
import type { MemoryEdge } from "./entity-edge.js";

describe("MemoryEntitySchema", () => {
it("round-trips a full fixture", () => {
Expand Down
Loading
Loading