@axiom-lattice/pg-stores 3.1.12 → 3.1.13

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.mjs CHANGED
@@ -9884,6 +9884,22 @@ var createProjectRoomReadStates = {
9884
9884
  }
9885
9885
  };
9886
9886
 
9887
+ // src/migrations/project_room_message_retention_migration.ts
9888
+ var addProjectRoomMessageRetentionIndex = {
9889
+ version: 179,
9890
+ name: "add_project_room_message_retention_index",
9891
+ up: async (client) => {
9892
+ await client.query(`
9893
+ CREATE INDEX IF NOT EXISTS idx_lattice_project_room_messages_chat_created
9894
+ ON lattice_project_room_messages (created_at)
9895
+ WHERE source IN ('user', 'agent')
9896
+ `);
9897
+ },
9898
+ down: async (client) => {
9899
+ await client.query("DROP INDEX IF EXISTS idx_lattice_project_room_messages_chat_created");
9900
+ }
9901
+ };
9902
+
9887
9903
  // src/migrations/user_push_subscription_migration.ts
9888
9904
  var createUserPushSubscriptions = {
9889
9905
  version: 178,
@@ -10728,6 +10744,30 @@ var PostgreSQLProjectRoomMessageStore = class {
10728
10744
  );
10729
10745
  return result.rows[0]?.count ?? 0;
10730
10746
  }
10747
+ /**
10748
+ * Deletes one bounded batch of chat messages older than a horizon.
10749
+ *
10750
+ * @param input Exclusive upper time bound and requested batch size (clamped to 1..1000).
10751
+ * @returns The number of deleted rows.
10752
+ * @remarks Only `source IN ('user','agent')` rows are eligible; task/system events are retained.
10753
+ */
10754
+ async deleteChatOlderThan(input) {
10755
+ if (!(input.before instanceof Date) || Number.isNaN(input.before.getTime())) {
10756
+ throw new RangeError("Project room message retention horizon date is invalid");
10757
+ }
10758
+ const limit = Math.min(1e3, Math.max(1, Math.trunc(Number.isFinite(input.limit) ? input.limit : 1)));
10759
+ const result = await this.pool.query(
10760
+ `DELETE FROM lattice_project_room_messages
10761
+ WHERE ctid IN (
10762
+ SELECT ctid FROM lattice_project_room_messages
10763
+ WHERE created_at < $1 AND source IN ('user','agent')
10764
+ ORDER BY created_at ASC
10765
+ LIMIT $2
10766
+ )`,
10767
+ [input.before, limit]
10768
+ );
10769
+ return result.rowCount ?? 0;
10770
+ }
10731
10771
  parameters(input) {
10732
10772
  return [
10733
10773
  input.id,
@@ -10905,6 +10945,7 @@ async function createPgStoreConfig(connectionString) {
10905
10945
  mm.register(addAgentWebAppsIdentity);
10906
10946
  mm.register(createProjectRoomReadStates);
10907
10947
  mm.register(createUserPushSubscriptions);
10948
+ mm.register(addProjectRoomMessageRetentionIndex);
10908
10949
  await mm.migrate();
10909
10950
  const checkpoint = PostgresSaver.fromConnString(connectionString);
10910
10951
  checkpoint.setup().catch((err) => {