mnemocyte 0.3.0 → 0.5.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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"postgres-BHQ1pj16.mjs","names":["timestampParam","insertMemoryRows","vectorSearchQuery","lexicalSearchQuery","getMemoryEmbeddingsQuery","deleteMemoryQuery","deleteMemoriesForEntityQuery","findDuplicatePairsQuery"],"sources":["../src/db/vector.ts","../src/db/schema.ts","../src/db/index.ts","../src/db/cancellation.ts","../src/db/queries/events.ts","../src/db/queries/memories.ts","../src/db/queries/meta.ts","../src/memory/postgres-records.ts","../src/memory/postgres.ts"],"sourcesContent":["export function formatVectorComponent(value: number): string {\n\tif (!Number.isFinite(value)) {\n\t\tthrow new Error(\"Vector values must be finite numbers.\");\n\t}\n\treturn Object.is(value, -0) ? \"0\" : value.toString();\n}\n","import { sql } from \"drizzle-orm\";\nimport {\n\ttype AnyPgColumn,\n\tcustomType,\n\tindex,\n\tinteger,\n\tjsonb,\n\tpgTable,\n\treal,\n\ttext,\n\ttimestamp,\n} from \"drizzle-orm/pg-core\";\nimport type { JsonObject } from \"../types.js\";\nimport { formatVectorComponent } from \"./vector.js\";\n\nconst vector = customType<{\n\tdata: number[];\n\tdriverData: string;\n\tconfig: { dimensions?: number };\n}>({\n\tdataType(config) {\n\t\tconst dimensions = config?.dimensions ?? 1536;\n\t\treturn `vector(${dimensions})`;\n\t},\n\ttoDriver(value) {\n\t\treturn `[${value.map(formatVectorComponent).join(\",\")}]`;\n\t},\n\tfromDriver(value) {\n\t\treturn value.slice(1, -1).split(\",\").filter(Boolean).map(Number);\n\t},\n});\n\nexport const memoriesTable = pgTable(\n\t\"mnemocyte_memories\",\n\t{\n\t\tid: text(\"id\").primaryKey(),\n\t\tentityId: text(\"entity_id\").notNull(),\n\t\tcontent: text(\"content\").notNull(),\n\t\ttype: text(\"type\").notNull().default(\"fact\"),\n\t\timportance: text(\"importance\").notNull().default(\"normal\"),\n\t\ttags: text(\"tags\").array().notNull().default(sql`'{}'::text[]`),\n\t\tsource: text(\"source\"),\n\t\tmetadata: jsonb(\"metadata\").$type<JsonObject>().notNull().default({}),\n\t\tconfidence: real(\"confidence\").notNull().default(1),\n\t\tembedding: vector(\"embedding\", { dimensions: 1536 }),\n\t\tembeddingModel: text(\"embedding_model\").notNull(),\n\t\tembeddingDimensions: integer(\"embedding_dimensions\").notNull(),\n\t\tsupersededBy: text(\"superseded_by\").references(\n\t\t\t(): AnyPgColumn => memoriesTable.id,\n\t\t),\n\t\tsupersededAt: timestamp(\"superseded_at\", { withTimezone: true }),\n\t\texpiresAt: timestamp(\"expires_at\", { withTimezone: true }),\n\t\tlastAccessedAt: timestamp(\"last_accessed_at\", { withTimezone: true }),\n\t\taccessCount: integer(\"access_count\").notNull().default(0),\n\t\tcreatedAt: timestamp(\"created_at\", { withTimezone: true })\n\t\t\t.notNull()\n\t\t\t.defaultNow(),\n\t\tupdatedAt: timestamp(\"updated_at\", { withTimezone: true })\n\t\t\t.notNull()\n\t\t\t.defaultNow(),\n\t},\n\t(table) => [\n\t\tindex(\"mnemocyte_memories_entity_idx\").on(table.entityId),\n\t\tindex(\"mnemocyte_memories_entity_type_idx\").on(table.entityId, table.type),\n\t\tindex(\"mnemocyte_memories_embedding_hnsw_idx\").using(\n\t\t\t\"hnsw\",\n\t\t\ttable.embedding.op(\"vector_cosine_ops\"),\n\t\t),\n\t],\n);\n\nexport const eventsTable = pgTable(\n\t\"mnemocyte_events\",\n\t{\n\t\tid: text(\"id\").primaryKey(),\n\t\tentityId: text(\"entity_id\").notNull(),\n\t\tdescription: text(\"description\").notNull(),\n\t\tmetadata: jsonb(\"metadata\").$type<JsonObject>().notNull().default({}),\n\t\ttimestamp: timestamp(\"timestamp\", { withTimezone: true })\n\t\t\t.notNull()\n\t\t\t.defaultNow(),\n\t},\n\t(table) => [\n\t\tindex(\"mnemocyte_events_entity_time_idx\").on(\n\t\t\ttable.entityId,\n\t\t\ttable.timestamp,\n\t\t),\n\t],\n);\n\nexport const metaTable = pgTable(\"mnemocyte_meta\", {\n\tkey: text(\"key\").primaryKey(),\n\tembeddingDimensions: integer(\"embedding_dimensions\").notNull(),\n\tembeddingModel: text(\"embedding_model\"),\n});\n\nexport type MemoryRow = typeof memoriesTable.$inferSelect;\nexport type NewMemoryRow = typeof memoriesTable.$inferInsert;\nexport type EventRow = typeof eventsTable.$inferSelect;\nexport type NewEventRow = typeof eventsTable.$inferInsert;\nexport type MetaRow = typeof metaTable.$inferSelect;\n","import { drizzle, type PostgresJsDatabase } from \"drizzle-orm/postgres-js\";\nimport postgres from \"postgres\";\nimport { parsePostgresDatabaseUrl } from \"../database-url.js\";\nimport * as schema from \"./schema.js\";\n\nexport type MnemocyteDatabase = PostgresJsDatabase<Record<string, unknown>>;\n\nexport interface DatabaseHandle {\n\tdb: MnemocyteDatabase;\n\tclose(): Promise<void>;\n}\n\nexport function createCallerOwnedDatabaseHandle<\n\tTSchema extends Record<string, unknown>,\n>(db: PostgresJsDatabase<TSchema>): DatabaseHandle {\n\treturn {\n\t\tdb,\n\t\tasync close() {},\n\t};\n}\n\ntype PostgresSslMode =\n\t| \"require\"\n\t| \"prefer\"\n\t| \"allow\"\n\t| \"verify-full\"\n\t| \"disable\";\n\ntype ValidPostgresSsl =\n\t| \"require\"\n\t| \"prefer\"\n\t| \"allow\"\n\t| \"verify-full\"\n\t| boolean\n\t| { rejectUnauthorized: false };\n\nfunction parseSslFromUrl(url: URL): ValidPostgresSsl | undefined {\n\tconst mode = url.searchParams.get(\"sslmode\") as PostgresSslMode | null;\n\tif (!mode || mode === \"disable\") return undefined;\n\n\tif (mode === \"require\" || mode === \"prefer\" || mode === \"allow\") {\n\t\treturn { rejectUnauthorized: false };\n\t}\n\n\tif (mode === \"verify-full\") return \"verify-full\";\n\n\treturn undefined;\n}\n\nexport function createDatabase(databaseUrl: string): DatabaseHandle {\n\tconst url = parsePostgresDatabaseUrl(databaseUrl);\n\tconst ssl = parseSslFromUrl(url);\n\n\tconst isPooler =\n\t\turl.port === \"6543\" || url.searchParams.get(\"pgbouncer\") === \"true\";\n\n\tconst client = postgres(databaseUrl, {\n\t\tmax: 10,\n\t\tidle_timeout: 20,\n\t\tconnect_timeout: 10,\n\t\t...(ssl ? { ssl } : {}),\n\t\t...(isPooler ? { prepare: false } : {}),\n\t});\n\n\treturn {\n\t\tdb: drizzle(client, { schema }),\n\t\tasync close() {\n\t\t\tawait client.end();\n\t\t},\n\t};\n}\n","import type { SQL } from \"drizzle-orm\";\nimport { PgDialect } from \"drizzle-orm/pg-core\";\nimport type { Sql } from \"postgres\";\nimport { MnemocyteError } from \"../errors.js\";\nimport { throwIfAborted } from \"../resilience.js\";\nimport type { MnemocyteDatabase } from \"./index.js\";\n\nconst postgresDialect = new PgDialect();\n\ninterface CancelableQuery<T> extends PromiseLike<T> {\n\tcancel(): void;\n}\n\nasync function awaitCancelableQuery<T>(\n\tquery: CancelableQuery<T>,\n\tsignal: AbortSignal | undefined,\n): Promise<T> {\n\tthrowIfAborted(signal);\n\tif (!signal) {\n\t\treturn await query;\n\t}\n\tconst onAbort = (): void => {\n\t\tquery.cancel();\n\t};\n\tsignal.addEventListener(\"abort\", onAbort, { once: true });\n\ttry {\n\t\treturn await query;\n\t} catch (error) {\n\t\tif (signal.aborted) {\n\t\t\tthrow new MnemocyteError(\n\t\t\t\t\"Operation was aborted.\",\n\t\t\t\t\"ABORTED\",\n\t\t\t\tsignal.reason,\n\t\t\t);\n\t\t}\n\t\tthrow error;\n\t} finally {\n\t\tsignal.removeEventListener(\"abort\", onAbort);\n\t}\n}\n\nexport async function executeCancelableSql<T>(\n\tdb: MnemocyteDatabase,\n\tstatement: SQL,\n\tsignal: AbortSignal | undefined,\n): Promise<T> {\n\tconst query = postgresDialect.sqlToQuery(statement);\n\tconst client = (db as MnemocyteDatabase & { $client?: Sql }).$client;\n\tif (!client) {\n\t\tthrow new MnemocyteError(\n\t\t\t\"Cancelable Postgres query requires the postgres.js client.\",\n\t\t\t\"DB\",\n\t\t);\n\t}\n\treturn (await awaitCancelableQuery(\n\t\tclient.unsafe(query.sql, query.params as never[]),\n\t\tsignal,\n\t)) as T;\n}\n","import { sql } from \"drizzle-orm\";\nimport { MnemocyteError } from \"../../errors.js\";\nimport type { AuditLogCursor } from \"../../types.js\";\nimport { executeCancelableSql } from \"../cancellation.js\";\nimport type { MnemocyteDatabase } from \"../index.js\";\nimport { type EventRow, eventsTable, type NewEventRow } from \"../schema.js\";\n\nexport interface EventFilter {\n\tentityId: string;\n\tlimit?: number;\n\tbefore?: Date;\n\tafter?: Date;\n\tbeforeCursor?: AuditLogCursor;\n\tafterCursor?: AuditLogCursor;\n}\n\nfunction timestampParam(value: Date) {\n\treturn sql`${value.toISOString()}::timestamptz`;\n}\n\nexport async function insertEvent(\n\tdb: MnemocyteDatabase,\n\trow: NewEventRow,\n): Promise<EventRow> {\n\tconst result = await db.insert(eventsTable).values(row).returning();\n\tconst inserted = result[0];\n\tif (!inserted) {\n\t\tthrow new MnemocyteError(\"Event insert returned no rows.\", \"DB\");\n\t}\n\treturn inserted;\n}\n\nexport async function listEvents(\n\tdb: MnemocyteDatabase,\n\tfilter: EventFilter,\n\tsignal?: AbortSignal,\n): Promise<EventRow[]> {\n\treturn executeCancelableSql<EventRow[]>(\n\t\tdb,\n\t\tsql`\n\t\t\tSELECT\n\t\t\t\tid,\n\t\t\t\tentity_id AS \"entityId\",\n\t\t\t\tdescription,\n\t\t\t\tmetadata,\n\t\t\t\ttimestamp\n\t\t\tFROM mnemocyte_events\n\t\t\tWHERE entity_id = ${filter.entityId}\n\t\t\t\t${filter.before ? sql`AND timestamp < ${timestampParam(filter.before)}` : sql``}\n\t\t\t\t${filter.after ? sql`AND timestamp > ${timestampParam(filter.after)}` : sql``}\n\t\t\t\t${\n\t\t\t\t\tfilter.beforeCursor\n\t\t\t\t\t\t? sql`AND (timestamp, id) < (${timestampParam(filter.beforeCursor.timestamp)}, ${filter.beforeCursor.id})`\n\t\t\t\t\t\t: sql``\n\t\t\t\t}\n\t\t\t\t${\n\t\t\t\t\tfilter.afterCursor\n\t\t\t\t\t\t? sql`AND (timestamp, id) > (${timestampParam(filter.afterCursor.timestamp)}, ${filter.afterCursor.id})`\n\t\t\t\t\t\t: sql``\n\t\t\t\t}\n\t\t\tORDER BY timestamp DESC, id DESC\n\t\t\tLIMIT ${filter.limit ?? 50}\n\t\t`,\n\t\tsignal,\n\t);\n}\n","import {\n\tand,\n\tcount,\n\tcountDistinct,\n\teq,\n\tinArray,\n\tisNotNull,\n\tisNull,\n\tlt,\n\tor,\n\ttype SQL,\n\tsql,\n} from \"drizzle-orm\";\nimport type { ImportanceLevel, MemoryType } from \"../../types.js\";\nimport { executeCancelableSql } from \"../cancellation.js\";\nimport type { MnemocyteDatabase } from \"../index.js\";\nimport { type MemoryRow, memoriesTable, type NewMemoryRow } from \"../schema.js\";\nimport { formatVectorComponent } from \"../vector.js\";\n\nexport interface MemoryFilter {\n\tentityId: string;\n\ttypes?: readonly MemoryType[];\n\ttags?: readonly string[];\n\tbefore?: Date;\n\tafter?: Date;\n\tincludeSuperseded?: boolean;\n\tincludeExpired?: boolean;\n}\n\nexport interface VectorSearchInput extends MemoryFilter {\n\tembedding: readonly number[];\n\tlimit: number;\n\tminVectorScore?: number;\n}\n\nexport interface LexicalSearchInput extends MemoryFilter {\n\tquery: string;\n\tlimit: number;\n}\n\nexport interface MemoryStatsCounts {\n\tmemoryCount: number;\n\tactiveMemoryCount: number;\n\texpiredMemoryCount: number;\n\tsupersededMemoryCount: number;\n}\n\nexport interface GuardedDeleteResult {\n\tmatchedCount: number;\n\tdeletedCount: number;\n\thasDependents: boolean;\n\tdeletedByEntity: Array<{ entityId: string; deletedCount: number }>;\n}\n\nexport interface GlobalMemoryStatsCounts extends MemoryStatsCounts {\n\tentityCount: number;\n}\n\nfunction vectorLiteral(embedding: readonly number[]): string {\n\treturn `[${embedding.map(formatVectorComponent).join(\",\")}]`;\n}\n\nfunction clampedVectorScore(embedding: string) {\n\tconst rawScore = sql`1 - (embedding <=> ${embedding}::vector)`;\n\treturn sql<number>`\n\t\tCASE\n\t\t\tWHEN ${rawScore} = 'NaN'::double precision\n\t\t\t\tOR ${rawScore} = 'Infinity'::double precision\n\t\t\t\tOR ${rawScore} = '-Infinity'::double precision\n\t\t\t\tTHEN 0::double precision\n\t\t\tELSE GREATEST(\n\t\t\t\t0::double precision,\n\t\t\t\tLEAST(1::double precision, ${rawScore})\n\t\t\t)\n\t\tEND\n\t`;\n}\n\ntype RawTimestamp = Date | string;\n\nexport type RecallMemoryRow = Omit<\n\tMemoryRow,\n\t| \"embedding\"\n\t| \"supersededAt\"\n\t| \"expiresAt\"\n\t| \"lastAccessedAt\"\n\t| \"createdAt\"\n\t| \"updatedAt\"\n> & {\n\tsupersededAt: RawTimestamp | null;\n\texpiresAt: RawTimestamp | null;\n\tlastAccessedAt: RawTimestamp | null;\n\tcreatedAt: RawTimestamp;\n\tupdatedAt: RawTimestamp;\n};\n\nexport type VectorSearchRow = RecallMemoryRow & { vectorScore: number };\n\nexport type LexicalSearchRow = RecallMemoryRow & { lexicalScore: number };\n\nfunction timestampParam(value: Date) {\n\treturn sql`${value.toISOString()}::timestamptz`;\n}\n\nfunction textArrayLiteral(values: readonly string[]) {\n\treturn sql`ARRAY[${sql.join(\n\t\tvalues.map((value) => sql`${value}`),\n\t\tsql`, `,\n\t)}]::text[]`;\n}\n\nfunction tagsContainAll(tags: readonly string[] | undefined) {\n\treturn tags && tags.length > 0\n\t\t? sql`${memoriesTable.tags} @> ${textArrayLiteral(tags)}`\n\t\t: undefined;\n}\n\nfunction rawTagsFilter(tags: readonly string[] | undefined) {\n\treturn tags && tags.length > 0\n\t\t? sql`AND tags @> ${textArrayLiteral(tags)}`\n\t\t: sql``;\n}\n\nfunction duplicateTagsFilter(tags: readonly string[] | undefined) {\n\treturn tags && tags.length > 0\n\t\t? sql`AND a.tags @> ${textArrayLiteral(tags)} AND b.tags @> ${textArrayLiteral(tags)}`\n\t\t: sql``;\n}\n\nfunction memoryStatsCountFields(now: Date) {\n\treturn {\n\t\tmemoryCount: count(),\n\t\tactiveMemoryCount: sql<number>`\n\t\t\t(count(*) FILTER (\n\t\t\t\tWHERE ${memoriesTable.supersededBy} IS NULL\n\t\t\t\t\tAND (${memoriesTable.expiresAt} IS NULL OR ${memoriesTable.expiresAt} > ${timestampParam(now)})\n\t\t\t))::int\n\t\t`.mapWith(Number),\n\t\texpiredMemoryCount: sql<number>`\n\t\t\t(count(*) FILTER (\n\t\t\t\tWHERE ${memoriesTable.expiresAt} IS NOT NULL\n\t\t\t\t\tAND ${memoriesTable.expiresAt} <= ${timestampParam(now)}\n\t\t\t))::int\n\t\t`.mapWith(Number),\n\t\tsupersededMemoryCount:\n\t\t\tsql<number>`(count(*) FILTER (WHERE ${memoriesTable.supersededBy} IS NOT NULL))::int`.mapWith(\n\t\t\t\tNumber,\n\t\t\t),\n\t};\n}\n\nfunction emptyMemoryStatsCounts(): MemoryStatsCounts {\n\treturn {\n\t\tmemoryCount: 0,\n\t\tactiveMemoryCount: 0,\n\t\texpiredMemoryCount: 0,\n\t\tsupersededMemoryCount: 0,\n\t};\n}\n\nexport async function insertMemories(\n\tdb: MnemocyteDatabase,\n\trows: NewMemoryRow[],\n): Promise<MemoryRow[]> {\n\tif (rows.length === 0) {\n\t\treturn [];\n\t}\n\treturn db.insert(memoriesTable).values(rows).returning();\n}\n\nexport async function getMemoryById(\n\tdb: MnemocyteDatabase,\n\tentityId: string,\n\tmemoryId: string,\n): Promise<MemoryRow | null> {\n\tconst result = await db\n\t\t.select()\n\t\t.from(memoriesTable)\n\t\t.where(\n\t\t\tand(eq(memoriesTable.entityId, entityId), eq(memoriesTable.id, memoryId)),\n\t\t)\n\t\t.limit(1);\n\treturn result[0] ?? null;\n}\n\nexport async function getEntityMemoryStatsCounts(\n\tdb: MnemocyteDatabase,\n\tentityId: string,\n\tnow: Date,\n): Promise<MemoryStatsCounts> {\n\tconst rows = await db\n\t\t.select(memoryStatsCountFields(now))\n\t\t.from(memoriesTable)\n\t\t.where(eq(memoriesTable.entityId, entityId));\n\treturn rows[0] ?? emptyMemoryStatsCounts();\n}\n\nexport async function getGlobalMemoryStatsCounts(\n\tdb: MnemocyteDatabase,\n\tnow: Date,\n): Promise<GlobalMemoryStatsCounts> {\n\tconst rows = await db\n\t\t.select({\n\t\t\tentityCount: countDistinct(memoriesTable.entityId),\n\t\t\t...memoryStatsCountFields(now),\n\t\t})\n\t\t.from(memoriesTable);\n\treturn rows[0] ?? { entityCount: 0, ...emptyMemoryStatsCounts() };\n}\n\nexport async function deleteMemory(\n\tdb: MnemocyteDatabase,\n\tentityId: string,\n\tmemoryId: string,\n): Promise<GuardedDeleteResult> {\n\treturn deleteMemoriesWithDependentGuard(\n\t\tdb,\n\t\tand(eq(memoriesTable.entityId, entityId), eq(memoriesTable.id, memoryId)),\n\t);\n}\n\nexport async function deleteMemoriesForEntity(\n\tdb: MnemocyteDatabase,\n\tentityId: string,\n): Promise<GuardedDeleteResult> {\n\treturn deleteMemoriesWithDependentGuard(\n\t\tdb,\n\t\teq(memoriesTable.entityId, entityId),\n\t);\n}\n\nexport interface PruneFilter {\n\tentityId?: string;\n\texpired?: boolean;\n\tsuperseded?: boolean;\n\tcreatedBefore?: Date;\n\tnotAccessedSince?: Date;\n\ttypes?: readonly MemoryType[];\n\ttags?: readonly string[];\n\tmaxImportanceLevels?: readonly ImportanceLevel[];\n}\n\nfunction pruneConditions(filter: PruneFilter) {\n\treturn and(\n\t\tfilter.entityId !== undefined\n\t\t\t? eq(memoriesTable.entityId, filter.entityId)\n\t\t\t: undefined,\n\t\tfilter.expired\n\t\t\t? and(\n\t\t\t\t\tisNotNull(memoriesTable.expiresAt),\n\t\t\t\t\tsql`${memoriesTable.expiresAt} <= now()`,\n\t\t\t\t)\n\t\t\t: undefined,\n\t\tfilter.superseded ? isNotNull(memoriesTable.supersededBy) : undefined,\n\t\tfilter.createdBefore\n\t\t\t? lt(memoriesTable.createdAt, filter.createdBefore)\n\t\t\t: undefined,\n\t\tfilter.notAccessedSince\n\t\t\t? or(\n\t\t\t\t\tisNull(memoriesTable.lastAccessedAt),\n\t\t\t\t\tlt(memoriesTable.lastAccessedAt, filter.notAccessedSince),\n\t\t\t\t)\n\t\t\t: undefined,\n\t\tfilter.types && filter.types.length > 0\n\t\t\t? inArray(memoriesTable.type, [...filter.types])\n\t\t\t: undefined,\n\t\ttagsContainAll(filter.tags),\n\t\tfilter.maxImportanceLevels && filter.maxImportanceLevels.length > 0\n\t\t\t? inArray(memoriesTable.importance, [...filter.maxImportanceLevels])\n\t\t\t: undefined,\n\t);\n}\n\nexport async function countPruneMatches(\n\tdb: MnemocyteDatabase,\n\tfilter: PruneFilter,\n\tsignal?: AbortSignal,\n): Promise<number> {\n\tconst conditions = pruneConditions(filter);\n\tconst rows = await executeCancelableSql<Array<{ count: number | string }>>(\n\t\tdb,\n\t\tsql`\n\t\t\tSELECT count(*)::int AS count\n\t\t\tFROM ${memoriesTable}\n\t\t\t${conditions ? sql`WHERE ${conditions}` : sql``}\n\t\t`,\n\t\tsignal,\n\t);\n\treturn Number(rows[0]?.count ?? 0);\n}\n\nexport async function pruneMemories(\n\tdb: MnemocyteDatabase,\n\tfilter: PruneFilter,\n\tsignal?: AbortSignal,\n): Promise<GuardedDeleteResult> {\n\tconst conditions = pruneConditions(filter);\n\treturn deleteMemoriesWithDependentGuard(db, conditions, signal);\n}\n\nasync function deleteMemoriesWithDependentGuard(\n\tdb: MnemocyteDatabase,\n\tconditions: SQL | undefined,\n\tsignal?: AbortSignal,\n): Promise<GuardedDeleteResult> {\n\tconst rows = await executeCancelableSql<\n\t\tArray<{\n\t\t\tmatchedCount: number | string;\n\t\t\tdeletedCount: number | string;\n\t\t\thasDependents: boolean;\n\t\t\tentityId: string | null;\n\t\t\tentityDeletedCount: number | string | null;\n\t\t}>\n\t>(\n\t\tdb,\n\t\tsql`\n\t\t\tWITH candidates AS MATERIALIZED (\n\t\t\t\tSELECT id, entity_id\n\t\t\t\tFROM ${memoriesTable}\n\t\t\t\t${conditions ? sql`WHERE ${conditions}` : sql``}\n\t\t\t),\n\t\t\tdependents AS MATERIALIZED (\n\t\t\t\tSELECT 1\n\t\t\t\tFROM ${memoriesTable} AS dependent\n\t\t\t\tINNER JOIN candidates AS target\n\t\t\t\t\tON dependent.superseded_by = target.id\n\t\t\t\tLIMIT 1\n\t\t\t),\n\t\t\tdeleted AS (\n\t\t\t\tDELETE FROM ${memoriesTable}\n\t\t\t\tWHERE ${memoriesTable.id} IN (SELECT id FROM candidates)\n\t\t\t\t\tAND NOT EXISTS (SELECT 1 FROM dependents)\n\t\t\t\tRETURNING id, entity_id\n\t\t\t),\n\t\t\tdeleted_counts AS (\n\t\t\t\tSELECT entity_id, count(*)::int AS deleted_count\n\t\t\t\tFROM deleted\n\t\t\t\tGROUP BY entity_id\n\t\t\t),\n\t\t\tsummary AS (\n\t\t\t\tSELECT\n\t\t\t\t\t(SELECT count(*)::int FROM candidates) AS matched_count,\n\t\t\t\t\t(SELECT count(*)::int FROM deleted) AS deleted_count,\n\t\t\t\t\tEXISTS (SELECT 1 FROM dependents) AS has_dependents\n\t\t\t)\n\t\t\tSELECT\n\t\t\t\tsummary.matched_count AS \"matchedCount\",\n\t\t\t\tsummary.deleted_count AS \"deletedCount\",\n\t\t\t\tsummary.has_dependents AS \"hasDependents\",\n\t\t\t\tdeleted_counts.entity_id AS \"entityId\",\n\t\t\t\tdeleted_counts.deleted_count AS \"entityDeletedCount\"\n\t\t\tFROM summary\n\t\t\tLEFT JOIN deleted_counts ON true\n\t\t\tORDER BY deleted_counts.entity_id\n\t\t`,\n\t\tsignal,\n\t);\n\tconst row = rows[0];\n\treturn {\n\t\tmatchedCount: Number(row?.matchedCount ?? 0),\n\t\tdeletedCount: Number(row?.deletedCount ?? 0),\n\t\thasDependents: row?.hasDependents === true,\n\t\tdeletedByEntity: rows.flatMap((detail) =>\n\t\t\tdetail.entityId === null\n\t\t\t\t? []\n\t\t\t\t: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tentityId: detail.entityId,\n\t\t\t\t\t\t\tdeletedCount: Number(detail.entityDeletedCount ?? 0),\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t),\n\t};\n}\n\nexport interface DuplicateSearchInput {\n\tentityId: string;\n\tthreshold: number;\n\tlimit: number;\n\ttypes?: readonly string[];\n\ttags?: readonly string[];\n\tincludeSuperseded?: boolean;\n\tincludeExpired?: boolean;\n}\n\nexport async function findDuplicatePairs(\n\tdb: MnemocyteDatabase,\n\tinput: DuplicateSearchInput,\n\tsignal?: AbortSignal,\n): Promise<Array<{ a: MemoryRow; b: MemoryRow; similarity: number }>> {\n\tconst rows = await executeCancelableSql<Array<Record<string, unknown>>>(\n\t\tdb,\n\t\tsql`\n\t\t\tSELECT\n\t\t\t\ta.id AS \"aId\",\n\t\t\t\ta.entity_id AS \"aEntityId\",\n\t\t\t\ta.content AS \"aContent\",\n\t\t\t\ta.type AS \"aType\",\n\t\t\t\ta.importance AS \"aImportance\",\n\t\t\t\ta.tags AS \"aTags\",\n\t\t\t\ta.source AS \"aSource\",\n\t\t\t\ta.metadata AS \"aMetadata\",\n\t\t\t\ta.confidence AS \"aConfidence\",\n\t\t\t\ta.embedding AS \"aEmbedding\",\n\t\t\t\ta.embedding_model AS \"aEmbeddingModel\",\n\t\t\t\ta.embedding_dimensions AS \"aEmbeddingDimensions\",\n\t\t\t\ta.superseded_by AS \"aSupersededBy\",\n\t\t\t\ta.superseded_at AS \"aSupersededAt\",\n\t\t\t\ta.expires_at AS \"aExpiresAt\",\n\t\t\t\ta.last_accessed_at AS \"aLastAccessedAt\",\n\t\t\t\ta.access_count AS \"aAccessCount\",\n\t\t\t\ta.created_at AS \"aCreatedAt\",\n\t\t\t\ta.updated_at AS \"aUpdatedAt\",\n\t\t\t\tb.id AS \"bId\",\n\t\t\t\tb.entity_id AS \"bEntityId\",\n\t\t\t\tb.content AS \"bContent\",\n\t\t\t\tb.type AS \"bType\",\n\t\t\t\tb.importance AS \"bImportance\",\n\t\t\t\tb.tags AS \"bTags\",\n\t\t\t\tb.source AS \"bSource\",\n\t\t\t\tb.metadata AS \"bMetadata\",\n\t\t\t\tb.confidence AS \"bConfidence\",\n\t\t\t\tb.embedding AS \"bEmbedding\",\n\t\t\t\tb.embedding_model AS \"bEmbeddingModel\",\n\t\t\t\tb.embedding_dimensions AS \"bEmbeddingDimensions\",\n\t\t\t\tb.superseded_by AS \"bSupersededBy\",\n\t\t\t\tb.superseded_at AS \"bSupersededAt\",\n\t\t\t\tb.expires_at AS \"bExpiresAt\",\n\t\t\t\tb.last_accessed_at AS \"bLastAccessedAt\",\n\t\t\t\tb.access_count AS \"bAccessCount\",\n\t\t\t\tb.created_at AS \"bCreatedAt\",\n\t\t\t\tb.updated_at AS \"bUpdatedAt\",\n\t\t\t\t1 - (a.embedding <=> b.embedding) AS \"similarity\"\n\t\t\tFROM mnemocyte_memories a\n\t\t\tJOIN mnemocyte_memories b\n\t\t\t\tON b.entity_id = a.entity_id\n\t\t\t\tAND a.id < b.id\n\t\t\t\tAND a.embedding IS NOT NULL\n\t\t\t\tAND b.embedding IS NOT NULL\n\t\t\tWHERE\n\t\t\t\ta.entity_id = ${input.entityId}\n\t\t\t\t${input.includeSuperseded ? sql`` : sql`AND a.superseded_by IS NULL AND b.superseded_by IS NULL`}\n\t\t\t\t${input.includeExpired ? sql`` : sql`AND (a.expires_at IS NULL OR a.expires_at > now()) AND (b.expires_at IS NULL OR b.expires_at > now())`}\n\t\t\t\t${\n\t\t\t\t\tinput.types && input.types.length > 0\n\t\t\t\t\t\t? sql`AND a.type IN (${sql.join(\n\t\t\t\t\t\t\t\tinput.types.map((type) => sql`${type}`),\n\t\t\t\t\t\t\t\tsql`, `,\n\t\t\t\t\t\t\t)}) AND b.type IN (${sql.join(\n\t\t\t\t\t\t\t\tinput.types.map((type) => sql`${type}`),\n\t\t\t\t\t\t\t\tsql`, `,\n\t\t\t\t\t\t\t)})`\n\t\t\t\t\t\t: sql``\n\t\t\t\t}\n\t\t\t\t${duplicateTagsFilter(input.tags)}\n\t\t\t\tAND 1 - (a.embedding <=> b.embedding) >= ${input.threshold}\n\t\t\tORDER BY \"similarity\" DESC\n\t\t\tLIMIT ${input.limit}\n\t\t`,\n\t\tsignal,\n\t);\n\treturn rows.map((row) => {\n\t\tconst a = {\n\t\t\tid: row.aId,\n\t\t\tentityId: row.aEntityId,\n\t\t\tcontent: row.aContent,\n\t\t\ttype: row.aType,\n\t\t\timportance: row.aImportance,\n\t\t\ttags: row.aTags,\n\t\t\tsource: row.aSource,\n\t\t\tmetadata: row.aMetadata,\n\t\t\tconfidence: row.aConfidence,\n\t\t\tembedding: row.aEmbedding,\n\t\t\tembeddingModel: row.aEmbeddingModel,\n\t\t\tembeddingDimensions: row.aEmbeddingDimensions,\n\t\t\tsupersededBy: row.aSupersededBy,\n\t\t\tsupersededAt: row.aSupersededAt,\n\t\t\texpiresAt: row.aExpiresAt,\n\t\t\tlastAccessedAt: row.aLastAccessedAt,\n\t\t\taccessCount: row.aAccessCount,\n\t\t\tcreatedAt: row.aCreatedAt,\n\t\t\tupdatedAt: row.aUpdatedAt,\n\t\t} as unknown as MemoryRow;\n\t\tconst b = {\n\t\t\tid: row.bId,\n\t\t\tentityId: row.bEntityId,\n\t\t\tcontent: row.bContent,\n\t\t\ttype: row.bType,\n\t\t\timportance: row.bImportance,\n\t\t\ttags: row.bTags,\n\t\t\tsource: row.bSource,\n\t\t\tmetadata: row.bMetadata,\n\t\t\tconfidence: row.bConfidence,\n\t\t\tembedding: row.bEmbedding,\n\t\t\tembeddingModel: row.bEmbeddingModel,\n\t\t\tembeddingDimensions: row.bEmbeddingDimensions,\n\t\t\tsupersededBy: row.bSupersededBy,\n\t\t\tsupersededAt: row.bSupersededAt,\n\t\t\texpiresAt: row.bExpiresAt,\n\t\t\tlastAccessedAt: row.bLastAccessedAt,\n\t\t\taccessCount: row.bAccessCount,\n\t\t\tcreatedAt: row.bCreatedAt,\n\t\t\tupdatedAt: row.bUpdatedAt,\n\t\t} as unknown as MemoryRow;\n\t\treturn {\n\t\t\ta,\n\t\t\tb,\n\t\t\tsimilarity: Number(row.similarity) || 0,\n\t\t};\n\t});\n}\n\nexport interface SupersedeRow {\n\tid: string;\n\ttags: string[];\n}\n\nexport async function loadConsolidationTargets(\n\tdb: MnemocyteDatabase,\n\tentityId: string,\n\tids: readonly string[],\n): Promise<Array<{ id: string; tags: string[]; supersededBy: string | null }>> {\n\tif (ids.length === 0) {\n\t\treturn [];\n\t}\n\tconst rows = await db\n\t\t.select({\n\t\t\tid: memoriesTable.id,\n\t\t\ttags: memoriesTable.tags,\n\t\t\tsupersededBy: memoriesTable.supersededBy,\n\t\t})\n\t\t.from(memoriesTable)\n\t\t.where(\n\t\t\tand(\n\t\t\t\teq(memoriesTable.entityId, entityId),\n\t\t\t\tinArray(memoriesTable.id, [...ids]),\n\t\t\t),\n\t\t);\n\treturn rows;\n}\n\nexport async function lockConsolidationMemories(\n\tdb: MnemocyteDatabase,\n\tentityId: string,\n\tsurvivorId: string,\n\tsupersededIds: readonly string[],\n): Promise<Array<{ id: string; tags: string[]; supersededBy: string | null }>> {\n\tconst ids = [...new Set([survivorId, ...supersededIds])].sort();\n\treturn db\n\t\t.select({\n\t\t\tid: memoriesTable.id,\n\t\t\ttags: memoriesTable.tags,\n\t\t\tsupersededBy: memoriesTable.supersededBy,\n\t\t})\n\t\t.from(memoriesTable)\n\t\t.where(\n\t\t\tand(eq(memoriesTable.entityId, entityId), inArray(memoriesTable.id, ids)),\n\t\t)\n\t\t.orderBy(memoriesTable.id)\n\t\t.for(\"update\");\n}\n\nexport async function markMemoriesSuperseded(\n\tdb: MnemocyteDatabase,\n\tparams: {\n\t\tsurvivorId: string;\n\t\tentityId: string;\n\t\tids: readonly string[];\n\t\tnow: Date;\n\t},\n): Promise<SupersedeRow[]> {\n\tif (params.ids.length === 0) {\n\t\treturn [];\n\t}\n\tconst result = await db\n\t\t.update(memoriesTable)\n\t\t.set({\n\t\t\tsupersededBy: params.survivorId,\n\t\t\tsupersededAt: params.now,\n\t\t\tupdatedAt: params.now,\n\t\t})\n\t\t.where(\n\t\t\tand(\n\t\t\t\teq(memoriesTable.entityId, params.entityId),\n\t\t\t\tinArray(memoriesTable.id, [...params.ids]),\n\t\t\t\tisNull(memoriesTable.supersededBy),\n\t\t\t),\n\t\t)\n\t\t.returning({ id: memoriesTable.id, tags: memoriesTable.tags });\n\treturn result;\n}\n\nexport async function setMemoryTags(\n\tdb: MnemocyteDatabase,\n\tparams: {\n\t\tentityId: string;\n\t\tmemoryId: string;\n\t\ttags: readonly string[];\n\t\tnow: Date;\n\t},\n): Promise<void> {\n\tawait db\n\t\t.update(memoriesTable)\n\t\t.set({ tags: [...params.tags], updatedAt: params.now })\n\t\t.where(\n\t\t\tand(\n\t\t\t\teq(memoriesTable.entityId, params.entityId),\n\t\t\t\teq(memoriesTable.id, params.memoryId),\n\t\t\t),\n\t\t);\n}\n\nexport async function markMemoriesAccessed(\n\tdb: MnemocyteDatabase,\n\tmemoryIds: readonly string[],\n): Promise<\n\tArray<{\n\t\tid: string;\n\t\tlastAccessedAt: Date | null;\n\t\taccessCount: number;\n\t\tupdatedAt: Date;\n\t}>\n> {\n\tconst now = new Date();\n\tif (memoryIds.length === 0) {\n\t\treturn [];\n\t}\n\treturn db\n\t\t.update(memoriesTable)\n\t\t.set({\n\t\t\tlastAccessedAt: now,\n\t\t\taccessCount: sql`${memoriesTable.accessCount} + 1`,\n\t\t\tupdatedAt: now,\n\t\t})\n\t\t.where(inArray(memoriesTable.id, [...memoryIds]))\n\t\t.returning({\n\t\t\tid: memoriesTable.id,\n\t\t\tlastAccessedAt: memoriesTable.lastAccessedAt,\n\t\t\taccessCount: memoriesTable.accessCount,\n\t\t\tupdatedAt: memoriesTable.updatedAt,\n\t\t});\n}\n\nexport async function getMemoryEmbeddings(\n\tdb: MnemocyteDatabase,\n\tmemoryIds: readonly string[],\n): Promise<Map<string, number[]>> {\n\tif (memoryIds.length === 0) {\n\t\treturn new Map();\n\t}\n\tconst rows = await db\n\t\t.select({\n\t\t\tid: memoriesTable.id,\n\t\t\tembedding: memoriesTable.embedding,\n\t\t})\n\t\t.from(memoriesTable)\n\t\t.where(inArray(memoriesTable.id, [...memoryIds]));\n\treturn new Map(\n\t\trows.flatMap((row) => (row.embedding ? [[row.id, row.embedding]] : [])),\n\t);\n}\n\nexport async function vectorSearch(\n\tdb: MnemocyteDatabase,\n\tinput: VectorSearchInput,\n): Promise<VectorSearchRow[]> {\n\tconst embedding = vectorLiteral(input.embedding);\n\tconst vectorScore = clampedVectorScore(embedding);\n\tconst minVectorScore = input.minVectorScore ?? 0;\n\tconst rows = await db.execute(sql`\n\t\tSELECT\n\t\t\tid,\n\t\t\tentity_id AS \"entityId\",\n\t\t\tcontent,\n\t\t\ttype,\n\t\t\timportance,\n\t\t\ttags,\n\t\t\tsource,\n\t\t\tmetadata,\n\t\t\tconfidence,\n\t\t\tembedding_model AS \"embeddingModel\",\n\t\t\tembedding_dimensions AS \"embeddingDimensions\",\n\t\t\tsuperseded_by AS \"supersededBy\",\n\t\t\tsuperseded_at AS \"supersededAt\",\n\t\t\texpires_at AS \"expiresAt\",\n\t\t\tlast_accessed_at AS \"lastAccessedAt\",\n\t\t\taccess_count AS \"accessCount\",\n\t\t\tcreated_at AS \"createdAt\",\n\t\t\tupdated_at AS \"updatedAt\",\n\t\t\t${vectorScore} AS \"vectorScore\"\n\t\tFROM mnemocyte_memories\n\t\tWHERE\n\t\t\tentity_id = ${input.entityId}\n\t\t\tAND embedding IS NOT NULL\n\t\t\t${input.includeSuperseded ? sql`` : sql`AND superseded_by IS NULL`}\n\t\t\t${input.includeExpired ? sql`` : sql`AND (expires_at IS NULL OR expires_at > now())`}\n\t\t\t${\n\t\t\t\tinput.types && input.types.length > 0\n\t\t\t\t\t? sql`AND type IN (${sql.join(\n\t\t\t\t\t\t\tinput.types.map((type) => sql`${type}`),\n\t\t\t\t\t\t\tsql`, `,\n\t\t\t\t\t\t)})`\n\t\t\t\t\t: sql``\n\t\t\t}\n\t\t\t${rawTagsFilter(input.tags)}\n\t\t\t${input.before ? sql`AND created_at < ${timestampParam(input.before)}` : sql``}\n\t\t\t${input.after ? sql`AND created_at > ${timestampParam(input.after)}` : sql``}\n\t\t\tAND ${vectorScore} >= ${minVectorScore}\n\t\tORDER BY embedding <=> ${embedding}::vector\n\t\tLIMIT ${input.limit}\n\t`);\n\treturn rows as unknown as VectorSearchRow[];\n}\n\nexport async function lexicalSearch(\n\tdb: MnemocyteDatabase,\n\tinput: LexicalSearchInput,\n): Promise<LexicalSearchRow[]> {\n\tconst rows = await db.execute(sql`\n\t\tSELECT\n\t\t\tid,\n\t\t\tentity_id AS \"entityId\",\n\t\t\tcontent,\n\t\t\ttype,\n\t\t\timportance,\n\t\t\ttags,\n\t\t\tsource,\n\t\t\tmetadata,\n\t\t\tconfidence,\n\t\t\tembedding_model AS \"embeddingModel\",\n\t\t\tembedding_dimensions AS \"embeddingDimensions\",\n\t\t\tsuperseded_by AS \"supersededBy\",\n\t\t\tsuperseded_at AS \"supersededAt\",\n\t\t\texpires_at AS \"expiresAt\",\n\t\t\tlast_accessed_at AS \"lastAccessedAt\",\n\t\t\taccess_count AS \"accessCount\",\n\t\t\tcreated_at AS \"createdAt\",\n\t\t\tupdated_at AS \"updatedAt\",\n\t\t\tts_rank(to_tsvector('english', content), websearch_to_tsquery('english', ${input.query})) AS \"lexicalScore\"\n\t\tFROM mnemocyte_memories\n\t\tWHERE\n\t\t\tentity_id = ${input.entityId}\n\t\t\t${input.includeSuperseded ? sql`` : sql`AND superseded_by IS NULL`}\n\t\t\t${input.includeExpired ? sql`` : sql`AND (expires_at IS NULL OR expires_at > now())`}\n\t\t\t${\n\t\t\t\tinput.types && input.types.length > 0\n\t\t\t\t\t? sql`AND type IN (${sql.join(\n\t\t\t\t\t\t\tinput.types.map((type) => sql`${type}`),\n\t\t\t\t\t\t\tsql`, `,\n\t\t\t\t\t\t)})`\n\t\t\t\t\t: sql``\n\t\t\t}\n\t\t\t${rawTagsFilter(input.tags)}\n\t\t\t${input.before ? sql`AND created_at < ${timestampParam(input.before)}` : sql``}\n\t\t\t${input.after ? sql`AND created_at > ${timestampParam(input.after)}` : sql``}\n\t\t\tAND to_tsvector('english', content) @@ websearch_to_tsquery('english', ${input.query})\n\t\tORDER BY \"lexicalScore\" DESC\n\t\tLIMIT ${input.limit}\n\t`);\n\treturn rows as unknown as LexicalSearchRow[];\n}\n","import { and, eq, isNull } from \"drizzle-orm\";\nimport type { MnemocyteDatabase } from \"../index.js\";\nimport { type MetaRow, memoriesTable, metaTable } from \"../schema.js\";\n\nexport const INSTALLATION_META_KEY = \"installation\";\n\nexport async function getInstallationMeta(\n\tdb: MnemocyteDatabase,\n): Promise<MetaRow | null> {\n\tconst rows = await db\n\t\t.select()\n\t\t.from(metaTable)\n\t\t.where(eq(metaTable.key, INSTALLATION_META_KEY))\n\t\t.limit(1);\n\treturn rows[0] ?? null;\n}\n\nexport async function getStoredEmbeddingModels(\n\tdb: MnemocyteDatabase,\n): Promise<string[]> {\n\tconst rows = await db\n\t\t.selectDistinct({ embeddingModel: memoriesTable.embeddingModel })\n\t\t.from(memoriesTable)\n\t\t.limit(2);\n\treturn rows.map((row) => row.embeddingModel);\n}\n\nexport async function recordInstallationEmbeddingModel(\n\tdb: MnemocyteDatabase,\n\tembeddingModel: string,\n): Promise<MetaRow | null> {\n\tconst rows = await db\n\t\t.update(metaTable)\n\t\t.set({ embeddingModel })\n\t\t.where(\n\t\t\tand(\n\t\t\t\teq(metaTable.key, INSTALLATION_META_KEY),\n\t\t\t\tisNull(metaTable.embeddingModel),\n\t\t\t),\n\t\t)\n\t\t.returning();\n\treturn rows[0] ?? null;\n}\n","import type { MemoryRow } from \"../db/schema.js\";\nimport type { ImportanceLevel, Memory, MemoryType } from \"../types.js\";\nimport { cloneJsonObject } from \"./json.js\";\n\ntype MemoryRowTimestamp = Date | string;\n\ntype MemoryLikeRow = Omit<\n\tMemoryRow,\n\t| \"embedding\"\n\t| \"supersededAt\"\n\t| \"expiresAt\"\n\t| \"lastAccessedAt\"\n\t| \"createdAt\"\n\t| \"updatedAt\"\n> & {\n\tsupersededAt: MemoryRowTimestamp | null;\n\texpiresAt: MemoryRowTimestamp | null;\n\tlastAccessedAt: MemoryRowTimestamp | null;\n\tcreatedAt: MemoryRowTimestamp;\n\tupdatedAt: MemoryRowTimestamp;\n};\n\nfunction toDate(value: MemoryRowTimestamp): Date {\n\treturn value instanceof Date ? value : new Date(value);\n}\n\nfunction toNullableDate(value: MemoryRowTimestamp | null): Date | null {\n\treturn value === null ? null : toDate(value);\n}\n\nexport function rowToMemory(row: MemoryLikeRow): Memory {\n\treturn {\n\t\tid: row.id,\n\t\tentityId: row.entityId,\n\t\tcontent: row.content,\n\t\ttype: row.type as MemoryType,\n\t\timportance: row.importance as ImportanceLevel,\n\t\ttags: row.tags,\n\t\tsource: row.source,\n\t\tmetadata: cloneJsonObject(row.metadata),\n\t\tconfidence: row.confidence,\n\t\tembeddingModel: row.embeddingModel,\n\t\tembeddingDimensions: row.embeddingDimensions,\n\t\tsupersededBy: row.supersededBy,\n\t\tsupersededAt: toNullableDate(row.supersededAt),\n\t\texpiresAt: toNullableDate(row.expiresAt),\n\t\tlastAccessedAt: toNullableDate(row.lastAccessedAt),\n\t\taccessCount: row.accessCount,\n\t\tcreatedAt: toDate(row.createdAt),\n\t\tupdatedAt: toDate(row.updatedAt),\n\t};\n}\n","import type { DatabaseHandle } from \"../db/index.js\";\nimport { insertEvent, listEvents } from \"../db/queries/events.js\";\nimport {\n\tcountPruneMatches,\n\tdeleteMemoriesForEntity as deleteMemoriesForEntityQuery,\n\tdeleteMemory as deleteMemoryQuery,\n\tfindDuplicatePairs as findDuplicatePairsQuery,\n\tgetEntityMemoryStatsCounts,\n\tgetGlobalMemoryStatsCounts,\n\tgetMemoryById,\n\tgetMemoryEmbeddings as getMemoryEmbeddingsQuery,\n\tinsertMemories as insertMemoryRows,\n\tlexicalSearch as lexicalSearchQuery,\n\tloadConsolidationTargets,\n\tlockConsolidationMemories,\n\tmarkMemoriesAccessed,\n\tmarkMemoriesSuperseded,\n\ttype PruneFilter,\n\tpruneMemories,\n\tsetMemoryTags,\n\tvectorSearch as vectorSearchQuery,\n} from \"../db/queries/memories.js\";\nimport {\n\tgetInstallationMeta,\n\tgetStoredEmbeddingModels,\n\trecordInstallationEmbeddingModel,\n} from \"../db/queries/meta.js\";\nimport type { EventRow, NewMemoryRow } from \"../db/schema.js\";\nimport { MnemocyteError } from \"../errors.js\";\nimport { throwIfAborted } from \"../resilience.js\";\nimport type {\n\tAuditEvent,\n\tEmbedder,\n\tEntityStats,\n\tGlobalStats,\n\tImportanceLevel,\n\tMnemocyteClient,\n\tMnemocyteConfig,\n} from \"../types.js\";\nimport { createMemoryClient } from \"./client-core.js\";\nimport {\n\tDEFAULT_AUDIT_LOG_LIMIT,\n\tDEFAULT_DUPLICATE_LIMIT,\n\tDEFAULT_DUPLICATE_THRESHOLD,\n\tIMPORTANCE_RANK,\n} from \"./defaults.js\";\nimport { memoryHasDependentsError } from \"./deletion.js\";\nimport { cloneJsonObject } from \"./json.js\";\nimport { rowToMemory } from \"./postgres-records.js\";\nimport { createEventId, type StoredMemory } from \"./records.js\";\nimport {\n\tassertPruneFilterHasSelector,\n\ttype MemoryStore,\n\ttype StoreConsolidateInput,\n\ttype StoreConsolidateResult,\n\ttype StoreDuplicatePair,\n\ttype StoreLexicalCandidate,\n\ttype StoreLexicalSearchInput,\n\ttype StoreVectorCandidate,\n\ttype StoreVectorSearchInput,\n\ttype ValidatedPruneFilter,\n} from \"./store.js\";\n\nconst IMPORTANCE_LEVELS: readonly ImportanceLevel[] = [\n\t\"low\",\n\t\"normal\",\n\t\"high\",\n\t\"critical\",\n];\n\nconst MIGRATION_ERROR_CODES = new Set([\"42P01\", \"42703\", \"42704\", \"42883\"]);\nconst CONSOLIDATION_SURVIVOR_FOREIGN_KEY =\n\t\"mnemocyte_memories_superseded_by_mnemocyte_memories_id_fk\";\n\nfunction rowToAuditEvent(row: EventRow): AuditEvent {\n\treturn {\n\t\tid: row.id,\n\t\tentityId: row.entityId,\n\t\tdescription: row.description,\n\t\tmetadata: cloneJsonObject(row.metadata),\n\t\ttimestamp: new Date(row.timestamp),\n\t};\n}\n\nfunction importanceCeilingLevels(\n\tmax: ImportanceLevel,\n): readonly ImportanceLevel[] {\n\treturn IMPORTANCE_LEVELS.filter(\n\t\t(level) => IMPORTANCE_RANK[level] <= IMPORTANCE_RANK[max],\n\t);\n}\n\nfunction hasPostgresErrorCode(error: unknown, code: string): boolean {\n\treturn (\n\t\ttypeof error === \"object\" &&\n\t\terror !== null &&\n\t\t\"code\" in error &&\n\t\terror.code === code\n\t);\n}\n\nfunction hasPostgresConstraintName(error: unknown, name: string): boolean {\n\treturn (\n\t\ttypeof error === \"object\" &&\n\t\terror !== null &&\n\t\t\"constraint_name\" in error &&\n\t\terror.constraint_name === name\n\t);\n}\n\nfunction getPostgresErrorCode(error: unknown): string | undefined {\n\treturn typeof error === \"object\" &&\n\t\terror !== null &&\n\t\t\"code\" in error &&\n\t\ttypeof (error as { code?: unknown }).code === \"string\"\n\t\t? (error as { code: string }).code\n\t\t: undefined;\n}\n\nfunction normalizePostgresError(error: unknown): MnemocyteError {\n\tif (error instanceof MnemocyteError) {\n\t\treturn error;\n\t}\n\tconst code = getPostgresErrorCode(error);\n\tif (code && MIGRATION_ERROR_CODES.has(code)) {\n\t\treturn new MnemocyteError(\n\t\t\t\"Postgres schema is missing or incompatible. Apply the bundled Mnemocyte migrations before using the Postgres backend.\",\n\t\t\t\"MIGRATION\",\n\t\t\terror,\n\t\t);\n\t}\n\treturn new MnemocyteError(\"Postgres operation failed.\", \"DB\", error);\n}\n\nasync function runPostgresOperation<T>(\n\toperation: () => Promise<T>,\n): Promise<T> {\n\ttry {\n\t\treturn await operation();\n\t} catch (error) {\n\t\tthrow normalizePostgresError(error);\n\t}\n}\n\nasync function runPostgresDeleteOperation<T>(\n\toperation: () => Promise<T>,\n): Promise<T> {\n\ttry {\n\t\treturn await operation();\n\t} catch (error) {\n\t\tif (error instanceof MnemocyteError) {\n\t\t\tthrow error;\n\t\t}\n\t\tif (\n\t\t\thasPostgresErrorCode(error, \"23503\") &&\n\t\t\thasPostgresConstraintName(error, CONSOLIDATION_SURVIVOR_FOREIGN_KEY)\n\t\t) {\n\t\t\tthrow memoryHasDependentsError(error);\n\t\t}\n\t\tthrow normalizePostgresError(error);\n\t}\n}\n\nfunction toPruneFilter(input: ValidatedPruneFilter): PruneFilter {\n\tconst filter: PruneFilter = {};\n\tif (input.entityId !== undefined) {\n\t\tfilter.entityId = input.entityId;\n\t}\n\tif (input.expired === true) {\n\t\tfilter.expired = true;\n\t}\n\tif (input.superseded === true) {\n\t\tfilter.superseded = true;\n\t}\n\tif (input.createdBefore !== undefined) {\n\t\tfilter.createdBefore = input.createdBefore;\n\t}\n\tif (input.notAccessedSince !== undefined) {\n\t\tfilter.notAccessedSince = input.notAccessedSince;\n\t}\n\tif (input.types !== undefined && input.types.length > 0) {\n\t\tfilter.types = input.types;\n\t}\n\tif (input.tags !== undefined && input.tags.length > 0) {\n\t\tfilter.tags = input.tags;\n\t}\n\tif (input.maxImportance !== undefined) {\n\t\tfilter.maxImportanceLevels = importanceCeilingLevels(input.maxImportance);\n\t}\n\treturn filter;\n}\n\nfunction toMemoryRow(memory: StoredMemory): NewMemoryRow {\n\treturn {\n\t\t...memory,\n\t\ttags: [...memory.tags],\n\t\tembedding: [...memory.embedding],\n\t};\n}\n\nexport function createPostgresStore(handle: DatabaseHandle): MemoryStore {\n\tlet schemaValidated = false;\n\tlet schemaValidationPromise: Promise<void> | undefined;\n\n\tasync function ensureEmbeddingCompatibility(\n\t\tembedder: Embedder,\n\t): Promise<void> {\n\t\tif (schemaValidated) {\n\t\t\treturn;\n\t\t}\n\t\tif (!schemaValidationPromise) {\n\t\t\tschemaValidationPromise = validateEmbeddingCompatibility(embedder).catch(\n\t\t\t\t(error: unknown) => {\n\t\t\t\t\tschemaValidationPromise = undefined;\n\t\t\t\t\tthrow error;\n\t\t\t\t},\n\t\t\t);\n\t\t}\n\t\tawait schemaValidationPromise;\n\t}\n\n\tasync function validateEmbeddingCompatibility(\n\t\tembedder: Embedder,\n\t): Promise<void> {\n\t\tlet meta: Awaited<ReturnType<typeof getInstallationMeta>>;\n\t\ttry {\n\t\t\tmeta = await getInstallationMeta(handle.db);\n\t\t} catch (error) {\n\t\t\tif (\n\t\t\t\thasPostgresErrorCode(error, \"42P01\") ||\n\t\t\t\thasPostgresErrorCode(error, \"42703\")\n\t\t\t) {\n\t\t\t\tthrow new MnemocyteError(\n\t\t\t\t\t\"Postgres embedding metadata is missing or outdated. Apply the bundled migrations through 0002_add_embedding_model.sql, or render a fresh dimension-specific initial migration, before using embedding-dependent operations.\",\n\t\t\t\t\t\"MIGRATION\",\n\t\t\t\t\terror,\n\t\t\t\t);\n\t\t\t}\n\t\t\tthrow normalizePostgresError(error);\n\t\t}\n\t\tif (!meta) {\n\t\t\tthrow new MnemocyteError(\n\t\t\t\t'mnemocyte_meta is missing the \"installation\" row. Apply the bundled migrations, or render a fresh dimension-specific initial migration, before using embedding-dependent operations.',\n\t\t\t\t\"MIGRATION\",\n\t\t\t);\n\t\t}\n\t\tif (meta.embeddingDimensions !== embedder.dimensions) {\n\t\t\tthrow new MnemocyteError(\n\t\t\t\t`embedder.dimensions (${embedder.dimensions}) must match mnemocyte_meta.embedding_dimensions (${meta.embeddingDimensions}). Render and apply a migration for the selected embedding dimension, or configure an embedder that matches this installation.`,\n\t\t\t\t\"CONFIG\",\n\t\t\t);\n\t\t}\n\t\tlet installationModel = meta.embeddingModel;\n\t\tif (installationModel === null) {\n\t\t\ttry {\n\t\t\t\tconst storedModels = await getStoredEmbeddingModels(handle.db);\n\t\t\t\tif (storedModels.length > 1) {\n\t\t\t\t\tthrow new MnemocyteError(\n\t\t\t\t\t\t\"mnemocyte_meta.embedding_model is unset, but stored memories contain multiple embedding_model values. Re-embed or remove the mixed historical rows, then explicitly record the installation model before using embedding-dependent operations.\",\n\t\t\t\t\t\t\"MIGRATION\",\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tconst inferredModel = storedModels[0] ?? embedder.model;\n\t\t\t\tconst recorded = await recordInstallationEmbeddingModel(\n\t\t\t\t\thandle.db,\n\t\t\t\t\tinferredModel,\n\t\t\t\t);\n\t\t\t\tif (recorded) {\n\t\t\t\t\tinstallationModel = recorded.embeddingModel;\n\t\t\t\t} else {\n\t\t\t\t\tconst concurrentlyRecorded = await getInstallationMeta(handle.db);\n\t\t\t\t\tinstallationModel = concurrentlyRecorded?.embeddingModel ?? null;\n\t\t\t\t}\n\t\t\t} catch (error) {\n\t\t\t\tthrow normalizePostgresError(error);\n\t\t\t}\n\t\t\tif (installationModel === null) {\n\t\t\t\tthrow new MnemocyteError(\n\t\t\t\t\t\"mnemocyte_meta.embedding_model could not be recorded. Verify the installation metadata row and retry.\",\n\t\t\t\t\t\"MIGRATION\",\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\tif (installationModel !== embedder.model) {\n\t\t\tthrow new MnemocyteError(\n\t\t\t\t`embedder.model (\"${embedder.model}\") must match mnemocyte_meta.embedding_model (\"${installationModel}\"). Configure the recorded model, or explicitly re-embed existing memories and update the installation metadata.`,\n\t\t\t\t\"CONFIG\",\n\t\t\t);\n\t\t}\n\t\tschemaValidated = true;\n\t}\n\n\treturn {\n\t\tbackend: \"postgres\",\n\t\tasync ensureSchema() {},\n\t\tensureEmbeddingCompatibility,\n\t\tasync insertMemories(memories) {\n\t\t\treturn runPostgresOperation(async () => {\n\t\t\t\tconst rows = await insertMemoryRows(\n\t\t\t\t\thandle.db,\n\t\t\t\t\tmemories.map(toMemoryRow),\n\t\t\t\t);\n\t\t\t\treturn rows.map(rowToMemory);\n\t\t\t});\n\t\t},\n\t\tasync vectorSearch(input: StoreVectorSearchInput) {\n\t\t\treturn runPostgresOperation(async () => {\n\t\t\t\tconst rows = await vectorSearchQuery(handle.db, input);\n\t\t\t\treturn rows.map(\n\t\t\t\t\t(row) =>\n\t\t\t\t\t\t({\n\t\t\t\t\t\t\tmemory: rowToMemory(row),\n\t\t\t\t\t\t\tvectorScore: row.vectorScore,\n\t\t\t\t\t\t}) satisfies StoreVectorCandidate,\n\t\t\t\t);\n\t\t\t});\n\t\t},\n\t\tasync lexicalSearch(input: StoreLexicalSearchInput) {\n\t\t\treturn runPostgresOperation(async () => {\n\t\t\t\tconst rows = await lexicalSearchQuery(handle.db, input);\n\t\t\t\treturn rows.map(\n\t\t\t\t\t(row) =>\n\t\t\t\t\t\t({\n\t\t\t\t\t\t\tmemory: rowToMemory(row),\n\t\t\t\t\t\t\tlexicalScore: row.lexicalScore,\n\t\t\t\t\t\t}) satisfies StoreLexicalCandidate,\n\t\t\t\t);\n\t\t\t});\n\t\t},\n\t\tasync getMemoryEmbeddings(memoryIds) {\n\t\t\treturn runPostgresOperation(() =>\n\t\t\t\tgetMemoryEmbeddingsQuery(handle.db, memoryIds),\n\t\t\t);\n\t\t},\n\t\tasync markMemoriesAccessed(memoryIds) {\n\t\t\treturn runPostgresOperation(async () => {\n\t\t\t\tconst rows = await markMemoriesAccessed(handle.db, memoryIds);\n\t\t\t\treturn rows.map((row) => {\n\t\t\t\t\tif (row.lastAccessedAt === null) {\n\t\t\t\t\t\tthrow new MnemocyteError(\n\t\t\t\t\t\t\t\"Postgres access update returned no timestamp.\",\n\t\t\t\t\t\t\t\"DB\",\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\treturn {\n\t\t\t\t\t\t...row,\n\t\t\t\t\t\tlastAccessedAt: row.lastAccessedAt,\n\t\t\t\t\t};\n\t\t\t\t});\n\t\t\t});\n\t\t},\n\t\tasync deleteMemory(entityId, memoryId) {\n\t\t\treturn runPostgresDeleteOperation(async () => {\n\t\t\t\tconst result = await deleteMemoryQuery(handle.db, entityId, memoryId);\n\t\t\t\tif (result.hasDependents) {\n\t\t\t\t\tthrow memoryHasDependentsError();\n\t\t\t\t}\n\t\t\t\treturn result.deletedCount > 0;\n\t\t\t});\n\t\t},\n\t\tasync deleteMemoriesForEntity(entityId) {\n\t\t\treturn runPostgresDeleteOperation(async () => {\n\t\t\t\tconst result = await deleteMemoriesForEntityQuery(handle.db, entityId);\n\t\t\t\tif (result.hasDependents) {\n\t\t\t\t\tthrow memoryHasDependentsError();\n\t\t\t\t}\n\t\t\t\treturn result.deletedCount;\n\t\t\t});\n\t\t},\n\t\tasync prune(input, options) {\n\t\t\treturn runPostgresDeleteOperation(async () => {\n\t\t\t\tthrowIfAborted(options?.signal);\n\t\t\t\tassertPruneFilterHasSelector(input);\n\t\t\t\tconst filter = toPruneFilter(input);\n\t\t\t\tconst dryRun = input.dryRun === true;\n\t\t\t\tif (dryRun) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tmatchedCount: await countPruneMatches(\n\t\t\t\t\t\t\thandle.db,\n\t\t\t\t\t\t\tfilter,\n\t\t\t\t\t\t\toptions?.signal,\n\t\t\t\t\t\t),\n\t\t\t\t\t\tdeletedCount: 0,\n\t\t\t\t\t\tdryRun: true,\n\t\t\t\t\t\tdeletedByEntity: [],\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\tconst result = await pruneMemories(handle.db, filter, options?.signal);\n\t\t\t\tif (result.hasDependents) {\n\t\t\t\t\tthrow memoryHasDependentsError();\n\t\t\t\t}\n\t\t\t\treturn {\n\t\t\t\t\tmatchedCount: result.matchedCount,\n\t\t\t\t\tdeletedCount: result.deletedCount,\n\t\t\t\t\tdryRun: false,\n\t\t\t\t\tdeletedByEntity: result.deletedByEntity,\n\t\t\t\t};\n\t\t\t});\n\t\t},\n\t\tasync findDuplicatePairs(input, options) {\n\t\t\treturn runPostgresOperation(async () => {\n\t\t\t\tconst rows = await findDuplicatePairsQuery(\n\t\t\t\t\thandle.db,\n\t\t\t\t\t{\n\t\t\t\t\t\tentityId: input.entityId,\n\t\t\t\t\t\tthreshold: input.threshold ?? DEFAULT_DUPLICATE_THRESHOLD,\n\t\t\t\t\t\tlimit: input.limit ?? DEFAULT_DUPLICATE_LIMIT,\n\t\t\t\t\t\t...(input.types === undefined ? {} : { types: input.types }),\n\t\t\t\t\t\t...(input.tags === undefined ? {} : { tags: input.tags }),\n\t\t\t\t\t\t...(input.includeSuperseded === undefined\n\t\t\t\t\t\t\t? {}\n\t\t\t\t\t\t\t: { includeSuperseded: input.includeSuperseded }),\n\t\t\t\t\t\t...(input.includeExpired === undefined\n\t\t\t\t\t\t\t? {}\n\t\t\t\t\t\t\t: { includeExpired: input.includeExpired }),\n\t\t\t\t\t},\n\t\t\t\t\toptions?.signal,\n\t\t\t\t);\n\t\t\t\treturn rows.map(\n\t\t\t\t\t(row) =>\n\t\t\t\t\t\t({\n\t\t\t\t\t\t\ta: rowToMemory(row.a),\n\t\t\t\t\t\t\tb: rowToMemory(row.b),\n\t\t\t\t\t\t\tsimilarity: Math.max(0, Math.min(1, row.similarity)),\n\t\t\t\t\t\t}) satisfies StoreDuplicatePair,\n\t\t\t\t);\n\t\t\t});\n\t\t},\n\t\tasync addAuditEvents(events) {\n\t\t\treturn runPostgresOperation(async () => {\n\t\t\t\tfor (const event of events) {\n\t\t\t\t\tawait insertEvent(handle.db, {\n\t\t\t\t\t\tid: event.id,\n\t\t\t\t\t\tentityId: event.entityId,\n\t\t\t\t\t\tdescription: event.description,\n\t\t\t\t\t\tmetadata: cloneJsonObject(event.metadata),\n\t\t\t\t\t\ttimestamp: event.timestamp,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t});\n\t\t},\n\t\tasync listAuditLog(input, options) {\n\t\t\treturn runPostgresOperation(async () => {\n\t\t\t\tconst rows = await listEvents(\n\t\t\t\t\thandle.db,\n\t\t\t\t\t{\n\t\t\t\t\t\tentityId: input.entityId,\n\t\t\t\t\t\tlimit: input.limit ?? DEFAULT_AUDIT_LOG_LIMIT,\n\t\t\t\t\t\t...(input.before === undefined ? {} : { before: input.before }),\n\t\t\t\t\t\t...(input.after === undefined ? {} : { after: input.after }),\n\t\t\t\t\t\t...(input.beforeCursor === undefined\n\t\t\t\t\t\t\t? {}\n\t\t\t\t\t\t\t: { beforeCursor: input.beforeCursor }),\n\t\t\t\t\t\t...(input.afterCursor === undefined\n\t\t\t\t\t\t\t? {}\n\t\t\t\t\t\t\t: { afterCursor: input.afterCursor }),\n\t\t\t\t\t},\n\t\t\t\t\toptions?.signal,\n\t\t\t\t);\n\t\t\t\treturn rows.map(rowToAuditEvent);\n\t\t\t});\n\t\t},\n\t\tasync getMemory(entityId, memoryId, options) {\n\t\t\treturn runPostgresOperation(async () => {\n\t\t\t\tthrowIfAborted(options?.signal);\n\t\t\t\tconst row = await getMemoryById(handle.db, entityId, memoryId);\n\t\t\t\tthrowIfAborted(options?.signal);\n\t\t\t\treturn row ? rowToMemory(row) : null;\n\t\t\t});\n\t\t},\n\t\tasync loadConsolidationTargets(entityId, ids, options) {\n\t\t\treturn runPostgresOperation(async () => {\n\t\t\t\tthrowIfAborted(options?.signal);\n\t\t\t\tconst targets = await loadConsolidationTargets(\n\t\t\t\t\thandle.db,\n\t\t\t\t\tentityId,\n\t\t\t\t\tids,\n\t\t\t\t);\n\t\t\t\tthrowIfAborted(options?.signal);\n\t\t\t\treturn targets;\n\t\t\t});\n\t\t},\n\t\tasync consolidate(\n\t\t\tinput: StoreConsolidateInput,\n\t\t\toptions,\n\t\t): Promise<StoreConsolidateResult> {\n\t\t\treturn runPostgresOperation(async () => {\n\t\t\t\tthrowIfAborted(options?.signal);\n\t\t\t\tconst newSupersededIds = await handle.db.transaction(async (tx) => {\n\t\t\t\t\tthrowIfAborted(options?.signal);\n\t\t\t\t\tconst lockedMemories = await lockConsolidationMemories(\n\t\t\t\t\t\ttx,\n\t\t\t\t\t\tinput.entityId,\n\t\t\t\t\t\tinput.survivorId,\n\t\t\t\t\t\tinput.supersededIds,\n\t\t\t\t\t);\n\t\t\t\t\tthrowIfAborted(options?.signal);\n\t\t\t\t\tconst survivor = lockedMemories.find(\n\t\t\t\t\t\t(memory) => memory.id === input.survivorId,\n\t\t\t\t\t);\n\t\t\t\t\tif (!survivor || survivor.supersededBy !== null) {\n\t\t\t\t\t\tthrow new MnemocyteError(\n\t\t\t\t\t\t\t\"Consolidation survivor changed before mutation.\",\n\t\t\t\t\t\t\t\"CONFLICT\",\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\tconst targets = lockedMemories.filter(\n\t\t\t\t\t\t(memory) => memory.id !== input.survivorId,\n\t\t\t\t\t);\n\t\t\t\t\tif (\n\t\t\t\t\t\ttargets.some(\n\t\t\t\t\t\t\t(target) =>\n\t\t\t\t\t\t\t\ttarget.supersededBy !== null &&\n\t\t\t\t\t\t\t\ttarget.supersededBy !== input.survivorId,\n\t\t\t\t\t\t)\n\t\t\t\t\t) {\n\t\t\t\t\t\tthrow new MnemocyteError(\n\t\t\t\t\t\t\t\"Superseded memory already belongs to a different survivor.\",\n\t\t\t\t\t\t\t\"CONFLICT\",\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\tconst activeIds = targets\n\t\t\t\t\t\t.filter((target) => target.supersededBy === null)\n\t\t\t\t\t\t.map((target) => target.id);\n\t\t\t\t\tconst updated = await markMemoriesSuperseded(tx, {\n\t\t\t\t\t\tsurvivorId: input.survivorId,\n\t\t\t\t\t\tentityId: input.entityId,\n\t\t\t\t\t\tids: activeIds,\n\t\t\t\t\t\tnow: input.now,\n\t\t\t\t\t});\n\t\t\t\t\tthrowIfAborted(options?.signal);\n\t\t\t\t\tconst ids = updated.map((row) => row.id);\n\t\t\t\t\tif (input.auditEnabled) {\n\t\t\t\t\t\tfor (const id of ids) {\n\t\t\t\t\t\t\tthrowIfAborted(options?.signal);\n\t\t\t\t\t\t\tawait insertEvent(tx, {\n\t\t\t\t\t\t\t\tid: createEventId(),\n\t\t\t\t\t\t\t\tentityId: input.entityId,\n\t\t\t\t\t\t\t\tdescription: \"memory.superseded\",\n\t\t\t\t\t\t\t\tmetadata: { memoryId: id, supersededBy: input.survivorId },\n\t\t\t\t\t\t\t\ttimestamp: input.now,\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\tthrowIfAborted(options?.signal);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif (input.mergeTags && updated.length > 0) {\n\t\t\t\t\t\tconst mergedTags = new Set(survivor.tags);\n\t\t\t\t\t\tfor (const row of updated) {\n\t\t\t\t\t\t\tthrowIfAborted(options?.signal);\n\t\t\t\t\t\t\tfor (const tag of row.tags) {\n\t\t\t\t\t\t\t\tmergedTags.add(tag);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (mergedTags.size !== survivor.tags.length) {\n\t\t\t\t\t\t\tthrowIfAborted(options?.signal);\n\t\t\t\t\t\t\tawait setMemoryTags(tx, {\n\t\t\t\t\t\t\t\tentityId: input.entityId,\n\t\t\t\t\t\t\t\tmemoryId: input.survivorId,\n\t\t\t\t\t\t\t\ttags: [...mergedTags],\n\t\t\t\t\t\t\t\tnow: input.now,\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\tthrowIfAborted(options?.signal);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tthrowIfAborted(options?.signal);\n\t\t\t\t\treturn ids;\n\t\t\t\t});\n\t\t\t\treturn { supersededIds: newSupersededIds };\n\t\t\t});\n\t\t},\n\t\tasync stats(input, now) {\n\t\t\treturn runPostgresOperation(async () => {\n\t\t\t\tif (input?.entityId) {\n\t\t\t\t\tconst counts = await getEntityMemoryStatsCounts(\n\t\t\t\t\t\thandle.db,\n\t\t\t\t\t\tinput.entityId,\n\t\t\t\t\t\tnow,\n\t\t\t\t\t);\n\t\t\t\t\treturn {\n\t\t\t\t\t\tentityId: input.entityId,\n\t\t\t\t\t\t...counts,\n\t\t\t\t\t} satisfies EntityStats;\n\t\t\t\t}\n\t\t\t\treturn (await getGlobalMemoryStatsCounts(\n\t\t\t\t\thandle.db,\n\t\t\t\t\tnow,\n\t\t\t\t)) satisfies GlobalStats;\n\t\t\t});\n\t\t},\n\t\tasync close() {\n\t\t\treturn runPostgresOperation(() => handle.close());\n\t\t},\n\t};\n}\n\nexport function createPostgresClient(\n\tconfig: MnemocyteConfig,\n\thandle: DatabaseHandle,\n): MnemocyteClient {\n\treturn createMemoryClient(config, createPostgresStore(handle));\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA,SAAgB,sBAAsB,OAAuB;CAC5D,IAAI,CAAC,OAAO,SAAS,KAAK,GACzB,MAAM,IAAI,MAAM,uCAAuC;CAExD,OAAO,OAAO,GAAG,OAAO,EAAE,IAAI,MAAM,MAAM,SAAS;AACpD;;;;;;;;ACUA,MAAM,SAAS,WAIZ;CACF,SAAS,QAAQ;EAEhB,OAAO,UADY,QAAQ,cAAc,KACb;CAC7B;CACA,SAAS,OAAO;EACf,OAAO,IAAI,MAAM,IAAI,qBAAqB,EAAE,KAAK,GAAG,EAAE;CACvD;CACA,WAAW,OAAO;EACjB,OAAO,MAAM,MAAM,GAAG,EAAE,EAAE,MAAM,GAAG,EAAE,OAAO,OAAO,EAAE,IAAI,MAAM;CAChE;AACD,CAAC;AAED,MAAa,gBAAgB,QAC5B,sBACA;CACC,IAAI,KAAK,IAAI,EAAE,WAAW;CAC1B,UAAU,KAAK,WAAW,EAAE,QAAQ;CACpC,SAAS,KAAK,SAAS,EAAE,QAAQ;CACjC,MAAM,KAAK,MAAM,EAAE,QAAQ,EAAE,QAAQ,MAAM;CAC3C,YAAY,KAAK,YAAY,EAAE,QAAQ,EAAE,QAAQ,QAAQ;CACzD,MAAM,KAAK,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAG,cAAc;CAC9D,QAAQ,KAAK,QAAQ;CACrB,UAAU,MAAM,UAAU,EAAE,MAAkB,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC;CACpE,YAAY,KAAK,YAAY,EAAE,QAAQ,E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AI;MACxC,KAAK,MAAM,OAAO,SAAS;OAC1B,eAAe,SAAS,MAAM;OAC9B,KAAK,MAAM,OAAO,IAAI,MACrB,WAAW,IAAI,GAAG;MAEpB;MACA,IAAI,WAAW,SAAS,SAAS,KAAK,QAAQ;OAC7C,eAAe,SAAS,MAAM;OAC9B,MAAM,cAAc,IAAI;QACvB,UAAU,MAAM;QAChB,UAAU,MAAM;QAChB,MAAM,CAAC,GAAG,UAAU;QACpB,KAAK,MAAM;OACZ,CAAC;OACD,eAAe,SAAS,MAAM;MAC/B;KACD;KACA,eAAe,SAAS,MAAM;KAC9B,OAAO;IACR,CAAC,EACwC;GAC1C,CAAC;EACF;EACA,MAAM,MAAM,OAAO,KAAK;GACvB,OAAO,qBAAqB,YAAY;IACvC,IAAI,OAAO,UAAU;KACpB,MAAM,SAAS,MAAM,2BACpB,OAAO,IACP,MAAM,UACN,GACD;KACA,OAAO;MACN,UAAU,MAAM;MAChB,GAAG;KACJ;IACD;IACA,OAAQ,MAAM,2BACb,OAAO,IACP,GACD;GACD,CAAC;EACF;EACA,MAAM,QAAQ;GACb,OAAO,2BAA2B,OAAO,MAAM,CAAC;EACjD;CACD;AACD"}
@@ -0,0 +1,9 @@
1
+ import { r as createDatabase, t as createPostgresStore } from "./postgres-BHQ1pj16.mjs";
2
+ //#region src/memory/postgres-runtime.ts
3
+ function createPostgresStoreFromUrl(databaseUrl) {
4
+ return createPostgresStore(createDatabase(databaseUrl));
5
+ }
6
+ //#endregion
7
+ export { createPostgresStoreFromUrl };
8
+
9
+ //# sourceMappingURL=postgres-runtime-DxJxns07.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"postgres-runtime-DxJxns07.mjs","names":[],"sources":["../src/memory/postgres-runtime.ts"],"sourcesContent":["import { createDatabase } from \"../db/index.js\";\nimport { createPostgresStore } from \"./postgres.js\";\nimport type { MemoryStore } from \"./store.js\";\n\nexport function createPostgresStoreFromUrl(databaseUrl: string): MemoryStore {\n\treturn createPostgresStore(createDatabase(databaseUrl));\n}\n"],"mappings":";;AAIA,SAAgB,2BAA2B,aAAkC;CAC5E,OAAO,oBAAoB,eAAe,WAAW,CAAC;AACvD"}